mshtml: Added IHTMLInputElement::defaultValue property implementation.
[wine/multimedia.git] / dlls / msxml3 / saxreader.c
blob3b167b797c59e35847e1eb30a371ba19de82612a
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 SAXEntityResolver,
172 SAXErrorHandler,
173 SAXLexicalHandler,
174 SAXHandler_Last
177 struct saxanyhandler_iface
179 IUnknown *handler;
180 IUnknown *vbhandler;
183 struct saxcontenthandler_iface
185 ISAXContentHandler *handler;
186 IVBSAXContentHandler *vbhandler;
189 struct saxerrorhandler_iface
191 ISAXErrorHandler *handler;
192 IVBSAXErrorHandler *vbhandler;
195 struct saxlexicalhandler_iface
197 ISAXLexicalHandler *handler;
198 IVBSAXLexicalHandler *vbhandler;
201 struct saxentityresolver_iface
203 ISAXEntityResolver *handler;
204 IVBSAXEntityResolver *vbhandler;
207 struct saxhandler_iface
209 union {
210 struct saxcontenthandler_iface content;
211 struct saxentityresolver_iface entityresolver;
212 struct saxerrorhandler_iface error;
213 struct saxlexicalhandler_iface lexical;
214 struct saxanyhandler_iface anyhandler;
215 } u;
218 typedef struct
220 DispatchEx dispex;
221 IVBSAXXMLReader IVBSAXXMLReader_iface;
222 ISAXXMLReader ISAXXMLReader_iface;
223 LONG ref;
225 struct saxhandler_iface saxhandlers[SAXHandler_Last];
226 xmlSAXHandler sax;
227 BOOL isParsing;
228 struct bstrpool pool;
229 saxreader_feature features;
230 BSTR xmldecl_version;
231 MSXML_VERSION version;
232 } saxreader;
234 static HRESULT saxreader_put_handler(saxreader *reader, enum saxhandler_type type, void *ptr, BOOL vb)
236 struct saxanyhandler_iface *iface = &reader->saxhandlers[type].u.anyhandler;
237 IUnknown *unk = (IUnknown*)ptr;
239 if (unk)
240 IUnknown_AddRef(unk);
242 if ((vb && iface->vbhandler) || (!vb && iface->handler))
243 IUnknown_Release(vb ? iface->vbhandler : iface->handler);
245 if (vb)
246 iface->vbhandler = unk;
247 else
248 iface->handler = unk;
250 return S_OK;
253 static HRESULT saxreader_get_handler(const saxreader *reader, enum saxhandler_type type, BOOL vb, void **ret)
255 const struct saxanyhandler_iface *iface = &reader->saxhandlers[type].u.anyhandler;
257 if (!ret) return E_POINTER;
259 if ((vb && iface->vbhandler) || (!vb && iface->handler))
261 if (vb)
262 IUnknown_AddRef(iface->vbhandler);
263 else
264 IUnknown_AddRef(iface->handler);
267 *ret = vb ? iface->vbhandler : iface->handler;
269 return S_OK;
272 static struct saxcontenthandler_iface *saxreader_get_contenthandler(saxreader *reader)
274 return &reader->saxhandlers[SAXContentHandler].u.content;
277 static struct saxerrorhandler_iface *saxreader_get_errorhandler(saxreader *reader)
279 return &reader->saxhandlers[SAXErrorHandler].u.error;
282 static struct saxlexicalhandler_iface *saxreader_get_lexicalhandler(saxreader *reader)
284 return &reader->saxhandlers[SAXLexicalHandler].u.lexical;
287 typedef struct
289 IVBSAXLocator IVBSAXLocator_iface;
290 ISAXLocator ISAXLocator_iface;
291 IVBSAXAttributes IVBSAXAttributes_iface;
292 ISAXAttributes ISAXAttributes_iface;
293 LONG ref;
294 saxreader *saxreader;
295 HRESULT ret;
296 xmlParserCtxtPtr pParserCtxt;
297 BSTR publicId;
298 BSTR systemId;
299 int line;
300 int column;
301 BOOL vbInterface;
302 struct list elements;
304 BSTR namespaceUri;
305 int attributesSize;
306 int nb_attributes;
307 struct _attributes
309 BSTR szLocalname;
310 BSTR szURI;
311 BSTR szValue;
312 BSTR szQName;
313 } *attributes;
314 } saxlocator;
316 static inline saxreader *impl_from_IVBSAXXMLReader( IVBSAXXMLReader *iface )
318 return CONTAINING_RECORD(iface, saxreader, IVBSAXXMLReader_iface);
321 static inline saxreader *impl_from_ISAXXMLReader( ISAXXMLReader *iface )
323 return CONTAINING_RECORD(iface, saxreader, ISAXXMLReader_iface);
326 static inline saxlocator *impl_from_IVBSAXLocator( IVBSAXLocator *iface )
328 return CONTAINING_RECORD(iface, saxlocator, IVBSAXLocator_iface);
331 static inline saxlocator *impl_from_ISAXLocator( ISAXLocator *iface )
333 return CONTAINING_RECORD(iface, saxlocator, ISAXLocator_iface);
336 static inline saxlocator *impl_from_IVBSAXAttributes( IVBSAXAttributes *iface )
338 return CONTAINING_RECORD(iface, saxlocator, IVBSAXAttributes_iface);
341 static inline saxlocator *impl_from_ISAXAttributes( ISAXAttributes *iface )
343 return CONTAINING_RECORD(iface, saxlocator, ISAXAttributes_iface);
346 static inline int saxreader_has_handler(const saxlocator *locator, enum saxhandler_type type)
348 struct saxanyhandler_iface *iface = &locator->saxreader->saxhandlers[type].u.anyhandler;
349 return (locator->vbInterface && iface->vbhandler) || (!locator->vbInterface && iface->handler);
352 /* property names */
353 static const WCHAR PropertyCharsetW[] = {
354 'c','h','a','r','s','e','t',0
356 static const WCHAR PropertyXmlDeclVersionW[] = {
357 'x','m','l','d','e','c','l','-','v','e','r','s','i','o','n',0
359 static const WCHAR PropertyDeclHandlerW[] = {
360 'h','t','t','p',':','/','/','x','m','l','.','o','r','g','/',
361 's','a','x','/','p','r','o','p','e','r','t','i','e','s','/',
362 'd','e','c','l','a','r','a','t','i','o','n',
363 '-','h','a','n','d','l','e','r',0
365 static const WCHAR PropertyDomNodeW[] = {
366 'h','t','t','p',':','/','/','x','m','l','.','o','r','g','/',
367 's','a','x','/','p','r','o','p','e','r','t','i','e','s','/',
368 'd','o','m','-','n','o','d','e',0
370 static const WCHAR PropertyInputSourceW[] = {
371 'i','n','p','u','t','-','s','o','u','r','c','e',0
373 static const WCHAR PropertyLexicalHandlerW[] = {
374 'h','t','t','p',':','/','/','x','m','l','.','o','r','g','/',
375 's','a','x','/','p','r','o','p','e','r','t','i','e','s','/',
376 'l','e','x','i','c','a','l','-','h','a','n','d','l','e','r',0
378 static const WCHAR PropertyMaxElementDepthW[] = {
379 'm','a','x','-','e','l','e','m','e','n','t','-','d','e','p','t','h',0
381 static const WCHAR PropertyMaxXMLSizeW[] = {
382 'm','a','x','-','x','m','l','-','s','i','z','e',0
384 static const WCHAR PropertySchemaDeclHandlerW[] = {
385 's','c','h','e','m','a','-','d','e','c','l','a','r','a','t','i','o','n','-',
386 'h','a','n','d','l','e','r',0
388 static const WCHAR PropertyXMLDeclEncodingW[] = {
389 'x','m','l','d','e','c','l','-','e','n','c','o','d','i','n','g',0
391 static const WCHAR PropertyXMLDeclStandaloneW[] = {
392 'x','m','l','d','e','c','l','-','s','t','a','n','d','a','l','o','n','e',0
394 static const WCHAR PropertyXMLDeclVersionW[] = {
395 'x','m','l','d','e','c','l','-','v','e','r','s','i','o','n',0
398 static inline HRESULT set_feature_value(saxreader *reader, saxreader_feature feature, VARIANT_BOOL value)
400 /* handling of non-VARIANT_* values is version dependent */
401 if ((reader->version < MSXML4) && (value != VARIANT_TRUE))
402 value = VARIANT_FALSE;
403 if ((reader->version >= MSXML4) && (value != VARIANT_FALSE))
404 value = VARIANT_TRUE;
406 if (value == VARIANT_TRUE)
407 reader->features |= feature;
408 else
409 reader->features &= ~feature;
411 return S_OK;
414 static inline HRESULT get_feature_value(const saxreader *reader, saxreader_feature feature, VARIANT_BOOL *value)
416 *value = reader->features & feature ? VARIANT_TRUE : VARIANT_FALSE;
417 return S_OK;
420 static BOOL is_namespaces_enabled(const saxreader *reader)
422 return (reader->version < MSXML4) || (reader->features & Namespaces);
425 static BSTR build_qname(BSTR prefix, BSTR local)
427 if (prefix && *prefix)
429 BSTR qname = SysAllocStringLen(NULL, SysStringLen(prefix) + SysStringLen(local) + 1);
430 WCHAR *ptr;
432 ptr = qname;
433 strcpyW(ptr, prefix);
434 ptr += SysStringLen(prefix);
435 *ptr++ = ':';
436 strcpyW(ptr, local);
437 return qname;
439 else
440 return SysAllocString(local);
443 static element_entry* alloc_element_entry(const xmlChar *local, const xmlChar *prefix, int nb_ns,
444 const xmlChar **namespaces)
446 element_entry *ret;
447 int i;
449 ret = heap_alloc(sizeof(*ret));
450 if (!ret) return ret;
452 ret->local = bstr_from_xmlChar(local);
453 ret->prefix = bstr_from_xmlChar(prefix);
454 ret->qname = build_qname(ret->prefix, ret->local);
455 ret->ns = nb_ns ? heap_alloc(nb_ns*sizeof(ns)) : NULL;
456 ret->ns_count = nb_ns;
458 for (i=0; i < nb_ns; i++)
460 ret->ns[i].prefix = bstr_from_xmlChar(namespaces[2*i]);
461 ret->ns[i].uri = bstr_from_xmlChar(namespaces[2*i+1]);
464 return ret;
467 static void free_element_entry(element_entry *element)
469 int i;
471 for (i=0; i<element->ns_count;i++)
473 SysFreeString(element->ns[i].prefix);
474 SysFreeString(element->ns[i].uri);
477 SysFreeString(element->prefix);
478 SysFreeString(element->local);
480 heap_free(element->ns);
481 heap_free(element);
484 static void push_element_ns(saxlocator *locator, element_entry *element)
486 list_add_head(&locator->elements, &element->entry);
489 static element_entry * pop_element_ns(saxlocator *locator)
491 element_entry *element = LIST_ENTRY(list_head(&locator->elements), element_entry, entry);
493 if (element)
494 list_remove(&element->entry);
496 return element;
499 static BSTR find_element_uri(saxlocator *locator, const xmlChar *uri)
501 element_entry *element;
502 BSTR uriW;
503 int i;
505 if (!uri) return NULL;
507 uriW = bstr_from_xmlChar(uri);
509 LIST_FOR_EACH_ENTRY(element, &locator->elements, element_entry, entry)
511 for (i=0; i < element->ns_count; i++)
512 if (!strcmpW(uriW, element->ns[i].uri))
514 SysFreeString(uriW);
515 return element->ns[i].uri;
519 SysFreeString(uriW);
520 ERR("namespace uri not found, %s\n", debugstr_a((char*)uri));
521 return NULL;
524 /* used to localize version dependent error check behaviour */
525 static inline BOOL sax_callback_failed(saxlocator *This, HRESULT hr)
527 return This->saxreader->version >= MSXML4 ? FAILED(hr) : hr != S_OK;
530 /* index value -1 means it tries to loop for a first time */
531 static inline BOOL iterate_endprefix_index(saxlocator *This, const element_entry *element, int *i)
533 if (This->saxreader->version >= MSXML4)
535 if (*i == -1) *i = 0; else ++*i;
536 return *i < element->ns_count;
538 else
540 if (*i == -1) *i = element->ns_count-1; else --*i;
541 return *i >= 0;
545 static BOOL bstr_pool_insert(struct bstrpool *pool, BSTR pool_entry)
547 if (!pool->pool)
549 pool->pool = HeapAlloc(GetProcessHeap(), 0, 16 * sizeof(*pool->pool));
550 if (!pool->pool)
551 return FALSE;
553 pool->index = 0;
554 pool->len = 16;
556 else if (pool->index == pool->len)
558 BSTR *realloc = HeapReAlloc(GetProcessHeap(), 0, pool->pool, pool->len * 2 * sizeof(*realloc));
560 if (!realloc)
561 return FALSE;
563 pool->pool = realloc;
564 pool->len *= 2;
567 pool->pool[pool->index++] = pool_entry;
568 return TRUE;
571 static void free_bstr_pool(struct bstrpool *pool)
573 unsigned int i;
575 for (i = 0; i < pool->index; i++)
576 SysFreeString(pool->pool[i]);
578 HeapFree(GetProcessHeap(), 0, pool->pool);
580 pool->pool = NULL;
581 pool->index = pool->len = 0;
584 static BSTR bstr_from_xmlCharN(const xmlChar *buf, int len)
586 DWORD dLen;
587 BSTR bstr;
589 if (!buf)
590 return NULL;
592 dLen = MultiByteToWideChar(CP_UTF8, 0, (LPCSTR)buf, len, NULL, 0);
593 if(len != -1) dLen++;
594 bstr = SysAllocStringLen(NULL, dLen-1);
595 if (!bstr)
596 return NULL;
597 MultiByteToWideChar(CP_UTF8, 0, (LPCSTR)buf, len, bstr, dLen);
598 if(len != -1) bstr[dLen-1] = '\0';
600 return bstr;
603 static BSTR QName_from_xmlChar(const xmlChar *prefix, const xmlChar *name)
605 xmlChar *qname;
606 BSTR bstr;
608 if(!name) return NULL;
610 if(!prefix || !*prefix)
611 return bstr_from_xmlChar(name);
613 qname = xmlBuildQName(name, prefix, NULL, 0);
614 bstr = bstr_from_xmlChar(qname);
615 xmlFree(qname);
617 return bstr;
620 static BSTR pooled_bstr_from_xmlChar(struct bstrpool *pool, const xmlChar *buf)
622 BSTR pool_entry = bstr_from_xmlChar(buf);
624 if (pool_entry && !bstr_pool_insert(pool, pool_entry))
626 SysFreeString(pool_entry);
627 return NULL;
630 return pool_entry;
633 static BSTR pooled_bstr_from_xmlCharN(struct bstrpool *pool, const xmlChar *buf, int len)
635 BSTR pool_entry = bstr_from_xmlCharN(buf, len);
637 if (pool_entry && !bstr_pool_insert(pool, pool_entry))
639 SysFreeString(pool_entry);
640 return NULL;
643 return pool_entry;
646 static void format_error_message_from_id(saxlocator *This, HRESULT hr)
648 struct saxerrorhandler_iface *handler = saxreader_get_errorhandler(This->saxreader);
649 xmlStopParser(This->pParserCtxt);
650 This->ret = hr;
652 if (saxreader_has_handler(This, SAXErrorHandler))
654 WCHAR msg[1024];
655 if(!FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM,
656 NULL, hr, 0, msg, sizeof(msg), NULL))
658 FIXME("MSXML errors not yet supported.\n");
659 msg[0] = '\0';
662 if(This->vbInterface)
664 BSTR bstrMsg = SysAllocString(msg);
665 IVBSAXErrorHandler_fatalError(handler->vbhandler,
666 &This->IVBSAXLocator_iface, &bstrMsg, hr);
667 SysFreeString(bstrMsg);
669 else
670 ISAXErrorHandler_fatalError(handler->handler,
671 &This->ISAXLocator_iface, msg, hr);
675 static void update_position(saxlocator *This, BOOL fix_column)
677 const xmlChar *p = This->pParserCtxt->input->cur-1;
679 This->line = xmlSAX2GetLineNumber(This->pParserCtxt);
680 if(fix_column)
682 This->column = 1;
683 for(; *p!='\n' && *p!='\r' && p>=This->pParserCtxt->input->base; p--)
684 This->column++;
686 else
688 This->column = xmlSAX2GetColumnNumber(This->pParserCtxt);
692 /*** IVBSAXAttributes interface ***/
693 /*** IUnknown methods ***/
694 static HRESULT WINAPI ivbsaxattributes_QueryInterface(
695 IVBSAXAttributes* iface,
696 REFIID riid,
697 void **ppvObject)
699 saxlocator *This = impl_from_IVBSAXAttributes(iface);
700 TRACE("%p %s %p\n", This, debugstr_guid(riid), ppvObject);
701 return IVBSAXLocator_QueryInterface(&This->IVBSAXLocator_iface, riid, ppvObject);
704 static ULONG WINAPI ivbsaxattributes_AddRef(IVBSAXAttributes* iface)
706 saxlocator *This = impl_from_IVBSAXAttributes(iface);
707 return ISAXLocator_AddRef(&This->ISAXLocator_iface);
710 static ULONG WINAPI ivbsaxattributes_Release(IVBSAXAttributes* iface)
712 saxlocator *This = impl_from_IVBSAXAttributes(iface);
713 return ISAXLocator_Release(&This->ISAXLocator_iface);
716 /*** IDispatch methods ***/
717 static HRESULT WINAPI ivbsaxattributes_GetTypeInfoCount( IVBSAXAttributes *iface, UINT* pctinfo )
719 saxlocator *This = impl_from_IVBSAXAttributes( iface );
721 TRACE("(%p)->(%p)\n", This, pctinfo);
723 *pctinfo = 1;
725 return S_OK;
728 static HRESULT WINAPI ivbsaxattributes_GetTypeInfo(
729 IVBSAXAttributes *iface,
730 UINT iTInfo, LCID lcid, ITypeInfo** ti )
732 saxlocator *This = impl_from_IVBSAXAttributes( iface );
733 HRESULT hr;
735 TRACE("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ti);
737 hr = get_typeinfo(IVBSAXAttributes_tid, ti);
738 ITypeInfo_AddRef(*ti);
739 return hr;
742 static HRESULT WINAPI ivbsaxattributes_GetIDsOfNames(
743 IVBSAXAttributes *iface,
744 REFIID riid,
745 LPOLESTR* rgszNames,
746 UINT cNames,
747 LCID lcid,
748 DISPID* rgDispId)
750 saxlocator *This = impl_from_IVBSAXAttributes( iface );
751 ITypeInfo *typeinfo;
752 HRESULT hr;
754 TRACE("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames, cNames,
755 lcid, rgDispId);
757 if(!rgszNames || cNames == 0 || !rgDispId)
758 return E_INVALIDARG;
760 hr = get_typeinfo(IVBSAXAttributes_tid, &typeinfo);
761 if(SUCCEEDED(hr))
762 hr = ITypeInfo_GetIDsOfNames(typeinfo, rgszNames, cNames, rgDispId);
764 return hr;
767 static HRESULT WINAPI ivbsaxattributes_Invoke(
768 IVBSAXAttributes *iface,
769 DISPID dispIdMember,
770 REFIID riid,
771 LCID lcid,
772 WORD wFlags,
773 DISPPARAMS* pDispParams,
774 VARIANT* pVarResult,
775 EXCEPINFO* pExcepInfo,
776 UINT* puArgErr)
778 saxlocator *This = impl_from_IVBSAXAttributes( iface );
779 ITypeInfo *typeinfo;
780 HRESULT hr;
782 TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
783 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
785 hr = get_typeinfo(IVBSAXAttributes_tid, &typeinfo);
786 if(SUCCEEDED(hr))
787 hr = ITypeInfo_Invoke(typeinfo, &This->IVBSAXAttributes_iface, dispIdMember, wFlags,
788 pDispParams, pVarResult, pExcepInfo, puArgErr);
790 return hr;
793 /*** IVBSAXAttributes methods ***/
794 static HRESULT WINAPI ivbsaxattributes_get_length(
795 IVBSAXAttributes* iface,
796 int *nLength)
798 saxlocator *This = impl_from_IVBSAXAttributes( iface );
799 return ISAXAttributes_getLength(&This->ISAXAttributes_iface, nLength);
802 static HRESULT WINAPI ivbsaxattributes_getURI(
803 IVBSAXAttributes* iface,
804 int nIndex,
805 BSTR *uri)
807 int len;
808 saxlocator *This = impl_from_IVBSAXAttributes( iface );
809 return ISAXAttributes_getURI(&This->ISAXAttributes_iface, nIndex, (const WCHAR**)uri, &len);
812 static HRESULT WINAPI ivbsaxattributes_getLocalName(
813 IVBSAXAttributes* iface,
814 int nIndex,
815 BSTR *localName)
817 int len;
818 saxlocator *This = impl_from_IVBSAXAttributes( iface );
819 return ISAXAttributes_getLocalName(&This->ISAXAttributes_iface, nIndex,
820 (const WCHAR**)localName, &len);
823 static HRESULT WINAPI ivbsaxattributes_getQName(
824 IVBSAXAttributes* iface,
825 int nIndex,
826 BSTR *QName)
828 int len;
829 saxlocator *This = impl_from_IVBSAXAttributes( iface );
830 return ISAXAttributes_getQName(&This->ISAXAttributes_iface, nIndex, (const WCHAR**)QName, &len);
833 static HRESULT WINAPI ivbsaxattributes_getIndexFromName(
834 IVBSAXAttributes* iface,
835 BSTR uri,
836 BSTR localName,
837 int *index)
839 saxlocator *This = impl_from_IVBSAXAttributes( iface );
840 return ISAXAttributes_getIndexFromName(&This->ISAXAttributes_iface, uri, SysStringLen(uri),
841 localName, SysStringLen(localName), index);
844 static HRESULT WINAPI ivbsaxattributes_getIndexFromQName(
845 IVBSAXAttributes* iface,
846 BSTR QName,
847 int *index)
849 saxlocator *This = impl_from_IVBSAXAttributes( iface );
850 return ISAXAttributes_getIndexFromQName(&This->ISAXAttributes_iface, QName,
851 SysStringLen(QName), index);
854 static HRESULT WINAPI ivbsaxattributes_getType(
855 IVBSAXAttributes* iface,
856 int nIndex,
857 BSTR *type)
859 int len;
860 saxlocator *This = impl_from_IVBSAXAttributes( iface );
861 return ISAXAttributes_getType(&This->ISAXAttributes_iface, nIndex, (const WCHAR**)type, &len);
864 static HRESULT WINAPI ivbsaxattributes_getTypeFromName(
865 IVBSAXAttributes* iface,
866 BSTR uri,
867 BSTR localName,
868 BSTR *type)
870 int len;
871 saxlocator *This = impl_from_IVBSAXAttributes( iface );
872 return ISAXAttributes_getTypeFromName(&This->ISAXAttributes_iface, uri, SysStringLen(uri),
873 localName, SysStringLen(localName), (const WCHAR**)type, &len);
876 static HRESULT WINAPI ivbsaxattributes_getTypeFromQName(
877 IVBSAXAttributes* iface,
878 BSTR QName,
879 BSTR *type)
881 int len;
882 saxlocator *This = impl_from_IVBSAXAttributes( iface );
883 return ISAXAttributes_getTypeFromQName(&This->ISAXAttributes_iface, QName, SysStringLen(QName),
884 (const WCHAR**)type, &len);
887 static HRESULT WINAPI ivbsaxattributes_getValue(
888 IVBSAXAttributes* iface,
889 int nIndex,
890 BSTR *value)
892 int len;
893 saxlocator *This = impl_from_IVBSAXAttributes( iface );
894 return ISAXAttributes_getValue(&This->ISAXAttributes_iface, nIndex, (const WCHAR**)value, &len);
897 static HRESULT WINAPI ivbsaxattributes_getValueFromName(
898 IVBSAXAttributes* iface,
899 BSTR uri,
900 BSTR localName,
901 BSTR *value)
903 int len;
904 saxlocator *This = impl_from_IVBSAXAttributes( iface );
905 return ISAXAttributes_getValueFromName(&This->ISAXAttributes_iface, uri, SysStringLen(uri),
906 localName, SysStringLen(localName), (const WCHAR**)value, &len);
909 static HRESULT WINAPI ivbsaxattributes_getValueFromQName(
910 IVBSAXAttributes* iface,
911 BSTR QName,
912 BSTR *value)
914 int len;
915 saxlocator *This = impl_from_IVBSAXAttributes( iface );
916 return ISAXAttributes_getValueFromQName(&This->ISAXAttributes_iface, QName,
917 SysStringLen(QName), (const WCHAR**)value, &len);
920 static const struct IVBSAXAttributesVtbl ivbsaxattributes_vtbl =
922 ivbsaxattributes_QueryInterface,
923 ivbsaxattributes_AddRef,
924 ivbsaxattributes_Release,
925 ivbsaxattributes_GetTypeInfoCount,
926 ivbsaxattributes_GetTypeInfo,
927 ivbsaxattributes_GetIDsOfNames,
928 ivbsaxattributes_Invoke,
929 ivbsaxattributes_get_length,
930 ivbsaxattributes_getURI,
931 ivbsaxattributes_getLocalName,
932 ivbsaxattributes_getQName,
933 ivbsaxattributes_getIndexFromName,
934 ivbsaxattributes_getIndexFromQName,
935 ivbsaxattributes_getType,
936 ivbsaxattributes_getTypeFromName,
937 ivbsaxattributes_getTypeFromQName,
938 ivbsaxattributes_getValue,
939 ivbsaxattributes_getValueFromName,
940 ivbsaxattributes_getValueFromQName
943 /*** ISAXAttributes interface ***/
944 /*** IUnknown methods ***/
945 static HRESULT WINAPI isaxattributes_QueryInterface(
946 ISAXAttributes* iface,
947 REFIID riid,
948 void **ppvObject)
950 saxlocator *This = impl_from_ISAXAttributes(iface);
951 TRACE("%p %s %p\n", This, debugstr_guid(riid), ppvObject);
952 return ISAXLocator_QueryInterface(&This->ISAXLocator_iface, riid, ppvObject);
955 static ULONG WINAPI isaxattributes_AddRef(ISAXAttributes* iface)
957 saxlocator *This = impl_from_ISAXAttributes(iface);
958 TRACE("%p\n", This);
959 return ISAXLocator_AddRef(&This->ISAXLocator_iface);
962 static ULONG WINAPI isaxattributes_Release(ISAXAttributes* iface)
964 saxlocator *This = impl_from_ISAXAttributes(iface);
966 TRACE("%p\n", This);
967 return ISAXLocator_Release(&This->ISAXLocator_iface);
970 /*** ISAXAttributes methods ***/
971 static HRESULT WINAPI isaxattributes_getLength(
972 ISAXAttributes* iface,
973 int *length)
975 saxlocator *This = impl_from_ISAXAttributes( iface );
977 *length = This->nb_attributes;
978 TRACE("Length set to %d\n", *length);
979 return S_OK;
982 static HRESULT WINAPI isaxattributes_getURI(
983 ISAXAttributes* iface,
984 int index,
985 const WCHAR **url,
986 int *size)
988 saxlocator *This = impl_from_ISAXAttributes( iface );
989 TRACE("(%p)->(%d)\n", This, index);
991 if(index >= This->nb_attributes || index < 0) return E_INVALIDARG;
992 if(!url || !size) return E_POINTER;
994 *size = SysStringLen(This->attributes[index].szURI);
995 *url = This->attributes[index].szURI;
997 TRACE("(%s:%d)\n", debugstr_w(This->attributes[index].szURI), *size);
999 return S_OK;
1002 static HRESULT WINAPI isaxattributes_getLocalName(
1003 ISAXAttributes* iface,
1004 int nIndex,
1005 const WCHAR **pLocalName,
1006 int *pLocalNameLength)
1008 saxlocator *This = impl_from_ISAXAttributes( iface );
1009 TRACE("(%p)->(%d)\n", This, nIndex);
1011 if(nIndex>=This->nb_attributes || nIndex<0) return E_INVALIDARG;
1012 if(!pLocalName || !pLocalNameLength) return E_POINTER;
1014 *pLocalNameLength = SysStringLen(This->attributes[nIndex].szLocalname);
1015 *pLocalName = This->attributes[nIndex].szLocalname;
1017 return S_OK;
1020 static HRESULT WINAPI isaxattributes_getQName(
1021 ISAXAttributes* iface,
1022 int nIndex,
1023 const WCHAR **pQName,
1024 int *pQNameLength)
1026 saxlocator *This = impl_from_ISAXAttributes( iface );
1027 TRACE("(%p)->(%d)\n", This, nIndex);
1029 if(nIndex>=This->nb_attributes || nIndex<0) return E_INVALIDARG;
1030 if(!pQName || !pQNameLength) return E_POINTER;
1032 *pQNameLength = SysStringLen(This->attributes[nIndex].szQName);
1033 *pQName = This->attributes[nIndex].szQName;
1035 return S_OK;
1038 static HRESULT WINAPI isaxattributes_getName(
1039 ISAXAttributes* iface,
1040 int index,
1041 const WCHAR **uri,
1042 int *pUriLength,
1043 const WCHAR **localName,
1044 int *pLocalNameSize,
1045 const WCHAR **QName,
1046 int *pQNameLength)
1048 saxlocator *This = impl_from_ISAXAttributes( iface );
1049 TRACE("(%p)->(%d)\n", This, index);
1051 if(index>=This->nb_attributes || index<0) return E_INVALIDARG;
1052 if(!uri || !pUriLength || !localName || !pLocalNameSize
1053 || !QName || !pQNameLength) return E_POINTER;
1055 *pUriLength = SysStringLen(This->attributes[index].szURI);
1056 *uri = This->attributes[index].szURI;
1057 *pLocalNameSize = SysStringLen(This->attributes[index].szLocalname);
1058 *localName = This->attributes[index].szLocalname;
1059 *pQNameLength = SysStringLen(This->attributes[index].szQName);
1060 *QName = This->attributes[index].szQName;
1062 TRACE("(%s, %s, %s)\n", debugstr_w(*uri), debugstr_w(*localName), debugstr_w(*QName));
1064 return S_OK;
1067 static HRESULT WINAPI isaxattributes_getIndexFromName(
1068 ISAXAttributes* iface,
1069 const WCHAR *pUri,
1070 int cUriLength,
1071 const WCHAR *pLocalName,
1072 int cocalNameLength,
1073 int *index)
1075 saxlocator *This = impl_from_ISAXAttributes( iface );
1076 int i;
1077 TRACE("(%p)->(%s, %d, %s, %d)\n", This, debugstr_w(pUri), cUriLength,
1078 debugstr_w(pLocalName), cocalNameLength);
1080 if(!pUri || !pLocalName || !index) return E_POINTER;
1082 for(i=0; i<This->nb_attributes; i++)
1084 if(cUriLength!=SysStringLen(This->attributes[i].szURI)
1085 || cocalNameLength!=SysStringLen(This->attributes[i].szLocalname))
1086 continue;
1087 if(cUriLength && memcmp(pUri, This->attributes[i].szURI,
1088 sizeof(WCHAR)*cUriLength))
1089 continue;
1090 if(cocalNameLength && memcmp(pLocalName, This->attributes[i].szLocalname,
1091 sizeof(WCHAR)*cocalNameLength))
1092 continue;
1094 *index = i;
1095 return S_OK;
1098 return E_INVALIDARG;
1101 static HRESULT WINAPI isaxattributes_getIndexFromQName(
1102 ISAXAttributes* iface,
1103 const WCHAR *pQName,
1104 int nQNameLength,
1105 int *index)
1107 saxlocator *This = impl_from_ISAXAttributes( iface );
1108 int i;
1109 TRACE("(%p)->(%s, %d)\n", This, debugstr_w(pQName), nQNameLength);
1111 if(!pQName || !index) return E_POINTER;
1112 if(!nQNameLength) return E_INVALIDARG;
1114 for(i=0; i<This->nb_attributes; i++)
1116 if(nQNameLength!=SysStringLen(This->attributes[i].szQName)) continue;
1117 if(memcmp(pQName, This->attributes[i].szQName, sizeof(WCHAR)*nQNameLength)) continue;
1119 *index = i;
1120 return S_OK;
1123 return E_INVALIDARG;
1126 static HRESULT WINAPI isaxattributes_getType(
1127 ISAXAttributes* iface,
1128 int nIndex,
1129 const WCHAR **pType,
1130 int *pTypeLength)
1132 saxlocator *This = impl_from_ISAXAttributes( iface );
1134 FIXME("(%p)->(%d) stub\n", This, nIndex);
1135 return E_NOTIMPL;
1138 static HRESULT WINAPI isaxattributes_getTypeFromName(
1139 ISAXAttributes* iface,
1140 const WCHAR *pUri,
1141 int nUri,
1142 const WCHAR *pLocalName,
1143 int nLocalName,
1144 const WCHAR **pType,
1145 int *nType)
1147 saxlocator *This = impl_from_ISAXAttributes( iface );
1149 FIXME("(%p)->(%s, %d, %s, %d) stub\n", This, debugstr_w(pUri), nUri,
1150 debugstr_w(pLocalName), nLocalName);
1151 return E_NOTIMPL;
1154 static HRESULT WINAPI isaxattributes_getTypeFromQName(
1155 ISAXAttributes* iface,
1156 const WCHAR *pQName,
1157 int nQName,
1158 const WCHAR **pType,
1159 int *nType)
1161 saxlocator *This = impl_from_ISAXAttributes( iface );
1163 FIXME("(%p)->(%s, %d) stub\n", This, debugstr_w(pQName), nQName);
1164 return E_NOTIMPL;
1167 static HRESULT WINAPI isaxattributes_getValue(
1168 ISAXAttributes* iface,
1169 int index,
1170 const WCHAR **value,
1171 int *nValue)
1173 saxlocator *This = impl_from_ISAXAttributes( iface );
1174 TRACE("(%p)->(%d)\n", This, index);
1176 if(index>=This->nb_attributes || index<0) return E_INVALIDARG;
1177 if(!value || !nValue) return E_POINTER;
1179 *nValue = SysStringLen(This->attributes[index].szValue);
1180 *value = This->attributes[index].szValue;
1182 TRACE("(%s:%d)\n", debugstr_w(*value), *nValue);
1184 return S_OK;
1187 static HRESULT WINAPI isaxattributes_getValueFromName(
1188 ISAXAttributes* iface,
1189 const WCHAR *pUri,
1190 int nUri,
1191 const WCHAR *pLocalName,
1192 int nLocalName,
1193 const WCHAR **pValue,
1194 int *nValue)
1196 HRESULT hr;
1197 int index;
1198 saxlocator *This = impl_from_ISAXAttributes( iface );
1199 TRACE("(%p)->(%s, %d, %s, %d)\n", This, debugstr_w(pUri), nUri,
1200 debugstr_w(pLocalName), nLocalName);
1202 hr = ISAXAttributes_getIndexFromName(iface,
1203 pUri, nUri, pLocalName, nLocalName, &index);
1204 if(hr==S_OK) hr = ISAXAttributes_getValue(iface, index, pValue, nValue);
1206 return hr;
1209 static HRESULT WINAPI isaxattributes_getValueFromQName(
1210 ISAXAttributes* iface,
1211 const WCHAR *pQName,
1212 int nQName,
1213 const WCHAR **pValue,
1214 int *nValue)
1216 HRESULT hr;
1217 int index;
1218 saxlocator *This = impl_from_ISAXAttributes( iface );
1219 TRACE("(%p)->(%s, %d)\n", This, debugstr_w(pQName), nQName);
1221 hr = ISAXAttributes_getIndexFromQName(iface, pQName, nQName, &index);
1222 if(hr==S_OK) hr = ISAXAttributes_getValue(iface, index, pValue, nValue);
1224 return hr;
1227 static const struct ISAXAttributesVtbl isaxattributes_vtbl =
1229 isaxattributes_QueryInterface,
1230 isaxattributes_AddRef,
1231 isaxattributes_Release,
1232 isaxattributes_getLength,
1233 isaxattributes_getURI,
1234 isaxattributes_getLocalName,
1235 isaxattributes_getQName,
1236 isaxattributes_getName,
1237 isaxattributes_getIndexFromName,
1238 isaxattributes_getIndexFromQName,
1239 isaxattributes_getType,
1240 isaxattributes_getTypeFromName,
1241 isaxattributes_getTypeFromQName,
1242 isaxattributes_getValue,
1243 isaxattributes_getValueFromName,
1244 isaxattributes_getValueFromQName
1247 static HRESULT SAXAttributes_populate(saxlocator *locator,
1248 int nb_namespaces, const xmlChar **xmlNamespaces,
1249 int nb_attributes, const xmlChar **xmlAttributes)
1251 static const xmlChar xmlns[] = "xmlns";
1252 static const WCHAR xmlnsW[] = { 'x','m','l','n','s',0 };
1254 struct _attributes *attrs;
1255 int i;
1257 /* skip namespace definitions */
1258 if ((locator->saxreader->features & NamespacePrefixes) == 0)
1259 nb_namespaces = 0;
1261 locator->nb_attributes = nb_namespaces + nb_attributes;
1262 if(locator->nb_attributes > locator->attributesSize)
1264 attrs = heap_realloc(locator->attributes, sizeof(struct _attributes)*locator->nb_attributes*2);
1265 if(!attrs)
1267 locator->nb_attributes = 0;
1268 return E_OUTOFMEMORY;
1270 locator->attributes = attrs;
1272 else
1274 attrs = locator->attributes;
1277 for (i = 0; i < nb_namespaces; i++)
1279 attrs[nb_attributes+i].szLocalname = SysAllocStringLen(NULL, 0);
1280 attrs[nb_attributes+i].szURI = locator->namespaceUri;
1281 attrs[nb_attributes+i].szValue = bstr_from_xmlChar(xmlNamespaces[2*i+1]);
1282 if(!xmlNamespaces[2*i])
1283 attrs[nb_attributes+i].szQName = SysAllocString(xmlnsW);
1284 else
1285 attrs[nb_attributes+i].szQName = QName_from_xmlChar(xmlns, xmlNamespaces[2*i]);
1288 for (i = 0; i < nb_attributes; i++)
1290 static const xmlChar xmlA[] = "xml";
1292 if (xmlStrEqual(xmlAttributes[i*5+1], xmlA))
1293 attrs[i].szURI = bstr_from_xmlChar(xmlAttributes[i*5+2]);
1294 else
1295 /* that's an important feature to keep same uri pointer for every reported attribute */
1296 attrs[i].szURI = find_element_uri(locator, xmlAttributes[i*5+2]);
1298 attrs[i].szLocalname = bstr_from_xmlChar(xmlAttributes[i*5]);
1299 attrs[i].szValue = bstr_from_xmlCharN(xmlAttributes[i*5+3],
1300 xmlAttributes[i*5+4]-xmlAttributes[i*5+3]);
1301 attrs[i].szQName = QName_from_xmlChar(xmlAttributes[i*5+1],
1302 xmlAttributes[i*5]);
1305 return S_OK;
1308 /*** LibXML callbacks ***/
1309 static void libxmlStartDocument(void *ctx)
1311 saxlocator *This = ctx;
1312 struct saxcontenthandler_iface *handler = saxreader_get_contenthandler(This->saxreader);
1313 HRESULT hr;
1315 if (This->saxreader->version >= MSXML4)
1317 const xmlChar *p = This->pParserCtxt->input->cur-1;
1318 update_position(This, FALSE);
1319 while(p>This->pParserCtxt->input->base && *p!='>')
1321 if(*p=='\n' || (*p=='\r' && *(p+1)!='\n'))
1322 This->line--;
1323 p--;
1325 This->column = 0;
1326 for(; p>=This->pParserCtxt->input->base && *p!='\n' && *p!='\r'; p--)
1327 This->column++;
1330 /* store version value, declaration has to contain version attribute */
1331 if (This->pParserCtxt->standalone != -1)
1333 SysFreeString(This->saxreader->xmldecl_version);
1334 This->saxreader->xmldecl_version = bstr_from_xmlChar(This->pParserCtxt->version);
1337 if (saxreader_has_handler(This, SAXContentHandler))
1339 if(This->vbInterface)
1340 hr = IVBSAXContentHandler_startDocument(handler->vbhandler);
1341 else
1342 hr = ISAXContentHandler_startDocument(handler->handler);
1344 if (sax_callback_failed(This, hr))
1345 format_error_message_from_id(This, hr);
1349 static void libxmlEndDocument(void *ctx)
1351 saxlocator *This = ctx;
1352 struct saxcontenthandler_iface *handler = saxreader_get_contenthandler(This->saxreader);
1353 HRESULT hr;
1355 if (This->saxreader->version >= MSXML4) {
1356 update_position(This, FALSE);
1357 if(This->column > 1)
1358 This->line++;
1359 This->column = 0;
1360 } else {
1361 This->column = 0;
1362 This->line = 0;
1365 if(This->ret != S_OK) return;
1367 if (saxreader_has_handler(This, SAXContentHandler))
1369 if(This->vbInterface)
1370 hr = IVBSAXContentHandler_endDocument(handler->vbhandler);
1371 else
1372 hr = ISAXContentHandler_endDocument(handler->handler);
1374 if (sax_callback_failed(This, hr))
1375 format_error_message_from_id(This, hr);
1379 static void libxmlStartElementNS(
1380 void *ctx,
1381 const xmlChar *localname,
1382 const xmlChar *prefix,
1383 const xmlChar *URI,
1384 int nb_namespaces,
1385 const xmlChar **namespaces,
1386 int nb_attributes,
1387 int nb_defaulted,
1388 const xmlChar **attributes)
1390 saxlocator *This = ctx;
1391 struct saxcontenthandler_iface *handler = saxreader_get_contenthandler(This->saxreader);
1392 element_entry *element;
1393 HRESULT hr = S_OK;
1394 BSTR uri;
1396 update_position(This, TRUE);
1397 if(*(This->pParserCtxt->input->cur) == '/')
1398 This->column++;
1399 if(This->saxreader->version < MSXML4)
1400 This->column++;
1402 element = alloc_element_entry(localname, prefix, nb_namespaces, namespaces);
1403 push_element_ns(This, element);
1405 if (is_namespaces_enabled(This->saxreader))
1407 int i;
1409 for (i = 0; i < nb_namespaces && saxreader_has_handler(This, SAXContentHandler); i++)
1411 if (This->vbInterface)
1412 hr = IVBSAXContentHandler_startPrefixMapping(
1413 handler->vbhandler,
1414 &element->ns[i].prefix,
1415 &element->ns[i].uri);
1416 else
1417 hr = ISAXContentHandler_startPrefixMapping(
1418 handler->handler,
1419 element->ns[i].prefix,
1420 SysStringLen(element->ns[i].prefix),
1421 element->ns[i].uri,
1422 SysStringLen(element->ns[i].uri));
1424 if (sax_callback_failed(This, hr))
1426 format_error_message_from_id(This, hr);
1427 return;
1432 uri = find_element_uri(This, URI);
1433 hr = SAXAttributes_populate(This, nb_namespaces, namespaces, nb_attributes, attributes);
1434 if (hr == S_OK && saxreader_has_handler(This, SAXContentHandler))
1436 BSTR local;
1438 if (is_namespaces_enabled(This->saxreader))
1439 local = element->local;
1440 else
1441 uri = local = NULL;
1443 if (This->vbInterface)
1444 hr = IVBSAXContentHandler_startElement(handler->vbhandler,
1445 &uri, &local, &element->qname, &This->IVBSAXAttributes_iface);
1446 else
1447 hr = ISAXContentHandler_startElement(handler->handler,
1448 uri, SysStringLen(uri),
1449 local, SysStringLen(local),
1450 element->qname, SysStringLen(element->qname),
1451 &This->ISAXAttributes_iface);
1453 if (sax_callback_failed(This, hr))
1454 format_error_message_from_id(This, hr);
1458 static void libxmlEndElementNS(
1459 void *ctx,
1460 const xmlChar *localname,
1461 const xmlChar *prefix,
1462 const xmlChar *URI)
1464 saxlocator *This = ctx;
1465 struct saxcontenthandler_iface *handler = saxreader_get_contenthandler(This->saxreader);
1466 element_entry *element;
1467 const xmlChar *p;
1468 BSTR uri, local;
1469 HRESULT hr;
1471 update_position(This, FALSE);
1472 p = This->pParserCtxt->input->cur;
1474 if (This->saxreader->version >= MSXML4)
1476 p--;
1477 while(p>This->pParserCtxt->input->base && *p!='>')
1479 if(*p=='\n' || (*p=='\r' && *(p+1)!='\n'))
1480 This->line--;
1481 p--;
1484 else if(*(p-1)!='>' || *(p-2)!='/')
1486 p--;
1487 while(p-2>=This->pParserCtxt->input->base
1488 && *(p-2)!='<' && *(p-1)!='/')
1490 if(*p=='\n' || (*p=='\r' && *(p+1)!='\n'))
1491 This->line--;
1492 p--;
1495 This->column = 0;
1496 for(; p>=This->pParserCtxt->input->base && *p!='\n' && *p!='\r'; p--)
1497 This->column++;
1499 uri = find_element_uri(This, URI);
1500 element = pop_element_ns(This);
1502 if (!saxreader_has_handler(This, SAXContentHandler))
1504 This->nb_attributes = 0;
1505 free_element_entry(element);
1506 return;
1509 if (is_namespaces_enabled(This->saxreader))
1510 local = element->local;
1511 else
1512 uri = local = NULL;
1514 if (This->vbInterface)
1515 hr = IVBSAXContentHandler_endElement(
1516 handler->vbhandler,
1517 &uri, &local, &element->qname);
1518 else
1519 hr = ISAXContentHandler_endElement(
1520 handler->handler,
1521 uri, SysStringLen(uri),
1522 local, SysStringLen(local),
1523 element->qname, SysStringLen(element->qname));
1525 This->nb_attributes = 0;
1527 if (sax_callback_failed(This, hr))
1529 format_error_message_from_id(This, hr);
1530 free_element_entry(element);
1531 return;
1534 if (is_namespaces_enabled(This->saxreader))
1536 int i = -1;
1537 while (iterate_endprefix_index(This, element, &i) && saxreader_has_handler(This, SAXContentHandler))
1539 if (This->vbInterface)
1540 hr = IVBSAXContentHandler_endPrefixMapping(
1541 handler->vbhandler, &element->ns[i].prefix);
1542 else
1543 hr = ISAXContentHandler_endPrefixMapping(
1544 handler->handler, element->ns[i].prefix, SysStringLen(element->ns[i].prefix));
1546 if (sax_callback_failed(This, hr)) break;
1549 if (sax_callback_failed(This, hr))
1550 format_error_message_from_id(This, hr);
1553 free_element_entry(element);
1556 static void libxmlCharacters(
1557 void *ctx,
1558 const xmlChar *ch,
1559 int len)
1561 saxlocator *This = ctx;
1562 struct saxcontenthandler_iface *handler = saxreader_get_contenthandler(This->saxreader);
1563 BSTR Chars;
1564 HRESULT hr;
1565 xmlChar *cur, *end;
1566 BOOL lastEvent = FALSE;
1568 if (!saxreader_has_handler(This, SAXContentHandler)) return;
1570 update_position(This, FALSE);
1571 cur = (xmlChar*)This->pParserCtxt->input->cur;
1572 while(cur>=This->pParserCtxt->input->base && *cur!='>')
1574 if(*cur=='\n' || (*cur=='\r' && *(cur+1)!='\n'))
1575 This->line--;
1576 cur--;
1578 This->column = 1;
1579 for(; cur>=This->pParserCtxt->input->base && *cur!='\n' && *cur!='\r'; cur--)
1580 This->column++;
1582 cur = (xmlChar*)ch;
1583 if(*(ch-1)=='\r') cur--;
1584 end = cur;
1586 while(1)
1588 while(end-ch<len && *end!='\r') end++;
1589 if(end-ch==len)
1591 lastEvent = TRUE;
1593 else
1595 *end = '\n';
1596 end++;
1599 if (This->saxreader->version >= MSXML4)
1601 xmlChar *p;
1603 for(p=cur; p!=end; p++)
1605 if(*p=='\n')
1607 This->line++;
1608 This->column = 1;
1610 else
1612 This->column++;
1616 if(!lastEvent)
1617 This->column = 0;
1620 Chars = pooled_bstr_from_xmlCharN(&This->saxreader->pool, cur, end-cur);
1621 if(This->vbInterface)
1622 hr = IVBSAXContentHandler_characters(handler->vbhandler, &Chars);
1623 else
1624 hr = ISAXContentHandler_characters(handler->handler, Chars, SysStringLen(Chars));
1626 if (sax_callback_failed(This, hr))
1628 format_error_message_from_id(This, hr);
1629 return;
1632 if (This->saxreader->version < MSXML4)
1633 This->column += end-cur;
1635 if(lastEvent)
1636 break;
1638 *(end-1) = '\r';
1639 if(*end == '\n')
1641 end++;
1642 This->column++;
1644 cur = end;
1646 if(end-ch == len) break;
1650 static void libxmlSetDocumentLocator(
1651 void *ctx,
1652 xmlSAXLocatorPtr loc)
1654 saxlocator *This = ctx;
1655 struct saxcontenthandler_iface *handler = saxreader_get_contenthandler(This->saxreader);
1656 HRESULT hr = S_OK;
1658 if (saxreader_has_handler(This, SAXContentHandler))
1660 if(This->vbInterface)
1661 hr = IVBSAXContentHandler_putref_documentLocator(handler->vbhandler,
1662 &This->IVBSAXLocator_iface);
1663 else
1664 hr = ISAXContentHandler_putDocumentLocator(handler->handler, &This->ISAXLocator_iface);
1667 if(FAILED(hr))
1668 format_error_message_from_id(This, hr);
1671 static void libxmlComment(void *ctx, const xmlChar *value)
1673 saxlocator *This = ctx;
1674 struct saxlexicalhandler_iface *handler = saxreader_get_lexicalhandler(This->saxreader);
1675 BSTR bValue;
1676 HRESULT hr;
1677 const xmlChar *p = This->pParserCtxt->input->cur;
1679 update_position(This, FALSE);
1680 while(p-4>=This->pParserCtxt->input->base
1681 && memcmp(p-4, "<!--", sizeof(char[4])))
1683 if(*p=='\n' || (*p=='\r' && *(p+1)!='\n'))
1684 This->line--;
1685 p--;
1688 This->column = 0;
1689 for(; p>=This->pParserCtxt->input->base && *p!='\n' && *p!='\r'; p--)
1690 This->column++;
1692 if (!saxreader_has_handler(This, SAXLexicalHandler)) return;
1694 bValue = pooled_bstr_from_xmlChar(&This->saxreader->pool, value);
1696 if (This->vbInterface)
1697 hr = IVBSAXLexicalHandler_comment(handler->vbhandler, &bValue);
1698 else
1699 hr = ISAXLexicalHandler_comment(handler->handler, bValue, SysStringLen(bValue));
1701 if(FAILED(hr))
1702 format_error_message_from_id(This, hr);
1705 static void libxmlFatalError(void *ctx, const char *msg, ...)
1707 saxlocator *This = ctx;
1708 struct saxerrorhandler_iface *handler = saxreader_get_errorhandler(This->saxreader);
1709 char message[1024];
1710 WCHAR *error;
1711 DWORD len;
1712 va_list args;
1714 if(This->ret != S_OK) {
1715 xmlStopParser(This->pParserCtxt);
1716 return;
1719 va_start(args, msg);
1720 vsprintf(message, msg, args);
1721 va_end(args);
1723 len = MultiByteToWideChar(CP_UNIXCP, 0, message, -1, NULL, 0);
1724 error = heap_alloc(sizeof(WCHAR)*len);
1725 if(error)
1727 MultiByteToWideChar(CP_UNIXCP, 0, message, -1, error, len);
1728 TRACE("fatal error for %p: %s\n", This, debugstr_w(error));
1731 if (!saxreader_has_handler(This, SAXErrorHandler))
1733 xmlStopParser(This->pParserCtxt);
1734 This->ret = E_FAIL;
1735 heap_free(error);
1736 return;
1739 FIXME("Error handling is not compatible.\n");
1741 if(This->vbInterface)
1743 BSTR bstrError = SysAllocString(error);
1744 IVBSAXErrorHandler_fatalError(handler->vbhandler, &This->IVBSAXLocator_iface,
1745 &bstrError, E_FAIL);
1746 SysFreeString(bstrError);
1748 else
1749 ISAXErrorHandler_fatalError(handler->handler, &This->ISAXLocator_iface, error, E_FAIL);
1751 heap_free(error);
1753 xmlStopParser(This->pParserCtxt);
1754 This->ret = E_FAIL;
1757 static void libxmlCDataBlock(void *ctx, const xmlChar *value, int len)
1759 saxlocator *This = ctx;
1760 struct saxcontenthandler_iface *content = saxreader_get_contenthandler(This->saxreader);
1761 struct saxlexicalhandler_iface *lexical = saxreader_get_lexicalhandler(This->saxreader);
1762 HRESULT hr = S_OK;
1763 xmlChar *beg = (xmlChar*)This->pParserCtxt->input->cur-len;
1764 xmlChar *cur, *end;
1765 int realLen;
1766 BSTR Chars;
1767 BOOL lastEvent = FALSE, change;
1769 update_position(This, FALSE);
1770 while(beg-9>=This->pParserCtxt->input->base
1771 && memcmp(beg-9, "<![CDATA[", sizeof(char[9])))
1773 if(*beg=='\n' || (*beg=='\r' && *(beg+1)!='\n'))
1774 This->line--;
1775 beg--;
1777 This->column = 0;
1778 for(; beg>=This->pParserCtxt->input->base && *beg!='\n' && *beg!='\r'; beg--)
1779 This->column++;
1781 if (saxreader_has_handler(This, SAXLexicalHandler))
1783 if (This->vbInterface)
1784 hr = IVBSAXLexicalHandler_startCDATA(lexical->vbhandler);
1785 else
1786 hr = ISAXLexicalHandler_startCDATA(lexical->handler);
1789 if(FAILED(hr))
1791 format_error_message_from_id(This, hr);
1792 return;
1795 realLen = This->pParserCtxt->input->cur-beg-3;
1796 cur = beg;
1797 end = beg;
1799 while(1)
1801 while(end-beg<realLen && *end!='\r') end++;
1802 if(end-beg==realLen)
1804 end--;
1805 lastEvent = TRUE;
1807 else if(end-beg==realLen-1 && *end=='\r' && *(end+1)=='\n')
1808 lastEvent = TRUE;
1810 if(*end == '\r') change = TRUE;
1811 else change = FALSE;
1813 if(change) *end = '\n';
1815 if (saxreader_has_handler(This, SAXContentHandler))
1817 Chars = pooled_bstr_from_xmlCharN(&This->saxreader->pool, cur, end-cur+1);
1818 if (This->vbInterface)
1819 hr = IVBSAXContentHandler_characters(content->vbhandler, &Chars);
1820 else
1821 hr = ISAXContentHandler_characters(content->handler, Chars, SysStringLen(Chars));
1824 if(change) *end = '\r';
1826 if(lastEvent)
1827 break;
1829 This->column += end-cur+2;
1830 end += 2;
1831 cur = end;
1834 if (saxreader_has_handler(This, SAXLexicalHandler))
1836 if (This->vbInterface)
1837 hr = IVBSAXLexicalHandler_endCDATA(lexical->vbhandler);
1838 else
1839 hr = ISAXLexicalHandler_endCDATA(lexical->handler);
1842 if(FAILED(hr))
1843 format_error_message_from_id(This, hr);
1845 This->column += 4+end-cur;
1848 static xmlParserInputPtr libxmlresolveentity(void *ctx, const xmlChar *publicid, const xmlChar *systemid)
1850 FIXME("entity resolving not implemented, %s, %s\n", publicid, systemid);
1851 return xmlSAX2ResolveEntity(ctx, publicid, systemid);
1854 /*** IVBSAXLocator interface ***/
1855 /*** IUnknown methods ***/
1856 static HRESULT WINAPI ivbsaxlocator_QueryInterface(IVBSAXLocator* iface, REFIID riid, void **ppvObject)
1858 saxlocator *This = impl_from_IVBSAXLocator( iface );
1860 TRACE("%p %s %p\n", This, debugstr_guid( riid ), ppvObject);
1862 *ppvObject = NULL;
1864 if ( IsEqualGUID( riid, &IID_IUnknown ) ||
1865 IsEqualGUID( riid, &IID_IDispatch) ||
1866 IsEqualGUID( riid, &IID_IVBSAXLocator ))
1868 *ppvObject = iface;
1870 else if ( IsEqualGUID( riid, &IID_IVBSAXAttributes ))
1872 *ppvObject = &This->IVBSAXAttributes_iface;
1874 else
1876 FIXME("interface %s not implemented\n", debugstr_guid(riid));
1877 return E_NOINTERFACE;
1880 IVBSAXLocator_AddRef( iface );
1882 return S_OK;
1885 static ULONG WINAPI ivbsaxlocator_AddRef(IVBSAXLocator* iface)
1887 saxlocator *This = impl_from_IVBSAXLocator( iface );
1888 TRACE("%p\n", This );
1889 return InterlockedIncrement( &This->ref );
1892 static ULONG WINAPI ivbsaxlocator_Release(
1893 IVBSAXLocator* iface)
1895 saxlocator *This = impl_from_IVBSAXLocator( iface );
1896 return ISAXLocator_Release((ISAXLocator*)&This->IVBSAXLocator_iface);
1899 /*** IDispatch methods ***/
1900 static HRESULT WINAPI ivbsaxlocator_GetTypeInfoCount( IVBSAXLocator *iface, UINT* pctinfo )
1902 saxlocator *This = impl_from_IVBSAXLocator( iface );
1904 TRACE("(%p)->(%p)\n", This, pctinfo);
1906 *pctinfo = 1;
1908 return S_OK;
1911 static HRESULT WINAPI ivbsaxlocator_GetTypeInfo(
1912 IVBSAXLocator *iface,
1913 UINT iTInfo, LCID lcid, ITypeInfo** ti )
1915 saxlocator *This = impl_from_IVBSAXLocator( iface );
1916 HRESULT hr;
1918 TRACE("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ti);
1920 hr = get_typeinfo(IVBSAXLocator_tid, ti);
1921 ITypeInfo_AddRef(*ti);
1922 return hr;
1925 static HRESULT WINAPI ivbsaxlocator_GetIDsOfNames(
1926 IVBSAXLocator *iface,
1927 REFIID riid,
1928 LPOLESTR* rgszNames,
1929 UINT cNames,
1930 LCID lcid,
1931 DISPID* rgDispId)
1933 saxlocator *This = impl_from_IVBSAXLocator( iface );
1934 ITypeInfo *typeinfo;
1935 HRESULT hr;
1937 TRACE("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames, cNames,
1938 lcid, rgDispId);
1940 if(!rgszNames || cNames == 0 || !rgDispId)
1941 return E_INVALIDARG;
1943 hr = get_typeinfo(IVBSAXLocator_tid, &typeinfo);
1944 if(SUCCEEDED(hr))
1945 hr = ITypeInfo_GetIDsOfNames(typeinfo, rgszNames, cNames, rgDispId);
1947 return hr;
1950 static HRESULT WINAPI ivbsaxlocator_Invoke(
1951 IVBSAXLocator *iface,
1952 DISPID dispIdMember,
1953 REFIID riid,
1954 LCID lcid,
1955 WORD wFlags,
1956 DISPPARAMS* pDispParams,
1957 VARIANT* pVarResult,
1958 EXCEPINFO* pExcepInfo,
1959 UINT* puArgErr)
1961 saxlocator *This = impl_from_IVBSAXLocator( iface );
1962 ITypeInfo *typeinfo;
1963 HRESULT hr;
1965 TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
1966 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
1968 hr = get_typeinfo(IVBSAXLocator_tid, &typeinfo);
1969 if(SUCCEEDED(hr))
1970 hr = ITypeInfo_Invoke(typeinfo, &This->IVBSAXLocator_iface, dispIdMember, wFlags,
1971 pDispParams, pVarResult, pExcepInfo, puArgErr);
1973 return hr;
1976 /*** IVBSAXLocator methods ***/
1977 static HRESULT WINAPI ivbsaxlocator_get_columnNumber(
1978 IVBSAXLocator* iface,
1979 int *pnColumn)
1981 saxlocator *This = impl_from_IVBSAXLocator( iface );
1982 return ISAXLocator_getColumnNumber((ISAXLocator*)&This->IVBSAXLocator_iface, pnColumn);
1985 static HRESULT WINAPI ivbsaxlocator_get_lineNumber(
1986 IVBSAXLocator* iface,
1987 int *pnLine)
1989 saxlocator *This = impl_from_IVBSAXLocator( iface );
1990 return ISAXLocator_getLineNumber((ISAXLocator*)&This->IVBSAXLocator_iface, pnLine);
1993 static HRESULT WINAPI ivbsaxlocator_get_publicId(
1994 IVBSAXLocator* iface,
1995 BSTR* publicId)
1997 saxlocator *This = impl_from_IVBSAXLocator( iface );
1998 return ISAXLocator_getPublicId((ISAXLocator*)&This->IVBSAXLocator_iface,
1999 (const WCHAR**)publicId);
2002 static HRESULT WINAPI ivbsaxlocator_get_systemId(
2003 IVBSAXLocator* iface,
2004 BSTR* systemId)
2006 saxlocator *This = impl_from_IVBSAXLocator( iface );
2007 return ISAXLocator_getSystemId((ISAXLocator*)&This->IVBSAXLocator_iface,
2008 (const WCHAR**)systemId);
2011 static const struct IVBSAXLocatorVtbl VBSAXLocatorVtbl =
2013 ivbsaxlocator_QueryInterface,
2014 ivbsaxlocator_AddRef,
2015 ivbsaxlocator_Release,
2016 ivbsaxlocator_GetTypeInfoCount,
2017 ivbsaxlocator_GetTypeInfo,
2018 ivbsaxlocator_GetIDsOfNames,
2019 ivbsaxlocator_Invoke,
2020 ivbsaxlocator_get_columnNumber,
2021 ivbsaxlocator_get_lineNumber,
2022 ivbsaxlocator_get_publicId,
2023 ivbsaxlocator_get_systemId
2026 /*** ISAXLocator interface ***/
2027 /*** IUnknown methods ***/
2028 static HRESULT WINAPI isaxlocator_QueryInterface(ISAXLocator* iface, REFIID riid, void **ppvObject)
2030 saxlocator *This = impl_from_ISAXLocator( iface );
2032 TRACE("%p %s %p\n", This, debugstr_guid( riid ), ppvObject );
2034 *ppvObject = NULL;
2036 if ( IsEqualGUID( riid, &IID_IUnknown ) ||
2037 IsEqualGUID( riid, &IID_ISAXLocator ))
2039 *ppvObject = iface;
2041 else if ( IsEqualGUID( riid, &IID_ISAXAttributes ))
2043 *ppvObject = &This->ISAXAttributes_iface;
2045 else
2047 WARN("interface %s not implemented\n", debugstr_guid(riid));
2048 return E_NOINTERFACE;
2051 ISAXLocator_AddRef( iface );
2053 return S_OK;
2056 static ULONG WINAPI isaxlocator_AddRef(ISAXLocator* iface)
2058 saxlocator *This = impl_from_ISAXLocator( iface );
2059 ULONG ref = InterlockedIncrement( &This->ref );
2060 TRACE("(%p)->(%d)\n", This, ref);
2061 return ref;
2064 static ULONG WINAPI isaxlocator_Release(
2065 ISAXLocator* iface)
2067 saxlocator *This = impl_from_ISAXLocator( iface );
2068 LONG ref = InterlockedDecrement( &This->ref );
2070 TRACE("(%p)->(%d)\n", This, ref );
2072 if (ref == 0)
2074 element_entry *element, *element2;
2075 int index;
2077 SysFreeString(This->publicId);
2078 SysFreeString(This->systemId);
2079 SysFreeString(This->namespaceUri);
2081 for(index=0; index<This->nb_attributes; index++)
2083 SysFreeString(This->attributes[index].szLocalname);
2084 SysFreeString(This->attributes[index].szValue);
2085 SysFreeString(This->attributes[index].szQName);
2087 heap_free(This->attributes);
2089 /* element stack */
2090 LIST_FOR_EACH_ENTRY_SAFE(element, element2, &This->elements, element_entry, entry)
2092 list_remove(&element->entry);
2093 free_element_entry(element);
2096 ISAXXMLReader_Release(&This->saxreader->ISAXXMLReader_iface);
2097 heap_free( This );
2100 return ref;
2103 /*** ISAXLocator methods ***/
2104 static HRESULT WINAPI isaxlocator_getColumnNumber(
2105 ISAXLocator* iface,
2106 int *pnColumn)
2108 saxlocator *This = impl_from_ISAXLocator( iface );
2110 *pnColumn = This->column;
2111 return S_OK;
2114 static HRESULT WINAPI isaxlocator_getLineNumber(
2115 ISAXLocator* iface,
2116 int *pnLine)
2118 saxlocator *This = impl_from_ISAXLocator( iface );
2120 *pnLine = This->line;
2121 return S_OK;
2124 static HRESULT WINAPI isaxlocator_getPublicId(
2125 ISAXLocator* iface,
2126 const WCHAR ** ppwchPublicId)
2128 BSTR publicId;
2129 saxlocator *This = impl_from_ISAXLocator( iface );
2131 SysFreeString(This->publicId);
2133 publicId = bstr_from_xmlChar(xmlSAX2GetPublicId(This->pParserCtxt));
2134 if(SysStringLen(publicId))
2135 This->publicId = publicId;
2136 else
2138 SysFreeString(publicId);
2139 This->publicId = NULL;
2142 *ppwchPublicId = This->publicId;
2143 return S_OK;
2146 static HRESULT WINAPI isaxlocator_getSystemId(
2147 ISAXLocator* iface,
2148 const WCHAR ** ppwchSystemId)
2150 BSTR systemId;
2151 saxlocator *This = impl_from_ISAXLocator( iface );
2153 SysFreeString(This->systemId);
2155 systemId = bstr_from_xmlChar(xmlSAX2GetSystemId(This->pParserCtxt));
2156 if(SysStringLen(systemId))
2157 This->systemId = systemId;
2158 else
2160 SysFreeString(systemId);
2161 This->systemId = NULL;
2164 *ppwchSystemId = This->systemId;
2165 return S_OK;
2168 static const struct ISAXLocatorVtbl SAXLocatorVtbl =
2170 isaxlocator_QueryInterface,
2171 isaxlocator_AddRef,
2172 isaxlocator_Release,
2173 isaxlocator_getColumnNumber,
2174 isaxlocator_getLineNumber,
2175 isaxlocator_getPublicId,
2176 isaxlocator_getSystemId
2179 static HRESULT SAXLocator_create(saxreader *reader, saxlocator **ppsaxlocator, BOOL vbInterface)
2181 static const WCHAR w3xmlns[] = { 'h','t','t','p',':','/','/', 'w','w','w','.','w','3','.',
2182 'o','r','g','/','2','0','0','0','/','x','m','l','n','s','/',0 };
2184 saxlocator *locator;
2186 locator = heap_alloc( sizeof (*locator) );
2187 if( !locator )
2188 return E_OUTOFMEMORY;
2190 locator->IVBSAXLocator_iface.lpVtbl = &VBSAXLocatorVtbl;
2191 locator->ISAXLocator_iface.lpVtbl = &SAXLocatorVtbl;
2192 locator->IVBSAXAttributes_iface.lpVtbl = &ivbsaxattributes_vtbl;
2193 locator->ISAXAttributes_iface.lpVtbl = &isaxattributes_vtbl;
2194 locator->ref = 1;
2195 locator->vbInterface = vbInterface;
2197 locator->saxreader = reader;
2198 ISAXXMLReader_AddRef(&reader->ISAXXMLReader_iface);
2200 locator->pParserCtxt = NULL;
2201 locator->publicId = NULL;
2202 locator->systemId = NULL;
2203 locator->line = reader->version < MSXML4 ? 0 : 1;
2204 locator->column = 0;
2205 locator->ret = S_OK;
2206 if (locator->saxreader->version >= MSXML6)
2207 locator->namespaceUri = SysAllocString(w3xmlns);
2208 else
2209 locator->namespaceUri = SysAllocStringLen(NULL, 0);
2210 if(!locator->namespaceUri)
2212 ISAXXMLReader_Release(&reader->ISAXXMLReader_iface);
2213 heap_free(locator);
2214 return E_OUTOFMEMORY;
2217 locator->attributesSize = 8;
2218 locator->nb_attributes = 0;
2219 locator->attributes = heap_alloc(sizeof(struct _attributes)*locator->attributesSize);
2220 if(!locator->attributes)
2222 ISAXXMLReader_Release(&reader->ISAXXMLReader_iface);
2223 SysFreeString(locator->namespaceUri);
2224 heap_free(locator);
2225 return E_OUTOFMEMORY;
2228 list_init(&locator->elements);
2230 *ppsaxlocator = locator;
2232 TRACE("returning %p\n", *ppsaxlocator);
2234 return S_OK;
2237 /*** SAXXMLReader internal functions ***/
2238 static HRESULT internal_parseBuffer(saxreader *This, const char *buffer, int size, BOOL vbInterface)
2240 xmlCharEncoding encoding = XML_CHAR_ENCODING_NONE;
2241 xmlChar *enc_name = NULL;
2242 saxlocator *locator;
2243 HRESULT hr;
2245 TRACE("(%p)->(%p %d)\n", This, buffer, size);
2247 hr = SAXLocator_create(This, &locator, vbInterface);
2248 if (FAILED(hr))
2249 return hr;
2251 if (size >= 4)
2253 const unsigned char *buff = (unsigned char*)buffer;
2255 encoding = xmlDetectCharEncoding((xmlChar*)buffer, 4);
2256 enc_name = (xmlChar*)xmlGetCharEncodingName(encoding);
2257 TRACE("detected encoding: %s\n", enc_name);
2258 /* skip BOM, parser won't switch encodings and so won't skip it on its own */
2259 if ((encoding == XML_CHAR_ENCODING_UTF8) &&
2260 buff[0] == 0xEF && buff[1] == 0xBB && buff[2] == 0xBF)
2262 buffer += 3;
2263 size -= 3;
2267 /* if libxml2 detection failed try to guess */
2268 if (encoding == XML_CHAR_ENCODING_NONE)
2270 const WCHAR *ptr = (WCHAR*)buffer;
2271 /* xml declaration with possibly specfied encoding will be still handled by parser */
2272 if ((size >= 2) && *ptr == '<' && ptr[1] != '?')
2274 enc_name = (xmlChar*)xmlGetCharEncodingName(XML_CHAR_ENCODING_UTF16LE);
2275 encoding = XML_CHAR_ENCODING_UTF16LE;
2278 else if (encoding == XML_CHAR_ENCODING_UTF8)
2279 enc_name = (xmlChar*)xmlGetCharEncodingName(encoding);
2280 else
2281 enc_name = NULL;
2283 locator->pParserCtxt = xmlCreateMemoryParserCtxt(buffer, size);
2284 if (!locator->pParserCtxt)
2286 ISAXLocator_Release(&locator->ISAXLocator_iface);
2287 return E_FAIL;
2290 if (enc_name)
2292 locator->pParserCtxt->encoding = xmlStrdup(enc_name);
2293 if (encoding == XML_CHAR_ENCODING_UTF16LE) {
2294 TRACE("switching to %s\n", enc_name);
2295 xmlSwitchEncoding(locator->pParserCtxt, encoding);
2299 xmlFree(locator->pParserCtxt->sax);
2300 locator->pParserCtxt->sax = &locator->saxreader->sax;
2301 locator->pParserCtxt->userData = locator;
2303 This->isParsing = TRUE;
2304 if(xmlParseDocument(locator->pParserCtxt) == -1 && locator->ret == S_OK)
2305 hr = E_FAIL;
2306 else
2307 hr = locator->ret;
2308 This->isParsing = FALSE;
2310 if(locator->pParserCtxt)
2312 locator->pParserCtxt->sax = NULL;
2313 xmlFreeParserCtxt(locator->pParserCtxt);
2314 locator->pParserCtxt = NULL;
2317 ISAXLocator_Release(&locator->ISAXLocator_iface);
2318 return hr;
2321 static HRESULT internal_parseStream(saxreader *This, ISequentialStream *stream, BOOL vbInterface)
2323 saxlocator *locator;
2324 HRESULT hr;
2325 ULONG dataRead;
2326 char data[1024];
2327 int ret;
2329 dataRead = 0;
2330 hr = ISequentialStream_Read(stream, data, sizeof(data), &dataRead);
2331 if(FAILED(hr)) return hr;
2333 hr = SAXLocator_create(This, &locator, vbInterface);
2334 if(FAILED(hr)) return hr;
2336 locator->pParserCtxt = xmlCreatePushParserCtxt(
2337 &locator->saxreader->sax, locator,
2338 data, dataRead, NULL);
2339 if(!locator->pParserCtxt)
2341 ISAXLocator_Release(&locator->ISAXLocator_iface);
2342 return E_FAIL;
2345 This->isParsing = TRUE;
2347 if(dataRead != sizeof(data))
2349 ret = xmlParseChunk(locator->pParserCtxt, data, 0, 1);
2350 hr = ret!=XML_ERR_OK && locator->ret==S_OK ? E_FAIL : locator->ret;
2352 else
2354 while(1)
2356 dataRead = 0;
2357 hr = ISequentialStream_Read(stream, data, sizeof(data), &dataRead);
2358 if (FAILED(hr)) break;
2360 ret = xmlParseChunk(locator->pParserCtxt, data, dataRead, 0);
2361 hr = ret!=XML_ERR_OK && locator->ret==S_OK ? E_FAIL : locator->ret;
2363 if (hr != S_OK) break;
2365 if (dataRead != sizeof(data))
2367 ret = xmlParseChunk(locator->pParserCtxt, data, 0, 1);
2368 hr = ret!=XML_ERR_OK && locator->ret==S_OK ? E_FAIL : locator->ret;
2369 break;
2374 This->isParsing = FALSE;
2376 xmlFreeParserCtxt(locator->pParserCtxt);
2377 locator->pParserCtxt = NULL;
2378 ISAXLocator_Release(&locator->ISAXLocator_iface);
2379 return hr;
2382 static HRESULT internal_parse(
2383 saxreader* This,
2384 VARIANT varInput,
2385 BOOL vbInterface)
2387 HRESULT hr;
2389 TRACE("(%p)->(%s)\n", This, debugstr_variant(&varInput));
2391 /* Dispose of the BSTRs in the pool from a prior run, if any. */
2392 free_bstr_pool(&This->pool);
2394 switch(V_VT(&varInput))
2396 case VT_BSTR:
2397 hr = internal_parseBuffer(This, (const char*)V_BSTR(&varInput),
2398 strlenW(V_BSTR(&varInput))*sizeof(WCHAR), vbInterface);
2399 break;
2400 case VT_ARRAY|VT_UI1: {
2401 void *pSAData;
2402 LONG lBound, uBound;
2403 ULONG dataRead;
2405 hr = SafeArrayGetLBound(V_ARRAY(&varInput), 1, &lBound);
2406 if(hr != S_OK) break;
2407 hr = SafeArrayGetUBound(V_ARRAY(&varInput), 1, &uBound);
2408 if(hr != S_OK) break;
2409 dataRead = (uBound-lBound)*SafeArrayGetElemsize(V_ARRAY(&varInput));
2410 hr = SafeArrayAccessData(V_ARRAY(&varInput), &pSAData);
2411 if(hr != S_OK) break;
2412 hr = internal_parseBuffer(This, pSAData, dataRead, vbInterface);
2413 SafeArrayUnaccessData(V_ARRAY(&varInput));
2414 break;
2416 case VT_UNKNOWN:
2417 case VT_DISPATCH: {
2418 IPersistStream *persistStream;
2419 ISequentialStream *stream = NULL;
2420 IXMLDOMDocument *xmlDoc;
2422 if(IUnknown_QueryInterface(V_UNKNOWN(&varInput),
2423 &IID_IXMLDOMDocument, (void**)&xmlDoc) == S_OK)
2425 BSTR bstrData;
2427 IXMLDOMDocument_get_xml(xmlDoc, &bstrData);
2428 hr = internal_parseBuffer(This, (const char*)bstrData,
2429 SysStringByteLen(bstrData), vbInterface);
2430 IXMLDOMDocument_Release(xmlDoc);
2431 SysFreeString(bstrData);
2432 break;
2435 if(IUnknown_QueryInterface(V_UNKNOWN(&varInput),
2436 &IID_IPersistStream, (void**)&persistStream) == S_OK)
2438 IStream *stream_copy;
2440 hr = CreateStreamOnHGlobal(NULL, TRUE, &stream_copy);
2441 if(hr != S_OK)
2443 IPersistStream_Release(persistStream);
2444 return hr;
2447 hr = IPersistStream_Save(persistStream, stream_copy, TRUE);
2448 IPersistStream_Release(persistStream);
2449 if(hr == S_OK)
2450 IStream_QueryInterface(stream_copy, &IID_ISequentialStream, (void**)&stream);
2452 IStream_Release(stream_copy);
2455 /* try base interface first */
2456 if(!stream)
2458 IUnknown_QueryInterface(V_UNKNOWN(&varInput), &IID_ISequentialStream, (void**)&stream);
2459 if (!stream)
2460 /* this should never happen if IStream is implemented properly, but just in case */
2461 IUnknown_QueryInterface(V_UNKNOWN(&varInput), &IID_IStream, (void**)&stream);
2464 if(stream)
2466 hr = internal_parseStream(This, stream, vbInterface);
2467 ISequentialStream_Release(stream);
2469 else
2471 WARN("IUnknown* input doesn't support any of expected interfaces\n");
2472 hr = E_INVALIDARG;
2475 break;
2477 default:
2478 WARN("vt %d not implemented\n", V_VT(&varInput));
2479 hr = E_INVALIDARG;
2482 return hr;
2485 static HRESULT internal_vbonDataAvailable(void *obj, char *ptr, DWORD len)
2487 saxreader *This = obj;
2489 return internal_parseBuffer(This, ptr, len, TRUE);
2492 static HRESULT internal_onDataAvailable(void *obj, char *ptr, DWORD len)
2494 saxreader *This = obj;
2496 return internal_parseBuffer(This, ptr, len, FALSE);
2499 static HRESULT internal_parseURL(
2500 saxreader* This,
2501 const WCHAR *url,
2502 BOOL vbInterface)
2504 IMoniker *mon;
2505 bsc_t *bsc;
2506 HRESULT hr;
2508 TRACE("(%p)->(%s)\n", This, debugstr_w(url));
2510 hr = create_moniker_from_url(url, &mon);
2511 if(FAILED(hr))
2512 return hr;
2514 if(vbInterface) hr = bind_url(mon, internal_vbonDataAvailable, This, &bsc);
2515 else hr = bind_url(mon, internal_onDataAvailable, This, &bsc);
2516 IMoniker_Release(mon);
2518 if(FAILED(hr))
2519 return hr;
2521 return detach_bsc(bsc);
2524 static HRESULT internal_putProperty(
2525 saxreader* This,
2526 const WCHAR *prop,
2527 VARIANT value,
2528 BOOL vbInterface)
2530 TRACE("(%p)->(%s %s)\n", This, debugstr_w(prop), debugstr_variant(&value));
2532 if(!memcmp(prop, PropertyDeclHandlerW, sizeof(PropertyDeclHandlerW)))
2534 if(This->isParsing) return E_FAIL;
2536 switch (V_VT(&value))
2538 case VT_EMPTY:
2539 saxreader_put_handler(This, SAXDeclHandler, NULL, vbInterface);
2540 break;
2541 case VT_UNKNOWN:
2543 IUnknown *handler = NULL;
2545 if (V_UNKNOWN(&value))
2547 HRESULT hr;
2549 if (vbInterface)
2550 hr = IUnknown_QueryInterface(V_UNKNOWN(&value), &IID_IVBSAXDeclHandler, (void**)&handler);
2551 else
2552 hr = IUnknown_QueryInterface(V_UNKNOWN(&value), &IID_ISAXDeclHandler, (void**)&handler);
2553 if (FAILED(hr)) return hr;
2556 saxreader_put_handler(This, SAXDeclHandler, handler, vbInterface);
2557 if (handler) IUnknown_Release(handler);
2558 break;
2560 default:
2561 return E_INVALIDARG;
2564 return S_OK;
2567 if(!memcmp(prop, PropertyLexicalHandlerW, sizeof(PropertyLexicalHandlerW)))
2569 if(This->isParsing) return E_FAIL;
2571 switch (V_VT(&value))
2573 case VT_EMPTY:
2574 saxreader_put_handler(This, SAXLexicalHandler, NULL, vbInterface);
2575 break;
2576 case VT_UNKNOWN:
2578 IUnknown *handler = NULL;
2580 if (V_UNKNOWN(&value))
2582 HRESULT hr;
2584 if (vbInterface)
2585 hr = IUnknown_QueryInterface(V_UNKNOWN(&value), &IID_IVBSAXLexicalHandler, (void**)&handler);
2586 else
2587 hr = IUnknown_QueryInterface(V_UNKNOWN(&value), &IID_ISAXLexicalHandler, (void**)&handler);
2588 if (FAILED(hr)) return hr;
2591 saxreader_put_handler(This, SAXLexicalHandler, handler, vbInterface);
2592 if (handler) IUnknown_Release(handler);
2593 break;
2595 default:
2596 return E_INVALIDARG;
2599 return S_OK;
2602 if(!memcmp(prop, PropertyMaxXMLSizeW, sizeof(PropertyMaxXMLSizeW)))
2604 if (V_VT(&value) == VT_I4 && V_I4(&value) == 0) return S_OK;
2605 FIXME("(%p)->(%s): max-xml-size unsupported\n", This, debugstr_variant(&value));
2606 return E_NOTIMPL;
2609 if(!memcmp(prop, PropertyMaxElementDepthW, sizeof(PropertyMaxElementDepthW)))
2611 if (V_VT(&value) == VT_I4 && V_I4(&value) == 0) return S_OK;
2612 FIXME("(%p)->(%s): max-element-depth unsupported\n", This, debugstr_variant(&value));
2613 return E_NOTIMPL;
2616 FIXME("(%p)->(%s:%s): unsupported property\n", This, debugstr_w(prop), debugstr_variant(&value));
2618 if(!memcmp(prop, PropertyCharsetW, sizeof(PropertyCharsetW)))
2619 return E_NOTIMPL;
2621 if(!memcmp(prop, PropertyDomNodeW, sizeof(PropertyDomNodeW)))
2622 return E_FAIL;
2624 if(!memcmp(prop, PropertyInputSourceW, sizeof(PropertyInputSourceW)))
2625 return E_NOTIMPL;
2627 if(!memcmp(prop, PropertySchemaDeclHandlerW, sizeof(PropertySchemaDeclHandlerW)))
2628 return E_NOTIMPL;
2630 if(!memcmp(prop, PropertyXMLDeclEncodingW, sizeof(PropertyXMLDeclEncodingW)))
2631 return E_FAIL;
2633 if(!memcmp(prop, PropertyXMLDeclStandaloneW, sizeof(PropertyXMLDeclStandaloneW)))
2634 return E_FAIL;
2636 if(!memcmp(prop, PropertyXMLDeclVersionW, sizeof(PropertyXMLDeclVersionW)))
2637 return E_FAIL;
2639 return E_INVALIDARG;
2642 static HRESULT internal_getProperty(const saxreader* This, const WCHAR *prop, VARIANT *value, BOOL vb)
2644 TRACE("(%p)->(%s)\n", This, debugstr_w(prop));
2646 if (!value) return E_POINTER;
2648 if (!memcmp(PropertyLexicalHandlerW, prop, sizeof(PropertyLexicalHandlerW)))
2650 V_VT(value) = VT_UNKNOWN;
2651 saxreader_get_handler(This, SAXLexicalHandler, vb, (void**)&V_UNKNOWN(value));
2652 return S_OK;
2655 if (!memcmp(PropertyDeclHandlerW, prop, sizeof(PropertyDeclHandlerW)))
2657 V_VT(value) = VT_UNKNOWN;
2658 saxreader_get_handler(This, SAXDeclHandler, vb, (void**)&V_UNKNOWN(value));
2659 return S_OK;
2662 if (!memcmp(PropertyXmlDeclVersionW, prop, sizeof(PropertyXmlDeclVersionW)))
2664 V_VT(value) = VT_BSTR;
2665 V_BSTR(value) = SysAllocString(This->xmldecl_version);
2666 return S_OK;
2669 FIXME("(%p)->(%s) unsupported property\n", This, debugstr_w(prop));
2671 return E_NOTIMPL;
2674 /*** IVBSAXXMLReader interface ***/
2675 /*** IUnknown methods ***/
2676 static HRESULT WINAPI saxxmlreader_QueryInterface(IVBSAXXMLReader* iface, REFIID riid, void **ppvObject)
2678 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2680 TRACE("%p %s %p\n", This, debugstr_guid( riid ), ppvObject );
2682 *ppvObject = NULL;
2684 if ( IsEqualGUID( riid, &IID_IUnknown ) ||
2685 IsEqualGUID( riid, &IID_IDispatch ) ||
2686 IsEqualGUID( riid, &IID_IVBSAXXMLReader ))
2688 *ppvObject = iface;
2690 else if( IsEqualGUID( riid, &IID_ISAXXMLReader ))
2692 *ppvObject = &This->ISAXXMLReader_iface;
2694 else if (dispex_query_interface(&This->dispex, riid, ppvObject))
2696 return *ppvObject ? S_OK : E_NOINTERFACE;
2698 else
2700 FIXME("interface %s not implemented\n", debugstr_guid(riid));
2701 return E_NOINTERFACE;
2704 IVBSAXXMLReader_AddRef( iface );
2706 return S_OK;
2709 static ULONG WINAPI saxxmlreader_AddRef(IVBSAXXMLReader* iface)
2711 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2712 TRACE("%p\n", This );
2713 return InterlockedIncrement( &This->ref );
2716 static ULONG WINAPI saxxmlreader_Release(
2717 IVBSAXXMLReader* iface)
2719 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2720 LONG ref;
2722 TRACE("%p\n", This );
2724 ref = InterlockedDecrement( &This->ref );
2725 if ( ref == 0 )
2727 int i;
2729 for (i = 0; i < SAXHandler_Last; i++)
2731 struct saxanyhandler_iface *iface = &This->saxhandlers[i].u.anyhandler;
2733 if (iface->handler)
2734 IUnknown_Release(iface->handler);
2736 if (iface->vbhandler)
2737 IUnknown_Release(iface->vbhandler);
2740 SysFreeString(This->xmldecl_version);
2741 free_bstr_pool(&This->pool);
2743 release_dispex(&This->dispex);
2744 heap_free( This );
2747 return ref;
2749 /*** IDispatch ***/
2750 static HRESULT WINAPI saxxmlreader_GetTypeInfoCount( IVBSAXXMLReader *iface, UINT* pctinfo )
2752 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2753 return IDispatchEx_GetTypeInfoCount(&This->dispex.IDispatchEx_iface, pctinfo);
2756 static HRESULT WINAPI saxxmlreader_GetTypeInfo(
2757 IVBSAXXMLReader *iface,
2758 UINT iTInfo, LCID lcid, ITypeInfo** ppTInfo )
2760 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2761 return IDispatchEx_GetTypeInfo(&This->dispex.IDispatchEx_iface,
2762 iTInfo, lcid, ppTInfo);
2765 static HRESULT WINAPI saxxmlreader_GetIDsOfNames(
2766 IVBSAXXMLReader *iface,
2767 REFIID riid,
2768 LPOLESTR* rgszNames,
2769 UINT cNames,
2770 LCID lcid,
2771 DISPID* rgDispId)
2773 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2774 return IDispatchEx_GetIDsOfNames(&This->dispex.IDispatchEx_iface,
2775 riid, rgszNames, cNames, lcid, rgDispId);
2778 static HRESULT WINAPI saxxmlreader_Invoke(
2779 IVBSAXXMLReader *iface,
2780 DISPID dispIdMember,
2781 REFIID riid,
2782 LCID lcid,
2783 WORD wFlags,
2784 DISPPARAMS* pDispParams,
2785 VARIANT* pVarResult,
2786 EXCEPINFO* pExcepInfo,
2787 UINT* puArgErr)
2789 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2790 return IDispatchEx_Invoke(&This->dispex.IDispatchEx_iface,
2791 dispIdMember, riid, lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
2794 /*** IVBSAXXMLReader methods ***/
2795 static HRESULT WINAPI saxxmlreader_getFeature(
2796 IVBSAXXMLReader* iface,
2797 const WCHAR *feature_name,
2798 VARIANT_BOOL *value)
2800 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2801 saxreader_feature feature;
2803 TRACE("(%p)->(%s %p)\n", This, debugstr_w(feature_name), value);
2805 feature = get_saxreader_feature(feature_name);
2806 if (feature == Namespaces || feature == NamespacePrefixes)
2807 return get_feature_value(This, feature, value);
2809 FIXME("(%p)->(%s %p) stub\n", This, debugstr_w(feature_name), value);
2810 return E_NOTIMPL;
2813 static HRESULT WINAPI saxxmlreader_putFeature(
2814 IVBSAXXMLReader* iface,
2815 const WCHAR *feature_name,
2816 VARIANT_BOOL value)
2818 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2819 saxreader_feature feature;
2821 TRACE("(%p)->(%s %x)\n", This, debugstr_w(feature_name), value);
2823 feature = get_saxreader_feature(feature_name);
2825 /* accepted cases */
2826 if ((feature == ExternalGeneralEntities && value == VARIANT_FALSE) ||
2827 (feature == ExternalParameterEntities && value == VARIANT_FALSE) ||
2828 feature == Namespaces ||
2829 feature == NamespacePrefixes)
2831 return set_feature_value(This, feature, value);
2834 if (feature == LexicalHandlerParEntities || feature == ProhibitDTD)
2836 FIXME("(%p)->(%s %x) stub\n", This, debugstr_w(feature_name), value);
2837 return set_feature_value(This, feature, value);
2840 FIXME("(%p)->(%s %x) stub\n", This, debugstr_w(feature_name), value);
2841 return E_NOTIMPL;
2844 static HRESULT WINAPI saxxmlreader_getProperty(
2845 IVBSAXXMLReader* iface,
2846 const WCHAR *prop,
2847 VARIANT *value)
2849 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2850 return internal_getProperty(This, prop, value, TRUE);
2853 static HRESULT WINAPI saxxmlreader_putProperty(
2854 IVBSAXXMLReader* iface,
2855 const WCHAR *pProp,
2856 VARIANT value)
2858 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2859 return internal_putProperty(This, pProp, value, TRUE);
2862 static HRESULT WINAPI saxxmlreader_get_entityResolver(
2863 IVBSAXXMLReader* iface,
2864 IVBSAXEntityResolver **resolver)
2866 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2867 return saxreader_get_handler(This, SAXEntityResolver, TRUE, (void**)resolver);
2870 static HRESULT WINAPI saxxmlreader_put_entityResolver(
2871 IVBSAXXMLReader* iface,
2872 IVBSAXEntityResolver *resolver)
2874 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2875 return saxreader_put_handler(This, SAXEntityResolver, resolver, TRUE);
2878 static HRESULT WINAPI saxxmlreader_get_contentHandler(
2879 IVBSAXXMLReader* iface,
2880 IVBSAXContentHandler **handler)
2882 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2883 return saxreader_get_handler(This, SAXContentHandler, TRUE, (void**)handler);
2886 static HRESULT WINAPI saxxmlreader_put_contentHandler(
2887 IVBSAXXMLReader* iface,
2888 IVBSAXContentHandler *handler)
2890 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2891 return saxreader_put_handler(This, SAXContentHandler, handler, TRUE);
2894 static HRESULT WINAPI saxxmlreader_get_dtdHandler(
2895 IVBSAXXMLReader* iface,
2896 IVBSAXDTDHandler **handler)
2898 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2899 return saxreader_get_handler(This, SAXDTDHandler, TRUE, (void**)handler);
2902 static HRESULT WINAPI saxxmlreader_put_dtdHandler(
2903 IVBSAXXMLReader* iface,
2904 IVBSAXDTDHandler *handler)
2906 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2907 return saxreader_put_handler(This, SAXDTDHandler, handler, TRUE);
2910 static HRESULT WINAPI saxxmlreader_get_errorHandler(
2911 IVBSAXXMLReader* iface,
2912 IVBSAXErrorHandler **handler)
2914 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2915 return saxreader_get_handler(This, SAXErrorHandler, TRUE, (void**)handler);
2918 static HRESULT WINAPI saxxmlreader_put_errorHandler(
2919 IVBSAXXMLReader* iface,
2920 IVBSAXErrorHandler *handler)
2922 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2923 return saxreader_put_handler(This, SAXErrorHandler, handler, TRUE);
2926 static HRESULT WINAPI saxxmlreader_get_baseURL(
2927 IVBSAXXMLReader* iface,
2928 const WCHAR **pBaseUrl)
2930 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2932 FIXME("(%p)->(%p) stub\n", This, pBaseUrl);
2933 return E_NOTIMPL;
2936 static HRESULT WINAPI saxxmlreader_put_baseURL(
2937 IVBSAXXMLReader* iface,
2938 const WCHAR *pBaseUrl)
2940 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2942 FIXME("(%p)->(%s) stub\n", This, debugstr_w(pBaseUrl));
2943 return E_NOTIMPL;
2946 static HRESULT WINAPI saxxmlreader_get_secureBaseURL(
2947 IVBSAXXMLReader* iface,
2948 const WCHAR **pSecureBaseUrl)
2950 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2952 FIXME("(%p)->(%p) stub\n", This, pSecureBaseUrl);
2953 return E_NOTIMPL;
2957 static HRESULT WINAPI saxxmlreader_put_secureBaseURL(
2958 IVBSAXXMLReader* iface,
2959 const WCHAR *secureBaseUrl)
2961 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2963 FIXME("(%p)->(%s) stub\n", This, debugstr_w(secureBaseUrl));
2964 return E_NOTIMPL;
2967 static HRESULT WINAPI saxxmlreader_parse(
2968 IVBSAXXMLReader* iface,
2969 VARIANT varInput)
2971 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2972 return internal_parse(This, varInput, TRUE);
2975 static HRESULT WINAPI saxxmlreader_parseURL(
2976 IVBSAXXMLReader* iface,
2977 const WCHAR *url)
2979 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2980 return internal_parseURL(This, url, TRUE);
2983 static const struct IVBSAXXMLReaderVtbl VBSAXXMLReaderVtbl =
2985 saxxmlreader_QueryInterface,
2986 saxxmlreader_AddRef,
2987 saxxmlreader_Release,
2988 saxxmlreader_GetTypeInfoCount,
2989 saxxmlreader_GetTypeInfo,
2990 saxxmlreader_GetIDsOfNames,
2991 saxxmlreader_Invoke,
2992 saxxmlreader_getFeature,
2993 saxxmlreader_putFeature,
2994 saxxmlreader_getProperty,
2995 saxxmlreader_putProperty,
2996 saxxmlreader_get_entityResolver,
2997 saxxmlreader_put_entityResolver,
2998 saxxmlreader_get_contentHandler,
2999 saxxmlreader_put_contentHandler,
3000 saxxmlreader_get_dtdHandler,
3001 saxxmlreader_put_dtdHandler,
3002 saxxmlreader_get_errorHandler,
3003 saxxmlreader_put_errorHandler,
3004 saxxmlreader_get_baseURL,
3005 saxxmlreader_put_baseURL,
3006 saxxmlreader_get_secureBaseURL,
3007 saxxmlreader_put_secureBaseURL,
3008 saxxmlreader_parse,
3009 saxxmlreader_parseURL
3012 /*** ISAXXMLReader interface ***/
3013 /*** IUnknown methods ***/
3014 static HRESULT WINAPI isaxxmlreader_QueryInterface(ISAXXMLReader* iface, REFIID riid, void **ppvObject)
3016 saxreader *This = impl_from_ISAXXMLReader( iface );
3017 return saxxmlreader_QueryInterface(&This->IVBSAXXMLReader_iface, riid, ppvObject);
3020 static ULONG WINAPI isaxxmlreader_AddRef(ISAXXMLReader* iface)
3022 saxreader *This = impl_from_ISAXXMLReader( iface );
3023 return saxxmlreader_AddRef(&This->IVBSAXXMLReader_iface);
3026 static ULONG WINAPI isaxxmlreader_Release(ISAXXMLReader* iface)
3028 saxreader *This = impl_from_ISAXXMLReader( iface );
3029 return saxxmlreader_Release(&This->IVBSAXXMLReader_iface);
3032 /*** ISAXXMLReader methods ***/
3033 static HRESULT WINAPI isaxxmlreader_getFeature(
3034 ISAXXMLReader* iface,
3035 const WCHAR *pFeature,
3036 VARIANT_BOOL *pValue)
3038 saxreader *This = impl_from_ISAXXMLReader( iface );
3039 return IVBSAXXMLReader_getFeature(&This->IVBSAXXMLReader_iface, pFeature, pValue);
3042 static HRESULT WINAPI isaxxmlreader_putFeature(
3043 ISAXXMLReader* iface,
3044 const WCHAR *pFeature,
3045 VARIANT_BOOL vfValue)
3047 saxreader *This = impl_from_ISAXXMLReader( iface );
3048 return IVBSAXXMLReader_putFeature(&This->IVBSAXXMLReader_iface, pFeature, vfValue);
3051 static HRESULT WINAPI isaxxmlreader_getProperty(
3052 ISAXXMLReader* iface,
3053 const WCHAR *prop,
3054 VARIANT *value)
3056 saxreader *This = impl_from_ISAXXMLReader( iface );
3057 return internal_getProperty(This, prop, value, FALSE);
3060 static HRESULT WINAPI isaxxmlreader_putProperty(
3061 ISAXXMLReader* iface,
3062 const WCHAR *pProp,
3063 VARIANT value)
3065 saxreader *This = impl_from_ISAXXMLReader( iface );
3066 return internal_putProperty(This, pProp, value, FALSE);
3069 static HRESULT WINAPI isaxxmlreader_getEntityResolver(
3070 ISAXXMLReader* iface,
3071 ISAXEntityResolver **resolver)
3073 saxreader *This = impl_from_ISAXXMLReader( iface );
3074 return saxreader_get_handler(This, SAXEntityResolver, FALSE, (void**)resolver);
3077 static HRESULT WINAPI isaxxmlreader_putEntityResolver(
3078 ISAXXMLReader* iface,
3079 ISAXEntityResolver *resolver)
3081 saxreader *This = impl_from_ISAXXMLReader( iface );
3082 return saxreader_put_handler(This, SAXEntityResolver, resolver, FALSE);
3085 static HRESULT WINAPI isaxxmlreader_getContentHandler(
3086 ISAXXMLReader* iface,
3087 ISAXContentHandler **handler)
3089 saxreader *This = impl_from_ISAXXMLReader( iface );
3090 return saxreader_get_handler(This, SAXContentHandler, FALSE, (void**)handler);
3093 static HRESULT WINAPI isaxxmlreader_putContentHandler(
3094 ISAXXMLReader* iface,
3095 ISAXContentHandler *handler)
3097 saxreader *This = impl_from_ISAXXMLReader( iface );
3098 return saxreader_put_handler(This, SAXContentHandler, handler, FALSE);
3101 static HRESULT WINAPI isaxxmlreader_getDTDHandler(
3102 ISAXXMLReader* iface,
3103 ISAXDTDHandler **handler)
3105 saxreader *This = impl_from_ISAXXMLReader( iface );
3106 return saxreader_get_handler(This, SAXDTDHandler, FALSE, (void**)handler);
3109 static HRESULT WINAPI isaxxmlreader_putDTDHandler(
3110 ISAXXMLReader* iface,
3111 ISAXDTDHandler *handler)
3113 saxreader *This = impl_from_ISAXXMLReader( iface );
3114 return saxreader_put_handler(This, SAXDTDHandler, handler, FALSE);
3117 static HRESULT WINAPI isaxxmlreader_getErrorHandler(
3118 ISAXXMLReader* iface,
3119 ISAXErrorHandler **handler)
3121 saxreader *This = impl_from_ISAXXMLReader( iface );
3122 return saxreader_get_handler(This, SAXErrorHandler, FALSE, (void**)handler);
3125 static HRESULT WINAPI isaxxmlreader_putErrorHandler(ISAXXMLReader* iface, ISAXErrorHandler *handler)
3127 saxreader *This = impl_from_ISAXXMLReader( iface );
3128 return saxreader_put_handler(This, SAXErrorHandler, handler, FALSE);
3131 static HRESULT WINAPI isaxxmlreader_getBaseURL(
3132 ISAXXMLReader* iface,
3133 const WCHAR **pBaseUrl)
3135 saxreader *This = impl_from_ISAXXMLReader( iface );
3136 return IVBSAXXMLReader_get_baseURL(&This->IVBSAXXMLReader_iface, pBaseUrl);
3139 static HRESULT WINAPI isaxxmlreader_putBaseURL(
3140 ISAXXMLReader* iface,
3141 const WCHAR *pBaseUrl)
3143 saxreader *This = impl_from_ISAXXMLReader( iface );
3144 return IVBSAXXMLReader_put_baseURL(&This->IVBSAXXMLReader_iface, pBaseUrl);
3147 static HRESULT WINAPI isaxxmlreader_getSecureBaseURL(
3148 ISAXXMLReader* iface,
3149 const WCHAR **pSecureBaseUrl)
3151 saxreader *This = impl_from_ISAXXMLReader( iface );
3152 return IVBSAXXMLReader_get_secureBaseURL(&This->IVBSAXXMLReader_iface, pSecureBaseUrl);
3155 static HRESULT WINAPI isaxxmlreader_putSecureBaseURL(
3156 ISAXXMLReader* iface,
3157 const WCHAR *secureBaseUrl)
3159 saxreader *This = impl_from_ISAXXMLReader( iface );
3160 return IVBSAXXMLReader_put_secureBaseURL(&This->IVBSAXXMLReader_iface, secureBaseUrl);
3163 static HRESULT WINAPI isaxxmlreader_parse(
3164 ISAXXMLReader* iface,
3165 VARIANT varInput)
3167 saxreader *This = impl_from_ISAXXMLReader( iface );
3168 return internal_parse(This, varInput, FALSE);
3171 static HRESULT WINAPI isaxxmlreader_parseURL(
3172 ISAXXMLReader* iface,
3173 const WCHAR *url)
3175 saxreader *This = impl_from_ISAXXMLReader( iface );
3176 return internal_parseURL(This, url, FALSE);
3179 static const struct ISAXXMLReaderVtbl SAXXMLReaderVtbl =
3181 isaxxmlreader_QueryInterface,
3182 isaxxmlreader_AddRef,
3183 isaxxmlreader_Release,
3184 isaxxmlreader_getFeature,
3185 isaxxmlreader_putFeature,
3186 isaxxmlreader_getProperty,
3187 isaxxmlreader_putProperty,
3188 isaxxmlreader_getEntityResolver,
3189 isaxxmlreader_putEntityResolver,
3190 isaxxmlreader_getContentHandler,
3191 isaxxmlreader_putContentHandler,
3192 isaxxmlreader_getDTDHandler,
3193 isaxxmlreader_putDTDHandler,
3194 isaxxmlreader_getErrorHandler,
3195 isaxxmlreader_putErrorHandler,
3196 isaxxmlreader_getBaseURL,
3197 isaxxmlreader_putBaseURL,
3198 isaxxmlreader_getSecureBaseURL,
3199 isaxxmlreader_putSecureBaseURL,
3200 isaxxmlreader_parse,
3201 isaxxmlreader_parseURL
3204 static const tid_t saxreader_iface_tids[] = {
3205 IVBSAXXMLReader_tid,
3208 static dispex_static_data_t saxreader_dispex = {
3209 NULL,
3210 IVBSAXXMLReader_tid,
3211 NULL,
3212 saxreader_iface_tids
3215 HRESULT SAXXMLReader_create(MSXML_VERSION version, IUnknown *outer, LPVOID *ppObj)
3217 saxreader *reader;
3219 TRACE("(%p, %p)\n", outer, ppObj);
3221 reader = heap_alloc( sizeof (*reader) );
3222 if( !reader )
3223 return E_OUTOFMEMORY;
3225 reader->IVBSAXXMLReader_iface.lpVtbl = &VBSAXXMLReaderVtbl;
3226 reader->ISAXXMLReader_iface.lpVtbl = &SAXXMLReaderVtbl;
3227 reader->ref = 1;
3228 memset(reader->saxhandlers, 0, sizeof(reader->saxhandlers));
3229 reader->isParsing = FALSE;
3230 reader->xmldecl_version = NULL;
3231 reader->pool.pool = NULL;
3232 reader->pool.index = 0;
3233 reader->pool.len = 0;
3234 reader->features = Namespaces | NamespacePrefixes;
3235 reader->version = version;
3237 init_dispex(&reader->dispex, (IUnknown*)&reader->IVBSAXXMLReader_iface, &saxreader_dispex);
3239 memset(&reader->sax, 0, sizeof(xmlSAXHandler));
3240 reader->sax.initialized = XML_SAX2_MAGIC;
3241 reader->sax.startDocument = libxmlStartDocument;
3242 reader->sax.endDocument = libxmlEndDocument;
3243 reader->sax.startElementNs = libxmlStartElementNS;
3244 reader->sax.endElementNs = libxmlEndElementNS;
3245 reader->sax.characters = libxmlCharacters;
3246 reader->sax.setDocumentLocator = libxmlSetDocumentLocator;
3247 reader->sax.comment = libxmlComment;
3248 reader->sax.error = libxmlFatalError;
3249 reader->sax.fatalError = libxmlFatalError;
3250 reader->sax.cdataBlock = libxmlCDataBlock;
3251 reader->sax.resolveEntity = libxmlresolveentity;
3253 *ppObj = &reader->IVBSAXXMLReader_iface;
3255 TRACE("returning iface %p\n", *ppObj);
3257 return S_OK;
3260 #else
3262 HRESULT SAXXMLReader_create(MSXML_VERSION version, IUnknown *pUnkOuter, LPVOID *ppObj)
3264 MESSAGE("This program tried to use a SAX XML Reader object, but\n"
3265 "libxml2 support was not present at compile time.\n");
3266 return E_NOTIMPL;
3269 #endif