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
);
56 ExhaustiveErrors
= 1 << 1,
57 ExternalGeneralEntities
= 1 << 2,
58 ExternalParameterEntities
= 1 << 3,
59 ForcedResync
= 1 << 4,
60 NamespacePrefixes
= 1 << 5,
62 ParameterEntities
= 1 << 7,
63 PreserveSystemIndentifiers
= 1 << 8,
65 SchemaValidation
= 1 << 10,
66 ServerHttpRequest
= 1 << 11,
67 SuppressValidationfatalError
= 1 << 12,
68 UseInlineSchema
= 1 << 13,
69 UseSchemaLocation
= 1 << 14,
70 LexicalHandlerParEntities
= 1 << 15
74 static const WCHAR FeatureExternalGeneralEntitiesW
[] = {
75 'h','t','t','p',':','/','/','x','m','l','.','o','r','g','/','s','a','x','/',
76 'f','e','a','t','u','r','e','s','/','e','x','t','e','r','n','a','l','-','g','e','n','e','r','a','l',
77 '-','e','n','t','i','t','i','e','s',0
80 static const WCHAR FeatureExternalParameterEntitiesW
[] = {
81 'h','t','t','p',':','/','/','x','m','l','.','o','r','g','/','s','a','x','/','f','e','a','t','u','r','e','s',
82 '/','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
85 static const WCHAR FeatureLexicalHandlerParEntitiesW
[] = {
86 'h','t','t','p',':','/','/','x','m','l','.','o','r','g','/','s','a','x','/','f','e','a','t','u','r','e','s',
87 '/','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
90 static const WCHAR FeatureProhibitDTDW
[] = {
91 'p','r','o','h','i','b','i','t','-','d','t','d',0
94 static const WCHAR FeatureNamespacesW
[] = {
95 'h','t','t','p',':','/','/','x','m','l','.','o','r','g','/','s','a','x','/','f','e','a','t','u','r','e','s',
96 '/','n','a','m','e','s','p','a','c','e','s',0
99 static const WCHAR FeatureNamespacePrefixesW
[] = {
100 'h','t','t','p',':','/','/','x','m','l','.','o','r','g','/','s','a','x','/','f','e','a','t','u','r','e','s',
101 '/','n','a','m','e','s','p','a','c','e','-','p','r','e','f','i','x','e','s',0
104 struct saxreader_feature_pair
106 saxreader_feature feature
;
110 static const struct saxreader_feature_pair saxreader_feature_map
[] = {
111 { ExternalGeneralEntities
, FeatureExternalGeneralEntitiesW
},
112 { ExternalParameterEntities
, FeatureExternalParameterEntitiesW
},
113 { LexicalHandlerParEntities
, FeatureLexicalHandlerParEntitiesW
},
114 { NamespacePrefixes
, FeatureNamespacePrefixesW
},
115 { Namespaces
, FeatureNamespacesW
},
116 { ProhibitDTD
, FeatureProhibitDTDW
}
119 static saxreader_feature
get_saxreader_feature(const WCHAR
*name
)
124 max
= sizeof(saxreader_feature_map
)/sizeof(struct saxreader_feature_pair
) - 1;
130 c
= strcmpW(saxreader_feature_map
[n
].name
, name
);
132 return saxreader_feature_map
[n
].feature
;
140 return FeatureUnknown
;
162 ns
*ns
; /* namespaces defined in this particular element */
168 SAXContentHandler
= 0,
176 struct saxhandler_iface
182 struct saxcontenthandler_iface
184 ISAXContentHandler
*handler
;
185 IVBSAXContentHandler
*vbhandler
;
188 struct saxerrorhandler_iface
190 ISAXErrorHandler
*handler
;
191 IVBSAXErrorHandler
*vbhandler
;
194 struct saxlexicalhandler_iface
196 ISAXLexicalHandler
*handler
;
197 IVBSAXLexicalHandler
*vbhandler
;
203 IVBSAXXMLReader IVBSAXXMLReader_iface
;
204 ISAXXMLReader ISAXXMLReader_iface
;
207 struct saxhandler_iface saxhandlers
[SAXHandler_Last
];
210 struct bstrpool pool
;
211 saxreader_feature features
;
212 BSTR xmldecl_version
;
213 MSXML_VERSION version
;
216 static HRESULT
saxreader_put_handler(saxreader
*reader
, enum saxhandler_type type
, void *ptr
, BOOL vb
)
218 struct saxhandler_iface
*iface
= &reader
->saxhandlers
[type
];
219 IUnknown
*unk
= (IUnknown
*)ptr
;
222 IUnknown_AddRef(unk
);
224 if ((vb
&& iface
->vbhandler
) || (!vb
&& iface
->handler
))
225 IUnknown_Release(vb
? iface
->vbhandler
: iface
->handler
);
228 iface
->vbhandler
= unk
;
230 iface
->handler
= unk
;
235 static HRESULT
saxreader_get_handler(const saxreader
*reader
, enum saxhandler_type type
, BOOL vb
, void **ret
)
237 const struct saxhandler_iface
*iface
= &reader
->saxhandlers
[type
];
239 if (!ret
) return E_POINTER
;
241 if ((vb
&& iface
->vbhandler
) || (!vb
&& iface
->handler
))
244 IUnknown_AddRef(iface
->vbhandler
);
246 IUnknown_AddRef(iface
->handler
);
249 *ret
= vb
? iface
->vbhandler
: iface
->handler
;
254 static struct saxcontenthandler_iface
*saxreader_get_contenthandler(saxreader
*reader
)
256 return (struct saxcontenthandler_iface
*)&reader
->saxhandlers
[SAXContentHandler
];
259 static struct saxerrorhandler_iface
*saxreader_get_errorhandler(saxreader
*reader
)
261 return (struct saxerrorhandler_iface
*)&reader
->saxhandlers
[SAXErrorHandler
];
264 static struct saxlexicalhandler_iface
*saxreader_get_lexicalhandler(saxreader
*reader
)
266 return (struct saxlexicalhandler_iface
*)&reader
->saxhandlers
[SAXLexicalHandler
];
271 IVBSAXLocator IVBSAXLocator_iface
;
272 ISAXLocator ISAXLocator_iface
;
273 IVBSAXAttributes IVBSAXAttributes_iface
;
274 ISAXAttributes ISAXAttributes_iface
;
276 saxreader
*saxreader
;
278 xmlParserCtxtPtr pParserCtxt
;
284 struct list elements
;
298 static inline saxreader
*impl_from_IVBSAXXMLReader( IVBSAXXMLReader
*iface
)
300 return CONTAINING_RECORD(iface
, saxreader
, IVBSAXXMLReader_iface
);
303 static inline saxreader
*impl_from_ISAXXMLReader( ISAXXMLReader
*iface
)
305 return CONTAINING_RECORD(iface
, saxreader
, ISAXXMLReader_iface
);
308 static inline saxlocator
*impl_from_IVBSAXLocator( IVBSAXLocator
*iface
)
310 return CONTAINING_RECORD(iface
, saxlocator
, IVBSAXLocator_iface
);
313 static inline saxlocator
*impl_from_ISAXLocator( ISAXLocator
*iface
)
315 return CONTAINING_RECORD(iface
, saxlocator
, ISAXLocator_iface
);
318 static inline saxlocator
*impl_from_IVBSAXAttributes( IVBSAXAttributes
*iface
)
320 return CONTAINING_RECORD(iface
, saxlocator
, IVBSAXAttributes_iface
);
323 static inline saxlocator
*impl_from_ISAXAttributes( ISAXAttributes
*iface
)
325 return CONTAINING_RECORD(iface
, saxlocator
, ISAXAttributes_iface
);
328 static inline int saxreader_has_handler(const saxlocator
*locator
, enum saxhandler_type type
)
330 return (locator
->vbInterface
&& locator
->saxreader
->saxhandlers
[type
].vbhandler
) ||
331 (!locator
->vbInterface
&& locator
->saxreader
->saxhandlers
[type
].handler
);
335 static const WCHAR PropertyCharsetW
[] = {
336 'c','h','a','r','s','e','t',0
338 static const WCHAR PropertyXmlDeclVersionW
[] = {
339 'x','m','l','d','e','c','l','-','v','e','r','s','i','o','n',0
341 static const WCHAR PropertyDeclHandlerW
[] = {
342 'h','t','t','p',':','/','/','x','m','l','.','o','r','g','/',
343 's','a','x','/','p','r','o','p','e','r','t','i','e','s','/',
344 'd','e','c','l','a','r','a','t','i','o','n',
345 '-','h','a','n','d','l','e','r',0
347 static const WCHAR PropertyDomNodeW
[] = {
348 'h','t','t','p',':','/','/','x','m','l','.','o','r','g','/',
349 's','a','x','/','p','r','o','p','e','r','t','i','e','s','/',
350 'd','o','m','-','n','o','d','e',0
352 static const WCHAR PropertyInputSourceW
[] = {
353 'i','n','p','u','t','-','s','o','u','r','c','e',0
355 static const WCHAR PropertyLexicalHandlerW
[] = {
356 'h','t','t','p',':','/','/','x','m','l','.','o','r','g','/',
357 's','a','x','/','p','r','o','p','e','r','t','i','e','s','/',
358 'l','e','x','i','c','a','l','-','h','a','n','d','l','e','r',0
360 static const WCHAR PropertyMaxElementDepthW
[] = {
361 'm','a','x','-','e','l','e','m','e','n','t','-','d','e','p','t','h',0
363 static const WCHAR PropertyMaxXMLSizeW
[] = {
364 'm','a','x','-','x','m','l','-','s','i','z','e',0
366 static const WCHAR PropertySchemaDeclHandlerW
[] = {
367 's','c','h','e','m','a','-','d','e','c','l','a','r','a','t','i','o','n','-',
368 'h','a','n','d','l','e','r',0
370 static const WCHAR PropertyXMLDeclEncodingW
[] = {
371 'x','m','l','d','e','c','l','-','e','n','c','o','d','i','n','g',0
373 static const WCHAR PropertyXMLDeclStandaloneW
[] = {
374 'x','m','l','d','e','c','l','-','s','t','a','n','d','a','l','o','n','e',0
376 static const WCHAR PropertyXMLDeclVersionW
[] = {
377 'x','m','l','d','e','c','l','-','v','e','r','s','i','o','n',0
380 static inline HRESULT
set_feature_value(saxreader
*reader
, saxreader_feature feature
, VARIANT_BOOL value
)
382 /* handling of non-VARIANT_* values is version dependent */
383 if ((reader
->version
< MSXML4
) && (value
!= VARIANT_TRUE
))
384 value
= VARIANT_FALSE
;
385 if ((reader
->version
>= MSXML4
) && (value
!= VARIANT_FALSE
))
386 value
= VARIANT_TRUE
;
388 if (value
== VARIANT_TRUE
)
389 reader
->features
|= feature
;
391 reader
->features
&= ~feature
;
396 static inline HRESULT
get_feature_value(const saxreader
*reader
, saxreader_feature feature
, VARIANT_BOOL
*value
)
398 *value
= reader
->features
& feature
? VARIANT_TRUE
: VARIANT_FALSE
;
402 static BOOL
is_namespaces_enabled(const saxreader
*reader
)
404 return (reader
->version
< MSXML4
) || (reader
->features
& Namespaces
);
407 static BSTR
build_qname(BSTR prefix
, BSTR local
)
409 if (prefix
&& *prefix
)
411 BSTR qname
= SysAllocStringLen(NULL
, SysStringLen(prefix
) + SysStringLen(local
) + 1);
415 strcpyW(ptr
, prefix
);
416 ptr
+= SysStringLen(prefix
);
422 return SysAllocString(local
);
425 static element_entry
* alloc_element_entry(const xmlChar
*local
, const xmlChar
*prefix
, int nb_ns
,
426 const xmlChar
**namespaces
)
431 ret
= heap_alloc(sizeof(*ret
));
432 if (!ret
) return ret
;
434 ret
->local
= bstr_from_xmlChar(local
);
435 ret
->prefix
= bstr_from_xmlChar(prefix
);
436 ret
->qname
= build_qname(ret
->prefix
, ret
->local
);
437 ret
->ns
= nb_ns
? heap_alloc(nb_ns
*sizeof(ns
)) : NULL
;
438 ret
->ns_count
= nb_ns
;
440 for (i
=0; i
< nb_ns
; i
++)
442 ret
->ns
[i
].prefix
= bstr_from_xmlChar(namespaces
[2*i
]);
443 ret
->ns
[i
].uri
= bstr_from_xmlChar(namespaces
[2*i
+1]);
449 static void free_element_entry(element_entry
*element
)
453 for (i
=0; i
<element
->ns_count
;i
++)
455 SysFreeString(element
->ns
[i
].prefix
);
456 SysFreeString(element
->ns
[i
].uri
);
459 SysFreeString(element
->prefix
);
460 SysFreeString(element
->local
);
462 heap_free(element
->ns
);
466 static void push_element_ns(saxlocator
*locator
, element_entry
*element
)
468 list_add_head(&locator
->elements
, &element
->entry
);
471 static element_entry
* pop_element_ns(saxlocator
*locator
)
473 element_entry
*element
= LIST_ENTRY(list_head(&locator
->elements
), element_entry
, entry
);
476 list_remove(&element
->entry
);
481 static BSTR
find_element_uri(saxlocator
*locator
, const xmlChar
*uri
)
483 element_entry
*element
;
487 if (!uri
) return NULL
;
489 uriW
= bstr_from_xmlChar(uri
);
491 LIST_FOR_EACH_ENTRY(element
, &locator
->elements
, element_entry
, entry
)
493 for (i
=0; i
< element
->ns_count
; i
++)
494 if (!strcmpW(uriW
, element
->ns
[i
].uri
))
497 return element
->ns
[i
].uri
;
502 ERR("namespace uri not found, %s\n", debugstr_a((char*)uri
));
506 /* used to localize version dependent error check behaviour */
507 static inline BOOL
sax_callback_failed(saxlocator
*This
, HRESULT hr
)
509 return This
->saxreader
->version
>= MSXML4
? FAILED(hr
) : hr
!= S_OK
;
512 /* index value -1 means it tries to loop for a first time */
513 static inline BOOL
iterate_endprefix_index(saxlocator
*This
, const element_entry
*element
, int *i
)
515 if (This
->saxreader
->version
>= MSXML4
)
517 if (*i
== -1) *i
= 0; else ++*i
;
518 return *i
< element
->ns_count
;
522 if (*i
== -1) *i
= element
->ns_count
-1; else --*i
;
527 static BOOL
bstr_pool_insert(struct bstrpool
*pool
, BSTR pool_entry
)
531 pool
->pool
= HeapAlloc(GetProcessHeap(), 0, 16 * sizeof(*pool
->pool
));
538 else if (pool
->index
== pool
->len
)
540 BSTR
*realloc
= HeapReAlloc(GetProcessHeap(), 0, pool
->pool
, pool
->len
* 2 * sizeof(*realloc
));
545 pool
->pool
= realloc
;
549 pool
->pool
[pool
->index
++] = pool_entry
;
553 static void free_bstr_pool(struct bstrpool
*pool
)
557 for (i
= 0; i
< pool
->index
; i
++)
558 SysFreeString(pool
->pool
[i
]);
560 HeapFree(GetProcessHeap(), 0, pool
->pool
);
563 pool
->index
= pool
->len
= 0;
566 static BSTR
bstr_from_xmlCharN(const xmlChar
*buf
, int len
)
574 dLen
= MultiByteToWideChar(CP_UTF8
, 0, (LPCSTR
)buf
, len
, NULL
, 0);
575 if(len
!= -1) dLen
++;
576 bstr
= SysAllocStringLen(NULL
, dLen
-1);
579 MultiByteToWideChar(CP_UTF8
, 0, (LPCSTR
)buf
, len
, bstr
, dLen
);
580 if(len
!= -1) bstr
[dLen
-1] = '\0';
585 static BSTR
QName_from_xmlChar(const xmlChar
*prefix
, const xmlChar
*name
)
590 if(!name
) return NULL
;
592 if(!prefix
|| !*prefix
)
593 return bstr_from_xmlChar(name
);
595 qname
= xmlBuildQName(name
, prefix
, NULL
, 0);
596 bstr
= bstr_from_xmlChar(qname
);
602 static BSTR
pooled_bstr_from_xmlChar(struct bstrpool
*pool
, const xmlChar
*buf
)
604 BSTR pool_entry
= bstr_from_xmlChar(buf
);
606 if (pool_entry
&& !bstr_pool_insert(pool
, pool_entry
))
608 SysFreeString(pool_entry
);
615 static BSTR
pooled_bstr_from_xmlCharN(struct bstrpool
*pool
, const xmlChar
*buf
, int len
)
617 BSTR pool_entry
= bstr_from_xmlCharN(buf
, len
);
619 if (pool_entry
&& !bstr_pool_insert(pool
, pool_entry
))
621 SysFreeString(pool_entry
);
628 static void format_error_message_from_id(saxlocator
*This
, HRESULT hr
)
630 struct saxerrorhandler_iface
*handler
= saxreader_get_errorhandler(This
->saxreader
);
631 xmlStopParser(This
->pParserCtxt
);
634 if (saxreader_has_handler(This
, SAXErrorHandler
))
637 if(!FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM
,
638 NULL
, hr
, 0, msg
, sizeof(msg
), NULL
))
640 FIXME("MSXML errors not yet supported.\n");
644 if(This
->vbInterface
)
646 BSTR bstrMsg
= SysAllocString(msg
);
647 IVBSAXErrorHandler_fatalError(handler
->vbhandler
,
648 &This
->IVBSAXLocator_iface
, &bstrMsg
, hr
);
649 SysFreeString(bstrMsg
);
652 ISAXErrorHandler_fatalError(handler
->handler
,
653 &This
->ISAXLocator_iface
, msg
, hr
);
657 static void update_position(saxlocator
*This
, BOOL fix_column
)
659 const xmlChar
*p
= This
->pParserCtxt
->input
->cur
-1;
661 This
->line
= xmlSAX2GetLineNumber(This
->pParserCtxt
);
665 for(; *p
!='\n' && *p
!='\r' && p
>=This
->pParserCtxt
->input
->base
; p
--)
670 This
->column
= xmlSAX2GetColumnNumber(This
->pParserCtxt
);
674 /*** IVBSAXAttributes interface ***/
675 /*** IUnknown methods ***/
676 static HRESULT WINAPI
ivbsaxattributes_QueryInterface(
677 IVBSAXAttributes
* iface
,
681 saxlocator
*This
= impl_from_IVBSAXAttributes(iface
);
682 TRACE("%p %s %p\n", This
, debugstr_guid(riid
), ppvObject
);
683 return IVBSAXLocator_QueryInterface(&This
->IVBSAXLocator_iface
, riid
, ppvObject
);
686 static ULONG WINAPI
ivbsaxattributes_AddRef(IVBSAXAttributes
* iface
)
688 saxlocator
*This
= impl_from_IVBSAXAttributes(iface
);
689 return ISAXLocator_AddRef(&This
->ISAXLocator_iface
);
692 static ULONG WINAPI
ivbsaxattributes_Release(IVBSAXAttributes
* iface
)
694 saxlocator
*This
= impl_from_IVBSAXAttributes(iface
);
695 return ISAXLocator_Release(&This
->ISAXLocator_iface
);
698 /*** IDispatch methods ***/
699 static HRESULT WINAPI
ivbsaxattributes_GetTypeInfoCount( IVBSAXAttributes
*iface
, UINT
* pctinfo
)
701 saxlocator
*This
= impl_from_IVBSAXAttributes( iface
);
703 TRACE("(%p)->(%p)\n", This
, pctinfo
);
710 static HRESULT WINAPI
ivbsaxattributes_GetTypeInfo(
711 IVBSAXAttributes
*iface
,
712 UINT iTInfo
, LCID lcid
, ITypeInfo
** ppTInfo
)
714 saxlocator
*This
= impl_from_IVBSAXAttributes( iface
);
717 TRACE("(%p)->(%u %u %p)\n", This
, iTInfo
, lcid
, ppTInfo
);
719 hr
= get_typeinfo(IVBSAXAttributes_tid
, ppTInfo
);
724 static HRESULT WINAPI
ivbsaxattributes_GetIDsOfNames(
725 IVBSAXAttributes
*iface
,
732 saxlocator
*This
= impl_from_IVBSAXAttributes( iface
);
736 TRACE("(%p)->(%s %p %u %u %p)\n", This
, debugstr_guid(riid
), rgszNames
, cNames
,
739 if(!rgszNames
|| cNames
== 0 || !rgDispId
)
742 hr
= get_typeinfo(IVBSAXAttributes_tid
, &typeinfo
);
745 hr
= ITypeInfo_GetIDsOfNames(typeinfo
, rgszNames
, cNames
, rgDispId
);
746 ITypeInfo_Release(typeinfo
);
752 static HRESULT WINAPI
ivbsaxattributes_Invoke(
753 IVBSAXAttributes
*iface
,
758 DISPPARAMS
* pDispParams
,
760 EXCEPINFO
* pExcepInfo
,
763 saxlocator
*This
= impl_from_IVBSAXAttributes( iface
);
767 TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This
, dispIdMember
, debugstr_guid(riid
),
768 lcid
, wFlags
, pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
770 hr
= get_typeinfo(IVBSAXAttributes_tid
, &typeinfo
);
773 hr
= ITypeInfo_Invoke(typeinfo
, &This
->IVBSAXAttributes_iface
, dispIdMember
, wFlags
,
774 pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
775 ITypeInfo_Release(typeinfo
);
781 /*** IVBSAXAttributes methods ***/
782 static HRESULT WINAPI
ivbsaxattributes_get_length(
783 IVBSAXAttributes
* iface
,
786 saxlocator
*This
= impl_from_IVBSAXAttributes( iface
);
787 return ISAXAttributes_getLength(&This
->ISAXAttributes_iface
, nLength
);
790 static HRESULT WINAPI
ivbsaxattributes_getURI(
791 IVBSAXAttributes
* iface
,
796 saxlocator
*This
= impl_from_IVBSAXAttributes( iface
);
797 return ISAXAttributes_getURI(&This
->ISAXAttributes_iface
, nIndex
, (const WCHAR
**)uri
, &len
);
800 static HRESULT WINAPI
ivbsaxattributes_getLocalName(
801 IVBSAXAttributes
* iface
,
806 saxlocator
*This
= impl_from_IVBSAXAttributes( iface
);
807 return ISAXAttributes_getLocalName(&This
->ISAXAttributes_iface
, nIndex
,
808 (const WCHAR
**)localName
, &len
);
811 static HRESULT WINAPI
ivbsaxattributes_getQName(
812 IVBSAXAttributes
* iface
,
817 saxlocator
*This
= impl_from_IVBSAXAttributes( iface
);
818 return ISAXAttributes_getQName(&This
->ISAXAttributes_iface
, nIndex
, (const WCHAR
**)QName
, &len
);
821 static HRESULT WINAPI
ivbsaxattributes_getIndexFromName(
822 IVBSAXAttributes
* iface
,
827 saxlocator
*This
= impl_from_IVBSAXAttributes( iface
);
828 return ISAXAttributes_getIndexFromName(&This
->ISAXAttributes_iface
, uri
, SysStringLen(uri
),
829 localName
, SysStringLen(localName
), index
);
832 static HRESULT WINAPI
ivbsaxattributes_getIndexFromQName(
833 IVBSAXAttributes
* iface
,
837 saxlocator
*This
= impl_from_IVBSAXAttributes( iface
);
838 return ISAXAttributes_getIndexFromQName(&This
->ISAXAttributes_iface
, QName
,
839 SysStringLen(QName
), index
);
842 static HRESULT WINAPI
ivbsaxattributes_getType(
843 IVBSAXAttributes
* iface
,
848 saxlocator
*This
= impl_from_IVBSAXAttributes( iface
);
849 return ISAXAttributes_getType(&This
->ISAXAttributes_iface
, nIndex
, (const WCHAR
**)type
, &len
);
852 static HRESULT WINAPI
ivbsaxattributes_getTypeFromName(
853 IVBSAXAttributes
* iface
,
859 saxlocator
*This
= impl_from_IVBSAXAttributes( iface
);
860 return ISAXAttributes_getTypeFromName(&This
->ISAXAttributes_iface
, uri
, SysStringLen(uri
),
861 localName
, SysStringLen(localName
), (const WCHAR
**)type
, &len
);
864 static HRESULT WINAPI
ivbsaxattributes_getTypeFromQName(
865 IVBSAXAttributes
* iface
,
870 saxlocator
*This
= impl_from_IVBSAXAttributes( iface
);
871 return ISAXAttributes_getTypeFromQName(&This
->ISAXAttributes_iface
, QName
, SysStringLen(QName
),
872 (const WCHAR
**)type
, &len
);
875 static HRESULT WINAPI
ivbsaxattributes_getValue(
876 IVBSAXAttributes
* iface
,
881 saxlocator
*This
= impl_from_IVBSAXAttributes( iface
);
882 return ISAXAttributes_getValue(&This
->ISAXAttributes_iface
, nIndex
, (const WCHAR
**)value
, &len
);
885 static HRESULT WINAPI
ivbsaxattributes_getValueFromName(
886 IVBSAXAttributes
* iface
,
892 saxlocator
*This
= impl_from_IVBSAXAttributes( iface
);
893 return ISAXAttributes_getValueFromName(&This
->ISAXAttributes_iface
, uri
, SysStringLen(uri
),
894 localName
, SysStringLen(localName
), (const WCHAR
**)value
, &len
);
897 static HRESULT WINAPI
ivbsaxattributes_getValueFromQName(
898 IVBSAXAttributes
* iface
,
903 saxlocator
*This
= impl_from_IVBSAXAttributes( iface
);
904 return ISAXAttributes_getValueFromQName(&This
->ISAXAttributes_iface
, QName
,
905 SysStringLen(QName
), (const WCHAR
**)value
, &len
);
908 static const struct IVBSAXAttributesVtbl ivbsaxattributes_vtbl
=
910 ivbsaxattributes_QueryInterface
,
911 ivbsaxattributes_AddRef
,
912 ivbsaxattributes_Release
,
913 ivbsaxattributes_GetTypeInfoCount
,
914 ivbsaxattributes_GetTypeInfo
,
915 ivbsaxattributes_GetIDsOfNames
,
916 ivbsaxattributes_Invoke
,
917 ivbsaxattributes_get_length
,
918 ivbsaxattributes_getURI
,
919 ivbsaxattributes_getLocalName
,
920 ivbsaxattributes_getQName
,
921 ivbsaxattributes_getIndexFromName
,
922 ivbsaxattributes_getIndexFromQName
,
923 ivbsaxattributes_getType
,
924 ivbsaxattributes_getTypeFromName
,
925 ivbsaxattributes_getTypeFromQName
,
926 ivbsaxattributes_getValue
,
927 ivbsaxattributes_getValueFromName
,
928 ivbsaxattributes_getValueFromQName
931 /*** ISAXAttributes interface ***/
932 /*** IUnknown methods ***/
933 static HRESULT WINAPI
isaxattributes_QueryInterface(
934 ISAXAttributes
* iface
,
938 saxlocator
*This
= impl_from_ISAXAttributes(iface
);
939 TRACE("%p %s %p\n", This
, debugstr_guid(riid
), ppvObject
);
940 return ISAXLocator_QueryInterface(&This
->ISAXLocator_iface
, riid
, ppvObject
);
943 static ULONG WINAPI
isaxattributes_AddRef(ISAXAttributes
* iface
)
945 saxlocator
*This
= impl_from_ISAXAttributes(iface
);
947 return ISAXLocator_AddRef(&This
->ISAXLocator_iface
);
950 static ULONG WINAPI
isaxattributes_Release(ISAXAttributes
* iface
)
952 saxlocator
*This
= impl_from_ISAXAttributes(iface
);
955 return ISAXLocator_Release(&This
->ISAXLocator_iface
);
958 /*** ISAXAttributes methods ***/
959 static HRESULT WINAPI
isaxattributes_getLength(
960 ISAXAttributes
* iface
,
963 saxlocator
*This
= impl_from_ISAXAttributes( iface
);
965 *length
= This
->nb_attributes
;
966 TRACE("Length set to %d\n", *length
);
970 static HRESULT WINAPI
isaxattributes_getURI(
971 ISAXAttributes
* iface
,
976 saxlocator
*This
= impl_from_ISAXAttributes( iface
);
977 TRACE("(%p)->(%d)\n", This
, index
);
979 if(index
>= This
->nb_attributes
|| index
< 0) return E_INVALIDARG
;
980 if(!url
|| !size
) return E_POINTER
;
982 *size
= SysStringLen(This
->attributes
[index
].szURI
);
983 *url
= This
->attributes
[index
].szURI
;
985 TRACE("(%s:%d)\n", debugstr_w(This
->attributes
[index
].szURI
), *size
);
990 static HRESULT WINAPI
isaxattributes_getLocalName(
991 ISAXAttributes
* iface
,
993 const WCHAR
**pLocalName
,
994 int *pLocalNameLength
)
996 saxlocator
*This
= impl_from_ISAXAttributes( iface
);
997 TRACE("(%p)->(%d)\n", This
, nIndex
);
999 if(nIndex
>=This
->nb_attributes
|| nIndex
<0) return E_INVALIDARG
;
1000 if(!pLocalName
|| !pLocalNameLength
) return E_POINTER
;
1002 *pLocalNameLength
= SysStringLen(This
->attributes
[nIndex
].szLocalname
);
1003 *pLocalName
= This
->attributes
[nIndex
].szLocalname
;
1008 static HRESULT WINAPI
isaxattributes_getQName(
1009 ISAXAttributes
* iface
,
1011 const WCHAR
**pQName
,
1014 saxlocator
*This
= impl_from_ISAXAttributes( iface
);
1015 TRACE("(%p)->(%d)\n", This
, nIndex
);
1017 if(nIndex
>=This
->nb_attributes
|| nIndex
<0) return E_INVALIDARG
;
1018 if(!pQName
|| !pQNameLength
) return E_POINTER
;
1020 *pQNameLength
= SysStringLen(This
->attributes
[nIndex
].szQName
);
1021 *pQName
= This
->attributes
[nIndex
].szQName
;
1026 static HRESULT WINAPI
isaxattributes_getName(
1027 ISAXAttributes
* iface
,
1031 const WCHAR
**localName
,
1032 int *pLocalNameSize
,
1033 const WCHAR
**QName
,
1036 saxlocator
*This
= impl_from_ISAXAttributes( iface
);
1037 TRACE("(%p)->(%d)\n", This
, index
);
1039 if(index
>=This
->nb_attributes
|| index
<0) return E_INVALIDARG
;
1040 if(!uri
|| !pUriLength
|| !localName
|| !pLocalNameSize
1041 || !QName
|| !pQNameLength
) return E_POINTER
;
1043 *pUriLength
= SysStringLen(This
->attributes
[index
].szURI
);
1044 *uri
= This
->attributes
[index
].szURI
;
1045 *pLocalNameSize
= SysStringLen(This
->attributes
[index
].szLocalname
);
1046 *localName
= This
->attributes
[index
].szLocalname
;
1047 *pQNameLength
= SysStringLen(This
->attributes
[index
].szQName
);
1048 *QName
= This
->attributes
[index
].szQName
;
1050 TRACE("(%s, %s, %s)\n", debugstr_w(*uri
), debugstr_w(*localName
), debugstr_w(*QName
));
1055 static HRESULT WINAPI
isaxattributes_getIndexFromName(
1056 ISAXAttributes
* iface
,
1059 const WCHAR
*pLocalName
,
1060 int cocalNameLength
,
1063 saxlocator
*This
= impl_from_ISAXAttributes( iface
);
1065 TRACE("(%p)->(%s, %d, %s, %d)\n", This
, debugstr_w(pUri
), cUriLength
,
1066 debugstr_w(pLocalName
), cocalNameLength
);
1068 if(!pUri
|| !pLocalName
|| !index
) return E_POINTER
;
1070 for(i
=0; i
<This
->nb_attributes
; i
++)
1072 if(cUriLength
!=SysStringLen(This
->attributes
[i
].szURI
)
1073 || cocalNameLength
!=SysStringLen(This
->attributes
[i
].szLocalname
))
1075 if(cUriLength
&& memcmp(pUri
, This
->attributes
[i
].szURI
,
1076 sizeof(WCHAR
)*cUriLength
))
1078 if(cocalNameLength
&& memcmp(pLocalName
, This
->attributes
[i
].szLocalname
,
1079 sizeof(WCHAR
)*cocalNameLength
))
1086 return E_INVALIDARG
;
1089 static HRESULT WINAPI
isaxattributes_getIndexFromQName(
1090 ISAXAttributes
* iface
,
1091 const WCHAR
*pQName
,
1095 saxlocator
*This
= impl_from_ISAXAttributes( iface
);
1097 TRACE("(%p)->(%s, %d)\n", This
, debugstr_w(pQName
), nQNameLength
);
1099 if(!pQName
|| !index
) return E_POINTER
;
1100 if(!nQNameLength
) return E_INVALIDARG
;
1102 for(i
=0; i
<This
->nb_attributes
; i
++)
1104 if(nQNameLength
!=SysStringLen(This
->attributes
[i
].szQName
)) continue;
1105 if(memcmp(pQName
, This
->attributes
[i
].szQName
, sizeof(WCHAR
)*nQNameLength
)) continue;
1111 return E_INVALIDARG
;
1114 static HRESULT WINAPI
isaxattributes_getType(
1115 ISAXAttributes
* iface
,
1117 const WCHAR
**pType
,
1120 saxlocator
*This
= impl_from_ISAXAttributes( iface
);
1122 FIXME("(%p)->(%d) stub\n", This
, nIndex
);
1126 static HRESULT WINAPI
isaxattributes_getTypeFromName(
1127 ISAXAttributes
* iface
,
1130 const WCHAR
*pLocalName
,
1132 const WCHAR
**pType
,
1135 saxlocator
*This
= impl_from_ISAXAttributes( iface
);
1137 FIXME("(%p)->(%s, %d, %s, %d) stub\n", This
, debugstr_w(pUri
), nUri
,
1138 debugstr_w(pLocalName
), nLocalName
);
1142 static HRESULT WINAPI
isaxattributes_getTypeFromQName(
1143 ISAXAttributes
* iface
,
1144 const WCHAR
*pQName
,
1146 const WCHAR
**pType
,
1149 saxlocator
*This
= impl_from_ISAXAttributes( iface
);
1151 FIXME("(%p)->(%s, %d) stub\n", This
, debugstr_w(pQName
), nQName
);
1155 static HRESULT WINAPI
isaxattributes_getValue(
1156 ISAXAttributes
* iface
,
1158 const WCHAR
**value
,
1161 saxlocator
*This
= impl_from_ISAXAttributes( iface
);
1162 TRACE("(%p)->(%d)\n", This
, index
);
1164 if(index
>=This
->nb_attributes
|| index
<0) return E_INVALIDARG
;
1165 if(!value
|| !nValue
) return E_POINTER
;
1167 *nValue
= SysStringLen(This
->attributes
[index
].szValue
);
1168 *value
= This
->attributes
[index
].szValue
;
1170 TRACE("(%s:%d)\n", debugstr_w(*value
), *nValue
);
1175 static HRESULT WINAPI
isaxattributes_getValueFromName(
1176 ISAXAttributes
* iface
,
1179 const WCHAR
*pLocalName
,
1181 const WCHAR
**pValue
,
1186 saxlocator
*This
= impl_from_ISAXAttributes( iface
);
1187 TRACE("(%p)->(%s, %d, %s, %d)\n", This
, debugstr_w(pUri
), nUri
,
1188 debugstr_w(pLocalName
), nLocalName
);
1190 hr
= ISAXAttributes_getIndexFromName(iface
,
1191 pUri
, nUri
, pLocalName
, nLocalName
, &index
);
1192 if(hr
==S_OK
) hr
= ISAXAttributes_getValue(iface
, index
, pValue
, nValue
);
1197 static HRESULT WINAPI
isaxattributes_getValueFromQName(
1198 ISAXAttributes
* iface
,
1199 const WCHAR
*pQName
,
1201 const WCHAR
**pValue
,
1206 saxlocator
*This
= impl_from_ISAXAttributes( iface
);
1207 TRACE("(%p)->(%s, %d)\n", This
, debugstr_w(pQName
), nQName
);
1209 hr
= ISAXAttributes_getIndexFromQName(iface
, pQName
, nQName
, &index
);
1210 if(hr
==S_OK
) hr
= ISAXAttributes_getValue(iface
, index
, pValue
, nValue
);
1215 static const struct ISAXAttributesVtbl isaxattributes_vtbl
=
1217 isaxattributes_QueryInterface
,
1218 isaxattributes_AddRef
,
1219 isaxattributes_Release
,
1220 isaxattributes_getLength
,
1221 isaxattributes_getURI
,
1222 isaxattributes_getLocalName
,
1223 isaxattributes_getQName
,
1224 isaxattributes_getName
,
1225 isaxattributes_getIndexFromName
,
1226 isaxattributes_getIndexFromQName
,
1227 isaxattributes_getType
,
1228 isaxattributes_getTypeFromName
,
1229 isaxattributes_getTypeFromQName
,
1230 isaxattributes_getValue
,
1231 isaxattributes_getValueFromName
,
1232 isaxattributes_getValueFromQName
1235 static HRESULT
SAXAttributes_populate(saxlocator
*locator
,
1236 int nb_namespaces
, const xmlChar
**xmlNamespaces
,
1237 int nb_attributes
, const xmlChar
**xmlAttributes
)
1239 static const xmlChar xmlns
[] = "xmlns";
1240 static const WCHAR xmlnsW
[] = { 'x','m','l','n','s',0 };
1242 struct _attributes
*attrs
;
1245 /* skip namespace definitions */
1246 if ((locator
->saxreader
->features
& NamespacePrefixes
) == 0)
1249 locator
->nb_attributes
= nb_namespaces
+ nb_attributes
;
1250 if(locator
->nb_attributes
> locator
->attributesSize
)
1252 attrs
= heap_realloc(locator
->attributes
, sizeof(struct _attributes
)*locator
->nb_attributes
*2);
1255 locator
->nb_attributes
= 0;
1256 return E_OUTOFMEMORY
;
1258 locator
->attributes
= attrs
;
1262 attrs
= locator
->attributes
;
1265 for (i
= 0; i
< nb_namespaces
; i
++)
1267 attrs
[nb_attributes
+i
].szLocalname
= SysAllocStringLen(NULL
, 0);
1268 attrs
[nb_attributes
+i
].szURI
= locator
->namespaceUri
;
1269 attrs
[nb_attributes
+i
].szValue
= bstr_from_xmlChar(xmlNamespaces
[2*i
+1]);
1270 if(!xmlNamespaces
[2*i
])
1271 attrs
[nb_attributes
+i
].szQName
= SysAllocString(xmlnsW
);
1273 attrs
[nb_attributes
+i
].szQName
= QName_from_xmlChar(xmlns
, xmlNamespaces
[2*i
]);
1276 for (i
= 0; i
< nb_attributes
; i
++)
1278 static const xmlChar xmlA
[] = "xml";
1280 if (xmlStrEqual(xmlAttributes
[i
*5+1], xmlA
))
1281 attrs
[i
].szURI
= bstr_from_xmlChar(xmlAttributes
[i
*5+2]);
1283 /* that's an important feature to keep same uri pointer for every reported attribute */
1284 attrs
[i
].szURI
= find_element_uri(locator
, xmlAttributes
[i
*5+2]);
1286 attrs
[i
].szLocalname
= bstr_from_xmlChar(xmlAttributes
[i
*5]);
1287 attrs
[i
].szValue
= bstr_from_xmlCharN(xmlAttributes
[i
*5+3],
1288 xmlAttributes
[i
*5+4]-xmlAttributes
[i
*5+3]);
1289 attrs
[i
].szQName
= QName_from_xmlChar(xmlAttributes
[i
*5+1],
1290 xmlAttributes
[i
*5]);
1296 /*** LibXML callbacks ***/
1297 static void libxmlStartDocument(void *ctx
)
1299 saxlocator
*This
= ctx
;
1300 struct saxcontenthandler_iface
*handler
= saxreader_get_contenthandler(This
->saxreader
);
1303 if (This
->saxreader
->version
>= MSXML4
)
1305 const xmlChar
*p
= This
->pParserCtxt
->input
->cur
-1;
1306 update_position(This
, FALSE
);
1307 while(p
>This
->pParserCtxt
->input
->base
&& *p
!='>')
1309 if(*p
=='\n' || (*p
=='\r' && *(p
+1)!='\n'))
1314 for(; p
>=This
->pParserCtxt
->input
->base
&& *p
!='\n' && *p
!='\r'; p
--)
1318 /* store version value, declaration has to contain version attribute */
1319 if (This
->pParserCtxt
->standalone
!= -1)
1321 SysFreeString(This
->saxreader
->xmldecl_version
);
1322 This
->saxreader
->xmldecl_version
= bstr_from_xmlChar(This
->pParserCtxt
->version
);
1325 if (saxreader_has_handler(This
, SAXContentHandler
))
1327 if(This
->vbInterface
)
1328 hr
= IVBSAXContentHandler_startDocument(handler
->vbhandler
);
1330 hr
= ISAXContentHandler_startDocument(handler
->handler
);
1332 if (sax_callback_failed(This
, hr
))
1333 format_error_message_from_id(This
, hr
);
1337 static void libxmlEndDocument(void *ctx
)
1339 saxlocator
*This
= ctx
;
1340 struct saxcontenthandler_iface
*handler
= saxreader_get_contenthandler(This
->saxreader
);
1343 if (This
->saxreader
->version
>= MSXML4
) {
1344 update_position(This
, FALSE
);
1345 if(This
->column
> 1)
1353 if(This
->ret
!= S_OK
) return;
1355 if (saxreader_has_handler(This
, SAXContentHandler
))
1357 if(This
->vbInterface
)
1358 hr
= IVBSAXContentHandler_endDocument(handler
->vbhandler
);
1360 hr
= ISAXContentHandler_endDocument(handler
->handler
);
1362 if (sax_callback_failed(This
, hr
))
1363 format_error_message_from_id(This
, hr
);
1367 static void libxmlStartElementNS(
1369 const xmlChar
*localname
,
1370 const xmlChar
*prefix
,
1373 const xmlChar
**namespaces
,
1376 const xmlChar
**attributes
)
1378 saxlocator
*This
= ctx
;
1379 struct saxcontenthandler_iface
*handler
= saxreader_get_contenthandler(This
->saxreader
);
1380 element_entry
*element
;
1384 update_position(This
, TRUE
);
1385 if(*(This
->pParserCtxt
->input
->cur
) == '/')
1387 if(This
->saxreader
->version
< MSXML4
)
1390 element
= alloc_element_entry(localname
, prefix
, nb_namespaces
, namespaces
);
1391 push_element_ns(This
, element
);
1393 if (is_namespaces_enabled(This
->saxreader
))
1397 for (i
= 0; i
< nb_namespaces
&& saxreader_has_handler(This
, SAXContentHandler
); i
++)
1399 if (This
->vbInterface
)
1400 hr
= IVBSAXContentHandler_startPrefixMapping(
1402 &element
->ns
[i
].prefix
,
1403 &element
->ns
[i
].uri
);
1405 hr
= ISAXContentHandler_startPrefixMapping(
1407 element
->ns
[i
].prefix
,
1408 SysStringLen(element
->ns
[i
].prefix
),
1410 SysStringLen(element
->ns
[i
].uri
));
1412 if (sax_callback_failed(This
, hr
))
1414 format_error_message_from_id(This
, hr
);
1420 uri
= find_element_uri(This
, URI
);
1421 hr
= SAXAttributes_populate(This
, nb_namespaces
, namespaces
, nb_attributes
, attributes
);
1422 if (hr
== S_OK
&& saxreader_has_handler(This
, SAXContentHandler
))
1426 if (is_namespaces_enabled(This
->saxreader
))
1427 local
= element
->local
;
1431 if (This
->vbInterface
)
1432 hr
= IVBSAXContentHandler_startElement(handler
->vbhandler
,
1433 &uri
, &local
, &element
->qname
, &This
->IVBSAXAttributes_iface
);
1435 hr
= ISAXContentHandler_startElement(handler
->handler
,
1436 uri
, SysStringLen(uri
),
1437 local
, SysStringLen(local
),
1438 element
->qname
, SysStringLen(element
->qname
),
1439 &This
->ISAXAttributes_iface
);
1441 if (sax_callback_failed(This
, hr
))
1442 format_error_message_from_id(This
, hr
);
1446 static void libxmlEndElementNS(
1448 const xmlChar
*localname
,
1449 const xmlChar
*prefix
,
1452 saxlocator
*This
= ctx
;
1453 struct saxcontenthandler_iface
*handler
= saxreader_get_contenthandler(This
->saxreader
);
1454 element_entry
*element
;
1459 update_position(This
, FALSE
);
1460 p
= This
->pParserCtxt
->input
->cur
;
1462 if (This
->saxreader
->version
>= MSXML4
)
1465 while(p
>This
->pParserCtxt
->input
->base
&& *p
!='>')
1467 if(*p
=='\n' || (*p
=='\r' && *(p
+1)!='\n'))
1472 else if(*(p
-1)!='>' || *(p
-2)!='/')
1475 while(p
-2>=This
->pParserCtxt
->input
->base
1476 && *(p
-2)!='<' && *(p
-1)!='/')
1478 if(*p
=='\n' || (*p
=='\r' && *(p
+1)!='\n'))
1484 for(; p
>=This
->pParserCtxt
->input
->base
&& *p
!='\n' && *p
!='\r'; p
--)
1487 uri
= find_element_uri(This
, URI
);
1488 element
= pop_element_ns(This
);
1490 if (!saxreader_has_handler(This
, SAXContentHandler
))
1492 This
->nb_attributes
= 0;
1493 free_element_entry(element
);
1497 if (is_namespaces_enabled(This
->saxreader
))
1498 local
= element
->local
;
1502 if (This
->vbInterface
)
1503 hr
= IVBSAXContentHandler_endElement(
1505 &uri
, &local
, &element
->qname
);
1507 hr
= ISAXContentHandler_endElement(
1509 uri
, SysStringLen(uri
),
1510 local
, SysStringLen(local
),
1511 element
->qname
, SysStringLen(element
->qname
));
1513 This
->nb_attributes
= 0;
1515 if (sax_callback_failed(This
, hr
))
1517 format_error_message_from_id(This
, hr
);
1518 free_element_entry(element
);
1522 if (is_namespaces_enabled(This
->saxreader
))
1525 while (iterate_endprefix_index(This
, element
, &i
) && saxreader_has_handler(This
, SAXContentHandler
))
1527 if (This
->vbInterface
)
1528 hr
= IVBSAXContentHandler_endPrefixMapping(
1529 handler
->vbhandler
, &element
->ns
[i
].prefix
);
1531 hr
= ISAXContentHandler_endPrefixMapping(
1532 handler
->handler
, element
->ns
[i
].prefix
, SysStringLen(element
->ns
[i
].prefix
));
1534 if (sax_callback_failed(This
, hr
)) break;
1537 if (sax_callback_failed(This
, hr
))
1538 format_error_message_from_id(This
, hr
);
1541 free_element_entry(element
);
1544 static void libxmlCharacters(
1549 saxlocator
*This
= ctx
;
1550 struct saxcontenthandler_iface
*handler
= saxreader_get_contenthandler(This
->saxreader
);
1554 BOOL lastEvent
= FALSE
;
1556 if (!saxreader_has_handler(This
, SAXContentHandler
)) return;
1558 update_position(This
, FALSE
);
1559 cur
= (xmlChar
*)This
->pParserCtxt
->input
->cur
;
1560 while(cur
>=This
->pParserCtxt
->input
->base
&& *cur
!='>')
1562 if(*cur
=='\n' || (*cur
=='\r' && *(cur
+1)!='\n'))
1567 for(; cur
>=This
->pParserCtxt
->input
->base
&& *cur
!='\n' && *cur
!='\r'; cur
--)
1571 if(*(ch
-1)=='\r') cur
--;
1576 while(end
-ch
<len
&& *end
!='\r') end
++;
1587 if (This
->saxreader
->version
>= MSXML4
)
1591 for(p
=cur
; p
!=end
; p
++)
1608 Chars
= pooled_bstr_from_xmlCharN(&This
->saxreader
->pool
, cur
, end
-cur
);
1609 if(This
->vbInterface
)
1610 hr
= IVBSAXContentHandler_characters(handler
->vbhandler
, &Chars
);
1612 hr
= ISAXContentHandler_characters(handler
->handler
, Chars
, SysStringLen(Chars
));
1614 if (sax_callback_failed(This
, hr
))
1616 format_error_message_from_id(This
, hr
);
1620 if (This
->saxreader
->version
< MSXML4
)
1621 This
->column
+= end
-cur
;
1634 if(end
-ch
== len
) break;
1638 static void libxmlSetDocumentLocator(
1640 xmlSAXLocatorPtr loc
)
1642 saxlocator
*This
= ctx
;
1643 struct saxcontenthandler_iface
*handler
= saxreader_get_contenthandler(This
->saxreader
);
1646 if (saxreader_has_handler(This
, SAXContentHandler
))
1648 if(This
->vbInterface
)
1649 hr
= IVBSAXContentHandler_putref_documentLocator(handler
->vbhandler
,
1650 &This
->IVBSAXLocator_iface
);
1652 hr
= ISAXContentHandler_putDocumentLocator(handler
->handler
, &This
->ISAXLocator_iface
);
1656 format_error_message_from_id(This
, hr
);
1659 static void libxmlComment(void *ctx
, const xmlChar
*value
)
1661 saxlocator
*This
= ctx
;
1662 struct saxlexicalhandler_iface
*handler
= saxreader_get_lexicalhandler(This
->saxreader
);
1665 const xmlChar
*p
= This
->pParserCtxt
->input
->cur
;
1667 update_position(This
, FALSE
);
1668 while(p
-4>=This
->pParserCtxt
->input
->base
1669 && memcmp(p
-4, "<!--", sizeof(char[4])))
1671 if(*p
=='\n' || (*p
=='\r' && *(p
+1)!='\n'))
1677 for(; p
>=This
->pParserCtxt
->input
->base
&& *p
!='\n' && *p
!='\r'; p
--)
1680 if (!saxreader_has_handler(This
, SAXLexicalHandler
)) return;
1682 bValue
= pooled_bstr_from_xmlChar(&This
->saxreader
->pool
, value
);
1684 if (This
->vbInterface
)
1685 hr
= IVBSAXLexicalHandler_comment(handler
->vbhandler
, &bValue
);
1687 hr
= ISAXLexicalHandler_comment(handler
->handler
, bValue
, SysStringLen(bValue
));
1690 format_error_message_from_id(This
, hr
);
1693 static void libxmlFatalError(void *ctx
, const char *msg
, ...)
1695 saxlocator
*This
= ctx
;
1696 struct saxerrorhandler_iface
*handler
= saxreader_get_errorhandler(This
->saxreader
);
1702 if(This
->ret
!= S_OK
) {
1703 xmlStopParser(This
->pParserCtxt
);
1707 va_start(args
, msg
);
1708 vsprintf(message
, msg
, args
);
1711 len
= MultiByteToWideChar(CP_UNIXCP
, 0, message
, -1, NULL
, 0);
1712 error
= heap_alloc(sizeof(WCHAR
)*len
);
1715 MultiByteToWideChar(CP_UNIXCP
, 0, message
, -1, error
, len
);
1716 TRACE("fatal error for %p: %s\n", This
, debugstr_w(error
));
1719 if (!saxreader_has_handler(This
, SAXErrorHandler
))
1721 xmlStopParser(This
->pParserCtxt
);
1727 FIXME("Error handling is not compatible.\n");
1729 if(This
->vbInterface
)
1731 BSTR bstrError
= SysAllocString(error
);
1732 IVBSAXErrorHandler_fatalError(handler
->vbhandler
, &This
->IVBSAXLocator_iface
,
1733 &bstrError
, E_FAIL
);
1734 SysFreeString(bstrError
);
1737 ISAXErrorHandler_fatalError(handler
->handler
, &This
->ISAXLocator_iface
, error
, E_FAIL
);
1741 xmlStopParser(This
->pParserCtxt
);
1745 static void libxmlCDataBlock(void *ctx
, const xmlChar
*value
, int len
)
1747 saxlocator
*This
= ctx
;
1748 struct saxcontenthandler_iface
*content
= saxreader_get_contenthandler(This
->saxreader
);
1749 struct saxlexicalhandler_iface
*lexical
= saxreader_get_lexicalhandler(This
->saxreader
);
1751 xmlChar
*beg
= (xmlChar
*)This
->pParserCtxt
->input
->cur
-len
;
1755 BOOL lastEvent
= FALSE
, change
;
1757 update_position(This
, FALSE
);
1758 while(beg
-9>=This
->pParserCtxt
->input
->base
1759 && memcmp(beg
-9, "<![CDATA[", sizeof(char[9])))
1761 if(*beg
=='\n' || (*beg
=='\r' && *(beg
+1)!='\n'))
1766 for(; beg
>=This
->pParserCtxt
->input
->base
&& *beg
!='\n' && *beg
!='\r'; beg
--)
1769 if (saxreader_has_handler(This
, SAXLexicalHandler
))
1771 if (This
->vbInterface
)
1772 hr
= IVBSAXLexicalHandler_startCDATA(lexical
->vbhandler
);
1774 hr
= ISAXLexicalHandler_startCDATA(lexical
->handler
);
1779 format_error_message_from_id(This
, hr
);
1783 realLen
= This
->pParserCtxt
->input
->cur
-beg
-3;
1789 while(end
-beg
<realLen
&& *end
!='\r') end
++;
1790 if(end
-beg
==realLen
)
1795 else if(end
-beg
==realLen
-1 && *end
=='\r' && *(end
+1)=='\n')
1798 if(*end
== '\r') change
= TRUE
;
1799 else change
= FALSE
;
1801 if(change
) *end
= '\n';
1803 if (saxreader_has_handler(This
, SAXContentHandler
))
1805 Chars
= pooled_bstr_from_xmlCharN(&This
->saxreader
->pool
, cur
, end
-cur
+1);
1806 if (This
->vbInterface
)
1807 hr
= IVBSAXContentHandler_characters(content
->vbhandler
, &Chars
);
1809 hr
= ISAXContentHandler_characters(content
->handler
, Chars
, SysStringLen(Chars
));
1812 if(change
) *end
= '\r';
1817 This
->column
+= end
-cur
+2;
1822 if (saxreader_has_handler(This
, SAXLexicalHandler
))
1824 if (This
->vbInterface
)
1825 hr
= IVBSAXLexicalHandler_endCDATA(lexical
->vbhandler
);
1827 hr
= ISAXLexicalHandler_endCDATA(lexical
->handler
);
1831 format_error_message_from_id(This
, hr
);
1833 This
->column
+= 4+end
-cur
;
1836 /*** IVBSAXLocator interface ***/
1837 /*** IUnknown methods ***/
1838 static HRESULT WINAPI
ivbsaxlocator_QueryInterface(IVBSAXLocator
* iface
, REFIID riid
, void **ppvObject
)
1840 saxlocator
*This
= impl_from_IVBSAXLocator( iface
);
1842 TRACE("%p %s %p\n", This
, debugstr_guid( riid
), ppvObject
);
1846 if ( IsEqualGUID( riid
, &IID_IUnknown
) ||
1847 IsEqualGUID( riid
, &IID_IDispatch
) ||
1848 IsEqualGUID( riid
, &IID_IVBSAXLocator
))
1852 else if ( IsEqualGUID( riid
, &IID_IVBSAXAttributes
))
1854 *ppvObject
= &This
->IVBSAXAttributes_iface
;
1858 FIXME("interface %s not implemented\n", debugstr_guid(riid
));
1859 return E_NOINTERFACE
;
1862 IVBSAXLocator_AddRef( iface
);
1867 static ULONG WINAPI
ivbsaxlocator_AddRef(IVBSAXLocator
* iface
)
1869 saxlocator
*This
= impl_from_IVBSAXLocator( iface
);
1870 TRACE("%p\n", This
);
1871 return InterlockedIncrement( &This
->ref
);
1874 static ULONG WINAPI
ivbsaxlocator_Release(
1875 IVBSAXLocator
* iface
)
1877 saxlocator
*This
= impl_from_IVBSAXLocator( iface
);
1878 return ISAXLocator_Release((ISAXLocator
*)&This
->IVBSAXLocator_iface
);
1881 /*** IDispatch methods ***/
1882 static HRESULT WINAPI
ivbsaxlocator_GetTypeInfoCount( IVBSAXLocator
*iface
, UINT
* pctinfo
)
1884 saxlocator
*This
= impl_from_IVBSAXLocator( iface
);
1886 TRACE("(%p)->(%p)\n", This
, pctinfo
);
1893 static HRESULT WINAPI
ivbsaxlocator_GetTypeInfo(
1894 IVBSAXLocator
*iface
,
1895 UINT iTInfo
, LCID lcid
, ITypeInfo
** ppTInfo
)
1897 saxlocator
*This
= impl_from_IVBSAXLocator( iface
);
1900 TRACE("(%p)->(%u %u %p)\n", This
, iTInfo
, lcid
, ppTInfo
);
1902 hr
= get_typeinfo(IVBSAXLocator_tid
, ppTInfo
);
1907 static HRESULT WINAPI
ivbsaxlocator_GetIDsOfNames(
1908 IVBSAXLocator
*iface
,
1910 LPOLESTR
* rgszNames
,
1915 saxlocator
*This
= impl_from_IVBSAXLocator( iface
);
1916 ITypeInfo
*typeinfo
;
1919 TRACE("(%p)->(%s %p %u %u %p)\n", This
, debugstr_guid(riid
), rgszNames
, cNames
,
1922 if(!rgszNames
|| cNames
== 0 || !rgDispId
)
1923 return E_INVALIDARG
;
1925 hr
= get_typeinfo(IVBSAXLocator_tid
, &typeinfo
);
1928 hr
= ITypeInfo_GetIDsOfNames(typeinfo
, rgszNames
, cNames
, rgDispId
);
1929 ITypeInfo_Release(typeinfo
);
1935 static HRESULT WINAPI
ivbsaxlocator_Invoke(
1936 IVBSAXLocator
*iface
,
1937 DISPID dispIdMember
,
1941 DISPPARAMS
* pDispParams
,
1942 VARIANT
* pVarResult
,
1943 EXCEPINFO
* pExcepInfo
,
1946 saxlocator
*This
= impl_from_IVBSAXLocator( iface
);
1947 ITypeInfo
*typeinfo
;
1950 TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This
, dispIdMember
, debugstr_guid(riid
),
1951 lcid
, wFlags
, pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
1953 hr
= get_typeinfo(IVBSAXLocator_tid
, &typeinfo
);
1956 hr
= ITypeInfo_Invoke(typeinfo
, &This
->IVBSAXLocator_iface
, dispIdMember
, wFlags
,
1957 pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
1958 ITypeInfo_Release(typeinfo
);
1964 /*** IVBSAXLocator methods ***/
1965 static HRESULT WINAPI
ivbsaxlocator_get_columnNumber(
1966 IVBSAXLocator
* iface
,
1969 saxlocator
*This
= impl_from_IVBSAXLocator( iface
);
1970 return ISAXLocator_getColumnNumber((ISAXLocator
*)&This
->IVBSAXLocator_iface
, pnColumn
);
1973 static HRESULT WINAPI
ivbsaxlocator_get_lineNumber(
1974 IVBSAXLocator
* iface
,
1977 saxlocator
*This
= impl_from_IVBSAXLocator( iface
);
1978 return ISAXLocator_getLineNumber((ISAXLocator
*)&This
->IVBSAXLocator_iface
, pnLine
);
1981 static HRESULT WINAPI
ivbsaxlocator_get_publicId(
1982 IVBSAXLocator
* iface
,
1985 saxlocator
*This
= impl_from_IVBSAXLocator( iface
);
1986 return ISAXLocator_getPublicId((ISAXLocator
*)&This
->IVBSAXLocator_iface
,
1987 (const WCHAR
**)publicId
);
1990 static HRESULT WINAPI
ivbsaxlocator_get_systemId(
1991 IVBSAXLocator
* iface
,
1994 saxlocator
*This
= impl_from_IVBSAXLocator( iface
);
1995 return ISAXLocator_getSystemId((ISAXLocator
*)&This
->IVBSAXLocator_iface
,
1996 (const WCHAR
**)systemId
);
1999 static const struct IVBSAXLocatorVtbl VBSAXLocatorVtbl
=
2001 ivbsaxlocator_QueryInterface
,
2002 ivbsaxlocator_AddRef
,
2003 ivbsaxlocator_Release
,
2004 ivbsaxlocator_GetTypeInfoCount
,
2005 ivbsaxlocator_GetTypeInfo
,
2006 ivbsaxlocator_GetIDsOfNames
,
2007 ivbsaxlocator_Invoke
,
2008 ivbsaxlocator_get_columnNumber
,
2009 ivbsaxlocator_get_lineNumber
,
2010 ivbsaxlocator_get_publicId
,
2011 ivbsaxlocator_get_systemId
2014 /*** ISAXLocator interface ***/
2015 /*** IUnknown methods ***/
2016 static HRESULT WINAPI
isaxlocator_QueryInterface(ISAXLocator
* iface
, REFIID riid
, void **ppvObject
)
2018 saxlocator
*This
= impl_from_ISAXLocator( iface
);
2020 TRACE("%p %s %p\n", This
, debugstr_guid( riid
), ppvObject
);
2024 if ( IsEqualGUID( riid
, &IID_IUnknown
) ||
2025 IsEqualGUID( riid
, &IID_ISAXLocator
))
2029 else if ( IsEqualGUID( riid
, &IID_ISAXAttributes
))
2031 *ppvObject
= &This
->ISAXAttributes_iface
;
2035 WARN("interface %s not implemented\n", debugstr_guid(riid
));
2036 return E_NOINTERFACE
;
2039 ISAXLocator_AddRef( iface
);
2044 static ULONG WINAPI
isaxlocator_AddRef(ISAXLocator
* iface
)
2046 saxlocator
*This
= impl_from_ISAXLocator( iface
);
2047 ULONG ref
= InterlockedIncrement( &This
->ref
);
2048 TRACE("(%p)->(%d)\n", This
, ref
);
2052 static ULONG WINAPI
isaxlocator_Release(
2055 saxlocator
*This
= impl_from_ISAXLocator( iface
);
2056 LONG ref
= InterlockedDecrement( &This
->ref
);
2058 TRACE("(%p)->(%d)\n", This
, ref
);
2062 element_entry
*element
, *element2
;
2065 SysFreeString(This
->publicId
);
2066 SysFreeString(This
->systemId
);
2067 SysFreeString(This
->namespaceUri
);
2069 for(index
=0; index
<This
->nb_attributes
; index
++)
2071 SysFreeString(This
->attributes
[index
].szLocalname
);
2072 SysFreeString(This
->attributes
[index
].szValue
);
2073 SysFreeString(This
->attributes
[index
].szQName
);
2075 heap_free(This
->attributes
);
2078 LIST_FOR_EACH_ENTRY_SAFE(element
, element2
, &This
->elements
, element_entry
, entry
)
2080 list_remove(&element
->entry
);
2081 free_element_entry(element
);
2084 ISAXXMLReader_Release(&This
->saxreader
->ISAXXMLReader_iface
);
2091 /*** ISAXLocator methods ***/
2092 static HRESULT WINAPI
isaxlocator_getColumnNumber(
2096 saxlocator
*This
= impl_from_ISAXLocator( iface
);
2098 *pnColumn
= This
->column
;
2102 static HRESULT WINAPI
isaxlocator_getLineNumber(
2106 saxlocator
*This
= impl_from_ISAXLocator( iface
);
2108 *pnLine
= This
->line
;
2112 static HRESULT WINAPI
isaxlocator_getPublicId(
2114 const WCHAR
** ppwchPublicId
)
2117 saxlocator
*This
= impl_from_ISAXLocator( iface
);
2119 SysFreeString(This
->publicId
);
2121 publicId
= bstr_from_xmlChar(xmlSAX2GetPublicId(This
->pParserCtxt
));
2122 if(SysStringLen(publicId
))
2123 This
->publicId
= (WCHAR
*)&publicId
;
2126 SysFreeString(publicId
);
2127 This
->publicId
= NULL
;
2130 *ppwchPublicId
= This
->publicId
;
2134 static HRESULT WINAPI
isaxlocator_getSystemId(
2136 const WCHAR
** ppwchSystemId
)
2139 saxlocator
*This
= impl_from_ISAXLocator( iface
);
2141 SysFreeString(This
->systemId
);
2143 systemId
= bstr_from_xmlChar(xmlSAX2GetSystemId(This
->pParserCtxt
));
2144 if(SysStringLen(systemId
))
2145 This
->systemId
= (WCHAR
*)&systemId
;
2148 SysFreeString(systemId
);
2149 This
->systemId
= NULL
;
2152 *ppwchSystemId
= This
->systemId
;
2156 static const struct ISAXLocatorVtbl SAXLocatorVtbl
=
2158 isaxlocator_QueryInterface
,
2160 isaxlocator_Release
,
2161 isaxlocator_getColumnNumber
,
2162 isaxlocator_getLineNumber
,
2163 isaxlocator_getPublicId
,
2164 isaxlocator_getSystemId
2167 static HRESULT
SAXLocator_create(saxreader
*reader
, saxlocator
**ppsaxlocator
, BOOL vbInterface
)
2169 static const WCHAR w3xmlns
[] = { 'h','t','t','p',':','/','/', 'w','w','w','.','w','3','.',
2170 'o','r','g','/','2','0','0','0','/','x','m','l','n','s','/',0 };
2172 saxlocator
*locator
;
2174 locator
= heap_alloc( sizeof (*locator
) );
2176 return E_OUTOFMEMORY
;
2178 locator
->IVBSAXLocator_iface
.lpVtbl
= &VBSAXLocatorVtbl
;
2179 locator
->ISAXLocator_iface
.lpVtbl
= &SAXLocatorVtbl
;
2180 locator
->IVBSAXAttributes_iface
.lpVtbl
= &ivbsaxattributes_vtbl
;
2181 locator
->ISAXAttributes_iface
.lpVtbl
= &isaxattributes_vtbl
;
2183 locator
->vbInterface
= vbInterface
;
2185 locator
->saxreader
= reader
;
2186 ISAXXMLReader_AddRef(&reader
->ISAXXMLReader_iface
);
2188 locator
->pParserCtxt
= NULL
;
2189 locator
->publicId
= NULL
;
2190 locator
->systemId
= NULL
;
2191 locator
->line
= reader
->version
< MSXML4
? 0 : 1;
2192 locator
->column
= 0;
2193 locator
->ret
= S_OK
;
2194 if (locator
->saxreader
->version
>= MSXML6
)
2195 locator
->namespaceUri
= SysAllocString(w3xmlns
);
2197 locator
->namespaceUri
= SysAllocStringLen(NULL
, 0);
2198 if(!locator
->namespaceUri
)
2200 ISAXXMLReader_Release(&reader
->ISAXXMLReader_iface
);
2202 return E_OUTOFMEMORY
;
2205 locator
->attributesSize
= 8;
2206 locator
->nb_attributes
= 0;
2207 locator
->attributes
= heap_alloc(sizeof(struct _attributes
)*locator
->attributesSize
);
2208 if(!locator
->attributes
)
2210 ISAXXMLReader_Release(&reader
->ISAXXMLReader_iface
);
2211 SysFreeString(locator
->namespaceUri
);
2213 return E_OUTOFMEMORY
;
2216 list_init(&locator
->elements
);
2218 *ppsaxlocator
= locator
;
2220 TRACE("returning %p\n", *ppsaxlocator
);
2225 /*** SAXXMLReader internal functions ***/
2226 static HRESULT
internal_parseBuffer(saxreader
*This
, const char *buffer
, int size
, BOOL vbInterface
)
2228 xmlCharEncoding encoding
= XML_CHAR_ENCODING_NONE
;
2229 xmlChar
*enc_name
= NULL
;
2230 saxlocator
*locator
;
2233 TRACE("(%p)->(%p %d)\n", This
, buffer
, size
);
2235 hr
= SAXLocator_create(This
, &locator
, vbInterface
);
2241 const unsigned char *buff
= (unsigned char*)buffer
;
2243 encoding
= xmlDetectCharEncoding((xmlChar
*)buffer
, 4);
2244 enc_name
= (xmlChar
*)xmlGetCharEncodingName(encoding
);
2245 TRACE("detected encoding: %s\n", enc_name
);
2246 /* skip BOM, parser won't switch encodings and so won't skip it on its own */
2247 if ((encoding
== XML_CHAR_ENCODING_UTF8
) &&
2248 buff
[0] == 0xEF && buff
[1] == 0xBB && buff
[2] == 0xBF)
2255 /* if libxml2 detection failed try to guess */
2256 if (encoding
== XML_CHAR_ENCODING_NONE
)
2258 const WCHAR
*ptr
= (WCHAR
*)buffer
;
2259 /* xml declaration with possibly specfied encoding will be still handled by parser */
2260 if ((size
>= 2) && *ptr
== '<' && ptr
[1] != '?')
2262 enc_name
= (xmlChar
*)xmlGetCharEncodingName(XML_CHAR_ENCODING_UTF16LE
);
2263 encoding
= XML_CHAR_ENCODING_UTF16LE
;
2266 else if (encoding
== XML_CHAR_ENCODING_UTF8
)
2267 enc_name
= (xmlChar
*)xmlGetCharEncodingName(encoding
);
2271 locator
->pParserCtxt
= xmlCreateMemoryParserCtxt(buffer
, size
);
2272 if (!locator
->pParserCtxt
)
2274 ISAXLocator_Release(&locator
->ISAXLocator_iface
);
2280 locator
->pParserCtxt
->encoding
= xmlStrdup(enc_name
);
2281 if (encoding
== XML_CHAR_ENCODING_UTF16LE
) {
2282 TRACE("switching to %s\n", enc_name
);
2283 xmlSwitchEncoding(locator
->pParserCtxt
, encoding
);
2287 xmlFree(locator
->pParserCtxt
->sax
);
2288 locator
->pParserCtxt
->sax
= &locator
->saxreader
->sax
;
2289 locator
->pParserCtxt
->userData
= locator
;
2291 This
->isParsing
= TRUE
;
2292 if(xmlParseDocument(locator
->pParserCtxt
) == -1 && locator
->ret
== S_OK
)
2296 This
->isParsing
= FALSE
;
2298 if(locator
->pParserCtxt
)
2300 locator
->pParserCtxt
->sax
= NULL
;
2301 xmlFreeParserCtxt(locator
->pParserCtxt
);
2302 locator
->pParserCtxt
= NULL
;
2305 ISAXLocator_Release(&locator
->ISAXLocator_iface
);
2309 static HRESULT
internal_parseStream(saxreader
*This
, ISequentialStream
*stream
, BOOL vbInterface
)
2311 saxlocator
*locator
;
2318 hr
= ISequentialStream_Read(stream
, data
, sizeof(data
), &dataRead
);
2319 if(FAILED(hr
)) return hr
;
2321 hr
= SAXLocator_create(This
, &locator
, vbInterface
);
2322 if(FAILED(hr
)) return hr
;
2324 locator
->pParserCtxt
= xmlCreatePushParserCtxt(
2325 &locator
->saxreader
->sax
, locator
,
2326 data
, dataRead
, NULL
);
2327 if(!locator
->pParserCtxt
)
2329 ISAXLocator_Release(&locator
->ISAXLocator_iface
);
2333 This
->isParsing
= TRUE
;
2335 if(dataRead
!= sizeof(data
))
2337 ret
= xmlParseChunk(locator
->pParserCtxt
, data
, 0, 1);
2338 hr
= ret
!=XML_ERR_OK
&& locator
->ret
==S_OK
? E_FAIL
: locator
->ret
;
2345 hr
= ISequentialStream_Read(stream
, data
, sizeof(data
), &dataRead
);
2346 if (FAILED(hr
)) break;
2348 ret
= xmlParseChunk(locator
->pParserCtxt
, data
, dataRead
, 0);
2349 hr
= ret
!=XML_ERR_OK
&& locator
->ret
==S_OK
? E_FAIL
: locator
->ret
;
2351 if (hr
!= S_OK
) break;
2353 if (dataRead
!= sizeof(data
))
2355 ret
= xmlParseChunk(locator
->pParserCtxt
, data
, 0, 1);
2356 hr
= ret
!=XML_ERR_OK
&& locator
->ret
==S_OK
? E_FAIL
: locator
->ret
;
2362 This
->isParsing
= FALSE
;
2364 xmlFreeParserCtxt(locator
->pParserCtxt
);
2365 locator
->pParserCtxt
= NULL
;
2366 ISAXLocator_Release(&locator
->ISAXLocator_iface
);
2370 static HRESULT
internal_getEntityResolver(
2372 void *pEntityResolver
,
2375 FIXME("(%p)->(%p) stub\n", This
, pEntityResolver
);
2379 static HRESULT
internal_putEntityResolver(
2381 void *pEntityResolver
,
2384 FIXME("(%p)->(%p) stub\n", This
, pEntityResolver
);
2388 static HRESULT
internal_parse(
2395 TRACE("(%p)->(%s)\n", This
, debugstr_variant(&varInput
));
2397 /* Dispose of the BSTRs in the pool from a prior run, if any. */
2398 free_bstr_pool(&This
->pool
);
2400 switch(V_VT(&varInput
))
2403 hr
= internal_parseBuffer(This
, (const char*)V_BSTR(&varInput
),
2404 strlenW(V_BSTR(&varInput
))*sizeof(WCHAR
), vbInterface
);
2406 case VT_ARRAY
|VT_UI1
: {
2408 LONG lBound
, uBound
;
2411 hr
= SafeArrayGetLBound(V_ARRAY(&varInput
), 1, &lBound
);
2412 if(hr
!= S_OK
) break;
2413 hr
= SafeArrayGetUBound(V_ARRAY(&varInput
), 1, &uBound
);
2414 if(hr
!= S_OK
) break;
2415 dataRead
= (uBound
-lBound
)*SafeArrayGetElemsize(V_ARRAY(&varInput
));
2416 hr
= SafeArrayAccessData(V_ARRAY(&varInput
), &pSAData
);
2417 if(hr
!= S_OK
) break;
2418 hr
= internal_parseBuffer(This
, pSAData
, dataRead
, vbInterface
);
2419 SafeArrayUnaccessData(V_ARRAY(&varInput
));
2424 IPersistStream
*persistStream
;
2425 ISequentialStream
*stream
= NULL
;
2426 IXMLDOMDocument
*xmlDoc
;
2428 if(IUnknown_QueryInterface(V_UNKNOWN(&varInput
),
2429 &IID_IXMLDOMDocument
, (void**)&xmlDoc
) == S_OK
)
2433 IXMLDOMDocument_get_xml(xmlDoc
, &bstrData
);
2434 hr
= internal_parseBuffer(This
, (const char*)bstrData
,
2435 SysStringByteLen(bstrData
), vbInterface
);
2436 IXMLDOMDocument_Release(xmlDoc
);
2437 SysFreeString(bstrData
);
2441 if(IUnknown_QueryInterface(V_UNKNOWN(&varInput
),
2442 &IID_IPersistStream
, (void**)&persistStream
) == S_OK
)
2444 IStream
*stream_copy
;
2446 hr
= CreateStreamOnHGlobal(NULL
, TRUE
, &stream_copy
);
2449 IPersistStream_Release(persistStream
);
2453 hr
= IPersistStream_Save(persistStream
, stream_copy
, TRUE
);
2454 IPersistStream_Release(persistStream
);
2456 IStream_QueryInterface(stream_copy
, &IID_ISequentialStream
, (void**)&stream
);
2458 IStream_Release(stream_copy
);
2461 /* try base interface first */
2464 IUnknown_QueryInterface(V_UNKNOWN(&varInput
), &IID_ISequentialStream
, (void**)&stream
);
2466 /* this should never happen if IStream is implemented properly, but just in case */
2467 IUnknown_QueryInterface(V_UNKNOWN(&varInput
), &IID_IStream
, (void**)&stream
);
2472 hr
= internal_parseStream(This
, stream
, vbInterface
);
2473 ISequentialStream_Release(stream
);
2477 WARN("IUnknown* input doesn't support any of expected interfaces\n");
2484 WARN("vt %d not implemented\n", V_VT(&varInput
));
2491 static HRESULT
internal_vbonDataAvailable(void *obj
, char *ptr
, DWORD len
)
2493 saxreader
*This
= obj
;
2495 return internal_parseBuffer(This
, ptr
, len
, TRUE
);
2498 static HRESULT
internal_onDataAvailable(void *obj
, char *ptr
, DWORD len
)
2500 saxreader
*This
= obj
;
2502 return internal_parseBuffer(This
, ptr
, len
, FALSE
);
2505 static HRESULT
internal_parseURL(
2514 TRACE("(%p)->(%s)\n", This
, debugstr_w(url
));
2516 hr
= create_moniker_from_url(url
, &mon
);
2520 if(vbInterface
) hr
= bind_url(mon
, internal_vbonDataAvailable
, This
, &bsc
);
2521 else hr
= bind_url(mon
, internal_onDataAvailable
, This
, &bsc
);
2522 IMoniker_Release(mon
);
2527 return detach_bsc(bsc
);
2530 static HRESULT
internal_putProperty(
2536 TRACE("(%p)->(%s %s)\n", This
, debugstr_w(prop
), debugstr_variant(&value
));
2538 if(!memcmp(prop
, PropertyDeclHandlerW
, sizeof(PropertyDeclHandlerW
)))
2540 if(This
->isParsing
) return E_FAIL
;
2542 switch (V_VT(&value
))
2545 saxreader_put_handler(This
, SAXDeclHandler
, NULL
, vbInterface
);
2549 IUnknown
*handler
= NULL
;
2551 if (V_UNKNOWN(&value
))
2556 hr
= IUnknown_QueryInterface(V_UNKNOWN(&value
), &IID_IVBSAXDeclHandler
, (void**)&handler
);
2558 hr
= IUnknown_QueryInterface(V_UNKNOWN(&value
), &IID_ISAXDeclHandler
, (void**)&handler
);
2559 if (FAILED(hr
)) return hr
;
2562 saxreader_put_handler(This
, SAXDeclHandler
, handler
, vbInterface
);
2563 if (handler
) IUnknown_Release(handler
);
2567 return E_INVALIDARG
;
2573 if(!memcmp(prop
, PropertyLexicalHandlerW
, sizeof(PropertyLexicalHandlerW
)))
2575 if(This
->isParsing
) return E_FAIL
;
2577 switch (V_VT(&value
))
2580 saxreader_put_handler(This
, SAXLexicalHandler
, NULL
, vbInterface
);
2584 IUnknown
*handler
= NULL
;
2586 if (V_UNKNOWN(&value
))
2591 hr
= IUnknown_QueryInterface(V_UNKNOWN(&value
), &IID_IVBSAXLexicalHandler
, (void**)&handler
);
2593 hr
= IUnknown_QueryInterface(V_UNKNOWN(&value
), &IID_ISAXLexicalHandler
, (void**)&handler
);
2594 if (FAILED(hr
)) return hr
;
2597 saxreader_put_handler(This
, SAXLexicalHandler
, handler
, vbInterface
);
2598 if (handler
) IUnknown_Release(handler
);
2602 return E_INVALIDARG
;
2608 if(!memcmp(prop
, PropertyMaxXMLSizeW
, sizeof(PropertyMaxXMLSizeW
)))
2610 if (V_VT(&value
) == VT_I4
&& V_I4(&value
) == 0) return S_OK
;
2611 FIXME("(%p)->(%s): max-xml-size unsupported\n", This
, debugstr_variant(&value
));
2615 if(!memcmp(prop
, PropertyMaxElementDepthW
, sizeof(PropertyMaxElementDepthW
)))
2617 if (V_VT(&value
) == VT_I4
&& V_I4(&value
) == 0) return S_OK
;
2618 FIXME("(%p)->(%s): max-element-depth unsupported\n", This
, debugstr_variant(&value
));
2622 FIXME("(%p)->(%s:%s): unsupported property\n", This
, debugstr_w(prop
), debugstr_variant(&value
));
2624 if(!memcmp(prop
, PropertyCharsetW
, sizeof(PropertyCharsetW
)))
2627 if(!memcmp(prop
, PropertyDomNodeW
, sizeof(PropertyDomNodeW
)))
2630 if(!memcmp(prop
, PropertyInputSourceW
, sizeof(PropertyInputSourceW
)))
2633 if(!memcmp(prop
, PropertySchemaDeclHandlerW
, sizeof(PropertySchemaDeclHandlerW
)))
2636 if(!memcmp(prop
, PropertyXMLDeclEncodingW
, sizeof(PropertyXMLDeclEncodingW
)))
2639 if(!memcmp(prop
, PropertyXMLDeclStandaloneW
, sizeof(PropertyXMLDeclStandaloneW
)))
2642 if(!memcmp(prop
, PropertyXMLDeclVersionW
, sizeof(PropertyXMLDeclVersionW
)))
2645 return E_INVALIDARG
;
2648 static HRESULT
internal_getProperty(const saxreader
* This
, const WCHAR
*prop
, VARIANT
*value
, BOOL vb
)
2650 TRACE("(%p)->(%s)\n", This
, debugstr_w(prop
));
2652 if (!value
) return E_POINTER
;
2654 if (!memcmp(PropertyLexicalHandlerW
, prop
, sizeof(PropertyLexicalHandlerW
)))
2656 V_VT(value
) = VT_UNKNOWN
;
2657 saxreader_get_handler(This
, SAXLexicalHandler
, vb
, (void**)&V_UNKNOWN(value
));
2661 if (!memcmp(PropertyDeclHandlerW
, prop
, sizeof(PropertyDeclHandlerW
)))
2663 V_VT(value
) = VT_UNKNOWN
;
2664 saxreader_get_handler(This
, SAXDeclHandler
, vb
, (void**)&V_UNKNOWN(value
));
2668 if (!memcmp(PropertyXmlDeclVersionW
, prop
, sizeof(PropertyXmlDeclVersionW
)))
2670 V_VT(value
) = VT_BSTR
;
2671 V_BSTR(value
) = SysAllocString(This
->xmldecl_version
);
2675 FIXME("(%p)->(%s) unsupported property\n", This
, debugstr_w(prop
));
2680 /*** IVBSAXXMLReader interface ***/
2681 /*** IUnknown methods ***/
2682 static HRESULT WINAPI
saxxmlreader_QueryInterface(IVBSAXXMLReader
* iface
, REFIID riid
, void **ppvObject
)
2684 saxreader
*This
= impl_from_IVBSAXXMLReader( iface
);
2686 TRACE("%p %s %p\n", This
, debugstr_guid( riid
), ppvObject
);
2690 if ( IsEqualGUID( riid
, &IID_IUnknown
) ||
2691 IsEqualGUID( riid
, &IID_IDispatch
) ||
2692 IsEqualGUID( riid
, &IID_IVBSAXXMLReader
))
2696 else if( IsEqualGUID( riid
, &IID_ISAXXMLReader
))
2698 *ppvObject
= &This
->ISAXXMLReader_iface
;
2700 else if (dispex_query_interface(&This
->dispex
, riid
, ppvObject
))
2702 return *ppvObject
? S_OK
: E_NOINTERFACE
;
2706 FIXME("interface %s not implemented\n", debugstr_guid(riid
));
2707 return E_NOINTERFACE
;
2710 IVBSAXXMLReader_AddRef( iface
);
2715 static ULONG WINAPI
saxxmlreader_AddRef(IVBSAXXMLReader
* iface
)
2717 saxreader
*This
= impl_from_IVBSAXXMLReader( iface
);
2718 TRACE("%p\n", This
);
2719 return InterlockedIncrement( &This
->ref
);
2722 static ULONG WINAPI
saxxmlreader_Release(
2723 IVBSAXXMLReader
* iface
)
2725 saxreader
*This
= impl_from_IVBSAXXMLReader( iface
);
2728 TRACE("%p\n", This
);
2730 ref
= InterlockedDecrement( &This
->ref
);
2735 for (i
= 0; i
< SAXHandler_Last
; i
++)
2737 struct saxhandler_iface
*iface
= &This
->saxhandlers
[i
];
2740 IUnknown_Release(iface
->handler
);
2742 if (iface
->vbhandler
)
2743 IUnknown_Release(iface
->vbhandler
);
2746 SysFreeString(This
->xmldecl_version
);
2747 free_bstr_pool(&This
->pool
);
2749 release_dispex(&This
->dispex
);
2756 static HRESULT WINAPI
saxxmlreader_GetTypeInfoCount( IVBSAXXMLReader
*iface
, UINT
* pctinfo
)
2758 saxreader
*This
= impl_from_IVBSAXXMLReader( iface
);
2759 return IDispatchEx_GetTypeInfoCount(&This
->dispex
.IDispatchEx_iface
, pctinfo
);
2762 static HRESULT WINAPI
saxxmlreader_GetTypeInfo(
2763 IVBSAXXMLReader
*iface
,
2764 UINT iTInfo
, LCID lcid
, ITypeInfo
** ppTInfo
)
2766 saxreader
*This
= impl_from_IVBSAXXMLReader( iface
);
2767 return IDispatchEx_GetTypeInfo(&This
->dispex
.IDispatchEx_iface
,
2768 iTInfo
, lcid
, ppTInfo
);
2771 static HRESULT WINAPI
saxxmlreader_GetIDsOfNames(
2772 IVBSAXXMLReader
*iface
,
2774 LPOLESTR
* rgszNames
,
2779 saxreader
*This
= impl_from_IVBSAXXMLReader( iface
);
2780 return IDispatchEx_GetIDsOfNames(&This
->dispex
.IDispatchEx_iface
,
2781 riid
, rgszNames
, cNames
, lcid
, rgDispId
);
2784 static HRESULT WINAPI
saxxmlreader_Invoke(
2785 IVBSAXXMLReader
*iface
,
2786 DISPID dispIdMember
,
2790 DISPPARAMS
* pDispParams
,
2791 VARIANT
* pVarResult
,
2792 EXCEPINFO
* pExcepInfo
,
2795 saxreader
*This
= impl_from_IVBSAXXMLReader( iface
);
2796 return IDispatchEx_Invoke(&This
->dispex
.IDispatchEx_iface
,
2797 dispIdMember
, riid
, lcid
, wFlags
, pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
2800 /*** IVBSAXXMLReader methods ***/
2801 static HRESULT WINAPI
saxxmlreader_getFeature(
2802 IVBSAXXMLReader
* iface
,
2803 const WCHAR
*feature_name
,
2804 VARIANT_BOOL
*value
)
2806 saxreader
*This
= impl_from_IVBSAXXMLReader( iface
);
2807 saxreader_feature feature
;
2809 TRACE("(%p)->(%s %p)\n", This
, debugstr_w(feature_name
), value
);
2811 feature
= get_saxreader_feature(feature_name
);
2812 if (feature
== Namespaces
|| feature
== NamespacePrefixes
)
2813 return get_feature_value(This
, feature
, value
);
2815 FIXME("(%p)->(%s %p) stub\n", This
, debugstr_w(feature_name
), value
);
2819 static HRESULT WINAPI
saxxmlreader_putFeature(
2820 IVBSAXXMLReader
* iface
,
2821 const WCHAR
*feature_name
,
2824 saxreader
*This
= impl_from_IVBSAXXMLReader( iface
);
2825 saxreader_feature feature
;
2827 TRACE("(%p)->(%s %x)\n", This
, debugstr_w(feature_name
), value
);
2829 feature
= get_saxreader_feature(feature_name
);
2831 /* accepted cases */
2832 if ((feature
== ExternalGeneralEntities
&& value
== VARIANT_FALSE
) ||
2833 (feature
== ExternalParameterEntities
&& value
== VARIANT_FALSE
) ||
2834 feature
== Namespaces
||
2835 feature
== NamespacePrefixes
)
2837 return set_feature_value(This
, feature
, value
);
2840 if (feature
== LexicalHandlerParEntities
|| feature
== ProhibitDTD
)
2842 FIXME("(%p)->(%s %x) stub\n", This
, debugstr_w(feature_name
), value
);
2843 return set_feature_value(This
, feature
, value
);
2846 FIXME("(%p)->(%s %x) stub\n", This
, debugstr_w(feature_name
), value
);
2850 static HRESULT WINAPI
saxxmlreader_getProperty(
2851 IVBSAXXMLReader
* iface
,
2855 saxreader
*This
= impl_from_IVBSAXXMLReader( iface
);
2856 return internal_getProperty(This
, prop
, value
, TRUE
);
2859 static HRESULT WINAPI
saxxmlreader_putProperty(
2860 IVBSAXXMLReader
* iface
,
2864 saxreader
*This
= impl_from_IVBSAXXMLReader( iface
);
2865 return internal_putProperty(This
, pProp
, value
, TRUE
);
2868 static HRESULT WINAPI
saxxmlreader_get_entityResolver(
2869 IVBSAXXMLReader
* iface
,
2870 IVBSAXEntityResolver
**pEntityResolver
)
2872 saxreader
*This
= impl_from_IVBSAXXMLReader( iface
);
2873 return internal_getEntityResolver(This
, pEntityResolver
, TRUE
);
2876 static HRESULT WINAPI
saxxmlreader_put_entityResolver(
2877 IVBSAXXMLReader
* iface
,
2878 IVBSAXEntityResolver
*pEntityResolver
)
2880 saxreader
*This
= impl_from_IVBSAXXMLReader( iface
);
2881 return internal_putEntityResolver(This
, pEntityResolver
, TRUE
);
2884 static HRESULT WINAPI
saxxmlreader_get_contentHandler(
2885 IVBSAXXMLReader
* iface
,
2886 IVBSAXContentHandler
**handler
)
2888 saxreader
*This
= impl_from_IVBSAXXMLReader( iface
);
2889 return saxreader_get_handler(This
, SAXContentHandler
, TRUE
, (void**)handler
);
2892 static HRESULT WINAPI
saxxmlreader_put_contentHandler(
2893 IVBSAXXMLReader
* iface
,
2894 IVBSAXContentHandler
*handler
)
2896 saxreader
*This
= impl_from_IVBSAXXMLReader( iface
);
2897 return saxreader_put_handler(This
, SAXContentHandler
, handler
, TRUE
);
2900 static HRESULT WINAPI
saxxmlreader_get_dtdHandler(
2901 IVBSAXXMLReader
* iface
,
2902 IVBSAXDTDHandler
**handler
)
2904 saxreader
*This
= impl_from_IVBSAXXMLReader( iface
);
2905 return saxreader_get_handler(This
, SAXDTDHandler
, TRUE
, (void**)handler
);
2908 static HRESULT WINAPI
saxxmlreader_put_dtdHandler(
2909 IVBSAXXMLReader
* iface
,
2910 IVBSAXDTDHandler
*handler
)
2912 saxreader
*This
= impl_from_IVBSAXXMLReader( iface
);
2913 return saxreader_put_handler(This
, SAXDTDHandler
, handler
, TRUE
);
2916 static HRESULT WINAPI
saxxmlreader_get_errorHandler(
2917 IVBSAXXMLReader
* iface
,
2918 IVBSAXErrorHandler
**handler
)
2920 saxreader
*This
= impl_from_IVBSAXXMLReader( iface
);
2921 return saxreader_get_handler(This
, SAXErrorHandler
, TRUE
, (void**)handler
);
2924 static HRESULT WINAPI
saxxmlreader_put_errorHandler(
2925 IVBSAXXMLReader
* iface
,
2926 IVBSAXErrorHandler
*handler
)
2928 saxreader
*This
= impl_from_IVBSAXXMLReader( iface
);
2929 return saxreader_put_handler(This
, SAXErrorHandler
, handler
, TRUE
);
2932 static HRESULT WINAPI
saxxmlreader_get_baseURL(
2933 IVBSAXXMLReader
* iface
,
2934 const WCHAR
**pBaseUrl
)
2936 saxreader
*This
= impl_from_IVBSAXXMLReader( iface
);
2938 FIXME("(%p)->(%p) stub\n", This
, pBaseUrl
);
2942 static HRESULT WINAPI
saxxmlreader_put_baseURL(
2943 IVBSAXXMLReader
* iface
,
2944 const WCHAR
*pBaseUrl
)
2946 saxreader
*This
= impl_from_IVBSAXXMLReader( iface
);
2948 FIXME("(%p)->(%s) stub\n", This
, debugstr_w(pBaseUrl
));
2952 static HRESULT WINAPI
saxxmlreader_get_secureBaseURL(
2953 IVBSAXXMLReader
* iface
,
2954 const WCHAR
**pSecureBaseUrl
)
2956 saxreader
*This
= impl_from_IVBSAXXMLReader( iface
);
2958 FIXME("(%p)->(%p) stub\n", This
, pSecureBaseUrl
);
2963 static HRESULT WINAPI
saxxmlreader_put_secureBaseURL(
2964 IVBSAXXMLReader
* iface
,
2965 const WCHAR
*secureBaseUrl
)
2967 saxreader
*This
= impl_from_IVBSAXXMLReader( iface
);
2969 FIXME("(%p)->(%s) stub\n", This
, debugstr_w(secureBaseUrl
));
2973 static HRESULT WINAPI
saxxmlreader_parse(
2974 IVBSAXXMLReader
* iface
,
2977 saxreader
*This
= impl_from_IVBSAXXMLReader( iface
);
2978 return internal_parse(This
, varInput
, TRUE
);
2981 static HRESULT WINAPI
saxxmlreader_parseURL(
2982 IVBSAXXMLReader
* iface
,
2985 saxreader
*This
= impl_from_IVBSAXXMLReader( iface
);
2986 return internal_parseURL(This
, url
, TRUE
);
2989 static const struct IVBSAXXMLReaderVtbl VBSAXXMLReaderVtbl
=
2991 saxxmlreader_QueryInterface
,
2992 saxxmlreader_AddRef
,
2993 saxxmlreader_Release
,
2994 saxxmlreader_GetTypeInfoCount
,
2995 saxxmlreader_GetTypeInfo
,
2996 saxxmlreader_GetIDsOfNames
,
2997 saxxmlreader_Invoke
,
2998 saxxmlreader_getFeature
,
2999 saxxmlreader_putFeature
,
3000 saxxmlreader_getProperty
,
3001 saxxmlreader_putProperty
,
3002 saxxmlreader_get_entityResolver
,
3003 saxxmlreader_put_entityResolver
,
3004 saxxmlreader_get_contentHandler
,
3005 saxxmlreader_put_contentHandler
,
3006 saxxmlreader_get_dtdHandler
,
3007 saxxmlreader_put_dtdHandler
,
3008 saxxmlreader_get_errorHandler
,
3009 saxxmlreader_put_errorHandler
,
3010 saxxmlreader_get_baseURL
,
3011 saxxmlreader_put_baseURL
,
3012 saxxmlreader_get_secureBaseURL
,
3013 saxxmlreader_put_secureBaseURL
,
3015 saxxmlreader_parseURL
3018 /*** ISAXXMLReader interface ***/
3019 /*** IUnknown methods ***/
3020 static HRESULT WINAPI
isaxxmlreader_QueryInterface(ISAXXMLReader
* iface
, REFIID riid
, void **ppvObject
)
3022 saxreader
*This
= impl_from_ISAXXMLReader( iface
);
3023 return saxxmlreader_QueryInterface(&This
->IVBSAXXMLReader_iface
, riid
, ppvObject
);
3026 static ULONG WINAPI
isaxxmlreader_AddRef(ISAXXMLReader
* iface
)
3028 saxreader
*This
= impl_from_ISAXXMLReader( iface
);
3029 return saxxmlreader_AddRef(&This
->IVBSAXXMLReader_iface
);
3032 static ULONG WINAPI
isaxxmlreader_Release(ISAXXMLReader
* iface
)
3034 saxreader
*This
= impl_from_ISAXXMLReader( iface
);
3035 return saxxmlreader_Release(&This
->IVBSAXXMLReader_iface
);
3038 /*** ISAXXMLReader methods ***/
3039 static HRESULT WINAPI
isaxxmlreader_getFeature(
3040 ISAXXMLReader
* iface
,
3041 const WCHAR
*pFeature
,
3042 VARIANT_BOOL
*pValue
)
3044 saxreader
*This
= impl_from_ISAXXMLReader( iface
);
3045 return IVBSAXXMLReader_getFeature(&This
->IVBSAXXMLReader_iface
, pFeature
, pValue
);
3048 static HRESULT WINAPI
isaxxmlreader_putFeature(
3049 ISAXXMLReader
* iface
,
3050 const WCHAR
*pFeature
,
3051 VARIANT_BOOL vfValue
)
3053 saxreader
*This
= impl_from_ISAXXMLReader( iface
);
3054 return IVBSAXXMLReader_putFeature(&This
->IVBSAXXMLReader_iface
, pFeature
, vfValue
);
3057 static HRESULT WINAPI
isaxxmlreader_getProperty(
3058 ISAXXMLReader
* iface
,
3062 saxreader
*This
= impl_from_ISAXXMLReader( iface
);
3063 return internal_getProperty(This
, prop
, value
, FALSE
);
3066 static HRESULT WINAPI
isaxxmlreader_putProperty(
3067 ISAXXMLReader
* iface
,
3071 saxreader
*This
= impl_from_ISAXXMLReader( iface
);
3072 return internal_putProperty(This
, pProp
, value
, FALSE
);
3075 static HRESULT WINAPI
isaxxmlreader_getEntityResolver(
3076 ISAXXMLReader
* iface
,
3077 ISAXEntityResolver
**ppEntityResolver
)
3079 saxreader
*This
= impl_from_ISAXXMLReader( iface
);
3080 return internal_getEntityResolver(This
, ppEntityResolver
, FALSE
);
3083 static HRESULT WINAPI
isaxxmlreader_putEntityResolver(
3084 ISAXXMLReader
* iface
,
3085 ISAXEntityResolver
*pEntityResolver
)
3087 saxreader
*This
= impl_from_ISAXXMLReader( iface
);
3088 return internal_putEntityResolver(This
, pEntityResolver
, FALSE
);
3091 static HRESULT WINAPI
isaxxmlreader_getContentHandler(
3092 ISAXXMLReader
* iface
,
3093 ISAXContentHandler
**handler
)
3095 saxreader
*This
= impl_from_ISAXXMLReader( iface
);
3096 return saxreader_get_handler(This
, SAXContentHandler
, FALSE
, (void**)handler
);
3099 static HRESULT WINAPI
isaxxmlreader_putContentHandler(
3100 ISAXXMLReader
* iface
,
3101 ISAXContentHandler
*handler
)
3103 saxreader
*This
= impl_from_ISAXXMLReader( iface
);
3104 return saxreader_put_handler(This
, SAXContentHandler
, handler
, FALSE
);
3107 static HRESULT WINAPI
isaxxmlreader_getDTDHandler(
3108 ISAXXMLReader
* iface
,
3109 ISAXDTDHandler
**handler
)
3111 saxreader
*This
= impl_from_ISAXXMLReader( iface
);
3112 return saxreader_get_handler(This
, SAXDTDHandler
, FALSE
, (void**)handler
);
3115 static HRESULT WINAPI
isaxxmlreader_putDTDHandler(
3116 ISAXXMLReader
* iface
,
3117 ISAXDTDHandler
*handler
)
3119 saxreader
*This
= impl_from_ISAXXMLReader( iface
);
3120 return saxreader_put_handler(This
, SAXDTDHandler
, handler
, FALSE
);
3123 static HRESULT WINAPI
isaxxmlreader_getErrorHandler(
3124 ISAXXMLReader
* iface
,
3125 ISAXErrorHandler
**handler
)
3127 saxreader
*This
= impl_from_ISAXXMLReader( iface
);
3128 return saxreader_get_handler(This
, SAXErrorHandler
, FALSE
, (void**)handler
);
3131 static HRESULT WINAPI
isaxxmlreader_putErrorHandler(ISAXXMLReader
* iface
, ISAXErrorHandler
*handler
)
3133 saxreader
*This
= impl_from_ISAXXMLReader( iface
);
3134 return saxreader_put_handler(This
, SAXErrorHandler
, handler
, FALSE
);
3137 static HRESULT WINAPI
isaxxmlreader_getBaseURL(
3138 ISAXXMLReader
* iface
,
3139 const WCHAR
**pBaseUrl
)
3141 saxreader
*This
= impl_from_ISAXXMLReader( iface
);
3142 return IVBSAXXMLReader_get_baseURL(&This
->IVBSAXXMLReader_iface
, pBaseUrl
);
3145 static HRESULT WINAPI
isaxxmlreader_putBaseURL(
3146 ISAXXMLReader
* iface
,
3147 const WCHAR
*pBaseUrl
)
3149 saxreader
*This
= impl_from_ISAXXMLReader( iface
);
3150 return IVBSAXXMLReader_put_baseURL(&This
->IVBSAXXMLReader_iface
, pBaseUrl
);
3153 static HRESULT WINAPI
isaxxmlreader_getSecureBaseURL(
3154 ISAXXMLReader
* iface
,
3155 const WCHAR
**pSecureBaseUrl
)
3157 saxreader
*This
= impl_from_ISAXXMLReader( iface
);
3158 return IVBSAXXMLReader_get_secureBaseURL(&This
->IVBSAXXMLReader_iface
, pSecureBaseUrl
);
3161 static HRESULT WINAPI
isaxxmlreader_putSecureBaseURL(
3162 ISAXXMLReader
* iface
,
3163 const WCHAR
*secureBaseUrl
)
3165 saxreader
*This
= impl_from_ISAXXMLReader( iface
);
3166 return IVBSAXXMLReader_put_secureBaseURL(&This
->IVBSAXXMLReader_iface
, secureBaseUrl
);
3169 static HRESULT WINAPI
isaxxmlreader_parse(
3170 ISAXXMLReader
* iface
,
3173 saxreader
*This
= impl_from_ISAXXMLReader( iface
);
3174 return internal_parse(This
, varInput
, FALSE
);
3177 static HRESULT WINAPI
isaxxmlreader_parseURL(
3178 ISAXXMLReader
* iface
,
3181 saxreader
*This
= impl_from_ISAXXMLReader( iface
);
3182 return internal_parseURL(This
, url
, FALSE
);
3185 static const struct ISAXXMLReaderVtbl SAXXMLReaderVtbl
=
3187 isaxxmlreader_QueryInterface
,
3188 isaxxmlreader_AddRef
,
3189 isaxxmlreader_Release
,
3190 isaxxmlreader_getFeature
,
3191 isaxxmlreader_putFeature
,
3192 isaxxmlreader_getProperty
,
3193 isaxxmlreader_putProperty
,
3194 isaxxmlreader_getEntityResolver
,
3195 isaxxmlreader_putEntityResolver
,
3196 isaxxmlreader_getContentHandler
,
3197 isaxxmlreader_putContentHandler
,
3198 isaxxmlreader_getDTDHandler
,
3199 isaxxmlreader_putDTDHandler
,
3200 isaxxmlreader_getErrorHandler
,
3201 isaxxmlreader_putErrorHandler
,
3202 isaxxmlreader_getBaseURL
,
3203 isaxxmlreader_putBaseURL
,
3204 isaxxmlreader_getSecureBaseURL
,
3205 isaxxmlreader_putSecureBaseURL
,
3206 isaxxmlreader_parse
,
3207 isaxxmlreader_parseURL
3210 static const tid_t saxreader_iface_tids
[] = {
3211 IVBSAXXMLReader_tid
,
3214 static dispex_static_data_t saxreader_dispex
= {
3216 IVBSAXXMLReader_tid
,
3218 saxreader_iface_tids
3221 HRESULT
SAXXMLReader_create(MSXML_VERSION version
, IUnknown
*outer
, LPVOID
*ppObj
)
3225 TRACE("(%p, %p)\n", outer
, ppObj
);
3227 reader
= heap_alloc( sizeof (*reader
) );
3229 return E_OUTOFMEMORY
;
3231 reader
->IVBSAXXMLReader_iface
.lpVtbl
= &VBSAXXMLReaderVtbl
;
3232 reader
->ISAXXMLReader_iface
.lpVtbl
= &SAXXMLReaderVtbl
;
3234 memset(reader
->saxhandlers
, 0, sizeof(reader
->saxhandlers
));
3235 reader
->isParsing
= FALSE
;
3236 reader
->xmldecl_version
= NULL
;
3237 reader
->pool
.pool
= NULL
;
3238 reader
->pool
.index
= 0;
3239 reader
->pool
.len
= 0;
3240 reader
->features
= Namespaces
| NamespacePrefixes
;
3241 reader
->version
= version
;
3243 init_dispex(&reader
->dispex
, (IUnknown
*)&reader
->IVBSAXXMLReader_iface
, &saxreader_dispex
);
3245 memset(&reader
->sax
, 0, sizeof(xmlSAXHandler
));
3246 reader
->sax
.initialized
= XML_SAX2_MAGIC
;
3247 reader
->sax
.startDocument
= libxmlStartDocument
;
3248 reader
->sax
.endDocument
= libxmlEndDocument
;
3249 reader
->sax
.startElementNs
= libxmlStartElementNS
;
3250 reader
->sax
.endElementNs
= libxmlEndElementNS
;
3251 reader
->sax
.characters
= libxmlCharacters
;
3252 reader
->sax
.setDocumentLocator
= libxmlSetDocumentLocator
;
3253 reader
->sax
.comment
= libxmlComment
;
3254 reader
->sax
.error
= libxmlFatalError
;
3255 reader
->sax
.fatalError
= libxmlFatalError
;
3256 reader
->sax
.cdataBlock
= libxmlCDataBlock
;
3258 *ppObj
= &reader
->IVBSAXXMLReader_iface
;
3260 TRACE("returning iface %p\n", *ppObj
);
3267 HRESULT
SAXXMLReader_create(MSXML_VERSION version
, IUnknown
*pUnkOuter
, LPVOID
*ppObj
)
3269 MESSAGE("This program tried to use a SAX XML Reader object, but\n"
3270 "libxml2 support was not present at compile time.\n");