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
)
113 if (!once
++) FIXME("timeout not supported\n");
117 if (ec
->index
>= view
->count
) return WBEM_S_FALSE
;
119 hr
= create_class_object( view
->table
->name
, iface
, ec
->index
, NULL
, apObjects
);
120 if (hr
!= S_OK
) return hr
;
124 if (ec
->index
== view
->count
&& uCount
> 1) return WBEM_S_FALSE
;
125 if (uCount
> 1) return WBEM_S_TIMEDOUT
;
126 return WBEM_S_NO_ERROR
;
129 static HRESULT WINAPI
enum_class_object_NextAsync(
130 IEnumWbemClassObject
*iface
,
132 IWbemObjectSink
*pSink
)
134 FIXME("%p, %u, %p\n", iface
, uCount
, pSink
);
138 static HRESULT WINAPI
enum_class_object_Clone(
139 IEnumWbemClassObject
*iface
,
140 IEnumWbemClassObject
**ppEnum
)
142 struct enum_class_object
*ec
= impl_from_IEnumWbemClassObject( iface
);
144 TRACE("%p, %p\n", iface
, ppEnum
);
146 return EnumWbemClassObject_create( ec
->query
, (void **)ppEnum
);
149 static HRESULT WINAPI
enum_class_object_Skip(
150 IEnumWbemClassObject
*iface
,
154 struct enum_class_object
*ec
= impl_from_IEnumWbemClassObject( iface
);
155 struct view
*view
= ec
->query
->view
;
157 TRACE("%p, %d, %u\n", iface
, lTimeout
, nCount
);
159 if (lTimeout
!= WBEM_INFINITE
) FIXME("timeout not supported\n");
161 if (!view
->count
) return WBEM_S_FALSE
;
163 if (nCount
> view
->count
- ec
->index
)
165 ec
->index
= view
->count
- 1;
169 return WBEM_S_NO_ERROR
;
172 static const IEnumWbemClassObjectVtbl enum_class_object_vtbl
=
174 enum_class_object_QueryInterface
,
175 enum_class_object_AddRef
,
176 enum_class_object_Release
,
177 enum_class_object_Reset
,
178 enum_class_object_Next
,
179 enum_class_object_NextAsync
,
180 enum_class_object_Clone
,
181 enum_class_object_Skip
184 HRESULT
EnumWbemClassObject_create( struct query
*query
, LPVOID
*ppObj
)
186 struct enum_class_object
*ec
;
188 TRACE("%p\n", ppObj
);
190 ec
= heap_alloc( sizeof(*ec
) );
191 if (!ec
) return E_OUTOFMEMORY
;
193 ec
->IEnumWbemClassObject_iface
.lpVtbl
= &enum_class_object_vtbl
;
195 ec
->query
= addref_query( query
);
198 *ppObj
= &ec
->IEnumWbemClassObject_iface
;
200 TRACE("returning iface %p\n", *ppObj
);
204 static struct record
*create_record( struct table
*table
)
207 struct record
*record
;
209 if (!(record
= heap_alloc( sizeof(struct record
) ))) return NULL
;
210 if (!(record
->fields
= heap_alloc( table
->num_cols
* sizeof(struct field
) )))
215 for (i
= 0; i
< table
->num_cols
; i
++)
217 record
->fields
[i
].type
= table
->columns
[i
].type
;
218 record
->fields
[i
].vartype
= table
->columns
[i
].vartype
;
219 record
->fields
[i
].u
.ival
= 0;
221 record
->count
= table
->num_cols
;
222 record
->table
= addref_table( table
);
226 void destroy_array( struct array
*array
, CIMTYPE type
)
231 if (type
== CIM_STRING
|| type
== CIM_DATETIME
)
233 size
= get_type_size( type
);
234 for (i
= 0; i
< array
->count
; i
++) heap_free( *(WCHAR
**)((char *)array
->ptr
+ i
* size
) );
236 heap_free( array
->ptr
);
240 static void destroy_record( struct record
*record
)
245 release_table( record
->table
);
246 for (i
= 0; i
< record
->count
; i
++)
248 if (record
->fields
[i
].type
== CIM_STRING
|| record
->fields
[i
].type
== CIM_DATETIME
)
249 heap_free( record
->fields
[i
].u
.sval
);
250 else if (record
->fields
[i
].type
& CIM_FLAG_ARRAY
)
251 destroy_array( record
->fields
[i
].u
.aval
, record
->fields
[i
].type
& CIM_TYPE_MASK
);
253 heap_free( record
->fields
);
259 IWbemClassObject IWbemClassObject_iface
;
262 IEnumWbemClassObject
*iter
;
266 struct record
*record
; /* uncommitted instance */
269 static inline struct class_object
*impl_from_IWbemClassObject(
270 IWbemClassObject
*iface
)
272 return CONTAINING_RECORD(iface
, struct class_object
, IWbemClassObject_iface
);
275 static ULONG WINAPI
class_object_AddRef(
276 IWbemClassObject
*iface
)
278 struct class_object
*co
= impl_from_IWbemClassObject( iface
);
279 return InterlockedIncrement( &co
->refs
);
282 static ULONG WINAPI
class_object_Release(
283 IWbemClassObject
*iface
)
285 struct class_object
*co
= impl_from_IWbemClassObject( iface
);
286 LONG refs
= InterlockedDecrement( &co
->refs
);
289 TRACE("destroying %p\n", co
);
290 if (co
->iter
) IEnumWbemClassObject_Release( co
->iter
);
291 destroy_record( co
->record
);
292 heap_free( co
->name
);
298 static HRESULT WINAPI
class_object_QueryInterface(
299 IWbemClassObject
*iface
,
303 struct class_object
*co
= impl_from_IWbemClassObject( iface
);
305 TRACE("%p, %s, %p\n", co
, debugstr_guid( riid
), ppvObject
);
307 if ( IsEqualGUID( riid
, &IID_IWbemClassObject
) ||
308 IsEqualGUID( riid
, &IID_IUnknown
) )
312 else if (IsEqualGUID( riid
, &IID_IClientSecurity
))
314 *ppvObject
= &client_security
;
319 FIXME("interface %s not implemented\n", debugstr_guid(riid
));
320 return E_NOINTERFACE
;
322 IWbemClassObject_AddRef( iface
);
326 static HRESULT WINAPI
class_object_GetQualifierSet(
327 IWbemClassObject
*iface
,
328 IWbemQualifierSet
**ppQualSet
)
330 FIXME("%p, %p\n", iface
, ppQualSet
);
334 static HRESULT
record_get_value( const struct record
*record
, UINT index
, VARIANT
*var
, CIMTYPE
*type
)
336 VARTYPE vartype
= record
->fields
[index
].vartype
;
338 if (type
) *type
= record
->fields
[index
].type
;
340 if (record
->fields
[index
].type
& CIM_FLAG_ARRAY
)
342 V_VT( var
) = vartype
? vartype
: to_vartype( record
->fields
[index
].type
& CIM_TYPE_MASK
) | VT_ARRAY
;
343 V_ARRAY( var
) = to_safearray( record
->fields
[index
].u
.aval
, record
->fields
[index
].type
& CIM_TYPE_MASK
);
346 switch (record
->fields
[index
].type
)
350 if (!vartype
) vartype
= VT_BSTR
;
351 V_BSTR( var
) = SysAllocString( record
->fields
[index
].u
.sval
);
354 if (!vartype
) vartype
= VT_I4
;
355 V_I4( var
) = record
->fields
[index
].u
.ival
;
358 if (!vartype
) vartype
= VT_UI4
;
359 V_UI4( var
) = record
->fields
[index
].u
.ival
;
362 FIXME("unhandled type %u\n", record
->fields
[index
].type
);
363 return WBEM_E_INVALID_PARAMETER
;
365 V_VT( var
) = vartype
;
369 static HRESULT WINAPI
class_object_Get(
370 IWbemClassObject
*iface
,
377 struct class_object
*co
= impl_from_IWbemClassObject( iface
);
378 struct enum_class_object
*ec
= impl_from_IEnumWbemClassObject( co
->iter
);
380 TRACE("%p, %s, %08x, %p, %p, %p\n", iface
, debugstr_w(wszName
), lFlags
, pVal
, pType
, plFlavor
);
387 if ((hr
= get_column_index( co
->record
->table
, wszName
, &index
)) != S_OK
) return hr
;
388 return record_get_value( co
->record
, index
, pVal
, pType
);
390 return get_propval( ec
->query
->view
, co
->index
, wszName
, pVal
, pType
, plFlavor
);
393 static HRESULT
record_set_value( struct record
*record
, UINT index
, VARIANT
*var
)
399 if ((hr
= to_longlong( var
, &val
, &type
)) != S_OK
) return hr
;
400 if (type
!= record
->fields
[index
].type
) return WBEM_E_TYPE_MISMATCH
;
402 if (type
& CIM_FLAG_ARRAY
)
404 record
->fields
[index
].u
.aval
= (struct array
*)(INT_PTR
)val
;
411 record
->fields
[index
].u
.sval
= (WCHAR
*)(INT_PTR
)val
;
417 record
->fields
[index
].u
.ival
= val
;
420 FIXME("unhandled type %u\n", type
);
423 return WBEM_E_INVALID_PARAMETER
;
426 static HRESULT WINAPI
class_object_Put(
427 IWbemClassObject
*iface
,
433 struct class_object
*co
= impl_from_IWbemClassObject( iface
);
434 struct enum_class_object
*ec
= impl_from_IEnumWbemClassObject( co
->iter
);
436 TRACE("%p, %s, %08x, %p, %u\n", iface
, debugstr_w(wszName
), lFlags
, pVal
, Type
);
443 if ((hr
= get_column_index( co
->record
->table
, wszName
, &index
)) != S_OK
) return hr
;
444 return record_set_value( co
->record
, index
, pVal
);
446 return put_propval( ec
->query
->view
, co
->index
, wszName
, pVal
, Type
);
449 static HRESULT WINAPI
class_object_Delete(
450 IWbemClassObject
*iface
,
453 FIXME("%p, %s\n", iface
, debugstr_w(wszName
));
457 static HRESULT WINAPI
class_object_GetNames(
458 IWbemClassObject
*iface
,
459 LPCWSTR wszQualifierName
,
461 VARIANT
*pQualifierVal
,
464 struct class_object
*co
= impl_from_IWbemClassObject( iface
);
465 struct enum_class_object
*ec
= impl_from_IEnumWbemClassObject( co
->iter
);
467 TRACE("%p, %s, %08x, %s, %p\n", iface
, debugstr_w(wszQualifierName
), lFlags
,
468 debugstr_variant(pQualifierVal
), pNames
);
470 if (lFlags
!= WBEM_FLAG_ALWAYS
&&
471 lFlags
!= WBEM_FLAG_NONSYSTEM_ONLY
&&
472 lFlags
!= WBEM_FLAG_SYSTEM_ONLY
)
474 FIXME("flags %08x not supported\n", lFlags
);
477 if (wszQualifierName
|| pQualifierVal
)
478 FIXME("qualifier not supported\n");
480 return get_properties( ec
->query
->view
, lFlags
, pNames
);
483 static HRESULT WINAPI
class_object_BeginEnumeration(
484 IWbemClassObject
*iface
,
487 struct class_object
*co
= impl_from_IWbemClassObject( iface
);
489 TRACE("%p, %08x\n", iface
, lEnumFlags
);
491 if (lEnumFlags
) FIXME("flags 0x%08x not supported\n", lEnumFlags
);
493 co
->index_property
= 0;
497 static HRESULT WINAPI
class_object_Next(
498 IWbemClassObject
*iface
,
505 struct class_object
*obj
= impl_from_IWbemClassObject( iface
);
506 struct enum_class_object
*iter
= impl_from_IEnumWbemClassObject( obj
->iter
);
507 struct view
*view
= iter
->query
->view
;
512 TRACE("%p, %08x, %p, %p, %p, %p\n", iface
, lFlags
, strName
, pVal
, pType
, plFlavor
);
514 for (i
= obj
->index_property
; i
< view
->table
->num_cols
; i
++)
516 if (is_method( view
->table
, i
)) continue;
517 if (!is_selected_prop( view
, view
->table
->columns
[i
].name
)) continue;
518 if (!(prop
= SysAllocString( view
->table
->columns
[i
].name
))) return E_OUTOFMEMORY
;
519 if ((hr
= get_propval( view
, obj
->index
, prop
, pVal
, pType
, plFlavor
)) != S_OK
)
521 SysFreeString( prop
);
524 obj
->index_property
= i
+ 1;
528 return WBEM_S_NO_MORE_DATA
;
531 static HRESULT WINAPI
class_object_EndEnumeration(
532 IWbemClassObject
*iface
)
534 struct class_object
*co
= impl_from_IWbemClassObject( iface
);
536 TRACE("%p\n", iface
);
538 co
->index_property
= 0;
542 static HRESULT WINAPI
class_object_GetPropertyQualifierSet(
543 IWbemClassObject
*iface
,
545 IWbemQualifierSet
**ppQualSet
)
547 struct class_object
*co
= impl_from_IWbemClassObject( iface
);
549 TRACE("%p, %s, %p\n", iface
, debugstr_w(wszProperty
), ppQualSet
);
551 return WbemQualifierSet_create( co
->name
, wszProperty
, (void **)ppQualSet
);
554 static HRESULT WINAPI
class_object_Clone(
555 IWbemClassObject
*iface
,
556 IWbemClassObject
**ppCopy
)
558 FIXME("%p, %p\n", iface
, ppCopy
);
562 static BSTR
get_body_text( const struct table
*table
, UINT row
, UINT
*len
)
564 static const WCHAR fmtW
[] = {'\n','\t','%','s',' ','=',' ','%','s',';',0};
570 for (i
= 0; i
< table
->num_cols
; i
++)
572 if ((value
= get_value_bstr( table
, row
, i
)))
574 *len
+= sizeof(fmtW
) / sizeof(fmtW
[0]);
575 *len
+= strlenW( table
->columns
[i
].name
);
576 *len
+= SysStringLen( value
);
577 SysFreeString( value
);
580 if (!(ret
= SysAllocStringLen( NULL
, *len
))) return NULL
;
582 for (i
= 0; i
< table
->num_cols
; i
++)
584 if ((value
= get_value_bstr( table
, row
, i
)))
586 p
+= sprintfW( p
, fmtW
, table
->columns
[i
].name
, value
);
587 SysFreeString( value
);
593 static BSTR
get_object_text( const struct view
*view
, UINT index
)
595 static const WCHAR fmtW
[] =
596 {'\n','i','n','s','t','a','n','c','e',' ','o','f',' ','%','s','\n','{','%','s','\n','}',';',0};
597 UINT len
, len_body
, row
= view
->result
[index
];
600 len
= sizeof(fmtW
) / sizeof(fmtW
[0]);
601 len
+= strlenW( view
->table
->name
);
602 if (!(body
= get_body_text( view
->table
, row
, &len_body
))) return NULL
;
605 if (!(ret
= SysAllocStringLen( NULL
, len
))) return NULL
;
606 sprintfW( ret
, fmtW
, view
->table
->name
, body
);
607 SysFreeString( body
);
611 static HRESULT WINAPI
class_object_GetObjectText(
612 IWbemClassObject
*iface
,
614 BSTR
*pstrObjectText
)
616 struct class_object
*co
= impl_from_IWbemClassObject( iface
);
617 struct enum_class_object
*ec
= impl_from_IEnumWbemClassObject( co
->iter
);
618 struct view
*view
= ec
->query
->view
;
621 TRACE("%p, %08x, %p\n", iface
, lFlags
, pstrObjectText
);
623 if (lFlags
) FIXME("flags %08x not implemented\n", lFlags
);
625 if (!(text
= get_object_text( view
, co
->index
))) return E_OUTOFMEMORY
;
626 *pstrObjectText
= text
;
630 static HRESULT WINAPI
class_object_SpawnDerivedClass(
631 IWbemClassObject
*iface
,
633 IWbemClassObject
**ppNewClass
)
635 FIXME("%p, %08x, %p\n", iface
, lFlags
, ppNewClass
);
639 static HRESULT WINAPI
class_object_SpawnInstance(
640 IWbemClassObject
*iface
,
642 IWbemClassObject
**ppNewInstance
)
644 struct class_object
*co
= impl_from_IWbemClassObject( iface
);
645 struct enum_class_object
*ec
= impl_from_IEnumWbemClassObject( co
->iter
);
646 struct view
*view
= ec
->query
->view
;
647 struct record
*record
;
649 TRACE("%p, %08x, %p\n", iface
, lFlags
, ppNewInstance
);
651 if (!(record
= create_record( view
->table
))) return E_OUTOFMEMORY
;
653 return create_class_object( co
->name
, NULL
, 0, record
, ppNewInstance
);
656 static HRESULT WINAPI
class_object_CompareTo(
657 IWbemClassObject
*iface
,
659 IWbemClassObject
*pCompareTo
)
661 FIXME("%p, %08x, %p\n", iface
, lFlags
, pCompareTo
);
665 static HRESULT WINAPI
class_object_GetPropertyOrigin(
666 IWbemClassObject
*iface
,
668 BSTR
*pstrClassName
)
670 FIXME("%p, %s, %p\n", iface
, debugstr_w(wszName
), pstrClassName
);
674 static HRESULT WINAPI
class_object_InheritsFrom(
675 IWbemClassObject
*iface
,
676 LPCWSTR strAncestor
)
678 FIXME("%p, %s\n", iface
, debugstr_w(strAncestor
));
682 static UINT
count_instances( IEnumWbemClassObject
*iter
)
685 while (!IEnumWbemClassObject_Skip( iter
, WBEM_INFINITE
, 1 )) count
++;
686 IEnumWbemClassObject_Reset( iter
);
690 static void set_default_value( CIMTYPE type
, UINT val
, BYTE
*ptr
)
698 *(UINT16
*)ptr
= val
;
704 *(UINT32
*)ptr
= val
;
707 FIXME("unhandled type %u\n", type
);
712 static HRESULT
create_signature_columns_and_data( IEnumWbemClassObject
*iter
, UINT
*num_cols
,
713 struct column
**cols
, BYTE
**data
)
715 static const WCHAR parameterW
[] = {'P','a','r','a','m','e','t','e','r',0};
716 static const WCHAR typeW
[] = {'T','y','p','e',0};
717 static const WCHAR varianttypeW
[] = {'V','a','r','i','a','n','t','T','y','p','e',0};
718 static const WCHAR defaultvalueW
[] = {'D','e','f','a','u','l','t','V','a','l','u','e',0};
719 struct column
*columns
;
721 IWbemClassObject
*param
;
723 HRESULT hr
= E_OUTOFMEMORY
;
728 count
= count_instances( iter
);
729 if (!(columns
= heap_alloc( count
* sizeof(struct column
) ))) return E_OUTOFMEMORY
;
730 if (!(row
= heap_alloc_zero( count
* sizeof(LONGLONG
) ))) goto error
;
734 IEnumWbemClassObject_Next( iter
, WBEM_INFINITE
, 1, ¶m
, &count
);
737 hr
= IWbemClassObject_Get( param
, parameterW
, 0, &val
, NULL
, NULL
);
738 if (hr
!= S_OK
) goto error
;
739 columns
[i
].name
= heap_strdupW( V_BSTR( &val
) );
740 VariantClear( &val
);
742 hr
= IWbemClassObject_Get( param
, typeW
, 0, &val
, NULL
, NULL
);
743 if (hr
!= S_OK
) goto error
;
744 columns
[i
].type
= V_UI4( &val
);
746 hr
= IWbemClassObject_Get( param
, varianttypeW
, 0, &val
, NULL
, NULL
);
747 if (hr
!= S_OK
) goto error
;
748 columns
[i
].vartype
= V_UI4( &val
);
750 hr
= IWbemClassObject_Get( param
, defaultvalueW
, 0, &val
, NULL
, NULL
);
751 if (hr
!= S_OK
) goto error
;
752 if (V_UI4( &val
)) set_default_value( columns
[i
].type
, V_UI4( &val
), row
+ offset
);
753 offset
+= get_type_size( columns
[i
].type
);
755 IWbemClassObject_Release( param
);
764 for (; i
>= 0; i
--) heap_free( (WCHAR
*)columns
[i
].name
);
765 heap_free( columns
);
770 static HRESULT
create_signature_table( IEnumWbemClassObject
*iter
, WCHAR
*name
)
774 struct column
*columns
;
778 hr
= create_signature_columns_and_data( iter
, &num_cols
, &columns
, &row
);
779 if (hr
!= S_OK
) return hr
;
781 if (!(table
= create_table( name
, num_cols
, columns
, 1, 1, row
, NULL
)))
783 free_columns( columns
, num_cols
);
785 return E_OUTOFMEMORY
;
787 if (!add_table( table
)) free_table( table
); /* already exists */
791 static WCHAR
*build_signature_table_name( const WCHAR
*class, const WCHAR
*method
, enum param_direction dir
)
793 static const WCHAR fmtW
[] = {'_','_','%','s','_','%','s','_','%','s',0};
794 static const WCHAR outW
[] = {'O','U','T',0};
795 static const WCHAR inW
[] = {'I','N',0};
796 UINT len
= SIZEOF(fmtW
) + SIZEOF(outW
) + strlenW( class ) + strlenW( method
);
799 if (!(ret
= heap_alloc( len
* sizeof(WCHAR
) ))) return NULL
;
800 sprintfW( ret
, fmtW
, class, method
, dir
== PARAM_IN
? inW
: outW
);
801 return struprW( ret
);
804 HRESULT
create_signature( const WCHAR
*class, const WCHAR
*method
, enum param_direction dir
,
805 IWbemClassObject
**sig
)
807 static const WCHAR selectW
[] =
808 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
809 '_','_','P','A','R','A','M','E','T','E','R','S',' ','W','H','E','R','E',' ',
810 'C','l','a','s','s','=','\'','%','s','\'',' ','A','N','D',' ',
811 'M','e','t','h','o','d','=','\'','%','s','\'',' ','A','N','D',' ',
812 'D','i','r','e','c','t','i','o','n','%','s',0};
813 static const WCHAR geW
[] = {'>','=','0',0};
814 static const WCHAR leW
[] = {'<','=','0',0};
815 UINT len
= SIZEOF(selectW
) + SIZEOF(geW
);
816 IEnumWbemClassObject
*iter
;
820 len
+= strlenW( class ) + strlenW( method
);
821 if (!(query
= heap_alloc( len
* sizeof(WCHAR
) ))) return E_OUTOFMEMORY
;
822 sprintfW( query
, selectW
, class, method
, dir
>= 0 ? geW
: leW
);
824 hr
= exec_query( query
, &iter
);
826 if (hr
!= S_OK
) return hr
;
828 if (!(name
= build_signature_table_name( class, method
, dir
)))
830 IEnumWbemClassObject_Release( iter
);
831 return E_OUTOFMEMORY
;
833 hr
= create_signature_table( iter
, name
);
834 IEnumWbemClassObject_Release( iter
);
836 hr
= get_object( name
, sig
);
842 static HRESULT WINAPI
class_object_GetMethod(
843 IWbemClassObject
*iface
,
846 IWbemClassObject
**ppInSignature
,
847 IWbemClassObject
**ppOutSignature
)
849 struct class_object
*co
= impl_from_IWbemClassObject( iface
);
850 IWbemClassObject
*in
, *out
;
853 TRACE("%p, %s, %08x, %p, %p\n", iface
, debugstr_w(wszName
), lFlags
, ppInSignature
, ppOutSignature
);
855 hr
= create_signature( co
->name
, wszName
, PARAM_IN
, &in
);
856 if (hr
!= S_OK
) return hr
;
858 hr
= create_signature( co
->name
, wszName
, PARAM_OUT
, &out
);
861 if (ppInSignature
) *ppInSignature
= in
;
862 else IWbemClassObject_Release( in
);
863 if (ppOutSignature
) *ppOutSignature
= out
;
864 else IWbemClassObject_Release( out
);
866 else IWbemClassObject_Release( in
);
870 static HRESULT WINAPI
class_object_PutMethod(
871 IWbemClassObject
*iface
,
874 IWbemClassObject
*pInSignature
,
875 IWbemClassObject
*pOutSignature
)
877 FIXME("%p, %s, %08x, %p, %p\n", iface
, debugstr_w(wszName
), lFlags
, pInSignature
, pOutSignature
);
881 static HRESULT WINAPI
class_object_DeleteMethod(
882 IWbemClassObject
*iface
,
885 FIXME("%p, %s\n", iface
, debugstr_w(wszName
));
889 static HRESULT WINAPI
class_object_BeginMethodEnumeration(
890 IWbemClassObject
*iface
,
893 struct class_object
*co
= impl_from_IWbemClassObject( iface
);
895 TRACE("%p, %08x\n", iface
, lEnumFlags
);
897 if (lEnumFlags
) FIXME("flags 0x%08x not supported\n", lEnumFlags
);
901 WARN("not allowed on instance\n");
902 return WBEM_E_ILLEGAL_OPERATION
;
904 co
->index_method
= 0;
908 static HRESULT WINAPI
class_object_NextMethod(
909 IWbemClassObject
*iface
,
912 IWbemClassObject
**ppInSignature
,
913 IWbemClassObject
**ppOutSignature
)
915 struct class_object
*co
= impl_from_IWbemClassObject( iface
);
919 TRACE("%p, %08x, %p, %p, %p\n", iface
, lFlags
, pstrName
, ppInSignature
, ppOutSignature
);
921 if (!(method
= get_method_name( co
->name
, co
->index_method
))) return WBEM_S_NO_MORE_DATA
;
923 hr
= create_signature( co
->name
, method
, PARAM_IN
, ppInSignature
);
926 SysFreeString( method
);
929 hr
= create_signature( co
->name
, method
, PARAM_OUT
, ppOutSignature
);
932 SysFreeString( method
);
933 IWbemClassObject_Release( *ppInSignature
);
943 static HRESULT WINAPI
class_object_EndMethodEnumeration(
944 IWbemClassObject
*iface
)
946 struct class_object
*co
= impl_from_IWbemClassObject( iface
);
948 TRACE("%p\n", iface
);
950 co
->index_method
= 0;
954 static HRESULT WINAPI
class_object_GetMethodQualifierSet(
955 IWbemClassObject
*iface
,
957 IWbemQualifierSet
**ppQualSet
)
959 FIXME("%p, %s, %p\n", iface
, debugstr_w(wszMethod
), ppQualSet
);
963 static HRESULT WINAPI
class_object_GetMethodOrigin(
964 IWbemClassObject
*iface
,
965 LPCWSTR wszMethodName
,
968 FIXME("%p, %s, %p\n", iface
, debugstr_w(wszMethodName
), pstrClassName
);
972 static const IWbemClassObjectVtbl class_object_vtbl
=
974 class_object_QueryInterface
,
976 class_object_Release
,
977 class_object_GetQualifierSet
,
981 class_object_GetNames
,
982 class_object_BeginEnumeration
,
984 class_object_EndEnumeration
,
985 class_object_GetPropertyQualifierSet
,
987 class_object_GetObjectText
,
988 class_object_SpawnDerivedClass
,
989 class_object_SpawnInstance
,
990 class_object_CompareTo
,
991 class_object_GetPropertyOrigin
,
992 class_object_InheritsFrom
,
993 class_object_GetMethod
,
994 class_object_PutMethod
,
995 class_object_DeleteMethod
,
996 class_object_BeginMethodEnumeration
,
997 class_object_NextMethod
,
998 class_object_EndMethodEnumeration
,
999 class_object_GetMethodQualifierSet
,
1000 class_object_GetMethodOrigin
1003 HRESULT
create_class_object( const WCHAR
*name
, IEnumWbemClassObject
*iter
, UINT index
,
1004 struct record
*record
, IWbemClassObject
**obj
)
1006 struct class_object
*co
;
1008 TRACE("%s, %p\n", debugstr_w(name
), obj
);
1010 co
= heap_alloc( sizeof(*co
) );
1011 if (!co
) return E_OUTOFMEMORY
;
1013 co
->IWbemClassObject_iface
.lpVtbl
= &class_object_vtbl
;
1015 if (!name
) co
->name
= NULL
;
1016 else if (!(co
->name
= heap_strdupW( name
)))
1019 return E_OUTOFMEMORY
;
1023 co
->index_method
= 0;
1024 co
->index_property
= 0;
1025 co
->record
= record
;
1026 if (iter
) IEnumWbemClassObject_AddRef( iter
);
1028 *obj
= &co
->IWbemClassObject_iface
;
1030 TRACE("returning iface %p\n", *obj
);