schannel: Use FIELD_OFFSET instead of offsetof.
[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_IUnknown ) )
63     {
64         *ppvObject = iface;
65     }
66     else if ( IsEqualGUID( riid, &IID_IDispatch ) ||
67               IsEqualGUID( riid, &IID_IXMLDOMNode ) )
68     {
69         return IUnknown_QueryInterface(This->node_unk, riid, ppvObject);
70     }
71     else
72     {
73         FIXME("Unsupported inteferace %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     FIXME("\n");
110     return E_NOTIMPL;
111 }
112
113 static HRESULT WINAPI dom_pi_GetTypeInfo(
114     IXMLDOMProcessingInstruction *iface,
115     UINT iTInfo, LCID lcid,
116     ITypeInfo** ppTInfo )
117 {
118     FIXME("\n");
119     return E_NOTIMPL;
120 }
121
122 static HRESULT WINAPI dom_pi_GetIDsOfNames(
123     IXMLDOMProcessingInstruction *iface,
124     REFIID riid, LPOLESTR* rgszNames,
125     UINT cNames, LCID lcid, DISPID* rgDispId )
126 {
127     FIXME("\n");
128     return E_NOTIMPL;
129 }
130
131 static HRESULT WINAPI dom_pi_Invoke(
132     IXMLDOMProcessingInstruction *iface,
133     DISPID dispIdMember, REFIID riid, LCID lcid,
134     WORD wFlags, DISPPARAMS* pDispParams, VARIANT* pVarResult,
135     EXCEPINFO* pExcepInfo, UINT* puArgErr )
136 {
137     FIXME("\n");
138     return E_NOTIMPL;
139 }
140
141 static HRESULT WINAPI dom_pi_get_nodeName(
142     IXMLDOMProcessingInstruction *iface,
143     BSTR* p )
144 {
145     dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
146     return IXMLDOMNode_get_nodeName( This->node, p );
147 }
148
149 static HRESULT WINAPI dom_pi_get_nodeValue(
150     IXMLDOMProcessingInstruction *iface,
151     VARIANT* var1 )
152 {
153     dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
154     return IXMLDOMNode_get_nodeValue( This->node, var1 );
155 }
156
157 static HRESULT WINAPI dom_pi_put_nodeValue(
158     IXMLDOMProcessingInstruction *iface,
159     VARIANT var1 )
160 {
161     dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
162     return IXMLDOMNode_put_nodeValue( This->node, var1 );
163 }
164
165 static HRESULT WINAPI dom_pi_get_nodeType(
166     IXMLDOMProcessingInstruction *iface,
167     DOMNodeType* domNodeType )
168 {
169     dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
170     return IXMLDOMNode_get_nodeType( This->node, domNodeType );
171 }
172
173 static HRESULT WINAPI dom_pi_get_parentNode(
174     IXMLDOMProcessingInstruction *iface,
175     IXMLDOMNode** parent )
176 {
177     dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
178     return IXMLDOMNode_get_parentNode( This->node, parent );
179 }
180
181 static HRESULT WINAPI dom_pi_get_childNodes(
182     IXMLDOMProcessingInstruction *iface,
183     IXMLDOMNodeList** outList)
184 {
185     dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
186     return IXMLDOMNode_get_childNodes( This->node, outList );
187 }
188
189 static HRESULT WINAPI dom_pi_get_firstChild(
190     IXMLDOMProcessingInstruction *iface,
191     IXMLDOMNode** domNode)
192 {
193     dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
194     return IXMLDOMNode_get_firstChild( This->node, domNode );
195 }
196
197 static HRESULT WINAPI dom_pi_get_lastChild(
198     IXMLDOMProcessingInstruction *iface,
199     IXMLDOMNode** domNode)
200 {
201     dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
202     return IXMLDOMNode_get_lastChild( This->node, domNode );
203 }
204
205 static HRESULT WINAPI dom_pi_get_previousSibling(
206     IXMLDOMProcessingInstruction *iface,
207     IXMLDOMNode** domNode)
208 {
209     dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
210     return IXMLDOMNode_get_previousSibling( This->node, domNode );
211 }
212
213 static HRESULT WINAPI dom_pi_get_nextSibling(
214     IXMLDOMProcessingInstruction *iface,
215     IXMLDOMNode** domNode)
216 {
217     dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
218     return IXMLDOMNode_get_nextSibling( This->node, domNode );
219 }
220
221 static HRESULT WINAPI dom_pi_get_attributes(
222     IXMLDOMProcessingInstruction *iface,
223     IXMLDOMNamedNodeMap** attributeMap)
224 {
225     dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
226     return IXMLDOMNode_get_attributes( This->node, attributeMap );
227 }
228
229 static HRESULT WINAPI dom_pi_insertBefore(
230     IXMLDOMProcessingInstruction *iface,
231     IXMLDOMNode* newNode, VARIANT var1,
232     IXMLDOMNode** outOldNode)
233 {
234     dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
235     return IXMLDOMNode_insertBefore( This->node, newNode, var1, outOldNode );
236 }
237
238 static HRESULT WINAPI dom_pi_replaceChild(
239     IXMLDOMProcessingInstruction *iface,
240     IXMLDOMNode* newNode,
241     IXMLDOMNode* oldNode,
242     IXMLDOMNode** outOldNode)
243 {
244     dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
245     return IXMLDOMNode_replaceChild( This->node, newNode, oldNode, outOldNode );
246 }
247
248 static HRESULT WINAPI dom_pi_removeChild(
249     IXMLDOMProcessingInstruction *iface,
250     IXMLDOMNode* domNode, IXMLDOMNode** oldNode)
251 {
252     dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
253     return IXMLDOMNode_removeChild( This->node, domNode, oldNode );
254 }
255
256 static HRESULT WINAPI dom_pi_appendChild(
257     IXMLDOMProcessingInstruction *iface,
258     IXMLDOMNode* newNode, IXMLDOMNode** outNewNode)
259 {
260     dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
261     return IXMLDOMNode_appendChild( This->node, newNode, outNewNode );
262 }
263
264 static HRESULT WINAPI dom_pi_hasChildNodes(
265     IXMLDOMProcessingInstruction *iface,
266     VARIANT_BOOL* pbool)
267 {
268     dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
269     return IXMLDOMNode_hasChildNodes( This->node, pbool );
270 }
271
272 static HRESULT WINAPI dom_pi_get_ownerDocument(
273     IXMLDOMProcessingInstruction *iface,
274     IXMLDOMDocument** domDocument)
275 {
276     dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
277     return IXMLDOMNode_get_ownerDocument( This->node, domDocument );
278 }
279
280 static HRESULT WINAPI dom_pi_cloneNode(
281     IXMLDOMProcessingInstruction *iface,
282     VARIANT_BOOL pbool, IXMLDOMNode** outNode)
283 {
284     dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
285     return IXMLDOMNode_cloneNode( This->node, pbool, outNode );
286 }
287
288 static HRESULT WINAPI dom_pi_get_nodeTypeString(
289     IXMLDOMProcessingInstruction *iface,
290     BSTR* p)
291 {
292     dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
293     return IXMLDOMNode_get_nodeTypeString( This->node, p );
294 }
295
296 static HRESULT WINAPI dom_pi_get_text(
297     IXMLDOMProcessingInstruction *iface,
298     BSTR* p)
299 {
300     dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
301     return IXMLDOMNode_get_text( This->node, p );
302 }
303
304 static HRESULT WINAPI dom_pi_put_text(
305     IXMLDOMProcessingInstruction *iface,
306     BSTR p)
307 {
308     dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
309     return IXMLDOMNode_put_text( This->node, p );
310 }
311
312 static HRESULT WINAPI dom_pi_get_specified(
313     IXMLDOMProcessingInstruction *iface,
314     VARIANT_BOOL* pbool)
315 {
316     dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
317     return IXMLDOMNode_get_specified( This->node, pbool );
318 }
319
320 static HRESULT WINAPI dom_pi_get_definition(
321     IXMLDOMProcessingInstruction *iface,
322     IXMLDOMNode** domNode)
323 {
324     dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
325     return IXMLDOMNode_get_definition( This->node, domNode );
326 }
327
328 static HRESULT WINAPI dom_pi_get_nodeTypedValue(
329     IXMLDOMProcessingInstruction *iface,
330     VARIANT* var1)
331 {
332     dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
333     return IXMLDOMNode_get_nodeTypedValue( This->node, var1 );
334 }
335
336 static HRESULT WINAPI dom_pi_put_nodeTypedValue(
337     IXMLDOMProcessingInstruction *iface,
338     VARIANT var1)
339 {
340     dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
341     return IXMLDOMNode_put_nodeTypedValue( This->node, var1 );
342 }
343
344 static HRESULT WINAPI dom_pi_get_dataType(
345     IXMLDOMProcessingInstruction *iface,
346     VARIANT* var1)
347 {
348     dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
349     return IXMLDOMNode_get_dataType( This->node, var1 );
350 }
351
352 static HRESULT WINAPI dom_pi_put_dataType(
353     IXMLDOMProcessingInstruction *iface,
354     BSTR p)
355 {
356     dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
357     return IXMLDOMNode_put_dataType( This->node, p );
358 }
359
360 static HRESULT WINAPI dom_pi_get_xml(
361     IXMLDOMProcessingInstruction *iface,
362     BSTR* p)
363 {
364     dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
365     return IXMLDOMNode_get_xml( This->node, p );
366 }
367
368 static HRESULT WINAPI dom_pi_transformNode(
369     IXMLDOMProcessingInstruction *iface,
370     IXMLDOMNode* domNode, BSTR* p)
371 {
372     dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
373     return IXMLDOMNode_transformNode( This->node, domNode, p );
374 }
375
376 static HRESULT WINAPI dom_pi_selectNodes(
377     IXMLDOMProcessingInstruction *iface,
378     BSTR p, IXMLDOMNodeList** outList)
379 {
380     dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
381     return IXMLDOMNode_selectNodes( This->node, p, outList );
382 }
383
384 static HRESULT WINAPI dom_pi_selectSingleNode(
385     IXMLDOMProcessingInstruction *iface,
386     BSTR p, IXMLDOMNode** outNode)
387 {
388     dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
389     return IXMLDOMNode_selectSingleNode( This->node, p, outNode );
390 }
391
392 static HRESULT WINAPI dom_pi_get_parsed(
393     IXMLDOMProcessingInstruction *iface,
394     VARIANT_BOOL* pbool)
395 {
396     dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
397     return IXMLDOMNode_get_parsed( This->node, pbool );
398 }
399
400 static HRESULT WINAPI dom_pi_get_namespaceURI(
401     IXMLDOMProcessingInstruction *iface,
402     BSTR* p)
403 {
404     dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
405     return IXMLDOMNode_get_namespaceURI( This->node, p );
406 }
407
408 static HRESULT WINAPI dom_pi_get_prefix(
409     IXMLDOMProcessingInstruction *iface,
410     BSTR* p)
411 {
412     dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
413     return IXMLDOMNode_get_prefix( This->node, p );
414 }
415
416 static HRESULT WINAPI dom_pi_get_baseName(
417     IXMLDOMProcessingInstruction *iface,
418     BSTR* p)
419 {
420     dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
421     return IXMLDOMNode_get_baseName( This->node, p );
422 }
423
424 static HRESULT WINAPI dom_pi_transformNodeToObject(
425     IXMLDOMProcessingInstruction *iface,
426     IXMLDOMNode* domNode, VARIANT var1)
427 {
428     dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
429     return IXMLDOMNode_transformNodeToObject( This->node, domNode, var1 );
430 }
431
432 static HRESULT WINAPI dom_pi_get_target(
433     IXMLDOMProcessingInstruction *iface,
434     BSTR *p)
435 {
436     FIXME("\n");
437     return E_NOTIMPL;
438 }
439
440 static HRESULT WINAPI dom_pi_get_data(
441     IXMLDOMProcessingInstruction *iface,
442     BSTR *p)
443 {
444     FIXME("\n");
445     return E_NOTIMPL;
446 }
447
448 static HRESULT WINAPI dom_pi_put_data(
449     IXMLDOMProcessingInstruction *iface,
450     BSTR data)
451 {
452     FIXME("\n");
453     return E_NOTIMPL;
454 }
455
456 static const struct IXMLDOMProcessingInstructionVtbl dom_pi_vtbl =
457 {
458     dom_pi_QueryInterface,
459     dom_pi_AddRef,
460     dom_pi_Release,
461     dom_pi_GetTypeInfoCount,
462     dom_pi_GetTypeInfo,
463     dom_pi_GetIDsOfNames,
464     dom_pi_Invoke,
465     dom_pi_get_nodeName,
466     dom_pi_get_nodeValue,
467     dom_pi_put_nodeValue,
468     dom_pi_get_nodeType,
469     dom_pi_get_parentNode,
470     dom_pi_get_childNodes,
471     dom_pi_get_firstChild,
472     dom_pi_get_lastChild,
473     dom_pi_get_previousSibling,
474     dom_pi_get_nextSibling,
475     dom_pi_get_attributes,
476     dom_pi_insertBefore,
477     dom_pi_replaceChild,
478     dom_pi_removeChild,
479     dom_pi_appendChild,
480     dom_pi_hasChildNodes,
481     dom_pi_get_ownerDocument,
482     dom_pi_cloneNode,
483     dom_pi_get_nodeTypeString,
484     dom_pi_get_text,
485     dom_pi_put_text,
486     dom_pi_get_specified,
487     dom_pi_get_definition,
488     dom_pi_get_nodeTypedValue,
489     dom_pi_put_nodeTypedValue,
490     dom_pi_get_dataType,
491     dom_pi_put_dataType,
492     dom_pi_get_xml,
493     dom_pi_transformNode,
494     dom_pi_selectNodes,
495     dom_pi_selectSingleNode,
496     dom_pi_get_parsed,
497     dom_pi_get_namespaceURI,
498     dom_pi_get_prefix,
499     dom_pi_get_baseName,
500     dom_pi_transformNodeToObject,
501
502     dom_pi_get_target,
503     dom_pi_get_data,
504     dom_pi_put_data
505 };
506
507 IUnknown* create_pi( xmlNodePtr pi )
508 {
509     dom_pi *This;
510     HRESULT hr;
511
512     This = HeapAlloc( GetProcessHeap(), 0, sizeof *This );
513     if ( !This )
514         return NULL;
515
516     This->lpVtbl = &dom_pi_vtbl;
517     This->ref = 1;
518
519     This->node_unk = create_basic_node( pi, (IUnknown*)&This->lpVtbl );
520     if(!This->node_unk)
521     {
522         HeapFree(GetProcessHeap(), 0, This);
523         return NULL;
524     }
525
526     hr = IUnknown_QueryInterface(This->node_unk, &IID_IXMLDOMNode, (LPVOID*)&This->node);
527     if(FAILED(hr))
528     {
529         IUnknown_Release(This->node_unk);
530         HeapFree( GetProcessHeap(), 0, This );
531         return NULL;
532     }
533     /* The ref on This->node is actually looped back into this object, so release it */
534     IXMLDOMNode_Release(This->node);
535
536     return (IUnknown*) &This->lpVtbl;
537 }
538
539 #endif