nsiproxy: Introduce IOCTL_NSIPROXY_WINE_GET_ALL_PARAMETERS.
[wine.git] / dlls / wbemdisp / main.c
blob0ceb417ad521a1c91c11716630688b209d30657d
1 /*
2 * Copyright 2013 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 #include <stdarg.h>
21 #define COBJMACROS
23 #include "windef.h"
24 #include "winbase.h"
25 #include "objbase.h"
26 #include "wmiutils.h"
27 #include "wbemdisp.h"
28 #include "rpcproxy.h"
30 #include "wine/debug.h"
31 #include "wine/heap.h"
32 #include "wbemdisp_private.h"
33 #include "wbemdisp_classes.h"
35 WINE_DEFAULT_DEBUG_CHANNEL(wbemdisp);
37 static HRESULT WINAPI WinMGMTS_QueryInterface(IParseDisplayName *iface, REFIID riid, void **ppv)
39 if(IsEqualGUID(riid, &IID_IUnknown)) {
40 TRACE("(IID_IUnknown %p)\n", ppv);
41 *ppv = iface;
42 }else if(IsEqualGUID(riid, &IID_IParseDisplayName)) {
43 TRACE("(IID_IParseDisplayName %p)\n", ppv);
44 *ppv = iface;
45 }else {
46 WARN("Unsupported riid %s\n", debugstr_guid(riid));
47 *ppv = NULL;
48 return E_NOINTERFACE;
51 IUnknown_AddRef((IUnknown*)*ppv);
52 return S_OK;
55 static ULONG WINAPI WinMGMTS_AddRef(IParseDisplayName *iface)
57 return 2;
60 static ULONG WINAPI WinMGMTS_Release(IParseDisplayName *iface)
62 return 1;
65 static HRESULT parse_path( const WCHAR *str, BSTR *server, BSTR *namespace, BSTR *relative )
67 IWbemPath *path;
68 ULONG len;
69 HRESULT hr;
71 *server = *namespace = *relative = NULL;
73 hr = CoCreateInstance( &CLSID_WbemDefPath, NULL, CLSCTX_INPROC_SERVER, &IID_IWbemPath, (void **)&path );
74 if (hr != S_OK) return hr;
76 hr = IWbemPath_SetText( path, WBEMPATH_CREATE_ACCEPT_ALL, str );
77 if (hr != S_OK) goto done;
79 len = 0;
80 hr = IWbemPath_GetServer( path, &len, NULL );
81 if (hr == S_OK)
83 if (!(*server = SysAllocStringLen( NULL, len )))
85 hr = E_OUTOFMEMORY;
86 goto done;
88 hr = IWbemPath_GetServer( path, &len, *server );
89 if (hr != S_OK) goto done;
92 len = 0;
93 hr = IWbemPath_GetText( path, WBEMPATH_GET_NAMESPACE_ONLY, &len, NULL );
94 if (hr == S_OK)
96 if (!(*namespace = SysAllocStringLen( NULL, len )))
98 hr = E_OUTOFMEMORY;
99 goto done;
101 hr = IWbemPath_GetText( path, WBEMPATH_GET_NAMESPACE_ONLY, &len, *namespace );
102 if (hr != S_OK) goto done;
104 len = 0;
105 hr = IWbemPath_GetText( path, WBEMPATH_GET_RELATIVE_ONLY, &len, NULL );
106 if (hr == S_OK)
108 if (!(*relative = SysAllocStringLen( NULL, len )))
110 hr = E_OUTOFMEMORY;
111 goto done;
113 hr = IWbemPath_GetText( path, WBEMPATH_GET_RELATIVE_ONLY, &len, *relative );
116 done:
117 IWbemPath_Release( path );
118 if (hr != S_OK)
120 SysFreeString( *server );
121 SysFreeString( *namespace );
122 SysFreeString( *relative );
124 return hr;
127 static HRESULT WINAPI WinMGMTS_ParseDisplayName(IParseDisplayName *iface, IBindCtx *pbc, LPOLESTR pszDisplayName,
128 ULONG *pchEaten, IMoniker **ppmkOut)
130 const DWORD prefix_len = ARRAY_SIZE(L"winmgmts:") - 1;
131 ISWbemLocator *locator = NULL;
132 ISWbemServices *services = NULL;
133 ISWbemObject *obj = NULL;
134 BSTR server, namespace, relative;
135 WCHAR *p;
136 HRESULT hr;
138 TRACE( "%p, %p, %s, %p, %p\n", iface, pbc, debugstr_w(pszDisplayName), pchEaten, ppmkOut );
140 if (wcsnicmp( pszDisplayName, L"winmgmts:", prefix_len )) return MK_E_SYNTAX;
142 p = pszDisplayName + prefix_len;
143 if (*p == '{')
145 FIXME( "ignoring security settings\n" );
146 while (*p && *p != '}') p++;
147 if (*p == '}') p++;
148 if (*p == '!') p++;
150 hr = parse_path( p, &server, &namespace, &relative );
151 if (hr != S_OK) return hr;
153 hr = SWbemLocator_create( (void **)&locator );
154 if (hr != S_OK) goto done;
156 hr = ISWbemLocator_ConnectServer( locator, server, namespace, NULL, NULL, NULL, NULL, 0, NULL, &services );
157 if (hr != S_OK) goto done;
159 if (!relative || !*relative) CreatePointerMoniker( (IUnknown *)services, ppmkOut );
160 else
162 hr = ISWbemServices_Get( services, relative, 0, NULL, &obj );
163 if (hr != S_OK) goto done;
164 hr = CreatePointerMoniker( (IUnknown *)obj, ppmkOut );
167 done:
168 if (obj) ISWbemObject_Release( obj );
169 if (services) ISWbemServices_Release( services );
170 if (locator) ISWbemLocator_Release( locator );
171 SysFreeString( server );
172 SysFreeString( namespace );
173 SysFreeString( relative );
174 if (hr == S_OK) *pchEaten = lstrlenW( pszDisplayName );
175 return hr;
178 static const IParseDisplayNameVtbl WinMGMTSVtbl = {
179 WinMGMTS_QueryInterface,
180 WinMGMTS_AddRef,
181 WinMGMTS_Release,
182 WinMGMTS_ParseDisplayName
185 static IParseDisplayName winmgmts = { &WinMGMTSVtbl };
187 static HRESULT WinMGMTS_create(void **ppv)
189 *ppv = &winmgmts;
190 return S_OK;
193 struct factory
195 IClassFactory IClassFactory_iface;
196 HRESULT (*fnCreateInstance)( LPVOID * );
199 static inline struct factory *impl_from_IClassFactory( IClassFactory *iface )
201 return CONTAINING_RECORD( iface, struct factory, IClassFactory_iface );
204 static HRESULT WINAPI factory_QueryInterface( IClassFactory *iface, REFIID riid, LPVOID *obj )
206 if (IsEqualGUID( riid, &IID_IUnknown ) || IsEqualGUID( riid, &IID_IClassFactory ))
208 IClassFactory_AddRef( iface );
209 *obj = iface;
210 return S_OK;
212 WARN( "interface %s not implemented\n", debugstr_guid(riid) );
213 return E_NOINTERFACE;
216 static ULONG WINAPI factory_AddRef( IClassFactory *iface )
218 return 2;
221 static ULONG WINAPI factory_Release( IClassFactory *iface )
223 return 1;
226 static HRESULT WINAPI factory_CreateInstance( IClassFactory *iface, LPUNKNOWN outer, REFIID riid,
227 LPVOID *obj )
229 struct factory *factory = impl_from_IClassFactory( iface );
230 IUnknown *unk;
231 HRESULT hr;
233 TRACE( "%p, %s, %p\n", outer, debugstr_guid(riid), obj );
235 *obj = NULL;
236 if (outer) return CLASS_E_NOAGGREGATION;
238 hr = factory->fnCreateInstance( (LPVOID *)&unk );
239 if (FAILED( hr ))
240 return hr;
242 hr = IUnknown_QueryInterface( unk, riid, obj );
243 IUnknown_Release( unk );
244 return hr;
247 static HRESULT WINAPI factory_LockServer( IClassFactory *iface, BOOL lock )
249 FIXME( "%p, %d\n", iface, lock );
250 return S_OK;
253 static const struct IClassFactoryVtbl factory_vtbl =
255 factory_QueryInterface,
256 factory_AddRef,
257 factory_Release,
258 factory_CreateInstance,
259 factory_LockServer
262 static struct factory swbem_locator_cf = { { &factory_vtbl }, SWbemLocator_create };
263 static struct factory swbem_namedvalueset_cf = { { &factory_vtbl }, SWbemNamedValueSet_create };
264 static struct factory winmgmts_cf = { { &factory_vtbl }, WinMGMTS_create };
266 HRESULT WINAPI DllGetClassObject( REFCLSID rclsid, REFIID iid, LPVOID *obj )
268 IClassFactory *cf = NULL;
270 TRACE( "%s, %s, %p\n", debugstr_guid(rclsid), debugstr_guid(iid), obj );
272 if (IsEqualGUID( rclsid, &CLSID_SWbemLocator ))
273 cf = &swbem_locator_cf.IClassFactory_iface;
274 else if (IsEqualGUID( rclsid, &CLSID_WinMGMTS ))
275 cf = &winmgmts_cf.IClassFactory_iface;
276 else if (IsEqualGUID( rclsid, &CLSID_SWbemNamedValueSet ))
277 cf = &swbem_namedvalueset_cf.IClassFactory_iface;
278 else
279 return CLASS_E_CLASSNOTAVAILABLE;
281 return IClassFactory_QueryInterface( cf, iid, obj );