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
38 #include "wine/debug.h"
40 #include "msxml_private.h"
42 WINE_DEFAULT_DEBUG_CHANNEL(msxml);
46 #include <libxml/SAX2.h>
47 #include <libxml/parserInternals.h>
49 typedef struct _saxreader
51 const struct IVBSAXXMLReaderVtbl *lpVBSAXXMLReaderVtbl;
52 const struct ISAXXMLReaderVtbl *lpSAXXMLReaderVtbl;
54 struct ISAXContentHandler *contentHandler;
55 struct IVBSAXContentHandler *vbcontentHandler;
56 struct ISAXErrorHandler *errorHandler;
57 struct IVBSAXErrorHandler *vberrorHandler;
58 struct ISAXLexicalHandler *lexicalHandler;
59 struct IVBSAXLexicalHandler *vblexicalHandler;
60 struct ISAXDeclHandler *declHandler;
61 struct IVBSAXDeclHandler *vbdeclHandler;
66 typedef struct _saxlocator
68 const struct IVBSAXLocatorVtbl *lpVBSAXLocatorVtbl;
69 const struct ISAXLocatorVtbl *lpSAXLocatorVtbl;
73 xmlParserCtxtPtr pParserCtxt;
87 typedef struct _saxattributes
89 const struct IVBSAXAttributesVtbl *lpVBSAXAttributesVtbl;
90 const struct ISAXAttributesVtbl *lpSAXAttributesVtbl;
99 static inline saxreader *impl_from_IVBSAXXMLReader( IVBSAXXMLReader *iface )
101 return (saxreader *)((char*)iface - FIELD_OFFSET(saxreader, lpVBSAXXMLReaderVtbl));
104 static inline saxreader *impl_from_ISAXXMLReader( ISAXXMLReader *iface )
106 return (saxreader *)((char*)iface - FIELD_OFFSET(saxreader, lpSAXXMLReaderVtbl));
109 static inline saxlocator *impl_from_IVBSAXLocator( IVBSAXLocator *iface )
111 return (saxlocator *)((char*)iface - FIELD_OFFSET(saxlocator, lpVBSAXLocatorVtbl));
114 static inline saxlocator *impl_from_ISAXLocator( ISAXLocator *iface )
116 return (saxlocator *)((char*)iface - FIELD_OFFSET(saxlocator, lpSAXLocatorVtbl));
119 static inline saxattributes *impl_from_IVBSAXAttributes( IVBSAXAttributes *iface )
121 return (saxattributes *)((char*)iface - FIELD_OFFSET(saxattributes, lpVBSAXAttributesVtbl));
124 static inline saxattributes *impl_from_ISAXAttributes( ISAXAttributes *iface )
126 return (saxattributes *)((char*)iface - FIELD_OFFSET(saxattributes, lpSAXAttributesVtbl));
129 static inline BOOL has_content_handler(const saxlocator *locator)
131 return (locator->vbInterface && locator->saxreader->vbcontentHandler) ||
132 (!locator->vbInterface && locator->saxreader->contentHandler);
135 static inline BOOL has_error_handler(const saxlocator *locator)
137 return (locator->vbInterface && locator->saxreader->vberrorHandler) ||
138 (!locator->vbInterface && locator->saxreader->errorHandler);
141 static HRESULT namespacePush(saxlocator *locator, int ns)
143 if(locator->nsStackLast>=locator->nsStackSize)
147 new_stack = HeapReAlloc(GetProcessHeap(), 0,
148 locator->nsStack, sizeof(int)*locator->nsStackSize*2);
149 if(!new_stack) return E_OUTOFMEMORY;
150 locator->nsStack = new_stack;
151 locator->nsStackSize *= 2;
153 locator->nsStack[locator->nsStackLast++] = ns;
158 static int namespacePop(saxlocator *locator)
160 if(locator->nsStackLast == 0) return 0;
161 return locator->nsStack[--locator->nsStackLast];
164 static BSTR bstr_from_xmlCharN(const xmlChar *buf, int len)
172 dLen = MultiByteToWideChar(CP_UTF8, 0, (LPCSTR)buf, len, NULL, 0);
173 if(len != -1) dLen++;
174 bstr = SysAllocStringLen(NULL, dLen-1);
177 MultiByteToWideChar(CP_UTF8, 0, (LPCSTR)buf, len, bstr, dLen);
178 if(len != -1) bstr[dLen-1] = '\0';
183 static BSTR QName_from_xmlChar(const xmlChar *prefix, const xmlChar *name)
188 if(!name) return NULL;
190 if(!prefix || !*prefix)
191 return bstr_from_xmlChar(name);
193 qname = xmlBuildQName(name, prefix, NULL, 0);
194 bstr = bstr_from_xmlChar(qname);
200 static void format_error_message_from_id(saxlocator *This, HRESULT hr)
202 xmlStopParser(This->pParserCtxt);
205 if(has_error_handler(This))
208 if(!FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM,
209 NULL, hr, 0, msg, sizeof(msg), NULL))
211 FIXME("MSXML errors not yet supported.\n");
215 if(This->vbInterface)
217 BSTR bstrMsg = SysAllocString(msg);
218 IVBSAXErrorHandler_fatalError(This->saxreader->vberrorHandler,
219 (IVBSAXLocator*)&This->lpVBSAXLocatorVtbl, &bstrMsg, hr);
220 SysFreeString(bstrMsg);
223 ISAXErrorHandler_fatalError(This->saxreader->errorHandler,
224 (ISAXLocator*)&This->lpSAXLocatorVtbl, msg, hr);
228 static void update_position(saxlocator *This, xmlChar *end)
230 if(This->lastCur == NULL)
232 This->lastCur = (xmlChar*)This->pParserCtxt->input->base;
234 This->realColumn = 1;
236 else if(This->lastCur < This->pParserCtxt->input->base)
238 This->lastCur = (xmlChar*)This->pParserCtxt->input->base;
240 This->realColumn = 1;
243 if(This->pParserCtxt->input->cur<This->lastCur)
245 This->lastCur = (xmlChar*)This->pParserCtxt->input->base;
247 This->realColumn = 1;
250 if(!end) end = (xmlChar*)This->pParserCtxt->input->cur;
252 while(This->lastCur < end)
254 if(*(This->lastCur) == '\n')
257 This->realColumn = 1;
259 else if(*(This->lastCur) == '\r' &&
260 (This->lastCur==This->pParserCtxt->input->end ||
261 *(This->lastCur+1)!='\n'))
264 This->realColumn = 1;
266 else This->realColumn++;
270 /* Count multibyte UTF8 encoded characters once */
271 while((*(This->lastCur)&0xC0) == 0x80) This->lastCur++;
274 This->line = This->realLine;
275 This->column = This->realColumn;
278 /*** IVBSAXAttributes interface ***/
279 /*** IUnknown methods ***/
280 static HRESULT WINAPI ivbsaxattributes_QueryInterface(
281 IVBSAXAttributes* iface,
285 saxattributes *This = impl_from_IVBSAXAttributes(iface);
287 TRACE("%p %s %p\n", This, debugstr_guid(riid), ppvObject);
291 if (IsEqualGUID(riid, &IID_IUnknown) ||
292 IsEqualGUID(riid, &IID_IDispatch) ||
293 IsEqualGUID(riid, &IID_IVBSAXAttributes))
299 FIXME("interface %s not implemented\n", debugstr_guid(riid));
300 return E_NOINTERFACE;
303 IVBSAXAttributes_AddRef(iface);
308 static ULONG WINAPI ivbsaxattributes_AddRef(IVBSAXAttributes* iface)
310 saxattributes *This = impl_from_IVBSAXAttributes(iface);
311 return ISAXAttributes_AddRef((ISAXAttributes*)&This->lpSAXAttributesVtbl);
314 static ULONG WINAPI ivbsaxattributes_Release(IVBSAXAttributes* iface)
316 saxattributes *This = impl_from_IVBSAXAttributes(iface);
317 return ISAXAttributes_Release((ISAXAttributes*)&This->lpSAXAttributesVtbl);
320 /*** IDispatch methods ***/
321 static HRESULT WINAPI ivbsaxattributes_GetTypeInfoCount( IVBSAXAttributes *iface, UINT* pctinfo )
323 saxattributes *This = impl_from_IVBSAXAttributes( iface );
325 TRACE("(%p)->(%p)\n", This, pctinfo);
332 static HRESULT WINAPI ivbsaxattributes_GetTypeInfo(
333 IVBSAXAttributes *iface,
334 UINT iTInfo, LCID lcid, ITypeInfo** ppTInfo )
336 saxattributes *This = impl_from_IVBSAXAttributes( iface );
339 TRACE("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo);
341 hr = get_typeinfo(IVBSAXAttributes_tid, ppTInfo);
346 static HRESULT WINAPI ivbsaxattributes_GetIDsOfNames(
347 IVBSAXAttributes *iface,
354 saxattributes *This = impl_from_IVBSAXAttributes( iface );
358 TRACE("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames, cNames,
361 if(!rgszNames || cNames == 0 || !rgDispId)
364 hr = get_typeinfo(IVBSAXAttributes_tid, &typeinfo);
367 hr = ITypeInfo_GetIDsOfNames(typeinfo, rgszNames, cNames, rgDispId);
368 ITypeInfo_Release(typeinfo);
374 static HRESULT WINAPI ivbsaxattributes_Invoke(
375 IVBSAXAttributes *iface,
380 DISPPARAMS* pDispParams,
382 EXCEPINFO* pExcepInfo,
385 saxattributes *This = impl_from_IVBSAXAttributes( iface );
389 TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
390 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
392 hr = get_typeinfo(IVBSAXAttributes_tid, &typeinfo);
395 hr = ITypeInfo_Invoke(typeinfo, &(This->lpVBSAXAttributesVtbl), dispIdMember, wFlags, pDispParams,
396 pVarResult, pExcepInfo, puArgErr);
397 ITypeInfo_Release(typeinfo);
403 /*** IVBSAXAttributes methods ***/
404 static HRESULT WINAPI ivbsaxattributes_get_length(
405 IVBSAXAttributes* iface,
408 saxattributes *This = impl_from_IVBSAXAttributes( iface );
409 return ISAXAttributes_getLength(
410 (ISAXAttributes*)&This->lpSAXAttributesVtbl,
414 static HRESULT WINAPI ivbsaxattributes_getURI(
415 IVBSAXAttributes* iface,
420 saxattributes *This = impl_from_IVBSAXAttributes( iface );
421 return ISAXAttributes_getURI(
422 (ISAXAttributes*)&This->lpSAXAttributesVtbl,
423 nIndex, (const WCHAR**)uri, &len);
426 static HRESULT WINAPI ivbsaxattributes_getLocalName(
427 IVBSAXAttributes* iface,
432 saxattributes *This = impl_from_IVBSAXAttributes( iface );
433 return ISAXAttributes_getLocalName(
434 (ISAXAttributes*)&This->lpSAXAttributesVtbl,
435 nIndex, (const WCHAR**)localName, &len);
438 static HRESULT WINAPI ivbsaxattributes_getQName(
439 IVBSAXAttributes* iface,
444 saxattributes *This = impl_from_IVBSAXAttributes( iface );
445 return ISAXAttributes_getQName(
446 (ISAXAttributes*)&This->lpSAXAttributesVtbl,
447 nIndex, (const WCHAR**)QName, &len);
450 static HRESULT WINAPI ivbsaxattributes_getIndexFromName(
451 IVBSAXAttributes* iface,
456 saxattributes *This = impl_from_IVBSAXAttributes( iface );
457 return ISAXAttributes_getIndexFromName(
458 (ISAXAttributes*)&This->lpSAXAttributesVtbl, uri, SysStringLen(uri),
459 localName, SysStringLen(localName), index);
462 static HRESULT WINAPI ivbsaxattributes_getIndexFromQName(
463 IVBSAXAttributes* iface,
467 saxattributes *This = impl_from_IVBSAXAttributes( iface );
468 return ISAXAttributes_getIndexFromQName(
469 (ISAXAttributes*)&This->lpSAXAttributesVtbl, QName,
470 SysStringLen(QName), index);
473 static HRESULT WINAPI ivbsaxattributes_getType(
474 IVBSAXAttributes* iface,
479 saxattributes *This = impl_from_IVBSAXAttributes( iface );
480 return ISAXAttributes_getType(
481 (ISAXAttributes*)&This->lpSAXAttributesVtbl,
482 nIndex, (const WCHAR**)type, &len);
485 static HRESULT WINAPI ivbsaxattributes_getTypeFromName(
486 IVBSAXAttributes* iface,
492 saxattributes *This = impl_from_IVBSAXAttributes( iface );
493 return ISAXAttributes_getTypeFromName(
494 (ISAXAttributes*)&This->lpSAXAttributesVtbl, uri, SysStringLen(uri),
495 localName, SysStringLen(localName), (const WCHAR**)type, &len);
498 static HRESULT WINAPI ivbsaxattributes_getTypeFromQName(
499 IVBSAXAttributes* iface,
504 saxattributes *This = impl_from_IVBSAXAttributes( iface );
505 return ISAXAttributes_getTypeFromQName(
506 (ISAXAttributes*)&This->lpSAXAttributesVtbl, QName,
507 SysStringLen(QName), (const WCHAR**)type, &len);
510 static HRESULT WINAPI ivbsaxattributes_getValue(
511 IVBSAXAttributes* iface,
516 saxattributes *This = impl_from_IVBSAXAttributes( iface );
517 return ISAXAttributes_getValue(
518 (ISAXAttributes*)&This->lpSAXAttributesVtbl,
519 nIndex, (const WCHAR**)value, &len);
522 static HRESULT WINAPI ivbsaxattributes_getValueFromName(
523 IVBSAXAttributes* iface,
529 saxattributes *This = impl_from_IVBSAXAttributes( iface );
530 return ISAXAttributes_getValueFromName(
531 (ISAXAttributes*)&This->lpSAXAttributesVtbl, uri, SysStringLen(uri),
532 localName, SysStringLen(localName), (const WCHAR**)value, &len);
535 static HRESULT WINAPI ivbsaxattributes_getValueFromQName(
536 IVBSAXAttributes* iface,
541 saxattributes *This = impl_from_IVBSAXAttributes( iface );
542 return ISAXAttributes_getValueFromQName(
543 (ISAXAttributes*)&This->lpSAXAttributesVtbl, QName,
544 SysStringLen(QName), (const WCHAR**)value, &len);
547 static const struct IVBSAXAttributesVtbl ivbsaxattributes_vtbl =
549 ivbsaxattributes_QueryInterface,
550 ivbsaxattributes_AddRef,
551 ivbsaxattributes_Release,
552 ivbsaxattributes_GetTypeInfoCount,
553 ivbsaxattributes_GetTypeInfo,
554 ivbsaxattributes_GetIDsOfNames,
555 ivbsaxattributes_Invoke,
556 ivbsaxattributes_get_length,
557 ivbsaxattributes_getURI,
558 ivbsaxattributes_getLocalName,
559 ivbsaxattributes_getQName,
560 ivbsaxattributes_getIndexFromName,
561 ivbsaxattributes_getIndexFromQName,
562 ivbsaxattributes_getType,
563 ivbsaxattributes_getTypeFromName,
564 ivbsaxattributes_getTypeFromQName,
565 ivbsaxattributes_getValue,
566 ivbsaxattributes_getValueFromName,
567 ivbsaxattributes_getValueFromQName
570 /*** ISAXAttributes interface ***/
571 /*** IUnknown methods ***/
572 static HRESULT WINAPI isaxattributes_QueryInterface(
573 ISAXAttributes* iface,
577 saxattributes *This = impl_from_ISAXAttributes(iface);
579 TRACE("%p %s %p\n", This, debugstr_guid(riid), ppvObject);
583 if (IsEqualGUID(riid, &IID_IUnknown) ||
584 IsEqualGUID(riid, &IID_ISAXAttributes))
590 FIXME("interface %s not implemented\n", debugstr_guid(riid));
591 return E_NOINTERFACE;
594 ISAXAttributes_AddRef(iface);
599 static ULONG WINAPI isaxattributes_AddRef(ISAXAttributes* iface)
601 saxattributes *This = impl_from_ISAXAttributes(iface);
603 return InterlockedIncrement(&This->ref);
606 static ULONG WINAPI isaxattributes_Release(ISAXAttributes* iface)
608 saxattributes *This = impl_from_ISAXAttributes(iface);
613 ref = InterlockedDecrement(&This->ref);
617 for(index=0; index<This->nb_attributes; index++)
619 SysFreeString(This->szLocalname[index]);
620 SysFreeString(This->szURI[index]);
621 SysFreeString(This->szValue[index]);
622 SysFreeString(This->szQName[index]);
625 heap_free(This->szLocalname);
626 heap_free(This->szURI);
627 heap_free(This->szValue);
628 heap_free(This->szQName);
636 /*** ISAXAttributes methods ***/
637 static HRESULT WINAPI isaxattributes_getLength(
638 ISAXAttributes* iface,
641 saxattributes *This = impl_from_ISAXAttributes( iface );
643 *length = This->nb_attributes;
644 TRACE("Length set to %d\n", *length);
648 static HRESULT WINAPI isaxattributes_getURI(
649 ISAXAttributes* iface,
654 saxattributes *This = impl_from_ISAXAttributes( iface );
655 TRACE("(%p)->(%d)\n", This, nIndex);
657 if(nIndex>=This->nb_attributes || nIndex<0) return E_INVALIDARG;
658 if(!pUrl || !pUriSize) return E_POINTER;
660 *pUriSize = SysStringLen(This->szURI[nIndex]);
661 *pUrl = This->szURI[nIndex];
666 static HRESULT WINAPI isaxattributes_getLocalName(
667 ISAXAttributes* iface,
669 const WCHAR **pLocalName,
670 int *pLocalNameLength)
672 saxattributes *This = impl_from_ISAXAttributes( iface );
673 TRACE("(%p)->(%d)\n", This, nIndex);
675 if(nIndex>=This->nb_attributes || nIndex<0) return E_INVALIDARG;
676 if(!pLocalName || !pLocalNameLength) return E_POINTER;
678 *pLocalNameLength = SysStringLen(This->szLocalname[nIndex]);
679 *pLocalName = This->szLocalname[nIndex];
684 static HRESULT WINAPI isaxattributes_getQName(
685 ISAXAttributes* iface,
687 const WCHAR **pQName,
690 saxattributes *This = impl_from_ISAXAttributes( iface );
691 TRACE("(%p)->(%d)\n", This, nIndex);
693 if(nIndex>=This->nb_attributes || nIndex<0) return E_INVALIDARG;
694 if(!pQName || !pQNameLength) return E_POINTER;
696 *pQNameLength = SysStringLen(This->szQName[nIndex]);
697 *pQName = This->szQName[nIndex];
702 static HRESULT WINAPI isaxattributes_getName(
703 ISAXAttributes* iface,
707 const WCHAR **pLocalName,
709 const WCHAR **pQName,
712 saxattributes *This = impl_from_ISAXAttributes( iface );
713 TRACE("(%p)->(%d)\n", This, nIndex);
715 if(nIndex>=This->nb_attributes || nIndex<0) return E_INVALIDARG;
716 if(!pUri || !pUriLength || !pLocalName || !pLocalNameSize
717 || !pQName || !pQNameLength) return E_POINTER;
719 *pUriLength = SysStringLen(This->szURI[nIndex]);
720 *pUri = This->szURI[nIndex];
721 *pLocalNameSize = SysStringLen(This->szLocalname[nIndex]);
722 *pLocalName = This->szLocalname[nIndex];
723 *pQNameLength = SysStringLen(This->szQName[nIndex]);
724 *pQName = This->szQName[nIndex];
729 static HRESULT WINAPI isaxattributes_getIndexFromName(
730 ISAXAttributes* iface,
733 const WCHAR *pLocalName,
737 saxattributes *This = impl_from_ISAXAttributes( iface );
739 TRACE("(%p)->(%s, %d, %s, %d)\n", This, debugstr_w(pUri), cUriLength,
740 debugstr_w(pLocalName), cocalNameLength);
742 if(!pUri || !pLocalName || !index) return E_POINTER;
744 for(i=0; i<This->nb_attributes; i++)
746 if(cUriLength!=SysStringLen(This->szURI[i])
747 || cocalNameLength!=SysStringLen(This->szLocalname[i]))
749 if(cUriLength && memcmp(pUri, This->szURI[i],
750 sizeof(WCHAR)*cUriLength))
752 if(cocalNameLength && memcmp(pLocalName, This->szLocalname[i],
753 sizeof(WCHAR)*cocalNameLength))
763 static HRESULT WINAPI isaxattributes_getIndexFromQName(
764 ISAXAttributes* iface,
769 saxattributes *This = impl_from_ISAXAttributes( iface );
771 TRACE("(%p)->(%s, %d)\n", This, debugstr_w(pQName), nQNameLength);
773 if(!pQName || !index) return E_POINTER;
774 if(!nQNameLength) return E_INVALIDARG;
776 for(i=0; i<This->nb_attributes; i++)
778 if(nQNameLength!=SysStringLen(This->szQName[i])) continue;
779 if(memcmp(pQName, This->szQName, sizeof(WCHAR)*nQNameLength)) continue;
788 static HRESULT WINAPI isaxattributes_getType(
789 ISAXAttributes* iface,
794 saxattributes *This = impl_from_ISAXAttributes( iface );
796 FIXME("(%p)->(%d) stub\n", This, nIndex);
800 static HRESULT WINAPI isaxattributes_getTypeFromName(
801 ISAXAttributes* iface,
804 const WCHAR *pLocalName,
809 saxattributes *This = impl_from_ISAXAttributes( iface );
811 FIXME("(%p)->(%s, %d, %s, %d) stub\n", This, debugstr_w(pUri), nUri,
812 debugstr_w(pLocalName), nLocalName);
816 static HRESULT WINAPI isaxattributes_getTypeFromQName(
817 ISAXAttributes* iface,
823 saxattributes *This = impl_from_ISAXAttributes( iface );
825 FIXME("(%p)->(%s, %d) stub\n", This, debugstr_w(pQName), nQName);
829 static HRESULT WINAPI isaxattributes_getValue(
830 ISAXAttributes* iface,
832 const WCHAR **pValue,
835 saxattributes *This = impl_from_ISAXAttributes( iface );
836 TRACE("(%p)->(%d)\n", This, nIndex);
838 if(nIndex>=This->nb_attributes || nIndex<0) return E_INVALIDARG;
839 if(!pValue || !nValue) return E_POINTER;
841 *nValue = SysStringLen(This->szValue[nIndex]);
842 *pValue = This->szValue[nIndex];
847 static HRESULT WINAPI isaxattributes_getValueFromName(
848 ISAXAttributes* iface,
851 const WCHAR *pLocalName,
853 const WCHAR **pValue,
858 saxattributes *This = impl_from_ISAXAttributes( iface );
859 TRACE("(%p)->(%s, %d, %s, %d)\n", This, debugstr_w(pUri), nUri,
860 debugstr_w(pLocalName), nLocalName);
862 hr = ISAXAttributes_getIndexFromName(iface,
863 pUri, nUri, pLocalName, nLocalName, &index);
864 if(hr==S_OK) hr = ISAXAttributes_getValue(iface, index, pValue, nValue);
869 static HRESULT WINAPI isaxattributes_getValueFromQName(
870 ISAXAttributes* iface,
873 const WCHAR **pValue,
878 saxattributes *This = impl_from_ISAXAttributes( iface );
879 TRACE("(%p)->(%s, %d)\n", This, debugstr_w(pQName), nQName);
881 hr = ISAXAttributes_getIndexFromQName(iface, pQName, nQName, &index);
882 if(hr==S_OK) hr = ISAXAttributes_getValue(iface, index, pValue, nValue);
887 static const struct ISAXAttributesVtbl isaxattributes_vtbl =
889 isaxattributes_QueryInterface,
890 isaxattributes_AddRef,
891 isaxattributes_Release,
892 isaxattributes_getLength,
893 isaxattributes_getURI,
894 isaxattributes_getLocalName,
895 isaxattributes_getQName,
896 isaxattributes_getName,
897 isaxattributes_getIndexFromName,
898 isaxattributes_getIndexFromQName,
899 isaxattributes_getType,
900 isaxattributes_getTypeFromName,
901 isaxattributes_getTypeFromQName,
902 isaxattributes_getValue,
903 isaxattributes_getValueFromName,
904 isaxattributes_getValueFromQName
907 static HRESULT SAXAttributes_create(saxattributes **attr,
908 int nb_namespaces, const xmlChar **xmlNamespaces,
909 int nb_attributes, const xmlChar **xmlAttributes)
911 saxattributes *attributes;
913 static const xmlChar xmlns[] = "xmlns";
915 attributes = heap_alloc(sizeof(*attributes));
917 return E_OUTOFMEMORY;
919 attributes->lpVBSAXAttributesVtbl = &ivbsaxattributes_vtbl;
920 attributes->lpSAXAttributesVtbl = &isaxattributes_vtbl;
923 attributes->nb_attributes = nb_namespaces+nb_attributes;
925 attributes->szLocalname = heap_alloc(sizeof(BSTR)*attributes->nb_attributes);
926 attributes->szURI = heap_alloc(sizeof(BSTR)*attributes->nb_attributes);
927 attributes->szValue = heap_alloc(sizeof(BSTR)*attributes->nb_attributes);
928 attributes->szQName = heap_alloc(sizeof(BSTR)*attributes->nb_attributes);
930 if(!attributes->szLocalname || !attributes->szURI
931 || !attributes->szValue || !attributes->szQName)
933 heap_free(attributes->szLocalname);
934 heap_free(attributes->szURI);
935 heap_free(attributes->szValue);
936 heap_free(attributes->szQName);
937 heap_free(attributes);
941 for(index=0; index<nb_namespaces; index++)
943 attributes->szLocalname[index] = SysAllocStringLen(NULL, 0);
944 attributes->szURI[index] = SysAllocStringLen(NULL, 0);
945 attributes->szValue[index] = bstr_from_xmlChar(xmlNamespaces[2*index+1]);
946 attributes->szQName[index] = QName_from_xmlChar(xmlns, xmlNamespaces[2*index]);
949 for(index=0; index<nb_attributes; index++)
951 attributes->szLocalname[nb_namespaces+index] =
952 bstr_from_xmlChar(xmlAttributes[index*5]);
953 attributes->szURI[nb_namespaces+index] =
954 bstr_from_xmlChar(xmlAttributes[index*5+2]);
955 attributes->szValue[nb_namespaces+index] =
956 bstr_from_xmlCharN(xmlAttributes[index*5+3],
957 xmlAttributes[index*5+4]-xmlAttributes[index*5+3]);
958 attributes->szQName[nb_namespaces+index] =
959 QName_from_xmlChar(xmlAttributes[index*5+1], xmlAttributes[index*5]);
964 TRACE("returning %p\n", *attr);
969 /*** LibXML callbacks ***/
970 static void libxmlStartDocument(void *ctx)
972 saxlocator *This = ctx;
975 if(has_content_handler(This))
977 if(This->vbInterface)
978 hr = IVBSAXContentHandler_startDocument(This->saxreader->vbcontentHandler);
980 hr = ISAXContentHandler_startDocument(This->saxreader->contentHandler);
983 format_error_message_from_id(This, hr);
986 update_position(This, NULL);
989 static void libxmlEndDocument(void *ctx)
991 saxlocator *This = ctx;
997 if(This->ret != S_OK) return;
999 if(has_content_handler(This))
1001 if(This->vbInterface)
1002 hr = IVBSAXContentHandler_endDocument(This->saxreader->vbcontentHandler);
1004 hr = ISAXContentHandler_endDocument(This->saxreader->contentHandler);
1007 format_error_message_from_id(This, hr);
1011 static void libxmlStartElementNS(
1013 const xmlChar *localname,
1014 const xmlChar *prefix,
1017 const xmlChar **namespaces,
1020 const xmlChar **attributes)
1022 BSTR NamespaceUri, LocalName, QName, Prefix, Uri;
1023 saxlocator *This = ctx;
1025 saxattributes *attr;
1028 if(*(This->pParserCtxt->input->cur) == '/')
1029 update_position(This, (xmlChar*)This->pParserCtxt->input->cur+2);
1031 update_position(This, (xmlChar*)This->pParserCtxt->input->cur+1);
1033 hr = namespacePush(This, nb_namespaces);
1034 if(hr==S_OK && has_content_handler(This))
1036 for(index=0; index<nb_namespaces; index++)
1038 Prefix = bstr_from_xmlChar(namespaces[2*index]);
1039 Uri = bstr_from_xmlChar(namespaces[2*index+1]);
1041 if(This->vbInterface)
1042 hr = IVBSAXContentHandler_startPrefixMapping(
1043 This->saxreader->vbcontentHandler,
1046 hr = ISAXContentHandler_startPrefixMapping(
1047 This->saxreader->contentHandler,
1048 Prefix, SysStringLen(Prefix),
1049 Uri, SysStringLen(Uri));
1051 SysFreeString(Prefix);
1056 format_error_message_from_id(This, hr);
1061 NamespaceUri = bstr_from_xmlChar(URI);
1062 LocalName = bstr_from_xmlChar(localname);
1063 QName = QName_from_xmlChar(prefix, localname);
1065 hr = SAXAttributes_create(&attr, nb_namespaces, namespaces, nb_attributes, attributes);
1068 if(This->vbInterface)
1069 hr = IVBSAXContentHandler_startElement(
1070 This->saxreader->vbcontentHandler,
1071 &NamespaceUri, &LocalName, &QName,
1072 (IVBSAXAttributes*)&attr->lpVBSAXAttributesVtbl);
1074 hr = ISAXContentHandler_startElement(
1075 This->saxreader->contentHandler,
1076 NamespaceUri, SysStringLen(NamespaceUri),
1077 LocalName, SysStringLen(LocalName),
1078 QName, SysStringLen(QName),
1079 (ISAXAttributes*)&attr->lpSAXAttributesVtbl);
1081 ISAXAttributes_Release((ISAXAttributes*)&attr->lpSAXAttributesVtbl);
1084 SysFreeString(NamespaceUri);
1085 SysFreeString(LocalName);
1086 SysFreeString(QName);
1090 format_error_message_from_id(This, hr);
1093 static void libxmlEndElementNS(
1095 const xmlChar *localname,
1096 const xmlChar *prefix,
1099 BSTR NamespaceUri, LocalName, QName, Prefix;
1100 saxlocator *This = ctx;
1105 end = (xmlChar*)This->pParserCtxt->input->cur;
1106 if(*(end-1) != '>' || *(end-2) != '/')
1107 while(end-2>=This->pParserCtxt->input->base
1108 && *(end-2)!='<' && *(end-1)!='/') end--;
1110 update_position(This, end);
1112 nsNr = namespacePop(This);
1114 if(has_content_handler(This))
1116 NamespaceUri = bstr_from_xmlChar(URI);
1117 LocalName = bstr_from_xmlChar(localname);
1118 QName = QName_from_xmlChar(prefix, localname);
1120 if(This->vbInterface)
1121 hr = IVBSAXContentHandler_endElement(
1122 This->saxreader->vbcontentHandler,
1123 &NamespaceUri, &LocalName, &QName);
1125 hr = ISAXContentHandler_endElement(
1126 This->saxreader->contentHandler,
1127 NamespaceUri, SysStringLen(NamespaceUri),
1128 LocalName, SysStringLen(LocalName),
1129 QName, SysStringLen(QName));
1131 SysFreeString(NamespaceUri);
1132 SysFreeString(LocalName);
1133 SysFreeString(QName);
1137 format_error_message_from_id(This, hr);
1141 for(index=This->pParserCtxt->nsNr-2;
1142 index>=This->pParserCtxt->nsNr-nsNr*2; index-=2)
1144 Prefix = bstr_from_xmlChar(This->pParserCtxt->nsTab[index]);
1146 if(This->vbInterface)
1147 hr = IVBSAXContentHandler_endPrefixMapping(
1148 This->saxreader->vbcontentHandler, &Prefix);
1150 hr = ISAXContentHandler_endPrefixMapping(
1151 This->saxreader->contentHandler,
1152 Prefix, SysStringLen(Prefix));
1154 SysFreeString(Prefix);
1158 format_error_message_from_id(This, hr);
1165 update_position(This, NULL);
1168 static void libxmlCharacters(
1173 saxlocator *This = ctx;
1178 BOOL lastEvent = FALSE;
1180 if(!(has_content_handler(This))) return;
1183 if(*(ch-1)=='\r') cur--;
1186 if(ch<This->pParserCtxt->input->base || ch>This->pParserCtxt->input->end)
1191 while(end-ch<len && *end!='\r') end++;
1198 if(!lastEvent) *end = '\n';
1200 Chars = bstr_from_xmlCharN(cur, end-cur+1);
1201 if(This->vbInterface)
1202 hr = IVBSAXContentHandler_characters(
1203 This->saxreader->vbcontentHandler, &Chars);
1205 hr = ISAXContentHandler_characters(
1206 This->saxreader->contentHandler,
1207 Chars, SysStringLen(Chars));
1208 SysFreeString(Chars);
1212 format_error_message_from_id(This, hr);
1216 This->column += end-cur+1;
1230 if(end-ch == len) break;
1233 if(ch<This->pParserCtxt->input->base || ch>This->pParserCtxt->input->end)
1234 This->column = This->realColumn
1235 +This->pParserCtxt->input->cur-This->lastCur;
1238 static void libxmlSetDocumentLocator(
1240 xmlSAXLocatorPtr loc)
1242 saxlocator *This = ctx;
1245 if(has_content_handler(This))
1247 if(This->vbInterface)
1248 hr = IVBSAXContentHandler_putref_documentLocator(
1249 This->saxreader->vbcontentHandler,
1250 (IVBSAXLocator*)&This->lpVBSAXLocatorVtbl);
1252 hr = ISAXContentHandler_putDocumentLocator(
1253 This->saxreader->contentHandler,
1254 (ISAXLocator*)&This->lpSAXLocatorVtbl);
1258 format_error_message_from_id(This, hr);
1261 static void libxmlComment(void *ctx, const xmlChar *value)
1263 saxlocator *This = ctx;
1266 xmlChar *beg = (xmlChar*)This->pParserCtxt->input->cur;
1268 while(beg-4>=This->pParserCtxt->input->base
1269 && memcmp(beg-4, "<!--", sizeof(char[4]))) beg--;
1270 update_position(This, beg);
1272 if(!This->vbInterface && !This->saxreader->lexicalHandler) return;
1273 if(This->vbInterface && !This->saxreader->vblexicalHandler) return;
1275 bValue = bstr_from_xmlChar(value);
1277 if(This->vbInterface)
1278 hr = IVBSAXLexicalHandler_comment(
1279 This->saxreader->vblexicalHandler, &bValue);
1281 hr = ISAXLexicalHandler_comment(
1282 This->saxreader->lexicalHandler,
1283 bValue, SysStringLen(bValue));
1285 SysFreeString(bValue);
1288 format_error_message_from_id(This, hr);
1290 update_position(This, NULL);
1293 static void libxmlFatalError(void *ctx, const char *msg, ...)
1295 saxlocator *This = ctx;
1301 va_start(args, msg);
1302 vsprintf(message, msg, args);
1305 len = MultiByteToWideChar(CP_UNIXCP, 0, message, -1, NULL, 0);
1306 error = heap_alloc(sizeof(WCHAR)*len);
1309 MultiByteToWideChar(CP_UNIXCP, 0, message, -1, error, len);
1310 TRACE("fatal error for %p: %s\n", This, debugstr_w(error));
1313 if(!has_error_handler(This))
1315 xmlStopParser(This->pParserCtxt);
1321 FIXME("Error handling is not compatible.\n");
1323 if(This->vbInterface)
1325 BSTR bstrError = SysAllocString(error);
1326 IVBSAXErrorHandler_fatalError(This->saxreader->vberrorHandler,
1327 (IVBSAXLocator*)&This->lpVBSAXLocatorVtbl, &bstrError, E_FAIL);
1328 SysFreeString(bstrError);
1331 ISAXErrorHandler_fatalError(This->saxreader->errorHandler,
1332 (ISAXLocator*)&This->lpSAXLocatorVtbl, error, E_FAIL);
1336 xmlStopParser(This->pParserCtxt);
1340 static void libxmlCDataBlock(void *ctx, const xmlChar *value, int len)
1342 saxlocator *This = ctx;
1344 xmlChar *beg = (xmlChar*)This->pParserCtxt->input->cur-len;
1348 BOOL lastEvent = FALSE, change;
1350 while(beg-9>=This->pParserCtxt->input->base
1351 && memcmp(beg-9, "<![CDATA[", sizeof(char[9]))) beg--;
1352 update_position(This, beg);
1354 if(This->vbInterface && This->saxreader->vblexicalHandler)
1355 hr = IVBSAXLexicalHandler_startCDATA(This->saxreader->vblexicalHandler);
1356 if(!This->vbInterface && This->saxreader->lexicalHandler)
1357 hr = ISAXLexicalHandler_startCDATA(This->saxreader->lexicalHandler);
1361 format_error_message_from_id(This, hr);
1365 realLen = This->pParserCtxt->input->cur-beg-3;
1371 while(end-beg<realLen && *end!='\r') end++;
1372 if(end-beg==realLen)
1377 else if(end-beg==realLen-1 && *end=='\r' && *(end+1)=='\n')
1380 if(*end == '\r') change = TRUE;
1381 else change = FALSE;
1383 if(change) *end = '\n';
1385 if(has_content_handler(This))
1387 Chars = bstr_from_xmlCharN(cur, end-cur+1);
1388 if(This->vbInterface)
1389 hr = IVBSAXContentHandler_characters(
1390 This->saxreader->vbcontentHandler, &Chars);
1392 hr = ISAXContentHandler_characters(
1393 This->saxreader->contentHandler,
1394 Chars, SysStringLen(Chars));
1395 SysFreeString(Chars);
1398 if(change) *end = '\r';
1403 This->column += end-cur+2;
1408 if(This->vbInterface && This->saxreader->vblexicalHandler)
1409 hr = IVBSAXLexicalHandler_endCDATA(This->saxreader->vblexicalHandler);
1410 if(!This->vbInterface && This->saxreader->lexicalHandler)
1411 hr = ISAXLexicalHandler_endCDATA(This->saxreader->lexicalHandler);
1414 format_error_message_from_id(This, hr);
1416 This->column += 4+end-cur;
1419 /*** IVBSAXLocator interface ***/
1420 /*** IUnknown methods ***/
1421 static HRESULT WINAPI ivbsaxlocator_QueryInterface(IVBSAXLocator* iface, REFIID riid, void **ppvObject)
1423 saxlocator *This = impl_from_IVBSAXLocator( iface );
1425 TRACE("%p %s %p\n", This, debugstr_guid( riid ), ppvObject);
1429 if ( IsEqualGUID( riid, &IID_IUnknown ) ||
1430 IsEqualGUID( riid, &IID_IDispatch) ||
1431 IsEqualGUID( riid, &IID_IVBSAXLocator ))
1437 FIXME("interface %s not implemented\n", debugstr_guid(riid));
1438 return E_NOINTERFACE;
1441 IVBSAXLocator_AddRef( iface );
1446 static ULONG WINAPI ivbsaxlocator_AddRef(IVBSAXLocator* iface)
1448 saxlocator *This = impl_from_IVBSAXLocator( iface );
1449 TRACE("%p\n", This );
1450 return InterlockedIncrement( &This->ref );
1453 static ULONG WINAPI ivbsaxlocator_Release(
1454 IVBSAXLocator* iface)
1456 saxlocator *This = impl_from_IVBSAXLocator( iface );
1457 return ISAXLocator_Release((ISAXLocator*)&This->lpVBSAXLocatorVtbl);
1460 /*** IDispatch methods ***/
1461 static HRESULT WINAPI ivbsaxlocator_GetTypeInfoCount( IVBSAXLocator *iface, UINT* pctinfo )
1463 saxlocator *This = impl_from_IVBSAXLocator( iface );
1465 TRACE("(%p)->(%p)\n", This, pctinfo);
1472 static HRESULT WINAPI ivbsaxlocator_GetTypeInfo(
1473 IVBSAXLocator *iface,
1474 UINT iTInfo, LCID lcid, ITypeInfo** ppTInfo )
1476 saxlocator *This = impl_from_IVBSAXLocator( iface );
1479 TRACE("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo);
1481 hr = get_typeinfo(IVBSAXLocator_tid, ppTInfo);
1486 static HRESULT WINAPI ivbsaxlocator_GetIDsOfNames(
1487 IVBSAXLocator *iface,
1489 LPOLESTR* rgszNames,
1494 saxlocator *This = impl_from_IVBSAXLocator( iface );
1495 ITypeInfo *typeinfo;
1498 TRACE("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames, cNames,
1501 if(!rgszNames || cNames == 0 || !rgDispId)
1502 return E_INVALIDARG;
1504 hr = get_typeinfo(IVBSAXLocator_tid, &typeinfo);
1507 hr = ITypeInfo_GetIDsOfNames(typeinfo, rgszNames, cNames, rgDispId);
1508 ITypeInfo_Release(typeinfo);
1514 static HRESULT WINAPI ivbsaxlocator_Invoke(
1515 IVBSAXLocator *iface,
1516 DISPID dispIdMember,
1520 DISPPARAMS* pDispParams,
1521 VARIANT* pVarResult,
1522 EXCEPINFO* pExcepInfo,
1525 saxlocator *This = impl_from_IVBSAXLocator( iface );
1526 ITypeInfo *typeinfo;
1529 TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
1530 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
1532 hr = get_typeinfo(IVBSAXLocator_tid, &typeinfo);
1535 hr = ITypeInfo_Invoke(typeinfo, &(This->lpVBSAXLocatorVtbl), dispIdMember, wFlags, pDispParams,
1536 pVarResult, pExcepInfo, puArgErr);
1537 ITypeInfo_Release(typeinfo);
1543 /*** IVBSAXLocator methods ***/
1544 static HRESULT WINAPI ivbsaxlocator_get_columnNumber(
1545 IVBSAXLocator* iface,
1548 saxlocator *This = impl_from_IVBSAXLocator( iface );
1549 return ISAXLocator_getColumnNumber(
1550 (ISAXLocator*)&This->lpVBSAXLocatorVtbl,
1554 static HRESULT WINAPI ivbsaxlocator_get_lineNumber(
1555 IVBSAXLocator* iface,
1558 saxlocator *This = impl_from_IVBSAXLocator( iface );
1559 return ISAXLocator_getLineNumber(
1560 (ISAXLocator*)&This->lpVBSAXLocatorVtbl,
1564 static HRESULT WINAPI ivbsaxlocator_get_publicId(
1565 IVBSAXLocator* iface,
1568 saxlocator *This = impl_from_IVBSAXLocator( iface );
1569 return ISAXLocator_getPublicId(
1570 (ISAXLocator*)&This->lpVBSAXLocatorVtbl,
1571 (const WCHAR**)publicId);
1574 static HRESULT WINAPI ivbsaxlocator_get_systemId(
1575 IVBSAXLocator* iface,
1578 saxlocator *This = impl_from_IVBSAXLocator( iface );
1579 return ISAXLocator_getSystemId(
1580 (ISAXLocator*)&This->lpVBSAXLocatorVtbl,
1581 (const WCHAR**)systemId);
1584 static const struct IVBSAXLocatorVtbl ivbsaxlocator_vtbl =
1586 ivbsaxlocator_QueryInterface,
1587 ivbsaxlocator_AddRef,
1588 ivbsaxlocator_Release,
1589 ivbsaxlocator_GetTypeInfoCount,
1590 ivbsaxlocator_GetTypeInfo,
1591 ivbsaxlocator_GetIDsOfNames,
1592 ivbsaxlocator_Invoke,
1593 ivbsaxlocator_get_columnNumber,
1594 ivbsaxlocator_get_lineNumber,
1595 ivbsaxlocator_get_publicId,
1596 ivbsaxlocator_get_systemId
1599 /*** ISAXLocator interface ***/
1600 /*** IUnknown methods ***/
1601 static HRESULT WINAPI isaxlocator_QueryInterface(ISAXLocator* iface, REFIID riid, void **ppvObject)
1603 saxlocator *This = impl_from_ISAXLocator( iface );
1605 TRACE("%p %s %p\n", This, debugstr_guid( riid ), ppvObject );
1609 if ( IsEqualGUID( riid, &IID_IUnknown ) ||
1610 IsEqualGUID( riid, &IID_ISAXLocator ))
1616 FIXME("interface %s not implemented\n", debugstr_guid(riid));
1617 return E_NOINTERFACE;
1620 ISAXLocator_AddRef( iface );
1625 static ULONG WINAPI isaxlocator_AddRef(ISAXLocator* iface)
1627 saxlocator *This = impl_from_ISAXLocator( iface );
1628 TRACE("%p\n", This );
1629 return InterlockedIncrement( &This->ref );
1632 static ULONG WINAPI isaxlocator_Release(
1635 saxlocator *This = impl_from_ISAXLocator( iface );
1638 TRACE("%p\n", This );
1640 ref = InterlockedDecrement( &This->ref );
1643 SysFreeString(This->publicId);
1644 SysFreeString(This->systemId);
1645 heap_free(This->nsStack);
1647 ISAXXMLReader_Release((ISAXXMLReader*)&This->saxreader->lpSAXXMLReaderVtbl);
1654 /*** ISAXLocator methods ***/
1655 static HRESULT WINAPI isaxlocator_getColumnNumber(
1659 saxlocator *This = impl_from_ISAXLocator( iface );
1661 *pnColumn = This->column;
1665 static HRESULT WINAPI isaxlocator_getLineNumber(
1669 saxlocator *This = impl_from_ISAXLocator( iface );
1671 *pnLine = This->line;
1675 static HRESULT WINAPI isaxlocator_getPublicId(
1677 const WCHAR ** ppwchPublicId)
1680 saxlocator *This = impl_from_ISAXLocator( iface );
1682 SysFreeString(This->publicId);
1684 publicId = bstr_from_xmlChar(xmlSAX2GetPublicId(This->pParserCtxt));
1685 if(SysStringLen(publicId))
1686 This->publicId = (WCHAR*)&publicId;
1689 SysFreeString(publicId);
1690 This->publicId = NULL;
1693 *ppwchPublicId = This->publicId;
1697 static HRESULT WINAPI isaxlocator_getSystemId(
1699 const WCHAR ** ppwchSystemId)
1702 saxlocator *This = impl_from_ISAXLocator( iface );
1704 SysFreeString(This->systemId);
1706 systemId = bstr_from_xmlChar(xmlSAX2GetSystemId(This->pParserCtxt));
1707 if(SysStringLen(systemId))
1708 This->systemId = (WCHAR*)&systemId;
1711 SysFreeString(systemId);
1712 This->systemId = NULL;
1715 *ppwchSystemId = This->systemId;
1719 static const struct ISAXLocatorVtbl isaxlocator_vtbl =
1721 isaxlocator_QueryInterface,
1723 isaxlocator_Release,
1724 isaxlocator_getColumnNumber,
1725 isaxlocator_getLineNumber,
1726 isaxlocator_getPublicId,
1727 isaxlocator_getSystemId
1730 static HRESULT SAXLocator_create(saxreader *reader, saxlocator **ppsaxlocator, BOOL vbInterface)
1732 saxlocator *locator;
1734 locator = heap_alloc( sizeof (*locator) );
1736 return E_OUTOFMEMORY;
1738 locator->lpVBSAXLocatorVtbl = &ivbsaxlocator_vtbl;
1739 locator->lpSAXLocatorVtbl = &isaxlocator_vtbl;
1741 locator->vbInterface = vbInterface;
1743 locator->saxreader = reader;
1744 ISAXXMLReader_AddRef((ISAXXMLReader*)&reader->lpSAXXMLReaderVtbl);
1746 locator->pParserCtxt = NULL;
1747 locator->publicId = NULL;
1748 locator->systemId = NULL;
1749 locator->lastCur = NULL;
1751 locator->column = 0;
1752 locator->ret = S_OK;
1753 locator->nsStackSize = 8;
1754 locator->nsStackLast = 0;
1755 locator->nsStack = heap_alloc(sizeof(int)*locator->nsStackSize);
1756 if(!locator->nsStack)
1758 ISAXXMLReader_Release((ISAXXMLReader*)&reader->lpSAXXMLReaderVtbl);
1760 return E_OUTOFMEMORY;
1763 *ppsaxlocator = locator;
1765 TRACE("returning %p\n", *ppsaxlocator);
1770 /*** SAXXMLReader internal functions ***/
1771 static HRESULT internal_parseBuffer(saxreader *This, const char *buffer, int size, BOOL vbInterface)
1773 xmlCharEncoding encoding = XML_CHAR_ENCODING_NONE;
1774 xmlChar *enc_name = NULL;
1775 saxlocator *locator;
1778 hr = SAXLocator_create(This, &locator, vbInterface);
1784 const unsigned char *buff = (unsigned char*)buffer;
1786 encoding = xmlDetectCharEncoding((xmlChar*)buffer, 4);
1787 enc_name = (xmlChar*)xmlGetCharEncodingName(encoding);
1788 TRACE("detected encoding: %s\n", enc_name);
1789 /* skip BOM, parser won't switch encodings and so won't skip it on its own */
1790 if ((encoding == XML_CHAR_ENCODING_UTF8) &&
1791 buff[0] == 0xEF && buff[1] == 0xBB && buff[2] == 0xBF)
1798 locator->pParserCtxt = xmlCreateMemoryParserCtxt(buffer, size);
1799 if(!locator->pParserCtxt)
1801 ISAXLocator_Release((ISAXLocator*)&locator->lpSAXLocatorVtbl);
1805 if (encoding == XML_CHAR_ENCODING_UTF8)
1806 locator->pParserCtxt->encoding = xmlStrdup(enc_name);
1808 xmlFree(locator->pParserCtxt->sax);
1809 locator->pParserCtxt->sax = &locator->saxreader->sax;
1810 locator->pParserCtxt->userData = locator;
1812 This->isParsing = TRUE;
1813 if(xmlParseDocument(locator->pParserCtxt) == -1) hr = E_FAIL;
1814 else hr = locator->ret;
1815 This->isParsing = FALSE;
1817 if(locator->pParserCtxt)
1819 locator->pParserCtxt->sax = NULL;
1820 xmlFreeParserCtxt(locator->pParserCtxt);
1821 locator->pParserCtxt = NULL;
1824 ISAXLocator_Release((ISAXLocator*)&locator->lpSAXLocatorVtbl);
1828 static HRESULT internal_parseStream(saxreader *This, IStream *stream, BOOL vbInterface)
1830 saxlocator *locator;
1835 hr = IStream_Read(stream, data, sizeof(data), &dataRead);
1839 hr = SAXLocator_create(This, &locator, vbInterface);
1843 locator->pParserCtxt = xmlCreatePushParserCtxt(
1844 &locator->saxreader->sax, locator,
1845 data, dataRead, NULL);
1846 if(!locator->pParserCtxt)
1848 ISAXLocator_Release((ISAXLocator*)&locator->lpSAXLocatorVtbl);
1852 This->isParsing = TRUE;
1855 hr = IStream_Read(stream, data, sizeof(data), &dataRead);
1859 if(xmlParseChunk(locator->pParserCtxt, data, dataRead, 0)) hr = E_FAIL;
1860 else hr = locator->ret;
1862 if(hr != S_OK) break;
1864 if(dataRead != sizeof(data))
1866 if(xmlParseChunk(locator->pParserCtxt, data, 0, 1)) hr = E_FAIL;
1867 else hr = locator->ret;
1872 This->isParsing = FALSE;
1874 xmlFreeParserCtxt(locator->pParserCtxt);
1875 locator->pParserCtxt = NULL;
1876 ISAXLocator_Release((ISAXLocator*)&locator->lpSAXLocatorVtbl);
1880 static HRESULT internal_getEntityResolver(
1882 void *pEntityResolver,
1885 FIXME("(%p)->(%p) stub\n", This, pEntityResolver);
1889 static HRESULT internal_putEntityResolver(
1891 void *pEntityResolver,
1894 FIXME("(%p)->(%p) stub\n", This, pEntityResolver);
1898 static HRESULT internal_getContentHandler(
1900 void *pContentHandler,
1903 TRACE("(%p)->(%p)\n", This, pContentHandler);
1904 if(pContentHandler == NULL)
1906 if((vbInterface && This->vbcontentHandler)
1907 || (!vbInterface && This->contentHandler))
1910 IVBSAXContentHandler_AddRef(This->vbcontentHandler);
1912 ISAXContentHandler_AddRef(This->contentHandler);
1914 if(vbInterface) *(IVBSAXContentHandler**)pContentHandler =
1915 This->vbcontentHandler;
1916 else *(ISAXContentHandler**)pContentHandler = This->contentHandler;
1921 static HRESULT internal_putContentHandler(
1923 void *contentHandler,
1926 TRACE("(%p)->(%p)\n", This, contentHandler);
1930 IVBSAXContentHandler_AddRef((IVBSAXContentHandler*)contentHandler);
1932 ISAXContentHandler_AddRef((ISAXContentHandler*)contentHandler);
1934 if((vbInterface && This->vbcontentHandler)
1935 || (!vbInterface && This->contentHandler))
1938 IVBSAXContentHandler_Release(This->vbcontentHandler);
1940 ISAXContentHandler_Release(This->contentHandler);
1943 This->vbcontentHandler = contentHandler;
1945 This->contentHandler = contentHandler;
1950 static HRESULT internal_getDTDHandler(
1955 FIXME("(%p)->(%p) stub\n", This, pDTDHandler);
1959 static HRESULT internal_putDTDHandler(
1964 FIXME("(%p)->(%p) stub\n", This, pDTDHandler);
1968 static HRESULT internal_getErrorHandler(
1970 void *pErrorHandler,
1973 TRACE("(%p)->(%p)\n", This, pErrorHandler);
1974 if(pErrorHandler == NULL)
1977 if(vbInterface && This->vberrorHandler)
1978 IVBSAXErrorHandler_AddRef(This->vberrorHandler);
1979 else if(!vbInterface && This->errorHandler)
1980 ISAXErrorHandler_AddRef(This->errorHandler);
1983 *(IVBSAXErrorHandler**)pErrorHandler = This->vberrorHandler;
1985 *(ISAXErrorHandler**)pErrorHandler = This->errorHandler;
1991 static HRESULT internal_putErrorHandler(
1996 TRACE("(%p)->(%p)\n", This, errorHandler);
2000 IVBSAXErrorHandler_AddRef((IVBSAXErrorHandler*)errorHandler);
2002 ISAXErrorHandler_AddRef((ISAXErrorHandler*)errorHandler);
2005 if(vbInterface && This->vberrorHandler)
2006 IVBSAXErrorHandler_Release(This->vberrorHandler);
2007 else if(!vbInterface && This->errorHandler)
2008 ISAXErrorHandler_Release(This->errorHandler);
2011 This->vberrorHandler = errorHandler;
2013 This->errorHandler = errorHandler;
2019 static HRESULT internal_parse(
2026 TRACE("(%p)\n", This);
2029 switch(V_VT(&varInput))
2032 hr = internal_parseBuffer(This, (const char*)V_BSTR(&varInput),
2033 SysStringByteLen(V_BSTR(&varInput)), vbInterface);
2035 case VT_ARRAY|VT_UI1: {
2037 LONG lBound, uBound;
2040 hr = SafeArrayGetLBound(V_ARRAY(&varInput), 1, &lBound);
2041 if(hr != S_OK) break;
2042 hr = SafeArrayGetUBound(V_ARRAY(&varInput), 1, &uBound);
2043 if(hr != S_OK) break;
2044 dataRead = (uBound-lBound)*SafeArrayGetElemsize(V_ARRAY(&varInput));
2045 hr = SafeArrayAccessData(V_ARRAY(&varInput), &pSAData);
2046 if(hr != S_OK) break;
2047 hr = internal_parseBuffer(This, pSAData, dataRead, vbInterface);
2048 SafeArrayUnaccessData(V_ARRAY(&varInput));
2053 IPersistStream *persistStream;
2054 IStream *stream = NULL;
2055 IXMLDOMDocument *xmlDoc;
2057 if(IUnknown_QueryInterface(V_UNKNOWN(&varInput),
2058 &IID_IXMLDOMDocument, (void**)&xmlDoc) == S_OK)
2062 IXMLDOMDocument_get_xml(xmlDoc, &bstrData);
2063 hr = internal_parseBuffer(This, (const char*)bstrData,
2064 SysStringByteLen(bstrData), vbInterface);
2065 IXMLDOMDocument_Release(xmlDoc);
2066 SysFreeString(bstrData);
2070 if(IUnknown_QueryInterface(V_UNKNOWN(&varInput),
2071 &IID_IPersistStream, (void**)&persistStream) == S_OK)
2073 hr = CreateStreamOnHGlobal(NULL, TRUE, &stream);
2076 IPersistStream_Release(persistStream);
2080 hr = IPersistStream_Save(persistStream, stream, TRUE);
2081 IPersistStream_Release(persistStream);
2084 IStream_Release(stream);
2088 if(stream || IUnknown_QueryInterface(V_UNKNOWN(&varInput),
2089 &IID_IStream, (void**)&stream) == S_OK)
2091 hr = internal_parseStream(This, stream, vbInterface);
2092 IStream_Release(stream);
2097 WARN("vt %d not implemented\n", V_VT(&varInput));
2104 static HRESULT internal_vbonDataAvailable(void *obj, char *ptr, DWORD len)
2106 saxreader *This = obj;
2108 return internal_parseBuffer(This, ptr, len, TRUE);
2111 static HRESULT internal_onDataAvailable(void *obj, char *ptr, DWORD len)
2113 saxreader *This = obj;
2115 return internal_parseBuffer(This, ptr, len, FALSE);
2118 static HRESULT internal_parseURL(
2126 TRACE("(%p)->(%s)\n", This, debugstr_w(url));
2128 if(vbInterface) hr = bind_url(url, internal_vbonDataAvailable, This, &bsc);
2129 else hr = bind_url(url, internal_onDataAvailable, This, &bsc);
2139 static HRESULT internal_putProperty(
2145 static const WCHAR wszCharset[] = {
2146 'c','h','a','r','s','e','t',0
2148 static const WCHAR wszDeclarationHandler[] = {
2149 'h','t','t','p',':','/','/','x','m','l','.','o','r','g','/',
2150 's','a','x','/','p','r','o','p','e','r','t','i','e','s','/',
2151 'd','e','c','l','a','r','a','t','i','o','n',
2152 '-','h','a','n','d','l','e','r',0
2154 static const WCHAR wszDomNode[] = {
2155 'h','t','t','p',':','/','/','x','m','l','.','o','r','g','/',
2156 's','a','x','/','p','r','o','p','e','r','t','i','e','s','/',
2157 'd','o','m','-','n','o','d','e',0
2159 static const WCHAR wszInputSource[] = {
2160 'i','n','p','u','t','-','s','o','u','r','c','e',0
2162 static const WCHAR wszLexicalHandler[] = {
2163 'h','t','t','p',':','/','/','x','m','l','.','o','r','g','/',
2164 's','a','x','/','p','r','o','p','e','r','t','i','e','s','/',
2165 'l','e','x','i','c','a','l','-','h','a','n','d','l','e','r',0
2167 static const WCHAR wszMaxElementDepth[] = {
2168 'm','a','x','-','e','l','e','m','e','n','t','-','d','e','p','t','h',0
2170 static const WCHAR wszMaxXMLSize[] = {
2171 'm','a','x','-','x','m','l','-','s','i','z','e',0
2173 static const WCHAR wszSchemaDeclarationHandler[] = {
2174 's','c','h','e','m','a','-',
2175 'd','e','c','l','a','r','a','t','i','o','n','-',
2176 'h','a','n','d','l','e','r',0
2178 static const WCHAR wszXMLDeclEncoding[] = {
2179 'x','m','l','d','e','c','l','-','e','n','c','o','d','i','n','g',0
2181 static const WCHAR wszXMLDeclStandalone[] = {
2182 'x','m','l','d','e','c','l',
2183 '-','s','t','a','n','d','a','l','o','n','e',0
2185 static const WCHAR wszXMLDeclVersion[] = {
2186 'x','m','l','d','e','c','l','-','v','e','r','s','i','o','n',0
2189 TRACE("(%p)->(%s)\n", This, debugstr_w(pProp));
2191 if(!memcmp(pProp, wszDeclarationHandler, sizeof(wszDeclarationHandler)))
2193 if(This->isParsing) return E_FAIL;
2195 if(V_UNKNOWN(&value))
2198 IVBSAXDeclHandler_AddRef((IVBSAXDeclHandler*)V_UNKNOWN(&value));
2200 ISAXDeclHandler_AddRef((ISAXDeclHandler*)V_UNKNOWN(&value));
2202 if((vbInterface && This->vbdeclHandler)
2203 || (!vbInterface && This->declHandler))
2206 IVBSAXDeclHandler_Release(This->vbdeclHandler);
2208 ISAXDeclHandler_Release(This->declHandler);
2211 This->vbdeclHandler = (IVBSAXDeclHandler*)V_UNKNOWN(&value);
2213 This->declHandler = (ISAXDeclHandler*)V_UNKNOWN(&value);
2217 if(!memcmp(pProp, wszLexicalHandler, sizeof(wszLexicalHandler)))
2219 if(This->isParsing) return E_FAIL;
2221 if(V_UNKNOWN(&value))
2224 IVBSAXLexicalHandler_AddRef(
2225 (IVBSAXLexicalHandler*)V_UNKNOWN(&value));
2227 ISAXLexicalHandler_AddRef(
2228 (ISAXLexicalHandler*)V_UNKNOWN(&value));
2230 if((vbInterface && This->vblexicalHandler)
2231 || (!vbInterface && This->lexicalHandler))
2234 IVBSAXLexicalHandler_Release(This->vblexicalHandler);
2236 ISAXLexicalHandler_Release(This->lexicalHandler);
2239 This->vblexicalHandler = (IVBSAXLexicalHandler*)V_UNKNOWN(&value);
2241 This->lexicalHandler = (ISAXLexicalHandler*)V_UNKNOWN(&value);
2245 FIXME("(%p)->(%s): unsupported property\n", This, debugstr_w(pProp));
2247 if(!memcmp(pProp, wszCharset, sizeof(wszCharset)))
2250 if(!memcmp(pProp, wszDomNode, sizeof(wszDomNode)))
2253 if(!memcmp(pProp, wszInputSource, sizeof(wszInputSource)))
2256 if(!memcmp(pProp, wszMaxElementDepth, sizeof(wszMaxElementDepth)))
2259 if(!memcmp(pProp, wszMaxXMLSize, sizeof(wszMaxXMLSize)))
2262 if(!memcmp(pProp, wszSchemaDeclarationHandler,
2263 sizeof(wszSchemaDeclarationHandler)))
2266 if(!memcmp(pProp, wszXMLDeclEncoding, sizeof(wszXMLDeclEncoding)))
2269 if(!memcmp(pProp, wszXMLDeclStandalone, sizeof(wszXMLDeclStandalone)))
2272 if(!memcmp(pProp, wszXMLDeclVersion, sizeof(wszXMLDeclVersion)))
2275 return E_INVALIDARG;
2278 /*** IVBSAXXMLReader interface ***/
2279 /*** IUnknown methods ***/
2280 static HRESULT WINAPI saxxmlreader_QueryInterface(IVBSAXXMLReader* iface, REFIID riid, void **ppvObject)
2282 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2284 TRACE("%p %s %p\n", This, debugstr_guid( riid ), ppvObject );
2288 if ( IsEqualGUID( riid, &IID_IUnknown ) ||
2289 IsEqualGUID( riid, &IID_IDispatch ) ||
2290 IsEqualGUID( riid, &IID_IVBSAXXMLReader ))
2294 else if( IsEqualGUID( riid, &IID_ISAXXMLReader ))
2296 *ppvObject = &This->lpSAXXMLReaderVtbl;
2300 FIXME("interface %s not implemented\n", debugstr_guid(riid));
2301 return E_NOINTERFACE;
2304 IVBSAXXMLReader_AddRef( iface );
2309 static ULONG WINAPI saxxmlreader_AddRef(IVBSAXXMLReader* iface)
2311 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2312 TRACE("%p\n", This );
2313 return InterlockedIncrement( &This->ref );
2316 static ULONG WINAPI saxxmlreader_Release(
2317 IVBSAXXMLReader* iface)
2319 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2322 TRACE("%p\n", This );
2324 ref = InterlockedDecrement( &This->ref );
2327 if(This->contentHandler)
2328 ISAXContentHandler_Release(This->contentHandler);
2330 if(This->vbcontentHandler)
2331 IVBSAXContentHandler_Release(This->vbcontentHandler);
2333 if(This->errorHandler)
2334 ISAXErrorHandler_Release(This->errorHandler);
2336 if(This->vberrorHandler)
2337 IVBSAXErrorHandler_Release(This->vberrorHandler);
2339 if(This->lexicalHandler)
2340 ISAXLexicalHandler_Release(This->lexicalHandler);
2342 if(This->vblexicalHandler)
2343 IVBSAXLexicalHandler_Release(This->vblexicalHandler);
2345 if(This->declHandler)
2346 ISAXDeclHandler_Release(This->declHandler);
2348 if(This->vbdeclHandler)
2349 IVBSAXDeclHandler_Release(This->vbdeclHandler);
2357 static HRESULT WINAPI saxxmlreader_GetTypeInfoCount( IVBSAXXMLReader *iface, UINT* pctinfo )
2359 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2361 TRACE("(%p)->(%p)\n", This, pctinfo);
2368 static HRESULT WINAPI saxxmlreader_GetTypeInfo(
2369 IVBSAXXMLReader *iface,
2370 UINT iTInfo, LCID lcid, ITypeInfo** ppTInfo )
2372 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2375 TRACE("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo);
2377 hr = get_typeinfo(IVBSAXXMLReader_tid, ppTInfo);
2382 static HRESULT WINAPI saxxmlreader_GetIDsOfNames(
2383 IVBSAXXMLReader *iface,
2385 LPOLESTR* rgszNames,
2390 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2391 ITypeInfo *typeinfo;
2394 TRACE("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames, cNames,
2397 if(!rgszNames || cNames == 0 || !rgDispId)
2398 return E_INVALIDARG;
2400 hr = get_typeinfo(IVBSAXXMLReader_tid, &typeinfo);
2403 hr = ITypeInfo_GetIDsOfNames(typeinfo, rgszNames, cNames, rgDispId);
2404 ITypeInfo_Release(typeinfo);
2410 static HRESULT WINAPI saxxmlreader_Invoke(
2411 IVBSAXXMLReader *iface,
2412 DISPID dispIdMember,
2416 DISPPARAMS* pDispParams,
2417 VARIANT* pVarResult,
2418 EXCEPINFO* pExcepInfo,
2421 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2422 ITypeInfo *typeinfo;
2425 TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
2426 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
2428 hr = get_typeinfo(IVBSAXXMLReader_tid, &typeinfo);
2431 hr = ITypeInfo_Invoke(typeinfo, &(This->lpVBSAXXMLReaderVtbl), dispIdMember, wFlags, pDispParams,
2432 pVarResult, pExcepInfo, puArgErr);
2433 ITypeInfo_Release(typeinfo);
2439 /*** IVBSAXXMLReader methods ***/
2440 static HRESULT WINAPI saxxmlreader_getFeature(
2441 IVBSAXXMLReader* iface,
2442 const WCHAR *pFeature,
2443 VARIANT_BOOL *pValue)
2445 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2447 FIXME("(%p)->(%s %p) stub\n", This, debugstr_w(pFeature), pValue);
2451 static HRESULT WINAPI saxxmlreader_putFeature(
2452 IVBSAXXMLReader* iface,
2453 const WCHAR *pFeature,
2454 VARIANT_BOOL vfValue)
2456 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2458 FIXME("(%p)->(%s %x) stub\n", This, debugstr_w(pFeature), vfValue);
2462 static HRESULT WINAPI saxxmlreader_getProperty(
2463 IVBSAXXMLReader* iface,
2467 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2469 FIXME("(%p)->(%s %p) stub\n", This, debugstr_w(pProp), pValue);
2473 static HRESULT WINAPI saxxmlreader_putProperty(
2474 IVBSAXXMLReader* iface,
2478 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2479 return internal_putProperty(This, pProp, value, TRUE);
2482 static HRESULT WINAPI saxxmlreader_get_entityResolver(
2483 IVBSAXXMLReader* iface,
2484 IVBSAXEntityResolver **pEntityResolver)
2486 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2487 return internal_getEntityResolver(This, pEntityResolver, TRUE);
2490 static HRESULT WINAPI saxxmlreader_put_entityResolver(
2491 IVBSAXXMLReader* iface,
2492 IVBSAXEntityResolver *pEntityResolver)
2494 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2495 return internal_putEntityResolver(This, pEntityResolver, TRUE);
2498 static HRESULT WINAPI saxxmlreader_get_contentHandler(
2499 IVBSAXXMLReader* iface,
2500 IVBSAXContentHandler **ppContentHandler)
2502 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2503 return internal_getContentHandler(This, ppContentHandler, TRUE);
2506 static HRESULT WINAPI saxxmlreader_put_contentHandler(
2507 IVBSAXXMLReader* iface,
2508 IVBSAXContentHandler *contentHandler)
2510 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2511 return internal_putContentHandler(This, contentHandler, TRUE);
2514 static HRESULT WINAPI saxxmlreader_get_dtdHandler(
2515 IVBSAXXMLReader* iface,
2516 IVBSAXDTDHandler **pDTDHandler)
2518 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2519 return internal_getDTDHandler(This, pDTDHandler, TRUE);
2522 static HRESULT WINAPI saxxmlreader_put_dtdHandler(
2523 IVBSAXXMLReader* iface,
2524 IVBSAXDTDHandler *pDTDHandler)
2526 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2527 return internal_putDTDHandler(This, pDTDHandler, TRUE);
2530 static HRESULT WINAPI saxxmlreader_get_errorHandler(
2531 IVBSAXXMLReader* iface,
2532 IVBSAXErrorHandler **pErrorHandler)
2534 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2535 return internal_getErrorHandler(This, pErrorHandler, TRUE);
2538 static HRESULT WINAPI saxxmlreader_put_errorHandler(
2539 IVBSAXXMLReader* iface,
2540 IVBSAXErrorHandler *errorHandler)
2542 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2543 return internal_putErrorHandler(This, errorHandler, TRUE);
2546 static HRESULT WINAPI saxxmlreader_get_baseURL(
2547 IVBSAXXMLReader* iface,
2548 const WCHAR **pBaseUrl)
2550 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2552 FIXME("(%p)->(%p) stub\n", This, pBaseUrl);
2556 static HRESULT WINAPI saxxmlreader_put_baseURL(
2557 IVBSAXXMLReader* iface,
2558 const WCHAR *pBaseUrl)
2560 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2562 FIXME("(%p)->(%s) stub\n", This, debugstr_w(pBaseUrl));
2566 static HRESULT WINAPI saxxmlreader_get_secureBaseURL(
2567 IVBSAXXMLReader* iface,
2568 const WCHAR **pSecureBaseUrl)
2570 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2572 FIXME("(%p)->(%p) stub\n", This, pSecureBaseUrl);
2577 static HRESULT WINAPI saxxmlreader_put_secureBaseURL(
2578 IVBSAXXMLReader* iface,
2579 const WCHAR *secureBaseUrl)
2581 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2583 FIXME("(%p)->(%s) stub\n", This, debugstr_w(secureBaseUrl));
2587 static HRESULT WINAPI saxxmlreader_parse(
2588 IVBSAXXMLReader* iface,
2591 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2592 return internal_parse(This, varInput, TRUE);
2595 static HRESULT WINAPI saxxmlreader_parseURL(
2596 IVBSAXXMLReader* iface,
2599 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2600 return internal_parseURL(This, url, TRUE);
2603 static const struct IVBSAXXMLReaderVtbl saxreader_vtbl =
2605 saxxmlreader_QueryInterface,
2606 saxxmlreader_AddRef,
2607 saxxmlreader_Release,
2608 saxxmlreader_GetTypeInfoCount,
2609 saxxmlreader_GetTypeInfo,
2610 saxxmlreader_GetIDsOfNames,
2611 saxxmlreader_Invoke,
2612 saxxmlreader_getFeature,
2613 saxxmlreader_putFeature,
2614 saxxmlreader_getProperty,
2615 saxxmlreader_putProperty,
2616 saxxmlreader_get_entityResolver,
2617 saxxmlreader_put_entityResolver,
2618 saxxmlreader_get_contentHandler,
2619 saxxmlreader_put_contentHandler,
2620 saxxmlreader_get_dtdHandler,
2621 saxxmlreader_put_dtdHandler,
2622 saxxmlreader_get_errorHandler,
2623 saxxmlreader_put_errorHandler,
2624 saxxmlreader_get_baseURL,
2625 saxxmlreader_put_baseURL,
2626 saxxmlreader_get_secureBaseURL,
2627 saxxmlreader_put_secureBaseURL,
2629 saxxmlreader_parseURL
2632 /*** ISAXXMLReader interface ***/
2633 /*** IUnknown methods ***/
2634 static HRESULT WINAPI isaxxmlreader_QueryInterface(ISAXXMLReader* iface, REFIID riid, void **ppvObject)
2636 saxreader *This = impl_from_ISAXXMLReader( iface );
2637 return saxxmlreader_QueryInterface((IVBSAXXMLReader*)&This->lpVBSAXXMLReaderVtbl, riid, ppvObject);
2640 static ULONG WINAPI isaxxmlreader_AddRef(ISAXXMLReader* iface)
2642 saxreader *This = impl_from_ISAXXMLReader( iface );
2643 return saxxmlreader_AddRef((IVBSAXXMLReader*)&This->lpVBSAXXMLReaderVtbl);
2646 static ULONG WINAPI isaxxmlreader_Release(ISAXXMLReader* iface)
2648 saxreader *This = impl_from_ISAXXMLReader( iface );
2649 return saxxmlreader_Release((IVBSAXXMLReader*)&This->lpVBSAXXMLReaderVtbl);
2652 /*** ISAXXMLReader methods ***/
2653 static HRESULT WINAPI isaxxmlreader_getFeature(
2654 ISAXXMLReader* iface,
2655 const WCHAR *pFeature,
2656 VARIANT_BOOL *pValue)
2658 saxreader *This = impl_from_ISAXXMLReader( iface );
2659 return IVBSAXXMLReader_getFeature(
2660 (IVBSAXXMLReader*)&This->lpVBSAXXMLReaderVtbl,
2664 static HRESULT WINAPI isaxxmlreader_putFeature(
2665 ISAXXMLReader* iface,
2666 const WCHAR *pFeature,
2667 VARIANT_BOOL vfValue)
2669 saxreader *This = impl_from_ISAXXMLReader( iface );
2670 return IVBSAXXMLReader_putFeature(
2671 (IVBSAXXMLReader*)&This->lpVBSAXXMLReaderVtbl,
2675 static HRESULT WINAPI isaxxmlreader_getProperty(
2676 ISAXXMLReader* iface,
2680 saxreader *This = impl_from_ISAXXMLReader( iface );
2681 return IVBSAXXMLReader_getProperty(
2682 (IVBSAXXMLReader*)&This->lpVBSAXXMLReaderVtbl,
2686 static HRESULT WINAPI isaxxmlreader_putProperty(
2687 ISAXXMLReader* iface,
2691 saxreader *This = impl_from_ISAXXMLReader( iface );
2692 return internal_putProperty(This, pProp, value, FALSE);
2695 static HRESULT WINAPI isaxxmlreader_getEntityResolver(
2696 ISAXXMLReader* iface,
2697 ISAXEntityResolver **ppEntityResolver)
2699 saxreader *This = impl_from_ISAXXMLReader( iface );
2700 return internal_getEntityResolver(This, ppEntityResolver, FALSE);
2703 static HRESULT WINAPI isaxxmlreader_putEntityResolver(
2704 ISAXXMLReader* iface,
2705 ISAXEntityResolver *pEntityResolver)
2707 saxreader *This = impl_from_ISAXXMLReader( iface );
2708 return internal_putEntityResolver(This, pEntityResolver, FALSE);
2711 static HRESULT WINAPI isaxxmlreader_getContentHandler(
2712 ISAXXMLReader* iface,
2713 ISAXContentHandler **pContentHandler)
2715 saxreader *This = impl_from_ISAXXMLReader( iface );
2716 return internal_getContentHandler(This, pContentHandler, FALSE);
2719 static HRESULT WINAPI isaxxmlreader_putContentHandler(
2720 ISAXXMLReader* iface,
2721 ISAXContentHandler *contentHandler)
2723 saxreader *This = impl_from_ISAXXMLReader( iface );
2724 return internal_putContentHandler(This, contentHandler, FALSE);
2727 static HRESULT WINAPI isaxxmlreader_getDTDHandler(
2728 ISAXXMLReader* iface,
2729 ISAXDTDHandler **pDTDHandler)
2731 saxreader *This = impl_from_ISAXXMLReader( iface );
2732 return internal_getDTDHandler(This, pDTDHandler, FALSE);
2735 static HRESULT WINAPI isaxxmlreader_putDTDHandler(
2736 ISAXXMLReader* iface,
2737 ISAXDTDHandler *pDTDHandler)
2739 saxreader *This = impl_from_ISAXXMLReader( iface );
2740 return internal_putDTDHandler(This, pDTDHandler, FALSE);
2743 static HRESULT WINAPI isaxxmlreader_getErrorHandler(
2744 ISAXXMLReader* iface,
2745 ISAXErrorHandler **pErrorHandler)
2747 saxreader *This = impl_from_ISAXXMLReader( iface );
2748 return internal_getErrorHandler(This, pErrorHandler, FALSE);
2751 static HRESULT WINAPI isaxxmlreader_putErrorHandler(
2752 ISAXXMLReader* iface,
2753 ISAXErrorHandler *errorHandler)
2755 saxreader *This = impl_from_ISAXXMLReader( iface );
2756 return internal_putErrorHandler(This, errorHandler, FALSE);
2759 static HRESULT WINAPI isaxxmlreader_getBaseURL(
2760 ISAXXMLReader* iface,
2761 const WCHAR **pBaseUrl)
2763 saxreader *This = impl_from_ISAXXMLReader( iface );
2764 return IVBSAXXMLReader_get_baseURL(
2765 (IVBSAXXMLReader*)&This->lpVBSAXXMLReaderVtbl,
2769 static HRESULT WINAPI isaxxmlreader_putBaseURL(
2770 ISAXXMLReader* iface,
2771 const WCHAR *pBaseUrl)
2773 saxreader *This = impl_from_ISAXXMLReader( iface );
2774 return IVBSAXXMLReader_put_baseURL(
2775 (IVBSAXXMLReader*)&This->lpVBSAXXMLReaderVtbl,
2779 static HRESULT WINAPI isaxxmlreader_getSecureBaseURL(
2780 ISAXXMLReader* iface,
2781 const WCHAR **pSecureBaseUrl)
2783 saxreader *This = impl_from_ISAXXMLReader( iface );
2784 return IVBSAXXMLReader_get_secureBaseURL(
2785 (IVBSAXXMLReader*)&This->lpVBSAXXMLReaderVtbl,
2789 static HRESULT WINAPI isaxxmlreader_putSecureBaseURL(
2790 ISAXXMLReader* iface,
2791 const WCHAR *secureBaseUrl)
2793 saxreader *This = impl_from_ISAXXMLReader( iface );
2794 return IVBSAXXMLReader_put_secureBaseURL(
2795 (IVBSAXXMLReader*)&This->lpVBSAXXMLReaderVtbl,
2799 static HRESULT WINAPI isaxxmlreader_parse(
2800 ISAXXMLReader* iface,
2803 saxreader *This = impl_from_ISAXXMLReader( iface );
2804 return internal_parse(This, varInput, FALSE);
2807 static HRESULT WINAPI isaxxmlreader_parseURL(
2808 ISAXXMLReader* iface,
2811 saxreader *This = impl_from_ISAXXMLReader( iface );
2812 return internal_parseURL(This, url, FALSE);
2815 static const struct ISAXXMLReaderVtbl isaxreader_vtbl =
2817 isaxxmlreader_QueryInterface,
2818 isaxxmlreader_AddRef,
2819 isaxxmlreader_Release,
2820 isaxxmlreader_getFeature,
2821 isaxxmlreader_putFeature,
2822 isaxxmlreader_getProperty,
2823 isaxxmlreader_putProperty,
2824 isaxxmlreader_getEntityResolver,
2825 isaxxmlreader_putEntityResolver,
2826 isaxxmlreader_getContentHandler,
2827 isaxxmlreader_putContentHandler,
2828 isaxxmlreader_getDTDHandler,
2829 isaxxmlreader_putDTDHandler,
2830 isaxxmlreader_getErrorHandler,
2831 isaxxmlreader_putErrorHandler,
2832 isaxxmlreader_getBaseURL,
2833 isaxxmlreader_putBaseURL,
2834 isaxxmlreader_getSecureBaseURL,
2835 isaxxmlreader_putSecureBaseURL,
2836 isaxxmlreader_parse,
2837 isaxxmlreader_parseURL
2840 HRESULT SAXXMLReader_create(IUnknown *pUnkOuter, LPVOID *ppObj)
2844 TRACE("(%p,%p)\n", pUnkOuter, ppObj);
2846 reader = heap_alloc( sizeof (*reader) );
2848 return E_OUTOFMEMORY;
2850 reader->lpVBSAXXMLReaderVtbl = &saxreader_vtbl;
2851 reader->lpSAXXMLReaderVtbl = &isaxreader_vtbl;
2853 reader->contentHandler = NULL;
2854 reader->vbcontentHandler = NULL;
2855 reader->errorHandler = NULL;
2856 reader->vberrorHandler = NULL;
2857 reader->lexicalHandler = NULL;
2858 reader->vblexicalHandler = NULL;
2859 reader->declHandler = NULL;
2860 reader->vbdeclHandler = NULL;
2861 reader->isParsing = FALSE;
2863 memset(&reader->sax, 0, sizeof(xmlSAXHandler));
2864 reader->sax.initialized = XML_SAX2_MAGIC;
2865 reader->sax.startDocument = libxmlStartDocument;
2866 reader->sax.endDocument = libxmlEndDocument;
2867 reader->sax.startElementNs = libxmlStartElementNS;
2868 reader->sax.endElementNs = libxmlEndElementNS;
2869 reader->sax.characters = libxmlCharacters;
2870 reader->sax.setDocumentLocator = libxmlSetDocumentLocator;
2871 reader->sax.comment = libxmlComment;
2872 reader->sax.error = libxmlFatalError;
2873 reader->sax.fatalError = libxmlFatalError;
2874 reader->sax.cdataBlock = libxmlCDataBlock;
2876 *ppObj = &reader->lpVBSAXXMLReaderVtbl;
2878 TRACE("returning iface %p\n", *ppObj);
2885 HRESULT SAXXMLReader_create(IUnknown *pUnkOuter, LPVOID *ppObj)
2887 MESSAGE("This program tried to use a SAX XML Reader object, but\n"
2888 "libxml2 support was not present at compile time.\n");