2 * Copyright 2012 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 #include "wbemprox_private.h"
21 struct enum_class_object
23 IEnumWbemClassObject IEnumWbemClassObject_iface
;
29 static inline struct enum_class_object
*impl_from_IEnumWbemClassObject(
30 IEnumWbemClassObject
*iface
)
32 return CONTAINING_RECORD(iface
, struct enum_class_object
, IEnumWbemClassObject_iface
);
35 static ULONG WINAPI
enum_class_object_AddRef(
36 IEnumWbemClassObject
*iface
)
38 struct enum_class_object
*ec
= impl_from_IEnumWbemClassObject( iface
);
39 return InterlockedIncrement( &ec
->refs
);
42 static ULONG WINAPI
enum_class_object_Release(
43 IEnumWbemClassObject
*iface
)
45 struct enum_class_object
*ec
= impl_from_IEnumWbemClassObject( iface
);
46 LONG refs
= InterlockedDecrement( &ec
->refs
);
49 TRACE("destroying %p\n", ec
);
50 release_query( ec
->query
);
56 static HRESULT WINAPI
enum_class_object_QueryInterface(
57 IEnumWbemClassObject
*iface
,
61 struct enum_class_object
*ec
= impl_from_IEnumWbemClassObject( iface
);
63 TRACE("%p, %s, %p\n", ec
, debugstr_guid( riid
), ppvObject
);
65 if ( IsEqualGUID( riid
, &IID_IEnumWbemClassObject
) ||
66 IsEqualGUID( riid
, &IID_IUnknown
) )
70 else if ( IsEqualGUID( riid
, &IID_IClientSecurity
) )
72 *ppvObject
= &client_security
;
77 FIXME("interface %s not implemented\n", debugstr_guid(riid
));
80 IEnumWbemClassObject_AddRef( iface
);
84 static HRESULT WINAPI
enum_class_object_Reset(
85 IEnumWbemClassObject
*iface
)
87 struct enum_class_object
*ec
= impl_from_IEnumWbemClassObject( iface
);
92 return WBEM_S_NO_ERROR
;
95 static HRESULT WINAPI
enum_class_object_Next(
96 IEnumWbemClassObject
*iface
,
99 IWbemClassObject
**apObjects
,
102 struct enum_class_object
*ec
= impl_from_IEnumWbemClassObject( iface
);
103 struct view
*view
= ec
->query
->view
;
106 TRACE("%p, %d, %u, %p, %p\n", iface
, lTimeout
, uCount
, apObjects
, puReturned
);
108 if (!uCount
) return WBEM_S_FALSE
;
109 if (!apObjects
|| !puReturned
) return WBEM_E_INVALID_PARAMETER
;
110 if (lTimeout
!= WBEM_INFINITE
) FIXME("timeout not supported\n");
113 if (ec
->index
>= view
->count
) return WBEM_S_FALSE
;
115 hr
= create_class_object( view
->table
->name
, iface
, ec
->index
, NULL
, apObjects
);
116 if (hr
!= S_OK
) return hr
;
120 if (ec
->index
== view
->count
&& uCount
> 1) return WBEM_S_FALSE
;
121 if (uCount
> 1) return WBEM_S_TIMEDOUT
;
122 return WBEM_S_NO_ERROR
;
125 static HRESULT WINAPI
enum_class_object_NextAsync(
126 IEnumWbemClassObject
*iface
,
128 IWbemObjectSink
*pSink
)
130 FIXME("%p, %u, %p\n", iface
, uCount
, pSink
);
134 static HRESULT WINAPI
enum_class_object_Clone(
135 IEnumWbemClassObject
*iface
,
136 IEnumWbemClassObject
**ppEnum
)
138 struct enum_class_object
*ec
= impl_from_IEnumWbemClassObject( iface
);
140 TRACE("%p, %p\n", iface
, ppEnum
);
142 return EnumWbemClassObject_create( ec
->query
, (void **)ppEnum
);
145 static HRESULT WINAPI
enum_class_object_Skip(
146 IEnumWbemClassObject
*iface
,
150 struct enum_class_object
*ec
= impl_from_IEnumWbemClassObject( iface
);
151 struct view
*view
= ec
->query
->view
;
153 TRACE("%p, %d, %u\n", iface
, lTimeout
, nCount
);
155 if (lTimeout
!= WBEM_INFINITE
) FIXME("timeout not supported\n");
157 if (!view
->count
) return WBEM_S_FALSE
;
159 if (nCount
> view
->count
- ec
->index
)
161 ec
->index
= view
->count
- 1;
165 return WBEM_S_NO_ERROR
;
168 static const IEnumWbemClassObjectVtbl enum_class_object_vtbl
=
170 enum_class_object_QueryInterface
,
171 enum_class_object_AddRef
,
172 enum_class_object_Release
,
173 enum_class_object_Reset
,
174 enum_class_object_Next
,
175 enum_class_object_NextAsync
,
176 enum_class_object_Clone
,
177 enum_class_object_Skip
180 HRESULT
EnumWbemClassObject_create( struct query
*query
, LPVOID
*ppObj
)
182 struct enum_class_object
*ec
;
184 TRACE("%p\n", ppObj
);
186 ec
= heap_alloc( sizeof(*ec
) );
187 if (!ec
) return E_OUTOFMEMORY
;
189 ec
->IEnumWbemClassObject_iface
.lpVtbl
= &enum_class_object_vtbl
;
191 ec
->query
= addref_query( query
);
194 *ppObj
= &ec
->IEnumWbemClassObject_iface
;
196 TRACE("returning iface %p\n", *ppObj
);
200 static struct record
*create_record( struct table
*table
)
203 struct record
*record
;
205 if (!(record
= heap_alloc( sizeof(struct record
) ))) return NULL
;
206 if (!(record
->fields
= heap_alloc( table
->num_cols
* sizeof(struct field
) )))
211 for (i
= 0; i
< table
->num_cols
; i
++)
213 record
->fields
[i
].type
= table
->columns
[i
].type
;
214 record
->fields
[i
].vartype
= table
->columns
[i
].vartype
;
215 record
->fields
[i
].u
.ival
= 0;
217 record
->count
= table
->num_cols
;
218 record
->table
= addref_table( table
);
222 void destroy_array( struct array
*array
, CIMTYPE type
)
227 if (type
== CIM_STRING
|| type
== CIM_DATETIME
)
229 size
= get_type_size( type
);
230 for (i
= 0; i
< array
->count
; i
++) heap_free( *(WCHAR
**)((char *)array
->ptr
+ i
* size
) );
232 heap_free( array
->ptr
);
236 static void destroy_record( struct record
*record
)
241 release_table( record
->table
);
242 for (i
= 0; i
< record
->count
; i
++)
244 if (record
->fields
[i
].type
== CIM_STRING
|| record
->fields
[i
].type
== CIM_DATETIME
)
245 heap_free( record
->fields
[i
].u
.sval
);
246 else if (record
->fields
[i
].type
& CIM_FLAG_ARRAY
)
247 destroy_array( record
->fields
[i
].u
.aval
, record
->fields
[i
].type
& CIM_TYPE_MASK
);
249 heap_free( record
->fields
);
255 IWbemClassObject IWbemClassObject_iface
;
258 IEnumWbemClassObject
*iter
;
262 struct record
*record
; /* uncommitted instance */
265 static inline struct class_object
*impl_from_IWbemClassObject(
266 IWbemClassObject
*iface
)
268 return CONTAINING_RECORD(iface
, struct class_object
, IWbemClassObject_iface
);
271 static ULONG WINAPI
class_object_AddRef(
272 IWbemClassObject
*iface
)
274 struct class_object
*co
= impl_from_IWbemClassObject( iface
);
275 return InterlockedIncrement( &co
->refs
);
278 static ULONG WINAPI
class_object_Release(
279 IWbemClassObject
*iface
)
281 struct class_object
*co
= impl_from_IWbemClassObject( iface
);
282 LONG refs
= InterlockedDecrement( &co
->refs
);
285 TRACE("destroying %p\n", co
);
286 if (co
->iter
) IEnumWbemClassObject_Release( co
->iter
);
287 destroy_record( co
->record
);
288 heap_free( co
->name
);
294 static HRESULT WINAPI
class_object_QueryInterface(
295 IWbemClassObject
*iface
,
299 struct class_object
*co
= impl_from_IWbemClassObject( iface
);
301 TRACE("%p, %s, %p\n", co
, debugstr_guid( riid
), ppvObject
);
303 if ( IsEqualGUID( riid
, &IID_IWbemClassObject
) ||
304 IsEqualGUID( riid
, &IID_IUnknown
) )
308 else if (IsEqualGUID( riid
, &IID_IClientSecurity
))
310 *ppvObject
= &client_security
;
315 FIXME("interface %s not implemented\n", debugstr_guid(riid
));
316 return E_NOINTERFACE
;
318 IWbemClassObject_AddRef( iface
);
322 static HRESULT WINAPI
class_object_GetQualifierSet(
323 IWbemClassObject
*iface
,
324 IWbemQualifierSet
**ppQualSet
)
326 FIXME("%p, %p\n", iface
, ppQualSet
);
330 static HRESULT
record_get_value( const struct record
*record
, UINT index
, VARIANT
*var
, CIMTYPE
*type
)
332 VARTYPE vartype
= record
->fields
[index
].vartype
;
334 if (type
) *type
= record
->fields
[index
].type
;
336 if (record
->fields
[index
].type
& CIM_FLAG_ARRAY
)
338 V_VT( var
) = vartype
? vartype
: to_vartype( record
->fields
[index
].type
& CIM_TYPE_MASK
) | VT_ARRAY
;
339 V_ARRAY( var
) = to_safearray( record
->fields
[index
].u
.aval
, record
->fields
[index
].type
& CIM_TYPE_MASK
);
342 switch (record
->fields
[index
].type
)
346 if (!vartype
) vartype
= VT_BSTR
;
347 V_BSTR( var
) = SysAllocString( record
->fields
[index
].u
.sval
);
350 if (!vartype
) vartype
= VT_I4
;
351 V_I4( var
) = record
->fields
[index
].u
.ival
;
354 if (!vartype
) vartype
= VT_UI4
;
355 V_UI4( var
) = record
->fields
[index
].u
.ival
;
358 FIXME("unhandled type %u\n", record
->fields
[index
].type
);
359 return WBEM_E_INVALID_PARAMETER
;
361 V_VT( var
) = vartype
;
365 static HRESULT WINAPI
class_object_Get(
366 IWbemClassObject
*iface
,
373 struct class_object
*co
= impl_from_IWbemClassObject( iface
);
374 struct enum_class_object
*ec
= impl_from_IEnumWbemClassObject( co
->iter
);
376 TRACE("%p, %s, %08x, %p, %p, %p\n", iface
, debugstr_w(wszName
), lFlags
, pVal
, pType
, plFlavor
);
383 if ((hr
= get_column_index( co
->record
->table
, wszName
, &index
)) != S_OK
) return hr
;
384 return record_get_value( co
->record
, index
, pVal
, pType
);
386 return get_propval( ec
->query
->view
, co
->index
, wszName
, pVal
, pType
, plFlavor
);
389 static HRESULT
record_set_value( struct record
*record
, UINT index
, VARIANT
*var
)
395 if ((hr
= to_longlong( var
, &val
, &type
)) != S_OK
) return hr
;
396 if (type
!= record
->fields
[index
].type
) return WBEM_E_TYPE_MISMATCH
;
398 if (type
& CIM_FLAG_ARRAY
)
400 record
->fields
[index
].u
.aval
= (struct array
*)(INT_PTR
)val
;
407 record
->fields
[index
].u
.sval
= (WCHAR
*)(INT_PTR
)val
;
413 record
->fields
[index
].u
.ival
= val
;
416 FIXME("unhandled type %u\n", type
);
419 return WBEM_E_INVALID_PARAMETER
;
422 static HRESULT WINAPI
class_object_Put(
423 IWbemClassObject
*iface
,
429 struct class_object
*co
= impl_from_IWbemClassObject( iface
);
430 struct enum_class_object
*ec
= impl_from_IEnumWbemClassObject( co
->iter
);
432 TRACE("%p, %s, %08x, %p, %u\n", iface
, debugstr_w(wszName
), lFlags
, pVal
, Type
);
439 if ((hr
= get_column_index( co
->record
->table
, wszName
, &index
)) != S_OK
) return hr
;
440 return record_set_value( co
->record
, index
, pVal
);
442 return put_propval( ec
->query
->view
, co
->index
, wszName
, pVal
, Type
);
445 static HRESULT WINAPI
class_object_Delete(
446 IWbemClassObject
*iface
,
449 FIXME("%p, %s\n", iface
, debugstr_w(wszName
));
453 static HRESULT WINAPI
class_object_GetNames(
454 IWbemClassObject
*iface
,
455 LPCWSTR wszQualifierName
,
457 VARIANT
*pQualifierVal
,
460 struct class_object
*co
= impl_from_IWbemClassObject( iface
);
461 struct enum_class_object
*ec
= impl_from_IEnumWbemClassObject( co
->iter
);
463 TRACE("%p, %s, %08x, %s, %p\n", iface
, debugstr_w(wszQualifierName
), lFlags
,
464 debugstr_variant(pQualifierVal
), pNames
);
466 if (lFlags
!= WBEM_FLAG_ALWAYS
&&
467 lFlags
!= WBEM_FLAG_NONSYSTEM_ONLY
&&
468 lFlags
!= WBEM_FLAG_SYSTEM_ONLY
)
470 FIXME("flags %08x not supported\n", lFlags
);
473 if (wszQualifierName
|| pQualifierVal
)
474 FIXME("qualifier not supported\n");
476 return get_properties( ec
->query
->view
, lFlags
, pNames
);
479 static HRESULT WINAPI
class_object_BeginEnumeration(
480 IWbemClassObject
*iface
,
483 struct class_object
*co
= impl_from_IWbemClassObject( iface
);
485 TRACE("%p, %08x\n", iface
, lEnumFlags
);
487 if (lEnumFlags
) FIXME("flags 0x%08x not supported\n", lEnumFlags
);
489 co
->index_property
= 0;
493 static HRESULT WINAPI
class_object_Next(
494 IWbemClassObject
*iface
,
501 struct class_object
*obj
= impl_from_IWbemClassObject( iface
);
502 struct enum_class_object
*iter
= impl_from_IEnumWbemClassObject( obj
->iter
);
503 struct view
*view
= iter
->query
->view
;
508 TRACE("%p, %08x, %p, %p, %p, %p\n", iface
, lFlags
, strName
, pVal
, pType
, plFlavor
);
510 for (i
= obj
->index_property
; i
< view
->table
->num_cols
; i
++)
512 if (is_method( view
->table
, i
)) continue;
513 if (!is_selected_prop( view
, view
->table
->columns
[i
].name
)) continue;
514 if (!(prop
= SysAllocString( view
->table
->columns
[i
].name
))) return E_OUTOFMEMORY
;
515 if ((hr
= get_propval( view
, obj
->index
, prop
, pVal
, pType
, plFlavor
)) != S_OK
)
517 SysFreeString( prop
);
520 obj
->index_property
= i
+ 1;
524 return WBEM_S_NO_MORE_DATA
;
527 static HRESULT WINAPI
class_object_EndEnumeration(
528 IWbemClassObject
*iface
)
530 struct class_object
*co
= impl_from_IWbemClassObject( iface
);
532 TRACE("%p\n", iface
);
534 co
->index_property
= 0;
538 static HRESULT WINAPI
class_object_GetPropertyQualifierSet(
539 IWbemClassObject
*iface
,
541 IWbemQualifierSet
**ppQualSet
)
543 struct class_object
*co
= impl_from_IWbemClassObject( iface
);
545 TRACE("%p, %s, %p\n", iface
, debugstr_w(wszProperty
), ppQualSet
);
547 return WbemQualifierSet_create( co
->name
, wszProperty
, (void **)ppQualSet
);
550 static HRESULT WINAPI
class_object_Clone(
551 IWbemClassObject
*iface
,
552 IWbemClassObject
**ppCopy
)
554 FIXME("%p, %p\n", iface
, ppCopy
);
558 static BSTR
get_body_text( const struct table
*table
, UINT row
, UINT
*len
)
560 static const WCHAR fmtW
[] = {'\n','\t','%','s',' ','=',' ','%','s',';',0};
566 for (i
= 0; i
< table
->num_cols
; i
++)
568 if ((value
= get_value_bstr( table
, row
, i
)))
570 *len
+= sizeof(fmtW
) / sizeof(fmtW
[0]);
571 *len
+= strlenW( table
->columns
[i
].name
);
572 *len
+= SysStringLen( value
);
573 SysFreeString( value
);
576 if (!(ret
= SysAllocStringLen( NULL
, *len
))) return NULL
;
578 for (i
= 0; i
< table
->num_cols
; i
++)
580 if ((value
= get_value_bstr( table
, row
, i
)))
582 p
+= sprintfW( p
, fmtW
, table
->columns
[i
].name
, value
);
583 SysFreeString( value
);
589 static BSTR
get_object_text( const struct view
*view
, UINT index
)
591 static const WCHAR fmtW
[] =
592 {'\n','i','n','s','t','a','n','c','e',' ','o','f',' ','%','s','\n','{','%','s','\n','}',';',0};
593 UINT len
, len_body
, row
= view
->result
[index
];
596 len
= sizeof(fmtW
) / sizeof(fmtW
[0]);
597 len
+= strlenW( view
->table
->name
);
598 if (!(body
= get_body_text( view
->table
, row
, &len_body
))) return NULL
;
601 if (!(ret
= SysAllocStringLen( NULL
, len
))) return NULL
;
602 sprintfW( ret
, fmtW
, view
->table
->name
, body
);
603 SysFreeString( body
);
607 static HRESULT WINAPI
class_object_GetObjectText(
608 IWbemClassObject
*iface
,
610 BSTR
*pstrObjectText
)
612 struct class_object
*co
= impl_from_IWbemClassObject( iface
);
613 struct enum_class_object
*ec
= impl_from_IEnumWbemClassObject( co
->iter
);
614 struct view
*view
= ec
->query
->view
;
617 TRACE("%p, %08x, %p\n", iface
, lFlags
, pstrObjectText
);
619 if (lFlags
) FIXME("flags %08x not implemented\n", lFlags
);
621 if (!(text
= get_object_text( view
, co
->index
))) return E_OUTOFMEMORY
;
622 *pstrObjectText
= text
;
626 static HRESULT WINAPI
class_object_SpawnDerivedClass(
627 IWbemClassObject
*iface
,
629 IWbemClassObject
**ppNewClass
)
631 FIXME("%p, %08x, %p\n", iface
, lFlags
, ppNewClass
);
635 static HRESULT WINAPI
class_object_SpawnInstance(
636 IWbemClassObject
*iface
,
638 IWbemClassObject
**ppNewInstance
)
640 struct class_object
*co
= impl_from_IWbemClassObject( iface
);
641 struct enum_class_object
*ec
= impl_from_IEnumWbemClassObject( co
->iter
);
642 struct view
*view
= ec
->query
->view
;
643 struct record
*record
;
645 TRACE("%p, %08x, %p\n", iface
, lFlags
, ppNewInstance
);
647 if (!(record
= create_record( view
->table
))) return E_OUTOFMEMORY
;
649 return create_class_object( co
->name
, NULL
, 0, record
, ppNewInstance
);
652 static HRESULT WINAPI
class_object_CompareTo(
653 IWbemClassObject
*iface
,
655 IWbemClassObject
*pCompareTo
)
657 FIXME("%p, %08x, %p\n", iface
, lFlags
, pCompareTo
);
661 static HRESULT WINAPI
class_object_GetPropertyOrigin(
662 IWbemClassObject
*iface
,
664 BSTR
*pstrClassName
)
666 FIXME("%p, %s, %p\n", iface
, debugstr_w(wszName
), pstrClassName
);
670 static HRESULT WINAPI
class_object_InheritsFrom(
671 IWbemClassObject
*iface
,
672 LPCWSTR strAncestor
)
674 FIXME("%p, %s\n", iface
, debugstr_w(strAncestor
));
678 static UINT
count_instances( IEnumWbemClassObject
*iter
)
681 while (!IEnumWbemClassObject_Skip( iter
, WBEM_INFINITE
, 1 )) count
++;
682 IEnumWbemClassObject_Reset( iter
);
686 static void set_default_value( CIMTYPE type
, UINT val
, BYTE
*ptr
)
694 *(UINT16
*)ptr
= val
;
700 *(UINT32
*)ptr
= val
;
703 FIXME("unhandled type %u\n", type
);
708 static HRESULT
create_signature_columns_and_data( IEnumWbemClassObject
*iter
, UINT
*num_cols
,
709 struct column
**cols
, BYTE
**data
)
711 static const WCHAR parameterW
[] = {'P','a','r','a','m','e','t','e','r',0};
712 static const WCHAR typeW
[] = {'T','y','p','e',0};
713 static const WCHAR varianttypeW
[] = {'V','a','r','i','a','n','t','T','y','p','e',0};
714 static const WCHAR defaultvalueW
[] = {'D','e','f','a','u','l','t','V','a','l','u','e',0};
715 struct column
*columns
;
717 IWbemClassObject
*param
;
719 HRESULT hr
= E_OUTOFMEMORY
;
724 count
= count_instances( iter
);
725 if (!(columns
= heap_alloc( count
* sizeof(struct column
) ))) return E_OUTOFMEMORY
;
726 if (!(row
= heap_alloc_zero( count
* sizeof(LONGLONG
) ))) goto error
;
730 IEnumWbemClassObject_Next( iter
, WBEM_INFINITE
, 1, ¶m
, &count
);
733 hr
= IWbemClassObject_Get( param
, parameterW
, 0, &val
, NULL
, NULL
);
734 if (hr
!= S_OK
) goto error
;
735 columns
[i
].name
= heap_strdupW( V_BSTR( &val
) );
736 VariantClear( &val
);
738 hr
= IWbemClassObject_Get( param
, typeW
, 0, &val
, NULL
, NULL
);
739 if (hr
!= S_OK
) goto error
;
740 columns
[i
].type
= V_UI4( &val
);
742 hr
= IWbemClassObject_Get( param
, varianttypeW
, 0, &val
, NULL
, NULL
);
743 if (hr
!= S_OK
) goto error
;
744 columns
[i
].vartype
= V_UI4( &val
);
746 hr
= IWbemClassObject_Get( param
, defaultvalueW
, 0, &val
, NULL
, NULL
);
747 if (hr
!= S_OK
) goto error
;
748 if (V_UI4( &val
)) set_default_value( columns
[i
].type
, V_UI4( &val
), row
+ offset
);
749 offset
+= get_type_size( columns
[i
].type
);
751 IWbemClassObject_Release( param
);
760 for (; i
>= 0; i
--) heap_free( (WCHAR
*)columns
[i
].name
);
761 heap_free( columns
);
766 static HRESULT
create_signature_table( IEnumWbemClassObject
*iter
, WCHAR
*name
)
770 struct column
*columns
;
774 hr
= create_signature_columns_and_data( iter
, &num_cols
, &columns
, &row
);
775 if (hr
!= S_OK
) return hr
;
777 if (!(table
= create_table( name
, num_cols
, columns
, 1, 1, row
, NULL
)))
779 free_columns( columns
, num_cols
);
781 return E_OUTOFMEMORY
;
783 if (!add_table( table
)) free_table( table
); /* already exists */
787 static WCHAR
*build_signature_table_name( const WCHAR
*class, const WCHAR
*method
, enum param_direction dir
)
789 static const WCHAR fmtW
[] = {'_','_','%','s','_','%','s','_','%','s',0};
790 static const WCHAR outW
[] = {'O','U','T',0};
791 static const WCHAR inW
[] = {'I','N',0};
792 UINT len
= SIZEOF(fmtW
) + SIZEOF(outW
) + strlenW( class ) + strlenW( method
);
795 if (!(ret
= heap_alloc( len
* sizeof(WCHAR
) ))) return NULL
;
796 sprintfW( ret
, fmtW
, class, method
, dir
== PARAM_IN
? inW
: outW
);
797 return struprW( ret
);
800 HRESULT
create_signature( const WCHAR
*class, const WCHAR
*method
, enum param_direction dir
,
801 IWbemClassObject
**sig
)
803 static const WCHAR selectW
[] =
804 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
805 '_','_','P','A','R','A','M','E','T','E','R','S',' ','W','H','E','R','E',' ',
806 'C','l','a','s','s','=','\'','%','s','\'',' ','A','N','D',' ',
807 'M','e','t','h','o','d','=','\'','%','s','\'',' ','A','N','D',' ',
808 'D','i','r','e','c','t','i','o','n','%','s',0};
809 static const WCHAR geW
[] = {'>','=','0',0};
810 static const WCHAR leW
[] = {'<','=','0',0};
811 UINT len
= SIZEOF(selectW
) + SIZEOF(geW
);
812 IEnumWbemClassObject
*iter
;
816 len
+= strlenW( class ) + strlenW( method
);
817 if (!(query
= heap_alloc( len
* sizeof(WCHAR
) ))) return E_OUTOFMEMORY
;
818 sprintfW( query
, selectW
, class, method
, dir
>= 0 ? geW
: leW
);
820 hr
= exec_query( query
, &iter
);
822 if (hr
!= S_OK
) return hr
;
824 if (!(name
= build_signature_table_name( class, method
, dir
)))
826 IEnumWbemClassObject_Release( iter
);
827 return E_OUTOFMEMORY
;
829 hr
= create_signature_table( iter
, name
);
830 IEnumWbemClassObject_Release( iter
);
832 hr
= get_object( name
, sig
);
838 static HRESULT WINAPI
class_object_GetMethod(
839 IWbemClassObject
*iface
,
842 IWbemClassObject
**ppInSignature
,
843 IWbemClassObject
**ppOutSignature
)
845 struct class_object
*co
= impl_from_IWbemClassObject( iface
);
846 IWbemClassObject
*in
, *out
;
849 TRACE("%p, %s, %08x, %p, %p\n", iface
, debugstr_w(wszName
), lFlags
, ppInSignature
, ppOutSignature
);
851 hr
= create_signature( co
->name
, wszName
, PARAM_IN
, &in
);
852 if (hr
!= S_OK
) return hr
;
854 hr
= create_signature( co
->name
, wszName
, PARAM_OUT
, &out
);
857 if (ppInSignature
) *ppInSignature
= in
;
858 else IWbemClassObject_Release( in
);
859 if (ppOutSignature
) *ppOutSignature
= out
;
860 else IWbemClassObject_Release( out
);
862 else IWbemClassObject_Release( in
);
866 static HRESULT WINAPI
class_object_PutMethod(
867 IWbemClassObject
*iface
,
870 IWbemClassObject
*pInSignature
,
871 IWbemClassObject
*pOutSignature
)
873 FIXME("%p, %s, %08x, %p, %p\n", iface
, debugstr_w(wszName
), lFlags
, pInSignature
, pOutSignature
);
877 static HRESULT WINAPI
class_object_DeleteMethod(
878 IWbemClassObject
*iface
,
881 FIXME("%p, %s\n", iface
, debugstr_w(wszName
));
885 static HRESULT WINAPI
class_object_BeginMethodEnumeration(
886 IWbemClassObject
*iface
,
889 struct class_object
*co
= impl_from_IWbemClassObject( iface
);
891 TRACE("%p, %08x\n", iface
, lEnumFlags
);
893 if (lEnumFlags
) FIXME("flags 0x%08x not supported\n", lEnumFlags
);
897 WARN("not allowed on instance\n");
898 return WBEM_E_ILLEGAL_OPERATION
;
900 co
->index_method
= 0;
904 static HRESULT WINAPI
class_object_NextMethod(
905 IWbemClassObject
*iface
,
908 IWbemClassObject
**ppInSignature
,
909 IWbemClassObject
**ppOutSignature
)
911 struct class_object
*co
= impl_from_IWbemClassObject( iface
);
915 TRACE("%p, %08x, %p, %p, %p\n", iface
, lFlags
, pstrName
, ppInSignature
, ppOutSignature
);
917 if (!(method
= get_method_name( co
->name
, co
->index_method
))) return WBEM_S_NO_MORE_DATA
;
919 hr
= create_signature( co
->name
, method
, PARAM_IN
, ppInSignature
);
922 SysFreeString( method
);
925 hr
= create_signature( co
->name
, method
, PARAM_OUT
, ppOutSignature
);
928 SysFreeString( method
);
929 IWbemClassObject_Release( *ppInSignature
);
939 static HRESULT WINAPI
class_object_EndMethodEnumeration(
940 IWbemClassObject
*iface
)
942 struct class_object
*co
= impl_from_IWbemClassObject( iface
);
944 TRACE("%p\n", iface
);
946 co
->index_method
= 0;
950 static HRESULT WINAPI
class_object_GetMethodQualifierSet(
951 IWbemClassObject
*iface
,
953 IWbemQualifierSet
**ppQualSet
)
955 FIXME("%p, %s, %p\n", iface
, debugstr_w(wszMethod
), ppQualSet
);
959 static HRESULT WINAPI
class_object_GetMethodOrigin(
960 IWbemClassObject
*iface
,
961 LPCWSTR wszMethodName
,
964 FIXME("%p, %s, %p\n", iface
, debugstr_w(wszMethodName
), pstrClassName
);
968 static const IWbemClassObjectVtbl class_object_vtbl
=
970 class_object_QueryInterface
,
972 class_object_Release
,
973 class_object_GetQualifierSet
,
977 class_object_GetNames
,
978 class_object_BeginEnumeration
,
980 class_object_EndEnumeration
,
981 class_object_GetPropertyQualifierSet
,
983 class_object_GetObjectText
,
984 class_object_SpawnDerivedClass
,
985 class_object_SpawnInstance
,
986 class_object_CompareTo
,
987 class_object_GetPropertyOrigin
,
988 class_object_InheritsFrom
,
989 class_object_GetMethod
,
990 class_object_PutMethod
,
991 class_object_DeleteMethod
,
992 class_object_BeginMethodEnumeration
,
993 class_object_NextMethod
,
994 class_object_EndMethodEnumeration
,
995 class_object_GetMethodQualifierSet
,
996 class_object_GetMethodOrigin
999 HRESULT
create_class_object( const WCHAR
*name
, IEnumWbemClassObject
*iter
, UINT index
,
1000 struct record
*record
, IWbemClassObject
**obj
)
1002 struct class_object
*co
;
1004 TRACE("%s, %p\n", debugstr_w(name
), obj
);
1006 co
= heap_alloc( sizeof(*co
) );
1007 if (!co
) return E_OUTOFMEMORY
;
1009 co
->IWbemClassObject_iface
.lpVtbl
= &class_object_vtbl
;
1011 if (!name
) co
->name
= NULL
;
1012 else if (!(co
->name
= heap_strdupW( name
)))
1015 return E_OUTOFMEMORY
;
1019 co
->index_method
= 0;
1020 co
->index_property
= 0;
1021 co
->record
= record
;
1022 if (iter
) IEnumWbemClassObject_AddRef( iter
);
1024 *obj
= &co
->IWbemClassObject_iface
;
1026 TRACE("returning iface %p\n", *obj
);