windowscodecs: Add more tests for PNG metadata.
[wine/multimedia.git] / dlls / msxml3 / saxreader.c
blob9ebdc0f611f4cde03403da196a1a5c335a35cf0a
1 /*
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
21 #define COBJMACROS
23 #include "config.h"
25 #include <stdarg.h>
26 #ifdef HAVE_LIBXML2
27 # include <libxml/parser.h>
28 # include <libxml/xmlerror.h>
29 # include <libxml/SAX2.h>
30 # include <libxml/parserInternals.h>
31 #endif
33 #include "windef.h"
34 #include "winbase.h"
35 #include "winuser.h"
36 #include "winnls.h"
37 #include "ole2.h"
38 #include "msxml6.h"
39 #include "wininet.h"
40 #include "urlmon.h"
41 #include "winreg.h"
42 #include "shlwapi.h"
44 #include "wine/debug.h"
45 #include "wine/list.h"
47 #include "msxml_private.h"
49 WINE_DEFAULT_DEBUG_CHANNEL(msxml);
51 #ifdef HAVE_LIBXML2
53 typedef enum
55 FeatureUnknown = 0,
56 ExhaustiveErrors = 1 << 1,
57 ExternalGeneralEntities = 1 << 2,
58 ExternalParameterEntities = 1 << 3,
59 ForcedResync = 1 << 4,
60 NamespacePrefixes = 1 << 5,
61 Namespaces = 1 << 6,
62 ParameterEntities = 1 << 7,
63 PreserveSystemIndentifiers = 1 << 8,
64 ProhibitDTD = 1 << 9,
65 SchemaValidation = 1 << 10,
66 ServerHttpRequest = 1 << 11,
67 SuppressValidationfatalError = 1 << 12,
68 UseInlineSchema = 1 << 13,
69 UseSchemaLocation = 1 << 14,
70 LexicalHandlerParEntities = 1 << 15
71 } saxreader_feature;
73 /* feature names */
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;
107 const WCHAR *name;
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)
121 int min, max, n, c;
123 min = 0;
124 max = sizeof(saxreader_feature_map)/sizeof(struct saxreader_feature_pair) - 1;
126 while (min <= max)
128 n = (min+max)/2;
130 c = strcmpW(saxreader_feature_map[n].name, name);
131 if (!c)
132 return saxreader_feature_map[n].feature;
134 if (c > 0)
135 max = n-1;
136 else
137 min = n+1;
140 return FeatureUnknown;
143 struct bstrpool
145 BSTR *pool;
146 unsigned int index;
147 unsigned int len;
150 typedef struct
152 BSTR prefix;
153 BSTR uri;
154 } ns;
156 typedef struct
158 struct list entry;
159 BSTR prefix;
160 BSTR local;
161 BSTR qname;
162 ns *ns; /* namespaces defined in this particular element */
163 int ns_count;
164 } element_entry;
166 enum saxhandler_type
168 SAXContentHandler = 0,
169 SAXDeclHandler,
170 SAXDTDHandler,
171 SAXErrorHandler,
172 SAXLexicalHandler,
173 SAXHandler_Last
176 struct saxhandler_iface
178 IUnknown *handler;
179 IUnknown *vbhandler;
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;
200 typedef struct
202 DispatchEx dispex;
203 IVBSAXXMLReader IVBSAXXMLReader_iface;
204 ISAXXMLReader ISAXXMLReader_iface;
205 LONG ref;
207 struct saxhandler_iface saxhandlers[SAXHandler_Last];
208 xmlSAXHandler sax;
209 BOOL isParsing;
210 struct bstrpool pool;
211 saxreader_feature features;
212 BSTR xmldecl_version;
213 MSXML_VERSION version;
214 } saxreader;
216 static HRESULT saxreader_put_handler(saxreader *reader, enum saxhandler_type type, void *ptr, BOOL vb)
218 struct saxhandler_iface *iface = &reader->saxhandlers[type];
219 IUnknown *unk = (IUnknown*)ptr;
221 if (unk)
222 IUnknown_AddRef(unk);
224 if ((vb && iface->vbhandler) || (!vb && iface->handler))
225 IUnknown_Release(vb ? iface->vbhandler : iface->handler);
227 if (vb)
228 iface->vbhandler = unk;
229 else
230 iface->handler = unk;
232 return S_OK;
235 static HRESULT saxreader_get_handler(const saxreader *reader, enum saxhandler_type type, BOOL vb, void **ret)
237 const struct saxhandler_iface *iface = &reader->saxhandlers[type];
239 if (!ret) return E_POINTER;
241 if ((vb && iface->vbhandler) || (!vb && iface->handler))
243 if (vb)
244 IUnknown_AddRef(iface->vbhandler);
245 else
246 IUnknown_AddRef(iface->handler);
249 *ret = vb ? iface->vbhandler : iface->handler;
251 return S_OK;
254 static struct saxcontenthandler_iface *saxreader_get_contenthandler(saxreader *reader)
256 return (struct saxcontenthandler_iface*)&reader->saxhandlers[SAXContentHandler];
259 static struct saxerrorhandler_iface *saxreader_get_errorhandler(saxreader *reader)
261 return (struct saxerrorhandler_iface*)&reader->saxhandlers[SAXErrorHandler];
264 static struct saxlexicalhandler_iface *saxreader_get_lexicalhandler(saxreader *reader)
266 return (struct saxlexicalhandler_iface*)&reader->saxhandlers[SAXLexicalHandler];
269 typedef struct
271 IVBSAXLocator IVBSAXLocator_iface;
272 ISAXLocator ISAXLocator_iface;
273 IVBSAXAttributes IVBSAXAttributes_iface;
274 ISAXAttributes ISAXAttributes_iface;
275 LONG ref;
276 saxreader *saxreader;
277 HRESULT ret;
278 xmlParserCtxtPtr pParserCtxt;
279 WCHAR *publicId;
280 WCHAR *systemId;
281 int line;
282 int column;
283 BOOL vbInterface;
284 struct list elements;
286 BSTR namespaceUri;
287 int attributesSize;
288 int nb_attributes;
289 struct _attributes
291 BSTR szLocalname;
292 BSTR szURI;
293 BSTR szValue;
294 BSTR szQName;
295 } *attributes;
296 } saxlocator;
298 static inline saxreader *impl_from_IVBSAXXMLReader( IVBSAXXMLReader *iface )
300 return CONTAINING_RECORD(iface, saxreader, IVBSAXXMLReader_iface);
303 static inline saxreader *impl_from_ISAXXMLReader( ISAXXMLReader *iface )
305 return CONTAINING_RECORD(iface, saxreader, ISAXXMLReader_iface);
308 static inline saxlocator *impl_from_IVBSAXLocator( IVBSAXLocator *iface )
310 return CONTAINING_RECORD(iface, saxlocator, IVBSAXLocator_iface);
313 static inline saxlocator *impl_from_ISAXLocator( ISAXLocator *iface )
315 return CONTAINING_RECORD(iface, saxlocator, ISAXLocator_iface);
318 static inline saxlocator *impl_from_IVBSAXAttributes( IVBSAXAttributes *iface )
320 return CONTAINING_RECORD(iface, saxlocator, IVBSAXAttributes_iface);
323 static inline saxlocator *impl_from_ISAXAttributes( ISAXAttributes *iface )
325 return CONTAINING_RECORD(iface, saxlocator, ISAXAttributes_iface);
328 static inline int saxreader_has_handler(const saxlocator *locator, enum saxhandler_type type)
330 return (locator->vbInterface && locator->saxreader->saxhandlers[type].vbhandler) ||
331 (!locator->vbInterface && locator->saxreader->saxhandlers[type].handler);
334 /* property names */
335 static const WCHAR PropertyCharsetW[] = {
336 'c','h','a','r','s','e','t',0
338 static const WCHAR PropertyXmlDeclVersionW[] = {
339 'x','m','l','d','e','c','l','-','v','e','r','s','i','o','n',0
341 static const WCHAR PropertyDeclHandlerW[] = {
342 'h','t','t','p',':','/','/','x','m','l','.','o','r','g','/',
343 's','a','x','/','p','r','o','p','e','r','t','i','e','s','/',
344 'd','e','c','l','a','r','a','t','i','o','n',
345 '-','h','a','n','d','l','e','r',0
347 static const WCHAR PropertyDomNodeW[] = {
348 'h','t','t','p',':','/','/','x','m','l','.','o','r','g','/',
349 's','a','x','/','p','r','o','p','e','r','t','i','e','s','/',
350 'd','o','m','-','n','o','d','e',0
352 static const WCHAR PropertyInputSourceW[] = {
353 'i','n','p','u','t','-','s','o','u','r','c','e',0
355 static const WCHAR PropertyLexicalHandlerW[] = {
356 'h','t','t','p',':','/','/','x','m','l','.','o','r','g','/',
357 's','a','x','/','p','r','o','p','e','r','t','i','e','s','/',
358 'l','e','x','i','c','a','l','-','h','a','n','d','l','e','r',0
360 static const WCHAR PropertyMaxElementDepthW[] = {
361 'm','a','x','-','e','l','e','m','e','n','t','-','d','e','p','t','h',0
363 static const WCHAR PropertyMaxXMLSizeW[] = {
364 'm','a','x','-','x','m','l','-','s','i','z','e',0
366 static const WCHAR PropertySchemaDeclHandlerW[] = {
367 's','c','h','e','m','a','-','d','e','c','l','a','r','a','t','i','o','n','-',
368 'h','a','n','d','l','e','r',0
370 static const WCHAR PropertyXMLDeclEncodingW[] = {
371 'x','m','l','d','e','c','l','-','e','n','c','o','d','i','n','g',0
373 static const WCHAR PropertyXMLDeclStandaloneW[] = {
374 'x','m','l','d','e','c','l','-','s','t','a','n','d','a','l','o','n','e',0
376 static const WCHAR PropertyXMLDeclVersionW[] = {
377 'x','m','l','d','e','c','l','-','v','e','r','s','i','o','n',0
380 static inline HRESULT set_feature_value(saxreader *reader, saxreader_feature feature, VARIANT_BOOL value)
382 /* handling of non-VARIANT_* values is version dependent */
383 if ((reader->version < MSXML4) && (value != VARIANT_TRUE))
384 value = VARIANT_FALSE;
385 if ((reader->version >= MSXML4) && (value != VARIANT_FALSE))
386 value = VARIANT_TRUE;
388 if (value == VARIANT_TRUE)
389 reader->features |= feature;
390 else
391 reader->features &= ~feature;
393 return S_OK;
396 static inline HRESULT get_feature_value(const saxreader *reader, saxreader_feature feature, VARIANT_BOOL *value)
398 *value = reader->features & feature ? VARIANT_TRUE : VARIANT_FALSE;
399 return S_OK;
402 static BOOL is_namespaces_enabled(const saxreader *reader)
404 return (reader->version < MSXML4) || (reader->features & Namespaces);
407 static BSTR build_qname(BSTR prefix, BSTR local)
409 if (prefix && *prefix)
411 BSTR qname = SysAllocStringLen(NULL, SysStringLen(prefix) + SysStringLen(local) + 1);
412 WCHAR *ptr;
414 ptr = qname;
415 strcpyW(ptr, prefix);
416 ptr += SysStringLen(prefix);
417 *ptr++ = ':';
418 strcpyW(ptr, local);
419 return qname;
421 else
422 return SysAllocString(local);
425 static element_entry* alloc_element_entry(const xmlChar *local, const xmlChar *prefix, int nb_ns,
426 const xmlChar **namespaces)
428 element_entry *ret;
429 int i;
431 ret = heap_alloc(sizeof(*ret));
432 if (!ret) return ret;
434 ret->local = bstr_from_xmlChar(local);
435 ret->prefix = bstr_from_xmlChar(prefix);
436 ret->qname = build_qname(ret->prefix, ret->local);
437 ret->ns = nb_ns ? heap_alloc(nb_ns*sizeof(ns)) : NULL;
438 ret->ns_count = nb_ns;
440 for (i=0; i < nb_ns; i++)
442 ret->ns[i].prefix = bstr_from_xmlChar(namespaces[2*i]);
443 ret->ns[i].uri = bstr_from_xmlChar(namespaces[2*i+1]);
446 return ret;
449 static void free_element_entry(element_entry *element)
451 int i;
453 for (i=0; i<element->ns_count;i++)
455 SysFreeString(element->ns[i].prefix);
456 SysFreeString(element->ns[i].uri);
459 SysFreeString(element->prefix);
460 SysFreeString(element->local);
462 heap_free(element->ns);
463 heap_free(element);
466 static void push_element_ns(saxlocator *locator, element_entry *element)
468 list_add_head(&locator->elements, &element->entry);
471 static element_entry * pop_element_ns(saxlocator *locator)
473 element_entry *element = LIST_ENTRY(list_head(&locator->elements), element_entry, entry);
475 if (element)
476 list_remove(&element->entry);
478 return element;
481 static BSTR find_element_uri(saxlocator *locator, const xmlChar *uri)
483 element_entry *element;
484 BSTR uriW;
485 int i;
487 if (!uri) return NULL;
489 uriW = bstr_from_xmlChar(uri);
491 LIST_FOR_EACH_ENTRY(element, &locator->elements, element_entry, entry)
493 for (i=0; i < element->ns_count; i++)
494 if (!strcmpW(uriW, element->ns[i].uri))
496 SysFreeString(uriW);
497 return element->ns[i].uri;
501 SysFreeString(uriW);
502 ERR("namespace uri not found, %s\n", debugstr_a((char*)uri));
503 return NULL;
506 /* used to localize version dependent error check behaviour */
507 static inline BOOL sax_callback_failed(saxlocator *This, HRESULT hr)
509 return This->saxreader->version >= MSXML4 ? FAILED(hr) : hr != S_OK;
512 /* index value -1 means it tries to loop for a first time */
513 static inline BOOL iterate_endprefix_index(saxlocator *This, const element_entry *element, int *i)
515 if (This->saxreader->version >= MSXML4)
517 if (*i == -1) *i = 0; else ++*i;
518 return *i < element->ns_count;
520 else
522 if (*i == -1) *i = element->ns_count-1; else --*i;
523 return *i >= 0;
527 static BOOL bstr_pool_insert(struct bstrpool *pool, BSTR pool_entry)
529 if (!pool->pool)
531 pool->pool = HeapAlloc(GetProcessHeap(), 0, 16 * sizeof(*pool->pool));
532 if (!pool->pool)
533 return FALSE;
535 pool->index = 0;
536 pool->len = 16;
538 else if (pool->index == pool->len)
540 BSTR *realloc = HeapReAlloc(GetProcessHeap(), 0, pool->pool, pool->len * 2 * sizeof(*realloc));
542 if (!realloc)
543 return FALSE;
545 pool->pool = realloc;
546 pool->len *= 2;
549 pool->pool[pool->index++] = pool_entry;
550 return TRUE;
553 static void free_bstr_pool(struct bstrpool *pool)
555 unsigned int i;
557 for (i = 0; i < pool->index; i++)
558 SysFreeString(pool->pool[i]);
560 HeapFree(GetProcessHeap(), 0, pool->pool);
562 pool->pool = NULL;
563 pool->index = pool->len = 0;
566 static BSTR bstr_from_xmlCharN(const xmlChar *buf, int len)
568 DWORD dLen;
569 BSTR bstr;
571 if (!buf)
572 return NULL;
574 dLen = MultiByteToWideChar(CP_UTF8, 0, (LPCSTR)buf, len, NULL, 0);
575 if(len != -1) dLen++;
576 bstr = SysAllocStringLen(NULL, dLen-1);
577 if (!bstr)
578 return NULL;
579 MultiByteToWideChar(CP_UTF8, 0, (LPCSTR)buf, len, bstr, dLen);
580 if(len != -1) bstr[dLen-1] = '\0';
582 return bstr;
585 static BSTR QName_from_xmlChar(const xmlChar *prefix, const xmlChar *name)
587 xmlChar *qname;
588 BSTR bstr;
590 if(!name) return NULL;
592 if(!prefix || !*prefix)
593 return bstr_from_xmlChar(name);
595 qname = xmlBuildQName(name, prefix, NULL, 0);
596 bstr = bstr_from_xmlChar(qname);
597 xmlFree(qname);
599 return bstr;
602 static BSTR pooled_bstr_from_xmlChar(struct bstrpool *pool, const xmlChar *buf)
604 BSTR pool_entry = bstr_from_xmlChar(buf);
606 if (pool_entry && !bstr_pool_insert(pool, pool_entry))
608 SysFreeString(pool_entry);
609 return NULL;
612 return pool_entry;
615 static BSTR pooled_bstr_from_xmlCharN(struct bstrpool *pool, const xmlChar *buf, int len)
617 BSTR pool_entry = bstr_from_xmlCharN(buf, len);
619 if (pool_entry && !bstr_pool_insert(pool, pool_entry))
621 SysFreeString(pool_entry);
622 return NULL;
625 return pool_entry;
628 static void format_error_message_from_id(saxlocator *This, HRESULT hr)
630 struct saxerrorhandler_iface *handler = saxreader_get_errorhandler(This->saxreader);
631 xmlStopParser(This->pParserCtxt);
632 This->ret = hr;
634 if (saxreader_has_handler(This, SAXErrorHandler))
636 WCHAR msg[1024];
637 if(!FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM,
638 NULL, hr, 0, msg, sizeof(msg), NULL))
640 FIXME("MSXML errors not yet supported.\n");
641 msg[0] = '\0';
644 if(This->vbInterface)
646 BSTR bstrMsg = SysAllocString(msg);
647 IVBSAXErrorHandler_fatalError(handler->vbhandler,
648 &This->IVBSAXLocator_iface, &bstrMsg, hr);
649 SysFreeString(bstrMsg);
651 else
652 ISAXErrorHandler_fatalError(handler->handler,
653 &This->ISAXLocator_iface, msg, hr);
657 static void update_position(saxlocator *This, BOOL fix_column)
659 const xmlChar *p = This->pParserCtxt->input->cur-1;
661 This->line = xmlSAX2GetLineNumber(This->pParserCtxt);
662 if(fix_column)
664 This->column = 1;
665 for(; *p!='\n' && *p!='\r' && p>=This->pParserCtxt->input->base; p--)
666 This->column++;
668 else
670 This->column = xmlSAX2GetColumnNumber(This->pParserCtxt);
674 /*** IVBSAXAttributes interface ***/
675 /*** IUnknown methods ***/
676 static HRESULT WINAPI ivbsaxattributes_QueryInterface(
677 IVBSAXAttributes* iface,
678 REFIID riid,
679 void **ppvObject)
681 saxlocator *This = impl_from_IVBSAXAttributes(iface);
682 TRACE("%p %s %p\n", This, debugstr_guid(riid), ppvObject);
683 return IVBSAXLocator_QueryInterface(&This->IVBSAXLocator_iface, riid, ppvObject);
686 static ULONG WINAPI ivbsaxattributes_AddRef(IVBSAXAttributes* iface)
688 saxlocator *This = impl_from_IVBSAXAttributes(iface);
689 return ISAXLocator_AddRef(&This->ISAXLocator_iface);
692 static ULONG WINAPI ivbsaxattributes_Release(IVBSAXAttributes* iface)
694 saxlocator *This = impl_from_IVBSAXAttributes(iface);
695 return ISAXLocator_Release(&This->ISAXLocator_iface);
698 /*** IDispatch methods ***/
699 static HRESULT WINAPI ivbsaxattributes_GetTypeInfoCount( IVBSAXAttributes *iface, UINT* pctinfo )
701 saxlocator *This = impl_from_IVBSAXAttributes( iface );
703 TRACE("(%p)->(%p)\n", This, pctinfo);
705 *pctinfo = 1;
707 return S_OK;
710 static HRESULT WINAPI ivbsaxattributes_GetTypeInfo(
711 IVBSAXAttributes *iface,
712 UINT iTInfo, LCID lcid, ITypeInfo** ppTInfo )
714 saxlocator *This = impl_from_IVBSAXAttributes( iface );
715 HRESULT hr;
717 TRACE("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo);
719 hr = get_typeinfo(IVBSAXAttributes_tid, ppTInfo);
721 return hr;
724 static HRESULT WINAPI ivbsaxattributes_GetIDsOfNames(
725 IVBSAXAttributes *iface,
726 REFIID riid,
727 LPOLESTR* rgszNames,
728 UINT cNames,
729 LCID lcid,
730 DISPID* rgDispId)
732 saxlocator *This = impl_from_IVBSAXAttributes( iface );
733 ITypeInfo *typeinfo;
734 HRESULT hr;
736 TRACE("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames, cNames,
737 lcid, rgDispId);
739 if(!rgszNames || cNames == 0 || !rgDispId)
740 return E_INVALIDARG;
742 hr = get_typeinfo(IVBSAXAttributes_tid, &typeinfo);
743 if(SUCCEEDED(hr))
745 hr = ITypeInfo_GetIDsOfNames(typeinfo, rgszNames, cNames, rgDispId);
746 ITypeInfo_Release(typeinfo);
749 return hr;
752 static HRESULT WINAPI ivbsaxattributes_Invoke(
753 IVBSAXAttributes *iface,
754 DISPID dispIdMember,
755 REFIID riid,
756 LCID lcid,
757 WORD wFlags,
758 DISPPARAMS* pDispParams,
759 VARIANT* pVarResult,
760 EXCEPINFO* pExcepInfo,
761 UINT* puArgErr)
763 saxlocator *This = impl_from_IVBSAXAttributes( iface );
764 ITypeInfo *typeinfo;
765 HRESULT hr;
767 TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
768 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
770 hr = get_typeinfo(IVBSAXAttributes_tid, &typeinfo);
771 if(SUCCEEDED(hr))
773 hr = ITypeInfo_Invoke(typeinfo, &This->IVBSAXAttributes_iface, dispIdMember, wFlags,
774 pDispParams, pVarResult, pExcepInfo, puArgErr);
775 ITypeInfo_Release(typeinfo);
778 return hr;
781 /*** IVBSAXAttributes methods ***/
782 static HRESULT WINAPI ivbsaxattributes_get_length(
783 IVBSAXAttributes* iface,
784 int *nLength)
786 saxlocator *This = impl_from_IVBSAXAttributes( iface );
787 return ISAXAttributes_getLength(&This->ISAXAttributes_iface, nLength);
790 static HRESULT WINAPI ivbsaxattributes_getURI(
791 IVBSAXAttributes* iface,
792 int nIndex,
793 BSTR *uri)
795 int len;
796 saxlocator *This = impl_from_IVBSAXAttributes( iface );
797 return ISAXAttributes_getURI(&This->ISAXAttributes_iface, nIndex, (const WCHAR**)uri, &len);
800 static HRESULT WINAPI ivbsaxattributes_getLocalName(
801 IVBSAXAttributes* iface,
802 int nIndex,
803 BSTR *localName)
805 int len;
806 saxlocator *This = impl_from_IVBSAXAttributes( iface );
807 return ISAXAttributes_getLocalName(&This->ISAXAttributes_iface, nIndex,
808 (const WCHAR**)localName, &len);
811 static HRESULT WINAPI ivbsaxattributes_getQName(
812 IVBSAXAttributes* iface,
813 int nIndex,
814 BSTR *QName)
816 int len;
817 saxlocator *This = impl_from_IVBSAXAttributes( iface );
818 return ISAXAttributes_getQName(&This->ISAXAttributes_iface, nIndex, (const WCHAR**)QName, &len);
821 static HRESULT WINAPI ivbsaxattributes_getIndexFromName(
822 IVBSAXAttributes* iface,
823 BSTR uri,
824 BSTR localName,
825 int *index)
827 saxlocator *This = impl_from_IVBSAXAttributes( iface );
828 return ISAXAttributes_getIndexFromName(&This->ISAXAttributes_iface, uri, SysStringLen(uri),
829 localName, SysStringLen(localName), index);
832 static HRESULT WINAPI ivbsaxattributes_getIndexFromQName(
833 IVBSAXAttributes* iface,
834 BSTR QName,
835 int *index)
837 saxlocator *This = impl_from_IVBSAXAttributes( iface );
838 return ISAXAttributes_getIndexFromQName(&This->ISAXAttributes_iface, QName,
839 SysStringLen(QName), index);
842 static HRESULT WINAPI ivbsaxattributes_getType(
843 IVBSAXAttributes* iface,
844 int nIndex,
845 BSTR *type)
847 int len;
848 saxlocator *This = impl_from_IVBSAXAttributes( iface );
849 return ISAXAttributes_getType(&This->ISAXAttributes_iface, nIndex, (const WCHAR**)type, &len);
852 static HRESULT WINAPI ivbsaxattributes_getTypeFromName(
853 IVBSAXAttributes* iface,
854 BSTR uri,
855 BSTR localName,
856 BSTR *type)
858 int len;
859 saxlocator *This = impl_from_IVBSAXAttributes( iface );
860 return ISAXAttributes_getTypeFromName(&This->ISAXAttributes_iface, uri, SysStringLen(uri),
861 localName, SysStringLen(localName), (const WCHAR**)type, &len);
864 static HRESULT WINAPI ivbsaxattributes_getTypeFromQName(
865 IVBSAXAttributes* iface,
866 BSTR QName,
867 BSTR *type)
869 int len;
870 saxlocator *This = impl_from_IVBSAXAttributes( iface );
871 return ISAXAttributes_getTypeFromQName(&This->ISAXAttributes_iface, QName, SysStringLen(QName),
872 (const WCHAR**)type, &len);
875 static HRESULT WINAPI ivbsaxattributes_getValue(
876 IVBSAXAttributes* iface,
877 int nIndex,
878 BSTR *value)
880 int len;
881 saxlocator *This = impl_from_IVBSAXAttributes( iface );
882 return ISAXAttributes_getValue(&This->ISAXAttributes_iface, nIndex, (const WCHAR**)value, &len);
885 static HRESULT WINAPI ivbsaxattributes_getValueFromName(
886 IVBSAXAttributes* iface,
887 BSTR uri,
888 BSTR localName,
889 BSTR *value)
891 int len;
892 saxlocator *This = impl_from_IVBSAXAttributes( iface );
893 return ISAXAttributes_getValueFromName(&This->ISAXAttributes_iface, uri, SysStringLen(uri),
894 localName, SysStringLen(localName), (const WCHAR**)value, &len);
897 static HRESULT WINAPI ivbsaxattributes_getValueFromQName(
898 IVBSAXAttributes* iface,
899 BSTR QName,
900 BSTR *value)
902 int len;
903 saxlocator *This = impl_from_IVBSAXAttributes( iface );
904 return ISAXAttributes_getValueFromQName(&This->ISAXAttributes_iface, QName,
905 SysStringLen(QName), (const WCHAR**)value, &len);
908 static const struct IVBSAXAttributesVtbl ivbsaxattributes_vtbl =
910 ivbsaxattributes_QueryInterface,
911 ivbsaxattributes_AddRef,
912 ivbsaxattributes_Release,
913 ivbsaxattributes_GetTypeInfoCount,
914 ivbsaxattributes_GetTypeInfo,
915 ivbsaxattributes_GetIDsOfNames,
916 ivbsaxattributes_Invoke,
917 ivbsaxattributes_get_length,
918 ivbsaxattributes_getURI,
919 ivbsaxattributes_getLocalName,
920 ivbsaxattributes_getQName,
921 ivbsaxattributes_getIndexFromName,
922 ivbsaxattributes_getIndexFromQName,
923 ivbsaxattributes_getType,
924 ivbsaxattributes_getTypeFromName,
925 ivbsaxattributes_getTypeFromQName,
926 ivbsaxattributes_getValue,
927 ivbsaxattributes_getValueFromName,
928 ivbsaxattributes_getValueFromQName
931 /*** ISAXAttributes interface ***/
932 /*** IUnknown methods ***/
933 static HRESULT WINAPI isaxattributes_QueryInterface(
934 ISAXAttributes* iface,
935 REFIID riid,
936 void **ppvObject)
938 saxlocator *This = impl_from_ISAXAttributes(iface);
939 TRACE("%p %s %p\n", This, debugstr_guid(riid), ppvObject);
940 return ISAXLocator_QueryInterface(&This->ISAXLocator_iface, riid, ppvObject);
943 static ULONG WINAPI isaxattributes_AddRef(ISAXAttributes* iface)
945 saxlocator *This = impl_from_ISAXAttributes(iface);
946 TRACE("%p\n", This);
947 return ISAXLocator_AddRef(&This->ISAXLocator_iface);
950 static ULONG WINAPI isaxattributes_Release(ISAXAttributes* iface)
952 saxlocator *This = impl_from_ISAXAttributes(iface);
954 TRACE("%p\n", This);
955 return ISAXLocator_Release(&This->ISAXLocator_iface);
958 /*** ISAXAttributes methods ***/
959 static HRESULT WINAPI isaxattributes_getLength(
960 ISAXAttributes* iface,
961 int *length)
963 saxlocator *This = impl_from_ISAXAttributes( iface );
965 *length = This->nb_attributes;
966 TRACE("Length set to %d\n", *length);
967 return S_OK;
970 static HRESULT WINAPI isaxattributes_getURI(
971 ISAXAttributes* iface,
972 int index,
973 const WCHAR **url,
974 int *size)
976 saxlocator *This = impl_from_ISAXAttributes( iface );
977 TRACE("(%p)->(%d)\n", This, index);
979 if(index >= This->nb_attributes || index < 0) return E_INVALIDARG;
980 if(!url || !size) return E_POINTER;
982 *size = SysStringLen(This->attributes[index].szURI);
983 *url = This->attributes[index].szURI;
985 TRACE("(%s:%d)\n", debugstr_w(This->attributes[index].szURI), *size);
987 return S_OK;
990 static HRESULT WINAPI isaxattributes_getLocalName(
991 ISAXAttributes* iface,
992 int nIndex,
993 const WCHAR **pLocalName,
994 int *pLocalNameLength)
996 saxlocator *This = impl_from_ISAXAttributes( iface );
997 TRACE("(%p)->(%d)\n", This, nIndex);
999 if(nIndex>=This->nb_attributes || nIndex<0) return E_INVALIDARG;
1000 if(!pLocalName || !pLocalNameLength) return E_POINTER;
1002 *pLocalNameLength = SysStringLen(This->attributes[nIndex].szLocalname);
1003 *pLocalName = This->attributes[nIndex].szLocalname;
1005 return S_OK;
1008 static HRESULT WINAPI isaxattributes_getQName(
1009 ISAXAttributes* iface,
1010 int nIndex,
1011 const WCHAR **pQName,
1012 int *pQNameLength)
1014 saxlocator *This = impl_from_ISAXAttributes( iface );
1015 TRACE("(%p)->(%d)\n", This, nIndex);
1017 if(nIndex>=This->nb_attributes || nIndex<0) return E_INVALIDARG;
1018 if(!pQName || !pQNameLength) return E_POINTER;
1020 *pQNameLength = SysStringLen(This->attributes[nIndex].szQName);
1021 *pQName = This->attributes[nIndex].szQName;
1023 return S_OK;
1026 static HRESULT WINAPI isaxattributes_getName(
1027 ISAXAttributes* iface,
1028 int index,
1029 const WCHAR **uri,
1030 int *pUriLength,
1031 const WCHAR **localName,
1032 int *pLocalNameSize,
1033 const WCHAR **QName,
1034 int *pQNameLength)
1036 saxlocator *This = impl_from_ISAXAttributes( iface );
1037 TRACE("(%p)->(%d)\n", This, index);
1039 if(index>=This->nb_attributes || index<0) return E_INVALIDARG;
1040 if(!uri || !pUriLength || !localName || !pLocalNameSize
1041 || !QName || !pQNameLength) return E_POINTER;
1043 *pUriLength = SysStringLen(This->attributes[index].szURI);
1044 *uri = This->attributes[index].szURI;
1045 *pLocalNameSize = SysStringLen(This->attributes[index].szLocalname);
1046 *localName = This->attributes[index].szLocalname;
1047 *pQNameLength = SysStringLen(This->attributes[index].szQName);
1048 *QName = This->attributes[index].szQName;
1050 TRACE("(%s, %s, %s)\n", debugstr_w(*uri), debugstr_w(*localName), debugstr_w(*QName));
1052 return S_OK;
1055 static HRESULT WINAPI isaxattributes_getIndexFromName(
1056 ISAXAttributes* iface,
1057 const WCHAR *pUri,
1058 int cUriLength,
1059 const WCHAR *pLocalName,
1060 int cocalNameLength,
1061 int *index)
1063 saxlocator *This = impl_from_ISAXAttributes( iface );
1064 int i;
1065 TRACE("(%p)->(%s, %d, %s, %d)\n", This, debugstr_w(pUri), cUriLength,
1066 debugstr_w(pLocalName), cocalNameLength);
1068 if(!pUri || !pLocalName || !index) return E_POINTER;
1070 for(i=0; i<This->nb_attributes; i++)
1072 if(cUriLength!=SysStringLen(This->attributes[i].szURI)
1073 || cocalNameLength!=SysStringLen(This->attributes[i].szLocalname))
1074 continue;
1075 if(cUriLength && memcmp(pUri, This->attributes[i].szURI,
1076 sizeof(WCHAR)*cUriLength))
1077 continue;
1078 if(cocalNameLength && memcmp(pLocalName, This->attributes[i].szLocalname,
1079 sizeof(WCHAR)*cocalNameLength))
1080 continue;
1082 *index = i;
1083 return S_OK;
1086 return E_INVALIDARG;
1089 static HRESULT WINAPI isaxattributes_getIndexFromQName(
1090 ISAXAttributes* iface,
1091 const WCHAR *pQName,
1092 int nQNameLength,
1093 int *index)
1095 saxlocator *This = impl_from_ISAXAttributes( iface );
1096 int i;
1097 TRACE("(%p)->(%s, %d)\n", This, debugstr_w(pQName), nQNameLength);
1099 if(!pQName || !index) return E_POINTER;
1100 if(!nQNameLength) return E_INVALIDARG;
1102 for(i=0; i<This->nb_attributes; i++)
1104 if(nQNameLength!=SysStringLen(This->attributes[i].szQName)) continue;
1105 if(memcmp(pQName, This->attributes[i].szQName, sizeof(WCHAR)*nQNameLength)) continue;
1107 *index = i;
1108 return S_OK;
1111 return E_INVALIDARG;
1114 static HRESULT WINAPI isaxattributes_getType(
1115 ISAXAttributes* iface,
1116 int nIndex,
1117 const WCHAR **pType,
1118 int *pTypeLength)
1120 saxlocator *This = impl_from_ISAXAttributes( iface );
1122 FIXME("(%p)->(%d) stub\n", This, nIndex);
1123 return E_NOTIMPL;
1126 static HRESULT WINAPI isaxattributes_getTypeFromName(
1127 ISAXAttributes* iface,
1128 const WCHAR *pUri,
1129 int nUri,
1130 const WCHAR *pLocalName,
1131 int nLocalName,
1132 const WCHAR **pType,
1133 int *nType)
1135 saxlocator *This = impl_from_ISAXAttributes( iface );
1137 FIXME("(%p)->(%s, %d, %s, %d) stub\n", This, debugstr_w(pUri), nUri,
1138 debugstr_w(pLocalName), nLocalName);
1139 return E_NOTIMPL;
1142 static HRESULT WINAPI isaxattributes_getTypeFromQName(
1143 ISAXAttributes* iface,
1144 const WCHAR *pQName,
1145 int nQName,
1146 const WCHAR **pType,
1147 int *nType)
1149 saxlocator *This = impl_from_ISAXAttributes( iface );
1151 FIXME("(%p)->(%s, %d) stub\n", This, debugstr_w(pQName), nQName);
1152 return E_NOTIMPL;
1155 static HRESULT WINAPI isaxattributes_getValue(
1156 ISAXAttributes* iface,
1157 int index,
1158 const WCHAR **value,
1159 int *nValue)
1161 saxlocator *This = impl_from_ISAXAttributes( iface );
1162 TRACE("(%p)->(%d)\n", This, index);
1164 if(index>=This->nb_attributes || index<0) return E_INVALIDARG;
1165 if(!value || !nValue) return E_POINTER;
1167 *nValue = SysStringLen(This->attributes[index].szValue);
1168 *value = This->attributes[index].szValue;
1170 TRACE("(%s:%d)\n", debugstr_w(*value), *nValue);
1172 return S_OK;
1175 static HRESULT WINAPI isaxattributes_getValueFromName(
1176 ISAXAttributes* iface,
1177 const WCHAR *pUri,
1178 int nUri,
1179 const WCHAR *pLocalName,
1180 int nLocalName,
1181 const WCHAR **pValue,
1182 int *nValue)
1184 HRESULT hr;
1185 int index;
1186 saxlocator *This = impl_from_ISAXAttributes( iface );
1187 TRACE("(%p)->(%s, %d, %s, %d)\n", This, debugstr_w(pUri), nUri,
1188 debugstr_w(pLocalName), nLocalName);
1190 hr = ISAXAttributes_getIndexFromName(iface,
1191 pUri, nUri, pLocalName, nLocalName, &index);
1192 if(hr==S_OK) hr = ISAXAttributes_getValue(iface, index, pValue, nValue);
1194 return hr;
1197 static HRESULT WINAPI isaxattributes_getValueFromQName(
1198 ISAXAttributes* iface,
1199 const WCHAR *pQName,
1200 int nQName,
1201 const WCHAR **pValue,
1202 int *nValue)
1204 HRESULT hr;
1205 int index;
1206 saxlocator *This = impl_from_ISAXAttributes( iface );
1207 TRACE("(%p)->(%s, %d)\n", This, debugstr_w(pQName), nQName);
1209 hr = ISAXAttributes_getIndexFromQName(iface, pQName, nQName, &index);
1210 if(hr==S_OK) hr = ISAXAttributes_getValue(iface, index, pValue, nValue);
1212 return hr;
1215 static const struct ISAXAttributesVtbl isaxattributes_vtbl =
1217 isaxattributes_QueryInterface,
1218 isaxattributes_AddRef,
1219 isaxattributes_Release,
1220 isaxattributes_getLength,
1221 isaxattributes_getURI,
1222 isaxattributes_getLocalName,
1223 isaxattributes_getQName,
1224 isaxattributes_getName,
1225 isaxattributes_getIndexFromName,
1226 isaxattributes_getIndexFromQName,
1227 isaxattributes_getType,
1228 isaxattributes_getTypeFromName,
1229 isaxattributes_getTypeFromQName,
1230 isaxattributes_getValue,
1231 isaxattributes_getValueFromName,
1232 isaxattributes_getValueFromQName
1235 static HRESULT SAXAttributes_populate(saxlocator *locator,
1236 int nb_namespaces, const xmlChar **xmlNamespaces,
1237 int nb_attributes, const xmlChar **xmlAttributes)
1239 static const xmlChar xmlns[] = "xmlns";
1240 static const WCHAR xmlnsW[] = { 'x','m','l','n','s',0 };
1242 struct _attributes *attrs;
1243 int i;
1245 /* skip namespace definitions */
1246 if ((locator->saxreader->features & NamespacePrefixes) == 0)
1247 nb_namespaces = 0;
1249 locator->nb_attributes = nb_namespaces + nb_attributes;
1250 if(locator->nb_attributes > locator->attributesSize)
1252 attrs = heap_realloc(locator->attributes, sizeof(struct _attributes)*locator->nb_attributes*2);
1253 if(!attrs)
1255 locator->nb_attributes = 0;
1256 return E_OUTOFMEMORY;
1258 locator->attributes = attrs;
1260 else
1262 attrs = locator->attributes;
1265 for (i = 0; i < nb_namespaces; i++)
1267 attrs[nb_attributes+i].szLocalname = SysAllocStringLen(NULL, 0);
1268 attrs[nb_attributes+i].szURI = locator->namespaceUri;
1269 attrs[nb_attributes+i].szValue = bstr_from_xmlChar(xmlNamespaces[2*i+1]);
1270 if(!xmlNamespaces[2*i])
1271 attrs[nb_attributes+i].szQName = SysAllocString(xmlnsW);
1272 else
1273 attrs[nb_attributes+i].szQName = QName_from_xmlChar(xmlns, xmlNamespaces[2*i]);
1276 for (i = 0; i < nb_attributes; i++)
1278 static const xmlChar xmlA[] = "xml";
1280 if (xmlStrEqual(xmlAttributes[i*5+1], xmlA))
1281 attrs[i].szURI = bstr_from_xmlChar(xmlAttributes[i*5+2]);
1282 else
1283 /* that's an important feature to keep same uri pointer for every reported attribute */
1284 attrs[i].szURI = find_element_uri(locator, xmlAttributes[i*5+2]);
1286 attrs[i].szLocalname = bstr_from_xmlChar(xmlAttributes[i*5]);
1287 attrs[i].szValue = bstr_from_xmlCharN(xmlAttributes[i*5+3],
1288 xmlAttributes[i*5+4]-xmlAttributes[i*5+3]);
1289 attrs[i].szQName = QName_from_xmlChar(xmlAttributes[i*5+1],
1290 xmlAttributes[i*5]);
1293 return S_OK;
1296 /*** LibXML callbacks ***/
1297 static void libxmlStartDocument(void *ctx)
1299 saxlocator *This = ctx;
1300 struct saxcontenthandler_iface *handler = saxreader_get_contenthandler(This->saxreader);
1301 HRESULT hr;
1303 if (This->saxreader->version >= MSXML4)
1305 const xmlChar *p = This->pParserCtxt->input->cur-1;
1306 update_position(This, FALSE);
1307 while(p>This->pParserCtxt->input->base && *p!='>')
1309 if(*p=='\n' || (*p=='\r' && *(p+1)!='\n'))
1310 This->line--;
1311 p--;
1313 This->column = 0;
1314 for(; p>=This->pParserCtxt->input->base && *p!='\n' && *p!='\r'; p--)
1315 This->column++;
1318 /* store version value, declaration has to contain version attribute */
1319 if (This->pParserCtxt->standalone != -1)
1321 SysFreeString(This->saxreader->xmldecl_version);
1322 This->saxreader->xmldecl_version = bstr_from_xmlChar(This->pParserCtxt->version);
1325 if (saxreader_has_handler(This, SAXContentHandler))
1327 if(This->vbInterface)
1328 hr = IVBSAXContentHandler_startDocument(handler->vbhandler);
1329 else
1330 hr = ISAXContentHandler_startDocument(handler->handler);
1332 if (sax_callback_failed(This, hr))
1333 format_error_message_from_id(This, hr);
1337 static void libxmlEndDocument(void *ctx)
1339 saxlocator *This = ctx;
1340 struct saxcontenthandler_iface *handler = saxreader_get_contenthandler(This->saxreader);
1341 HRESULT hr;
1343 if (This->saxreader->version >= MSXML4) {
1344 update_position(This, FALSE);
1345 if(This->column > 1)
1346 This->line++;
1347 This->column = 0;
1348 } else {
1349 This->column = 0;
1350 This->line = 0;
1353 if(This->ret != S_OK) return;
1355 if (saxreader_has_handler(This, SAXContentHandler))
1357 if(This->vbInterface)
1358 hr = IVBSAXContentHandler_endDocument(handler->vbhandler);
1359 else
1360 hr = ISAXContentHandler_endDocument(handler->handler);
1362 if (sax_callback_failed(This, hr))
1363 format_error_message_from_id(This, hr);
1367 static void libxmlStartElementNS(
1368 void *ctx,
1369 const xmlChar *localname,
1370 const xmlChar *prefix,
1371 const xmlChar *URI,
1372 int nb_namespaces,
1373 const xmlChar **namespaces,
1374 int nb_attributes,
1375 int nb_defaulted,
1376 const xmlChar **attributes)
1378 saxlocator *This = ctx;
1379 struct saxcontenthandler_iface *handler = saxreader_get_contenthandler(This->saxreader);
1380 element_entry *element;
1381 HRESULT hr = S_OK;
1382 BSTR uri;
1384 update_position(This, TRUE);
1385 if(*(This->pParserCtxt->input->cur) == '/')
1386 This->column++;
1387 if(This->saxreader->version < MSXML4)
1388 This->column++;
1390 element = alloc_element_entry(localname, prefix, nb_namespaces, namespaces);
1391 push_element_ns(This, element);
1393 if (is_namespaces_enabled(This->saxreader))
1395 int i;
1397 for (i = 0; i < nb_namespaces && saxreader_has_handler(This, SAXContentHandler); i++)
1399 if (This->vbInterface)
1400 hr = IVBSAXContentHandler_startPrefixMapping(
1401 handler->vbhandler,
1402 &element->ns[i].prefix,
1403 &element->ns[i].uri);
1404 else
1405 hr = ISAXContentHandler_startPrefixMapping(
1406 handler->handler,
1407 element->ns[i].prefix,
1408 SysStringLen(element->ns[i].prefix),
1409 element->ns[i].uri,
1410 SysStringLen(element->ns[i].uri));
1412 if (sax_callback_failed(This, hr))
1414 format_error_message_from_id(This, hr);
1415 return;
1420 uri = find_element_uri(This, URI);
1421 hr = SAXAttributes_populate(This, nb_namespaces, namespaces, nb_attributes, attributes);
1422 if (hr == S_OK && saxreader_has_handler(This, SAXContentHandler))
1424 BSTR local;
1426 if (is_namespaces_enabled(This->saxreader))
1427 local = element->local;
1428 else
1429 uri = local = NULL;
1431 if (This->vbInterface)
1432 hr = IVBSAXContentHandler_startElement(handler->vbhandler,
1433 &uri, &local, &element->qname, &This->IVBSAXAttributes_iface);
1434 else
1435 hr = ISAXContentHandler_startElement(handler->handler,
1436 uri, SysStringLen(uri),
1437 local, SysStringLen(local),
1438 element->qname, SysStringLen(element->qname),
1439 &This->ISAXAttributes_iface);
1441 if (sax_callback_failed(This, hr))
1442 format_error_message_from_id(This, hr);
1446 static void libxmlEndElementNS(
1447 void *ctx,
1448 const xmlChar *localname,
1449 const xmlChar *prefix,
1450 const xmlChar *URI)
1452 saxlocator *This = ctx;
1453 struct saxcontenthandler_iface *handler = saxreader_get_contenthandler(This->saxreader);
1454 element_entry *element;
1455 const xmlChar *p;
1456 BSTR uri, local;
1457 HRESULT hr;
1459 update_position(This, FALSE);
1460 p = This->pParserCtxt->input->cur;
1462 if (This->saxreader->version >= MSXML4)
1464 p--;
1465 while(p>This->pParserCtxt->input->base && *p!='>')
1467 if(*p=='\n' || (*p=='\r' && *(p+1)!='\n'))
1468 This->line--;
1469 p--;
1472 else if(*(p-1)!='>' || *(p-2)!='/')
1474 p--;
1475 while(p-2>=This->pParserCtxt->input->base
1476 && *(p-2)!='<' && *(p-1)!='/')
1478 if(*p=='\n' || (*p=='\r' && *(p+1)!='\n'))
1479 This->line--;
1480 p--;
1483 This->column = 0;
1484 for(; p>=This->pParserCtxt->input->base && *p!='\n' && *p!='\r'; p--)
1485 This->column++;
1487 uri = find_element_uri(This, URI);
1488 element = pop_element_ns(This);
1490 if (!saxreader_has_handler(This, SAXContentHandler))
1492 This->nb_attributes = 0;
1493 free_element_entry(element);
1494 return;
1497 if (is_namespaces_enabled(This->saxreader))
1498 local = element->local;
1499 else
1500 uri = local = NULL;
1502 if (This->vbInterface)
1503 hr = IVBSAXContentHandler_endElement(
1504 handler->vbhandler,
1505 &uri, &local, &element->qname);
1506 else
1507 hr = ISAXContentHandler_endElement(
1508 handler->handler,
1509 uri, SysStringLen(uri),
1510 local, SysStringLen(local),
1511 element->qname, SysStringLen(element->qname));
1513 This->nb_attributes = 0;
1515 if (sax_callback_failed(This, hr))
1517 format_error_message_from_id(This, hr);
1518 free_element_entry(element);
1519 return;
1522 if (is_namespaces_enabled(This->saxreader))
1524 int i = -1;
1525 while (iterate_endprefix_index(This, element, &i) && saxreader_has_handler(This, SAXContentHandler))
1527 if (This->vbInterface)
1528 hr = IVBSAXContentHandler_endPrefixMapping(
1529 handler->vbhandler, &element->ns[i].prefix);
1530 else
1531 hr = ISAXContentHandler_endPrefixMapping(
1532 handler->handler, element->ns[i].prefix, SysStringLen(element->ns[i].prefix));
1534 if (sax_callback_failed(This, hr)) break;
1537 if (sax_callback_failed(This, hr))
1538 format_error_message_from_id(This, hr);
1541 free_element_entry(element);
1544 static void libxmlCharacters(
1545 void *ctx,
1546 const xmlChar *ch,
1547 int len)
1549 saxlocator *This = ctx;
1550 struct saxcontenthandler_iface *handler = saxreader_get_contenthandler(This->saxreader);
1551 BSTR Chars;
1552 HRESULT hr;
1553 xmlChar *cur, *end;
1554 BOOL lastEvent = FALSE;
1556 if (!saxreader_has_handler(This, SAXContentHandler)) return;
1558 update_position(This, FALSE);
1559 cur = (xmlChar*)This->pParserCtxt->input->cur;
1560 while(cur>=This->pParserCtxt->input->base && *cur!='>')
1562 if(*cur=='\n' || (*cur=='\r' && *(cur+1)!='\n'))
1563 This->line--;
1564 cur--;
1566 This->column = 1;
1567 for(; cur>=This->pParserCtxt->input->base && *cur!='\n' && *cur!='\r'; cur--)
1568 This->column++;
1570 cur = (xmlChar*)ch;
1571 if(*(ch-1)=='\r') cur--;
1572 end = cur;
1574 while(1)
1576 while(end-ch<len && *end!='\r') end++;
1577 if(end-ch==len)
1579 lastEvent = TRUE;
1581 else
1583 *end = '\n';
1584 end++;
1587 if (This->saxreader->version >= MSXML4)
1589 xmlChar *p;
1591 for(p=cur; p!=end; p++)
1593 if(*p=='\n')
1595 This->line++;
1596 This->column = 1;
1598 else
1600 This->column++;
1604 if(!lastEvent)
1605 This->column = 0;
1608 Chars = pooled_bstr_from_xmlCharN(&This->saxreader->pool, cur, end-cur);
1609 if(This->vbInterface)
1610 hr = IVBSAXContentHandler_characters(handler->vbhandler, &Chars);
1611 else
1612 hr = ISAXContentHandler_characters(handler->handler, Chars, SysStringLen(Chars));
1614 if (sax_callback_failed(This, hr))
1616 format_error_message_from_id(This, hr);
1617 return;
1620 if (This->saxreader->version < MSXML4)
1621 This->column += end-cur;
1623 if(lastEvent)
1624 break;
1626 *(end-1) = '\r';
1627 if(*end == '\n')
1629 end++;
1630 This->column++;
1632 cur = end;
1634 if(end-ch == len) break;
1638 static void libxmlSetDocumentLocator(
1639 void *ctx,
1640 xmlSAXLocatorPtr loc)
1642 saxlocator *This = ctx;
1643 struct saxcontenthandler_iface *handler = saxreader_get_contenthandler(This->saxreader);
1644 HRESULT hr = S_OK;
1646 if (saxreader_has_handler(This, SAXContentHandler))
1648 if(This->vbInterface)
1649 hr = IVBSAXContentHandler_putref_documentLocator(handler->vbhandler,
1650 &This->IVBSAXLocator_iface);
1651 else
1652 hr = ISAXContentHandler_putDocumentLocator(handler->handler, &This->ISAXLocator_iface);
1655 if(FAILED(hr))
1656 format_error_message_from_id(This, hr);
1659 static void libxmlComment(void *ctx, const xmlChar *value)
1661 saxlocator *This = ctx;
1662 struct saxlexicalhandler_iface *handler = saxreader_get_lexicalhandler(This->saxreader);
1663 BSTR bValue;
1664 HRESULT hr;
1665 const xmlChar *p = This->pParserCtxt->input->cur;
1667 update_position(This, FALSE);
1668 while(p-4>=This->pParserCtxt->input->base
1669 && memcmp(p-4, "<!--", sizeof(char[4])))
1671 if(*p=='\n' || (*p=='\r' && *(p+1)!='\n'))
1672 This->line--;
1673 p--;
1676 This->column = 0;
1677 for(; p>=This->pParserCtxt->input->base && *p!='\n' && *p!='\r'; p--)
1678 This->column++;
1680 if (!saxreader_has_handler(This, SAXLexicalHandler)) return;
1682 bValue = pooled_bstr_from_xmlChar(&This->saxreader->pool, value);
1684 if (This->vbInterface)
1685 hr = IVBSAXLexicalHandler_comment(handler->vbhandler, &bValue);
1686 else
1687 hr = ISAXLexicalHandler_comment(handler->handler, bValue, SysStringLen(bValue));
1689 if(FAILED(hr))
1690 format_error_message_from_id(This, hr);
1693 static void libxmlFatalError(void *ctx, const char *msg, ...)
1695 saxlocator *This = ctx;
1696 struct saxerrorhandler_iface *handler = saxreader_get_errorhandler(This->saxreader);
1697 char message[1024];
1698 WCHAR *error;
1699 DWORD len;
1700 va_list args;
1702 if(This->ret != S_OK) {
1703 xmlStopParser(This->pParserCtxt);
1704 return;
1707 va_start(args, msg);
1708 vsprintf(message, msg, args);
1709 va_end(args);
1711 len = MultiByteToWideChar(CP_UNIXCP, 0, message, -1, NULL, 0);
1712 error = heap_alloc(sizeof(WCHAR)*len);
1713 if(error)
1715 MultiByteToWideChar(CP_UNIXCP, 0, message, -1, error, len);
1716 TRACE("fatal error for %p: %s\n", This, debugstr_w(error));
1719 if (!saxreader_has_handler(This, SAXErrorHandler))
1721 xmlStopParser(This->pParserCtxt);
1722 This->ret = E_FAIL;
1723 heap_free(error);
1724 return;
1727 FIXME("Error handling is not compatible.\n");
1729 if(This->vbInterface)
1731 BSTR bstrError = SysAllocString(error);
1732 IVBSAXErrorHandler_fatalError(handler->vbhandler, &This->IVBSAXLocator_iface,
1733 &bstrError, E_FAIL);
1734 SysFreeString(bstrError);
1736 else
1737 ISAXErrorHandler_fatalError(handler->handler, &This->ISAXLocator_iface, error, E_FAIL);
1739 heap_free(error);
1741 xmlStopParser(This->pParserCtxt);
1742 This->ret = E_FAIL;
1745 static void libxmlCDataBlock(void *ctx, const xmlChar *value, int len)
1747 saxlocator *This = ctx;
1748 struct saxcontenthandler_iface *content = saxreader_get_contenthandler(This->saxreader);
1749 struct saxlexicalhandler_iface *lexical = saxreader_get_lexicalhandler(This->saxreader);
1750 HRESULT hr = S_OK;
1751 xmlChar *beg = (xmlChar*)This->pParserCtxt->input->cur-len;
1752 xmlChar *cur, *end;
1753 int realLen;
1754 BSTR Chars;
1755 BOOL lastEvent = FALSE, change;
1757 update_position(This, FALSE);
1758 while(beg-9>=This->pParserCtxt->input->base
1759 && memcmp(beg-9, "<![CDATA[", sizeof(char[9])))
1761 if(*beg=='\n' || (*beg=='\r' && *(beg+1)!='\n'))
1762 This->line--;
1763 beg--;
1765 This->column = 0;
1766 for(; beg>=This->pParserCtxt->input->base && *beg!='\n' && *beg!='\r'; beg--)
1767 This->column++;
1769 if (saxreader_has_handler(This, SAXLexicalHandler))
1771 if (This->vbInterface)
1772 hr = IVBSAXLexicalHandler_startCDATA(lexical->vbhandler);
1773 else
1774 hr = ISAXLexicalHandler_startCDATA(lexical->handler);
1777 if(FAILED(hr))
1779 format_error_message_from_id(This, hr);
1780 return;
1783 realLen = This->pParserCtxt->input->cur-beg-3;
1784 cur = beg;
1785 end = beg;
1787 while(1)
1789 while(end-beg<realLen && *end!='\r') end++;
1790 if(end-beg==realLen)
1792 end--;
1793 lastEvent = TRUE;
1795 else if(end-beg==realLen-1 && *end=='\r' && *(end+1)=='\n')
1796 lastEvent = TRUE;
1798 if(*end == '\r') change = TRUE;
1799 else change = FALSE;
1801 if(change) *end = '\n';
1803 if (saxreader_has_handler(This, SAXContentHandler))
1805 Chars = pooled_bstr_from_xmlCharN(&This->saxreader->pool, cur, end-cur+1);
1806 if (This->vbInterface)
1807 hr = IVBSAXContentHandler_characters(content->vbhandler, &Chars);
1808 else
1809 hr = ISAXContentHandler_characters(content->handler, Chars, SysStringLen(Chars));
1812 if(change) *end = '\r';
1814 if(lastEvent)
1815 break;
1817 This->column += end-cur+2;
1818 end += 2;
1819 cur = end;
1822 if (saxreader_has_handler(This, SAXLexicalHandler))
1824 if (This->vbInterface)
1825 hr = IVBSAXLexicalHandler_endCDATA(lexical->vbhandler);
1826 else
1827 hr = ISAXLexicalHandler_endCDATA(lexical->handler);
1830 if(FAILED(hr))
1831 format_error_message_from_id(This, hr);
1833 This->column += 4+end-cur;
1836 /*** IVBSAXLocator interface ***/
1837 /*** IUnknown methods ***/
1838 static HRESULT WINAPI ivbsaxlocator_QueryInterface(IVBSAXLocator* iface, REFIID riid, void **ppvObject)
1840 saxlocator *This = impl_from_IVBSAXLocator( iface );
1842 TRACE("%p %s %p\n", This, debugstr_guid( riid ), ppvObject);
1844 *ppvObject = NULL;
1846 if ( IsEqualGUID( riid, &IID_IUnknown ) ||
1847 IsEqualGUID( riid, &IID_IDispatch) ||
1848 IsEqualGUID( riid, &IID_IVBSAXLocator ))
1850 *ppvObject = iface;
1852 else if ( IsEqualGUID( riid, &IID_IVBSAXAttributes ))
1854 *ppvObject = &This->IVBSAXAttributes_iface;
1856 else
1858 FIXME("interface %s not implemented\n", debugstr_guid(riid));
1859 return E_NOINTERFACE;
1862 IVBSAXLocator_AddRef( iface );
1864 return S_OK;
1867 static ULONG WINAPI ivbsaxlocator_AddRef(IVBSAXLocator* iface)
1869 saxlocator *This = impl_from_IVBSAXLocator( iface );
1870 TRACE("%p\n", This );
1871 return InterlockedIncrement( &This->ref );
1874 static ULONG WINAPI ivbsaxlocator_Release(
1875 IVBSAXLocator* iface)
1877 saxlocator *This = impl_from_IVBSAXLocator( iface );
1878 return ISAXLocator_Release((ISAXLocator*)&This->IVBSAXLocator_iface);
1881 /*** IDispatch methods ***/
1882 static HRESULT WINAPI ivbsaxlocator_GetTypeInfoCount( IVBSAXLocator *iface, UINT* pctinfo )
1884 saxlocator *This = impl_from_IVBSAXLocator( iface );
1886 TRACE("(%p)->(%p)\n", This, pctinfo);
1888 *pctinfo = 1;
1890 return S_OK;
1893 static HRESULT WINAPI ivbsaxlocator_GetTypeInfo(
1894 IVBSAXLocator *iface,
1895 UINT iTInfo, LCID lcid, ITypeInfo** ppTInfo )
1897 saxlocator *This = impl_from_IVBSAXLocator( iface );
1898 HRESULT hr;
1900 TRACE("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo);
1902 hr = get_typeinfo(IVBSAXLocator_tid, ppTInfo);
1904 return hr;
1907 static HRESULT WINAPI ivbsaxlocator_GetIDsOfNames(
1908 IVBSAXLocator *iface,
1909 REFIID riid,
1910 LPOLESTR* rgszNames,
1911 UINT cNames,
1912 LCID lcid,
1913 DISPID* rgDispId)
1915 saxlocator *This = impl_from_IVBSAXLocator( iface );
1916 ITypeInfo *typeinfo;
1917 HRESULT hr;
1919 TRACE("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames, cNames,
1920 lcid, rgDispId);
1922 if(!rgszNames || cNames == 0 || !rgDispId)
1923 return E_INVALIDARG;
1925 hr = get_typeinfo(IVBSAXLocator_tid, &typeinfo);
1926 if(SUCCEEDED(hr))
1928 hr = ITypeInfo_GetIDsOfNames(typeinfo, rgszNames, cNames, rgDispId);
1929 ITypeInfo_Release(typeinfo);
1932 return hr;
1935 static HRESULT WINAPI ivbsaxlocator_Invoke(
1936 IVBSAXLocator *iface,
1937 DISPID dispIdMember,
1938 REFIID riid,
1939 LCID lcid,
1940 WORD wFlags,
1941 DISPPARAMS* pDispParams,
1942 VARIANT* pVarResult,
1943 EXCEPINFO* pExcepInfo,
1944 UINT* puArgErr)
1946 saxlocator *This = impl_from_IVBSAXLocator( iface );
1947 ITypeInfo *typeinfo;
1948 HRESULT hr;
1950 TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
1951 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
1953 hr = get_typeinfo(IVBSAXLocator_tid, &typeinfo);
1954 if(SUCCEEDED(hr))
1956 hr = ITypeInfo_Invoke(typeinfo, &This->IVBSAXLocator_iface, dispIdMember, wFlags,
1957 pDispParams, pVarResult, pExcepInfo, puArgErr);
1958 ITypeInfo_Release(typeinfo);
1961 return hr;
1964 /*** IVBSAXLocator methods ***/
1965 static HRESULT WINAPI ivbsaxlocator_get_columnNumber(
1966 IVBSAXLocator* iface,
1967 int *pnColumn)
1969 saxlocator *This = impl_from_IVBSAXLocator( iface );
1970 return ISAXLocator_getColumnNumber((ISAXLocator*)&This->IVBSAXLocator_iface, pnColumn);
1973 static HRESULT WINAPI ivbsaxlocator_get_lineNumber(
1974 IVBSAXLocator* iface,
1975 int *pnLine)
1977 saxlocator *This = impl_from_IVBSAXLocator( iface );
1978 return ISAXLocator_getLineNumber((ISAXLocator*)&This->IVBSAXLocator_iface, pnLine);
1981 static HRESULT WINAPI ivbsaxlocator_get_publicId(
1982 IVBSAXLocator* iface,
1983 BSTR* publicId)
1985 saxlocator *This = impl_from_IVBSAXLocator( iface );
1986 return ISAXLocator_getPublicId((ISAXLocator*)&This->IVBSAXLocator_iface,
1987 (const WCHAR**)publicId);
1990 static HRESULT WINAPI ivbsaxlocator_get_systemId(
1991 IVBSAXLocator* iface,
1992 BSTR* systemId)
1994 saxlocator *This = impl_from_IVBSAXLocator( iface );
1995 return ISAXLocator_getSystemId((ISAXLocator*)&This->IVBSAXLocator_iface,
1996 (const WCHAR**)systemId);
1999 static const struct IVBSAXLocatorVtbl VBSAXLocatorVtbl =
2001 ivbsaxlocator_QueryInterface,
2002 ivbsaxlocator_AddRef,
2003 ivbsaxlocator_Release,
2004 ivbsaxlocator_GetTypeInfoCount,
2005 ivbsaxlocator_GetTypeInfo,
2006 ivbsaxlocator_GetIDsOfNames,
2007 ivbsaxlocator_Invoke,
2008 ivbsaxlocator_get_columnNumber,
2009 ivbsaxlocator_get_lineNumber,
2010 ivbsaxlocator_get_publicId,
2011 ivbsaxlocator_get_systemId
2014 /*** ISAXLocator interface ***/
2015 /*** IUnknown methods ***/
2016 static HRESULT WINAPI isaxlocator_QueryInterface(ISAXLocator* iface, REFIID riid, void **ppvObject)
2018 saxlocator *This = impl_from_ISAXLocator( iface );
2020 TRACE("%p %s %p\n", This, debugstr_guid( riid ), ppvObject );
2022 *ppvObject = NULL;
2024 if ( IsEqualGUID( riid, &IID_IUnknown ) ||
2025 IsEqualGUID( riid, &IID_ISAXLocator ))
2027 *ppvObject = iface;
2029 else if ( IsEqualGUID( riid, &IID_ISAXAttributes ))
2031 *ppvObject = &This->ISAXAttributes_iface;
2033 else
2035 WARN("interface %s not implemented\n", debugstr_guid(riid));
2036 return E_NOINTERFACE;
2039 ISAXLocator_AddRef( iface );
2041 return S_OK;
2044 static ULONG WINAPI isaxlocator_AddRef(ISAXLocator* iface)
2046 saxlocator *This = impl_from_ISAXLocator( iface );
2047 ULONG ref = InterlockedIncrement( &This->ref );
2048 TRACE("(%p)->(%d)\n", This, ref);
2049 return ref;
2052 static ULONG WINAPI isaxlocator_Release(
2053 ISAXLocator* iface)
2055 saxlocator *This = impl_from_ISAXLocator( iface );
2056 LONG ref = InterlockedDecrement( &This->ref );
2058 TRACE("(%p)->(%d)\n", This, ref );
2060 if (ref == 0)
2062 element_entry *element, *element2;
2063 int index;
2065 SysFreeString(This->publicId);
2066 SysFreeString(This->systemId);
2067 SysFreeString(This->namespaceUri);
2069 for(index=0; index<This->nb_attributes; index++)
2071 SysFreeString(This->attributes[index].szLocalname);
2072 SysFreeString(This->attributes[index].szValue);
2073 SysFreeString(This->attributes[index].szQName);
2075 heap_free(This->attributes);
2077 /* element stack */
2078 LIST_FOR_EACH_ENTRY_SAFE(element, element2, &This->elements, element_entry, entry)
2080 list_remove(&element->entry);
2081 free_element_entry(element);
2084 ISAXXMLReader_Release(&This->saxreader->ISAXXMLReader_iface);
2085 heap_free( This );
2088 return ref;
2091 /*** ISAXLocator methods ***/
2092 static HRESULT WINAPI isaxlocator_getColumnNumber(
2093 ISAXLocator* iface,
2094 int *pnColumn)
2096 saxlocator *This = impl_from_ISAXLocator( iface );
2098 *pnColumn = This->column;
2099 return S_OK;
2102 static HRESULT WINAPI isaxlocator_getLineNumber(
2103 ISAXLocator* iface,
2104 int *pnLine)
2106 saxlocator *This = impl_from_ISAXLocator( iface );
2108 *pnLine = This->line;
2109 return S_OK;
2112 static HRESULT WINAPI isaxlocator_getPublicId(
2113 ISAXLocator* iface,
2114 const WCHAR ** ppwchPublicId)
2116 BSTR publicId;
2117 saxlocator *This = impl_from_ISAXLocator( iface );
2119 SysFreeString(This->publicId);
2121 publicId = bstr_from_xmlChar(xmlSAX2GetPublicId(This->pParserCtxt));
2122 if(SysStringLen(publicId))
2123 This->publicId = (WCHAR*)&publicId;
2124 else
2126 SysFreeString(publicId);
2127 This->publicId = NULL;
2130 *ppwchPublicId = This->publicId;
2131 return S_OK;
2134 static HRESULT WINAPI isaxlocator_getSystemId(
2135 ISAXLocator* iface,
2136 const WCHAR ** ppwchSystemId)
2138 BSTR systemId;
2139 saxlocator *This = impl_from_ISAXLocator( iface );
2141 SysFreeString(This->systemId);
2143 systemId = bstr_from_xmlChar(xmlSAX2GetSystemId(This->pParserCtxt));
2144 if(SysStringLen(systemId))
2145 This->systemId = (WCHAR*)&systemId;
2146 else
2148 SysFreeString(systemId);
2149 This->systemId = NULL;
2152 *ppwchSystemId = This->systemId;
2153 return S_OK;
2156 static const struct ISAXLocatorVtbl SAXLocatorVtbl =
2158 isaxlocator_QueryInterface,
2159 isaxlocator_AddRef,
2160 isaxlocator_Release,
2161 isaxlocator_getColumnNumber,
2162 isaxlocator_getLineNumber,
2163 isaxlocator_getPublicId,
2164 isaxlocator_getSystemId
2167 static HRESULT SAXLocator_create(saxreader *reader, saxlocator **ppsaxlocator, BOOL vbInterface)
2169 static const WCHAR w3xmlns[] = { 'h','t','t','p',':','/','/', 'w','w','w','.','w','3','.',
2170 'o','r','g','/','2','0','0','0','/','x','m','l','n','s','/',0 };
2172 saxlocator *locator;
2174 locator = heap_alloc( sizeof (*locator) );
2175 if( !locator )
2176 return E_OUTOFMEMORY;
2178 locator->IVBSAXLocator_iface.lpVtbl = &VBSAXLocatorVtbl;
2179 locator->ISAXLocator_iface.lpVtbl = &SAXLocatorVtbl;
2180 locator->IVBSAXAttributes_iface.lpVtbl = &ivbsaxattributes_vtbl;
2181 locator->ISAXAttributes_iface.lpVtbl = &isaxattributes_vtbl;
2182 locator->ref = 1;
2183 locator->vbInterface = vbInterface;
2185 locator->saxreader = reader;
2186 ISAXXMLReader_AddRef(&reader->ISAXXMLReader_iface);
2188 locator->pParserCtxt = NULL;
2189 locator->publicId = NULL;
2190 locator->systemId = NULL;
2191 locator->line = reader->version < MSXML4 ? 0 : 1;
2192 locator->column = 0;
2193 locator->ret = S_OK;
2194 if (locator->saxreader->version >= MSXML6)
2195 locator->namespaceUri = SysAllocString(w3xmlns);
2196 else
2197 locator->namespaceUri = SysAllocStringLen(NULL, 0);
2198 if(!locator->namespaceUri)
2200 ISAXXMLReader_Release(&reader->ISAXXMLReader_iface);
2201 heap_free(locator);
2202 return E_OUTOFMEMORY;
2205 locator->attributesSize = 8;
2206 locator->nb_attributes = 0;
2207 locator->attributes = heap_alloc(sizeof(struct _attributes)*locator->attributesSize);
2208 if(!locator->attributes)
2210 ISAXXMLReader_Release(&reader->ISAXXMLReader_iface);
2211 SysFreeString(locator->namespaceUri);
2212 heap_free(locator);
2213 return E_OUTOFMEMORY;
2216 list_init(&locator->elements);
2218 *ppsaxlocator = locator;
2220 TRACE("returning %p\n", *ppsaxlocator);
2222 return S_OK;
2225 /*** SAXXMLReader internal functions ***/
2226 static HRESULT internal_parseBuffer(saxreader *This, const char *buffer, int size, BOOL vbInterface)
2228 xmlCharEncoding encoding = XML_CHAR_ENCODING_NONE;
2229 xmlChar *enc_name = NULL;
2230 saxlocator *locator;
2231 HRESULT hr;
2233 TRACE("(%p)->(%p %d)\n", This, buffer, size);
2235 hr = SAXLocator_create(This, &locator, vbInterface);
2236 if (FAILED(hr))
2237 return hr;
2239 if (size >= 4)
2241 const unsigned char *buff = (unsigned char*)buffer;
2243 encoding = xmlDetectCharEncoding((xmlChar*)buffer, 4);
2244 enc_name = (xmlChar*)xmlGetCharEncodingName(encoding);
2245 TRACE("detected encoding: %s\n", enc_name);
2246 /* skip BOM, parser won't switch encodings and so won't skip it on its own */
2247 if ((encoding == XML_CHAR_ENCODING_UTF8) &&
2248 buff[0] == 0xEF && buff[1] == 0xBB && buff[2] == 0xBF)
2250 buffer += 3;
2251 size -= 3;
2255 /* if libxml2 detection failed try to guess */
2256 if (encoding == XML_CHAR_ENCODING_NONE)
2258 const WCHAR *ptr = (WCHAR*)buffer;
2259 /* xml declaration with possibly specfied encoding will be still handled by parser */
2260 if ((size >= 2) && *ptr == '<' && ptr[1] != '?')
2262 enc_name = (xmlChar*)xmlGetCharEncodingName(XML_CHAR_ENCODING_UTF16LE);
2263 encoding = XML_CHAR_ENCODING_UTF16LE;
2266 else if (encoding == XML_CHAR_ENCODING_UTF8)
2267 enc_name = (xmlChar*)xmlGetCharEncodingName(encoding);
2268 else
2269 enc_name = NULL;
2271 locator->pParserCtxt = xmlCreateMemoryParserCtxt(buffer, size);
2272 if (!locator->pParserCtxt)
2274 ISAXLocator_Release(&locator->ISAXLocator_iface);
2275 return E_FAIL;
2278 if (enc_name)
2280 locator->pParserCtxt->encoding = xmlStrdup(enc_name);
2281 if (encoding == XML_CHAR_ENCODING_UTF16LE) {
2282 TRACE("switching to %s\n", enc_name);
2283 xmlSwitchEncoding(locator->pParserCtxt, encoding);
2287 xmlFree(locator->pParserCtxt->sax);
2288 locator->pParserCtxt->sax = &locator->saxreader->sax;
2289 locator->pParserCtxt->userData = locator;
2291 This->isParsing = TRUE;
2292 if(xmlParseDocument(locator->pParserCtxt) == -1 && locator->ret == S_OK)
2293 hr = E_FAIL;
2294 else
2295 hr = locator->ret;
2296 This->isParsing = FALSE;
2298 if(locator->pParserCtxt)
2300 locator->pParserCtxt->sax = NULL;
2301 xmlFreeParserCtxt(locator->pParserCtxt);
2302 locator->pParserCtxt = NULL;
2305 ISAXLocator_Release(&locator->ISAXLocator_iface);
2306 return hr;
2309 static HRESULT internal_parseStream(saxreader *This, ISequentialStream *stream, BOOL vbInterface)
2311 saxlocator *locator;
2312 HRESULT hr;
2313 ULONG dataRead;
2314 char data[1024];
2315 int ret;
2317 dataRead = 0;
2318 hr = ISequentialStream_Read(stream, data, sizeof(data), &dataRead);
2319 if(FAILED(hr)) return hr;
2321 hr = SAXLocator_create(This, &locator, vbInterface);
2322 if(FAILED(hr)) return hr;
2324 locator->pParserCtxt = xmlCreatePushParserCtxt(
2325 &locator->saxreader->sax, locator,
2326 data, dataRead, NULL);
2327 if(!locator->pParserCtxt)
2329 ISAXLocator_Release(&locator->ISAXLocator_iface);
2330 return E_FAIL;
2333 This->isParsing = TRUE;
2335 if(dataRead != sizeof(data))
2337 ret = xmlParseChunk(locator->pParserCtxt, data, 0, 1);
2338 hr = ret!=XML_ERR_OK && locator->ret==S_OK ? E_FAIL : locator->ret;
2340 else
2342 while(1)
2344 dataRead = 0;
2345 hr = ISequentialStream_Read(stream, data, sizeof(data), &dataRead);
2346 if (FAILED(hr)) break;
2348 ret = xmlParseChunk(locator->pParserCtxt, data, dataRead, 0);
2349 hr = ret!=XML_ERR_OK && locator->ret==S_OK ? E_FAIL : locator->ret;
2351 if (hr != S_OK) break;
2353 if (dataRead != sizeof(data))
2355 ret = xmlParseChunk(locator->pParserCtxt, data, 0, 1);
2356 hr = ret!=XML_ERR_OK && locator->ret==S_OK ? E_FAIL : locator->ret;
2357 break;
2362 This->isParsing = FALSE;
2364 xmlFreeParserCtxt(locator->pParserCtxt);
2365 locator->pParserCtxt = NULL;
2366 ISAXLocator_Release(&locator->ISAXLocator_iface);
2367 return hr;
2370 static HRESULT internal_getEntityResolver(
2371 saxreader *This,
2372 void *pEntityResolver,
2373 BOOL vbInterface)
2375 FIXME("(%p)->(%p) stub\n", This, pEntityResolver);
2376 return E_NOTIMPL;
2379 static HRESULT internal_putEntityResolver(
2380 saxreader *This,
2381 void *pEntityResolver,
2382 BOOL vbInterface)
2384 FIXME("(%p)->(%p) stub\n", This, pEntityResolver);
2385 return E_NOTIMPL;
2388 static HRESULT internal_parse(
2389 saxreader* This,
2390 VARIANT varInput,
2391 BOOL vbInterface)
2393 HRESULT hr;
2395 TRACE("(%p)->(%s)\n", This, debugstr_variant(&varInput));
2397 /* Dispose of the BSTRs in the pool from a prior run, if any. */
2398 free_bstr_pool(&This->pool);
2400 switch(V_VT(&varInput))
2402 case VT_BSTR:
2403 hr = internal_parseBuffer(This, (const char*)V_BSTR(&varInput),
2404 strlenW(V_BSTR(&varInput))*sizeof(WCHAR), vbInterface);
2405 break;
2406 case VT_ARRAY|VT_UI1: {
2407 void *pSAData;
2408 LONG lBound, uBound;
2409 ULONG dataRead;
2411 hr = SafeArrayGetLBound(V_ARRAY(&varInput), 1, &lBound);
2412 if(hr != S_OK) break;
2413 hr = SafeArrayGetUBound(V_ARRAY(&varInput), 1, &uBound);
2414 if(hr != S_OK) break;
2415 dataRead = (uBound-lBound)*SafeArrayGetElemsize(V_ARRAY(&varInput));
2416 hr = SafeArrayAccessData(V_ARRAY(&varInput), &pSAData);
2417 if(hr != S_OK) break;
2418 hr = internal_parseBuffer(This, pSAData, dataRead, vbInterface);
2419 SafeArrayUnaccessData(V_ARRAY(&varInput));
2420 break;
2422 case VT_UNKNOWN:
2423 case VT_DISPATCH: {
2424 IPersistStream *persistStream;
2425 ISequentialStream *stream = NULL;
2426 IXMLDOMDocument *xmlDoc;
2428 if(IUnknown_QueryInterface(V_UNKNOWN(&varInput),
2429 &IID_IXMLDOMDocument, (void**)&xmlDoc) == S_OK)
2431 BSTR bstrData;
2433 IXMLDOMDocument_get_xml(xmlDoc, &bstrData);
2434 hr = internal_parseBuffer(This, (const char*)bstrData,
2435 SysStringByteLen(bstrData), vbInterface);
2436 IXMLDOMDocument_Release(xmlDoc);
2437 SysFreeString(bstrData);
2438 break;
2441 if(IUnknown_QueryInterface(V_UNKNOWN(&varInput),
2442 &IID_IPersistStream, (void**)&persistStream) == S_OK)
2444 IStream *stream_copy;
2446 hr = CreateStreamOnHGlobal(NULL, TRUE, &stream_copy);
2447 if(hr != S_OK)
2449 IPersistStream_Release(persistStream);
2450 return hr;
2453 hr = IPersistStream_Save(persistStream, stream_copy, TRUE);
2454 IPersistStream_Release(persistStream);
2455 if(hr == S_OK)
2456 IStream_QueryInterface(stream_copy, &IID_ISequentialStream, (void**)&stream);
2458 IStream_Release(stream_copy);
2461 /* try base interface first */
2462 if(!stream)
2464 IUnknown_QueryInterface(V_UNKNOWN(&varInput), &IID_ISequentialStream, (void**)&stream);
2465 if (!stream)
2466 /* this should never happen if IStream is implemented properly, but just in case */
2467 IUnknown_QueryInterface(V_UNKNOWN(&varInput), &IID_IStream, (void**)&stream);
2470 if(stream)
2472 hr = internal_parseStream(This, stream, vbInterface);
2473 ISequentialStream_Release(stream);
2475 else
2477 WARN("IUnknown* input doesn't support any of expected interfaces\n");
2478 hr = E_INVALIDARG;
2481 break;
2483 default:
2484 WARN("vt %d not implemented\n", V_VT(&varInput));
2485 hr = E_INVALIDARG;
2488 return hr;
2491 static HRESULT internal_vbonDataAvailable(void *obj, char *ptr, DWORD len)
2493 saxreader *This = obj;
2495 return internal_parseBuffer(This, ptr, len, TRUE);
2498 static HRESULT internal_onDataAvailable(void *obj, char *ptr, DWORD len)
2500 saxreader *This = obj;
2502 return internal_parseBuffer(This, ptr, len, FALSE);
2505 static HRESULT internal_parseURL(
2506 saxreader* This,
2507 const WCHAR *url,
2508 BOOL vbInterface)
2510 IMoniker *mon;
2511 bsc_t *bsc;
2512 HRESULT hr;
2514 TRACE("(%p)->(%s)\n", This, debugstr_w(url));
2516 hr = create_moniker_from_url(url, &mon);
2517 if(FAILED(hr))
2518 return hr;
2520 if(vbInterface) hr = bind_url(mon, internal_vbonDataAvailable, This, &bsc);
2521 else hr = bind_url(mon, internal_onDataAvailable, This, &bsc);
2522 IMoniker_Release(mon);
2524 if(FAILED(hr))
2525 return hr;
2527 return detach_bsc(bsc);
2530 static HRESULT internal_putProperty(
2531 saxreader* This,
2532 const WCHAR *prop,
2533 VARIANT value,
2534 BOOL vbInterface)
2536 TRACE("(%p)->(%s %s)\n", This, debugstr_w(prop), debugstr_variant(&value));
2538 if(!memcmp(prop, PropertyDeclHandlerW, sizeof(PropertyDeclHandlerW)))
2540 if(This->isParsing) return E_FAIL;
2542 switch (V_VT(&value))
2544 case VT_EMPTY:
2545 saxreader_put_handler(This, SAXDeclHandler, NULL, vbInterface);
2546 break;
2547 case VT_UNKNOWN:
2549 IUnknown *handler = NULL;
2551 if (V_UNKNOWN(&value))
2553 HRESULT hr;
2555 if (vbInterface)
2556 hr = IUnknown_QueryInterface(V_UNKNOWN(&value), &IID_IVBSAXDeclHandler, (void**)&handler);
2557 else
2558 hr = IUnknown_QueryInterface(V_UNKNOWN(&value), &IID_ISAXDeclHandler, (void**)&handler);
2559 if (FAILED(hr)) return hr;
2562 saxreader_put_handler(This, SAXDeclHandler, handler, vbInterface);
2563 if (handler) IUnknown_Release(handler);
2564 break;
2566 default:
2567 return E_INVALIDARG;
2570 return S_OK;
2573 if(!memcmp(prop, PropertyLexicalHandlerW, sizeof(PropertyLexicalHandlerW)))
2575 if(This->isParsing) return E_FAIL;
2577 switch (V_VT(&value))
2579 case VT_EMPTY:
2580 saxreader_put_handler(This, SAXLexicalHandler, NULL, vbInterface);
2581 break;
2582 case VT_UNKNOWN:
2584 IUnknown *handler = NULL;
2586 if (V_UNKNOWN(&value))
2588 HRESULT hr;
2590 if (vbInterface)
2591 hr = IUnknown_QueryInterface(V_UNKNOWN(&value), &IID_IVBSAXLexicalHandler, (void**)&handler);
2592 else
2593 hr = IUnknown_QueryInterface(V_UNKNOWN(&value), &IID_ISAXLexicalHandler, (void**)&handler);
2594 if (FAILED(hr)) return hr;
2597 saxreader_put_handler(This, SAXLexicalHandler, handler, vbInterface);
2598 if (handler) IUnknown_Release(handler);
2599 break;
2601 default:
2602 return E_INVALIDARG;
2605 return S_OK;
2608 if(!memcmp(prop, PropertyMaxXMLSizeW, sizeof(PropertyMaxXMLSizeW)))
2610 if (V_VT(&value) == VT_I4 && V_I4(&value) == 0) return S_OK;
2611 FIXME("(%p)->(%s): max-xml-size unsupported\n", This, debugstr_variant(&value));
2612 return E_NOTIMPL;
2615 if(!memcmp(prop, PropertyMaxElementDepthW, sizeof(PropertyMaxElementDepthW)))
2617 if (V_VT(&value) == VT_I4 && V_I4(&value) == 0) return S_OK;
2618 FIXME("(%p)->(%s): max-element-depth unsupported\n", This, debugstr_variant(&value));
2619 return E_NOTIMPL;
2622 FIXME("(%p)->(%s:%s): unsupported property\n", This, debugstr_w(prop), debugstr_variant(&value));
2624 if(!memcmp(prop, PropertyCharsetW, sizeof(PropertyCharsetW)))
2625 return E_NOTIMPL;
2627 if(!memcmp(prop, PropertyDomNodeW, sizeof(PropertyDomNodeW)))
2628 return E_FAIL;
2630 if(!memcmp(prop, PropertyInputSourceW, sizeof(PropertyInputSourceW)))
2631 return E_NOTIMPL;
2633 if(!memcmp(prop, PropertySchemaDeclHandlerW, sizeof(PropertySchemaDeclHandlerW)))
2634 return E_NOTIMPL;
2636 if(!memcmp(prop, PropertyXMLDeclEncodingW, sizeof(PropertyXMLDeclEncodingW)))
2637 return E_FAIL;
2639 if(!memcmp(prop, PropertyXMLDeclStandaloneW, sizeof(PropertyXMLDeclStandaloneW)))
2640 return E_FAIL;
2642 if(!memcmp(prop, PropertyXMLDeclVersionW, sizeof(PropertyXMLDeclVersionW)))
2643 return E_FAIL;
2645 return E_INVALIDARG;
2648 static HRESULT internal_getProperty(const saxreader* This, const WCHAR *prop, VARIANT *value, BOOL vb)
2650 TRACE("(%p)->(%s)\n", This, debugstr_w(prop));
2652 if (!value) return E_POINTER;
2654 if (!memcmp(PropertyLexicalHandlerW, prop, sizeof(PropertyLexicalHandlerW)))
2656 V_VT(value) = VT_UNKNOWN;
2657 saxreader_get_handler(This, SAXLexicalHandler, vb, (void**)&V_UNKNOWN(value));
2658 return S_OK;
2661 if (!memcmp(PropertyDeclHandlerW, prop, sizeof(PropertyDeclHandlerW)))
2663 V_VT(value) = VT_UNKNOWN;
2664 saxreader_get_handler(This, SAXDeclHandler, vb, (void**)&V_UNKNOWN(value));
2665 return S_OK;
2668 if (!memcmp(PropertyXmlDeclVersionW, prop, sizeof(PropertyXmlDeclVersionW)))
2670 V_VT(value) = VT_BSTR;
2671 V_BSTR(value) = SysAllocString(This->xmldecl_version);
2672 return S_OK;
2675 FIXME("(%p)->(%s) unsupported property\n", This, debugstr_w(prop));
2677 return E_NOTIMPL;
2680 /*** IVBSAXXMLReader interface ***/
2681 /*** IUnknown methods ***/
2682 static HRESULT WINAPI saxxmlreader_QueryInterface(IVBSAXXMLReader* iface, REFIID riid, void **ppvObject)
2684 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2686 TRACE("%p %s %p\n", This, debugstr_guid( riid ), ppvObject );
2688 *ppvObject = NULL;
2690 if ( IsEqualGUID( riid, &IID_IUnknown ) ||
2691 IsEqualGUID( riid, &IID_IDispatch ) ||
2692 IsEqualGUID( riid, &IID_IVBSAXXMLReader ))
2694 *ppvObject = iface;
2696 else if( IsEqualGUID( riid, &IID_ISAXXMLReader ))
2698 *ppvObject = &This->ISAXXMLReader_iface;
2700 else if (dispex_query_interface(&This->dispex, riid, ppvObject))
2702 return *ppvObject ? S_OK : E_NOINTERFACE;
2704 else
2706 FIXME("interface %s not implemented\n", debugstr_guid(riid));
2707 return E_NOINTERFACE;
2710 IVBSAXXMLReader_AddRef( iface );
2712 return S_OK;
2715 static ULONG WINAPI saxxmlreader_AddRef(IVBSAXXMLReader* iface)
2717 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2718 TRACE("%p\n", This );
2719 return InterlockedIncrement( &This->ref );
2722 static ULONG WINAPI saxxmlreader_Release(
2723 IVBSAXXMLReader* iface)
2725 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2726 LONG ref;
2728 TRACE("%p\n", This );
2730 ref = InterlockedDecrement( &This->ref );
2731 if ( ref == 0 )
2733 int i;
2735 for (i = 0; i < SAXHandler_Last; i++)
2737 struct saxhandler_iface *iface = &This->saxhandlers[i];
2739 if (iface->handler)
2740 IUnknown_Release(iface->handler);
2742 if (iface->vbhandler)
2743 IUnknown_Release(iface->vbhandler);
2746 SysFreeString(This->xmldecl_version);
2747 free_bstr_pool(&This->pool);
2749 release_dispex(&This->dispex);
2750 heap_free( This );
2753 return ref;
2755 /*** IDispatch ***/
2756 static HRESULT WINAPI saxxmlreader_GetTypeInfoCount( IVBSAXXMLReader *iface, UINT* pctinfo )
2758 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2759 return IDispatchEx_GetTypeInfoCount(&This->dispex.IDispatchEx_iface, pctinfo);
2762 static HRESULT WINAPI saxxmlreader_GetTypeInfo(
2763 IVBSAXXMLReader *iface,
2764 UINT iTInfo, LCID lcid, ITypeInfo** ppTInfo )
2766 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2767 return IDispatchEx_GetTypeInfo(&This->dispex.IDispatchEx_iface,
2768 iTInfo, lcid, ppTInfo);
2771 static HRESULT WINAPI saxxmlreader_GetIDsOfNames(
2772 IVBSAXXMLReader *iface,
2773 REFIID riid,
2774 LPOLESTR* rgszNames,
2775 UINT cNames,
2776 LCID lcid,
2777 DISPID* rgDispId)
2779 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2780 return IDispatchEx_GetIDsOfNames(&This->dispex.IDispatchEx_iface,
2781 riid, rgszNames, cNames, lcid, rgDispId);
2784 static HRESULT WINAPI saxxmlreader_Invoke(
2785 IVBSAXXMLReader *iface,
2786 DISPID dispIdMember,
2787 REFIID riid,
2788 LCID lcid,
2789 WORD wFlags,
2790 DISPPARAMS* pDispParams,
2791 VARIANT* pVarResult,
2792 EXCEPINFO* pExcepInfo,
2793 UINT* puArgErr)
2795 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2796 return IDispatchEx_Invoke(&This->dispex.IDispatchEx_iface,
2797 dispIdMember, riid, lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
2800 /*** IVBSAXXMLReader methods ***/
2801 static HRESULT WINAPI saxxmlreader_getFeature(
2802 IVBSAXXMLReader* iface,
2803 const WCHAR *feature_name,
2804 VARIANT_BOOL *value)
2806 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2807 saxreader_feature feature;
2809 TRACE("(%p)->(%s %p)\n", This, debugstr_w(feature_name), value);
2811 feature = get_saxreader_feature(feature_name);
2812 if (feature == Namespaces || feature == NamespacePrefixes)
2813 return get_feature_value(This, feature, value);
2815 FIXME("(%p)->(%s %p) stub\n", This, debugstr_w(feature_name), value);
2816 return E_NOTIMPL;
2819 static HRESULT WINAPI saxxmlreader_putFeature(
2820 IVBSAXXMLReader* iface,
2821 const WCHAR *feature_name,
2822 VARIANT_BOOL value)
2824 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2825 saxreader_feature feature;
2827 TRACE("(%p)->(%s %x)\n", This, debugstr_w(feature_name), value);
2829 feature = get_saxreader_feature(feature_name);
2831 /* accepted cases */
2832 if ((feature == ExternalGeneralEntities && value == VARIANT_FALSE) ||
2833 (feature == ExternalParameterEntities && value == VARIANT_FALSE) ||
2834 feature == Namespaces ||
2835 feature == NamespacePrefixes)
2837 return set_feature_value(This, feature, value);
2840 if (feature == LexicalHandlerParEntities || feature == ProhibitDTD)
2842 FIXME("(%p)->(%s %x) stub\n", This, debugstr_w(feature_name), value);
2843 return set_feature_value(This, feature, value);
2846 FIXME("(%p)->(%s %x) stub\n", This, debugstr_w(feature_name), value);
2847 return E_NOTIMPL;
2850 static HRESULT WINAPI saxxmlreader_getProperty(
2851 IVBSAXXMLReader* iface,
2852 const WCHAR *prop,
2853 VARIANT *value)
2855 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2856 return internal_getProperty(This, prop, value, TRUE);
2859 static HRESULT WINAPI saxxmlreader_putProperty(
2860 IVBSAXXMLReader* iface,
2861 const WCHAR *pProp,
2862 VARIANT value)
2864 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2865 return internal_putProperty(This, pProp, value, TRUE);
2868 static HRESULT WINAPI saxxmlreader_get_entityResolver(
2869 IVBSAXXMLReader* iface,
2870 IVBSAXEntityResolver **pEntityResolver)
2872 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2873 return internal_getEntityResolver(This, pEntityResolver, TRUE);
2876 static HRESULT WINAPI saxxmlreader_put_entityResolver(
2877 IVBSAXXMLReader* iface,
2878 IVBSAXEntityResolver *pEntityResolver)
2880 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2881 return internal_putEntityResolver(This, pEntityResolver, TRUE);
2884 static HRESULT WINAPI saxxmlreader_get_contentHandler(
2885 IVBSAXXMLReader* iface,
2886 IVBSAXContentHandler **handler)
2888 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2889 return saxreader_get_handler(This, SAXContentHandler, TRUE, (void**)handler);
2892 static HRESULT WINAPI saxxmlreader_put_contentHandler(
2893 IVBSAXXMLReader* iface,
2894 IVBSAXContentHandler *handler)
2896 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2897 return saxreader_put_handler(This, SAXContentHandler, handler, TRUE);
2900 static HRESULT WINAPI saxxmlreader_get_dtdHandler(
2901 IVBSAXXMLReader* iface,
2902 IVBSAXDTDHandler **handler)
2904 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2905 return saxreader_get_handler(This, SAXDTDHandler, TRUE, (void**)handler);
2908 static HRESULT WINAPI saxxmlreader_put_dtdHandler(
2909 IVBSAXXMLReader* iface,
2910 IVBSAXDTDHandler *handler)
2912 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2913 return saxreader_put_handler(This, SAXDTDHandler, handler, TRUE);
2916 static HRESULT WINAPI saxxmlreader_get_errorHandler(
2917 IVBSAXXMLReader* iface,
2918 IVBSAXErrorHandler **handler)
2920 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2921 return saxreader_get_handler(This, SAXErrorHandler, TRUE, (void**)handler);
2924 static HRESULT WINAPI saxxmlreader_put_errorHandler(
2925 IVBSAXXMLReader* iface,
2926 IVBSAXErrorHandler *handler)
2928 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2929 return saxreader_put_handler(This, SAXErrorHandler, handler, TRUE);
2932 static HRESULT WINAPI saxxmlreader_get_baseURL(
2933 IVBSAXXMLReader* iface,
2934 const WCHAR **pBaseUrl)
2936 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2938 FIXME("(%p)->(%p) stub\n", This, pBaseUrl);
2939 return E_NOTIMPL;
2942 static HRESULT WINAPI saxxmlreader_put_baseURL(
2943 IVBSAXXMLReader* iface,
2944 const WCHAR *pBaseUrl)
2946 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2948 FIXME("(%p)->(%s) stub\n", This, debugstr_w(pBaseUrl));
2949 return E_NOTIMPL;
2952 static HRESULT WINAPI saxxmlreader_get_secureBaseURL(
2953 IVBSAXXMLReader* iface,
2954 const WCHAR **pSecureBaseUrl)
2956 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2958 FIXME("(%p)->(%p) stub\n", This, pSecureBaseUrl);
2959 return E_NOTIMPL;
2963 static HRESULT WINAPI saxxmlreader_put_secureBaseURL(
2964 IVBSAXXMLReader* iface,
2965 const WCHAR *secureBaseUrl)
2967 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2969 FIXME("(%p)->(%s) stub\n", This, debugstr_w(secureBaseUrl));
2970 return E_NOTIMPL;
2973 static HRESULT WINAPI saxxmlreader_parse(
2974 IVBSAXXMLReader* iface,
2975 VARIANT varInput)
2977 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2978 return internal_parse(This, varInput, TRUE);
2981 static HRESULT WINAPI saxxmlreader_parseURL(
2982 IVBSAXXMLReader* iface,
2983 const WCHAR *url)
2985 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2986 return internal_parseURL(This, url, TRUE);
2989 static const struct IVBSAXXMLReaderVtbl VBSAXXMLReaderVtbl =
2991 saxxmlreader_QueryInterface,
2992 saxxmlreader_AddRef,
2993 saxxmlreader_Release,
2994 saxxmlreader_GetTypeInfoCount,
2995 saxxmlreader_GetTypeInfo,
2996 saxxmlreader_GetIDsOfNames,
2997 saxxmlreader_Invoke,
2998 saxxmlreader_getFeature,
2999 saxxmlreader_putFeature,
3000 saxxmlreader_getProperty,
3001 saxxmlreader_putProperty,
3002 saxxmlreader_get_entityResolver,
3003 saxxmlreader_put_entityResolver,
3004 saxxmlreader_get_contentHandler,
3005 saxxmlreader_put_contentHandler,
3006 saxxmlreader_get_dtdHandler,
3007 saxxmlreader_put_dtdHandler,
3008 saxxmlreader_get_errorHandler,
3009 saxxmlreader_put_errorHandler,
3010 saxxmlreader_get_baseURL,
3011 saxxmlreader_put_baseURL,
3012 saxxmlreader_get_secureBaseURL,
3013 saxxmlreader_put_secureBaseURL,
3014 saxxmlreader_parse,
3015 saxxmlreader_parseURL
3018 /*** ISAXXMLReader interface ***/
3019 /*** IUnknown methods ***/
3020 static HRESULT WINAPI isaxxmlreader_QueryInterface(ISAXXMLReader* iface, REFIID riid, void **ppvObject)
3022 saxreader *This = impl_from_ISAXXMLReader( iface );
3023 return saxxmlreader_QueryInterface(&This->IVBSAXXMLReader_iface, riid, ppvObject);
3026 static ULONG WINAPI isaxxmlreader_AddRef(ISAXXMLReader* iface)
3028 saxreader *This = impl_from_ISAXXMLReader( iface );
3029 return saxxmlreader_AddRef(&This->IVBSAXXMLReader_iface);
3032 static ULONG WINAPI isaxxmlreader_Release(ISAXXMLReader* iface)
3034 saxreader *This = impl_from_ISAXXMLReader( iface );
3035 return saxxmlreader_Release(&This->IVBSAXXMLReader_iface);
3038 /*** ISAXXMLReader methods ***/
3039 static HRESULT WINAPI isaxxmlreader_getFeature(
3040 ISAXXMLReader* iface,
3041 const WCHAR *pFeature,
3042 VARIANT_BOOL *pValue)
3044 saxreader *This = impl_from_ISAXXMLReader( iface );
3045 return IVBSAXXMLReader_getFeature(&This->IVBSAXXMLReader_iface, pFeature, pValue);
3048 static HRESULT WINAPI isaxxmlreader_putFeature(
3049 ISAXXMLReader* iface,
3050 const WCHAR *pFeature,
3051 VARIANT_BOOL vfValue)
3053 saxreader *This = impl_from_ISAXXMLReader( iface );
3054 return IVBSAXXMLReader_putFeature(&This->IVBSAXXMLReader_iface, pFeature, vfValue);
3057 static HRESULT WINAPI isaxxmlreader_getProperty(
3058 ISAXXMLReader* iface,
3059 const WCHAR *prop,
3060 VARIANT *value)
3062 saxreader *This = impl_from_ISAXXMLReader( iface );
3063 return internal_getProperty(This, prop, value, FALSE);
3066 static HRESULT WINAPI isaxxmlreader_putProperty(
3067 ISAXXMLReader* iface,
3068 const WCHAR *pProp,
3069 VARIANT value)
3071 saxreader *This = impl_from_ISAXXMLReader( iface );
3072 return internal_putProperty(This, pProp, value, FALSE);
3075 static HRESULT WINAPI isaxxmlreader_getEntityResolver(
3076 ISAXXMLReader* iface,
3077 ISAXEntityResolver **ppEntityResolver)
3079 saxreader *This = impl_from_ISAXXMLReader( iface );
3080 return internal_getEntityResolver(This, ppEntityResolver, FALSE);
3083 static HRESULT WINAPI isaxxmlreader_putEntityResolver(
3084 ISAXXMLReader* iface,
3085 ISAXEntityResolver *pEntityResolver)
3087 saxreader *This = impl_from_ISAXXMLReader( iface );
3088 return internal_putEntityResolver(This, pEntityResolver, FALSE);
3091 static HRESULT WINAPI isaxxmlreader_getContentHandler(
3092 ISAXXMLReader* iface,
3093 ISAXContentHandler **handler)
3095 saxreader *This = impl_from_ISAXXMLReader( iface );
3096 return saxreader_get_handler(This, SAXContentHandler, FALSE, (void**)handler);
3099 static HRESULT WINAPI isaxxmlreader_putContentHandler(
3100 ISAXXMLReader* iface,
3101 ISAXContentHandler *handler)
3103 saxreader *This = impl_from_ISAXXMLReader( iface );
3104 return saxreader_put_handler(This, SAXContentHandler, handler, FALSE);
3107 static HRESULT WINAPI isaxxmlreader_getDTDHandler(
3108 ISAXXMLReader* iface,
3109 ISAXDTDHandler **handler)
3111 saxreader *This = impl_from_ISAXXMLReader( iface );
3112 return saxreader_get_handler(This, SAXDTDHandler, FALSE, (void**)handler);
3115 static HRESULT WINAPI isaxxmlreader_putDTDHandler(
3116 ISAXXMLReader* iface,
3117 ISAXDTDHandler *handler)
3119 saxreader *This = impl_from_ISAXXMLReader( iface );
3120 return saxreader_put_handler(This, SAXDTDHandler, handler, FALSE);
3123 static HRESULT WINAPI isaxxmlreader_getErrorHandler(
3124 ISAXXMLReader* iface,
3125 ISAXErrorHandler **handler)
3127 saxreader *This = impl_from_ISAXXMLReader( iface );
3128 return saxreader_get_handler(This, SAXErrorHandler, FALSE, (void**)handler);
3131 static HRESULT WINAPI isaxxmlreader_putErrorHandler(ISAXXMLReader* iface, ISAXErrorHandler *handler)
3133 saxreader *This = impl_from_ISAXXMLReader( iface );
3134 return saxreader_put_handler(This, SAXErrorHandler, handler, FALSE);
3137 static HRESULT WINAPI isaxxmlreader_getBaseURL(
3138 ISAXXMLReader* iface,
3139 const WCHAR **pBaseUrl)
3141 saxreader *This = impl_from_ISAXXMLReader( iface );
3142 return IVBSAXXMLReader_get_baseURL(&This->IVBSAXXMLReader_iface, pBaseUrl);
3145 static HRESULT WINAPI isaxxmlreader_putBaseURL(
3146 ISAXXMLReader* iface,
3147 const WCHAR *pBaseUrl)
3149 saxreader *This = impl_from_ISAXXMLReader( iface );
3150 return IVBSAXXMLReader_put_baseURL(&This->IVBSAXXMLReader_iface, pBaseUrl);
3153 static HRESULT WINAPI isaxxmlreader_getSecureBaseURL(
3154 ISAXXMLReader* iface,
3155 const WCHAR **pSecureBaseUrl)
3157 saxreader *This = impl_from_ISAXXMLReader( iface );
3158 return IVBSAXXMLReader_get_secureBaseURL(&This->IVBSAXXMLReader_iface, pSecureBaseUrl);
3161 static HRESULT WINAPI isaxxmlreader_putSecureBaseURL(
3162 ISAXXMLReader* iface,
3163 const WCHAR *secureBaseUrl)
3165 saxreader *This = impl_from_ISAXXMLReader( iface );
3166 return IVBSAXXMLReader_put_secureBaseURL(&This->IVBSAXXMLReader_iface, secureBaseUrl);
3169 static HRESULT WINAPI isaxxmlreader_parse(
3170 ISAXXMLReader* iface,
3171 VARIANT varInput)
3173 saxreader *This = impl_from_ISAXXMLReader( iface );
3174 return internal_parse(This, varInput, FALSE);
3177 static HRESULT WINAPI isaxxmlreader_parseURL(
3178 ISAXXMLReader* iface,
3179 const WCHAR *url)
3181 saxreader *This = impl_from_ISAXXMLReader( iface );
3182 return internal_parseURL(This, url, FALSE);
3185 static const struct ISAXXMLReaderVtbl SAXXMLReaderVtbl =
3187 isaxxmlreader_QueryInterface,
3188 isaxxmlreader_AddRef,
3189 isaxxmlreader_Release,
3190 isaxxmlreader_getFeature,
3191 isaxxmlreader_putFeature,
3192 isaxxmlreader_getProperty,
3193 isaxxmlreader_putProperty,
3194 isaxxmlreader_getEntityResolver,
3195 isaxxmlreader_putEntityResolver,
3196 isaxxmlreader_getContentHandler,
3197 isaxxmlreader_putContentHandler,
3198 isaxxmlreader_getDTDHandler,
3199 isaxxmlreader_putDTDHandler,
3200 isaxxmlreader_getErrorHandler,
3201 isaxxmlreader_putErrorHandler,
3202 isaxxmlreader_getBaseURL,
3203 isaxxmlreader_putBaseURL,
3204 isaxxmlreader_getSecureBaseURL,
3205 isaxxmlreader_putSecureBaseURL,
3206 isaxxmlreader_parse,
3207 isaxxmlreader_parseURL
3210 static const tid_t saxreader_iface_tids[] = {
3211 IVBSAXXMLReader_tid,
3214 static dispex_static_data_t saxreader_dispex = {
3215 NULL,
3216 IVBSAXXMLReader_tid,
3217 NULL,
3218 saxreader_iface_tids
3221 HRESULT SAXXMLReader_create(MSXML_VERSION version, IUnknown *outer, LPVOID *ppObj)
3223 saxreader *reader;
3225 TRACE("(%p, %p)\n", outer, ppObj);
3227 reader = heap_alloc( sizeof (*reader) );
3228 if( !reader )
3229 return E_OUTOFMEMORY;
3231 reader->IVBSAXXMLReader_iface.lpVtbl = &VBSAXXMLReaderVtbl;
3232 reader->ISAXXMLReader_iface.lpVtbl = &SAXXMLReaderVtbl;
3233 reader->ref = 1;
3234 memset(reader->saxhandlers, 0, sizeof(reader->saxhandlers));
3235 reader->isParsing = FALSE;
3236 reader->xmldecl_version = NULL;
3237 reader->pool.pool = NULL;
3238 reader->pool.index = 0;
3239 reader->pool.len = 0;
3240 reader->features = Namespaces | NamespacePrefixes;
3241 reader->version = version;
3243 init_dispex(&reader->dispex, (IUnknown*)&reader->IVBSAXXMLReader_iface, &saxreader_dispex);
3245 memset(&reader->sax, 0, sizeof(xmlSAXHandler));
3246 reader->sax.initialized = XML_SAX2_MAGIC;
3247 reader->sax.startDocument = libxmlStartDocument;
3248 reader->sax.endDocument = libxmlEndDocument;
3249 reader->sax.startElementNs = libxmlStartElementNS;
3250 reader->sax.endElementNs = libxmlEndElementNS;
3251 reader->sax.characters = libxmlCharacters;
3252 reader->sax.setDocumentLocator = libxmlSetDocumentLocator;
3253 reader->sax.comment = libxmlComment;
3254 reader->sax.error = libxmlFatalError;
3255 reader->sax.fatalError = libxmlFatalError;
3256 reader->sax.cdataBlock = libxmlCDataBlock;
3258 *ppObj = &reader->IVBSAXXMLReader_iface;
3260 TRACE("returning iface %p\n", *ppObj);
3262 return S_OK;
3265 #else
3267 HRESULT SAXXMLReader_create(MSXML_VERSION version, IUnknown *pUnkOuter, LPVOID *ppObj)
3269 MESSAGE("This program tried to use a SAX XML Reader object, but\n"
3270 "libxml2 support was not present at compile time.\n");
3271 return E_NOTIMPL;
3274 #endif