ntdll: Make sure we don't try to attach the main exe a second time.
[wine/zf.git] / dlls / msxml3 / attribute.c
blobc303969bc39fcf0036960194301a68bad2b4b46e
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 #ifdef HAVE_LIBXML2
44 WINE_DEFAULT_DEBUG_CHANNEL(msxml);
46 static const xmlChar xmlns[] = "xmlns";
48 typedef struct _domattr
50 xmlnode node;
51 IXMLDOMAttribute IXMLDOMAttribute_iface;
52 LONG ref;
53 BOOL floating;
54 } domattr;
56 static const tid_t domattr_se_tids[] = {
57 IXMLDOMNode_tid,
58 IXMLDOMAttribute_tid,
59 NULL_tid
62 static inline domattr *impl_from_IXMLDOMAttribute( IXMLDOMAttribute *iface )
64 return CONTAINING_RECORD(iface, domattr, IXMLDOMAttribute_iface);
67 static HRESULT WINAPI domattr_QueryInterface(
68 IXMLDOMAttribute *iface,
69 REFIID riid,
70 void** ppvObject )
72 domattr *This = impl_from_IXMLDOMAttribute( iface );
73 TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppvObject);
75 if ( IsEqualGUID( riid, &IID_IXMLDOMAttribute ) ||
76 IsEqualGUID( riid, &IID_IXMLDOMNode ) ||
77 IsEqualGUID( riid, &IID_IDispatch ) ||
78 IsEqualGUID( riid, &IID_IUnknown ) )
80 *ppvObject = iface;
82 else if(node_query_interface(&This->node, riid, ppvObject))
84 return *ppvObject ? S_OK : E_NOINTERFACE;
86 else if(IsEqualGUID( riid, &IID_ISupportErrorInfo ))
88 return node_create_supporterrorinfo(domattr_se_tids, ppvObject);
90 else
92 TRACE("Unsupported interface %s\n", debugstr_guid(riid));
93 *ppvObject = NULL;
94 return E_NOINTERFACE;
97 IXMLDOMAttribute_AddRef(iface);
98 return S_OK;
101 static ULONG WINAPI domattr_AddRef(
102 IXMLDOMAttribute *iface )
104 domattr *This = impl_from_IXMLDOMAttribute( iface );
105 ULONG ref = InterlockedIncrement( &This->ref );
106 TRACE("(%p)->(%d)\n", This, ref);
107 return ref;
110 static ULONG WINAPI domattr_Release(
111 IXMLDOMAttribute *iface )
113 domattr *This = impl_from_IXMLDOMAttribute( iface );
114 ULONG ref = InterlockedDecrement( &This->ref );
116 TRACE("(%p)->(%d)\n", This, ref);
117 if ( ref == 0 )
119 destroy_xmlnode(&This->node);
120 if ( This->floating )
122 xmlFreeNs( This->node.node->ns );
123 xmlFreeNode( This->node.node );
125 heap_free( This );
128 return ref;
131 static HRESULT WINAPI domattr_GetTypeInfoCount(
132 IXMLDOMAttribute *iface,
133 UINT* pctinfo )
135 domattr *This = impl_from_IXMLDOMAttribute( iface );
136 return IDispatchEx_GetTypeInfoCount(&This->node.dispex.IDispatchEx_iface, pctinfo);
139 static HRESULT WINAPI domattr_GetTypeInfo(
140 IXMLDOMAttribute *iface,
141 UINT iTInfo, LCID lcid,
142 ITypeInfo** ppTInfo )
144 domattr *This = impl_from_IXMLDOMAttribute( iface );
145 return IDispatchEx_GetTypeInfo(&This->node.dispex.IDispatchEx_iface,
146 iTInfo, lcid, ppTInfo);
149 static HRESULT WINAPI domattr_GetIDsOfNames(
150 IXMLDOMAttribute *iface,
151 REFIID riid, LPOLESTR* rgszNames,
152 UINT cNames, LCID lcid, DISPID* rgDispId )
154 domattr *This = impl_from_IXMLDOMAttribute( iface );
155 return IDispatchEx_GetIDsOfNames(&This->node.dispex.IDispatchEx_iface,
156 riid, rgszNames, cNames, lcid, rgDispId);
159 static HRESULT WINAPI domattr_Invoke(
160 IXMLDOMAttribute *iface,
161 DISPID dispIdMember, REFIID riid, LCID lcid,
162 WORD wFlags, DISPPARAMS* pDispParams, VARIANT* pVarResult,
163 EXCEPINFO* pExcepInfo, UINT* puArgErr )
165 domattr *This = impl_from_IXMLDOMAttribute( iface );
166 return IDispatchEx_Invoke(&This->node.dispex.IDispatchEx_iface,
167 dispIdMember, riid, lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
170 static HRESULT WINAPI domattr_get_nodeName(
171 IXMLDOMAttribute *iface,
172 BSTR* p )
174 domattr *This = impl_from_IXMLDOMAttribute( iface );
176 TRACE("(%p)->(%p)\n", This, p);
178 return node_get_nodeName(&This->node, p);
181 static HRESULT WINAPI domattr_get_nodeValue(
182 IXMLDOMAttribute *iface,
183 VARIANT* value)
185 domattr *This = impl_from_IXMLDOMAttribute( iface );
187 TRACE("(%p)->(%p)\n", This, value);
189 return node_get_content(&This->node, value);
192 static HRESULT WINAPI domattr_put_nodeValue(
193 IXMLDOMAttribute *iface,
194 VARIANT value)
196 domattr *This = impl_from_IXMLDOMAttribute( iface );
198 TRACE("(%p)->(%s)\n", This, debugstr_variant(&value));
200 return node_put_value_escaped(&This->node, &value);
203 static HRESULT WINAPI domattr_get_nodeType(
204 IXMLDOMAttribute *iface,
205 DOMNodeType* domNodeType )
207 domattr *This = impl_from_IXMLDOMAttribute( iface );
209 TRACE("(%p)->(%p)\n", This, domNodeType);
211 *domNodeType = NODE_ATTRIBUTE;
212 return S_OK;
215 static HRESULT WINAPI domattr_get_parentNode(
216 IXMLDOMAttribute *iface,
217 IXMLDOMNode** parent )
219 domattr *This = impl_from_IXMLDOMAttribute( iface );
220 TRACE("(%p)->(%p)\n", This, parent);
221 if (!parent) return E_INVALIDARG;
222 *parent = NULL;
223 return S_FALSE;
226 static HRESULT WINAPI domattr_get_childNodes(
227 IXMLDOMAttribute *iface,
228 IXMLDOMNodeList** outList)
230 domattr *This = impl_from_IXMLDOMAttribute( iface );
232 TRACE("(%p)->(%p)\n", This, outList);
234 return node_get_child_nodes(&This->node, outList);
237 static HRESULT WINAPI domattr_get_firstChild(
238 IXMLDOMAttribute *iface,
239 IXMLDOMNode** domNode)
241 domattr *This = impl_from_IXMLDOMAttribute( iface );
243 TRACE("(%p)->(%p)\n", This, domNode);
245 return node_get_first_child(&This->node, domNode);
248 static HRESULT WINAPI domattr_get_lastChild(
249 IXMLDOMAttribute *iface,
250 IXMLDOMNode** domNode)
252 domattr *This = impl_from_IXMLDOMAttribute( iface );
254 TRACE("(%p)->(%p)\n", This, domNode);
256 return node_get_last_child(&This->node, domNode);
259 static HRESULT WINAPI domattr_get_previousSibling(
260 IXMLDOMAttribute *iface,
261 IXMLDOMNode** domNode)
263 domattr *This = impl_from_IXMLDOMAttribute( iface );
265 TRACE("(%p)->(%p)\n", This, domNode);
267 return return_null_node(domNode);
270 static HRESULT WINAPI domattr_get_nextSibling(
271 IXMLDOMAttribute *iface,
272 IXMLDOMNode** domNode)
274 domattr *This = impl_from_IXMLDOMAttribute( iface );
276 TRACE("(%p)->(%p)\n", This, domNode);
278 return return_null_node(domNode);
281 static HRESULT WINAPI domattr_get_attributes(
282 IXMLDOMAttribute *iface,
283 IXMLDOMNamedNodeMap** attributeMap)
285 domattr *This = impl_from_IXMLDOMAttribute( iface );
287 TRACE("(%p)->(%p)\n", This, attributeMap);
289 return return_null_ptr((void**)attributeMap);
292 static HRESULT WINAPI domattr_insertBefore(
293 IXMLDOMAttribute *iface,
294 IXMLDOMNode* newNode, VARIANT refChild,
295 IXMLDOMNode** old_node)
297 domattr *This = impl_from_IXMLDOMAttribute( iface );
298 DOMNodeType type;
299 HRESULT hr;
301 FIXME("(%p)->(%p %s %p) needs test\n", This, newNode, debugstr_variant(&refChild), old_node);
303 if (!newNode) return E_INVALIDARG;
305 hr = IXMLDOMNode_get_nodeType(newNode, &type);
306 if (hr != S_OK) return hr;
308 TRACE("new node type %d\n", type);
309 switch (type)
311 case NODE_ATTRIBUTE:
312 case NODE_CDATA_SECTION:
313 case NODE_COMMENT:
314 case NODE_ELEMENT:
315 case NODE_PROCESSING_INSTRUCTION:
316 if (old_node) *old_node = NULL;
317 return E_FAIL;
318 default:
319 return node_insert_before(&This->node, newNode, &refChild, old_node);
323 static HRESULT WINAPI domattr_replaceChild(
324 IXMLDOMAttribute *iface,
325 IXMLDOMNode* newNode,
326 IXMLDOMNode* oldNode,
327 IXMLDOMNode** outOldNode)
329 domattr *This = impl_from_IXMLDOMAttribute( iface );
331 FIXME("(%p)->(%p %p %p) needs tests\n", This, newNode, oldNode, outOldNode);
333 return node_replace_child(&This->node, newNode, oldNode, outOldNode);
336 static HRESULT WINAPI domattr_removeChild(
337 IXMLDOMAttribute *iface,
338 IXMLDOMNode *child, IXMLDOMNode **oldChild)
340 domattr *This = impl_from_IXMLDOMAttribute( iface );
341 TRACE("(%p)->(%p %p)\n", This, child, oldChild);
342 return node_remove_child(&This->node, child, oldChild);
345 static HRESULT WINAPI domattr_appendChild(
346 IXMLDOMAttribute *iface,
347 IXMLDOMNode *child, IXMLDOMNode **outChild)
349 domattr *This = impl_from_IXMLDOMAttribute( iface );
350 TRACE("(%p)->(%p %p)\n", This, child, outChild);
351 return node_append_child(&This->node, child, outChild);
354 static HRESULT WINAPI domattr_hasChildNodes(
355 IXMLDOMAttribute *iface,
356 VARIANT_BOOL *ret)
358 domattr *This = impl_from_IXMLDOMAttribute( iface );
359 TRACE("(%p)->(%p)\n", This, ret);
360 return node_has_childnodes(&This->node, ret);
363 static HRESULT WINAPI domattr_get_ownerDocument(
364 IXMLDOMAttribute *iface,
365 IXMLDOMDocument **doc)
367 domattr *This = impl_from_IXMLDOMAttribute( iface );
368 TRACE("(%p)->(%p)\n", This, doc);
369 return node_get_owner_doc(&This->node, doc);
372 static HRESULT WINAPI domattr_cloneNode(
373 IXMLDOMAttribute *iface,
374 VARIANT_BOOL deep, IXMLDOMNode** outNode)
376 domattr *This = impl_from_IXMLDOMAttribute( iface );
377 TRACE("(%p)->(%d %p)\n", This, deep, outNode);
378 return node_clone( &This->node, deep, outNode );
381 static HRESULT WINAPI domattr_get_nodeTypeString(
382 IXMLDOMAttribute *iface,
383 BSTR* p)
385 domattr *This = impl_from_IXMLDOMAttribute( iface );
386 static const WCHAR attributeW[] = {'a','t','t','r','i','b','u','t','e',0};
388 TRACE("(%p)->(%p)\n", This, p);
390 return return_bstr(attributeW, p);
393 static HRESULT WINAPI domattr_get_text(
394 IXMLDOMAttribute *iface,
395 BSTR* p)
397 domattr *This = impl_from_IXMLDOMAttribute( iface );
398 TRACE("(%p)->(%p)\n", This, p);
399 return node_get_text(&This->node, p);
402 static HRESULT WINAPI domattr_put_text(
403 IXMLDOMAttribute *iface,
404 BSTR p)
406 domattr *This = impl_from_IXMLDOMAttribute( iface );
407 TRACE("(%p)->(%s)\n", This, debugstr_w(p));
408 return node_put_text( &This->node, p );
411 static HRESULT WINAPI domattr_get_specified(
412 IXMLDOMAttribute *iface,
413 VARIANT_BOOL* isSpecified)
415 domattr *This = impl_from_IXMLDOMAttribute( iface );
416 FIXME("(%p)->(%p) stub!\n", This, isSpecified);
417 *isSpecified = VARIANT_TRUE;
418 return S_OK;
421 static HRESULT WINAPI domattr_get_definition(
422 IXMLDOMAttribute *iface,
423 IXMLDOMNode** definitionNode)
425 domattr *This = impl_from_IXMLDOMAttribute( iface );
426 FIXME("(%p)->(%p)\n", This, definitionNode);
427 return E_NOTIMPL;
430 static HRESULT WINAPI domattr_get_nodeTypedValue(
431 IXMLDOMAttribute *iface,
432 VARIANT* value)
434 domattr *This = impl_from_IXMLDOMAttribute( iface );
435 IXMLDOMDocument *doc;
436 HRESULT hr;
438 TRACE("(%p)->(%p)\n", This, value);
440 hr = IXMLDOMAttribute_get_ownerDocument(iface, &doc);
441 if (hr == S_OK)
443 IXMLDOMDocument3 *doc3;
445 hr = IXMLDOMDocument_QueryInterface(doc, &IID_IXMLDOMDocument3, (void**)&doc3);
446 IXMLDOMDocument_Release(doc);
448 if (hr == S_OK)
450 VARIANT schemas;
452 hr = IXMLDOMDocument3_get_schemas(doc3, &schemas);
453 IXMLDOMDocument3_Release(doc3);
455 if (hr != S_OK)
456 return IXMLDOMAttribute_get_value(iface, value);
457 else
459 FIXME("need to query schema for attribute type\n");
460 VariantClear(&schemas);
465 return return_null_var(value);
468 static HRESULT WINAPI domattr_put_nodeTypedValue(
469 IXMLDOMAttribute *iface,
470 VARIANT typedValue)
472 domattr *This = impl_from_IXMLDOMAttribute( iface );
473 FIXME("(%p)->(%s)\n", This, debugstr_variant(&typedValue));
474 return E_NOTIMPL;
477 static HRESULT WINAPI domattr_get_dataType(
478 IXMLDOMAttribute *iface,
479 VARIANT* typename)
481 domattr *This = impl_from_IXMLDOMAttribute( iface );
482 TRACE("(%p)->(%p)\n", This, typename);
483 return return_null_var( typename );
486 static HRESULT WINAPI domattr_put_dataType(
487 IXMLDOMAttribute *iface,
488 BSTR p)
490 domattr *This = impl_from_IXMLDOMAttribute( iface );
492 FIXME("(%p)->(%s)\n", This, debugstr_w(p));
494 if(!p)
495 return E_INVALIDARG;
497 return E_FAIL;
500 static HRESULT WINAPI domattr_get_xml(
501 IXMLDOMAttribute *iface,
502 BSTR* p)
504 domattr *This = impl_from_IXMLDOMAttribute( iface );
506 TRACE("(%p)->(%p)\n", This, p);
508 return node_get_xml(&This->node, FALSE, p);
511 static HRESULT WINAPI domattr_transformNode(
512 IXMLDOMAttribute *iface,
513 IXMLDOMNode *node, BSTR *p)
515 domattr *This = impl_from_IXMLDOMAttribute( iface );
516 TRACE("(%p)->(%p %p)\n", This, node, p);
517 return node_transform_node(&This->node, node, p);
520 static HRESULT WINAPI domattr_selectNodes(
521 IXMLDOMAttribute *iface,
522 BSTR p, IXMLDOMNodeList** outList)
524 domattr *This = impl_from_IXMLDOMAttribute( iface );
525 TRACE("(%p)->(%s %p)\n", This, debugstr_w(p), outList);
526 return node_select_nodes(&This->node, p, outList);
529 static HRESULT WINAPI domattr_selectSingleNode(
530 IXMLDOMAttribute *iface,
531 BSTR p, IXMLDOMNode** outNode)
533 domattr *This = impl_from_IXMLDOMAttribute( iface );
534 TRACE("(%p)->(%s %p)\n", This, debugstr_w(p), outNode);
535 return node_select_singlenode(&This->node, p, outNode);
538 static HRESULT WINAPI domattr_get_parsed(
539 IXMLDOMAttribute *iface,
540 VARIANT_BOOL* isParsed)
542 domattr *This = impl_from_IXMLDOMAttribute( iface );
543 FIXME("(%p)->(%p) stub!\n", This, isParsed);
544 *isParsed = VARIANT_TRUE;
545 return S_OK;
548 static HRESULT WINAPI domattr_get_namespaceURI(
549 IXMLDOMAttribute *iface,
550 BSTR* p)
552 static const WCHAR w3xmlns[] = { 'h','t','t','p',':','/','/', 'w','w','w','.','w','3','.',
553 'o','r','g','/','2','0','0','0','/','x','m','l','n','s','/',0 };
554 domattr *This = impl_from_IXMLDOMAttribute( iface );
555 xmlNsPtr ns = This->node.node->ns;
557 TRACE("(%p)->(%p)\n", This, p);
559 if (!p)
560 return E_INVALIDARG;
562 *p = NULL;
564 if (ns)
566 /* special case for default namespace definition */
567 if (xmlStrEqual(This->node.node->name, xmlns))
568 *p = bstr_from_xmlChar(xmlns);
569 else if (xmlStrEqual(ns->prefix, xmlns))
571 if (xmldoc_version(This->node.node->doc) == MSXML6)
572 *p = SysAllocString(w3xmlns);
573 else
574 *p = SysAllocStringLen(NULL, 0);
576 else if (ns->href)
577 *p = bstr_from_xmlChar(ns->href);
580 TRACE("uri: %s\n", debugstr_w(*p));
582 return *p ? S_OK : S_FALSE;
585 static HRESULT WINAPI domattr_get_prefix(
586 IXMLDOMAttribute *iface,
587 BSTR* prefix)
589 domattr *This = impl_from_IXMLDOMAttribute( iface );
590 xmlNsPtr ns = This->node.node->ns;
592 TRACE("(%p)->(%p)\n", This, prefix);
594 if (!prefix) return E_INVALIDARG;
596 *prefix = NULL;
598 if (ns)
600 /* special case for default namespace definition */
601 if (xmlStrEqual(This->node.node->name, xmlns))
602 *prefix = bstr_from_xmlChar(xmlns);
603 else if (ns->prefix)
604 *prefix = bstr_from_xmlChar(ns->prefix);
607 TRACE("prefix: %s\n", debugstr_w(*prefix));
609 return *prefix ? S_OK : S_FALSE;
612 static HRESULT WINAPI domattr_get_baseName(
613 IXMLDOMAttribute *iface,
614 BSTR* name)
616 domattr *This = impl_from_IXMLDOMAttribute( iface );
617 TRACE("(%p)->(%p)\n", This, name);
618 return node_get_base_name( &This->node, name );
621 static HRESULT WINAPI domattr_transformNodeToObject(
622 IXMLDOMAttribute *iface,
623 IXMLDOMNode* domNode, VARIANT var1)
625 domattr *This = impl_from_IXMLDOMAttribute( iface );
626 FIXME("(%p)->(%p %s)\n", This, domNode, debugstr_variant(&var1));
627 return E_NOTIMPL;
630 static HRESULT WINAPI domattr_get_name(
631 IXMLDOMAttribute *iface,
632 BSTR *p)
634 domattr *This = impl_from_IXMLDOMAttribute( iface );
636 TRACE("(%p)->(%p)\n", This, p);
638 return node_get_nodeName(&This->node, p);
641 static HRESULT WINAPI domattr_get_value(
642 IXMLDOMAttribute *iface,
643 VARIANT *value)
645 domattr *This = impl_from_IXMLDOMAttribute( iface );
647 TRACE("(%p)->(%p)\n", This, value);
649 return node_get_content(&This->node, value);
652 static HRESULT WINAPI domattr_put_value(
653 IXMLDOMAttribute *iface,
654 VARIANT value)
656 domattr *This = impl_from_IXMLDOMAttribute( iface );
658 TRACE("(%p)->(%s)\n", This, debugstr_variant(&value));
660 return node_put_value_escaped(&This->node, &value);
663 static const struct IXMLDOMAttributeVtbl domattr_vtbl =
665 domattr_QueryInterface,
666 domattr_AddRef,
667 domattr_Release,
668 domattr_GetTypeInfoCount,
669 domattr_GetTypeInfo,
670 domattr_GetIDsOfNames,
671 domattr_Invoke,
672 domattr_get_nodeName,
673 domattr_get_nodeValue,
674 domattr_put_nodeValue,
675 domattr_get_nodeType,
676 domattr_get_parentNode,
677 domattr_get_childNodes,
678 domattr_get_firstChild,
679 domattr_get_lastChild,
680 domattr_get_previousSibling,
681 domattr_get_nextSibling,
682 domattr_get_attributes,
683 domattr_insertBefore,
684 domattr_replaceChild,
685 domattr_removeChild,
686 domattr_appendChild,
687 domattr_hasChildNodes,
688 domattr_get_ownerDocument,
689 domattr_cloneNode,
690 domattr_get_nodeTypeString,
691 domattr_get_text,
692 domattr_put_text,
693 domattr_get_specified,
694 domattr_get_definition,
695 domattr_get_nodeTypedValue,
696 domattr_put_nodeTypedValue,
697 domattr_get_dataType,
698 domattr_put_dataType,
699 domattr_get_xml,
700 domattr_transformNode,
701 domattr_selectNodes,
702 domattr_selectSingleNode,
703 domattr_get_parsed,
704 domattr_get_namespaceURI,
705 domattr_get_prefix,
706 domattr_get_baseName,
707 domattr_transformNodeToObject,
708 domattr_get_name,
709 domattr_get_value,
710 domattr_put_value
713 static const tid_t domattr_iface_tids[] = {
714 IXMLDOMAttribute_tid,
718 static dispex_static_data_t domattr_dispex = {
719 NULL,
720 IXMLDOMAttribute_tid,
721 NULL,
722 domattr_iface_tids
725 IUnknown* create_attribute( xmlNodePtr attribute, BOOL floating )
727 domattr *This;
729 This = heap_alloc( sizeof *This );
730 if ( !This )
731 return NULL;
733 This->IXMLDOMAttribute_iface.lpVtbl = &domattr_vtbl;
734 This->ref = 1;
735 This->floating = floating;
737 init_xmlnode(&This->node, attribute, (IXMLDOMNode*)&This->IXMLDOMAttribute_iface, &domattr_dispex);
739 return (IUnknown*)&This->IXMLDOMAttribute_iface;
742 #endif