2 * SAX Reader implementation
4 * Copyright 2008 Alistair Leslie-Hughes
5 * Copyright 2008 Piotr Caban
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
27 # include <libxml/parser.h>
28 # include <libxml/xmlerror.h>
29 # include <libxml/SAX2.h>
30 # include <libxml/parserInternals.h>
44 #include "wine/debug.h"
45 #include "wine/list.h"
47 #include "msxml_private.h"
49 WINE_DEFAULT_DEBUG_CHANNEL(msxml);
55 ExhaustiveErrors = 1 << 1,
56 ExternalGeneralEntities = 1 << 2,
57 ExternalParameterEntities = 1 << 3,
58 ForcedResync = 1 << 4,
59 NamespacePrefixes = 1 << 5,
61 ParameterEntities = 1 << 7,
62 PreserveSystemIndentifiers = 1 << 8,
64 SchemaValidation = 1 << 10,
65 ServerHttpRequest = 1 << 11,
66 SuppressValidationfatalError = 1 << 12,
67 UseInlineSchema = 1 << 13,
68 UseSchemaLocation = 1 << 14,
69 LexicalHandlerParEntities = 1 << 15
91 ns *ns; /* namespaces defined in this particular element */
98 IVBSAXXMLReader IVBSAXXMLReader_iface;
99 ISAXXMLReader ISAXXMLReader_iface;
101 ISAXContentHandler *contentHandler;
102 IVBSAXContentHandler *vbcontentHandler;
103 ISAXErrorHandler *errorHandler;
104 IVBSAXErrorHandler *vberrorHandler;
105 ISAXLexicalHandler *lexicalHandler;
106 IVBSAXLexicalHandler *vblexicalHandler;
107 ISAXDeclHandler *declHandler;
108 IVBSAXDeclHandler *vbdeclHandler;
111 struct bstrpool pool;
112 saxreader_features features;
113 MSXML_VERSION version;
118 IVBSAXLocator IVBSAXLocator_iface;
119 ISAXLocator ISAXLocator_iface;
120 IVBSAXAttributes IVBSAXAttributes_iface;
121 ISAXAttributes ISAXAttributes_iface;
123 saxreader *saxreader;
125 xmlParserCtxtPtr pParserCtxt;
131 struct list elements;
145 static inline saxreader *impl_from_IVBSAXXMLReader( IVBSAXXMLReader *iface )
147 return CONTAINING_RECORD(iface, saxreader, IVBSAXXMLReader_iface);
150 static inline saxreader *impl_from_ISAXXMLReader( ISAXXMLReader *iface )
152 return CONTAINING_RECORD(iface, saxreader, ISAXXMLReader_iface);
155 static inline saxlocator *impl_from_IVBSAXLocator( IVBSAXLocator *iface )
157 return CONTAINING_RECORD(iface, saxlocator, IVBSAXLocator_iface);
160 static inline saxlocator *impl_from_ISAXLocator( ISAXLocator *iface )
162 return CONTAINING_RECORD(iface, saxlocator, ISAXLocator_iface);
165 static inline saxlocator *impl_from_IVBSAXAttributes( IVBSAXAttributes *iface )
167 return CONTAINING_RECORD(iface, saxlocator, IVBSAXAttributes_iface);
170 static inline saxlocator *impl_from_ISAXAttributes( ISAXAttributes *iface )
172 return CONTAINING_RECORD(iface, saxlocator, ISAXAttributes_iface);
176 static const WCHAR PropertyCharsetW[] = {
177 'c','h','a','r','s','e','t',0
179 static const WCHAR PropertyDeclHandlerW[] = {
180 'h','t','t','p',':','/','/','x','m','l','.','o','r','g','/',
181 's','a','x','/','p','r','o','p','e','r','t','i','e','s','/',
182 'd','e','c','l','a','r','a','t','i','o','n',
183 '-','h','a','n','d','l','e','r',0
185 static const WCHAR PropertyDomNodeW[] = {
186 'h','t','t','p',':','/','/','x','m','l','.','o','r','g','/',
187 's','a','x','/','p','r','o','p','e','r','t','i','e','s','/',
188 'd','o','m','-','n','o','d','e',0
190 static const WCHAR PropertyInputSourceW[] = {
191 'i','n','p','u','t','-','s','o','u','r','c','e',0
193 static const WCHAR PropertyLexicalHandlerW[] = {
194 'h','t','t','p',':','/','/','x','m','l','.','o','r','g','/',
195 's','a','x','/','p','r','o','p','e','r','t','i','e','s','/',
196 'l','e','x','i','c','a','l','-','h','a','n','d','l','e','r',0
198 static const WCHAR PropertyMaxElementDepthW[] = {
199 'm','a','x','-','e','l','e','m','e','n','t','-','d','e','p','t','h',0
201 static const WCHAR PropertyMaxXMLSizeW[] = {
202 'm','a','x','-','x','m','l','-','s','i','z','e',0
204 static const WCHAR PropertySchemaDeclHandlerW[] = {
205 's','c','h','e','m','a','-','d','e','c','l','a','r','a','t','i','o','n','-',
206 'h','a','n','d','l','e','r',0
208 static const WCHAR PropertyXMLDeclEncodingW[] = {
209 'x','m','l','d','e','c','l','-','e','n','c','o','d','i','n','g',0
211 static const WCHAR PropertyXMLDeclStandaloneW[] = {
212 'x','m','l','d','e','c','l','-','s','t','a','n','d','a','l','o','n','e',0
214 static const WCHAR PropertyXMLDeclVersionW[] = {
215 'x','m','l','d','e','c','l','-','v','e','r','s','i','o','n',0
219 static const WCHAR FeatureExternalGeneralEntitiesW[] = {
220 'h','t','t','p',':','/','/','x','m','l','.','o','r','g','/','s','a','x','/',
221 'f','e','a','t','u','r','e','s','/','e','x','t','e','r','n','a','l','-','g','e','n','e','r','a','l',
222 '-','e','n','t','i','t','i','e','s',0
225 static const WCHAR FeatureExternalParameterEntitiesW[] = {
226 'h','t','t','p',':','/','/','x','m','l','.','o','r','g','/','s','a','x','/','f','e','a','t','u','r','e','s',
227 '/','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
230 static const WCHAR FeatureLexicalHandlerParEntitiesW[] = {
231 'h','t','t','p',':','/','/','x','m','l','.','o','r','g','/','s','a','x','/','f','e','a','t','u','r','e','s',
232 '/','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
235 static const WCHAR FeatureProhibitDTDW[] = {
236 'p','r','o','h','i','b','i','t','-','d','t','d',0
239 static const WCHAR FeatureNamespacesW[] = {
240 'h','t','t','p',':','/','/','x','m','l','.','o','r','g','/','s','a','x','/','f','e','a','t','u','r','e','s',
241 '/','n','a','m','e','s','p','a','c','e','s',0
244 static inline HRESULT set_feature_value(saxreader *reader, saxreader_features feature, VARIANT_BOOL value)
246 if (value == VARIANT_TRUE)
247 reader->features |= feature;
249 reader->features &= ~feature;
254 static inline HRESULT get_feature_value(const saxreader *reader, saxreader_features feature, VARIANT_BOOL *value)
256 *value = reader->features & feature ? VARIANT_TRUE : VARIANT_FALSE;
260 static inline BOOL has_content_handler(const saxlocator *locator)
262 return (locator->vbInterface && locator->saxreader->vbcontentHandler) ||
263 (!locator->vbInterface && locator->saxreader->contentHandler);
266 static inline BOOL has_error_handler(const saxlocator *locator)
268 return (locator->vbInterface && locator->saxreader->vberrorHandler) ||
269 (!locator->vbInterface && locator->saxreader->errorHandler);
272 static BSTR build_qname(BSTR prefix, BSTR local)
274 if (prefix && *prefix)
276 BSTR qname = SysAllocStringLen(NULL, SysStringLen(prefix) + SysStringLen(local) + 1);
280 strcpyW(ptr, prefix);
281 ptr += SysStringLen(prefix);
287 return SysAllocString(local);
290 static element_entry* alloc_element_entry(const xmlChar *local, const xmlChar *prefix, int nb_ns,
291 const xmlChar **namespaces)
296 ret = heap_alloc(sizeof(*ret));
297 if (!ret) return ret;
299 ret->local = bstr_from_xmlChar(local);
300 ret->prefix = bstr_from_xmlChar(prefix);
301 ret->qname = build_qname(ret->prefix, ret->local);
302 ret->ns = nb_ns ? heap_alloc(nb_ns*sizeof(ns)) : NULL;
303 ret->ns_count = nb_ns;
305 for (i=0; i < nb_ns; i++)
307 ret->ns[i].prefix = bstr_from_xmlChar(namespaces[2*i]);
308 ret->ns[i].uri = bstr_from_xmlChar(namespaces[2*i+1]);
314 static void free_element_entry(element_entry *element)
318 for (i=0; i<element->ns_count;i++)
320 SysFreeString(element->ns[i].prefix);
321 SysFreeString(element->ns[i].uri);
324 SysFreeString(element->prefix);
325 SysFreeString(element->local);
327 heap_free(element->ns);
331 static void push_element_ns(saxlocator *locator, element_entry *element)
333 list_add_head(&locator->elements, &element->entry);
336 static element_entry * pop_element_ns(saxlocator *locator)
338 element_entry *element = LIST_ENTRY(list_head(&locator->elements), element_entry, entry);
341 list_remove(&element->entry);
346 static BSTR find_element_uri(saxlocator *locator, const xmlChar *uri)
348 element_entry *element;
352 if (!uri) return NULL;
354 uriW = bstr_from_xmlChar(uri);
356 LIST_FOR_EACH_ENTRY(element, &locator->elements, element_entry, entry)
358 for (i=0; i < element->ns_count; i++)
359 if (!strcmpW(uriW, element->ns[i].uri))
362 return element->ns[i].uri;
367 ERR("namespace uri not found, %s\n", debugstr_a((char*)uri));
371 /* used to localize version dependent error check behaviour */
372 static inline BOOL sax_callback_failed(saxlocator *This, HRESULT hr)
374 return This->saxreader->version >= MSXML4 ? FAILED(hr) : hr != S_OK;
377 /* index value -1 means it tries to loop for a first time */
378 static inline BOOL iterate_endprefix_index(saxlocator *This, const element_entry *element, int *i)
380 if (This->saxreader->version >= MSXML6)
382 if (*i == -1) *i = 0; else ++*i;
383 return *i < element->ns_count;
387 if (*i == -1) *i = element->ns_count-1; else --*i;
392 static BOOL bstr_pool_insert(struct bstrpool *pool, BSTR pool_entry)
396 pool->pool = HeapAlloc(GetProcessHeap(), 0, 16 * sizeof(*pool->pool));
403 else if (pool->index == pool->len)
405 BSTR *realloc = HeapReAlloc(GetProcessHeap(), 0, pool->pool, pool->len * 2 * sizeof(*realloc));
410 pool->pool = realloc;
414 pool->pool[pool->index++] = pool_entry;
418 static void free_bstr_pool(struct bstrpool *pool)
422 for (i = 0; i < pool->index; i++)
423 SysFreeString(pool->pool[i]);
425 HeapFree(GetProcessHeap(), 0, pool->pool);
428 pool->index = pool->len = 0;
431 static BSTR bstr_from_xmlCharN(const xmlChar *buf, int len)
439 dLen = MultiByteToWideChar(CP_UTF8, 0, (LPCSTR)buf, len, NULL, 0);
440 if(len != -1) dLen++;
441 bstr = SysAllocStringLen(NULL, dLen-1);
444 MultiByteToWideChar(CP_UTF8, 0, (LPCSTR)buf, len, bstr, dLen);
445 if(len != -1) bstr[dLen-1] = '\0';
450 static BSTR QName_from_xmlChar(const xmlChar *prefix, const xmlChar *name)
455 if(!name) return NULL;
457 if(!prefix || !*prefix)
458 return bstr_from_xmlChar(name);
460 qname = xmlBuildQName(name, prefix, NULL, 0);
461 bstr = bstr_from_xmlChar(qname);
467 static BSTR pooled_bstr_from_xmlChar(struct bstrpool *pool, const xmlChar *buf)
469 BSTR pool_entry = bstr_from_xmlChar(buf);
471 if (pool_entry && !bstr_pool_insert(pool, pool_entry))
473 SysFreeString(pool_entry);
480 static BSTR pooled_bstr_from_xmlCharN(struct bstrpool *pool, const xmlChar *buf, int len)
482 BSTR pool_entry = bstr_from_xmlCharN(buf, len);
484 if (pool_entry && !bstr_pool_insert(pool, pool_entry))
486 SysFreeString(pool_entry);
493 static void format_error_message_from_id(saxlocator *This, HRESULT hr)
495 xmlStopParser(This->pParserCtxt);
498 if(has_error_handler(This))
501 if(!FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM,
502 NULL, hr, 0, msg, sizeof(msg), NULL))
504 FIXME("MSXML errors not yet supported.\n");
508 if(This->vbInterface)
510 BSTR bstrMsg = SysAllocString(msg);
511 IVBSAXErrorHandler_fatalError(This->saxreader->vberrorHandler,
512 &This->IVBSAXLocator_iface, &bstrMsg, hr);
513 SysFreeString(bstrMsg);
516 ISAXErrorHandler_fatalError(This->saxreader->errorHandler,
517 &This->ISAXLocator_iface, msg, hr);
521 static void update_position(saxlocator *This, BOOL fix_column)
523 const xmlChar *p = This->pParserCtxt->input->cur-1;
525 This->line = xmlSAX2GetLineNumber(This->pParserCtxt);
529 for(; *p!='\n' && *p!='\r' && p>=This->pParserCtxt->input->base; p--)
534 This->column = xmlSAX2GetColumnNumber(This->pParserCtxt);
538 /*** IVBSAXAttributes interface ***/
539 /*** IUnknown methods ***/
540 static HRESULT WINAPI ivbsaxattributes_QueryInterface(
541 IVBSAXAttributes* iface,
545 saxlocator *This = impl_from_IVBSAXAttributes(iface);
546 TRACE("%p %s %p\n", This, debugstr_guid(riid), ppvObject);
547 return IVBSAXLocator_QueryInterface(&This->IVBSAXLocator_iface, riid, ppvObject);
550 static ULONG WINAPI ivbsaxattributes_AddRef(IVBSAXAttributes* iface)
552 saxlocator *This = impl_from_IVBSAXAttributes(iface);
553 return ISAXLocator_AddRef(&This->ISAXLocator_iface);
556 static ULONG WINAPI ivbsaxattributes_Release(IVBSAXAttributes* iface)
558 saxlocator *This = impl_from_IVBSAXAttributes(iface);
559 return ISAXLocator_Release(&This->ISAXLocator_iface);
562 /*** IDispatch methods ***/
563 static HRESULT WINAPI ivbsaxattributes_GetTypeInfoCount( IVBSAXAttributes *iface, UINT* pctinfo )
565 saxlocator *This = impl_from_IVBSAXAttributes( iface );
567 TRACE("(%p)->(%p)\n", This, pctinfo);
574 static HRESULT WINAPI ivbsaxattributes_GetTypeInfo(
575 IVBSAXAttributes *iface,
576 UINT iTInfo, LCID lcid, ITypeInfo** ppTInfo )
578 saxlocator *This = impl_from_IVBSAXAttributes( iface );
581 TRACE("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo);
583 hr = get_typeinfo(IVBSAXAttributes_tid, ppTInfo);
588 static HRESULT WINAPI ivbsaxattributes_GetIDsOfNames(
589 IVBSAXAttributes *iface,
596 saxlocator *This = impl_from_IVBSAXAttributes( iface );
600 TRACE("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames, cNames,
603 if(!rgszNames || cNames == 0 || !rgDispId)
606 hr = get_typeinfo(IVBSAXAttributes_tid, &typeinfo);
609 hr = ITypeInfo_GetIDsOfNames(typeinfo, rgszNames, cNames, rgDispId);
610 ITypeInfo_Release(typeinfo);
616 static HRESULT WINAPI ivbsaxattributes_Invoke(
617 IVBSAXAttributes *iface,
622 DISPPARAMS* pDispParams,
624 EXCEPINFO* pExcepInfo,
627 saxlocator *This = impl_from_IVBSAXAttributes( iface );
631 TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
632 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
634 hr = get_typeinfo(IVBSAXAttributes_tid, &typeinfo);
637 hr = ITypeInfo_Invoke(typeinfo, &This->IVBSAXAttributes_iface, dispIdMember, wFlags,
638 pDispParams, pVarResult, pExcepInfo, puArgErr);
639 ITypeInfo_Release(typeinfo);
645 /*** IVBSAXAttributes methods ***/
646 static HRESULT WINAPI ivbsaxattributes_get_length(
647 IVBSAXAttributes* iface,
650 saxlocator *This = impl_from_IVBSAXAttributes( iface );
651 return ISAXAttributes_getLength(&This->ISAXAttributes_iface, nLength);
654 static HRESULT WINAPI ivbsaxattributes_getURI(
655 IVBSAXAttributes* iface,
660 saxlocator *This = impl_from_IVBSAXAttributes( iface );
661 return ISAXAttributes_getURI(&This->ISAXAttributes_iface, nIndex, (const WCHAR**)uri, &len);
664 static HRESULT WINAPI ivbsaxattributes_getLocalName(
665 IVBSAXAttributes* iface,
670 saxlocator *This = impl_from_IVBSAXAttributes( iface );
671 return ISAXAttributes_getLocalName(&This->ISAXAttributes_iface, nIndex,
672 (const WCHAR**)localName, &len);
675 static HRESULT WINAPI ivbsaxattributes_getQName(
676 IVBSAXAttributes* iface,
681 saxlocator *This = impl_from_IVBSAXAttributes( iface );
682 return ISAXAttributes_getQName(&This->ISAXAttributes_iface, nIndex, (const WCHAR**)QName, &len);
685 static HRESULT WINAPI ivbsaxattributes_getIndexFromName(
686 IVBSAXAttributes* iface,
691 saxlocator *This = impl_from_IVBSAXAttributes( iface );
692 return ISAXAttributes_getIndexFromName(&This->ISAXAttributes_iface, uri, SysStringLen(uri),
693 localName, SysStringLen(localName), index);
696 static HRESULT WINAPI ivbsaxattributes_getIndexFromQName(
697 IVBSAXAttributes* iface,
701 saxlocator *This = impl_from_IVBSAXAttributes( iface );
702 return ISAXAttributes_getIndexFromQName(&This->ISAXAttributes_iface, QName,
703 SysStringLen(QName), index);
706 static HRESULT WINAPI ivbsaxattributes_getType(
707 IVBSAXAttributes* iface,
712 saxlocator *This = impl_from_IVBSAXAttributes( iface );
713 return ISAXAttributes_getType(&This->ISAXAttributes_iface, nIndex, (const WCHAR**)type, &len);
716 static HRESULT WINAPI ivbsaxattributes_getTypeFromName(
717 IVBSAXAttributes* iface,
723 saxlocator *This = impl_from_IVBSAXAttributes( iface );
724 return ISAXAttributes_getTypeFromName(&This->ISAXAttributes_iface, uri, SysStringLen(uri),
725 localName, SysStringLen(localName), (const WCHAR**)type, &len);
728 static HRESULT WINAPI ivbsaxattributes_getTypeFromQName(
729 IVBSAXAttributes* iface,
734 saxlocator *This = impl_from_IVBSAXAttributes( iface );
735 return ISAXAttributes_getTypeFromQName(&This->ISAXAttributes_iface, QName, SysStringLen(QName),
736 (const WCHAR**)type, &len);
739 static HRESULT WINAPI ivbsaxattributes_getValue(
740 IVBSAXAttributes* iface,
745 saxlocator *This = impl_from_IVBSAXAttributes( iface );
746 return ISAXAttributes_getValue(&This->ISAXAttributes_iface, nIndex, (const WCHAR**)value, &len);
749 static HRESULT WINAPI ivbsaxattributes_getValueFromName(
750 IVBSAXAttributes* iface,
756 saxlocator *This = impl_from_IVBSAXAttributes( iface );
757 return ISAXAttributes_getValueFromName(&This->ISAXAttributes_iface, uri, SysStringLen(uri),
758 localName, SysStringLen(localName), (const WCHAR**)value, &len);
761 static HRESULT WINAPI ivbsaxattributes_getValueFromQName(
762 IVBSAXAttributes* iface,
767 saxlocator *This = impl_from_IVBSAXAttributes( iface );
768 return ISAXAttributes_getValueFromQName(&This->ISAXAttributes_iface, QName,
769 SysStringLen(QName), (const WCHAR**)value, &len);
772 static const struct IVBSAXAttributesVtbl ivbsaxattributes_vtbl =
774 ivbsaxattributes_QueryInterface,
775 ivbsaxattributes_AddRef,
776 ivbsaxattributes_Release,
777 ivbsaxattributes_GetTypeInfoCount,
778 ivbsaxattributes_GetTypeInfo,
779 ivbsaxattributes_GetIDsOfNames,
780 ivbsaxattributes_Invoke,
781 ivbsaxattributes_get_length,
782 ivbsaxattributes_getURI,
783 ivbsaxattributes_getLocalName,
784 ivbsaxattributes_getQName,
785 ivbsaxattributes_getIndexFromName,
786 ivbsaxattributes_getIndexFromQName,
787 ivbsaxattributes_getType,
788 ivbsaxattributes_getTypeFromName,
789 ivbsaxattributes_getTypeFromQName,
790 ivbsaxattributes_getValue,
791 ivbsaxattributes_getValueFromName,
792 ivbsaxattributes_getValueFromQName
795 /*** ISAXAttributes interface ***/
796 /*** IUnknown methods ***/
797 static HRESULT WINAPI isaxattributes_QueryInterface(
798 ISAXAttributes* iface,
802 saxlocator *This = impl_from_ISAXAttributes(iface);
803 TRACE("%p %s %p\n", This, debugstr_guid(riid), ppvObject);
804 return ISAXLocator_QueryInterface(&This->ISAXLocator_iface, riid, ppvObject);
807 static ULONG WINAPI isaxattributes_AddRef(ISAXAttributes* iface)
809 saxlocator *This = impl_from_ISAXAttributes(iface);
811 return ISAXLocator_AddRef(&This->ISAXLocator_iface);
814 static ULONG WINAPI isaxattributes_Release(ISAXAttributes* iface)
816 saxlocator *This = impl_from_ISAXAttributes(iface);
819 return ISAXLocator_Release(&This->ISAXLocator_iface);
822 /*** ISAXAttributes methods ***/
823 static HRESULT WINAPI isaxattributes_getLength(
824 ISAXAttributes* iface,
827 saxlocator *This = impl_from_ISAXAttributes( iface );
829 *length = This->nb_attributes;
830 TRACE("Length set to %d\n", *length);
834 static HRESULT WINAPI isaxattributes_getURI(
835 ISAXAttributes* iface,
840 saxlocator *This = impl_from_ISAXAttributes( iface );
841 TRACE("(%p)->(%d)\n", This, index);
843 if(index >= This->nb_attributes || index < 0) return E_INVALIDARG;
844 if(!url || !size) return E_POINTER;
846 *size = SysStringLen(This->attributes[index].szURI);
847 *url = This->attributes[index].szURI;
849 TRACE("(%s:%d)\n", debugstr_w(This->attributes[index].szURI), *size);
854 static HRESULT WINAPI isaxattributes_getLocalName(
855 ISAXAttributes* iface,
857 const WCHAR **pLocalName,
858 int *pLocalNameLength)
860 saxlocator *This = impl_from_ISAXAttributes( iface );
861 TRACE("(%p)->(%d)\n", This, nIndex);
863 if(nIndex>=This->nb_attributes || nIndex<0) return E_INVALIDARG;
864 if(!pLocalName || !pLocalNameLength) return E_POINTER;
866 *pLocalNameLength = SysStringLen(This->attributes[nIndex].szLocalname);
867 *pLocalName = This->attributes[nIndex].szLocalname;
872 static HRESULT WINAPI isaxattributes_getQName(
873 ISAXAttributes* iface,
875 const WCHAR **pQName,
878 saxlocator *This = impl_from_ISAXAttributes( iface );
879 TRACE("(%p)->(%d)\n", This, nIndex);
881 if(nIndex>=This->nb_attributes || nIndex<0) return E_INVALIDARG;
882 if(!pQName || !pQNameLength) return E_POINTER;
884 *pQNameLength = SysStringLen(This->attributes[nIndex].szQName);
885 *pQName = This->attributes[nIndex].szQName;
890 static HRESULT WINAPI isaxattributes_getName(
891 ISAXAttributes* iface,
895 const WCHAR **localName,
900 saxlocator *This = impl_from_ISAXAttributes( iface );
901 TRACE("(%p)->(%d)\n", This, index);
903 if(index>=This->nb_attributes || index<0) return E_INVALIDARG;
904 if(!uri || !pUriLength || !localName || !pLocalNameSize
905 || !QName || !pQNameLength) return E_POINTER;
907 *pUriLength = SysStringLen(This->attributes[index].szURI);
908 *uri = This->attributes[index].szURI;
909 *pLocalNameSize = SysStringLen(This->attributes[index].szLocalname);
910 *localName = This->attributes[index].szLocalname;
911 *pQNameLength = SysStringLen(This->attributes[index].szQName);
912 *QName = This->attributes[index].szQName;
914 TRACE("(%s, %s, %s)\n", debugstr_w(*uri), debugstr_w(*localName), debugstr_w(*QName));
919 static HRESULT WINAPI isaxattributes_getIndexFromName(
920 ISAXAttributes* iface,
923 const WCHAR *pLocalName,
927 saxlocator *This = impl_from_ISAXAttributes( iface );
929 TRACE("(%p)->(%s, %d, %s, %d)\n", This, debugstr_w(pUri), cUriLength,
930 debugstr_w(pLocalName), cocalNameLength);
932 if(!pUri || !pLocalName || !index) return E_POINTER;
934 for(i=0; i<This->nb_attributes; i++)
936 if(cUriLength!=SysStringLen(This->attributes[i].szURI)
937 || cocalNameLength!=SysStringLen(This->attributes[i].szLocalname))
939 if(cUriLength && memcmp(pUri, This->attributes[i].szURI,
940 sizeof(WCHAR)*cUriLength))
942 if(cocalNameLength && memcmp(pLocalName, This->attributes[i].szLocalname,
943 sizeof(WCHAR)*cocalNameLength))
953 static HRESULT WINAPI isaxattributes_getIndexFromQName(
954 ISAXAttributes* iface,
959 saxlocator *This = impl_from_ISAXAttributes( iface );
961 TRACE("(%p)->(%s, %d)\n", This, debugstr_w(pQName), nQNameLength);
963 if(!pQName || !index) return E_POINTER;
964 if(!nQNameLength) return E_INVALIDARG;
966 for(i=0; i<This->nb_attributes; i++)
968 if(nQNameLength!=SysStringLen(This->attributes[i].szQName)) continue;
969 if(memcmp(pQName, This->attributes[i].szQName, sizeof(WCHAR)*nQNameLength)) continue;
978 static HRESULT WINAPI isaxattributes_getType(
979 ISAXAttributes* iface,
984 saxlocator *This = impl_from_ISAXAttributes( iface );
986 FIXME("(%p)->(%d) stub\n", This, nIndex);
990 static HRESULT WINAPI isaxattributes_getTypeFromName(
991 ISAXAttributes* iface,
994 const WCHAR *pLocalName,
999 saxlocator *This = impl_from_ISAXAttributes( iface );
1001 FIXME("(%p)->(%s, %d, %s, %d) stub\n", This, debugstr_w(pUri), nUri,
1002 debugstr_w(pLocalName), nLocalName);
1006 static HRESULT WINAPI isaxattributes_getTypeFromQName(
1007 ISAXAttributes* iface,
1008 const WCHAR *pQName,
1010 const WCHAR **pType,
1013 saxlocator *This = impl_from_ISAXAttributes( iface );
1015 FIXME("(%p)->(%s, %d) stub\n", This, debugstr_w(pQName), nQName);
1019 static HRESULT WINAPI isaxattributes_getValue(
1020 ISAXAttributes* iface,
1022 const WCHAR **value,
1025 saxlocator *This = impl_from_ISAXAttributes( iface );
1026 TRACE("(%p)->(%d)\n", This, index);
1028 if(index>=This->nb_attributes || index<0) return E_INVALIDARG;
1029 if(!value || !nValue) return E_POINTER;
1031 *nValue = SysStringLen(This->attributes[index].szValue);
1032 *value = This->attributes[index].szValue;
1034 TRACE("(%s:%d)\n", debugstr_w(*value), *nValue);
1039 static HRESULT WINAPI isaxattributes_getValueFromName(
1040 ISAXAttributes* iface,
1043 const WCHAR *pLocalName,
1045 const WCHAR **pValue,
1050 saxlocator *This = impl_from_ISAXAttributes( iface );
1051 TRACE("(%p)->(%s, %d, %s, %d)\n", This, debugstr_w(pUri), nUri,
1052 debugstr_w(pLocalName), nLocalName);
1054 hr = ISAXAttributes_getIndexFromName(iface,
1055 pUri, nUri, pLocalName, nLocalName, &index);
1056 if(hr==S_OK) hr = ISAXAttributes_getValue(iface, index, pValue, nValue);
1061 static HRESULT WINAPI isaxattributes_getValueFromQName(
1062 ISAXAttributes* iface,
1063 const WCHAR *pQName,
1065 const WCHAR **pValue,
1070 saxlocator *This = impl_from_ISAXAttributes( iface );
1071 TRACE("(%p)->(%s, %d)\n", This, debugstr_w(pQName), nQName);
1073 hr = ISAXAttributes_getIndexFromQName(iface, pQName, nQName, &index);
1074 if(hr==S_OK) hr = ISAXAttributes_getValue(iface, index, pValue, nValue);
1079 static const struct ISAXAttributesVtbl isaxattributes_vtbl =
1081 isaxattributes_QueryInterface,
1082 isaxattributes_AddRef,
1083 isaxattributes_Release,
1084 isaxattributes_getLength,
1085 isaxattributes_getURI,
1086 isaxattributes_getLocalName,
1087 isaxattributes_getQName,
1088 isaxattributes_getName,
1089 isaxattributes_getIndexFromName,
1090 isaxattributes_getIndexFromQName,
1091 isaxattributes_getType,
1092 isaxattributes_getTypeFromName,
1093 isaxattributes_getTypeFromQName,
1094 isaxattributes_getValue,
1095 isaxattributes_getValueFromName,
1096 isaxattributes_getValueFromQName
1099 static HRESULT SAXAttributes_populate(saxlocator *locator,
1100 int nb_namespaces, const xmlChar **xmlNamespaces,
1101 int nb_attributes, const xmlChar **xmlAttributes)
1103 static const xmlChar xmlns[] = "xmlns";
1104 static const WCHAR xmlnsW[] = { 'x','m','l','n','s',0 };
1106 struct _attributes *attrs;
1109 locator->nb_attributes = nb_namespaces+nb_attributes;
1110 if(locator->nb_attributes > locator->attributesSize)
1112 attrs = heap_realloc(locator->attributes, sizeof(struct _attributes)*locator->nb_attributes*2);
1115 locator->nb_attributes = 0;
1116 return E_OUTOFMEMORY;
1118 locator->attributes = attrs;
1122 attrs = locator->attributes;
1125 for(index=0; index<nb_namespaces; index++)
1127 attrs[nb_attributes+index].szLocalname = SysAllocStringLen(NULL, 0);
1128 attrs[nb_attributes+index].szURI = locator->namespaceUri;
1129 attrs[nb_attributes+index].szValue = bstr_from_xmlChar(xmlNamespaces[2*index+1]);
1130 if(!xmlNamespaces[2*index])
1131 attrs[nb_attributes+index].szQName = SysAllocString(xmlnsW);
1133 attrs[nb_attributes+index].szQName = QName_from_xmlChar(xmlns, xmlNamespaces[2*index]);
1136 for(index=0; index<nb_attributes; index++)
1138 static const xmlChar xmlA[] = "xml";
1140 if (xmlStrEqual(xmlAttributes[index*5+1], xmlA))
1141 attrs[index].szURI = bstr_from_xmlChar(xmlAttributes[index*5+2]);
1143 attrs[index].szURI = find_element_uri(locator, xmlAttributes[index*5+2]);
1145 attrs[index].szLocalname = bstr_from_xmlChar(xmlAttributes[index*5]);
1146 attrs[index].szValue = bstr_from_xmlCharN(xmlAttributes[index*5+3],
1147 xmlAttributes[index*5+4]-xmlAttributes[index*5+3]);
1148 attrs[index].szQName = QName_from_xmlChar(xmlAttributes[index*5+1],
1149 xmlAttributes[index*5]);
1155 /*** LibXML callbacks ***/
1156 static void libxmlStartDocument(void *ctx)
1158 saxlocator *This = ctx;
1161 if (This->saxreader->version >= MSXML4)
1163 const xmlChar *p = This->pParserCtxt->input->cur-1;
1164 update_position(This, FALSE);
1165 while(p>This->pParserCtxt->input->base && *p!='>')
1167 if(*p=='\n' || (*p=='\r' && *(p+1)!='\n'))
1172 for(; p>=This->pParserCtxt->input->base && *p!='\n' && *p!='\r'; p--)
1176 if(has_content_handler(This))
1178 if(This->vbInterface)
1179 hr = IVBSAXContentHandler_startDocument(This->saxreader->vbcontentHandler);
1181 hr = ISAXContentHandler_startDocument(This->saxreader->contentHandler);
1183 if (sax_callback_failed(This, hr))
1184 format_error_message_from_id(This, hr);
1188 static void libxmlEndDocument(void *ctx)
1190 saxlocator *This = ctx;
1193 if (This->saxreader->version >= MSXML4) {
1194 update_position(This, FALSE);
1195 if(This->column > 1)
1203 if(This->ret != S_OK) return;
1205 if(has_content_handler(This))
1207 if(This->vbInterface)
1208 hr = IVBSAXContentHandler_endDocument(This->saxreader->vbcontentHandler);
1210 hr = ISAXContentHandler_endDocument(This->saxreader->contentHandler);
1212 if (sax_callback_failed(This, hr))
1213 format_error_message_from_id(This, hr);
1217 static void libxmlStartElementNS(
1219 const xmlChar *localname,
1220 const xmlChar *prefix,
1223 const xmlChar **namespaces,
1226 const xmlChar **attributes)
1228 saxlocator *This = ctx;
1229 element_entry *element;
1232 update_position(This, TRUE);
1233 if(*(This->pParserCtxt->input->cur) == '/')
1235 if(This->saxreader->version < MSXML4)
1238 element = alloc_element_entry(localname, prefix, nb_namespaces, namespaces);
1239 push_element_ns(This, element);
1241 if (has_content_handler(This))
1246 for (i = 0; i < nb_namespaces; i++)
1248 if(This->vbInterface)
1249 hr = IVBSAXContentHandler_startPrefixMapping(
1250 This->saxreader->vbcontentHandler,
1251 &element->ns[i].prefix,
1252 &element->ns[i].uri);
1254 hr = ISAXContentHandler_startPrefixMapping(
1255 This->saxreader->contentHandler,
1256 element->ns[i].prefix,
1257 SysStringLen(element->ns[i].prefix),
1259 SysStringLen(element->ns[i].uri));
1261 if (sax_callback_failed(This, hr))
1263 format_error_message_from_id(This, hr);
1268 uri = find_element_uri(This, URI);
1270 hr = SAXAttributes_populate(This, nb_namespaces, namespaces, nb_attributes, attributes);
1273 if(This->vbInterface)
1274 hr = IVBSAXContentHandler_startElement(This->saxreader->vbcontentHandler,
1275 &uri, &element->local, &element->qname, &This->IVBSAXAttributes_iface);
1277 hr = ISAXContentHandler_startElement(This->saxreader->contentHandler,
1278 uri, SysStringLen(uri),
1279 element->local, SysStringLen(element->local),
1280 element->qname, SysStringLen(element->qname),
1281 &This->ISAXAttributes_iface);
1285 if (sax_callback_failed(This, hr))
1286 format_error_message_from_id(This, hr);
1289 static void libxmlEndElementNS(
1291 const xmlChar *localname,
1292 const xmlChar *prefix,
1295 saxlocator *This = ctx;
1296 element_entry *element;
1302 update_position(This, FALSE);
1303 p = This->pParserCtxt->input->cur;
1305 if (This->saxreader->version >= MSXML4)
1308 while(p>This->pParserCtxt->input->base && *p!='>')
1310 if(*p=='\n' || (*p=='\r' && *(p+1)!='\n'))
1315 else if(*(p-1)!='>' || *(p-2)!='/')
1318 while(p-2>=This->pParserCtxt->input->base
1319 && *(p-2)!='<' && *(p-1)!='/')
1321 if(*p=='\n' || (*p=='\r' && *(p+1)!='\n'))
1327 for(; p>=This->pParserCtxt->input->base && *p!='\n' && *p!='\r'; p--)
1330 uri = find_element_uri(This, URI);
1331 element = pop_element_ns(This);
1333 if (!has_content_handler(This))
1335 This->nb_attributes = 0;
1336 free_element_entry(element);
1340 if(This->vbInterface)
1341 hr = IVBSAXContentHandler_endElement(
1342 This->saxreader->vbcontentHandler,
1343 &uri, &element->local, &element->qname);
1345 hr = ISAXContentHandler_endElement(
1346 This->saxreader->contentHandler,
1347 uri, SysStringLen(uri),
1348 element->local, SysStringLen(element->local),
1349 element->qname, SysStringLen(element->qname));
1351 This->nb_attributes = 0;
1353 if (sax_callback_failed(This, hr))
1355 format_error_message_from_id(This, hr);
1356 free_element_entry(element);
1361 while (iterate_endprefix_index(This, element, &i))
1363 if(This->vbInterface)
1364 hr = IVBSAXContentHandler_endPrefixMapping(
1365 This->saxreader->vbcontentHandler, &element->ns[i].prefix);
1367 hr = ISAXContentHandler_endPrefixMapping(
1368 This->saxreader->contentHandler,
1369 element->ns[i].prefix, SysStringLen(element->ns[i].prefix));
1371 if (sax_callback_failed(This, hr)) break;
1374 if (sax_callback_failed(This, hr))
1375 format_error_message_from_id(This, hr);
1377 free_element_entry(element);
1380 static void libxmlCharacters(
1385 saxlocator *This = ctx;
1389 BOOL lastEvent = FALSE;
1391 if(!(has_content_handler(This))) return;
1393 update_position(This, FALSE);
1394 cur = (xmlChar*)This->pParserCtxt->input->cur;
1395 while(cur>=This->pParserCtxt->input->base && *cur!='>')
1397 if(*cur=='\n' || (*cur=='\r' && *(cur+1)!='\n'))
1402 for(; cur>=This->pParserCtxt->input->base && *cur!='\n' && *cur!='\r'; cur--)
1406 if(*(ch-1)=='\r') cur--;
1411 while(end-ch<len && *end!='\r') end++;
1422 if (This->saxreader->version >= MSXML4)
1426 for(p=cur; p!=end; p++)
1443 Chars = pooled_bstr_from_xmlCharN(&This->saxreader->pool, cur, end-cur);
1444 if(This->vbInterface)
1445 hr = IVBSAXContentHandler_characters(
1446 This->saxreader->vbcontentHandler, &Chars);
1448 hr = ISAXContentHandler_characters(
1449 This->saxreader->contentHandler,
1450 Chars, SysStringLen(Chars));
1452 if (sax_callback_failed(This, hr))
1454 format_error_message_from_id(This, hr);
1458 if (This->saxreader->version < MSXML4)
1459 This->column += end-cur;
1472 if(end-ch == len) break;
1476 static void libxmlSetDocumentLocator(
1478 xmlSAXLocatorPtr loc)
1480 saxlocator *This = ctx;
1483 if(has_content_handler(This))
1485 if(This->vbInterface)
1486 hr = IVBSAXContentHandler_putref_documentLocator(This->saxreader->vbcontentHandler,
1487 &This->IVBSAXLocator_iface);
1489 hr = ISAXContentHandler_putDocumentLocator(This->saxreader->contentHandler,
1490 &This->ISAXLocator_iface);
1494 format_error_message_from_id(This, hr);
1497 static void libxmlComment(void *ctx, const xmlChar *value)
1499 saxlocator *This = ctx;
1502 const xmlChar *p = This->pParserCtxt->input->cur;
1504 update_position(This, FALSE);
1505 while(p-4>=This->pParserCtxt->input->base
1506 && memcmp(p-4, "<!--", sizeof(char[4])))
1508 if(*p=='\n' || (*p=='\r' && *(p+1)!='\n'))
1513 for(; p>=This->pParserCtxt->input->base && *p!='\n' && *p!='\r'; p--)
1516 if(!This->vbInterface && !This->saxreader->lexicalHandler) return;
1517 if(This->vbInterface && !This->saxreader->vblexicalHandler) return;
1519 bValue = pooled_bstr_from_xmlChar(&This->saxreader->pool, value);
1521 if(This->vbInterface)
1522 hr = IVBSAXLexicalHandler_comment(
1523 This->saxreader->vblexicalHandler, &bValue);
1525 hr = ISAXLexicalHandler_comment(
1526 This->saxreader->lexicalHandler,
1527 bValue, SysStringLen(bValue));
1530 format_error_message_from_id(This, hr);
1533 static void libxmlFatalError(void *ctx, const char *msg, ...)
1535 saxlocator *This = ctx;
1541 if(This->ret != S_OK) {
1542 xmlStopParser(This->pParserCtxt);
1546 va_start(args, msg);
1547 vsprintf(message, msg, args);
1550 len = MultiByteToWideChar(CP_UNIXCP, 0, message, -1, NULL, 0);
1551 error = heap_alloc(sizeof(WCHAR)*len);
1554 MultiByteToWideChar(CP_UNIXCP, 0, message, -1, error, len);
1555 TRACE("fatal error for %p: %s\n", This, debugstr_w(error));
1558 if(!has_error_handler(This))
1560 xmlStopParser(This->pParserCtxt);
1566 FIXME("Error handling is not compatible.\n");
1568 if(This->vbInterface)
1570 BSTR bstrError = SysAllocString(error);
1571 IVBSAXErrorHandler_fatalError(This->saxreader->vberrorHandler, &This->IVBSAXLocator_iface,
1572 &bstrError, E_FAIL);
1573 SysFreeString(bstrError);
1576 ISAXErrorHandler_fatalError(This->saxreader->errorHandler, &This->ISAXLocator_iface,
1581 xmlStopParser(This->pParserCtxt);
1585 static void libxmlCDataBlock(void *ctx, const xmlChar *value, int len)
1587 saxlocator *This = ctx;
1589 xmlChar *beg = (xmlChar*)This->pParserCtxt->input->cur-len;
1593 BOOL lastEvent = FALSE, change;
1595 update_position(This, FALSE);
1596 while(beg-9>=This->pParserCtxt->input->base
1597 && memcmp(beg-9, "<![CDATA[", sizeof(char[9])))
1599 if(*beg=='\n' || (*beg=='\r' && *(beg+1)!='\n'))
1604 for(; beg>=This->pParserCtxt->input->base && *beg!='\n' && *beg!='\r'; beg--)
1607 if(This->vbInterface && This->saxreader->vblexicalHandler)
1608 hr = IVBSAXLexicalHandler_startCDATA(This->saxreader->vblexicalHandler);
1609 if(!This->vbInterface && This->saxreader->lexicalHandler)
1610 hr = ISAXLexicalHandler_startCDATA(This->saxreader->lexicalHandler);
1614 format_error_message_from_id(This, hr);
1618 realLen = This->pParserCtxt->input->cur-beg-3;
1624 while(end-beg<realLen && *end!='\r') end++;
1625 if(end-beg==realLen)
1630 else if(end-beg==realLen-1 && *end=='\r' && *(end+1)=='\n')
1633 if(*end == '\r') change = TRUE;
1634 else change = FALSE;
1636 if(change) *end = '\n';
1638 if(has_content_handler(This))
1640 Chars = pooled_bstr_from_xmlCharN(&This->saxreader->pool, cur, end-cur+1);
1641 if(This->vbInterface)
1642 hr = IVBSAXContentHandler_characters(
1643 This->saxreader->vbcontentHandler, &Chars);
1645 hr = ISAXContentHandler_characters(
1646 This->saxreader->contentHandler,
1647 Chars, SysStringLen(Chars));
1650 if(change) *end = '\r';
1655 This->column += end-cur+2;
1660 if(This->vbInterface && This->saxreader->vblexicalHandler)
1661 hr = IVBSAXLexicalHandler_endCDATA(This->saxreader->vblexicalHandler);
1662 if(!This->vbInterface && This->saxreader->lexicalHandler)
1663 hr = ISAXLexicalHandler_endCDATA(This->saxreader->lexicalHandler);
1666 format_error_message_from_id(This, hr);
1668 This->column += 4+end-cur;
1671 /*** IVBSAXLocator interface ***/
1672 /*** IUnknown methods ***/
1673 static HRESULT WINAPI ivbsaxlocator_QueryInterface(IVBSAXLocator* iface, REFIID riid, void **ppvObject)
1675 saxlocator *This = impl_from_IVBSAXLocator( iface );
1677 TRACE("%p %s %p\n", This, debugstr_guid( riid ), ppvObject);
1681 if ( IsEqualGUID( riid, &IID_IUnknown ) ||
1682 IsEqualGUID( riid, &IID_IDispatch) ||
1683 IsEqualGUID( riid, &IID_IVBSAXLocator ))
1687 else if ( IsEqualGUID( riid, &IID_IVBSAXAttributes ))
1689 *ppvObject = &This->IVBSAXAttributes_iface;
1693 FIXME("interface %s not implemented\n", debugstr_guid(riid));
1694 return E_NOINTERFACE;
1697 IVBSAXLocator_AddRef( iface );
1702 static ULONG WINAPI ivbsaxlocator_AddRef(IVBSAXLocator* iface)
1704 saxlocator *This = impl_from_IVBSAXLocator( iface );
1705 TRACE("%p\n", This );
1706 return InterlockedIncrement( &This->ref );
1709 static ULONG WINAPI ivbsaxlocator_Release(
1710 IVBSAXLocator* iface)
1712 saxlocator *This = impl_from_IVBSAXLocator( iface );
1713 return ISAXLocator_Release((ISAXLocator*)&This->IVBSAXLocator_iface);
1716 /*** IDispatch methods ***/
1717 static HRESULT WINAPI ivbsaxlocator_GetTypeInfoCount( IVBSAXLocator *iface, UINT* pctinfo )
1719 saxlocator *This = impl_from_IVBSAXLocator( iface );
1721 TRACE("(%p)->(%p)\n", This, pctinfo);
1728 static HRESULT WINAPI ivbsaxlocator_GetTypeInfo(
1729 IVBSAXLocator *iface,
1730 UINT iTInfo, LCID lcid, ITypeInfo** ppTInfo )
1732 saxlocator *This = impl_from_IVBSAXLocator( iface );
1735 TRACE("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo);
1737 hr = get_typeinfo(IVBSAXLocator_tid, ppTInfo);
1742 static HRESULT WINAPI ivbsaxlocator_GetIDsOfNames(
1743 IVBSAXLocator *iface,
1745 LPOLESTR* rgszNames,
1750 saxlocator *This = impl_from_IVBSAXLocator( iface );
1751 ITypeInfo *typeinfo;
1754 TRACE("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames, cNames,
1757 if(!rgszNames || cNames == 0 || !rgDispId)
1758 return E_INVALIDARG;
1760 hr = get_typeinfo(IVBSAXLocator_tid, &typeinfo);
1763 hr = ITypeInfo_GetIDsOfNames(typeinfo, rgszNames, cNames, rgDispId);
1764 ITypeInfo_Release(typeinfo);
1770 static HRESULT WINAPI ivbsaxlocator_Invoke(
1771 IVBSAXLocator *iface,
1772 DISPID dispIdMember,
1776 DISPPARAMS* pDispParams,
1777 VARIANT* pVarResult,
1778 EXCEPINFO* pExcepInfo,
1781 saxlocator *This = impl_from_IVBSAXLocator( iface );
1782 ITypeInfo *typeinfo;
1785 TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
1786 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
1788 hr = get_typeinfo(IVBSAXLocator_tid, &typeinfo);
1791 hr = ITypeInfo_Invoke(typeinfo, &This->IVBSAXLocator_iface, dispIdMember, wFlags,
1792 pDispParams, pVarResult, pExcepInfo, puArgErr);
1793 ITypeInfo_Release(typeinfo);
1799 /*** IVBSAXLocator methods ***/
1800 static HRESULT WINAPI ivbsaxlocator_get_columnNumber(
1801 IVBSAXLocator* iface,
1804 saxlocator *This = impl_from_IVBSAXLocator( iface );
1805 return ISAXLocator_getColumnNumber((ISAXLocator*)&This->IVBSAXLocator_iface, pnColumn);
1808 static HRESULT WINAPI ivbsaxlocator_get_lineNumber(
1809 IVBSAXLocator* iface,
1812 saxlocator *This = impl_from_IVBSAXLocator( iface );
1813 return ISAXLocator_getLineNumber((ISAXLocator*)&This->IVBSAXLocator_iface, pnLine);
1816 static HRESULT WINAPI ivbsaxlocator_get_publicId(
1817 IVBSAXLocator* iface,
1820 saxlocator *This = impl_from_IVBSAXLocator( iface );
1821 return ISAXLocator_getPublicId((ISAXLocator*)&This->IVBSAXLocator_iface,
1822 (const WCHAR**)publicId);
1825 static HRESULT WINAPI ivbsaxlocator_get_systemId(
1826 IVBSAXLocator* iface,
1829 saxlocator *This = impl_from_IVBSAXLocator( iface );
1830 return ISAXLocator_getSystemId((ISAXLocator*)&This->IVBSAXLocator_iface,
1831 (const WCHAR**)systemId);
1834 static const struct IVBSAXLocatorVtbl VBSAXLocatorVtbl =
1836 ivbsaxlocator_QueryInterface,
1837 ivbsaxlocator_AddRef,
1838 ivbsaxlocator_Release,
1839 ivbsaxlocator_GetTypeInfoCount,
1840 ivbsaxlocator_GetTypeInfo,
1841 ivbsaxlocator_GetIDsOfNames,
1842 ivbsaxlocator_Invoke,
1843 ivbsaxlocator_get_columnNumber,
1844 ivbsaxlocator_get_lineNumber,
1845 ivbsaxlocator_get_publicId,
1846 ivbsaxlocator_get_systemId
1849 /*** ISAXLocator interface ***/
1850 /*** IUnknown methods ***/
1851 static HRESULT WINAPI isaxlocator_QueryInterface(ISAXLocator* iface, REFIID riid, void **ppvObject)
1853 saxlocator *This = impl_from_ISAXLocator( iface );
1855 TRACE("%p %s %p\n", This, debugstr_guid( riid ), ppvObject );
1859 if ( IsEqualGUID( riid, &IID_IUnknown ) ||
1860 IsEqualGUID( riid, &IID_ISAXLocator ))
1864 else if ( IsEqualGUID( riid, &IID_ISAXAttributes ))
1866 *ppvObject = &This->ISAXAttributes_iface;
1870 FIXME("interface %s not implemented\n", debugstr_guid(riid));
1871 return E_NOINTERFACE;
1874 ISAXLocator_AddRef( iface );
1879 static ULONG WINAPI isaxlocator_AddRef(ISAXLocator* iface)
1881 saxlocator *This = impl_from_ISAXLocator( iface );
1882 ULONG ref = InterlockedIncrement( &This->ref );
1883 TRACE("(%p)->(%d)\n", This, ref);
1887 static ULONG WINAPI isaxlocator_Release(
1890 saxlocator *This = impl_from_ISAXLocator( iface );
1891 LONG ref = InterlockedDecrement( &This->ref );
1893 TRACE("(%p)->(%d)\n", This, ref );
1897 element_entry *element, *element2;
1900 SysFreeString(This->publicId);
1901 SysFreeString(This->systemId);
1902 SysFreeString(This->namespaceUri);
1904 for(index=0; index<This->nb_attributes; index++)
1906 SysFreeString(This->attributes[index].szLocalname);
1907 SysFreeString(This->attributes[index].szValue);
1908 SysFreeString(This->attributes[index].szQName);
1910 heap_free(This->attributes);
1913 LIST_FOR_EACH_ENTRY_SAFE(element, element2, &This->elements, element_entry, entry)
1915 list_remove(&element->entry);
1916 free_element_entry(element);
1919 ISAXXMLReader_Release(&This->saxreader->ISAXXMLReader_iface);
1926 /*** ISAXLocator methods ***/
1927 static HRESULT WINAPI isaxlocator_getColumnNumber(
1931 saxlocator *This = impl_from_ISAXLocator( iface );
1933 *pnColumn = This->column;
1937 static HRESULT WINAPI isaxlocator_getLineNumber(
1941 saxlocator *This = impl_from_ISAXLocator( iface );
1943 *pnLine = This->line;
1947 static HRESULT WINAPI isaxlocator_getPublicId(
1949 const WCHAR ** ppwchPublicId)
1952 saxlocator *This = impl_from_ISAXLocator( iface );
1954 SysFreeString(This->publicId);
1956 publicId = bstr_from_xmlChar(xmlSAX2GetPublicId(This->pParserCtxt));
1957 if(SysStringLen(publicId))
1958 This->publicId = (WCHAR*)&publicId;
1961 SysFreeString(publicId);
1962 This->publicId = NULL;
1965 *ppwchPublicId = This->publicId;
1969 static HRESULT WINAPI isaxlocator_getSystemId(
1971 const WCHAR ** ppwchSystemId)
1974 saxlocator *This = impl_from_ISAXLocator( iface );
1976 SysFreeString(This->systemId);
1978 systemId = bstr_from_xmlChar(xmlSAX2GetSystemId(This->pParserCtxt));
1979 if(SysStringLen(systemId))
1980 This->systemId = (WCHAR*)&systemId;
1983 SysFreeString(systemId);
1984 This->systemId = NULL;
1987 *ppwchSystemId = This->systemId;
1991 static const struct ISAXLocatorVtbl SAXLocatorVtbl =
1993 isaxlocator_QueryInterface,
1995 isaxlocator_Release,
1996 isaxlocator_getColumnNumber,
1997 isaxlocator_getLineNumber,
1998 isaxlocator_getPublicId,
1999 isaxlocator_getSystemId
2002 static HRESULT SAXLocator_create(saxreader *reader, saxlocator **ppsaxlocator, BOOL vbInterface)
2004 static const WCHAR w3xmlns[] = { 'h','t','t','p',':','/','/', 'w','w','w','.','w','3','.',
2005 'o','r','g','/','2','0','0','0','/','x','m','l','n','s','/',0 };
2007 saxlocator *locator;
2009 locator = heap_alloc( sizeof (*locator) );
2011 return E_OUTOFMEMORY;
2013 locator->IVBSAXLocator_iface.lpVtbl = &VBSAXLocatorVtbl;
2014 locator->ISAXLocator_iface.lpVtbl = &SAXLocatorVtbl;
2015 locator->IVBSAXAttributes_iface.lpVtbl = &ivbsaxattributes_vtbl;
2016 locator->ISAXAttributes_iface.lpVtbl = &isaxattributes_vtbl;
2018 locator->vbInterface = vbInterface;
2020 locator->saxreader = reader;
2021 ISAXXMLReader_AddRef(&reader->ISAXXMLReader_iface);
2023 locator->pParserCtxt = NULL;
2024 locator->publicId = NULL;
2025 locator->systemId = NULL;
2026 locator->line = reader->version < MSXML4 ? 0 : 1;
2027 locator->column = 0;
2028 locator->ret = S_OK;
2029 if (locator->saxreader->version >= MSXML6)
2030 locator->namespaceUri = SysAllocString(w3xmlns);
2032 locator->namespaceUri = SysAllocStringLen(NULL, 0);
2033 if(!locator->namespaceUri)
2035 ISAXXMLReader_Release(&reader->ISAXXMLReader_iface);
2037 return E_OUTOFMEMORY;
2040 locator->attributesSize = 8;
2041 locator->nb_attributes = 0;
2042 locator->attributes = heap_alloc(sizeof(struct _attributes)*locator->attributesSize);
2043 if(!locator->attributes)
2045 ISAXXMLReader_Release(&reader->ISAXXMLReader_iface);
2046 SysFreeString(locator->namespaceUri);
2048 return E_OUTOFMEMORY;
2051 list_init(&locator->elements);
2053 *ppsaxlocator = locator;
2055 TRACE("returning %p\n", *ppsaxlocator);
2060 /*** SAXXMLReader internal functions ***/
2061 static HRESULT internal_parseBuffer(saxreader *This, const char *buffer, int size, BOOL vbInterface)
2063 xmlCharEncoding encoding = XML_CHAR_ENCODING_NONE;
2064 xmlChar *enc_name = NULL;
2065 saxlocator *locator;
2068 hr = SAXLocator_create(This, &locator, vbInterface);
2074 const unsigned char *buff = (unsigned char*)buffer;
2076 encoding = xmlDetectCharEncoding((xmlChar*)buffer, 4);
2077 enc_name = (xmlChar*)xmlGetCharEncodingName(encoding);
2078 TRACE("detected encoding: %s\n", enc_name);
2079 /* skip BOM, parser won't switch encodings and so won't skip it on its own */
2080 if ((encoding == XML_CHAR_ENCODING_UTF8) &&
2081 buff[0] == 0xEF && buff[1] == 0xBB && buff[2] == 0xBF)
2088 locator->pParserCtxt = xmlCreateMemoryParserCtxt(buffer, size);
2089 if(!locator->pParserCtxt)
2091 ISAXLocator_Release(&locator->ISAXLocator_iface);
2095 if (encoding == XML_CHAR_ENCODING_UTF8)
2096 locator->pParserCtxt->encoding = xmlStrdup(enc_name);
2098 xmlFree(locator->pParserCtxt->sax);
2099 locator->pParserCtxt->sax = &locator->saxreader->sax;
2100 locator->pParserCtxt->userData = locator;
2102 This->isParsing = TRUE;
2103 if(xmlParseDocument(locator->pParserCtxt)==-1 && locator->ret==S_OK)
2107 This->isParsing = FALSE;
2109 if(locator->pParserCtxt)
2111 locator->pParserCtxt->sax = NULL;
2112 xmlFreeParserCtxt(locator->pParserCtxt);
2113 locator->pParserCtxt = NULL;
2116 ISAXLocator_Release(&locator->ISAXLocator_iface);
2120 static HRESULT internal_parseStream(saxreader *This, IStream *stream, BOOL vbInterface)
2122 saxlocator *locator;
2129 hr = IStream_Read(stream, data, sizeof(data), &dataRead);
2130 if(FAILED(hr)) return hr;
2132 hr = SAXLocator_create(This, &locator, vbInterface);
2133 if(FAILED(hr)) return hr;
2135 locator->pParserCtxt = xmlCreatePushParserCtxt(
2136 &locator->saxreader->sax, locator,
2137 data, dataRead, NULL);
2138 if(!locator->pParserCtxt)
2140 ISAXLocator_Release(&locator->ISAXLocator_iface);
2144 This->isParsing = TRUE;
2146 if(dataRead != sizeof(data))
2148 ret = xmlParseChunk(locator->pParserCtxt, data, 0, 1);
2149 hr = ret!=XML_ERR_OK && locator->ret==S_OK ? E_FAIL : locator->ret;
2156 hr = IStream_Read(stream, data, sizeof(data), &dataRead);
2157 if (FAILED(hr)) break;
2159 ret = xmlParseChunk(locator->pParserCtxt, data, dataRead, 0);
2160 hr = ret!=XML_ERR_OK && locator->ret==S_OK ? E_FAIL : locator->ret;
2162 if (hr != S_OK) break;
2164 if (dataRead != sizeof(data))
2166 ret = xmlParseChunk(locator->pParserCtxt, data, 0, 1);
2167 hr = ret!=XML_ERR_OK && locator->ret==S_OK ? E_FAIL : locator->ret;
2173 This->isParsing = FALSE;
2175 xmlFreeParserCtxt(locator->pParserCtxt);
2176 locator->pParserCtxt = NULL;
2177 ISAXLocator_Release(&locator->ISAXLocator_iface);
2181 static HRESULT internal_getEntityResolver(
2183 void *pEntityResolver,
2186 FIXME("(%p)->(%p) stub\n", This, pEntityResolver);
2190 static HRESULT internal_putEntityResolver(
2192 void *pEntityResolver,
2195 FIXME("(%p)->(%p) stub\n", This, pEntityResolver);
2199 static HRESULT internal_getContentHandler(
2201 void *pContentHandler,
2204 TRACE("(%p)->(%p)\n", This, pContentHandler);
2205 if(pContentHandler == NULL)
2207 if((vbInterface && This->vbcontentHandler)
2208 || (!vbInterface && This->contentHandler))
2211 IVBSAXContentHandler_AddRef(This->vbcontentHandler);
2213 ISAXContentHandler_AddRef(This->contentHandler);
2215 if(vbInterface) *(IVBSAXContentHandler**)pContentHandler =
2216 This->vbcontentHandler;
2217 else *(ISAXContentHandler**)pContentHandler = This->contentHandler;
2222 static HRESULT internal_putContentHandler(
2224 void *contentHandler,
2227 TRACE("(%p)->(%p)\n", This, contentHandler);
2231 IVBSAXContentHandler_AddRef((IVBSAXContentHandler*)contentHandler);
2233 ISAXContentHandler_AddRef((ISAXContentHandler*)contentHandler);
2235 if((vbInterface && This->vbcontentHandler)
2236 || (!vbInterface && This->contentHandler))
2239 IVBSAXContentHandler_Release(This->vbcontentHandler);
2241 ISAXContentHandler_Release(This->contentHandler);
2244 This->vbcontentHandler = contentHandler;
2246 This->contentHandler = contentHandler;
2251 static HRESULT internal_getDTDHandler(
2256 FIXME("(%p)->(%p) stub\n", This, pDTDHandler);
2260 static HRESULT internal_putDTDHandler(
2265 FIXME("(%p)->(%p) stub\n", This, pDTDHandler);
2269 static HRESULT internal_getErrorHandler(
2271 void *pErrorHandler,
2274 TRACE("(%p)->(%p)\n", This, pErrorHandler);
2275 if(pErrorHandler == NULL)
2278 if(vbInterface && This->vberrorHandler)
2279 IVBSAXErrorHandler_AddRef(This->vberrorHandler);
2280 else if(!vbInterface && This->errorHandler)
2281 ISAXErrorHandler_AddRef(This->errorHandler);
2284 *(IVBSAXErrorHandler**)pErrorHandler = This->vberrorHandler;
2286 *(ISAXErrorHandler**)pErrorHandler = This->errorHandler;
2292 static HRESULT internal_putErrorHandler(
2297 TRACE("(%p)->(%p)\n", This, errorHandler);
2301 IVBSAXErrorHandler_AddRef((IVBSAXErrorHandler*)errorHandler);
2303 ISAXErrorHandler_AddRef((ISAXErrorHandler*)errorHandler);
2306 if(vbInterface && This->vberrorHandler)
2307 IVBSAXErrorHandler_Release(This->vberrorHandler);
2308 else if(!vbInterface && This->errorHandler)
2309 ISAXErrorHandler_Release(This->errorHandler);
2312 This->vberrorHandler = errorHandler;
2314 This->errorHandler = errorHandler;
2320 static HRESULT internal_parse(
2327 TRACE("(%p)->(%s)\n", This, debugstr_variant(&varInput));
2329 /* Dispose of the BSTRs in the pool from a prior run, if any. */
2330 free_bstr_pool(&This->pool);
2332 switch(V_VT(&varInput))
2335 hr = internal_parseBuffer(This, (const char*)V_BSTR(&varInput),
2336 SysStringByteLen(V_BSTR(&varInput)), vbInterface);
2338 case VT_ARRAY|VT_UI1: {
2340 LONG lBound, uBound;
2343 hr = SafeArrayGetLBound(V_ARRAY(&varInput), 1, &lBound);
2344 if(hr != S_OK) break;
2345 hr = SafeArrayGetUBound(V_ARRAY(&varInput), 1, &uBound);
2346 if(hr != S_OK) break;
2347 dataRead = (uBound-lBound)*SafeArrayGetElemsize(V_ARRAY(&varInput));
2348 hr = SafeArrayAccessData(V_ARRAY(&varInput), &pSAData);
2349 if(hr != S_OK) break;
2350 hr = internal_parseBuffer(This, pSAData, dataRead, vbInterface);
2351 SafeArrayUnaccessData(V_ARRAY(&varInput));
2356 IPersistStream *persistStream;
2357 IStream *stream = NULL;
2358 IXMLDOMDocument *xmlDoc;
2360 if(IUnknown_QueryInterface(V_UNKNOWN(&varInput),
2361 &IID_IXMLDOMDocument, (void**)&xmlDoc) == S_OK)
2365 IXMLDOMDocument_get_xml(xmlDoc, &bstrData);
2366 hr = internal_parseBuffer(This, (const char*)bstrData,
2367 SysStringByteLen(bstrData), vbInterface);
2368 IXMLDOMDocument_Release(xmlDoc);
2369 SysFreeString(bstrData);
2373 if(IUnknown_QueryInterface(V_UNKNOWN(&varInput),
2374 &IID_IPersistStream, (void**)&persistStream) == S_OK)
2376 hr = CreateStreamOnHGlobal(NULL, TRUE, &stream);
2379 IPersistStream_Release(persistStream);
2383 hr = IPersistStream_Save(persistStream, stream, TRUE);
2384 IPersistStream_Release(persistStream);
2387 IStream_Release(stream);
2392 if(stream || IUnknown_QueryInterface(V_UNKNOWN(&varInput),
2393 &IID_IStream, (void**)&stream) == S_OK)
2395 hr = internal_parseStream(This, stream, vbInterface);
2396 IStream_Release(stream);
2401 WARN("vt %d not implemented\n", V_VT(&varInput));
2408 static HRESULT internal_vbonDataAvailable(void *obj, char *ptr, DWORD len)
2410 saxreader *This = obj;
2412 return internal_parseBuffer(This, ptr, len, TRUE);
2415 static HRESULT internal_onDataAvailable(void *obj, char *ptr, DWORD len)
2417 saxreader *This = obj;
2419 return internal_parseBuffer(This, ptr, len, FALSE);
2422 static HRESULT internal_parseURL(
2431 TRACE("(%p)->(%s)\n", This, debugstr_w(url));
2433 hr = create_moniker_from_url(url, &mon);
2437 if(vbInterface) hr = bind_url(mon, internal_vbonDataAvailable, This, &bsc);
2438 else hr = bind_url(mon, internal_onDataAvailable, This, &bsc);
2439 IMoniker_Release(mon);
2444 return detach_bsc(bsc);
2447 static HRESULT internal_putProperty(
2453 TRACE("(%p)->(%s %s)\n", This, debugstr_w(prop), debugstr_variant(&value));
2455 if(!memcmp(prop, PropertyDeclHandlerW, sizeof(PropertyDeclHandlerW)))
2457 if(This->isParsing) return E_FAIL;
2459 switch (V_VT(&value))
2464 if (This->vbdeclHandler)
2466 IVBSAXDeclHandler_Release(This->vbdeclHandler);
2467 This->vbdeclHandler = NULL;
2471 if (This->declHandler)
2473 ISAXDeclHandler_Release(This->declHandler);
2474 This->declHandler = NULL;
2478 if (V_UNKNOWN(&value)) IUnknown_AddRef(V_UNKNOWN(&value));
2480 if ((vbInterface && This->vbdeclHandler) ||
2481 (!vbInterface && This->declHandler))
2484 IVBSAXDeclHandler_Release(This->vbdeclHandler);
2486 ISAXDeclHandler_Release(This->declHandler);
2490 This->vbdeclHandler = (IVBSAXDeclHandler*)V_UNKNOWN(&value);
2492 This->declHandler = (ISAXDeclHandler*)V_UNKNOWN(&value);
2495 return E_INVALIDARG;
2501 if(!memcmp(prop, PropertyLexicalHandlerW, sizeof(PropertyLexicalHandlerW)))
2503 if(This->isParsing) return E_FAIL;
2505 switch (V_VT(&value))
2510 if (This->vblexicalHandler)
2512 IVBSAXLexicalHandler_Release(This->vblexicalHandler);
2513 This->vblexicalHandler = NULL;
2517 if (This->lexicalHandler)
2519 ISAXLexicalHandler_Release(This->lexicalHandler);
2520 This->lexicalHandler = NULL;
2524 if (V_UNKNOWN(&value)) IUnknown_AddRef(V_UNKNOWN(&value));
2526 if ((vbInterface && This->vblexicalHandler) ||
2527 (!vbInterface && This->lexicalHandler))
2530 IVBSAXLexicalHandler_Release(This->vblexicalHandler);
2532 ISAXLexicalHandler_Release(This->lexicalHandler);
2536 This->vblexicalHandler = (IVBSAXLexicalHandler*)V_UNKNOWN(&value);
2538 This->lexicalHandler = (ISAXLexicalHandler*)V_UNKNOWN(&value);
2541 return E_INVALIDARG;
2547 if(!memcmp(prop, PropertyMaxXMLSizeW, sizeof(PropertyMaxXMLSizeW)))
2549 if (V_VT(&value) == VT_I4 && V_I4(&value) == 0) return S_OK;
2550 FIXME("(%p)->(%s): max-xml-size unsupported\n", This, debugstr_variant(&value));
2554 if(!memcmp(prop, PropertyMaxElementDepthW, sizeof(PropertyMaxElementDepthW)))
2556 if (V_VT(&value) == VT_I4 && V_I4(&value) == 0) return S_OK;
2557 FIXME("(%p)->(%s): max-element-depth unsupported\n", This, debugstr_variant(&value));
2561 FIXME("(%p)->(%s:%s): unsupported property\n", This, debugstr_w(prop), debugstr_variant(&value));
2563 if(!memcmp(prop, PropertyCharsetW, sizeof(PropertyCharsetW)))
2566 if(!memcmp(prop, PropertyDomNodeW, sizeof(PropertyDomNodeW)))
2569 if(!memcmp(prop, PropertyInputSourceW, sizeof(PropertyInputSourceW)))
2572 if(!memcmp(prop, PropertySchemaDeclHandlerW, sizeof(PropertySchemaDeclHandlerW)))
2575 if(!memcmp(prop, PropertyXMLDeclEncodingW, sizeof(PropertyXMLDeclEncodingW)))
2578 if(!memcmp(prop, PropertyXMLDeclStandaloneW, sizeof(PropertyXMLDeclStandaloneW)))
2581 if(!memcmp(prop, PropertyXMLDeclVersionW, sizeof(PropertyXMLDeclVersionW)))
2584 return E_INVALIDARG;
2587 static HRESULT internal_getProperty(const saxreader* This, const WCHAR *prop, VARIANT *value, BOOL vb)
2589 TRACE("(%p)->(%s)\n", This, debugstr_w(prop));
2591 if (!value) return E_POINTER;
2593 if (!memcmp(PropertyLexicalHandlerW, prop, sizeof(PropertyLexicalHandlerW)))
2595 V_VT(value) = VT_UNKNOWN;
2596 V_UNKNOWN(value) = vb ? (IUnknown*)This->vblexicalHandler : (IUnknown*)This->lexicalHandler;
2597 if (V_UNKNOWN(value)) IUnknown_AddRef(V_UNKNOWN(value));
2601 if (!memcmp(PropertyDeclHandlerW, prop, sizeof(PropertyDeclHandlerW)))
2603 V_VT(value) = VT_UNKNOWN;
2604 V_UNKNOWN(value) = vb ? (IUnknown*)This->vbdeclHandler : (IUnknown*)This->declHandler;
2605 if (V_UNKNOWN(value)) IUnknown_AddRef(V_UNKNOWN(value));
2609 FIXME("(%p)->(%s) unsupported property\n", This, debugstr_w(prop));
2614 /*** IVBSAXXMLReader interface ***/
2615 /*** IUnknown methods ***/
2616 static HRESULT WINAPI saxxmlreader_QueryInterface(IVBSAXXMLReader* iface, REFIID riid, void **ppvObject)
2618 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2620 TRACE("%p %s %p\n", This, debugstr_guid( riid ), ppvObject );
2624 if ( IsEqualGUID( riid, &IID_IUnknown ) ||
2625 IsEqualGUID( riid, &IID_IDispatch ) ||
2626 IsEqualGUID( riid, &IID_IVBSAXXMLReader ))
2630 else if( IsEqualGUID( riid, &IID_ISAXXMLReader ))
2632 *ppvObject = &This->ISAXXMLReader_iface;
2634 else if (dispex_query_interface(&This->dispex, riid, ppvObject))
2636 return *ppvObject ? S_OK : E_NOINTERFACE;
2640 FIXME("interface %s not implemented\n", debugstr_guid(riid));
2641 return E_NOINTERFACE;
2644 IVBSAXXMLReader_AddRef( iface );
2649 static ULONG WINAPI saxxmlreader_AddRef(IVBSAXXMLReader* iface)
2651 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2652 TRACE("%p\n", This );
2653 return InterlockedIncrement( &This->ref );
2656 static ULONG WINAPI saxxmlreader_Release(
2657 IVBSAXXMLReader* iface)
2659 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2662 TRACE("%p\n", This );
2664 ref = InterlockedDecrement( &This->ref );
2667 if(This->contentHandler)
2668 ISAXContentHandler_Release(This->contentHandler);
2670 if(This->vbcontentHandler)
2671 IVBSAXContentHandler_Release(This->vbcontentHandler);
2673 if(This->errorHandler)
2674 ISAXErrorHandler_Release(This->errorHandler);
2676 if(This->vberrorHandler)
2677 IVBSAXErrorHandler_Release(This->vberrorHandler);
2679 if(This->lexicalHandler)
2680 ISAXLexicalHandler_Release(This->lexicalHandler);
2682 if(This->vblexicalHandler)
2683 IVBSAXLexicalHandler_Release(This->vblexicalHandler);
2685 if(This->declHandler)
2686 ISAXDeclHandler_Release(This->declHandler);
2688 if(This->vbdeclHandler)
2689 IVBSAXDeclHandler_Release(This->vbdeclHandler);
2691 free_bstr_pool(&This->pool);
2693 release_dispex(&This->dispex);
2700 static HRESULT WINAPI saxxmlreader_GetTypeInfoCount( IVBSAXXMLReader *iface, UINT* pctinfo )
2702 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2703 return IDispatchEx_GetTypeInfoCount(&This->dispex.IDispatchEx_iface, pctinfo);
2706 static HRESULT WINAPI saxxmlreader_GetTypeInfo(
2707 IVBSAXXMLReader *iface,
2708 UINT iTInfo, LCID lcid, ITypeInfo** ppTInfo )
2710 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2711 return IDispatchEx_GetTypeInfo(&This->dispex.IDispatchEx_iface,
2712 iTInfo, lcid, ppTInfo);
2715 static HRESULT WINAPI saxxmlreader_GetIDsOfNames(
2716 IVBSAXXMLReader *iface,
2718 LPOLESTR* rgszNames,
2723 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2724 return IDispatchEx_GetIDsOfNames(&This->dispex.IDispatchEx_iface,
2725 riid, rgszNames, cNames, lcid, rgDispId);
2728 static HRESULT WINAPI saxxmlreader_Invoke(
2729 IVBSAXXMLReader *iface,
2730 DISPID dispIdMember,
2734 DISPPARAMS* pDispParams,
2735 VARIANT* pVarResult,
2736 EXCEPINFO* pExcepInfo,
2739 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2740 return IDispatchEx_Invoke(&This->dispex.IDispatchEx_iface,
2741 dispIdMember, riid, lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
2744 /*** IVBSAXXMLReader methods ***/
2745 static HRESULT WINAPI saxxmlreader_getFeature(
2746 IVBSAXXMLReader* iface,
2747 const WCHAR *feature,
2748 VARIANT_BOOL *value)
2750 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2752 if (!strcmpW(FeatureNamespacesW, feature))
2753 return get_feature_value(This, Namespaces, value);
2755 FIXME("(%p)->(%s %p) stub\n", This, debugstr_w(feature), value);
2759 static HRESULT WINAPI saxxmlreader_putFeature(
2760 IVBSAXXMLReader* iface,
2761 const WCHAR *feature,
2764 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2766 TRACE("(%p)->(%s %x)\n", This, debugstr_w(feature), value);
2768 if (!strcmpW(FeatureExternalGeneralEntitiesW, feature) && value == VARIANT_FALSE)
2769 return set_feature_value(This, ExternalGeneralEntities, value);
2771 if (!strcmpW(FeatureExternalParameterEntitiesW, feature) && value == VARIANT_FALSE)
2772 return set_feature_value(This, ExternalParameterEntities, value);
2774 if (!strcmpW(FeatureLexicalHandlerParEntitiesW, feature))
2776 FIXME("(%p)->(%s %x) stub\n", This, debugstr_w(feature), value);
2777 return set_feature_value(This, LexicalHandlerParEntities, value);
2780 if (!strcmpW(FeatureProhibitDTDW, feature))
2782 FIXME("(%p)->(%s %x) stub\n", This, debugstr_w(feature), value);
2783 return set_feature_value(This, ProhibitDTD, value);
2786 if (!strcmpW(FeatureNamespacesW, feature) && value == VARIANT_TRUE)
2787 return set_feature_value(This, Namespaces, value);
2789 FIXME("(%p)->(%s %x) stub\n", This, debugstr_w(feature), value);
2793 static HRESULT WINAPI saxxmlreader_getProperty(
2794 IVBSAXXMLReader* iface,
2798 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2799 return internal_getProperty(This, prop, value, TRUE);
2802 static HRESULT WINAPI saxxmlreader_putProperty(
2803 IVBSAXXMLReader* iface,
2807 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2808 return internal_putProperty(This, pProp, value, TRUE);
2811 static HRESULT WINAPI saxxmlreader_get_entityResolver(
2812 IVBSAXXMLReader* iface,
2813 IVBSAXEntityResolver **pEntityResolver)
2815 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2816 return internal_getEntityResolver(This, pEntityResolver, TRUE);
2819 static HRESULT WINAPI saxxmlreader_put_entityResolver(
2820 IVBSAXXMLReader* iface,
2821 IVBSAXEntityResolver *pEntityResolver)
2823 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2824 return internal_putEntityResolver(This, pEntityResolver, TRUE);
2827 static HRESULT WINAPI saxxmlreader_get_contentHandler(
2828 IVBSAXXMLReader* iface,
2829 IVBSAXContentHandler **ppContentHandler)
2831 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2832 return internal_getContentHandler(This, ppContentHandler, TRUE);
2835 static HRESULT WINAPI saxxmlreader_put_contentHandler(
2836 IVBSAXXMLReader* iface,
2837 IVBSAXContentHandler *contentHandler)
2839 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2840 return internal_putContentHandler(This, contentHandler, TRUE);
2843 static HRESULT WINAPI saxxmlreader_get_dtdHandler(
2844 IVBSAXXMLReader* iface,
2845 IVBSAXDTDHandler **pDTDHandler)
2847 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2848 return internal_getDTDHandler(This, pDTDHandler, TRUE);
2851 static HRESULT WINAPI saxxmlreader_put_dtdHandler(
2852 IVBSAXXMLReader* iface,
2853 IVBSAXDTDHandler *pDTDHandler)
2855 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2856 return internal_putDTDHandler(This, pDTDHandler, TRUE);
2859 static HRESULT WINAPI saxxmlreader_get_errorHandler(
2860 IVBSAXXMLReader* iface,
2861 IVBSAXErrorHandler **pErrorHandler)
2863 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2864 return internal_getErrorHandler(This, pErrorHandler, TRUE);
2867 static HRESULT WINAPI saxxmlreader_put_errorHandler(
2868 IVBSAXXMLReader* iface,
2869 IVBSAXErrorHandler *errorHandler)
2871 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2872 return internal_putErrorHandler(This, errorHandler, TRUE);
2875 static HRESULT WINAPI saxxmlreader_get_baseURL(
2876 IVBSAXXMLReader* iface,
2877 const WCHAR **pBaseUrl)
2879 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2881 FIXME("(%p)->(%p) stub\n", This, pBaseUrl);
2885 static HRESULT WINAPI saxxmlreader_put_baseURL(
2886 IVBSAXXMLReader* iface,
2887 const WCHAR *pBaseUrl)
2889 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2891 FIXME("(%p)->(%s) stub\n", This, debugstr_w(pBaseUrl));
2895 static HRESULT WINAPI saxxmlreader_get_secureBaseURL(
2896 IVBSAXXMLReader* iface,
2897 const WCHAR **pSecureBaseUrl)
2899 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2901 FIXME("(%p)->(%p) stub\n", This, pSecureBaseUrl);
2906 static HRESULT WINAPI saxxmlreader_put_secureBaseURL(
2907 IVBSAXXMLReader* iface,
2908 const WCHAR *secureBaseUrl)
2910 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2912 FIXME("(%p)->(%s) stub\n", This, debugstr_w(secureBaseUrl));
2916 static HRESULT WINAPI saxxmlreader_parse(
2917 IVBSAXXMLReader* iface,
2920 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2921 return internal_parse(This, varInput, TRUE);
2924 static HRESULT WINAPI saxxmlreader_parseURL(
2925 IVBSAXXMLReader* iface,
2928 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2929 return internal_parseURL(This, url, TRUE);
2932 static const struct IVBSAXXMLReaderVtbl VBSAXXMLReaderVtbl =
2934 saxxmlreader_QueryInterface,
2935 saxxmlreader_AddRef,
2936 saxxmlreader_Release,
2937 saxxmlreader_GetTypeInfoCount,
2938 saxxmlreader_GetTypeInfo,
2939 saxxmlreader_GetIDsOfNames,
2940 saxxmlreader_Invoke,
2941 saxxmlreader_getFeature,
2942 saxxmlreader_putFeature,
2943 saxxmlreader_getProperty,
2944 saxxmlreader_putProperty,
2945 saxxmlreader_get_entityResolver,
2946 saxxmlreader_put_entityResolver,
2947 saxxmlreader_get_contentHandler,
2948 saxxmlreader_put_contentHandler,
2949 saxxmlreader_get_dtdHandler,
2950 saxxmlreader_put_dtdHandler,
2951 saxxmlreader_get_errorHandler,
2952 saxxmlreader_put_errorHandler,
2953 saxxmlreader_get_baseURL,
2954 saxxmlreader_put_baseURL,
2955 saxxmlreader_get_secureBaseURL,
2956 saxxmlreader_put_secureBaseURL,
2958 saxxmlreader_parseURL
2961 /*** ISAXXMLReader interface ***/
2962 /*** IUnknown methods ***/
2963 static HRESULT WINAPI isaxxmlreader_QueryInterface(ISAXXMLReader* iface, REFIID riid, void **ppvObject)
2965 saxreader *This = impl_from_ISAXXMLReader( iface );
2966 return saxxmlreader_QueryInterface(&This->IVBSAXXMLReader_iface, riid, ppvObject);
2969 static ULONG WINAPI isaxxmlreader_AddRef(ISAXXMLReader* iface)
2971 saxreader *This = impl_from_ISAXXMLReader( iface );
2972 return saxxmlreader_AddRef(&This->IVBSAXXMLReader_iface);
2975 static ULONG WINAPI isaxxmlreader_Release(ISAXXMLReader* iface)
2977 saxreader *This = impl_from_ISAXXMLReader( iface );
2978 return saxxmlreader_Release(&This->IVBSAXXMLReader_iface);
2981 /*** ISAXXMLReader methods ***/
2982 static HRESULT WINAPI isaxxmlreader_getFeature(
2983 ISAXXMLReader* iface,
2984 const WCHAR *pFeature,
2985 VARIANT_BOOL *pValue)
2987 saxreader *This = impl_from_ISAXXMLReader( iface );
2988 return IVBSAXXMLReader_getFeature(&This->IVBSAXXMLReader_iface, pFeature, pValue);
2991 static HRESULT WINAPI isaxxmlreader_putFeature(
2992 ISAXXMLReader* iface,
2993 const WCHAR *pFeature,
2994 VARIANT_BOOL vfValue)
2996 saxreader *This = impl_from_ISAXXMLReader( iface );
2997 return IVBSAXXMLReader_putFeature(&This->IVBSAXXMLReader_iface, pFeature, vfValue);
3000 static HRESULT WINAPI isaxxmlreader_getProperty(
3001 ISAXXMLReader* iface,
3005 saxreader *This = impl_from_ISAXXMLReader( iface );
3006 return internal_getProperty(This, prop, value, FALSE);
3009 static HRESULT WINAPI isaxxmlreader_putProperty(
3010 ISAXXMLReader* iface,
3014 saxreader *This = impl_from_ISAXXMLReader( iface );
3015 return internal_putProperty(This, pProp, value, FALSE);
3018 static HRESULT WINAPI isaxxmlreader_getEntityResolver(
3019 ISAXXMLReader* iface,
3020 ISAXEntityResolver **ppEntityResolver)
3022 saxreader *This = impl_from_ISAXXMLReader( iface );
3023 return internal_getEntityResolver(This, ppEntityResolver, FALSE);
3026 static HRESULT WINAPI isaxxmlreader_putEntityResolver(
3027 ISAXXMLReader* iface,
3028 ISAXEntityResolver *pEntityResolver)
3030 saxreader *This = impl_from_ISAXXMLReader( iface );
3031 return internal_putEntityResolver(This, pEntityResolver, FALSE);
3034 static HRESULT WINAPI isaxxmlreader_getContentHandler(
3035 ISAXXMLReader* iface,
3036 ISAXContentHandler **pContentHandler)
3038 saxreader *This = impl_from_ISAXXMLReader( iface );
3039 return internal_getContentHandler(This, pContentHandler, FALSE);
3042 static HRESULT WINAPI isaxxmlreader_putContentHandler(
3043 ISAXXMLReader* iface,
3044 ISAXContentHandler *contentHandler)
3046 saxreader *This = impl_from_ISAXXMLReader( iface );
3047 return internal_putContentHandler(This, contentHandler, FALSE);
3050 static HRESULT WINAPI isaxxmlreader_getDTDHandler(
3051 ISAXXMLReader* iface,
3052 ISAXDTDHandler **pDTDHandler)
3054 saxreader *This = impl_from_ISAXXMLReader( iface );
3055 return internal_getDTDHandler(This, pDTDHandler, FALSE);
3058 static HRESULT WINAPI isaxxmlreader_putDTDHandler(
3059 ISAXXMLReader* iface,
3060 ISAXDTDHandler *pDTDHandler)
3062 saxreader *This = impl_from_ISAXXMLReader( iface );
3063 return internal_putDTDHandler(This, pDTDHandler, FALSE);
3066 static HRESULT WINAPI isaxxmlreader_getErrorHandler(
3067 ISAXXMLReader* iface,
3068 ISAXErrorHandler **pErrorHandler)
3070 saxreader *This = impl_from_ISAXXMLReader( iface );
3071 return internal_getErrorHandler(This, pErrorHandler, FALSE);
3074 static HRESULT WINAPI isaxxmlreader_putErrorHandler(
3075 ISAXXMLReader* iface,
3076 ISAXErrorHandler *errorHandler)
3078 saxreader *This = impl_from_ISAXXMLReader( iface );
3079 return internal_putErrorHandler(This, errorHandler, FALSE);
3082 static HRESULT WINAPI isaxxmlreader_getBaseURL(
3083 ISAXXMLReader* iface,
3084 const WCHAR **pBaseUrl)
3086 saxreader *This = impl_from_ISAXXMLReader( iface );
3087 return IVBSAXXMLReader_get_baseURL(&This->IVBSAXXMLReader_iface, pBaseUrl);
3090 static HRESULT WINAPI isaxxmlreader_putBaseURL(
3091 ISAXXMLReader* iface,
3092 const WCHAR *pBaseUrl)
3094 saxreader *This = impl_from_ISAXXMLReader( iface );
3095 return IVBSAXXMLReader_put_baseURL(&This->IVBSAXXMLReader_iface, pBaseUrl);
3098 static HRESULT WINAPI isaxxmlreader_getSecureBaseURL(
3099 ISAXXMLReader* iface,
3100 const WCHAR **pSecureBaseUrl)
3102 saxreader *This = impl_from_ISAXXMLReader( iface );
3103 return IVBSAXXMLReader_get_secureBaseURL(&This->IVBSAXXMLReader_iface, pSecureBaseUrl);
3106 static HRESULT WINAPI isaxxmlreader_putSecureBaseURL(
3107 ISAXXMLReader* iface,
3108 const WCHAR *secureBaseUrl)
3110 saxreader *This = impl_from_ISAXXMLReader( iface );
3111 return IVBSAXXMLReader_put_secureBaseURL(&This->IVBSAXXMLReader_iface, secureBaseUrl);
3114 static HRESULT WINAPI isaxxmlreader_parse(
3115 ISAXXMLReader* iface,
3118 saxreader *This = impl_from_ISAXXMLReader( iface );
3119 return internal_parse(This, varInput, FALSE);
3122 static HRESULT WINAPI isaxxmlreader_parseURL(
3123 ISAXXMLReader* iface,
3126 saxreader *This = impl_from_ISAXXMLReader( iface );
3127 return internal_parseURL(This, url, FALSE);
3130 static const struct ISAXXMLReaderVtbl SAXXMLReaderVtbl =
3132 isaxxmlreader_QueryInterface,
3133 isaxxmlreader_AddRef,
3134 isaxxmlreader_Release,
3135 isaxxmlreader_getFeature,
3136 isaxxmlreader_putFeature,
3137 isaxxmlreader_getProperty,
3138 isaxxmlreader_putProperty,
3139 isaxxmlreader_getEntityResolver,
3140 isaxxmlreader_putEntityResolver,
3141 isaxxmlreader_getContentHandler,
3142 isaxxmlreader_putContentHandler,
3143 isaxxmlreader_getDTDHandler,
3144 isaxxmlreader_putDTDHandler,
3145 isaxxmlreader_getErrorHandler,
3146 isaxxmlreader_putErrorHandler,
3147 isaxxmlreader_getBaseURL,
3148 isaxxmlreader_putBaseURL,
3149 isaxxmlreader_getSecureBaseURL,
3150 isaxxmlreader_putSecureBaseURL,
3151 isaxxmlreader_parse,
3152 isaxxmlreader_parseURL
3155 static const tid_t saxreader_iface_tids[] = {
3156 IVBSAXXMLReader_tid,
3159 static dispex_static_data_t saxreader_dispex = {
3161 IVBSAXXMLReader_tid,
3163 saxreader_iface_tids
3166 HRESULT SAXXMLReader_create(MSXML_VERSION version, IUnknown *outer, LPVOID *ppObj)
3170 TRACE("(%p, %p)\n", outer, ppObj);
3172 reader = heap_alloc( sizeof (*reader) );
3174 return E_OUTOFMEMORY;
3176 reader->IVBSAXXMLReader_iface.lpVtbl = &VBSAXXMLReaderVtbl;
3177 reader->ISAXXMLReader_iface.lpVtbl = &SAXXMLReaderVtbl;
3179 reader->contentHandler = NULL;
3180 reader->vbcontentHandler = NULL;
3181 reader->errorHandler = NULL;
3182 reader->vberrorHandler = NULL;
3183 reader->lexicalHandler = NULL;
3184 reader->vblexicalHandler = NULL;
3185 reader->declHandler = NULL;
3186 reader->vbdeclHandler = NULL;
3187 reader->isParsing = FALSE;
3188 reader->pool.pool = NULL;
3189 reader->pool.index = 0;
3190 reader->pool.len = 0;
3191 reader->features = Namespaces;
3192 reader->version = version;
3194 init_dispex(&reader->dispex, (IUnknown*)&reader->IVBSAXXMLReader_iface, &saxreader_dispex);
3196 memset(&reader->sax, 0, sizeof(xmlSAXHandler));
3197 reader->sax.initialized = XML_SAX2_MAGIC;
3198 reader->sax.startDocument = libxmlStartDocument;
3199 reader->sax.endDocument = libxmlEndDocument;
3200 reader->sax.startElementNs = libxmlStartElementNS;
3201 reader->sax.endElementNs = libxmlEndElementNS;
3202 reader->sax.characters = libxmlCharacters;
3203 reader->sax.setDocumentLocator = libxmlSetDocumentLocator;
3204 reader->sax.comment = libxmlComment;
3205 reader->sax.error = libxmlFatalError;
3206 reader->sax.fatalError = libxmlFatalError;
3207 reader->sax.cdataBlock = libxmlCDataBlock;
3209 *ppObj = &reader->IVBSAXXMLReader_iface;
3211 TRACE("returning iface %p\n", *ppObj);
3218 HRESULT SAXXMLReader_create(MSXML_VERSION version, IUnknown *pUnkOuter, LPVOID *ppObj)
3220 MESSAGE("This program tried to use a SAX XML Reader object, but\n"
3221 "libxml2 support was not present at compile time.\n");