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 const DWORD prefix_len
= ARRAY_SIZE(L
"winmgmts:") - 1;
133 ISWbemLocator
*locator
= NULL
;
134 ISWbemServices
*services
= NULL
;
135 ISWbemObject
*obj
= NULL
;
136 BSTR server
, namespace, relative
;
140 TRACE( "%p, %p, %s, %p, %p\n", iface
, pbc
, debugstr_w(pszDisplayName
), pchEaten
, ppmkOut
);
142 if (wcsnicmp( pszDisplayName
, L
"winmgmts:", prefix_len
)) return MK_E_SYNTAX
;
144 p
= pszDisplayName
+ prefix_len
;
147 FIXME( "ignoring security settings\n" );
148 while (*p
&& *p
!= '}') p
++;
152 hr
= parse_path( p
, &server
, &namespace, &relative
);
153 if (hr
!= S_OK
) return hr
;
155 hr
= SWbemLocator_create( (void **)&locator
);
156 if (hr
!= S_OK
) goto done
;
158 hr
= ISWbemLocator_ConnectServer( locator
, server
, namespace, NULL
, NULL
, NULL
, NULL
, 0, NULL
, &services
);
159 if (hr
!= S_OK
) goto done
;
161 if (!relative
|| !*relative
) CreatePointerMoniker( (IUnknown
*)services
, ppmkOut
);
164 hr
= ISWbemServices_Get( services
, relative
, 0, NULL
, &obj
);
165 if (hr
!= S_OK
) goto done
;
166 hr
= CreatePointerMoniker( (IUnknown
*)obj
, ppmkOut
);
170 if (obj
) ISWbemObject_Release( obj
);
171 if (services
) ISWbemServices_Release( services
);
172 if (locator
) ISWbemLocator_Release( locator
);
173 SysFreeString( server
);
174 SysFreeString( namespace );
175 SysFreeString( relative
);
176 if (hr
== S_OK
) *pchEaten
= lstrlenW( pszDisplayName
);
180 static const IParseDisplayNameVtbl WinMGMTSVtbl
= {
181 WinMGMTS_QueryInterface
,
184 WinMGMTS_ParseDisplayName
187 static IParseDisplayName winmgmts
= { &WinMGMTSVtbl
};
189 static HRESULT
WinMGMTS_create(void **ppv
)
197 IClassFactory IClassFactory_iface
;
198 HRESULT (*fnCreateInstance
)( LPVOID
* );
201 static inline struct factory
*impl_from_IClassFactory( IClassFactory
*iface
)
203 return CONTAINING_RECORD( iface
, struct factory
, IClassFactory_iface
);
206 static HRESULT WINAPI
factory_QueryInterface( IClassFactory
*iface
, REFIID riid
, LPVOID
*obj
)
208 if (IsEqualGUID( riid
, &IID_IUnknown
) || IsEqualGUID( riid
, &IID_IClassFactory
))
210 IClassFactory_AddRef( iface
);
214 WARN( "interface %s not implemented\n", debugstr_guid(riid
) );
215 return E_NOINTERFACE
;
218 static ULONG WINAPI
factory_AddRef( IClassFactory
*iface
)
223 static ULONG WINAPI
factory_Release( IClassFactory
*iface
)
228 static HRESULT WINAPI
factory_CreateInstance( IClassFactory
*iface
, LPUNKNOWN outer
, REFIID riid
,
231 struct factory
*factory
= impl_from_IClassFactory( iface
);
235 TRACE( "%p, %s, %p\n", outer
, debugstr_guid(riid
), obj
);
238 if (outer
) return CLASS_E_NOAGGREGATION
;
240 hr
= factory
->fnCreateInstance( (LPVOID
*)&unk
);
244 hr
= IUnknown_QueryInterface( unk
, riid
, obj
);
245 IUnknown_Release( unk
);
249 static HRESULT WINAPI
factory_LockServer( IClassFactory
*iface
, BOOL lock
)
251 FIXME( "%p, %d\n", iface
, lock
);
255 static const struct IClassFactoryVtbl factory_vtbl
=
257 factory_QueryInterface
,
260 factory_CreateInstance
,
264 static struct factory swbem_locator_cf
= { { &factory_vtbl
}, SWbemLocator_create
};
265 static struct factory swbem_namedvalueset_cf
= { { &factory_vtbl
}, SWbemNamedValueSet_create
};
266 static struct factory winmgmts_cf
= { { &factory_vtbl
}, WinMGMTS_create
};
268 BOOL WINAPI
DllMain( HINSTANCE hinst
, DWORD reason
, LPVOID reserved
)
273 case DLL_PROCESS_ATTACH
:
275 DisableThreadLibraryCalls( hinst
);
281 HRESULT WINAPI
DllGetClassObject( REFCLSID rclsid
, REFIID iid
, LPVOID
*obj
)
283 IClassFactory
*cf
= NULL
;
285 TRACE( "%s, %s, %p\n", debugstr_guid(rclsid
), debugstr_guid(iid
), obj
);
287 if (IsEqualGUID( rclsid
, &CLSID_SWbemLocator
))
288 cf
= &swbem_locator_cf
.IClassFactory_iface
;
289 else if (IsEqualGUID( rclsid
, &CLSID_WinMGMTS
))
290 cf
= &winmgmts_cf
.IClassFactory_iface
;
291 else if (IsEqualGUID( rclsid
, &CLSID_SWbemNamedValueSet
))
292 cf
= &swbem_namedvalueset_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
);