mshtml: Keep reference in node returned from get_node.
[wine] / dlls / wbemprox / services.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 "initguid.h"
27 #include "objbase.h"
28 #include "wbemcli.h"
29
30 #include "wine/debug.h"
31 #include "wine/unicode.h"
32 #include "wbemprox_private.h"
33
34 WINE_DEFAULT_DEBUG_CHANNEL(wbemprox);
35
36 struct client_security
37 {
38     IClientSecurity IClientSecurity_iface;
39 };
40
41 static inline struct client_security *impl_from_IClientSecurity( IClientSecurity *iface )
42 {
43     return CONTAINING_RECORD( iface, struct client_security, IClientSecurity_iface );
44 }
45
46 static HRESULT WINAPI client_security_QueryInterface(
47     IClientSecurity *iface,
48     REFIID riid,
49     void **ppvObject )
50 {
51     struct client_security *cs = impl_from_IClientSecurity( iface );
52
53     TRACE("%p %s %p\n", cs, debugstr_guid( riid ), ppvObject );
54
55     if ( IsEqualGUID( riid, &IID_IClientSecurity ) ||
56          IsEqualGUID( riid, &IID_IUnknown ) )
57     {
58         *ppvObject = cs;
59     }
60     else
61     {
62         FIXME("interface %s not implemented\n", debugstr_guid(riid));
63         return E_NOINTERFACE;
64     }
65     IClientSecurity_AddRef( iface );
66     return S_OK;
67 }
68
69 static ULONG WINAPI client_security_AddRef(
70     IClientSecurity *iface )
71 {
72     FIXME("%p\n", iface);
73     return 2;
74 }
75
76 static ULONG WINAPI client_security_Release(
77     IClientSecurity *iface )
78 {
79     FIXME("%p\n", iface);
80     return 1;
81 }
82
83 static HRESULT WINAPI client_security_QueryBlanket(
84     IClientSecurity *iface,
85     IUnknown *pProxy,
86     DWORD *pAuthnSvc,
87     DWORD *pAuthzSvc,
88     OLECHAR **pServerPrincName,
89     DWORD *pAuthnLevel,
90     DWORD *pImpLevel,
91     void **pAuthInfo,
92     DWORD *pCapabilities )
93 {
94     FIXME("\n");
95     return WBEM_E_FAILED;
96 }
97
98 static HRESULT WINAPI client_security_SetBlanket(
99     IClientSecurity *iface,
100     IUnknown *pProxy,
101     DWORD AuthnSvc,
102     DWORD AuthzSvc,
103     OLECHAR *pServerPrincName,
104     DWORD AuthnLevel,
105     DWORD ImpLevel,
106     void *pAuthInfo,
107     DWORD Capabilities )
108 {
109     FIXME("%p, %p, %u, %u, %s, %u, %u, %p, 0x%08x\n", iface, pProxy, AuthnSvc, AuthzSvc,
110           debugstr_w(pServerPrincName), AuthnLevel, ImpLevel, pAuthInfo, Capabilities);
111     return WBEM_NO_ERROR;
112 }
113
114 static HRESULT WINAPI client_security_CopyProxy(
115     IClientSecurity *iface,
116     IUnknown *pProxy,
117     IUnknown **ppCopy )
118 {
119     FIXME("\n");
120     return WBEM_E_FAILED;
121 }
122
123 static const IClientSecurityVtbl client_security_vtbl =
124 {
125     client_security_QueryInterface,
126     client_security_AddRef,
127     client_security_Release,
128     client_security_QueryBlanket,
129     client_security_SetBlanket,
130     client_security_CopyProxy
131 };
132
133 static IClientSecurity client_security = { &client_security_vtbl };
134
135 struct wbem_services
136 {
137     IWbemServices IWbemServices_iface;
138     LONG refs;
139     WCHAR *namespace;
140 };
141
142 static inline struct wbem_services *impl_from_IWbemServices( IWbemServices *iface )
143 {
144     return CONTAINING_RECORD( iface, struct wbem_services, IWbemServices_iface );
145 }
146
147 static ULONG WINAPI wbem_services_AddRef(
148     IWbemServices *iface )
149 {
150     struct wbem_services *ws = impl_from_IWbemServices( iface );
151     return InterlockedIncrement( &ws->refs );
152 }
153
154 static ULONG WINAPI wbem_services_Release(
155     IWbemServices *iface )
156 {
157     struct wbem_services *ws = impl_from_IWbemServices( iface );
158     LONG refs = InterlockedDecrement( &ws->refs );
159     if (!refs)
160     {
161         TRACE("destroying %p\n", ws);
162         heap_free( ws->namespace );
163         heap_free( ws );
164     }
165     return refs;
166 }
167
168 static HRESULT WINAPI wbem_services_QueryInterface(
169     IWbemServices *iface,
170     REFIID riid,
171     void **ppvObject )
172 {
173     struct wbem_services *ws = impl_from_IWbemServices( iface );
174
175     TRACE("%p %s %p\n", ws, debugstr_guid( riid ), ppvObject );
176
177     if ( IsEqualGUID( riid, &IID_IWbemServices ) ||
178          IsEqualGUID( riid, &IID_IUnknown ) )
179     {
180         *ppvObject = ws;
181     }
182     else if ( IsEqualGUID( riid, &IID_IClientSecurity ) )
183     {
184         *ppvObject = &client_security;
185         return S_OK;
186     }
187     else
188     {
189         FIXME("interface %s not implemented\n", debugstr_guid(riid));
190         return E_NOINTERFACE;
191     }
192     IWbemServices_AddRef( iface );
193     return S_OK;
194 }
195
196 static HRESULT WINAPI wbem_services_OpenNamespace(
197     IWbemServices *iface,
198     const BSTR strNamespace,
199     LONG lFlags,
200     IWbemContext *pCtx,
201     IWbemServices **ppWorkingNamespace,
202     IWbemCallResult **ppResult )
203 {
204     FIXME("\n");
205     return WBEM_E_FAILED;
206 }
207
208 static HRESULT WINAPI wbem_services_CancelAsyncCall(
209     IWbemServices *iface,
210     IWbemObjectSink *pSink )
211 {
212     FIXME("\n");
213     return WBEM_E_FAILED;
214 }
215
216 static HRESULT WINAPI wbem_services_QueryObjectSink(
217     IWbemServices *iface,
218     LONG lFlags,
219     IWbemObjectSink **ppResponseHandler )
220 {
221     FIXME("\n");
222     return WBEM_E_FAILED;
223 }
224
225 static HRESULT WINAPI wbem_services_GetObject(
226     IWbemServices *iface,
227     const BSTR strObjectPath,
228     LONG lFlags,
229     IWbemContext *pCtx,
230     IWbemClassObject **ppObject,
231     IWbemCallResult **ppCallResult )
232 {
233     FIXME("\n");
234     return WBEM_E_FAILED;
235 }
236
237 static HRESULT WINAPI wbem_services_GetObjectAsync(
238     IWbemServices *iface,
239     const BSTR strObjectPath,
240     LONG lFlags,
241     IWbemContext *pCtx,
242     IWbemObjectSink *pResponseHandler )
243 {
244     FIXME("\n");
245     return WBEM_E_FAILED;
246 }
247
248 static HRESULT WINAPI wbem_services_PutClass(
249     IWbemServices *iface,
250     IWbemClassObject *pObject,
251     LONG lFlags,
252     IWbemContext *pCtx,
253     IWbemCallResult **ppCallResult )
254 {
255     FIXME("\n");
256     return WBEM_E_FAILED;
257 }
258
259 static HRESULT WINAPI wbem_services_PutClassAsync(
260     IWbemServices *iface,
261     IWbemClassObject *pObject,
262     LONG lFlags,
263     IWbemContext *pCtx,
264     IWbemObjectSink *pResponseHandler )
265 {
266     FIXME("\n");
267     return WBEM_E_FAILED;
268 }
269
270 static HRESULT WINAPI wbem_services_DeleteClass(
271     IWbemServices *iface,
272     const BSTR strClass,
273     LONG lFlags,
274     IWbemContext *pCtx,
275     IWbemCallResult **ppCallResult )
276 {
277     FIXME("\n");
278     return WBEM_E_FAILED;
279 }
280
281 static HRESULT WINAPI wbem_services_DeleteClassAsync(
282     IWbemServices *iface,
283     const BSTR strClass,
284     LONG lFlags,
285     IWbemContext *pCtx,
286     IWbemObjectSink *pResponseHandler )
287 {
288     FIXME("\n");
289     return WBEM_E_FAILED;
290 }
291
292 static HRESULT WINAPI wbem_services_CreateClassEnum(
293     IWbemServices *iface,
294     const BSTR strSuperclass,
295     LONG lFlags,
296     IWbemContext *pCtx,
297     IEnumWbemClassObject **ppEnum )
298 {
299     FIXME("\n");
300     return WBEM_E_FAILED;
301 }
302
303 static HRESULT WINAPI wbem_services_CreateClassEnumAsync(
304     IWbemServices *iface,
305     const BSTR strSuperclass,
306     LONG lFlags,
307     IWbemContext *pCtx,
308     IWbemObjectSink *pResponseHandler )
309 {
310     FIXME("\n");
311     return WBEM_E_FAILED;
312 }
313
314 static HRESULT WINAPI wbem_services_PutInstance(
315     IWbemServices *iface,
316     IWbemClassObject *pInst,
317     LONG lFlags,
318     IWbemContext *pCtx,
319     IWbemCallResult **ppCallResult )
320 {
321     FIXME("\n");
322     return WBEM_E_FAILED;
323 }
324
325 static HRESULT WINAPI wbem_services_PutInstanceAsync(
326     IWbemServices *iface,
327     IWbemClassObject *pInst,
328     LONG lFlags,
329     IWbemContext *pCtx,
330     IWbemObjectSink *pResponseHandler )
331 {
332     FIXME("\n");
333     return WBEM_E_FAILED;
334 }
335
336 static HRESULT WINAPI wbem_services_DeleteInstance(
337     IWbemServices *iface,
338     const BSTR strObjectPath,
339     LONG lFlags,
340     IWbemContext *pCtx,
341     IWbemCallResult **ppCallResult )
342 {
343     FIXME("\n");
344     return WBEM_E_FAILED;
345 }
346
347 static HRESULT WINAPI wbem_services_DeleteInstanceAsync(
348     IWbemServices *iface,
349     const BSTR strObjectPath,
350     LONG lFlags,
351     IWbemContext *pCtx,
352     IWbemObjectSink *pResponseHandler )
353 {
354     FIXME("\n");
355     return WBEM_E_FAILED;
356 }
357
358 static HRESULT WINAPI wbem_services_CreateInstanceEnum(
359     IWbemServices *iface,
360     const BSTR strFilter,
361     LONG lFlags,
362     IWbemContext *pCtx,
363     IEnumWbemClassObject **ppEnum )
364 {
365     FIXME("\n");
366     return WBEM_E_FAILED;
367 }
368
369 static HRESULT WINAPI wbem_services_CreateInstanceEnumAsync(
370     IWbemServices *iface,
371     const BSTR strFilter,
372     LONG lFlags,
373     IWbemContext *pCtx,
374     IWbemObjectSink *pResponseHandler )
375 {
376     FIXME("\n");
377     return WBEM_E_FAILED;
378 }
379
380 static HRESULT WINAPI wbem_services_ExecQuery(
381     IWbemServices *iface,
382     const BSTR strQueryLanguage,
383     const BSTR strQuery,
384     LONG lFlags,
385     IWbemContext *pCtx,
386     IEnumWbemClassObject **ppEnum )
387 {
388     static const WCHAR wqlW[] = {'W','Q','L',0};
389
390     TRACE("%p, %s, %s, 0x%08x, %p, %p\n", iface, debugstr_w(strQueryLanguage),
391           debugstr_w(strQuery), lFlags, pCtx, ppEnum);
392
393     if (!strQueryLanguage || !strQuery) return WBEM_E_INVALID_PARAMETER;
394     if (strcmpiW( strQueryLanguage, wqlW )) return WBEM_E_INVALID_QUERY_TYPE;
395     return exec_query( strQuery, ppEnum );
396 }
397
398 static HRESULT WINAPI wbem_services_ExecQueryAsync(
399     IWbemServices *iface,
400     const BSTR strQueryLanguage,
401     const BSTR strQuery,
402     LONG lFlags,
403     IWbemContext *pCtx,
404     IWbemObjectSink *pResponseHandler )
405 {
406     FIXME("\n");
407     return WBEM_E_FAILED;
408 }
409
410 static HRESULT WINAPI wbem_services_ExecNotificationQuery(
411     IWbemServices *iface,
412     const BSTR strQueryLanguage,
413     const BSTR strQuery,
414     LONG lFlags,
415     IWbemContext *pCtx,
416     IEnumWbemClassObject **ppEnum )
417 {
418     FIXME("\n");
419     return WBEM_E_FAILED;
420 }
421
422 static HRESULT WINAPI wbem_services_ExecNotificationQueryAsync(
423     IWbemServices *iface,
424     const BSTR strQueryLanguage,
425     const BSTR strQuery,
426     LONG lFlags,
427     IWbemContext *pCtx,
428     IWbemObjectSink *pResponseHandler )
429 {
430     FIXME("\n");
431     return WBEM_E_FAILED;
432 }
433
434 static HRESULT WINAPI wbem_services_ExecMethod(
435     IWbemServices *iface,
436     const BSTR strObjectPath,
437     const BSTR strMethodName,
438     LONG lFlags,
439     IWbemContext *pCtx,
440     IWbemClassObject *pInParams,
441     IWbemClassObject **ppOutParams,
442     IWbemCallResult **ppCallResult )
443 {
444     FIXME("\n");
445     return WBEM_E_FAILED;
446 }
447
448 static HRESULT WINAPI wbem_services_ExecMethodAsync(
449     IWbemServices *iface,
450     const BSTR strObjectPath,
451     const BSTR strMethodName,
452     LONG lFlags,
453     IWbemContext *pCtx,
454     IWbemClassObject *pInParams,
455     IWbemObjectSink *pResponseHandler )
456 {
457     FIXME("\n");
458     return WBEM_E_FAILED;
459 }
460
461 static const IWbemServicesVtbl wbem_services_vtbl =
462 {
463     wbem_services_QueryInterface,
464     wbem_services_AddRef,
465     wbem_services_Release,
466     wbem_services_OpenNamespace,
467     wbem_services_CancelAsyncCall,
468     wbem_services_QueryObjectSink,
469     wbem_services_GetObject,
470     wbem_services_GetObjectAsync,
471     wbem_services_PutClass,
472     wbem_services_PutClassAsync,
473     wbem_services_DeleteClass,
474     wbem_services_DeleteClassAsync,
475     wbem_services_CreateClassEnum,
476     wbem_services_CreateClassEnumAsync,
477     wbem_services_PutInstance,
478     wbem_services_PutInstanceAsync,
479     wbem_services_DeleteInstance,
480     wbem_services_DeleteInstanceAsync,
481     wbem_services_CreateInstanceEnum,
482     wbem_services_CreateInstanceEnumAsync,
483     wbem_services_ExecQuery,
484     wbem_services_ExecQueryAsync,
485     wbem_services_ExecNotificationQuery,
486     wbem_services_ExecNotificationQueryAsync,
487     wbem_services_ExecMethod,
488     wbem_services_ExecMethodAsync
489 };
490
491 HRESULT WbemServices_create( IUnknown *pUnkOuter, WCHAR *namespace, LPVOID *ppObj )
492 {
493     struct wbem_services *ws;
494
495     TRACE("(%p,%p)\n", pUnkOuter, ppObj);
496
497     ws = heap_alloc( sizeof(*ws) );
498     if (!ws) return E_OUTOFMEMORY;
499
500     ws->IWbemServices_iface.lpVtbl = &wbem_services_vtbl;
501     ws->refs = 1;
502     ws->namespace = namespace;
503
504     *ppObj = &ws->IWbemServices_iface;
505
506     TRACE("returning iface %p\n", *ppObj);
507     return S_OK;
508 }