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 HRESULT WINAPI
WinMGMTS_QueryInterface(IParseDisplayName
*iface
, REFIID riid
, void **ppv
)
39 if(IsEqualGUID(riid
, &IID_IUnknown
)) {
40 TRACE("(IID_IUnknown %p)\n", ppv
);
42 }else if(IsEqualGUID(riid
, &IID_IParseDisplayName
)) {
43 TRACE("(IID_IParseDisplayName %p)\n", ppv
);
46 WARN("Unsupported riid %s\n", debugstr_guid(riid
));
51 IUnknown_AddRef((IUnknown
*)*ppv
);
55 static ULONG WINAPI
WinMGMTS_AddRef(IParseDisplayName
*iface
)
60 static ULONG WINAPI
WinMGMTS_Release(IParseDisplayName
*iface
)
65 static HRESULT
parse_path( const WCHAR
*str
, BSTR
*server
, BSTR
*namespace, BSTR
*relative
)
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
;
80 hr
= IWbemPath_GetServer( path
, &len
, NULL
);
83 if (!(*server
= SysAllocStringLen( NULL
, len
)))
88 hr
= IWbemPath_GetServer( path
, &len
, *server
);
89 if (hr
!= S_OK
) goto done
;
93 hr
= IWbemPath_GetText( path
, WBEMPATH_GET_NAMESPACE_ONLY
, &len
, NULL
);
96 if (!(*namespace = SysAllocStringLen( NULL
, len
)))
101 hr
= IWbemPath_GetText( path
, WBEMPATH_GET_NAMESPACE_ONLY
, &len
, *namespace );
102 if (hr
!= S_OK
) goto done
;
105 hr
= IWbemPath_GetText( path
, WBEMPATH_GET_RELATIVE_ONLY
, &len
, NULL
);
108 if (!(*relative
= SysAllocStringLen( NULL
, len
)))
113 hr
= IWbemPath_GetText( path
, WBEMPATH_GET_RELATIVE_ONLY
, &len
, *relative
);
117 IWbemPath_Release( path
);
120 SysFreeString( *server
);
121 SysFreeString( *namespace );
122 SysFreeString( *relative
);
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
;
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
;
145 FIXME( "ignoring security settings\n" );
146 while (*p
&& *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
);
162 hr
= ISWbemServices_Get( services
, relative
, 0, NULL
, &obj
);
163 if (hr
!= S_OK
) goto done
;
164 hr
= CreatePointerMoniker( (IUnknown
*)obj
, ppmkOut
);
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
);
178 static const IParseDisplayNameVtbl WinMGMTSVtbl
= {
179 WinMGMTS_QueryInterface
,
182 WinMGMTS_ParseDisplayName
185 static IParseDisplayName winmgmts
= { &WinMGMTSVtbl
};
187 static HRESULT
WinMGMTS_create(void **ppv
)
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
);
212 WARN( "interface %s not implemented\n", debugstr_guid(riid
) );
213 return E_NOINTERFACE
;
216 static ULONG WINAPI
factory_AddRef( IClassFactory
*iface
)
221 static ULONG WINAPI
factory_Release( IClassFactory
*iface
)
226 static HRESULT WINAPI
factory_CreateInstance( IClassFactory
*iface
, LPUNKNOWN outer
, REFIID riid
,
229 struct factory
*factory
= impl_from_IClassFactory( iface
);
233 TRACE( "%p, %s, %p\n", outer
, debugstr_guid(riid
), obj
);
236 if (outer
) return CLASS_E_NOAGGREGATION
;
238 hr
= factory
->fnCreateInstance( (LPVOID
*)&unk
);
242 hr
= IUnknown_QueryInterface( unk
, riid
, obj
);
243 IUnknown_Release( unk
);
247 static HRESULT WINAPI
factory_LockServer( IClassFactory
*iface
, BOOL lock
)
249 FIXME( "%p, %d\n", iface
, lock
);
253 static const struct IClassFactoryVtbl factory_vtbl
=
255 factory_QueryInterface
,
258 factory_CreateInstance
,
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
;
279 return CLASS_E_CLASSNOTAVAILABLE
;
281 return IClassFactory_QueryInterface( cf
, iid
, obj
);