oledb32: Implement DataConvert DBTYPE_VARIANT->DBTYPE_BYTES.
[wine/wine-gecko.git] / dlls / msxml3 / nodemap.c
blob94faf9faf81f8f5926cd88c24e1b573f20036300
1 /*
2 * Node map implementation
4 * Copyright 2005 Mike McCormack
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include "config.h"
23 #define COBJMACROS
25 #include <stdarg.h>
26 #ifdef HAVE_LIBXML2
27 # include <libxml/parser.h>
28 # include <libxml/xmlerror.h>
29 #endif
31 #include "windef.h"
32 #include "winbase.h"
33 #include "winuser.h"
34 #include "winnls.h"
35 #include "ole2.h"
36 #include "msxml6.h"
37 #include "msxml2did.h"
39 #include "msxml_private.h"
41 #include "wine/debug.h"
43 WINE_DEFAULT_DEBUG_CHANNEL(msxml);
45 #ifdef HAVE_LIBXML2
47 typedef struct
49 DispatchEx dispex;
50 IXMLDOMNamedNodeMap IXMLDOMNamedNodeMap_iface;
51 ISupportErrorInfo ISupportErrorInfo_iface;
52 LONG ref;
54 xmlNodePtr node;
55 LONG iterator;
56 IEnumVARIANT *enumvariant;
58 const struct nodemap_funcs *funcs;
59 } xmlnodemap;
61 static HRESULT nodemap_get_item(IUnknown *iface, LONG index, VARIANT *item)
63 V_VT(item) = VT_DISPATCH;
64 return IXMLDOMNamedNodeMap_get_item((IXMLDOMNamedNodeMap*)iface, index, (IXMLDOMNode**)&V_DISPATCH(item));
67 static const struct enumvariant_funcs nodemap_enumvariant = {
68 nodemap_get_item,
69 NULL
72 static inline xmlnodemap *impl_from_IXMLDOMNamedNodeMap( IXMLDOMNamedNodeMap *iface )
74 return CONTAINING_RECORD(iface, xmlnodemap, IXMLDOMNamedNodeMap_iface);
77 static inline xmlnodemap *impl_from_ISupportErrorInfo( ISupportErrorInfo *iface )
79 return CONTAINING_RECORD(iface, xmlnodemap, ISupportErrorInfo_iface);
82 static HRESULT WINAPI xmlnodemap_QueryInterface(
83 IXMLDOMNamedNodeMap *iface,
84 REFIID riid, void** ppvObject )
86 xmlnodemap *This = impl_from_IXMLDOMNamedNodeMap( iface );
87 TRACE("(%p)->(%s %p)\n", iface, debugstr_guid(riid), ppvObject);
89 if( IsEqualGUID( riid, &IID_IUnknown ) ||
90 IsEqualGUID( riid, &IID_IDispatch ) ||
91 IsEqualGUID( riid, &IID_IXMLDOMNamedNodeMap ) )
93 *ppvObject = iface;
95 else if (IsEqualGUID( riid, &IID_IEnumVARIANT ))
97 if (!This->enumvariant)
99 HRESULT hr = create_enumvariant((IUnknown*)iface, FALSE, &nodemap_enumvariant, &This->enumvariant);
100 if (FAILED(hr)) return hr;
103 return IEnumVARIANT_QueryInterface(This->enumvariant, &IID_IEnumVARIANT, ppvObject);
105 else if (dispex_query_interface(&This->dispex, riid, ppvObject))
107 return *ppvObject ? S_OK : E_NOINTERFACE;
109 else if( IsEqualGUID( riid, &IID_ISupportErrorInfo ))
111 *ppvObject = &This->ISupportErrorInfo_iface;
113 else
115 TRACE("interface %s not implemented\n", debugstr_guid(riid));
116 *ppvObject = NULL;
117 return E_NOINTERFACE;
120 IXMLDOMNamedNodeMap_AddRef( iface );
122 return S_OK;
125 static ULONG WINAPI xmlnodemap_AddRef(
126 IXMLDOMNamedNodeMap *iface )
128 xmlnodemap *This = impl_from_IXMLDOMNamedNodeMap( iface );
129 ULONG ref = InterlockedIncrement( &This->ref );
130 TRACE("(%p)->(%d)\n", This, ref);
131 return ref;
134 static ULONG WINAPI xmlnodemap_Release(
135 IXMLDOMNamedNodeMap *iface )
137 xmlnodemap *This = impl_from_IXMLDOMNamedNodeMap( iface );
138 ULONG ref = InterlockedDecrement( &This->ref );
140 TRACE("(%p)->(%d)\n", This, ref);
141 if ( ref == 0 )
143 xmldoc_release( This->node->doc );
144 if (This->enumvariant) IEnumVARIANT_Release(This->enumvariant);
145 release_dispex(&This->dispex);
146 heap_free( This );
149 return ref;
152 static HRESULT WINAPI xmlnodemap_GetTypeInfoCount(
153 IXMLDOMNamedNodeMap *iface,
154 UINT* pctinfo )
156 xmlnodemap *This = impl_from_IXMLDOMNamedNodeMap( iface );
157 return IDispatchEx_GetTypeInfoCount(&This->dispex.IDispatchEx_iface, pctinfo);
160 static HRESULT WINAPI xmlnodemap_GetTypeInfo(
161 IXMLDOMNamedNodeMap *iface,
162 UINT iTInfo, LCID lcid,
163 ITypeInfo** ppTInfo )
165 xmlnodemap *This = impl_from_IXMLDOMNamedNodeMap( iface );
166 return IDispatchEx_GetTypeInfo(&This->dispex.IDispatchEx_iface,
167 iTInfo, lcid, ppTInfo);
170 static HRESULT WINAPI xmlnodemap_GetIDsOfNames(
171 IXMLDOMNamedNodeMap *iface,
172 REFIID riid, LPOLESTR* rgszNames,
173 UINT cNames, LCID lcid, DISPID* rgDispId )
175 xmlnodemap *This = impl_from_IXMLDOMNamedNodeMap( iface );
176 return IDispatchEx_GetIDsOfNames(&This->dispex.IDispatchEx_iface,
177 riid, rgszNames, cNames, lcid, rgDispId);
180 static HRESULT WINAPI xmlnodemap_Invoke(
181 IXMLDOMNamedNodeMap *iface,
182 DISPID dispIdMember, REFIID riid, LCID lcid,
183 WORD wFlags, DISPPARAMS* pDispParams, VARIANT* pVarResult,
184 EXCEPINFO* pExcepInfo, UINT* puArgErr )
186 xmlnodemap *This = impl_from_IXMLDOMNamedNodeMap( iface );
187 return IDispatchEx_Invoke(&This->dispex.IDispatchEx_iface,
188 dispIdMember, riid, lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
191 static HRESULT WINAPI xmlnodemap_getNamedItem(
192 IXMLDOMNamedNodeMap *iface,
193 BSTR name,
194 IXMLDOMNode** item)
196 xmlnodemap *This = impl_from_IXMLDOMNamedNodeMap( iface );
198 TRACE("(%p)->(%s %p)\n", This, debugstr_w(name), item );
200 return This->funcs->get_named_item(This->node, name, item);
203 static HRESULT WINAPI xmlnodemap_setNamedItem(
204 IXMLDOMNamedNodeMap *iface,
205 IXMLDOMNode* newItem,
206 IXMLDOMNode** namedItem)
208 xmlnodemap *This = impl_from_IXMLDOMNamedNodeMap( iface );
210 TRACE("(%p)->(%p %p)\n", This, newItem, namedItem );
212 return This->funcs->set_named_item(This->node, newItem, namedItem);
215 static HRESULT WINAPI xmlnodemap_removeNamedItem(
216 IXMLDOMNamedNodeMap *iface,
217 BSTR name,
218 IXMLDOMNode** namedItem)
220 xmlnodemap *This = impl_from_IXMLDOMNamedNodeMap( iface );
222 TRACE("(%p)->(%s %p)\n", This, debugstr_w(name), namedItem );
224 return This->funcs->remove_named_item(This->node, name, namedItem);
227 static HRESULT WINAPI xmlnodemap_get_item(
228 IXMLDOMNamedNodeMap *iface,
229 LONG index,
230 IXMLDOMNode** item)
232 xmlnodemap *This = impl_from_IXMLDOMNamedNodeMap( iface );
234 TRACE("(%p)->(%d %p)\n", This, index, item);
236 return This->funcs->get_item(This->node, index, item);
239 static HRESULT WINAPI xmlnodemap_get_length(
240 IXMLDOMNamedNodeMap *iface,
241 LONG *length)
243 xmlnodemap *This = impl_from_IXMLDOMNamedNodeMap( iface );
245 TRACE("(%p)->(%p)\n", This, length);
247 return This->funcs->get_length(This->node, length);
250 static HRESULT WINAPI xmlnodemap_getQualifiedItem(
251 IXMLDOMNamedNodeMap *iface,
252 BSTR baseName,
253 BSTR namespaceURI,
254 IXMLDOMNode** item)
256 xmlnodemap *This = impl_from_IXMLDOMNamedNodeMap( iface );
258 TRACE("(%p)->(%s %s %p)\n", This, debugstr_w(baseName), debugstr_w(namespaceURI), item);
260 return This->funcs->get_qualified_item(This->node, baseName, namespaceURI, item);
263 static HRESULT WINAPI xmlnodemap_removeQualifiedItem(
264 IXMLDOMNamedNodeMap *iface,
265 BSTR baseName,
266 BSTR namespaceURI,
267 IXMLDOMNode** item)
269 xmlnodemap *This = impl_from_IXMLDOMNamedNodeMap( iface );
271 TRACE("(%p)->(%s %s %p)\n", This, debugstr_w(baseName), debugstr_w(namespaceURI), item);
273 return This->funcs->remove_qualified_item(This->node, baseName, namespaceURI, item);
276 static HRESULT WINAPI xmlnodemap_nextNode(
277 IXMLDOMNamedNodeMap *iface,
278 IXMLDOMNode** nextItem)
280 xmlnodemap *This = impl_from_IXMLDOMNamedNodeMap( iface );
282 TRACE("(%p)->(%p: %d)\n", This, nextItem, This->iterator);
284 return This->funcs->next_node(This->node, &This->iterator, nextItem);
287 static HRESULT WINAPI xmlnodemap_reset(
288 IXMLDOMNamedNodeMap *iface )
290 xmlnodemap *This = impl_from_IXMLDOMNamedNodeMap( iface );
292 TRACE("(%p)->(%d)\n", This, This->iterator);
294 This->iterator = 0;
296 return S_OK;
299 static HRESULT WINAPI xmlnodemap__newEnum(
300 IXMLDOMNamedNodeMap *iface,
301 IUnknown** enumv)
303 xmlnodemap *This = impl_from_IXMLDOMNamedNodeMap( iface );
304 TRACE("(%p)->(%p)\n", This, enumv);
305 return create_enumvariant((IUnknown*)iface, TRUE, &nodemap_enumvariant, (IEnumVARIANT**)enumv);
308 static const struct IXMLDOMNamedNodeMapVtbl XMLDOMNamedNodeMapVtbl =
310 xmlnodemap_QueryInterface,
311 xmlnodemap_AddRef,
312 xmlnodemap_Release,
313 xmlnodemap_GetTypeInfoCount,
314 xmlnodemap_GetTypeInfo,
315 xmlnodemap_GetIDsOfNames,
316 xmlnodemap_Invoke,
317 xmlnodemap_getNamedItem,
318 xmlnodemap_setNamedItem,
319 xmlnodemap_removeNamedItem,
320 xmlnodemap_get_item,
321 xmlnodemap_get_length,
322 xmlnodemap_getQualifiedItem,
323 xmlnodemap_removeQualifiedItem,
324 xmlnodemap_nextNode,
325 xmlnodemap_reset,
326 xmlnodemap__newEnum,
329 static HRESULT WINAPI support_error_QueryInterface(
330 ISupportErrorInfo *iface,
331 REFIID riid, void** ppvObject )
333 xmlnodemap *This = impl_from_ISupportErrorInfo( iface );
334 TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppvObject);
335 return IXMLDOMNamedNodeMap_QueryInterface(&This->IXMLDOMNamedNodeMap_iface, riid, ppvObject);
338 static ULONG WINAPI support_error_AddRef(
339 ISupportErrorInfo *iface )
341 xmlnodemap *This = impl_from_ISupportErrorInfo( iface );
342 return IXMLDOMNamedNodeMap_AddRef(&This->IXMLDOMNamedNodeMap_iface);
345 static ULONG WINAPI support_error_Release(
346 ISupportErrorInfo *iface )
348 xmlnodemap *This = impl_from_ISupportErrorInfo( iface );
349 return IXMLDOMNamedNodeMap_Release(&This->IXMLDOMNamedNodeMap_iface);
352 static HRESULT WINAPI support_error_InterfaceSupportsErrorInfo(
353 ISupportErrorInfo *iface,
354 REFIID riid )
356 xmlnodemap *This = impl_from_ISupportErrorInfo( iface );
357 TRACE("(%p)->(%s)\n", This, debugstr_guid(riid));
358 return IsEqualGUID(riid, &IID_IXMLDOMNamedNodeMap) ? S_OK : S_FALSE;
361 static const struct ISupportErrorInfoVtbl SupportErrorInfoVtbl =
363 support_error_QueryInterface,
364 support_error_AddRef,
365 support_error_Release,
366 support_error_InterfaceSupportsErrorInfo
369 static HRESULT xmlnodemap_get_dispid(IUnknown *iface, BSTR name, DWORD flags, DISPID *dispid)
371 WCHAR *ptr;
372 int idx = 0;
374 for(ptr = name; *ptr && isdigitW(*ptr); ptr++)
375 idx = idx*10 + (*ptr-'0');
376 if(*ptr)
377 return DISP_E_UNKNOWNNAME;
379 *dispid = DISPID_DOM_COLLECTION_BASE + idx;
380 TRACE("ret %x\n", *dispid);
381 return S_OK;
384 static HRESULT xmlnodemap_invoke(IUnknown *iface, DISPID id, LCID lcid, WORD flags, DISPPARAMS *params,
385 VARIANT *res, EXCEPINFO *ei)
387 xmlnodemap *This = impl_from_IXMLDOMNamedNodeMap( (IXMLDOMNamedNodeMap*)iface );
389 TRACE("(%p)->(%x %x %x %p %p %p)\n", This, id, lcid, flags, params, res, ei);
391 V_VT(res) = VT_DISPATCH;
392 V_DISPATCH(res) = NULL;
394 if (id < DISPID_DOM_COLLECTION_BASE || id > DISPID_DOM_COLLECTION_MAX)
395 return DISP_E_UNKNOWNNAME;
397 switch(flags)
399 case INVOKE_PROPERTYGET:
401 IXMLDOMNode *disp = NULL;
403 IXMLDOMNamedNodeMap_get_item(&This->IXMLDOMNamedNodeMap_iface, id - DISPID_DOM_COLLECTION_BASE, &disp);
404 V_DISPATCH(res) = (IDispatch*)disp;
405 break;
407 default:
409 FIXME("unimplemented flags %x\n", flags);
410 break;
414 TRACE("ret %p\n", V_DISPATCH(res));
416 return S_OK;
419 static const dispex_static_data_vtbl_t xmlnodemap_dispex_vtbl = {
420 xmlnodemap_get_dispid,
421 xmlnodemap_invoke
424 static const tid_t xmlnodemap_iface_tids[] = {
425 IXMLDOMNamedNodeMap_tid,
429 static dispex_static_data_t xmlnodemap_dispex = {
430 &xmlnodemap_dispex_vtbl,
431 IXMLDOMNamedNodeMap_tid,
432 NULL,
433 xmlnodemap_iface_tids
436 IXMLDOMNamedNodeMap *create_nodemap(xmlNodePtr node, const struct nodemap_funcs *funcs)
438 xmlnodemap *This;
440 This = heap_alloc( sizeof *This );
441 if ( !This )
442 return NULL;
444 This->IXMLDOMNamedNodeMap_iface.lpVtbl = &XMLDOMNamedNodeMapVtbl;
445 This->ISupportErrorInfo_iface.lpVtbl = &SupportErrorInfoVtbl;
446 This->node = node;
447 This->ref = 1;
448 This->iterator = 0;
449 This->enumvariant = NULL;
450 This->funcs = funcs;
452 init_dispex(&This->dispex, (IUnknown*)&This->IXMLDOMNamedNodeMap_iface, &xmlnodemap_dispex);
454 xmldoc_add_ref(node->doc);
456 return &This->IXMLDOMNamedNodeMap_iface;
459 #endif