2 * SAX Reader implementation
4 * Copyright 2008 Alistair Leslie-Hughes
5 * Copyright 2008 Piotr Caban
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
27 # include <libxml/parser.h>
28 # include <libxml/xmlerror.h>
29 # include <libxml/SAX2.h>
30 # include <libxml/parserInternals.h>
44 #include "wine/debug.h"
45 #include "wine/list.h"
47 #include "msxml_private.h"
49 WINE_DEFAULT_DEBUG_CHANNEL(msxml);
55 ExhaustiveErrors = 1 << 1,
56 ExternalGeneralEntities = 1 << 2,
57 ExternalParameterEntities = 1 << 3,
58 ForcedResync = 1 << 4,
59 NamespacePrefixes = 1 << 5,
61 ParameterEntities = 1 << 7,
62 PreserveSystemIndentifiers = 1 << 8,
64 SchemaValidation = 1 << 10,
65 ServerHttpRequest = 1 << 11,
66 SuppressValidationfatalError = 1 << 12,
67 UseInlineSchema = 1 << 13,
68 UseSchemaLocation = 1 << 14,
69 LexicalHandlerParEntities = 1 << 15
91 ns *ns; /* namespaces defined in this particular element */
98 IVBSAXXMLReader IVBSAXXMLReader_iface;
99 ISAXXMLReader ISAXXMLReader_iface;
101 ISAXContentHandler *contentHandler;
102 IVBSAXContentHandler *vbcontentHandler;
103 ISAXErrorHandler *errorHandler;
104 IVBSAXErrorHandler *vberrorHandler;
105 ISAXLexicalHandler *lexicalHandler;
106 IVBSAXLexicalHandler *vblexicalHandler;
107 ISAXDeclHandler *declHandler;
108 IVBSAXDeclHandler *vbdeclHandler;
111 struct bstrpool pool;
112 saxreader_features features;
113 MSXML_VERSION version;
118 IVBSAXLocator IVBSAXLocator_iface;
119 ISAXLocator ISAXLocator_iface;
120 IVBSAXAttributes IVBSAXAttributes_iface;
121 ISAXAttributes ISAXAttributes_iface;
123 saxreader *saxreader;
125 xmlParserCtxtPtr pParserCtxt;
131 struct list elements;
145 static inline saxreader *impl_from_IVBSAXXMLReader( IVBSAXXMLReader *iface )
147 return CONTAINING_RECORD(iface, saxreader, IVBSAXXMLReader_iface);
150 static inline saxreader *impl_from_ISAXXMLReader( ISAXXMLReader *iface )
152 return CONTAINING_RECORD(iface, saxreader, ISAXXMLReader_iface);
155 static inline saxlocator *impl_from_IVBSAXLocator( IVBSAXLocator *iface )
157 return CONTAINING_RECORD(iface, saxlocator, IVBSAXLocator_iface);
160 static inline saxlocator *impl_from_ISAXLocator( ISAXLocator *iface )
162 return CONTAINING_RECORD(iface, saxlocator, ISAXLocator_iface);
165 static inline saxlocator *impl_from_IVBSAXAttributes( IVBSAXAttributes *iface )
167 return CONTAINING_RECORD(iface, saxlocator, IVBSAXAttributes_iface);
170 static inline saxlocator *impl_from_ISAXAttributes( ISAXAttributes *iface )
172 return CONTAINING_RECORD(iface, saxlocator, ISAXAttributes_iface);
176 static const WCHAR PropertyCharsetW[] = {
177 'c','h','a','r','s','e','t',0
179 static const WCHAR PropertyDeclHandlerW[] = {
180 'h','t','t','p',':','/','/','x','m','l','.','o','r','g','/',
181 's','a','x','/','p','r','o','p','e','r','t','i','e','s','/',
182 'd','e','c','l','a','r','a','t','i','o','n',
183 '-','h','a','n','d','l','e','r',0
185 static const WCHAR PropertyDomNodeW[] = {
186 'h','t','t','p',':','/','/','x','m','l','.','o','r','g','/',
187 's','a','x','/','p','r','o','p','e','r','t','i','e','s','/',
188 'd','o','m','-','n','o','d','e',0
190 static const WCHAR PropertyInputSourceW[] = {
191 'i','n','p','u','t','-','s','o','u','r','c','e',0
193 static const WCHAR PropertyLexicalHandlerW[] = {
194 'h','t','t','p',':','/','/','x','m','l','.','o','r','g','/',
195 's','a','x','/','p','r','o','p','e','r','t','i','e','s','/',
196 'l','e','x','i','c','a','l','-','h','a','n','d','l','e','r',0
198 static const WCHAR PropertyMaxElementDepthW[] = {
199 'm','a','x','-','e','l','e','m','e','n','t','-','d','e','p','t','h',0
201 static const WCHAR PropertyMaxXMLSizeW[] = {
202 'm','a','x','-','x','m','l','-','s','i','z','e',0
204 static const WCHAR PropertySchemaDeclHandlerW[] = {
205 's','c','h','e','m','a','-','d','e','c','l','a','r','a','t','i','o','n','-',
206 'h','a','n','d','l','e','r',0
208 static const WCHAR PropertyXMLDeclEncodingW[] = {
209 'x','m','l','d','e','c','l','-','e','n','c','o','d','i','n','g',0
211 static const WCHAR PropertyXMLDeclStandaloneW[] = {
212 'x','m','l','d','e','c','l','-','s','t','a','n','d','a','l','o','n','e',0
214 static const WCHAR PropertyXMLDeclVersionW[] = {
215 'x','m','l','d','e','c','l','-','v','e','r','s','i','o','n',0
219 static const WCHAR FeatureExternalGeneralEntitiesW[] = {
220 'h','t','t','p',':','/','/','x','m','l','.','o','r','g','/','s','a','x','/',
221 'f','e','a','t','u','r','e','s','/','e','x','t','e','r','n','a','l','-','g','e','n','e','r','a','l',
222 '-','e','n','t','i','t','i','e','s',0
225 static const WCHAR FeatureExternalParameterEntitiesW[] = {
226 'h','t','t','p',':','/','/','x','m','l','.','o','r','g','/','s','a','x','/','f','e','a','t','u','r','e','s',
227 '/','e','x','t','e','r','n','a','l','-','p','a','r','a','m','e','t','e','r','-','e','n','t','i','t','i','e','s',0
230 static const WCHAR FeatureLexicalHandlerParEntitiesW[] = {
231 'h','t','t','p',':','/','/','x','m','l','.','o','r','g','/','s','a','x','/','f','e','a','t','u','r','e','s',
232 '/','l','e','x','i','c','a','l','-','h','a','n','d','l','e','r','/','p','a','r','a','m','e','t','e','r','-','e','n','t','i','t','i','e','s',0
235 static const WCHAR FeatureProhibitDTDW[] = {
236 'p','r','o','h','i','b','i','t','-','d','t','d',0
239 static const WCHAR FeatureNamespacesW[] = {
240 'h','t','t','p',':','/','/','x','m','l','.','o','r','g','/','s','a','x','/','f','e','a','t','u','r','e','s',
241 '/','n','a','m','e','s','p','a','c','e','s',0
244 static inline HRESULT set_feature_value(saxreader *reader, saxreader_features feature, VARIANT_BOOL value)
246 if (value == VARIANT_TRUE)
247 reader->features |= feature;
249 reader->features &= ~feature;
254 static inline HRESULT get_feature_value(const saxreader *reader, saxreader_features feature, VARIANT_BOOL *value)
256 *value = reader->features & feature ? VARIANT_TRUE : VARIANT_FALSE;
260 static inline BOOL has_content_handler(const saxlocator *locator)
262 return (locator->vbInterface && locator->saxreader->vbcontentHandler) ||
263 (!locator->vbInterface && locator->saxreader->contentHandler);
266 static inline BOOL has_error_handler(const saxlocator *locator)
268 return (locator->vbInterface && locator->saxreader->vberrorHandler) ||
269 (!locator->vbInterface && locator->saxreader->errorHandler);
272 static BSTR build_qname(BSTR prefix, BSTR local)
274 if (prefix && *prefix)
276 BSTR qname = SysAllocStringLen(NULL, SysStringLen(prefix) + SysStringLen(local) + 1);
280 strcpyW(ptr, prefix);
281 ptr += SysStringLen(prefix);
287 return SysAllocString(local);
290 static element_entry* alloc_element_entry(const xmlChar *local, const xmlChar *prefix, int nb_ns,
291 const xmlChar **namespaces)
296 ret = heap_alloc(sizeof(*ret));
297 if (!ret) return ret;
299 ret->local = bstr_from_xmlChar(local);
300 ret->prefix = bstr_from_xmlChar(prefix);
301 ret->qname = build_qname(ret->prefix, ret->local);
302 ret->ns = nb_ns ? heap_alloc(nb_ns*sizeof(ns)) : NULL;
303 ret->ns_count = nb_ns;
305 for (i=0; i < nb_ns; i++)
307 ret->ns[i].prefix = bstr_from_xmlChar(namespaces[2*i]);
308 ret->ns[i].uri = bstr_from_xmlChar(namespaces[2*i+1]);
314 static void free_element_entry(element_entry *element)
318 for (i=0; i<element->ns_count;i++)
320 SysFreeString(element->ns[i].prefix);
321 SysFreeString(element->ns[i].uri);
324 SysFreeString(element->prefix);
325 SysFreeString(element->local);
327 heap_free(element->ns);
331 static void push_element_ns(saxlocator *locator, element_entry *element)
333 list_add_head(&locator->elements, &element->entry);
336 static element_entry * pop_element_ns(saxlocator *locator)
338 element_entry *element = LIST_ENTRY(list_head(&locator->elements), element_entry, entry);
341 list_remove(&element->entry);
346 static BSTR find_element_uri(saxlocator *locator, const xmlChar *uri)
348 element_entry *element;
352 if (!uri) return NULL;
354 uriW = bstr_from_xmlChar(uri);
356 LIST_FOR_EACH_ENTRY(element, &locator->elements, element_entry, entry)
358 for (i=0; i < element->ns_count; i++)
359 if (!strcmpW(uriW, element->ns[i].uri))
362 return element->ns[i].uri;
367 ERR("namespace uri not found, %s\n", debugstr_a((char*)uri));
371 /* used to localize version dependent error check behaviour */
372 static inline BOOL sax_callback_failed(saxlocator *This, HRESULT hr)
374 return This->saxreader->version >= MSXML6 ? FAILED(hr) : hr != S_OK;
377 /* index value -1 means it tries to loop for a first time */
378 static inline BOOL iterate_endprefix_index(saxlocator *This, const element_entry *element, int *i)
380 if (This->saxreader->version >= MSXML6)
382 if (*i == -1) *i = 0; else ++*i;
383 return *i < element->ns_count;
387 if (*i == -1) *i = element->ns_count-1; else --*i;
392 static BOOL bstr_pool_insert(struct bstrpool *pool, BSTR pool_entry)
396 pool->pool = HeapAlloc(GetProcessHeap(), 0, 16 * sizeof(*pool->pool));
403 else if (pool->index == pool->len)
405 BSTR *realloc = HeapReAlloc(GetProcessHeap(), 0, pool->pool, pool->len * 2 * sizeof(*realloc));
410 pool->pool = realloc;
414 pool->pool[pool->index++] = pool_entry;
418 static void free_bstr_pool(struct bstrpool *pool)
422 for (i = 0; i < pool->index; i++)
423 SysFreeString(pool->pool[i]);
425 HeapFree(GetProcessHeap(), 0, pool->pool);
428 pool->index = pool->len = 0;
431 static BSTR bstr_from_xmlCharN(const xmlChar *buf, int len)
439 dLen = MultiByteToWideChar(CP_UTF8, 0, (LPCSTR)buf, len, NULL, 0);
440 if(len != -1) dLen++;
441 bstr = SysAllocStringLen(NULL, dLen-1);
444 MultiByteToWideChar(CP_UTF8, 0, (LPCSTR)buf, len, bstr, dLen);
445 if(len != -1) bstr[dLen-1] = '\0';
450 static BSTR QName_from_xmlChar(const xmlChar *prefix, const xmlChar *name)
455 if(!name) return NULL;
457 if(!prefix || !*prefix)
458 return bstr_from_xmlChar(name);
460 qname = xmlBuildQName(name, prefix, NULL, 0);
461 bstr = bstr_from_xmlChar(qname);
467 static BSTR pooled_bstr_from_xmlChar(struct bstrpool *pool, const xmlChar *buf)
469 BSTR pool_entry = bstr_from_xmlChar(buf);
471 if (pool_entry && !bstr_pool_insert(pool, pool_entry))
473 SysFreeString(pool_entry);
480 static BSTR pooled_bstr_from_xmlCharN(struct bstrpool *pool, const xmlChar *buf, int len)
482 BSTR pool_entry = bstr_from_xmlCharN(buf, len);
484 if (pool_entry && !bstr_pool_insert(pool, pool_entry))
486 SysFreeString(pool_entry);
493 static void format_error_message_from_id(saxlocator *This, HRESULT hr)
495 xmlStopParser(This->pParserCtxt);
498 if(has_error_handler(This))
501 if(!FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM,
502 NULL, hr, 0, msg, sizeof(msg), NULL))
504 FIXME("MSXML errors not yet supported.\n");
508 if(This->vbInterface)
510 BSTR bstrMsg = SysAllocString(msg);
511 IVBSAXErrorHandler_fatalError(This->saxreader->vberrorHandler,
512 &This->IVBSAXLocator_iface, &bstrMsg, hr);
513 SysFreeString(bstrMsg);
516 ISAXErrorHandler_fatalError(This->saxreader->errorHandler,
517 &This->ISAXLocator_iface, msg, hr);
521 static void update_position(saxlocator *This, BOOL fix_column)
523 const xmlChar *p = This->pParserCtxt->input->cur-1;
525 This->line = xmlSAX2GetLineNumber(This->pParserCtxt);
529 for(; *p!='\n' && *p!='\r' && p>=This->pParserCtxt->input->base; p--)
534 This->column = xmlSAX2GetColumnNumber(This->pParserCtxt);
538 /*** IVBSAXAttributes interface ***/
539 /*** IUnknown methods ***/
540 static HRESULT WINAPI ivbsaxattributes_QueryInterface(
541 IVBSAXAttributes* iface,
545 saxlocator *This = impl_from_IVBSAXAttributes(iface);
546 TRACE("%p %s %p\n", This, debugstr_guid(riid), ppvObject);
547 return IVBSAXLocator_QueryInterface(&This->IVBSAXLocator_iface, riid, ppvObject);
550 static ULONG WINAPI ivbsaxattributes_AddRef(IVBSAXAttributes* iface)
552 saxlocator *This = impl_from_IVBSAXAttributes(iface);
553 return ISAXLocator_AddRef(&This->ISAXLocator_iface);
556 static ULONG WINAPI ivbsaxattributes_Release(IVBSAXAttributes* iface)
558 saxlocator *This = impl_from_IVBSAXAttributes(iface);
559 return ISAXLocator_Release(&This->ISAXLocator_iface);
562 /*** IDispatch methods ***/
563 static HRESULT WINAPI ivbsaxattributes_GetTypeInfoCount( IVBSAXAttributes *iface, UINT* pctinfo )
565 saxlocator *This = impl_from_IVBSAXAttributes( iface );
567 TRACE("(%p)->(%p)\n", This, pctinfo);
574 static HRESULT WINAPI ivbsaxattributes_GetTypeInfo(
575 IVBSAXAttributes *iface,
576 UINT iTInfo, LCID lcid, ITypeInfo** ppTInfo )
578 saxlocator *This = impl_from_IVBSAXAttributes( iface );
581 TRACE("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo);
583 hr = get_typeinfo(IVBSAXAttributes_tid, ppTInfo);
588 static HRESULT WINAPI ivbsaxattributes_GetIDsOfNames(
589 IVBSAXAttributes *iface,
596 saxlocator *This = impl_from_IVBSAXAttributes( iface );
600 TRACE("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames, cNames,
603 if(!rgszNames || cNames == 0 || !rgDispId)
606 hr = get_typeinfo(IVBSAXAttributes_tid, &typeinfo);
609 hr = ITypeInfo_GetIDsOfNames(typeinfo, rgszNames, cNames, rgDispId);
610 ITypeInfo_Release(typeinfo);
616 static HRESULT WINAPI ivbsaxattributes_Invoke(
617 IVBSAXAttributes *iface,
622 DISPPARAMS* pDispParams,
624 EXCEPINFO* pExcepInfo,
627 saxlocator *This = impl_from_IVBSAXAttributes( iface );
631 TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
632 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
634 hr = get_typeinfo(IVBSAXAttributes_tid, &typeinfo);
637 hr = ITypeInfo_Invoke(typeinfo, &This->IVBSAXAttributes_iface, dispIdMember, wFlags,
638 pDispParams, pVarResult, pExcepInfo, puArgErr);
639 ITypeInfo_Release(typeinfo);
645 /*** IVBSAXAttributes methods ***/
646 static HRESULT WINAPI ivbsaxattributes_get_length(
647 IVBSAXAttributes* iface,
650 saxlocator *This = impl_from_IVBSAXAttributes( iface );
651 return ISAXAttributes_getLength(&This->ISAXAttributes_iface, nLength);
654 static HRESULT WINAPI ivbsaxattributes_getURI(
655 IVBSAXAttributes* iface,
660 saxlocator *This = impl_from_IVBSAXAttributes( iface );
661 return ISAXAttributes_getURI(&This->ISAXAttributes_iface, nIndex, (const WCHAR**)uri, &len);
664 static HRESULT WINAPI ivbsaxattributes_getLocalName(
665 IVBSAXAttributes* iface,
670 saxlocator *This = impl_from_IVBSAXAttributes( iface );
671 return ISAXAttributes_getLocalName(&This->ISAXAttributes_iface, nIndex,
672 (const WCHAR**)localName, &len);
675 static HRESULT WINAPI ivbsaxattributes_getQName(
676 IVBSAXAttributes* iface,
681 saxlocator *This = impl_from_IVBSAXAttributes( iface );
682 return ISAXAttributes_getQName(&This->ISAXAttributes_iface, nIndex, (const WCHAR**)QName, &len);
685 static HRESULT WINAPI ivbsaxattributes_getIndexFromName(
686 IVBSAXAttributes* iface,
691 saxlocator *This = impl_from_IVBSAXAttributes( iface );
692 return ISAXAttributes_getIndexFromName(&This->ISAXAttributes_iface, uri, SysStringLen(uri),
693 localName, SysStringLen(localName), index);
696 static HRESULT WINAPI ivbsaxattributes_getIndexFromQName(
697 IVBSAXAttributes* iface,
701 saxlocator *This = impl_from_IVBSAXAttributes( iface );
702 return ISAXAttributes_getIndexFromQName(&This->ISAXAttributes_iface, QName,
703 SysStringLen(QName), index);
706 static HRESULT WINAPI ivbsaxattributes_getType(
707 IVBSAXAttributes* iface,
712 saxlocator *This = impl_from_IVBSAXAttributes( iface );
713 return ISAXAttributes_getType(&This->ISAXAttributes_iface, nIndex, (const WCHAR**)type, &len);
716 static HRESULT WINAPI ivbsaxattributes_getTypeFromName(
717 IVBSAXAttributes* iface,
723 saxlocator *This = impl_from_IVBSAXAttributes( iface );
724 return ISAXAttributes_getTypeFromName(&This->ISAXAttributes_iface, uri, SysStringLen(uri),
725 localName, SysStringLen(localName), (const WCHAR**)type, &len);
728 static HRESULT WINAPI ivbsaxattributes_getTypeFromQName(
729 IVBSAXAttributes* iface,
734 saxlocator *This = impl_from_IVBSAXAttributes( iface );
735 return ISAXAttributes_getTypeFromQName(&This->ISAXAttributes_iface, QName, SysStringLen(QName),
736 (const WCHAR**)type, &len);
739 static HRESULT WINAPI ivbsaxattributes_getValue(
740 IVBSAXAttributes* iface,
745 saxlocator *This = impl_from_IVBSAXAttributes( iface );
746 return ISAXAttributes_getValue(&This->ISAXAttributes_iface, nIndex, (const WCHAR**)value, &len);
749 static HRESULT WINAPI ivbsaxattributes_getValueFromName(
750 IVBSAXAttributes* iface,
756 saxlocator *This = impl_from_IVBSAXAttributes( iface );
757 return ISAXAttributes_getValueFromName(&This->ISAXAttributes_iface, uri, SysStringLen(uri),
758 localName, SysStringLen(localName), (const WCHAR**)value, &len);
761 static HRESULT WINAPI ivbsaxattributes_getValueFromQName(
762 IVBSAXAttributes* iface,
767 saxlocator *This = impl_from_IVBSAXAttributes( iface );
768 return ISAXAttributes_getValueFromQName(&This->ISAXAttributes_iface, QName,
769 SysStringLen(QName), (const WCHAR**)value, &len);
772 static const struct IVBSAXAttributesVtbl ivbsaxattributes_vtbl =
774 ivbsaxattributes_QueryInterface,
775 ivbsaxattributes_AddRef,
776 ivbsaxattributes_Release,
777 ivbsaxattributes_GetTypeInfoCount,
778 ivbsaxattributes_GetTypeInfo,
779 ivbsaxattributes_GetIDsOfNames,
780 ivbsaxattributes_Invoke,
781 ivbsaxattributes_get_length,
782 ivbsaxattributes_getURI,
783 ivbsaxattributes_getLocalName,
784 ivbsaxattributes_getQName,
785 ivbsaxattributes_getIndexFromName,
786 ivbsaxattributes_getIndexFromQName,
787 ivbsaxattributes_getType,
788 ivbsaxattributes_getTypeFromName,
789 ivbsaxattributes_getTypeFromQName,
790 ivbsaxattributes_getValue,
791 ivbsaxattributes_getValueFromName,
792 ivbsaxattributes_getValueFromQName
795 /*** ISAXAttributes interface ***/
796 /*** IUnknown methods ***/
797 static HRESULT WINAPI isaxattributes_QueryInterface(
798 ISAXAttributes* iface,
802 saxlocator *This = impl_from_ISAXAttributes(iface);
803 TRACE("%p %s %p\n", This, debugstr_guid(riid), ppvObject);
804 return ISAXLocator_QueryInterface(&This->ISAXLocator_iface, riid, ppvObject);
807 static ULONG WINAPI isaxattributes_AddRef(ISAXAttributes* iface)
809 saxlocator *This = impl_from_ISAXAttributes(iface);
811 return ISAXLocator_AddRef(&This->ISAXLocator_iface);
814 static ULONG WINAPI isaxattributes_Release(ISAXAttributes* iface)
816 saxlocator *This = impl_from_ISAXAttributes(iface);
819 return ISAXLocator_Release(&This->ISAXLocator_iface);
822 /*** ISAXAttributes methods ***/
823 static HRESULT WINAPI isaxattributes_getLength(
824 ISAXAttributes* iface,
827 saxlocator *This = impl_from_ISAXAttributes( iface );
829 *length = This->nb_attributes;
830 TRACE("Length set to %d\n", *length);
834 static HRESULT WINAPI isaxattributes_getURI(
835 ISAXAttributes* iface,
840 saxlocator *This = impl_from_ISAXAttributes( iface );
841 TRACE("(%p)->(%d)\n", This, index);
843 if(index >= This->nb_attributes || index < 0) return E_INVALIDARG;
844 if(!url || !size) return E_POINTER;
846 *size = SysStringLen(This->attributes[index].szURI);
847 *url = This->attributes[index].szURI;
849 TRACE("(%s:%d)\n", debugstr_w(This->attributes[index].szURI), *size);
854 static HRESULT WINAPI isaxattributes_getLocalName(
855 ISAXAttributes* iface,
857 const WCHAR **pLocalName,
858 int *pLocalNameLength)
860 saxlocator *This = impl_from_ISAXAttributes( iface );
861 TRACE("(%p)->(%d)\n", This, nIndex);
863 if(nIndex>=This->nb_attributes || nIndex<0) return E_INVALIDARG;
864 if(!pLocalName || !pLocalNameLength) return E_POINTER;
866 *pLocalNameLength = SysStringLen(This->attributes[nIndex].szLocalname);
867 *pLocalName = This->attributes[nIndex].szLocalname;
872 static HRESULT WINAPI isaxattributes_getQName(
873 ISAXAttributes* iface,
875 const WCHAR **pQName,
878 saxlocator *This = impl_from_ISAXAttributes( iface );
879 TRACE("(%p)->(%d)\n", This, nIndex);
881 if(nIndex>=This->nb_attributes || nIndex<0) return E_INVALIDARG;
882 if(!pQName || !pQNameLength) return E_POINTER;
884 *pQNameLength = SysStringLen(This->attributes[nIndex].szQName);
885 *pQName = This->attributes[nIndex].szQName;
890 static HRESULT WINAPI isaxattributes_getName(
891 ISAXAttributes* iface,
895 const WCHAR **localName,
900 saxlocator *This = impl_from_ISAXAttributes( iface );
901 TRACE("(%p)->(%d)\n", This, index);
903 if(index>=This->nb_attributes || index<0) return E_INVALIDARG;
904 if(!uri || !pUriLength || !localName || !pLocalNameSize
905 || !QName || !pQNameLength) return E_POINTER;
907 *pUriLength = SysStringLen(This->attributes[index].szURI);
908 *uri = This->attributes[index].szURI;
909 *pLocalNameSize = SysStringLen(This->attributes[index].szLocalname);
910 *localName = This->attributes[index].szLocalname;
911 *pQNameLength = SysStringLen(This->attributes[index].szQName);
912 *QName = This->attributes[index].szQName;
914 TRACE("(%s, %s, %s)\n", debugstr_w(*uri), debugstr_w(*localName), debugstr_w(*QName));
919 static HRESULT WINAPI isaxattributes_getIndexFromName(
920 ISAXAttributes* iface,
923 const WCHAR *pLocalName,
927 saxlocator *This = impl_from_ISAXAttributes( iface );
929 TRACE("(%p)->(%s, %d, %s, %d)\n", This, debugstr_w(pUri), cUriLength,
930 debugstr_w(pLocalName), cocalNameLength);
932 if(!pUri || !pLocalName || !index) return E_POINTER;
934 for(i=0; i<This->nb_attributes; i++)
936 if(cUriLength!=SysStringLen(This->attributes[i].szURI)
937 || cocalNameLength!=SysStringLen(This->attributes[i].szLocalname))
939 if(cUriLength && memcmp(pUri, This->attributes[i].szURI,
940 sizeof(WCHAR)*cUriLength))
942 if(cocalNameLength && memcmp(pLocalName, This->attributes[i].szLocalname,
943 sizeof(WCHAR)*cocalNameLength))
953 static HRESULT WINAPI isaxattributes_getIndexFromQName(
954 ISAXAttributes* iface,
959 saxlocator *This = impl_from_ISAXAttributes( iface );
961 TRACE("(%p)->(%s, %d)\n", This, debugstr_w(pQName), nQNameLength);
963 if(!pQName || !index) return E_POINTER;
964 if(!nQNameLength) return E_INVALIDARG;
966 for(i=0; i<This->nb_attributes; i++)
968 if(nQNameLength!=SysStringLen(This->attributes[i].szQName)) continue;
969 if(memcmp(pQName, This->attributes[i].szQName, sizeof(WCHAR)*nQNameLength)) continue;
978 static HRESULT WINAPI isaxattributes_getType(
979 ISAXAttributes* iface,
984 saxlocator *This = impl_from_ISAXAttributes( iface );
986 FIXME("(%p)->(%d) stub\n", This, nIndex);
990 static HRESULT WINAPI isaxattributes_getTypeFromName(
991 ISAXAttributes* iface,
994 const WCHAR *pLocalName,
999 saxlocator *This = impl_from_ISAXAttributes( iface );
1001 FIXME("(%p)->(%s, %d, %s, %d) stub\n", This, debugstr_w(pUri), nUri,
1002 debugstr_w(pLocalName), nLocalName);
1006 static HRESULT WINAPI isaxattributes_getTypeFromQName(
1007 ISAXAttributes* iface,
1008 const WCHAR *pQName,
1010 const WCHAR **pType,
1013 saxlocator *This = impl_from_ISAXAttributes( iface );
1015 FIXME("(%p)->(%s, %d) stub\n", This, debugstr_w(pQName), nQName);
1019 static HRESULT WINAPI isaxattributes_getValue(
1020 ISAXAttributes* iface,
1022 const WCHAR **value,
1025 saxlocator *This = impl_from_ISAXAttributes( iface );
1026 TRACE("(%p)->(%d)\n", This, index);
1028 if(index>=This->nb_attributes || index<0) return E_INVALIDARG;
1029 if(!value || !nValue) return E_POINTER;
1031 *nValue = SysStringLen(This->attributes[index].szValue);
1032 *value = This->attributes[index].szValue;
1034 TRACE("(%s:%d)\n", debugstr_w(*value), *nValue);
1039 static HRESULT WINAPI isaxattributes_getValueFromName(
1040 ISAXAttributes* iface,
1043 const WCHAR *pLocalName,
1045 const WCHAR **pValue,
1050 saxlocator *This = impl_from_ISAXAttributes( iface );
1051 TRACE("(%p)->(%s, %d, %s, %d)\n", This, debugstr_w(pUri), nUri,
1052 debugstr_w(pLocalName), nLocalName);
1054 hr = ISAXAttributes_getIndexFromName(iface,
1055 pUri, nUri, pLocalName, nLocalName, &index);
1056 if(hr==S_OK) hr = ISAXAttributes_getValue(iface, index, pValue, nValue);
1061 static HRESULT WINAPI isaxattributes_getValueFromQName(
1062 ISAXAttributes* iface,
1063 const WCHAR *pQName,
1065 const WCHAR **pValue,
1070 saxlocator *This = impl_from_ISAXAttributes( iface );
1071 TRACE("(%p)->(%s, %d)\n", This, debugstr_w(pQName), nQName);
1073 hr = ISAXAttributes_getIndexFromQName(iface, pQName, nQName, &index);
1074 if(hr==S_OK) hr = ISAXAttributes_getValue(iface, index, pValue, nValue);
1079 static const struct ISAXAttributesVtbl isaxattributes_vtbl =
1081 isaxattributes_QueryInterface,
1082 isaxattributes_AddRef,
1083 isaxattributes_Release,
1084 isaxattributes_getLength,
1085 isaxattributes_getURI,
1086 isaxattributes_getLocalName,
1087 isaxattributes_getQName,
1088 isaxattributes_getName,
1089 isaxattributes_getIndexFromName,
1090 isaxattributes_getIndexFromQName,
1091 isaxattributes_getType,
1092 isaxattributes_getTypeFromName,
1093 isaxattributes_getTypeFromQName,
1094 isaxattributes_getValue,
1095 isaxattributes_getValueFromName,
1096 isaxattributes_getValueFromQName
1099 static HRESULT SAXAttributes_populate(saxlocator *locator,
1100 int nb_namespaces, const xmlChar **xmlNamespaces,
1101 int nb_attributes, const xmlChar **xmlAttributes)
1103 static const xmlChar xmlns[] = "xmlns";
1104 static const WCHAR xmlnsW[] = { 'x','m','l','n','s',0 };
1106 struct _attributes *attrs;
1109 locator->nb_attributes = nb_namespaces+nb_attributes;
1110 if(locator->nb_attributes > locator->attributesSize)
1112 attrs = heap_realloc(locator->attributes, sizeof(struct _attributes)*locator->nb_attributes*2);
1115 locator->nb_attributes = 0;
1116 return E_OUTOFMEMORY;
1118 locator->attributes = attrs;
1122 attrs = locator->attributes;
1125 for(index=0; index<nb_namespaces; index++)
1127 attrs[nb_attributes+index].szLocalname = SysAllocStringLen(NULL, 0);
1128 attrs[nb_attributes+index].szURI = locator->namespaceUri;
1129 attrs[nb_attributes+index].szValue = bstr_from_xmlChar(xmlNamespaces[2*index+1]);
1130 if(!xmlNamespaces[2*index])
1131 attrs[nb_attributes+index].szQName = SysAllocString(xmlnsW);
1133 attrs[nb_attributes+index].szQName = QName_from_xmlChar(xmlns, xmlNamespaces[2*index]);
1136 for(index=0; index<nb_attributes; index++)
1138 static const xmlChar xmlA[] = "xml";
1140 if (xmlStrEqual(xmlAttributes[index*5+1], xmlA))
1141 attrs[index].szURI = bstr_from_xmlChar(xmlAttributes[index*5+2]);
1143 attrs[index].szURI = find_element_uri(locator, xmlAttributes[index*5+2]);
1145 attrs[index].szLocalname = bstr_from_xmlChar(xmlAttributes[index*5]);
1146 attrs[index].szValue = bstr_from_xmlCharN(xmlAttributes[index*5+3],
1147 xmlAttributes[index*5+4]-xmlAttributes[index*5+3]);
1148 attrs[index].szQName = QName_from_xmlChar(xmlAttributes[index*5+1],
1149 xmlAttributes[index*5]);
1155 /*** LibXML callbacks ***/
1156 static void libxmlStartDocument(void *ctx)
1158 saxlocator *This = ctx;
1161 if(This->saxreader->version >= MSXML6)
1163 const xmlChar *p = This->pParserCtxt->input->cur-1;
1164 update_position(This, FALSE);
1165 while(p>This->pParserCtxt->input->base && *p!='>')
1167 if(*p=='\n' || (*p=='\r' && *(p+1)!='\n'))
1172 for(; p>=This->pParserCtxt->input->base && *p!='\n' && *p!='\r'; p--)
1176 if(has_content_handler(This))
1178 if(This->vbInterface)
1179 hr = IVBSAXContentHandler_startDocument(This->saxreader->vbcontentHandler);
1181 hr = ISAXContentHandler_startDocument(This->saxreader->contentHandler);
1183 if (sax_callback_failed(This, hr))
1184 format_error_message_from_id(This, hr);
1188 static void libxmlEndDocument(void *ctx)
1190 saxlocator *This = ctx;
1193 if(This->saxreader->version >= MSXML6) {
1194 update_position(This, FALSE);
1195 if(This->column > 1)
1203 if(This->ret != S_OK) return;
1205 if(has_content_handler(This))
1207 if(This->vbInterface)
1208 hr = IVBSAXContentHandler_endDocument(This->saxreader->vbcontentHandler);
1210 hr = ISAXContentHandler_endDocument(This->saxreader->contentHandler);
1212 if (sax_callback_failed(This, hr))
1213 format_error_message_from_id(This, hr);
1217 static void libxmlStartElementNS(
1219 const xmlChar *localname,
1220 const xmlChar *prefix,
1223 const xmlChar **namespaces,
1226 const xmlChar **attributes)
1228 saxlocator *This = ctx;
1229 element_entry *element;
1232 update_position(This, TRUE);
1233 if(*(This->pParserCtxt->input->cur) == '/')
1235 if(This->saxreader->version < MSXML6)
1238 element = alloc_element_entry(localname, prefix, nb_namespaces, namespaces);
1239 push_element_ns(This, element);
1241 if (has_content_handler(This))
1246 for (i = 0; i < nb_namespaces; i++)
1248 if(This->vbInterface)
1249 hr = IVBSAXContentHandler_startPrefixMapping(
1250 This->saxreader->vbcontentHandler,
1251 &element->ns[i].prefix,
1252 &element->ns[i].uri);
1254 hr = ISAXContentHandler_startPrefixMapping(
1255 This->saxreader->contentHandler,
1256 element->ns[i].prefix,
1257 SysStringLen(element->ns[i].prefix),
1259 SysStringLen(element->ns[i].uri));
1261 if (sax_callback_failed(This, hr))
1263 format_error_message_from_id(This, hr);
1268 uri = find_element_uri(This, URI);
1270 hr = SAXAttributes_populate(This, nb_namespaces, namespaces, nb_attributes, attributes);
1273 if(This->vbInterface)
1274 hr = IVBSAXContentHandler_startElement(This->saxreader->vbcontentHandler,
1275 &uri, &element->local, &element->qname, &This->IVBSAXAttributes_iface);
1277 hr = ISAXContentHandler_startElement(This->saxreader->contentHandler,
1278 uri, SysStringLen(uri),
1279 element->local, SysStringLen(element->local),
1280 element->qname, SysStringLen(element->qname),
1281 &This->ISAXAttributes_iface);
1285 if (sax_callback_failed(This, hr))
1286 format_error_message_from_id(This, hr);
1289 static void libxmlEndElementNS(
1291 const xmlChar *localname,
1292 const xmlChar *prefix,
1295 saxlocator *This = ctx;
1296 element_entry *element;
1302 update_position(This, FALSE);
1303 p = This->pParserCtxt->input->cur;
1304 if(This->saxreader->version >= MSXML6)
1307 while(p>This->pParserCtxt->input->base && *p!='>')
1309 if(*p=='\n' || (*p=='\r' && *(p+1)!='\n'))
1314 else if(*(p-1)!='>' || *(p-2)!='/')
1317 while(p-2>=This->pParserCtxt->input->base
1318 && *(p-2)!='<' && *(p-1)!='/')
1320 if(*p=='\n' || (*p=='\r' && *(p+1)!='\n'))
1326 for(; p>=This->pParserCtxt->input->base && *p!='\n' && *p!='\r'; p--)
1329 uri = find_element_uri(This, URI);
1330 element = pop_element_ns(This);
1332 if (!has_content_handler(This))
1334 This->nb_attributes = 0;
1335 free_element_entry(element);
1339 if(This->vbInterface)
1340 hr = IVBSAXContentHandler_endElement(
1341 This->saxreader->vbcontentHandler,
1342 &uri, &element->local, &element->qname);
1344 hr = ISAXContentHandler_endElement(
1345 This->saxreader->contentHandler,
1346 uri, SysStringLen(uri),
1347 element->local, SysStringLen(element->local),
1348 element->qname, SysStringLen(element->qname));
1350 This->nb_attributes = 0;
1352 if (sax_callback_failed(This, hr))
1354 format_error_message_from_id(This, hr);
1355 free_element_entry(element);
1360 while (iterate_endprefix_index(This, element, &i))
1362 if(This->vbInterface)
1363 hr = IVBSAXContentHandler_endPrefixMapping(
1364 This->saxreader->vbcontentHandler, &element->ns[i].prefix);
1366 hr = ISAXContentHandler_endPrefixMapping(
1367 This->saxreader->contentHandler,
1368 element->ns[i].prefix, SysStringLen(element->ns[i].prefix));
1370 if (sax_callback_failed(This, hr)) break;
1373 if (sax_callback_failed(This, hr))
1374 format_error_message_from_id(This, hr);
1376 free_element_entry(element);
1379 static void libxmlCharacters(
1384 saxlocator *This = ctx;
1388 BOOL lastEvent = FALSE;
1390 if(!(has_content_handler(This))) return;
1392 update_position(This, FALSE);
1393 cur = (xmlChar*)This->pParserCtxt->input->cur;
1394 while(cur>=This->pParserCtxt->input->base && *cur!='>')
1396 if(*cur=='\n' || (*cur=='\r' && *(cur+1)!='\n'))
1401 for(; cur>=This->pParserCtxt->input->base && *cur!='\n' && *cur!='\r'; cur--)
1405 if(*(ch-1)=='\r') cur--;
1410 while(end-ch<len && *end!='\r') end++;
1421 if(This->saxreader->version >= MSXML6)
1425 for(p=cur; p!=end; p++)
1442 Chars = pooled_bstr_from_xmlCharN(&This->saxreader->pool, cur, end-cur);
1443 if(This->vbInterface)
1444 hr = IVBSAXContentHandler_characters(
1445 This->saxreader->vbcontentHandler, &Chars);
1447 hr = ISAXContentHandler_characters(
1448 This->saxreader->contentHandler,
1449 Chars, SysStringLen(Chars));
1451 if (sax_callback_failed(This, hr))
1453 format_error_message_from_id(This, hr);
1457 if(This->saxreader->version < MSXML6)
1458 This->column += end-cur;
1471 if(end-ch == len) break;
1475 static void libxmlSetDocumentLocator(
1477 xmlSAXLocatorPtr loc)
1479 saxlocator *This = ctx;
1482 if(has_content_handler(This))
1484 if(This->vbInterface)
1485 hr = IVBSAXContentHandler_putref_documentLocator(This->saxreader->vbcontentHandler,
1486 &This->IVBSAXLocator_iface);
1488 hr = ISAXContentHandler_putDocumentLocator(This->saxreader->contentHandler,
1489 &This->ISAXLocator_iface);
1493 format_error_message_from_id(This, hr);
1496 static void libxmlComment(void *ctx, const xmlChar *value)
1498 saxlocator *This = ctx;
1501 const xmlChar *p = This->pParserCtxt->input->cur;
1503 update_position(This, FALSE);
1504 while(p-4>=This->pParserCtxt->input->base
1505 && memcmp(p-4, "<!--", sizeof(char[4])))
1507 if(*p=='\n' || (*p=='\r' && *(p+1)!='\n'))
1512 for(; p>=This->pParserCtxt->input->base && *p!='\n' && *p!='\r'; p--)
1515 if(!This->vbInterface && !This->saxreader->lexicalHandler) return;
1516 if(This->vbInterface && !This->saxreader->vblexicalHandler) return;
1518 bValue = pooled_bstr_from_xmlChar(&This->saxreader->pool, value);
1520 if(This->vbInterface)
1521 hr = IVBSAXLexicalHandler_comment(
1522 This->saxreader->vblexicalHandler, &bValue);
1524 hr = ISAXLexicalHandler_comment(
1525 This->saxreader->lexicalHandler,
1526 bValue, SysStringLen(bValue));
1529 format_error_message_from_id(This, hr);
1532 static void libxmlFatalError(void *ctx, const char *msg, ...)
1534 saxlocator *This = ctx;
1540 if(This->ret != S_OK) {
1541 xmlStopParser(This->pParserCtxt);
1545 va_start(args, msg);
1546 vsprintf(message, msg, args);
1549 len = MultiByteToWideChar(CP_UNIXCP, 0, message, -1, NULL, 0);
1550 error = heap_alloc(sizeof(WCHAR)*len);
1553 MultiByteToWideChar(CP_UNIXCP, 0, message, -1, error, len);
1554 TRACE("fatal error for %p: %s\n", This, debugstr_w(error));
1557 if(!has_error_handler(This))
1559 xmlStopParser(This->pParserCtxt);
1565 FIXME("Error handling is not compatible.\n");
1567 if(This->vbInterface)
1569 BSTR bstrError = SysAllocString(error);
1570 IVBSAXErrorHandler_fatalError(This->saxreader->vberrorHandler, &This->IVBSAXLocator_iface,
1571 &bstrError, E_FAIL);
1572 SysFreeString(bstrError);
1575 ISAXErrorHandler_fatalError(This->saxreader->errorHandler, &This->ISAXLocator_iface,
1580 xmlStopParser(This->pParserCtxt);
1584 static void libxmlCDataBlock(void *ctx, const xmlChar *value, int len)
1586 saxlocator *This = ctx;
1588 xmlChar *beg = (xmlChar*)This->pParserCtxt->input->cur-len;
1592 BOOL lastEvent = FALSE, change;
1594 update_position(This, FALSE);
1595 while(beg-9>=This->pParserCtxt->input->base
1596 && memcmp(beg-9, "<![CDATA[", sizeof(char[9])))
1598 if(*beg=='\n' || (*beg=='\r' && *(beg+1)!='\n'))
1603 for(; beg>=This->pParserCtxt->input->base && *beg!='\n' && *beg!='\r'; beg--)
1606 if(This->vbInterface && This->saxreader->vblexicalHandler)
1607 hr = IVBSAXLexicalHandler_startCDATA(This->saxreader->vblexicalHandler);
1608 if(!This->vbInterface && This->saxreader->lexicalHandler)
1609 hr = ISAXLexicalHandler_startCDATA(This->saxreader->lexicalHandler);
1613 format_error_message_from_id(This, hr);
1617 realLen = This->pParserCtxt->input->cur-beg-3;
1623 while(end-beg<realLen && *end!='\r') end++;
1624 if(end-beg==realLen)
1629 else if(end-beg==realLen-1 && *end=='\r' && *(end+1)=='\n')
1632 if(*end == '\r') change = TRUE;
1633 else change = FALSE;
1635 if(change) *end = '\n';
1637 if(has_content_handler(This))
1639 Chars = pooled_bstr_from_xmlCharN(&This->saxreader->pool, cur, end-cur+1);
1640 if(This->vbInterface)
1641 hr = IVBSAXContentHandler_characters(
1642 This->saxreader->vbcontentHandler, &Chars);
1644 hr = ISAXContentHandler_characters(
1645 This->saxreader->contentHandler,
1646 Chars, SysStringLen(Chars));
1649 if(change) *end = '\r';
1654 This->column += end-cur+2;
1659 if(This->vbInterface && This->saxreader->vblexicalHandler)
1660 hr = IVBSAXLexicalHandler_endCDATA(This->saxreader->vblexicalHandler);
1661 if(!This->vbInterface && This->saxreader->lexicalHandler)
1662 hr = ISAXLexicalHandler_endCDATA(This->saxreader->lexicalHandler);
1665 format_error_message_from_id(This, hr);
1667 This->column += 4+end-cur;
1670 /*** IVBSAXLocator interface ***/
1671 /*** IUnknown methods ***/
1672 static HRESULT WINAPI ivbsaxlocator_QueryInterface(IVBSAXLocator* iface, REFIID riid, void **ppvObject)
1674 saxlocator *This = impl_from_IVBSAXLocator( iface );
1676 TRACE("%p %s %p\n", This, debugstr_guid( riid ), ppvObject);
1680 if ( IsEqualGUID( riid, &IID_IUnknown ) ||
1681 IsEqualGUID( riid, &IID_IDispatch) ||
1682 IsEqualGUID( riid, &IID_IVBSAXLocator ))
1686 else if ( IsEqualGUID( riid, &IID_IVBSAXAttributes ))
1688 *ppvObject = &This->IVBSAXAttributes_iface;
1692 FIXME("interface %s not implemented\n", debugstr_guid(riid));
1693 return E_NOINTERFACE;
1696 IVBSAXLocator_AddRef( iface );
1701 static ULONG WINAPI ivbsaxlocator_AddRef(IVBSAXLocator* iface)
1703 saxlocator *This = impl_from_IVBSAXLocator( iface );
1704 TRACE("%p\n", This );
1705 return InterlockedIncrement( &This->ref );
1708 static ULONG WINAPI ivbsaxlocator_Release(
1709 IVBSAXLocator* iface)
1711 saxlocator *This = impl_from_IVBSAXLocator( iface );
1712 return ISAXLocator_Release((ISAXLocator*)&This->IVBSAXLocator_iface);
1715 /*** IDispatch methods ***/
1716 static HRESULT WINAPI ivbsaxlocator_GetTypeInfoCount( IVBSAXLocator *iface, UINT* pctinfo )
1718 saxlocator *This = impl_from_IVBSAXLocator( iface );
1720 TRACE("(%p)->(%p)\n", This, pctinfo);
1727 static HRESULT WINAPI ivbsaxlocator_GetTypeInfo(
1728 IVBSAXLocator *iface,
1729 UINT iTInfo, LCID lcid, ITypeInfo** ppTInfo )
1731 saxlocator *This = impl_from_IVBSAXLocator( iface );
1734 TRACE("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo);
1736 hr = get_typeinfo(IVBSAXLocator_tid, ppTInfo);
1741 static HRESULT WINAPI ivbsaxlocator_GetIDsOfNames(
1742 IVBSAXLocator *iface,
1744 LPOLESTR* rgszNames,
1749 saxlocator *This = impl_from_IVBSAXLocator( iface );
1750 ITypeInfo *typeinfo;
1753 TRACE("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames, cNames,
1756 if(!rgszNames || cNames == 0 || !rgDispId)
1757 return E_INVALIDARG;
1759 hr = get_typeinfo(IVBSAXLocator_tid, &typeinfo);
1762 hr = ITypeInfo_GetIDsOfNames(typeinfo, rgszNames, cNames, rgDispId);
1763 ITypeInfo_Release(typeinfo);
1769 static HRESULT WINAPI ivbsaxlocator_Invoke(
1770 IVBSAXLocator *iface,
1771 DISPID dispIdMember,
1775 DISPPARAMS* pDispParams,
1776 VARIANT* pVarResult,
1777 EXCEPINFO* pExcepInfo,
1780 saxlocator *This = impl_from_IVBSAXLocator( iface );
1781 ITypeInfo *typeinfo;
1784 TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
1785 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
1787 hr = get_typeinfo(IVBSAXLocator_tid, &typeinfo);
1790 hr = ITypeInfo_Invoke(typeinfo, &This->IVBSAXLocator_iface, dispIdMember, wFlags,
1791 pDispParams, pVarResult, pExcepInfo, puArgErr);
1792 ITypeInfo_Release(typeinfo);
1798 /*** IVBSAXLocator methods ***/
1799 static HRESULT WINAPI ivbsaxlocator_get_columnNumber(
1800 IVBSAXLocator* iface,
1803 saxlocator *This = impl_from_IVBSAXLocator( iface );
1804 return ISAXLocator_getColumnNumber((ISAXLocator*)&This->IVBSAXLocator_iface, pnColumn);
1807 static HRESULT WINAPI ivbsaxlocator_get_lineNumber(
1808 IVBSAXLocator* iface,
1811 saxlocator *This = impl_from_IVBSAXLocator( iface );
1812 return ISAXLocator_getLineNumber((ISAXLocator*)&This->IVBSAXLocator_iface, pnLine);
1815 static HRESULT WINAPI ivbsaxlocator_get_publicId(
1816 IVBSAXLocator* iface,
1819 saxlocator *This = impl_from_IVBSAXLocator( iface );
1820 return ISAXLocator_getPublicId((ISAXLocator*)&This->IVBSAXLocator_iface,
1821 (const WCHAR**)publicId);
1824 static HRESULT WINAPI ivbsaxlocator_get_systemId(
1825 IVBSAXLocator* iface,
1828 saxlocator *This = impl_from_IVBSAXLocator( iface );
1829 return ISAXLocator_getSystemId((ISAXLocator*)&This->IVBSAXLocator_iface,
1830 (const WCHAR**)systemId);
1833 static const struct IVBSAXLocatorVtbl VBSAXLocatorVtbl =
1835 ivbsaxlocator_QueryInterface,
1836 ivbsaxlocator_AddRef,
1837 ivbsaxlocator_Release,
1838 ivbsaxlocator_GetTypeInfoCount,
1839 ivbsaxlocator_GetTypeInfo,
1840 ivbsaxlocator_GetIDsOfNames,
1841 ivbsaxlocator_Invoke,
1842 ivbsaxlocator_get_columnNumber,
1843 ivbsaxlocator_get_lineNumber,
1844 ivbsaxlocator_get_publicId,
1845 ivbsaxlocator_get_systemId
1848 /*** ISAXLocator interface ***/
1849 /*** IUnknown methods ***/
1850 static HRESULT WINAPI isaxlocator_QueryInterface(ISAXLocator* iface, REFIID riid, void **ppvObject)
1852 saxlocator *This = impl_from_ISAXLocator( iface );
1854 TRACE("%p %s %p\n", This, debugstr_guid( riid ), ppvObject );
1858 if ( IsEqualGUID( riid, &IID_IUnknown ) ||
1859 IsEqualGUID( riid, &IID_ISAXLocator ))
1863 else if ( IsEqualGUID( riid, &IID_ISAXAttributes ))
1865 *ppvObject = &This->ISAXAttributes_iface;
1869 FIXME("interface %s not implemented\n", debugstr_guid(riid));
1870 return E_NOINTERFACE;
1873 ISAXLocator_AddRef( iface );
1878 static ULONG WINAPI isaxlocator_AddRef(ISAXLocator* iface)
1880 saxlocator *This = impl_from_ISAXLocator( iface );
1881 ULONG ref = InterlockedIncrement( &This->ref );
1882 TRACE("(%p)->(%d)\n", This, ref);
1886 static ULONG WINAPI isaxlocator_Release(
1889 saxlocator *This = impl_from_ISAXLocator( iface );
1890 LONG ref = InterlockedDecrement( &This->ref );
1892 TRACE("(%p)->(%d)\n", This, ref );
1896 element_entry *element, *element2;
1899 SysFreeString(This->publicId);
1900 SysFreeString(This->systemId);
1901 SysFreeString(This->namespaceUri);
1903 for(index=0; index<This->nb_attributes; index++)
1905 SysFreeString(This->attributes[index].szLocalname);
1906 SysFreeString(This->attributes[index].szValue);
1907 SysFreeString(This->attributes[index].szQName);
1909 heap_free(This->attributes);
1912 LIST_FOR_EACH_ENTRY_SAFE(element, element2, &This->elements, element_entry, entry)
1914 list_remove(&element->entry);
1915 free_element_entry(element);
1918 ISAXXMLReader_Release(&This->saxreader->ISAXXMLReader_iface);
1925 /*** ISAXLocator methods ***/
1926 static HRESULT WINAPI isaxlocator_getColumnNumber(
1930 saxlocator *This = impl_from_ISAXLocator( iface );
1932 *pnColumn = This->column;
1936 static HRESULT WINAPI isaxlocator_getLineNumber(
1940 saxlocator *This = impl_from_ISAXLocator( iface );
1942 *pnLine = This->line;
1946 static HRESULT WINAPI isaxlocator_getPublicId(
1948 const WCHAR ** ppwchPublicId)
1951 saxlocator *This = impl_from_ISAXLocator( iface );
1953 SysFreeString(This->publicId);
1955 publicId = bstr_from_xmlChar(xmlSAX2GetPublicId(This->pParserCtxt));
1956 if(SysStringLen(publicId))
1957 This->publicId = (WCHAR*)&publicId;
1960 SysFreeString(publicId);
1961 This->publicId = NULL;
1964 *ppwchPublicId = This->publicId;
1968 static HRESULT WINAPI isaxlocator_getSystemId(
1970 const WCHAR ** ppwchSystemId)
1973 saxlocator *This = impl_from_ISAXLocator( iface );
1975 SysFreeString(This->systemId);
1977 systemId = bstr_from_xmlChar(xmlSAX2GetSystemId(This->pParserCtxt));
1978 if(SysStringLen(systemId))
1979 This->systemId = (WCHAR*)&systemId;
1982 SysFreeString(systemId);
1983 This->systemId = NULL;
1986 *ppwchSystemId = This->systemId;
1990 static const struct ISAXLocatorVtbl SAXLocatorVtbl =
1992 isaxlocator_QueryInterface,
1994 isaxlocator_Release,
1995 isaxlocator_getColumnNumber,
1996 isaxlocator_getLineNumber,
1997 isaxlocator_getPublicId,
1998 isaxlocator_getSystemId
2001 static HRESULT SAXLocator_create(saxreader *reader, saxlocator **ppsaxlocator, BOOL vbInterface)
2003 static const WCHAR w3xmlns[] = { 'h','t','t','p',':','/','/', 'w','w','w','.','w','3','.',
2004 'o','r','g','/','2','0','0','0','/','x','m','l','n','s','/',0 };
2006 saxlocator *locator;
2008 locator = heap_alloc( sizeof (*locator) );
2010 return E_OUTOFMEMORY;
2012 locator->IVBSAXLocator_iface.lpVtbl = &VBSAXLocatorVtbl;
2013 locator->ISAXLocator_iface.lpVtbl = &SAXLocatorVtbl;
2014 locator->IVBSAXAttributes_iface.lpVtbl = &ivbsaxattributes_vtbl;
2015 locator->ISAXAttributes_iface.lpVtbl = &isaxattributes_vtbl;
2017 locator->vbInterface = vbInterface;
2019 locator->saxreader = reader;
2020 ISAXXMLReader_AddRef(&reader->ISAXXMLReader_iface);
2022 locator->pParserCtxt = NULL;
2023 locator->publicId = NULL;
2024 locator->systemId = NULL;
2025 locator->line = (reader->version>=MSXML6 ? 1 : 0);
2026 locator->column = 0;
2027 locator->ret = S_OK;
2028 if(locator->saxreader->version >= MSXML6)
2029 locator->namespaceUri = SysAllocString(w3xmlns);
2031 locator->namespaceUri = SysAllocStringLen(NULL, 0);
2032 if(!locator->namespaceUri)
2034 ISAXXMLReader_Release(&reader->ISAXXMLReader_iface);
2036 return E_OUTOFMEMORY;
2039 locator->attributesSize = 8;
2040 locator->nb_attributes = 0;
2041 locator->attributes = heap_alloc(sizeof(struct _attributes)*locator->attributesSize);
2042 if(!locator->attributes)
2044 ISAXXMLReader_Release(&reader->ISAXXMLReader_iface);
2045 SysFreeString(locator->namespaceUri);
2047 return E_OUTOFMEMORY;
2050 list_init(&locator->elements);
2052 *ppsaxlocator = locator;
2054 TRACE("returning %p\n", *ppsaxlocator);
2059 /*** SAXXMLReader internal functions ***/
2060 static HRESULT internal_parseBuffer(saxreader *This, const char *buffer, int size, BOOL vbInterface)
2062 xmlCharEncoding encoding = XML_CHAR_ENCODING_NONE;
2063 xmlChar *enc_name = NULL;
2064 saxlocator *locator;
2067 hr = SAXLocator_create(This, &locator, vbInterface);
2073 const unsigned char *buff = (unsigned char*)buffer;
2075 encoding = xmlDetectCharEncoding((xmlChar*)buffer, 4);
2076 enc_name = (xmlChar*)xmlGetCharEncodingName(encoding);
2077 TRACE("detected encoding: %s\n", enc_name);
2078 /* skip BOM, parser won't switch encodings and so won't skip it on its own */
2079 if ((encoding == XML_CHAR_ENCODING_UTF8) &&
2080 buff[0] == 0xEF && buff[1] == 0xBB && buff[2] == 0xBF)
2087 locator->pParserCtxt = xmlCreateMemoryParserCtxt(buffer, size);
2088 if(!locator->pParserCtxt)
2090 ISAXLocator_Release(&locator->ISAXLocator_iface);
2094 if (encoding == XML_CHAR_ENCODING_UTF8)
2095 locator->pParserCtxt->encoding = xmlStrdup(enc_name);
2097 xmlFree(locator->pParserCtxt->sax);
2098 locator->pParserCtxt->sax = &locator->saxreader->sax;
2099 locator->pParserCtxt->userData = locator;
2101 This->isParsing = TRUE;
2102 if(xmlParseDocument(locator->pParserCtxt)==-1 && locator->ret==S_OK)
2106 This->isParsing = FALSE;
2108 if(locator->pParserCtxt)
2110 locator->pParserCtxt->sax = NULL;
2111 xmlFreeParserCtxt(locator->pParserCtxt);
2112 locator->pParserCtxt = NULL;
2115 ISAXLocator_Release(&locator->ISAXLocator_iface);
2119 static HRESULT internal_parseStream(saxreader *This, IStream *stream, BOOL vbInterface)
2121 saxlocator *locator;
2128 hr = IStream_Read(stream, data, sizeof(data), &dataRead);
2129 if(FAILED(hr)) return hr;
2131 hr = SAXLocator_create(This, &locator, vbInterface);
2132 if(FAILED(hr)) return hr;
2134 locator->pParserCtxt = xmlCreatePushParserCtxt(
2135 &locator->saxreader->sax, locator,
2136 data, dataRead, NULL);
2137 if(!locator->pParserCtxt)
2139 ISAXLocator_Release(&locator->ISAXLocator_iface);
2143 This->isParsing = TRUE;
2145 if(dataRead != sizeof(data))
2147 ret = xmlParseChunk(locator->pParserCtxt, data, 0, 1);
2148 hr = ret!=XML_ERR_OK && locator->ret==S_OK ? E_FAIL : locator->ret;
2155 hr = IStream_Read(stream, data, sizeof(data), &dataRead);
2156 if (FAILED(hr)) break;
2158 ret = xmlParseChunk(locator->pParserCtxt, data, dataRead, 0);
2159 hr = ret!=XML_ERR_OK && locator->ret==S_OK ? E_FAIL : locator->ret;
2161 if (hr != S_OK) break;
2163 if (dataRead != sizeof(data))
2165 ret = xmlParseChunk(locator->pParserCtxt, data, 0, 1);
2166 hr = ret!=XML_ERR_OK && locator->ret==S_OK ? E_FAIL : locator->ret;
2172 This->isParsing = FALSE;
2174 xmlFreeParserCtxt(locator->pParserCtxt);
2175 locator->pParserCtxt = NULL;
2176 ISAXLocator_Release(&locator->ISAXLocator_iface);
2180 static HRESULT internal_getEntityResolver(
2182 void *pEntityResolver,
2185 FIXME("(%p)->(%p) stub\n", This, pEntityResolver);
2189 static HRESULT internal_putEntityResolver(
2191 void *pEntityResolver,
2194 FIXME("(%p)->(%p) stub\n", This, pEntityResolver);
2198 static HRESULT internal_getContentHandler(
2200 void *pContentHandler,
2203 TRACE("(%p)->(%p)\n", This, pContentHandler);
2204 if(pContentHandler == NULL)
2206 if((vbInterface && This->vbcontentHandler)
2207 || (!vbInterface && This->contentHandler))
2210 IVBSAXContentHandler_AddRef(This->vbcontentHandler);
2212 ISAXContentHandler_AddRef(This->contentHandler);
2214 if(vbInterface) *(IVBSAXContentHandler**)pContentHandler =
2215 This->vbcontentHandler;
2216 else *(ISAXContentHandler**)pContentHandler = This->contentHandler;
2221 static HRESULT internal_putContentHandler(
2223 void *contentHandler,
2226 TRACE("(%p)->(%p)\n", This, contentHandler);
2230 IVBSAXContentHandler_AddRef((IVBSAXContentHandler*)contentHandler);
2232 ISAXContentHandler_AddRef((ISAXContentHandler*)contentHandler);
2234 if((vbInterface && This->vbcontentHandler)
2235 || (!vbInterface && This->contentHandler))
2238 IVBSAXContentHandler_Release(This->vbcontentHandler);
2240 ISAXContentHandler_Release(This->contentHandler);
2243 This->vbcontentHandler = contentHandler;
2245 This->contentHandler = contentHandler;
2250 static HRESULT internal_getDTDHandler(
2255 FIXME("(%p)->(%p) stub\n", This, pDTDHandler);
2259 static HRESULT internal_putDTDHandler(
2264 FIXME("(%p)->(%p) stub\n", This, pDTDHandler);
2268 static HRESULT internal_getErrorHandler(
2270 void *pErrorHandler,
2273 TRACE("(%p)->(%p)\n", This, pErrorHandler);
2274 if(pErrorHandler == NULL)
2277 if(vbInterface && This->vberrorHandler)
2278 IVBSAXErrorHandler_AddRef(This->vberrorHandler);
2279 else if(!vbInterface && This->errorHandler)
2280 ISAXErrorHandler_AddRef(This->errorHandler);
2283 *(IVBSAXErrorHandler**)pErrorHandler = This->vberrorHandler;
2285 *(ISAXErrorHandler**)pErrorHandler = This->errorHandler;
2291 static HRESULT internal_putErrorHandler(
2296 TRACE("(%p)->(%p)\n", This, errorHandler);
2300 IVBSAXErrorHandler_AddRef((IVBSAXErrorHandler*)errorHandler);
2302 ISAXErrorHandler_AddRef((ISAXErrorHandler*)errorHandler);
2305 if(vbInterface && This->vberrorHandler)
2306 IVBSAXErrorHandler_Release(This->vberrorHandler);
2307 else if(!vbInterface && This->errorHandler)
2308 ISAXErrorHandler_Release(This->errorHandler);
2311 This->vberrorHandler = errorHandler;
2313 This->errorHandler = errorHandler;
2319 static HRESULT internal_parse(
2326 TRACE("(%p)->(%s)\n", This, debugstr_variant(&varInput));
2328 /* Dispose of the BSTRs in the pool from a prior run, if any. */
2329 free_bstr_pool(&This->pool);
2331 switch(V_VT(&varInput))
2334 hr = internal_parseBuffer(This, (const char*)V_BSTR(&varInput),
2335 SysStringByteLen(V_BSTR(&varInput)), vbInterface);
2337 case VT_ARRAY|VT_UI1: {
2339 LONG lBound, uBound;
2342 hr = SafeArrayGetLBound(V_ARRAY(&varInput), 1, &lBound);
2343 if(hr != S_OK) break;
2344 hr = SafeArrayGetUBound(V_ARRAY(&varInput), 1, &uBound);
2345 if(hr != S_OK) break;
2346 dataRead = (uBound-lBound)*SafeArrayGetElemsize(V_ARRAY(&varInput));
2347 hr = SafeArrayAccessData(V_ARRAY(&varInput), &pSAData);
2348 if(hr != S_OK) break;
2349 hr = internal_parseBuffer(This, pSAData, dataRead, vbInterface);
2350 SafeArrayUnaccessData(V_ARRAY(&varInput));
2355 IPersistStream *persistStream;
2356 IStream *stream = NULL;
2357 IXMLDOMDocument *xmlDoc;
2359 if(IUnknown_QueryInterface(V_UNKNOWN(&varInput),
2360 &IID_IXMLDOMDocument, (void**)&xmlDoc) == S_OK)
2364 IXMLDOMDocument_get_xml(xmlDoc, &bstrData);
2365 hr = internal_parseBuffer(This, (const char*)bstrData,
2366 SysStringByteLen(bstrData), vbInterface);
2367 IXMLDOMDocument_Release(xmlDoc);
2368 SysFreeString(bstrData);
2372 if(IUnknown_QueryInterface(V_UNKNOWN(&varInput),
2373 &IID_IPersistStream, (void**)&persistStream) == S_OK)
2375 hr = CreateStreamOnHGlobal(NULL, TRUE, &stream);
2378 IPersistStream_Release(persistStream);
2382 hr = IPersistStream_Save(persistStream, stream, TRUE);
2383 IPersistStream_Release(persistStream);
2386 IStream_Release(stream);
2391 if(stream || IUnknown_QueryInterface(V_UNKNOWN(&varInput),
2392 &IID_IStream, (void**)&stream) == S_OK)
2394 hr = internal_parseStream(This, stream, vbInterface);
2395 IStream_Release(stream);
2400 WARN("vt %d not implemented\n", V_VT(&varInput));
2407 static HRESULT internal_vbonDataAvailable(void *obj, char *ptr, DWORD len)
2409 saxreader *This = obj;
2411 return internal_parseBuffer(This, ptr, len, TRUE);
2414 static HRESULT internal_onDataAvailable(void *obj, char *ptr, DWORD len)
2416 saxreader *This = obj;
2418 return internal_parseBuffer(This, ptr, len, FALSE);
2421 static HRESULT internal_parseURL(
2430 TRACE("(%p)->(%s)\n", This, debugstr_w(url));
2432 hr = create_moniker_from_url(url, &mon);
2436 if(vbInterface) hr = bind_url(mon, internal_vbonDataAvailable, This, &bsc);
2437 else hr = bind_url(mon, internal_onDataAvailable, This, &bsc);
2438 IMoniker_Release(mon);
2443 return detach_bsc(bsc);
2446 static HRESULT internal_putProperty(
2452 TRACE("(%p)->(%s %s)\n", This, debugstr_w(prop), debugstr_variant(&value));
2454 if(!memcmp(prop, PropertyDeclHandlerW, sizeof(PropertyDeclHandlerW)))
2456 if(This->isParsing) return E_FAIL;
2458 switch (V_VT(&value))
2463 if (This->vbdeclHandler)
2465 IVBSAXDeclHandler_Release(This->vbdeclHandler);
2466 This->vbdeclHandler = NULL;
2470 if (This->declHandler)
2472 ISAXDeclHandler_Release(This->declHandler);
2473 This->declHandler = NULL;
2477 if (V_UNKNOWN(&value)) IUnknown_AddRef(V_UNKNOWN(&value));
2479 if ((vbInterface && This->vbdeclHandler) ||
2480 (!vbInterface && This->declHandler))
2483 IVBSAXDeclHandler_Release(This->vbdeclHandler);
2485 ISAXDeclHandler_Release(This->declHandler);
2489 This->vbdeclHandler = (IVBSAXDeclHandler*)V_UNKNOWN(&value);
2491 This->declHandler = (ISAXDeclHandler*)V_UNKNOWN(&value);
2494 return E_INVALIDARG;
2500 if(!memcmp(prop, PropertyLexicalHandlerW, sizeof(PropertyLexicalHandlerW)))
2502 if(This->isParsing) return E_FAIL;
2504 switch (V_VT(&value))
2509 if (This->vblexicalHandler)
2511 IVBSAXLexicalHandler_Release(This->vblexicalHandler);
2512 This->vblexicalHandler = NULL;
2516 if (This->lexicalHandler)
2518 ISAXLexicalHandler_Release(This->lexicalHandler);
2519 This->lexicalHandler = NULL;
2523 if (V_UNKNOWN(&value)) IUnknown_AddRef(V_UNKNOWN(&value));
2525 if ((vbInterface && This->vblexicalHandler) ||
2526 (!vbInterface && This->lexicalHandler))
2529 IVBSAXLexicalHandler_Release(This->vblexicalHandler);
2531 ISAXLexicalHandler_Release(This->lexicalHandler);
2535 This->vblexicalHandler = (IVBSAXLexicalHandler*)V_UNKNOWN(&value);
2537 This->lexicalHandler = (ISAXLexicalHandler*)V_UNKNOWN(&value);
2540 return E_INVALIDARG;
2546 if(!memcmp(prop, PropertyMaxXMLSizeW, sizeof(PropertyMaxXMLSizeW)))
2548 if (V_VT(&value) == VT_I4 && V_I4(&value) == 0) return S_OK;
2549 FIXME("(%p)->(%s): max-xml-size unsupported\n", This, debugstr_variant(&value));
2553 if(!memcmp(prop, PropertyMaxElementDepthW, sizeof(PropertyMaxElementDepthW)))
2555 if (V_VT(&value) == VT_I4 && V_I4(&value) == 0) return S_OK;
2556 FIXME("(%p)->(%s): max-element-depth unsupported\n", This, debugstr_variant(&value));
2560 FIXME("(%p)->(%s:%s): unsupported property\n", This, debugstr_w(prop), debugstr_variant(&value));
2562 if(!memcmp(prop, PropertyCharsetW, sizeof(PropertyCharsetW)))
2565 if(!memcmp(prop, PropertyDomNodeW, sizeof(PropertyDomNodeW)))
2568 if(!memcmp(prop, PropertyInputSourceW, sizeof(PropertyInputSourceW)))
2571 if(!memcmp(prop, PropertySchemaDeclHandlerW, sizeof(PropertySchemaDeclHandlerW)))
2574 if(!memcmp(prop, PropertyXMLDeclEncodingW, sizeof(PropertyXMLDeclEncodingW)))
2577 if(!memcmp(prop, PropertyXMLDeclStandaloneW, sizeof(PropertyXMLDeclStandaloneW)))
2580 if(!memcmp(prop, PropertyXMLDeclVersionW, sizeof(PropertyXMLDeclVersionW)))
2583 return E_INVALIDARG;
2586 static HRESULT internal_getProperty(const saxreader* This, const WCHAR *prop, VARIANT *value, BOOL vb)
2588 TRACE("(%p)->(%s)\n", This, debugstr_w(prop));
2590 if (!value) return E_POINTER;
2592 if (!memcmp(PropertyLexicalHandlerW, prop, sizeof(PropertyLexicalHandlerW)))
2594 V_VT(value) = VT_UNKNOWN;
2595 V_UNKNOWN(value) = vb ? (IUnknown*)This->vblexicalHandler : (IUnknown*)This->lexicalHandler;
2596 if (V_UNKNOWN(value)) IUnknown_AddRef(V_UNKNOWN(value));
2600 if (!memcmp(PropertyDeclHandlerW, prop, sizeof(PropertyDeclHandlerW)))
2602 V_VT(value) = VT_UNKNOWN;
2603 V_UNKNOWN(value) = vb ? (IUnknown*)This->vbdeclHandler : (IUnknown*)This->declHandler;
2604 if (V_UNKNOWN(value)) IUnknown_AddRef(V_UNKNOWN(value));
2608 FIXME("(%p)->(%s) unsupported property\n", This, debugstr_w(prop));
2613 /*** IVBSAXXMLReader interface ***/
2614 /*** IUnknown methods ***/
2615 static HRESULT WINAPI saxxmlreader_QueryInterface(IVBSAXXMLReader* iface, REFIID riid, void **ppvObject)
2617 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2619 TRACE("%p %s %p\n", This, debugstr_guid( riid ), ppvObject );
2623 if ( IsEqualGUID( riid, &IID_IUnknown ) ||
2624 IsEqualGUID( riid, &IID_IDispatch ) ||
2625 IsEqualGUID( riid, &IID_IVBSAXXMLReader ))
2629 else if( IsEqualGUID( riid, &IID_ISAXXMLReader ))
2631 *ppvObject = &This->ISAXXMLReader_iface;
2633 else if (dispex_query_interface(&This->dispex, riid, ppvObject))
2635 return *ppvObject ? S_OK : E_NOINTERFACE;
2639 FIXME("interface %s not implemented\n", debugstr_guid(riid));
2640 return E_NOINTERFACE;
2643 IVBSAXXMLReader_AddRef( iface );
2648 static ULONG WINAPI saxxmlreader_AddRef(IVBSAXXMLReader* iface)
2650 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2651 TRACE("%p\n", This );
2652 return InterlockedIncrement( &This->ref );
2655 static ULONG WINAPI saxxmlreader_Release(
2656 IVBSAXXMLReader* iface)
2658 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2661 TRACE("%p\n", This );
2663 ref = InterlockedDecrement( &This->ref );
2666 if(This->contentHandler)
2667 ISAXContentHandler_Release(This->contentHandler);
2669 if(This->vbcontentHandler)
2670 IVBSAXContentHandler_Release(This->vbcontentHandler);
2672 if(This->errorHandler)
2673 ISAXErrorHandler_Release(This->errorHandler);
2675 if(This->vberrorHandler)
2676 IVBSAXErrorHandler_Release(This->vberrorHandler);
2678 if(This->lexicalHandler)
2679 ISAXLexicalHandler_Release(This->lexicalHandler);
2681 if(This->vblexicalHandler)
2682 IVBSAXLexicalHandler_Release(This->vblexicalHandler);
2684 if(This->declHandler)
2685 ISAXDeclHandler_Release(This->declHandler);
2687 if(This->vbdeclHandler)
2688 IVBSAXDeclHandler_Release(This->vbdeclHandler);
2690 free_bstr_pool(&This->pool);
2692 release_dispex(&This->dispex);
2699 static HRESULT WINAPI saxxmlreader_GetTypeInfoCount( IVBSAXXMLReader *iface, UINT* pctinfo )
2701 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2702 return IDispatchEx_GetTypeInfoCount(&This->dispex.IDispatchEx_iface, pctinfo);
2705 static HRESULT WINAPI saxxmlreader_GetTypeInfo(
2706 IVBSAXXMLReader *iface,
2707 UINT iTInfo, LCID lcid, ITypeInfo** ppTInfo )
2709 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2710 return IDispatchEx_GetTypeInfo(&This->dispex.IDispatchEx_iface,
2711 iTInfo, lcid, ppTInfo);
2714 static HRESULT WINAPI saxxmlreader_GetIDsOfNames(
2715 IVBSAXXMLReader *iface,
2717 LPOLESTR* rgszNames,
2722 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2723 return IDispatchEx_GetIDsOfNames(&This->dispex.IDispatchEx_iface,
2724 riid, rgszNames, cNames, lcid, rgDispId);
2727 static HRESULT WINAPI saxxmlreader_Invoke(
2728 IVBSAXXMLReader *iface,
2729 DISPID dispIdMember,
2733 DISPPARAMS* pDispParams,
2734 VARIANT* pVarResult,
2735 EXCEPINFO* pExcepInfo,
2738 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2739 return IDispatchEx_Invoke(&This->dispex.IDispatchEx_iface,
2740 dispIdMember, riid, lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
2743 /*** IVBSAXXMLReader methods ***/
2744 static HRESULT WINAPI saxxmlreader_getFeature(
2745 IVBSAXXMLReader* iface,
2746 const WCHAR *feature,
2747 VARIANT_BOOL *value)
2749 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2751 if (!strcmpW(FeatureNamespacesW, feature))
2752 return get_feature_value(This, Namespaces, value);
2754 FIXME("(%p)->(%s %p) stub\n", This, debugstr_w(feature), value);
2758 static HRESULT WINAPI saxxmlreader_putFeature(
2759 IVBSAXXMLReader* iface,
2760 const WCHAR *feature,
2763 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2765 TRACE("(%p)->(%s %x)\n", This, debugstr_w(feature), value);
2767 if (!strcmpW(FeatureExternalGeneralEntitiesW, feature) && value == VARIANT_FALSE)
2768 return set_feature_value(This, ExternalGeneralEntities, value);
2770 if (!strcmpW(FeatureExternalParameterEntitiesW, feature) && value == VARIANT_FALSE)
2771 return set_feature_value(This, ExternalParameterEntities, value);
2773 if (!strcmpW(FeatureLexicalHandlerParEntitiesW, feature))
2775 FIXME("(%p)->(%s %x) stub\n", This, debugstr_w(feature), value);
2776 return set_feature_value(This, LexicalHandlerParEntities, value);
2779 if (!strcmpW(FeatureProhibitDTDW, feature))
2781 FIXME("(%p)->(%s %x) stub\n", This, debugstr_w(feature), value);
2782 return set_feature_value(This, ProhibitDTD, value);
2785 if (!strcmpW(FeatureNamespacesW, feature) && value == VARIANT_TRUE)
2786 return set_feature_value(This, Namespaces, value);
2788 FIXME("(%p)->(%s %x) stub\n", This, debugstr_w(feature), value);
2792 static HRESULT WINAPI saxxmlreader_getProperty(
2793 IVBSAXXMLReader* iface,
2797 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2798 return internal_getProperty(This, prop, value, TRUE);
2801 static HRESULT WINAPI saxxmlreader_putProperty(
2802 IVBSAXXMLReader* iface,
2806 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2807 return internal_putProperty(This, pProp, value, TRUE);
2810 static HRESULT WINAPI saxxmlreader_get_entityResolver(
2811 IVBSAXXMLReader* iface,
2812 IVBSAXEntityResolver **pEntityResolver)
2814 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2815 return internal_getEntityResolver(This, pEntityResolver, TRUE);
2818 static HRESULT WINAPI saxxmlreader_put_entityResolver(
2819 IVBSAXXMLReader* iface,
2820 IVBSAXEntityResolver *pEntityResolver)
2822 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2823 return internal_putEntityResolver(This, pEntityResolver, TRUE);
2826 static HRESULT WINAPI saxxmlreader_get_contentHandler(
2827 IVBSAXXMLReader* iface,
2828 IVBSAXContentHandler **ppContentHandler)
2830 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2831 return internal_getContentHandler(This, ppContentHandler, TRUE);
2834 static HRESULT WINAPI saxxmlreader_put_contentHandler(
2835 IVBSAXXMLReader* iface,
2836 IVBSAXContentHandler *contentHandler)
2838 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2839 return internal_putContentHandler(This, contentHandler, TRUE);
2842 static HRESULT WINAPI saxxmlreader_get_dtdHandler(
2843 IVBSAXXMLReader* iface,
2844 IVBSAXDTDHandler **pDTDHandler)
2846 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2847 return internal_getDTDHandler(This, pDTDHandler, TRUE);
2850 static HRESULT WINAPI saxxmlreader_put_dtdHandler(
2851 IVBSAXXMLReader* iface,
2852 IVBSAXDTDHandler *pDTDHandler)
2854 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2855 return internal_putDTDHandler(This, pDTDHandler, TRUE);
2858 static HRESULT WINAPI saxxmlreader_get_errorHandler(
2859 IVBSAXXMLReader* iface,
2860 IVBSAXErrorHandler **pErrorHandler)
2862 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2863 return internal_getErrorHandler(This, pErrorHandler, TRUE);
2866 static HRESULT WINAPI saxxmlreader_put_errorHandler(
2867 IVBSAXXMLReader* iface,
2868 IVBSAXErrorHandler *errorHandler)
2870 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2871 return internal_putErrorHandler(This, errorHandler, TRUE);
2874 static HRESULT WINAPI saxxmlreader_get_baseURL(
2875 IVBSAXXMLReader* iface,
2876 const WCHAR **pBaseUrl)
2878 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2880 FIXME("(%p)->(%p) stub\n", This, pBaseUrl);
2884 static HRESULT WINAPI saxxmlreader_put_baseURL(
2885 IVBSAXXMLReader* iface,
2886 const WCHAR *pBaseUrl)
2888 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2890 FIXME("(%p)->(%s) stub\n", This, debugstr_w(pBaseUrl));
2894 static HRESULT WINAPI saxxmlreader_get_secureBaseURL(
2895 IVBSAXXMLReader* iface,
2896 const WCHAR **pSecureBaseUrl)
2898 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2900 FIXME("(%p)->(%p) stub\n", This, pSecureBaseUrl);
2905 static HRESULT WINAPI saxxmlreader_put_secureBaseURL(
2906 IVBSAXXMLReader* iface,
2907 const WCHAR *secureBaseUrl)
2909 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2911 FIXME("(%p)->(%s) stub\n", This, debugstr_w(secureBaseUrl));
2915 static HRESULT WINAPI saxxmlreader_parse(
2916 IVBSAXXMLReader* iface,
2919 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2920 return internal_parse(This, varInput, TRUE);
2923 static HRESULT WINAPI saxxmlreader_parseURL(
2924 IVBSAXXMLReader* iface,
2927 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2928 return internal_parseURL(This, url, TRUE);
2931 static const struct IVBSAXXMLReaderVtbl VBSAXXMLReaderVtbl =
2933 saxxmlreader_QueryInterface,
2934 saxxmlreader_AddRef,
2935 saxxmlreader_Release,
2936 saxxmlreader_GetTypeInfoCount,
2937 saxxmlreader_GetTypeInfo,
2938 saxxmlreader_GetIDsOfNames,
2939 saxxmlreader_Invoke,
2940 saxxmlreader_getFeature,
2941 saxxmlreader_putFeature,
2942 saxxmlreader_getProperty,
2943 saxxmlreader_putProperty,
2944 saxxmlreader_get_entityResolver,
2945 saxxmlreader_put_entityResolver,
2946 saxxmlreader_get_contentHandler,
2947 saxxmlreader_put_contentHandler,
2948 saxxmlreader_get_dtdHandler,
2949 saxxmlreader_put_dtdHandler,
2950 saxxmlreader_get_errorHandler,
2951 saxxmlreader_put_errorHandler,
2952 saxxmlreader_get_baseURL,
2953 saxxmlreader_put_baseURL,
2954 saxxmlreader_get_secureBaseURL,
2955 saxxmlreader_put_secureBaseURL,
2957 saxxmlreader_parseURL
2960 /*** ISAXXMLReader interface ***/
2961 /*** IUnknown methods ***/
2962 static HRESULT WINAPI isaxxmlreader_QueryInterface(ISAXXMLReader* iface, REFIID riid, void **ppvObject)
2964 saxreader *This = impl_from_ISAXXMLReader( iface );
2965 return saxxmlreader_QueryInterface(&This->IVBSAXXMLReader_iface, riid, ppvObject);
2968 static ULONG WINAPI isaxxmlreader_AddRef(ISAXXMLReader* iface)
2970 saxreader *This = impl_from_ISAXXMLReader( iface );
2971 return saxxmlreader_AddRef(&This->IVBSAXXMLReader_iface);
2974 static ULONG WINAPI isaxxmlreader_Release(ISAXXMLReader* iface)
2976 saxreader *This = impl_from_ISAXXMLReader( iface );
2977 return saxxmlreader_Release(&This->IVBSAXXMLReader_iface);
2980 /*** ISAXXMLReader methods ***/
2981 static HRESULT WINAPI isaxxmlreader_getFeature(
2982 ISAXXMLReader* iface,
2983 const WCHAR *pFeature,
2984 VARIANT_BOOL *pValue)
2986 saxreader *This = impl_from_ISAXXMLReader( iface );
2987 return IVBSAXXMLReader_getFeature(&This->IVBSAXXMLReader_iface, pFeature, pValue);
2990 static HRESULT WINAPI isaxxmlreader_putFeature(
2991 ISAXXMLReader* iface,
2992 const WCHAR *pFeature,
2993 VARIANT_BOOL vfValue)
2995 saxreader *This = impl_from_ISAXXMLReader( iface );
2996 return IVBSAXXMLReader_putFeature(&This->IVBSAXXMLReader_iface, pFeature, vfValue);
2999 static HRESULT WINAPI isaxxmlreader_getProperty(
3000 ISAXXMLReader* iface,
3004 saxreader *This = impl_from_ISAXXMLReader( iface );
3005 return internal_getProperty(This, prop, value, FALSE);
3008 static HRESULT WINAPI isaxxmlreader_putProperty(
3009 ISAXXMLReader* iface,
3013 saxreader *This = impl_from_ISAXXMLReader( iface );
3014 return internal_putProperty(This, pProp, value, FALSE);
3017 static HRESULT WINAPI isaxxmlreader_getEntityResolver(
3018 ISAXXMLReader* iface,
3019 ISAXEntityResolver **ppEntityResolver)
3021 saxreader *This = impl_from_ISAXXMLReader( iface );
3022 return internal_getEntityResolver(This, ppEntityResolver, FALSE);
3025 static HRESULT WINAPI isaxxmlreader_putEntityResolver(
3026 ISAXXMLReader* iface,
3027 ISAXEntityResolver *pEntityResolver)
3029 saxreader *This = impl_from_ISAXXMLReader( iface );
3030 return internal_putEntityResolver(This, pEntityResolver, FALSE);
3033 static HRESULT WINAPI isaxxmlreader_getContentHandler(
3034 ISAXXMLReader* iface,
3035 ISAXContentHandler **pContentHandler)
3037 saxreader *This = impl_from_ISAXXMLReader( iface );
3038 return internal_getContentHandler(This, pContentHandler, FALSE);
3041 static HRESULT WINAPI isaxxmlreader_putContentHandler(
3042 ISAXXMLReader* iface,
3043 ISAXContentHandler *contentHandler)
3045 saxreader *This = impl_from_ISAXXMLReader( iface );
3046 return internal_putContentHandler(This, contentHandler, FALSE);
3049 static HRESULT WINAPI isaxxmlreader_getDTDHandler(
3050 ISAXXMLReader* iface,
3051 ISAXDTDHandler **pDTDHandler)
3053 saxreader *This = impl_from_ISAXXMLReader( iface );
3054 return internal_getDTDHandler(This, pDTDHandler, FALSE);
3057 static HRESULT WINAPI isaxxmlreader_putDTDHandler(
3058 ISAXXMLReader* iface,
3059 ISAXDTDHandler *pDTDHandler)
3061 saxreader *This = impl_from_ISAXXMLReader( iface );
3062 return internal_putDTDHandler(This, pDTDHandler, FALSE);
3065 static HRESULT WINAPI isaxxmlreader_getErrorHandler(
3066 ISAXXMLReader* iface,
3067 ISAXErrorHandler **pErrorHandler)
3069 saxreader *This = impl_from_ISAXXMLReader( iface );
3070 return internal_getErrorHandler(This, pErrorHandler, FALSE);
3073 static HRESULT WINAPI isaxxmlreader_putErrorHandler(
3074 ISAXXMLReader* iface,
3075 ISAXErrorHandler *errorHandler)
3077 saxreader *This = impl_from_ISAXXMLReader( iface );
3078 return internal_putErrorHandler(This, errorHandler, FALSE);
3081 static HRESULT WINAPI isaxxmlreader_getBaseURL(
3082 ISAXXMLReader* iface,
3083 const WCHAR **pBaseUrl)
3085 saxreader *This = impl_from_ISAXXMLReader( iface );
3086 return IVBSAXXMLReader_get_baseURL(&This->IVBSAXXMLReader_iface, pBaseUrl);
3089 static HRESULT WINAPI isaxxmlreader_putBaseURL(
3090 ISAXXMLReader* iface,
3091 const WCHAR *pBaseUrl)
3093 saxreader *This = impl_from_ISAXXMLReader( iface );
3094 return IVBSAXXMLReader_put_baseURL(&This->IVBSAXXMLReader_iface, pBaseUrl);
3097 static HRESULT WINAPI isaxxmlreader_getSecureBaseURL(
3098 ISAXXMLReader* iface,
3099 const WCHAR **pSecureBaseUrl)
3101 saxreader *This = impl_from_ISAXXMLReader( iface );
3102 return IVBSAXXMLReader_get_secureBaseURL(&This->IVBSAXXMLReader_iface, pSecureBaseUrl);
3105 static HRESULT WINAPI isaxxmlreader_putSecureBaseURL(
3106 ISAXXMLReader* iface,
3107 const WCHAR *secureBaseUrl)
3109 saxreader *This = impl_from_ISAXXMLReader( iface );
3110 return IVBSAXXMLReader_put_secureBaseURL(&This->IVBSAXXMLReader_iface, secureBaseUrl);
3113 static HRESULT WINAPI isaxxmlreader_parse(
3114 ISAXXMLReader* iface,
3117 saxreader *This = impl_from_ISAXXMLReader( iface );
3118 return internal_parse(This, varInput, FALSE);
3121 static HRESULT WINAPI isaxxmlreader_parseURL(
3122 ISAXXMLReader* iface,
3125 saxreader *This = impl_from_ISAXXMLReader( iface );
3126 return internal_parseURL(This, url, FALSE);
3129 static const struct ISAXXMLReaderVtbl SAXXMLReaderVtbl =
3131 isaxxmlreader_QueryInterface,
3132 isaxxmlreader_AddRef,
3133 isaxxmlreader_Release,
3134 isaxxmlreader_getFeature,
3135 isaxxmlreader_putFeature,
3136 isaxxmlreader_getProperty,
3137 isaxxmlreader_putProperty,
3138 isaxxmlreader_getEntityResolver,
3139 isaxxmlreader_putEntityResolver,
3140 isaxxmlreader_getContentHandler,
3141 isaxxmlreader_putContentHandler,
3142 isaxxmlreader_getDTDHandler,
3143 isaxxmlreader_putDTDHandler,
3144 isaxxmlreader_getErrorHandler,
3145 isaxxmlreader_putErrorHandler,
3146 isaxxmlreader_getBaseURL,
3147 isaxxmlreader_putBaseURL,
3148 isaxxmlreader_getSecureBaseURL,
3149 isaxxmlreader_putSecureBaseURL,
3150 isaxxmlreader_parse,
3151 isaxxmlreader_parseURL
3154 static const tid_t saxreader_iface_tids[] = {
3155 IVBSAXXMLReader_tid,
3158 static dispex_static_data_t saxreader_dispex = {
3160 IVBSAXXMLReader_tid,
3162 saxreader_iface_tids
3165 HRESULT SAXXMLReader_create(MSXML_VERSION version, IUnknown *outer, LPVOID *ppObj)
3169 TRACE("(%p, %p)\n", outer, ppObj);
3171 reader = heap_alloc( sizeof (*reader) );
3173 return E_OUTOFMEMORY;
3175 reader->IVBSAXXMLReader_iface.lpVtbl = &VBSAXXMLReaderVtbl;
3176 reader->ISAXXMLReader_iface.lpVtbl = &SAXXMLReaderVtbl;
3178 reader->contentHandler = NULL;
3179 reader->vbcontentHandler = NULL;
3180 reader->errorHandler = NULL;
3181 reader->vberrorHandler = NULL;
3182 reader->lexicalHandler = NULL;
3183 reader->vblexicalHandler = NULL;
3184 reader->declHandler = NULL;
3185 reader->vbdeclHandler = NULL;
3186 reader->isParsing = FALSE;
3187 reader->pool.pool = NULL;
3188 reader->pool.index = 0;
3189 reader->pool.len = 0;
3190 reader->features = Namespaces;
3191 reader->version = version;
3193 init_dispex(&reader->dispex, (IUnknown*)&reader->IVBSAXXMLReader_iface, &saxreader_dispex);
3195 memset(&reader->sax, 0, sizeof(xmlSAXHandler));
3196 reader->sax.initialized = XML_SAX2_MAGIC;
3197 reader->sax.startDocument = libxmlStartDocument;
3198 reader->sax.endDocument = libxmlEndDocument;
3199 reader->sax.startElementNs = libxmlStartElementNS;
3200 reader->sax.endElementNs = libxmlEndElementNS;
3201 reader->sax.characters = libxmlCharacters;
3202 reader->sax.setDocumentLocator = libxmlSetDocumentLocator;
3203 reader->sax.comment = libxmlComment;
3204 reader->sax.error = libxmlFatalError;
3205 reader->sax.fatalError = libxmlFatalError;
3206 reader->sax.cdataBlock = libxmlCDataBlock;
3208 *ppObj = &reader->IVBSAXXMLReader_iface;
3210 TRACE("returning iface %p\n", *ppObj);
3217 HRESULT SAXXMLReader_create(MSXML_VERSION version, IUnknown *pUnkOuter, LPVOID *ppObj)
3219 MESSAGE("This program tried to use a SAX XML Reader object, but\n"
3220 "libxml2 support was not present at compile time.\n");