include/mscvpdb.h: Use flexible array members for the rest of structures.
[wine.git] / dlls / msxml3 / attribute.c
blob0cbba93c53a8c2f5eb58840d7510cb4606841005
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 <stdarg.h>
24 #include <libxml/parser.h>
25 #include <libxml/xmlerror.h>
26 #include <libxml/HTMLtree.h>
28 #include "windef.h"
29 #include "winbase.h"
30 #include "winuser.h"
31 #include "ole2.h"
32 #include "msxml6.h"
34 #include "msxml_private.h"
36 #include "wine/debug.h"
38 WINE_DEFAULT_DEBUG_CHANNEL(msxml);
40 static const xmlChar xmlns[] = "xmlns";
42 typedef struct _domattr
44 xmlnode node;
45 IXMLDOMAttribute IXMLDOMAttribute_iface;
46 LONG ref;
47 BOOL floating;
48 } domattr;
50 static const tid_t domattr_se_tids[] = {
51 IXMLDOMNode_tid,
52 IXMLDOMAttribute_tid,
53 NULL_tid
56 static inline domattr *impl_from_IXMLDOMAttribute( IXMLDOMAttribute *iface )
58 return CONTAINING_RECORD(iface, domattr, IXMLDOMAttribute_iface);
61 static HRESULT WINAPI domattr_QueryInterface(
62 IXMLDOMAttribute *iface,
63 REFIID riid,
64 void** ppvObject )
66 domattr *This = impl_from_IXMLDOMAttribute( iface );
67 TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppvObject);
69 if ( IsEqualGUID( riid, &IID_IXMLDOMAttribute ) ||
70 IsEqualGUID( riid, &IID_IXMLDOMNode ) ||
71 IsEqualGUID( riid, &IID_IDispatch ) ||
72 IsEqualGUID( riid, &IID_IUnknown ) )
74 *ppvObject = iface;
76 else if(node_query_interface(&This->node, riid, ppvObject))
78 return *ppvObject ? S_OK : E_NOINTERFACE;
80 else if(IsEqualGUID( riid, &IID_ISupportErrorInfo ))
82 return node_create_supporterrorinfo(domattr_se_tids, ppvObject);
84 else
86 TRACE("Unsupported interface %s\n", debugstr_guid(riid));
87 *ppvObject = NULL;
88 return E_NOINTERFACE;
91 IXMLDOMAttribute_AddRef(iface);
92 return S_OK;
95 static ULONG WINAPI domattr_AddRef(
96 IXMLDOMAttribute *iface )
98 domattr *attr = impl_from_IXMLDOMAttribute( iface );
99 ULONG ref = InterlockedIncrement( &attr->ref );
100 TRACE("%p, refcount %lu.\n", iface, ref);
101 return ref;
104 static ULONG WINAPI domattr_Release(
105 IXMLDOMAttribute *iface )
107 domattr *This = impl_from_IXMLDOMAttribute( iface );
108 ULONG ref = InterlockedDecrement( &This->ref );
110 TRACE("%p, refcount %lu.\n", iface, ref);
111 if ( ref == 0 )
113 destroy_xmlnode(&This->node);
114 if ( This->floating )
116 xmlFreeNs( This->node.node->ns );
117 xmlFreeNode( This->node.node );
119 free( This );
122 return ref;
125 static HRESULT WINAPI domattr_GetTypeInfoCount(
126 IXMLDOMAttribute *iface,
127 UINT* pctinfo )
129 domattr *This = impl_from_IXMLDOMAttribute( iface );
130 return IDispatchEx_GetTypeInfoCount(&This->node.dispex.IDispatchEx_iface, pctinfo);
133 static HRESULT WINAPI domattr_GetTypeInfo(
134 IXMLDOMAttribute *iface,
135 UINT iTInfo, LCID lcid,
136 ITypeInfo** ppTInfo )
138 domattr *This = impl_from_IXMLDOMAttribute( iface );
139 return IDispatchEx_GetTypeInfo(&This->node.dispex.IDispatchEx_iface,
140 iTInfo, lcid, ppTInfo);
143 static HRESULT WINAPI domattr_GetIDsOfNames(
144 IXMLDOMAttribute *iface,
145 REFIID riid, LPOLESTR* rgszNames,
146 UINT cNames, LCID lcid, DISPID* rgDispId )
148 domattr *This = impl_from_IXMLDOMAttribute( iface );
149 return IDispatchEx_GetIDsOfNames(&This->node.dispex.IDispatchEx_iface,
150 riid, rgszNames, cNames, lcid, rgDispId);
153 static HRESULT WINAPI domattr_Invoke(
154 IXMLDOMAttribute *iface,
155 DISPID dispIdMember, REFIID riid, LCID lcid,
156 WORD wFlags, DISPPARAMS* pDispParams, VARIANT* pVarResult,
157 EXCEPINFO* pExcepInfo, UINT* puArgErr )
159 domattr *This = impl_from_IXMLDOMAttribute( iface );
160 return IDispatchEx_Invoke(&This->node.dispex.IDispatchEx_iface,
161 dispIdMember, riid, lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
164 static HRESULT WINAPI domattr_get_nodeName(
165 IXMLDOMAttribute *iface,
166 BSTR* p )
168 domattr *This = impl_from_IXMLDOMAttribute( iface );
170 TRACE("(%p)->(%p)\n", This, p);
172 return node_get_nodeName(&This->node, p);
175 static HRESULT WINAPI domattr_get_nodeValue(
176 IXMLDOMAttribute *iface,
177 VARIANT* value)
179 domattr *This = impl_from_IXMLDOMAttribute( iface );
181 TRACE("(%p)->(%p)\n", This, value);
183 return node_get_content(&This->node, value);
186 static HRESULT WINAPI domattr_put_nodeValue(
187 IXMLDOMAttribute *iface,
188 VARIANT value)
190 domattr *This = impl_from_IXMLDOMAttribute( iface );
192 TRACE("(%p)->(%s)\n", This, debugstr_variant(&value));
194 return node_put_value_escaped(&This->node, &value);
197 static HRESULT WINAPI domattr_get_nodeType(
198 IXMLDOMAttribute *iface,
199 DOMNodeType* domNodeType )
201 domattr *This = impl_from_IXMLDOMAttribute( iface );
203 TRACE("(%p)->(%p)\n", This, domNodeType);
205 *domNodeType = NODE_ATTRIBUTE;
206 return S_OK;
209 static HRESULT WINAPI domattr_get_parentNode(
210 IXMLDOMAttribute *iface,
211 IXMLDOMNode** parent )
213 domattr *This = impl_from_IXMLDOMAttribute( iface );
214 TRACE("(%p)->(%p)\n", This, parent);
215 if (!parent) return E_INVALIDARG;
216 *parent = NULL;
217 return S_FALSE;
220 static HRESULT WINAPI domattr_get_childNodes(
221 IXMLDOMAttribute *iface,
222 IXMLDOMNodeList** outList)
224 domattr *This = impl_from_IXMLDOMAttribute( iface );
226 TRACE("(%p)->(%p)\n", This, outList);
228 return node_get_child_nodes(&This->node, outList);
231 static HRESULT WINAPI domattr_get_firstChild(
232 IXMLDOMAttribute *iface,
233 IXMLDOMNode** domNode)
235 domattr *This = impl_from_IXMLDOMAttribute( iface );
237 TRACE("(%p)->(%p)\n", This, domNode);
239 return node_get_first_child(&This->node, domNode);
242 static HRESULT WINAPI domattr_get_lastChild(
243 IXMLDOMAttribute *iface,
244 IXMLDOMNode** domNode)
246 domattr *This = impl_from_IXMLDOMAttribute( iface );
248 TRACE("(%p)->(%p)\n", This, domNode);
250 return node_get_last_child(&This->node, domNode);
253 static HRESULT WINAPI domattr_get_previousSibling(
254 IXMLDOMAttribute *iface,
255 IXMLDOMNode** domNode)
257 domattr *This = impl_from_IXMLDOMAttribute( iface );
259 TRACE("(%p)->(%p)\n", This, domNode);
261 return return_null_node(domNode);
264 static HRESULT WINAPI domattr_get_nextSibling(
265 IXMLDOMAttribute *iface,
266 IXMLDOMNode** domNode)
268 domattr *This = impl_from_IXMLDOMAttribute( iface );
270 TRACE("(%p)->(%p)\n", This, domNode);
272 return return_null_node(domNode);
275 static HRESULT WINAPI domattr_get_attributes(
276 IXMLDOMAttribute *iface,
277 IXMLDOMNamedNodeMap** attributeMap)
279 domattr *This = impl_from_IXMLDOMAttribute( iface );
281 TRACE("(%p)->(%p)\n", This, attributeMap);
283 return return_null_ptr((void**)attributeMap);
286 static HRESULT WINAPI domattr_insertBefore(
287 IXMLDOMAttribute *iface,
288 IXMLDOMNode* newNode, VARIANT refChild,
289 IXMLDOMNode** old_node)
291 domattr *This = impl_from_IXMLDOMAttribute( iface );
292 DOMNodeType type;
293 HRESULT hr;
295 FIXME("(%p)->(%p %s %p) needs test\n", This, newNode, debugstr_variant(&refChild), old_node);
297 if (!newNode) return E_INVALIDARG;
299 hr = IXMLDOMNode_get_nodeType(newNode, &type);
300 if (hr != S_OK) return hr;
302 TRACE("new node type %d\n", type);
303 switch (type)
305 case NODE_ATTRIBUTE:
306 case NODE_CDATA_SECTION:
307 case NODE_COMMENT:
308 case NODE_ELEMENT:
309 case NODE_PROCESSING_INSTRUCTION:
310 if (old_node) *old_node = NULL;
311 return E_FAIL;
312 default:
313 return node_insert_before(&This->node, newNode, &refChild, old_node);
317 static HRESULT WINAPI domattr_replaceChild(
318 IXMLDOMAttribute *iface,
319 IXMLDOMNode* newNode,
320 IXMLDOMNode* oldNode,
321 IXMLDOMNode** outOldNode)
323 domattr *This = impl_from_IXMLDOMAttribute( iface );
325 FIXME("(%p)->(%p %p %p) needs tests\n", This, newNode, oldNode, outOldNode);
327 return node_replace_child(&This->node, newNode, oldNode, outOldNode);
330 static HRESULT WINAPI domattr_removeChild(
331 IXMLDOMAttribute *iface,
332 IXMLDOMNode *child, IXMLDOMNode **oldChild)
334 domattr *This = impl_from_IXMLDOMAttribute( iface );
335 TRACE("(%p)->(%p %p)\n", This, child, oldChild);
336 return node_remove_child(&This->node, child, oldChild);
339 static HRESULT WINAPI domattr_appendChild(
340 IXMLDOMAttribute *iface,
341 IXMLDOMNode *child, IXMLDOMNode **outChild)
343 domattr *This = impl_from_IXMLDOMAttribute( iface );
344 TRACE("(%p)->(%p %p)\n", This, child, outChild);
345 return node_append_child(&This->node, child, outChild);
348 static HRESULT WINAPI domattr_hasChildNodes(
349 IXMLDOMAttribute *iface,
350 VARIANT_BOOL *ret)
352 domattr *This = impl_from_IXMLDOMAttribute( iface );
353 TRACE("(%p)->(%p)\n", This, ret);
354 return node_has_childnodes(&This->node, ret);
357 static HRESULT WINAPI domattr_get_ownerDocument(
358 IXMLDOMAttribute *iface,
359 IXMLDOMDocument **doc)
361 domattr *This = impl_from_IXMLDOMAttribute( iface );
362 TRACE("(%p)->(%p)\n", This, doc);
363 return node_get_owner_doc(&This->node, doc);
366 static HRESULT WINAPI domattr_cloneNode(
367 IXMLDOMAttribute *iface,
368 VARIANT_BOOL deep, IXMLDOMNode** outNode)
370 domattr *This = impl_from_IXMLDOMAttribute( iface );
371 TRACE("(%p)->(%d %p)\n", This, deep, outNode);
372 return node_clone( &This->node, deep, outNode );
375 static HRESULT WINAPI domattr_get_nodeTypeString(
376 IXMLDOMAttribute *iface,
377 BSTR* p)
379 domattr *This = impl_from_IXMLDOMAttribute( iface );
380 static const WCHAR attributeW[] = {'a','t','t','r','i','b','u','t','e',0};
382 TRACE("(%p)->(%p)\n", This, p);
384 return return_bstr(attributeW, p);
387 static HRESULT WINAPI domattr_get_text(
388 IXMLDOMAttribute *iface,
389 BSTR* p)
391 domattr *This = impl_from_IXMLDOMAttribute( iface );
392 TRACE("(%p)->(%p)\n", This, p);
393 return node_get_text(&This->node, p);
396 static HRESULT WINAPI domattr_put_text(
397 IXMLDOMAttribute *iface,
398 BSTR p)
400 domattr *This = impl_from_IXMLDOMAttribute( iface );
401 TRACE("(%p)->(%s)\n", This, debugstr_w(p));
402 return node_put_text( &This->node, p );
405 static HRESULT WINAPI domattr_get_specified(
406 IXMLDOMAttribute *iface,
407 VARIANT_BOOL* isSpecified)
409 domattr *This = impl_from_IXMLDOMAttribute( iface );
410 FIXME("(%p)->(%p) stub!\n", This, isSpecified);
411 *isSpecified = VARIANT_TRUE;
412 return S_OK;
415 static HRESULT WINAPI domattr_get_definition(
416 IXMLDOMAttribute *iface,
417 IXMLDOMNode** definitionNode)
419 domattr *This = impl_from_IXMLDOMAttribute( iface );
420 FIXME("(%p)->(%p)\n", This, definitionNode);
421 return E_NOTIMPL;
424 static HRESULT WINAPI domattr_get_nodeTypedValue(
425 IXMLDOMAttribute *iface,
426 VARIANT* value)
428 domattr *This = impl_from_IXMLDOMAttribute( iface );
429 IXMLDOMDocument *doc;
430 HRESULT hr;
432 TRACE("(%p)->(%p)\n", This, value);
434 hr = IXMLDOMAttribute_get_ownerDocument(iface, &doc);
435 if (hr == S_OK)
437 IXMLDOMDocument3 *doc3;
439 hr = IXMLDOMDocument_QueryInterface(doc, &IID_IXMLDOMDocument3, (void**)&doc3);
440 IXMLDOMDocument_Release(doc);
442 if (hr == S_OK)
444 VARIANT schemas;
446 hr = IXMLDOMDocument3_get_schemas(doc3, &schemas);
447 IXMLDOMDocument3_Release(doc3);
449 if (hr != S_OK)
450 return IXMLDOMAttribute_get_value(iface, value);
451 else
453 FIXME("need to query schema for attribute type\n");
454 VariantClear(&schemas);
459 return return_null_var(value);
462 static HRESULT WINAPI domattr_put_nodeTypedValue(
463 IXMLDOMAttribute *iface,
464 VARIANT typedValue)
466 domattr *This = impl_from_IXMLDOMAttribute( iface );
467 FIXME("(%p)->(%s)\n", This, debugstr_variant(&typedValue));
468 return E_NOTIMPL;
471 static HRESULT WINAPI domattr_get_dataType(
472 IXMLDOMAttribute *iface,
473 VARIANT* typename)
475 domattr *This = impl_from_IXMLDOMAttribute( iface );
476 TRACE("(%p)->(%p)\n", This, typename);
477 return return_null_var( typename );
480 static HRESULT WINAPI domattr_put_dataType(
481 IXMLDOMAttribute *iface,
482 BSTR p)
484 domattr *This = impl_from_IXMLDOMAttribute( iface );
486 FIXME("(%p)->(%s)\n", This, debugstr_w(p));
488 if(!p)
489 return E_INVALIDARG;
491 return E_FAIL;
494 static HRESULT WINAPI domattr_get_xml(
495 IXMLDOMAttribute *iface,
496 BSTR* p)
498 domattr *This = impl_from_IXMLDOMAttribute( iface );
500 TRACE("(%p)->(%p)\n", This, p);
502 return node_get_xml(&This->node, FALSE, p);
505 static HRESULT WINAPI domattr_transformNode(
506 IXMLDOMAttribute *iface,
507 IXMLDOMNode *node, BSTR *p)
509 domattr *This = impl_from_IXMLDOMAttribute( iface );
510 TRACE("(%p)->(%p %p)\n", This, node, p);
511 return node_transform_node(&This->node, node, p);
514 static HRESULT WINAPI domattr_selectNodes(
515 IXMLDOMAttribute *iface,
516 BSTR p, IXMLDOMNodeList** outList)
518 domattr *This = impl_from_IXMLDOMAttribute( iface );
519 TRACE("(%p)->(%s %p)\n", This, debugstr_w(p), outList);
520 return node_select_nodes(&This->node, p, outList);
523 static HRESULT WINAPI domattr_selectSingleNode(
524 IXMLDOMAttribute *iface,
525 BSTR p, IXMLDOMNode** outNode)
527 domattr *This = impl_from_IXMLDOMAttribute( iface );
528 TRACE("(%p)->(%s %p)\n", This, debugstr_w(p), outNode);
529 return node_select_singlenode(&This->node, p, outNode);
532 static HRESULT WINAPI domattr_get_parsed(
533 IXMLDOMAttribute *iface,
534 VARIANT_BOOL* isParsed)
536 domattr *This = impl_from_IXMLDOMAttribute( iface );
537 FIXME("(%p)->(%p) stub!\n", This, isParsed);
538 *isParsed = VARIANT_TRUE;
539 return S_OK;
542 static HRESULT WINAPI domattr_get_namespaceURI(
543 IXMLDOMAttribute *iface,
544 BSTR* p)
546 domattr *This = impl_from_IXMLDOMAttribute( iface );
547 xmlNsPtr ns = This->node.node->ns;
548 BSTR nodename, pfx;
549 BOOL is6, isdefault;
550 HRESULT hr;
552 TRACE("(%p)->(%p)\n", This, p);
554 if (!p)
555 return E_INVALIDARG;
557 *p = NULL;
558 nodename = NULL;
559 hr = IXMLDOMAttribute_get_nodeName(iface, &nodename);
560 if (FAILED(hr))
561 return hr;
563 pfx = NULL;
564 hr = IXMLDOMAttribute_get_prefix(iface, &pfx);
565 if (FAILED(hr))
567 SysFreeString(nodename);
568 return hr;
571 is6 = xmldoc_version(This->node.node->doc) == MSXML6;
572 isdefault = !wcscmp(nodename, L"xmlns");
573 if (isdefault || (pfx && !wcscmp(L"xmlns", pfx)))
575 if (is6)
576 *p = SysAllocString(L"http://www.w3.org/2000/xmlns/");
577 else if (!ns || !isdefault)
578 *p = SysAllocStringLen(NULL, 0);
579 else
580 *p = SysAllocString(L"xmlns");
582 else if (ns && ns->href)
583 *p = bstr_from_xmlChar(ns->href);
585 SysFreeString(nodename);
586 SysFreeString(pfx);
588 TRACE("uri: %s\n", debugstr_w(*p));
590 return *p ? S_OK : S_FALSE;
593 static HRESULT WINAPI domattr_get_prefix(
594 IXMLDOMAttribute *iface,
595 BSTR* prefix)
597 domattr *This = impl_from_IXMLDOMAttribute( iface );
598 xmlNsPtr ns = This->node.node->ns;
600 TRACE("(%p)->(%p)\n", This, prefix);
602 if (!prefix) return E_INVALIDARG;
604 *prefix = NULL;
606 if (xmldoc_version(This->node.node->doc) != MSXML6 &&
607 xmlStrEqual(This->node.node->name, xmlns))
608 *prefix = bstr_from_xmlChar(xmlns);
609 else if (ns && ns->prefix)
610 *prefix = bstr_from_xmlChar(ns->prefix);
612 TRACE("prefix: %s\n", debugstr_w(*prefix));
614 return *prefix ? S_OK : S_FALSE;
617 static HRESULT WINAPI domattr_get_baseName(
618 IXMLDOMAttribute *iface,
619 BSTR* name)
621 domattr *This = impl_from_IXMLDOMAttribute( iface );
622 TRACE("(%p)->(%p)\n", This, name);
623 return node_get_base_name( &This->node, name );
626 static HRESULT WINAPI domattr_transformNodeToObject(
627 IXMLDOMAttribute *iface,
628 IXMLDOMNode* domNode, VARIANT var1)
630 domattr *This = impl_from_IXMLDOMAttribute( iface );
631 FIXME("(%p)->(%p %s)\n", This, domNode, debugstr_variant(&var1));
632 return E_NOTIMPL;
635 static HRESULT WINAPI domattr_get_name(
636 IXMLDOMAttribute *iface,
637 BSTR *p)
639 domattr *This = impl_from_IXMLDOMAttribute( iface );
641 TRACE("(%p)->(%p)\n", This, p);
643 return node_get_nodeName(&This->node, p);
646 static HRESULT WINAPI domattr_get_value(
647 IXMLDOMAttribute *iface,
648 VARIANT *value)
650 domattr *This = impl_from_IXMLDOMAttribute( iface );
652 TRACE("(%p)->(%p)\n", This, value);
654 return node_get_content(&This->node, value);
657 static HRESULT WINAPI domattr_put_value(
658 IXMLDOMAttribute *iface,
659 VARIANT value)
661 domattr *This = impl_from_IXMLDOMAttribute( iface );
663 TRACE("(%p)->(%s)\n", This, debugstr_variant(&value));
665 return node_put_value_escaped(&This->node, &value);
668 static const struct IXMLDOMAttributeVtbl domattr_vtbl =
670 domattr_QueryInterface,
671 domattr_AddRef,
672 domattr_Release,
673 domattr_GetTypeInfoCount,
674 domattr_GetTypeInfo,
675 domattr_GetIDsOfNames,
676 domattr_Invoke,
677 domattr_get_nodeName,
678 domattr_get_nodeValue,
679 domattr_put_nodeValue,
680 domattr_get_nodeType,
681 domattr_get_parentNode,
682 domattr_get_childNodes,
683 domattr_get_firstChild,
684 domattr_get_lastChild,
685 domattr_get_previousSibling,
686 domattr_get_nextSibling,
687 domattr_get_attributes,
688 domattr_insertBefore,
689 domattr_replaceChild,
690 domattr_removeChild,
691 domattr_appendChild,
692 domattr_hasChildNodes,
693 domattr_get_ownerDocument,
694 domattr_cloneNode,
695 domattr_get_nodeTypeString,
696 domattr_get_text,
697 domattr_put_text,
698 domattr_get_specified,
699 domattr_get_definition,
700 domattr_get_nodeTypedValue,
701 domattr_put_nodeTypedValue,
702 domattr_get_dataType,
703 domattr_put_dataType,
704 domattr_get_xml,
705 domattr_transformNode,
706 domattr_selectNodes,
707 domattr_selectSingleNode,
708 domattr_get_parsed,
709 domattr_get_namespaceURI,
710 domattr_get_prefix,
711 domattr_get_baseName,
712 domattr_transformNodeToObject,
713 domattr_get_name,
714 domattr_get_value,
715 domattr_put_value
718 static const tid_t domattr_iface_tids[] = {
719 IXMLDOMAttribute_tid,
723 static dispex_static_data_t domattr_dispex = {
724 NULL,
725 IXMLDOMAttribute_tid,
726 NULL,
727 domattr_iface_tids
730 IUnknown* create_attribute( xmlNodePtr attribute, BOOL floating )
732 domattr *This;
734 This = malloc(sizeof(*This));
735 if ( !This )
736 return NULL;
738 This->IXMLDOMAttribute_iface.lpVtbl = &domattr_vtbl;
739 This->ref = 1;
740 This->floating = floating;
742 init_xmlnode(&This->node, attribute, (IXMLDOMNode*)&This->IXMLDOMAttribute_iface, &domattr_dispex);
744 return (IUnknown*)&This->IXMLDOMAttribute_iface;