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
;
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
->count
) return WBEM_S_FALSE
;
129 hr
= create_class_object( view
->table
->name
, iface
, ec
->index
, NULL
, apObjects
);
130 if (hr
!= S_OK
) return hr
;
134 if (ec
->index
== view
->count
&& uCount
> 1) return WBEM_S_FALSE
;
135 if (uCount
> 1) return WBEM_S_TIMEDOUT
;
136 return WBEM_S_NO_ERROR
;
139 static HRESULT WINAPI
enum_class_object_NextAsync(
140 IEnumWbemClassObject
*iface
,
142 IWbemObjectSink
*pSink
)
144 FIXME("%p, %u, %p\n", iface
, uCount
, pSink
);
148 static HRESULT WINAPI
enum_class_object_Clone(
149 IEnumWbemClassObject
*iface
,
150 IEnumWbemClassObject
**ppEnum
)
152 struct enum_class_object
*ec
= impl_from_IEnumWbemClassObject( iface
);
154 TRACE("%p, %p\n", iface
, ppEnum
);
156 return EnumWbemClassObject_create( ec
->query
, (void **)ppEnum
);
159 static HRESULT WINAPI
enum_class_object_Skip(
160 IEnumWbemClassObject
*iface
,
164 struct enum_class_object
*ec
= impl_from_IEnumWbemClassObject( iface
);
165 struct view
*view
= ec
->query
->view
;
168 TRACE("%p, %d, %u\n", iface
, lTimeout
, nCount
);
170 if (lTimeout
!= WBEM_INFINITE
&& !once
++) FIXME("timeout not supported\n");
172 if (!view
->count
) return WBEM_S_FALSE
;
174 if (nCount
> view
->count
- ec
->index
)
176 ec
->index
= view
->count
- 1;
180 return WBEM_S_NO_ERROR
;
183 static const IEnumWbemClassObjectVtbl enum_class_object_vtbl
=
185 enum_class_object_QueryInterface
,
186 enum_class_object_AddRef
,
187 enum_class_object_Release
,
188 enum_class_object_Reset
,
189 enum_class_object_Next
,
190 enum_class_object_NextAsync
,
191 enum_class_object_Clone
,
192 enum_class_object_Skip
195 HRESULT
EnumWbemClassObject_create( struct query
*query
, LPVOID
*ppObj
)
197 struct enum_class_object
*ec
;
199 TRACE("%p\n", ppObj
);
201 ec
= heap_alloc( sizeof(*ec
) );
202 if (!ec
) return E_OUTOFMEMORY
;
204 ec
->IEnumWbemClassObject_iface
.lpVtbl
= &enum_class_object_vtbl
;
206 ec
->query
= addref_query( query
);
209 *ppObj
= &ec
->IEnumWbemClassObject_iface
;
211 TRACE("returning iface %p\n", *ppObj
);
215 static struct record
*create_record( struct table
*table
)
218 struct record
*record
;
220 if (!(record
= heap_alloc( sizeof(struct record
) ))) return NULL
;
221 if (!(record
->fields
= heap_alloc( table
->num_cols
* sizeof(struct field
) )))
226 for (i
= 0; i
< table
->num_cols
; i
++)
228 record
->fields
[i
].type
= table
->columns
[i
].type
;
229 record
->fields
[i
].vartype
= table
->columns
[i
].vartype
;
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
)
242 if (type
== CIM_STRING
|| type
== CIM_DATETIME
)
244 size
= get_type_size( type
);
245 for (i
= 0; i
< array
->count
; i
++) heap_free( *(WCHAR
**)((char *)array
->ptr
+ i
* size
) );
247 heap_free( array
->ptr
);
251 static void destroy_record( struct record
*record
)
256 release_table( record
->table
);
257 for (i
= 0; i
< record
->count
; i
++)
259 if (record
->fields
[i
].type
== CIM_STRING
|| record
->fields
[i
].type
== CIM_DATETIME
)
260 heap_free( record
->fields
[i
].u
.sval
);
261 else if (record
->fields
[i
].type
& CIM_FLAG_ARRAY
)
262 destroy_array( record
->fields
[i
].u
.aval
, record
->fields
[i
].type
& CIM_TYPE_MASK
);
264 heap_free( record
->fields
);
270 IWbemClassObject IWbemClassObject_iface
;
273 IEnumWbemClassObject
*iter
;
277 struct record
*record
; /* uncommitted instance */
280 static inline struct class_object
*impl_from_IWbemClassObject(
281 IWbemClassObject
*iface
)
283 return CONTAINING_RECORD(iface
, struct class_object
, IWbemClassObject_iface
);
286 static ULONG WINAPI
class_object_AddRef(
287 IWbemClassObject
*iface
)
289 struct class_object
*co
= impl_from_IWbemClassObject( iface
);
290 return InterlockedIncrement( &co
->refs
);
293 static ULONG WINAPI
class_object_Release(
294 IWbemClassObject
*iface
)
296 struct class_object
*co
= impl_from_IWbemClassObject( iface
);
297 LONG refs
= InterlockedDecrement( &co
->refs
);
300 TRACE("destroying %p\n", co
);
301 if (co
->iter
) IEnumWbemClassObject_Release( co
->iter
);
302 destroy_record( co
->record
);
303 heap_free( co
->name
);
309 static HRESULT WINAPI
class_object_QueryInterface(
310 IWbemClassObject
*iface
,
314 struct class_object
*co
= impl_from_IWbemClassObject( iface
);
316 TRACE("%p, %s, %p\n", co
, debugstr_guid( riid
), ppvObject
);
318 if ( IsEqualGUID( riid
, &IID_IWbemClassObject
) ||
319 IsEqualGUID( riid
, &IID_IUnknown
) )
323 else if (IsEqualGUID( riid
, &IID_IClientSecurity
))
325 *ppvObject
= &client_security
;
330 FIXME("interface %s not implemented\n", debugstr_guid(riid
));
331 return E_NOINTERFACE
;
333 IWbemClassObject_AddRef( iface
);
337 static HRESULT WINAPI
class_object_GetQualifierSet(
338 IWbemClassObject
*iface
,
339 IWbemQualifierSet
**ppQualSet
)
341 FIXME("%p, %p\n", iface
, ppQualSet
);
345 static HRESULT
record_get_value( const struct record
*record
, UINT index
, VARIANT
*var
, CIMTYPE
*type
)
347 VARTYPE vartype
= record
->fields
[index
].vartype
;
349 if (type
) *type
= record
->fields
[index
].type
;
351 if (record
->fields
[index
].type
& CIM_FLAG_ARRAY
)
353 V_VT( var
) = vartype
? vartype
: to_vartype( record
->fields
[index
].type
& CIM_TYPE_MASK
) | VT_ARRAY
;
354 V_ARRAY( var
) = to_safearray( record
->fields
[index
].u
.aval
, record
->fields
[index
].type
& CIM_TYPE_MASK
);
357 switch (record
->fields
[index
].type
)
361 if (!vartype
) vartype
= VT_BSTR
;
362 V_BSTR( var
) = SysAllocString( record
->fields
[index
].u
.sval
);
365 if (!vartype
) vartype
= VT_I4
;
366 V_I4( var
) = record
->fields
[index
].u
.ival
;
369 if (!vartype
) vartype
= VT_UI4
;
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
;
422 record
->fields
[index
].u
.sval
= (WCHAR
*)(INT_PTR
)val
;
428 record
->fields
[index
].u
.ival
= val
;
431 FIXME("unhandled type %u\n", type
);
434 return WBEM_E_INVALID_PARAMETER
;
437 static HRESULT WINAPI
class_object_Put(
438 IWbemClassObject
*iface
,
444 struct class_object
*co
= impl_from_IWbemClassObject( iface
);
445 struct enum_class_object
*ec
= impl_from_IEnumWbemClassObject( co
->iter
);
447 TRACE("%p, %s, %08x, %p, %u\n", iface
, debugstr_w(wszName
), lFlags
, pVal
, Type
);
454 if ((hr
= get_column_index( co
->record
->table
, wszName
, &index
)) != S_OK
) return hr
;
455 return record_set_value( co
->record
, index
, pVal
);
457 return put_propval( ec
->query
->view
, co
->index
, wszName
, pVal
, Type
);
460 static HRESULT WINAPI
class_object_Delete(
461 IWbemClassObject
*iface
,
464 FIXME("%p, %s\n", iface
, debugstr_w(wszName
));
468 static HRESULT WINAPI
class_object_GetNames(
469 IWbemClassObject
*iface
,
470 LPCWSTR wszQualifierName
,
472 VARIANT
*pQualifierVal
,
475 struct class_object
*co
= impl_from_IWbemClassObject( iface
);
476 struct enum_class_object
*ec
= impl_from_IEnumWbemClassObject( co
->iter
);
478 TRACE("%p, %s, %08x, %s, %p\n", iface
, debugstr_w(wszQualifierName
), lFlags
,
479 debugstr_variant(pQualifierVal
), pNames
);
481 if (lFlags
!= WBEM_FLAG_ALWAYS
&&
482 lFlags
!= WBEM_FLAG_NONSYSTEM_ONLY
&&
483 lFlags
!= WBEM_FLAG_SYSTEM_ONLY
)
485 FIXME("flags %08x not supported\n", lFlags
);
488 if (wszQualifierName
|| pQualifierVal
)
489 FIXME("qualifier not supported\n");
491 return get_properties( ec
->query
->view
, lFlags
, pNames
);
494 static HRESULT WINAPI
class_object_BeginEnumeration(
495 IWbemClassObject
*iface
,
498 struct class_object
*co
= impl_from_IWbemClassObject( iface
);
500 TRACE("%p, %08x\n", iface
, lEnumFlags
);
502 if (lEnumFlags
) FIXME("flags 0x%08x not supported\n", lEnumFlags
);
504 co
->index_property
= 0;
508 static HRESULT WINAPI
class_object_Next(
509 IWbemClassObject
*iface
,
516 struct class_object
*obj
= impl_from_IWbemClassObject( iface
);
517 struct enum_class_object
*iter
= impl_from_IEnumWbemClassObject( obj
->iter
);
518 struct view
*view
= iter
->query
->view
;
523 TRACE("%p, %08x, %p, %p, %p, %p\n", iface
, lFlags
, strName
, pVal
, pType
, plFlavor
);
525 for (i
= obj
->index_property
; i
< view
->table
->num_cols
; i
++)
527 if (is_method( view
->table
, i
)) continue;
528 if (!is_selected_prop( view
, view
->table
->columns
[i
].name
)) continue;
529 if (!(prop
= SysAllocString( view
->table
->columns
[i
].name
))) return E_OUTOFMEMORY
;
530 if ((hr
= get_propval( view
, obj
->index
, prop
, pVal
, pType
, plFlavor
)) != S_OK
)
532 SysFreeString( prop
);
535 obj
->index_property
= i
+ 1;
539 return WBEM_S_NO_MORE_DATA
;
542 static HRESULT WINAPI
class_object_EndEnumeration(
543 IWbemClassObject
*iface
)
545 struct class_object
*co
= impl_from_IWbemClassObject( iface
);
547 TRACE("%p\n", iface
);
549 co
->index_property
= 0;
553 static HRESULT WINAPI
class_object_GetPropertyQualifierSet(
554 IWbemClassObject
*iface
,
556 IWbemQualifierSet
**ppQualSet
)
558 struct class_object
*co
= impl_from_IWbemClassObject( iface
);
560 TRACE("%p, %s, %p\n", iface
, debugstr_w(wszProperty
), ppQualSet
);
562 return WbemQualifierSet_create( co
->name
, wszProperty
, (void **)ppQualSet
);
565 static HRESULT WINAPI
class_object_Clone(
566 IWbemClassObject
*iface
,
567 IWbemClassObject
**ppCopy
)
569 FIXME("%p, %p\n", iface
, ppCopy
);
573 static BSTR
get_body_text( const struct table
*table
, UINT row
, UINT
*len
)
575 static const WCHAR fmtW
[] = {'\n','\t','%','s',' ','=',' ','%','s',';',0};
581 for (i
= 0; i
< table
->num_cols
; i
++)
583 if ((value
= get_value_bstr( table
, row
, i
)))
585 *len
+= sizeof(fmtW
) / sizeof(fmtW
[0]);
586 *len
+= strlenW( table
->columns
[i
].name
);
587 *len
+= SysStringLen( value
);
588 SysFreeString( value
);
591 if (!(ret
= SysAllocStringLen( NULL
, *len
))) return NULL
;
593 for (i
= 0; i
< table
->num_cols
; i
++)
595 if ((value
= get_value_bstr( table
, row
, i
)))
597 p
+= sprintfW( p
, fmtW
, table
->columns
[i
].name
, value
);
598 SysFreeString( value
);
604 static BSTR
get_object_text( const struct view
*view
, UINT index
)
606 static const WCHAR fmtW
[] =
607 {'\n','i','n','s','t','a','n','c','e',' ','o','f',' ','%','s','\n','{','%','s','\n','}',';',0};
608 UINT len
, len_body
, row
= view
->result
[index
];
611 len
= sizeof(fmtW
) / sizeof(fmtW
[0]);
612 len
+= strlenW( view
->table
->name
);
613 if (!(body
= get_body_text( view
->table
, row
, &len_body
))) return NULL
;
616 if (!(ret
= SysAllocStringLen( NULL
, len
))) return NULL
;
617 sprintfW( ret
, fmtW
, view
->table
->name
, body
);
618 SysFreeString( body
);
622 static HRESULT WINAPI
class_object_GetObjectText(
623 IWbemClassObject
*iface
,
625 BSTR
*pstrObjectText
)
627 struct class_object
*co
= impl_from_IWbemClassObject( iface
);
628 struct enum_class_object
*ec
= impl_from_IEnumWbemClassObject( co
->iter
);
629 struct view
*view
= ec
->query
->view
;
632 TRACE("%p, %08x, %p\n", iface
, lFlags
, pstrObjectText
);
634 if (lFlags
) FIXME("flags %08x not implemented\n", lFlags
);
636 if (!(text
= get_object_text( view
, co
->index
))) return E_OUTOFMEMORY
;
637 *pstrObjectText
= text
;
641 static HRESULT WINAPI
class_object_SpawnDerivedClass(
642 IWbemClassObject
*iface
,
644 IWbemClassObject
**ppNewClass
)
646 FIXME("%p, %08x, %p\n", iface
, lFlags
, ppNewClass
);
650 static HRESULT WINAPI
class_object_SpawnInstance(
651 IWbemClassObject
*iface
,
653 IWbemClassObject
**ppNewInstance
)
655 struct class_object
*co
= impl_from_IWbemClassObject( iface
);
656 struct enum_class_object
*ec
= impl_from_IEnumWbemClassObject( co
->iter
);
657 struct view
*view
= ec
->query
->view
;
658 struct record
*record
;
660 TRACE("%p, %08x, %p\n", iface
, lFlags
, ppNewInstance
);
662 if (!(record
= create_record( view
->table
))) return E_OUTOFMEMORY
;
664 return create_class_object( co
->name
, NULL
, 0, record
, ppNewInstance
);
667 static HRESULT WINAPI
class_object_CompareTo(
668 IWbemClassObject
*iface
,
670 IWbemClassObject
*pCompareTo
)
672 FIXME("%p, %08x, %p\n", iface
, lFlags
, pCompareTo
);
676 static HRESULT WINAPI
class_object_GetPropertyOrigin(
677 IWbemClassObject
*iface
,
679 BSTR
*pstrClassName
)
681 FIXME("%p, %s, %p\n", iface
, debugstr_w(wszName
), pstrClassName
);
685 static HRESULT WINAPI
class_object_InheritsFrom(
686 IWbemClassObject
*iface
,
687 LPCWSTR strAncestor
)
689 FIXME("%p, %s\n", iface
, debugstr_w(strAncestor
));
693 static UINT
count_instances( IEnumWbemClassObject
*iter
)
696 while (!IEnumWbemClassObject_Skip( iter
, WBEM_INFINITE
, 1 )) count
++;
697 IEnumWbemClassObject_Reset( iter
);
701 static void set_default_value( CIMTYPE type
, UINT val
, BYTE
*ptr
)
709 *(UINT16
*)ptr
= val
;
715 *(UINT32
*)ptr
= val
;
718 FIXME("unhandled type %u\n", type
);
723 static HRESULT
create_signature_columns_and_data( IEnumWbemClassObject
*iter
, UINT
*num_cols
,
724 struct column
**cols
, BYTE
**data
)
726 static const WCHAR parameterW
[] = {'P','a','r','a','m','e','t','e','r',0};
727 static const WCHAR typeW
[] = {'T','y','p','e',0};
728 static const WCHAR varianttypeW
[] = {'V','a','r','i','a','n','t','T','y','p','e',0};
729 static const WCHAR defaultvalueW
[] = {'D','e','f','a','u','l','t','V','a','l','u','e',0};
730 struct column
*columns
;
732 IWbemClassObject
*param
;
734 HRESULT hr
= E_OUTOFMEMORY
;
739 count
= count_instances( iter
);
740 if (!(columns
= heap_alloc( count
* sizeof(struct column
) ))) return E_OUTOFMEMORY
;
741 if (!(row
= heap_alloc_zero( count
* sizeof(LONGLONG
) ))) goto error
;
745 IEnumWbemClassObject_Next( iter
, WBEM_INFINITE
, 1, ¶m
, &count
);
748 hr
= IWbemClassObject_Get( param
, parameterW
, 0, &val
, NULL
, NULL
);
749 if (hr
!= S_OK
) goto error
;
750 columns
[i
].name
= heap_strdupW( V_BSTR( &val
) );
751 VariantClear( &val
);
753 hr
= IWbemClassObject_Get( param
, typeW
, 0, &val
, NULL
, NULL
);
754 if (hr
!= S_OK
) goto error
;
755 columns
[i
].type
= V_UI4( &val
);
757 hr
= IWbemClassObject_Get( param
, varianttypeW
, 0, &val
, NULL
, NULL
);
758 if (hr
!= S_OK
) goto error
;
759 columns
[i
].vartype
= V_UI4( &val
);
761 hr
= IWbemClassObject_Get( param
, defaultvalueW
, 0, &val
, NULL
, NULL
);
762 if (hr
!= S_OK
) goto error
;
763 if (V_UI4( &val
)) set_default_value( columns
[i
].type
, V_UI4( &val
), row
+ offset
);
764 offset
+= get_type_size( columns
[i
].type
);
766 IWbemClassObject_Release( param
);
775 for (; i
>= 0; i
--) heap_free( (WCHAR
*)columns
[i
].name
);
776 heap_free( columns
);
781 static HRESULT
create_signature_table( IEnumWbemClassObject
*iter
, WCHAR
*name
)
785 struct column
*columns
;
789 hr
= create_signature_columns_and_data( iter
, &num_cols
, &columns
, &row
);
790 if (hr
!= S_OK
) return hr
;
792 if (!(table
= create_table( name
, num_cols
, columns
, 1, 1, row
, NULL
)))
794 free_columns( columns
, num_cols
);
796 return E_OUTOFMEMORY
;
798 if (!add_table( table
)) free_table( table
); /* already exists */
802 static WCHAR
*build_signature_table_name( const WCHAR
*class, const WCHAR
*method
, enum param_direction dir
)
804 static const WCHAR fmtW
[] = {'_','_','%','s','_','%','s','_','%','s',0};
805 static const WCHAR outW
[] = {'O','U','T',0};
806 static const WCHAR inW
[] = {'I','N',0};
807 UINT len
= SIZEOF(fmtW
) + SIZEOF(outW
) + strlenW( class ) + strlenW( method
);
810 if (!(ret
= heap_alloc( len
* sizeof(WCHAR
) ))) return NULL
;
811 sprintfW( ret
, fmtW
, class, method
, dir
== PARAM_IN
? inW
: outW
);
812 return struprW( ret
);
815 HRESULT
create_signature( const WCHAR
*class, const WCHAR
*method
, enum param_direction dir
,
816 IWbemClassObject
**sig
)
818 static const WCHAR selectW
[] =
819 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
820 '_','_','P','A','R','A','M','E','T','E','R','S',' ','W','H','E','R','E',' ',
821 'C','l','a','s','s','=','\'','%','s','\'',' ','A','N','D',' ',
822 'M','e','t','h','o','d','=','\'','%','s','\'',' ','A','N','D',' ',
823 'D','i','r','e','c','t','i','o','n','%','s',0};
824 static const WCHAR geW
[] = {'>','=','0',0};
825 static const WCHAR leW
[] = {'<','=','0',0};
826 UINT len
= SIZEOF(selectW
) + SIZEOF(geW
);
827 IEnumWbemClassObject
*iter
;
831 len
+= strlenW( class ) + strlenW( method
);
832 if (!(query
= heap_alloc( len
* sizeof(WCHAR
) ))) return E_OUTOFMEMORY
;
833 sprintfW( query
, selectW
, class, method
, dir
>= 0 ? geW
: leW
);
835 hr
= exec_query( query
, &iter
);
837 if (hr
!= S_OK
) return hr
;
839 if (!(name
= build_signature_table_name( class, method
, dir
)))
841 IEnumWbemClassObject_Release( iter
);
842 return E_OUTOFMEMORY
;
844 hr
= create_signature_table( iter
, name
);
845 IEnumWbemClassObject_Release( iter
);
847 hr
= get_object( name
, sig
);
853 static HRESULT WINAPI
class_object_GetMethod(
854 IWbemClassObject
*iface
,
857 IWbemClassObject
**ppInSignature
,
858 IWbemClassObject
**ppOutSignature
)
860 struct class_object
*co
= impl_from_IWbemClassObject( iface
);
861 IWbemClassObject
*in
, *out
;
864 TRACE("%p, %s, %08x, %p, %p\n", iface
, debugstr_w(wszName
), lFlags
, ppInSignature
, ppOutSignature
);
866 hr
= create_signature( co
->name
, wszName
, PARAM_IN
, &in
);
867 if (hr
!= S_OK
) return hr
;
869 hr
= create_signature( co
->name
, wszName
, PARAM_OUT
, &out
);
872 if (ppInSignature
) *ppInSignature
= in
;
873 else IWbemClassObject_Release( in
);
874 if (ppOutSignature
) *ppOutSignature
= out
;
875 else IWbemClassObject_Release( out
);
877 else IWbemClassObject_Release( in
);
881 static HRESULT WINAPI
class_object_PutMethod(
882 IWbemClassObject
*iface
,
885 IWbemClassObject
*pInSignature
,
886 IWbemClassObject
*pOutSignature
)
888 FIXME("%p, %s, %08x, %p, %p\n", iface
, debugstr_w(wszName
), lFlags
, pInSignature
, pOutSignature
);
892 static HRESULT WINAPI
class_object_DeleteMethod(
893 IWbemClassObject
*iface
,
896 FIXME("%p, %s\n", iface
, debugstr_w(wszName
));
900 static HRESULT WINAPI
class_object_BeginMethodEnumeration(
901 IWbemClassObject
*iface
,
904 struct class_object
*co
= impl_from_IWbemClassObject( iface
);
906 TRACE("%p, %08x\n", iface
, lEnumFlags
);
908 if (lEnumFlags
) FIXME("flags 0x%08x not supported\n", lEnumFlags
);
912 WARN("not allowed on instance\n");
913 return WBEM_E_ILLEGAL_OPERATION
;
915 co
->index_method
= 0;
919 static HRESULT WINAPI
class_object_NextMethod(
920 IWbemClassObject
*iface
,
923 IWbemClassObject
**ppInSignature
,
924 IWbemClassObject
**ppOutSignature
)
926 struct class_object
*co
= impl_from_IWbemClassObject( iface
);
930 TRACE("%p, %08x, %p, %p, %p\n", iface
, lFlags
, pstrName
, ppInSignature
, ppOutSignature
);
932 if (!(method
= get_method_name( co
->name
, co
->index_method
))) return WBEM_S_NO_MORE_DATA
;
934 hr
= create_signature( co
->name
, method
, PARAM_IN
, ppInSignature
);
937 SysFreeString( method
);
940 hr
= create_signature( co
->name
, method
, PARAM_OUT
, ppOutSignature
);
943 SysFreeString( method
);
944 IWbemClassObject_Release( *ppInSignature
);
954 static HRESULT WINAPI
class_object_EndMethodEnumeration(
955 IWbemClassObject
*iface
)
957 struct class_object
*co
= impl_from_IWbemClassObject( iface
);
959 TRACE("%p\n", iface
);
961 co
->index_method
= 0;
965 static HRESULT WINAPI
class_object_GetMethodQualifierSet(
966 IWbemClassObject
*iface
,
968 IWbemQualifierSet
**ppQualSet
)
970 FIXME("%p, %s, %p\n", iface
, debugstr_w(wszMethod
), ppQualSet
);
974 static HRESULT WINAPI
class_object_GetMethodOrigin(
975 IWbemClassObject
*iface
,
976 LPCWSTR wszMethodName
,
979 FIXME("%p, %s, %p\n", iface
, debugstr_w(wszMethodName
), pstrClassName
);
983 static const IWbemClassObjectVtbl class_object_vtbl
=
985 class_object_QueryInterface
,
987 class_object_Release
,
988 class_object_GetQualifierSet
,
992 class_object_GetNames
,
993 class_object_BeginEnumeration
,
995 class_object_EndEnumeration
,
996 class_object_GetPropertyQualifierSet
,
998 class_object_GetObjectText
,
999 class_object_SpawnDerivedClass
,
1000 class_object_SpawnInstance
,
1001 class_object_CompareTo
,
1002 class_object_GetPropertyOrigin
,
1003 class_object_InheritsFrom
,
1004 class_object_GetMethod
,
1005 class_object_PutMethod
,
1006 class_object_DeleteMethod
,
1007 class_object_BeginMethodEnumeration
,
1008 class_object_NextMethod
,
1009 class_object_EndMethodEnumeration
,
1010 class_object_GetMethodQualifierSet
,
1011 class_object_GetMethodOrigin
1014 HRESULT
create_class_object( const WCHAR
*name
, IEnumWbemClassObject
*iter
, UINT index
,
1015 struct record
*record
, IWbemClassObject
**obj
)
1017 struct class_object
*co
;
1019 TRACE("%s, %p\n", debugstr_w(name
), obj
);
1021 co
= heap_alloc( sizeof(*co
) );
1022 if (!co
) return E_OUTOFMEMORY
;
1024 co
->IWbemClassObject_iface
.lpVtbl
= &class_object_vtbl
;
1026 if (!name
) co
->name
= NULL
;
1027 else if (!(co
->name
= heap_strdupW( name
)))
1030 return E_OUTOFMEMORY
;
1034 co
->index_method
= 0;
1035 co
->index_property
= 0;
1036 co
->record
= record
;
1037 if (iter
) IEnumWbemClassObject_AddRef( iter
);
1039 *obj
= &co
->IWbemClassObject_iface
;
1041 TRACE("returning iface %p\n", *obj
);