msxml: Fix parsing <.../> elements.
[wine/hacks.git] / dlls / msxml3 / saxreader.c
blob94a7e1df2250a8ea41d080bfad5492b619cadd7c
1 /*
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
21 #define COBJMACROS
23 #include "config.h"
25 #include <stdarg.h>
26 #include <assert.h>
27 #include "windef.h"
28 #include "winbase.h"
29 #include "winuser.h"
30 #include "winnls.h"
31 #include "ole2.h"
32 #include "msxml2.h"
33 #include "wininet.h"
34 #include "urlmon.h"
35 #include "winreg.h"
36 #include "shlwapi.h"
38 #include "wine/debug.h"
40 #include "msxml_private.h"
42 WINE_DEFAULT_DEBUG_CHANNEL(msxml);
44 #ifdef HAVE_LIBXML2
46 #include <libxml/SAX2.h>
47 #include <libxml/parserInternals.h>
49 typedef struct _saxreader
51 const struct IVBSAXXMLReaderVtbl *lpVBSAXXMLReaderVtbl;
52 const struct ISAXXMLReaderVtbl *lpSAXXMLReaderVtbl;
53 LONG ref;
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;
62 xmlSAXHandler sax;
63 BOOL isParsing;
64 } saxreader;
66 typedef struct _saxlocator
68 const struct IVBSAXLocatorVtbl *lpVBSAXLocatorVtbl;
69 const struct ISAXLocatorVtbl *lpSAXLocatorVtbl;
70 LONG ref;
71 saxreader *saxreader;
72 HRESULT ret;
73 xmlParserCtxtPtr pParserCtxt;
74 WCHAR *publicId;
75 WCHAR *systemId;
76 xmlChar *lastCur;
77 int line;
78 int realLine;
79 int column;
80 int realColumn;
81 BOOL vbInterface;
82 int nsStackSize;
83 int nsStackLast;
84 int *nsStack;
85 } saxlocator;
87 typedef struct _saxattributes
89 const struct IVBSAXAttributesVtbl *lpVBSAXAttributesVtbl;
90 const struct ISAXAttributesVtbl *lpSAXAttributesVtbl;
91 LONG ref;
92 int nb_attributes;
93 BSTR *szLocalname;
94 BSTR *szURI;
95 BSTR *szValue;
96 BSTR *szQName;
97 } saxattributes;
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)
134 int *new_stack;
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;
144 return S_OK;
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)
155 DWORD dLen;
156 LPWSTR str;
157 BSTR bstr;
159 if (!buf)
160 return NULL;
162 dLen = MultiByteToWideChar(CP_UTF8, 0, (LPCSTR)buf, len, NULL, 0);
163 if(len != -1) dLen++;
164 str = (LPWSTR)HeapAlloc(GetProcessHeap(), 0, dLen * sizeof (WCHAR));
165 if (!str)
166 return NULL;
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);
172 return bstr;
175 static BSTR QName_from_xmlChar(const xmlChar *prefix, const xmlChar *name)
177 DWORD dLen, dLast;
178 LPWSTR str;
179 BSTR bstr;
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));
189 if(!str)
190 return NULL;
192 dLast = MultiByteToWideChar(CP_UTF8, 0, (LPCSTR)prefix, -1, str, dLen);
193 str[dLast-1] = ':';
194 MultiByteToWideChar(CP_UTF8, 0, (LPCSTR)name, -1, &str[dLast], dLen-dLast);
195 bstr = SysAllocString(str);
197 HeapFree(GetProcessHeap(), 0, str);
199 return bstr;
202 static void format_error_message_from_id(saxlocator *This, HRESULT hr)
204 xmlStopParser(This->pParserCtxt);
205 This->ret = hr;
207 if((This->vbInterface && This->saxreader->vberrorHandler)
208 || (!This->vbInterface && This->saxreader->errorHandler))
210 WCHAR msg[1024];
211 if(!FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM,
212 NULL, hr, 0, msg, sizeof(msg), NULL))
214 FIXME("MSXML errors not yet supported.\n");
215 msg[0] = '\0';
218 if(This->vbInterface)
220 BSTR bstrMsg = SysAllocString(msg);
221 IVBSAXErrorHandler_fatalError(This->saxreader->vberrorHandler,
222 (IVBSAXLocator*)&This->lpVBSAXLocatorVtbl, &bstrMsg, hr);
224 else
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;
235 This->realLine = 1;
236 This->realColumn = 1;
238 else if(This->lastCur < This->pParserCtxt->input->base)
240 This->lastCur = (xmlChar*)This->pParserCtxt->input->base;
241 This->realLine = 1;
242 This->realColumn = 1;
245 if(This->pParserCtxt->input->cur<This->lastCur)
247 This->lastCur = (xmlChar*)This->pParserCtxt->input->base;
248 This->realLine -= 1;
249 This->realColumn = 1;
252 if(!end) end = (xmlChar*)This->pParserCtxt->input->cur;
254 while(This->lastCur < end)
256 if(*(This->lastCur) == '\n')
258 This->realLine++;
259 This->realColumn = 1;
261 else if(*(This->lastCur) == '\r' &&
262 (This->lastCur==This->pParserCtxt->input->end ||
263 *(This->lastCur+1)!='\n'))
265 This->realLine++;
266 This->realColumn = 1;
268 else This->realColumn++;
270 This->lastCur++;
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,
284 REFIID riid,
285 void **ppvObject)
287 saxattributes *This = impl_from_IVBSAXAttributes(iface);
289 TRACE("%p %s %p\n", This, debugstr_guid(riid), ppvObject);
291 *ppvObject = NULL;
293 if (IsEqualGUID(riid, &IID_IUnknown) ||
294 IsEqualGUID(riid, &IID_IDispatch) ||
295 IsEqualGUID(riid, &IID_IVBSAXAttributes))
297 *ppvObject = iface;
299 else
301 FIXME("interface %s not implemented\n", debugstr_guid(riid));
302 return E_NOINTERFACE;
305 IVBSAXAttributes_AddRef(iface);
307 return S_OK;
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);
329 *pctinfo = 1;
331 return S_OK;
334 static HRESULT WINAPI ivbsaxattributes_GetTypeInfo(
335 IVBSAXAttributes *iface,
336 UINT iTInfo, LCID lcid, ITypeInfo** ppTInfo )
338 saxattributes *This = impl_from_IVBSAXAttributes( iface );
339 HRESULT hr;
341 TRACE("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo);
343 hr = get_typeinfo(IVBSAXAttributes_tid, ppTInfo);
345 return hr;
348 static HRESULT WINAPI ivbsaxattributes_GetIDsOfNames(
349 IVBSAXAttributes *iface,
350 REFIID riid,
351 LPOLESTR* rgszNames,
352 UINT cNames,
353 LCID lcid,
354 DISPID* rgDispId)
356 saxattributes *This = impl_from_IVBSAXAttributes( iface );
357 ITypeInfo *typeinfo;
358 HRESULT hr;
360 TRACE("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames, cNames,
361 lcid, rgDispId);
363 if(!rgszNames || cNames == 0 || !rgDispId)
364 return E_INVALIDARG;
366 hr = get_typeinfo(IVBSAXAttributes_tid, &typeinfo);
367 if(SUCCEEDED(hr))
369 hr = ITypeInfo_GetIDsOfNames(typeinfo, rgszNames, cNames, rgDispId);
370 ITypeInfo_Release(typeinfo);
373 return hr;
376 static HRESULT WINAPI ivbsaxattributes_Invoke(
377 IVBSAXAttributes *iface,
378 DISPID dispIdMember,
379 REFIID riid,
380 LCID lcid,
381 WORD wFlags,
382 DISPPARAMS* pDispParams,
383 VARIANT* pVarResult,
384 EXCEPINFO* pExcepInfo,
385 UINT* puArgErr)
387 saxattributes *This = impl_from_IVBSAXAttributes( iface );
388 ITypeInfo *typeinfo;
389 HRESULT hr;
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);
395 if(SUCCEEDED(hr))
397 hr = ITypeInfo_Invoke(typeinfo, &(This->lpVBSAXAttributesVtbl), dispIdMember, wFlags, pDispParams,
398 pVarResult, pExcepInfo, puArgErr);
399 ITypeInfo_Release(typeinfo);
402 return hr;
405 /*** IVBSAXAttributes methods ***/
406 static HRESULT WINAPI ivbsaxattributes_get_length(
407 IVBSAXAttributes* iface,
408 int *nLength)
410 saxattributes *This = impl_from_IVBSAXAttributes( iface );
411 return ISAXAttributes_getLength(
412 (ISAXAttributes*)&This->lpSAXAttributesVtbl,
413 nLength);
416 static HRESULT WINAPI ivbsaxattributes_getURI(
417 IVBSAXAttributes* iface,
418 int nIndex,
419 BSTR *uri)
421 int len;
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,
430 int nIndex,
431 BSTR *localName)
433 int len;
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,
442 int nIndex,
443 BSTR *QName)
445 int len;
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,
454 BSTR uri,
455 BSTR localName,
456 int *index)
458 saxattributes *This = impl_from_IVBSAXAttributes( iface );
459 return ISAXAttributes_getIndexFromName(
460 (ISAXAttributes*)&This->lpSAXAttributesVtbl,
461 (const WCHAR*)uri, SysStringLen(uri),
462 (const WCHAR*)localName, SysStringLen(localName), index);
465 static HRESULT WINAPI ivbsaxattributes_getIndexFromQName(
466 IVBSAXAttributes* iface,
467 BSTR QName,
468 int *index)
470 saxattributes *This = impl_from_IVBSAXAttributes( iface );
471 return ISAXAttributes_getIndexFromQName(
472 (ISAXAttributes*)&This->lpSAXAttributesVtbl,
473 (const WCHAR*)QName, SysStringLen(QName), index);
476 static HRESULT WINAPI ivbsaxattributes_getType(
477 IVBSAXAttributes* iface,
478 int nIndex,
479 BSTR *type)
481 int len;
482 saxattributes *This = impl_from_IVBSAXAttributes( iface );
483 return ISAXAttributes_getType(
484 (ISAXAttributes*)&This->lpSAXAttributesVtbl,
485 nIndex, (const WCHAR**)type, &len);
488 static HRESULT WINAPI ivbsaxattributes_getTypeFromName(
489 IVBSAXAttributes* iface,
490 BSTR uri,
491 BSTR localName,
492 BSTR *type)
494 int len;
495 saxattributes *This = impl_from_IVBSAXAttributes( iface );
496 return ISAXAttributes_getTypeFromName(
497 (ISAXAttributes*)&This->lpSAXAttributesVtbl,
498 (const WCHAR*)uri, SysStringLen(uri),
499 (const WCHAR*)localName, SysStringLen(localName),
500 (const WCHAR**)type, &len);
503 static HRESULT WINAPI ivbsaxattributes_getTypeFromQName(
504 IVBSAXAttributes* iface,
505 BSTR QName,
506 BSTR *type)
508 int len;
509 saxattributes *This = impl_from_IVBSAXAttributes( iface );
510 return ISAXAttributes_getTypeFromQName(
511 (ISAXAttributes*)&This->lpSAXAttributesVtbl,
512 (const WCHAR*)QName, SysStringLen(QName),
513 (const WCHAR**)type, &len);
516 static HRESULT WINAPI ivbsaxattributes_getValue(
517 IVBSAXAttributes* iface,
518 int nIndex,
519 BSTR *value)
521 int len;
522 saxattributes *This = impl_from_IVBSAXAttributes( iface );
523 return ISAXAttributes_getValue(
524 (ISAXAttributes*)&This->lpSAXAttributesVtbl,
525 nIndex, (const WCHAR**)value, &len);
528 static HRESULT WINAPI ivbsaxattributes_getValueFromName(
529 IVBSAXAttributes* iface,
530 BSTR uri,
531 BSTR localName,
532 BSTR *value)
534 int len;
535 saxattributes *This = impl_from_IVBSAXAttributes( iface );
536 return ISAXAttributes_getValueFromName(
537 (ISAXAttributes*)&This->lpSAXAttributesVtbl,
538 (const WCHAR*)uri, SysStringLen(uri),
539 (const WCHAR*)localName, SysStringLen(localName),
540 (const WCHAR**)value, &len);
543 static HRESULT WINAPI ivbsaxattributes_getValueFromQName(
544 IVBSAXAttributes* iface,
545 BSTR QName,
546 BSTR *value)
548 int len;
549 saxattributes *This = impl_from_IVBSAXAttributes( iface );
550 return ISAXAttributes_getValueFromQName(
551 (ISAXAttributes*)&This->lpSAXAttributesVtbl,
552 (const WCHAR*)QName, SysStringLen(QName),
553 (const WCHAR**)value, &len);
556 static const struct IVBSAXAttributesVtbl ivbsaxattributes_vtbl =
558 ivbsaxattributes_QueryInterface,
559 ivbsaxattributes_AddRef,
560 ivbsaxattributes_Release,
561 ivbsaxattributes_GetTypeInfoCount,
562 ivbsaxattributes_GetTypeInfo,
563 ivbsaxattributes_GetIDsOfNames,
564 ivbsaxattributes_Invoke,
565 ivbsaxattributes_get_length,
566 ivbsaxattributes_getURI,
567 ivbsaxattributes_getLocalName,
568 ivbsaxattributes_getQName,
569 ivbsaxattributes_getIndexFromName,
570 ivbsaxattributes_getIndexFromQName,
571 ivbsaxattributes_getType,
572 ivbsaxattributes_getTypeFromName,
573 ivbsaxattributes_getTypeFromQName,
574 ivbsaxattributes_getValue,
575 ivbsaxattributes_getValueFromName,
576 ivbsaxattributes_getValueFromQName
579 /*** ISAXAttributes interface ***/
580 /*** IUnknown methods ***/
581 static HRESULT WINAPI isaxattributes_QueryInterface(
582 ISAXAttributes* iface,
583 REFIID riid,
584 void **ppvObject)
586 saxattributes *This = impl_from_ISAXAttributes(iface);
588 TRACE("%p %s %p\n", This, debugstr_guid(riid), ppvObject);
590 *ppvObject = NULL;
592 if (IsEqualGUID(riid, &IID_IUnknown) ||
593 IsEqualGUID(riid, &IID_ISAXAttributes))
595 *ppvObject = iface;
597 else
599 FIXME("interface %s not implemented\n", debugstr_guid(riid));
600 return E_NOINTERFACE;
603 ISAXAttributes_AddRef(iface);
605 return S_OK;
608 static ULONG WINAPI isaxattributes_AddRef(ISAXAttributes* iface)
610 saxattributes *This = impl_from_ISAXAttributes(iface);
611 TRACE("%p\n", This);
612 return InterlockedIncrement(&This->ref);
615 static ULONG WINAPI isaxattributes_Release(ISAXAttributes* iface)
617 saxattributes *This = impl_from_ISAXAttributes(iface);
618 LONG ref;
620 TRACE("%p\n", This);
622 ref = InterlockedDecrement(&This->ref);
623 if (ref==0)
625 int index;
626 for(index=0; index<This->nb_attributes; index++)
628 SysFreeString(This->szLocalname[index]);
629 SysFreeString(This->szURI[index]);
630 SysFreeString(This->szValue[index]);
631 SysFreeString(This->szQName[index]);
634 HeapFree(GetProcessHeap(), 0, This->szLocalname);
635 HeapFree(GetProcessHeap(), 0, This->szURI);
636 HeapFree(GetProcessHeap(), 0, This->szValue);
637 HeapFree(GetProcessHeap(), 0, This->szQName);
639 HeapFree(GetProcessHeap(), 0, This);
642 return ref;
645 /*** ISAXAttributes methods ***/
646 static HRESULT WINAPI isaxattributes_getLength(
647 ISAXAttributes* iface,
648 int *length)
650 saxattributes *This = impl_from_ISAXAttributes( iface );
652 *length = This->nb_attributes;
653 TRACE("Length set to %d\n", *length);
654 return S_OK;
657 static HRESULT WINAPI isaxattributes_getURI(
658 ISAXAttributes* iface,
659 int nIndex,
660 const WCHAR **pUrl,
661 int *pUriSize)
663 saxattributes *This = impl_from_ISAXAttributes( iface );
664 TRACE("(%p)->(%d)\n", This, nIndex);
666 if(nIndex>=This->nb_attributes || nIndex<0) return E_INVALIDARG;
667 if(!pUrl || !pUriSize) return E_POINTER;
669 *pUriSize = SysStringLen(This->szURI[nIndex]);
670 *pUrl = This->szURI[nIndex];
672 return S_OK;
675 static HRESULT WINAPI isaxattributes_getLocalName(
676 ISAXAttributes* iface,
677 int nIndex,
678 const WCHAR **pLocalName,
679 int *pLocalNameLength)
681 saxattributes *This = impl_from_ISAXAttributes( iface );
682 TRACE("(%p)->(%d)\n", This, nIndex);
684 if(nIndex>=This->nb_attributes || nIndex<0) return E_INVALIDARG;
685 if(!pLocalName || !pLocalNameLength) return E_POINTER;
687 *pLocalNameLength = SysStringLen(This->szLocalname[nIndex]);
688 *pLocalName = This->szLocalname[nIndex];
690 return S_OK;
693 static HRESULT WINAPI isaxattributes_getQName(
694 ISAXAttributes* iface,
695 int nIndex,
696 const WCHAR **pQName,
697 int *pQNameLength)
699 saxattributes *This = impl_from_ISAXAttributes( iface );
700 TRACE("(%p)->(%d)\n", This, nIndex);
702 if(nIndex>=This->nb_attributes || nIndex<0) return E_INVALIDARG;
703 if(!pQName || !pQNameLength) return E_POINTER;
705 *pQNameLength = SysStringLen(This->szQName[nIndex]);
706 *pQName = This->szQName[nIndex];
708 return S_OK;
711 static HRESULT WINAPI isaxattributes_getName(
712 ISAXAttributes* iface,
713 int nIndex,
714 const WCHAR **pUri,
715 int *pUriLength,
716 const WCHAR **pLocalName,
717 int *pLocalNameSize,
718 const WCHAR **pQName,
719 int *pQNameLength)
721 saxattributes *This = impl_from_ISAXAttributes( iface );
722 TRACE("(%p)->(%d)\n", This, nIndex);
724 if(nIndex>=This->nb_attributes || nIndex<0) return E_INVALIDARG;
725 if(!pUri || !pUriLength || !pLocalName || !pLocalNameSize
726 || !pQName || !pQNameLength) return E_POINTER;
728 *pUriLength = SysStringLen(This->szURI[nIndex]);
729 *pUri = This->szURI[nIndex];
730 *pLocalNameSize = SysStringLen(This->szLocalname[nIndex]);
731 *pLocalName = This->szLocalname[nIndex];
732 *pQNameLength = SysStringLen(This->szQName[nIndex]);
733 *pQName = This->szQName[nIndex];
735 return S_OK;
738 static HRESULT WINAPI isaxattributes_getIndexFromName(
739 ISAXAttributes* iface,
740 const WCHAR *pUri,
741 int cUriLength,
742 const WCHAR *pLocalName,
743 int cocalNameLength,
744 int *index)
746 saxattributes *This = impl_from_ISAXAttributes( iface );
747 int i;
748 TRACE("(%p)->(%s, %d, %s, %d)\n", This, debugstr_w(pUri), cUriLength,
749 debugstr_w(pLocalName), cocalNameLength);
751 if(!pUri || !pLocalName || !index) return E_POINTER;
753 for(i=0; i<This->nb_attributes; i++)
755 if(cUriLength!=SysStringLen(This->szURI[i])
756 || cocalNameLength!=SysStringLen(This->szLocalname[i]))
757 continue;
758 if(cUriLength && memcmp(pUri, This->szURI[i],
759 sizeof(WCHAR)*cUriLength))
760 continue;
761 if(cocalNameLength && memcmp(pLocalName, This->szLocalname[i],
762 sizeof(WCHAR)*cocalNameLength))
763 continue;
765 *index = i;
766 return S_OK;
769 return E_INVALIDARG;
772 static HRESULT WINAPI isaxattributes_getIndexFromQName(
773 ISAXAttributes* iface,
774 const WCHAR *pQName,
775 int nQNameLength,
776 int *index)
778 saxattributes *This = impl_from_ISAXAttributes( iface );
779 int i;
780 TRACE("(%p)->(%s, %d)\n", This, debugstr_w(pQName), nQNameLength);
782 if(!pQName || !index) return E_POINTER;
783 if(!nQNameLength) return E_INVALIDARG;
785 for(i=0; i<This->nb_attributes; i++)
787 if(nQNameLength!=SysStringLen(This->szQName[i])) continue;
788 if(memcmp(pQName, This->szQName, sizeof(WCHAR)*nQNameLength)) continue;
790 *index = i;
791 return S_OK;
794 return E_INVALIDARG;
797 static HRESULT WINAPI isaxattributes_getType(
798 ISAXAttributes* iface,
799 int nIndex,
800 const WCHAR **pType,
801 int *pTypeLength)
803 saxattributes *This = impl_from_ISAXAttributes( iface );
805 FIXME("(%p)->(%d) stub\n", This, nIndex);
806 return E_NOTIMPL;
809 static HRESULT WINAPI isaxattributes_getTypeFromName(
810 ISAXAttributes* iface,
811 const WCHAR *pUri,
812 int nUri,
813 const WCHAR *pLocalName,
814 int nLocalName,
815 const WCHAR **pType,
816 int *nType)
818 saxattributes *This = impl_from_ISAXAttributes( iface );
820 FIXME("(%p)->(%s, %d, %s, %d) stub\n", This, debugstr_w(pUri), nUri,
821 debugstr_w(pLocalName), nLocalName);
822 return E_NOTIMPL;
825 static HRESULT WINAPI isaxattributes_getTypeFromQName(
826 ISAXAttributes* iface,
827 const WCHAR *pQName,
828 int nQName,
829 const WCHAR **pType,
830 int *nType)
832 saxattributes *This = impl_from_ISAXAttributes( iface );
834 FIXME("(%p)->(%s, %d) stub\n", This, debugstr_w(pQName), nQName);
835 return E_NOTIMPL;
838 static HRESULT WINAPI isaxattributes_getValue(
839 ISAXAttributes* iface,
840 int nIndex,
841 const WCHAR **pValue,
842 int *nValue)
844 saxattributes *This = impl_from_ISAXAttributes( iface );
845 TRACE("(%p)->(%d)\n", This, nIndex);
847 if(nIndex>=This->nb_attributes || nIndex<0) return E_INVALIDARG;
848 if(!pValue || !nValue) return E_POINTER;
850 *nValue = SysStringLen(This->szValue[nIndex]);
851 *pValue = This->szValue[nIndex];
853 return S_OK;
856 static HRESULT WINAPI isaxattributes_getValueFromName(
857 ISAXAttributes* iface,
858 const WCHAR *pUri,
859 int nUri,
860 const WCHAR *pLocalName,
861 int nLocalName,
862 const WCHAR **pValue,
863 int *nValue)
865 HRESULT hr;
866 int index;
867 saxattributes *This = impl_from_ISAXAttributes( iface );
868 TRACE("(%p)->(%s, %d, %s, %d)\n", This, debugstr_w(pUri), nUri,
869 debugstr_w(pLocalName), nLocalName);
871 hr = ISAXAttributes_getIndexFromName(iface,
872 pUri, nUri, pLocalName, nLocalName, &index);
873 if(hr==S_OK) hr = ISAXAttributes_getValue(iface, index, pValue, nValue);
875 return hr;
878 static HRESULT WINAPI isaxattributes_getValueFromQName(
879 ISAXAttributes* iface,
880 const WCHAR *pQName,
881 int nQName,
882 const WCHAR **pValue,
883 int *nValue)
885 HRESULT hr;
886 int index;
887 saxattributes *This = impl_from_ISAXAttributes( iface );
888 TRACE("(%p)->(%s, %d)\n", This, debugstr_w(pQName), nQName);
890 hr = ISAXAttributes_getIndexFromQName(iface, pQName, nQName, &index);
891 if(hr==S_OK) hr = ISAXAttributes_getValue(iface, index, pValue, nValue);
893 return hr;
896 static const struct ISAXAttributesVtbl isaxattributes_vtbl =
898 isaxattributes_QueryInterface,
899 isaxattributes_AddRef,
900 isaxattributes_Release,
901 isaxattributes_getLength,
902 isaxattributes_getURI,
903 isaxattributes_getLocalName,
904 isaxattributes_getQName,
905 isaxattributes_getName,
906 isaxattributes_getIndexFromName,
907 isaxattributes_getIndexFromQName,
908 isaxattributes_getType,
909 isaxattributes_getTypeFromName,
910 isaxattributes_getTypeFromQName,
911 isaxattributes_getValue,
912 isaxattributes_getValueFromName,
913 isaxattributes_getValueFromQName
916 static HRESULT SAXAttributes_create(saxattributes **attr,
917 int nb_namespaces, const xmlChar **xmlNamespaces,
918 int nb_attributes, const xmlChar **xmlAttributes)
920 saxattributes *attributes;
921 int index;
922 static const xmlChar xmlns[] = "xmlns";
924 attributes = HeapAlloc(GetProcessHeap(), 0, sizeof(*attributes));
925 if(!attributes)
926 return E_OUTOFMEMORY;
928 attributes->lpVBSAXAttributesVtbl = &ivbsaxattributes_vtbl;
929 attributes->lpSAXAttributesVtbl = &isaxattributes_vtbl;
930 attributes->ref = 1;
932 attributes->nb_attributes = nb_namespaces+nb_attributes;
934 attributes->szLocalname =
935 HeapAlloc(GetProcessHeap(), 0, sizeof(BSTR)*attributes->nb_attributes);
936 attributes->szURI =
937 HeapAlloc(GetProcessHeap(), 0, sizeof(BSTR)*attributes->nb_attributes);
938 attributes->szValue =
939 HeapAlloc(GetProcessHeap(), 0, sizeof(BSTR)*attributes->nb_attributes);
940 attributes->szQName =
941 HeapAlloc(GetProcessHeap(), 0, sizeof(BSTR)*attributes->nb_attributes);
943 if(!attributes->szLocalname || !attributes->szURI
944 || !attributes->szValue || !attributes->szQName)
946 HeapFree(GetProcessHeap(), 0, attributes->szLocalname);
947 HeapFree(GetProcessHeap(), 0, attributes->szURI);
948 HeapFree(GetProcessHeap(), 0, attributes->szValue);
949 HeapFree(GetProcessHeap(), 0, attributes->szQName);
950 HeapFree(GetProcessHeap(), 0, attributes);
951 return E_FAIL;
954 for(index=0; index<nb_namespaces; index++)
956 attributes->szLocalname[index] = SysAllocStringLen(NULL, 0);
957 attributes->szURI[index] = SysAllocStringLen(NULL, 0);
958 attributes->szValue[index] = bstr_from_xmlChar(xmlNamespaces[2*index+1]);
959 attributes->szQName[index] = QName_from_xmlChar(xmlns, xmlNamespaces[2*index]);
962 for(index=0; index<nb_attributes; index++)
964 attributes->szLocalname[nb_namespaces+index] =
965 bstr_from_xmlChar(xmlAttributes[index*5]);
966 attributes->szURI[nb_namespaces+index] =
967 bstr_from_xmlChar(xmlAttributes[index*5+2]);
968 attributes->szValue[nb_namespaces+index] =
969 bstr_from_xmlCharN(xmlAttributes[index*5+3],
970 xmlAttributes[index*5+4]-xmlAttributes[index*5+3]);
971 attributes->szQName[nb_namespaces+index] =
972 QName_from_xmlChar(xmlAttributes[index*5+1], xmlAttributes[index*5]);
975 *attr = attributes;
977 TRACE("returning %p\n", *attr);
979 return S_OK;
982 /*** LibXML callbacks ***/
983 static void libxmlStartDocument(void *ctx)
985 saxlocator *This = ctx;
986 HRESULT hr;
988 if((This->vbInterface && This->saxreader->vbcontentHandler)
989 || (!This->vbInterface && This->saxreader->contentHandler))
991 if(This->vbInterface)
992 hr = IVBSAXContentHandler_startDocument(This->saxreader->vbcontentHandler);
993 else
994 hr = ISAXContentHandler_startDocument(This->saxreader->contentHandler);
996 if(hr != S_OK)
997 format_error_message_from_id(This, hr);
1000 update_position(This, NULL);
1003 static void libxmlEndDocument(void *ctx)
1005 saxlocator *This = ctx;
1006 HRESULT hr;
1008 This->column = 0;
1009 This->line = 0;
1011 if(This->ret != S_OK) return;
1013 if((This->vbInterface && This->saxreader->vbcontentHandler)
1014 || (!This->vbInterface && This->saxreader->contentHandler))
1016 if(This->vbInterface)
1017 hr = IVBSAXContentHandler_endDocument(This->saxreader->vbcontentHandler);
1018 else
1019 hr = ISAXContentHandler_endDocument(This->saxreader->contentHandler);
1021 if(hr != S_OK)
1022 format_error_message_from_id(This, hr);
1026 static void libxmlStartElementNS(
1027 void *ctx,
1028 const xmlChar *localname,
1029 const xmlChar *prefix,
1030 const xmlChar *URI,
1031 int nb_namespaces,
1032 const xmlChar **namespaces,
1033 int nb_attributes,
1034 int nb_defaulted,
1035 const xmlChar **attributes)
1037 BSTR NamespaceUri, LocalName, QName, Prefix, Uri;
1038 saxlocator *This = ctx;
1039 HRESULT hr;
1040 saxattributes *attr;
1041 int index;
1043 if(*(This->pParserCtxt->input->cur) == '/')
1044 update_position(This, (xmlChar*)This->pParserCtxt->input->cur+2);
1045 else
1046 update_position(This, (xmlChar*)This->pParserCtxt->input->cur+1);
1048 hr = namespacePush(This, nb_namespaces);
1049 if(hr==S_OK && ((This->vbInterface && This->saxreader->vbcontentHandler)
1050 || (!This->vbInterface && This->saxreader->contentHandler)))
1052 for(index=0; index<nb_namespaces; index++)
1054 Prefix = bstr_from_xmlChar(namespaces[2*index]);
1055 Uri = bstr_from_xmlChar(namespaces[2*index+1]);
1057 if(This->vbInterface)
1058 hr = IVBSAXContentHandler_startPrefixMapping(
1059 This->saxreader->vbcontentHandler,
1060 &Prefix, &Uri);
1061 else
1062 hr = ISAXContentHandler_startPrefixMapping(
1063 This->saxreader->contentHandler,
1064 Prefix, SysStringLen(Prefix),
1065 Uri, SysStringLen(Uri));
1067 SysFreeString(Prefix);
1068 SysFreeString(Uri);
1070 if(hr != S_OK)
1072 format_error_message_from_id(This, hr);
1073 return;
1077 NamespaceUri = bstr_from_xmlChar(URI);
1078 LocalName = bstr_from_xmlChar(localname);
1079 QName = QName_from_xmlChar(prefix, localname);
1081 hr = SAXAttributes_create(&attr, nb_namespaces, namespaces, nb_attributes, attributes);
1082 if(hr == S_OK)
1084 if(This->vbInterface)
1085 hr = IVBSAXContentHandler_startElement(
1086 This->saxreader->vbcontentHandler,
1087 &NamespaceUri, &LocalName, &QName,
1088 (IVBSAXAttributes*)&attr->lpVBSAXAttributesVtbl);
1089 else
1090 hr = ISAXContentHandler_startElement(
1091 This->saxreader->contentHandler,
1092 NamespaceUri, SysStringLen(NamespaceUri),
1093 LocalName, SysStringLen(LocalName),
1094 QName, SysStringLen(QName),
1095 (ISAXAttributes*)&attr->lpSAXAttributesVtbl);
1097 ISAXAttributes_Release((ISAXAttributes*)&attr->lpSAXAttributesVtbl);
1100 SysFreeString(NamespaceUri);
1101 SysFreeString(LocalName);
1102 SysFreeString(QName);
1105 if(hr != S_OK)
1106 format_error_message_from_id(This, hr);
1109 static void libxmlEndElementNS(
1110 void *ctx,
1111 const xmlChar *localname,
1112 const xmlChar *prefix,
1113 const xmlChar *URI)
1115 BSTR NamespaceUri, LocalName, QName, Prefix;
1116 saxlocator *This = ctx;
1117 HRESULT hr;
1118 xmlChar *end;
1119 int nsNr, index;
1121 end = (xmlChar*)This->pParserCtxt->input->cur;
1122 if(*(end-1) != '>' || *(end-2) != '/')
1123 while(*(end-2)!='<' && *(end-1)!='/') end--;
1125 update_position(This, end);
1127 nsNr = namespacePop(This);
1129 if((This->vbInterface && This->saxreader->vbcontentHandler)
1130 || (!This->vbInterface && This->saxreader->contentHandler))
1132 NamespaceUri = bstr_from_xmlChar(URI);
1133 LocalName = bstr_from_xmlChar(localname);
1134 QName = QName_from_xmlChar(prefix, localname);
1136 if(This->vbInterface)
1137 hr = IVBSAXContentHandler_endElement(
1138 This->saxreader->vbcontentHandler,
1139 &NamespaceUri, &LocalName, &QName);
1140 else
1141 hr = ISAXContentHandler_endElement(
1142 This->saxreader->contentHandler,
1143 NamespaceUri, SysStringLen(NamespaceUri),
1144 LocalName, SysStringLen(LocalName),
1145 QName, SysStringLen(QName));
1147 SysFreeString(NamespaceUri);
1148 SysFreeString(LocalName);
1149 SysFreeString(QName);
1151 if(hr != S_OK)
1153 format_error_message_from_id(This, hr);
1154 return;
1157 for(index=This->pParserCtxt->nsNr-2;
1158 index>=This->pParserCtxt->nsNr-nsNr*2; index-=2)
1160 Prefix = bstr_from_xmlChar(This->pParserCtxt->nsTab[index]);
1162 if(This->vbInterface)
1163 hr = IVBSAXContentHandler_endPrefixMapping(
1164 This->saxreader->vbcontentHandler, &Prefix);
1165 else
1166 hr = ISAXContentHandler_endPrefixMapping(
1167 This->saxreader->contentHandler,
1168 Prefix, SysStringLen(Prefix));
1170 SysFreeString(Prefix);
1174 update_position(This, NULL);
1177 static void libxmlCharacters(
1178 void *ctx,
1179 const xmlChar *ch,
1180 int len)
1182 saxlocator *This = ctx;
1183 BSTR Chars;
1184 HRESULT hr;
1185 xmlChar *cur;
1186 xmlChar *end;
1187 BOOL lastEvent = FALSE;
1189 if((This->vbInterface && !This->saxreader->vbcontentHandler)
1190 || (!This->vbInterface && !This->saxreader->contentHandler))
1191 return;
1193 cur = (xmlChar*)ch;
1194 if(*(ch-1)=='\r') cur--;
1195 end = cur;
1197 if(ch<This->pParserCtxt->input->base || ch>This->pParserCtxt->input->end)
1198 This->column++;
1200 while(1)
1202 while(end-ch<len && *end!='\r') end++;
1203 if(end-ch==len)
1205 end--;
1206 lastEvent = TRUE;
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);
1215 else
1216 hr = ISAXContentHandler_characters(
1217 This->saxreader->contentHandler,
1218 Chars, SysStringLen(Chars));
1219 SysFreeString(Chars);
1221 This->column += end-cur+1;
1223 if(lastEvent)
1224 break;
1226 *end = '\r';
1227 end++;
1228 if(*end == '\n')
1230 end++;
1231 This->column++;
1233 cur = end;
1235 if(end-ch == len) break;
1238 if(ch<This->pParserCtxt->input->base || ch>This->pParserCtxt->input->end)
1239 This->column = This->realColumn
1240 +This->pParserCtxt->input->cur-This->lastCur;
1243 static void libxmlSetDocumentLocator(
1244 void *ctx,
1245 xmlSAXLocatorPtr loc)
1247 saxlocator *This = ctx;
1248 HRESULT hr;
1250 if(This->vbInterface)
1251 hr = IVBSAXContentHandler_putref_documentLocator(
1252 This->saxreader->vbcontentHandler,
1253 (IVBSAXLocator*)&This->lpVBSAXLocatorVtbl);
1254 else
1255 hr = ISAXContentHandler_putDocumentLocator(
1256 This->saxreader->contentHandler,
1257 (ISAXLocator*)&This->lpSAXLocatorVtbl);
1259 if(FAILED(hr))
1260 format_error_message_from_id(This, hr);
1263 static void libxmlFatalError(void *ctx, const char *msg, ...)
1265 saxlocator *This = ctx;
1266 char message[1024];
1267 WCHAR *wszError;
1268 DWORD len;
1269 va_list args;
1271 if((This->vbInterface && !This->saxreader->vberrorHandler)
1272 || (!This->vbInterface && !This->saxreader->errorHandler))
1274 xmlStopParser(This->pParserCtxt);
1275 This->ret = E_FAIL;
1276 return;
1279 FIXME("Error handling is not compatible.\n");
1281 va_start(args, msg);
1282 vsprintf(message, msg, args);
1283 va_end(args);
1285 len = MultiByteToWideChar(CP_UNIXCP, 0, message, -1, NULL, 0);
1286 wszError = HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR)*len);
1287 if(wszError)
1288 MultiByteToWideChar(CP_UNIXCP, 0, message, -1, (LPWSTR)wszError, len);
1290 if(This->vbInterface)
1292 BSTR bstrError = SysAllocString(wszError);
1293 IVBSAXErrorHandler_fatalError(This->saxreader->vberrorHandler,
1294 (IVBSAXLocator*)&This->lpVBSAXLocatorVtbl, &bstrError, E_FAIL);
1296 else
1297 ISAXErrorHandler_fatalError(This->saxreader->errorHandler,
1298 (ISAXLocator*)&This->lpSAXLocatorVtbl, wszError, E_FAIL);
1300 HeapFree(GetProcessHeap(), 0, wszError);
1302 xmlStopParser(This->pParserCtxt);
1303 This->ret = E_FAIL;
1306 /*** IVBSAXLocator interface ***/
1307 /*** IUnknown methods ***/
1308 static HRESULT WINAPI ivbsaxlocator_QueryInterface(IVBSAXLocator* iface, REFIID riid, void **ppvObject)
1310 saxlocator *This = impl_from_IVBSAXLocator( iface );
1312 TRACE("%p %s %p\n", This, debugstr_guid( riid ), ppvObject);
1314 *ppvObject = NULL;
1316 if ( IsEqualGUID( riid, &IID_IUnknown ) ||
1317 IsEqualGUID( riid, &IID_IDispatch) ||
1318 IsEqualGUID( riid, &IID_IVBSAXLocator ))
1320 *ppvObject = iface;
1322 else
1324 FIXME("interface %s not implemented\n", debugstr_guid(riid));
1325 return E_NOINTERFACE;
1328 IVBSAXLocator_AddRef( iface );
1330 return S_OK;
1333 static ULONG WINAPI ivbsaxlocator_AddRef(IVBSAXLocator* iface)
1335 saxlocator *This = impl_from_IVBSAXLocator( iface );
1336 TRACE("%p\n", This );
1337 return InterlockedIncrement( &This->ref );
1340 static ULONG WINAPI ivbsaxlocator_Release(
1341 IVBSAXLocator* iface)
1343 saxlocator *This = impl_from_IVBSAXLocator( iface );
1344 return ISAXLocator_Release((ISAXLocator*)&This->lpVBSAXLocatorVtbl);
1347 /*** IDispatch methods ***/
1348 static HRESULT WINAPI ivbsaxlocator_GetTypeInfoCount( IVBSAXLocator *iface, UINT* pctinfo )
1350 saxlocator *This = impl_from_IVBSAXLocator( iface );
1352 TRACE("(%p)->(%p)\n", This, pctinfo);
1354 *pctinfo = 1;
1356 return S_OK;
1359 static HRESULT WINAPI ivbsaxlocator_GetTypeInfo(
1360 IVBSAXLocator *iface,
1361 UINT iTInfo, LCID lcid, ITypeInfo** ppTInfo )
1363 saxlocator *This = impl_from_IVBSAXLocator( iface );
1364 HRESULT hr;
1366 TRACE("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo);
1368 hr = get_typeinfo(IVBSAXLocator_tid, ppTInfo);
1370 return hr;
1373 static HRESULT WINAPI ivbsaxlocator_GetIDsOfNames(
1374 IVBSAXLocator *iface,
1375 REFIID riid,
1376 LPOLESTR* rgszNames,
1377 UINT cNames,
1378 LCID lcid,
1379 DISPID* rgDispId)
1381 saxlocator *This = impl_from_IVBSAXLocator( iface );
1382 ITypeInfo *typeinfo;
1383 HRESULT hr;
1385 TRACE("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames, cNames,
1386 lcid, rgDispId);
1388 if(!rgszNames || cNames == 0 || !rgDispId)
1389 return E_INVALIDARG;
1391 hr = get_typeinfo(IVBSAXLocator_tid, &typeinfo);
1392 if(SUCCEEDED(hr))
1394 hr = ITypeInfo_GetIDsOfNames(typeinfo, rgszNames, cNames, rgDispId);
1395 ITypeInfo_Release(typeinfo);
1398 return hr;
1401 static HRESULT WINAPI ivbsaxlocator_Invoke(
1402 IVBSAXLocator *iface,
1403 DISPID dispIdMember,
1404 REFIID riid,
1405 LCID lcid,
1406 WORD wFlags,
1407 DISPPARAMS* pDispParams,
1408 VARIANT* pVarResult,
1409 EXCEPINFO* pExcepInfo,
1410 UINT* puArgErr)
1412 saxlocator *This = impl_from_IVBSAXLocator( iface );
1413 ITypeInfo *typeinfo;
1414 HRESULT hr;
1416 TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
1417 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
1419 hr = get_typeinfo(IVBSAXLocator_tid, &typeinfo);
1420 if(SUCCEEDED(hr))
1422 hr = ITypeInfo_Invoke(typeinfo, &(This->lpVBSAXLocatorVtbl), dispIdMember, wFlags, pDispParams,
1423 pVarResult, pExcepInfo, puArgErr);
1424 ITypeInfo_Release(typeinfo);
1427 return hr;
1430 /*** IVBSAXLocator methods ***/
1431 static HRESULT WINAPI ivbsaxlocator_get_columnNumber(
1432 IVBSAXLocator* iface,
1433 int *pnColumn)
1435 saxlocator *This = impl_from_IVBSAXLocator( iface );
1436 return ISAXLocator_getColumnNumber(
1437 (ISAXLocator*)&This->lpVBSAXLocatorVtbl,
1438 pnColumn);
1441 static HRESULT WINAPI ivbsaxlocator_get_lineNumber(
1442 IVBSAXLocator* iface,
1443 int *pnLine)
1445 saxlocator *This = impl_from_IVBSAXLocator( iface );
1446 return ISAXLocator_getLineNumber(
1447 (ISAXLocator*)&This->lpVBSAXLocatorVtbl,
1448 pnLine);
1451 static HRESULT WINAPI ivbsaxlocator_get_publicId(
1452 IVBSAXLocator* iface,
1453 BSTR* publicId)
1455 saxlocator *This = impl_from_IVBSAXLocator( iface );
1456 return ISAXLocator_getPublicId(
1457 (ISAXLocator*)&This->lpVBSAXLocatorVtbl,
1458 (const WCHAR**)publicId);
1461 static HRESULT WINAPI ivbsaxlocator_get_systemId(
1462 IVBSAXLocator* iface,
1463 BSTR* systemId)
1465 saxlocator *This = impl_from_IVBSAXLocator( iface );
1466 return ISAXLocator_getSystemId(
1467 (ISAXLocator*)&This->lpVBSAXLocatorVtbl,
1468 (const WCHAR**)systemId);
1471 static const struct IVBSAXLocatorVtbl ivbsaxlocator_vtbl =
1473 ivbsaxlocator_QueryInterface,
1474 ivbsaxlocator_AddRef,
1475 ivbsaxlocator_Release,
1476 ivbsaxlocator_GetTypeInfoCount,
1477 ivbsaxlocator_GetTypeInfo,
1478 ivbsaxlocator_GetIDsOfNames,
1479 ivbsaxlocator_Invoke,
1480 ivbsaxlocator_get_columnNumber,
1481 ivbsaxlocator_get_lineNumber,
1482 ivbsaxlocator_get_publicId,
1483 ivbsaxlocator_get_systemId
1486 /*** ISAXLocator interface ***/
1487 /*** IUnknown methods ***/
1488 static HRESULT WINAPI isaxlocator_QueryInterface(ISAXLocator* iface, REFIID riid, void **ppvObject)
1490 saxlocator *This = impl_from_ISAXLocator( iface );
1492 TRACE("%p %s %p\n", This, debugstr_guid( riid ), ppvObject );
1494 *ppvObject = NULL;
1496 if ( IsEqualGUID( riid, &IID_IUnknown ) ||
1497 IsEqualGUID( riid, &IID_ISAXLocator ))
1499 *ppvObject = iface;
1501 else
1503 FIXME("interface %s not implemented\n", debugstr_guid(riid));
1504 return E_NOINTERFACE;
1507 ISAXLocator_AddRef( iface );
1509 return S_OK;
1512 static ULONG WINAPI isaxlocator_AddRef(ISAXLocator* iface)
1514 saxlocator *This = impl_from_ISAXLocator( iface );
1515 TRACE("%p\n", This );
1516 return InterlockedIncrement( &This->ref );
1519 static ULONG WINAPI isaxlocator_Release(
1520 ISAXLocator* iface)
1522 saxlocator *This = impl_from_ISAXLocator( iface );
1523 LONG ref;
1525 TRACE("%p\n", This );
1527 ref = InterlockedDecrement( &This->ref );
1528 if ( ref == 0 )
1530 SysFreeString(This->publicId);
1531 SysFreeString(This->systemId);
1532 HeapFree(GetProcessHeap(), 0, This->nsStack);
1534 ISAXXMLReader_Release((ISAXXMLReader*)&This->saxreader->lpSAXXMLReaderVtbl);
1535 HeapFree( GetProcessHeap(), 0, This );
1538 return ref;
1541 /*** ISAXLocator methods ***/
1542 static HRESULT WINAPI isaxlocator_getColumnNumber(
1543 ISAXLocator* iface,
1544 int *pnColumn)
1546 saxlocator *This = impl_from_ISAXLocator( iface );
1548 *pnColumn = This->column;
1549 return S_OK;
1552 static HRESULT WINAPI isaxlocator_getLineNumber(
1553 ISAXLocator* iface,
1554 int *pnLine)
1556 saxlocator *This = impl_from_ISAXLocator( iface );
1558 *pnLine = This->line;
1559 return S_OK;
1562 static HRESULT WINAPI isaxlocator_getPublicId(
1563 ISAXLocator* iface,
1564 const WCHAR ** ppwchPublicId)
1566 BSTR publicId;
1567 saxlocator *This = impl_from_ISAXLocator( iface );
1569 SysFreeString(This->publicId);
1571 publicId = bstr_from_xmlChar(xmlSAX2GetPublicId(This->pParserCtxt));
1572 if(SysStringLen(publicId))
1573 This->publicId = (WCHAR*)&publicId;
1574 else
1576 SysFreeString(publicId);
1577 This->publicId = NULL;
1580 *ppwchPublicId = This->publicId;
1581 return S_OK;
1584 static HRESULT WINAPI isaxlocator_getSystemId(
1585 ISAXLocator* iface,
1586 const WCHAR ** ppwchSystemId)
1588 BSTR systemId;
1589 saxlocator *This = impl_from_ISAXLocator( iface );
1591 SysFreeString(This->systemId);
1593 systemId = bstr_from_xmlChar(xmlSAX2GetSystemId(This->pParserCtxt));
1594 if(SysStringLen(systemId))
1595 This->systemId = (WCHAR*)&systemId;
1596 else
1598 SysFreeString(systemId);
1599 This->systemId = NULL;
1602 *ppwchSystemId = This->systemId;
1603 return S_OK;
1606 static const struct ISAXLocatorVtbl isaxlocator_vtbl =
1608 isaxlocator_QueryInterface,
1609 isaxlocator_AddRef,
1610 isaxlocator_Release,
1611 isaxlocator_getColumnNumber,
1612 isaxlocator_getLineNumber,
1613 isaxlocator_getPublicId,
1614 isaxlocator_getSystemId
1617 static HRESULT SAXLocator_create(saxreader *reader, saxlocator **ppsaxlocator, BOOL vbInterface)
1619 saxlocator *locator;
1621 locator = HeapAlloc( GetProcessHeap(), 0, sizeof (*locator) );
1622 if( !locator )
1623 return E_OUTOFMEMORY;
1625 locator->lpVBSAXLocatorVtbl = &ivbsaxlocator_vtbl;
1626 locator->lpSAXLocatorVtbl = &isaxlocator_vtbl;
1627 locator->ref = 1;
1628 locator->vbInterface = vbInterface;
1630 locator->saxreader = reader;
1631 ISAXXMLReader_AddRef((ISAXXMLReader*)&reader->lpSAXXMLReaderVtbl);
1633 locator->pParserCtxt = NULL;
1634 locator->publicId = NULL;
1635 locator->systemId = NULL;
1636 locator->lastCur = NULL;
1637 locator->line = 0;
1638 locator->column = 0;
1639 locator->ret = S_OK;
1640 locator->nsStackSize = 8;
1641 locator->nsStackLast = 0;
1642 locator->nsStack = HeapAlloc(GetProcessHeap(), 0, locator->nsStackSize);
1643 if(!locator->nsStack)
1645 ISAXXMLReader_Release((ISAXXMLReader*)&reader->lpSAXXMLReaderVtbl);
1646 HeapFree(GetProcessHeap(), 0, locator);
1647 return E_OUTOFMEMORY;
1650 *ppsaxlocator = locator;
1652 TRACE("returning %p\n", *ppsaxlocator);
1654 return S_OK;
1657 /*** SAXXMLReader internal functions ***/
1658 static HRESULT internal_parseBuffer(saxreader *This, const char *buffer, int size, BOOL vbInterface)
1660 saxlocator *locator;
1661 HRESULT hr;
1663 hr = SAXLocator_create(This, &locator, vbInterface);
1664 if(FAILED(hr))
1665 return E_FAIL;
1667 locator->pParserCtxt = xmlCreateMemoryParserCtxt(buffer, size);
1668 if(!locator->pParserCtxt)
1670 ISAXLocator_Release((ISAXLocator*)&locator->lpSAXLocatorVtbl);
1671 return E_FAIL;
1674 locator->pParserCtxt->sax = &locator->saxreader->sax;
1675 locator->pParserCtxt->userData = locator;
1677 This->isParsing = TRUE;
1678 if(xmlParseDocument(locator->pParserCtxt)) hr = E_FAIL;
1679 else hr = locator->ret;
1680 This->isParsing = FALSE;
1682 if(locator->pParserCtxt)
1684 locator->pParserCtxt->sax = NULL;
1685 xmlFreeParserCtxt(locator->pParserCtxt);
1686 locator->pParserCtxt = NULL;
1689 ISAXLocator_Release((ISAXLocator*)&locator->lpSAXLocatorVtbl);
1690 return S_OK;
1693 static HRESULT internal_parseStream(saxreader *This, IStream *stream, BOOL vbInterface)
1695 saxlocator *locator;
1696 HRESULT hr;
1697 ULONG dataRead;
1698 char data[1024];
1700 hr = IStream_Read(stream, data, sizeof(data), &dataRead);
1701 if(hr != S_OK)
1702 return hr;
1704 hr = SAXLocator_create(This, &locator, vbInterface);
1705 if(FAILED(hr))
1706 return E_FAIL;
1708 locator->pParserCtxt = xmlCreatePushParserCtxt(
1709 &locator->saxreader->sax, locator,
1710 data, dataRead, NULL);
1711 if(!locator->pParserCtxt)
1713 ISAXLocator_Release((ISAXLocator*)&locator->lpSAXLocatorVtbl);
1714 return E_FAIL;
1717 This->isParsing = TRUE;
1718 while(1)
1720 hr = IStream_Read(stream, data, sizeof(data), &dataRead);
1721 if(hr != S_OK)
1722 break;
1724 if(xmlParseChunk(locator->pParserCtxt, data, dataRead, 0)) hr = E_FAIL;
1725 else hr = locator->ret;
1727 if(hr != S_OK) break;
1729 if(dataRead != sizeof(data))
1731 if(xmlParseChunk(locator->pParserCtxt, data, 0, 1)) hr = E_FAIL;
1732 else hr = locator->ret;
1734 break;
1737 This->isParsing = FALSE;
1739 locator->pParserCtxt->sax = NULL;
1740 xmlFreeParserCtxt(locator->pParserCtxt);
1741 locator->pParserCtxt = NULL;
1742 ISAXLocator_Release((ISAXLocator*)&locator->lpSAXLocatorVtbl);
1743 return hr;
1746 static HRESULT WINAPI internal_getEntityResolver(
1747 saxreader *This,
1748 void *pEntityResolver,
1749 BOOL vbInterface)
1751 FIXME("(%p)->(%p) stub\n", This, pEntityResolver);
1752 return E_NOTIMPL;
1755 static HRESULT WINAPI internal_putEntityResolver(
1756 saxreader *This,
1757 void *pEntityResolver,
1758 BOOL vbInterface)
1760 FIXME("(%p)->(%p) stub\n", This, pEntityResolver);
1761 return E_NOTIMPL;
1764 static HRESULT WINAPI internal_getContentHandler(
1765 saxreader* This,
1766 void *pContentHandler,
1767 BOOL vbInterface)
1769 TRACE("(%p)->(%p)\n", This, pContentHandler);
1770 if(pContentHandler == NULL)
1771 return E_POINTER;
1772 if((vbInterface && This->vbcontentHandler)
1773 || (!vbInterface && This->contentHandler))
1775 if(vbInterface)
1776 IVBSAXContentHandler_AddRef(This->vbcontentHandler);
1777 else
1778 ISAXContentHandler_AddRef(This->contentHandler);
1780 if(vbInterface) *(IVBSAXContentHandler**)pContentHandler =
1781 This->vbcontentHandler;
1782 else *(ISAXContentHandler**)pContentHandler = This->contentHandler;
1784 return S_OK;
1787 static HRESULT WINAPI internal_putContentHandler(
1788 saxreader* This,
1789 void *contentHandler,
1790 BOOL vbInterface)
1792 TRACE("(%p)->(%p)\n", This, contentHandler);
1793 if(contentHandler)
1795 if(vbInterface)
1796 IVBSAXContentHandler_AddRef((IVBSAXContentHandler*)contentHandler);
1797 else
1798 ISAXContentHandler_AddRef((ISAXContentHandler*)contentHandler);
1800 if((vbInterface && This->vbcontentHandler)
1801 || (!vbInterface && This->contentHandler))
1803 if(vbInterface)
1804 IVBSAXContentHandler_Release(This->vbcontentHandler);
1805 else
1806 ISAXContentHandler_Release(This->contentHandler);
1808 if(vbInterface)
1809 This->vbcontentHandler = contentHandler;
1810 else
1811 This->contentHandler = contentHandler;
1813 return S_OK;
1816 static HRESULT WINAPI internal_getDTDHandler(
1817 saxreader* This,
1818 void *pDTDHandler,
1819 BOOL vbInterface)
1821 FIXME("(%p)->(%p) stub\n", This, pDTDHandler);
1822 return E_NOTIMPL;
1825 static HRESULT WINAPI internal_putDTDHandler(
1826 saxreader* This,
1827 void *pDTDHandler,
1828 BOOL vbInterface)
1830 FIXME("(%p)->(%p) stub\n", This, pDTDHandler);
1831 return E_NOTIMPL;
1834 static HRESULT WINAPI internal_getErrorHandler(
1835 saxreader* This,
1836 void *pErrorHandler,
1837 BOOL vbInterface)
1839 TRACE("(%p)->(%p)\n", This, pErrorHandler);
1840 if(pErrorHandler == NULL)
1841 return E_POINTER;
1843 if(vbInterface && This->vberrorHandler)
1844 IVBSAXErrorHandler_AddRef(This->vberrorHandler);
1845 else if(!vbInterface && This->errorHandler)
1846 ISAXErrorHandler_AddRef(This->errorHandler);
1848 if(vbInterface)
1849 *(IVBSAXErrorHandler**)pErrorHandler = This->vberrorHandler;
1850 else
1851 *(ISAXErrorHandler**)pErrorHandler = This->errorHandler;
1853 return S_OK;
1857 static HRESULT WINAPI internal_putErrorHandler(
1858 saxreader* This,
1859 void *errorHandler,
1860 BOOL vbInterface)
1862 TRACE("(%p)->(%p)\n", This, errorHandler);
1863 if(errorHandler)
1865 if(vbInterface)
1866 IVBSAXErrorHandler_AddRef((IVBSAXErrorHandler*)errorHandler);
1867 else
1868 ISAXErrorHandler_AddRef((ISAXErrorHandler*)errorHandler);
1871 if(vbInterface && This->vberrorHandler)
1872 IVBSAXErrorHandler_Release(This->vberrorHandler);
1873 else if(!vbInterface && This->errorHandler)
1874 ISAXErrorHandler_Release(This->errorHandler);
1876 if(vbInterface)
1877 This->vberrorHandler = errorHandler;
1878 else
1879 This->errorHandler = errorHandler;
1881 return S_OK;
1885 static HRESULT WINAPI internal_parse(
1886 saxreader* This,
1887 VARIANT varInput,
1888 BOOL vbInterface)
1890 HRESULT hr;
1892 TRACE("(%p)\n", This);
1894 hr = S_OK;
1895 switch(V_VT(&varInput))
1897 case VT_BSTR:
1898 hr = internal_parseBuffer(This, (const char*)V_BSTR(&varInput),
1899 SysStringByteLen(V_BSTR(&varInput)), vbInterface);
1900 break;
1901 case VT_ARRAY|VT_UI1: {
1902 void *pSAData;
1903 LONG lBound, uBound;
1904 ULONG dataRead;
1906 hr = SafeArrayGetLBound(V_ARRAY(&varInput), 1, &lBound);
1907 if(hr != S_OK) break;
1908 hr = SafeArrayGetUBound(V_ARRAY(&varInput), 1, &uBound);
1909 if(hr != S_OK) break;
1910 dataRead = (uBound-lBound)*SafeArrayGetElemsize(V_ARRAY(&varInput));
1911 hr = SafeArrayAccessData(V_ARRAY(&varInput), (void**)&pSAData);
1912 if(hr != S_OK) break;
1913 hr = internal_parseBuffer(This, pSAData, dataRead, vbInterface);
1914 SafeArrayUnaccessData(V_ARRAY(&varInput));
1915 break;
1917 case VT_UNKNOWN:
1918 case VT_DISPATCH: {
1919 IPersistStream *persistStream;
1920 IStream *stream = NULL;
1921 IXMLDOMDocument *xmlDoc;
1923 if(IUnknown_QueryInterface(V_UNKNOWN(&varInput),
1924 &IID_IXMLDOMDocument, (void**)&xmlDoc) == S_OK)
1926 BSTR bstrData;
1928 IXMLDOMDocument_get_xml(xmlDoc, &bstrData);
1929 hr = internal_parseBuffer(This, (const char*)bstrData,
1930 SysStringByteLen(bstrData), vbInterface);
1931 IXMLDOMDocument_Release(xmlDoc);
1932 break;
1934 if(IUnknown_QueryInterface(V_UNKNOWN(&varInput),
1935 &IID_IPersistStream, (void**)&persistStream) == S_OK)
1937 hr = IPersistStream_Save(persistStream, stream, TRUE);
1938 IPersistStream_Release(persistStream);
1939 if(hr != S_OK) break;
1941 if(stream || IUnknown_QueryInterface(V_UNKNOWN(&varInput),
1942 &IID_IStream, (void**)&stream) == S_OK)
1944 hr = internal_parseStream(This, stream, vbInterface);
1945 IStream_Release(stream);
1946 break;
1949 default:
1950 WARN("vt %d not implemented\n", V_VT(&varInput));
1951 hr = E_INVALIDARG;
1954 return hr;
1957 static HRESULT internal_vbonDataAvailable(void *obj, char *ptr, DWORD len)
1959 saxreader *This = obj;
1961 return internal_parseBuffer(This, ptr, len, TRUE);
1964 static HRESULT internal_onDataAvailable(void *obj, char *ptr, DWORD len)
1966 saxreader *This = obj;
1968 return internal_parseBuffer(This, ptr, len, FALSE);
1971 static HRESULT WINAPI internal_parseURL(
1972 saxreader* This,
1973 const WCHAR *url,
1974 BOOL vbInterface)
1976 bsc_t *bsc;
1977 HRESULT hr;
1979 TRACE("(%p)->(%s)\n", This, debugstr_w(url));
1981 if(vbInterface) hr = bind_url(url, internal_vbonDataAvailable, This, &bsc);
1982 else hr = bind_url(url, internal_onDataAvailable, This, &bsc);
1984 if(FAILED(hr))
1985 return hr;
1987 detach_bsc(bsc);
1989 return S_OK;
1992 static HRESULT WINAPI internal_putProperty(
1993 saxreader* This,
1994 const WCHAR *pProp,
1995 VARIANT value,
1996 BOOL vbInterface)
1998 static const WCHAR wszCharset[] = {
1999 'c','h','a','r','s','e','t',0
2001 static const WCHAR wszDeclarationHandler[] = {
2002 'h','t','t','p',':','/','/','x','m','l','.','o','r','g','/',
2003 's','a','x','/','p','r','o','p','e','r','t','i','e','s','/',
2004 'd','e','c','l','a','r','a','t','i','o','n',
2005 '-','h','a','n','d','l','e','r',0
2007 static const WCHAR wszDomNode[] = {
2008 'h','t','t','p',':','/','/','x','m','l','.','o','r','g','/',
2009 's','a','x','/','p','r','o','p','e','r','t','i','e','s','/',
2010 'd','o','m','-','n','o','d','e',0
2012 static const WCHAR wszInputSource[] = {
2013 'i','n','p','u','t','-','s','o','u','r','c','e',0
2015 static const WCHAR wszLexicalHandler[] = {
2016 'h','t','t','p',':','/','/','x','m','l','.','o','r','g','/',
2017 's','a','x','/','p','r','o','p','e','r','t','i','e','s','/',
2018 'l','e','x','i','c','a','l','-','h','a','n','d','l','e','r',0
2020 static const WCHAR wszMaxElementDepth[] = {
2021 'm','a','x','-','e','l','e','m','e','n','t','-','d','e','p','t','h',0
2023 static const WCHAR wszMaxXMLSize[] = {
2024 'm','a','x','-','x','m','l','-','s','i','z','e',0
2026 static const WCHAR wszSchemaDeclarationHandler[] = {
2027 's','c','h','e','m','a','-',
2028 'd','e','c','l','a','r','a','t','i','o','n','-',
2029 'h','a','n','d','l','e','r',0
2031 static const WCHAR wszXMLDeclEncoding[] = {
2032 'x','m','l','d','e','c','l','-','e','n','c','o','d','i','n','g',0
2034 static const WCHAR wszXMLDeclStandalone[] = {
2035 'x','m','l','d','e','c','l',
2036 '-','s','t','a','n','d','a','l','o','n','e',0
2038 static const WCHAR wszXMLDeclVersion[] = {
2039 'x','m','l','d','e','c','l','-','v','e','r','s','i','o','n',0
2042 FIXME("(%p)->(%s): semi-stub\n", This, debugstr_w(pProp));
2044 if(!memcmp(pProp, wszCharset, sizeof(wszCharset)))
2045 return E_NOTIMPL;
2047 if(!memcmp(pProp, wszDeclarationHandler, sizeof(wszDeclarationHandler)))
2049 if(This->isParsing) return E_FAIL;
2051 if(V_UNKNOWN(&value))
2053 if(vbInterface)
2054 IVBSAXDeclHandler_AddRef((IVBSAXDeclHandler*)V_UNKNOWN(&value));
2055 else
2056 ISAXDeclHandler_AddRef((ISAXDeclHandler*)V_UNKNOWN(&value));
2058 if((vbInterface && This->vbdeclHandler)
2059 || (!vbInterface && This->declHandler))
2061 if(vbInterface)
2062 IVBSAXDeclHandler_Release(This->vbdeclHandler);
2063 else
2064 ISAXDeclHandler_Release(This->declHandler);
2066 if(vbInterface)
2067 This->vbdeclHandler = (IVBSAXDeclHandler*)V_UNKNOWN(&value);
2068 else
2069 This->declHandler = (ISAXDeclHandler*)V_UNKNOWN(&value);
2070 return S_OK;
2073 if(!memcmp(pProp, wszDomNode, sizeof(wszDomNode)))
2074 return E_FAIL;
2076 if(!memcmp(pProp, wszInputSource, sizeof(wszInputSource)))
2077 return E_NOTIMPL;
2079 if(!memcmp(pProp, wszLexicalHandler, sizeof(wszLexicalHandler)))
2081 if(This->isParsing) return E_FAIL;
2083 if(V_UNKNOWN(&value))
2085 if(vbInterface)
2086 IVBSAXLexicalHandler_AddRef(
2087 (IVBSAXLexicalHandler*)V_UNKNOWN(&value));
2088 else
2089 ISAXLexicalHandler_AddRef(
2090 (ISAXLexicalHandler*)V_UNKNOWN(&value));
2092 if((vbInterface && This->vblexicalHandler)
2093 || (!vbInterface && This->lexicalHandler))
2095 if(vbInterface)
2096 IVBSAXLexicalHandler_Release(This->vblexicalHandler);
2097 else
2098 ISAXLexicalHandler_Release(This->lexicalHandler);
2100 if(vbInterface)
2101 This->vblexicalHandler = (IVBSAXLexicalHandler*)V_UNKNOWN(&value);
2102 else
2103 This->lexicalHandler = (ISAXLexicalHandler*)V_UNKNOWN(&value);
2104 return S_OK;
2107 if(!memcmp(pProp, wszMaxElementDepth, sizeof(wszMaxElementDepth)))
2108 return E_NOTIMPL;
2110 if(!memcmp(pProp, wszMaxXMLSize, sizeof(wszMaxXMLSize)))
2111 return E_NOTIMPL;
2113 if(!memcmp(pProp, wszSchemaDeclarationHandler,
2114 sizeof(wszSchemaDeclarationHandler)))
2115 return E_NOTIMPL;
2117 if(!memcmp(pProp, wszXMLDeclEncoding, sizeof(wszXMLDeclEncoding)))
2118 return E_FAIL;
2120 if(!memcmp(pProp, wszXMLDeclStandalone, sizeof(wszXMLDeclStandalone)))
2121 return E_FAIL;
2123 if(!memcmp(pProp, wszXMLDeclVersion, sizeof(wszXMLDeclVersion)))
2124 return E_FAIL;
2126 return E_INVALIDARG;
2129 /*** IVBSAXXMLReader interface ***/
2130 /*** IUnknown methods ***/
2131 static HRESULT WINAPI saxxmlreader_QueryInterface(IVBSAXXMLReader* iface, REFIID riid, void **ppvObject)
2133 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2135 TRACE("%p %s %p\n", This, debugstr_guid( riid ), ppvObject );
2137 *ppvObject = NULL;
2139 if ( IsEqualGUID( riid, &IID_IUnknown ) ||
2140 IsEqualGUID( riid, &IID_IDispatch ) ||
2141 IsEqualGUID( riid, &IID_IVBSAXXMLReader ))
2143 *ppvObject = iface;
2145 else if( IsEqualGUID( riid, &IID_ISAXXMLReader ))
2147 *ppvObject = (ISAXXMLReader*)&This->lpSAXXMLReaderVtbl;
2149 else
2151 FIXME("interface %s not implemented\n", debugstr_guid(riid));
2152 return E_NOINTERFACE;
2155 IVBSAXXMLReader_AddRef( iface );
2157 return S_OK;
2160 static ULONG WINAPI saxxmlreader_AddRef(IVBSAXXMLReader* iface)
2162 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2163 TRACE("%p\n", This );
2164 return InterlockedIncrement( &This->ref );
2167 static ULONG WINAPI saxxmlreader_Release(
2168 IVBSAXXMLReader* iface)
2170 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2171 LONG ref;
2173 TRACE("%p\n", This );
2175 ref = InterlockedDecrement( &This->ref );
2176 if ( ref == 0 )
2178 if(This->contentHandler)
2179 ISAXContentHandler_Release(This->contentHandler);
2181 if(This->vbcontentHandler)
2182 IVBSAXContentHandler_Release(This->vbcontentHandler);
2184 if(This->errorHandler)
2185 ISAXErrorHandler_Release(This->errorHandler);
2187 if(This->vberrorHandler)
2188 IVBSAXErrorHandler_Release(This->vberrorHandler);
2190 if(This->lexicalHandler)
2191 ISAXLexicalHandler_Release(This->lexicalHandler);
2193 if(This->vblexicalHandler)
2194 IVBSAXLexicalHandler_Release(This->vblexicalHandler);
2196 if(This->declHandler)
2197 ISAXDeclHandler_Release(This->declHandler);
2199 if(This->vbdeclHandler)
2200 IVBSAXDeclHandler_Release(This->vbdeclHandler);
2202 HeapFree( GetProcessHeap(), 0, This );
2205 return ref;
2207 /*** IDispatch ***/
2208 static HRESULT WINAPI saxxmlreader_GetTypeInfoCount( IVBSAXXMLReader *iface, UINT* pctinfo )
2210 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2212 TRACE("(%p)->(%p)\n", This, pctinfo);
2214 *pctinfo = 1;
2216 return S_OK;
2219 static HRESULT WINAPI saxxmlreader_GetTypeInfo(
2220 IVBSAXXMLReader *iface,
2221 UINT iTInfo, LCID lcid, ITypeInfo** ppTInfo )
2223 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2224 HRESULT hr;
2226 TRACE("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo);
2228 hr = get_typeinfo(IVBSAXXMLReader_tid, ppTInfo);
2230 return hr;
2233 static HRESULT WINAPI saxxmlreader_GetIDsOfNames(
2234 IVBSAXXMLReader *iface,
2235 REFIID riid,
2236 LPOLESTR* rgszNames,
2237 UINT cNames,
2238 LCID lcid,
2239 DISPID* rgDispId)
2241 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2242 ITypeInfo *typeinfo;
2243 HRESULT hr;
2245 TRACE("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames, cNames,
2246 lcid, rgDispId);
2248 if(!rgszNames || cNames == 0 || !rgDispId)
2249 return E_INVALIDARG;
2251 hr = get_typeinfo(IVBSAXXMLReader_tid, &typeinfo);
2252 if(SUCCEEDED(hr))
2254 hr = ITypeInfo_GetIDsOfNames(typeinfo, rgszNames, cNames, rgDispId);
2255 ITypeInfo_Release(typeinfo);
2258 return hr;
2261 static HRESULT WINAPI saxxmlreader_Invoke(
2262 IVBSAXXMLReader *iface,
2263 DISPID dispIdMember,
2264 REFIID riid,
2265 LCID lcid,
2266 WORD wFlags,
2267 DISPPARAMS* pDispParams,
2268 VARIANT* pVarResult,
2269 EXCEPINFO* pExcepInfo,
2270 UINT* puArgErr)
2272 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2273 ITypeInfo *typeinfo;
2274 HRESULT hr;
2276 TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
2277 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
2279 hr = get_typeinfo(IVBSAXXMLReader_tid, &typeinfo);
2280 if(SUCCEEDED(hr))
2282 hr = ITypeInfo_Invoke(typeinfo, &(This->lpVBSAXXMLReaderVtbl), dispIdMember, wFlags, pDispParams,
2283 pVarResult, pExcepInfo, puArgErr);
2284 ITypeInfo_Release(typeinfo);
2287 return hr;
2290 /*** IVBSAXXMLReader methods ***/
2291 static HRESULT WINAPI saxxmlreader_getFeature(
2292 IVBSAXXMLReader* iface,
2293 const WCHAR *pFeature,
2294 VARIANT_BOOL *pValue)
2296 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2298 FIXME("(%p)->(%s %p) stub\n", This, debugstr_w(pFeature), pValue);
2299 return E_NOTIMPL;
2302 static HRESULT WINAPI saxxmlreader_putFeature(
2303 IVBSAXXMLReader* iface,
2304 const WCHAR *pFeature,
2305 VARIANT_BOOL vfValue)
2307 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2309 FIXME("(%p)->(%s %x) stub\n", This, debugstr_w(pFeature), vfValue);
2310 return E_NOTIMPL;
2313 static HRESULT WINAPI saxxmlreader_getProperty(
2314 IVBSAXXMLReader* iface,
2315 const WCHAR *pProp,
2316 VARIANT *pValue)
2318 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2320 FIXME("(%p)->(%s %p) stub\n", This, debugstr_w(pProp), pValue);
2321 return E_NOTIMPL;
2324 static HRESULT WINAPI saxxmlreader_putProperty(
2325 IVBSAXXMLReader* iface,
2326 const WCHAR *pProp,
2327 VARIANT value)
2329 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2330 return internal_putProperty(This, pProp, value, TRUE);
2333 static HRESULT WINAPI saxxmlreader_get_entityResolver(
2334 IVBSAXXMLReader* iface,
2335 IVBSAXEntityResolver **pEntityResolver)
2337 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2338 return internal_getEntityResolver(This, pEntityResolver, TRUE);
2341 static HRESULT WINAPI saxxmlreader_put_entityResolver(
2342 IVBSAXXMLReader* iface,
2343 IVBSAXEntityResolver *pEntityResolver)
2345 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2346 return internal_putEntityResolver(This, pEntityResolver, TRUE);
2349 static HRESULT WINAPI saxxmlreader_get_contentHandler(
2350 IVBSAXXMLReader* iface,
2351 IVBSAXContentHandler **ppContentHandler)
2353 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2354 return internal_getContentHandler(This, ppContentHandler, TRUE);
2357 static HRESULT WINAPI saxxmlreader_put_contentHandler(
2358 IVBSAXXMLReader* iface,
2359 IVBSAXContentHandler *contentHandler)
2361 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2362 return internal_putContentHandler(This, contentHandler, TRUE);
2365 static HRESULT WINAPI saxxmlreader_get_dtdHandler(
2366 IVBSAXXMLReader* iface,
2367 IVBSAXDTDHandler **pDTDHandler)
2369 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2370 return internal_getDTDHandler(This, pDTDHandler, TRUE);
2373 static HRESULT WINAPI saxxmlreader_put_dtdHandler(
2374 IVBSAXXMLReader* iface,
2375 IVBSAXDTDHandler *pDTDHandler)
2377 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2378 return internal_putDTDHandler(This, pDTDHandler, TRUE);
2381 static HRESULT WINAPI saxxmlreader_get_errorHandler(
2382 IVBSAXXMLReader* iface,
2383 IVBSAXErrorHandler **pErrorHandler)
2385 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2386 return internal_getErrorHandler(This, pErrorHandler, TRUE);
2389 static HRESULT WINAPI saxxmlreader_put_errorHandler(
2390 IVBSAXXMLReader* iface,
2391 IVBSAXErrorHandler *errorHandler)
2393 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2394 return internal_putErrorHandler(This, errorHandler, TRUE);
2397 static HRESULT WINAPI saxxmlreader_get_baseURL(
2398 IVBSAXXMLReader* iface,
2399 const WCHAR **pBaseUrl)
2401 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2403 FIXME("(%p)->(%p) stub\n", This, pBaseUrl);
2404 return E_NOTIMPL;
2407 static HRESULT WINAPI saxxmlreader_put_baseURL(
2408 IVBSAXXMLReader* iface,
2409 const WCHAR *pBaseUrl)
2411 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2413 FIXME("(%p)->(%s) stub\n", This, debugstr_w(pBaseUrl));
2414 return E_NOTIMPL;
2417 static HRESULT WINAPI saxxmlreader_get_secureBaseURL(
2418 IVBSAXXMLReader* iface,
2419 const WCHAR **pSecureBaseUrl)
2421 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2423 FIXME("(%p)->(%p) stub\n", This, pSecureBaseUrl);
2424 return E_NOTIMPL;
2428 static HRESULT WINAPI saxxmlreader_put_secureBaseURL(
2429 IVBSAXXMLReader* iface,
2430 const WCHAR *secureBaseUrl)
2432 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2434 FIXME("(%p)->(%s) stub\n", This, debugstr_w(secureBaseUrl));
2435 return E_NOTIMPL;
2438 static HRESULT WINAPI saxxmlreader_parse(
2439 IVBSAXXMLReader* iface,
2440 VARIANT varInput)
2442 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2443 return internal_parse(This, varInput, TRUE);
2446 static HRESULT WINAPI saxxmlreader_parseURL(
2447 IVBSAXXMLReader* iface,
2448 const WCHAR *url)
2450 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2451 return internal_parseURL(This, url, TRUE);
2454 static const struct IVBSAXXMLReaderVtbl saxreader_vtbl =
2456 saxxmlreader_QueryInterface,
2457 saxxmlreader_AddRef,
2458 saxxmlreader_Release,
2459 saxxmlreader_GetTypeInfoCount,
2460 saxxmlreader_GetTypeInfo,
2461 saxxmlreader_GetIDsOfNames,
2462 saxxmlreader_Invoke,
2463 saxxmlreader_getFeature,
2464 saxxmlreader_putFeature,
2465 saxxmlreader_getProperty,
2466 saxxmlreader_putProperty,
2467 saxxmlreader_get_entityResolver,
2468 saxxmlreader_put_entityResolver,
2469 saxxmlreader_get_contentHandler,
2470 saxxmlreader_put_contentHandler,
2471 saxxmlreader_get_dtdHandler,
2472 saxxmlreader_put_dtdHandler,
2473 saxxmlreader_get_errorHandler,
2474 saxxmlreader_put_errorHandler,
2475 saxxmlreader_get_baseURL,
2476 saxxmlreader_put_baseURL,
2477 saxxmlreader_get_secureBaseURL,
2478 saxxmlreader_put_secureBaseURL,
2479 saxxmlreader_parse,
2480 saxxmlreader_parseURL
2483 /*** ISAXXMLReader interface ***/
2484 /*** IUnknown methods ***/
2485 static HRESULT WINAPI isaxxmlreader_QueryInterface(ISAXXMLReader* iface, REFIID riid, void **ppvObject)
2487 saxreader *This = impl_from_ISAXXMLReader( iface );
2488 return saxxmlreader_QueryInterface((IVBSAXXMLReader*)&This->lpVBSAXXMLReaderVtbl, riid, ppvObject);
2491 static ULONG WINAPI isaxxmlreader_AddRef(ISAXXMLReader* iface)
2493 saxreader *This = impl_from_ISAXXMLReader( iface );
2494 return saxxmlreader_AddRef((IVBSAXXMLReader*)&This->lpVBSAXXMLReaderVtbl);
2497 static ULONG WINAPI isaxxmlreader_Release(ISAXXMLReader* iface)
2499 saxreader *This = impl_from_ISAXXMLReader( iface );
2500 return saxxmlreader_Release((IVBSAXXMLReader*)&This->lpVBSAXXMLReaderVtbl);
2503 /*** ISAXXMLReader methods ***/
2504 static HRESULT WINAPI isaxxmlreader_getFeature(
2505 ISAXXMLReader* iface,
2506 const WCHAR *pFeature,
2507 VARIANT_BOOL *pValue)
2509 saxreader *This = impl_from_ISAXXMLReader( iface );
2510 return IVBSAXXMLReader_getFeature(
2511 (IVBSAXXMLReader*)&This->lpVBSAXXMLReaderVtbl,
2512 pFeature, pValue);
2515 static HRESULT WINAPI isaxxmlreader_putFeature(
2516 ISAXXMLReader* iface,
2517 const WCHAR *pFeature,
2518 VARIANT_BOOL vfValue)
2520 saxreader *This = impl_from_ISAXXMLReader( iface );
2521 return IVBSAXXMLReader_putFeature(
2522 (IVBSAXXMLReader*)&This->lpVBSAXXMLReaderVtbl,
2523 pFeature, vfValue);
2526 static HRESULT WINAPI isaxxmlreader_getProperty(
2527 ISAXXMLReader* iface,
2528 const WCHAR *pProp,
2529 VARIANT *pValue)
2531 saxreader *This = impl_from_ISAXXMLReader( iface );
2532 return IVBSAXXMLReader_getProperty(
2533 (IVBSAXXMLReader*)&This->lpVBSAXXMLReaderVtbl,
2534 pProp, pValue);
2537 static HRESULT WINAPI isaxxmlreader_putProperty(
2538 ISAXXMLReader* iface,
2539 const WCHAR *pProp,
2540 VARIANT value)
2542 saxreader *This = impl_from_ISAXXMLReader( iface );
2543 return internal_putProperty(This, pProp, value, FALSE);
2546 static HRESULT WINAPI isaxxmlreader_getEntityResolver(
2547 ISAXXMLReader* iface,
2548 ISAXEntityResolver **ppEntityResolver)
2550 saxreader *This = impl_from_ISAXXMLReader( iface );
2551 return internal_getEntityResolver(This, ppEntityResolver, FALSE);
2554 static HRESULT WINAPI isaxxmlreader_putEntityResolver(
2555 ISAXXMLReader* iface,
2556 ISAXEntityResolver *pEntityResolver)
2558 saxreader *This = impl_from_ISAXXMLReader( iface );
2559 return internal_putEntityResolver(This, pEntityResolver, FALSE);
2562 static HRESULT WINAPI isaxxmlreader_getContentHandler(
2563 ISAXXMLReader* iface,
2564 ISAXContentHandler **pContentHandler)
2566 saxreader *This = impl_from_ISAXXMLReader( iface );
2567 return internal_getContentHandler(This, pContentHandler, FALSE);
2570 static HRESULT WINAPI isaxxmlreader_putContentHandler(
2571 ISAXXMLReader* iface,
2572 ISAXContentHandler *contentHandler)
2574 saxreader *This = impl_from_ISAXXMLReader( iface );
2575 return internal_putContentHandler(This, contentHandler, FALSE);
2578 static HRESULT WINAPI isaxxmlreader_getDTDHandler(
2579 ISAXXMLReader* iface,
2580 ISAXDTDHandler **pDTDHandler)
2582 saxreader *This = impl_from_ISAXXMLReader( iface );
2583 return internal_getDTDHandler(This, pDTDHandler, FALSE);
2586 static HRESULT WINAPI isaxxmlreader_putDTDHandler(
2587 ISAXXMLReader* iface,
2588 ISAXDTDHandler *pDTDHandler)
2590 saxreader *This = impl_from_ISAXXMLReader( iface );
2591 return internal_putDTDHandler(This, pDTDHandler, FALSE);
2594 static HRESULT WINAPI isaxxmlreader_getErrorHandler(
2595 ISAXXMLReader* iface,
2596 ISAXErrorHandler **pErrorHandler)
2598 saxreader *This = impl_from_ISAXXMLReader( iface );
2599 return internal_getErrorHandler(This, pErrorHandler, FALSE);
2602 static HRESULT WINAPI isaxxmlreader_putErrorHandler(
2603 ISAXXMLReader* iface,
2604 ISAXErrorHandler *errorHandler)
2606 saxreader *This = impl_from_ISAXXMLReader( iface );
2607 return internal_putErrorHandler(This, errorHandler, FALSE);
2610 static HRESULT WINAPI isaxxmlreader_getBaseURL(
2611 ISAXXMLReader* iface,
2612 const WCHAR **pBaseUrl)
2614 saxreader *This = impl_from_ISAXXMLReader( iface );
2615 return IVBSAXXMLReader_get_baseURL(
2616 (IVBSAXXMLReader*)&This->lpVBSAXXMLReaderVtbl,
2617 pBaseUrl);
2620 static HRESULT WINAPI isaxxmlreader_putBaseURL(
2621 ISAXXMLReader* iface,
2622 const WCHAR *pBaseUrl)
2624 saxreader *This = impl_from_ISAXXMLReader( iface );
2625 return IVBSAXXMLReader_put_baseURL(
2626 (IVBSAXXMLReader*)&This->lpVBSAXXMLReaderVtbl,
2627 pBaseUrl);
2630 static HRESULT WINAPI isaxxmlreader_getSecureBaseURL(
2631 ISAXXMLReader* iface,
2632 const WCHAR **pSecureBaseUrl)
2634 saxreader *This = impl_from_ISAXXMLReader( iface );
2635 return IVBSAXXMLReader_get_secureBaseURL(
2636 (IVBSAXXMLReader*)&This->lpVBSAXXMLReaderVtbl,
2637 pSecureBaseUrl);
2640 static HRESULT WINAPI isaxxmlreader_putSecureBaseURL(
2641 ISAXXMLReader* iface,
2642 const WCHAR *secureBaseUrl)
2644 saxreader *This = impl_from_ISAXXMLReader( iface );
2645 return IVBSAXXMLReader_put_secureBaseURL(
2646 (IVBSAXXMLReader*)&This->lpVBSAXXMLReaderVtbl,
2647 secureBaseUrl);
2650 static HRESULT WINAPI isaxxmlreader_parse(
2651 ISAXXMLReader* iface,
2652 VARIANT varInput)
2654 saxreader *This = impl_from_ISAXXMLReader( iface );
2655 return internal_parse(This, varInput, FALSE);
2658 static HRESULT WINAPI isaxxmlreader_parseURL(
2659 ISAXXMLReader* iface,
2660 const WCHAR *url)
2662 saxreader *This = impl_from_ISAXXMLReader( iface );
2663 return internal_parseURL(This, url, FALSE);
2666 static const struct ISAXXMLReaderVtbl isaxreader_vtbl =
2668 isaxxmlreader_QueryInterface,
2669 isaxxmlreader_AddRef,
2670 isaxxmlreader_Release,
2671 isaxxmlreader_getFeature,
2672 isaxxmlreader_putFeature,
2673 isaxxmlreader_getProperty,
2674 isaxxmlreader_putProperty,
2675 isaxxmlreader_getEntityResolver,
2676 isaxxmlreader_putEntityResolver,
2677 isaxxmlreader_getContentHandler,
2678 isaxxmlreader_putContentHandler,
2679 isaxxmlreader_getDTDHandler,
2680 isaxxmlreader_putDTDHandler,
2681 isaxxmlreader_getErrorHandler,
2682 isaxxmlreader_putErrorHandler,
2683 isaxxmlreader_getBaseURL,
2684 isaxxmlreader_putBaseURL,
2685 isaxxmlreader_getSecureBaseURL,
2686 isaxxmlreader_putSecureBaseURL,
2687 isaxxmlreader_parse,
2688 isaxxmlreader_parseURL
2691 HRESULT SAXXMLReader_create(IUnknown *pUnkOuter, LPVOID *ppObj)
2693 saxreader *reader;
2695 TRACE("(%p,%p)\n", pUnkOuter, ppObj);
2697 reader = HeapAlloc( GetProcessHeap(), 0, sizeof (*reader) );
2698 if( !reader )
2699 return E_OUTOFMEMORY;
2701 reader->lpVBSAXXMLReaderVtbl = &saxreader_vtbl;
2702 reader->lpSAXXMLReaderVtbl = &isaxreader_vtbl;
2703 reader->ref = 1;
2704 reader->contentHandler = NULL;
2705 reader->vbcontentHandler = NULL;
2706 reader->errorHandler = NULL;
2707 reader->vberrorHandler = NULL;
2708 reader->lexicalHandler = NULL;
2709 reader->vblexicalHandler = NULL;
2710 reader->declHandler = NULL;
2711 reader->vbdeclHandler = NULL;
2712 reader->isParsing = FALSE;
2714 memset(&reader->sax, 0, sizeof(xmlSAXHandler));
2715 reader->sax.initialized = XML_SAX2_MAGIC;
2716 reader->sax.startDocument = libxmlStartDocument;
2717 reader->sax.endDocument = libxmlEndDocument;
2718 reader->sax.startElementNs = libxmlStartElementNS;
2719 reader->sax.endElementNs = libxmlEndElementNS;
2720 reader->sax.characters = libxmlCharacters;
2721 reader->sax.setDocumentLocator = libxmlSetDocumentLocator;
2722 reader->sax.error = libxmlFatalError;
2723 reader->sax.fatalError = libxmlFatalError;
2725 *ppObj = &reader->lpVBSAXXMLReaderVtbl;
2727 TRACE("returning iface %p\n", *ppObj);
2729 return S_OK;
2732 #else
2734 HRESULT SAXXMLReader_create(IUnknown *pUnkOuter, LPVOID *ppObj)
2736 MESSAGE("This program tried to use a SAX XML Reader object, but\n"
2737 "libxml2 support was not present at compile time.\n");
2738 return E_NOTIMPL;
2741 #endif