add IStream interface and implement write call

Josef Reidinger josef.reidinger at gmail.com
Sat Jan 12 12:27:20 CST 2008


---
 dlls/msxml3/domdoc.c |  161 +++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 159 insertions(+), 2 deletions(-)

diff --git a/dlls/msxml3/domdoc.c b/dlls/msxml3/domdoc.c
index 856fcb0..2ca970d 100644
--- a/dlls/msxml3/domdoc.c
+++ b/dlls/msxml3/domdoc.c
@@ -169,6 +169,7 @@ typedef struct _domdoc
 {
     const struct IXMLDOMDocument2Vtbl *lpVtbl;
     const struct IPersistStreamVtbl   *lpvtblIPersistStream;
+    const struct IStreamVtbl          *lpvtblIStream;
     LONG ref;
     VARIANT_BOOL async;
     VARIANT_BOOL validating;
@@ -182,6 +183,8 @@ typedef struct _domdoc
 
      /* IPersistStream */
      IStream *stream;
+     /* for istream chunk */
+     xmlParserCtxtPtr chunkParser;
 } domdoc;
 
 LONG xmldoc_add_ref(xmlDocPtr doc)
@@ -219,6 +222,10 @@ static inline domdoc *impl_from_IPersistStream(IPersistStream *iface)
     return (domdoc *)((char*)iface - FIELD_OFFSET(domdoc, lpvtblIPersistStream));
 }
 
+static inline domdoc *impl_from_IStream(IStream *iface)
+{
+    return (domdoc *)((char*)iface - FIELD_OFFSET(domdoc, lpvtblIStream));
+}
 /************************************************************************
  * xmldoc implementation of IPersistStream.
  */
@@ -339,6 +346,150 @@ static const IPersistStreamVtbl xmldoc_IPersistStream_VTable =
     xmldoc_IPersistStream_GetSizeMax,
 };
 
+/************************************************************************
+ * xmldoc implementation of IStream.
+ */
+
+static HRESULT WINAPI xmldoc_IStream_QueryInterface(
+    IStream *iface, REFIID riid, LPVOID *ppvObj)
+{
+    domdoc *this = impl_from_IStream(iface);
+    return IXMLDocument_QueryInterface((IXMLDocument *)this, riid, ppvObj);
+}
+
+static ULONG WINAPI xmldoc_IStream_AddRef(
+    IStream *iface)
+{
+    domdoc *this = impl_from_IStream(iface);
+    return IXMLDocument_AddRef((IXMLDocument *)this);
+}
+
+static ULONG WINAPI xmldoc_IStream_Release(
+    IStream *iface)
+{
+    domdoc *this = impl_from_IStream(iface);
+    return IXMLDocument_Release((IXMLDocument *)this);
+}
+
+
+static HRESULT WINAPI xmldoc_IStream_Read(
+    IStream *iface, void *pv, ULONG cb, ULONG *pcbRead)
+{
+    FIXME("(%p, %p, %u, %p): stub!\n", iface, pv, cb, pcbRead);
+    return E_NOTIMPL;
+}
+
+static HRESULT WINAPI xmldoc_IStream_Write(
+    IStream *iface, void const *pv, ULONG cb, ULONG *pcbRead)
+{
+    domdoc *This = impl_from_IStream(iface);
+    if (!This->chunkParser){
+      TRACE("first chunk\n");
+      This->chunkParser = xmlCreatePushParserCtxt (NULL, NULL,pv, cb, NULL);
+    } else {
+      int res;
+      TRACE("continue with some parsing chunks\n");
+      res = xmlParseChunk (This->chunkParser, pv,cb, 0);
+      if (res)
+        ERR("Parse chunk failed (%p,%p,%u) with error %i\n",This->chunkParser,
+          pv,cb,res);
+      if (This->chunkParser->wellFormed){
+        xmlDocPtr xmldoc = This->chunkParser->myDoc;
+        attach_xmlnode(This->node, (xmlNodePtr) xmldoc);
+        xmlClearParserCtxt(This->chunkParser);
+        This->chunkParser = NULL;
+      }
+    }
+    FIXME("not set correctly readed chars");
+    *pcbRead = cb;
+
+    return S_OK;
+}
+
+
+static HRESULT WINAPI xmldoc_IStream_Seek(
+    IStream *iface, LARGE_INTEGER dlibMove,
+    DWORD dwOrigin, ULARGE_INTEGER* plibNewPosition)
+{
+    /* this call can be used only for read,
+     * call on write break reading chunks */
+    FIXME("(%p ): stub!\n", iface);
+    return E_NOTIMPL;
+}
+
+static HRESULT WINAPI xmldoc_IStream_SetSize(
+    IStream *iface, ULARGE_INTEGER libNewSize)
+{
+    TRACE("(%p): this call doesn't allow on xml stream.\n", iface);
+    return E_NOTIMPL;
+}
+
+static HRESULT WINAPI xmldoc_IStream_CopyTo( IStream *iface, IStream *target,
+    ULARGE_INTEGER cb, ULARGE_INTEGER* pcbRead, ULARGE_INTEGER* pcbWritten)
+{
+    TRACE("(%p): this call doesn't allow on xml stream.\n", iface);
+    return E_NOTIMPL;
+}
+
+static HRESULT WINAPI xmldoc_IStream_Commit( IStream *iface,
+    DWORD grfCommitFlags)
+{
+    TRACE("(%p): this call doesn't allow on xml stream.\n", iface);
+    return E_NOTIMPL;
+}
+
+static HRESULT WINAPI xmldoc_IStream_Revert(IStream* iface)
+{
+    TRACE("(%p): this call doesn't allow on xml stream.\n", iface);
+    return E_NOTIMPL;
+}
+
+
+static HRESULT WINAPI xmldoc_IStream_LockRegion(IStream* iface,
+    ULARGE_INTEGER libOffset, ULARGE_INTEGER cb, DWORD dwLockType)
+{
+    TRACE("(%p): this call doesn't allow on xml stream.\n", iface);
+    return E_NOTIMPL;
+}
+
+static HRESULT WINAPI xmldoc_IStream_UnlockRegion(IStream* iface,
+    ULARGE_INTEGER libOffset, ULARGE_INTEGER cb, DWORD dwLockType)
+{
+    TRACE("(%p): this call doesn't allow on xml stream.\n", iface);
+    return E_NOTIMPL;
+}
+
+static HRESULT WINAPI xmldoc_IStream_Stat(IStream* iface, STATSTG *pstatstg,
+    DWORD grfStatFlag)
+{
+    FIXME("(%p): stub.\n", iface);
+    return E_NOTIMPL;
+}
+
+static HRESULT WINAPI xmldoc_IStream_Clone(IStream* iface, IStream **ppstm)
+{
+    TRACE("(%p): this call doesn't allow on xml stream.\n", iface);
+    return E_NOTIMPL;
+}
+
+static const IStreamVtbl xmldoc_IStream_VTable =
+{
+    xmldoc_IStream_QueryInterface,
+    xmldoc_IStream_AddRef,
+    xmldoc_IStream_Release,
+    xmldoc_IStream_Read,
+    xmldoc_IStream_Write,
+    xmldoc_IStream_Seek,
+    xmldoc_IStream_SetSize,
+    xmldoc_IStream_CopyTo,
+    xmldoc_IStream_Commit,
+    xmldoc_IStream_Revert,
+    xmldoc_IStream_LockRegion,
+    xmldoc_IStream_UnlockRegion,
+    xmldoc_IStream_Stat,
+    xmldoc_IStream_Clone
+};
+
 static HRESULT WINAPI domdoc_QueryInterface( IXMLDOMDocument2 *iface, REFIID riid, void** ppvObject )
 {
     domdoc *This = impl_from_IXMLDOMDocument2( iface );
@@ -362,6 +513,10 @@ static HRESULT WINAPI domdoc_QueryInterface( IXMLDOMDocument2 *iface, REFIID rii
     {
         *ppvObject = (IPersistStream*)&(This->lpvtblIPersistStream);
     }
+    else if (IsEqualGUID(&IID_IStream, riid))
+    {
+        *ppvObject = (IStream*)&(This->lpvtblIStream);
+    }
     else if(IsEqualGUID(&IID_IRunnableObject, riid))
     {
         TRACE("IID_IRunnableObject not supported returning NULL\n");
@@ -1808,6 +1963,7 @@ HRESULT DOMDocument_create(IUnknown *pUnkOuter, LPVOID *ppObj)
 
     doc->lpVtbl = &domdoc_vtbl;
     doc->lpvtblIPersistStream = &xmldoc_IPersistStream_VTable;
+    doc->lpvtblIStream = &xmldoc_IStream_VTable;
     doc->ref = 1;
     doc->async = 0;
     doc->validating = 0;
@@ -1817,6 +1973,7 @@ HRESULT DOMDocument_create(IUnknown *pUnkOuter, LPVOID *ppObj)
     doc->error = S_OK;
     doc->schema = NULL;
     doc->stream = NULL;
+    doc->chunkParser = NULL;
 
     xmldoc = xmlNewDoc(NULL);
     if(!xmldoc)
-- 
1.5.3.8


--------------050508000702030508070007--



More information about the wine-patches mailing list