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
27 # include <libxml/parser.h>
28 # include <libxml/xmlerror.h>
29 # include <libxml/SAX2.h>
30 # include <libxml/parserInternals.h>
44 #include "wine/debug.h"
46 #include "msxml_private.h"
48 WINE_DEFAULT_DEBUG_CHANNEL(msxml
);
59 typedef struct _saxreader
61 IVBSAXXMLReader IVBSAXXMLReader_iface
;
62 ISAXXMLReader ISAXXMLReader_iface
;
64 struct ISAXContentHandler
*contentHandler
;
65 struct IVBSAXContentHandler
*vbcontentHandler
;
66 struct ISAXErrorHandler
*errorHandler
;
67 struct IVBSAXErrorHandler
*vberrorHandler
;
68 struct ISAXLexicalHandler
*lexicalHandler
;
69 struct IVBSAXLexicalHandler
*vblexicalHandler
;
70 struct ISAXDeclHandler
*declHandler
;
71 struct IVBSAXDeclHandler
*vbdeclHandler
;
77 typedef struct _saxlocator
79 IVBSAXLocator IVBSAXLocator_iface
;
80 ISAXLocator ISAXLocator_iface
;
84 xmlParserCtxtPtr pParserCtxt
;
98 typedef struct _saxattributes
100 IVBSAXAttributes IVBSAXAttributes_iface
;
101 ISAXAttributes ISAXAttributes_iface
;
110 static inline saxreader
*impl_from_IVBSAXXMLReader( IVBSAXXMLReader
*iface
)
112 return CONTAINING_RECORD(iface
, saxreader
, IVBSAXXMLReader_iface
);
115 static inline saxreader
*impl_from_ISAXXMLReader( ISAXXMLReader
*iface
)
117 return CONTAINING_RECORD(iface
, saxreader
, ISAXXMLReader_iface
);
120 static inline saxlocator
*impl_from_IVBSAXLocator( IVBSAXLocator
*iface
)
122 return CONTAINING_RECORD(iface
, saxlocator
, IVBSAXLocator_iface
);
125 static inline saxlocator
*impl_from_ISAXLocator( ISAXLocator
*iface
)
127 return CONTAINING_RECORD(iface
, saxlocator
, ISAXLocator_iface
);
130 static inline saxattributes
*impl_from_IVBSAXAttributes( IVBSAXAttributes
*iface
)
132 return CONTAINING_RECORD(iface
, saxattributes
, IVBSAXAttributes_iface
);
135 static inline saxattributes
*impl_from_ISAXAttributes( ISAXAttributes
*iface
)
137 return CONTAINING_RECORD(iface
, saxattributes
, ISAXAttributes_iface
);
141 static const WCHAR PropertyCharsetW
[] = {
142 'c','h','a','r','s','e','t',0
144 static const WCHAR PropertyDeclHandlerW
[] = {
145 'h','t','t','p',':','/','/','x','m','l','.','o','r','g','/',
146 's','a','x','/','p','r','o','p','e','r','t','i','e','s','/',
147 'd','e','c','l','a','r','a','t','i','o','n',
148 '-','h','a','n','d','l','e','r',0
150 static const WCHAR PropertyDomNodeW
[] = {
151 'h','t','t','p',':','/','/','x','m','l','.','o','r','g','/',
152 's','a','x','/','p','r','o','p','e','r','t','i','e','s','/',
153 'd','o','m','-','n','o','d','e',0
155 static const WCHAR PropertyInputSourceW
[] = {
156 'i','n','p','u','t','-','s','o','u','r','c','e',0
158 static const WCHAR PropertyLexicalHandlerW
[] = {
159 'h','t','t','p',':','/','/','x','m','l','.','o','r','g','/',
160 's','a','x','/','p','r','o','p','e','r','t','i','e','s','/',
161 'l','e','x','i','c','a','l','-','h','a','n','d','l','e','r',0
163 static const WCHAR PropertyMaxElementDepthW
[] = {
164 'm','a','x','-','e','l','e','m','e','n','t','-','d','e','p','t','h',0
166 static const WCHAR PropertyMaxXMLSizeW
[] = {
167 'm','a','x','-','x','m','l','-','s','i','z','e',0
169 static const WCHAR PropertySchemaDeclHandlerW
[] = {
170 's','c','h','e','m','a','-','d','e','c','l','a','r','a','t','i','o','n','-',
171 'h','a','n','d','l','e','r',0
173 static const WCHAR PropertyXMLDeclEncodingW
[] = {
174 'x','m','l','d','e','c','l','-','e','n','c','o','d','i','n','g',0
176 static const WCHAR PropertyXMLDeclStandaloneW
[] = {
177 'x','m','l','d','e','c','l','-','s','t','a','n','d','a','l','o','n','e',0
179 static const WCHAR PropertyXMLDeclVersionW
[] = {
180 'x','m','l','d','e','c','l','-','v','e','r','s','i','o','n',0
183 static inline BOOL
has_content_handler(const saxlocator
*locator
)
185 return (locator
->vbInterface
&& locator
->saxreader
->vbcontentHandler
) ||
186 (!locator
->vbInterface
&& locator
->saxreader
->contentHandler
);
189 static inline BOOL
has_error_handler(const saxlocator
*locator
)
191 return (locator
->vbInterface
&& locator
->saxreader
->vberrorHandler
) ||
192 (!locator
->vbInterface
&& locator
->saxreader
->errorHandler
);
195 static HRESULT
namespacePush(saxlocator
*locator
, int ns
)
197 if(locator
->nsStackLast
>=locator
->nsStackSize
)
201 new_stack
= HeapReAlloc(GetProcessHeap(), 0,
202 locator
->nsStack
, sizeof(int)*locator
->nsStackSize
*2);
203 if(!new_stack
) return E_OUTOFMEMORY
;
204 locator
->nsStack
= new_stack
;
205 locator
->nsStackSize
*= 2;
207 locator
->nsStack
[locator
->nsStackLast
++] = ns
;
212 static int namespacePop(saxlocator
*locator
)
214 if(locator
->nsStackLast
== 0) return 0;
215 return locator
->nsStack
[--locator
->nsStackLast
];
218 static BOOL
bstr_pool_insert(struct bstrpool
*pool
, BSTR pool_entry
)
222 pool
->pool
= HeapAlloc(GetProcessHeap(), 0, 16 * sizeof(*pool
->pool
));
229 else if (pool
->index
== pool
->len
)
231 BSTR
*realloc
= HeapReAlloc(GetProcessHeap(), 0, pool
->pool
, pool
->len
* 2 * sizeof(*realloc
));
236 pool
->pool
= realloc
;
240 pool
->pool
[pool
->index
++] = pool_entry
;
244 static void free_bstr_pool(struct bstrpool
*pool
)
248 for (i
= 0; i
< pool
->index
; i
++)
249 SysFreeString(pool
->pool
[i
]);
251 HeapFree(GetProcessHeap(), 0, pool
->pool
);
254 pool
->index
= pool
->len
= 0;
257 static BSTR
bstr_from_xmlCharN(const xmlChar
*buf
, int len
)
265 dLen
= MultiByteToWideChar(CP_UTF8
, 0, (LPCSTR
)buf
, len
, NULL
, 0);
266 if(len
!= -1) dLen
++;
267 bstr
= SysAllocStringLen(NULL
, dLen
-1);
270 MultiByteToWideChar(CP_UTF8
, 0, (LPCSTR
)buf
, len
, bstr
, dLen
);
271 if(len
!= -1) bstr
[dLen
-1] = '\0';
276 static BSTR
QName_from_xmlChar(const xmlChar
*prefix
, const xmlChar
*name
)
281 if(!name
) return NULL
;
283 if(!prefix
|| !*prefix
)
284 return bstr_from_xmlChar(name
);
286 qname
= xmlBuildQName(name
, prefix
, NULL
, 0);
287 bstr
= bstr_from_xmlChar(qname
);
293 static BSTR
pooled_bstr_from_xmlChar(struct bstrpool
*pool
, const xmlChar
*buf
)
295 BSTR pool_entry
= bstr_from_xmlChar(buf
);
297 if (pool_entry
&& !bstr_pool_insert(pool
, pool_entry
))
299 SysFreeString(pool_entry
);
306 static BSTR
pooled_bstr_from_xmlCharN(struct bstrpool
*pool
, const xmlChar
*buf
, int len
)
308 BSTR pool_entry
= bstr_from_xmlCharN(buf
, len
);
310 if (pool_entry
&& !bstr_pool_insert(pool
, pool_entry
))
312 SysFreeString(pool_entry
);
319 static BSTR
pooled_QName_from_xmlChar(struct bstrpool
*pool
, const xmlChar
*prefix
, const xmlChar
*name
)
321 BSTR pool_entry
= QName_from_xmlChar(prefix
, name
);
323 if (pool_entry
&& !bstr_pool_insert(pool
, pool_entry
))
325 SysFreeString(pool_entry
);
332 static void format_error_message_from_id(saxlocator
*This
, HRESULT hr
)
334 xmlStopParser(This
->pParserCtxt
);
337 if(has_error_handler(This
))
340 if(!FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM
,
341 NULL
, hr
, 0, msg
, sizeof(msg
), NULL
))
343 FIXME("MSXML errors not yet supported.\n");
347 if(This
->vbInterface
)
349 BSTR bstrMsg
= SysAllocString(msg
);
350 IVBSAXErrorHandler_fatalError(This
->saxreader
->vberrorHandler
,
351 &This
->IVBSAXLocator_iface
, &bstrMsg
, hr
);
352 SysFreeString(bstrMsg
);
355 ISAXErrorHandler_fatalError(This
->saxreader
->errorHandler
,
356 &This
->ISAXLocator_iface
, msg
, hr
);
360 static void update_position(saxlocator
*This
, xmlChar
*end
)
362 if(This
->lastCur
== NULL
)
364 This
->lastCur
= (xmlChar
*)This
->pParserCtxt
->input
->base
;
366 This
->realColumn
= 1;
368 else if(This
->lastCur
< This
->pParserCtxt
->input
->base
)
370 This
->lastCur
= (xmlChar
*)This
->pParserCtxt
->input
->base
;
372 This
->realColumn
= 1;
375 if(This
->pParserCtxt
->input
->cur
<This
->lastCur
)
377 This
->lastCur
= (xmlChar
*)This
->pParserCtxt
->input
->base
;
379 This
->realColumn
= 1;
382 if(!end
) end
= (xmlChar
*)This
->pParserCtxt
->input
->cur
;
384 while(This
->lastCur
< end
)
386 if(*(This
->lastCur
) == '\n')
389 This
->realColumn
= 1;
391 else if(*(This
->lastCur
) == '\r' &&
392 (This
->lastCur
==This
->pParserCtxt
->input
->end
||
393 *(This
->lastCur
+1)!='\n'))
396 This
->realColumn
= 1;
398 else This
->realColumn
++;
402 /* Count multibyte UTF8 encoded characters once */
403 while((*(This
->lastCur
)&0xC0) == 0x80) This
->lastCur
++;
406 This
->line
= This
->realLine
;
407 This
->column
= This
->realColumn
;
410 /*** IVBSAXAttributes interface ***/
411 /*** IUnknown methods ***/
412 static HRESULT WINAPI
ivbsaxattributes_QueryInterface(
413 IVBSAXAttributes
* iface
,
417 saxattributes
*This
= impl_from_IVBSAXAttributes(iface
);
419 TRACE("%p %s %p\n", This
, debugstr_guid(riid
), ppvObject
);
423 if (IsEqualGUID(riid
, &IID_IUnknown
) ||
424 IsEqualGUID(riid
, &IID_IDispatch
) ||
425 IsEqualGUID(riid
, &IID_IVBSAXAttributes
))
431 FIXME("interface %s not implemented\n", debugstr_guid(riid
));
432 return E_NOINTERFACE
;
435 IVBSAXAttributes_AddRef(iface
);
440 static ULONG WINAPI
ivbsaxattributes_AddRef(IVBSAXAttributes
* iface
)
442 saxattributes
*This
= impl_from_IVBSAXAttributes(iface
);
443 return ISAXAttributes_AddRef(&This
->ISAXAttributes_iface
);
446 static ULONG WINAPI
ivbsaxattributes_Release(IVBSAXAttributes
* iface
)
448 saxattributes
*This
= impl_from_IVBSAXAttributes(iface
);
449 return ISAXAttributes_Release(&This
->ISAXAttributes_iface
);
452 /*** IDispatch methods ***/
453 static HRESULT WINAPI
ivbsaxattributes_GetTypeInfoCount( IVBSAXAttributes
*iface
, UINT
* pctinfo
)
455 saxattributes
*This
= impl_from_IVBSAXAttributes( iface
);
457 TRACE("(%p)->(%p)\n", This
, pctinfo
);
464 static HRESULT WINAPI
ivbsaxattributes_GetTypeInfo(
465 IVBSAXAttributes
*iface
,
466 UINT iTInfo
, LCID lcid
, ITypeInfo
** ppTInfo
)
468 saxattributes
*This
= impl_from_IVBSAXAttributes( iface
);
471 TRACE("(%p)->(%u %u %p)\n", This
, iTInfo
, lcid
, ppTInfo
);
473 hr
= get_typeinfo(IVBSAXAttributes_tid
, ppTInfo
);
478 static HRESULT WINAPI
ivbsaxattributes_GetIDsOfNames(
479 IVBSAXAttributes
*iface
,
486 saxattributes
*This
= impl_from_IVBSAXAttributes( iface
);
490 TRACE("(%p)->(%s %p %u %u %p)\n", This
, debugstr_guid(riid
), rgszNames
, cNames
,
493 if(!rgszNames
|| cNames
== 0 || !rgDispId
)
496 hr
= get_typeinfo(IVBSAXAttributes_tid
, &typeinfo
);
499 hr
= ITypeInfo_GetIDsOfNames(typeinfo
, rgszNames
, cNames
, rgDispId
);
500 ITypeInfo_Release(typeinfo
);
506 static HRESULT WINAPI
ivbsaxattributes_Invoke(
507 IVBSAXAttributes
*iface
,
512 DISPPARAMS
* pDispParams
,
514 EXCEPINFO
* pExcepInfo
,
517 saxattributes
*This
= impl_from_IVBSAXAttributes( iface
);
521 TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This
, dispIdMember
, debugstr_guid(riid
),
522 lcid
, wFlags
, pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
524 hr
= get_typeinfo(IVBSAXAttributes_tid
, &typeinfo
);
527 hr
= ITypeInfo_Invoke(typeinfo
, &This
->IVBSAXAttributes_iface
, dispIdMember
, wFlags
,
528 pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
529 ITypeInfo_Release(typeinfo
);
535 /*** IVBSAXAttributes methods ***/
536 static HRESULT WINAPI
ivbsaxattributes_get_length(
537 IVBSAXAttributes
* iface
,
540 saxattributes
*This
= impl_from_IVBSAXAttributes( iface
);
541 return ISAXAttributes_getLength(&This
->ISAXAttributes_iface
, nLength
);
544 static HRESULT WINAPI
ivbsaxattributes_getURI(
545 IVBSAXAttributes
* iface
,
550 saxattributes
*This
= impl_from_IVBSAXAttributes( iface
);
551 return ISAXAttributes_getURI(&This
->ISAXAttributes_iface
, nIndex
, (const WCHAR
**)uri
, &len
);
554 static HRESULT WINAPI
ivbsaxattributes_getLocalName(
555 IVBSAXAttributes
* iface
,
560 saxattributes
*This
= impl_from_IVBSAXAttributes( iface
);
561 return ISAXAttributes_getLocalName(&This
->ISAXAttributes_iface
, nIndex
,
562 (const WCHAR
**)localName
, &len
);
565 static HRESULT WINAPI
ivbsaxattributes_getQName(
566 IVBSAXAttributes
* iface
,
571 saxattributes
*This
= impl_from_IVBSAXAttributes( iface
);
572 return ISAXAttributes_getQName(&This
->ISAXAttributes_iface
, nIndex
, (const WCHAR
**)QName
, &len
);
575 static HRESULT WINAPI
ivbsaxattributes_getIndexFromName(
576 IVBSAXAttributes
* iface
,
581 saxattributes
*This
= impl_from_IVBSAXAttributes( iface
);
582 return ISAXAttributes_getIndexFromName(&This
->ISAXAttributes_iface
, uri
, SysStringLen(uri
),
583 localName
, SysStringLen(localName
), index
);
586 static HRESULT WINAPI
ivbsaxattributes_getIndexFromQName(
587 IVBSAXAttributes
* iface
,
591 saxattributes
*This
= impl_from_IVBSAXAttributes( iface
);
592 return ISAXAttributes_getIndexFromQName(&This
->ISAXAttributes_iface
, QName
,
593 SysStringLen(QName
), index
);
596 static HRESULT WINAPI
ivbsaxattributes_getType(
597 IVBSAXAttributes
* iface
,
602 saxattributes
*This
= impl_from_IVBSAXAttributes( iface
);
603 return ISAXAttributes_getType(&This
->ISAXAttributes_iface
, nIndex
, (const WCHAR
**)type
, &len
);
606 static HRESULT WINAPI
ivbsaxattributes_getTypeFromName(
607 IVBSAXAttributes
* iface
,
613 saxattributes
*This
= impl_from_IVBSAXAttributes( iface
);
614 return ISAXAttributes_getTypeFromName(&This
->ISAXAttributes_iface
, uri
, SysStringLen(uri
),
615 localName
, SysStringLen(localName
), (const WCHAR
**)type
, &len
);
618 static HRESULT WINAPI
ivbsaxattributes_getTypeFromQName(
619 IVBSAXAttributes
* iface
,
624 saxattributes
*This
= impl_from_IVBSAXAttributes( iface
);
625 return ISAXAttributes_getTypeFromQName(&This
->ISAXAttributes_iface
, QName
, SysStringLen(QName
),
626 (const WCHAR
**)type
, &len
);
629 static HRESULT WINAPI
ivbsaxattributes_getValue(
630 IVBSAXAttributes
* iface
,
635 saxattributes
*This
= impl_from_IVBSAXAttributes( iface
);
636 return ISAXAttributes_getValue(&This
->ISAXAttributes_iface
, nIndex
, (const WCHAR
**)value
, &len
);
639 static HRESULT WINAPI
ivbsaxattributes_getValueFromName(
640 IVBSAXAttributes
* iface
,
646 saxattributes
*This
= impl_from_IVBSAXAttributes( iface
);
647 return ISAXAttributes_getValueFromName(&This
->ISAXAttributes_iface
, uri
, SysStringLen(uri
),
648 localName
, SysStringLen(localName
), (const WCHAR
**)value
, &len
);
651 static HRESULT WINAPI
ivbsaxattributes_getValueFromQName(
652 IVBSAXAttributes
* iface
,
657 saxattributes
*This
= impl_from_IVBSAXAttributes( iface
);
658 return ISAXAttributes_getValueFromQName(&This
->ISAXAttributes_iface
, QName
,
659 SysStringLen(QName
), (const WCHAR
**)value
, &len
);
662 static const struct IVBSAXAttributesVtbl ivbsaxattributes_vtbl
=
664 ivbsaxattributes_QueryInterface
,
665 ivbsaxattributes_AddRef
,
666 ivbsaxattributes_Release
,
667 ivbsaxattributes_GetTypeInfoCount
,
668 ivbsaxattributes_GetTypeInfo
,
669 ivbsaxattributes_GetIDsOfNames
,
670 ivbsaxattributes_Invoke
,
671 ivbsaxattributes_get_length
,
672 ivbsaxattributes_getURI
,
673 ivbsaxattributes_getLocalName
,
674 ivbsaxattributes_getQName
,
675 ivbsaxattributes_getIndexFromName
,
676 ivbsaxattributes_getIndexFromQName
,
677 ivbsaxattributes_getType
,
678 ivbsaxattributes_getTypeFromName
,
679 ivbsaxattributes_getTypeFromQName
,
680 ivbsaxattributes_getValue
,
681 ivbsaxattributes_getValueFromName
,
682 ivbsaxattributes_getValueFromQName
685 /*** ISAXAttributes interface ***/
686 /*** IUnknown methods ***/
687 static HRESULT WINAPI
isaxattributes_QueryInterface(
688 ISAXAttributes
* iface
,
692 saxattributes
*This
= impl_from_ISAXAttributes(iface
);
694 TRACE("%p %s %p\n", This
, debugstr_guid(riid
), ppvObject
);
698 if (IsEqualGUID(riid
, &IID_IUnknown
) ||
699 IsEqualGUID(riid
, &IID_ISAXAttributes
))
705 FIXME("interface %s not implemented\n", debugstr_guid(riid
));
706 return E_NOINTERFACE
;
709 ISAXAttributes_AddRef(iface
);
714 static ULONG WINAPI
isaxattributes_AddRef(ISAXAttributes
* iface
)
716 saxattributes
*This
= impl_from_ISAXAttributes(iface
);
718 return InterlockedIncrement(&This
->ref
);
721 static ULONG WINAPI
isaxattributes_Release(ISAXAttributes
* iface
)
723 saxattributes
*This
= impl_from_ISAXAttributes(iface
);
728 ref
= InterlockedDecrement(&This
->ref
);
732 for(index
=0; index
<This
->nb_attributes
; index
++)
734 SysFreeString(This
->szLocalname
[index
]);
735 SysFreeString(This
->szURI
[index
]);
736 SysFreeString(This
->szValue
[index
]);
737 SysFreeString(This
->szQName
[index
]);
740 heap_free(This
->szLocalname
);
741 heap_free(This
->szURI
);
742 heap_free(This
->szValue
);
743 heap_free(This
->szQName
);
751 /*** ISAXAttributes methods ***/
752 static HRESULT WINAPI
isaxattributes_getLength(
753 ISAXAttributes
* iface
,
756 saxattributes
*This
= impl_from_ISAXAttributes( iface
);
758 *length
= This
->nb_attributes
;
759 TRACE("Length set to %d\n", *length
);
763 static HRESULT WINAPI
isaxattributes_getURI(
764 ISAXAttributes
* iface
,
769 saxattributes
*This
= impl_from_ISAXAttributes( iface
);
770 TRACE("(%p)->(%d)\n", This
, nIndex
);
772 if(nIndex
>=This
->nb_attributes
|| nIndex
<0) return E_INVALIDARG
;
773 if(!pUrl
|| !pUriSize
) return E_POINTER
;
775 *pUriSize
= SysStringLen(This
->szURI
[nIndex
]);
776 *pUrl
= This
->szURI
[nIndex
];
781 static HRESULT WINAPI
isaxattributes_getLocalName(
782 ISAXAttributes
* iface
,
784 const WCHAR
**pLocalName
,
785 int *pLocalNameLength
)
787 saxattributes
*This
= impl_from_ISAXAttributes( iface
);
788 TRACE("(%p)->(%d)\n", This
, nIndex
);
790 if(nIndex
>=This
->nb_attributes
|| nIndex
<0) return E_INVALIDARG
;
791 if(!pLocalName
|| !pLocalNameLength
) return E_POINTER
;
793 *pLocalNameLength
= SysStringLen(This
->szLocalname
[nIndex
]);
794 *pLocalName
= This
->szLocalname
[nIndex
];
799 static HRESULT WINAPI
isaxattributes_getQName(
800 ISAXAttributes
* iface
,
802 const WCHAR
**pQName
,
805 saxattributes
*This
= impl_from_ISAXAttributes( iface
);
806 TRACE("(%p)->(%d)\n", This
, nIndex
);
808 if(nIndex
>=This
->nb_attributes
|| nIndex
<0) return E_INVALIDARG
;
809 if(!pQName
|| !pQNameLength
) return E_POINTER
;
811 *pQNameLength
= SysStringLen(This
->szQName
[nIndex
]);
812 *pQName
= This
->szQName
[nIndex
];
817 static HRESULT WINAPI
isaxattributes_getName(
818 ISAXAttributes
* iface
,
822 const WCHAR
**pLocalName
,
824 const WCHAR
**pQName
,
827 saxattributes
*This
= impl_from_ISAXAttributes( iface
);
828 TRACE("(%p)->(%d)\n", This
, nIndex
);
830 if(nIndex
>=This
->nb_attributes
|| nIndex
<0) return E_INVALIDARG
;
831 if(!pUri
|| !pUriLength
|| !pLocalName
|| !pLocalNameSize
832 || !pQName
|| !pQNameLength
) return E_POINTER
;
834 *pUriLength
= SysStringLen(This
->szURI
[nIndex
]);
835 *pUri
= This
->szURI
[nIndex
];
836 *pLocalNameSize
= SysStringLen(This
->szLocalname
[nIndex
]);
837 *pLocalName
= This
->szLocalname
[nIndex
];
838 *pQNameLength
= SysStringLen(This
->szQName
[nIndex
]);
839 *pQName
= This
->szQName
[nIndex
];
844 static HRESULT WINAPI
isaxattributes_getIndexFromName(
845 ISAXAttributes
* iface
,
848 const WCHAR
*pLocalName
,
852 saxattributes
*This
= impl_from_ISAXAttributes( iface
);
854 TRACE("(%p)->(%s, %d, %s, %d)\n", This
, debugstr_w(pUri
), cUriLength
,
855 debugstr_w(pLocalName
), cocalNameLength
);
857 if(!pUri
|| !pLocalName
|| !index
) return E_POINTER
;
859 for(i
=0; i
<This
->nb_attributes
; i
++)
861 if(cUriLength
!=SysStringLen(This
->szURI
[i
])
862 || cocalNameLength
!=SysStringLen(This
->szLocalname
[i
]))
864 if(cUriLength
&& memcmp(pUri
, This
->szURI
[i
],
865 sizeof(WCHAR
)*cUriLength
))
867 if(cocalNameLength
&& memcmp(pLocalName
, This
->szLocalname
[i
],
868 sizeof(WCHAR
)*cocalNameLength
))
878 static HRESULT WINAPI
isaxattributes_getIndexFromQName(
879 ISAXAttributes
* iface
,
884 saxattributes
*This
= impl_from_ISAXAttributes( iface
);
886 TRACE("(%p)->(%s, %d)\n", This
, debugstr_w(pQName
), nQNameLength
);
888 if(!pQName
|| !index
) return E_POINTER
;
889 if(!nQNameLength
) return E_INVALIDARG
;
891 for(i
=0; i
<This
->nb_attributes
; i
++)
893 if(nQNameLength
!=SysStringLen(This
->szQName
[i
])) continue;
894 if(memcmp(pQName
, This
->szQName
, sizeof(WCHAR
)*nQNameLength
)) continue;
903 static HRESULT WINAPI
isaxattributes_getType(
904 ISAXAttributes
* iface
,
909 saxattributes
*This
= impl_from_ISAXAttributes( iface
);
911 FIXME("(%p)->(%d) stub\n", This
, nIndex
);
915 static HRESULT WINAPI
isaxattributes_getTypeFromName(
916 ISAXAttributes
* iface
,
919 const WCHAR
*pLocalName
,
924 saxattributes
*This
= impl_from_ISAXAttributes( iface
);
926 FIXME("(%p)->(%s, %d, %s, %d) stub\n", This
, debugstr_w(pUri
), nUri
,
927 debugstr_w(pLocalName
), nLocalName
);
931 static HRESULT WINAPI
isaxattributes_getTypeFromQName(
932 ISAXAttributes
* iface
,
938 saxattributes
*This
= impl_from_ISAXAttributes( iface
);
940 FIXME("(%p)->(%s, %d) stub\n", This
, debugstr_w(pQName
), nQName
);
944 static HRESULT WINAPI
isaxattributes_getValue(
945 ISAXAttributes
* iface
,
947 const WCHAR
**pValue
,
950 saxattributes
*This
= impl_from_ISAXAttributes( iface
);
951 TRACE("(%p)->(%d)\n", This
, nIndex
);
953 if(nIndex
>=This
->nb_attributes
|| nIndex
<0) return E_INVALIDARG
;
954 if(!pValue
|| !nValue
) return E_POINTER
;
956 *nValue
= SysStringLen(This
->szValue
[nIndex
]);
957 *pValue
= This
->szValue
[nIndex
];
962 static HRESULT WINAPI
isaxattributes_getValueFromName(
963 ISAXAttributes
* iface
,
966 const WCHAR
*pLocalName
,
968 const WCHAR
**pValue
,
973 saxattributes
*This
= impl_from_ISAXAttributes( iface
);
974 TRACE("(%p)->(%s, %d, %s, %d)\n", This
, debugstr_w(pUri
), nUri
,
975 debugstr_w(pLocalName
), nLocalName
);
977 hr
= ISAXAttributes_getIndexFromName(iface
,
978 pUri
, nUri
, pLocalName
, nLocalName
, &index
);
979 if(hr
==S_OK
) hr
= ISAXAttributes_getValue(iface
, index
, pValue
, nValue
);
984 static HRESULT WINAPI
isaxattributes_getValueFromQName(
985 ISAXAttributes
* iface
,
988 const WCHAR
**pValue
,
993 saxattributes
*This
= impl_from_ISAXAttributes( iface
);
994 TRACE("(%p)->(%s, %d)\n", This
, debugstr_w(pQName
), nQName
);
996 hr
= ISAXAttributes_getIndexFromQName(iface
, pQName
, nQName
, &index
);
997 if(hr
==S_OK
) hr
= ISAXAttributes_getValue(iface
, index
, pValue
, nValue
);
1002 static const struct ISAXAttributesVtbl isaxattributes_vtbl
=
1004 isaxattributes_QueryInterface
,
1005 isaxattributes_AddRef
,
1006 isaxattributes_Release
,
1007 isaxattributes_getLength
,
1008 isaxattributes_getURI
,
1009 isaxattributes_getLocalName
,
1010 isaxattributes_getQName
,
1011 isaxattributes_getName
,
1012 isaxattributes_getIndexFromName
,
1013 isaxattributes_getIndexFromQName
,
1014 isaxattributes_getType
,
1015 isaxattributes_getTypeFromName
,
1016 isaxattributes_getTypeFromQName
,
1017 isaxattributes_getValue
,
1018 isaxattributes_getValueFromName
,
1019 isaxattributes_getValueFromQName
1022 static HRESULT
SAXAttributes_create(saxattributes
**attr
,
1023 int nb_namespaces
, const xmlChar
**xmlNamespaces
,
1024 int nb_attributes
, const xmlChar
**xmlAttributes
)
1026 saxattributes
*attributes
;
1028 static const xmlChar xmlns
[] = "xmlns";
1030 attributes
= heap_alloc(sizeof(*attributes
));
1032 return E_OUTOFMEMORY
;
1034 attributes
->IVBSAXAttributes_iface
.lpVtbl
= &ivbsaxattributes_vtbl
;
1035 attributes
->ISAXAttributes_iface
.lpVtbl
= &isaxattributes_vtbl
;
1036 attributes
->ref
= 1;
1038 attributes
->nb_attributes
= nb_namespaces
+nb_attributes
;
1040 attributes
->szLocalname
= heap_alloc(sizeof(BSTR
)*attributes
->nb_attributes
);
1041 attributes
->szURI
= heap_alloc(sizeof(BSTR
)*attributes
->nb_attributes
);
1042 attributes
->szValue
= heap_alloc(sizeof(BSTR
)*attributes
->nb_attributes
);
1043 attributes
->szQName
= heap_alloc(sizeof(BSTR
)*attributes
->nb_attributes
);
1045 if(!attributes
->szLocalname
|| !attributes
->szURI
1046 || !attributes
->szValue
|| !attributes
->szQName
)
1048 heap_free(attributes
->szLocalname
);
1049 heap_free(attributes
->szURI
);
1050 heap_free(attributes
->szValue
);
1051 heap_free(attributes
->szQName
);
1052 heap_free(attributes
);
1056 for(index
=0; index
<nb_namespaces
; index
++)
1058 attributes
->szLocalname
[index
] = SysAllocStringLen(NULL
, 0);
1059 attributes
->szURI
[index
] = SysAllocStringLen(NULL
, 0);
1060 attributes
->szValue
[index
] = bstr_from_xmlChar(xmlNamespaces
[2*index
+1]);
1061 attributes
->szQName
[index
] = QName_from_xmlChar(xmlns
, xmlNamespaces
[2*index
]);
1064 for(index
=0; index
<nb_attributes
; index
++)
1066 attributes
->szLocalname
[nb_namespaces
+index
] =
1067 bstr_from_xmlChar(xmlAttributes
[index
*5]);
1068 attributes
->szURI
[nb_namespaces
+index
] =
1069 bstr_from_xmlChar(xmlAttributes
[index
*5+2]);
1070 attributes
->szValue
[nb_namespaces
+index
] =
1071 bstr_from_xmlCharN(xmlAttributes
[index
*5+3],
1072 xmlAttributes
[index
*5+4]-xmlAttributes
[index
*5+3]);
1073 attributes
->szQName
[nb_namespaces
+index
] =
1074 QName_from_xmlChar(xmlAttributes
[index
*5+1], xmlAttributes
[index
*5]);
1079 TRACE("returning %p\n", *attr
);
1084 /*** LibXML callbacks ***/
1085 static void libxmlStartDocument(void *ctx
)
1087 saxlocator
*This
= ctx
;
1090 if(has_content_handler(This
))
1092 if(This
->vbInterface
)
1093 hr
= IVBSAXContentHandler_startDocument(This
->saxreader
->vbcontentHandler
);
1095 hr
= ISAXContentHandler_startDocument(This
->saxreader
->contentHandler
);
1098 format_error_message_from_id(This
, hr
);
1101 update_position(This
, NULL
);
1104 static void libxmlEndDocument(void *ctx
)
1106 saxlocator
*This
= ctx
;
1112 if(This
->ret
!= S_OK
) return;
1114 if(has_content_handler(This
))
1116 if(This
->vbInterface
)
1117 hr
= IVBSAXContentHandler_endDocument(This
->saxreader
->vbcontentHandler
);
1119 hr
= ISAXContentHandler_endDocument(This
->saxreader
->contentHandler
);
1122 format_error_message_from_id(This
, hr
);
1126 static void libxmlStartElementNS(
1128 const xmlChar
*localname
,
1129 const xmlChar
*prefix
,
1132 const xmlChar
**namespaces
,
1135 const xmlChar
**attributes
)
1137 BSTR NamespaceUri
, LocalName
, QName
, Prefix
, Uri
;
1138 saxlocator
*This
= ctx
;
1140 saxattributes
*attr
;
1143 if(*(This
->pParserCtxt
->input
->cur
) == '/')
1144 update_position(This
, (xmlChar
*)This
->pParserCtxt
->input
->cur
+2);
1146 update_position(This
, (xmlChar
*)This
->pParserCtxt
->input
->cur
+1);
1148 hr
= namespacePush(This
, nb_namespaces
);
1149 if(hr
==S_OK
&& has_content_handler(This
))
1151 for(index
=0; index
<nb_namespaces
; index
++)
1153 Prefix
= pooled_bstr_from_xmlChar(&This
->saxreader
->pool
, namespaces
[2*index
]);
1154 Uri
= pooled_bstr_from_xmlChar(&This
->saxreader
->pool
, namespaces
[2*index
+1]);
1156 if(This
->vbInterface
)
1157 hr
= IVBSAXContentHandler_startPrefixMapping(
1158 This
->saxreader
->vbcontentHandler
,
1161 hr
= ISAXContentHandler_startPrefixMapping(
1162 This
->saxreader
->contentHandler
,
1163 Prefix
, SysStringLen(Prefix
),
1164 Uri
, SysStringLen(Uri
));
1168 format_error_message_from_id(This
, hr
);
1173 NamespaceUri
= pooled_bstr_from_xmlChar(&This
->saxreader
->pool
, URI
);
1174 LocalName
= pooled_bstr_from_xmlChar(&This
->saxreader
->pool
, localname
);
1175 QName
= pooled_QName_from_xmlChar(&This
->saxreader
->pool
, prefix
, localname
);
1177 hr
= SAXAttributes_create(&attr
, nb_namespaces
, namespaces
, nb_attributes
, attributes
);
1180 if(This
->vbInterface
)
1181 hr
= IVBSAXContentHandler_startElement(This
->saxreader
->vbcontentHandler
,
1182 &NamespaceUri
, &LocalName
, &QName
, &attr
->IVBSAXAttributes_iface
);
1184 hr
= ISAXContentHandler_startElement(This
->saxreader
->contentHandler
, NamespaceUri
,
1185 SysStringLen(NamespaceUri
), LocalName
, SysStringLen(LocalName
), QName
,
1186 SysStringLen(QName
), &attr
->ISAXAttributes_iface
);
1188 ISAXAttributes_Release(&attr
->ISAXAttributes_iface
);
1193 format_error_message_from_id(This
, hr
);
1196 static void libxmlEndElementNS(
1198 const xmlChar
*localname
,
1199 const xmlChar
*prefix
,
1202 BSTR NamespaceUri
, LocalName
, QName
, Prefix
;
1203 saxlocator
*This
= ctx
;
1208 end
= (xmlChar
*)This
->pParserCtxt
->input
->cur
;
1209 if(*(end
-1) != '>' || *(end
-2) != '/')
1210 while(end
-2>=This
->pParserCtxt
->input
->base
1211 && *(end
-2)!='<' && *(end
-1)!='/') end
--;
1213 update_position(This
, end
);
1215 nsNr
= namespacePop(This
);
1217 if(has_content_handler(This
))
1219 NamespaceUri
= pooled_bstr_from_xmlChar(&This
->saxreader
->pool
, URI
);
1220 LocalName
= pooled_bstr_from_xmlChar(&This
->saxreader
->pool
, localname
);
1221 QName
= pooled_QName_from_xmlChar(&This
->saxreader
->pool
, prefix
, localname
);
1223 if(This
->vbInterface
)
1224 hr
= IVBSAXContentHandler_endElement(
1225 This
->saxreader
->vbcontentHandler
,
1226 &NamespaceUri
, &LocalName
, &QName
);
1228 hr
= ISAXContentHandler_endElement(
1229 This
->saxreader
->contentHandler
,
1230 NamespaceUri
, SysStringLen(NamespaceUri
),
1231 LocalName
, SysStringLen(LocalName
),
1232 QName
, SysStringLen(QName
));
1236 format_error_message_from_id(This
, hr
);
1240 for(index
=This
->pParserCtxt
->nsNr
-2;
1241 index
>=This
->pParserCtxt
->nsNr
-nsNr
*2; index
-=2)
1243 Prefix
= pooled_bstr_from_xmlChar(&This
->saxreader
->pool
, This
->pParserCtxt
->nsTab
[index
]);
1245 if(This
->vbInterface
)
1246 hr
= IVBSAXContentHandler_endPrefixMapping(
1247 This
->saxreader
->vbcontentHandler
, &Prefix
);
1249 hr
= ISAXContentHandler_endPrefixMapping(
1250 This
->saxreader
->contentHandler
,
1251 Prefix
, SysStringLen(Prefix
));
1255 format_error_message_from_id(This
, hr
);
1262 update_position(This
, NULL
);
1265 static void libxmlCharacters(
1270 saxlocator
*This
= ctx
;
1275 BOOL lastEvent
= FALSE
;
1277 if(!(has_content_handler(This
))) return;
1280 if(*(ch
-1)=='\r') cur
--;
1283 if(ch
<This
->pParserCtxt
->input
->base
|| ch
>This
->pParserCtxt
->input
->end
)
1288 while(end
-ch
<len
&& *end
!='\r') end
++;
1295 if(!lastEvent
) *end
= '\n';
1297 Chars
= pooled_bstr_from_xmlCharN(&This
->saxreader
->pool
, cur
, end
-cur
+1);
1298 if(This
->vbInterface
)
1299 hr
= IVBSAXContentHandler_characters(
1300 This
->saxreader
->vbcontentHandler
, &Chars
);
1302 hr
= ISAXContentHandler_characters(
1303 This
->saxreader
->contentHandler
,
1304 Chars
, SysStringLen(Chars
));
1308 format_error_message_from_id(This
, hr
);
1312 This
->column
+= end
-cur
+1;
1326 if(end
-ch
== len
) break;
1329 if(ch
<This
->pParserCtxt
->input
->base
|| ch
>This
->pParserCtxt
->input
->end
)
1330 This
->column
= This
->realColumn
1331 +This
->pParserCtxt
->input
->cur
-This
->lastCur
;
1334 static void libxmlSetDocumentLocator(
1336 xmlSAXLocatorPtr loc
)
1338 saxlocator
*This
= ctx
;
1341 if(has_content_handler(This
))
1343 if(This
->vbInterface
)
1344 hr
= IVBSAXContentHandler_putref_documentLocator(This
->saxreader
->vbcontentHandler
,
1345 &This
->IVBSAXLocator_iface
);
1347 hr
= ISAXContentHandler_putDocumentLocator(This
->saxreader
->contentHandler
,
1348 &This
->ISAXLocator_iface
);
1352 format_error_message_from_id(This
, hr
);
1355 static void libxmlComment(void *ctx
, const xmlChar
*value
)
1357 saxlocator
*This
= ctx
;
1360 xmlChar
*beg
= (xmlChar
*)This
->pParserCtxt
->input
->cur
;
1362 while(beg
-4>=This
->pParserCtxt
->input
->base
1363 && memcmp(beg
-4, "<!--", sizeof(char[4]))) beg
--;
1364 update_position(This
, beg
);
1366 if(!This
->vbInterface
&& !This
->saxreader
->lexicalHandler
) return;
1367 if(This
->vbInterface
&& !This
->saxreader
->vblexicalHandler
) return;
1369 bValue
= pooled_bstr_from_xmlChar(&This
->saxreader
->pool
, value
);
1371 if(This
->vbInterface
)
1372 hr
= IVBSAXLexicalHandler_comment(
1373 This
->saxreader
->vblexicalHandler
, &bValue
);
1375 hr
= ISAXLexicalHandler_comment(
1376 This
->saxreader
->lexicalHandler
,
1377 bValue
, SysStringLen(bValue
));
1380 format_error_message_from_id(This
, hr
);
1382 update_position(This
, NULL
);
1385 static void libxmlFatalError(void *ctx
, const char *msg
, ...)
1387 saxlocator
*This
= ctx
;
1393 va_start(args
, msg
);
1394 vsprintf(message
, msg
, args
);
1397 len
= MultiByteToWideChar(CP_UNIXCP
, 0, message
, -1, NULL
, 0);
1398 error
= heap_alloc(sizeof(WCHAR
)*len
);
1401 MultiByteToWideChar(CP_UNIXCP
, 0, message
, -1, error
, len
);
1402 TRACE("fatal error for %p: %s\n", This
, debugstr_w(error
));
1405 if(!has_error_handler(This
))
1407 xmlStopParser(This
->pParserCtxt
);
1413 FIXME("Error handling is not compatible.\n");
1415 if(This
->vbInterface
)
1417 BSTR bstrError
= SysAllocString(error
);
1418 IVBSAXErrorHandler_fatalError(This
->saxreader
->vberrorHandler
, &This
->IVBSAXLocator_iface
,
1419 &bstrError
, E_FAIL
);
1420 SysFreeString(bstrError
);
1423 ISAXErrorHandler_fatalError(This
->saxreader
->errorHandler
, &This
->ISAXLocator_iface
,
1428 xmlStopParser(This
->pParserCtxt
);
1432 static void libxmlCDataBlock(void *ctx
, const xmlChar
*value
, int len
)
1434 saxlocator
*This
= ctx
;
1436 xmlChar
*beg
= (xmlChar
*)This
->pParserCtxt
->input
->cur
-len
;
1440 BOOL lastEvent
= FALSE
, change
;
1442 while(beg
-9>=This
->pParserCtxt
->input
->base
1443 && memcmp(beg
-9, "<![CDATA[", sizeof(char[9]))) beg
--;
1444 update_position(This
, beg
);
1446 if(This
->vbInterface
&& This
->saxreader
->vblexicalHandler
)
1447 hr
= IVBSAXLexicalHandler_startCDATA(This
->saxreader
->vblexicalHandler
);
1448 if(!This
->vbInterface
&& This
->saxreader
->lexicalHandler
)
1449 hr
= ISAXLexicalHandler_startCDATA(This
->saxreader
->lexicalHandler
);
1453 format_error_message_from_id(This
, hr
);
1457 realLen
= This
->pParserCtxt
->input
->cur
-beg
-3;
1463 while(end
-beg
<realLen
&& *end
!='\r') end
++;
1464 if(end
-beg
==realLen
)
1469 else if(end
-beg
==realLen
-1 && *end
=='\r' && *(end
+1)=='\n')
1472 if(*end
== '\r') change
= TRUE
;
1473 else change
= FALSE
;
1475 if(change
) *end
= '\n';
1477 if(has_content_handler(This
))
1479 Chars
= pooled_bstr_from_xmlCharN(&This
->saxreader
->pool
, cur
, end
-cur
+1);
1480 if(This
->vbInterface
)
1481 hr
= IVBSAXContentHandler_characters(
1482 This
->saxreader
->vbcontentHandler
, &Chars
);
1484 hr
= ISAXContentHandler_characters(
1485 This
->saxreader
->contentHandler
,
1486 Chars
, SysStringLen(Chars
));
1489 if(change
) *end
= '\r';
1494 This
->column
+= end
-cur
+2;
1499 if(This
->vbInterface
&& This
->saxreader
->vblexicalHandler
)
1500 hr
= IVBSAXLexicalHandler_endCDATA(This
->saxreader
->vblexicalHandler
);
1501 if(!This
->vbInterface
&& This
->saxreader
->lexicalHandler
)
1502 hr
= ISAXLexicalHandler_endCDATA(This
->saxreader
->lexicalHandler
);
1505 format_error_message_from_id(This
, hr
);
1507 This
->column
+= 4+end
-cur
;
1510 /*** IVBSAXLocator interface ***/
1511 /*** IUnknown methods ***/
1512 static HRESULT WINAPI
ivbsaxlocator_QueryInterface(IVBSAXLocator
* iface
, REFIID riid
, void **ppvObject
)
1514 saxlocator
*This
= impl_from_IVBSAXLocator( iface
);
1516 TRACE("%p %s %p\n", This
, debugstr_guid( riid
), ppvObject
);
1520 if ( IsEqualGUID( riid
, &IID_IUnknown
) ||
1521 IsEqualGUID( riid
, &IID_IDispatch
) ||
1522 IsEqualGUID( riid
, &IID_IVBSAXLocator
))
1528 FIXME("interface %s not implemented\n", debugstr_guid(riid
));
1529 return E_NOINTERFACE
;
1532 IVBSAXLocator_AddRef( iface
);
1537 static ULONG WINAPI
ivbsaxlocator_AddRef(IVBSAXLocator
* iface
)
1539 saxlocator
*This
= impl_from_IVBSAXLocator( iface
);
1540 TRACE("%p\n", This
);
1541 return InterlockedIncrement( &This
->ref
);
1544 static ULONG WINAPI
ivbsaxlocator_Release(
1545 IVBSAXLocator
* iface
)
1547 saxlocator
*This
= impl_from_IVBSAXLocator( iface
);
1548 return ISAXLocator_Release((ISAXLocator
*)&This
->IVBSAXLocator_iface
);
1551 /*** IDispatch methods ***/
1552 static HRESULT WINAPI
ivbsaxlocator_GetTypeInfoCount( IVBSAXLocator
*iface
, UINT
* pctinfo
)
1554 saxlocator
*This
= impl_from_IVBSAXLocator( iface
);
1556 TRACE("(%p)->(%p)\n", This
, pctinfo
);
1563 static HRESULT WINAPI
ivbsaxlocator_GetTypeInfo(
1564 IVBSAXLocator
*iface
,
1565 UINT iTInfo
, LCID lcid
, ITypeInfo
** ppTInfo
)
1567 saxlocator
*This
= impl_from_IVBSAXLocator( iface
);
1570 TRACE("(%p)->(%u %u %p)\n", This
, iTInfo
, lcid
, ppTInfo
);
1572 hr
= get_typeinfo(IVBSAXLocator_tid
, ppTInfo
);
1577 static HRESULT WINAPI
ivbsaxlocator_GetIDsOfNames(
1578 IVBSAXLocator
*iface
,
1580 LPOLESTR
* rgszNames
,
1585 saxlocator
*This
= impl_from_IVBSAXLocator( iface
);
1586 ITypeInfo
*typeinfo
;
1589 TRACE("(%p)->(%s %p %u %u %p)\n", This
, debugstr_guid(riid
), rgszNames
, cNames
,
1592 if(!rgszNames
|| cNames
== 0 || !rgDispId
)
1593 return E_INVALIDARG
;
1595 hr
= get_typeinfo(IVBSAXLocator_tid
, &typeinfo
);
1598 hr
= ITypeInfo_GetIDsOfNames(typeinfo
, rgszNames
, cNames
, rgDispId
);
1599 ITypeInfo_Release(typeinfo
);
1605 static HRESULT WINAPI
ivbsaxlocator_Invoke(
1606 IVBSAXLocator
*iface
,
1607 DISPID dispIdMember
,
1611 DISPPARAMS
* pDispParams
,
1612 VARIANT
* pVarResult
,
1613 EXCEPINFO
* pExcepInfo
,
1616 saxlocator
*This
= impl_from_IVBSAXLocator( iface
);
1617 ITypeInfo
*typeinfo
;
1620 TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This
, dispIdMember
, debugstr_guid(riid
),
1621 lcid
, wFlags
, pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
1623 hr
= get_typeinfo(IVBSAXLocator_tid
, &typeinfo
);
1626 hr
= ITypeInfo_Invoke(typeinfo
, &This
->IVBSAXLocator_iface
, dispIdMember
, wFlags
,
1627 pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
1628 ITypeInfo_Release(typeinfo
);
1634 /*** IVBSAXLocator methods ***/
1635 static HRESULT WINAPI
ivbsaxlocator_get_columnNumber(
1636 IVBSAXLocator
* iface
,
1639 saxlocator
*This
= impl_from_IVBSAXLocator( iface
);
1640 return ISAXLocator_getColumnNumber((ISAXLocator
*)&This
->IVBSAXLocator_iface
, pnColumn
);
1643 static HRESULT WINAPI
ivbsaxlocator_get_lineNumber(
1644 IVBSAXLocator
* iface
,
1647 saxlocator
*This
= impl_from_IVBSAXLocator( iface
);
1648 return ISAXLocator_getLineNumber((ISAXLocator
*)&This
->IVBSAXLocator_iface
, pnLine
);
1651 static HRESULT WINAPI
ivbsaxlocator_get_publicId(
1652 IVBSAXLocator
* iface
,
1655 saxlocator
*This
= impl_from_IVBSAXLocator( iface
);
1656 return ISAXLocator_getPublicId((ISAXLocator
*)&This
->IVBSAXLocator_iface
,
1657 (const WCHAR
**)publicId
);
1660 static HRESULT WINAPI
ivbsaxlocator_get_systemId(
1661 IVBSAXLocator
* iface
,
1664 saxlocator
*This
= impl_from_IVBSAXLocator( iface
);
1665 return ISAXLocator_getSystemId((ISAXLocator
*)&This
->IVBSAXLocator_iface
,
1666 (const WCHAR
**)systemId
);
1669 static const struct IVBSAXLocatorVtbl ivbsaxlocator_vtbl
=
1671 ivbsaxlocator_QueryInterface
,
1672 ivbsaxlocator_AddRef
,
1673 ivbsaxlocator_Release
,
1674 ivbsaxlocator_GetTypeInfoCount
,
1675 ivbsaxlocator_GetTypeInfo
,
1676 ivbsaxlocator_GetIDsOfNames
,
1677 ivbsaxlocator_Invoke
,
1678 ivbsaxlocator_get_columnNumber
,
1679 ivbsaxlocator_get_lineNumber
,
1680 ivbsaxlocator_get_publicId
,
1681 ivbsaxlocator_get_systemId
1684 /*** ISAXLocator interface ***/
1685 /*** IUnknown methods ***/
1686 static HRESULT WINAPI
isaxlocator_QueryInterface(ISAXLocator
* iface
, REFIID riid
, void **ppvObject
)
1688 saxlocator
*This
= impl_from_ISAXLocator( iface
);
1690 TRACE("%p %s %p\n", This
, debugstr_guid( riid
), ppvObject
);
1694 if ( IsEqualGUID( riid
, &IID_IUnknown
) ||
1695 IsEqualGUID( riid
, &IID_ISAXLocator
))
1701 FIXME("interface %s not implemented\n", debugstr_guid(riid
));
1702 return E_NOINTERFACE
;
1705 ISAXLocator_AddRef( iface
);
1710 static ULONG WINAPI
isaxlocator_AddRef(ISAXLocator
* iface
)
1712 saxlocator
*This
= impl_from_ISAXLocator( iface
);
1713 TRACE("%p\n", This
);
1714 return InterlockedIncrement( &This
->ref
);
1717 static ULONG WINAPI
isaxlocator_Release(
1720 saxlocator
*This
= impl_from_ISAXLocator( iface
);
1723 TRACE("%p\n", This
);
1725 ref
= InterlockedDecrement( &This
->ref
);
1728 SysFreeString(This
->publicId
);
1729 SysFreeString(This
->systemId
);
1730 heap_free(This
->nsStack
);
1732 ISAXXMLReader_Release(&This
->saxreader
->ISAXXMLReader_iface
);
1739 /*** ISAXLocator methods ***/
1740 static HRESULT WINAPI
isaxlocator_getColumnNumber(
1744 saxlocator
*This
= impl_from_ISAXLocator( iface
);
1746 *pnColumn
= This
->column
;
1750 static HRESULT WINAPI
isaxlocator_getLineNumber(
1754 saxlocator
*This
= impl_from_ISAXLocator( iface
);
1756 *pnLine
= This
->line
;
1760 static HRESULT WINAPI
isaxlocator_getPublicId(
1762 const WCHAR
** ppwchPublicId
)
1765 saxlocator
*This
= impl_from_ISAXLocator( iface
);
1767 SysFreeString(This
->publicId
);
1769 publicId
= bstr_from_xmlChar(xmlSAX2GetPublicId(This
->pParserCtxt
));
1770 if(SysStringLen(publicId
))
1771 This
->publicId
= (WCHAR
*)&publicId
;
1774 SysFreeString(publicId
);
1775 This
->publicId
= NULL
;
1778 *ppwchPublicId
= This
->publicId
;
1782 static HRESULT WINAPI
isaxlocator_getSystemId(
1784 const WCHAR
** ppwchSystemId
)
1787 saxlocator
*This
= impl_from_ISAXLocator( iface
);
1789 SysFreeString(This
->systemId
);
1791 systemId
= bstr_from_xmlChar(xmlSAX2GetSystemId(This
->pParserCtxt
));
1792 if(SysStringLen(systemId
))
1793 This
->systemId
= (WCHAR
*)&systemId
;
1796 SysFreeString(systemId
);
1797 This
->systemId
= NULL
;
1800 *ppwchSystemId
= This
->systemId
;
1804 static const struct ISAXLocatorVtbl isaxlocator_vtbl
=
1806 isaxlocator_QueryInterface
,
1808 isaxlocator_Release
,
1809 isaxlocator_getColumnNumber
,
1810 isaxlocator_getLineNumber
,
1811 isaxlocator_getPublicId
,
1812 isaxlocator_getSystemId
1815 static HRESULT
SAXLocator_create(saxreader
*reader
, saxlocator
**ppsaxlocator
, BOOL vbInterface
)
1817 saxlocator
*locator
;
1819 locator
= heap_alloc( sizeof (*locator
) );
1821 return E_OUTOFMEMORY
;
1823 locator
->IVBSAXLocator_iface
.lpVtbl
= &ivbsaxlocator_vtbl
;
1824 locator
->ISAXLocator_iface
.lpVtbl
= &isaxlocator_vtbl
;
1826 locator
->vbInterface
= vbInterface
;
1828 locator
->saxreader
= reader
;
1829 ISAXXMLReader_AddRef(&reader
->ISAXXMLReader_iface
);
1831 locator
->pParserCtxt
= NULL
;
1832 locator
->publicId
= NULL
;
1833 locator
->systemId
= NULL
;
1834 locator
->lastCur
= NULL
;
1836 locator
->column
= 0;
1837 locator
->ret
= S_OK
;
1838 locator
->nsStackSize
= 8;
1839 locator
->nsStackLast
= 0;
1840 locator
->nsStack
= heap_alloc(sizeof(int)*locator
->nsStackSize
);
1841 if(!locator
->nsStack
)
1843 ISAXXMLReader_Release(&reader
->ISAXXMLReader_iface
);
1845 return E_OUTOFMEMORY
;
1848 *ppsaxlocator
= locator
;
1850 TRACE("returning %p\n", *ppsaxlocator
);
1855 /*** SAXXMLReader internal functions ***/
1856 static HRESULT
internal_parseBuffer(saxreader
*This
, const char *buffer
, int size
, BOOL vbInterface
)
1858 xmlCharEncoding encoding
= XML_CHAR_ENCODING_NONE
;
1859 xmlChar
*enc_name
= NULL
;
1860 saxlocator
*locator
;
1863 hr
= SAXLocator_create(This
, &locator
, vbInterface
);
1869 const unsigned char *buff
= (unsigned char*)buffer
;
1871 encoding
= xmlDetectCharEncoding((xmlChar
*)buffer
, 4);
1872 enc_name
= (xmlChar
*)xmlGetCharEncodingName(encoding
);
1873 TRACE("detected encoding: %s\n", enc_name
);
1874 /* skip BOM, parser won't switch encodings and so won't skip it on its own */
1875 if ((encoding
== XML_CHAR_ENCODING_UTF8
) &&
1876 buff
[0] == 0xEF && buff
[1] == 0xBB && buff
[2] == 0xBF)
1883 locator
->pParserCtxt
= xmlCreateMemoryParserCtxt(buffer
, size
);
1884 if(!locator
->pParserCtxt
)
1886 ISAXLocator_Release(&locator
->ISAXLocator_iface
);
1890 if (encoding
== XML_CHAR_ENCODING_UTF8
)
1891 locator
->pParserCtxt
->encoding
= xmlStrdup(enc_name
);
1893 xmlFree(locator
->pParserCtxt
->sax
);
1894 locator
->pParserCtxt
->sax
= &locator
->saxreader
->sax
;
1895 locator
->pParserCtxt
->userData
= locator
;
1897 This
->isParsing
= TRUE
;
1898 if(xmlParseDocument(locator
->pParserCtxt
) == -1) hr
= E_FAIL
;
1899 else hr
= locator
->ret
;
1900 This
->isParsing
= FALSE
;
1902 if(locator
->pParserCtxt
)
1904 locator
->pParserCtxt
->sax
= NULL
;
1905 xmlFreeParserCtxt(locator
->pParserCtxt
);
1906 locator
->pParserCtxt
= NULL
;
1909 ISAXLocator_Release(&locator
->ISAXLocator_iface
);
1913 static HRESULT
internal_parseStream(saxreader
*This
, IStream
*stream
, BOOL vbInterface
)
1915 saxlocator
*locator
;
1922 hr
= IStream_Read(stream
, data
, sizeof(data
), &dataRead
);
1923 if(FAILED(hr
)) return hr
;
1925 hr
= SAXLocator_create(This
, &locator
, vbInterface
);
1926 if(FAILED(hr
)) return hr
;
1928 locator
->pParserCtxt
= xmlCreatePushParserCtxt(
1929 &locator
->saxreader
->sax
, locator
,
1930 data
, dataRead
, NULL
);
1931 if(!locator
->pParserCtxt
)
1933 ISAXLocator_Release(&locator
->ISAXLocator_iface
);
1937 This
->isParsing
= TRUE
;
1939 if(dataRead
!= sizeof(data
))
1941 ret
= xmlParseChunk(locator
->pParserCtxt
, data
, 0, 1);
1942 hr
= ret
!= XML_ERR_OK
? E_FAIL
: locator
->ret
;
1949 hr
= IStream_Read(stream
, data
, sizeof(data
), &dataRead
);
1950 if (FAILED(hr
)) break;
1952 ret
= xmlParseChunk(locator
->pParserCtxt
, data
, dataRead
, 0);
1953 hr
= ret
!= XML_ERR_OK
? E_FAIL
: locator
->ret
;
1955 if (hr
!= S_OK
) break;
1957 if (dataRead
!= sizeof(data
))
1959 ret
= xmlParseChunk(locator
->pParserCtxt
, data
, 0, 1);
1960 hr
= ret
!= XML_ERR_OK
? E_FAIL
: locator
->ret
;
1966 This
->isParsing
= FALSE
;
1968 xmlFreeParserCtxt(locator
->pParserCtxt
);
1969 locator
->pParserCtxt
= NULL
;
1970 ISAXLocator_Release(&locator
->ISAXLocator_iface
);
1974 static HRESULT
internal_getEntityResolver(
1976 void *pEntityResolver
,
1979 FIXME("(%p)->(%p) stub\n", This
, pEntityResolver
);
1983 static HRESULT
internal_putEntityResolver(
1985 void *pEntityResolver
,
1988 FIXME("(%p)->(%p) stub\n", This
, pEntityResolver
);
1992 static HRESULT
internal_getContentHandler(
1994 void *pContentHandler
,
1997 TRACE("(%p)->(%p)\n", This
, pContentHandler
);
1998 if(pContentHandler
== NULL
)
2000 if((vbInterface
&& This
->vbcontentHandler
)
2001 || (!vbInterface
&& This
->contentHandler
))
2004 IVBSAXContentHandler_AddRef(This
->vbcontentHandler
);
2006 ISAXContentHandler_AddRef(This
->contentHandler
);
2008 if(vbInterface
) *(IVBSAXContentHandler
**)pContentHandler
=
2009 This
->vbcontentHandler
;
2010 else *(ISAXContentHandler
**)pContentHandler
= This
->contentHandler
;
2015 static HRESULT
internal_putContentHandler(
2017 void *contentHandler
,
2020 TRACE("(%p)->(%p)\n", This
, contentHandler
);
2024 IVBSAXContentHandler_AddRef((IVBSAXContentHandler
*)contentHandler
);
2026 ISAXContentHandler_AddRef((ISAXContentHandler
*)contentHandler
);
2028 if((vbInterface
&& This
->vbcontentHandler
)
2029 || (!vbInterface
&& This
->contentHandler
))
2032 IVBSAXContentHandler_Release(This
->vbcontentHandler
);
2034 ISAXContentHandler_Release(This
->contentHandler
);
2037 This
->vbcontentHandler
= contentHandler
;
2039 This
->contentHandler
= contentHandler
;
2044 static HRESULT
internal_getDTDHandler(
2049 FIXME("(%p)->(%p) stub\n", This
, pDTDHandler
);
2053 static HRESULT
internal_putDTDHandler(
2058 FIXME("(%p)->(%p) stub\n", This
, pDTDHandler
);
2062 static HRESULT
internal_getErrorHandler(
2064 void *pErrorHandler
,
2067 TRACE("(%p)->(%p)\n", This
, pErrorHandler
);
2068 if(pErrorHandler
== NULL
)
2071 if(vbInterface
&& This
->vberrorHandler
)
2072 IVBSAXErrorHandler_AddRef(This
->vberrorHandler
);
2073 else if(!vbInterface
&& This
->errorHandler
)
2074 ISAXErrorHandler_AddRef(This
->errorHandler
);
2077 *(IVBSAXErrorHandler
**)pErrorHandler
= This
->vberrorHandler
;
2079 *(ISAXErrorHandler
**)pErrorHandler
= This
->errorHandler
;
2085 static HRESULT
internal_putErrorHandler(
2090 TRACE("(%p)->(%p)\n", This
, errorHandler
);
2094 IVBSAXErrorHandler_AddRef((IVBSAXErrorHandler
*)errorHandler
);
2096 ISAXErrorHandler_AddRef((ISAXErrorHandler
*)errorHandler
);
2099 if(vbInterface
&& This
->vberrorHandler
)
2100 IVBSAXErrorHandler_Release(This
->vberrorHandler
);
2101 else if(!vbInterface
&& This
->errorHandler
)
2102 ISAXErrorHandler_Release(This
->errorHandler
);
2105 This
->vberrorHandler
= errorHandler
;
2107 This
->errorHandler
= errorHandler
;
2113 static HRESULT
internal_parse(
2120 TRACE("(%p)->(%s)\n", This
, debugstr_variant(&varInput
));
2122 /* Dispose of the BSTRs in the pool from a prior run, if any. */
2123 free_bstr_pool(&This
->pool
);
2125 switch(V_VT(&varInput
))
2128 hr
= internal_parseBuffer(This
, (const char*)V_BSTR(&varInput
),
2129 SysStringByteLen(V_BSTR(&varInput
)), vbInterface
);
2131 case VT_ARRAY
|VT_UI1
: {
2133 LONG lBound
, uBound
;
2136 hr
= SafeArrayGetLBound(V_ARRAY(&varInput
), 1, &lBound
);
2137 if(hr
!= S_OK
) break;
2138 hr
= SafeArrayGetUBound(V_ARRAY(&varInput
), 1, &uBound
);
2139 if(hr
!= S_OK
) break;
2140 dataRead
= (uBound
-lBound
)*SafeArrayGetElemsize(V_ARRAY(&varInput
));
2141 hr
= SafeArrayAccessData(V_ARRAY(&varInput
), &pSAData
);
2142 if(hr
!= S_OK
) break;
2143 hr
= internal_parseBuffer(This
, pSAData
, dataRead
, vbInterface
);
2144 SafeArrayUnaccessData(V_ARRAY(&varInput
));
2149 IPersistStream
*persistStream
;
2150 IStream
*stream
= NULL
;
2151 IXMLDOMDocument
*xmlDoc
;
2153 if(IUnknown_QueryInterface(V_UNKNOWN(&varInput
),
2154 &IID_IXMLDOMDocument
, (void**)&xmlDoc
) == S_OK
)
2158 IXMLDOMDocument_get_xml(xmlDoc
, &bstrData
);
2159 hr
= internal_parseBuffer(This
, (const char*)bstrData
,
2160 SysStringByteLen(bstrData
), vbInterface
);
2161 IXMLDOMDocument_Release(xmlDoc
);
2162 SysFreeString(bstrData
);
2166 if(IUnknown_QueryInterface(V_UNKNOWN(&varInput
),
2167 &IID_IPersistStream
, (void**)&persistStream
) == S_OK
)
2169 hr
= CreateStreamOnHGlobal(NULL
, TRUE
, &stream
);
2172 IPersistStream_Release(persistStream
);
2176 hr
= IPersistStream_Save(persistStream
, stream
, TRUE
);
2177 IPersistStream_Release(persistStream
);
2180 IStream_Release(stream
);
2184 if(stream
|| IUnknown_QueryInterface(V_UNKNOWN(&varInput
),
2185 &IID_IStream
, (void**)&stream
) == S_OK
)
2187 hr
= internal_parseStream(This
, stream
, vbInterface
);
2188 IStream_Release(stream
);
2193 WARN("vt %d not implemented\n", V_VT(&varInput
));
2200 static HRESULT
internal_vbonDataAvailable(void *obj
, char *ptr
, DWORD len
)
2202 saxreader
*This
= obj
;
2204 return internal_parseBuffer(This
, ptr
, len
, TRUE
);
2207 static HRESULT
internal_onDataAvailable(void *obj
, char *ptr
, DWORD len
)
2209 saxreader
*This
= obj
;
2211 return internal_parseBuffer(This
, ptr
, len
, FALSE
);
2214 static HRESULT
internal_parseURL(
2222 TRACE("(%p)->(%s)\n", This
, debugstr_w(url
));
2224 if(vbInterface
) hr
= bind_url(url
, internal_vbonDataAvailable
, This
, &bsc
);
2225 else hr
= bind_url(url
, internal_onDataAvailable
, This
, &bsc
);
2235 static HRESULT
internal_putProperty(
2241 TRACE("(%p)->(%s %s)\n", This
, debugstr_w(prop
), debugstr_variant(&value
));
2243 if(!memcmp(prop
, PropertyDeclHandlerW
, sizeof(PropertyDeclHandlerW
)))
2245 if(This
->isParsing
) return E_FAIL
;
2247 switch (V_VT(&value
))
2252 if (This
->vbdeclHandler
)
2254 IVBSAXDeclHandler_Release(This
->vbdeclHandler
);
2255 This
->vbdeclHandler
= NULL
;
2259 if (This
->declHandler
)
2261 ISAXDeclHandler_Release(This
->declHandler
);
2262 This
->declHandler
= NULL
;
2266 if (V_UNKNOWN(&value
)) IUnknown_AddRef(V_UNKNOWN(&value
));
2268 if ((vbInterface
&& This
->vbdeclHandler
) ||
2269 (!vbInterface
&& This
->declHandler
))
2272 IVBSAXDeclHandler_Release(This
->vbdeclHandler
);
2274 ISAXDeclHandler_Release(This
->declHandler
);
2278 This
->vbdeclHandler
= (IVBSAXDeclHandler
*)V_UNKNOWN(&value
);
2280 This
->declHandler
= (ISAXDeclHandler
*)V_UNKNOWN(&value
);
2283 return E_INVALIDARG
;
2289 if(!memcmp(prop
, PropertyLexicalHandlerW
, sizeof(PropertyLexicalHandlerW
)))
2291 if(This
->isParsing
) return E_FAIL
;
2293 switch (V_VT(&value
))
2298 if (This
->vblexicalHandler
)
2300 IVBSAXLexicalHandler_Release(This
->vblexicalHandler
);
2301 This
->vblexicalHandler
= NULL
;
2305 if (This
->lexicalHandler
)
2307 ISAXLexicalHandler_Release(This
->lexicalHandler
);
2308 This
->lexicalHandler
= NULL
;
2312 if (V_UNKNOWN(&value
)) IUnknown_AddRef(V_UNKNOWN(&value
));
2314 if ((vbInterface
&& This
->vblexicalHandler
) ||
2315 (!vbInterface
&& This
->lexicalHandler
))
2318 IVBSAXLexicalHandler_Release(This
->vblexicalHandler
);
2320 ISAXLexicalHandler_Release(This
->lexicalHandler
);
2324 This
->vblexicalHandler
= (IVBSAXLexicalHandler
*)V_UNKNOWN(&value
);
2326 This
->lexicalHandler
= (ISAXLexicalHandler
*)V_UNKNOWN(&value
);
2329 return E_INVALIDARG
;
2335 FIXME("(%p)->(%s): unsupported property\n", This
, debugstr_w(prop
));
2337 if(!memcmp(prop
, PropertyCharsetW
, sizeof(PropertyCharsetW
)))
2340 if(!memcmp(prop
, PropertyDomNodeW
, sizeof(PropertyDomNodeW
)))
2343 if(!memcmp(prop
, PropertyInputSourceW
, sizeof(PropertyInputSourceW
)))
2346 if(!memcmp(prop
, PropertyMaxElementDepthW
, sizeof(PropertyMaxElementDepthW
)))
2349 if(!memcmp(prop
, PropertyMaxXMLSizeW
, sizeof(PropertyMaxXMLSizeW
)))
2352 if(!memcmp(prop
, PropertySchemaDeclHandlerW
, sizeof(PropertySchemaDeclHandlerW
)))
2355 if(!memcmp(prop
, PropertyXMLDeclEncodingW
, sizeof(PropertyXMLDeclEncodingW
)))
2358 if(!memcmp(prop
, PropertyXMLDeclStandaloneW
, sizeof(PropertyXMLDeclStandaloneW
)))
2361 if(!memcmp(prop
, PropertyXMLDeclVersionW
, sizeof(PropertyXMLDeclVersionW
)))
2364 return E_INVALIDARG
;
2367 static HRESULT
internal_getProperty(const saxreader
* This
, const WCHAR
*prop
, VARIANT
*value
, BOOL vb
)
2369 TRACE("(%p)->(%s)\n", This
, debugstr_w(prop
));
2371 if (!value
) return E_POINTER
;
2373 if (!memcmp(PropertyLexicalHandlerW
, prop
, sizeof(PropertyLexicalHandlerW
)))
2375 V_VT(value
) = VT_UNKNOWN
;
2376 V_UNKNOWN(value
) = vb
? (IUnknown
*)This
->vblexicalHandler
: (IUnknown
*)This
->lexicalHandler
;
2377 if (V_UNKNOWN(value
)) IUnknown_AddRef(V_UNKNOWN(value
));
2381 if (!memcmp(PropertyDeclHandlerW
, prop
, sizeof(PropertyDeclHandlerW
)))
2383 V_VT(value
) = VT_UNKNOWN
;
2384 V_UNKNOWN(value
) = vb
? (IUnknown
*)This
->vbdeclHandler
: (IUnknown
*)This
->declHandler
;
2385 if (V_UNKNOWN(value
)) IUnknown_AddRef(V_UNKNOWN(value
));
2389 FIXME("(%p)->(%s) unsupported property\n", This
, debugstr_w(prop
));
2394 /*** IVBSAXXMLReader interface ***/
2395 /*** IUnknown methods ***/
2396 static HRESULT WINAPI
saxxmlreader_QueryInterface(IVBSAXXMLReader
* iface
, REFIID riid
, void **ppvObject
)
2398 saxreader
*This
= impl_from_IVBSAXXMLReader( iface
);
2400 TRACE("%p %s %p\n", This
, debugstr_guid( riid
), ppvObject
);
2404 if ( IsEqualGUID( riid
, &IID_IUnknown
) ||
2405 IsEqualGUID( riid
, &IID_IDispatch
) ||
2406 IsEqualGUID( riid
, &IID_IVBSAXXMLReader
))
2410 else if( IsEqualGUID( riid
, &IID_ISAXXMLReader
))
2412 *ppvObject
= &This
->ISAXXMLReader_iface
;
2416 FIXME("interface %s not implemented\n", debugstr_guid(riid
));
2417 return E_NOINTERFACE
;
2420 IVBSAXXMLReader_AddRef( iface
);
2425 static ULONG WINAPI
saxxmlreader_AddRef(IVBSAXXMLReader
* iface
)
2427 saxreader
*This
= impl_from_IVBSAXXMLReader( iface
);
2428 TRACE("%p\n", This
);
2429 return InterlockedIncrement( &This
->ref
);
2432 static ULONG WINAPI
saxxmlreader_Release(
2433 IVBSAXXMLReader
* iface
)
2435 saxreader
*This
= impl_from_IVBSAXXMLReader( iface
);
2438 TRACE("%p\n", This
);
2440 ref
= InterlockedDecrement( &This
->ref
);
2443 if(This
->contentHandler
)
2444 ISAXContentHandler_Release(This
->contentHandler
);
2446 if(This
->vbcontentHandler
)
2447 IVBSAXContentHandler_Release(This
->vbcontentHandler
);
2449 if(This
->errorHandler
)
2450 ISAXErrorHandler_Release(This
->errorHandler
);
2452 if(This
->vberrorHandler
)
2453 IVBSAXErrorHandler_Release(This
->vberrorHandler
);
2455 if(This
->lexicalHandler
)
2456 ISAXLexicalHandler_Release(This
->lexicalHandler
);
2458 if(This
->vblexicalHandler
)
2459 IVBSAXLexicalHandler_Release(This
->vblexicalHandler
);
2461 if(This
->declHandler
)
2462 ISAXDeclHandler_Release(This
->declHandler
);
2464 if(This
->vbdeclHandler
)
2465 IVBSAXDeclHandler_Release(This
->vbdeclHandler
);
2467 free_bstr_pool(&This
->pool
);
2475 static HRESULT WINAPI
saxxmlreader_GetTypeInfoCount( IVBSAXXMLReader
*iface
, UINT
* pctinfo
)
2477 saxreader
*This
= impl_from_IVBSAXXMLReader( iface
);
2479 TRACE("(%p)->(%p)\n", This
, pctinfo
);
2486 static HRESULT WINAPI
saxxmlreader_GetTypeInfo(
2487 IVBSAXXMLReader
*iface
,
2488 UINT iTInfo
, LCID lcid
, ITypeInfo
** ppTInfo
)
2490 saxreader
*This
= impl_from_IVBSAXXMLReader( iface
);
2493 TRACE("(%p)->(%u %u %p)\n", This
, iTInfo
, lcid
, ppTInfo
);
2495 hr
= get_typeinfo(IVBSAXXMLReader_tid
, ppTInfo
);
2500 static HRESULT WINAPI
saxxmlreader_GetIDsOfNames(
2501 IVBSAXXMLReader
*iface
,
2503 LPOLESTR
* rgszNames
,
2508 saxreader
*This
= impl_from_IVBSAXXMLReader( iface
);
2509 ITypeInfo
*typeinfo
;
2512 TRACE("(%p)->(%s %p %u %u %p)\n", This
, debugstr_guid(riid
), rgszNames
, cNames
,
2515 if(!rgszNames
|| cNames
== 0 || !rgDispId
)
2516 return E_INVALIDARG
;
2518 hr
= get_typeinfo(IVBSAXXMLReader_tid
, &typeinfo
);
2521 hr
= ITypeInfo_GetIDsOfNames(typeinfo
, rgszNames
, cNames
, rgDispId
);
2522 ITypeInfo_Release(typeinfo
);
2528 static HRESULT WINAPI
saxxmlreader_Invoke(
2529 IVBSAXXMLReader
*iface
,
2530 DISPID dispIdMember
,
2534 DISPPARAMS
* pDispParams
,
2535 VARIANT
* pVarResult
,
2536 EXCEPINFO
* pExcepInfo
,
2539 saxreader
*This
= impl_from_IVBSAXXMLReader( iface
);
2540 ITypeInfo
*typeinfo
;
2543 TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This
, dispIdMember
, debugstr_guid(riid
),
2544 lcid
, wFlags
, pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
2546 hr
= get_typeinfo(IVBSAXXMLReader_tid
, &typeinfo
);
2549 hr
= ITypeInfo_Invoke(typeinfo
, &This
->IVBSAXXMLReader_iface
, dispIdMember
, wFlags
,
2550 pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
2551 ITypeInfo_Release(typeinfo
);
2557 /*** IVBSAXXMLReader methods ***/
2558 static HRESULT WINAPI
saxxmlreader_getFeature(
2559 IVBSAXXMLReader
* iface
,
2560 const WCHAR
*pFeature
,
2561 VARIANT_BOOL
*pValue
)
2563 saxreader
*This
= impl_from_IVBSAXXMLReader( iface
);
2565 FIXME("(%p)->(%s %p) stub\n", This
, debugstr_w(pFeature
), pValue
);
2569 static HRESULT WINAPI
saxxmlreader_putFeature(
2570 IVBSAXXMLReader
* iface
,
2571 const WCHAR
*pFeature
,
2572 VARIANT_BOOL vfValue
)
2574 saxreader
*This
= impl_from_IVBSAXXMLReader( iface
);
2576 FIXME("(%p)->(%s %x) stub\n", This
, debugstr_w(pFeature
), vfValue
);
2580 static HRESULT WINAPI
saxxmlreader_getProperty(
2581 IVBSAXXMLReader
* iface
,
2585 saxreader
*This
= impl_from_IVBSAXXMLReader( iface
);
2586 return internal_getProperty(This
, prop
, value
, TRUE
);
2589 static HRESULT WINAPI
saxxmlreader_putProperty(
2590 IVBSAXXMLReader
* iface
,
2594 saxreader
*This
= impl_from_IVBSAXXMLReader( iface
);
2595 return internal_putProperty(This
, pProp
, value
, TRUE
);
2598 static HRESULT WINAPI
saxxmlreader_get_entityResolver(
2599 IVBSAXXMLReader
* iface
,
2600 IVBSAXEntityResolver
**pEntityResolver
)
2602 saxreader
*This
= impl_from_IVBSAXXMLReader( iface
);
2603 return internal_getEntityResolver(This
, pEntityResolver
, TRUE
);
2606 static HRESULT WINAPI
saxxmlreader_put_entityResolver(
2607 IVBSAXXMLReader
* iface
,
2608 IVBSAXEntityResolver
*pEntityResolver
)
2610 saxreader
*This
= impl_from_IVBSAXXMLReader( iface
);
2611 return internal_putEntityResolver(This
, pEntityResolver
, TRUE
);
2614 static HRESULT WINAPI
saxxmlreader_get_contentHandler(
2615 IVBSAXXMLReader
* iface
,
2616 IVBSAXContentHandler
**ppContentHandler
)
2618 saxreader
*This
= impl_from_IVBSAXXMLReader( iface
);
2619 return internal_getContentHandler(This
, ppContentHandler
, TRUE
);
2622 static HRESULT WINAPI
saxxmlreader_put_contentHandler(
2623 IVBSAXXMLReader
* iface
,
2624 IVBSAXContentHandler
*contentHandler
)
2626 saxreader
*This
= impl_from_IVBSAXXMLReader( iface
);
2627 return internal_putContentHandler(This
, contentHandler
, TRUE
);
2630 static HRESULT WINAPI
saxxmlreader_get_dtdHandler(
2631 IVBSAXXMLReader
* iface
,
2632 IVBSAXDTDHandler
**pDTDHandler
)
2634 saxreader
*This
= impl_from_IVBSAXXMLReader( iface
);
2635 return internal_getDTDHandler(This
, pDTDHandler
, TRUE
);
2638 static HRESULT WINAPI
saxxmlreader_put_dtdHandler(
2639 IVBSAXXMLReader
* iface
,
2640 IVBSAXDTDHandler
*pDTDHandler
)
2642 saxreader
*This
= impl_from_IVBSAXXMLReader( iface
);
2643 return internal_putDTDHandler(This
, pDTDHandler
, TRUE
);
2646 static HRESULT WINAPI
saxxmlreader_get_errorHandler(
2647 IVBSAXXMLReader
* iface
,
2648 IVBSAXErrorHandler
**pErrorHandler
)
2650 saxreader
*This
= impl_from_IVBSAXXMLReader( iface
);
2651 return internal_getErrorHandler(This
, pErrorHandler
, TRUE
);
2654 static HRESULT WINAPI
saxxmlreader_put_errorHandler(
2655 IVBSAXXMLReader
* iface
,
2656 IVBSAXErrorHandler
*errorHandler
)
2658 saxreader
*This
= impl_from_IVBSAXXMLReader( iface
);
2659 return internal_putErrorHandler(This
, errorHandler
, TRUE
);
2662 static HRESULT WINAPI
saxxmlreader_get_baseURL(
2663 IVBSAXXMLReader
* iface
,
2664 const WCHAR
**pBaseUrl
)
2666 saxreader
*This
= impl_from_IVBSAXXMLReader( iface
);
2668 FIXME("(%p)->(%p) stub\n", This
, pBaseUrl
);
2672 static HRESULT WINAPI
saxxmlreader_put_baseURL(
2673 IVBSAXXMLReader
* iface
,
2674 const WCHAR
*pBaseUrl
)
2676 saxreader
*This
= impl_from_IVBSAXXMLReader( iface
);
2678 FIXME("(%p)->(%s) stub\n", This
, debugstr_w(pBaseUrl
));
2682 static HRESULT WINAPI
saxxmlreader_get_secureBaseURL(
2683 IVBSAXXMLReader
* iface
,
2684 const WCHAR
**pSecureBaseUrl
)
2686 saxreader
*This
= impl_from_IVBSAXXMLReader( iface
);
2688 FIXME("(%p)->(%p) stub\n", This
, pSecureBaseUrl
);
2693 static HRESULT WINAPI
saxxmlreader_put_secureBaseURL(
2694 IVBSAXXMLReader
* iface
,
2695 const WCHAR
*secureBaseUrl
)
2697 saxreader
*This
= impl_from_IVBSAXXMLReader( iface
);
2699 FIXME("(%p)->(%s) stub\n", This
, debugstr_w(secureBaseUrl
));
2703 static HRESULT WINAPI
saxxmlreader_parse(
2704 IVBSAXXMLReader
* iface
,
2707 saxreader
*This
= impl_from_IVBSAXXMLReader( iface
);
2708 return internal_parse(This
, varInput
, TRUE
);
2711 static HRESULT WINAPI
saxxmlreader_parseURL(
2712 IVBSAXXMLReader
* iface
,
2715 saxreader
*This
= impl_from_IVBSAXXMLReader( iface
);
2716 return internal_parseURL(This
, url
, TRUE
);
2719 static const struct IVBSAXXMLReaderVtbl saxreader_vtbl
=
2721 saxxmlreader_QueryInterface
,
2722 saxxmlreader_AddRef
,
2723 saxxmlreader_Release
,
2724 saxxmlreader_GetTypeInfoCount
,
2725 saxxmlreader_GetTypeInfo
,
2726 saxxmlreader_GetIDsOfNames
,
2727 saxxmlreader_Invoke
,
2728 saxxmlreader_getFeature
,
2729 saxxmlreader_putFeature
,
2730 saxxmlreader_getProperty
,
2731 saxxmlreader_putProperty
,
2732 saxxmlreader_get_entityResolver
,
2733 saxxmlreader_put_entityResolver
,
2734 saxxmlreader_get_contentHandler
,
2735 saxxmlreader_put_contentHandler
,
2736 saxxmlreader_get_dtdHandler
,
2737 saxxmlreader_put_dtdHandler
,
2738 saxxmlreader_get_errorHandler
,
2739 saxxmlreader_put_errorHandler
,
2740 saxxmlreader_get_baseURL
,
2741 saxxmlreader_put_baseURL
,
2742 saxxmlreader_get_secureBaseURL
,
2743 saxxmlreader_put_secureBaseURL
,
2745 saxxmlreader_parseURL
2748 /*** ISAXXMLReader interface ***/
2749 /*** IUnknown methods ***/
2750 static HRESULT WINAPI
isaxxmlreader_QueryInterface(ISAXXMLReader
* iface
, REFIID riid
, void **ppvObject
)
2752 saxreader
*This
= impl_from_ISAXXMLReader( iface
);
2753 return saxxmlreader_QueryInterface(&This
->IVBSAXXMLReader_iface
, riid
, ppvObject
);
2756 static ULONG WINAPI
isaxxmlreader_AddRef(ISAXXMLReader
* iface
)
2758 saxreader
*This
= impl_from_ISAXXMLReader( iface
);
2759 return saxxmlreader_AddRef(&This
->IVBSAXXMLReader_iface
);
2762 static ULONG WINAPI
isaxxmlreader_Release(ISAXXMLReader
* iface
)
2764 saxreader
*This
= impl_from_ISAXXMLReader( iface
);
2765 return saxxmlreader_Release(&This
->IVBSAXXMLReader_iface
);
2768 /*** ISAXXMLReader methods ***/
2769 static HRESULT WINAPI
isaxxmlreader_getFeature(
2770 ISAXXMLReader
* iface
,
2771 const WCHAR
*pFeature
,
2772 VARIANT_BOOL
*pValue
)
2774 saxreader
*This
= impl_from_ISAXXMLReader( iface
);
2775 return IVBSAXXMLReader_getFeature(&This
->IVBSAXXMLReader_iface
, pFeature
, pValue
);
2778 static HRESULT WINAPI
isaxxmlreader_putFeature(
2779 ISAXXMLReader
* iface
,
2780 const WCHAR
*pFeature
,
2781 VARIANT_BOOL vfValue
)
2783 saxreader
*This
= impl_from_ISAXXMLReader( iface
);
2784 return IVBSAXXMLReader_putFeature(&This
->IVBSAXXMLReader_iface
, pFeature
, vfValue
);
2787 static HRESULT WINAPI
isaxxmlreader_getProperty(
2788 ISAXXMLReader
* iface
,
2792 saxreader
*This
= impl_from_ISAXXMLReader( iface
);
2793 return internal_getProperty(This
, prop
, value
, FALSE
);
2796 static HRESULT WINAPI
isaxxmlreader_putProperty(
2797 ISAXXMLReader
* iface
,
2801 saxreader
*This
= impl_from_ISAXXMLReader( iface
);
2802 return internal_putProperty(This
, pProp
, value
, FALSE
);
2805 static HRESULT WINAPI
isaxxmlreader_getEntityResolver(
2806 ISAXXMLReader
* iface
,
2807 ISAXEntityResolver
**ppEntityResolver
)
2809 saxreader
*This
= impl_from_ISAXXMLReader( iface
);
2810 return internal_getEntityResolver(This
, ppEntityResolver
, FALSE
);
2813 static HRESULT WINAPI
isaxxmlreader_putEntityResolver(
2814 ISAXXMLReader
* iface
,
2815 ISAXEntityResolver
*pEntityResolver
)
2817 saxreader
*This
= impl_from_ISAXXMLReader( iface
);
2818 return internal_putEntityResolver(This
, pEntityResolver
, FALSE
);
2821 static HRESULT WINAPI
isaxxmlreader_getContentHandler(
2822 ISAXXMLReader
* iface
,
2823 ISAXContentHandler
**pContentHandler
)
2825 saxreader
*This
= impl_from_ISAXXMLReader( iface
);
2826 return internal_getContentHandler(This
, pContentHandler
, FALSE
);
2829 static HRESULT WINAPI
isaxxmlreader_putContentHandler(
2830 ISAXXMLReader
* iface
,
2831 ISAXContentHandler
*contentHandler
)
2833 saxreader
*This
= impl_from_ISAXXMLReader( iface
);
2834 return internal_putContentHandler(This
, contentHandler
, FALSE
);
2837 static HRESULT WINAPI
isaxxmlreader_getDTDHandler(
2838 ISAXXMLReader
* iface
,
2839 ISAXDTDHandler
**pDTDHandler
)
2841 saxreader
*This
= impl_from_ISAXXMLReader( iface
);
2842 return internal_getDTDHandler(This
, pDTDHandler
, FALSE
);
2845 static HRESULT WINAPI
isaxxmlreader_putDTDHandler(
2846 ISAXXMLReader
* iface
,
2847 ISAXDTDHandler
*pDTDHandler
)
2849 saxreader
*This
= impl_from_ISAXXMLReader( iface
);
2850 return internal_putDTDHandler(This
, pDTDHandler
, FALSE
);
2853 static HRESULT WINAPI
isaxxmlreader_getErrorHandler(
2854 ISAXXMLReader
* iface
,
2855 ISAXErrorHandler
**pErrorHandler
)
2857 saxreader
*This
= impl_from_ISAXXMLReader( iface
);
2858 return internal_getErrorHandler(This
, pErrorHandler
, FALSE
);
2861 static HRESULT WINAPI
isaxxmlreader_putErrorHandler(
2862 ISAXXMLReader
* iface
,
2863 ISAXErrorHandler
*errorHandler
)
2865 saxreader
*This
= impl_from_ISAXXMLReader( iface
);
2866 return internal_putErrorHandler(This
, errorHandler
, FALSE
);
2869 static HRESULT WINAPI
isaxxmlreader_getBaseURL(
2870 ISAXXMLReader
* iface
,
2871 const WCHAR
**pBaseUrl
)
2873 saxreader
*This
= impl_from_ISAXXMLReader( iface
);
2874 return IVBSAXXMLReader_get_baseURL(&This
->IVBSAXXMLReader_iface
, pBaseUrl
);
2877 static HRESULT WINAPI
isaxxmlreader_putBaseURL(
2878 ISAXXMLReader
* iface
,
2879 const WCHAR
*pBaseUrl
)
2881 saxreader
*This
= impl_from_ISAXXMLReader( iface
);
2882 return IVBSAXXMLReader_put_baseURL(&This
->IVBSAXXMLReader_iface
, pBaseUrl
);
2885 static HRESULT WINAPI
isaxxmlreader_getSecureBaseURL(
2886 ISAXXMLReader
* iface
,
2887 const WCHAR
**pSecureBaseUrl
)
2889 saxreader
*This
= impl_from_ISAXXMLReader( iface
);
2890 return IVBSAXXMLReader_get_secureBaseURL(&This
->IVBSAXXMLReader_iface
, pSecureBaseUrl
);
2893 static HRESULT WINAPI
isaxxmlreader_putSecureBaseURL(
2894 ISAXXMLReader
* iface
,
2895 const WCHAR
*secureBaseUrl
)
2897 saxreader
*This
= impl_from_ISAXXMLReader( iface
);
2898 return IVBSAXXMLReader_put_secureBaseURL(&This
->IVBSAXXMLReader_iface
, secureBaseUrl
);
2901 static HRESULT WINAPI
isaxxmlreader_parse(
2902 ISAXXMLReader
* iface
,
2905 saxreader
*This
= impl_from_ISAXXMLReader( iface
);
2906 return internal_parse(This
, varInput
, FALSE
);
2909 static HRESULT WINAPI
isaxxmlreader_parseURL(
2910 ISAXXMLReader
* iface
,
2913 saxreader
*This
= impl_from_ISAXXMLReader( iface
);
2914 return internal_parseURL(This
, url
, FALSE
);
2917 static const struct ISAXXMLReaderVtbl isaxreader_vtbl
=
2919 isaxxmlreader_QueryInterface
,
2920 isaxxmlreader_AddRef
,
2921 isaxxmlreader_Release
,
2922 isaxxmlreader_getFeature
,
2923 isaxxmlreader_putFeature
,
2924 isaxxmlreader_getProperty
,
2925 isaxxmlreader_putProperty
,
2926 isaxxmlreader_getEntityResolver
,
2927 isaxxmlreader_putEntityResolver
,
2928 isaxxmlreader_getContentHandler
,
2929 isaxxmlreader_putContentHandler
,
2930 isaxxmlreader_getDTDHandler
,
2931 isaxxmlreader_putDTDHandler
,
2932 isaxxmlreader_getErrorHandler
,
2933 isaxxmlreader_putErrorHandler
,
2934 isaxxmlreader_getBaseURL
,
2935 isaxxmlreader_putBaseURL
,
2936 isaxxmlreader_getSecureBaseURL
,
2937 isaxxmlreader_putSecureBaseURL
,
2938 isaxxmlreader_parse
,
2939 isaxxmlreader_parseURL
2942 HRESULT
SAXXMLReader_create(IUnknown
*pUnkOuter
, LPVOID
*ppObj
)
2946 TRACE("(%p,%p)\n", pUnkOuter
, ppObj
);
2948 reader
= heap_alloc( sizeof (*reader
) );
2950 return E_OUTOFMEMORY
;
2952 reader
->IVBSAXXMLReader_iface
.lpVtbl
= &saxreader_vtbl
;
2953 reader
->ISAXXMLReader_iface
.lpVtbl
= &isaxreader_vtbl
;
2955 reader
->contentHandler
= NULL
;
2956 reader
->vbcontentHandler
= NULL
;
2957 reader
->errorHandler
= NULL
;
2958 reader
->vberrorHandler
= NULL
;
2959 reader
->lexicalHandler
= NULL
;
2960 reader
->vblexicalHandler
= NULL
;
2961 reader
->declHandler
= NULL
;
2962 reader
->vbdeclHandler
= NULL
;
2963 reader
->isParsing
= FALSE
;
2964 reader
->pool
.pool
= NULL
;
2965 reader
->pool
.index
= 0;
2966 reader
->pool
.len
= 0;
2968 memset(&reader
->sax
, 0, sizeof(xmlSAXHandler
));
2969 reader
->sax
.initialized
= XML_SAX2_MAGIC
;
2970 reader
->sax
.startDocument
= libxmlStartDocument
;
2971 reader
->sax
.endDocument
= libxmlEndDocument
;
2972 reader
->sax
.startElementNs
= libxmlStartElementNS
;
2973 reader
->sax
.endElementNs
= libxmlEndElementNS
;
2974 reader
->sax
.characters
= libxmlCharacters
;
2975 reader
->sax
.setDocumentLocator
= libxmlSetDocumentLocator
;
2976 reader
->sax
.comment
= libxmlComment
;
2977 reader
->sax
.error
= libxmlFatalError
;
2978 reader
->sax
.fatalError
= libxmlFatalError
;
2979 reader
->sax
.cdataBlock
= libxmlCDataBlock
;
2981 *ppObj
= &reader
->IVBSAXXMLReader_iface
;
2983 TRACE("returning iface %p\n", *ppObj
);
2990 HRESULT
SAXXMLReader_create(IUnknown
*pUnkOuter
, LPVOID
*ppObj
)
2992 MESSAGE("This program tried to use a SAX XML Reader object, but\n"
2993 "libxml2 support was not present at compile time.\n");