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
28 #include "wine/debug.h"
29 #include "wbemprox_private.h"
31 WINE_DEFAULT_DEBUG_CHANNEL(wbemprox
);
33 struct enum_class_object
35 IEnumWbemClassObject IEnumWbemClassObject_iface
;
41 static inline struct enum_class_object
*impl_from_IEnumWbemClassObject(
42 IEnumWbemClassObject
*iface
)
44 return CONTAINING_RECORD(iface
, struct enum_class_object
, IEnumWbemClassObject_iface
);
47 static ULONG WINAPI
enum_class_object_AddRef(
48 IEnumWbemClassObject
*iface
)
50 struct enum_class_object
*ec
= impl_from_IEnumWbemClassObject( iface
);
51 return InterlockedIncrement( &ec
->refs
);
54 static ULONG WINAPI
enum_class_object_Release(
55 IEnumWbemClassObject
*iface
)
57 struct enum_class_object
*ec
= impl_from_IEnumWbemClassObject( iface
);
58 LONG refs
= InterlockedDecrement( &ec
->refs
);
61 TRACE("destroying %p\n", ec
);
62 release_query( ec
->query
);
68 static HRESULT WINAPI
enum_class_object_QueryInterface(
69 IEnumWbemClassObject
*iface
,
73 struct enum_class_object
*ec
= impl_from_IEnumWbemClassObject( iface
);
75 TRACE("%p, %s, %p\n", ec
, debugstr_guid( riid
), ppvObject
);
77 if ( IsEqualGUID( riid
, &IID_IEnumWbemClassObject
) ||
78 IsEqualGUID( riid
, &IID_IUnknown
) )
82 else if ( IsEqualGUID( riid
, &IID_IClientSecurity
) )
84 *ppvObject
= &client_security
;
89 FIXME("interface %s not implemented\n", debugstr_guid(riid
));
92 IEnumWbemClassObject_AddRef( iface
);
96 static HRESULT WINAPI
enum_class_object_Reset(
97 IEnumWbemClassObject
*iface
)
99 struct enum_class_object
*ec
= impl_from_IEnumWbemClassObject( iface
);
101 TRACE("%p\n", iface
);
104 return WBEM_S_NO_ERROR
;
107 static HRESULT WINAPI
enum_class_object_Next(
108 IEnumWbemClassObject
*iface
,
111 IWbemClassObject
**apObjects
,
114 struct enum_class_object
*ec
= impl_from_IEnumWbemClassObject( iface
);
115 struct view
*view
= ec
->query
->view
;
120 TRACE("%p, %d, %u, %p, %p\n", iface
, lTimeout
, uCount
, apObjects
, puReturned
);
122 if (!uCount
) return WBEM_S_FALSE
;
123 if (!apObjects
|| !puReturned
) return WBEM_E_INVALID_PARAMETER
;
124 if (lTimeout
!= WBEM_INFINITE
&& !once
++) FIXME("timeout not supported\n");
127 if (ec
->index
>= view
->result_count
) return WBEM_S_FALSE
;
129 table
= get_view_table( view
, ec
->index
);
130 hr
= create_class_object( table
->name
, iface
, ec
->index
, NULL
, apObjects
);
131 if (hr
!= S_OK
) return hr
;
135 if (ec
->index
== view
->result_count
&& uCount
> 1) return WBEM_S_FALSE
;
136 if (uCount
> 1) return WBEM_S_TIMEDOUT
;
137 return WBEM_S_NO_ERROR
;
140 static HRESULT WINAPI
enum_class_object_NextAsync(
141 IEnumWbemClassObject
*iface
,
143 IWbemObjectSink
*pSink
)
145 FIXME("%p, %u, %p\n", iface
, uCount
, pSink
);
149 static HRESULT WINAPI
enum_class_object_Clone(
150 IEnumWbemClassObject
*iface
,
151 IEnumWbemClassObject
**ppEnum
)
153 struct enum_class_object
*ec
= impl_from_IEnumWbemClassObject( iface
);
155 TRACE("%p, %p\n", iface
, ppEnum
);
157 return EnumWbemClassObject_create( ec
->query
, (void **)ppEnum
);
160 static HRESULT WINAPI
enum_class_object_Skip(
161 IEnumWbemClassObject
*iface
,
165 struct enum_class_object
*ec
= impl_from_IEnumWbemClassObject( iface
);
166 struct view
*view
= ec
->query
->view
;
169 TRACE("%p, %d, %u\n", iface
, lTimeout
, nCount
);
171 if (lTimeout
!= WBEM_INFINITE
&& !once
++) FIXME("timeout not supported\n");
173 if (!view
->result_count
) return WBEM_S_FALSE
;
175 if (nCount
> view
->result_count
- ec
->index
)
177 ec
->index
= view
->result_count
- 1;
181 return WBEM_S_NO_ERROR
;
184 static const IEnumWbemClassObjectVtbl enum_class_object_vtbl
=
186 enum_class_object_QueryInterface
,
187 enum_class_object_AddRef
,
188 enum_class_object_Release
,
189 enum_class_object_Reset
,
190 enum_class_object_Next
,
191 enum_class_object_NextAsync
,
192 enum_class_object_Clone
,
193 enum_class_object_Skip
196 HRESULT
EnumWbemClassObject_create( struct query
*query
, LPVOID
*ppObj
)
198 struct enum_class_object
*ec
;
200 TRACE("%p\n", ppObj
);
202 ec
= heap_alloc( sizeof(*ec
) );
203 if (!ec
) return E_OUTOFMEMORY
;
205 ec
->IEnumWbemClassObject_iface
.lpVtbl
= &enum_class_object_vtbl
;
207 ec
->query
= addref_query( query
);
210 *ppObj
= &ec
->IEnumWbemClassObject_iface
;
212 TRACE("returning iface %p\n", *ppObj
);
216 static struct record
*create_record( struct table
*table
)
219 struct record
*record
;
221 if (!(record
= heap_alloc( sizeof(struct record
) ))) return NULL
;
222 if (!(record
->fields
= heap_alloc( table
->num_cols
* sizeof(struct field
) )))
227 for (i
= 0; i
< table
->num_cols
; i
++)
229 record
->fields
[i
].type
= table
->columns
[i
].type
;
230 record
->fields
[i
].u
.ival
= 0;
232 record
->count
= table
->num_cols
;
233 record
->table
= addref_table( table
);
237 void destroy_array( struct array
*array
, CIMTYPE type
)
241 if (type
== CIM_STRING
|| type
== CIM_DATETIME
|| type
== CIM_REFERENCE
)
243 for (i
= 0; i
< array
->count
; i
++) heap_free( *(WCHAR
**)((char *)array
->ptr
+ i
* array
->elem_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
||
258 record
->fields
[i
].type
== CIM_DATETIME
||
259 record
->fields
[i
].type
== CIM_REFERENCE
) heap_free( record
->fields
[i
].u
.sval
);
260 else if (record
->fields
[i
].type
& CIM_FLAG_ARRAY
)
261 destroy_array( record
->fields
[i
].u
.aval
, record
->fields
[i
].type
& CIM_TYPE_MASK
);
263 heap_free( record
->fields
);
269 IWbemClassObject IWbemClassObject_iface
;
272 IEnumWbemClassObject
*iter
;
276 struct record
*record
; /* uncommitted instance */
279 static inline struct class_object
*impl_from_IWbemClassObject(
280 IWbemClassObject
*iface
)
282 return CONTAINING_RECORD(iface
, struct class_object
, IWbemClassObject_iface
);
285 static ULONG WINAPI
class_object_AddRef(
286 IWbemClassObject
*iface
)
288 struct class_object
*co
= impl_from_IWbemClassObject( iface
);
289 return InterlockedIncrement( &co
->refs
);
292 static ULONG WINAPI
class_object_Release(
293 IWbemClassObject
*iface
)
295 struct class_object
*co
= impl_from_IWbemClassObject( iface
);
296 LONG refs
= InterlockedDecrement( &co
->refs
);
299 TRACE("destroying %p\n", co
);
300 if (co
->iter
) IEnumWbemClassObject_Release( co
->iter
);
301 destroy_record( co
->record
);
302 heap_free( co
->name
);
308 static HRESULT WINAPI
class_object_QueryInterface(
309 IWbemClassObject
*iface
,
313 struct class_object
*co
= impl_from_IWbemClassObject( iface
);
315 TRACE("%p, %s, %p\n", co
, debugstr_guid( riid
), ppvObject
);
317 if ( IsEqualGUID( riid
, &IID_IWbemClassObject
) ||
318 IsEqualGUID( riid
, &IID_IUnknown
) )
322 else if (IsEqualGUID( riid
, &IID_IClientSecurity
))
324 *ppvObject
= &client_security
;
329 FIXME("interface %s not implemented\n", debugstr_guid(riid
));
330 return E_NOINTERFACE
;
332 IWbemClassObject_AddRef( iface
);
336 static HRESULT WINAPI
class_object_GetQualifierSet(
337 IWbemClassObject
*iface
,
338 IWbemQualifierSet
**ppQualSet
)
340 struct class_object
*co
= impl_from_IWbemClassObject( iface
);
342 TRACE("%p, %p\n", iface
, ppQualSet
);
344 return WbemQualifierSet_create( co
->name
, NULL
, (void **)ppQualSet
);
347 static HRESULT
record_get_value( const struct record
*record
, UINT index
, VARIANT
*var
, CIMTYPE
*type
)
349 VARTYPE vartype
= to_vartype( record
->fields
[index
].type
& CIM_TYPE_MASK
);
351 if (type
) *type
= record
->fields
[index
].type
;
353 if (record
->fields
[index
].type
& CIM_FLAG_ARRAY
)
355 V_VT( var
) = vartype
| VT_ARRAY
;
356 V_ARRAY( var
) = to_safearray( record
->fields
[index
].u
.aval
, record
->fields
[index
].type
& CIM_TYPE_MASK
);
359 switch (record
->fields
[index
].type
)
364 V_BSTR( var
) = SysAllocString( record
->fields
[index
].u
.sval
);
367 V_I4( var
) = record
->fields
[index
].u
.ival
;
370 V_UI4( var
) = record
->fields
[index
].u
.ival
;
373 FIXME("unhandled type %u\n", record
->fields
[index
].type
);
374 return WBEM_E_INVALID_PARAMETER
;
376 V_VT( var
) = vartype
;
380 static HRESULT WINAPI
class_object_Get(
381 IWbemClassObject
*iface
,
388 struct class_object
*co
= impl_from_IWbemClassObject( iface
);
389 struct enum_class_object
*ec
= impl_from_IEnumWbemClassObject( co
->iter
);
391 TRACE("%p, %s, %08x, %p, %p, %p\n", iface
, debugstr_w(wszName
), lFlags
, pVal
, pType
, plFlavor
);
398 if ((hr
= get_column_index( co
->record
->table
, wszName
, &index
)) != S_OK
) return hr
;
399 return record_get_value( co
->record
, index
, pVal
, pType
);
401 return get_propval( ec
->query
->view
, co
->index
, wszName
, pVal
, pType
, plFlavor
);
404 static HRESULT
record_set_value( struct record
*record
, UINT index
, VARIANT
*var
)
410 if ((hr
= to_longlong( var
, &val
, &type
)) != S_OK
) return hr
;
411 if (type
!= record
->fields
[index
].type
) return WBEM_E_TYPE_MISMATCH
;
413 if (type
& CIM_FLAG_ARRAY
)
415 record
->fields
[index
].u
.aval
= (struct array
*)(INT_PTR
)val
;
423 record
->fields
[index
].u
.sval
= (WCHAR
*)(INT_PTR
)val
;
429 record
->fields
[index
].u
.ival
= val
;
432 FIXME("unhandled type %u\n", type
);
435 return WBEM_E_INVALID_PARAMETER
;
438 static HRESULT WINAPI
class_object_Put(
439 IWbemClassObject
*iface
,
445 struct class_object
*co
= impl_from_IWbemClassObject( iface
);
446 struct enum_class_object
*ec
= impl_from_IEnumWbemClassObject( co
->iter
);
448 TRACE("%p, %s, %08x, %p, %u\n", iface
, debugstr_w(wszName
), lFlags
, pVal
, Type
);
455 if ((hr
= get_column_index( co
->record
->table
, wszName
, &index
)) != S_OK
) return hr
;
456 return record_set_value( co
->record
, index
, pVal
);
458 return put_propval( ec
->query
->view
, co
->index
, wszName
, pVal
, Type
);
461 static HRESULT WINAPI
class_object_Delete(
462 IWbemClassObject
*iface
,
465 FIXME("%p, %s\n", iface
, debugstr_w(wszName
));
469 static HRESULT WINAPI
class_object_GetNames(
470 IWbemClassObject
*iface
,
471 LPCWSTR wszQualifierName
,
473 VARIANT
*pQualifierVal
,
476 struct class_object
*co
= impl_from_IWbemClassObject( iface
);
477 struct enum_class_object
*ec
= impl_from_IEnumWbemClassObject( co
->iter
);
479 TRACE("%p, %s, %08x, %s, %p\n", iface
, debugstr_w(wszQualifierName
), lFlags
,
480 debugstr_variant(pQualifierVal
), pNames
);
482 if (lFlags
!= WBEM_FLAG_ALWAYS
&&
483 lFlags
!= WBEM_FLAG_NONSYSTEM_ONLY
&&
484 lFlags
!= WBEM_FLAG_SYSTEM_ONLY
)
486 FIXME("flags %08x not supported\n", lFlags
);
489 if (wszQualifierName
|| pQualifierVal
)
490 FIXME("qualifier not supported\n");
492 return get_properties( ec
->query
->view
, co
->index
, lFlags
, pNames
);
495 static HRESULT WINAPI
class_object_BeginEnumeration(
496 IWbemClassObject
*iface
,
499 struct class_object
*co
= impl_from_IWbemClassObject( iface
);
501 TRACE("%p, %08x\n", iface
, lEnumFlags
);
503 if (lEnumFlags
) FIXME("flags 0x%08x not supported\n", lEnumFlags
);
505 co
->index_property
= 0;
509 static HRESULT WINAPI
class_object_Next(
510 IWbemClassObject
*iface
,
517 struct class_object
*obj
= impl_from_IWbemClassObject( iface
);
518 struct enum_class_object
*iter
= impl_from_IEnumWbemClassObject( obj
->iter
);
519 struct view
*view
= iter
->query
->view
;
520 struct table
*table
= get_view_table( view
, obj
->index
);
525 TRACE("%p, %08x, %p, %p, %p, %p\n", iface
, lFlags
, strName
, pVal
, pType
, plFlavor
);
527 for (i
= obj
->index_property
; i
< table
->num_cols
; i
++)
529 if (is_method( table
, i
)) continue;
530 if (!is_result_prop( view
, table
->columns
[i
].name
)) continue;
531 if (!(prop
= SysAllocString( table
->columns
[i
].name
))) return E_OUTOFMEMORY
;
532 if ((hr
= get_propval( view
, obj
->index
, prop
, pVal
, pType
, plFlavor
)) != S_OK
)
534 SysFreeString( prop
);
538 obj
->index_property
= i
+ 1;
539 if (strName
) *strName
= prop
;
540 else SysFreeString( prop
);
544 return WBEM_S_NO_MORE_DATA
;
547 static HRESULT WINAPI
class_object_EndEnumeration(
548 IWbemClassObject
*iface
)
550 struct class_object
*co
= impl_from_IWbemClassObject( iface
);
552 TRACE("%p\n", iface
);
554 co
->index_property
= 0;
558 static HRESULT WINAPI
class_object_GetPropertyQualifierSet(
559 IWbemClassObject
*iface
,
561 IWbemQualifierSet
**ppQualSet
)
563 struct class_object
*co
= impl_from_IWbemClassObject( iface
);
565 TRACE("%p, %s, %p\n", iface
, debugstr_w(wszProperty
), ppQualSet
);
567 return WbemQualifierSet_create( co
->name
, wszProperty
, (void **)ppQualSet
);
570 static HRESULT WINAPI
class_object_Clone(
571 IWbemClassObject
*iface
,
572 IWbemClassObject
**ppCopy
)
574 FIXME("%p, %p\n", iface
, ppCopy
);
578 static BSTR
get_body_text( const struct table
*table
, UINT row
, UINT
*len
)
580 static const WCHAR fmtW
[] = {'\n','\t','%','s',' ','=',' ','%','s',';',0};
586 for (i
= 0; i
< table
->num_cols
; i
++)
588 if ((value
= get_value_bstr( table
, row
, i
)))
590 *len
+= ARRAY_SIZE( fmtW
);
591 *len
+= lstrlenW( table
->columns
[i
].name
);
592 *len
+= SysStringLen( value
);
593 SysFreeString( value
);
596 if (!(ret
= SysAllocStringLen( NULL
, *len
))) return NULL
;
598 for (i
= 0; i
< table
->num_cols
; i
++)
600 if ((value
= get_value_bstr( table
, row
, i
)))
602 p
+= swprintf( p
, *len
- (p
- ret
), fmtW
, table
->columns
[i
].name
, value
);
603 SysFreeString( value
);
609 static BSTR
get_object_text( const struct view
*view
, UINT index
)
611 static const WCHAR fmtW
[] =
612 {'\n','i','n','s','t','a','n','c','e',' ','o','f',' ','%','s','\n','{','%','s','\n','}',';',0};
613 UINT len
, len_body
, row
= view
->result
[index
];
614 struct table
*table
= get_view_table( view
, index
);
617 len
= ARRAY_SIZE( fmtW
);
618 len
+= lstrlenW( table
->name
);
619 if (!(body
= get_body_text( table
, row
, &len_body
))) return NULL
;
622 if (!(ret
= SysAllocStringLen( NULL
, len
))) return NULL
;
623 swprintf( ret
, len
, fmtW
, table
->name
, body
);
624 SysFreeString( body
);
628 static HRESULT WINAPI
class_object_GetObjectText(
629 IWbemClassObject
*iface
,
631 BSTR
*pstrObjectText
)
633 struct class_object
*co
= impl_from_IWbemClassObject( iface
);
634 struct enum_class_object
*ec
= impl_from_IEnumWbemClassObject( co
->iter
);
635 struct view
*view
= ec
->query
->view
;
638 TRACE("%p, %08x, %p\n", iface
, lFlags
, pstrObjectText
);
640 if (lFlags
) FIXME("flags %08x not implemented\n", lFlags
);
642 if (!(text
= get_object_text( view
, co
->index
))) return E_OUTOFMEMORY
;
643 *pstrObjectText
= text
;
647 static HRESULT WINAPI
class_object_SpawnDerivedClass(
648 IWbemClassObject
*iface
,
650 IWbemClassObject
**ppNewClass
)
652 FIXME("%p, %08x, %p\n", iface
, lFlags
, ppNewClass
);
656 static HRESULT WINAPI
class_object_SpawnInstance(
657 IWbemClassObject
*iface
,
659 IWbemClassObject
**ppNewInstance
)
661 struct class_object
*co
= impl_from_IWbemClassObject( iface
);
662 struct enum_class_object
*ec
= impl_from_IEnumWbemClassObject( co
->iter
);
663 struct table
*table
= get_view_table( ec
->query
->view
, co
->index
);
664 struct record
*record
;
666 TRACE("%p, %08x, %p\n", iface
, lFlags
, ppNewInstance
);
668 if (!(record
= create_record( table
))) return E_OUTOFMEMORY
;
670 return create_class_object( co
->name
, NULL
, 0, record
, ppNewInstance
);
673 static HRESULT WINAPI
class_object_CompareTo(
674 IWbemClassObject
*iface
,
676 IWbemClassObject
*pCompareTo
)
678 FIXME("%p, %08x, %p\n", iface
, lFlags
, pCompareTo
);
682 static HRESULT WINAPI
class_object_GetPropertyOrigin(
683 IWbemClassObject
*iface
,
685 BSTR
*pstrClassName
)
687 FIXME("%p, %s, %p\n", iface
, debugstr_w(wszName
), pstrClassName
);
691 static HRESULT WINAPI
class_object_InheritsFrom(
692 IWbemClassObject
*iface
,
693 LPCWSTR strAncestor
)
695 FIXME("%p, %s\n", iface
, debugstr_w(strAncestor
));
699 static UINT
count_instances( IEnumWbemClassObject
*iter
)
702 while (!IEnumWbemClassObject_Skip( iter
, WBEM_INFINITE
, 1 )) count
++;
703 IEnumWbemClassObject_Reset( iter
);
707 static void set_default_value( CIMTYPE type
, UINT val
, BYTE
*ptr
)
715 *(UINT16
*)ptr
= val
;
721 *(UINT32
*)ptr
= val
;
724 FIXME("unhandled type %u\n", type
);
729 static HRESULT
create_signature_columns_and_data( IEnumWbemClassObject
*iter
, UINT
*num_cols
,
730 struct column
**cols
, BYTE
**data
)
732 static const WCHAR parameterW
[] = {'P','a','r','a','m','e','t','e','r',0};
733 static const WCHAR typeW
[] = {'T','y','p','e',0};
734 static const WCHAR defaultvalueW
[] = {'D','e','f','a','u','l','t','V','a','l','u','e',0};
735 struct column
*columns
;
737 IWbemClassObject
*param
;
739 HRESULT hr
= E_OUTOFMEMORY
;
744 count
= count_instances( iter
);
745 if (!(columns
= heap_alloc( count
* sizeof(struct column
) ))) return E_OUTOFMEMORY
;
746 if (!(row
= heap_alloc_zero( count
* sizeof(LONGLONG
) ))) goto error
;
750 IEnumWbemClassObject_Next( iter
, WBEM_INFINITE
, 1, ¶m
, &count
);
753 hr
= IWbemClassObject_Get( param
, parameterW
, 0, &val
, NULL
, NULL
);
754 if (hr
!= S_OK
) goto error
;
755 columns
[i
].name
= heap_strdupW( V_BSTR( &val
) );
756 VariantClear( &val
);
758 hr
= IWbemClassObject_Get( param
, typeW
, 0, &val
, NULL
, NULL
);
759 if (hr
!= S_OK
) goto error
;
760 columns
[i
].type
= V_UI4( &val
);
762 hr
= IWbemClassObject_Get( param
, defaultvalueW
, 0, &val
, NULL
, NULL
);
763 if (hr
!= S_OK
) goto error
;
764 if (V_UI4( &val
)) set_default_value( columns
[i
].type
, V_UI4( &val
), row
+ offset
);
765 offset
+= get_type_size( columns
[i
].type
);
767 IWbemClassObject_Release( param
);
776 for (; i
>= 0; i
--) heap_free( (WCHAR
*)columns
[i
].name
);
777 heap_free( columns
);
782 static HRESULT
create_signature_table( IEnumWbemClassObject
*iter
, WCHAR
*name
)
786 struct column
*columns
;
790 hr
= create_signature_columns_and_data( iter
, &num_cols
, &columns
, &row
);
791 if (hr
!= S_OK
) return hr
;
793 if (!(table
= create_table( name
, num_cols
, columns
, 1, 1, row
, NULL
)))
795 free_columns( columns
, num_cols
);
797 return E_OUTOFMEMORY
;
799 if (!add_table( table
)) free_table( table
); /* already exists */
803 static WCHAR
*build_signature_table_name( const WCHAR
*class, const WCHAR
*method
, enum param_direction dir
)
805 static const WCHAR fmtW
[] = {'_','_','%','s','_','%','s','_','%','s',0};
806 static const WCHAR outW
[] = {'O','U','T',0};
807 static const WCHAR inW
[] = {'I','N',0};
808 UINT len
= ARRAY_SIZE(fmtW
) + ARRAY_SIZE(outW
) + lstrlenW( class ) + lstrlenW( method
);
811 if (!(ret
= heap_alloc( len
* sizeof(WCHAR
) ))) return NULL
;
812 swprintf( ret
, len
, fmtW
, class, method
, dir
== PARAM_IN
? inW
: outW
);
813 return wcsupr( ret
);
816 HRESULT
create_signature( const WCHAR
*class, const WCHAR
*method
, enum param_direction dir
,
817 IWbemClassObject
**sig
)
819 static const WCHAR selectW
[] =
820 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
821 '_','_','P','A','R','A','M','E','T','E','R','S',' ','W','H','E','R','E',' ',
822 'C','l','a','s','s','=','\'','%','s','\'',' ','A','N','D',' ',
823 'M','e','t','h','o','d','=','\'','%','s','\'',' ','A','N','D',' ',
824 'D','i','r','e','c','t','i','o','n','%','s',0};
825 static const WCHAR geW
[] = {'>','=','0',0};
826 static const WCHAR leW
[] = {'<','=','0',0};
827 UINT len
= ARRAY_SIZE(selectW
) + ARRAY_SIZE(geW
);
828 IEnumWbemClassObject
*iter
;
832 len
+= lstrlenW( class ) + lstrlenW( method
);
833 if (!(query
= heap_alloc( len
* sizeof(WCHAR
) ))) return E_OUTOFMEMORY
;
834 swprintf( query
, len
, selectW
, class, method
, dir
>= 0 ? geW
: leW
);
836 hr
= exec_query( query
, &iter
);
838 if (hr
!= S_OK
) return hr
;
840 if (!count_instances( iter
))
843 IEnumWbemClassObject_Release( iter
);
847 if (!(name
= build_signature_table_name( class, method
, dir
)))
849 IEnumWbemClassObject_Release( iter
);
850 return E_OUTOFMEMORY
;
852 hr
= create_signature_table( iter
, name
);
853 IEnumWbemClassObject_Release( iter
);
855 hr
= get_object( name
, sig
);
861 static HRESULT WINAPI
class_object_GetMethod(
862 IWbemClassObject
*iface
,
865 IWbemClassObject
**ppInSignature
,
866 IWbemClassObject
**ppOutSignature
)
868 struct class_object
*co
= impl_from_IWbemClassObject( iface
);
869 IWbemClassObject
*in
, *out
;
872 TRACE("%p, %s, %08x, %p, %p\n", iface
, debugstr_w(wszName
), lFlags
, ppInSignature
, ppOutSignature
);
874 hr
= create_signature( co
->name
, wszName
, PARAM_IN
, &in
);
875 if (hr
!= S_OK
) return hr
;
877 hr
= create_signature( co
->name
, wszName
, PARAM_OUT
, &out
);
880 if (ppInSignature
) *ppInSignature
= in
;
881 else if (in
) IWbemClassObject_Release( in
);
882 if (ppOutSignature
) *ppOutSignature
= out
;
883 else if (out
) IWbemClassObject_Release( out
);
885 else IWbemClassObject_Release( in
);
889 static HRESULT WINAPI
class_object_PutMethod(
890 IWbemClassObject
*iface
,
893 IWbemClassObject
*pInSignature
,
894 IWbemClassObject
*pOutSignature
)
896 FIXME("%p, %s, %08x, %p, %p\n", iface
, debugstr_w(wszName
), lFlags
, pInSignature
, pOutSignature
);
900 static HRESULT WINAPI
class_object_DeleteMethod(
901 IWbemClassObject
*iface
,
904 FIXME("%p, %s\n", iface
, debugstr_w(wszName
));
908 static HRESULT WINAPI
class_object_BeginMethodEnumeration(
909 IWbemClassObject
*iface
,
912 struct class_object
*co
= impl_from_IWbemClassObject( iface
);
914 TRACE("%p, %08x\n", iface
, lEnumFlags
);
916 if (lEnumFlags
) FIXME("flags 0x%08x not supported\n", lEnumFlags
);
918 co
->index_method
= 0;
922 static HRESULT WINAPI
class_object_NextMethod(
923 IWbemClassObject
*iface
,
926 IWbemClassObject
**ppInSignature
,
927 IWbemClassObject
**ppOutSignature
)
929 struct class_object
*co
= impl_from_IWbemClassObject( iface
);
933 TRACE("%p, %08x, %p, %p, %p\n", iface
, lFlags
, pstrName
, ppInSignature
, ppOutSignature
);
935 if (!(method
= get_method_name( co
->name
, co
->index_method
))) return WBEM_S_NO_MORE_DATA
;
937 hr
= create_signature( co
->name
, method
, PARAM_IN
, ppInSignature
);
940 SysFreeString( method
);
943 hr
= create_signature( co
->name
, method
, PARAM_OUT
, ppOutSignature
);
946 SysFreeString( method
);
948 IWbemClassObject_Release( *ppInSignature
);
958 static HRESULT WINAPI
class_object_EndMethodEnumeration(
959 IWbemClassObject
*iface
)
961 struct class_object
*co
= impl_from_IWbemClassObject( iface
);
963 TRACE("%p\n", iface
);
965 co
->index_method
= 0;
969 static HRESULT WINAPI
class_object_GetMethodQualifierSet(
970 IWbemClassObject
*iface
,
972 IWbemQualifierSet
**ppQualSet
)
974 FIXME("%p, %s, %p\n", iface
, debugstr_w(wszMethod
), ppQualSet
);
978 static HRESULT WINAPI
class_object_GetMethodOrigin(
979 IWbemClassObject
*iface
,
980 LPCWSTR wszMethodName
,
983 FIXME("%p, %s, %p\n", iface
, debugstr_w(wszMethodName
), pstrClassName
);
987 static const IWbemClassObjectVtbl class_object_vtbl
=
989 class_object_QueryInterface
,
991 class_object_Release
,
992 class_object_GetQualifierSet
,
996 class_object_GetNames
,
997 class_object_BeginEnumeration
,
999 class_object_EndEnumeration
,
1000 class_object_GetPropertyQualifierSet
,
1002 class_object_GetObjectText
,
1003 class_object_SpawnDerivedClass
,
1004 class_object_SpawnInstance
,
1005 class_object_CompareTo
,
1006 class_object_GetPropertyOrigin
,
1007 class_object_InheritsFrom
,
1008 class_object_GetMethod
,
1009 class_object_PutMethod
,
1010 class_object_DeleteMethod
,
1011 class_object_BeginMethodEnumeration
,
1012 class_object_NextMethod
,
1013 class_object_EndMethodEnumeration
,
1014 class_object_GetMethodQualifierSet
,
1015 class_object_GetMethodOrigin
1018 HRESULT
create_class_object( const WCHAR
*name
, IEnumWbemClassObject
*iter
, UINT index
,
1019 struct record
*record
, IWbemClassObject
**obj
)
1021 struct class_object
*co
;
1023 TRACE("%s, %p\n", debugstr_w(name
), obj
);
1025 co
= heap_alloc( sizeof(*co
) );
1026 if (!co
) return E_OUTOFMEMORY
;
1028 co
->IWbemClassObject_iface
.lpVtbl
= &class_object_vtbl
;
1030 if (!name
) co
->name
= NULL
;
1031 else if (!(co
->name
= heap_strdupW( name
)))
1034 return E_OUTOFMEMORY
;
1038 co
->index_method
= 0;
1039 co
->index_property
= 0;
1040 co
->record
= record
;
1041 if (iter
) IEnumWbemClassObject_AddRef( iter
);
1043 *obj
= &co
->IWbemClassObject_iface
;
1045 TRACE("returning iface %p\n", *obj
);