2 * Copyright 2008 Jacek Caban for CodeWeavers
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
25 # include <libxml/parser.h>
26 # include <libxml/xmlerror.h>
35 #include "msxml6did.h"
41 #include "wine/debug.h"
42 #include "wine/unicode.h"
44 #include "msxml_private.h"
46 WINE_DEFAULT_DEBUG_CHANNEL(msxml
);
48 static CRITICAL_SECTION cs_dispex_static_data
;
49 static CRITICAL_SECTION_DEBUG cs_dispex_static_data_dbg
=
51 0, 0, &cs_dispex_static_data
,
52 { &cs_dispex_static_data_dbg
.ProcessLocksList
, &cs_dispex_static_data_dbg
.ProcessLocksList
},
53 0, 0, { (DWORD_PTR
)(__FILE__
": dispex_static_data") }
55 static CRITICAL_SECTION cs_dispex_static_data
= { &cs_dispex_static_data_dbg
, -1, 0, 0, 0, 0 };
67 enum lib_version_t lib
;
81 struct dispex_data_t
{
84 func_info_t
**name_table
;
89 static struct list dispex_data_list
= LIST_INIT(dispex_data_list
);
90 static ITypeLib
*typelib
[LibXml_Last
];
91 static ITypeInfo
*typeinfos
[LAST_tid
];
93 /* indexed with lib_version_t values */
94 static lib_id_t lib_ids
[] = {
99 static tid_id_t tid_ids
[] = {
100 { &IID_NULL
, LibXml_Last
},
101 { &IID_IXMLDOMAttribute
, LibXml2
},
102 { &IID_IXMLDOMCDATASection
, LibXml2
},
103 { &IID_IXMLDOMComment
, LibXml2
},
104 { &IID_IXMLDOMDocument
, LibXml2
},
105 { &IID_IXMLDOMDocument2
, LibXml2
},
106 { &IID_IXMLDOMDocument3
, LibXml2
},
107 { &IID_IXMLDOMDocumentFragment
, LibXml2
},
108 { &IID_IXMLDOMDocumentType
, LibXml2
},
109 { &IID_IXMLDOMElement
, LibXml2
},
110 { &IID_IXMLDOMEntityReference
, LibXml2
},
111 { &IID_IXMLDOMImplementation
, LibXml2
},
112 { &IID_IXMLDOMNamedNodeMap
, LibXml2
},
113 { &IID_IXMLDOMNode
, LibXml2
},
114 { &IID_IXMLDOMNodeList
, LibXml2
},
115 { &IID_IXMLDOMParseError2
, LibXml2
},
116 { &IID_IXMLDOMProcessingInstruction
, LibXml2
},
117 { &IID_IXMLDOMSchemaCollection
, LibXml2
},
118 { &IID_IXMLDOMSchemaCollection2
, LibXml2
},
119 { &IID_IXMLDOMSelection
, LibXml2
},
120 { &IID_IXMLDOMText
, LibXml2
},
121 { &IID_IXMLElement
, LibXml
},
122 { &IID_IXMLDocument
, LibXml
},
123 { &IID_IXMLHTTPRequest
, LibXml2
},
124 { &IID_IXSLProcessor
, LibXml2
},
125 { &IID_IXSLTemplate
, LibXml2
},
126 { &IID_IVBSAXAttributes
, LibXml2
},
127 { &IID_IVBSAXContentHandler
, LibXml2
},
128 { &IID_IVBSAXDeclHandler
, LibXml2
},
129 { &IID_IVBSAXDTDHandler
, LibXml2
},
130 { &IID_IVBSAXEntityResolver
, LibXml2
},
131 { &IID_IVBSAXErrorHandler
, LibXml2
},
132 { &IID_IVBSAXLexicalHandler
, LibXml2
},
133 { &IID_IVBSAXLocator
, LibXml2
},
134 { &IID_IVBSAXXMLFilter
, LibXml2
},
135 { &IID_IVBSAXXMLReader
, LibXml2
},
136 { &IID_IMXAttributes
, LibXml2
},
137 { &IID_IMXReaderControl
, LibXml2
},
138 { &IID_IMXWriter
, LibXml2
},
139 { &IID_IVBMXNamespaceManager
, LibXml2
},
140 { &IID_IServerXMLHTTPRequest
, LibXml2
}
143 const IID
*get_riid_from_tid(tid_t tid
)
145 return tid_ids
[tid
].iid
;
148 static inline unsigned get_libid_from_tid(tid_t tid
)
150 return tid_ids
[tid
].lib
;
153 HRESULT
get_typeinfo(enum tid_t tid
, ITypeInfo
**typeinfo
)
155 unsigned lib
= get_libid_from_tid(tid
);
161 hres
= LoadRegTypeLib(lib_ids
[lib
].iid
, lib_ids
[lib
].major
, 0, LOCALE_SYSTEM_DEFAULT
, &tl
);
163 ERR("LoadRegTypeLib failed: %08x\n", hres
);
167 if(InterlockedCompareExchangePointer((void**)&typelib
[lib
], tl
, NULL
))
168 ITypeLib_Release(tl
);
171 if(!typeinfos
[tid
]) {
174 hres
= ITypeLib_GetTypeInfoOfGuid(typelib
[lib
], get_riid_from_tid(tid
), &ti
);
176 /* try harder with typelib from msxml.dll */
177 hres
= ITypeLib_GetTypeInfoOfGuid(typelib
[LibXml
], get_riid_from_tid(tid
), &ti
);
179 ERR("GetTypeInfoOfGuid failed: %08x\n", hres
);
184 if(InterlockedCompareExchangePointer((void**)(typeinfos
+tid
), ti
, NULL
))
185 ITypeInfo_Release(ti
);
188 *typeinfo
= typeinfos
[tid
];
190 ITypeInfo_AddRef(typeinfos
[tid
]);
194 void release_typelib(void)
199 while(!list_empty(&dispex_data_list
)) {
200 iter
= LIST_ENTRY(list_head(&dispex_data_list
), dispex_data_t
, entry
);
201 list_remove(&iter
->entry
);
203 for(i
=0; i
< iter
->func_cnt
; i
++)
204 SysFreeString(iter
->funcs
[i
].name
);
206 heap_free(iter
->funcs
);
207 heap_free(iter
->name_table
);
211 for(i
=0; i
< sizeof(typeinfos
)/sizeof(*typeinfos
); i
++)
213 ITypeInfo_Release(typeinfos
[i
]);
215 for(i
=0; i
< sizeof(typelib
)/sizeof(*typelib
); i
++)
217 ITypeLib_Release(typelib
[i
]);
219 DeleteCriticalSection(&cs_dispex_static_data
);
222 static void add_func_info(dispex_data_t
*data
, DWORD
*size
, tid_t tid
, DISPID id
, ITypeInfo
*dti
)
226 if(data
->func_cnt
&& data
->funcs
[data
->func_cnt
-1].id
== id
)
229 if(data
->func_cnt
== *size
)
230 data
->funcs
= heap_realloc(data
->funcs
, (*size
<<= 1)*sizeof(func_info_t
));
232 hres
= ITypeInfo_GetDocumentation(dti
, id
, &data
->funcs
[data
->func_cnt
].name
, NULL
, NULL
, NULL
);
236 data
->funcs
[data
->func_cnt
].id
= id
;
237 data
->funcs
[data
->func_cnt
].tid
= tid
;
242 static int dispid_cmp(const void *p1
, const void *p2
)
244 return ((const func_info_t
*)p1
)->id
- ((const func_info_t
*)p2
)->id
;
247 static int func_name_cmp(const void *p1
, const void *p2
)
249 return strcmpiW((*(func_info_t
* const*)p1
)->name
, (*(func_info_t
* const*)p2
)->name
);
252 static dispex_data_t
*preprocess_dispex_data(DispatchEx
*This
)
254 const tid_t
*tid
= This
->data
->iface_tids
;
261 TRACE("(%p)\n", This
);
263 hres
= get_typeinfo(This
->data
->disp_tid
, &dti
);
265 ERR("Could not get disp type info: %08x\n", hres
);
269 data
= heap_alloc(sizeof(dispex_data_t
));
271 data
->funcs
= heap_alloc(size
*sizeof(func_info_t
));
272 list_add_tail(&dispex_data_list
, &data
->entry
);
275 hres
= get_typeinfo(*tid
, &ti
);
281 hres
= ITypeInfo_GetFuncDesc(ti
, i
++, &funcdesc
);
285 add_func_info(data
, &size
, *tid
, funcdesc
->memid
, dti
);
286 ITypeInfo_ReleaseFuncDesc(ti
, funcdesc
);
289 ITypeInfo_Release(ti
);
293 if(!data
->func_cnt
) {
294 heap_free(data
->funcs
);
296 }else if(data
->func_cnt
!= size
) {
297 data
->funcs
= heap_realloc(data
->funcs
, data
->func_cnt
* sizeof(func_info_t
));
300 qsort(data
->funcs
, data
->func_cnt
, sizeof(func_info_t
), dispid_cmp
);
303 data
->name_table
= heap_alloc(data
->func_cnt
* sizeof(func_info_t
*));
304 for(i
=0; i
< data
->func_cnt
; i
++)
305 data
->name_table
[i
] = data
->funcs
+i
;
306 qsort(data
->name_table
, data
->func_cnt
, sizeof(func_info_t
*), func_name_cmp
);
308 data
->name_table
= NULL
;
311 ITypeInfo_Release(dti
);
315 static dispex_data_t
*get_dispex_data(DispatchEx
*This
)
318 return This
->data
->data
;
320 EnterCriticalSection(&cs_dispex_static_data
);
322 if(!This
->data
->data
)
323 This
->data
->data
= preprocess_dispex_data(This
);
325 LeaveCriticalSection(&cs_dispex_static_data
);
327 return This
->data
->data
;
330 static inline DispatchEx
*impl_from_IDispatchEx(IDispatchEx
*iface
)
332 return CONTAINING_RECORD(iface
, DispatchEx
, IDispatchEx_iface
);
335 static HRESULT WINAPI
DispatchEx_QueryInterface(IDispatchEx
*iface
, REFIID riid
, void **ppv
)
337 DispatchEx
*This
= impl_from_IDispatchEx(iface
);
339 return IUnknown_QueryInterface(This
->outer
, riid
, ppv
);
342 static ULONG WINAPI
DispatchEx_AddRef(IDispatchEx
*iface
)
344 DispatchEx
*This
= impl_from_IDispatchEx(iface
);
346 return IUnknown_AddRef(This
->outer
);
349 static ULONG WINAPI
DispatchEx_Release(IDispatchEx
*iface
)
351 DispatchEx
*This
= impl_from_IDispatchEx(iface
);
353 return IUnknown_Release(This
->outer
);
356 static HRESULT WINAPI
DispatchEx_GetTypeInfoCount(IDispatchEx
*iface
, UINT
*pctinfo
)
358 DispatchEx
*This
= impl_from_IDispatchEx(iface
);
360 TRACE("(%p)->(%p)\n", This
, pctinfo
);
366 static HRESULT WINAPI
DispatchEx_GetTypeInfo(IDispatchEx
*iface
, UINT iTInfo
,
367 LCID lcid
, ITypeInfo
**ppTInfo
)
369 DispatchEx
*This
= impl_from_IDispatchEx(iface
);
371 TRACE("(%p)->(%u %u %p)\n", This
, iTInfo
, lcid
, ppTInfo
);
373 return get_typeinfo(This
->data
->disp_tid
, ppTInfo
);
376 static HRESULT WINAPI
DispatchEx_GetIDsOfNames(IDispatchEx
*iface
, REFIID riid
,
377 LPOLESTR
*rgszNames
, UINT cNames
,
378 LCID lcid
, DISPID
*rgDispId
)
380 DispatchEx
*This
= impl_from_IDispatchEx(iface
);
384 TRACE("(%p)->(%s %p %u %u %p)\n", This
, debugstr_guid(riid
), rgszNames
, cNames
,
387 for(i
=0; i
< cNames
; i
++) {
388 hres
= IDispatchEx_GetDispID(&This
->IDispatchEx_iface
, rgszNames
[i
], 0, rgDispId
+i
);
396 static HRESULT WINAPI
DispatchEx_Invoke(IDispatchEx
*iface
, DISPID dispIdMember
,
397 REFIID riid
, LCID lcid
, WORD wFlags
, DISPPARAMS
*pDispParams
,
398 VARIANT
*pVarResult
, EXCEPINFO
*pExcepInfo
, UINT
*puArgErr
)
400 DispatchEx
*This
= impl_from_IDispatchEx(iface
);
402 TRACE("(%p)->(%x %s %x %x %p %p %p %p)\n", This
, dispIdMember
, debugstr_guid(riid
),
403 lcid
, wFlags
, pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
405 return IDispatchEx_InvokeEx(&This
->IDispatchEx_iface
, dispIdMember
, lcid
, wFlags
,
406 pDispParams
, pVarResult
, pExcepInfo
, NULL
);
409 static HRESULT WINAPI
DispatchEx_GetDispID(IDispatchEx
*iface
, BSTR bstrName
, DWORD grfdex
, DISPID
*pid
)
411 DispatchEx
*This
= impl_from_IDispatchEx(iface
);
415 TRACE("(%p)->(%s %x %p)\n", This
, debugstr_w(bstrName
), grfdex
, pid
);
417 if(grfdex
& ~(fdexNameCaseSensitive
|fdexNameEnsure
|fdexNameImplicit
))
418 FIXME("Unsupported grfdex %x\n", grfdex
);
420 data
= get_dispex_data(This
);
425 max
= data
->func_cnt
-1;
430 c
= strcmpiW(data
->name_table
[n
]->name
, bstrName
);
432 if((grfdex
& fdexNameCaseSensitive
) && strcmpW(data
->name_table
[n
]->name
, bstrName
))
435 *pid
= data
->name_table
[n
]->id
;
445 if(This
->data
->vtbl
&& This
->data
->vtbl
->get_dispid
) {
448 hres
= This
->data
->vtbl
->get_dispid(This
->outer
, bstrName
, grfdex
, pid
);
449 if(hres
!= DISP_E_UNKNOWNNAME
)
453 TRACE("not found %s\n", debugstr_w(bstrName
));
454 return DISP_E_UNKNOWNNAME
;
457 static BOOL
is_propputref_id(DISPID id
)
461 case DISPID_DOM_DOCUMENT_DOCUMENTELEMENT
:
462 case DISPID_XMLDOM_DOCUMENT2_SCHEMAS
:
463 case DISPID_XMLDOM_SELECTION_CONTEXT
:
464 case DISPID_XMLDOM_TEMPLATE_STYLESHEET
:
465 case DISPID_SAX_CONTENTHANDLER_DOCUMENTLOCATOR
:
466 case DISPID_SAX_XMLFILTER_PARENT
:
467 case DISPID_SAX_XMLREADER_ENTITYRESOLVER
:
468 case DISPID_SAX_XMLREADER_CONTENTHANDLER
:
469 case DISPID_SAX_XMLREADER_DTDHANDLER
:
470 case DISPID_SAX_XMLREADER_ERRORHANDLER
:
471 case DISPID_MXXML_FILTER_ENTITYRESOLVER
:
472 case DISPID_MXXML_FILTER_CONTENTHANDLER
:
473 case DISPID_MXXML_FILTER_DTDHANDLER
:
474 case DISPID_MXXML_FILTER_ERRORHANDLER
:
481 static HRESULT WINAPI
DispatchEx_InvokeEx(IDispatchEx
*iface
, DISPID id
, LCID lcid
, WORD wFlags
, DISPPARAMS
*pdp
,
482 VARIANT
*pvarRes
, EXCEPINFO
*pei
, IServiceProvider
*pspCaller
)
484 DispatchEx
*This
= impl_from_IDispatchEx(iface
);
492 TRACE("(%p)->(%x %x %x %p %p %p %p)\n", This
, id
, lcid
, wFlags
, pdp
, pvarRes
, pei
, pspCaller
);
494 if(This
->data
->vtbl
&& This
->data
->vtbl
->invoke
) {
495 hres
= This
->data
->vtbl
->invoke(This
->outer
, id
, lcid
, wFlags
, pdp
, pvarRes
, pei
);
496 if (hres
!= DISP_E_UNKNOWNNAME
) return hres
;
499 if(wFlags
== DISPATCH_CONSTRUCT
) {
500 FIXME("DISPATCH_CONSTRUCT not implemented\n");
504 data
= get_dispex_data(This
);
509 max
= data
->func_cnt
-1;
514 if(data
->funcs
[n
].id
== id
)
517 if(data
->funcs
[n
].id
< id
)
524 WARN("invalid id %x\n", id
);
525 return DISP_E_UNKNOWNNAME
;
528 hres
= get_typeinfo(data
->funcs
[n
].tid
, &ti
);
530 ERR("Could not get type info: %08x\n", hres
);
534 hres
= IUnknown_QueryInterface(This
->outer
, get_riid_from_tid(data
->funcs
[n
].tid
), (void**)&unk
);
536 ERR("Could not get iface: %08x\n", hres
);
537 ITypeInfo_Release(ti
);
541 if (is_propputref_id(id
) && wFlags
== DISPATCH_PROPERTYPUT
)
542 wFlags
= DISPATCH_PROPERTYPUTREF
;
543 hres
= ITypeInfo_Invoke(ti
, unk
, id
, wFlags
, pdp
, pvarRes
, pei
, &argerr
);
545 ITypeInfo_Release(ti
);
546 IUnknown_Release(unk
);
550 static HRESULT WINAPI
DispatchEx_DeleteMemberByName(IDispatchEx
*iface
, BSTR bstrName
, DWORD grfdex
)
552 DispatchEx
*This
= impl_from_IDispatchEx(iface
);
553 TRACE("Not implemented in native msxml3 (%p)->(%s %x)\n", This
, debugstr_w(bstrName
), grfdex
);
557 static HRESULT WINAPI
DispatchEx_DeleteMemberByDispID(IDispatchEx
*iface
, DISPID id
)
559 DispatchEx
*This
= impl_from_IDispatchEx(iface
);
560 TRACE("Not implemented in native msxml3 (%p)->(%x)\n", This
, id
);
564 static HRESULT WINAPI
DispatchEx_GetMemberProperties(IDispatchEx
*iface
, DISPID id
, DWORD grfdexFetch
, DWORD
*pgrfdex
)
566 DispatchEx
*This
= impl_from_IDispatchEx(iface
);
567 TRACE("Not implemented in native msxml3 (%p)->(%x %x %p)\n", This
, id
, grfdexFetch
, pgrfdex
);
571 static HRESULT WINAPI
DispatchEx_GetMemberName(IDispatchEx
*iface
, DISPID id
, BSTR
*pbstrName
)
573 DispatchEx
*This
= impl_from_IDispatchEx(iface
);
574 TRACE("Not implemented in native msxml3 (%p)->(%x %p)\n", This
, id
, pbstrName
);
578 static HRESULT WINAPI
DispatchEx_GetNextDispID(IDispatchEx
*iface
, DWORD grfdex
, DISPID id
, DISPID
*pid
)
580 DispatchEx
*This
= impl_from_IDispatchEx(iface
);
581 TRACE(" Not implemented in native msxml3 (%p)->(%x %x %p)\n", This
, grfdex
, id
, pid
);
585 static HRESULT WINAPI
DispatchEx_GetNameSpaceParent(IDispatchEx
*iface
, IUnknown
**ppunk
)
587 DispatchEx
*This
= impl_from_IDispatchEx(iface
);
588 TRACE("Not implemented in native msxml3 (%p)->(%p)\n", This
, ppunk
);
592 static IDispatchExVtbl DispatchExVtbl
= {
593 DispatchEx_QueryInterface
,
596 DispatchEx_GetTypeInfoCount
,
597 DispatchEx_GetTypeInfo
,
598 DispatchEx_GetIDsOfNames
,
600 DispatchEx_GetDispID
,
602 DispatchEx_DeleteMemberByName
,
603 DispatchEx_DeleteMemberByDispID
,
604 DispatchEx_GetMemberProperties
,
605 DispatchEx_GetMemberName
,
606 DispatchEx_GetNextDispID
,
607 DispatchEx_GetNameSpaceParent
610 BOOL
dispex_query_interface(DispatchEx
*This
, REFIID riid
, void **ppv
)
612 static const IID IID_UndocumentedScriptIface
=
613 {0x719c3050,0xf9d3,0x11cf,{0xa4,0x93,0x00,0x40,0x05,0x23,0xa8,0xa0}};
614 static const IID IID_IDispatchJS
=
615 {0x719c3050,0xf9d3,0x11cf,{0xa4,0x93,0x00,0x40,0x05,0x23,0xa8,0xa6}};
617 if(IsEqualGUID(&IID_IDispatch
, riid
)) {
618 TRACE("(%p)->(IID_IDispatch %p)\n", This
, ppv
);
619 *ppv
= &This
->IDispatchEx_iface
;
620 }else if(IsEqualGUID(&IID_IDispatchEx
, riid
)) {
621 TRACE("(%p)->(IID_IDispatchEx %p)\n", This
, ppv
);
622 *ppv
= &This
->IDispatchEx_iface
;
623 }else if(IsEqualGUID(&IID_IDispatchJS
, riid
)) {
624 TRACE("(%p)->(IID_IDispatchJS %p) returning NULL\n", This
, ppv
);
626 }else if(IsEqualGUID(&IID_UndocumentedScriptIface
, riid
)) {
627 TRACE("(%p)->(IID_UndocumentedScriptIface %p) returning NULL\n", This
, ppv
);
629 }else if (IsEqualGUID(&IID_IObjectIdentity
, riid
)) {
630 TRACE("IID_IObjectIdentity not supported returning NULL\n");
637 IUnknown_AddRef((IUnknown
*)*ppv
);
641 void init_dispex(DispatchEx
*dispex
, IUnknown
*outer
, dispex_static_data_t
*data
)
643 dispex
->IDispatchEx_iface
.lpVtbl
= &DispatchExVtbl
;
644 dispex
->outer
= outer
;