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 MSXML_VERSION version
;
215 static HRESULT
saxreader_put_handler(saxreader
*reader
, enum saxhandler_type type
, void *ptr
, BOOL vb
)
217 struct saxhandler_iface
*iface
= &reader
->saxhandlers
[type
];
218 IUnknown
*unk
= (IUnknown
*)ptr
;
221 IUnknown_AddRef(unk
);
223 if ((vb
&& iface
->vbhandler
) || (!vb
&& iface
->handler
))
224 IUnknown_Release(vb
? iface
->vbhandler
: iface
->handler
);
227 iface
->vbhandler
= unk
;
229 iface
->handler
= unk
;
234 static HRESULT
saxreader_get_handler(const saxreader
*reader
, enum saxhandler_type type
, BOOL vb
, void **ret
)
236 const struct saxhandler_iface
*iface
= &reader
->saxhandlers
[type
];
238 if (!ret
) return E_POINTER
;
240 if ((vb
&& iface
->vbhandler
) || (!vb
&& iface
->handler
))
243 IUnknown_AddRef(iface
->vbhandler
);
245 IUnknown_AddRef(iface
->handler
);
248 *ret
= vb
? iface
->vbhandler
: iface
->handler
;
253 static struct saxcontenthandler_iface
*saxreader_get_contenthandler(saxreader
*reader
)
255 return (struct saxcontenthandler_iface
*)&reader
->saxhandlers
[SAXContentHandler
];
258 static struct saxerrorhandler_iface
*saxreader_get_errorhandler(saxreader
*reader
)
260 return (struct saxerrorhandler_iface
*)&reader
->saxhandlers
[SAXErrorHandler
];
263 static struct saxlexicalhandler_iface
*saxreader_get_lexicalhandler(saxreader
*reader
)
265 return (struct saxlexicalhandler_iface
*)&reader
->saxhandlers
[SAXLexicalHandler
];
270 IVBSAXLocator IVBSAXLocator_iface
;
271 ISAXLocator ISAXLocator_iface
;
272 IVBSAXAttributes IVBSAXAttributes_iface
;
273 ISAXAttributes ISAXAttributes_iface
;
275 saxreader
*saxreader
;
277 xmlParserCtxtPtr pParserCtxt
;
283 struct list elements
;
297 static inline saxreader
*impl_from_IVBSAXXMLReader( IVBSAXXMLReader
*iface
)
299 return CONTAINING_RECORD(iface
, saxreader
, IVBSAXXMLReader_iface
);
302 static inline saxreader
*impl_from_ISAXXMLReader( ISAXXMLReader
*iface
)
304 return CONTAINING_RECORD(iface
, saxreader
, ISAXXMLReader_iface
);
307 static inline saxlocator
*impl_from_IVBSAXLocator( IVBSAXLocator
*iface
)
309 return CONTAINING_RECORD(iface
, saxlocator
, IVBSAXLocator_iface
);
312 static inline saxlocator
*impl_from_ISAXLocator( ISAXLocator
*iface
)
314 return CONTAINING_RECORD(iface
, saxlocator
, ISAXLocator_iface
);
317 static inline saxlocator
*impl_from_IVBSAXAttributes( IVBSAXAttributes
*iface
)
319 return CONTAINING_RECORD(iface
, saxlocator
, IVBSAXAttributes_iface
);
322 static inline saxlocator
*impl_from_ISAXAttributes( ISAXAttributes
*iface
)
324 return CONTAINING_RECORD(iface
, saxlocator
, ISAXAttributes_iface
);
327 static inline int saxreader_has_handler(const saxlocator
*locator
, enum saxhandler_type type
)
329 return (locator
->vbInterface
&& locator
->saxreader
->saxhandlers
[type
].vbhandler
) ||
330 (!locator
->vbInterface
&& locator
->saxreader
->saxhandlers
[type
].handler
);
334 static const WCHAR PropertyCharsetW
[] = {
335 'c','h','a','r','s','e','t',0
337 static const WCHAR PropertyDeclHandlerW
[] = {
338 'h','t','t','p',':','/','/','x','m','l','.','o','r','g','/',
339 's','a','x','/','p','r','o','p','e','r','t','i','e','s','/',
340 'd','e','c','l','a','r','a','t','i','o','n',
341 '-','h','a','n','d','l','e','r',0
343 static const WCHAR PropertyDomNodeW
[] = {
344 'h','t','t','p',':','/','/','x','m','l','.','o','r','g','/',
345 's','a','x','/','p','r','o','p','e','r','t','i','e','s','/',
346 'd','o','m','-','n','o','d','e',0
348 static const WCHAR PropertyInputSourceW
[] = {
349 'i','n','p','u','t','-','s','o','u','r','c','e',0
351 static const WCHAR PropertyLexicalHandlerW
[] = {
352 'h','t','t','p',':','/','/','x','m','l','.','o','r','g','/',
353 's','a','x','/','p','r','o','p','e','r','t','i','e','s','/',
354 'l','e','x','i','c','a','l','-','h','a','n','d','l','e','r',0
356 static const WCHAR PropertyMaxElementDepthW
[] = {
357 'm','a','x','-','e','l','e','m','e','n','t','-','d','e','p','t','h',0
359 static const WCHAR PropertyMaxXMLSizeW
[] = {
360 'm','a','x','-','x','m','l','-','s','i','z','e',0
362 static const WCHAR PropertySchemaDeclHandlerW
[] = {
363 's','c','h','e','m','a','-','d','e','c','l','a','r','a','t','i','o','n','-',
364 'h','a','n','d','l','e','r',0
366 static const WCHAR PropertyXMLDeclEncodingW
[] = {
367 'x','m','l','d','e','c','l','-','e','n','c','o','d','i','n','g',0
369 static const WCHAR PropertyXMLDeclStandaloneW
[] = {
370 'x','m','l','d','e','c','l','-','s','t','a','n','d','a','l','o','n','e',0
372 static const WCHAR PropertyXMLDeclVersionW
[] = {
373 'x','m','l','d','e','c','l','-','v','e','r','s','i','o','n',0
376 static inline HRESULT
set_feature_value(saxreader
*reader
, saxreader_feature feature
, VARIANT_BOOL value
)
378 /* handling of non-VARIANT_* values is version dependent */
379 if ((reader
->version
< MSXML4
) && (value
!= VARIANT_TRUE
))
380 value
= VARIANT_FALSE
;
381 if ((reader
->version
>= MSXML4
) && (value
!= VARIANT_FALSE
))
382 value
= VARIANT_TRUE
;
384 if (value
== VARIANT_TRUE
)
385 reader
->features
|= feature
;
387 reader
->features
&= ~feature
;
392 static inline HRESULT
get_feature_value(const saxreader
*reader
, saxreader_feature feature
, VARIANT_BOOL
*value
)
394 *value
= reader
->features
& feature
? VARIANT_TRUE
: VARIANT_FALSE
;
398 static BOOL
is_namespaces_enabled(const saxreader
*reader
)
400 return (reader
->version
< MSXML4
) || (reader
->features
& Namespaces
);
403 static BSTR
build_qname(BSTR prefix
, BSTR local
)
405 if (prefix
&& *prefix
)
407 BSTR qname
= SysAllocStringLen(NULL
, SysStringLen(prefix
) + SysStringLen(local
) + 1);
411 strcpyW(ptr
, prefix
);
412 ptr
+= SysStringLen(prefix
);
418 return SysAllocString(local
);
421 static element_entry
* alloc_element_entry(const xmlChar
*local
, const xmlChar
*prefix
, int nb_ns
,
422 const xmlChar
**namespaces
)
427 ret
= heap_alloc(sizeof(*ret
));
428 if (!ret
) return ret
;
430 ret
->local
= bstr_from_xmlChar(local
);
431 ret
->prefix
= bstr_from_xmlChar(prefix
);
432 ret
->qname
= build_qname(ret
->prefix
, ret
->local
);
433 ret
->ns
= nb_ns
? heap_alloc(nb_ns
*sizeof(ns
)) : NULL
;
434 ret
->ns_count
= nb_ns
;
436 for (i
=0; i
< nb_ns
; i
++)
438 ret
->ns
[i
].prefix
= bstr_from_xmlChar(namespaces
[2*i
]);
439 ret
->ns
[i
].uri
= bstr_from_xmlChar(namespaces
[2*i
+1]);
445 static void free_element_entry(element_entry
*element
)
449 for (i
=0; i
<element
->ns_count
;i
++)
451 SysFreeString(element
->ns
[i
].prefix
);
452 SysFreeString(element
->ns
[i
].uri
);
455 SysFreeString(element
->prefix
);
456 SysFreeString(element
->local
);
458 heap_free(element
->ns
);
462 static void push_element_ns(saxlocator
*locator
, element_entry
*element
)
464 list_add_head(&locator
->elements
, &element
->entry
);
467 static element_entry
* pop_element_ns(saxlocator
*locator
)
469 element_entry
*element
= LIST_ENTRY(list_head(&locator
->elements
), element_entry
, entry
);
472 list_remove(&element
->entry
);
477 static BSTR
find_element_uri(saxlocator
*locator
, const xmlChar
*uri
)
479 element_entry
*element
;
483 if (!uri
) return NULL
;
485 uriW
= bstr_from_xmlChar(uri
);
487 LIST_FOR_EACH_ENTRY(element
, &locator
->elements
, element_entry
, entry
)
489 for (i
=0; i
< element
->ns_count
; i
++)
490 if (!strcmpW(uriW
, element
->ns
[i
].uri
))
493 return element
->ns
[i
].uri
;
498 ERR("namespace uri not found, %s\n", debugstr_a((char*)uri
));
502 /* used to localize version dependent error check behaviour */
503 static inline BOOL
sax_callback_failed(saxlocator
*This
, HRESULT hr
)
505 return This
->saxreader
->version
>= MSXML4
? FAILED(hr
) : hr
!= S_OK
;
508 /* index value -1 means it tries to loop for a first time */
509 static inline BOOL
iterate_endprefix_index(saxlocator
*This
, const element_entry
*element
, int *i
)
511 if (This
->saxreader
->version
>= MSXML4
)
513 if (*i
== -1) *i
= 0; else ++*i
;
514 return *i
< element
->ns_count
;
518 if (*i
== -1) *i
= element
->ns_count
-1; else --*i
;
523 static BOOL
bstr_pool_insert(struct bstrpool
*pool
, BSTR pool_entry
)
527 pool
->pool
= HeapAlloc(GetProcessHeap(), 0, 16 * sizeof(*pool
->pool
));
534 else if (pool
->index
== pool
->len
)
536 BSTR
*realloc
= HeapReAlloc(GetProcessHeap(), 0, pool
->pool
, pool
->len
* 2 * sizeof(*realloc
));
541 pool
->pool
= realloc
;
545 pool
->pool
[pool
->index
++] = pool_entry
;
549 static void free_bstr_pool(struct bstrpool
*pool
)
553 for (i
= 0; i
< pool
->index
; i
++)
554 SysFreeString(pool
->pool
[i
]);
556 HeapFree(GetProcessHeap(), 0, pool
->pool
);
559 pool
->index
= pool
->len
= 0;
562 static BSTR
bstr_from_xmlCharN(const xmlChar
*buf
, int len
)
570 dLen
= MultiByteToWideChar(CP_UTF8
, 0, (LPCSTR
)buf
, len
, NULL
, 0);
571 if(len
!= -1) dLen
++;
572 bstr
= SysAllocStringLen(NULL
, dLen
-1);
575 MultiByteToWideChar(CP_UTF8
, 0, (LPCSTR
)buf
, len
, bstr
, dLen
);
576 if(len
!= -1) bstr
[dLen
-1] = '\0';
581 static BSTR
QName_from_xmlChar(const xmlChar
*prefix
, const xmlChar
*name
)
586 if(!name
) return NULL
;
588 if(!prefix
|| !*prefix
)
589 return bstr_from_xmlChar(name
);
591 qname
= xmlBuildQName(name
, prefix
, NULL
, 0);
592 bstr
= bstr_from_xmlChar(qname
);
598 static BSTR
pooled_bstr_from_xmlChar(struct bstrpool
*pool
, const xmlChar
*buf
)
600 BSTR pool_entry
= bstr_from_xmlChar(buf
);
602 if (pool_entry
&& !bstr_pool_insert(pool
, pool_entry
))
604 SysFreeString(pool_entry
);
611 static BSTR
pooled_bstr_from_xmlCharN(struct bstrpool
*pool
, const xmlChar
*buf
, int len
)
613 BSTR pool_entry
= bstr_from_xmlCharN(buf
, len
);
615 if (pool_entry
&& !bstr_pool_insert(pool
, pool_entry
))
617 SysFreeString(pool_entry
);
624 static void format_error_message_from_id(saxlocator
*This
, HRESULT hr
)
626 struct saxerrorhandler_iface
*handler
= saxreader_get_errorhandler(This
->saxreader
);
627 xmlStopParser(This
->pParserCtxt
);
630 if (saxreader_has_handler(This
, SAXErrorHandler
))
633 if(!FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM
,
634 NULL
, hr
, 0, msg
, sizeof(msg
), NULL
))
636 FIXME("MSXML errors not yet supported.\n");
640 if(This
->vbInterface
)
642 BSTR bstrMsg
= SysAllocString(msg
);
643 IVBSAXErrorHandler_fatalError(handler
->vbhandler
,
644 &This
->IVBSAXLocator_iface
, &bstrMsg
, hr
);
645 SysFreeString(bstrMsg
);
648 ISAXErrorHandler_fatalError(handler
->handler
,
649 &This
->ISAXLocator_iface
, msg
, hr
);
653 static void update_position(saxlocator
*This
, BOOL fix_column
)
655 const xmlChar
*p
= This
->pParserCtxt
->input
->cur
-1;
657 This
->line
= xmlSAX2GetLineNumber(This
->pParserCtxt
);
661 for(; *p
!='\n' && *p
!='\r' && p
>=This
->pParserCtxt
->input
->base
; p
--)
666 This
->column
= xmlSAX2GetColumnNumber(This
->pParserCtxt
);
670 /*** IVBSAXAttributes interface ***/
671 /*** IUnknown methods ***/
672 static HRESULT WINAPI
ivbsaxattributes_QueryInterface(
673 IVBSAXAttributes
* iface
,
677 saxlocator
*This
= impl_from_IVBSAXAttributes(iface
);
678 TRACE("%p %s %p\n", This
, debugstr_guid(riid
), ppvObject
);
679 return IVBSAXLocator_QueryInterface(&This
->IVBSAXLocator_iface
, riid
, ppvObject
);
682 static ULONG WINAPI
ivbsaxattributes_AddRef(IVBSAXAttributes
* iface
)
684 saxlocator
*This
= impl_from_IVBSAXAttributes(iface
);
685 return ISAXLocator_AddRef(&This
->ISAXLocator_iface
);
688 static ULONG WINAPI
ivbsaxattributes_Release(IVBSAXAttributes
* iface
)
690 saxlocator
*This
= impl_from_IVBSAXAttributes(iface
);
691 return ISAXLocator_Release(&This
->ISAXLocator_iface
);
694 /*** IDispatch methods ***/
695 static HRESULT WINAPI
ivbsaxattributes_GetTypeInfoCount( IVBSAXAttributes
*iface
, UINT
* pctinfo
)
697 saxlocator
*This
= impl_from_IVBSAXAttributes( iface
);
699 TRACE("(%p)->(%p)\n", This
, pctinfo
);
706 static HRESULT WINAPI
ivbsaxattributes_GetTypeInfo(
707 IVBSAXAttributes
*iface
,
708 UINT iTInfo
, LCID lcid
, ITypeInfo
** ppTInfo
)
710 saxlocator
*This
= impl_from_IVBSAXAttributes( iface
);
713 TRACE("(%p)->(%u %u %p)\n", This
, iTInfo
, lcid
, ppTInfo
);
715 hr
= get_typeinfo(IVBSAXAttributes_tid
, ppTInfo
);
720 static HRESULT WINAPI
ivbsaxattributes_GetIDsOfNames(
721 IVBSAXAttributes
*iface
,
728 saxlocator
*This
= impl_from_IVBSAXAttributes( iface
);
732 TRACE("(%p)->(%s %p %u %u %p)\n", This
, debugstr_guid(riid
), rgszNames
, cNames
,
735 if(!rgszNames
|| cNames
== 0 || !rgDispId
)
738 hr
= get_typeinfo(IVBSAXAttributes_tid
, &typeinfo
);
741 hr
= ITypeInfo_GetIDsOfNames(typeinfo
, rgszNames
, cNames
, rgDispId
);
742 ITypeInfo_Release(typeinfo
);
748 static HRESULT WINAPI
ivbsaxattributes_Invoke(
749 IVBSAXAttributes
*iface
,
754 DISPPARAMS
* pDispParams
,
756 EXCEPINFO
* pExcepInfo
,
759 saxlocator
*This
= impl_from_IVBSAXAttributes( iface
);
763 TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This
, dispIdMember
, debugstr_guid(riid
),
764 lcid
, wFlags
, pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
766 hr
= get_typeinfo(IVBSAXAttributes_tid
, &typeinfo
);
769 hr
= ITypeInfo_Invoke(typeinfo
, &This
->IVBSAXAttributes_iface
, dispIdMember
, wFlags
,
770 pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
771 ITypeInfo_Release(typeinfo
);
777 /*** IVBSAXAttributes methods ***/
778 static HRESULT WINAPI
ivbsaxattributes_get_length(
779 IVBSAXAttributes
* iface
,
782 saxlocator
*This
= impl_from_IVBSAXAttributes( iface
);
783 return ISAXAttributes_getLength(&This
->ISAXAttributes_iface
, nLength
);
786 static HRESULT WINAPI
ivbsaxattributes_getURI(
787 IVBSAXAttributes
* iface
,
792 saxlocator
*This
= impl_from_IVBSAXAttributes( iface
);
793 return ISAXAttributes_getURI(&This
->ISAXAttributes_iface
, nIndex
, (const WCHAR
**)uri
, &len
);
796 static HRESULT WINAPI
ivbsaxattributes_getLocalName(
797 IVBSAXAttributes
* iface
,
802 saxlocator
*This
= impl_from_IVBSAXAttributes( iface
);
803 return ISAXAttributes_getLocalName(&This
->ISAXAttributes_iface
, nIndex
,
804 (const WCHAR
**)localName
, &len
);
807 static HRESULT WINAPI
ivbsaxattributes_getQName(
808 IVBSAXAttributes
* iface
,
813 saxlocator
*This
= impl_from_IVBSAXAttributes( iface
);
814 return ISAXAttributes_getQName(&This
->ISAXAttributes_iface
, nIndex
, (const WCHAR
**)QName
, &len
);
817 static HRESULT WINAPI
ivbsaxattributes_getIndexFromName(
818 IVBSAXAttributes
* iface
,
823 saxlocator
*This
= impl_from_IVBSAXAttributes( iface
);
824 return ISAXAttributes_getIndexFromName(&This
->ISAXAttributes_iface
, uri
, SysStringLen(uri
),
825 localName
, SysStringLen(localName
), index
);
828 static HRESULT WINAPI
ivbsaxattributes_getIndexFromQName(
829 IVBSAXAttributes
* iface
,
833 saxlocator
*This
= impl_from_IVBSAXAttributes( iface
);
834 return ISAXAttributes_getIndexFromQName(&This
->ISAXAttributes_iface
, QName
,
835 SysStringLen(QName
), index
);
838 static HRESULT WINAPI
ivbsaxattributes_getType(
839 IVBSAXAttributes
* iface
,
844 saxlocator
*This
= impl_from_IVBSAXAttributes( iface
);
845 return ISAXAttributes_getType(&This
->ISAXAttributes_iface
, nIndex
, (const WCHAR
**)type
, &len
);
848 static HRESULT WINAPI
ivbsaxattributes_getTypeFromName(
849 IVBSAXAttributes
* iface
,
855 saxlocator
*This
= impl_from_IVBSAXAttributes( iface
);
856 return ISAXAttributes_getTypeFromName(&This
->ISAXAttributes_iface
, uri
, SysStringLen(uri
),
857 localName
, SysStringLen(localName
), (const WCHAR
**)type
, &len
);
860 static HRESULT WINAPI
ivbsaxattributes_getTypeFromQName(
861 IVBSAXAttributes
* iface
,
866 saxlocator
*This
= impl_from_IVBSAXAttributes( iface
);
867 return ISAXAttributes_getTypeFromQName(&This
->ISAXAttributes_iface
, QName
, SysStringLen(QName
),
868 (const WCHAR
**)type
, &len
);
871 static HRESULT WINAPI
ivbsaxattributes_getValue(
872 IVBSAXAttributes
* iface
,
877 saxlocator
*This
= impl_from_IVBSAXAttributes( iface
);
878 return ISAXAttributes_getValue(&This
->ISAXAttributes_iface
, nIndex
, (const WCHAR
**)value
, &len
);
881 static HRESULT WINAPI
ivbsaxattributes_getValueFromName(
882 IVBSAXAttributes
* iface
,
888 saxlocator
*This
= impl_from_IVBSAXAttributes( iface
);
889 return ISAXAttributes_getValueFromName(&This
->ISAXAttributes_iface
, uri
, SysStringLen(uri
),
890 localName
, SysStringLen(localName
), (const WCHAR
**)value
, &len
);
893 static HRESULT WINAPI
ivbsaxattributes_getValueFromQName(
894 IVBSAXAttributes
* iface
,
899 saxlocator
*This
= impl_from_IVBSAXAttributes( iface
);
900 return ISAXAttributes_getValueFromQName(&This
->ISAXAttributes_iface
, QName
,
901 SysStringLen(QName
), (const WCHAR
**)value
, &len
);
904 static const struct IVBSAXAttributesVtbl ivbsaxattributes_vtbl
=
906 ivbsaxattributes_QueryInterface
,
907 ivbsaxattributes_AddRef
,
908 ivbsaxattributes_Release
,
909 ivbsaxattributes_GetTypeInfoCount
,
910 ivbsaxattributes_GetTypeInfo
,
911 ivbsaxattributes_GetIDsOfNames
,
912 ivbsaxattributes_Invoke
,
913 ivbsaxattributes_get_length
,
914 ivbsaxattributes_getURI
,
915 ivbsaxattributes_getLocalName
,
916 ivbsaxattributes_getQName
,
917 ivbsaxattributes_getIndexFromName
,
918 ivbsaxattributes_getIndexFromQName
,
919 ivbsaxattributes_getType
,
920 ivbsaxattributes_getTypeFromName
,
921 ivbsaxattributes_getTypeFromQName
,
922 ivbsaxattributes_getValue
,
923 ivbsaxattributes_getValueFromName
,
924 ivbsaxattributes_getValueFromQName
927 /*** ISAXAttributes interface ***/
928 /*** IUnknown methods ***/
929 static HRESULT WINAPI
isaxattributes_QueryInterface(
930 ISAXAttributes
* iface
,
934 saxlocator
*This
= impl_from_ISAXAttributes(iface
);
935 TRACE("%p %s %p\n", This
, debugstr_guid(riid
), ppvObject
);
936 return ISAXLocator_QueryInterface(&This
->ISAXLocator_iface
, riid
, ppvObject
);
939 static ULONG WINAPI
isaxattributes_AddRef(ISAXAttributes
* iface
)
941 saxlocator
*This
= impl_from_ISAXAttributes(iface
);
943 return ISAXLocator_AddRef(&This
->ISAXLocator_iface
);
946 static ULONG WINAPI
isaxattributes_Release(ISAXAttributes
* iface
)
948 saxlocator
*This
= impl_from_ISAXAttributes(iface
);
951 return ISAXLocator_Release(&This
->ISAXLocator_iface
);
954 /*** ISAXAttributes methods ***/
955 static HRESULT WINAPI
isaxattributes_getLength(
956 ISAXAttributes
* iface
,
959 saxlocator
*This
= impl_from_ISAXAttributes( iface
);
961 *length
= This
->nb_attributes
;
962 TRACE("Length set to %d\n", *length
);
966 static HRESULT WINAPI
isaxattributes_getURI(
967 ISAXAttributes
* iface
,
972 saxlocator
*This
= impl_from_ISAXAttributes( iface
);
973 TRACE("(%p)->(%d)\n", This
, index
);
975 if(index
>= This
->nb_attributes
|| index
< 0) return E_INVALIDARG
;
976 if(!url
|| !size
) return E_POINTER
;
978 *size
= SysStringLen(This
->attributes
[index
].szURI
);
979 *url
= This
->attributes
[index
].szURI
;
981 TRACE("(%s:%d)\n", debugstr_w(This
->attributes
[index
].szURI
), *size
);
986 static HRESULT WINAPI
isaxattributes_getLocalName(
987 ISAXAttributes
* iface
,
989 const WCHAR
**pLocalName
,
990 int *pLocalNameLength
)
992 saxlocator
*This
= impl_from_ISAXAttributes( iface
);
993 TRACE("(%p)->(%d)\n", This
, nIndex
);
995 if(nIndex
>=This
->nb_attributes
|| nIndex
<0) return E_INVALIDARG
;
996 if(!pLocalName
|| !pLocalNameLength
) return E_POINTER
;
998 *pLocalNameLength
= SysStringLen(This
->attributes
[nIndex
].szLocalname
);
999 *pLocalName
= This
->attributes
[nIndex
].szLocalname
;
1004 static HRESULT WINAPI
isaxattributes_getQName(
1005 ISAXAttributes
* iface
,
1007 const WCHAR
**pQName
,
1010 saxlocator
*This
= impl_from_ISAXAttributes( iface
);
1011 TRACE("(%p)->(%d)\n", This
, nIndex
);
1013 if(nIndex
>=This
->nb_attributes
|| nIndex
<0) return E_INVALIDARG
;
1014 if(!pQName
|| !pQNameLength
) return E_POINTER
;
1016 *pQNameLength
= SysStringLen(This
->attributes
[nIndex
].szQName
);
1017 *pQName
= This
->attributes
[nIndex
].szQName
;
1022 static HRESULT WINAPI
isaxattributes_getName(
1023 ISAXAttributes
* iface
,
1027 const WCHAR
**localName
,
1028 int *pLocalNameSize
,
1029 const WCHAR
**QName
,
1032 saxlocator
*This
= impl_from_ISAXAttributes( iface
);
1033 TRACE("(%p)->(%d)\n", This
, index
);
1035 if(index
>=This
->nb_attributes
|| index
<0) return E_INVALIDARG
;
1036 if(!uri
|| !pUriLength
|| !localName
|| !pLocalNameSize
1037 || !QName
|| !pQNameLength
) return E_POINTER
;
1039 *pUriLength
= SysStringLen(This
->attributes
[index
].szURI
);
1040 *uri
= This
->attributes
[index
].szURI
;
1041 *pLocalNameSize
= SysStringLen(This
->attributes
[index
].szLocalname
);
1042 *localName
= This
->attributes
[index
].szLocalname
;
1043 *pQNameLength
= SysStringLen(This
->attributes
[index
].szQName
);
1044 *QName
= This
->attributes
[index
].szQName
;
1046 TRACE("(%s, %s, %s)\n", debugstr_w(*uri
), debugstr_w(*localName
), debugstr_w(*QName
));
1051 static HRESULT WINAPI
isaxattributes_getIndexFromName(
1052 ISAXAttributes
* iface
,
1055 const WCHAR
*pLocalName
,
1056 int cocalNameLength
,
1059 saxlocator
*This
= impl_from_ISAXAttributes( iface
);
1061 TRACE("(%p)->(%s, %d, %s, %d)\n", This
, debugstr_w(pUri
), cUriLength
,
1062 debugstr_w(pLocalName
), cocalNameLength
);
1064 if(!pUri
|| !pLocalName
|| !index
) return E_POINTER
;
1066 for(i
=0; i
<This
->nb_attributes
; i
++)
1068 if(cUriLength
!=SysStringLen(This
->attributes
[i
].szURI
)
1069 || cocalNameLength
!=SysStringLen(This
->attributes
[i
].szLocalname
))
1071 if(cUriLength
&& memcmp(pUri
, This
->attributes
[i
].szURI
,
1072 sizeof(WCHAR
)*cUriLength
))
1074 if(cocalNameLength
&& memcmp(pLocalName
, This
->attributes
[i
].szLocalname
,
1075 sizeof(WCHAR
)*cocalNameLength
))
1082 return E_INVALIDARG
;
1085 static HRESULT WINAPI
isaxattributes_getIndexFromQName(
1086 ISAXAttributes
* iface
,
1087 const WCHAR
*pQName
,
1091 saxlocator
*This
= impl_from_ISAXAttributes( iface
);
1093 TRACE("(%p)->(%s, %d)\n", This
, debugstr_w(pQName
), nQNameLength
);
1095 if(!pQName
|| !index
) return E_POINTER
;
1096 if(!nQNameLength
) return E_INVALIDARG
;
1098 for(i
=0; i
<This
->nb_attributes
; i
++)
1100 if(nQNameLength
!=SysStringLen(This
->attributes
[i
].szQName
)) continue;
1101 if(memcmp(pQName
, This
->attributes
[i
].szQName
, sizeof(WCHAR
)*nQNameLength
)) continue;
1107 return E_INVALIDARG
;
1110 static HRESULT WINAPI
isaxattributes_getType(
1111 ISAXAttributes
* iface
,
1113 const WCHAR
**pType
,
1116 saxlocator
*This
= impl_from_ISAXAttributes( iface
);
1118 FIXME("(%p)->(%d) stub\n", This
, nIndex
);
1122 static HRESULT WINAPI
isaxattributes_getTypeFromName(
1123 ISAXAttributes
* iface
,
1126 const WCHAR
*pLocalName
,
1128 const WCHAR
**pType
,
1131 saxlocator
*This
= impl_from_ISAXAttributes( iface
);
1133 FIXME("(%p)->(%s, %d, %s, %d) stub\n", This
, debugstr_w(pUri
), nUri
,
1134 debugstr_w(pLocalName
), nLocalName
);
1138 static HRESULT WINAPI
isaxattributes_getTypeFromQName(
1139 ISAXAttributes
* iface
,
1140 const WCHAR
*pQName
,
1142 const WCHAR
**pType
,
1145 saxlocator
*This
= impl_from_ISAXAttributes( iface
);
1147 FIXME("(%p)->(%s, %d) stub\n", This
, debugstr_w(pQName
), nQName
);
1151 static HRESULT WINAPI
isaxattributes_getValue(
1152 ISAXAttributes
* iface
,
1154 const WCHAR
**value
,
1157 saxlocator
*This
= impl_from_ISAXAttributes( iface
);
1158 TRACE("(%p)->(%d)\n", This
, index
);
1160 if(index
>=This
->nb_attributes
|| index
<0) return E_INVALIDARG
;
1161 if(!value
|| !nValue
) return E_POINTER
;
1163 *nValue
= SysStringLen(This
->attributes
[index
].szValue
);
1164 *value
= This
->attributes
[index
].szValue
;
1166 TRACE("(%s:%d)\n", debugstr_w(*value
), *nValue
);
1171 static HRESULT WINAPI
isaxattributes_getValueFromName(
1172 ISAXAttributes
* iface
,
1175 const WCHAR
*pLocalName
,
1177 const WCHAR
**pValue
,
1182 saxlocator
*This
= impl_from_ISAXAttributes( iface
);
1183 TRACE("(%p)->(%s, %d, %s, %d)\n", This
, debugstr_w(pUri
), nUri
,
1184 debugstr_w(pLocalName
), nLocalName
);
1186 hr
= ISAXAttributes_getIndexFromName(iface
,
1187 pUri
, nUri
, pLocalName
, nLocalName
, &index
);
1188 if(hr
==S_OK
) hr
= ISAXAttributes_getValue(iface
, index
, pValue
, nValue
);
1193 static HRESULT WINAPI
isaxattributes_getValueFromQName(
1194 ISAXAttributes
* iface
,
1195 const WCHAR
*pQName
,
1197 const WCHAR
**pValue
,
1202 saxlocator
*This
= impl_from_ISAXAttributes( iface
);
1203 TRACE("(%p)->(%s, %d)\n", This
, debugstr_w(pQName
), nQName
);
1205 hr
= ISAXAttributes_getIndexFromQName(iface
, pQName
, nQName
, &index
);
1206 if(hr
==S_OK
) hr
= ISAXAttributes_getValue(iface
, index
, pValue
, nValue
);
1211 static const struct ISAXAttributesVtbl isaxattributes_vtbl
=
1213 isaxattributes_QueryInterface
,
1214 isaxattributes_AddRef
,
1215 isaxattributes_Release
,
1216 isaxattributes_getLength
,
1217 isaxattributes_getURI
,
1218 isaxattributes_getLocalName
,
1219 isaxattributes_getQName
,
1220 isaxattributes_getName
,
1221 isaxattributes_getIndexFromName
,
1222 isaxattributes_getIndexFromQName
,
1223 isaxattributes_getType
,
1224 isaxattributes_getTypeFromName
,
1225 isaxattributes_getTypeFromQName
,
1226 isaxattributes_getValue
,
1227 isaxattributes_getValueFromName
,
1228 isaxattributes_getValueFromQName
1231 static HRESULT
SAXAttributes_populate(saxlocator
*locator
,
1232 int nb_namespaces
, const xmlChar
**xmlNamespaces
,
1233 int nb_attributes
, const xmlChar
**xmlAttributes
)
1235 static const xmlChar xmlns
[] = "xmlns";
1236 static const WCHAR xmlnsW
[] = { 'x','m','l','n','s',0 };
1238 struct _attributes
*attrs
;
1241 /* skip namespace definitions */
1242 if ((locator
->saxreader
->features
& NamespacePrefixes
) == 0)
1245 locator
->nb_attributes
= nb_namespaces
+ nb_attributes
;
1246 if(locator
->nb_attributes
> locator
->attributesSize
)
1248 attrs
= heap_realloc(locator
->attributes
, sizeof(struct _attributes
)*locator
->nb_attributes
*2);
1251 locator
->nb_attributes
= 0;
1252 return E_OUTOFMEMORY
;
1254 locator
->attributes
= attrs
;
1258 attrs
= locator
->attributes
;
1261 for (i
= 0; i
< nb_namespaces
; i
++)
1263 attrs
[nb_attributes
+i
].szLocalname
= SysAllocStringLen(NULL
, 0);
1264 attrs
[nb_attributes
+i
].szURI
= locator
->namespaceUri
;
1265 attrs
[nb_attributes
+i
].szValue
= bstr_from_xmlChar(xmlNamespaces
[2*i
+1]);
1266 if(!xmlNamespaces
[2*i
])
1267 attrs
[nb_attributes
+i
].szQName
= SysAllocString(xmlnsW
);
1269 attrs
[nb_attributes
+i
].szQName
= QName_from_xmlChar(xmlns
, xmlNamespaces
[2*i
]);
1272 for (i
= 0; i
< nb_attributes
; i
++)
1274 static const xmlChar xmlA
[] = "xml";
1276 if (xmlStrEqual(xmlAttributes
[i
*5+1], xmlA
))
1277 attrs
[i
].szURI
= bstr_from_xmlChar(xmlAttributes
[i
*5+2]);
1279 /* that's an important feature to keep same uri pointer for every reported attribute */
1280 attrs
[i
].szURI
= find_element_uri(locator
, xmlAttributes
[i
*5+2]);
1282 attrs
[i
].szLocalname
= bstr_from_xmlChar(xmlAttributes
[i
*5]);
1283 attrs
[i
].szValue
= bstr_from_xmlCharN(xmlAttributes
[i
*5+3],
1284 xmlAttributes
[i
*5+4]-xmlAttributes
[i
*5+3]);
1285 attrs
[i
].szQName
= QName_from_xmlChar(xmlAttributes
[i
*5+1],
1286 xmlAttributes
[i
*5]);
1292 /*** LibXML callbacks ***/
1293 static void libxmlStartDocument(void *ctx
)
1295 saxlocator
*This
= ctx
;
1296 struct saxcontenthandler_iface
*handler
= saxreader_get_contenthandler(This
->saxreader
);
1299 if (This
->saxreader
->version
>= MSXML4
)
1301 const xmlChar
*p
= This
->pParserCtxt
->input
->cur
-1;
1302 update_position(This
, FALSE
);
1303 while(p
>This
->pParserCtxt
->input
->base
&& *p
!='>')
1305 if(*p
=='\n' || (*p
=='\r' && *(p
+1)!='\n'))
1310 for(; p
>=This
->pParserCtxt
->input
->base
&& *p
!='\n' && *p
!='\r'; p
--)
1314 if (saxreader_has_handler(This
, SAXContentHandler
))
1316 if(This
->vbInterface
)
1317 hr
= IVBSAXContentHandler_startDocument(handler
->vbhandler
);
1319 hr
= ISAXContentHandler_startDocument(handler
->handler
);
1321 if (sax_callback_failed(This
, hr
))
1322 format_error_message_from_id(This
, hr
);
1326 static void libxmlEndDocument(void *ctx
)
1328 saxlocator
*This
= ctx
;
1329 struct saxcontenthandler_iface
*handler
= saxreader_get_contenthandler(This
->saxreader
);
1332 if (This
->saxreader
->version
>= MSXML4
) {
1333 update_position(This
, FALSE
);
1334 if(This
->column
> 1)
1342 if(This
->ret
!= S_OK
) return;
1344 if (saxreader_has_handler(This
, SAXContentHandler
))
1346 if(This
->vbInterface
)
1347 hr
= IVBSAXContentHandler_endDocument(handler
->vbhandler
);
1349 hr
= ISAXContentHandler_endDocument(handler
->handler
);
1351 if (sax_callback_failed(This
, hr
))
1352 format_error_message_from_id(This
, hr
);
1356 static void libxmlStartElementNS(
1358 const xmlChar
*localname
,
1359 const xmlChar
*prefix
,
1362 const xmlChar
**namespaces
,
1365 const xmlChar
**attributes
)
1367 saxlocator
*This
= ctx
;
1368 struct saxcontenthandler_iface
*handler
= saxreader_get_contenthandler(This
->saxreader
);
1369 element_entry
*element
;
1373 update_position(This
, TRUE
);
1374 if(*(This
->pParserCtxt
->input
->cur
) == '/')
1376 if(This
->saxreader
->version
< MSXML4
)
1379 element
= alloc_element_entry(localname
, prefix
, nb_namespaces
, namespaces
);
1380 push_element_ns(This
, element
);
1382 if (is_namespaces_enabled(This
->saxreader
))
1386 for (i
= 0; i
< nb_namespaces
&& saxreader_has_handler(This
, SAXContentHandler
); i
++)
1388 if (This
->vbInterface
)
1389 hr
= IVBSAXContentHandler_startPrefixMapping(
1391 &element
->ns
[i
].prefix
,
1392 &element
->ns
[i
].uri
);
1394 hr
= ISAXContentHandler_startPrefixMapping(
1396 element
->ns
[i
].prefix
,
1397 SysStringLen(element
->ns
[i
].prefix
),
1399 SysStringLen(element
->ns
[i
].uri
));
1401 if (sax_callback_failed(This
, hr
))
1403 format_error_message_from_id(This
, hr
);
1409 uri
= find_element_uri(This
, URI
);
1410 hr
= SAXAttributes_populate(This
, nb_namespaces
, namespaces
, nb_attributes
, attributes
);
1411 if (hr
== S_OK
&& saxreader_has_handler(This
, SAXContentHandler
))
1415 if (is_namespaces_enabled(This
->saxreader
))
1416 local
= element
->local
;
1420 if (This
->vbInterface
)
1421 hr
= IVBSAXContentHandler_startElement(handler
->vbhandler
,
1422 &uri
, &local
, &element
->qname
, &This
->IVBSAXAttributes_iface
);
1424 hr
= ISAXContentHandler_startElement(handler
->handler
,
1425 uri
, SysStringLen(uri
),
1426 local
, SysStringLen(local
),
1427 element
->qname
, SysStringLen(element
->qname
),
1428 &This
->ISAXAttributes_iface
);
1430 if (sax_callback_failed(This
, hr
))
1431 format_error_message_from_id(This
, hr
);
1435 static void libxmlEndElementNS(
1437 const xmlChar
*localname
,
1438 const xmlChar
*prefix
,
1441 saxlocator
*This
= ctx
;
1442 struct saxcontenthandler_iface
*handler
= saxreader_get_contenthandler(This
->saxreader
);
1443 element_entry
*element
;
1448 update_position(This
, FALSE
);
1449 p
= This
->pParserCtxt
->input
->cur
;
1451 if (This
->saxreader
->version
>= MSXML4
)
1454 while(p
>This
->pParserCtxt
->input
->base
&& *p
!='>')
1456 if(*p
=='\n' || (*p
=='\r' && *(p
+1)!='\n'))
1461 else if(*(p
-1)!='>' || *(p
-2)!='/')
1464 while(p
-2>=This
->pParserCtxt
->input
->base
1465 && *(p
-2)!='<' && *(p
-1)!='/')
1467 if(*p
=='\n' || (*p
=='\r' && *(p
+1)!='\n'))
1473 for(; p
>=This
->pParserCtxt
->input
->base
&& *p
!='\n' && *p
!='\r'; p
--)
1476 uri
= find_element_uri(This
, URI
);
1477 element
= pop_element_ns(This
);
1479 if (!saxreader_has_handler(This
, SAXContentHandler
))
1481 This
->nb_attributes
= 0;
1482 free_element_entry(element
);
1486 if (is_namespaces_enabled(This
->saxreader
))
1487 local
= element
->local
;
1491 if (This
->vbInterface
)
1492 hr
= IVBSAXContentHandler_endElement(
1494 &uri
, &local
, &element
->qname
);
1496 hr
= ISAXContentHandler_endElement(
1498 uri
, SysStringLen(uri
),
1499 local
, SysStringLen(local
),
1500 element
->qname
, SysStringLen(element
->qname
));
1502 This
->nb_attributes
= 0;
1504 if (sax_callback_failed(This
, hr
))
1506 format_error_message_from_id(This
, hr
);
1507 free_element_entry(element
);
1511 if (is_namespaces_enabled(This
->saxreader
))
1514 while (iterate_endprefix_index(This
, element
, &i
) && saxreader_has_handler(This
, SAXContentHandler
))
1516 if (This
->vbInterface
)
1517 hr
= IVBSAXContentHandler_endPrefixMapping(
1518 handler
->vbhandler
, &element
->ns
[i
].prefix
);
1520 hr
= ISAXContentHandler_endPrefixMapping(
1521 handler
->handler
, element
->ns
[i
].prefix
, SysStringLen(element
->ns
[i
].prefix
));
1523 if (sax_callback_failed(This
, hr
)) break;
1526 if (sax_callback_failed(This
, hr
))
1527 format_error_message_from_id(This
, hr
);
1530 free_element_entry(element
);
1533 static void libxmlCharacters(
1538 saxlocator
*This
= ctx
;
1539 struct saxcontenthandler_iface
*handler
= saxreader_get_contenthandler(This
->saxreader
);
1543 BOOL lastEvent
= FALSE
;
1545 if (!saxreader_has_handler(This
, SAXContentHandler
)) return;
1547 update_position(This
, FALSE
);
1548 cur
= (xmlChar
*)This
->pParserCtxt
->input
->cur
;
1549 while(cur
>=This
->pParserCtxt
->input
->base
&& *cur
!='>')
1551 if(*cur
=='\n' || (*cur
=='\r' && *(cur
+1)!='\n'))
1556 for(; cur
>=This
->pParserCtxt
->input
->base
&& *cur
!='\n' && *cur
!='\r'; cur
--)
1560 if(*(ch
-1)=='\r') cur
--;
1565 while(end
-ch
<len
&& *end
!='\r') end
++;
1576 if (This
->saxreader
->version
>= MSXML4
)
1580 for(p
=cur
; p
!=end
; p
++)
1597 Chars
= pooled_bstr_from_xmlCharN(&This
->saxreader
->pool
, cur
, end
-cur
);
1598 if(This
->vbInterface
)
1599 hr
= IVBSAXContentHandler_characters(handler
->vbhandler
, &Chars
);
1601 hr
= ISAXContentHandler_characters(handler
->handler
, Chars
, SysStringLen(Chars
));
1603 if (sax_callback_failed(This
, hr
))
1605 format_error_message_from_id(This
, hr
);
1609 if (This
->saxreader
->version
< MSXML4
)
1610 This
->column
+= end
-cur
;
1623 if(end
-ch
== len
) break;
1627 static void libxmlSetDocumentLocator(
1629 xmlSAXLocatorPtr loc
)
1631 saxlocator
*This
= ctx
;
1632 struct saxcontenthandler_iface
*handler
= saxreader_get_contenthandler(This
->saxreader
);
1635 if (saxreader_has_handler(This
, SAXContentHandler
))
1637 if(This
->vbInterface
)
1638 hr
= IVBSAXContentHandler_putref_documentLocator(handler
->vbhandler
,
1639 &This
->IVBSAXLocator_iface
);
1641 hr
= ISAXContentHandler_putDocumentLocator(handler
->handler
, &This
->ISAXLocator_iface
);
1645 format_error_message_from_id(This
, hr
);
1648 static void libxmlComment(void *ctx
, const xmlChar
*value
)
1650 saxlocator
*This
= ctx
;
1651 struct saxlexicalhandler_iface
*handler
= saxreader_get_lexicalhandler(This
->saxreader
);
1654 const xmlChar
*p
= This
->pParserCtxt
->input
->cur
;
1656 update_position(This
, FALSE
);
1657 while(p
-4>=This
->pParserCtxt
->input
->base
1658 && memcmp(p
-4, "<!--", sizeof(char[4])))
1660 if(*p
=='\n' || (*p
=='\r' && *(p
+1)!='\n'))
1666 for(; p
>=This
->pParserCtxt
->input
->base
&& *p
!='\n' && *p
!='\r'; p
--)
1669 if (!saxreader_has_handler(This
, SAXLexicalHandler
)) return;
1671 bValue
= pooled_bstr_from_xmlChar(&This
->saxreader
->pool
, value
);
1673 if (This
->vbInterface
)
1674 hr
= IVBSAXLexicalHandler_comment(handler
->vbhandler
, &bValue
);
1676 hr
= ISAXLexicalHandler_comment(handler
->handler
, bValue
, SysStringLen(bValue
));
1679 format_error_message_from_id(This
, hr
);
1682 static void libxmlFatalError(void *ctx
, const char *msg
, ...)
1684 saxlocator
*This
= ctx
;
1685 struct saxerrorhandler_iface
*handler
= saxreader_get_errorhandler(This
->saxreader
);
1691 if(This
->ret
!= S_OK
) {
1692 xmlStopParser(This
->pParserCtxt
);
1696 va_start(args
, msg
);
1697 vsprintf(message
, msg
, args
);
1700 len
= MultiByteToWideChar(CP_UNIXCP
, 0, message
, -1, NULL
, 0);
1701 error
= heap_alloc(sizeof(WCHAR
)*len
);
1704 MultiByteToWideChar(CP_UNIXCP
, 0, message
, -1, error
, len
);
1705 TRACE("fatal error for %p: %s\n", This
, debugstr_w(error
));
1708 if (!saxreader_has_handler(This
, SAXErrorHandler
))
1710 xmlStopParser(This
->pParserCtxt
);
1716 FIXME("Error handling is not compatible.\n");
1718 if(This
->vbInterface
)
1720 BSTR bstrError
= SysAllocString(error
);
1721 IVBSAXErrorHandler_fatalError(handler
->vbhandler
, &This
->IVBSAXLocator_iface
,
1722 &bstrError
, E_FAIL
);
1723 SysFreeString(bstrError
);
1726 ISAXErrorHandler_fatalError(handler
->handler
, &This
->ISAXLocator_iface
, error
, E_FAIL
);
1730 xmlStopParser(This
->pParserCtxt
);
1734 static void libxmlCDataBlock(void *ctx
, const xmlChar
*value
, int len
)
1736 saxlocator
*This
= ctx
;
1737 struct saxcontenthandler_iface
*content
= saxreader_get_contenthandler(This
->saxreader
);
1738 struct saxlexicalhandler_iface
*lexical
= saxreader_get_lexicalhandler(This
->saxreader
);
1740 xmlChar
*beg
= (xmlChar
*)This
->pParserCtxt
->input
->cur
-len
;
1744 BOOL lastEvent
= FALSE
, change
;
1746 update_position(This
, FALSE
);
1747 while(beg
-9>=This
->pParserCtxt
->input
->base
1748 && memcmp(beg
-9, "<![CDATA[", sizeof(char[9])))
1750 if(*beg
=='\n' || (*beg
=='\r' && *(beg
+1)!='\n'))
1755 for(; beg
>=This
->pParserCtxt
->input
->base
&& *beg
!='\n' && *beg
!='\r'; beg
--)
1758 if (saxreader_has_handler(This
, SAXLexicalHandler
))
1760 if (This
->vbInterface
)
1761 hr
= IVBSAXLexicalHandler_startCDATA(lexical
->vbhandler
);
1763 hr
= ISAXLexicalHandler_startCDATA(lexical
->handler
);
1768 format_error_message_from_id(This
, hr
);
1772 realLen
= This
->pParserCtxt
->input
->cur
-beg
-3;
1778 while(end
-beg
<realLen
&& *end
!='\r') end
++;
1779 if(end
-beg
==realLen
)
1784 else if(end
-beg
==realLen
-1 && *end
=='\r' && *(end
+1)=='\n')
1787 if(*end
== '\r') change
= TRUE
;
1788 else change
= FALSE
;
1790 if(change
) *end
= '\n';
1792 if (saxreader_has_handler(This
, SAXContentHandler
))
1794 Chars
= pooled_bstr_from_xmlCharN(&This
->saxreader
->pool
, cur
, end
-cur
+1);
1795 if (This
->vbInterface
)
1796 hr
= IVBSAXContentHandler_characters(content
->vbhandler
, &Chars
);
1798 hr
= ISAXContentHandler_characters(content
->handler
, Chars
, SysStringLen(Chars
));
1801 if(change
) *end
= '\r';
1806 This
->column
+= end
-cur
+2;
1811 if (saxreader_has_handler(This
, SAXLexicalHandler
))
1813 if (This
->vbInterface
)
1814 hr
= IVBSAXLexicalHandler_endCDATA(lexical
->vbhandler
);
1816 hr
= ISAXLexicalHandler_endCDATA(lexical
->handler
);
1820 format_error_message_from_id(This
, hr
);
1822 This
->column
+= 4+end
-cur
;
1825 /*** IVBSAXLocator interface ***/
1826 /*** IUnknown methods ***/
1827 static HRESULT WINAPI
ivbsaxlocator_QueryInterface(IVBSAXLocator
* iface
, REFIID riid
, void **ppvObject
)
1829 saxlocator
*This
= impl_from_IVBSAXLocator( iface
);
1831 TRACE("%p %s %p\n", This
, debugstr_guid( riid
), ppvObject
);
1835 if ( IsEqualGUID( riid
, &IID_IUnknown
) ||
1836 IsEqualGUID( riid
, &IID_IDispatch
) ||
1837 IsEqualGUID( riid
, &IID_IVBSAXLocator
))
1841 else if ( IsEqualGUID( riid
, &IID_IVBSAXAttributes
))
1843 *ppvObject
= &This
->IVBSAXAttributes_iface
;
1847 FIXME("interface %s not implemented\n", debugstr_guid(riid
));
1848 return E_NOINTERFACE
;
1851 IVBSAXLocator_AddRef( iface
);
1856 static ULONG WINAPI
ivbsaxlocator_AddRef(IVBSAXLocator
* iface
)
1858 saxlocator
*This
= impl_from_IVBSAXLocator( iface
);
1859 TRACE("%p\n", This
);
1860 return InterlockedIncrement( &This
->ref
);
1863 static ULONG WINAPI
ivbsaxlocator_Release(
1864 IVBSAXLocator
* iface
)
1866 saxlocator
*This
= impl_from_IVBSAXLocator( iface
);
1867 return ISAXLocator_Release((ISAXLocator
*)&This
->IVBSAXLocator_iface
);
1870 /*** IDispatch methods ***/
1871 static HRESULT WINAPI
ivbsaxlocator_GetTypeInfoCount( IVBSAXLocator
*iface
, UINT
* pctinfo
)
1873 saxlocator
*This
= impl_from_IVBSAXLocator( iface
);
1875 TRACE("(%p)->(%p)\n", This
, pctinfo
);
1882 static HRESULT WINAPI
ivbsaxlocator_GetTypeInfo(
1883 IVBSAXLocator
*iface
,
1884 UINT iTInfo
, LCID lcid
, ITypeInfo
** ppTInfo
)
1886 saxlocator
*This
= impl_from_IVBSAXLocator( iface
);
1889 TRACE("(%p)->(%u %u %p)\n", This
, iTInfo
, lcid
, ppTInfo
);
1891 hr
= get_typeinfo(IVBSAXLocator_tid
, ppTInfo
);
1896 static HRESULT WINAPI
ivbsaxlocator_GetIDsOfNames(
1897 IVBSAXLocator
*iface
,
1899 LPOLESTR
* rgszNames
,
1904 saxlocator
*This
= impl_from_IVBSAXLocator( iface
);
1905 ITypeInfo
*typeinfo
;
1908 TRACE("(%p)->(%s %p %u %u %p)\n", This
, debugstr_guid(riid
), rgszNames
, cNames
,
1911 if(!rgszNames
|| cNames
== 0 || !rgDispId
)
1912 return E_INVALIDARG
;
1914 hr
= get_typeinfo(IVBSAXLocator_tid
, &typeinfo
);
1917 hr
= ITypeInfo_GetIDsOfNames(typeinfo
, rgszNames
, cNames
, rgDispId
);
1918 ITypeInfo_Release(typeinfo
);
1924 static HRESULT WINAPI
ivbsaxlocator_Invoke(
1925 IVBSAXLocator
*iface
,
1926 DISPID dispIdMember
,
1930 DISPPARAMS
* pDispParams
,
1931 VARIANT
* pVarResult
,
1932 EXCEPINFO
* pExcepInfo
,
1935 saxlocator
*This
= impl_from_IVBSAXLocator( iface
);
1936 ITypeInfo
*typeinfo
;
1939 TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This
, dispIdMember
, debugstr_guid(riid
),
1940 lcid
, wFlags
, pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
1942 hr
= get_typeinfo(IVBSAXLocator_tid
, &typeinfo
);
1945 hr
= ITypeInfo_Invoke(typeinfo
, &This
->IVBSAXLocator_iface
, dispIdMember
, wFlags
,
1946 pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
1947 ITypeInfo_Release(typeinfo
);
1953 /*** IVBSAXLocator methods ***/
1954 static HRESULT WINAPI
ivbsaxlocator_get_columnNumber(
1955 IVBSAXLocator
* iface
,
1958 saxlocator
*This
= impl_from_IVBSAXLocator( iface
);
1959 return ISAXLocator_getColumnNumber((ISAXLocator
*)&This
->IVBSAXLocator_iface
, pnColumn
);
1962 static HRESULT WINAPI
ivbsaxlocator_get_lineNumber(
1963 IVBSAXLocator
* iface
,
1966 saxlocator
*This
= impl_from_IVBSAXLocator( iface
);
1967 return ISAXLocator_getLineNumber((ISAXLocator
*)&This
->IVBSAXLocator_iface
, pnLine
);
1970 static HRESULT WINAPI
ivbsaxlocator_get_publicId(
1971 IVBSAXLocator
* iface
,
1974 saxlocator
*This
= impl_from_IVBSAXLocator( iface
);
1975 return ISAXLocator_getPublicId((ISAXLocator
*)&This
->IVBSAXLocator_iface
,
1976 (const WCHAR
**)publicId
);
1979 static HRESULT WINAPI
ivbsaxlocator_get_systemId(
1980 IVBSAXLocator
* iface
,
1983 saxlocator
*This
= impl_from_IVBSAXLocator( iface
);
1984 return ISAXLocator_getSystemId((ISAXLocator
*)&This
->IVBSAXLocator_iface
,
1985 (const WCHAR
**)systemId
);
1988 static const struct IVBSAXLocatorVtbl VBSAXLocatorVtbl
=
1990 ivbsaxlocator_QueryInterface
,
1991 ivbsaxlocator_AddRef
,
1992 ivbsaxlocator_Release
,
1993 ivbsaxlocator_GetTypeInfoCount
,
1994 ivbsaxlocator_GetTypeInfo
,
1995 ivbsaxlocator_GetIDsOfNames
,
1996 ivbsaxlocator_Invoke
,
1997 ivbsaxlocator_get_columnNumber
,
1998 ivbsaxlocator_get_lineNumber
,
1999 ivbsaxlocator_get_publicId
,
2000 ivbsaxlocator_get_systemId
2003 /*** ISAXLocator interface ***/
2004 /*** IUnknown methods ***/
2005 static HRESULT WINAPI
isaxlocator_QueryInterface(ISAXLocator
* iface
, REFIID riid
, void **ppvObject
)
2007 saxlocator
*This
= impl_from_ISAXLocator( iface
);
2009 TRACE("%p %s %p\n", This
, debugstr_guid( riid
), ppvObject
);
2013 if ( IsEqualGUID( riid
, &IID_IUnknown
) ||
2014 IsEqualGUID( riid
, &IID_ISAXLocator
))
2018 else if ( IsEqualGUID( riid
, &IID_ISAXAttributes
))
2020 *ppvObject
= &This
->ISAXAttributes_iface
;
2024 WARN("interface %s not implemented\n", debugstr_guid(riid
));
2025 return E_NOINTERFACE
;
2028 ISAXLocator_AddRef( iface
);
2033 static ULONG WINAPI
isaxlocator_AddRef(ISAXLocator
* iface
)
2035 saxlocator
*This
= impl_from_ISAXLocator( iface
);
2036 ULONG ref
= InterlockedIncrement( &This
->ref
);
2037 TRACE("(%p)->(%d)\n", This
, ref
);
2041 static ULONG WINAPI
isaxlocator_Release(
2044 saxlocator
*This
= impl_from_ISAXLocator( iface
);
2045 LONG ref
= InterlockedDecrement( &This
->ref
);
2047 TRACE("(%p)->(%d)\n", This
, ref
);
2051 element_entry
*element
, *element2
;
2054 SysFreeString(This
->publicId
);
2055 SysFreeString(This
->systemId
);
2056 SysFreeString(This
->namespaceUri
);
2058 for(index
=0; index
<This
->nb_attributes
; index
++)
2060 SysFreeString(This
->attributes
[index
].szLocalname
);
2061 SysFreeString(This
->attributes
[index
].szValue
);
2062 SysFreeString(This
->attributes
[index
].szQName
);
2064 heap_free(This
->attributes
);
2067 LIST_FOR_EACH_ENTRY_SAFE(element
, element2
, &This
->elements
, element_entry
, entry
)
2069 list_remove(&element
->entry
);
2070 free_element_entry(element
);
2073 ISAXXMLReader_Release(&This
->saxreader
->ISAXXMLReader_iface
);
2080 /*** ISAXLocator methods ***/
2081 static HRESULT WINAPI
isaxlocator_getColumnNumber(
2085 saxlocator
*This
= impl_from_ISAXLocator( iface
);
2087 *pnColumn
= This
->column
;
2091 static HRESULT WINAPI
isaxlocator_getLineNumber(
2095 saxlocator
*This
= impl_from_ISAXLocator( iface
);
2097 *pnLine
= This
->line
;
2101 static HRESULT WINAPI
isaxlocator_getPublicId(
2103 const WCHAR
** ppwchPublicId
)
2106 saxlocator
*This
= impl_from_ISAXLocator( iface
);
2108 SysFreeString(This
->publicId
);
2110 publicId
= bstr_from_xmlChar(xmlSAX2GetPublicId(This
->pParserCtxt
));
2111 if(SysStringLen(publicId
))
2112 This
->publicId
= (WCHAR
*)&publicId
;
2115 SysFreeString(publicId
);
2116 This
->publicId
= NULL
;
2119 *ppwchPublicId
= This
->publicId
;
2123 static HRESULT WINAPI
isaxlocator_getSystemId(
2125 const WCHAR
** ppwchSystemId
)
2128 saxlocator
*This
= impl_from_ISAXLocator( iface
);
2130 SysFreeString(This
->systemId
);
2132 systemId
= bstr_from_xmlChar(xmlSAX2GetSystemId(This
->pParserCtxt
));
2133 if(SysStringLen(systemId
))
2134 This
->systemId
= (WCHAR
*)&systemId
;
2137 SysFreeString(systemId
);
2138 This
->systemId
= NULL
;
2141 *ppwchSystemId
= This
->systemId
;
2145 static const struct ISAXLocatorVtbl SAXLocatorVtbl
=
2147 isaxlocator_QueryInterface
,
2149 isaxlocator_Release
,
2150 isaxlocator_getColumnNumber
,
2151 isaxlocator_getLineNumber
,
2152 isaxlocator_getPublicId
,
2153 isaxlocator_getSystemId
2156 static HRESULT
SAXLocator_create(saxreader
*reader
, saxlocator
**ppsaxlocator
, BOOL vbInterface
)
2158 static const WCHAR w3xmlns
[] = { 'h','t','t','p',':','/','/', 'w','w','w','.','w','3','.',
2159 'o','r','g','/','2','0','0','0','/','x','m','l','n','s','/',0 };
2161 saxlocator
*locator
;
2163 locator
= heap_alloc( sizeof (*locator
) );
2165 return E_OUTOFMEMORY
;
2167 locator
->IVBSAXLocator_iface
.lpVtbl
= &VBSAXLocatorVtbl
;
2168 locator
->ISAXLocator_iface
.lpVtbl
= &SAXLocatorVtbl
;
2169 locator
->IVBSAXAttributes_iface
.lpVtbl
= &ivbsaxattributes_vtbl
;
2170 locator
->ISAXAttributes_iface
.lpVtbl
= &isaxattributes_vtbl
;
2172 locator
->vbInterface
= vbInterface
;
2174 locator
->saxreader
= reader
;
2175 ISAXXMLReader_AddRef(&reader
->ISAXXMLReader_iface
);
2177 locator
->pParserCtxt
= NULL
;
2178 locator
->publicId
= NULL
;
2179 locator
->systemId
= NULL
;
2180 locator
->line
= reader
->version
< MSXML4
? 0 : 1;
2181 locator
->column
= 0;
2182 locator
->ret
= S_OK
;
2183 if (locator
->saxreader
->version
>= MSXML6
)
2184 locator
->namespaceUri
= SysAllocString(w3xmlns
);
2186 locator
->namespaceUri
= SysAllocStringLen(NULL
, 0);
2187 if(!locator
->namespaceUri
)
2189 ISAXXMLReader_Release(&reader
->ISAXXMLReader_iface
);
2191 return E_OUTOFMEMORY
;
2194 locator
->attributesSize
= 8;
2195 locator
->nb_attributes
= 0;
2196 locator
->attributes
= heap_alloc(sizeof(struct _attributes
)*locator
->attributesSize
);
2197 if(!locator
->attributes
)
2199 ISAXXMLReader_Release(&reader
->ISAXXMLReader_iface
);
2200 SysFreeString(locator
->namespaceUri
);
2202 return E_OUTOFMEMORY
;
2205 list_init(&locator
->elements
);
2207 *ppsaxlocator
= locator
;
2209 TRACE("returning %p\n", *ppsaxlocator
);
2214 /*** SAXXMLReader internal functions ***/
2215 static HRESULT
internal_parseBuffer(saxreader
*This
, const char *buffer
, int size
, BOOL vbInterface
)
2217 xmlCharEncoding encoding
= XML_CHAR_ENCODING_NONE
;
2218 xmlChar
*enc_name
= NULL
;
2219 saxlocator
*locator
;
2222 TRACE("(%p)->(%p %d)\n", This
, buffer
, size
);
2224 hr
= SAXLocator_create(This
, &locator
, vbInterface
);
2230 const unsigned char *buff
= (unsigned char*)buffer
;
2232 encoding
= xmlDetectCharEncoding((xmlChar
*)buffer
, 4);
2233 enc_name
= (xmlChar
*)xmlGetCharEncodingName(encoding
);
2234 TRACE("detected encoding: %s\n", enc_name
);
2235 /* skip BOM, parser won't switch encodings and so won't skip it on its own */
2236 if ((encoding
== XML_CHAR_ENCODING_UTF8
) &&
2237 buff
[0] == 0xEF && buff
[1] == 0xBB && buff
[2] == 0xBF)
2244 /* if libxml2 detection failed try to guess */
2245 if (encoding
== XML_CHAR_ENCODING_NONE
)
2247 const WCHAR
*ptr
= (WCHAR
*)buffer
;
2248 /* xml declaration with possibly specfied encoding will be still handled by parser */
2249 if ((size
>= 2) && *ptr
== '<' && ptr
[1] != '?')
2251 enc_name
= (xmlChar
*)xmlGetCharEncodingName(XML_CHAR_ENCODING_UTF16LE
);
2252 encoding
= XML_CHAR_ENCODING_UTF16LE
;
2255 else if (encoding
== XML_CHAR_ENCODING_UTF8
)
2256 enc_name
= (xmlChar
*)xmlGetCharEncodingName(encoding
);
2260 locator
->pParserCtxt
= xmlCreateMemoryParserCtxt(buffer
, size
);
2261 if (!locator
->pParserCtxt
)
2263 ISAXLocator_Release(&locator
->ISAXLocator_iface
);
2269 locator
->pParserCtxt
->encoding
= xmlStrdup(enc_name
);
2270 if (encoding
== XML_CHAR_ENCODING_UTF16LE
) {
2271 TRACE("switching to %s\n", enc_name
);
2272 xmlSwitchEncoding(locator
->pParserCtxt
, encoding
);
2276 xmlFree(locator
->pParserCtxt
->sax
);
2277 locator
->pParserCtxt
->sax
= &locator
->saxreader
->sax
;
2278 locator
->pParserCtxt
->userData
= locator
;
2280 This
->isParsing
= TRUE
;
2281 if(xmlParseDocument(locator
->pParserCtxt
) == -1 && locator
->ret
== S_OK
)
2285 This
->isParsing
= FALSE
;
2287 if(locator
->pParserCtxt
)
2289 locator
->pParserCtxt
->sax
= NULL
;
2290 xmlFreeParserCtxt(locator
->pParserCtxt
);
2291 locator
->pParserCtxt
= NULL
;
2294 ISAXLocator_Release(&locator
->ISAXLocator_iface
);
2298 static HRESULT
internal_parseStream(saxreader
*This
, ISequentialStream
*stream
, BOOL vbInterface
)
2300 saxlocator
*locator
;
2307 hr
= ISequentialStream_Read(stream
, data
, sizeof(data
), &dataRead
);
2308 if(FAILED(hr
)) return hr
;
2310 hr
= SAXLocator_create(This
, &locator
, vbInterface
);
2311 if(FAILED(hr
)) return hr
;
2313 locator
->pParserCtxt
= xmlCreatePushParserCtxt(
2314 &locator
->saxreader
->sax
, locator
,
2315 data
, dataRead
, NULL
);
2316 if(!locator
->pParserCtxt
)
2318 ISAXLocator_Release(&locator
->ISAXLocator_iface
);
2322 This
->isParsing
= TRUE
;
2324 if(dataRead
!= sizeof(data
))
2326 ret
= xmlParseChunk(locator
->pParserCtxt
, data
, 0, 1);
2327 hr
= ret
!=XML_ERR_OK
&& locator
->ret
==S_OK
? E_FAIL
: locator
->ret
;
2334 hr
= ISequentialStream_Read(stream
, data
, sizeof(data
), &dataRead
);
2335 if (FAILED(hr
)) break;
2337 ret
= xmlParseChunk(locator
->pParserCtxt
, data
, dataRead
, 0);
2338 hr
= ret
!=XML_ERR_OK
&& locator
->ret
==S_OK
? E_FAIL
: locator
->ret
;
2340 if (hr
!= S_OK
) break;
2342 if (dataRead
!= sizeof(data
))
2344 ret
= xmlParseChunk(locator
->pParserCtxt
, data
, 0, 1);
2345 hr
= ret
!=XML_ERR_OK
&& locator
->ret
==S_OK
? E_FAIL
: locator
->ret
;
2351 This
->isParsing
= FALSE
;
2353 xmlFreeParserCtxt(locator
->pParserCtxt
);
2354 locator
->pParserCtxt
= NULL
;
2355 ISAXLocator_Release(&locator
->ISAXLocator_iface
);
2359 static HRESULT
internal_getEntityResolver(
2361 void *pEntityResolver
,
2364 FIXME("(%p)->(%p) stub\n", This
, pEntityResolver
);
2368 static HRESULT
internal_putEntityResolver(
2370 void *pEntityResolver
,
2373 FIXME("(%p)->(%p) stub\n", This
, pEntityResolver
);
2377 static HRESULT
internal_parse(
2384 TRACE("(%p)->(%s)\n", This
, debugstr_variant(&varInput
));
2386 /* Dispose of the BSTRs in the pool from a prior run, if any. */
2387 free_bstr_pool(&This
->pool
);
2389 switch(V_VT(&varInput
))
2392 hr
= internal_parseBuffer(This
, (const char*)V_BSTR(&varInput
),
2393 strlenW(V_BSTR(&varInput
))*sizeof(WCHAR
), vbInterface
);
2395 case VT_ARRAY
|VT_UI1
: {
2397 LONG lBound
, uBound
;
2400 hr
= SafeArrayGetLBound(V_ARRAY(&varInput
), 1, &lBound
);
2401 if(hr
!= S_OK
) break;
2402 hr
= SafeArrayGetUBound(V_ARRAY(&varInput
), 1, &uBound
);
2403 if(hr
!= S_OK
) break;
2404 dataRead
= (uBound
-lBound
)*SafeArrayGetElemsize(V_ARRAY(&varInput
));
2405 hr
= SafeArrayAccessData(V_ARRAY(&varInput
), &pSAData
);
2406 if(hr
!= S_OK
) break;
2407 hr
= internal_parseBuffer(This
, pSAData
, dataRead
, vbInterface
);
2408 SafeArrayUnaccessData(V_ARRAY(&varInput
));
2413 IPersistStream
*persistStream
;
2414 ISequentialStream
*stream
= NULL
;
2415 IXMLDOMDocument
*xmlDoc
;
2417 if(IUnknown_QueryInterface(V_UNKNOWN(&varInput
),
2418 &IID_IXMLDOMDocument
, (void**)&xmlDoc
) == S_OK
)
2422 IXMLDOMDocument_get_xml(xmlDoc
, &bstrData
);
2423 hr
= internal_parseBuffer(This
, (const char*)bstrData
,
2424 SysStringByteLen(bstrData
), vbInterface
);
2425 IXMLDOMDocument_Release(xmlDoc
);
2426 SysFreeString(bstrData
);
2430 if(IUnknown_QueryInterface(V_UNKNOWN(&varInput
),
2431 &IID_IPersistStream
, (void**)&persistStream
) == S_OK
)
2433 IStream
*stream_copy
;
2435 hr
= CreateStreamOnHGlobal(NULL
, TRUE
, &stream_copy
);
2438 IPersistStream_Release(persistStream
);
2442 hr
= IPersistStream_Save(persistStream
, stream_copy
, TRUE
);
2443 IPersistStream_Release(persistStream
);
2445 IStream_QueryInterface(stream_copy
, &IID_ISequentialStream
, (void**)&stream
);
2447 IStream_Release(stream_copy
);
2450 /* try base interface first */
2453 IUnknown_QueryInterface(V_UNKNOWN(&varInput
), &IID_ISequentialStream
, (void**)&stream
);
2455 /* this should never happen if IStream is implemented properly, but just in case */
2456 IUnknown_QueryInterface(V_UNKNOWN(&varInput
), &IID_IStream
, (void**)&stream
);
2461 hr
= internal_parseStream(This
, stream
, vbInterface
);
2462 ISequentialStream_Release(stream
);
2466 WARN("IUnknown* input doesn't support any of expected interfaces\n");
2473 WARN("vt %d not implemented\n", V_VT(&varInput
));
2480 static HRESULT
internal_vbonDataAvailable(void *obj
, char *ptr
, DWORD len
)
2482 saxreader
*This
= obj
;
2484 return internal_parseBuffer(This
, ptr
, len
, TRUE
);
2487 static HRESULT
internal_onDataAvailable(void *obj
, char *ptr
, DWORD len
)
2489 saxreader
*This
= obj
;
2491 return internal_parseBuffer(This
, ptr
, len
, FALSE
);
2494 static HRESULT
internal_parseURL(
2503 TRACE("(%p)->(%s)\n", This
, debugstr_w(url
));
2505 hr
= create_moniker_from_url(url
, &mon
);
2509 if(vbInterface
) hr
= bind_url(mon
, internal_vbonDataAvailable
, This
, &bsc
);
2510 else hr
= bind_url(mon
, internal_onDataAvailable
, This
, &bsc
);
2511 IMoniker_Release(mon
);
2516 return detach_bsc(bsc
);
2519 static HRESULT
internal_putProperty(
2525 TRACE("(%p)->(%s %s)\n", This
, debugstr_w(prop
), debugstr_variant(&value
));
2527 if(!memcmp(prop
, PropertyDeclHandlerW
, sizeof(PropertyDeclHandlerW
)))
2529 if(This
->isParsing
) return E_FAIL
;
2531 switch (V_VT(&value
))
2534 saxreader_put_handler(This
, SAXDeclHandler
, NULL
, vbInterface
);
2538 IUnknown
*handler
= NULL
;
2540 if (V_UNKNOWN(&value
))
2545 hr
= IUnknown_QueryInterface(V_UNKNOWN(&value
), &IID_IVBSAXDeclHandler
, (void**)&handler
);
2547 hr
= IUnknown_QueryInterface(V_UNKNOWN(&value
), &IID_ISAXDeclHandler
, (void**)&handler
);
2548 if (FAILED(hr
)) return hr
;
2551 saxreader_put_handler(This
, SAXDeclHandler
, handler
, vbInterface
);
2552 if (handler
) IUnknown_Release(handler
);
2556 return E_INVALIDARG
;
2562 if(!memcmp(prop
, PropertyLexicalHandlerW
, sizeof(PropertyLexicalHandlerW
)))
2564 if(This
->isParsing
) return E_FAIL
;
2566 switch (V_VT(&value
))
2569 saxreader_put_handler(This
, SAXLexicalHandler
, NULL
, vbInterface
);
2573 IUnknown
*handler
= NULL
;
2575 if (V_UNKNOWN(&value
))
2580 hr
= IUnknown_QueryInterface(V_UNKNOWN(&value
), &IID_IVBSAXLexicalHandler
, (void**)&handler
);
2582 hr
= IUnknown_QueryInterface(V_UNKNOWN(&value
), &IID_ISAXLexicalHandler
, (void**)&handler
);
2583 if (FAILED(hr
)) return hr
;
2586 saxreader_put_handler(This
, SAXLexicalHandler
, handler
, vbInterface
);
2587 if (handler
) IUnknown_Release(handler
);
2591 return E_INVALIDARG
;
2597 if(!memcmp(prop
, PropertyMaxXMLSizeW
, sizeof(PropertyMaxXMLSizeW
)))
2599 if (V_VT(&value
) == VT_I4
&& V_I4(&value
) == 0) return S_OK
;
2600 FIXME("(%p)->(%s): max-xml-size unsupported\n", This
, debugstr_variant(&value
));
2604 if(!memcmp(prop
, PropertyMaxElementDepthW
, sizeof(PropertyMaxElementDepthW
)))
2606 if (V_VT(&value
) == VT_I4
&& V_I4(&value
) == 0) return S_OK
;
2607 FIXME("(%p)->(%s): max-element-depth unsupported\n", This
, debugstr_variant(&value
));
2611 FIXME("(%p)->(%s:%s): unsupported property\n", This
, debugstr_w(prop
), debugstr_variant(&value
));
2613 if(!memcmp(prop
, PropertyCharsetW
, sizeof(PropertyCharsetW
)))
2616 if(!memcmp(prop
, PropertyDomNodeW
, sizeof(PropertyDomNodeW
)))
2619 if(!memcmp(prop
, PropertyInputSourceW
, sizeof(PropertyInputSourceW
)))
2622 if(!memcmp(prop
, PropertySchemaDeclHandlerW
, sizeof(PropertySchemaDeclHandlerW
)))
2625 if(!memcmp(prop
, PropertyXMLDeclEncodingW
, sizeof(PropertyXMLDeclEncodingW
)))
2628 if(!memcmp(prop
, PropertyXMLDeclStandaloneW
, sizeof(PropertyXMLDeclStandaloneW
)))
2631 if(!memcmp(prop
, PropertyXMLDeclVersionW
, sizeof(PropertyXMLDeclVersionW
)))
2634 return E_INVALIDARG
;
2637 static HRESULT
internal_getProperty(const saxreader
* This
, const WCHAR
*prop
, VARIANT
*value
, BOOL vb
)
2639 TRACE("(%p)->(%s)\n", This
, debugstr_w(prop
));
2641 if (!value
) return E_POINTER
;
2643 if (!memcmp(PropertyLexicalHandlerW
, prop
, sizeof(PropertyLexicalHandlerW
)))
2645 V_VT(value
) = VT_UNKNOWN
;
2646 saxreader_get_handler(This
, SAXLexicalHandler
, vb
, (void**)&V_UNKNOWN(value
));
2650 if (!memcmp(PropertyDeclHandlerW
, prop
, sizeof(PropertyDeclHandlerW
)))
2652 V_VT(value
) = VT_UNKNOWN
;
2653 saxreader_get_handler(This
, SAXDeclHandler
, vb
, (void**)&V_UNKNOWN(value
));
2657 FIXME("(%p)->(%s) unsupported property\n", This
, debugstr_w(prop
));
2662 /*** IVBSAXXMLReader interface ***/
2663 /*** IUnknown methods ***/
2664 static HRESULT WINAPI
saxxmlreader_QueryInterface(IVBSAXXMLReader
* iface
, REFIID riid
, void **ppvObject
)
2666 saxreader
*This
= impl_from_IVBSAXXMLReader( iface
);
2668 TRACE("%p %s %p\n", This
, debugstr_guid( riid
), ppvObject
);
2672 if ( IsEqualGUID( riid
, &IID_IUnknown
) ||
2673 IsEqualGUID( riid
, &IID_IDispatch
) ||
2674 IsEqualGUID( riid
, &IID_IVBSAXXMLReader
))
2678 else if( IsEqualGUID( riid
, &IID_ISAXXMLReader
))
2680 *ppvObject
= &This
->ISAXXMLReader_iface
;
2682 else if (dispex_query_interface(&This
->dispex
, riid
, ppvObject
))
2684 return *ppvObject
? S_OK
: E_NOINTERFACE
;
2688 FIXME("interface %s not implemented\n", debugstr_guid(riid
));
2689 return E_NOINTERFACE
;
2692 IVBSAXXMLReader_AddRef( iface
);
2697 static ULONG WINAPI
saxxmlreader_AddRef(IVBSAXXMLReader
* iface
)
2699 saxreader
*This
= impl_from_IVBSAXXMLReader( iface
);
2700 TRACE("%p\n", This
);
2701 return InterlockedIncrement( &This
->ref
);
2704 static ULONG WINAPI
saxxmlreader_Release(
2705 IVBSAXXMLReader
* iface
)
2707 saxreader
*This
= impl_from_IVBSAXXMLReader( iface
);
2710 TRACE("%p\n", This
);
2712 ref
= InterlockedDecrement( &This
->ref
);
2717 for (i
= 0; i
< SAXHandler_Last
; i
++)
2719 struct saxhandler_iface
*iface
= &This
->saxhandlers
[i
];
2722 IUnknown_Release(iface
->handler
);
2724 if (iface
->vbhandler
)
2725 IUnknown_Release(iface
->vbhandler
);
2728 free_bstr_pool(&This
->pool
);
2730 release_dispex(&This
->dispex
);
2737 static HRESULT WINAPI
saxxmlreader_GetTypeInfoCount( IVBSAXXMLReader
*iface
, UINT
* pctinfo
)
2739 saxreader
*This
= impl_from_IVBSAXXMLReader( iface
);
2740 return IDispatchEx_GetTypeInfoCount(&This
->dispex
.IDispatchEx_iface
, pctinfo
);
2743 static HRESULT WINAPI
saxxmlreader_GetTypeInfo(
2744 IVBSAXXMLReader
*iface
,
2745 UINT iTInfo
, LCID lcid
, ITypeInfo
** ppTInfo
)
2747 saxreader
*This
= impl_from_IVBSAXXMLReader( iface
);
2748 return IDispatchEx_GetTypeInfo(&This
->dispex
.IDispatchEx_iface
,
2749 iTInfo
, lcid
, ppTInfo
);
2752 static HRESULT WINAPI
saxxmlreader_GetIDsOfNames(
2753 IVBSAXXMLReader
*iface
,
2755 LPOLESTR
* rgszNames
,
2760 saxreader
*This
= impl_from_IVBSAXXMLReader( iface
);
2761 return IDispatchEx_GetIDsOfNames(&This
->dispex
.IDispatchEx_iface
,
2762 riid
, rgszNames
, cNames
, lcid
, rgDispId
);
2765 static HRESULT WINAPI
saxxmlreader_Invoke(
2766 IVBSAXXMLReader
*iface
,
2767 DISPID dispIdMember
,
2771 DISPPARAMS
* pDispParams
,
2772 VARIANT
* pVarResult
,
2773 EXCEPINFO
* pExcepInfo
,
2776 saxreader
*This
= impl_from_IVBSAXXMLReader( iface
);
2777 return IDispatchEx_Invoke(&This
->dispex
.IDispatchEx_iface
,
2778 dispIdMember
, riid
, lcid
, wFlags
, pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
2781 /*** IVBSAXXMLReader methods ***/
2782 static HRESULT WINAPI
saxxmlreader_getFeature(
2783 IVBSAXXMLReader
* iface
,
2784 const WCHAR
*feature_name
,
2785 VARIANT_BOOL
*value
)
2787 saxreader
*This
= impl_from_IVBSAXXMLReader( iface
);
2788 saxreader_feature feature
;
2790 TRACE("(%p)->(%s %p)\n", This
, debugstr_w(feature_name
), value
);
2792 feature
= get_saxreader_feature(feature_name
);
2793 if (feature
== Namespaces
|| feature
== NamespacePrefixes
)
2794 return get_feature_value(This
, feature
, value
);
2796 FIXME("(%p)->(%s %p) stub\n", This
, debugstr_w(feature_name
), value
);
2800 static HRESULT WINAPI
saxxmlreader_putFeature(
2801 IVBSAXXMLReader
* iface
,
2802 const WCHAR
*feature_name
,
2805 saxreader
*This
= impl_from_IVBSAXXMLReader( iface
);
2806 saxreader_feature feature
;
2808 TRACE("(%p)->(%s %x)\n", This
, debugstr_w(feature_name
), value
);
2810 feature
= get_saxreader_feature(feature_name
);
2812 /* accepted cases */
2813 if ((feature
== ExternalGeneralEntities
&& value
== VARIANT_FALSE
) ||
2814 (feature
== ExternalParameterEntities
&& value
== VARIANT_FALSE
) ||
2815 feature
== Namespaces
||
2816 feature
== NamespacePrefixes
)
2818 return set_feature_value(This
, feature
, value
);
2821 if (feature
== LexicalHandlerParEntities
|| feature
== ProhibitDTD
)
2823 FIXME("(%p)->(%s %x) stub\n", This
, debugstr_w(feature_name
), value
);
2824 return set_feature_value(This
, feature
, value
);
2827 FIXME("(%p)->(%s %x) stub\n", This
, debugstr_w(feature_name
), value
);
2831 static HRESULT WINAPI
saxxmlreader_getProperty(
2832 IVBSAXXMLReader
* iface
,
2836 saxreader
*This
= impl_from_IVBSAXXMLReader( iface
);
2837 return internal_getProperty(This
, prop
, value
, TRUE
);
2840 static HRESULT WINAPI
saxxmlreader_putProperty(
2841 IVBSAXXMLReader
* iface
,
2845 saxreader
*This
= impl_from_IVBSAXXMLReader( iface
);
2846 return internal_putProperty(This
, pProp
, value
, TRUE
);
2849 static HRESULT WINAPI
saxxmlreader_get_entityResolver(
2850 IVBSAXXMLReader
* iface
,
2851 IVBSAXEntityResolver
**pEntityResolver
)
2853 saxreader
*This
= impl_from_IVBSAXXMLReader( iface
);
2854 return internal_getEntityResolver(This
, pEntityResolver
, TRUE
);
2857 static HRESULT WINAPI
saxxmlreader_put_entityResolver(
2858 IVBSAXXMLReader
* iface
,
2859 IVBSAXEntityResolver
*pEntityResolver
)
2861 saxreader
*This
= impl_from_IVBSAXXMLReader( iface
);
2862 return internal_putEntityResolver(This
, pEntityResolver
, TRUE
);
2865 static HRESULT WINAPI
saxxmlreader_get_contentHandler(
2866 IVBSAXXMLReader
* iface
,
2867 IVBSAXContentHandler
**handler
)
2869 saxreader
*This
= impl_from_IVBSAXXMLReader( iface
);
2870 return saxreader_get_handler(This
, SAXContentHandler
, TRUE
, (void**)handler
);
2873 static HRESULT WINAPI
saxxmlreader_put_contentHandler(
2874 IVBSAXXMLReader
* iface
,
2875 IVBSAXContentHandler
*handler
)
2877 saxreader
*This
= impl_from_IVBSAXXMLReader( iface
);
2878 return saxreader_put_handler(This
, SAXContentHandler
, handler
, TRUE
);
2881 static HRESULT WINAPI
saxxmlreader_get_dtdHandler(
2882 IVBSAXXMLReader
* iface
,
2883 IVBSAXDTDHandler
**handler
)
2885 saxreader
*This
= impl_from_IVBSAXXMLReader( iface
);
2886 return saxreader_get_handler(This
, SAXDTDHandler
, TRUE
, (void**)handler
);
2889 static HRESULT WINAPI
saxxmlreader_put_dtdHandler(
2890 IVBSAXXMLReader
* iface
,
2891 IVBSAXDTDHandler
*handler
)
2893 saxreader
*This
= impl_from_IVBSAXXMLReader( iface
);
2894 return saxreader_put_handler(This
, SAXDTDHandler
, handler
, TRUE
);
2897 static HRESULT WINAPI
saxxmlreader_get_errorHandler(
2898 IVBSAXXMLReader
* iface
,
2899 IVBSAXErrorHandler
**handler
)
2901 saxreader
*This
= impl_from_IVBSAXXMLReader( iface
);
2902 return saxreader_get_handler(This
, SAXErrorHandler
, TRUE
, (void**)handler
);
2905 static HRESULT WINAPI
saxxmlreader_put_errorHandler(
2906 IVBSAXXMLReader
* iface
,
2907 IVBSAXErrorHandler
*handler
)
2909 saxreader
*This
= impl_from_IVBSAXXMLReader( iface
);
2910 return saxreader_put_handler(This
, SAXErrorHandler
, handler
, TRUE
);
2913 static HRESULT WINAPI
saxxmlreader_get_baseURL(
2914 IVBSAXXMLReader
* iface
,
2915 const WCHAR
**pBaseUrl
)
2917 saxreader
*This
= impl_from_IVBSAXXMLReader( iface
);
2919 FIXME("(%p)->(%p) stub\n", This
, pBaseUrl
);
2923 static HRESULT WINAPI
saxxmlreader_put_baseURL(
2924 IVBSAXXMLReader
* iface
,
2925 const WCHAR
*pBaseUrl
)
2927 saxreader
*This
= impl_from_IVBSAXXMLReader( iface
);
2929 FIXME("(%p)->(%s) stub\n", This
, debugstr_w(pBaseUrl
));
2933 static HRESULT WINAPI
saxxmlreader_get_secureBaseURL(
2934 IVBSAXXMLReader
* iface
,
2935 const WCHAR
**pSecureBaseUrl
)
2937 saxreader
*This
= impl_from_IVBSAXXMLReader( iface
);
2939 FIXME("(%p)->(%p) stub\n", This
, pSecureBaseUrl
);
2944 static HRESULT WINAPI
saxxmlreader_put_secureBaseURL(
2945 IVBSAXXMLReader
* iface
,
2946 const WCHAR
*secureBaseUrl
)
2948 saxreader
*This
= impl_from_IVBSAXXMLReader( iface
);
2950 FIXME("(%p)->(%s) stub\n", This
, debugstr_w(secureBaseUrl
));
2954 static HRESULT WINAPI
saxxmlreader_parse(
2955 IVBSAXXMLReader
* iface
,
2958 saxreader
*This
= impl_from_IVBSAXXMLReader( iface
);
2959 return internal_parse(This
, varInput
, TRUE
);
2962 static HRESULT WINAPI
saxxmlreader_parseURL(
2963 IVBSAXXMLReader
* iface
,
2966 saxreader
*This
= impl_from_IVBSAXXMLReader( iface
);
2967 return internal_parseURL(This
, url
, TRUE
);
2970 static const struct IVBSAXXMLReaderVtbl VBSAXXMLReaderVtbl
=
2972 saxxmlreader_QueryInterface
,
2973 saxxmlreader_AddRef
,
2974 saxxmlreader_Release
,
2975 saxxmlreader_GetTypeInfoCount
,
2976 saxxmlreader_GetTypeInfo
,
2977 saxxmlreader_GetIDsOfNames
,
2978 saxxmlreader_Invoke
,
2979 saxxmlreader_getFeature
,
2980 saxxmlreader_putFeature
,
2981 saxxmlreader_getProperty
,
2982 saxxmlreader_putProperty
,
2983 saxxmlreader_get_entityResolver
,
2984 saxxmlreader_put_entityResolver
,
2985 saxxmlreader_get_contentHandler
,
2986 saxxmlreader_put_contentHandler
,
2987 saxxmlreader_get_dtdHandler
,
2988 saxxmlreader_put_dtdHandler
,
2989 saxxmlreader_get_errorHandler
,
2990 saxxmlreader_put_errorHandler
,
2991 saxxmlreader_get_baseURL
,
2992 saxxmlreader_put_baseURL
,
2993 saxxmlreader_get_secureBaseURL
,
2994 saxxmlreader_put_secureBaseURL
,
2996 saxxmlreader_parseURL
2999 /*** ISAXXMLReader interface ***/
3000 /*** IUnknown methods ***/
3001 static HRESULT WINAPI
isaxxmlreader_QueryInterface(ISAXXMLReader
* iface
, REFIID riid
, void **ppvObject
)
3003 saxreader
*This
= impl_from_ISAXXMLReader( iface
);
3004 return saxxmlreader_QueryInterface(&This
->IVBSAXXMLReader_iface
, riid
, ppvObject
);
3007 static ULONG WINAPI
isaxxmlreader_AddRef(ISAXXMLReader
* iface
)
3009 saxreader
*This
= impl_from_ISAXXMLReader( iface
);
3010 return saxxmlreader_AddRef(&This
->IVBSAXXMLReader_iface
);
3013 static ULONG WINAPI
isaxxmlreader_Release(ISAXXMLReader
* iface
)
3015 saxreader
*This
= impl_from_ISAXXMLReader( iface
);
3016 return saxxmlreader_Release(&This
->IVBSAXXMLReader_iface
);
3019 /*** ISAXXMLReader methods ***/
3020 static HRESULT WINAPI
isaxxmlreader_getFeature(
3021 ISAXXMLReader
* iface
,
3022 const WCHAR
*pFeature
,
3023 VARIANT_BOOL
*pValue
)
3025 saxreader
*This
= impl_from_ISAXXMLReader( iface
);
3026 return IVBSAXXMLReader_getFeature(&This
->IVBSAXXMLReader_iface
, pFeature
, pValue
);
3029 static HRESULT WINAPI
isaxxmlreader_putFeature(
3030 ISAXXMLReader
* iface
,
3031 const WCHAR
*pFeature
,
3032 VARIANT_BOOL vfValue
)
3034 saxreader
*This
= impl_from_ISAXXMLReader( iface
);
3035 return IVBSAXXMLReader_putFeature(&This
->IVBSAXXMLReader_iface
, pFeature
, vfValue
);
3038 static HRESULT WINAPI
isaxxmlreader_getProperty(
3039 ISAXXMLReader
* iface
,
3043 saxreader
*This
= impl_from_ISAXXMLReader( iface
);
3044 return internal_getProperty(This
, prop
, value
, FALSE
);
3047 static HRESULT WINAPI
isaxxmlreader_putProperty(
3048 ISAXXMLReader
* iface
,
3052 saxreader
*This
= impl_from_ISAXXMLReader( iface
);
3053 return internal_putProperty(This
, pProp
, value
, FALSE
);
3056 static HRESULT WINAPI
isaxxmlreader_getEntityResolver(
3057 ISAXXMLReader
* iface
,
3058 ISAXEntityResolver
**ppEntityResolver
)
3060 saxreader
*This
= impl_from_ISAXXMLReader( iface
);
3061 return internal_getEntityResolver(This
, ppEntityResolver
, FALSE
);
3064 static HRESULT WINAPI
isaxxmlreader_putEntityResolver(
3065 ISAXXMLReader
* iface
,
3066 ISAXEntityResolver
*pEntityResolver
)
3068 saxreader
*This
= impl_from_ISAXXMLReader( iface
);
3069 return internal_putEntityResolver(This
, pEntityResolver
, FALSE
);
3072 static HRESULT WINAPI
isaxxmlreader_getContentHandler(
3073 ISAXXMLReader
* iface
,
3074 ISAXContentHandler
**handler
)
3076 saxreader
*This
= impl_from_ISAXXMLReader( iface
);
3077 return saxreader_get_handler(This
, SAXContentHandler
, FALSE
, (void**)handler
);
3080 static HRESULT WINAPI
isaxxmlreader_putContentHandler(
3081 ISAXXMLReader
* iface
,
3082 ISAXContentHandler
*handler
)
3084 saxreader
*This
= impl_from_ISAXXMLReader( iface
);
3085 return saxreader_put_handler(This
, SAXContentHandler
, handler
, FALSE
);
3088 static HRESULT WINAPI
isaxxmlreader_getDTDHandler(
3089 ISAXXMLReader
* iface
,
3090 ISAXDTDHandler
**handler
)
3092 saxreader
*This
= impl_from_ISAXXMLReader( iface
);
3093 return saxreader_get_handler(This
, SAXDTDHandler
, FALSE
, (void**)handler
);
3096 static HRESULT WINAPI
isaxxmlreader_putDTDHandler(
3097 ISAXXMLReader
* iface
,
3098 ISAXDTDHandler
*handler
)
3100 saxreader
*This
= impl_from_ISAXXMLReader( iface
);
3101 return saxreader_put_handler(This
, SAXDTDHandler
, handler
, FALSE
);
3104 static HRESULT WINAPI
isaxxmlreader_getErrorHandler(
3105 ISAXXMLReader
* iface
,
3106 ISAXErrorHandler
**handler
)
3108 saxreader
*This
= impl_from_ISAXXMLReader( iface
);
3109 return saxreader_get_handler(This
, SAXErrorHandler
, FALSE
, (void**)handler
);
3112 static HRESULT WINAPI
isaxxmlreader_putErrorHandler(ISAXXMLReader
* iface
, ISAXErrorHandler
*handler
)
3114 saxreader
*This
= impl_from_ISAXXMLReader( iface
);
3115 return saxreader_put_handler(This
, SAXErrorHandler
, handler
, FALSE
);
3118 static HRESULT WINAPI
isaxxmlreader_getBaseURL(
3119 ISAXXMLReader
* iface
,
3120 const WCHAR
**pBaseUrl
)
3122 saxreader
*This
= impl_from_ISAXXMLReader( iface
);
3123 return IVBSAXXMLReader_get_baseURL(&This
->IVBSAXXMLReader_iface
, pBaseUrl
);
3126 static HRESULT WINAPI
isaxxmlreader_putBaseURL(
3127 ISAXXMLReader
* iface
,
3128 const WCHAR
*pBaseUrl
)
3130 saxreader
*This
= impl_from_ISAXXMLReader( iface
);
3131 return IVBSAXXMLReader_put_baseURL(&This
->IVBSAXXMLReader_iface
, pBaseUrl
);
3134 static HRESULT WINAPI
isaxxmlreader_getSecureBaseURL(
3135 ISAXXMLReader
* iface
,
3136 const WCHAR
**pSecureBaseUrl
)
3138 saxreader
*This
= impl_from_ISAXXMLReader( iface
);
3139 return IVBSAXXMLReader_get_secureBaseURL(&This
->IVBSAXXMLReader_iface
, pSecureBaseUrl
);
3142 static HRESULT WINAPI
isaxxmlreader_putSecureBaseURL(
3143 ISAXXMLReader
* iface
,
3144 const WCHAR
*secureBaseUrl
)
3146 saxreader
*This
= impl_from_ISAXXMLReader( iface
);
3147 return IVBSAXXMLReader_put_secureBaseURL(&This
->IVBSAXXMLReader_iface
, secureBaseUrl
);
3150 static HRESULT WINAPI
isaxxmlreader_parse(
3151 ISAXXMLReader
* iface
,
3154 saxreader
*This
= impl_from_ISAXXMLReader( iface
);
3155 return internal_parse(This
, varInput
, FALSE
);
3158 static HRESULT WINAPI
isaxxmlreader_parseURL(
3159 ISAXXMLReader
* iface
,
3162 saxreader
*This
= impl_from_ISAXXMLReader( iface
);
3163 return internal_parseURL(This
, url
, FALSE
);
3166 static const struct ISAXXMLReaderVtbl SAXXMLReaderVtbl
=
3168 isaxxmlreader_QueryInterface
,
3169 isaxxmlreader_AddRef
,
3170 isaxxmlreader_Release
,
3171 isaxxmlreader_getFeature
,
3172 isaxxmlreader_putFeature
,
3173 isaxxmlreader_getProperty
,
3174 isaxxmlreader_putProperty
,
3175 isaxxmlreader_getEntityResolver
,
3176 isaxxmlreader_putEntityResolver
,
3177 isaxxmlreader_getContentHandler
,
3178 isaxxmlreader_putContentHandler
,
3179 isaxxmlreader_getDTDHandler
,
3180 isaxxmlreader_putDTDHandler
,
3181 isaxxmlreader_getErrorHandler
,
3182 isaxxmlreader_putErrorHandler
,
3183 isaxxmlreader_getBaseURL
,
3184 isaxxmlreader_putBaseURL
,
3185 isaxxmlreader_getSecureBaseURL
,
3186 isaxxmlreader_putSecureBaseURL
,
3187 isaxxmlreader_parse
,
3188 isaxxmlreader_parseURL
3191 static const tid_t saxreader_iface_tids
[] = {
3192 IVBSAXXMLReader_tid
,
3195 static dispex_static_data_t saxreader_dispex
= {
3197 IVBSAXXMLReader_tid
,
3199 saxreader_iface_tids
3202 HRESULT
SAXXMLReader_create(MSXML_VERSION version
, IUnknown
*outer
, LPVOID
*ppObj
)
3206 TRACE("(%p, %p)\n", outer
, ppObj
);
3208 reader
= heap_alloc( sizeof (*reader
) );
3210 return E_OUTOFMEMORY
;
3212 reader
->IVBSAXXMLReader_iface
.lpVtbl
= &VBSAXXMLReaderVtbl
;
3213 reader
->ISAXXMLReader_iface
.lpVtbl
= &SAXXMLReaderVtbl
;
3215 memset(reader
->saxhandlers
, 0, sizeof(reader
->saxhandlers
));
3216 reader
->isParsing
= FALSE
;
3217 reader
->pool
.pool
= NULL
;
3218 reader
->pool
.index
= 0;
3219 reader
->pool
.len
= 0;
3220 reader
->features
= Namespaces
| NamespacePrefixes
;
3221 reader
->version
= version
;
3223 init_dispex(&reader
->dispex
, (IUnknown
*)&reader
->IVBSAXXMLReader_iface
, &saxreader_dispex
);
3225 memset(&reader
->sax
, 0, sizeof(xmlSAXHandler
));
3226 reader
->sax
.initialized
= XML_SAX2_MAGIC
;
3227 reader
->sax
.startDocument
= libxmlStartDocument
;
3228 reader
->sax
.endDocument
= libxmlEndDocument
;
3229 reader
->sax
.startElementNs
= libxmlStartElementNS
;
3230 reader
->sax
.endElementNs
= libxmlEndElementNS
;
3231 reader
->sax
.characters
= libxmlCharacters
;
3232 reader
->sax
.setDocumentLocator
= libxmlSetDocumentLocator
;
3233 reader
->sax
.comment
= libxmlComment
;
3234 reader
->sax
.error
= libxmlFatalError
;
3235 reader
->sax
.fatalError
= libxmlFatalError
;
3236 reader
->sax
.cdataBlock
= libxmlCDataBlock
;
3238 *ppObj
= &reader
->IVBSAXXMLReader_iface
;
3240 TRACE("returning iface %p\n", *ppObj
);
3247 HRESULT
SAXXMLReader_create(MSXML_VERSION version
, IUnknown
*pUnkOuter
, LPVOID
*ppObj
)
3249 MESSAGE("This program tried to use a SAX XML Reader object, but\n"
3250 "libxml2 support was not present at compile time.\n");