mshtml: Fixed Exec_ShellDocView_84 tests.
[wine/multimedia.git] / dlls / msxml3 / saxreader.c
blobb3b6fc4f992b9f8328a4200cde6031c77fff9274
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 typedef struct
168 DispatchEx dispex;
169 IVBSAXXMLReader IVBSAXXMLReader_iface;
170 ISAXXMLReader ISAXXMLReader_iface;
171 LONG ref;
172 ISAXContentHandler *contentHandler;
173 IVBSAXContentHandler *vbcontentHandler;
174 ISAXErrorHandler *errorHandler;
175 IVBSAXErrorHandler *vberrorHandler;
176 ISAXLexicalHandler *lexicalHandler;
177 IVBSAXLexicalHandler *vblexicalHandler;
178 ISAXDeclHandler *declHandler;
179 IVBSAXDeclHandler *vbdeclHandler;
180 xmlSAXHandler sax;
181 BOOL isParsing;
182 struct bstrpool pool;
183 saxreader_feature features;
184 MSXML_VERSION version;
185 } saxreader;
187 typedef struct
189 IVBSAXLocator IVBSAXLocator_iface;
190 ISAXLocator ISAXLocator_iface;
191 IVBSAXAttributes IVBSAXAttributes_iface;
192 ISAXAttributes ISAXAttributes_iface;
193 LONG ref;
194 saxreader *saxreader;
195 HRESULT ret;
196 xmlParserCtxtPtr pParserCtxt;
197 WCHAR *publicId;
198 WCHAR *systemId;
199 int line;
200 int column;
201 BOOL vbInterface;
202 struct list elements;
204 BSTR namespaceUri;
205 int attributesSize;
206 int nb_attributes;
207 struct _attributes
209 BSTR szLocalname;
210 BSTR szURI;
211 BSTR szValue;
212 BSTR szQName;
213 } *attributes;
214 } saxlocator;
216 static inline saxreader *impl_from_IVBSAXXMLReader( IVBSAXXMLReader *iface )
218 return CONTAINING_RECORD(iface, saxreader, IVBSAXXMLReader_iface);
221 static inline saxreader *impl_from_ISAXXMLReader( ISAXXMLReader *iface )
223 return CONTAINING_RECORD(iface, saxreader, ISAXXMLReader_iface);
226 static inline saxlocator *impl_from_IVBSAXLocator( IVBSAXLocator *iface )
228 return CONTAINING_RECORD(iface, saxlocator, IVBSAXLocator_iface);
231 static inline saxlocator *impl_from_ISAXLocator( ISAXLocator *iface )
233 return CONTAINING_RECORD(iface, saxlocator, ISAXLocator_iface);
236 static inline saxlocator *impl_from_IVBSAXAttributes( IVBSAXAttributes *iface )
238 return CONTAINING_RECORD(iface, saxlocator, IVBSAXAttributes_iface);
241 static inline saxlocator *impl_from_ISAXAttributes( ISAXAttributes *iface )
243 return CONTAINING_RECORD(iface, saxlocator, ISAXAttributes_iface);
246 /* property names */
247 static const WCHAR PropertyCharsetW[] = {
248 'c','h','a','r','s','e','t',0
250 static const WCHAR PropertyDeclHandlerW[] = {
251 'h','t','t','p',':','/','/','x','m','l','.','o','r','g','/',
252 's','a','x','/','p','r','o','p','e','r','t','i','e','s','/',
253 'd','e','c','l','a','r','a','t','i','o','n',
254 '-','h','a','n','d','l','e','r',0
256 static const WCHAR PropertyDomNodeW[] = {
257 'h','t','t','p',':','/','/','x','m','l','.','o','r','g','/',
258 's','a','x','/','p','r','o','p','e','r','t','i','e','s','/',
259 'd','o','m','-','n','o','d','e',0
261 static const WCHAR PropertyInputSourceW[] = {
262 'i','n','p','u','t','-','s','o','u','r','c','e',0
264 static const WCHAR PropertyLexicalHandlerW[] = {
265 'h','t','t','p',':','/','/','x','m','l','.','o','r','g','/',
266 's','a','x','/','p','r','o','p','e','r','t','i','e','s','/',
267 'l','e','x','i','c','a','l','-','h','a','n','d','l','e','r',0
269 static const WCHAR PropertyMaxElementDepthW[] = {
270 'm','a','x','-','e','l','e','m','e','n','t','-','d','e','p','t','h',0
272 static const WCHAR PropertyMaxXMLSizeW[] = {
273 'm','a','x','-','x','m','l','-','s','i','z','e',0
275 static const WCHAR PropertySchemaDeclHandlerW[] = {
276 's','c','h','e','m','a','-','d','e','c','l','a','r','a','t','i','o','n','-',
277 'h','a','n','d','l','e','r',0
279 static const WCHAR PropertyXMLDeclEncodingW[] = {
280 'x','m','l','d','e','c','l','-','e','n','c','o','d','i','n','g',0
282 static const WCHAR PropertyXMLDeclStandaloneW[] = {
283 'x','m','l','d','e','c','l','-','s','t','a','n','d','a','l','o','n','e',0
285 static const WCHAR PropertyXMLDeclVersionW[] = {
286 'x','m','l','d','e','c','l','-','v','e','r','s','i','o','n',0
289 static inline HRESULT set_feature_value(saxreader *reader, saxreader_feature feature, VARIANT_BOOL value)
291 /* handling of non-VARIANT_* values is version dependent */
292 if ((reader->version < MSXML4) && (value != VARIANT_TRUE))
293 value = VARIANT_FALSE;
294 if ((reader->version >= MSXML4) && (value != VARIANT_FALSE))
295 value = VARIANT_TRUE;
297 if (value == VARIANT_TRUE)
298 reader->features |= feature;
299 else
300 reader->features &= ~feature;
302 return S_OK;
305 static inline HRESULT get_feature_value(const saxreader *reader, saxreader_feature feature, VARIANT_BOOL *value)
307 *value = reader->features & feature ? VARIANT_TRUE : VARIANT_FALSE;
308 return S_OK;
311 static BOOL is_namespaces_enabled(const saxreader *reader)
313 return (reader->version < MSXML4) || (reader->features & Namespaces);
316 static inline int has_content_handler(const saxlocator *locator)
318 return (locator->vbInterface && locator->saxreader->vbcontentHandler) ||
319 (!locator->vbInterface && locator->saxreader->contentHandler);
322 static inline int has_lexical_handler(const saxlocator *locator)
324 return (locator->vbInterface && locator->saxreader->vblexicalHandler) ||
325 (!locator->vbInterface && locator->saxreader->lexicalHandler);
328 static inline int has_error_handler(const saxlocator *locator)
330 return (locator->vbInterface && locator->saxreader->vberrorHandler) ||
331 (!locator->vbInterface && locator->saxreader->errorHandler);
334 static BSTR build_qname(BSTR prefix, BSTR local)
336 if (prefix && *prefix)
338 BSTR qname = SysAllocStringLen(NULL, SysStringLen(prefix) + SysStringLen(local) + 1);
339 WCHAR *ptr;
341 ptr = qname;
342 strcpyW(ptr, prefix);
343 ptr += SysStringLen(prefix);
344 *ptr++ = ':';
345 strcpyW(ptr, local);
346 return qname;
348 else
349 return SysAllocString(local);
352 static element_entry* alloc_element_entry(const xmlChar *local, const xmlChar *prefix, int nb_ns,
353 const xmlChar **namespaces)
355 element_entry *ret;
356 int i;
358 ret = heap_alloc(sizeof(*ret));
359 if (!ret) return ret;
361 ret->local = bstr_from_xmlChar(local);
362 ret->prefix = bstr_from_xmlChar(prefix);
363 ret->qname = build_qname(ret->prefix, ret->local);
364 ret->ns = nb_ns ? heap_alloc(nb_ns*sizeof(ns)) : NULL;
365 ret->ns_count = nb_ns;
367 for (i=0; i < nb_ns; i++)
369 ret->ns[i].prefix = bstr_from_xmlChar(namespaces[2*i]);
370 ret->ns[i].uri = bstr_from_xmlChar(namespaces[2*i+1]);
373 return ret;
376 static void free_element_entry(element_entry *element)
378 int i;
380 for (i=0; i<element->ns_count;i++)
382 SysFreeString(element->ns[i].prefix);
383 SysFreeString(element->ns[i].uri);
386 SysFreeString(element->prefix);
387 SysFreeString(element->local);
389 heap_free(element->ns);
390 heap_free(element);
393 static void push_element_ns(saxlocator *locator, element_entry *element)
395 list_add_head(&locator->elements, &element->entry);
398 static element_entry * pop_element_ns(saxlocator *locator)
400 element_entry *element = LIST_ENTRY(list_head(&locator->elements), element_entry, entry);
402 if (element)
403 list_remove(&element->entry);
405 return element;
408 static BSTR find_element_uri(saxlocator *locator, const xmlChar *uri)
410 element_entry *element;
411 BSTR uriW;
412 int i;
414 if (!uri) return NULL;
416 uriW = bstr_from_xmlChar(uri);
418 LIST_FOR_EACH_ENTRY(element, &locator->elements, element_entry, entry)
420 for (i=0; i < element->ns_count; i++)
421 if (!strcmpW(uriW, element->ns[i].uri))
423 SysFreeString(uriW);
424 return element->ns[i].uri;
428 SysFreeString(uriW);
429 ERR("namespace uri not found, %s\n", debugstr_a((char*)uri));
430 return NULL;
433 /* used to localize version dependent error check behaviour */
434 static inline BOOL sax_callback_failed(saxlocator *This, HRESULT hr)
436 return This->saxreader->version >= MSXML4 ? FAILED(hr) : hr != S_OK;
439 /* index value -1 means it tries to loop for a first time */
440 static inline BOOL iterate_endprefix_index(saxlocator *This, const element_entry *element, int *i)
442 if (This->saxreader->version >= MSXML4)
444 if (*i == -1) *i = 0; else ++*i;
445 return *i < element->ns_count;
447 else
449 if (*i == -1) *i = element->ns_count-1; else --*i;
450 return *i >= 0;
454 static BOOL bstr_pool_insert(struct bstrpool *pool, BSTR pool_entry)
456 if (!pool->pool)
458 pool->pool = HeapAlloc(GetProcessHeap(), 0, 16 * sizeof(*pool->pool));
459 if (!pool->pool)
460 return FALSE;
462 pool->index = 0;
463 pool->len = 16;
465 else if (pool->index == pool->len)
467 BSTR *realloc = HeapReAlloc(GetProcessHeap(), 0, pool->pool, pool->len * 2 * sizeof(*realloc));
469 if (!realloc)
470 return FALSE;
472 pool->pool = realloc;
473 pool->len *= 2;
476 pool->pool[pool->index++] = pool_entry;
477 return TRUE;
480 static void free_bstr_pool(struct bstrpool *pool)
482 unsigned int i;
484 for (i = 0; i < pool->index; i++)
485 SysFreeString(pool->pool[i]);
487 HeapFree(GetProcessHeap(), 0, pool->pool);
489 pool->pool = NULL;
490 pool->index = pool->len = 0;
493 static BSTR bstr_from_xmlCharN(const xmlChar *buf, int len)
495 DWORD dLen;
496 BSTR bstr;
498 if (!buf)
499 return NULL;
501 dLen = MultiByteToWideChar(CP_UTF8, 0, (LPCSTR)buf, len, NULL, 0);
502 if(len != -1) dLen++;
503 bstr = SysAllocStringLen(NULL, dLen-1);
504 if (!bstr)
505 return NULL;
506 MultiByteToWideChar(CP_UTF8, 0, (LPCSTR)buf, len, bstr, dLen);
507 if(len != -1) bstr[dLen-1] = '\0';
509 return bstr;
512 static BSTR QName_from_xmlChar(const xmlChar *prefix, const xmlChar *name)
514 xmlChar *qname;
515 BSTR bstr;
517 if(!name) return NULL;
519 if(!prefix || !*prefix)
520 return bstr_from_xmlChar(name);
522 qname = xmlBuildQName(name, prefix, NULL, 0);
523 bstr = bstr_from_xmlChar(qname);
524 xmlFree(qname);
526 return bstr;
529 static BSTR pooled_bstr_from_xmlChar(struct bstrpool *pool, const xmlChar *buf)
531 BSTR pool_entry = bstr_from_xmlChar(buf);
533 if (pool_entry && !bstr_pool_insert(pool, pool_entry))
535 SysFreeString(pool_entry);
536 return NULL;
539 return pool_entry;
542 static BSTR pooled_bstr_from_xmlCharN(struct bstrpool *pool, const xmlChar *buf, int len)
544 BSTR pool_entry = bstr_from_xmlCharN(buf, len);
546 if (pool_entry && !bstr_pool_insert(pool, pool_entry))
548 SysFreeString(pool_entry);
549 return NULL;
552 return pool_entry;
555 static void format_error_message_from_id(saxlocator *This, HRESULT hr)
557 xmlStopParser(This->pParserCtxt);
558 This->ret = hr;
560 if(has_error_handler(This))
562 WCHAR msg[1024];
563 if(!FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM,
564 NULL, hr, 0, msg, sizeof(msg), NULL))
566 FIXME("MSXML errors not yet supported.\n");
567 msg[0] = '\0';
570 if(This->vbInterface)
572 BSTR bstrMsg = SysAllocString(msg);
573 IVBSAXErrorHandler_fatalError(This->saxreader->vberrorHandler,
574 &This->IVBSAXLocator_iface, &bstrMsg, hr);
575 SysFreeString(bstrMsg);
577 else
578 ISAXErrorHandler_fatalError(This->saxreader->errorHandler,
579 &This->ISAXLocator_iface, msg, hr);
583 static void update_position(saxlocator *This, BOOL fix_column)
585 const xmlChar *p = This->pParserCtxt->input->cur-1;
587 This->line = xmlSAX2GetLineNumber(This->pParserCtxt);
588 if(fix_column)
590 This->column = 1;
591 for(; *p!='\n' && *p!='\r' && p>=This->pParserCtxt->input->base; p--)
592 This->column++;
594 else
596 This->column = xmlSAX2GetColumnNumber(This->pParserCtxt);
600 /*** IVBSAXAttributes interface ***/
601 /*** IUnknown methods ***/
602 static HRESULT WINAPI ivbsaxattributes_QueryInterface(
603 IVBSAXAttributes* iface,
604 REFIID riid,
605 void **ppvObject)
607 saxlocator *This = impl_from_IVBSAXAttributes(iface);
608 TRACE("%p %s %p\n", This, debugstr_guid(riid), ppvObject);
609 return IVBSAXLocator_QueryInterface(&This->IVBSAXLocator_iface, riid, ppvObject);
612 static ULONG WINAPI ivbsaxattributes_AddRef(IVBSAXAttributes* iface)
614 saxlocator *This = impl_from_IVBSAXAttributes(iface);
615 return ISAXLocator_AddRef(&This->ISAXLocator_iface);
618 static ULONG WINAPI ivbsaxattributes_Release(IVBSAXAttributes* iface)
620 saxlocator *This = impl_from_IVBSAXAttributes(iface);
621 return ISAXLocator_Release(&This->ISAXLocator_iface);
624 /*** IDispatch methods ***/
625 static HRESULT WINAPI ivbsaxattributes_GetTypeInfoCount( IVBSAXAttributes *iface, UINT* pctinfo )
627 saxlocator *This = impl_from_IVBSAXAttributes( iface );
629 TRACE("(%p)->(%p)\n", This, pctinfo);
631 *pctinfo = 1;
633 return S_OK;
636 static HRESULT WINAPI ivbsaxattributes_GetTypeInfo(
637 IVBSAXAttributes *iface,
638 UINT iTInfo, LCID lcid, ITypeInfo** ppTInfo )
640 saxlocator *This = impl_from_IVBSAXAttributes( iface );
641 HRESULT hr;
643 TRACE("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo);
645 hr = get_typeinfo(IVBSAXAttributes_tid, ppTInfo);
647 return hr;
650 static HRESULT WINAPI ivbsaxattributes_GetIDsOfNames(
651 IVBSAXAttributes *iface,
652 REFIID riid,
653 LPOLESTR* rgszNames,
654 UINT cNames,
655 LCID lcid,
656 DISPID* rgDispId)
658 saxlocator *This = impl_from_IVBSAXAttributes( iface );
659 ITypeInfo *typeinfo;
660 HRESULT hr;
662 TRACE("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames, cNames,
663 lcid, rgDispId);
665 if(!rgszNames || cNames == 0 || !rgDispId)
666 return E_INVALIDARG;
668 hr = get_typeinfo(IVBSAXAttributes_tid, &typeinfo);
669 if(SUCCEEDED(hr))
671 hr = ITypeInfo_GetIDsOfNames(typeinfo, rgszNames, cNames, rgDispId);
672 ITypeInfo_Release(typeinfo);
675 return hr;
678 static HRESULT WINAPI ivbsaxattributes_Invoke(
679 IVBSAXAttributes *iface,
680 DISPID dispIdMember,
681 REFIID riid,
682 LCID lcid,
683 WORD wFlags,
684 DISPPARAMS* pDispParams,
685 VARIANT* pVarResult,
686 EXCEPINFO* pExcepInfo,
687 UINT* puArgErr)
689 saxlocator *This = impl_from_IVBSAXAttributes( iface );
690 ITypeInfo *typeinfo;
691 HRESULT hr;
693 TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
694 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
696 hr = get_typeinfo(IVBSAXAttributes_tid, &typeinfo);
697 if(SUCCEEDED(hr))
699 hr = ITypeInfo_Invoke(typeinfo, &This->IVBSAXAttributes_iface, dispIdMember, wFlags,
700 pDispParams, pVarResult, pExcepInfo, puArgErr);
701 ITypeInfo_Release(typeinfo);
704 return hr;
707 /*** IVBSAXAttributes methods ***/
708 static HRESULT WINAPI ivbsaxattributes_get_length(
709 IVBSAXAttributes* iface,
710 int *nLength)
712 saxlocator *This = impl_from_IVBSAXAttributes( iface );
713 return ISAXAttributes_getLength(&This->ISAXAttributes_iface, nLength);
716 static HRESULT WINAPI ivbsaxattributes_getURI(
717 IVBSAXAttributes* iface,
718 int nIndex,
719 BSTR *uri)
721 int len;
722 saxlocator *This = impl_from_IVBSAXAttributes( iface );
723 return ISAXAttributes_getURI(&This->ISAXAttributes_iface, nIndex, (const WCHAR**)uri, &len);
726 static HRESULT WINAPI ivbsaxattributes_getLocalName(
727 IVBSAXAttributes* iface,
728 int nIndex,
729 BSTR *localName)
731 int len;
732 saxlocator *This = impl_from_IVBSAXAttributes( iface );
733 return ISAXAttributes_getLocalName(&This->ISAXAttributes_iface, nIndex,
734 (const WCHAR**)localName, &len);
737 static HRESULT WINAPI ivbsaxattributes_getQName(
738 IVBSAXAttributes* iface,
739 int nIndex,
740 BSTR *QName)
742 int len;
743 saxlocator *This = impl_from_IVBSAXAttributes( iface );
744 return ISAXAttributes_getQName(&This->ISAXAttributes_iface, nIndex, (const WCHAR**)QName, &len);
747 static HRESULT WINAPI ivbsaxattributes_getIndexFromName(
748 IVBSAXAttributes* iface,
749 BSTR uri,
750 BSTR localName,
751 int *index)
753 saxlocator *This = impl_from_IVBSAXAttributes( iface );
754 return ISAXAttributes_getIndexFromName(&This->ISAXAttributes_iface, uri, SysStringLen(uri),
755 localName, SysStringLen(localName), index);
758 static HRESULT WINAPI ivbsaxattributes_getIndexFromQName(
759 IVBSAXAttributes* iface,
760 BSTR QName,
761 int *index)
763 saxlocator *This = impl_from_IVBSAXAttributes( iface );
764 return ISAXAttributes_getIndexFromQName(&This->ISAXAttributes_iface, QName,
765 SysStringLen(QName), index);
768 static HRESULT WINAPI ivbsaxattributes_getType(
769 IVBSAXAttributes* iface,
770 int nIndex,
771 BSTR *type)
773 int len;
774 saxlocator *This = impl_from_IVBSAXAttributes( iface );
775 return ISAXAttributes_getType(&This->ISAXAttributes_iface, nIndex, (const WCHAR**)type, &len);
778 static HRESULT WINAPI ivbsaxattributes_getTypeFromName(
779 IVBSAXAttributes* iface,
780 BSTR uri,
781 BSTR localName,
782 BSTR *type)
784 int len;
785 saxlocator *This = impl_from_IVBSAXAttributes( iface );
786 return ISAXAttributes_getTypeFromName(&This->ISAXAttributes_iface, uri, SysStringLen(uri),
787 localName, SysStringLen(localName), (const WCHAR**)type, &len);
790 static HRESULT WINAPI ivbsaxattributes_getTypeFromQName(
791 IVBSAXAttributes* iface,
792 BSTR QName,
793 BSTR *type)
795 int len;
796 saxlocator *This = impl_from_IVBSAXAttributes( iface );
797 return ISAXAttributes_getTypeFromQName(&This->ISAXAttributes_iface, QName, SysStringLen(QName),
798 (const WCHAR**)type, &len);
801 static HRESULT WINAPI ivbsaxattributes_getValue(
802 IVBSAXAttributes* iface,
803 int nIndex,
804 BSTR *value)
806 int len;
807 saxlocator *This = impl_from_IVBSAXAttributes( iface );
808 return ISAXAttributes_getValue(&This->ISAXAttributes_iface, nIndex, (const WCHAR**)value, &len);
811 static HRESULT WINAPI ivbsaxattributes_getValueFromName(
812 IVBSAXAttributes* iface,
813 BSTR uri,
814 BSTR localName,
815 BSTR *value)
817 int len;
818 saxlocator *This = impl_from_IVBSAXAttributes( iface );
819 return ISAXAttributes_getValueFromName(&This->ISAXAttributes_iface, uri, SysStringLen(uri),
820 localName, SysStringLen(localName), (const WCHAR**)value, &len);
823 static HRESULT WINAPI ivbsaxattributes_getValueFromQName(
824 IVBSAXAttributes* iface,
825 BSTR QName,
826 BSTR *value)
828 int len;
829 saxlocator *This = impl_from_IVBSAXAttributes( iface );
830 return ISAXAttributes_getValueFromQName(&This->ISAXAttributes_iface, QName,
831 SysStringLen(QName), (const WCHAR**)value, &len);
834 static const struct IVBSAXAttributesVtbl ivbsaxattributes_vtbl =
836 ivbsaxattributes_QueryInterface,
837 ivbsaxattributes_AddRef,
838 ivbsaxattributes_Release,
839 ivbsaxattributes_GetTypeInfoCount,
840 ivbsaxattributes_GetTypeInfo,
841 ivbsaxattributes_GetIDsOfNames,
842 ivbsaxattributes_Invoke,
843 ivbsaxattributes_get_length,
844 ivbsaxattributes_getURI,
845 ivbsaxattributes_getLocalName,
846 ivbsaxattributes_getQName,
847 ivbsaxattributes_getIndexFromName,
848 ivbsaxattributes_getIndexFromQName,
849 ivbsaxattributes_getType,
850 ivbsaxattributes_getTypeFromName,
851 ivbsaxattributes_getTypeFromQName,
852 ivbsaxattributes_getValue,
853 ivbsaxattributes_getValueFromName,
854 ivbsaxattributes_getValueFromQName
857 /*** ISAXAttributes interface ***/
858 /*** IUnknown methods ***/
859 static HRESULT WINAPI isaxattributes_QueryInterface(
860 ISAXAttributes* iface,
861 REFIID riid,
862 void **ppvObject)
864 saxlocator *This = impl_from_ISAXAttributes(iface);
865 TRACE("%p %s %p\n", This, debugstr_guid(riid), ppvObject);
866 return ISAXLocator_QueryInterface(&This->ISAXLocator_iface, riid, ppvObject);
869 static ULONG WINAPI isaxattributes_AddRef(ISAXAttributes* iface)
871 saxlocator *This = impl_from_ISAXAttributes(iface);
872 TRACE("%p\n", This);
873 return ISAXLocator_AddRef(&This->ISAXLocator_iface);
876 static ULONG WINAPI isaxattributes_Release(ISAXAttributes* iface)
878 saxlocator *This = impl_from_ISAXAttributes(iface);
880 TRACE("%p\n", This);
881 return ISAXLocator_Release(&This->ISAXLocator_iface);
884 /*** ISAXAttributes methods ***/
885 static HRESULT WINAPI isaxattributes_getLength(
886 ISAXAttributes* iface,
887 int *length)
889 saxlocator *This = impl_from_ISAXAttributes( iface );
891 *length = This->nb_attributes;
892 TRACE("Length set to %d\n", *length);
893 return S_OK;
896 static HRESULT WINAPI isaxattributes_getURI(
897 ISAXAttributes* iface,
898 int index,
899 const WCHAR **url,
900 int *size)
902 saxlocator *This = impl_from_ISAXAttributes( iface );
903 TRACE("(%p)->(%d)\n", This, index);
905 if(index >= This->nb_attributes || index < 0) return E_INVALIDARG;
906 if(!url || !size) return E_POINTER;
908 *size = SysStringLen(This->attributes[index].szURI);
909 *url = This->attributes[index].szURI;
911 TRACE("(%s:%d)\n", debugstr_w(This->attributes[index].szURI), *size);
913 return S_OK;
916 static HRESULT WINAPI isaxattributes_getLocalName(
917 ISAXAttributes* iface,
918 int nIndex,
919 const WCHAR **pLocalName,
920 int *pLocalNameLength)
922 saxlocator *This = impl_from_ISAXAttributes( iface );
923 TRACE("(%p)->(%d)\n", This, nIndex);
925 if(nIndex>=This->nb_attributes || nIndex<0) return E_INVALIDARG;
926 if(!pLocalName || !pLocalNameLength) return E_POINTER;
928 *pLocalNameLength = SysStringLen(This->attributes[nIndex].szLocalname);
929 *pLocalName = This->attributes[nIndex].szLocalname;
931 return S_OK;
934 static HRESULT WINAPI isaxattributes_getQName(
935 ISAXAttributes* iface,
936 int nIndex,
937 const WCHAR **pQName,
938 int *pQNameLength)
940 saxlocator *This = impl_from_ISAXAttributes( iface );
941 TRACE("(%p)->(%d)\n", This, nIndex);
943 if(nIndex>=This->nb_attributes || nIndex<0) return E_INVALIDARG;
944 if(!pQName || !pQNameLength) return E_POINTER;
946 *pQNameLength = SysStringLen(This->attributes[nIndex].szQName);
947 *pQName = This->attributes[nIndex].szQName;
949 return S_OK;
952 static HRESULT WINAPI isaxattributes_getName(
953 ISAXAttributes* iface,
954 int index,
955 const WCHAR **uri,
956 int *pUriLength,
957 const WCHAR **localName,
958 int *pLocalNameSize,
959 const WCHAR **QName,
960 int *pQNameLength)
962 saxlocator *This = impl_from_ISAXAttributes( iface );
963 TRACE("(%p)->(%d)\n", This, index);
965 if(index>=This->nb_attributes || index<0) return E_INVALIDARG;
966 if(!uri || !pUriLength || !localName || !pLocalNameSize
967 || !QName || !pQNameLength) return E_POINTER;
969 *pUriLength = SysStringLen(This->attributes[index].szURI);
970 *uri = This->attributes[index].szURI;
971 *pLocalNameSize = SysStringLen(This->attributes[index].szLocalname);
972 *localName = This->attributes[index].szLocalname;
973 *pQNameLength = SysStringLen(This->attributes[index].szQName);
974 *QName = This->attributes[index].szQName;
976 TRACE("(%s, %s, %s)\n", debugstr_w(*uri), debugstr_w(*localName), debugstr_w(*QName));
978 return S_OK;
981 static HRESULT WINAPI isaxattributes_getIndexFromName(
982 ISAXAttributes* iface,
983 const WCHAR *pUri,
984 int cUriLength,
985 const WCHAR *pLocalName,
986 int cocalNameLength,
987 int *index)
989 saxlocator *This = impl_from_ISAXAttributes( iface );
990 int i;
991 TRACE("(%p)->(%s, %d, %s, %d)\n", This, debugstr_w(pUri), cUriLength,
992 debugstr_w(pLocalName), cocalNameLength);
994 if(!pUri || !pLocalName || !index) return E_POINTER;
996 for(i=0; i<This->nb_attributes; i++)
998 if(cUriLength!=SysStringLen(This->attributes[i].szURI)
999 || cocalNameLength!=SysStringLen(This->attributes[i].szLocalname))
1000 continue;
1001 if(cUriLength && memcmp(pUri, This->attributes[i].szURI,
1002 sizeof(WCHAR)*cUriLength))
1003 continue;
1004 if(cocalNameLength && memcmp(pLocalName, This->attributes[i].szLocalname,
1005 sizeof(WCHAR)*cocalNameLength))
1006 continue;
1008 *index = i;
1009 return S_OK;
1012 return E_INVALIDARG;
1015 static HRESULT WINAPI isaxattributes_getIndexFromQName(
1016 ISAXAttributes* iface,
1017 const WCHAR *pQName,
1018 int nQNameLength,
1019 int *index)
1021 saxlocator *This = impl_from_ISAXAttributes( iface );
1022 int i;
1023 TRACE("(%p)->(%s, %d)\n", This, debugstr_w(pQName), nQNameLength);
1025 if(!pQName || !index) return E_POINTER;
1026 if(!nQNameLength) return E_INVALIDARG;
1028 for(i=0; i<This->nb_attributes; i++)
1030 if(nQNameLength!=SysStringLen(This->attributes[i].szQName)) continue;
1031 if(memcmp(pQName, This->attributes[i].szQName, sizeof(WCHAR)*nQNameLength)) continue;
1033 *index = i;
1034 return S_OK;
1037 return E_INVALIDARG;
1040 static HRESULT WINAPI isaxattributes_getType(
1041 ISAXAttributes* iface,
1042 int nIndex,
1043 const WCHAR **pType,
1044 int *pTypeLength)
1046 saxlocator *This = impl_from_ISAXAttributes( iface );
1048 FIXME("(%p)->(%d) stub\n", This, nIndex);
1049 return E_NOTIMPL;
1052 static HRESULT WINAPI isaxattributes_getTypeFromName(
1053 ISAXAttributes* iface,
1054 const WCHAR *pUri,
1055 int nUri,
1056 const WCHAR *pLocalName,
1057 int nLocalName,
1058 const WCHAR **pType,
1059 int *nType)
1061 saxlocator *This = impl_from_ISAXAttributes( iface );
1063 FIXME("(%p)->(%s, %d, %s, %d) stub\n", This, debugstr_w(pUri), nUri,
1064 debugstr_w(pLocalName), nLocalName);
1065 return E_NOTIMPL;
1068 static HRESULT WINAPI isaxattributes_getTypeFromQName(
1069 ISAXAttributes* iface,
1070 const WCHAR *pQName,
1071 int nQName,
1072 const WCHAR **pType,
1073 int *nType)
1075 saxlocator *This = impl_from_ISAXAttributes( iface );
1077 FIXME("(%p)->(%s, %d) stub\n", This, debugstr_w(pQName), nQName);
1078 return E_NOTIMPL;
1081 static HRESULT WINAPI isaxattributes_getValue(
1082 ISAXAttributes* iface,
1083 int index,
1084 const WCHAR **value,
1085 int *nValue)
1087 saxlocator *This = impl_from_ISAXAttributes( iface );
1088 TRACE("(%p)->(%d)\n", This, index);
1090 if(index>=This->nb_attributes || index<0) return E_INVALIDARG;
1091 if(!value || !nValue) return E_POINTER;
1093 *nValue = SysStringLen(This->attributes[index].szValue);
1094 *value = This->attributes[index].szValue;
1096 TRACE("(%s:%d)\n", debugstr_w(*value), *nValue);
1098 return S_OK;
1101 static HRESULT WINAPI isaxattributes_getValueFromName(
1102 ISAXAttributes* iface,
1103 const WCHAR *pUri,
1104 int nUri,
1105 const WCHAR *pLocalName,
1106 int nLocalName,
1107 const WCHAR **pValue,
1108 int *nValue)
1110 HRESULT hr;
1111 int index;
1112 saxlocator *This = impl_from_ISAXAttributes( iface );
1113 TRACE("(%p)->(%s, %d, %s, %d)\n", This, debugstr_w(pUri), nUri,
1114 debugstr_w(pLocalName), nLocalName);
1116 hr = ISAXAttributes_getIndexFromName(iface,
1117 pUri, nUri, pLocalName, nLocalName, &index);
1118 if(hr==S_OK) hr = ISAXAttributes_getValue(iface, index, pValue, nValue);
1120 return hr;
1123 static HRESULT WINAPI isaxattributes_getValueFromQName(
1124 ISAXAttributes* iface,
1125 const WCHAR *pQName,
1126 int nQName,
1127 const WCHAR **pValue,
1128 int *nValue)
1130 HRESULT hr;
1131 int index;
1132 saxlocator *This = impl_from_ISAXAttributes( iface );
1133 TRACE("(%p)->(%s, %d)\n", This, debugstr_w(pQName), nQName);
1135 hr = ISAXAttributes_getIndexFromQName(iface, pQName, nQName, &index);
1136 if(hr==S_OK) hr = ISAXAttributes_getValue(iface, index, pValue, nValue);
1138 return hr;
1141 static const struct ISAXAttributesVtbl isaxattributes_vtbl =
1143 isaxattributes_QueryInterface,
1144 isaxattributes_AddRef,
1145 isaxattributes_Release,
1146 isaxattributes_getLength,
1147 isaxattributes_getURI,
1148 isaxattributes_getLocalName,
1149 isaxattributes_getQName,
1150 isaxattributes_getName,
1151 isaxattributes_getIndexFromName,
1152 isaxattributes_getIndexFromQName,
1153 isaxattributes_getType,
1154 isaxattributes_getTypeFromName,
1155 isaxattributes_getTypeFromQName,
1156 isaxattributes_getValue,
1157 isaxattributes_getValueFromName,
1158 isaxattributes_getValueFromQName
1161 static HRESULT SAXAttributes_populate(saxlocator *locator,
1162 int nb_namespaces, const xmlChar **xmlNamespaces,
1163 int nb_attributes, const xmlChar **xmlAttributes)
1165 static const xmlChar xmlns[] = "xmlns";
1166 static const WCHAR xmlnsW[] = { 'x','m','l','n','s',0 };
1168 struct _attributes *attrs;
1169 int i;
1171 /* skip namespace definitions */
1172 if ((locator->saxreader->features & NamespacePrefixes) == 0)
1173 nb_namespaces = 0;
1175 locator->nb_attributes = nb_namespaces + nb_attributes;
1176 if(locator->nb_attributes > locator->attributesSize)
1178 attrs = heap_realloc(locator->attributes, sizeof(struct _attributes)*locator->nb_attributes*2);
1179 if(!attrs)
1181 locator->nb_attributes = 0;
1182 return E_OUTOFMEMORY;
1184 locator->attributes = attrs;
1186 else
1188 attrs = locator->attributes;
1191 for (i = 0; i < nb_namespaces; i++)
1193 attrs[nb_attributes+i].szLocalname = SysAllocStringLen(NULL, 0);
1194 attrs[nb_attributes+i].szURI = locator->namespaceUri;
1195 attrs[nb_attributes+i].szValue = bstr_from_xmlChar(xmlNamespaces[2*i+1]);
1196 if(!xmlNamespaces[2*i])
1197 attrs[nb_attributes+i].szQName = SysAllocString(xmlnsW);
1198 else
1199 attrs[nb_attributes+i].szQName = QName_from_xmlChar(xmlns, xmlNamespaces[2*i]);
1202 for (i = 0; i < nb_attributes; i++)
1204 static const xmlChar xmlA[] = "xml";
1206 if (xmlStrEqual(xmlAttributes[i*5+1], xmlA))
1207 attrs[i].szURI = bstr_from_xmlChar(xmlAttributes[i*5+2]);
1208 else
1209 attrs[i].szURI = find_element_uri(locator, xmlAttributes[i*5+2]);
1211 attrs[i].szLocalname = bstr_from_xmlChar(xmlAttributes[i*5]);
1212 attrs[i].szValue = bstr_from_xmlCharN(xmlAttributes[i*5+3],
1213 xmlAttributes[i*5+4]-xmlAttributes[i*5+3]);
1214 attrs[i].szQName = QName_from_xmlChar(xmlAttributes[i*5+1],
1215 xmlAttributes[i*5]);
1218 return S_OK;
1221 /*** LibXML callbacks ***/
1222 static void libxmlStartDocument(void *ctx)
1224 saxlocator *This = ctx;
1225 HRESULT hr;
1227 if (This->saxreader->version >= MSXML4)
1229 const xmlChar *p = This->pParserCtxt->input->cur-1;
1230 update_position(This, FALSE);
1231 while(p>This->pParserCtxt->input->base && *p!='>')
1233 if(*p=='\n' || (*p=='\r' && *(p+1)!='\n'))
1234 This->line--;
1235 p--;
1237 This->column = 0;
1238 for(; p>=This->pParserCtxt->input->base && *p!='\n' && *p!='\r'; p--)
1239 This->column++;
1242 if(has_content_handler(This))
1244 if(This->vbInterface)
1245 hr = IVBSAXContentHandler_startDocument(This->saxreader->vbcontentHandler);
1246 else
1247 hr = ISAXContentHandler_startDocument(This->saxreader->contentHandler);
1249 if (sax_callback_failed(This, hr))
1250 format_error_message_from_id(This, hr);
1254 static void libxmlEndDocument(void *ctx)
1256 saxlocator *This = ctx;
1257 HRESULT hr;
1259 if (This->saxreader->version >= MSXML4) {
1260 update_position(This, FALSE);
1261 if(This->column > 1)
1262 This->line++;
1263 This->column = 0;
1264 } else {
1265 This->column = 0;
1266 This->line = 0;
1269 if(This->ret != S_OK) return;
1271 if(has_content_handler(This))
1273 if(This->vbInterface)
1274 hr = IVBSAXContentHandler_endDocument(This->saxreader->vbcontentHandler);
1275 else
1276 hr = ISAXContentHandler_endDocument(This->saxreader->contentHandler);
1278 if (sax_callback_failed(This, hr))
1279 format_error_message_from_id(This, hr);
1283 static void libxmlStartElementNS(
1284 void *ctx,
1285 const xmlChar *localname,
1286 const xmlChar *prefix,
1287 const xmlChar *URI,
1288 int nb_namespaces,
1289 const xmlChar **namespaces,
1290 int nb_attributes,
1291 int nb_defaulted,
1292 const xmlChar **attributes)
1294 saxlocator *This = ctx;
1295 element_entry *element;
1296 HRESULT hr = S_OK;
1297 BSTR uri;
1299 update_position(This, TRUE);
1300 if(*(This->pParserCtxt->input->cur) == '/')
1301 This->column++;
1302 if(This->saxreader->version < MSXML4)
1303 This->column++;
1305 element = alloc_element_entry(localname, prefix, nb_namespaces, namespaces);
1306 push_element_ns(This, element);
1308 if (is_namespaces_enabled(This->saxreader))
1310 int i;
1312 for (i = 0; i < nb_namespaces && has_content_handler(This); i++)
1314 if (This->vbInterface)
1315 hr = IVBSAXContentHandler_startPrefixMapping(
1316 This->saxreader->vbcontentHandler,
1317 &element->ns[i].prefix,
1318 &element->ns[i].uri);
1319 else
1320 hr = ISAXContentHandler_startPrefixMapping(
1321 This->saxreader->contentHandler,
1322 element->ns[i].prefix,
1323 SysStringLen(element->ns[i].prefix),
1324 element->ns[i].uri,
1325 SysStringLen(element->ns[i].uri));
1327 if (sax_callback_failed(This, hr))
1329 format_error_message_from_id(This, hr);
1330 return;
1335 uri = find_element_uri(This, URI);
1336 hr = SAXAttributes_populate(This, nb_namespaces, namespaces, nb_attributes, attributes);
1337 if (hr == S_OK && has_content_handler(This))
1339 BSTR local;
1341 if (is_namespaces_enabled(This->saxreader))
1342 local = element->local;
1343 else
1344 uri = local = NULL;
1346 if (This->vbInterface)
1347 hr = IVBSAXContentHandler_startElement(This->saxreader->vbcontentHandler,
1348 &uri, &local, &element->qname, &This->IVBSAXAttributes_iface);
1349 else
1350 hr = ISAXContentHandler_startElement(This->saxreader->contentHandler,
1351 uri, SysStringLen(uri),
1352 local, SysStringLen(local),
1353 element->qname, SysStringLen(element->qname),
1354 &This->ISAXAttributes_iface);
1356 if (sax_callback_failed(This, hr))
1357 format_error_message_from_id(This, hr);
1361 static void libxmlEndElementNS(
1362 void *ctx,
1363 const xmlChar *localname,
1364 const xmlChar *prefix,
1365 const xmlChar *URI)
1367 saxlocator *This = ctx;
1368 element_entry *element;
1369 const xmlChar *p;
1370 BSTR uri, local;
1371 HRESULT hr;
1373 update_position(This, FALSE);
1374 p = This->pParserCtxt->input->cur;
1376 if (This->saxreader->version >= MSXML4)
1378 p--;
1379 while(p>This->pParserCtxt->input->base && *p!='>')
1381 if(*p=='\n' || (*p=='\r' && *(p+1)!='\n'))
1382 This->line--;
1383 p--;
1386 else if(*(p-1)!='>' || *(p-2)!='/')
1388 p--;
1389 while(p-2>=This->pParserCtxt->input->base
1390 && *(p-2)!='<' && *(p-1)!='/')
1392 if(*p=='\n' || (*p=='\r' && *(p+1)!='\n'))
1393 This->line--;
1394 p--;
1397 This->column = 0;
1398 for(; p>=This->pParserCtxt->input->base && *p!='\n' && *p!='\r'; p--)
1399 This->column++;
1401 uri = find_element_uri(This, URI);
1402 element = pop_element_ns(This);
1404 if (!has_content_handler(This))
1406 This->nb_attributes = 0;
1407 free_element_entry(element);
1408 return;
1411 if (is_namespaces_enabled(This->saxreader))
1412 local = element->local;
1413 else
1414 uri = local = NULL;
1416 if (This->vbInterface)
1417 hr = IVBSAXContentHandler_endElement(
1418 This->saxreader->vbcontentHandler,
1419 &uri, &local, &element->qname);
1420 else
1421 hr = ISAXContentHandler_endElement(
1422 This->saxreader->contentHandler,
1423 uri, SysStringLen(uri),
1424 local, SysStringLen(local),
1425 element->qname, SysStringLen(element->qname));
1427 This->nb_attributes = 0;
1429 if (sax_callback_failed(This, hr))
1431 format_error_message_from_id(This, hr);
1432 free_element_entry(element);
1433 return;
1436 if (is_namespaces_enabled(This->saxreader))
1438 int i = -1;
1439 while (iterate_endprefix_index(This, element, &i) && has_content_handler(This))
1441 if (This->vbInterface)
1442 hr = IVBSAXContentHandler_endPrefixMapping(
1443 This->saxreader->vbcontentHandler, &element->ns[i].prefix);
1444 else
1445 hr = ISAXContentHandler_endPrefixMapping(
1446 This->saxreader->contentHandler,
1447 element->ns[i].prefix, SysStringLen(element->ns[i].prefix));
1449 if (sax_callback_failed(This, hr)) break;
1452 if (sax_callback_failed(This, hr))
1453 format_error_message_from_id(This, hr);
1456 free_element_entry(element);
1459 static void libxmlCharacters(
1460 void *ctx,
1461 const xmlChar *ch,
1462 int len)
1464 saxlocator *This = ctx;
1465 BSTR Chars;
1466 HRESULT hr;
1467 xmlChar *cur, *end;
1468 BOOL lastEvent = FALSE;
1470 if(!(has_content_handler(This))) return;
1472 update_position(This, FALSE);
1473 cur = (xmlChar*)This->pParserCtxt->input->cur;
1474 while(cur>=This->pParserCtxt->input->base && *cur!='>')
1476 if(*cur=='\n' || (*cur=='\r' && *(cur+1)!='\n'))
1477 This->line--;
1478 cur--;
1480 This->column = 1;
1481 for(; cur>=This->pParserCtxt->input->base && *cur!='\n' && *cur!='\r'; cur--)
1482 This->column++;
1484 cur = (xmlChar*)ch;
1485 if(*(ch-1)=='\r') cur--;
1486 end = cur;
1488 while(1)
1490 while(end-ch<len && *end!='\r') end++;
1491 if(end-ch==len)
1493 lastEvent = TRUE;
1495 else
1497 *end = '\n';
1498 end++;
1501 if (This->saxreader->version >= MSXML4)
1503 xmlChar *p;
1505 for(p=cur; p!=end; p++)
1507 if(*p=='\n')
1509 This->line++;
1510 This->column = 1;
1512 else
1514 This->column++;
1518 if(!lastEvent)
1519 This->column = 0;
1522 Chars = pooled_bstr_from_xmlCharN(&This->saxreader->pool, cur, end-cur);
1523 if(This->vbInterface)
1524 hr = IVBSAXContentHandler_characters(
1525 This->saxreader->vbcontentHandler, &Chars);
1526 else
1527 hr = ISAXContentHandler_characters(
1528 This->saxreader->contentHandler,
1529 Chars, SysStringLen(Chars));
1531 if (sax_callback_failed(This, hr))
1533 format_error_message_from_id(This, hr);
1534 return;
1537 if (This->saxreader->version < MSXML4)
1538 This->column += end-cur;
1540 if(lastEvent)
1541 break;
1543 *(end-1) = '\r';
1544 if(*end == '\n')
1546 end++;
1547 This->column++;
1549 cur = end;
1551 if(end-ch == len) break;
1555 static void libxmlSetDocumentLocator(
1556 void *ctx,
1557 xmlSAXLocatorPtr loc)
1559 saxlocator *This = ctx;
1560 HRESULT hr = S_OK;
1562 if(has_content_handler(This))
1564 if(This->vbInterface)
1565 hr = IVBSAXContentHandler_putref_documentLocator(This->saxreader->vbcontentHandler,
1566 &This->IVBSAXLocator_iface);
1567 else
1568 hr = ISAXContentHandler_putDocumentLocator(This->saxreader->contentHandler,
1569 &This->ISAXLocator_iface);
1572 if(FAILED(hr))
1573 format_error_message_from_id(This, hr);
1576 static void libxmlComment(void *ctx, const xmlChar *value)
1578 saxlocator *This = ctx;
1579 BSTR bValue;
1580 HRESULT hr;
1581 const xmlChar *p = This->pParserCtxt->input->cur;
1583 update_position(This, FALSE);
1584 while(p-4>=This->pParserCtxt->input->base
1585 && memcmp(p-4, "<!--", sizeof(char[4])))
1587 if(*p=='\n' || (*p=='\r' && *(p+1)!='\n'))
1588 This->line--;
1589 p--;
1592 This->column = 0;
1593 for(; p>=This->pParserCtxt->input->base && *p!='\n' && *p!='\r'; p--)
1594 This->column++;
1596 if (!has_lexical_handler(This)) return;
1598 bValue = pooled_bstr_from_xmlChar(&This->saxreader->pool, value);
1600 if(This->vbInterface)
1601 hr = IVBSAXLexicalHandler_comment(
1602 This->saxreader->vblexicalHandler, &bValue);
1603 else
1604 hr = ISAXLexicalHandler_comment(
1605 This->saxreader->lexicalHandler,
1606 bValue, SysStringLen(bValue));
1608 if(FAILED(hr))
1609 format_error_message_from_id(This, hr);
1612 static void libxmlFatalError(void *ctx, const char *msg, ...)
1614 saxlocator *This = ctx;
1615 char message[1024];
1616 WCHAR *error;
1617 DWORD len;
1618 va_list args;
1620 if(This->ret != S_OK) {
1621 xmlStopParser(This->pParserCtxt);
1622 return;
1625 va_start(args, msg);
1626 vsprintf(message, msg, args);
1627 va_end(args);
1629 len = MultiByteToWideChar(CP_UNIXCP, 0, message, -1, NULL, 0);
1630 error = heap_alloc(sizeof(WCHAR)*len);
1631 if(error)
1633 MultiByteToWideChar(CP_UNIXCP, 0, message, -1, error, len);
1634 TRACE("fatal error for %p: %s\n", This, debugstr_w(error));
1637 if(!has_error_handler(This))
1639 xmlStopParser(This->pParserCtxt);
1640 This->ret = E_FAIL;
1641 heap_free(error);
1642 return;
1645 FIXME("Error handling is not compatible.\n");
1647 if(This->vbInterface)
1649 BSTR bstrError = SysAllocString(error);
1650 IVBSAXErrorHandler_fatalError(This->saxreader->vberrorHandler, &This->IVBSAXLocator_iface,
1651 &bstrError, E_FAIL);
1652 SysFreeString(bstrError);
1654 else
1655 ISAXErrorHandler_fatalError(This->saxreader->errorHandler, &This->ISAXLocator_iface,
1656 error, E_FAIL);
1658 heap_free(error);
1660 xmlStopParser(This->pParserCtxt);
1661 This->ret = E_FAIL;
1664 static void libxmlCDataBlock(void *ctx, const xmlChar *value, int len)
1666 saxlocator *This = ctx;
1667 HRESULT hr = S_OK;
1668 xmlChar *beg = (xmlChar*)This->pParserCtxt->input->cur-len;
1669 xmlChar *cur, *end;
1670 int realLen;
1671 BSTR Chars;
1672 BOOL lastEvent = FALSE, change;
1674 update_position(This, FALSE);
1675 while(beg-9>=This->pParserCtxt->input->base
1676 && memcmp(beg-9, "<![CDATA[", sizeof(char[9])))
1678 if(*beg=='\n' || (*beg=='\r' && *(beg+1)!='\n'))
1679 This->line--;
1680 beg--;
1682 This->column = 0;
1683 for(; beg>=This->pParserCtxt->input->base && *beg!='\n' && *beg!='\r'; beg--)
1684 This->column++;
1686 if (has_lexical_handler(This))
1688 if (This->vbInterface)
1689 hr = IVBSAXLexicalHandler_startCDATA(This->saxreader->vblexicalHandler);
1690 else
1691 hr = ISAXLexicalHandler_startCDATA(This->saxreader->lexicalHandler);
1694 if(FAILED(hr))
1696 format_error_message_from_id(This, hr);
1697 return;
1700 realLen = This->pParserCtxt->input->cur-beg-3;
1701 cur = beg;
1702 end = beg;
1704 while(1)
1706 while(end-beg<realLen && *end!='\r') end++;
1707 if(end-beg==realLen)
1709 end--;
1710 lastEvent = TRUE;
1712 else if(end-beg==realLen-1 && *end=='\r' && *(end+1)=='\n')
1713 lastEvent = TRUE;
1715 if(*end == '\r') change = TRUE;
1716 else change = FALSE;
1718 if(change) *end = '\n';
1720 if(has_content_handler(This))
1722 Chars = pooled_bstr_from_xmlCharN(&This->saxreader->pool, cur, end-cur+1);
1723 if(This->vbInterface)
1724 hr = IVBSAXContentHandler_characters(
1725 This->saxreader->vbcontentHandler, &Chars);
1726 else
1727 hr = ISAXContentHandler_characters(
1728 This->saxreader->contentHandler,
1729 Chars, SysStringLen(Chars));
1732 if(change) *end = '\r';
1734 if(lastEvent)
1735 break;
1737 This->column += end-cur+2;
1738 end += 2;
1739 cur = end;
1742 if (has_lexical_handler(This))
1744 if (This->vbInterface)
1745 hr = IVBSAXLexicalHandler_endCDATA(This->saxreader->vblexicalHandler);
1746 else
1747 hr = ISAXLexicalHandler_endCDATA(This->saxreader->lexicalHandler);
1750 if(FAILED(hr))
1751 format_error_message_from_id(This, hr);
1753 This->column += 4+end-cur;
1756 /*** IVBSAXLocator interface ***/
1757 /*** IUnknown methods ***/
1758 static HRESULT WINAPI ivbsaxlocator_QueryInterface(IVBSAXLocator* iface, REFIID riid, void **ppvObject)
1760 saxlocator *This = impl_from_IVBSAXLocator( iface );
1762 TRACE("%p %s %p\n", This, debugstr_guid( riid ), ppvObject);
1764 *ppvObject = NULL;
1766 if ( IsEqualGUID( riid, &IID_IUnknown ) ||
1767 IsEqualGUID( riid, &IID_IDispatch) ||
1768 IsEqualGUID( riid, &IID_IVBSAXLocator ))
1770 *ppvObject = iface;
1772 else if ( IsEqualGUID( riid, &IID_IVBSAXAttributes ))
1774 *ppvObject = &This->IVBSAXAttributes_iface;
1776 else
1778 FIXME("interface %s not implemented\n", debugstr_guid(riid));
1779 return E_NOINTERFACE;
1782 IVBSAXLocator_AddRef( iface );
1784 return S_OK;
1787 static ULONG WINAPI ivbsaxlocator_AddRef(IVBSAXLocator* iface)
1789 saxlocator *This = impl_from_IVBSAXLocator( iface );
1790 TRACE("%p\n", This );
1791 return InterlockedIncrement( &This->ref );
1794 static ULONG WINAPI ivbsaxlocator_Release(
1795 IVBSAXLocator* iface)
1797 saxlocator *This = impl_from_IVBSAXLocator( iface );
1798 return ISAXLocator_Release((ISAXLocator*)&This->IVBSAXLocator_iface);
1801 /*** IDispatch methods ***/
1802 static HRESULT WINAPI ivbsaxlocator_GetTypeInfoCount( IVBSAXLocator *iface, UINT* pctinfo )
1804 saxlocator *This = impl_from_IVBSAXLocator( iface );
1806 TRACE("(%p)->(%p)\n", This, pctinfo);
1808 *pctinfo = 1;
1810 return S_OK;
1813 static HRESULT WINAPI ivbsaxlocator_GetTypeInfo(
1814 IVBSAXLocator *iface,
1815 UINT iTInfo, LCID lcid, ITypeInfo** ppTInfo )
1817 saxlocator *This = impl_from_IVBSAXLocator( iface );
1818 HRESULT hr;
1820 TRACE("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo);
1822 hr = get_typeinfo(IVBSAXLocator_tid, ppTInfo);
1824 return hr;
1827 static HRESULT WINAPI ivbsaxlocator_GetIDsOfNames(
1828 IVBSAXLocator *iface,
1829 REFIID riid,
1830 LPOLESTR* rgszNames,
1831 UINT cNames,
1832 LCID lcid,
1833 DISPID* rgDispId)
1835 saxlocator *This = impl_from_IVBSAXLocator( iface );
1836 ITypeInfo *typeinfo;
1837 HRESULT hr;
1839 TRACE("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames, cNames,
1840 lcid, rgDispId);
1842 if(!rgszNames || cNames == 0 || !rgDispId)
1843 return E_INVALIDARG;
1845 hr = get_typeinfo(IVBSAXLocator_tid, &typeinfo);
1846 if(SUCCEEDED(hr))
1848 hr = ITypeInfo_GetIDsOfNames(typeinfo, rgszNames, cNames, rgDispId);
1849 ITypeInfo_Release(typeinfo);
1852 return hr;
1855 static HRESULT WINAPI ivbsaxlocator_Invoke(
1856 IVBSAXLocator *iface,
1857 DISPID dispIdMember,
1858 REFIID riid,
1859 LCID lcid,
1860 WORD wFlags,
1861 DISPPARAMS* pDispParams,
1862 VARIANT* pVarResult,
1863 EXCEPINFO* pExcepInfo,
1864 UINT* puArgErr)
1866 saxlocator *This = impl_from_IVBSAXLocator( iface );
1867 ITypeInfo *typeinfo;
1868 HRESULT hr;
1870 TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
1871 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
1873 hr = get_typeinfo(IVBSAXLocator_tid, &typeinfo);
1874 if(SUCCEEDED(hr))
1876 hr = ITypeInfo_Invoke(typeinfo, &This->IVBSAXLocator_iface, dispIdMember, wFlags,
1877 pDispParams, pVarResult, pExcepInfo, puArgErr);
1878 ITypeInfo_Release(typeinfo);
1881 return hr;
1884 /*** IVBSAXLocator methods ***/
1885 static HRESULT WINAPI ivbsaxlocator_get_columnNumber(
1886 IVBSAXLocator* iface,
1887 int *pnColumn)
1889 saxlocator *This = impl_from_IVBSAXLocator( iface );
1890 return ISAXLocator_getColumnNumber((ISAXLocator*)&This->IVBSAXLocator_iface, pnColumn);
1893 static HRESULT WINAPI ivbsaxlocator_get_lineNumber(
1894 IVBSAXLocator* iface,
1895 int *pnLine)
1897 saxlocator *This = impl_from_IVBSAXLocator( iface );
1898 return ISAXLocator_getLineNumber((ISAXLocator*)&This->IVBSAXLocator_iface, pnLine);
1901 static HRESULT WINAPI ivbsaxlocator_get_publicId(
1902 IVBSAXLocator* iface,
1903 BSTR* publicId)
1905 saxlocator *This = impl_from_IVBSAXLocator( iface );
1906 return ISAXLocator_getPublicId((ISAXLocator*)&This->IVBSAXLocator_iface,
1907 (const WCHAR**)publicId);
1910 static HRESULT WINAPI ivbsaxlocator_get_systemId(
1911 IVBSAXLocator* iface,
1912 BSTR* systemId)
1914 saxlocator *This = impl_from_IVBSAXLocator( iface );
1915 return ISAXLocator_getSystemId((ISAXLocator*)&This->IVBSAXLocator_iface,
1916 (const WCHAR**)systemId);
1919 static const struct IVBSAXLocatorVtbl VBSAXLocatorVtbl =
1921 ivbsaxlocator_QueryInterface,
1922 ivbsaxlocator_AddRef,
1923 ivbsaxlocator_Release,
1924 ivbsaxlocator_GetTypeInfoCount,
1925 ivbsaxlocator_GetTypeInfo,
1926 ivbsaxlocator_GetIDsOfNames,
1927 ivbsaxlocator_Invoke,
1928 ivbsaxlocator_get_columnNumber,
1929 ivbsaxlocator_get_lineNumber,
1930 ivbsaxlocator_get_publicId,
1931 ivbsaxlocator_get_systemId
1934 /*** ISAXLocator interface ***/
1935 /*** IUnknown methods ***/
1936 static HRESULT WINAPI isaxlocator_QueryInterface(ISAXLocator* iface, REFIID riid, void **ppvObject)
1938 saxlocator *This = impl_from_ISAXLocator( iface );
1940 TRACE("%p %s %p\n", This, debugstr_guid( riid ), ppvObject );
1942 *ppvObject = NULL;
1944 if ( IsEqualGUID( riid, &IID_IUnknown ) ||
1945 IsEqualGUID( riid, &IID_ISAXLocator ))
1947 *ppvObject = iface;
1949 else if ( IsEqualGUID( riid, &IID_ISAXAttributes ))
1951 *ppvObject = &This->ISAXAttributes_iface;
1953 else
1955 WARN("interface %s not implemented\n", debugstr_guid(riid));
1956 return E_NOINTERFACE;
1959 ISAXLocator_AddRef( iface );
1961 return S_OK;
1964 static ULONG WINAPI isaxlocator_AddRef(ISAXLocator* iface)
1966 saxlocator *This = impl_from_ISAXLocator( iface );
1967 ULONG ref = InterlockedIncrement( &This->ref );
1968 TRACE("(%p)->(%d)\n", This, ref);
1969 return ref;
1972 static ULONG WINAPI isaxlocator_Release(
1973 ISAXLocator* iface)
1975 saxlocator *This = impl_from_ISAXLocator( iface );
1976 LONG ref = InterlockedDecrement( &This->ref );
1978 TRACE("(%p)->(%d)\n", This, ref );
1980 if (ref == 0)
1982 element_entry *element, *element2;
1983 int index;
1985 SysFreeString(This->publicId);
1986 SysFreeString(This->systemId);
1987 SysFreeString(This->namespaceUri);
1989 for(index=0; index<This->nb_attributes; index++)
1991 SysFreeString(This->attributes[index].szLocalname);
1992 SysFreeString(This->attributes[index].szValue);
1993 SysFreeString(This->attributes[index].szQName);
1995 heap_free(This->attributes);
1997 /* element stack */
1998 LIST_FOR_EACH_ENTRY_SAFE(element, element2, &This->elements, element_entry, entry)
2000 list_remove(&element->entry);
2001 free_element_entry(element);
2004 ISAXXMLReader_Release(&This->saxreader->ISAXXMLReader_iface);
2005 heap_free( This );
2008 return ref;
2011 /*** ISAXLocator methods ***/
2012 static HRESULT WINAPI isaxlocator_getColumnNumber(
2013 ISAXLocator* iface,
2014 int *pnColumn)
2016 saxlocator *This = impl_from_ISAXLocator( iface );
2018 *pnColumn = This->column;
2019 return S_OK;
2022 static HRESULT WINAPI isaxlocator_getLineNumber(
2023 ISAXLocator* iface,
2024 int *pnLine)
2026 saxlocator *This = impl_from_ISAXLocator( iface );
2028 *pnLine = This->line;
2029 return S_OK;
2032 static HRESULT WINAPI isaxlocator_getPublicId(
2033 ISAXLocator* iface,
2034 const WCHAR ** ppwchPublicId)
2036 BSTR publicId;
2037 saxlocator *This = impl_from_ISAXLocator( iface );
2039 SysFreeString(This->publicId);
2041 publicId = bstr_from_xmlChar(xmlSAX2GetPublicId(This->pParserCtxt));
2042 if(SysStringLen(publicId))
2043 This->publicId = (WCHAR*)&publicId;
2044 else
2046 SysFreeString(publicId);
2047 This->publicId = NULL;
2050 *ppwchPublicId = This->publicId;
2051 return S_OK;
2054 static HRESULT WINAPI isaxlocator_getSystemId(
2055 ISAXLocator* iface,
2056 const WCHAR ** ppwchSystemId)
2058 BSTR systemId;
2059 saxlocator *This = impl_from_ISAXLocator( iface );
2061 SysFreeString(This->systemId);
2063 systemId = bstr_from_xmlChar(xmlSAX2GetSystemId(This->pParserCtxt));
2064 if(SysStringLen(systemId))
2065 This->systemId = (WCHAR*)&systemId;
2066 else
2068 SysFreeString(systemId);
2069 This->systemId = NULL;
2072 *ppwchSystemId = This->systemId;
2073 return S_OK;
2076 static const struct ISAXLocatorVtbl SAXLocatorVtbl =
2078 isaxlocator_QueryInterface,
2079 isaxlocator_AddRef,
2080 isaxlocator_Release,
2081 isaxlocator_getColumnNumber,
2082 isaxlocator_getLineNumber,
2083 isaxlocator_getPublicId,
2084 isaxlocator_getSystemId
2087 static HRESULT SAXLocator_create(saxreader *reader, saxlocator **ppsaxlocator, BOOL vbInterface)
2089 static const WCHAR w3xmlns[] = { 'h','t','t','p',':','/','/', 'w','w','w','.','w','3','.',
2090 'o','r','g','/','2','0','0','0','/','x','m','l','n','s','/',0 };
2092 saxlocator *locator;
2094 locator = heap_alloc( sizeof (*locator) );
2095 if( !locator )
2096 return E_OUTOFMEMORY;
2098 locator->IVBSAXLocator_iface.lpVtbl = &VBSAXLocatorVtbl;
2099 locator->ISAXLocator_iface.lpVtbl = &SAXLocatorVtbl;
2100 locator->IVBSAXAttributes_iface.lpVtbl = &ivbsaxattributes_vtbl;
2101 locator->ISAXAttributes_iface.lpVtbl = &isaxattributes_vtbl;
2102 locator->ref = 1;
2103 locator->vbInterface = vbInterface;
2105 locator->saxreader = reader;
2106 ISAXXMLReader_AddRef(&reader->ISAXXMLReader_iface);
2108 locator->pParserCtxt = NULL;
2109 locator->publicId = NULL;
2110 locator->systemId = NULL;
2111 locator->line = reader->version < MSXML4 ? 0 : 1;
2112 locator->column = 0;
2113 locator->ret = S_OK;
2114 if (locator->saxreader->version >= MSXML6)
2115 locator->namespaceUri = SysAllocString(w3xmlns);
2116 else
2117 locator->namespaceUri = SysAllocStringLen(NULL, 0);
2118 if(!locator->namespaceUri)
2120 ISAXXMLReader_Release(&reader->ISAXXMLReader_iface);
2121 heap_free(locator);
2122 return E_OUTOFMEMORY;
2125 locator->attributesSize = 8;
2126 locator->nb_attributes = 0;
2127 locator->attributes = heap_alloc(sizeof(struct _attributes)*locator->attributesSize);
2128 if(!locator->attributes)
2130 ISAXXMLReader_Release(&reader->ISAXXMLReader_iface);
2131 SysFreeString(locator->namespaceUri);
2132 heap_free(locator);
2133 return E_OUTOFMEMORY;
2136 list_init(&locator->elements);
2138 *ppsaxlocator = locator;
2140 TRACE("returning %p\n", *ppsaxlocator);
2142 return S_OK;
2145 /*** SAXXMLReader internal functions ***/
2146 static HRESULT internal_parseBuffer(saxreader *This, const char *buffer, int size, BOOL vbInterface)
2148 xmlCharEncoding encoding = XML_CHAR_ENCODING_NONE;
2149 xmlChar *enc_name = NULL;
2150 saxlocator *locator;
2151 HRESULT hr;
2153 hr = SAXLocator_create(This, &locator, vbInterface);
2154 if (FAILED(hr))
2155 return hr;
2157 if (size >= 4)
2159 const unsigned char *buff = (unsigned char*)buffer;
2161 encoding = xmlDetectCharEncoding((xmlChar*)buffer, 4);
2162 enc_name = (xmlChar*)xmlGetCharEncodingName(encoding);
2163 TRACE("detected encoding: %s\n", enc_name);
2164 /* skip BOM, parser won't switch encodings and so won't skip it on its own */
2165 if ((encoding == XML_CHAR_ENCODING_UTF8) &&
2166 buff[0] == 0xEF && buff[1] == 0xBB && buff[2] == 0xBF)
2168 buffer += 3;
2169 size -= 3;
2173 /* if libxml2 detection failed try to guess */
2174 if (encoding == XML_CHAR_ENCODING_NONE)
2176 const WCHAR *ptr = (WCHAR*)buffer;
2177 /* xml declaration with possibly specfied encoding will be still handled by parser */
2178 if ((size >= 2) && *ptr == '<' && ptr[1] != '?')
2180 enc_name = (xmlChar*)xmlGetCharEncodingName(XML_CHAR_ENCODING_UTF16LE);
2181 encoding = XML_CHAR_ENCODING_UTF16LE;
2184 else if (encoding == XML_CHAR_ENCODING_UTF8)
2185 enc_name = (xmlChar*)xmlGetCharEncodingName(encoding);
2186 else
2187 enc_name = NULL;
2189 locator->pParserCtxt = xmlCreateMemoryParserCtxt(buffer, size);
2190 if (!locator->pParserCtxt)
2192 ISAXLocator_Release(&locator->ISAXLocator_iface);
2193 return E_FAIL;
2196 if (enc_name)
2198 locator->pParserCtxt->encoding = xmlStrdup(enc_name);
2199 if (encoding == XML_CHAR_ENCODING_UTF16LE) {
2200 TRACE("switching to %s\n", enc_name);
2201 xmlSwitchEncoding(locator->pParserCtxt, encoding);
2205 xmlFree(locator->pParserCtxt->sax);
2206 locator->pParserCtxt->sax = &locator->saxreader->sax;
2207 locator->pParserCtxt->userData = locator;
2209 This->isParsing = TRUE;
2210 if(xmlParseDocument(locator->pParserCtxt) == -1 && locator->ret == S_OK)
2211 hr = E_FAIL;
2212 else
2213 hr = locator->ret;
2214 This->isParsing = FALSE;
2216 if(locator->pParserCtxt)
2218 locator->pParserCtxt->sax = NULL;
2219 xmlFreeParserCtxt(locator->pParserCtxt);
2220 locator->pParserCtxt = NULL;
2223 ISAXLocator_Release(&locator->ISAXLocator_iface);
2224 return hr;
2227 static HRESULT internal_parseStream(saxreader *This, IStream *stream, BOOL vbInterface)
2229 saxlocator *locator;
2230 HRESULT hr;
2231 ULONG dataRead;
2232 char data[1024];
2233 int ret;
2235 dataRead = 0;
2236 hr = IStream_Read(stream, data, sizeof(data), &dataRead);
2237 if(FAILED(hr)) return hr;
2239 hr = SAXLocator_create(This, &locator, vbInterface);
2240 if(FAILED(hr)) return hr;
2242 locator->pParserCtxt = xmlCreatePushParserCtxt(
2243 &locator->saxreader->sax, locator,
2244 data, dataRead, NULL);
2245 if(!locator->pParserCtxt)
2247 ISAXLocator_Release(&locator->ISAXLocator_iface);
2248 return E_FAIL;
2251 This->isParsing = TRUE;
2253 if(dataRead != sizeof(data))
2255 ret = xmlParseChunk(locator->pParserCtxt, data, 0, 1);
2256 hr = ret!=XML_ERR_OK && locator->ret==S_OK ? E_FAIL : locator->ret;
2258 else
2260 while(1)
2262 dataRead = 0;
2263 hr = IStream_Read(stream, data, sizeof(data), &dataRead);
2264 if (FAILED(hr)) break;
2266 ret = xmlParseChunk(locator->pParserCtxt, data, dataRead, 0);
2267 hr = ret!=XML_ERR_OK && locator->ret==S_OK ? E_FAIL : locator->ret;
2269 if (hr != S_OK) break;
2271 if (dataRead != sizeof(data))
2273 ret = xmlParseChunk(locator->pParserCtxt, data, 0, 1);
2274 hr = ret!=XML_ERR_OK && locator->ret==S_OK ? E_FAIL : locator->ret;
2275 break;
2280 This->isParsing = FALSE;
2282 xmlFreeParserCtxt(locator->pParserCtxt);
2283 locator->pParserCtxt = NULL;
2284 ISAXLocator_Release(&locator->ISAXLocator_iface);
2285 return hr;
2288 static HRESULT internal_getEntityResolver(
2289 saxreader *This,
2290 void *pEntityResolver,
2291 BOOL vbInterface)
2293 FIXME("(%p)->(%p) stub\n", This, pEntityResolver);
2294 return E_NOTIMPL;
2297 static HRESULT internal_putEntityResolver(
2298 saxreader *This,
2299 void *pEntityResolver,
2300 BOOL vbInterface)
2302 FIXME("(%p)->(%p) stub\n", This, pEntityResolver);
2303 return E_NOTIMPL;
2306 static HRESULT internal_getContentHandler(
2307 saxreader* This,
2308 void *pContentHandler,
2309 BOOL vbInterface)
2311 TRACE("(%p)->(%p)\n", This, pContentHandler);
2312 if(pContentHandler == NULL)
2313 return E_POINTER;
2314 if((vbInterface && This->vbcontentHandler)
2315 || (!vbInterface && This->contentHandler))
2317 if(vbInterface)
2318 IVBSAXContentHandler_AddRef(This->vbcontentHandler);
2319 else
2320 ISAXContentHandler_AddRef(This->contentHandler);
2322 if(vbInterface) *(IVBSAXContentHandler**)pContentHandler =
2323 This->vbcontentHandler;
2324 else *(ISAXContentHandler**)pContentHandler = This->contentHandler;
2326 return S_OK;
2329 static HRESULT internal_putContentHandler(
2330 saxreader* This,
2331 void *contentHandler,
2332 BOOL vbInterface)
2334 TRACE("(%p)->(%p)\n", This, contentHandler);
2335 if(contentHandler)
2337 if(vbInterface)
2338 IVBSAXContentHandler_AddRef((IVBSAXContentHandler*)contentHandler);
2339 else
2340 ISAXContentHandler_AddRef((ISAXContentHandler*)contentHandler);
2342 if((vbInterface && This->vbcontentHandler)
2343 || (!vbInterface && This->contentHandler))
2345 if(vbInterface)
2346 IVBSAXContentHandler_Release(This->vbcontentHandler);
2347 else
2348 ISAXContentHandler_Release(This->contentHandler);
2350 if(vbInterface)
2351 This->vbcontentHandler = contentHandler;
2352 else
2353 This->contentHandler = contentHandler;
2355 return S_OK;
2358 static HRESULT internal_getDTDHandler(
2359 saxreader* This,
2360 void *pDTDHandler,
2361 BOOL vbInterface)
2363 FIXME("(%p)->(%p) stub\n", This, pDTDHandler);
2364 return E_NOTIMPL;
2367 static HRESULT internal_putDTDHandler(
2368 saxreader* This,
2369 void *pDTDHandler,
2370 BOOL vbInterface)
2372 FIXME("(%p)->(%p) stub\n", This, pDTDHandler);
2373 return E_NOTIMPL;
2376 static HRESULT internal_getErrorHandler(
2377 saxreader* This,
2378 void *pErrorHandler,
2379 BOOL vbInterface)
2381 TRACE("(%p)->(%p)\n", This, pErrorHandler);
2382 if(pErrorHandler == NULL)
2383 return E_POINTER;
2385 if(vbInterface && This->vberrorHandler)
2386 IVBSAXErrorHandler_AddRef(This->vberrorHandler);
2387 else if(!vbInterface && This->errorHandler)
2388 ISAXErrorHandler_AddRef(This->errorHandler);
2390 if(vbInterface)
2391 *(IVBSAXErrorHandler**)pErrorHandler = This->vberrorHandler;
2392 else
2393 *(ISAXErrorHandler**)pErrorHandler = This->errorHandler;
2395 return S_OK;
2399 static HRESULT internal_putErrorHandler(
2400 saxreader* This,
2401 void *errorHandler,
2402 BOOL vbInterface)
2404 TRACE("(%p)->(%p)\n", This, errorHandler);
2405 if(errorHandler)
2407 if(vbInterface)
2408 IVBSAXErrorHandler_AddRef((IVBSAXErrorHandler*)errorHandler);
2409 else
2410 ISAXErrorHandler_AddRef((ISAXErrorHandler*)errorHandler);
2413 if(vbInterface && This->vberrorHandler)
2414 IVBSAXErrorHandler_Release(This->vberrorHandler);
2415 else if(!vbInterface && This->errorHandler)
2416 ISAXErrorHandler_Release(This->errorHandler);
2418 if(vbInterface)
2419 This->vberrorHandler = errorHandler;
2420 else
2421 This->errorHandler = errorHandler;
2423 return S_OK;
2427 static HRESULT internal_parse(
2428 saxreader* This,
2429 VARIANT varInput,
2430 BOOL vbInterface)
2432 HRESULT hr;
2434 TRACE("(%p)->(%s)\n", This, debugstr_variant(&varInput));
2436 /* Dispose of the BSTRs in the pool from a prior run, if any. */
2437 free_bstr_pool(&This->pool);
2439 switch(V_VT(&varInput))
2441 case VT_BSTR:
2442 hr = internal_parseBuffer(This, (const char*)V_BSTR(&varInput),
2443 SysStringByteLen(V_BSTR(&varInput)), vbInterface);
2444 break;
2445 case VT_ARRAY|VT_UI1: {
2446 void *pSAData;
2447 LONG lBound, uBound;
2448 ULONG dataRead;
2450 hr = SafeArrayGetLBound(V_ARRAY(&varInput), 1, &lBound);
2451 if(hr != S_OK) break;
2452 hr = SafeArrayGetUBound(V_ARRAY(&varInput), 1, &uBound);
2453 if(hr != S_OK) break;
2454 dataRead = (uBound-lBound)*SafeArrayGetElemsize(V_ARRAY(&varInput));
2455 hr = SafeArrayAccessData(V_ARRAY(&varInput), &pSAData);
2456 if(hr != S_OK) break;
2457 hr = internal_parseBuffer(This, pSAData, dataRead, vbInterface);
2458 SafeArrayUnaccessData(V_ARRAY(&varInput));
2459 break;
2461 case VT_UNKNOWN:
2462 case VT_DISPATCH: {
2463 IPersistStream *persistStream;
2464 IStream *stream = NULL;
2465 IXMLDOMDocument *xmlDoc;
2467 if(IUnknown_QueryInterface(V_UNKNOWN(&varInput),
2468 &IID_IXMLDOMDocument, (void**)&xmlDoc) == S_OK)
2470 BSTR bstrData;
2472 IXMLDOMDocument_get_xml(xmlDoc, &bstrData);
2473 hr = internal_parseBuffer(This, (const char*)bstrData,
2474 SysStringByteLen(bstrData), vbInterface);
2475 IXMLDOMDocument_Release(xmlDoc);
2476 SysFreeString(bstrData);
2477 break;
2480 if(IUnknown_QueryInterface(V_UNKNOWN(&varInput),
2481 &IID_IPersistStream, (void**)&persistStream) == S_OK)
2483 hr = CreateStreamOnHGlobal(NULL, TRUE, &stream);
2484 if(hr != S_OK)
2486 IPersistStream_Release(persistStream);
2487 return hr;
2490 hr = IPersistStream_Save(persistStream, stream, TRUE);
2491 IPersistStream_Release(persistStream);
2492 if(hr != S_OK)
2494 IStream_Release(stream);
2495 stream = NULL;
2499 if(stream || IUnknown_QueryInterface(V_UNKNOWN(&varInput),
2500 &IID_IStream, (void**)&stream) == S_OK)
2502 hr = internal_parseStream(This, stream, vbInterface);
2503 IStream_Release(stream);
2504 break;
2507 default:
2508 WARN("vt %d not implemented\n", V_VT(&varInput));
2509 hr = E_INVALIDARG;
2512 return hr;
2515 static HRESULT internal_vbonDataAvailable(void *obj, char *ptr, DWORD len)
2517 saxreader *This = obj;
2519 return internal_parseBuffer(This, ptr, len, TRUE);
2522 static HRESULT internal_onDataAvailable(void *obj, char *ptr, DWORD len)
2524 saxreader *This = obj;
2526 return internal_parseBuffer(This, ptr, len, FALSE);
2529 static HRESULT internal_parseURL(
2530 saxreader* This,
2531 const WCHAR *url,
2532 BOOL vbInterface)
2534 IMoniker *mon;
2535 bsc_t *bsc;
2536 HRESULT hr;
2538 TRACE("(%p)->(%s)\n", This, debugstr_w(url));
2540 hr = create_moniker_from_url(url, &mon);
2541 if(FAILED(hr))
2542 return hr;
2544 if(vbInterface) hr = bind_url(mon, internal_vbonDataAvailable, This, &bsc);
2545 else hr = bind_url(mon, internal_onDataAvailable, This, &bsc);
2546 IMoniker_Release(mon);
2548 if(FAILED(hr))
2549 return hr;
2551 return detach_bsc(bsc);
2554 static HRESULT internal_putProperty(
2555 saxreader* This,
2556 const WCHAR *prop,
2557 VARIANT value,
2558 BOOL vbInterface)
2560 TRACE("(%p)->(%s %s)\n", This, debugstr_w(prop), debugstr_variant(&value));
2562 if(!memcmp(prop, PropertyDeclHandlerW, sizeof(PropertyDeclHandlerW)))
2564 if(This->isParsing) return E_FAIL;
2566 switch (V_VT(&value))
2568 case VT_EMPTY:
2569 if (vbInterface)
2571 if (This->vbdeclHandler)
2573 IVBSAXDeclHandler_Release(This->vbdeclHandler);
2574 This->vbdeclHandler = NULL;
2577 else
2578 if (This->declHandler)
2580 ISAXDeclHandler_Release(This->declHandler);
2581 This->declHandler = NULL;
2583 break;
2584 case VT_UNKNOWN:
2585 if ((vbInterface && This->vbdeclHandler) ||
2586 (!vbInterface && This->declHandler))
2588 if (vbInterface)
2589 IVBSAXDeclHandler_Release(This->vbdeclHandler);
2590 else
2591 ISAXDeclHandler_Release(This->declHandler);
2594 if (V_UNKNOWN(&value))
2596 return vbInterface ?
2597 IVBSAXDeclHandler_QueryInterface(V_UNKNOWN(&value), &IID_IVBSAXDeclHandler, (void**)&This->vbdeclHandler) :
2598 ISAXDeclHandler_QueryInterface(V_UNKNOWN(&value), &IID_ISAXDeclHandler, (void**)&This->declHandler);
2600 else
2602 This->vbdeclHandler = NULL;
2603 This->declHandler = NULL;
2605 break;
2606 default:
2607 return E_INVALIDARG;
2610 return S_OK;
2613 if(!memcmp(prop, PropertyLexicalHandlerW, sizeof(PropertyLexicalHandlerW)))
2615 if(This->isParsing) return E_FAIL;
2617 switch (V_VT(&value))
2619 case VT_EMPTY:
2620 if (vbInterface)
2622 if (This->vblexicalHandler)
2624 IVBSAXLexicalHandler_Release(This->vblexicalHandler);
2625 This->vblexicalHandler = NULL;
2628 else
2629 if (This->lexicalHandler)
2631 ISAXLexicalHandler_Release(This->lexicalHandler);
2632 This->lexicalHandler = NULL;
2634 break;
2635 case VT_UNKNOWN:
2636 if ((vbInterface && This->vblexicalHandler) ||
2637 (!vbInterface && This->lexicalHandler))
2639 if (vbInterface)
2640 IVBSAXLexicalHandler_Release(This->vblexicalHandler);
2641 else
2642 ISAXLexicalHandler_Release(This->lexicalHandler);
2645 if (V_UNKNOWN(&value))
2647 return vbInterface ?
2648 IVBSAXLexicalHandler_QueryInterface(V_UNKNOWN(&value), &IID_IVBSAXLexicalHandler, (void**)&This->vblexicalHandler) :
2649 ISAXLexicalHandler_QueryInterface(V_UNKNOWN(&value), &IID_ISAXLexicalHandler, (void**)&This->lexicalHandler);
2651 else
2653 This->vblexicalHandler = NULL;
2654 This->lexicalHandler = NULL;
2657 break;
2658 default:
2659 return E_INVALIDARG;
2662 return S_OK;
2665 if(!memcmp(prop, PropertyMaxXMLSizeW, sizeof(PropertyMaxXMLSizeW)))
2667 if (V_VT(&value) == VT_I4 && V_I4(&value) == 0) return S_OK;
2668 FIXME("(%p)->(%s): max-xml-size unsupported\n", This, debugstr_variant(&value));
2669 return E_NOTIMPL;
2672 if(!memcmp(prop, PropertyMaxElementDepthW, sizeof(PropertyMaxElementDepthW)))
2674 if (V_VT(&value) == VT_I4 && V_I4(&value) == 0) return S_OK;
2675 FIXME("(%p)->(%s): max-element-depth unsupported\n", This, debugstr_variant(&value));
2676 return E_NOTIMPL;
2679 FIXME("(%p)->(%s:%s): unsupported property\n", This, debugstr_w(prop), debugstr_variant(&value));
2681 if(!memcmp(prop, PropertyCharsetW, sizeof(PropertyCharsetW)))
2682 return E_NOTIMPL;
2684 if(!memcmp(prop, PropertyDomNodeW, sizeof(PropertyDomNodeW)))
2685 return E_FAIL;
2687 if(!memcmp(prop, PropertyInputSourceW, sizeof(PropertyInputSourceW)))
2688 return E_NOTIMPL;
2690 if(!memcmp(prop, PropertySchemaDeclHandlerW, sizeof(PropertySchemaDeclHandlerW)))
2691 return E_NOTIMPL;
2693 if(!memcmp(prop, PropertyXMLDeclEncodingW, sizeof(PropertyXMLDeclEncodingW)))
2694 return E_FAIL;
2696 if(!memcmp(prop, PropertyXMLDeclStandaloneW, sizeof(PropertyXMLDeclStandaloneW)))
2697 return E_FAIL;
2699 if(!memcmp(prop, PropertyXMLDeclVersionW, sizeof(PropertyXMLDeclVersionW)))
2700 return E_FAIL;
2702 return E_INVALIDARG;
2705 static HRESULT internal_getProperty(const saxreader* This, const WCHAR *prop, VARIANT *value, BOOL vb)
2707 TRACE("(%p)->(%s)\n", This, debugstr_w(prop));
2709 if (!value) return E_POINTER;
2711 if (!memcmp(PropertyLexicalHandlerW, prop, sizeof(PropertyLexicalHandlerW)))
2713 V_VT(value) = VT_UNKNOWN;
2714 V_UNKNOWN(value) = vb ? (IUnknown*)This->vblexicalHandler : (IUnknown*)This->lexicalHandler;
2715 if (V_UNKNOWN(value)) IUnknown_AddRef(V_UNKNOWN(value));
2716 return S_OK;
2719 if (!memcmp(PropertyDeclHandlerW, prop, sizeof(PropertyDeclHandlerW)))
2721 V_VT(value) = VT_UNKNOWN;
2722 V_UNKNOWN(value) = vb ? (IUnknown*)This->vbdeclHandler : (IUnknown*)This->declHandler;
2723 if (V_UNKNOWN(value)) IUnknown_AddRef(V_UNKNOWN(value));
2724 return S_OK;
2727 FIXME("(%p)->(%s) unsupported property\n", This, debugstr_w(prop));
2729 return E_NOTIMPL;
2732 /*** IVBSAXXMLReader interface ***/
2733 /*** IUnknown methods ***/
2734 static HRESULT WINAPI saxxmlreader_QueryInterface(IVBSAXXMLReader* iface, REFIID riid, void **ppvObject)
2736 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2738 TRACE("%p %s %p\n", This, debugstr_guid( riid ), ppvObject );
2740 *ppvObject = NULL;
2742 if ( IsEqualGUID( riid, &IID_IUnknown ) ||
2743 IsEqualGUID( riid, &IID_IDispatch ) ||
2744 IsEqualGUID( riid, &IID_IVBSAXXMLReader ))
2746 *ppvObject = iface;
2748 else if( IsEqualGUID( riid, &IID_ISAXXMLReader ))
2750 *ppvObject = &This->ISAXXMLReader_iface;
2752 else if (dispex_query_interface(&This->dispex, riid, ppvObject))
2754 return *ppvObject ? S_OK : E_NOINTERFACE;
2756 else
2758 FIXME("interface %s not implemented\n", debugstr_guid(riid));
2759 return E_NOINTERFACE;
2762 IVBSAXXMLReader_AddRef( iface );
2764 return S_OK;
2767 static ULONG WINAPI saxxmlreader_AddRef(IVBSAXXMLReader* iface)
2769 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2770 TRACE("%p\n", This );
2771 return InterlockedIncrement( &This->ref );
2774 static ULONG WINAPI saxxmlreader_Release(
2775 IVBSAXXMLReader* iface)
2777 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2778 LONG ref;
2780 TRACE("%p\n", This );
2782 ref = InterlockedDecrement( &This->ref );
2783 if ( ref == 0 )
2785 if(This->contentHandler)
2786 ISAXContentHandler_Release(This->contentHandler);
2788 if(This->vbcontentHandler)
2789 IVBSAXContentHandler_Release(This->vbcontentHandler);
2791 if(This->errorHandler)
2792 ISAXErrorHandler_Release(This->errorHandler);
2794 if(This->vberrorHandler)
2795 IVBSAXErrorHandler_Release(This->vberrorHandler);
2797 if(This->lexicalHandler)
2798 ISAXLexicalHandler_Release(This->lexicalHandler);
2800 if(This->vblexicalHandler)
2801 IVBSAXLexicalHandler_Release(This->vblexicalHandler);
2803 if(This->declHandler)
2804 ISAXDeclHandler_Release(This->declHandler);
2806 if(This->vbdeclHandler)
2807 IVBSAXDeclHandler_Release(This->vbdeclHandler);
2809 free_bstr_pool(&This->pool);
2811 release_dispex(&This->dispex);
2812 heap_free( This );
2815 return ref;
2817 /*** IDispatch ***/
2818 static HRESULT WINAPI saxxmlreader_GetTypeInfoCount( IVBSAXXMLReader *iface, UINT* pctinfo )
2820 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2821 return IDispatchEx_GetTypeInfoCount(&This->dispex.IDispatchEx_iface, pctinfo);
2824 static HRESULT WINAPI saxxmlreader_GetTypeInfo(
2825 IVBSAXXMLReader *iface,
2826 UINT iTInfo, LCID lcid, ITypeInfo** ppTInfo )
2828 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2829 return IDispatchEx_GetTypeInfo(&This->dispex.IDispatchEx_iface,
2830 iTInfo, lcid, ppTInfo);
2833 static HRESULT WINAPI saxxmlreader_GetIDsOfNames(
2834 IVBSAXXMLReader *iface,
2835 REFIID riid,
2836 LPOLESTR* rgszNames,
2837 UINT cNames,
2838 LCID lcid,
2839 DISPID* rgDispId)
2841 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2842 return IDispatchEx_GetIDsOfNames(&This->dispex.IDispatchEx_iface,
2843 riid, rgszNames, cNames, lcid, rgDispId);
2846 static HRESULT WINAPI saxxmlreader_Invoke(
2847 IVBSAXXMLReader *iface,
2848 DISPID dispIdMember,
2849 REFIID riid,
2850 LCID lcid,
2851 WORD wFlags,
2852 DISPPARAMS* pDispParams,
2853 VARIANT* pVarResult,
2854 EXCEPINFO* pExcepInfo,
2855 UINT* puArgErr)
2857 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2858 return IDispatchEx_Invoke(&This->dispex.IDispatchEx_iface,
2859 dispIdMember, riid, lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
2862 /*** IVBSAXXMLReader methods ***/
2863 static HRESULT WINAPI saxxmlreader_getFeature(
2864 IVBSAXXMLReader* iface,
2865 const WCHAR *feature_name,
2866 VARIANT_BOOL *value)
2868 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2869 saxreader_feature feature;
2871 TRACE("(%p)->(%s %p)\n", This, debugstr_w(feature_name), value);
2873 feature = get_saxreader_feature(feature_name);
2874 if (feature == Namespaces || feature == NamespacePrefixes)
2875 return get_feature_value(This, feature, value);
2877 FIXME("(%p)->(%s %p) stub\n", This, debugstr_w(feature_name), value);
2878 return E_NOTIMPL;
2881 static HRESULT WINAPI saxxmlreader_putFeature(
2882 IVBSAXXMLReader* iface,
2883 const WCHAR *feature_name,
2884 VARIANT_BOOL value)
2886 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2887 saxreader_feature feature;
2889 TRACE("(%p)->(%s %x)\n", This, debugstr_w(feature_name), value);
2891 feature = get_saxreader_feature(feature_name);
2893 /* accepted cases */
2894 if ((feature == ExternalGeneralEntities && value == VARIANT_FALSE) ||
2895 (feature == ExternalParameterEntities && value == VARIANT_FALSE) ||
2896 feature == Namespaces ||
2897 feature == NamespacePrefixes)
2899 return set_feature_value(This, feature, value);
2902 if (feature == LexicalHandlerParEntities || feature == ProhibitDTD)
2904 FIXME("(%p)->(%s %x) stub\n", This, debugstr_w(feature_name), value);
2905 return set_feature_value(This, feature, value);
2908 FIXME("(%p)->(%s %x) stub\n", This, debugstr_w(feature_name), value);
2909 return E_NOTIMPL;
2912 static HRESULT WINAPI saxxmlreader_getProperty(
2913 IVBSAXXMLReader* iface,
2914 const WCHAR *prop,
2915 VARIANT *value)
2917 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2918 return internal_getProperty(This, prop, value, TRUE);
2921 static HRESULT WINAPI saxxmlreader_putProperty(
2922 IVBSAXXMLReader* iface,
2923 const WCHAR *pProp,
2924 VARIANT value)
2926 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2927 return internal_putProperty(This, pProp, value, TRUE);
2930 static HRESULT WINAPI saxxmlreader_get_entityResolver(
2931 IVBSAXXMLReader* iface,
2932 IVBSAXEntityResolver **pEntityResolver)
2934 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2935 return internal_getEntityResolver(This, pEntityResolver, TRUE);
2938 static HRESULT WINAPI saxxmlreader_put_entityResolver(
2939 IVBSAXXMLReader* iface,
2940 IVBSAXEntityResolver *pEntityResolver)
2942 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2943 return internal_putEntityResolver(This, pEntityResolver, TRUE);
2946 static HRESULT WINAPI saxxmlreader_get_contentHandler(
2947 IVBSAXXMLReader* iface,
2948 IVBSAXContentHandler **ppContentHandler)
2950 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2951 return internal_getContentHandler(This, ppContentHandler, TRUE);
2954 static HRESULT WINAPI saxxmlreader_put_contentHandler(
2955 IVBSAXXMLReader* iface,
2956 IVBSAXContentHandler *contentHandler)
2958 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2959 return internal_putContentHandler(This, contentHandler, TRUE);
2962 static HRESULT WINAPI saxxmlreader_get_dtdHandler(
2963 IVBSAXXMLReader* iface,
2964 IVBSAXDTDHandler **pDTDHandler)
2966 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2967 return internal_getDTDHandler(This, pDTDHandler, TRUE);
2970 static HRESULT WINAPI saxxmlreader_put_dtdHandler(
2971 IVBSAXXMLReader* iface,
2972 IVBSAXDTDHandler *pDTDHandler)
2974 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2975 return internal_putDTDHandler(This, pDTDHandler, TRUE);
2978 static HRESULT WINAPI saxxmlreader_get_errorHandler(
2979 IVBSAXXMLReader* iface,
2980 IVBSAXErrorHandler **pErrorHandler)
2982 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2983 return internal_getErrorHandler(This, pErrorHandler, TRUE);
2986 static HRESULT WINAPI saxxmlreader_put_errorHandler(
2987 IVBSAXXMLReader* iface,
2988 IVBSAXErrorHandler *errorHandler)
2990 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2991 return internal_putErrorHandler(This, errorHandler, TRUE);
2994 static HRESULT WINAPI saxxmlreader_get_baseURL(
2995 IVBSAXXMLReader* iface,
2996 const WCHAR **pBaseUrl)
2998 saxreader *This = impl_from_IVBSAXXMLReader( iface );
3000 FIXME("(%p)->(%p) stub\n", This, pBaseUrl);
3001 return E_NOTIMPL;
3004 static HRESULT WINAPI saxxmlreader_put_baseURL(
3005 IVBSAXXMLReader* iface,
3006 const WCHAR *pBaseUrl)
3008 saxreader *This = impl_from_IVBSAXXMLReader( iface );
3010 FIXME("(%p)->(%s) stub\n", This, debugstr_w(pBaseUrl));
3011 return E_NOTIMPL;
3014 static HRESULT WINAPI saxxmlreader_get_secureBaseURL(
3015 IVBSAXXMLReader* iface,
3016 const WCHAR **pSecureBaseUrl)
3018 saxreader *This = impl_from_IVBSAXXMLReader( iface );
3020 FIXME("(%p)->(%p) stub\n", This, pSecureBaseUrl);
3021 return E_NOTIMPL;
3025 static HRESULT WINAPI saxxmlreader_put_secureBaseURL(
3026 IVBSAXXMLReader* iface,
3027 const WCHAR *secureBaseUrl)
3029 saxreader *This = impl_from_IVBSAXXMLReader( iface );
3031 FIXME("(%p)->(%s) stub\n", This, debugstr_w(secureBaseUrl));
3032 return E_NOTIMPL;
3035 static HRESULT WINAPI saxxmlreader_parse(
3036 IVBSAXXMLReader* iface,
3037 VARIANT varInput)
3039 saxreader *This = impl_from_IVBSAXXMLReader( iface );
3040 return internal_parse(This, varInput, TRUE);
3043 static HRESULT WINAPI saxxmlreader_parseURL(
3044 IVBSAXXMLReader* iface,
3045 const WCHAR *url)
3047 saxreader *This = impl_from_IVBSAXXMLReader( iface );
3048 return internal_parseURL(This, url, TRUE);
3051 static const struct IVBSAXXMLReaderVtbl VBSAXXMLReaderVtbl =
3053 saxxmlreader_QueryInterface,
3054 saxxmlreader_AddRef,
3055 saxxmlreader_Release,
3056 saxxmlreader_GetTypeInfoCount,
3057 saxxmlreader_GetTypeInfo,
3058 saxxmlreader_GetIDsOfNames,
3059 saxxmlreader_Invoke,
3060 saxxmlreader_getFeature,
3061 saxxmlreader_putFeature,
3062 saxxmlreader_getProperty,
3063 saxxmlreader_putProperty,
3064 saxxmlreader_get_entityResolver,
3065 saxxmlreader_put_entityResolver,
3066 saxxmlreader_get_contentHandler,
3067 saxxmlreader_put_contentHandler,
3068 saxxmlreader_get_dtdHandler,
3069 saxxmlreader_put_dtdHandler,
3070 saxxmlreader_get_errorHandler,
3071 saxxmlreader_put_errorHandler,
3072 saxxmlreader_get_baseURL,
3073 saxxmlreader_put_baseURL,
3074 saxxmlreader_get_secureBaseURL,
3075 saxxmlreader_put_secureBaseURL,
3076 saxxmlreader_parse,
3077 saxxmlreader_parseURL
3080 /*** ISAXXMLReader interface ***/
3081 /*** IUnknown methods ***/
3082 static HRESULT WINAPI isaxxmlreader_QueryInterface(ISAXXMLReader* iface, REFIID riid, void **ppvObject)
3084 saxreader *This = impl_from_ISAXXMLReader( iface );
3085 return saxxmlreader_QueryInterface(&This->IVBSAXXMLReader_iface, riid, ppvObject);
3088 static ULONG WINAPI isaxxmlreader_AddRef(ISAXXMLReader* iface)
3090 saxreader *This = impl_from_ISAXXMLReader( iface );
3091 return saxxmlreader_AddRef(&This->IVBSAXXMLReader_iface);
3094 static ULONG WINAPI isaxxmlreader_Release(ISAXXMLReader* iface)
3096 saxreader *This = impl_from_ISAXXMLReader( iface );
3097 return saxxmlreader_Release(&This->IVBSAXXMLReader_iface);
3100 /*** ISAXXMLReader methods ***/
3101 static HRESULT WINAPI isaxxmlreader_getFeature(
3102 ISAXXMLReader* iface,
3103 const WCHAR *pFeature,
3104 VARIANT_BOOL *pValue)
3106 saxreader *This = impl_from_ISAXXMLReader( iface );
3107 return IVBSAXXMLReader_getFeature(&This->IVBSAXXMLReader_iface, pFeature, pValue);
3110 static HRESULT WINAPI isaxxmlreader_putFeature(
3111 ISAXXMLReader* iface,
3112 const WCHAR *pFeature,
3113 VARIANT_BOOL vfValue)
3115 saxreader *This = impl_from_ISAXXMLReader( iface );
3116 return IVBSAXXMLReader_putFeature(&This->IVBSAXXMLReader_iface, pFeature, vfValue);
3119 static HRESULT WINAPI isaxxmlreader_getProperty(
3120 ISAXXMLReader* iface,
3121 const WCHAR *prop,
3122 VARIANT *value)
3124 saxreader *This = impl_from_ISAXXMLReader( iface );
3125 return internal_getProperty(This, prop, value, FALSE);
3128 static HRESULT WINAPI isaxxmlreader_putProperty(
3129 ISAXXMLReader* iface,
3130 const WCHAR *pProp,
3131 VARIANT value)
3133 saxreader *This = impl_from_ISAXXMLReader( iface );
3134 return internal_putProperty(This, pProp, value, FALSE);
3137 static HRESULT WINAPI isaxxmlreader_getEntityResolver(
3138 ISAXXMLReader* iface,
3139 ISAXEntityResolver **ppEntityResolver)
3141 saxreader *This = impl_from_ISAXXMLReader( iface );
3142 return internal_getEntityResolver(This, ppEntityResolver, FALSE);
3145 static HRESULT WINAPI isaxxmlreader_putEntityResolver(
3146 ISAXXMLReader* iface,
3147 ISAXEntityResolver *pEntityResolver)
3149 saxreader *This = impl_from_ISAXXMLReader( iface );
3150 return internal_putEntityResolver(This, pEntityResolver, FALSE);
3153 static HRESULT WINAPI isaxxmlreader_getContentHandler(
3154 ISAXXMLReader* iface,
3155 ISAXContentHandler **pContentHandler)
3157 saxreader *This = impl_from_ISAXXMLReader( iface );
3158 return internal_getContentHandler(This, pContentHandler, FALSE);
3161 static HRESULT WINAPI isaxxmlreader_putContentHandler(
3162 ISAXXMLReader* iface,
3163 ISAXContentHandler *contentHandler)
3165 saxreader *This = impl_from_ISAXXMLReader( iface );
3166 return internal_putContentHandler(This, contentHandler, FALSE);
3169 static HRESULT WINAPI isaxxmlreader_getDTDHandler(
3170 ISAXXMLReader* iface,
3171 ISAXDTDHandler **pDTDHandler)
3173 saxreader *This = impl_from_ISAXXMLReader( iface );
3174 return internal_getDTDHandler(This, pDTDHandler, FALSE);
3177 static HRESULT WINAPI isaxxmlreader_putDTDHandler(
3178 ISAXXMLReader* iface,
3179 ISAXDTDHandler *pDTDHandler)
3181 saxreader *This = impl_from_ISAXXMLReader( iface );
3182 return internal_putDTDHandler(This, pDTDHandler, FALSE);
3185 static HRESULT WINAPI isaxxmlreader_getErrorHandler(
3186 ISAXXMLReader* iface,
3187 ISAXErrorHandler **pErrorHandler)
3189 saxreader *This = impl_from_ISAXXMLReader( iface );
3190 return internal_getErrorHandler(This, pErrorHandler, FALSE);
3193 static HRESULT WINAPI isaxxmlreader_putErrorHandler(
3194 ISAXXMLReader* iface,
3195 ISAXErrorHandler *errorHandler)
3197 saxreader *This = impl_from_ISAXXMLReader( iface );
3198 return internal_putErrorHandler(This, errorHandler, FALSE);
3201 static HRESULT WINAPI isaxxmlreader_getBaseURL(
3202 ISAXXMLReader* iface,
3203 const WCHAR **pBaseUrl)
3205 saxreader *This = impl_from_ISAXXMLReader( iface );
3206 return IVBSAXXMLReader_get_baseURL(&This->IVBSAXXMLReader_iface, pBaseUrl);
3209 static HRESULT WINAPI isaxxmlreader_putBaseURL(
3210 ISAXXMLReader* iface,
3211 const WCHAR *pBaseUrl)
3213 saxreader *This = impl_from_ISAXXMLReader( iface );
3214 return IVBSAXXMLReader_put_baseURL(&This->IVBSAXXMLReader_iface, pBaseUrl);
3217 static HRESULT WINAPI isaxxmlreader_getSecureBaseURL(
3218 ISAXXMLReader* iface,
3219 const WCHAR **pSecureBaseUrl)
3221 saxreader *This = impl_from_ISAXXMLReader( iface );
3222 return IVBSAXXMLReader_get_secureBaseURL(&This->IVBSAXXMLReader_iface, pSecureBaseUrl);
3225 static HRESULT WINAPI isaxxmlreader_putSecureBaseURL(
3226 ISAXXMLReader* iface,
3227 const WCHAR *secureBaseUrl)
3229 saxreader *This = impl_from_ISAXXMLReader( iface );
3230 return IVBSAXXMLReader_put_secureBaseURL(&This->IVBSAXXMLReader_iface, secureBaseUrl);
3233 static HRESULT WINAPI isaxxmlreader_parse(
3234 ISAXXMLReader* iface,
3235 VARIANT varInput)
3237 saxreader *This = impl_from_ISAXXMLReader( iface );
3238 return internal_parse(This, varInput, FALSE);
3241 static HRESULT WINAPI isaxxmlreader_parseURL(
3242 ISAXXMLReader* iface,
3243 const WCHAR *url)
3245 saxreader *This = impl_from_ISAXXMLReader( iface );
3246 return internal_parseURL(This, url, FALSE);
3249 static const struct ISAXXMLReaderVtbl SAXXMLReaderVtbl =
3251 isaxxmlreader_QueryInterface,
3252 isaxxmlreader_AddRef,
3253 isaxxmlreader_Release,
3254 isaxxmlreader_getFeature,
3255 isaxxmlreader_putFeature,
3256 isaxxmlreader_getProperty,
3257 isaxxmlreader_putProperty,
3258 isaxxmlreader_getEntityResolver,
3259 isaxxmlreader_putEntityResolver,
3260 isaxxmlreader_getContentHandler,
3261 isaxxmlreader_putContentHandler,
3262 isaxxmlreader_getDTDHandler,
3263 isaxxmlreader_putDTDHandler,
3264 isaxxmlreader_getErrorHandler,
3265 isaxxmlreader_putErrorHandler,
3266 isaxxmlreader_getBaseURL,
3267 isaxxmlreader_putBaseURL,
3268 isaxxmlreader_getSecureBaseURL,
3269 isaxxmlreader_putSecureBaseURL,
3270 isaxxmlreader_parse,
3271 isaxxmlreader_parseURL
3274 static const tid_t saxreader_iface_tids[] = {
3275 IVBSAXXMLReader_tid,
3278 static dispex_static_data_t saxreader_dispex = {
3279 NULL,
3280 IVBSAXXMLReader_tid,
3281 NULL,
3282 saxreader_iface_tids
3285 HRESULT SAXXMLReader_create(MSXML_VERSION version, IUnknown *outer, LPVOID *ppObj)
3287 saxreader *reader;
3289 TRACE("(%p, %p)\n", outer, ppObj);
3291 reader = heap_alloc( sizeof (*reader) );
3292 if( !reader )
3293 return E_OUTOFMEMORY;
3295 reader->IVBSAXXMLReader_iface.lpVtbl = &VBSAXXMLReaderVtbl;
3296 reader->ISAXXMLReader_iface.lpVtbl = &SAXXMLReaderVtbl;
3297 reader->ref = 1;
3298 reader->contentHandler = NULL;
3299 reader->vbcontentHandler = NULL;
3300 reader->errorHandler = NULL;
3301 reader->vberrorHandler = NULL;
3302 reader->lexicalHandler = NULL;
3303 reader->vblexicalHandler = NULL;
3304 reader->declHandler = NULL;
3305 reader->vbdeclHandler = NULL;
3306 reader->isParsing = FALSE;
3307 reader->pool.pool = NULL;
3308 reader->pool.index = 0;
3309 reader->pool.len = 0;
3310 reader->features = Namespaces | NamespacePrefixes;
3311 reader->version = version;
3313 init_dispex(&reader->dispex, (IUnknown*)&reader->IVBSAXXMLReader_iface, &saxreader_dispex);
3315 memset(&reader->sax, 0, sizeof(xmlSAXHandler));
3316 reader->sax.initialized = XML_SAX2_MAGIC;
3317 reader->sax.startDocument = libxmlStartDocument;
3318 reader->sax.endDocument = libxmlEndDocument;
3319 reader->sax.startElementNs = libxmlStartElementNS;
3320 reader->sax.endElementNs = libxmlEndElementNS;
3321 reader->sax.characters = libxmlCharacters;
3322 reader->sax.setDocumentLocator = libxmlSetDocumentLocator;
3323 reader->sax.comment = libxmlComment;
3324 reader->sax.error = libxmlFatalError;
3325 reader->sax.fatalError = libxmlFatalError;
3326 reader->sax.cdataBlock = libxmlCDataBlock;
3328 *ppObj = &reader->IVBSAXXMLReader_iface;
3330 TRACE("returning iface %p\n", *ppObj);
3332 return S_OK;
3335 #else
3337 HRESULT SAXXMLReader_create(MSXML_VERSION version, IUnknown *pUnkOuter, LPVOID *ppObj)
3339 MESSAGE("This program tried to use a SAX XML Reader object, but\n"
3340 "libxml2 support was not present at compile time.\n");
3341 return E_NOTIMPL;
3344 #endif