msvcp: Sync num_get<>::_Getifld.
[wine/multimedia.git] / dlls / wbemprox / services.c
blob663d2d0550ae9bbfb45d4d31fd4edf01de23b7b9
1 /*
2 * Copyright 2012 Hans Leidekker for CodeWeavers
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.
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.
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
19 #define COBJMACROS
21 #include "config.h"
22 #include <stdarg.h>
24 #include "windef.h"
25 #include "winbase.h"
26 #include "objbase.h"
27 #include "wbemcli.h"
29 #include "wine/debug.h"
30 #include "wine/unicode.h"
31 #include "wbemprox_private.h"
33 WINE_DEFAULT_DEBUG_CHANNEL(wbemprox);
35 struct client_security
37 IClientSecurity IClientSecurity_iface;
40 static inline struct client_security *impl_from_IClientSecurity( IClientSecurity *iface )
42 return CONTAINING_RECORD( iface, struct client_security, IClientSecurity_iface );
45 static HRESULT WINAPI client_security_QueryInterface(
46 IClientSecurity *iface,
47 REFIID riid,
48 void **ppvObject )
50 struct client_security *cs = impl_from_IClientSecurity( iface );
52 TRACE("%p %s %p\n", cs, debugstr_guid( riid ), ppvObject );
54 if ( IsEqualGUID( riid, &IID_IClientSecurity ) ||
55 IsEqualGUID( riid, &IID_IUnknown ) )
57 *ppvObject = cs;
59 else
61 FIXME("interface %s not implemented\n", debugstr_guid(riid));
62 return E_NOINTERFACE;
64 IClientSecurity_AddRef( iface );
65 return S_OK;
68 static ULONG WINAPI client_security_AddRef(
69 IClientSecurity *iface )
71 FIXME("%p\n", iface);
72 return 2;
75 static ULONG WINAPI client_security_Release(
76 IClientSecurity *iface )
78 FIXME("%p\n", iface);
79 return 1;
82 static HRESULT WINAPI client_security_QueryBlanket(
83 IClientSecurity *iface,
84 IUnknown *pProxy,
85 DWORD *pAuthnSvc,
86 DWORD *pAuthzSvc,
87 OLECHAR **pServerPrincName,
88 DWORD *pAuthnLevel,
89 DWORD *pImpLevel,
90 void **pAuthInfo,
91 DWORD *pCapabilities )
93 FIXME("\n");
94 return WBEM_E_FAILED;
97 static HRESULT WINAPI client_security_SetBlanket(
98 IClientSecurity *iface,
99 IUnknown *pProxy,
100 DWORD AuthnSvc,
101 DWORD AuthzSvc,
102 OLECHAR *pServerPrincName,
103 DWORD AuthnLevel,
104 DWORD ImpLevel,
105 void *pAuthInfo,
106 DWORD Capabilities )
108 static const OLECHAR defaultW[] =
109 {'<','C','O','L','E','_','D','E','F','A','U','L','T','_','P','R','I','N','C','I','P','A','L','>',0};
110 const OLECHAR *princname = (pServerPrincName == COLE_DEFAULT_PRINCIPAL) ? defaultW : pServerPrincName;
112 FIXME("%p, %p, %u, %u, %s, %u, %u, %p, 0x%08x\n", iface, pProxy, AuthnSvc, AuthzSvc,
113 debugstr_w(princname), AuthnLevel, ImpLevel, pAuthInfo, Capabilities);
114 return WBEM_NO_ERROR;
117 static HRESULT WINAPI client_security_CopyProxy(
118 IClientSecurity *iface,
119 IUnknown *pProxy,
120 IUnknown **ppCopy )
122 FIXME("\n");
123 return WBEM_E_FAILED;
126 static const IClientSecurityVtbl client_security_vtbl =
128 client_security_QueryInterface,
129 client_security_AddRef,
130 client_security_Release,
131 client_security_QueryBlanket,
132 client_security_SetBlanket,
133 client_security_CopyProxy
136 IClientSecurity client_security = { &client_security_vtbl };
138 struct wbem_services
140 IWbemServices IWbemServices_iface;
141 LONG refs;
142 WCHAR *namespace;
145 static inline struct wbem_services *impl_from_IWbemServices( IWbemServices *iface )
147 return CONTAINING_RECORD( iface, struct wbem_services, IWbemServices_iface );
150 static ULONG WINAPI wbem_services_AddRef(
151 IWbemServices *iface )
153 struct wbem_services *ws = impl_from_IWbemServices( iface );
154 return InterlockedIncrement( &ws->refs );
157 static ULONG WINAPI wbem_services_Release(
158 IWbemServices *iface )
160 struct wbem_services *ws = impl_from_IWbemServices( iface );
161 LONG refs = InterlockedDecrement( &ws->refs );
162 if (!refs)
164 TRACE("destroying %p\n", ws);
165 heap_free( ws->namespace );
166 heap_free( ws );
168 return refs;
171 static HRESULT WINAPI wbem_services_QueryInterface(
172 IWbemServices *iface,
173 REFIID riid,
174 void **ppvObject )
176 struct wbem_services *ws = impl_from_IWbemServices( iface );
178 TRACE("%p %s %p\n", ws, debugstr_guid( riid ), ppvObject );
180 if ( IsEqualGUID( riid, &IID_IWbemServices ) ||
181 IsEqualGUID( riid, &IID_IUnknown ) )
183 *ppvObject = ws;
185 else if ( IsEqualGUID( riid, &IID_IClientSecurity ) )
187 *ppvObject = &client_security;
188 return S_OK;
190 else
192 FIXME("interface %s not implemented\n", debugstr_guid(riid));
193 return E_NOINTERFACE;
195 IWbemServices_AddRef( iface );
196 return S_OK;
199 static HRESULT WINAPI wbem_services_OpenNamespace(
200 IWbemServices *iface,
201 const BSTR strNamespace,
202 LONG lFlags,
203 IWbemContext *pCtx,
204 IWbemServices **ppWorkingNamespace,
205 IWbemCallResult **ppResult )
207 static const WCHAR cimv2W[] = {'c','i','m','v','2',0};
208 static const WCHAR defaultW[] = {'d','e','f','a','u','l','t',0};
209 struct wbem_services *ws = impl_from_IWbemServices( iface );
211 TRACE("%p, %s, 0x%08x, %p, %p, %p\n", iface, debugstr_w(strNamespace), lFlags,
212 pCtx, ppWorkingNamespace, ppResult);
214 if ((strcmpiW( strNamespace, cimv2W ) && strcmpiW( strNamespace, defaultW )) || ws->namespace)
215 return WBEM_E_INVALID_NAMESPACE;
217 return WbemServices_create( NULL, cimv2W, (void **)ppWorkingNamespace );
220 static HRESULT WINAPI wbem_services_CancelAsyncCall(
221 IWbemServices *iface,
222 IWbemObjectSink *pSink )
224 FIXME("\n");
225 return WBEM_E_FAILED;
228 static HRESULT WINAPI wbem_services_QueryObjectSink(
229 IWbemServices *iface,
230 LONG lFlags,
231 IWbemObjectSink **ppResponseHandler )
233 FIXME("\n");
234 return WBEM_E_FAILED;
237 struct path
239 WCHAR *class;
240 UINT class_len;
241 WCHAR *filter;
242 UINT filter_len;
245 static HRESULT parse_path( const WCHAR *str, struct path **ret )
247 struct path *path;
248 const WCHAR *p = str, *q;
249 UINT len;
251 if (!(path = heap_alloc_zero( sizeof(*path) ))) return E_OUTOFMEMORY;
253 while (*p && *p != '.') p++;
255 len = p - str;
256 if (!(path->class = heap_alloc( (len + 1) * sizeof(WCHAR) )))
258 heap_free( path );
259 return E_OUTOFMEMORY;
261 memcpy( path->class, str, len * sizeof(WCHAR) );
262 path->class[len] = 0;
263 path->class_len = len;
265 if (p[0] == '.' && p[1])
267 q = ++p;
268 while (*q) q++;
270 len = q - p;
271 if (!(path->filter = heap_alloc( (len + 1) * sizeof(WCHAR) )))
273 heap_free( path->class );
274 heap_free( path );
275 return E_OUTOFMEMORY;
277 memcpy( path->filter, p, len * sizeof(WCHAR) );
278 path->filter[len] = 0;
279 path->filter_len = len;
281 *ret = path;
282 return S_OK;
285 static void free_path( struct path *path )
287 heap_free( path->class );
288 heap_free( path->filter );
289 heap_free( path );
292 static HRESULT create_instance_enum( const struct path *path, IEnumWbemClassObject **iter )
294 static const WCHAR selectW[] =
295 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ','%','s',' ',
296 'W','H','E','R','E',' ','%','s',0};
297 static const WCHAR select_allW[] =
298 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',0};
299 WCHAR *query;
300 HRESULT hr;
301 UINT len;
303 if (path->filter)
305 len = path->class_len + path->filter_len + SIZEOF(selectW);
306 if (!(query = heap_alloc( len * sizeof(WCHAR) ))) return E_OUTOFMEMORY;
307 sprintfW( query, selectW, path->class, path->filter );
309 else
311 len = path->class_len + SIZEOF(select_allW);
312 if (!(query = heap_alloc( len * sizeof(WCHAR) ))) return E_OUTOFMEMORY;
313 strcpyW( query, select_allW );
314 strcatW( query, path->class );
316 hr = exec_query( query, iter );
317 heap_free( query );
318 return hr;
321 HRESULT get_object( const WCHAR *object_path, IWbemClassObject **obj )
323 IEnumWbemClassObject *iter;
324 struct path *path;
325 HRESULT hr;
327 hr = parse_path( object_path, &path );
328 if (hr != S_OK) return hr;
330 hr = create_instance_enum( path, &iter );
331 if (hr != S_OK)
333 free_path( path );
334 return hr;
336 hr = create_class_object( path->class, iter, 0, NULL, obj );
337 IEnumWbemClassObject_Release( iter );
338 free_path( path );
339 return hr;
342 static HRESULT WINAPI wbem_services_GetObject(
343 IWbemServices *iface,
344 const BSTR strObjectPath,
345 LONG lFlags,
346 IWbemContext *pCtx,
347 IWbemClassObject **ppObject,
348 IWbemCallResult **ppCallResult )
350 TRACE("%p, %s, 0x%08x, %p, %p, %p\n", iface, debugstr_w(strObjectPath), lFlags,
351 pCtx, ppObject, ppCallResult);
353 if (lFlags) FIXME("unsupported flags 0x%08x\n", lFlags);
355 if (!strObjectPath)
357 FIXME("no support for creating new classes\n");
358 return WBEM_E_FAILED;
360 return get_object( strObjectPath, ppObject );
363 static HRESULT WINAPI wbem_services_GetObjectAsync(
364 IWbemServices *iface,
365 const BSTR strObjectPath,
366 LONG lFlags,
367 IWbemContext *pCtx,
368 IWbemObjectSink *pResponseHandler )
370 FIXME("\n");
371 return WBEM_E_FAILED;
374 static HRESULT WINAPI wbem_services_PutClass(
375 IWbemServices *iface,
376 IWbemClassObject *pObject,
377 LONG lFlags,
378 IWbemContext *pCtx,
379 IWbemCallResult **ppCallResult )
381 FIXME("\n");
382 return WBEM_E_FAILED;
385 static HRESULT WINAPI wbem_services_PutClassAsync(
386 IWbemServices *iface,
387 IWbemClassObject *pObject,
388 LONG lFlags,
389 IWbemContext *pCtx,
390 IWbemObjectSink *pResponseHandler )
392 FIXME("\n");
393 return WBEM_E_FAILED;
396 static HRESULT WINAPI wbem_services_DeleteClass(
397 IWbemServices *iface,
398 const BSTR strClass,
399 LONG lFlags,
400 IWbemContext *pCtx,
401 IWbemCallResult **ppCallResult )
403 FIXME("\n");
404 return WBEM_E_FAILED;
407 static HRESULT WINAPI wbem_services_DeleteClassAsync(
408 IWbemServices *iface,
409 const BSTR strClass,
410 LONG lFlags,
411 IWbemContext *pCtx,
412 IWbemObjectSink *pResponseHandler )
414 FIXME("\n");
415 return WBEM_E_FAILED;
418 static HRESULT WINAPI wbem_services_CreateClassEnum(
419 IWbemServices *iface,
420 const BSTR strSuperclass,
421 LONG lFlags,
422 IWbemContext *pCtx,
423 IEnumWbemClassObject **ppEnum )
425 FIXME("\n");
426 return WBEM_E_FAILED;
429 static HRESULT WINAPI wbem_services_CreateClassEnumAsync(
430 IWbemServices *iface,
431 const BSTR strSuperclass,
432 LONG lFlags,
433 IWbemContext *pCtx,
434 IWbemObjectSink *pResponseHandler )
436 FIXME("\n");
437 return WBEM_E_FAILED;
440 static HRESULT WINAPI wbem_services_PutInstance(
441 IWbemServices *iface,
442 IWbemClassObject *pInst,
443 LONG lFlags,
444 IWbemContext *pCtx,
445 IWbemCallResult **ppCallResult )
447 FIXME("\n");
448 return WBEM_E_FAILED;
451 static HRESULT WINAPI wbem_services_PutInstanceAsync(
452 IWbemServices *iface,
453 IWbemClassObject *pInst,
454 LONG lFlags,
455 IWbemContext *pCtx,
456 IWbemObjectSink *pResponseHandler )
458 FIXME("\n");
459 return WBEM_E_FAILED;
462 static HRESULT WINAPI wbem_services_DeleteInstance(
463 IWbemServices *iface,
464 const BSTR strObjectPath,
465 LONG lFlags,
466 IWbemContext *pCtx,
467 IWbemCallResult **ppCallResult )
469 FIXME("\n");
470 return WBEM_E_FAILED;
473 static HRESULT WINAPI wbem_services_DeleteInstanceAsync(
474 IWbemServices *iface,
475 const BSTR strObjectPath,
476 LONG lFlags,
477 IWbemContext *pCtx,
478 IWbemObjectSink *pResponseHandler )
480 FIXME("\n");
481 return WBEM_E_FAILED;
484 static HRESULT WINAPI wbem_services_CreateInstanceEnum(
485 IWbemServices *iface,
486 const BSTR strClass,
487 LONG lFlags,
488 IWbemContext *pCtx,
489 IEnumWbemClassObject **ppEnum )
491 struct path *path;
492 HRESULT hr;
494 TRACE("%p, %s, 0%08x, %p, %p\n", iface, debugstr_w(strClass), lFlags, pCtx, ppEnum);
496 if (lFlags) FIXME("unsupported flags 0x%08x\n", lFlags);
498 hr = parse_path( strClass, &path );
499 if (hr != S_OK) return hr;
501 hr = create_instance_enum( path, ppEnum );
502 free_path( path );
503 return hr;
506 static HRESULT WINAPI wbem_services_CreateInstanceEnumAsync(
507 IWbemServices *iface,
508 const BSTR strFilter,
509 LONG lFlags,
510 IWbemContext *pCtx,
511 IWbemObjectSink *pResponseHandler )
513 FIXME("\n");
514 return WBEM_E_FAILED;
517 static HRESULT WINAPI wbem_services_ExecQuery(
518 IWbemServices *iface,
519 const BSTR strQueryLanguage,
520 const BSTR strQuery,
521 LONG lFlags,
522 IWbemContext *pCtx,
523 IEnumWbemClassObject **ppEnum )
525 static const WCHAR wqlW[] = {'W','Q','L',0};
527 TRACE("%p, %s, %s, 0x%08x, %p, %p\n", iface, debugstr_w(strQueryLanguage),
528 debugstr_w(strQuery), lFlags, pCtx, ppEnum);
530 if (!strQueryLanguage || !strQuery) return WBEM_E_INVALID_PARAMETER;
531 if (strcmpiW( strQueryLanguage, wqlW )) return WBEM_E_INVALID_QUERY_TYPE;
532 return exec_query( strQuery, ppEnum );
535 static HRESULT WINAPI wbem_services_ExecQueryAsync(
536 IWbemServices *iface,
537 const BSTR strQueryLanguage,
538 const BSTR strQuery,
539 LONG lFlags,
540 IWbemContext *pCtx,
541 IWbemObjectSink *pResponseHandler )
543 FIXME("\n");
544 return WBEM_E_FAILED;
547 static HRESULT WINAPI wbem_services_ExecNotificationQuery(
548 IWbemServices *iface,
549 const BSTR strQueryLanguage,
550 const BSTR strQuery,
551 LONG lFlags,
552 IWbemContext *pCtx,
553 IEnumWbemClassObject **ppEnum )
555 FIXME("\n");
556 return WBEM_E_FAILED;
559 static HRESULT WINAPI wbem_services_ExecNotificationQueryAsync(
560 IWbemServices *iface,
561 const BSTR strQueryLanguage,
562 const BSTR strQuery,
563 LONG lFlags,
564 IWbemContext *pCtx,
565 IWbemObjectSink *pResponseHandler )
567 FIXME("\n");
568 return WBEM_E_FAILED;
571 static HRESULT WINAPI wbem_services_ExecMethod(
572 IWbemServices *iface,
573 const BSTR strObjectPath,
574 const BSTR strMethodName,
575 LONG lFlags,
576 IWbemContext *pCtx,
577 IWbemClassObject *pInParams,
578 IWbemClassObject **ppOutParams,
579 IWbemCallResult **ppCallResult )
581 IWbemClassObject *obj;
582 struct table *table;
583 class_method *func;
584 struct path *path;
585 HRESULT hr;
587 TRACE("%p, %s, %s, %08x, %p, %p, %p, %p\n", iface, debugstr_w(strObjectPath),
588 debugstr_w(strMethodName), lFlags, pCtx, pInParams, ppOutParams, ppCallResult);
590 if (lFlags) FIXME("flags %08x not supported\n", lFlags);
592 if ((hr = get_object( strObjectPath, &obj ))) return hr;
593 if ((hr = parse_path( strObjectPath, &path )) != S_OK)
595 IWbemClassObject_Release( obj );
596 return hr;
598 table = grab_table( path->class );
599 free_path( path );
600 if (!table)
602 IWbemClassObject_Release( obj );
603 return WBEM_E_NOT_FOUND;
605 hr = get_method( table, strMethodName, &func );
606 release_table( table );
607 if (hr != S_OK)
609 IWbemClassObject_Release( obj );
610 return hr;
612 hr = func( obj, pInParams, ppOutParams );
613 IWbemClassObject_Release( obj );
614 return hr;
617 static HRESULT WINAPI wbem_services_ExecMethodAsync(
618 IWbemServices *iface,
619 const BSTR strObjectPath,
620 const BSTR strMethodName,
621 LONG lFlags,
622 IWbemContext *pCtx,
623 IWbemClassObject *pInParams,
624 IWbemObjectSink *pResponseHandler )
626 FIXME("\n");
627 return WBEM_E_FAILED;
630 static const IWbemServicesVtbl wbem_services_vtbl =
632 wbem_services_QueryInterface,
633 wbem_services_AddRef,
634 wbem_services_Release,
635 wbem_services_OpenNamespace,
636 wbem_services_CancelAsyncCall,
637 wbem_services_QueryObjectSink,
638 wbem_services_GetObject,
639 wbem_services_GetObjectAsync,
640 wbem_services_PutClass,
641 wbem_services_PutClassAsync,
642 wbem_services_DeleteClass,
643 wbem_services_DeleteClassAsync,
644 wbem_services_CreateClassEnum,
645 wbem_services_CreateClassEnumAsync,
646 wbem_services_PutInstance,
647 wbem_services_PutInstanceAsync,
648 wbem_services_DeleteInstance,
649 wbem_services_DeleteInstanceAsync,
650 wbem_services_CreateInstanceEnum,
651 wbem_services_CreateInstanceEnumAsync,
652 wbem_services_ExecQuery,
653 wbem_services_ExecQueryAsync,
654 wbem_services_ExecNotificationQuery,
655 wbem_services_ExecNotificationQueryAsync,
656 wbem_services_ExecMethod,
657 wbem_services_ExecMethodAsync
660 HRESULT WbemServices_create( IUnknown *pUnkOuter, const WCHAR *namespace, LPVOID *ppObj )
662 struct wbem_services *ws;
664 TRACE("(%p,%p)\n", pUnkOuter, ppObj);
666 ws = heap_alloc( sizeof(*ws) );
667 if (!ws) return E_OUTOFMEMORY;
669 ws->IWbemServices_iface.lpVtbl = &wbem_services_vtbl;
670 ws->refs = 1;
671 ws->namespace = heap_strdupW( namespace );
673 *ppObj = &ws->IWbemServices_iface;
675 TRACE("returning iface %p\n", *ppObj);
676 return S_OK;