2 * SAX Reader implementation
4 * Copyright 2008 Alistair Leslie-Hughes
5 * Copyright 2008 Piotr Caban
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
38 #include "wine/debug.h"
40 #include "msxml_private.h"
42 WINE_DEFAULT_DEBUG_CHANNEL(msxml
);
46 #include <libxml/SAX2.h>
47 #include <libxml/parserInternals.h>
49 typedef struct _saxreader
51 const struct IVBSAXXMLReaderVtbl
*lpVBSAXXMLReaderVtbl
;
52 const struct ISAXXMLReaderVtbl
*lpSAXXMLReaderVtbl
;
54 struct ISAXContentHandler
*contentHandler
;
55 struct IVBSAXContentHandler
*vbcontentHandler
;
56 struct ISAXErrorHandler
*errorHandler
;
57 struct IVBSAXErrorHandler
*vberrorHandler
;
58 struct ISAXLexicalHandler
*lexicalHandler
;
59 struct IVBSAXLexicalHandler
*vblexicalHandler
;
60 struct ISAXDeclHandler
*declHandler
;
61 struct IVBSAXDeclHandler
*vbdeclHandler
;
66 typedef struct _saxlocator
68 const struct IVBSAXLocatorVtbl
*lpVBSAXLocatorVtbl
;
69 const struct ISAXLocatorVtbl
*lpSAXLocatorVtbl
;
73 xmlParserCtxtPtr pParserCtxt
;
87 typedef struct _saxattributes
89 const struct IVBSAXAttributesVtbl
*lpVBSAXAttributesVtbl
;
90 const struct ISAXAttributesVtbl
*lpSAXAttributesVtbl
;
99 static inline saxreader
*impl_from_IVBSAXXMLReader( IVBSAXXMLReader
*iface
)
101 return (saxreader
*)((char*)iface
- FIELD_OFFSET(saxreader
, lpVBSAXXMLReaderVtbl
));
104 static inline saxreader
*impl_from_ISAXXMLReader( ISAXXMLReader
*iface
)
106 return (saxreader
*)((char*)iface
- FIELD_OFFSET(saxreader
, lpSAXXMLReaderVtbl
));
109 static inline saxlocator
*impl_from_IVBSAXLocator( IVBSAXLocator
*iface
)
111 return (saxlocator
*)((char*)iface
- FIELD_OFFSET(saxlocator
, lpVBSAXLocatorVtbl
));
114 static inline saxlocator
*impl_from_ISAXLocator( ISAXLocator
*iface
)
116 return (saxlocator
*)((char*)iface
- FIELD_OFFSET(saxlocator
, lpSAXLocatorVtbl
));
119 static inline saxattributes
*impl_from_IVBSAXAttributes( IVBSAXAttributes
*iface
)
121 return (saxattributes
*)((char*)iface
- FIELD_OFFSET(saxattributes
, lpVBSAXAttributesVtbl
));
124 static inline saxattributes
*impl_from_ISAXAttributes( ISAXAttributes
*iface
)
126 return (saxattributes
*)((char*)iface
- FIELD_OFFSET(saxattributes
, lpSAXAttributesVtbl
));
129 static inline BOOL
has_content_handler(const saxlocator
*locator
)
131 return (locator
->vbInterface
&& locator
->saxreader
->vbcontentHandler
) ||
132 (!locator
->vbInterface
&& locator
->saxreader
->contentHandler
);
135 static HRESULT
namespacePush(saxlocator
*locator
, int ns
)
137 if(locator
->nsStackLast
>=locator
->nsStackSize
)
141 new_stack
= HeapReAlloc(GetProcessHeap(), 0,
142 locator
->nsStack
, locator
->nsStackSize
*2);
143 if(!new_stack
) return E_OUTOFMEMORY
;
144 locator
->nsStack
= new_stack
;
145 locator
->nsStackSize
*= 2;
147 locator
->nsStack
[locator
->nsStackLast
++] = ns
;
152 static int namespacePop(saxlocator
*locator
)
154 if(locator
->nsStackLast
== 0) return 0;
155 return locator
->nsStack
[--locator
->nsStackLast
];
158 static BSTR
bstr_from_xmlCharN(const xmlChar
*buf
, int len
)
167 dLen
= MultiByteToWideChar(CP_UTF8
, 0, (LPCSTR
)buf
, len
, NULL
, 0);
168 if(len
!= -1) dLen
++;
169 str
= HeapAlloc(GetProcessHeap(), 0, dLen
* sizeof (WCHAR
));
172 MultiByteToWideChar(CP_UTF8
, 0, (LPCSTR
)buf
, len
, str
, dLen
);
173 if(len
!= -1) str
[dLen
-1] = '\0';
174 bstr
= SysAllocString(str
);
175 HeapFree(GetProcessHeap(), 0, str
);
180 static BSTR
QName_from_xmlChar(const xmlChar
*prefix
, const xmlChar
*name
)
186 if(!name
) return NULL
;
188 if(!prefix
|| *prefix
=='\0')
189 return bstr_from_xmlChar(name
);
191 dLen
= MultiByteToWideChar(CP_UTF8
, 0, (LPCSTR
)prefix
, -1, NULL
, 0)
192 + MultiByteToWideChar(CP_UTF8
, 0, (LPCSTR
)name
, -1, NULL
, 0);
193 str
= HeapAlloc(GetProcessHeap(), 0, dLen
* sizeof(WCHAR
));
197 dLast
= MultiByteToWideChar(CP_UTF8
, 0, (LPCSTR
)prefix
, -1, str
, dLen
);
199 MultiByteToWideChar(CP_UTF8
, 0, (LPCSTR
)name
, -1, &str
[dLast
], dLen
-dLast
);
200 bstr
= SysAllocString(str
);
202 HeapFree(GetProcessHeap(), 0, str
);
207 static void format_error_message_from_id(saxlocator
*This
, HRESULT hr
)
209 xmlStopParser(This
->pParserCtxt
);
212 if((This
->vbInterface
&& This
->saxreader
->vberrorHandler
)
213 || (!This
->vbInterface
&& This
->saxreader
->errorHandler
))
216 if(!FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM
,
217 NULL
, hr
, 0, msg
, sizeof(msg
), NULL
))
219 FIXME("MSXML errors not yet supported.\n");
223 if(This
->vbInterface
)
225 BSTR bstrMsg
= SysAllocString(msg
);
226 IVBSAXErrorHandler_fatalError(This
->saxreader
->vberrorHandler
,
227 (IVBSAXLocator
*)&This
->lpVBSAXLocatorVtbl
, &bstrMsg
, hr
);
230 ISAXErrorHandler_fatalError(This
->saxreader
->errorHandler
,
231 (ISAXLocator
*)&This
->lpSAXLocatorVtbl
, msg
, hr
);
235 static void update_position(saxlocator
*This
, xmlChar
*end
)
237 if(This
->lastCur
== NULL
)
239 This
->lastCur
= (xmlChar
*)This
->pParserCtxt
->input
->base
;
241 This
->realColumn
= 1;
243 else if(This
->lastCur
< This
->pParserCtxt
->input
->base
)
245 This
->lastCur
= (xmlChar
*)This
->pParserCtxt
->input
->base
;
247 This
->realColumn
= 1;
250 if(This
->pParserCtxt
->input
->cur
<This
->lastCur
)
252 This
->lastCur
= (xmlChar
*)This
->pParserCtxt
->input
->base
;
254 This
->realColumn
= 1;
257 if(!end
) end
= (xmlChar
*)This
->pParserCtxt
->input
->cur
;
259 while(This
->lastCur
< end
)
261 if(*(This
->lastCur
) == '\n')
264 This
->realColumn
= 1;
266 else if(*(This
->lastCur
) == '\r' &&
267 (This
->lastCur
==This
->pParserCtxt
->input
->end
||
268 *(This
->lastCur
+1)!='\n'))
271 This
->realColumn
= 1;
273 else This
->realColumn
++;
277 /* Count multibyte UTF8 encoded characters once */
278 while((*(This
->lastCur
)&0xC0) == 0x80) This
->lastCur
++;
281 This
->line
= This
->realLine
;
282 This
->column
= This
->realColumn
;
285 /*** IVBSAXAttributes interface ***/
286 /*** IUnknown methods ***/
287 static HRESULT WINAPI
ivbsaxattributes_QueryInterface(
288 IVBSAXAttributes
* iface
,
292 saxattributes
*This
= impl_from_IVBSAXAttributes(iface
);
294 TRACE("%p %s %p\n", This
, debugstr_guid(riid
), ppvObject
);
298 if (IsEqualGUID(riid
, &IID_IUnknown
) ||
299 IsEqualGUID(riid
, &IID_IDispatch
) ||
300 IsEqualGUID(riid
, &IID_IVBSAXAttributes
))
306 FIXME("interface %s not implemented\n", debugstr_guid(riid
));
307 return E_NOINTERFACE
;
310 IVBSAXAttributes_AddRef(iface
);
315 static ULONG WINAPI
ivbsaxattributes_AddRef(IVBSAXAttributes
* iface
)
317 saxattributes
*This
= impl_from_IVBSAXAttributes(iface
);
318 return ISAXAttributes_AddRef((ISAXAttributes
*)&This
->lpSAXAttributesVtbl
);
321 static ULONG WINAPI
ivbsaxattributes_Release(IVBSAXAttributes
* iface
)
323 saxattributes
*This
= impl_from_IVBSAXAttributes(iface
);
324 return ISAXAttributes_Release((ISAXAttributes
*)&This
->lpSAXAttributesVtbl
);
327 /*** IDispatch methods ***/
328 static HRESULT WINAPI
ivbsaxattributes_GetTypeInfoCount( IVBSAXAttributes
*iface
, UINT
* pctinfo
)
330 saxattributes
*This
= impl_from_IVBSAXAttributes( iface
);
332 TRACE("(%p)->(%p)\n", This
, pctinfo
);
339 static HRESULT WINAPI
ivbsaxattributes_GetTypeInfo(
340 IVBSAXAttributes
*iface
,
341 UINT iTInfo
, LCID lcid
, ITypeInfo
** ppTInfo
)
343 saxattributes
*This
= impl_from_IVBSAXAttributes( iface
);
346 TRACE("(%p)->(%u %u %p)\n", This
, iTInfo
, lcid
, ppTInfo
);
348 hr
= get_typeinfo(IVBSAXAttributes_tid
, ppTInfo
);
353 static HRESULT WINAPI
ivbsaxattributes_GetIDsOfNames(
354 IVBSAXAttributes
*iface
,
361 saxattributes
*This
= impl_from_IVBSAXAttributes( iface
);
365 TRACE("(%p)->(%s %p %u %u %p)\n", This
, debugstr_guid(riid
), rgszNames
, cNames
,
368 if(!rgszNames
|| cNames
== 0 || !rgDispId
)
371 hr
= get_typeinfo(IVBSAXAttributes_tid
, &typeinfo
);
374 hr
= ITypeInfo_GetIDsOfNames(typeinfo
, rgszNames
, cNames
, rgDispId
);
375 ITypeInfo_Release(typeinfo
);
381 static HRESULT WINAPI
ivbsaxattributes_Invoke(
382 IVBSAXAttributes
*iface
,
387 DISPPARAMS
* pDispParams
,
389 EXCEPINFO
* pExcepInfo
,
392 saxattributes
*This
= impl_from_IVBSAXAttributes( iface
);
396 TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This
, dispIdMember
, debugstr_guid(riid
),
397 lcid
, wFlags
, pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
399 hr
= get_typeinfo(IVBSAXAttributes_tid
, &typeinfo
);
402 hr
= ITypeInfo_Invoke(typeinfo
, &(This
->lpVBSAXAttributesVtbl
), dispIdMember
, wFlags
, pDispParams
,
403 pVarResult
, pExcepInfo
, puArgErr
);
404 ITypeInfo_Release(typeinfo
);
410 /*** IVBSAXAttributes methods ***/
411 static HRESULT WINAPI
ivbsaxattributes_get_length(
412 IVBSAXAttributes
* iface
,
415 saxattributes
*This
= impl_from_IVBSAXAttributes( iface
);
416 return ISAXAttributes_getLength(
417 (ISAXAttributes
*)&This
->lpSAXAttributesVtbl
,
421 static HRESULT WINAPI
ivbsaxattributes_getURI(
422 IVBSAXAttributes
* iface
,
427 saxattributes
*This
= impl_from_IVBSAXAttributes( iface
);
428 return ISAXAttributes_getURI(
429 (ISAXAttributes
*)&This
->lpSAXAttributesVtbl
,
430 nIndex
, (const WCHAR
**)uri
, &len
);
433 static HRESULT WINAPI
ivbsaxattributes_getLocalName(
434 IVBSAXAttributes
* iface
,
439 saxattributes
*This
= impl_from_IVBSAXAttributes( iface
);
440 return ISAXAttributes_getLocalName(
441 (ISAXAttributes
*)&This
->lpSAXAttributesVtbl
,
442 nIndex
, (const WCHAR
**)localName
, &len
);
445 static HRESULT WINAPI
ivbsaxattributes_getQName(
446 IVBSAXAttributes
* iface
,
451 saxattributes
*This
= impl_from_IVBSAXAttributes( iface
);
452 return ISAXAttributes_getQName(
453 (ISAXAttributes
*)&This
->lpSAXAttributesVtbl
,
454 nIndex
, (const WCHAR
**)QName
, &len
);
457 static HRESULT WINAPI
ivbsaxattributes_getIndexFromName(
458 IVBSAXAttributes
* iface
,
463 saxattributes
*This
= impl_from_IVBSAXAttributes( iface
);
464 return ISAXAttributes_getIndexFromName(
465 (ISAXAttributes
*)&This
->lpSAXAttributesVtbl
, uri
, SysStringLen(uri
),
466 localName
, SysStringLen(localName
), index
);
469 static HRESULT WINAPI
ivbsaxattributes_getIndexFromQName(
470 IVBSAXAttributes
* iface
,
474 saxattributes
*This
= impl_from_IVBSAXAttributes( iface
);
475 return ISAXAttributes_getIndexFromQName(
476 (ISAXAttributes
*)&This
->lpSAXAttributesVtbl
, QName
,
477 SysStringLen(QName
), index
);
480 static HRESULT WINAPI
ivbsaxattributes_getType(
481 IVBSAXAttributes
* iface
,
486 saxattributes
*This
= impl_from_IVBSAXAttributes( iface
);
487 return ISAXAttributes_getType(
488 (ISAXAttributes
*)&This
->lpSAXAttributesVtbl
,
489 nIndex
, (const WCHAR
**)type
, &len
);
492 static HRESULT WINAPI
ivbsaxattributes_getTypeFromName(
493 IVBSAXAttributes
* iface
,
499 saxattributes
*This
= impl_from_IVBSAXAttributes( iface
);
500 return ISAXAttributes_getTypeFromName(
501 (ISAXAttributes
*)&This
->lpSAXAttributesVtbl
, uri
, SysStringLen(uri
),
502 localName
, SysStringLen(localName
), (const WCHAR
**)type
, &len
);
505 static HRESULT WINAPI
ivbsaxattributes_getTypeFromQName(
506 IVBSAXAttributes
* iface
,
511 saxattributes
*This
= impl_from_IVBSAXAttributes( iface
);
512 return ISAXAttributes_getTypeFromQName(
513 (ISAXAttributes
*)&This
->lpSAXAttributesVtbl
, QName
,
514 SysStringLen(QName
), (const WCHAR
**)type
, &len
);
517 static HRESULT WINAPI
ivbsaxattributes_getValue(
518 IVBSAXAttributes
* iface
,
523 saxattributes
*This
= impl_from_IVBSAXAttributes( iface
);
524 return ISAXAttributes_getValue(
525 (ISAXAttributes
*)&This
->lpSAXAttributesVtbl
,
526 nIndex
, (const WCHAR
**)value
, &len
);
529 static HRESULT WINAPI
ivbsaxattributes_getValueFromName(
530 IVBSAXAttributes
* iface
,
536 saxattributes
*This
= impl_from_IVBSAXAttributes( iface
);
537 return ISAXAttributes_getValueFromName(
538 (ISAXAttributes
*)&This
->lpSAXAttributesVtbl
, uri
, SysStringLen(uri
),
539 localName
, SysStringLen(localName
), (const WCHAR
**)value
, &len
);
542 static HRESULT WINAPI
ivbsaxattributes_getValueFromQName(
543 IVBSAXAttributes
* iface
,
548 saxattributes
*This
= impl_from_IVBSAXAttributes( iface
);
549 return ISAXAttributes_getValueFromQName(
550 (ISAXAttributes
*)&This
->lpSAXAttributesVtbl
, QName
,
551 SysStringLen(QName
), (const WCHAR
**)value
, &len
);
554 static const struct IVBSAXAttributesVtbl ivbsaxattributes_vtbl
=
556 ivbsaxattributes_QueryInterface
,
557 ivbsaxattributes_AddRef
,
558 ivbsaxattributes_Release
,
559 ivbsaxattributes_GetTypeInfoCount
,
560 ivbsaxattributes_GetTypeInfo
,
561 ivbsaxattributes_GetIDsOfNames
,
562 ivbsaxattributes_Invoke
,
563 ivbsaxattributes_get_length
,
564 ivbsaxattributes_getURI
,
565 ivbsaxattributes_getLocalName
,
566 ivbsaxattributes_getQName
,
567 ivbsaxattributes_getIndexFromName
,
568 ivbsaxattributes_getIndexFromQName
,
569 ivbsaxattributes_getType
,
570 ivbsaxattributes_getTypeFromName
,
571 ivbsaxattributes_getTypeFromQName
,
572 ivbsaxattributes_getValue
,
573 ivbsaxattributes_getValueFromName
,
574 ivbsaxattributes_getValueFromQName
577 /*** ISAXAttributes interface ***/
578 /*** IUnknown methods ***/
579 static HRESULT WINAPI
isaxattributes_QueryInterface(
580 ISAXAttributes
* iface
,
584 saxattributes
*This
= impl_from_ISAXAttributes(iface
);
586 TRACE("%p %s %p\n", This
, debugstr_guid(riid
), ppvObject
);
590 if (IsEqualGUID(riid
, &IID_IUnknown
) ||
591 IsEqualGUID(riid
, &IID_ISAXAttributes
))
597 FIXME("interface %s not implemented\n", debugstr_guid(riid
));
598 return E_NOINTERFACE
;
601 ISAXAttributes_AddRef(iface
);
606 static ULONG WINAPI
isaxattributes_AddRef(ISAXAttributes
* iface
)
608 saxattributes
*This
= impl_from_ISAXAttributes(iface
);
610 return InterlockedIncrement(&This
->ref
);
613 static ULONG WINAPI
isaxattributes_Release(ISAXAttributes
* iface
)
615 saxattributes
*This
= impl_from_ISAXAttributes(iface
);
620 ref
= InterlockedDecrement(&This
->ref
);
624 for(index
=0; index
<This
->nb_attributes
; index
++)
626 SysFreeString(This
->szLocalname
[index
]);
627 SysFreeString(This
->szURI
[index
]);
628 SysFreeString(This
->szValue
[index
]);
629 SysFreeString(This
->szQName
[index
]);
632 HeapFree(GetProcessHeap(), 0, This
->szLocalname
);
633 HeapFree(GetProcessHeap(), 0, This
->szURI
);
634 HeapFree(GetProcessHeap(), 0, This
->szValue
);
635 HeapFree(GetProcessHeap(), 0, This
->szQName
);
637 HeapFree(GetProcessHeap(), 0, This
);
643 /*** ISAXAttributes methods ***/
644 static HRESULT WINAPI
isaxattributes_getLength(
645 ISAXAttributes
* iface
,
648 saxattributes
*This
= impl_from_ISAXAttributes( iface
);
650 *length
= This
->nb_attributes
;
651 TRACE("Length set to %d\n", *length
);
655 static HRESULT WINAPI
isaxattributes_getURI(
656 ISAXAttributes
* iface
,
661 saxattributes
*This
= impl_from_ISAXAttributes( iface
);
662 TRACE("(%p)->(%d)\n", This
, nIndex
);
664 if(nIndex
>=This
->nb_attributes
|| nIndex
<0) return E_INVALIDARG
;
665 if(!pUrl
|| !pUriSize
) return E_POINTER
;
667 *pUriSize
= SysStringLen(This
->szURI
[nIndex
]);
668 *pUrl
= This
->szURI
[nIndex
];
673 static HRESULT WINAPI
isaxattributes_getLocalName(
674 ISAXAttributes
* iface
,
676 const WCHAR
**pLocalName
,
677 int *pLocalNameLength
)
679 saxattributes
*This
= impl_from_ISAXAttributes( iface
);
680 TRACE("(%p)->(%d)\n", This
, nIndex
);
682 if(nIndex
>=This
->nb_attributes
|| nIndex
<0) return E_INVALIDARG
;
683 if(!pLocalName
|| !pLocalNameLength
) return E_POINTER
;
685 *pLocalNameLength
= SysStringLen(This
->szLocalname
[nIndex
]);
686 *pLocalName
= This
->szLocalname
[nIndex
];
691 static HRESULT WINAPI
isaxattributes_getQName(
692 ISAXAttributes
* iface
,
694 const WCHAR
**pQName
,
697 saxattributes
*This
= impl_from_ISAXAttributes( iface
);
698 TRACE("(%p)->(%d)\n", This
, nIndex
);
700 if(nIndex
>=This
->nb_attributes
|| nIndex
<0) return E_INVALIDARG
;
701 if(!pQName
|| !pQNameLength
) return E_POINTER
;
703 *pQNameLength
= SysStringLen(This
->szQName
[nIndex
]);
704 *pQName
= This
->szQName
[nIndex
];
709 static HRESULT WINAPI
isaxattributes_getName(
710 ISAXAttributes
* iface
,
714 const WCHAR
**pLocalName
,
716 const WCHAR
**pQName
,
719 saxattributes
*This
= impl_from_ISAXAttributes( iface
);
720 TRACE("(%p)->(%d)\n", This
, nIndex
);
722 if(nIndex
>=This
->nb_attributes
|| nIndex
<0) return E_INVALIDARG
;
723 if(!pUri
|| !pUriLength
|| !pLocalName
|| !pLocalNameSize
724 || !pQName
|| !pQNameLength
) return E_POINTER
;
726 *pUriLength
= SysStringLen(This
->szURI
[nIndex
]);
727 *pUri
= This
->szURI
[nIndex
];
728 *pLocalNameSize
= SysStringLen(This
->szLocalname
[nIndex
]);
729 *pLocalName
= This
->szLocalname
[nIndex
];
730 *pQNameLength
= SysStringLen(This
->szQName
[nIndex
]);
731 *pQName
= This
->szQName
[nIndex
];
736 static HRESULT WINAPI
isaxattributes_getIndexFromName(
737 ISAXAttributes
* iface
,
740 const WCHAR
*pLocalName
,
744 saxattributes
*This
= impl_from_ISAXAttributes( iface
);
746 TRACE("(%p)->(%s, %d, %s, %d)\n", This
, debugstr_w(pUri
), cUriLength
,
747 debugstr_w(pLocalName
), cocalNameLength
);
749 if(!pUri
|| !pLocalName
|| !index
) return E_POINTER
;
751 for(i
=0; i
<This
->nb_attributes
; i
++)
753 if(cUriLength
!=SysStringLen(This
->szURI
[i
])
754 || cocalNameLength
!=SysStringLen(This
->szLocalname
[i
]))
756 if(cUriLength
&& memcmp(pUri
, This
->szURI
[i
],
757 sizeof(WCHAR
)*cUriLength
))
759 if(cocalNameLength
&& memcmp(pLocalName
, This
->szLocalname
[i
],
760 sizeof(WCHAR
)*cocalNameLength
))
770 static HRESULT WINAPI
isaxattributes_getIndexFromQName(
771 ISAXAttributes
* iface
,
776 saxattributes
*This
= impl_from_ISAXAttributes( iface
);
778 TRACE("(%p)->(%s, %d)\n", This
, debugstr_w(pQName
), nQNameLength
);
780 if(!pQName
|| !index
) return E_POINTER
;
781 if(!nQNameLength
) return E_INVALIDARG
;
783 for(i
=0; i
<This
->nb_attributes
; i
++)
785 if(nQNameLength
!=SysStringLen(This
->szQName
[i
])) continue;
786 if(memcmp(pQName
, This
->szQName
, sizeof(WCHAR
)*nQNameLength
)) continue;
795 static HRESULT WINAPI
isaxattributes_getType(
796 ISAXAttributes
* iface
,
801 saxattributes
*This
= impl_from_ISAXAttributes( iface
);
803 FIXME("(%p)->(%d) stub\n", This
, nIndex
);
807 static HRESULT WINAPI
isaxattributes_getTypeFromName(
808 ISAXAttributes
* iface
,
811 const WCHAR
*pLocalName
,
816 saxattributes
*This
= impl_from_ISAXAttributes( iface
);
818 FIXME("(%p)->(%s, %d, %s, %d) stub\n", This
, debugstr_w(pUri
), nUri
,
819 debugstr_w(pLocalName
), nLocalName
);
823 static HRESULT WINAPI
isaxattributes_getTypeFromQName(
824 ISAXAttributes
* iface
,
830 saxattributes
*This
= impl_from_ISAXAttributes( iface
);
832 FIXME("(%p)->(%s, %d) stub\n", This
, debugstr_w(pQName
), nQName
);
836 static HRESULT WINAPI
isaxattributes_getValue(
837 ISAXAttributes
* iface
,
839 const WCHAR
**pValue
,
842 saxattributes
*This
= impl_from_ISAXAttributes( iface
);
843 TRACE("(%p)->(%d)\n", This
, nIndex
);
845 if(nIndex
>=This
->nb_attributes
|| nIndex
<0) return E_INVALIDARG
;
846 if(!pValue
|| !nValue
) return E_POINTER
;
848 *nValue
= SysStringLen(This
->szValue
[nIndex
]);
849 *pValue
= This
->szValue
[nIndex
];
854 static HRESULT WINAPI
isaxattributes_getValueFromName(
855 ISAXAttributes
* iface
,
858 const WCHAR
*pLocalName
,
860 const WCHAR
**pValue
,
865 saxattributes
*This
= impl_from_ISAXAttributes( iface
);
866 TRACE("(%p)->(%s, %d, %s, %d)\n", This
, debugstr_w(pUri
), nUri
,
867 debugstr_w(pLocalName
), nLocalName
);
869 hr
= ISAXAttributes_getIndexFromName(iface
,
870 pUri
, nUri
, pLocalName
, nLocalName
, &index
);
871 if(hr
==S_OK
) hr
= ISAXAttributes_getValue(iface
, index
, pValue
, nValue
);
876 static HRESULT WINAPI
isaxattributes_getValueFromQName(
877 ISAXAttributes
* iface
,
880 const WCHAR
**pValue
,
885 saxattributes
*This
= impl_from_ISAXAttributes( iface
);
886 TRACE("(%p)->(%s, %d)\n", This
, debugstr_w(pQName
), nQName
);
888 hr
= ISAXAttributes_getIndexFromQName(iface
, pQName
, nQName
, &index
);
889 if(hr
==S_OK
) hr
= ISAXAttributes_getValue(iface
, index
, pValue
, nValue
);
894 static const struct ISAXAttributesVtbl isaxattributes_vtbl
=
896 isaxattributes_QueryInterface
,
897 isaxattributes_AddRef
,
898 isaxattributes_Release
,
899 isaxattributes_getLength
,
900 isaxattributes_getURI
,
901 isaxattributes_getLocalName
,
902 isaxattributes_getQName
,
903 isaxattributes_getName
,
904 isaxattributes_getIndexFromName
,
905 isaxattributes_getIndexFromQName
,
906 isaxattributes_getType
,
907 isaxattributes_getTypeFromName
,
908 isaxattributes_getTypeFromQName
,
909 isaxattributes_getValue
,
910 isaxattributes_getValueFromName
,
911 isaxattributes_getValueFromQName
914 static HRESULT
SAXAttributes_create(saxattributes
**attr
,
915 int nb_namespaces
, const xmlChar
**xmlNamespaces
,
916 int nb_attributes
, const xmlChar
**xmlAttributes
)
918 saxattributes
*attributes
;
920 static const xmlChar xmlns
[] = "xmlns";
922 attributes
= HeapAlloc(GetProcessHeap(), 0, sizeof(*attributes
));
924 return E_OUTOFMEMORY
;
926 attributes
->lpVBSAXAttributesVtbl
= &ivbsaxattributes_vtbl
;
927 attributes
->lpSAXAttributesVtbl
= &isaxattributes_vtbl
;
930 attributes
->nb_attributes
= nb_namespaces
+nb_attributes
;
932 attributes
->szLocalname
=
933 HeapAlloc(GetProcessHeap(), 0, sizeof(BSTR
)*attributes
->nb_attributes
);
935 HeapAlloc(GetProcessHeap(), 0, sizeof(BSTR
)*attributes
->nb_attributes
);
936 attributes
->szValue
=
937 HeapAlloc(GetProcessHeap(), 0, sizeof(BSTR
)*attributes
->nb_attributes
);
938 attributes
->szQName
=
939 HeapAlloc(GetProcessHeap(), 0, sizeof(BSTR
)*attributes
->nb_attributes
);
941 if(!attributes
->szLocalname
|| !attributes
->szURI
942 || !attributes
->szValue
|| !attributes
->szQName
)
944 HeapFree(GetProcessHeap(), 0, attributes
->szLocalname
);
945 HeapFree(GetProcessHeap(), 0, attributes
->szURI
);
946 HeapFree(GetProcessHeap(), 0, attributes
->szValue
);
947 HeapFree(GetProcessHeap(), 0, attributes
->szQName
);
948 HeapFree(GetProcessHeap(), 0, attributes
);
952 for(index
=0; index
<nb_namespaces
; index
++)
954 attributes
->szLocalname
[index
] = SysAllocStringLen(NULL
, 0);
955 attributes
->szURI
[index
] = SysAllocStringLen(NULL
, 0);
956 attributes
->szValue
[index
] = bstr_from_xmlChar(xmlNamespaces
[2*index
+1]);
957 attributes
->szQName
[index
] = QName_from_xmlChar(xmlns
, xmlNamespaces
[2*index
]);
960 for(index
=0; index
<nb_attributes
; index
++)
962 attributes
->szLocalname
[nb_namespaces
+index
] =
963 bstr_from_xmlChar(xmlAttributes
[index
*5]);
964 attributes
->szURI
[nb_namespaces
+index
] =
965 bstr_from_xmlChar(xmlAttributes
[index
*5+2]);
966 attributes
->szValue
[nb_namespaces
+index
] =
967 bstr_from_xmlCharN(xmlAttributes
[index
*5+3],
968 xmlAttributes
[index
*5+4]-xmlAttributes
[index
*5+3]);
969 attributes
->szQName
[nb_namespaces
+index
] =
970 QName_from_xmlChar(xmlAttributes
[index
*5+1], xmlAttributes
[index
*5]);
975 TRACE("returning %p\n", *attr
);
980 /*** LibXML callbacks ***/
981 static void libxmlStartDocument(void *ctx
)
983 saxlocator
*This
= ctx
;
986 if(has_content_handler(This
))
988 if(This
->vbInterface
)
989 hr
= IVBSAXContentHandler_startDocument(This
->saxreader
->vbcontentHandler
);
991 hr
= ISAXContentHandler_startDocument(This
->saxreader
->contentHandler
);
994 format_error_message_from_id(This
, hr
);
997 update_position(This
, NULL
);
1000 static void libxmlEndDocument(void *ctx
)
1002 saxlocator
*This
= ctx
;
1008 if(This
->ret
!= S_OK
) return;
1010 if(has_content_handler(This
))
1012 if(This
->vbInterface
)
1013 hr
= IVBSAXContentHandler_endDocument(This
->saxreader
->vbcontentHandler
);
1015 hr
= ISAXContentHandler_endDocument(This
->saxreader
->contentHandler
);
1018 format_error_message_from_id(This
, hr
);
1022 static void libxmlStartElementNS(
1024 const xmlChar
*localname
,
1025 const xmlChar
*prefix
,
1028 const xmlChar
**namespaces
,
1031 const xmlChar
**attributes
)
1033 BSTR NamespaceUri
, LocalName
, QName
, Prefix
, Uri
;
1034 saxlocator
*This
= ctx
;
1036 saxattributes
*attr
;
1039 if(*(This
->pParserCtxt
->input
->cur
) == '/')
1040 update_position(This
, (xmlChar
*)This
->pParserCtxt
->input
->cur
+2);
1042 update_position(This
, (xmlChar
*)This
->pParserCtxt
->input
->cur
+1);
1044 hr
= namespacePush(This
, nb_namespaces
);
1045 if(hr
==S_OK
&& has_content_handler(This
))
1047 for(index
=0; index
<nb_namespaces
; index
++)
1049 Prefix
= bstr_from_xmlChar(namespaces
[2*index
]);
1050 Uri
= bstr_from_xmlChar(namespaces
[2*index
+1]);
1052 if(This
->vbInterface
)
1053 hr
= IVBSAXContentHandler_startPrefixMapping(
1054 This
->saxreader
->vbcontentHandler
,
1057 hr
= ISAXContentHandler_startPrefixMapping(
1058 This
->saxreader
->contentHandler
,
1059 Prefix
, SysStringLen(Prefix
),
1060 Uri
, SysStringLen(Uri
));
1062 SysFreeString(Prefix
);
1067 format_error_message_from_id(This
, hr
);
1072 NamespaceUri
= bstr_from_xmlChar(URI
);
1073 LocalName
= bstr_from_xmlChar(localname
);
1074 QName
= QName_from_xmlChar(prefix
, localname
);
1076 hr
= SAXAttributes_create(&attr
, nb_namespaces
, namespaces
, nb_attributes
, attributes
);
1079 if(This
->vbInterface
)
1080 hr
= IVBSAXContentHandler_startElement(
1081 This
->saxreader
->vbcontentHandler
,
1082 &NamespaceUri
, &LocalName
, &QName
,
1083 (IVBSAXAttributes
*)&attr
->lpVBSAXAttributesVtbl
);
1085 hr
= ISAXContentHandler_startElement(
1086 This
->saxreader
->contentHandler
,
1087 NamespaceUri
, SysStringLen(NamespaceUri
),
1088 LocalName
, SysStringLen(LocalName
),
1089 QName
, SysStringLen(QName
),
1090 (ISAXAttributes
*)&attr
->lpSAXAttributesVtbl
);
1092 ISAXAttributes_Release((ISAXAttributes
*)&attr
->lpSAXAttributesVtbl
);
1095 SysFreeString(NamespaceUri
);
1096 SysFreeString(LocalName
);
1097 SysFreeString(QName
);
1101 format_error_message_from_id(This
, hr
);
1104 static void libxmlEndElementNS(
1106 const xmlChar
*localname
,
1107 const xmlChar
*prefix
,
1110 BSTR NamespaceUri
, LocalName
, QName
, Prefix
;
1111 saxlocator
*This
= ctx
;
1116 end
= (xmlChar
*)This
->pParserCtxt
->input
->cur
;
1117 if(*(end
-1) != '>' || *(end
-2) != '/')
1118 while(*(end
-2)!='<' && *(end
-1)!='/') end
--;
1120 update_position(This
, end
);
1122 nsNr
= namespacePop(This
);
1124 if(has_content_handler(This
))
1126 NamespaceUri
= bstr_from_xmlChar(URI
);
1127 LocalName
= bstr_from_xmlChar(localname
);
1128 QName
= QName_from_xmlChar(prefix
, localname
);
1130 if(This
->vbInterface
)
1131 hr
= IVBSAXContentHandler_endElement(
1132 This
->saxreader
->vbcontentHandler
,
1133 &NamespaceUri
, &LocalName
, &QName
);
1135 hr
= ISAXContentHandler_endElement(
1136 This
->saxreader
->contentHandler
,
1137 NamespaceUri
, SysStringLen(NamespaceUri
),
1138 LocalName
, SysStringLen(LocalName
),
1139 QName
, SysStringLen(QName
));
1141 SysFreeString(NamespaceUri
);
1142 SysFreeString(LocalName
);
1143 SysFreeString(QName
);
1147 format_error_message_from_id(This
, hr
);
1151 for(index
=This
->pParserCtxt
->nsNr
-2;
1152 index
>=This
->pParserCtxt
->nsNr
-nsNr
*2; index
-=2)
1154 Prefix
= bstr_from_xmlChar(This
->pParserCtxt
->nsTab
[index
]);
1156 if(This
->vbInterface
)
1157 hr
= IVBSAXContentHandler_endPrefixMapping(
1158 This
->saxreader
->vbcontentHandler
, &Prefix
);
1160 hr
= ISAXContentHandler_endPrefixMapping(
1161 This
->saxreader
->contentHandler
,
1162 Prefix
, SysStringLen(Prefix
));
1164 SysFreeString(Prefix
);
1168 format_error_message_from_id(This
, hr
);
1175 update_position(This
, NULL
);
1178 static void libxmlCharacters(
1183 saxlocator
*This
= ctx
;
1188 BOOL lastEvent
= FALSE
;
1190 if(!(has_content_handler(This
))) return;
1193 if(*(ch
-1)=='\r') cur
--;
1196 if(ch
<This
->pParserCtxt
->input
->base
|| ch
>This
->pParserCtxt
->input
->end
)
1201 while(end
-ch
<len
&& *end
!='\r') end
++;
1208 if(!lastEvent
) *end
= '\n';
1210 Chars
= bstr_from_xmlCharN(cur
, end
-cur
+1);
1211 if(This
->vbInterface
)
1212 hr
= IVBSAXContentHandler_characters(
1213 This
->saxreader
->vbcontentHandler
, &Chars
);
1215 hr
= ISAXContentHandler_characters(
1216 This
->saxreader
->contentHandler
,
1217 Chars
, SysStringLen(Chars
));
1218 SysFreeString(Chars
);
1222 format_error_message_from_id(This
, hr
);
1226 This
->column
+= end
-cur
+1;
1240 if(end
-ch
== len
) break;
1243 if(ch
<This
->pParserCtxt
->input
->base
|| ch
>This
->pParserCtxt
->input
->end
)
1244 This
->column
= This
->realColumn
1245 +This
->pParserCtxt
->input
->cur
-This
->lastCur
;
1248 static void libxmlSetDocumentLocator(
1250 xmlSAXLocatorPtr loc
)
1252 saxlocator
*This
= ctx
;
1255 if(This
->vbInterface
)
1256 hr
= IVBSAXContentHandler_putref_documentLocator(
1257 This
->saxreader
->vbcontentHandler
,
1258 (IVBSAXLocator
*)&This
->lpVBSAXLocatorVtbl
);
1260 hr
= ISAXContentHandler_putDocumentLocator(
1261 This
->saxreader
->contentHandler
,
1262 (ISAXLocator
*)&This
->lpSAXLocatorVtbl
);
1265 format_error_message_from_id(This
, hr
);
1268 static void libxmlComment(void *ctx
, const xmlChar
*value
)
1270 saxlocator
*This
= ctx
;
1273 xmlChar
*beg
= (xmlChar
*)This
->pParserCtxt
->input
->cur
;
1275 while(memcmp(beg
-4, "<!--", sizeof(char[4]))) beg
--;
1276 update_position(This
, beg
);
1278 if(!This
->vbInterface
&& !This
->saxreader
->lexicalHandler
) return;
1279 if(This
->vbInterface
&& !This
->saxreader
->vblexicalHandler
) return;
1281 bValue
= bstr_from_xmlChar(value
);
1283 if(This
->vbInterface
)
1284 hr
= IVBSAXLexicalHandler_comment(
1285 This
->saxreader
->vblexicalHandler
, &bValue
);
1287 hr
= ISAXLexicalHandler_comment(
1288 This
->saxreader
->lexicalHandler
,
1289 bValue
, SysStringLen(bValue
));
1291 SysFreeString(bValue
);
1294 format_error_message_from_id(This
, hr
);
1296 update_position(This
, NULL
);
1299 static void libxmlFatalError(void *ctx
, const char *msg
, ...)
1301 saxlocator
*This
= ctx
;
1307 if((This
->vbInterface
&& !This
->saxreader
->vberrorHandler
)
1308 || (!This
->vbInterface
&& !This
->saxreader
->errorHandler
))
1310 xmlStopParser(This
->pParserCtxt
);
1315 FIXME("Error handling is not compatible.\n");
1317 va_start(args
, msg
);
1318 vsprintf(message
, msg
, args
);
1321 len
= MultiByteToWideChar(CP_UNIXCP
, 0, message
, -1, NULL
, 0);
1322 wszError
= HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR
)*len
);
1324 MultiByteToWideChar(CP_UNIXCP
, 0, message
, -1, wszError
, len
);
1326 if(This
->vbInterface
)
1328 BSTR bstrError
= SysAllocString(wszError
);
1329 IVBSAXErrorHandler_fatalError(This
->saxreader
->vberrorHandler
,
1330 (IVBSAXLocator
*)&This
->lpVBSAXLocatorVtbl
, &bstrError
, E_FAIL
);
1333 ISAXErrorHandler_fatalError(This
->saxreader
->errorHandler
,
1334 (ISAXLocator
*)&This
->lpSAXLocatorVtbl
, wszError
, E_FAIL
);
1336 HeapFree(GetProcessHeap(), 0, wszError
);
1338 xmlStopParser(This
->pParserCtxt
);
1342 static void libxmlCDataBlock(void *ctx
, const xmlChar
*value
, int len
)
1344 saxlocator
*This
= ctx
;
1346 xmlChar
*beg
= (xmlChar
*)This
->pParserCtxt
->input
->cur
-len
;
1350 BOOL lastEvent
= FALSE
, change
;
1352 while(memcmp(beg
-9, "<![CDATA[", sizeof(char[9]))) beg
--;
1353 update_position(This
, beg
);
1355 if(This
->vbInterface
&& This
->saxreader
->vblexicalHandler
)
1356 hr
= IVBSAXLexicalHandler_startCDATA(This
->saxreader
->vblexicalHandler
);
1357 if(!This
->vbInterface
&& This
->saxreader
->lexicalHandler
)
1358 hr
= ISAXLexicalHandler_startCDATA(This
->saxreader
->lexicalHandler
);
1362 format_error_message_from_id(This
, hr
);
1366 realLen
= This
->pParserCtxt
->input
->cur
-beg
-3;
1372 while(end
-beg
<realLen
&& *end
!='\r') end
++;
1373 if(end
-beg
==realLen
)
1378 else if(end
-beg
==realLen
-1 && *end
=='\r' && *(end
+1)=='\n')
1381 if(*end
== '\r') change
= TRUE
;
1382 else change
= FALSE
;
1384 if(change
) *end
= '\n';
1386 if(has_content_handler(This
))
1388 Chars
= bstr_from_xmlCharN(cur
, end
-cur
+1);
1389 if(This
->vbInterface
)
1390 hr
= IVBSAXContentHandler_characters(
1391 This
->saxreader
->vbcontentHandler
, &Chars
);
1393 hr
= ISAXContentHandler_characters(
1394 This
->saxreader
->contentHandler
,
1395 Chars
, SysStringLen(Chars
));
1396 SysFreeString(Chars
);
1399 if(change
) *end
= '\r';
1404 This
->column
+= end
-cur
+2;
1409 if(This
->vbInterface
&& This
->saxreader
->vblexicalHandler
)
1410 hr
= IVBSAXLexicalHandler_endCDATA(This
->saxreader
->vblexicalHandler
);
1411 if(!This
->vbInterface
&& This
->saxreader
->lexicalHandler
)
1412 hr
= ISAXLexicalHandler_endCDATA(This
->saxreader
->lexicalHandler
);
1415 format_error_message_from_id(This
, hr
);
1417 This
->column
+= 4+end
-cur
;
1420 /*** IVBSAXLocator interface ***/
1421 /*** IUnknown methods ***/
1422 static HRESULT WINAPI
ivbsaxlocator_QueryInterface(IVBSAXLocator
* iface
, REFIID riid
, void **ppvObject
)
1424 saxlocator
*This
= impl_from_IVBSAXLocator( iface
);
1426 TRACE("%p %s %p\n", This
, debugstr_guid( riid
), ppvObject
);
1430 if ( IsEqualGUID( riid
, &IID_IUnknown
) ||
1431 IsEqualGUID( riid
, &IID_IDispatch
) ||
1432 IsEqualGUID( riid
, &IID_IVBSAXLocator
))
1438 FIXME("interface %s not implemented\n", debugstr_guid(riid
));
1439 return E_NOINTERFACE
;
1442 IVBSAXLocator_AddRef( iface
);
1447 static ULONG WINAPI
ivbsaxlocator_AddRef(IVBSAXLocator
* iface
)
1449 saxlocator
*This
= impl_from_IVBSAXLocator( iface
);
1450 TRACE("%p\n", This
);
1451 return InterlockedIncrement( &This
->ref
);
1454 static ULONG WINAPI
ivbsaxlocator_Release(
1455 IVBSAXLocator
* iface
)
1457 saxlocator
*This
= impl_from_IVBSAXLocator( iface
);
1458 return ISAXLocator_Release((ISAXLocator
*)&This
->lpVBSAXLocatorVtbl
);
1461 /*** IDispatch methods ***/
1462 static HRESULT WINAPI
ivbsaxlocator_GetTypeInfoCount( IVBSAXLocator
*iface
, UINT
* pctinfo
)
1464 saxlocator
*This
= impl_from_IVBSAXLocator( iface
);
1466 TRACE("(%p)->(%p)\n", This
, pctinfo
);
1473 static HRESULT WINAPI
ivbsaxlocator_GetTypeInfo(
1474 IVBSAXLocator
*iface
,
1475 UINT iTInfo
, LCID lcid
, ITypeInfo
** ppTInfo
)
1477 saxlocator
*This
= impl_from_IVBSAXLocator( iface
);
1480 TRACE("(%p)->(%u %u %p)\n", This
, iTInfo
, lcid
, ppTInfo
);
1482 hr
= get_typeinfo(IVBSAXLocator_tid
, ppTInfo
);
1487 static HRESULT WINAPI
ivbsaxlocator_GetIDsOfNames(
1488 IVBSAXLocator
*iface
,
1490 LPOLESTR
* rgszNames
,
1495 saxlocator
*This
= impl_from_IVBSAXLocator( iface
);
1496 ITypeInfo
*typeinfo
;
1499 TRACE("(%p)->(%s %p %u %u %p)\n", This
, debugstr_guid(riid
), rgszNames
, cNames
,
1502 if(!rgszNames
|| cNames
== 0 || !rgDispId
)
1503 return E_INVALIDARG
;
1505 hr
= get_typeinfo(IVBSAXLocator_tid
, &typeinfo
);
1508 hr
= ITypeInfo_GetIDsOfNames(typeinfo
, rgszNames
, cNames
, rgDispId
);
1509 ITypeInfo_Release(typeinfo
);
1515 static HRESULT WINAPI
ivbsaxlocator_Invoke(
1516 IVBSAXLocator
*iface
,
1517 DISPID dispIdMember
,
1521 DISPPARAMS
* pDispParams
,
1522 VARIANT
* pVarResult
,
1523 EXCEPINFO
* pExcepInfo
,
1526 saxlocator
*This
= impl_from_IVBSAXLocator( iface
);
1527 ITypeInfo
*typeinfo
;
1530 TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This
, dispIdMember
, debugstr_guid(riid
),
1531 lcid
, wFlags
, pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
1533 hr
= get_typeinfo(IVBSAXLocator_tid
, &typeinfo
);
1536 hr
= ITypeInfo_Invoke(typeinfo
, &(This
->lpVBSAXLocatorVtbl
), dispIdMember
, wFlags
, pDispParams
,
1537 pVarResult
, pExcepInfo
, puArgErr
);
1538 ITypeInfo_Release(typeinfo
);
1544 /*** IVBSAXLocator methods ***/
1545 static HRESULT WINAPI
ivbsaxlocator_get_columnNumber(
1546 IVBSAXLocator
* iface
,
1549 saxlocator
*This
= impl_from_IVBSAXLocator( iface
);
1550 return ISAXLocator_getColumnNumber(
1551 (ISAXLocator
*)&This
->lpVBSAXLocatorVtbl
,
1555 static HRESULT WINAPI
ivbsaxlocator_get_lineNumber(
1556 IVBSAXLocator
* iface
,
1559 saxlocator
*This
= impl_from_IVBSAXLocator( iface
);
1560 return ISAXLocator_getLineNumber(
1561 (ISAXLocator
*)&This
->lpVBSAXLocatorVtbl
,
1565 static HRESULT WINAPI
ivbsaxlocator_get_publicId(
1566 IVBSAXLocator
* iface
,
1569 saxlocator
*This
= impl_from_IVBSAXLocator( iface
);
1570 return ISAXLocator_getPublicId(
1571 (ISAXLocator
*)&This
->lpVBSAXLocatorVtbl
,
1572 (const WCHAR
**)publicId
);
1575 static HRESULT WINAPI
ivbsaxlocator_get_systemId(
1576 IVBSAXLocator
* iface
,
1579 saxlocator
*This
= impl_from_IVBSAXLocator( iface
);
1580 return ISAXLocator_getSystemId(
1581 (ISAXLocator
*)&This
->lpVBSAXLocatorVtbl
,
1582 (const WCHAR
**)systemId
);
1585 static const struct IVBSAXLocatorVtbl ivbsaxlocator_vtbl
=
1587 ivbsaxlocator_QueryInterface
,
1588 ivbsaxlocator_AddRef
,
1589 ivbsaxlocator_Release
,
1590 ivbsaxlocator_GetTypeInfoCount
,
1591 ivbsaxlocator_GetTypeInfo
,
1592 ivbsaxlocator_GetIDsOfNames
,
1593 ivbsaxlocator_Invoke
,
1594 ivbsaxlocator_get_columnNumber
,
1595 ivbsaxlocator_get_lineNumber
,
1596 ivbsaxlocator_get_publicId
,
1597 ivbsaxlocator_get_systemId
1600 /*** ISAXLocator interface ***/
1601 /*** IUnknown methods ***/
1602 static HRESULT WINAPI
isaxlocator_QueryInterface(ISAXLocator
* iface
, REFIID riid
, void **ppvObject
)
1604 saxlocator
*This
= impl_from_ISAXLocator( iface
);
1606 TRACE("%p %s %p\n", This
, debugstr_guid( riid
), ppvObject
);
1610 if ( IsEqualGUID( riid
, &IID_IUnknown
) ||
1611 IsEqualGUID( riid
, &IID_ISAXLocator
))
1617 FIXME("interface %s not implemented\n", debugstr_guid(riid
));
1618 return E_NOINTERFACE
;
1621 ISAXLocator_AddRef( iface
);
1626 static ULONG WINAPI
isaxlocator_AddRef(ISAXLocator
* iface
)
1628 saxlocator
*This
= impl_from_ISAXLocator( iface
);
1629 TRACE("%p\n", This
);
1630 return InterlockedIncrement( &This
->ref
);
1633 static ULONG WINAPI
isaxlocator_Release(
1636 saxlocator
*This
= impl_from_ISAXLocator( iface
);
1639 TRACE("%p\n", This
);
1641 ref
= InterlockedDecrement( &This
->ref
);
1644 SysFreeString(This
->publicId
);
1645 SysFreeString(This
->systemId
);
1646 HeapFree(GetProcessHeap(), 0, This
->nsStack
);
1648 ISAXXMLReader_Release((ISAXXMLReader
*)&This
->saxreader
->lpSAXXMLReaderVtbl
);
1649 HeapFree( GetProcessHeap(), 0, This
);
1655 /*** ISAXLocator methods ***/
1656 static HRESULT WINAPI
isaxlocator_getColumnNumber(
1660 saxlocator
*This
= impl_from_ISAXLocator( iface
);
1662 *pnColumn
= This
->column
;
1666 static HRESULT WINAPI
isaxlocator_getLineNumber(
1670 saxlocator
*This
= impl_from_ISAXLocator( iface
);
1672 *pnLine
= This
->line
;
1676 static HRESULT WINAPI
isaxlocator_getPublicId(
1678 const WCHAR
** ppwchPublicId
)
1681 saxlocator
*This
= impl_from_ISAXLocator( iface
);
1683 SysFreeString(This
->publicId
);
1685 publicId
= bstr_from_xmlChar(xmlSAX2GetPublicId(This
->pParserCtxt
));
1686 if(SysStringLen(publicId
))
1687 This
->publicId
= (WCHAR
*)&publicId
;
1690 SysFreeString(publicId
);
1691 This
->publicId
= NULL
;
1694 *ppwchPublicId
= This
->publicId
;
1698 static HRESULT WINAPI
isaxlocator_getSystemId(
1700 const WCHAR
** ppwchSystemId
)
1703 saxlocator
*This
= impl_from_ISAXLocator( iface
);
1705 SysFreeString(This
->systemId
);
1707 systemId
= bstr_from_xmlChar(xmlSAX2GetSystemId(This
->pParserCtxt
));
1708 if(SysStringLen(systemId
))
1709 This
->systemId
= (WCHAR
*)&systemId
;
1712 SysFreeString(systemId
);
1713 This
->systemId
= NULL
;
1716 *ppwchSystemId
= This
->systemId
;
1720 static const struct ISAXLocatorVtbl isaxlocator_vtbl
=
1722 isaxlocator_QueryInterface
,
1724 isaxlocator_Release
,
1725 isaxlocator_getColumnNumber
,
1726 isaxlocator_getLineNumber
,
1727 isaxlocator_getPublicId
,
1728 isaxlocator_getSystemId
1731 static HRESULT
SAXLocator_create(saxreader
*reader
, saxlocator
**ppsaxlocator
, BOOL vbInterface
)
1733 saxlocator
*locator
;
1735 locator
= HeapAlloc( GetProcessHeap(), 0, sizeof (*locator
) );
1737 return E_OUTOFMEMORY
;
1739 locator
->lpVBSAXLocatorVtbl
= &ivbsaxlocator_vtbl
;
1740 locator
->lpSAXLocatorVtbl
= &isaxlocator_vtbl
;
1742 locator
->vbInterface
= vbInterface
;
1744 locator
->saxreader
= reader
;
1745 ISAXXMLReader_AddRef((ISAXXMLReader
*)&reader
->lpSAXXMLReaderVtbl
);
1747 locator
->pParserCtxt
= NULL
;
1748 locator
->publicId
= NULL
;
1749 locator
->systemId
= NULL
;
1750 locator
->lastCur
= NULL
;
1752 locator
->column
= 0;
1753 locator
->ret
= S_OK
;
1754 locator
->nsStackSize
= 8;
1755 locator
->nsStackLast
= 0;
1756 locator
->nsStack
= HeapAlloc(GetProcessHeap(), 0, locator
->nsStackSize
);
1757 if(!locator
->nsStack
)
1759 ISAXXMLReader_Release((ISAXXMLReader
*)&reader
->lpSAXXMLReaderVtbl
);
1760 HeapFree(GetProcessHeap(), 0, locator
);
1761 return E_OUTOFMEMORY
;
1764 *ppsaxlocator
= locator
;
1766 TRACE("returning %p\n", *ppsaxlocator
);
1771 /*** SAXXMLReader internal functions ***/
1772 static HRESULT
internal_parseBuffer(saxreader
*This
, const char *buffer
, int size
, BOOL vbInterface
)
1774 saxlocator
*locator
;
1777 hr
= SAXLocator_create(This
, &locator
, vbInterface
);
1781 locator
->pParserCtxt
= xmlCreateMemoryParserCtxt(buffer
, size
);
1782 if(!locator
->pParserCtxt
)
1784 ISAXLocator_Release((ISAXLocator
*)&locator
->lpSAXLocatorVtbl
);
1788 xmlFree(locator
->pParserCtxt
->sax
);
1789 locator
->pParserCtxt
->sax
= &locator
->saxreader
->sax
;
1790 locator
->pParserCtxt
->userData
= locator
;
1792 This
->isParsing
= TRUE
;
1793 if(xmlParseDocument(locator
->pParserCtxt
)) hr
= E_FAIL
;
1794 else hr
= locator
->ret
;
1795 This
->isParsing
= FALSE
;
1797 if(locator
->pParserCtxt
)
1799 locator
->pParserCtxt
->sax
= NULL
;
1800 xmlFreeParserCtxt(locator
->pParserCtxt
);
1801 locator
->pParserCtxt
= NULL
;
1804 ISAXLocator_Release((ISAXLocator
*)&locator
->lpSAXLocatorVtbl
);
1808 static HRESULT
internal_parseStream(saxreader
*This
, IStream
*stream
, BOOL vbInterface
)
1810 saxlocator
*locator
;
1815 hr
= IStream_Read(stream
, data
, sizeof(data
), &dataRead
);
1819 hr
= SAXLocator_create(This
, &locator
, vbInterface
);
1823 locator
->pParserCtxt
= xmlCreatePushParserCtxt(
1824 &locator
->saxreader
->sax
, locator
,
1825 data
, dataRead
, NULL
);
1826 if(!locator
->pParserCtxt
)
1828 ISAXLocator_Release((ISAXLocator
*)&locator
->lpSAXLocatorVtbl
);
1832 This
->isParsing
= TRUE
;
1835 hr
= IStream_Read(stream
, data
, sizeof(data
), &dataRead
);
1839 if(xmlParseChunk(locator
->pParserCtxt
, data
, dataRead
, 0)) hr
= E_FAIL
;
1840 else hr
= locator
->ret
;
1842 if(hr
!= S_OK
) break;
1844 if(dataRead
!= sizeof(data
))
1846 if(xmlParseChunk(locator
->pParserCtxt
, data
, 0, 1)) hr
= E_FAIL
;
1847 else hr
= locator
->ret
;
1852 This
->isParsing
= FALSE
;
1854 xmlFreeParserCtxt(locator
->pParserCtxt
);
1855 locator
->pParserCtxt
= NULL
;
1856 ISAXLocator_Release((ISAXLocator
*)&locator
->lpSAXLocatorVtbl
);
1860 static HRESULT
internal_getEntityResolver(
1862 void *pEntityResolver
,
1865 FIXME("(%p)->(%p) stub\n", This
, pEntityResolver
);
1869 static HRESULT
internal_putEntityResolver(
1871 void *pEntityResolver
,
1874 FIXME("(%p)->(%p) stub\n", This
, pEntityResolver
);
1878 static HRESULT
internal_getContentHandler(
1880 void *pContentHandler
,
1883 TRACE("(%p)->(%p)\n", This
, pContentHandler
);
1884 if(pContentHandler
== NULL
)
1886 if((vbInterface
&& This
->vbcontentHandler
)
1887 || (!vbInterface
&& This
->contentHandler
))
1890 IVBSAXContentHandler_AddRef(This
->vbcontentHandler
);
1892 ISAXContentHandler_AddRef(This
->contentHandler
);
1894 if(vbInterface
) *(IVBSAXContentHandler
**)pContentHandler
=
1895 This
->vbcontentHandler
;
1896 else *(ISAXContentHandler
**)pContentHandler
= This
->contentHandler
;
1901 static HRESULT
internal_putContentHandler(
1903 void *contentHandler
,
1906 TRACE("(%p)->(%p)\n", This
, contentHandler
);
1910 IVBSAXContentHandler_AddRef((IVBSAXContentHandler
*)contentHandler
);
1912 ISAXContentHandler_AddRef((ISAXContentHandler
*)contentHandler
);
1914 if((vbInterface
&& This
->vbcontentHandler
)
1915 || (!vbInterface
&& This
->contentHandler
))
1918 IVBSAXContentHandler_Release(This
->vbcontentHandler
);
1920 ISAXContentHandler_Release(This
->contentHandler
);
1923 This
->vbcontentHandler
= contentHandler
;
1925 This
->contentHandler
= contentHandler
;
1930 static HRESULT
internal_getDTDHandler(
1935 FIXME("(%p)->(%p) stub\n", This
, pDTDHandler
);
1939 static HRESULT
internal_putDTDHandler(
1944 FIXME("(%p)->(%p) stub\n", This
, pDTDHandler
);
1948 static HRESULT
internal_getErrorHandler(
1950 void *pErrorHandler
,
1953 TRACE("(%p)->(%p)\n", This
, pErrorHandler
);
1954 if(pErrorHandler
== NULL
)
1957 if(vbInterface
&& This
->vberrorHandler
)
1958 IVBSAXErrorHandler_AddRef(This
->vberrorHandler
);
1959 else if(!vbInterface
&& This
->errorHandler
)
1960 ISAXErrorHandler_AddRef(This
->errorHandler
);
1963 *(IVBSAXErrorHandler
**)pErrorHandler
= This
->vberrorHandler
;
1965 *(ISAXErrorHandler
**)pErrorHandler
= This
->errorHandler
;
1971 static HRESULT
internal_putErrorHandler(
1976 TRACE("(%p)->(%p)\n", This
, errorHandler
);
1980 IVBSAXErrorHandler_AddRef((IVBSAXErrorHandler
*)errorHandler
);
1982 ISAXErrorHandler_AddRef((ISAXErrorHandler
*)errorHandler
);
1985 if(vbInterface
&& This
->vberrorHandler
)
1986 IVBSAXErrorHandler_Release(This
->vberrorHandler
);
1987 else if(!vbInterface
&& This
->errorHandler
)
1988 ISAXErrorHandler_Release(This
->errorHandler
);
1991 This
->vberrorHandler
= errorHandler
;
1993 This
->errorHandler
= errorHandler
;
1999 static HRESULT
internal_parse(
2006 TRACE("(%p)\n", This
);
2009 switch(V_VT(&varInput
))
2012 hr
= internal_parseBuffer(This
, (const char*)V_BSTR(&varInput
),
2013 SysStringByteLen(V_BSTR(&varInput
)), vbInterface
);
2015 case VT_ARRAY
|VT_UI1
: {
2017 LONG lBound
, uBound
;
2020 hr
= SafeArrayGetLBound(V_ARRAY(&varInput
), 1, &lBound
);
2021 if(hr
!= S_OK
) break;
2022 hr
= SafeArrayGetUBound(V_ARRAY(&varInput
), 1, &uBound
);
2023 if(hr
!= S_OK
) break;
2024 dataRead
= (uBound
-lBound
)*SafeArrayGetElemsize(V_ARRAY(&varInput
));
2025 hr
= SafeArrayAccessData(V_ARRAY(&varInput
), &pSAData
);
2026 if(hr
!= S_OK
) break;
2027 hr
= internal_parseBuffer(This
, pSAData
, dataRead
, vbInterface
);
2028 SafeArrayUnaccessData(V_ARRAY(&varInput
));
2033 IPersistStream
*persistStream
;
2034 IStream
*stream
= NULL
;
2035 IXMLDOMDocument
*xmlDoc
;
2037 if(IUnknown_QueryInterface(V_UNKNOWN(&varInput
),
2038 &IID_IXMLDOMDocument
, (void**)&xmlDoc
) == S_OK
)
2042 IXMLDOMDocument_get_xml(xmlDoc
, &bstrData
);
2043 hr
= internal_parseBuffer(This
, (const char*)bstrData
,
2044 SysStringByteLen(bstrData
), vbInterface
);
2045 IXMLDOMDocument_Release(xmlDoc
);
2046 SysFreeString(bstrData
);
2049 if(IUnknown_QueryInterface(V_UNKNOWN(&varInput
),
2050 &IID_IPersistStream
, (void**)&persistStream
) == S_OK
)
2052 hr
= IPersistStream_Save(persistStream
, stream
, TRUE
);
2053 IPersistStream_Release(persistStream
);
2054 if(hr
!= S_OK
) break;
2056 if(stream
|| IUnknown_QueryInterface(V_UNKNOWN(&varInput
),
2057 &IID_IStream
, (void**)&stream
) == S_OK
)
2059 hr
= internal_parseStream(This
, stream
, vbInterface
);
2060 IStream_Release(stream
);
2065 WARN("vt %d not implemented\n", V_VT(&varInput
));
2072 static HRESULT
internal_vbonDataAvailable(void *obj
, char *ptr
, DWORD len
)
2074 saxreader
*This
= obj
;
2076 return internal_parseBuffer(This
, ptr
, len
, TRUE
);
2079 static HRESULT
internal_onDataAvailable(void *obj
, char *ptr
, DWORD len
)
2081 saxreader
*This
= obj
;
2083 return internal_parseBuffer(This
, ptr
, len
, FALSE
);
2086 static HRESULT
internal_parseURL(
2094 TRACE("(%p)->(%s)\n", This
, debugstr_w(url
));
2096 if(vbInterface
) hr
= bind_url(url
, internal_vbonDataAvailable
, This
, &bsc
);
2097 else hr
= bind_url(url
, internal_onDataAvailable
, This
, &bsc
);
2107 static HRESULT
internal_putProperty(
2113 static const WCHAR wszCharset
[] = {
2114 'c','h','a','r','s','e','t',0
2116 static const WCHAR wszDeclarationHandler
[] = {
2117 'h','t','t','p',':','/','/','x','m','l','.','o','r','g','/',
2118 's','a','x','/','p','r','o','p','e','r','t','i','e','s','/',
2119 'd','e','c','l','a','r','a','t','i','o','n',
2120 '-','h','a','n','d','l','e','r',0
2122 static const WCHAR wszDomNode
[] = {
2123 'h','t','t','p',':','/','/','x','m','l','.','o','r','g','/',
2124 's','a','x','/','p','r','o','p','e','r','t','i','e','s','/',
2125 'd','o','m','-','n','o','d','e',0
2127 static const WCHAR wszInputSource
[] = {
2128 'i','n','p','u','t','-','s','o','u','r','c','e',0
2130 static const WCHAR wszLexicalHandler
[] = {
2131 'h','t','t','p',':','/','/','x','m','l','.','o','r','g','/',
2132 's','a','x','/','p','r','o','p','e','r','t','i','e','s','/',
2133 'l','e','x','i','c','a','l','-','h','a','n','d','l','e','r',0
2135 static const WCHAR wszMaxElementDepth
[] = {
2136 'm','a','x','-','e','l','e','m','e','n','t','-','d','e','p','t','h',0
2138 static const WCHAR wszMaxXMLSize
[] = {
2139 'm','a','x','-','x','m','l','-','s','i','z','e',0
2141 static const WCHAR wszSchemaDeclarationHandler
[] = {
2142 's','c','h','e','m','a','-',
2143 'd','e','c','l','a','r','a','t','i','o','n','-',
2144 'h','a','n','d','l','e','r',0
2146 static const WCHAR wszXMLDeclEncoding
[] = {
2147 'x','m','l','d','e','c','l','-','e','n','c','o','d','i','n','g',0
2149 static const WCHAR wszXMLDeclStandalone
[] = {
2150 'x','m','l','d','e','c','l',
2151 '-','s','t','a','n','d','a','l','o','n','e',0
2153 static const WCHAR wszXMLDeclVersion
[] = {
2154 'x','m','l','d','e','c','l','-','v','e','r','s','i','o','n',0
2157 FIXME("(%p)->(%s): semi-stub\n", This
, debugstr_w(pProp
));
2159 if(!memcmp(pProp
, wszCharset
, sizeof(wszCharset
)))
2162 if(!memcmp(pProp
, wszDeclarationHandler
, sizeof(wszDeclarationHandler
)))
2164 if(This
->isParsing
) return E_FAIL
;
2166 if(V_UNKNOWN(&value
))
2169 IVBSAXDeclHandler_AddRef((IVBSAXDeclHandler
*)V_UNKNOWN(&value
));
2171 ISAXDeclHandler_AddRef((ISAXDeclHandler
*)V_UNKNOWN(&value
));
2173 if((vbInterface
&& This
->vbdeclHandler
)
2174 || (!vbInterface
&& This
->declHandler
))
2177 IVBSAXDeclHandler_Release(This
->vbdeclHandler
);
2179 ISAXDeclHandler_Release(This
->declHandler
);
2182 This
->vbdeclHandler
= (IVBSAXDeclHandler
*)V_UNKNOWN(&value
);
2184 This
->declHandler
= (ISAXDeclHandler
*)V_UNKNOWN(&value
);
2188 if(!memcmp(pProp
, wszDomNode
, sizeof(wszDomNode
)))
2191 if(!memcmp(pProp
, wszInputSource
, sizeof(wszInputSource
)))
2194 if(!memcmp(pProp
, wszLexicalHandler
, sizeof(wszLexicalHandler
)))
2196 if(This
->isParsing
) return E_FAIL
;
2198 if(V_UNKNOWN(&value
))
2201 IVBSAXLexicalHandler_AddRef(
2202 (IVBSAXLexicalHandler
*)V_UNKNOWN(&value
));
2204 ISAXLexicalHandler_AddRef(
2205 (ISAXLexicalHandler
*)V_UNKNOWN(&value
));
2207 if((vbInterface
&& This
->vblexicalHandler
)
2208 || (!vbInterface
&& This
->lexicalHandler
))
2211 IVBSAXLexicalHandler_Release(This
->vblexicalHandler
);
2213 ISAXLexicalHandler_Release(This
->lexicalHandler
);
2216 This
->vblexicalHandler
= (IVBSAXLexicalHandler
*)V_UNKNOWN(&value
);
2218 This
->lexicalHandler
= (ISAXLexicalHandler
*)V_UNKNOWN(&value
);
2222 if(!memcmp(pProp
, wszMaxElementDepth
, sizeof(wszMaxElementDepth
)))
2225 if(!memcmp(pProp
, wszMaxXMLSize
, sizeof(wszMaxXMLSize
)))
2228 if(!memcmp(pProp
, wszSchemaDeclarationHandler
,
2229 sizeof(wszSchemaDeclarationHandler
)))
2232 if(!memcmp(pProp
, wszXMLDeclEncoding
, sizeof(wszXMLDeclEncoding
)))
2235 if(!memcmp(pProp
, wszXMLDeclStandalone
, sizeof(wszXMLDeclStandalone
)))
2238 if(!memcmp(pProp
, wszXMLDeclVersion
, sizeof(wszXMLDeclVersion
)))
2241 return E_INVALIDARG
;
2244 /*** IVBSAXXMLReader interface ***/
2245 /*** IUnknown methods ***/
2246 static HRESULT WINAPI
saxxmlreader_QueryInterface(IVBSAXXMLReader
* iface
, REFIID riid
, void **ppvObject
)
2248 saxreader
*This
= impl_from_IVBSAXXMLReader( iface
);
2250 TRACE("%p %s %p\n", This
, debugstr_guid( riid
), ppvObject
);
2254 if ( IsEqualGUID( riid
, &IID_IUnknown
) ||
2255 IsEqualGUID( riid
, &IID_IDispatch
) ||
2256 IsEqualGUID( riid
, &IID_IVBSAXXMLReader
))
2260 else if( IsEqualGUID( riid
, &IID_ISAXXMLReader
))
2262 *ppvObject
= &This
->lpSAXXMLReaderVtbl
;
2266 FIXME("interface %s not implemented\n", debugstr_guid(riid
));
2267 return E_NOINTERFACE
;
2270 IVBSAXXMLReader_AddRef( iface
);
2275 static ULONG WINAPI
saxxmlreader_AddRef(IVBSAXXMLReader
* iface
)
2277 saxreader
*This
= impl_from_IVBSAXXMLReader( iface
);
2278 TRACE("%p\n", This
);
2279 return InterlockedIncrement( &This
->ref
);
2282 static ULONG WINAPI
saxxmlreader_Release(
2283 IVBSAXXMLReader
* iface
)
2285 saxreader
*This
= impl_from_IVBSAXXMLReader( iface
);
2288 TRACE("%p\n", This
);
2290 ref
= InterlockedDecrement( &This
->ref
);
2293 if(This
->contentHandler
)
2294 ISAXContentHandler_Release(This
->contentHandler
);
2296 if(This
->vbcontentHandler
)
2297 IVBSAXContentHandler_Release(This
->vbcontentHandler
);
2299 if(This
->errorHandler
)
2300 ISAXErrorHandler_Release(This
->errorHandler
);
2302 if(This
->vberrorHandler
)
2303 IVBSAXErrorHandler_Release(This
->vberrorHandler
);
2305 if(This
->lexicalHandler
)
2306 ISAXLexicalHandler_Release(This
->lexicalHandler
);
2308 if(This
->vblexicalHandler
)
2309 IVBSAXLexicalHandler_Release(This
->vblexicalHandler
);
2311 if(This
->declHandler
)
2312 ISAXDeclHandler_Release(This
->declHandler
);
2314 if(This
->vbdeclHandler
)
2315 IVBSAXDeclHandler_Release(This
->vbdeclHandler
);
2317 HeapFree( GetProcessHeap(), 0, This
);
2323 static HRESULT WINAPI
saxxmlreader_GetTypeInfoCount( IVBSAXXMLReader
*iface
, UINT
* pctinfo
)
2325 saxreader
*This
= impl_from_IVBSAXXMLReader( iface
);
2327 TRACE("(%p)->(%p)\n", This
, pctinfo
);
2334 static HRESULT WINAPI
saxxmlreader_GetTypeInfo(
2335 IVBSAXXMLReader
*iface
,
2336 UINT iTInfo
, LCID lcid
, ITypeInfo
** ppTInfo
)
2338 saxreader
*This
= impl_from_IVBSAXXMLReader( iface
);
2341 TRACE("(%p)->(%u %u %p)\n", This
, iTInfo
, lcid
, ppTInfo
);
2343 hr
= get_typeinfo(IVBSAXXMLReader_tid
, ppTInfo
);
2348 static HRESULT WINAPI
saxxmlreader_GetIDsOfNames(
2349 IVBSAXXMLReader
*iface
,
2351 LPOLESTR
* rgszNames
,
2356 saxreader
*This
= impl_from_IVBSAXXMLReader( iface
);
2357 ITypeInfo
*typeinfo
;
2360 TRACE("(%p)->(%s %p %u %u %p)\n", This
, debugstr_guid(riid
), rgszNames
, cNames
,
2363 if(!rgszNames
|| cNames
== 0 || !rgDispId
)
2364 return E_INVALIDARG
;
2366 hr
= get_typeinfo(IVBSAXXMLReader_tid
, &typeinfo
);
2369 hr
= ITypeInfo_GetIDsOfNames(typeinfo
, rgszNames
, cNames
, rgDispId
);
2370 ITypeInfo_Release(typeinfo
);
2376 static HRESULT WINAPI
saxxmlreader_Invoke(
2377 IVBSAXXMLReader
*iface
,
2378 DISPID dispIdMember
,
2382 DISPPARAMS
* pDispParams
,
2383 VARIANT
* pVarResult
,
2384 EXCEPINFO
* pExcepInfo
,
2387 saxreader
*This
= impl_from_IVBSAXXMLReader( iface
);
2388 ITypeInfo
*typeinfo
;
2391 TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This
, dispIdMember
, debugstr_guid(riid
),
2392 lcid
, wFlags
, pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
2394 hr
= get_typeinfo(IVBSAXXMLReader_tid
, &typeinfo
);
2397 hr
= ITypeInfo_Invoke(typeinfo
, &(This
->lpVBSAXXMLReaderVtbl
), dispIdMember
, wFlags
, pDispParams
,
2398 pVarResult
, pExcepInfo
, puArgErr
);
2399 ITypeInfo_Release(typeinfo
);
2405 /*** IVBSAXXMLReader methods ***/
2406 static HRESULT WINAPI
saxxmlreader_getFeature(
2407 IVBSAXXMLReader
* iface
,
2408 const WCHAR
*pFeature
,
2409 VARIANT_BOOL
*pValue
)
2411 saxreader
*This
= impl_from_IVBSAXXMLReader( iface
);
2413 FIXME("(%p)->(%s %p) stub\n", This
, debugstr_w(pFeature
), pValue
);
2417 static HRESULT WINAPI
saxxmlreader_putFeature(
2418 IVBSAXXMLReader
* iface
,
2419 const WCHAR
*pFeature
,
2420 VARIANT_BOOL vfValue
)
2422 saxreader
*This
= impl_from_IVBSAXXMLReader( iface
);
2424 FIXME("(%p)->(%s %x) stub\n", This
, debugstr_w(pFeature
), vfValue
);
2428 static HRESULT WINAPI
saxxmlreader_getProperty(
2429 IVBSAXXMLReader
* iface
,
2433 saxreader
*This
= impl_from_IVBSAXXMLReader( iface
);
2435 FIXME("(%p)->(%s %p) stub\n", This
, debugstr_w(pProp
), pValue
);
2439 static HRESULT WINAPI
saxxmlreader_putProperty(
2440 IVBSAXXMLReader
* iface
,
2444 saxreader
*This
= impl_from_IVBSAXXMLReader( iface
);
2445 return internal_putProperty(This
, pProp
, value
, TRUE
);
2448 static HRESULT WINAPI
saxxmlreader_get_entityResolver(
2449 IVBSAXXMLReader
* iface
,
2450 IVBSAXEntityResolver
**pEntityResolver
)
2452 saxreader
*This
= impl_from_IVBSAXXMLReader( iface
);
2453 return internal_getEntityResolver(This
, pEntityResolver
, TRUE
);
2456 static HRESULT WINAPI
saxxmlreader_put_entityResolver(
2457 IVBSAXXMLReader
* iface
,
2458 IVBSAXEntityResolver
*pEntityResolver
)
2460 saxreader
*This
= impl_from_IVBSAXXMLReader( iface
);
2461 return internal_putEntityResolver(This
, pEntityResolver
, TRUE
);
2464 static HRESULT WINAPI
saxxmlreader_get_contentHandler(
2465 IVBSAXXMLReader
* iface
,
2466 IVBSAXContentHandler
**ppContentHandler
)
2468 saxreader
*This
= impl_from_IVBSAXXMLReader( iface
);
2469 return internal_getContentHandler(This
, ppContentHandler
, TRUE
);
2472 static HRESULT WINAPI
saxxmlreader_put_contentHandler(
2473 IVBSAXXMLReader
* iface
,
2474 IVBSAXContentHandler
*contentHandler
)
2476 saxreader
*This
= impl_from_IVBSAXXMLReader( iface
);
2477 return internal_putContentHandler(This
, contentHandler
, TRUE
);
2480 static HRESULT WINAPI
saxxmlreader_get_dtdHandler(
2481 IVBSAXXMLReader
* iface
,
2482 IVBSAXDTDHandler
**pDTDHandler
)
2484 saxreader
*This
= impl_from_IVBSAXXMLReader( iface
);
2485 return internal_getDTDHandler(This
, pDTDHandler
, TRUE
);
2488 static HRESULT WINAPI
saxxmlreader_put_dtdHandler(
2489 IVBSAXXMLReader
* iface
,
2490 IVBSAXDTDHandler
*pDTDHandler
)
2492 saxreader
*This
= impl_from_IVBSAXXMLReader( iface
);
2493 return internal_putDTDHandler(This
, pDTDHandler
, TRUE
);
2496 static HRESULT WINAPI
saxxmlreader_get_errorHandler(
2497 IVBSAXXMLReader
* iface
,
2498 IVBSAXErrorHandler
**pErrorHandler
)
2500 saxreader
*This
= impl_from_IVBSAXXMLReader( iface
);
2501 return internal_getErrorHandler(This
, pErrorHandler
, TRUE
);
2504 static HRESULT WINAPI
saxxmlreader_put_errorHandler(
2505 IVBSAXXMLReader
* iface
,
2506 IVBSAXErrorHandler
*errorHandler
)
2508 saxreader
*This
= impl_from_IVBSAXXMLReader( iface
);
2509 return internal_putErrorHandler(This
, errorHandler
, TRUE
);
2512 static HRESULT WINAPI
saxxmlreader_get_baseURL(
2513 IVBSAXXMLReader
* iface
,
2514 const WCHAR
**pBaseUrl
)
2516 saxreader
*This
= impl_from_IVBSAXXMLReader( iface
);
2518 FIXME("(%p)->(%p) stub\n", This
, pBaseUrl
);
2522 static HRESULT WINAPI
saxxmlreader_put_baseURL(
2523 IVBSAXXMLReader
* iface
,
2524 const WCHAR
*pBaseUrl
)
2526 saxreader
*This
= impl_from_IVBSAXXMLReader( iface
);
2528 FIXME("(%p)->(%s) stub\n", This
, debugstr_w(pBaseUrl
));
2532 static HRESULT WINAPI
saxxmlreader_get_secureBaseURL(
2533 IVBSAXXMLReader
* iface
,
2534 const WCHAR
**pSecureBaseUrl
)
2536 saxreader
*This
= impl_from_IVBSAXXMLReader( iface
);
2538 FIXME("(%p)->(%p) stub\n", This
, pSecureBaseUrl
);
2543 static HRESULT WINAPI
saxxmlreader_put_secureBaseURL(
2544 IVBSAXXMLReader
* iface
,
2545 const WCHAR
*secureBaseUrl
)
2547 saxreader
*This
= impl_from_IVBSAXXMLReader( iface
);
2549 FIXME("(%p)->(%s) stub\n", This
, debugstr_w(secureBaseUrl
));
2553 static HRESULT WINAPI
saxxmlreader_parse(
2554 IVBSAXXMLReader
* iface
,
2557 saxreader
*This
= impl_from_IVBSAXXMLReader( iface
);
2558 return internal_parse(This
, varInput
, TRUE
);
2561 static HRESULT WINAPI
saxxmlreader_parseURL(
2562 IVBSAXXMLReader
* iface
,
2565 saxreader
*This
= impl_from_IVBSAXXMLReader( iface
);
2566 return internal_parseURL(This
, url
, TRUE
);
2569 static const struct IVBSAXXMLReaderVtbl saxreader_vtbl
=
2571 saxxmlreader_QueryInterface
,
2572 saxxmlreader_AddRef
,
2573 saxxmlreader_Release
,
2574 saxxmlreader_GetTypeInfoCount
,
2575 saxxmlreader_GetTypeInfo
,
2576 saxxmlreader_GetIDsOfNames
,
2577 saxxmlreader_Invoke
,
2578 saxxmlreader_getFeature
,
2579 saxxmlreader_putFeature
,
2580 saxxmlreader_getProperty
,
2581 saxxmlreader_putProperty
,
2582 saxxmlreader_get_entityResolver
,
2583 saxxmlreader_put_entityResolver
,
2584 saxxmlreader_get_contentHandler
,
2585 saxxmlreader_put_contentHandler
,
2586 saxxmlreader_get_dtdHandler
,
2587 saxxmlreader_put_dtdHandler
,
2588 saxxmlreader_get_errorHandler
,
2589 saxxmlreader_put_errorHandler
,
2590 saxxmlreader_get_baseURL
,
2591 saxxmlreader_put_baseURL
,
2592 saxxmlreader_get_secureBaseURL
,
2593 saxxmlreader_put_secureBaseURL
,
2595 saxxmlreader_parseURL
2598 /*** ISAXXMLReader interface ***/
2599 /*** IUnknown methods ***/
2600 static HRESULT WINAPI
isaxxmlreader_QueryInterface(ISAXXMLReader
* iface
, REFIID riid
, void **ppvObject
)
2602 saxreader
*This
= impl_from_ISAXXMLReader( iface
);
2603 return saxxmlreader_QueryInterface((IVBSAXXMLReader
*)&This
->lpVBSAXXMLReaderVtbl
, riid
, ppvObject
);
2606 static ULONG WINAPI
isaxxmlreader_AddRef(ISAXXMLReader
* iface
)
2608 saxreader
*This
= impl_from_ISAXXMLReader( iface
);
2609 return saxxmlreader_AddRef((IVBSAXXMLReader
*)&This
->lpVBSAXXMLReaderVtbl
);
2612 static ULONG WINAPI
isaxxmlreader_Release(ISAXXMLReader
* iface
)
2614 saxreader
*This
= impl_from_ISAXXMLReader( iface
);
2615 return saxxmlreader_Release((IVBSAXXMLReader
*)&This
->lpVBSAXXMLReaderVtbl
);
2618 /*** ISAXXMLReader methods ***/
2619 static HRESULT WINAPI
isaxxmlreader_getFeature(
2620 ISAXXMLReader
* iface
,
2621 const WCHAR
*pFeature
,
2622 VARIANT_BOOL
*pValue
)
2624 saxreader
*This
= impl_from_ISAXXMLReader( iface
);
2625 return IVBSAXXMLReader_getFeature(
2626 (IVBSAXXMLReader
*)&This
->lpVBSAXXMLReaderVtbl
,
2630 static HRESULT WINAPI
isaxxmlreader_putFeature(
2631 ISAXXMLReader
* iface
,
2632 const WCHAR
*pFeature
,
2633 VARIANT_BOOL vfValue
)
2635 saxreader
*This
= impl_from_ISAXXMLReader( iface
);
2636 return IVBSAXXMLReader_putFeature(
2637 (IVBSAXXMLReader
*)&This
->lpVBSAXXMLReaderVtbl
,
2641 static HRESULT WINAPI
isaxxmlreader_getProperty(
2642 ISAXXMLReader
* iface
,
2646 saxreader
*This
= impl_from_ISAXXMLReader( iface
);
2647 return IVBSAXXMLReader_getProperty(
2648 (IVBSAXXMLReader
*)&This
->lpVBSAXXMLReaderVtbl
,
2652 static HRESULT WINAPI
isaxxmlreader_putProperty(
2653 ISAXXMLReader
* iface
,
2657 saxreader
*This
= impl_from_ISAXXMLReader( iface
);
2658 return internal_putProperty(This
, pProp
, value
, FALSE
);
2661 static HRESULT WINAPI
isaxxmlreader_getEntityResolver(
2662 ISAXXMLReader
* iface
,
2663 ISAXEntityResolver
**ppEntityResolver
)
2665 saxreader
*This
= impl_from_ISAXXMLReader( iface
);
2666 return internal_getEntityResolver(This
, ppEntityResolver
, FALSE
);
2669 static HRESULT WINAPI
isaxxmlreader_putEntityResolver(
2670 ISAXXMLReader
* iface
,
2671 ISAXEntityResolver
*pEntityResolver
)
2673 saxreader
*This
= impl_from_ISAXXMLReader( iface
);
2674 return internal_putEntityResolver(This
, pEntityResolver
, FALSE
);
2677 static HRESULT WINAPI
isaxxmlreader_getContentHandler(
2678 ISAXXMLReader
* iface
,
2679 ISAXContentHandler
**pContentHandler
)
2681 saxreader
*This
= impl_from_ISAXXMLReader( iface
);
2682 return internal_getContentHandler(This
, pContentHandler
, FALSE
);
2685 static HRESULT WINAPI
isaxxmlreader_putContentHandler(
2686 ISAXXMLReader
* iface
,
2687 ISAXContentHandler
*contentHandler
)
2689 saxreader
*This
= impl_from_ISAXXMLReader( iface
);
2690 return internal_putContentHandler(This
, contentHandler
, FALSE
);
2693 static HRESULT WINAPI
isaxxmlreader_getDTDHandler(
2694 ISAXXMLReader
* iface
,
2695 ISAXDTDHandler
**pDTDHandler
)
2697 saxreader
*This
= impl_from_ISAXXMLReader( iface
);
2698 return internal_getDTDHandler(This
, pDTDHandler
, FALSE
);
2701 static HRESULT WINAPI
isaxxmlreader_putDTDHandler(
2702 ISAXXMLReader
* iface
,
2703 ISAXDTDHandler
*pDTDHandler
)
2705 saxreader
*This
= impl_from_ISAXXMLReader( iface
);
2706 return internal_putDTDHandler(This
, pDTDHandler
, FALSE
);
2709 static HRESULT WINAPI
isaxxmlreader_getErrorHandler(
2710 ISAXXMLReader
* iface
,
2711 ISAXErrorHandler
**pErrorHandler
)
2713 saxreader
*This
= impl_from_ISAXXMLReader( iface
);
2714 return internal_getErrorHandler(This
, pErrorHandler
, FALSE
);
2717 static HRESULT WINAPI
isaxxmlreader_putErrorHandler(
2718 ISAXXMLReader
* iface
,
2719 ISAXErrorHandler
*errorHandler
)
2721 saxreader
*This
= impl_from_ISAXXMLReader( iface
);
2722 return internal_putErrorHandler(This
, errorHandler
, FALSE
);
2725 static HRESULT WINAPI
isaxxmlreader_getBaseURL(
2726 ISAXXMLReader
* iface
,
2727 const WCHAR
**pBaseUrl
)
2729 saxreader
*This
= impl_from_ISAXXMLReader( iface
);
2730 return IVBSAXXMLReader_get_baseURL(
2731 (IVBSAXXMLReader
*)&This
->lpVBSAXXMLReaderVtbl
,
2735 static HRESULT WINAPI
isaxxmlreader_putBaseURL(
2736 ISAXXMLReader
* iface
,
2737 const WCHAR
*pBaseUrl
)
2739 saxreader
*This
= impl_from_ISAXXMLReader( iface
);
2740 return IVBSAXXMLReader_put_baseURL(
2741 (IVBSAXXMLReader
*)&This
->lpVBSAXXMLReaderVtbl
,
2745 static HRESULT WINAPI
isaxxmlreader_getSecureBaseURL(
2746 ISAXXMLReader
* iface
,
2747 const WCHAR
**pSecureBaseUrl
)
2749 saxreader
*This
= impl_from_ISAXXMLReader( iface
);
2750 return IVBSAXXMLReader_get_secureBaseURL(
2751 (IVBSAXXMLReader
*)&This
->lpVBSAXXMLReaderVtbl
,
2755 static HRESULT WINAPI
isaxxmlreader_putSecureBaseURL(
2756 ISAXXMLReader
* iface
,
2757 const WCHAR
*secureBaseUrl
)
2759 saxreader
*This
= impl_from_ISAXXMLReader( iface
);
2760 return IVBSAXXMLReader_put_secureBaseURL(
2761 (IVBSAXXMLReader
*)&This
->lpVBSAXXMLReaderVtbl
,
2765 static HRESULT WINAPI
isaxxmlreader_parse(
2766 ISAXXMLReader
* iface
,
2769 saxreader
*This
= impl_from_ISAXXMLReader( iface
);
2770 return internal_parse(This
, varInput
, FALSE
);
2773 static HRESULT WINAPI
isaxxmlreader_parseURL(
2774 ISAXXMLReader
* iface
,
2777 saxreader
*This
= impl_from_ISAXXMLReader( iface
);
2778 return internal_parseURL(This
, url
, FALSE
);
2781 static const struct ISAXXMLReaderVtbl isaxreader_vtbl
=
2783 isaxxmlreader_QueryInterface
,
2784 isaxxmlreader_AddRef
,
2785 isaxxmlreader_Release
,
2786 isaxxmlreader_getFeature
,
2787 isaxxmlreader_putFeature
,
2788 isaxxmlreader_getProperty
,
2789 isaxxmlreader_putProperty
,
2790 isaxxmlreader_getEntityResolver
,
2791 isaxxmlreader_putEntityResolver
,
2792 isaxxmlreader_getContentHandler
,
2793 isaxxmlreader_putContentHandler
,
2794 isaxxmlreader_getDTDHandler
,
2795 isaxxmlreader_putDTDHandler
,
2796 isaxxmlreader_getErrorHandler
,
2797 isaxxmlreader_putErrorHandler
,
2798 isaxxmlreader_getBaseURL
,
2799 isaxxmlreader_putBaseURL
,
2800 isaxxmlreader_getSecureBaseURL
,
2801 isaxxmlreader_putSecureBaseURL
,
2802 isaxxmlreader_parse
,
2803 isaxxmlreader_parseURL
2806 HRESULT
SAXXMLReader_create(IUnknown
*pUnkOuter
, LPVOID
*ppObj
)
2810 TRACE("(%p,%p)\n", pUnkOuter
, ppObj
);
2812 reader
= HeapAlloc( GetProcessHeap(), 0, sizeof (*reader
) );
2814 return E_OUTOFMEMORY
;
2816 reader
->lpVBSAXXMLReaderVtbl
= &saxreader_vtbl
;
2817 reader
->lpSAXXMLReaderVtbl
= &isaxreader_vtbl
;
2819 reader
->contentHandler
= NULL
;
2820 reader
->vbcontentHandler
= NULL
;
2821 reader
->errorHandler
= NULL
;
2822 reader
->vberrorHandler
= NULL
;
2823 reader
->lexicalHandler
= NULL
;
2824 reader
->vblexicalHandler
= NULL
;
2825 reader
->declHandler
= NULL
;
2826 reader
->vbdeclHandler
= NULL
;
2827 reader
->isParsing
= FALSE
;
2829 memset(&reader
->sax
, 0, sizeof(xmlSAXHandler
));
2830 reader
->sax
.initialized
= XML_SAX2_MAGIC
;
2831 reader
->sax
.startDocument
= libxmlStartDocument
;
2832 reader
->sax
.endDocument
= libxmlEndDocument
;
2833 reader
->sax
.startElementNs
= libxmlStartElementNS
;
2834 reader
->sax
.endElementNs
= libxmlEndElementNS
;
2835 reader
->sax
.characters
= libxmlCharacters
;
2836 reader
->sax
.setDocumentLocator
= libxmlSetDocumentLocator
;
2837 reader
->sax
.comment
= libxmlComment
;
2838 reader
->sax
.error
= libxmlFatalError
;
2839 reader
->sax
.fatalError
= libxmlFatalError
;
2840 reader
->sax
.cdataBlock
= libxmlCDataBlock
;
2842 *ppObj
= &reader
->lpVBSAXXMLReaderVtbl
;
2844 TRACE("returning iface %p\n", *ppObj
);
2851 HRESULT
SAXXMLReader_create(IUnknown
*pUnkOuter
, LPVOID
*ppObj
)
2853 MESSAGE("This program tried to use a SAX XML Reader object, but\n"
2854 "libxml2 support was not present at compile time.\n");