amstream: Implement AMAudioStream::NewSegment.
[wine/zf.git] / dlls / wbemdisp / main.c
blobb3ee4de30ccb41d99f93afa245d983253ed1ca46
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 HINSTANCE instance;
39 static HRESULT WINAPI WinMGMTS_QueryInterface(IParseDisplayName *iface, REFIID riid, void **ppv)
41 if(IsEqualGUID(riid, &IID_IUnknown)) {
42 TRACE("(IID_IUnknown %p)\n", ppv);
43 *ppv = iface;
44 }else if(IsEqualGUID(riid, &IID_IParseDisplayName)) {
45 TRACE("(IID_IParseDisplayName %p)\n", ppv);
46 *ppv = iface;
47 }else {
48 WARN("Unsupported riid %s\n", debugstr_guid(riid));
49 *ppv = NULL;
50 return E_NOINTERFACE;
53 IUnknown_AddRef((IUnknown*)*ppv);
54 return S_OK;
57 static ULONG WINAPI WinMGMTS_AddRef(IParseDisplayName *iface)
59 return 2;
62 static ULONG WINAPI WinMGMTS_Release(IParseDisplayName *iface)
64 return 1;
67 static HRESULT parse_path( const WCHAR *str, BSTR *server, BSTR *namespace, BSTR *relative )
69 IWbemPath *path;
70 ULONG len;
71 HRESULT hr;
73 *server = *namespace = *relative = NULL;
75 hr = CoCreateInstance( &CLSID_WbemDefPath, NULL, CLSCTX_INPROC_SERVER, &IID_IWbemPath, (void **)&path );
76 if (hr != S_OK) return hr;
78 hr = IWbemPath_SetText( path, WBEMPATH_CREATE_ACCEPT_ALL, str );
79 if (hr != S_OK) goto done;
81 len = 0;
82 hr = IWbemPath_GetServer( path, &len, NULL );
83 if (hr == S_OK)
85 if (!(*server = SysAllocStringLen( NULL, len )))
87 hr = E_OUTOFMEMORY;
88 goto done;
90 hr = IWbemPath_GetServer( path, &len, *server );
91 if (hr != S_OK) goto done;
94 len = 0;
95 hr = IWbemPath_GetText( path, WBEMPATH_GET_NAMESPACE_ONLY, &len, NULL );
96 if (hr == S_OK)
98 if (!(*namespace = SysAllocStringLen( NULL, len )))
100 hr = E_OUTOFMEMORY;
101 goto done;
103 hr = IWbemPath_GetText( path, WBEMPATH_GET_NAMESPACE_ONLY, &len, *namespace );
104 if (hr != S_OK) goto done;
106 len = 0;
107 hr = IWbemPath_GetText( path, WBEMPATH_GET_RELATIVE_ONLY, &len, NULL );
108 if (hr == S_OK)
110 if (!(*relative = SysAllocStringLen( NULL, len )))
112 hr = E_OUTOFMEMORY;
113 goto done;
115 hr = IWbemPath_GetText( path, WBEMPATH_GET_RELATIVE_ONLY, &len, *relative );
118 done:
119 IWbemPath_Release( path );
120 if (hr != S_OK)
122 SysFreeString( *server );
123 SysFreeString( *namespace );
124 SysFreeString( *relative );
126 return hr;
129 static HRESULT WINAPI WinMGMTS_ParseDisplayName(IParseDisplayName *iface, IBindCtx *pbc, LPOLESTR pszDisplayName,
130 ULONG *pchEaten, IMoniker **ppmkOut)
132 static const WCHAR prefixW[] = {'w','i','n','m','g','m','t','s',':',0};
133 const DWORD prefix_len = ARRAY_SIZE(prefixW) - 1;
134 ISWbemLocator *locator = NULL;
135 ISWbemServices *services = NULL;
136 ISWbemObject *obj = NULL;
137 BSTR server, namespace, relative;
138 WCHAR *p;
139 HRESULT hr;
141 TRACE( "%p, %p, %s, %p, %p\n", iface, pbc, debugstr_w(pszDisplayName), pchEaten, ppmkOut );
143 if (wcsnicmp( pszDisplayName, prefixW, prefix_len )) return MK_E_SYNTAX;
145 p = pszDisplayName + prefix_len;
146 if (*p == '{')
148 FIXME( "ignoring security settings\n" );
149 while (*p && *p != '}') p++;
150 if (*p == '}') p++;
151 if (*p == '!') p++;
153 hr = parse_path( p, &server, &namespace, &relative );
154 if (hr != S_OK) return hr;
156 hr = SWbemLocator_create( (void **)&locator );
157 if (hr != S_OK) goto done;
159 hr = ISWbemLocator_ConnectServer( locator, server, namespace, NULL, NULL, NULL, NULL, 0, NULL, &services );
160 if (hr != S_OK) goto done;
162 if (!relative || !*relative) CreatePointerMoniker( (IUnknown *)services, ppmkOut );
163 else
165 hr = ISWbemServices_Get( services, relative, 0, NULL, &obj );
166 if (hr != S_OK) goto done;
167 hr = CreatePointerMoniker( (IUnknown *)obj, ppmkOut );
170 done:
171 if (obj) ISWbemObject_Release( obj );
172 if (services) ISWbemServices_Release( services );
173 if (locator) ISWbemLocator_Release( locator );
174 SysFreeString( server );
175 SysFreeString( namespace );
176 SysFreeString( relative );
177 if (hr == S_OK) *pchEaten = lstrlenW( pszDisplayName );
178 return hr;
181 static const IParseDisplayNameVtbl WinMGMTSVtbl = {
182 WinMGMTS_QueryInterface,
183 WinMGMTS_AddRef,
184 WinMGMTS_Release,
185 WinMGMTS_ParseDisplayName
188 static IParseDisplayName winmgmts = { &WinMGMTSVtbl };
190 static HRESULT WinMGMTS_create(void **ppv)
192 *ppv = &winmgmts;
193 return S_OK;
196 struct factory
198 IClassFactory IClassFactory_iface;
199 HRESULT (*fnCreateInstance)( LPVOID * );
202 static inline struct factory *impl_from_IClassFactory( IClassFactory *iface )
204 return CONTAINING_RECORD( iface, struct factory, IClassFactory_iface );
207 static HRESULT WINAPI factory_QueryInterface( IClassFactory *iface, REFIID riid, LPVOID *obj )
209 if (IsEqualGUID( riid, &IID_IUnknown ) || IsEqualGUID( riid, &IID_IClassFactory ))
211 IClassFactory_AddRef( iface );
212 *obj = iface;
213 return S_OK;
215 FIXME( "interface %s not implemented\n", debugstr_guid(riid) );
216 return E_NOINTERFACE;
219 static ULONG WINAPI factory_AddRef( IClassFactory *iface )
221 return 2;
224 static ULONG WINAPI factory_Release( IClassFactory *iface )
226 return 1;
229 static HRESULT WINAPI factory_CreateInstance( IClassFactory *iface, LPUNKNOWN outer, REFIID riid,
230 LPVOID *obj )
232 struct factory *factory = impl_from_IClassFactory( iface );
233 IUnknown *unk;
234 HRESULT hr;
236 TRACE( "%p, %s, %p\n", outer, debugstr_guid(riid), obj );
238 *obj = NULL;
239 if (outer) return CLASS_E_NOAGGREGATION;
241 hr = factory->fnCreateInstance( (LPVOID *)&unk );
242 if (FAILED( hr ))
243 return hr;
245 hr = IUnknown_QueryInterface( unk, riid, obj );
246 IUnknown_Release( unk );
247 return hr;
250 static HRESULT WINAPI factory_LockServer( IClassFactory *iface, BOOL lock )
252 FIXME( "%p, %d\n", iface, lock );
253 return S_OK;
256 static const struct IClassFactoryVtbl factory_vtbl =
258 factory_QueryInterface,
259 factory_AddRef,
260 factory_Release,
261 factory_CreateInstance,
262 factory_LockServer
265 static struct factory swbem_locator_cf = { { &factory_vtbl }, SWbemLocator_create };
266 static struct factory winmgmts_cf = { { &factory_vtbl }, WinMGMTS_create };
268 BOOL WINAPI DllMain( HINSTANCE hinst, DWORD reason, LPVOID reserved )
271 switch (reason)
273 case DLL_WINE_PREATTACH:
274 return FALSE; /* prefer native version */
275 case DLL_PROCESS_ATTACH:
276 instance = hinst;
277 DisableThreadLibraryCalls( hinst );
278 break;
280 return TRUE;
283 HRESULT WINAPI DllGetClassObject( REFCLSID rclsid, REFIID iid, LPVOID *obj )
285 IClassFactory *cf = NULL;
287 TRACE( "%s, %s, %p\n", debugstr_guid(rclsid), debugstr_guid(iid), obj );
289 if (IsEqualGUID( rclsid, &CLSID_SWbemLocator ))
290 cf = &swbem_locator_cf.IClassFactory_iface;
291 else if (IsEqualGUID( rclsid, &CLSID_WinMGMTS ))
292 cf = &winmgmts_cf.IClassFactory_iface;
293 else
294 return CLASS_E_CLASSNOTAVAILABLE;
296 return IClassFactory_QueryInterface( cf, iid, obj );
299 /***********************************************************************
300 * DllCanUnloadNow (WBEMDISP.@)
302 HRESULT WINAPI DllCanUnloadNow(void)
304 return S_FALSE;
307 /***********************************************************************
308 * DllRegisterServer (WBEMDISP.@)
310 HRESULT WINAPI DllRegisterServer(void)
312 return __wine_register_resources( instance );
315 /***********************************************************************
316 * DllUnregisterServer (WBEMDISP.@)
318 HRESULT WINAPI DllUnregisterServer(void)
320 return __wine_unregister_resources( instance );