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
;
107 TRACE("%p, %d, %u, %p, %p\n", iface
, lTimeout
, uCount
, apObjects
, puReturned
);
109 if (!uCount
) return WBEM_S_FALSE
;
110 if (!apObjects
|| !puReturned
) return WBEM_E_INVALID_PARAMETER
;
111 if (lTimeout
!= WBEM_INFINITE
&& !once
++) FIXME("timeout not supported\n");
114 if (ec
->index
>= view
->count
) return WBEM_S_FALSE
;
116 hr
= create_class_object( view
->table
->name
, iface
, ec
->index
, NULL
, apObjects
);
117 if (hr
!= S_OK
) return hr
;
121 if (ec
->index
== view
->count
&& uCount
> 1) return WBEM_S_FALSE
;
122 if (uCount
> 1) return WBEM_S_TIMEDOUT
;
123 return WBEM_S_NO_ERROR
;
126 static HRESULT WINAPI
enum_class_object_NextAsync(
127 IEnumWbemClassObject
*iface
,
129 IWbemObjectSink
*pSink
)
131 FIXME("%p, %u, %p\n", iface
, uCount
, pSink
);
135 static HRESULT WINAPI
enum_class_object_Clone(
136 IEnumWbemClassObject
*iface
,
137 IEnumWbemClassObject
**ppEnum
)
139 struct enum_class_object
*ec
= impl_from_IEnumWbemClassObject( iface
);
141 TRACE("%p, %p\n", iface
, ppEnum
);
143 return EnumWbemClassObject_create( ec
->query
, (void **)ppEnum
);
146 static HRESULT WINAPI
enum_class_object_Skip(
147 IEnumWbemClassObject
*iface
,
151 struct enum_class_object
*ec
= impl_from_IEnumWbemClassObject( iface
);
152 struct view
*view
= ec
->query
->view
;
155 TRACE("%p, %d, %u\n", iface
, lTimeout
, nCount
);
157 if (lTimeout
!= WBEM_INFINITE
&& !once
++) FIXME("timeout not supported\n");
159 if (!view
->count
) return WBEM_S_FALSE
;
161 if (nCount
> view
->count
- ec
->index
)
163 ec
->index
= view
->count
- 1;
167 return WBEM_S_NO_ERROR
;
170 static const IEnumWbemClassObjectVtbl enum_class_object_vtbl
=
172 enum_class_object_QueryInterface
,
173 enum_class_object_AddRef
,
174 enum_class_object_Release
,
175 enum_class_object_Reset
,
176 enum_class_object_Next
,
177 enum_class_object_NextAsync
,
178 enum_class_object_Clone
,
179 enum_class_object_Skip
182 HRESULT
EnumWbemClassObject_create( struct query
*query
, LPVOID
*ppObj
)
184 struct enum_class_object
*ec
;
186 TRACE("%p\n", ppObj
);
188 ec
= heap_alloc( sizeof(*ec
) );
189 if (!ec
) return E_OUTOFMEMORY
;
191 ec
->IEnumWbemClassObject_iface
.lpVtbl
= &enum_class_object_vtbl
;
193 ec
->query
= addref_query( query
);
196 *ppObj
= &ec
->IEnumWbemClassObject_iface
;
198 TRACE("returning iface %p\n", *ppObj
);
202 static struct record
*create_record( struct table
*table
)
205 struct record
*record
;
207 if (!(record
= heap_alloc( sizeof(struct record
) ))) return NULL
;
208 if (!(record
->fields
= heap_alloc( table
->num_cols
* sizeof(struct field
) )))
213 for (i
= 0; i
< table
->num_cols
; i
++)
215 record
->fields
[i
].type
= table
->columns
[i
].type
;
216 record
->fields
[i
].vartype
= table
->columns
[i
].vartype
;
217 record
->fields
[i
].u
.ival
= 0;
219 record
->count
= table
->num_cols
;
220 record
->table
= addref_table( table
);
224 void destroy_array( struct array
*array
, CIMTYPE type
)
229 if (type
== CIM_STRING
|| type
== CIM_DATETIME
)
231 size
= get_type_size( type
);
232 for (i
= 0; i
< array
->count
; i
++) heap_free( *(WCHAR
**)((char *)array
->ptr
+ i
* size
) );
234 heap_free( array
->ptr
);
238 static void destroy_record( struct record
*record
)
243 release_table( record
->table
);
244 for (i
= 0; i
< record
->count
; i
++)
246 if (record
->fields
[i
].type
== CIM_STRING
|| record
->fields
[i
].type
== CIM_DATETIME
)
247 heap_free( record
->fields
[i
].u
.sval
);
248 else if (record
->fields
[i
].type
& CIM_FLAG_ARRAY
)
249 destroy_array( record
->fields
[i
].u
.aval
, record
->fields
[i
].type
& CIM_TYPE_MASK
);
251 heap_free( record
->fields
);
257 IWbemClassObject IWbemClassObject_iface
;
260 IEnumWbemClassObject
*iter
;
264 struct record
*record
; /* uncommitted instance */
267 static inline struct class_object
*impl_from_IWbemClassObject(
268 IWbemClassObject
*iface
)
270 return CONTAINING_RECORD(iface
, struct class_object
, IWbemClassObject_iface
);
273 static ULONG WINAPI
class_object_AddRef(
274 IWbemClassObject
*iface
)
276 struct class_object
*co
= impl_from_IWbemClassObject( iface
);
277 return InterlockedIncrement( &co
->refs
);
280 static ULONG WINAPI
class_object_Release(
281 IWbemClassObject
*iface
)
283 struct class_object
*co
= impl_from_IWbemClassObject( iface
);
284 LONG refs
= InterlockedDecrement( &co
->refs
);
287 TRACE("destroying %p\n", co
);
288 if (co
->iter
) IEnumWbemClassObject_Release( co
->iter
);
289 destroy_record( co
->record
);
290 heap_free( co
->name
);
296 static HRESULT WINAPI
class_object_QueryInterface(
297 IWbemClassObject
*iface
,
301 struct class_object
*co
= impl_from_IWbemClassObject( iface
);
303 TRACE("%p, %s, %p\n", co
, debugstr_guid( riid
), ppvObject
);
305 if ( IsEqualGUID( riid
, &IID_IWbemClassObject
) ||
306 IsEqualGUID( riid
, &IID_IUnknown
) )
310 else if (IsEqualGUID( riid
, &IID_IClientSecurity
))
312 *ppvObject
= &client_security
;
317 FIXME("interface %s not implemented\n", debugstr_guid(riid
));
318 return E_NOINTERFACE
;
320 IWbemClassObject_AddRef( iface
);
324 static HRESULT WINAPI
class_object_GetQualifierSet(
325 IWbemClassObject
*iface
,
326 IWbemQualifierSet
**ppQualSet
)
328 FIXME("%p, %p\n", iface
, ppQualSet
);
332 static HRESULT
record_get_value( const struct record
*record
, UINT index
, VARIANT
*var
, CIMTYPE
*type
)
334 VARTYPE vartype
= record
->fields
[index
].vartype
;
336 if (type
) *type
= record
->fields
[index
].type
;
338 if (record
->fields
[index
].type
& CIM_FLAG_ARRAY
)
340 V_VT( var
) = vartype
? vartype
: to_vartype( record
->fields
[index
].type
& CIM_TYPE_MASK
) | VT_ARRAY
;
341 V_ARRAY( var
) = to_safearray( record
->fields
[index
].u
.aval
, record
->fields
[index
].type
& CIM_TYPE_MASK
);
344 switch (record
->fields
[index
].type
)
348 if (!vartype
) vartype
= VT_BSTR
;
349 V_BSTR( var
) = SysAllocString( record
->fields
[index
].u
.sval
);
352 if (!vartype
) vartype
= VT_I4
;
353 V_I4( var
) = record
->fields
[index
].u
.ival
;
356 if (!vartype
) vartype
= VT_UI4
;
357 V_UI4( var
) = record
->fields
[index
].u
.ival
;
360 FIXME("unhandled type %u\n", record
->fields
[index
].type
);
361 return WBEM_E_INVALID_PARAMETER
;
363 V_VT( var
) = vartype
;
367 static HRESULT WINAPI
class_object_Get(
368 IWbemClassObject
*iface
,
375 struct class_object
*co
= impl_from_IWbemClassObject( iface
);
376 struct enum_class_object
*ec
= impl_from_IEnumWbemClassObject( co
->iter
);
378 TRACE("%p, %s, %08x, %p, %p, %p\n", iface
, debugstr_w(wszName
), lFlags
, pVal
, pType
, plFlavor
);
385 if ((hr
= get_column_index( co
->record
->table
, wszName
, &index
)) != S_OK
) return hr
;
386 return record_get_value( co
->record
, index
, pVal
, pType
);
388 return get_propval( ec
->query
->view
, co
->index
, wszName
, pVal
, pType
, plFlavor
);
391 static HRESULT
record_set_value( struct record
*record
, UINT index
, VARIANT
*var
)
397 if ((hr
= to_longlong( var
, &val
, &type
)) != S_OK
) return hr
;
398 if (type
!= record
->fields
[index
].type
) return WBEM_E_TYPE_MISMATCH
;
400 if (type
& CIM_FLAG_ARRAY
)
402 record
->fields
[index
].u
.aval
= (struct array
*)(INT_PTR
)val
;
409 record
->fields
[index
].u
.sval
= (WCHAR
*)(INT_PTR
)val
;
415 record
->fields
[index
].u
.ival
= val
;
418 FIXME("unhandled type %u\n", type
);
421 return WBEM_E_INVALID_PARAMETER
;
424 static HRESULT WINAPI
class_object_Put(
425 IWbemClassObject
*iface
,
431 struct class_object
*co
= impl_from_IWbemClassObject( iface
);
432 struct enum_class_object
*ec
= impl_from_IEnumWbemClassObject( co
->iter
);
434 TRACE("%p, %s, %08x, %p, %u\n", iface
, debugstr_w(wszName
), lFlags
, pVal
, Type
);
441 if ((hr
= get_column_index( co
->record
->table
, wszName
, &index
)) != S_OK
) return hr
;
442 return record_set_value( co
->record
, index
, pVal
);
444 return put_propval( ec
->query
->view
, co
->index
, wszName
, pVal
, Type
);
447 static HRESULT WINAPI
class_object_Delete(
448 IWbemClassObject
*iface
,
451 FIXME("%p, %s\n", iface
, debugstr_w(wszName
));
455 static HRESULT WINAPI
class_object_GetNames(
456 IWbemClassObject
*iface
,
457 LPCWSTR wszQualifierName
,
459 VARIANT
*pQualifierVal
,
462 struct class_object
*co
= impl_from_IWbemClassObject( iface
);
463 struct enum_class_object
*ec
= impl_from_IEnumWbemClassObject( co
->iter
);
465 TRACE("%p, %s, %08x, %s, %p\n", iface
, debugstr_w(wszQualifierName
), lFlags
,
466 debugstr_variant(pQualifierVal
), pNames
);
468 if (lFlags
!= WBEM_FLAG_ALWAYS
&&
469 lFlags
!= WBEM_FLAG_NONSYSTEM_ONLY
&&
470 lFlags
!= WBEM_FLAG_SYSTEM_ONLY
)
472 FIXME("flags %08x not supported\n", lFlags
);
475 if (wszQualifierName
|| pQualifierVal
)
476 FIXME("qualifier not supported\n");
478 return get_properties( ec
->query
->view
, lFlags
, pNames
);
481 static HRESULT WINAPI
class_object_BeginEnumeration(
482 IWbemClassObject
*iface
,
485 struct class_object
*co
= impl_from_IWbemClassObject( iface
);
487 TRACE("%p, %08x\n", iface
, lEnumFlags
);
489 if (lEnumFlags
) FIXME("flags 0x%08x not supported\n", lEnumFlags
);
491 co
->index_property
= 0;
495 static HRESULT WINAPI
class_object_Next(
496 IWbemClassObject
*iface
,
503 struct class_object
*obj
= impl_from_IWbemClassObject( iface
);
504 struct enum_class_object
*iter
= impl_from_IEnumWbemClassObject( obj
->iter
);
505 struct view
*view
= iter
->query
->view
;
510 TRACE("%p, %08x, %p, %p, %p, %p\n", iface
, lFlags
, strName
, pVal
, pType
, plFlavor
);
512 for (i
= obj
->index_property
; i
< view
->table
->num_cols
; i
++)
514 if (is_method( view
->table
, i
)) continue;
515 if (!is_selected_prop( view
, view
->table
->columns
[i
].name
)) continue;
516 if (!(prop
= SysAllocString( view
->table
->columns
[i
].name
))) return E_OUTOFMEMORY
;
517 if ((hr
= get_propval( view
, obj
->index
, prop
, pVal
, pType
, plFlavor
)) != S_OK
)
519 SysFreeString( prop
);
522 obj
->index_property
= i
+ 1;
526 return WBEM_S_NO_MORE_DATA
;
529 static HRESULT WINAPI
class_object_EndEnumeration(
530 IWbemClassObject
*iface
)
532 struct class_object
*co
= impl_from_IWbemClassObject( iface
);
534 TRACE("%p\n", iface
);
536 co
->index_property
= 0;
540 static HRESULT WINAPI
class_object_GetPropertyQualifierSet(
541 IWbemClassObject
*iface
,
543 IWbemQualifierSet
**ppQualSet
)
545 struct class_object
*co
= impl_from_IWbemClassObject( iface
);
547 TRACE("%p, %s, %p\n", iface
, debugstr_w(wszProperty
), ppQualSet
);
549 return WbemQualifierSet_create( co
->name
, wszProperty
, (void **)ppQualSet
);
552 static HRESULT WINAPI
class_object_Clone(
553 IWbemClassObject
*iface
,
554 IWbemClassObject
**ppCopy
)
556 FIXME("%p, %p\n", iface
, ppCopy
);
560 static BSTR
get_body_text( const struct table
*table
, UINT row
, UINT
*len
)
562 static const WCHAR fmtW
[] = {'\n','\t','%','s',' ','=',' ','%','s',';',0};
568 for (i
= 0; i
< table
->num_cols
; i
++)
570 if ((value
= get_value_bstr( table
, row
, i
)))
572 *len
+= sizeof(fmtW
) / sizeof(fmtW
[0]);
573 *len
+= strlenW( table
->columns
[i
].name
);
574 *len
+= SysStringLen( value
);
575 SysFreeString( value
);
578 if (!(ret
= SysAllocStringLen( NULL
, *len
))) return NULL
;
580 for (i
= 0; i
< table
->num_cols
; i
++)
582 if ((value
= get_value_bstr( table
, row
, i
)))
584 p
+= sprintfW( p
, fmtW
, table
->columns
[i
].name
, value
);
585 SysFreeString( value
);
591 static BSTR
get_object_text( const struct view
*view
, UINT index
)
593 static const WCHAR fmtW
[] =
594 {'\n','i','n','s','t','a','n','c','e',' ','o','f',' ','%','s','\n','{','%','s','\n','}',';',0};
595 UINT len
, len_body
, row
= view
->result
[index
];
598 len
= sizeof(fmtW
) / sizeof(fmtW
[0]);
599 len
+= strlenW( view
->table
->name
);
600 if (!(body
= get_body_text( view
->table
, row
, &len_body
))) return NULL
;
603 if (!(ret
= SysAllocStringLen( NULL
, len
))) return NULL
;
604 sprintfW( ret
, fmtW
, view
->table
->name
, body
);
605 SysFreeString( body
);
609 static HRESULT WINAPI
class_object_GetObjectText(
610 IWbemClassObject
*iface
,
612 BSTR
*pstrObjectText
)
614 struct class_object
*co
= impl_from_IWbemClassObject( iface
);
615 struct enum_class_object
*ec
= impl_from_IEnumWbemClassObject( co
->iter
);
616 struct view
*view
= ec
->query
->view
;
619 TRACE("%p, %08x, %p\n", iface
, lFlags
, pstrObjectText
);
621 if (lFlags
) FIXME("flags %08x not implemented\n", lFlags
);
623 if (!(text
= get_object_text( view
, co
->index
))) return E_OUTOFMEMORY
;
624 *pstrObjectText
= text
;
628 static HRESULT WINAPI
class_object_SpawnDerivedClass(
629 IWbemClassObject
*iface
,
631 IWbemClassObject
**ppNewClass
)
633 FIXME("%p, %08x, %p\n", iface
, lFlags
, ppNewClass
);
637 static HRESULT WINAPI
class_object_SpawnInstance(
638 IWbemClassObject
*iface
,
640 IWbemClassObject
**ppNewInstance
)
642 struct class_object
*co
= impl_from_IWbemClassObject( iface
);
643 struct enum_class_object
*ec
= impl_from_IEnumWbemClassObject( co
->iter
);
644 struct view
*view
= ec
->query
->view
;
645 struct record
*record
;
647 TRACE("%p, %08x, %p\n", iface
, lFlags
, ppNewInstance
);
649 if (!(record
= create_record( view
->table
))) return E_OUTOFMEMORY
;
651 return create_class_object( co
->name
, NULL
, 0, record
, ppNewInstance
);
654 static HRESULT WINAPI
class_object_CompareTo(
655 IWbemClassObject
*iface
,
657 IWbemClassObject
*pCompareTo
)
659 FIXME("%p, %08x, %p\n", iface
, lFlags
, pCompareTo
);
663 static HRESULT WINAPI
class_object_GetPropertyOrigin(
664 IWbemClassObject
*iface
,
666 BSTR
*pstrClassName
)
668 FIXME("%p, %s, %p\n", iface
, debugstr_w(wszName
), pstrClassName
);
672 static HRESULT WINAPI
class_object_InheritsFrom(
673 IWbemClassObject
*iface
,
674 LPCWSTR strAncestor
)
676 FIXME("%p, %s\n", iface
, debugstr_w(strAncestor
));
680 static UINT
count_instances( IEnumWbemClassObject
*iter
)
683 while (!IEnumWbemClassObject_Skip( iter
, WBEM_INFINITE
, 1 )) count
++;
684 IEnumWbemClassObject_Reset( iter
);
688 static void set_default_value( CIMTYPE type
, UINT val
, BYTE
*ptr
)
696 *(UINT16
*)ptr
= val
;
702 *(UINT32
*)ptr
= val
;
705 FIXME("unhandled type %u\n", type
);
710 static HRESULT
create_signature_columns_and_data( IEnumWbemClassObject
*iter
, UINT
*num_cols
,
711 struct column
**cols
, BYTE
**data
)
713 static const WCHAR parameterW
[] = {'P','a','r','a','m','e','t','e','r',0};
714 static const WCHAR typeW
[] = {'T','y','p','e',0};
715 static const WCHAR varianttypeW
[] = {'V','a','r','i','a','n','t','T','y','p','e',0};
716 static const WCHAR defaultvalueW
[] = {'D','e','f','a','u','l','t','V','a','l','u','e',0};
717 struct column
*columns
;
719 IWbemClassObject
*param
;
721 HRESULT hr
= E_OUTOFMEMORY
;
726 count
= count_instances( iter
);
727 if (!(columns
= heap_alloc( count
* sizeof(struct column
) ))) return E_OUTOFMEMORY
;
728 if (!(row
= heap_alloc_zero( count
* sizeof(LONGLONG
) ))) goto error
;
732 IEnumWbemClassObject_Next( iter
, WBEM_INFINITE
, 1, ¶m
, &count
);
735 hr
= IWbemClassObject_Get( param
, parameterW
, 0, &val
, NULL
, NULL
);
736 if (hr
!= S_OK
) goto error
;
737 columns
[i
].name
= heap_strdupW( V_BSTR( &val
) );
738 VariantClear( &val
);
740 hr
= IWbemClassObject_Get( param
, typeW
, 0, &val
, NULL
, NULL
);
741 if (hr
!= S_OK
) goto error
;
742 columns
[i
].type
= V_UI4( &val
);
744 hr
= IWbemClassObject_Get( param
, varianttypeW
, 0, &val
, NULL
, NULL
);
745 if (hr
!= S_OK
) goto error
;
746 columns
[i
].vartype
= V_UI4( &val
);
748 hr
= IWbemClassObject_Get( param
, defaultvalueW
, 0, &val
, NULL
, NULL
);
749 if (hr
!= S_OK
) goto error
;
750 if (V_UI4( &val
)) set_default_value( columns
[i
].type
, V_UI4( &val
), row
+ offset
);
751 offset
+= get_type_size( columns
[i
].type
);
753 IWbemClassObject_Release( param
);
762 for (; i
>= 0; i
--) heap_free( (WCHAR
*)columns
[i
].name
);
763 heap_free( columns
);
768 static HRESULT
create_signature_table( IEnumWbemClassObject
*iter
, WCHAR
*name
)
772 struct column
*columns
;
776 hr
= create_signature_columns_and_data( iter
, &num_cols
, &columns
, &row
);
777 if (hr
!= S_OK
) return hr
;
779 if (!(table
= create_table( name
, num_cols
, columns
, 1, 1, row
, NULL
)))
781 free_columns( columns
, num_cols
);
783 return E_OUTOFMEMORY
;
785 if (!add_table( table
)) free_table( table
); /* already exists */
789 static WCHAR
*build_signature_table_name( const WCHAR
*class, const WCHAR
*method
, enum param_direction dir
)
791 static const WCHAR fmtW
[] = {'_','_','%','s','_','%','s','_','%','s',0};
792 static const WCHAR outW
[] = {'O','U','T',0};
793 static const WCHAR inW
[] = {'I','N',0};
794 UINT len
= SIZEOF(fmtW
) + SIZEOF(outW
) + strlenW( class ) + strlenW( method
);
797 if (!(ret
= heap_alloc( len
* sizeof(WCHAR
) ))) return NULL
;
798 sprintfW( ret
, fmtW
, class, method
, dir
== PARAM_IN
? inW
: outW
);
799 return struprW( ret
);
802 HRESULT
create_signature( const WCHAR
*class, const WCHAR
*method
, enum param_direction dir
,
803 IWbemClassObject
**sig
)
805 static const WCHAR selectW
[] =
806 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
807 '_','_','P','A','R','A','M','E','T','E','R','S',' ','W','H','E','R','E',' ',
808 'C','l','a','s','s','=','\'','%','s','\'',' ','A','N','D',' ',
809 'M','e','t','h','o','d','=','\'','%','s','\'',' ','A','N','D',' ',
810 'D','i','r','e','c','t','i','o','n','%','s',0};
811 static const WCHAR geW
[] = {'>','=','0',0};
812 static const WCHAR leW
[] = {'<','=','0',0};
813 UINT len
= SIZEOF(selectW
) + SIZEOF(geW
);
814 IEnumWbemClassObject
*iter
;
818 len
+= strlenW( class ) + strlenW( method
);
819 if (!(query
= heap_alloc( len
* sizeof(WCHAR
) ))) return E_OUTOFMEMORY
;
820 sprintfW( query
, selectW
, class, method
, dir
>= 0 ? geW
: leW
);
822 hr
= exec_query( query
, &iter
);
824 if (hr
!= S_OK
) return hr
;
826 if (!(name
= build_signature_table_name( class, method
, dir
)))
828 IEnumWbemClassObject_Release( iter
);
829 return E_OUTOFMEMORY
;
831 hr
= create_signature_table( iter
, name
);
832 IEnumWbemClassObject_Release( iter
);
834 hr
= get_object( name
, sig
);
840 static HRESULT WINAPI
class_object_GetMethod(
841 IWbemClassObject
*iface
,
844 IWbemClassObject
**ppInSignature
,
845 IWbemClassObject
**ppOutSignature
)
847 struct class_object
*co
= impl_from_IWbemClassObject( iface
);
848 IWbemClassObject
*in
, *out
;
851 TRACE("%p, %s, %08x, %p, %p\n", iface
, debugstr_w(wszName
), lFlags
, ppInSignature
, ppOutSignature
);
853 hr
= create_signature( co
->name
, wszName
, PARAM_IN
, &in
);
854 if (hr
!= S_OK
) return hr
;
856 hr
= create_signature( co
->name
, wszName
, PARAM_OUT
, &out
);
859 if (ppInSignature
) *ppInSignature
= in
;
860 else IWbemClassObject_Release( in
);
861 if (ppOutSignature
) *ppOutSignature
= out
;
862 else IWbemClassObject_Release( out
);
864 else IWbemClassObject_Release( in
);
868 static HRESULT WINAPI
class_object_PutMethod(
869 IWbemClassObject
*iface
,
872 IWbemClassObject
*pInSignature
,
873 IWbemClassObject
*pOutSignature
)
875 FIXME("%p, %s, %08x, %p, %p\n", iface
, debugstr_w(wszName
), lFlags
, pInSignature
, pOutSignature
);
879 static HRESULT WINAPI
class_object_DeleteMethod(
880 IWbemClassObject
*iface
,
883 FIXME("%p, %s\n", iface
, debugstr_w(wszName
));
887 static HRESULT WINAPI
class_object_BeginMethodEnumeration(
888 IWbemClassObject
*iface
,
891 struct class_object
*co
= impl_from_IWbemClassObject( iface
);
893 TRACE("%p, %08x\n", iface
, lEnumFlags
);
895 if (lEnumFlags
) FIXME("flags 0x%08x not supported\n", lEnumFlags
);
899 WARN("not allowed on instance\n");
900 return WBEM_E_ILLEGAL_OPERATION
;
902 co
->index_method
= 0;
906 static HRESULT WINAPI
class_object_NextMethod(
907 IWbemClassObject
*iface
,
910 IWbemClassObject
**ppInSignature
,
911 IWbemClassObject
**ppOutSignature
)
913 struct class_object
*co
= impl_from_IWbemClassObject( iface
);
917 TRACE("%p, %08x, %p, %p, %p\n", iface
, lFlags
, pstrName
, ppInSignature
, ppOutSignature
);
919 if (!(method
= get_method_name( co
->name
, co
->index_method
))) return WBEM_S_NO_MORE_DATA
;
921 hr
= create_signature( co
->name
, method
, PARAM_IN
, ppInSignature
);
924 SysFreeString( method
);
927 hr
= create_signature( co
->name
, method
, PARAM_OUT
, ppOutSignature
);
930 SysFreeString( method
);
931 IWbemClassObject_Release( *ppInSignature
);
941 static HRESULT WINAPI
class_object_EndMethodEnumeration(
942 IWbemClassObject
*iface
)
944 struct class_object
*co
= impl_from_IWbemClassObject( iface
);
946 TRACE("%p\n", iface
);
948 co
->index_method
= 0;
952 static HRESULT WINAPI
class_object_GetMethodQualifierSet(
953 IWbemClassObject
*iface
,
955 IWbemQualifierSet
**ppQualSet
)
957 FIXME("%p, %s, %p\n", iface
, debugstr_w(wszMethod
), ppQualSet
);
961 static HRESULT WINAPI
class_object_GetMethodOrigin(
962 IWbemClassObject
*iface
,
963 LPCWSTR wszMethodName
,
966 FIXME("%p, %s, %p\n", iface
, debugstr_w(wszMethodName
), pstrClassName
);
970 static const IWbemClassObjectVtbl class_object_vtbl
=
972 class_object_QueryInterface
,
974 class_object_Release
,
975 class_object_GetQualifierSet
,
979 class_object_GetNames
,
980 class_object_BeginEnumeration
,
982 class_object_EndEnumeration
,
983 class_object_GetPropertyQualifierSet
,
985 class_object_GetObjectText
,
986 class_object_SpawnDerivedClass
,
987 class_object_SpawnInstance
,
988 class_object_CompareTo
,
989 class_object_GetPropertyOrigin
,
990 class_object_InheritsFrom
,
991 class_object_GetMethod
,
992 class_object_PutMethod
,
993 class_object_DeleteMethod
,
994 class_object_BeginMethodEnumeration
,
995 class_object_NextMethod
,
996 class_object_EndMethodEnumeration
,
997 class_object_GetMethodQualifierSet
,
998 class_object_GetMethodOrigin
1001 HRESULT
create_class_object( const WCHAR
*name
, IEnumWbemClassObject
*iter
, UINT index
,
1002 struct record
*record
, IWbemClassObject
**obj
)
1004 struct class_object
*co
;
1006 TRACE("%s, %p\n", debugstr_w(name
), obj
);
1008 co
= heap_alloc( sizeof(*co
) );
1009 if (!co
) return E_OUTOFMEMORY
;
1011 co
->IWbemClassObject_iface
.lpVtbl
= &class_object_vtbl
;
1013 if (!name
) co
->name
= NULL
;
1014 else if (!(co
->name
= heap_strdupW( name
)))
1017 return E_OUTOFMEMORY
;
1021 co
->index_method
= 0;
1022 co
->index_property
= 0;
1023 co
->record
= record
;
1024 if (iter
) IEnumWbemClassObject_AddRef( iter
);
1026 *obj
= &co
->IWbemClassObject_iface
;
1028 TRACE("returning iface %p\n", *obj
);