Synchronize with trunk revision 59781.
[reactos.git] / dll / win32 / msxml3 / node.c
1 /*
2 * Node implementation
3 *
4 * Copyright 2005 Mike McCormack
5 *
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.
10 *
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.
15 *
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
19 */
20
21 #define WIN32_NO_STATUS
22 #define _INC_WINDOWS
23
24 #include <config.h>
25
26 #define COBJMACROS
27
28 //#include <stdarg.h>
29
30 #ifdef HAVE_LIBXML2
31 //# include <libxml/parser.h>
32 //# include <libxml/xmlerror.h>
33 # include <libxml/HTMLtree.h>
34 # ifdef SONAME_LIBXSLT
35 # ifdef HAVE_LIBXSLT_PATTERN_H
36 # include <libxslt/pattern.h>
37 # endif
38 # ifdef HAVE_LIBXSLT_TRANSFORM_H
39 # include <libxslt/transform.h>
40 # endif
41 # include <libxslt/xsltutils.h>
42 # include <libxslt/xsltInternals.h>
43 # endif
44 #endif
45
46 #include <windef.h>
47 #include <winbase.h>
48 //#include "winuser.h"
49 //#include "winnls.h"
50 #include <ole2.h>
51 #include <msxml6.h>
52
53 #include "msxml_private.h"
54
55 #include <wine/debug.h>
56
57 WINE_DEFAULT_DEBUG_CHANNEL(msxml);
58
59 #ifdef HAVE_LIBXML2
60
61 #ifdef SONAME_LIBXSLT
62 extern void* libxslt_handle;
63 # define MAKE_FUNCPTR(f) extern typeof(f) * p##f
64 MAKE_FUNCPTR(xsltApplyStylesheet);
65 MAKE_FUNCPTR(xsltCleanupGlobals);
66 MAKE_FUNCPTR(xsltFreeStylesheet);
67 MAKE_FUNCPTR(xsltParseStylesheetDoc);
68 # undef MAKE_FUNCPTR
69 #endif
70
71 static const IID IID_xmlnode = {0x4f2f4ba2,0xb822,0x11df,{0x8b,0x8a,0x68,0x50,0xdf,0xd7,0x20,0x85}};
72
73 xmlNodePtr xmlNodePtr_from_domnode( IXMLDOMNode *iface, xmlElementType type )
74 {
75 xmlnode *This;
76
77 if ( !iface )
78 return NULL;
79 This = get_node_obj( iface );
80 if ( !This || !This->node )
81 return NULL;
82 if ( type && This->node->type != type )
83 return NULL;
84 return This->node;
85 }
86
87 BOOL node_query_interface(xmlnode *This, REFIID riid, void **ppv)
88 {
89 if(IsEqualGUID(&IID_xmlnode, riid)) {
90 TRACE("(%p)->(IID_xmlnode %p)\n", This, ppv);
91 *ppv = This;
92 return TRUE;
93 }
94
95 return dispex_query_interface(&This->dispex, riid, ppv);
96 }
97
98 /* common ISupportErrorInfo implementation */
99 typedef struct {
100 ISupportErrorInfo ISupportErrorInfo_iface;
101 LONG ref;
102
103 const tid_t* iids;
104 } SupportErrorInfo;
105
106 static inline SupportErrorInfo *impl_from_ISupportErrorInfo(ISupportErrorInfo *iface)
107 {
108 return CONTAINING_RECORD(iface, SupportErrorInfo, ISupportErrorInfo_iface);
109 }
110
111 static HRESULT WINAPI SupportErrorInfo_QueryInterface(ISupportErrorInfo *iface, REFIID riid, void **obj)
112 {
113 SupportErrorInfo *This = impl_from_ISupportErrorInfo(iface);
114 TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), obj);
115
116 *obj = NULL;
117
118 if (IsEqualGUID(riid, &IID_IUnknown) || IsEqualGUID(riid, &IID_ISupportErrorInfo)) {
119 *obj = iface;
120 ISupportErrorInfo_AddRef(iface);
121 return S_OK;
122 }
123
124 return E_NOINTERFACE;
125 }
126
127 static ULONG WINAPI SupportErrorInfo_AddRef(ISupportErrorInfo *iface)
128 {
129 SupportErrorInfo *This = impl_from_ISupportErrorInfo(iface);
130 ULONG ref = InterlockedIncrement(&This->ref);
131 TRACE("(%p)->(%d)\n", This, ref );
132 return ref;
133 }
134
135 static ULONG WINAPI SupportErrorInfo_Release(ISupportErrorInfo *iface)
136 {
137 SupportErrorInfo *This = impl_from_ISupportErrorInfo(iface);
138 LONG ref = InterlockedDecrement(&This->ref);
139
140 TRACE("(%p)->(%d)\n", This, ref);
141
142 if (ref == 0)
143 heap_free(This);
144
145 return ref;
146 }
147
148 static HRESULT WINAPI SupportErrorInfo_InterfaceSupportsErrorInfo(ISupportErrorInfo *iface, REFIID riid)
149 {
150 SupportErrorInfo *This = impl_from_ISupportErrorInfo(iface);
151 enum tid_t const *tid;
152
153 TRACE("(%p)->(%s)\n", This, debugstr_guid(riid));
154
155 tid = This->iids;
156 while (*tid)
157 {
158 if (IsEqualGUID(riid, get_riid_from_tid(*tid)))
159 return S_OK;
160 tid++;
161 }
162
163 return S_FALSE;
164 }
165
166 static const struct ISupportErrorInfoVtbl SupportErrorInfoVtbl = {
167 SupportErrorInfo_QueryInterface,
168 SupportErrorInfo_AddRef,
169 SupportErrorInfo_Release,
170 SupportErrorInfo_InterfaceSupportsErrorInfo
171 };
172
173 HRESULT node_create_supporterrorinfo(enum tid_t const *iids, void **obj)
174 {
175 SupportErrorInfo *This;
176
177 This = heap_alloc(sizeof(*This));
178 if (!This) return E_OUTOFMEMORY;
179
180 This->ISupportErrorInfo_iface.lpVtbl = &SupportErrorInfoVtbl;
181 This->ref = 1;
182 This->iids = iids;
183
184 *obj = &This->ISupportErrorInfo_iface;
185
186 return S_OK;
187 }
188
189 xmlnode *get_node_obj(IXMLDOMNode *node)
190 {
191 xmlnode *obj = NULL;
192 HRESULT hres;
193
194 hres = IXMLDOMNode_QueryInterface(node, &IID_xmlnode, (void**)&obj);
195 if (!obj) WARN("node is not our IXMLDOMNode implementation\n");
196 return SUCCEEDED(hres) ? obj : NULL;
197 }
198
199 HRESULT node_get_nodeName(xmlnode *This, BSTR *name)
200 {
201 BSTR prefix, base;
202 HRESULT hr;
203
204 if (!name)
205 return E_INVALIDARG;
206
207 hr = node_get_base_name(This, &base);
208 if (hr != S_OK) return hr;
209
210 hr = node_get_prefix(This, &prefix);
211 if (hr == S_OK)
212 {
213 static const WCHAR colW = ':';
214 WCHAR *ptr;
215
216 /* +1 for ':' */
217 ptr = *name = SysAllocStringLen(NULL, SysStringLen(base) + SysStringLen(prefix) + 1);
218 memcpy(ptr, prefix, SysStringByteLen(prefix));
219 ptr += SysStringLen(prefix);
220 memcpy(ptr++, &colW, sizeof(WCHAR));
221 memcpy(ptr, base, SysStringByteLen(base));
222
223 SysFreeString(base);
224 SysFreeString(prefix);
225 }
226 else
227 *name = base;
228
229 return S_OK;
230 }
231
232 HRESULT node_get_content(xmlnode *This, VARIANT *value)
233 {
234 xmlChar *content;
235
236 if(!value)
237 return E_INVALIDARG;
238
239 content = xmlNodeGetContent(This->node);
240 V_VT(value) = VT_BSTR;
241 V_BSTR(value) = bstr_from_xmlChar( content );
242 xmlFree(content);
243
244 TRACE("%p returned %s\n", This, debugstr_w(V_BSTR(value)));
245 return S_OK;
246 }
247
248 HRESULT node_set_content(xmlnode *This, LPCWSTR value)
249 {
250 xmlChar *str;
251
252 TRACE("(%p)->(%s)\n", This, debugstr_w(value));
253 str = xmlchar_from_wchar(value);
254 if(!str)
255 return E_OUTOFMEMORY;
256
257 xmlNodeSetContent(This->node, str);
258 heap_free(str);
259 return S_OK;
260 }
261
262 static HRESULT node_set_content_escaped(xmlnode *This, LPCWSTR value)
263 {
264 xmlChar *str, *escaped;
265
266 TRACE("(%p)->(%s)\n", This, debugstr_w(value));
267 str = xmlchar_from_wchar(value);
268 if(!str)
269 return E_OUTOFMEMORY;
270
271 escaped = xmlEncodeSpecialChars(NULL, str);
272 if(!escaped)
273 {
274 heap_free(str);
275 return E_OUTOFMEMORY;
276 }
277
278 xmlNodeSetContent(This->node, escaped);
279
280 heap_free(str);
281 xmlFree(escaped);
282
283 return S_OK;
284 }
285
286 HRESULT node_put_value(xmlnode *This, VARIANT *value)
287 {
288 HRESULT hr;
289
290 if (V_VT(value) != VT_BSTR)
291 {
292 VARIANT string_value;
293
294 VariantInit(&string_value);
295 hr = VariantChangeType(&string_value, value, 0, VT_BSTR);
296 if(FAILED(hr)) {
297 WARN("Couldn't convert to VT_BSTR\n");
298 return hr;
299 }
300
301 hr = node_set_content(This, V_BSTR(&string_value));
302 VariantClear(&string_value);
303 }
304 else
305 hr = node_set_content(This, V_BSTR(value));
306
307 return hr;
308 }
309
310 HRESULT node_put_value_escaped(xmlnode *This, VARIANT *value)
311 {
312 HRESULT hr;
313
314 if (V_VT(value) != VT_BSTR)
315 {
316 VARIANT string_value;
317
318 VariantInit(&string_value);
319 hr = VariantChangeType(&string_value, value, 0, VT_BSTR);
320 if(FAILED(hr)) {
321 WARN("Couldn't convert to VT_BSTR\n");
322 return hr;
323 }
324
325 hr = node_set_content_escaped(This, V_BSTR(&string_value));
326 VariantClear(&string_value);
327 }
328 else
329 hr = node_set_content_escaped(This, V_BSTR(value));
330
331 return hr;
332 }
333
334 static HRESULT get_node(
335 xmlnode *This,
336 const char *name,
337 xmlNodePtr node,
338 IXMLDOMNode **out )
339 {
340 TRACE("(%p)->(%s %p %p)\n", This, name, node, out );
341
342 if ( !out )
343 return E_INVALIDARG;
344
345 /* if we don't have a doc, use our parent. */
346 if(node && !node->doc && node->parent)
347 node->doc = node->parent->doc;
348
349 *out = create_node( node );
350 if (!*out)
351 return S_FALSE;
352 return S_OK;
353 }
354
355 HRESULT node_get_parent(xmlnode *This, IXMLDOMNode **parent)
356 {
357 return get_node( This, "parent", This->node->parent, parent );
358 }
359
360 HRESULT node_get_child_nodes(xmlnode *This, IXMLDOMNodeList **ret)
361 {
362 if(!ret)
363 return E_INVALIDARG;
364
365 *ret = create_children_nodelist(This->node);
366 if(!*ret)
367 return E_OUTOFMEMORY;
368
369 return S_OK;
370 }
371
372 HRESULT node_get_first_child(xmlnode *This, IXMLDOMNode **ret)
373 {
374 return get_node(This, "firstChild", This->node->children, ret);
375 }
376
377 HRESULT node_get_last_child(xmlnode *This, IXMLDOMNode **ret)
378 {
379 return get_node(This, "lastChild", This->node->last, ret);
380 }
381
382 HRESULT node_get_previous_sibling(xmlnode *This, IXMLDOMNode **ret)
383 {
384 return get_node(This, "previous", This->node->prev, ret);
385 }
386
387 HRESULT node_get_next_sibling(xmlnode *This, IXMLDOMNode **ret)
388 {
389 return get_node(This, "next", This->node->next, ret);
390 }
391
392 static int node_get_inst_cnt(xmlNodePtr node)
393 {
394 int ret = *(LONG *)&node->_private;
395 xmlNodePtr child;
396
397 /* add attribute counts */
398 if (node->type == XML_ELEMENT_NODE)
399 {
400 xmlAttrPtr prop = node->properties;
401
402 while (prop)
403 {
404 ret += node_get_inst_cnt((xmlNodePtr)prop);
405 prop = prop->next;
406 }
407 }
408
409 /* add children counts */
410 child = node->children;
411 while (child)
412 {
413 ret += node_get_inst_cnt(child);
414 child = child->next;
415 }
416
417 return ret;
418 }
419
420 int xmlnode_get_inst_cnt(xmlnode *node)
421 {
422 return node_get_inst_cnt(node->node);
423 }
424
425 HRESULT node_insert_before(xmlnode *This, IXMLDOMNode *new_child, const VARIANT *ref_child,
426 IXMLDOMNode **ret)
427 {
428 IXMLDOMNode *before = NULL;
429 xmlnode *node_obj;
430 int refcount = 0;
431 xmlDocPtr doc;
432 HRESULT hr;
433
434 if(!new_child)
435 return E_INVALIDARG;
436
437 node_obj = get_node_obj(new_child);
438 if(!node_obj) return E_FAIL;
439
440 switch(V_VT(ref_child))
441 {
442 case VT_EMPTY:
443 case VT_NULL:
444 break;
445
446 case VT_UNKNOWN:
447 case VT_DISPATCH:
448 if (V_UNKNOWN(ref_child))
449 {
450 hr = IUnknown_QueryInterface(V_UNKNOWN(ref_child), &IID_IXMLDOMNode, (void**)&before);
451 if(FAILED(hr)) return hr;
452 }
453 break;
454
455 default:
456 FIXME("refChild var type %x\n", V_VT(ref_child));
457 return E_FAIL;
458 }
459
460 TRACE("new child %p, This->node %p\n", node_obj->node, This->node);
461
462 if(!node_obj->node->parent)
463 if(xmldoc_remove_orphan(node_obj->node->doc, node_obj->node) != S_OK)
464 WARN("%p is not an orphan of %p\n", node_obj->node, node_obj->node->doc);
465
466 refcount = xmlnode_get_inst_cnt(node_obj);
467
468 if(before)
469 {
470 xmlnode *before_node_obj = get_node_obj(before);
471 IXMLDOMNode_Release(before);
472 if(!before_node_obj) return E_FAIL;
473
474 /* unlink from current parent first */
475 if(node_obj->parent)
476 {
477 hr = IXMLDOMNode_removeChild(node_obj->parent, node_obj->iface, NULL);
478 if (hr == S_OK) xmldoc_remove_orphan(node_obj->node->doc, node_obj->node);
479 }
480
481 doc = node_obj->node->doc;
482
483 /* refs count including subtree */
484 if (doc != before_node_obj->node->doc)
485 refcount = xmlnode_get_inst_cnt(node_obj);
486
487 if (refcount) xmldoc_add_refs(before_node_obj->node->doc, refcount);
488 xmlAddPrevSibling(before_node_obj->node, node_obj->node);
489 if (refcount) xmldoc_release_refs(doc, refcount);
490 node_obj->parent = This->parent;
491 }
492 else
493 {
494 /* unlink from current parent first */
495 if(node_obj->parent)
496 {
497 hr = IXMLDOMNode_removeChild(node_obj->parent, node_obj->iface, NULL);
498 if (hr == S_OK) xmldoc_remove_orphan(node_obj->node->doc, node_obj->node);
499 }
500 doc = node_obj->node->doc;
501
502 if (doc != This->node->doc)
503 refcount = xmlnode_get_inst_cnt(node_obj);
504
505 if (refcount) xmldoc_add_refs(This->node->doc, refcount);
506 /* xmlAddChild doesn't unlink node from previous parent */
507 xmlUnlinkNode(node_obj->node);
508 xmlAddChild(This->node, node_obj->node);
509 if (refcount) xmldoc_release_refs(doc, refcount);
510 node_obj->parent = This->iface;
511 }
512
513 if(ret)
514 {
515 IXMLDOMNode_AddRef(new_child);
516 *ret = new_child;
517 }
518
519 TRACE("ret S_OK\n");
520 return S_OK;
521 }
522
523 HRESULT node_replace_child(xmlnode *This, IXMLDOMNode *newChild, IXMLDOMNode *oldChild,
524 IXMLDOMNode **ret)
525 {
526 xmlnode *old_child, *new_child;
527 xmlDocPtr leaving_doc;
528 xmlNode *my_ancestor;
529 int refcount = 0;
530
531 /* Do not believe any documentation telling that newChild == NULL
532 means removal. It does certainly *not* apply to msxml3! */
533 if(!newChild || !oldChild)
534 return E_INVALIDARG;
535
536 if(ret)
537 *ret = NULL;
538
539 old_child = get_node_obj(oldChild);
540 if(!old_child) return E_FAIL;
541
542 if(old_child->node->parent != This->node)
543 {
544 WARN("childNode %p is not a child of %p\n", oldChild, This);
545 return E_INVALIDARG;
546 }
547
548 new_child = get_node_obj(newChild);
549 if(!new_child) return E_FAIL;
550
551 my_ancestor = This->node;
552 while(my_ancestor)
553 {
554 if(my_ancestor == new_child->node)
555 {
556 WARN("tried to create loop\n");
557 return E_FAIL;
558 }
559 my_ancestor = my_ancestor->parent;
560 }
561
562 if(!new_child->node->parent)
563 if(xmldoc_remove_orphan(new_child->node->doc, new_child->node) != S_OK)
564 WARN("%p is not an orphan of %p\n", new_child->node, new_child->node->doc);
565
566 leaving_doc = new_child->node->doc;
567
568 if (leaving_doc != old_child->node->doc)
569 refcount = xmlnode_get_inst_cnt(new_child);
570
571 if (refcount) xmldoc_add_refs(old_child->node->doc, refcount);
572 xmlReplaceNode(old_child->node, new_child->node);
573 if (refcount) xmldoc_release_refs(leaving_doc, refcount);
574 new_child->parent = old_child->parent;
575 old_child->parent = NULL;
576
577 xmldoc_add_orphan(old_child->node->doc, old_child->node);
578
579 if(ret)
580 {
581 IXMLDOMNode_AddRef(oldChild);
582 *ret = oldChild;
583 }
584
585 return S_OK;
586 }
587
588 HRESULT node_remove_child(xmlnode *This, IXMLDOMNode* child, IXMLDOMNode** oldChild)
589 {
590 xmlnode *child_node;
591
592 if(!child) return E_INVALIDARG;
593
594 if(oldChild)
595 *oldChild = NULL;
596
597 child_node = get_node_obj(child);
598 if(!child_node) return E_FAIL;
599
600 if(child_node->node->parent != This->node)
601 {
602 WARN("childNode %p is not a child of %p\n", child, This);
603 return E_INVALIDARG;
604 }
605
606 xmlUnlinkNode(child_node->node);
607 child_node->parent = NULL;
608 xmldoc_add_orphan(child_node->node->doc, child_node->node);
609
610 if(oldChild)
611 {
612 IXMLDOMNode_AddRef(child);
613 *oldChild = child;
614 }
615
616 return S_OK;
617 }
618
619 HRESULT node_append_child(xmlnode *This, IXMLDOMNode *child, IXMLDOMNode **outChild)
620 {
621 DOMNodeType type;
622 VARIANT var;
623 HRESULT hr;
624
625 hr = IXMLDOMNode_get_nodeType(child, &type);
626 if(FAILED(hr) || type == NODE_ATTRIBUTE) {
627 if (outChild) *outChild = NULL;
628 return E_FAIL;
629 }
630
631 VariantInit(&var);
632 return IXMLDOMNode_insertBefore(This->iface, child, var, outChild);
633 }
634
635 HRESULT node_has_childnodes(const xmlnode *This, VARIANT_BOOL *ret)
636 {
637 if (!ret) return E_INVALIDARG;
638
639 if (!This->node->children)
640 {
641 *ret = VARIANT_FALSE;
642 return S_FALSE;
643 }
644
645 *ret = VARIANT_TRUE;
646 return S_OK;
647 }
648
649 HRESULT node_get_owner_doc(const xmlnode *This, IXMLDOMDocument **doc)
650 {
651 return get_domdoc_from_xmldoc(This->node->doc, (IXMLDOMDocument3**)doc);
652 }
653
654 HRESULT node_clone(xmlnode *This, VARIANT_BOOL deep, IXMLDOMNode **cloneNode)
655 {
656 IXMLDOMNode *node;
657 xmlNodePtr clone;
658
659 if(!cloneNode) return E_INVALIDARG;
660
661 clone = xmlCopyNode(This->node, deep ? 1 : 2);
662 if (clone)
663 {
664 xmlSetTreeDoc(clone, This->node->doc);
665 xmldoc_add_orphan(clone->doc, clone);
666
667 node = create_node(clone);
668 if (!node)
669 {
670 ERR("Copy failed\n");
671 xmldoc_remove_orphan(clone->doc, clone);
672 xmlFreeNode(clone);
673 return E_FAIL;
674 }
675
676 *cloneNode = node;
677 }
678 else
679 {
680 ERR("Copy failed\n");
681 return E_FAIL;
682 }
683
684 return S_OK;
685 }
686
687 static inline xmlChar* trim_whitespace(xmlChar* str)
688 {
689 xmlChar* ret = str;
690 int len;
691
692 if (!str)
693 return NULL;
694
695 while (*ret && isspace(*ret))
696 ++ret;
697 len = xmlStrlen(ret);
698 if (len)
699 while (isspace(ret[len-1])) --len;
700
701 ret = xmlStrndup(ret, len);
702 xmlFree(str);
703 return ret;
704 }
705
706 static xmlChar* do_get_text(xmlNodePtr node)
707 {
708 xmlNodePtr child;
709 xmlChar* str;
710 BOOL preserving = is_preserving_whitespace(node);
711
712 if (!node->children)
713 {
714 str = xmlNodeGetContent(node);
715 }
716 else
717 {
718 xmlElementType prev_type = XML_TEXT_NODE;
719 xmlChar* tmp;
720 str = xmlStrdup(BAD_CAST "");
721 for (child = node->children; child != NULL; child = child->next)
722 {
723 switch (child->type)
724 {
725 case XML_ELEMENT_NODE:
726 tmp = do_get_text(child);
727 break;
728 case XML_TEXT_NODE:
729 case XML_CDATA_SECTION_NODE:
730 case XML_ENTITY_REF_NODE:
731 case XML_ENTITY_NODE:
732 tmp = xmlNodeGetContent(child);
733 break;
734 default:
735 tmp = NULL;
736 break;
737 }
738
739 if (tmp)
740 {
741 if (*tmp)
742 {
743 if (prev_type == XML_ELEMENT_NODE && child->type == XML_ELEMENT_NODE)
744 str = xmlStrcat(str, BAD_CAST " ");
745 str = xmlStrcat(str, tmp);
746 prev_type = child->type;
747 }
748 xmlFree(tmp);
749 }
750 }
751 }
752
753 switch (node->type)
754 {
755 case XML_ELEMENT_NODE:
756 case XML_TEXT_NODE:
757 case XML_ENTITY_REF_NODE:
758 case XML_ENTITY_NODE:
759 case XML_DOCUMENT_NODE:
760 case XML_DOCUMENT_FRAG_NODE:
761 if (!preserving)
762 str = trim_whitespace(str);
763 break;
764 default:
765 break;
766 }
767
768 return str;
769 }
770
771 HRESULT node_get_text(const xmlnode *This, BSTR *text)
772 {
773 BSTR str = NULL;
774 xmlChar *content;
775
776 if (!text) return E_INVALIDARG;
777
778 content = do_get_text(This->node);
779 if (content)
780 {
781 str = bstr_from_xmlChar(content);
782 xmlFree(content);
783 }
784
785 /* Always return a string. */
786 if (!str) str = SysAllocStringLen( NULL, 0 );
787
788 TRACE("%p %s\n", This, debugstr_w(str) );
789 *text = str;
790
791 return S_OK;
792 }
793
794 HRESULT node_put_text(xmlnode *This, BSTR text)
795 {
796 xmlChar *str, *str2;
797
798 TRACE("(%p)->(%s)\n", This, debugstr_w(text));
799
800 str = xmlchar_from_wchar(text);
801
802 /* Escape the string. */
803 str2 = xmlEncodeEntitiesReentrant(This->node->doc, str);
804 heap_free(str);
805
806 xmlNodeSetContent(This->node, str2);
807 xmlFree(str2);
808
809 return S_OK;
810 }
811
812 BSTR EnsureCorrectEOL(BSTR sInput)
813 {
814 int nNum = 0;
815 BSTR sNew;
816 int nLen;
817 int i;
818
819 nLen = SysStringLen(sInput);
820 /* Count line endings */
821 for(i=0; i < nLen; i++)
822 {
823 if(sInput[i] == '\n')
824 nNum++;
825 }
826
827 TRACE("len=%d, num=%d\n", nLen, nNum);
828
829 /* Add linefeed as needed */
830 if(nNum > 0)
831 {
832 int nPlace = 0;
833 sNew = SysAllocStringLen(NULL, nLen + nNum);
834 for(i=0; i < nLen; i++)
835 {
836 if(sInput[i] == '\n')
837 {
838 sNew[i+nPlace] = '\r';
839 nPlace++;
840 }
841 sNew[i+nPlace] = sInput[i];
842 }
843
844 SysFreeString(sInput);
845 }
846 else
847 {
848 sNew = sInput;
849 }
850
851 TRACE("len %d\n", SysStringLen(sNew));
852
853 return sNew;
854 }
855
856 /*
857 * We are trying to replicate the same behaviour as msxml by converting
858 * line endings to \r\n and using indents as \t. The problem is that msxml
859 * only formats nodes that have a line ending. Using libxml we cannot
860 * reproduce behaviour exactly.
861 *
862 */
863 HRESULT node_get_xml(xmlnode *This, BOOL ensure_eol, BSTR *ret)
864 {
865 xmlBufferPtr xml_buf;
866 xmlNodePtr xmldecl;
867 int size;
868
869 if(!ret)
870 return E_INVALIDARG;
871
872 *ret = NULL;
873
874 xml_buf = xmlBufferCreate();
875 if(!xml_buf)
876 return E_OUTOFMEMORY;
877
878 xmldecl = xmldoc_unlink_xmldecl( This->node->doc );
879
880 size = xmlNodeDump(xml_buf, This->node->doc, This->node, 0, 1);
881 if(size > 0) {
882 const xmlChar *buf_content;
883 BSTR content;
884
885 /* Attribute Nodes return a space in front of their name */
886 buf_content = xmlBufferContent(xml_buf);
887
888 content = bstr_from_xmlChar(buf_content + (buf_content[0] == ' ' ? 1 : 0));
889 if(ensure_eol)
890 content = EnsureCorrectEOL(content);
891
892 *ret = content;
893 }else {
894 *ret = SysAllocStringLen(NULL, 0);
895 }
896
897 xmlBufferFree(xml_buf);
898 xmldoc_link_xmldecl( This->node->doc, xmldecl );
899 return *ret ? S_OK : E_OUTOFMEMORY;
900 }
901
902 static void htmldtd_dumpcontent(xmlOutputBufferPtr buf, xmlDocPtr doc)
903 {
904 xmlDtdPtr cur = doc->intSubset;
905
906 xmlOutputBufferWriteString(buf, "<!DOCTYPE ");
907 xmlOutputBufferWriteString(buf, (const char *)cur->name);
908 if (cur->ExternalID)
909 {
910 xmlOutputBufferWriteString(buf, " PUBLIC ");
911 xmlBufferWriteQuotedString(buf->buffer, cur->ExternalID);
912 if (cur->SystemID)
913 {
914 xmlOutputBufferWriteString(buf, " ");
915 xmlBufferWriteQuotedString(buf->buffer, cur->SystemID);
916 }
917 }
918 else if (cur->SystemID)
919 {
920 xmlOutputBufferWriteString(buf, " SYSTEM ");
921 xmlBufferWriteQuotedString(buf->buffer, cur->SystemID);
922 }
923 xmlOutputBufferWriteString(buf, ">\n");
924 }
925
926 static void htmldoc_dumpcontent(xmlOutputBufferPtr buf, xmlDocPtr doc)
927 {
928 xmlElementType type;
929
930 /* force HTML output */
931 type = doc->type;
932 doc->type = XML_HTML_DOCUMENT_NODE;
933 if (doc->intSubset)
934 htmldtd_dumpcontent(buf, doc);
935 if (doc->children)
936 {
937 xmlNodePtr cur = doc->children;
938
939 while (cur)
940 {
941 htmlNodeDumpFormatOutput(buf, doc, cur, NULL, 1);
942 cur = cur->next;
943 }
944
945 }
946 doc->type = type;
947 }
948
949 HRESULT node_transform_node(const xmlnode *This, IXMLDOMNode *stylesheet, BSTR *p)
950 {
951 #ifdef SONAME_LIBXSLT
952 xsltStylesheetPtr xsltSS;
953 xmlnode *sheet;
954
955 if (!libxslt_handle) return E_NOTIMPL;
956 if (!stylesheet || !p) return E_INVALIDARG;
957
958 *p = NULL;
959
960 sheet = get_node_obj(stylesheet);
961 if(!sheet) return E_FAIL;
962
963 xsltSS = pxsltParseStylesheetDoc(sheet->node->doc);
964 if(xsltSS)
965 {
966 xmlDocPtr result = pxsltApplyStylesheet(xsltSS, This->node->doc, NULL);
967 if(result)
968 {
969 const xmlChar *content;
970
971 if(result->type == XML_HTML_DOCUMENT_NODE)
972 {
973 xmlOutputBufferPtr output = xmlAllocOutputBuffer(NULL);
974 if (output)
975 {
976 htmldoc_dumpcontent(output, result->doc);
977 content = xmlBufferContent(output->buffer);
978 *p = bstr_from_xmlChar(content);
979 xmlOutputBufferClose(output);
980 }
981 }
982 else
983 {
984 xmlBufferPtr buf = xmlBufferCreate();
985 if (buf)
986 {
987 int size = xmlNodeDump(buf, NULL, (xmlNodePtr)result, 0, 0);
988 if(size > 0)
989 {
990 content = xmlBufferContent(buf);
991 *p = bstr_from_xmlChar(content);
992 }
993 xmlBufferFree(buf);
994 }
995 }
996 xmlFreeDoc(result);
997 }
998 /* libxslt "helpfully" frees the XML document the stylesheet was
999 generated from, too */
1000 xsltSS->doc = NULL;
1001 pxsltFreeStylesheet(xsltSS);
1002 }
1003
1004 if(!*p) *p = SysAllocStringLen(NULL, 0);
1005
1006 return S_OK;
1007 #else
1008 FIXME("libxslt headers were not found at compile time\n");
1009 return E_NOTIMPL;
1010 #endif
1011 }
1012
1013 HRESULT node_select_nodes(const xmlnode *This, BSTR query, IXMLDOMNodeList **nodes)
1014 {
1015 xmlChar* str;
1016 HRESULT hr;
1017
1018 if (!query || !nodes) return E_INVALIDARG;
1019
1020 str = xmlchar_from_wchar(query);
1021 hr = create_selection(This->node, str, nodes);
1022 heap_free(str);
1023
1024 return hr;
1025 }
1026
1027 HRESULT node_select_singlenode(const xmlnode *This, BSTR query, IXMLDOMNode **node)
1028 {
1029 IXMLDOMNodeList *list;
1030 HRESULT hr;
1031
1032 hr = node_select_nodes(This, query, &list);
1033 if (hr == S_OK)
1034 {
1035 hr = IXMLDOMNodeList_nextNode(list, node);
1036 IXMLDOMNodeList_Release(list);
1037 }
1038 return hr;
1039 }
1040
1041 HRESULT node_get_namespaceURI(xmlnode *This, BSTR *namespaceURI)
1042 {
1043 xmlNsPtr ns = This->node->ns;
1044
1045 if(!namespaceURI)
1046 return E_INVALIDARG;
1047
1048 *namespaceURI = NULL;
1049
1050 if (ns && ns->href)
1051 *namespaceURI = bstr_from_xmlChar(ns->href);
1052
1053 TRACE("uri: %s\n", debugstr_w(*namespaceURI));
1054
1055 return *namespaceURI ? S_OK : S_FALSE;
1056 }
1057
1058 HRESULT node_get_prefix(xmlnode *This, BSTR *prefix)
1059 {
1060 xmlNsPtr ns = This->node->ns;
1061
1062 if (!prefix) return E_INVALIDARG;
1063
1064 *prefix = NULL;
1065
1066 if (ns && ns->prefix)
1067 *prefix = bstr_from_xmlChar(ns->prefix);
1068
1069 TRACE("prefix: %s\n", debugstr_w(*prefix));
1070
1071 return *prefix ? S_OK : S_FALSE;
1072 }
1073
1074 HRESULT node_get_base_name(xmlnode *This, BSTR *name)
1075 {
1076 if (!name) return E_INVALIDARG;
1077
1078 *name = bstr_from_xmlChar(This->node->name);
1079 if (!*name) return E_OUTOFMEMORY;
1080
1081 TRACE("returning %s\n", debugstr_w(*name));
1082
1083 return S_OK;
1084 }
1085
1086 /* _private field holds a number of COM instances spawned from this libxml2 node */
1087 static void xmlnode_add_ref(xmlNodePtr node)
1088 {
1089 if (node->type == XML_DOCUMENT_NODE) return;
1090 InterlockedIncrement((LONG*)&node->_private);
1091 }
1092
1093 static void xmlnode_release(xmlNodePtr node)
1094 {
1095 if (node->type == XML_DOCUMENT_NODE) return;
1096 InterlockedDecrement((LONG*)&node->_private);
1097 }
1098
1099 void destroy_xmlnode(xmlnode *This)
1100 {
1101 if(This->node)
1102 {
1103 xmlnode_release(This->node);
1104 xmldoc_release(This->node->doc);
1105 }
1106 release_dispex(&This->dispex);
1107 }
1108
1109 void init_xmlnode(xmlnode *This, xmlNodePtr node, IXMLDOMNode *node_iface, dispex_static_data_t *dispex_data)
1110 {
1111 if(node)
1112 {
1113 xmlnode_add_ref(node);
1114 xmldoc_add_ref(node->doc);
1115 }
1116
1117 This->node = node;
1118 This->iface = node_iface;
1119 This->parent = NULL;
1120
1121 init_dispex(&This->dispex, (IUnknown*)This->iface, dispex_data);
1122 }
1123
1124 typedef struct {
1125 xmlnode node;
1126 IXMLDOMNode IXMLDOMNode_iface;
1127 LONG ref;
1128 } unknode;
1129
1130 static inline unknode *unknode_from_IXMLDOMNode(IXMLDOMNode *iface)
1131 {
1132 return CONTAINING_RECORD(iface, unknode, IXMLDOMNode_iface);
1133 }
1134
1135 static HRESULT WINAPI unknode_QueryInterface(
1136 IXMLDOMNode *iface,
1137 REFIID riid,
1138 void** ppvObject )
1139 {
1140 unknode *This = unknode_from_IXMLDOMNode( iface );
1141
1142 TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppvObject);
1143
1144 if (IsEqualGUID(riid, &IID_IUnknown)) {
1145 *ppvObject = iface;
1146 }else if (IsEqualGUID( riid, &IID_IDispatch) ||
1147 IsEqualGUID( riid, &IID_IXMLDOMNode)) {
1148 *ppvObject = &This->IXMLDOMNode_iface;
1149 }else if(node_query_interface(&This->node, riid, ppvObject)) {
1150 return *ppvObject ? S_OK : E_NOINTERFACE;
1151 }else {
1152 FIXME("interface %s not implemented\n", debugstr_guid(riid));
1153 *ppvObject = NULL;
1154 return E_NOINTERFACE;
1155 }
1156
1157 IUnknown_AddRef((IUnknown*)*ppvObject);
1158 return S_OK;
1159 }
1160
1161 static ULONG WINAPI unknode_AddRef(
1162 IXMLDOMNode *iface )
1163 {
1164 unknode *This = unknode_from_IXMLDOMNode( iface );
1165
1166 return InterlockedIncrement(&This->ref);
1167 }
1168
1169 static ULONG WINAPI unknode_Release(
1170 IXMLDOMNode *iface )
1171 {
1172 unknode *This = unknode_from_IXMLDOMNode( iface );
1173 LONG ref;
1174
1175 ref = InterlockedDecrement( &This->ref );
1176 if(!ref) {
1177 destroy_xmlnode(&This->node);
1178 heap_free(This);
1179 }
1180
1181 return ref;
1182 }
1183
1184 static HRESULT WINAPI unknode_GetTypeInfoCount(
1185 IXMLDOMNode *iface,
1186 UINT* pctinfo )
1187 {
1188 unknode *This = unknode_from_IXMLDOMNode( iface );
1189
1190 TRACE("(%p)->(%p)\n", This, pctinfo);
1191
1192 *pctinfo = 1;
1193
1194 return S_OK;
1195 }
1196
1197 static HRESULT WINAPI unknode_GetTypeInfo(
1198 IXMLDOMNode *iface,
1199 UINT iTInfo,
1200 LCID lcid,
1201 ITypeInfo** ppTInfo )
1202 {
1203 unknode *This = unknode_from_IXMLDOMNode( iface );
1204 HRESULT hr;
1205
1206 TRACE("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo);
1207
1208 hr = get_typeinfo(IXMLDOMNode_tid, ppTInfo);
1209
1210 return hr;
1211 }
1212
1213 static HRESULT WINAPI unknode_GetIDsOfNames(
1214 IXMLDOMNode *iface,
1215 REFIID riid,
1216 LPOLESTR* rgszNames,
1217 UINT cNames,
1218 LCID lcid,
1219 DISPID* rgDispId )
1220 {
1221 unknode *This = unknode_from_IXMLDOMNode( iface );
1222
1223 ITypeInfo *typeinfo;
1224 HRESULT hr;
1225
1226 TRACE("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames, cNames,
1227 lcid, rgDispId);
1228
1229 if(!rgszNames || cNames == 0 || !rgDispId)
1230 return E_INVALIDARG;
1231
1232 hr = get_typeinfo(IXMLDOMNode_tid, &typeinfo);
1233 if(SUCCEEDED(hr))
1234 {
1235 hr = ITypeInfo_GetIDsOfNames(typeinfo, rgszNames, cNames, rgDispId);
1236 ITypeInfo_Release(typeinfo);
1237 }
1238
1239 return hr;
1240 }
1241
1242 static HRESULT WINAPI unknode_Invoke(
1243 IXMLDOMNode *iface,
1244 DISPID dispIdMember,
1245 REFIID riid,
1246 LCID lcid,
1247 WORD wFlags,
1248 DISPPARAMS* pDispParams,
1249 VARIANT* pVarResult,
1250 EXCEPINFO* pExcepInfo,
1251 UINT* puArgErr )
1252 {
1253 unknode *This = unknode_from_IXMLDOMNode( iface );
1254 ITypeInfo *typeinfo;
1255 HRESULT hr;
1256
1257 TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
1258 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
1259
1260 hr = get_typeinfo(IXMLDOMNode_tid, &typeinfo);
1261 if(SUCCEEDED(hr))
1262 {
1263 hr = ITypeInfo_Invoke(typeinfo, &This->IXMLDOMNode_iface, dispIdMember, wFlags, pDispParams,
1264 pVarResult, pExcepInfo, puArgErr);
1265 ITypeInfo_Release(typeinfo);
1266 }
1267
1268 return hr;
1269 }
1270
1271 static HRESULT WINAPI unknode_get_nodeName(
1272 IXMLDOMNode *iface,
1273 BSTR* p )
1274 {
1275 unknode *This = unknode_from_IXMLDOMNode( iface );
1276
1277 FIXME("(%p)->(%p)\n", This, p);
1278
1279 return node_get_nodeName(&This->node, p);
1280 }
1281
1282 static HRESULT WINAPI unknode_get_nodeValue(
1283 IXMLDOMNode *iface,
1284 VARIANT* value)
1285 {
1286 unknode *This = unknode_from_IXMLDOMNode( iface );
1287
1288 FIXME("(%p)->(%p)\n", This, value);
1289
1290 if(!value)
1291 return E_INVALIDARG;
1292
1293 V_VT(value) = VT_NULL;
1294 return S_FALSE;
1295 }
1296
1297 static HRESULT WINAPI unknode_put_nodeValue(
1298 IXMLDOMNode *iface,
1299 VARIANT value)
1300 {
1301 unknode *This = unknode_from_IXMLDOMNode( iface );
1302 FIXME("(%p)->(v%d)\n", This, V_VT(&value));
1303 return E_FAIL;
1304 }
1305
1306 static HRESULT WINAPI unknode_get_nodeType(
1307 IXMLDOMNode *iface,
1308 DOMNodeType* domNodeType )
1309 {
1310 unknode *This = unknode_from_IXMLDOMNode( iface );
1311
1312 FIXME("(%p)->(%p)\n", This, domNodeType);
1313
1314 *domNodeType = This->node.node->type;
1315 return S_OK;
1316 }
1317
1318 static HRESULT WINAPI unknode_get_parentNode(
1319 IXMLDOMNode *iface,
1320 IXMLDOMNode** parent )
1321 {
1322 unknode *This = unknode_from_IXMLDOMNode( iface );
1323 FIXME("(%p)->(%p)\n", This, parent);
1324 if (!parent) return E_INVALIDARG;
1325 *parent = NULL;
1326 return S_FALSE;
1327 }
1328
1329 static HRESULT WINAPI unknode_get_childNodes(
1330 IXMLDOMNode *iface,
1331 IXMLDOMNodeList** outList)
1332 {
1333 unknode *This = unknode_from_IXMLDOMNode( iface );
1334
1335 TRACE("(%p)->(%p)\n", This, outList);
1336
1337 return node_get_child_nodes(&This->node, outList);
1338 }
1339
1340 static HRESULT WINAPI unknode_get_firstChild(
1341 IXMLDOMNode *iface,
1342 IXMLDOMNode** domNode)
1343 {
1344 unknode *This = unknode_from_IXMLDOMNode( iface );
1345
1346 TRACE("(%p)->(%p)\n", This, domNode);
1347
1348 return node_get_first_child(&This->node, domNode);
1349 }
1350
1351 static HRESULT WINAPI unknode_get_lastChild(
1352 IXMLDOMNode *iface,
1353 IXMLDOMNode** domNode)
1354 {
1355 unknode *This = unknode_from_IXMLDOMNode( iface );
1356
1357 TRACE("(%p)->(%p)\n", This, domNode);
1358
1359 return node_get_last_child(&This->node, domNode);
1360 }
1361
1362 static HRESULT WINAPI unknode_get_previousSibling(
1363 IXMLDOMNode *iface,
1364 IXMLDOMNode** domNode)
1365 {
1366 unknode *This = unknode_from_IXMLDOMNode( iface );
1367
1368 TRACE("(%p)->(%p)\n", This, domNode);
1369
1370 return node_get_previous_sibling(&This->node, domNode);
1371 }
1372
1373 static HRESULT WINAPI unknode_get_nextSibling(
1374 IXMLDOMNode *iface,
1375 IXMLDOMNode** domNode)
1376 {
1377 unknode *This = unknode_from_IXMLDOMNode( iface );
1378
1379 TRACE("(%p)->(%p)\n", This, domNode);
1380
1381 return node_get_next_sibling(&This->node, domNode);
1382 }
1383
1384 static HRESULT WINAPI unknode_get_attributes(
1385 IXMLDOMNode *iface,
1386 IXMLDOMNamedNodeMap** attributeMap)
1387 {
1388 unknode *This = unknode_from_IXMLDOMNode( iface );
1389
1390 FIXME("(%p)->(%p)\n", This, attributeMap);
1391
1392 return return_null_ptr((void**)attributeMap);
1393 }
1394
1395 static HRESULT WINAPI unknode_insertBefore(
1396 IXMLDOMNode *iface,
1397 IXMLDOMNode* newNode, VARIANT refChild,
1398 IXMLDOMNode** outOldNode)
1399 {
1400 unknode *This = unknode_from_IXMLDOMNode( iface );
1401
1402 FIXME("(%p)->(%p x%d %p)\n", This, newNode, V_VT(&refChild), outOldNode);
1403
1404 return node_insert_before(&This->node, newNode, &refChild, outOldNode);
1405 }
1406
1407 static HRESULT WINAPI unknode_replaceChild(
1408 IXMLDOMNode *iface,
1409 IXMLDOMNode* newNode,
1410 IXMLDOMNode* oldNode,
1411 IXMLDOMNode** outOldNode)
1412 {
1413 unknode *This = unknode_from_IXMLDOMNode( iface );
1414
1415 FIXME("(%p)->(%p %p %p)\n", This, newNode, oldNode, outOldNode);
1416
1417 return node_replace_child(&This->node, newNode, oldNode, outOldNode);
1418 }
1419
1420 static HRESULT WINAPI unknode_removeChild(
1421 IXMLDOMNode *iface,
1422 IXMLDOMNode* domNode, IXMLDOMNode** oldNode)
1423 {
1424 unknode *This = unknode_from_IXMLDOMNode( iface );
1425 return node_remove_child(&This->node, domNode, oldNode);
1426 }
1427
1428 static HRESULT WINAPI unknode_appendChild(
1429 IXMLDOMNode *iface,
1430 IXMLDOMNode* newNode, IXMLDOMNode** outNewNode)
1431 {
1432 unknode *This = unknode_from_IXMLDOMNode( iface );
1433 return node_append_child(&This->node, newNode, outNewNode);
1434 }
1435
1436 static HRESULT WINAPI unknode_hasChildNodes(
1437 IXMLDOMNode *iface,
1438 VARIANT_BOOL* pbool)
1439 {
1440 unknode *This = unknode_from_IXMLDOMNode( iface );
1441 return node_has_childnodes(&This->node, pbool);
1442 }
1443
1444 static HRESULT WINAPI unknode_get_ownerDocument(
1445 IXMLDOMNode *iface,
1446 IXMLDOMDocument** domDocument)
1447 {
1448 unknode *This = unknode_from_IXMLDOMNode( iface );
1449 return node_get_owner_doc(&This->node, domDocument);
1450 }
1451
1452 static HRESULT WINAPI unknode_cloneNode(
1453 IXMLDOMNode *iface,
1454 VARIANT_BOOL pbool, IXMLDOMNode** outNode)
1455 {
1456 unknode *This = unknode_from_IXMLDOMNode( iface );
1457 return node_clone(&This->node, pbool, outNode );
1458 }
1459
1460 static HRESULT WINAPI unknode_get_nodeTypeString(
1461 IXMLDOMNode *iface,
1462 BSTR* p)
1463 {
1464 unknode *This = unknode_from_IXMLDOMNode( iface );
1465
1466 FIXME("(%p)->(%p)\n", This, p);
1467
1468 return node_get_nodeName(&This->node, p);
1469 }
1470
1471 static HRESULT WINAPI unknode_get_text(
1472 IXMLDOMNode *iface,
1473 BSTR* p)
1474 {
1475 unknode *This = unknode_from_IXMLDOMNode( iface );
1476 return node_get_text(&This->node, p);
1477 }
1478
1479 static HRESULT WINAPI unknode_put_text(
1480 IXMLDOMNode *iface,
1481 BSTR p)
1482 {
1483 unknode *This = unknode_from_IXMLDOMNode( iface );
1484 return node_put_text(&This->node, p);
1485 }
1486
1487 static HRESULT WINAPI unknode_get_specified(
1488 IXMLDOMNode *iface,
1489 VARIANT_BOOL* isSpecified)
1490 {
1491 unknode *This = unknode_from_IXMLDOMNode( iface );
1492 FIXME("(%p)->(%p) stub!\n", This, isSpecified);
1493 *isSpecified = VARIANT_TRUE;
1494 return S_OK;
1495 }
1496
1497 static HRESULT WINAPI unknode_get_definition(
1498 IXMLDOMNode *iface,
1499 IXMLDOMNode** definitionNode)
1500 {
1501 unknode *This = unknode_from_IXMLDOMNode( iface );
1502 FIXME("(%p)->(%p)\n", This, definitionNode);
1503 return E_NOTIMPL;
1504 }
1505
1506 static HRESULT WINAPI unknode_get_nodeTypedValue(
1507 IXMLDOMNode *iface,
1508 VARIANT* var1)
1509 {
1510 unknode *This = unknode_from_IXMLDOMNode( iface );
1511 FIXME("(%p)->(%p)\n", This, var1);
1512 return return_null_var(var1);
1513 }
1514
1515 static HRESULT WINAPI unknode_put_nodeTypedValue(
1516 IXMLDOMNode *iface,
1517 VARIANT typedValue)
1518 {
1519 unknode *This = unknode_from_IXMLDOMNode( iface );
1520 FIXME("(%p)->(%s)\n", This, debugstr_variant(&typedValue));
1521 return E_NOTIMPL;
1522 }
1523
1524 static HRESULT WINAPI unknode_get_dataType(
1525 IXMLDOMNode *iface,
1526 VARIANT* var1)
1527 {
1528 unknode *This = unknode_from_IXMLDOMNode( iface );
1529 TRACE("(%p)->(%p)\n", This, var1);
1530 return return_null_var(var1);
1531 }
1532
1533 static HRESULT WINAPI unknode_put_dataType(
1534 IXMLDOMNode *iface,
1535 BSTR p)
1536 {
1537 unknode *This = unknode_from_IXMLDOMNode( iface );
1538
1539 FIXME("(%p)->(%s)\n", This, debugstr_w(p));
1540
1541 if(!p)
1542 return E_INVALIDARG;
1543
1544 return E_FAIL;
1545 }
1546
1547 static HRESULT WINAPI unknode_get_xml(
1548 IXMLDOMNode *iface,
1549 BSTR* p)
1550 {
1551 unknode *This = unknode_from_IXMLDOMNode( iface );
1552
1553 FIXME("(%p)->(%p)\n", This, p);
1554
1555 return node_get_xml(&This->node, FALSE, p);
1556 }
1557
1558 static HRESULT WINAPI unknode_transformNode(
1559 IXMLDOMNode *iface,
1560 IXMLDOMNode* domNode, BSTR* p)
1561 {
1562 unknode *This = unknode_from_IXMLDOMNode( iface );
1563 return node_transform_node(&This->node, domNode, p);
1564 }
1565
1566 static HRESULT WINAPI unknode_selectNodes(
1567 IXMLDOMNode *iface,
1568 BSTR p, IXMLDOMNodeList** outList)
1569 {
1570 unknode *This = unknode_from_IXMLDOMNode( iface );
1571 return node_select_nodes(&This->node, p, outList);
1572 }
1573
1574 static HRESULT WINAPI unknode_selectSingleNode(
1575 IXMLDOMNode *iface,
1576 BSTR p, IXMLDOMNode** outNode)
1577 {
1578 unknode *This = unknode_from_IXMLDOMNode( iface );
1579 return node_select_singlenode(&This->node, p, outNode);
1580 }
1581
1582 static HRESULT WINAPI unknode_get_parsed(
1583 IXMLDOMNode *iface,
1584 VARIANT_BOOL* isParsed)
1585 {
1586 unknode *This = unknode_from_IXMLDOMNode( iface );
1587 FIXME("(%p)->(%p) stub!\n", This, isParsed);
1588 *isParsed = VARIANT_TRUE;
1589 return S_OK;
1590 }
1591
1592 static HRESULT WINAPI unknode_get_namespaceURI(
1593 IXMLDOMNode *iface,
1594 BSTR* p)
1595 {
1596 unknode *This = unknode_from_IXMLDOMNode( iface );
1597 TRACE("(%p)->(%p)\n", This, p);
1598 return node_get_namespaceURI(&This->node, p);
1599 }
1600
1601 static HRESULT WINAPI unknode_get_prefix(
1602 IXMLDOMNode *iface,
1603 BSTR* p)
1604 {
1605 unknode *This = unknode_from_IXMLDOMNode( iface );
1606 return node_get_prefix(&This->node, p);
1607 }
1608
1609 static HRESULT WINAPI unknode_get_baseName(
1610 IXMLDOMNode *iface,
1611 BSTR* p)
1612 {
1613 unknode *This = unknode_from_IXMLDOMNode( iface );
1614 return node_get_base_name(&This->node, p);
1615 }
1616
1617 static HRESULT WINAPI unknode_transformNodeToObject(
1618 IXMLDOMNode *iface,
1619 IXMLDOMNode* domNode, VARIANT var1)
1620 {
1621 unknode *This = unknode_from_IXMLDOMNode( iface );
1622 FIXME("(%p)->(%p %s)\n", This, domNode, debugstr_variant(&var1));
1623 return E_NOTIMPL;
1624 }
1625
1626 static const struct IXMLDOMNodeVtbl unknode_vtbl =
1627 {
1628 unknode_QueryInterface,
1629 unknode_AddRef,
1630 unknode_Release,
1631 unknode_GetTypeInfoCount,
1632 unknode_GetTypeInfo,
1633 unknode_GetIDsOfNames,
1634 unknode_Invoke,
1635 unknode_get_nodeName,
1636 unknode_get_nodeValue,
1637 unknode_put_nodeValue,
1638 unknode_get_nodeType,
1639 unknode_get_parentNode,
1640 unknode_get_childNodes,
1641 unknode_get_firstChild,
1642 unknode_get_lastChild,
1643 unknode_get_previousSibling,
1644 unknode_get_nextSibling,
1645 unknode_get_attributes,
1646 unknode_insertBefore,
1647 unknode_replaceChild,
1648 unknode_removeChild,
1649 unknode_appendChild,
1650 unknode_hasChildNodes,
1651 unknode_get_ownerDocument,
1652 unknode_cloneNode,
1653 unknode_get_nodeTypeString,
1654 unknode_get_text,
1655 unknode_put_text,
1656 unknode_get_specified,
1657 unknode_get_definition,
1658 unknode_get_nodeTypedValue,
1659 unknode_put_nodeTypedValue,
1660 unknode_get_dataType,
1661 unknode_put_dataType,
1662 unknode_get_xml,
1663 unknode_transformNode,
1664 unknode_selectNodes,
1665 unknode_selectSingleNode,
1666 unknode_get_parsed,
1667 unknode_get_namespaceURI,
1668 unknode_get_prefix,
1669 unknode_get_baseName,
1670 unknode_transformNodeToObject
1671 };
1672
1673 IXMLDOMNode *create_node( xmlNodePtr node )
1674 {
1675 IUnknown *pUnk;
1676 IXMLDOMNode *ret;
1677 HRESULT hr;
1678
1679 if ( !node )
1680 return NULL;
1681
1682 TRACE("type %d\n", node->type);
1683 switch(node->type)
1684 {
1685 case XML_ELEMENT_NODE:
1686 pUnk = create_element( node );
1687 break;
1688 case XML_ATTRIBUTE_NODE:
1689 pUnk = create_attribute( node );
1690 break;
1691 case XML_TEXT_NODE:
1692 pUnk = create_text( node );
1693 break;
1694 case XML_CDATA_SECTION_NODE:
1695 pUnk = create_cdata( node );
1696 break;
1697 case XML_ENTITY_REF_NODE:
1698 pUnk = create_doc_entity_ref( node );
1699 break;
1700 case XML_PI_NODE:
1701 pUnk = create_pi( node );
1702 break;
1703 case XML_COMMENT_NODE:
1704 pUnk = create_comment( node );
1705 break;
1706 case XML_DOCUMENT_NODE:
1707 pUnk = create_domdoc( node );
1708 break;
1709 case XML_DOCUMENT_FRAG_NODE:
1710 pUnk = create_doc_fragment( node );
1711 break;
1712 case XML_DTD_NODE:
1713 pUnk = create_doc_type( node );
1714 break;
1715 default: {
1716 unknode *new_node;
1717
1718 FIXME("only creating basic node for type %d\n", node->type);
1719
1720 new_node = heap_alloc(sizeof(unknode));
1721 if(!new_node)
1722 return NULL;
1723
1724 new_node->IXMLDOMNode_iface.lpVtbl = &unknode_vtbl;
1725 new_node->ref = 1;
1726 init_xmlnode(&new_node->node, node, &new_node->IXMLDOMNode_iface, NULL);
1727 pUnk = (IUnknown*)&new_node->IXMLDOMNode_iface;
1728 }
1729 }
1730
1731 hr = IUnknown_QueryInterface(pUnk, &IID_IXMLDOMNode, (LPVOID*)&ret);
1732 IUnknown_Release(pUnk);
1733 if(FAILED(hr)) return NULL;
1734 return ret;
1735 }
1736 #endif