mshtml: Added IHTMLFrameBase::frameBorder implementation.
[wine] / dlls / wbemprox / class.c
1 /*
2  * Copyright 2012 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 "config.h"
22 #include <stdarg.h>
23
24 #include "windef.h"
25 #include "winbase.h"
26 #include "objbase.h"
27 #include "wbemcli.h"
28
29 #include "wine/debug.h"
30 #include "wbemprox_private.h"
31
32 WINE_DEFAULT_DEBUG_CHANNEL(wbemprox);
33
34 struct enum_class_object
35 {
36     IEnumWbemClassObject IEnumWbemClassObject_iface;
37     LONG refs;
38     struct query *query;
39     UINT index;
40 };
41
42 static inline struct enum_class_object *impl_from_IEnumWbemClassObject(
43     IEnumWbemClassObject *iface )
44 {
45     return CONTAINING_RECORD(iface, struct enum_class_object, IEnumWbemClassObject_iface);
46 }
47
48 static ULONG WINAPI enum_class_object_AddRef(
49     IEnumWbemClassObject *iface )
50 {
51     struct enum_class_object *ec = impl_from_IEnumWbemClassObject( iface );
52     return InterlockedIncrement( &ec->refs );
53 }
54
55 static ULONG WINAPI enum_class_object_Release(
56     IEnumWbemClassObject *iface )
57 {
58     struct enum_class_object *ec = impl_from_IEnumWbemClassObject( iface );
59     LONG refs = InterlockedDecrement( &ec->refs );
60     if (!refs)
61     {
62         TRACE("destroying %p\n", ec);
63         release_query( ec->query );
64         heap_free( ec );
65     }
66     return refs;
67 }
68
69 static HRESULT WINAPI enum_class_object_QueryInterface(
70     IEnumWbemClassObject *iface,
71     REFIID riid,
72     void **ppvObject )
73 {
74     struct enum_class_object *ec = impl_from_IEnumWbemClassObject( iface );
75
76     TRACE("%p, %s, %p\n", ec, debugstr_guid( riid ), ppvObject );
77
78     if ( IsEqualGUID( riid, &IID_IEnumWbemClassObject ) ||
79          IsEqualGUID( riid, &IID_IUnknown ) )
80     {
81         *ppvObject = ec;
82     }
83     else if ( IsEqualGUID( riid, &IID_IClientSecurity ) )
84     {
85         *ppvObject = &client_security;
86         return S_OK;
87     }
88     else
89     {
90         FIXME("interface %s not implemented\n", debugstr_guid(riid));
91         return E_NOINTERFACE;
92     }
93     IEnumWbemClassObject_AddRef( iface );
94     return S_OK;
95 }
96
97 static HRESULT WINAPI enum_class_object_Reset(
98     IEnumWbemClassObject *iface )
99 {
100     struct enum_class_object *ec = impl_from_IEnumWbemClassObject( iface );
101
102     TRACE("%p\n", iface);
103
104     ec->index = 0;
105     return WBEM_S_NO_ERROR;
106 }
107
108 static HRESULT WINAPI enum_class_object_Next(
109     IEnumWbemClassObject *iface,
110     LONG lTimeout,
111     ULONG uCount,
112     IWbemClassObject **apObjects,
113     ULONG *puReturned )
114 {
115     struct enum_class_object *ec = impl_from_IEnumWbemClassObject( iface );
116     struct view *view = ec->query->view;
117     HRESULT hr;
118
119     TRACE("%p, %d, %u, %p, %p\n", iface, lTimeout, uCount, apObjects, puReturned);
120
121     if (!uCount) return WBEM_S_FALSE;
122     if (!apObjects || !puReturned) return WBEM_E_INVALID_PARAMETER;
123     if (lTimeout != WBEM_INFINITE) FIXME("timeout not supported\n");
124
125     *puReturned = 0;
126     if (ec->index + uCount > view->count) return WBEM_S_FALSE;
127
128     hr = WbemClassObject_create( NULL, iface, ec->index, (void **)apObjects );
129     if (hr != S_OK) return hr;
130
131     ec->index++;
132     *puReturned = 1;
133     if (ec->index == view->count) return WBEM_S_FALSE;
134     if (uCount > 1) return WBEM_S_TIMEDOUT;
135     return WBEM_S_NO_ERROR;
136 }
137
138 static HRESULT WINAPI enum_class_object_NextAsync(
139     IEnumWbemClassObject *iface,
140     ULONG uCount,
141     IWbemObjectSink *pSink )
142 {
143     FIXME("%p, %u, %p\n", iface, uCount, pSink);
144     return E_NOTIMPL;
145 }
146
147 static HRESULT WINAPI enum_class_object_Clone(
148     IEnumWbemClassObject *iface,
149     IEnumWbemClassObject **ppEnum )
150 {
151     struct enum_class_object *ec = impl_from_IEnumWbemClassObject( iface );
152
153     TRACE("%p, %p\n", iface, ppEnum);
154
155     return EnumWbemClassObject_create( NULL, ec->query, (void **)ppEnum );
156 }
157
158 static HRESULT WINAPI enum_class_object_Skip(
159     IEnumWbemClassObject *iface,
160     LONG lTimeout,
161     ULONG nCount )
162 {
163     struct enum_class_object *ec = impl_from_IEnumWbemClassObject( iface );
164     struct view *view = ec->query->view;
165
166     TRACE("%p, %d, %u\n", iface, lTimeout, nCount);
167
168     if (lTimeout != WBEM_INFINITE) FIXME("timeout not supported\n");
169
170     if (ec->index + nCount >= view->count)
171     {
172         ec->index = view->count - 1;
173         return WBEM_S_FALSE;
174     }
175     ec->index += nCount;
176     return WBEM_S_NO_ERROR;
177 }
178
179 static const IEnumWbemClassObjectVtbl enum_class_object_vtbl =
180 {
181     enum_class_object_QueryInterface,
182     enum_class_object_AddRef,
183     enum_class_object_Release,
184     enum_class_object_Reset,
185     enum_class_object_Next,
186     enum_class_object_NextAsync,
187     enum_class_object_Clone,
188     enum_class_object_Skip
189 };
190
191 HRESULT EnumWbemClassObject_create(
192     IUnknown *pUnkOuter, struct query *query, LPVOID *ppObj )
193 {
194     struct enum_class_object *ec;
195
196     TRACE("%p, %p\n", pUnkOuter, ppObj);
197
198     ec = heap_alloc( sizeof(*ec) );
199     if (!ec) return E_OUTOFMEMORY;
200
201     ec->IEnumWbemClassObject_iface.lpVtbl = &enum_class_object_vtbl;
202     ec->refs  = 1;
203     ec->query = query;
204     addref_query( query );
205     ec->index = 0;
206
207     *ppObj = &ec->IEnumWbemClassObject_iface;
208
209     TRACE("returning iface %p\n", *ppObj);
210     return S_OK;
211 }
212
213 struct class_object
214 {
215     IWbemClassObject IWbemClassObject_iface;
216     LONG refs;
217     IEnumWbemClassObject *iter;
218     UINT index;
219 };
220
221 static inline struct class_object *impl_from_IWbemClassObject(
222     IWbemClassObject *iface )
223 {
224     return CONTAINING_RECORD(iface, struct class_object, IWbemClassObject_iface);
225 }
226
227 static ULONG WINAPI class_object_AddRef(
228     IWbemClassObject *iface )
229 {
230     struct class_object *co = impl_from_IWbemClassObject( iface );
231     return InterlockedIncrement( &co->refs );
232 }
233
234 static ULONG WINAPI class_object_Release(
235     IWbemClassObject *iface )
236 {
237     struct class_object *co = impl_from_IWbemClassObject( iface );
238     LONG refs = InterlockedDecrement( &co->refs );
239     if (!refs)
240     {
241         TRACE("destroying %p\n", co);
242         if (co->iter) IEnumWbemClassObject_Release( co->iter );
243         heap_free( co );
244     }
245     return refs;
246 }
247
248 static HRESULT WINAPI class_object_QueryInterface(
249     IWbemClassObject *iface,
250     REFIID riid,
251     void **ppvObject )
252 {
253     struct class_object *co = impl_from_IWbemClassObject( iface );
254
255     TRACE("%p, %s, %p\n", co, debugstr_guid( riid ), ppvObject );
256
257     if ( IsEqualGUID( riid, &IID_IWbemClassObject ) ||
258          IsEqualGUID( riid, &IID_IUnknown ) )
259     {
260         *ppvObject = co;
261     }
262     else
263     {
264         FIXME("interface %s not implemented\n", debugstr_guid(riid));
265         return E_NOINTERFACE;
266     }
267     IWbemClassObject_AddRef( iface );
268     return S_OK;
269 }
270
271 static HRESULT WINAPI class_object_GetQualifierSet(
272     IWbemClassObject *iface,
273     IWbemQualifierSet **ppQualSet )
274 {
275     FIXME("%p, %p\n", iface, ppQualSet);
276     return E_NOTIMPL;
277 }
278
279 static HRESULT WINAPI class_object_Get(
280     IWbemClassObject *iface,
281     LPCWSTR wszName,
282     LONG lFlags,
283     VARIANT *pVal,
284     CIMTYPE *pType,
285     LONG *plFlavor )
286 {
287     struct class_object *co = impl_from_IWbemClassObject( iface );
288     struct enum_class_object *ec = impl_from_IEnumWbemClassObject( co->iter );
289     struct view *view = ec->query->view;
290
291     TRACE("%p, %s, %08x, %p, %p, %p\n", iface, debugstr_w(wszName), lFlags, pVal, pType, plFlavor);
292
293     return get_propval( view, co->index, wszName, pVal, pType, plFlavor );
294 }
295
296 static HRESULT WINAPI class_object_Put(
297     IWbemClassObject *iface,
298     LPCWSTR wszName,
299     LONG lFlags,
300     VARIANT *pVal,
301     CIMTYPE Type )
302 {
303     FIXME("%p, %s, %08x, %p, %u\n", iface, debugstr_w(wszName), lFlags, pVal, Type);
304     return E_NOTIMPL;
305 }
306
307 static HRESULT WINAPI class_object_Delete(
308     IWbemClassObject *iface,
309     LPCWSTR wszName )
310 {
311     FIXME("%p, %s\n", iface, debugstr_w(wszName));
312     return E_NOTIMPL;
313 }
314
315 static HRESULT WINAPI class_object_GetNames(
316     IWbemClassObject *iface,
317     LPCWSTR wszQualifierName,
318     LONG lFlags,
319     VARIANT *pQualifierVal,
320     SAFEARRAY **pNames )
321 {
322     struct class_object *co = impl_from_IWbemClassObject( iface );
323     struct enum_class_object *ec = impl_from_IEnumWbemClassObject( co->iter );
324
325     TRACE("%p, %s, %08x, %p, %p\n", iface, debugstr_w(wszQualifierName), lFlags, pQualifierVal, pNames);
326
327     if (wszQualifierName || pQualifierVal)
328     {
329         FIXME("qualifier not supported\n");
330         return E_NOTIMPL;
331     }
332     if (lFlags != WBEM_FLAG_ALWAYS)
333     {
334         FIXME("flags %08x not supported\n", lFlags);
335         return E_NOTIMPL;
336     }
337     return get_properties( ec->query->view, pNames );
338 }
339
340 static HRESULT WINAPI class_object_BeginEnumeration(
341     IWbemClassObject *iface,
342     LONG lEnumFlags )
343 {
344     FIXME("%p, %08x\n", iface, lEnumFlags);
345     return E_NOTIMPL;
346 }
347
348 static HRESULT WINAPI class_object_Next(
349     IWbemClassObject *iface,
350     LONG lFlags,
351     BSTR *strName,
352     VARIANT *pVal,
353     CIMTYPE *pType,
354     LONG *plFlavor )
355 {
356     FIXME("%p, %08x, %p, %p, %p, %p\n", iface, lFlags, strName, pVal, pType, plFlavor);
357     return E_NOTIMPL;
358 }
359
360 static HRESULT WINAPI class_object_EndEnumeration(
361     IWbemClassObject *iface )
362 {
363     FIXME("%p\n", iface);
364     return E_NOTIMPL;
365 }
366
367 static HRESULT WINAPI class_object_GetPropertyQualifierSet(
368     IWbemClassObject *iface,
369     LPCWSTR wszProperty,
370     IWbemQualifierSet **ppQualSet )
371 {
372     FIXME("%p, %s, %p\n", iface, debugstr_w(wszProperty), ppQualSet);
373     return E_NOTIMPL;
374 }
375
376 static HRESULT WINAPI class_object_Clone(
377     IWbemClassObject *iface,
378     IWbemClassObject **ppCopy )
379 {
380     FIXME("%p, %p\n", iface, ppCopy);
381     return E_NOTIMPL;
382 }
383
384 static HRESULT WINAPI class_object_GetObjectText(
385     IWbemClassObject *iface,
386     LONG lFlags,
387     BSTR *pstrObjectText )
388 {
389     FIXME("%p, %08x, %p\n", iface, lFlags, pstrObjectText);
390     return E_NOTIMPL;
391 }
392
393 static HRESULT WINAPI class_object_SpawnDerivedClass(
394     IWbemClassObject *iface,
395     LONG lFlags,
396     IWbemClassObject **ppNewClass )
397 {
398     FIXME("%p, %08x, %p\n", iface, lFlags, ppNewClass);
399     return E_NOTIMPL;
400 }
401
402 static HRESULT WINAPI class_object_SpawnInstance(
403     IWbemClassObject *iface,
404     LONG lFlags,
405     IWbemClassObject **ppNewInstance )
406 {
407     FIXME("%p, %08x, %p\n", iface, lFlags, ppNewInstance);
408     return E_NOTIMPL;
409 }
410
411 static HRESULT WINAPI class_object_CompareTo(
412     IWbemClassObject *iface,
413     LONG lFlags,
414     IWbemClassObject *pCompareTo )
415 {
416     FIXME("%p, %08x, %p\n", iface, lFlags, pCompareTo);
417     return E_NOTIMPL;
418 }
419
420 static HRESULT WINAPI class_object_GetPropertyOrigin(
421     IWbemClassObject *iface,
422     LPCWSTR wszName,
423     BSTR *pstrClassName )
424 {
425     FIXME("%p, %s, %p\n", iface, debugstr_w(wszName), pstrClassName);
426     return E_NOTIMPL;
427 }
428
429 static HRESULT WINAPI class_object_InheritsFrom(
430     IWbemClassObject *iface,
431     LPCWSTR strAncestor )
432 {
433     FIXME("%p, %s\n", iface, debugstr_w(strAncestor));
434     return E_NOTIMPL;
435 }
436
437 static HRESULT WINAPI class_object_GetMethod(
438     IWbemClassObject *iface,
439     LPCWSTR wszName,
440     LONG lFlags,
441     IWbemClassObject **ppInSignature,
442     IWbemClassObject **ppOutSignature )
443 {
444     FIXME("%p, %s, %08x, %p, %p\n", iface, debugstr_w(wszName), lFlags, ppInSignature, ppOutSignature);
445     return E_NOTIMPL;
446 }
447
448 static HRESULT WINAPI class_object_PutMethod(
449     IWbemClassObject *iface,
450     LPCWSTR wszName,
451     LONG lFlags,
452     IWbemClassObject *pInSignature,
453     IWbemClassObject *pOutSignature )
454 {
455     FIXME("%p, %s, %08x, %p, %p\n", iface, debugstr_w(wszName), lFlags, pInSignature, pOutSignature);
456     return E_NOTIMPL;
457 }
458
459 static HRESULT WINAPI class_object_DeleteMethod(
460     IWbemClassObject *iface,
461     LPCWSTR wszName )
462 {
463     FIXME("%p, %s\n", iface, debugstr_w(wszName));
464     return E_NOTIMPL;
465 }
466
467 static HRESULT WINAPI class_object_BeginMethodEnumeration(
468     IWbemClassObject *iface,
469     LONG lEnumFlags)
470 {
471     FIXME("%p, %08x\n", iface, lEnumFlags);
472     return E_NOTIMPL;
473 }
474
475 static HRESULT WINAPI class_object_NextMethod(
476     IWbemClassObject *iface,
477     LONG lFlags,
478     BSTR *pstrName,
479     IWbemClassObject **ppInSignature,
480     IWbemClassObject **ppOutSignature)
481 {
482     FIXME("%p, %08x, %p, %p, %p\n", iface, lFlags, pstrName, ppInSignature, ppOutSignature);
483     return E_NOTIMPL;
484 }
485
486 static HRESULT WINAPI class_object_EndMethodEnumeration(
487     IWbemClassObject *iface )
488 {
489     FIXME("%p\n", iface);
490     return E_NOTIMPL;
491 }
492
493 static HRESULT WINAPI class_object_GetMethodQualifierSet(
494     IWbemClassObject *iface,
495     LPCWSTR wszMethod,
496     IWbemQualifierSet **ppQualSet)
497 {
498     FIXME("%p, %s, %p\n", iface, debugstr_w(wszMethod), ppQualSet);
499     return E_NOTIMPL;
500 }
501
502 static HRESULT WINAPI class_object_GetMethodOrigin(
503     IWbemClassObject *iface,
504     LPCWSTR wszMethodName,
505     BSTR *pstrClassName)
506 {
507     FIXME("%p, %s, %p\n", iface, debugstr_w(wszMethodName), pstrClassName);
508     return E_NOTIMPL;
509 }
510
511 static const IWbemClassObjectVtbl class_object_vtbl =
512 {
513     class_object_QueryInterface,
514     class_object_AddRef,
515     class_object_Release,
516     class_object_GetQualifierSet,
517     class_object_Get,
518     class_object_Put,
519     class_object_Delete,
520     class_object_GetNames,
521     class_object_BeginEnumeration,
522     class_object_Next,
523     class_object_EndEnumeration,
524     class_object_GetPropertyQualifierSet,
525     class_object_Clone,
526     class_object_GetObjectText,
527     class_object_SpawnDerivedClass,
528     class_object_SpawnInstance,
529     class_object_CompareTo,
530     class_object_GetPropertyOrigin,
531     class_object_InheritsFrom,
532     class_object_GetMethod,
533     class_object_PutMethod,
534     class_object_DeleteMethod,
535     class_object_BeginMethodEnumeration,
536     class_object_NextMethod,
537     class_object_EndMethodEnumeration,
538     class_object_GetMethodQualifierSet,
539     class_object_GetMethodOrigin
540 };
541
542 HRESULT WbemClassObject_create(
543     IUnknown *pUnkOuter, IEnumWbemClassObject *iter, UINT index, LPVOID *ppObj )
544 {
545     struct class_object *co;
546
547     TRACE("%p, %p\n", pUnkOuter, ppObj);
548
549     co = heap_alloc( sizeof(*co) );
550     if (!co) return E_OUTOFMEMORY;
551
552     co->IWbemClassObject_iface.lpVtbl = &class_object_vtbl;
553     co->refs  = 1;
554     co->iter  = iter;
555     co->index = index;
556     if (iter) IEnumWbemClassObject_AddRef( iter );
557
558     *ppObj = &co->IWbemClassObject_iface;
559
560     TRACE("returning iface %p\n", *ppObj);
561     return S_OK;
562 }