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);
59 typedef struct _saxreader
61 IVBSAXXMLReader IVBSAXXMLReader_iface;
62 ISAXXMLReader ISAXXMLReader_iface;
64 struct ISAXContentHandler *contentHandler;
65 struct IVBSAXContentHandler *vbcontentHandler;
66 struct ISAXErrorHandler *errorHandler;
67 struct IVBSAXErrorHandler *vberrorHandler;
68 struct ISAXLexicalHandler *lexicalHandler;
69 struct IVBSAXLexicalHandler *vblexicalHandler;
70 struct ISAXDeclHandler *declHandler;
71 struct IVBSAXDeclHandler *vbdeclHandler;
77 typedef struct _saxlocator
79 IVBSAXLocator IVBSAXLocator_iface;
80 ISAXLocator ISAXLocator_iface;
84 xmlParserCtxtPtr pParserCtxt;
98 typedef struct _saxattributes
100 IVBSAXAttributes IVBSAXAttributes_iface;
101 ISAXAttributes ISAXAttributes_iface;
110 static inline saxreader *impl_from_IVBSAXXMLReader( IVBSAXXMLReader *iface )
112 return CONTAINING_RECORD(iface, saxreader, IVBSAXXMLReader_iface);
115 static inline saxreader *impl_from_ISAXXMLReader( ISAXXMLReader *iface )
117 return CONTAINING_RECORD(iface, saxreader, ISAXXMLReader_iface);
120 static inline saxlocator *impl_from_IVBSAXLocator( IVBSAXLocator *iface )
122 return CONTAINING_RECORD(iface, saxlocator, IVBSAXLocator_iface);
125 static inline saxlocator *impl_from_ISAXLocator( ISAXLocator *iface )
127 return CONTAINING_RECORD(iface, saxlocator, ISAXLocator_iface);
130 static inline saxattributes *impl_from_IVBSAXAttributes( IVBSAXAttributes *iface )
132 return CONTAINING_RECORD(iface, saxattributes, IVBSAXAttributes_iface);
135 static inline saxattributes *impl_from_ISAXAttributes( ISAXAttributes *iface )
137 return CONTAINING_RECORD(iface, saxattributes, ISAXAttributes_iface);
140 static inline BOOL has_content_handler(const saxlocator *locator)
142 return (locator->vbInterface && locator->saxreader->vbcontentHandler) ||
143 (!locator->vbInterface && locator->saxreader->contentHandler);
146 static inline BOOL has_error_handler(const saxlocator *locator)
148 return (locator->vbInterface && locator->saxreader->vberrorHandler) ||
149 (!locator->vbInterface && locator->saxreader->errorHandler);
152 static HRESULT namespacePush(saxlocator *locator, int ns)
154 if(locator->nsStackLast>=locator->nsStackSize)
158 new_stack = HeapReAlloc(GetProcessHeap(), 0,
159 locator->nsStack, sizeof(int)*locator->nsStackSize*2);
160 if(!new_stack) return E_OUTOFMEMORY;
161 locator->nsStack = new_stack;
162 locator->nsStackSize *= 2;
164 locator->nsStack[locator->nsStackLast++] = ns;
169 static int namespacePop(saxlocator *locator)
171 if(locator->nsStackLast == 0) return 0;
172 return locator->nsStack[--locator->nsStackLast];
175 static BOOL bstr_pool_insert(struct bstrpool *pool, BSTR pool_entry)
179 pool->pool = HeapAlloc(GetProcessHeap(), 0, 16 * sizeof(*pool->pool));
186 else if (pool->index == pool->len)
188 BSTR *realloc = HeapReAlloc(GetProcessHeap(), 0, pool->pool, pool->len * 2 * sizeof(*realloc));
193 pool->pool = realloc;
197 pool->pool[pool->index++] = pool_entry;
201 static void free_bstr_pool(struct bstrpool *pool)
205 for (i = 0; i < pool->index; i++)
206 SysFreeString(pool->pool[i]);
208 HeapFree(GetProcessHeap(), 0, pool->pool);
211 pool->index = pool->len = 0;
214 static BSTR bstr_from_xmlCharN(const xmlChar *buf, int len)
222 dLen = MultiByteToWideChar(CP_UTF8, 0, (LPCSTR)buf, len, NULL, 0);
223 if(len != -1) dLen++;
224 bstr = SysAllocStringLen(NULL, dLen-1);
227 MultiByteToWideChar(CP_UTF8, 0, (LPCSTR)buf, len, bstr, dLen);
228 if(len != -1) bstr[dLen-1] = '\0';
233 static BSTR QName_from_xmlChar(const xmlChar *prefix, const xmlChar *name)
238 if(!name) return NULL;
240 if(!prefix || !*prefix)
241 return bstr_from_xmlChar(name);
243 qname = xmlBuildQName(name, prefix, NULL, 0);
244 bstr = bstr_from_xmlChar(qname);
250 static BSTR pooled_bstr_from_xmlChar(struct bstrpool *pool, const xmlChar *buf)
252 BSTR pool_entry = bstr_from_xmlChar(buf);
254 if (pool_entry && !bstr_pool_insert(pool, pool_entry))
256 SysFreeString(pool_entry);
263 static BSTR pooled_bstr_from_xmlCharN(struct bstrpool *pool, const xmlChar *buf, int len)
265 BSTR pool_entry = bstr_from_xmlCharN(buf, len);
267 if (pool_entry && !bstr_pool_insert(pool, pool_entry))
269 SysFreeString(pool_entry);
276 static BSTR pooled_QName_from_xmlChar(struct bstrpool *pool, const xmlChar *prefix, const xmlChar *name)
278 BSTR pool_entry = QName_from_xmlChar(prefix, name);
280 if (pool_entry && !bstr_pool_insert(pool, pool_entry))
282 SysFreeString(pool_entry);
289 static void format_error_message_from_id(saxlocator *This, HRESULT hr)
291 xmlStopParser(This->pParserCtxt);
294 if(has_error_handler(This))
297 if(!FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM,
298 NULL, hr, 0, msg, sizeof(msg), NULL))
300 FIXME("MSXML errors not yet supported.\n");
304 if(This->vbInterface)
306 BSTR bstrMsg = SysAllocString(msg);
307 IVBSAXErrorHandler_fatalError(This->saxreader->vberrorHandler,
308 &This->IVBSAXLocator_iface, &bstrMsg, hr);
309 SysFreeString(bstrMsg);
312 ISAXErrorHandler_fatalError(This->saxreader->errorHandler,
313 &This->ISAXLocator_iface, msg, hr);
317 static void update_position(saxlocator *This, xmlChar *end)
319 if(This->lastCur == NULL)
321 This->lastCur = (xmlChar*)This->pParserCtxt->input->base;
323 This->realColumn = 1;
325 else if(This->lastCur < This->pParserCtxt->input->base)
327 This->lastCur = (xmlChar*)This->pParserCtxt->input->base;
329 This->realColumn = 1;
332 if(This->pParserCtxt->input->cur<This->lastCur)
334 This->lastCur = (xmlChar*)This->pParserCtxt->input->base;
336 This->realColumn = 1;
339 if(!end) end = (xmlChar*)This->pParserCtxt->input->cur;
341 while(This->lastCur < end)
343 if(*(This->lastCur) == '\n')
346 This->realColumn = 1;
348 else if(*(This->lastCur) == '\r' &&
349 (This->lastCur==This->pParserCtxt->input->end ||
350 *(This->lastCur+1)!='\n'))
353 This->realColumn = 1;
355 else This->realColumn++;
359 /* Count multibyte UTF8 encoded characters once */
360 while((*(This->lastCur)&0xC0) == 0x80) This->lastCur++;
363 This->line = This->realLine;
364 This->column = This->realColumn;
367 /*** IVBSAXAttributes interface ***/
368 /*** IUnknown methods ***/
369 static HRESULT WINAPI ivbsaxattributes_QueryInterface(
370 IVBSAXAttributes* iface,
374 saxattributes *This = impl_from_IVBSAXAttributes(iface);
376 TRACE("%p %s %p\n", This, debugstr_guid(riid), ppvObject);
380 if (IsEqualGUID(riid, &IID_IUnknown) ||
381 IsEqualGUID(riid, &IID_IDispatch) ||
382 IsEqualGUID(riid, &IID_IVBSAXAttributes))
388 FIXME("interface %s not implemented\n", debugstr_guid(riid));
389 return E_NOINTERFACE;
392 IVBSAXAttributes_AddRef(iface);
397 static ULONG WINAPI ivbsaxattributes_AddRef(IVBSAXAttributes* iface)
399 saxattributes *This = impl_from_IVBSAXAttributes(iface);
400 return ISAXAttributes_AddRef(&This->ISAXAttributes_iface);
403 static ULONG WINAPI ivbsaxattributes_Release(IVBSAXAttributes* iface)
405 saxattributes *This = impl_from_IVBSAXAttributes(iface);
406 return ISAXAttributes_Release(&This->ISAXAttributes_iface);
409 /*** IDispatch methods ***/
410 static HRESULT WINAPI ivbsaxattributes_GetTypeInfoCount( IVBSAXAttributes *iface, UINT* pctinfo )
412 saxattributes *This = impl_from_IVBSAXAttributes( iface );
414 TRACE("(%p)->(%p)\n", This, pctinfo);
421 static HRESULT WINAPI ivbsaxattributes_GetTypeInfo(
422 IVBSAXAttributes *iface,
423 UINT iTInfo, LCID lcid, ITypeInfo** ppTInfo )
425 saxattributes *This = impl_from_IVBSAXAttributes( iface );
428 TRACE("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo);
430 hr = get_typeinfo(IVBSAXAttributes_tid, ppTInfo);
435 static HRESULT WINAPI ivbsaxattributes_GetIDsOfNames(
436 IVBSAXAttributes *iface,
443 saxattributes *This = impl_from_IVBSAXAttributes( iface );
447 TRACE("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames, cNames,
450 if(!rgszNames || cNames == 0 || !rgDispId)
453 hr = get_typeinfo(IVBSAXAttributes_tid, &typeinfo);
456 hr = ITypeInfo_GetIDsOfNames(typeinfo, rgszNames, cNames, rgDispId);
457 ITypeInfo_Release(typeinfo);
463 static HRESULT WINAPI ivbsaxattributes_Invoke(
464 IVBSAXAttributes *iface,
469 DISPPARAMS* pDispParams,
471 EXCEPINFO* pExcepInfo,
474 saxattributes *This = impl_from_IVBSAXAttributes( iface );
478 TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
479 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
481 hr = get_typeinfo(IVBSAXAttributes_tid, &typeinfo);
484 hr = ITypeInfo_Invoke(typeinfo, &This->IVBSAXAttributes_iface, dispIdMember, wFlags,
485 pDispParams, pVarResult, pExcepInfo, puArgErr);
486 ITypeInfo_Release(typeinfo);
492 /*** IVBSAXAttributes methods ***/
493 static HRESULT WINAPI ivbsaxattributes_get_length(
494 IVBSAXAttributes* iface,
497 saxattributes *This = impl_from_IVBSAXAttributes( iface );
498 return ISAXAttributes_getLength(&This->ISAXAttributes_iface, nLength);
501 static HRESULT WINAPI ivbsaxattributes_getURI(
502 IVBSAXAttributes* iface,
507 saxattributes *This = impl_from_IVBSAXAttributes( iface );
508 return ISAXAttributes_getURI(&This->ISAXAttributes_iface, nIndex, (const WCHAR**)uri, &len);
511 static HRESULT WINAPI ivbsaxattributes_getLocalName(
512 IVBSAXAttributes* iface,
517 saxattributes *This = impl_from_IVBSAXAttributes( iface );
518 return ISAXAttributes_getLocalName(&This->ISAXAttributes_iface, nIndex,
519 (const WCHAR**)localName, &len);
522 static HRESULT WINAPI ivbsaxattributes_getQName(
523 IVBSAXAttributes* iface,
528 saxattributes *This = impl_from_IVBSAXAttributes( iface );
529 return ISAXAttributes_getQName(&This->ISAXAttributes_iface, nIndex, (const WCHAR**)QName, &len);
532 static HRESULT WINAPI ivbsaxattributes_getIndexFromName(
533 IVBSAXAttributes* iface,
538 saxattributes *This = impl_from_IVBSAXAttributes( iface );
539 return ISAXAttributes_getIndexFromName(&This->ISAXAttributes_iface, uri, SysStringLen(uri),
540 localName, SysStringLen(localName), index);
543 static HRESULT WINAPI ivbsaxattributes_getIndexFromQName(
544 IVBSAXAttributes* iface,
548 saxattributes *This = impl_from_IVBSAXAttributes( iface );
549 return ISAXAttributes_getIndexFromQName(&This->ISAXAttributes_iface, QName,
550 SysStringLen(QName), index);
553 static HRESULT WINAPI ivbsaxattributes_getType(
554 IVBSAXAttributes* iface,
559 saxattributes *This = impl_from_IVBSAXAttributes( iface );
560 return ISAXAttributes_getType(&This->ISAXAttributes_iface, nIndex, (const WCHAR**)type, &len);
563 static HRESULT WINAPI ivbsaxattributes_getTypeFromName(
564 IVBSAXAttributes* iface,
570 saxattributes *This = impl_from_IVBSAXAttributes( iface );
571 return ISAXAttributes_getTypeFromName(&This->ISAXAttributes_iface, uri, SysStringLen(uri),
572 localName, SysStringLen(localName), (const WCHAR**)type, &len);
575 static HRESULT WINAPI ivbsaxattributes_getTypeFromQName(
576 IVBSAXAttributes* iface,
581 saxattributes *This = impl_from_IVBSAXAttributes( iface );
582 return ISAXAttributes_getTypeFromQName(&This->ISAXAttributes_iface, QName, SysStringLen(QName),
583 (const WCHAR**)type, &len);
586 static HRESULT WINAPI ivbsaxattributes_getValue(
587 IVBSAXAttributes* iface,
592 saxattributes *This = impl_from_IVBSAXAttributes( iface );
593 return ISAXAttributes_getValue(&This->ISAXAttributes_iface, nIndex, (const WCHAR**)value, &len);
596 static HRESULT WINAPI ivbsaxattributes_getValueFromName(
597 IVBSAXAttributes* iface,
603 saxattributes *This = impl_from_IVBSAXAttributes( iface );
604 return ISAXAttributes_getValueFromName(&This->ISAXAttributes_iface, uri, SysStringLen(uri),
605 localName, SysStringLen(localName), (const WCHAR**)value, &len);
608 static HRESULT WINAPI ivbsaxattributes_getValueFromQName(
609 IVBSAXAttributes* iface,
614 saxattributes *This = impl_from_IVBSAXAttributes( iface );
615 return ISAXAttributes_getValueFromQName(&This->ISAXAttributes_iface, QName,
616 SysStringLen(QName), (const WCHAR**)value, &len);
619 static const struct IVBSAXAttributesVtbl ivbsaxattributes_vtbl =
621 ivbsaxattributes_QueryInterface,
622 ivbsaxattributes_AddRef,
623 ivbsaxattributes_Release,
624 ivbsaxattributes_GetTypeInfoCount,
625 ivbsaxattributes_GetTypeInfo,
626 ivbsaxattributes_GetIDsOfNames,
627 ivbsaxattributes_Invoke,
628 ivbsaxattributes_get_length,
629 ivbsaxattributes_getURI,
630 ivbsaxattributes_getLocalName,
631 ivbsaxattributes_getQName,
632 ivbsaxattributes_getIndexFromName,
633 ivbsaxattributes_getIndexFromQName,
634 ivbsaxattributes_getType,
635 ivbsaxattributes_getTypeFromName,
636 ivbsaxattributes_getTypeFromQName,
637 ivbsaxattributes_getValue,
638 ivbsaxattributes_getValueFromName,
639 ivbsaxattributes_getValueFromQName
642 /*** ISAXAttributes interface ***/
643 /*** IUnknown methods ***/
644 static HRESULT WINAPI isaxattributes_QueryInterface(
645 ISAXAttributes* iface,
649 saxattributes *This = impl_from_ISAXAttributes(iface);
651 TRACE("%p %s %p\n", This, debugstr_guid(riid), ppvObject);
655 if (IsEqualGUID(riid, &IID_IUnknown) ||
656 IsEqualGUID(riid, &IID_ISAXAttributes))
662 FIXME("interface %s not implemented\n", debugstr_guid(riid));
663 return E_NOINTERFACE;
666 ISAXAttributes_AddRef(iface);
671 static ULONG WINAPI isaxattributes_AddRef(ISAXAttributes* iface)
673 saxattributes *This = impl_from_ISAXAttributes(iface);
675 return InterlockedIncrement(&This->ref);
678 static ULONG WINAPI isaxattributes_Release(ISAXAttributes* iface)
680 saxattributes *This = impl_from_ISAXAttributes(iface);
685 ref = InterlockedDecrement(&This->ref);
689 for(index=0; index<This->nb_attributes; index++)
691 SysFreeString(This->szLocalname[index]);
692 SysFreeString(This->szURI[index]);
693 SysFreeString(This->szValue[index]);
694 SysFreeString(This->szQName[index]);
697 heap_free(This->szLocalname);
698 heap_free(This->szURI);
699 heap_free(This->szValue);
700 heap_free(This->szQName);
708 /*** ISAXAttributes methods ***/
709 static HRESULT WINAPI isaxattributes_getLength(
710 ISAXAttributes* iface,
713 saxattributes *This = impl_from_ISAXAttributes( iface );
715 *length = This->nb_attributes;
716 TRACE("Length set to %d\n", *length);
720 static HRESULT WINAPI isaxattributes_getURI(
721 ISAXAttributes* iface,
726 saxattributes *This = impl_from_ISAXAttributes( iface );
727 TRACE("(%p)->(%d)\n", This, nIndex);
729 if(nIndex>=This->nb_attributes || nIndex<0) return E_INVALIDARG;
730 if(!pUrl || !pUriSize) return E_POINTER;
732 *pUriSize = SysStringLen(This->szURI[nIndex]);
733 *pUrl = This->szURI[nIndex];
738 static HRESULT WINAPI isaxattributes_getLocalName(
739 ISAXAttributes* iface,
741 const WCHAR **pLocalName,
742 int *pLocalNameLength)
744 saxattributes *This = impl_from_ISAXAttributes( iface );
745 TRACE("(%p)->(%d)\n", This, nIndex);
747 if(nIndex>=This->nb_attributes || nIndex<0) return E_INVALIDARG;
748 if(!pLocalName || !pLocalNameLength) return E_POINTER;
750 *pLocalNameLength = SysStringLen(This->szLocalname[nIndex]);
751 *pLocalName = This->szLocalname[nIndex];
756 static HRESULT WINAPI isaxattributes_getQName(
757 ISAXAttributes* iface,
759 const WCHAR **pQName,
762 saxattributes *This = impl_from_ISAXAttributes( iface );
763 TRACE("(%p)->(%d)\n", This, nIndex);
765 if(nIndex>=This->nb_attributes || nIndex<0) return E_INVALIDARG;
766 if(!pQName || !pQNameLength) return E_POINTER;
768 *pQNameLength = SysStringLen(This->szQName[nIndex]);
769 *pQName = This->szQName[nIndex];
774 static HRESULT WINAPI isaxattributes_getName(
775 ISAXAttributes* iface,
779 const WCHAR **pLocalName,
781 const WCHAR **pQName,
784 saxattributes *This = impl_from_ISAXAttributes( iface );
785 TRACE("(%p)->(%d)\n", This, nIndex);
787 if(nIndex>=This->nb_attributes || nIndex<0) return E_INVALIDARG;
788 if(!pUri || !pUriLength || !pLocalName || !pLocalNameSize
789 || !pQName || !pQNameLength) return E_POINTER;
791 *pUriLength = SysStringLen(This->szURI[nIndex]);
792 *pUri = This->szURI[nIndex];
793 *pLocalNameSize = SysStringLen(This->szLocalname[nIndex]);
794 *pLocalName = This->szLocalname[nIndex];
795 *pQNameLength = SysStringLen(This->szQName[nIndex]);
796 *pQName = This->szQName[nIndex];
801 static HRESULT WINAPI isaxattributes_getIndexFromName(
802 ISAXAttributes* iface,
805 const WCHAR *pLocalName,
809 saxattributes *This = impl_from_ISAXAttributes( iface );
811 TRACE("(%p)->(%s, %d, %s, %d)\n", This, debugstr_w(pUri), cUriLength,
812 debugstr_w(pLocalName), cocalNameLength);
814 if(!pUri || !pLocalName || !index) return E_POINTER;
816 for(i=0; i<This->nb_attributes; i++)
818 if(cUriLength!=SysStringLen(This->szURI[i])
819 || cocalNameLength!=SysStringLen(This->szLocalname[i]))
821 if(cUriLength && memcmp(pUri, This->szURI[i],
822 sizeof(WCHAR)*cUriLength))
824 if(cocalNameLength && memcmp(pLocalName, This->szLocalname[i],
825 sizeof(WCHAR)*cocalNameLength))
835 static HRESULT WINAPI isaxattributes_getIndexFromQName(
836 ISAXAttributes* iface,
841 saxattributes *This = impl_from_ISAXAttributes( iface );
843 TRACE("(%p)->(%s, %d)\n", This, debugstr_w(pQName), nQNameLength);
845 if(!pQName || !index) return E_POINTER;
846 if(!nQNameLength) return E_INVALIDARG;
848 for(i=0; i<This->nb_attributes; i++)
850 if(nQNameLength!=SysStringLen(This->szQName[i])) continue;
851 if(memcmp(pQName, This->szQName, sizeof(WCHAR)*nQNameLength)) continue;
860 static HRESULT WINAPI isaxattributes_getType(
861 ISAXAttributes* iface,
866 saxattributes *This = impl_from_ISAXAttributes( iface );
868 FIXME("(%p)->(%d) stub\n", This, nIndex);
872 static HRESULT WINAPI isaxattributes_getTypeFromName(
873 ISAXAttributes* iface,
876 const WCHAR *pLocalName,
881 saxattributes *This = impl_from_ISAXAttributes( iface );
883 FIXME("(%p)->(%s, %d, %s, %d) stub\n", This, debugstr_w(pUri), nUri,
884 debugstr_w(pLocalName), nLocalName);
888 static HRESULT WINAPI isaxattributes_getTypeFromQName(
889 ISAXAttributes* iface,
895 saxattributes *This = impl_from_ISAXAttributes( iface );
897 FIXME("(%p)->(%s, %d) stub\n", This, debugstr_w(pQName), nQName);
901 static HRESULT WINAPI isaxattributes_getValue(
902 ISAXAttributes* iface,
904 const WCHAR **pValue,
907 saxattributes *This = impl_from_ISAXAttributes( iface );
908 TRACE("(%p)->(%d)\n", This, nIndex);
910 if(nIndex>=This->nb_attributes || nIndex<0) return E_INVALIDARG;
911 if(!pValue || !nValue) return E_POINTER;
913 *nValue = SysStringLen(This->szValue[nIndex]);
914 *pValue = This->szValue[nIndex];
919 static HRESULT WINAPI isaxattributes_getValueFromName(
920 ISAXAttributes* iface,
923 const WCHAR *pLocalName,
925 const WCHAR **pValue,
930 saxattributes *This = impl_from_ISAXAttributes( iface );
931 TRACE("(%p)->(%s, %d, %s, %d)\n", This, debugstr_w(pUri), nUri,
932 debugstr_w(pLocalName), nLocalName);
934 hr = ISAXAttributes_getIndexFromName(iface,
935 pUri, nUri, pLocalName, nLocalName, &index);
936 if(hr==S_OK) hr = ISAXAttributes_getValue(iface, index, pValue, nValue);
941 static HRESULT WINAPI isaxattributes_getValueFromQName(
942 ISAXAttributes* iface,
945 const WCHAR **pValue,
950 saxattributes *This = impl_from_ISAXAttributes( iface );
951 TRACE("(%p)->(%s, %d)\n", This, debugstr_w(pQName), nQName);
953 hr = ISAXAttributes_getIndexFromQName(iface, pQName, nQName, &index);
954 if(hr==S_OK) hr = ISAXAttributes_getValue(iface, index, pValue, nValue);
959 static const struct ISAXAttributesVtbl isaxattributes_vtbl =
961 isaxattributes_QueryInterface,
962 isaxattributes_AddRef,
963 isaxattributes_Release,
964 isaxattributes_getLength,
965 isaxattributes_getURI,
966 isaxattributes_getLocalName,
967 isaxattributes_getQName,
968 isaxattributes_getName,
969 isaxattributes_getIndexFromName,
970 isaxattributes_getIndexFromQName,
971 isaxattributes_getType,
972 isaxattributes_getTypeFromName,
973 isaxattributes_getTypeFromQName,
974 isaxattributes_getValue,
975 isaxattributes_getValueFromName,
976 isaxattributes_getValueFromQName
979 static HRESULT SAXAttributes_create(saxattributes **attr,
980 int nb_namespaces, const xmlChar **xmlNamespaces,
981 int nb_attributes, const xmlChar **xmlAttributes)
983 saxattributes *attributes;
985 static const xmlChar xmlns[] = "xmlns";
987 attributes = heap_alloc(sizeof(*attributes));
989 return E_OUTOFMEMORY;
991 attributes->IVBSAXAttributes_iface.lpVtbl = &ivbsaxattributes_vtbl;
992 attributes->ISAXAttributes_iface.lpVtbl = &isaxattributes_vtbl;
995 attributes->nb_attributes = nb_namespaces+nb_attributes;
997 attributes->szLocalname = heap_alloc(sizeof(BSTR)*attributes->nb_attributes);
998 attributes->szURI = heap_alloc(sizeof(BSTR)*attributes->nb_attributes);
999 attributes->szValue = heap_alloc(sizeof(BSTR)*attributes->nb_attributes);
1000 attributes->szQName = heap_alloc(sizeof(BSTR)*attributes->nb_attributes);
1002 if(!attributes->szLocalname || !attributes->szURI
1003 || !attributes->szValue || !attributes->szQName)
1005 heap_free(attributes->szLocalname);
1006 heap_free(attributes->szURI);
1007 heap_free(attributes->szValue);
1008 heap_free(attributes->szQName);
1009 heap_free(attributes);
1013 for(index=0; index<nb_namespaces; index++)
1015 attributes->szLocalname[index] = SysAllocStringLen(NULL, 0);
1016 attributes->szURI[index] = SysAllocStringLen(NULL, 0);
1017 attributes->szValue[index] = bstr_from_xmlChar(xmlNamespaces[2*index+1]);
1018 attributes->szQName[index] = QName_from_xmlChar(xmlns, xmlNamespaces[2*index]);
1021 for(index=0; index<nb_attributes; index++)
1023 attributes->szLocalname[nb_namespaces+index] =
1024 bstr_from_xmlChar(xmlAttributes[index*5]);
1025 attributes->szURI[nb_namespaces+index] =
1026 bstr_from_xmlChar(xmlAttributes[index*5+2]);
1027 attributes->szValue[nb_namespaces+index] =
1028 bstr_from_xmlCharN(xmlAttributes[index*5+3],
1029 xmlAttributes[index*5+4]-xmlAttributes[index*5+3]);
1030 attributes->szQName[nb_namespaces+index] =
1031 QName_from_xmlChar(xmlAttributes[index*5+1], xmlAttributes[index*5]);
1036 TRACE("returning %p\n", *attr);
1041 /*** LibXML callbacks ***/
1042 static void libxmlStartDocument(void *ctx)
1044 saxlocator *This = ctx;
1047 if(has_content_handler(This))
1049 if(This->vbInterface)
1050 hr = IVBSAXContentHandler_startDocument(This->saxreader->vbcontentHandler);
1052 hr = ISAXContentHandler_startDocument(This->saxreader->contentHandler);
1055 format_error_message_from_id(This, hr);
1058 update_position(This, NULL);
1061 static void libxmlEndDocument(void *ctx)
1063 saxlocator *This = ctx;
1069 if(This->ret != S_OK) return;
1071 if(has_content_handler(This))
1073 if(This->vbInterface)
1074 hr = IVBSAXContentHandler_endDocument(This->saxreader->vbcontentHandler);
1076 hr = ISAXContentHandler_endDocument(This->saxreader->contentHandler);
1079 format_error_message_from_id(This, hr);
1083 static void libxmlStartElementNS(
1085 const xmlChar *localname,
1086 const xmlChar *prefix,
1089 const xmlChar **namespaces,
1092 const xmlChar **attributes)
1094 BSTR NamespaceUri, LocalName, QName, Prefix, Uri;
1095 saxlocator *This = ctx;
1097 saxattributes *attr;
1100 if(*(This->pParserCtxt->input->cur) == '/')
1101 update_position(This, (xmlChar*)This->pParserCtxt->input->cur+2);
1103 update_position(This, (xmlChar*)This->pParserCtxt->input->cur+1);
1105 hr = namespacePush(This, nb_namespaces);
1106 if(hr==S_OK && has_content_handler(This))
1108 for(index=0; index<nb_namespaces; index++)
1110 Prefix = pooled_bstr_from_xmlChar(&This->saxreader->pool, namespaces[2*index]);
1111 Uri = pooled_bstr_from_xmlChar(&This->saxreader->pool, namespaces[2*index+1]);
1113 if(This->vbInterface)
1114 hr = IVBSAXContentHandler_startPrefixMapping(
1115 This->saxreader->vbcontentHandler,
1118 hr = ISAXContentHandler_startPrefixMapping(
1119 This->saxreader->contentHandler,
1120 Prefix, SysStringLen(Prefix),
1121 Uri, SysStringLen(Uri));
1125 format_error_message_from_id(This, hr);
1130 NamespaceUri = pooled_bstr_from_xmlChar(&This->saxreader->pool, URI);
1131 LocalName = pooled_bstr_from_xmlChar(&This->saxreader->pool, localname);
1132 QName = pooled_QName_from_xmlChar(&This->saxreader->pool, prefix, localname);
1134 hr = SAXAttributes_create(&attr, nb_namespaces, namespaces, nb_attributes, attributes);
1137 if(This->vbInterface)
1138 hr = IVBSAXContentHandler_startElement(This->saxreader->vbcontentHandler,
1139 &NamespaceUri, &LocalName, &QName, &attr->IVBSAXAttributes_iface);
1141 hr = ISAXContentHandler_startElement(This->saxreader->contentHandler, NamespaceUri,
1142 SysStringLen(NamespaceUri), LocalName, SysStringLen(LocalName), QName,
1143 SysStringLen(QName), &attr->ISAXAttributes_iface);
1145 ISAXAttributes_Release(&attr->ISAXAttributes_iface);
1150 format_error_message_from_id(This, hr);
1153 static void libxmlEndElementNS(
1155 const xmlChar *localname,
1156 const xmlChar *prefix,
1159 BSTR NamespaceUri, LocalName, QName, Prefix;
1160 saxlocator *This = ctx;
1165 end = (xmlChar*)This->pParserCtxt->input->cur;
1166 if(*(end-1) != '>' || *(end-2) != '/')
1167 while(end-2>=This->pParserCtxt->input->base
1168 && *(end-2)!='<' && *(end-1)!='/') end--;
1170 update_position(This, end);
1172 nsNr = namespacePop(This);
1174 if(has_content_handler(This))
1176 NamespaceUri = pooled_bstr_from_xmlChar(&This->saxreader->pool, URI);
1177 LocalName = pooled_bstr_from_xmlChar(&This->saxreader->pool, localname);
1178 QName = pooled_QName_from_xmlChar(&This->saxreader->pool, prefix, localname);
1180 if(This->vbInterface)
1181 hr = IVBSAXContentHandler_endElement(
1182 This->saxreader->vbcontentHandler,
1183 &NamespaceUri, &LocalName, &QName);
1185 hr = ISAXContentHandler_endElement(
1186 This->saxreader->contentHandler,
1187 NamespaceUri, SysStringLen(NamespaceUri),
1188 LocalName, SysStringLen(LocalName),
1189 QName, SysStringLen(QName));
1193 format_error_message_from_id(This, hr);
1197 for(index=This->pParserCtxt->nsNr-2;
1198 index>=This->pParserCtxt->nsNr-nsNr*2; index-=2)
1200 Prefix = pooled_bstr_from_xmlChar(&This->saxreader->pool, This->pParserCtxt->nsTab[index]);
1202 if(This->vbInterface)
1203 hr = IVBSAXContentHandler_endPrefixMapping(
1204 This->saxreader->vbcontentHandler, &Prefix);
1206 hr = ISAXContentHandler_endPrefixMapping(
1207 This->saxreader->contentHandler,
1208 Prefix, SysStringLen(Prefix));
1212 format_error_message_from_id(This, hr);
1219 update_position(This, NULL);
1222 static void libxmlCharacters(
1227 saxlocator *This = ctx;
1232 BOOL lastEvent = FALSE;
1234 if(!(has_content_handler(This))) return;
1237 if(*(ch-1)=='\r') cur--;
1240 if(ch<This->pParserCtxt->input->base || ch>This->pParserCtxt->input->end)
1245 while(end-ch<len && *end!='\r') end++;
1252 if(!lastEvent) *end = '\n';
1254 Chars = pooled_bstr_from_xmlCharN(&This->saxreader->pool, cur, end-cur+1);
1255 if(This->vbInterface)
1256 hr = IVBSAXContentHandler_characters(
1257 This->saxreader->vbcontentHandler, &Chars);
1259 hr = ISAXContentHandler_characters(
1260 This->saxreader->contentHandler,
1261 Chars, SysStringLen(Chars));
1265 format_error_message_from_id(This, hr);
1269 This->column += end-cur+1;
1283 if(end-ch == len) break;
1286 if(ch<This->pParserCtxt->input->base || ch>This->pParserCtxt->input->end)
1287 This->column = This->realColumn
1288 +This->pParserCtxt->input->cur-This->lastCur;
1291 static void libxmlSetDocumentLocator(
1293 xmlSAXLocatorPtr loc)
1295 saxlocator *This = ctx;
1298 if(has_content_handler(This))
1300 if(This->vbInterface)
1301 hr = IVBSAXContentHandler_putref_documentLocator(This->saxreader->vbcontentHandler,
1302 &This->IVBSAXLocator_iface);
1304 hr = ISAXContentHandler_putDocumentLocator(This->saxreader->contentHandler,
1305 &This->ISAXLocator_iface);
1309 format_error_message_from_id(This, hr);
1312 static void libxmlComment(void *ctx, const xmlChar *value)
1314 saxlocator *This = ctx;
1317 xmlChar *beg = (xmlChar*)This->pParserCtxt->input->cur;
1319 while(beg-4>=This->pParserCtxt->input->base
1320 && memcmp(beg-4, "<!--", sizeof(char[4]))) beg--;
1321 update_position(This, beg);
1323 if(!This->vbInterface && !This->saxreader->lexicalHandler) return;
1324 if(This->vbInterface && !This->saxreader->vblexicalHandler) return;
1326 bValue = pooled_bstr_from_xmlChar(&This->saxreader->pool, value);
1328 if(This->vbInterface)
1329 hr = IVBSAXLexicalHandler_comment(
1330 This->saxreader->vblexicalHandler, &bValue);
1332 hr = ISAXLexicalHandler_comment(
1333 This->saxreader->lexicalHandler,
1334 bValue, SysStringLen(bValue));
1337 format_error_message_from_id(This, hr);
1339 update_position(This, NULL);
1342 static void libxmlFatalError(void *ctx, const char *msg, ...)
1344 saxlocator *This = ctx;
1350 va_start(args, msg);
1351 vsprintf(message, msg, args);
1354 len = MultiByteToWideChar(CP_UNIXCP, 0, message, -1, NULL, 0);
1355 error = heap_alloc(sizeof(WCHAR)*len);
1358 MultiByteToWideChar(CP_UNIXCP, 0, message, -1, error, len);
1359 TRACE("fatal error for %p: %s\n", This, debugstr_w(error));
1362 if(!has_error_handler(This))
1364 xmlStopParser(This->pParserCtxt);
1370 FIXME("Error handling is not compatible.\n");
1372 if(This->vbInterface)
1374 BSTR bstrError = SysAllocString(error);
1375 IVBSAXErrorHandler_fatalError(This->saxreader->vberrorHandler, &This->IVBSAXLocator_iface,
1376 &bstrError, E_FAIL);
1377 SysFreeString(bstrError);
1380 ISAXErrorHandler_fatalError(This->saxreader->errorHandler, &This->ISAXLocator_iface,
1385 xmlStopParser(This->pParserCtxt);
1389 static void libxmlCDataBlock(void *ctx, const xmlChar *value, int len)
1391 saxlocator *This = ctx;
1393 xmlChar *beg = (xmlChar*)This->pParserCtxt->input->cur-len;
1397 BOOL lastEvent = FALSE, change;
1399 while(beg-9>=This->pParserCtxt->input->base
1400 && memcmp(beg-9, "<![CDATA[", sizeof(char[9]))) beg--;
1401 update_position(This, beg);
1403 if(This->vbInterface && This->saxreader->vblexicalHandler)
1404 hr = IVBSAXLexicalHandler_startCDATA(This->saxreader->vblexicalHandler);
1405 if(!This->vbInterface && This->saxreader->lexicalHandler)
1406 hr = ISAXLexicalHandler_startCDATA(This->saxreader->lexicalHandler);
1410 format_error_message_from_id(This, hr);
1414 realLen = This->pParserCtxt->input->cur-beg-3;
1420 while(end-beg<realLen && *end!='\r') end++;
1421 if(end-beg==realLen)
1426 else if(end-beg==realLen-1 && *end=='\r' && *(end+1)=='\n')
1429 if(*end == '\r') change = TRUE;
1430 else change = FALSE;
1432 if(change) *end = '\n';
1434 if(has_content_handler(This))
1436 Chars = pooled_bstr_from_xmlCharN(&This->saxreader->pool, cur, end-cur+1);
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));
1446 if(change) *end = '\r';
1451 This->column += end-cur+2;
1456 if(This->vbInterface && This->saxreader->vblexicalHandler)
1457 hr = IVBSAXLexicalHandler_endCDATA(This->saxreader->vblexicalHandler);
1458 if(!This->vbInterface && This->saxreader->lexicalHandler)
1459 hr = ISAXLexicalHandler_endCDATA(This->saxreader->lexicalHandler);
1462 format_error_message_from_id(This, hr);
1464 This->column += 4+end-cur;
1467 /*** IVBSAXLocator interface ***/
1468 /*** IUnknown methods ***/
1469 static HRESULT WINAPI ivbsaxlocator_QueryInterface(IVBSAXLocator* iface, REFIID riid, void **ppvObject)
1471 saxlocator *This = impl_from_IVBSAXLocator( iface );
1473 TRACE("%p %s %p\n", This, debugstr_guid( riid ), ppvObject);
1477 if ( IsEqualGUID( riid, &IID_IUnknown ) ||
1478 IsEqualGUID( riid, &IID_IDispatch) ||
1479 IsEqualGUID( riid, &IID_IVBSAXLocator ))
1485 FIXME("interface %s not implemented\n", debugstr_guid(riid));
1486 return E_NOINTERFACE;
1489 IVBSAXLocator_AddRef( iface );
1494 static ULONG WINAPI ivbsaxlocator_AddRef(IVBSAXLocator* iface)
1496 saxlocator *This = impl_from_IVBSAXLocator( iface );
1497 TRACE("%p\n", This );
1498 return InterlockedIncrement( &This->ref );
1501 static ULONG WINAPI ivbsaxlocator_Release(
1502 IVBSAXLocator* iface)
1504 saxlocator *This = impl_from_IVBSAXLocator( iface );
1505 return ISAXLocator_Release((ISAXLocator*)&This->IVBSAXLocator_iface);
1508 /*** IDispatch methods ***/
1509 static HRESULT WINAPI ivbsaxlocator_GetTypeInfoCount( IVBSAXLocator *iface, UINT* pctinfo )
1511 saxlocator *This = impl_from_IVBSAXLocator( iface );
1513 TRACE("(%p)->(%p)\n", This, pctinfo);
1520 static HRESULT WINAPI ivbsaxlocator_GetTypeInfo(
1521 IVBSAXLocator *iface,
1522 UINT iTInfo, LCID lcid, ITypeInfo** ppTInfo )
1524 saxlocator *This = impl_from_IVBSAXLocator( iface );
1527 TRACE("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo);
1529 hr = get_typeinfo(IVBSAXLocator_tid, ppTInfo);
1534 static HRESULT WINAPI ivbsaxlocator_GetIDsOfNames(
1535 IVBSAXLocator *iface,
1537 LPOLESTR* rgszNames,
1542 saxlocator *This = impl_from_IVBSAXLocator( iface );
1543 ITypeInfo *typeinfo;
1546 TRACE("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames, cNames,
1549 if(!rgszNames || cNames == 0 || !rgDispId)
1550 return E_INVALIDARG;
1552 hr = get_typeinfo(IVBSAXLocator_tid, &typeinfo);
1555 hr = ITypeInfo_GetIDsOfNames(typeinfo, rgszNames, cNames, rgDispId);
1556 ITypeInfo_Release(typeinfo);
1562 static HRESULT WINAPI ivbsaxlocator_Invoke(
1563 IVBSAXLocator *iface,
1564 DISPID dispIdMember,
1568 DISPPARAMS* pDispParams,
1569 VARIANT* pVarResult,
1570 EXCEPINFO* pExcepInfo,
1573 saxlocator *This = impl_from_IVBSAXLocator( iface );
1574 ITypeInfo *typeinfo;
1577 TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
1578 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
1580 hr = get_typeinfo(IVBSAXLocator_tid, &typeinfo);
1583 hr = ITypeInfo_Invoke(typeinfo, &This->IVBSAXLocator_iface, dispIdMember, wFlags,
1584 pDispParams, pVarResult, pExcepInfo, puArgErr);
1585 ITypeInfo_Release(typeinfo);
1591 /*** IVBSAXLocator methods ***/
1592 static HRESULT WINAPI ivbsaxlocator_get_columnNumber(
1593 IVBSAXLocator* iface,
1596 saxlocator *This = impl_from_IVBSAXLocator( iface );
1597 return ISAXLocator_getColumnNumber((ISAXLocator*)&This->IVBSAXLocator_iface, pnColumn);
1600 static HRESULT WINAPI ivbsaxlocator_get_lineNumber(
1601 IVBSAXLocator* iface,
1604 saxlocator *This = impl_from_IVBSAXLocator( iface );
1605 return ISAXLocator_getLineNumber((ISAXLocator*)&This->IVBSAXLocator_iface, pnLine);
1608 static HRESULT WINAPI ivbsaxlocator_get_publicId(
1609 IVBSAXLocator* iface,
1612 saxlocator *This = impl_from_IVBSAXLocator( iface );
1613 return ISAXLocator_getPublicId((ISAXLocator*)&This->IVBSAXLocator_iface,
1614 (const WCHAR**)publicId);
1617 static HRESULT WINAPI ivbsaxlocator_get_systemId(
1618 IVBSAXLocator* iface,
1621 saxlocator *This = impl_from_IVBSAXLocator( iface );
1622 return ISAXLocator_getSystemId((ISAXLocator*)&This->IVBSAXLocator_iface,
1623 (const WCHAR**)systemId);
1626 static const struct IVBSAXLocatorVtbl ivbsaxlocator_vtbl =
1628 ivbsaxlocator_QueryInterface,
1629 ivbsaxlocator_AddRef,
1630 ivbsaxlocator_Release,
1631 ivbsaxlocator_GetTypeInfoCount,
1632 ivbsaxlocator_GetTypeInfo,
1633 ivbsaxlocator_GetIDsOfNames,
1634 ivbsaxlocator_Invoke,
1635 ivbsaxlocator_get_columnNumber,
1636 ivbsaxlocator_get_lineNumber,
1637 ivbsaxlocator_get_publicId,
1638 ivbsaxlocator_get_systemId
1641 /*** ISAXLocator interface ***/
1642 /*** IUnknown methods ***/
1643 static HRESULT WINAPI isaxlocator_QueryInterface(ISAXLocator* iface, REFIID riid, void **ppvObject)
1645 saxlocator *This = impl_from_ISAXLocator( iface );
1647 TRACE("%p %s %p\n", This, debugstr_guid( riid ), ppvObject );
1651 if ( IsEqualGUID( riid, &IID_IUnknown ) ||
1652 IsEqualGUID( riid, &IID_ISAXLocator ))
1658 FIXME("interface %s not implemented\n", debugstr_guid(riid));
1659 return E_NOINTERFACE;
1662 ISAXLocator_AddRef( iface );
1667 static ULONG WINAPI isaxlocator_AddRef(ISAXLocator* iface)
1669 saxlocator *This = impl_from_ISAXLocator( iface );
1670 TRACE("%p\n", This );
1671 return InterlockedIncrement( &This->ref );
1674 static ULONG WINAPI isaxlocator_Release(
1677 saxlocator *This = impl_from_ISAXLocator( iface );
1680 TRACE("%p\n", This );
1682 ref = InterlockedDecrement( &This->ref );
1685 SysFreeString(This->publicId);
1686 SysFreeString(This->systemId);
1687 heap_free(This->nsStack);
1689 ISAXXMLReader_Release(&This->saxreader->ISAXXMLReader_iface);
1696 /*** ISAXLocator methods ***/
1697 static HRESULT WINAPI isaxlocator_getColumnNumber(
1701 saxlocator *This = impl_from_ISAXLocator( iface );
1703 *pnColumn = This->column;
1707 static HRESULT WINAPI isaxlocator_getLineNumber(
1711 saxlocator *This = impl_from_ISAXLocator( iface );
1713 *pnLine = This->line;
1717 static HRESULT WINAPI isaxlocator_getPublicId(
1719 const WCHAR ** ppwchPublicId)
1722 saxlocator *This = impl_from_ISAXLocator( iface );
1724 SysFreeString(This->publicId);
1726 publicId = bstr_from_xmlChar(xmlSAX2GetPublicId(This->pParserCtxt));
1727 if(SysStringLen(publicId))
1728 This->publicId = (WCHAR*)&publicId;
1731 SysFreeString(publicId);
1732 This->publicId = NULL;
1735 *ppwchPublicId = This->publicId;
1739 static HRESULT WINAPI isaxlocator_getSystemId(
1741 const WCHAR ** ppwchSystemId)
1744 saxlocator *This = impl_from_ISAXLocator( iface );
1746 SysFreeString(This->systemId);
1748 systemId = bstr_from_xmlChar(xmlSAX2GetSystemId(This->pParserCtxt));
1749 if(SysStringLen(systemId))
1750 This->systemId = (WCHAR*)&systemId;
1753 SysFreeString(systemId);
1754 This->systemId = NULL;
1757 *ppwchSystemId = This->systemId;
1761 static const struct ISAXLocatorVtbl isaxlocator_vtbl =
1763 isaxlocator_QueryInterface,
1765 isaxlocator_Release,
1766 isaxlocator_getColumnNumber,
1767 isaxlocator_getLineNumber,
1768 isaxlocator_getPublicId,
1769 isaxlocator_getSystemId
1772 static HRESULT SAXLocator_create(saxreader *reader, saxlocator **ppsaxlocator, BOOL vbInterface)
1774 saxlocator *locator;
1776 locator = heap_alloc( sizeof (*locator) );
1778 return E_OUTOFMEMORY;
1780 locator->IVBSAXLocator_iface.lpVtbl = &ivbsaxlocator_vtbl;
1781 locator->ISAXLocator_iface.lpVtbl = &isaxlocator_vtbl;
1783 locator->vbInterface = vbInterface;
1785 locator->saxreader = reader;
1786 ISAXXMLReader_AddRef(&reader->ISAXXMLReader_iface);
1788 locator->pParserCtxt = NULL;
1789 locator->publicId = NULL;
1790 locator->systemId = NULL;
1791 locator->lastCur = NULL;
1793 locator->column = 0;
1794 locator->ret = S_OK;
1795 locator->nsStackSize = 8;
1796 locator->nsStackLast = 0;
1797 locator->nsStack = heap_alloc(sizeof(int)*locator->nsStackSize);
1798 if(!locator->nsStack)
1800 ISAXXMLReader_Release(&reader->ISAXXMLReader_iface);
1802 return E_OUTOFMEMORY;
1805 *ppsaxlocator = locator;
1807 TRACE("returning %p\n", *ppsaxlocator);
1812 /*** SAXXMLReader internal functions ***/
1813 static HRESULT internal_parseBuffer(saxreader *This, const char *buffer, int size, BOOL vbInterface)
1815 xmlCharEncoding encoding = XML_CHAR_ENCODING_NONE;
1816 xmlChar *enc_name = NULL;
1817 saxlocator *locator;
1820 hr = SAXLocator_create(This, &locator, vbInterface);
1826 const unsigned char *buff = (unsigned char*)buffer;
1828 encoding = xmlDetectCharEncoding((xmlChar*)buffer, 4);
1829 enc_name = (xmlChar*)xmlGetCharEncodingName(encoding);
1830 TRACE("detected encoding: %s\n", enc_name);
1831 /* skip BOM, parser won't switch encodings and so won't skip it on its own */
1832 if ((encoding == XML_CHAR_ENCODING_UTF8) &&
1833 buff[0] == 0xEF && buff[1] == 0xBB && buff[2] == 0xBF)
1840 locator->pParserCtxt = xmlCreateMemoryParserCtxt(buffer, size);
1841 if(!locator->pParserCtxt)
1843 ISAXLocator_Release(&locator->ISAXLocator_iface);
1847 if (encoding == XML_CHAR_ENCODING_UTF8)
1848 locator->pParserCtxt->encoding = xmlStrdup(enc_name);
1850 xmlFree(locator->pParserCtxt->sax);
1851 locator->pParserCtxt->sax = &locator->saxreader->sax;
1852 locator->pParserCtxt->userData = locator;
1854 This->isParsing = TRUE;
1855 if(xmlParseDocument(locator->pParserCtxt) == -1) hr = E_FAIL;
1856 else hr = locator->ret;
1857 This->isParsing = FALSE;
1859 if(locator->pParserCtxt)
1861 locator->pParserCtxt->sax = NULL;
1862 xmlFreeParserCtxt(locator->pParserCtxt);
1863 locator->pParserCtxt = NULL;
1866 ISAXLocator_Release(&locator->ISAXLocator_iface);
1870 static HRESULT internal_parseStream(saxreader *This, IStream *stream, BOOL vbInterface)
1872 saxlocator *locator;
1877 hr = IStream_Read(stream, data, sizeof(data), &dataRead);
1881 hr = SAXLocator_create(This, &locator, vbInterface);
1885 locator->pParserCtxt = xmlCreatePushParserCtxt(
1886 &locator->saxreader->sax, locator,
1887 data, dataRead, NULL);
1888 if(!locator->pParserCtxt)
1890 ISAXLocator_Release(&locator->ISAXLocator_iface);
1894 This->isParsing = TRUE;
1897 hr = IStream_Read(stream, data, sizeof(data), &dataRead);
1901 if(xmlParseChunk(locator->pParserCtxt, data, dataRead, 0) != XML_ERR_OK) hr = E_FAIL;
1902 else hr = locator->ret;
1904 if(hr != S_OK) break;
1906 if(dataRead != sizeof(data))
1908 if(xmlParseChunk(locator->pParserCtxt, data, 0, 1) != XML_ERR_OK) hr = E_FAIL;
1909 else hr = locator->ret;
1914 This->isParsing = FALSE;
1916 xmlFreeParserCtxt(locator->pParserCtxt);
1917 locator->pParserCtxt = NULL;
1918 ISAXLocator_Release(&locator->ISAXLocator_iface);
1922 static HRESULT internal_getEntityResolver(
1924 void *pEntityResolver,
1927 FIXME("(%p)->(%p) stub\n", This, pEntityResolver);
1931 static HRESULT internal_putEntityResolver(
1933 void *pEntityResolver,
1936 FIXME("(%p)->(%p) stub\n", This, pEntityResolver);
1940 static HRESULT internal_getContentHandler(
1942 void *pContentHandler,
1945 TRACE("(%p)->(%p)\n", This, pContentHandler);
1946 if(pContentHandler == NULL)
1948 if((vbInterface && This->vbcontentHandler)
1949 || (!vbInterface && This->contentHandler))
1952 IVBSAXContentHandler_AddRef(This->vbcontentHandler);
1954 ISAXContentHandler_AddRef(This->contentHandler);
1956 if(vbInterface) *(IVBSAXContentHandler**)pContentHandler =
1957 This->vbcontentHandler;
1958 else *(ISAXContentHandler**)pContentHandler = This->contentHandler;
1963 static HRESULT internal_putContentHandler(
1965 void *contentHandler,
1968 TRACE("(%p)->(%p)\n", This, contentHandler);
1972 IVBSAXContentHandler_AddRef((IVBSAXContentHandler*)contentHandler);
1974 ISAXContentHandler_AddRef((ISAXContentHandler*)contentHandler);
1976 if((vbInterface && This->vbcontentHandler)
1977 || (!vbInterface && This->contentHandler))
1980 IVBSAXContentHandler_Release(This->vbcontentHandler);
1982 ISAXContentHandler_Release(This->contentHandler);
1985 This->vbcontentHandler = contentHandler;
1987 This->contentHandler = contentHandler;
1992 static HRESULT internal_getDTDHandler(
1997 FIXME("(%p)->(%p) stub\n", This, pDTDHandler);
2001 static HRESULT internal_putDTDHandler(
2006 FIXME("(%p)->(%p) stub\n", This, pDTDHandler);
2010 static HRESULT internal_getErrorHandler(
2012 void *pErrorHandler,
2015 TRACE("(%p)->(%p)\n", This, pErrorHandler);
2016 if(pErrorHandler == NULL)
2019 if(vbInterface && This->vberrorHandler)
2020 IVBSAXErrorHandler_AddRef(This->vberrorHandler);
2021 else if(!vbInterface && This->errorHandler)
2022 ISAXErrorHandler_AddRef(This->errorHandler);
2025 *(IVBSAXErrorHandler**)pErrorHandler = This->vberrorHandler;
2027 *(ISAXErrorHandler**)pErrorHandler = This->errorHandler;
2033 static HRESULT internal_putErrorHandler(
2038 TRACE("(%p)->(%p)\n", This, errorHandler);
2042 IVBSAXErrorHandler_AddRef((IVBSAXErrorHandler*)errorHandler);
2044 ISAXErrorHandler_AddRef((ISAXErrorHandler*)errorHandler);
2047 if(vbInterface && This->vberrorHandler)
2048 IVBSAXErrorHandler_Release(This->vberrorHandler);
2049 else if(!vbInterface && This->errorHandler)
2050 ISAXErrorHandler_Release(This->errorHandler);
2053 This->vberrorHandler = errorHandler;
2055 This->errorHandler = errorHandler;
2061 static HRESULT internal_parse(
2068 TRACE("(%p)->(%s)\n", This, debugstr_variant(&varInput));
2070 /* Dispose of the BSTRs in the pool from a prior run, if any. */
2071 free_bstr_pool(&This->pool);
2073 switch(V_VT(&varInput))
2076 hr = internal_parseBuffer(This, (const char*)V_BSTR(&varInput),
2077 SysStringByteLen(V_BSTR(&varInput)), vbInterface);
2079 case VT_ARRAY|VT_UI1: {
2081 LONG lBound, uBound;
2084 hr = SafeArrayGetLBound(V_ARRAY(&varInput), 1, &lBound);
2085 if(hr != S_OK) break;
2086 hr = SafeArrayGetUBound(V_ARRAY(&varInput), 1, &uBound);
2087 if(hr != S_OK) break;
2088 dataRead = (uBound-lBound)*SafeArrayGetElemsize(V_ARRAY(&varInput));
2089 hr = SafeArrayAccessData(V_ARRAY(&varInput), &pSAData);
2090 if(hr != S_OK) break;
2091 hr = internal_parseBuffer(This, pSAData, dataRead, vbInterface);
2092 SafeArrayUnaccessData(V_ARRAY(&varInput));
2097 IPersistStream *persistStream;
2098 IStream *stream = NULL;
2099 IXMLDOMDocument *xmlDoc;
2101 if(IUnknown_QueryInterface(V_UNKNOWN(&varInput),
2102 &IID_IXMLDOMDocument, (void**)&xmlDoc) == S_OK)
2106 IXMLDOMDocument_get_xml(xmlDoc, &bstrData);
2107 hr = internal_parseBuffer(This, (const char*)bstrData,
2108 SysStringByteLen(bstrData), vbInterface);
2109 IXMLDOMDocument_Release(xmlDoc);
2110 SysFreeString(bstrData);
2114 if(IUnknown_QueryInterface(V_UNKNOWN(&varInput),
2115 &IID_IPersistStream, (void**)&persistStream) == S_OK)
2117 hr = CreateStreamOnHGlobal(NULL, TRUE, &stream);
2120 IPersistStream_Release(persistStream);
2124 hr = IPersistStream_Save(persistStream, stream, TRUE);
2125 IPersistStream_Release(persistStream);
2128 IStream_Release(stream);
2132 if(stream || IUnknown_QueryInterface(V_UNKNOWN(&varInput),
2133 &IID_IStream, (void**)&stream) == S_OK)
2135 hr = internal_parseStream(This, stream, vbInterface);
2136 IStream_Release(stream);
2141 WARN("vt %d not implemented\n", V_VT(&varInput));
2148 static HRESULT internal_vbonDataAvailable(void *obj, char *ptr, DWORD len)
2150 saxreader *This = obj;
2152 return internal_parseBuffer(This, ptr, len, TRUE);
2155 static HRESULT internal_onDataAvailable(void *obj, char *ptr, DWORD len)
2157 saxreader *This = obj;
2159 return internal_parseBuffer(This, ptr, len, FALSE);
2162 static HRESULT internal_parseURL(
2170 TRACE("(%p)->(%s)\n", This, debugstr_w(url));
2172 if(vbInterface) hr = bind_url(url, internal_vbonDataAvailable, This, &bsc);
2173 else hr = bind_url(url, internal_onDataAvailable, This, &bsc);
2183 static HRESULT internal_putProperty(
2189 static const WCHAR wszCharset[] = {
2190 'c','h','a','r','s','e','t',0
2192 static const WCHAR wszDeclarationHandler[] = {
2193 'h','t','t','p',':','/','/','x','m','l','.','o','r','g','/',
2194 's','a','x','/','p','r','o','p','e','r','t','i','e','s','/',
2195 'd','e','c','l','a','r','a','t','i','o','n',
2196 '-','h','a','n','d','l','e','r',0
2198 static const WCHAR wszDomNode[] = {
2199 'h','t','t','p',':','/','/','x','m','l','.','o','r','g','/',
2200 's','a','x','/','p','r','o','p','e','r','t','i','e','s','/',
2201 'd','o','m','-','n','o','d','e',0
2203 static const WCHAR wszInputSource[] = {
2204 'i','n','p','u','t','-','s','o','u','r','c','e',0
2206 static const WCHAR wszLexicalHandler[] = {
2207 'h','t','t','p',':','/','/','x','m','l','.','o','r','g','/',
2208 's','a','x','/','p','r','o','p','e','r','t','i','e','s','/',
2209 'l','e','x','i','c','a','l','-','h','a','n','d','l','e','r',0
2211 static const WCHAR wszMaxElementDepth[] = {
2212 'm','a','x','-','e','l','e','m','e','n','t','-','d','e','p','t','h',0
2214 static const WCHAR wszMaxXMLSize[] = {
2215 'm','a','x','-','x','m','l','-','s','i','z','e',0
2217 static const WCHAR wszSchemaDeclarationHandler[] = {
2218 's','c','h','e','m','a','-',
2219 'd','e','c','l','a','r','a','t','i','o','n','-',
2220 'h','a','n','d','l','e','r',0
2222 static const WCHAR wszXMLDeclEncoding[] = {
2223 'x','m','l','d','e','c','l','-','e','n','c','o','d','i','n','g',0
2225 static const WCHAR wszXMLDeclStandalone[] = {
2226 'x','m','l','d','e','c','l',
2227 '-','s','t','a','n','d','a','l','o','n','e',0
2229 static const WCHAR wszXMLDeclVersion[] = {
2230 'x','m','l','d','e','c','l','-','v','e','r','s','i','o','n',0
2233 TRACE("(%p)->(%s %s)\n", This, debugstr_w(pProp), debugstr_variant(&value));
2235 if(!memcmp(pProp, wszDeclarationHandler, sizeof(wszDeclarationHandler)))
2237 if(This->isParsing) return E_FAIL;
2239 if(V_UNKNOWN(&value))
2242 IVBSAXDeclHandler_AddRef((IVBSAXDeclHandler*)V_UNKNOWN(&value));
2244 ISAXDeclHandler_AddRef((ISAXDeclHandler*)V_UNKNOWN(&value));
2246 if((vbInterface && This->vbdeclHandler)
2247 || (!vbInterface && This->declHandler))
2250 IVBSAXDeclHandler_Release(This->vbdeclHandler);
2252 ISAXDeclHandler_Release(This->declHandler);
2255 This->vbdeclHandler = (IVBSAXDeclHandler*)V_UNKNOWN(&value);
2257 This->declHandler = (ISAXDeclHandler*)V_UNKNOWN(&value);
2261 if(!memcmp(pProp, wszLexicalHandler, sizeof(wszLexicalHandler)))
2263 if(This->isParsing) return E_FAIL;
2265 if(V_UNKNOWN(&value))
2268 IVBSAXLexicalHandler_AddRef(
2269 (IVBSAXLexicalHandler*)V_UNKNOWN(&value));
2271 ISAXLexicalHandler_AddRef(
2272 (ISAXLexicalHandler*)V_UNKNOWN(&value));
2274 if((vbInterface && This->vblexicalHandler)
2275 || (!vbInterface && This->lexicalHandler))
2278 IVBSAXLexicalHandler_Release(This->vblexicalHandler);
2280 ISAXLexicalHandler_Release(This->lexicalHandler);
2283 This->vblexicalHandler = (IVBSAXLexicalHandler*)V_UNKNOWN(&value);
2285 This->lexicalHandler = (ISAXLexicalHandler*)V_UNKNOWN(&value);
2289 FIXME("(%p)->(%s): unsupported property\n", This, debugstr_w(pProp));
2291 if(!memcmp(pProp, wszCharset, sizeof(wszCharset)))
2294 if(!memcmp(pProp, wszDomNode, sizeof(wszDomNode)))
2297 if(!memcmp(pProp, wszInputSource, sizeof(wszInputSource)))
2300 if(!memcmp(pProp, wszMaxElementDepth, sizeof(wszMaxElementDepth)))
2303 if(!memcmp(pProp, wszMaxXMLSize, sizeof(wszMaxXMLSize)))
2306 if(!memcmp(pProp, wszSchemaDeclarationHandler,
2307 sizeof(wszSchemaDeclarationHandler)))
2310 if(!memcmp(pProp, wszXMLDeclEncoding, sizeof(wszXMLDeclEncoding)))
2313 if(!memcmp(pProp, wszXMLDeclStandalone, sizeof(wszXMLDeclStandalone)))
2316 if(!memcmp(pProp, wszXMLDeclVersion, sizeof(wszXMLDeclVersion)))
2319 return E_INVALIDARG;
2322 /*** IVBSAXXMLReader interface ***/
2323 /*** IUnknown methods ***/
2324 static HRESULT WINAPI saxxmlreader_QueryInterface(IVBSAXXMLReader* iface, REFIID riid, void **ppvObject)
2326 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2328 TRACE("%p %s %p\n", This, debugstr_guid( riid ), ppvObject );
2332 if ( IsEqualGUID( riid, &IID_IUnknown ) ||
2333 IsEqualGUID( riid, &IID_IDispatch ) ||
2334 IsEqualGUID( riid, &IID_IVBSAXXMLReader ))
2338 else if( IsEqualGUID( riid, &IID_ISAXXMLReader ))
2340 *ppvObject = &This->ISAXXMLReader_iface;
2344 FIXME("interface %s not implemented\n", debugstr_guid(riid));
2345 return E_NOINTERFACE;
2348 IVBSAXXMLReader_AddRef( iface );
2353 static ULONG WINAPI saxxmlreader_AddRef(IVBSAXXMLReader* iface)
2355 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2356 TRACE("%p\n", This );
2357 return InterlockedIncrement( &This->ref );
2360 static ULONG WINAPI saxxmlreader_Release(
2361 IVBSAXXMLReader* iface)
2363 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2366 TRACE("%p\n", This );
2368 ref = InterlockedDecrement( &This->ref );
2371 if(This->contentHandler)
2372 ISAXContentHandler_Release(This->contentHandler);
2374 if(This->vbcontentHandler)
2375 IVBSAXContentHandler_Release(This->vbcontentHandler);
2377 if(This->errorHandler)
2378 ISAXErrorHandler_Release(This->errorHandler);
2380 if(This->vberrorHandler)
2381 IVBSAXErrorHandler_Release(This->vberrorHandler);
2383 if(This->lexicalHandler)
2384 ISAXLexicalHandler_Release(This->lexicalHandler);
2386 if(This->vblexicalHandler)
2387 IVBSAXLexicalHandler_Release(This->vblexicalHandler);
2389 if(This->declHandler)
2390 ISAXDeclHandler_Release(This->declHandler);
2392 if(This->vbdeclHandler)
2393 IVBSAXDeclHandler_Release(This->vbdeclHandler);
2395 free_bstr_pool(&This->pool);
2403 static HRESULT WINAPI saxxmlreader_GetTypeInfoCount( IVBSAXXMLReader *iface, UINT* pctinfo )
2405 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2407 TRACE("(%p)->(%p)\n", This, pctinfo);
2414 static HRESULT WINAPI saxxmlreader_GetTypeInfo(
2415 IVBSAXXMLReader *iface,
2416 UINT iTInfo, LCID lcid, ITypeInfo** ppTInfo )
2418 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2421 TRACE("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo);
2423 hr = get_typeinfo(IVBSAXXMLReader_tid, ppTInfo);
2428 static HRESULT WINAPI saxxmlreader_GetIDsOfNames(
2429 IVBSAXXMLReader *iface,
2431 LPOLESTR* rgszNames,
2436 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2437 ITypeInfo *typeinfo;
2440 TRACE("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames, cNames,
2443 if(!rgszNames || cNames == 0 || !rgDispId)
2444 return E_INVALIDARG;
2446 hr = get_typeinfo(IVBSAXXMLReader_tid, &typeinfo);
2449 hr = ITypeInfo_GetIDsOfNames(typeinfo, rgszNames, cNames, rgDispId);
2450 ITypeInfo_Release(typeinfo);
2456 static HRESULT WINAPI saxxmlreader_Invoke(
2457 IVBSAXXMLReader *iface,
2458 DISPID dispIdMember,
2462 DISPPARAMS* pDispParams,
2463 VARIANT* pVarResult,
2464 EXCEPINFO* pExcepInfo,
2467 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2468 ITypeInfo *typeinfo;
2471 TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
2472 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
2474 hr = get_typeinfo(IVBSAXXMLReader_tid, &typeinfo);
2477 hr = ITypeInfo_Invoke(typeinfo, &This->IVBSAXXMLReader_iface, dispIdMember, wFlags,
2478 pDispParams, pVarResult, pExcepInfo, puArgErr);
2479 ITypeInfo_Release(typeinfo);
2485 /*** IVBSAXXMLReader methods ***/
2486 static HRESULT WINAPI saxxmlreader_getFeature(
2487 IVBSAXXMLReader* iface,
2488 const WCHAR *pFeature,
2489 VARIANT_BOOL *pValue)
2491 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2493 FIXME("(%p)->(%s %p) stub\n", This, debugstr_w(pFeature), pValue);
2497 static HRESULT WINAPI saxxmlreader_putFeature(
2498 IVBSAXXMLReader* iface,
2499 const WCHAR *pFeature,
2500 VARIANT_BOOL vfValue)
2502 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2504 FIXME("(%p)->(%s %x) stub\n", This, debugstr_w(pFeature), vfValue);
2508 static HRESULT WINAPI saxxmlreader_getProperty(
2509 IVBSAXXMLReader* iface,
2513 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2515 FIXME("(%p)->(%s %p) stub\n", This, debugstr_w(pProp), pValue);
2519 static HRESULT WINAPI saxxmlreader_putProperty(
2520 IVBSAXXMLReader* iface,
2524 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2525 return internal_putProperty(This, pProp, value, TRUE);
2528 static HRESULT WINAPI saxxmlreader_get_entityResolver(
2529 IVBSAXXMLReader* iface,
2530 IVBSAXEntityResolver **pEntityResolver)
2532 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2533 return internal_getEntityResolver(This, pEntityResolver, TRUE);
2536 static HRESULT WINAPI saxxmlreader_put_entityResolver(
2537 IVBSAXXMLReader* iface,
2538 IVBSAXEntityResolver *pEntityResolver)
2540 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2541 return internal_putEntityResolver(This, pEntityResolver, TRUE);
2544 static HRESULT WINAPI saxxmlreader_get_contentHandler(
2545 IVBSAXXMLReader* iface,
2546 IVBSAXContentHandler **ppContentHandler)
2548 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2549 return internal_getContentHandler(This, ppContentHandler, TRUE);
2552 static HRESULT WINAPI saxxmlreader_put_contentHandler(
2553 IVBSAXXMLReader* iface,
2554 IVBSAXContentHandler *contentHandler)
2556 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2557 return internal_putContentHandler(This, contentHandler, TRUE);
2560 static HRESULT WINAPI saxxmlreader_get_dtdHandler(
2561 IVBSAXXMLReader* iface,
2562 IVBSAXDTDHandler **pDTDHandler)
2564 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2565 return internal_getDTDHandler(This, pDTDHandler, TRUE);
2568 static HRESULT WINAPI saxxmlreader_put_dtdHandler(
2569 IVBSAXXMLReader* iface,
2570 IVBSAXDTDHandler *pDTDHandler)
2572 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2573 return internal_putDTDHandler(This, pDTDHandler, TRUE);
2576 static HRESULT WINAPI saxxmlreader_get_errorHandler(
2577 IVBSAXXMLReader* iface,
2578 IVBSAXErrorHandler **pErrorHandler)
2580 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2581 return internal_getErrorHandler(This, pErrorHandler, TRUE);
2584 static HRESULT WINAPI saxxmlreader_put_errorHandler(
2585 IVBSAXXMLReader* iface,
2586 IVBSAXErrorHandler *errorHandler)
2588 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2589 return internal_putErrorHandler(This, errorHandler, TRUE);
2592 static HRESULT WINAPI saxxmlreader_get_baseURL(
2593 IVBSAXXMLReader* iface,
2594 const WCHAR **pBaseUrl)
2596 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2598 FIXME("(%p)->(%p) stub\n", This, pBaseUrl);
2602 static HRESULT WINAPI saxxmlreader_put_baseURL(
2603 IVBSAXXMLReader* iface,
2604 const WCHAR *pBaseUrl)
2606 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2608 FIXME("(%p)->(%s) stub\n", This, debugstr_w(pBaseUrl));
2612 static HRESULT WINAPI saxxmlreader_get_secureBaseURL(
2613 IVBSAXXMLReader* iface,
2614 const WCHAR **pSecureBaseUrl)
2616 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2618 FIXME("(%p)->(%p) stub\n", This, pSecureBaseUrl);
2623 static HRESULT WINAPI saxxmlreader_put_secureBaseURL(
2624 IVBSAXXMLReader* iface,
2625 const WCHAR *secureBaseUrl)
2627 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2629 FIXME("(%p)->(%s) stub\n", This, debugstr_w(secureBaseUrl));
2633 static HRESULT WINAPI saxxmlreader_parse(
2634 IVBSAXXMLReader* iface,
2637 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2638 return internal_parse(This, varInput, TRUE);
2641 static HRESULT WINAPI saxxmlreader_parseURL(
2642 IVBSAXXMLReader* iface,
2645 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2646 return internal_parseURL(This, url, TRUE);
2649 static const struct IVBSAXXMLReaderVtbl saxreader_vtbl =
2651 saxxmlreader_QueryInterface,
2652 saxxmlreader_AddRef,
2653 saxxmlreader_Release,
2654 saxxmlreader_GetTypeInfoCount,
2655 saxxmlreader_GetTypeInfo,
2656 saxxmlreader_GetIDsOfNames,
2657 saxxmlreader_Invoke,
2658 saxxmlreader_getFeature,
2659 saxxmlreader_putFeature,
2660 saxxmlreader_getProperty,
2661 saxxmlreader_putProperty,
2662 saxxmlreader_get_entityResolver,
2663 saxxmlreader_put_entityResolver,
2664 saxxmlreader_get_contentHandler,
2665 saxxmlreader_put_contentHandler,
2666 saxxmlreader_get_dtdHandler,
2667 saxxmlreader_put_dtdHandler,
2668 saxxmlreader_get_errorHandler,
2669 saxxmlreader_put_errorHandler,
2670 saxxmlreader_get_baseURL,
2671 saxxmlreader_put_baseURL,
2672 saxxmlreader_get_secureBaseURL,
2673 saxxmlreader_put_secureBaseURL,
2675 saxxmlreader_parseURL
2678 /*** ISAXXMLReader interface ***/
2679 /*** IUnknown methods ***/
2680 static HRESULT WINAPI isaxxmlreader_QueryInterface(ISAXXMLReader* iface, REFIID riid, void **ppvObject)
2682 saxreader *This = impl_from_ISAXXMLReader( iface );
2683 return saxxmlreader_QueryInterface(&This->IVBSAXXMLReader_iface, riid, ppvObject);
2686 static ULONG WINAPI isaxxmlreader_AddRef(ISAXXMLReader* iface)
2688 saxreader *This = impl_from_ISAXXMLReader( iface );
2689 return saxxmlreader_AddRef(&This->IVBSAXXMLReader_iface);
2692 static ULONG WINAPI isaxxmlreader_Release(ISAXXMLReader* iface)
2694 saxreader *This = impl_from_ISAXXMLReader( iface );
2695 return saxxmlreader_Release(&This->IVBSAXXMLReader_iface);
2698 /*** ISAXXMLReader methods ***/
2699 static HRESULT WINAPI isaxxmlreader_getFeature(
2700 ISAXXMLReader* iface,
2701 const WCHAR *pFeature,
2702 VARIANT_BOOL *pValue)
2704 saxreader *This = impl_from_ISAXXMLReader( iface );
2705 return IVBSAXXMLReader_getFeature(&This->IVBSAXXMLReader_iface, pFeature, pValue);
2708 static HRESULT WINAPI isaxxmlreader_putFeature(
2709 ISAXXMLReader* iface,
2710 const WCHAR *pFeature,
2711 VARIANT_BOOL vfValue)
2713 saxreader *This = impl_from_ISAXXMLReader( iface );
2714 return IVBSAXXMLReader_putFeature(&This->IVBSAXXMLReader_iface, pFeature, vfValue);
2717 static HRESULT WINAPI isaxxmlreader_getProperty(
2718 ISAXXMLReader* iface,
2722 saxreader *This = impl_from_ISAXXMLReader( iface );
2723 return IVBSAXXMLReader_getProperty(&This->IVBSAXXMLReader_iface, pProp, pValue);
2726 static HRESULT WINAPI isaxxmlreader_putProperty(
2727 ISAXXMLReader* iface,
2731 saxreader *This = impl_from_ISAXXMLReader( iface );
2732 return internal_putProperty(This, pProp, value, FALSE);
2735 static HRESULT WINAPI isaxxmlreader_getEntityResolver(
2736 ISAXXMLReader* iface,
2737 ISAXEntityResolver **ppEntityResolver)
2739 saxreader *This = impl_from_ISAXXMLReader( iface );
2740 return internal_getEntityResolver(This, ppEntityResolver, FALSE);
2743 static HRESULT WINAPI isaxxmlreader_putEntityResolver(
2744 ISAXXMLReader* iface,
2745 ISAXEntityResolver *pEntityResolver)
2747 saxreader *This = impl_from_ISAXXMLReader( iface );
2748 return internal_putEntityResolver(This, pEntityResolver, FALSE);
2751 static HRESULT WINAPI isaxxmlreader_getContentHandler(
2752 ISAXXMLReader* iface,
2753 ISAXContentHandler **pContentHandler)
2755 saxreader *This = impl_from_ISAXXMLReader( iface );
2756 return internal_getContentHandler(This, pContentHandler, FALSE);
2759 static HRESULT WINAPI isaxxmlreader_putContentHandler(
2760 ISAXXMLReader* iface,
2761 ISAXContentHandler *contentHandler)
2763 saxreader *This = impl_from_ISAXXMLReader( iface );
2764 return internal_putContentHandler(This, contentHandler, FALSE);
2767 static HRESULT WINAPI isaxxmlreader_getDTDHandler(
2768 ISAXXMLReader* iface,
2769 ISAXDTDHandler **pDTDHandler)
2771 saxreader *This = impl_from_ISAXXMLReader( iface );
2772 return internal_getDTDHandler(This, pDTDHandler, FALSE);
2775 static HRESULT WINAPI isaxxmlreader_putDTDHandler(
2776 ISAXXMLReader* iface,
2777 ISAXDTDHandler *pDTDHandler)
2779 saxreader *This = impl_from_ISAXXMLReader( iface );
2780 return internal_putDTDHandler(This, pDTDHandler, FALSE);
2783 static HRESULT WINAPI isaxxmlreader_getErrorHandler(
2784 ISAXXMLReader* iface,
2785 ISAXErrorHandler **pErrorHandler)
2787 saxreader *This = impl_from_ISAXXMLReader( iface );
2788 return internal_getErrorHandler(This, pErrorHandler, FALSE);
2791 static HRESULT WINAPI isaxxmlreader_putErrorHandler(
2792 ISAXXMLReader* iface,
2793 ISAXErrorHandler *errorHandler)
2795 saxreader *This = impl_from_ISAXXMLReader( iface );
2796 return internal_putErrorHandler(This, errorHandler, FALSE);
2799 static HRESULT WINAPI isaxxmlreader_getBaseURL(
2800 ISAXXMLReader* iface,
2801 const WCHAR **pBaseUrl)
2803 saxreader *This = impl_from_ISAXXMLReader( iface );
2804 return IVBSAXXMLReader_get_baseURL(&This->IVBSAXXMLReader_iface, pBaseUrl);
2807 static HRESULT WINAPI isaxxmlreader_putBaseURL(
2808 ISAXXMLReader* iface,
2809 const WCHAR *pBaseUrl)
2811 saxreader *This = impl_from_ISAXXMLReader( iface );
2812 return IVBSAXXMLReader_put_baseURL(&This->IVBSAXXMLReader_iface, pBaseUrl);
2815 static HRESULT WINAPI isaxxmlreader_getSecureBaseURL(
2816 ISAXXMLReader* iface,
2817 const WCHAR **pSecureBaseUrl)
2819 saxreader *This = impl_from_ISAXXMLReader( iface );
2820 return IVBSAXXMLReader_get_secureBaseURL(&This->IVBSAXXMLReader_iface, pSecureBaseUrl);
2823 static HRESULT WINAPI isaxxmlreader_putSecureBaseURL(
2824 ISAXXMLReader* iface,
2825 const WCHAR *secureBaseUrl)
2827 saxreader *This = impl_from_ISAXXMLReader( iface );
2828 return IVBSAXXMLReader_put_secureBaseURL(&This->IVBSAXXMLReader_iface, secureBaseUrl);
2831 static HRESULT WINAPI isaxxmlreader_parse(
2832 ISAXXMLReader* iface,
2835 saxreader *This = impl_from_ISAXXMLReader( iface );
2836 return internal_parse(This, varInput, FALSE);
2839 static HRESULT WINAPI isaxxmlreader_parseURL(
2840 ISAXXMLReader* iface,
2843 saxreader *This = impl_from_ISAXXMLReader( iface );
2844 return internal_parseURL(This, url, FALSE);
2847 static const struct ISAXXMLReaderVtbl isaxreader_vtbl =
2849 isaxxmlreader_QueryInterface,
2850 isaxxmlreader_AddRef,
2851 isaxxmlreader_Release,
2852 isaxxmlreader_getFeature,
2853 isaxxmlreader_putFeature,
2854 isaxxmlreader_getProperty,
2855 isaxxmlreader_putProperty,
2856 isaxxmlreader_getEntityResolver,
2857 isaxxmlreader_putEntityResolver,
2858 isaxxmlreader_getContentHandler,
2859 isaxxmlreader_putContentHandler,
2860 isaxxmlreader_getDTDHandler,
2861 isaxxmlreader_putDTDHandler,
2862 isaxxmlreader_getErrorHandler,
2863 isaxxmlreader_putErrorHandler,
2864 isaxxmlreader_getBaseURL,
2865 isaxxmlreader_putBaseURL,
2866 isaxxmlreader_getSecureBaseURL,
2867 isaxxmlreader_putSecureBaseURL,
2868 isaxxmlreader_parse,
2869 isaxxmlreader_parseURL
2872 HRESULT SAXXMLReader_create(IUnknown *pUnkOuter, LPVOID *ppObj)
2876 TRACE("(%p,%p)\n", pUnkOuter, ppObj);
2878 reader = heap_alloc( sizeof (*reader) );
2880 return E_OUTOFMEMORY;
2882 reader->IVBSAXXMLReader_iface.lpVtbl = &saxreader_vtbl;
2883 reader->ISAXXMLReader_iface.lpVtbl = &isaxreader_vtbl;
2885 reader->contentHandler = NULL;
2886 reader->vbcontentHandler = NULL;
2887 reader->errorHandler = NULL;
2888 reader->vberrorHandler = NULL;
2889 reader->lexicalHandler = NULL;
2890 reader->vblexicalHandler = NULL;
2891 reader->declHandler = NULL;
2892 reader->vbdeclHandler = NULL;
2893 reader->isParsing = FALSE;
2894 reader->pool.pool = NULL;
2895 reader->pool.index = 0;
2896 reader->pool.len = 0;
2898 memset(&reader->sax, 0, sizeof(xmlSAXHandler));
2899 reader->sax.initialized = XML_SAX2_MAGIC;
2900 reader->sax.startDocument = libxmlStartDocument;
2901 reader->sax.endDocument = libxmlEndDocument;
2902 reader->sax.startElementNs = libxmlStartElementNS;
2903 reader->sax.endElementNs = libxmlEndElementNS;
2904 reader->sax.characters = libxmlCharacters;
2905 reader->sax.setDocumentLocator = libxmlSetDocumentLocator;
2906 reader->sax.comment = libxmlComment;
2907 reader->sax.error = libxmlFatalError;
2908 reader->sax.fatalError = libxmlFatalError;
2909 reader->sax.cdataBlock = libxmlCDataBlock;
2911 *ppObj = &reader->IVBSAXXMLReader_iface;
2913 TRACE("returning iface %p\n", *ppObj);
2920 HRESULT SAXXMLReader_create(IUnknown *pUnkOuter, LPVOID *ppObj)
2922 MESSAGE("This program tried to use a SAX XML Reader object, but\n"
2923 "libxml2 support was not present at compile time.\n");