d3dcompiler: Add argument check in D3DReflect().
[wine] / dlls / msxml3 / stylesheet.c
1 /*
2  *    XSLTemplate/XSLProcessor support
3  *
4  * Copyright 2011 Nikolay Sivov for CodeWeavers
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 "msxml6.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 _xsltemplate
41 {
42     IXSLTemplate IXSLTemplate_iface;
43     LONG ref;
44
45     IXMLDOMNode *node;
46 } xsltemplate;
47
48 typedef struct _xslprocessor
49 {
50     IXSLProcessor IXSLProcessor_iface;
51     LONG ref;
52 } xslprocessor;
53
54 static HRESULT XSLProcessor_create(IXSLProcessor**);
55
56 static inline xsltemplate *impl_from_IXSLTemplate( IXSLTemplate *iface )
57 {
58     return CONTAINING_RECORD(iface, xsltemplate, IXSLTemplate_iface);
59 }
60
61 static inline xslprocessor *impl_from_IXSLProcessor( IXSLProcessor *iface )
62 {
63     return CONTAINING_RECORD(iface, xslprocessor, IXSLProcessor_iface);
64 }
65
66 static void xsltemplate_set_node( xsltemplate *This, IXMLDOMNode *node )
67 {
68     if (This->node) IXMLDOMNode_Release(This->node);
69     This->node = node;
70     if (node) IXMLDOMNode_AddRef(node);
71 }
72
73 static HRESULT WINAPI xsltemplate_QueryInterface(
74     IXSLTemplate *iface,
75     REFIID riid,
76     void** ppvObject )
77 {
78     xsltemplate *This = impl_from_IXSLTemplate( iface );
79     TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppvObject);
80
81     if ( IsEqualGUID( riid, &IID_IXSLTemplate ) ||
82          IsEqualGUID( riid, &IID_IDispatch ) ||
83          IsEqualGUID( riid, &IID_IUnknown ) )
84     {
85         *ppvObject = iface;
86     }
87     else
88     {
89         FIXME("Unsupported interface %s\n", debugstr_guid(riid));
90         return E_NOINTERFACE;
91     }
92
93     IUnknown_AddRef((IUnknown*)*ppvObject);
94     return S_OK;
95 }
96
97 static ULONG WINAPI xsltemplate_AddRef( IXSLTemplate *iface )
98 {
99     xsltemplate *This = impl_from_IXSLTemplate( iface );
100     return InterlockedIncrement( &This->ref );
101 }
102
103 static ULONG WINAPI xsltemplate_Release( IXSLTemplate *iface )
104 {
105     xsltemplate *This = impl_from_IXSLTemplate( iface );
106     ULONG ref;
107
108     ref = InterlockedDecrement( &This->ref );
109     if ( ref == 0 )
110     {
111         if (This->node) IXMLDOMNode_Release( This->node );
112         heap_free( This );
113     }
114
115     return ref;
116 }
117
118 static HRESULT WINAPI xsltemplate_GetTypeInfoCount( IXSLTemplate *iface, UINT* pctinfo )
119 {
120     xsltemplate *This = impl_from_IXSLTemplate( iface );
121
122     TRACE("(%p)->(%p)\n", This, pctinfo);
123
124     *pctinfo = 1;
125     return S_OK;
126 }
127
128 static HRESULT WINAPI xsltemplate_GetTypeInfo(
129     IXSLTemplate *iface,
130     UINT iTInfo, LCID lcid,
131     ITypeInfo** ppTInfo )
132 {
133     xsltemplate *This = impl_from_IXSLTemplate( iface );
134
135     TRACE("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo);
136
137     return get_typeinfo(IXSLTemplate_tid, ppTInfo);
138 }
139
140 static HRESULT WINAPI xsltemplate_GetIDsOfNames(
141     IXSLTemplate *iface,
142     REFIID riid, LPOLESTR* rgszNames,
143     UINT cNames, LCID lcid, DISPID* rgDispId )
144 {
145     xsltemplate *This = impl_from_IXSLTemplate( iface );
146     ITypeInfo *typeinfo;
147     HRESULT hr;
148
149     TRACE("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames, cNames,
150           lcid, rgDispId);
151
152     if(!rgszNames || cNames == 0 || !rgDispId)
153         return E_INVALIDARG;
154
155     hr = get_typeinfo(IXSLTemplate_tid, &typeinfo);
156     if(SUCCEEDED(hr))
157     {
158         hr = ITypeInfo_GetIDsOfNames(typeinfo, rgszNames, cNames, rgDispId);
159         ITypeInfo_Release(typeinfo);
160     }
161
162     return hr;
163 }
164
165 static HRESULT WINAPI xsltemplate_Invoke(
166     IXSLTemplate *iface,
167     DISPID dispIdMember, REFIID riid, LCID lcid,
168     WORD wFlags, DISPPARAMS* pDispParams, VARIANT* pVarResult,
169     EXCEPINFO* pExcepInfo, UINT* puArgErr )
170 {
171     xsltemplate *This = impl_from_IXSLTemplate( iface );
172     ITypeInfo *typeinfo;
173     HRESULT hr;
174
175     TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
176           lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
177
178     hr = get_typeinfo(IXSLTemplate_tid, &typeinfo);
179     if(SUCCEEDED(hr))
180     {
181        hr = ITypeInfo_Invoke(typeinfo, &This->IXSLTemplate_iface, dispIdMember,
182                 wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
183         ITypeInfo_Release(typeinfo);
184     }
185
186     return hr;
187 }
188
189 static HRESULT WINAPI xsltemplate_putref_stylesheet( IXSLTemplate *iface,
190     IXMLDOMNode *node)
191 {
192     xsltemplate *This = impl_from_IXSLTemplate( iface );
193
194     TRACE("(%p)->(%p)\n", This, node);
195
196     if (!node)
197     {
198         xsltemplate_set_node(This, NULL);
199         return S_OK;
200     }
201
202     /* FIXME: test for document type */
203     xsltemplate_set_node(This, node);
204
205     return S_OK;
206 }
207
208 static HRESULT WINAPI xsltemplate_get_stylesheet( IXSLTemplate *iface,
209     IXMLDOMNode **node)
210 {
211     xsltemplate *This = impl_from_IXSLTemplate( iface );
212
213     FIXME("(%p)->(%p): stub\n", This, node);
214     return E_NOTIMPL;
215 }
216
217 static HRESULT WINAPI xsltemplate_createProcessor( IXSLTemplate *iface,
218     IXSLProcessor **processor)
219 {
220     xsltemplate *This = impl_from_IXSLTemplate( iface );
221
222     TRACE("(%p)->(%p)\n", This, processor);
223
224     if (!processor) return E_INVALIDARG;
225
226     return XSLProcessor_create(processor);
227 }
228
229 static const struct IXSLTemplateVtbl xsltemplate_vtbl =
230 {
231     xsltemplate_QueryInterface,
232     xsltemplate_AddRef,
233     xsltemplate_Release,
234     xsltemplate_GetTypeInfoCount,
235     xsltemplate_GetTypeInfo,
236     xsltemplate_GetIDsOfNames,
237     xsltemplate_Invoke,
238
239     xsltemplate_putref_stylesheet,
240     xsltemplate_get_stylesheet,
241     xsltemplate_createProcessor
242 };
243
244 HRESULT XSLTemplate_create(IUnknown *pUnkOuter, void **ppObj)
245 {
246     xsltemplate *This;
247
248     TRACE("(%p,%p)\n", pUnkOuter, ppObj);
249
250     if(pUnkOuter) FIXME("support aggregation, outer\n");
251
252     This = heap_alloc( sizeof (*This) );
253     if(!This)
254         return E_OUTOFMEMORY;
255
256     This->IXSLTemplate_iface.lpVtbl = &xsltemplate_vtbl;
257     This->ref = 1;
258     This->node = NULL;
259
260     *ppObj = &This->IXSLTemplate_iface;
261
262     TRACE("returning iface %p\n", *ppObj);
263
264     return S_OK;
265 }
266
267 /*** IXSLProcessor ***/
268 static HRESULT WINAPI xslprocessor_QueryInterface(
269     IXSLProcessor *iface,
270     REFIID riid,
271     void** ppvObject )
272 {
273     xslprocessor *This = impl_from_IXSLProcessor( iface );
274     TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppvObject);
275
276     if ( IsEqualGUID( riid, &IID_IXSLProcessor ) ||
277          IsEqualGUID( riid, &IID_IDispatch ) ||
278          IsEqualGUID( riid, &IID_IUnknown ) )
279     {
280         *ppvObject = iface;
281     }
282     else
283     {
284         FIXME("Unsupported interface %s\n", debugstr_guid(riid));
285         return E_NOINTERFACE;
286     }
287
288     IUnknown_AddRef((IUnknown*)*ppvObject);
289     return S_OK;
290 }
291
292 static ULONG WINAPI xslprocessor_AddRef( IXSLProcessor *iface )
293 {
294     xslprocessor *This = impl_from_IXSLProcessor( iface );
295     return InterlockedIncrement( &This->ref );
296 }
297
298 static ULONG WINAPI xslprocessor_Release( IXSLProcessor *iface )
299 {
300     xslprocessor *This = impl_from_IXSLProcessor( iface );
301     ULONG ref;
302
303     ref = InterlockedDecrement( &This->ref );
304     if ( ref == 0 )
305         heap_free( This );
306
307     return ref;
308 }
309
310 static HRESULT WINAPI xslprocessor_GetTypeInfoCount( IXSLProcessor *iface, UINT* pctinfo )
311 {
312     xslprocessor *This = impl_from_IXSLProcessor( iface );
313
314     TRACE("(%p)->(%p)\n", This, pctinfo);
315
316     *pctinfo = 1;
317     return S_OK;
318 }
319
320 static HRESULT WINAPI xslprocessor_GetTypeInfo(
321     IXSLProcessor *iface,
322     UINT iTInfo, LCID lcid,
323     ITypeInfo** ppTInfo )
324 {
325     xslprocessor *This = impl_from_IXSLProcessor( iface );
326
327     TRACE("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo);
328
329     return get_typeinfo(IXSLProcessor_tid, ppTInfo);
330 }
331
332 static HRESULT WINAPI xslprocessor_GetIDsOfNames(
333     IXSLProcessor *iface,
334     REFIID riid, LPOLESTR* rgszNames,
335     UINT cNames, LCID lcid, DISPID* rgDispId )
336 {
337     xslprocessor *This = impl_from_IXSLProcessor( iface );
338     ITypeInfo *typeinfo;
339     HRESULT hr;
340
341     TRACE("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames, cNames,
342           lcid, rgDispId);
343
344     if(!rgszNames || cNames == 0 || !rgDispId)
345         return E_INVALIDARG;
346
347     hr = get_typeinfo(IXSLProcessor_tid, &typeinfo);
348     if(SUCCEEDED(hr))
349     {
350         hr = ITypeInfo_GetIDsOfNames(typeinfo, rgszNames, cNames, rgDispId);
351         ITypeInfo_Release(typeinfo);
352     }
353
354     return hr;
355 }
356
357 static HRESULT WINAPI xslprocessor_Invoke(
358     IXSLProcessor *iface,
359     DISPID dispIdMember, REFIID riid, LCID lcid,
360     WORD wFlags, DISPPARAMS* pDispParams, VARIANT* pVarResult,
361     EXCEPINFO* pExcepInfo, UINT* puArgErr )
362 {
363     xslprocessor *This = impl_from_IXSLProcessor( iface );
364     ITypeInfo *typeinfo;
365     HRESULT hr;
366
367     TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
368           lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
369
370     hr = get_typeinfo(IXSLProcessor_tid, &typeinfo);
371     if(SUCCEEDED(hr))
372     {
373        hr = ITypeInfo_Invoke(typeinfo, &This->IXSLProcessor_iface, dispIdMember,
374                 wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
375         ITypeInfo_Release(typeinfo);
376     }
377
378     return hr;
379 }
380
381 static HRESULT WINAPI xslprocessor_put_input( IXSLProcessor *iface, VARIANT input )
382 {
383     xslprocessor *This = impl_from_IXSLProcessor( iface );
384
385     FIXME("(%p): stub\n", This);
386     return E_NOTIMPL;
387 }
388
389 static HRESULT WINAPI xslprocessor_get_input( IXSLProcessor *iface, VARIANT *input )
390 {
391     xslprocessor *This = impl_from_IXSLProcessor( iface );
392
393     FIXME("(%p)->(%p): stub\n", This, input);
394     return E_NOTIMPL;
395 }
396
397 static HRESULT WINAPI xslprocessor_get_ownerTemplate(
398     IXSLProcessor *iface,
399     IXSLTemplate **template)
400 {
401     xslprocessor *This = impl_from_IXSLProcessor( iface );
402
403     FIXME("(%p)->(%p): stub\n", This, template);
404     return E_NOTIMPL;
405 }
406
407 static HRESULT WINAPI xslprocessor_setStartMode(
408     IXSLProcessor *iface,
409     BSTR p,
410     BSTR uri)
411 {
412     xslprocessor *This = impl_from_IXSLProcessor( iface );
413
414     FIXME("(%p)->(%s %s): stub\n", This, wine_dbgstr_w(p), wine_dbgstr_w(uri));
415     return E_NOTIMPL;
416 }
417
418 static HRESULT WINAPI xslprocessor_get_startMode(
419     IXSLProcessor *iface,
420     BSTR *p)
421 {
422     xslprocessor *This = impl_from_IXSLProcessor( iface );
423
424     FIXME("(%p)->(%p): stub\n", This, p);
425     return E_NOTIMPL;
426 }
427
428 static HRESULT WINAPI xslprocessor_get_startModeURI(
429     IXSLProcessor *iface,
430     BSTR *uri)
431 {
432     xslprocessor *This = impl_from_IXSLProcessor( iface );
433
434     FIXME("(%p)->(%p): stub\n", This, uri);
435     return E_NOTIMPL;
436 }
437
438 static HRESULT WINAPI xslprocessor_put_output(
439     IXSLProcessor *iface,
440     VARIANT output)
441 {
442     xslprocessor *This = impl_from_IXSLProcessor( iface );
443
444     FIXME("(%p): stub\n", This);
445     return E_NOTIMPL;
446 }
447
448 static HRESULT WINAPI xslprocessor_get_output(
449     IXSLProcessor *iface,
450     VARIANT *output)
451 {
452     xslprocessor *This = impl_from_IXSLProcessor( iface );
453
454     FIXME("(%p)->(%p): stub\n", This, output);
455     return E_NOTIMPL;
456 }
457
458 static HRESULT WINAPI xslprocessor_transform(
459     IXSLProcessor *iface,
460     VARIANT_BOOL  *pbool)
461 {
462     xslprocessor *This = impl_from_IXSLProcessor( iface );
463
464     FIXME("(%p)->(%p): stub\n", This, pbool);
465     return E_NOTIMPL;
466 }
467
468 static HRESULT WINAPI xslprocessor_reset( IXSLProcessor *iface )
469 {
470     xslprocessor *This = impl_from_IXSLProcessor( iface );
471
472     FIXME("(%p): stub\n", This);
473     return E_NOTIMPL;
474 }
475
476 static HRESULT WINAPI xslprocessor_get_readyState(
477     IXSLProcessor *iface,
478     LONG *state)
479 {
480     xslprocessor *This = impl_from_IXSLProcessor( iface );
481
482     FIXME("(%p)->(%p): stub\n", This, state);
483     return E_NOTIMPL;
484 }
485
486 static HRESULT WINAPI xslprocessor_addParameter(
487     IXSLProcessor *iface,
488     BSTR p,
489     VARIANT var,
490     BSTR uri)
491 {
492     xslprocessor *This = impl_from_IXSLProcessor( iface );
493
494     FIXME("(%p)->(%s %s): stub\n", This, wine_dbgstr_w(p), wine_dbgstr_w(uri));
495     return E_NOTIMPL;
496 }
497
498 static HRESULT WINAPI xslprocessor_addObject(
499     IXSLProcessor *iface,
500     IDispatch *obj,
501     BSTR uri)
502 {
503     xslprocessor *This = impl_from_IXSLProcessor( iface );
504
505     FIXME("(%p)->(%p %s): stub\n", This, obj, wine_dbgstr_w(uri));
506     return E_NOTIMPL;
507 }
508
509 static HRESULT WINAPI xslprocessor_get_stylesheet(
510     IXSLProcessor *iface,
511     IXMLDOMNode  **node)
512 {
513     xslprocessor *This = impl_from_IXSLProcessor( iface );
514
515     FIXME("(%p)->(%p): stub\n", This, node);
516     return E_NOTIMPL;
517 }
518
519 static const struct IXSLProcessorVtbl xslprocessor_vtbl =
520 {
521     xslprocessor_QueryInterface,
522     xslprocessor_AddRef,
523     xslprocessor_Release,
524     xslprocessor_GetTypeInfoCount,
525     xslprocessor_GetTypeInfo,
526     xslprocessor_GetIDsOfNames,
527     xslprocessor_Invoke,
528
529     xslprocessor_put_input,
530     xslprocessor_get_input,
531     xslprocessor_get_ownerTemplate,
532     xslprocessor_setStartMode,
533     xslprocessor_get_startMode,
534     xslprocessor_get_startModeURI,
535     xslprocessor_put_output,
536     xslprocessor_get_output,
537     xslprocessor_transform,
538     xslprocessor_reset,
539     xslprocessor_get_readyState,
540     xslprocessor_addParameter,
541     xslprocessor_addObject,
542     xslprocessor_get_stylesheet
543 };
544
545 HRESULT XSLProcessor_create(IXSLProcessor **ppObj)
546 {
547     xslprocessor *This;
548
549     TRACE("(%p)\n", ppObj);
550
551     This = heap_alloc( sizeof (*This) );
552     if(!This)
553         return E_OUTOFMEMORY;
554
555     This->IXSLProcessor_iface.lpVtbl = &xslprocessor_vtbl;
556     This->ref = 1;
557
558     *ppObj = &This->IXSLProcessor_iface;
559
560     TRACE("returning iface %p\n", *ppObj);
561
562     return S_OK;
563 }
564
565 #else
566
567 HRESULT XSLTemplate_create(IUnknown *pUnkOuter, void **ppObj)
568 {
569     MESSAGE("This program tried to use a XSLTemplate object, but\n"
570             "libxml2 support was not present at compile time.\n");
571     return E_NOTIMPL;
572 }
573
574 #endif