2012-06-14 16:03:26 +02:00
|
|
|
/*
|
|
|
|
* Copyright 2012 Hans Leidekker for CodeWeavers
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define COBJMACROS
|
|
|
|
|
|
|
|
#include <stdarg.h>
|
|
|
|
|
|
|
|
#include "windef.h"
|
|
|
|
#include "winbase.h"
|
|
|
|
#include "objbase.h"
|
|
|
|
#include "wbemcli.h"
|
|
|
|
|
|
|
|
#include "wine/debug.h"
|
|
|
|
#include "wbemprox_private.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(wbemprox);
|
|
|
|
|
|
|
|
struct enum_class_object
|
|
|
|
{
|
|
|
|
IEnumWbemClassObject IEnumWbemClassObject_iface;
|
|
|
|
LONG refs;
|
2012-06-15 15:46:51 +02:00
|
|
|
struct query *query;
|
2012-06-27 11:33:52 +02:00
|
|
|
UINT index;
|
2012-06-14 16:03:26 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
static inline struct enum_class_object *impl_from_IEnumWbemClassObject(
|
|
|
|
IEnumWbemClassObject *iface )
|
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(iface, struct enum_class_object, IEnumWbemClassObject_iface);
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI enum_class_object_AddRef(
|
|
|
|
IEnumWbemClassObject *iface )
|
|
|
|
{
|
|
|
|
struct enum_class_object *ec = impl_from_IEnumWbemClassObject( iface );
|
|
|
|
return InterlockedIncrement( &ec->refs );
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI enum_class_object_Release(
|
|
|
|
IEnumWbemClassObject *iface )
|
|
|
|
{
|
|
|
|
struct enum_class_object *ec = impl_from_IEnumWbemClassObject( iface );
|
|
|
|
LONG refs = InterlockedDecrement( &ec->refs );
|
|
|
|
if (!refs)
|
|
|
|
{
|
|
|
|
TRACE("destroying %p\n", ec);
|
2012-06-28 09:25:13 +02:00
|
|
|
release_query( ec->query );
|
2012-06-14 16:03:26 +02:00
|
|
|
heap_free( ec );
|
|
|
|
}
|
|
|
|
return refs;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI enum_class_object_QueryInterface(
|
|
|
|
IEnumWbemClassObject *iface,
|
|
|
|
REFIID riid,
|
|
|
|
void **ppvObject )
|
|
|
|
{
|
|
|
|
struct enum_class_object *ec = impl_from_IEnumWbemClassObject( iface );
|
|
|
|
|
|
|
|
TRACE("%p, %s, %p\n", ec, debugstr_guid( riid ), ppvObject );
|
|
|
|
|
|
|
|
if ( IsEqualGUID( riid, &IID_IEnumWbemClassObject ) ||
|
|
|
|
IsEqualGUID( riid, &IID_IUnknown ) )
|
|
|
|
{
|
|
|
|
*ppvObject = ec;
|
|
|
|
}
|
2012-06-28 09:24:42 +02:00
|
|
|
else if ( IsEqualGUID( riid, &IID_IClientSecurity ) )
|
|
|
|
{
|
|
|
|
*ppvObject = &client_security;
|
|
|
|
return S_OK;
|
|
|
|
}
|
2012-06-14 16:03:26 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
FIXME("interface %s not implemented\n", debugstr_guid(riid));
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
IEnumWbemClassObject_AddRef( iface );
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI enum_class_object_Reset(
|
|
|
|
IEnumWbemClassObject *iface )
|
|
|
|
{
|
2012-06-18 09:30:43 +02:00
|
|
|
struct enum_class_object *ec = impl_from_IEnumWbemClassObject( iface );
|
|
|
|
|
|
|
|
TRACE("%p\n", iface);
|
|
|
|
|
2012-06-27 11:33:52 +02:00
|
|
|
ec->index = 0;
|
2012-06-18 09:30:43 +02:00
|
|
|
return WBEM_S_NO_ERROR;
|
2012-06-14 16:03:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI enum_class_object_Next(
|
|
|
|
IEnumWbemClassObject *iface,
|
|
|
|
LONG lTimeout,
|
|
|
|
ULONG uCount,
|
|
|
|
IWbemClassObject **apObjects,
|
|
|
|
ULONG *puReturned )
|
|
|
|
{
|
2012-06-15 15:48:32 +02:00
|
|
|
struct enum_class_object *ec = impl_from_IEnumWbemClassObject( iface );
|
|
|
|
struct view *view = ec->query->view;
|
2019-09-10 17:09:14 +02:00
|
|
|
struct table *table;
|
2015-10-05 14:13:08 +02:00
|
|
|
static int once = 0;
|
2012-06-15 15:48:32 +02:00
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
TRACE("%p, %d, %u, %p, %p\n", iface, lTimeout, uCount, apObjects, puReturned);
|
|
|
|
|
|
|
|
if (!uCount) return WBEM_S_FALSE;
|
|
|
|
if (!apObjects || !puReturned) return WBEM_E_INVALID_PARAMETER;
|
2015-10-05 14:13:08 +02:00
|
|
|
if (lTimeout != WBEM_INFINITE && !once++) FIXME("timeout not supported\n");
|
2012-06-15 15:48:32 +02:00
|
|
|
|
|
|
|
*puReturned = 0;
|
2019-09-10 17:09:14 +02:00
|
|
|
if (ec->index >= view->result_count) return WBEM_S_FALSE;
|
2012-06-15 15:48:32 +02:00
|
|
|
|
2019-09-10 17:09:14 +02:00
|
|
|
table = get_view_table( view, ec->index );
|
|
|
|
hr = create_class_object( table->name, iface, ec->index, NULL, apObjects );
|
2012-06-15 15:48:32 +02:00
|
|
|
if (hr != S_OK) return hr;
|
|
|
|
|
2012-06-27 11:33:52 +02:00
|
|
|
ec->index++;
|
2012-06-15 15:48:32 +02:00
|
|
|
*puReturned = 1;
|
2019-09-10 17:09:14 +02:00
|
|
|
if (ec->index == view->result_count && uCount > 1) return WBEM_S_FALSE;
|
2012-06-15 15:48:32 +02:00
|
|
|
if (uCount > 1) return WBEM_S_TIMEDOUT;
|
|
|
|
return WBEM_S_NO_ERROR;
|
2012-06-14 16:03:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI enum_class_object_NextAsync(
|
|
|
|
IEnumWbemClassObject *iface,
|
|
|
|
ULONG uCount,
|
|
|
|
IWbemObjectSink *pSink )
|
|
|
|
{
|
|
|
|
FIXME("%p, %u, %p\n", iface, uCount, pSink);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI enum_class_object_Clone(
|
|
|
|
IEnumWbemClassObject *iface,
|
|
|
|
IEnumWbemClassObject **ppEnum )
|
|
|
|
{
|
2012-06-28 09:25:39 +02:00
|
|
|
struct enum_class_object *ec = impl_from_IEnumWbemClassObject( iface );
|
|
|
|
|
|
|
|
TRACE("%p, %p\n", iface, ppEnum);
|
|
|
|
|
2013-12-30 10:21:36 +01:00
|
|
|
return EnumWbemClassObject_create( ec->query, (void **)ppEnum );
|
2012-06-14 16:03:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI enum_class_object_Skip(
|
|
|
|
IEnumWbemClassObject *iface,
|
|
|
|
LONG lTimeout,
|
|
|
|
ULONG nCount )
|
|
|
|
{
|
2012-06-18 09:31:00 +02:00
|
|
|
struct enum_class_object *ec = impl_from_IEnumWbemClassObject( iface );
|
|
|
|
struct view *view = ec->query->view;
|
2015-10-05 14:13:08 +02:00
|
|
|
static int once = 0;
|
2012-06-18 09:31:00 +02:00
|
|
|
|
|
|
|
TRACE("%p, %d, %u\n", iface, lTimeout, nCount);
|
|
|
|
|
2015-10-05 14:13:08 +02:00
|
|
|
if (lTimeout != WBEM_INFINITE && !once++) FIXME("timeout not supported\n");
|
2012-06-18 09:31:00 +02:00
|
|
|
|
2019-09-10 17:09:14 +02:00
|
|
|
if (!view->result_count) return WBEM_S_FALSE;
|
2012-07-25 13:12:42 +02:00
|
|
|
|
2019-09-10 17:09:14 +02:00
|
|
|
if (nCount > view->result_count - ec->index)
|
2012-06-18 09:31:00 +02:00
|
|
|
{
|
2019-09-10 17:09:14 +02:00
|
|
|
ec->index = view->result_count - 1;
|
2012-06-18 09:31:00 +02:00
|
|
|
return WBEM_S_FALSE;
|
|
|
|
}
|
2012-06-27 11:33:52 +02:00
|
|
|
ec->index += nCount;
|
2012-06-18 09:31:00 +02:00
|
|
|
return WBEM_S_NO_ERROR;
|
2012-06-14 16:03:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static const IEnumWbemClassObjectVtbl enum_class_object_vtbl =
|
|
|
|
{
|
|
|
|
enum_class_object_QueryInterface,
|
|
|
|
enum_class_object_AddRef,
|
|
|
|
enum_class_object_Release,
|
|
|
|
enum_class_object_Reset,
|
|
|
|
enum_class_object_Next,
|
|
|
|
enum_class_object_NextAsync,
|
|
|
|
enum_class_object_Clone,
|
|
|
|
enum_class_object_Skip
|
|
|
|
};
|
|
|
|
|
2013-12-30 10:21:36 +01:00
|
|
|
HRESULT EnumWbemClassObject_create( struct query *query, LPVOID *ppObj )
|
2012-06-14 16:03:26 +02:00
|
|
|
{
|
|
|
|
struct enum_class_object *ec;
|
|
|
|
|
2013-12-30 10:21:36 +01:00
|
|
|
TRACE("%p\n", ppObj);
|
2012-06-14 16:03:26 +02:00
|
|
|
|
|
|
|
ec = heap_alloc( sizeof(*ec) );
|
|
|
|
if (!ec) return E_OUTOFMEMORY;
|
|
|
|
|
|
|
|
ec->IEnumWbemClassObject_iface.lpVtbl = &enum_class_object_vtbl;
|
|
|
|
ec->refs = 1;
|
2012-10-17 11:06:41 +02:00
|
|
|
ec->query = addref_query( query );
|
2012-06-27 11:33:52 +02:00
|
|
|
ec->index = 0;
|
2012-06-14 16:03:26 +02:00
|
|
|
|
|
|
|
*ppObj = &ec->IEnumWbemClassObject_iface;
|
|
|
|
|
|
|
|
TRACE("returning iface %p\n", *ppObj);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2012-10-17 11:06:41 +02:00
|
|
|
static struct record *create_record( struct table *table )
|
2012-09-06 14:03:50 +02:00
|
|
|
{
|
|
|
|
UINT i;
|
|
|
|
struct record *record;
|
|
|
|
|
|
|
|
if (!(record = heap_alloc( sizeof(struct record) ))) return NULL;
|
2012-10-17 11:06:41 +02:00
|
|
|
if (!(record->fields = heap_alloc( table->num_cols * sizeof(struct field) )))
|
2012-09-06 14:03:50 +02:00
|
|
|
{
|
|
|
|
heap_free( record );
|
|
|
|
return NULL;
|
|
|
|
}
|
2012-10-17 11:06:41 +02:00
|
|
|
for (i = 0; i < table->num_cols; i++)
|
2012-09-06 14:03:50 +02:00
|
|
|
{
|
2012-10-17 11:06:41 +02:00
|
|
|
record->fields[i].type = table->columns[i].type;
|
2012-10-12 14:25:39 +02:00
|
|
|
record->fields[i].u.ival = 0;
|
2012-09-06 14:03:50 +02:00
|
|
|
}
|
2012-10-17 11:06:41 +02:00
|
|
|
record->count = table->num_cols;
|
|
|
|
record->table = addref_table( table );
|
2012-09-06 14:03:50 +02:00
|
|
|
return record;
|
|
|
|
}
|
|
|
|
|
2012-10-12 14:25:13 +02:00
|
|
|
void destroy_array( struct array *array, CIMTYPE type )
|
|
|
|
{
|
2019-08-27 16:35:55 +02:00
|
|
|
UINT i;
|
2012-10-12 14:25:13 +02:00
|
|
|
if (!array) return;
|
2019-07-05 11:14:50 +02:00
|
|
|
if (type == CIM_STRING || type == CIM_DATETIME || type == CIM_REFERENCE)
|
2012-10-12 14:25:13 +02:00
|
|
|
{
|
2019-08-27 16:35:55 +02:00
|
|
|
for (i = 0; i < array->count; i++) heap_free( *(WCHAR **)((char *)array->ptr + i * array->elem_size) );
|
2012-10-12 14:25:13 +02:00
|
|
|
}
|
|
|
|
heap_free( array->ptr );
|
|
|
|
heap_free( array );
|
|
|
|
}
|
|
|
|
|
2012-09-06 14:03:50 +02:00
|
|
|
static void destroy_record( struct record *record )
|
|
|
|
{
|
|
|
|
UINT i;
|
|
|
|
|
|
|
|
if (!record) return;
|
2012-10-17 11:06:41 +02:00
|
|
|
release_table( record->table );
|
2012-09-06 14:03:50 +02:00
|
|
|
for (i = 0; i < record->count; i++)
|
|
|
|
{
|
2019-07-05 11:14:50 +02:00
|
|
|
if (record->fields[i].type == CIM_STRING ||
|
|
|
|
record->fields[i].type == CIM_DATETIME ||
|
|
|
|
record->fields[i].type == CIM_REFERENCE) heap_free( record->fields[i].u.sval );
|
2012-10-12 14:25:13 +02:00
|
|
|
else if (record->fields[i].type & CIM_FLAG_ARRAY)
|
|
|
|
destroy_array( record->fields[i].u.aval, record->fields[i].type & CIM_TYPE_MASK );
|
2012-09-06 14:03:50 +02:00
|
|
|
}
|
|
|
|
heap_free( record->fields );
|
|
|
|
heap_free( record );
|
|
|
|
}
|
|
|
|
|
2012-06-14 16:03:26 +02:00
|
|
|
struct class_object
|
|
|
|
{
|
|
|
|
IWbemClassObject IWbemClassObject_iface;
|
|
|
|
LONG refs;
|
2012-07-30 15:04:30 +02:00
|
|
|
WCHAR *name;
|
2012-06-15 15:48:32 +02:00
|
|
|
IEnumWbemClassObject *iter;
|
|
|
|
UINT index;
|
2012-07-30 15:04:49 +02:00
|
|
|
UINT index_method;
|
2012-07-30 15:05:09 +02:00
|
|
|
UINT index_property;
|
2012-09-06 14:03:50 +02:00
|
|
|
struct record *record; /* uncommitted instance */
|
2012-06-14 16:03:26 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
static inline struct class_object *impl_from_IWbemClassObject(
|
|
|
|
IWbemClassObject *iface )
|
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(iface, struct class_object, IWbemClassObject_iface);
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI class_object_AddRef(
|
|
|
|
IWbemClassObject *iface )
|
|
|
|
{
|
|
|
|
struct class_object *co = impl_from_IWbemClassObject( iface );
|
|
|
|
return InterlockedIncrement( &co->refs );
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI class_object_Release(
|
|
|
|
IWbemClassObject *iface )
|
|
|
|
{
|
|
|
|
struct class_object *co = impl_from_IWbemClassObject( iface );
|
|
|
|
LONG refs = InterlockedDecrement( &co->refs );
|
|
|
|
if (!refs)
|
|
|
|
{
|
|
|
|
TRACE("destroying %p\n", co);
|
2012-06-15 15:48:32 +02:00
|
|
|
if (co->iter) IEnumWbemClassObject_Release( co->iter );
|
2012-09-06 14:03:50 +02:00
|
|
|
destroy_record( co->record );
|
2012-07-30 15:04:30 +02:00
|
|
|
heap_free( co->name );
|
2012-06-14 16:03:26 +02:00
|
|
|
heap_free( co );
|
|
|
|
}
|
|
|
|
return refs;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI class_object_QueryInterface(
|
|
|
|
IWbemClassObject *iface,
|
|
|
|
REFIID riid,
|
|
|
|
void **ppvObject )
|
|
|
|
{
|
|
|
|
struct class_object *co = impl_from_IWbemClassObject( iface );
|
|
|
|
|
|
|
|
TRACE("%p, %s, %p\n", co, debugstr_guid( riid ), ppvObject );
|
|
|
|
|
|
|
|
if ( IsEqualGUID( riid, &IID_IWbemClassObject ) ||
|
|
|
|
IsEqualGUID( riid, &IID_IUnknown ) )
|
|
|
|
{
|
|
|
|
*ppvObject = co;
|
|
|
|
}
|
2012-09-06 14:04:14 +02:00
|
|
|
else if (IsEqualGUID( riid, &IID_IClientSecurity ))
|
|
|
|
{
|
|
|
|
*ppvObject = &client_security;
|
|
|
|
return S_OK;
|
|
|
|
}
|
2012-06-14 16:03:26 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
FIXME("interface %s not implemented\n", debugstr_guid(riid));
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
IWbemClassObject_AddRef( iface );
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI class_object_GetQualifierSet(
|
|
|
|
IWbemClassObject *iface,
|
|
|
|
IWbemQualifierSet **ppQualSet )
|
|
|
|
{
|
2019-08-28 14:14:28 +02:00
|
|
|
struct class_object *co = impl_from_IWbemClassObject( iface );
|
|
|
|
|
|
|
|
TRACE("%p, %p\n", iface, ppQualSet);
|
|
|
|
|
|
|
|
return WbemQualifierSet_create( co->name, NULL, (void **)ppQualSet );
|
2012-06-14 16:03:26 +02:00
|
|
|
}
|
|
|
|
|
2012-10-10 12:02:05 +02:00
|
|
|
static HRESULT record_get_value( const struct record *record, UINT index, VARIANT *var, CIMTYPE *type )
|
|
|
|
{
|
2019-09-19 19:33:29 +02:00
|
|
|
VARTYPE vartype = to_vartype( record->fields[index].type & CIM_TYPE_MASK );
|
2012-10-12 14:25:39 +02:00
|
|
|
|
2012-10-10 12:02:05 +02:00
|
|
|
if (type) *type = record->fields[index].type;
|
|
|
|
|
2012-10-10 12:03:10 +02:00
|
|
|
if (record->fields[index].type & CIM_FLAG_ARRAY)
|
|
|
|
{
|
2019-09-19 19:33:29 +02:00
|
|
|
V_VT( var ) = vartype | VT_ARRAY;
|
2012-10-12 14:25:39 +02:00
|
|
|
V_ARRAY( var ) = to_safearray( record->fields[index].u.aval, record->fields[index].type & CIM_TYPE_MASK );
|
2012-10-10 12:03:10 +02:00
|
|
|
return S_OK;
|
|
|
|
}
|
2012-10-10 12:02:05 +02:00
|
|
|
switch (record->fields[index].type)
|
|
|
|
{
|
|
|
|
case CIM_STRING:
|
|
|
|
case CIM_DATETIME:
|
2019-07-05 11:14:50 +02:00
|
|
|
case CIM_REFERENCE:
|
2012-10-10 12:02:05 +02:00
|
|
|
V_BSTR( var ) = SysAllocString( record->fields[index].u.sval );
|
2012-10-12 14:25:39 +02:00
|
|
|
break;
|
2012-10-10 12:02:05 +02:00
|
|
|
case CIM_SINT32:
|
|
|
|
V_I4( var ) = record->fields[index].u.ival;
|
2012-10-12 14:25:39 +02:00
|
|
|
break;
|
2012-10-10 12:02:05 +02:00
|
|
|
case CIM_UINT32:
|
|
|
|
V_UI4( var ) = record->fields[index].u.ival;
|
2012-10-12 14:25:39 +02:00
|
|
|
break;
|
2012-10-10 12:02:05 +02:00
|
|
|
default:
|
|
|
|
FIXME("unhandled type %u\n", record->fields[index].type);
|
2012-10-12 14:25:39 +02:00
|
|
|
return WBEM_E_INVALID_PARAMETER;
|
2012-10-10 12:02:05 +02:00
|
|
|
}
|
2012-10-12 14:25:39 +02:00
|
|
|
V_VT( var ) = vartype;
|
|
|
|
return S_OK;
|
2012-10-10 12:02:05 +02:00
|
|
|
}
|
|
|
|
|
2012-06-14 16:03:26 +02:00
|
|
|
static HRESULT WINAPI class_object_Get(
|
|
|
|
IWbemClassObject *iface,
|
|
|
|
LPCWSTR wszName,
|
|
|
|
LONG lFlags,
|
|
|
|
VARIANT *pVal,
|
|
|
|
CIMTYPE *pType,
|
|
|
|
LONG *plFlavor )
|
|
|
|
{
|
2012-06-18 09:31:29 +02:00
|
|
|
struct class_object *co = impl_from_IWbemClassObject( iface );
|
|
|
|
struct enum_class_object *ec = impl_from_IEnumWbemClassObject( co->iter );
|
|
|
|
|
|
|
|
TRACE("%p, %s, %08x, %p, %p, %p\n", iface, debugstr_w(wszName), lFlags, pVal, pType, plFlavor);
|
|
|
|
|
2012-10-10 12:02:05 +02:00
|
|
|
if (co->record)
|
|
|
|
{
|
|
|
|
UINT index;
|
|
|
|
HRESULT hr;
|
|
|
|
|
2012-10-17 11:06:41 +02:00
|
|
|
if ((hr = get_column_index( co->record->table, wszName, &index )) != S_OK) return hr;
|
2012-10-10 12:02:05 +02:00
|
|
|
return record_get_value( co->record, index, pVal, pType );
|
|
|
|
}
|
|
|
|
return get_propval( ec->query->view, co->index, wszName, pVal, pType, plFlavor );
|
2012-06-14 16:03:26 +02:00
|
|
|
}
|
|
|
|
|
2012-09-06 14:04:03 +02:00
|
|
|
static HRESULT record_set_value( struct record *record, UINT index, VARIANT *var )
|
|
|
|
{
|
|
|
|
LONGLONG val;
|
|
|
|
CIMTYPE type;
|
|
|
|
HRESULT hr;
|
|
|
|
|
2012-10-10 12:03:10 +02:00
|
|
|
if ((hr = to_longlong( var, &val, &type )) != S_OK) return hr;
|
2012-09-06 14:04:03 +02:00
|
|
|
if (type != record->fields[index].type) return WBEM_E_TYPE_MISMATCH;
|
|
|
|
|
2012-10-10 12:03:10 +02:00
|
|
|
if (type & CIM_FLAG_ARRAY)
|
|
|
|
{
|
|
|
|
record->fields[index].u.aval = (struct array *)(INT_PTR)val;
|
|
|
|
return S_OK;
|
|
|
|
}
|
2012-09-06 14:04:03 +02:00
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case CIM_STRING:
|
|
|
|
case CIM_DATETIME:
|
2019-07-05 11:14:50 +02:00
|
|
|
case CIM_REFERENCE:
|
2012-09-06 14:04:03 +02:00
|
|
|
record->fields[index].u.sval = (WCHAR *)(INT_PTR)val;
|
|
|
|
return S_OK;
|
|
|
|
case CIM_SINT16:
|
|
|
|
case CIM_UINT16:
|
|
|
|
case CIM_SINT32:
|
|
|
|
case CIM_UINT32:
|
|
|
|
record->fields[index].u.ival = val;
|
|
|
|
return S_OK;
|
|
|
|
default:
|
|
|
|
FIXME("unhandled type %u\n", type);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return WBEM_E_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
|
2012-06-14 16:03:26 +02:00
|
|
|
static HRESULT WINAPI class_object_Put(
|
|
|
|
IWbemClassObject *iface,
|
|
|
|
LPCWSTR wszName,
|
|
|
|
LONG lFlags,
|
|
|
|
VARIANT *pVal,
|
|
|
|
CIMTYPE Type )
|
|
|
|
{
|
2012-07-25 13:12:10 +02:00
|
|
|
struct class_object *co = impl_from_IWbemClassObject( iface );
|
|
|
|
struct enum_class_object *ec = impl_from_IEnumWbemClassObject( co->iter );
|
|
|
|
|
|
|
|
TRACE("%p, %s, %08x, %p, %u\n", iface, debugstr_w(wszName), lFlags, pVal, Type);
|
|
|
|
|
2012-09-06 14:04:03 +02:00
|
|
|
if (co->record)
|
|
|
|
{
|
|
|
|
UINT index;
|
|
|
|
HRESULT hr;
|
|
|
|
|
2012-10-17 11:06:41 +02:00
|
|
|
if ((hr = get_column_index( co->record->table, wszName, &index )) != S_OK) return hr;
|
2012-09-06 14:04:03 +02:00
|
|
|
return record_set_value( co->record, index, pVal );
|
|
|
|
}
|
|
|
|
return put_propval( ec->query->view, co->index, wszName, pVal, Type );
|
2012-06-14 16:03:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI class_object_Delete(
|
|
|
|
IWbemClassObject *iface,
|
|
|
|
LPCWSTR wszName )
|
|
|
|
{
|
|
|
|
FIXME("%p, %s\n", iface, debugstr_w(wszName));
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI class_object_GetNames(
|
|
|
|
IWbemClassObject *iface,
|
|
|
|
LPCWSTR wszQualifierName,
|
|
|
|
LONG lFlags,
|
|
|
|
VARIANT *pQualifierVal,
|
2012-06-19 10:19:19 +02:00
|
|
|
SAFEARRAY **pNames )
|
2012-06-14 16:03:26 +02:00
|
|
|
{
|
2012-06-19 10:19:38 +02:00
|
|
|
struct class_object *co = impl_from_IWbemClassObject( iface );
|
|
|
|
struct enum_class_object *ec = impl_from_IEnumWbemClassObject( co->iter );
|
|
|
|
|
2013-02-06 13:54:06 +01:00
|
|
|
TRACE("%p, %s, %08x, %s, %p\n", iface, debugstr_w(wszQualifierName), lFlags,
|
|
|
|
debugstr_variant(pQualifierVal), pNames);
|
2012-06-19 10:19:38 +02:00
|
|
|
|
2014-03-24 11:42:00 +01:00
|
|
|
if (lFlags != WBEM_FLAG_ALWAYS &&
|
|
|
|
lFlags != WBEM_FLAG_NONSYSTEM_ONLY &&
|
|
|
|
lFlags != WBEM_FLAG_SYSTEM_ONLY)
|
2012-06-19 10:19:38 +02:00
|
|
|
{
|
|
|
|
FIXME("flags %08x not supported\n", lFlags);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
2014-03-24 11:42:00 +01:00
|
|
|
if (wszQualifierName || pQualifierVal)
|
|
|
|
FIXME("qualifier not supported\n");
|
|
|
|
|
2019-09-10 17:09:14 +02:00
|
|
|
return get_properties( ec->query->view, co->index, lFlags, pNames );
|
2012-06-14 16:03:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI class_object_BeginEnumeration(
|
|
|
|
IWbemClassObject *iface,
|
|
|
|
LONG lEnumFlags )
|
|
|
|
{
|
2012-07-30 15:05:09 +02:00
|
|
|
struct class_object *co = impl_from_IWbemClassObject( iface );
|
|
|
|
|
|
|
|
TRACE("%p, %08x\n", iface, lEnumFlags);
|
|
|
|
|
|
|
|
if (lEnumFlags) FIXME("flags 0x%08x not supported\n", lEnumFlags);
|
|
|
|
|
|
|
|
co->index_property = 0;
|
|
|
|
return S_OK;
|
2012-06-14 16:03:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI class_object_Next(
|
|
|
|
IWbemClassObject *iface,
|
|
|
|
LONG lFlags,
|
|
|
|
BSTR *strName,
|
|
|
|
VARIANT *pVal,
|
|
|
|
CIMTYPE *pType,
|
|
|
|
LONG *plFlavor )
|
|
|
|
{
|
2014-04-30 10:19:30 +02:00
|
|
|
struct class_object *obj = impl_from_IWbemClassObject( iface );
|
|
|
|
struct enum_class_object *iter = impl_from_IEnumWbemClassObject( obj->iter );
|
|
|
|
struct view *view = iter->query->view;
|
2019-09-10 17:09:14 +02:00
|
|
|
struct table *table = get_view_table( view, obj->index );
|
2014-04-30 10:19:30 +02:00
|
|
|
BSTR prop;
|
2012-07-30 15:05:09 +02:00
|
|
|
HRESULT hr;
|
2014-04-30 10:19:30 +02:00
|
|
|
UINT i;
|
2012-07-30 15:05:09 +02:00
|
|
|
|
|
|
|
TRACE("%p, %08x, %p, %p, %p, %p\n", iface, lFlags, strName, pVal, pType, plFlavor);
|
|
|
|
|
2019-09-10 17:09:14 +02:00
|
|
|
for (i = obj->index_property; i < table->num_cols; i++)
|
2012-07-30 15:05:09 +02:00
|
|
|
{
|
2019-09-10 17:09:14 +02:00
|
|
|
if (is_method( table, i )) continue;
|
|
|
|
if (!is_result_prop( view, table->columns[i].name )) continue;
|
|
|
|
if (!(prop = SysAllocString( table->columns[i].name ))) return E_OUTOFMEMORY;
|
2014-04-30 10:19:30 +02:00
|
|
|
if ((hr = get_propval( view, obj->index, prop, pVal, pType, plFlavor )) != S_OK)
|
|
|
|
{
|
|
|
|
SysFreeString( prop );
|
|
|
|
return hr;
|
|
|
|
}
|
2018-10-09 15:25:03 +02:00
|
|
|
|
2014-04-30 10:19:30 +02:00
|
|
|
obj->index_property = i + 1;
|
2018-10-09 15:25:03 +02:00
|
|
|
if (strName) *strName = prop;
|
|
|
|
else SysFreeString( prop );
|
|
|
|
|
2014-04-30 10:19:30 +02:00
|
|
|
return S_OK;
|
2012-07-30 15:05:09 +02:00
|
|
|
}
|
2014-04-30 10:19:30 +02:00
|
|
|
return WBEM_S_NO_MORE_DATA;
|
2012-06-14 16:03:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI class_object_EndEnumeration(
|
|
|
|
IWbemClassObject *iface )
|
|
|
|
{
|
2012-07-30 15:05:09 +02:00
|
|
|
struct class_object *co = impl_from_IWbemClassObject( iface );
|
|
|
|
|
|
|
|
TRACE("%p\n", iface);
|
|
|
|
|
|
|
|
co->index_property = 0;
|
|
|
|
return S_OK;
|
2012-06-14 16:03:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI class_object_GetPropertyQualifierSet(
|
|
|
|
IWbemClassObject *iface,
|
|
|
|
LPCWSTR wszProperty,
|
|
|
|
IWbemQualifierSet **ppQualSet )
|
|
|
|
{
|
2013-01-25 17:34:00 +01:00
|
|
|
struct class_object *co = impl_from_IWbemClassObject( iface );
|
|
|
|
|
|
|
|
TRACE("%p, %s, %p\n", iface, debugstr_w(wszProperty), ppQualSet);
|
|
|
|
|
2013-12-30 10:21:36 +01:00
|
|
|
return WbemQualifierSet_create( co->name, wszProperty, (void **)ppQualSet );
|
2012-06-14 16:03:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI class_object_Clone(
|
|
|
|
IWbemClassObject *iface,
|
|
|
|
IWbemClassObject **ppCopy )
|
|
|
|
{
|
|
|
|
FIXME("%p, %p\n", iface, ppCopy);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
2012-09-04 13:49:40 +02:00
|
|
|
static BSTR get_body_text( const struct table *table, UINT row, UINT *len )
|
|
|
|
{
|
|
|
|
BSTR value, ret;
|
|
|
|
WCHAR *p;
|
|
|
|
UINT i;
|
|
|
|
|
|
|
|
*len = 0;
|
|
|
|
for (i = 0; i < table->num_cols; i++)
|
|
|
|
{
|
2012-11-02 15:34:27 +01:00
|
|
|
if ((value = get_value_bstr( table, row, i )))
|
|
|
|
{
|
2020-04-20 10:38:10 +02:00
|
|
|
*len += ARRAY_SIZE( L"\n\t%s = %s;" );
|
2019-07-04 09:27:39 +02:00
|
|
|
*len += lstrlenW( table->columns[i].name );
|
2012-11-02 15:34:27 +01:00
|
|
|
*len += SysStringLen( value );
|
|
|
|
SysFreeString( value );
|
|
|
|
}
|
2012-09-04 13:49:40 +02:00
|
|
|
}
|
|
|
|
if (!(ret = SysAllocStringLen( NULL, *len ))) return NULL;
|
|
|
|
p = ret;
|
|
|
|
for (i = 0; i < table->num_cols; i++)
|
|
|
|
{
|
2012-11-02 15:34:27 +01:00
|
|
|
if ((value = get_value_bstr( table, row, i )))
|
|
|
|
{
|
2020-04-20 10:38:10 +02:00
|
|
|
p += swprintf( p, *len - (p - ret), L"\n\t%s = %s;", table->columns[i].name, value );
|
2012-11-02 15:34:27 +01:00
|
|
|
SysFreeString( value );
|
|
|
|
}
|
2012-09-04 13:49:40 +02:00
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static BSTR get_object_text( const struct view *view, UINT index )
|
|
|
|
{
|
|
|
|
UINT len, len_body, row = view->result[index];
|
2019-09-10 17:09:14 +02:00
|
|
|
struct table *table = get_view_table( view, index );
|
2012-09-04 13:49:40 +02:00
|
|
|
BSTR ret, body;
|
|
|
|
|
2020-04-20 10:38:10 +02:00
|
|
|
len = ARRAY_SIZE( L"\ninstance of %s\n{%s\n};" );
|
2019-09-10 17:09:14 +02:00
|
|
|
len += lstrlenW( table->name );
|
|
|
|
if (!(body = get_body_text( table, row, &len_body ))) return NULL;
|
2012-09-04 13:49:40 +02:00
|
|
|
len += len_body;
|
|
|
|
|
|
|
|
if (!(ret = SysAllocStringLen( NULL, len ))) return NULL;
|
2020-04-20 10:38:10 +02:00
|
|
|
swprintf( ret, len, L"\ninstance of %s\n{%s\n};", table->name, body );
|
2012-09-04 13:49:40 +02:00
|
|
|
SysFreeString( body );
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2012-06-14 16:03:26 +02:00
|
|
|
static HRESULT WINAPI class_object_GetObjectText(
|
|
|
|
IWbemClassObject *iface,
|
|
|
|
LONG lFlags,
|
|
|
|
BSTR *pstrObjectText )
|
|
|
|
{
|
2012-09-04 13:49:40 +02:00
|
|
|
struct class_object *co = impl_from_IWbemClassObject( iface );
|
|
|
|
struct enum_class_object *ec = impl_from_IEnumWbemClassObject( co->iter );
|
|
|
|
struct view *view = ec->query->view;
|
|
|
|
BSTR text;
|
|
|
|
|
|
|
|
TRACE("%p, %08x, %p\n", iface, lFlags, pstrObjectText);
|
|
|
|
|
|
|
|
if (lFlags) FIXME("flags %08x not implemented\n", lFlags);
|
|
|
|
|
|
|
|
if (!(text = get_object_text( view, co->index ))) return E_OUTOFMEMORY;
|
|
|
|
*pstrObjectText = text;
|
|
|
|
return S_OK;
|
2012-06-14 16:03:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI class_object_SpawnDerivedClass(
|
|
|
|
IWbemClassObject *iface,
|
|
|
|
LONG lFlags,
|
|
|
|
IWbemClassObject **ppNewClass )
|
|
|
|
{
|
|
|
|
FIXME("%p, %08x, %p\n", iface, lFlags, ppNewClass);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI class_object_SpawnInstance(
|
|
|
|
IWbemClassObject *iface,
|
|
|
|
LONG lFlags,
|
|
|
|
IWbemClassObject **ppNewInstance )
|
|
|
|
{
|
2012-09-06 14:03:50 +02:00
|
|
|
struct class_object *co = impl_from_IWbemClassObject( iface );
|
|
|
|
struct enum_class_object *ec = impl_from_IEnumWbemClassObject( co->iter );
|
2019-09-10 17:09:14 +02:00
|
|
|
struct table *table = get_view_table( ec->query->view, co->index );
|
2012-09-06 14:03:50 +02:00
|
|
|
struct record *record;
|
|
|
|
|
|
|
|
TRACE("%p, %08x, %p\n", iface, lFlags, ppNewInstance);
|
|
|
|
|
2019-09-10 17:09:14 +02:00
|
|
|
if (!(record = create_record( table ))) return E_OUTOFMEMORY;
|
2012-09-06 14:03:50 +02:00
|
|
|
|
|
|
|
return create_class_object( co->name, NULL, 0, record, ppNewInstance );
|
2012-06-14 16:03:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI class_object_CompareTo(
|
|
|
|
IWbemClassObject *iface,
|
|
|
|
LONG lFlags,
|
|
|
|
IWbemClassObject *pCompareTo )
|
|
|
|
{
|
|
|
|
FIXME("%p, %08x, %p\n", iface, lFlags, pCompareTo);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI class_object_GetPropertyOrigin(
|
|
|
|
IWbemClassObject *iface,
|
|
|
|
LPCWSTR wszName,
|
|
|
|
BSTR *pstrClassName )
|
|
|
|
{
|
|
|
|
FIXME("%p, %s, %p\n", iface, debugstr_w(wszName), pstrClassName);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI class_object_InheritsFrom(
|
|
|
|
IWbemClassObject *iface,
|
|
|
|
LPCWSTR strAncestor )
|
|
|
|
{
|
|
|
|
FIXME("%p, %s\n", iface, debugstr_w(strAncestor));
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
2012-07-25 13:13:17 +02:00
|
|
|
static UINT count_instances( IEnumWbemClassObject *iter )
|
|
|
|
{
|
|
|
|
UINT count = 0;
|
|
|
|
while (!IEnumWbemClassObject_Skip( iter, WBEM_INFINITE, 1 )) count++;
|
|
|
|
IEnumWbemClassObject_Reset( iter );
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void set_default_value( CIMTYPE type, UINT val, BYTE *ptr )
|
|
|
|
{
|
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case CIM_SINT16:
|
|
|
|
*(INT16 *)ptr = val;
|
|
|
|
break;
|
|
|
|
case CIM_UINT16:
|
|
|
|
*(UINT16 *)ptr = val;
|
|
|
|
break;
|
|
|
|
case CIM_SINT32:
|
|
|
|
*(INT32 *)ptr = val;
|
|
|
|
break;
|
|
|
|
case CIM_UINT32:
|
|
|
|
*(UINT32 *)ptr = val;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
FIXME("unhandled type %u\n", type);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-27 10:22:28 +02:00
|
|
|
static HRESULT create_signature_columns_and_data( IEnumWbemClassObject *iter, UINT *num_cols,
|
2012-07-25 13:13:17 +02:00
|
|
|
struct column **cols, BYTE **data )
|
|
|
|
{
|
|
|
|
struct column *columns;
|
|
|
|
BYTE *row;
|
|
|
|
IWbemClassObject *param;
|
|
|
|
VARIANT val;
|
|
|
|
HRESULT hr = E_OUTOFMEMORY;
|
|
|
|
UINT offset = 0;
|
|
|
|
ULONG count;
|
|
|
|
int i = 0;
|
|
|
|
|
|
|
|
count = count_instances( iter );
|
|
|
|
if (!(columns = heap_alloc( count * sizeof(struct column) ))) return E_OUTOFMEMORY;
|
|
|
|
if (!(row = heap_alloc_zero( count * sizeof(LONGLONG) ))) goto error;
|
|
|
|
|
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
IEnumWbemClassObject_Next( iter, WBEM_INFINITE, 1, ¶m, &count );
|
|
|
|
if (!count) break;
|
|
|
|
|
2020-04-20 10:38:10 +02:00
|
|
|
hr = IWbemClassObject_Get( param, L"Parameter", 0, &val, NULL, NULL );
|
2012-07-25 13:13:17 +02:00
|
|
|
if (hr != S_OK) goto error;
|
|
|
|
columns[i].name = heap_strdupW( V_BSTR( &val ) );
|
|
|
|
VariantClear( &val );
|
|
|
|
|
2020-04-20 10:38:10 +02:00
|
|
|
hr = IWbemClassObject_Get( param, L"Type", 0, &val, NULL, NULL );
|
2012-07-25 13:13:17 +02:00
|
|
|
if (hr != S_OK) goto error;
|
2012-10-12 14:25:39 +02:00
|
|
|
columns[i].type = V_UI4( &val );
|
|
|
|
|
2020-04-20 10:38:10 +02:00
|
|
|
hr = IWbemClassObject_Get( param, L"DefaultValue", 0, &val, NULL, NULL );
|
2012-07-25 13:13:17 +02:00
|
|
|
if (hr != S_OK) goto error;
|
|
|
|
if (V_UI4( &val )) set_default_value( columns[i].type, V_UI4( &val ), row + offset );
|
|
|
|
offset += get_type_size( columns[i].type );
|
|
|
|
|
|
|
|
IWbemClassObject_Release( param );
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
*num_cols = i;
|
|
|
|
*cols = columns;
|
|
|
|
*data = row;
|
|
|
|
return S_OK;
|
|
|
|
|
|
|
|
error:
|
|
|
|
for (; i >= 0; i--) heap_free( (WCHAR *)columns[i].name );
|
|
|
|
heap_free( columns );
|
|
|
|
heap_free( row );
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2012-07-27 10:22:28 +02:00
|
|
|
static HRESULT create_signature_table( IEnumWbemClassObject *iter, WCHAR *name )
|
2012-07-25 13:13:17 +02:00
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
struct table *table;
|
|
|
|
struct column *columns;
|
|
|
|
UINT num_cols;
|
|
|
|
BYTE *row;
|
|
|
|
|
|
|
|
hr = create_signature_columns_and_data( iter, &num_cols, &columns, &row );
|
|
|
|
if (hr != S_OK) return hr;
|
|
|
|
|
2013-06-04 13:28:21 +02:00
|
|
|
if (!(table = create_table( name, num_cols, columns, 1, 1, row, NULL )))
|
2012-07-25 13:13:17 +02:00
|
|
|
{
|
|
|
|
free_columns( columns, num_cols );
|
|
|
|
heap_free( row );
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
}
|
|
|
|
if (!add_table( table )) free_table( table ); /* already exists */
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2012-07-27 10:22:28 +02:00
|
|
|
static WCHAR *build_signature_table_name( const WCHAR *class, const WCHAR *method, enum param_direction dir )
|
2012-07-25 13:13:17 +02:00
|
|
|
{
|
2020-04-20 10:38:10 +02:00
|
|
|
UINT len = ARRAY_SIZE(L"__%s_%s_%s") + ARRAY_SIZE(L"OUT") + lstrlenW( class ) + lstrlenW( method );
|
2012-07-25 13:13:17 +02:00
|
|
|
WCHAR *ret;
|
|
|
|
|
|
|
|
if (!(ret = heap_alloc( len * sizeof(WCHAR) ))) return NULL;
|
2020-04-20 10:38:10 +02:00
|
|
|
swprintf( ret, len, L"__%s_%s_%s", class, method, dir == PARAM_IN ? L"IN" : L"OUT" );
|
2019-07-04 09:27:39 +02:00
|
|
|
return wcsupr( ret );
|
2012-07-25 13:13:17 +02:00
|
|
|
}
|
|
|
|
|
2012-10-12 14:26:12 +02:00
|
|
|
HRESULT create_signature( const WCHAR *class, const WCHAR *method, enum param_direction dir,
|
|
|
|
IWbemClassObject **sig )
|
2012-07-25 13:13:17 +02:00
|
|
|
{
|
2020-04-20 10:38:10 +02:00
|
|
|
static const WCHAR selectW[] = L"SELECT * FROM __PARAMETERS WHERE Class='%s' AND Method='%s' AND Direction%s";
|
|
|
|
UINT len = ARRAY_SIZE(selectW) + ARRAY_SIZE(L">=0");
|
2012-07-25 13:13:17 +02:00
|
|
|
IEnumWbemClassObject *iter;
|
|
|
|
WCHAR *query, *name;
|
|
|
|
HRESULT hr;
|
|
|
|
|
2019-07-04 09:27:39 +02:00
|
|
|
len += lstrlenW( class ) + lstrlenW( method );
|
2012-07-25 13:13:17 +02:00
|
|
|
if (!(query = heap_alloc( len * sizeof(WCHAR) ))) return E_OUTOFMEMORY;
|
2020-04-20 10:38:10 +02:00
|
|
|
swprintf( query, len, selectW, class, method, dir >= 0 ? L">=0" : L"<=0" );
|
2012-07-25 13:13:17 +02:00
|
|
|
|
|
|
|
hr = exec_query( query, &iter );
|
|
|
|
heap_free( query );
|
|
|
|
if (hr != S_OK) return hr;
|
|
|
|
|
2018-10-17 08:47:20 +02:00
|
|
|
if (!count_instances( iter ))
|
|
|
|
{
|
|
|
|
*sig = NULL;
|
|
|
|
IEnumWbemClassObject_Release( iter );
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2012-07-25 13:13:17 +02:00
|
|
|
if (!(name = build_signature_table_name( class, method, dir )))
|
|
|
|
{
|
|
|
|
IEnumWbemClassObject_Release( iter );
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
}
|
|
|
|
hr = create_signature_table( iter, name );
|
|
|
|
IEnumWbemClassObject_Release( iter );
|
2013-02-04 16:56:11 +01:00
|
|
|
if (hr == S_OK)
|
|
|
|
hr = get_object( name, sig );
|
|
|
|
|
|
|
|
heap_free( name );
|
|
|
|
return hr;
|
2012-07-25 13:13:17 +02:00
|
|
|
}
|
|
|
|
|
2012-06-14 16:03:26 +02:00
|
|
|
static HRESULT WINAPI class_object_GetMethod(
|
|
|
|
IWbemClassObject *iface,
|
|
|
|
LPCWSTR wszName,
|
|
|
|
LONG lFlags,
|
|
|
|
IWbemClassObject **ppInSignature,
|
|
|
|
IWbemClassObject **ppOutSignature )
|
|
|
|
{
|
2012-07-25 13:13:17 +02:00
|
|
|
struct class_object *co = impl_from_IWbemClassObject( iface );
|
2013-01-11 17:21:23 +01:00
|
|
|
IWbemClassObject *in, *out;
|
2012-07-25 13:13:17 +02:00
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
TRACE("%p, %s, %08x, %p, %p\n", iface, debugstr_w(wszName), lFlags, ppInSignature, ppOutSignature);
|
|
|
|
|
2013-01-11 17:21:23 +01:00
|
|
|
hr = create_signature( co->name, wszName, PARAM_IN, &in );
|
|
|
|
if (hr != S_OK) return hr;
|
2012-07-25 13:13:17 +02:00
|
|
|
|
2013-01-11 17:21:23 +01:00
|
|
|
hr = create_signature( co->name, wszName, PARAM_OUT, &out );
|
|
|
|
if (hr == S_OK)
|
|
|
|
{
|
|
|
|
if (ppInSignature) *ppInSignature = in;
|
2018-10-17 08:47:20 +02:00
|
|
|
else if (in) IWbemClassObject_Release( in );
|
2013-01-11 17:21:23 +01:00
|
|
|
if (ppOutSignature) *ppOutSignature = out;
|
2018-10-17 08:47:20 +02:00
|
|
|
else if (out) IWbemClassObject_Release( out );
|
2013-01-11 17:21:23 +01:00
|
|
|
}
|
|
|
|
else IWbemClassObject_Release( in );
|
2012-07-25 13:13:17 +02:00
|
|
|
return hr;
|
2012-06-14 16:03:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI class_object_PutMethod(
|
|
|
|
IWbemClassObject *iface,
|
|
|
|
LPCWSTR wszName,
|
|
|
|
LONG lFlags,
|
|
|
|
IWbemClassObject *pInSignature,
|
|
|
|
IWbemClassObject *pOutSignature )
|
|
|
|
{
|
|
|
|
FIXME("%p, %s, %08x, %p, %p\n", iface, debugstr_w(wszName), lFlags, pInSignature, pOutSignature);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI class_object_DeleteMethod(
|
|
|
|
IWbemClassObject *iface,
|
|
|
|
LPCWSTR wszName )
|
|
|
|
{
|
|
|
|
FIXME("%p, %s\n", iface, debugstr_w(wszName));
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI class_object_BeginMethodEnumeration(
|
|
|
|
IWbemClassObject *iface,
|
|
|
|
LONG lEnumFlags)
|
|
|
|
{
|
2012-07-30 15:04:49 +02:00
|
|
|
struct class_object *co = impl_from_IWbemClassObject( iface );
|
|
|
|
|
|
|
|
TRACE("%p, %08x\n", iface, lEnumFlags);
|
|
|
|
|
|
|
|
if (lEnumFlags) FIXME("flags 0x%08x not supported\n", lEnumFlags);
|
|
|
|
|
|
|
|
co->index_method = 0;
|
|
|
|
return S_OK;
|
2012-06-14 16:03:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI class_object_NextMethod(
|
|
|
|
IWbemClassObject *iface,
|
|
|
|
LONG lFlags,
|
|
|
|
BSTR *pstrName,
|
|
|
|
IWbemClassObject **ppInSignature,
|
|
|
|
IWbemClassObject **ppOutSignature)
|
|
|
|
{
|
2012-07-30 15:04:49 +02:00
|
|
|
struct class_object *co = impl_from_IWbemClassObject( iface );
|
2012-10-10 12:01:44 +02:00
|
|
|
BSTR method;
|
2012-07-30 15:04:49 +02:00
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
TRACE("%p, %08x, %p, %p, %p\n", iface, lFlags, pstrName, ppInSignature, ppOutSignature);
|
|
|
|
|
|
|
|
if (!(method = get_method_name( co->name, co->index_method ))) return WBEM_S_NO_MORE_DATA;
|
|
|
|
|
|
|
|
hr = create_signature( co->name, method, PARAM_IN, ppInSignature );
|
2012-10-10 12:01:44 +02:00
|
|
|
if (hr != S_OK)
|
|
|
|
{
|
|
|
|
SysFreeString( method );
|
|
|
|
return hr;
|
|
|
|
}
|
2012-07-30 15:04:49 +02:00
|
|
|
hr = create_signature( co->name, method, PARAM_OUT, ppOutSignature );
|
2012-10-10 12:01:44 +02:00
|
|
|
if (hr != S_OK)
|
|
|
|
{
|
|
|
|
SysFreeString( method );
|
2018-10-17 08:47:20 +02:00
|
|
|
if (*ppInSignature)
|
|
|
|
IWbemClassObject_Release( *ppInSignature );
|
2012-10-10 12:01:44 +02:00
|
|
|
}
|
2012-07-30 15:04:49 +02:00
|
|
|
else
|
|
|
|
{
|
2012-10-10 12:01:44 +02:00
|
|
|
*pstrName = method;
|
2012-07-30 15:04:49 +02:00
|
|
|
co->index_method++;
|
|
|
|
}
|
|
|
|
return hr;
|
2012-06-14 16:03:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI class_object_EndMethodEnumeration(
|
|
|
|
IWbemClassObject *iface )
|
|
|
|
{
|
2012-07-30 15:04:49 +02:00
|
|
|
struct class_object *co = impl_from_IWbemClassObject( iface );
|
|
|
|
|
|
|
|
TRACE("%p\n", iface);
|
|
|
|
|
|
|
|
co->index_method = 0;
|
|
|
|
return S_OK;
|
2012-06-14 16:03:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI class_object_GetMethodQualifierSet(
|
|
|
|
IWbemClassObject *iface,
|
|
|
|
LPCWSTR wszMethod,
|
|
|
|
IWbemQualifierSet **ppQualSet)
|
|
|
|
{
|
|
|
|
FIXME("%p, %s, %p\n", iface, debugstr_w(wszMethod), ppQualSet);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI class_object_GetMethodOrigin(
|
|
|
|
IWbemClassObject *iface,
|
|
|
|
LPCWSTR wszMethodName,
|
|
|
|
BSTR *pstrClassName)
|
|
|
|
{
|
|
|
|
FIXME("%p, %s, %p\n", iface, debugstr_w(wszMethodName), pstrClassName);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const IWbemClassObjectVtbl class_object_vtbl =
|
|
|
|
{
|
|
|
|
class_object_QueryInterface,
|
|
|
|
class_object_AddRef,
|
|
|
|
class_object_Release,
|
|
|
|
class_object_GetQualifierSet,
|
|
|
|
class_object_Get,
|
|
|
|
class_object_Put,
|
|
|
|
class_object_Delete,
|
|
|
|
class_object_GetNames,
|
|
|
|
class_object_BeginEnumeration,
|
|
|
|
class_object_Next,
|
|
|
|
class_object_EndEnumeration,
|
|
|
|
class_object_GetPropertyQualifierSet,
|
|
|
|
class_object_Clone,
|
|
|
|
class_object_GetObjectText,
|
|
|
|
class_object_SpawnDerivedClass,
|
|
|
|
class_object_SpawnInstance,
|
|
|
|
class_object_CompareTo,
|
|
|
|
class_object_GetPropertyOrigin,
|
|
|
|
class_object_InheritsFrom,
|
|
|
|
class_object_GetMethod,
|
|
|
|
class_object_PutMethod,
|
|
|
|
class_object_DeleteMethod,
|
|
|
|
class_object_BeginMethodEnumeration,
|
|
|
|
class_object_NextMethod,
|
|
|
|
class_object_EndMethodEnumeration,
|
|
|
|
class_object_GetMethodQualifierSet,
|
|
|
|
class_object_GetMethodOrigin
|
|
|
|
};
|
|
|
|
|
2012-09-06 14:03:50 +02:00
|
|
|
HRESULT create_class_object( const WCHAR *name, IEnumWbemClassObject *iter, UINT index,
|
|
|
|
struct record *record, IWbemClassObject **obj )
|
2012-06-14 16:03:26 +02:00
|
|
|
{
|
|
|
|
struct class_object *co;
|
|
|
|
|
2012-07-30 15:04:30 +02:00
|
|
|
TRACE("%s, %p\n", debugstr_w(name), obj);
|
2012-06-14 16:03:26 +02:00
|
|
|
|
|
|
|
co = heap_alloc( sizeof(*co) );
|
|
|
|
if (!co) return E_OUTOFMEMORY;
|
|
|
|
|
|
|
|
co->IWbemClassObject_iface.lpVtbl = &class_object_vtbl;
|
2012-06-15 15:48:32 +02:00
|
|
|
co->refs = 1;
|
2013-01-28 15:56:40 +01:00
|
|
|
if (!name) co->name = NULL;
|
|
|
|
else if (!(co->name = heap_strdupW( name )))
|
2012-07-30 15:04:30 +02:00
|
|
|
{
|
|
|
|
heap_free( co );
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
}
|
2012-07-30 15:04:49 +02:00
|
|
|
co->iter = iter;
|
|
|
|
co->index = index;
|
|
|
|
co->index_method = 0;
|
2012-07-30 15:05:09 +02:00
|
|
|
co->index_property = 0;
|
2012-09-06 14:03:50 +02:00
|
|
|
co->record = record;
|
2012-06-15 15:48:32 +02:00
|
|
|
if (iter) IEnumWbemClassObject_AddRef( iter );
|
2012-06-14 16:03:26 +02:00
|
|
|
|
2012-07-30 15:04:30 +02:00
|
|
|
*obj = &co->IWbemClassObject_iface;
|
2012-06-14 16:03:26 +02:00
|
|
|
|
2012-07-30 15:04:30 +02:00
|
|
|
TRACE("returning iface %p\n", *obj);
|
2012-06-14 16:03:26 +02:00
|
|
|
return S_OK;
|
|
|
|
}
|