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 */
169 IVBSAXXMLReader IVBSAXXMLReader_iface
;
170 ISAXXMLReader ISAXXMLReader_iface
;
172 ISAXContentHandler
*contentHandler
;
173 IVBSAXContentHandler
*vbcontentHandler
;
174 ISAXErrorHandler
*errorHandler
;
175 IVBSAXErrorHandler
*vberrorHandler
;
176 ISAXLexicalHandler
*lexicalHandler
;
177 IVBSAXLexicalHandler
*vblexicalHandler
;
178 ISAXDeclHandler
*declHandler
;
179 IVBSAXDeclHandler
*vbdeclHandler
;
182 struct bstrpool pool
;
183 saxreader_feature features
;
184 MSXML_VERSION version
;
189 IVBSAXLocator IVBSAXLocator_iface
;
190 ISAXLocator ISAXLocator_iface
;
191 IVBSAXAttributes IVBSAXAttributes_iface
;
192 ISAXAttributes ISAXAttributes_iface
;
194 saxreader
*saxreader
;
196 xmlParserCtxtPtr pParserCtxt
;
202 struct list elements
;
216 static inline saxreader
*impl_from_IVBSAXXMLReader( IVBSAXXMLReader
*iface
)
218 return CONTAINING_RECORD(iface
, saxreader
, IVBSAXXMLReader_iface
);
221 static inline saxreader
*impl_from_ISAXXMLReader( ISAXXMLReader
*iface
)
223 return CONTAINING_RECORD(iface
, saxreader
, ISAXXMLReader_iface
);
226 static inline saxlocator
*impl_from_IVBSAXLocator( IVBSAXLocator
*iface
)
228 return CONTAINING_RECORD(iface
, saxlocator
, IVBSAXLocator_iface
);
231 static inline saxlocator
*impl_from_ISAXLocator( ISAXLocator
*iface
)
233 return CONTAINING_RECORD(iface
, saxlocator
, ISAXLocator_iface
);
236 static inline saxlocator
*impl_from_IVBSAXAttributes( IVBSAXAttributes
*iface
)
238 return CONTAINING_RECORD(iface
, saxlocator
, IVBSAXAttributes_iface
);
241 static inline saxlocator
*impl_from_ISAXAttributes( ISAXAttributes
*iface
)
243 return CONTAINING_RECORD(iface
, saxlocator
, ISAXAttributes_iface
);
247 static const WCHAR PropertyCharsetW
[] = {
248 'c','h','a','r','s','e','t',0
250 static const WCHAR PropertyDeclHandlerW
[] = {
251 'h','t','t','p',':','/','/','x','m','l','.','o','r','g','/',
252 's','a','x','/','p','r','o','p','e','r','t','i','e','s','/',
253 'd','e','c','l','a','r','a','t','i','o','n',
254 '-','h','a','n','d','l','e','r',0
256 static const WCHAR PropertyDomNodeW
[] = {
257 'h','t','t','p',':','/','/','x','m','l','.','o','r','g','/',
258 's','a','x','/','p','r','o','p','e','r','t','i','e','s','/',
259 'd','o','m','-','n','o','d','e',0
261 static const WCHAR PropertyInputSourceW
[] = {
262 'i','n','p','u','t','-','s','o','u','r','c','e',0
264 static const WCHAR PropertyLexicalHandlerW
[] = {
265 'h','t','t','p',':','/','/','x','m','l','.','o','r','g','/',
266 's','a','x','/','p','r','o','p','e','r','t','i','e','s','/',
267 'l','e','x','i','c','a','l','-','h','a','n','d','l','e','r',0
269 static const WCHAR PropertyMaxElementDepthW
[] = {
270 'm','a','x','-','e','l','e','m','e','n','t','-','d','e','p','t','h',0
272 static const WCHAR PropertyMaxXMLSizeW
[] = {
273 'm','a','x','-','x','m','l','-','s','i','z','e',0
275 static const WCHAR PropertySchemaDeclHandlerW
[] = {
276 's','c','h','e','m','a','-','d','e','c','l','a','r','a','t','i','o','n','-',
277 'h','a','n','d','l','e','r',0
279 static const WCHAR PropertyXMLDeclEncodingW
[] = {
280 'x','m','l','d','e','c','l','-','e','n','c','o','d','i','n','g',0
282 static const WCHAR PropertyXMLDeclStandaloneW
[] = {
283 'x','m','l','d','e','c','l','-','s','t','a','n','d','a','l','o','n','e',0
285 static const WCHAR PropertyXMLDeclVersionW
[] = {
286 'x','m','l','d','e','c','l','-','v','e','r','s','i','o','n',0
289 static inline HRESULT
set_feature_value(saxreader
*reader
, saxreader_feature feature
, VARIANT_BOOL value
)
291 /* handling of non-VARIANT_* values is version dependent */
292 if ((reader
->version
< MSXML4
) && (value
!= VARIANT_TRUE
))
293 value
= VARIANT_FALSE
;
294 if ((reader
->version
>= MSXML4
) && (value
!= VARIANT_FALSE
))
295 value
= VARIANT_TRUE
;
297 if (value
== VARIANT_TRUE
)
298 reader
->features
|= feature
;
300 reader
->features
&= ~feature
;
305 static inline HRESULT
get_feature_value(const saxreader
*reader
, saxreader_feature feature
, VARIANT_BOOL
*value
)
307 *value
= reader
->features
& feature
? VARIANT_TRUE
: VARIANT_FALSE
;
311 static BOOL
is_namespaces_enabled(const saxreader
*reader
)
313 return (reader
->version
< MSXML4
) || (reader
->features
& Namespaces
);
316 static inline int has_content_handler(const saxlocator
*locator
)
318 return (locator
->vbInterface
&& locator
->saxreader
->vbcontentHandler
) ||
319 (!locator
->vbInterface
&& locator
->saxreader
->contentHandler
);
322 static inline int has_lexical_handler(const saxlocator
*locator
)
324 return (locator
->vbInterface
&& locator
->saxreader
->vblexicalHandler
) ||
325 (!locator
->vbInterface
&& locator
->saxreader
->lexicalHandler
);
328 static inline int has_error_handler(const saxlocator
*locator
)
330 return (locator
->vbInterface
&& locator
->saxreader
->vberrorHandler
) ||
331 (!locator
->vbInterface
&& locator
->saxreader
->errorHandler
);
334 static BSTR
build_qname(BSTR prefix
, BSTR local
)
336 if (prefix
&& *prefix
)
338 BSTR qname
= SysAllocStringLen(NULL
, SysStringLen(prefix
) + SysStringLen(local
) + 1);
342 strcpyW(ptr
, prefix
);
343 ptr
+= SysStringLen(prefix
);
349 return SysAllocString(local
);
352 static element_entry
* alloc_element_entry(const xmlChar
*local
, const xmlChar
*prefix
, int nb_ns
,
353 const xmlChar
**namespaces
)
358 ret
= heap_alloc(sizeof(*ret
));
359 if (!ret
) return ret
;
361 ret
->local
= bstr_from_xmlChar(local
);
362 ret
->prefix
= bstr_from_xmlChar(prefix
);
363 ret
->qname
= build_qname(ret
->prefix
, ret
->local
);
364 ret
->ns
= nb_ns
? heap_alloc(nb_ns
*sizeof(ns
)) : NULL
;
365 ret
->ns_count
= nb_ns
;
367 for (i
=0; i
< nb_ns
; i
++)
369 ret
->ns
[i
].prefix
= bstr_from_xmlChar(namespaces
[2*i
]);
370 ret
->ns
[i
].uri
= bstr_from_xmlChar(namespaces
[2*i
+1]);
376 static void free_element_entry(element_entry
*element
)
380 for (i
=0; i
<element
->ns_count
;i
++)
382 SysFreeString(element
->ns
[i
].prefix
);
383 SysFreeString(element
->ns
[i
].uri
);
386 SysFreeString(element
->prefix
);
387 SysFreeString(element
->local
);
389 heap_free(element
->ns
);
393 static void push_element_ns(saxlocator
*locator
, element_entry
*element
)
395 list_add_head(&locator
->elements
, &element
->entry
);
398 static element_entry
* pop_element_ns(saxlocator
*locator
)
400 element_entry
*element
= LIST_ENTRY(list_head(&locator
->elements
), element_entry
, entry
);
403 list_remove(&element
->entry
);
408 static BSTR
find_element_uri(saxlocator
*locator
, const xmlChar
*uri
)
410 element_entry
*element
;
414 if (!uri
) return NULL
;
416 uriW
= bstr_from_xmlChar(uri
);
418 LIST_FOR_EACH_ENTRY(element
, &locator
->elements
, element_entry
, entry
)
420 for (i
=0; i
< element
->ns_count
; i
++)
421 if (!strcmpW(uriW
, element
->ns
[i
].uri
))
424 return element
->ns
[i
].uri
;
429 ERR("namespace uri not found, %s\n", debugstr_a((char*)uri
));
433 /* used to localize version dependent error check behaviour */
434 static inline BOOL
sax_callback_failed(saxlocator
*This
, HRESULT hr
)
436 return This
->saxreader
->version
>= MSXML4
? FAILED(hr
) : hr
!= S_OK
;
439 /* index value -1 means it tries to loop for a first time */
440 static inline BOOL
iterate_endprefix_index(saxlocator
*This
, const element_entry
*element
, int *i
)
442 if (This
->saxreader
->version
>= MSXML4
)
444 if (*i
== -1) *i
= 0; else ++*i
;
445 return *i
< element
->ns_count
;
449 if (*i
== -1) *i
= element
->ns_count
-1; else --*i
;
454 static BOOL
bstr_pool_insert(struct bstrpool
*pool
, BSTR pool_entry
)
458 pool
->pool
= HeapAlloc(GetProcessHeap(), 0, 16 * sizeof(*pool
->pool
));
465 else if (pool
->index
== pool
->len
)
467 BSTR
*realloc
= HeapReAlloc(GetProcessHeap(), 0, pool
->pool
, pool
->len
* 2 * sizeof(*realloc
));
472 pool
->pool
= realloc
;
476 pool
->pool
[pool
->index
++] = pool_entry
;
480 static void free_bstr_pool(struct bstrpool
*pool
)
484 for (i
= 0; i
< pool
->index
; i
++)
485 SysFreeString(pool
->pool
[i
]);
487 HeapFree(GetProcessHeap(), 0, pool
->pool
);
490 pool
->index
= pool
->len
= 0;
493 static BSTR
bstr_from_xmlCharN(const xmlChar
*buf
, int len
)
501 dLen
= MultiByteToWideChar(CP_UTF8
, 0, (LPCSTR
)buf
, len
, NULL
, 0);
502 if(len
!= -1) dLen
++;
503 bstr
= SysAllocStringLen(NULL
, dLen
-1);
506 MultiByteToWideChar(CP_UTF8
, 0, (LPCSTR
)buf
, len
, bstr
, dLen
);
507 if(len
!= -1) bstr
[dLen
-1] = '\0';
512 static BSTR
QName_from_xmlChar(const xmlChar
*prefix
, const xmlChar
*name
)
517 if(!name
) return NULL
;
519 if(!prefix
|| !*prefix
)
520 return bstr_from_xmlChar(name
);
522 qname
= xmlBuildQName(name
, prefix
, NULL
, 0);
523 bstr
= bstr_from_xmlChar(qname
);
529 static BSTR
pooled_bstr_from_xmlChar(struct bstrpool
*pool
, const xmlChar
*buf
)
531 BSTR pool_entry
= bstr_from_xmlChar(buf
);
533 if (pool_entry
&& !bstr_pool_insert(pool
, pool_entry
))
535 SysFreeString(pool_entry
);
542 static BSTR
pooled_bstr_from_xmlCharN(struct bstrpool
*pool
, const xmlChar
*buf
, int len
)
544 BSTR pool_entry
= bstr_from_xmlCharN(buf
, len
);
546 if (pool_entry
&& !bstr_pool_insert(pool
, pool_entry
))
548 SysFreeString(pool_entry
);
555 static void format_error_message_from_id(saxlocator
*This
, HRESULT hr
)
557 xmlStopParser(This
->pParserCtxt
);
560 if(has_error_handler(This
))
563 if(!FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM
,
564 NULL
, hr
, 0, msg
, sizeof(msg
), NULL
))
566 FIXME("MSXML errors not yet supported.\n");
570 if(This
->vbInterface
)
572 BSTR bstrMsg
= SysAllocString(msg
);
573 IVBSAXErrorHandler_fatalError(This
->saxreader
->vberrorHandler
,
574 &This
->IVBSAXLocator_iface
, &bstrMsg
, hr
);
575 SysFreeString(bstrMsg
);
578 ISAXErrorHandler_fatalError(This
->saxreader
->errorHandler
,
579 &This
->ISAXLocator_iface
, msg
, hr
);
583 static void update_position(saxlocator
*This
, BOOL fix_column
)
585 const xmlChar
*p
= This
->pParserCtxt
->input
->cur
-1;
587 This
->line
= xmlSAX2GetLineNumber(This
->pParserCtxt
);
591 for(; *p
!='\n' && *p
!='\r' && p
>=This
->pParserCtxt
->input
->base
; p
--)
596 This
->column
= xmlSAX2GetColumnNumber(This
->pParserCtxt
);
600 /*** IVBSAXAttributes interface ***/
601 /*** IUnknown methods ***/
602 static HRESULT WINAPI
ivbsaxattributes_QueryInterface(
603 IVBSAXAttributes
* iface
,
607 saxlocator
*This
= impl_from_IVBSAXAttributes(iface
);
608 TRACE("%p %s %p\n", This
, debugstr_guid(riid
), ppvObject
);
609 return IVBSAXLocator_QueryInterface(&This
->IVBSAXLocator_iface
, riid
, ppvObject
);
612 static ULONG WINAPI
ivbsaxattributes_AddRef(IVBSAXAttributes
* iface
)
614 saxlocator
*This
= impl_from_IVBSAXAttributes(iface
);
615 return ISAXLocator_AddRef(&This
->ISAXLocator_iface
);
618 static ULONG WINAPI
ivbsaxattributes_Release(IVBSAXAttributes
* iface
)
620 saxlocator
*This
= impl_from_IVBSAXAttributes(iface
);
621 return ISAXLocator_Release(&This
->ISAXLocator_iface
);
624 /*** IDispatch methods ***/
625 static HRESULT WINAPI
ivbsaxattributes_GetTypeInfoCount( IVBSAXAttributes
*iface
, UINT
* pctinfo
)
627 saxlocator
*This
= impl_from_IVBSAXAttributes( iface
);
629 TRACE("(%p)->(%p)\n", This
, pctinfo
);
636 static HRESULT WINAPI
ivbsaxattributes_GetTypeInfo(
637 IVBSAXAttributes
*iface
,
638 UINT iTInfo
, LCID lcid
, ITypeInfo
** ppTInfo
)
640 saxlocator
*This
= impl_from_IVBSAXAttributes( iface
);
643 TRACE("(%p)->(%u %u %p)\n", This
, iTInfo
, lcid
, ppTInfo
);
645 hr
= get_typeinfo(IVBSAXAttributes_tid
, ppTInfo
);
650 static HRESULT WINAPI
ivbsaxattributes_GetIDsOfNames(
651 IVBSAXAttributes
*iface
,
658 saxlocator
*This
= impl_from_IVBSAXAttributes( iface
);
662 TRACE("(%p)->(%s %p %u %u %p)\n", This
, debugstr_guid(riid
), rgszNames
, cNames
,
665 if(!rgszNames
|| cNames
== 0 || !rgDispId
)
668 hr
= get_typeinfo(IVBSAXAttributes_tid
, &typeinfo
);
671 hr
= ITypeInfo_GetIDsOfNames(typeinfo
, rgszNames
, cNames
, rgDispId
);
672 ITypeInfo_Release(typeinfo
);
678 static HRESULT WINAPI
ivbsaxattributes_Invoke(
679 IVBSAXAttributes
*iface
,
684 DISPPARAMS
* pDispParams
,
686 EXCEPINFO
* pExcepInfo
,
689 saxlocator
*This
= impl_from_IVBSAXAttributes( iface
);
693 TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This
, dispIdMember
, debugstr_guid(riid
),
694 lcid
, wFlags
, pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
696 hr
= get_typeinfo(IVBSAXAttributes_tid
, &typeinfo
);
699 hr
= ITypeInfo_Invoke(typeinfo
, &This
->IVBSAXAttributes_iface
, dispIdMember
, wFlags
,
700 pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
701 ITypeInfo_Release(typeinfo
);
707 /*** IVBSAXAttributes methods ***/
708 static HRESULT WINAPI
ivbsaxattributes_get_length(
709 IVBSAXAttributes
* iface
,
712 saxlocator
*This
= impl_from_IVBSAXAttributes( iface
);
713 return ISAXAttributes_getLength(&This
->ISAXAttributes_iface
, nLength
);
716 static HRESULT WINAPI
ivbsaxattributes_getURI(
717 IVBSAXAttributes
* iface
,
722 saxlocator
*This
= impl_from_IVBSAXAttributes( iface
);
723 return ISAXAttributes_getURI(&This
->ISAXAttributes_iface
, nIndex
, (const WCHAR
**)uri
, &len
);
726 static HRESULT WINAPI
ivbsaxattributes_getLocalName(
727 IVBSAXAttributes
* iface
,
732 saxlocator
*This
= impl_from_IVBSAXAttributes( iface
);
733 return ISAXAttributes_getLocalName(&This
->ISAXAttributes_iface
, nIndex
,
734 (const WCHAR
**)localName
, &len
);
737 static HRESULT WINAPI
ivbsaxattributes_getQName(
738 IVBSAXAttributes
* iface
,
743 saxlocator
*This
= impl_from_IVBSAXAttributes( iface
);
744 return ISAXAttributes_getQName(&This
->ISAXAttributes_iface
, nIndex
, (const WCHAR
**)QName
, &len
);
747 static HRESULT WINAPI
ivbsaxattributes_getIndexFromName(
748 IVBSAXAttributes
* iface
,
753 saxlocator
*This
= impl_from_IVBSAXAttributes( iface
);
754 return ISAXAttributes_getIndexFromName(&This
->ISAXAttributes_iface
, uri
, SysStringLen(uri
),
755 localName
, SysStringLen(localName
), index
);
758 static HRESULT WINAPI
ivbsaxattributes_getIndexFromQName(
759 IVBSAXAttributes
* iface
,
763 saxlocator
*This
= impl_from_IVBSAXAttributes( iface
);
764 return ISAXAttributes_getIndexFromQName(&This
->ISAXAttributes_iface
, QName
,
765 SysStringLen(QName
), index
);
768 static HRESULT WINAPI
ivbsaxattributes_getType(
769 IVBSAXAttributes
* iface
,
774 saxlocator
*This
= impl_from_IVBSAXAttributes( iface
);
775 return ISAXAttributes_getType(&This
->ISAXAttributes_iface
, nIndex
, (const WCHAR
**)type
, &len
);
778 static HRESULT WINAPI
ivbsaxattributes_getTypeFromName(
779 IVBSAXAttributes
* iface
,
785 saxlocator
*This
= impl_from_IVBSAXAttributes( iface
);
786 return ISAXAttributes_getTypeFromName(&This
->ISAXAttributes_iface
, uri
, SysStringLen(uri
),
787 localName
, SysStringLen(localName
), (const WCHAR
**)type
, &len
);
790 static HRESULT WINAPI
ivbsaxattributes_getTypeFromQName(
791 IVBSAXAttributes
* iface
,
796 saxlocator
*This
= impl_from_IVBSAXAttributes( iface
);
797 return ISAXAttributes_getTypeFromQName(&This
->ISAXAttributes_iface
, QName
, SysStringLen(QName
),
798 (const WCHAR
**)type
, &len
);
801 static HRESULT WINAPI
ivbsaxattributes_getValue(
802 IVBSAXAttributes
* iface
,
807 saxlocator
*This
= impl_from_IVBSAXAttributes( iface
);
808 return ISAXAttributes_getValue(&This
->ISAXAttributes_iface
, nIndex
, (const WCHAR
**)value
, &len
);
811 static HRESULT WINAPI
ivbsaxattributes_getValueFromName(
812 IVBSAXAttributes
* iface
,
818 saxlocator
*This
= impl_from_IVBSAXAttributes( iface
);
819 return ISAXAttributes_getValueFromName(&This
->ISAXAttributes_iface
, uri
, SysStringLen(uri
),
820 localName
, SysStringLen(localName
), (const WCHAR
**)value
, &len
);
823 static HRESULT WINAPI
ivbsaxattributes_getValueFromQName(
824 IVBSAXAttributes
* iface
,
829 saxlocator
*This
= impl_from_IVBSAXAttributes( iface
);
830 return ISAXAttributes_getValueFromQName(&This
->ISAXAttributes_iface
, QName
,
831 SysStringLen(QName
), (const WCHAR
**)value
, &len
);
834 static const struct IVBSAXAttributesVtbl ivbsaxattributes_vtbl
=
836 ivbsaxattributes_QueryInterface
,
837 ivbsaxattributes_AddRef
,
838 ivbsaxattributes_Release
,
839 ivbsaxattributes_GetTypeInfoCount
,
840 ivbsaxattributes_GetTypeInfo
,
841 ivbsaxattributes_GetIDsOfNames
,
842 ivbsaxattributes_Invoke
,
843 ivbsaxattributes_get_length
,
844 ivbsaxattributes_getURI
,
845 ivbsaxattributes_getLocalName
,
846 ivbsaxattributes_getQName
,
847 ivbsaxattributes_getIndexFromName
,
848 ivbsaxattributes_getIndexFromQName
,
849 ivbsaxattributes_getType
,
850 ivbsaxattributes_getTypeFromName
,
851 ivbsaxattributes_getTypeFromQName
,
852 ivbsaxattributes_getValue
,
853 ivbsaxattributes_getValueFromName
,
854 ivbsaxattributes_getValueFromQName
857 /*** ISAXAttributes interface ***/
858 /*** IUnknown methods ***/
859 static HRESULT WINAPI
isaxattributes_QueryInterface(
860 ISAXAttributes
* iface
,
864 saxlocator
*This
= impl_from_ISAXAttributes(iface
);
865 TRACE("%p %s %p\n", This
, debugstr_guid(riid
), ppvObject
);
866 return ISAXLocator_QueryInterface(&This
->ISAXLocator_iface
, riid
, ppvObject
);
869 static ULONG WINAPI
isaxattributes_AddRef(ISAXAttributes
* iface
)
871 saxlocator
*This
= impl_from_ISAXAttributes(iface
);
873 return ISAXLocator_AddRef(&This
->ISAXLocator_iface
);
876 static ULONG WINAPI
isaxattributes_Release(ISAXAttributes
* iface
)
878 saxlocator
*This
= impl_from_ISAXAttributes(iface
);
881 return ISAXLocator_Release(&This
->ISAXLocator_iface
);
884 /*** ISAXAttributes methods ***/
885 static HRESULT WINAPI
isaxattributes_getLength(
886 ISAXAttributes
* iface
,
889 saxlocator
*This
= impl_from_ISAXAttributes( iface
);
891 *length
= This
->nb_attributes
;
892 TRACE("Length set to %d\n", *length
);
896 static HRESULT WINAPI
isaxattributes_getURI(
897 ISAXAttributes
* iface
,
902 saxlocator
*This
= impl_from_ISAXAttributes( iface
);
903 TRACE("(%p)->(%d)\n", This
, index
);
905 if(index
>= This
->nb_attributes
|| index
< 0) return E_INVALIDARG
;
906 if(!url
|| !size
) return E_POINTER
;
908 *size
= SysStringLen(This
->attributes
[index
].szURI
);
909 *url
= This
->attributes
[index
].szURI
;
911 TRACE("(%s:%d)\n", debugstr_w(This
->attributes
[index
].szURI
), *size
);
916 static HRESULT WINAPI
isaxattributes_getLocalName(
917 ISAXAttributes
* iface
,
919 const WCHAR
**pLocalName
,
920 int *pLocalNameLength
)
922 saxlocator
*This
= impl_from_ISAXAttributes( iface
);
923 TRACE("(%p)->(%d)\n", This
, nIndex
);
925 if(nIndex
>=This
->nb_attributes
|| nIndex
<0) return E_INVALIDARG
;
926 if(!pLocalName
|| !pLocalNameLength
) return E_POINTER
;
928 *pLocalNameLength
= SysStringLen(This
->attributes
[nIndex
].szLocalname
);
929 *pLocalName
= This
->attributes
[nIndex
].szLocalname
;
934 static HRESULT WINAPI
isaxattributes_getQName(
935 ISAXAttributes
* iface
,
937 const WCHAR
**pQName
,
940 saxlocator
*This
= impl_from_ISAXAttributes( iface
);
941 TRACE("(%p)->(%d)\n", This
, nIndex
);
943 if(nIndex
>=This
->nb_attributes
|| nIndex
<0) return E_INVALIDARG
;
944 if(!pQName
|| !pQNameLength
) return E_POINTER
;
946 *pQNameLength
= SysStringLen(This
->attributes
[nIndex
].szQName
);
947 *pQName
= This
->attributes
[nIndex
].szQName
;
952 static HRESULT WINAPI
isaxattributes_getName(
953 ISAXAttributes
* iface
,
957 const WCHAR
**localName
,
962 saxlocator
*This
= impl_from_ISAXAttributes( iface
);
963 TRACE("(%p)->(%d)\n", This
, index
);
965 if(index
>=This
->nb_attributes
|| index
<0) return E_INVALIDARG
;
966 if(!uri
|| !pUriLength
|| !localName
|| !pLocalNameSize
967 || !QName
|| !pQNameLength
) return E_POINTER
;
969 *pUriLength
= SysStringLen(This
->attributes
[index
].szURI
);
970 *uri
= This
->attributes
[index
].szURI
;
971 *pLocalNameSize
= SysStringLen(This
->attributes
[index
].szLocalname
);
972 *localName
= This
->attributes
[index
].szLocalname
;
973 *pQNameLength
= SysStringLen(This
->attributes
[index
].szQName
);
974 *QName
= This
->attributes
[index
].szQName
;
976 TRACE("(%s, %s, %s)\n", debugstr_w(*uri
), debugstr_w(*localName
), debugstr_w(*QName
));
981 static HRESULT WINAPI
isaxattributes_getIndexFromName(
982 ISAXAttributes
* iface
,
985 const WCHAR
*pLocalName
,
989 saxlocator
*This
= impl_from_ISAXAttributes( iface
);
991 TRACE("(%p)->(%s, %d, %s, %d)\n", This
, debugstr_w(pUri
), cUriLength
,
992 debugstr_w(pLocalName
), cocalNameLength
);
994 if(!pUri
|| !pLocalName
|| !index
) return E_POINTER
;
996 for(i
=0; i
<This
->nb_attributes
; i
++)
998 if(cUriLength
!=SysStringLen(This
->attributes
[i
].szURI
)
999 || cocalNameLength
!=SysStringLen(This
->attributes
[i
].szLocalname
))
1001 if(cUriLength
&& memcmp(pUri
, This
->attributes
[i
].szURI
,
1002 sizeof(WCHAR
)*cUriLength
))
1004 if(cocalNameLength
&& memcmp(pLocalName
, This
->attributes
[i
].szLocalname
,
1005 sizeof(WCHAR
)*cocalNameLength
))
1012 return E_INVALIDARG
;
1015 static HRESULT WINAPI
isaxattributes_getIndexFromQName(
1016 ISAXAttributes
* iface
,
1017 const WCHAR
*pQName
,
1021 saxlocator
*This
= impl_from_ISAXAttributes( iface
);
1023 TRACE("(%p)->(%s, %d)\n", This
, debugstr_w(pQName
), nQNameLength
);
1025 if(!pQName
|| !index
) return E_POINTER
;
1026 if(!nQNameLength
) return E_INVALIDARG
;
1028 for(i
=0; i
<This
->nb_attributes
; i
++)
1030 if(nQNameLength
!=SysStringLen(This
->attributes
[i
].szQName
)) continue;
1031 if(memcmp(pQName
, This
->attributes
[i
].szQName
, sizeof(WCHAR
)*nQNameLength
)) continue;
1037 return E_INVALIDARG
;
1040 static HRESULT WINAPI
isaxattributes_getType(
1041 ISAXAttributes
* iface
,
1043 const WCHAR
**pType
,
1046 saxlocator
*This
= impl_from_ISAXAttributes( iface
);
1048 FIXME("(%p)->(%d) stub\n", This
, nIndex
);
1052 static HRESULT WINAPI
isaxattributes_getTypeFromName(
1053 ISAXAttributes
* iface
,
1056 const WCHAR
*pLocalName
,
1058 const WCHAR
**pType
,
1061 saxlocator
*This
= impl_from_ISAXAttributes( iface
);
1063 FIXME("(%p)->(%s, %d, %s, %d) stub\n", This
, debugstr_w(pUri
), nUri
,
1064 debugstr_w(pLocalName
), nLocalName
);
1068 static HRESULT WINAPI
isaxattributes_getTypeFromQName(
1069 ISAXAttributes
* iface
,
1070 const WCHAR
*pQName
,
1072 const WCHAR
**pType
,
1075 saxlocator
*This
= impl_from_ISAXAttributes( iface
);
1077 FIXME("(%p)->(%s, %d) stub\n", This
, debugstr_w(pQName
), nQName
);
1081 static HRESULT WINAPI
isaxattributes_getValue(
1082 ISAXAttributes
* iface
,
1084 const WCHAR
**value
,
1087 saxlocator
*This
= impl_from_ISAXAttributes( iface
);
1088 TRACE("(%p)->(%d)\n", This
, index
);
1090 if(index
>=This
->nb_attributes
|| index
<0) return E_INVALIDARG
;
1091 if(!value
|| !nValue
) return E_POINTER
;
1093 *nValue
= SysStringLen(This
->attributes
[index
].szValue
);
1094 *value
= This
->attributes
[index
].szValue
;
1096 TRACE("(%s:%d)\n", debugstr_w(*value
), *nValue
);
1101 static HRESULT WINAPI
isaxattributes_getValueFromName(
1102 ISAXAttributes
* iface
,
1105 const WCHAR
*pLocalName
,
1107 const WCHAR
**pValue
,
1112 saxlocator
*This
= impl_from_ISAXAttributes( iface
);
1113 TRACE("(%p)->(%s, %d, %s, %d)\n", This
, debugstr_w(pUri
), nUri
,
1114 debugstr_w(pLocalName
), nLocalName
);
1116 hr
= ISAXAttributes_getIndexFromName(iface
,
1117 pUri
, nUri
, pLocalName
, nLocalName
, &index
);
1118 if(hr
==S_OK
) hr
= ISAXAttributes_getValue(iface
, index
, pValue
, nValue
);
1123 static HRESULT WINAPI
isaxattributes_getValueFromQName(
1124 ISAXAttributes
* iface
,
1125 const WCHAR
*pQName
,
1127 const WCHAR
**pValue
,
1132 saxlocator
*This
= impl_from_ISAXAttributes( iface
);
1133 TRACE("(%p)->(%s, %d)\n", This
, debugstr_w(pQName
), nQName
);
1135 hr
= ISAXAttributes_getIndexFromQName(iface
, pQName
, nQName
, &index
);
1136 if(hr
==S_OK
) hr
= ISAXAttributes_getValue(iface
, index
, pValue
, nValue
);
1141 static const struct ISAXAttributesVtbl isaxattributes_vtbl
=
1143 isaxattributes_QueryInterface
,
1144 isaxattributes_AddRef
,
1145 isaxattributes_Release
,
1146 isaxattributes_getLength
,
1147 isaxattributes_getURI
,
1148 isaxattributes_getLocalName
,
1149 isaxattributes_getQName
,
1150 isaxattributes_getName
,
1151 isaxattributes_getIndexFromName
,
1152 isaxattributes_getIndexFromQName
,
1153 isaxattributes_getType
,
1154 isaxattributes_getTypeFromName
,
1155 isaxattributes_getTypeFromQName
,
1156 isaxattributes_getValue
,
1157 isaxattributes_getValueFromName
,
1158 isaxattributes_getValueFromQName
1161 static HRESULT
SAXAttributes_populate(saxlocator
*locator
,
1162 int nb_namespaces
, const xmlChar
**xmlNamespaces
,
1163 int nb_attributes
, const xmlChar
**xmlAttributes
)
1165 static const xmlChar xmlns
[] = "xmlns";
1166 static const WCHAR xmlnsW
[] = { 'x','m','l','n','s',0 };
1168 struct _attributes
*attrs
;
1171 /* skip namespace definitions */
1172 if ((locator
->saxreader
->features
& NamespacePrefixes
) == 0)
1175 locator
->nb_attributes
= nb_namespaces
+ nb_attributes
;
1176 if(locator
->nb_attributes
> locator
->attributesSize
)
1178 attrs
= heap_realloc(locator
->attributes
, sizeof(struct _attributes
)*locator
->nb_attributes
*2);
1181 locator
->nb_attributes
= 0;
1182 return E_OUTOFMEMORY
;
1184 locator
->attributes
= attrs
;
1188 attrs
= locator
->attributes
;
1191 for (i
= 0; i
< nb_namespaces
; i
++)
1193 attrs
[nb_attributes
+i
].szLocalname
= SysAllocStringLen(NULL
, 0);
1194 attrs
[nb_attributes
+i
].szURI
= locator
->namespaceUri
;
1195 attrs
[nb_attributes
+i
].szValue
= bstr_from_xmlChar(xmlNamespaces
[2*i
+1]);
1196 if(!xmlNamespaces
[2*i
])
1197 attrs
[nb_attributes
+i
].szQName
= SysAllocString(xmlnsW
);
1199 attrs
[nb_attributes
+i
].szQName
= QName_from_xmlChar(xmlns
, xmlNamespaces
[2*i
]);
1202 for (i
= 0; i
< nb_attributes
; i
++)
1204 static const xmlChar xmlA
[] = "xml";
1206 if (xmlStrEqual(xmlAttributes
[i
*5+1], xmlA
))
1207 attrs
[i
].szURI
= bstr_from_xmlChar(xmlAttributes
[i
*5+2]);
1209 attrs
[i
].szURI
= find_element_uri(locator
, xmlAttributes
[i
*5+2]);
1211 attrs
[i
].szLocalname
= bstr_from_xmlChar(xmlAttributes
[i
*5]);
1212 attrs
[i
].szValue
= bstr_from_xmlCharN(xmlAttributes
[i
*5+3],
1213 xmlAttributes
[i
*5+4]-xmlAttributes
[i
*5+3]);
1214 attrs
[i
].szQName
= QName_from_xmlChar(xmlAttributes
[i
*5+1],
1215 xmlAttributes
[i
*5]);
1221 /*** LibXML callbacks ***/
1222 static void libxmlStartDocument(void *ctx
)
1224 saxlocator
*This
= ctx
;
1227 if (This
->saxreader
->version
>= MSXML4
)
1229 const xmlChar
*p
= This
->pParserCtxt
->input
->cur
-1;
1230 update_position(This
, FALSE
);
1231 while(p
>This
->pParserCtxt
->input
->base
&& *p
!='>')
1233 if(*p
=='\n' || (*p
=='\r' && *(p
+1)!='\n'))
1238 for(; p
>=This
->pParserCtxt
->input
->base
&& *p
!='\n' && *p
!='\r'; p
--)
1242 if(has_content_handler(This
))
1244 if(This
->vbInterface
)
1245 hr
= IVBSAXContentHandler_startDocument(This
->saxreader
->vbcontentHandler
);
1247 hr
= ISAXContentHandler_startDocument(This
->saxreader
->contentHandler
);
1249 if (sax_callback_failed(This
, hr
))
1250 format_error_message_from_id(This
, hr
);
1254 static void libxmlEndDocument(void *ctx
)
1256 saxlocator
*This
= ctx
;
1259 if (This
->saxreader
->version
>= MSXML4
) {
1260 update_position(This
, FALSE
);
1261 if(This
->column
> 1)
1269 if(This
->ret
!= S_OK
) return;
1271 if(has_content_handler(This
))
1273 if(This
->vbInterface
)
1274 hr
= IVBSAXContentHandler_endDocument(This
->saxreader
->vbcontentHandler
);
1276 hr
= ISAXContentHandler_endDocument(This
->saxreader
->contentHandler
);
1278 if (sax_callback_failed(This
, hr
))
1279 format_error_message_from_id(This
, hr
);
1283 static void libxmlStartElementNS(
1285 const xmlChar
*localname
,
1286 const xmlChar
*prefix
,
1289 const xmlChar
**namespaces
,
1292 const xmlChar
**attributes
)
1294 saxlocator
*This
= ctx
;
1295 element_entry
*element
;
1299 update_position(This
, TRUE
);
1300 if(*(This
->pParserCtxt
->input
->cur
) == '/')
1302 if(This
->saxreader
->version
< MSXML4
)
1305 element
= alloc_element_entry(localname
, prefix
, nb_namespaces
, namespaces
);
1306 push_element_ns(This
, element
);
1308 if (is_namespaces_enabled(This
->saxreader
))
1312 for (i
= 0; i
< nb_namespaces
&& has_content_handler(This
); i
++)
1314 if (This
->vbInterface
)
1315 hr
= IVBSAXContentHandler_startPrefixMapping(
1316 This
->saxreader
->vbcontentHandler
,
1317 &element
->ns
[i
].prefix
,
1318 &element
->ns
[i
].uri
);
1320 hr
= ISAXContentHandler_startPrefixMapping(
1321 This
->saxreader
->contentHandler
,
1322 element
->ns
[i
].prefix
,
1323 SysStringLen(element
->ns
[i
].prefix
),
1325 SysStringLen(element
->ns
[i
].uri
));
1327 if (sax_callback_failed(This
, hr
))
1329 format_error_message_from_id(This
, hr
);
1335 uri
= find_element_uri(This
, URI
);
1336 hr
= SAXAttributes_populate(This
, nb_namespaces
, namespaces
, nb_attributes
, attributes
);
1337 if (hr
== S_OK
&& has_content_handler(This
))
1341 if (is_namespaces_enabled(This
->saxreader
))
1342 local
= element
->local
;
1346 if (This
->vbInterface
)
1347 hr
= IVBSAXContentHandler_startElement(This
->saxreader
->vbcontentHandler
,
1348 &uri
, &local
, &element
->qname
, &This
->IVBSAXAttributes_iface
);
1350 hr
= ISAXContentHandler_startElement(This
->saxreader
->contentHandler
,
1351 uri
, SysStringLen(uri
),
1352 local
, SysStringLen(local
),
1353 element
->qname
, SysStringLen(element
->qname
),
1354 &This
->ISAXAttributes_iface
);
1356 if (sax_callback_failed(This
, hr
))
1357 format_error_message_from_id(This
, hr
);
1361 static void libxmlEndElementNS(
1363 const xmlChar
*localname
,
1364 const xmlChar
*prefix
,
1367 saxlocator
*This
= ctx
;
1368 element_entry
*element
;
1373 update_position(This
, FALSE
);
1374 p
= This
->pParserCtxt
->input
->cur
;
1376 if (This
->saxreader
->version
>= MSXML4
)
1379 while(p
>This
->pParserCtxt
->input
->base
&& *p
!='>')
1381 if(*p
=='\n' || (*p
=='\r' && *(p
+1)!='\n'))
1386 else if(*(p
-1)!='>' || *(p
-2)!='/')
1389 while(p
-2>=This
->pParserCtxt
->input
->base
1390 && *(p
-2)!='<' && *(p
-1)!='/')
1392 if(*p
=='\n' || (*p
=='\r' && *(p
+1)!='\n'))
1398 for(; p
>=This
->pParserCtxt
->input
->base
&& *p
!='\n' && *p
!='\r'; p
--)
1401 uri
= find_element_uri(This
, URI
);
1402 element
= pop_element_ns(This
);
1404 if (!has_content_handler(This
))
1406 This
->nb_attributes
= 0;
1407 free_element_entry(element
);
1411 if (is_namespaces_enabled(This
->saxreader
))
1412 local
= element
->local
;
1416 if (This
->vbInterface
)
1417 hr
= IVBSAXContentHandler_endElement(
1418 This
->saxreader
->vbcontentHandler
,
1419 &uri
, &local
, &element
->qname
);
1421 hr
= ISAXContentHandler_endElement(
1422 This
->saxreader
->contentHandler
,
1423 uri
, SysStringLen(uri
),
1424 local
, SysStringLen(local
),
1425 element
->qname
, SysStringLen(element
->qname
));
1427 This
->nb_attributes
= 0;
1429 if (sax_callback_failed(This
, hr
))
1431 format_error_message_from_id(This
, hr
);
1432 free_element_entry(element
);
1436 if (is_namespaces_enabled(This
->saxreader
))
1439 while (iterate_endprefix_index(This
, element
, &i
) && has_content_handler(This
))
1441 if (This
->vbInterface
)
1442 hr
= IVBSAXContentHandler_endPrefixMapping(
1443 This
->saxreader
->vbcontentHandler
, &element
->ns
[i
].prefix
);
1445 hr
= ISAXContentHandler_endPrefixMapping(
1446 This
->saxreader
->contentHandler
,
1447 element
->ns
[i
].prefix
, SysStringLen(element
->ns
[i
].prefix
));
1449 if (sax_callback_failed(This
, hr
)) break;
1452 if (sax_callback_failed(This
, hr
))
1453 format_error_message_from_id(This
, hr
);
1456 free_element_entry(element
);
1459 static void libxmlCharacters(
1464 saxlocator
*This
= ctx
;
1468 BOOL lastEvent
= FALSE
;
1470 if(!(has_content_handler(This
))) return;
1472 update_position(This
, FALSE
);
1473 cur
= (xmlChar
*)This
->pParserCtxt
->input
->cur
;
1474 while(cur
>=This
->pParserCtxt
->input
->base
&& *cur
!='>')
1476 if(*cur
=='\n' || (*cur
=='\r' && *(cur
+1)!='\n'))
1481 for(; cur
>=This
->pParserCtxt
->input
->base
&& *cur
!='\n' && *cur
!='\r'; cur
--)
1485 if(*(ch
-1)=='\r') cur
--;
1490 while(end
-ch
<len
&& *end
!='\r') end
++;
1501 if (This
->saxreader
->version
>= MSXML4
)
1505 for(p
=cur
; p
!=end
; p
++)
1522 Chars
= pooled_bstr_from_xmlCharN(&This
->saxreader
->pool
, cur
, end
-cur
);
1523 if(This
->vbInterface
)
1524 hr
= IVBSAXContentHandler_characters(
1525 This
->saxreader
->vbcontentHandler
, &Chars
);
1527 hr
= ISAXContentHandler_characters(
1528 This
->saxreader
->contentHandler
,
1529 Chars
, SysStringLen(Chars
));
1531 if (sax_callback_failed(This
, hr
))
1533 format_error_message_from_id(This
, hr
);
1537 if (This
->saxreader
->version
< MSXML4
)
1538 This
->column
+= end
-cur
;
1551 if(end
-ch
== len
) break;
1555 static void libxmlSetDocumentLocator(
1557 xmlSAXLocatorPtr loc
)
1559 saxlocator
*This
= ctx
;
1562 if(has_content_handler(This
))
1564 if(This
->vbInterface
)
1565 hr
= IVBSAXContentHandler_putref_documentLocator(This
->saxreader
->vbcontentHandler
,
1566 &This
->IVBSAXLocator_iface
);
1568 hr
= ISAXContentHandler_putDocumentLocator(This
->saxreader
->contentHandler
,
1569 &This
->ISAXLocator_iface
);
1573 format_error_message_from_id(This
, hr
);
1576 static void libxmlComment(void *ctx
, const xmlChar
*value
)
1578 saxlocator
*This
= ctx
;
1581 const xmlChar
*p
= This
->pParserCtxt
->input
->cur
;
1583 update_position(This
, FALSE
);
1584 while(p
-4>=This
->pParserCtxt
->input
->base
1585 && memcmp(p
-4, "<!--", sizeof(char[4])))
1587 if(*p
=='\n' || (*p
=='\r' && *(p
+1)!='\n'))
1593 for(; p
>=This
->pParserCtxt
->input
->base
&& *p
!='\n' && *p
!='\r'; p
--)
1596 if (!has_lexical_handler(This
)) return;
1598 bValue
= pooled_bstr_from_xmlChar(&This
->saxreader
->pool
, value
);
1600 if(This
->vbInterface
)
1601 hr
= IVBSAXLexicalHandler_comment(
1602 This
->saxreader
->vblexicalHandler
, &bValue
);
1604 hr
= ISAXLexicalHandler_comment(
1605 This
->saxreader
->lexicalHandler
,
1606 bValue
, SysStringLen(bValue
));
1609 format_error_message_from_id(This
, hr
);
1612 static void libxmlFatalError(void *ctx
, const char *msg
, ...)
1614 saxlocator
*This
= ctx
;
1620 if(This
->ret
!= S_OK
) {
1621 xmlStopParser(This
->pParserCtxt
);
1625 va_start(args
, msg
);
1626 vsprintf(message
, msg
, args
);
1629 len
= MultiByteToWideChar(CP_UNIXCP
, 0, message
, -1, NULL
, 0);
1630 error
= heap_alloc(sizeof(WCHAR
)*len
);
1633 MultiByteToWideChar(CP_UNIXCP
, 0, message
, -1, error
, len
);
1634 TRACE("fatal error for %p: %s\n", This
, debugstr_w(error
));
1637 if(!has_error_handler(This
))
1639 xmlStopParser(This
->pParserCtxt
);
1645 FIXME("Error handling is not compatible.\n");
1647 if(This
->vbInterface
)
1649 BSTR bstrError
= SysAllocString(error
);
1650 IVBSAXErrorHandler_fatalError(This
->saxreader
->vberrorHandler
, &This
->IVBSAXLocator_iface
,
1651 &bstrError
, E_FAIL
);
1652 SysFreeString(bstrError
);
1655 ISAXErrorHandler_fatalError(This
->saxreader
->errorHandler
, &This
->ISAXLocator_iface
,
1660 xmlStopParser(This
->pParserCtxt
);
1664 static void libxmlCDataBlock(void *ctx
, const xmlChar
*value
, int len
)
1666 saxlocator
*This
= ctx
;
1668 xmlChar
*beg
= (xmlChar
*)This
->pParserCtxt
->input
->cur
-len
;
1672 BOOL lastEvent
= FALSE
, change
;
1674 update_position(This
, FALSE
);
1675 while(beg
-9>=This
->pParserCtxt
->input
->base
1676 && memcmp(beg
-9, "<![CDATA[", sizeof(char[9])))
1678 if(*beg
=='\n' || (*beg
=='\r' && *(beg
+1)!='\n'))
1683 for(; beg
>=This
->pParserCtxt
->input
->base
&& *beg
!='\n' && *beg
!='\r'; beg
--)
1686 if (has_lexical_handler(This
))
1688 if (This
->vbInterface
)
1689 hr
= IVBSAXLexicalHandler_startCDATA(This
->saxreader
->vblexicalHandler
);
1691 hr
= ISAXLexicalHandler_startCDATA(This
->saxreader
->lexicalHandler
);
1696 format_error_message_from_id(This
, hr
);
1700 realLen
= This
->pParserCtxt
->input
->cur
-beg
-3;
1706 while(end
-beg
<realLen
&& *end
!='\r') end
++;
1707 if(end
-beg
==realLen
)
1712 else if(end
-beg
==realLen
-1 && *end
=='\r' && *(end
+1)=='\n')
1715 if(*end
== '\r') change
= TRUE
;
1716 else change
= FALSE
;
1718 if(change
) *end
= '\n';
1720 if(has_content_handler(This
))
1722 Chars
= pooled_bstr_from_xmlCharN(&This
->saxreader
->pool
, cur
, end
-cur
+1);
1723 if(This
->vbInterface
)
1724 hr
= IVBSAXContentHandler_characters(
1725 This
->saxreader
->vbcontentHandler
, &Chars
);
1727 hr
= ISAXContentHandler_characters(
1728 This
->saxreader
->contentHandler
,
1729 Chars
, SysStringLen(Chars
));
1732 if(change
) *end
= '\r';
1737 This
->column
+= end
-cur
+2;
1742 if (has_lexical_handler(This
))
1744 if (This
->vbInterface
)
1745 hr
= IVBSAXLexicalHandler_endCDATA(This
->saxreader
->vblexicalHandler
);
1747 hr
= ISAXLexicalHandler_endCDATA(This
->saxreader
->lexicalHandler
);
1751 format_error_message_from_id(This
, hr
);
1753 This
->column
+= 4+end
-cur
;
1756 /*** IVBSAXLocator interface ***/
1757 /*** IUnknown methods ***/
1758 static HRESULT WINAPI
ivbsaxlocator_QueryInterface(IVBSAXLocator
* iface
, REFIID riid
, void **ppvObject
)
1760 saxlocator
*This
= impl_from_IVBSAXLocator( iface
);
1762 TRACE("%p %s %p\n", This
, debugstr_guid( riid
), ppvObject
);
1766 if ( IsEqualGUID( riid
, &IID_IUnknown
) ||
1767 IsEqualGUID( riid
, &IID_IDispatch
) ||
1768 IsEqualGUID( riid
, &IID_IVBSAXLocator
))
1772 else if ( IsEqualGUID( riid
, &IID_IVBSAXAttributes
))
1774 *ppvObject
= &This
->IVBSAXAttributes_iface
;
1778 FIXME("interface %s not implemented\n", debugstr_guid(riid
));
1779 return E_NOINTERFACE
;
1782 IVBSAXLocator_AddRef( iface
);
1787 static ULONG WINAPI
ivbsaxlocator_AddRef(IVBSAXLocator
* iface
)
1789 saxlocator
*This
= impl_from_IVBSAXLocator( iface
);
1790 TRACE("%p\n", This
);
1791 return InterlockedIncrement( &This
->ref
);
1794 static ULONG WINAPI
ivbsaxlocator_Release(
1795 IVBSAXLocator
* iface
)
1797 saxlocator
*This
= impl_from_IVBSAXLocator( iface
);
1798 return ISAXLocator_Release((ISAXLocator
*)&This
->IVBSAXLocator_iface
);
1801 /*** IDispatch methods ***/
1802 static HRESULT WINAPI
ivbsaxlocator_GetTypeInfoCount( IVBSAXLocator
*iface
, UINT
* pctinfo
)
1804 saxlocator
*This
= impl_from_IVBSAXLocator( iface
);
1806 TRACE("(%p)->(%p)\n", This
, pctinfo
);
1813 static HRESULT WINAPI
ivbsaxlocator_GetTypeInfo(
1814 IVBSAXLocator
*iface
,
1815 UINT iTInfo
, LCID lcid
, ITypeInfo
** ppTInfo
)
1817 saxlocator
*This
= impl_from_IVBSAXLocator( iface
);
1820 TRACE("(%p)->(%u %u %p)\n", This
, iTInfo
, lcid
, ppTInfo
);
1822 hr
= get_typeinfo(IVBSAXLocator_tid
, ppTInfo
);
1827 static HRESULT WINAPI
ivbsaxlocator_GetIDsOfNames(
1828 IVBSAXLocator
*iface
,
1830 LPOLESTR
* rgszNames
,
1835 saxlocator
*This
= impl_from_IVBSAXLocator( iface
);
1836 ITypeInfo
*typeinfo
;
1839 TRACE("(%p)->(%s %p %u %u %p)\n", This
, debugstr_guid(riid
), rgszNames
, cNames
,
1842 if(!rgszNames
|| cNames
== 0 || !rgDispId
)
1843 return E_INVALIDARG
;
1845 hr
= get_typeinfo(IVBSAXLocator_tid
, &typeinfo
);
1848 hr
= ITypeInfo_GetIDsOfNames(typeinfo
, rgszNames
, cNames
, rgDispId
);
1849 ITypeInfo_Release(typeinfo
);
1855 static HRESULT WINAPI
ivbsaxlocator_Invoke(
1856 IVBSAXLocator
*iface
,
1857 DISPID dispIdMember
,
1861 DISPPARAMS
* pDispParams
,
1862 VARIANT
* pVarResult
,
1863 EXCEPINFO
* pExcepInfo
,
1866 saxlocator
*This
= impl_from_IVBSAXLocator( iface
);
1867 ITypeInfo
*typeinfo
;
1870 TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This
, dispIdMember
, debugstr_guid(riid
),
1871 lcid
, wFlags
, pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
1873 hr
= get_typeinfo(IVBSAXLocator_tid
, &typeinfo
);
1876 hr
= ITypeInfo_Invoke(typeinfo
, &This
->IVBSAXLocator_iface
, dispIdMember
, wFlags
,
1877 pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
1878 ITypeInfo_Release(typeinfo
);
1884 /*** IVBSAXLocator methods ***/
1885 static HRESULT WINAPI
ivbsaxlocator_get_columnNumber(
1886 IVBSAXLocator
* iface
,
1889 saxlocator
*This
= impl_from_IVBSAXLocator( iface
);
1890 return ISAXLocator_getColumnNumber((ISAXLocator
*)&This
->IVBSAXLocator_iface
, pnColumn
);
1893 static HRESULT WINAPI
ivbsaxlocator_get_lineNumber(
1894 IVBSAXLocator
* iface
,
1897 saxlocator
*This
= impl_from_IVBSAXLocator( iface
);
1898 return ISAXLocator_getLineNumber((ISAXLocator
*)&This
->IVBSAXLocator_iface
, pnLine
);
1901 static HRESULT WINAPI
ivbsaxlocator_get_publicId(
1902 IVBSAXLocator
* iface
,
1905 saxlocator
*This
= impl_from_IVBSAXLocator( iface
);
1906 return ISAXLocator_getPublicId((ISAXLocator
*)&This
->IVBSAXLocator_iface
,
1907 (const WCHAR
**)publicId
);
1910 static HRESULT WINAPI
ivbsaxlocator_get_systemId(
1911 IVBSAXLocator
* iface
,
1914 saxlocator
*This
= impl_from_IVBSAXLocator( iface
);
1915 return ISAXLocator_getSystemId((ISAXLocator
*)&This
->IVBSAXLocator_iface
,
1916 (const WCHAR
**)systemId
);
1919 static const struct IVBSAXLocatorVtbl VBSAXLocatorVtbl
=
1921 ivbsaxlocator_QueryInterface
,
1922 ivbsaxlocator_AddRef
,
1923 ivbsaxlocator_Release
,
1924 ivbsaxlocator_GetTypeInfoCount
,
1925 ivbsaxlocator_GetTypeInfo
,
1926 ivbsaxlocator_GetIDsOfNames
,
1927 ivbsaxlocator_Invoke
,
1928 ivbsaxlocator_get_columnNumber
,
1929 ivbsaxlocator_get_lineNumber
,
1930 ivbsaxlocator_get_publicId
,
1931 ivbsaxlocator_get_systemId
1934 /*** ISAXLocator interface ***/
1935 /*** IUnknown methods ***/
1936 static HRESULT WINAPI
isaxlocator_QueryInterface(ISAXLocator
* iface
, REFIID riid
, void **ppvObject
)
1938 saxlocator
*This
= impl_from_ISAXLocator( iface
);
1940 TRACE("%p %s %p\n", This
, debugstr_guid( riid
), ppvObject
);
1944 if ( IsEqualGUID( riid
, &IID_IUnknown
) ||
1945 IsEqualGUID( riid
, &IID_ISAXLocator
))
1949 else if ( IsEqualGUID( riid
, &IID_ISAXAttributes
))
1951 *ppvObject
= &This
->ISAXAttributes_iface
;
1955 WARN("interface %s not implemented\n", debugstr_guid(riid
));
1956 return E_NOINTERFACE
;
1959 ISAXLocator_AddRef( iface
);
1964 static ULONG WINAPI
isaxlocator_AddRef(ISAXLocator
* iface
)
1966 saxlocator
*This
= impl_from_ISAXLocator( iface
);
1967 ULONG ref
= InterlockedIncrement( &This
->ref
);
1968 TRACE("(%p)->(%d)\n", This
, ref
);
1972 static ULONG WINAPI
isaxlocator_Release(
1975 saxlocator
*This
= impl_from_ISAXLocator( iface
);
1976 LONG ref
= InterlockedDecrement( &This
->ref
);
1978 TRACE("(%p)->(%d)\n", This
, ref
);
1982 element_entry
*element
, *element2
;
1985 SysFreeString(This
->publicId
);
1986 SysFreeString(This
->systemId
);
1987 SysFreeString(This
->namespaceUri
);
1989 for(index
=0; index
<This
->nb_attributes
; index
++)
1991 SysFreeString(This
->attributes
[index
].szLocalname
);
1992 SysFreeString(This
->attributes
[index
].szValue
);
1993 SysFreeString(This
->attributes
[index
].szQName
);
1995 heap_free(This
->attributes
);
1998 LIST_FOR_EACH_ENTRY_SAFE(element
, element2
, &This
->elements
, element_entry
, entry
)
2000 list_remove(&element
->entry
);
2001 free_element_entry(element
);
2004 ISAXXMLReader_Release(&This
->saxreader
->ISAXXMLReader_iface
);
2011 /*** ISAXLocator methods ***/
2012 static HRESULT WINAPI
isaxlocator_getColumnNumber(
2016 saxlocator
*This
= impl_from_ISAXLocator( iface
);
2018 *pnColumn
= This
->column
;
2022 static HRESULT WINAPI
isaxlocator_getLineNumber(
2026 saxlocator
*This
= impl_from_ISAXLocator( iface
);
2028 *pnLine
= This
->line
;
2032 static HRESULT WINAPI
isaxlocator_getPublicId(
2034 const WCHAR
** ppwchPublicId
)
2037 saxlocator
*This
= impl_from_ISAXLocator( iface
);
2039 SysFreeString(This
->publicId
);
2041 publicId
= bstr_from_xmlChar(xmlSAX2GetPublicId(This
->pParserCtxt
));
2042 if(SysStringLen(publicId
))
2043 This
->publicId
= (WCHAR
*)&publicId
;
2046 SysFreeString(publicId
);
2047 This
->publicId
= NULL
;
2050 *ppwchPublicId
= This
->publicId
;
2054 static HRESULT WINAPI
isaxlocator_getSystemId(
2056 const WCHAR
** ppwchSystemId
)
2059 saxlocator
*This
= impl_from_ISAXLocator( iface
);
2061 SysFreeString(This
->systemId
);
2063 systemId
= bstr_from_xmlChar(xmlSAX2GetSystemId(This
->pParserCtxt
));
2064 if(SysStringLen(systemId
))
2065 This
->systemId
= (WCHAR
*)&systemId
;
2068 SysFreeString(systemId
);
2069 This
->systemId
= NULL
;
2072 *ppwchSystemId
= This
->systemId
;
2076 static const struct ISAXLocatorVtbl SAXLocatorVtbl
=
2078 isaxlocator_QueryInterface
,
2080 isaxlocator_Release
,
2081 isaxlocator_getColumnNumber
,
2082 isaxlocator_getLineNumber
,
2083 isaxlocator_getPublicId
,
2084 isaxlocator_getSystemId
2087 static HRESULT
SAXLocator_create(saxreader
*reader
, saxlocator
**ppsaxlocator
, BOOL vbInterface
)
2089 static const WCHAR w3xmlns
[] = { 'h','t','t','p',':','/','/', 'w','w','w','.','w','3','.',
2090 'o','r','g','/','2','0','0','0','/','x','m','l','n','s','/',0 };
2092 saxlocator
*locator
;
2094 locator
= heap_alloc( sizeof (*locator
) );
2096 return E_OUTOFMEMORY
;
2098 locator
->IVBSAXLocator_iface
.lpVtbl
= &VBSAXLocatorVtbl
;
2099 locator
->ISAXLocator_iface
.lpVtbl
= &SAXLocatorVtbl
;
2100 locator
->IVBSAXAttributes_iface
.lpVtbl
= &ivbsaxattributes_vtbl
;
2101 locator
->ISAXAttributes_iface
.lpVtbl
= &isaxattributes_vtbl
;
2103 locator
->vbInterface
= vbInterface
;
2105 locator
->saxreader
= reader
;
2106 ISAXXMLReader_AddRef(&reader
->ISAXXMLReader_iface
);
2108 locator
->pParserCtxt
= NULL
;
2109 locator
->publicId
= NULL
;
2110 locator
->systemId
= NULL
;
2111 locator
->line
= reader
->version
< MSXML4
? 0 : 1;
2112 locator
->column
= 0;
2113 locator
->ret
= S_OK
;
2114 if (locator
->saxreader
->version
>= MSXML6
)
2115 locator
->namespaceUri
= SysAllocString(w3xmlns
);
2117 locator
->namespaceUri
= SysAllocStringLen(NULL
, 0);
2118 if(!locator
->namespaceUri
)
2120 ISAXXMLReader_Release(&reader
->ISAXXMLReader_iface
);
2122 return E_OUTOFMEMORY
;
2125 locator
->attributesSize
= 8;
2126 locator
->nb_attributes
= 0;
2127 locator
->attributes
= heap_alloc(sizeof(struct _attributes
)*locator
->attributesSize
);
2128 if(!locator
->attributes
)
2130 ISAXXMLReader_Release(&reader
->ISAXXMLReader_iface
);
2131 SysFreeString(locator
->namespaceUri
);
2133 return E_OUTOFMEMORY
;
2136 list_init(&locator
->elements
);
2138 *ppsaxlocator
= locator
;
2140 TRACE("returning %p\n", *ppsaxlocator
);
2145 /*** SAXXMLReader internal functions ***/
2146 static HRESULT
internal_parseBuffer(saxreader
*This
, const char *buffer
, int size
, BOOL vbInterface
)
2148 xmlCharEncoding encoding
= XML_CHAR_ENCODING_NONE
;
2149 xmlChar
*enc_name
= NULL
;
2150 saxlocator
*locator
;
2153 hr
= SAXLocator_create(This
, &locator
, vbInterface
);
2159 const unsigned char *buff
= (unsigned char*)buffer
;
2161 encoding
= xmlDetectCharEncoding((xmlChar
*)buffer
, 4);
2162 enc_name
= (xmlChar
*)xmlGetCharEncodingName(encoding
);
2163 TRACE("detected encoding: %s\n", enc_name
);
2164 /* skip BOM, parser won't switch encodings and so won't skip it on its own */
2165 if ((encoding
== XML_CHAR_ENCODING_UTF8
) &&
2166 buff
[0] == 0xEF && buff
[1] == 0xBB && buff
[2] == 0xBF)
2173 /* if libxml2 detection failed try to guess */
2174 if (encoding
== XML_CHAR_ENCODING_NONE
)
2176 const WCHAR
*ptr
= (WCHAR
*)buffer
;
2177 /* xml declaration with possibly specfied encoding will be still handled by parser */
2178 if ((size
>= 2) && *ptr
== '<' && ptr
[1] != '?')
2180 enc_name
= (xmlChar
*)xmlGetCharEncodingName(XML_CHAR_ENCODING_UTF16LE
);
2181 encoding
= XML_CHAR_ENCODING_UTF16LE
;
2184 else if (encoding
== XML_CHAR_ENCODING_UTF8
)
2185 enc_name
= (xmlChar
*)xmlGetCharEncodingName(encoding
);
2189 locator
->pParserCtxt
= xmlCreateMemoryParserCtxt(buffer
, size
);
2190 if (!locator
->pParserCtxt
)
2192 ISAXLocator_Release(&locator
->ISAXLocator_iface
);
2198 locator
->pParserCtxt
->encoding
= xmlStrdup(enc_name
);
2199 if (encoding
== XML_CHAR_ENCODING_UTF16LE
) {
2200 TRACE("switching to %s\n", enc_name
);
2201 xmlSwitchEncoding(locator
->pParserCtxt
, encoding
);
2205 xmlFree(locator
->pParserCtxt
->sax
);
2206 locator
->pParserCtxt
->sax
= &locator
->saxreader
->sax
;
2207 locator
->pParserCtxt
->userData
= locator
;
2209 This
->isParsing
= TRUE
;
2210 if(xmlParseDocument(locator
->pParserCtxt
) == -1 && locator
->ret
== S_OK
)
2214 This
->isParsing
= FALSE
;
2216 if(locator
->pParserCtxt
)
2218 locator
->pParserCtxt
->sax
= NULL
;
2219 xmlFreeParserCtxt(locator
->pParserCtxt
);
2220 locator
->pParserCtxt
= NULL
;
2223 ISAXLocator_Release(&locator
->ISAXLocator_iface
);
2227 static HRESULT
internal_parseStream(saxreader
*This
, IStream
*stream
, BOOL vbInterface
)
2229 saxlocator
*locator
;
2236 hr
= IStream_Read(stream
, data
, sizeof(data
), &dataRead
);
2237 if(FAILED(hr
)) return hr
;
2239 hr
= SAXLocator_create(This
, &locator
, vbInterface
);
2240 if(FAILED(hr
)) return hr
;
2242 locator
->pParserCtxt
= xmlCreatePushParserCtxt(
2243 &locator
->saxreader
->sax
, locator
,
2244 data
, dataRead
, NULL
);
2245 if(!locator
->pParserCtxt
)
2247 ISAXLocator_Release(&locator
->ISAXLocator_iface
);
2251 This
->isParsing
= TRUE
;
2253 if(dataRead
!= sizeof(data
))
2255 ret
= xmlParseChunk(locator
->pParserCtxt
, data
, 0, 1);
2256 hr
= ret
!=XML_ERR_OK
&& locator
->ret
==S_OK
? E_FAIL
: locator
->ret
;
2263 hr
= IStream_Read(stream
, data
, sizeof(data
), &dataRead
);
2264 if (FAILED(hr
)) break;
2266 ret
= xmlParseChunk(locator
->pParserCtxt
, data
, dataRead
, 0);
2267 hr
= ret
!=XML_ERR_OK
&& locator
->ret
==S_OK
? E_FAIL
: locator
->ret
;
2269 if (hr
!= S_OK
) break;
2271 if (dataRead
!= sizeof(data
))
2273 ret
= xmlParseChunk(locator
->pParserCtxt
, data
, 0, 1);
2274 hr
= ret
!=XML_ERR_OK
&& locator
->ret
==S_OK
? E_FAIL
: locator
->ret
;
2280 This
->isParsing
= FALSE
;
2282 xmlFreeParserCtxt(locator
->pParserCtxt
);
2283 locator
->pParserCtxt
= NULL
;
2284 ISAXLocator_Release(&locator
->ISAXLocator_iface
);
2288 static HRESULT
internal_getEntityResolver(
2290 void *pEntityResolver
,
2293 FIXME("(%p)->(%p) stub\n", This
, pEntityResolver
);
2297 static HRESULT
internal_putEntityResolver(
2299 void *pEntityResolver
,
2302 FIXME("(%p)->(%p) stub\n", This
, pEntityResolver
);
2306 static HRESULT
internal_getContentHandler(
2308 void *pContentHandler
,
2311 TRACE("(%p)->(%p)\n", This
, pContentHandler
);
2312 if(pContentHandler
== NULL
)
2314 if((vbInterface
&& This
->vbcontentHandler
)
2315 || (!vbInterface
&& This
->contentHandler
))
2318 IVBSAXContentHandler_AddRef(This
->vbcontentHandler
);
2320 ISAXContentHandler_AddRef(This
->contentHandler
);
2322 if(vbInterface
) *(IVBSAXContentHandler
**)pContentHandler
=
2323 This
->vbcontentHandler
;
2324 else *(ISAXContentHandler
**)pContentHandler
= This
->contentHandler
;
2329 static HRESULT
internal_putContentHandler(
2331 void *contentHandler
,
2334 TRACE("(%p)->(%p)\n", This
, contentHandler
);
2338 IVBSAXContentHandler_AddRef((IVBSAXContentHandler
*)contentHandler
);
2340 ISAXContentHandler_AddRef((ISAXContentHandler
*)contentHandler
);
2342 if((vbInterface
&& This
->vbcontentHandler
)
2343 || (!vbInterface
&& This
->contentHandler
))
2346 IVBSAXContentHandler_Release(This
->vbcontentHandler
);
2348 ISAXContentHandler_Release(This
->contentHandler
);
2351 This
->vbcontentHandler
= contentHandler
;
2353 This
->contentHandler
= contentHandler
;
2358 static HRESULT
internal_getDTDHandler(
2363 FIXME("(%p)->(%p) stub\n", This
, pDTDHandler
);
2367 static HRESULT
internal_putDTDHandler(
2372 FIXME("(%p)->(%p) stub\n", This
, pDTDHandler
);
2376 static HRESULT
internal_getErrorHandler(
2378 void *pErrorHandler
,
2381 TRACE("(%p)->(%p)\n", This
, pErrorHandler
);
2382 if(pErrorHandler
== NULL
)
2385 if(vbInterface
&& This
->vberrorHandler
)
2386 IVBSAXErrorHandler_AddRef(This
->vberrorHandler
);
2387 else if(!vbInterface
&& This
->errorHandler
)
2388 ISAXErrorHandler_AddRef(This
->errorHandler
);
2391 *(IVBSAXErrorHandler
**)pErrorHandler
= This
->vberrorHandler
;
2393 *(ISAXErrorHandler
**)pErrorHandler
= This
->errorHandler
;
2399 static HRESULT
internal_putErrorHandler(
2404 TRACE("(%p)->(%p)\n", This
, errorHandler
);
2408 IVBSAXErrorHandler_AddRef((IVBSAXErrorHandler
*)errorHandler
);
2410 ISAXErrorHandler_AddRef((ISAXErrorHandler
*)errorHandler
);
2413 if(vbInterface
&& This
->vberrorHandler
)
2414 IVBSAXErrorHandler_Release(This
->vberrorHandler
);
2415 else if(!vbInterface
&& This
->errorHandler
)
2416 ISAXErrorHandler_Release(This
->errorHandler
);
2419 This
->vberrorHandler
= errorHandler
;
2421 This
->errorHandler
= errorHandler
;
2427 static HRESULT
internal_parse(
2434 TRACE("(%p)->(%s)\n", This
, debugstr_variant(&varInput
));
2436 /* Dispose of the BSTRs in the pool from a prior run, if any. */
2437 free_bstr_pool(&This
->pool
);
2439 switch(V_VT(&varInput
))
2442 hr
= internal_parseBuffer(This
, (const char*)V_BSTR(&varInput
),
2443 SysStringByteLen(V_BSTR(&varInput
)), vbInterface
);
2445 case VT_ARRAY
|VT_UI1
: {
2447 LONG lBound
, uBound
;
2450 hr
= SafeArrayGetLBound(V_ARRAY(&varInput
), 1, &lBound
);
2451 if(hr
!= S_OK
) break;
2452 hr
= SafeArrayGetUBound(V_ARRAY(&varInput
), 1, &uBound
);
2453 if(hr
!= S_OK
) break;
2454 dataRead
= (uBound
-lBound
)*SafeArrayGetElemsize(V_ARRAY(&varInput
));
2455 hr
= SafeArrayAccessData(V_ARRAY(&varInput
), &pSAData
);
2456 if(hr
!= S_OK
) break;
2457 hr
= internal_parseBuffer(This
, pSAData
, dataRead
, vbInterface
);
2458 SafeArrayUnaccessData(V_ARRAY(&varInput
));
2463 IPersistStream
*persistStream
;
2464 IStream
*stream
= NULL
;
2465 IXMLDOMDocument
*xmlDoc
;
2467 if(IUnknown_QueryInterface(V_UNKNOWN(&varInput
),
2468 &IID_IXMLDOMDocument
, (void**)&xmlDoc
) == S_OK
)
2472 IXMLDOMDocument_get_xml(xmlDoc
, &bstrData
);
2473 hr
= internal_parseBuffer(This
, (const char*)bstrData
,
2474 SysStringByteLen(bstrData
), vbInterface
);
2475 IXMLDOMDocument_Release(xmlDoc
);
2476 SysFreeString(bstrData
);
2480 if(IUnknown_QueryInterface(V_UNKNOWN(&varInput
),
2481 &IID_IPersistStream
, (void**)&persistStream
) == S_OK
)
2483 hr
= CreateStreamOnHGlobal(NULL
, TRUE
, &stream
);
2486 IPersistStream_Release(persistStream
);
2490 hr
= IPersistStream_Save(persistStream
, stream
, TRUE
);
2491 IPersistStream_Release(persistStream
);
2494 IStream_Release(stream
);
2499 if(stream
|| IUnknown_QueryInterface(V_UNKNOWN(&varInput
),
2500 &IID_IStream
, (void**)&stream
) == S_OK
)
2502 hr
= internal_parseStream(This
, stream
, vbInterface
);
2503 IStream_Release(stream
);
2508 WARN("vt %d not implemented\n", V_VT(&varInput
));
2515 static HRESULT
internal_vbonDataAvailable(void *obj
, char *ptr
, DWORD len
)
2517 saxreader
*This
= obj
;
2519 return internal_parseBuffer(This
, ptr
, len
, TRUE
);
2522 static HRESULT
internal_onDataAvailable(void *obj
, char *ptr
, DWORD len
)
2524 saxreader
*This
= obj
;
2526 return internal_parseBuffer(This
, ptr
, len
, FALSE
);
2529 static HRESULT
internal_parseURL(
2538 TRACE("(%p)->(%s)\n", This
, debugstr_w(url
));
2540 hr
= create_moniker_from_url(url
, &mon
);
2544 if(vbInterface
) hr
= bind_url(mon
, internal_vbonDataAvailable
, This
, &bsc
);
2545 else hr
= bind_url(mon
, internal_onDataAvailable
, This
, &bsc
);
2546 IMoniker_Release(mon
);
2551 return detach_bsc(bsc
);
2554 static HRESULT
internal_putProperty(
2560 TRACE("(%p)->(%s %s)\n", This
, debugstr_w(prop
), debugstr_variant(&value
));
2562 if(!memcmp(prop
, PropertyDeclHandlerW
, sizeof(PropertyDeclHandlerW
)))
2564 if(This
->isParsing
) return E_FAIL
;
2566 switch (V_VT(&value
))
2571 if (This
->vbdeclHandler
)
2573 IVBSAXDeclHandler_Release(This
->vbdeclHandler
);
2574 This
->vbdeclHandler
= NULL
;
2578 if (This
->declHandler
)
2580 ISAXDeclHandler_Release(This
->declHandler
);
2581 This
->declHandler
= NULL
;
2585 if ((vbInterface
&& This
->vbdeclHandler
) ||
2586 (!vbInterface
&& This
->declHandler
))
2589 IVBSAXDeclHandler_Release(This
->vbdeclHandler
);
2591 ISAXDeclHandler_Release(This
->declHandler
);
2594 if (V_UNKNOWN(&value
))
2596 return vbInterface
?
2597 IVBSAXDeclHandler_QueryInterface(V_UNKNOWN(&value
), &IID_IVBSAXDeclHandler
, (void**)&This
->vbdeclHandler
) :
2598 ISAXDeclHandler_QueryInterface(V_UNKNOWN(&value
), &IID_ISAXDeclHandler
, (void**)&This
->declHandler
);
2602 This
->vbdeclHandler
= NULL
;
2603 This
->declHandler
= NULL
;
2607 return E_INVALIDARG
;
2613 if(!memcmp(prop
, PropertyLexicalHandlerW
, sizeof(PropertyLexicalHandlerW
)))
2615 if(This
->isParsing
) return E_FAIL
;
2617 switch (V_VT(&value
))
2622 if (This
->vblexicalHandler
)
2624 IVBSAXLexicalHandler_Release(This
->vblexicalHandler
);
2625 This
->vblexicalHandler
= NULL
;
2629 if (This
->lexicalHandler
)
2631 ISAXLexicalHandler_Release(This
->lexicalHandler
);
2632 This
->lexicalHandler
= NULL
;
2636 if ((vbInterface
&& This
->vblexicalHandler
) ||
2637 (!vbInterface
&& This
->lexicalHandler
))
2640 IVBSAXLexicalHandler_Release(This
->vblexicalHandler
);
2642 ISAXLexicalHandler_Release(This
->lexicalHandler
);
2645 if (V_UNKNOWN(&value
))
2647 return vbInterface
?
2648 IVBSAXLexicalHandler_QueryInterface(V_UNKNOWN(&value
), &IID_IVBSAXLexicalHandler
, (void**)&This
->vblexicalHandler
) :
2649 ISAXLexicalHandler_QueryInterface(V_UNKNOWN(&value
), &IID_ISAXLexicalHandler
, (void**)&This
->lexicalHandler
);
2653 This
->vblexicalHandler
= NULL
;
2654 This
->lexicalHandler
= NULL
;
2659 return E_INVALIDARG
;
2665 if(!memcmp(prop
, PropertyMaxXMLSizeW
, sizeof(PropertyMaxXMLSizeW
)))
2667 if (V_VT(&value
) == VT_I4
&& V_I4(&value
) == 0) return S_OK
;
2668 FIXME("(%p)->(%s): max-xml-size unsupported\n", This
, debugstr_variant(&value
));
2672 if(!memcmp(prop
, PropertyMaxElementDepthW
, sizeof(PropertyMaxElementDepthW
)))
2674 if (V_VT(&value
) == VT_I4
&& V_I4(&value
) == 0) return S_OK
;
2675 FIXME("(%p)->(%s): max-element-depth unsupported\n", This
, debugstr_variant(&value
));
2679 FIXME("(%p)->(%s:%s): unsupported property\n", This
, debugstr_w(prop
), debugstr_variant(&value
));
2681 if(!memcmp(prop
, PropertyCharsetW
, sizeof(PropertyCharsetW
)))
2684 if(!memcmp(prop
, PropertyDomNodeW
, sizeof(PropertyDomNodeW
)))
2687 if(!memcmp(prop
, PropertyInputSourceW
, sizeof(PropertyInputSourceW
)))
2690 if(!memcmp(prop
, PropertySchemaDeclHandlerW
, sizeof(PropertySchemaDeclHandlerW
)))
2693 if(!memcmp(prop
, PropertyXMLDeclEncodingW
, sizeof(PropertyXMLDeclEncodingW
)))
2696 if(!memcmp(prop
, PropertyXMLDeclStandaloneW
, sizeof(PropertyXMLDeclStandaloneW
)))
2699 if(!memcmp(prop
, PropertyXMLDeclVersionW
, sizeof(PropertyXMLDeclVersionW
)))
2702 return E_INVALIDARG
;
2705 static HRESULT
internal_getProperty(const saxreader
* This
, const WCHAR
*prop
, VARIANT
*value
, BOOL vb
)
2707 TRACE("(%p)->(%s)\n", This
, debugstr_w(prop
));
2709 if (!value
) return E_POINTER
;
2711 if (!memcmp(PropertyLexicalHandlerW
, prop
, sizeof(PropertyLexicalHandlerW
)))
2713 V_VT(value
) = VT_UNKNOWN
;
2714 V_UNKNOWN(value
) = vb
? (IUnknown
*)This
->vblexicalHandler
: (IUnknown
*)This
->lexicalHandler
;
2715 if (V_UNKNOWN(value
)) IUnknown_AddRef(V_UNKNOWN(value
));
2719 if (!memcmp(PropertyDeclHandlerW
, prop
, sizeof(PropertyDeclHandlerW
)))
2721 V_VT(value
) = VT_UNKNOWN
;
2722 V_UNKNOWN(value
) = vb
? (IUnknown
*)This
->vbdeclHandler
: (IUnknown
*)This
->declHandler
;
2723 if (V_UNKNOWN(value
)) IUnknown_AddRef(V_UNKNOWN(value
));
2727 FIXME("(%p)->(%s) unsupported property\n", This
, debugstr_w(prop
));
2732 /*** IVBSAXXMLReader interface ***/
2733 /*** IUnknown methods ***/
2734 static HRESULT WINAPI
saxxmlreader_QueryInterface(IVBSAXXMLReader
* iface
, REFIID riid
, void **ppvObject
)
2736 saxreader
*This
= impl_from_IVBSAXXMLReader( iface
);
2738 TRACE("%p %s %p\n", This
, debugstr_guid( riid
), ppvObject
);
2742 if ( IsEqualGUID( riid
, &IID_IUnknown
) ||
2743 IsEqualGUID( riid
, &IID_IDispatch
) ||
2744 IsEqualGUID( riid
, &IID_IVBSAXXMLReader
))
2748 else if( IsEqualGUID( riid
, &IID_ISAXXMLReader
))
2750 *ppvObject
= &This
->ISAXXMLReader_iface
;
2752 else if (dispex_query_interface(&This
->dispex
, riid
, ppvObject
))
2754 return *ppvObject
? S_OK
: E_NOINTERFACE
;
2758 FIXME("interface %s not implemented\n", debugstr_guid(riid
));
2759 return E_NOINTERFACE
;
2762 IVBSAXXMLReader_AddRef( iface
);
2767 static ULONG WINAPI
saxxmlreader_AddRef(IVBSAXXMLReader
* iface
)
2769 saxreader
*This
= impl_from_IVBSAXXMLReader( iface
);
2770 TRACE("%p\n", This
);
2771 return InterlockedIncrement( &This
->ref
);
2774 static ULONG WINAPI
saxxmlreader_Release(
2775 IVBSAXXMLReader
* iface
)
2777 saxreader
*This
= impl_from_IVBSAXXMLReader( iface
);
2780 TRACE("%p\n", This
);
2782 ref
= InterlockedDecrement( &This
->ref
);
2785 if(This
->contentHandler
)
2786 ISAXContentHandler_Release(This
->contentHandler
);
2788 if(This
->vbcontentHandler
)
2789 IVBSAXContentHandler_Release(This
->vbcontentHandler
);
2791 if(This
->errorHandler
)
2792 ISAXErrorHandler_Release(This
->errorHandler
);
2794 if(This
->vberrorHandler
)
2795 IVBSAXErrorHandler_Release(This
->vberrorHandler
);
2797 if(This
->lexicalHandler
)
2798 ISAXLexicalHandler_Release(This
->lexicalHandler
);
2800 if(This
->vblexicalHandler
)
2801 IVBSAXLexicalHandler_Release(This
->vblexicalHandler
);
2803 if(This
->declHandler
)
2804 ISAXDeclHandler_Release(This
->declHandler
);
2806 if(This
->vbdeclHandler
)
2807 IVBSAXDeclHandler_Release(This
->vbdeclHandler
);
2809 free_bstr_pool(&This
->pool
);
2811 release_dispex(&This
->dispex
);
2818 static HRESULT WINAPI
saxxmlreader_GetTypeInfoCount( IVBSAXXMLReader
*iface
, UINT
* pctinfo
)
2820 saxreader
*This
= impl_from_IVBSAXXMLReader( iface
);
2821 return IDispatchEx_GetTypeInfoCount(&This
->dispex
.IDispatchEx_iface
, pctinfo
);
2824 static HRESULT WINAPI
saxxmlreader_GetTypeInfo(
2825 IVBSAXXMLReader
*iface
,
2826 UINT iTInfo
, LCID lcid
, ITypeInfo
** ppTInfo
)
2828 saxreader
*This
= impl_from_IVBSAXXMLReader( iface
);
2829 return IDispatchEx_GetTypeInfo(&This
->dispex
.IDispatchEx_iface
,
2830 iTInfo
, lcid
, ppTInfo
);
2833 static HRESULT WINAPI
saxxmlreader_GetIDsOfNames(
2834 IVBSAXXMLReader
*iface
,
2836 LPOLESTR
* rgszNames
,
2841 saxreader
*This
= impl_from_IVBSAXXMLReader( iface
);
2842 return IDispatchEx_GetIDsOfNames(&This
->dispex
.IDispatchEx_iface
,
2843 riid
, rgszNames
, cNames
, lcid
, rgDispId
);
2846 static HRESULT WINAPI
saxxmlreader_Invoke(
2847 IVBSAXXMLReader
*iface
,
2848 DISPID dispIdMember
,
2852 DISPPARAMS
* pDispParams
,
2853 VARIANT
* pVarResult
,
2854 EXCEPINFO
* pExcepInfo
,
2857 saxreader
*This
= impl_from_IVBSAXXMLReader( iface
);
2858 return IDispatchEx_Invoke(&This
->dispex
.IDispatchEx_iface
,
2859 dispIdMember
, riid
, lcid
, wFlags
, pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
2862 /*** IVBSAXXMLReader methods ***/
2863 static HRESULT WINAPI
saxxmlreader_getFeature(
2864 IVBSAXXMLReader
* iface
,
2865 const WCHAR
*feature_name
,
2866 VARIANT_BOOL
*value
)
2868 saxreader
*This
= impl_from_IVBSAXXMLReader( iface
);
2869 saxreader_feature feature
;
2871 TRACE("(%p)->(%s %p)\n", This
, debugstr_w(feature_name
), value
);
2873 feature
= get_saxreader_feature(feature_name
);
2874 if (feature
== Namespaces
|| feature
== NamespacePrefixes
)
2875 return get_feature_value(This
, feature
, value
);
2877 FIXME("(%p)->(%s %p) stub\n", This
, debugstr_w(feature_name
), value
);
2881 static HRESULT WINAPI
saxxmlreader_putFeature(
2882 IVBSAXXMLReader
* iface
,
2883 const WCHAR
*feature_name
,
2886 saxreader
*This
= impl_from_IVBSAXXMLReader( iface
);
2887 saxreader_feature feature
;
2889 TRACE("(%p)->(%s %x)\n", This
, debugstr_w(feature_name
), value
);
2891 feature
= get_saxreader_feature(feature_name
);
2893 /* accepted cases */
2894 if ((feature
== ExternalGeneralEntities
&& value
== VARIANT_FALSE
) ||
2895 (feature
== ExternalParameterEntities
&& value
== VARIANT_FALSE
) ||
2896 feature
== Namespaces
||
2897 feature
== NamespacePrefixes
)
2899 return set_feature_value(This
, feature
, value
);
2902 if (feature
== LexicalHandlerParEntities
|| feature
== ProhibitDTD
)
2904 FIXME("(%p)->(%s %x) stub\n", This
, debugstr_w(feature_name
), value
);
2905 return set_feature_value(This
, feature
, value
);
2908 FIXME("(%p)->(%s %x) stub\n", This
, debugstr_w(feature_name
), value
);
2912 static HRESULT WINAPI
saxxmlreader_getProperty(
2913 IVBSAXXMLReader
* iface
,
2917 saxreader
*This
= impl_from_IVBSAXXMLReader( iface
);
2918 return internal_getProperty(This
, prop
, value
, TRUE
);
2921 static HRESULT WINAPI
saxxmlreader_putProperty(
2922 IVBSAXXMLReader
* iface
,
2926 saxreader
*This
= impl_from_IVBSAXXMLReader( iface
);
2927 return internal_putProperty(This
, pProp
, value
, TRUE
);
2930 static HRESULT WINAPI
saxxmlreader_get_entityResolver(
2931 IVBSAXXMLReader
* iface
,
2932 IVBSAXEntityResolver
**pEntityResolver
)
2934 saxreader
*This
= impl_from_IVBSAXXMLReader( iface
);
2935 return internal_getEntityResolver(This
, pEntityResolver
, TRUE
);
2938 static HRESULT WINAPI
saxxmlreader_put_entityResolver(
2939 IVBSAXXMLReader
* iface
,
2940 IVBSAXEntityResolver
*pEntityResolver
)
2942 saxreader
*This
= impl_from_IVBSAXXMLReader( iface
);
2943 return internal_putEntityResolver(This
, pEntityResolver
, TRUE
);
2946 static HRESULT WINAPI
saxxmlreader_get_contentHandler(
2947 IVBSAXXMLReader
* iface
,
2948 IVBSAXContentHandler
**ppContentHandler
)
2950 saxreader
*This
= impl_from_IVBSAXXMLReader( iface
);
2951 return internal_getContentHandler(This
, ppContentHandler
, TRUE
);
2954 static HRESULT WINAPI
saxxmlreader_put_contentHandler(
2955 IVBSAXXMLReader
* iface
,
2956 IVBSAXContentHandler
*contentHandler
)
2958 saxreader
*This
= impl_from_IVBSAXXMLReader( iface
);
2959 return internal_putContentHandler(This
, contentHandler
, TRUE
);
2962 static HRESULT WINAPI
saxxmlreader_get_dtdHandler(
2963 IVBSAXXMLReader
* iface
,
2964 IVBSAXDTDHandler
**pDTDHandler
)
2966 saxreader
*This
= impl_from_IVBSAXXMLReader( iface
);
2967 return internal_getDTDHandler(This
, pDTDHandler
, TRUE
);
2970 static HRESULT WINAPI
saxxmlreader_put_dtdHandler(
2971 IVBSAXXMLReader
* iface
,
2972 IVBSAXDTDHandler
*pDTDHandler
)
2974 saxreader
*This
= impl_from_IVBSAXXMLReader( iface
);
2975 return internal_putDTDHandler(This
, pDTDHandler
, TRUE
);
2978 static HRESULT WINAPI
saxxmlreader_get_errorHandler(
2979 IVBSAXXMLReader
* iface
,
2980 IVBSAXErrorHandler
**pErrorHandler
)
2982 saxreader
*This
= impl_from_IVBSAXXMLReader( iface
);
2983 return internal_getErrorHandler(This
, pErrorHandler
, TRUE
);
2986 static HRESULT WINAPI
saxxmlreader_put_errorHandler(
2987 IVBSAXXMLReader
* iface
,
2988 IVBSAXErrorHandler
*errorHandler
)
2990 saxreader
*This
= impl_from_IVBSAXXMLReader( iface
);
2991 return internal_putErrorHandler(This
, errorHandler
, TRUE
);
2994 static HRESULT WINAPI
saxxmlreader_get_baseURL(
2995 IVBSAXXMLReader
* iface
,
2996 const WCHAR
**pBaseUrl
)
2998 saxreader
*This
= impl_from_IVBSAXXMLReader( iface
);
3000 FIXME("(%p)->(%p) stub\n", This
, pBaseUrl
);
3004 static HRESULT WINAPI
saxxmlreader_put_baseURL(
3005 IVBSAXXMLReader
* iface
,
3006 const WCHAR
*pBaseUrl
)
3008 saxreader
*This
= impl_from_IVBSAXXMLReader( iface
);
3010 FIXME("(%p)->(%s) stub\n", This
, debugstr_w(pBaseUrl
));
3014 static HRESULT WINAPI
saxxmlreader_get_secureBaseURL(
3015 IVBSAXXMLReader
* iface
,
3016 const WCHAR
**pSecureBaseUrl
)
3018 saxreader
*This
= impl_from_IVBSAXXMLReader( iface
);
3020 FIXME("(%p)->(%p) stub\n", This
, pSecureBaseUrl
);
3025 static HRESULT WINAPI
saxxmlreader_put_secureBaseURL(
3026 IVBSAXXMLReader
* iface
,
3027 const WCHAR
*secureBaseUrl
)
3029 saxreader
*This
= impl_from_IVBSAXXMLReader( iface
);
3031 FIXME("(%p)->(%s) stub\n", This
, debugstr_w(secureBaseUrl
));
3035 static HRESULT WINAPI
saxxmlreader_parse(
3036 IVBSAXXMLReader
* iface
,
3039 saxreader
*This
= impl_from_IVBSAXXMLReader( iface
);
3040 return internal_parse(This
, varInput
, TRUE
);
3043 static HRESULT WINAPI
saxxmlreader_parseURL(
3044 IVBSAXXMLReader
* iface
,
3047 saxreader
*This
= impl_from_IVBSAXXMLReader( iface
);
3048 return internal_parseURL(This
, url
, TRUE
);
3051 static const struct IVBSAXXMLReaderVtbl VBSAXXMLReaderVtbl
=
3053 saxxmlreader_QueryInterface
,
3054 saxxmlreader_AddRef
,
3055 saxxmlreader_Release
,
3056 saxxmlreader_GetTypeInfoCount
,
3057 saxxmlreader_GetTypeInfo
,
3058 saxxmlreader_GetIDsOfNames
,
3059 saxxmlreader_Invoke
,
3060 saxxmlreader_getFeature
,
3061 saxxmlreader_putFeature
,
3062 saxxmlreader_getProperty
,
3063 saxxmlreader_putProperty
,
3064 saxxmlreader_get_entityResolver
,
3065 saxxmlreader_put_entityResolver
,
3066 saxxmlreader_get_contentHandler
,
3067 saxxmlreader_put_contentHandler
,
3068 saxxmlreader_get_dtdHandler
,
3069 saxxmlreader_put_dtdHandler
,
3070 saxxmlreader_get_errorHandler
,
3071 saxxmlreader_put_errorHandler
,
3072 saxxmlreader_get_baseURL
,
3073 saxxmlreader_put_baseURL
,
3074 saxxmlreader_get_secureBaseURL
,
3075 saxxmlreader_put_secureBaseURL
,
3077 saxxmlreader_parseURL
3080 /*** ISAXXMLReader interface ***/
3081 /*** IUnknown methods ***/
3082 static HRESULT WINAPI
isaxxmlreader_QueryInterface(ISAXXMLReader
* iface
, REFIID riid
, void **ppvObject
)
3084 saxreader
*This
= impl_from_ISAXXMLReader( iface
);
3085 return saxxmlreader_QueryInterface(&This
->IVBSAXXMLReader_iface
, riid
, ppvObject
);
3088 static ULONG WINAPI
isaxxmlreader_AddRef(ISAXXMLReader
* iface
)
3090 saxreader
*This
= impl_from_ISAXXMLReader( iface
);
3091 return saxxmlreader_AddRef(&This
->IVBSAXXMLReader_iface
);
3094 static ULONG WINAPI
isaxxmlreader_Release(ISAXXMLReader
* iface
)
3096 saxreader
*This
= impl_from_ISAXXMLReader( iface
);
3097 return saxxmlreader_Release(&This
->IVBSAXXMLReader_iface
);
3100 /*** ISAXXMLReader methods ***/
3101 static HRESULT WINAPI
isaxxmlreader_getFeature(
3102 ISAXXMLReader
* iface
,
3103 const WCHAR
*pFeature
,
3104 VARIANT_BOOL
*pValue
)
3106 saxreader
*This
= impl_from_ISAXXMLReader( iface
);
3107 return IVBSAXXMLReader_getFeature(&This
->IVBSAXXMLReader_iface
, pFeature
, pValue
);
3110 static HRESULT WINAPI
isaxxmlreader_putFeature(
3111 ISAXXMLReader
* iface
,
3112 const WCHAR
*pFeature
,
3113 VARIANT_BOOL vfValue
)
3115 saxreader
*This
= impl_from_ISAXXMLReader( iface
);
3116 return IVBSAXXMLReader_putFeature(&This
->IVBSAXXMLReader_iface
, pFeature
, vfValue
);
3119 static HRESULT WINAPI
isaxxmlreader_getProperty(
3120 ISAXXMLReader
* iface
,
3124 saxreader
*This
= impl_from_ISAXXMLReader( iface
);
3125 return internal_getProperty(This
, prop
, value
, FALSE
);
3128 static HRESULT WINAPI
isaxxmlreader_putProperty(
3129 ISAXXMLReader
* iface
,
3133 saxreader
*This
= impl_from_ISAXXMLReader( iface
);
3134 return internal_putProperty(This
, pProp
, value
, FALSE
);
3137 static HRESULT WINAPI
isaxxmlreader_getEntityResolver(
3138 ISAXXMLReader
* iface
,
3139 ISAXEntityResolver
**ppEntityResolver
)
3141 saxreader
*This
= impl_from_ISAXXMLReader( iface
);
3142 return internal_getEntityResolver(This
, ppEntityResolver
, FALSE
);
3145 static HRESULT WINAPI
isaxxmlreader_putEntityResolver(
3146 ISAXXMLReader
* iface
,
3147 ISAXEntityResolver
*pEntityResolver
)
3149 saxreader
*This
= impl_from_ISAXXMLReader( iface
);
3150 return internal_putEntityResolver(This
, pEntityResolver
, FALSE
);
3153 static HRESULT WINAPI
isaxxmlreader_getContentHandler(
3154 ISAXXMLReader
* iface
,
3155 ISAXContentHandler
**pContentHandler
)
3157 saxreader
*This
= impl_from_ISAXXMLReader( iface
);
3158 return internal_getContentHandler(This
, pContentHandler
, FALSE
);
3161 static HRESULT WINAPI
isaxxmlreader_putContentHandler(
3162 ISAXXMLReader
* iface
,
3163 ISAXContentHandler
*contentHandler
)
3165 saxreader
*This
= impl_from_ISAXXMLReader( iface
);
3166 return internal_putContentHandler(This
, contentHandler
, FALSE
);
3169 static HRESULT WINAPI
isaxxmlreader_getDTDHandler(
3170 ISAXXMLReader
* iface
,
3171 ISAXDTDHandler
**pDTDHandler
)
3173 saxreader
*This
= impl_from_ISAXXMLReader( iface
);
3174 return internal_getDTDHandler(This
, pDTDHandler
, FALSE
);
3177 static HRESULT WINAPI
isaxxmlreader_putDTDHandler(
3178 ISAXXMLReader
* iface
,
3179 ISAXDTDHandler
*pDTDHandler
)
3181 saxreader
*This
= impl_from_ISAXXMLReader( iface
);
3182 return internal_putDTDHandler(This
, pDTDHandler
, FALSE
);
3185 static HRESULT WINAPI
isaxxmlreader_getErrorHandler(
3186 ISAXXMLReader
* iface
,
3187 ISAXErrorHandler
**pErrorHandler
)
3189 saxreader
*This
= impl_from_ISAXXMLReader( iface
);
3190 return internal_getErrorHandler(This
, pErrorHandler
, FALSE
);
3193 static HRESULT WINAPI
isaxxmlreader_putErrorHandler(
3194 ISAXXMLReader
* iface
,
3195 ISAXErrorHandler
*errorHandler
)
3197 saxreader
*This
= impl_from_ISAXXMLReader( iface
);
3198 return internal_putErrorHandler(This
, errorHandler
, FALSE
);
3201 static HRESULT WINAPI
isaxxmlreader_getBaseURL(
3202 ISAXXMLReader
* iface
,
3203 const WCHAR
**pBaseUrl
)
3205 saxreader
*This
= impl_from_ISAXXMLReader( iface
);
3206 return IVBSAXXMLReader_get_baseURL(&This
->IVBSAXXMLReader_iface
, pBaseUrl
);
3209 static HRESULT WINAPI
isaxxmlreader_putBaseURL(
3210 ISAXXMLReader
* iface
,
3211 const WCHAR
*pBaseUrl
)
3213 saxreader
*This
= impl_from_ISAXXMLReader( iface
);
3214 return IVBSAXXMLReader_put_baseURL(&This
->IVBSAXXMLReader_iface
, pBaseUrl
);
3217 static HRESULT WINAPI
isaxxmlreader_getSecureBaseURL(
3218 ISAXXMLReader
* iface
,
3219 const WCHAR
**pSecureBaseUrl
)
3221 saxreader
*This
= impl_from_ISAXXMLReader( iface
);
3222 return IVBSAXXMLReader_get_secureBaseURL(&This
->IVBSAXXMLReader_iface
, pSecureBaseUrl
);
3225 static HRESULT WINAPI
isaxxmlreader_putSecureBaseURL(
3226 ISAXXMLReader
* iface
,
3227 const WCHAR
*secureBaseUrl
)
3229 saxreader
*This
= impl_from_ISAXXMLReader( iface
);
3230 return IVBSAXXMLReader_put_secureBaseURL(&This
->IVBSAXXMLReader_iface
, secureBaseUrl
);
3233 static HRESULT WINAPI
isaxxmlreader_parse(
3234 ISAXXMLReader
* iface
,
3237 saxreader
*This
= impl_from_ISAXXMLReader( iface
);
3238 return internal_parse(This
, varInput
, FALSE
);
3241 static HRESULT WINAPI
isaxxmlreader_parseURL(
3242 ISAXXMLReader
* iface
,
3245 saxreader
*This
= impl_from_ISAXXMLReader( iface
);
3246 return internal_parseURL(This
, url
, FALSE
);
3249 static const struct ISAXXMLReaderVtbl SAXXMLReaderVtbl
=
3251 isaxxmlreader_QueryInterface
,
3252 isaxxmlreader_AddRef
,
3253 isaxxmlreader_Release
,
3254 isaxxmlreader_getFeature
,
3255 isaxxmlreader_putFeature
,
3256 isaxxmlreader_getProperty
,
3257 isaxxmlreader_putProperty
,
3258 isaxxmlreader_getEntityResolver
,
3259 isaxxmlreader_putEntityResolver
,
3260 isaxxmlreader_getContentHandler
,
3261 isaxxmlreader_putContentHandler
,
3262 isaxxmlreader_getDTDHandler
,
3263 isaxxmlreader_putDTDHandler
,
3264 isaxxmlreader_getErrorHandler
,
3265 isaxxmlreader_putErrorHandler
,
3266 isaxxmlreader_getBaseURL
,
3267 isaxxmlreader_putBaseURL
,
3268 isaxxmlreader_getSecureBaseURL
,
3269 isaxxmlreader_putSecureBaseURL
,
3270 isaxxmlreader_parse
,
3271 isaxxmlreader_parseURL
3274 static const tid_t saxreader_iface_tids
[] = {
3275 IVBSAXXMLReader_tid
,
3278 static dispex_static_data_t saxreader_dispex
= {
3280 IVBSAXXMLReader_tid
,
3282 saxreader_iface_tids
3285 HRESULT
SAXXMLReader_create(MSXML_VERSION version
, IUnknown
*outer
, LPVOID
*ppObj
)
3289 TRACE("(%p, %p)\n", outer
, ppObj
);
3291 reader
= heap_alloc( sizeof (*reader
) );
3293 return E_OUTOFMEMORY
;
3295 reader
->IVBSAXXMLReader_iface
.lpVtbl
= &VBSAXXMLReaderVtbl
;
3296 reader
->ISAXXMLReader_iface
.lpVtbl
= &SAXXMLReaderVtbl
;
3298 reader
->contentHandler
= NULL
;
3299 reader
->vbcontentHandler
= NULL
;
3300 reader
->errorHandler
= NULL
;
3301 reader
->vberrorHandler
= NULL
;
3302 reader
->lexicalHandler
= NULL
;
3303 reader
->vblexicalHandler
= NULL
;
3304 reader
->declHandler
= NULL
;
3305 reader
->vbdeclHandler
= NULL
;
3306 reader
->isParsing
= FALSE
;
3307 reader
->pool
.pool
= NULL
;
3308 reader
->pool
.index
= 0;
3309 reader
->pool
.len
= 0;
3310 reader
->features
= Namespaces
| NamespacePrefixes
;
3311 reader
->version
= version
;
3313 init_dispex(&reader
->dispex
, (IUnknown
*)&reader
->IVBSAXXMLReader_iface
, &saxreader_dispex
);
3315 memset(&reader
->sax
, 0, sizeof(xmlSAXHandler
));
3316 reader
->sax
.initialized
= XML_SAX2_MAGIC
;
3317 reader
->sax
.startDocument
= libxmlStartDocument
;
3318 reader
->sax
.endDocument
= libxmlEndDocument
;
3319 reader
->sax
.startElementNs
= libxmlStartElementNS
;
3320 reader
->sax
.endElementNs
= libxmlEndElementNS
;
3321 reader
->sax
.characters
= libxmlCharacters
;
3322 reader
->sax
.setDocumentLocator
= libxmlSetDocumentLocator
;
3323 reader
->sax
.comment
= libxmlComment
;
3324 reader
->sax
.error
= libxmlFatalError
;
3325 reader
->sax
.fatalError
= libxmlFatalError
;
3326 reader
->sax
.cdataBlock
= libxmlCDataBlock
;
3328 *ppObj
= &reader
->IVBSAXXMLReader_iface
;
3330 TRACE("returning iface %p\n", *ppObj
);
3337 HRESULT
SAXXMLReader_create(MSXML_VERSION version
, IUnknown
*pUnkOuter
, LPVOID
*ppObj
)
3339 MESSAGE("This program tried to use a SAX XML Reader object, but\n"
3340 "libxml2 support was not present at compile time.\n");