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
);
52 typedef struct _saxreader
54 IVBSAXXMLReader IVBSAXXMLReader_iface
;
55 ISAXXMLReader ISAXXMLReader_iface
;
57 struct ISAXContentHandler
*contentHandler
;
58 struct IVBSAXContentHandler
*vbcontentHandler
;
59 struct ISAXErrorHandler
*errorHandler
;
60 struct IVBSAXErrorHandler
*vberrorHandler
;
61 struct ISAXLexicalHandler
*lexicalHandler
;
62 struct IVBSAXLexicalHandler
*vblexicalHandler
;
63 struct ISAXDeclHandler
*declHandler
;
64 struct IVBSAXDeclHandler
*vbdeclHandler
;
69 typedef struct _saxlocator
71 IVBSAXLocator IVBSAXLocator_iface
;
72 ISAXLocator ISAXLocator_iface
;
76 xmlParserCtxtPtr pParserCtxt
;
90 typedef struct _saxattributes
92 IVBSAXAttributes IVBSAXAttributes_iface
;
93 ISAXAttributes ISAXAttributes_iface
;
102 static inline saxreader
*impl_from_IVBSAXXMLReader( IVBSAXXMLReader
*iface
)
104 return CONTAINING_RECORD(iface
, saxreader
, IVBSAXXMLReader_iface
);
107 static inline saxreader
*impl_from_ISAXXMLReader( ISAXXMLReader
*iface
)
109 return CONTAINING_RECORD(iface
, saxreader
, ISAXXMLReader_iface
);
112 static inline saxlocator
*impl_from_IVBSAXLocator( IVBSAXLocator
*iface
)
114 return CONTAINING_RECORD(iface
, saxlocator
, IVBSAXLocator_iface
);
117 static inline saxlocator
*impl_from_ISAXLocator( ISAXLocator
*iface
)
119 return CONTAINING_RECORD(iface
, saxlocator
, ISAXLocator_iface
);
122 static inline saxattributes
*impl_from_IVBSAXAttributes( IVBSAXAttributes
*iface
)
124 return CONTAINING_RECORD(iface
, saxattributes
, IVBSAXAttributes_iface
);
127 static inline saxattributes
*impl_from_ISAXAttributes( ISAXAttributes
*iface
)
129 return CONTAINING_RECORD(iface
, saxattributes
, ISAXAttributes_iface
);
132 static inline BOOL
has_content_handler(const saxlocator
*locator
)
134 return (locator
->vbInterface
&& locator
->saxreader
->vbcontentHandler
) ||
135 (!locator
->vbInterface
&& locator
->saxreader
->contentHandler
);
138 static inline BOOL
has_error_handler(const saxlocator
*locator
)
140 return (locator
->vbInterface
&& locator
->saxreader
->vberrorHandler
) ||
141 (!locator
->vbInterface
&& locator
->saxreader
->errorHandler
);
144 static HRESULT
namespacePush(saxlocator
*locator
, int ns
)
146 if(locator
->nsStackLast
>=locator
->nsStackSize
)
150 new_stack
= HeapReAlloc(GetProcessHeap(), 0,
151 locator
->nsStack
, sizeof(int)*locator
->nsStackSize
*2);
152 if(!new_stack
) return E_OUTOFMEMORY
;
153 locator
->nsStack
= new_stack
;
154 locator
->nsStackSize
*= 2;
156 locator
->nsStack
[locator
->nsStackLast
++] = ns
;
161 static int namespacePop(saxlocator
*locator
)
163 if(locator
->nsStackLast
== 0) return 0;
164 return locator
->nsStack
[--locator
->nsStackLast
];
167 static BSTR
bstr_from_xmlCharN(const xmlChar
*buf
, int len
)
175 dLen
= MultiByteToWideChar(CP_UTF8
, 0, (LPCSTR
)buf
, len
, NULL
, 0);
176 if(len
!= -1) dLen
++;
177 bstr
= SysAllocStringLen(NULL
, dLen
-1);
180 MultiByteToWideChar(CP_UTF8
, 0, (LPCSTR
)buf
, len
, bstr
, dLen
);
181 if(len
!= -1) bstr
[dLen
-1] = '\0';
186 static BSTR
QName_from_xmlChar(const xmlChar
*prefix
, const xmlChar
*name
)
191 if(!name
) return NULL
;
193 if(!prefix
|| !*prefix
)
194 return bstr_from_xmlChar(name
);
196 qname
= xmlBuildQName(name
, prefix
, NULL
, 0);
197 bstr
= bstr_from_xmlChar(qname
);
203 static void format_error_message_from_id(saxlocator
*This
, HRESULT hr
)
205 xmlStopParser(This
->pParserCtxt
);
208 if(has_error_handler(This
))
211 if(!FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM
,
212 NULL
, hr
, 0, msg
, sizeof(msg
), NULL
))
214 FIXME("MSXML errors not yet supported.\n");
218 if(This
->vbInterface
)
220 BSTR bstrMsg
= SysAllocString(msg
);
221 IVBSAXErrorHandler_fatalError(This
->saxreader
->vberrorHandler
,
222 &This
->IVBSAXLocator_iface
, &bstrMsg
, hr
);
223 SysFreeString(bstrMsg
);
226 ISAXErrorHandler_fatalError(This
->saxreader
->errorHandler
,
227 &This
->ISAXLocator_iface
, msg
, hr
);
231 static void update_position(saxlocator
*This
, xmlChar
*end
)
233 if(This
->lastCur
== NULL
)
235 This
->lastCur
= (xmlChar
*)This
->pParserCtxt
->input
->base
;
237 This
->realColumn
= 1;
239 else if(This
->lastCur
< This
->pParserCtxt
->input
->base
)
241 This
->lastCur
= (xmlChar
*)This
->pParserCtxt
->input
->base
;
243 This
->realColumn
= 1;
246 if(This
->pParserCtxt
->input
->cur
<This
->lastCur
)
248 This
->lastCur
= (xmlChar
*)This
->pParserCtxt
->input
->base
;
250 This
->realColumn
= 1;
253 if(!end
) end
= (xmlChar
*)This
->pParserCtxt
->input
->cur
;
255 while(This
->lastCur
< end
)
257 if(*(This
->lastCur
) == '\n')
260 This
->realColumn
= 1;
262 else if(*(This
->lastCur
) == '\r' &&
263 (This
->lastCur
==This
->pParserCtxt
->input
->end
||
264 *(This
->lastCur
+1)!='\n'))
267 This
->realColumn
= 1;
269 else This
->realColumn
++;
273 /* Count multibyte UTF8 encoded characters once */
274 while((*(This
->lastCur
)&0xC0) == 0x80) This
->lastCur
++;
277 This
->line
= This
->realLine
;
278 This
->column
= This
->realColumn
;
281 /*** IVBSAXAttributes interface ***/
282 /*** IUnknown methods ***/
283 static HRESULT WINAPI
ivbsaxattributes_QueryInterface(
284 IVBSAXAttributes
* iface
,
288 saxattributes
*This
= impl_from_IVBSAXAttributes(iface
);
290 TRACE("%p %s %p\n", This
, debugstr_guid(riid
), ppvObject
);
294 if (IsEqualGUID(riid
, &IID_IUnknown
) ||
295 IsEqualGUID(riid
, &IID_IDispatch
) ||
296 IsEqualGUID(riid
, &IID_IVBSAXAttributes
))
302 FIXME("interface %s not implemented\n", debugstr_guid(riid
));
303 return E_NOINTERFACE
;
306 IVBSAXAttributes_AddRef(iface
);
311 static ULONG WINAPI
ivbsaxattributes_AddRef(IVBSAXAttributes
* iface
)
313 saxattributes
*This
= impl_from_IVBSAXAttributes(iface
);
314 return ISAXAttributes_AddRef(&This
->ISAXAttributes_iface
);
317 static ULONG WINAPI
ivbsaxattributes_Release(IVBSAXAttributes
* iface
)
319 saxattributes
*This
= impl_from_IVBSAXAttributes(iface
);
320 return ISAXAttributes_Release(&This
->ISAXAttributes_iface
);
323 /*** IDispatch methods ***/
324 static HRESULT WINAPI
ivbsaxattributes_GetTypeInfoCount( IVBSAXAttributes
*iface
, UINT
* pctinfo
)
326 saxattributes
*This
= impl_from_IVBSAXAttributes( iface
);
328 TRACE("(%p)->(%p)\n", This
, pctinfo
);
335 static HRESULT WINAPI
ivbsaxattributes_GetTypeInfo(
336 IVBSAXAttributes
*iface
,
337 UINT iTInfo
, LCID lcid
, ITypeInfo
** ppTInfo
)
339 saxattributes
*This
= impl_from_IVBSAXAttributes( iface
);
342 TRACE("(%p)->(%u %u %p)\n", This
, iTInfo
, lcid
, ppTInfo
);
344 hr
= get_typeinfo(IVBSAXAttributes_tid
, ppTInfo
);
349 static HRESULT WINAPI
ivbsaxattributes_GetIDsOfNames(
350 IVBSAXAttributes
*iface
,
357 saxattributes
*This
= impl_from_IVBSAXAttributes( iface
);
361 TRACE("(%p)->(%s %p %u %u %p)\n", This
, debugstr_guid(riid
), rgszNames
, cNames
,
364 if(!rgszNames
|| cNames
== 0 || !rgDispId
)
367 hr
= get_typeinfo(IVBSAXAttributes_tid
, &typeinfo
);
370 hr
= ITypeInfo_GetIDsOfNames(typeinfo
, rgszNames
, cNames
, rgDispId
);
371 ITypeInfo_Release(typeinfo
);
377 static HRESULT WINAPI
ivbsaxattributes_Invoke(
378 IVBSAXAttributes
*iface
,
383 DISPPARAMS
* pDispParams
,
385 EXCEPINFO
* pExcepInfo
,
388 saxattributes
*This
= impl_from_IVBSAXAttributes( iface
);
392 TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This
, dispIdMember
, debugstr_guid(riid
),
393 lcid
, wFlags
, pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
395 hr
= get_typeinfo(IVBSAXAttributes_tid
, &typeinfo
);
398 hr
= ITypeInfo_Invoke(typeinfo
, &This
->IVBSAXAttributes_iface
, dispIdMember
, wFlags
,
399 pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
400 ITypeInfo_Release(typeinfo
);
406 /*** IVBSAXAttributes methods ***/
407 static HRESULT WINAPI
ivbsaxattributes_get_length(
408 IVBSAXAttributes
* iface
,
411 saxattributes
*This
= impl_from_IVBSAXAttributes( iface
);
412 return ISAXAttributes_getLength(&This
->ISAXAttributes_iface
, nLength
);
415 static HRESULT WINAPI
ivbsaxattributes_getURI(
416 IVBSAXAttributes
* iface
,
421 saxattributes
*This
= impl_from_IVBSAXAttributes( iface
);
422 return ISAXAttributes_getURI(&This
->ISAXAttributes_iface
, nIndex
, (const WCHAR
**)uri
, &len
);
425 static HRESULT WINAPI
ivbsaxattributes_getLocalName(
426 IVBSAXAttributes
* iface
,
431 saxattributes
*This
= impl_from_IVBSAXAttributes( iface
);
432 return ISAXAttributes_getLocalName(&This
->ISAXAttributes_iface
, nIndex
,
433 (const WCHAR
**)localName
, &len
);
436 static HRESULT WINAPI
ivbsaxattributes_getQName(
437 IVBSAXAttributes
* iface
,
442 saxattributes
*This
= impl_from_IVBSAXAttributes( iface
);
443 return ISAXAttributes_getQName(&This
->ISAXAttributes_iface
, nIndex
, (const WCHAR
**)QName
, &len
);
446 static HRESULT WINAPI
ivbsaxattributes_getIndexFromName(
447 IVBSAXAttributes
* iface
,
452 saxattributes
*This
= impl_from_IVBSAXAttributes( iface
);
453 return ISAXAttributes_getIndexFromName(&This
->ISAXAttributes_iface
, uri
, SysStringLen(uri
),
454 localName
, SysStringLen(localName
), index
);
457 static HRESULT WINAPI
ivbsaxattributes_getIndexFromQName(
458 IVBSAXAttributes
* iface
,
462 saxattributes
*This
= impl_from_IVBSAXAttributes( iface
);
463 return ISAXAttributes_getIndexFromQName(&This
->ISAXAttributes_iface
, QName
,
464 SysStringLen(QName
), index
);
467 static HRESULT WINAPI
ivbsaxattributes_getType(
468 IVBSAXAttributes
* iface
,
473 saxattributes
*This
= impl_from_IVBSAXAttributes( iface
);
474 return ISAXAttributes_getType(&This
->ISAXAttributes_iface
, nIndex
, (const WCHAR
**)type
, &len
);
477 static HRESULT WINAPI
ivbsaxattributes_getTypeFromName(
478 IVBSAXAttributes
* iface
,
484 saxattributes
*This
= impl_from_IVBSAXAttributes( iface
);
485 return ISAXAttributes_getTypeFromName(&This
->ISAXAttributes_iface
, uri
, SysStringLen(uri
),
486 localName
, SysStringLen(localName
), (const WCHAR
**)type
, &len
);
489 static HRESULT WINAPI
ivbsaxattributes_getTypeFromQName(
490 IVBSAXAttributes
* iface
,
495 saxattributes
*This
= impl_from_IVBSAXAttributes( iface
);
496 return ISAXAttributes_getTypeFromQName(&This
->ISAXAttributes_iface
, QName
, SysStringLen(QName
),
497 (const WCHAR
**)type
, &len
);
500 static HRESULT WINAPI
ivbsaxattributes_getValue(
501 IVBSAXAttributes
* iface
,
506 saxattributes
*This
= impl_from_IVBSAXAttributes( iface
);
507 return ISAXAttributes_getValue(&This
->ISAXAttributes_iface
, nIndex
, (const WCHAR
**)value
, &len
);
510 static HRESULT WINAPI
ivbsaxattributes_getValueFromName(
511 IVBSAXAttributes
* iface
,
517 saxattributes
*This
= impl_from_IVBSAXAttributes( iface
);
518 return ISAXAttributes_getValueFromName(&This
->ISAXAttributes_iface
, uri
, SysStringLen(uri
),
519 localName
, SysStringLen(localName
), (const WCHAR
**)value
, &len
);
522 static HRESULT WINAPI
ivbsaxattributes_getValueFromQName(
523 IVBSAXAttributes
* iface
,
528 saxattributes
*This
= impl_from_IVBSAXAttributes( iface
);
529 return ISAXAttributes_getValueFromQName(&This
->ISAXAttributes_iface
, QName
,
530 SysStringLen(QName
), (const WCHAR
**)value
, &len
);
533 static const struct IVBSAXAttributesVtbl ivbsaxattributes_vtbl
=
535 ivbsaxattributes_QueryInterface
,
536 ivbsaxattributes_AddRef
,
537 ivbsaxattributes_Release
,
538 ivbsaxattributes_GetTypeInfoCount
,
539 ivbsaxattributes_GetTypeInfo
,
540 ivbsaxattributes_GetIDsOfNames
,
541 ivbsaxattributes_Invoke
,
542 ivbsaxattributes_get_length
,
543 ivbsaxattributes_getURI
,
544 ivbsaxattributes_getLocalName
,
545 ivbsaxattributes_getQName
,
546 ivbsaxattributes_getIndexFromName
,
547 ivbsaxattributes_getIndexFromQName
,
548 ivbsaxattributes_getType
,
549 ivbsaxattributes_getTypeFromName
,
550 ivbsaxattributes_getTypeFromQName
,
551 ivbsaxattributes_getValue
,
552 ivbsaxattributes_getValueFromName
,
553 ivbsaxattributes_getValueFromQName
556 /*** ISAXAttributes interface ***/
557 /*** IUnknown methods ***/
558 static HRESULT WINAPI
isaxattributes_QueryInterface(
559 ISAXAttributes
* iface
,
563 saxattributes
*This
= impl_from_ISAXAttributes(iface
);
565 TRACE("%p %s %p\n", This
, debugstr_guid(riid
), ppvObject
);
569 if (IsEqualGUID(riid
, &IID_IUnknown
) ||
570 IsEqualGUID(riid
, &IID_ISAXAttributes
))
576 FIXME("interface %s not implemented\n", debugstr_guid(riid
));
577 return E_NOINTERFACE
;
580 ISAXAttributes_AddRef(iface
);
585 static ULONG WINAPI
isaxattributes_AddRef(ISAXAttributes
* iface
)
587 saxattributes
*This
= impl_from_ISAXAttributes(iface
);
589 return InterlockedIncrement(&This
->ref
);
592 static ULONG WINAPI
isaxattributes_Release(ISAXAttributes
* iface
)
594 saxattributes
*This
= impl_from_ISAXAttributes(iface
);
599 ref
= InterlockedDecrement(&This
->ref
);
603 for(index
=0; index
<This
->nb_attributes
; index
++)
605 SysFreeString(This
->szLocalname
[index
]);
606 SysFreeString(This
->szURI
[index
]);
607 SysFreeString(This
->szValue
[index
]);
608 SysFreeString(This
->szQName
[index
]);
611 heap_free(This
->szLocalname
);
612 heap_free(This
->szURI
);
613 heap_free(This
->szValue
);
614 heap_free(This
->szQName
);
622 /*** ISAXAttributes methods ***/
623 static HRESULT WINAPI
isaxattributes_getLength(
624 ISAXAttributes
* iface
,
627 saxattributes
*This
= impl_from_ISAXAttributes( iface
);
629 *length
= This
->nb_attributes
;
630 TRACE("Length set to %d\n", *length
);
634 static HRESULT WINAPI
isaxattributes_getURI(
635 ISAXAttributes
* iface
,
640 saxattributes
*This
= impl_from_ISAXAttributes( iface
);
641 TRACE("(%p)->(%d)\n", This
, nIndex
);
643 if(nIndex
>=This
->nb_attributes
|| nIndex
<0) return E_INVALIDARG
;
644 if(!pUrl
|| !pUriSize
) return E_POINTER
;
646 *pUriSize
= SysStringLen(This
->szURI
[nIndex
]);
647 *pUrl
= This
->szURI
[nIndex
];
652 static HRESULT WINAPI
isaxattributes_getLocalName(
653 ISAXAttributes
* iface
,
655 const WCHAR
**pLocalName
,
656 int *pLocalNameLength
)
658 saxattributes
*This
= impl_from_ISAXAttributes( iface
);
659 TRACE("(%p)->(%d)\n", This
, nIndex
);
661 if(nIndex
>=This
->nb_attributes
|| nIndex
<0) return E_INVALIDARG
;
662 if(!pLocalName
|| !pLocalNameLength
) return E_POINTER
;
664 *pLocalNameLength
= SysStringLen(This
->szLocalname
[nIndex
]);
665 *pLocalName
= This
->szLocalname
[nIndex
];
670 static HRESULT WINAPI
isaxattributes_getQName(
671 ISAXAttributes
* iface
,
673 const WCHAR
**pQName
,
676 saxattributes
*This
= impl_from_ISAXAttributes( iface
);
677 TRACE("(%p)->(%d)\n", This
, nIndex
);
679 if(nIndex
>=This
->nb_attributes
|| nIndex
<0) return E_INVALIDARG
;
680 if(!pQName
|| !pQNameLength
) return E_POINTER
;
682 *pQNameLength
= SysStringLen(This
->szQName
[nIndex
]);
683 *pQName
= This
->szQName
[nIndex
];
688 static HRESULT WINAPI
isaxattributes_getName(
689 ISAXAttributes
* iface
,
693 const WCHAR
**pLocalName
,
695 const WCHAR
**pQName
,
698 saxattributes
*This
= impl_from_ISAXAttributes( iface
);
699 TRACE("(%p)->(%d)\n", This
, nIndex
);
701 if(nIndex
>=This
->nb_attributes
|| nIndex
<0) return E_INVALIDARG
;
702 if(!pUri
|| !pUriLength
|| !pLocalName
|| !pLocalNameSize
703 || !pQName
|| !pQNameLength
) return E_POINTER
;
705 *pUriLength
= SysStringLen(This
->szURI
[nIndex
]);
706 *pUri
= This
->szURI
[nIndex
];
707 *pLocalNameSize
= SysStringLen(This
->szLocalname
[nIndex
]);
708 *pLocalName
= This
->szLocalname
[nIndex
];
709 *pQNameLength
= SysStringLen(This
->szQName
[nIndex
]);
710 *pQName
= This
->szQName
[nIndex
];
715 static HRESULT WINAPI
isaxattributes_getIndexFromName(
716 ISAXAttributes
* iface
,
719 const WCHAR
*pLocalName
,
723 saxattributes
*This
= impl_from_ISAXAttributes( iface
);
725 TRACE("(%p)->(%s, %d, %s, %d)\n", This
, debugstr_w(pUri
), cUriLength
,
726 debugstr_w(pLocalName
), cocalNameLength
);
728 if(!pUri
|| !pLocalName
|| !index
) return E_POINTER
;
730 for(i
=0; i
<This
->nb_attributes
; i
++)
732 if(cUriLength
!=SysStringLen(This
->szURI
[i
])
733 || cocalNameLength
!=SysStringLen(This
->szLocalname
[i
]))
735 if(cUriLength
&& memcmp(pUri
, This
->szURI
[i
],
736 sizeof(WCHAR
)*cUriLength
))
738 if(cocalNameLength
&& memcmp(pLocalName
, This
->szLocalname
[i
],
739 sizeof(WCHAR
)*cocalNameLength
))
749 static HRESULT WINAPI
isaxattributes_getIndexFromQName(
750 ISAXAttributes
* iface
,
755 saxattributes
*This
= impl_from_ISAXAttributes( iface
);
757 TRACE("(%p)->(%s, %d)\n", This
, debugstr_w(pQName
), nQNameLength
);
759 if(!pQName
|| !index
) return E_POINTER
;
760 if(!nQNameLength
) return E_INVALIDARG
;
762 for(i
=0; i
<This
->nb_attributes
; i
++)
764 if(nQNameLength
!=SysStringLen(This
->szQName
[i
])) continue;
765 if(memcmp(pQName
, This
->szQName
, sizeof(WCHAR
)*nQNameLength
)) continue;
774 static HRESULT WINAPI
isaxattributes_getType(
775 ISAXAttributes
* iface
,
780 saxattributes
*This
= impl_from_ISAXAttributes( iface
);
782 FIXME("(%p)->(%d) stub\n", This
, nIndex
);
786 static HRESULT WINAPI
isaxattributes_getTypeFromName(
787 ISAXAttributes
* iface
,
790 const WCHAR
*pLocalName
,
795 saxattributes
*This
= impl_from_ISAXAttributes( iface
);
797 FIXME("(%p)->(%s, %d, %s, %d) stub\n", This
, debugstr_w(pUri
), nUri
,
798 debugstr_w(pLocalName
), nLocalName
);
802 static HRESULT WINAPI
isaxattributes_getTypeFromQName(
803 ISAXAttributes
* iface
,
809 saxattributes
*This
= impl_from_ISAXAttributes( iface
);
811 FIXME("(%p)->(%s, %d) stub\n", This
, debugstr_w(pQName
), nQName
);
815 static HRESULT WINAPI
isaxattributes_getValue(
816 ISAXAttributes
* iface
,
818 const WCHAR
**pValue
,
821 saxattributes
*This
= impl_from_ISAXAttributes( iface
);
822 TRACE("(%p)->(%d)\n", This
, nIndex
);
824 if(nIndex
>=This
->nb_attributes
|| nIndex
<0) return E_INVALIDARG
;
825 if(!pValue
|| !nValue
) return E_POINTER
;
827 *nValue
= SysStringLen(This
->szValue
[nIndex
]);
828 *pValue
= This
->szValue
[nIndex
];
833 static HRESULT WINAPI
isaxattributes_getValueFromName(
834 ISAXAttributes
* iface
,
837 const WCHAR
*pLocalName
,
839 const WCHAR
**pValue
,
844 saxattributes
*This
= impl_from_ISAXAttributes( iface
);
845 TRACE("(%p)->(%s, %d, %s, %d)\n", This
, debugstr_w(pUri
), nUri
,
846 debugstr_w(pLocalName
), nLocalName
);
848 hr
= ISAXAttributes_getIndexFromName(iface
,
849 pUri
, nUri
, pLocalName
, nLocalName
, &index
);
850 if(hr
==S_OK
) hr
= ISAXAttributes_getValue(iface
, index
, pValue
, nValue
);
855 static HRESULT WINAPI
isaxattributes_getValueFromQName(
856 ISAXAttributes
* iface
,
859 const WCHAR
**pValue
,
864 saxattributes
*This
= impl_from_ISAXAttributes( iface
);
865 TRACE("(%p)->(%s, %d)\n", This
, debugstr_w(pQName
), nQName
);
867 hr
= ISAXAttributes_getIndexFromQName(iface
, pQName
, nQName
, &index
);
868 if(hr
==S_OK
) hr
= ISAXAttributes_getValue(iface
, index
, pValue
, nValue
);
873 static const struct ISAXAttributesVtbl isaxattributes_vtbl
=
875 isaxattributes_QueryInterface
,
876 isaxattributes_AddRef
,
877 isaxattributes_Release
,
878 isaxattributes_getLength
,
879 isaxattributes_getURI
,
880 isaxattributes_getLocalName
,
881 isaxattributes_getQName
,
882 isaxattributes_getName
,
883 isaxattributes_getIndexFromName
,
884 isaxattributes_getIndexFromQName
,
885 isaxattributes_getType
,
886 isaxattributes_getTypeFromName
,
887 isaxattributes_getTypeFromQName
,
888 isaxattributes_getValue
,
889 isaxattributes_getValueFromName
,
890 isaxattributes_getValueFromQName
893 static HRESULT
SAXAttributes_create(saxattributes
**attr
,
894 int nb_namespaces
, const xmlChar
**xmlNamespaces
,
895 int nb_attributes
, const xmlChar
**xmlAttributes
)
897 saxattributes
*attributes
;
899 static const xmlChar xmlns
[] = "xmlns";
901 attributes
= heap_alloc(sizeof(*attributes
));
903 return E_OUTOFMEMORY
;
905 attributes
->IVBSAXAttributes_iface
.lpVtbl
= &ivbsaxattributes_vtbl
;
906 attributes
->ISAXAttributes_iface
.lpVtbl
= &isaxattributes_vtbl
;
909 attributes
->nb_attributes
= nb_namespaces
+nb_attributes
;
911 attributes
->szLocalname
= heap_alloc(sizeof(BSTR
)*attributes
->nb_attributes
);
912 attributes
->szURI
= heap_alloc(sizeof(BSTR
)*attributes
->nb_attributes
);
913 attributes
->szValue
= heap_alloc(sizeof(BSTR
)*attributes
->nb_attributes
);
914 attributes
->szQName
= heap_alloc(sizeof(BSTR
)*attributes
->nb_attributes
);
916 if(!attributes
->szLocalname
|| !attributes
->szURI
917 || !attributes
->szValue
|| !attributes
->szQName
)
919 heap_free(attributes
->szLocalname
);
920 heap_free(attributes
->szURI
);
921 heap_free(attributes
->szValue
);
922 heap_free(attributes
->szQName
);
923 heap_free(attributes
);
927 for(index
=0; index
<nb_namespaces
; index
++)
929 attributes
->szLocalname
[index
] = SysAllocStringLen(NULL
, 0);
930 attributes
->szURI
[index
] = SysAllocStringLen(NULL
, 0);
931 attributes
->szValue
[index
] = bstr_from_xmlChar(xmlNamespaces
[2*index
+1]);
932 attributes
->szQName
[index
] = QName_from_xmlChar(xmlns
, xmlNamespaces
[2*index
]);
935 for(index
=0; index
<nb_attributes
; index
++)
937 attributes
->szLocalname
[nb_namespaces
+index
] =
938 bstr_from_xmlChar(xmlAttributes
[index
*5]);
939 attributes
->szURI
[nb_namespaces
+index
] =
940 bstr_from_xmlChar(xmlAttributes
[index
*5+2]);
941 attributes
->szValue
[nb_namespaces
+index
] =
942 bstr_from_xmlCharN(xmlAttributes
[index
*5+3],
943 xmlAttributes
[index
*5+4]-xmlAttributes
[index
*5+3]);
944 attributes
->szQName
[nb_namespaces
+index
] =
945 QName_from_xmlChar(xmlAttributes
[index
*5+1], xmlAttributes
[index
*5]);
950 TRACE("returning %p\n", *attr
);
955 /*** LibXML callbacks ***/
956 static void libxmlStartDocument(void *ctx
)
958 saxlocator
*This
= ctx
;
961 if(has_content_handler(This
))
963 if(This
->vbInterface
)
964 hr
= IVBSAXContentHandler_startDocument(This
->saxreader
->vbcontentHandler
);
966 hr
= ISAXContentHandler_startDocument(This
->saxreader
->contentHandler
);
969 format_error_message_from_id(This
, hr
);
972 update_position(This
, NULL
);
975 static void libxmlEndDocument(void *ctx
)
977 saxlocator
*This
= ctx
;
983 if(This
->ret
!= S_OK
) return;
985 if(has_content_handler(This
))
987 if(This
->vbInterface
)
988 hr
= IVBSAXContentHandler_endDocument(This
->saxreader
->vbcontentHandler
);
990 hr
= ISAXContentHandler_endDocument(This
->saxreader
->contentHandler
);
993 format_error_message_from_id(This
, hr
);
997 static void libxmlStartElementNS(
999 const xmlChar
*localname
,
1000 const xmlChar
*prefix
,
1003 const xmlChar
**namespaces
,
1006 const xmlChar
**attributes
)
1008 BSTR NamespaceUri
, LocalName
, QName
, Prefix
, Uri
;
1009 saxlocator
*This
= ctx
;
1011 saxattributes
*attr
;
1014 if(*(This
->pParserCtxt
->input
->cur
) == '/')
1015 update_position(This
, (xmlChar
*)This
->pParserCtxt
->input
->cur
+2);
1017 update_position(This
, (xmlChar
*)This
->pParserCtxt
->input
->cur
+1);
1019 hr
= namespacePush(This
, nb_namespaces
);
1020 if(hr
==S_OK
&& has_content_handler(This
))
1022 for(index
=0; index
<nb_namespaces
; index
++)
1024 Prefix
= bstr_from_xmlChar(namespaces
[2*index
]);
1025 Uri
= bstr_from_xmlChar(namespaces
[2*index
+1]);
1027 if(This
->vbInterface
)
1028 hr
= IVBSAXContentHandler_startPrefixMapping(
1029 This
->saxreader
->vbcontentHandler
,
1032 hr
= ISAXContentHandler_startPrefixMapping(
1033 This
->saxreader
->contentHandler
,
1034 Prefix
, SysStringLen(Prefix
),
1035 Uri
, SysStringLen(Uri
));
1037 SysFreeString(Prefix
);
1042 format_error_message_from_id(This
, hr
);
1047 NamespaceUri
= bstr_from_xmlChar(URI
);
1048 LocalName
= bstr_from_xmlChar(localname
);
1049 QName
= QName_from_xmlChar(prefix
, localname
);
1051 hr
= SAXAttributes_create(&attr
, nb_namespaces
, namespaces
, nb_attributes
, attributes
);
1054 if(This
->vbInterface
)
1055 hr
= IVBSAXContentHandler_startElement(This
->saxreader
->vbcontentHandler
,
1056 &NamespaceUri
, &LocalName
, &QName
, &attr
->IVBSAXAttributes_iface
);
1058 hr
= ISAXContentHandler_startElement(This
->saxreader
->contentHandler
, NamespaceUri
,
1059 SysStringLen(NamespaceUri
), LocalName
, SysStringLen(LocalName
), QName
,
1060 SysStringLen(QName
), &attr
->ISAXAttributes_iface
);
1062 ISAXAttributes_Release(&attr
->ISAXAttributes_iface
);
1065 SysFreeString(NamespaceUri
);
1066 SysFreeString(LocalName
);
1067 SysFreeString(QName
);
1071 format_error_message_from_id(This
, hr
);
1074 static void libxmlEndElementNS(
1076 const xmlChar
*localname
,
1077 const xmlChar
*prefix
,
1080 BSTR NamespaceUri
, LocalName
, QName
, Prefix
;
1081 saxlocator
*This
= ctx
;
1086 end
= (xmlChar
*)This
->pParserCtxt
->input
->cur
;
1087 if(*(end
-1) != '>' || *(end
-2) != '/')
1088 while(end
-2>=This
->pParserCtxt
->input
->base
1089 && *(end
-2)!='<' && *(end
-1)!='/') end
--;
1091 update_position(This
, end
);
1093 nsNr
= namespacePop(This
);
1095 if(has_content_handler(This
))
1097 NamespaceUri
= bstr_from_xmlChar(URI
);
1098 LocalName
= bstr_from_xmlChar(localname
);
1099 QName
= QName_from_xmlChar(prefix
, localname
);
1101 if(This
->vbInterface
)
1102 hr
= IVBSAXContentHandler_endElement(
1103 This
->saxreader
->vbcontentHandler
,
1104 &NamespaceUri
, &LocalName
, &QName
);
1106 hr
= ISAXContentHandler_endElement(
1107 This
->saxreader
->contentHandler
,
1108 NamespaceUri
, SysStringLen(NamespaceUri
),
1109 LocalName
, SysStringLen(LocalName
),
1110 QName
, SysStringLen(QName
));
1112 SysFreeString(NamespaceUri
);
1113 SysFreeString(LocalName
);
1114 SysFreeString(QName
);
1118 format_error_message_from_id(This
, hr
);
1122 for(index
=This
->pParserCtxt
->nsNr
-2;
1123 index
>=This
->pParserCtxt
->nsNr
-nsNr
*2; index
-=2)
1125 Prefix
= bstr_from_xmlChar(This
->pParserCtxt
->nsTab
[index
]);
1127 if(This
->vbInterface
)
1128 hr
= IVBSAXContentHandler_endPrefixMapping(
1129 This
->saxreader
->vbcontentHandler
, &Prefix
);
1131 hr
= ISAXContentHandler_endPrefixMapping(
1132 This
->saxreader
->contentHandler
,
1133 Prefix
, SysStringLen(Prefix
));
1135 SysFreeString(Prefix
);
1139 format_error_message_from_id(This
, hr
);
1146 update_position(This
, NULL
);
1149 static void libxmlCharacters(
1154 saxlocator
*This
= ctx
;
1159 BOOL lastEvent
= FALSE
;
1161 if(!(has_content_handler(This
))) return;
1164 if(*(ch
-1)=='\r') cur
--;
1167 if(ch
<This
->pParserCtxt
->input
->base
|| ch
>This
->pParserCtxt
->input
->end
)
1172 while(end
-ch
<len
&& *end
!='\r') end
++;
1179 if(!lastEvent
) *end
= '\n';
1181 Chars
= bstr_from_xmlCharN(cur
, end
-cur
+1);
1182 if(This
->vbInterface
)
1183 hr
= IVBSAXContentHandler_characters(
1184 This
->saxreader
->vbcontentHandler
, &Chars
);
1186 hr
= ISAXContentHandler_characters(
1187 This
->saxreader
->contentHandler
,
1188 Chars
, SysStringLen(Chars
));
1189 SysFreeString(Chars
);
1193 format_error_message_from_id(This
, hr
);
1197 This
->column
+= end
-cur
+1;
1211 if(end
-ch
== len
) break;
1214 if(ch
<This
->pParserCtxt
->input
->base
|| ch
>This
->pParserCtxt
->input
->end
)
1215 This
->column
= This
->realColumn
1216 +This
->pParserCtxt
->input
->cur
-This
->lastCur
;
1219 static void libxmlSetDocumentLocator(
1221 xmlSAXLocatorPtr loc
)
1223 saxlocator
*This
= ctx
;
1226 if(has_content_handler(This
))
1228 if(This
->vbInterface
)
1229 hr
= IVBSAXContentHandler_putref_documentLocator(This
->saxreader
->vbcontentHandler
,
1230 &This
->IVBSAXLocator_iface
);
1232 hr
= ISAXContentHandler_putDocumentLocator(This
->saxreader
->contentHandler
,
1233 &This
->ISAXLocator_iface
);
1237 format_error_message_from_id(This
, hr
);
1240 static void libxmlComment(void *ctx
, const xmlChar
*value
)
1242 saxlocator
*This
= ctx
;
1245 xmlChar
*beg
= (xmlChar
*)This
->pParserCtxt
->input
->cur
;
1247 while(beg
-4>=This
->pParserCtxt
->input
->base
1248 && memcmp(beg
-4, "<!--", sizeof(char[4]))) beg
--;
1249 update_position(This
, beg
);
1251 if(!This
->vbInterface
&& !This
->saxreader
->lexicalHandler
) return;
1252 if(This
->vbInterface
&& !This
->saxreader
->vblexicalHandler
) return;
1254 bValue
= bstr_from_xmlChar(value
);
1256 if(This
->vbInterface
)
1257 hr
= IVBSAXLexicalHandler_comment(
1258 This
->saxreader
->vblexicalHandler
, &bValue
);
1260 hr
= ISAXLexicalHandler_comment(
1261 This
->saxreader
->lexicalHandler
,
1262 bValue
, SysStringLen(bValue
));
1264 SysFreeString(bValue
);
1267 format_error_message_from_id(This
, hr
);
1269 update_position(This
, NULL
);
1272 static void libxmlFatalError(void *ctx
, const char *msg
, ...)
1274 saxlocator
*This
= ctx
;
1280 va_start(args
, msg
);
1281 vsprintf(message
, msg
, args
);
1284 len
= MultiByteToWideChar(CP_UNIXCP
, 0, message
, -1, NULL
, 0);
1285 error
= heap_alloc(sizeof(WCHAR
)*len
);
1288 MultiByteToWideChar(CP_UNIXCP
, 0, message
, -1, error
, len
);
1289 TRACE("fatal error for %p: %s\n", This
, debugstr_w(error
));
1292 if(!has_error_handler(This
))
1294 xmlStopParser(This
->pParserCtxt
);
1300 FIXME("Error handling is not compatible.\n");
1302 if(This
->vbInterface
)
1304 BSTR bstrError
= SysAllocString(error
);
1305 IVBSAXErrorHandler_fatalError(This
->saxreader
->vberrorHandler
, &This
->IVBSAXLocator_iface
,
1306 &bstrError
, E_FAIL
);
1307 SysFreeString(bstrError
);
1310 ISAXErrorHandler_fatalError(This
->saxreader
->errorHandler
, &This
->ISAXLocator_iface
,
1315 xmlStopParser(This
->pParserCtxt
);
1319 static void libxmlCDataBlock(void *ctx
, const xmlChar
*value
, int len
)
1321 saxlocator
*This
= ctx
;
1323 xmlChar
*beg
= (xmlChar
*)This
->pParserCtxt
->input
->cur
-len
;
1327 BOOL lastEvent
= FALSE
, change
;
1329 while(beg
-9>=This
->pParserCtxt
->input
->base
1330 && memcmp(beg
-9, "<![CDATA[", sizeof(char[9]))) beg
--;
1331 update_position(This
, beg
);
1333 if(This
->vbInterface
&& This
->saxreader
->vblexicalHandler
)
1334 hr
= IVBSAXLexicalHandler_startCDATA(This
->saxreader
->vblexicalHandler
);
1335 if(!This
->vbInterface
&& This
->saxreader
->lexicalHandler
)
1336 hr
= ISAXLexicalHandler_startCDATA(This
->saxreader
->lexicalHandler
);
1340 format_error_message_from_id(This
, hr
);
1344 realLen
= This
->pParserCtxt
->input
->cur
-beg
-3;
1350 while(end
-beg
<realLen
&& *end
!='\r') end
++;
1351 if(end
-beg
==realLen
)
1356 else if(end
-beg
==realLen
-1 && *end
=='\r' && *(end
+1)=='\n')
1359 if(*end
== '\r') change
= TRUE
;
1360 else change
= FALSE
;
1362 if(change
) *end
= '\n';
1364 if(has_content_handler(This
))
1366 Chars
= bstr_from_xmlCharN(cur
, end
-cur
+1);
1367 if(This
->vbInterface
)
1368 hr
= IVBSAXContentHandler_characters(
1369 This
->saxreader
->vbcontentHandler
, &Chars
);
1371 hr
= ISAXContentHandler_characters(
1372 This
->saxreader
->contentHandler
,
1373 Chars
, SysStringLen(Chars
));
1374 SysFreeString(Chars
);
1377 if(change
) *end
= '\r';
1382 This
->column
+= end
-cur
+2;
1387 if(This
->vbInterface
&& This
->saxreader
->vblexicalHandler
)
1388 hr
= IVBSAXLexicalHandler_endCDATA(This
->saxreader
->vblexicalHandler
);
1389 if(!This
->vbInterface
&& This
->saxreader
->lexicalHandler
)
1390 hr
= ISAXLexicalHandler_endCDATA(This
->saxreader
->lexicalHandler
);
1393 format_error_message_from_id(This
, hr
);
1395 This
->column
+= 4+end
-cur
;
1398 /*** IVBSAXLocator interface ***/
1399 /*** IUnknown methods ***/
1400 static HRESULT WINAPI
ivbsaxlocator_QueryInterface(IVBSAXLocator
* iface
, REFIID riid
, void **ppvObject
)
1402 saxlocator
*This
= impl_from_IVBSAXLocator( iface
);
1404 TRACE("%p %s %p\n", This
, debugstr_guid( riid
), ppvObject
);
1408 if ( IsEqualGUID( riid
, &IID_IUnknown
) ||
1409 IsEqualGUID( riid
, &IID_IDispatch
) ||
1410 IsEqualGUID( riid
, &IID_IVBSAXLocator
))
1416 FIXME("interface %s not implemented\n", debugstr_guid(riid
));
1417 return E_NOINTERFACE
;
1420 IVBSAXLocator_AddRef( iface
);
1425 static ULONG WINAPI
ivbsaxlocator_AddRef(IVBSAXLocator
* iface
)
1427 saxlocator
*This
= impl_from_IVBSAXLocator( iface
);
1428 TRACE("%p\n", This
);
1429 return InterlockedIncrement( &This
->ref
);
1432 static ULONG WINAPI
ivbsaxlocator_Release(
1433 IVBSAXLocator
* iface
)
1435 saxlocator
*This
= impl_from_IVBSAXLocator( iface
);
1436 return ISAXLocator_Release((ISAXLocator
*)&This
->IVBSAXLocator_iface
);
1439 /*** IDispatch methods ***/
1440 static HRESULT WINAPI
ivbsaxlocator_GetTypeInfoCount( IVBSAXLocator
*iface
, UINT
* pctinfo
)
1442 saxlocator
*This
= impl_from_IVBSAXLocator( iface
);
1444 TRACE("(%p)->(%p)\n", This
, pctinfo
);
1451 static HRESULT WINAPI
ivbsaxlocator_GetTypeInfo(
1452 IVBSAXLocator
*iface
,
1453 UINT iTInfo
, LCID lcid
, ITypeInfo
** ppTInfo
)
1455 saxlocator
*This
= impl_from_IVBSAXLocator( iface
);
1458 TRACE("(%p)->(%u %u %p)\n", This
, iTInfo
, lcid
, ppTInfo
);
1460 hr
= get_typeinfo(IVBSAXLocator_tid
, ppTInfo
);
1465 static HRESULT WINAPI
ivbsaxlocator_GetIDsOfNames(
1466 IVBSAXLocator
*iface
,
1468 LPOLESTR
* rgszNames
,
1473 saxlocator
*This
= impl_from_IVBSAXLocator( iface
);
1474 ITypeInfo
*typeinfo
;
1477 TRACE("(%p)->(%s %p %u %u %p)\n", This
, debugstr_guid(riid
), rgszNames
, cNames
,
1480 if(!rgszNames
|| cNames
== 0 || !rgDispId
)
1481 return E_INVALIDARG
;
1483 hr
= get_typeinfo(IVBSAXLocator_tid
, &typeinfo
);
1486 hr
= ITypeInfo_GetIDsOfNames(typeinfo
, rgszNames
, cNames
, rgDispId
);
1487 ITypeInfo_Release(typeinfo
);
1493 static HRESULT WINAPI
ivbsaxlocator_Invoke(
1494 IVBSAXLocator
*iface
,
1495 DISPID dispIdMember
,
1499 DISPPARAMS
* pDispParams
,
1500 VARIANT
* pVarResult
,
1501 EXCEPINFO
* pExcepInfo
,
1504 saxlocator
*This
= impl_from_IVBSAXLocator( iface
);
1505 ITypeInfo
*typeinfo
;
1508 TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This
, dispIdMember
, debugstr_guid(riid
),
1509 lcid
, wFlags
, pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
1511 hr
= get_typeinfo(IVBSAXLocator_tid
, &typeinfo
);
1514 hr
= ITypeInfo_Invoke(typeinfo
, &This
->IVBSAXLocator_iface
, dispIdMember
, wFlags
,
1515 pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
1516 ITypeInfo_Release(typeinfo
);
1522 /*** IVBSAXLocator methods ***/
1523 static HRESULT WINAPI
ivbsaxlocator_get_columnNumber(
1524 IVBSAXLocator
* iface
,
1527 saxlocator
*This
= impl_from_IVBSAXLocator( iface
);
1528 return ISAXLocator_getColumnNumber((ISAXLocator
*)&This
->IVBSAXLocator_iface
, pnColumn
);
1531 static HRESULT WINAPI
ivbsaxlocator_get_lineNumber(
1532 IVBSAXLocator
* iface
,
1535 saxlocator
*This
= impl_from_IVBSAXLocator( iface
);
1536 return ISAXLocator_getLineNumber((ISAXLocator
*)&This
->IVBSAXLocator_iface
, pnLine
);
1539 static HRESULT WINAPI
ivbsaxlocator_get_publicId(
1540 IVBSAXLocator
* iface
,
1543 saxlocator
*This
= impl_from_IVBSAXLocator( iface
);
1544 return ISAXLocator_getPublicId((ISAXLocator
*)&This
->IVBSAXLocator_iface
,
1545 (const WCHAR
**)publicId
);
1548 static HRESULT WINAPI
ivbsaxlocator_get_systemId(
1549 IVBSAXLocator
* iface
,
1552 saxlocator
*This
= impl_from_IVBSAXLocator( iface
);
1553 return ISAXLocator_getSystemId((ISAXLocator
*)&This
->IVBSAXLocator_iface
,
1554 (const WCHAR
**)systemId
);
1557 static const struct IVBSAXLocatorVtbl ivbsaxlocator_vtbl
=
1559 ivbsaxlocator_QueryInterface
,
1560 ivbsaxlocator_AddRef
,
1561 ivbsaxlocator_Release
,
1562 ivbsaxlocator_GetTypeInfoCount
,
1563 ivbsaxlocator_GetTypeInfo
,
1564 ivbsaxlocator_GetIDsOfNames
,
1565 ivbsaxlocator_Invoke
,
1566 ivbsaxlocator_get_columnNumber
,
1567 ivbsaxlocator_get_lineNumber
,
1568 ivbsaxlocator_get_publicId
,
1569 ivbsaxlocator_get_systemId
1572 /*** ISAXLocator interface ***/
1573 /*** IUnknown methods ***/
1574 static HRESULT WINAPI
isaxlocator_QueryInterface(ISAXLocator
* iface
, REFIID riid
, void **ppvObject
)
1576 saxlocator
*This
= impl_from_ISAXLocator( iface
);
1578 TRACE("%p %s %p\n", This
, debugstr_guid( riid
), ppvObject
);
1582 if ( IsEqualGUID( riid
, &IID_IUnknown
) ||
1583 IsEqualGUID( riid
, &IID_ISAXLocator
))
1589 FIXME("interface %s not implemented\n", debugstr_guid(riid
));
1590 return E_NOINTERFACE
;
1593 ISAXLocator_AddRef( iface
);
1598 static ULONG WINAPI
isaxlocator_AddRef(ISAXLocator
* iface
)
1600 saxlocator
*This
= impl_from_ISAXLocator( iface
);
1601 TRACE("%p\n", This
);
1602 return InterlockedIncrement( &This
->ref
);
1605 static ULONG WINAPI
isaxlocator_Release(
1608 saxlocator
*This
= impl_from_ISAXLocator( iface
);
1611 TRACE("%p\n", This
);
1613 ref
= InterlockedDecrement( &This
->ref
);
1616 SysFreeString(This
->publicId
);
1617 SysFreeString(This
->systemId
);
1618 heap_free(This
->nsStack
);
1620 ISAXXMLReader_Release(&This
->saxreader
->ISAXXMLReader_iface
);
1627 /*** ISAXLocator methods ***/
1628 static HRESULT WINAPI
isaxlocator_getColumnNumber(
1632 saxlocator
*This
= impl_from_ISAXLocator( iface
);
1634 *pnColumn
= This
->column
;
1638 static HRESULT WINAPI
isaxlocator_getLineNumber(
1642 saxlocator
*This
= impl_from_ISAXLocator( iface
);
1644 *pnLine
= This
->line
;
1648 static HRESULT WINAPI
isaxlocator_getPublicId(
1650 const WCHAR
** ppwchPublicId
)
1653 saxlocator
*This
= impl_from_ISAXLocator( iface
);
1655 SysFreeString(This
->publicId
);
1657 publicId
= bstr_from_xmlChar(xmlSAX2GetPublicId(This
->pParserCtxt
));
1658 if(SysStringLen(publicId
))
1659 This
->publicId
= (WCHAR
*)&publicId
;
1662 SysFreeString(publicId
);
1663 This
->publicId
= NULL
;
1666 *ppwchPublicId
= This
->publicId
;
1670 static HRESULT WINAPI
isaxlocator_getSystemId(
1672 const WCHAR
** ppwchSystemId
)
1675 saxlocator
*This
= impl_from_ISAXLocator( iface
);
1677 SysFreeString(This
->systemId
);
1679 systemId
= bstr_from_xmlChar(xmlSAX2GetSystemId(This
->pParserCtxt
));
1680 if(SysStringLen(systemId
))
1681 This
->systemId
= (WCHAR
*)&systemId
;
1684 SysFreeString(systemId
);
1685 This
->systemId
= NULL
;
1688 *ppwchSystemId
= This
->systemId
;
1692 static const struct ISAXLocatorVtbl isaxlocator_vtbl
=
1694 isaxlocator_QueryInterface
,
1696 isaxlocator_Release
,
1697 isaxlocator_getColumnNumber
,
1698 isaxlocator_getLineNumber
,
1699 isaxlocator_getPublicId
,
1700 isaxlocator_getSystemId
1703 static HRESULT
SAXLocator_create(saxreader
*reader
, saxlocator
**ppsaxlocator
, BOOL vbInterface
)
1705 saxlocator
*locator
;
1707 locator
= heap_alloc( sizeof (*locator
) );
1709 return E_OUTOFMEMORY
;
1711 locator
->IVBSAXLocator_iface
.lpVtbl
= &ivbsaxlocator_vtbl
;
1712 locator
->ISAXLocator_iface
.lpVtbl
= &isaxlocator_vtbl
;
1714 locator
->vbInterface
= vbInterface
;
1716 locator
->saxreader
= reader
;
1717 ISAXXMLReader_AddRef(&reader
->ISAXXMLReader_iface
);
1719 locator
->pParserCtxt
= NULL
;
1720 locator
->publicId
= NULL
;
1721 locator
->systemId
= NULL
;
1722 locator
->lastCur
= NULL
;
1724 locator
->column
= 0;
1725 locator
->ret
= S_OK
;
1726 locator
->nsStackSize
= 8;
1727 locator
->nsStackLast
= 0;
1728 locator
->nsStack
= heap_alloc(sizeof(int)*locator
->nsStackSize
);
1729 if(!locator
->nsStack
)
1731 ISAXXMLReader_Release(&reader
->ISAXXMLReader_iface
);
1733 return E_OUTOFMEMORY
;
1736 *ppsaxlocator
= locator
;
1738 TRACE("returning %p\n", *ppsaxlocator
);
1743 /*** SAXXMLReader internal functions ***/
1744 static HRESULT
internal_parseBuffer(saxreader
*This
, const char *buffer
, int size
, BOOL vbInterface
)
1746 xmlCharEncoding encoding
= XML_CHAR_ENCODING_NONE
;
1747 xmlChar
*enc_name
= NULL
;
1748 saxlocator
*locator
;
1751 hr
= SAXLocator_create(This
, &locator
, vbInterface
);
1757 const unsigned char *buff
= (unsigned char*)buffer
;
1759 encoding
= xmlDetectCharEncoding((xmlChar
*)buffer
, 4);
1760 enc_name
= (xmlChar
*)xmlGetCharEncodingName(encoding
);
1761 TRACE("detected encoding: %s\n", enc_name
);
1762 /* skip BOM, parser won't switch encodings and so won't skip it on its own */
1763 if ((encoding
== XML_CHAR_ENCODING_UTF8
) &&
1764 buff
[0] == 0xEF && buff
[1] == 0xBB && buff
[2] == 0xBF)
1771 locator
->pParserCtxt
= xmlCreateMemoryParserCtxt(buffer
, size
);
1772 if(!locator
->pParserCtxt
)
1774 ISAXLocator_Release(&locator
->ISAXLocator_iface
);
1778 if (encoding
== XML_CHAR_ENCODING_UTF8
)
1779 locator
->pParserCtxt
->encoding
= xmlStrdup(enc_name
);
1781 xmlFree(locator
->pParserCtxt
->sax
);
1782 locator
->pParserCtxt
->sax
= &locator
->saxreader
->sax
;
1783 locator
->pParserCtxt
->userData
= locator
;
1785 This
->isParsing
= TRUE
;
1786 if(xmlParseDocument(locator
->pParserCtxt
) == -1) hr
= E_FAIL
;
1787 else hr
= locator
->ret
;
1788 This
->isParsing
= FALSE
;
1790 if(locator
->pParserCtxt
)
1792 locator
->pParserCtxt
->sax
= NULL
;
1793 xmlFreeParserCtxt(locator
->pParserCtxt
);
1794 locator
->pParserCtxt
= NULL
;
1797 ISAXLocator_Release(&locator
->ISAXLocator_iface
);
1801 static HRESULT
internal_parseStream(saxreader
*This
, IStream
*stream
, BOOL vbInterface
)
1803 saxlocator
*locator
;
1808 hr
= IStream_Read(stream
, data
, sizeof(data
), &dataRead
);
1812 hr
= SAXLocator_create(This
, &locator
, vbInterface
);
1816 locator
->pParserCtxt
= xmlCreatePushParserCtxt(
1817 &locator
->saxreader
->sax
, locator
,
1818 data
, dataRead
, NULL
);
1819 if(!locator
->pParserCtxt
)
1821 ISAXLocator_Release(&locator
->ISAXLocator_iface
);
1825 This
->isParsing
= TRUE
;
1828 hr
= IStream_Read(stream
, data
, sizeof(data
), &dataRead
);
1832 if(xmlParseChunk(locator
->pParserCtxt
, data
, dataRead
, 0) != XML_ERR_OK
) hr
= E_FAIL
;
1833 else hr
= locator
->ret
;
1835 if(hr
!= S_OK
) break;
1837 if(dataRead
!= sizeof(data
))
1839 if(xmlParseChunk(locator
->pParserCtxt
, data
, 0, 1) != XML_ERR_OK
) hr
= E_FAIL
;
1840 else hr
= locator
->ret
;
1845 This
->isParsing
= FALSE
;
1847 xmlFreeParserCtxt(locator
->pParserCtxt
);
1848 locator
->pParserCtxt
= NULL
;
1849 ISAXLocator_Release(&locator
->ISAXLocator_iface
);
1853 static HRESULT
internal_getEntityResolver(
1855 void *pEntityResolver
,
1858 FIXME("(%p)->(%p) stub\n", This
, pEntityResolver
);
1862 static HRESULT
internal_putEntityResolver(
1864 void *pEntityResolver
,
1867 FIXME("(%p)->(%p) stub\n", This
, pEntityResolver
);
1871 static HRESULT
internal_getContentHandler(
1873 void *pContentHandler
,
1876 TRACE("(%p)->(%p)\n", This
, pContentHandler
);
1877 if(pContentHandler
== NULL
)
1879 if((vbInterface
&& This
->vbcontentHandler
)
1880 || (!vbInterface
&& This
->contentHandler
))
1883 IVBSAXContentHandler_AddRef(This
->vbcontentHandler
);
1885 ISAXContentHandler_AddRef(This
->contentHandler
);
1887 if(vbInterface
) *(IVBSAXContentHandler
**)pContentHandler
=
1888 This
->vbcontentHandler
;
1889 else *(ISAXContentHandler
**)pContentHandler
= This
->contentHandler
;
1894 static HRESULT
internal_putContentHandler(
1896 void *contentHandler
,
1899 TRACE("(%p)->(%p)\n", This
, contentHandler
);
1903 IVBSAXContentHandler_AddRef((IVBSAXContentHandler
*)contentHandler
);
1905 ISAXContentHandler_AddRef((ISAXContentHandler
*)contentHandler
);
1907 if((vbInterface
&& This
->vbcontentHandler
)
1908 || (!vbInterface
&& This
->contentHandler
))
1911 IVBSAXContentHandler_Release(This
->vbcontentHandler
);
1913 ISAXContentHandler_Release(This
->contentHandler
);
1916 This
->vbcontentHandler
= contentHandler
;
1918 This
->contentHandler
= contentHandler
;
1923 static HRESULT
internal_getDTDHandler(
1928 FIXME("(%p)->(%p) stub\n", This
, pDTDHandler
);
1932 static HRESULT
internal_putDTDHandler(
1937 FIXME("(%p)->(%p) stub\n", This
, pDTDHandler
);
1941 static HRESULT
internal_getErrorHandler(
1943 void *pErrorHandler
,
1946 TRACE("(%p)->(%p)\n", This
, pErrorHandler
);
1947 if(pErrorHandler
== NULL
)
1950 if(vbInterface
&& This
->vberrorHandler
)
1951 IVBSAXErrorHandler_AddRef(This
->vberrorHandler
);
1952 else if(!vbInterface
&& This
->errorHandler
)
1953 ISAXErrorHandler_AddRef(This
->errorHandler
);
1956 *(IVBSAXErrorHandler
**)pErrorHandler
= This
->vberrorHandler
;
1958 *(ISAXErrorHandler
**)pErrorHandler
= This
->errorHandler
;
1964 static HRESULT
internal_putErrorHandler(
1969 TRACE("(%p)->(%p)\n", This
, errorHandler
);
1973 IVBSAXErrorHandler_AddRef((IVBSAXErrorHandler
*)errorHandler
);
1975 ISAXErrorHandler_AddRef((ISAXErrorHandler
*)errorHandler
);
1978 if(vbInterface
&& This
->vberrorHandler
)
1979 IVBSAXErrorHandler_Release(This
->vberrorHandler
);
1980 else if(!vbInterface
&& This
->errorHandler
)
1981 ISAXErrorHandler_Release(This
->errorHandler
);
1984 This
->vberrorHandler
= errorHandler
;
1986 This
->errorHandler
= errorHandler
;
1992 static HRESULT
internal_parse(
1999 TRACE("(%p)->(%s)\n", This
, debugstr_variant(&varInput
));
2002 switch(V_VT(&varInput
))
2005 hr
= internal_parseBuffer(This
, (const char*)V_BSTR(&varInput
),
2006 SysStringByteLen(V_BSTR(&varInput
)), vbInterface
);
2008 case VT_ARRAY
|VT_UI1
: {
2010 LONG lBound
, uBound
;
2013 hr
= SafeArrayGetLBound(V_ARRAY(&varInput
), 1, &lBound
);
2014 if(hr
!= S_OK
) break;
2015 hr
= SafeArrayGetUBound(V_ARRAY(&varInput
), 1, &uBound
);
2016 if(hr
!= S_OK
) break;
2017 dataRead
= (uBound
-lBound
)*SafeArrayGetElemsize(V_ARRAY(&varInput
));
2018 hr
= SafeArrayAccessData(V_ARRAY(&varInput
), &pSAData
);
2019 if(hr
!= S_OK
) break;
2020 hr
= internal_parseBuffer(This
, pSAData
, dataRead
, vbInterface
);
2021 SafeArrayUnaccessData(V_ARRAY(&varInput
));
2026 IPersistStream
*persistStream
;
2027 IStream
*stream
= NULL
;
2028 IXMLDOMDocument
*xmlDoc
;
2030 if(IUnknown_QueryInterface(V_UNKNOWN(&varInput
),
2031 &IID_IXMLDOMDocument
, (void**)&xmlDoc
) == S_OK
)
2035 IXMLDOMDocument_get_xml(xmlDoc
, &bstrData
);
2036 hr
= internal_parseBuffer(This
, (const char*)bstrData
,
2037 SysStringByteLen(bstrData
), vbInterface
);
2038 IXMLDOMDocument_Release(xmlDoc
);
2039 SysFreeString(bstrData
);
2043 if(IUnknown_QueryInterface(V_UNKNOWN(&varInput
),
2044 &IID_IPersistStream
, (void**)&persistStream
) == S_OK
)
2046 hr
= CreateStreamOnHGlobal(NULL
, TRUE
, &stream
);
2049 IPersistStream_Release(persistStream
);
2053 hr
= IPersistStream_Save(persistStream
, stream
, TRUE
);
2054 IPersistStream_Release(persistStream
);
2057 IStream_Release(stream
);
2061 if(stream
|| IUnknown_QueryInterface(V_UNKNOWN(&varInput
),
2062 &IID_IStream
, (void**)&stream
) == S_OK
)
2064 hr
= internal_parseStream(This
, stream
, vbInterface
);
2065 IStream_Release(stream
);
2070 WARN("vt %d not implemented\n", V_VT(&varInput
));
2077 static HRESULT
internal_vbonDataAvailable(void *obj
, char *ptr
, DWORD len
)
2079 saxreader
*This
= obj
;
2081 return internal_parseBuffer(This
, ptr
, len
, TRUE
);
2084 static HRESULT
internal_onDataAvailable(void *obj
, char *ptr
, DWORD len
)
2086 saxreader
*This
= obj
;
2088 return internal_parseBuffer(This
, ptr
, len
, FALSE
);
2091 static HRESULT
internal_parseURL(
2099 TRACE("(%p)->(%s)\n", This
, debugstr_w(url
));
2101 if(vbInterface
) hr
= bind_url(url
, internal_vbonDataAvailable
, This
, &bsc
);
2102 else hr
= bind_url(url
, internal_onDataAvailable
, This
, &bsc
);
2112 static HRESULT
internal_putProperty(
2118 static const WCHAR wszCharset
[] = {
2119 'c','h','a','r','s','e','t',0
2121 static const WCHAR wszDeclarationHandler
[] = {
2122 'h','t','t','p',':','/','/','x','m','l','.','o','r','g','/',
2123 's','a','x','/','p','r','o','p','e','r','t','i','e','s','/',
2124 'd','e','c','l','a','r','a','t','i','o','n',
2125 '-','h','a','n','d','l','e','r',0
2127 static const WCHAR wszDomNode
[] = {
2128 'h','t','t','p',':','/','/','x','m','l','.','o','r','g','/',
2129 's','a','x','/','p','r','o','p','e','r','t','i','e','s','/',
2130 'd','o','m','-','n','o','d','e',0
2132 static const WCHAR wszInputSource
[] = {
2133 'i','n','p','u','t','-','s','o','u','r','c','e',0
2135 static const WCHAR wszLexicalHandler
[] = {
2136 'h','t','t','p',':','/','/','x','m','l','.','o','r','g','/',
2137 's','a','x','/','p','r','o','p','e','r','t','i','e','s','/',
2138 'l','e','x','i','c','a','l','-','h','a','n','d','l','e','r',0
2140 static const WCHAR wszMaxElementDepth
[] = {
2141 'm','a','x','-','e','l','e','m','e','n','t','-','d','e','p','t','h',0
2143 static const WCHAR wszMaxXMLSize
[] = {
2144 'm','a','x','-','x','m','l','-','s','i','z','e',0
2146 static const WCHAR wszSchemaDeclarationHandler
[] = {
2147 's','c','h','e','m','a','-',
2148 'd','e','c','l','a','r','a','t','i','o','n','-',
2149 'h','a','n','d','l','e','r',0
2151 static const WCHAR wszXMLDeclEncoding
[] = {
2152 'x','m','l','d','e','c','l','-','e','n','c','o','d','i','n','g',0
2154 static const WCHAR wszXMLDeclStandalone
[] = {
2155 'x','m','l','d','e','c','l',
2156 '-','s','t','a','n','d','a','l','o','n','e',0
2158 static const WCHAR wszXMLDeclVersion
[] = {
2159 'x','m','l','d','e','c','l','-','v','e','r','s','i','o','n',0
2162 TRACE("(%p)->(%s %s)\n", This
, debugstr_w(pProp
), debugstr_variant(&value
));
2164 if(!memcmp(pProp
, wszDeclarationHandler
, sizeof(wszDeclarationHandler
)))
2166 if(This
->isParsing
) return E_FAIL
;
2168 if(V_UNKNOWN(&value
))
2171 IVBSAXDeclHandler_AddRef((IVBSAXDeclHandler
*)V_UNKNOWN(&value
));
2173 ISAXDeclHandler_AddRef((ISAXDeclHandler
*)V_UNKNOWN(&value
));
2175 if((vbInterface
&& This
->vbdeclHandler
)
2176 || (!vbInterface
&& This
->declHandler
))
2179 IVBSAXDeclHandler_Release(This
->vbdeclHandler
);
2181 ISAXDeclHandler_Release(This
->declHandler
);
2184 This
->vbdeclHandler
= (IVBSAXDeclHandler
*)V_UNKNOWN(&value
);
2186 This
->declHandler
= (ISAXDeclHandler
*)V_UNKNOWN(&value
);
2190 if(!memcmp(pProp
, wszLexicalHandler
, sizeof(wszLexicalHandler
)))
2192 if(This
->isParsing
) return E_FAIL
;
2194 if(V_UNKNOWN(&value
))
2197 IVBSAXLexicalHandler_AddRef(
2198 (IVBSAXLexicalHandler
*)V_UNKNOWN(&value
));
2200 ISAXLexicalHandler_AddRef(
2201 (ISAXLexicalHandler
*)V_UNKNOWN(&value
));
2203 if((vbInterface
&& This
->vblexicalHandler
)
2204 || (!vbInterface
&& This
->lexicalHandler
))
2207 IVBSAXLexicalHandler_Release(This
->vblexicalHandler
);
2209 ISAXLexicalHandler_Release(This
->lexicalHandler
);
2212 This
->vblexicalHandler
= (IVBSAXLexicalHandler
*)V_UNKNOWN(&value
);
2214 This
->lexicalHandler
= (ISAXLexicalHandler
*)V_UNKNOWN(&value
);
2218 FIXME("(%p)->(%s): unsupported property\n", This
, debugstr_w(pProp
));
2220 if(!memcmp(pProp
, wszCharset
, sizeof(wszCharset
)))
2223 if(!memcmp(pProp
, wszDomNode
, sizeof(wszDomNode
)))
2226 if(!memcmp(pProp
, wszInputSource
, sizeof(wszInputSource
)))
2229 if(!memcmp(pProp
, wszMaxElementDepth
, sizeof(wszMaxElementDepth
)))
2232 if(!memcmp(pProp
, wszMaxXMLSize
, sizeof(wszMaxXMLSize
)))
2235 if(!memcmp(pProp
, wszSchemaDeclarationHandler
,
2236 sizeof(wszSchemaDeclarationHandler
)))
2239 if(!memcmp(pProp
, wszXMLDeclEncoding
, sizeof(wszXMLDeclEncoding
)))
2242 if(!memcmp(pProp
, wszXMLDeclStandalone
, sizeof(wszXMLDeclStandalone
)))
2245 if(!memcmp(pProp
, wszXMLDeclVersion
, sizeof(wszXMLDeclVersion
)))
2248 return E_INVALIDARG
;
2251 /*** IVBSAXXMLReader interface ***/
2252 /*** IUnknown methods ***/
2253 static HRESULT WINAPI
saxxmlreader_QueryInterface(IVBSAXXMLReader
* iface
, REFIID riid
, void **ppvObject
)
2255 saxreader
*This
= impl_from_IVBSAXXMLReader( iface
);
2257 TRACE("%p %s %p\n", This
, debugstr_guid( riid
), ppvObject
);
2261 if ( IsEqualGUID( riid
, &IID_IUnknown
) ||
2262 IsEqualGUID( riid
, &IID_IDispatch
) ||
2263 IsEqualGUID( riid
, &IID_IVBSAXXMLReader
))
2267 else if( IsEqualGUID( riid
, &IID_ISAXXMLReader
))
2269 *ppvObject
= &This
->ISAXXMLReader_iface
;
2273 FIXME("interface %s not implemented\n", debugstr_guid(riid
));
2274 return E_NOINTERFACE
;
2277 IVBSAXXMLReader_AddRef( iface
);
2282 static ULONG WINAPI
saxxmlreader_AddRef(IVBSAXXMLReader
* iface
)
2284 saxreader
*This
= impl_from_IVBSAXXMLReader( iface
);
2285 TRACE("%p\n", This
);
2286 return InterlockedIncrement( &This
->ref
);
2289 static ULONG WINAPI
saxxmlreader_Release(
2290 IVBSAXXMLReader
* iface
)
2292 saxreader
*This
= impl_from_IVBSAXXMLReader( iface
);
2295 TRACE("%p\n", This
);
2297 ref
= InterlockedDecrement( &This
->ref
);
2300 if(This
->contentHandler
)
2301 ISAXContentHandler_Release(This
->contentHandler
);
2303 if(This
->vbcontentHandler
)
2304 IVBSAXContentHandler_Release(This
->vbcontentHandler
);
2306 if(This
->errorHandler
)
2307 ISAXErrorHandler_Release(This
->errorHandler
);
2309 if(This
->vberrorHandler
)
2310 IVBSAXErrorHandler_Release(This
->vberrorHandler
);
2312 if(This
->lexicalHandler
)
2313 ISAXLexicalHandler_Release(This
->lexicalHandler
);
2315 if(This
->vblexicalHandler
)
2316 IVBSAXLexicalHandler_Release(This
->vblexicalHandler
);
2318 if(This
->declHandler
)
2319 ISAXDeclHandler_Release(This
->declHandler
);
2321 if(This
->vbdeclHandler
)
2322 IVBSAXDeclHandler_Release(This
->vbdeclHandler
);
2330 static HRESULT WINAPI
saxxmlreader_GetTypeInfoCount( IVBSAXXMLReader
*iface
, UINT
* pctinfo
)
2332 saxreader
*This
= impl_from_IVBSAXXMLReader( iface
);
2334 TRACE("(%p)->(%p)\n", This
, pctinfo
);
2341 static HRESULT WINAPI
saxxmlreader_GetTypeInfo(
2342 IVBSAXXMLReader
*iface
,
2343 UINT iTInfo
, LCID lcid
, ITypeInfo
** ppTInfo
)
2345 saxreader
*This
= impl_from_IVBSAXXMLReader( iface
);
2348 TRACE("(%p)->(%u %u %p)\n", This
, iTInfo
, lcid
, ppTInfo
);
2350 hr
= get_typeinfo(IVBSAXXMLReader_tid
, ppTInfo
);
2355 static HRESULT WINAPI
saxxmlreader_GetIDsOfNames(
2356 IVBSAXXMLReader
*iface
,
2358 LPOLESTR
* rgszNames
,
2363 saxreader
*This
= impl_from_IVBSAXXMLReader( iface
);
2364 ITypeInfo
*typeinfo
;
2367 TRACE("(%p)->(%s %p %u %u %p)\n", This
, debugstr_guid(riid
), rgszNames
, cNames
,
2370 if(!rgszNames
|| cNames
== 0 || !rgDispId
)
2371 return E_INVALIDARG
;
2373 hr
= get_typeinfo(IVBSAXXMLReader_tid
, &typeinfo
);
2376 hr
= ITypeInfo_GetIDsOfNames(typeinfo
, rgszNames
, cNames
, rgDispId
);
2377 ITypeInfo_Release(typeinfo
);
2383 static HRESULT WINAPI
saxxmlreader_Invoke(
2384 IVBSAXXMLReader
*iface
,
2385 DISPID dispIdMember
,
2389 DISPPARAMS
* pDispParams
,
2390 VARIANT
* pVarResult
,
2391 EXCEPINFO
* pExcepInfo
,
2394 saxreader
*This
= impl_from_IVBSAXXMLReader( iface
);
2395 ITypeInfo
*typeinfo
;
2398 TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This
, dispIdMember
, debugstr_guid(riid
),
2399 lcid
, wFlags
, pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
2401 hr
= get_typeinfo(IVBSAXXMLReader_tid
, &typeinfo
);
2404 hr
= ITypeInfo_Invoke(typeinfo
, &This
->IVBSAXXMLReader_iface
, dispIdMember
, wFlags
,
2405 pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
2406 ITypeInfo_Release(typeinfo
);
2412 /*** IVBSAXXMLReader methods ***/
2413 static HRESULT WINAPI
saxxmlreader_getFeature(
2414 IVBSAXXMLReader
* iface
,
2415 const WCHAR
*pFeature
,
2416 VARIANT_BOOL
*pValue
)
2418 saxreader
*This
= impl_from_IVBSAXXMLReader( iface
);
2420 FIXME("(%p)->(%s %p) stub\n", This
, debugstr_w(pFeature
), pValue
);
2424 static HRESULT WINAPI
saxxmlreader_putFeature(
2425 IVBSAXXMLReader
* iface
,
2426 const WCHAR
*pFeature
,
2427 VARIANT_BOOL vfValue
)
2429 saxreader
*This
= impl_from_IVBSAXXMLReader( iface
);
2431 FIXME("(%p)->(%s %x) stub\n", This
, debugstr_w(pFeature
), vfValue
);
2435 static HRESULT WINAPI
saxxmlreader_getProperty(
2436 IVBSAXXMLReader
* iface
,
2440 saxreader
*This
= impl_from_IVBSAXXMLReader( iface
);
2442 FIXME("(%p)->(%s %p) stub\n", This
, debugstr_w(pProp
), pValue
);
2446 static HRESULT WINAPI
saxxmlreader_putProperty(
2447 IVBSAXXMLReader
* iface
,
2451 saxreader
*This
= impl_from_IVBSAXXMLReader( iface
);
2452 return internal_putProperty(This
, pProp
, value
, TRUE
);
2455 static HRESULT WINAPI
saxxmlreader_get_entityResolver(
2456 IVBSAXXMLReader
* iface
,
2457 IVBSAXEntityResolver
**pEntityResolver
)
2459 saxreader
*This
= impl_from_IVBSAXXMLReader( iface
);
2460 return internal_getEntityResolver(This
, pEntityResolver
, TRUE
);
2463 static HRESULT WINAPI
saxxmlreader_put_entityResolver(
2464 IVBSAXXMLReader
* iface
,
2465 IVBSAXEntityResolver
*pEntityResolver
)
2467 saxreader
*This
= impl_from_IVBSAXXMLReader( iface
);
2468 return internal_putEntityResolver(This
, pEntityResolver
, TRUE
);
2471 static HRESULT WINAPI
saxxmlreader_get_contentHandler(
2472 IVBSAXXMLReader
* iface
,
2473 IVBSAXContentHandler
**ppContentHandler
)
2475 saxreader
*This
= impl_from_IVBSAXXMLReader( iface
);
2476 return internal_getContentHandler(This
, ppContentHandler
, TRUE
);
2479 static HRESULT WINAPI
saxxmlreader_put_contentHandler(
2480 IVBSAXXMLReader
* iface
,
2481 IVBSAXContentHandler
*contentHandler
)
2483 saxreader
*This
= impl_from_IVBSAXXMLReader( iface
);
2484 return internal_putContentHandler(This
, contentHandler
, TRUE
);
2487 static HRESULT WINAPI
saxxmlreader_get_dtdHandler(
2488 IVBSAXXMLReader
* iface
,
2489 IVBSAXDTDHandler
**pDTDHandler
)
2491 saxreader
*This
= impl_from_IVBSAXXMLReader( iface
);
2492 return internal_getDTDHandler(This
, pDTDHandler
, TRUE
);
2495 static HRESULT WINAPI
saxxmlreader_put_dtdHandler(
2496 IVBSAXXMLReader
* iface
,
2497 IVBSAXDTDHandler
*pDTDHandler
)
2499 saxreader
*This
= impl_from_IVBSAXXMLReader( iface
);
2500 return internal_putDTDHandler(This
, pDTDHandler
, TRUE
);
2503 static HRESULT WINAPI
saxxmlreader_get_errorHandler(
2504 IVBSAXXMLReader
* iface
,
2505 IVBSAXErrorHandler
**pErrorHandler
)
2507 saxreader
*This
= impl_from_IVBSAXXMLReader( iface
);
2508 return internal_getErrorHandler(This
, pErrorHandler
, TRUE
);
2511 static HRESULT WINAPI
saxxmlreader_put_errorHandler(
2512 IVBSAXXMLReader
* iface
,
2513 IVBSAXErrorHandler
*errorHandler
)
2515 saxreader
*This
= impl_from_IVBSAXXMLReader( iface
);
2516 return internal_putErrorHandler(This
, errorHandler
, TRUE
);
2519 static HRESULT WINAPI
saxxmlreader_get_baseURL(
2520 IVBSAXXMLReader
* iface
,
2521 const WCHAR
**pBaseUrl
)
2523 saxreader
*This
= impl_from_IVBSAXXMLReader( iface
);
2525 FIXME("(%p)->(%p) stub\n", This
, pBaseUrl
);
2529 static HRESULT WINAPI
saxxmlreader_put_baseURL(
2530 IVBSAXXMLReader
* iface
,
2531 const WCHAR
*pBaseUrl
)
2533 saxreader
*This
= impl_from_IVBSAXXMLReader( iface
);
2535 FIXME("(%p)->(%s) stub\n", This
, debugstr_w(pBaseUrl
));
2539 static HRESULT WINAPI
saxxmlreader_get_secureBaseURL(
2540 IVBSAXXMLReader
* iface
,
2541 const WCHAR
**pSecureBaseUrl
)
2543 saxreader
*This
= impl_from_IVBSAXXMLReader( iface
);
2545 FIXME("(%p)->(%p) stub\n", This
, pSecureBaseUrl
);
2550 static HRESULT WINAPI
saxxmlreader_put_secureBaseURL(
2551 IVBSAXXMLReader
* iface
,
2552 const WCHAR
*secureBaseUrl
)
2554 saxreader
*This
= impl_from_IVBSAXXMLReader( iface
);
2556 FIXME("(%p)->(%s) stub\n", This
, debugstr_w(secureBaseUrl
));
2560 static HRESULT WINAPI
saxxmlreader_parse(
2561 IVBSAXXMLReader
* iface
,
2564 saxreader
*This
= impl_from_IVBSAXXMLReader( iface
);
2565 return internal_parse(This
, varInput
, TRUE
);
2568 static HRESULT WINAPI
saxxmlreader_parseURL(
2569 IVBSAXXMLReader
* iface
,
2572 saxreader
*This
= impl_from_IVBSAXXMLReader( iface
);
2573 return internal_parseURL(This
, url
, TRUE
);
2576 static const struct IVBSAXXMLReaderVtbl saxreader_vtbl
=
2578 saxxmlreader_QueryInterface
,
2579 saxxmlreader_AddRef
,
2580 saxxmlreader_Release
,
2581 saxxmlreader_GetTypeInfoCount
,
2582 saxxmlreader_GetTypeInfo
,
2583 saxxmlreader_GetIDsOfNames
,
2584 saxxmlreader_Invoke
,
2585 saxxmlreader_getFeature
,
2586 saxxmlreader_putFeature
,
2587 saxxmlreader_getProperty
,
2588 saxxmlreader_putProperty
,
2589 saxxmlreader_get_entityResolver
,
2590 saxxmlreader_put_entityResolver
,
2591 saxxmlreader_get_contentHandler
,
2592 saxxmlreader_put_contentHandler
,
2593 saxxmlreader_get_dtdHandler
,
2594 saxxmlreader_put_dtdHandler
,
2595 saxxmlreader_get_errorHandler
,
2596 saxxmlreader_put_errorHandler
,
2597 saxxmlreader_get_baseURL
,
2598 saxxmlreader_put_baseURL
,
2599 saxxmlreader_get_secureBaseURL
,
2600 saxxmlreader_put_secureBaseURL
,
2602 saxxmlreader_parseURL
2605 /*** ISAXXMLReader interface ***/
2606 /*** IUnknown methods ***/
2607 static HRESULT WINAPI
isaxxmlreader_QueryInterface(ISAXXMLReader
* iface
, REFIID riid
, void **ppvObject
)
2609 saxreader
*This
= impl_from_ISAXXMLReader( iface
);
2610 return saxxmlreader_QueryInterface(&This
->IVBSAXXMLReader_iface
, riid
, ppvObject
);
2613 static ULONG WINAPI
isaxxmlreader_AddRef(ISAXXMLReader
* iface
)
2615 saxreader
*This
= impl_from_ISAXXMLReader( iface
);
2616 return saxxmlreader_AddRef(&This
->IVBSAXXMLReader_iface
);
2619 static ULONG WINAPI
isaxxmlreader_Release(ISAXXMLReader
* iface
)
2621 saxreader
*This
= impl_from_ISAXXMLReader( iface
);
2622 return saxxmlreader_Release(&This
->IVBSAXXMLReader_iface
);
2625 /*** ISAXXMLReader methods ***/
2626 static HRESULT WINAPI
isaxxmlreader_getFeature(
2627 ISAXXMLReader
* iface
,
2628 const WCHAR
*pFeature
,
2629 VARIANT_BOOL
*pValue
)
2631 saxreader
*This
= impl_from_ISAXXMLReader( iface
);
2632 return IVBSAXXMLReader_getFeature(&This
->IVBSAXXMLReader_iface
, pFeature
, pValue
);
2635 static HRESULT WINAPI
isaxxmlreader_putFeature(
2636 ISAXXMLReader
* iface
,
2637 const WCHAR
*pFeature
,
2638 VARIANT_BOOL vfValue
)
2640 saxreader
*This
= impl_from_ISAXXMLReader( iface
);
2641 return IVBSAXXMLReader_putFeature(&This
->IVBSAXXMLReader_iface
, pFeature
, vfValue
);
2644 static HRESULT WINAPI
isaxxmlreader_getProperty(
2645 ISAXXMLReader
* iface
,
2649 saxreader
*This
= impl_from_ISAXXMLReader( iface
);
2650 return IVBSAXXMLReader_getProperty(&This
->IVBSAXXMLReader_iface
, pProp
, pValue
);
2653 static HRESULT WINAPI
isaxxmlreader_putProperty(
2654 ISAXXMLReader
* iface
,
2658 saxreader
*This
= impl_from_ISAXXMLReader( iface
);
2659 return internal_putProperty(This
, pProp
, value
, FALSE
);
2662 static HRESULT WINAPI
isaxxmlreader_getEntityResolver(
2663 ISAXXMLReader
* iface
,
2664 ISAXEntityResolver
**ppEntityResolver
)
2666 saxreader
*This
= impl_from_ISAXXMLReader( iface
);
2667 return internal_getEntityResolver(This
, ppEntityResolver
, FALSE
);
2670 static HRESULT WINAPI
isaxxmlreader_putEntityResolver(
2671 ISAXXMLReader
* iface
,
2672 ISAXEntityResolver
*pEntityResolver
)
2674 saxreader
*This
= impl_from_ISAXXMLReader( iface
);
2675 return internal_putEntityResolver(This
, pEntityResolver
, FALSE
);
2678 static HRESULT WINAPI
isaxxmlreader_getContentHandler(
2679 ISAXXMLReader
* iface
,
2680 ISAXContentHandler
**pContentHandler
)
2682 saxreader
*This
= impl_from_ISAXXMLReader( iface
);
2683 return internal_getContentHandler(This
, pContentHandler
, FALSE
);
2686 static HRESULT WINAPI
isaxxmlreader_putContentHandler(
2687 ISAXXMLReader
* iface
,
2688 ISAXContentHandler
*contentHandler
)
2690 saxreader
*This
= impl_from_ISAXXMLReader( iface
);
2691 return internal_putContentHandler(This
, contentHandler
, FALSE
);
2694 static HRESULT WINAPI
isaxxmlreader_getDTDHandler(
2695 ISAXXMLReader
* iface
,
2696 ISAXDTDHandler
**pDTDHandler
)
2698 saxreader
*This
= impl_from_ISAXXMLReader( iface
);
2699 return internal_getDTDHandler(This
, pDTDHandler
, FALSE
);
2702 static HRESULT WINAPI
isaxxmlreader_putDTDHandler(
2703 ISAXXMLReader
* iface
,
2704 ISAXDTDHandler
*pDTDHandler
)
2706 saxreader
*This
= impl_from_ISAXXMLReader( iface
);
2707 return internal_putDTDHandler(This
, pDTDHandler
, FALSE
);
2710 static HRESULT WINAPI
isaxxmlreader_getErrorHandler(
2711 ISAXXMLReader
* iface
,
2712 ISAXErrorHandler
**pErrorHandler
)
2714 saxreader
*This
= impl_from_ISAXXMLReader( iface
);
2715 return internal_getErrorHandler(This
, pErrorHandler
, FALSE
);
2718 static HRESULT WINAPI
isaxxmlreader_putErrorHandler(
2719 ISAXXMLReader
* iface
,
2720 ISAXErrorHandler
*errorHandler
)
2722 saxreader
*This
= impl_from_ISAXXMLReader( iface
);
2723 return internal_putErrorHandler(This
, errorHandler
, FALSE
);
2726 static HRESULT WINAPI
isaxxmlreader_getBaseURL(
2727 ISAXXMLReader
* iface
,
2728 const WCHAR
**pBaseUrl
)
2730 saxreader
*This
= impl_from_ISAXXMLReader( iface
);
2731 return IVBSAXXMLReader_get_baseURL(&This
->IVBSAXXMLReader_iface
, pBaseUrl
);
2734 static HRESULT WINAPI
isaxxmlreader_putBaseURL(
2735 ISAXXMLReader
* iface
,
2736 const WCHAR
*pBaseUrl
)
2738 saxreader
*This
= impl_from_ISAXXMLReader( iface
);
2739 return IVBSAXXMLReader_put_baseURL(&This
->IVBSAXXMLReader_iface
, pBaseUrl
);
2742 static HRESULT WINAPI
isaxxmlreader_getSecureBaseURL(
2743 ISAXXMLReader
* iface
,
2744 const WCHAR
**pSecureBaseUrl
)
2746 saxreader
*This
= impl_from_ISAXXMLReader( iface
);
2747 return IVBSAXXMLReader_get_secureBaseURL(&This
->IVBSAXXMLReader_iface
, pSecureBaseUrl
);
2750 static HRESULT WINAPI
isaxxmlreader_putSecureBaseURL(
2751 ISAXXMLReader
* iface
,
2752 const WCHAR
*secureBaseUrl
)
2754 saxreader
*This
= impl_from_ISAXXMLReader( iface
);
2755 return IVBSAXXMLReader_put_secureBaseURL(&This
->IVBSAXXMLReader_iface
, secureBaseUrl
);
2758 static HRESULT WINAPI
isaxxmlreader_parse(
2759 ISAXXMLReader
* iface
,
2762 saxreader
*This
= impl_from_ISAXXMLReader( iface
);
2763 return internal_parse(This
, varInput
, FALSE
);
2766 static HRESULT WINAPI
isaxxmlreader_parseURL(
2767 ISAXXMLReader
* iface
,
2770 saxreader
*This
= impl_from_ISAXXMLReader( iface
);
2771 return internal_parseURL(This
, url
, FALSE
);
2774 static const struct ISAXXMLReaderVtbl isaxreader_vtbl
=
2776 isaxxmlreader_QueryInterface
,
2777 isaxxmlreader_AddRef
,
2778 isaxxmlreader_Release
,
2779 isaxxmlreader_getFeature
,
2780 isaxxmlreader_putFeature
,
2781 isaxxmlreader_getProperty
,
2782 isaxxmlreader_putProperty
,
2783 isaxxmlreader_getEntityResolver
,
2784 isaxxmlreader_putEntityResolver
,
2785 isaxxmlreader_getContentHandler
,
2786 isaxxmlreader_putContentHandler
,
2787 isaxxmlreader_getDTDHandler
,
2788 isaxxmlreader_putDTDHandler
,
2789 isaxxmlreader_getErrorHandler
,
2790 isaxxmlreader_putErrorHandler
,
2791 isaxxmlreader_getBaseURL
,
2792 isaxxmlreader_putBaseURL
,
2793 isaxxmlreader_getSecureBaseURL
,
2794 isaxxmlreader_putSecureBaseURL
,
2795 isaxxmlreader_parse
,
2796 isaxxmlreader_parseURL
2799 HRESULT
SAXXMLReader_create(IUnknown
*pUnkOuter
, LPVOID
*ppObj
)
2803 TRACE("(%p,%p)\n", pUnkOuter
, ppObj
);
2805 reader
= heap_alloc( sizeof (*reader
) );
2807 return E_OUTOFMEMORY
;
2809 reader
->IVBSAXXMLReader_iface
.lpVtbl
= &saxreader_vtbl
;
2810 reader
->ISAXXMLReader_iface
.lpVtbl
= &isaxreader_vtbl
;
2812 reader
->contentHandler
= NULL
;
2813 reader
->vbcontentHandler
= NULL
;
2814 reader
->errorHandler
= NULL
;
2815 reader
->vberrorHandler
= NULL
;
2816 reader
->lexicalHandler
= NULL
;
2817 reader
->vblexicalHandler
= NULL
;
2818 reader
->declHandler
= NULL
;
2819 reader
->vbdeclHandler
= NULL
;
2820 reader
->isParsing
= FALSE
;
2822 memset(&reader
->sax
, 0, sizeof(xmlSAXHandler
));
2823 reader
->sax
.initialized
= XML_SAX2_MAGIC
;
2824 reader
->sax
.startDocument
= libxmlStartDocument
;
2825 reader
->sax
.endDocument
= libxmlEndDocument
;
2826 reader
->sax
.startElementNs
= libxmlStartElementNS
;
2827 reader
->sax
.endElementNs
= libxmlEndElementNS
;
2828 reader
->sax
.characters
= libxmlCharacters
;
2829 reader
->sax
.setDocumentLocator
= libxmlSetDocumentLocator
;
2830 reader
->sax
.comment
= libxmlComment
;
2831 reader
->sax
.error
= libxmlFatalError
;
2832 reader
->sax
.fatalError
= libxmlFatalError
;
2833 reader
->sax
.cdataBlock
= libxmlCDataBlock
;
2835 *ppObj
= &reader
->IVBSAXXMLReader_iface
;
2837 TRACE("returning iface %p\n", *ppObj
);
2844 HRESULT
SAXXMLReader_create(IUnknown
*pUnkOuter
, LPVOID
*ppObj
)
2846 MESSAGE("This program tried to use a SAX XML Reader object, but\n"
2847 "libxml2 support was not present at compile time.\n");