oledb32: Check start for NULL before strstrW (Coverity).
[wine] / dlls / msxml3 / doctype.c
1 /*
2  *    DOM DTD node implementation
3  *
4  * Copyright 2010 Nikolay Sivov
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 #ifdef HAVE_LIBXML2
27 # include <libxml/parser.h>
28 # include <libxml/xmlerror.h>
29 #endif
30
31 #include "windef.h"
32 #include "winbase.h"
33 #include "winuser.h"
34 #include "winnls.h"
35 #include "ole2.h"
36 #include "msxml6.h"
37
38 #include "msxml_private.h"
39
40 #include "wine/debug.h"
41
42 WINE_DEFAULT_DEBUG_CHANNEL(msxml);
43
44 #ifdef HAVE_LIBXML2
45
46 typedef struct _domdoctype
47 {
48     xmlnode node;
49     IXMLDOMDocumentType IXMLDOMDocumentType_iface;
50     LONG ref;
51 } domdoctype;
52
53 static inline domdoctype *impl_from_IXMLDOMDocumentType( IXMLDOMDocumentType *iface )
54 {
55     return CONTAINING_RECORD(iface, domdoctype, IXMLDOMDocumentType_iface);
56 }
57
58 static HRESULT WINAPI domdoctype_QueryInterface(
59     IXMLDOMDocumentType *iface,
60     REFIID riid,
61     void** ppvObject )
62 {
63     domdoctype *This = impl_from_IXMLDOMDocumentType( iface );
64
65     TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppvObject);
66
67     if ( IsEqualGUID( riid, &IID_IXMLDOMDocumentType ) ||
68          IsEqualGUID( riid, &IID_IXMLDOMNode ) ||
69          IsEqualGUID( riid, &IID_IDispatch ) ||
70          IsEqualGUID( riid, &IID_IUnknown ) )
71     {
72         *ppvObject = &This->IXMLDOMDocumentType_iface;
73     }
74     else if(node_query_interface(&This->node, riid, ppvObject))
75     {
76         return *ppvObject ? S_OK : E_NOINTERFACE;
77     }
78     else
79     {
80         TRACE("interface %s not implemented\n", debugstr_guid(riid));
81         *ppvObject = NULL;
82         return E_NOINTERFACE;
83     }
84
85     IUnknown_AddRef( (IUnknown*)*ppvObject );
86     return S_OK;
87 }
88
89 static ULONG WINAPI domdoctype_AddRef(
90     IXMLDOMDocumentType *iface )
91 {
92     domdoctype *This = impl_from_IXMLDOMDocumentType( iface );
93     LONG ref = InterlockedIncrement(&This->ref);
94     TRACE("(%p)->(%d)\n", This, ref);
95     return ref;
96 }
97
98 static ULONG WINAPI domdoctype_Release(
99     IXMLDOMDocumentType *iface )
100 {
101     domdoctype *This = impl_from_IXMLDOMDocumentType( iface );
102     ULONG ref = InterlockedDecrement(&This->ref);
103
104     TRACE("(%p)->(%d)\n", This, ref);
105
106     if(!ref) {
107         destroy_xmlnode(&This->node);
108         heap_free(This);
109     }
110
111     return ref;
112 }
113
114 static HRESULT WINAPI domdoctype_GetTypeInfoCount(
115     IXMLDOMDocumentType *iface,
116     UINT* pctinfo )
117 {
118     domdoctype *This = impl_from_IXMLDOMDocumentType( iface );
119     return IDispatchEx_GetTypeInfoCount(&This->node.dispex.IDispatchEx_iface, pctinfo);
120 }
121
122 static HRESULT WINAPI domdoctype_GetTypeInfo(
123     IXMLDOMDocumentType *iface,
124     UINT iTInfo, LCID lcid,
125     ITypeInfo** ppTInfo )
126 {
127     domdoctype *This = impl_from_IXMLDOMDocumentType( iface );
128     return IDispatchEx_GetTypeInfo(&This->node.dispex.IDispatchEx_iface,
129         iTInfo, lcid, ppTInfo);
130 }
131
132 static HRESULT WINAPI domdoctype_GetIDsOfNames(
133     IXMLDOMDocumentType *iface,
134     REFIID riid, LPOLESTR* rgszNames,
135     UINT cNames, LCID lcid, DISPID* rgDispId )
136 {
137     domdoctype *This = impl_from_IXMLDOMDocumentType( iface );
138     return IDispatchEx_GetIDsOfNames(&This->node.dispex.IDispatchEx_iface,
139         riid, rgszNames, cNames, lcid, rgDispId);
140 }
141
142 static HRESULT WINAPI domdoctype_Invoke(
143     IXMLDOMDocumentType *iface,
144     DISPID dispIdMember, REFIID riid, LCID lcid,
145     WORD wFlags, DISPPARAMS* pDispParams, VARIANT* pVarResult,
146     EXCEPINFO* pExcepInfo, UINT* puArgErr )
147 {
148     domdoctype *This = impl_from_IXMLDOMDocumentType( iface );
149     return IDispatchEx_Invoke(&This->node.dispex.IDispatchEx_iface,
150         dispIdMember, riid, lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
151 }
152
153 static HRESULT WINAPI domdoctype_get_nodeName(
154     IXMLDOMDocumentType *iface,
155     BSTR* p )
156 {
157     domdoctype *This = impl_from_IXMLDOMDocumentType( iface );
158     FIXME("(%p)->(%p): stub\n", This, p);
159     return E_NOTIMPL;
160 }
161
162 static HRESULT WINAPI domdoctype_get_nodeValue(
163     IXMLDOMDocumentType *iface,
164     VARIANT* value)
165 {
166     domdoctype *This = impl_from_IXMLDOMDocumentType( iface );
167     FIXME("(%p)->(%p): stub\n", This, value);
168     return E_NOTIMPL;
169 }
170
171 static HRESULT WINAPI domdoctype_put_nodeValue(
172     IXMLDOMDocumentType *iface,
173     VARIANT value)
174 {
175     domdoctype *This = impl_from_IXMLDOMDocumentType( iface );
176     FIXME("(%p)->(%s): stub\n", This, debugstr_variant(&value));
177     return E_NOTIMPL;
178 }
179
180 static HRESULT WINAPI domdoctype_get_nodeType(
181     IXMLDOMDocumentType *iface,
182     DOMNodeType* domNodeType )
183 {
184     domdoctype *This = impl_from_IXMLDOMDocumentType( iface );
185
186     TRACE("(%p)->(%p)\n", This, domNodeType);
187
188     *domNodeType = NODE_DOCUMENT_TYPE;
189     return S_OK;
190 }
191
192 static HRESULT WINAPI domdoctype_get_parentNode(
193     IXMLDOMDocumentType *iface,
194     IXMLDOMNode** parent )
195 {
196     domdoctype *This = impl_from_IXMLDOMDocumentType( iface );
197     FIXME("(%p)->(%p): stub\n", This, parent);
198     return E_NOTIMPL;
199 }
200
201 static HRESULT WINAPI domdoctype_get_childNodes(
202     IXMLDOMDocumentType *iface,
203     IXMLDOMNodeList** outList)
204 {
205     domdoctype *This = impl_from_IXMLDOMDocumentType( iface );
206     FIXME("(%p)->(%p): stub\n", This, outList);
207     return E_NOTIMPL;
208 }
209
210 static HRESULT WINAPI domdoctype_get_firstChild(
211     IXMLDOMDocumentType *iface,
212     IXMLDOMNode** domNode)
213 {
214     domdoctype *This = impl_from_IXMLDOMDocumentType( iface );
215     FIXME("(%p)->(%p): stub\n", This, domNode);
216     return E_NOTIMPL;
217 }
218
219 static HRESULT WINAPI domdoctype_get_lastChild(
220     IXMLDOMDocumentType *iface,
221     IXMLDOMNode** domNode)
222 {
223     domdoctype *This = impl_from_IXMLDOMDocumentType( iface );
224     FIXME("(%p)->(%p): stub\n", This, domNode);
225     return E_NOTIMPL;
226 }
227
228 static HRESULT WINAPI domdoctype_get_previousSibling(
229     IXMLDOMDocumentType *iface,
230     IXMLDOMNode** domNode)
231 {
232     domdoctype *This = impl_from_IXMLDOMDocumentType( iface );
233     FIXME("(%p)->(%p): stub\n", This, domNode);
234     return E_NOTIMPL;
235 }
236
237 static HRESULT WINAPI domdoctype_get_nextSibling(
238     IXMLDOMDocumentType *iface,
239     IXMLDOMNode** domNode)
240 {
241     domdoctype *This = impl_from_IXMLDOMDocumentType( iface );
242     FIXME("(%p)->(%p): stub\n", This, domNode);
243     return E_NOTIMPL;
244 }
245
246 static HRESULT WINAPI domdoctype_get_attributes(
247     IXMLDOMDocumentType *iface,
248     IXMLDOMNamedNodeMap** attributeMap)
249 {
250     domdoctype *This = impl_from_IXMLDOMDocumentType( iface );
251     FIXME("(%p)->(%p): stub\n", This, attributeMap);
252     return E_NOTIMPL;
253 }
254
255 static HRESULT WINAPI domdoctype_insertBefore(
256     IXMLDOMDocumentType *iface,
257     IXMLDOMNode* newNode, VARIANT refChild,
258     IXMLDOMNode** outOldNode)
259 {
260     domdoctype *This = impl_from_IXMLDOMDocumentType( iface );
261
262     FIXME("(%p)->(%p %s %p): stub\n", This, newNode, debugstr_variant(&refChild), outOldNode);
263
264     return E_NOTIMPL;
265 }
266
267 static HRESULT WINAPI domdoctype_replaceChild(
268     IXMLDOMDocumentType *iface,
269     IXMLDOMNode* newNode,
270     IXMLDOMNode* oldNode,
271     IXMLDOMNode** outOldNode)
272 {
273     domdoctype *This = impl_from_IXMLDOMDocumentType( iface );
274
275     FIXME("(%p)->(%p %p %p): stub\n", This, newNode, oldNode, outOldNode);
276
277     return E_NOTIMPL;
278 }
279
280 static HRESULT WINAPI domdoctype_removeChild(
281     IXMLDOMDocumentType *iface,
282     IXMLDOMNode* domNode, IXMLDOMNode** oldNode)
283 {
284     domdoctype *This = impl_from_IXMLDOMDocumentType( iface );
285     FIXME("(%p)->(%p %p): stub\n", This, domNode, oldNode);
286     return E_NOTIMPL;
287 }
288
289 static HRESULT WINAPI domdoctype_appendChild(
290     IXMLDOMDocumentType *iface,
291     IXMLDOMNode* newNode, IXMLDOMNode** outNewNode)
292 {
293     domdoctype *This = impl_from_IXMLDOMDocumentType( iface );
294     FIXME("(%p)->(%p %p): stub\n", This, newNode, outNewNode);
295     return E_NOTIMPL;
296 }
297
298 static HRESULT WINAPI domdoctype_hasChildNodes(
299     IXMLDOMDocumentType *iface,
300     VARIANT_BOOL* pbool)
301 {
302     domdoctype *This = impl_from_IXMLDOMDocumentType( iface );
303     FIXME("(%p)->(%p): stub\n", This, pbool);
304     return E_NOTIMPL;
305 }
306
307 static HRESULT WINAPI domdoctype_get_ownerDocument(
308     IXMLDOMDocumentType *iface,
309     IXMLDOMDocument** domDocument)
310 {
311     domdoctype *This = impl_from_IXMLDOMDocumentType( iface );
312     FIXME("(%p)->(%p): stub\n", This, domDocument);
313     return E_NOTIMPL;
314 }
315
316 static HRESULT WINAPI domdoctype_cloneNode(
317     IXMLDOMDocumentType *iface,
318     VARIANT_BOOL deep, IXMLDOMNode** outNode)
319 {
320     domdoctype *This = impl_from_IXMLDOMDocumentType( iface );
321     FIXME("(%p)->(%d %p): stub\n", This, deep, outNode);
322     return E_NOTIMPL;
323 }
324
325 static HRESULT WINAPI domdoctype_get_nodeTypeString(
326     IXMLDOMDocumentType *iface,
327     BSTR* p)
328 {
329     domdoctype *This = impl_from_IXMLDOMDocumentType( iface );
330     FIXME("(%p)->(%p): stub\n", This, p);
331     return E_NOTIMPL;
332 }
333
334 static HRESULT WINAPI domdoctype_get_text(
335     IXMLDOMDocumentType *iface,
336     BSTR* p)
337 {
338     domdoctype *This = impl_from_IXMLDOMDocumentType( iface );
339     FIXME("(%p)->(%p): stub\n", This, p);
340     return E_NOTIMPL;
341 }
342
343 static HRESULT WINAPI domdoctype_put_text(
344     IXMLDOMDocumentType *iface,
345     BSTR p)
346 {
347     domdoctype *This = impl_from_IXMLDOMDocumentType( iface );
348     FIXME("(%p)->(%s): stub\n", This, debugstr_w(p));
349     return E_NOTIMPL;
350 }
351
352 static HRESULT WINAPI domdoctype_get_specified(
353     IXMLDOMDocumentType *iface,
354     VARIANT_BOOL* isSpecified)
355 {
356     domdoctype *This = impl_from_IXMLDOMDocumentType( iface );
357     FIXME("(%p)->(%p): stub\n", This, isSpecified);
358     return E_NOTIMPL;
359 }
360
361 static HRESULT WINAPI domdoctype_get_definition(
362     IXMLDOMDocumentType *iface,
363     IXMLDOMNode** definitionNode)
364 {
365     domdoctype *This = impl_from_IXMLDOMDocumentType( iface );
366     FIXME("(%p)->(%p)\n", This, definitionNode);
367     return E_NOTIMPL;
368 }
369
370 static HRESULT WINAPI domdoctype_get_nodeTypedValue(
371     IXMLDOMDocumentType *iface,
372     VARIANT* v)
373 {
374     domdoctype *This = impl_from_IXMLDOMDocumentType( iface );
375     TRACE("(%p)->(%p)\n", This, v);
376     return return_null_var(v);
377 }
378
379 static HRESULT WINAPI domdoctype_put_nodeTypedValue(
380     IXMLDOMDocumentType *iface,
381     VARIANT value)
382 {
383     domdoctype *This = impl_from_IXMLDOMDocumentType( iface );
384     FIXME("(%p)->(%s): stub\n", This, debugstr_variant(&value));
385     return E_NOTIMPL;
386 }
387
388 static HRESULT WINAPI domdoctype_get_dataType(
389     IXMLDOMDocumentType *iface,
390     VARIANT* typename)
391 {
392     domdoctype *This = impl_from_IXMLDOMDocumentType( iface );
393     FIXME("(%p)->(%p): stub\n", This, typename);
394     return E_NOTIMPL;
395 }
396
397 static HRESULT WINAPI domdoctype_put_dataType(
398     IXMLDOMDocumentType *iface,
399     BSTR p)
400 {
401     domdoctype *This = impl_from_IXMLDOMDocumentType( iface );
402     FIXME("(%p)->(%s): stub\n", This, debugstr_w(p));
403     return E_NOTIMPL;
404 }
405
406 static HRESULT WINAPI domdoctype_get_xml(
407     IXMLDOMDocumentType *iface,
408     BSTR* p)
409 {
410     domdoctype *This = impl_from_IXMLDOMDocumentType( iface );
411     FIXME("(%p)->(%p): stub\n", This, p);
412     return E_NOTIMPL;
413 }
414
415 static HRESULT WINAPI domdoctype_transformNode(
416     IXMLDOMDocumentType *iface,
417     IXMLDOMNode* domNode, BSTR* p)
418 {
419     domdoctype *This = impl_from_IXMLDOMDocumentType( iface );
420     FIXME("(%p)->(%p %p): stub\n", This, domNode, p);
421     return E_NOTIMPL;
422 }
423
424 static HRESULT WINAPI domdoctype_selectNodes(
425     IXMLDOMDocumentType *iface,
426     BSTR p, IXMLDOMNodeList** outList)
427 {
428     domdoctype *This = impl_from_IXMLDOMDocumentType( iface );
429     FIXME("(%p)->(%s %p): stub\n", This, debugstr_w(p), outList);
430     return E_NOTIMPL;
431 }
432
433 static HRESULT WINAPI domdoctype_selectSingleNode(
434     IXMLDOMDocumentType *iface,
435     BSTR p, IXMLDOMNode** outNode)
436 {
437     domdoctype *This = impl_from_IXMLDOMDocumentType( iface );
438     FIXME("(%p)->(%s %p): stub\n", This, debugstr_w(p), outNode);
439     return E_NOTIMPL;
440 }
441
442 static HRESULT WINAPI domdoctype_get_parsed(
443     IXMLDOMDocumentType *iface,
444     VARIANT_BOOL* isParsed)
445 {
446     domdoctype *This = impl_from_IXMLDOMDocumentType( iface );
447     FIXME("(%p)->(%p): stub\n", This, isParsed);
448     return E_NOTIMPL;
449 }
450
451 static HRESULT WINAPI domdoctype_get_namespaceURI(
452     IXMLDOMDocumentType *iface,
453     BSTR* p)
454 {
455     domdoctype *This = impl_from_IXMLDOMDocumentType( iface );
456     FIXME("(%p)->(%p): stub\n", This, p);
457     return E_NOTIMPL;
458 }
459
460 static HRESULT WINAPI domdoctype_get_prefix(
461     IXMLDOMDocumentType *iface,
462     BSTR* prefix)
463 {
464     domdoctype *This = impl_from_IXMLDOMDocumentType( iface );
465     FIXME("(%p)->(%p): stub\n", This, prefix);
466     return E_NOTIMPL;
467 }
468
469 static HRESULT WINAPI domdoctype_get_baseName(
470     IXMLDOMDocumentType *iface,
471     BSTR* name)
472 {
473     domdoctype *This = impl_from_IXMLDOMDocumentType( iface );
474     FIXME("(%p)->(%p): stub\n", This, name);
475     return E_NOTIMPL;
476 }
477
478 static HRESULT WINAPI domdoctype_transformNodeToObject(
479     IXMLDOMDocumentType *iface,
480     IXMLDOMNode* domNode, VARIANT var1)
481 {
482     domdoctype *This = impl_from_IXMLDOMDocumentType( iface );
483     FIXME("(%p)->(%p %s): stub\n", This, domNode, debugstr_variant(&var1));
484     return E_NOTIMPL;
485 }
486
487 static HRESULT WINAPI domdoctype_get_name(
488     IXMLDOMDocumentType *iface,
489     BSTR *p)
490 {
491     domdoctype *This = impl_from_IXMLDOMDocumentType( iface );
492     FIXME("(%p)->(%p): stub\n", This, p);
493     return E_NOTIMPL;
494 }
495
496 static HRESULT WINAPI domdoctype_get_entities(
497     IXMLDOMDocumentType *iface,
498     IXMLDOMNamedNodeMap **entityMap)
499 {
500     domdoctype *This = impl_from_IXMLDOMDocumentType( iface );
501     FIXME("(%p)->(%p): stub\n", This, entityMap);
502     return E_NOTIMPL;
503 }
504
505 static HRESULT WINAPI domdoctype_get_notations(
506     IXMLDOMDocumentType *iface,
507     IXMLDOMNamedNodeMap **notationMap)
508 {
509     domdoctype *This = impl_from_IXMLDOMDocumentType( iface );
510     FIXME("(%p)->(%p): stub\n", This, notationMap);
511     return E_NOTIMPL;
512 }
513
514 static const struct IXMLDOMDocumentTypeVtbl domdoctype_vtbl =
515 {
516     domdoctype_QueryInterface,
517     domdoctype_AddRef,
518     domdoctype_Release,
519     domdoctype_GetTypeInfoCount,
520     domdoctype_GetTypeInfo,
521     domdoctype_GetIDsOfNames,
522     domdoctype_Invoke,
523     domdoctype_get_nodeName,
524     domdoctype_get_nodeValue,
525     domdoctype_put_nodeValue,
526     domdoctype_get_nodeType,
527     domdoctype_get_parentNode,
528     domdoctype_get_childNodes,
529     domdoctype_get_firstChild,
530     domdoctype_get_lastChild,
531     domdoctype_get_previousSibling,
532     domdoctype_get_nextSibling,
533     domdoctype_get_attributes,
534     domdoctype_insertBefore,
535     domdoctype_replaceChild,
536     domdoctype_removeChild,
537     domdoctype_appendChild,
538     domdoctype_hasChildNodes,
539     domdoctype_get_ownerDocument,
540     domdoctype_cloneNode,
541     domdoctype_get_nodeTypeString,
542     domdoctype_get_text,
543     domdoctype_put_text,
544     domdoctype_get_specified,
545     domdoctype_get_definition,
546     domdoctype_get_nodeTypedValue,
547     domdoctype_put_nodeTypedValue,
548     domdoctype_get_dataType,
549     domdoctype_put_dataType,
550     domdoctype_get_xml,
551     domdoctype_transformNode,
552     domdoctype_selectNodes,
553     domdoctype_selectSingleNode,
554     domdoctype_get_parsed,
555     domdoctype_get_namespaceURI,
556     domdoctype_get_prefix,
557     domdoctype_get_baseName,
558     domdoctype_transformNodeToObject,
559     domdoctype_get_name,
560     domdoctype_get_entities,
561     domdoctype_get_notations
562 };
563
564 static const tid_t domdoctype_iface_tids[] = {
565     IXMLDOMDocumentType_tid,
566     0
567 };
568
569 static dispex_static_data_t domdoctype_dispex = {
570     NULL,
571     IXMLDOMDocumentType_tid,
572     NULL,
573     domdoctype_iface_tids
574 };
575
576 IUnknown* create_doc_type( xmlNodePtr doctype )
577 {
578     domdoctype *This;
579
580     This = heap_alloc( sizeof *This );
581     if ( !This )
582         return NULL;
583
584     This->IXMLDOMDocumentType_iface.lpVtbl = &domdoctype_vtbl;
585     This->ref = 1;
586
587     init_xmlnode(&This->node, doctype, (IXMLDOMNode*)&This->IXMLDOMDocumentType_iface,
588             &domdoctype_dispex);
589
590     return (IUnknown*)&This->IXMLDOMDocumentType_iface;
591 }
592
593 #endif