ReactOS  0.4.15-dev-489-g75a0787
qualifier.c
Go to the documentation of this file.
1 /*
2  * Copyright 2013 Hans Leidekker for CodeWeavers
3  *
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.
8  *
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.
13  *
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
17  */
18 
19 #define COBJMACROS
20 
21 #include <stdarg.h>
22 #ifdef __REACTOS__
23 #include <wchar.h>
24 #endif
25 
26 #include "windef.h"
27 #include "winbase.h"
28 #include "objbase.h"
29 #include "wbemcli.h"
30 
31 #include "wine/debug.h"
32 #include "wbemprox_private.h"
33 
35 
37 {
40  WCHAR *class;
42 };
43 
45  IWbemQualifierSet *iface )
46 {
48 }
49 
51  IWbemQualifierSet *iface )
52 {
54  return InterlockedIncrement( &set->refs );
55 }
56 
58  IWbemQualifierSet *iface )
59 {
61  LONG refs = InterlockedDecrement( &set->refs );
62  if (!refs)
63  {
64  TRACE("destroying %p\n", set);
65  heap_free( set->class );
66  heap_free( set->member );
67  heap_free( set );
68  }
69  return refs;
70 }
71 
73  IWbemQualifierSet *iface,
74  REFIID riid,
75  void **ppvObject )
76 {
78 
79  TRACE("%p, %s, %p\n", set, debugstr_guid( riid ), ppvObject );
80 
81  if ( IsEqualGUID( riid, &IID_IWbemQualifierSet ) ||
83  {
84  *ppvObject = set;
85  }
86  else
87  {
88  FIXME("interface %s not implemented\n", debugstr_guid(riid));
89  return E_NOINTERFACE;
90  }
91  IWbemQualifierSet_AddRef( iface );
92  return S_OK;
93 }
94 
95 static HRESULT create_qualifier_enum( const WCHAR *class, const WCHAR *member, const WCHAR *name,
96  IEnumWbemClassObject **iter )
97 {
98  static const WCHAR fmtW[] =
99  {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ','_','_','Q','U','A','L',
100  'I','F','I','E','R','S',' ','W','H','E','R','E',' ','C','l','a','s','s','=',
101  '\'','%','s','\'',' ','A','N','D',' ','M','e','m','b','e','r','=','\'','%','s','\'',' ',
102  'A','N','D',' ','N','a','m','e','=','\'','%','s','\'',0};
103  static const WCHAR fmt2W[] =
104  {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ','_','_','Q','U','A','L',
105  'I','F','I','E','R','S',' ','W','H','E','R','E',' ','C','l','a','s','s','=',
106  '\'','%','s','\'',' ','A','N','D',' ','M','e','m','b','e','r','=','\'','%','s','\'',0};
107  static const WCHAR fmt3W[] =
108  {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ','_','_','Q','U','A','L',
109  'I','F','I','E','R','S',' ','W','H','E','R','E',' ','C','l','a','s','s','=',
110  '\'','%','s','\'',0};
111  WCHAR *query;
112  HRESULT hr;
113  int len;
114 
115  if (member && name)
116  {
117  len = lstrlenW( class ) + lstrlenW( member ) + lstrlenW( name ) + ARRAY_SIZE(fmtW);
118  if (!(query = heap_alloc( len * sizeof(WCHAR) ))) return E_OUTOFMEMORY;
119  swprintf( query, fmtW, class, member, name );
120  }
121  else if (member)
122  {
123  len = lstrlenW( class ) + lstrlenW( member ) + ARRAY_SIZE(fmt2W);
124  if (!(query = heap_alloc( len * sizeof(WCHAR) ))) return E_OUTOFMEMORY;
125  swprintf( query, fmt2W, class, member );
126  }
127  else
128  {
129  len = lstrlenW( class ) + ARRAY_SIZE(fmt3W);
130  if (!(query = heap_alloc( len * sizeof(WCHAR) ))) return E_OUTOFMEMORY;
131  swprintf( query, fmt3W, class );
132  }
133 
134  hr = exec_query( query, iter );
135  heap_free( query );
136  return hr;
137 }
138 
139 static HRESULT get_qualifier_value( const WCHAR *class, const WCHAR *member, const WCHAR *name,
140  VARIANT *val, LONG *flavor )
141 {
142  static const WCHAR intvalueW[] = {'I','n','t','e','g','e','r','V','a','l','u','e',0};
143  static const WCHAR strvalueW[] = {'S','t','r','i','n','g','V','a','l','u','e',0};
144  static const WCHAR boolvalueW[] = {'B','o','o','l','V','a','l','u','e',0};
145  static const WCHAR flavorW[] = {'F','l','a','v','o','r',0};
146  static const WCHAR typeW[] = {'T','y','p','e',0};
147  IEnumWbemClassObject *iter;
149  VARIANT var;
150  HRESULT hr;
151 
152  hr = create_qualifier_enum( class, member, name, &iter );
153  if (FAILED( hr )) return hr;
154 
155  hr = create_class_object( NULL, iter, 0, NULL, &obj );
156  IEnumWbemClassObject_Release( iter );
157  if (FAILED( hr )) return hr;
158 
159  if (flavor)
160  {
161  hr = IWbemClassObject_Get( obj, flavorW, 0, &var, NULL, NULL );
162  if (hr != S_OK) goto done;
163  *flavor = V_I4( &var );
164  }
165  hr = IWbemClassObject_Get( obj, typeW, 0, &var, NULL, NULL );
166  if (hr != S_OK) goto done;
167  switch (V_UI4( &var ))
168  {
169  case CIM_STRING:
170  hr = IWbemClassObject_Get( obj, strvalueW, 0, val, NULL, NULL );
171  break;
172  case CIM_SINT32:
173  hr = IWbemClassObject_Get( obj, intvalueW, 0, val, NULL, NULL );
174  break;
175  case CIM_BOOLEAN:
176  hr = IWbemClassObject_Get( obj, boolvalueW, 0, val, NULL, NULL );
177  break;
178  default:
179  ERR("unhandled type %u\n", V_UI4( &var ));
180  break;
181  }
182 
183 done:
184  IWbemClassObject_Release( obj );
185  return hr;
186 }
187 
189  IWbemQualifierSet *iface,
190  LPCWSTR wszName,
191  LONG lFlags,
192  VARIANT *pVal,
193  LONG *plFlavor )
194 {
195  struct qualifier_set *set = impl_from_IWbemQualifierSet( iface );
196 
197  TRACE("%p, %s, %08x, %p, %p\n", iface, debugstr_w(wszName), lFlags, pVal, plFlavor);
198  if (lFlags)
199  {
200  FIXME("flags %08x not supported\n", lFlags);
201  return E_NOTIMPL;
202  }
203  return get_qualifier_value( set->class, set->member, wszName, pVal, plFlavor );
204 }
205 
207  IWbemQualifierSet *iface,
208  LPCWSTR wszName,
209  VARIANT *pVal,
210  LONG lFlavor )
211 {
212  FIXME("%p, %s, %p, %d\n", iface, debugstr_w(wszName), pVal, lFlavor);
213  return E_NOTIMPL;
214 }
215 
217  IWbemQualifierSet *iface,
218  LPCWSTR wszName )
219 {
220  FIXME("%p, %s\n", iface, debugstr_w(wszName));
221  return E_NOTIMPL;
222 }
223 
225  IWbemQualifierSet *iface,
226  LONG lFlags,
227  SAFEARRAY **pNames )
228 {
229  struct qualifier_set *set = impl_from_IWbemQualifierSet( iface );
230  IEnumWbemClassObject *iter;
232  HRESULT hr;
233 
234  TRACE("%p, %08x, %p\n", iface, lFlags, pNames);
235  if (lFlags)
236  {
237  FIXME("flags %08x not supported\n", lFlags);
238  return E_NOTIMPL;
239  }
240 
241  hr = create_qualifier_enum( set->class, set->member, NULL, &iter );
242  if (FAILED( hr )) return hr;
243 
244  hr = create_class_object( NULL, iter, 0, NULL, &obj );
245  IEnumWbemClassObject_Release( iter );
246  if (FAILED( hr )) return hr;
247 
248  hr = IWbemClassObject_GetNames( obj, NULL, 0, NULL, pNames );
249  IWbemClassObject_Release( obj );
250  return hr;
251 }
252 
254  IWbemQualifierSet *iface,
255  LONG lFlags )
256 {
257  FIXME("%p, %08x\n", iface, lFlags);
258  return E_NOTIMPL;
259 }
260 
262  IWbemQualifierSet *iface,
263  LONG lFlags,
264  BSTR *pstrName,
265  VARIANT *pVal,
266  LONG *plFlavor )
267 {
268  FIXME("%p, %08x, %p, %p, %p\n", iface, lFlags, pstrName, pVal, plFlavor);
269  return E_NOTIMPL;
270 }
271 
273  IWbemQualifierSet *iface )
274 {
275  FIXME("%p\n", iface);
276  return E_NOTIMPL;
277 }
278 
279 static const IWbemQualifierSetVtbl qualifier_set_vtbl =
280 {
291 };
292 
293 HRESULT WbemQualifierSet_create( const WCHAR *class, const WCHAR *member, LPVOID *ppObj )
294 {
295  struct qualifier_set *set;
296 
297  TRACE("%p\n", ppObj);
298 
299  if (!(set = heap_alloc( sizeof(*set) ))) return E_OUTOFMEMORY;
300 
301  set->IWbemQualifierSet_iface.lpVtbl = &qualifier_set_vtbl;
302  if (!(set->class = heap_strdupW( class )))
303  {
304  heap_free( set );
305  return E_OUTOFMEMORY;
306  }
307  if (!member) set->member = NULL;
308  else if (!(set->member = heap_strdupW( member )))
309  {
310  heap_free( set->class );
311  heap_free( set );
312  return E_OUTOFMEMORY;
313  }
314  set->refs = 1;
315 
316  *ppObj = &set->IWbemQualifierSet_iface;
317 
318  TRACE("returning iface %p\n", *ppObj);
319  return S_OK;
320 }
const char * var
Definition: shader.c:5666
static ULONG WINAPI qualifier_set_AddRef(IWbemQualifierSet *iface)
Definition: qualifier.c:50
#define REFIID
Definition: guiddef.h:118
WCHAR * member
Definition: qualifier.c:41
#define E_NOINTERFACE
Definition: winerror.h:2364
HRESULT hr
Definition: shlfolder.c:183
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185
REFIID riid
Definition: precomp.h:44
static HRESULT WINAPI qualifier_set_GetNames(IWbemQualifierSet *iface, LONG lFlags, SAFEARRAY **pNames)
Definition: qualifier.c:224
static HRESULT WINAPI qualifier_set_EndEnumeration(IWbemQualifierSet *iface)
Definition: qualifier.c:272
static const WCHAR typeW[]
Definition: name.c:51
static HRESULT WINAPI qualifier_set_QueryInterface(IWbemQualifierSet *iface, REFIID riid, void **ppvObject)
Definition: qualifier.c:72
static HRESULT WINAPI qualifier_set_Get(IWbemQualifierSet *iface, LPCWSTR wszName, LONG lFlags, VARIANT *pVal, LONG *plFlavor)
Definition: qualifier.c:188
OLECHAR * BSTR
Definition: compat.h:1943
#define lstrlenW
Definition: compat.h:416
static HRESULT WINAPI qualifier_set_Put(IWbemQualifierSet *iface, LPCWSTR wszName, VARIANT *pVal, LONG lFlavor)
Definition: qualifier.c:206
static void * heap_alloc(size_t len)
Definition: appwiz.h:65
#define V_I4(A)
Definition: oleauto.h:247
GLsizei GLsizei GLuint * obj
Definition: glext.h:6042
HRESULT WbemQualifierSet_create(const WCHAR *class, const WCHAR *member, LPVOID *ppObj)
Definition: qualifier.c:293
#define E_OUTOFMEMORY
Definition: ddrawi.h:100
long LONG
Definition: pedump.c:60
static ULONG WINAPI qualifier_set_Release(IWbemQualifierSet *iface)
Definition: qualifier.c:57
static WCHAR * heap_strdupW(const WCHAR *str)
Definition: propsheet.c:178
#define debugstr_w
Definition: kernel32.h:32
#define FIXME(fmt,...)
Definition: debug.h:111
smooth NULL
Definition: ftsmooth.c:416
static UINT set(struct ID3DXConstantTableImpl *table, IDirect3DDevice9 *device, struct ctab_constant *constant, const void **indata, D3DXPARAMETER_TYPE intype, UINT *size, UINT incol, D3DXPARAMETER_CLASS inclass, UINT index, BOOL is_pointer)
Definition: shader.c:1095
#define debugstr_guid
Definition: kernel32.h:35
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
GLuint GLfloat * val
Definition: glext.h:7180
#define TRACE(s)
Definition: solgame.cpp:4
__wchar_t WCHAR
Definition: xmlstorage.h:180
LONG HRESULT
Definition: typedefs.h:78
const GUID IID_IUnknown
static HRESULT get_qualifier_value(const WCHAR *class, const WCHAR *member, const WCHAR *name, VARIANT *val, LONG *flavor)
Definition: qualifier.c:139
#define swprintf(buf, format,...)
Definition: sprintf.c:56
#define WINAPI
Definition: msvc.h:6
#define V_UI4(A)
Definition: oleauto.h:270
IWbemQualifierSet IWbemQualifierSet_iface
Definition: qualifier.c:38
#define InterlockedDecrement
Definition: armddk.h:52
GLenum GLsizei len
Definition: glext.h:6722
REFIID LPVOID * ppvObject
Definition: precomp.h:44
static const IWbemQualifierSetVtbl qualifier_set_vtbl
Definition: qualifier.c:279
#define ERR(fmt,...)
Definition: debug.h:110
#define S_OK
Definition: intsafe.h:59
#define InterlockedIncrement
Definition: armddk.h:53
HRESULT create_class_object(const WCHAR *name, IEnumWbemClassObject *iter, UINT index, struct record *record, IWbemClassObject **obj)
Definition: class.c:1021
#define ARRAY_SIZE(a)
Definition: main.h:24
static struct qualifier_set * impl_from_IWbemQualifierSet(IWbemQualifierSet *iface)
Definition: qualifier.c:44
#define E_NOTIMPL
Definition: ddrawi.h:99
HRESULT exec_query(const WCHAR *str, IEnumWbemClassObject **result)
Definition: query.c:786
WINE_DEFAULT_DEBUG_CHANNEL(wbemprox)
BOOL WINAPI IsEqualGUID(REFGUID rguid1, REFGUID rguid2)
Definition: compobj.c:4112
static HRESULT WINAPI qualifier_set_Delete(IWbemQualifierSet *iface, LPCWSTR wszName)
Definition: qualifier.c:216
Definition: name.c:38
static HRESULT WINAPI qualifier_set_BeginEnumeration(IWbemQualifierSet *iface, LONG lFlags)
Definition: qualifier.c:253
unsigned int ULONG
Definition: retypes.h:1
static HRESULT WINAPI qualifier_set_Next(IWbemQualifierSet *iface, LONG lFlags, BSTR *pstrName, VARIANT *pVal, LONG *plFlavor)
Definition: qualifier.c:261
Definition: _set.h:46
GLenum query
Definition: glext.h:7781
static BOOL heap_free(void *mem)
Definition: appwiz.h:75
static HRESULT create_qualifier_enum(const WCHAR *class, const WCHAR *member, const WCHAR *name, IEnumWbemClassObject **iter)
Definition: qualifier.c:95