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);
54 ExhaustiveErrors = 1 << 1,
55 ExternalGeneralEntities = 1 << 2,
56 ExternalParameterEntities = 1 << 3,
57 ForcedResync = 1 << 4,
58 NamespacePrefixes = 1 << 5,
60 ParameterEntities = 1 << 7,
61 PreserveSystemIndentifiers = 1 << 8,
63 SchemaValidation = 1 << 10,
64 ServerHttpRequest = 1 << 11,
65 SuppressValidationfatalError = 1 << 12,
66 UseInlineSchema = 1 << 13,
67 UseSchemaLocation = 1 << 14,
68 LexicalHandlerParEntities = 1 << 15
78 typedef struct _saxreader
80 IVBSAXXMLReader IVBSAXXMLReader_iface;
81 ISAXXMLReader ISAXXMLReader_iface;
83 struct ISAXContentHandler *contentHandler;
84 struct IVBSAXContentHandler *vbcontentHandler;
85 struct ISAXErrorHandler *errorHandler;
86 struct IVBSAXErrorHandler *vberrorHandler;
87 struct ISAXLexicalHandler *lexicalHandler;
88 struct IVBSAXLexicalHandler *vblexicalHandler;
89 struct ISAXDeclHandler *declHandler;
90 struct IVBSAXDeclHandler *vbdeclHandler;
94 enum ReaderFeatures features;
95 MSXML_VERSION version;
98 typedef struct _saxlocator
100 IVBSAXLocator IVBSAXLocator_iface;
101 ISAXLocator ISAXLocator_iface;
102 IVBSAXAttributes IVBSAXAttributes_iface;
103 ISAXAttributes ISAXAttributes_iface;
105 saxreader *saxreader;
107 xmlParserCtxtPtr pParserCtxt;
136 static inline saxreader *impl_from_IVBSAXXMLReader( IVBSAXXMLReader *iface )
138 return CONTAINING_RECORD(iface, saxreader, IVBSAXXMLReader_iface);
141 static inline saxreader *impl_from_ISAXXMLReader( ISAXXMLReader *iface )
143 return CONTAINING_RECORD(iface, saxreader, ISAXXMLReader_iface);
146 static inline saxlocator *impl_from_IVBSAXLocator( IVBSAXLocator *iface )
148 return CONTAINING_RECORD(iface, saxlocator, IVBSAXLocator_iface);
151 static inline saxlocator *impl_from_ISAXLocator( ISAXLocator *iface )
153 return CONTAINING_RECORD(iface, saxlocator, ISAXLocator_iface);
156 static inline saxlocator *impl_from_IVBSAXAttributes( IVBSAXAttributes *iface )
158 return CONTAINING_RECORD(iface, saxlocator, IVBSAXAttributes_iface);
161 static inline saxlocator *impl_from_ISAXAttributes( ISAXAttributes *iface )
163 return CONTAINING_RECORD(iface, saxlocator, ISAXAttributes_iface);
167 static const WCHAR PropertyCharsetW[] = {
168 'c','h','a','r','s','e','t',0
170 static const WCHAR PropertyDeclHandlerW[] = {
171 'h','t','t','p',':','/','/','x','m','l','.','o','r','g','/',
172 's','a','x','/','p','r','o','p','e','r','t','i','e','s','/',
173 'd','e','c','l','a','r','a','t','i','o','n',
174 '-','h','a','n','d','l','e','r',0
176 static const WCHAR PropertyDomNodeW[] = {
177 'h','t','t','p',':','/','/','x','m','l','.','o','r','g','/',
178 's','a','x','/','p','r','o','p','e','r','t','i','e','s','/',
179 'd','o','m','-','n','o','d','e',0
181 static const WCHAR PropertyInputSourceW[] = {
182 'i','n','p','u','t','-','s','o','u','r','c','e',0
184 static const WCHAR PropertyLexicalHandlerW[] = {
185 'h','t','t','p',':','/','/','x','m','l','.','o','r','g','/',
186 's','a','x','/','p','r','o','p','e','r','t','i','e','s','/',
187 'l','e','x','i','c','a','l','-','h','a','n','d','l','e','r',0
189 static const WCHAR PropertyMaxElementDepthW[] = {
190 'm','a','x','-','e','l','e','m','e','n','t','-','d','e','p','t','h',0
192 static const WCHAR PropertyMaxXMLSizeW[] = {
193 'm','a','x','-','x','m','l','-','s','i','z','e',0
195 static const WCHAR PropertySchemaDeclHandlerW[] = {
196 's','c','h','e','m','a','-','d','e','c','l','a','r','a','t','i','o','n','-',
197 'h','a','n','d','l','e','r',0
199 static const WCHAR PropertyXMLDeclEncodingW[] = {
200 'x','m','l','d','e','c','l','-','e','n','c','o','d','i','n','g',0
202 static const WCHAR PropertyXMLDeclStandaloneW[] = {
203 'x','m','l','d','e','c','l','-','s','t','a','n','d','a','l','o','n','e',0
205 static const WCHAR PropertyXMLDeclVersionW[] = {
206 'x','m','l','d','e','c','l','-','v','e','r','s','i','o','n',0
210 static const WCHAR FeatureExternalGeneralEntitiesW[] = {
211 'h','t','t','p',':','/','/','x','m','l','.','o','r','g','/','s','a','x','/',
212 'f','e','a','t','u','r','e','s','/','e','x','t','e','r','n','a','l','-','g','e','n','e','r','a','l',
213 '-','e','n','t','i','t','i','e','s',0
216 static const WCHAR FeatureExternalParameterEntitiesW[] = {
217 'h','t','t','p',':','/','/','x','m','l','.','o','r','g','/','s','a','x','/','f','e','a','t','u','r','e','s',
218 '/','e','x','t','e','r','n','a','l','-','p','a','r','a','m','e','t','e','r','-','e','n','t','i','t','i','e','s',0
221 static const WCHAR FeatureLexicalHandlerParEntitiesW[] = {
222 'h','t','t','p',':','/','/','x','m','l','.','o','r','g','/','s','a','x','/','f','e','a','t','u','r','e','s',
223 '/','l','e','x','i','c','a','l','-','h','a','n','d','l','e','r','/','p','a','r','a','m','e','t','e','r','-','e','n','t','i','t','i','e','s',0
226 static const WCHAR FeatureProhibitDTDW[] = {
227 'p','r','o','h','i','b','i','t','-','d','t','d',0
230 static const WCHAR FeatureNamespacesW[] = {
231 'h','t','t','p',':','/','/','x','m','l','.','o','r','g','/','s','a','x','/','f','e','a','t','u','r','e','s',
232 '/','n','a','m','e','s','p','a','c','e','s',0
235 static inline HRESULT set_feature_value(saxreader *reader, enum ReaderFeatures feature, VARIANT_BOOL value)
237 if (value == VARIANT_TRUE)
238 reader->features |= feature;
240 reader->features &= ~feature;
245 static inline HRESULT get_feature_value(const saxreader *reader, enum ReaderFeatures feature, VARIANT_BOOL *value)
247 *value = reader->features & feature ? VARIANT_TRUE : VARIANT_FALSE;
251 static inline BOOL has_content_handler(const saxlocator *locator)
253 return (locator->vbInterface && locator->saxreader->vbcontentHandler) ||
254 (!locator->vbInterface && locator->saxreader->contentHandler);
257 static inline BOOL has_error_handler(const saxlocator *locator)
259 return (locator->vbInterface && locator->saxreader->vberrorHandler) ||
260 (!locator->vbInterface && locator->saxreader->errorHandler);
263 static HRESULT namespacePush(saxlocator *locator, const xmlChar *prefix,
266 if(locator->nsStackLast>=locator->nsStackSize)
268 struct nsstack *new_stack;
270 new_stack = HeapReAlloc(GetProcessHeap(), 0,
271 locator->nsStack, sizeof(struct nsstack)*locator->nsStackSize*2);
272 if(!new_stack) return E_OUTOFMEMORY;
273 locator->nsStack = new_stack;
274 locator->nsStackSize *= 2;
277 locator->nsStack[locator->nsStackLast].ptr = uri;
280 locator->nsStack[locator->nsStackLast].prefix = bstr_from_xmlChar(prefix);
281 if(!locator->nsStack[locator->nsStackLast].prefix)
282 return E_OUTOFMEMORY;
283 locator->nsStack[locator->nsStackLast].uri = bstr_from_xmlChar(uri);
284 if(!locator->nsStack[locator->nsStackLast].uri)
286 SysFreeString(locator->nsStack[locator->nsStackLast].prefix);
287 return E_OUTOFMEMORY;
292 locator->nsStack[locator->nsStackLast].prefix = NULL;
293 locator->nsStack[locator->nsStackLast].uri = NULL;
296 locator->nsStackLast++;
301 static HRESULT namespacePop(saxlocator *locator)
303 if(locator->nsStackLast == 0)
305 ERR("namespace stack is empty\n");
309 SysFreeString(locator->nsStack[--locator->nsStackLast].prefix);
310 SysFreeString(locator->nsStack[locator->nsStackLast].uri);
311 locator->nsStack[locator->nsStackLast].prefix = NULL;
312 locator->nsStack[locator->nsStackLast].uri = NULL;
316 static BSTR namespaceFind(saxlocator *locator, const xmlChar *ptr)
320 for(i=locator->nsStackLast-1; i>=0; i--)
322 if(ptr == locator->nsStack[i].ptr)
323 return locator->nsStack[i].uri;
326 ERR("namespace not found\n");
330 static BOOL bstr_pool_insert(struct bstrpool *pool, BSTR pool_entry)
334 pool->pool = HeapAlloc(GetProcessHeap(), 0, 16 * sizeof(*pool->pool));
341 else if (pool->index == pool->len)
343 BSTR *realloc = HeapReAlloc(GetProcessHeap(), 0, pool->pool, pool->len * 2 * sizeof(*realloc));
348 pool->pool = realloc;
352 pool->pool[pool->index++] = pool_entry;
356 static void free_bstr_pool(struct bstrpool *pool)
360 for (i = 0; i < pool->index; i++)
361 SysFreeString(pool->pool[i]);
363 HeapFree(GetProcessHeap(), 0, pool->pool);
366 pool->index = pool->len = 0;
369 static BSTR bstr_from_xmlCharN(const xmlChar *buf, int len)
377 dLen = MultiByteToWideChar(CP_UTF8, 0, (LPCSTR)buf, len, NULL, 0);
378 if(len != -1) dLen++;
379 bstr = SysAllocStringLen(NULL, dLen-1);
382 MultiByteToWideChar(CP_UTF8, 0, (LPCSTR)buf, len, bstr, dLen);
383 if(len != -1) bstr[dLen-1] = '\0';
388 static BSTR QName_from_xmlChar(const xmlChar *prefix, const xmlChar *name)
393 if(!name) return NULL;
395 if(!prefix || !*prefix)
396 return bstr_from_xmlChar(name);
398 qname = xmlBuildQName(name, prefix, NULL, 0);
399 bstr = bstr_from_xmlChar(qname);
405 static BSTR pooled_bstr_from_xmlChar(struct bstrpool *pool, const xmlChar *buf)
407 BSTR pool_entry = bstr_from_xmlChar(buf);
409 if (pool_entry && !bstr_pool_insert(pool, pool_entry))
411 SysFreeString(pool_entry);
418 static BSTR pooled_bstr_from_xmlCharN(struct bstrpool *pool, const xmlChar *buf, int len)
420 BSTR pool_entry = bstr_from_xmlCharN(buf, len);
422 if (pool_entry && !bstr_pool_insert(pool, pool_entry))
424 SysFreeString(pool_entry);
431 static BSTR pooled_QName_from_xmlChar(struct bstrpool *pool, const xmlChar *prefix, const xmlChar *name)
433 BSTR pool_entry = QName_from_xmlChar(prefix, name);
435 if (pool_entry && !bstr_pool_insert(pool, pool_entry))
437 SysFreeString(pool_entry);
444 static void format_error_message_from_id(saxlocator *This, HRESULT hr)
446 xmlStopParser(This->pParserCtxt);
449 if(has_error_handler(This))
452 if(!FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM,
453 NULL, hr, 0, msg, sizeof(msg), NULL))
455 FIXME("MSXML errors not yet supported.\n");
459 if(This->vbInterface)
461 BSTR bstrMsg = SysAllocString(msg);
462 IVBSAXErrorHandler_fatalError(This->saxreader->vberrorHandler,
463 &This->IVBSAXLocator_iface, &bstrMsg, hr);
464 SysFreeString(bstrMsg);
467 ISAXErrorHandler_fatalError(This->saxreader->errorHandler,
468 &This->ISAXLocator_iface, msg, hr);
472 static void update_position(saxlocator *This, xmlChar *end)
474 if(This->lastCur == NULL)
476 This->lastCur = (xmlChar*)This->pParserCtxt->input->base;
478 This->realColumn = 1;
480 else if(This->lastCur < This->pParserCtxt->input->base)
482 This->lastCur = (xmlChar*)This->pParserCtxt->input->base;
484 This->realColumn = 1;
487 if(This->pParserCtxt->input->cur<This->lastCur)
489 This->lastCur = (xmlChar*)This->pParserCtxt->input->base;
491 This->realColumn = 1;
494 if(!end) end = (xmlChar*)This->pParserCtxt->input->cur;
496 while(This->lastCur < end)
498 if(*(This->lastCur) == '\n')
501 This->realColumn = 1;
503 else if(*(This->lastCur) == '\r' &&
504 (This->lastCur==This->pParserCtxt->input->end ||
505 *(This->lastCur+1)!='\n'))
508 This->realColumn = 1;
510 else This->realColumn++;
514 /* Count multibyte UTF8 encoded characters once */
515 while((*(This->lastCur)&0xC0) == 0x80) This->lastCur++;
518 This->line = This->realLine;
519 This->column = This->realColumn;
522 /*** IVBSAXAttributes interface ***/
523 /*** IUnknown methods ***/
524 static HRESULT WINAPI ivbsaxattributes_QueryInterface(
525 IVBSAXAttributes* iface,
529 saxlocator *This = impl_from_IVBSAXAttributes(iface);
530 TRACE("%p %s %p\n", This, debugstr_guid(riid), ppvObject);
531 return IVBSAXLocator_QueryInterface(&This->IVBSAXLocator_iface, riid, ppvObject);
534 static ULONG WINAPI ivbsaxattributes_AddRef(IVBSAXAttributes* iface)
536 saxlocator *This = impl_from_IVBSAXAttributes(iface);
537 return ISAXLocator_AddRef(&This->ISAXLocator_iface);
540 static ULONG WINAPI ivbsaxattributes_Release(IVBSAXAttributes* iface)
542 saxlocator *This = impl_from_IVBSAXAttributes(iface);
543 return ISAXLocator_Release(&This->ISAXLocator_iface);
546 /*** IDispatch methods ***/
547 static HRESULT WINAPI ivbsaxattributes_GetTypeInfoCount( IVBSAXAttributes *iface, UINT* pctinfo )
549 saxlocator *This = impl_from_IVBSAXAttributes( iface );
551 TRACE("(%p)->(%p)\n", This, pctinfo);
558 static HRESULT WINAPI ivbsaxattributes_GetTypeInfo(
559 IVBSAXAttributes *iface,
560 UINT iTInfo, LCID lcid, ITypeInfo** ppTInfo )
562 saxlocator *This = impl_from_IVBSAXAttributes( iface );
565 TRACE("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo);
567 hr = get_typeinfo(IVBSAXAttributes_tid, ppTInfo);
572 static HRESULT WINAPI ivbsaxattributes_GetIDsOfNames(
573 IVBSAXAttributes *iface,
580 saxlocator *This = impl_from_IVBSAXAttributes( iface );
584 TRACE("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames, cNames,
587 if(!rgszNames || cNames == 0 || !rgDispId)
590 hr = get_typeinfo(IVBSAXAttributes_tid, &typeinfo);
593 hr = ITypeInfo_GetIDsOfNames(typeinfo, rgszNames, cNames, rgDispId);
594 ITypeInfo_Release(typeinfo);
600 static HRESULT WINAPI ivbsaxattributes_Invoke(
601 IVBSAXAttributes *iface,
606 DISPPARAMS* pDispParams,
608 EXCEPINFO* pExcepInfo,
611 saxlocator *This = impl_from_IVBSAXAttributes( iface );
615 TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
616 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
618 hr = get_typeinfo(IVBSAXAttributes_tid, &typeinfo);
621 hr = ITypeInfo_Invoke(typeinfo, &This->IVBSAXAttributes_iface, dispIdMember, wFlags,
622 pDispParams, pVarResult, pExcepInfo, puArgErr);
623 ITypeInfo_Release(typeinfo);
629 /*** IVBSAXAttributes methods ***/
630 static HRESULT WINAPI ivbsaxattributes_get_length(
631 IVBSAXAttributes* iface,
634 saxlocator *This = impl_from_IVBSAXAttributes( iface );
635 return ISAXAttributes_getLength(&This->ISAXAttributes_iface, nLength);
638 static HRESULT WINAPI ivbsaxattributes_getURI(
639 IVBSAXAttributes* iface,
644 saxlocator *This = impl_from_IVBSAXAttributes( iface );
645 return ISAXAttributes_getURI(&This->ISAXAttributes_iface, nIndex, (const WCHAR**)uri, &len);
648 static HRESULT WINAPI ivbsaxattributes_getLocalName(
649 IVBSAXAttributes* iface,
654 saxlocator *This = impl_from_IVBSAXAttributes( iface );
655 return ISAXAttributes_getLocalName(&This->ISAXAttributes_iface, nIndex,
656 (const WCHAR**)localName, &len);
659 static HRESULT WINAPI ivbsaxattributes_getQName(
660 IVBSAXAttributes* iface,
665 saxlocator *This = impl_from_IVBSAXAttributes( iface );
666 return ISAXAttributes_getQName(&This->ISAXAttributes_iface, nIndex, (const WCHAR**)QName, &len);
669 static HRESULT WINAPI ivbsaxattributes_getIndexFromName(
670 IVBSAXAttributes* iface,
675 saxlocator *This = impl_from_IVBSAXAttributes( iface );
676 return ISAXAttributes_getIndexFromName(&This->ISAXAttributes_iface, uri, SysStringLen(uri),
677 localName, SysStringLen(localName), index);
680 static HRESULT WINAPI ivbsaxattributes_getIndexFromQName(
681 IVBSAXAttributes* iface,
685 saxlocator *This = impl_from_IVBSAXAttributes( iface );
686 return ISAXAttributes_getIndexFromQName(&This->ISAXAttributes_iface, QName,
687 SysStringLen(QName), index);
690 static HRESULT WINAPI ivbsaxattributes_getType(
691 IVBSAXAttributes* iface,
696 saxlocator *This = impl_from_IVBSAXAttributes( iface );
697 return ISAXAttributes_getType(&This->ISAXAttributes_iface, nIndex, (const WCHAR**)type, &len);
700 static HRESULT WINAPI ivbsaxattributes_getTypeFromName(
701 IVBSAXAttributes* iface,
707 saxlocator *This = impl_from_IVBSAXAttributes( iface );
708 return ISAXAttributes_getTypeFromName(&This->ISAXAttributes_iface, uri, SysStringLen(uri),
709 localName, SysStringLen(localName), (const WCHAR**)type, &len);
712 static HRESULT WINAPI ivbsaxattributes_getTypeFromQName(
713 IVBSAXAttributes* iface,
718 saxlocator *This = impl_from_IVBSAXAttributes( iface );
719 return ISAXAttributes_getTypeFromQName(&This->ISAXAttributes_iface, QName, SysStringLen(QName),
720 (const WCHAR**)type, &len);
723 static HRESULT WINAPI ivbsaxattributes_getValue(
724 IVBSAXAttributes* iface,
729 saxlocator *This = impl_from_IVBSAXAttributes( iface );
730 return ISAXAttributes_getValue(&This->ISAXAttributes_iface, nIndex, (const WCHAR**)value, &len);
733 static HRESULT WINAPI ivbsaxattributes_getValueFromName(
734 IVBSAXAttributes* iface,
740 saxlocator *This = impl_from_IVBSAXAttributes( iface );
741 return ISAXAttributes_getValueFromName(&This->ISAXAttributes_iface, uri, SysStringLen(uri),
742 localName, SysStringLen(localName), (const WCHAR**)value, &len);
745 static HRESULT WINAPI ivbsaxattributes_getValueFromQName(
746 IVBSAXAttributes* iface,
751 saxlocator *This = impl_from_IVBSAXAttributes( iface );
752 return ISAXAttributes_getValueFromQName(&This->ISAXAttributes_iface, QName,
753 SysStringLen(QName), (const WCHAR**)value, &len);
756 static const struct IVBSAXAttributesVtbl ivbsaxattributes_vtbl =
758 ivbsaxattributes_QueryInterface,
759 ivbsaxattributes_AddRef,
760 ivbsaxattributes_Release,
761 ivbsaxattributes_GetTypeInfoCount,
762 ivbsaxattributes_GetTypeInfo,
763 ivbsaxattributes_GetIDsOfNames,
764 ivbsaxattributes_Invoke,
765 ivbsaxattributes_get_length,
766 ivbsaxattributes_getURI,
767 ivbsaxattributes_getLocalName,
768 ivbsaxattributes_getQName,
769 ivbsaxattributes_getIndexFromName,
770 ivbsaxattributes_getIndexFromQName,
771 ivbsaxattributes_getType,
772 ivbsaxattributes_getTypeFromName,
773 ivbsaxattributes_getTypeFromQName,
774 ivbsaxattributes_getValue,
775 ivbsaxattributes_getValueFromName,
776 ivbsaxattributes_getValueFromQName
779 /*** ISAXAttributes interface ***/
780 /*** IUnknown methods ***/
781 static HRESULT WINAPI isaxattributes_QueryInterface(
782 ISAXAttributes* iface,
786 saxlocator *This = impl_from_ISAXAttributes(iface);
787 TRACE("%p %s %p\n", This, debugstr_guid(riid), ppvObject);
788 return ISAXLocator_QueryInterface(&This->ISAXLocator_iface, riid, ppvObject);
791 static ULONG WINAPI isaxattributes_AddRef(ISAXAttributes* iface)
793 saxlocator *This = impl_from_ISAXAttributes(iface);
795 return ISAXLocator_AddRef(&This->ISAXLocator_iface);
798 static ULONG WINAPI isaxattributes_Release(ISAXAttributes* iface)
800 saxlocator *This = impl_from_ISAXAttributes(iface);
803 return ISAXLocator_Release(&This->ISAXLocator_iface);
806 /*** ISAXAttributes methods ***/
807 static HRESULT WINAPI isaxattributes_getLength(
808 ISAXAttributes* iface,
811 saxlocator *This = impl_from_ISAXAttributes( iface );
813 *length = This->nb_attributes;
814 TRACE("Length set to %d\n", *length);
818 static HRESULT WINAPI isaxattributes_getURI(
819 ISAXAttributes* iface,
824 saxlocator *This = impl_from_ISAXAttributes( iface );
825 TRACE("(%p)->(%d)\n", This, index);
827 if(index >= This->nb_attributes || index < 0) return E_INVALIDARG;
828 if(!url || !size) return E_POINTER;
830 *size = SysStringLen(This->attributes[index].szURI);
831 *url = This->attributes[index].szURI;
833 TRACE("(%s:%d)\n", debugstr_w(This->attributes[index].szURI), *size);
838 static HRESULT WINAPI isaxattributes_getLocalName(
839 ISAXAttributes* iface,
841 const WCHAR **pLocalName,
842 int *pLocalNameLength)
844 saxlocator *This = impl_from_ISAXAttributes( iface );
845 TRACE("(%p)->(%d)\n", This, nIndex);
847 if(nIndex>=This->nb_attributes || nIndex<0) return E_INVALIDARG;
848 if(!pLocalName || !pLocalNameLength) return E_POINTER;
850 *pLocalNameLength = SysStringLen(This->attributes[nIndex].szLocalname);
851 *pLocalName = This->attributes[nIndex].szLocalname;
856 static HRESULT WINAPI isaxattributes_getQName(
857 ISAXAttributes* iface,
859 const WCHAR **pQName,
862 saxlocator *This = impl_from_ISAXAttributes( iface );
863 TRACE("(%p)->(%d)\n", This, nIndex);
865 if(nIndex>=This->nb_attributes || nIndex<0) return E_INVALIDARG;
866 if(!pQName || !pQNameLength) return E_POINTER;
868 *pQNameLength = SysStringLen(This->attributes[nIndex].szQName);
869 *pQName = This->attributes[nIndex].szQName;
874 static HRESULT WINAPI isaxattributes_getName(
875 ISAXAttributes* iface,
879 const WCHAR **localName,
884 saxlocator *This = impl_from_ISAXAttributes( iface );
885 TRACE("(%p)->(%d)\n", This, index);
887 if(index>=This->nb_attributes || index<0) return E_INVALIDARG;
888 if(!uri || !pUriLength || !localName || !pLocalNameSize
889 || !QName || !pQNameLength) return E_POINTER;
891 *pUriLength = SysStringLen(This->attributes[index].szURI);
892 *uri = This->attributes[index].szURI;
893 *pLocalNameSize = SysStringLen(This->attributes[index].szLocalname);
894 *localName = This->attributes[index].szLocalname;
895 *pQNameLength = SysStringLen(This->attributes[index].szQName);
896 *QName = This->attributes[index].szQName;
898 TRACE("(%s, %s, %s)\n", debugstr_w(*uri), debugstr_w(*localName), debugstr_w(*QName));
903 static HRESULT WINAPI isaxattributes_getIndexFromName(
904 ISAXAttributes* iface,
907 const WCHAR *pLocalName,
911 saxlocator *This = impl_from_ISAXAttributes( iface );
913 TRACE("(%p)->(%s, %d, %s, %d)\n", This, debugstr_w(pUri), cUriLength,
914 debugstr_w(pLocalName), cocalNameLength);
916 if(!pUri || !pLocalName || !index) return E_POINTER;
918 for(i=0; i<This->nb_attributes; i++)
920 if(cUriLength!=SysStringLen(This->attributes[i].szURI)
921 || cocalNameLength!=SysStringLen(This->attributes[i].szLocalname))
923 if(cUriLength && memcmp(pUri, This->attributes[i].szURI,
924 sizeof(WCHAR)*cUriLength))
926 if(cocalNameLength && memcmp(pLocalName, This->attributes[i].szLocalname,
927 sizeof(WCHAR)*cocalNameLength))
937 static HRESULT WINAPI isaxattributes_getIndexFromQName(
938 ISAXAttributes* iface,
943 saxlocator *This = impl_from_ISAXAttributes( iface );
945 TRACE("(%p)->(%s, %d)\n", This, debugstr_w(pQName), nQNameLength);
947 if(!pQName || !index) return E_POINTER;
948 if(!nQNameLength) return E_INVALIDARG;
950 for(i=0; i<This->nb_attributes; i++)
952 if(nQNameLength!=SysStringLen(This->attributes[i].szQName)) continue;
953 if(memcmp(pQName, This->attributes[i].szQName, sizeof(WCHAR)*nQNameLength)) continue;
962 static HRESULT WINAPI isaxattributes_getType(
963 ISAXAttributes* iface,
968 saxlocator *This = impl_from_ISAXAttributes( iface );
970 FIXME("(%p)->(%d) stub\n", This, nIndex);
974 static HRESULT WINAPI isaxattributes_getTypeFromName(
975 ISAXAttributes* iface,
978 const WCHAR *pLocalName,
983 saxlocator *This = impl_from_ISAXAttributes( iface );
985 FIXME("(%p)->(%s, %d, %s, %d) stub\n", This, debugstr_w(pUri), nUri,
986 debugstr_w(pLocalName), nLocalName);
990 static HRESULT WINAPI isaxattributes_getTypeFromQName(
991 ISAXAttributes* iface,
997 saxlocator *This = impl_from_ISAXAttributes( iface );
999 FIXME("(%p)->(%s, %d) stub\n", This, debugstr_w(pQName), nQName);
1003 static HRESULT WINAPI isaxattributes_getValue(
1004 ISAXAttributes* iface,
1006 const WCHAR **value,
1009 saxlocator *This = impl_from_ISAXAttributes( iface );
1010 TRACE("(%p)->(%d)\n", This, index);
1012 if(index>=This->nb_attributes || index<0) return E_INVALIDARG;
1013 if(!value || !nValue) return E_POINTER;
1015 *nValue = SysStringLen(This->attributes[index].szValue);
1016 *value = This->attributes[index].szValue;
1018 TRACE("(%s:%d)\n", debugstr_w(*value), *nValue);
1023 static HRESULT WINAPI isaxattributes_getValueFromName(
1024 ISAXAttributes* iface,
1027 const WCHAR *pLocalName,
1029 const WCHAR **pValue,
1034 saxlocator *This = impl_from_ISAXAttributes( iface );
1035 TRACE("(%p)->(%s, %d, %s, %d)\n", This, debugstr_w(pUri), nUri,
1036 debugstr_w(pLocalName), nLocalName);
1038 hr = ISAXAttributes_getIndexFromName(iface,
1039 pUri, nUri, pLocalName, nLocalName, &index);
1040 if(hr==S_OK) hr = ISAXAttributes_getValue(iface, index, pValue, nValue);
1045 static HRESULT WINAPI isaxattributes_getValueFromQName(
1046 ISAXAttributes* iface,
1047 const WCHAR *pQName,
1049 const WCHAR **pValue,
1054 saxlocator *This = impl_from_ISAXAttributes( iface );
1055 TRACE("(%p)->(%s, %d)\n", This, debugstr_w(pQName), nQName);
1057 hr = ISAXAttributes_getIndexFromQName(iface, pQName, nQName, &index);
1058 if(hr==S_OK) hr = ISAXAttributes_getValue(iface, index, pValue, nValue);
1063 static const struct ISAXAttributesVtbl isaxattributes_vtbl =
1065 isaxattributes_QueryInterface,
1066 isaxattributes_AddRef,
1067 isaxattributes_Release,
1068 isaxattributes_getLength,
1069 isaxattributes_getURI,
1070 isaxattributes_getLocalName,
1071 isaxattributes_getQName,
1072 isaxattributes_getName,
1073 isaxattributes_getIndexFromName,
1074 isaxattributes_getIndexFromQName,
1075 isaxattributes_getType,
1076 isaxattributes_getTypeFromName,
1077 isaxattributes_getTypeFromQName,
1078 isaxattributes_getValue,
1079 isaxattributes_getValueFromName,
1080 isaxattributes_getValueFromQName
1083 static HRESULT SAXAttributes_populate(saxlocator *locator,
1084 int nb_namespaces, const xmlChar **xmlNamespaces,
1085 int nb_attributes, const xmlChar **xmlAttributes)
1087 static const xmlChar xmlns[] = "xmlns";
1088 static const WCHAR xmlnsW[] = { 'x','m','l','n','s',0 };
1089 static const WCHAR w3xmlns[] = { 'h','t','t','p',':','/','/', 'w','w','w','.','w','3','.',
1090 'o','r','g','/','2','0','0','0','/','x','m','l','n','s','/',0 };
1092 struct _attributes *attrs;
1095 locator->nb_attributes = nb_namespaces+nb_attributes;
1096 if(locator->nb_attributes > locator->attributesSize)
1098 attrs = heap_realloc(locator->attributes, sizeof(struct _attributes)*locator->nb_attributes*2);
1101 locator->nb_attributes = 0;
1102 return E_OUTOFMEMORY;
1104 locator->attributes = attrs;
1108 attrs = locator->attributes;
1111 for(index=0; index<nb_namespaces; index++)
1113 attrs[nb_attributes+index].szLocalname = SysAllocStringLen(NULL, 0);
1114 if(locator->saxreader->version >= MSXML6)
1115 attrs[nb_attributes+index].szURI = SysAllocString(w3xmlns);
1117 attrs[nb_attributes+index].szURI = SysAllocStringLen(NULL, 0);
1118 attrs[nb_attributes+index].szValue = bstr_from_xmlChar(xmlNamespaces[2*index+1]);
1119 if(!xmlNamespaces[2*index])
1120 attrs[nb_attributes+index].szQName = SysAllocString(xmlnsW);
1122 attrs[nb_attributes+index].szQName = QName_from_xmlChar(xmlns, xmlNamespaces[2*index]);
1125 for(index=0; index<nb_attributes; index++)
1127 attrs[index].szLocalname = bstr_from_xmlChar(xmlAttributes[index*5]);
1128 attrs[index].szURI = bstr_from_xmlChar(xmlAttributes[index*5+2]);
1129 attrs[index].szValue = bstr_from_xmlCharN(xmlAttributes[index*5+3],
1130 xmlAttributes[index*5+4]-xmlAttributes[index*5+3]);
1131 attrs[index].szQName = QName_from_xmlChar(xmlAttributes[index*5+1],
1132 xmlAttributes[index*5]);
1138 /*** LibXML callbacks ***/
1139 static void libxmlStartDocument(void *ctx)
1141 saxlocator *This = ctx;
1144 if(This->saxreader->version >= MSXML6) {
1145 xmlChar *end = (xmlChar*)This->pParserCtxt->input->cur;
1146 while(end>This->pParserCtxt->input->base && *end!='>')
1148 update_position(This, end);
1151 if(has_content_handler(This))
1153 if(This->vbInterface)
1154 hr = IVBSAXContentHandler_startDocument(This->saxreader->vbcontentHandler);
1156 hr = ISAXContentHandler_startDocument(This->saxreader->contentHandler);
1158 if(This->saxreader->version>=MSXML6 ? FAILED(hr) : hr!=S_OK)
1159 format_error_message_from_id(This, hr);
1162 update_position(This, NULL);
1165 static void libxmlEndDocument(void *ctx)
1167 saxlocator *This = ctx;
1170 if(This->saxreader->version >= MSXML6) {
1171 update_position(This, NULL);
1172 if(This->column > 1)
1180 if(This->ret != S_OK) return;
1182 if(has_content_handler(This))
1184 if(This->vbInterface)
1185 hr = IVBSAXContentHandler_endDocument(This->saxreader->vbcontentHandler);
1187 hr = ISAXContentHandler_endDocument(This->saxreader->contentHandler);
1189 if(This->saxreader->version>=MSXML6 ? FAILED(hr) : hr!=S_OK)
1190 format_error_message_from_id(This, hr);
1194 static void libxmlStartElementNS(
1196 const xmlChar *localname,
1197 const xmlChar *prefix,
1200 const xmlChar **namespaces,
1203 const xmlChar **attributes)
1205 BSTR NamespaceUri, LocalName, QName;
1206 saxlocator *This = ctx;
1211 if(*(This->pParserCtxt->input->cur) == '/')
1213 if(This->saxreader->version < MSXML6)
1215 update_position(This, (xmlChar*)This->pParserCtxt->input->cur+index);
1217 hr = namespacePush(This, NULL, NULL);
1218 for(index=0; hr==S_OK && index<nb_namespaces; index++)
1219 hr = namespacePush(This, namespaces[2*index], namespaces[2*index+1]);
1222 for(; index>=0; index--)
1227 if(hr==S_OK && has_content_handler(This))
1229 for(index=0; index<nb_namespaces; index++)
1231 if(This->vbInterface)
1232 hr = IVBSAXContentHandler_startPrefixMapping(
1233 This->saxreader->vbcontentHandler,
1234 &This->nsStack[This->nsStackLast-nb_namespaces+index].prefix,
1235 &This->nsStack[This->nsStackLast-nb_namespaces+index].uri);
1237 hr = ISAXContentHandler_startPrefixMapping(
1238 This->saxreader->contentHandler,
1239 This->nsStack[This->nsStackLast-nb_namespaces+index].prefix,
1240 SysStringLen(This->nsStack[This->nsStackLast-nb_namespaces+index].prefix),
1241 This->nsStack[This->nsStackLast-nb_namespaces+index].uri,
1242 SysStringLen(This->nsStack[This->nsStackLast-nb_namespaces+index].uri));
1244 if(This->saxreader->version>=MSXML6 ? FAILED(hr) : hr!=S_OK)
1246 format_error_message_from_id(This, hr);
1251 NamespaceUri = namespaceFind(This, URI);
1252 LocalName = pooled_bstr_from_xmlChar(&This->saxreader->pool, localname);
1253 QName = pooled_QName_from_xmlChar(&This->saxreader->pool, prefix, localname);
1255 hr = SAXAttributes_populate(This, nb_namespaces, namespaces, nb_attributes, attributes);
1258 if(This->vbInterface)
1259 hr = IVBSAXContentHandler_startElement(This->saxreader->vbcontentHandler,
1260 &NamespaceUri, &LocalName, &QName, &This->IVBSAXAttributes_iface);
1262 hr = ISAXContentHandler_startElement(This->saxreader->contentHandler, NamespaceUri,
1263 SysStringLen(NamespaceUri), LocalName, SysStringLen(LocalName), QName,
1264 SysStringLen(QName), &This->ISAXAttributes_iface);
1268 if(This->saxreader->version>=MSXML6 ? FAILED(hr) : hr!=S_OK)
1269 format_error_message_from_id(This, hr);
1272 static void libxmlEndElementNS(
1274 const xmlChar *localname,
1275 const xmlChar *prefix,
1278 BSTR NamespaceUri, LocalName, QName;
1279 saxlocator *This = ctx;
1282 struct nsstack *elem = &This->nsStack[This->nsStackLast-1];
1284 end = (xmlChar*)This->pParserCtxt->input->cur;
1285 if(This->saxreader->version >= MSXML6) {
1286 while(end>This->pParserCtxt->input->base && *end!='>')
1288 } else if(*(end-1) != '>' || *(end-2) != '/') {
1289 while(end-2>=This->pParserCtxt->input->base
1290 && *(end-2)!='<' && *(end-1)!='/') end--;
1293 update_position(This, end);
1295 if(has_content_handler(This))
1297 NamespaceUri = namespaceFind(This, URI);
1298 LocalName = pooled_bstr_from_xmlChar(&This->saxreader->pool, localname);
1299 QName = pooled_QName_from_xmlChar(&This->saxreader->pool, prefix, localname);
1301 if(This->vbInterface)
1302 hr = IVBSAXContentHandler_endElement(
1303 This->saxreader->vbcontentHandler,
1304 &NamespaceUri, &LocalName, &QName);
1306 hr = ISAXContentHandler_endElement(
1307 This->saxreader->contentHandler,
1308 NamespaceUri, SysStringLen(NamespaceUri),
1309 LocalName, SysStringLen(LocalName),
1310 QName, SysStringLen(QName));
1312 This->nb_attributes = 0;
1314 if(This->saxreader->version>=MSXML6 ? FAILED(hr) : hr!=S_OK)
1316 format_error_message_from_id(This, hr);
1320 if(This->saxreader->version >= MSXML6)
1327 while(elem < &This->nsStack[This->nsStackLast]) {
1328 if(This->vbInterface)
1329 hr = IVBSAXContentHandler_endPrefixMapping(
1330 This->saxreader->vbcontentHandler, &elem->prefix);
1332 hr = ISAXContentHandler_endPrefixMapping(
1333 This->saxreader->contentHandler,
1334 elem->prefix, SysStringLen(elem->prefix));
1338 format_error_message_from_id(This, hr);
1357 if(This->vbInterface)
1358 hr = IVBSAXContentHandler_endPrefixMapping(
1359 This->saxreader->vbcontentHandler, &elem->prefix);
1361 hr = ISAXContentHandler_endPrefixMapping(
1362 This->saxreader->contentHandler,
1363 elem->prefix, SysStringLen(elem->prefix));
1367 format_error_message_from_id(This, hr);
1378 This->nb_attributes = 0;
1386 update_position(This, NULL);
1389 static void libxmlCharacters(
1394 saxlocator *This = ctx;
1399 BOOL lastEvent = FALSE;
1401 if(!(has_content_handler(This))) return;
1404 if(*(ch-1)=='\r') cur--;
1407 if(ch<This->pParserCtxt->input->base || ch>This->pParserCtxt->input->end)
1412 while(end-ch<len && *end!='\r') end++;
1419 if(!lastEvent) *end = '\n';
1421 if(This->saxreader->version >= MSXML6) {
1422 update_position(This, end);
1433 Chars = pooled_bstr_from_xmlCharN(&This->saxreader->pool, cur, end-cur+1);
1434 if(This->vbInterface)
1435 hr = IVBSAXContentHandler_characters(
1436 This->saxreader->vbcontentHandler, &Chars);
1438 hr = ISAXContentHandler_characters(
1439 This->saxreader->contentHandler,
1440 Chars, SysStringLen(Chars));
1442 if(This->saxreader->version>=MSXML6 ? FAILED(hr) : hr!=S_OK)
1444 format_error_message_from_id(This, hr);
1448 This->column += end-cur+1;
1462 if(end-ch == len) break;
1465 if(ch<This->pParserCtxt->input->base || ch>This->pParserCtxt->input->end)
1466 This->column = This->realColumn
1467 +This->pParserCtxt->input->cur-This->lastCur;
1470 static void libxmlSetDocumentLocator(
1472 xmlSAXLocatorPtr loc)
1474 saxlocator *This = ctx;
1477 if(has_content_handler(This))
1479 if(This->vbInterface)
1480 hr = IVBSAXContentHandler_putref_documentLocator(This->saxreader->vbcontentHandler,
1481 &This->IVBSAXLocator_iface);
1483 hr = ISAXContentHandler_putDocumentLocator(This->saxreader->contentHandler,
1484 &This->ISAXLocator_iface);
1488 format_error_message_from_id(This, hr);
1491 static void libxmlComment(void *ctx, const xmlChar *value)
1493 saxlocator *This = ctx;
1496 xmlChar *beg = (xmlChar*)This->pParserCtxt->input->cur;
1498 while(beg-4>=This->pParserCtxt->input->base
1499 && memcmp(beg-4, "<!--", sizeof(char[4]))) beg--;
1500 update_position(This, beg);
1502 if(!This->vbInterface && !This->saxreader->lexicalHandler) return;
1503 if(This->vbInterface && !This->saxreader->vblexicalHandler) return;
1505 bValue = pooled_bstr_from_xmlChar(&This->saxreader->pool, value);
1507 if(This->vbInterface)
1508 hr = IVBSAXLexicalHandler_comment(
1509 This->saxreader->vblexicalHandler, &bValue);
1511 hr = ISAXLexicalHandler_comment(
1512 This->saxreader->lexicalHandler,
1513 bValue, SysStringLen(bValue));
1516 format_error_message_from_id(This, hr);
1518 update_position(This, NULL);
1521 static void libxmlFatalError(void *ctx, const char *msg, ...)
1523 saxlocator *This = ctx;
1529 if(This->ret != S_OK) {
1530 xmlStopParser(This->pParserCtxt);
1534 va_start(args, msg);
1535 vsprintf(message, msg, args);
1538 len = MultiByteToWideChar(CP_UNIXCP, 0, message, -1, NULL, 0);
1539 error = heap_alloc(sizeof(WCHAR)*len);
1542 MultiByteToWideChar(CP_UNIXCP, 0, message, -1, error, len);
1543 TRACE("fatal error for %p: %s\n", This, debugstr_w(error));
1546 if(!has_error_handler(This))
1548 xmlStopParser(This->pParserCtxt);
1554 FIXME("Error handling is not compatible.\n");
1556 if(This->vbInterface)
1558 BSTR bstrError = SysAllocString(error);
1559 IVBSAXErrorHandler_fatalError(This->saxreader->vberrorHandler, &This->IVBSAXLocator_iface,
1560 &bstrError, E_FAIL);
1561 SysFreeString(bstrError);
1564 ISAXErrorHandler_fatalError(This->saxreader->errorHandler, &This->ISAXLocator_iface,
1569 xmlStopParser(This->pParserCtxt);
1573 static void libxmlCDataBlock(void *ctx, const xmlChar *value, int len)
1575 saxlocator *This = ctx;
1577 xmlChar *beg = (xmlChar*)This->pParserCtxt->input->cur-len;
1581 BOOL lastEvent = FALSE, change;
1583 while(beg-9>=This->pParserCtxt->input->base
1584 && memcmp(beg-9, "<![CDATA[", sizeof(char[9]))) beg--;
1585 update_position(This, beg);
1587 if(This->vbInterface && This->saxreader->vblexicalHandler)
1588 hr = IVBSAXLexicalHandler_startCDATA(This->saxreader->vblexicalHandler);
1589 if(!This->vbInterface && This->saxreader->lexicalHandler)
1590 hr = ISAXLexicalHandler_startCDATA(This->saxreader->lexicalHandler);
1594 format_error_message_from_id(This, hr);
1598 realLen = This->pParserCtxt->input->cur-beg-3;
1604 while(end-beg<realLen && *end!='\r') end++;
1605 if(end-beg==realLen)
1610 else if(end-beg==realLen-1 && *end=='\r' && *(end+1)=='\n')
1613 if(*end == '\r') change = TRUE;
1614 else change = FALSE;
1616 if(change) *end = '\n';
1618 if(has_content_handler(This))
1620 Chars = pooled_bstr_from_xmlCharN(&This->saxreader->pool, cur, end-cur+1);
1621 if(This->vbInterface)
1622 hr = IVBSAXContentHandler_characters(
1623 This->saxreader->vbcontentHandler, &Chars);
1625 hr = ISAXContentHandler_characters(
1626 This->saxreader->contentHandler,
1627 Chars, SysStringLen(Chars));
1630 if(change) *end = '\r';
1635 This->column += end-cur+2;
1640 if(This->vbInterface && This->saxreader->vblexicalHandler)
1641 hr = IVBSAXLexicalHandler_endCDATA(This->saxreader->vblexicalHandler);
1642 if(!This->vbInterface && This->saxreader->lexicalHandler)
1643 hr = ISAXLexicalHandler_endCDATA(This->saxreader->lexicalHandler);
1646 format_error_message_from_id(This, hr);
1648 This->column += 4+end-cur;
1651 /*** IVBSAXLocator interface ***/
1652 /*** IUnknown methods ***/
1653 static HRESULT WINAPI ivbsaxlocator_QueryInterface(IVBSAXLocator* iface, REFIID riid, void **ppvObject)
1655 saxlocator *This = impl_from_IVBSAXLocator( iface );
1657 TRACE("%p %s %p\n", This, debugstr_guid( riid ), ppvObject);
1661 if ( IsEqualGUID( riid, &IID_IUnknown ) ||
1662 IsEqualGUID( riid, &IID_IDispatch) ||
1663 IsEqualGUID( riid, &IID_IVBSAXLocator ))
1667 else if ( IsEqualGUID( riid, &IID_IVBSAXAttributes ))
1669 *ppvObject = &This->IVBSAXAttributes_iface;
1673 FIXME("interface %s not implemented\n", debugstr_guid(riid));
1674 return E_NOINTERFACE;
1677 IVBSAXLocator_AddRef( iface );
1682 static ULONG WINAPI ivbsaxlocator_AddRef(IVBSAXLocator* iface)
1684 saxlocator *This = impl_from_IVBSAXLocator( iface );
1685 TRACE("%p\n", This );
1686 return InterlockedIncrement( &This->ref );
1689 static ULONG WINAPI ivbsaxlocator_Release(
1690 IVBSAXLocator* iface)
1692 saxlocator *This = impl_from_IVBSAXLocator( iface );
1693 return ISAXLocator_Release((ISAXLocator*)&This->IVBSAXLocator_iface);
1696 /*** IDispatch methods ***/
1697 static HRESULT WINAPI ivbsaxlocator_GetTypeInfoCount( IVBSAXLocator *iface, UINT* pctinfo )
1699 saxlocator *This = impl_from_IVBSAXLocator( iface );
1701 TRACE("(%p)->(%p)\n", This, pctinfo);
1708 static HRESULT WINAPI ivbsaxlocator_GetTypeInfo(
1709 IVBSAXLocator *iface,
1710 UINT iTInfo, LCID lcid, ITypeInfo** ppTInfo )
1712 saxlocator *This = impl_from_IVBSAXLocator( iface );
1715 TRACE("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo);
1717 hr = get_typeinfo(IVBSAXLocator_tid, ppTInfo);
1722 static HRESULT WINAPI ivbsaxlocator_GetIDsOfNames(
1723 IVBSAXLocator *iface,
1725 LPOLESTR* rgszNames,
1730 saxlocator *This = impl_from_IVBSAXLocator( iface );
1731 ITypeInfo *typeinfo;
1734 TRACE("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames, cNames,
1737 if(!rgszNames || cNames == 0 || !rgDispId)
1738 return E_INVALIDARG;
1740 hr = get_typeinfo(IVBSAXLocator_tid, &typeinfo);
1743 hr = ITypeInfo_GetIDsOfNames(typeinfo, rgszNames, cNames, rgDispId);
1744 ITypeInfo_Release(typeinfo);
1750 static HRESULT WINAPI ivbsaxlocator_Invoke(
1751 IVBSAXLocator *iface,
1752 DISPID dispIdMember,
1756 DISPPARAMS* pDispParams,
1757 VARIANT* pVarResult,
1758 EXCEPINFO* pExcepInfo,
1761 saxlocator *This = impl_from_IVBSAXLocator( iface );
1762 ITypeInfo *typeinfo;
1765 TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
1766 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
1768 hr = get_typeinfo(IVBSAXLocator_tid, &typeinfo);
1771 hr = ITypeInfo_Invoke(typeinfo, &This->IVBSAXLocator_iface, dispIdMember, wFlags,
1772 pDispParams, pVarResult, pExcepInfo, puArgErr);
1773 ITypeInfo_Release(typeinfo);
1779 /*** IVBSAXLocator methods ***/
1780 static HRESULT WINAPI ivbsaxlocator_get_columnNumber(
1781 IVBSAXLocator* iface,
1784 saxlocator *This = impl_from_IVBSAXLocator( iface );
1785 return ISAXLocator_getColumnNumber((ISAXLocator*)&This->IVBSAXLocator_iface, pnColumn);
1788 static HRESULT WINAPI ivbsaxlocator_get_lineNumber(
1789 IVBSAXLocator* iface,
1792 saxlocator *This = impl_from_IVBSAXLocator( iface );
1793 return ISAXLocator_getLineNumber((ISAXLocator*)&This->IVBSAXLocator_iface, pnLine);
1796 static HRESULT WINAPI ivbsaxlocator_get_publicId(
1797 IVBSAXLocator* iface,
1800 saxlocator *This = impl_from_IVBSAXLocator( iface );
1801 return ISAXLocator_getPublicId((ISAXLocator*)&This->IVBSAXLocator_iface,
1802 (const WCHAR**)publicId);
1805 static HRESULT WINAPI ivbsaxlocator_get_systemId(
1806 IVBSAXLocator* iface,
1809 saxlocator *This = impl_from_IVBSAXLocator( iface );
1810 return ISAXLocator_getSystemId((ISAXLocator*)&This->IVBSAXLocator_iface,
1811 (const WCHAR**)systemId);
1814 static const struct IVBSAXLocatorVtbl ivbsaxlocator_vtbl =
1816 ivbsaxlocator_QueryInterface,
1817 ivbsaxlocator_AddRef,
1818 ivbsaxlocator_Release,
1819 ivbsaxlocator_GetTypeInfoCount,
1820 ivbsaxlocator_GetTypeInfo,
1821 ivbsaxlocator_GetIDsOfNames,
1822 ivbsaxlocator_Invoke,
1823 ivbsaxlocator_get_columnNumber,
1824 ivbsaxlocator_get_lineNumber,
1825 ivbsaxlocator_get_publicId,
1826 ivbsaxlocator_get_systemId
1829 /*** ISAXLocator interface ***/
1830 /*** IUnknown methods ***/
1831 static HRESULT WINAPI isaxlocator_QueryInterface(ISAXLocator* iface, REFIID riid, void **ppvObject)
1833 saxlocator *This = impl_from_ISAXLocator( iface );
1835 TRACE("%p %s %p\n", This, debugstr_guid( riid ), ppvObject );
1839 if ( IsEqualGUID( riid, &IID_IUnknown ) ||
1840 IsEqualGUID( riid, &IID_ISAXLocator ))
1844 else if ( IsEqualGUID( riid, &IID_ISAXAttributes ))
1846 *ppvObject = &This->ISAXAttributes_iface;
1850 FIXME("interface %s not implemented\n", debugstr_guid(riid));
1851 return E_NOINTERFACE;
1854 ISAXLocator_AddRef( iface );
1859 static ULONG WINAPI isaxlocator_AddRef(ISAXLocator* iface)
1861 saxlocator *This = impl_from_ISAXLocator( iface );
1862 TRACE("%p\n", This );
1863 return InterlockedIncrement( &This->ref );
1866 static ULONG WINAPI isaxlocator_Release(
1869 saxlocator *This = impl_from_ISAXLocator( iface );
1872 TRACE("%p\n", This );
1874 ref = InterlockedDecrement( &This->ref );
1879 SysFreeString(This->publicId);
1880 SysFreeString(This->systemId);
1881 while(This->nsStackLast)
1883 heap_free(This->nsStack);
1885 for(index=0; index<This->nb_attributes; index++)
1887 SysFreeString(This->attributes[index].szLocalname);
1888 SysFreeString(This->attributes[index].szURI);
1889 SysFreeString(This->attributes[index].szValue);
1890 SysFreeString(This->attributes[index].szQName);
1892 heap_free(This->attributes);
1894 ISAXXMLReader_Release(&This->saxreader->ISAXXMLReader_iface);
1901 /*** ISAXLocator methods ***/
1902 static HRESULT WINAPI isaxlocator_getColumnNumber(
1906 saxlocator *This = impl_from_ISAXLocator( iface );
1908 *pnColumn = This->column;
1912 static HRESULT WINAPI isaxlocator_getLineNumber(
1916 saxlocator *This = impl_from_ISAXLocator( iface );
1918 *pnLine = This->line;
1922 static HRESULT WINAPI isaxlocator_getPublicId(
1924 const WCHAR ** ppwchPublicId)
1927 saxlocator *This = impl_from_ISAXLocator( iface );
1929 SysFreeString(This->publicId);
1931 publicId = bstr_from_xmlChar(xmlSAX2GetPublicId(This->pParserCtxt));
1932 if(SysStringLen(publicId))
1933 This->publicId = (WCHAR*)&publicId;
1936 SysFreeString(publicId);
1937 This->publicId = NULL;
1940 *ppwchPublicId = This->publicId;
1944 static HRESULT WINAPI isaxlocator_getSystemId(
1946 const WCHAR ** ppwchSystemId)
1949 saxlocator *This = impl_from_ISAXLocator( iface );
1951 SysFreeString(This->systemId);
1953 systemId = bstr_from_xmlChar(xmlSAX2GetSystemId(This->pParserCtxt));
1954 if(SysStringLen(systemId))
1955 This->systemId = (WCHAR*)&systemId;
1958 SysFreeString(systemId);
1959 This->systemId = NULL;
1962 *ppwchSystemId = This->systemId;
1966 static const struct ISAXLocatorVtbl isaxlocator_vtbl =
1968 isaxlocator_QueryInterface,
1970 isaxlocator_Release,
1971 isaxlocator_getColumnNumber,
1972 isaxlocator_getLineNumber,
1973 isaxlocator_getPublicId,
1974 isaxlocator_getSystemId
1977 static HRESULT SAXLocator_create(saxreader *reader, saxlocator **ppsaxlocator, BOOL vbInterface)
1979 saxlocator *locator;
1981 locator = heap_alloc( sizeof (*locator) );
1983 return E_OUTOFMEMORY;
1985 locator->IVBSAXLocator_iface.lpVtbl = &ivbsaxlocator_vtbl;
1986 locator->ISAXLocator_iface.lpVtbl = &isaxlocator_vtbl;
1987 locator->IVBSAXAttributes_iface.lpVtbl = &ivbsaxattributes_vtbl;
1988 locator->ISAXAttributes_iface.lpVtbl = &isaxattributes_vtbl;
1990 locator->vbInterface = vbInterface;
1992 locator->saxreader = reader;
1993 ISAXXMLReader_AddRef(&reader->ISAXXMLReader_iface);
1995 locator->pParserCtxt = NULL;
1996 locator->publicId = NULL;
1997 locator->systemId = NULL;
1998 locator->lastCur = NULL;
1999 locator->line = (reader->version>=MSXML6 ? 1 : 0);
2000 locator->column = 0;
2001 locator->ret = S_OK;
2002 locator->nsStackSize = 8;
2003 locator->nsStackLast = 0;
2004 locator->nsStack = heap_alloc(sizeof(struct nsstack)*locator->nsStackSize);
2005 if(!locator->nsStack)
2007 ISAXXMLReader_Release(&reader->ISAXXMLReader_iface);
2009 return E_OUTOFMEMORY;
2012 locator->attributesSize = 8;
2013 locator->nb_attributes = 0;
2014 locator->attributes = heap_alloc(sizeof(struct _attributes)*locator->attributesSize);
2015 if(!locator->attributes)
2017 ISAXXMLReader_Release(&reader->ISAXXMLReader_iface);
2018 heap_free(locator->nsStack);
2020 return E_OUTOFMEMORY;
2023 *ppsaxlocator = locator;
2025 TRACE("returning %p\n", *ppsaxlocator);
2030 /*** SAXXMLReader internal functions ***/
2031 static HRESULT internal_parseBuffer(saxreader *This, const char *buffer, int size, BOOL vbInterface)
2033 xmlCharEncoding encoding = XML_CHAR_ENCODING_NONE;
2034 xmlChar *enc_name = NULL;
2035 saxlocator *locator;
2038 hr = SAXLocator_create(This, &locator, vbInterface);
2044 const unsigned char *buff = (unsigned char*)buffer;
2046 encoding = xmlDetectCharEncoding((xmlChar*)buffer, 4);
2047 enc_name = (xmlChar*)xmlGetCharEncodingName(encoding);
2048 TRACE("detected encoding: %s\n", enc_name);
2049 /* skip BOM, parser won't switch encodings and so won't skip it on its own */
2050 if ((encoding == XML_CHAR_ENCODING_UTF8) &&
2051 buff[0] == 0xEF && buff[1] == 0xBB && buff[2] == 0xBF)
2058 locator->pParserCtxt = xmlCreateMemoryParserCtxt(buffer, size);
2059 if(!locator->pParserCtxt)
2061 ISAXLocator_Release(&locator->ISAXLocator_iface);
2065 if (encoding == XML_CHAR_ENCODING_UTF8)
2066 locator->pParserCtxt->encoding = xmlStrdup(enc_name);
2068 xmlFree(locator->pParserCtxt->sax);
2069 locator->pParserCtxt->sax = &locator->saxreader->sax;
2070 locator->pParserCtxt->userData = locator;
2072 This->isParsing = TRUE;
2073 if(xmlParseDocument(locator->pParserCtxt)==-1 && locator->ret==S_OK)
2077 This->isParsing = FALSE;
2079 if(locator->pParserCtxt)
2081 locator->pParserCtxt->sax = NULL;
2082 xmlFreeParserCtxt(locator->pParserCtxt);
2083 locator->pParserCtxt = NULL;
2086 ISAXLocator_Release(&locator->ISAXLocator_iface);
2090 static HRESULT internal_parseStream(saxreader *This, IStream *stream, BOOL vbInterface)
2092 saxlocator *locator;
2099 hr = IStream_Read(stream, data, sizeof(data), &dataRead);
2100 if(FAILED(hr)) return hr;
2102 hr = SAXLocator_create(This, &locator, vbInterface);
2103 if(FAILED(hr)) return hr;
2105 locator->pParserCtxt = xmlCreatePushParserCtxt(
2106 &locator->saxreader->sax, locator,
2107 data, dataRead, NULL);
2108 if(!locator->pParserCtxt)
2110 ISAXLocator_Release(&locator->ISAXLocator_iface);
2114 This->isParsing = TRUE;
2116 if(dataRead != sizeof(data))
2118 ret = xmlParseChunk(locator->pParserCtxt, data, 0, 1);
2119 hr = ret!=XML_ERR_OK && locator->ret==S_OK ? E_FAIL : locator->ret;
2126 hr = IStream_Read(stream, data, sizeof(data), &dataRead);
2127 if (FAILED(hr)) break;
2129 ret = xmlParseChunk(locator->pParserCtxt, data, dataRead, 0);
2130 hr = ret!=XML_ERR_OK && locator->ret==S_OK ? E_FAIL : locator->ret;
2132 if (hr != S_OK) break;
2134 if (dataRead != sizeof(data))
2136 ret = xmlParseChunk(locator->pParserCtxt, data, 0, 1);
2137 hr = ret!=XML_ERR_OK && locator->ret==S_OK ? E_FAIL : locator->ret;
2143 This->isParsing = FALSE;
2145 xmlFreeParserCtxt(locator->pParserCtxt);
2146 locator->pParserCtxt = NULL;
2147 ISAXLocator_Release(&locator->ISAXLocator_iface);
2151 static HRESULT internal_getEntityResolver(
2153 void *pEntityResolver,
2156 FIXME("(%p)->(%p) stub\n", This, pEntityResolver);
2160 static HRESULT internal_putEntityResolver(
2162 void *pEntityResolver,
2165 FIXME("(%p)->(%p) stub\n", This, pEntityResolver);
2169 static HRESULT internal_getContentHandler(
2171 void *pContentHandler,
2174 TRACE("(%p)->(%p)\n", This, pContentHandler);
2175 if(pContentHandler == NULL)
2177 if((vbInterface && This->vbcontentHandler)
2178 || (!vbInterface && This->contentHandler))
2181 IVBSAXContentHandler_AddRef(This->vbcontentHandler);
2183 ISAXContentHandler_AddRef(This->contentHandler);
2185 if(vbInterface) *(IVBSAXContentHandler**)pContentHandler =
2186 This->vbcontentHandler;
2187 else *(ISAXContentHandler**)pContentHandler = This->contentHandler;
2192 static HRESULT internal_putContentHandler(
2194 void *contentHandler,
2197 TRACE("(%p)->(%p)\n", This, contentHandler);
2201 IVBSAXContentHandler_AddRef((IVBSAXContentHandler*)contentHandler);
2203 ISAXContentHandler_AddRef((ISAXContentHandler*)contentHandler);
2205 if((vbInterface && This->vbcontentHandler)
2206 || (!vbInterface && This->contentHandler))
2209 IVBSAXContentHandler_Release(This->vbcontentHandler);
2211 ISAXContentHandler_Release(This->contentHandler);
2214 This->vbcontentHandler = contentHandler;
2216 This->contentHandler = contentHandler;
2221 static HRESULT internal_getDTDHandler(
2226 FIXME("(%p)->(%p) stub\n", This, pDTDHandler);
2230 static HRESULT internal_putDTDHandler(
2235 FIXME("(%p)->(%p) stub\n", This, pDTDHandler);
2239 static HRESULT internal_getErrorHandler(
2241 void *pErrorHandler,
2244 TRACE("(%p)->(%p)\n", This, pErrorHandler);
2245 if(pErrorHandler == NULL)
2248 if(vbInterface && This->vberrorHandler)
2249 IVBSAXErrorHandler_AddRef(This->vberrorHandler);
2250 else if(!vbInterface && This->errorHandler)
2251 ISAXErrorHandler_AddRef(This->errorHandler);
2254 *(IVBSAXErrorHandler**)pErrorHandler = This->vberrorHandler;
2256 *(ISAXErrorHandler**)pErrorHandler = This->errorHandler;
2262 static HRESULT internal_putErrorHandler(
2267 TRACE("(%p)->(%p)\n", This, errorHandler);
2271 IVBSAXErrorHandler_AddRef((IVBSAXErrorHandler*)errorHandler);
2273 ISAXErrorHandler_AddRef((ISAXErrorHandler*)errorHandler);
2276 if(vbInterface && This->vberrorHandler)
2277 IVBSAXErrorHandler_Release(This->vberrorHandler);
2278 else if(!vbInterface && This->errorHandler)
2279 ISAXErrorHandler_Release(This->errorHandler);
2282 This->vberrorHandler = errorHandler;
2284 This->errorHandler = errorHandler;
2290 static HRESULT internal_parse(
2297 TRACE("(%p)->(%s)\n", This, debugstr_variant(&varInput));
2299 /* Dispose of the BSTRs in the pool from a prior run, if any. */
2300 free_bstr_pool(&This->pool);
2302 switch(V_VT(&varInput))
2305 hr = internal_parseBuffer(This, (const char*)V_BSTR(&varInput),
2306 SysStringByteLen(V_BSTR(&varInput)), vbInterface);
2308 case VT_ARRAY|VT_UI1: {
2310 LONG lBound, uBound;
2313 hr = SafeArrayGetLBound(V_ARRAY(&varInput), 1, &lBound);
2314 if(hr != S_OK) break;
2315 hr = SafeArrayGetUBound(V_ARRAY(&varInput), 1, &uBound);
2316 if(hr != S_OK) break;
2317 dataRead = (uBound-lBound)*SafeArrayGetElemsize(V_ARRAY(&varInput));
2318 hr = SafeArrayAccessData(V_ARRAY(&varInput), &pSAData);
2319 if(hr != S_OK) break;
2320 hr = internal_parseBuffer(This, pSAData, dataRead, vbInterface);
2321 SafeArrayUnaccessData(V_ARRAY(&varInput));
2326 IPersistStream *persistStream;
2327 IStream *stream = NULL;
2328 IXMLDOMDocument *xmlDoc;
2330 if(IUnknown_QueryInterface(V_UNKNOWN(&varInput),
2331 &IID_IXMLDOMDocument, (void**)&xmlDoc) == S_OK)
2335 IXMLDOMDocument_get_xml(xmlDoc, &bstrData);
2336 hr = internal_parseBuffer(This, (const char*)bstrData,
2337 SysStringByteLen(bstrData), vbInterface);
2338 IXMLDOMDocument_Release(xmlDoc);
2339 SysFreeString(bstrData);
2343 if(IUnknown_QueryInterface(V_UNKNOWN(&varInput),
2344 &IID_IPersistStream, (void**)&persistStream) == S_OK)
2346 hr = CreateStreamOnHGlobal(NULL, TRUE, &stream);
2349 IPersistStream_Release(persistStream);
2353 hr = IPersistStream_Save(persistStream, stream, TRUE);
2354 IPersistStream_Release(persistStream);
2357 IStream_Release(stream);
2361 if(stream || IUnknown_QueryInterface(V_UNKNOWN(&varInput),
2362 &IID_IStream, (void**)&stream) == S_OK)
2364 hr = internal_parseStream(This, stream, vbInterface);
2365 IStream_Release(stream);
2370 WARN("vt %d not implemented\n", V_VT(&varInput));
2377 static HRESULT internal_vbonDataAvailable(void *obj, char *ptr, DWORD len)
2379 saxreader *This = obj;
2381 return internal_parseBuffer(This, ptr, len, TRUE);
2384 static HRESULT internal_onDataAvailable(void *obj, char *ptr, DWORD len)
2386 saxreader *This = obj;
2388 return internal_parseBuffer(This, ptr, len, FALSE);
2391 static HRESULT internal_parseURL(
2399 TRACE("(%p)->(%s)\n", This, debugstr_w(url));
2401 if(vbInterface) hr = bind_url(url, internal_vbonDataAvailable, This, &bsc);
2402 else hr = bind_url(url, internal_onDataAvailable, This, &bsc);
2407 return detach_bsc(bsc);
2410 static HRESULT internal_putProperty(
2416 TRACE("(%p)->(%s %s)\n", This, debugstr_w(prop), debugstr_variant(&value));
2418 if(!memcmp(prop, PropertyDeclHandlerW, sizeof(PropertyDeclHandlerW)))
2420 if(This->isParsing) return E_FAIL;
2422 switch (V_VT(&value))
2427 if (This->vbdeclHandler)
2429 IVBSAXDeclHandler_Release(This->vbdeclHandler);
2430 This->vbdeclHandler = NULL;
2434 if (This->declHandler)
2436 ISAXDeclHandler_Release(This->declHandler);
2437 This->declHandler = NULL;
2441 if (V_UNKNOWN(&value)) IUnknown_AddRef(V_UNKNOWN(&value));
2443 if ((vbInterface && This->vbdeclHandler) ||
2444 (!vbInterface && This->declHandler))
2447 IVBSAXDeclHandler_Release(This->vbdeclHandler);
2449 ISAXDeclHandler_Release(This->declHandler);
2453 This->vbdeclHandler = (IVBSAXDeclHandler*)V_UNKNOWN(&value);
2455 This->declHandler = (ISAXDeclHandler*)V_UNKNOWN(&value);
2458 return E_INVALIDARG;
2464 if(!memcmp(prop, PropertyLexicalHandlerW, sizeof(PropertyLexicalHandlerW)))
2466 if(This->isParsing) return E_FAIL;
2468 switch (V_VT(&value))
2473 if (This->vblexicalHandler)
2475 IVBSAXLexicalHandler_Release(This->vblexicalHandler);
2476 This->vblexicalHandler = NULL;
2480 if (This->lexicalHandler)
2482 ISAXLexicalHandler_Release(This->lexicalHandler);
2483 This->lexicalHandler = NULL;
2487 if (V_UNKNOWN(&value)) IUnknown_AddRef(V_UNKNOWN(&value));
2489 if ((vbInterface && This->vblexicalHandler) ||
2490 (!vbInterface && This->lexicalHandler))
2493 IVBSAXLexicalHandler_Release(This->vblexicalHandler);
2495 ISAXLexicalHandler_Release(This->lexicalHandler);
2499 This->vblexicalHandler = (IVBSAXLexicalHandler*)V_UNKNOWN(&value);
2501 This->lexicalHandler = (ISAXLexicalHandler*)V_UNKNOWN(&value);
2504 return E_INVALIDARG;
2510 if(!memcmp(prop, PropertyMaxXMLSizeW, sizeof(PropertyMaxXMLSizeW)))
2512 if (V_VT(&value) == VT_I4 && V_I4(&value) == 0) return S_OK;
2513 FIXME("(%p)->(%s): max-xml-size unsupported\n", This, debugstr_variant(&value));
2517 if(!memcmp(prop, PropertyMaxElementDepthW, sizeof(PropertyMaxElementDepthW)))
2519 if (V_VT(&value) == VT_I4 && V_I4(&value) == 0) return S_OK;
2520 FIXME("(%p)->(%s): max-element-depth unsupported\n", This, debugstr_variant(&value));
2524 FIXME("(%p)->(%s:%s): unsupported property\n", This, debugstr_w(prop), debugstr_variant(&value));
2526 if(!memcmp(prop, PropertyCharsetW, sizeof(PropertyCharsetW)))
2529 if(!memcmp(prop, PropertyDomNodeW, sizeof(PropertyDomNodeW)))
2532 if(!memcmp(prop, PropertyInputSourceW, sizeof(PropertyInputSourceW)))
2535 if(!memcmp(prop, PropertySchemaDeclHandlerW, sizeof(PropertySchemaDeclHandlerW)))
2538 if(!memcmp(prop, PropertyXMLDeclEncodingW, sizeof(PropertyXMLDeclEncodingW)))
2541 if(!memcmp(prop, PropertyXMLDeclStandaloneW, sizeof(PropertyXMLDeclStandaloneW)))
2544 if(!memcmp(prop, PropertyXMLDeclVersionW, sizeof(PropertyXMLDeclVersionW)))
2547 return E_INVALIDARG;
2550 static HRESULT internal_getProperty(const saxreader* This, const WCHAR *prop, VARIANT *value, BOOL vb)
2552 TRACE("(%p)->(%s)\n", This, debugstr_w(prop));
2554 if (!value) return E_POINTER;
2556 if (!memcmp(PropertyLexicalHandlerW, prop, sizeof(PropertyLexicalHandlerW)))
2558 V_VT(value) = VT_UNKNOWN;
2559 V_UNKNOWN(value) = vb ? (IUnknown*)This->vblexicalHandler : (IUnknown*)This->lexicalHandler;
2560 if (V_UNKNOWN(value)) IUnknown_AddRef(V_UNKNOWN(value));
2564 if (!memcmp(PropertyDeclHandlerW, prop, sizeof(PropertyDeclHandlerW)))
2566 V_VT(value) = VT_UNKNOWN;
2567 V_UNKNOWN(value) = vb ? (IUnknown*)This->vbdeclHandler : (IUnknown*)This->declHandler;
2568 if (V_UNKNOWN(value)) IUnknown_AddRef(V_UNKNOWN(value));
2572 FIXME("(%p)->(%s) unsupported property\n", This, debugstr_w(prop));
2577 /*** IVBSAXXMLReader interface ***/
2578 /*** IUnknown methods ***/
2579 static HRESULT WINAPI saxxmlreader_QueryInterface(IVBSAXXMLReader* iface, REFIID riid, void **ppvObject)
2581 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2583 TRACE("%p %s %p\n", This, debugstr_guid( riid ), ppvObject );
2587 if ( IsEqualGUID( riid, &IID_IUnknown ) ||
2588 IsEqualGUID( riid, &IID_IDispatch ) ||
2589 IsEqualGUID( riid, &IID_IVBSAXXMLReader ))
2593 else if( IsEqualGUID( riid, &IID_ISAXXMLReader ))
2595 *ppvObject = &This->ISAXXMLReader_iface;
2599 FIXME("interface %s not implemented\n", debugstr_guid(riid));
2600 return E_NOINTERFACE;
2603 IVBSAXXMLReader_AddRef( iface );
2608 static ULONG WINAPI saxxmlreader_AddRef(IVBSAXXMLReader* iface)
2610 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2611 TRACE("%p\n", This );
2612 return InterlockedIncrement( &This->ref );
2615 static ULONG WINAPI saxxmlreader_Release(
2616 IVBSAXXMLReader* iface)
2618 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2621 TRACE("%p\n", This );
2623 ref = InterlockedDecrement( &This->ref );
2626 if(This->contentHandler)
2627 ISAXContentHandler_Release(This->contentHandler);
2629 if(This->vbcontentHandler)
2630 IVBSAXContentHandler_Release(This->vbcontentHandler);
2632 if(This->errorHandler)
2633 ISAXErrorHandler_Release(This->errorHandler);
2635 if(This->vberrorHandler)
2636 IVBSAXErrorHandler_Release(This->vberrorHandler);
2638 if(This->lexicalHandler)
2639 ISAXLexicalHandler_Release(This->lexicalHandler);
2641 if(This->vblexicalHandler)
2642 IVBSAXLexicalHandler_Release(This->vblexicalHandler);
2644 if(This->declHandler)
2645 ISAXDeclHandler_Release(This->declHandler);
2647 if(This->vbdeclHandler)
2648 IVBSAXDeclHandler_Release(This->vbdeclHandler);
2650 free_bstr_pool(&This->pool);
2658 static HRESULT WINAPI saxxmlreader_GetTypeInfoCount( IVBSAXXMLReader *iface, UINT* pctinfo )
2660 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2662 TRACE("(%p)->(%p)\n", This, pctinfo);
2669 static HRESULT WINAPI saxxmlreader_GetTypeInfo(
2670 IVBSAXXMLReader *iface,
2671 UINT iTInfo, LCID lcid, ITypeInfo** ppTInfo )
2673 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2676 TRACE("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo);
2678 hr = get_typeinfo(IVBSAXXMLReader_tid, ppTInfo);
2683 static HRESULT WINAPI saxxmlreader_GetIDsOfNames(
2684 IVBSAXXMLReader *iface,
2686 LPOLESTR* rgszNames,
2691 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2692 ITypeInfo *typeinfo;
2695 TRACE("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames, cNames,
2698 if(!rgszNames || cNames == 0 || !rgDispId)
2699 return E_INVALIDARG;
2701 hr = get_typeinfo(IVBSAXXMLReader_tid, &typeinfo);
2704 hr = ITypeInfo_GetIDsOfNames(typeinfo, rgszNames, cNames, rgDispId);
2705 ITypeInfo_Release(typeinfo);
2711 static HRESULT WINAPI saxxmlreader_Invoke(
2712 IVBSAXXMLReader *iface,
2713 DISPID dispIdMember,
2717 DISPPARAMS* pDispParams,
2718 VARIANT* pVarResult,
2719 EXCEPINFO* pExcepInfo,
2722 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2723 ITypeInfo *typeinfo;
2726 TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
2727 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
2729 hr = get_typeinfo(IVBSAXXMLReader_tid, &typeinfo);
2732 hr = ITypeInfo_Invoke(typeinfo, &This->IVBSAXXMLReader_iface, dispIdMember, wFlags,
2733 pDispParams, pVarResult, pExcepInfo, puArgErr);
2734 ITypeInfo_Release(typeinfo);
2740 /*** IVBSAXXMLReader methods ***/
2741 static HRESULT WINAPI saxxmlreader_getFeature(
2742 IVBSAXXMLReader* iface,
2743 const WCHAR *feature,
2744 VARIANT_BOOL *value)
2746 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2748 if (!strcmpW(FeatureNamespacesW, feature))
2749 return get_feature_value(This, Namespaces, value);
2751 FIXME("(%p)->(%s %p) stub\n", This, debugstr_w(feature), value);
2755 static HRESULT WINAPI saxxmlreader_putFeature(
2756 IVBSAXXMLReader* iface,
2757 const WCHAR *feature,
2760 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2762 TRACE("(%p)->(%s %x)\n", This, debugstr_w(feature), value);
2764 if (!strcmpW(FeatureExternalGeneralEntitiesW, feature) && value == VARIANT_FALSE)
2765 return set_feature_value(This, ExternalGeneralEntities, value);
2767 if (!strcmpW(FeatureExternalParameterEntitiesW, feature) && value == VARIANT_FALSE)
2768 return set_feature_value(This, ExternalParameterEntities, value);
2770 if (!strcmpW(FeatureLexicalHandlerParEntitiesW, feature))
2772 FIXME("(%p)->(%s %x) stub\n", This, debugstr_w(feature), value);
2773 return set_feature_value(This, LexicalHandlerParEntities, value);
2776 if (!strcmpW(FeatureProhibitDTDW, feature))
2778 FIXME("(%p)->(%s %x) stub\n", This, debugstr_w(feature), value);
2779 return set_feature_value(This, ProhibitDTD, value);
2782 if (!strcmpW(FeatureNamespacesW, feature) && value == VARIANT_TRUE)
2783 return set_feature_value(This, Namespaces, value);
2785 FIXME("(%p)->(%s %x) stub\n", This, debugstr_w(feature), value);
2789 static HRESULT WINAPI saxxmlreader_getProperty(
2790 IVBSAXXMLReader* iface,
2794 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2795 return internal_getProperty(This, prop, value, TRUE);
2798 static HRESULT WINAPI saxxmlreader_putProperty(
2799 IVBSAXXMLReader* iface,
2803 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2804 return internal_putProperty(This, pProp, value, TRUE);
2807 static HRESULT WINAPI saxxmlreader_get_entityResolver(
2808 IVBSAXXMLReader* iface,
2809 IVBSAXEntityResolver **pEntityResolver)
2811 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2812 return internal_getEntityResolver(This, pEntityResolver, TRUE);
2815 static HRESULT WINAPI saxxmlreader_put_entityResolver(
2816 IVBSAXXMLReader* iface,
2817 IVBSAXEntityResolver *pEntityResolver)
2819 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2820 return internal_putEntityResolver(This, pEntityResolver, TRUE);
2823 static HRESULT WINAPI saxxmlreader_get_contentHandler(
2824 IVBSAXXMLReader* iface,
2825 IVBSAXContentHandler **ppContentHandler)
2827 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2828 return internal_getContentHandler(This, ppContentHandler, TRUE);
2831 static HRESULT WINAPI saxxmlreader_put_contentHandler(
2832 IVBSAXXMLReader* iface,
2833 IVBSAXContentHandler *contentHandler)
2835 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2836 return internal_putContentHandler(This, contentHandler, TRUE);
2839 static HRESULT WINAPI saxxmlreader_get_dtdHandler(
2840 IVBSAXXMLReader* iface,
2841 IVBSAXDTDHandler **pDTDHandler)
2843 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2844 return internal_getDTDHandler(This, pDTDHandler, TRUE);
2847 static HRESULT WINAPI saxxmlreader_put_dtdHandler(
2848 IVBSAXXMLReader* iface,
2849 IVBSAXDTDHandler *pDTDHandler)
2851 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2852 return internal_putDTDHandler(This, pDTDHandler, TRUE);
2855 static HRESULT WINAPI saxxmlreader_get_errorHandler(
2856 IVBSAXXMLReader* iface,
2857 IVBSAXErrorHandler **pErrorHandler)
2859 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2860 return internal_getErrorHandler(This, pErrorHandler, TRUE);
2863 static HRESULT WINAPI saxxmlreader_put_errorHandler(
2864 IVBSAXXMLReader* iface,
2865 IVBSAXErrorHandler *errorHandler)
2867 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2868 return internal_putErrorHandler(This, errorHandler, TRUE);
2871 static HRESULT WINAPI saxxmlreader_get_baseURL(
2872 IVBSAXXMLReader* iface,
2873 const WCHAR **pBaseUrl)
2875 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2877 FIXME("(%p)->(%p) stub\n", This, pBaseUrl);
2881 static HRESULT WINAPI saxxmlreader_put_baseURL(
2882 IVBSAXXMLReader* iface,
2883 const WCHAR *pBaseUrl)
2885 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2887 FIXME("(%p)->(%s) stub\n", This, debugstr_w(pBaseUrl));
2891 static HRESULT WINAPI saxxmlreader_get_secureBaseURL(
2892 IVBSAXXMLReader* iface,
2893 const WCHAR **pSecureBaseUrl)
2895 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2897 FIXME("(%p)->(%p) stub\n", This, pSecureBaseUrl);
2902 static HRESULT WINAPI saxxmlreader_put_secureBaseURL(
2903 IVBSAXXMLReader* iface,
2904 const WCHAR *secureBaseUrl)
2906 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2908 FIXME("(%p)->(%s) stub\n", This, debugstr_w(secureBaseUrl));
2912 static HRESULT WINAPI saxxmlreader_parse(
2913 IVBSAXXMLReader* iface,
2916 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2917 return internal_parse(This, varInput, TRUE);
2920 static HRESULT WINAPI saxxmlreader_parseURL(
2921 IVBSAXXMLReader* iface,
2924 saxreader *This = impl_from_IVBSAXXMLReader( iface );
2925 return internal_parseURL(This, url, TRUE);
2928 static const struct IVBSAXXMLReaderVtbl saxreader_vtbl =
2930 saxxmlreader_QueryInterface,
2931 saxxmlreader_AddRef,
2932 saxxmlreader_Release,
2933 saxxmlreader_GetTypeInfoCount,
2934 saxxmlreader_GetTypeInfo,
2935 saxxmlreader_GetIDsOfNames,
2936 saxxmlreader_Invoke,
2937 saxxmlreader_getFeature,
2938 saxxmlreader_putFeature,
2939 saxxmlreader_getProperty,
2940 saxxmlreader_putProperty,
2941 saxxmlreader_get_entityResolver,
2942 saxxmlreader_put_entityResolver,
2943 saxxmlreader_get_contentHandler,
2944 saxxmlreader_put_contentHandler,
2945 saxxmlreader_get_dtdHandler,
2946 saxxmlreader_put_dtdHandler,
2947 saxxmlreader_get_errorHandler,
2948 saxxmlreader_put_errorHandler,
2949 saxxmlreader_get_baseURL,
2950 saxxmlreader_put_baseURL,
2951 saxxmlreader_get_secureBaseURL,
2952 saxxmlreader_put_secureBaseURL,
2954 saxxmlreader_parseURL
2957 /*** ISAXXMLReader interface ***/
2958 /*** IUnknown methods ***/
2959 static HRESULT WINAPI isaxxmlreader_QueryInterface(ISAXXMLReader* iface, REFIID riid, void **ppvObject)
2961 saxreader *This = impl_from_ISAXXMLReader( iface );
2962 return saxxmlreader_QueryInterface(&This->IVBSAXXMLReader_iface, riid, ppvObject);
2965 static ULONG WINAPI isaxxmlreader_AddRef(ISAXXMLReader* iface)
2967 saxreader *This = impl_from_ISAXXMLReader( iface );
2968 return saxxmlreader_AddRef(&This->IVBSAXXMLReader_iface);
2971 static ULONG WINAPI isaxxmlreader_Release(ISAXXMLReader* iface)
2973 saxreader *This = impl_from_ISAXXMLReader( iface );
2974 return saxxmlreader_Release(&This->IVBSAXXMLReader_iface);
2977 /*** ISAXXMLReader methods ***/
2978 static HRESULT WINAPI isaxxmlreader_getFeature(
2979 ISAXXMLReader* iface,
2980 const WCHAR *pFeature,
2981 VARIANT_BOOL *pValue)
2983 saxreader *This = impl_from_ISAXXMLReader( iface );
2984 return IVBSAXXMLReader_getFeature(&This->IVBSAXXMLReader_iface, pFeature, pValue);
2987 static HRESULT WINAPI isaxxmlreader_putFeature(
2988 ISAXXMLReader* iface,
2989 const WCHAR *pFeature,
2990 VARIANT_BOOL vfValue)
2992 saxreader *This = impl_from_ISAXXMLReader( iface );
2993 return IVBSAXXMLReader_putFeature(&This->IVBSAXXMLReader_iface, pFeature, vfValue);
2996 static HRESULT WINAPI isaxxmlreader_getProperty(
2997 ISAXXMLReader* iface,
3001 saxreader *This = impl_from_ISAXXMLReader( iface );
3002 return internal_getProperty(This, prop, value, FALSE);
3005 static HRESULT WINAPI isaxxmlreader_putProperty(
3006 ISAXXMLReader* iface,
3010 saxreader *This = impl_from_ISAXXMLReader( iface );
3011 return internal_putProperty(This, pProp, value, FALSE);
3014 static HRESULT WINAPI isaxxmlreader_getEntityResolver(
3015 ISAXXMLReader* iface,
3016 ISAXEntityResolver **ppEntityResolver)
3018 saxreader *This = impl_from_ISAXXMLReader( iface );
3019 return internal_getEntityResolver(This, ppEntityResolver, FALSE);
3022 static HRESULT WINAPI isaxxmlreader_putEntityResolver(
3023 ISAXXMLReader* iface,
3024 ISAXEntityResolver *pEntityResolver)
3026 saxreader *This = impl_from_ISAXXMLReader( iface );
3027 return internal_putEntityResolver(This, pEntityResolver, FALSE);
3030 static HRESULT WINAPI isaxxmlreader_getContentHandler(
3031 ISAXXMLReader* iface,
3032 ISAXContentHandler **pContentHandler)
3034 saxreader *This = impl_from_ISAXXMLReader( iface );
3035 return internal_getContentHandler(This, pContentHandler, FALSE);
3038 static HRESULT WINAPI isaxxmlreader_putContentHandler(
3039 ISAXXMLReader* iface,
3040 ISAXContentHandler *contentHandler)
3042 saxreader *This = impl_from_ISAXXMLReader( iface );
3043 return internal_putContentHandler(This, contentHandler, FALSE);
3046 static HRESULT WINAPI isaxxmlreader_getDTDHandler(
3047 ISAXXMLReader* iface,
3048 ISAXDTDHandler **pDTDHandler)
3050 saxreader *This = impl_from_ISAXXMLReader( iface );
3051 return internal_getDTDHandler(This, pDTDHandler, FALSE);
3054 static HRESULT WINAPI isaxxmlreader_putDTDHandler(
3055 ISAXXMLReader* iface,
3056 ISAXDTDHandler *pDTDHandler)
3058 saxreader *This = impl_from_ISAXXMLReader( iface );
3059 return internal_putDTDHandler(This, pDTDHandler, FALSE);
3062 static HRESULT WINAPI isaxxmlreader_getErrorHandler(
3063 ISAXXMLReader* iface,
3064 ISAXErrorHandler **pErrorHandler)
3066 saxreader *This = impl_from_ISAXXMLReader( iface );
3067 return internal_getErrorHandler(This, pErrorHandler, FALSE);
3070 static HRESULT WINAPI isaxxmlreader_putErrorHandler(
3071 ISAXXMLReader* iface,
3072 ISAXErrorHandler *errorHandler)
3074 saxreader *This = impl_from_ISAXXMLReader( iface );
3075 return internal_putErrorHandler(This, errorHandler, FALSE);
3078 static HRESULT WINAPI isaxxmlreader_getBaseURL(
3079 ISAXXMLReader* iface,
3080 const WCHAR **pBaseUrl)
3082 saxreader *This = impl_from_ISAXXMLReader( iface );
3083 return IVBSAXXMLReader_get_baseURL(&This->IVBSAXXMLReader_iface, pBaseUrl);
3086 static HRESULT WINAPI isaxxmlreader_putBaseURL(
3087 ISAXXMLReader* iface,
3088 const WCHAR *pBaseUrl)
3090 saxreader *This = impl_from_ISAXXMLReader( iface );
3091 return IVBSAXXMLReader_put_baseURL(&This->IVBSAXXMLReader_iface, pBaseUrl);
3094 static HRESULT WINAPI isaxxmlreader_getSecureBaseURL(
3095 ISAXXMLReader* iface,
3096 const WCHAR **pSecureBaseUrl)
3098 saxreader *This = impl_from_ISAXXMLReader( iface );
3099 return IVBSAXXMLReader_get_secureBaseURL(&This->IVBSAXXMLReader_iface, pSecureBaseUrl);
3102 static HRESULT WINAPI isaxxmlreader_putSecureBaseURL(
3103 ISAXXMLReader* iface,
3104 const WCHAR *secureBaseUrl)
3106 saxreader *This = impl_from_ISAXXMLReader( iface );
3107 return IVBSAXXMLReader_put_secureBaseURL(&This->IVBSAXXMLReader_iface, secureBaseUrl);
3110 static HRESULT WINAPI isaxxmlreader_parse(
3111 ISAXXMLReader* iface,
3114 saxreader *This = impl_from_ISAXXMLReader( iface );
3115 return internal_parse(This, varInput, FALSE);
3118 static HRESULT WINAPI isaxxmlreader_parseURL(
3119 ISAXXMLReader* iface,
3122 saxreader *This = impl_from_ISAXXMLReader( iface );
3123 return internal_parseURL(This, url, FALSE);
3126 static const struct ISAXXMLReaderVtbl isaxreader_vtbl =
3128 isaxxmlreader_QueryInterface,
3129 isaxxmlreader_AddRef,
3130 isaxxmlreader_Release,
3131 isaxxmlreader_getFeature,
3132 isaxxmlreader_putFeature,
3133 isaxxmlreader_getProperty,
3134 isaxxmlreader_putProperty,
3135 isaxxmlreader_getEntityResolver,
3136 isaxxmlreader_putEntityResolver,
3137 isaxxmlreader_getContentHandler,
3138 isaxxmlreader_putContentHandler,
3139 isaxxmlreader_getDTDHandler,
3140 isaxxmlreader_putDTDHandler,
3141 isaxxmlreader_getErrorHandler,
3142 isaxxmlreader_putErrorHandler,
3143 isaxxmlreader_getBaseURL,
3144 isaxxmlreader_putBaseURL,
3145 isaxxmlreader_getSecureBaseURL,
3146 isaxxmlreader_putSecureBaseURL,
3147 isaxxmlreader_parse,
3148 isaxxmlreader_parseURL
3151 HRESULT SAXXMLReader_create(MSXML_VERSION version, IUnknown *pUnkOuter, LPVOID *ppObj)
3155 TRACE("(%p,%p)\n", pUnkOuter, ppObj);
3157 reader = heap_alloc( sizeof (*reader) );
3159 return E_OUTOFMEMORY;
3161 reader->IVBSAXXMLReader_iface.lpVtbl = &saxreader_vtbl;
3162 reader->ISAXXMLReader_iface.lpVtbl = &isaxreader_vtbl;
3164 reader->contentHandler = NULL;
3165 reader->vbcontentHandler = NULL;
3166 reader->errorHandler = NULL;
3167 reader->vberrorHandler = NULL;
3168 reader->lexicalHandler = NULL;
3169 reader->vblexicalHandler = NULL;
3170 reader->declHandler = NULL;
3171 reader->vbdeclHandler = NULL;
3172 reader->isParsing = FALSE;
3173 reader->pool.pool = NULL;
3174 reader->pool.index = 0;
3175 reader->pool.len = 0;
3176 reader->features = Namespaces;
3177 reader->version = version;
3179 memset(&reader->sax, 0, sizeof(xmlSAXHandler));
3180 reader->sax.initialized = XML_SAX2_MAGIC;
3181 reader->sax.startDocument = libxmlStartDocument;
3182 reader->sax.endDocument = libxmlEndDocument;
3183 reader->sax.startElementNs = libxmlStartElementNS;
3184 reader->sax.endElementNs = libxmlEndElementNS;
3185 reader->sax.characters = libxmlCharacters;
3186 reader->sax.setDocumentLocator = libxmlSetDocumentLocator;
3187 reader->sax.comment = libxmlComment;
3188 reader->sax.error = libxmlFatalError;
3189 reader->sax.fatalError = libxmlFatalError;
3190 reader->sax.cdataBlock = libxmlCDataBlock;
3192 *ppObj = &reader->IVBSAXXMLReader_iface;
3194 TRACE("returning iface %p\n", *ppObj);
3201 HRESULT SAXXMLReader_create(MSXML_VERSION version, IUnknown *pUnkOuter, LPVOID *ppObj)
3203 MESSAGE("This program tried to use a SAX XML Reader object, but\n"
3204 "libxml2 support was not present at compile time.\n");