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
28 #include "wine/debug.h"
29 #include "wbemprox_private.h"
31 WINE_DEFAULT_DEBUG_CHANNEL(wbemprox
);
35 IWbemQualifierSet IWbemQualifierSet_iface
;
41 static inline struct qualifier_set
*impl_from_IWbemQualifierSet(
42 IWbemQualifierSet
*iface
)
44 return CONTAINING_RECORD(iface
, struct qualifier_set
, IWbemQualifierSet_iface
);
47 static ULONG WINAPI
qualifier_set_AddRef(
48 IWbemQualifierSet
*iface
)
50 struct qualifier_set
*set
= impl_from_IWbemQualifierSet( iface
);
51 return InterlockedIncrement( &set
->refs
);
54 static ULONG WINAPI
qualifier_set_Release(
55 IWbemQualifierSet
*iface
)
57 struct qualifier_set
*set
= impl_from_IWbemQualifierSet( iface
);
58 LONG refs
= InterlockedDecrement( &set
->refs
);
61 TRACE("destroying %p\n", set
);
62 heap_free( set
->class );
63 heap_free( set
->member
);
69 static HRESULT WINAPI
qualifier_set_QueryInterface(
70 IWbemQualifierSet
*iface
,
74 struct qualifier_set
*set
= impl_from_IWbemQualifierSet( iface
);
76 TRACE("%p, %s, %p\n", set
, debugstr_guid( riid
), ppvObject
);
78 if ( IsEqualGUID( riid
, &IID_IWbemQualifierSet
) ||
79 IsEqualGUID( riid
, &IID_IUnknown
) )
85 FIXME("interface %s not implemented\n", debugstr_guid(riid
));
88 IWbemQualifierSet_AddRef( iface
);
92 static HRESULT
create_qualifier_enum( const WCHAR
*class, const WCHAR
*member
, const WCHAR
*name
,
93 IEnumWbemClassObject
**iter
)
95 static const WCHAR fmtW
[] = L
"SELECT * FROM __QUALIFIERS WHERE Class='%s' AND Member='%s' AND Name='%s'";
96 static const WCHAR fmt2W
[] = L
"SELECT * FROM __QUALIFIERS WHERE Class='%s' AND Member='%s'";
97 static const WCHAR fmt3W
[] = L
"SELECT * FROM __QUALIFIERS WHERE Class='%s'";
104 len
= lstrlenW( class ) + lstrlenW( member
) + lstrlenW( name
) + ARRAY_SIZE(fmtW
);
105 if (!(query
= heap_alloc( len
* sizeof(WCHAR
) ))) return E_OUTOFMEMORY
;
106 swprintf( query
, len
, fmtW
, class, member
, name
);
110 len
= lstrlenW( class ) + lstrlenW( member
) + ARRAY_SIZE(fmt2W
);
111 if (!(query
= heap_alloc( len
* sizeof(WCHAR
) ))) return E_OUTOFMEMORY
;
112 swprintf( query
, len
, fmt2W
, class, member
);
116 len
= lstrlenW( class ) + ARRAY_SIZE(fmt3W
);
117 if (!(query
= heap_alloc( len
* sizeof(WCHAR
) ))) return E_OUTOFMEMORY
;
118 swprintf( query
, len
, fmt3W
, class );
121 hr
= exec_query( query
, iter
);
126 static HRESULT
get_qualifier_value( const WCHAR
*class, const WCHAR
*member
, const WCHAR
*name
,
127 VARIANT
*val
, LONG
*flavor
)
129 IEnumWbemClassObject
*iter
;
130 IWbemClassObject
*obj
;
134 hr
= create_qualifier_enum( class, member
, name
, &iter
);
135 if (FAILED( hr
)) return hr
;
137 hr
= create_class_object( NULL
, iter
, 0, NULL
, &obj
);
138 IEnumWbemClassObject_Release( iter
);
139 if (FAILED( hr
)) return hr
;
143 hr
= IWbemClassObject_Get( obj
, L
"Flavor", 0, &var
, NULL
, NULL
);
144 if (hr
!= S_OK
) goto done
;
145 *flavor
= V_I4( &var
);
147 hr
= IWbemClassObject_Get( obj
, L
"Type", 0, &var
, NULL
, NULL
);
148 if (hr
!= S_OK
) goto done
;
149 switch (V_UI4( &var
))
152 hr
= IWbemClassObject_Get( obj
, L
"StringValue", 0, val
, NULL
, NULL
);
155 hr
= IWbemClassObject_Get( obj
, L
"IntegerValue", 0, val
, NULL
, NULL
);
158 hr
= IWbemClassObject_Get( obj
, L
"BoolValue", 0, val
, NULL
, NULL
);
161 ERR("unhandled type %u\n", V_UI4( &var
));
166 IWbemClassObject_Release( obj
);
170 static HRESULT WINAPI
qualifier_set_Get(
171 IWbemQualifierSet
*iface
,
177 struct qualifier_set
*set
= impl_from_IWbemQualifierSet( iface
);
179 TRACE("%p, %s, %08x, %p, %p\n", iface
, debugstr_w(wszName
), lFlags
, pVal
, plFlavor
);
182 FIXME("flags %08x not supported\n", lFlags
);
185 return get_qualifier_value( set
->class, set
->member
, wszName
, pVal
, plFlavor
);
188 static HRESULT WINAPI
qualifier_set_Put(
189 IWbemQualifierSet
*iface
,
194 FIXME("%p, %s, %p, %d\n", iface
, debugstr_w(wszName
), pVal
, lFlavor
);
198 static HRESULT WINAPI
qualifier_set_Delete(
199 IWbemQualifierSet
*iface
,
202 FIXME("%p, %s\n", iface
, debugstr_w(wszName
));
206 static HRESULT WINAPI
qualifier_set_GetNames(
207 IWbemQualifierSet
*iface
,
211 struct qualifier_set
*set
= impl_from_IWbemQualifierSet( iface
);
212 IEnumWbemClassObject
*iter
;
213 IWbemClassObject
*obj
;
216 TRACE("%p, %08x, %p\n", iface
, lFlags
, pNames
);
219 FIXME("flags %08x not supported\n", lFlags
);
223 hr
= create_qualifier_enum( set
->class, set
->member
, NULL
, &iter
);
224 if (FAILED( hr
)) return hr
;
226 hr
= create_class_object( NULL
, iter
, 0, NULL
, &obj
);
227 IEnumWbemClassObject_Release( iter
);
228 if (FAILED( hr
)) return hr
;
230 hr
= IWbemClassObject_GetNames( obj
, NULL
, 0, NULL
, pNames
);
231 IWbemClassObject_Release( obj
);
235 static HRESULT WINAPI
qualifier_set_BeginEnumeration(
236 IWbemQualifierSet
*iface
,
239 FIXME("%p, %08x\n", iface
, lFlags
);
243 static HRESULT WINAPI
qualifier_set_Next(
244 IWbemQualifierSet
*iface
,
250 FIXME("%p, %08x, %p, %p, %p\n", iface
, lFlags
, pstrName
, pVal
, plFlavor
);
254 static HRESULT WINAPI
qualifier_set_EndEnumeration(
255 IWbemQualifierSet
*iface
)
257 FIXME("%p\n", iface
);
261 static const IWbemQualifierSetVtbl qualifier_set_vtbl
=
263 qualifier_set_QueryInterface
,
264 qualifier_set_AddRef
,
265 qualifier_set_Release
,
268 qualifier_set_Delete
,
269 qualifier_set_GetNames
,
270 qualifier_set_BeginEnumeration
,
272 qualifier_set_EndEnumeration
275 HRESULT
WbemQualifierSet_create( const WCHAR
*class, const WCHAR
*member
, LPVOID
*ppObj
)
277 struct qualifier_set
*set
;
279 TRACE("%p\n", ppObj
);
281 if (!(set
= heap_alloc( sizeof(*set
) ))) return E_OUTOFMEMORY
;
283 set
->IWbemQualifierSet_iface
.lpVtbl
= &qualifier_set_vtbl
;
284 if (!(set
->class = heap_strdupW( class )))
287 return E_OUTOFMEMORY
;
289 if (!member
) set
->member
= NULL
;
290 else if (!(set
->member
= heap_strdupW( member
)))
292 heap_free( set
->class );
294 return E_OUTOFMEMORY
;
298 *ppObj
= &set
->IWbemQualifierSet_iface
;
300 TRACE("returning iface %p\n", *ppObj
);