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
;
37 enum wbm_namespace ns
;
42 static inline struct qualifier_set
*impl_from_IWbemQualifierSet(
43 IWbemQualifierSet
*iface
)
45 return CONTAINING_RECORD(iface
, struct qualifier_set
, IWbemQualifierSet_iface
);
48 static ULONG WINAPI
qualifier_set_AddRef(
49 IWbemQualifierSet
*iface
)
51 struct qualifier_set
*set
= impl_from_IWbemQualifierSet( iface
);
52 return InterlockedIncrement( &set
->refs
);
55 static ULONG WINAPI
qualifier_set_Release(
56 IWbemQualifierSet
*iface
)
58 struct qualifier_set
*set
= impl_from_IWbemQualifierSet( iface
);
59 LONG refs
= InterlockedDecrement( &set
->refs
);
62 TRACE("destroying %p\n", set
);
70 static HRESULT WINAPI
qualifier_set_QueryInterface(
71 IWbemQualifierSet
*iface
,
75 struct qualifier_set
*set
= impl_from_IWbemQualifierSet( iface
);
77 TRACE("%p, %s, %p\n", set
, debugstr_guid( riid
), ppvObject
);
79 if ( IsEqualGUID( riid
, &IID_IWbemQualifierSet
) ||
80 IsEqualGUID( riid
, &IID_IUnknown
) )
86 FIXME("interface %s not implemented\n", debugstr_guid(riid
));
89 IWbemQualifierSet_AddRef( iface
);
93 static HRESULT
create_qualifier_enum( enum wbm_namespace ns
, const WCHAR
*class, const WCHAR
*member
,
94 const WCHAR
*name
, IEnumWbemClassObject
**iter
)
96 static const WCHAR fmtW
[] = L
"SELECT * FROM __QUALIFIERS WHERE Class='%s' AND Member='%s' AND Name='%s'";
97 static const WCHAR fmt2W
[] = L
"SELECT * FROM __QUALIFIERS WHERE Class='%s' AND Member='%s'";
98 static const WCHAR fmt3W
[] = L
"SELECT * FROM __QUALIFIERS WHERE Class='%s'";
105 len
= lstrlenW( class ) + lstrlenW( member
) + lstrlenW( name
) + ARRAY_SIZE(fmtW
);
106 if (!(query
= malloc( len
* sizeof(WCHAR
) ))) return E_OUTOFMEMORY
;
107 swprintf( query
, len
, fmtW
, class, member
, name
);
111 len
= lstrlenW( class ) + lstrlenW( member
) + ARRAY_SIZE(fmt2W
);
112 if (!(query
= malloc( len
* sizeof(WCHAR
) ))) return E_OUTOFMEMORY
;
113 swprintf( query
, len
, fmt2W
, class, member
);
117 len
= lstrlenW( class ) + ARRAY_SIZE(fmt3W
);
118 if (!(query
= malloc( len
* sizeof(WCHAR
) ))) return E_OUTOFMEMORY
;
119 swprintf( query
, len
, fmt3W
, class );
122 hr
= exec_query( ns
, query
, iter
);
127 static HRESULT
get_qualifier_value( enum wbm_namespace ns
, const WCHAR
*class, const WCHAR
*member
, const WCHAR
*name
,
128 VARIANT
*val
, LONG
*flavor
)
130 IEnumWbemClassObject
*iter
;
131 IWbemClassObject
*obj
;
135 hr
= create_qualifier_enum( ns
, class, member
, name
, &iter
);
136 if (FAILED( hr
)) return hr
;
138 hr
= create_class_object( ns
, NULL
, iter
, 0, NULL
, &obj
);
139 IEnumWbemClassObject_Release( iter
);
140 if (FAILED( hr
)) return hr
;
144 hr
= IWbemClassObject_Get( obj
, L
"Flavor", 0, &var
, NULL
, NULL
);
145 if (hr
!= S_OK
) goto done
;
146 *flavor
= V_I4( &var
);
148 hr
= IWbemClassObject_Get( obj
, L
"Type", 0, &var
, NULL
, NULL
);
149 if (hr
!= S_OK
) goto done
;
150 switch (V_UI4( &var
))
153 hr
= IWbemClassObject_Get( obj
, L
"StringValue", 0, val
, NULL
, NULL
);
156 hr
= IWbemClassObject_Get( obj
, L
"IntegerValue", 0, val
, NULL
, NULL
);
159 hr
= IWbemClassObject_Get( obj
, L
"BoolValue", 0, val
, NULL
, NULL
);
162 ERR( "unhandled type %lu\n", V_UI4( &var
) );
167 IWbemClassObject_Release( obj
);
171 static HRESULT WINAPI
qualifier_set_Get(
172 IWbemQualifierSet
*iface
,
178 struct qualifier_set
*set
= impl_from_IWbemQualifierSet( iface
);
180 TRACE( "%p, %s, %#lx, %p, %p\n", iface
, debugstr_w(wszName
), lFlags
, pVal
, plFlavor
);
183 FIXME( "flags %#lx not supported\n", lFlags
);
186 return get_qualifier_value( set
->ns
, set
->class, set
->member
, wszName
, pVal
, plFlavor
);
189 static HRESULT WINAPI
qualifier_set_Put(
190 IWbemQualifierSet
*iface
,
195 FIXME( "%p, %s, %p, %ld\n", iface
, debugstr_w(wszName
), pVal
, lFlavor
);
199 static HRESULT WINAPI
qualifier_set_Delete(
200 IWbemQualifierSet
*iface
,
203 FIXME("%p, %s\n", iface
, debugstr_w(wszName
));
207 static HRESULT WINAPI
qualifier_set_GetNames(
208 IWbemQualifierSet
*iface
,
212 struct qualifier_set
*set
= impl_from_IWbemQualifierSet( iface
);
213 IEnumWbemClassObject
*iter
;
214 IWbemClassObject
*obj
;
217 TRACE( "%p, %#lx, %p\n", iface
, lFlags
, pNames
);
220 FIXME( "flags %#lx not supported\n", lFlags
);
224 hr
= create_qualifier_enum( set
->ns
, set
->class, set
->member
, NULL
, &iter
);
225 if (FAILED( hr
)) return hr
;
227 hr
= create_class_object( set
->ns
, NULL
, iter
, 0, NULL
, &obj
);
228 IEnumWbemClassObject_Release( iter
);
229 if (FAILED( hr
)) return hr
;
231 hr
= IWbemClassObject_GetNames( obj
, NULL
, 0, NULL
, pNames
);
232 IWbemClassObject_Release( obj
);
236 static HRESULT WINAPI
qualifier_set_BeginEnumeration(
237 IWbemQualifierSet
*iface
,
240 FIXME( "%p, %#lx\n", iface
, lFlags
);
244 static HRESULT WINAPI
qualifier_set_Next(
245 IWbemQualifierSet
*iface
,
251 FIXME( "%p, %#lx, %p, %p, %p\n", iface
, lFlags
, pstrName
, pVal
, plFlavor
);
255 static HRESULT WINAPI
qualifier_set_EndEnumeration(
256 IWbemQualifierSet
*iface
)
258 FIXME("%p\n", iface
);
262 static const IWbemQualifierSetVtbl qualifier_set_vtbl
=
264 qualifier_set_QueryInterface
,
265 qualifier_set_AddRef
,
266 qualifier_set_Release
,
269 qualifier_set_Delete
,
270 qualifier_set_GetNames
,
271 qualifier_set_BeginEnumeration
,
273 qualifier_set_EndEnumeration
276 HRESULT
WbemQualifierSet_create( enum wbm_namespace ns
, const WCHAR
*class, const WCHAR
*member
, LPVOID
*ppObj
)
278 struct qualifier_set
*set
;
280 TRACE("%p\n", ppObj
);
282 if (!(set
= malloc( sizeof(*set
) ))) return E_OUTOFMEMORY
;
284 set
->IWbemQualifierSet_iface
.lpVtbl
= &qualifier_set_vtbl
;
285 if (!(set
->class = wcsdup( class )))
288 return E_OUTOFMEMORY
;
290 if (!member
) set
->member
= NULL
;
291 else if (!(set
->member
= wcsdup( member
)))
295 return E_OUTOFMEMORY
;
300 *ppObj
= &set
->IWbemQualifierSet_iface
;
302 TRACE("returning iface %p\n", *ppObj
);