msdmo: Actually copy output string in IEnumDMO_fnNext.
[wine.git] / dlls / wbemprox / qualifier.c
blob4da34454aedbf70697df18e32a0bcf3921a06ab7
1 /*
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 COBJMACROS
21 #include "config.h"
22 #include <stdarg.h>
24 #include "windef.h"
25 #include "winbase.h"
26 #include "objbase.h"
27 #include "wbemcli.h"
29 #include "wine/debug.h"
30 #include "wbemprox_private.h"
32 WINE_DEFAULT_DEBUG_CHANNEL(wbemprox);
34 struct qualifier_set
36 IWbemQualifierSet IWbemQualifierSet_iface;
37 LONG refs;
38 WCHAR *class;
39 WCHAR *member;
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 );
60 if (!refs)
62 TRACE("destroying %p\n", set);
63 heap_free( set->class );
64 heap_free( set->member );
65 heap_free( set );
67 return refs;
70 static HRESULT WINAPI qualifier_set_QueryInterface(
71 IWbemQualifierSet *iface,
72 REFIID riid,
73 void **ppvObject )
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 ) )
82 *ppvObject = set;
84 else
86 FIXME("interface %s not implemented\n", debugstr_guid(riid));
87 return E_NOINTERFACE;
89 IWbemQualifierSet_AddRef( iface );
90 return S_OK;
93 static HRESULT create_qualifier_enum( const WCHAR *class, const WCHAR *member, const WCHAR *name,
94 IEnumWbemClassObject **iter )
96 static const WCHAR fmtW[] =
97 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ','_','_','Q','U','A','L',
98 'I','F','I','E','R','S',' ','W','H','E','R','E',' ','C','l','a','s','s','=',
99 '\'','%','s','\'',' ','A','N','D',' ','M','e','m','b','e','r','=','\'','%','s','\'',' ',
100 'A','N','D',' ','N','a','m','e','=','\'','%','s','\'',0};
101 static const WCHAR fmt2W[] =
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','\'',0};
105 static const WCHAR noneW[] = {'_','_','N','O','N','E',0};
106 WCHAR *query;
107 HRESULT hr;
108 int len;
110 if (!member) member = noneW;
111 len = strlenW( class ) + strlenW( member );
112 if (name) len += strlenW( name ) + SIZEOF(fmtW);
113 else len += SIZEOF(fmt2W);
115 if (!(query = heap_alloc( len * sizeof(WCHAR) ))) return E_OUTOFMEMORY;
116 if (name) sprintfW( query, fmtW, class, member, name );
117 else sprintfW( query, fmt2W, class, member );
119 hr = exec_query( query, iter );
120 heap_free( query );
121 return hr;
124 static HRESULT get_qualifier_value( const WCHAR *class, const WCHAR *member, const WCHAR *name,
125 VARIANT *val, LONG *flavor )
127 static const WCHAR qualifiersW[] = {'_','_','Q','U','A','L','I','F','I','E','R','S',0};
128 static const WCHAR intvalueW[] = {'I','n','t','e','g','e','r','V','a','l','u','e',0};
129 static const WCHAR strvalueW[] = {'S','t','r','i','n','g','V','a','l','u','e',0};
130 static const WCHAR flavorW[] = {'F','l','a','v','o','r',0};
131 static const WCHAR typeW[] = {'T','y','p','e',0};
132 IEnumWbemClassObject *iter;
133 IWbemClassObject *obj;
134 VARIANT var;
135 HRESULT hr;
137 hr = create_qualifier_enum( class, member, name, &iter );
138 if (FAILED( hr )) return hr;
140 hr = create_class_object( qualifiersW, iter, 0, NULL, &obj );
141 IEnumWbemClassObject_Release( iter );
142 if (FAILED( hr )) return hr;
144 if (flavor)
146 hr = IWbemClassObject_Get( obj, flavorW, 0, &var, NULL, NULL );
147 if (hr != S_OK) goto done;
148 *flavor = V_I4( &var );
150 hr = IWbemClassObject_Get( obj, typeW, 0, &var, NULL, NULL );
151 if (hr != S_OK) goto done;
152 switch (V_UI4( &var ))
154 case CIM_STRING:
155 hr = IWbemClassObject_Get( obj, strvalueW, 0, val, NULL, NULL );
156 break;
157 case CIM_SINT32:
158 hr = IWbemClassObject_Get( obj, intvalueW, 0, val, NULL, NULL );
159 break;
160 default:
161 ERR("unhandled type %u\n", V_UI4( &var ));
162 break;
165 done:
166 IWbemClassObject_Release( obj );
167 return hr;
170 static HRESULT WINAPI qualifier_set_Get(
171 IWbemQualifierSet *iface,
172 LPCWSTR wszName,
173 LONG lFlags,
174 VARIANT *pVal,
175 LONG *plFlavor )
177 struct qualifier_set *set = impl_from_IWbemQualifierSet( iface );
179 FIXME("%p, %s, %08x, %p, %p\n", iface, debugstr_w(wszName), lFlags, pVal, plFlavor);
180 return get_qualifier_value( set->class, set->member, wszName, pVal, plFlavor );
183 static HRESULT WINAPI qualifier_set_Put(
184 IWbemQualifierSet *iface,
185 LPCWSTR wszName,
186 VARIANT *pVal,
187 LONG lFlavor )
189 FIXME("%p, %s, %p, %d\n", iface, debugstr_w(wszName), pVal, lFlavor);
190 return E_NOTIMPL;
193 static HRESULT WINAPI qualifier_set_Delete(
194 IWbemQualifierSet *iface,
195 LPCWSTR wszName )
197 FIXME("%p, %s\n", iface, debugstr_w(wszName));
198 return E_NOTIMPL;
201 static HRESULT WINAPI qualifier_set_GetNames(
202 IWbemQualifierSet *iface,
203 LONG lFlags,
204 SAFEARRAY **pNames )
206 FIXME("%p, %08x, %p\n", iface, lFlags, pNames);
207 return E_NOTIMPL;
210 static HRESULT WINAPI qualifier_set_BeginEnumeration(
211 IWbemQualifierSet *iface,
212 LONG lFlags )
214 FIXME("%p, %08x\n", iface, lFlags);
215 return E_NOTIMPL;
218 static HRESULT WINAPI qualifier_set_Next(
219 IWbemQualifierSet *iface,
220 LONG lFlags,
221 BSTR *pstrName,
222 VARIANT *pVal,
223 LONG *plFlavor )
225 FIXME("%p, %08x, %p, %p, %p\n", iface, lFlags, pstrName, pVal, plFlavor);
226 return E_NOTIMPL;
229 static HRESULT WINAPI qualifier_set_EndEnumeration(
230 IWbemQualifierSet *iface )
232 FIXME("%p\n", iface);
233 return E_NOTIMPL;
236 static const IWbemQualifierSetVtbl qualifier_set_vtbl =
238 qualifier_set_QueryInterface,
239 qualifier_set_AddRef,
240 qualifier_set_Release,
241 qualifier_set_Get,
242 qualifier_set_Put,
243 qualifier_set_Delete,
244 qualifier_set_GetNames,
245 qualifier_set_BeginEnumeration,
246 qualifier_set_Next,
247 qualifier_set_EndEnumeration
250 HRESULT WbemQualifierSet_create( const WCHAR *class, const WCHAR *member, LPVOID *ppObj )
252 struct qualifier_set *set;
254 TRACE("%p\n", ppObj);
256 if (!(set = heap_alloc( sizeof(*set) ))) return E_OUTOFMEMORY;
258 set->IWbemQualifierSet_iface.lpVtbl = &qualifier_set_vtbl;
259 if (!(set->class = heap_strdupW( class )))
261 heap_free( set );
262 return E_OUTOFMEMORY;
264 if (!member) set->member = NULL;
265 else if (!(set->member = heap_strdupW( member )))
267 heap_free( set->class );
268 heap_free( set );
269 return E_OUTOFMEMORY;
271 set->refs = 1;
273 *ppObj = &set->IWbemQualifierSet_iface;
275 TRACE("returning iface %p\n", *ppObj);
276 return S_OK;