wer: Add new stubbed wer.dll.
[wine/hramrach.git] / dlls / msxml3 / nodemap.c
blob7d23ec80bd540cda30053da38be79dc0b154f0f9
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 #include "windef.h"
27 #include "winbase.h"
28 #include "winuser.h"
29 #include "winnls.h"
30 #include "ole2.h"
31 #include "msxml2.h"
33 #include "msxml_private.h"
35 #include "wine/debug.h"
37 WINE_DEFAULT_DEBUG_CHANNEL(msxml);
39 #ifdef HAVE_LIBXML2
41 typedef struct _xmlnodemap
43 const struct IXMLDOMNamedNodeMapVtbl *lpVtbl;
44 const struct ISupportErrorInfoVtbl *lpSEIVtbl;
45 LONG ref;
46 IXMLDOMNode *node;
47 LONG iterator;
48 } xmlnodemap;
50 static inline xmlnodemap *impl_from_IXMLDOMNamedNodeMap( IXMLDOMNamedNodeMap *iface )
52 return (xmlnodemap *)((char*)iface - FIELD_OFFSET(xmlnodemap, lpVtbl));
55 static inline xmlnodemap *impl_from_ISupportErrorInfo( ISupportErrorInfo *iface )
57 return (xmlnodemap *)((char*)iface - FIELD_OFFSET(xmlnodemap, lpSEIVtbl));
60 static HRESULT WINAPI xmlnodemap_QueryInterface(
61 IXMLDOMNamedNodeMap *iface,
62 REFIID riid, void** ppvObject )
64 xmlnodemap *This = impl_from_IXMLDOMNamedNodeMap( iface );
65 TRACE("(%p)->(%s %p)\n", iface, debugstr_guid(riid), ppvObject);
67 if( IsEqualGUID( riid, &IID_IUnknown ) ||
68 IsEqualGUID( riid, &IID_IDispatch ) ||
69 IsEqualGUID( riid, &IID_IXMLDOMNamedNodeMap ) )
71 *ppvObject = iface;
73 else if( IsEqualGUID( riid, &IID_ISupportErrorInfo ))
75 *ppvObject = &This->lpSEIVtbl;
77 else
79 FIXME("interface %s not implemented\n", debugstr_guid(riid));
80 return E_NOINTERFACE;
83 IXMLDOMElement_AddRef( iface );
85 return S_OK;
88 static ULONG WINAPI xmlnodemap_AddRef(
89 IXMLDOMNamedNodeMap *iface )
91 xmlnodemap *This = impl_from_IXMLDOMNamedNodeMap( iface );
92 return InterlockedIncrement( &This->ref );
95 static ULONG WINAPI xmlnodemap_Release(
96 IXMLDOMNamedNodeMap *iface )
98 xmlnodemap *This = impl_from_IXMLDOMNamedNodeMap( iface );
99 ULONG ref;
101 ref = InterlockedDecrement( &This->ref );
102 if ( ref == 0 )
104 IXMLDOMNode_Release( This->node );
105 heap_free( This );
108 return ref;
111 static HRESULT WINAPI xmlnodemap_GetTypeInfoCount(
112 IXMLDOMNamedNodeMap *iface,
113 UINT* pctinfo )
115 xmlnodemap *This = impl_from_IXMLDOMNamedNodeMap( iface );
117 TRACE("(%p)->(%p)\n", This, pctinfo);
119 *pctinfo = 1;
121 return S_OK;
124 static HRESULT WINAPI xmlnodemap_GetTypeInfo(
125 IXMLDOMNamedNodeMap *iface,
126 UINT iTInfo, LCID lcid,
127 ITypeInfo** ppTInfo )
129 xmlnodemap *This = impl_from_IXMLDOMNamedNodeMap( iface );
130 HRESULT hr;
132 TRACE("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo);
134 hr = get_typeinfo(IXMLDOMNamedNodeMap_tid, ppTInfo);
136 return hr;
139 static HRESULT WINAPI xmlnodemap_GetIDsOfNames(
140 IXMLDOMNamedNodeMap *iface,
141 REFIID riid, LPOLESTR* rgszNames,
142 UINT cNames, LCID lcid, DISPID* rgDispId )
144 xmlnodemap *This = impl_from_IXMLDOMNamedNodeMap( iface );
145 ITypeInfo *typeinfo;
146 HRESULT hr;
148 TRACE("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames, cNames,
149 lcid, rgDispId);
151 if(!rgszNames || cNames == 0 || !rgDispId)
152 return E_INVALIDARG;
154 hr = get_typeinfo(IXMLDOMNamedNodeMap_tid, &typeinfo);
155 if(SUCCEEDED(hr))
157 hr = ITypeInfo_GetIDsOfNames(typeinfo, rgszNames, cNames, rgDispId);
158 ITypeInfo_Release(typeinfo);
161 return hr;
164 static HRESULT WINAPI xmlnodemap_Invoke(
165 IXMLDOMNamedNodeMap *iface,
166 DISPID dispIdMember, REFIID riid, LCID lcid,
167 WORD wFlags, DISPPARAMS* pDispParams, VARIANT* pVarResult,
168 EXCEPINFO* pExcepInfo, UINT* puArgErr )
170 xmlnodemap *This = impl_from_IXMLDOMNamedNodeMap( iface );
171 ITypeInfo *typeinfo;
172 HRESULT hr;
174 TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
175 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
177 hr = get_typeinfo(IXMLDOMNamedNodeMap_tid, &typeinfo);
178 if(SUCCEEDED(hr))
180 hr = ITypeInfo_Invoke(typeinfo, &(This->lpVtbl), dispIdMember, wFlags, pDispParams,
181 pVarResult, pExcepInfo, puArgErr);
182 ITypeInfo_Release(typeinfo);
185 return hr;
188 xmlChar *xmlChar_from_wchar( LPWSTR str )
190 DWORD len;
191 xmlChar *xmlstr;
193 len = WideCharToMultiByte( CP_UTF8, 0, str, -1, NULL, 0, NULL, NULL );
194 xmlstr = heap_alloc( len );
195 if ( xmlstr )
196 WideCharToMultiByte( CP_UTF8, 0, str, -1, (LPSTR) xmlstr, len, NULL, NULL );
197 return xmlstr;
200 static HRESULT WINAPI xmlnodemap_getNamedItem(
201 IXMLDOMNamedNodeMap *iface,
202 BSTR name,
203 IXMLDOMNode** namedItem)
205 xmlnodemap *This = impl_from_IXMLDOMNamedNodeMap( iface );
206 xmlChar *element_name;
207 xmlAttrPtr attr;
208 xmlNodePtr node;
210 TRACE("(%p)->(%s %p)\n", This, debugstr_w(name), namedItem );
212 if ( !namedItem )
213 return E_INVALIDARG;
215 node = xmlNodePtr_from_domnode( This->node, 0 );
216 if ( !node )
217 return E_FAIL;
219 element_name = xmlChar_from_wchar( name );
220 attr = xmlHasNsProp( node, element_name, NULL );
221 heap_free( element_name );
223 if ( !attr )
225 *namedItem = NULL;
226 return S_FALSE;
229 *namedItem = create_node( (xmlNodePtr) attr );
231 return S_OK;
234 static HRESULT WINAPI xmlnodemap_setNamedItem(
235 IXMLDOMNamedNodeMap *iface,
236 IXMLDOMNode* newItem,
237 IXMLDOMNode** namedItem)
239 xmlnodemap *This = impl_from_IXMLDOMNamedNodeMap( iface );
240 xmlnode *ThisNew = NULL;
241 xmlNodePtr nodeNew;
242 IXMLDOMNode *pAttr = NULL;
243 xmlNodePtr node;
245 TRACE("(%p)->(%p %p)\n", This, newItem, namedItem );
247 if(!newItem)
248 return E_INVALIDARG;
250 if(namedItem) *namedItem = NULL;
252 node = xmlNodePtr_from_domnode( This->node, 0 );
253 if ( !node )
254 return E_FAIL;
256 /* Must be an Attribute */
257 IUnknown_QueryInterface(newItem, &IID_IXMLDOMNode, (LPVOID*)&pAttr);
258 if(pAttr)
260 ThisNew = impl_from_IXMLDOMNode( pAttr );
262 if(ThisNew->node->type != XML_ATTRIBUTE_NODE)
264 IUnknown_Release(pAttr);
265 return E_FAIL;
268 if(!ThisNew->node->parent)
269 if(xmldoc_remove_orphan(ThisNew->node->doc, ThisNew->node) != S_OK)
270 WARN("%p is not an orphan of %p\n", ThisNew->node, ThisNew->node->doc);
272 nodeNew = xmlAddChild(node, ThisNew->node);
274 if(namedItem)
275 *namedItem = create_node( nodeNew );
277 IUnknown_Release(pAttr);
279 return S_OK;
282 return E_INVALIDARG;
285 static HRESULT WINAPI xmlnodemap_removeNamedItem(
286 IXMLDOMNamedNodeMap *iface,
287 BSTR name,
288 IXMLDOMNode** namedItem)
290 xmlnodemap *This = impl_from_IXMLDOMNamedNodeMap( iface );
291 xmlChar *element_name;
292 xmlAttrPtr attr;
293 xmlNodePtr node;
295 TRACE("(%p)->(%s %p)\n", This, debugstr_w(name), namedItem );
297 if ( !name)
298 return E_INVALIDARG;
300 node = xmlNodePtr_from_domnode( This->node, 0 );
301 if ( !node )
302 return E_FAIL;
304 element_name = xmlChar_from_wchar( name );
305 attr = xmlHasNsProp( node, element_name, NULL );
306 heap_free( element_name );
308 if ( !attr )
310 if( namedItem )
311 *namedItem = NULL;
312 return S_FALSE;
315 if ( namedItem )
317 xmlUnlinkNode( (xmlNodePtr) attr );
318 xmldoc_add_orphan( attr->doc, (xmlNodePtr) attr );
319 *namedItem = create_node( (xmlNodePtr) attr );
321 else
323 if( xmlRemoveProp( attr ) == -1 )
324 ERR("xmlRemoveProp failed\n");
327 return S_OK;
330 static HRESULT WINAPI xmlnodemap_get_item(
331 IXMLDOMNamedNodeMap *iface,
332 LONG index,
333 IXMLDOMNode** listItem)
335 xmlnodemap *This = impl_from_IXMLDOMNamedNodeMap( iface );
336 xmlNodePtr node;
337 xmlAttrPtr curr;
338 LONG attrIndex;
340 TRACE("(%p)->(%d %p)\n", This, index, listItem);
342 *listItem = NULL;
344 if (index < 0)
345 return S_FALSE;
347 node = xmlNodePtr_from_domnode( This->node, 0 );
348 curr = node->properties;
350 for (attrIndex = 0; attrIndex < index; attrIndex++) {
351 if (curr->next == NULL)
352 return S_FALSE;
353 else
354 curr = curr->next;
357 *listItem = create_node( (xmlNodePtr) curr );
359 return S_OK;
362 static HRESULT WINAPI xmlnodemap_get_length(
363 IXMLDOMNamedNodeMap *iface,
364 LONG *listLength)
366 xmlNodePtr node;
367 xmlAttrPtr first;
368 xmlAttrPtr curr;
369 LONG attrCount;
371 xmlnodemap *This = impl_from_IXMLDOMNamedNodeMap( iface );
373 TRACE("(%p)->(%p)\n", This, listLength);
375 if( !listLength )
376 return E_INVALIDARG;
378 node = xmlNodePtr_from_domnode( This->node, 0 );
379 if ( !node )
380 return E_FAIL;
382 first = node->properties;
383 if (first == NULL) {
384 *listLength = 0;
385 return S_OK;
388 curr = first;
389 attrCount = 1;
390 while (curr->next != NULL) {
391 attrCount++;
392 curr = curr->next;
394 *listLength = attrCount;
396 return S_OK;
399 static HRESULT WINAPI xmlnodemap_getQualifiedItem(
400 IXMLDOMNamedNodeMap *iface,
401 BSTR baseName,
402 BSTR namespaceURI,
403 IXMLDOMNode** qualifiedItem)
405 xmlnodemap *This = impl_from_IXMLDOMNamedNodeMap( iface );
406 FIXME("(%p)->(%s %s %p)\n", This, debugstr_w(baseName), debugstr_w(namespaceURI), qualifiedItem);
407 return E_NOTIMPL;
410 static HRESULT WINAPI xmlnodemap_removeQualifiedItem(
411 IXMLDOMNamedNodeMap *iface,
412 BSTR baseName,
413 BSTR namespaceURI,
414 IXMLDOMNode** qualifiedItem)
416 xmlnodemap *This = impl_from_IXMLDOMNamedNodeMap( iface );
417 FIXME("(%p)->(%s %s %p)\n", This, debugstr_w(baseName), debugstr_w(namespaceURI), qualifiedItem);
418 return E_NOTIMPL;
421 static HRESULT WINAPI xmlnodemap_nextNode(
422 IXMLDOMNamedNodeMap *iface,
423 IXMLDOMNode** nextItem)
425 xmlnodemap *This = impl_from_IXMLDOMNamedNodeMap( iface );
426 xmlNodePtr node;
427 xmlAttrPtr curr;
428 LONG attrIndex;
430 TRACE("(%p)->(%p: %d)\n", This, nextItem, This->iterator);
432 *nextItem = NULL;
434 node = xmlNodePtr_from_domnode( This->node, 0 );
435 curr = node->properties;
437 for (attrIndex = 0; attrIndex < This->iterator; attrIndex++) {
438 if (curr->next == NULL)
439 return S_FALSE;
440 else
441 curr = curr->next;
444 This->iterator++;
446 *nextItem = create_node( (xmlNodePtr) curr );
448 return S_OK;
451 static HRESULT WINAPI xmlnodemap_reset(
452 IXMLDOMNamedNodeMap *iface )
454 xmlnodemap *This = impl_from_IXMLDOMNamedNodeMap( iface );
456 TRACE("(%p: %d)\n", This, This->iterator);
458 This->iterator = 0;
460 return S_OK;
463 static HRESULT WINAPI xmlnodemap__newEnum(
464 IXMLDOMNamedNodeMap *iface,
465 IUnknown** ppUnk)
467 xmlnodemap *This = impl_from_IXMLDOMNamedNodeMap( iface );
468 FIXME("(%p)->(%p)\n", This, ppUnk);
469 return E_NOTIMPL;
472 static const struct IXMLDOMNamedNodeMapVtbl xmlnodemap_vtbl =
474 xmlnodemap_QueryInterface,
475 xmlnodemap_AddRef,
476 xmlnodemap_Release,
477 xmlnodemap_GetTypeInfoCount,
478 xmlnodemap_GetTypeInfo,
479 xmlnodemap_GetIDsOfNames,
480 xmlnodemap_Invoke,
481 xmlnodemap_getNamedItem,
482 xmlnodemap_setNamedItem,
483 xmlnodemap_removeNamedItem,
484 xmlnodemap_get_item,
485 xmlnodemap_get_length,
486 xmlnodemap_getQualifiedItem,
487 xmlnodemap_removeQualifiedItem,
488 xmlnodemap_nextNode,
489 xmlnodemap_reset,
490 xmlnodemap__newEnum,
493 static HRESULT WINAPI support_error_QueryInterface(
494 ISupportErrorInfo *iface,
495 REFIID riid, void** ppvObject )
497 xmlnodemap *This = impl_from_ISupportErrorInfo( iface );
498 TRACE("%p %s %p\n", iface, debugstr_guid(riid), ppvObject);
500 return IXMLDOMNamedNodeMap_QueryInterface((IXMLDOMNamedNodeMap*)&This->lpVtbl, riid, ppvObject);
503 static ULONG WINAPI support_error_AddRef(
504 ISupportErrorInfo *iface )
506 xmlnodemap *This = impl_from_ISupportErrorInfo( iface );
507 return IXMLDOMNamedNodeMap_AddRef((IXMLDOMNamedNodeMap*)&This->lpVtbl);
510 static ULONG WINAPI support_error_Release(
511 ISupportErrorInfo *iface )
513 xmlnodemap *This = impl_from_ISupportErrorInfo( iface );
514 return IXMLDOMNamedNodeMap_Release((IXMLDOMNamedNodeMap*)&This->lpVtbl);
517 static HRESULT WINAPI support_error_InterfaceSupportsErrorInfo(
518 ISupportErrorInfo *iface,
519 REFIID riid )
521 FIXME("(%p)->(%s)\n", iface, debugstr_guid(riid));
522 return S_FALSE;
525 static const struct ISupportErrorInfoVtbl support_error_vtbl =
527 support_error_QueryInterface,
528 support_error_AddRef,
529 support_error_Release,
530 support_error_InterfaceSupportsErrorInfo
533 IXMLDOMNamedNodeMap *create_nodemap( IXMLDOMNode *node )
535 xmlnodemap *nodemap;
537 nodemap = heap_alloc( sizeof *nodemap );
538 if ( !nodemap )
539 return NULL;
541 nodemap->lpVtbl = &xmlnodemap_vtbl;
542 nodemap->lpSEIVtbl = &support_error_vtbl;
543 nodemap->node = node;
544 nodemap->ref = 1;
545 nodemap->iterator = 0;
547 IXMLDOMNode_AddRef( node );
548 /* Since we AddRef a node here, we don't need to call xmldoc_add_ref() */
550 return (IXMLDOMNamedNodeMap*) &nodemap->lpVtbl;
553 #endif