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
29 #include "wine/debug.h"
30 #include "wbemprox_private.h"
32 WINE_DEFAULT_DEBUG_CHANNEL(wbemprox
);
34 struct enum_class_object
36 IEnumWbemClassObject IEnumWbemClassObject_iface
;
42 static inline struct enum_class_object
*impl_from_IEnumWbemClassObject(
43 IEnumWbemClassObject
*iface
)
45 return CONTAINING_RECORD(iface
, struct enum_class_object
, IEnumWbemClassObject_iface
);
48 static ULONG WINAPI
enum_class_object_AddRef(
49 IEnumWbemClassObject
*iface
)
51 struct enum_class_object
*ec
= impl_from_IEnumWbemClassObject( iface
);
52 return InterlockedIncrement( &ec
->refs
);
55 static ULONG WINAPI
enum_class_object_Release(
56 IEnumWbemClassObject
*iface
)
58 struct enum_class_object
*ec
= impl_from_IEnumWbemClassObject( iface
);
59 LONG refs
= InterlockedDecrement( &ec
->refs
);
62 TRACE("destroying %p\n", ec
);
63 release_query( ec
->query
);
69 static HRESULT WINAPI
enum_class_object_QueryInterface(
70 IEnumWbemClassObject
*iface
,
74 struct enum_class_object
*ec
= impl_from_IEnumWbemClassObject( iface
);
76 TRACE("%p, %s, %p\n", ec
, debugstr_guid( riid
), ppvObject
);
78 if ( IsEqualGUID( riid
, &IID_IEnumWbemClassObject
) ||
79 IsEqualGUID( riid
, &IID_IUnknown
) )
83 else if ( IsEqualGUID( riid
, &IID_IClientSecurity
) )
85 *ppvObject
= &client_security
;
90 FIXME("interface %s not implemented\n", debugstr_guid(riid
));
93 IEnumWbemClassObject_AddRef( iface
);
97 static HRESULT WINAPI
enum_class_object_Reset(
98 IEnumWbemClassObject
*iface
)
100 struct enum_class_object
*ec
= impl_from_IEnumWbemClassObject( iface
);
102 TRACE("%p\n", iface
);
105 return WBEM_S_NO_ERROR
;
108 static HRESULT WINAPI
enum_class_object_Next(
109 IEnumWbemClassObject
*iface
,
112 IWbemClassObject
**apObjects
,
115 struct enum_class_object
*ec
= impl_from_IEnumWbemClassObject( iface
);
116 struct view
*view
= ec
->query
->view
;
119 TRACE("%p, %d, %u, %p, %p\n", iface
, lTimeout
, uCount
, apObjects
, puReturned
);
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");
126 if (ec
->index
>= view
->count
) return WBEM_S_FALSE
;
128 hr
= create_class_object( view
->table
->name
, iface
, ec
->index
, NULL
, apObjects
);
129 if (hr
!= S_OK
) return hr
;
133 if (ec
->index
== view
->count
&& uCount
> 1) return WBEM_S_FALSE
;
134 if (uCount
> 1) return WBEM_S_TIMEDOUT
;
135 return WBEM_S_NO_ERROR
;
138 static HRESULT WINAPI
enum_class_object_NextAsync(
139 IEnumWbemClassObject
*iface
,
141 IWbemObjectSink
*pSink
)
143 FIXME("%p, %u, %p\n", iface
, uCount
, pSink
);
147 static HRESULT WINAPI
enum_class_object_Clone(
148 IEnumWbemClassObject
*iface
,
149 IEnumWbemClassObject
**ppEnum
)
151 struct enum_class_object
*ec
= impl_from_IEnumWbemClassObject( iface
);
153 TRACE("%p, %p\n", iface
, ppEnum
);
155 return EnumWbemClassObject_create( ec
->query
, (void **)ppEnum
);
158 static HRESULT WINAPI
enum_class_object_Skip(
159 IEnumWbemClassObject
*iface
,
163 struct enum_class_object
*ec
= impl_from_IEnumWbemClassObject( iface
);
164 struct view
*view
= ec
->query
->view
;
166 TRACE("%p, %d, %u\n", iface
, lTimeout
, nCount
);
168 if (lTimeout
!= WBEM_INFINITE
) FIXME("timeout not supported\n");
170 if (!view
->count
) return WBEM_S_FALSE
;
172 if (nCount
> view
->count
- ec
->index
)
174 ec
->index
= view
->count
- 1;
178 return WBEM_S_NO_ERROR
;
181 static const IEnumWbemClassObjectVtbl enum_class_object_vtbl
=
183 enum_class_object_QueryInterface
,
184 enum_class_object_AddRef
,
185 enum_class_object_Release
,
186 enum_class_object_Reset
,
187 enum_class_object_Next
,
188 enum_class_object_NextAsync
,
189 enum_class_object_Clone
,
190 enum_class_object_Skip
193 HRESULT
EnumWbemClassObject_create( struct query
*query
, LPVOID
*ppObj
)
195 struct enum_class_object
*ec
;
197 TRACE("%p\n", ppObj
);
199 ec
= heap_alloc( sizeof(*ec
) );
200 if (!ec
) return E_OUTOFMEMORY
;
202 ec
->IEnumWbemClassObject_iface
.lpVtbl
= &enum_class_object_vtbl
;
204 ec
->query
= addref_query( query
);
207 *ppObj
= &ec
->IEnumWbemClassObject_iface
;
209 TRACE("returning iface %p\n", *ppObj
);
213 static struct record
*create_record( struct table
*table
)
216 struct record
*record
;
218 if (!(record
= heap_alloc( sizeof(struct record
) ))) return NULL
;
219 if (!(record
->fields
= heap_alloc( table
->num_cols
* sizeof(struct field
) )))
224 for (i
= 0; i
< table
->num_cols
; i
++)
226 record
->fields
[i
].type
= table
->columns
[i
].type
;
227 record
->fields
[i
].vartype
= table
->columns
[i
].vartype
;
228 record
->fields
[i
].u
.ival
= 0;
230 record
->count
= table
->num_cols
;
231 record
->table
= addref_table( table
);
235 void destroy_array( struct array
*array
, CIMTYPE type
)
240 if (type
== CIM_STRING
|| type
== CIM_DATETIME
)
242 size
= get_type_size( type
);
243 for (i
= 0; i
< array
->count
; i
++) heap_free( *(WCHAR
**)((char *)array
->ptr
+ i
* size
) );
245 heap_free( array
->ptr
);
249 static void destroy_record( struct record
*record
)
254 release_table( record
->table
);
255 for (i
= 0; i
< record
->count
; i
++)
257 if (record
->fields
[i
].type
== CIM_STRING
|| record
->fields
[i
].type
== CIM_DATETIME
)
258 heap_free( record
->fields
[i
].u
.sval
);
259 else if (record
->fields
[i
].type
& CIM_FLAG_ARRAY
)
260 destroy_array( record
->fields
[i
].u
.aval
, record
->fields
[i
].type
& CIM_TYPE_MASK
);
262 heap_free( record
->fields
);
268 IWbemClassObject IWbemClassObject_iface
;
271 IEnumWbemClassObject
*iter
;
275 struct record
*record
; /* uncommitted instance */
278 static inline struct class_object
*impl_from_IWbemClassObject(
279 IWbemClassObject
*iface
)
281 return CONTAINING_RECORD(iface
, struct class_object
, IWbemClassObject_iface
);
284 static ULONG WINAPI
class_object_AddRef(
285 IWbemClassObject
*iface
)
287 struct class_object
*co
= impl_from_IWbemClassObject( iface
);
288 return InterlockedIncrement( &co
->refs
);
291 static ULONG WINAPI
class_object_Release(
292 IWbemClassObject
*iface
)
294 struct class_object
*co
= impl_from_IWbemClassObject( iface
);
295 LONG refs
= InterlockedDecrement( &co
->refs
);
298 TRACE("destroying %p\n", co
);
299 if (co
->iter
) IEnumWbemClassObject_Release( co
->iter
);
300 destroy_record( co
->record
);
301 heap_free( co
->name
);
307 static HRESULT WINAPI
class_object_QueryInterface(
308 IWbemClassObject
*iface
,
312 struct class_object
*co
= impl_from_IWbemClassObject( iface
);
314 TRACE("%p, %s, %p\n", co
, debugstr_guid( riid
), ppvObject
);
316 if ( IsEqualGUID( riid
, &IID_IWbemClassObject
) ||
317 IsEqualGUID( riid
, &IID_IUnknown
) )
321 else if (IsEqualGUID( riid
, &IID_IClientSecurity
))
323 *ppvObject
= &client_security
;
328 FIXME("interface %s not implemented\n", debugstr_guid(riid
));
329 return E_NOINTERFACE
;
331 IWbemClassObject_AddRef( iface
);
335 static HRESULT WINAPI
class_object_GetQualifierSet(
336 IWbemClassObject
*iface
,
337 IWbemQualifierSet
**ppQualSet
)
339 FIXME("%p, %p\n", iface
, ppQualSet
);
343 static HRESULT
record_get_value( const struct record
*record
, UINT index
, VARIANT
*var
, CIMTYPE
*type
)
345 VARTYPE vartype
= record
->fields
[index
].vartype
;
347 if (type
) *type
= record
->fields
[index
].type
;
349 if (record
->fields
[index
].type
& CIM_FLAG_ARRAY
)
351 V_VT( var
) = vartype
? vartype
: to_vartype( record
->fields
[index
].type
& CIM_TYPE_MASK
) | VT_ARRAY
;
352 V_ARRAY( var
) = to_safearray( record
->fields
[index
].u
.aval
, record
->fields
[index
].type
& CIM_TYPE_MASK
);
355 switch (record
->fields
[index
].type
)
359 if (!vartype
) vartype
= VT_BSTR
;
360 V_BSTR( var
) = SysAllocString( record
->fields
[index
].u
.sval
);
363 if (!vartype
) vartype
= VT_I4
;
364 V_I4( var
) = record
->fields
[index
].u
.ival
;
367 if (!vartype
) vartype
= VT_UI4
;
368 V_UI4( var
) = record
->fields
[index
].u
.ival
;
371 FIXME("unhandled type %u\n", record
->fields
[index
].type
);
372 return WBEM_E_INVALID_PARAMETER
;
374 V_VT( var
) = vartype
;
378 static HRESULT WINAPI
class_object_Get(
379 IWbemClassObject
*iface
,
386 struct class_object
*co
= impl_from_IWbemClassObject( iface
);
387 struct enum_class_object
*ec
= impl_from_IEnumWbemClassObject( co
->iter
);
389 TRACE("%p, %s, %08x, %p, %p, %p\n", iface
, debugstr_w(wszName
), lFlags
, pVal
, pType
, plFlavor
);
396 if ((hr
= get_column_index( co
->record
->table
, wszName
, &index
)) != S_OK
) return hr
;
397 return record_get_value( co
->record
, index
, pVal
, pType
);
399 return get_propval( ec
->query
->view
, co
->index
, wszName
, pVal
, pType
, plFlavor
);
402 static HRESULT
record_set_value( struct record
*record
, UINT index
, VARIANT
*var
)
408 if ((hr
= to_longlong( var
, &val
, &type
)) != S_OK
) return hr
;
409 if (type
!= record
->fields
[index
].type
) return WBEM_E_TYPE_MISMATCH
;
411 if (type
& CIM_FLAG_ARRAY
)
413 record
->fields
[index
].u
.aval
= (struct array
*)(INT_PTR
)val
;
420 record
->fields
[index
].u
.sval
= (WCHAR
*)(INT_PTR
)val
;
426 record
->fields
[index
].u
.ival
= val
;
429 FIXME("unhandled type %u\n", type
);
432 return WBEM_E_INVALID_PARAMETER
;
435 static HRESULT WINAPI
class_object_Put(
436 IWbemClassObject
*iface
,
442 struct class_object
*co
= impl_from_IWbemClassObject( iface
);
443 struct enum_class_object
*ec
= impl_from_IEnumWbemClassObject( co
->iter
);
445 TRACE("%p, %s, %08x, %p, %u\n", iface
, debugstr_w(wszName
), lFlags
, pVal
, Type
);
452 if ((hr
= get_column_index( co
->record
->table
, wszName
, &index
)) != S_OK
) return hr
;
453 return record_set_value( co
->record
, index
, pVal
);
455 return put_propval( ec
->query
->view
, co
->index
, wszName
, pVal
, Type
);
458 static HRESULT WINAPI
class_object_Delete(
459 IWbemClassObject
*iface
,
462 FIXME("%p, %s\n", iface
, debugstr_w(wszName
));
466 static HRESULT WINAPI
class_object_GetNames(
467 IWbemClassObject
*iface
,
468 LPCWSTR wszQualifierName
,
470 VARIANT
*pQualifierVal
,
473 struct class_object
*co
= impl_from_IWbemClassObject( iface
);
474 struct enum_class_object
*ec
= impl_from_IEnumWbemClassObject( co
->iter
);
476 TRACE("%p, %s, %08x, %s, %p\n", iface
, debugstr_w(wszQualifierName
), lFlags
,
477 debugstr_variant(pQualifierVal
), pNames
);
479 if (lFlags
!= WBEM_FLAG_ALWAYS
&&
480 lFlags
!= WBEM_FLAG_NONSYSTEM_ONLY
&&
481 lFlags
!= WBEM_FLAG_SYSTEM_ONLY
)
483 FIXME("flags %08x not supported\n", lFlags
);
486 if (wszQualifierName
|| pQualifierVal
)
487 FIXME("qualifier not supported\n");
489 return get_properties( ec
->query
->view
, lFlags
, pNames
);
492 static HRESULT WINAPI
class_object_BeginEnumeration(
493 IWbemClassObject
*iface
,
496 struct class_object
*co
= impl_from_IWbemClassObject( iface
);
498 TRACE("%p, %08x\n", iface
, lEnumFlags
);
500 if (lEnumFlags
) FIXME("flags 0x%08x not supported\n", lEnumFlags
);
502 co
->index_property
= 0;
506 static HRESULT WINAPI
class_object_Next(
507 IWbemClassObject
*iface
,
514 struct class_object
*obj
= impl_from_IWbemClassObject( iface
);
515 struct enum_class_object
*iter
= impl_from_IEnumWbemClassObject( obj
->iter
);
516 struct view
*view
= iter
->query
->view
;
521 TRACE("%p, %08x, %p, %p, %p, %p\n", iface
, lFlags
, strName
, pVal
, pType
, plFlavor
);
523 for (i
= obj
->index_property
; i
< view
->table
->num_cols
; i
++)
525 if (is_method( view
->table
, i
)) continue;
526 if (!is_selected_prop( view
, view
->table
->columns
[i
].name
)) continue;
527 if (!(prop
= SysAllocString( view
->table
->columns
[i
].name
))) return E_OUTOFMEMORY
;
528 if ((hr
= get_propval( view
, obj
->index
, prop
, pVal
, pType
, plFlavor
)) != S_OK
)
530 SysFreeString( prop
);
533 obj
->index_property
= i
+ 1;
537 return WBEM_S_NO_MORE_DATA
;
540 static HRESULT WINAPI
class_object_EndEnumeration(
541 IWbemClassObject
*iface
)
543 struct class_object
*co
= impl_from_IWbemClassObject( iface
);
545 TRACE("%p\n", iface
);
547 co
->index_property
= 0;
551 static HRESULT WINAPI
class_object_GetPropertyQualifierSet(
552 IWbemClassObject
*iface
,
554 IWbemQualifierSet
**ppQualSet
)
556 struct class_object
*co
= impl_from_IWbemClassObject( iface
);
558 TRACE("%p, %s, %p\n", iface
, debugstr_w(wszProperty
), ppQualSet
);
560 return WbemQualifierSet_create( co
->name
, wszProperty
, (void **)ppQualSet
);
563 static HRESULT WINAPI
class_object_Clone(
564 IWbemClassObject
*iface
,
565 IWbemClassObject
**ppCopy
)
567 FIXME("%p, %p\n", iface
, ppCopy
);
571 static BSTR
get_body_text( const struct table
*table
, UINT row
, UINT
*len
)
573 static const WCHAR fmtW
[] = {'\n','\t','%','s',' ','=',' ','%','s',';',0};
579 for (i
= 0; i
< table
->num_cols
; i
++)
581 if ((value
= get_value_bstr( table
, row
, i
)))
583 *len
+= sizeof(fmtW
) / sizeof(fmtW
[0]);
584 *len
+= strlenW( table
->columns
[i
].name
);
585 *len
+= SysStringLen( value
);
586 SysFreeString( value
);
589 if (!(ret
= SysAllocStringLen( NULL
, *len
))) return NULL
;
591 for (i
= 0; i
< table
->num_cols
; i
++)
593 if ((value
= get_value_bstr( table
, row
, i
)))
595 p
+= sprintfW( p
, fmtW
, table
->columns
[i
].name
, value
);
596 SysFreeString( value
);
602 static BSTR
get_object_text( const struct view
*view
, UINT index
)
604 static const WCHAR fmtW
[] =
605 {'\n','i','n','s','t','a','n','c','e',' ','o','f',' ','%','s','\n','{','%','s','\n','}',';',0};
606 UINT len
, len_body
, row
= view
->result
[index
];
609 len
= sizeof(fmtW
) / sizeof(fmtW
[0]);
610 len
+= strlenW( view
->table
->name
);
611 if (!(body
= get_body_text( view
->table
, row
, &len_body
))) return NULL
;
614 if (!(ret
= SysAllocStringLen( NULL
, len
))) return NULL
;
615 sprintfW( ret
, fmtW
, view
->table
->name
, body
);
616 SysFreeString( body
);
620 static HRESULT WINAPI
class_object_GetObjectText(
621 IWbemClassObject
*iface
,
623 BSTR
*pstrObjectText
)
625 struct class_object
*co
= impl_from_IWbemClassObject( iface
);
626 struct enum_class_object
*ec
= impl_from_IEnumWbemClassObject( co
->iter
);
627 struct view
*view
= ec
->query
->view
;
630 TRACE("%p, %08x, %p\n", iface
, lFlags
, pstrObjectText
);
632 if (lFlags
) FIXME("flags %08x not implemented\n", lFlags
);
634 if (!(text
= get_object_text( view
, co
->index
))) return E_OUTOFMEMORY
;
635 *pstrObjectText
= text
;
639 static HRESULT WINAPI
class_object_SpawnDerivedClass(
640 IWbemClassObject
*iface
,
642 IWbemClassObject
**ppNewClass
)
644 FIXME("%p, %08x, %p\n", iface
, lFlags
, ppNewClass
);
648 static HRESULT WINAPI
class_object_SpawnInstance(
649 IWbemClassObject
*iface
,
651 IWbemClassObject
**ppNewInstance
)
653 struct class_object
*co
= impl_from_IWbemClassObject( iface
);
654 struct enum_class_object
*ec
= impl_from_IEnumWbemClassObject( co
->iter
);
655 struct view
*view
= ec
->query
->view
;
656 struct record
*record
;
658 TRACE("%p, %08x, %p\n", iface
, lFlags
, ppNewInstance
);
660 if (!(record
= create_record( view
->table
))) return E_OUTOFMEMORY
;
662 return create_class_object( co
->name
, NULL
, 0, record
, ppNewInstance
);
665 static HRESULT WINAPI
class_object_CompareTo(
666 IWbemClassObject
*iface
,
668 IWbemClassObject
*pCompareTo
)
670 FIXME("%p, %08x, %p\n", iface
, lFlags
, pCompareTo
);
674 static HRESULT WINAPI
class_object_GetPropertyOrigin(
675 IWbemClassObject
*iface
,
677 BSTR
*pstrClassName
)
679 FIXME("%p, %s, %p\n", iface
, debugstr_w(wszName
), pstrClassName
);
683 static HRESULT WINAPI
class_object_InheritsFrom(
684 IWbemClassObject
*iface
,
685 LPCWSTR strAncestor
)
687 FIXME("%p, %s\n", iface
, debugstr_w(strAncestor
));
691 static UINT
count_instances( IEnumWbemClassObject
*iter
)
694 while (!IEnumWbemClassObject_Skip( iter
, WBEM_INFINITE
, 1 )) count
++;
695 IEnumWbemClassObject_Reset( iter
);
699 static void set_default_value( CIMTYPE type
, UINT val
, BYTE
*ptr
)
707 *(UINT16
*)ptr
= val
;
713 *(UINT32
*)ptr
= val
;
716 FIXME("unhandled type %u\n", type
);
721 static HRESULT
create_signature_columns_and_data( IEnumWbemClassObject
*iter
, UINT
*num_cols
,
722 struct column
**cols
, BYTE
**data
)
724 static const WCHAR parameterW
[] = {'P','a','r','a','m','e','t','e','r',0};
725 static const WCHAR typeW
[] = {'T','y','p','e',0};
726 static const WCHAR varianttypeW
[] = {'V','a','r','i','a','n','t','T','y','p','e',0};
727 static const WCHAR defaultvalueW
[] = {'D','e','f','a','u','l','t','V','a','l','u','e',0};
728 struct column
*columns
;
730 IWbemClassObject
*param
;
732 HRESULT hr
= E_OUTOFMEMORY
;
737 count
= count_instances( iter
);
738 if (!(columns
= heap_alloc( count
* sizeof(struct column
) ))) return E_OUTOFMEMORY
;
739 if (!(row
= heap_alloc_zero( count
* sizeof(LONGLONG
) ))) goto error
;
743 IEnumWbemClassObject_Next( iter
, WBEM_INFINITE
, 1, ¶m
, &count
);
746 hr
= IWbemClassObject_Get( param
, parameterW
, 0, &val
, NULL
, NULL
);
747 if (hr
!= S_OK
) goto error
;
748 columns
[i
].name
= heap_strdupW( V_BSTR( &val
) );
749 VariantClear( &val
);
751 hr
= IWbemClassObject_Get( param
, typeW
, 0, &val
, NULL
, NULL
);
752 if (hr
!= S_OK
) goto error
;
753 columns
[i
].type
= V_UI4( &val
);
755 hr
= IWbemClassObject_Get( param
, varianttypeW
, 0, &val
, NULL
, NULL
);
756 if (hr
!= S_OK
) goto error
;
757 columns
[i
].vartype
= V_UI4( &val
);
759 hr
= IWbemClassObject_Get( param
, defaultvalueW
, 0, &val
, NULL
, NULL
);
760 if (hr
!= S_OK
) goto error
;
761 if (V_UI4( &val
)) set_default_value( columns
[i
].type
, V_UI4( &val
), row
+ offset
);
762 offset
+= get_type_size( columns
[i
].type
);
764 IWbemClassObject_Release( param
);
773 for (; i
>= 0; i
--) heap_free( (WCHAR
*)columns
[i
].name
);
774 heap_free( columns
);
779 static HRESULT
create_signature_table( IEnumWbemClassObject
*iter
, WCHAR
*name
)
783 struct column
*columns
;
787 hr
= create_signature_columns_and_data( iter
, &num_cols
, &columns
, &row
);
788 if (hr
!= S_OK
) return hr
;
790 if (!(table
= create_table( name
, num_cols
, columns
, 1, 1, row
, NULL
)))
792 free_columns( columns
, num_cols
);
794 return E_OUTOFMEMORY
;
796 if (!add_table( table
)) free_table( table
); /* already exists */
800 static WCHAR
*build_signature_table_name( const WCHAR
*class, const WCHAR
*method
, enum param_direction dir
)
802 static const WCHAR fmtW
[] = {'_','_','%','s','_','%','s','_','%','s',0};
803 static const WCHAR outW
[] = {'O','U','T',0};
804 static const WCHAR inW
[] = {'I','N',0};
805 UINT len
= SIZEOF(fmtW
) + SIZEOF(outW
) + strlenW( class ) + strlenW( method
);
808 if (!(ret
= heap_alloc( len
* sizeof(WCHAR
) ))) return NULL
;
809 sprintfW( ret
, fmtW
, class, method
, dir
== PARAM_IN
? inW
: outW
);
810 return struprW( ret
);
813 HRESULT
create_signature( const WCHAR
*class, const WCHAR
*method
, enum param_direction dir
,
814 IWbemClassObject
**sig
)
816 static const WCHAR selectW
[] =
817 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
818 '_','_','P','A','R','A','M','E','T','E','R','S',' ','W','H','E','R','E',' ',
819 'C','l','a','s','s','=','\'','%','s','\'',' ','A','N','D',' ',
820 'M','e','t','h','o','d','=','\'','%','s','\'',' ','A','N','D',' ',
821 'D','i','r','e','c','t','i','o','n','%','s',0};
822 static const WCHAR geW
[] = {'>','=','0',0};
823 static const WCHAR leW
[] = {'<','=','0',0};
824 UINT len
= SIZEOF(selectW
) + SIZEOF(geW
);
825 IEnumWbemClassObject
*iter
;
829 len
+= strlenW( class ) + strlenW( method
);
830 if (!(query
= heap_alloc( len
* sizeof(WCHAR
) ))) return E_OUTOFMEMORY
;
831 sprintfW( query
, selectW
, class, method
, dir
>= 0 ? geW
: leW
);
833 hr
= exec_query( query
, &iter
);
835 if (hr
!= S_OK
) return hr
;
837 if (!(name
= build_signature_table_name( class, method
, dir
)))
839 IEnumWbemClassObject_Release( iter
);
840 return E_OUTOFMEMORY
;
842 hr
= create_signature_table( iter
, name
);
843 IEnumWbemClassObject_Release( iter
);
845 hr
= get_object( name
, sig
);
851 static HRESULT WINAPI
class_object_GetMethod(
852 IWbemClassObject
*iface
,
855 IWbemClassObject
**ppInSignature
,
856 IWbemClassObject
**ppOutSignature
)
858 struct class_object
*co
= impl_from_IWbemClassObject( iface
);
859 IWbemClassObject
*in
, *out
;
862 TRACE("%p, %s, %08x, %p, %p\n", iface
, debugstr_w(wszName
), lFlags
, ppInSignature
, ppOutSignature
);
864 hr
= create_signature( co
->name
, wszName
, PARAM_IN
, &in
);
865 if (hr
!= S_OK
) return hr
;
867 hr
= create_signature( co
->name
, wszName
, PARAM_OUT
, &out
);
870 if (ppInSignature
) *ppInSignature
= in
;
871 else IWbemClassObject_Release( in
);
872 if (ppOutSignature
) *ppOutSignature
= out
;
873 else IWbemClassObject_Release( out
);
875 else IWbemClassObject_Release( in
);
879 static HRESULT WINAPI
class_object_PutMethod(
880 IWbemClassObject
*iface
,
883 IWbemClassObject
*pInSignature
,
884 IWbemClassObject
*pOutSignature
)
886 FIXME("%p, %s, %08x, %p, %p\n", iface
, debugstr_w(wszName
), lFlags
, pInSignature
, pOutSignature
);
890 static HRESULT WINAPI
class_object_DeleteMethod(
891 IWbemClassObject
*iface
,
894 FIXME("%p, %s\n", iface
, debugstr_w(wszName
));
898 static HRESULT WINAPI
class_object_BeginMethodEnumeration(
899 IWbemClassObject
*iface
,
902 struct class_object
*co
= impl_from_IWbemClassObject( iface
);
904 TRACE("%p, %08x\n", iface
, lEnumFlags
);
906 if (lEnumFlags
) FIXME("flags 0x%08x not supported\n", lEnumFlags
);
910 WARN("not allowed on instance\n");
911 return WBEM_E_ILLEGAL_OPERATION
;
913 co
->index_method
= 0;
917 static HRESULT WINAPI
class_object_NextMethod(
918 IWbemClassObject
*iface
,
921 IWbemClassObject
**ppInSignature
,
922 IWbemClassObject
**ppOutSignature
)
924 struct class_object
*co
= impl_from_IWbemClassObject( iface
);
928 TRACE("%p, %08x, %p, %p, %p\n", iface
, lFlags
, pstrName
, ppInSignature
, ppOutSignature
);
930 if (!(method
= get_method_name( co
->name
, co
->index_method
))) return WBEM_S_NO_MORE_DATA
;
932 hr
= create_signature( co
->name
, method
, PARAM_IN
, ppInSignature
);
935 SysFreeString( method
);
938 hr
= create_signature( co
->name
, method
, PARAM_OUT
, ppOutSignature
);
941 SysFreeString( method
);
942 IWbemClassObject_Release( *ppInSignature
);
952 static HRESULT WINAPI
class_object_EndMethodEnumeration(
953 IWbemClassObject
*iface
)
955 struct class_object
*co
= impl_from_IWbemClassObject( iface
);
957 TRACE("%p\n", iface
);
959 co
->index_method
= 0;
963 static HRESULT WINAPI
class_object_GetMethodQualifierSet(
964 IWbemClassObject
*iface
,
966 IWbemQualifierSet
**ppQualSet
)
968 FIXME("%p, %s, %p\n", iface
, debugstr_w(wszMethod
), ppQualSet
);
972 static HRESULT WINAPI
class_object_GetMethodOrigin(
973 IWbemClassObject
*iface
,
974 LPCWSTR wszMethodName
,
977 FIXME("%p, %s, %p\n", iface
, debugstr_w(wszMethodName
), pstrClassName
);
981 static const IWbemClassObjectVtbl class_object_vtbl
=
983 class_object_QueryInterface
,
985 class_object_Release
,
986 class_object_GetQualifierSet
,
990 class_object_GetNames
,
991 class_object_BeginEnumeration
,
993 class_object_EndEnumeration
,
994 class_object_GetPropertyQualifierSet
,
996 class_object_GetObjectText
,
997 class_object_SpawnDerivedClass
,
998 class_object_SpawnInstance
,
999 class_object_CompareTo
,
1000 class_object_GetPropertyOrigin
,
1001 class_object_InheritsFrom
,
1002 class_object_GetMethod
,
1003 class_object_PutMethod
,
1004 class_object_DeleteMethod
,
1005 class_object_BeginMethodEnumeration
,
1006 class_object_NextMethod
,
1007 class_object_EndMethodEnumeration
,
1008 class_object_GetMethodQualifierSet
,
1009 class_object_GetMethodOrigin
1012 HRESULT
create_class_object( const WCHAR
*name
, IEnumWbemClassObject
*iter
, UINT index
,
1013 struct record
*record
, IWbemClassObject
**obj
)
1015 struct class_object
*co
;
1017 TRACE("%s, %p\n", debugstr_w(name
), obj
);
1019 co
= heap_alloc( sizeof(*co
) );
1020 if (!co
) return E_OUTOFMEMORY
;
1022 co
->IWbemClassObject_iface
.lpVtbl
= &class_object_vtbl
;
1024 if (!name
) co
->name
= NULL
;
1025 else if (!(co
->name
= heap_strdupW( name
)))
1028 return E_OUTOFMEMORY
;
1032 co
->index_method
= 0;
1033 co
->index_property
= 0;
1034 co
->record
= record
;
1035 if (iter
) IEnumWbemClassObject_AddRef( iter
);
1037 *obj
= &co
->IWbemClassObject_iface
;
1039 TRACE("returning iface %p\n", *obj
);