wbemprox: Add support for parsing WQL queries.
[wine] / dlls / wbemprox / class.c
1 /*
2  * Copyright 2012 Hans Leidekker for CodeWeavers
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
17  */
18
19 #define COBJMACROS
20
21 #include "config.h"
22 #include <stdarg.h>
23
24 #include "windef.h"
25 #include "winbase.h"
26 #include "objbase.h"
27 #include "wbemcli.h"
28
29 #include "wine/debug.h"
30 #include "wbemprox_private.h"
31
32 WINE_DEFAULT_DEBUG_CHANNEL(wbemprox);
33
34 struct enum_class_object
35 {
36     IEnumWbemClassObject IEnumWbemClassObject_iface;
37     LONG refs;
38     struct query *query;
39 };
40
41 static inline struct enum_class_object *impl_from_IEnumWbemClassObject(
42     IEnumWbemClassObject *iface )
43 {
44     return CONTAINING_RECORD(iface, struct enum_class_object, IEnumWbemClassObject_iface);
45 }
46
47 static ULONG WINAPI enum_class_object_AddRef(
48     IEnumWbemClassObject *iface )
49 {
50     struct enum_class_object *ec = impl_from_IEnumWbemClassObject( iface );
51     return InterlockedIncrement( &ec->refs );
52 }
53
54 static ULONG WINAPI enum_class_object_Release(
55     IEnumWbemClassObject *iface )
56 {
57     struct enum_class_object *ec = impl_from_IEnumWbemClassObject( iface );
58     LONG refs = InterlockedDecrement( &ec->refs );
59     if (!refs)
60     {
61         TRACE("destroying %p\n", ec);
62         free_query( ec->query );
63         heap_free( ec );
64     }
65     return refs;
66 }
67
68 static HRESULT WINAPI enum_class_object_QueryInterface(
69     IEnumWbemClassObject *iface,
70     REFIID riid,
71     void **ppvObject )
72 {
73     struct enum_class_object *ec = impl_from_IEnumWbemClassObject( iface );
74
75     TRACE("%p, %s, %p\n", ec, debugstr_guid( riid ), ppvObject );
76
77     if ( IsEqualGUID( riid, &IID_IEnumWbemClassObject ) ||
78          IsEqualGUID( riid, &IID_IUnknown ) )
79     {
80         *ppvObject = ec;
81     }
82     else
83     {
84         FIXME("interface %s not implemented\n", debugstr_guid(riid));
85         return E_NOINTERFACE;
86     }
87     IEnumWbemClassObject_AddRef( iface );
88     return S_OK;
89 }
90
91 static HRESULT WINAPI enum_class_object_Reset(
92     IEnumWbemClassObject *iface )
93 {
94     FIXME("%p\n", iface);
95     return E_NOTIMPL;
96 }
97
98 static HRESULT WINAPI enum_class_object_Next(
99     IEnumWbemClassObject *iface,
100     LONG lTimeout,
101     ULONG uCount,
102     IWbemClassObject **apObjects,
103     ULONG *puReturned )
104 {
105     FIXME("%p, %d, %u, %p, %p\n", iface, lTimeout, uCount, apObjects, puReturned);
106     return E_NOTIMPL;
107 }
108
109 static HRESULT WINAPI enum_class_object_NextAsync(
110     IEnumWbemClassObject *iface,
111     ULONG uCount,
112     IWbemObjectSink *pSink )
113 {
114     FIXME("%p, %u, %p\n", iface, uCount, pSink);
115     return E_NOTIMPL;
116 }
117
118 static HRESULT WINAPI enum_class_object_Clone(
119     IEnumWbemClassObject *iface,
120     IEnumWbemClassObject **ppEnum )
121 {
122     FIXME("%p, %p\n", iface, ppEnum);
123     return E_NOTIMPL;
124 }
125
126 static HRESULT WINAPI enum_class_object_Skip(
127     IEnumWbemClassObject *iface,
128     LONG lTimeout,
129     ULONG nCount )
130 {
131     FIXME("%p, %d, %u\n", iface, lTimeout, nCount);
132     return E_NOTIMPL;
133 }
134
135 static const IEnumWbemClassObjectVtbl enum_class_object_vtbl =
136 {
137     enum_class_object_QueryInterface,
138     enum_class_object_AddRef,
139     enum_class_object_Release,
140     enum_class_object_Reset,
141     enum_class_object_Next,
142     enum_class_object_NextAsync,
143     enum_class_object_Clone,
144     enum_class_object_Skip
145 };
146
147 HRESULT EnumWbemClassObject_create(
148     IUnknown *pUnkOuter, struct query *query, LPVOID *ppObj )
149 {
150     struct enum_class_object *ec;
151
152     TRACE("%p, %p\n", pUnkOuter, ppObj);
153
154     ec = heap_alloc( sizeof(*ec) );
155     if (!ec) return E_OUTOFMEMORY;
156
157     ec->IEnumWbemClassObject_iface.lpVtbl = &enum_class_object_vtbl;
158     ec->refs  = 1;
159     ec->query = query;
160
161     *ppObj = &ec->IEnumWbemClassObject_iface;
162
163     TRACE("returning iface %p\n", *ppObj);
164     return S_OK;
165 }
166
167 struct class_object
168 {
169     IWbemClassObject IWbemClassObject_iface;
170     LONG refs;
171 };
172
173 static inline struct class_object *impl_from_IWbemClassObject(
174     IWbemClassObject *iface )
175 {
176     return CONTAINING_RECORD(iface, struct class_object, IWbemClassObject_iface);
177 }
178
179 static ULONG WINAPI class_object_AddRef(
180     IWbemClassObject *iface )
181 {
182     struct class_object *co = impl_from_IWbemClassObject( iface );
183     return InterlockedIncrement( &co->refs );
184 }
185
186 static ULONG WINAPI class_object_Release(
187     IWbemClassObject *iface )
188 {
189     struct class_object *co = impl_from_IWbemClassObject( iface );
190     LONG refs = InterlockedDecrement( &co->refs );
191     if (!refs)
192     {
193         TRACE("destroying %p\n", co);
194         heap_free( co );
195     }
196     return refs;
197 }
198
199 static HRESULT WINAPI class_object_QueryInterface(
200     IWbemClassObject *iface,
201     REFIID riid,
202     void **ppvObject )
203 {
204     struct class_object *co = impl_from_IWbemClassObject( iface );
205
206     TRACE("%p, %s, %p\n", co, debugstr_guid( riid ), ppvObject );
207
208     if ( IsEqualGUID( riid, &IID_IWbemClassObject ) ||
209          IsEqualGUID( riid, &IID_IUnknown ) )
210     {
211         *ppvObject = co;
212     }
213     else
214     {
215         FIXME("interface %s not implemented\n", debugstr_guid(riid));
216         return E_NOINTERFACE;
217     }
218     IWbemClassObject_AddRef( iface );
219     return S_OK;
220 }
221
222 static HRESULT WINAPI class_object_GetQualifierSet(
223     IWbemClassObject *iface,
224     IWbemQualifierSet **ppQualSet )
225 {
226     FIXME("%p, %p\n", iface, ppQualSet);
227     return E_NOTIMPL;
228 }
229
230 static HRESULT WINAPI class_object_Get(
231     IWbemClassObject *iface,
232     LPCWSTR wszName,
233     LONG lFlags,
234     VARIANT *pVal,
235     CIMTYPE *pType,
236     LONG *plFlavor )
237 {
238     FIXME("%p, %s, %08x, %p, %p, %p\n", iface, debugstr_w(wszName), lFlags, pVal, pType, plFlavor);
239     return E_NOTIMPL;
240 }
241
242 static HRESULT WINAPI class_object_Put(
243     IWbemClassObject *iface,
244     LPCWSTR wszName,
245     LONG lFlags,
246     VARIANT *pVal,
247     CIMTYPE Type )
248 {
249     FIXME("%p, %s, %08x, %p, %u\n", iface, debugstr_w(wszName), lFlags, pVal, Type);
250     return E_NOTIMPL;
251 }
252
253 static HRESULT WINAPI class_object_Delete(
254     IWbemClassObject *iface,
255     LPCWSTR wszName )
256 {
257     FIXME("%p, %s\n", iface, debugstr_w(wszName));
258     return E_NOTIMPL;
259 }
260
261 static HRESULT WINAPI class_object_GetNames(
262     IWbemClassObject *iface,
263     LPCWSTR wszQualifierName,
264     LONG lFlags,
265     VARIANT *pQualifierVal,
266     SAFEARRAY *pNames )
267 {
268     FIXME("%p, %s, %08x, %p, %p\n", iface, debugstr_w(wszQualifierName), lFlags, pQualifierVal, pNames);
269     return E_NOTIMPL;
270 }
271
272 static HRESULT WINAPI class_object_BeginEnumeration(
273     IWbemClassObject *iface,
274     LONG lEnumFlags )
275 {
276     FIXME("%p, %08x\n", iface, lEnumFlags);
277     return E_NOTIMPL;
278 }
279
280 static HRESULT WINAPI class_object_Next(
281     IWbemClassObject *iface,
282     LONG lFlags,
283     BSTR *strName,
284     VARIANT *pVal,
285     CIMTYPE *pType,
286     LONG *plFlavor )
287 {
288     FIXME("%p, %08x, %p, %p, %p, %p\n", iface, lFlags, strName, pVal, pType, plFlavor);
289     return E_NOTIMPL;
290 }
291
292 static HRESULT WINAPI class_object_EndEnumeration(
293     IWbemClassObject *iface )
294 {
295     FIXME("%p\n", iface);
296     return E_NOTIMPL;
297 }
298
299 static HRESULT WINAPI class_object_GetPropertyQualifierSet(
300     IWbemClassObject *iface,
301     LPCWSTR wszProperty,
302     IWbemQualifierSet **ppQualSet )
303 {
304     FIXME("%p, %s, %p\n", iface, debugstr_w(wszProperty), ppQualSet);
305     return E_NOTIMPL;
306 }
307
308 static HRESULT WINAPI class_object_Clone(
309     IWbemClassObject *iface,
310     IWbemClassObject **ppCopy )
311 {
312     FIXME("%p, %p\n", iface, ppCopy);
313     return E_NOTIMPL;
314 }
315
316 static HRESULT WINAPI class_object_GetObjectText(
317     IWbemClassObject *iface,
318     LONG lFlags,
319     BSTR *pstrObjectText )
320 {
321     FIXME("%p, %08x, %p\n", iface, lFlags, pstrObjectText);
322     return E_NOTIMPL;
323 }
324
325 static HRESULT WINAPI class_object_SpawnDerivedClass(
326     IWbemClassObject *iface,
327     LONG lFlags,
328     IWbemClassObject **ppNewClass )
329 {
330     FIXME("%p, %08x, %p\n", iface, lFlags, ppNewClass);
331     return E_NOTIMPL;
332 }
333
334 static HRESULT WINAPI class_object_SpawnInstance(
335     IWbemClassObject *iface,
336     LONG lFlags,
337     IWbemClassObject **ppNewInstance )
338 {
339     FIXME("%p, %08x, %p\n", iface, lFlags, ppNewInstance);
340     return E_NOTIMPL;
341 }
342
343 static HRESULT WINAPI class_object_CompareTo(
344     IWbemClassObject *iface,
345     LONG lFlags,
346     IWbemClassObject *pCompareTo )
347 {
348     FIXME("%p, %08x, %p\n", iface, lFlags, pCompareTo);
349     return E_NOTIMPL;
350 }
351
352 static HRESULT WINAPI class_object_GetPropertyOrigin(
353     IWbemClassObject *iface,
354     LPCWSTR wszName,
355     BSTR *pstrClassName )
356 {
357     FIXME("%p, %s, %p\n", iface, debugstr_w(wszName), pstrClassName);
358     return E_NOTIMPL;
359 }
360
361 static HRESULT WINAPI class_object_InheritsFrom(
362     IWbemClassObject *iface,
363     LPCWSTR strAncestor )
364 {
365     FIXME("%p, %s\n", iface, debugstr_w(strAncestor));
366     return E_NOTIMPL;
367 }
368
369 static HRESULT WINAPI class_object_GetMethod(
370     IWbemClassObject *iface,
371     LPCWSTR wszName,
372     LONG lFlags,
373     IWbemClassObject **ppInSignature,
374     IWbemClassObject **ppOutSignature )
375 {
376     FIXME("%p, %s, %08x, %p, %p\n", iface, debugstr_w(wszName), lFlags, ppInSignature, ppOutSignature);
377     return E_NOTIMPL;
378 }
379
380 static HRESULT WINAPI class_object_PutMethod(
381     IWbemClassObject *iface,
382     LPCWSTR wszName,
383     LONG lFlags,
384     IWbemClassObject *pInSignature,
385     IWbemClassObject *pOutSignature )
386 {
387     FIXME("%p, %s, %08x, %p, %p\n", iface, debugstr_w(wszName), lFlags, pInSignature, pOutSignature);
388     return E_NOTIMPL;
389 }
390
391 static HRESULT WINAPI class_object_DeleteMethod(
392     IWbemClassObject *iface,
393     LPCWSTR wszName )
394 {
395     FIXME("%p, %s\n", iface, debugstr_w(wszName));
396     return E_NOTIMPL;
397 }
398
399 static HRESULT WINAPI class_object_BeginMethodEnumeration(
400     IWbemClassObject *iface,
401     LONG lEnumFlags)
402 {
403     FIXME("%p, %08x\n", iface, lEnumFlags);
404     return E_NOTIMPL;
405 }
406
407 static HRESULT WINAPI class_object_NextMethod(
408     IWbemClassObject *iface,
409     LONG lFlags,
410     BSTR *pstrName,
411     IWbemClassObject **ppInSignature,
412     IWbemClassObject **ppOutSignature)
413 {
414     FIXME("%p, %08x, %p, %p, %p\n", iface, lFlags, pstrName, ppInSignature, ppOutSignature);
415     return E_NOTIMPL;
416 }
417
418 static HRESULT WINAPI class_object_EndMethodEnumeration(
419     IWbemClassObject *iface )
420 {
421     FIXME("%p\n", iface);
422     return E_NOTIMPL;
423 }
424
425 static HRESULT WINAPI class_object_GetMethodQualifierSet(
426     IWbemClassObject *iface,
427     LPCWSTR wszMethod,
428     IWbemQualifierSet **ppQualSet)
429 {
430     FIXME("%p, %s, %p\n", iface, debugstr_w(wszMethod), ppQualSet);
431     return E_NOTIMPL;
432 }
433
434 static HRESULT WINAPI class_object_GetMethodOrigin(
435     IWbemClassObject *iface,
436     LPCWSTR wszMethodName,
437     BSTR *pstrClassName)
438 {
439     FIXME("%p, %s, %p\n", iface, debugstr_w(wszMethodName), pstrClassName);
440     return E_NOTIMPL;
441 }
442
443 static const IWbemClassObjectVtbl class_object_vtbl =
444 {
445     class_object_QueryInterface,
446     class_object_AddRef,
447     class_object_Release,
448     class_object_GetQualifierSet,
449     class_object_Get,
450     class_object_Put,
451     class_object_Delete,
452     class_object_GetNames,
453     class_object_BeginEnumeration,
454     class_object_Next,
455     class_object_EndEnumeration,
456     class_object_GetPropertyQualifierSet,
457     class_object_Clone,
458     class_object_GetObjectText,
459     class_object_SpawnDerivedClass,
460     class_object_SpawnInstance,
461     class_object_CompareTo,
462     class_object_GetPropertyOrigin,
463     class_object_InheritsFrom,
464     class_object_GetMethod,
465     class_object_PutMethod,
466     class_object_DeleteMethod,
467     class_object_BeginMethodEnumeration,
468     class_object_NextMethod,
469     class_object_EndMethodEnumeration,
470     class_object_GetMethodQualifierSet,
471     class_object_GetMethodOrigin
472 };
473
474 HRESULT WbemClassObject_create(
475     IUnknown *pUnkOuter, LPVOID *ppObj )
476 {
477     struct class_object *co;
478
479     TRACE("%p, %p\n", pUnkOuter, ppObj);
480
481     co = heap_alloc( sizeof(*co) );
482     if (!co) return E_OUTOFMEMORY;
483
484     co->IWbemClassObject_iface.lpVtbl = &class_object_vtbl;
485     co->refs = 1;
486
487     *ppObj = &co->IWbemClassObject_iface;
488
489     TRACE("returning iface %p\n", *ppObj);
490     return S_OK;
491 }