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 HRESULT namespacePush(saxlocator *locator, int ns)
137 if(locator->nsStackLast>=locator->nsStackSize)
141 new_stack = HeapReAlloc(GetProcessHeap(), 0,
142 locator->nsStack, locator->nsStackSize*2);
143 if(!new_stack) return E_OUTOFMEMORY;
144 locator->nsStack = new_stack;
145 locator->nsStackSize *= 2;
147 locator->nsStack[locator->nsStackLast++] = ns;
152 static int namespacePop(saxlocator *locator)
154 if(locator->nsStackLast == 0) return 0;
155 return locator->nsStack[--locator->nsStackLast];
158 static BSTR bstr_from_xmlCharN(const xmlChar *buf, int len)
167 dLen = MultiByteToWideChar(CP_UTF8, 0, (LPCSTR)buf, len, NULL, 0);
168 if(len != -1) dLen++;
169 str = heap_alloc(dLen * sizeof (WCHAR));
172 MultiByteToWideChar(CP_UTF8, 0, (LPCSTR)buf, len, str, dLen);
173 if(len != -1) str[dLen-1] = '\0';
174 bstr = SysAllocString(str);
180 static BSTR QName_from_xmlChar(const xmlChar *prefix, const xmlChar *name)
186 if(!name) return NULL;
188 if(!prefix || *prefix=='\0')
189 return bstr_from_xmlChar(name);
191 dLen = MultiByteToWideChar(CP_UTF8, 0, (LPCSTR)prefix, -1, NULL, 0)
192 + MultiByteToWideChar(CP_UTF8, 0, (LPCSTR)name, -1, NULL, 0);
193 str = heap_alloc(dLen * sizeof(WCHAR));
197 dLast = MultiByteToWideChar(CP_UTF8, 0, (LPCSTR)prefix, -1, str, dLen);
199 MultiByteToWideChar(CP_UTF8, 0, (LPCSTR)name, -1, &str[dLast], dLen-dLast);
200 bstr = SysAllocString(str);
207 static void format_error_message_from_id(saxlocator *This, HRESULT hr)
209 xmlStopParser(This->pParserCtxt);
212 if((This->vbInterface && This->saxreader->vberrorHandler)
213 || (!This->vbInterface && This->saxreader->errorHandler))
216 if(!FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM,
217 NULL, hr, 0, msg, sizeof(msg), NULL))
219 FIXME("MSXML errors not yet supported.\n");
223 if(This->vbInterface)
225 BSTR bstrMsg = SysAllocString(msg);
226 IVBSAXErrorHandler_fatalError(This->saxreader->vberrorHandler,
227 (IVBSAXLocator*)&This->lpVBSAXLocatorVtbl, &bstrMsg, hr);
230 ISAXErrorHandler_fatalError(This->saxreader->errorHandler,
231 (ISAXLocator*)&This->lpSAXLocatorVtbl, msg, hr);
235 static void update_position(saxlocator *This, xmlChar *end)
237 if(This->lastCur == NULL)
239 This->lastCur = (xmlChar*)This->pParserCtxt->input->base;
241 This->realColumn = 1;
243 else if(This->lastCur < This->pParserCtxt->input->base)
245 This->lastCur = (xmlChar*)This->pParserCtxt->input->base;
247 This->realColumn = 1;
250 if(This->pParserCtxt->input->cur<This->lastCur)
252 This->lastCur = (xmlChar*)This->pParserCtxt->input->base;
254 This->realColumn = 1;
257 if(!end) end = (xmlChar*)This->pParserCtxt->input->cur;
259 while(This->lastCur < end)
261 if(*(This->lastCur) == '\n')
264 This->realColumn = 1;
266 else if(*(This->lastCur) == '\r' &&
267 (This->lastCur==This->pParserCtxt->input->end ||
268 *(This->lastCur+1)!='\n'))
271 This->realColumn = 1;
273 else This->realColumn++;
277 /* Count multibyte UTF8 encoded characters once */
278 while((*(This->lastCur)&0xC0) == 0x80) This->lastCur++;
281 This->line = This->realLine;
282 This->column = This->realColumn;
285 /*** IVBSAXAttributes interface ***/
286 /*** IUnknown methods ***/
287 static HRESULT WINAPI ivbsaxattributes_QueryInterface(
288 IVBSAXAttributes* iface,
292 saxattributes *This = impl_from_IVBSAXAttributes(iface);
294 TRACE("%p %s %p\n", This, debugstr_guid(riid), ppvObject);
298 if (IsEqualGUID(riid, &IID_IUnknown) ||
299 IsEqualGUID(riid, &IID_IDispatch) ||
300 IsEqualGUID(riid, &IID_IVBSAXAttributes))
306 FIXME("interface %s not implemented\n", debugstr_guid(riid));
307 return E_NOINTERFACE;
310 IVBSAXAttributes_AddRef(iface);
315 static ULONG WINAPI ivbsaxattributes_AddRef(IVBSAXAttributes* iface)
317 saxattributes *This = impl_from_IVBSAXAttributes(iface);
318 return ISAXAttributes_AddRef((ISAXAttributes*)&This->lpSAXAttributesVtbl);
321 static ULONG WINAPI ivbsaxattributes_Release(IVBSAXAttributes* iface)
323 saxattributes *This = impl_from_IVBSAXAttributes(iface);
324 return ISAXAttributes_Release((ISAXAttributes*)&This->lpSAXAttributesVtbl);
327 /*** IDispatch methods ***/
328 static HRESULT WINAPI ivbsaxattributes_GetTypeInfoCount( IVBSAXAttributes *iface, UINT* pctinfo )
330 saxattributes *This = impl_from_IVBSAXAttributes( iface );
332 TRACE("(%p)->(%p)\n", This, pctinfo);
339 static HRESULT WINAPI ivbsaxattributes_GetTypeInfo(
340 IVBSAXAttributes *iface,
341 UINT iTInfo, LCID lcid, ITypeInfo** ppTInfo )
343 saxattributes *This = impl_from_IVBSAXAttributes( iface );
346 TRACE("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo);
348 hr = get_typeinfo(IVBSAXAttributes_tid, ppTInfo);
353 static HRESULT WINAPI ivbsaxattributes_GetIDsOfNames(
354 IVBSAXAttributes *iface,
361 saxattributes *This = impl_from_IVBSAXAttributes( iface );
365 TRACE("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames, cNames,
368 if(!rgszNames || cNames == 0 || !rgDispId)
371 hr = get_typeinfo(IVBSAXAttributes_tid, &typeinfo);
374 hr = ITypeInfo_GetIDsOfNames(typeinfo, rgszNames, cNames, rgDispId);
375 ITypeInfo_Release(typeinfo);
381 static HRESULT WINAPI ivbsaxattributes_Invoke(
382 IVBSAXAttributes *iface,
387 DISPPARAMS* pDispParams,
389 EXCEPINFO* pExcepInfo,
392 saxattributes *This = impl_from_IVBSAXAttributes( iface );
396 TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
397 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
399 hr = get_typeinfo(IVBSAXAttributes_tid, &typeinfo);
402 hr = ITypeInfo_Invoke(typeinfo, &(This->lpVBSAXAttributesVtbl), dispIdMember, wFlags, pDispParams,
403 pVarResult, pExcepInfo, puArgErr);
404 ITypeInfo_Release(typeinfo);
410 /*** IVBSAXAttributes methods ***/
411 static HRESULT WINAPI ivbsaxattributes_get_length(
412 IVBSAXAttributes* iface,
415 saxattributes *This = impl_from_IVBSAXAttributes( iface );
416 return ISAXAttributes_getLength(
417 (ISAXAttributes*)&This->lpSAXAttributesVtbl,
421 static HRESULT WINAPI ivbsaxattributes_getURI(
422 IVBSAXAttributes* iface,
427 saxattributes *This = impl_from_IVBSAXAttributes( iface );
428 return ISAXAttributes_getURI(
429 (ISAXAttributes*)&This->lpSAXAttributesVtbl,
430 nIndex, (const WCHAR**)uri, &len);
433 static HRESULT WINAPI ivbsaxattributes_getLocalName(
434 IVBSAXAttributes* iface,
439 saxattributes *This = impl_from_IVBSAXAttributes( iface );
440 return ISAXAttributes_getLocalName(
441 (ISAXAttributes*)&This->lpSAXAttributesVtbl,
442 nIndex, (const WCHAR**)localName, &len);
445 static HRESULT WINAPI ivbsaxattributes_getQName(
446 IVBSAXAttributes* iface,
451 saxattributes *This = impl_from_IVBSAXAttributes( iface );
452 return ISAXAttributes_getQName(
453 (ISAXAttributes*)&This->lpSAXAttributesVtbl,
454 nIndex, (const WCHAR**)QName, &len);
457 static HRESULT WINAPI ivbsaxattributes_getIndexFromName(
458 IVBSAXAttributes* iface,
463 saxattributes *This = impl_from_IVBSAXAttributes( iface );
464 return ISAXAttributes_getIndexFromName(
465 (ISAXAttributes*)&This->lpSAXAttributesVtbl, uri, SysStringLen(uri),
466 localName, SysStringLen(localName), index);
469 static HRESULT WINAPI ivbsaxattributes_getIndexFromQName(
470 IVBSAXAttributes* iface,
474 saxattributes *This = impl_from_IVBSAXAttributes( iface );
475 return ISAXAttributes_getIndexFromQName(
476 (ISAXAttributes*)&This->lpSAXAttributesVtbl, QName,
477 SysStringLen(QName), index);
480 static HRESULT WINAPI ivbsaxattributes_getType(
481 IVBSAXAttributes* iface,
486 saxattributes *This = impl_from_IVBSAXAttributes( iface );
487 return ISAXAttributes_getType(
488 (ISAXAttributes*)&This->lpSAXAttributesVtbl,
489 nIndex, (const WCHAR**)type, &len);
492 static HRESULT WINAPI ivbsaxattributes_getTypeFromName(
493 IVBSAXAttributes* iface,
499 saxattributes *This = impl_from_IVBSAXAttributes( iface );
500 return ISAXAttributes_getTypeFromName(
501 (ISAXAttributes*)&This->lpSAXAttributesVtbl, uri, SysStringLen(uri),
502 localName, SysStringLen(localName), (const WCHAR**)type, &len);
505 static HRESULT WINAPI ivbsaxattributes_getTypeFromQName(
506 IVBSAXAttributes* iface,
511 saxattributes *This = impl_from_IVBSAXAttributes( iface );
512 return ISAXAttributes_getTypeFromQName(
513 (ISAXAttributes*)&This->lpSAXAttributesVtbl, QName,
514 SysStringLen(QName), (const WCHAR**)type, &len);
517 static HRESULT WINAPI ivbsaxattributes_getValue(
518 IVBSAXAttributes* iface,
523 saxattributes *This = impl_from_IVBSAXAttributes( iface );
524 return ISAXAttributes_getValue(
525 (ISAXAttributes*)&This->lpSAXAttributesVtbl,
526 nIndex, (const WCHAR**)value, &len);
529 static HRESULT WINAPI ivbsaxattributes_getValueFromName(
530 IVBSAXAttributes* iface,
536 saxattributes *This = impl_from_IVBSAXAttributes( iface );
537 return ISAXAttributes_getValueFromName(
538 (ISAXAttributes*)&This->lpSAXAttributesVtbl, uri, SysStringLen(uri),
539 localName, SysStringLen(localName), (const WCHAR**)value, &len);
542 static HRESULT WINAPI ivbsaxattributes_getValueFromQName(
543 IVBSAXAttributes* iface,
548 saxattributes *This = impl_from_IVBSAXAttributes( iface );
549 return ISAXAttributes_getValueFromQName(
550 (ISAXAttributes*)&This->lpSAXAttributesVtbl, QName,
551 SysStringLen(QName), (const WCHAR**)value, &len);
554 static const struct IVBSAXAttributesVtbl ivbsaxattributes_vtbl =
556 ivbsaxattributes_QueryInterface,
557 ivbsaxattributes_AddRef,
558 ivbsaxattributes_Release,
559 ivbsaxattributes_GetTypeInfoCount,
560 ivbsaxattributes_GetTypeInfo,
561 ivbsaxattributes_GetIDsOfNames,
562 ivbsaxattributes_Invoke,
563 ivbsaxattributes_get_length,
564 ivbsaxattributes_getURI,
565 ivbsaxattributes_getLocalName,
566 ivbsaxattributes_getQName,
567 ivbsaxattributes_getIndexFromName,
568 ivbsaxattributes_getIndexFromQName,
569 ivbsaxattributes_getType,
570 ivbsaxattributes_getTypeFromName,
571 ivbsaxattributes_getTypeFromQName,
572 ivbsaxattributes_getValue,
573 ivbsaxattributes_getValueFromName,
574 ivbsaxattributes_getValueFromQName
577 /*** ISAXAttributes interface ***/
578 /*** IUnknown methods ***/
579 static HRESULT WINAPI isaxattributes_QueryInterface(
580 ISAXAttributes* iface,
584 saxattributes *This = impl_from_ISAXAttributes(iface);
586 TRACE("%p %s %p\n", This, debugstr_guid(riid), ppvObject);
590 if (IsEqualGUID(riid, &IID_IUnknown) ||
591 IsEqualGUID(riid, &IID_ISAXAttributes))
597 FIXME("interface %s not implemented\n", debugstr_guid(riid));
598 return E_NOINTERFACE;
601 ISAXAttributes_AddRef(iface);
606 static ULONG WINAPI isaxattributes_AddRef(ISAXAttributes* iface)
608 saxattributes *This = impl_from_ISAXAttributes(iface);
610 return InterlockedIncrement(&This->ref);
613 static ULONG WINAPI isaxattributes_Release(ISAXAttributes* iface)
615 saxattributes *This = impl_from_ISAXAttributes(iface);
620 ref = InterlockedDecrement(&This->ref);
624 for(index=0; index<This->nb_attributes; index++)
626 SysFreeString(This->szLocalname[index]);
627 SysFreeString(This->szURI[index]);
628 SysFreeString(This->szValue[index]);
629 SysFreeString(This->szQName[index]);
632 heap_free(This->szLocalname);
633 heap_free(This->szURI);
634 heap_free(This->szValue);
635 heap_free(This->szQName);
643 /*** ISAXAttributes methods ***/
644 static HRESULT WINAPI isaxattributes_getLength(
645 ISAXAttributes* iface,
648 saxattributes *This = impl_from_ISAXAttributes( iface );
650 *length = This->nb_attributes;
651 TRACE("Length set to %d\n", *length);
655 static HRESULT WINAPI isaxattributes_getURI(
656 ISAXAttributes* iface,
661 saxattributes *This = impl_from_ISAXAttributes( iface );
662 TRACE("(%p)->(%d)\n", This, nIndex);
664 if(nIndex>=This->nb_attributes || nIndex<0) return E_INVALIDARG;
665 if(!pUrl || !pUriSize) return E_POINTER;
667 *pUriSize = SysStringLen(This->szURI[nIndex]);
668 *pUrl = This->szURI[nIndex];
673 static HRESULT WINAPI isaxattributes_getLocalName(
674 ISAXAttributes* iface,
676 const WCHAR **pLocalName,
677 int *pLocalNameLength)
679 saxattributes *This = impl_from_ISAXAttributes( iface );
680 TRACE("(%p)->(%d)\n", This, nIndex);
682 if(nIndex>=This->nb_attributes || nIndex<0) return E_INVALIDARG;
683 if(!pLocalName || !pLocalNameLength) return E_POINTER;
685 *pLocalNameLength = SysStringLen(This->szLocalname[nIndex]);
686 *pLocalName = This->szLocalname[nIndex];
691 static HRESULT WINAPI isaxattributes_getQName(
692 ISAXAttributes* iface,
694 const WCHAR **pQName,
697 saxattributes *This = impl_from_ISAXAttributes( iface );
698 TRACE("(%p)->(%d)\n", This, nIndex);
700 if(nIndex>=This->nb_attributes || nIndex<0) return E_INVALIDARG;
701 if(!pQName || !pQNameLength) return E_POINTER;
703 *pQNameLength = SysStringLen(This->szQName[nIndex]);
704 *pQName = This->szQName[nIndex];
709 static HRESULT WINAPI isaxattributes_getName(
710 ISAXAttributes* iface,
714 const WCHAR **pLocalName,
716 const WCHAR **pQName,
719 saxattributes *This = impl_from_ISAXAttributes( iface );
720 TRACE("(%p)->(%d)\n", This, nIndex);
722 if(nIndex>=This->nb_attributes || nIndex<0) return E_INVALIDARG;
723 if(!pUri || !pUriLength || !pLocalName || !pLocalNameSize
724 || !pQName || !pQNameLength) return E_POINTER;
726 *pUriLength = SysStringLen(This->szURI[nIndex]);
727 *pUri = This->szURI[nIndex];
728 *pLocalNameSize = SysStringLen(This->szLocalname[nIndex]);
729 *pLocalName = This->szLocalname[nIndex];
730 *pQNameLength = SysStringLen(This->szQName[nIndex]);
731 *pQName = This->szQName[nIndex];
736 static HRESULT WINAPI isaxattributes_getIndexFromName(
737 ISAXAttributes* iface,
740 const WCHAR *pLocalName,
744 saxattributes *This = impl_from_ISAXAttributes( iface );
746 TRACE("(%p)->(%s, %d, %s, %d)\n", This, debugstr_w(pUri), cUriLength,
747 debugstr_w(pLocalName), cocalNameLength);
749 if(!pUri || !pLocalName || !index) return E_POINTER;
751 for(i=0; i<This->nb_attributes; i++)
753 if(cUriLength!=SysStringLen(This->szURI[i])
754 || cocalNameLength!=SysStringLen(This->szLocalname[i]))
756 if(cUriLength && memcmp(pUri, This->szURI[i],
757 sizeof(WCHAR)*cUriLength))
759 if(cocalNameLength && memcmp(pLocalName, This->szLocalname[i],
760 sizeof(WCHAR)*cocalNameLength))
770 static HRESULT WINAPI isaxattributes_getIndexFromQName(
771 ISAXAttributes* iface,
776 saxattributes *This = impl_from_ISAXAttributes( iface );
778 TRACE("(%p)->(%s, %d)\n", This, debugstr_w(pQName), nQNameLength);
780 if(!pQName || !index) return E_POINTER;
781 if(!nQNameLength) return E_INVALIDARG;
783 for(i=0; i<This->nb_attributes; i++)
785 if(nQNameLength!=SysStringLen(This->szQName[i])) continue;
786 if(memcmp(pQName, This->szQName, sizeof(WCHAR)*nQNameLength)) continue;
795 static HRESULT WINAPI isaxattributes_getType(
796 ISAXAttributes* iface,
801 saxattributes *This = impl_from_ISAXAttributes( iface );
803 FIXME("(%p)->(%d) stub\n", This, nIndex);
807 static HRESULT WINAPI isaxattributes_getTypeFromName(
808 ISAXAttributes* iface,
811 const WCHAR *pLocalName,
816 saxattributes *This = impl_from_ISAXAttributes( iface );
818 FIXME("(%p)->(%s, %d, %s, %d) stub\n", This, debugstr_w(pUri), nUri,
819 debugstr_w(pLocalName), nLocalName);
823 static HRESULT WINAPI isaxattributes_getTypeFromQName(
824 ISAXAttributes* iface,
830 saxattributes *This = impl_from_ISAXAttributes( iface );
832 FIXME("(%p)->(%s, %d) stub\n", This, debugstr_w(pQName), nQName);
836 static HRESULT WINAPI isaxattributes_getValue(
837 ISAXAttributes* iface,
839 const WCHAR **pValue,
842 saxattributes *This = impl_from_ISAXAttributes( iface );
843 TRACE("(%p)->(%d)\n", This, nIndex);
845 if(nIndex>=This->nb_attributes || nIndex<0) return E_INVALIDARG;
846 if(!pValue || !nValue) return E_POINTER;
848 *nValue = SysStringLen(This->szValue[nIndex]);
849 *pValue = This->szValue[nIndex];
854 static HRESULT WINAPI isaxattributes_getValueFromName(
855 ISAXAttributes* iface,
858 const WCHAR *pLocalName,
860 const WCHAR **pValue,
865 saxattributes *This = impl_from_ISAXAttributes( iface );
866 TRACE("(%p)->(%s, %d, %s, %d)\n", This, debugstr_w(pUri), nUri,
867 debugstr_w(pLocalName), nLocalName);
869 hr = ISAXAttributes_getIndexFromName(iface,
870 pUri, nUri, pLocalName, nLocalName, &index);
871 if(hr==S_OK) hr = ISAXAttributes_getValue(iface, index, pValue, nValue);
876 static HRESULT WINAPI isaxattributes_getValueFromQName(
877 ISAXAttributes* iface,
880 const WCHAR **pValue,
885 saxattributes *This = impl_from_ISAXAttributes( iface );
886 TRACE("(%p)->(%s, %d)\n", This, debugstr_w(pQName), nQName);
888 hr = ISAXAttributes_getIndexFromQName(iface, pQName, nQName, &index);
889 if(hr==S_OK) hr = ISAXAttributes_getValue(iface, index, pValue, nValue);
894 static const struct ISAXAttributesVtbl isaxattributes_vtbl =
896 isaxattributes_QueryInterface,
897 isaxattributes_AddRef,
898 isaxattributes_Release,
899 isaxattributes_getLength,
900 isaxattributes_getURI,
901 isaxattributes_getLocalName,
902 isaxattributes_getQName,
903 isaxattributes_getName,
904 isaxattributes_getIndexFromName,
905 isaxattributes_getIndexFromQName,
906 isaxattributes_getType,
907 isaxattributes_getTypeFromName,
908 isaxattributes_getTypeFromQName,
909 isaxattributes_getValue,
910 isaxattributes_getValueFromName,
911 isaxattributes_getValueFromQName
914 static HRESULT SAXAttributes_create(saxattributes **attr,
915 int nb_namespaces, const xmlChar **xmlNamespaces,
916 int nb_attributes, const xmlChar **xmlAttributes)
918 saxattributes *attributes;
920 static const xmlChar xmlns[] = "xmlns";
922 attributes = heap_alloc(sizeof(*attributes));
924 return E_OUTOFMEMORY;
926 attributes->lpVBSAXAttributesVtbl = &ivbsaxattributes_vtbl;
927 attributes->lpSAXAttributesVtbl = &isaxattributes_vtbl;
930 attributes->nb_attributes = nb_namespaces+nb_attributes;
932 attributes->szLocalname = heap_alloc(sizeof(BSTR)*attributes->nb_attributes);
933 attributes->szURI = heap_alloc(sizeof(BSTR)*attributes->nb_attributes);
934 attributes->szValue = heap_alloc(sizeof(BSTR)*attributes->nb_attributes);
935 attributes->szQName = heap_alloc(sizeof(BSTR)*attributes->nb_attributes);
937 if(!attributes->szLocalname || !attributes->szURI
938 || !attributes->szValue || !attributes->szQName)
940 heap_free(attributes->szLocalname);
941 heap_free(attributes->szURI);
942 heap_free(attributes->szValue);
943 heap_free(attributes->szQName);
944 heap_free(attributes);
948 for(index=0; index<nb_namespaces; index++)
950 attributes->szLocalname[index] = SysAllocStringLen(NULL, 0);
951 attributes->szURI[index] = SysAllocStringLen(NULL, 0);
952 attributes->szValue[index] = bstr_from_xmlChar(xmlNamespaces[2*index+1]);
953 attributes->szQName[index] = QName_from_xmlChar(xmlns, xmlNamespaces[2*index]);
956 for(index=0; index<nb_attributes; index++)
958 attributes->szLocalname[nb_namespaces+index] =
959 bstr_from_xmlChar(xmlAttributes[index*5]);
960 attributes->szURI[nb_namespaces+index] =
961 bstr_from_xmlChar(xmlAttributes[index*5+2]);
962 attributes->szValue[nb_namespaces+index] =
963 bstr_from_xmlCharN(xmlAttributes[index*5+3],
964 xmlAttributes[index*5+4]-xmlAttributes[index*5+3]);
965 attributes->szQName[nb_namespaces+index] =
966 QName_from_xmlChar(xmlAttributes[index*5+1], xmlAttributes[index*5]);
971 TRACE("returning %p\n", *attr);
976 /*** LibXML callbacks ***/
977 static void libxmlStartDocument(void *ctx)
979 saxlocator *This = ctx;
982 if(has_content_handler(This))
984 if(This->vbInterface)
985 hr = IVBSAXContentHandler_startDocument(This->saxreader->vbcontentHandler);
987 hr = ISAXContentHandler_startDocument(This->saxreader->contentHandler);
990 format_error_message_from_id(This, hr);
993 update_position(This, NULL);
996 static void libxmlEndDocument(void *ctx)
998 saxlocator *This = ctx;
1004 if(This->ret != S_OK) return;
1006 if(has_content_handler(This))
1008 if(This->vbInterface)
1009 hr = IVBSAXContentHandler_endDocument(This->saxreader->vbcontentHandler);
1011 hr = ISAXContentHandler_endDocument(This->saxreader->contentHandler);
1014 format_error_message_from_id(This, hr);
1018 static void libxmlStartElementNS(
1020 const xmlChar *localname,
1021 const xmlChar *prefix,
1024 const xmlChar **namespaces,
1027 const xmlChar **attributes)
1029 BSTR NamespaceUri, LocalName, QName, Prefix, Uri;
1030 saxlocator *This = ctx;
1032 saxattributes *attr;
1035 if(*(This->pParserCtxt->input->cur) == '/')
1036 update_position(This, (xmlChar*)This->pParserCtxt->input->cur+2);
1038 update_position(This, (xmlChar*)This->pParserCtxt->input->cur+1);
1040 hr = namespacePush(This, nb_namespaces);
1041 if(hr==S_OK && has_content_handler(This))
1043 for(index=0; index<nb_namespaces; index++)
1045 Prefix = bstr_from_xmlChar(namespaces[2*index]);
1046 Uri = bstr_from_xmlChar(namespaces[2*index+1]);
1048 if(This->vbInterface)
1049 hr = IVBSAXContentHandler_startPrefixMapping(
1050 This->saxreader->vbcontentHandler,
1053 hr = ISAXContentHandler_startPrefixMapping(
1054 This->saxreader->contentHandler,
1055 Prefix, SysStringLen(Prefix),
1056 Uri, SysStringLen(Uri));
1058 SysFreeString(Prefix);
1063 format_error_message_from_id(This, hr);
1068 NamespaceUri = bstr_from_xmlChar(URI);
1069 LocalName = bstr_from_xmlChar(localname);
1070 QName = QName_from_xmlChar(prefix, localname);
1072 hr = SAXAttributes_create(&attr, nb_namespaces, namespaces, nb_attributes, attributes);
1075 if(This->vbInterface)
1076 hr = IVBSAXContentHandler_startElement(
1077 This->saxreader->vbcontentHandler,
1078 &NamespaceUri, &LocalName, &QName,
1079 (IVBSAXAttributes*)&attr->lpVBSAXAttributesVtbl);
1081 hr = ISAXContentHandler_startElement(
1082 This->saxreader->contentHandler,
1083 NamespaceUri, SysStringLen(NamespaceUri),
1084 LocalName, SysStringLen(LocalName),
1085 QName, SysStringLen(QName),
1086 (ISAXAttributes*)&attr->lpSAXAttributesVtbl);
1088 ISAXAttributes_Release((ISAXAttributes*)&attr->lpSAXAttributesVtbl);
1091 SysFreeString(NamespaceUri);
1092 SysFreeString(LocalName);
1093 SysFreeString(QName);
1097 format_error_message_from_id(This, hr);
1100 static void libxmlEndElementNS(
1102 const xmlChar *localname,
1103 const xmlChar *prefix,
1106 BSTR NamespaceUri, LocalName, QName, Prefix;
1107 saxlocator *This = ctx;
1112 end = (xmlChar*)This->pParserCtxt->input->cur;
1113 if(*(end-1) != '>' || *(end-2) != '/')
1114 while(*(end-2)!='<' && *(end-1)!='/') end--;
1116 update_position(This, end);
1118 nsNr = namespacePop(This);
1120 if(has_content_handler(This))
1122 NamespaceUri = bstr_from_xmlChar(URI);
1123 LocalName = bstr_from_xmlChar(localname);
1124 QName = QName_from_xmlChar(prefix, localname);
1126 if(This->vbInterface)
1127 hr = IVBSAXContentHandler_endElement(
1128 This->saxreader->vbcontentHandler,
1129 &NamespaceUri, &LocalName, &QName);
1131 hr = ISAXContentHandler_endElement(
1132 This->saxreader->contentHandler,
1133 NamespaceUri, SysStringLen(NamespaceUri),
1134 LocalName, SysStringLen(LocalName),
1135 QName, SysStringLen(QName));
1137 SysFreeString(NamespaceUri);
1138 SysFreeString(LocalName);
1139 SysFreeString(QName);
1143 format_error_message_from_id(This, hr);
1147 for(index=This->pParserCtxt->nsNr-2;
1148 index>=This->pParserCtxt->nsNr-nsNr*2; index-=2)
1150 Prefix = bstr_from_xmlChar(This->pParserCtxt->nsTab[index]);
1152 if(This->vbInterface)
1153 hr = IVBSAXContentHandler_endPrefixMapping(
1154 This->saxreader->vbcontentHandler, &Prefix);
1156 hr = ISAXContentHandler_endPrefixMapping(
1157 This->saxreader->contentHandler,
1158 Prefix, SysStringLen(Prefix));
1160 SysFreeString(Prefix);
1164 format_error_message_from_id(This, hr);
1171 update_position(This, NULL);
1174 static void libxmlCharacters(
1179 saxlocator *This = ctx;
1184 BOOL lastEvent = FALSE;
1186 if(!(has_content_handler(This))) return;
1189 if(*(ch-1)=='\r') cur--;
1192 if(ch<This->pParserCtxt->input->base || ch>This->pParserCtxt->input->end)
1197 while(end-ch<len && *end!='\r') end++;
1204 if(!lastEvent) *end = '\n';
1206 Chars = bstr_from_xmlCharN(cur, end-cur+1);
1207 if(This->vbInterface)
1208 hr = IVBSAXContentHandler_characters(
1209 This->saxreader->vbcontentHandler, &Chars);
1211 hr = ISAXContentHandler_characters(
1212 This->saxreader->contentHandler,
1213 Chars, SysStringLen(Chars));
1214 SysFreeString(Chars);
1218 format_error_message_from_id(This, hr);
1222 This->column += end-cur+1;
1236 if(end-ch == len) break;
1239 if(ch<This->pParserCtxt->input->base || ch>This->pParserCtxt->input->end)
1240 This->column = This->realColumn
1241 +This->pParserCtxt->input->cur-This->lastCur;
1244 static void libxmlSetDocumentLocator(
1246 xmlSAXLocatorPtr loc)
1248 saxlocator *This = ctx;
1251 if(This->vbInterface)
1252 hr = IVBSAXContentHandler_putref_documentLocator(
1253 This->saxreader->vbcontentHandler,
1254 (IVBSAXLocator*)&This->lpVBSAXLocatorVtbl);
1256 hr = ISAXContentHandler_putDocumentLocator(
1257 This->saxreader->contentHandler,
1258 (ISAXLocator*)&This->lpSAXLocatorVtbl);
1261 format_error_message_from_id(This, hr);
1264 static void libxmlComment(void *ctx, const xmlChar *value)
1266 saxlocator *This = ctx;
1269 xmlChar *beg = (xmlChar*)This->pParserCtxt->input->cur;
1271 while(memcmp(beg-4, "<!--", sizeof(char[4]))) beg--;
1272 update_position(This, beg);
1274 if(!This->vbInterface && !This->saxreader->lexicalHandler) return;
1275 if(This->vbInterface && !This->saxreader->vblexicalHandler) return;
1277 bValue = bstr_from_xmlChar(value);
1279 if(This->vbInterface)
1280 hr = IVBSAXLexicalHandler_comment(
1281 This->saxreader->vblexicalHandler, &bValue);
1283 hr = ISAXLexicalHandler_comment(
1284 This->saxreader->lexicalHandler,
1285 bValue, SysStringLen(bValue));
1287 SysFreeString(bValue);
1290 format_error_message_from_id(This, hr);
1292 update_position(This, NULL);
1295 static void libxmlFatalError(void *ctx, const char *msg, ...)
1297 saxlocator *This = ctx;
1303 if((This->vbInterface && !This->saxreader->vberrorHandler)
1304 || (!This->vbInterface && !This->saxreader->errorHandler))
1306 xmlStopParser(This->pParserCtxt);
1311 FIXME("Error handling is not compatible.\n");
1313 va_start(args, msg);
1314 vsprintf(message, msg, args);
1317 len = MultiByteToWideChar(CP_UNIXCP, 0, message, -1, NULL, 0);
1318 wszError = heap_alloc(sizeof(WCHAR)*len);
1320 MultiByteToWideChar(CP_UNIXCP, 0, message, -1, wszError, len);
1322 if(This->vbInterface)
1324 BSTR bstrError = SysAllocString(wszError);
1325 IVBSAXErrorHandler_fatalError(This->saxreader->vberrorHandler,
1326 (IVBSAXLocator*)&This->lpVBSAXLocatorVtbl, &bstrError, E_FAIL);
1329 ISAXErrorHandler_fatalError(This->saxreader->errorHandler,
1330 (ISAXLocator*)&This->lpSAXLocatorVtbl, wszError, E_FAIL);
1332 heap_free(wszError);
1334 xmlStopParser(This->pParserCtxt);
1338 static void libxmlCDataBlock(void *ctx, const xmlChar *value, int len)
1340 saxlocator *This = ctx;
1342 xmlChar *beg = (xmlChar*)This->pParserCtxt->input->cur-len;
1346 BOOL lastEvent = FALSE, change;
1348 while(memcmp(beg-9, "<![CDATA[", sizeof(char[9]))) beg--;
1349 update_position(This, beg);
1351 if(This->vbInterface && This->saxreader->vblexicalHandler)
1352 hr = IVBSAXLexicalHandler_startCDATA(This->saxreader->vblexicalHandler);
1353 if(!This->vbInterface && This->saxreader->lexicalHandler)
1354 hr = ISAXLexicalHandler_startCDATA(This->saxreader->lexicalHandler);
1358 format_error_message_from_id(This, hr);
1362 realLen = This->pParserCtxt->input->cur-beg-3;
1368 while(end-beg<realLen && *end!='\r') end++;
1369 if(end-beg==realLen)
1374 else if(end-beg==realLen-1 && *end=='\r' && *(end+1)=='\n')
1377 if(*end == '\r') change = TRUE;
1378 else change = FALSE;
1380 if(change) *end = '\n';
1382 if(has_content_handler(This))
1384 Chars = bstr_from_xmlCharN(cur, end-cur+1);
1385 if(This->vbInterface)
1386 hr = IVBSAXContentHandler_characters(
1387 This->saxreader->vbcontentHandler, &Chars);
1389 hr = ISAXContentHandler_characters(
1390 This->saxreader->contentHandler,
1391 Chars, SysStringLen(Chars));
1392 SysFreeString(Chars);
1395 if(change) *end = '\r';
1400 This->column += end-cur+2;
1405 if(This->vbInterface && This->saxreader->vblexicalHandler)
1406 hr = IVBSAXLexicalHandler_endCDATA(This->saxreader->vblexicalHandler);
1407 if(!This->vbInterface && This->saxreader->lexicalHandler)
1408 hr = ISAXLexicalHandler_endCDATA(This->saxreader->lexicalHandler);
1411 format_error_message_from_id(This, hr);
1413 This->column += 4+end-cur;
1416 /*** IVBSAXLocator interface ***/
1417 /*** IUnknown methods ***/
1418 static HRESULT WINAPI ivbsaxlocator_QueryInterface(IVBSAXLocator* iface, REFIID riid, void **ppvObject)
1420 saxlocator *This = impl_from_IVBSAXLocator( iface );
1422 TRACE("%p %s %p\n", This, debugstr_guid( riid ), ppvObject);
1426 if ( IsEqualGUID( riid, &IID_IUnknown ) ||
1427 IsEqualGUID( riid, &IID_IDispatch) ||
1428 IsEqualGUID( riid, &IID_IVBSAXLocator ))
1434 FIXME("interface %s not implemented\n", debugstr_guid(riid));
1435 return E_NOINTERFACE;
1438 IVBSAXLocator_AddRef( iface );
1443 static ULONG WINAPI ivbsaxlocator_AddRef(IVBSAXLocator* iface)
1445 saxlocator *This = impl_from_IVBSAXLocator( iface );
1446 TRACE("%p\n", This );
1447 return InterlockedIncrement( &This->ref );
1450 static ULONG WINAPI ivbsaxlocator_Release(
1451 IVBSAXLocator* iface)
1453 saxlocator *This = impl_from_IVBSAXLocator( iface );
1454 return ISAXLocator_Release((ISAXLocator*)&This->lpVBSAXLocatorVtbl);
1457 /*** IDispatch methods ***/
1458 static HRESULT WINAPI ivbsaxlocator_GetTypeInfoCount( IVBSAXLocator *iface, UINT* pctinfo )
1460 saxlocator *This = impl_from_IVBSAXLocator( iface );
1462 TRACE("(%p)->(%p)\n", This, pctinfo);
1469 static HRESULT WINAPI ivbsaxlocator_GetTypeInfo(
1470 IVBSAXLocator *iface,
1471 UINT iTInfo, LCID lcid, ITypeInfo** ppTInfo )
1473 saxlocator *This = impl_from_IVBSAXLocator( iface );
1476 TRACE("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo);
1478 hr = get_typeinfo(IVBSAXLocator_tid, ppTInfo);
1483 static HRESULT WINAPI ivbsaxlocator_GetIDsOfNames(
1484 IVBSAXLocator *iface,
1486 LPOLESTR* rgszNames,
1491 saxlocator *This = impl_from_IVBSAXLocator( iface );
1492 ITypeInfo *typeinfo;
1495 TRACE("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames, cNames,
1498 if(!rgszNames || cNames == 0 || !rgDispId)
1499 return E_INVALIDARG;
1501 hr = get_typeinfo(IVBSAXLocator_tid, &typeinfo);
1504 hr = ITypeInfo_GetIDsOfNames(typeinfo, rgszNames, cNames, rgDispId);
1505 ITypeInfo_Release(typeinfo);
1511 static HRESULT WINAPI ivbsaxlocator_Invoke(
1512 IVBSAXLocator *iface,
1513 DISPID dispIdMember,
1517 DISPPARAMS* pDispParams,
1518 VARIANT* pVarResult,
1519 EXCEPINFO* pExcepInfo,
1522 saxlocator *This = impl_from_IVBSAXLocator( iface );
1523 ITypeInfo *typeinfo;
1526 TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
1527 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
1529 hr = get_typeinfo(IVBSAXLocator_tid, &typeinfo);
1532 hr = ITypeInfo_Invoke(typeinfo, &(This->lpVBSAXLocatorVtbl), dispIdMember, wFlags, pDispParams,
1533 pVarResult, pExcepInfo, puArgErr);
1534 ITypeInfo_Release(typeinfo);
1540 /*** IVBSAXLocator methods ***/
1541 static HRESULT WINAPI ivbsaxlocator_get_columnNumber(
1542 IVBSAXLocator* iface,
1545 saxlocator *This = impl_from_IVBSAXLocator( iface );
1546 return ISAXLocator_getColumnNumber(
1547 (ISAXLocator*)&This->lpVBSAXLocatorVtbl,
1551 static HRESULT WINAPI ivbsaxlocator_get_lineNumber(
1552 IVBSAXLocator* iface,
1555 saxlocator *This = impl_from_IVBSAXLocator( iface );
1556 return ISAXLocator_getLineNumber(
1557 (ISAXLocator*)&This->lpVBSAXLocatorVtbl,
1561 static HRESULT WINAPI ivbsaxlocator_get_publicId(
1562 IVBSAXLocator* iface,
1565 saxlocator *This = impl_from_IVBSAXLocator( iface );
1566 return ISAXLocator_getPublicId(
1567 (ISAXLocator*)&This->lpVBSAXLocatorVtbl,
1568 (const WCHAR**)publicId);
1571 static HRESULT WINAPI ivbsaxlocator_get_systemId(
1572 IVBSAXLocator* iface,
1575 saxlocator *This = impl_from_IVBSAXLocator( iface );
1576 return ISAXLocator_getSystemId(
1577 (ISAXLocator*)&This->lpVBSAXLocatorVtbl,
1578 (const WCHAR**)systemId);
1581 static const struct IVBSAXLocatorVtbl ivbsaxlocator_vtbl =
1583 ivbsaxlocator_QueryInterface,
1584 ivbsaxlocator_AddRef,
1585 ivbsaxlocator_Release,
1586 ivbsaxlocator_GetTypeInfoCount,
1587 ivbsaxlocator_GetTypeInfo,
1588 ivbsaxlocator_GetIDsOfNames,
1589 ivbsaxlocator_Invoke,
1590 ivbsaxlocator_get_columnNumber,
1591 ivbsaxlocator_get_lineNumber,
1592 ivbsaxlocator_get_publicId,
1593 ivbsaxlocator_get_systemId
1596 /*** ISAXLocator interface ***/
1597 /*** IUnknown methods ***/
1598 static HRESULT WINAPI isaxlocator_QueryInterface(ISAXLocator* iface, REFIID riid, void **ppvObject)
1600 saxlocator *This = impl_from_ISAXLocator( iface );
1602 TRACE("%p %s %p\n", This, debugstr_guid( riid ), ppvObject );
1606 if ( IsEqualGUID( riid, &IID_IUnknown ) ||
1607 IsEqualGUID( riid, &IID_ISAXLocator ))
1613 FIXME("interface %s not implemented\n", debugstr_guid(riid));
1614 return E_NOINTERFACE;
1617 ISAXLocator_AddRef( iface );
1622 static ULONG WINAPI isaxlocator_AddRef(ISAXLocator* iface)
1624 saxlocator *This = impl_from_ISAXLocator( iface );
1625 TRACE("%p\n", This );
1626 return InterlockedIncrement( &This->ref );
1629 static ULONG WINAPI isaxlocator_Release(
1632 saxlocator *This = impl_from_ISAXLocator( iface );
1635 TRACE("%p\n", This );
1637 ref = InterlockedDecrement( &This->ref );
1640 SysFreeString(This->publicId);
1641 SysFreeString(This->systemId);
1642 heap_free(This->nsStack);
1644 ISAXXMLReader_Release((ISAXXMLReader*)&This->saxreader->lpSAXXMLReaderVtbl);
1651 /*** ISAXLocator methods ***/
1652 static HRESULT WINAPI isaxlocator_getColumnNumber(
1656 saxlocator *This = impl_from_ISAXLocator( iface );
1658 *pnColumn = This->column;
1662 static HRESULT WINAPI isaxlocator_getLineNumber(
1666 saxlocator *This = impl_from_ISAXLocator( iface );
1668 *pnLine = This->line;
1672 static HRESULT WINAPI isaxlocator_getPublicId(
1674 const WCHAR ** ppwchPublicId)
1677 saxlocator *This = impl_from_ISAXLocator( iface );
1679 SysFreeString(This->publicId);
1681 publicId = bstr_from_xmlChar(xmlSAX2GetPublicId(This->pParserCtxt));
1682 if(SysStringLen(publicId))
1683 This->publicId = (WCHAR*)&publicId;
1686 SysFreeString(publicId);
1687 This->publicId = NULL;
1690 *ppwchPublicId = This->publicId;
1694 static HRESULT WINAPI isaxlocator_getSystemId(
1696 const WCHAR ** ppwchSystemId)
1699 saxlocator *This = impl_from_ISAXLocator( iface );
1701 SysFreeString(This->systemId);
1703 systemId = bstr_from_xmlChar(xmlSAX2GetSystemId(This->pParserCtxt));
1704 if(SysStringLen(systemId))
1705 This->systemId = (WCHAR*)&systemId;
1708 SysFreeString(systemId);
1709 This->systemId = NULL;
1712 *ppwchSystemId = This->systemId;
1716 static const struct ISAXLocatorVtbl isaxlocator_vtbl =
1718 isaxlocator_QueryInterface,
1720 isaxlocator_Release,
1721 isaxlocator_getColumnNumber,
1722 isaxlocator_getLineNumber,
1723 isaxlocator_getPublicId,
1724 isaxlocator_getSystemId
1727 static HRESULT SAXLocator_create(saxreader *reader, saxlocator **ppsaxlocator, BOOL vbInterface)
1729 saxlocator *locator;
1731 locator = heap_alloc( sizeof (*locator) );
1733 return E_OUTOFMEMORY;
1735 locator->lpVBSAXLocatorVtbl = &ivbsaxlocator_vtbl;
1736 locator->lpSAXLocatorVtbl = &isaxlocator_vtbl;
1738 locator->vbInterface = vbInterface;
1740 locator->saxreader = reader;
1741 ISAXXMLReader_AddRef((ISAXXMLReader*)&reader->lpSAXXMLReaderVtbl);
1743 locator->pParserCtxt = NULL;
1744 locator->publicId = NULL;
1745 locator->systemId = NULL;
1746 locator->lastCur = NULL;
1748 locator->column = 0;
1749 locator->ret = S_OK;
1750 locator->nsStackSize = 8;
1751 locator->nsStackLast = 0;
1752 locator->nsStack = heap_alloc(locator->nsStackSize);
1753 if(!locator->nsStack)
1755 ISAXXMLReader_Release((ISAXXMLReader*)&reader->lpSAXXMLReaderVtbl);
1757 return E_OUTOFMEMORY;
1760 *ppsaxlocator = locator;
1762 TRACE("returning %p\n", *ppsaxlocator);
1767 /*** SAXXMLReader internal functions ***/
1768 static HRESULT internal_parseBuffer(saxreader *This, const char *buffer, int size, BOOL vbInterface)
1770 saxlocator *locator;
1773 hr = SAXLocator_create(This, &locator, vbInterface);
1777 locator->pParserCtxt = xmlCreateMemoryParserCtxt(buffer, size);
1778 if(!locator->pParserCtxt)
1780 ISAXLocator_Release((ISAXLocator*)&locator->lpSAXLocatorVtbl);
1784 xmlFree(locator->pParserCtxt->sax);
1785 locator->pParserCtxt->sax = &locator->saxreader->sax;
1786 locator->pParserCtxt->userData = locator;
1788 This->isParsing = TRUE;
1789 if(xmlParseDocument(locator->pParserCtxt)) hr = E_FAIL;
1790 else hr = locator->ret;
1791 This->isParsing = FALSE;
1793 if(locator->pParserCtxt)
1795 locator->pParserCtxt->sax = NULL;
1796 xmlFreeParserCtxt(locator->pParserCtxt);
1797 locator->pParserCtxt = NULL;
1800 ISAXLocator_Release((ISAXLocator*)&locator->lpSAXLocatorVtbl);
1804 static HRESULT internal_parseStream(saxreader *This, IStream *stream, BOOL vbInterface)
1806 saxlocator *locator;
1811 hr = IStream_Read(stream, data, sizeof(data), &dataRead);
1815 hr = SAXLocator_create(This, &locator, vbInterface);
1819 locator->pParserCtxt = xmlCreatePushParserCtxt(
1820 &locator->saxreader->sax, locator,
1821 data, dataRead, NULL);
1822 if(!locator->pParserCtxt)
1824 ISAXLocator_Release((ISAXLocator*)&locator->lpSAXLocatorVtbl);
1828 This->isParsing = TRUE;
1831 hr = IStream_Read(stream, data, sizeof(data), &dataRead);
1835 if(xmlParseChunk(locator->pParserCtxt, data, dataRead, 0)) hr = E_FAIL;
1836 else hr = locator->ret;
1838 if(hr != S_OK) break;
1840 if(dataRead != sizeof(data))
1842 if(xmlParseChunk(locator->pParserCtxt, data, 0, 1)) hr = E_FAIL;
1843 else hr = locator->ret;
1848 This->isParsing = FALSE;
1850 xmlFreeParserCtxt(locator->pParserCtxt);
1851 locator->pParserCtxt = NULL;
1852 ISAXLocator_Release((ISAXLocator*)&locator->lpSAXLocatorVtbl);
1856 static HRESULT internal_getEntityResolver(
1858 void *pEntityResolver,
1861 FIXME("(%p)->(%p) stub\n", This, pEntityResolver);
1865 static HRESULT internal_putEntityResolver(
1867 void *pEntityResolver,
1870 FIXME("(%p)->(%p) stub\n", This, pEntityResolver);
1874 static HRESULT internal_getContentHandler(
1876 void *pContentHandler,
1879 TRACE("(%p)->(%p)\n", This, pContentHandler);
1880 if(pContentHandler == NULL)
1882 if((vbInterface && This->vbcontentHandler)
1883 || (!vbInterface && This->contentHandler))
1886 IVBSAXContentHandler_AddRef(This->vbcontentHandler);
1888 ISAXContentHandler_AddRef(This->contentHandler);
1890 if(vbInterface) *(IVBSAXContentHandler**)pContentHandler =
1891 This->vbcontentHandler;
1892 else *(ISAXContentHandler**)pContentHandler = This->contentHandler;
1897 static HRESULT internal_putContentHandler(
1899 void *contentHandler,
1902 TRACE("(%p)->(%p)\n", This, contentHandler);
1906 IVBSAXContentHandler_AddRef((IVBSAXContentHandler*)contentHandler);
1908 ISAXContentHandler_AddRef((ISAXContentHandler*)contentHandler);
1910 if((vbInterface && This->vbcontentHandler)
1911 || (!vbInterface && This->contentHandler))
1914 IVBSAXContentHandler_Release(This->vbcontentHandler);
1916 ISAXContentHandler_Release(This->contentHandler);
1919 This->vbcontentHandler = contentHandler;
1921 This->contentHandler = contentHandler;
1926 static HRESULT internal_getDTDHandler(
1931 FIXME("(%p)->(%p) stub\n", This, pDTDHandler);
1935 static HRESULT internal_putDTDHandler(
1940 FIXME("(%p)->(%p) stub\n", This, pDTDHandler);
1944 static HRESULT internal_getErrorHandler(
1946 void *pErrorHandler,
1949 TRACE("(%p)->(%p)\n", This, pErrorHandler);
1950 if(pErrorHandler == NULL)
1953 if(vbInterface && This->vberrorHandler)
1954 IVBSAXErrorHandler_AddRef(This->vberrorHandler);
1955 else if(!vbInterface && This->errorHandler)
1956 ISAXErrorHandler_AddRef(This->errorHandler);
1959 *(IVBSAXErrorHandler**)pErrorHandler = This->vberrorHandler;
1961 *(ISAXErrorHandler**)pErrorHandler = This->errorHandler;
1967 static HRESULT internal_putErrorHandler(
1972 TRACE("(%p)->(%p)\n", This, errorHandler);
1976 IVBSAXErrorHandler_AddRef((IVBSAXErrorHandler*)errorHandler);
1978 ISAXErrorHandler_AddRef((ISAXErrorHandler*)errorHandler);
1981 if(vbInterface && This->vberrorHandler)
1982 IVBSAXErrorHandler_Release(This->vberrorHandler);
1983 else if(!vbInterface && This->errorHandler)
1984 ISAXErrorHandler_Release(This->errorHandler);
1987 This->vberrorHandler = errorHandler;
1989 This->errorHandler = errorHandler;
1995 static HRESULT internal_parse(
2002 TRACE("(%p)\n", This);
2005 switch(V_VT(&varInput))
2008 hr = internal_parseBuffer(This, (const char*)V_BSTR(&varInput),
2009 SysStringByteLen(V_BSTR(&varInput)), vbInterface);
2011 case VT_ARRAY|VT_UI1: {
2013 LONG lBound, uBound;
2016 hr = SafeArrayGetLBound(V_ARRAY(&varInput), 1, &lBound);
2017 if(hr != S_OK) break;
2018 hr = SafeArrayGetUBound(V_ARRAY(&varInput), 1, &uBound);
2019 if(hr != S_OK) break;
2020 dataRead = (uBound-lBound)*SafeArrayGetElemsize(V_ARRAY(&varInput));
2021 hr = SafeArrayAccessData(V_ARRAY(&varInput), &pSAData);
2022 if(hr != S_OK) break;
2023 hr = internal_parseBuffer(This, pSAData, dataRead, vbInterface);
2024 SafeArrayUnaccessData(V_ARRAY(&varInput));
2029 IPersistStream *persistStream;
2030 IStream *stream = NULL;
2031 IXMLDOMDocument *xmlDoc;
2033 if(IUnknown_QueryInterface(V_UNKNOWN(&varInput),
2034 &IID_IXMLDOMDocument, (void**)&xmlDoc) == S_OK)
2038 IXMLDOMDocument_get_xml(xmlDoc, &bstrData);
2039 hr = internal_parseBuffer(This, (const char*)bstrData,
2040 SysStringByteLen(bstrData), vbInterface);
2041 IXMLDOMDocument_Release(xmlDoc);
2042 SysFreeString(bstrData);
2045 if(IUnknown_QueryInterface(V_UNKNOWN(&varInput),
2046 &IID_IPersistStream, (void**)&persistStream) == S_OK)
2048 hr = IPersistStream_Save(persistStream, stream, TRUE);
2049 IPersistStream_Release(persistStream);
2050 if(hr != S_OK) break;
2052 if(stream || IUnknown_QueryInterface(V_UNKNOWN(&varInput),
2053 &IID_IStream, (void**)&stream) == S_OK)
2055 hr = internal_parseStream(This, stream, vbInterface);
2056 IStream_Release(stream);
2061 WARN("vt %d not implemented\n", V_VT(&varInput));
2068 static HRESULT internal_vbonDataAvailable(void *obj, char *ptr, DWORD len)
2070 saxreader *This = obj;
2072 return internal_parseBuffer(This, ptr, len, TRUE);
2075 static HRESULT internal_onDataAvailable(void *obj, char *ptr, DWORD len)
2077 saxreader *This = obj;
2079 return internal_parseBuffer(This, ptr, len, FALSE);
2082 static HRESULT internal_parseURL(
2090 TRACE("(%p)->(%s)\n", This, debugstr_w(url));
2092 if(vbInterface) hr = bind_url(url, internal_vbonDataAvailable, This, &bsc);
2093 else hr = bind_url(url, internal_onDataAvailable, This, &bsc);
2103 static HRESULT internal_putProperty(
2109 static const WCHAR wszCharset[] = {
2110 'c','h','a','r','s','e','t',0
2112 static const WCHAR wszDeclarationHandler[] = {
2113 'h','t','t','p',':','/','/','x','m','l','.','o','r','g','/',
2114 's','a','x','/','p','r','o','p','e','r','t','i','e','s','/',
2115 'd','e','c','l','a','r','a','t','i','o','n',
2116 '-','h','a','n','d','l','e','r',0
2118 static const WCHAR wszDomNode[] = {
2119 'h','t','t','p',':','/','/','x','m','l','.','o','r','g','/',
2120 's','a','x','/','p','r','o','p','e','r','t','i','e','s','/',
2121 'd','o','m','-','n','o','d','e',0
2123 static const WCHAR wszInputSource[] = {
2124 'i','n','p','u','t','-','s','o','u','r','c','e',0
2126 static const WCHAR wszLexicalHandler[] = {
2127 'h','t','t','p',':','/','/','x','m','l','.','o','r','g','/',
2128 's','a','x','/','p','r','o','p','e','r','t','i','e','s','/',
2129 'l','e','x','i','c','a','l','-','h','a','n','d','l','e','r',0
2131 static const WCHAR wszMaxElementDepth[] = {
2132 'm','a','x','-','e','l','e','m','e','n','t','-','d','e','p','t','h',0
2134 static const WCHAR wszMaxXMLSize[] = {
2135 'm','a','x','-','x','m','l','-','s','i','z','e',0
2137 static const WCHAR wszSchemaDeclarationHandler[] = {
2138 's','c','h','e','m','a','-',
2139 'd','e','c','l','a','r','a','t','i','o','n','-',
2140 'h','a','n','d','l','e','r',0
2142 static const WCHAR wszXMLDeclEncoding[] = {
2143 'x','m','l','d','e','c','l','-','e','n','c','o','d','i','n','g',0
2145 static const WCHAR wszXMLDeclStandalone[] = {
2146 'x','m','l','d','e','c','l',
2147 '-','s','t','a','n','d','a','l','o','n','e',0
2149 static const WCHAR wszXMLDeclVersion[] = {
2150 'x','m','l','d','e','c','l','-','v','e','r','s','i','o','n',0
2153 FIXME("(%p)->(%s): semi-stub\n", This, debugstr_w(pProp));
2155 if(!memcmp(pProp, wszCharset, sizeof(wszCharset)))
2158 if(!memcmp(pProp, wszDeclarationHandler, sizeof(wszDeclarationHandler)))
2160 if(This->isParsing) return E_FAIL;
2162 if(V_UNKNOWN(&value))
2165 IVBSAXDeclHandler_AddRef((IVBSAXDeclHandler*)V_UNKNOWN(&value));
2167 ISAXDeclHandler_AddRef((ISAXDeclHandler*)V_UNKNOWN(&value));
2169 if((vbInterface && This->vbdeclHandler)
2170 || (!vbInterface && This->declHandler))
2173 IVBSAXDeclHandler_Release(This->vbdeclHandler);
2175 ISAXDeclHandler_Release(This->declHandler);
2178 This->vbdeclHandler = (IVBSAXDeclHandler*)V_UNKNOWN(&value);
2180 This->declHandler = (ISAXDeclHandler*)V_UNKNOWN(&value);
2184 if(!memcmp(pProp, wszDomNode, sizeof(wszDomNode)))
2187 if(!memcmp(pProp, wszInputSource, sizeof(wszInputSource)))
2190 if(!memcmp(pProp, wszLexicalHandler, sizeof(wszLexicalHandler)))
2192 if(This->isParsing) return E_FAIL;
2194 if(V_UNKNOWN(&value))
2197 IVBSAXLexicalHandler_AddRef(
2198 (IVBSAXLexicalHandler*)V_UNKNOWN(&value));
2200 ISAXLexicalHandler_AddRef(
2201 (ISAXLexicalHandler*)V_UNKNOWN(&value));
2203 if((vbInterface && This->vblexicalHandler)
2204 || (!vbInterface && This->lexicalHandler))
2207 IVBSAXLexicalHandler_Release(This->vblexicalHandler);
2209 ISAXLexicalHandler_Release(This->lexicalHandler);
2212 This->vblexicalHandler = (IVBSAXLexicalHandler*)V_UNKNOWN(&value);
2214 This->lexicalHandler = (ISAXLexicalHandler*)V_UNKNOWN(&value);
2218 if(!memcmp(pProp, wszMaxElementDepth, sizeof(wszMaxElementDepth)))
2221 if(!memcmp(pProp, wszMaxXMLSize, sizeof(wszMaxXMLSize)))
2224 if(!memcmp(pProp, wszSchemaDeclarationHandler,
2225 sizeof(wszSchemaDeclarationHandler)))
2228 if(!memcmp(pProp, wszXMLDeclEncoding, sizeof(wszXMLDeclEncoding)))
2231 if(!memcmp(pProp, wszXMLDeclStandalone, sizeof(wszXMLDeclStandalone)))
2234 if(!memcmp(pProp, wszXMLDeclVersion, sizeof(wszXMLDeclVersion)))
2237 return E_INVALIDARG;
2240 /*** IVBSAXXMLReader interface ***/
2241 /*** IUnknown methods ***/
2242 static HRESULT WINAPI saxxmlreader_QueryInterface(IVBSAXXMLReader* iface, REFIID riid, void **ppvObject)
2244 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2246 TRACE("%p %s %p\n", This, debugstr_guid( riid ), ppvObject );
2250 if ( IsEqualGUID( riid, &IID_IUnknown ) ||
2251 IsEqualGUID( riid, &IID_IDispatch ) ||
2252 IsEqualGUID( riid, &IID_IVBSAXXMLReader ))
2256 else if( IsEqualGUID( riid, &IID_ISAXXMLReader ))
2258 *ppvObject = &This->lpSAXXMLReaderVtbl;
2262 FIXME("interface %s not implemented\n", debugstr_guid(riid));
2263 return E_NOINTERFACE;
2266 IVBSAXXMLReader_AddRef( iface );
2271 static ULONG WINAPI saxxmlreader_AddRef(IVBSAXXMLReader* iface)
2273 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2274 TRACE("%p\n", This );
2275 return InterlockedIncrement( &This->ref );
2278 static ULONG WINAPI saxxmlreader_Release(
2279 IVBSAXXMLReader* iface)
2281 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2284 TRACE("%p\n", This );
2286 ref = InterlockedDecrement( &This->ref );
2289 if(This->contentHandler)
2290 ISAXContentHandler_Release(This->contentHandler);
2292 if(This->vbcontentHandler)
2293 IVBSAXContentHandler_Release(This->vbcontentHandler);
2295 if(This->errorHandler)
2296 ISAXErrorHandler_Release(This->errorHandler);
2298 if(This->vberrorHandler)
2299 IVBSAXErrorHandler_Release(This->vberrorHandler);
2301 if(This->lexicalHandler)
2302 ISAXLexicalHandler_Release(This->lexicalHandler);
2304 if(This->vblexicalHandler)
2305 IVBSAXLexicalHandler_Release(This->vblexicalHandler);
2307 if(This->declHandler)
2308 ISAXDeclHandler_Release(This->declHandler);
2310 if(This->vbdeclHandler)
2311 IVBSAXDeclHandler_Release(This->vbdeclHandler);
2319 static HRESULT WINAPI saxxmlreader_GetTypeInfoCount( IVBSAXXMLReader *iface, UINT* pctinfo )
2321 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2323 TRACE("(%p)->(%p)\n", This, pctinfo);
2330 static HRESULT WINAPI saxxmlreader_GetTypeInfo(
2331 IVBSAXXMLReader *iface,
2332 UINT iTInfo, LCID lcid, ITypeInfo** ppTInfo )
2334 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2337 TRACE("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo);
2339 hr = get_typeinfo(IVBSAXXMLReader_tid, ppTInfo);
2344 static HRESULT WINAPI saxxmlreader_GetIDsOfNames(
2345 IVBSAXXMLReader *iface,
2347 LPOLESTR* rgszNames,
2352 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2353 ITypeInfo *typeinfo;
2356 TRACE("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames, cNames,
2359 if(!rgszNames || cNames == 0 || !rgDispId)
2360 return E_INVALIDARG;
2362 hr = get_typeinfo(IVBSAXXMLReader_tid, &typeinfo);
2365 hr = ITypeInfo_GetIDsOfNames(typeinfo, rgszNames, cNames, rgDispId);
2366 ITypeInfo_Release(typeinfo);
2372 static HRESULT WINAPI saxxmlreader_Invoke(
2373 IVBSAXXMLReader *iface,
2374 DISPID dispIdMember,
2378 DISPPARAMS* pDispParams,
2379 VARIANT* pVarResult,
2380 EXCEPINFO* pExcepInfo,
2383 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2384 ITypeInfo *typeinfo;
2387 TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
2388 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
2390 hr = get_typeinfo(IVBSAXXMLReader_tid, &typeinfo);
2393 hr = ITypeInfo_Invoke(typeinfo, &(This->lpVBSAXXMLReaderVtbl), dispIdMember, wFlags, pDispParams,
2394 pVarResult, pExcepInfo, puArgErr);
2395 ITypeInfo_Release(typeinfo);
2401 /*** IVBSAXXMLReader methods ***/
2402 static HRESULT WINAPI saxxmlreader_getFeature(
2403 IVBSAXXMLReader* iface,
2404 const WCHAR *pFeature,
2405 VARIANT_BOOL *pValue)
2407 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2409 FIXME("(%p)->(%s %p) stub\n", This, debugstr_w(pFeature), pValue);
2413 static HRESULT WINAPI saxxmlreader_putFeature(
2414 IVBSAXXMLReader* iface,
2415 const WCHAR *pFeature,
2416 VARIANT_BOOL vfValue)
2418 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2420 FIXME("(%p)->(%s %x) stub\n", This, debugstr_w(pFeature), vfValue);
2424 static HRESULT WINAPI saxxmlreader_getProperty(
2425 IVBSAXXMLReader* iface,
2429 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2431 FIXME("(%p)->(%s %p) stub\n", This, debugstr_w(pProp), pValue);
2435 static HRESULT WINAPI saxxmlreader_putProperty(
2436 IVBSAXXMLReader* iface,
2440 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2441 return internal_putProperty(This, pProp, value, TRUE);
2444 static HRESULT WINAPI saxxmlreader_get_entityResolver(
2445 IVBSAXXMLReader* iface,
2446 IVBSAXEntityResolver **pEntityResolver)
2448 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2449 return internal_getEntityResolver(This, pEntityResolver, TRUE);
2452 static HRESULT WINAPI saxxmlreader_put_entityResolver(
2453 IVBSAXXMLReader* iface,
2454 IVBSAXEntityResolver *pEntityResolver)
2456 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2457 return internal_putEntityResolver(This, pEntityResolver, TRUE);
2460 static HRESULT WINAPI saxxmlreader_get_contentHandler(
2461 IVBSAXXMLReader* iface,
2462 IVBSAXContentHandler **ppContentHandler)
2464 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2465 return internal_getContentHandler(This, ppContentHandler, TRUE);
2468 static HRESULT WINAPI saxxmlreader_put_contentHandler(
2469 IVBSAXXMLReader* iface,
2470 IVBSAXContentHandler *contentHandler)
2472 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2473 return internal_putContentHandler(This, contentHandler, TRUE);
2476 static HRESULT WINAPI saxxmlreader_get_dtdHandler(
2477 IVBSAXXMLReader* iface,
2478 IVBSAXDTDHandler **pDTDHandler)
2480 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2481 return internal_getDTDHandler(This, pDTDHandler, TRUE);
2484 static HRESULT WINAPI saxxmlreader_put_dtdHandler(
2485 IVBSAXXMLReader* iface,
2486 IVBSAXDTDHandler *pDTDHandler)
2488 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2489 return internal_putDTDHandler(This, pDTDHandler, TRUE);
2492 static HRESULT WINAPI saxxmlreader_get_errorHandler(
2493 IVBSAXXMLReader* iface,
2494 IVBSAXErrorHandler **pErrorHandler)
2496 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2497 return internal_getErrorHandler(This, pErrorHandler, TRUE);
2500 static HRESULT WINAPI saxxmlreader_put_errorHandler(
2501 IVBSAXXMLReader* iface,
2502 IVBSAXErrorHandler *errorHandler)
2504 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2505 return internal_putErrorHandler(This, errorHandler, TRUE);
2508 static HRESULT WINAPI saxxmlreader_get_baseURL(
2509 IVBSAXXMLReader* iface,
2510 const WCHAR **pBaseUrl)
2512 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2514 FIXME("(%p)->(%p) stub\n", This, pBaseUrl);
2518 static HRESULT WINAPI saxxmlreader_put_baseURL(
2519 IVBSAXXMLReader* iface,
2520 const WCHAR *pBaseUrl)
2522 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2524 FIXME("(%p)->(%s) stub\n", This, debugstr_w(pBaseUrl));
2528 static HRESULT WINAPI saxxmlreader_get_secureBaseURL(
2529 IVBSAXXMLReader* iface,
2530 const WCHAR **pSecureBaseUrl)
2532 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2534 FIXME("(%p)->(%p) stub\n", This, pSecureBaseUrl);
2539 static HRESULT WINAPI saxxmlreader_put_secureBaseURL(
2540 IVBSAXXMLReader* iface,
2541 const WCHAR *secureBaseUrl)
2543 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2545 FIXME("(%p)->(%s) stub\n", This, debugstr_w(secureBaseUrl));
2549 static HRESULT WINAPI saxxmlreader_parse(
2550 IVBSAXXMLReader* iface,
2553 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2554 return internal_parse(This, varInput, TRUE);
2557 static HRESULT WINAPI saxxmlreader_parseURL(
2558 IVBSAXXMLReader* iface,
2561 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2562 return internal_parseURL(This, url, TRUE);
2565 static const struct IVBSAXXMLReaderVtbl saxreader_vtbl =
2567 saxxmlreader_QueryInterface,
2568 saxxmlreader_AddRef,
2569 saxxmlreader_Release,
2570 saxxmlreader_GetTypeInfoCount,
2571 saxxmlreader_GetTypeInfo,
2572 saxxmlreader_GetIDsOfNames,
2573 saxxmlreader_Invoke,
2574 saxxmlreader_getFeature,
2575 saxxmlreader_putFeature,
2576 saxxmlreader_getProperty,
2577 saxxmlreader_putProperty,
2578 saxxmlreader_get_entityResolver,
2579 saxxmlreader_put_entityResolver,
2580 saxxmlreader_get_contentHandler,
2581 saxxmlreader_put_contentHandler,
2582 saxxmlreader_get_dtdHandler,
2583 saxxmlreader_put_dtdHandler,
2584 saxxmlreader_get_errorHandler,
2585 saxxmlreader_put_errorHandler,
2586 saxxmlreader_get_baseURL,
2587 saxxmlreader_put_baseURL,
2588 saxxmlreader_get_secureBaseURL,
2589 saxxmlreader_put_secureBaseURL,
2591 saxxmlreader_parseURL
2594 /*** ISAXXMLReader interface ***/
2595 /*** IUnknown methods ***/
2596 static HRESULT WINAPI isaxxmlreader_QueryInterface(ISAXXMLReader* iface, REFIID riid, void **ppvObject)
2598 saxreader *This = impl_from_ISAXXMLReader( iface );
2599 return saxxmlreader_QueryInterface((IVBSAXXMLReader*)&This->lpVBSAXXMLReaderVtbl, riid, ppvObject);
2602 static ULONG WINAPI isaxxmlreader_AddRef(ISAXXMLReader* iface)
2604 saxreader *This = impl_from_ISAXXMLReader( iface );
2605 return saxxmlreader_AddRef((IVBSAXXMLReader*)&This->lpVBSAXXMLReaderVtbl);
2608 static ULONG WINAPI isaxxmlreader_Release(ISAXXMLReader* iface)
2610 saxreader *This = impl_from_ISAXXMLReader( iface );
2611 return saxxmlreader_Release((IVBSAXXMLReader*)&This->lpVBSAXXMLReaderVtbl);
2614 /*** ISAXXMLReader methods ***/
2615 static HRESULT WINAPI isaxxmlreader_getFeature(
2616 ISAXXMLReader* iface,
2617 const WCHAR *pFeature,
2618 VARIANT_BOOL *pValue)
2620 saxreader *This = impl_from_ISAXXMLReader( iface );
2621 return IVBSAXXMLReader_getFeature(
2622 (IVBSAXXMLReader*)&This->lpVBSAXXMLReaderVtbl,
2626 static HRESULT WINAPI isaxxmlreader_putFeature(
2627 ISAXXMLReader* iface,
2628 const WCHAR *pFeature,
2629 VARIANT_BOOL vfValue)
2631 saxreader *This = impl_from_ISAXXMLReader( iface );
2632 return IVBSAXXMLReader_putFeature(
2633 (IVBSAXXMLReader*)&This->lpVBSAXXMLReaderVtbl,
2637 static HRESULT WINAPI isaxxmlreader_getProperty(
2638 ISAXXMLReader* iface,
2642 saxreader *This = impl_from_ISAXXMLReader( iface );
2643 return IVBSAXXMLReader_getProperty(
2644 (IVBSAXXMLReader*)&This->lpVBSAXXMLReaderVtbl,
2648 static HRESULT WINAPI isaxxmlreader_putProperty(
2649 ISAXXMLReader* iface,
2653 saxreader *This = impl_from_ISAXXMLReader( iface );
2654 return internal_putProperty(This, pProp, value, FALSE);
2657 static HRESULT WINAPI isaxxmlreader_getEntityResolver(
2658 ISAXXMLReader* iface,
2659 ISAXEntityResolver **ppEntityResolver)
2661 saxreader *This = impl_from_ISAXXMLReader( iface );
2662 return internal_getEntityResolver(This, ppEntityResolver, FALSE);
2665 static HRESULT WINAPI isaxxmlreader_putEntityResolver(
2666 ISAXXMLReader* iface,
2667 ISAXEntityResolver *pEntityResolver)
2669 saxreader *This = impl_from_ISAXXMLReader( iface );
2670 return internal_putEntityResolver(This, pEntityResolver, FALSE);
2673 static HRESULT WINAPI isaxxmlreader_getContentHandler(
2674 ISAXXMLReader* iface,
2675 ISAXContentHandler **pContentHandler)
2677 saxreader *This = impl_from_ISAXXMLReader( iface );
2678 return internal_getContentHandler(This, pContentHandler, FALSE);
2681 static HRESULT WINAPI isaxxmlreader_putContentHandler(
2682 ISAXXMLReader* iface,
2683 ISAXContentHandler *contentHandler)
2685 saxreader *This = impl_from_ISAXXMLReader( iface );
2686 return internal_putContentHandler(This, contentHandler, FALSE);
2689 static HRESULT WINAPI isaxxmlreader_getDTDHandler(
2690 ISAXXMLReader* iface,
2691 ISAXDTDHandler **pDTDHandler)
2693 saxreader *This = impl_from_ISAXXMLReader( iface );
2694 return internal_getDTDHandler(This, pDTDHandler, FALSE);
2697 static HRESULT WINAPI isaxxmlreader_putDTDHandler(
2698 ISAXXMLReader* iface,
2699 ISAXDTDHandler *pDTDHandler)
2701 saxreader *This = impl_from_ISAXXMLReader( iface );
2702 return internal_putDTDHandler(This, pDTDHandler, FALSE);
2705 static HRESULT WINAPI isaxxmlreader_getErrorHandler(
2706 ISAXXMLReader* iface,
2707 ISAXErrorHandler **pErrorHandler)
2709 saxreader *This = impl_from_ISAXXMLReader( iface );
2710 return internal_getErrorHandler(This, pErrorHandler, FALSE);
2713 static HRESULT WINAPI isaxxmlreader_putErrorHandler(
2714 ISAXXMLReader* iface,
2715 ISAXErrorHandler *errorHandler)
2717 saxreader *This = impl_from_ISAXXMLReader( iface );
2718 return internal_putErrorHandler(This, errorHandler, FALSE);
2721 static HRESULT WINAPI isaxxmlreader_getBaseURL(
2722 ISAXXMLReader* iface,
2723 const WCHAR **pBaseUrl)
2725 saxreader *This = impl_from_ISAXXMLReader( iface );
2726 return IVBSAXXMLReader_get_baseURL(
2727 (IVBSAXXMLReader*)&This->lpVBSAXXMLReaderVtbl,
2731 static HRESULT WINAPI isaxxmlreader_putBaseURL(
2732 ISAXXMLReader* iface,
2733 const WCHAR *pBaseUrl)
2735 saxreader *This = impl_from_ISAXXMLReader( iface );
2736 return IVBSAXXMLReader_put_baseURL(
2737 (IVBSAXXMLReader*)&This->lpVBSAXXMLReaderVtbl,
2741 static HRESULT WINAPI isaxxmlreader_getSecureBaseURL(
2742 ISAXXMLReader* iface,
2743 const WCHAR **pSecureBaseUrl)
2745 saxreader *This = impl_from_ISAXXMLReader( iface );
2746 return IVBSAXXMLReader_get_secureBaseURL(
2747 (IVBSAXXMLReader*)&This->lpVBSAXXMLReaderVtbl,
2751 static HRESULT WINAPI isaxxmlreader_putSecureBaseURL(
2752 ISAXXMLReader* iface,
2753 const WCHAR *secureBaseUrl)
2755 saxreader *This = impl_from_ISAXXMLReader( iface );
2756 return IVBSAXXMLReader_put_secureBaseURL(
2757 (IVBSAXXMLReader*)&This->lpVBSAXXMLReaderVtbl,
2761 static HRESULT WINAPI isaxxmlreader_parse(
2762 ISAXXMLReader* iface,
2765 saxreader *This = impl_from_ISAXXMLReader( iface );
2766 return internal_parse(This, varInput, FALSE);
2769 static HRESULT WINAPI isaxxmlreader_parseURL(
2770 ISAXXMLReader* iface,
2773 saxreader *This = impl_from_ISAXXMLReader( iface );
2774 return internal_parseURL(This, url, FALSE);
2777 static const struct ISAXXMLReaderVtbl isaxreader_vtbl =
2779 isaxxmlreader_QueryInterface,
2780 isaxxmlreader_AddRef,
2781 isaxxmlreader_Release,
2782 isaxxmlreader_getFeature,
2783 isaxxmlreader_putFeature,
2784 isaxxmlreader_getProperty,
2785 isaxxmlreader_putProperty,
2786 isaxxmlreader_getEntityResolver,
2787 isaxxmlreader_putEntityResolver,
2788 isaxxmlreader_getContentHandler,
2789 isaxxmlreader_putContentHandler,
2790 isaxxmlreader_getDTDHandler,
2791 isaxxmlreader_putDTDHandler,
2792 isaxxmlreader_getErrorHandler,
2793 isaxxmlreader_putErrorHandler,
2794 isaxxmlreader_getBaseURL,
2795 isaxxmlreader_putBaseURL,
2796 isaxxmlreader_getSecureBaseURL,
2797 isaxxmlreader_putSecureBaseURL,
2798 isaxxmlreader_parse,
2799 isaxxmlreader_parseURL
2802 HRESULT SAXXMLReader_create(IUnknown *pUnkOuter, LPVOID *ppObj)
2806 TRACE("(%p,%p)\n", pUnkOuter, ppObj);
2808 reader = heap_alloc( sizeof (*reader) );
2810 return E_OUTOFMEMORY;
2812 reader->lpVBSAXXMLReaderVtbl = &saxreader_vtbl;
2813 reader->lpSAXXMLReaderVtbl = &isaxreader_vtbl;
2815 reader->contentHandler = NULL;
2816 reader->vbcontentHandler = NULL;
2817 reader->errorHandler = NULL;
2818 reader->vberrorHandler = NULL;
2819 reader->lexicalHandler = NULL;
2820 reader->vblexicalHandler = NULL;
2821 reader->declHandler = NULL;
2822 reader->vbdeclHandler = NULL;
2823 reader->isParsing = FALSE;
2825 memset(&reader->sax, 0, sizeof(xmlSAXHandler));
2826 reader->sax.initialized = XML_SAX2_MAGIC;
2827 reader->sax.startDocument = libxmlStartDocument;
2828 reader->sax.endDocument = libxmlEndDocument;
2829 reader->sax.startElementNs = libxmlStartElementNS;
2830 reader->sax.endElementNs = libxmlEndElementNS;
2831 reader->sax.characters = libxmlCharacters;
2832 reader->sax.setDocumentLocator = libxmlSetDocumentLocator;
2833 reader->sax.comment = libxmlComment;
2834 reader->sax.error = libxmlFatalError;
2835 reader->sax.fatalError = libxmlFatalError;
2836 reader->sax.cdataBlock = libxmlCDataBlock;
2838 *ppObj = &reader->lpVBSAXXMLReaderVtbl;
2840 TRACE("returning iface %p\n", *ppObj);
2847 HRESULT SAXXMLReader_create(IUnknown *pUnkOuter, LPVOID *ppObj)
2849 MESSAGE("This program tried to use a SAX XML Reader object, but\n"
2850 "libxml2 support was not present at compile time.\n");