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));
130 static HRESULT namespacePush(saxlocator *locator, int ns)
132 if(locator->nsStackLast>=locator->nsStackSize)
136 new_stack = HeapReAlloc(GetProcessHeap(), 0,
137 locator->nsStack, locator->nsStackSize*2);
138 if(!new_stack) return E_OUTOFMEMORY;
139 locator->nsStack = new_stack;
140 locator->nsStackSize *= 2;
142 locator->nsStack[locator->nsStackLast++] = ns;
147 static int namespacePop(saxlocator *locator)
149 if(locator->nsStackLast == 0) return 0;
150 return locator->nsStack[--locator->nsStackLast];
153 static BSTR bstr_from_xmlCharN(const xmlChar *buf, int len)
162 dLen = MultiByteToWideChar(CP_UTF8, 0, (LPCSTR)buf, len, NULL, 0);
163 if(len != -1) dLen++;
164 str = HeapAlloc(GetProcessHeap(), 0, dLen * sizeof (WCHAR));
167 MultiByteToWideChar(CP_UTF8, 0, (LPCSTR)buf, len, str, dLen);
168 if(len != -1) str[dLen-1] = '\0';
169 bstr = SysAllocString(str);
170 HeapFree(GetProcessHeap(), 0, str);
175 static BSTR QName_from_xmlChar(const xmlChar *prefix, const xmlChar *name)
181 if(!name) return NULL;
183 if(!prefix || *prefix=='\0')
184 return bstr_from_xmlChar(name);
186 dLen = MultiByteToWideChar(CP_UTF8, 0, (LPCSTR)prefix, -1, NULL, 0)
187 + MultiByteToWideChar(CP_UTF8, 0, (LPCSTR)name, -1, NULL, 0);
188 str = HeapAlloc(GetProcessHeap(), 0, dLen * sizeof(WCHAR));
192 dLast = MultiByteToWideChar(CP_UTF8, 0, (LPCSTR)prefix, -1, str, dLen);
194 MultiByteToWideChar(CP_UTF8, 0, (LPCSTR)name, -1, &str[dLast], dLen-dLast);
195 bstr = SysAllocString(str);
197 HeapFree(GetProcessHeap(), 0, str);
202 static void format_error_message_from_id(saxlocator *This, HRESULT hr)
204 xmlStopParser(This->pParserCtxt);
207 if((This->vbInterface && This->saxreader->vberrorHandler)
208 || (!This->vbInterface && This->saxreader->errorHandler))
211 if(!FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM,
212 NULL, hr, 0, msg, sizeof(msg), NULL))
214 FIXME("MSXML errors not yet supported.\n");
218 if(This->vbInterface)
220 BSTR bstrMsg = SysAllocString(msg);
221 IVBSAXErrorHandler_fatalError(This->saxreader->vberrorHandler,
222 (IVBSAXLocator*)&This->lpVBSAXLocatorVtbl, &bstrMsg, hr);
225 ISAXErrorHandler_fatalError(This->saxreader->errorHandler,
226 (ISAXLocator*)&This->lpSAXLocatorVtbl, msg, hr);
230 static void update_position(saxlocator *This, xmlChar *end)
232 if(This->lastCur == NULL)
234 This->lastCur = (xmlChar*)This->pParserCtxt->input->base;
236 This->realColumn = 1;
238 else if(This->lastCur < This->pParserCtxt->input->base)
240 This->lastCur = (xmlChar*)This->pParserCtxt->input->base;
242 This->realColumn = 1;
245 if(This->pParserCtxt->input->cur<This->lastCur)
247 This->lastCur = (xmlChar*)This->pParserCtxt->input->base;
249 This->realColumn = 1;
252 if(!end) end = (xmlChar*)This->pParserCtxt->input->cur;
254 while(This->lastCur < end)
256 if(*(This->lastCur) == '\n')
259 This->realColumn = 1;
261 else if(*(This->lastCur) == '\r' &&
262 (This->lastCur==This->pParserCtxt->input->end ||
263 *(This->lastCur+1)!='\n'))
266 This->realColumn = 1;
268 else This->realColumn++;
272 /* Count multibyte UTF8 encoded characters once */
273 while((*(This->lastCur)&0xC0) == 0x80) This->lastCur++;
276 This->line = This->realLine;
277 This->column = This->realColumn;
280 /*** IVBSAXAttributes interface ***/
281 /*** IUnknown methods ***/
282 static HRESULT WINAPI ivbsaxattributes_QueryInterface(
283 IVBSAXAttributes* iface,
287 saxattributes *This = impl_from_IVBSAXAttributes(iface);
289 TRACE("%p %s %p\n", This, debugstr_guid(riid), ppvObject);
293 if (IsEqualGUID(riid, &IID_IUnknown) ||
294 IsEqualGUID(riid, &IID_IDispatch) ||
295 IsEqualGUID(riid, &IID_IVBSAXAttributes))
301 FIXME("interface %s not implemented\n", debugstr_guid(riid));
302 return E_NOINTERFACE;
305 IVBSAXAttributes_AddRef(iface);
310 static ULONG WINAPI ivbsaxattributes_AddRef(IVBSAXAttributes* iface)
312 saxattributes *This = impl_from_IVBSAXAttributes(iface);
313 return ISAXAttributes_AddRef((ISAXAttributes*)&This->lpSAXAttributesVtbl);
316 static ULONG WINAPI ivbsaxattributes_Release(IVBSAXAttributes* iface)
318 saxattributes *This = impl_from_IVBSAXAttributes(iface);
319 return ISAXAttributes_Release((ISAXAttributes*)&This->lpSAXAttributesVtbl);
322 /*** IDispatch methods ***/
323 static HRESULT WINAPI ivbsaxattributes_GetTypeInfoCount( IVBSAXAttributes *iface, UINT* pctinfo )
325 saxattributes *This = impl_from_IVBSAXAttributes( iface );
327 TRACE("(%p)->(%p)\n", This, pctinfo);
334 static HRESULT WINAPI ivbsaxattributes_GetTypeInfo(
335 IVBSAXAttributes *iface,
336 UINT iTInfo, LCID lcid, ITypeInfo** ppTInfo )
338 saxattributes *This = impl_from_IVBSAXAttributes( iface );
341 TRACE("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo);
343 hr = get_typeinfo(IVBSAXAttributes_tid, ppTInfo);
348 static HRESULT WINAPI ivbsaxattributes_GetIDsOfNames(
349 IVBSAXAttributes *iface,
356 saxattributes *This = impl_from_IVBSAXAttributes( iface );
360 TRACE("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames, cNames,
363 if(!rgszNames || cNames == 0 || !rgDispId)
366 hr = get_typeinfo(IVBSAXAttributes_tid, &typeinfo);
369 hr = ITypeInfo_GetIDsOfNames(typeinfo, rgszNames, cNames, rgDispId);
370 ITypeInfo_Release(typeinfo);
376 static HRESULT WINAPI ivbsaxattributes_Invoke(
377 IVBSAXAttributes *iface,
382 DISPPARAMS* pDispParams,
384 EXCEPINFO* pExcepInfo,
387 saxattributes *This = impl_from_IVBSAXAttributes( iface );
391 TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
392 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
394 hr = get_typeinfo(IVBSAXAttributes_tid, &typeinfo);
397 hr = ITypeInfo_Invoke(typeinfo, &(This->lpVBSAXAttributesVtbl), dispIdMember, wFlags, pDispParams,
398 pVarResult, pExcepInfo, puArgErr);
399 ITypeInfo_Release(typeinfo);
405 /*** IVBSAXAttributes methods ***/
406 static HRESULT WINAPI ivbsaxattributes_get_length(
407 IVBSAXAttributes* iface,
410 saxattributes *This = impl_from_IVBSAXAttributes( iface );
411 return ISAXAttributes_getLength(
412 (ISAXAttributes*)&This->lpSAXAttributesVtbl,
416 static HRESULT WINAPI ivbsaxattributes_getURI(
417 IVBSAXAttributes* iface,
422 saxattributes *This = impl_from_IVBSAXAttributes( iface );
423 return ISAXAttributes_getURI(
424 (ISAXAttributes*)&This->lpSAXAttributesVtbl,
425 nIndex, (const WCHAR**)uri, &len);
428 static HRESULT WINAPI ivbsaxattributes_getLocalName(
429 IVBSAXAttributes* iface,
434 saxattributes *This = impl_from_IVBSAXAttributes( iface );
435 return ISAXAttributes_getLocalName(
436 (ISAXAttributes*)&This->lpSAXAttributesVtbl,
437 nIndex, (const WCHAR**)localName, &len);
440 static HRESULT WINAPI ivbsaxattributes_getQName(
441 IVBSAXAttributes* iface,
446 saxattributes *This = impl_from_IVBSAXAttributes( iface );
447 return ISAXAttributes_getQName(
448 (ISAXAttributes*)&This->lpSAXAttributesVtbl,
449 nIndex, (const WCHAR**)QName, &len);
452 static HRESULT WINAPI ivbsaxattributes_getIndexFromName(
453 IVBSAXAttributes* iface,
458 saxattributes *This = impl_from_IVBSAXAttributes( iface );
459 return ISAXAttributes_getIndexFromName(
460 (ISAXAttributes*)&This->lpSAXAttributesVtbl, uri, SysStringLen(uri),
461 localName, SysStringLen(localName), index);
464 static HRESULT WINAPI ivbsaxattributes_getIndexFromQName(
465 IVBSAXAttributes* iface,
469 saxattributes *This = impl_from_IVBSAXAttributes( iface );
470 return ISAXAttributes_getIndexFromQName(
471 (ISAXAttributes*)&This->lpSAXAttributesVtbl, QName,
472 SysStringLen(QName), index);
475 static HRESULT WINAPI ivbsaxattributes_getType(
476 IVBSAXAttributes* iface,
481 saxattributes *This = impl_from_IVBSAXAttributes( iface );
482 return ISAXAttributes_getType(
483 (ISAXAttributes*)&This->lpSAXAttributesVtbl,
484 nIndex, (const WCHAR**)type, &len);
487 static HRESULT WINAPI ivbsaxattributes_getTypeFromName(
488 IVBSAXAttributes* iface,
494 saxattributes *This = impl_from_IVBSAXAttributes( iface );
495 return ISAXAttributes_getTypeFromName(
496 (ISAXAttributes*)&This->lpSAXAttributesVtbl, uri, SysStringLen(uri),
497 localName, SysStringLen(localName), (const WCHAR**)type, &len);
500 static HRESULT WINAPI ivbsaxattributes_getTypeFromQName(
501 IVBSAXAttributes* iface,
506 saxattributes *This = impl_from_IVBSAXAttributes( iface );
507 return ISAXAttributes_getTypeFromQName(
508 (ISAXAttributes*)&This->lpSAXAttributesVtbl, QName,
509 SysStringLen(QName), (const WCHAR**)type, &len);
512 static HRESULT WINAPI ivbsaxattributes_getValue(
513 IVBSAXAttributes* iface,
518 saxattributes *This = impl_from_IVBSAXAttributes( iface );
519 return ISAXAttributes_getValue(
520 (ISAXAttributes*)&This->lpSAXAttributesVtbl,
521 nIndex, (const WCHAR**)value, &len);
524 static HRESULT WINAPI ivbsaxattributes_getValueFromName(
525 IVBSAXAttributes* iface,
531 saxattributes *This = impl_from_IVBSAXAttributes( iface );
532 return ISAXAttributes_getValueFromName(
533 (ISAXAttributes*)&This->lpSAXAttributesVtbl, uri, SysStringLen(uri),
534 localName, SysStringLen(localName), (const WCHAR**)value, &len);
537 static HRESULT WINAPI ivbsaxattributes_getValueFromQName(
538 IVBSAXAttributes* iface,
543 saxattributes *This = impl_from_IVBSAXAttributes( iface );
544 return ISAXAttributes_getValueFromQName(
545 (ISAXAttributes*)&This->lpSAXAttributesVtbl, QName,
546 SysStringLen(QName), (const WCHAR**)value, &len);
549 static const struct IVBSAXAttributesVtbl ivbsaxattributes_vtbl =
551 ivbsaxattributes_QueryInterface,
552 ivbsaxattributes_AddRef,
553 ivbsaxattributes_Release,
554 ivbsaxattributes_GetTypeInfoCount,
555 ivbsaxattributes_GetTypeInfo,
556 ivbsaxattributes_GetIDsOfNames,
557 ivbsaxattributes_Invoke,
558 ivbsaxattributes_get_length,
559 ivbsaxattributes_getURI,
560 ivbsaxattributes_getLocalName,
561 ivbsaxattributes_getQName,
562 ivbsaxattributes_getIndexFromName,
563 ivbsaxattributes_getIndexFromQName,
564 ivbsaxattributes_getType,
565 ivbsaxattributes_getTypeFromName,
566 ivbsaxattributes_getTypeFromQName,
567 ivbsaxattributes_getValue,
568 ivbsaxattributes_getValueFromName,
569 ivbsaxattributes_getValueFromQName
572 /*** ISAXAttributes interface ***/
573 /*** IUnknown methods ***/
574 static HRESULT WINAPI isaxattributes_QueryInterface(
575 ISAXAttributes* iface,
579 saxattributes *This = impl_from_ISAXAttributes(iface);
581 TRACE("%p %s %p\n", This, debugstr_guid(riid), ppvObject);
585 if (IsEqualGUID(riid, &IID_IUnknown) ||
586 IsEqualGUID(riid, &IID_ISAXAttributes))
592 FIXME("interface %s not implemented\n", debugstr_guid(riid));
593 return E_NOINTERFACE;
596 ISAXAttributes_AddRef(iface);
601 static ULONG WINAPI isaxattributes_AddRef(ISAXAttributes* iface)
603 saxattributes *This = impl_from_ISAXAttributes(iface);
605 return InterlockedIncrement(&This->ref);
608 static ULONG WINAPI isaxattributes_Release(ISAXAttributes* iface)
610 saxattributes *This = impl_from_ISAXAttributes(iface);
615 ref = InterlockedDecrement(&This->ref);
619 for(index=0; index<This->nb_attributes; index++)
621 SysFreeString(This->szLocalname[index]);
622 SysFreeString(This->szURI[index]);
623 SysFreeString(This->szValue[index]);
624 SysFreeString(This->szQName[index]);
627 HeapFree(GetProcessHeap(), 0, This->szLocalname);
628 HeapFree(GetProcessHeap(), 0, This->szURI);
629 HeapFree(GetProcessHeap(), 0, This->szValue);
630 HeapFree(GetProcessHeap(), 0, This->szQName);
632 HeapFree(GetProcessHeap(), 0, This);
638 /*** ISAXAttributes methods ***/
639 static HRESULT WINAPI isaxattributes_getLength(
640 ISAXAttributes* iface,
643 saxattributes *This = impl_from_ISAXAttributes( iface );
645 *length = This->nb_attributes;
646 TRACE("Length set to %d\n", *length);
650 static HRESULT WINAPI isaxattributes_getURI(
651 ISAXAttributes* iface,
656 saxattributes *This = impl_from_ISAXAttributes( iface );
657 TRACE("(%p)->(%d)\n", This, nIndex);
659 if(nIndex>=This->nb_attributes || nIndex<0) return E_INVALIDARG;
660 if(!pUrl || !pUriSize) return E_POINTER;
662 *pUriSize = SysStringLen(This->szURI[nIndex]);
663 *pUrl = This->szURI[nIndex];
668 static HRESULT WINAPI isaxattributes_getLocalName(
669 ISAXAttributes* iface,
671 const WCHAR **pLocalName,
672 int *pLocalNameLength)
674 saxattributes *This = impl_from_ISAXAttributes( iface );
675 TRACE("(%p)->(%d)\n", This, nIndex);
677 if(nIndex>=This->nb_attributes || nIndex<0) return E_INVALIDARG;
678 if(!pLocalName || !pLocalNameLength) return E_POINTER;
680 *pLocalNameLength = SysStringLen(This->szLocalname[nIndex]);
681 *pLocalName = This->szLocalname[nIndex];
686 static HRESULT WINAPI isaxattributes_getQName(
687 ISAXAttributes* iface,
689 const WCHAR **pQName,
692 saxattributes *This = impl_from_ISAXAttributes( iface );
693 TRACE("(%p)->(%d)\n", This, nIndex);
695 if(nIndex>=This->nb_attributes || nIndex<0) return E_INVALIDARG;
696 if(!pQName || !pQNameLength) return E_POINTER;
698 *pQNameLength = SysStringLen(This->szQName[nIndex]);
699 *pQName = This->szQName[nIndex];
704 static HRESULT WINAPI isaxattributes_getName(
705 ISAXAttributes* iface,
709 const WCHAR **pLocalName,
711 const WCHAR **pQName,
714 saxattributes *This = impl_from_ISAXAttributes( iface );
715 TRACE("(%p)->(%d)\n", This, nIndex);
717 if(nIndex>=This->nb_attributes || nIndex<0) return E_INVALIDARG;
718 if(!pUri || !pUriLength || !pLocalName || !pLocalNameSize
719 || !pQName || !pQNameLength) return E_POINTER;
721 *pUriLength = SysStringLen(This->szURI[nIndex]);
722 *pUri = This->szURI[nIndex];
723 *pLocalNameSize = SysStringLen(This->szLocalname[nIndex]);
724 *pLocalName = This->szLocalname[nIndex];
725 *pQNameLength = SysStringLen(This->szQName[nIndex]);
726 *pQName = This->szQName[nIndex];
731 static HRESULT WINAPI isaxattributes_getIndexFromName(
732 ISAXAttributes* iface,
735 const WCHAR *pLocalName,
739 saxattributes *This = impl_from_ISAXAttributes( iface );
741 TRACE("(%p)->(%s, %d, %s, %d)\n", This, debugstr_w(pUri), cUriLength,
742 debugstr_w(pLocalName), cocalNameLength);
744 if(!pUri || !pLocalName || !index) return E_POINTER;
746 for(i=0; i<This->nb_attributes; i++)
748 if(cUriLength!=SysStringLen(This->szURI[i])
749 || cocalNameLength!=SysStringLen(This->szLocalname[i]))
751 if(cUriLength && memcmp(pUri, This->szURI[i],
752 sizeof(WCHAR)*cUriLength))
754 if(cocalNameLength && memcmp(pLocalName, This->szLocalname[i],
755 sizeof(WCHAR)*cocalNameLength))
765 static HRESULT WINAPI isaxattributes_getIndexFromQName(
766 ISAXAttributes* iface,
771 saxattributes *This = impl_from_ISAXAttributes( iface );
773 TRACE("(%p)->(%s, %d)\n", This, debugstr_w(pQName), nQNameLength);
775 if(!pQName || !index) return E_POINTER;
776 if(!nQNameLength) return E_INVALIDARG;
778 for(i=0; i<This->nb_attributes; i++)
780 if(nQNameLength!=SysStringLen(This->szQName[i])) continue;
781 if(memcmp(pQName, This->szQName, sizeof(WCHAR)*nQNameLength)) continue;
790 static HRESULT WINAPI isaxattributes_getType(
791 ISAXAttributes* iface,
796 saxattributes *This = impl_from_ISAXAttributes( iface );
798 FIXME("(%p)->(%d) stub\n", This, nIndex);
802 static HRESULT WINAPI isaxattributes_getTypeFromName(
803 ISAXAttributes* iface,
806 const WCHAR *pLocalName,
811 saxattributes *This = impl_from_ISAXAttributes( iface );
813 FIXME("(%p)->(%s, %d, %s, %d) stub\n", This, debugstr_w(pUri), nUri,
814 debugstr_w(pLocalName), nLocalName);
818 static HRESULT WINAPI isaxattributes_getTypeFromQName(
819 ISAXAttributes* iface,
825 saxattributes *This = impl_from_ISAXAttributes( iface );
827 FIXME("(%p)->(%s, %d) stub\n", This, debugstr_w(pQName), nQName);
831 static HRESULT WINAPI isaxattributes_getValue(
832 ISAXAttributes* iface,
834 const WCHAR **pValue,
837 saxattributes *This = impl_from_ISAXAttributes( iface );
838 TRACE("(%p)->(%d)\n", This, nIndex);
840 if(nIndex>=This->nb_attributes || nIndex<0) return E_INVALIDARG;
841 if(!pValue || !nValue) return E_POINTER;
843 *nValue = SysStringLen(This->szValue[nIndex]);
844 *pValue = This->szValue[nIndex];
849 static HRESULT WINAPI isaxattributes_getValueFromName(
850 ISAXAttributes* iface,
853 const WCHAR *pLocalName,
855 const WCHAR **pValue,
860 saxattributes *This = impl_from_ISAXAttributes( iface );
861 TRACE("(%p)->(%s, %d, %s, %d)\n", This, debugstr_w(pUri), nUri,
862 debugstr_w(pLocalName), nLocalName);
864 hr = ISAXAttributes_getIndexFromName(iface,
865 pUri, nUri, pLocalName, nLocalName, &index);
866 if(hr==S_OK) hr = ISAXAttributes_getValue(iface, index, pValue, nValue);
871 static HRESULT WINAPI isaxattributes_getValueFromQName(
872 ISAXAttributes* iface,
875 const WCHAR **pValue,
880 saxattributes *This = impl_from_ISAXAttributes( iface );
881 TRACE("(%p)->(%s, %d)\n", This, debugstr_w(pQName), nQName);
883 hr = ISAXAttributes_getIndexFromQName(iface, pQName, nQName, &index);
884 if(hr==S_OK) hr = ISAXAttributes_getValue(iface, index, pValue, nValue);
889 static const struct ISAXAttributesVtbl isaxattributes_vtbl =
891 isaxattributes_QueryInterface,
892 isaxattributes_AddRef,
893 isaxattributes_Release,
894 isaxattributes_getLength,
895 isaxattributes_getURI,
896 isaxattributes_getLocalName,
897 isaxattributes_getQName,
898 isaxattributes_getName,
899 isaxattributes_getIndexFromName,
900 isaxattributes_getIndexFromQName,
901 isaxattributes_getType,
902 isaxattributes_getTypeFromName,
903 isaxattributes_getTypeFromQName,
904 isaxattributes_getValue,
905 isaxattributes_getValueFromName,
906 isaxattributes_getValueFromQName
909 static HRESULT SAXAttributes_create(saxattributes **attr,
910 int nb_namespaces, const xmlChar **xmlNamespaces,
911 int nb_attributes, const xmlChar **xmlAttributes)
913 saxattributes *attributes;
915 static const xmlChar xmlns[] = "xmlns";
917 attributes = HeapAlloc(GetProcessHeap(), 0, sizeof(*attributes));
919 return E_OUTOFMEMORY;
921 attributes->lpVBSAXAttributesVtbl = &ivbsaxattributes_vtbl;
922 attributes->lpSAXAttributesVtbl = &isaxattributes_vtbl;
925 attributes->nb_attributes = nb_namespaces+nb_attributes;
927 attributes->szLocalname =
928 HeapAlloc(GetProcessHeap(), 0, sizeof(BSTR)*attributes->nb_attributes);
930 HeapAlloc(GetProcessHeap(), 0, sizeof(BSTR)*attributes->nb_attributes);
931 attributes->szValue =
932 HeapAlloc(GetProcessHeap(), 0, sizeof(BSTR)*attributes->nb_attributes);
933 attributes->szQName =
934 HeapAlloc(GetProcessHeap(), 0, sizeof(BSTR)*attributes->nb_attributes);
936 if(!attributes->szLocalname || !attributes->szURI
937 || !attributes->szValue || !attributes->szQName)
939 HeapFree(GetProcessHeap(), 0, attributes->szLocalname);
940 HeapFree(GetProcessHeap(), 0, attributes->szURI);
941 HeapFree(GetProcessHeap(), 0, attributes->szValue);
942 HeapFree(GetProcessHeap(), 0, attributes->szQName);
943 HeapFree(GetProcessHeap(), 0, attributes);
947 for(index=0; index<nb_namespaces; index++)
949 attributes->szLocalname[index] = SysAllocStringLen(NULL, 0);
950 attributes->szURI[index] = SysAllocStringLen(NULL, 0);
951 attributes->szValue[index] = bstr_from_xmlChar(xmlNamespaces[2*index+1]);
952 attributes->szQName[index] = QName_from_xmlChar(xmlns, xmlNamespaces[2*index]);
955 for(index=0; index<nb_attributes; index++)
957 attributes->szLocalname[nb_namespaces+index] =
958 bstr_from_xmlChar(xmlAttributes[index*5]);
959 attributes->szURI[nb_namespaces+index] =
960 bstr_from_xmlChar(xmlAttributes[index*5+2]);
961 attributes->szValue[nb_namespaces+index] =
962 bstr_from_xmlCharN(xmlAttributes[index*5+3],
963 xmlAttributes[index*5+4]-xmlAttributes[index*5+3]);
964 attributes->szQName[nb_namespaces+index] =
965 QName_from_xmlChar(xmlAttributes[index*5+1], xmlAttributes[index*5]);
970 TRACE("returning %p\n", *attr);
975 /*** LibXML callbacks ***/
976 static void libxmlStartDocument(void *ctx)
978 saxlocator *This = ctx;
981 if((This->vbInterface && This->saxreader->vbcontentHandler)
982 || (!This->vbInterface && This->saxreader->contentHandler))
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((This->vbInterface && This->saxreader->vbcontentHandler)
1007 || (!This->vbInterface && This->saxreader->contentHandler))
1009 if(This->vbInterface)
1010 hr = IVBSAXContentHandler_endDocument(This->saxreader->vbcontentHandler);
1012 hr = ISAXContentHandler_endDocument(This->saxreader->contentHandler);
1015 format_error_message_from_id(This, hr);
1019 static void libxmlStartElementNS(
1021 const xmlChar *localname,
1022 const xmlChar *prefix,
1025 const xmlChar **namespaces,
1028 const xmlChar **attributes)
1030 BSTR NamespaceUri, LocalName, QName, Prefix, Uri;
1031 saxlocator *This = ctx;
1033 saxattributes *attr;
1036 if(*(This->pParserCtxt->input->cur) == '/')
1037 update_position(This, (xmlChar*)This->pParserCtxt->input->cur+2);
1039 update_position(This, (xmlChar*)This->pParserCtxt->input->cur+1);
1041 hr = namespacePush(This, nb_namespaces);
1042 if(hr==S_OK && ((This->vbInterface && This->saxreader->vbcontentHandler)
1043 || (!This->vbInterface && This->saxreader->contentHandler)))
1045 for(index=0; index<nb_namespaces; index++)
1047 Prefix = bstr_from_xmlChar(namespaces[2*index]);
1048 Uri = bstr_from_xmlChar(namespaces[2*index+1]);
1050 if(This->vbInterface)
1051 hr = IVBSAXContentHandler_startPrefixMapping(
1052 This->saxreader->vbcontentHandler,
1055 hr = ISAXContentHandler_startPrefixMapping(
1056 This->saxreader->contentHandler,
1057 Prefix, SysStringLen(Prefix),
1058 Uri, SysStringLen(Uri));
1060 SysFreeString(Prefix);
1065 format_error_message_from_id(This, hr);
1070 NamespaceUri = bstr_from_xmlChar(URI);
1071 LocalName = bstr_from_xmlChar(localname);
1072 QName = QName_from_xmlChar(prefix, localname);
1074 hr = SAXAttributes_create(&attr, nb_namespaces, namespaces, nb_attributes, attributes);
1077 if(This->vbInterface)
1078 hr = IVBSAXContentHandler_startElement(
1079 This->saxreader->vbcontentHandler,
1080 &NamespaceUri, &LocalName, &QName,
1081 (IVBSAXAttributes*)&attr->lpVBSAXAttributesVtbl);
1083 hr = ISAXContentHandler_startElement(
1084 This->saxreader->contentHandler,
1085 NamespaceUri, SysStringLen(NamespaceUri),
1086 LocalName, SysStringLen(LocalName),
1087 QName, SysStringLen(QName),
1088 (ISAXAttributes*)&attr->lpSAXAttributesVtbl);
1090 ISAXAttributes_Release((ISAXAttributes*)&attr->lpSAXAttributesVtbl);
1093 SysFreeString(NamespaceUri);
1094 SysFreeString(LocalName);
1095 SysFreeString(QName);
1099 format_error_message_from_id(This, hr);
1102 static void libxmlEndElementNS(
1104 const xmlChar *localname,
1105 const xmlChar *prefix,
1108 BSTR NamespaceUri, LocalName, QName, Prefix;
1109 saxlocator *This = ctx;
1114 end = (xmlChar*)This->pParserCtxt->input->cur;
1115 if(*(end-1) != '>' || *(end-2) != '/')
1116 while(*(end-2)!='<' && *(end-1)!='/') end--;
1118 update_position(This, end);
1120 nsNr = namespacePop(This);
1122 if((This->vbInterface && This->saxreader->vbcontentHandler)
1123 || (!This->vbInterface && This->saxreader->contentHandler))
1125 NamespaceUri = bstr_from_xmlChar(URI);
1126 LocalName = bstr_from_xmlChar(localname);
1127 QName = QName_from_xmlChar(prefix, localname);
1129 if(This->vbInterface)
1130 hr = IVBSAXContentHandler_endElement(
1131 This->saxreader->vbcontentHandler,
1132 &NamespaceUri, &LocalName, &QName);
1134 hr = ISAXContentHandler_endElement(
1135 This->saxreader->contentHandler,
1136 NamespaceUri, SysStringLen(NamespaceUri),
1137 LocalName, SysStringLen(LocalName),
1138 QName, SysStringLen(QName));
1140 SysFreeString(NamespaceUri);
1141 SysFreeString(LocalName);
1142 SysFreeString(QName);
1146 format_error_message_from_id(This, hr);
1150 for(index=This->pParserCtxt->nsNr-2;
1151 index>=This->pParserCtxt->nsNr-nsNr*2; index-=2)
1153 Prefix = bstr_from_xmlChar(This->pParserCtxt->nsTab[index]);
1155 if(This->vbInterface)
1156 hr = IVBSAXContentHandler_endPrefixMapping(
1157 This->saxreader->vbcontentHandler, &Prefix);
1159 hr = ISAXContentHandler_endPrefixMapping(
1160 This->saxreader->contentHandler,
1161 Prefix, SysStringLen(Prefix));
1163 SysFreeString(Prefix);
1167 format_error_message_from_id(This, hr);
1174 update_position(This, NULL);
1177 static void libxmlCharacters(
1182 saxlocator *This = ctx;
1187 BOOL lastEvent = FALSE;
1189 if((This->vbInterface && !This->saxreader->vbcontentHandler)
1190 || (!This->vbInterface && !This->saxreader->contentHandler))
1194 if(*(ch-1)=='\r') cur--;
1197 if(ch<This->pParserCtxt->input->base || ch>This->pParserCtxt->input->end)
1202 while(end-ch<len && *end!='\r') end++;
1209 if(!lastEvent) *end = '\n';
1211 Chars = bstr_from_xmlCharN(cur, end-cur+1);
1212 if(This->vbInterface)
1213 hr = IVBSAXContentHandler_characters(
1214 This->saxreader->vbcontentHandler, &Chars);
1216 hr = ISAXContentHandler_characters(
1217 This->saxreader->contentHandler,
1218 Chars, SysStringLen(Chars));
1219 SysFreeString(Chars);
1223 format_error_message_from_id(This, hr);
1227 This->column += end-cur+1;
1241 if(end-ch == len) break;
1244 if(ch<This->pParserCtxt->input->base || ch>This->pParserCtxt->input->end)
1245 This->column = This->realColumn
1246 +This->pParserCtxt->input->cur-This->lastCur;
1249 static void libxmlSetDocumentLocator(
1251 xmlSAXLocatorPtr loc)
1253 saxlocator *This = ctx;
1256 if(This->vbInterface)
1257 hr = IVBSAXContentHandler_putref_documentLocator(
1258 This->saxreader->vbcontentHandler,
1259 (IVBSAXLocator*)&This->lpVBSAXLocatorVtbl);
1261 hr = ISAXContentHandler_putDocumentLocator(
1262 This->saxreader->contentHandler,
1263 (ISAXLocator*)&This->lpSAXLocatorVtbl);
1266 format_error_message_from_id(This, hr);
1269 static void libxmlComment(void *ctx, const xmlChar *value)
1271 saxlocator *This = ctx;
1274 xmlChar *beg = (xmlChar*)This->pParserCtxt->input->cur;
1276 while(memcmp(beg-4, "<!--", sizeof(char[4]))) beg--;
1277 update_position(This, beg);
1279 if(!This->vbInterface && !This->saxreader->lexicalHandler) return;
1280 if(This->vbInterface && !This->saxreader->vblexicalHandler) return;
1282 bValue = bstr_from_xmlChar(value);
1284 if(This->vbInterface)
1285 hr = IVBSAXLexicalHandler_comment(
1286 This->saxreader->vblexicalHandler, &bValue);
1288 hr = ISAXLexicalHandler_comment(
1289 This->saxreader->lexicalHandler,
1290 bValue, SysStringLen(bValue));
1292 SysFreeString(bValue);
1295 format_error_message_from_id(This, hr);
1297 update_position(This, NULL);
1300 static void libxmlFatalError(void *ctx, const char *msg, ...)
1302 saxlocator *This = ctx;
1308 if((This->vbInterface && !This->saxreader->vberrorHandler)
1309 || (!This->vbInterface && !This->saxreader->errorHandler))
1311 xmlStopParser(This->pParserCtxt);
1316 FIXME("Error handling is not compatible.\n");
1318 va_start(args, msg);
1319 vsprintf(message, msg, args);
1322 len = MultiByteToWideChar(CP_UNIXCP, 0, message, -1, NULL, 0);
1323 wszError = HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR)*len);
1325 MultiByteToWideChar(CP_UNIXCP, 0, message, -1, wszError, len);
1327 if(This->vbInterface)
1329 BSTR bstrError = SysAllocString(wszError);
1330 IVBSAXErrorHandler_fatalError(This->saxreader->vberrorHandler,
1331 (IVBSAXLocator*)&This->lpVBSAXLocatorVtbl, &bstrError, E_FAIL);
1334 ISAXErrorHandler_fatalError(This->saxreader->errorHandler,
1335 (ISAXLocator*)&This->lpSAXLocatorVtbl, wszError, E_FAIL);
1337 HeapFree(GetProcessHeap(), 0, wszError);
1339 xmlStopParser(This->pParserCtxt);
1343 static void libxmlCDataBlock(void *ctx, const xmlChar *value, int len)
1345 saxlocator *This = ctx;
1347 xmlChar *beg = (xmlChar*)This->pParserCtxt->input->cur-len;
1351 BOOL lastEvent = FALSE, change;
1353 while(memcmp(beg-9, "<![CDATA[", sizeof(char[9]))) beg--;
1354 update_position(This, beg);
1356 if(This->vbInterface && This->saxreader->vblexicalHandler)
1357 hr = IVBSAXLexicalHandler_startCDATA(This->saxreader->vblexicalHandler);
1358 if(!This->vbInterface && This->saxreader->lexicalHandler)
1359 hr = ISAXLexicalHandler_startCDATA(This->saxreader->lexicalHandler);
1363 format_error_message_from_id(This, hr);
1367 realLen = This->pParserCtxt->input->cur-beg-3;
1373 while(end-beg<realLen && *end!='\r') end++;
1374 if(end-beg==realLen)
1379 else if(end-beg==realLen-1 && *end=='\r' && *(end+1)=='\n')
1382 if(*end == '\r') change = TRUE;
1383 else change = FALSE;
1385 if(change) *end = '\n';
1387 if((This->vbInterface && This->saxreader->vbcontentHandler) ||
1388 (!This->vbInterface && This->saxreader->contentHandler))
1390 Chars = bstr_from_xmlCharN(cur, end-cur+1);
1391 if(This->vbInterface)
1392 hr = IVBSAXContentHandler_characters(
1393 This->saxreader->vbcontentHandler, &Chars);
1395 hr = ISAXContentHandler_characters(
1396 This->saxreader->contentHandler,
1397 Chars, SysStringLen(Chars));
1398 SysFreeString(Chars);
1401 if(change) *end = '\r';
1406 This->column += end-cur+2;
1411 if(This->vbInterface && This->saxreader->vblexicalHandler)
1412 hr = IVBSAXLexicalHandler_endCDATA(This->saxreader->vblexicalHandler);
1413 if(!This->vbInterface && This->saxreader->lexicalHandler)
1414 hr = ISAXLexicalHandler_endCDATA(This->saxreader->lexicalHandler);
1417 format_error_message_from_id(This, hr);
1419 This->column += 4+end-cur;
1422 /*** IVBSAXLocator interface ***/
1423 /*** IUnknown methods ***/
1424 static HRESULT WINAPI ivbsaxlocator_QueryInterface(IVBSAXLocator* iface, REFIID riid, void **ppvObject)
1426 saxlocator *This = impl_from_IVBSAXLocator( iface );
1428 TRACE("%p %s %p\n", This, debugstr_guid( riid ), ppvObject);
1432 if ( IsEqualGUID( riid, &IID_IUnknown ) ||
1433 IsEqualGUID( riid, &IID_IDispatch) ||
1434 IsEqualGUID( riid, &IID_IVBSAXLocator ))
1440 FIXME("interface %s not implemented\n", debugstr_guid(riid));
1441 return E_NOINTERFACE;
1444 IVBSAXLocator_AddRef( iface );
1449 static ULONG WINAPI ivbsaxlocator_AddRef(IVBSAXLocator* iface)
1451 saxlocator *This = impl_from_IVBSAXLocator( iface );
1452 TRACE("%p\n", This );
1453 return InterlockedIncrement( &This->ref );
1456 static ULONG WINAPI ivbsaxlocator_Release(
1457 IVBSAXLocator* iface)
1459 saxlocator *This = impl_from_IVBSAXLocator( iface );
1460 return ISAXLocator_Release((ISAXLocator*)&This->lpVBSAXLocatorVtbl);
1463 /*** IDispatch methods ***/
1464 static HRESULT WINAPI ivbsaxlocator_GetTypeInfoCount( IVBSAXLocator *iface, UINT* pctinfo )
1466 saxlocator *This = impl_from_IVBSAXLocator( iface );
1468 TRACE("(%p)->(%p)\n", This, pctinfo);
1475 static HRESULT WINAPI ivbsaxlocator_GetTypeInfo(
1476 IVBSAXLocator *iface,
1477 UINT iTInfo, LCID lcid, ITypeInfo** ppTInfo )
1479 saxlocator *This = impl_from_IVBSAXLocator( iface );
1482 TRACE("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo);
1484 hr = get_typeinfo(IVBSAXLocator_tid, ppTInfo);
1489 static HRESULT WINAPI ivbsaxlocator_GetIDsOfNames(
1490 IVBSAXLocator *iface,
1492 LPOLESTR* rgszNames,
1497 saxlocator *This = impl_from_IVBSAXLocator( iface );
1498 ITypeInfo *typeinfo;
1501 TRACE("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames, cNames,
1504 if(!rgszNames || cNames == 0 || !rgDispId)
1505 return E_INVALIDARG;
1507 hr = get_typeinfo(IVBSAXLocator_tid, &typeinfo);
1510 hr = ITypeInfo_GetIDsOfNames(typeinfo, rgszNames, cNames, rgDispId);
1511 ITypeInfo_Release(typeinfo);
1517 static HRESULT WINAPI ivbsaxlocator_Invoke(
1518 IVBSAXLocator *iface,
1519 DISPID dispIdMember,
1523 DISPPARAMS* pDispParams,
1524 VARIANT* pVarResult,
1525 EXCEPINFO* pExcepInfo,
1528 saxlocator *This = impl_from_IVBSAXLocator( iface );
1529 ITypeInfo *typeinfo;
1532 TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
1533 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
1535 hr = get_typeinfo(IVBSAXLocator_tid, &typeinfo);
1538 hr = ITypeInfo_Invoke(typeinfo, &(This->lpVBSAXLocatorVtbl), dispIdMember, wFlags, pDispParams,
1539 pVarResult, pExcepInfo, puArgErr);
1540 ITypeInfo_Release(typeinfo);
1546 /*** IVBSAXLocator methods ***/
1547 static HRESULT WINAPI ivbsaxlocator_get_columnNumber(
1548 IVBSAXLocator* iface,
1551 saxlocator *This = impl_from_IVBSAXLocator( iface );
1552 return ISAXLocator_getColumnNumber(
1553 (ISAXLocator*)&This->lpVBSAXLocatorVtbl,
1557 static HRESULT WINAPI ivbsaxlocator_get_lineNumber(
1558 IVBSAXLocator* iface,
1561 saxlocator *This = impl_from_IVBSAXLocator( iface );
1562 return ISAXLocator_getLineNumber(
1563 (ISAXLocator*)&This->lpVBSAXLocatorVtbl,
1567 static HRESULT WINAPI ivbsaxlocator_get_publicId(
1568 IVBSAXLocator* iface,
1571 saxlocator *This = impl_from_IVBSAXLocator( iface );
1572 return ISAXLocator_getPublicId(
1573 (ISAXLocator*)&This->lpVBSAXLocatorVtbl,
1574 (const WCHAR**)publicId);
1577 static HRESULT WINAPI ivbsaxlocator_get_systemId(
1578 IVBSAXLocator* iface,
1581 saxlocator *This = impl_from_IVBSAXLocator( iface );
1582 return ISAXLocator_getSystemId(
1583 (ISAXLocator*)&This->lpVBSAXLocatorVtbl,
1584 (const WCHAR**)systemId);
1587 static const struct IVBSAXLocatorVtbl ivbsaxlocator_vtbl =
1589 ivbsaxlocator_QueryInterface,
1590 ivbsaxlocator_AddRef,
1591 ivbsaxlocator_Release,
1592 ivbsaxlocator_GetTypeInfoCount,
1593 ivbsaxlocator_GetTypeInfo,
1594 ivbsaxlocator_GetIDsOfNames,
1595 ivbsaxlocator_Invoke,
1596 ivbsaxlocator_get_columnNumber,
1597 ivbsaxlocator_get_lineNumber,
1598 ivbsaxlocator_get_publicId,
1599 ivbsaxlocator_get_systemId
1602 /*** ISAXLocator interface ***/
1603 /*** IUnknown methods ***/
1604 static HRESULT WINAPI isaxlocator_QueryInterface(ISAXLocator* iface, REFIID riid, void **ppvObject)
1606 saxlocator *This = impl_from_ISAXLocator( iface );
1608 TRACE("%p %s %p\n", This, debugstr_guid( riid ), ppvObject );
1612 if ( IsEqualGUID( riid, &IID_IUnknown ) ||
1613 IsEqualGUID( riid, &IID_ISAXLocator ))
1619 FIXME("interface %s not implemented\n", debugstr_guid(riid));
1620 return E_NOINTERFACE;
1623 ISAXLocator_AddRef( iface );
1628 static ULONG WINAPI isaxlocator_AddRef(ISAXLocator* iface)
1630 saxlocator *This = impl_from_ISAXLocator( iface );
1631 TRACE("%p\n", This );
1632 return InterlockedIncrement( &This->ref );
1635 static ULONG WINAPI isaxlocator_Release(
1638 saxlocator *This = impl_from_ISAXLocator( iface );
1641 TRACE("%p\n", This );
1643 ref = InterlockedDecrement( &This->ref );
1646 SysFreeString(This->publicId);
1647 SysFreeString(This->systemId);
1648 HeapFree(GetProcessHeap(), 0, This->nsStack);
1650 ISAXXMLReader_Release((ISAXXMLReader*)&This->saxreader->lpSAXXMLReaderVtbl);
1651 HeapFree( GetProcessHeap(), 0, This );
1657 /*** ISAXLocator methods ***/
1658 static HRESULT WINAPI isaxlocator_getColumnNumber(
1662 saxlocator *This = impl_from_ISAXLocator( iface );
1664 *pnColumn = This->column;
1668 static HRESULT WINAPI isaxlocator_getLineNumber(
1672 saxlocator *This = impl_from_ISAXLocator( iface );
1674 *pnLine = This->line;
1678 static HRESULT WINAPI isaxlocator_getPublicId(
1680 const WCHAR ** ppwchPublicId)
1683 saxlocator *This = impl_from_ISAXLocator( iface );
1685 SysFreeString(This->publicId);
1687 publicId = bstr_from_xmlChar(xmlSAX2GetPublicId(This->pParserCtxt));
1688 if(SysStringLen(publicId))
1689 This->publicId = (WCHAR*)&publicId;
1692 SysFreeString(publicId);
1693 This->publicId = NULL;
1696 *ppwchPublicId = This->publicId;
1700 static HRESULT WINAPI isaxlocator_getSystemId(
1702 const WCHAR ** ppwchSystemId)
1705 saxlocator *This = impl_from_ISAXLocator( iface );
1707 SysFreeString(This->systemId);
1709 systemId = bstr_from_xmlChar(xmlSAX2GetSystemId(This->pParserCtxt));
1710 if(SysStringLen(systemId))
1711 This->systemId = (WCHAR*)&systemId;
1714 SysFreeString(systemId);
1715 This->systemId = NULL;
1718 *ppwchSystemId = This->systemId;
1722 static const struct ISAXLocatorVtbl isaxlocator_vtbl =
1724 isaxlocator_QueryInterface,
1726 isaxlocator_Release,
1727 isaxlocator_getColumnNumber,
1728 isaxlocator_getLineNumber,
1729 isaxlocator_getPublicId,
1730 isaxlocator_getSystemId
1733 static HRESULT SAXLocator_create(saxreader *reader, saxlocator **ppsaxlocator, BOOL vbInterface)
1735 saxlocator *locator;
1737 locator = HeapAlloc( GetProcessHeap(), 0, sizeof (*locator) );
1739 return E_OUTOFMEMORY;
1741 locator->lpVBSAXLocatorVtbl = &ivbsaxlocator_vtbl;
1742 locator->lpSAXLocatorVtbl = &isaxlocator_vtbl;
1744 locator->vbInterface = vbInterface;
1746 locator->saxreader = reader;
1747 ISAXXMLReader_AddRef((ISAXXMLReader*)&reader->lpSAXXMLReaderVtbl);
1749 locator->pParserCtxt = NULL;
1750 locator->publicId = NULL;
1751 locator->systemId = NULL;
1752 locator->lastCur = NULL;
1754 locator->column = 0;
1755 locator->ret = S_OK;
1756 locator->nsStackSize = 8;
1757 locator->nsStackLast = 0;
1758 locator->nsStack = HeapAlloc(GetProcessHeap(), 0, locator->nsStackSize);
1759 if(!locator->nsStack)
1761 ISAXXMLReader_Release((ISAXXMLReader*)&reader->lpSAXXMLReaderVtbl);
1762 HeapFree(GetProcessHeap(), 0, locator);
1763 return E_OUTOFMEMORY;
1766 *ppsaxlocator = locator;
1768 TRACE("returning %p\n", *ppsaxlocator);
1773 /*** SAXXMLReader internal functions ***/
1774 static HRESULT internal_parseBuffer(saxreader *This, const char *buffer, int size, BOOL vbInterface)
1776 saxlocator *locator;
1779 hr = SAXLocator_create(This, &locator, vbInterface);
1783 locator->pParserCtxt = xmlCreateMemoryParserCtxt(buffer, size);
1784 if(!locator->pParserCtxt)
1786 ISAXLocator_Release((ISAXLocator*)&locator->lpSAXLocatorVtbl);
1790 locator->pParserCtxt->sax = &locator->saxreader->sax;
1791 locator->pParserCtxt->userData = locator;
1793 This->isParsing = TRUE;
1794 if(xmlParseDocument(locator->pParserCtxt)) hr = E_FAIL;
1795 else hr = locator->ret;
1796 This->isParsing = FALSE;
1798 if(locator->pParserCtxt)
1800 locator->pParserCtxt->sax = NULL;
1801 xmlFreeParserCtxt(locator->pParserCtxt);
1802 locator->pParserCtxt = NULL;
1805 ISAXLocator_Release((ISAXLocator*)&locator->lpSAXLocatorVtbl);
1809 static HRESULT internal_parseStream(saxreader *This, IStream *stream, BOOL vbInterface)
1811 saxlocator *locator;
1816 hr = IStream_Read(stream, data, sizeof(data), &dataRead);
1820 hr = SAXLocator_create(This, &locator, vbInterface);
1824 locator->pParserCtxt = xmlCreatePushParserCtxt(
1825 &locator->saxreader->sax, locator,
1826 data, dataRead, NULL);
1827 if(!locator->pParserCtxt)
1829 ISAXLocator_Release((ISAXLocator*)&locator->lpSAXLocatorVtbl);
1833 This->isParsing = TRUE;
1836 hr = IStream_Read(stream, data, sizeof(data), &dataRead);
1840 if(xmlParseChunk(locator->pParserCtxt, data, dataRead, 0)) hr = E_FAIL;
1841 else hr = locator->ret;
1843 if(hr != S_OK) break;
1845 if(dataRead != sizeof(data))
1847 if(xmlParseChunk(locator->pParserCtxt, data, 0, 1)) hr = E_FAIL;
1848 else hr = locator->ret;
1853 This->isParsing = FALSE;
1855 locator->pParserCtxt->sax = NULL;
1856 xmlFreeParserCtxt(locator->pParserCtxt);
1857 locator->pParserCtxt = NULL;
1858 ISAXLocator_Release((ISAXLocator*)&locator->lpSAXLocatorVtbl);
1862 static HRESULT internal_getEntityResolver(
1864 void *pEntityResolver,
1867 FIXME("(%p)->(%p) stub\n", This, pEntityResolver);
1871 static HRESULT internal_putEntityResolver(
1873 void *pEntityResolver,
1876 FIXME("(%p)->(%p) stub\n", This, pEntityResolver);
1880 static HRESULT internal_getContentHandler(
1882 void *pContentHandler,
1885 TRACE("(%p)->(%p)\n", This, pContentHandler);
1886 if(pContentHandler == NULL)
1888 if((vbInterface && This->vbcontentHandler)
1889 || (!vbInterface && This->contentHandler))
1892 IVBSAXContentHandler_AddRef(This->vbcontentHandler);
1894 ISAXContentHandler_AddRef(This->contentHandler);
1896 if(vbInterface) *(IVBSAXContentHandler**)pContentHandler =
1897 This->vbcontentHandler;
1898 else *(ISAXContentHandler**)pContentHandler = This->contentHandler;
1903 static HRESULT internal_putContentHandler(
1905 void *contentHandler,
1908 TRACE("(%p)->(%p)\n", This, contentHandler);
1912 IVBSAXContentHandler_AddRef((IVBSAXContentHandler*)contentHandler);
1914 ISAXContentHandler_AddRef((ISAXContentHandler*)contentHandler);
1916 if((vbInterface && This->vbcontentHandler)
1917 || (!vbInterface && This->contentHandler))
1920 IVBSAXContentHandler_Release(This->vbcontentHandler);
1922 ISAXContentHandler_Release(This->contentHandler);
1925 This->vbcontentHandler = contentHandler;
1927 This->contentHandler = contentHandler;
1932 static HRESULT internal_getDTDHandler(
1937 FIXME("(%p)->(%p) stub\n", This, pDTDHandler);
1941 static HRESULT internal_putDTDHandler(
1946 FIXME("(%p)->(%p) stub\n", This, pDTDHandler);
1950 static HRESULT internal_getErrorHandler(
1952 void *pErrorHandler,
1955 TRACE("(%p)->(%p)\n", This, pErrorHandler);
1956 if(pErrorHandler == NULL)
1959 if(vbInterface && This->vberrorHandler)
1960 IVBSAXErrorHandler_AddRef(This->vberrorHandler);
1961 else if(!vbInterface && This->errorHandler)
1962 ISAXErrorHandler_AddRef(This->errorHandler);
1965 *(IVBSAXErrorHandler**)pErrorHandler = This->vberrorHandler;
1967 *(ISAXErrorHandler**)pErrorHandler = This->errorHandler;
1973 static HRESULT internal_putErrorHandler(
1978 TRACE("(%p)->(%p)\n", This, errorHandler);
1982 IVBSAXErrorHandler_AddRef((IVBSAXErrorHandler*)errorHandler);
1984 ISAXErrorHandler_AddRef((ISAXErrorHandler*)errorHandler);
1987 if(vbInterface && This->vberrorHandler)
1988 IVBSAXErrorHandler_Release(This->vberrorHandler);
1989 else if(!vbInterface && This->errorHandler)
1990 ISAXErrorHandler_Release(This->errorHandler);
1993 This->vberrorHandler = errorHandler;
1995 This->errorHandler = errorHandler;
2001 static HRESULT internal_parse(
2008 TRACE("(%p)\n", This);
2011 switch(V_VT(&varInput))
2014 hr = internal_parseBuffer(This, (const char*)V_BSTR(&varInput),
2015 SysStringByteLen(V_BSTR(&varInput)), vbInterface);
2017 case VT_ARRAY|VT_UI1: {
2019 LONG lBound, uBound;
2022 hr = SafeArrayGetLBound(V_ARRAY(&varInput), 1, &lBound);
2023 if(hr != S_OK) break;
2024 hr = SafeArrayGetUBound(V_ARRAY(&varInput), 1, &uBound);
2025 if(hr != S_OK) break;
2026 dataRead = (uBound-lBound)*SafeArrayGetElemsize(V_ARRAY(&varInput));
2027 hr = SafeArrayAccessData(V_ARRAY(&varInput), &pSAData);
2028 if(hr != S_OK) break;
2029 hr = internal_parseBuffer(This, pSAData, dataRead, vbInterface);
2030 SafeArrayUnaccessData(V_ARRAY(&varInput));
2035 IPersistStream *persistStream;
2036 IStream *stream = NULL;
2037 IXMLDOMDocument *xmlDoc;
2039 if(IUnknown_QueryInterface(V_UNKNOWN(&varInput),
2040 &IID_IXMLDOMDocument, (void**)&xmlDoc) == S_OK)
2044 IXMLDOMDocument_get_xml(xmlDoc, &bstrData);
2045 hr = internal_parseBuffer(This, (const char*)bstrData,
2046 SysStringByteLen(bstrData), vbInterface);
2047 IXMLDOMDocument_Release(xmlDoc);
2050 if(IUnknown_QueryInterface(V_UNKNOWN(&varInput),
2051 &IID_IPersistStream, (void**)&persistStream) == S_OK)
2053 hr = IPersistStream_Save(persistStream, stream, TRUE);
2054 IPersistStream_Release(persistStream);
2055 if(hr != S_OK) break;
2057 if(stream || IUnknown_QueryInterface(V_UNKNOWN(&varInput),
2058 &IID_IStream, (void**)&stream) == S_OK)
2060 hr = internal_parseStream(This, stream, vbInterface);
2061 IStream_Release(stream);
2066 WARN("vt %d not implemented\n", V_VT(&varInput));
2073 static HRESULT internal_vbonDataAvailable(void *obj, char *ptr, DWORD len)
2075 saxreader *This = obj;
2077 return internal_parseBuffer(This, ptr, len, TRUE);
2080 static HRESULT internal_onDataAvailable(void *obj, char *ptr, DWORD len)
2082 saxreader *This = obj;
2084 return internal_parseBuffer(This, ptr, len, FALSE);
2087 static HRESULT internal_parseURL(
2095 TRACE("(%p)->(%s)\n", This, debugstr_w(url));
2097 if(vbInterface) hr = bind_url(url, internal_vbonDataAvailable, This, &bsc);
2098 else hr = bind_url(url, internal_onDataAvailable, This, &bsc);
2108 static HRESULT internal_putProperty(
2114 static const WCHAR wszCharset[] = {
2115 'c','h','a','r','s','e','t',0
2117 static const WCHAR wszDeclarationHandler[] = {
2118 'h','t','t','p',':','/','/','x','m','l','.','o','r','g','/',
2119 's','a','x','/','p','r','o','p','e','r','t','i','e','s','/',
2120 'd','e','c','l','a','r','a','t','i','o','n',
2121 '-','h','a','n','d','l','e','r',0
2123 static const WCHAR wszDomNode[] = {
2124 'h','t','t','p',':','/','/','x','m','l','.','o','r','g','/',
2125 's','a','x','/','p','r','o','p','e','r','t','i','e','s','/',
2126 'd','o','m','-','n','o','d','e',0
2128 static const WCHAR wszInputSource[] = {
2129 'i','n','p','u','t','-','s','o','u','r','c','e',0
2131 static const WCHAR wszLexicalHandler[] = {
2132 'h','t','t','p',':','/','/','x','m','l','.','o','r','g','/',
2133 's','a','x','/','p','r','o','p','e','r','t','i','e','s','/',
2134 'l','e','x','i','c','a','l','-','h','a','n','d','l','e','r',0
2136 static const WCHAR wszMaxElementDepth[] = {
2137 'm','a','x','-','e','l','e','m','e','n','t','-','d','e','p','t','h',0
2139 static const WCHAR wszMaxXMLSize[] = {
2140 'm','a','x','-','x','m','l','-','s','i','z','e',0
2142 static const WCHAR wszSchemaDeclarationHandler[] = {
2143 's','c','h','e','m','a','-',
2144 'd','e','c','l','a','r','a','t','i','o','n','-',
2145 'h','a','n','d','l','e','r',0
2147 static const WCHAR wszXMLDeclEncoding[] = {
2148 'x','m','l','d','e','c','l','-','e','n','c','o','d','i','n','g',0
2150 static const WCHAR wszXMLDeclStandalone[] = {
2151 'x','m','l','d','e','c','l',
2152 '-','s','t','a','n','d','a','l','o','n','e',0
2154 static const WCHAR wszXMLDeclVersion[] = {
2155 'x','m','l','d','e','c','l','-','v','e','r','s','i','o','n',0
2158 FIXME("(%p)->(%s): semi-stub\n", This, debugstr_w(pProp));
2160 if(!memcmp(pProp, wszCharset, sizeof(wszCharset)))
2163 if(!memcmp(pProp, wszDeclarationHandler, sizeof(wszDeclarationHandler)))
2165 if(This->isParsing) return E_FAIL;
2167 if(V_UNKNOWN(&value))
2170 IVBSAXDeclHandler_AddRef((IVBSAXDeclHandler*)V_UNKNOWN(&value));
2172 ISAXDeclHandler_AddRef((ISAXDeclHandler*)V_UNKNOWN(&value));
2174 if((vbInterface && This->vbdeclHandler)
2175 || (!vbInterface && This->declHandler))
2178 IVBSAXDeclHandler_Release(This->vbdeclHandler);
2180 ISAXDeclHandler_Release(This->declHandler);
2183 This->vbdeclHandler = (IVBSAXDeclHandler*)V_UNKNOWN(&value);
2185 This->declHandler = (ISAXDeclHandler*)V_UNKNOWN(&value);
2189 if(!memcmp(pProp, wszDomNode, sizeof(wszDomNode)))
2192 if(!memcmp(pProp, wszInputSource, sizeof(wszInputSource)))
2195 if(!memcmp(pProp, wszLexicalHandler, sizeof(wszLexicalHandler)))
2197 if(This->isParsing) return E_FAIL;
2199 if(V_UNKNOWN(&value))
2202 IVBSAXLexicalHandler_AddRef(
2203 (IVBSAXLexicalHandler*)V_UNKNOWN(&value));
2205 ISAXLexicalHandler_AddRef(
2206 (ISAXLexicalHandler*)V_UNKNOWN(&value));
2208 if((vbInterface && This->vblexicalHandler)
2209 || (!vbInterface && This->lexicalHandler))
2212 IVBSAXLexicalHandler_Release(This->vblexicalHandler);
2214 ISAXLexicalHandler_Release(This->lexicalHandler);
2217 This->vblexicalHandler = (IVBSAXLexicalHandler*)V_UNKNOWN(&value);
2219 This->lexicalHandler = (ISAXLexicalHandler*)V_UNKNOWN(&value);
2223 if(!memcmp(pProp, wszMaxElementDepth, sizeof(wszMaxElementDepth)))
2226 if(!memcmp(pProp, wszMaxXMLSize, sizeof(wszMaxXMLSize)))
2229 if(!memcmp(pProp, wszSchemaDeclarationHandler,
2230 sizeof(wszSchemaDeclarationHandler)))
2233 if(!memcmp(pProp, wszXMLDeclEncoding, sizeof(wszXMLDeclEncoding)))
2236 if(!memcmp(pProp, wszXMLDeclStandalone, sizeof(wszXMLDeclStandalone)))
2239 if(!memcmp(pProp, wszXMLDeclVersion, sizeof(wszXMLDeclVersion)))
2242 return E_INVALIDARG;
2245 /*** IVBSAXXMLReader interface ***/
2246 /*** IUnknown methods ***/
2247 static HRESULT WINAPI saxxmlreader_QueryInterface(IVBSAXXMLReader* iface, REFIID riid, void **ppvObject)
2249 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2251 TRACE("%p %s %p\n", This, debugstr_guid( riid ), ppvObject );
2255 if ( IsEqualGUID( riid, &IID_IUnknown ) ||
2256 IsEqualGUID( riid, &IID_IDispatch ) ||
2257 IsEqualGUID( riid, &IID_IVBSAXXMLReader ))
2261 else if( IsEqualGUID( riid, &IID_ISAXXMLReader ))
2263 *ppvObject = &This->lpSAXXMLReaderVtbl;
2267 FIXME("interface %s not implemented\n", debugstr_guid(riid));
2268 return E_NOINTERFACE;
2271 IVBSAXXMLReader_AddRef( iface );
2276 static ULONG WINAPI saxxmlreader_AddRef(IVBSAXXMLReader* iface)
2278 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2279 TRACE("%p\n", This );
2280 return InterlockedIncrement( &This->ref );
2283 static ULONG WINAPI saxxmlreader_Release(
2284 IVBSAXXMLReader* iface)
2286 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2289 TRACE("%p\n", This );
2291 ref = InterlockedDecrement( &This->ref );
2294 if(This->contentHandler)
2295 ISAXContentHandler_Release(This->contentHandler);
2297 if(This->vbcontentHandler)
2298 IVBSAXContentHandler_Release(This->vbcontentHandler);
2300 if(This->errorHandler)
2301 ISAXErrorHandler_Release(This->errorHandler);
2303 if(This->vberrorHandler)
2304 IVBSAXErrorHandler_Release(This->vberrorHandler);
2306 if(This->lexicalHandler)
2307 ISAXLexicalHandler_Release(This->lexicalHandler);
2309 if(This->vblexicalHandler)
2310 IVBSAXLexicalHandler_Release(This->vblexicalHandler);
2312 if(This->declHandler)
2313 ISAXDeclHandler_Release(This->declHandler);
2315 if(This->vbdeclHandler)
2316 IVBSAXDeclHandler_Release(This->vbdeclHandler);
2318 HeapFree( GetProcessHeap(), 0, This );
2324 static HRESULT WINAPI saxxmlreader_GetTypeInfoCount( IVBSAXXMLReader *iface, UINT* pctinfo )
2326 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2328 TRACE("(%p)->(%p)\n", This, pctinfo);
2335 static HRESULT WINAPI saxxmlreader_GetTypeInfo(
2336 IVBSAXXMLReader *iface,
2337 UINT iTInfo, LCID lcid, ITypeInfo** ppTInfo )
2339 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2342 TRACE("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo);
2344 hr = get_typeinfo(IVBSAXXMLReader_tid, ppTInfo);
2349 static HRESULT WINAPI saxxmlreader_GetIDsOfNames(
2350 IVBSAXXMLReader *iface,
2352 LPOLESTR* rgszNames,
2357 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2358 ITypeInfo *typeinfo;
2361 TRACE("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames, cNames,
2364 if(!rgszNames || cNames == 0 || !rgDispId)
2365 return E_INVALIDARG;
2367 hr = get_typeinfo(IVBSAXXMLReader_tid, &typeinfo);
2370 hr = ITypeInfo_GetIDsOfNames(typeinfo, rgszNames, cNames, rgDispId);
2371 ITypeInfo_Release(typeinfo);
2377 static HRESULT WINAPI saxxmlreader_Invoke(
2378 IVBSAXXMLReader *iface,
2379 DISPID dispIdMember,
2383 DISPPARAMS* pDispParams,
2384 VARIANT* pVarResult,
2385 EXCEPINFO* pExcepInfo,
2388 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2389 ITypeInfo *typeinfo;
2392 TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
2393 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
2395 hr = get_typeinfo(IVBSAXXMLReader_tid, &typeinfo);
2398 hr = ITypeInfo_Invoke(typeinfo, &(This->lpVBSAXXMLReaderVtbl), dispIdMember, wFlags, pDispParams,
2399 pVarResult, pExcepInfo, puArgErr);
2400 ITypeInfo_Release(typeinfo);
2406 /*** IVBSAXXMLReader methods ***/
2407 static HRESULT WINAPI saxxmlreader_getFeature(
2408 IVBSAXXMLReader* iface,
2409 const WCHAR *pFeature,
2410 VARIANT_BOOL *pValue)
2412 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2414 FIXME("(%p)->(%s %p) stub\n", This, debugstr_w(pFeature), pValue);
2418 static HRESULT WINAPI saxxmlreader_putFeature(
2419 IVBSAXXMLReader* iface,
2420 const WCHAR *pFeature,
2421 VARIANT_BOOL vfValue)
2423 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2425 FIXME("(%p)->(%s %x) stub\n", This, debugstr_w(pFeature), vfValue);
2429 static HRESULT WINAPI saxxmlreader_getProperty(
2430 IVBSAXXMLReader* iface,
2434 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2436 FIXME("(%p)->(%s %p) stub\n", This, debugstr_w(pProp), pValue);
2440 static HRESULT WINAPI saxxmlreader_putProperty(
2441 IVBSAXXMLReader* iface,
2445 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2446 return internal_putProperty(This, pProp, value, TRUE);
2449 static HRESULT WINAPI saxxmlreader_get_entityResolver(
2450 IVBSAXXMLReader* iface,
2451 IVBSAXEntityResolver **pEntityResolver)
2453 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2454 return internal_getEntityResolver(This, pEntityResolver, TRUE);
2457 static HRESULT WINAPI saxxmlreader_put_entityResolver(
2458 IVBSAXXMLReader* iface,
2459 IVBSAXEntityResolver *pEntityResolver)
2461 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2462 return internal_putEntityResolver(This, pEntityResolver, TRUE);
2465 static HRESULT WINAPI saxxmlreader_get_contentHandler(
2466 IVBSAXXMLReader* iface,
2467 IVBSAXContentHandler **ppContentHandler)
2469 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2470 return internal_getContentHandler(This, ppContentHandler, TRUE);
2473 static HRESULT WINAPI saxxmlreader_put_contentHandler(
2474 IVBSAXXMLReader* iface,
2475 IVBSAXContentHandler *contentHandler)
2477 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2478 return internal_putContentHandler(This, contentHandler, TRUE);
2481 static HRESULT WINAPI saxxmlreader_get_dtdHandler(
2482 IVBSAXXMLReader* iface,
2483 IVBSAXDTDHandler **pDTDHandler)
2485 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2486 return internal_getDTDHandler(This, pDTDHandler, TRUE);
2489 static HRESULT WINAPI saxxmlreader_put_dtdHandler(
2490 IVBSAXXMLReader* iface,
2491 IVBSAXDTDHandler *pDTDHandler)
2493 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2494 return internal_putDTDHandler(This, pDTDHandler, TRUE);
2497 static HRESULT WINAPI saxxmlreader_get_errorHandler(
2498 IVBSAXXMLReader* iface,
2499 IVBSAXErrorHandler **pErrorHandler)
2501 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2502 return internal_getErrorHandler(This, pErrorHandler, TRUE);
2505 static HRESULT WINAPI saxxmlreader_put_errorHandler(
2506 IVBSAXXMLReader* iface,
2507 IVBSAXErrorHandler *errorHandler)
2509 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2510 return internal_putErrorHandler(This, errorHandler, TRUE);
2513 static HRESULT WINAPI saxxmlreader_get_baseURL(
2514 IVBSAXXMLReader* iface,
2515 const WCHAR **pBaseUrl)
2517 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2519 FIXME("(%p)->(%p) stub\n", This, pBaseUrl);
2523 static HRESULT WINAPI saxxmlreader_put_baseURL(
2524 IVBSAXXMLReader* iface,
2525 const WCHAR *pBaseUrl)
2527 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2529 FIXME("(%p)->(%s) stub\n", This, debugstr_w(pBaseUrl));
2533 static HRESULT WINAPI saxxmlreader_get_secureBaseURL(
2534 IVBSAXXMLReader* iface,
2535 const WCHAR **pSecureBaseUrl)
2537 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2539 FIXME("(%p)->(%p) stub\n", This, pSecureBaseUrl);
2544 static HRESULT WINAPI saxxmlreader_put_secureBaseURL(
2545 IVBSAXXMLReader* iface,
2546 const WCHAR *secureBaseUrl)
2548 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2550 FIXME("(%p)->(%s) stub\n", This, debugstr_w(secureBaseUrl));
2554 static HRESULT WINAPI saxxmlreader_parse(
2555 IVBSAXXMLReader* iface,
2558 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2559 return internal_parse(This, varInput, TRUE);
2562 static HRESULT WINAPI saxxmlreader_parseURL(
2563 IVBSAXXMLReader* iface,
2566 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2567 return internal_parseURL(This, url, TRUE);
2570 static const struct IVBSAXXMLReaderVtbl saxreader_vtbl =
2572 saxxmlreader_QueryInterface,
2573 saxxmlreader_AddRef,
2574 saxxmlreader_Release,
2575 saxxmlreader_GetTypeInfoCount,
2576 saxxmlreader_GetTypeInfo,
2577 saxxmlreader_GetIDsOfNames,
2578 saxxmlreader_Invoke,
2579 saxxmlreader_getFeature,
2580 saxxmlreader_putFeature,
2581 saxxmlreader_getProperty,
2582 saxxmlreader_putProperty,
2583 saxxmlreader_get_entityResolver,
2584 saxxmlreader_put_entityResolver,
2585 saxxmlreader_get_contentHandler,
2586 saxxmlreader_put_contentHandler,
2587 saxxmlreader_get_dtdHandler,
2588 saxxmlreader_put_dtdHandler,
2589 saxxmlreader_get_errorHandler,
2590 saxxmlreader_put_errorHandler,
2591 saxxmlreader_get_baseURL,
2592 saxxmlreader_put_baseURL,
2593 saxxmlreader_get_secureBaseURL,
2594 saxxmlreader_put_secureBaseURL,
2596 saxxmlreader_parseURL
2599 /*** ISAXXMLReader interface ***/
2600 /*** IUnknown methods ***/
2601 static HRESULT WINAPI isaxxmlreader_QueryInterface(ISAXXMLReader* iface, REFIID riid, void **ppvObject)
2603 saxreader *This = impl_from_ISAXXMLReader( iface );
2604 return saxxmlreader_QueryInterface((IVBSAXXMLReader*)&This->lpVBSAXXMLReaderVtbl, riid, ppvObject);
2607 static ULONG WINAPI isaxxmlreader_AddRef(ISAXXMLReader* iface)
2609 saxreader *This = impl_from_ISAXXMLReader( iface );
2610 return saxxmlreader_AddRef((IVBSAXXMLReader*)&This->lpVBSAXXMLReaderVtbl);
2613 static ULONG WINAPI isaxxmlreader_Release(ISAXXMLReader* iface)
2615 saxreader *This = impl_from_ISAXXMLReader( iface );
2616 return saxxmlreader_Release((IVBSAXXMLReader*)&This->lpVBSAXXMLReaderVtbl);
2619 /*** ISAXXMLReader methods ***/
2620 static HRESULT WINAPI isaxxmlreader_getFeature(
2621 ISAXXMLReader* iface,
2622 const WCHAR *pFeature,
2623 VARIANT_BOOL *pValue)
2625 saxreader *This = impl_from_ISAXXMLReader( iface );
2626 return IVBSAXXMLReader_getFeature(
2627 (IVBSAXXMLReader*)&This->lpVBSAXXMLReaderVtbl,
2631 static HRESULT WINAPI isaxxmlreader_putFeature(
2632 ISAXXMLReader* iface,
2633 const WCHAR *pFeature,
2634 VARIANT_BOOL vfValue)
2636 saxreader *This = impl_from_ISAXXMLReader( iface );
2637 return IVBSAXXMLReader_putFeature(
2638 (IVBSAXXMLReader*)&This->lpVBSAXXMLReaderVtbl,
2642 static HRESULT WINAPI isaxxmlreader_getProperty(
2643 ISAXXMLReader* iface,
2647 saxreader *This = impl_from_ISAXXMLReader( iface );
2648 return IVBSAXXMLReader_getProperty(
2649 (IVBSAXXMLReader*)&This->lpVBSAXXMLReaderVtbl,
2653 static HRESULT WINAPI isaxxmlreader_putProperty(
2654 ISAXXMLReader* iface,
2658 saxreader *This = impl_from_ISAXXMLReader( iface );
2659 return internal_putProperty(This, pProp, value, FALSE);
2662 static HRESULT WINAPI isaxxmlreader_getEntityResolver(
2663 ISAXXMLReader* iface,
2664 ISAXEntityResolver **ppEntityResolver)
2666 saxreader *This = impl_from_ISAXXMLReader( iface );
2667 return internal_getEntityResolver(This, ppEntityResolver, FALSE);
2670 static HRESULT WINAPI isaxxmlreader_putEntityResolver(
2671 ISAXXMLReader* iface,
2672 ISAXEntityResolver *pEntityResolver)
2674 saxreader *This = impl_from_ISAXXMLReader( iface );
2675 return internal_putEntityResolver(This, pEntityResolver, FALSE);
2678 static HRESULT WINAPI isaxxmlreader_getContentHandler(
2679 ISAXXMLReader* iface,
2680 ISAXContentHandler **pContentHandler)
2682 saxreader *This = impl_from_ISAXXMLReader( iface );
2683 return internal_getContentHandler(This, pContentHandler, FALSE);
2686 static HRESULT WINAPI isaxxmlreader_putContentHandler(
2687 ISAXXMLReader* iface,
2688 ISAXContentHandler *contentHandler)
2690 saxreader *This = impl_from_ISAXXMLReader( iface );
2691 return internal_putContentHandler(This, contentHandler, FALSE);
2694 static HRESULT WINAPI isaxxmlreader_getDTDHandler(
2695 ISAXXMLReader* iface,
2696 ISAXDTDHandler **pDTDHandler)
2698 saxreader *This = impl_from_ISAXXMLReader( iface );
2699 return internal_getDTDHandler(This, pDTDHandler, FALSE);
2702 static HRESULT WINAPI isaxxmlreader_putDTDHandler(
2703 ISAXXMLReader* iface,
2704 ISAXDTDHandler *pDTDHandler)
2706 saxreader *This = impl_from_ISAXXMLReader( iface );
2707 return internal_putDTDHandler(This, pDTDHandler, FALSE);
2710 static HRESULT WINAPI isaxxmlreader_getErrorHandler(
2711 ISAXXMLReader* iface,
2712 ISAXErrorHandler **pErrorHandler)
2714 saxreader *This = impl_from_ISAXXMLReader( iface );
2715 return internal_getErrorHandler(This, pErrorHandler, FALSE);
2718 static HRESULT WINAPI isaxxmlreader_putErrorHandler(
2719 ISAXXMLReader* iface,
2720 ISAXErrorHandler *errorHandler)
2722 saxreader *This = impl_from_ISAXXMLReader( iface );
2723 return internal_putErrorHandler(This, errorHandler, FALSE);
2726 static HRESULT WINAPI isaxxmlreader_getBaseURL(
2727 ISAXXMLReader* iface,
2728 const WCHAR **pBaseUrl)
2730 saxreader *This = impl_from_ISAXXMLReader( iface );
2731 return IVBSAXXMLReader_get_baseURL(
2732 (IVBSAXXMLReader*)&This->lpVBSAXXMLReaderVtbl,
2736 static HRESULT WINAPI isaxxmlreader_putBaseURL(
2737 ISAXXMLReader* iface,
2738 const WCHAR *pBaseUrl)
2740 saxreader *This = impl_from_ISAXXMLReader( iface );
2741 return IVBSAXXMLReader_put_baseURL(
2742 (IVBSAXXMLReader*)&This->lpVBSAXXMLReaderVtbl,
2746 static HRESULT WINAPI isaxxmlreader_getSecureBaseURL(
2747 ISAXXMLReader* iface,
2748 const WCHAR **pSecureBaseUrl)
2750 saxreader *This = impl_from_ISAXXMLReader( iface );
2751 return IVBSAXXMLReader_get_secureBaseURL(
2752 (IVBSAXXMLReader*)&This->lpVBSAXXMLReaderVtbl,
2756 static HRESULT WINAPI isaxxmlreader_putSecureBaseURL(
2757 ISAXXMLReader* iface,
2758 const WCHAR *secureBaseUrl)
2760 saxreader *This = impl_from_ISAXXMLReader( iface );
2761 return IVBSAXXMLReader_put_secureBaseURL(
2762 (IVBSAXXMLReader*)&This->lpVBSAXXMLReaderVtbl,
2766 static HRESULT WINAPI isaxxmlreader_parse(
2767 ISAXXMLReader* iface,
2770 saxreader *This = impl_from_ISAXXMLReader( iface );
2771 return internal_parse(This, varInput, FALSE);
2774 static HRESULT WINAPI isaxxmlreader_parseURL(
2775 ISAXXMLReader* iface,
2778 saxreader *This = impl_from_ISAXXMLReader( iface );
2779 return internal_parseURL(This, url, FALSE);
2782 static const struct ISAXXMLReaderVtbl isaxreader_vtbl =
2784 isaxxmlreader_QueryInterface,
2785 isaxxmlreader_AddRef,
2786 isaxxmlreader_Release,
2787 isaxxmlreader_getFeature,
2788 isaxxmlreader_putFeature,
2789 isaxxmlreader_getProperty,
2790 isaxxmlreader_putProperty,
2791 isaxxmlreader_getEntityResolver,
2792 isaxxmlreader_putEntityResolver,
2793 isaxxmlreader_getContentHandler,
2794 isaxxmlreader_putContentHandler,
2795 isaxxmlreader_getDTDHandler,
2796 isaxxmlreader_putDTDHandler,
2797 isaxxmlreader_getErrorHandler,
2798 isaxxmlreader_putErrorHandler,
2799 isaxxmlreader_getBaseURL,
2800 isaxxmlreader_putBaseURL,
2801 isaxxmlreader_getSecureBaseURL,
2802 isaxxmlreader_putSecureBaseURL,
2803 isaxxmlreader_parse,
2804 isaxxmlreader_parseURL
2807 HRESULT SAXXMLReader_create(IUnknown *pUnkOuter, LPVOID *ppObj)
2811 TRACE("(%p,%p)\n", pUnkOuter, ppObj);
2813 reader = HeapAlloc( GetProcessHeap(), 0, sizeof (*reader) );
2815 return E_OUTOFMEMORY;
2817 reader->lpVBSAXXMLReaderVtbl = &saxreader_vtbl;
2818 reader->lpSAXXMLReaderVtbl = &isaxreader_vtbl;
2820 reader->contentHandler = NULL;
2821 reader->vbcontentHandler = NULL;
2822 reader->errorHandler = NULL;
2823 reader->vberrorHandler = NULL;
2824 reader->lexicalHandler = NULL;
2825 reader->vblexicalHandler = NULL;
2826 reader->declHandler = NULL;
2827 reader->vbdeclHandler = NULL;
2828 reader->isParsing = FALSE;
2830 memset(&reader->sax, 0, sizeof(xmlSAXHandler));
2831 reader->sax.initialized = XML_SAX2_MAGIC;
2832 reader->sax.startDocument = libxmlStartDocument;
2833 reader->sax.endDocument = libxmlEndDocument;
2834 reader->sax.startElementNs = libxmlStartElementNS;
2835 reader->sax.endElementNs = libxmlEndElementNS;
2836 reader->sax.characters = libxmlCharacters;
2837 reader->sax.setDocumentLocator = libxmlSetDocumentLocator;
2838 reader->sax.comment = libxmlComment;
2839 reader->sax.error = libxmlFatalError;
2840 reader->sax.fatalError = libxmlFatalError;
2841 reader->sax.cdataBlock = libxmlCDataBlock;
2843 *ppObj = &reader->lpVBSAXXMLReaderVtbl;
2845 TRACE("returning iface %p\n", *ppObj);
2852 HRESULT SAXXMLReader_create(IUnknown *pUnkOuter, LPVOID *ppObj)
2854 MESSAGE("This program tried to use a SAX XML Reader object, but\n"
2855 "libxml2 support was not present at compile time.\n");