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"
46 #include "msxml_private.h"
48 WINE_DEFAULT_DEBUG_CHANNEL(msxml);
54 ExhaustiveErrors = 1 << 1,
55 ExternalGeneralEntities = 1 << 2,
56 ExternalParameterEntities = 1 << 3,
57 ForcedResync = 1 << 4,
58 NamespacePrefixes = 1 << 5,
60 ParameterEntities = 1 << 7,
61 PreserveSystemIndentifiers = 1 << 8,
63 SchemaValidation = 1 << 10,
64 ServerHttpRequest = 1 << 11,
65 SuppressValidationfatalError = 1 << 12,
66 UseInlineSchema = 1 << 13,
67 UseSchemaLocation = 1 << 14,
68 LexicalHandlerParEntities = 1 << 15
78 typedef struct _saxreader
80 IVBSAXXMLReader IVBSAXXMLReader_iface;
81 ISAXXMLReader ISAXXMLReader_iface;
83 struct ISAXContentHandler *contentHandler;
84 struct IVBSAXContentHandler *vbcontentHandler;
85 struct ISAXErrorHandler *errorHandler;
86 struct IVBSAXErrorHandler *vberrorHandler;
87 struct ISAXLexicalHandler *lexicalHandler;
88 struct IVBSAXLexicalHandler *vblexicalHandler;
89 struct ISAXDeclHandler *declHandler;
90 struct IVBSAXDeclHandler *vbdeclHandler;
94 enum ReaderFeatures features;
97 typedef struct _saxlocator
99 IVBSAXLocator IVBSAXLocator_iface;
100 ISAXLocator ISAXLocator_iface;
102 saxreader *saxreader;
104 xmlParserCtxtPtr pParserCtxt;
118 typedef struct _saxattributes
120 IVBSAXAttributes IVBSAXAttributes_iface;
121 ISAXAttributes ISAXAttributes_iface;
130 static inline saxreader *impl_from_IVBSAXXMLReader( IVBSAXXMLReader *iface )
132 return CONTAINING_RECORD(iface, saxreader, IVBSAXXMLReader_iface);
135 static inline saxreader *impl_from_ISAXXMLReader( ISAXXMLReader *iface )
137 return CONTAINING_RECORD(iface, saxreader, ISAXXMLReader_iface);
140 static inline saxlocator *impl_from_IVBSAXLocator( IVBSAXLocator *iface )
142 return CONTAINING_RECORD(iface, saxlocator, IVBSAXLocator_iface);
145 static inline saxlocator *impl_from_ISAXLocator( ISAXLocator *iface )
147 return CONTAINING_RECORD(iface, saxlocator, ISAXLocator_iface);
150 static inline saxattributes *impl_from_IVBSAXAttributes( IVBSAXAttributes *iface )
152 return CONTAINING_RECORD(iface, saxattributes, IVBSAXAttributes_iface);
155 static inline saxattributes *impl_from_ISAXAttributes( ISAXAttributes *iface )
157 return CONTAINING_RECORD(iface, saxattributes, ISAXAttributes_iface);
161 static const WCHAR PropertyCharsetW[] = {
162 'c','h','a','r','s','e','t',0
164 static const WCHAR PropertyDeclHandlerW[] = {
165 'h','t','t','p',':','/','/','x','m','l','.','o','r','g','/',
166 's','a','x','/','p','r','o','p','e','r','t','i','e','s','/',
167 'd','e','c','l','a','r','a','t','i','o','n',
168 '-','h','a','n','d','l','e','r',0
170 static const WCHAR PropertyDomNodeW[] = {
171 'h','t','t','p',':','/','/','x','m','l','.','o','r','g','/',
172 's','a','x','/','p','r','o','p','e','r','t','i','e','s','/',
173 'd','o','m','-','n','o','d','e',0
175 static const WCHAR PropertyInputSourceW[] = {
176 'i','n','p','u','t','-','s','o','u','r','c','e',0
178 static const WCHAR PropertyLexicalHandlerW[] = {
179 'h','t','t','p',':','/','/','x','m','l','.','o','r','g','/',
180 's','a','x','/','p','r','o','p','e','r','t','i','e','s','/',
181 'l','e','x','i','c','a','l','-','h','a','n','d','l','e','r',0
183 static const WCHAR PropertyMaxElementDepthW[] = {
184 'm','a','x','-','e','l','e','m','e','n','t','-','d','e','p','t','h',0
186 static const WCHAR PropertyMaxXMLSizeW[] = {
187 'm','a','x','-','x','m','l','-','s','i','z','e',0
189 static const WCHAR PropertySchemaDeclHandlerW[] = {
190 's','c','h','e','m','a','-','d','e','c','l','a','r','a','t','i','o','n','-',
191 'h','a','n','d','l','e','r',0
193 static const WCHAR PropertyXMLDeclEncodingW[] = {
194 'x','m','l','d','e','c','l','-','e','n','c','o','d','i','n','g',0
196 static const WCHAR PropertyXMLDeclStandaloneW[] = {
197 'x','m','l','d','e','c','l','-','s','t','a','n','d','a','l','o','n','e',0
199 static const WCHAR PropertyXMLDeclVersionW[] = {
200 'x','m','l','d','e','c','l','-','v','e','r','s','i','o','n',0
204 static const WCHAR FeatureExternalGeneralEntitiesW[] = {
205 'h','t','t','p',':','/','/','x','m','l','.','o','r','g','/','s','a','x','/',
206 'f','e','a','t','u','r','e','s','/','e','x','t','e','r','n','a','l','-','g','e','n','e','r','a','l',
207 '-','e','n','t','i','t','i','e','s',0
210 static const WCHAR FeatureExternalParameterEntitiesW[] = {
211 'h','t','t','p',':','/','/','x','m','l','.','o','r','g','/','s','a','x','/','f','e','a','t','u','r','e','s',
212 '/','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
215 static const WCHAR FeatureLexicalHandlerParEntitiesW[] = {
216 'h','t','t','p',':','/','/','x','m','l','.','o','r','g','/','s','a','x','/','f','e','a','t','u','r','e','s',
217 '/','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
220 static const WCHAR FeatureProhibitDTDW[] = {
221 'p','r','o','h','i','b','i','t','-','d','t','d',0
224 static inline HRESULT set_feature_value(saxreader *reader, enum ReaderFeatures feature, VARIANT_BOOL value)
226 if (value == VARIANT_TRUE)
227 reader->features |= feature;
229 reader->features &= ~feature;
234 static inline BOOL has_content_handler(const saxlocator *locator)
236 return (locator->vbInterface && locator->saxreader->vbcontentHandler) ||
237 (!locator->vbInterface && locator->saxreader->contentHandler);
240 static inline BOOL has_error_handler(const saxlocator *locator)
242 return (locator->vbInterface && locator->saxreader->vberrorHandler) ||
243 (!locator->vbInterface && locator->saxreader->errorHandler);
246 static HRESULT namespacePush(saxlocator *locator, int ns)
248 if(locator->nsStackLast>=locator->nsStackSize)
252 new_stack = HeapReAlloc(GetProcessHeap(), 0,
253 locator->nsStack, sizeof(int)*locator->nsStackSize*2);
254 if(!new_stack) return E_OUTOFMEMORY;
255 locator->nsStack = new_stack;
256 locator->nsStackSize *= 2;
258 locator->nsStack[locator->nsStackLast++] = ns;
263 static int namespacePop(saxlocator *locator)
265 if(locator->nsStackLast == 0) return 0;
266 return locator->nsStack[--locator->nsStackLast];
269 static BOOL bstr_pool_insert(struct bstrpool *pool, BSTR pool_entry)
273 pool->pool = HeapAlloc(GetProcessHeap(), 0, 16 * sizeof(*pool->pool));
280 else if (pool->index == pool->len)
282 BSTR *realloc = HeapReAlloc(GetProcessHeap(), 0, pool->pool, pool->len * 2 * sizeof(*realloc));
287 pool->pool = realloc;
291 pool->pool[pool->index++] = pool_entry;
295 static void free_bstr_pool(struct bstrpool *pool)
299 for (i = 0; i < pool->index; i++)
300 SysFreeString(pool->pool[i]);
302 HeapFree(GetProcessHeap(), 0, pool->pool);
305 pool->index = pool->len = 0;
308 static BSTR bstr_from_xmlCharN(const xmlChar *buf, int len)
316 dLen = MultiByteToWideChar(CP_UTF8, 0, (LPCSTR)buf, len, NULL, 0);
317 if(len != -1) dLen++;
318 bstr = SysAllocStringLen(NULL, dLen-1);
321 MultiByteToWideChar(CP_UTF8, 0, (LPCSTR)buf, len, bstr, dLen);
322 if(len != -1) bstr[dLen-1] = '\0';
327 static BSTR QName_from_xmlChar(const xmlChar *prefix, const xmlChar *name)
332 if(!name) return NULL;
334 if(!prefix || !*prefix)
335 return bstr_from_xmlChar(name);
337 qname = xmlBuildQName(name, prefix, NULL, 0);
338 bstr = bstr_from_xmlChar(qname);
344 static BSTR pooled_bstr_from_xmlChar(struct bstrpool *pool, const xmlChar *buf)
346 BSTR pool_entry = bstr_from_xmlChar(buf);
348 if (pool_entry && !bstr_pool_insert(pool, pool_entry))
350 SysFreeString(pool_entry);
357 static BSTR pooled_bstr_from_xmlCharN(struct bstrpool *pool, const xmlChar *buf, int len)
359 BSTR pool_entry = bstr_from_xmlCharN(buf, len);
361 if (pool_entry && !bstr_pool_insert(pool, pool_entry))
363 SysFreeString(pool_entry);
370 static BSTR pooled_QName_from_xmlChar(struct bstrpool *pool, const xmlChar *prefix, const xmlChar *name)
372 BSTR pool_entry = QName_from_xmlChar(prefix, name);
374 if (pool_entry && !bstr_pool_insert(pool, pool_entry))
376 SysFreeString(pool_entry);
383 static void format_error_message_from_id(saxlocator *This, HRESULT hr)
385 xmlStopParser(This->pParserCtxt);
388 if(has_error_handler(This))
391 if(!FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM,
392 NULL, hr, 0, msg, sizeof(msg), NULL))
394 FIXME("MSXML errors not yet supported.\n");
398 if(This->vbInterface)
400 BSTR bstrMsg = SysAllocString(msg);
401 IVBSAXErrorHandler_fatalError(This->saxreader->vberrorHandler,
402 &This->IVBSAXLocator_iface, &bstrMsg, hr);
403 SysFreeString(bstrMsg);
406 ISAXErrorHandler_fatalError(This->saxreader->errorHandler,
407 &This->ISAXLocator_iface, msg, hr);
411 static void update_position(saxlocator *This, xmlChar *end)
413 if(This->lastCur == NULL)
415 This->lastCur = (xmlChar*)This->pParserCtxt->input->base;
417 This->realColumn = 1;
419 else if(This->lastCur < This->pParserCtxt->input->base)
421 This->lastCur = (xmlChar*)This->pParserCtxt->input->base;
423 This->realColumn = 1;
426 if(This->pParserCtxt->input->cur<This->lastCur)
428 This->lastCur = (xmlChar*)This->pParserCtxt->input->base;
430 This->realColumn = 1;
433 if(!end) end = (xmlChar*)This->pParserCtxt->input->cur;
435 while(This->lastCur < end)
437 if(*(This->lastCur) == '\n')
440 This->realColumn = 1;
442 else if(*(This->lastCur) == '\r' &&
443 (This->lastCur==This->pParserCtxt->input->end ||
444 *(This->lastCur+1)!='\n'))
447 This->realColumn = 1;
449 else This->realColumn++;
453 /* Count multibyte UTF8 encoded characters once */
454 while((*(This->lastCur)&0xC0) == 0x80) This->lastCur++;
457 This->line = This->realLine;
458 This->column = This->realColumn;
461 /*** IVBSAXAttributes interface ***/
462 /*** IUnknown methods ***/
463 static HRESULT WINAPI ivbsaxattributes_QueryInterface(
464 IVBSAXAttributes* iface,
468 saxattributes *This = impl_from_IVBSAXAttributes(iface);
470 TRACE("%p %s %p\n", This, debugstr_guid(riid), ppvObject);
474 if (IsEqualGUID(riid, &IID_IUnknown) ||
475 IsEqualGUID(riid, &IID_IDispatch) ||
476 IsEqualGUID(riid, &IID_IVBSAXAttributes))
482 FIXME("interface %s not implemented\n", debugstr_guid(riid));
483 return E_NOINTERFACE;
486 IVBSAXAttributes_AddRef(iface);
491 static ULONG WINAPI ivbsaxattributes_AddRef(IVBSAXAttributes* iface)
493 saxattributes *This = impl_from_IVBSAXAttributes(iface);
494 return ISAXAttributes_AddRef(&This->ISAXAttributes_iface);
497 static ULONG WINAPI ivbsaxattributes_Release(IVBSAXAttributes* iface)
499 saxattributes *This = impl_from_IVBSAXAttributes(iface);
500 return ISAXAttributes_Release(&This->ISAXAttributes_iface);
503 /*** IDispatch methods ***/
504 static HRESULT WINAPI ivbsaxattributes_GetTypeInfoCount( IVBSAXAttributes *iface, UINT* pctinfo )
506 saxattributes *This = impl_from_IVBSAXAttributes( iface );
508 TRACE("(%p)->(%p)\n", This, pctinfo);
515 static HRESULT WINAPI ivbsaxattributes_GetTypeInfo(
516 IVBSAXAttributes *iface,
517 UINT iTInfo, LCID lcid, ITypeInfo** ppTInfo )
519 saxattributes *This = impl_from_IVBSAXAttributes( iface );
522 TRACE("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo);
524 hr = get_typeinfo(IVBSAXAttributes_tid, ppTInfo);
529 static HRESULT WINAPI ivbsaxattributes_GetIDsOfNames(
530 IVBSAXAttributes *iface,
537 saxattributes *This = impl_from_IVBSAXAttributes( iface );
541 TRACE("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames, cNames,
544 if(!rgszNames || cNames == 0 || !rgDispId)
547 hr = get_typeinfo(IVBSAXAttributes_tid, &typeinfo);
550 hr = ITypeInfo_GetIDsOfNames(typeinfo, rgszNames, cNames, rgDispId);
551 ITypeInfo_Release(typeinfo);
557 static HRESULT WINAPI ivbsaxattributes_Invoke(
558 IVBSAXAttributes *iface,
563 DISPPARAMS* pDispParams,
565 EXCEPINFO* pExcepInfo,
568 saxattributes *This = impl_from_IVBSAXAttributes( iface );
572 TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
573 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
575 hr = get_typeinfo(IVBSAXAttributes_tid, &typeinfo);
578 hr = ITypeInfo_Invoke(typeinfo, &This->IVBSAXAttributes_iface, dispIdMember, wFlags,
579 pDispParams, pVarResult, pExcepInfo, puArgErr);
580 ITypeInfo_Release(typeinfo);
586 /*** IVBSAXAttributes methods ***/
587 static HRESULT WINAPI ivbsaxattributes_get_length(
588 IVBSAXAttributes* iface,
591 saxattributes *This = impl_from_IVBSAXAttributes( iface );
592 return ISAXAttributes_getLength(&This->ISAXAttributes_iface, nLength);
595 static HRESULT WINAPI ivbsaxattributes_getURI(
596 IVBSAXAttributes* iface,
601 saxattributes *This = impl_from_IVBSAXAttributes( iface );
602 return ISAXAttributes_getURI(&This->ISAXAttributes_iface, nIndex, (const WCHAR**)uri, &len);
605 static HRESULT WINAPI ivbsaxattributes_getLocalName(
606 IVBSAXAttributes* iface,
611 saxattributes *This = impl_from_IVBSAXAttributes( iface );
612 return ISAXAttributes_getLocalName(&This->ISAXAttributes_iface, nIndex,
613 (const WCHAR**)localName, &len);
616 static HRESULT WINAPI ivbsaxattributes_getQName(
617 IVBSAXAttributes* iface,
622 saxattributes *This = impl_from_IVBSAXAttributes( iface );
623 return ISAXAttributes_getQName(&This->ISAXAttributes_iface, nIndex, (const WCHAR**)QName, &len);
626 static HRESULT WINAPI ivbsaxattributes_getIndexFromName(
627 IVBSAXAttributes* iface,
632 saxattributes *This = impl_from_IVBSAXAttributes( iface );
633 return ISAXAttributes_getIndexFromName(&This->ISAXAttributes_iface, uri, SysStringLen(uri),
634 localName, SysStringLen(localName), index);
637 static HRESULT WINAPI ivbsaxattributes_getIndexFromQName(
638 IVBSAXAttributes* iface,
642 saxattributes *This = impl_from_IVBSAXAttributes( iface );
643 return ISAXAttributes_getIndexFromQName(&This->ISAXAttributes_iface, QName,
644 SysStringLen(QName), index);
647 static HRESULT WINAPI ivbsaxattributes_getType(
648 IVBSAXAttributes* iface,
653 saxattributes *This = impl_from_IVBSAXAttributes( iface );
654 return ISAXAttributes_getType(&This->ISAXAttributes_iface, nIndex, (const WCHAR**)type, &len);
657 static HRESULT WINAPI ivbsaxattributes_getTypeFromName(
658 IVBSAXAttributes* iface,
664 saxattributes *This = impl_from_IVBSAXAttributes( iface );
665 return ISAXAttributes_getTypeFromName(&This->ISAXAttributes_iface, uri, SysStringLen(uri),
666 localName, SysStringLen(localName), (const WCHAR**)type, &len);
669 static HRESULT WINAPI ivbsaxattributes_getTypeFromQName(
670 IVBSAXAttributes* iface,
675 saxattributes *This = impl_from_IVBSAXAttributes( iface );
676 return ISAXAttributes_getTypeFromQName(&This->ISAXAttributes_iface, QName, SysStringLen(QName),
677 (const WCHAR**)type, &len);
680 static HRESULT WINAPI ivbsaxattributes_getValue(
681 IVBSAXAttributes* iface,
686 saxattributes *This = impl_from_IVBSAXAttributes( iface );
687 return ISAXAttributes_getValue(&This->ISAXAttributes_iface, nIndex, (const WCHAR**)value, &len);
690 static HRESULT WINAPI ivbsaxattributes_getValueFromName(
691 IVBSAXAttributes* iface,
697 saxattributes *This = impl_from_IVBSAXAttributes( iface );
698 return ISAXAttributes_getValueFromName(&This->ISAXAttributes_iface, uri, SysStringLen(uri),
699 localName, SysStringLen(localName), (const WCHAR**)value, &len);
702 static HRESULT WINAPI ivbsaxattributes_getValueFromQName(
703 IVBSAXAttributes* iface,
708 saxattributes *This = impl_from_IVBSAXAttributes( iface );
709 return ISAXAttributes_getValueFromQName(&This->ISAXAttributes_iface, QName,
710 SysStringLen(QName), (const WCHAR**)value, &len);
713 static const struct IVBSAXAttributesVtbl ivbsaxattributes_vtbl =
715 ivbsaxattributes_QueryInterface,
716 ivbsaxattributes_AddRef,
717 ivbsaxattributes_Release,
718 ivbsaxattributes_GetTypeInfoCount,
719 ivbsaxattributes_GetTypeInfo,
720 ivbsaxattributes_GetIDsOfNames,
721 ivbsaxattributes_Invoke,
722 ivbsaxattributes_get_length,
723 ivbsaxattributes_getURI,
724 ivbsaxattributes_getLocalName,
725 ivbsaxattributes_getQName,
726 ivbsaxattributes_getIndexFromName,
727 ivbsaxattributes_getIndexFromQName,
728 ivbsaxattributes_getType,
729 ivbsaxattributes_getTypeFromName,
730 ivbsaxattributes_getTypeFromQName,
731 ivbsaxattributes_getValue,
732 ivbsaxattributes_getValueFromName,
733 ivbsaxattributes_getValueFromQName
736 /*** ISAXAttributes interface ***/
737 /*** IUnknown methods ***/
738 static HRESULT WINAPI isaxattributes_QueryInterface(
739 ISAXAttributes* iface,
743 saxattributes *This = impl_from_ISAXAttributes(iface);
745 TRACE("%p %s %p\n", This, debugstr_guid(riid), ppvObject);
749 if (IsEqualGUID(riid, &IID_IUnknown) ||
750 IsEqualGUID(riid, &IID_ISAXAttributes))
756 FIXME("interface %s not implemented\n", debugstr_guid(riid));
757 return E_NOINTERFACE;
760 ISAXAttributes_AddRef(iface);
765 static ULONG WINAPI isaxattributes_AddRef(ISAXAttributes* iface)
767 saxattributes *This = impl_from_ISAXAttributes(iface);
769 return InterlockedIncrement(&This->ref);
772 static ULONG WINAPI isaxattributes_Release(ISAXAttributes* iface)
774 saxattributes *This = impl_from_ISAXAttributes(iface);
779 ref = InterlockedDecrement(&This->ref);
783 for(index=0; index<This->nb_attributes; index++)
785 SysFreeString(This->szLocalname[index]);
786 SysFreeString(This->szURI[index]);
787 SysFreeString(This->szValue[index]);
788 SysFreeString(This->szQName[index]);
791 heap_free(This->szLocalname);
792 heap_free(This->szURI);
793 heap_free(This->szValue);
794 heap_free(This->szQName);
802 /*** ISAXAttributes methods ***/
803 static HRESULT WINAPI isaxattributes_getLength(
804 ISAXAttributes* iface,
807 saxattributes *This = impl_from_ISAXAttributes( iface );
809 *length = This->nb_attributes;
810 TRACE("Length set to %d\n", *length);
814 static HRESULT WINAPI isaxattributes_getURI(
815 ISAXAttributes* iface,
820 saxattributes *This = impl_from_ISAXAttributes( iface );
821 TRACE("(%p)->(%d)\n", This, nIndex);
823 if(nIndex>=This->nb_attributes || nIndex<0) return E_INVALIDARG;
824 if(!pUrl || !pUriSize) return E_POINTER;
826 *pUriSize = SysStringLen(This->szURI[nIndex]);
827 *pUrl = This->szURI[nIndex];
832 static HRESULT WINAPI isaxattributes_getLocalName(
833 ISAXAttributes* iface,
835 const WCHAR **pLocalName,
836 int *pLocalNameLength)
838 saxattributes *This = impl_from_ISAXAttributes( iface );
839 TRACE("(%p)->(%d)\n", This, nIndex);
841 if(nIndex>=This->nb_attributes || nIndex<0) return E_INVALIDARG;
842 if(!pLocalName || !pLocalNameLength) return E_POINTER;
844 *pLocalNameLength = SysStringLen(This->szLocalname[nIndex]);
845 *pLocalName = This->szLocalname[nIndex];
850 static HRESULT WINAPI isaxattributes_getQName(
851 ISAXAttributes* iface,
853 const WCHAR **pQName,
856 saxattributes *This = impl_from_ISAXAttributes( iface );
857 TRACE("(%p)->(%d)\n", This, nIndex);
859 if(nIndex>=This->nb_attributes || nIndex<0) return E_INVALIDARG;
860 if(!pQName || !pQNameLength) return E_POINTER;
862 *pQNameLength = SysStringLen(This->szQName[nIndex]);
863 *pQName = This->szQName[nIndex];
868 static HRESULT WINAPI isaxattributes_getName(
869 ISAXAttributes* iface,
873 const WCHAR **pLocalName,
875 const WCHAR **pQName,
878 saxattributes *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(!pUri || !pUriLength || !pLocalName || !pLocalNameSize
883 || !pQName || !pQNameLength) return E_POINTER;
885 *pUriLength = SysStringLen(This->szURI[nIndex]);
886 *pUri = This->szURI[nIndex];
887 *pLocalNameSize = SysStringLen(This->szLocalname[nIndex]);
888 *pLocalName = This->szLocalname[nIndex];
889 *pQNameLength = SysStringLen(This->szQName[nIndex]);
890 *pQName = This->szQName[nIndex];
895 static HRESULT WINAPI isaxattributes_getIndexFromName(
896 ISAXAttributes* iface,
899 const WCHAR *pLocalName,
903 saxattributes *This = impl_from_ISAXAttributes( iface );
905 TRACE("(%p)->(%s, %d, %s, %d)\n", This, debugstr_w(pUri), cUriLength,
906 debugstr_w(pLocalName), cocalNameLength);
908 if(!pUri || !pLocalName || !index) return E_POINTER;
910 for(i=0; i<This->nb_attributes; i++)
912 if(cUriLength!=SysStringLen(This->szURI[i])
913 || cocalNameLength!=SysStringLen(This->szLocalname[i]))
915 if(cUriLength && memcmp(pUri, This->szURI[i],
916 sizeof(WCHAR)*cUriLength))
918 if(cocalNameLength && memcmp(pLocalName, This->szLocalname[i],
919 sizeof(WCHAR)*cocalNameLength))
929 static HRESULT WINAPI isaxattributes_getIndexFromQName(
930 ISAXAttributes* iface,
935 saxattributes *This = impl_from_ISAXAttributes( iface );
937 TRACE("(%p)->(%s, %d)\n", This, debugstr_w(pQName), nQNameLength);
939 if(!pQName || !index) return E_POINTER;
940 if(!nQNameLength) return E_INVALIDARG;
942 for(i=0; i<This->nb_attributes; i++)
944 if(nQNameLength!=SysStringLen(This->szQName[i])) continue;
945 if(memcmp(pQName, This->szQName, sizeof(WCHAR)*nQNameLength)) continue;
954 static HRESULT WINAPI isaxattributes_getType(
955 ISAXAttributes* iface,
960 saxattributes *This = impl_from_ISAXAttributes( iface );
962 FIXME("(%p)->(%d) stub\n", This, nIndex);
966 static HRESULT WINAPI isaxattributes_getTypeFromName(
967 ISAXAttributes* iface,
970 const WCHAR *pLocalName,
975 saxattributes *This = impl_from_ISAXAttributes( iface );
977 FIXME("(%p)->(%s, %d, %s, %d) stub\n", This, debugstr_w(pUri), nUri,
978 debugstr_w(pLocalName), nLocalName);
982 static HRESULT WINAPI isaxattributes_getTypeFromQName(
983 ISAXAttributes* iface,
989 saxattributes *This = impl_from_ISAXAttributes( iface );
991 FIXME("(%p)->(%s, %d) stub\n", This, debugstr_w(pQName), nQName);
995 static HRESULT WINAPI isaxattributes_getValue(
996 ISAXAttributes* iface,
998 const WCHAR **pValue,
1001 saxattributes *This = impl_from_ISAXAttributes( iface );
1002 TRACE("(%p)->(%d)\n", This, nIndex);
1004 if(nIndex>=This->nb_attributes || nIndex<0) return E_INVALIDARG;
1005 if(!pValue || !nValue) return E_POINTER;
1007 *nValue = SysStringLen(This->szValue[nIndex]);
1008 *pValue = This->szValue[nIndex];
1013 static HRESULT WINAPI isaxattributes_getValueFromName(
1014 ISAXAttributes* iface,
1017 const WCHAR *pLocalName,
1019 const WCHAR **pValue,
1024 saxattributes *This = impl_from_ISAXAttributes( iface );
1025 TRACE("(%p)->(%s, %d, %s, %d)\n", This, debugstr_w(pUri), nUri,
1026 debugstr_w(pLocalName), nLocalName);
1028 hr = ISAXAttributes_getIndexFromName(iface,
1029 pUri, nUri, pLocalName, nLocalName, &index);
1030 if(hr==S_OK) hr = ISAXAttributes_getValue(iface, index, pValue, nValue);
1035 static HRESULT WINAPI isaxattributes_getValueFromQName(
1036 ISAXAttributes* iface,
1037 const WCHAR *pQName,
1039 const WCHAR **pValue,
1044 saxattributes *This = impl_from_ISAXAttributes( iface );
1045 TRACE("(%p)->(%s, %d)\n", This, debugstr_w(pQName), nQName);
1047 hr = ISAXAttributes_getIndexFromQName(iface, pQName, nQName, &index);
1048 if(hr==S_OK) hr = ISAXAttributes_getValue(iface, index, pValue, nValue);
1053 static const struct ISAXAttributesVtbl isaxattributes_vtbl =
1055 isaxattributes_QueryInterface,
1056 isaxattributes_AddRef,
1057 isaxattributes_Release,
1058 isaxattributes_getLength,
1059 isaxattributes_getURI,
1060 isaxattributes_getLocalName,
1061 isaxattributes_getQName,
1062 isaxattributes_getName,
1063 isaxattributes_getIndexFromName,
1064 isaxattributes_getIndexFromQName,
1065 isaxattributes_getType,
1066 isaxattributes_getTypeFromName,
1067 isaxattributes_getTypeFromQName,
1068 isaxattributes_getValue,
1069 isaxattributes_getValueFromName,
1070 isaxattributes_getValueFromQName
1073 static HRESULT SAXAttributes_create(saxattributes **attr,
1074 int nb_namespaces, const xmlChar **xmlNamespaces,
1075 int nb_attributes, const xmlChar **xmlAttributes)
1077 saxattributes *attributes;
1079 static const xmlChar xmlns[] = "xmlns";
1081 attributes = heap_alloc(sizeof(*attributes));
1083 return E_OUTOFMEMORY;
1085 attributes->IVBSAXAttributes_iface.lpVtbl = &ivbsaxattributes_vtbl;
1086 attributes->ISAXAttributes_iface.lpVtbl = &isaxattributes_vtbl;
1087 attributes->ref = 1;
1089 attributes->nb_attributes = nb_namespaces+nb_attributes;
1091 attributes->szLocalname = heap_alloc(sizeof(BSTR)*attributes->nb_attributes);
1092 attributes->szURI = heap_alloc(sizeof(BSTR)*attributes->nb_attributes);
1093 attributes->szValue = heap_alloc(sizeof(BSTR)*attributes->nb_attributes);
1094 attributes->szQName = heap_alloc(sizeof(BSTR)*attributes->nb_attributes);
1096 if(!attributes->szLocalname || !attributes->szURI
1097 || !attributes->szValue || !attributes->szQName)
1099 heap_free(attributes->szLocalname);
1100 heap_free(attributes->szURI);
1101 heap_free(attributes->szValue);
1102 heap_free(attributes->szQName);
1103 heap_free(attributes);
1107 for(index=0; index<nb_namespaces; index++)
1109 attributes->szLocalname[index] = SysAllocStringLen(NULL, 0);
1110 attributes->szURI[index] = SysAllocStringLen(NULL, 0);
1111 attributes->szValue[index] = bstr_from_xmlChar(xmlNamespaces[2*index+1]);
1112 attributes->szQName[index] = QName_from_xmlChar(xmlns, xmlNamespaces[2*index]);
1115 for(index=0; index<nb_attributes; index++)
1117 attributes->szLocalname[nb_namespaces+index] =
1118 bstr_from_xmlChar(xmlAttributes[index*5]);
1119 attributes->szURI[nb_namespaces+index] =
1120 bstr_from_xmlChar(xmlAttributes[index*5+2]);
1121 attributes->szValue[nb_namespaces+index] =
1122 bstr_from_xmlCharN(xmlAttributes[index*5+3],
1123 xmlAttributes[index*5+4]-xmlAttributes[index*5+3]);
1124 attributes->szQName[nb_namespaces+index] =
1125 QName_from_xmlChar(xmlAttributes[index*5+1], xmlAttributes[index*5]);
1130 TRACE("returning %p\n", *attr);
1135 /*** LibXML callbacks ***/
1136 static void libxmlStartDocument(void *ctx)
1138 saxlocator *This = ctx;
1141 if(has_content_handler(This))
1143 if(This->vbInterface)
1144 hr = IVBSAXContentHandler_startDocument(This->saxreader->vbcontentHandler);
1146 hr = ISAXContentHandler_startDocument(This->saxreader->contentHandler);
1149 format_error_message_from_id(This, hr);
1152 update_position(This, NULL);
1155 static void libxmlEndDocument(void *ctx)
1157 saxlocator *This = ctx;
1163 if(This->ret != S_OK) return;
1165 if(has_content_handler(This))
1167 if(This->vbInterface)
1168 hr = IVBSAXContentHandler_endDocument(This->saxreader->vbcontentHandler);
1170 hr = ISAXContentHandler_endDocument(This->saxreader->contentHandler);
1173 format_error_message_from_id(This, hr);
1177 static void libxmlStartElementNS(
1179 const xmlChar *localname,
1180 const xmlChar *prefix,
1183 const xmlChar **namespaces,
1186 const xmlChar **attributes)
1188 BSTR NamespaceUri, LocalName, QName, Prefix, Uri;
1189 saxlocator *This = ctx;
1191 saxattributes *attr;
1194 if(*(This->pParserCtxt->input->cur) == '/')
1195 update_position(This, (xmlChar*)This->pParserCtxt->input->cur+2);
1197 update_position(This, (xmlChar*)This->pParserCtxt->input->cur+1);
1199 hr = namespacePush(This, nb_namespaces);
1200 if(hr==S_OK && has_content_handler(This))
1202 for(index=0; index<nb_namespaces; index++)
1204 Prefix = pooled_bstr_from_xmlChar(&This->saxreader->pool, namespaces[2*index]);
1205 Uri = pooled_bstr_from_xmlChar(&This->saxreader->pool, namespaces[2*index+1]);
1207 if(This->vbInterface)
1208 hr = IVBSAXContentHandler_startPrefixMapping(
1209 This->saxreader->vbcontentHandler,
1212 hr = ISAXContentHandler_startPrefixMapping(
1213 This->saxreader->contentHandler,
1214 Prefix, SysStringLen(Prefix),
1215 Uri, SysStringLen(Uri));
1219 format_error_message_from_id(This, hr);
1224 NamespaceUri = pooled_bstr_from_xmlChar(&This->saxreader->pool, URI);
1225 LocalName = pooled_bstr_from_xmlChar(&This->saxreader->pool, localname);
1226 QName = pooled_QName_from_xmlChar(&This->saxreader->pool, prefix, localname);
1228 hr = SAXAttributes_create(&attr, nb_namespaces, namespaces, nb_attributes, attributes);
1231 if(This->vbInterface)
1232 hr = IVBSAXContentHandler_startElement(This->saxreader->vbcontentHandler,
1233 &NamespaceUri, &LocalName, &QName, &attr->IVBSAXAttributes_iface);
1235 hr = ISAXContentHandler_startElement(This->saxreader->contentHandler, NamespaceUri,
1236 SysStringLen(NamespaceUri), LocalName, SysStringLen(LocalName), QName,
1237 SysStringLen(QName), &attr->ISAXAttributes_iface);
1239 ISAXAttributes_Release(&attr->ISAXAttributes_iface);
1244 format_error_message_from_id(This, hr);
1247 static void libxmlEndElementNS(
1249 const xmlChar *localname,
1250 const xmlChar *prefix,
1253 BSTR NamespaceUri, LocalName, QName, Prefix;
1254 saxlocator *This = ctx;
1259 end = (xmlChar*)This->pParserCtxt->input->cur;
1260 if(*(end-1) != '>' || *(end-2) != '/')
1261 while(end-2>=This->pParserCtxt->input->base
1262 && *(end-2)!='<' && *(end-1)!='/') end--;
1264 update_position(This, end);
1266 nsNr = namespacePop(This);
1268 if(has_content_handler(This))
1270 NamespaceUri = pooled_bstr_from_xmlChar(&This->saxreader->pool, URI);
1271 LocalName = pooled_bstr_from_xmlChar(&This->saxreader->pool, localname);
1272 QName = pooled_QName_from_xmlChar(&This->saxreader->pool, prefix, localname);
1274 if(This->vbInterface)
1275 hr = IVBSAXContentHandler_endElement(
1276 This->saxreader->vbcontentHandler,
1277 &NamespaceUri, &LocalName, &QName);
1279 hr = ISAXContentHandler_endElement(
1280 This->saxreader->contentHandler,
1281 NamespaceUri, SysStringLen(NamespaceUri),
1282 LocalName, SysStringLen(LocalName),
1283 QName, SysStringLen(QName));
1287 format_error_message_from_id(This, hr);
1291 for(index=This->pParserCtxt->nsNr-2;
1292 index>=This->pParserCtxt->nsNr-nsNr*2; index-=2)
1294 Prefix = pooled_bstr_from_xmlChar(&This->saxreader->pool, This->pParserCtxt->nsTab[index]);
1296 if(This->vbInterface)
1297 hr = IVBSAXContentHandler_endPrefixMapping(
1298 This->saxreader->vbcontentHandler, &Prefix);
1300 hr = ISAXContentHandler_endPrefixMapping(
1301 This->saxreader->contentHandler,
1302 Prefix, SysStringLen(Prefix));
1306 format_error_message_from_id(This, hr);
1313 update_position(This, NULL);
1316 static void libxmlCharacters(
1321 saxlocator *This = ctx;
1326 BOOL lastEvent = FALSE;
1328 if(!(has_content_handler(This))) return;
1331 if(*(ch-1)=='\r') cur--;
1334 if(ch<This->pParserCtxt->input->base || ch>This->pParserCtxt->input->end)
1339 while(end-ch<len && *end!='\r') end++;
1346 if(!lastEvent) *end = '\n';
1348 Chars = pooled_bstr_from_xmlCharN(&This->saxreader->pool, cur, end-cur+1);
1349 if(This->vbInterface)
1350 hr = IVBSAXContentHandler_characters(
1351 This->saxreader->vbcontentHandler, &Chars);
1353 hr = ISAXContentHandler_characters(
1354 This->saxreader->contentHandler,
1355 Chars, SysStringLen(Chars));
1359 format_error_message_from_id(This, hr);
1363 This->column += end-cur+1;
1377 if(end-ch == len) break;
1380 if(ch<This->pParserCtxt->input->base || ch>This->pParserCtxt->input->end)
1381 This->column = This->realColumn
1382 +This->pParserCtxt->input->cur-This->lastCur;
1385 static void libxmlSetDocumentLocator(
1387 xmlSAXLocatorPtr loc)
1389 saxlocator *This = ctx;
1392 if(has_content_handler(This))
1394 if(This->vbInterface)
1395 hr = IVBSAXContentHandler_putref_documentLocator(This->saxreader->vbcontentHandler,
1396 &This->IVBSAXLocator_iface);
1398 hr = ISAXContentHandler_putDocumentLocator(This->saxreader->contentHandler,
1399 &This->ISAXLocator_iface);
1403 format_error_message_from_id(This, hr);
1406 static void libxmlComment(void *ctx, const xmlChar *value)
1408 saxlocator *This = ctx;
1411 xmlChar *beg = (xmlChar*)This->pParserCtxt->input->cur;
1413 while(beg-4>=This->pParserCtxt->input->base
1414 && memcmp(beg-4, "<!--", sizeof(char[4]))) beg--;
1415 update_position(This, beg);
1417 if(!This->vbInterface && !This->saxreader->lexicalHandler) return;
1418 if(This->vbInterface && !This->saxreader->vblexicalHandler) return;
1420 bValue = pooled_bstr_from_xmlChar(&This->saxreader->pool, value);
1422 if(This->vbInterface)
1423 hr = IVBSAXLexicalHandler_comment(
1424 This->saxreader->vblexicalHandler, &bValue);
1426 hr = ISAXLexicalHandler_comment(
1427 This->saxreader->lexicalHandler,
1428 bValue, SysStringLen(bValue));
1431 format_error_message_from_id(This, hr);
1433 update_position(This, NULL);
1436 static void libxmlFatalError(void *ctx, const char *msg, ...)
1438 saxlocator *This = ctx;
1444 va_start(args, msg);
1445 vsprintf(message, msg, args);
1448 len = MultiByteToWideChar(CP_UNIXCP, 0, message, -1, NULL, 0);
1449 error = heap_alloc(sizeof(WCHAR)*len);
1452 MultiByteToWideChar(CP_UNIXCP, 0, message, -1, error, len);
1453 TRACE("fatal error for %p: %s\n", This, debugstr_w(error));
1456 if(!has_error_handler(This))
1458 xmlStopParser(This->pParserCtxt);
1464 FIXME("Error handling is not compatible.\n");
1466 if(This->vbInterface)
1468 BSTR bstrError = SysAllocString(error);
1469 IVBSAXErrorHandler_fatalError(This->saxreader->vberrorHandler, &This->IVBSAXLocator_iface,
1470 &bstrError, E_FAIL);
1471 SysFreeString(bstrError);
1474 ISAXErrorHandler_fatalError(This->saxreader->errorHandler, &This->ISAXLocator_iface,
1479 xmlStopParser(This->pParserCtxt);
1483 static void libxmlCDataBlock(void *ctx, const xmlChar *value, int len)
1485 saxlocator *This = ctx;
1487 xmlChar *beg = (xmlChar*)This->pParserCtxt->input->cur-len;
1491 BOOL lastEvent = FALSE, change;
1493 while(beg-9>=This->pParserCtxt->input->base
1494 && memcmp(beg-9, "<![CDATA[", sizeof(char[9]))) beg--;
1495 update_position(This, beg);
1497 if(This->vbInterface && This->saxreader->vblexicalHandler)
1498 hr = IVBSAXLexicalHandler_startCDATA(This->saxreader->vblexicalHandler);
1499 if(!This->vbInterface && This->saxreader->lexicalHandler)
1500 hr = ISAXLexicalHandler_startCDATA(This->saxreader->lexicalHandler);
1504 format_error_message_from_id(This, hr);
1508 realLen = This->pParserCtxt->input->cur-beg-3;
1514 while(end-beg<realLen && *end!='\r') end++;
1515 if(end-beg==realLen)
1520 else if(end-beg==realLen-1 && *end=='\r' && *(end+1)=='\n')
1523 if(*end == '\r') change = TRUE;
1524 else change = FALSE;
1526 if(change) *end = '\n';
1528 if(has_content_handler(This))
1530 Chars = pooled_bstr_from_xmlCharN(&This->saxreader->pool, cur, end-cur+1);
1531 if(This->vbInterface)
1532 hr = IVBSAXContentHandler_characters(
1533 This->saxreader->vbcontentHandler, &Chars);
1535 hr = ISAXContentHandler_characters(
1536 This->saxreader->contentHandler,
1537 Chars, SysStringLen(Chars));
1540 if(change) *end = '\r';
1545 This->column += end-cur+2;
1550 if(This->vbInterface && This->saxreader->vblexicalHandler)
1551 hr = IVBSAXLexicalHandler_endCDATA(This->saxreader->vblexicalHandler);
1552 if(!This->vbInterface && This->saxreader->lexicalHandler)
1553 hr = ISAXLexicalHandler_endCDATA(This->saxreader->lexicalHandler);
1556 format_error_message_from_id(This, hr);
1558 This->column += 4+end-cur;
1561 /*** IVBSAXLocator interface ***/
1562 /*** IUnknown methods ***/
1563 static HRESULT WINAPI ivbsaxlocator_QueryInterface(IVBSAXLocator* iface, REFIID riid, void **ppvObject)
1565 saxlocator *This = impl_from_IVBSAXLocator( iface );
1567 TRACE("%p %s %p\n", This, debugstr_guid( riid ), ppvObject);
1571 if ( IsEqualGUID( riid, &IID_IUnknown ) ||
1572 IsEqualGUID( riid, &IID_IDispatch) ||
1573 IsEqualGUID( riid, &IID_IVBSAXLocator ))
1579 FIXME("interface %s not implemented\n", debugstr_guid(riid));
1580 return E_NOINTERFACE;
1583 IVBSAXLocator_AddRef( iface );
1588 static ULONG WINAPI ivbsaxlocator_AddRef(IVBSAXLocator* iface)
1590 saxlocator *This = impl_from_IVBSAXLocator( iface );
1591 TRACE("%p\n", This );
1592 return InterlockedIncrement( &This->ref );
1595 static ULONG WINAPI ivbsaxlocator_Release(
1596 IVBSAXLocator* iface)
1598 saxlocator *This = impl_from_IVBSAXLocator( iface );
1599 return ISAXLocator_Release((ISAXLocator*)&This->IVBSAXLocator_iface);
1602 /*** IDispatch methods ***/
1603 static HRESULT WINAPI ivbsaxlocator_GetTypeInfoCount( IVBSAXLocator *iface, UINT* pctinfo )
1605 saxlocator *This = impl_from_IVBSAXLocator( iface );
1607 TRACE("(%p)->(%p)\n", This, pctinfo);
1614 static HRESULT WINAPI ivbsaxlocator_GetTypeInfo(
1615 IVBSAXLocator *iface,
1616 UINT iTInfo, LCID lcid, ITypeInfo** ppTInfo )
1618 saxlocator *This = impl_from_IVBSAXLocator( iface );
1621 TRACE("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo);
1623 hr = get_typeinfo(IVBSAXLocator_tid, ppTInfo);
1628 static HRESULT WINAPI ivbsaxlocator_GetIDsOfNames(
1629 IVBSAXLocator *iface,
1631 LPOLESTR* rgszNames,
1636 saxlocator *This = impl_from_IVBSAXLocator( iface );
1637 ITypeInfo *typeinfo;
1640 TRACE("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames, cNames,
1643 if(!rgszNames || cNames == 0 || !rgDispId)
1644 return E_INVALIDARG;
1646 hr = get_typeinfo(IVBSAXLocator_tid, &typeinfo);
1649 hr = ITypeInfo_GetIDsOfNames(typeinfo, rgszNames, cNames, rgDispId);
1650 ITypeInfo_Release(typeinfo);
1656 static HRESULT WINAPI ivbsaxlocator_Invoke(
1657 IVBSAXLocator *iface,
1658 DISPID dispIdMember,
1662 DISPPARAMS* pDispParams,
1663 VARIANT* pVarResult,
1664 EXCEPINFO* pExcepInfo,
1667 saxlocator *This = impl_from_IVBSAXLocator( iface );
1668 ITypeInfo *typeinfo;
1671 TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
1672 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
1674 hr = get_typeinfo(IVBSAXLocator_tid, &typeinfo);
1677 hr = ITypeInfo_Invoke(typeinfo, &This->IVBSAXLocator_iface, dispIdMember, wFlags,
1678 pDispParams, pVarResult, pExcepInfo, puArgErr);
1679 ITypeInfo_Release(typeinfo);
1685 /*** IVBSAXLocator methods ***/
1686 static HRESULT WINAPI ivbsaxlocator_get_columnNumber(
1687 IVBSAXLocator* iface,
1690 saxlocator *This = impl_from_IVBSAXLocator( iface );
1691 return ISAXLocator_getColumnNumber((ISAXLocator*)&This->IVBSAXLocator_iface, pnColumn);
1694 static HRESULT WINAPI ivbsaxlocator_get_lineNumber(
1695 IVBSAXLocator* iface,
1698 saxlocator *This = impl_from_IVBSAXLocator( iface );
1699 return ISAXLocator_getLineNumber((ISAXLocator*)&This->IVBSAXLocator_iface, pnLine);
1702 static HRESULT WINAPI ivbsaxlocator_get_publicId(
1703 IVBSAXLocator* iface,
1706 saxlocator *This = impl_from_IVBSAXLocator( iface );
1707 return ISAXLocator_getPublicId((ISAXLocator*)&This->IVBSAXLocator_iface,
1708 (const WCHAR**)publicId);
1711 static HRESULT WINAPI ivbsaxlocator_get_systemId(
1712 IVBSAXLocator* iface,
1715 saxlocator *This = impl_from_IVBSAXLocator( iface );
1716 return ISAXLocator_getSystemId((ISAXLocator*)&This->IVBSAXLocator_iface,
1717 (const WCHAR**)systemId);
1720 static const struct IVBSAXLocatorVtbl ivbsaxlocator_vtbl =
1722 ivbsaxlocator_QueryInterface,
1723 ivbsaxlocator_AddRef,
1724 ivbsaxlocator_Release,
1725 ivbsaxlocator_GetTypeInfoCount,
1726 ivbsaxlocator_GetTypeInfo,
1727 ivbsaxlocator_GetIDsOfNames,
1728 ivbsaxlocator_Invoke,
1729 ivbsaxlocator_get_columnNumber,
1730 ivbsaxlocator_get_lineNumber,
1731 ivbsaxlocator_get_publicId,
1732 ivbsaxlocator_get_systemId
1735 /*** ISAXLocator interface ***/
1736 /*** IUnknown methods ***/
1737 static HRESULT WINAPI isaxlocator_QueryInterface(ISAXLocator* iface, REFIID riid, void **ppvObject)
1739 saxlocator *This = impl_from_ISAXLocator( iface );
1741 TRACE("%p %s %p\n", This, debugstr_guid( riid ), ppvObject );
1745 if ( IsEqualGUID( riid, &IID_IUnknown ) ||
1746 IsEqualGUID( riid, &IID_ISAXLocator ))
1752 FIXME("interface %s not implemented\n", debugstr_guid(riid));
1753 return E_NOINTERFACE;
1756 ISAXLocator_AddRef( iface );
1761 static ULONG WINAPI isaxlocator_AddRef(ISAXLocator* iface)
1763 saxlocator *This = impl_from_ISAXLocator( iface );
1764 TRACE("%p\n", This );
1765 return InterlockedIncrement( &This->ref );
1768 static ULONG WINAPI isaxlocator_Release(
1771 saxlocator *This = impl_from_ISAXLocator( iface );
1774 TRACE("%p\n", This );
1776 ref = InterlockedDecrement( &This->ref );
1779 SysFreeString(This->publicId);
1780 SysFreeString(This->systemId);
1781 heap_free(This->nsStack);
1783 ISAXXMLReader_Release(&This->saxreader->ISAXXMLReader_iface);
1790 /*** ISAXLocator methods ***/
1791 static HRESULT WINAPI isaxlocator_getColumnNumber(
1795 saxlocator *This = impl_from_ISAXLocator( iface );
1797 *pnColumn = This->column;
1801 static HRESULT WINAPI isaxlocator_getLineNumber(
1805 saxlocator *This = impl_from_ISAXLocator( iface );
1807 *pnLine = This->line;
1811 static HRESULT WINAPI isaxlocator_getPublicId(
1813 const WCHAR ** ppwchPublicId)
1816 saxlocator *This = impl_from_ISAXLocator( iface );
1818 SysFreeString(This->publicId);
1820 publicId = bstr_from_xmlChar(xmlSAX2GetPublicId(This->pParserCtxt));
1821 if(SysStringLen(publicId))
1822 This->publicId = (WCHAR*)&publicId;
1825 SysFreeString(publicId);
1826 This->publicId = NULL;
1829 *ppwchPublicId = This->publicId;
1833 static HRESULT WINAPI isaxlocator_getSystemId(
1835 const WCHAR ** ppwchSystemId)
1838 saxlocator *This = impl_from_ISAXLocator( iface );
1840 SysFreeString(This->systemId);
1842 systemId = bstr_from_xmlChar(xmlSAX2GetSystemId(This->pParserCtxt));
1843 if(SysStringLen(systemId))
1844 This->systemId = (WCHAR*)&systemId;
1847 SysFreeString(systemId);
1848 This->systemId = NULL;
1851 *ppwchSystemId = This->systemId;
1855 static const struct ISAXLocatorVtbl isaxlocator_vtbl =
1857 isaxlocator_QueryInterface,
1859 isaxlocator_Release,
1860 isaxlocator_getColumnNumber,
1861 isaxlocator_getLineNumber,
1862 isaxlocator_getPublicId,
1863 isaxlocator_getSystemId
1866 static HRESULT SAXLocator_create(saxreader *reader, saxlocator **ppsaxlocator, BOOL vbInterface)
1868 saxlocator *locator;
1870 locator = heap_alloc( sizeof (*locator) );
1872 return E_OUTOFMEMORY;
1874 locator->IVBSAXLocator_iface.lpVtbl = &ivbsaxlocator_vtbl;
1875 locator->ISAXLocator_iface.lpVtbl = &isaxlocator_vtbl;
1877 locator->vbInterface = vbInterface;
1879 locator->saxreader = reader;
1880 ISAXXMLReader_AddRef(&reader->ISAXXMLReader_iface);
1882 locator->pParserCtxt = NULL;
1883 locator->publicId = NULL;
1884 locator->systemId = NULL;
1885 locator->lastCur = NULL;
1887 locator->column = 0;
1888 locator->ret = S_OK;
1889 locator->nsStackSize = 8;
1890 locator->nsStackLast = 0;
1891 locator->nsStack = heap_alloc(sizeof(int)*locator->nsStackSize);
1892 if(!locator->nsStack)
1894 ISAXXMLReader_Release(&reader->ISAXXMLReader_iface);
1896 return E_OUTOFMEMORY;
1899 *ppsaxlocator = locator;
1901 TRACE("returning %p\n", *ppsaxlocator);
1906 /*** SAXXMLReader internal functions ***/
1907 static HRESULT internal_parseBuffer(saxreader *This, const char *buffer, int size, BOOL vbInterface)
1909 xmlCharEncoding encoding = XML_CHAR_ENCODING_NONE;
1910 xmlChar *enc_name = NULL;
1911 saxlocator *locator;
1914 hr = SAXLocator_create(This, &locator, vbInterface);
1920 const unsigned char *buff = (unsigned char*)buffer;
1922 encoding = xmlDetectCharEncoding((xmlChar*)buffer, 4);
1923 enc_name = (xmlChar*)xmlGetCharEncodingName(encoding);
1924 TRACE("detected encoding: %s\n", enc_name);
1925 /* skip BOM, parser won't switch encodings and so won't skip it on its own */
1926 if ((encoding == XML_CHAR_ENCODING_UTF8) &&
1927 buff[0] == 0xEF && buff[1] == 0xBB && buff[2] == 0xBF)
1934 locator->pParserCtxt = xmlCreateMemoryParserCtxt(buffer, size);
1935 if(!locator->pParserCtxt)
1937 ISAXLocator_Release(&locator->ISAXLocator_iface);
1941 if (encoding == XML_CHAR_ENCODING_UTF8)
1942 locator->pParserCtxt->encoding = xmlStrdup(enc_name);
1944 xmlFree(locator->pParserCtxt->sax);
1945 locator->pParserCtxt->sax = &locator->saxreader->sax;
1946 locator->pParserCtxt->userData = locator;
1948 This->isParsing = TRUE;
1949 if(xmlParseDocument(locator->pParserCtxt) == -1) hr = E_FAIL;
1950 else hr = locator->ret;
1951 This->isParsing = FALSE;
1953 if(locator->pParserCtxt)
1955 locator->pParserCtxt->sax = NULL;
1956 xmlFreeParserCtxt(locator->pParserCtxt);
1957 locator->pParserCtxt = NULL;
1960 ISAXLocator_Release(&locator->ISAXLocator_iface);
1964 static HRESULT internal_parseStream(saxreader *This, IStream *stream, BOOL vbInterface)
1966 saxlocator *locator;
1973 hr = IStream_Read(stream, data, sizeof(data), &dataRead);
1974 if(FAILED(hr)) return hr;
1976 hr = SAXLocator_create(This, &locator, vbInterface);
1977 if(FAILED(hr)) return hr;
1979 locator->pParserCtxt = xmlCreatePushParserCtxt(
1980 &locator->saxreader->sax, locator,
1981 data, dataRead, NULL);
1982 if(!locator->pParserCtxt)
1984 ISAXLocator_Release(&locator->ISAXLocator_iface);
1988 This->isParsing = TRUE;
1990 if(dataRead != sizeof(data))
1992 ret = xmlParseChunk(locator->pParserCtxt, data, 0, 1);
1993 hr = ret != XML_ERR_OK ? E_FAIL : locator->ret;
2000 hr = IStream_Read(stream, data, sizeof(data), &dataRead);
2001 if (FAILED(hr)) break;
2003 ret = xmlParseChunk(locator->pParserCtxt, data, dataRead, 0);
2004 hr = ret != XML_ERR_OK ? E_FAIL : locator->ret;
2006 if (hr != S_OK) break;
2008 if (dataRead != sizeof(data))
2010 ret = xmlParseChunk(locator->pParserCtxt, data, 0, 1);
2011 hr = ret != XML_ERR_OK ? E_FAIL : locator->ret;
2017 This->isParsing = FALSE;
2019 xmlFreeParserCtxt(locator->pParserCtxt);
2020 locator->pParserCtxt = NULL;
2021 ISAXLocator_Release(&locator->ISAXLocator_iface);
2025 static HRESULT internal_getEntityResolver(
2027 void *pEntityResolver,
2030 FIXME("(%p)->(%p) stub\n", This, pEntityResolver);
2034 static HRESULT internal_putEntityResolver(
2036 void *pEntityResolver,
2039 FIXME("(%p)->(%p) stub\n", This, pEntityResolver);
2043 static HRESULT internal_getContentHandler(
2045 void *pContentHandler,
2048 TRACE("(%p)->(%p)\n", This, pContentHandler);
2049 if(pContentHandler == NULL)
2051 if((vbInterface && This->vbcontentHandler)
2052 || (!vbInterface && This->contentHandler))
2055 IVBSAXContentHandler_AddRef(This->vbcontentHandler);
2057 ISAXContentHandler_AddRef(This->contentHandler);
2059 if(vbInterface) *(IVBSAXContentHandler**)pContentHandler =
2060 This->vbcontentHandler;
2061 else *(ISAXContentHandler**)pContentHandler = This->contentHandler;
2066 static HRESULT internal_putContentHandler(
2068 void *contentHandler,
2071 TRACE("(%p)->(%p)\n", This, contentHandler);
2075 IVBSAXContentHandler_AddRef((IVBSAXContentHandler*)contentHandler);
2077 ISAXContentHandler_AddRef((ISAXContentHandler*)contentHandler);
2079 if((vbInterface && This->vbcontentHandler)
2080 || (!vbInterface && This->contentHandler))
2083 IVBSAXContentHandler_Release(This->vbcontentHandler);
2085 ISAXContentHandler_Release(This->contentHandler);
2088 This->vbcontentHandler = contentHandler;
2090 This->contentHandler = contentHandler;
2095 static HRESULT internal_getDTDHandler(
2100 FIXME("(%p)->(%p) stub\n", This, pDTDHandler);
2104 static HRESULT internal_putDTDHandler(
2109 FIXME("(%p)->(%p) stub\n", This, pDTDHandler);
2113 static HRESULT internal_getErrorHandler(
2115 void *pErrorHandler,
2118 TRACE("(%p)->(%p)\n", This, pErrorHandler);
2119 if(pErrorHandler == NULL)
2122 if(vbInterface && This->vberrorHandler)
2123 IVBSAXErrorHandler_AddRef(This->vberrorHandler);
2124 else if(!vbInterface && This->errorHandler)
2125 ISAXErrorHandler_AddRef(This->errorHandler);
2128 *(IVBSAXErrorHandler**)pErrorHandler = This->vberrorHandler;
2130 *(ISAXErrorHandler**)pErrorHandler = This->errorHandler;
2136 static HRESULT internal_putErrorHandler(
2141 TRACE("(%p)->(%p)\n", This, errorHandler);
2145 IVBSAXErrorHandler_AddRef((IVBSAXErrorHandler*)errorHandler);
2147 ISAXErrorHandler_AddRef((ISAXErrorHandler*)errorHandler);
2150 if(vbInterface && This->vberrorHandler)
2151 IVBSAXErrorHandler_Release(This->vberrorHandler);
2152 else if(!vbInterface && This->errorHandler)
2153 ISAXErrorHandler_Release(This->errorHandler);
2156 This->vberrorHandler = errorHandler;
2158 This->errorHandler = errorHandler;
2164 static HRESULT internal_parse(
2171 TRACE("(%p)->(%s)\n", This, debugstr_variant(&varInput));
2173 /* Dispose of the BSTRs in the pool from a prior run, if any. */
2174 free_bstr_pool(&This->pool);
2176 switch(V_VT(&varInput))
2179 hr = internal_parseBuffer(This, (const char*)V_BSTR(&varInput),
2180 SysStringByteLen(V_BSTR(&varInput)), vbInterface);
2182 case VT_ARRAY|VT_UI1: {
2184 LONG lBound, uBound;
2187 hr = SafeArrayGetLBound(V_ARRAY(&varInput), 1, &lBound);
2188 if(hr != S_OK) break;
2189 hr = SafeArrayGetUBound(V_ARRAY(&varInput), 1, &uBound);
2190 if(hr != S_OK) break;
2191 dataRead = (uBound-lBound)*SafeArrayGetElemsize(V_ARRAY(&varInput));
2192 hr = SafeArrayAccessData(V_ARRAY(&varInput), &pSAData);
2193 if(hr != S_OK) break;
2194 hr = internal_parseBuffer(This, pSAData, dataRead, vbInterface);
2195 SafeArrayUnaccessData(V_ARRAY(&varInput));
2200 IPersistStream *persistStream;
2201 IStream *stream = NULL;
2202 IXMLDOMDocument *xmlDoc;
2204 if(IUnknown_QueryInterface(V_UNKNOWN(&varInput),
2205 &IID_IXMLDOMDocument, (void**)&xmlDoc) == S_OK)
2209 IXMLDOMDocument_get_xml(xmlDoc, &bstrData);
2210 hr = internal_parseBuffer(This, (const char*)bstrData,
2211 SysStringByteLen(bstrData), vbInterface);
2212 IXMLDOMDocument_Release(xmlDoc);
2213 SysFreeString(bstrData);
2217 if(IUnknown_QueryInterface(V_UNKNOWN(&varInput),
2218 &IID_IPersistStream, (void**)&persistStream) == S_OK)
2220 hr = CreateStreamOnHGlobal(NULL, TRUE, &stream);
2223 IPersistStream_Release(persistStream);
2227 hr = IPersistStream_Save(persistStream, stream, TRUE);
2228 IPersistStream_Release(persistStream);
2231 IStream_Release(stream);
2235 if(stream || IUnknown_QueryInterface(V_UNKNOWN(&varInput),
2236 &IID_IStream, (void**)&stream) == S_OK)
2238 hr = internal_parseStream(This, stream, vbInterface);
2239 IStream_Release(stream);
2244 WARN("vt %d not implemented\n", V_VT(&varInput));
2251 static HRESULT internal_vbonDataAvailable(void *obj, char *ptr, DWORD len)
2253 saxreader *This = obj;
2255 return internal_parseBuffer(This, ptr, len, TRUE);
2258 static HRESULT internal_onDataAvailable(void *obj, char *ptr, DWORD len)
2260 saxreader *This = obj;
2262 return internal_parseBuffer(This, ptr, len, FALSE);
2265 static HRESULT internal_parseURL(
2273 TRACE("(%p)->(%s)\n", This, debugstr_w(url));
2275 if(vbInterface) hr = bind_url(url, internal_vbonDataAvailable, This, &bsc);
2276 else hr = bind_url(url, internal_onDataAvailable, This, &bsc);
2286 static HRESULT internal_putProperty(
2292 TRACE("(%p)->(%s %s)\n", This, debugstr_w(prop), debugstr_variant(&value));
2294 if(!memcmp(prop, PropertyDeclHandlerW, sizeof(PropertyDeclHandlerW)))
2296 if(This->isParsing) return E_FAIL;
2298 switch (V_VT(&value))
2303 if (This->vbdeclHandler)
2305 IVBSAXDeclHandler_Release(This->vbdeclHandler);
2306 This->vbdeclHandler = NULL;
2310 if (This->declHandler)
2312 ISAXDeclHandler_Release(This->declHandler);
2313 This->declHandler = NULL;
2317 if (V_UNKNOWN(&value)) IUnknown_AddRef(V_UNKNOWN(&value));
2319 if ((vbInterface && This->vbdeclHandler) ||
2320 (!vbInterface && This->declHandler))
2323 IVBSAXDeclHandler_Release(This->vbdeclHandler);
2325 ISAXDeclHandler_Release(This->declHandler);
2329 This->vbdeclHandler = (IVBSAXDeclHandler*)V_UNKNOWN(&value);
2331 This->declHandler = (ISAXDeclHandler*)V_UNKNOWN(&value);
2334 return E_INVALIDARG;
2340 if(!memcmp(prop, PropertyLexicalHandlerW, sizeof(PropertyLexicalHandlerW)))
2342 if(This->isParsing) return E_FAIL;
2344 switch (V_VT(&value))
2349 if (This->vblexicalHandler)
2351 IVBSAXLexicalHandler_Release(This->vblexicalHandler);
2352 This->vblexicalHandler = NULL;
2356 if (This->lexicalHandler)
2358 ISAXLexicalHandler_Release(This->lexicalHandler);
2359 This->lexicalHandler = NULL;
2363 if (V_UNKNOWN(&value)) IUnknown_AddRef(V_UNKNOWN(&value));
2365 if ((vbInterface && This->vblexicalHandler) ||
2366 (!vbInterface && This->lexicalHandler))
2369 IVBSAXLexicalHandler_Release(This->vblexicalHandler);
2371 ISAXLexicalHandler_Release(This->lexicalHandler);
2375 This->vblexicalHandler = (IVBSAXLexicalHandler*)V_UNKNOWN(&value);
2377 This->lexicalHandler = (ISAXLexicalHandler*)V_UNKNOWN(&value);
2380 return E_INVALIDARG;
2386 if(!memcmp(prop, PropertyMaxXMLSizeW, sizeof(PropertyMaxXMLSizeW)))
2388 if (V_VT(&value) == VT_I4 && V_I4(&value) == 0) return S_OK;
2389 FIXME("(%p)->(%s): max-xml-size unsupported\n", This, debugstr_variant(&value));
2393 FIXME("(%p)->(%s:%s): unsupported property\n", This, debugstr_w(prop), debugstr_variant(&value));
2395 if(!memcmp(prop, PropertyCharsetW, sizeof(PropertyCharsetW)))
2398 if(!memcmp(prop, PropertyDomNodeW, sizeof(PropertyDomNodeW)))
2401 if(!memcmp(prop, PropertyInputSourceW, sizeof(PropertyInputSourceW)))
2404 if(!memcmp(prop, PropertyMaxElementDepthW, sizeof(PropertyMaxElementDepthW)))
2407 if(!memcmp(prop, PropertySchemaDeclHandlerW, sizeof(PropertySchemaDeclHandlerW)))
2410 if(!memcmp(prop, PropertyXMLDeclEncodingW, sizeof(PropertyXMLDeclEncodingW)))
2413 if(!memcmp(prop, PropertyXMLDeclStandaloneW, sizeof(PropertyXMLDeclStandaloneW)))
2416 if(!memcmp(prop, PropertyXMLDeclVersionW, sizeof(PropertyXMLDeclVersionW)))
2419 return E_INVALIDARG;
2422 static HRESULT internal_getProperty(const saxreader* This, const WCHAR *prop, VARIANT *value, BOOL vb)
2424 TRACE("(%p)->(%s)\n", This, debugstr_w(prop));
2426 if (!value) return E_POINTER;
2428 if (!memcmp(PropertyLexicalHandlerW, prop, sizeof(PropertyLexicalHandlerW)))
2430 V_VT(value) = VT_UNKNOWN;
2431 V_UNKNOWN(value) = vb ? (IUnknown*)This->vblexicalHandler : (IUnknown*)This->lexicalHandler;
2432 if (V_UNKNOWN(value)) IUnknown_AddRef(V_UNKNOWN(value));
2436 if (!memcmp(PropertyDeclHandlerW, prop, sizeof(PropertyDeclHandlerW)))
2438 V_VT(value) = VT_UNKNOWN;
2439 V_UNKNOWN(value) = vb ? (IUnknown*)This->vbdeclHandler : (IUnknown*)This->declHandler;
2440 if (V_UNKNOWN(value)) IUnknown_AddRef(V_UNKNOWN(value));
2444 FIXME("(%p)->(%s) unsupported property\n", This, debugstr_w(prop));
2449 /*** IVBSAXXMLReader interface ***/
2450 /*** IUnknown methods ***/
2451 static HRESULT WINAPI saxxmlreader_QueryInterface(IVBSAXXMLReader* iface, REFIID riid, void **ppvObject)
2453 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2455 TRACE("%p %s %p\n", This, debugstr_guid( riid ), ppvObject );
2459 if ( IsEqualGUID( riid, &IID_IUnknown ) ||
2460 IsEqualGUID( riid, &IID_IDispatch ) ||
2461 IsEqualGUID( riid, &IID_IVBSAXXMLReader ))
2465 else if( IsEqualGUID( riid, &IID_ISAXXMLReader ))
2467 *ppvObject = &This->ISAXXMLReader_iface;
2471 FIXME("interface %s not implemented\n", debugstr_guid(riid));
2472 return E_NOINTERFACE;
2475 IVBSAXXMLReader_AddRef( iface );
2480 static ULONG WINAPI saxxmlreader_AddRef(IVBSAXXMLReader* iface)
2482 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2483 TRACE("%p\n", This );
2484 return InterlockedIncrement( &This->ref );
2487 static ULONG WINAPI saxxmlreader_Release(
2488 IVBSAXXMLReader* iface)
2490 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2493 TRACE("%p\n", This );
2495 ref = InterlockedDecrement( &This->ref );
2498 if(This->contentHandler)
2499 ISAXContentHandler_Release(This->contentHandler);
2501 if(This->vbcontentHandler)
2502 IVBSAXContentHandler_Release(This->vbcontentHandler);
2504 if(This->errorHandler)
2505 ISAXErrorHandler_Release(This->errorHandler);
2507 if(This->vberrorHandler)
2508 IVBSAXErrorHandler_Release(This->vberrorHandler);
2510 if(This->lexicalHandler)
2511 ISAXLexicalHandler_Release(This->lexicalHandler);
2513 if(This->vblexicalHandler)
2514 IVBSAXLexicalHandler_Release(This->vblexicalHandler);
2516 if(This->declHandler)
2517 ISAXDeclHandler_Release(This->declHandler);
2519 if(This->vbdeclHandler)
2520 IVBSAXDeclHandler_Release(This->vbdeclHandler);
2522 free_bstr_pool(&This->pool);
2530 static HRESULT WINAPI saxxmlreader_GetTypeInfoCount( IVBSAXXMLReader *iface, UINT* pctinfo )
2532 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2534 TRACE("(%p)->(%p)\n", This, pctinfo);
2541 static HRESULT WINAPI saxxmlreader_GetTypeInfo(
2542 IVBSAXXMLReader *iface,
2543 UINT iTInfo, LCID lcid, ITypeInfo** ppTInfo )
2545 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2548 TRACE("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo);
2550 hr = get_typeinfo(IVBSAXXMLReader_tid, ppTInfo);
2555 static HRESULT WINAPI saxxmlreader_GetIDsOfNames(
2556 IVBSAXXMLReader *iface,
2558 LPOLESTR* rgszNames,
2563 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2564 ITypeInfo *typeinfo;
2567 TRACE("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames, cNames,
2570 if(!rgszNames || cNames == 0 || !rgDispId)
2571 return E_INVALIDARG;
2573 hr = get_typeinfo(IVBSAXXMLReader_tid, &typeinfo);
2576 hr = ITypeInfo_GetIDsOfNames(typeinfo, rgszNames, cNames, rgDispId);
2577 ITypeInfo_Release(typeinfo);
2583 static HRESULT WINAPI saxxmlreader_Invoke(
2584 IVBSAXXMLReader *iface,
2585 DISPID dispIdMember,
2589 DISPPARAMS* pDispParams,
2590 VARIANT* pVarResult,
2591 EXCEPINFO* pExcepInfo,
2594 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2595 ITypeInfo *typeinfo;
2598 TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
2599 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
2601 hr = get_typeinfo(IVBSAXXMLReader_tid, &typeinfo);
2604 hr = ITypeInfo_Invoke(typeinfo, &This->IVBSAXXMLReader_iface, dispIdMember, wFlags,
2605 pDispParams, pVarResult, pExcepInfo, puArgErr);
2606 ITypeInfo_Release(typeinfo);
2612 /*** IVBSAXXMLReader methods ***/
2613 static HRESULT WINAPI saxxmlreader_getFeature(
2614 IVBSAXXMLReader* iface,
2615 const WCHAR *pFeature,
2616 VARIANT_BOOL *pValue)
2618 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2620 FIXME("(%p)->(%s %p) stub\n", This, debugstr_w(pFeature), pValue);
2624 static HRESULT WINAPI saxxmlreader_putFeature(
2625 IVBSAXXMLReader* iface,
2626 const WCHAR *feature,
2629 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2631 TRACE("(%p)->(%s %x)\n", This, debugstr_w(feature), value);
2633 if (!strcmpW(FeatureExternalGeneralEntitiesW, feature) && value == VARIANT_FALSE)
2634 return set_feature_value(This, ExternalGeneralEntities, value);
2636 if (!strcmpW(FeatureExternalParameterEntitiesW, feature) && value == VARIANT_FALSE)
2637 return set_feature_value(This, ExternalParameterEntities, value);
2639 if (!strcmpW(FeatureLexicalHandlerParEntitiesW, feature))
2641 FIXME("(%p)->(%s %x) stub\n", This, debugstr_w(feature), value);
2642 return set_feature_value(This, LexicalHandlerParEntities, value);
2645 if (!strcmpW(FeatureProhibitDTDW, feature))
2647 FIXME("(%p)->(%s %x) stub\n", This, debugstr_w(feature), value);
2648 return set_feature_value(This, ProhibitDTD, value);
2651 FIXME("(%p)->(%s %x) stub\n", This, debugstr_w(feature), value);
2655 static HRESULT WINAPI saxxmlreader_getProperty(
2656 IVBSAXXMLReader* iface,
2660 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2661 return internal_getProperty(This, prop, value, TRUE);
2664 static HRESULT WINAPI saxxmlreader_putProperty(
2665 IVBSAXXMLReader* iface,
2669 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2670 return internal_putProperty(This, pProp, value, TRUE);
2673 static HRESULT WINAPI saxxmlreader_get_entityResolver(
2674 IVBSAXXMLReader* iface,
2675 IVBSAXEntityResolver **pEntityResolver)
2677 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2678 return internal_getEntityResolver(This, pEntityResolver, TRUE);
2681 static HRESULT WINAPI saxxmlreader_put_entityResolver(
2682 IVBSAXXMLReader* iface,
2683 IVBSAXEntityResolver *pEntityResolver)
2685 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2686 return internal_putEntityResolver(This, pEntityResolver, TRUE);
2689 static HRESULT WINAPI saxxmlreader_get_contentHandler(
2690 IVBSAXXMLReader* iface,
2691 IVBSAXContentHandler **ppContentHandler)
2693 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2694 return internal_getContentHandler(This, ppContentHandler, TRUE);
2697 static HRESULT WINAPI saxxmlreader_put_contentHandler(
2698 IVBSAXXMLReader* iface,
2699 IVBSAXContentHandler *contentHandler)
2701 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2702 return internal_putContentHandler(This, contentHandler, TRUE);
2705 static HRESULT WINAPI saxxmlreader_get_dtdHandler(
2706 IVBSAXXMLReader* iface,
2707 IVBSAXDTDHandler **pDTDHandler)
2709 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2710 return internal_getDTDHandler(This, pDTDHandler, TRUE);
2713 static HRESULT WINAPI saxxmlreader_put_dtdHandler(
2714 IVBSAXXMLReader* iface,
2715 IVBSAXDTDHandler *pDTDHandler)
2717 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2718 return internal_putDTDHandler(This, pDTDHandler, TRUE);
2721 static HRESULT WINAPI saxxmlreader_get_errorHandler(
2722 IVBSAXXMLReader* iface,
2723 IVBSAXErrorHandler **pErrorHandler)
2725 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2726 return internal_getErrorHandler(This, pErrorHandler, TRUE);
2729 static HRESULT WINAPI saxxmlreader_put_errorHandler(
2730 IVBSAXXMLReader* iface,
2731 IVBSAXErrorHandler *errorHandler)
2733 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2734 return internal_putErrorHandler(This, errorHandler, TRUE);
2737 static HRESULT WINAPI saxxmlreader_get_baseURL(
2738 IVBSAXXMLReader* iface,
2739 const WCHAR **pBaseUrl)
2741 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2743 FIXME("(%p)->(%p) stub\n", This, pBaseUrl);
2747 static HRESULT WINAPI saxxmlreader_put_baseURL(
2748 IVBSAXXMLReader* iface,
2749 const WCHAR *pBaseUrl)
2751 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2753 FIXME("(%p)->(%s) stub\n", This, debugstr_w(pBaseUrl));
2757 static HRESULT WINAPI saxxmlreader_get_secureBaseURL(
2758 IVBSAXXMLReader* iface,
2759 const WCHAR **pSecureBaseUrl)
2761 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2763 FIXME("(%p)->(%p) stub\n", This, pSecureBaseUrl);
2768 static HRESULT WINAPI saxxmlreader_put_secureBaseURL(
2769 IVBSAXXMLReader* iface,
2770 const WCHAR *secureBaseUrl)
2772 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2774 FIXME("(%p)->(%s) stub\n", This, debugstr_w(secureBaseUrl));
2778 static HRESULT WINAPI saxxmlreader_parse(
2779 IVBSAXXMLReader* iface,
2782 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2783 return internal_parse(This, varInput, TRUE);
2786 static HRESULT WINAPI saxxmlreader_parseURL(
2787 IVBSAXXMLReader* iface,
2790 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2791 return internal_parseURL(This, url, TRUE);
2794 static const struct IVBSAXXMLReaderVtbl saxreader_vtbl =
2796 saxxmlreader_QueryInterface,
2797 saxxmlreader_AddRef,
2798 saxxmlreader_Release,
2799 saxxmlreader_GetTypeInfoCount,
2800 saxxmlreader_GetTypeInfo,
2801 saxxmlreader_GetIDsOfNames,
2802 saxxmlreader_Invoke,
2803 saxxmlreader_getFeature,
2804 saxxmlreader_putFeature,
2805 saxxmlreader_getProperty,
2806 saxxmlreader_putProperty,
2807 saxxmlreader_get_entityResolver,
2808 saxxmlreader_put_entityResolver,
2809 saxxmlreader_get_contentHandler,
2810 saxxmlreader_put_contentHandler,
2811 saxxmlreader_get_dtdHandler,
2812 saxxmlreader_put_dtdHandler,
2813 saxxmlreader_get_errorHandler,
2814 saxxmlreader_put_errorHandler,
2815 saxxmlreader_get_baseURL,
2816 saxxmlreader_put_baseURL,
2817 saxxmlreader_get_secureBaseURL,
2818 saxxmlreader_put_secureBaseURL,
2820 saxxmlreader_parseURL
2823 /*** ISAXXMLReader interface ***/
2824 /*** IUnknown methods ***/
2825 static HRESULT WINAPI isaxxmlreader_QueryInterface(ISAXXMLReader* iface, REFIID riid, void **ppvObject)
2827 saxreader *This = impl_from_ISAXXMLReader( iface );
2828 return saxxmlreader_QueryInterface(&This->IVBSAXXMLReader_iface, riid, ppvObject);
2831 static ULONG WINAPI isaxxmlreader_AddRef(ISAXXMLReader* iface)
2833 saxreader *This = impl_from_ISAXXMLReader( iface );
2834 return saxxmlreader_AddRef(&This->IVBSAXXMLReader_iface);
2837 static ULONG WINAPI isaxxmlreader_Release(ISAXXMLReader* iface)
2839 saxreader *This = impl_from_ISAXXMLReader( iface );
2840 return saxxmlreader_Release(&This->IVBSAXXMLReader_iface);
2843 /*** ISAXXMLReader methods ***/
2844 static HRESULT WINAPI isaxxmlreader_getFeature(
2845 ISAXXMLReader* iface,
2846 const WCHAR *pFeature,
2847 VARIANT_BOOL *pValue)
2849 saxreader *This = impl_from_ISAXXMLReader( iface );
2850 return IVBSAXXMLReader_getFeature(&This->IVBSAXXMLReader_iface, pFeature, pValue);
2853 static HRESULT WINAPI isaxxmlreader_putFeature(
2854 ISAXXMLReader* iface,
2855 const WCHAR *pFeature,
2856 VARIANT_BOOL vfValue)
2858 saxreader *This = impl_from_ISAXXMLReader( iface );
2859 return IVBSAXXMLReader_putFeature(&This->IVBSAXXMLReader_iface, pFeature, vfValue);
2862 static HRESULT WINAPI isaxxmlreader_getProperty(
2863 ISAXXMLReader* iface,
2867 saxreader *This = impl_from_ISAXXMLReader( iface );
2868 return internal_getProperty(This, prop, value, FALSE);
2871 static HRESULT WINAPI isaxxmlreader_putProperty(
2872 ISAXXMLReader* iface,
2876 saxreader *This = impl_from_ISAXXMLReader( iface );
2877 return internal_putProperty(This, pProp, value, FALSE);
2880 static HRESULT WINAPI isaxxmlreader_getEntityResolver(
2881 ISAXXMLReader* iface,
2882 ISAXEntityResolver **ppEntityResolver)
2884 saxreader *This = impl_from_ISAXXMLReader( iface );
2885 return internal_getEntityResolver(This, ppEntityResolver, FALSE);
2888 static HRESULT WINAPI isaxxmlreader_putEntityResolver(
2889 ISAXXMLReader* iface,
2890 ISAXEntityResolver *pEntityResolver)
2892 saxreader *This = impl_from_ISAXXMLReader( iface );
2893 return internal_putEntityResolver(This, pEntityResolver, FALSE);
2896 static HRESULT WINAPI isaxxmlreader_getContentHandler(
2897 ISAXXMLReader* iface,
2898 ISAXContentHandler **pContentHandler)
2900 saxreader *This = impl_from_ISAXXMLReader( iface );
2901 return internal_getContentHandler(This, pContentHandler, FALSE);
2904 static HRESULT WINAPI isaxxmlreader_putContentHandler(
2905 ISAXXMLReader* iface,
2906 ISAXContentHandler *contentHandler)
2908 saxreader *This = impl_from_ISAXXMLReader( iface );
2909 return internal_putContentHandler(This, contentHandler, FALSE);
2912 static HRESULT WINAPI isaxxmlreader_getDTDHandler(
2913 ISAXXMLReader* iface,
2914 ISAXDTDHandler **pDTDHandler)
2916 saxreader *This = impl_from_ISAXXMLReader( iface );
2917 return internal_getDTDHandler(This, pDTDHandler, FALSE);
2920 static HRESULT WINAPI isaxxmlreader_putDTDHandler(
2921 ISAXXMLReader* iface,
2922 ISAXDTDHandler *pDTDHandler)
2924 saxreader *This = impl_from_ISAXXMLReader( iface );
2925 return internal_putDTDHandler(This, pDTDHandler, FALSE);
2928 static HRESULT WINAPI isaxxmlreader_getErrorHandler(
2929 ISAXXMLReader* iface,
2930 ISAXErrorHandler **pErrorHandler)
2932 saxreader *This = impl_from_ISAXXMLReader( iface );
2933 return internal_getErrorHandler(This, pErrorHandler, FALSE);
2936 static HRESULT WINAPI isaxxmlreader_putErrorHandler(
2937 ISAXXMLReader* iface,
2938 ISAXErrorHandler *errorHandler)
2940 saxreader *This = impl_from_ISAXXMLReader( iface );
2941 return internal_putErrorHandler(This, errorHandler, FALSE);
2944 static HRESULT WINAPI isaxxmlreader_getBaseURL(
2945 ISAXXMLReader* iface,
2946 const WCHAR **pBaseUrl)
2948 saxreader *This = impl_from_ISAXXMLReader( iface );
2949 return IVBSAXXMLReader_get_baseURL(&This->IVBSAXXMLReader_iface, pBaseUrl);
2952 static HRESULT WINAPI isaxxmlreader_putBaseURL(
2953 ISAXXMLReader* iface,
2954 const WCHAR *pBaseUrl)
2956 saxreader *This = impl_from_ISAXXMLReader( iface );
2957 return IVBSAXXMLReader_put_baseURL(&This->IVBSAXXMLReader_iface, pBaseUrl);
2960 static HRESULT WINAPI isaxxmlreader_getSecureBaseURL(
2961 ISAXXMLReader* iface,
2962 const WCHAR **pSecureBaseUrl)
2964 saxreader *This = impl_from_ISAXXMLReader( iface );
2965 return IVBSAXXMLReader_get_secureBaseURL(&This->IVBSAXXMLReader_iface, pSecureBaseUrl);
2968 static HRESULT WINAPI isaxxmlreader_putSecureBaseURL(
2969 ISAXXMLReader* iface,
2970 const WCHAR *secureBaseUrl)
2972 saxreader *This = impl_from_ISAXXMLReader( iface );
2973 return IVBSAXXMLReader_put_secureBaseURL(&This->IVBSAXXMLReader_iface, secureBaseUrl);
2976 static HRESULT WINAPI isaxxmlreader_parse(
2977 ISAXXMLReader* iface,
2980 saxreader *This = impl_from_ISAXXMLReader( iface );
2981 return internal_parse(This, varInput, FALSE);
2984 static HRESULT WINAPI isaxxmlreader_parseURL(
2985 ISAXXMLReader* iface,
2988 saxreader *This = impl_from_ISAXXMLReader( iface );
2989 return internal_parseURL(This, url, FALSE);
2992 static const struct ISAXXMLReaderVtbl isaxreader_vtbl =
2994 isaxxmlreader_QueryInterface,
2995 isaxxmlreader_AddRef,
2996 isaxxmlreader_Release,
2997 isaxxmlreader_getFeature,
2998 isaxxmlreader_putFeature,
2999 isaxxmlreader_getProperty,
3000 isaxxmlreader_putProperty,
3001 isaxxmlreader_getEntityResolver,
3002 isaxxmlreader_putEntityResolver,
3003 isaxxmlreader_getContentHandler,
3004 isaxxmlreader_putContentHandler,
3005 isaxxmlreader_getDTDHandler,
3006 isaxxmlreader_putDTDHandler,
3007 isaxxmlreader_getErrorHandler,
3008 isaxxmlreader_putErrorHandler,
3009 isaxxmlreader_getBaseURL,
3010 isaxxmlreader_putBaseURL,
3011 isaxxmlreader_getSecureBaseURL,
3012 isaxxmlreader_putSecureBaseURL,
3013 isaxxmlreader_parse,
3014 isaxxmlreader_parseURL
3017 HRESULT SAXXMLReader_create(IUnknown *pUnkOuter, LPVOID *ppObj)
3021 TRACE("(%p,%p)\n", pUnkOuter, ppObj);
3023 reader = heap_alloc( sizeof (*reader) );
3025 return E_OUTOFMEMORY;
3027 reader->IVBSAXXMLReader_iface.lpVtbl = &saxreader_vtbl;
3028 reader->ISAXXMLReader_iface.lpVtbl = &isaxreader_vtbl;
3030 reader->contentHandler = NULL;
3031 reader->vbcontentHandler = NULL;
3032 reader->errorHandler = NULL;
3033 reader->vberrorHandler = NULL;
3034 reader->lexicalHandler = NULL;
3035 reader->vblexicalHandler = NULL;
3036 reader->declHandler = NULL;
3037 reader->vbdeclHandler = NULL;
3038 reader->isParsing = FALSE;
3039 reader->pool.pool = NULL;
3040 reader->pool.index = 0;
3041 reader->pool.len = 0;
3042 reader->features = 0;
3044 memset(&reader->sax, 0, sizeof(xmlSAXHandler));
3045 reader->sax.initialized = XML_SAX2_MAGIC;
3046 reader->sax.startDocument = libxmlStartDocument;
3047 reader->sax.endDocument = libxmlEndDocument;
3048 reader->sax.startElementNs = libxmlStartElementNS;
3049 reader->sax.endElementNs = libxmlEndElementNS;
3050 reader->sax.characters = libxmlCharacters;
3051 reader->sax.setDocumentLocator = libxmlSetDocumentLocator;
3052 reader->sax.comment = libxmlComment;
3053 reader->sax.error = libxmlFatalError;
3054 reader->sax.fatalError = libxmlFatalError;
3055 reader->sax.cdataBlock = libxmlCDataBlock;
3057 *ppObj = &reader->IVBSAXXMLReader_iface;
3059 TRACE("returning iface %p\n", *ppObj);
3066 HRESULT SAXXMLReader_create(IUnknown *pUnkOuter, LPVOID *ppObj)
3068 MESSAGE("This program tried to use a SAX XML Reader object, but\n"
3069 "libxml2 support was not present at compile time.\n");