1 /*
2 * DOM processing instruction node implementation
3 *
4 * Copyright 2006 Huw Davies
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 COBJMACROS
22
23 #include "config.h"
24
25 #include <stdarg.h>
26 #include "windef.h"
27 #include "winbase.h"
28 #include "winuser.h"
29 #include "ole2.h"
30 #include "msxml2.h"
31
32 #include "msxml_private.h"
33
34 #include "wine/debug.h"
35
36 WINE_DEFAULT_DEBUG_CHANNEL(msxml);
37
38 #ifdef HAVE_LIBXML2
39
40 typedef struct _dom_pi
41 {
42 const struct IXMLDOMProcessingInstructionVtbl *lpVtbl;
43 LONG ref;
44 IUnknown *node_unk;
45 IXMLDOMNode *node;
46 } dom_pi;
47
48 static inline dom_pi *impl_from_IXMLDOMProcessingInstruction( IXMLDOMProcessingInstruction *iface )
49 {
50 return (dom_pi *)((char*)iface - FIELD_OFFSET(dom_pi, lpVtbl));
51 }
52
53 static HRESULT WINAPI dom_pi_QueryInterface(
54 IXMLDOMProcessingInstruction *iface,
55 REFIID riid,
56 void** ppvObject )
57 {
58 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
59 TRACE("%p %s %p\n", This, debugstr_guid(riid), ppvObject);
60
61 if ( IsEqualGUID( riid, &IID_IXMLDOMProcessingInstruction ) ||
62 IsEqualGUID( riid, &IID_IDispatch ) ||
63 IsEqualGUID( riid, &IID_IUnknown ) )
64 {
65 *ppvObject = iface;
66 }
67 else if ( IsEqualGUID( riid, &IID_IXMLDOMNode ) )
68 {
69 return IUnknown_QueryInterface(This->node_unk, riid, ppvObject);
70 }
71 else
72 {
73 FIXME("Unsupported interface %s\n", debugstr_guid(riid));
74 return E_NOINTERFACE;
75 }
76
77 IXMLDOMProcessingInstruction_AddRef( iface );
78
79 return S_OK;
80 }
81
82 static ULONG WINAPI dom_pi_AddRef(
83 IXMLDOMProcessingInstruction *iface )
84 {
85 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
86 return InterlockedIncrement( &This->ref );
87 }
88
89 static ULONG WINAPI dom_pi_Release(
90 IXMLDOMProcessingInstruction *iface )
91 {
92 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
93 ULONG ref;
94
95 ref = InterlockedDecrement( &This->ref );
96 if ( ref == 0 )
97 {
98 IUnknown_Release( This->node_unk );
99 HeapFree( GetProcessHeap(), 0, This );
100 }
101
102 return ref;
103 }
104
105 static HRESULT WINAPI dom_pi_GetTypeInfoCount(
106 IXMLDOMProcessingInstruction *iface,
107 UINT* pctinfo )
108 {
109 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
110
111 TRACE("(%p)->(%p)\n", This, pctinfo);
112
113 *pctinfo = 1;
114
115 return S_OK;
116 }
117
118 static HRESULT WINAPI dom_pi_GetTypeInfo(
119 IXMLDOMProcessingInstruction *iface,
120 UINT iTInfo, LCID lcid,
121 ITypeInfo** ppTInfo )
122 {
123 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
124 HRESULT hr;
125
126 TRACE("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo);
127
128 hr = get_typeinfo(IXMLDOMProcessingInstruction_tid, ppTInfo);
129
130 return hr;
131 }
132
133 static HRESULT WINAPI dom_pi_GetIDsOfNames(
134 IXMLDOMProcessingInstruction *iface,
135 REFIID riid, LPOLESTR* rgszNames,
136 UINT cNames, LCID lcid, DISPID* rgDispId )
137 {
138 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
139 ITypeInfo *typeinfo;
140 HRESULT hr;
141
142 TRACE("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames, cNames,
143 lcid, rgDispId);
144
145 if(!rgszNames || cNames == 0 || !rgDispId)
146 return E_INVALIDARG;
147
148 hr = get_typeinfo(IXMLDOMProcessingInstruction_tid, &typeinfo);
149 if(SUCCEEDED(hr))
150 {
151 hr = ITypeInfo_GetIDsOfNames(typeinfo, rgszNames, cNames, rgDispId);
152 ITypeInfo_Release(typeinfo);
153 }
154
155 return hr;
156 }
157
158 static HRESULT WINAPI dom_pi_Invoke(
159 IXMLDOMProcessingInstruction *iface,
160 DISPID dispIdMember, REFIID riid, LCID lcid,
161 WORD wFlags, DISPPARAMS* pDispParams, VARIANT* pVarResult,
162 EXCEPINFO* pExcepInfo, UINT* puArgErr )
163 {
164 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
165 ITypeInfo *typeinfo;
166 HRESULT hr;
167
168 TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
169 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
170
171 hr = get_typeinfo(IXMLDOMProcessingInstruction_tid, &typeinfo);
172 if(SUCCEEDED(hr))
173 {
174 hr = ITypeInfo_Invoke(typeinfo, &(This->lpVtbl), dispIdMember, wFlags, pDispParams,
175 pVarResult, pExcepInfo, puArgErr);
176 ITypeInfo_Release(typeinfo);
177 }
178
179 return hr;
180 }
181
182 static HRESULT WINAPI dom_pi_get_nodeName(
183 IXMLDOMProcessingInstruction *iface,
184 BSTR* p )
185 {
186 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
187 return IXMLDOMNode_get_nodeName( This->node, p );
188 }
189
190 static HRESULT WINAPI dom_pi_get_nodeValue(
191 IXMLDOMProcessingInstruction *iface,
192 VARIANT* var1 )
193 {
194 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
195 return IXMLDOMNode_get_nodeValue( This->node, var1 );
196 }
197
198 static HRESULT WINAPI dom_pi_put_nodeValue(
199 IXMLDOMProcessingInstruction *iface,
200 VARIANT var1 )
201 {
202 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
203 BSTR sTarget;
204 static const WCHAR szXML[] = {'x','m','l',0};
205 HRESULT hr;
206
207 TRACE("%p\n", This );
208
209 /* Cannot set data to a PI node whose target is 'xml' */
210 hr = dom_pi_get_nodeName(iface, &sTarget);
211 if(hr == S_OK)
212 {
213 if(lstrcmpW( sTarget, szXML) == 0)
214 {
215 SysFreeString(sTarget);
216 return E_FAIL;
217 }
218
219 SysFreeString(sTarget);
220 }
221
222 return IXMLDOMNode_put_nodeValue( This->node, var1 );
223 }
224
225 static HRESULT WINAPI dom_pi_get_nodeType(
226 IXMLDOMProcessingInstruction *iface,
227 DOMNodeType* domNodeType )
228 {
229 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
230 return IXMLDOMNode_get_nodeType( This->node, domNodeType );
231 }
232
233 static HRESULT WINAPI dom_pi_get_parentNode(
234 IXMLDOMProcessingInstruction *iface,
235 IXMLDOMNode** parent )
236 {
237 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
238 return IXMLDOMNode_get_parentNode( This->node, parent );
239 }
240
241 static HRESULT WINAPI dom_pi_get_childNodes(
242 IXMLDOMProcessingInstruction *iface,
243 IXMLDOMNodeList** outList)
244 {
245 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
246 return IXMLDOMNode_get_childNodes( This->node, outList );
247 }
248
249 static HRESULT WINAPI dom_pi_get_firstChild(
250 IXMLDOMProcessingInstruction *iface,
251 IXMLDOMNode** domNode)
252 {
253 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
254 return IXMLDOMNode_get_firstChild( This->node, domNode );
255 }
256
257 static HRESULT WINAPI dom_pi_get_lastChild(
258 IXMLDOMProcessingInstruction *iface,
259 IXMLDOMNode** domNode)
260 {
261 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
262 return IXMLDOMNode_get_lastChild( This->node, domNode );
263 }
264
265 static HRESULT WINAPI dom_pi_get_previousSibling(
266 IXMLDOMProcessingInstruction *iface,
267 IXMLDOMNode** domNode)
268 {
269 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
270 return IXMLDOMNode_get_previousSibling( This->node, domNode );
271 }
272
273 static HRESULT WINAPI dom_pi_get_nextSibling(
274 IXMLDOMProcessingInstruction *iface,
275 IXMLDOMNode** domNode)
276 {
277 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
278 return IXMLDOMNode_get_nextSibling( This->node, domNode );
279 }
280
281 static HRESULT WINAPI dom_pi_get_attributes(
282 IXMLDOMProcessingInstruction *iface,
283 IXMLDOMNamedNodeMap** attributeMap)
284 {
285 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
286 return IXMLDOMNode_get_attributes( This->node, attributeMap );
287 }
288
289 static HRESULT WINAPI dom_pi_insertBefore(
290 IXMLDOMProcessingInstruction *iface,
291 IXMLDOMNode* newNode, VARIANT var1,
292 IXMLDOMNode** outOldNode)
293 {
294 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
295 return IXMLDOMNode_insertBefore( This->node, newNode, var1, outOldNode );
296 }
297
298 static HRESULT WINAPI dom_pi_replaceChild(
299 IXMLDOMProcessingInstruction *iface,
300 IXMLDOMNode* newNode,
301 IXMLDOMNode* oldNode,
302 IXMLDOMNode** outOldNode)
303 {
304 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
305 return IXMLDOMNode_replaceChild( This->node, newNode, oldNode, outOldNode );
306 }
307
308 static HRESULT WINAPI dom_pi_removeChild(
309 IXMLDOMProcessingInstruction *iface,
310 IXMLDOMNode* domNode, IXMLDOMNode** oldNode)
311 {
312 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
313 return IXMLDOMNode_removeChild( This->node, domNode, oldNode );
314 }
315
316 static HRESULT WINAPI dom_pi_appendChild(
317 IXMLDOMProcessingInstruction *iface,
318 IXMLDOMNode* newNode, IXMLDOMNode** outNewNode)
319 {
320 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
321 return IXMLDOMNode_appendChild( This->node, newNode, outNewNode );
322 }
323
324 static HRESULT WINAPI dom_pi_hasChildNodes(
325 IXMLDOMProcessingInstruction *iface,
326 VARIANT_BOOL* pbool)
327 {
328 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
329 return IXMLDOMNode_hasChildNodes( This->node, pbool );
330 }
331
332 static HRESULT WINAPI dom_pi_get_ownerDocument(
333 IXMLDOMProcessingInstruction *iface,
334 IXMLDOMDocument** domDocument)
335 {
336 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
337 return IXMLDOMNode_get_ownerDocument( This->node, domDocument );
338 }
339
340 static HRESULT WINAPI dom_pi_cloneNode(
341 IXMLDOMProcessingInstruction *iface,
342 VARIANT_BOOL pbool, IXMLDOMNode** outNode)
343 {
344 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
345 return IXMLDOMNode_cloneNode( This->node, pbool, outNode );
346 }
347
348 static HRESULT WINAPI dom_pi_get_nodeTypeString(
349 IXMLDOMProcessingInstruction *iface,
350 BSTR* p)
351 {
352 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
353 return IXMLDOMNode_get_nodeTypeString( This->node, p );
354 }
355
356 static HRESULT WINAPI dom_pi_get_text(
357 IXMLDOMProcessingInstruction *iface,
358 BSTR* p)
359 {
360 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
361 return IXMLDOMNode_get_text( This->node, p );
362 }
363
364 static HRESULT WINAPI dom_pi_put_text(
365 IXMLDOMProcessingInstruction *iface,
366 BSTR p)
367 {
368 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
369 return IXMLDOMNode_put_text( This->node, p );
370 }
371
372 static HRESULT WINAPI dom_pi_get_specified(
373 IXMLDOMProcessingInstruction *iface,
374 VARIANT_BOOL* pbool)
375 {
376 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
377 return IXMLDOMNode_get_specified( This->node, pbool );
378 }
379
380 static HRESULT WINAPI dom_pi_get_definition(
381 IXMLDOMProcessingInstruction *iface,
382 IXMLDOMNode** domNode)
383 {
384 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
385 return IXMLDOMNode_get_definition( This->node, domNode );
386 }
387
388 static HRESULT WINAPI dom_pi_get_nodeTypedValue(
389 IXMLDOMProcessingInstruction *iface,
390 VARIANT* var1)
391 {
392 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
393 return IXMLDOMNode_get_nodeTypedValue( This->node, var1 );
394 }
395
396 static HRESULT WINAPI dom_pi_put_nodeTypedValue(
397 IXMLDOMProcessingInstruction *iface,
398 VARIANT var1)
399 {
400 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
401 return IXMLDOMNode_put_nodeTypedValue( This->node, var1 );
402 }
403
404 static HRESULT WINAPI dom_pi_get_dataType(
405 IXMLDOMProcessingInstruction *iface,
406 VARIANT* var1)
407 {
408 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
409 return IXMLDOMNode_get_dataType( This->node, var1 );
410 }
411
412 static HRESULT WINAPI dom_pi_put_dataType(
413 IXMLDOMProcessingInstruction *iface,
414 BSTR p)
415 {
416 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
417 return IXMLDOMNode_put_dataType( This->node, p );
418 }
419
420 static HRESULT WINAPI dom_pi_get_xml(
421 IXMLDOMProcessingInstruction *iface,
422 BSTR* p)
423 {
424 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
425 return IXMLDOMNode_get_xml( This->node, p );
426 }
427
428 static HRESULT WINAPI dom_pi_transformNode(
429 IXMLDOMProcessingInstruction *iface,
430 IXMLDOMNode* domNode, BSTR* p)
431 {
432 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
433 return IXMLDOMNode_transformNode( This->node, domNode, p );
434 }
435
436 static HRESULT WINAPI dom_pi_selectNodes(
437 IXMLDOMProcessingInstruction *iface,
438 BSTR p, IXMLDOMNodeList** outList)
439 {
440 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
441 return IXMLDOMNode_selectNodes( This->node, p, outList );
442 }
443
444 static HRESULT WINAPI dom_pi_selectSingleNode(
445 IXMLDOMProcessingInstruction *iface,
446 BSTR p, IXMLDOMNode** outNode)
447 {
448 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
449 return IXMLDOMNode_selectSingleNode( This->node, p, outNode );
450 }
451
452 static HRESULT WINAPI dom_pi_get_parsed(
453 IXMLDOMProcessingInstruction *iface,
454 VARIANT_BOOL* pbool)
455 {
456 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
457 return IXMLDOMNode_get_parsed( This->node, pbool );
458 }
459
460 static HRESULT WINAPI dom_pi_get_namespaceURI(
461 IXMLDOMProcessingInstruction *iface,
462 BSTR* p)
463 {
464 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
465 return IXMLDOMNode_get_namespaceURI( This->node, p );
466 }
467
468 static HRESULT WINAPI dom_pi_get_prefix(
469 IXMLDOMProcessingInstruction *iface,
470 BSTR* p)
471 {
472 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
473 return IXMLDOMNode_get_prefix( This->node, p );
474 }
475
476 static HRESULT WINAPI dom_pi_get_baseName(
477 IXMLDOMProcessingInstruction *iface,
478 BSTR* p)
479 {
480 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
481 return IXMLDOMNode_get_baseName( This->node, p );
482 }
483
484 static HRESULT WINAPI dom_pi_transformNodeToObject(
485 IXMLDOMProcessingInstruction *iface,
486 IXMLDOMNode* domNode, VARIANT var1)
487 {
488 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
489 return IXMLDOMNode_transformNodeToObject( This->node, domNode, var1 );
490 }
491
492 static HRESULT WINAPI dom_pi_get_target(
493 IXMLDOMProcessingInstruction *iface,
494 BSTR *p)
495 {
496 /* target returns the same value as nodeName property */
497 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
498 return IXMLDOMNode_get_nodeName( This->node, p );
499 }
500
501 static HRESULT WINAPI dom_pi_get_data(
502 IXMLDOMProcessingInstruction *iface,
503 BSTR *p)
504 {
505 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
506 HRESULT hr = E_FAIL;
507 VARIANT vRet;
508
509 if(!p)
510 return E_INVALIDARG;
511
512 hr = IXMLDOMNode_get_nodeValue( This->node, &vRet );
513 if(hr == S_OK)
514 {
515 *p = V_BSTR(&vRet);
516 }
517
518 return hr;
519 }
520
521 static HRESULT WINAPI dom_pi_put_data(
522 IXMLDOMProcessingInstruction *iface,
523 BSTR data)
524 {
525 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
526 HRESULT hr = E_FAIL;
527 VARIANT val;
528 BSTR sTarget;
529 static const WCHAR szXML[] = {'x','m','l',0};
530
531 TRACE("%p %s\n", This, debugstr_w(data) );
532
533 /* Cannot set data to a PI node whose target is 'xml' */
534 hr = dom_pi_get_nodeName(iface, &sTarget);
535 if(hr == S_OK)
536 {
537 if(lstrcmpW( sTarget, szXML) == 0)
538 {
539 SysFreeString(sTarget);
540 return E_FAIL;
541 }
542
543 SysFreeString(sTarget);
544 }
545
546 V_VT(&val) = VT_BSTR;
547 V_BSTR(&val) = data;
548
549 hr = IXMLDOMNode_put_nodeValue( This->node, val );
550
551 return hr;
552 }
553
554 static const struct IXMLDOMProcessingInstructionVtbl dom_pi_vtbl =
555 {
556 dom_pi_QueryInterface,
557 dom_pi_AddRef,
558 dom_pi_Release,
559 dom_pi_GetTypeInfoCount,
560 dom_pi_GetTypeInfo,
561 dom_pi_GetIDsOfNames,
562 dom_pi_Invoke,
563 dom_pi_get_nodeName,
564 dom_pi_get_nodeValue,
565 dom_pi_put_nodeValue,
566 dom_pi_get_nodeType,
567 dom_pi_get_parentNode,
568 dom_pi_get_childNodes,
569 dom_pi_get_firstChild,
570 dom_pi_get_lastChild,
571 dom_pi_get_previousSibling,
572 dom_pi_get_nextSibling,
573 dom_pi_get_attributes,
574 dom_pi_insertBefore,
575 dom_pi_replaceChild,
576 dom_pi_removeChild,
577 dom_pi_appendChild,
578 dom_pi_hasChildNodes,
579 dom_pi_get_ownerDocument,
580 dom_pi_cloneNode,
581 dom_pi_get_nodeTypeString,
582 dom_pi_get_text,
583 dom_pi_put_text,
584 dom_pi_get_specified,
585 dom_pi_get_definition,
586 dom_pi_get_nodeTypedValue,
587 dom_pi_put_nodeTypedValue,
588 dom_pi_get_dataType,
589 dom_pi_put_dataType,
590 dom_pi_get_xml,
591 dom_pi_transformNode,
592 dom_pi_selectNodes,
593 dom_pi_selectSingleNode,
594 dom_pi_get_parsed,
595 dom_pi_get_namespaceURI,
596 dom_pi_get_prefix,
597 dom_pi_get_baseName,
598 dom_pi_transformNodeToObject,
599
600 dom_pi_get_target,
601 dom_pi_get_data,
602 dom_pi_put_data
603 };
604
605 IUnknown* create_pi( xmlNodePtr pi )
606 {
607 dom_pi *This;
608 HRESULT hr;
609
610 This = HeapAlloc( GetProcessHeap(), 0, sizeof *This );
611 if ( !This )
612 return NULL;
613
614 This->lpVtbl = &dom_pi_vtbl;
615 This->ref = 1;
616
617 This->node_unk = create_basic_node( pi, (IUnknown*)&This->lpVtbl );
618 if(!This->node_unk)
619 {
620 HeapFree(GetProcessHeap(), 0, This);
621 return NULL;
622 }
623
624 hr = IUnknown_QueryInterface(This->node_unk, &IID_IXMLDOMNode, (LPVOID*)&This->node);
625 if(FAILED(hr))
626 {
627 IUnknown_Release(This->node_unk);
628 HeapFree( GetProcessHeap(), 0, This );
629 return NULL;
630 }
631 /* The ref on This->node is actually looped back into this object, so release it */
632 IXMLDOMNode_Release(This->node);
633
634 return (IUnknown*) &This->lpVtbl;
635 }
636
637 #endif
638
This page was automatically generated by the
LXR engine.
Visit the LXR main site for more
information.