msxml3: Enable inline wrappers and fix warnings.
[wine.git] / dlls / msxml3 / attribute.c
blobd461ce14c8f67a25ee0eb24e3518739f4a6af4c5
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 const tid_t domattr_se_tids[] = {
54 IXMLDOMNode_tid,
55 IXMLDOMAttribute_tid,
59 static inline domattr *impl_from_IXMLDOMAttribute( IXMLDOMAttribute *iface )
61 return CONTAINING_RECORD(iface, domattr, IXMLDOMAttribute_iface);
64 static HRESULT WINAPI domattr_QueryInterface(
65 IXMLDOMAttribute *iface,
66 REFIID riid,
67 void** ppvObject )
69 domattr *This = impl_from_IXMLDOMAttribute( iface );
70 TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppvObject);
72 if ( IsEqualGUID( riid, &IID_IXMLDOMAttribute ) ||
73 IsEqualGUID( riid, &IID_IXMLDOMNode ) ||
74 IsEqualGUID( riid, &IID_IDispatch ) ||
75 IsEqualGUID( riid, &IID_IUnknown ) )
77 *ppvObject = iface;
79 else if(node_query_interface(&This->node, riid, ppvObject))
81 return *ppvObject ? S_OK : E_NOINTERFACE;
83 else if(IsEqualGUID( riid, &IID_ISupportErrorInfo ))
85 return node_create_supporterrorinfo(domattr_se_tids, ppvObject);
87 else
89 TRACE("Unsupported interface %s\n", debugstr_guid(riid));
90 *ppvObject = NULL;
91 return E_NOINTERFACE;
94 IXMLDOMAttribute_AddRef(iface);
95 return S_OK;
98 static ULONG WINAPI domattr_AddRef(
99 IXMLDOMAttribute *iface )
101 domattr *This = impl_from_IXMLDOMAttribute( iface );
102 ULONG ref = InterlockedIncrement( &This->ref );
103 TRACE("(%p)->(%d)\n", This, ref);
104 return ref;
107 static ULONG WINAPI domattr_Release(
108 IXMLDOMAttribute *iface )
110 domattr *This = impl_from_IXMLDOMAttribute( iface );
111 ULONG ref = InterlockedDecrement( &This->ref );
113 TRACE("(%p)->(%d)\n", This, ref);
114 if ( ref == 0 )
116 destroy_xmlnode(&This->node);
117 heap_free( This );
120 return ref;
123 static HRESULT WINAPI domattr_GetTypeInfoCount(
124 IXMLDOMAttribute *iface,
125 UINT* pctinfo )
127 domattr *This = impl_from_IXMLDOMAttribute( iface );
128 return IDispatchEx_GetTypeInfoCount(&This->node.dispex.IDispatchEx_iface, pctinfo);
131 static HRESULT WINAPI domattr_GetTypeInfo(
132 IXMLDOMAttribute *iface,
133 UINT iTInfo, LCID lcid,
134 ITypeInfo** ppTInfo )
136 domattr *This = impl_from_IXMLDOMAttribute( iface );
137 return IDispatchEx_GetTypeInfo(&This->node.dispex.IDispatchEx_iface,
138 iTInfo, lcid, ppTInfo);
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 return IDispatchEx_GetIDsOfNames(&This->node.dispex.IDispatchEx_iface,
148 riid, rgszNames, cNames, lcid, rgDispId);
151 static HRESULT WINAPI domattr_Invoke(
152 IXMLDOMAttribute *iface,
153 DISPID dispIdMember, REFIID riid, LCID lcid,
154 WORD wFlags, DISPPARAMS* pDispParams, VARIANT* pVarResult,
155 EXCEPINFO* pExcepInfo, UINT* puArgErr )
157 domattr *This = impl_from_IXMLDOMAttribute( iface );
158 return IDispatchEx_Invoke(&This->node.dispex.IDispatchEx_iface,
159 dispIdMember, riid, lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
162 static HRESULT WINAPI domattr_get_nodeName(
163 IXMLDOMAttribute *iface,
164 BSTR* p )
166 domattr *This = impl_from_IXMLDOMAttribute( iface );
168 TRACE("(%p)->(%p)\n", This, p);
170 return node_get_nodeName(&This->node, p);
173 static HRESULT WINAPI domattr_get_nodeValue(
174 IXMLDOMAttribute *iface,
175 VARIANT* value)
177 domattr *This = impl_from_IXMLDOMAttribute( iface );
179 TRACE("(%p)->(%p)\n", This, value);
181 return node_get_content(&This->node, value);
184 static HRESULT WINAPI domattr_put_nodeValue(
185 IXMLDOMAttribute *iface,
186 VARIANT value)
188 domattr *This = impl_from_IXMLDOMAttribute( iface );
190 TRACE("(%p)->(%s)\n", This, debugstr_variant(&value));
192 return node_put_value_escaped(&This->node, &value);
195 static HRESULT WINAPI domattr_get_nodeType(
196 IXMLDOMAttribute *iface,
197 DOMNodeType* domNodeType )
199 domattr *This = impl_from_IXMLDOMAttribute( iface );
201 TRACE("(%p)->(%p)\n", This, domNodeType);
203 *domNodeType = NODE_ATTRIBUTE;
204 return S_OK;
207 static HRESULT WINAPI domattr_get_parentNode(
208 IXMLDOMAttribute *iface,
209 IXMLDOMNode** parent )
211 domattr *This = impl_from_IXMLDOMAttribute( iface );
212 TRACE("(%p)->(%p)\n", This, parent);
213 if (!parent) return E_INVALIDARG;
214 *parent = NULL;
215 return S_FALSE;
218 static HRESULT WINAPI domattr_get_childNodes(
219 IXMLDOMAttribute *iface,
220 IXMLDOMNodeList** outList)
222 domattr *This = impl_from_IXMLDOMAttribute( iface );
224 TRACE("(%p)->(%p)\n", This, outList);
226 return node_get_child_nodes(&This->node, outList);
229 static HRESULT WINAPI domattr_get_firstChild(
230 IXMLDOMAttribute *iface,
231 IXMLDOMNode** domNode)
233 domattr *This = impl_from_IXMLDOMAttribute( iface );
235 TRACE("(%p)->(%p)\n", This, domNode);
237 return node_get_first_child(&This->node, domNode);
240 static HRESULT WINAPI domattr_get_lastChild(
241 IXMLDOMAttribute *iface,
242 IXMLDOMNode** domNode)
244 domattr *This = impl_from_IXMLDOMAttribute( iface );
246 TRACE("(%p)->(%p)\n", This, domNode);
248 return node_get_last_child(&This->node, domNode);
251 static HRESULT WINAPI domattr_get_previousSibling(
252 IXMLDOMAttribute *iface,
253 IXMLDOMNode** domNode)
255 domattr *This = impl_from_IXMLDOMAttribute( iface );
257 TRACE("(%p)->(%p)\n", This, domNode);
259 return return_null_node(domNode);
262 static HRESULT WINAPI domattr_get_nextSibling(
263 IXMLDOMAttribute *iface,
264 IXMLDOMNode** domNode)
266 domattr *This = impl_from_IXMLDOMAttribute( iface );
268 TRACE("(%p)->(%p)\n", This, domNode);
270 return return_null_node(domNode);
273 static HRESULT WINAPI domattr_get_attributes(
274 IXMLDOMAttribute *iface,
275 IXMLDOMNamedNodeMap** attributeMap)
277 domattr *This = impl_from_IXMLDOMAttribute( iface );
279 TRACE("(%p)->(%p)\n", This, attributeMap);
281 return return_null_ptr((void**)attributeMap);
284 static HRESULT WINAPI domattr_insertBefore(
285 IXMLDOMAttribute *iface,
286 IXMLDOMNode* newNode, VARIANT refChild,
287 IXMLDOMNode** old_node)
289 domattr *This = impl_from_IXMLDOMAttribute( iface );
290 DOMNodeType type;
291 HRESULT hr;
293 FIXME("(%p)->(%p %s %p) needs test\n", This, newNode, debugstr_variant(&refChild), old_node);
295 if (!newNode) return E_INVALIDARG;
297 hr = IXMLDOMNode_get_nodeType(newNode, &type);
298 if (hr != S_OK) return hr;
300 TRACE("new node type %d\n", type);
301 switch (type)
303 case NODE_ATTRIBUTE:
304 case NODE_CDATA_SECTION:
305 case NODE_COMMENT:
306 case NODE_ELEMENT:
307 case NODE_PROCESSING_INSTRUCTION:
308 if (old_node) *old_node = NULL;
309 return E_FAIL;
310 default:
311 return node_insert_before(&This->node, newNode, &refChild, old_node);
315 static HRESULT WINAPI domattr_replaceChild(
316 IXMLDOMAttribute *iface,
317 IXMLDOMNode* newNode,
318 IXMLDOMNode* oldNode,
319 IXMLDOMNode** outOldNode)
321 domattr *This = impl_from_IXMLDOMAttribute( iface );
323 FIXME("(%p)->(%p %p %p) needs tests\n", This, newNode, oldNode, outOldNode);
325 return node_replace_child(&This->node, newNode, oldNode, outOldNode);
328 static HRESULT WINAPI domattr_removeChild(
329 IXMLDOMAttribute *iface,
330 IXMLDOMNode *child, IXMLDOMNode **oldChild)
332 domattr *This = impl_from_IXMLDOMAttribute( iface );
333 TRACE("(%p)->(%p %p)\n", This, child, oldChild);
334 return node_remove_child(&This->node, child, oldChild);
337 static HRESULT WINAPI domattr_appendChild(
338 IXMLDOMAttribute *iface,
339 IXMLDOMNode *child, IXMLDOMNode **outChild)
341 domattr *This = impl_from_IXMLDOMAttribute( iface );
342 TRACE("(%p)->(%p %p)\n", This, child, outChild);
343 return node_append_child(&This->node, child, outChild);
346 static HRESULT WINAPI domattr_hasChildNodes(
347 IXMLDOMAttribute *iface,
348 VARIANT_BOOL *ret)
350 domattr *This = impl_from_IXMLDOMAttribute( iface );
351 TRACE("(%p)->(%p)\n", This, ret);
352 return node_has_childnodes(&This->node, ret);
355 static HRESULT WINAPI domattr_get_ownerDocument(
356 IXMLDOMAttribute *iface,
357 IXMLDOMDocument **doc)
359 domattr *This = impl_from_IXMLDOMAttribute( iface );
360 TRACE("(%p)->(%p)\n", This, doc);
361 return node_get_owner_doc(&This->node, doc);
364 static HRESULT WINAPI domattr_cloneNode(
365 IXMLDOMAttribute *iface,
366 VARIANT_BOOL deep, IXMLDOMNode** outNode)
368 domattr *This = impl_from_IXMLDOMAttribute( iface );
369 TRACE("(%p)->(%d %p)\n", This, deep, outNode);
370 return node_clone( &This->node, deep, outNode );
373 static HRESULT WINAPI domattr_get_nodeTypeString(
374 IXMLDOMAttribute *iface,
375 BSTR* p)
377 domattr *This = impl_from_IXMLDOMAttribute( iface );
378 static const WCHAR attributeW[] = {'a','t','t','r','i','b','u','t','e',0};
380 TRACE("(%p)->(%p)\n", This, p);
382 return return_bstr(attributeW, p);
385 static HRESULT WINAPI domattr_get_text(
386 IXMLDOMAttribute *iface,
387 BSTR* p)
389 domattr *This = impl_from_IXMLDOMAttribute( iface );
390 TRACE("(%p)->(%p)\n", This, p);
391 return node_get_text(&This->node, p);
394 static HRESULT WINAPI domattr_put_text(
395 IXMLDOMAttribute *iface,
396 BSTR p)
398 domattr *This = impl_from_IXMLDOMAttribute( iface );
399 TRACE("(%p)->(%s)\n", This, debugstr_w(p));
400 return node_put_text( &This->node, p );
403 static HRESULT WINAPI domattr_get_specified(
404 IXMLDOMAttribute *iface,
405 VARIANT_BOOL* isSpecified)
407 domattr *This = impl_from_IXMLDOMAttribute( iface );
408 FIXME("(%p)->(%p) stub!\n", This, isSpecified);
409 *isSpecified = VARIANT_TRUE;
410 return S_OK;
413 static HRESULT WINAPI domattr_get_definition(
414 IXMLDOMAttribute *iface,
415 IXMLDOMNode** definitionNode)
417 domattr *This = impl_from_IXMLDOMAttribute( iface );
418 FIXME("(%p)->(%p)\n", This, definitionNode);
419 return E_NOTIMPL;
422 static HRESULT WINAPI domattr_get_nodeTypedValue(
423 IXMLDOMAttribute *iface,
424 VARIANT* value)
426 domattr *This = impl_from_IXMLDOMAttribute( iface );
427 IXMLDOMDocument *doc;
428 HRESULT hr;
430 TRACE("(%p)->(%p)\n", This, value);
432 hr = IXMLDOMAttribute_get_ownerDocument(iface, &doc);
433 if (hr == S_OK)
435 IXMLDOMDocument3 *doc3;
437 hr = IXMLDOMDocument_QueryInterface(doc, &IID_IXMLDOMDocument3, (void**)&doc3);
438 IXMLDOMDocument_Release(doc);
440 if (hr == S_OK)
442 VARIANT schemas;
444 hr = IXMLDOMDocument3_get_schemas(doc3, &schemas);
445 IXMLDOMDocument3_Release(doc3);
447 if (hr != S_OK)
448 return IXMLDOMAttribute_get_value(iface, value);
449 else
451 FIXME("need to query schema for attribute type\n");
452 VariantClear(&schemas);
457 return return_null_var(value);
460 static HRESULT WINAPI domattr_put_nodeTypedValue(
461 IXMLDOMAttribute *iface,
462 VARIANT typedValue)
464 domattr *This = impl_from_IXMLDOMAttribute( iface );
465 FIXME("(%p)->(%s)\n", This, debugstr_variant(&typedValue));
466 return E_NOTIMPL;
469 static HRESULT WINAPI domattr_get_dataType(
470 IXMLDOMAttribute *iface,
471 VARIANT* typename)
473 domattr *This = impl_from_IXMLDOMAttribute( iface );
474 TRACE("(%p)->(%p)\n", This, typename);
475 return return_null_var( typename );
478 static HRESULT WINAPI domattr_put_dataType(
479 IXMLDOMAttribute *iface,
480 BSTR p)
482 domattr *This = impl_from_IXMLDOMAttribute( iface );
484 FIXME("(%p)->(%s)\n", This, debugstr_w(p));
486 if(!p)
487 return E_INVALIDARG;
489 return E_FAIL;
492 static HRESULT WINAPI domattr_get_xml(
493 IXMLDOMAttribute *iface,
494 BSTR* p)
496 domattr *This = impl_from_IXMLDOMAttribute( iface );
498 TRACE("(%p)->(%p)\n", This, p);
500 return node_get_xml(&This->node, FALSE, p);
503 static HRESULT WINAPI domattr_transformNode(
504 IXMLDOMAttribute *iface,
505 IXMLDOMNode *node, BSTR *p)
507 domattr *This = impl_from_IXMLDOMAttribute( iface );
508 TRACE("(%p)->(%p %p)\n", This, node, p);
509 return node_transform_node(&This->node, node, p);
512 static HRESULT WINAPI domattr_selectNodes(
513 IXMLDOMAttribute *iface,
514 BSTR p, IXMLDOMNodeList** outList)
516 domattr *This = impl_from_IXMLDOMAttribute( iface );
517 TRACE("(%p)->(%s %p)\n", This, debugstr_w(p), outList);
518 return node_select_nodes(&This->node, p, outList);
521 static HRESULT WINAPI domattr_selectSingleNode(
522 IXMLDOMAttribute *iface,
523 BSTR p, IXMLDOMNode** outNode)
525 domattr *This = impl_from_IXMLDOMAttribute( iface );
526 TRACE("(%p)->(%s %p)\n", This, debugstr_w(p), outNode);
527 return node_select_singlenode(&This->node, p, outNode);
530 static HRESULT WINAPI domattr_get_parsed(
531 IXMLDOMAttribute *iface,
532 VARIANT_BOOL* isParsed)
534 domattr *This = impl_from_IXMLDOMAttribute( iface );
535 FIXME("(%p)->(%p) stub!\n", This, isParsed);
536 *isParsed = VARIANT_TRUE;
537 return S_OK;
540 static HRESULT WINAPI domattr_get_namespaceURI(
541 IXMLDOMAttribute *iface,
542 BSTR* p)
544 domattr *This = impl_from_IXMLDOMAttribute( iface );
545 TRACE("(%p)->(%p)\n", This, p);
546 return node_get_namespaceURI(&This->node, p);
549 static HRESULT WINAPI domattr_get_prefix(
550 IXMLDOMAttribute *iface,
551 BSTR* prefix)
553 domattr *This = impl_from_IXMLDOMAttribute( iface );
554 TRACE("(%p)->(%p)\n", This, prefix);
555 return node_get_prefix( &This->node, prefix );
558 static HRESULT WINAPI domattr_get_baseName(
559 IXMLDOMAttribute *iface,
560 BSTR* name)
562 domattr *This = impl_from_IXMLDOMAttribute( iface );
563 TRACE("(%p)->(%p)\n", This, name);
564 return node_get_base_name( &This->node, name );
567 static HRESULT WINAPI domattr_transformNodeToObject(
568 IXMLDOMAttribute *iface,
569 IXMLDOMNode* domNode, VARIANT var1)
571 domattr *This = impl_from_IXMLDOMAttribute( iface );
572 FIXME("(%p)->(%p %s)\n", This, domNode, debugstr_variant(&var1));
573 return E_NOTIMPL;
576 static HRESULT WINAPI domattr_get_name(
577 IXMLDOMAttribute *iface,
578 BSTR *p)
580 domattr *This = impl_from_IXMLDOMAttribute( iface );
582 TRACE("(%p)->(%p)\n", This, p);
584 return node_get_nodeName(&This->node, p);
587 static HRESULT WINAPI domattr_get_value(
588 IXMLDOMAttribute *iface,
589 VARIANT *value)
591 domattr *This = impl_from_IXMLDOMAttribute( iface );
593 TRACE("(%p)->(%p)\n", This, value);
595 return node_get_content(&This->node, value);
598 static HRESULT WINAPI domattr_put_value(
599 IXMLDOMAttribute *iface,
600 VARIANT value)
602 domattr *This = impl_from_IXMLDOMAttribute( iface );
604 TRACE("(%p)->(%s)\n", This, debugstr_variant(&value));
606 return node_put_value(&This->node, &value);
609 static const struct IXMLDOMAttributeVtbl domattr_vtbl =
611 domattr_QueryInterface,
612 domattr_AddRef,
613 domattr_Release,
614 domattr_GetTypeInfoCount,
615 domattr_GetTypeInfo,
616 domattr_GetIDsOfNames,
617 domattr_Invoke,
618 domattr_get_nodeName,
619 domattr_get_nodeValue,
620 domattr_put_nodeValue,
621 domattr_get_nodeType,
622 domattr_get_parentNode,
623 domattr_get_childNodes,
624 domattr_get_firstChild,
625 domattr_get_lastChild,
626 domattr_get_previousSibling,
627 domattr_get_nextSibling,
628 domattr_get_attributes,
629 domattr_insertBefore,
630 domattr_replaceChild,
631 domattr_removeChild,
632 domattr_appendChild,
633 domattr_hasChildNodes,
634 domattr_get_ownerDocument,
635 domattr_cloneNode,
636 domattr_get_nodeTypeString,
637 domattr_get_text,
638 domattr_put_text,
639 domattr_get_specified,
640 domattr_get_definition,
641 domattr_get_nodeTypedValue,
642 domattr_put_nodeTypedValue,
643 domattr_get_dataType,
644 domattr_put_dataType,
645 domattr_get_xml,
646 domattr_transformNode,
647 domattr_selectNodes,
648 domattr_selectSingleNode,
649 domattr_get_parsed,
650 domattr_get_namespaceURI,
651 domattr_get_prefix,
652 domattr_get_baseName,
653 domattr_transformNodeToObject,
654 domattr_get_name,
655 domattr_get_value,
656 domattr_put_value
659 static const tid_t domattr_iface_tids[] = {
660 IXMLDOMAttribute_tid,
664 static dispex_static_data_t domattr_dispex = {
665 NULL,
666 IXMLDOMAttribute_tid,
667 NULL,
668 domattr_iface_tids
671 IUnknown* create_attribute( xmlNodePtr attribute )
673 domattr *This;
675 This = heap_alloc( sizeof *This );
676 if ( !This )
677 return NULL;
679 This->IXMLDOMAttribute_iface.lpVtbl = &domattr_vtbl;
680 This->ref = 1;
682 init_xmlnode(&This->node, attribute, (IXMLDOMNode*)&This->IXMLDOMAttribute_iface, &domattr_dispex);
684 return (IUnknown*)&This->IXMLDOMAttribute_iface;
687 #endif