From 6f10f0d34b46a3fa87861dee609b514139dde7cb Mon Sep 17 00:00:00 2001 From: Christoph von Wittich Date: Sat, 6 Feb 2010 21:34:28 +0000 Subject: [PATCH] [MSXML3] sync msxml3 to wine 1.1.38 svn path=/trunk/; revision=45470 --- reactos/dll/win32/msxml3/attribute.c | 4 +- reactos/dll/win32/msxml3/bsc.c | 10 +-- reactos/dll/win32/msxml3/cdata.c | 51 +++++++++-- reactos/dll/win32/msxml3/comment.c | 53 ++++++++++-- reactos/dll/win32/msxml3/docfrag.c | 4 +- reactos/dll/win32/msxml3/domdoc.c | 53 +++++++----- reactos/dll/win32/msxml3/domimpl.c | 4 +- reactos/dll/win32/msxml3/element.c | 52 +++++++---- reactos/dll/win32/msxml3/entityref.c | 4 +- reactos/dll/win32/msxml3/factory.c | 3 +- reactos/dll/win32/msxml3/httprequest.c | 4 +- reactos/dll/win32/msxml3/msxml_private.h | 2 +- reactos/dll/win32/msxml3/node.c | 8 +- reactos/dll/win32/msxml3/nodelist.c | 4 +- reactos/dll/win32/msxml3/nodemap.c | 10 +-- reactos/dll/win32/msxml3/parseerror.c | 4 +- reactos/dll/win32/msxml3/pi.c | 4 +- reactos/dll/win32/msxml3/queryresult.c | 2 +- reactos/dll/win32/msxml3/regsvr.c | 6 +- reactos/dll/win32/msxml3/saxreader.c | 87 +++++++++---------- reactos/dll/win32/msxml3/schema.c | 4 +- reactos/dll/win32/msxml3/text.c | 51 +++++++++-- reactos/dll/win32/msxml3/xmldoc.c | 68 ++++++++++----- reactos/dll/win32/msxml3/xmlelem.c | 105 +++++++++++++---------- reactos/include/psdk/msxml2.idl | 8 ++ 25 files changed, 400 insertions(+), 205 deletions(-) diff --git a/reactos/dll/win32/msxml3/attribute.c b/reactos/dll/win32/msxml3/attribute.c index 6df849ee373..04b8c46cb4e 100644 --- a/reactos/dll/win32/msxml3/attribute.c +++ b/reactos/dll/win32/msxml3/attribute.c @@ -94,7 +94,7 @@ static ULONG WINAPI domattr_Release( if ( ref == 0 ) { destroy_xmlnode(&This->node); - HeapFree( GetProcessHeap(), 0, This ); + heap_free( This ); } return ref; @@ -546,7 +546,7 @@ IUnknown* create_attribute( xmlNodePtr attribute ) { domattr *This; - This = HeapAlloc( GetProcessHeap(), 0, sizeof *This ); + This = heap_alloc( sizeof *This ); if ( !This ) return NULL; diff --git a/reactos/dll/win32/msxml3/bsc.c b/reactos/dll/win32/msxml3/bsc.c index 1914ca88fa4..b24e04ca25a 100644 --- a/reactos/dll/win32/msxml3/bsc.c +++ b/reactos/dll/win32/msxml3/bsc.c @@ -93,11 +93,9 @@ static ULONG WINAPI bsc_Release( TRACE("(%p) ref=%d\n", This, ref); if(!ref) { - if(This->binding) - IBinding_Release(This->binding); - if(This->memstream) - IStream_Release(This->memstream); - HeapFree(GetProcessHeap(), 0, This); + if (This->binding) IBinding_Release(This->binding); + if (This->memstream) IStream_Release(This->memstream); + heap_free(This); } return ref; @@ -270,7 +268,7 @@ HRESULT bind_url(LPCWSTR url, HRESULT (*onDataAvailable)(void*,char*,DWORD), voi if(FAILED(hr)) return hr; - bsc = HeapAlloc(GetProcessHeap(), 0, sizeof(bsc_t)); + bsc = heap_alloc(sizeof(bsc_t)); bsc->lpVtbl = &bsc_vtbl; bsc->ref = 1; diff --git a/reactos/dll/win32/msxml3/cdata.c b/reactos/dll/win32/msxml3/cdata.c index 04b539d70bc..7d02a946a0c 100644 --- a/reactos/dll/win32/msxml3/cdata.c +++ b/reactos/dll/win32/msxml3/cdata.c @@ -101,7 +101,7 @@ static ULONG WINAPI domcdata_Release( if ( ref == 0 ) { destroy_xmlnode(&This->node); - HeapFree( GetProcessHeap(), 0, This ); + heap_free( This ); } return ref; @@ -606,7 +606,7 @@ static HRESULT WINAPI domcdata_appendData( } else hr = E_FAIL; - HeapFree(GetProcessHeap(), 0, pContent); + heap_free(pContent); return hr; } @@ -667,7 +667,7 @@ static HRESULT WINAPI domcdata_insertData( xmlNodeSetContent(This->node.node, str); hr = S_OK; } - HeapFree(GetProcessHeap(), 0, str); + heap_free(str); SysFreeString(sNewString); } @@ -684,8 +684,47 @@ static HRESULT WINAPI domcdata_deleteData( IXMLDOMCDATASection *iface, LONG offset, LONG count) { - FIXME("\n"); - return E_NOTIMPL; + HRESULT hr; + LONG len = -1; + BSTR str; + + TRACE("%p %d %d\n", iface, offset, count); + + hr = IXMLDOMCDATASection_get_length(iface, &len); + if(hr != S_OK) return hr; + + if((offset < 0) || (offset > len) || (count < 0)) + return E_INVALIDARG; + + if(len == 0) return S_OK; + + /* cutting start or end */ + if((offset == 0) || ((count + offset) >= len)) + { + if(offset == 0) + IXMLDOMCDATASection_substringData(iface, count, len - count, &str); + else + IXMLDOMCDATASection_substringData(iface, 0, offset, &str); + hr = IXMLDOMCDATASection_put_data(iface, str); + } + else + /* cutting from the inside */ + { + BSTR str_end; + + IXMLDOMCDATASection_substringData(iface, 0, offset, &str); + IXMLDOMCDATASection_substringData(iface, offset + count, len - count, &str_end); + + hr = IXMLDOMCDATASection_put_data(iface, str); + if(hr == S_OK) + hr = IXMLDOMCDATASection_appendData(iface, str_end); + + SysFreeString(str_end); + } + + SysFreeString(str); + + return hr; } static HRESULT WINAPI domcdata_replaceData( @@ -765,7 +804,7 @@ IUnknown* create_cdata( xmlNodePtr text ) { domcdata *This; - This = HeapAlloc( GetProcessHeap(), 0, sizeof *This ); + This = heap_alloc( sizeof *This ); if ( !This ) return NULL; diff --git a/reactos/dll/win32/msxml3/comment.c b/reactos/dll/win32/msxml3/comment.c index 09e3c8a4e18..1e3b965e84a 100644 --- a/reactos/dll/win32/msxml3/comment.c +++ b/reactos/dll/win32/msxml3/comment.c @@ -95,7 +95,7 @@ static ULONG WINAPI domcomment_Release( if ( ref == 0 ) { destroy_xmlnode(&This->node); - HeapFree( GetProcessHeap(), 0, This ); + heap_free( This ); } return ref; @@ -541,7 +541,7 @@ static HRESULT WINAPI domcomment_substringData( LONG nLength = 0; HRESULT hr = S_FALSE; - TRACE("%p\n", iface); + TRACE("%p %d %d %p\n", iface, offset, count, p); if(!p) return E_INVALIDARG; @@ -551,7 +551,7 @@ static HRESULT WINAPI domcomment_substringData( return E_INVALIDARG; if(count == 0) - return hr; + return S_FALSE; pContent = xmlNodeGetContent(This->node.node); if(pContent) @@ -630,7 +630,7 @@ static HRESULT WINAPI domcomment_insertData( LONG nLength = 0, nLengthP = 0; xmlChar *str = NULL; - TRACE("%p\n", This); + TRACE("%p %d %p\n", iface, offset, p); /* If have a NULL or empty string, don't do anything. */ if(SysStringLen(p) == 0) @@ -692,8 +692,47 @@ static HRESULT WINAPI domcomment_deleteData( IXMLDOMComment *iface, LONG offset, LONG count) { - FIXME("\n"); - return E_NOTIMPL; + HRESULT hr; + LONG len = -1; + BSTR str; + + TRACE("%p %d %d\n", iface, offset, count); + + hr = IXMLDOMComment_get_length(iface, &len); + if(hr != S_OK) return hr; + + if((offset < 0) || (offset > len) || (count < 0)) + return E_INVALIDARG; + + if(len == 0) return S_OK; + + /* cutting start or end */ + if((offset == 0) || ((count + offset) >= len)) + { + if(offset == 0) + IXMLDOMComment_substringData(iface, count, len - count, &str); + else + IXMLDOMComment_substringData(iface, 0, offset, &str); + hr = IXMLDOMComment_put_data(iface, str); + } + else + /* cutting from the inside */ + { + BSTR str_end; + + IXMLDOMComment_substringData(iface, 0, offset, &str); + IXMLDOMComment_substringData(iface, offset + count, len - count, &str_end); + + hr = IXMLDOMComment_put_data(iface, str); + if(hr == S_OK) + hr = IXMLDOMComment_appendData(iface, str_end); + + SysFreeString(str_end); + } + + SysFreeString(str); + + return hr; } static HRESULT WINAPI domcomment_replaceData( @@ -763,7 +802,7 @@ IUnknown* create_comment( xmlNodePtr comment ) { domcomment *This; - This = HeapAlloc( GetProcessHeap(), 0, sizeof *This ); + This = heap_alloc( sizeof *This ); if ( !This ) return NULL; diff --git a/reactos/dll/win32/msxml3/docfrag.c b/reactos/dll/win32/msxml3/docfrag.c index f5ac1aa7e55..b5f6e464799 100644 --- a/reactos/dll/win32/msxml3/docfrag.c +++ b/reactos/dll/win32/msxml3/docfrag.c @@ -94,7 +94,7 @@ static ULONG WINAPI domfrag_Release( if ( ref == 0 ) { destroy_xmlnode(&This->node); - HeapFree( GetProcessHeap(), 0, This ); + heap_free( This ); } return ref; @@ -519,7 +519,7 @@ IUnknown* create_doc_fragment( xmlNodePtr fragment ) { domfrag *This; - This = HeapAlloc( GetProcessHeap(), 0, sizeof *This ); + This = heap_alloc( sizeof *This ); if ( !This ) return NULL; diff --git a/reactos/dll/win32/msxml3/domdoc.c b/reactos/dll/win32/msxml3/domdoc.c index be19e566ff4..4914a7c0064 100644 --- a/reactos/dll/win32/msxml3/domdoc.c +++ b/reactos/dll/win32/msxml3/domdoc.c @@ -119,7 +119,7 @@ static inline xmldoc_priv * priv_from_xmlDocPtr(xmlDocPtr doc) static xmldoc_priv * create_priv(void) { xmldoc_priv *priv; - priv = HeapAlloc( GetProcessHeap(), 0, sizeof (*priv) ); + priv = heap_alloc( sizeof (*priv) ); if(priv) { @@ -164,9 +164,9 @@ LONG xmldoc_release(xmlDocPtr doc) LIST_FOR_EACH_ENTRY_SAFE( orphan, orphan2, &priv->orphans, orphan_entry, entry ) { xmlFreeNode( orphan->node ); - HeapFree( GetProcessHeap(), 0, orphan ); + heap_free( orphan ); } - HeapFree(GetProcessHeap(), 0, doc->_private); + heap_free(doc->_private); xmlFreeDoc(doc); } @@ -179,7 +179,7 @@ HRESULT xmldoc_add_orphan(xmlDocPtr doc, xmlNodePtr node) xmldoc_priv *priv = priv_from_xmlDocPtr(doc); orphan_entry *entry; - entry = HeapAlloc( GetProcessHeap(), 0, sizeof (*entry) ); + entry = heap_alloc( sizeof (*entry) ); if(!entry) return E_OUTOFMEMORY; @@ -198,7 +198,7 @@ HRESULT xmldoc_remove_orphan(xmlDocPtr doc, xmlNodePtr node) if( entry->node == node ) { list_remove( &entry->entry ); - HeapFree( GetProcessHeap(), 0, entry ); + heap_free( entry ); return S_OK; } } @@ -1041,7 +1041,7 @@ static HRESULT WINAPI domdoc_createElement( TRACE("created xmlptr %p\n", xmlnode); elem_unk = create_element(xmlnode); - HeapFree(GetProcessHeap(), 0, xml_name); + heap_free(xml_name); hr = IUnknown_QueryInterface(elem_unk, &IID_IXMLDOMElement, (void **)element); IUnknown_Release(elem_unk); @@ -1094,7 +1094,7 @@ static HRESULT WINAPI domdoc_createTextNode( xml_content = xmlChar_from_wchar(data); xmlnode = xmlNewText(xml_content); - HeapFree(GetProcessHeap(), 0, xml_content); + heap_free(xml_content); if(!xmlnode) return E_FAIL; @@ -1126,7 +1126,7 @@ static HRESULT WINAPI domdoc_createComment( xml_content = xmlChar_from_wchar(data); xmlnode = xmlNewComment(xml_content); - HeapFree(GetProcessHeap(), 0, xml_content); + heap_free(xml_content); if(!xmlnode) return E_FAIL; @@ -1158,7 +1158,7 @@ static HRESULT WINAPI domdoc_createCDATASection( xml_content = xmlChar_from_wchar(data); xmlnode = xmlNewCDataBlock(get_doc( This ), xml_content, strlen( (char*)xml_content) ); - HeapFree(GetProcessHeap(), 0, xml_content); + heap_free(xml_content); if(!xmlnode) return E_FAIL; @@ -1199,8 +1199,8 @@ static HRESULT WINAPI domdoc_createProcessingInstruction( TRACE("created xmlptr %p\n", xmlnode); *pi = (IXMLDOMProcessingInstruction*)create_pi(xmlnode); - HeapFree(GetProcessHeap(), 0, xml_content); - HeapFree(GetProcessHeap(), 0, xml_target); + heap_free(xml_content); + heap_free(xml_target); return S_OK; #else @@ -1228,7 +1228,7 @@ static HRESULT WINAPI domdoc_createAttribute( xml_name = xmlChar_from_wchar(name); xmlnode = (xmlNode *)xmlNewProp(NULL, xml_name, NULL); - HeapFree(GetProcessHeap(), 0, xml_name); + heap_free(xml_name); if(!xmlnode) return E_FAIL; @@ -1260,7 +1260,7 @@ static HRESULT WINAPI domdoc_createEntityReference( xml_name = xmlChar_from_wchar(name); xmlnode = xmlNewReference(get_doc( This ), xml_name ); - HeapFree(GetProcessHeap(), 0, xml_name); + heap_free(xml_name); if(!xmlnode) return E_FAIL; @@ -1279,17 +1279,28 @@ static HRESULT WINAPI domdoc_getElementsByTagName( BSTR tagName, IXMLDOMNodeList** resultList ) { + static const WCHAR xpathformat[] = + { '/','/','*','[','l','o','c','a','l','-','n','a','m','e','(',')','=','\'','%','s','\'',']',0 }; domdoc *This = impl_from_IXMLDOMDocument2( iface ); LPWSTR szPattern; HRESULT hr; TRACE("(%p)->(%s, %p)\n", This, debugstr_w(tagName), resultList); - szPattern = HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR)*(2+lstrlenW(tagName)+1)); - szPattern[0] = szPattern[1] = '/'; - lstrcpyW(szPattern + 2, tagName); + if (tagName[0] == '*' && tagName[1] == 0) + { + szPattern = heap_alloc(sizeof(WCHAR)*4); + szPattern[0] = szPattern[1] = '/'; + szPattern[2] = '*'; + szPattern[3] = 0; + } + else + { + szPattern = heap_alloc(sizeof(WCHAR)*(20+lstrlenW(tagName)+1)); + wsprintfW(szPattern, xpathformat, tagName); + } hr = queryresult_create((xmlNodePtr)get_doc(This), szPattern, resultList); - HeapFree(GetProcessHeap(), 0, szPattern); + heap_free(szPattern); return hr; } @@ -1359,7 +1370,7 @@ static HRESULT WINAPI domdoc_createNode( break; } - HeapFree(GetProcessHeap(), 0, xml_name); + heap_free(xml_name); if(xmlnode && *node) { @@ -1588,7 +1599,7 @@ static BOOL bstr_to_utf8( BSTR bstr, char **pstr, int *plen ) LPSTR str; len = WideCharToMultiByte( CP_UTF8, 0, bstr, blen, NULL, 0, NULL, NULL ); - str = HeapAlloc( GetProcessHeap(), 0, len ); + str = heap_alloc( len ); if ( !str ) return FALSE; WideCharToMultiByte( CP_UTF8, 0, bstr, blen, str, len, NULL, NULL ); @@ -1619,7 +1630,7 @@ static HRESULT WINAPI domdoc_loadXML( if ( bstrXML && bstr_to_utf8( bstrXML, &str, &len ) ) { xmldoc = doparse( str, len ); - HeapFree( GetProcessHeap(), 0, str ); + heap_free( str ); if ( !xmldoc ) This->error = E_FAIL; else @@ -2193,7 +2204,7 @@ HRESULT DOMDocument_create_from_xmldoc(xmlDocPtr xmldoc, IXMLDOMDocument2 **docu { domdoc *doc; - doc = HeapAlloc( GetProcessHeap(), 0, sizeof (*doc) ); + doc = heap_alloc( sizeof (*doc) ); if( !doc ) return E_OUTOFMEMORY; diff --git a/reactos/dll/win32/msxml3/domimpl.c b/reactos/dll/win32/msxml3/domimpl.c index b0b1cdead0e..1a07676e33f 100644 --- a/reactos/dll/win32/msxml3/domimpl.c +++ b/reactos/dll/win32/msxml3/domimpl.c @@ -89,7 +89,7 @@ static ULONG WINAPI dimimpl_Release( ref = InterlockedDecrement( &This->ref ); if ( ref == 0 ) { - HeapFree( GetProcessHeap(), 0, This ); + heap_free( This ); } return ref; @@ -216,7 +216,7 @@ IUnknown* create_doc_Implementation(void) { domimpl *This; - This = HeapAlloc( GetProcessHeap(), 0, sizeof *This ); + This = heap_alloc( sizeof *This ); if ( !This ) return NULL; diff --git a/reactos/dll/win32/msxml3/element.c b/reactos/dll/win32/msxml3/element.c index 63bf7af1d4b..f7bd3b03e08 100644 --- a/reactos/dll/win32/msxml3/element.c +++ b/reactos/dll/win32/msxml3/element.c @@ -502,7 +502,7 @@ static HRESULT WINAPI domelem_get_tagName( len = MultiByteToWideChar( CP_UTF8, 0, (LPCSTR) element->name, -1, NULL, 0 ); if (element->ns) len += MultiByteToWideChar( CP_UTF8, 0, (LPCSTR) element->ns->prefix, -1, NULL, 0 ); - str = HeapAlloc( GetProcessHeap(), 0, len * sizeof (WCHAR) ); + str = heap_alloc( len * sizeof (WCHAR) ); if ( !str ) return E_OUTOFMEMORY; if (element->ns) @@ -512,7 +512,7 @@ static HRESULT WINAPI domelem_get_tagName( } MultiByteToWideChar( CP_UTF8, 0, (LPCSTR) element->name, -1, str + offset, len - offset ); *p = SysAllocString( str ); - HeapFree( GetProcessHeap(), 0, str ); + heap_free( str ); return S_OK; } @@ -545,7 +545,7 @@ static HRESULT WINAPI domelem_getAttribute( else xml_value = xmlGetNsProp(element, xml_name, NULL); - HeapFree(GetProcessHeap(), 0, xml_name); + heap_free(xml_name); if(xml_value) { V_VT(value) = VT_BSTR; @@ -587,8 +587,8 @@ static HRESULT WINAPI domelem_setAttribute( if(!xmlSetNsProp(element, NULL, xml_name, xml_value)) hr = E_FAIL; - HeapFree(GetProcessHeap(), 0, xml_value); - HeapFree(GetProcessHeap(), 0, xml_name); + heap_free(xml_value); + heap_free(xml_name); VariantClear(&var); return hr; @@ -598,8 +598,19 @@ static HRESULT WINAPI domelem_removeAttribute( IXMLDOMElement *iface, BSTR p) { - FIXME("\n"); - return E_NOTIMPL; + domelem *This = impl_from_IXMLDOMElement( iface ); + IXMLDOMNamedNodeMap *attr; + HRESULT hr; + + TRACE("(%p)->(%s)", This, debugstr_w(p)); + + hr = IXMLDOMElement_get_attributes(iface, &attr); + if (hr != S_OK) return hr; + + hr = IXMLDOMNamedNodeMap_removeNamedItem(attr, p, NULL); + IXMLDOMNamedNodeMap_Release(attr); + + return hr; } static HRESULT WINAPI domelem_getAttributeNode( @@ -628,7 +639,7 @@ static HRESULT WINAPI domelem_getAttributeNode( if(!xmlValidateNameValue(xml_name)) { - HeapFree(GetProcessHeap(), 0, xml_name); + heap_free(xml_name); return E_FAIL; } @@ -639,7 +650,7 @@ static HRESULT WINAPI domelem_getAttributeNode( IUnknown_Release(unk); } - HeapFree(GetProcessHeap(), 0, xml_name); + heap_free(xml_name); return hr; } @@ -666,6 +677,8 @@ static HRESULT WINAPI domelem_getElementsByTagName( IXMLDOMElement *iface, BSTR bstrName, IXMLDOMNodeList** resultList) { + static const WCHAR xpathformat[] = + { '.','/','/','*','[','l','o','c','a','l','-','n','a','m','e','(',')','=','\'','%','s','\'',']',0 }; domelem *This = impl_from_IXMLDOMElement( iface ); LPWSTR szPattern; xmlNodePtr element; @@ -673,10 +686,19 @@ static HRESULT WINAPI domelem_getElementsByTagName( TRACE("(%p)->(%s,%p)\n", This, debugstr_w(bstrName), resultList); - szPattern = HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR)*(3+lstrlenW(bstrName)+1)); - szPattern[0] = '.'; - szPattern[1] = szPattern[2] = '/'; - lstrcpyW(szPattern+3, bstrName); + if (bstrName[0] == '*' && bstrName[1] == 0) + { + szPattern = heap_alloc(sizeof(WCHAR)*5); + szPattern[0] = '.'; + szPattern[1] = szPattern[2] = '/'; + szPattern[3] = '*'; + szPattern[4] = 0; + } + else + { + szPattern = heap_alloc(sizeof(WCHAR)*(21+lstrlenW(bstrName)+1)); + wsprintfW(szPattern, xpathformat, bstrName); + } TRACE("%s\n", debugstr_w(szPattern)); element = get_element(This); @@ -684,7 +706,7 @@ static HRESULT WINAPI domelem_getElementsByTagName( hr = E_FAIL; else hr = queryresult_create(element, szPattern, resultList); - HeapFree(GetProcessHeap(), 0, szPattern); + heap_free(szPattern); return hr; } @@ -768,7 +790,7 @@ IUnknown* create_element( xmlNodePtr element ) { domelem *This; - This = HeapAlloc( GetProcessHeap(), 0, sizeof *This ); + This = heap_alloc( sizeof *This ); if ( !This ) return NULL; diff --git a/reactos/dll/win32/msxml3/entityref.c b/reactos/dll/win32/msxml3/entityref.c index 7ba06c3d09b..1489dbd0c57 100644 --- a/reactos/dll/win32/msxml3/entityref.c +++ b/reactos/dll/win32/msxml3/entityref.c @@ -94,7 +94,7 @@ static ULONG WINAPI entityref_Release( if ( ref == 0 ) { destroy_xmlnode(&This->node); - HeapFree( GetProcessHeap(), 0, This ); + heap_free( This ); } return ref; @@ -518,7 +518,7 @@ IUnknown* create_doc_entity_ref( xmlNodePtr entity ) { entityref *This; - This = HeapAlloc( GetProcessHeap(), 0, sizeof *This ); + This = heap_alloc( sizeof *This ); if ( !This ) return NULL; diff --git a/reactos/dll/win32/msxml3/factory.c b/reactos/dll/win32/msxml3/factory.c index 37dfe01afcc..45ba3680c0f 100644 --- a/reactos/dll/win32/msxml3/factory.c +++ b/reactos/dll/win32/msxml3/factory.c @@ -147,7 +147,8 @@ HRESULT WINAPI DllGetClassObject( REFCLSID rclsid, REFIID iid, LPVOID *ppv ) if( IsEqualCLSID( rclsid, &CLSID_DOMDocument ) || /* Version indep. v 2.x */ IsEqualCLSID( rclsid, &CLSID_DOMDocument2 ) || /* Version indep. v 3.0 */ - IsEqualCLSID( rclsid, &CLSID_DOMDocument30 ) ) /* Version dep. v 3.0 */ + IsEqualCLSID( rclsid, &CLSID_DOMDocument30 )|| /* Version dep. v 3.0 */ + IsEqualCLSID( rclsid, &CLSID_DOMDocument40 )) /* Version dep. v 4.0 */ { cf = (IClassFactory*) &domdoccf.lpVtbl; } diff --git a/reactos/dll/win32/msxml3/httprequest.c b/reactos/dll/win32/msxml3/httprequest.c index bc0fe7c3fb2..a477753a71a 100644 --- a/reactos/dll/win32/msxml3/httprequest.c +++ b/reactos/dll/win32/msxml3/httprequest.c @@ -83,7 +83,7 @@ static ULONG WINAPI httprequest_Release(IXMLHTTPRequest *iface) ref = InterlockedDecrement( &This->ref ); if ( ref == 0 ) { - HeapFree( GetProcessHeap(), 0, This ); + heap_free( This ); } return ref; @@ -317,7 +317,7 @@ HRESULT XMLHTTPRequest_create(IUnknown *pUnkOuter, LPVOID *ppObj) TRACE("(%p,%p)\n", pUnkOuter, ppObj); - req = HeapAlloc( GetProcessHeap(), 0, sizeof (*req) ); + req = heap_alloc( sizeof (*req) ); if( !req ) return E_OUTOFMEMORY; diff --git a/reactos/dll/win32/msxml3/msxml_private.h b/reactos/dll/win32/msxml3/msxml_private.h index d62a8a467d2..e46642d84b6 100644 --- a/reactos/dll/win32/msxml3/msxml_private.h +++ b/reactos/dll/win32/msxml3/msxml_private.h @@ -135,7 +135,7 @@ extern LONG xmldoc_release( xmlDocPtr doc ); extern HRESULT xmldoc_add_orphan( xmlDocPtr doc, xmlNodePtr node ); extern HRESULT xmldoc_remove_orphan( xmlDocPtr doc, xmlNodePtr node ); -extern HRESULT XMLElement_create( IUnknown *pUnkOuter, xmlNodePtr node, LPVOID *ppObj ); +extern HRESULT XMLElement_create( IUnknown *pUnkOuter, xmlNodePtr node, LPVOID *ppObj, BOOL own ); extern xmlDocPtr parse_xml(char *ptr, int len); diff --git a/reactos/dll/win32/msxml3/node.c b/reactos/dll/win32/msxml3/node.c index 82f4c5678f2..6729512d69e 100644 --- a/reactos/dll/win32/msxml3/node.c +++ b/reactos/dll/win32/msxml3/node.c @@ -130,7 +130,7 @@ static ULONG WINAPI xmlnode_Release( ref = InterlockedDecrement( &This->ref ); if(!ref) { destroy_xmlnode(This); - HeapFree( GetProcessHeap(), 0, This ); + heap_free( This ); } return ref; @@ -354,7 +354,7 @@ static HRESULT WINAPI xmlnode_put_nodeValue( { str = xmlChar_from_wchar(V_BSTR(&string_value)); xmlNodeSetContent(This->node, str); - HeapFree(GetProcessHeap(),0,str); + heap_free(str); hr = S_OK; break; } @@ -920,7 +920,7 @@ static HRESULT WINAPI xmlnode_put_text( /* Escape the string. */ str2 = xmlEncodeEntitiesReentrant(This->node->doc, str); - HeapFree(GetProcessHeap(), 0, str); + heap_free(str); xmlNodeSetContent(This->node, str2); xmlFree(str2); @@ -1284,7 +1284,7 @@ static HRESULT WINAPI xmlnode_put_dataType( else ERR("Failed to Create Namepsace\n"); } - HeapFree( GetProcessHeap(), 0, str ); + heap_free( str ); } return hr; diff --git a/reactos/dll/win32/msxml3/nodelist.c b/reactos/dll/win32/msxml3/nodelist.c index e4ae604a5b9..011fff0bf61 100644 --- a/reactos/dll/win32/msxml3/nodelist.c +++ b/reactos/dll/win32/msxml3/nodelist.c @@ -104,7 +104,7 @@ static ULONG WINAPI xmlnodelist_Release( if ( ref == 0 ) { xmldoc_release( This->parent->doc ); - HeapFree( GetProcessHeap(), 0, This ); + heap_free( This ); } return ref; @@ -314,7 +314,7 @@ IXMLDOMNodeList* create_children_nodelist( xmlNodePtr node ) { xmlnodelist *nodelist; - nodelist = HeapAlloc( GetProcessHeap(), 0, sizeof *nodelist ); + nodelist = heap_alloc( sizeof *nodelist ); if ( !nodelist ) return NULL; diff --git a/reactos/dll/win32/msxml3/nodemap.c b/reactos/dll/win32/msxml3/nodemap.c index 825abef3149..91f7a323e5e 100644 --- a/reactos/dll/win32/msxml3/nodemap.c +++ b/reactos/dll/win32/msxml3/nodemap.c @@ -102,7 +102,7 @@ static ULONG WINAPI xmlnodemap_Release( if ( ref == 0 ) { IXMLDOMNode_Release( This->node ); - HeapFree( GetProcessHeap(), 0, This ); + heap_free( This ); } return ref; @@ -191,7 +191,7 @@ xmlChar *xmlChar_from_wchar( LPWSTR str ) xmlChar *xmlstr; len = WideCharToMultiByte( CP_UTF8, 0, str, -1, NULL, 0, NULL, NULL ); - xmlstr = HeapAlloc( GetProcessHeap(), 0, len ); + xmlstr = heap_alloc( len ); if ( xmlstr ) WideCharToMultiByte( CP_UTF8, 0, str, -1, (LPSTR) xmlstr, len, NULL, NULL ); return xmlstr; @@ -218,7 +218,7 @@ static HRESULT WINAPI xmlnodemap_getNamedItem( element_name = xmlChar_from_wchar( name ); attr = xmlHasNsProp( node, element_name, NULL ); - HeapFree( GetProcessHeap(), 0, element_name ); + heap_free( element_name ); if ( !attr ) { @@ -303,7 +303,7 @@ static HRESULT WINAPI xmlnodemap_removeNamedItem( element_name = xmlChar_from_wchar( name ); attr = xmlHasNsProp( node, element_name, NULL ); - HeapFree( GetProcessHeap(), 0, element_name ); + heap_free( element_name ); if ( !attr ) { @@ -531,7 +531,7 @@ IXMLDOMNamedNodeMap *create_nodemap( IXMLDOMNode *node ) { xmlnodemap *nodemap; - nodemap = HeapAlloc( GetProcessHeap(), 0, sizeof *nodemap ); + nodemap = heap_alloc( sizeof *nodemap ); if ( !nodemap ) return NULL; diff --git a/reactos/dll/win32/msxml3/parseerror.c b/reactos/dll/win32/msxml3/parseerror.c index b78f82915e9..40b17a0f3d9 100644 --- a/reactos/dll/win32/msxml3/parseerror.c +++ b/reactos/dll/win32/msxml3/parseerror.c @@ -97,7 +97,7 @@ static ULONG WINAPI parseError_Release( SysFreeString(This->url); SysFreeString(This->reason); SysFreeString(This->srcText); - HeapFree( GetProcessHeap(), 0, This ); + heap_free( This ); } return ref; @@ -283,7 +283,7 @@ IXMLDOMParseError *create_parseError( LONG code, BSTR url, BSTR reason, BSTR src { parse_error_t *This; - This = HeapAlloc( GetProcessHeap(), 0, sizeof(*This) ); + This = heap_alloc( sizeof(*This) ); if ( !This ) return NULL; diff --git a/reactos/dll/win32/msxml3/pi.c b/reactos/dll/win32/msxml3/pi.c index e814b8d1910..f32cebf8300 100644 --- a/reactos/dll/win32/msxml3/pi.c +++ b/reactos/dll/win32/msxml3/pi.c @@ -94,7 +94,7 @@ static ULONG WINAPI dom_pi_Release( if ( ref == 0 ) { destroy_xmlnode(&This->node); - HeapFree( GetProcessHeap(), 0, This ); + heap_free( This ); } return ref; @@ -604,7 +604,7 @@ IUnknown* create_pi( xmlNodePtr pi ) { dom_pi *This; - This = HeapAlloc( GetProcessHeap(), 0, sizeof *This ); + This = heap_alloc( sizeof *This ); if ( !This ) return NULL; diff --git a/reactos/dll/win32/msxml3/queryresult.c b/reactos/dll/win32/msxml3/queryresult.c index 50e8b79a83f..ab545968c08 100644 --- a/reactos/dll/win32/msxml3/queryresult.c +++ b/reactos/dll/win32/msxml3/queryresult.c @@ -413,7 +413,7 @@ cleanup: IXMLDOMNodeList_Release( (IXMLDOMNodeList*) &This->lpVtbl ); if (ctxt != NULL) xmlXPathFreeContext(ctxt); - HeapFree(GetProcessHeap(), 0, str); + heap_free(str); return hr; } diff --git a/reactos/dll/win32/msxml3/regsvr.c b/reactos/dll/win32/msxml3/regsvr.c index c8ae753c47d..d9b47dde89b 100644 --- a/reactos/dll/win32/msxml3/regsvr.c +++ b/reactos/dll/win32/msxml3/regsvr.c @@ -47,7 +47,7 @@ #include "wine/debug.h" #include "wine/unicode.h" -WINE_DEFAULT_DEBUG_CHANNEL(ole); +WINE_DEFAULT_DEBUG_CHANNEL(msxml); /* * Near the bottom of this file are the exported DllRegisterServer and @@ -702,7 +702,7 @@ static struct progid const progid_list[] = { }; /*********************************************************************** - * DllRegisterServer (OLEAUT32.@) + * DllRegisterServer (MSXML3.@) */ HRESULT WINAPI DllRegisterServer(void) { @@ -729,7 +729,7 @@ HRESULT WINAPI DllRegisterServer(void) } /*********************************************************************** - * DllUnregisterServer (OLEAUT32.@) + * DllUnregisterServer (MSXML3.@) */ HRESULT WINAPI DllUnregisterServer(void) { diff --git a/reactos/dll/win32/msxml3/saxreader.c b/reactos/dll/win32/msxml3/saxreader.c index 90600eb5a08..a3de7571694 100644 --- a/reactos/dll/win32/msxml3/saxreader.c +++ b/reactos/dll/win32/msxml3/saxreader.c @@ -126,6 +126,11 @@ static inline saxattributes *impl_from_ISAXAttributes( ISAXAttributes *iface ) return (saxattributes *)((char*)iface - FIELD_OFFSET(saxattributes, lpSAXAttributesVtbl)); } +static inline BOOL has_content_handler(const saxlocator *locator) +{ + return (locator->vbInterface && locator->saxreader->vbcontentHandler) || + (!locator->vbInterface && locator->saxreader->contentHandler); +} static HRESULT namespacePush(saxlocator *locator, int ns) { @@ -161,13 +166,13 @@ static BSTR bstr_from_xmlCharN(const xmlChar *buf, int len) dLen = MultiByteToWideChar(CP_UTF8, 0, (LPCSTR)buf, len, NULL, 0); if(len != -1) dLen++; - str = HeapAlloc(GetProcessHeap(), 0, dLen * sizeof (WCHAR)); + str = heap_alloc(dLen * sizeof (WCHAR)); if (!str) return NULL; MultiByteToWideChar(CP_UTF8, 0, (LPCSTR)buf, len, str, dLen); if(len != -1) str[dLen-1] = '\0'; bstr = SysAllocString(str); - HeapFree(GetProcessHeap(), 0, str); + heap_free(str); return bstr; } @@ -185,7 +190,7 @@ static BSTR QName_from_xmlChar(const xmlChar *prefix, const xmlChar *name) dLen = MultiByteToWideChar(CP_UTF8, 0, (LPCSTR)prefix, -1, NULL, 0) + MultiByteToWideChar(CP_UTF8, 0, (LPCSTR)name, -1, NULL, 0); - str = HeapAlloc(GetProcessHeap(), 0, dLen * sizeof(WCHAR)); + str = heap_alloc(dLen * sizeof(WCHAR)); if(!str) return NULL; @@ -194,7 +199,7 @@ static BSTR QName_from_xmlChar(const xmlChar *prefix, const xmlChar *name) MultiByteToWideChar(CP_UTF8, 0, (LPCSTR)name, -1, &str[dLast], dLen-dLast); bstr = SysAllocString(str); - HeapFree(GetProcessHeap(), 0, str); + heap_free(str); return bstr; } @@ -624,12 +629,12 @@ static ULONG WINAPI isaxattributes_Release(ISAXAttributes* iface) SysFreeString(This->szQName[index]); } - HeapFree(GetProcessHeap(), 0, This->szLocalname); - HeapFree(GetProcessHeap(), 0, This->szURI); - HeapFree(GetProcessHeap(), 0, This->szValue); - HeapFree(GetProcessHeap(), 0, This->szQName); + heap_free(This->szLocalname); + heap_free(This->szURI); + heap_free(This->szValue); + heap_free(This->szQName); - HeapFree(GetProcessHeap(), 0, This); + heap_free(This); } return ref; @@ -914,7 +919,7 @@ static HRESULT SAXAttributes_create(saxattributes **attr, int index; static const xmlChar xmlns[] = "xmlns"; - attributes = HeapAlloc(GetProcessHeap(), 0, sizeof(*attributes)); + attributes = heap_alloc(sizeof(*attributes)); if(!attributes) return E_OUTOFMEMORY; @@ -924,23 +929,19 @@ static HRESULT SAXAttributes_create(saxattributes **attr, attributes->nb_attributes = nb_namespaces+nb_attributes; - attributes->szLocalname = - HeapAlloc(GetProcessHeap(), 0, sizeof(BSTR)*attributes->nb_attributes); - attributes->szURI = - HeapAlloc(GetProcessHeap(), 0, sizeof(BSTR)*attributes->nb_attributes); - attributes->szValue = - HeapAlloc(GetProcessHeap(), 0, sizeof(BSTR)*attributes->nb_attributes); - attributes->szQName = - HeapAlloc(GetProcessHeap(), 0, sizeof(BSTR)*attributes->nb_attributes); + attributes->szLocalname = heap_alloc(sizeof(BSTR)*attributes->nb_attributes); + attributes->szURI = heap_alloc(sizeof(BSTR)*attributes->nb_attributes); + attributes->szValue = heap_alloc(sizeof(BSTR)*attributes->nb_attributes); + attributes->szQName = heap_alloc(sizeof(BSTR)*attributes->nb_attributes); if(!attributes->szLocalname || !attributes->szURI || !attributes->szValue || !attributes->szQName) { - HeapFree(GetProcessHeap(), 0, attributes->szLocalname); - HeapFree(GetProcessHeap(), 0, attributes->szURI); - HeapFree(GetProcessHeap(), 0, attributes->szValue); - HeapFree(GetProcessHeap(), 0, attributes->szQName); - HeapFree(GetProcessHeap(), 0, attributes); + heap_free(attributes->szLocalname); + heap_free(attributes->szURI); + heap_free(attributes->szValue); + heap_free(attributes->szQName); + heap_free(attributes); return E_FAIL; } @@ -978,8 +979,7 @@ static void libxmlStartDocument(void *ctx) saxlocator *This = ctx; HRESULT hr; - if((This->vbInterface && This->saxreader->vbcontentHandler) - || (!This->vbInterface && This->saxreader->contentHandler)) + if(has_content_handler(This)) { if(This->vbInterface) hr = IVBSAXContentHandler_startDocument(This->saxreader->vbcontentHandler); @@ -1003,8 +1003,7 @@ static void libxmlEndDocument(void *ctx) if(This->ret != S_OK) return; - if((This->vbInterface && This->saxreader->vbcontentHandler) - || (!This->vbInterface && This->saxreader->contentHandler)) + if(has_content_handler(This)) { if(This->vbInterface) hr = IVBSAXContentHandler_endDocument(This->saxreader->vbcontentHandler); @@ -1039,8 +1038,7 @@ static void libxmlStartElementNS( update_position(This, (xmlChar*)This->pParserCtxt->input->cur+1); hr = namespacePush(This, nb_namespaces); - if(hr==S_OK && ((This->vbInterface && This->saxreader->vbcontentHandler) - || (!This->vbInterface && This->saxreader->contentHandler))) + if(hr==S_OK && has_content_handler(This)) { for(index=0; indexvbInterface && This->saxreader->vbcontentHandler) - || (!This->vbInterface && This->saxreader->contentHandler)) + if(has_content_handler(This)) { NamespaceUri = bstr_from_xmlChar(URI); LocalName = bstr_from_xmlChar(localname); @@ -1186,9 +1183,7 @@ static void libxmlCharacters( xmlChar *end; BOOL lastEvent = FALSE; - if((This->vbInterface && !This->saxreader->vbcontentHandler) - || (!This->vbInterface && !This->saxreader->contentHandler)) - return; + if(!(has_content_handler(This))) return; cur = (xmlChar*)ch; if(*(ch-1)=='\r') cur--; @@ -1320,7 +1315,7 @@ static void libxmlFatalError(void *ctx, const char *msg, ...) va_end(args); len = MultiByteToWideChar(CP_UNIXCP, 0, message, -1, NULL, 0); - wszError = HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR)*len); + wszError = heap_alloc(sizeof(WCHAR)*len); if(wszError) MultiByteToWideChar(CP_UNIXCP, 0, message, -1, wszError, len); @@ -1334,7 +1329,7 @@ static void libxmlFatalError(void *ctx, const char *msg, ...) ISAXErrorHandler_fatalError(This->saxreader->errorHandler, (ISAXLocator*)&This->lpSAXLocatorVtbl, wszError, E_FAIL); - HeapFree(GetProcessHeap(), 0, wszError); + heap_free(wszError); xmlStopParser(This->pParserCtxt); This->ret = E_FAIL; @@ -1384,8 +1379,7 @@ static void libxmlCDataBlock(void *ctx, const xmlChar *value, int len) if(change) *end = '\n'; - if((This->vbInterface && This->saxreader->vbcontentHandler) || - (!This->vbInterface && This->saxreader->contentHandler)) + if(has_content_handler(This)) { Chars = bstr_from_xmlCharN(cur, end-cur+1); if(This->vbInterface) @@ -1645,10 +1639,10 @@ static ULONG WINAPI isaxlocator_Release( { SysFreeString(This->publicId); SysFreeString(This->systemId); - HeapFree(GetProcessHeap(), 0, This->nsStack); + heap_free(This->nsStack); ISAXXMLReader_Release((ISAXXMLReader*)&This->saxreader->lpSAXXMLReaderVtbl); - HeapFree( GetProcessHeap(), 0, This ); + heap_free( This ); } return ref; @@ -1734,7 +1728,7 @@ static HRESULT SAXLocator_create(saxreader *reader, saxlocator **ppsaxlocator, B { saxlocator *locator; - locator = HeapAlloc( GetProcessHeap(), 0, sizeof (*locator) ); + locator = heap_alloc( sizeof (*locator) ); if( !locator ) return E_OUTOFMEMORY; @@ -1755,11 +1749,11 @@ static HRESULT SAXLocator_create(saxreader *reader, saxlocator **ppsaxlocator, B locator->ret = S_OK; locator->nsStackSize = 8; locator->nsStackLast = 0; - locator->nsStack = HeapAlloc(GetProcessHeap(), 0, locator->nsStackSize); + locator->nsStack = heap_alloc(locator->nsStackSize); if(!locator->nsStack) { ISAXXMLReader_Release((ISAXXMLReader*)&reader->lpSAXXMLReaderVtbl); - HeapFree(GetProcessHeap(), 0, locator); + heap_free(locator); return E_OUTOFMEMORY; } @@ -1787,6 +1781,7 @@ static HRESULT internal_parseBuffer(saxreader *This, const char *buffer, int siz return E_FAIL; } + xmlFree(locator->pParserCtxt->sax); locator->pParserCtxt->sax = &locator->saxreader->sax; locator->pParserCtxt->userData = locator; @@ -1852,7 +1847,6 @@ static HRESULT internal_parseStream(saxreader *This, IStream *stream, BOOL vbInt } This->isParsing = FALSE; - locator->pParserCtxt->sax = NULL; xmlFreeParserCtxt(locator->pParserCtxt); locator->pParserCtxt = NULL; ISAXLocator_Release((ISAXLocator*)&locator->lpSAXLocatorVtbl); @@ -2045,6 +2039,7 @@ static HRESULT internal_parse( hr = internal_parseBuffer(This, (const char*)bstrData, SysStringByteLen(bstrData), vbInterface); IXMLDOMDocument_Release(xmlDoc); + SysFreeString(bstrData); break; } if(IUnknown_QueryInterface(V_UNKNOWN(&varInput), @@ -2315,7 +2310,7 @@ static ULONG WINAPI saxxmlreader_Release( if(This->vbdeclHandler) IVBSAXDeclHandler_Release(This->vbdeclHandler); - HeapFree( GetProcessHeap(), 0, This ); + heap_free( This ); } return ref; @@ -2810,7 +2805,7 @@ HRESULT SAXXMLReader_create(IUnknown *pUnkOuter, LPVOID *ppObj) TRACE("(%p,%p)\n", pUnkOuter, ppObj); - reader = HeapAlloc( GetProcessHeap(), 0, sizeof (*reader) ); + reader = heap_alloc( sizeof (*reader) ); if( !reader ) return E_OUTOFMEMORY; diff --git a/reactos/dll/win32/msxml3/schema.c b/reactos/dll/win32/msxml3/schema.c index e71586e421a..f0a616979a0 100644 --- a/reactos/dll/win32/msxml3/schema.c +++ b/reactos/dll/win32/msxml3/schema.c @@ -86,7 +86,7 @@ static ULONG WINAPI schema_cache_Release( IXMLDOMSchemaCollection *iface ) if ( ref == 0 ) { - HeapFree( GetProcessHeap(), 0, This ); + heap_free( This ); } return ref; @@ -233,7 +233,7 @@ static const struct IXMLDOMSchemaCollectionVtbl schema_vtbl = HRESULT SchemaCache_create(IUnknown *pUnkOuter, LPVOID *ppObj) { - schema_t *schema = HeapAlloc( GetProcessHeap(), 0, sizeof (*schema) ); + schema_t *schema = heap_alloc( sizeof (*schema) ); if( !schema ) return E_OUTOFMEMORY; diff --git a/reactos/dll/win32/msxml3/text.c b/reactos/dll/win32/msxml3/text.c index 6380a0e50ce..70ca3efee33 100644 --- a/reactos/dll/win32/msxml3/text.c +++ b/reactos/dll/win32/msxml3/text.c @@ -103,7 +103,7 @@ static ULONG WINAPI domtext_Release( if ( ref == 0 ) { destroy_xmlnode(&This->node); - HeapFree( GetProcessHeap(), 0, This ); + heap_free( This ); } return ref; @@ -605,7 +605,7 @@ static HRESULT WINAPI domtext_appendData( hr = S_OK; else hr = E_FAIL; - HeapFree( GetProcessHeap(), 0, pContent ); + heap_free( pContent ); } else hr = E_FAIL; @@ -669,7 +669,7 @@ static HRESULT WINAPI domtext_insertData( xmlNodeSetContent(This->node.node, str); hr = S_OK; } - HeapFree(GetProcessHeap(), 0, str); + heap_free(str); SysFreeString(sNewString); } @@ -686,8 +686,47 @@ static HRESULT WINAPI domtext_deleteData( IXMLDOMText *iface, LONG offset, LONG count) { - FIXME("\n"); - return E_NOTIMPL; + HRESULT hr; + LONG len = -1; + BSTR str; + + TRACE("%p %d %d\n", iface, offset, count); + + hr = IXMLDOMText_get_length(iface, &len); + if(hr != S_OK) return hr; + + if((offset < 0) || (offset > len) || (count < 0)) + return E_INVALIDARG; + + if(len == 0) return S_OK; + + /* cutting start or end */ + if((offset == 0) || ((count + offset) >= len)) + { + if(offset == 0) + IXMLDOMText_substringData(iface, count, len - count, &str); + else + IXMLDOMText_substringData(iface, 0, offset, &str); + hr = IXMLDOMText_put_data(iface, str); + } + else + /* cutting from the inside */ + { + BSTR str_end; + + IXMLDOMText_substringData(iface, 0, offset, &str); + IXMLDOMText_substringData(iface, offset + count, len - count, &str_end); + + hr = IXMLDOMText_put_data(iface, str); + if(hr == S_OK) + hr = IXMLDOMText_appendData(iface, str_end); + + SysFreeString(str_end); + } + + SysFreeString(str); + + return hr; } static HRESULT WINAPI domtext_replaceData( @@ -767,7 +806,7 @@ IUnknown* create_text( xmlNodePtr text ) { domtext *This; - This = HeapAlloc( GetProcessHeap(), 0, sizeof *This ); + This = heap_alloc( sizeof *This ); if ( !This ) return NULL; diff --git a/reactos/dll/win32/msxml3/xmldoc.c b/reactos/dll/win32/msxml3/xmldoc.c index 1a8c89404c5..d1a010f6485 100644 --- a/reactos/dll/win32/msxml3/xmldoc.c +++ b/reactos/dll/win32/msxml3/xmldoc.c @@ -54,7 +54,6 @@ typedef struct _xmldoc HRESULT error; /* IXMLDocument */ - IXMLElement *root; xmlDocPtr xmldoc; /* IPersistStream */ @@ -118,7 +117,7 @@ static ULONG WINAPI xmldoc_Release(IXMLDocument *iface) { xmlFreeDoc(This->xmldoc); if (This->stream) IStream_Release(This->stream); - HeapFree(GetProcessHeap(), 0, This); + heap_free(This); } return ref; @@ -198,17 +197,19 @@ static HRESULT WINAPI xmldoc_Invoke(IXMLDocument *iface, DISPID dispIdMember, static HRESULT WINAPI xmldoc_get_root(IXMLDocument *iface, IXMLElement **p) { xmldoc *This = impl_from_IXMLDocument(iface); + xmlNodePtr root; TRACE("(%p, %p)\n", iface, p); if (!p) return E_INVALIDARG; - *p = This->root; - if (!*p) + *p = NULL; + + if (!(root = xmlDocGetRootElement(This->xmldoc))) return E_FAIL; - return S_OK; + return XMLElement_create((IUnknown *)This, root, (LPVOID *)p, FALSE); } static HRESULT WINAPI xmldoc_get_fileSize(IXMLDocument *iface, BSTR *p) @@ -439,14 +440,32 @@ static HRESULT WINAPI xmldoc_put_charset(IXMLDocument *iface, BSTR p) static HRESULT WINAPI xmldoc_get_version(IXMLDocument *iface, BSTR *p) { - FIXME("(%p, %p): stub\n", iface, p); - return E_NOTIMPL; + xmldoc *This = impl_from_IXMLDocument(iface); + + TRACE("(%p, %p)\n", This, p); + + if (!p) return E_INVALIDARG; + *p = bstr_from_xmlChar(This->xmldoc->version); + + return S_OK; } static HRESULT WINAPI xmldoc_get_doctype(IXMLDocument *iface, BSTR *p) { - FIXME("(%p, %p): stub\n", iface, p); - return E_NOTIMPL; + xmldoc *This = impl_from_IXMLDocument(iface); + xmlDtd *dtd; + + TRACE("(%p, %p)\n", This, p); + + if (!p) return E_INVALIDARG; + + dtd = xmlGetIntSubset(This->xmldoc); + if (!dtd) return S_FALSE; + + *p = bstr_from_xmlChar(dtd->name); + CharUpperBuffW(*p, SysStringLen(*p)); + + return S_OK; } static HRESULT WINAPI xmldoc_get_dtdURl(IXMLDocument *iface, BSTR *p) @@ -501,7 +520,7 @@ static HRESULT WINAPI xmldoc_createElement(IXMLDocument *iface, VARIANT vType, node->type = type_msxml_to_libxml(V_I4(&vType)); /* FIXME: create xmlNodePtr based on vType and var1 */ - return XMLElement_create((IUnknown *)iface, node, (LPVOID *)ppElem); + return XMLElement_create((IUnknown *)iface, node, (LPVOID *)ppElem, TRUE); } static const struct IXMLDocumentVtbl xmldoc_vtbl = @@ -556,8 +575,13 @@ static ULONG WINAPI xmldoc_IPersistStreamInit_Release( static HRESULT WINAPI xmldoc_IPersistStreamInit_GetClassID( IPersistStreamInit *iface, CLSID *classid) { - FIXME("(%p,%p): stub!\n", iface, classid); - return E_NOTIMPL; + xmldoc *this = impl_from_IPersistStreamInit(iface); + TRACE("(%p,%p)\n", this, classid); + + if (!classid) return E_POINTER; + + *classid = CLSID_XMLDocument; + return S_OK; } static HRESULT WINAPI xmldoc_IPersistStreamInit_IsDirty( @@ -581,7 +605,6 @@ static HRESULT WINAPI xmldoc_IPersistStreamInit_Load( IPersistStreamInit *iface, LPSTREAM pStm) { xmldoc *This = impl_from_IPersistStreamInit(iface); - xmlNodePtr xmlnode; HRESULT hr; HGLOBAL hglobal; DWORD read, written, len; @@ -593,6 +616,8 @@ static HRESULT WINAPI xmldoc_IPersistStreamInit_Load( if (!pStm) return E_INVALIDARG; + /* release previously allocated stream */ + if (This->stream) IStream_Release(This->stream); hr = CreateStreamOnHGlobal(NULL, TRUE, &This->stream); if (FAILED(hr)) return hr; @@ -616,7 +641,10 @@ static HRESULT WINAPI xmldoc_IPersistStreamInit_Load( len = GlobalSize(hglobal); ptr = GlobalLock(hglobal); if (len != 0) + { + xmlFreeDoc(This->xmldoc); This->xmldoc = parse_xml(ptr, len); + } GlobalUnlock(hglobal); if (!This->xmldoc) @@ -625,8 +653,7 @@ static HRESULT WINAPI xmldoc_IPersistStreamInit_Load( return E_FAIL; } - xmlnode = xmlDocGetRootElement(This->xmldoc); - return XMLElement_create((IUnknown *)This, xmlnode, (LPVOID *)&This->root); + return S_OK; } static HRESULT WINAPI xmldoc_IPersistStreamInit_Save( @@ -639,15 +666,17 @@ static HRESULT WINAPI xmldoc_IPersistStreamInit_Save( static HRESULT WINAPI xmldoc_IPersistStreamInit_GetSizeMax( IPersistStreamInit *iface, ULARGE_INTEGER *pcbSize) { - FIXME("(%p, %p): stub!\n", iface, pcbSize); + xmldoc *This = impl_from_IPersistStreamInit(iface); + TRACE("(%p, %p)\n", This, pcbSize); return E_NOTIMPL; } static HRESULT WINAPI xmldoc_IPersistStreamInit_InitNew( IPersistStreamInit *iface) { - FIXME("(%p): stub!\n", iface); - return E_NOTIMPL; + xmldoc *This = impl_from_IPersistStreamInit(iface); + TRACE("(%p)\n", This); + return S_OK; } static const IPersistStreamInitVtbl xmldoc_IPersistStreamInit_VTable = @@ -669,7 +698,7 @@ HRESULT XMLDocument_create(IUnknown *pUnkOuter, LPVOID *ppObj) TRACE("(%p,%p)\n", pUnkOuter, ppObj); - doc = HeapAlloc(GetProcessHeap(), 0, sizeof (*doc)); + doc = heap_alloc(sizeof (*doc)); if(!doc) return E_OUTOFMEMORY; @@ -677,7 +706,6 @@ HRESULT XMLDocument_create(IUnknown *pUnkOuter, LPVOID *ppObj) doc->lpvtblIPersistStreamInit = &xmldoc_IPersistStreamInit_VTable; doc->ref = 1; doc->error = S_OK; - doc->root = NULL; doc->xmldoc = NULL; doc->stream = NULL; diff --git a/reactos/dll/win32/msxml3/xmlelem.c b/reactos/dll/win32/msxml3/xmlelem.c index 93cc53a2047..3ff307b3abe 100644 --- a/reactos/dll/win32/msxml3/xmlelem.c +++ b/reactos/dll/win32/msxml3/xmlelem.c @@ -48,6 +48,7 @@ typedef struct _xmlelem const IXMLElementVtbl *lpVtbl; LONG ref; xmlNodePtr node; + BOOL own; } xmlelem; static inline xmlelem *impl_from_IXMLElement(IXMLElement *iface) @@ -94,7 +95,8 @@ static ULONG WINAPI xmlelem_Release(IXMLElement *iface) ref = InterlockedDecrement(&This->ref); if (ref == 0) { - HeapFree(GetProcessHeap(), 0, This); + if (This->own) xmlFreeNode(This->node); + heap_free(This); } return ref; @@ -171,31 +173,17 @@ static HRESULT WINAPI xmlelem_Invoke(IXMLElement *iface, DISPID dispIdMember, return hr; } -static inline BSTR str_dup_upper(BSTR str) -{ - INT len = (lstrlenW(str) + 1) * sizeof(WCHAR); - BSTR p = SysAllocStringLen(NULL, len); - if (p) - { - memcpy(p, str, len); - CharUpperW(p); - } - return p; -} - static HRESULT WINAPI xmlelem_get_tagName(IXMLElement *iface, BSTR *p) { xmlelem *This = impl_from_IXMLElement(iface); - BSTR temp; TRACE("(%p, %p)\n", iface, p); if (!p) return E_INVALIDARG; - temp = bstr_from_xmlChar(This->node->name); - *p = str_dup_upper(temp); - SysFreeString(temp); + *p = bstr_from_xmlChar(This->node->name); + CharUpperBuffW(*p, SysStringLen(*p)); TRACE("returning %s\n", debugstr_w(*p)); @@ -226,7 +214,7 @@ static HRESULT WINAPI xmlelem_get_parent(IXMLElement *iface, IXMLElement **paren if (!This->node->parent) return S_FALSE; - return XMLElement_create((IUnknown *)iface, This->node->parent, (LPVOID *)parent); + return XMLElement_create((IUnknown *)iface, This->node->parent, (LPVOID *)parent, FALSE); } static HRESULT WINAPI xmlelem_setAttribute(IXMLElement *iface, BSTR strPropertyName, @@ -245,8 +233,8 @@ static HRESULT WINAPI xmlelem_setAttribute(IXMLElement *iface, BSTR strPropertyN value = xmlChar_from_wchar(V_BSTR(&PropertyValue)); attr = xmlSetProp(This->node, name, value); - HeapFree(GetProcessHeap(), 0, name); - HeapFree(GetProcessHeap(), 0, value); + heap_free(name); + heap_free(value); return (attr) ? S_OK : S_FALSE; } @@ -287,7 +275,7 @@ static HRESULT WINAPI xmlelem_getAttribute(IXMLElement *iface, BSTR strPropertyN V_BSTR(PropertyValue) = bstr_from_xmlChar(val); } - HeapFree(GetProcessHeap(), 0, name); + heap_free(name); xmlFree(val); TRACE("returning %s\n", debugstr_w(V_BSTR(PropertyValue))); return (val) ? S_OK : S_FALSE; @@ -317,7 +305,7 @@ static HRESULT WINAPI xmlelem_removeAttribute(IXMLElement *iface, BSTR strProper hr = S_OK; done: - HeapFree(GetProcessHeap(), 0, name); + heap_free(name); return hr; } @@ -330,7 +318,7 @@ static HRESULT WINAPI xmlelem_get_children(IXMLElement *iface, IXMLElementCollec if (!p) return E_INVALIDARG; - return XMLElementCollection_create((IUnknown *)iface, This->node->children, (LPVOID *)p); + return XMLElementCollection_create((IUnknown *)iface, This->node, (LPVOID *)p); } static LONG type_libxml_to_msxml(xmlElementType type) @@ -402,7 +390,7 @@ static HRESULT WINAPI xmlelem_put_text(IXMLElement *iface, BSTR p) content = xmlChar_from_wchar(p); xmlNodeSetContent(This->node, content); - HeapFree( GetProcessHeap(), 0, content); + heap_free(content); return S_OK; } @@ -421,13 +409,31 @@ static HRESULT WINAPI xmlelem_addChild(IXMLElement *iface, IXMLElement *pChildEl else child = xmlAddNextSibling(This->node, childElem->node->last); + /* parent is responsible for child data */ + if (child) childElem->own = FALSE; + return (child) ? S_OK : S_FALSE; } static HRESULT WINAPI xmlelem_removeChild(IXMLElement *iface, IXMLElement *pChildElem) { - FIXME("(%p, %p): stub\n", iface, pChildElem); - return E_NOTIMPL; + xmlelem *This = impl_from_IXMLElement(iface); + xmlelem *childElem = impl_from_IXMLElement(pChildElem); + + TRACE("(%p, %p)\n", This, childElem); + + if (!pChildElem) + return E_INVALIDARG; + + /* only supported for This is childElem parent case */ + if (This->node != childElem->node->parent) + return E_INVALIDARG; + + xmlUnlinkNode(childElem->node); + /* standalone element now */ + childElem->own = TRUE; + + return S_OK; } static const struct IXMLElementVtbl xmlelem_vtbl = @@ -453,7 +459,7 @@ static const struct IXMLElementVtbl xmlelem_vtbl = xmlelem_removeChild }; -HRESULT XMLElement_create(IUnknown *pUnkOuter, xmlNodePtr node, LPVOID *ppObj) +HRESULT XMLElement_create(IUnknown *pUnkOuter, xmlNodePtr node, LPVOID *ppObj, BOOL own) { xmlelem *elem; @@ -464,13 +470,14 @@ HRESULT XMLElement_create(IUnknown *pUnkOuter, xmlNodePtr node, LPVOID *ppObj) *ppObj = NULL; - elem = HeapAlloc(GetProcessHeap(), 0, sizeof (*elem)); + elem = heap_alloc(sizeof (*elem)); if(!elem) return E_OUTOFMEMORY; elem->lpVtbl = &xmlelem_vtbl; elem->ref = 1; elem->node = node; + elem->own = own; *ppObj = &elem->lpVtbl; @@ -493,6 +500,19 @@ typedef struct _xmlelem_collection xmlNodePtr current; } xmlelem_collection; +static inline LONG xmlelem_collection_updatelength(xmlelem_collection *collection) +{ + xmlNodePtr ptr = collection->node->children; + + collection->length = 0; + while (ptr) + { + collection->length++; + ptr = ptr->next; + } + return collection->length; +} + static inline xmlelem_collection *impl_from_IXMLElementCollection(IXMLElementCollection *iface) { return (xmlelem_collection *)((char*)iface - FIELD_OFFSET(xmlelem_collection, lpVtbl)); @@ -546,7 +566,7 @@ static ULONG WINAPI xmlelem_collection_Release(IXMLElementCollection *iface) ref = InterlockedDecrement(&This->ref); if (ref == 0) { - HeapFree(GetProcessHeap(), 0, This); + heap_free(This); } return ref; @@ -597,7 +617,7 @@ static HRESULT WINAPI xmlelem_collection_get_length(IXMLElementCollection *iface if (!p) return E_INVALIDARG; - *p = This->length; + *p = xmlelem_collection_updatelength(This); return S_OK; } @@ -619,7 +639,7 @@ static HRESULT WINAPI xmlelem_collection_item(IXMLElementCollection *iface, VARI VARIANT var2, IDispatch **ppDisp) { xmlelem_collection *This = impl_from_IXMLElementCollection(iface); - xmlNodePtr ptr = This->node; + xmlNodePtr ptr = This->node->children; int index, i; TRACE("(%p, %p)\n", iface, ppDisp); @@ -632,13 +652,15 @@ static HRESULT WINAPI xmlelem_collection_item(IXMLElementCollection *iface, VARI index = V_I4(&var1); if (index < 0) return E_INVALIDARG; + + xmlelem_collection_updatelength(This); if (index >= This->length) return E_FAIL; for (i = 0; i < index; i++) ptr = ptr->next; - return XMLElement_create((IUnknown *)iface, ptr, (LPVOID *)ppDisp); + return XMLElement_create((IUnknown *)iface, ptr, (LPVOID *)ppDisp, FALSE); } static const struct IXMLElementCollectionVtbl xmlelem_collection_vtbl = @@ -698,7 +720,7 @@ static HRESULT WINAPI xmlelem_collection_IEnumVARIANT_Next( This->current = This->current->next; V_VT(rgVar) = VT_DISPATCH; - return XMLElement_create((IUnknown *)iface, ptr, (LPVOID *)&V_DISPATCH(rgVar)); + return XMLElement_create((IUnknown *)iface, ptr, (LPVOID *)&V_DISPATCH(rgVar), FALSE); } static HRESULT WINAPI xmlelem_collection_IEnumVARIANT_Skip( @@ -712,7 +734,7 @@ static HRESULT WINAPI xmlelem_collection_IEnumVARIANT_Reset( IEnumVARIANT *iface) { xmlelem_collection *This = impl_from_IEnumVARIANT(iface); - This->current = This->node; + This->current = This->node->children; return S_OK; } @@ -737,16 +759,15 @@ static const struct IEnumVARIANTVtbl xmlelem_collection_IEnumVARIANTvtbl = static HRESULT XMLElementCollection_create(IUnknown *pUnkOuter, xmlNodePtr node, LPVOID *ppObj) { xmlelem_collection *collection; - xmlNodePtr ptr; TRACE("(%p,%p)\n", pUnkOuter, ppObj); *ppObj = NULL; - if (!node) + if (!node->children) return S_FALSE; - collection = HeapAlloc(GetProcessHeap(), 0, sizeof (*collection)); + collection = heap_alloc(sizeof (*collection)); if(!collection) return E_OUTOFMEMORY; @@ -755,14 +776,8 @@ static HRESULT XMLElementCollection_create(IUnknown *pUnkOuter, xmlNodePtr node, collection->ref = 1; collection->length = 0; collection->node = node; - collection->current = node; - - ptr = node; - while (ptr) - { - collection->length++; - ptr = ptr->next; - } + collection->current = node->children; + xmlelem_collection_updatelength(collection); *ppObj = &collection->lpVtbl; diff --git a/reactos/include/psdk/msxml2.idl b/reactos/include/psdk/msxml2.idl index e6f07b3b8b4..b6303c9f001 100644 --- a/reactos/include/psdk/msxml2.idl +++ b/reactos/include/psdk/msxml2.idl @@ -1070,6 +1070,14 @@ coclass DOMDocument30 [default, source] dispinterface XMLDOMDocumentEvents; } +[ + uuid(88d969c0-f192-11d4-a65f-0040963251e5) +] +coclass DOMDocument40 +{ + [default] interface IXMLDOMDocument2; + [default, source] dispinterface XMLDOMDocumentEvents; +} [ uuid(F6D90F12-9C73-11D3-B32E-00C04F990BB4)