ntdll/tests: Wait for async I/O to complete when the result is STATUS_PENDING.
[wine.git] / dlls / msxml3 / attribute.c
blob603477cd2d713eb44331bd1aac09b5eaeb4eb56e
1 /*
2 * DOM Attribute implementation
4 * Copyright 2006 Huw Davies
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 #define COBJMACROS
23 #include "config.h"
25 #include <stdarg.h>
26 #ifdef HAVE_LIBXML2
27 # include <libxml/parser.h>
28 # include <libxml/xmlerror.h>
29 # include <libxml/HTMLtree.h>
30 #endif
32 #include "windef.h"
33 #include "winbase.h"
34 #include "winuser.h"
35 #include "ole2.h"
36 #include "msxml6.h"
38 #include "msxml_private.h"
40 #include "wine/debug.h"
42 WINE_DEFAULT_DEBUG_CHANNEL(msxml);
44 #ifdef HAVE_LIBXML2
46 typedef struct _domattr
48 xmlnode node;
49 IXMLDOMAttribute IXMLDOMAttribute_iface;
50 LONG ref;
51 } domattr;
53 static inline domattr *impl_from_IXMLDOMAttribute( IXMLDOMAttribute *iface )
55 return CONTAINING_RECORD(iface, domattr, IXMLDOMAttribute_iface);
58 static HRESULT WINAPI domattr_QueryInterface(
59 IXMLDOMAttribute *iface,
60 REFIID riid,
61 void** ppvObject )
63 domattr *This = impl_from_IXMLDOMAttribute( iface );
64 TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppvObject);
66 if ( IsEqualGUID( riid, &IID_IXMLDOMAttribute ) ||
67 IsEqualGUID( riid, &IID_IXMLDOMNode ) ||
68 IsEqualGUID( riid, &IID_IDispatch ) ||
69 IsEqualGUID( riid, &IID_IUnknown ) )
71 *ppvObject = iface;
73 else if(node_query_interface(&This->node, riid, ppvObject))
75 return *ppvObject ? S_OK : E_NOINTERFACE;
77 else
79 TRACE("Unsupported interface %s\n", debugstr_guid(riid));
80 *ppvObject = NULL;
81 return E_NOINTERFACE;
84 IXMLDOMText_AddRef((IUnknown*)*ppvObject);
85 return S_OK;
88 static ULONG WINAPI domattr_AddRef(
89 IXMLDOMAttribute *iface )
91 domattr *This = impl_from_IXMLDOMAttribute( iface );
92 ULONG ref = InterlockedIncrement( &This->ref );
93 TRACE("(%p)->(%d)\n", This, ref);
94 return ref;
97 static ULONG WINAPI domattr_Release(
98 IXMLDOMAttribute *iface )
100 domattr *This = impl_from_IXMLDOMAttribute( iface );
101 ULONG ref = InterlockedDecrement( &This->ref );
103 TRACE("(%p)->(%d)\n", This, ref);
104 if ( ref == 0 )
106 destroy_xmlnode(&This->node);
107 heap_free( This );
110 return ref;
113 static HRESULT WINAPI domattr_GetTypeInfoCount(
114 IXMLDOMAttribute *iface,
115 UINT* pctinfo )
117 domattr *This = impl_from_IXMLDOMAttribute( iface );
119 TRACE("(%p)->(%p)\n", This, pctinfo);
121 *pctinfo = 1;
123 return S_OK;
126 static HRESULT WINAPI domattr_GetTypeInfo(
127 IXMLDOMAttribute *iface,
128 UINT iTInfo, LCID lcid,
129 ITypeInfo** ppTInfo )
131 domattr *This = impl_from_IXMLDOMAttribute( iface );
132 HRESULT hr;
134 TRACE("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo);
136 hr = get_typeinfo(IXMLDOMAttribute_tid, ppTInfo);
138 return hr;
141 static HRESULT WINAPI domattr_GetIDsOfNames(
142 IXMLDOMAttribute *iface,
143 REFIID riid, LPOLESTR* rgszNames,
144 UINT cNames, LCID lcid, DISPID* rgDispId )
146 domattr *This = impl_from_IXMLDOMAttribute( iface );
147 ITypeInfo *typeinfo;
148 HRESULT hr;
150 TRACE("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames, cNames,
151 lcid, rgDispId);
153 if(!rgszNames || cNames == 0 || !rgDispId)
154 return E_INVALIDARG;
156 hr = get_typeinfo(IXMLDOMAttribute_tid, &typeinfo);
157 if(SUCCEEDED(hr))
159 hr = ITypeInfo_GetIDsOfNames(typeinfo, rgszNames, cNames, rgDispId);
160 ITypeInfo_Release(typeinfo);
163 return hr;
166 static HRESULT WINAPI domattr_Invoke(
167 IXMLDOMAttribute *iface,
168 DISPID dispIdMember, REFIID riid, LCID lcid,
169 WORD wFlags, DISPPARAMS* pDispParams, VARIANT* pVarResult,
170 EXCEPINFO* pExcepInfo, UINT* puArgErr )
172 domattr *This = impl_from_IXMLDOMAttribute( iface );
173 ITypeInfo *typeinfo;
174 HRESULT hr;
176 TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
177 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
179 hr = get_typeinfo(IXMLDOMAttribute_tid, &typeinfo);
180 if(SUCCEEDED(hr))
182 hr = ITypeInfo_Invoke(typeinfo, &This->IXMLDOMAttribute_iface, dispIdMember, wFlags,
183 pDispParams, pVarResult, pExcepInfo, puArgErr);
184 ITypeInfo_Release(typeinfo);
186 return hr;
189 static HRESULT WINAPI domattr_get_nodeName(
190 IXMLDOMAttribute *iface,
191 BSTR* p )
193 domattr *This = impl_from_IXMLDOMAttribute( iface );
195 TRACE("(%p)->(%p)\n", This, p);
197 return node_get_nodeName(&This->node, p);
200 static HRESULT WINAPI domattr_get_nodeValue(
201 IXMLDOMAttribute *iface,
202 VARIANT* value)
204 domattr *This = impl_from_IXMLDOMAttribute( iface );
206 TRACE("(%p)->(%p)\n", This, value);
208 return node_get_content(&This->node, value);
211 static HRESULT WINAPI domattr_put_nodeValue(
212 IXMLDOMAttribute *iface,
213 VARIANT value)
215 domattr *This = impl_from_IXMLDOMAttribute( iface );
217 TRACE("(%p)->(%s)\n", This, debugstr_variant(&value));
219 return node_put_value_escaped(&This->node, &value);
222 static HRESULT WINAPI domattr_get_nodeType(
223 IXMLDOMAttribute *iface,
224 DOMNodeType* domNodeType )
226 domattr *This = impl_from_IXMLDOMAttribute( iface );
228 TRACE("(%p)->(%p)\n", This, domNodeType);
230 *domNodeType = NODE_ATTRIBUTE;
231 return S_OK;
234 static HRESULT WINAPI domattr_get_parentNode(
235 IXMLDOMAttribute *iface,
236 IXMLDOMNode** parent )
238 domattr *This = impl_from_IXMLDOMAttribute( iface );
239 TRACE("(%p)->(%p)\n", This, parent);
240 if (!parent) return E_INVALIDARG;
241 *parent = NULL;
242 return S_FALSE;
245 static HRESULT WINAPI domattr_get_childNodes(
246 IXMLDOMAttribute *iface,
247 IXMLDOMNodeList** outList)
249 domattr *This = impl_from_IXMLDOMAttribute( iface );
251 TRACE("(%p)->(%p)\n", This, outList);
253 return node_get_child_nodes(&This->node, outList);
256 static HRESULT WINAPI domattr_get_firstChild(
257 IXMLDOMAttribute *iface,
258 IXMLDOMNode** domNode)
260 domattr *This = impl_from_IXMLDOMAttribute( iface );
262 TRACE("(%p)->(%p)\n", This, domNode);
264 return node_get_first_child(&This->node, domNode);
267 static HRESULT WINAPI domattr_get_lastChild(
268 IXMLDOMAttribute *iface,
269 IXMLDOMNode** domNode)
271 domattr *This = impl_from_IXMLDOMAttribute( iface );
273 TRACE("(%p)->(%p)\n", This, domNode);
275 return node_get_last_child(&This->node, domNode);
278 static HRESULT WINAPI domattr_get_previousSibling(
279 IXMLDOMAttribute *iface,
280 IXMLDOMNode** domNode)
282 domattr *This = impl_from_IXMLDOMAttribute( iface );
284 TRACE("(%p)->(%p)\n", This, domNode);
286 return return_null_node(domNode);
289 static HRESULT WINAPI domattr_get_nextSibling(
290 IXMLDOMAttribute *iface,
291 IXMLDOMNode** domNode)
293 domattr *This = impl_from_IXMLDOMAttribute( iface );
295 TRACE("(%p)->(%p)\n", This, domNode);
297 return return_null_node(domNode);
300 static HRESULT WINAPI domattr_get_attributes(
301 IXMLDOMAttribute *iface,
302 IXMLDOMNamedNodeMap** attributeMap)
304 domattr *This = impl_from_IXMLDOMAttribute( iface );
306 TRACE("(%p)->(%p)\n", This, attributeMap);
308 return return_null_ptr((void**)attributeMap);
311 static HRESULT WINAPI domattr_insertBefore(
312 IXMLDOMAttribute *iface,
313 IXMLDOMNode* newNode, VARIANT refChild,
314 IXMLDOMNode** old_node)
316 domattr *This = impl_from_IXMLDOMAttribute( iface );
317 DOMNodeType type;
318 HRESULT hr;
320 FIXME("(%p)->(%p %s %p) needs test\n", This, newNode, debugstr_variant(&refChild), old_node);
322 if (!newNode) return E_INVALIDARG;
324 hr = IXMLDOMNode_get_nodeType(newNode, &type);
325 if (hr != S_OK) return hr;
327 TRACE("new node type %d\n", type);
328 switch (type)
330 case NODE_ATTRIBUTE:
331 case NODE_CDATA_SECTION:
332 case NODE_COMMENT:
333 case NODE_ELEMENT:
334 case NODE_PROCESSING_INSTRUCTION:
335 if (old_node) *old_node = NULL;
336 return E_FAIL;
337 default:
338 return node_insert_before(&This->node, newNode, &refChild, old_node);
342 static HRESULT WINAPI domattr_replaceChild(
343 IXMLDOMAttribute *iface,
344 IXMLDOMNode* newNode,
345 IXMLDOMNode* oldNode,
346 IXMLDOMNode** outOldNode)
348 domattr *This = impl_from_IXMLDOMAttribute( iface );
350 FIXME("(%p)->(%p %p %p) needs tests\n", This, newNode, oldNode, outOldNode);
352 return node_replace_child(&This->node, newNode, oldNode, outOldNode);
355 static HRESULT WINAPI domattr_removeChild(
356 IXMLDOMAttribute *iface,
357 IXMLDOMNode *child, IXMLDOMNode **oldChild)
359 domattr *This = impl_from_IXMLDOMAttribute( iface );
360 TRACE("(%p)->(%p %p)\n", This, child, oldChild);
361 return node_remove_child(&This->node, child, oldChild);
364 static HRESULT WINAPI domattr_appendChild(
365 IXMLDOMAttribute *iface,
366 IXMLDOMNode *child, IXMLDOMNode **outChild)
368 domattr *This = impl_from_IXMLDOMAttribute( iface );
369 TRACE("(%p)->(%p %p)\n", This, child, outChild);
370 return node_append_child(&This->node, child, outChild);
373 static HRESULT WINAPI domattr_hasChildNodes(
374 IXMLDOMAttribute *iface,
375 VARIANT_BOOL *ret)
377 domattr *This = impl_from_IXMLDOMAttribute( iface );
378 TRACE("(%p)->(%p)\n", This, ret);
379 return node_has_childnodes(&This->node, ret);
382 static HRESULT WINAPI domattr_get_ownerDocument(
383 IXMLDOMAttribute *iface,
384 IXMLDOMDocument **doc)
386 domattr *This = impl_from_IXMLDOMAttribute( iface );
387 TRACE("(%p)->(%p)\n", This, doc);
388 return node_get_owner_doc(&This->node, doc);
391 static HRESULT WINAPI domattr_cloneNode(
392 IXMLDOMAttribute *iface,
393 VARIANT_BOOL deep, IXMLDOMNode** outNode)
395 domattr *This = impl_from_IXMLDOMAttribute( iface );
396 TRACE("(%p)->(%d %p)\n", This, deep, outNode);
397 return node_clone( &This->node, deep, outNode );
400 static HRESULT WINAPI domattr_get_nodeTypeString(
401 IXMLDOMAttribute *iface,
402 BSTR* p)
404 domattr *This = impl_from_IXMLDOMAttribute( iface );
405 static const WCHAR attributeW[] = {'a','t','t','r','i','b','u','t','e',0};
407 TRACE("(%p)->(%p)\n", This, p);
409 return return_bstr(attributeW, p);
412 static HRESULT WINAPI domattr_get_text(
413 IXMLDOMAttribute *iface,
414 BSTR* p)
416 domattr *This = impl_from_IXMLDOMAttribute( iface );
417 TRACE("(%p)->(%p)\n", This, p);
418 return node_get_text(&This->node, p);
421 static HRESULT WINAPI domattr_put_text(
422 IXMLDOMAttribute *iface,
423 BSTR p)
425 domattr *This = impl_from_IXMLDOMAttribute( iface );
426 TRACE("(%p)->(%s)\n", This, debugstr_w(p));
427 return node_put_text( &This->node, p );
430 static HRESULT WINAPI domattr_get_specified(
431 IXMLDOMAttribute *iface,
432 VARIANT_BOOL* isSpecified)
434 domattr *This = impl_from_IXMLDOMAttribute( iface );
435 FIXME("(%p)->(%p) stub!\n", This, isSpecified);
436 *isSpecified = VARIANT_TRUE;
437 return S_OK;
440 static HRESULT WINAPI domattr_get_definition(
441 IXMLDOMAttribute *iface,
442 IXMLDOMNode** definitionNode)
444 domattr *This = impl_from_IXMLDOMAttribute( iface );
445 FIXME("(%p)->(%p)\n", This, definitionNode);
446 return E_NOTIMPL;
449 static HRESULT WINAPI domattr_get_nodeTypedValue(
450 IXMLDOMAttribute *iface,
451 VARIANT* var1)
453 domattr *This = impl_from_IXMLDOMAttribute( iface );
454 FIXME("(%p)->(%p)\n", This, var1);
455 return return_null_var(var1);
458 static HRESULT WINAPI domattr_put_nodeTypedValue(
459 IXMLDOMAttribute *iface,
460 VARIANT typedValue)
462 domattr *This = impl_from_IXMLDOMAttribute( iface );
463 FIXME("(%p)->(%s)\n", This, debugstr_variant(&typedValue));
464 return E_NOTIMPL;
467 static HRESULT WINAPI domattr_get_dataType(
468 IXMLDOMAttribute *iface,
469 VARIANT* typename)
471 domattr *This = impl_from_IXMLDOMAttribute( iface );
472 TRACE("(%p)->(%p)\n", This, typename);
473 return return_null_var( typename );
476 static HRESULT WINAPI domattr_put_dataType(
477 IXMLDOMAttribute *iface,
478 BSTR p)
480 domattr *This = impl_from_IXMLDOMAttribute( iface );
482 FIXME("(%p)->(%s)\n", This, debugstr_w(p));
484 if(!p)
485 return E_INVALIDARG;
487 return E_FAIL;
490 static HRESULT WINAPI domattr_get_xml(
491 IXMLDOMAttribute *iface,
492 BSTR* p)
494 domattr *This = impl_from_IXMLDOMAttribute( iface );
496 TRACE("(%p)->(%p)\n", This, p);
498 return node_get_xml(&This->node, FALSE, FALSE, p);
501 static HRESULT WINAPI domattr_transformNode(
502 IXMLDOMAttribute *iface,
503 IXMLDOMNode *node, BSTR *p)
505 domattr *This = impl_from_IXMLDOMAttribute( iface );
506 TRACE("(%p)->(%p %p)\n", This, node, p);
507 return node_transform_node(&This->node, node, p);
510 static HRESULT WINAPI domattr_selectNodes(
511 IXMLDOMAttribute *iface,
512 BSTR p, IXMLDOMNodeList** outList)
514 domattr *This = impl_from_IXMLDOMAttribute( iface );
515 TRACE("(%p)->(%s %p)\n", This, debugstr_w(p), outList);
516 return node_select_nodes(&This->node, p, outList);
519 static HRESULT WINAPI domattr_selectSingleNode(
520 IXMLDOMAttribute *iface,
521 BSTR p, IXMLDOMNode** outNode)
523 domattr *This = impl_from_IXMLDOMAttribute( iface );
524 TRACE("(%p)->(%s %p)\n", This, debugstr_w(p), outNode);
525 return node_select_singlenode(&This->node, p, outNode);
528 static HRESULT WINAPI domattr_get_parsed(
529 IXMLDOMAttribute *iface,
530 VARIANT_BOOL* isParsed)
532 domattr *This = impl_from_IXMLDOMAttribute( iface );
533 FIXME("(%p)->(%p) stub!\n", This, isParsed);
534 *isParsed = VARIANT_TRUE;
535 return S_OK;
538 static HRESULT WINAPI domattr_get_namespaceURI(
539 IXMLDOMAttribute *iface,
540 BSTR* p)
542 domattr *This = impl_from_IXMLDOMAttribute( iface );
543 TRACE("(%p)->(%p)\n", This, p);
544 return node_get_namespaceURI(&This->node, p);
547 static HRESULT WINAPI domattr_get_prefix(
548 IXMLDOMAttribute *iface,
549 BSTR* prefix)
551 domattr *This = impl_from_IXMLDOMAttribute( iface );
552 TRACE("(%p)->(%p)\n", This, prefix);
553 return node_get_prefix( &This->node, prefix );
556 static HRESULT WINAPI domattr_get_baseName(
557 IXMLDOMAttribute *iface,
558 BSTR* name)
560 domattr *This = impl_from_IXMLDOMAttribute( iface );
561 TRACE("(%p)->(%p)\n", This, name);
562 return node_get_base_name( &This->node, name );
565 static HRESULT WINAPI domattr_transformNodeToObject(
566 IXMLDOMAttribute *iface,
567 IXMLDOMNode* domNode, VARIANT var1)
569 domattr *This = impl_from_IXMLDOMAttribute( iface );
570 FIXME("(%p)->(%p %s)\n", This, domNode, debugstr_variant(&var1));
571 return E_NOTIMPL;
574 static HRESULT WINAPI domattr_get_name(
575 IXMLDOMAttribute *iface,
576 BSTR *p)
578 domattr *This = impl_from_IXMLDOMAttribute( iface );
580 TRACE("(%p)->(%p)\n", This, p);
582 return node_get_nodeName(&This->node, p);
585 static HRESULT WINAPI domattr_get_value(
586 IXMLDOMAttribute *iface,
587 VARIANT *value)
589 domattr *This = impl_from_IXMLDOMAttribute( iface );
591 TRACE("(%p)->(%p)\n", This, value);
593 return node_get_content(&This->node, value);
596 static HRESULT WINAPI domattr_put_value(
597 IXMLDOMAttribute *iface,
598 VARIANT value)
600 domattr *This = impl_from_IXMLDOMAttribute( iface );
602 TRACE("(%p)->(%s)\n", This, debugstr_variant(&value));
604 return node_put_value(&This->node, &value);
607 static const struct IXMLDOMAttributeVtbl domattr_vtbl =
609 domattr_QueryInterface,
610 domattr_AddRef,
611 domattr_Release,
612 domattr_GetTypeInfoCount,
613 domattr_GetTypeInfo,
614 domattr_GetIDsOfNames,
615 domattr_Invoke,
616 domattr_get_nodeName,
617 domattr_get_nodeValue,
618 domattr_put_nodeValue,
619 domattr_get_nodeType,
620 domattr_get_parentNode,
621 domattr_get_childNodes,
622 domattr_get_firstChild,
623 domattr_get_lastChild,
624 domattr_get_previousSibling,
625 domattr_get_nextSibling,
626 domattr_get_attributes,
627 domattr_insertBefore,
628 domattr_replaceChild,
629 domattr_removeChild,
630 domattr_appendChild,
631 domattr_hasChildNodes,
632 domattr_get_ownerDocument,
633 domattr_cloneNode,
634 domattr_get_nodeTypeString,
635 domattr_get_text,
636 domattr_put_text,
637 domattr_get_specified,
638 domattr_get_definition,
639 domattr_get_nodeTypedValue,
640 domattr_put_nodeTypedValue,
641 domattr_get_dataType,
642 domattr_put_dataType,
643 domattr_get_xml,
644 domattr_transformNode,
645 domattr_selectNodes,
646 domattr_selectSingleNode,
647 domattr_get_parsed,
648 domattr_get_namespaceURI,
649 domattr_get_prefix,
650 domattr_get_baseName,
651 domattr_transformNodeToObject,
652 domattr_get_name,
653 domattr_get_value,
654 domattr_put_value
657 IUnknown* create_attribute( xmlNodePtr attribute )
659 domattr *This;
661 This = heap_alloc( sizeof *This );
662 if ( !This )
663 return NULL;
665 This->IXMLDOMAttribute_iface.lpVtbl = &domattr_vtbl;
666 This->ref = 1;
668 init_xmlnode(&This->node, attribute, (IXMLDOMNode*)&This->IXMLDOMAttribute_iface, NULL);
670 return (IUnknown*)&This->IXMLDOMAttribute_iface;
673 #endif