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
37 #include "wine/debug.h"
39 #include "msxml_private.h"
41 WINE_DEFAULT_DEBUG_CHANNEL(msxml);
45 #include <libxml/SAX2.h>
46 #include <libxml/parserInternals.h>
48 typedef struct _saxreader
50 const struct IVBSAXXMLReaderVtbl *lpVBSAXXMLReaderVtbl;
51 const struct ISAXXMLReaderVtbl *lpSAXXMLReaderVtbl;
53 struct ISAXContentHandler *contentHandler;
54 struct IVBSAXContentHandler *vbcontentHandler;
55 struct ISAXErrorHandler *errorHandler;
56 struct IVBSAXErrorHandler *vberrorHandler;
57 struct ISAXLexicalHandler *lexicalHandler;
58 struct IVBSAXLexicalHandler *vblexicalHandler;
59 struct ISAXDeclHandler *declHandler;
60 struct IVBSAXDeclHandler *vbdeclHandler;
65 typedef struct _saxlocator
67 const struct IVBSAXLocatorVtbl *lpVBSAXLocatorVtbl;
68 const struct ISAXLocatorVtbl *lpSAXLocatorVtbl;
72 xmlParserCtxtPtr pParserCtxt;
86 typedef struct _saxattributes
88 const struct IVBSAXAttributesVtbl *lpVBSAXAttributesVtbl;
89 const struct ISAXAttributesVtbl *lpSAXAttributesVtbl;
98 static inline saxreader *impl_from_IVBSAXXMLReader( IVBSAXXMLReader *iface )
100 return (saxreader *)((char*)iface - FIELD_OFFSET(saxreader, lpVBSAXXMLReaderVtbl));
103 static inline saxreader *impl_from_ISAXXMLReader( ISAXXMLReader *iface )
105 return (saxreader *)((char*)iface - FIELD_OFFSET(saxreader, lpSAXXMLReaderVtbl));
108 static inline saxlocator *impl_from_IVBSAXLocator( IVBSAXLocator *iface )
110 return (saxlocator *)((char*)iface - FIELD_OFFSET(saxlocator, lpVBSAXLocatorVtbl));
113 static inline saxlocator *impl_from_ISAXLocator( ISAXLocator *iface )
115 return (saxlocator *)((char*)iface - FIELD_OFFSET(saxlocator, lpSAXLocatorVtbl));
118 static inline saxattributes *impl_from_IVBSAXAttributes( IVBSAXAttributes *iface )
120 return (saxattributes *)((char*)iface - FIELD_OFFSET(saxattributes, lpVBSAXAttributesVtbl));
123 static inline saxattributes *impl_from_ISAXAttributes( ISAXAttributes *iface )
125 return (saxattributes *)((char*)iface - FIELD_OFFSET(saxattributes, lpSAXAttributesVtbl));
128 static inline BOOL has_content_handler(const saxlocator *locator)
130 return (locator->vbInterface && locator->saxreader->vbcontentHandler) ||
131 (!locator->vbInterface && locator->saxreader->contentHandler);
134 static inline BOOL has_error_handler(const saxlocator *locator)
136 return (locator->vbInterface && locator->saxreader->vberrorHandler) ||
137 (!locator->vbInterface && locator->saxreader->errorHandler);
140 static HRESULT namespacePush(saxlocator *locator, int ns)
142 if(locator->nsStackLast>=locator->nsStackSize)
146 new_stack = HeapReAlloc(GetProcessHeap(), 0,
147 locator->nsStack, sizeof(int)*locator->nsStackSize*2);
148 if(!new_stack) return E_OUTOFMEMORY;
149 locator->nsStack = new_stack;
150 locator->nsStackSize *= 2;
152 locator->nsStack[locator->nsStackLast++] = ns;
157 static int namespacePop(saxlocator *locator)
159 if(locator->nsStackLast == 0) return 0;
160 return locator->nsStack[--locator->nsStackLast];
163 static BSTR bstr_from_xmlCharN(const xmlChar *buf, int len)
171 dLen = MultiByteToWideChar(CP_UTF8, 0, (LPCSTR)buf, len, NULL, 0);
172 if(len != -1) dLen++;
173 bstr = SysAllocStringLen(NULL, dLen-1);
176 MultiByteToWideChar(CP_UTF8, 0, (LPCSTR)buf, len, bstr, dLen);
177 if(len != -1) bstr[dLen-1] = '\0';
182 static BSTR QName_from_xmlChar(const xmlChar *prefix, const xmlChar *name)
187 if(!name) return NULL;
189 if(!prefix || !*prefix)
190 return bstr_from_xmlChar(name);
192 qname = xmlBuildQName(name, prefix, NULL, 0);
193 bstr = bstr_from_xmlChar(qname);
199 static void format_error_message_from_id(saxlocator *This, HRESULT hr)
201 xmlStopParser(This->pParserCtxt);
204 if(has_error_handler(This))
207 if(!FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM,
208 NULL, hr, 0, msg, sizeof(msg), NULL))
210 FIXME("MSXML errors not yet supported.\n");
214 if(This->vbInterface)
216 BSTR bstrMsg = SysAllocString(msg);
217 IVBSAXErrorHandler_fatalError(This->saxreader->vberrorHandler,
218 (IVBSAXLocator*)&This->lpVBSAXLocatorVtbl, &bstrMsg, hr);
219 SysFreeString(bstrMsg);
222 ISAXErrorHandler_fatalError(This->saxreader->errorHandler,
223 (ISAXLocator*)&This->lpSAXLocatorVtbl, msg, hr);
227 static void update_position(saxlocator *This, xmlChar *end)
229 if(This->lastCur == NULL)
231 This->lastCur = (xmlChar*)This->pParserCtxt->input->base;
233 This->realColumn = 1;
235 else if(This->lastCur < This->pParserCtxt->input->base)
237 This->lastCur = (xmlChar*)This->pParserCtxt->input->base;
239 This->realColumn = 1;
242 if(This->pParserCtxt->input->cur<This->lastCur)
244 This->lastCur = (xmlChar*)This->pParserCtxt->input->base;
246 This->realColumn = 1;
249 if(!end) end = (xmlChar*)This->pParserCtxt->input->cur;
251 while(This->lastCur < end)
253 if(*(This->lastCur) == '\n')
256 This->realColumn = 1;
258 else if(*(This->lastCur) == '\r' &&
259 (This->lastCur==This->pParserCtxt->input->end ||
260 *(This->lastCur+1)!='\n'))
263 This->realColumn = 1;
265 else This->realColumn++;
269 /* Count multibyte UTF8 encoded characters once */
270 while((*(This->lastCur)&0xC0) == 0x80) This->lastCur++;
273 This->line = This->realLine;
274 This->column = This->realColumn;
277 /*** IVBSAXAttributes interface ***/
278 /*** IUnknown methods ***/
279 static HRESULT WINAPI ivbsaxattributes_QueryInterface(
280 IVBSAXAttributes* iface,
284 saxattributes *This = impl_from_IVBSAXAttributes(iface);
286 TRACE("%p %s %p\n", This, debugstr_guid(riid), ppvObject);
290 if (IsEqualGUID(riid, &IID_IUnknown) ||
291 IsEqualGUID(riid, &IID_IDispatch) ||
292 IsEqualGUID(riid, &IID_IVBSAXAttributes))
298 FIXME("interface %s not implemented\n", debugstr_guid(riid));
299 return E_NOINTERFACE;
302 IVBSAXAttributes_AddRef(iface);
307 static ULONG WINAPI ivbsaxattributes_AddRef(IVBSAXAttributes* iface)
309 saxattributes *This = impl_from_IVBSAXAttributes(iface);
310 return ISAXAttributes_AddRef((ISAXAttributes*)&This->lpSAXAttributesVtbl);
313 static ULONG WINAPI ivbsaxattributes_Release(IVBSAXAttributes* iface)
315 saxattributes *This = impl_from_IVBSAXAttributes(iface);
316 return ISAXAttributes_Release((ISAXAttributes*)&This->lpSAXAttributesVtbl);
319 /*** IDispatch methods ***/
320 static HRESULT WINAPI ivbsaxattributes_GetTypeInfoCount( IVBSAXAttributes *iface, UINT* pctinfo )
322 saxattributes *This = impl_from_IVBSAXAttributes( iface );
324 TRACE("(%p)->(%p)\n", This, pctinfo);
331 static HRESULT WINAPI ivbsaxattributes_GetTypeInfo(
332 IVBSAXAttributes *iface,
333 UINT iTInfo, LCID lcid, ITypeInfo** ppTInfo )
335 saxattributes *This = impl_from_IVBSAXAttributes( iface );
338 TRACE("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo);
340 hr = get_typeinfo(IVBSAXAttributes_tid, ppTInfo);
345 static HRESULT WINAPI ivbsaxattributes_GetIDsOfNames(
346 IVBSAXAttributes *iface,
353 saxattributes *This = impl_from_IVBSAXAttributes( iface );
357 TRACE("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames, cNames,
360 if(!rgszNames || cNames == 0 || !rgDispId)
363 hr = get_typeinfo(IVBSAXAttributes_tid, &typeinfo);
366 hr = ITypeInfo_GetIDsOfNames(typeinfo, rgszNames, cNames, rgDispId);
367 ITypeInfo_Release(typeinfo);
373 static HRESULT WINAPI ivbsaxattributes_Invoke(
374 IVBSAXAttributes *iface,
379 DISPPARAMS* pDispParams,
381 EXCEPINFO* pExcepInfo,
384 saxattributes *This = impl_from_IVBSAXAttributes( iface );
388 TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
389 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
391 hr = get_typeinfo(IVBSAXAttributes_tid, &typeinfo);
394 hr = ITypeInfo_Invoke(typeinfo, &(This->lpVBSAXAttributesVtbl), dispIdMember, wFlags, pDispParams,
395 pVarResult, pExcepInfo, puArgErr);
396 ITypeInfo_Release(typeinfo);
402 /*** IVBSAXAttributes methods ***/
403 static HRESULT WINAPI ivbsaxattributes_get_length(
404 IVBSAXAttributes* iface,
407 saxattributes *This = impl_from_IVBSAXAttributes( iface );
408 return ISAXAttributes_getLength(
409 (ISAXAttributes*)&This->lpSAXAttributesVtbl,
413 static HRESULT WINAPI ivbsaxattributes_getURI(
414 IVBSAXAttributes* iface,
419 saxattributes *This = impl_from_IVBSAXAttributes( iface );
420 return ISAXAttributes_getURI(
421 (ISAXAttributes*)&This->lpSAXAttributesVtbl,
422 nIndex, (const WCHAR**)uri, &len);
425 static HRESULT WINAPI ivbsaxattributes_getLocalName(
426 IVBSAXAttributes* iface,
431 saxattributes *This = impl_from_IVBSAXAttributes( iface );
432 return ISAXAttributes_getLocalName(
433 (ISAXAttributes*)&This->lpSAXAttributesVtbl,
434 nIndex, (const WCHAR**)localName, &len);
437 static HRESULT WINAPI ivbsaxattributes_getQName(
438 IVBSAXAttributes* iface,
443 saxattributes *This = impl_from_IVBSAXAttributes( iface );
444 return ISAXAttributes_getQName(
445 (ISAXAttributes*)&This->lpSAXAttributesVtbl,
446 nIndex, (const WCHAR**)QName, &len);
449 static HRESULT WINAPI ivbsaxattributes_getIndexFromName(
450 IVBSAXAttributes* iface,
455 saxattributes *This = impl_from_IVBSAXAttributes( iface );
456 return ISAXAttributes_getIndexFromName(
457 (ISAXAttributes*)&This->lpSAXAttributesVtbl, uri, SysStringLen(uri),
458 localName, SysStringLen(localName), index);
461 static HRESULT WINAPI ivbsaxattributes_getIndexFromQName(
462 IVBSAXAttributes* iface,
466 saxattributes *This = impl_from_IVBSAXAttributes( iface );
467 return ISAXAttributes_getIndexFromQName(
468 (ISAXAttributes*)&This->lpSAXAttributesVtbl, QName,
469 SysStringLen(QName), index);
472 static HRESULT WINAPI ivbsaxattributes_getType(
473 IVBSAXAttributes* iface,
478 saxattributes *This = impl_from_IVBSAXAttributes( iface );
479 return ISAXAttributes_getType(
480 (ISAXAttributes*)&This->lpSAXAttributesVtbl,
481 nIndex, (const WCHAR**)type, &len);
484 static HRESULT WINAPI ivbsaxattributes_getTypeFromName(
485 IVBSAXAttributes* iface,
491 saxattributes *This = impl_from_IVBSAXAttributes( iface );
492 return ISAXAttributes_getTypeFromName(
493 (ISAXAttributes*)&This->lpSAXAttributesVtbl, uri, SysStringLen(uri),
494 localName, SysStringLen(localName), (const WCHAR**)type, &len);
497 static HRESULT WINAPI ivbsaxattributes_getTypeFromQName(
498 IVBSAXAttributes* iface,
503 saxattributes *This = impl_from_IVBSAXAttributes( iface );
504 return ISAXAttributes_getTypeFromQName(
505 (ISAXAttributes*)&This->lpSAXAttributesVtbl, QName,
506 SysStringLen(QName), (const WCHAR**)type, &len);
509 static HRESULT WINAPI ivbsaxattributes_getValue(
510 IVBSAXAttributes* iface,
515 saxattributes *This = impl_from_IVBSAXAttributes( iface );
516 return ISAXAttributes_getValue(
517 (ISAXAttributes*)&This->lpSAXAttributesVtbl,
518 nIndex, (const WCHAR**)value, &len);
521 static HRESULT WINAPI ivbsaxattributes_getValueFromName(
522 IVBSAXAttributes* iface,
528 saxattributes *This = impl_from_IVBSAXAttributes( iface );
529 return ISAXAttributes_getValueFromName(
530 (ISAXAttributes*)&This->lpSAXAttributesVtbl, uri, SysStringLen(uri),
531 localName, SysStringLen(localName), (const WCHAR**)value, &len);
534 static HRESULT WINAPI ivbsaxattributes_getValueFromQName(
535 IVBSAXAttributes* iface,
540 saxattributes *This = impl_from_IVBSAXAttributes( iface );
541 return ISAXAttributes_getValueFromQName(
542 (ISAXAttributes*)&This->lpSAXAttributesVtbl, QName,
543 SysStringLen(QName), (const WCHAR**)value, &len);
546 static const struct IVBSAXAttributesVtbl ivbsaxattributes_vtbl =
548 ivbsaxattributes_QueryInterface,
549 ivbsaxattributes_AddRef,
550 ivbsaxattributes_Release,
551 ivbsaxattributes_GetTypeInfoCount,
552 ivbsaxattributes_GetTypeInfo,
553 ivbsaxattributes_GetIDsOfNames,
554 ivbsaxattributes_Invoke,
555 ivbsaxattributes_get_length,
556 ivbsaxattributes_getURI,
557 ivbsaxattributes_getLocalName,
558 ivbsaxattributes_getQName,
559 ivbsaxattributes_getIndexFromName,
560 ivbsaxattributes_getIndexFromQName,
561 ivbsaxattributes_getType,
562 ivbsaxattributes_getTypeFromName,
563 ivbsaxattributes_getTypeFromQName,
564 ivbsaxattributes_getValue,
565 ivbsaxattributes_getValueFromName,
566 ivbsaxattributes_getValueFromQName
569 /*** ISAXAttributes interface ***/
570 /*** IUnknown methods ***/
571 static HRESULT WINAPI isaxattributes_QueryInterface(
572 ISAXAttributes* iface,
576 saxattributes *This = impl_from_ISAXAttributes(iface);
578 TRACE("%p %s %p\n", This, debugstr_guid(riid), ppvObject);
582 if (IsEqualGUID(riid, &IID_IUnknown) ||
583 IsEqualGUID(riid, &IID_ISAXAttributes))
589 FIXME("interface %s not implemented\n", debugstr_guid(riid));
590 return E_NOINTERFACE;
593 ISAXAttributes_AddRef(iface);
598 static ULONG WINAPI isaxattributes_AddRef(ISAXAttributes* iface)
600 saxattributes *This = impl_from_ISAXAttributes(iface);
602 return InterlockedIncrement(&This->ref);
605 static ULONG WINAPI isaxattributes_Release(ISAXAttributes* iface)
607 saxattributes *This = impl_from_ISAXAttributes(iface);
612 ref = InterlockedDecrement(&This->ref);
616 for(index=0; index<This->nb_attributes; index++)
618 SysFreeString(This->szLocalname[index]);
619 SysFreeString(This->szURI[index]);
620 SysFreeString(This->szValue[index]);
621 SysFreeString(This->szQName[index]);
624 heap_free(This->szLocalname);
625 heap_free(This->szURI);
626 heap_free(This->szValue);
627 heap_free(This->szQName);
635 /*** ISAXAttributes methods ***/
636 static HRESULT WINAPI isaxattributes_getLength(
637 ISAXAttributes* iface,
640 saxattributes *This = impl_from_ISAXAttributes( iface );
642 *length = This->nb_attributes;
643 TRACE("Length set to %d\n", *length);
647 static HRESULT WINAPI isaxattributes_getURI(
648 ISAXAttributes* iface,
653 saxattributes *This = impl_from_ISAXAttributes( iface );
654 TRACE("(%p)->(%d)\n", This, nIndex);
656 if(nIndex>=This->nb_attributes || nIndex<0) return E_INVALIDARG;
657 if(!pUrl || !pUriSize) return E_POINTER;
659 *pUriSize = SysStringLen(This->szURI[nIndex]);
660 *pUrl = This->szURI[nIndex];
665 static HRESULT WINAPI isaxattributes_getLocalName(
666 ISAXAttributes* iface,
668 const WCHAR **pLocalName,
669 int *pLocalNameLength)
671 saxattributes *This = impl_from_ISAXAttributes( iface );
672 TRACE("(%p)->(%d)\n", This, nIndex);
674 if(nIndex>=This->nb_attributes || nIndex<0) return E_INVALIDARG;
675 if(!pLocalName || !pLocalNameLength) return E_POINTER;
677 *pLocalNameLength = SysStringLen(This->szLocalname[nIndex]);
678 *pLocalName = This->szLocalname[nIndex];
683 static HRESULT WINAPI isaxattributes_getQName(
684 ISAXAttributes* iface,
686 const WCHAR **pQName,
689 saxattributes *This = impl_from_ISAXAttributes( iface );
690 TRACE("(%p)->(%d)\n", This, nIndex);
692 if(nIndex>=This->nb_attributes || nIndex<0) return E_INVALIDARG;
693 if(!pQName || !pQNameLength) return E_POINTER;
695 *pQNameLength = SysStringLen(This->szQName[nIndex]);
696 *pQName = This->szQName[nIndex];
701 static HRESULT WINAPI isaxattributes_getName(
702 ISAXAttributes* iface,
706 const WCHAR **pLocalName,
708 const WCHAR **pQName,
711 saxattributes *This = impl_from_ISAXAttributes( iface );
712 TRACE("(%p)->(%d)\n", This, nIndex);
714 if(nIndex>=This->nb_attributes || nIndex<0) return E_INVALIDARG;
715 if(!pUri || !pUriLength || !pLocalName || !pLocalNameSize
716 || !pQName || !pQNameLength) return E_POINTER;
718 *pUriLength = SysStringLen(This->szURI[nIndex]);
719 *pUri = This->szURI[nIndex];
720 *pLocalNameSize = SysStringLen(This->szLocalname[nIndex]);
721 *pLocalName = This->szLocalname[nIndex];
722 *pQNameLength = SysStringLen(This->szQName[nIndex]);
723 *pQName = This->szQName[nIndex];
728 static HRESULT WINAPI isaxattributes_getIndexFromName(
729 ISAXAttributes* iface,
732 const WCHAR *pLocalName,
736 saxattributes *This = impl_from_ISAXAttributes( iface );
738 TRACE("(%p)->(%s, %d, %s, %d)\n", This, debugstr_w(pUri), cUriLength,
739 debugstr_w(pLocalName), cocalNameLength);
741 if(!pUri || !pLocalName || !index) return E_POINTER;
743 for(i=0; i<This->nb_attributes; i++)
745 if(cUriLength!=SysStringLen(This->szURI[i])
746 || cocalNameLength!=SysStringLen(This->szLocalname[i]))
748 if(cUriLength && memcmp(pUri, This->szURI[i],
749 sizeof(WCHAR)*cUriLength))
751 if(cocalNameLength && memcmp(pLocalName, This->szLocalname[i],
752 sizeof(WCHAR)*cocalNameLength))
762 static HRESULT WINAPI isaxattributes_getIndexFromQName(
763 ISAXAttributes* iface,
768 saxattributes *This = impl_from_ISAXAttributes( iface );
770 TRACE("(%p)->(%s, %d)\n", This, debugstr_w(pQName), nQNameLength);
772 if(!pQName || !index) return E_POINTER;
773 if(!nQNameLength) return E_INVALIDARG;
775 for(i=0; i<This->nb_attributes; i++)
777 if(nQNameLength!=SysStringLen(This->szQName[i])) continue;
778 if(memcmp(pQName, This->szQName, sizeof(WCHAR)*nQNameLength)) continue;
787 static HRESULT WINAPI isaxattributes_getType(
788 ISAXAttributes* iface,
793 saxattributes *This = impl_from_ISAXAttributes( iface );
795 FIXME("(%p)->(%d) stub\n", This, nIndex);
799 static HRESULT WINAPI isaxattributes_getTypeFromName(
800 ISAXAttributes* iface,
803 const WCHAR *pLocalName,
808 saxattributes *This = impl_from_ISAXAttributes( iface );
810 FIXME("(%p)->(%s, %d, %s, %d) stub\n", This, debugstr_w(pUri), nUri,
811 debugstr_w(pLocalName), nLocalName);
815 static HRESULT WINAPI isaxattributes_getTypeFromQName(
816 ISAXAttributes* iface,
822 saxattributes *This = impl_from_ISAXAttributes( iface );
824 FIXME("(%p)->(%s, %d) stub\n", This, debugstr_w(pQName), nQName);
828 static HRESULT WINAPI isaxattributes_getValue(
829 ISAXAttributes* iface,
831 const WCHAR **pValue,
834 saxattributes *This = impl_from_ISAXAttributes( iface );
835 TRACE("(%p)->(%d)\n", This, nIndex);
837 if(nIndex>=This->nb_attributes || nIndex<0) return E_INVALIDARG;
838 if(!pValue || !nValue) return E_POINTER;
840 *nValue = SysStringLen(This->szValue[nIndex]);
841 *pValue = This->szValue[nIndex];
846 static HRESULT WINAPI isaxattributes_getValueFromName(
847 ISAXAttributes* iface,
850 const WCHAR *pLocalName,
852 const WCHAR **pValue,
857 saxattributes *This = impl_from_ISAXAttributes( iface );
858 TRACE("(%p)->(%s, %d, %s, %d)\n", This, debugstr_w(pUri), nUri,
859 debugstr_w(pLocalName), nLocalName);
861 hr = ISAXAttributes_getIndexFromName(iface,
862 pUri, nUri, pLocalName, nLocalName, &index);
863 if(hr==S_OK) hr = ISAXAttributes_getValue(iface, index, pValue, nValue);
868 static HRESULT WINAPI isaxattributes_getValueFromQName(
869 ISAXAttributes* iface,
872 const WCHAR **pValue,
877 saxattributes *This = impl_from_ISAXAttributes( iface );
878 TRACE("(%p)->(%s, %d)\n", This, debugstr_w(pQName), nQName);
880 hr = ISAXAttributes_getIndexFromQName(iface, pQName, nQName, &index);
881 if(hr==S_OK) hr = ISAXAttributes_getValue(iface, index, pValue, nValue);
886 static const struct ISAXAttributesVtbl isaxattributes_vtbl =
888 isaxattributes_QueryInterface,
889 isaxattributes_AddRef,
890 isaxattributes_Release,
891 isaxattributes_getLength,
892 isaxattributes_getURI,
893 isaxattributes_getLocalName,
894 isaxattributes_getQName,
895 isaxattributes_getName,
896 isaxattributes_getIndexFromName,
897 isaxattributes_getIndexFromQName,
898 isaxattributes_getType,
899 isaxattributes_getTypeFromName,
900 isaxattributes_getTypeFromQName,
901 isaxattributes_getValue,
902 isaxattributes_getValueFromName,
903 isaxattributes_getValueFromQName
906 static HRESULT SAXAttributes_create(saxattributes **attr,
907 int nb_namespaces, const xmlChar **xmlNamespaces,
908 int nb_attributes, const xmlChar **xmlAttributes)
910 saxattributes *attributes;
912 static const xmlChar xmlns[] = "xmlns";
914 attributes = heap_alloc(sizeof(*attributes));
916 return E_OUTOFMEMORY;
918 attributes->lpVBSAXAttributesVtbl = &ivbsaxattributes_vtbl;
919 attributes->lpSAXAttributesVtbl = &isaxattributes_vtbl;
922 attributes->nb_attributes = nb_namespaces+nb_attributes;
924 attributes->szLocalname = heap_alloc(sizeof(BSTR)*attributes->nb_attributes);
925 attributes->szURI = heap_alloc(sizeof(BSTR)*attributes->nb_attributes);
926 attributes->szValue = heap_alloc(sizeof(BSTR)*attributes->nb_attributes);
927 attributes->szQName = heap_alloc(sizeof(BSTR)*attributes->nb_attributes);
929 if(!attributes->szLocalname || !attributes->szURI
930 || !attributes->szValue || !attributes->szQName)
932 heap_free(attributes->szLocalname);
933 heap_free(attributes->szURI);
934 heap_free(attributes->szValue);
935 heap_free(attributes->szQName);
936 heap_free(attributes);
940 for(index=0; index<nb_namespaces; index++)
942 attributes->szLocalname[index] = SysAllocStringLen(NULL, 0);
943 attributes->szURI[index] = SysAllocStringLen(NULL, 0);
944 attributes->szValue[index] = bstr_from_xmlChar(xmlNamespaces[2*index+1]);
945 attributes->szQName[index] = QName_from_xmlChar(xmlns, xmlNamespaces[2*index]);
948 for(index=0; index<nb_attributes; index++)
950 attributes->szLocalname[nb_namespaces+index] =
951 bstr_from_xmlChar(xmlAttributes[index*5]);
952 attributes->szURI[nb_namespaces+index] =
953 bstr_from_xmlChar(xmlAttributes[index*5+2]);
954 attributes->szValue[nb_namespaces+index] =
955 bstr_from_xmlCharN(xmlAttributes[index*5+3],
956 xmlAttributes[index*5+4]-xmlAttributes[index*5+3]);
957 attributes->szQName[nb_namespaces+index] =
958 QName_from_xmlChar(xmlAttributes[index*5+1], xmlAttributes[index*5]);
963 TRACE("returning %p\n", *attr);
968 /*** LibXML callbacks ***/
969 static void libxmlStartDocument(void *ctx)
971 saxlocator *This = ctx;
974 if(has_content_handler(This))
976 if(This->vbInterface)
977 hr = IVBSAXContentHandler_startDocument(This->saxreader->vbcontentHandler);
979 hr = ISAXContentHandler_startDocument(This->saxreader->contentHandler);
982 format_error_message_from_id(This, hr);
985 update_position(This, NULL);
988 static void libxmlEndDocument(void *ctx)
990 saxlocator *This = ctx;
996 if(This->ret != S_OK) return;
998 if(has_content_handler(This))
1000 if(This->vbInterface)
1001 hr = IVBSAXContentHandler_endDocument(This->saxreader->vbcontentHandler);
1003 hr = ISAXContentHandler_endDocument(This->saxreader->contentHandler);
1006 format_error_message_from_id(This, hr);
1010 static void libxmlStartElementNS(
1012 const xmlChar *localname,
1013 const xmlChar *prefix,
1016 const xmlChar **namespaces,
1019 const xmlChar **attributes)
1021 BSTR NamespaceUri, LocalName, QName, Prefix, Uri;
1022 saxlocator *This = ctx;
1024 saxattributes *attr;
1027 if(*(This->pParserCtxt->input->cur) == '/')
1028 update_position(This, (xmlChar*)This->pParserCtxt->input->cur+2);
1030 update_position(This, (xmlChar*)This->pParserCtxt->input->cur+1);
1032 hr = namespacePush(This, nb_namespaces);
1033 if(hr==S_OK && has_content_handler(This))
1035 for(index=0; index<nb_namespaces; index++)
1037 Prefix = bstr_from_xmlChar(namespaces[2*index]);
1038 Uri = bstr_from_xmlChar(namespaces[2*index+1]);
1040 if(This->vbInterface)
1041 hr = IVBSAXContentHandler_startPrefixMapping(
1042 This->saxreader->vbcontentHandler,
1045 hr = ISAXContentHandler_startPrefixMapping(
1046 This->saxreader->contentHandler,
1047 Prefix, SysStringLen(Prefix),
1048 Uri, SysStringLen(Uri));
1050 SysFreeString(Prefix);
1055 format_error_message_from_id(This, hr);
1060 NamespaceUri = bstr_from_xmlChar(URI);
1061 LocalName = bstr_from_xmlChar(localname);
1062 QName = QName_from_xmlChar(prefix, localname);
1064 hr = SAXAttributes_create(&attr, nb_namespaces, namespaces, nb_attributes, attributes);
1067 if(This->vbInterface)
1068 hr = IVBSAXContentHandler_startElement(
1069 This->saxreader->vbcontentHandler,
1070 &NamespaceUri, &LocalName, &QName,
1071 (IVBSAXAttributes*)&attr->lpVBSAXAttributesVtbl);
1073 hr = ISAXContentHandler_startElement(
1074 This->saxreader->contentHandler,
1075 NamespaceUri, SysStringLen(NamespaceUri),
1076 LocalName, SysStringLen(LocalName),
1077 QName, SysStringLen(QName),
1078 (ISAXAttributes*)&attr->lpSAXAttributesVtbl);
1080 ISAXAttributes_Release((ISAXAttributes*)&attr->lpSAXAttributesVtbl);
1083 SysFreeString(NamespaceUri);
1084 SysFreeString(LocalName);
1085 SysFreeString(QName);
1089 format_error_message_from_id(This, hr);
1092 static void libxmlEndElementNS(
1094 const xmlChar *localname,
1095 const xmlChar *prefix,
1098 BSTR NamespaceUri, LocalName, QName, Prefix;
1099 saxlocator *This = ctx;
1104 end = (xmlChar*)This->pParserCtxt->input->cur;
1105 if(*(end-1) != '>' || *(end-2) != '/')
1106 while(end-2>=This->pParserCtxt->input->base
1107 && *(end-2)!='<' && *(end-1)!='/') end--;
1109 update_position(This, end);
1111 nsNr = namespacePop(This);
1113 if(has_content_handler(This))
1115 NamespaceUri = bstr_from_xmlChar(URI);
1116 LocalName = bstr_from_xmlChar(localname);
1117 QName = QName_from_xmlChar(prefix, localname);
1119 if(This->vbInterface)
1120 hr = IVBSAXContentHandler_endElement(
1121 This->saxreader->vbcontentHandler,
1122 &NamespaceUri, &LocalName, &QName);
1124 hr = ISAXContentHandler_endElement(
1125 This->saxreader->contentHandler,
1126 NamespaceUri, SysStringLen(NamespaceUri),
1127 LocalName, SysStringLen(LocalName),
1128 QName, SysStringLen(QName));
1130 SysFreeString(NamespaceUri);
1131 SysFreeString(LocalName);
1132 SysFreeString(QName);
1136 format_error_message_from_id(This, hr);
1140 for(index=This->pParserCtxt->nsNr-2;
1141 index>=This->pParserCtxt->nsNr-nsNr*2; index-=2)
1143 Prefix = bstr_from_xmlChar(This->pParserCtxt->nsTab[index]);
1145 if(This->vbInterface)
1146 hr = IVBSAXContentHandler_endPrefixMapping(
1147 This->saxreader->vbcontentHandler, &Prefix);
1149 hr = ISAXContentHandler_endPrefixMapping(
1150 This->saxreader->contentHandler,
1151 Prefix, SysStringLen(Prefix));
1153 SysFreeString(Prefix);
1157 format_error_message_from_id(This, hr);
1164 update_position(This, NULL);
1167 static void libxmlCharacters(
1172 saxlocator *This = ctx;
1177 BOOL lastEvent = FALSE;
1179 if(!(has_content_handler(This))) return;
1182 if(*(ch-1)=='\r') cur--;
1185 if(ch<This->pParserCtxt->input->base || ch>This->pParserCtxt->input->end)
1190 while(end-ch<len && *end!='\r') end++;
1197 if(!lastEvent) *end = '\n';
1199 Chars = bstr_from_xmlCharN(cur, end-cur+1);
1200 if(This->vbInterface)
1201 hr = IVBSAXContentHandler_characters(
1202 This->saxreader->vbcontentHandler, &Chars);
1204 hr = ISAXContentHandler_characters(
1205 This->saxreader->contentHandler,
1206 Chars, SysStringLen(Chars));
1207 SysFreeString(Chars);
1211 format_error_message_from_id(This, hr);
1215 This->column += end-cur+1;
1229 if(end-ch == len) break;
1232 if(ch<This->pParserCtxt->input->base || ch>This->pParserCtxt->input->end)
1233 This->column = This->realColumn
1234 +This->pParserCtxt->input->cur-This->lastCur;
1237 static void libxmlSetDocumentLocator(
1239 xmlSAXLocatorPtr loc)
1241 saxlocator *This = ctx;
1244 if(has_content_handler(This))
1246 if(This->vbInterface)
1247 hr = IVBSAXContentHandler_putref_documentLocator(
1248 This->saxreader->vbcontentHandler,
1249 (IVBSAXLocator*)&This->lpVBSAXLocatorVtbl);
1251 hr = ISAXContentHandler_putDocumentLocator(
1252 This->saxreader->contentHandler,
1253 (ISAXLocator*)&This->lpSAXLocatorVtbl);
1257 format_error_message_from_id(This, hr);
1260 static void libxmlComment(void *ctx, const xmlChar *value)
1262 saxlocator *This = ctx;
1265 xmlChar *beg = (xmlChar*)This->pParserCtxt->input->cur;
1267 while(beg-4>=This->pParserCtxt->input->base
1268 && memcmp(beg-4, "<!--", sizeof(char[4]))) beg--;
1269 update_position(This, beg);
1271 if(!This->vbInterface && !This->saxreader->lexicalHandler) return;
1272 if(This->vbInterface && !This->saxreader->vblexicalHandler) return;
1274 bValue = bstr_from_xmlChar(value);
1276 if(This->vbInterface)
1277 hr = IVBSAXLexicalHandler_comment(
1278 This->saxreader->vblexicalHandler, &bValue);
1280 hr = ISAXLexicalHandler_comment(
1281 This->saxreader->lexicalHandler,
1282 bValue, SysStringLen(bValue));
1284 SysFreeString(bValue);
1287 format_error_message_from_id(This, hr);
1289 update_position(This, NULL);
1292 static void libxmlFatalError(void *ctx, const char *msg, ...)
1294 saxlocator *This = ctx;
1300 va_start(args, msg);
1301 vsprintf(message, msg, args);
1304 len = MultiByteToWideChar(CP_UNIXCP, 0, message, -1, NULL, 0);
1305 error = heap_alloc(sizeof(WCHAR)*len);
1308 MultiByteToWideChar(CP_UNIXCP, 0, message, -1, error, len);
1309 TRACE("fatal error for %p: %s\n", This, debugstr_w(error));
1312 if(!has_error_handler(This))
1314 xmlStopParser(This->pParserCtxt);
1320 FIXME("Error handling is not compatible.\n");
1322 if(This->vbInterface)
1324 BSTR bstrError = SysAllocString(error);
1325 IVBSAXErrorHandler_fatalError(This->saxreader->vberrorHandler,
1326 (IVBSAXLocator*)&This->lpVBSAXLocatorVtbl, &bstrError, E_FAIL);
1327 SysFreeString(bstrError);
1330 ISAXErrorHandler_fatalError(This->saxreader->errorHandler,
1331 (ISAXLocator*)&This->lpSAXLocatorVtbl, error, E_FAIL);
1335 xmlStopParser(This->pParserCtxt);
1339 static void libxmlCDataBlock(void *ctx, const xmlChar *value, int len)
1341 saxlocator *This = ctx;
1343 xmlChar *beg = (xmlChar*)This->pParserCtxt->input->cur-len;
1347 BOOL lastEvent = FALSE, change;
1349 while(beg-9>=This->pParserCtxt->input->base
1350 && memcmp(beg-9, "<![CDATA[", sizeof(char[9]))) beg--;
1351 update_position(This, beg);
1353 if(This->vbInterface && This->saxreader->vblexicalHandler)
1354 hr = IVBSAXLexicalHandler_startCDATA(This->saxreader->vblexicalHandler);
1355 if(!This->vbInterface && This->saxreader->lexicalHandler)
1356 hr = ISAXLexicalHandler_startCDATA(This->saxreader->lexicalHandler);
1360 format_error_message_from_id(This, hr);
1364 realLen = This->pParserCtxt->input->cur-beg-3;
1370 while(end-beg<realLen && *end!='\r') end++;
1371 if(end-beg==realLen)
1376 else if(end-beg==realLen-1 && *end=='\r' && *(end+1)=='\n')
1379 if(*end == '\r') change = TRUE;
1380 else change = FALSE;
1382 if(change) *end = '\n';
1384 if(has_content_handler(This))
1386 Chars = bstr_from_xmlCharN(cur, end-cur+1);
1387 if(This->vbInterface)
1388 hr = IVBSAXContentHandler_characters(
1389 This->saxreader->vbcontentHandler, &Chars);
1391 hr = ISAXContentHandler_characters(
1392 This->saxreader->contentHandler,
1393 Chars, SysStringLen(Chars));
1394 SysFreeString(Chars);
1397 if(change) *end = '\r';
1402 This->column += end-cur+2;
1407 if(This->vbInterface && This->saxreader->vblexicalHandler)
1408 hr = IVBSAXLexicalHandler_endCDATA(This->saxreader->vblexicalHandler);
1409 if(!This->vbInterface && This->saxreader->lexicalHandler)
1410 hr = ISAXLexicalHandler_endCDATA(This->saxreader->lexicalHandler);
1413 format_error_message_from_id(This, hr);
1415 This->column += 4+end-cur;
1418 /*** IVBSAXLocator interface ***/
1419 /*** IUnknown methods ***/
1420 static HRESULT WINAPI ivbsaxlocator_QueryInterface(IVBSAXLocator* iface, REFIID riid, void **ppvObject)
1422 saxlocator *This = impl_from_IVBSAXLocator( iface );
1424 TRACE("%p %s %p\n", This, debugstr_guid( riid ), ppvObject);
1428 if ( IsEqualGUID( riid, &IID_IUnknown ) ||
1429 IsEqualGUID( riid, &IID_IDispatch) ||
1430 IsEqualGUID( riid, &IID_IVBSAXLocator ))
1436 FIXME("interface %s not implemented\n", debugstr_guid(riid));
1437 return E_NOINTERFACE;
1440 IVBSAXLocator_AddRef( iface );
1445 static ULONG WINAPI ivbsaxlocator_AddRef(IVBSAXLocator* iface)
1447 saxlocator *This = impl_from_IVBSAXLocator( iface );
1448 TRACE("%p\n", This );
1449 return InterlockedIncrement( &This->ref );
1452 static ULONG WINAPI ivbsaxlocator_Release(
1453 IVBSAXLocator* iface)
1455 saxlocator *This = impl_from_IVBSAXLocator( iface );
1456 return ISAXLocator_Release((ISAXLocator*)&This->lpVBSAXLocatorVtbl);
1459 /*** IDispatch methods ***/
1460 static HRESULT WINAPI ivbsaxlocator_GetTypeInfoCount( IVBSAXLocator *iface, UINT* pctinfo )
1462 saxlocator *This = impl_from_IVBSAXLocator( iface );
1464 TRACE("(%p)->(%p)\n", This, pctinfo);
1471 static HRESULT WINAPI ivbsaxlocator_GetTypeInfo(
1472 IVBSAXLocator *iface,
1473 UINT iTInfo, LCID lcid, ITypeInfo** ppTInfo )
1475 saxlocator *This = impl_from_IVBSAXLocator( iface );
1478 TRACE("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo);
1480 hr = get_typeinfo(IVBSAXLocator_tid, ppTInfo);
1485 static HRESULT WINAPI ivbsaxlocator_GetIDsOfNames(
1486 IVBSAXLocator *iface,
1488 LPOLESTR* rgszNames,
1493 saxlocator *This = impl_from_IVBSAXLocator( iface );
1494 ITypeInfo *typeinfo;
1497 TRACE("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames, cNames,
1500 if(!rgszNames || cNames == 0 || !rgDispId)
1501 return E_INVALIDARG;
1503 hr = get_typeinfo(IVBSAXLocator_tid, &typeinfo);
1506 hr = ITypeInfo_GetIDsOfNames(typeinfo, rgszNames, cNames, rgDispId);
1507 ITypeInfo_Release(typeinfo);
1513 static HRESULT WINAPI ivbsaxlocator_Invoke(
1514 IVBSAXLocator *iface,
1515 DISPID dispIdMember,
1519 DISPPARAMS* pDispParams,
1520 VARIANT* pVarResult,
1521 EXCEPINFO* pExcepInfo,
1524 saxlocator *This = impl_from_IVBSAXLocator( iface );
1525 ITypeInfo *typeinfo;
1528 TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
1529 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
1531 hr = get_typeinfo(IVBSAXLocator_tid, &typeinfo);
1534 hr = ITypeInfo_Invoke(typeinfo, &(This->lpVBSAXLocatorVtbl), dispIdMember, wFlags, pDispParams,
1535 pVarResult, pExcepInfo, puArgErr);
1536 ITypeInfo_Release(typeinfo);
1542 /*** IVBSAXLocator methods ***/
1543 static HRESULT WINAPI ivbsaxlocator_get_columnNumber(
1544 IVBSAXLocator* iface,
1547 saxlocator *This = impl_from_IVBSAXLocator( iface );
1548 return ISAXLocator_getColumnNumber(
1549 (ISAXLocator*)&This->lpVBSAXLocatorVtbl,
1553 static HRESULT WINAPI ivbsaxlocator_get_lineNumber(
1554 IVBSAXLocator* iface,
1557 saxlocator *This = impl_from_IVBSAXLocator( iface );
1558 return ISAXLocator_getLineNumber(
1559 (ISAXLocator*)&This->lpVBSAXLocatorVtbl,
1563 static HRESULT WINAPI ivbsaxlocator_get_publicId(
1564 IVBSAXLocator* iface,
1567 saxlocator *This = impl_from_IVBSAXLocator( iface );
1568 return ISAXLocator_getPublicId(
1569 (ISAXLocator*)&This->lpVBSAXLocatorVtbl,
1570 (const WCHAR**)publicId);
1573 static HRESULT WINAPI ivbsaxlocator_get_systemId(
1574 IVBSAXLocator* iface,
1577 saxlocator *This = impl_from_IVBSAXLocator( iface );
1578 return ISAXLocator_getSystemId(
1579 (ISAXLocator*)&This->lpVBSAXLocatorVtbl,
1580 (const WCHAR**)systemId);
1583 static const struct IVBSAXLocatorVtbl ivbsaxlocator_vtbl =
1585 ivbsaxlocator_QueryInterface,
1586 ivbsaxlocator_AddRef,
1587 ivbsaxlocator_Release,
1588 ivbsaxlocator_GetTypeInfoCount,
1589 ivbsaxlocator_GetTypeInfo,
1590 ivbsaxlocator_GetIDsOfNames,
1591 ivbsaxlocator_Invoke,
1592 ivbsaxlocator_get_columnNumber,
1593 ivbsaxlocator_get_lineNumber,
1594 ivbsaxlocator_get_publicId,
1595 ivbsaxlocator_get_systemId
1598 /*** ISAXLocator interface ***/
1599 /*** IUnknown methods ***/
1600 static HRESULT WINAPI isaxlocator_QueryInterface(ISAXLocator* iface, REFIID riid, void **ppvObject)
1602 saxlocator *This = impl_from_ISAXLocator( iface );
1604 TRACE("%p %s %p\n", This, debugstr_guid( riid ), ppvObject );
1608 if ( IsEqualGUID( riid, &IID_IUnknown ) ||
1609 IsEqualGUID( riid, &IID_ISAXLocator ))
1615 FIXME("interface %s not implemented\n", debugstr_guid(riid));
1616 return E_NOINTERFACE;
1619 ISAXLocator_AddRef( iface );
1624 static ULONG WINAPI isaxlocator_AddRef(ISAXLocator* iface)
1626 saxlocator *This = impl_from_ISAXLocator( iface );
1627 TRACE("%p\n", This );
1628 return InterlockedIncrement( &This->ref );
1631 static ULONG WINAPI isaxlocator_Release(
1634 saxlocator *This = impl_from_ISAXLocator( iface );
1637 TRACE("%p\n", This );
1639 ref = InterlockedDecrement( &This->ref );
1642 SysFreeString(This->publicId);
1643 SysFreeString(This->systemId);
1644 heap_free(This->nsStack);
1646 ISAXXMLReader_Release((ISAXXMLReader*)&This->saxreader->lpSAXXMLReaderVtbl);
1653 /*** ISAXLocator methods ***/
1654 static HRESULT WINAPI isaxlocator_getColumnNumber(
1658 saxlocator *This = impl_from_ISAXLocator( iface );
1660 *pnColumn = This->column;
1664 static HRESULT WINAPI isaxlocator_getLineNumber(
1668 saxlocator *This = impl_from_ISAXLocator( iface );
1670 *pnLine = This->line;
1674 static HRESULT WINAPI isaxlocator_getPublicId(
1676 const WCHAR ** ppwchPublicId)
1679 saxlocator *This = impl_from_ISAXLocator( iface );
1681 SysFreeString(This->publicId);
1683 publicId = bstr_from_xmlChar(xmlSAX2GetPublicId(This->pParserCtxt));
1684 if(SysStringLen(publicId))
1685 This->publicId = (WCHAR*)&publicId;
1688 SysFreeString(publicId);
1689 This->publicId = NULL;
1692 *ppwchPublicId = This->publicId;
1696 static HRESULT WINAPI isaxlocator_getSystemId(
1698 const WCHAR ** ppwchSystemId)
1701 saxlocator *This = impl_from_ISAXLocator( iface );
1703 SysFreeString(This->systemId);
1705 systemId = bstr_from_xmlChar(xmlSAX2GetSystemId(This->pParserCtxt));
1706 if(SysStringLen(systemId))
1707 This->systemId = (WCHAR*)&systemId;
1710 SysFreeString(systemId);
1711 This->systemId = NULL;
1714 *ppwchSystemId = This->systemId;
1718 static const struct ISAXLocatorVtbl isaxlocator_vtbl =
1720 isaxlocator_QueryInterface,
1722 isaxlocator_Release,
1723 isaxlocator_getColumnNumber,
1724 isaxlocator_getLineNumber,
1725 isaxlocator_getPublicId,
1726 isaxlocator_getSystemId
1729 static HRESULT SAXLocator_create(saxreader *reader, saxlocator **ppsaxlocator, BOOL vbInterface)
1731 saxlocator *locator;
1733 locator = heap_alloc( sizeof (*locator) );
1735 return E_OUTOFMEMORY;
1737 locator->lpVBSAXLocatorVtbl = &ivbsaxlocator_vtbl;
1738 locator->lpSAXLocatorVtbl = &isaxlocator_vtbl;
1740 locator->vbInterface = vbInterface;
1742 locator->saxreader = reader;
1743 ISAXXMLReader_AddRef((ISAXXMLReader*)&reader->lpSAXXMLReaderVtbl);
1745 locator->pParserCtxt = NULL;
1746 locator->publicId = NULL;
1747 locator->systemId = NULL;
1748 locator->lastCur = NULL;
1750 locator->column = 0;
1751 locator->ret = S_OK;
1752 locator->nsStackSize = 8;
1753 locator->nsStackLast = 0;
1754 locator->nsStack = heap_alloc(sizeof(int)*locator->nsStackSize);
1755 if(!locator->nsStack)
1757 ISAXXMLReader_Release((ISAXXMLReader*)&reader->lpSAXXMLReaderVtbl);
1759 return E_OUTOFMEMORY;
1762 *ppsaxlocator = locator;
1764 TRACE("returning %p\n", *ppsaxlocator);
1769 /*** SAXXMLReader internal functions ***/
1770 static HRESULT internal_parseBuffer(saxreader *This, const char *buffer, int size, BOOL vbInterface)
1772 xmlCharEncoding encoding = XML_CHAR_ENCODING_NONE;
1773 xmlChar *enc_name = NULL;
1774 saxlocator *locator;
1777 hr = SAXLocator_create(This, &locator, vbInterface);
1783 const unsigned char *buff = (unsigned char*)buffer;
1785 encoding = xmlDetectCharEncoding((xmlChar*)buffer, 4);
1786 enc_name = (xmlChar*)xmlGetCharEncodingName(encoding);
1787 TRACE("detected encoding: %s\n", enc_name);
1788 /* skip BOM, parser won't switch encodings and so won't skip it on its own */
1789 if ((encoding == XML_CHAR_ENCODING_UTF8) &&
1790 buff[0] == 0xEF && buff[1] == 0xBB && buff[2] == 0xBF)
1797 locator->pParserCtxt = xmlCreateMemoryParserCtxt(buffer, size);
1798 if(!locator->pParserCtxt)
1800 ISAXLocator_Release((ISAXLocator*)&locator->lpSAXLocatorVtbl);
1804 if (encoding == XML_CHAR_ENCODING_UTF8)
1805 locator->pParserCtxt->encoding = xmlStrdup(enc_name);
1807 xmlFree(locator->pParserCtxt->sax);
1808 locator->pParserCtxt->sax = &locator->saxreader->sax;
1809 locator->pParserCtxt->userData = locator;
1811 This->isParsing = TRUE;
1812 if(xmlParseDocument(locator->pParserCtxt) == -1) hr = E_FAIL;
1813 else hr = locator->ret;
1814 This->isParsing = FALSE;
1816 if(locator->pParserCtxt)
1818 locator->pParserCtxt->sax = NULL;
1819 xmlFreeParserCtxt(locator->pParserCtxt);
1820 locator->pParserCtxt = NULL;
1823 ISAXLocator_Release((ISAXLocator*)&locator->lpSAXLocatorVtbl);
1827 static HRESULT internal_parseStream(saxreader *This, IStream *stream, BOOL vbInterface)
1829 saxlocator *locator;
1834 hr = IStream_Read(stream, data, sizeof(data), &dataRead);
1838 hr = SAXLocator_create(This, &locator, vbInterface);
1842 locator->pParserCtxt = xmlCreatePushParserCtxt(
1843 &locator->saxreader->sax, locator,
1844 data, dataRead, NULL);
1845 if(!locator->pParserCtxt)
1847 ISAXLocator_Release((ISAXLocator*)&locator->lpSAXLocatorVtbl);
1851 This->isParsing = TRUE;
1854 hr = IStream_Read(stream, data, sizeof(data), &dataRead);
1858 if(xmlParseChunk(locator->pParserCtxt, data, dataRead, 0) != XML_ERR_OK) hr = E_FAIL;
1859 else hr = locator->ret;
1861 if(hr != S_OK) break;
1863 if(dataRead != sizeof(data))
1865 if(xmlParseChunk(locator->pParserCtxt, data, 0, 1) != XML_ERR_OK) hr = E_FAIL;
1866 else hr = locator->ret;
1871 This->isParsing = FALSE;
1873 xmlFreeParserCtxt(locator->pParserCtxt);
1874 locator->pParserCtxt = NULL;
1875 ISAXLocator_Release((ISAXLocator*)&locator->lpSAXLocatorVtbl);
1879 static HRESULT internal_getEntityResolver(
1881 void *pEntityResolver,
1884 FIXME("(%p)->(%p) stub\n", This, pEntityResolver);
1888 static HRESULT internal_putEntityResolver(
1890 void *pEntityResolver,
1893 FIXME("(%p)->(%p) stub\n", This, pEntityResolver);
1897 static HRESULT internal_getContentHandler(
1899 void *pContentHandler,
1902 TRACE("(%p)->(%p)\n", This, pContentHandler);
1903 if(pContentHandler == NULL)
1905 if((vbInterface && This->vbcontentHandler)
1906 || (!vbInterface && This->contentHandler))
1909 IVBSAXContentHandler_AddRef(This->vbcontentHandler);
1911 ISAXContentHandler_AddRef(This->contentHandler);
1913 if(vbInterface) *(IVBSAXContentHandler**)pContentHandler =
1914 This->vbcontentHandler;
1915 else *(ISAXContentHandler**)pContentHandler = This->contentHandler;
1920 static HRESULT internal_putContentHandler(
1922 void *contentHandler,
1925 TRACE("(%p)->(%p)\n", This, contentHandler);
1929 IVBSAXContentHandler_AddRef((IVBSAXContentHandler*)contentHandler);
1931 ISAXContentHandler_AddRef((ISAXContentHandler*)contentHandler);
1933 if((vbInterface && This->vbcontentHandler)
1934 || (!vbInterface && This->contentHandler))
1937 IVBSAXContentHandler_Release(This->vbcontentHandler);
1939 ISAXContentHandler_Release(This->contentHandler);
1942 This->vbcontentHandler = contentHandler;
1944 This->contentHandler = contentHandler;
1949 static HRESULT internal_getDTDHandler(
1954 FIXME("(%p)->(%p) stub\n", This, pDTDHandler);
1958 static HRESULT internal_putDTDHandler(
1963 FIXME("(%p)->(%p) stub\n", This, pDTDHandler);
1967 static HRESULT internal_getErrorHandler(
1969 void *pErrorHandler,
1972 TRACE("(%p)->(%p)\n", This, pErrorHandler);
1973 if(pErrorHandler == NULL)
1976 if(vbInterface && This->vberrorHandler)
1977 IVBSAXErrorHandler_AddRef(This->vberrorHandler);
1978 else if(!vbInterface && This->errorHandler)
1979 ISAXErrorHandler_AddRef(This->errorHandler);
1982 *(IVBSAXErrorHandler**)pErrorHandler = This->vberrorHandler;
1984 *(ISAXErrorHandler**)pErrorHandler = This->errorHandler;
1990 static HRESULT internal_putErrorHandler(
1995 TRACE("(%p)->(%p)\n", This, errorHandler);
1999 IVBSAXErrorHandler_AddRef((IVBSAXErrorHandler*)errorHandler);
2001 ISAXErrorHandler_AddRef((ISAXErrorHandler*)errorHandler);
2004 if(vbInterface && This->vberrorHandler)
2005 IVBSAXErrorHandler_Release(This->vberrorHandler);
2006 else if(!vbInterface && This->errorHandler)
2007 ISAXErrorHandler_Release(This->errorHandler);
2010 This->vberrorHandler = errorHandler;
2012 This->errorHandler = errorHandler;
2018 static HRESULT internal_parse(
2025 TRACE("(%p)\n", This);
2028 switch(V_VT(&varInput))
2031 hr = internal_parseBuffer(This, (const char*)V_BSTR(&varInput),
2032 SysStringByteLen(V_BSTR(&varInput)), vbInterface);
2034 case VT_ARRAY|VT_UI1: {
2036 LONG lBound, uBound;
2039 hr = SafeArrayGetLBound(V_ARRAY(&varInput), 1, &lBound);
2040 if(hr != S_OK) break;
2041 hr = SafeArrayGetUBound(V_ARRAY(&varInput), 1, &uBound);
2042 if(hr != S_OK) break;
2043 dataRead = (uBound-lBound)*SafeArrayGetElemsize(V_ARRAY(&varInput));
2044 hr = SafeArrayAccessData(V_ARRAY(&varInput), &pSAData);
2045 if(hr != S_OK) break;
2046 hr = internal_parseBuffer(This, pSAData, dataRead, vbInterface);
2047 SafeArrayUnaccessData(V_ARRAY(&varInput));
2052 IPersistStream *persistStream;
2053 IStream *stream = NULL;
2054 IXMLDOMDocument *xmlDoc;
2056 if(IUnknown_QueryInterface(V_UNKNOWN(&varInput),
2057 &IID_IXMLDOMDocument, (void**)&xmlDoc) == S_OK)
2061 IXMLDOMDocument_get_xml(xmlDoc, &bstrData);
2062 hr = internal_parseBuffer(This, (const char*)bstrData,
2063 SysStringByteLen(bstrData), vbInterface);
2064 IXMLDOMDocument_Release(xmlDoc);
2065 SysFreeString(bstrData);
2069 if(IUnknown_QueryInterface(V_UNKNOWN(&varInput),
2070 &IID_IPersistStream, (void**)&persistStream) == S_OK)
2072 hr = CreateStreamOnHGlobal(NULL, TRUE, &stream);
2075 IPersistStream_Release(persistStream);
2079 hr = IPersistStream_Save(persistStream, stream, TRUE);
2080 IPersistStream_Release(persistStream);
2083 IStream_Release(stream);
2087 if(stream || IUnknown_QueryInterface(V_UNKNOWN(&varInput),
2088 &IID_IStream, (void**)&stream) == S_OK)
2090 hr = internal_parseStream(This, stream, vbInterface);
2091 IStream_Release(stream);
2096 WARN("vt %d not implemented\n", V_VT(&varInput));
2103 static HRESULT internal_vbonDataAvailable(void *obj, char *ptr, DWORD len)
2105 saxreader *This = obj;
2107 return internal_parseBuffer(This, ptr, len, TRUE);
2110 static HRESULT internal_onDataAvailable(void *obj, char *ptr, DWORD len)
2112 saxreader *This = obj;
2114 return internal_parseBuffer(This, ptr, len, FALSE);
2117 static HRESULT internal_parseURL(
2125 TRACE("(%p)->(%s)\n", This, debugstr_w(url));
2127 if(vbInterface) hr = bind_url(url, internal_vbonDataAvailable, This, &bsc);
2128 else hr = bind_url(url, internal_onDataAvailable, This, &bsc);
2138 static HRESULT internal_putProperty(
2144 static const WCHAR wszCharset[] = {
2145 'c','h','a','r','s','e','t',0
2147 static const WCHAR wszDeclarationHandler[] = {
2148 'h','t','t','p',':','/','/','x','m','l','.','o','r','g','/',
2149 's','a','x','/','p','r','o','p','e','r','t','i','e','s','/',
2150 'd','e','c','l','a','r','a','t','i','o','n',
2151 '-','h','a','n','d','l','e','r',0
2153 static const WCHAR wszDomNode[] = {
2154 'h','t','t','p',':','/','/','x','m','l','.','o','r','g','/',
2155 's','a','x','/','p','r','o','p','e','r','t','i','e','s','/',
2156 'd','o','m','-','n','o','d','e',0
2158 static const WCHAR wszInputSource[] = {
2159 'i','n','p','u','t','-','s','o','u','r','c','e',0
2161 static const WCHAR wszLexicalHandler[] = {
2162 'h','t','t','p',':','/','/','x','m','l','.','o','r','g','/',
2163 's','a','x','/','p','r','o','p','e','r','t','i','e','s','/',
2164 'l','e','x','i','c','a','l','-','h','a','n','d','l','e','r',0
2166 static const WCHAR wszMaxElementDepth[] = {
2167 'm','a','x','-','e','l','e','m','e','n','t','-','d','e','p','t','h',0
2169 static const WCHAR wszMaxXMLSize[] = {
2170 'm','a','x','-','x','m','l','-','s','i','z','e',0
2172 static const WCHAR wszSchemaDeclarationHandler[] = {
2173 's','c','h','e','m','a','-',
2174 'd','e','c','l','a','r','a','t','i','o','n','-',
2175 'h','a','n','d','l','e','r',0
2177 static const WCHAR wszXMLDeclEncoding[] = {
2178 'x','m','l','d','e','c','l','-','e','n','c','o','d','i','n','g',0
2180 static const WCHAR wszXMLDeclStandalone[] = {
2181 'x','m','l','d','e','c','l',
2182 '-','s','t','a','n','d','a','l','o','n','e',0
2184 static const WCHAR wszXMLDeclVersion[] = {
2185 'x','m','l','d','e','c','l','-','v','e','r','s','i','o','n',0
2188 TRACE("(%p)->(%s)\n", This, debugstr_w(pProp));
2190 if(!memcmp(pProp, wszDeclarationHandler, sizeof(wszDeclarationHandler)))
2192 if(This->isParsing) return E_FAIL;
2194 if(V_UNKNOWN(&value))
2197 IVBSAXDeclHandler_AddRef((IVBSAXDeclHandler*)V_UNKNOWN(&value));
2199 ISAXDeclHandler_AddRef((ISAXDeclHandler*)V_UNKNOWN(&value));
2201 if((vbInterface && This->vbdeclHandler)
2202 || (!vbInterface && This->declHandler))
2205 IVBSAXDeclHandler_Release(This->vbdeclHandler);
2207 ISAXDeclHandler_Release(This->declHandler);
2210 This->vbdeclHandler = (IVBSAXDeclHandler*)V_UNKNOWN(&value);
2212 This->declHandler = (ISAXDeclHandler*)V_UNKNOWN(&value);
2216 if(!memcmp(pProp, wszLexicalHandler, sizeof(wszLexicalHandler)))
2218 if(This->isParsing) return E_FAIL;
2220 if(V_UNKNOWN(&value))
2223 IVBSAXLexicalHandler_AddRef(
2224 (IVBSAXLexicalHandler*)V_UNKNOWN(&value));
2226 ISAXLexicalHandler_AddRef(
2227 (ISAXLexicalHandler*)V_UNKNOWN(&value));
2229 if((vbInterface && This->vblexicalHandler)
2230 || (!vbInterface && This->lexicalHandler))
2233 IVBSAXLexicalHandler_Release(This->vblexicalHandler);
2235 ISAXLexicalHandler_Release(This->lexicalHandler);
2238 This->vblexicalHandler = (IVBSAXLexicalHandler*)V_UNKNOWN(&value);
2240 This->lexicalHandler = (ISAXLexicalHandler*)V_UNKNOWN(&value);
2244 FIXME("(%p)->(%s): unsupported property\n", This, debugstr_w(pProp));
2246 if(!memcmp(pProp, wszCharset, sizeof(wszCharset)))
2249 if(!memcmp(pProp, wszDomNode, sizeof(wszDomNode)))
2252 if(!memcmp(pProp, wszInputSource, sizeof(wszInputSource)))
2255 if(!memcmp(pProp, wszMaxElementDepth, sizeof(wszMaxElementDepth)))
2258 if(!memcmp(pProp, wszMaxXMLSize, sizeof(wszMaxXMLSize)))
2261 if(!memcmp(pProp, wszSchemaDeclarationHandler,
2262 sizeof(wszSchemaDeclarationHandler)))
2265 if(!memcmp(pProp, wszXMLDeclEncoding, sizeof(wszXMLDeclEncoding)))
2268 if(!memcmp(pProp, wszXMLDeclStandalone, sizeof(wszXMLDeclStandalone)))
2271 if(!memcmp(pProp, wszXMLDeclVersion, sizeof(wszXMLDeclVersion)))
2274 return E_INVALIDARG;
2277 /*** IVBSAXXMLReader interface ***/
2278 /*** IUnknown methods ***/
2279 static HRESULT WINAPI saxxmlreader_QueryInterface(IVBSAXXMLReader* iface, REFIID riid, void **ppvObject)
2281 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2283 TRACE("%p %s %p\n", This, debugstr_guid( riid ), ppvObject );
2287 if ( IsEqualGUID( riid, &IID_IUnknown ) ||
2288 IsEqualGUID( riid, &IID_IDispatch ) ||
2289 IsEqualGUID( riid, &IID_IVBSAXXMLReader ))
2293 else if( IsEqualGUID( riid, &IID_ISAXXMLReader ))
2295 *ppvObject = &This->lpSAXXMLReaderVtbl;
2299 FIXME("interface %s not implemented\n", debugstr_guid(riid));
2300 return E_NOINTERFACE;
2303 IVBSAXXMLReader_AddRef( iface );
2308 static ULONG WINAPI saxxmlreader_AddRef(IVBSAXXMLReader* iface)
2310 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2311 TRACE("%p\n", This );
2312 return InterlockedIncrement( &This->ref );
2315 static ULONG WINAPI saxxmlreader_Release(
2316 IVBSAXXMLReader* iface)
2318 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2321 TRACE("%p\n", This );
2323 ref = InterlockedDecrement( &This->ref );
2326 if(This->contentHandler)
2327 ISAXContentHandler_Release(This->contentHandler);
2329 if(This->vbcontentHandler)
2330 IVBSAXContentHandler_Release(This->vbcontentHandler);
2332 if(This->errorHandler)
2333 ISAXErrorHandler_Release(This->errorHandler);
2335 if(This->vberrorHandler)
2336 IVBSAXErrorHandler_Release(This->vberrorHandler);
2338 if(This->lexicalHandler)
2339 ISAXLexicalHandler_Release(This->lexicalHandler);
2341 if(This->vblexicalHandler)
2342 IVBSAXLexicalHandler_Release(This->vblexicalHandler);
2344 if(This->declHandler)
2345 ISAXDeclHandler_Release(This->declHandler);
2347 if(This->vbdeclHandler)
2348 IVBSAXDeclHandler_Release(This->vbdeclHandler);
2356 static HRESULT WINAPI saxxmlreader_GetTypeInfoCount( IVBSAXXMLReader *iface, UINT* pctinfo )
2358 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2360 TRACE("(%p)->(%p)\n", This, pctinfo);
2367 static HRESULT WINAPI saxxmlreader_GetTypeInfo(
2368 IVBSAXXMLReader *iface,
2369 UINT iTInfo, LCID lcid, ITypeInfo** ppTInfo )
2371 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2374 TRACE("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo);
2376 hr = get_typeinfo(IVBSAXXMLReader_tid, ppTInfo);
2381 static HRESULT WINAPI saxxmlreader_GetIDsOfNames(
2382 IVBSAXXMLReader *iface,
2384 LPOLESTR* rgszNames,
2389 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2390 ITypeInfo *typeinfo;
2393 TRACE("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames, cNames,
2396 if(!rgszNames || cNames == 0 || !rgDispId)
2397 return E_INVALIDARG;
2399 hr = get_typeinfo(IVBSAXXMLReader_tid, &typeinfo);
2402 hr = ITypeInfo_GetIDsOfNames(typeinfo, rgszNames, cNames, rgDispId);
2403 ITypeInfo_Release(typeinfo);
2409 static HRESULT WINAPI saxxmlreader_Invoke(
2410 IVBSAXXMLReader *iface,
2411 DISPID dispIdMember,
2415 DISPPARAMS* pDispParams,
2416 VARIANT* pVarResult,
2417 EXCEPINFO* pExcepInfo,
2420 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2421 ITypeInfo *typeinfo;
2424 TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
2425 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
2427 hr = get_typeinfo(IVBSAXXMLReader_tid, &typeinfo);
2430 hr = ITypeInfo_Invoke(typeinfo, &(This->lpVBSAXXMLReaderVtbl), dispIdMember, wFlags, pDispParams,
2431 pVarResult, pExcepInfo, puArgErr);
2432 ITypeInfo_Release(typeinfo);
2438 /*** IVBSAXXMLReader methods ***/
2439 static HRESULT WINAPI saxxmlreader_getFeature(
2440 IVBSAXXMLReader* iface,
2441 const WCHAR *pFeature,
2442 VARIANT_BOOL *pValue)
2444 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2446 FIXME("(%p)->(%s %p) stub\n", This, debugstr_w(pFeature), pValue);
2450 static HRESULT WINAPI saxxmlreader_putFeature(
2451 IVBSAXXMLReader* iface,
2452 const WCHAR *pFeature,
2453 VARIANT_BOOL vfValue)
2455 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2457 FIXME("(%p)->(%s %x) stub\n", This, debugstr_w(pFeature), vfValue);
2461 static HRESULT WINAPI saxxmlreader_getProperty(
2462 IVBSAXXMLReader* iface,
2466 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2468 FIXME("(%p)->(%s %p) stub\n", This, debugstr_w(pProp), pValue);
2472 static HRESULT WINAPI saxxmlreader_putProperty(
2473 IVBSAXXMLReader* iface,
2477 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2478 return internal_putProperty(This, pProp, value, TRUE);
2481 static HRESULT WINAPI saxxmlreader_get_entityResolver(
2482 IVBSAXXMLReader* iface,
2483 IVBSAXEntityResolver **pEntityResolver)
2485 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2486 return internal_getEntityResolver(This, pEntityResolver, TRUE);
2489 static HRESULT WINAPI saxxmlreader_put_entityResolver(
2490 IVBSAXXMLReader* iface,
2491 IVBSAXEntityResolver *pEntityResolver)
2493 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2494 return internal_putEntityResolver(This, pEntityResolver, TRUE);
2497 static HRESULT WINAPI saxxmlreader_get_contentHandler(
2498 IVBSAXXMLReader* iface,
2499 IVBSAXContentHandler **ppContentHandler)
2501 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2502 return internal_getContentHandler(This, ppContentHandler, TRUE);
2505 static HRESULT WINAPI saxxmlreader_put_contentHandler(
2506 IVBSAXXMLReader* iface,
2507 IVBSAXContentHandler *contentHandler)
2509 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2510 return internal_putContentHandler(This, contentHandler, TRUE);
2513 static HRESULT WINAPI saxxmlreader_get_dtdHandler(
2514 IVBSAXXMLReader* iface,
2515 IVBSAXDTDHandler **pDTDHandler)
2517 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2518 return internal_getDTDHandler(This, pDTDHandler, TRUE);
2521 static HRESULT WINAPI saxxmlreader_put_dtdHandler(
2522 IVBSAXXMLReader* iface,
2523 IVBSAXDTDHandler *pDTDHandler)
2525 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2526 return internal_putDTDHandler(This, pDTDHandler, TRUE);
2529 static HRESULT WINAPI saxxmlreader_get_errorHandler(
2530 IVBSAXXMLReader* iface,
2531 IVBSAXErrorHandler **pErrorHandler)
2533 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2534 return internal_getErrorHandler(This, pErrorHandler, TRUE);
2537 static HRESULT WINAPI saxxmlreader_put_errorHandler(
2538 IVBSAXXMLReader* iface,
2539 IVBSAXErrorHandler *errorHandler)
2541 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2542 return internal_putErrorHandler(This, errorHandler, TRUE);
2545 static HRESULT WINAPI saxxmlreader_get_baseURL(
2546 IVBSAXXMLReader* iface,
2547 const WCHAR **pBaseUrl)
2549 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2551 FIXME("(%p)->(%p) stub\n", This, pBaseUrl);
2555 static HRESULT WINAPI saxxmlreader_put_baseURL(
2556 IVBSAXXMLReader* iface,
2557 const WCHAR *pBaseUrl)
2559 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2561 FIXME("(%p)->(%s) stub\n", This, debugstr_w(pBaseUrl));
2565 static HRESULT WINAPI saxxmlreader_get_secureBaseURL(
2566 IVBSAXXMLReader* iface,
2567 const WCHAR **pSecureBaseUrl)
2569 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2571 FIXME("(%p)->(%p) stub\n", This, pSecureBaseUrl);
2576 static HRESULT WINAPI saxxmlreader_put_secureBaseURL(
2577 IVBSAXXMLReader* iface,
2578 const WCHAR *secureBaseUrl)
2580 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2582 FIXME("(%p)->(%s) stub\n", This, debugstr_w(secureBaseUrl));
2586 static HRESULT WINAPI saxxmlreader_parse(
2587 IVBSAXXMLReader* iface,
2590 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2591 return internal_parse(This, varInput, TRUE);
2594 static HRESULT WINAPI saxxmlreader_parseURL(
2595 IVBSAXXMLReader* iface,
2598 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2599 return internal_parseURL(This, url, TRUE);
2602 static const struct IVBSAXXMLReaderVtbl saxreader_vtbl =
2604 saxxmlreader_QueryInterface,
2605 saxxmlreader_AddRef,
2606 saxxmlreader_Release,
2607 saxxmlreader_GetTypeInfoCount,
2608 saxxmlreader_GetTypeInfo,
2609 saxxmlreader_GetIDsOfNames,
2610 saxxmlreader_Invoke,
2611 saxxmlreader_getFeature,
2612 saxxmlreader_putFeature,
2613 saxxmlreader_getProperty,
2614 saxxmlreader_putProperty,
2615 saxxmlreader_get_entityResolver,
2616 saxxmlreader_put_entityResolver,
2617 saxxmlreader_get_contentHandler,
2618 saxxmlreader_put_contentHandler,
2619 saxxmlreader_get_dtdHandler,
2620 saxxmlreader_put_dtdHandler,
2621 saxxmlreader_get_errorHandler,
2622 saxxmlreader_put_errorHandler,
2623 saxxmlreader_get_baseURL,
2624 saxxmlreader_put_baseURL,
2625 saxxmlreader_get_secureBaseURL,
2626 saxxmlreader_put_secureBaseURL,
2628 saxxmlreader_parseURL
2631 /*** ISAXXMLReader interface ***/
2632 /*** IUnknown methods ***/
2633 static HRESULT WINAPI isaxxmlreader_QueryInterface(ISAXXMLReader* iface, REFIID riid, void **ppvObject)
2635 saxreader *This = impl_from_ISAXXMLReader( iface );
2636 return saxxmlreader_QueryInterface((IVBSAXXMLReader*)&This->lpVBSAXXMLReaderVtbl, riid, ppvObject);
2639 static ULONG WINAPI isaxxmlreader_AddRef(ISAXXMLReader* iface)
2641 saxreader *This = impl_from_ISAXXMLReader( iface );
2642 return saxxmlreader_AddRef((IVBSAXXMLReader*)&This->lpVBSAXXMLReaderVtbl);
2645 static ULONG WINAPI isaxxmlreader_Release(ISAXXMLReader* iface)
2647 saxreader *This = impl_from_ISAXXMLReader( iface );
2648 return saxxmlreader_Release((IVBSAXXMLReader*)&This->lpVBSAXXMLReaderVtbl);
2651 /*** ISAXXMLReader methods ***/
2652 static HRESULT WINAPI isaxxmlreader_getFeature(
2653 ISAXXMLReader* iface,
2654 const WCHAR *pFeature,
2655 VARIANT_BOOL *pValue)
2657 saxreader *This = impl_from_ISAXXMLReader( iface );
2658 return IVBSAXXMLReader_getFeature(
2659 (IVBSAXXMLReader*)&This->lpVBSAXXMLReaderVtbl,
2663 static HRESULT WINAPI isaxxmlreader_putFeature(
2664 ISAXXMLReader* iface,
2665 const WCHAR *pFeature,
2666 VARIANT_BOOL vfValue)
2668 saxreader *This = impl_from_ISAXXMLReader( iface );
2669 return IVBSAXXMLReader_putFeature(
2670 (IVBSAXXMLReader*)&This->lpVBSAXXMLReaderVtbl,
2674 static HRESULT WINAPI isaxxmlreader_getProperty(
2675 ISAXXMLReader* iface,
2679 saxreader *This = impl_from_ISAXXMLReader( iface );
2680 return IVBSAXXMLReader_getProperty(
2681 (IVBSAXXMLReader*)&This->lpVBSAXXMLReaderVtbl,
2685 static HRESULT WINAPI isaxxmlreader_putProperty(
2686 ISAXXMLReader* iface,
2690 saxreader *This = impl_from_ISAXXMLReader( iface );
2691 return internal_putProperty(This, pProp, value, FALSE);
2694 static HRESULT WINAPI isaxxmlreader_getEntityResolver(
2695 ISAXXMLReader* iface,
2696 ISAXEntityResolver **ppEntityResolver)
2698 saxreader *This = impl_from_ISAXXMLReader( iface );
2699 return internal_getEntityResolver(This, ppEntityResolver, FALSE);
2702 static HRESULT WINAPI isaxxmlreader_putEntityResolver(
2703 ISAXXMLReader* iface,
2704 ISAXEntityResolver *pEntityResolver)
2706 saxreader *This = impl_from_ISAXXMLReader( iface );
2707 return internal_putEntityResolver(This, pEntityResolver, FALSE);
2710 static HRESULT WINAPI isaxxmlreader_getContentHandler(
2711 ISAXXMLReader* iface,
2712 ISAXContentHandler **pContentHandler)
2714 saxreader *This = impl_from_ISAXXMLReader( iface );
2715 return internal_getContentHandler(This, pContentHandler, FALSE);
2718 static HRESULT WINAPI isaxxmlreader_putContentHandler(
2719 ISAXXMLReader* iface,
2720 ISAXContentHandler *contentHandler)
2722 saxreader *This = impl_from_ISAXXMLReader( iface );
2723 return internal_putContentHandler(This, contentHandler, FALSE);
2726 static HRESULT WINAPI isaxxmlreader_getDTDHandler(
2727 ISAXXMLReader* iface,
2728 ISAXDTDHandler **pDTDHandler)
2730 saxreader *This = impl_from_ISAXXMLReader( iface );
2731 return internal_getDTDHandler(This, pDTDHandler, FALSE);
2734 static HRESULT WINAPI isaxxmlreader_putDTDHandler(
2735 ISAXXMLReader* iface,
2736 ISAXDTDHandler *pDTDHandler)
2738 saxreader *This = impl_from_ISAXXMLReader( iface );
2739 return internal_putDTDHandler(This, pDTDHandler, FALSE);
2742 static HRESULT WINAPI isaxxmlreader_getErrorHandler(
2743 ISAXXMLReader* iface,
2744 ISAXErrorHandler **pErrorHandler)
2746 saxreader *This = impl_from_ISAXXMLReader( iface );
2747 return internal_getErrorHandler(This, pErrorHandler, FALSE);
2750 static HRESULT WINAPI isaxxmlreader_putErrorHandler(
2751 ISAXXMLReader* iface,
2752 ISAXErrorHandler *errorHandler)
2754 saxreader *This = impl_from_ISAXXMLReader( iface );
2755 return internal_putErrorHandler(This, errorHandler, FALSE);
2758 static HRESULT WINAPI isaxxmlreader_getBaseURL(
2759 ISAXXMLReader* iface,
2760 const WCHAR **pBaseUrl)
2762 saxreader *This = impl_from_ISAXXMLReader( iface );
2763 return IVBSAXXMLReader_get_baseURL(
2764 (IVBSAXXMLReader*)&This->lpVBSAXXMLReaderVtbl,
2768 static HRESULT WINAPI isaxxmlreader_putBaseURL(
2769 ISAXXMLReader* iface,
2770 const WCHAR *pBaseUrl)
2772 saxreader *This = impl_from_ISAXXMLReader( iface );
2773 return IVBSAXXMLReader_put_baseURL(
2774 (IVBSAXXMLReader*)&This->lpVBSAXXMLReaderVtbl,
2778 static HRESULT WINAPI isaxxmlreader_getSecureBaseURL(
2779 ISAXXMLReader* iface,
2780 const WCHAR **pSecureBaseUrl)
2782 saxreader *This = impl_from_ISAXXMLReader( iface );
2783 return IVBSAXXMLReader_get_secureBaseURL(
2784 (IVBSAXXMLReader*)&This->lpVBSAXXMLReaderVtbl,
2788 static HRESULT WINAPI isaxxmlreader_putSecureBaseURL(
2789 ISAXXMLReader* iface,
2790 const WCHAR *secureBaseUrl)
2792 saxreader *This = impl_from_ISAXXMLReader( iface );
2793 return IVBSAXXMLReader_put_secureBaseURL(
2794 (IVBSAXXMLReader*)&This->lpVBSAXXMLReaderVtbl,
2798 static HRESULT WINAPI isaxxmlreader_parse(
2799 ISAXXMLReader* iface,
2802 saxreader *This = impl_from_ISAXXMLReader( iface );
2803 return internal_parse(This, varInput, FALSE);
2806 static HRESULT WINAPI isaxxmlreader_parseURL(
2807 ISAXXMLReader* iface,
2810 saxreader *This = impl_from_ISAXXMLReader( iface );
2811 return internal_parseURL(This, url, FALSE);
2814 static const struct ISAXXMLReaderVtbl isaxreader_vtbl =
2816 isaxxmlreader_QueryInterface,
2817 isaxxmlreader_AddRef,
2818 isaxxmlreader_Release,
2819 isaxxmlreader_getFeature,
2820 isaxxmlreader_putFeature,
2821 isaxxmlreader_getProperty,
2822 isaxxmlreader_putProperty,
2823 isaxxmlreader_getEntityResolver,
2824 isaxxmlreader_putEntityResolver,
2825 isaxxmlreader_getContentHandler,
2826 isaxxmlreader_putContentHandler,
2827 isaxxmlreader_getDTDHandler,
2828 isaxxmlreader_putDTDHandler,
2829 isaxxmlreader_getErrorHandler,
2830 isaxxmlreader_putErrorHandler,
2831 isaxxmlreader_getBaseURL,
2832 isaxxmlreader_putBaseURL,
2833 isaxxmlreader_getSecureBaseURL,
2834 isaxxmlreader_putSecureBaseURL,
2835 isaxxmlreader_parse,
2836 isaxxmlreader_parseURL
2839 HRESULT SAXXMLReader_create(IUnknown *pUnkOuter, LPVOID *ppObj)
2843 TRACE("(%p,%p)\n", pUnkOuter, ppObj);
2845 reader = heap_alloc( sizeof (*reader) );
2847 return E_OUTOFMEMORY;
2849 reader->lpVBSAXXMLReaderVtbl = &saxreader_vtbl;
2850 reader->lpSAXXMLReaderVtbl = &isaxreader_vtbl;
2852 reader->contentHandler = NULL;
2853 reader->vbcontentHandler = NULL;
2854 reader->errorHandler = NULL;
2855 reader->vberrorHandler = NULL;
2856 reader->lexicalHandler = NULL;
2857 reader->vblexicalHandler = NULL;
2858 reader->declHandler = NULL;
2859 reader->vbdeclHandler = NULL;
2860 reader->isParsing = FALSE;
2862 memset(&reader->sax, 0, sizeof(xmlSAXHandler));
2863 reader->sax.initialized = XML_SAX2_MAGIC;
2864 reader->sax.startDocument = libxmlStartDocument;
2865 reader->sax.endDocument = libxmlEndDocument;
2866 reader->sax.startElementNs = libxmlStartElementNS;
2867 reader->sax.endElementNs = libxmlEndElementNS;
2868 reader->sax.characters = libxmlCharacters;
2869 reader->sax.setDocumentLocator = libxmlSetDocumentLocator;
2870 reader->sax.comment = libxmlComment;
2871 reader->sax.error = libxmlFatalError;
2872 reader->sax.fatalError = libxmlFatalError;
2873 reader->sax.cdataBlock = libxmlCDataBlock;
2875 *ppObj = &reader->lpVBSAXXMLReaderVtbl;
2877 TRACE("returning iface %p\n", *ppObj);
2884 HRESULT SAXXMLReader_create(IUnknown *pUnkOuter, LPVOID *ppObj)
2886 MESSAGE("This program tried to use a SAX XML Reader object, but\n"
2887 "libxml2 support was not present at compile time.\n");