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 >= MSXML6 ? 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 attrs[index].szLocalname = bstr_from_xmlChar(xmlAttributes[index*5]);
1139 attrs[index].szURI = find_element_uri(locator, xmlAttributes[index*5+2]);
1140 attrs[index].szValue = bstr_from_xmlCharN(xmlAttributes[index*5+3],
1141 xmlAttributes[index*5+4]-xmlAttributes[index*5+3]);
1142 attrs[index].szQName = QName_from_xmlChar(xmlAttributes[index*5+1],
1143 xmlAttributes[index*5]);
1149 /*** LibXML callbacks ***/
1150 static void libxmlStartDocument(void *ctx)
1152 saxlocator *This = ctx;
1155 if(This->saxreader->version >= MSXML6)
1157 const xmlChar *p = This->pParserCtxt->input->cur-1;
1158 update_position(This, FALSE);
1159 while(p>This->pParserCtxt->input->base && *p!='>')
1161 if(*p=='\n' || (*p=='\r' && *(p+1)!='\n'))
1166 for(; p>=This->pParserCtxt->input->base && *p!='\n' && *p!='\r'; p--)
1170 if(has_content_handler(This))
1172 if(This->vbInterface)
1173 hr = IVBSAXContentHandler_startDocument(This->saxreader->vbcontentHandler);
1175 hr = ISAXContentHandler_startDocument(This->saxreader->contentHandler);
1177 if (sax_callback_failed(This, hr))
1178 format_error_message_from_id(This, hr);
1182 static void libxmlEndDocument(void *ctx)
1184 saxlocator *This = ctx;
1187 if(This->saxreader->version >= MSXML6) {
1188 update_position(This, FALSE);
1189 if(This->column > 1)
1197 if(This->ret != S_OK) return;
1199 if(has_content_handler(This))
1201 if(This->vbInterface)
1202 hr = IVBSAXContentHandler_endDocument(This->saxreader->vbcontentHandler);
1204 hr = ISAXContentHandler_endDocument(This->saxreader->contentHandler);
1206 if (sax_callback_failed(This, hr))
1207 format_error_message_from_id(This, hr);
1211 static void libxmlStartElementNS(
1213 const xmlChar *localname,
1214 const xmlChar *prefix,
1217 const xmlChar **namespaces,
1220 const xmlChar **attributes)
1222 saxlocator *This = ctx;
1223 element_entry *element;
1226 update_position(This, TRUE);
1227 if(*(This->pParserCtxt->input->cur) == '/')
1229 if(This->saxreader->version < MSXML6)
1232 element = alloc_element_entry(localname, prefix, nb_namespaces, namespaces);
1233 push_element_ns(This, element);
1235 if (has_content_handler(This))
1240 for (i = 0; i < nb_namespaces; i++)
1242 if(This->vbInterface)
1243 hr = IVBSAXContentHandler_startPrefixMapping(
1244 This->saxreader->vbcontentHandler,
1245 &element->ns[i].prefix,
1246 &element->ns[i].uri);
1248 hr = ISAXContentHandler_startPrefixMapping(
1249 This->saxreader->contentHandler,
1250 element->ns[i].prefix,
1251 SysStringLen(element->ns[i].prefix),
1253 SysStringLen(element->ns[i].uri));
1255 if (sax_callback_failed(This, hr))
1257 format_error_message_from_id(This, hr);
1262 uri = find_element_uri(This, URI);
1264 hr = SAXAttributes_populate(This, nb_namespaces, namespaces, nb_attributes, attributes);
1267 if(This->vbInterface)
1268 hr = IVBSAXContentHandler_startElement(This->saxreader->vbcontentHandler,
1269 &uri, &element->local, &element->qname, &This->IVBSAXAttributes_iface);
1271 hr = ISAXContentHandler_startElement(This->saxreader->contentHandler,
1272 uri, SysStringLen(uri),
1273 element->local, SysStringLen(element->local),
1274 element->qname, SysStringLen(element->qname),
1275 &This->ISAXAttributes_iface);
1279 if (sax_callback_failed(This, hr))
1280 format_error_message_from_id(This, hr);
1283 static void libxmlEndElementNS(
1285 const xmlChar *localname,
1286 const xmlChar *prefix,
1289 saxlocator *This = ctx;
1290 element_entry *element;
1296 update_position(This, FALSE);
1297 p = This->pParserCtxt->input->cur;
1298 if(This->saxreader->version >= MSXML6)
1301 while(p>This->pParserCtxt->input->base && *p!='>')
1303 if(*p=='\n' || (*p=='\r' && *(p+1)!='\n'))
1308 else if(*(p-1)!='>' || *(p-2)!='/')
1311 while(p-2>=This->pParserCtxt->input->base
1312 && *(p-2)!='<' && *(p-1)!='/')
1314 if(*p=='\n' || (*p=='\r' && *(p+1)!='\n'))
1320 for(; p>=This->pParserCtxt->input->base && *p!='\n' && *p!='\r'; p--)
1323 uri = find_element_uri(This, URI);
1324 element = pop_element_ns(This);
1326 if (!has_content_handler(This))
1328 This->nb_attributes = 0;
1329 free_element_entry(element);
1333 if(This->vbInterface)
1334 hr = IVBSAXContentHandler_endElement(
1335 This->saxreader->vbcontentHandler,
1336 &uri, &element->local, &element->qname);
1338 hr = ISAXContentHandler_endElement(
1339 This->saxreader->contentHandler,
1340 uri, SysStringLen(uri),
1341 element->local, SysStringLen(element->local),
1342 element->qname, SysStringLen(element->qname));
1344 This->nb_attributes = 0;
1346 if (sax_callback_failed(This, hr))
1348 format_error_message_from_id(This, hr);
1349 free_element_entry(element);
1354 while (iterate_endprefix_index(This, element, &i))
1356 if(This->vbInterface)
1357 hr = IVBSAXContentHandler_endPrefixMapping(
1358 This->saxreader->vbcontentHandler, &element->ns[i].prefix);
1360 hr = ISAXContentHandler_endPrefixMapping(
1361 This->saxreader->contentHandler,
1362 element->ns[i].prefix, SysStringLen(element->ns[i].prefix));
1364 if (sax_callback_failed(This, hr)) break;
1367 if (sax_callback_failed(This, hr))
1368 format_error_message_from_id(This, hr);
1370 free_element_entry(element);
1373 static void libxmlCharacters(
1378 saxlocator *This = ctx;
1382 BOOL lastEvent = FALSE;
1384 if(!(has_content_handler(This))) return;
1386 update_position(This, FALSE);
1387 cur = (xmlChar*)This->pParserCtxt->input->cur;
1388 while(cur>=This->pParserCtxt->input->base && *cur!='>')
1390 if(*cur=='\n' || (*cur=='\r' && *(cur+1)!='\n'))
1395 for(; cur>=This->pParserCtxt->input->base && *cur!='\n' && *cur!='\r'; cur--)
1399 if(*(ch-1)=='\r') cur--;
1404 while(end-ch<len && *end!='\r') end++;
1415 if(This->saxreader->version >= MSXML6)
1419 for(p=cur; p!=end; p++)
1436 Chars = pooled_bstr_from_xmlCharN(&This->saxreader->pool, cur, end-cur);
1437 if(This->vbInterface)
1438 hr = IVBSAXContentHandler_characters(
1439 This->saxreader->vbcontentHandler, &Chars);
1441 hr = ISAXContentHandler_characters(
1442 This->saxreader->contentHandler,
1443 Chars, SysStringLen(Chars));
1445 if (sax_callback_failed(This, hr))
1447 format_error_message_from_id(This, hr);
1451 if(This->saxreader->version < MSXML6)
1452 This->column += end-cur;
1465 if(end-ch == len) break;
1469 static void libxmlSetDocumentLocator(
1471 xmlSAXLocatorPtr loc)
1473 saxlocator *This = ctx;
1476 if(has_content_handler(This))
1478 if(This->vbInterface)
1479 hr = IVBSAXContentHandler_putref_documentLocator(This->saxreader->vbcontentHandler,
1480 &This->IVBSAXLocator_iface);
1482 hr = ISAXContentHandler_putDocumentLocator(This->saxreader->contentHandler,
1483 &This->ISAXLocator_iface);
1487 format_error_message_from_id(This, hr);
1490 static void libxmlComment(void *ctx, const xmlChar *value)
1492 saxlocator *This = ctx;
1495 const xmlChar *p = This->pParserCtxt->input->cur;
1497 update_position(This, FALSE);
1498 while(p-4>=This->pParserCtxt->input->base
1499 && memcmp(p-4, "<!--", sizeof(char[4])))
1501 if(*p=='\n' || (*p=='\r' && *(p+1)!='\n'))
1506 for(; p>=This->pParserCtxt->input->base && *p!='\n' && *p!='\r'; p--)
1509 if(!This->vbInterface && !This->saxreader->lexicalHandler) return;
1510 if(This->vbInterface && !This->saxreader->vblexicalHandler) return;
1512 bValue = pooled_bstr_from_xmlChar(&This->saxreader->pool, value);
1514 if(This->vbInterface)
1515 hr = IVBSAXLexicalHandler_comment(
1516 This->saxreader->vblexicalHandler, &bValue);
1518 hr = ISAXLexicalHandler_comment(
1519 This->saxreader->lexicalHandler,
1520 bValue, SysStringLen(bValue));
1523 format_error_message_from_id(This, hr);
1526 static void libxmlFatalError(void *ctx, const char *msg, ...)
1528 saxlocator *This = ctx;
1534 if(This->ret != S_OK) {
1535 xmlStopParser(This->pParserCtxt);
1539 va_start(args, msg);
1540 vsprintf(message, msg, args);
1543 len = MultiByteToWideChar(CP_UNIXCP, 0, message, -1, NULL, 0);
1544 error = heap_alloc(sizeof(WCHAR)*len);
1547 MultiByteToWideChar(CP_UNIXCP, 0, message, -1, error, len);
1548 TRACE("fatal error for %p: %s\n", This, debugstr_w(error));
1551 if(!has_error_handler(This))
1553 xmlStopParser(This->pParserCtxt);
1559 FIXME("Error handling is not compatible.\n");
1561 if(This->vbInterface)
1563 BSTR bstrError = SysAllocString(error);
1564 IVBSAXErrorHandler_fatalError(This->saxreader->vberrorHandler, &This->IVBSAXLocator_iface,
1565 &bstrError, E_FAIL);
1566 SysFreeString(bstrError);
1569 ISAXErrorHandler_fatalError(This->saxreader->errorHandler, &This->ISAXLocator_iface,
1574 xmlStopParser(This->pParserCtxt);
1578 static void libxmlCDataBlock(void *ctx, const xmlChar *value, int len)
1580 saxlocator *This = ctx;
1582 xmlChar *beg = (xmlChar*)This->pParserCtxt->input->cur-len;
1586 BOOL lastEvent = FALSE, change;
1588 update_position(This, FALSE);
1589 while(beg-9>=This->pParserCtxt->input->base
1590 && memcmp(beg-9, "<![CDATA[", sizeof(char[9])))
1592 if(*beg=='\n' || (*beg=='\r' && *(beg+1)!='\n'))
1597 for(; beg>=This->pParserCtxt->input->base && *beg!='\n' && *beg!='\r'; beg--)
1600 if(This->vbInterface && This->saxreader->vblexicalHandler)
1601 hr = IVBSAXLexicalHandler_startCDATA(This->saxreader->vblexicalHandler);
1602 if(!This->vbInterface && This->saxreader->lexicalHandler)
1603 hr = ISAXLexicalHandler_startCDATA(This->saxreader->lexicalHandler);
1607 format_error_message_from_id(This, hr);
1611 realLen = This->pParserCtxt->input->cur-beg-3;
1617 while(end-beg<realLen && *end!='\r') end++;
1618 if(end-beg==realLen)
1623 else if(end-beg==realLen-1 && *end=='\r' && *(end+1)=='\n')
1626 if(*end == '\r') change = TRUE;
1627 else change = FALSE;
1629 if(change) *end = '\n';
1631 if(has_content_handler(This))
1633 Chars = pooled_bstr_from_xmlCharN(&This->saxreader->pool, cur, end-cur+1);
1634 if(This->vbInterface)
1635 hr = IVBSAXContentHandler_characters(
1636 This->saxreader->vbcontentHandler, &Chars);
1638 hr = ISAXContentHandler_characters(
1639 This->saxreader->contentHandler,
1640 Chars, SysStringLen(Chars));
1643 if(change) *end = '\r';
1648 This->column += end-cur+2;
1653 if(This->vbInterface && This->saxreader->vblexicalHandler)
1654 hr = IVBSAXLexicalHandler_endCDATA(This->saxreader->vblexicalHandler);
1655 if(!This->vbInterface && This->saxreader->lexicalHandler)
1656 hr = ISAXLexicalHandler_endCDATA(This->saxreader->lexicalHandler);
1659 format_error_message_from_id(This, hr);
1661 This->column += 4+end-cur;
1664 /*** IVBSAXLocator interface ***/
1665 /*** IUnknown methods ***/
1666 static HRESULT WINAPI ivbsaxlocator_QueryInterface(IVBSAXLocator* iface, REFIID riid, void **ppvObject)
1668 saxlocator *This = impl_from_IVBSAXLocator( iface );
1670 TRACE("%p %s %p\n", This, debugstr_guid( riid ), ppvObject);
1674 if ( IsEqualGUID( riid, &IID_IUnknown ) ||
1675 IsEqualGUID( riid, &IID_IDispatch) ||
1676 IsEqualGUID( riid, &IID_IVBSAXLocator ))
1680 else if ( IsEqualGUID( riid, &IID_IVBSAXAttributes ))
1682 *ppvObject = &This->IVBSAXAttributes_iface;
1686 FIXME("interface %s not implemented\n", debugstr_guid(riid));
1687 return E_NOINTERFACE;
1690 IVBSAXLocator_AddRef( iface );
1695 static ULONG WINAPI ivbsaxlocator_AddRef(IVBSAXLocator* iface)
1697 saxlocator *This = impl_from_IVBSAXLocator( iface );
1698 TRACE("%p\n", This );
1699 return InterlockedIncrement( &This->ref );
1702 static ULONG WINAPI ivbsaxlocator_Release(
1703 IVBSAXLocator* iface)
1705 saxlocator *This = impl_from_IVBSAXLocator( iface );
1706 return ISAXLocator_Release((ISAXLocator*)&This->IVBSAXLocator_iface);
1709 /*** IDispatch methods ***/
1710 static HRESULT WINAPI ivbsaxlocator_GetTypeInfoCount( IVBSAXLocator *iface, UINT* pctinfo )
1712 saxlocator *This = impl_from_IVBSAXLocator( iface );
1714 TRACE("(%p)->(%p)\n", This, pctinfo);
1721 static HRESULT WINAPI ivbsaxlocator_GetTypeInfo(
1722 IVBSAXLocator *iface,
1723 UINT iTInfo, LCID lcid, ITypeInfo** ppTInfo )
1725 saxlocator *This = impl_from_IVBSAXLocator( iface );
1728 TRACE("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo);
1730 hr = get_typeinfo(IVBSAXLocator_tid, ppTInfo);
1735 static HRESULT WINAPI ivbsaxlocator_GetIDsOfNames(
1736 IVBSAXLocator *iface,
1738 LPOLESTR* rgszNames,
1743 saxlocator *This = impl_from_IVBSAXLocator( iface );
1744 ITypeInfo *typeinfo;
1747 TRACE("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames, cNames,
1750 if(!rgszNames || cNames == 0 || !rgDispId)
1751 return E_INVALIDARG;
1753 hr = get_typeinfo(IVBSAXLocator_tid, &typeinfo);
1756 hr = ITypeInfo_GetIDsOfNames(typeinfo, rgszNames, cNames, rgDispId);
1757 ITypeInfo_Release(typeinfo);
1763 static HRESULT WINAPI ivbsaxlocator_Invoke(
1764 IVBSAXLocator *iface,
1765 DISPID dispIdMember,
1769 DISPPARAMS* pDispParams,
1770 VARIANT* pVarResult,
1771 EXCEPINFO* pExcepInfo,
1774 saxlocator *This = impl_from_IVBSAXLocator( iface );
1775 ITypeInfo *typeinfo;
1778 TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
1779 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
1781 hr = get_typeinfo(IVBSAXLocator_tid, &typeinfo);
1784 hr = ITypeInfo_Invoke(typeinfo, &This->IVBSAXLocator_iface, dispIdMember, wFlags,
1785 pDispParams, pVarResult, pExcepInfo, puArgErr);
1786 ITypeInfo_Release(typeinfo);
1792 /*** IVBSAXLocator methods ***/
1793 static HRESULT WINAPI ivbsaxlocator_get_columnNumber(
1794 IVBSAXLocator* iface,
1797 saxlocator *This = impl_from_IVBSAXLocator( iface );
1798 return ISAXLocator_getColumnNumber((ISAXLocator*)&This->IVBSAXLocator_iface, pnColumn);
1801 static HRESULT WINAPI ivbsaxlocator_get_lineNumber(
1802 IVBSAXLocator* iface,
1805 saxlocator *This = impl_from_IVBSAXLocator( iface );
1806 return ISAXLocator_getLineNumber((ISAXLocator*)&This->IVBSAXLocator_iface, pnLine);
1809 static HRESULT WINAPI ivbsaxlocator_get_publicId(
1810 IVBSAXLocator* iface,
1813 saxlocator *This = impl_from_IVBSAXLocator( iface );
1814 return ISAXLocator_getPublicId((ISAXLocator*)&This->IVBSAXLocator_iface,
1815 (const WCHAR**)publicId);
1818 static HRESULT WINAPI ivbsaxlocator_get_systemId(
1819 IVBSAXLocator* iface,
1822 saxlocator *This = impl_from_IVBSAXLocator( iface );
1823 return ISAXLocator_getSystemId((ISAXLocator*)&This->IVBSAXLocator_iface,
1824 (const WCHAR**)systemId);
1827 static const struct IVBSAXLocatorVtbl VBSAXLocatorVtbl =
1829 ivbsaxlocator_QueryInterface,
1830 ivbsaxlocator_AddRef,
1831 ivbsaxlocator_Release,
1832 ivbsaxlocator_GetTypeInfoCount,
1833 ivbsaxlocator_GetTypeInfo,
1834 ivbsaxlocator_GetIDsOfNames,
1835 ivbsaxlocator_Invoke,
1836 ivbsaxlocator_get_columnNumber,
1837 ivbsaxlocator_get_lineNumber,
1838 ivbsaxlocator_get_publicId,
1839 ivbsaxlocator_get_systemId
1842 /*** ISAXLocator interface ***/
1843 /*** IUnknown methods ***/
1844 static HRESULT WINAPI isaxlocator_QueryInterface(ISAXLocator* iface, REFIID riid, void **ppvObject)
1846 saxlocator *This = impl_from_ISAXLocator( iface );
1848 TRACE("%p %s %p\n", This, debugstr_guid( riid ), ppvObject );
1852 if ( IsEqualGUID( riid, &IID_IUnknown ) ||
1853 IsEqualGUID( riid, &IID_ISAXLocator ))
1857 else if ( IsEqualGUID( riid, &IID_ISAXAttributes ))
1859 *ppvObject = &This->ISAXAttributes_iface;
1863 FIXME("interface %s not implemented\n", debugstr_guid(riid));
1864 return E_NOINTERFACE;
1867 ISAXLocator_AddRef( iface );
1872 static ULONG WINAPI isaxlocator_AddRef(ISAXLocator* iface)
1874 saxlocator *This = impl_from_ISAXLocator( iface );
1875 ULONG ref = InterlockedIncrement( &This->ref );
1876 TRACE("(%p)->(%d)\n", This, ref);
1880 static ULONG WINAPI isaxlocator_Release(
1883 saxlocator *This = impl_from_ISAXLocator( iface );
1884 LONG ref = InterlockedDecrement( &This->ref );
1886 TRACE("(%p)->(%d)\n", This, ref );
1890 element_entry *element, *element2;
1893 SysFreeString(This->publicId);
1894 SysFreeString(This->systemId);
1895 SysFreeString(This->namespaceUri);
1897 for(index=0; index<This->nb_attributes; index++)
1899 SysFreeString(This->attributes[index].szLocalname);
1900 SysFreeString(This->attributes[index].szValue);
1901 SysFreeString(This->attributes[index].szQName);
1903 heap_free(This->attributes);
1906 LIST_FOR_EACH_ENTRY_SAFE(element, element2, &This->elements, element_entry, entry)
1908 list_remove(&element->entry);
1909 free_element_entry(element);
1912 ISAXXMLReader_Release(&This->saxreader->ISAXXMLReader_iface);
1919 /*** ISAXLocator methods ***/
1920 static HRESULT WINAPI isaxlocator_getColumnNumber(
1924 saxlocator *This = impl_from_ISAXLocator( iface );
1926 *pnColumn = This->column;
1930 static HRESULT WINAPI isaxlocator_getLineNumber(
1934 saxlocator *This = impl_from_ISAXLocator( iface );
1936 *pnLine = This->line;
1940 static HRESULT WINAPI isaxlocator_getPublicId(
1942 const WCHAR ** ppwchPublicId)
1945 saxlocator *This = impl_from_ISAXLocator( iface );
1947 SysFreeString(This->publicId);
1949 publicId = bstr_from_xmlChar(xmlSAX2GetPublicId(This->pParserCtxt));
1950 if(SysStringLen(publicId))
1951 This->publicId = (WCHAR*)&publicId;
1954 SysFreeString(publicId);
1955 This->publicId = NULL;
1958 *ppwchPublicId = This->publicId;
1962 static HRESULT WINAPI isaxlocator_getSystemId(
1964 const WCHAR ** ppwchSystemId)
1967 saxlocator *This = impl_from_ISAXLocator( iface );
1969 SysFreeString(This->systemId);
1971 systemId = bstr_from_xmlChar(xmlSAX2GetSystemId(This->pParserCtxt));
1972 if(SysStringLen(systemId))
1973 This->systemId = (WCHAR*)&systemId;
1976 SysFreeString(systemId);
1977 This->systemId = NULL;
1980 *ppwchSystemId = This->systemId;
1984 static const struct ISAXLocatorVtbl SAXLocatorVtbl =
1986 isaxlocator_QueryInterface,
1988 isaxlocator_Release,
1989 isaxlocator_getColumnNumber,
1990 isaxlocator_getLineNumber,
1991 isaxlocator_getPublicId,
1992 isaxlocator_getSystemId
1995 static HRESULT SAXLocator_create(saxreader *reader, saxlocator **ppsaxlocator, BOOL vbInterface)
1997 static const WCHAR w3xmlns[] = { 'h','t','t','p',':','/','/', 'w','w','w','.','w','3','.',
1998 'o','r','g','/','2','0','0','0','/','x','m','l','n','s','/',0 };
2000 saxlocator *locator;
2002 locator = heap_alloc( sizeof (*locator) );
2004 return E_OUTOFMEMORY;
2006 locator->IVBSAXLocator_iface.lpVtbl = &VBSAXLocatorVtbl;
2007 locator->ISAXLocator_iface.lpVtbl = &SAXLocatorVtbl;
2008 locator->IVBSAXAttributes_iface.lpVtbl = &ivbsaxattributes_vtbl;
2009 locator->ISAXAttributes_iface.lpVtbl = &isaxattributes_vtbl;
2011 locator->vbInterface = vbInterface;
2013 locator->saxreader = reader;
2014 ISAXXMLReader_AddRef(&reader->ISAXXMLReader_iface);
2016 locator->pParserCtxt = NULL;
2017 locator->publicId = NULL;
2018 locator->systemId = NULL;
2019 locator->line = (reader->version>=MSXML6 ? 1 : 0);
2020 locator->column = 0;
2021 locator->ret = S_OK;
2022 if(locator->saxreader->version >= MSXML6)
2023 locator->namespaceUri = SysAllocString(w3xmlns);
2025 locator->namespaceUri = SysAllocStringLen(NULL, 0);
2026 if(!locator->namespaceUri)
2028 ISAXXMLReader_Release(&reader->ISAXXMLReader_iface);
2030 return E_OUTOFMEMORY;
2033 locator->attributesSize = 8;
2034 locator->nb_attributes = 0;
2035 locator->attributes = heap_alloc(sizeof(struct _attributes)*locator->attributesSize);
2036 if(!locator->attributes)
2038 ISAXXMLReader_Release(&reader->ISAXXMLReader_iface);
2039 SysFreeString(locator->namespaceUri);
2041 return E_OUTOFMEMORY;
2044 list_init(&locator->elements);
2046 *ppsaxlocator = locator;
2048 TRACE("returning %p\n", *ppsaxlocator);
2053 /*** SAXXMLReader internal functions ***/
2054 static HRESULT internal_parseBuffer(saxreader *This, const char *buffer, int size, BOOL vbInterface)
2056 xmlCharEncoding encoding = XML_CHAR_ENCODING_NONE;
2057 xmlChar *enc_name = NULL;
2058 saxlocator *locator;
2061 hr = SAXLocator_create(This, &locator, vbInterface);
2067 const unsigned char *buff = (unsigned char*)buffer;
2069 encoding = xmlDetectCharEncoding((xmlChar*)buffer, 4);
2070 enc_name = (xmlChar*)xmlGetCharEncodingName(encoding);
2071 TRACE("detected encoding: %s\n", enc_name);
2072 /* skip BOM, parser won't switch encodings and so won't skip it on its own */
2073 if ((encoding == XML_CHAR_ENCODING_UTF8) &&
2074 buff[0] == 0xEF && buff[1] == 0xBB && buff[2] == 0xBF)
2081 locator->pParserCtxt = xmlCreateMemoryParserCtxt(buffer, size);
2082 if(!locator->pParserCtxt)
2084 ISAXLocator_Release(&locator->ISAXLocator_iface);
2088 if (encoding == XML_CHAR_ENCODING_UTF8)
2089 locator->pParserCtxt->encoding = xmlStrdup(enc_name);
2091 xmlFree(locator->pParserCtxt->sax);
2092 locator->pParserCtxt->sax = &locator->saxreader->sax;
2093 locator->pParserCtxt->userData = locator;
2095 This->isParsing = TRUE;
2096 if(xmlParseDocument(locator->pParserCtxt)==-1 && locator->ret==S_OK)
2100 This->isParsing = FALSE;
2102 if(locator->pParserCtxt)
2104 locator->pParserCtxt->sax = NULL;
2105 xmlFreeParserCtxt(locator->pParserCtxt);
2106 locator->pParserCtxt = NULL;
2109 ISAXLocator_Release(&locator->ISAXLocator_iface);
2113 static HRESULT internal_parseStream(saxreader *This, IStream *stream, BOOL vbInterface)
2115 saxlocator *locator;
2122 hr = IStream_Read(stream, data, sizeof(data), &dataRead);
2123 if(FAILED(hr)) return hr;
2125 hr = SAXLocator_create(This, &locator, vbInterface);
2126 if(FAILED(hr)) return hr;
2128 locator->pParserCtxt = xmlCreatePushParserCtxt(
2129 &locator->saxreader->sax, locator,
2130 data, dataRead, NULL);
2131 if(!locator->pParserCtxt)
2133 ISAXLocator_Release(&locator->ISAXLocator_iface);
2137 This->isParsing = TRUE;
2139 if(dataRead != sizeof(data))
2141 ret = xmlParseChunk(locator->pParserCtxt, data, 0, 1);
2142 hr = ret!=XML_ERR_OK && locator->ret==S_OK ? E_FAIL : locator->ret;
2149 hr = IStream_Read(stream, data, sizeof(data), &dataRead);
2150 if (FAILED(hr)) break;
2152 ret = xmlParseChunk(locator->pParserCtxt, data, dataRead, 0);
2153 hr = ret!=XML_ERR_OK && locator->ret==S_OK ? E_FAIL : locator->ret;
2155 if (hr != S_OK) break;
2157 if (dataRead != sizeof(data))
2159 ret = xmlParseChunk(locator->pParserCtxt, data, 0, 1);
2160 hr = ret!=XML_ERR_OK && locator->ret==S_OK ? E_FAIL : locator->ret;
2166 This->isParsing = FALSE;
2168 xmlFreeParserCtxt(locator->pParserCtxt);
2169 locator->pParserCtxt = NULL;
2170 ISAXLocator_Release(&locator->ISAXLocator_iface);
2174 static HRESULT internal_getEntityResolver(
2176 void *pEntityResolver,
2179 FIXME("(%p)->(%p) stub\n", This, pEntityResolver);
2183 static HRESULT internal_putEntityResolver(
2185 void *pEntityResolver,
2188 FIXME("(%p)->(%p) stub\n", This, pEntityResolver);
2192 static HRESULT internal_getContentHandler(
2194 void *pContentHandler,
2197 TRACE("(%p)->(%p)\n", This, pContentHandler);
2198 if(pContentHandler == NULL)
2200 if((vbInterface && This->vbcontentHandler)
2201 || (!vbInterface && This->contentHandler))
2204 IVBSAXContentHandler_AddRef(This->vbcontentHandler);
2206 ISAXContentHandler_AddRef(This->contentHandler);
2208 if(vbInterface) *(IVBSAXContentHandler**)pContentHandler =
2209 This->vbcontentHandler;
2210 else *(ISAXContentHandler**)pContentHandler = This->contentHandler;
2215 static HRESULT internal_putContentHandler(
2217 void *contentHandler,
2220 TRACE("(%p)->(%p)\n", This, contentHandler);
2224 IVBSAXContentHandler_AddRef((IVBSAXContentHandler*)contentHandler);
2226 ISAXContentHandler_AddRef((ISAXContentHandler*)contentHandler);
2228 if((vbInterface && This->vbcontentHandler)
2229 || (!vbInterface && This->contentHandler))
2232 IVBSAXContentHandler_Release(This->vbcontentHandler);
2234 ISAXContentHandler_Release(This->contentHandler);
2237 This->vbcontentHandler = contentHandler;
2239 This->contentHandler = contentHandler;
2244 static HRESULT internal_getDTDHandler(
2249 FIXME("(%p)->(%p) stub\n", This, pDTDHandler);
2253 static HRESULT internal_putDTDHandler(
2258 FIXME("(%p)->(%p) stub\n", This, pDTDHandler);
2262 static HRESULT internal_getErrorHandler(
2264 void *pErrorHandler,
2267 TRACE("(%p)->(%p)\n", This, pErrorHandler);
2268 if(pErrorHandler == NULL)
2271 if(vbInterface && This->vberrorHandler)
2272 IVBSAXErrorHandler_AddRef(This->vberrorHandler);
2273 else if(!vbInterface && This->errorHandler)
2274 ISAXErrorHandler_AddRef(This->errorHandler);
2277 *(IVBSAXErrorHandler**)pErrorHandler = This->vberrorHandler;
2279 *(ISAXErrorHandler**)pErrorHandler = This->errorHandler;
2285 static HRESULT internal_putErrorHandler(
2290 TRACE("(%p)->(%p)\n", This, errorHandler);
2294 IVBSAXErrorHandler_AddRef((IVBSAXErrorHandler*)errorHandler);
2296 ISAXErrorHandler_AddRef((ISAXErrorHandler*)errorHandler);
2299 if(vbInterface && This->vberrorHandler)
2300 IVBSAXErrorHandler_Release(This->vberrorHandler);
2301 else if(!vbInterface && This->errorHandler)
2302 ISAXErrorHandler_Release(This->errorHandler);
2305 This->vberrorHandler = errorHandler;
2307 This->errorHandler = errorHandler;
2313 static HRESULT internal_parse(
2320 TRACE("(%p)->(%s)\n", This, debugstr_variant(&varInput));
2322 /* Dispose of the BSTRs in the pool from a prior run, if any. */
2323 free_bstr_pool(&This->pool);
2325 switch(V_VT(&varInput))
2328 hr = internal_parseBuffer(This, (const char*)V_BSTR(&varInput),
2329 SysStringByteLen(V_BSTR(&varInput)), vbInterface);
2331 case VT_ARRAY|VT_UI1: {
2333 LONG lBound, uBound;
2336 hr = SafeArrayGetLBound(V_ARRAY(&varInput), 1, &lBound);
2337 if(hr != S_OK) break;
2338 hr = SafeArrayGetUBound(V_ARRAY(&varInput), 1, &uBound);
2339 if(hr != S_OK) break;
2340 dataRead = (uBound-lBound)*SafeArrayGetElemsize(V_ARRAY(&varInput));
2341 hr = SafeArrayAccessData(V_ARRAY(&varInput), &pSAData);
2342 if(hr != S_OK) break;
2343 hr = internal_parseBuffer(This, pSAData, dataRead, vbInterface);
2344 SafeArrayUnaccessData(V_ARRAY(&varInput));
2349 IPersistStream *persistStream;
2350 IStream *stream = NULL;
2351 IXMLDOMDocument *xmlDoc;
2353 if(IUnknown_QueryInterface(V_UNKNOWN(&varInput),
2354 &IID_IXMLDOMDocument, (void**)&xmlDoc) == S_OK)
2358 IXMLDOMDocument_get_xml(xmlDoc, &bstrData);
2359 hr = internal_parseBuffer(This, (const char*)bstrData,
2360 SysStringByteLen(bstrData), vbInterface);
2361 IXMLDOMDocument_Release(xmlDoc);
2362 SysFreeString(bstrData);
2366 if(IUnknown_QueryInterface(V_UNKNOWN(&varInput),
2367 &IID_IPersistStream, (void**)&persistStream) == S_OK)
2369 hr = CreateStreamOnHGlobal(NULL, TRUE, &stream);
2372 IPersistStream_Release(persistStream);
2376 hr = IPersistStream_Save(persistStream, stream, TRUE);
2377 IPersistStream_Release(persistStream);
2380 IStream_Release(stream);
2385 if(stream || IUnknown_QueryInterface(V_UNKNOWN(&varInput),
2386 &IID_IStream, (void**)&stream) == S_OK)
2388 hr = internal_parseStream(This, stream, vbInterface);
2389 IStream_Release(stream);
2394 WARN("vt %d not implemented\n", V_VT(&varInput));
2401 static HRESULT internal_vbonDataAvailable(void *obj, char *ptr, DWORD len)
2403 saxreader *This = obj;
2405 return internal_parseBuffer(This, ptr, len, TRUE);
2408 static HRESULT internal_onDataAvailable(void *obj, char *ptr, DWORD len)
2410 saxreader *This = obj;
2412 return internal_parseBuffer(This, ptr, len, FALSE);
2415 static HRESULT internal_parseURL(
2423 TRACE("(%p)->(%s)\n", This, debugstr_w(url));
2425 if(vbInterface) hr = bind_url(url, internal_vbonDataAvailable, This, &bsc);
2426 else hr = bind_url(url, internal_onDataAvailable, This, &bsc);
2431 return detach_bsc(bsc);
2434 static HRESULT internal_putProperty(
2440 TRACE("(%p)->(%s %s)\n", This, debugstr_w(prop), debugstr_variant(&value));
2442 if(!memcmp(prop, PropertyDeclHandlerW, sizeof(PropertyDeclHandlerW)))
2444 if(This->isParsing) return E_FAIL;
2446 switch (V_VT(&value))
2451 if (This->vbdeclHandler)
2453 IVBSAXDeclHandler_Release(This->vbdeclHandler);
2454 This->vbdeclHandler = NULL;
2458 if (This->declHandler)
2460 ISAXDeclHandler_Release(This->declHandler);
2461 This->declHandler = NULL;
2465 if (V_UNKNOWN(&value)) IUnknown_AddRef(V_UNKNOWN(&value));
2467 if ((vbInterface && This->vbdeclHandler) ||
2468 (!vbInterface && This->declHandler))
2471 IVBSAXDeclHandler_Release(This->vbdeclHandler);
2473 ISAXDeclHandler_Release(This->declHandler);
2477 This->vbdeclHandler = (IVBSAXDeclHandler*)V_UNKNOWN(&value);
2479 This->declHandler = (ISAXDeclHandler*)V_UNKNOWN(&value);
2482 return E_INVALIDARG;
2488 if(!memcmp(prop, PropertyLexicalHandlerW, sizeof(PropertyLexicalHandlerW)))
2490 if(This->isParsing) return E_FAIL;
2492 switch (V_VT(&value))
2497 if (This->vblexicalHandler)
2499 IVBSAXLexicalHandler_Release(This->vblexicalHandler);
2500 This->vblexicalHandler = NULL;
2504 if (This->lexicalHandler)
2506 ISAXLexicalHandler_Release(This->lexicalHandler);
2507 This->lexicalHandler = NULL;
2511 if (V_UNKNOWN(&value)) IUnknown_AddRef(V_UNKNOWN(&value));
2513 if ((vbInterface && This->vblexicalHandler) ||
2514 (!vbInterface && This->lexicalHandler))
2517 IVBSAXLexicalHandler_Release(This->vblexicalHandler);
2519 ISAXLexicalHandler_Release(This->lexicalHandler);
2523 This->vblexicalHandler = (IVBSAXLexicalHandler*)V_UNKNOWN(&value);
2525 This->lexicalHandler = (ISAXLexicalHandler*)V_UNKNOWN(&value);
2528 return E_INVALIDARG;
2534 if(!memcmp(prop, PropertyMaxXMLSizeW, sizeof(PropertyMaxXMLSizeW)))
2536 if (V_VT(&value) == VT_I4 && V_I4(&value) == 0) return S_OK;
2537 FIXME("(%p)->(%s): max-xml-size unsupported\n", This, debugstr_variant(&value));
2541 if(!memcmp(prop, PropertyMaxElementDepthW, sizeof(PropertyMaxElementDepthW)))
2543 if (V_VT(&value) == VT_I4 && V_I4(&value) == 0) return S_OK;
2544 FIXME("(%p)->(%s): max-element-depth unsupported\n", This, debugstr_variant(&value));
2548 FIXME("(%p)->(%s:%s): unsupported property\n", This, debugstr_w(prop), debugstr_variant(&value));
2550 if(!memcmp(prop, PropertyCharsetW, sizeof(PropertyCharsetW)))
2553 if(!memcmp(prop, PropertyDomNodeW, sizeof(PropertyDomNodeW)))
2556 if(!memcmp(prop, PropertyInputSourceW, sizeof(PropertyInputSourceW)))
2559 if(!memcmp(prop, PropertySchemaDeclHandlerW, sizeof(PropertySchemaDeclHandlerW)))
2562 if(!memcmp(prop, PropertyXMLDeclEncodingW, sizeof(PropertyXMLDeclEncodingW)))
2565 if(!memcmp(prop, PropertyXMLDeclStandaloneW, sizeof(PropertyXMLDeclStandaloneW)))
2568 if(!memcmp(prop, PropertyXMLDeclVersionW, sizeof(PropertyXMLDeclVersionW)))
2571 return E_INVALIDARG;
2574 static HRESULT internal_getProperty(const saxreader* This, const WCHAR *prop, VARIANT *value, BOOL vb)
2576 TRACE("(%p)->(%s)\n", This, debugstr_w(prop));
2578 if (!value) return E_POINTER;
2580 if (!memcmp(PropertyLexicalHandlerW, prop, sizeof(PropertyLexicalHandlerW)))
2582 V_VT(value) = VT_UNKNOWN;
2583 V_UNKNOWN(value) = vb ? (IUnknown*)This->vblexicalHandler : (IUnknown*)This->lexicalHandler;
2584 if (V_UNKNOWN(value)) IUnknown_AddRef(V_UNKNOWN(value));
2588 if (!memcmp(PropertyDeclHandlerW, prop, sizeof(PropertyDeclHandlerW)))
2590 V_VT(value) = VT_UNKNOWN;
2591 V_UNKNOWN(value) = vb ? (IUnknown*)This->vbdeclHandler : (IUnknown*)This->declHandler;
2592 if (V_UNKNOWN(value)) IUnknown_AddRef(V_UNKNOWN(value));
2596 FIXME("(%p)->(%s) unsupported property\n", This, debugstr_w(prop));
2601 /*** IVBSAXXMLReader interface ***/
2602 /*** IUnknown methods ***/
2603 static HRESULT WINAPI saxxmlreader_QueryInterface(IVBSAXXMLReader* iface, REFIID riid, void **ppvObject)
2605 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2607 TRACE("%p %s %p\n", This, debugstr_guid( riid ), ppvObject );
2611 if ( IsEqualGUID( riid, &IID_IUnknown ) ||
2612 IsEqualGUID( riid, &IID_IDispatch ) ||
2613 IsEqualGUID( riid, &IID_IVBSAXXMLReader ))
2617 else if( IsEqualGUID( riid, &IID_ISAXXMLReader ))
2619 *ppvObject = &This->ISAXXMLReader_iface;
2621 else if (dispex_query_interface(&This->dispex, riid, ppvObject))
2623 return *ppvObject ? S_OK : E_NOINTERFACE;
2627 FIXME("interface %s not implemented\n", debugstr_guid(riid));
2628 return E_NOINTERFACE;
2631 IVBSAXXMLReader_AddRef( iface );
2636 static ULONG WINAPI saxxmlreader_AddRef(IVBSAXXMLReader* iface)
2638 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2639 TRACE("%p\n", This );
2640 return InterlockedIncrement( &This->ref );
2643 static ULONG WINAPI saxxmlreader_Release(
2644 IVBSAXXMLReader* iface)
2646 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2649 TRACE("%p\n", This );
2651 ref = InterlockedDecrement( &This->ref );
2654 if(This->contentHandler)
2655 ISAXContentHandler_Release(This->contentHandler);
2657 if(This->vbcontentHandler)
2658 IVBSAXContentHandler_Release(This->vbcontentHandler);
2660 if(This->errorHandler)
2661 ISAXErrorHandler_Release(This->errorHandler);
2663 if(This->vberrorHandler)
2664 IVBSAXErrorHandler_Release(This->vberrorHandler);
2666 if(This->lexicalHandler)
2667 ISAXLexicalHandler_Release(This->lexicalHandler);
2669 if(This->vblexicalHandler)
2670 IVBSAXLexicalHandler_Release(This->vblexicalHandler);
2672 if(This->declHandler)
2673 ISAXDeclHandler_Release(This->declHandler);
2675 if(This->vbdeclHandler)
2676 IVBSAXDeclHandler_Release(This->vbdeclHandler);
2678 free_bstr_pool(&This->pool);
2680 release_dispex(&This->dispex);
2687 static HRESULT WINAPI saxxmlreader_GetTypeInfoCount( IVBSAXXMLReader *iface, UINT* pctinfo )
2689 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2690 return IDispatchEx_GetTypeInfoCount(&This->dispex.IDispatchEx_iface, pctinfo);
2693 static HRESULT WINAPI saxxmlreader_GetTypeInfo(
2694 IVBSAXXMLReader *iface,
2695 UINT iTInfo, LCID lcid, ITypeInfo** ppTInfo )
2697 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2698 return IDispatchEx_GetTypeInfo(&This->dispex.IDispatchEx_iface,
2699 iTInfo, lcid, ppTInfo);
2702 static HRESULT WINAPI saxxmlreader_GetIDsOfNames(
2703 IVBSAXXMLReader *iface,
2705 LPOLESTR* rgszNames,
2710 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2711 return IDispatchEx_GetIDsOfNames(&This->dispex.IDispatchEx_iface,
2712 riid, rgszNames, cNames, lcid, rgDispId);
2715 static HRESULT WINAPI saxxmlreader_Invoke(
2716 IVBSAXXMLReader *iface,
2717 DISPID dispIdMember,
2721 DISPPARAMS* pDispParams,
2722 VARIANT* pVarResult,
2723 EXCEPINFO* pExcepInfo,
2726 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2727 return IDispatchEx_Invoke(&This->dispex.IDispatchEx_iface,
2728 dispIdMember, riid, lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
2731 /*** IVBSAXXMLReader methods ***/
2732 static HRESULT WINAPI saxxmlreader_getFeature(
2733 IVBSAXXMLReader* iface,
2734 const WCHAR *feature,
2735 VARIANT_BOOL *value)
2737 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2739 if (!strcmpW(FeatureNamespacesW, feature))
2740 return get_feature_value(This, Namespaces, value);
2742 FIXME("(%p)->(%s %p) stub\n", This, debugstr_w(feature), value);
2746 static HRESULT WINAPI saxxmlreader_putFeature(
2747 IVBSAXXMLReader* iface,
2748 const WCHAR *feature,
2751 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2753 TRACE("(%p)->(%s %x)\n", This, debugstr_w(feature), value);
2755 if (!strcmpW(FeatureExternalGeneralEntitiesW, feature) && value == VARIANT_FALSE)
2756 return set_feature_value(This, ExternalGeneralEntities, value);
2758 if (!strcmpW(FeatureExternalParameterEntitiesW, feature) && value == VARIANT_FALSE)
2759 return set_feature_value(This, ExternalParameterEntities, value);
2761 if (!strcmpW(FeatureLexicalHandlerParEntitiesW, feature))
2763 FIXME("(%p)->(%s %x) stub\n", This, debugstr_w(feature), value);
2764 return set_feature_value(This, LexicalHandlerParEntities, value);
2767 if (!strcmpW(FeatureProhibitDTDW, feature))
2769 FIXME("(%p)->(%s %x) stub\n", This, debugstr_w(feature), value);
2770 return set_feature_value(This, ProhibitDTD, value);
2773 if (!strcmpW(FeatureNamespacesW, feature) && value == VARIANT_TRUE)
2774 return set_feature_value(This, Namespaces, value);
2776 FIXME("(%p)->(%s %x) stub\n", This, debugstr_w(feature), value);
2780 static HRESULT WINAPI saxxmlreader_getProperty(
2781 IVBSAXXMLReader* iface,
2785 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2786 return internal_getProperty(This, prop, value, TRUE);
2789 static HRESULT WINAPI saxxmlreader_putProperty(
2790 IVBSAXXMLReader* iface,
2794 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2795 return internal_putProperty(This, pProp, value, TRUE);
2798 static HRESULT WINAPI saxxmlreader_get_entityResolver(
2799 IVBSAXXMLReader* iface,
2800 IVBSAXEntityResolver **pEntityResolver)
2802 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2803 return internal_getEntityResolver(This, pEntityResolver, TRUE);
2806 static HRESULT WINAPI saxxmlreader_put_entityResolver(
2807 IVBSAXXMLReader* iface,
2808 IVBSAXEntityResolver *pEntityResolver)
2810 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2811 return internal_putEntityResolver(This, pEntityResolver, TRUE);
2814 static HRESULT WINAPI saxxmlreader_get_contentHandler(
2815 IVBSAXXMLReader* iface,
2816 IVBSAXContentHandler **ppContentHandler)
2818 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2819 return internal_getContentHandler(This, ppContentHandler, TRUE);
2822 static HRESULT WINAPI saxxmlreader_put_contentHandler(
2823 IVBSAXXMLReader* iface,
2824 IVBSAXContentHandler *contentHandler)
2826 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2827 return internal_putContentHandler(This, contentHandler, TRUE);
2830 static HRESULT WINAPI saxxmlreader_get_dtdHandler(
2831 IVBSAXXMLReader* iface,
2832 IVBSAXDTDHandler **pDTDHandler)
2834 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2835 return internal_getDTDHandler(This, pDTDHandler, TRUE);
2838 static HRESULT WINAPI saxxmlreader_put_dtdHandler(
2839 IVBSAXXMLReader* iface,
2840 IVBSAXDTDHandler *pDTDHandler)
2842 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2843 return internal_putDTDHandler(This, pDTDHandler, TRUE);
2846 static HRESULT WINAPI saxxmlreader_get_errorHandler(
2847 IVBSAXXMLReader* iface,
2848 IVBSAXErrorHandler **pErrorHandler)
2850 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2851 return internal_getErrorHandler(This, pErrorHandler, TRUE);
2854 static HRESULT WINAPI saxxmlreader_put_errorHandler(
2855 IVBSAXXMLReader* iface,
2856 IVBSAXErrorHandler *errorHandler)
2858 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2859 return internal_putErrorHandler(This, errorHandler, TRUE);
2862 static HRESULT WINAPI saxxmlreader_get_baseURL(
2863 IVBSAXXMLReader* iface,
2864 const WCHAR **pBaseUrl)
2866 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2868 FIXME("(%p)->(%p) stub\n", This, pBaseUrl);
2872 static HRESULT WINAPI saxxmlreader_put_baseURL(
2873 IVBSAXXMLReader* iface,
2874 const WCHAR *pBaseUrl)
2876 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2878 FIXME("(%p)->(%s) stub\n", This, debugstr_w(pBaseUrl));
2882 static HRESULT WINAPI saxxmlreader_get_secureBaseURL(
2883 IVBSAXXMLReader* iface,
2884 const WCHAR **pSecureBaseUrl)
2886 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2888 FIXME("(%p)->(%p) stub\n", This, pSecureBaseUrl);
2893 static HRESULT WINAPI saxxmlreader_put_secureBaseURL(
2894 IVBSAXXMLReader* iface,
2895 const WCHAR *secureBaseUrl)
2897 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2899 FIXME("(%p)->(%s) stub\n", This, debugstr_w(secureBaseUrl));
2903 static HRESULT WINAPI saxxmlreader_parse(
2904 IVBSAXXMLReader* iface,
2907 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2908 return internal_parse(This, varInput, TRUE);
2911 static HRESULT WINAPI saxxmlreader_parseURL(
2912 IVBSAXXMLReader* iface,
2915 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2916 return internal_parseURL(This, url, TRUE);
2919 static const struct IVBSAXXMLReaderVtbl VBSAXXMLReaderVtbl =
2921 saxxmlreader_QueryInterface,
2922 saxxmlreader_AddRef,
2923 saxxmlreader_Release,
2924 saxxmlreader_GetTypeInfoCount,
2925 saxxmlreader_GetTypeInfo,
2926 saxxmlreader_GetIDsOfNames,
2927 saxxmlreader_Invoke,
2928 saxxmlreader_getFeature,
2929 saxxmlreader_putFeature,
2930 saxxmlreader_getProperty,
2931 saxxmlreader_putProperty,
2932 saxxmlreader_get_entityResolver,
2933 saxxmlreader_put_entityResolver,
2934 saxxmlreader_get_contentHandler,
2935 saxxmlreader_put_contentHandler,
2936 saxxmlreader_get_dtdHandler,
2937 saxxmlreader_put_dtdHandler,
2938 saxxmlreader_get_errorHandler,
2939 saxxmlreader_put_errorHandler,
2940 saxxmlreader_get_baseURL,
2941 saxxmlreader_put_baseURL,
2942 saxxmlreader_get_secureBaseURL,
2943 saxxmlreader_put_secureBaseURL,
2945 saxxmlreader_parseURL
2948 /*** ISAXXMLReader interface ***/
2949 /*** IUnknown methods ***/
2950 static HRESULT WINAPI isaxxmlreader_QueryInterface(ISAXXMLReader* iface, REFIID riid, void **ppvObject)
2952 saxreader *This = impl_from_ISAXXMLReader( iface );
2953 return saxxmlreader_QueryInterface(&This->IVBSAXXMLReader_iface, riid, ppvObject);
2956 static ULONG WINAPI isaxxmlreader_AddRef(ISAXXMLReader* iface)
2958 saxreader *This = impl_from_ISAXXMLReader( iface );
2959 return saxxmlreader_AddRef(&This->IVBSAXXMLReader_iface);
2962 static ULONG WINAPI isaxxmlreader_Release(ISAXXMLReader* iface)
2964 saxreader *This = impl_from_ISAXXMLReader( iface );
2965 return saxxmlreader_Release(&This->IVBSAXXMLReader_iface);
2968 /*** ISAXXMLReader methods ***/
2969 static HRESULT WINAPI isaxxmlreader_getFeature(
2970 ISAXXMLReader* iface,
2971 const WCHAR *pFeature,
2972 VARIANT_BOOL *pValue)
2974 saxreader *This = impl_from_ISAXXMLReader( iface );
2975 return IVBSAXXMLReader_getFeature(&This->IVBSAXXMLReader_iface, pFeature, pValue);
2978 static HRESULT WINAPI isaxxmlreader_putFeature(
2979 ISAXXMLReader* iface,
2980 const WCHAR *pFeature,
2981 VARIANT_BOOL vfValue)
2983 saxreader *This = impl_from_ISAXXMLReader( iface );
2984 return IVBSAXXMLReader_putFeature(&This->IVBSAXXMLReader_iface, pFeature, vfValue);
2987 static HRESULT WINAPI isaxxmlreader_getProperty(
2988 ISAXXMLReader* iface,
2992 saxreader *This = impl_from_ISAXXMLReader( iface );
2993 return internal_getProperty(This, prop, value, FALSE);
2996 static HRESULT WINAPI isaxxmlreader_putProperty(
2997 ISAXXMLReader* iface,
3001 saxreader *This = impl_from_ISAXXMLReader( iface );
3002 return internal_putProperty(This, pProp, value, FALSE);
3005 static HRESULT WINAPI isaxxmlreader_getEntityResolver(
3006 ISAXXMLReader* iface,
3007 ISAXEntityResolver **ppEntityResolver)
3009 saxreader *This = impl_from_ISAXXMLReader( iface );
3010 return internal_getEntityResolver(This, ppEntityResolver, FALSE);
3013 static HRESULT WINAPI isaxxmlreader_putEntityResolver(
3014 ISAXXMLReader* iface,
3015 ISAXEntityResolver *pEntityResolver)
3017 saxreader *This = impl_from_ISAXXMLReader( iface );
3018 return internal_putEntityResolver(This, pEntityResolver, FALSE);
3021 static HRESULT WINAPI isaxxmlreader_getContentHandler(
3022 ISAXXMLReader* iface,
3023 ISAXContentHandler **pContentHandler)
3025 saxreader *This = impl_from_ISAXXMLReader( iface );
3026 return internal_getContentHandler(This, pContentHandler, FALSE);
3029 static HRESULT WINAPI isaxxmlreader_putContentHandler(
3030 ISAXXMLReader* iface,
3031 ISAXContentHandler *contentHandler)
3033 saxreader *This = impl_from_ISAXXMLReader( iface );
3034 return internal_putContentHandler(This, contentHandler, FALSE);
3037 static HRESULT WINAPI isaxxmlreader_getDTDHandler(
3038 ISAXXMLReader* iface,
3039 ISAXDTDHandler **pDTDHandler)
3041 saxreader *This = impl_from_ISAXXMLReader( iface );
3042 return internal_getDTDHandler(This, pDTDHandler, FALSE);
3045 static HRESULT WINAPI isaxxmlreader_putDTDHandler(
3046 ISAXXMLReader* iface,
3047 ISAXDTDHandler *pDTDHandler)
3049 saxreader *This = impl_from_ISAXXMLReader( iface );
3050 return internal_putDTDHandler(This, pDTDHandler, FALSE);
3053 static HRESULT WINAPI isaxxmlreader_getErrorHandler(
3054 ISAXXMLReader* iface,
3055 ISAXErrorHandler **pErrorHandler)
3057 saxreader *This = impl_from_ISAXXMLReader( iface );
3058 return internal_getErrorHandler(This, pErrorHandler, FALSE);
3061 static HRESULT WINAPI isaxxmlreader_putErrorHandler(
3062 ISAXXMLReader* iface,
3063 ISAXErrorHandler *errorHandler)
3065 saxreader *This = impl_from_ISAXXMLReader( iface );
3066 return internal_putErrorHandler(This, errorHandler, FALSE);
3069 static HRESULT WINAPI isaxxmlreader_getBaseURL(
3070 ISAXXMLReader* iface,
3071 const WCHAR **pBaseUrl)
3073 saxreader *This = impl_from_ISAXXMLReader( iface );
3074 return IVBSAXXMLReader_get_baseURL(&This->IVBSAXXMLReader_iface, pBaseUrl);
3077 static HRESULT WINAPI isaxxmlreader_putBaseURL(
3078 ISAXXMLReader* iface,
3079 const WCHAR *pBaseUrl)
3081 saxreader *This = impl_from_ISAXXMLReader( iface );
3082 return IVBSAXXMLReader_put_baseURL(&This->IVBSAXXMLReader_iface, pBaseUrl);
3085 static HRESULT WINAPI isaxxmlreader_getSecureBaseURL(
3086 ISAXXMLReader* iface,
3087 const WCHAR **pSecureBaseUrl)
3089 saxreader *This = impl_from_ISAXXMLReader( iface );
3090 return IVBSAXXMLReader_get_secureBaseURL(&This->IVBSAXXMLReader_iface, pSecureBaseUrl);
3093 static HRESULT WINAPI isaxxmlreader_putSecureBaseURL(
3094 ISAXXMLReader* iface,
3095 const WCHAR *secureBaseUrl)
3097 saxreader *This = impl_from_ISAXXMLReader( iface );
3098 return IVBSAXXMLReader_put_secureBaseURL(&This->IVBSAXXMLReader_iface, secureBaseUrl);
3101 static HRESULT WINAPI isaxxmlreader_parse(
3102 ISAXXMLReader* iface,
3105 saxreader *This = impl_from_ISAXXMLReader( iface );
3106 return internal_parse(This, varInput, FALSE);
3109 static HRESULT WINAPI isaxxmlreader_parseURL(
3110 ISAXXMLReader* iface,
3113 saxreader *This = impl_from_ISAXXMLReader( iface );
3114 return internal_parseURL(This, url, FALSE);
3117 static const struct ISAXXMLReaderVtbl SAXXMLReaderVtbl =
3119 isaxxmlreader_QueryInterface,
3120 isaxxmlreader_AddRef,
3121 isaxxmlreader_Release,
3122 isaxxmlreader_getFeature,
3123 isaxxmlreader_putFeature,
3124 isaxxmlreader_getProperty,
3125 isaxxmlreader_putProperty,
3126 isaxxmlreader_getEntityResolver,
3127 isaxxmlreader_putEntityResolver,
3128 isaxxmlreader_getContentHandler,
3129 isaxxmlreader_putContentHandler,
3130 isaxxmlreader_getDTDHandler,
3131 isaxxmlreader_putDTDHandler,
3132 isaxxmlreader_getErrorHandler,
3133 isaxxmlreader_putErrorHandler,
3134 isaxxmlreader_getBaseURL,
3135 isaxxmlreader_putBaseURL,
3136 isaxxmlreader_getSecureBaseURL,
3137 isaxxmlreader_putSecureBaseURL,
3138 isaxxmlreader_parse,
3139 isaxxmlreader_parseURL
3142 static const tid_t saxreader_iface_tids[] = {
3143 IVBSAXXMLReader_tid,
3146 static dispex_static_data_t saxreader_dispex = {
3148 IVBSAXXMLReader_tid,
3150 saxreader_iface_tids
3153 HRESULT SAXXMLReader_create(MSXML_VERSION version, IUnknown *outer, LPVOID *ppObj)
3157 TRACE("(%p, %p)\n", outer, ppObj);
3159 reader = heap_alloc( sizeof (*reader) );
3161 return E_OUTOFMEMORY;
3163 reader->IVBSAXXMLReader_iface.lpVtbl = &VBSAXXMLReaderVtbl;
3164 reader->ISAXXMLReader_iface.lpVtbl = &SAXXMLReaderVtbl;
3166 reader->contentHandler = NULL;
3167 reader->vbcontentHandler = NULL;
3168 reader->errorHandler = NULL;
3169 reader->vberrorHandler = NULL;
3170 reader->lexicalHandler = NULL;
3171 reader->vblexicalHandler = NULL;
3172 reader->declHandler = NULL;
3173 reader->vbdeclHandler = NULL;
3174 reader->isParsing = FALSE;
3175 reader->pool.pool = NULL;
3176 reader->pool.index = 0;
3177 reader->pool.len = 0;
3178 reader->features = Namespaces;
3179 reader->version = version;
3181 init_dispex(&reader->dispex, (IUnknown*)&reader->IVBSAXXMLReader_iface, &saxreader_dispex);
3183 memset(&reader->sax, 0, sizeof(xmlSAXHandler));
3184 reader->sax.initialized = XML_SAX2_MAGIC;
3185 reader->sax.startDocument = libxmlStartDocument;
3186 reader->sax.endDocument = libxmlEndDocument;
3187 reader->sax.startElementNs = libxmlStartElementNS;
3188 reader->sax.endElementNs = libxmlEndElementNS;
3189 reader->sax.characters = libxmlCharacters;
3190 reader->sax.setDocumentLocator = libxmlSetDocumentLocator;
3191 reader->sax.comment = libxmlComment;
3192 reader->sax.error = libxmlFatalError;
3193 reader->sax.fatalError = libxmlFatalError;
3194 reader->sax.cdataBlock = libxmlCDataBlock;
3196 *ppObj = &reader->IVBSAXXMLReader_iface;
3198 TRACE("returning iface %p\n", *ppObj);
3205 HRESULT SAXXMLReader_create(MSXML_VERSION version, IUnknown *pUnkOuter, LPVOID *ppObj)
3207 MESSAGE("This program tried to use a SAX XML Reader object, but\n"
3208 "libxml2 support was not present at compile time.\n");