wineoss.drv: Avoid a potential NULL pointer dereference in a TRACE.
[wine/hacks.git] / dlls / msxml3 / pi.c
blob0baefe49031e7281f36adba719a59d59826cda9c
1 /*
2 * DOM processing instruction node implementation
4 * Copyright 2006 Huw Davies
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #define COBJMACROS
23 #include "config.h"
25 #include <stdarg.h>
26 #include "windef.h"
27 #include "winbase.h"
28 #include "winuser.h"
29 #include "ole2.h"
30 #include "msxml2.h"
32 #include "msxml_private.h"
34 #include "wine/debug.h"
36 WINE_DEFAULT_DEBUG_CHANNEL(msxml);
38 #ifdef HAVE_LIBXML2
40 typedef struct _dom_pi
42 xmlnode node;
43 const struct IXMLDOMProcessingInstructionVtbl *lpVtbl;
44 LONG ref;
45 } dom_pi;
47 static inline dom_pi *impl_from_IXMLDOMProcessingInstruction( IXMLDOMProcessingInstruction *iface )
49 return (dom_pi *)((char*)iface - FIELD_OFFSET(dom_pi, lpVtbl));
52 static HRESULT WINAPI dom_pi_QueryInterface(
53 IXMLDOMProcessingInstruction *iface,
54 REFIID riid,
55 void** ppvObject )
57 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
58 TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppvObject);
60 if ( IsEqualGUID( riid, &IID_IXMLDOMProcessingInstruction ) ||
61 IsEqualGUID( riid, &IID_IDispatch ) ||
62 IsEqualGUID( riid, &IID_IUnknown ) )
64 *ppvObject = iface;
66 else if ( IsEqualGUID( riid, &IID_IXMLDOMNode ) )
68 *ppvObject = IXMLDOMNode_from_impl(&This->node);
70 else
72 FIXME("Unsupported interface %s\n", debugstr_guid(riid));
73 return E_NOINTERFACE;
76 IUnknown_AddRef((IUnknown*)*ppvObject);
77 return S_OK;
80 static ULONG WINAPI dom_pi_AddRef(
81 IXMLDOMProcessingInstruction *iface )
83 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
84 return InterlockedIncrement( &This->ref );
87 static ULONG WINAPI dom_pi_Release(
88 IXMLDOMProcessingInstruction *iface )
90 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
91 ULONG ref;
93 ref = InterlockedDecrement( &This->ref );
94 if ( ref == 0 )
96 destroy_xmlnode(&This->node);
97 heap_free( This );
100 return ref;
103 static HRESULT WINAPI dom_pi_GetTypeInfoCount(
104 IXMLDOMProcessingInstruction *iface,
105 UINT* pctinfo )
107 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
109 TRACE("(%p)->(%p)\n", This, pctinfo);
111 *pctinfo = 1;
113 return S_OK;
116 static HRESULT WINAPI dom_pi_GetTypeInfo(
117 IXMLDOMProcessingInstruction *iface,
118 UINT iTInfo, LCID lcid,
119 ITypeInfo** ppTInfo )
121 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
122 HRESULT hr;
124 TRACE("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo);
126 hr = get_typeinfo(IXMLDOMProcessingInstruction_tid, ppTInfo);
128 return hr;
131 static HRESULT WINAPI dom_pi_GetIDsOfNames(
132 IXMLDOMProcessingInstruction *iface,
133 REFIID riid, LPOLESTR* rgszNames,
134 UINT cNames, LCID lcid, DISPID* rgDispId )
136 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
137 ITypeInfo *typeinfo;
138 HRESULT hr;
140 TRACE("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames, cNames,
141 lcid, rgDispId);
143 if(!rgszNames || cNames == 0 || !rgDispId)
144 return E_INVALIDARG;
146 hr = get_typeinfo(IXMLDOMProcessingInstruction_tid, &typeinfo);
147 if(SUCCEEDED(hr))
149 hr = ITypeInfo_GetIDsOfNames(typeinfo, rgszNames, cNames, rgDispId);
150 ITypeInfo_Release(typeinfo);
153 return hr;
156 static HRESULT WINAPI dom_pi_Invoke(
157 IXMLDOMProcessingInstruction *iface,
158 DISPID dispIdMember, REFIID riid, LCID lcid,
159 WORD wFlags, DISPPARAMS* pDispParams, VARIANT* pVarResult,
160 EXCEPINFO* pExcepInfo, UINT* puArgErr )
162 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
163 ITypeInfo *typeinfo;
164 HRESULT hr;
166 TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
167 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
169 hr = get_typeinfo(IXMLDOMProcessingInstruction_tid, &typeinfo);
170 if(SUCCEEDED(hr))
172 hr = ITypeInfo_Invoke(typeinfo, &(This->lpVtbl), dispIdMember, wFlags, pDispParams,
173 pVarResult, pExcepInfo, puArgErr);
174 ITypeInfo_Release(typeinfo);
177 return hr;
180 static HRESULT WINAPI dom_pi_get_nodeName(
181 IXMLDOMProcessingInstruction *iface,
182 BSTR* p )
184 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
185 return IXMLDOMNode_get_nodeName( IXMLDOMNode_from_impl(&This->node), p );
188 static HRESULT WINAPI dom_pi_get_nodeValue(
189 IXMLDOMProcessingInstruction *iface,
190 VARIANT* var1 )
192 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
193 return IXMLDOMNode_get_nodeValue( IXMLDOMNode_from_impl(&This->node), var1 );
196 static HRESULT WINAPI dom_pi_put_nodeValue(
197 IXMLDOMProcessingInstruction *iface,
198 VARIANT var1 )
200 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
201 BSTR sTarget;
202 static const WCHAR szXML[] = {'x','m','l',0};
203 HRESULT hr;
205 TRACE("%p\n", This );
207 /* Cannot set data to a PI node whose target is 'xml' */
208 hr = dom_pi_get_nodeName(iface, &sTarget);
209 if(hr == S_OK)
211 if(lstrcmpW( sTarget, szXML) == 0)
213 SysFreeString(sTarget);
214 return E_FAIL;
217 SysFreeString(sTarget);
220 return IXMLDOMNode_put_nodeValue( IXMLDOMNode_from_impl(&This->node), var1 );
223 static HRESULT WINAPI dom_pi_get_nodeType(
224 IXMLDOMProcessingInstruction *iface,
225 DOMNodeType* domNodeType )
227 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
228 return IXMLDOMNode_get_nodeType( IXMLDOMNode_from_impl(&This->node), domNodeType );
231 static HRESULT WINAPI dom_pi_get_parentNode(
232 IXMLDOMProcessingInstruction *iface,
233 IXMLDOMNode** parent )
235 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
236 return IXMLDOMNode_get_parentNode( IXMLDOMNode_from_impl(&This->node), parent );
239 static HRESULT WINAPI dom_pi_get_childNodes(
240 IXMLDOMProcessingInstruction *iface,
241 IXMLDOMNodeList** outList)
243 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
244 return IXMLDOMNode_get_childNodes( IXMLDOMNode_from_impl(&This->node), outList );
247 static HRESULT WINAPI dom_pi_get_firstChild(
248 IXMLDOMProcessingInstruction *iface,
249 IXMLDOMNode** domNode)
251 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
252 return IXMLDOMNode_get_firstChild( IXMLDOMNode_from_impl(&This->node), domNode );
255 static HRESULT WINAPI dom_pi_get_lastChild(
256 IXMLDOMProcessingInstruction *iface,
257 IXMLDOMNode** domNode)
259 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
260 return IXMLDOMNode_get_lastChild( IXMLDOMNode_from_impl(&This->node), domNode );
263 static HRESULT WINAPI dom_pi_get_previousSibling(
264 IXMLDOMProcessingInstruction *iface,
265 IXMLDOMNode** domNode)
267 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
268 return IXMLDOMNode_get_previousSibling( IXMLDOMNode_from_impl(&This->node), domNode );
271 static HRESULT WINAPI dom_pi_get_nextSibling(
272 IXMLDOMProcessingInstruction *iface,
273 IXMLDOMNode** domNode)
275 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
276 return IXMLDOMNode_get_nextSibling( IXMLDOMNode_from_impl(&This->node), domNode );
279 static HRESULT WINAPI dom_pi_get_attributes(
280 IXMLDOMProcessingInstruction *iface,
281 IXMLDOMNamedNodeMap** attributeMap)
283 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
284 return IXMLDOMNode_get_attributes( IXMLDOMNode_from_impl(&This->node), attributeMap );
287 static HRESULT WINAPI dom_pi_insertBefore(
288 IXMLDOMProcessingInstruction *iface,
289 IXMLDOMNode* newNode, VARIANT var1,
290 IXMLDOMNode** outOldNode)
292 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
293 return IXMLDOMNode_insertBefore( IXMLDOMNode_from_impl(&This->node), newNode, var1, outOldNode );
296 static HRESULT WINAPI dom_pi_replaceChild(
297 IXMLDOMProcessingInstruction *iface,
298 IXMLDOMNode* newNode,
299 IXMLDOMNode* oldNode,
300 IXMLDOMNode** outOldNode)
302 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
303 return IXMLDOMNode_replaceChild( IXMLDOMNode_from_impl(&This->node), newNode, oldNode, outOldNode );
306 static HRESULT WINAPI dom_pi_removeChild(
307 IXMLDOMProcessingInstruction *iface,
308 IXMLDOMNode* domNode, IXMLDOMNode** oldNode)
310 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
311 return IXMLDOMNode_removeChild( IXMLDOMNode_from_impl(&This->node), domNode, oldNode );
314 static HRESULT WINAPI dom_pi_appendChild(
315 IXMLDOMProcessingInstruction *iface,
316 IXMLDOMNode* newNode, IXMLDOMNode** outNewNode)
318 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
319 return IXMLDOMNode_appendChild( IXMLDOMNode_from_impl(&This->node), newNode, outNewNode );
322 static HRESULT WINAPI dom_pi_hasChildNodes(
323 IXMLDOMProcessingInstruction *iface,
324 VARIANT_BOOL* pbool)
326 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
327 return IXMLDOMNode_hasChildNodes( IXMLDOMNode_from_impl(&This->node), pbool );
330 static HRESULT WINAPI dom_pi_get_ownerDocument(
331 IXMLDOMProcessingInstruction *iface,
332 IXMLDOMDocument** domDocument)
334 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
335 return IXMLDOMNode_get_ownerDocument( IXMLDOMNode_from_impl(&This->node), domDocument );
338 static HRESULT WINAPI dom_pi_cloneNode(
339 IXMLDOMProcessingInstruction *iface,
340 VARIANT_BOOL pbool, IXMLDOMNode** outNode)
342 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
343 return IXMLDOMNode_cloneNode( IXMLDOMNode_from_impl(&This->node), pbool, outNode );
346 static HRESULT WINAPI dom_pi_get_nodeTypeString(
347 IXMLDOMProcessingInstruction *iface,
348 BSTR* p)
350 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
351 return IXMLDOMNode_get_nodeTypeString( IXMLDOMNode_from_impl(&This->node), p );
354 static HRESULT WINAPI dom_pi_get_text(
355 IXMLDOMProcessingInstruction *iface,
356 BSTR* p)
358 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
359 return IXMLDOMNode_get_text( IXMLDOMNode_from_impl(&This->node), p );
362 static HRESULT WINAPI dom_pi_put_text(
363 IXMLDOMProcessingInstruction *iface,
364 BSTR p)
366 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
367 return IXMLDOMNode_put_text( IXMLDOMNode_from_impl(&This->node), p );
370 static HRESULT WINAPI dom_pi_get_specified(
371 IXMLDOMProcessingInstruction *iface,
372 VARIANT_BOOL* pbool)
374 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
375 return IXMLDOMNode_get_specified( IXMLDOMNode_from_impl(&This->node), pbool );
378 static HRESULT WINAPI dom_pi_get_definition(
379 IXMLDOMProcessingInstruction *iface,
380 IXMLDOMNode** domNode)
382 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
383 return IXMLDOMNode_get_definition( IXMLDOMNode_from_impl(&This->node), domNode );
386 static HRESULT WINAPI dom_pi_get_nodeTypedValue(
387 IXMLDOMProcessingInstruction *iface,
388 VARIANT* var1)
390 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
391 return IXMLDOMNode_get_nodeTypedValue( IXMLDOMNode_from_impl(&This->node), var1 );
394 static HRESULT WINAPI dom_pi_put_nodeTypedValue(
395 IXMLDOMProcessingInstruction *iface,
396 VARIANT var1)
398 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
399 return IXMLDOMNode_put_nodeTypedValue( IXMLDOMNode_from_impl(&This->node), var1 );
402 static HRESULT WINAPI dom_pi_get_dataType(
403 IXMLDOMProcessingInstruction *iface,
404 VARIANT* var1)
406 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
407 return IXMLDOMNode_get_dataType( IXMLDOMNode_from_impl(&This->node), var1 );
410 static HRESULT WINAPI dom_pi_put_dataType(
411 IXMLDOMProcessingInstruction *iface,
412 BSTR p)
414 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
415 return IXMLDOMNode_put_dataType( IXMLDOMNode_from_impl(&This->node), p );
418 static HRESULT WINAPI dom_pi_get_xml(
419 IXMLDOMProcessingInstruction *iface,
420 BSTR* p)
422 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
423 return IXMLDOMNode_get_xml( IXMLDOMNode_from_impl(&This->node), p );
426 static HRESULT WINAPI dom_pi_transformNode(
427 IXMLDOMProcessingInstruction *iface,
428 IXMLDOMNode* domNode, BSTR* p)
430 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
431 return IXMLDOMNode_transformNode( IXMLDOMNode_from_impl(&This->node), domNode, p );
434 static HRESULT WINAPI dom_pi_selectNodes(
435 IXMLDOMProcessingInstruction *iface,
436 BSTR p, IXMLDOMNodeList** outList)
438 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
439 return IXMLDOMNode_selectNodes( IXMLDOMNode_from_impl(&This->node), p, outList );
442 static HRESULT WINAPI dom_pi_selectSingleNode(
443 IXMLDOMProcessingInstruction *iface,
444 BSTR p, IXMLDOMNode** outNode)
446 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
447 return IXMLDOMNode_selectSingleNode( IXMLDOMNode_from_impl(&This->node), p, outNode );
450 static HRESULT WINAPI dom_pi_get_parsed(
451 IXMLDOMProcessingInstruction *iface,
452 VARIANT_BOOL* pbool)
454 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
455 return IXMLDOMNode_get_parsed( IXMLDOMNode_from_impl(&This->node), pbool );
458 static HRESULT WINAPI dom_pi_get_namespaceURI(
459 IXMLDOMProcessingInstruction *iface,
460 BSTR* p)
462 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
463 return IXMLDOMNode_get_namespaceURI( IXMLDOMNode_from_impl(&This->node), p );
466 static HRESULT WINAPI dom_pi_get_prefix(
467 IXMLDOMProcessingInstruction *iface,
468 BSTR* p)
470 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
471 return IXMLDOMNode_get_prefix( IXMLDOMNode_from_impl(&This->node), p );
474 static HRESULT WINAPI dom_pi_get_baseName(
475 IXMLDOMProcessingInstruction *iface,
476 BSTR* p)
478 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
479 return IXMLDOMNode_get_baseName( IXMLDOMNode_from_impl(&This->node), p );
482 static HRESULT WINAPI dom_pi_transformNodeToObject(
483 IXMLDOMProcessingInstruction *iface,
484 IXMLDOMNode* domNode, VARIANT var1)
486 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
487 return IXMLDOMNode_transformNodeToObject( IXMLDOMNode_from_impl(&This->node), domNode, var1 );
490 static HRESULT WINAPI dom_pi_get_target(
491 IXMLDOMProcessingInstruction *iface,
492 BSTR *p)
494 /* target returns the same value as nodeName property */
495 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
496 return IXMLDOMNode_get_nodeName( IXMLDOMNode_from_impl(&This->node), p );
499 static HRESULT WINAPI dom_pi_get_data(
500 IXMLDOMProcessingInstruction *iface,
501 BSTR *p)
503 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
504 HRESULT hr = E_FAIL;
505 VARIANT vRet;
507 if(!p)
508 return E_INVALIDARG;
510 hr = IXMLDOMNode_get_nodeValue( IXMLDOMNode_from_impl(&This->node), &vRet );
511 if(hr == S_OK)
513 *p = V_BSTR(&vRet);
516 return hr;
519 static HRESULT WINAPI dom_pi_put_data(
520 IXMLDOMProcessingInstruction *iface,
521 BSTR data)
523 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
524 HRESULT hr = E_FAIL;
525 VARIANT val;
526 BSTR sTarget;
527 static const WCHAR szXML[] = {'x','m','l',0};
529 TRACE("(%p)->(%s)\n", This, debugstr_w(data) );
531 /* Cannot set data to a PI node whose target is 'xml' */
532 hr = dom_pi_get_nodeName(iface, &sTarget);
533 if(hr == S_OK)
535 if(lstrcmpW( sTarget, szXML) == 0)
537 SysFreeString(sTarget);
538 return E_FAIL;
541 SysFreeString(sTarget);
544 V_VT(&val) = VT_BSTR;
545 V_BSTR(&val) = data;
547 hr = IXMLDOMNode_put_nodeValue( IXMLDOMNode_from_impl(&This->node), val );
549 return hr;
552 static const struct IXMLDOMProcessingInstructionVtbl dom_pi_vtbl =
554 dom_pi_QueryInterface,
555 dom_pi_AddRef,
556 dom_pi_Release,
557 dom_pi_GetTypeInfoCount,
558 dom_pi_GetTypeInfo,
559 dom_pi_GetIDsOfNames,
560 dom_pi_Invoke,
561 dom_pi_get_nodeName,
562 dom_pi_get_nodeValue,
563 dom_pi_put_nodeValue,
564 dom_pi_get_nodeType,
565 dom_pi_get_parentNode,
566 dom_pi_get_childNodes,
567 dom_pi_get_firstChild,
568 dom_pi_get_lastChild,
569 dom_pi_get_previousSibling,
570 dom_pi_get_nextSibling,
571 dom_pi_get_attributes,
572 dom_pi_insertBefore,
573 dom_pi_replaceChild,
574 dom_pi_removeChild,
575 dom_pi_appendChild,
576 dom_pi_hasChildNodes,
577 dom_pi_get_ownerDocument,
578 dom_pi_cloneNode,
579 dom_pi_get_nodeTypeString,
580 dom_pi_get_text,
581 dom_pi_put_text,
582 dom_pi_get_specified,
583 dom_pi_get_definition,
584 dom_pi_get_nodeTypedValue,
585 dom_pi_put_nodeTypedValue,
586 dom_pi_get_dataType,
587 dom_pi_put_dataType,
588 dom_pi_get_xml,
589 dom_pi_transformNode,
590 dom_pi_selectNodes,
591 dom_pi_selectSingleNode,
592 dom_pi_get_parsed,
593 dom_pi_get_namespaceURI,
594 dom_pi_get_prefix,
595 dom_pi_get_baseName,
596 dom_pi_transformNodeToObject,
598 dom_pi_get_target,
599 dom_pi_get_data,
600 dom_pi_put_data
603 IUnknown* create_pi( xmlNodePtr pi )
605 dom_pi *This;
607 This = heap_alloc( sizeof *This );
608 if ( !This )
609 return NULL;
611 This->lpVtbl = &dom_pi_vtbl;
612 This->ref = 1;
614 init_xmlnode(&This->node, pi, (IUnknown*)&This->lpVtbl, NULL);
616 return (IUnknown*) &This->lpVtbl;
619 #endif