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
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
,
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
) )
59 FIXME("interface %s not implemented\n", debugstr_guid(riid
));
62 IClientSecurity_AddRef( iface
);
66 static ULONG WINAPI
client_security_AddRef(
67 IClientSecurity
*iface
)
73 static ULONG WINAPI
client_security_Release(
74 IClientSecurity
*iface
)
80 static HRESULT WINAPI
client_security_QueryBlanket(
81 IClientSecurity
*iface
,
85 OLECHAR
**pServerPrincName
,
89 DWORD
*pCapabilities
)
91 FIXME("semi-stub.\n");
94 *pAuthnSvc
= RPC_C_AUTHN_NONE
;
96 *pAuthzSvc
= RPC_C_AUTHZ_NONE
;
98 *pServerPrincName
= NULL
;
100 *pAuthnLevel
= RPC_C_AUTHN_LEVEL_NONE
;
102 *pImpLevel
= RPC_C_IMP_LEVEL_DEFAULT
;
108 return WBEM_NO_ERROR
;
111 static HRESULT WINAPI
client_security_SetBlanket(
112 IClientSecurity
*iface
,
116 OLECHAR
*pServerPrincName
,
122 const OLECHAR
*princname
= (pServerPrincName
== COLE_DEFAULT_PRINCIPAL
) ?
123 L
"<COLE_DEFAULT_PRINCIPAL>" : pServerPrincName
;
125 FIXME( "%p, %p, %lu, %lu, %s, %lu, %lu, %p, %#lx\n", iface
, pProxy
, AuthnSvc
, AuthzSvc
,
126 debugstr_w(princname
), AuthnLevel
, ImpLevel
, pAuthInfo
, Capabilities
);
127 return WBEM_NO_ERROR
;
130 static HRESULT WINAPI
client_security_CopyProxy(
131 IClientSecurity
*iface
,
136 return WBEM_E_FAILED
;
139 static const IClientSecurityVtbl client_security_vtbl
=
141 client_security_QueryInterface
,
142 client_security_AddRef
,
143 client_security_Release
,
144 client_security_QueryBlanket
,
145 client_security_SetBlanket
,
146 client_security_CopyProxy
149 IClientSecurity client_security
= { &client_security_vtbl
};
153 IWbemObjectSink
*sink
;
154 void (*proc
)( struct async_header
* );
161 struct async_header hdr
;
162 enum wbm_namespace ns
;
166 static void free_async( struct async_header
*async
)
168 if (async
->sink
) IWbemObjectSink_Release( async
->sink
);
169 CloseHandle( async
->cancel
);
170 CloseHandle( async
->wait
);
174 static BOOL
init_async( struct async_header
*async
, IWbemObjectSink
*sink
,
175 void (*proc
)(struct async_header
*) )
177 if (!(async
->wait
= CreateEventW( NULL
, FALSE
, FALSE
, NULL
))) return FALSE
;
178 if (!(async
->cancel
= CreateEventW( NULL
, FALSE
, FALSE
, NULL
)))
180 CloseHandle( async
->wait
);
185 IWbemObjectSink_AddRef( sink
);
189 static DWORD CALLBACK
async_proc( LPVOID param
)
191 struct async_header
*async
= param
;
192 HANDLE wait
= async
->wait
;
194 async
->proc( async
);
196 WaitForSingleObject( async
->cancel
, INFINITE
);
198 return ERROR_SUCCESS
;
201 static HRESULT
queue_async( struct async_header
*async
)
203 if (QueueUserWorkItem( async_proc
, async
, WT_EXECUTELONGFUNCTION
)) return S_OK
;
204 return HRESULT_FROM_WIN32( GetLastError() );
209 IWbemServices IWbemServices_iface
;
212 enum wbm_namespace ns
;
213 struct async_header
*async
;
214 IWbemContext
*context
;
217 static inline struct wbem_services
*impl_from_IWbemServices( IWbemServices
*iface
)
219 return CONTAINING_RECORD( iface
, struct wbem_services
, IWbemServices_iface
);
222 static ULONG WINAPI
wbem_services_AddRef(
223 IWbemServices
*iface
)
225 struct wbem_services
*ws
= impl_from_IWbemServices( iface
);
226 return InterlockedIncrement( &ws
->refs
);
229 static ULONG WINAPI
wbem_services_Release(
230 IWbemServices
*iface
)
232 struct wbem_services
*ws
= impl_from_IWbemServices( iface
);
233 LONG refs
= InterlockedDecrement( &ws
->refs
);
236 TRACE("destroying %p\n", ws
);
238 EnterCriticalSection( &ws
->cs
);
239 if (ws
->async
) SetEvent( ws
->async
->cancel
);
240 LeaveCriticalSection( &ws
->cs
);
243 WaitForSingleObject( ws
->async
->wait
, INFINITE
);
244 free_async( ws
->async
);
246 ws
->cs
.DebugInfo
->Spare
[0] = 0;
247 DeleteCriticalSection( &ws
->cs
);
249 IWbemContext_Release( ws
->context
);
255 static HRESULT WINAPI
wbem_services_QueryInterface(
256 IWbemServices
*iface
,
260 struct wbem_services
*ws
= impl_from_IWbemServices( iface
);
262 TRACE("%p %s %p\n", ws
, debugstr_guid( riid
), ppvObject
);
264 if ( IsEqualGUID( riid
, &IID_IWbemServices
) ||
265 IsEqualGUID( riid
, &IID_IUnknown
) )
269 else if ( IsEqualGUID( riid
, &IID_IClientSecurity
) )
271 *ppvObject
= &client_security
;
276 FIXME("interface %s not implemented\n", debugstr_guid(riid
));
277 return E_NOINTERFACE
;
279 IWbemServices_AddRef( iface
);
283 static HRESULT WINAPI
wbem_services_OpenNamespace(
284 IWbemServices
*iface
,
285 const BSTR strNamespace
,
288 IWbemServices
**ppWorkingNamespace
,
289 IWbemCallResult
**ppResult
)
291 struct wbem_services
*ws
= impl_from_IWbemServices( iface
);
293 TRACE( "%p, %s, %#lx, %p, %p, %p\n", iface
, debugstr_w(strNamespace
), lFlags
,
294 pCtx
, ppWorkingNamespace
, ppResult
);
296 if (ws
->ns
!= WBEMPROX_NAMESPACE_LAST
|| !strNamespace
)
297 return WBEM_E_INVALID_NAMESPACE
;
299 return WbemServices_create( strNamespace
, NULL
, (void **)ppWorkingNamespace
);
302 static HRESULT WINAPI
wbem_services_CancelAsyncCall(
303 IWbemServices
*iface
,
304 IWbemObjectSink
*pSink
)
306 struct wbem_services
*services
= impl_from_IWbemServices( iface
);
307 struct async_header
*async
;
309 TRACE("%p, %p\n", iface
, pSink
);
311 if (!pSink
) return WBEM_E_INVALID_PARAMETER
;
313 EnterCriticalSection( &services
->cs
);
315 if (!(async
= services
->async
))
317 LeaveCriticalSection( &services
->cs
);
318 return WBEM_E_INVALID_PARAMETER
;
320 services
->async
= NULL
;
321 SetEvent( async
->cancel
);
323 LeaveCriticalSection( &services
->cs
);
325 WaitForSingleObject( async
->wait
, INFINITE
);
330 static HRESULT WINAPI
wbem_services_QueryObjectSink(
331 IWbemServices
*iface
,
333 IWbemObjectSink
**ppResponseHandler
)
336 return WBEM_E_FAILED
;
339 HRESULT
parse_path( const WCHAR
*str
, struct path
**ret
)
342 const WCHAR
*p
= str
, *q
;
345 if (!(path
= calloc( 1, sizeof(*path
) ))) return E_OUTOFMEMORY
;
349 static const WCHAR cimv2W
[] = L
"ROOT\\CIMV2";
350 WCHAR server
[MAX_COMPUTERNAME_LENGTH
+1];
351 DWORD server_len
= ARRAY_SIZE(server
);
357 return WBEM_E_INVALID_OBJECT_PATH
;
362 while (*p
&& *p
!= '\\') p
++;
366 return WBEM_E_INVALID_OBJECT_PATH
;
370 if (!GetComputerNameW( server
, &server_len
) || server_len
!= len
|| wcsnicmp( q
, server
, server_len
))
373 return WBEM_E_NOT_SUPPORTED
;
377 while (*p
&& *p
!= ':') p
++;
381 return WBEM_E_INVALID_OBJECT_PATH
;
385 if (len
!= ARRAY_SIZE(cimv2W
) - 1 || wcsnicmp( q
, cimv2W
, ARRAY_SIZE(cimv2W
) - 1 ))
388 return WBEM_E_INVALID_NAMESPACE
;
394 while (*p
&& *p
!= '.') p
++;
397 if (!(path
->class = malloc( (len
+ 1) * sizeof(WCHAR
) )))
400 return E_OUTOFMEMORY
;
402 memcpy( path
->class, q
, len
* sizeof(WCHAR
) );
403 path
->class[len
] = 0;
404 path
->class_len
= len
;
406 if (p
[0] == '.' && p
[1])
412 if (!(path
->filter
= malloc( (len
+ 1) * sizeof(WCHAR
) )))
416 return E_OUTOFMEMORY
;
418 memcpy( path
->filter
, p
, len
* sizeof(WCHAR
) );
419 path
->filter
[len
] = 0;
420 path
->filter_len
= len
;
426 void free_path( struct path
*path
)
430 free( path
->filter
);
434 WCHAR
*query_from_path( const struct path
*path
)
436 static const WCHAR selectW
[] = L
"SELECT * FROM %s WHERE %s";
437 static const WCHAR select_allW
[] = L
"SELECT * FROM ";
443 len
= path
->class_len
+ path
->filter_len
+ ARRAY_SIZE(selectW
);
444 if (!(query
= malloc( len
* sizeof(WCHAR
) ))) return NULL
;
445 swprintf( query
, len
, selectW
, path
->class, path
->filter
);
449 len
= path
->class_len
+ ARRAY_SIZE(select_allW
);
450 if (!(query
= malloc( len
* sizeof(WCHAR
) ))) return NULL
;
451 lstrcpyW( query
, select_allW
);
452 lstrcatW( query
, path
->class );
457 static HRESULT
create_instance_enum( enum wbm_namespace ns
, const struct path
*path
, IEnumWbemClassObject
**iter
)
462 if (!(query
= query_from_path( path
))) return E_OUTOFMEMORY
;
463 hr
= exec_query( ns
, query
, iter
);
468 HRESULT
get_object( enum wbm_namespace ns
, const WCHAR
*object_path
, IWbemClassObject
**obj
)
470 IEnumWbemClassObject
*iter
;
475 hr
= parse_path( object_path
, &path
);
476 if (hr
!= S_OK
) return hr
;
478 hr
= create_instance_enum( ns
, path
, &iter
);
484 hr
= IEnumWbemClassObject_Next( iter
, WBEM_INFINITE
, 1, obj
, &count
);
485 if (hr
== WBEM_S_FALSE
)
487 hr
= WBEM_E_NOT_FOUND
;
490 IEnumWbemClassObject_Release( iter
);
495 static HRESULT WINAPI
wbem_services_GetObject(
496 IWbemServices
*iface
,
497 const BSTR strObjectPath
,
500 IWbemClassObject
**ppObject
,
501 IWbemCallResult
**ppCallResult
)
503 struct wbem_services
*services
= impl_from_IWbemServices( iface
);
505 TRACE( "%p, %s, %#lx, %p, %p, %p\n", iface
, debugstr_w(strObjectPath
), lFlags
,
506 pCtx
, ppObject
, ppCallResult
);
508 if (lFlags
) FIXME( "unsupported flags %#lx\n", lFlags
);
510 if (!strObjectPath
|| !strObjectPath
[0])
511 return create_class_object( services
->ns
, NULL
, NULL
, 0, NULL
, ppObject
);
513 return get_object( services
->ns
, strObjectPath
, ppObject
);
516 static HRESULT WINAPI
wbem_services_GetObjectAsync(
517 IWbemServices
*iface
,
518 const BSTR strObjectPath
,
521 IWbemObjectSink
*pResponseHandler
)
524 return WBEM_E_FAILED
;
527 static HRESULT WINAPI
wbem_services_PutClass(
528 IWbemServices
*iface
,
529 IWbemClassObject
*pObject
,
532 IWbemCallResult
**ppCallResult
)
535 return WBEM_E_FAILED
;
538 static HRESULT WINAPI
wbem_services_PutClassAsync(
539 IWbemServices
*iface
,
540 IWbemClassObject
*pObject
,
543 IWbemObjectSink
*pResponseHandler
)
546 return WBEM_E_FAILED
;
549 static HRESULT WINAPI
wbem_services_DeleteClass(
550 IWbemServices
*iface
,
554 IWbemCallResult
**ppCallResult
)
557 return WBEM_E_FAILED
;
560 static HRESULT WINAPI
wbem_services_DeleteClassAsync(
561 IWbemServices
*iface
,
565 IWbemObjectSink
*pResponseHandler
)
568 return WBEM_E_FAILED
;
571 static HRESULT WINAPI
wbem_services_CreateClassEnum(
572 IWbemServices
*iface
,
573 const BSTR strSuperclass
,
576 IEnumWbemClassObject
**ppEnum
)
579 return WBEM_E_FAILED
;
582 static HRESULT WINAPI
wbem_services_CreateClassEnumAsync(
583 IWbemServices
*iface
,
584 const BSTR strSuperclass
,
587 IWbemObjectSink
*pResponseHandler
)
590 return WBEM_E_FAILED
;
593 static HRESULT WINAPI
wbem_services_PutInstance(
594 IWbemServices
*iface
,
595 IWbemClassObject
*pInst
,
598 IWbemCallResult
**ppCallResult
)
601 return WBEM_E_FAILED
;
604 static HRESULT WINAPI
wbem_services_PutInstanceAsync(
605 IWbemServices
*iface
,
606 IWbemClassObject
*pInst
,
609 IWbemObjectSink
*pResponseHandler
)
612 return WBEM_E_FAILED
;
615 static HRESULT WINAPI
wbem_services_DeleteInstance(
616 IWbemServices
*iface
,
617 const BSTR strObjectPath
,
620 IWbemCallResult
**ppCallResult
)
623 return WBEM_E_FAILED
;
626 static HRESULT WINAPI
wbem_services_DeleteInstanceAsync(
627 IWbemServices
*iface
,
628 const BSTR strObjectPath
,
631 IWbemObjectSink
*pResponseHandler
)
634 return WBEM_E_FAILED
;
637 static HRESULT WINAPI
wbem_services_CreateInstanceEnum(
638 IWbemServices
*iface
,
642 IEnumWbemClassObject
**ppEnum
)
644 struct wbem_services
*services
= impl_from_IWbemServices( iface
);
648 TRACE( "%p, %s, %#lx, %p, %p\n", iface
, debugstr_w(strClass
), lFlags
, pCtx
, ppEnum
);
650 if (lFlags
) FIXME( "unsupported flags %#lx\n", lFlags
);
652 hr
= parse_path( strClass
, &path
);
653 if (hr
!= S_OK
) return hr
;
655 hr
= create_instance_enum( services
->ns
, path
, ppEnum
);
660 static HRESULT WINAPI
wbem_services_CreateInstanceEnumAsync(
661 IWbemServices
*iface
,
662 const BSTR strFilter
,
665 IWbemObjectSink
*pResponseHandler
)
668 return WBEM_E_FAILED
;
671 static HRESULT WINAPI
wbem_services_ExecQuery(
672 IWbemServices
*iface
,
673 const BSTR strQueryLanguage
,
677 IEnumWbemClassObject
**ppEnum
)
679 struct wbem_services
*services
= impl_from_IWbemServices( iface
);
681 TRACE( "%p, %s, %s, %#lx, %p, %p\n", iface
, debugstr_w(strQueryLanguage
),
682 debugstr_w(strQuery
), lFlags
, pCtx
, ppEnum
);
684 if (!strQueryLanguage
|| !strQuery
|| !strQuery
[0]) return WBEM_E_INVALID_PARAMETER
;
685 if (wcsicmp( strQueryLanguage
, L
"WQL" )) return WBEM_E_INVALID_QUERY_TYPE
;
686 return exec_query( services
->ns
, strQuery
, ppEnum
);
689 static void async_exec_query( struct async_header
*hdr
)
691 struct async_query
*query
= (struct async_query
*)hdr
;
692 IEnumWbemClassObject
*result
;
693 IWbemClassObject
*obj
;
697 hr
= exec_query( query
->ns
, query
->str
, &result
);
702 IEnumWbemClassObject_Next( result
, WBEM_INFINITE
, 1, &obj
, &count
);
704 IWbemObjectSink_Indicate( query
->hdr
.sink
, 1, &obj
);
705 IWbemClassObject_Release( obj
);
707 IEnumWbemClassObject_Release( result
);
709 IWbemObjectSink_SetStatus( query
->hdr
.sink
, WBEM_STATUS_COMPLETE
, hr
, NULL
, NULL
);
713 static HRESULT WINAPI
wbem_services_ExecQueryAsync(
714 IWbemServices
*iface
,
715 const BSTR strQueryLanguage
,
719 IWbemObjectSink
*pResponseHandler
)
721 struct wbem_services
*services
= impl_from_IWbemServices( iface
);
722 IWbemObjectSink
*sink
;
723 HRESULT hr
= E_OUTOFMEMORY
;
724 struct async_header
*async
;
725 struct async_query
*query
;
727 TRACE( "%p, %s, %s, %#lx, %p, %p\n", iface
, debugstr_w(strQueryLanguage
), debugstr_w(strQuery
),
728 lFlags
, pCtx
, pResponseHandler
);
730 if (!pResponseHandler
) return WBEM_E_INVALID_PARAMETER
;
732 hr
= IWbemObjectSink_QueryInterface( pResponseHandler
, &IID_IWbemObjectSink
, (void **)&sink
);
733 if (FAILED(hr
)) return hr
;
735 EnterCriticalSection( &services
->cs
);
739 FIXME("handle more than one pending async\n");
743 if (!(query
= calloc( 1, sizeof(*query
) ))) goto done
;
744 query
->ns
= services
->ns
;
745 async
= (struct async_header
*)query
;
747 if (!(init_async( async
, sink
, async_exec_query
)))
752 if (!(query
->str
= heap_strdupW( strQuery
)))
757 hr
= queue_async( async
);
758 if (hr
== S_OK
) services
->async
= async
;
766 LeaveCriticalSection( &services
->cs
);
767 IWbemObjectSink_Release( sink
);
771 static HRESULT WINAPI
wbem_services_ExecNotificationQuery(
772 IWbemServices
*iface
,
773 const BSTR strQueryLanguage
,
777 IEnumWbemClassObject
**ppEnum
)
780 return WBEM_E_FAILED
;
783 static HRESULT WINAPI
wbem_services_ExecNotificationQueryAsync(
784 IWbemServices
*iface
,
785 const BSTR strQueryLanguage
,
789 IWbemObjectSink
*pResponseHandler
)
791 struct wbem_services
*services
= impl_from_IWbemServices( iface
);
792 IWbemObjectSink
*sink
;
793 HRESULT hr
= E_OUTOFMEMORY
;
794 struct async_header
*async
;
795 struct async_query
*query
;
797 TRACE( "%p, %s, %s, %#lx, %p, %p\n", iface
, debugstr_w(strQueryLanguage
), debugstr_w(strQuery
),
798 lFlags
, pCtx
, pResponseHandler
);
800 if (!pResponseHandler
) return WBEM_E_INVALID_PARAMETER
;
802 hr
= IWbemObjectSink_QueryInterface( pResponseHandler
, &IID_IWbemObjectSink
, (void **)&sink
);
803 if (FAILED(hr
)) return hr
;
805 EnterCriticalSection( &services
->cs
);
809 FIXME("handle more than one pending async\n");
813 if (!(query
= calloc( 1, sizeof(*query
) ))) goto done
;
814 async
= (struct async_header
*)query
;
816 if (!(init_async( async
, sink
, async_exec_query
)))
821 if (!(query
->str
= heap_strdupW( strQuery
)))
826 hr
= queue_async( async
);
827 if (hr
== S_OK
) services
->async
= async
;
835 LeaveCriticalSection( &services
->cs
);
836 IWbemObjectSink_Release( sink
);
840 static HRESULT WINAPI
wbem_services_ExecMethod(
841 IWbemServices
*iface
,
842 const BSTR strObjectPath
,
843 const BSTR strMethodName
,
845 IWbemContext
*context
,
846 IWbemClassObject
*pInParams
,
847 IWbemClassObject
**ppOutParams
,
848 IWbemCallResult
**ppCallResult
)
850 struct wbem_services
*services
= impl_from_IWbemServices( iface
);
851 IEnumWbemClassObject
*result
= NULL
;
852 IWbemClassObject
*obj
= NULL
;
853 struct query
*query
= NULL
;
860 TRACE( "%p, %s, %s, %#lx, %p, %p, %p, %p\n", iface
, debugstr_w(strObjectPath
),
861 debugstr_w(strMethodName
), lFlags
, context
, pInParams
, ppOutParams
, ppCallResult
);
863 if (lFlags
) FIXME( "flags %#lx not supported\n", lFlags
);
865 if ((hr
= parse_path( strObjectPath
, &path
)) != S_OK
) return hr
;
866 if (!(str
= query_from_path( path
)))
871 if (!(query
= create_query( services
->ns
)))
876 hr
= parse_query( services
->ns
, str
, &query
->view
, &query
->mem
);
877 if (hr
!= S_OK
) goto done
;
879 hr
= execute_view( query
->view
);
880 if (hr
!= S_OK
) goto done
;
882 hr
= EnumWbemClassObject_create( query
, (void **)&result
);
883 if (hr
!= S_OK
) goto done
;
885 table
= get_view_table( query
->view
, 0 );
886 hr
= create_class_object( services
->ns
, table
->name
, result
, 0, NULL
, &obj
);
887 if (hr
!= S_OK
) goto done
;
889 hr
= get_method( table
, strMethodName
, &func
);
890 if (hr
!= S_OK
) goto done
;
892 hr
= func( obj
, context
? context
: services
->context
, pInParams
, ppOutParams
);
895 if (result
) IEnumWbemClassObject_Release( result
);
896 if (obj
) IWbemClassObject_Release( obj
);
903 static HRESULT WINAPI
wbem_services_ExecMethodAsync(
904 IWbemServices
*iface
,
905 const BSTR strObjectPath
,
906 const BSTR strMethodName
,
909 IWbemClassObject
*pInParams
,
910 IWbemObjectSink
*pResponseHandler
)
913 return WBEM_E_FAILED
;
916 static const IWbemServicesVtbl wbem_services_vtbl
=
918 wbem_services_QueryInterface
,
919 wbem_services_AddRef
,
920 wbem_services_Release
,
921 wbem_services_OpenNamespace
,
922 wbem_services_CancelAsyncCall
,
923 wbem_services_QueryObjectSink
,
924 wbem_services_GetObject
,
925 wbem_services_GetObjectAsync
,
926 wbem_services_PutClass
,
927 wbem_services_PutClassAsync
,
928 wbem_services_DeleteClass
,
929 wbem_services_DeleteClassAsync
,
930 wbem_services_CreateClassEnum
,
931 wbem_services_CreateClassEnumAsync
,
932 wbem_services_PutInstance
,
933 wbem_services_PutInstanceAsync
,
934 wbem_services_DeleteInstance
,
935 wbem_services_DeleteInstanceAsync
,
936 wbem_services_CreateInstanceEnum
,
937 wbem_services_CreateInstanceEnumAsync
,
938 wbem_services_ExecQuery
,
939 wbem_services_ExecQueryAsync
,
940 wbem_services_ExecNotificationQuery
,
941 wbem_services_ExecNotificationQueryAsync
,
942 wbem_services_ExecMethod
,
943 wbem_services_ExecMethodAsync
946 HRESULT
WbemServices_create( const WCHAR
*namespace, IWbemContext
*context
, LPVOID
*ppObj
)
948 struct wbem_services
*ws
;
949 enum wbm_namespace ns
;
951 TRACE("namespace %s, context %p, ppObj %p.\n", debugstr_w(namespace), context
, ppObj
);
954 ns
= WBEMPROX_NAMESPACE_LAST
;
955 else if ((ns
= get_namespace_from_string( namespace )) == WBEMPROX_NAMESPACE_LAST
)
956 return WBEM_E_INVALID_NAMESPACE
;
958 if (!(ws
= calloc( 1, sizeof(*ws
) ))) return E_OUTOFMEMORY
;
960 ws
->IWbemServices_iface
.lpVtbl
= &wbem_services_vtbl
;
963 InitializeCriticalSection( &ws
->cs
);
964 ws
->cs
.DebugInfo
->Spare
[0] = (DWORD_PTR
)(__FILE__
": wbemprox_services.cs");
966 IWbemContext_Clone( context
, &ws
->context
);
968 *ppObj
= &ws
->IWbemServices_iface
;
970 TRACE("returning iface %p\n", *ppObj
);
974 struct wbem_context_value
983 IWbemContext IWbemContext_iface
;
988 static void wbem_context_delete_values(struct wbem_context
*context
)
990 struct wbem_context_value
*value
, *next
;
992 LIST_FOR_EACH_ENTRY_SAFE(value
, next
, &context
->values
, struct wbem_context_value
, entry
)
994 list_remove( &value
->entry
);
995 VariantClear( &value
->value
);
1001 static struct wbem_context
*impl_from_IWbemContext( IWbemContext
*iface
)
1003 return CONTAINING_RECORD( iface
, struct wbem_context
, IWbemContext_iface
);
1006 static HRESULT WINAPI
wbem_context_QueryInterface(
1007 IWbemContext
*iface
,
1011 TRACE("%p, %s, %p\n", iface
, debugstr_guid( riid
), obj
);
1013 if ( IsEqualGUID( riid
, &IID_IWbemContext
) ||
1014 IsEqualGUID( riid
, &IID_IUnknown
) )
1020 FIXME("interface %s not implemented\n", debugstr_guid(riid
));
1021 return E_NOINTERFACE
;
1024 IWbemContext_AddRef( iface
);
1028 static ULONG WINAPI
wbem_context_AddRef(
1029 IWbemContext
*iface
)
1031 struct wbem_context
*context
= impl_from_IWbemContext( iface
);
1032 return InterlockedIncrement( &context
->refs
);
1035 static ULONG WINAPI
wbem_context_Release(
1036 IWbemContext
*iface
)
1038 struct wbem_context
*context
= impl_from_IWbemContext( iface
);
1039 LONG refs
= InterlockedDecrement( &context
->refs
);
1043 TRACE("destroying %p\n", context
);
1044 wbem_context_delete_values( context
);
1050 static HRESULT WINAPI
wbem_context_Clone(
1051 IWbemContext
*iface
,
1052 IWbemContext
**newcopy
)
1054 struct wbem_context
*context
= impl_from_IWbemContext( iface
);
1055 struct wbem_context_value
*value
;
1056 IWbemContext
*cloned_context
;
1059 TRACE("%p, %p\n", iface
, newcopy
);
1061 if (SUCCEEDED(hr
= WbemContext_create( (void **)&cloned_context
)))
1063 LIST_FOR_EACH_ENTRY( value
, &context
->values
, struct wbem_context_value
, entry
)
1065 if (FAILED(hr
= IWbemContext_SetValue( cloned_context
, value
->name
, 0, &value
->value
))) break;
1071 *newcopy
= cloned_context
;
1076 IWbemContext_Release( cloned_context
);
1082 static HRESULT WINAPI
wbem_context_GetNames(
1083 IWbemContext
*iface
,
1087 FIXME( "%p, %#lx, %p\n", iface
, flags
, names
);
1092 static HRESULT WINAPI
wbem_context_BeginEnumeration(
1093 IWbemContext
*iface
,
1096 FIXME( "%p, %#lx\n", iface
, flags
);
1101 static HRESULT WINAPI
wbem_context_Next(
1102 IWbemContext
*iface
,
1107 FIXME( "%p, %#lx, %p, %p\n", iface
, flags
, name
, value
);
1112 static HRESULT WINAPI
wbem_context_EndEnumeration(
1113 IWbemContext
*iface
)
1115 FIXME("%p\n", iface
);
1120 static struct wbem_context_value
*wbem_context_get_value( struct wbem_context
*context
, const WCHAR
*name
)
1122 struct wbem_context_value
*value
;
1124 LIST_FOR_EACH_ENTRY( value
, &context
->values
, struct wbem_context_value
, entry
)
1126 if (!lstrcmpiW( value
->name
, name
)) return value
;
1132 static HRESULT WINAPI
wbem_context_SetValue(
1133 IWbemContext
*iface
,
1138 struct wbem_context
*context
= impl_from_IWbemContext( iface
);
1139 struct wbem_context_value
*value
;
1142 TRACE( "%p, %s, %#lx, %s\n", iface
, debugstr_w(name
), flags
, debugstr_variant(var
) );
1145 return WBEM_E_INVALID_PARAMETER
;
1147 if ((value
= wbem_context_get_value( context
, name
)))
1149 VariantClear( &value
->value
);
1150 hr
= VariantCopy( &value
->value
, var
);
1154 if (!(value
= calloc( 1, sizeof(*value
) ))) return E_OUTOFMEMORY
;
1155 if (!(value
->name
= heap_strdupW( name
)))
1158 return E_OUTOFMEMORY
;
1160 if (FAILED(hr
= VariantCopy( &value
->value
, var
)))
1162 free( value
->name
);
1167 list_add_tail( &context
->values
, &value
->entry
);
1173 static HRESULT WINAPI
wbem_context_GetValue(
1174 IWbemContext
*iface
,
1179 struct wbem_context
*context
= impl_from_IWbemContext( iface
);
1180 struct wbem_context_value
*value
;
1182 TRACE( "%p, %s, %#lx, %p\n", iface
, debugstr_w(name
), flags
, var
);
1185 return WBEM_E_INVALID_PARAMETER
;
1187 if (!(value
= wbem_context_get_value( context
, name
)))
1188 return WBEM_E_NOT_FOUND
;
1190 V_VT(var
) = VT_EMPTY
;
1191 return VariantCopy( var
, &value
->value
);
1194 static HRESULT WINAPI
wbem_context_DeleteValue(
1195 IWbemContext
*iface
,
1199 FIXME( "%p, %s, %#lx\n", iface
, debugstr_w(name
), flags
);
1204 static HRESULT WINAPI
wbem_context_DeleteAll(
1205 IWbemContext
*iface
)
1207 FIXME("%p\n", iface
);
1212 static const IWbemContextVtbl wbem_context_vtbl
=
1214 wbem_context_QueryInterface
,
1215 wbem_context_AddRef
,
1216 wbem_context_Release
,
1218 wbem_context_GetNames
,
1219 wbem_context_BeginEnumeration
,
1221 wbem_context_EndEnumeration
,
1222 wbem_context_SetValue
,
1223 wbem_context_GetValue
,
1224 wbem_context_DeleteValue
,
1225 wbem_context_DeleteAll
,
1228 HRESULT
WbemContext_create( void **obj
)
1230 struct wbem_context
*context
;
1232 TRACE("(%p)\n", obj
);
1234 if (!(context
= malloc( sizeof(*context
) ))) return E_OUTOFMEMORY
;
1236 context
->IWbemContext_iface
.lpVtbl
= &wbem_context_vtbl
;
1238 list_init(&context
->values
);
1240 *obj
= &context
->IWbemContext_iface
;
1242 TRACE("returning iface %p\n", *obj
);