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
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
);
44 }else if(IsEqualGUID(riid
, &IID_IParseDisplayName
)) {
45 TRACE("(IID_IParseDisplayName %p)\n", ppv
);
48 WARN("Unsupported riid %s\n", debugstr_guid(riid
));
53 IUnknown_AddRef((IUnknown
*)*ppv
);
57 static ULONG WINAPI
WinMGMTS_AddRef(IParseDisplayName
*iface
)
62 static ULONG WINAPI
WinMGMTS_Release(IParseDisplayName
*iface
)
67 static HRESULT
parse_path( const WCHAR
*str
, BSTR
*server
, BSTR
*namespace, BSTR
*relative
)
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
;
82 hr
= IWbemPath_GetServer( path
, &len
, NULL
);
85 if (!(*server
= SysAllocStringLen( NULL
, len
)))
90 hr
= IWbemPath_GetServer( path
, &len
, *server
);
91 if (hr
!= S_OK
) goto done
;
95 hr
= IWbemPath_GetText( path
, WBEMPATH_GET_NAMESPACE_ONLY
, &len
, NULL
);
98 if (!(*namespace = SysAllocStringLen( NULL
, len
)))
103 hr
= IWbemPath_GetText( path
, WBEMPATH_GET_NAMESPACE_ONLY
, &len
, *namespace );
104 if (hr
!= S_OK
) goto done
;
107 hr
= IWbemPath_GetText( path
, WBEMPATH_GET_RELATIVE_ONLY
, &len
, NULL
);
110 if (!(*relative
= SysAllocStringLen( NULL
, len
)))
115 hr
= IWbemPath_GetText( path
, WBEMPATH_GET_RELATIVE_ONLY
, &len
, *relative
);
119 IWbemPath_Release( path
);
122 SysFreeString( *server
);
123 SysFreeString( *namespace );
124 SysFreeString( *relative
);
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
;
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
;
148 FIXME( "ignoring security settings\n" );
149 while (*p
&& *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
);
165 hr
= ISWbemServices_Get( services
, relative
, 0, NULL
, &obj
);
166 if (hr
!= S_OK
) goto done
;
167 hr
= CreatePointerMoniker( (IUnknown
*)obj
, ppmkOut
);
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
);
181 static const IParseDisplayNameVtbl WinMGMTSVtbl
= {
182 WinMGMTS_QueryInterface
,
185 WinMGMTS_ParseDisplayName
188 static IParseDisplayName winmgmts
= { &WinMGMTSVtbl
};
190 static HRESULT
WinMGMTS_create(void **ppv
)
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
);
215 FIXME( "interface %s not implemented\n", debugstr_guid(riid
) );
216 return E_NOINTERFACE
;
219 static ULONG WINAPI
factory_AddRef( IClassFactory
*iface
)
224 static ULONG WINAPI
factory_Release( IClassFactory
*iface
)
229 static HRESULT WINAPI
factory_CreateInstance( IClassFactory
*iface
, LPUNKNOWN outer
, REFIID riid
,
232 struct factory
*factory
= impl_from_IClassFactory( iface
);
236 TRACE( "%p, %s, %p\n", outer
, debugstr_guid(riid
), obj
);
239 if (outer
) return CLASS_E_NOAGGREGATION
;
241 hr
= factory
->fnCreateInstance( (LPVOID
*)&unk
);
245 hr
= IUnknown_QueryInterface( unk
, riid
, obj
);
246 IUnknown_Release( unk
);
250 static HRESULT WINAPI
factory_LockServer( IClassFactory
*iface
, BOOL lock
)
252 FIXME( "%p, %d\n", iface
, lock
);
256 static const struct IClassFactoryVtbl factory_vtbl
=
258 factory_QueryInterface
,
261 factory_CreateInstance
,
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
)
273 case DLL_WINE_PREATTACH
:
274 return FALSE
; /* prefer native version */
275 case DLL_PROCESS_ATTACH
:
277 DisableThreadLibraryCalls( hinst
);
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
;
294 return CLASS_E_CLASSNOTAVAILABLE
;
296 return IClassFactory_QueryInterface( cf
, iid
, obj
);
299 /***********************************************************************
300 * DllCanUnloadNow (WBEMDISP.@)
302 HRESULT WINAPI
DllCanUnloadNow(void)
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
);