msi/tests: Make tests run on win9x/NT4 again.
[wine] / dlls / msxml3 / pi.c
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     return IXMLDOMNode_put_nodeValue( This->node, var1 );
204 }
205
206 static HRESULT WINAPI dom_pi_get_nodeType(
207     IXMLDOMProcessingInstruction *iface,
208     DOMNodeType* domNodeType )
209 {
210     dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
211     return IXMLDOMNode_get_nodeType( This->node, domNodeType );
212 }
213
214 static HRESULT WINAPI dom_pi_get_parentNode(
215     IXMLDOMProcessingInstruction *iface,
216     IXMLDOMNode** parent )
217 {
218     dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
219     return IXMLDOMNode_get_parentNode( This->node, parent );
220 }
221
222 static HRESULT WINAPI dom_pi_get_childNodes(
223     IXMLDOMProcessingInstruction *iface,
224     IXMLDOMNodeList** outList)
225 {
226     dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
227     return IXMLDOMNode_get_childNodes( This->node, outList );
228 }
229
230 static HRESULT WINAPI dom_pi_get_firstChild(
231     IXMLDOMProcessingInstruction *iface,
232     IXMLDOMNode** domNode)
233 {
234     dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
235     return IXMLDOMNode_get_firstChild( This->node, domNode );
236 }
237
238 static HRESULT WINAPI dom_pi_get_lastChild(
239     IXMLDOMProcessingInstruction *iface,
240     IXMLDOMNode** domNode)
241 {
242     dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
243     return IXMLDOMNode_get_lastChild( This->node, domNode );
244 }
245
246 static HRESULT WINAPI dom_pi_get_previousSibling(
247     IXMLDOMProcessingInstruction *iface,
248     IXMLDOMNode** domNode)
249 {
250     dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
251     return IXMLDOMNode_get_previousSibling( This->node, domNode );
252 }
253
254 static HRESULT WINAPI dom_pi_get_nextSibling(
255     IXMLDOMProcessingInstruction *iface,
256     IXMLDOMNode** domNode)
257 {
258     dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
259     return IXMLDOMNode_get_nextSibling( This->node, domNode );
260 }
261
262 static HRESULT WINAPI dom_pi_get_attributes(
263     IXMLDOMProcessingInstruction *iface,
264     IXMLDOMNamedNodeMap** attributeMap)
265 {
266     dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
267     return IXMLDOMNode_get_attributes( This->node, attributeMap );
268 }
269
270 static HRESULT WINAPI dom_pi_insertBefore(
271     IXMLDOMProcessingInstruction *iface,
272     IXMLDOMNode* newNode, VARIANT var1,
273     IXMLDOMNode** outOldNode)
274 {
275     dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
276     return IXMLDOMNode_insertBefore( This->node, newNode, var1, outOldNode );
277 }
278
279 static HRESULT WINAPI dom_pi_replaceChild(
280     IXMLDOMProcessingInstruction *iface,
281     IXMLDOMNode* newNode,
282     IXMLDOMNode* oldNode,
283     IXMLDOMNode** outOldNode)
284 {
285     dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
286     return IXMLDOMNode_replaceChild( This->node, newNode, oldNode, outOldNode );
287 }
288
289 static HRESULT WINAPI dom_pi_removeChild(
290     IXMLDOMProcessingInstruction *iface,
291     IXMLDOMNode* domNode, IXMLDOMNode** oldNode)
292 {
293     dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
294     return IXMLDOMNode_removeChild( This->node, domNode, oldNode );
295 }
296
297 static HRESULT WINAPI dom_pi_appendChild(
298     IXMLDOMProcessingInstruction *iface,
299     IXMLDOMNode* newNode, IXMLDOMNode** outNewNode)
300 {
301     dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
302     return IXMLDOMNode_appendChild( This->node, newNode, outNewNode );
303 }
304
305 static HRESULT WINAPI dom_pi_hasChildNodes(
306     IXMLDOMProcessingInstruction *iface,
307     VARIANT_BOOL* pbool)
308 {
309     dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
310     return IXMLDOMNode_hasChildNodes( This->node, pbool );
311 }
312
313 static HRESULT WINAPI dom_pi_get_ownerDocument(
314     IXMLDOMProcessingInstruction *iface,
315     IXMLDOMDocument** domDocument)
316 {
317     dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
318     return IXMLDOMNode_get_ownerDocument( This->node, domDocument );
319 }
320
321 static HRESULT WINAPI dom_pi_cloneNode(
322     IXMLDOMProcessingInstruction *iface,
323     VARIANT_BOOL pbool, IXMLDOMNode** outNode)
324 {
325     dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
326     return IXMLDOMNode_cloneNode( This->node, pbool, outNode );
327 }
328
329 static HRESULT WINAPI dom_pi_get_nodeTypeString(
330     IXMLDOMProcessingInstruction *iface,
331     BSTR* p)
332 {
333     dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
334     return IXMLDOMNode_get_nodeTypeString( This->node, p );
335 }
336
337 static HRESULT WINAPI dom_pi_get_text(
338     IXMLDOMProcessingInstruction *iface,
339     BSTR* p)
340 {
341     dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
342     return IXMLDOMNode_get_text( This->node, p );
343 }
344
345 static HRESULT WINAPI dom_pi_put_text(
346     IXMLDOMProcessingInstruction *iface,
347     BSTR p)
348 {
349     dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
350     return IXMLDOMNode_put_text( This->node, p );
351 }
352
353 static HRESULT WINAPI dom_pi_get_specified(
354     IXMLDOMProcessingInstruction *iface,
355     VARIANT_BOOL* pbool)
356 {
357     dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
358     return IXMLDOMNode_get_specified( This->node, pbool );
359 }
360
361 static HRESULT WINAPI dom_pi_get_definition(
362     IXMLDOMProcessingInstruction *iface,
363     IXMLDOMNode** domNode)
364 {
365     dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
366     return IXMLDOMNode_get_definition( This->node, domNode );
367 }
368
369 static HRESULT WINAPI dom_pi_get_nodeTypedValue(
370     IXMLDOMProcessingInstruction *iface,
371     VARIANT* var1)
372 {
373     dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
374     return IXMLDOMNode_get_nodeTypedValue( This->node, var1 );
375 }
376
377 static HRESULT WINAPI dom_pi_put_nodeTypedValue(
378     IXMLDOMProcessingInstruction *iface,
379     VARIANT var1)
380 {
381     dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
382     return IXMLDOMNode_put_nodeTypedValue( This->node, var1 );
383 }
384
385 static HRESULT WINAPI dom_pi_get_dataType(
386     IXMLDOMProcessingInstruction *iface,
387     VARIANT* var1)
388 {
389     dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
390     return IXMLDOMNode_get_dataType( This->node, var1 );
391 }
392
393 static HRESULT WINAPI dom_pi_put_dataType(
394     IXMLDOMProcessingInstruction *iface,
395     BSTR p)
396 {
397     dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
398     return IXMLDOMNode_put_dataType( This->node, p );
399 }
400
401 static HRESULT WINAPI dom_pi_get_xml(
402     IXMLDOMProcessingInstruction *iface,
403     BSTR* p)
404 {
405     dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
406     return IXMLDOMNode_get_xml( This->node, p );
407 }
408
409 static HRESULT WINAPI dom_pi_transformNode(
410     IXMLDOMProcessingInstruction *iface,
411     IXMLDOMNode* domNode, BSTR* p)
412 {
413     dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
414     return IXMLDOMNode_transformNode( This->node, domNode, p );
415 }
416
417 static HRESULT WINAPI dom_pi_selectNodes(
418     IXMLDOMProcessingInstruction *iface,
419     BSTR p, IXMLDOMNodeList** outList)
420 {
421     dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
422     return IXMLDOMNode_selectNodes( This->node, p, outList );
423 }
424
425 static HRESULT WINAPI dom_pi_selectSingleNode(
426     IXMLDOMProcessingInstruction *iface,
427     BSTR p, IXMLDOMNode** outNode)
428 {
429     dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
430     return IXMLDOMNode_selectSingleNode( This->node, p, outNode );
431 }
432
433 static HRESULT WINAPI dom_pi_get_parsed(
434     IXMLDOMProcessingInstruction *iface,
435     VARIANT_BOOL* pbool)
436 {
437     dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
438     return IXMLDOMNode_get_parsed( This->node, pbool );
439 }
440
441 static HRESULT WINAPI dom_pi_get_namespaceURI(
442     IXMLDOMProcessingInstruction *iface,
443     BSTR* p)
444 {
445     dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
446     return IXMLDOMNode_get_namespaceURI( This->node, p );
447 }
448
449 static HRESULT WINAPI dom_pi_get_prefix(
450     IXMLDOMProcessingInstruction *iface,
451     BSTR* p)
452 {
453     dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
454     return IXMLDOMNode_get_prefix( This->node, p );
455 }
456
457 static HRESULT WINAPI dom_pi_get_baseName(
458     IXMLDOMProcessingInstruction *iface,
459     BSTR* p)
460 {
461     dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
462     return IXMLDOMNode_get_baseName( This->node, p );
463 }
464
465 static HRESULT WINAPI dom_pi_transformNodeToObject(
466     IXMLDOMProcessingInstruction *iface,
467     IXMLDOMNode* domNode, VARIANT var1)
468 {
469     dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
470     return IXMLDOMNode_transformNodeToObject( This->node, domNode, var1 );
471 }
472
473 static HRESULT WINAPI dom_pi_get_target(
474     IXMLDOMProcessingInstruction *iface,
475     BSTR *p)
476 {
477     /* target returns the same value as nodeName property */
478     dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
479     return IXMLDOMNode_get_nodeName( This->node, p );
480 }
481
482 static HRESULT WINAPI dom_pi_get_data(
483     IXMLDOMProcessingInstruction *iface,
484     BSTR *p)
485 {
486     dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
487     HRESULT hr = E_FAIL;
488     VARIANT vRet;
489
490     if(!p)
491         return E_INVALIDARG;
492
493     hr = IXMLDOMNode_get_nodeValue( This->node, &vRet );
494     if(hr == S_OK)
495     {
496         *p = V_BSTR(&vRet);
497     }
498
499     return hr;
500 }
501
502 static HRESULT WINAPI dom_pi_put_data(
503     IXMLDOMProcessingInstruction *iface,
504     BSTR data)
505 {
506     dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
507     HRESULT hr = E_FAIL;
508     VARIANT val;
509     BSTR sTarget;
510     static WCHAR szXML[] = {'x','m','l',0};
511
512     TRACE("%p %s\n", This, debugstr_w(data) );
513
514     /* Cannot set data to a PI node whos target is 'xml' */
515     hr = dom_pi_get_nodeName(iface, &sTarget);
516     if(hr == S_OK)
517     {
518         if(lstrcmpW( sTarget, szXML) == 0)
519         {
520             SysFreeString(sTarget);
521             return E_FAIL;
522         }
523
524         SysFreeString(sTarget);
525     }
526
527     V_VT(&val) = VT_BSTR;
528     V_BSTR(&val) = data;
529
530     hr = IXMLDOMNode_put_nodeValue( This->node, val );
531
532     return hr;
533 }
534
535 static const struct IXMLDOMProcessingInstructionVtbl dom_pi_vtbl =
536 {
537     dom_pi_QueryInterface,
538     dom_pi_AddRef,
539     dom_pi_Release,
540     dom_pi_GetTypeInfoCount,
541     dom_pi_GetTypeInfo,
542     dom_pi_GetIDsOfNames,
543     dom_pi_Invoke,
544     dom_pi_get_nodeName,
545     dom_pi_get_nodeValue,
546     dom_pi_put_nodeValue,
547     dom_pi_get_nodeType,
548     dom_pi_get_parentNode,
549     dom_pi_get_childNodes,
550     dom_pi_get_firstChild,
551     dom_pi_get_lastChild,
552     dom_pi_get_previousSibling,
553     dom_pi_get_nextSibling,
554     dom_pi_get_attributes,
555     dom_pi_insertBefore,
556     dom_pi_replaceChild,
557     dom_pi_removeChild,
558     dom_pi_appendChild,
559     dom_pi_hasChildNodes,
560     dom_pi_get_ownerDocument,
561     dom_pi_cloneNode,
562     dom_pi_get_nodeTypeString,
563     dom_pi_get_text,
564     dom_pi_put_text,
565     dom_pi_get_specified,
566     dom_pi_get_definition,
567     dom_pi_get_nodeTypedValue,
568     dom_pi_put_nodeTypedValue,
569     dom_pi_get_dataType,
570     dom_pi_put_dataType,
571     dom_pi_get_xml,
572     dom_pi_transformNode,
573     dom_pi_selectNodes,
574     dom_pi_selectSingleNode,
575     dom_pi_get_parsed,
576     dom_pi_get_namespaceURI,
577     dom_pi_get_prefix,
578     dom_pi_get_baseName,
579     dom_pi_transformNodeToObject,
580
581     dom_pi_get_target,
582     dom_pi_get_data,
583     dom_pi_put_data
584 };
585
586 IUnknown* create_pi( xmlNodePtr pi )
587 {
588     dom_pi *This;
589     HRESULT hr;
590
591     This = HeapAlloc( GetProcessHeap(), 0, sizeof *This );
592     if ( !This )
593         return NULL;
594
595     This->lpVtbl = &dom_pi_vtbl;
596     This->ref = 1;
597
598     This->node_unk = create_basic_node( pi, (IUnknown*)&This->lpVtbl );
599     if(!This->node_unk)
600     {
601         HeapFree(GetProcessHeap(), 0, This);
602         return NULL;
603     }
604
605     hr = IUnknown_QueryInterface(This->node_unk, &IID_IXMLDOMNode, (LPVOID*)&This->node);
606     if(FAILED(hr))
607     {
608         IUnknown_Release(This->node_unk);
609         HeapFree( GetProcessHeap(), 0, This );
610         return NULL;
611     }
612     /* The ref on This->node is actually looped back into this object, so release it */
613     IXMLDOMNode_Release(This->node);
614
615     return (IUnknown*) &This->lpVtbl;
616 }
617
618 #endif