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
19 #define WIN32_NO_STATUS
21 #define COM_NO_WINDOWS_H
34 #include "wine/debug.h"
35 #include "wbemprox_private.h"
37 WINE_DEFAULT_DEBUG_CHANNEL(wbemprox
);
41 IWbemQualifierSet IWbemQualifierSet_iface
;
47 static inline struct qualifier_set
*impl_from_IWbemQualifierSet(
48 IWbemQualifierSet
*iface
)
50 return CONTAINING_RECORD(iface
, struct qualifier_set
, IWbemQualifierSet_iface
);
53 static ULONG WINAPI
qualifier_set_AddRef(
54 IWbemQualifierSet
*iface
)
56 struct qualifier_set
*set
= impl_from_IWbemQualifierSet( iface
);
57 return InterlockedIncrement( &set
->refs
);
60 static ULONG WINAPI
qualifier_set_Release(
61 IWbemQualifierSet
*iface
)
63 struct qualifier_set
*set
= impl_from_IWbemQualifierSet( iface
);
64 LONG refs
= InterlockedDecrement( &set
->refs
);
67 TRACE("destroying %p\n", set
);
68 heap_free( set
->class );
69 heap_free( set
->member
);
75 static HRESULT WINAPI
qualifier_set_QueryInterface(
76 IWbemQualifierSet
*iface
,
80 struct qualifier_set
*set
= impl_from_IWbemQualifierSet( iface
);
82 TRACE("%p, %s, %p\n", set
, debugstr_guid( riid
), ppvObject
);
84 if ( IsEqualGUID( riid
, &IID_IWbemQualifierSet
) ||
85 IsEqualGUID( riid
, &IID_IUnknown
) )
91 FIXME("interface %s not implemented\n", debugstr_guid(riid
));
94 IWbemQualifierSet_AddRef( iface
);
98 static HRESULT
create_qualifier_enum( const WCHAR
*class, const WCHAR
*member
, const WCHAR
*name
,
99 IEnumWbemClassObject
**iter
)
101 static const WCHAR fmtW
[] =
102 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ','_','_','Q','U','A','L',
103 'I','F','I','E','R','S',' ','W','H','E','R','E',' ','C','l','a','s','s','=',
104 '\'','%','s','\'',' ','A','N','D',' ','M','e','m','b','e','r','=','\'','%','s','\'',' ',
105 'A','N','D',' ','N','a','m','e','=','\'','%','s','\'',0};
106 static const WCHAR fmt2W
[] =
107 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ','_','_','Q','U','A','L',
108 'I','F','I','E','R','S',' ','W','H','E','R','E',' ','C','l','a','s','s','=',
109 '\'','%','s','\'',' ','A','N','D',' ','M','e','m','b','e','r','=','\'','%','s','\'',0};
110 static const WCHAR noneW
[] = {'_','_','N','O','N','E',0};
115 if (!member
) member
= noneW
;
116 len
= strlenW( class ) + strlenW( member
);
117 if (name
) len
+= strlenW( name
) + SIZEOF(fmtW
);
118 else len
+= SIZEOF(fmt2W
);
120 if (!(query
= heap_alloc( len
* sizeof(WCHAR
) ))) return E_OUTOFMEMORY
;
121 if (name
) sprintfW( query
, fmtW
, class, member
, name
);
122 else sprintfW( query
, fmt2W
, class, member
);
124 hr
= exec_query( query
, iter
);
129 static HRESULT
get_qualifier_value( const WCHAR
*class, const WCHAR
*member
, const WCHAR
*name
,
130 VARIANT
*val
, LONG
*flavor
)
132 static const WCHAR qualifiersW
[] = {'_','_','Q','U','A','L','I','F','I','E','R','S',0};
133 static const WCHAR intvalueW
[] = {'I','n','t','e','g','e','r','V','a','l','u','e',0};
134 static const WCHAR strvalueW
[] = {'S','t','r','i','n','g','V','a','l','u','e',0};
135 static const WCHAR flavorW
[] = {'F','l','a','v','o','r',0};
136 static const WCHAR typeW
[] = {'T','y','p','e',0};
137 IEnumWbemClassObject
*iter
;
138 IWbemClassObject
*obj
;
142 hr
= create_qualifier_enum( class, member
, name
, &iter
);
143 if (FAILED( hr
)) return hr
;
145 hr
= create_class_object( qualifiersW
, iter
, 0, NULL
, &obj
);
146 IEnumWbemClassObject_Release( iter
);
147 if (FAILED( hr
)) return hr
;
151 hr
= IWbemClassObject_Get( obj
, flavorW
, 0, &var
, NULL
, NULL
);
152 if (hr
!= S_OK
) goto done
;
153 *flavor
= V_I4( &var
);
155 hr
= IWbemClassObject_Get( obj
, typeW
, 0, &var
, NULL
, NULL
);
156 if (hr
!= S_OK
) goto done
;
157 switch (V_UI4( &var
))
160 hr
= IWbemClassObject_Get( obj
, strvalueW
, 0, val
, NULL
, NULL
);
163 hr
= IWbemClassObject_Get( obj
, intvalueW
, 0, val
, NULL
, NULL
);
166 ERR("unhandled type %u\n", V_UI4( &var
));
171 IWbemClassObject_Release( obj
);
175 static HRESULT WINAPI
qualifier_set_Get(
176 IWbemQualifierSet
*iface
,
182 struct qualifier_set
*set
= impl_from_IWbemQualifierSet( iface
);
184 FIXME("%p, %s, %08x, %p, %p\n", iface
, debugstr_w(wszName
), lFlags
, pVal
, plFlavor
);
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 FIXME("%p, %08x, %p\n", iface
, lFlags
, pNames
);
215 static HRESULT WINAPI
qualifier_set_BeginEnumeration(
216 IWbemQualifierSet
*iface
,
219 FIXME("%p, %08x\n", iface
, lFlags
);
223 static HRESULT WINAPI
qualifier_set_Next(
224 IWbemQualifierSet
*iface
,
230 FIXME("%p, %08x, %p, %p, %p\n", iface
, lFlags
, pstrName
, pVal
, plFlavor
);
234 static HRESULT WINAPI
qualifier_set_EndEnumeration(
235 IWbemQualifierSet
*iface
)
237 FIXME("%p\n", iface
);
241 static const IWbemQualifierSetVtbl qualifier_set_vtbl
=
243 qualifier_set_QueryInterface
,
244 qualifier_set_AddRef
,
245 qualifier_set_Release
,
248 qualifier_set_Delete
,
249 qualifier_set_GetNames
,
250 qualifier_set_BeginEnumeration
,
252 qualifier_set_EndEnumeration
255 HRESULT
WbemQualifierSet_create(
256 IUnknown
*pUnkOuter
, const WCHAR
*class, const WCHAR
*member
, LPVOID
*ppObj
)
258 struct qualifier_set
*set
;
260 TRACE("%p, %p\n", pUnkOuter
, ppObj
);
262 if (!(set
= heap_alloc( sizeof(*set
) ))) return E_OUTOFMEMORY
;
264 set
->IWbemQualifierSet_iface
.lpVtbl
= &qualifier_set_vtbl
;
265 if (!(set
->class = heap_strdupW( class )))
268 return E_OUTOFMEMORY
;
270 if (!member
) set
->member
= NULL
;
271 else if (!(set
->member
= heap_strdupW( member
)))
273 heap_free( set
->class );
275 return E_OUTOFMEMORY
;
279 *ppObj
= &set
->IWbemQualifierSet_iface
;
281 TRACE("returning iface %p\n", *ppObj
);