jscript: Store the necessary function and variable info in the TypeInfo.
[wine.git] / dlls / wbemdisp / main.c
blobb921e490facd8554027a52c08dc5e21401dbf861
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 struct moniker
41 IMoniker IMoniker_iface;
42 LONG refs;
43 IUnknown *obj;
46 static inline struct moniker *impl_from_IMoniker(
47 IMoniker *iface )
49 return CONTAINING_RECORD( iface, struct moniker, IMoniker_iface );
52 static ULONG WINAPI moniker_AddRef(
53 IMoniker *iface )
55 struct moniker *moniker = impl_from_IMoniker( iface );
56 return InterlockedIncrement( &moniker->refs );
59 static ULONG WINAPI moniker_Release(
60 IMoniker *iface )
62 struct moniker *moniker = impl_from_IMoniker( iface );
63 LONG refs = InterlockedDecrement( &moniker->refs );
64 if (!refs)
66 TRACE( "destroying %p\n", moniker );
67 IUnknown_Release( moniker->obj );
68 heap_free( moniker );
70 return refs;
73 static HRESULT WINAPI moniker_QueryInterface(
74 IMoniker *iface, REFIID riid, void **ppvObject )
76 struct moniker *moniker = impl_from_IMoniker( iface );
78 TRACE( "%p, %s, %p\n", moniker, debugstr_guid( riid ), ppvObject );
80 if (IsEqualGUID( riid, &IID_IMoniker ) ||
81 IsEqualGUID( riid, &IID_IUnknown ))
83 *ppvObject = iface;
85 else
87 FIXME( "interface %s not implemented\n", debugstr_guid(riid) );
88 return E_NOINTERFACE;
90 IMoniker_AddRef( iface );
91 return S_OK;
94 static HRESULT WINAPI moniker_GetClassID(
95 IMoniker *iface, CLSID *pClassID )
97 FIXME( "\n" );
98 return E_NOTIMPL;
101 static HRESULT WINAPI moniker_IsDirty(
102 IMoniker *iface )
104 FIXME( "\n" );
105 return E_NOTIMPL;
108 static HRESULT WINAPI moniker_Load(
109 IMoniker *iface, IStream *pStm )
111 FIXME( "\n" );
112 return E_NOTIMPL;
115 static HRESULT WINAPI moniker_Save(
116 IMoniker *iface, IStream *pStm, BOOL fClearDirty )
118 FIXME( "\n" );
119 return E_NOTIMPL;
122 static HRESULT WINAPI moniker_GetSizeMax(
123 IMoniker *iface, ULARGE_INTEGER *pcbSize )
125 FIXME( "\n" );
126 return E_NOTIMPL;
129 static HRESULT WINAPI moniker_BindToObject(
130 IMoniker *iface, IBindCtx *pbc, IMoniker *pmkToLeft, REFIID riidResult, void **ppvResult )
132 struct moniker *moniker = impl_from_IMoniker( iface );
134 TRACE( "%p, %p, %p, %s, %p\n", iface, pbc, pmkToLeft, debugstr_guid(riidResult), ppvResult );
135 return IUnknown_QueryInterface( moniker->obj, riidResult, ppvResult );
138 static HRESULT WINAPI moniker_BindToStorage(
139 IMoniker *iface, IBindCtx *pbc, IMoniker *pmkToLeft, REFIID riid, void **ppvObj )
141 FIXME( "\n" );
142 return E_NOTIMPL;
145 static HRESULT WINAPI moniker_Reduce(
146 IMoniker *iface, IBindCtx *pbc, DWORD dwReduceHowFar, IMoniker **ppmkToLeft, IMoniker **ppmkReduced )
148 FIXME( "\n" );
149 return E_NOTIMPL;
152 static HRESULT WINAPI moniker_ComposeWith(
153 IMoniker *iface, IMoniker *pmkRight, BOOL fOnlyIfNotGeneric, IMoniker **ppmkComposite )
155 FIXME( "\n" );
156 return E_NOTIMPL;
159 static HRESULT WINAPI moniker_Enum(
160 IMoniker *iface, BOOL fForward, IEnumMoniker **ppenumMoniker )
162 FIXME( "\n" );
163 return E_NOTIMPL;
166 static HRESULT WINAPI moniker_IsEqual(
167 IMoniker *iface, IMoniker *pmkOtherMoniker )
169 FIXME( "\n" );
170 return E_NOTIMPL;
173 static HRESULT WINAPI moniker_Hash(
174 IMoniker *iface, DWORD *pdwHash )
176 FIXME( "\n" );
177 return E_NOTIMPL;
180 static HRESULT WINAPI moniker_IsRunning(
181 IMoniker *iface, IBindCtx *pbc, IMoniker *pmkToLeft, IMoniker *pmkNewlyRunning )
183 FIXME( "\n" );
184 return E_NOTIMPL;
187 static HRESULT WINAPI moniker_GetTimeOfLastChange(
188 IMoniker *iface, IBindCtx *pbc, IMoniker *pmkToLeft, FILETIME *pFileTime )
190 FIXME( "\n" );
191 return E_NOTIMPL;
194 static HRESULT WINAPI moniker_Inverse(
195 IMoniker *iface, IMoniker **ppmk )
197 FIXME( "\n" );
198 return E_NOTIMPL;
201 static HRESULT WINAPI moniker_CommonPrefixWith(
202 IMoniker *iface, IMoniker *pmkOther, IMoniker **ppmkPrefix )
204 FIXME( "\n" );
205 return E_NOTIMPL;
208 static HRESULT WINAPI moniker_RelativePathTo(
209 IMoniker *iface, IMoniker *pmkOther, IMoniker **ppmkRelPath )
211 FIXME( "\n" );
212 return E_NOTIMPL;
215 static HRESULT WINAPI moniker_GetDisplayName(
216 IMoniker *iface, IBindCtx *pbc, IMoniker *pmkToLeft, LPOLESTR *ppszDisplayName )
218 FIXME( "\n" );
219 return E_NOTIMPL;
222 static HRESULT WINAPI moniker_ParseDisplayName(
223 IMoniker *iface, IBindCtx *pbc, IMoniker *pmkToLeft, LPOLESTR pszDisplayName, ULONG *pchEaten,
224 IMoniker **ppmkOut )
226 FIXME( "\n" );
227 return E_NOTIMPL;
230 static HRESULT WINAPI moniker_IsSystemMoniker(
231 IMoniker *iface, DWORD *pdwMksys )
233 FIXME( "\n" );
234 return E_NOTIMPL;
237 static const IMonikerVtbl moniker_vtbl =
239 moniker_QueryInterface,
240 moniker_AddRef,
241 moniker_Release,
242 moniker_GetClassID,
243 moniker_IsDirty,
244 moniker_Load,
245 moniker_Save,
246 moniker_GetSizeMax,
247 moniker_BindToObject,
248 moniker_BindToStorage,
249 moniker_Reduce,
250 moniker_ComposeWith,
251 moniker_Enum,
252 moniker_IsEqual,
253 moniker_Hash,
254 moniker_IsRunning,
255 moniker_GetTimeOfLastChange,
256 moniker_Inverse,
257 moniker_CommonPrefixWith,
258 moniker_RelativePathTo,
259 moniker_GetDisplayName,
260 moniker_ParseDisplayName,
261 moniker_IsSystemMoniker
264 static HRESULT Moniker_create( IUnknown *unk, IMoniker **obj )
266 struct moniker *moniker;
268 TRACE( "%p, %p\n", unk, obj );
270 if (!(moniker = heap_alloc( sizeof(*moniker) ))) return E_OUTOFMEMORY;
271 moniker->IMoniker_iface.lpVtbl = &moniker_vtbl;
272 moniker->refs = 1;
273 moniker->obj = unk;
274 IUnknown_AddRef( moniker->obj );
276 *obj = &moniker->IMoniker_iface;
277 TRACE( "returning iface %p\n", *obj );
278 return S_OK;
281 static HRESULT WINAPI WinMGMTS_QueryInterface(IParseDisplayName *iface, REFIID riid, void **ppv)
283 if(IsEqualGUID(riid, &IID_IUnknown)) {
284 TRACE("(IID_IUnknown %p)\n", ppv);
285 *ppv = iface;
286 }else if(IsEqualGUID(riid, &IID_IParseDisplayName)) {
287 TRACE("(IID_IParseDisplayName %p)\n", ppv);
288 *ppv = iface;
289 }else {
290 WARN("Unsupported riid %s\n", debugstr_guid(riid));
291 *ppv = NULL;
292 return E_NOINTERFACE;
295 IUnknown_AddRef((IUnknown*)*ppv);
296 return S_OK;
299 static ULONG WINAPI WinMGMTS_AddRef(IParseDisplayName *iface)
301 return 2;
304 static ULONG WINAPI WinMGMTS_Release(IParseDisplayName *iface)
306 return 1;
309 static HRESULT parse_path( const WCHAR *str, BSTR *server, BSTR *namespace, BSTR *relative )
311 IWbemPath *path;
312 ULONG len;
313 HRESULT hr;
315 *server = *namespace = *relative = NULL;
317 hr = CoCreateInstance( &CLSID_WbemDefPath, NULL, CLSCTX_INPROC_SERVER, &IID_IWbemPath, (void **)&path );
318 if (hr != S_OK) return hr;
320 hr = IWbemPath_SetText( path, WBEMPATH_CREATE_ACCEPT_ALL, str );
321 if (hr != S_OK) goto done;
323 len = 0;
324 hr = IWbemPath_GetServer( path, &len, NULL );
325 if (hr == S_OK)
327 if (!(*server = SysAllocStringLen( NULL, len )))
329 hr = E_OUTOFMEMORY;
330 goto done;
332 hr = IWbemPath_GetServer( path, &len, *server );
333 if (hr != S_OK) goto done;
336 len = 0;
337 hr = IWbemPath_GetText( path, WBEMPATH_GET_NAMESPACE_ONLY, &len, NULL );
338 if (hr == S_OK)
340 if (!(*namespace = SysAllocStringLen( NULL, len )))
342 hr = E_OUTOFMEMORY;
343 goto done;
345 hr = IWbemPath_GetText( path, WBEMPATH_GET_NAMESPACE_ONLY, &len, *namespace );
346 if (hr != S_OK) goto done;
348 len = 0;
349 hr = IWbemPath_GetText( path, WBEMPATH_GET_RELATIVE_ONLY, &len, NULL );
350 if (hr == S_OK)
352 if (!(*relative = SysAllocStringLen( NULL, len )))
354 hr = E_OUTOFMEMORY;
355 goto done;
357 hr = IWbemPath_GetText( path, WBEMPATH_GET_RELATIVE_ONLY, &len, *relative );
360 done:
361 IWbemPath_Release( path );
362 if (hr != S_OK)
364 SysFreeString( *server );
365 SysFreeString( *namespace );
366 SysFreeString( *relative );
368 return hr;
371 static HRESULT WINAPI WinMGMTS_ParseDisplayName(IParseDisplayName *iface, IBindCtx *pbc, LPOLESTR pszDisplayName,
372 ULONG *pchEaten, IMoniker **ppmkOut)
374 static const WCHAR prefixW[] = {'w','i','n','m','g','m','t','s',':',0};
375 const DWORD prefix_len = ARRAY_SIZE(prefixW) - 1;
376 ISWbemLocator *locator = NULL;
377 ISWbemServices *services = NULL;
378 ISWbemObject *obj = NULL;
379 BSTR server, namespace, relative;
380 WCHAR *p;
381 HRESULT hr;
383 TRACE( "%p, %p, %s, %p, %p\n", iface, pbc, debugstr_w(pszDisplayName), pchEaten, ppmkOut );
385 if (wcsnicmp( pszDisplayName, prefixW, prefix_len )) return MK_E_SYNTAX;
387 p = pszDisplayName + prefix_len;
388 if (*p == '{')
390 FIXME( "ignoring security settings\n" );
391 while (*p && *p != '}') p++;
392 if (*p == '}') p++;
393 if (*p == '!') p++;
395 hr = parse_path( p, &server, &namespace, &relative );
396 if (hr != S_OK) return hr;
398 hr = SWbemLocator_create( (void **)&locator );
399 if (hr != S_OK) goto done;
401 hr = ISWbemLocator_ConnectServer( locator, server, namespace, NULL, NULL, NULL, NULL, 0, NULL, &services );
402 if (hr != S_OK) goto done;
404 if (!relative || !*relative) Moniker_create( (IUnknown *)services, ppmkOut );
405 else
407 hr = ISWbemServices_Get( services, relative, 0, NULL, &obj );
408 if (hr != S_OK) goto done;
409 hr = Moniker_create( (IUnknown *)obj, ppmkOut );
412 done:
413 if (obj) ISWbemObject_Release( obj );
414 if (services) ISWbemServices_Release( services );
415 if (locator) ISWbemLocator_Release( locator );
416 SysFreeString( server );
417 SysFreeString( namespace );
418 SysFreeString( relative );
419 if (hr == S_OK) *pchEaten = lstrlenW( pszDisplayName );
420 return hr;
423 static const IParseDisplayNameVtbl WinMGMTSVtbl = {
424 WinMGMTS_QueryInterface,
425 WinMGMTS_AddRef,
426 WinMGMTS_Release,
427 WinMGMTS_ParseDisplayName
430 static IParseDisplayName winmgmts = { &WinMGMTSVtbl };
432 static HRESULT WinMGMTS_create(void **ppv)
434 *ppv = &winmgmts;
435 return S_OK;
438 struct factory
440 IClassFactory IClassFactory_iface;
441 HRESULT (*fnCreateInstance)( LPVOID * );
444 static inline struct factory *impl_from_IClassFactory( IClassFactory *iface )
446 return CONTAINING_RECORD( iface, struct factory, IClassFactory_iface );
449 static HRESULT WINAPI factory_QueryInterface( IClassFactory *iface, REFIID riid, LPVOID *obj )
451 if (IsEqualGUID( riid, &IID_IUnknown ) || IsEqualGUID( riid, &IID_IClassFactory ))
453 IClassFactory_AddRef( iface );
454 *obj = iface;
455 return S_OK;
457 FIXME( "interface %s not implemented\n", debugstr_guid(riid) );
458 return E_NOINTERFACE;
461 static ULONG WINAPI factory_AddRef( IClassFactory *iface )
463 return 2;
466 static ULONG WINAPI factory_Release( IClassFactory *iface )
468 return 1;
471 static HRESULT WINAPI factory_CreateInstance( IClassFactory *iface, LPUNKNOWN outer, REFIID riid,
472 LPVOID *obj )
474 struct factory *factory = impl_from_IClassFactory( iface );
475 IUnknown *unk;
476 HRESULT hr;
478 TRACE( "%p, %s, %p\n", outer, debugstr_guid(riid), obj );
480 *obj = NULL;
481 if (outer) return CLASS_E_NOAGGREGATION;
483 hr = factory->fnCreateInstance( (LPVOID *)&unk );
484 if (FAILED( hr ))
485 return hr;
487 hr = IUnknown_QueryInterface( unk, riid, obj );
488 IUnknown_Release( unk );
489 return hr;
492 static HRESULT WINAPI factory_LockServer( IClassFactory *iface, BOOL lock )
494 FIXME( "%p, %d\n", iface, lock );
495 return S_OK;
498 static const struct IClassFactoryVtbl factory_vtbl =
500 factory_QueryInterface,
501 factory_AddRef,
502 factory_Release,
503 factory_CreateInstance,
504 factory_LockServer
507 static struct factory swbem_locator_cf = { { &factory_vtbl }, SWbemLocator_create };
508 static struct factory winmgmts_cf = { { &factory_vtbl }, WinMGMTS_create };
510 BOOL WINAPI DllMain( HINSTANCE hinst, DWORD reason, LPVOID reserved )
513 switch (reason)
515 case DLL_WINE_PREATTACH:
516 return FALSE; /* prefer native version */
517 case DLL_PROCESS_ATTACH:
518 instance = hinst;
519 DisableThreadLibraryCalls( hinst );
520 break;
522 return TRUE;
525 HRESULT WINAPI DllGetClassObject( REFCLSID rclsid, REFIID iid, LPVOID *obj )
527 IClassFactory *cf = NULL;
529 TRACE( "%s, %s, %p\n", debugstr_guid(rclsid), debugstr_guid(iid), obj );
531 if (IsEqualGUID( rclsid, &CLSID_SWbemLocator ))
532 cf = &swbem_locator_cf.IClassFactory_iface;
533 else if (IsEqualGUID( rclsid, &CLSID_WinMGMTS ))
534 cf = &winmgmts_cf.IClassFactory_iface;
535 else
536 return CLASS_E_CLASSNOTAVAILABLE;
538 return IClassFactory_QueryInterface( cf, iid, obj );
541 /***********************************************************************
542 * DllCanUnloadNow (WBEMDISP.@)
544 HRESULT WINAPI DllCanUnloadNow(void)
546 return S_FALSE;
549 /***********************************************************************
550 * DllRegisterServer (WBEMDISP.@)
552 HRESULT WINAPI DllRegisterServer(void)
554 return __wine_register_resources( instance );
557 /***********************************************************************
558 * DllUnregisterServer (WBEMDISP.@)
560 HRESULT WINAPI DllUnregisterServer(void)
562 return __wine_unregister_resources( instance );