wined3d: Correctly destroy the adapter on format initialization failure in no3d mode.
[wine/zf.git] / dlls / wbemprox / services.c
blobe2b452e217eae283eea0076e4991721e41581fde
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 <stdarg.h>
23 #include "windef.h"
24 #include "winbase.h"
25 #include "objbase.h"
26 #include "wbemcli.h"
28 #include "wine/debug.h"
29 #include "wbemprox_private.h"
31 WINE_DEFAULT_DEBUG_CHANNEL(wbemprox);
33 struct client_security
35 IClientSecurity IClientSecurity_iface;
38 static inline struct client_security *impl_from_IClientSecurity( IClientSecurity *iface )
40 return CONTAINING_RECORD( iface, struct client_security, IClientSecurity_iface );
43 static HRESULT WINAPI client_security_QueryInterface(
44 IClientSecurity *iface,
45 REFIID riid,
46 void **ppvObject )
48 struct client_security *cs = impl_from_IClientSecurity( iface );
50 TRACE("%p %s %p\n", cs, debugstr_guid( riid ), ppvObject );
52 if ( IsEqualGUID( riid, &IID_IClientSecurity ) ||
53 IsEqualGUID( riid, &IID_IUnknown ) )
55 *ppvObject = cs;
57 else
59 FIXME("interface %s not implemented\n", debugstr_guid(riid));
60 return E_NOINTERFACE;
62 IClientSecurity_AddRef( iface );
63 return S_OK;
66 static ULONG WINAPI client_security_AddRef(
67 IClientSecurity *iface )
69 FIXME("%p\n", iface);
70 return 2;
73 static ULONG WINAPI client_security_Release(
74 IClientSecurity *iface )
76 FIXME("%p\n", iface);
77 return 1;
80 static HRESULT WINAPI client_security_QueryBlanket(
81 IClientSecurity *iface,
82 IUnknown *pProxy,
83 DWORD *pAuthnSvc,
84 DWORD *pAuthzSvc,
85 OLECHAR **pServerPrincName,
86 DWORD *pAuthnLevel,
87 DWORD *pImpLevel,
88 void **pAuthInfo,
89 DWORD *pCapabilities )
91 FIXME("\n");
92 return WBEM_E_FAILED;
95 static HRESULT WINAPI client_security_SetBlanket(
96 IClientSecurity *iface,
97 IUnknown *pProxy,
98 DWORD AuthnSvc,
99 DWORD AuthzSvc,
100 OLECHAR *pServerPrincName,
101 DWORD AuthnLevel,
102 DWORD ImpLevel,
103 void *pAuthInfo,
104 DWORD Capabilities )
106 const OLECHAR *princname = (pServerPrincName == COLE_DEFAULT_PRINCIPAL) ?
107 L"<COLE_DEFAULT_PRINCIPAL>" : pServerPrincName;
109 FIXME("%p, %p, %u, %u, %s, %u, %u, %p, 0x%08x\n", iface, pProxy, AuthnSvc, AuthzSvc,
110 debugstr_w(princname), AuthnLevel, ImpLevel, pAuthInfo, Capabilities);
111 return WBEM_NO_ERROR;
114 static HRESULT WINAPI client_security_CopyProxy(
115 IClientSecurity *iface,
116 IUnknown *pProxy,
117 IUnknown **ppCopy )
119 FIXME("\n");
120 return WBEM_E_FAILED;
123 static const IClientSecurityVtbl client_security_vtbl =
125 client_security_QueryInterface,
126 client_security_AddRef,
127 client_security_Release,
128 client_security_QueryBlanket,
129 client_security_SetBlanket,
130 client_security_CopyProxy
133 IClientSecurity client_security = { &client_security_vtbl };
135 struct async_header
137 IWbemObjectSink *sink;
138 void (*proc)( struct async_header * );
139 HANDLE cancel;
140 HANDLE wait;
143 struct async_query
145 struct async_header hdr;
146 WCHAR *str;
149 static void free_async( struct async_header *async )
151 if (async->sink) IWbemObjectSink_Release( async->sink );
152 CloseHandle( async->cancel );
153 CloseHandle( async->wait );
154 heap_free( async );
157 static BOOL init_async( struct async_header *async, IWbemObjectSink *sink,
158 void (*proc)(struct async_header *) )
160 if (!(async->wait = CreateEventW( NULL, FALSE, FALSE, NULL ))) return FALSE;
161 if (!(async->cancel = CreateEventW( NULL, FALSE, FALSE, NULL )))
163 CloseHandle( async->wait );
164 return FALSE;
166 async->proc = proc;
167 async->sink = sink;
168 IWbemObjectSink_AddRef( sink );
169 return TRUE;
172 static DWORD CALLBACK async_proc( LPVOID param )
174 struct async_header *async = param;
175 HANDLE wait = async->wait;
177 async->proc( async );
179 WaitForSingleObject( async->cancel, INFINITE );
180 SetEvent( wait );
181 return ERROR_SUCCESS;
184 static HRESULT queue_async( struct async_header *async )
186 if (QueueUserWorkItem( async_proc, async, WT_EXECUTELONGFUNCTION )) return S_OK;
187 return HRESULT_FROM_WIN32( GetLastError() );
190 struct wbem_services
192 IWbemServices IWbemServices_iface;
193 LONG refs;
194 CRITICAL_SECTION cs;
195 WCHAR *namespace;
196 struct async_header *async;
199 static inline struct wbem_services *impl_from_IWbemServices( IWbemServices *iface )
201 return CONTAINING_RECORD( iface, struct wbem_services, IWbemServices_iface );
204 static ULONG WINAPI wbem_services_AddRef(
205 IWbemServices *iface )
207 struct wbem_services *ws = impl_from_IWbemServices( iface );
208 return InterlockedIncrement( &ws->refs );
211 static ULONG WINAPI wbem_services_Release(
212 IWbemServices *iface )
214 struct wbem_services *ws = impl_from_IWbemServices( iface );
215 LONG refs = InterlockedDecrement( &ws->refs );
216 if (!refs)
218 TRACE("destroying %p\n", ws);
220 EnterCriticalSection( &ws->cs );
221 if (ws->async) SetEvent( ws->async->cancel );
222 LeaveCriticalSection( &ws->cs );
223 if (ws->async)
225 WaitForSingleObject( ws->async->wait, INFINITE );
226 free_async( ws->async );
228 ws->cs.DebugInfo->Spare[0] = 0;
229 DeleteCriticalSection( &ws->cs );
230 heap_free( ws->namespace );
231 heap_free( ws );
233 return refs;
236 static HRESULT WINAPI wbem_services_QueryInterface(
237 IWbemServices *iface,
238 REFIID riid,
239 void **ppvObject )
241 struct wbem_services *ws = impl_from_IWbemServices( iface );
243 TRACE("%p %s %p\n", ws, debugstr_guid( riid ), ppvObject );
245 if ( IsEqualGUID( riid, &IID_IWbemServices ) ||
246 IsEqualGUID( riid, &IID_IUnknown ) )
248 *ppvObject = ws;
250 else if ( IsEqualGUID( riid, &IID_IClientSecurity ) )
252 *ppvObject = &client_security;
253 return S_OK;
255 else
257 FIXME("interface %s not implemented\n", debugstr_guid(riid));
258 return E_NOINTERFACE;
260 IWbemServices_AddRef( iface );
261 return S_OK;
264 static HRESULT WINAPI wbem_services_OpenNamespace(
265 IWbemServices *iface,
266 const BSTR strNamespace,
267 LONG lFlags,
268 IWbemContext *pCtx,
269 IWbemServices **ppWorkingNamespace,
270 IWbemCallResult **ppResult )
272 struct wbem_services *ws = impl_from_IWbemServices( iface );
274 TRACE("%p, %s, 0x%08x, %p, %p, %p\n", iface, debugstr_w(strNamespace), lFlags,
275 pCtx, ppWorkingNamespace, ppResult);
277 if ((wcsicmp( strNamespace, L"cimv2" ) && wcsicmp( strNamespace, L"default" )) || ws->namespace)
278 return WBEM_E_INVALID_NAMESPACE;
280 return WbemServices_create( L"cimv2", (void **)ppWorkingNamespace );
283 static HRESULT WINAPI wbem_services_CancelAsyncCall(
284 IWbemServices *iface,
285 IWbemObjectSink *pSink )
287 struct wbem_services *services = impl_from_IWbemServices( iface );
288 struct async_header *async;
290 TRACE("%p, %p\n", iface, pSink);
292 if (!pSink) return WBEM_E_INVALID_PARAMETER;
294 EnterCriticalSection( &services->cs );
296 if (!(async = services->async))
298 LeaveCriticalSection( &services->cs );
299 return WBEM_E_INVALID_PARAMETER;
301 services->async = NULL;
302 SetEvent( async->cancel );
304 LeaveCriticalSection( &services->cs );
306 WaitForSingleObject( async->wait, INFINITE );
307 free_async( async );
308 return S_OK;
311 static HRESULT WINAPI wbem_services_QueryObjectSink(
312 IWbemServices *iface,
313 LONG lFlags,
314 IWbemObjectSink **ppResponseHandler )
316 FIXME("\n");
317 return WBEM_E_FAILED;
320 HRESULT parse_path( const WCHAR *str, struct path **ret )
322 struct path *path;
323 const WCHAR *p = str, *q;
324 UINT len;
326 if (!(path = heap_alloc_zero( sizeof(*path) ))) return E_OUTOFMEMORY;
328 if (*p == '\\')
330 static const WCHAR cimv2W[] = L"ROOT\\CIMV2";
331 WCHAR server[MAX_COMPUTERNAME_LENGTH+1];
332 DWORD server_len = ARRAY_SIZE(server);
334 p++;
335 if (*p != '\\')
337 heap_free( path );
338 return WBEM_E_INVALID_OBJECT_PATH;
340 p++;
342 q = p;
343 while (*p && *p != '\\') p++;
344 if (!*p)
346 heap_free( path );
347 return WBEM_E_INVALID_OBJECT_PATH;
350 len = p - q;
351 if (!GetComputerNameW( server, &server_len ) || server_len != len || wcsnicmp( q, server, server_len ))
353 heap_free( path );
354 return WBEM_E_NOT_SUPPORTED;
357 q = ++p;
358 while (*p && *p != ':') p++;
359 if (!*p)
361 heap_free( path );
362 return WBEM_E_INVALID_OBJECT_PATH;
365 len = p - q;
366 if (len != ARRAY_SIZE(cimv2W) - 1 || wcsnicmp( q, cimv2W, ARRAY_SIZE(cimv2W) - 1 ))
368 heap_free( path );
369 return WBEM_E_INVALID_NAMESPACE;
371 p++;
374 q = p;
375 while (*p && *p != '.') p++;
377 len = p - q;
378 if (!(path->class = heap_alloc( (len + 1) * sizeof(WCHAR) )))
380 heap_free( path );
381 return E_OUTOFMEMORY;
383 memcpy( path->class, q, len * sizeof(WCHAR) );
384 path->class[len] = 0;
385 path->class_len = len;
387 if (p[0] == '.' && p[1])
389 q = ++p;
390 while (*q) q++;
392 len = q - p;
393 if (!(path->filter = heap_alloc( (len + 1) * sizeof(WCHAR) )))
395 heap_free( path->class );
396 heap_free( path );
397 return E_OUTOFMEMORY;
399 memcpy( path->filter, p, len * sizeof(WCHAR) );
400 path->filter[len] = 0;
401 path->filter_len = len;
403 *ret = path;
404 return S_OK;
407 void free_path( struct path *path )
409 if (!path) return;
410 heap_free( path->class );
411 heap_free( path->filter );
412 heap_free( path );
415 WCHAR *query_from_path( const struct path *path )
417 static const WCHAR selectW[] = L"SELECT * FROM %s WHERE %s";
418 static const WCHAR select_allW[] = L"SELECT * FROM ";
419 WCHAR *query;
420 UINT len;
422 if (path->filter)
424 len = path->class_len + path->filter_len + ARRAY_SIZE(selectW);
425 if (!(query = heap_alloc( len * sizeof(WCHAR) ))) return NULL;
426 swprintf( query, len, selectW, path->class, path->filter );
428 else
430 len = path->class_len + ARRAY_SIZE(select_allW);
431 if (!(query = heap_alloc( len * sizeof(WCHAR) ))) return NULL;
432 lstrcpyW( query, select_allW );
433 lstrcatW( query, path->class );
435 return query;
438 static HRESULT create_instance_enum( const struct path *path, IEnumWbemClassObject **iter )
440 WCHAR *query;
441 HRESULT hr;
443 if (!(query = query_from_path( path ))) return E_OUTOFMEMORY;
444 hr = exec_query( query, iter );
445 heap_free( query );
446 return hr;
449 HRESULT get_object( const WCHAR *object_path, IWbemClassObject **obj )
451 IEnumWbemClassObject *iter;
452 struct path *path;
453 HRESULT hr;
455 hr = parse_path( object_path, &path );
456 if (hr != S_OK) return hr;
458 hr = create_instance_enum( path, &iter );
459 if (hr != S_OK)
461 free_path( path );
462 return hr;
464 hr = create_class_object( path->class, iter, 0, NULL, obj );
465 IEnumWbemClassObject_Release( iter );
466 free_path( path );
467 return hr;
470 static HRESULT WINAPI wbem_services_GetObject(
471 IWbemServices *iface,
472 const BSTR strObjectPath,
473 LONG lFlags,
474 IWbemContext *pCtx,
475 IWbemClassObject **ppObject,
476 IWbemCallResult **ppCallResult )
478 TRACE("%p, %s, 0x%08x, %p, %p, %p\n", iface, debugstr_w(strObjectPath), lFlags,
479 pCtx, ppObject, ppCallResult);
481 if (lFlags) FIXME("unsupported flags 0x%08x\n", lFlags);
483 if (!strObjectPath || !strObjectPath[0])
484 return create_class_object( NULL, NULL, 0, NULL, ppObject );
486 return get_object( strObjectPath, ppObject );
489 static HRESULT WINAPI wbem_services_GetObjectAsync(
490 IWbemServices *iface,
491 const BSTR strObjectPath,
492 LONG lFlags,
493 IWbemContext *pCtx,
494 IWbemObjectSink *pResponseHandler )
496 FIXME("\n");
497 return WBEM_E_FAILED;
500 static HRESULT WINAPI wbem_services_PutClass(
501 IWbemServices *iface,
502 IWbemClassObject *pObject,
503 LONG lFlags,
504 IWbemContext *pCtx,
505 IWbemCallResult **ppCallResult )
507 FIXME("\n");
508 return WBEM_E_FAILED;
511 static HRESULT WINAPI wbem_services_PutClassAsync(
512 IWbemServices *iface,
513 IWbemClassObject *pObject,
514 LONG lFlags,
515 IWbemContext *pCtx,
516 IWbemObjectSink *pResponseHandler )
518 FIXME("\n");
519 return WBEM_E_FAILED;
522 static HRESULT WINAPI wbem_services_DeleteClass(
523 IWbemServices *iface,
524 const BSTR strClass,
525 LONG lFlags,
526 IWbemContext *pCtx,
527 IWbemCallResult **ppCallResult )
529 FIXME("\n");
530 return WBEM_E_FAILED;
533 static HRESULT WINAPI wbem_services_DeleteClassAsync(
534 IWbemServices *iface,
535 const BSTR strClass,
536 LONG lFlags,
537 IWbemContext *pCtx,
538 IWbemObjectSink *pResponseHandler )
540 FIXME("\n");
541 return WBEM_E_FAILED;
544 static HRESULT WINAPI wbem_services_CreateClassEnum(
545 IWbemServices *iface,
546 const BSTR strSuperclass,
547 LONG lFlags,
548 IWbemContext *pCtx,
549 IEnumWbemClassObject **ppEnum )
551 FIXME("\n");
552 return WBEM_E_FAILED;
555 static HRESULT WINAPI wbem_services_CreateClassEnumAsync(
556 IWbemServices *iface,
557 const BSTR strSuperclass,
558 LONG lFlags,
559 IWbemContext *pCtx,
560 IWbemObjectSink *pResponseHandler )
562 FIXME("\n");
563 return WBEM_E_FAILED;
566 static HRESULT WINAPI wbem_services_PutInstance(
567 IWbemServices *iface,
568 IWbemClassObject *pInst,
569 LONG lFlags,
570 IWbemContext *pCtx,
571 IWbemCallResult **ppCallResult )
573 FIXME("\n");
574 return WBEM_E_FAILED;
577 static HRESULT WINAPI wbem_services_PutInstanceAsync(
578 IWbemServices *iface,
579 IWbemClassObject *pInst,
580 LONG lFlags,
581 IWbemContext *pCtx,
582 IWbemObjectSink *pResponseHandler )
584 FIXME("\n");
585 return WBEM_E_FAILED;
588 static HRESULT WINAPI wbem_services_DeleteInstance(
589 IWbemServices *iface,
590 const BSTR strObjectPath,
591 LONG lFlags,
592 IWbemContext *pCtx,
593 IWbemCallResult **ppCallResult )
595 FIXME("\n");
596 return WBEM_E_FAILED;
599 static HRESULT WINAPI wbem_services_DeleteInstanceAsync(
600 IWbemServices *iface,
601 const BSTR strObjectPath,
602 LONG lFlags,
603 IWbemContext *pCtx,
604 IWbemObjectSink *pResponseHandler )
606 FIXME("\n");
607 return WBEM_E_FAILED;
610 static HRESULT WINAPI wbem_services_CreateInstanceEnum(
611 IWbemServices *iface,
612 const BSTR strClass,
613 LONG lFlags,
614 IWbemContext *pCtx,
615 IEnumWbemClassObject **ppEnum )
617 struct path *path;
618 HRESULT hr;
620 TRACE("%p, %s, 0%08x, %p, %p\n", iface, debugstr_w(strClass), lFlags, pCtx, ppEnum);
622 if (lFlags) FIXME("unsupported flags 0x%08x\n", lFlags);
624 hr = parse_path( strClass, &path );
625 if (hr != S_OK) return hr;
627 hr = create_instance_enum( path, ppEnum );
628 free_path( path );
629 return hr;
632 static HRESULT WINAPI wbem_services_CreateInstanceEnumAsync(
633 IWbemServices *iface,
634 const BSTR strFilter,
635 LONG lFlags,
636 IWbemContext *pCtx,
637 IWbemObjectSink *pResponseHandler )
639 FIXME("\n");
640 return WBEM_E_FAILED;
643 static HRESULT WINAPI wbem_services_ExecQuery(
644 IWbemServices *iface,
645 const BSTR strQueryLanguage,
646 const BSTR strQuery,
647 LONG lFlags,
648 IWbemContext *pCtx,
649 IEnumWbemClassObject **ppEnum )
651 TRACE("%p, %s, %s, 0x%08x, %p, %p\n", iface, debugstr_w(strQueryLanguage),
652 debugstr_w(strQuery), lFlags, pCtx, ppEnum);
654 if (!strQueryLanguage || !strQuery || !strQuery[0]) return WBEM_E_INVALID_PARAMETER;
655 if (wcsicmp( strQueryLanguage, L"WQL" )) return WBEM_E_INVALID_QUERY_TYPE;
656 return exec_query( strQuery, ppEnum );
659 static void async_exec_query( struct async_header *hdr )
661 struct async_query *query = (struct async_query *)hdr;
662 IEnumWbemClassObject *result;
663 IWbemClassObject *obj;
664 ULONG count;
665 HRESULT hr;
667 hr = exec_query( query->str, &result );
668 if (hr == S_OK)
670 for (;;)
672 IEnumWbemClassObject_Next( result, WBEM_INFINITE, 1, &obj, &count );
673 if (!count) break;
674 IWbemObjectSink_Indicate( query->hdr.sink, 1, &obj );
675 IWbemClassObject_Release( obj );
677 IEnumWbemClassObject_Release( result );
679 IWbemObjectSink_SetStatus( query->hdr.sink, WBEM_STATUS_COMPLETE, hr, NULL, NULL );
680 heap_free( query->str );
683 static HRESULT WINAPI wbem_services_ExecQueryAsync(
684 IWbemServices *iface,
685 const BSTR strQueryLanguage,
686 const BSTR strQuery,
687 LONG lFlags,
688 IWbemContext *pCtx,
689 IWbemObjectSink *pResponseHandler )
691 struct wbem_services *services = impl_from_IWbemServices( iface );
692 IWbemObjectSink *sink;
693 HRESULT hr = E_OUTOFMEMORY;
694 struct async_header *async;
695 struct async_query *query;
697 TRACE("%p, %s, %s, 0x%08x, %p, %p\n", iface, debugstr_w(strQueryLanguage), debugstr_w(strQuery),
698 lFlags, pCtx, pResponseHandler);
700 if (!pResponseHandler) return WBEM_E_INVALID_PARAMETER;
702 hr = IWbemObjectSink_QueryInterface( pResponseHandler, &IID_IWbemObjectSink, (void **)&sink );
703 if (FAILED(hr)) return hr;
705 EnterCriticalSection( &services->cs );
707 if (services->async)
709 FIXME("handle more than one pending async\n");
710 hr = WBEM_E_FAILED;
711 goto done;
713 if (!(query = heap_alloc_zero( sizeof(*query) ))) goto done;
714 async = (struct async_header *)query;
716 if (!(init_async( async, sink, async_exec_query )))
718 free_async( async );
719 goto done;
721 if (!(query->str = heap_strdupW( strQuery )))
723 free_async( async );
724 goto done;
726 hr = queue_async( async );
727 if (hr == S_OK) services->async = async;
728 else
730 heap_free( query->str );
731 free_async( async );
734 done:
735 LeaveCriticalSection( &services->cs );
736 IWbemObjectSink_Release( sink );
737 return hr;
740 static HRESULT WINAPI wbem_services_ExecNotificationQuery(
741 IWbemServices *iface,
742 const BSTR strQueryLanguage,
743 const BSTR strQuery,
744 LONG lFlags,
745 IWbemContext *pCtx,
746 IEnumWbemClassObject **ppEnum )
748 FIXME("\n");
749 return WBEM_E_FAILED;
752 static HRESULT WINAPI wbem_services_ExecNotificationQueryAsync(
753 IWbemServices *iface,
754 const BSTR strQueryLanguage,
755 const BSTR strQuery,
756 LONG lFlags,
757 IWbemContext *pCtx,
758 IWbemObjectSink *pResponseHandler )
760 struct wbem_services *services = impl_from_IWbemServices( iface );
761 IWbemObjectSink *sink;
762 HRESULT hr = E_OUTOFMEMORY;
763 struct async_header *async;
764 struct async_query *query;
766 TRACE("%p, %s, %s, 0x%08x, %p, %p\n", iface, debugstr_w(strQueryLanguage), debugstr_w(strQuery),
767 lFlags, pCtx, pResponseHandler);
769 if (!pResponseHandler) return WBEM_E_INVALID_PARAMETER;
771 hr = IWbemObjectSink_QueryInterface( pResponseHandler, &IID_IWbemObjectSink, (void **)&sink );
772 if (FAILED(hr)) return hr;
774 EnterCriticalSection( &services->cs );
776 if (services->async)
778 FIXME("handle more than one pending async\n");
779 hr = WBEM_E_FAILED;
780 goto done;
782 if (!(query = heap_alloc_zero( sizeof(*query) ))) goto done;
783 async = (struct async_header *)query;
785 if (!(init_async( async, sink, async_exec_query )))
787 free_async( async );
788 goto done;
790 if (!(query->str = heap_strdupW( strQuery )))
792 free_async( async );
793 goto done;
795 hr = queue_async( async );
796 if (hr == S_OK) services->async = async;
797 else
799 heap_free( query->str );
800 free_async( async );
803 done:
804 LeaveCriticalSection( &services->cs );
805 IWbemObjectSink_Release( sink );
806 return hr;
809 static HRESULT WINAPI wbem_services_ExecMethod(
810 IWbemServices *iface,
811 const BSTR strObjectPath,
812 const BSTR strMethodName,
813 LONG lFlags,
814 IWbemContext *pCtx,
815 IWbemClassObject *pInParams,
816 IWbemClassObject **ppOutParams,
817 IWbemCallResult **ppCallResult )
819 IEnumWbemClassObject *result = NULL;
820 IWbemClassObject *obj = NULL;
821 struct query *query = NULL;
822 struct path *path;
823 WCHAR *str;
824 class_method *func;
825 struct table *table;
826 HRESULT hr;
828 TRACE("%p, %s, %s, %08x, %p, %p, %p, %p\n", iface, debugstr_w(strObjectPath),
829 debugstr_w(strMethodName), lFlags, pCtx, pInParams, ppOutParams, ppCallResult);
831 if (lFlags) FIXME("flags %08x not supported\n", lFlags);
833 if ((hr = parse_path( strObjectPath, &path )) != S_OK) return hr;
834 if (!(str = query_from_path( path )))
836 hr = E_OUTOFMEMORY;
837 goto done;
839 if (!(query = create_query()))
841 hr = E_OUTOFMEMORY;
842 goto done;
844 hr = parse_query( str, &query->view, &query->mem );
845 if (hr != S_OK) goto done;
847 hr = execute_view( query->view );
848 if (hr != S_OK) goto done;
850 hr = EnumWbemClassObject_create( query, (void **)&result );
851 if (hr != S_OK) goto done;
853 table = get_view_table( query->view, 0 );
854 hr = create_class_object( table->name, result, 0, NULL, &obj );
855 if (hr != S_OK) goto done;
857 hr = get_method( table, strMethodName, &func );
858 if (hr != S_OK) goto done;
860 hr = func( obj, pInParams, ppOutParams );
862 done:
863 if (result) IEnumWbemClassObject_Release( result );
864 if (obj) IWbemClassObject_Release( obj );
865 free_query( query );
866 free_path( path );
867 heap_free( str );
868 return hr;
871 static HRESULT WINAPI wbem_services_ExecMethodAsync(
872 IWbemServices *iface,
873 const BSTR strObjectPath,
874 const BSTR strMethodName,
875 LONG lFlags,
876 IWbemContext *pCtx,
877 IWbemClassObject *pInParams,
878 IWbemObjectSink *pResponseHandler )
880 FIXME("\n");
881 return WBEM_E_FAILED;
884 static const IWbemServicesVtbl wbem_services_vtbl =
886 wbem_services_QueryInterface,
887 wbem_services_AddRef,
888 wbem_services_Release,
889 wbem_services_OpenNamespace,
890 wbem_services_CancelAsyncCall,
891 wbem_services_QueryObjectSink,
892 wbem_services_GetObject,
893 wbem_services_GetObjectAsync,
894 wbem_services_PutClass,
895 wbem_services_PutClassAsync,
896 wbem_services_DeleteClass,
897 wbem_services_DeleteClassAsync,
898 wbem_services_CreateClassEnum,
899 wbem_services_CreateClassEnumAsync,
900 wbem_services_PutInstance,
901 wbem_services_PutInstanceAsync,
902 wbem_services_DeleteInstance,
903 wbem_services_DeleteInstanceAsync,
904 wbem_services_CreateInstanceEnum,
905 wbem_services_CreateInstanceEnumAsync,
906 wbem_services_ExecQuery,
907 wbem_services_ExecQueryAsync,
908 wbem_services_ExecNotificationQuery,
909 wbem_services_ExecNotificationQueryAsync,
910 wbem_services_ExecMethod,
911 wbem_services_ExecMethodAsync
914 HRESULT WbemServices_create( const WCHAR *namespace, LPVOID *ppObj )
916 struct wbem_services *ws;
918 TRACE("(%p)\n", ppObj);
920 ws = heap_alloc( sizeof(*ws) );
921 if (!ws) return E_OUTOFMEMORY;
923 ws->IWbemServices_iface.lpVtbl = &wbem_services_vtbl;
924 ws->refs = 1;
925 ws->namespace = heap_strdupW( namespace );
926 ws->async = NULL;
927 InitializeCriticalSection( &ws->cs );
928 ws->cs.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": wbemprox_services.cs");
930 *ppObj = &ws->IWbemServices_iface;
932 TRACE("returning iface %p\n", *ppObj);
933 return S_OK;