2012-06-15 15:46:51 +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 "config.h"
|
|
|
|
#include <stdarg.h>
|
|
|
|
|
|
|
|
#include "windef.h"
|
|
|
|
#include "winbase.h"
|
|
|
|
#include "wbemcli.h"
|
|
|
|
|
|
|
|
#include "wine/debug.h"
|
|
|
|
#include "wbemprox_private.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(wbemprox);
|
|
|
|
|
2012-06-18 09:32:02 +02:00
|
|
|
HRESULT create_view( const struct property *proplist, const WCHAR *class,
|
|
|
|
const struct expr *cond, struct view **ret )
|
|
|
|
{
|
|
|
|
struct view *view = heap_alloc( sizeof(struct view) );
|
|
|
|
|
|
|
|
if (!view) return E_OUTOFMEMORY;
|
|
|
|
view->proplist = proplist;
|
2012-10-10 12:01:44 +02:00
|
|
|
view->table = grab_table( class );
|
2012-06-18 09:32:02 +02:00
|
|
|
view->cond = cond;
|
|
|
|
view->result = NULL;
|
|
|
|
view->count = 0;
|
|
|
|
*ret = view;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void destroy_view( struct view *view )
|
|
|
|
{
|
2013-02-25 11:03:33 +01:00
|
|
|
if (!view) return;
|
2012-10-10 12:01:44 +02:00
|
|
|
if (view->table) release_table( view->table );
|
2012-06-18 09:32:02 +02:00
|
|
|
heap_free( view->result );
|
|
|
|
heap_free( view );
|
|
|
|
}
|
|
|
|
|
2012-07-11 14:02:16 +02:00
|
|
|
static BOOL eval_like( const WCHAR *lstr, const WCHAR *rstr )
|
2012-06-15 15:47:54 +02:00
|
|
|
{
|
2012-07-11 14:02:16 +02:00
|
|
|
const WCHAR *p = lstr, *q = rstr;
|
2012-06-15 15:47:54 +02:00
|
|
|
|
|
|
|
while (*p && *q)
|
|
|
|
{
|
|
|
|
if (*q == '%')
|
|
|
|
{
|
|
|
|
while (*q == '%') q++;
|
|
|
|
if (!*q) return TRUE;
|
2015-08-14 14:58:13 +02:00
|
|
|
while (*p && *q && toupperW( *p ) == toupperW( *q )) { p++; q++; };
|
|
|
|
if (!*p && !*q) return TRUE;
|
2012-06-15 15:47:54 +02:00
|
|
|
}
|
2015-08-14 14:58:13 +02:00
|
|
|
if (*q != '%' && toupperW( *p++ ) != toupperW( *q++ )) return FALSE;
|
2012-06-15 15:47:54 +02:00
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2012-07-11 14:02:16 +02:00
|
|
|
static HRESULT eval_strcmp( UINT op, const WCHAR *lstr, const WCHAR *rstr, LONGLONG *val )
|
|
|
|
{
|
2012-10-10 12:00:58 +02:00
|
|
|
if (!lstr || !rstr)
|
|
|
|
{
|
|
|
|
*val = 0;
|
|
|
|
return S_OK;
|
|
|
|
}
|
2012-07-11 14:02:16 +02:00
|
|
|
switch (op)
|
|
|
|
{
|
|
|
|
case OP_EQ:
|
|
|
|
*val = !strcmpW( lstr, rstr );
|
|
|
|
break;
|
|
|
|
case OP_GT:
|
|
|
|
*val = strcmpW( lstr, rstr ) > 0;
|
|
|
|
break;
|
|
|
|
case OP_LT:
|
|
|
|
*val = strcmpW( lstr, rstr ) < 0;
|
|
|
|
break;
|
|
|
|
case OP_LE:
|
|
|
|
*val = strcmpW( lstr, rstr ) <= 0;
|
|
|
|
break;
|
|
|
|
case OP_GE:
|
|
|
|
*val = strcmpW( lstr, rstr ) >= 0;
|
|
|
|
break;
|
|
|
|
case OP_NE:
|
|
|
|
*val = strcmpW( lstr, rstr );
|
|
|
|
break;
|
|
|
|
case OP_LIKE:
|
|
|
|
*val = eval_like( lstr, rstr );
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
ERR("unhandled operator %u\n", op);
|
|
|
|
return WBEM_E_INVALID_QUERY;
|
|
|
|
}
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline BOOL is_strcmp( const struct complex_expr *expr )
|
|
|
|
{
|
|
|
|
return ((expr->left->type == EXPR_PROPVAL && expr->right->type == EXPR_SVAL) ||
|
|
|
|
(expr->left->type == EXPR_SVAL && expr->right->type == EXPR_PROPVAL));
|
|
|
|
}
|
|
|
|
|
2014-01-28 13:26:16 +01:00
|
|
|
static inline BOOL is_boolcmp( const struct complex_expr *expr, UINT ltype, UINT rtype )
|
|
|
|
{
|
|
|
|
if (ltype == CIM_BOOLEAN && expr->left->type == EXPR_PROPVAL &&
|
|
|
|
(expr->right->type == EXPR_SVAL || expr->right->type == EXPR_BVAL)) return TRUE;
|
|
|
|
else if (rtype == CIM_BOOLEAN && expr->right->type == EXPR_PROPVAL &&
|
|
|
|
(expr->left->type == EXPR_SVAL || expr->left->type == EXPR_BVAL)) return TRUE;
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT eval_boolcmp( UINT op, LONGLONG lval, LONGLONG rval, UINT ltype, UINT rtype, LONGLONG *val )
|
|
|
|
{
|
|
|
|
static const WCHAR trueW[] = {'T','r','u','e',0};
|
|
|
|
|
|
|
|
if (ltype == CIM_STRING) lval = !strcmpiW( (const WCHAR *)(INT_PTR)lval, trueW ) ? -1 : 0;
|
|
|
|
else if (rtype == CIM_STRING) rval = !strcmpiW( (const WCHAR *)(INT_PTR)rval, trueW ) ? -1 : 0;
|
|
|
|
|
|
|
|
switch (op)
|
|
|
|
{
|
|
|
|
case OP_EQ:
|
|
|
|
*val = (lval == rval);
|
|
|
|
break;
|
|
|
|
case OP_NE:
|
|
|
|
*val = (lval != rval);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
ERR("unhandled operator %u\n", op);
|
|
|
|
return WBEM_E_INVALID_QUERY;
|
|
|
|
}
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static UINT resolve_type( UINT left, UINT right )
|
|
|
|
{
|
|
|
|
switch (left)
|
|
|
|
{
|
|
|
|
case CIM_SINT8:
|
|
|
|
case CIM_SINT16:
|
|
|
|
case CIM_SINT32:
|
|
|
|
case CIM_SINT64:
|
|
|
|
case CIM_UINT8:
|
|
|
|
case CIM_UINT16:
|
|
|
|
case CIM_UINT32:
|
|
|
|
case CIM_UINT64:
|
|
|
|
switch (right)
|
|
|
|
{
|
|
|
|
case CIM_SINT8:
|
|
|
|
case CIM_SINT16:
|
|
|
|
case CIM_SINT32:
|
|
|
|
case CIM_SINT64:
|
|
|
|
case CIM_UINT8:
|
|
|
|
case CIM_UINT16:
|
|
|
|
case CIM_UINT32:
|
|
|
|
case CIM_UINT64:
|
|
|
|
return CIM_UINT64;
|
|
|
|
default: break;
|
|
|
|
}
|
2014-02-08 01:42:49 +01:00
|
|
|
break;
|
2014-01-28 13:26:16 +01:00
|
|
|
|
|
|
|
case CIM_STRING:
|
|
|
|
if (right == CIM_STRING) return CIM_STRING;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CIM_BOOLEAN:
|
|
|
|
if (right == CIM_BOOLEAN) return CIM_BOOLEAN;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return CIM_ILLEGAL;
|
|
|
|
}
|
|
|
|
|
2012-07-11 14:02:16 +02:00
|
|
|
static HRESULT eval_binary( const struct table *table, UINT row, const struct complex_expr *expr,
|
2014-01-28 13:26:16 +01:00
|
|
|
LONGLONG *val, UINT *type )
|
2012-06-15 15:47:54 +02:00
|
|
|
{
|
|
|
|
HRESULT lret, rret;
|
2012-06-27 11:34:23 +02:00
|
|
|
LONGLONG lval, rval;
|
2014-01-28 13:26:16 +01:00
|
|
|
UINT ltype, rtype;
|
2012-06-15 15:47:54 +02:00
|
|
|
|
2014-01-28 13:26:16 +01:00
|
|
|
lret = eval_cond( table, row, expr->left, &lval, <ype );
|
|
|
|
rret = eval_cond( table, row, expr->right, &rval, &rtype );
|
2012-06-15 15:47:54 +02:00
|
|
|
if (lret != S_OK || rret != S_OK) return WBEM_E_INVALID_QUERY;
|
|
|
|
|
2014-01-28 13:26:16 +01:00
|
|
|
*type = resolve_type( ltype, rtype );
|
|
|
|
|
|
|
|
if (is_boolcmp( expr, ltype, rtype ))
|
|
|
|
return eval_boolcmp( expr->op, lval, rval, ltype, rtype, val );
|
|
|
|
|
2012-07-11 14:02:16 +02:00
|
|
|
if (is_strcmp( expr ))
|
|
|
|
{
|
|
|
|
const WCHAR *lstr = (const WCHAR *)(INT_PTR)lval;
|
|
|
|
const WCHAR *rstr = (const WCHAR *)(INT_PTR)rval;
|
|
|
|
|
|
|
|
return eval_strcmp( expr->op, lstr, rstr, val );
|
|
|
|
}
|
2012-06-15 15:47:54 +02:00
|
|
|
switch (expr->op)
|
|
|
|
{
|
|
|
|
case OP_EQ:
|
|
|
|
*val = (lval == rval);
|
|
|
|
break;
|
|
|
|
case OP_AND:
|
|
|
|
*val = (lval && rval);
|
|
|
|
break;
|
|
|
|
case OP_OR:
|
|
|
|
*val = (lval || rval);
|
|
|
|
break;
|
|
|
|
case OP_GT:
|
|
|
|
*val = (lval > rval);
|
|
|
|
break;
|
|
|
|
case OP_LT:
|
|
|
|
*val = (lval < rval);
|
|
|
|
break;
|
|
|
|
case OP_LE:
|
|
|
|
*val = (lval <= rval);
|
|
|
|
break;
|
|
|
|
case OP_GE:
|
|
|
|
*val = (lval >= rval);
|
|
|
|
break;
|
|
|
|
case OP_NE:
|
|
|
|
*val = (lval != rval);
|
|
|
|
break;
|
|
|
|
default:
|
2012-07-11 14:02:16 +02:00
|
|
|
ERR("unhandled operator %u\n", expr->op);
|
2012-06-15 15:47:54 +02:00
|
|
|
return WBEM_E_INVALID_QUERY;
|
|
|
|
}
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT eval_unary( const struct table *table, UINT row, const struct complex_expr *expr,
|
2014-01-28 13:26:16 +01:00
|
|
|
LONGLONG *val, UINT *type )
|
2012-06-15 15:47:54 +02:00
|
|
|
|
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
UINT column;
|
2012-06-27 11:34:23 +02:00
|
|
|
LONGLONG lval;
|
2012-06-15 15:47:54 +02:00
|
|
|
|
2014-02-28 11:23:39 +01:00
|
|
|
if (expr->op == OP_NOT)
|
|
|
|
{
|
|
|
|
hr = eval_cond( table, row, expr->left, &lval, type );
|
|
|
|
if (hr != S_OK)
|
|
|
|
return hr;
|
|
|
|
*val = !lval;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2012-06-15 15:47:54 +02:00
|
|
|
hr = get_column_index( table, expr->left->u.propval->name, &column );
|
|
|
|
if (hr != S_OK)
|
|
|
|
return hr;
|
|
|
|
|
|
|
|
hr = get_value( table, row, column, &lval );
|
|
|
|
if (hr != S_OK)
|
|
|
|
return hr;
|
|
|
|
|
|
|
|
switch (expr->op)
|
|
|
|
{
|
|
|
|
case OP_ISNULL:
|
|
|
|
*val = !lval;
|
|
|
|
break;
|
|
|
|
case OP_NOTNULL:
|
|
|
|
*val = lval;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
ERR("unknown operator %u\n", expr->op);
|
|
|
|
return WBEM_E_INVALID_QUERY;
|
|
|
|
}
|
2014-01-28 13:26:16 +01:00
|
|
|
|
|
|
|
*type = table->columns[column].type & CIM_TYPE_MASK;
|
2012-06-15 15:47:54 +02:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT eval_propval( const struct table *table, UINT row, const struct property *propval,
|
2014-01-28 13:26:16 +01:00
|
|
|
LONGLONG *val, UINT *type )
|
2012-06-15 15:47:54 +02:00
|
|
|
|
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
UINT column;
|
|
|
|
|
|
|
|
hr = get_column_index( table, propval->name, &column );
|
|
|
|
if (hr != S_OK)
|
|
|
|
return hr;
|
|
|
|
|
2014-01-28 13:26:16 +01:00
|
|
|
*type = table->columns[column].type & CIM_TYPE_MASK;
|
2012-06-15 15:47:54 +02:00
|
|
|
return get_value( table, row, column, val );
|
|
|
|
}
|
|
|
|
|
2014-01-28 13:26:16 +01:00
|
|
|
HRESULT eval_cond( const struct table *table, UINT row, const struct expr *cond, LONGLONG *val, UINT *type )
|
2012-06-15 15:47:54 +02:00
|
|
|
{
|
|
|
|
if (!cond)
|
|
|
|
{
|
|
|
|
*val = 1;
|
2014-01-28 13:26:16 +01:00
|
|
|
*type = CIM_UINT64;
|
2012-06-15 15:47:54 +02:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
switch (cond->type)
|
|
|
|
{
|
|
|
|
case EXPR_COMPLEX:
|
2014-01-28 13:26:16 +01:00
|
|
|
return eval_binary( table, row, &cond->u.expr, val, type );
|
|
|
|
|
2012-06-15 15:47:54 +02:00
|
|
|
case EXPR_UNARY:
|
2014-01-28 13:26:16 +01:00
|
|
|
return eval_unary( table, row, &cond->u.expr, val, type );
|
|
|
|
|
2012-06-15 15:47:54 +02:00
|
|
|
case EXPR_PROPVAL:
|
2014-01-28 13:26:16 +01:00
|
|
|
return eval_propval( table, row, cond->u.propval, val, type );
|
|
|
|
|
2012-06-15 15:47:54 +02:00
|
|
|
case EXPR_SVAL:
|
2012-10-10 12:03:10 +02:00
|
|
|
*val = (INT_PTR)cond->u.sval;
|
2014-01-28 13:26:16 +01:00
|
|
|
*type = CIM_STRING;
|
2012-06-15 15:47:54 +02:00
|
|
|
return S_OK;
|
2014-01-28 13:26:16 +01:00
|
|
|
|
2012-06-15 15:47:54 +02:00
|
|
|
case EXPR_IVAL:
|
2014-01-28 13:26:16 +01:00
|
|
|
*val = cond->u.ival;
|
|
|
|
*type = CIM_UINT64;
|
|
|
|
return S_OK;
|
|
|
|
|
2012-06-15 15:47:54 +02:00
|
|
|
case EXPR_BVAL:
|
|
|
|
*val = cond->u.ival;
|
2014-01-28 13:26:16 +01:00
|
|
|
*type = CIM_BOOLEAN;
|
2012-06-15 15:47:54 +02:00
|
|
|
return S_OK;
|
2014-01-28 13:26:16 +01:00
|
|
|
|
2012-06-15 15:47:54 +02:00
|
|
|
default:
|
|
|
|
ERR("invalid expression type\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return WBEM_E_INVALID_QUERY;
|
|
|
|
}
|
|
|
|
|
2013-06-04 13:27:48 +02:00
|
|
|
HRESULT execute_view( struct view *view )
|
2012-06-15 15:47:54 +02:00
|
|
|
{
|
|
|
|
UINT i, j = 0, len;
|
|
|
|
|
2013-05-22 10:07:26 +02:00
|
|
|
if (!view->table) return S_OK;
|
2013-05-22 10:08:17 +02:00
|
|
|
if (view->table->fill)
|
|
|
|
{
|
|
|
|
clear_table( view->table );
|
2013-05-22 10:09:26 +02:00
|
|
|
view->table->fill( view->table, view->cond );
|
2013-05-22 10:08:17 +02:00
|
|
|
}
|
2013-05-22 10:07:26 +02:00
|
|
|
if (!view->table->num_rows) return S_OK;
|
2012-06-15 15:47:54 +02:00
|
|
|
|
|
|
|
len = min( view->table->num_rows, 16 );
|
|
|
|
if (!(view->result = heap_alloc( len * sizeof(UINT) ))) return E_OUTOFMEMORY;
|
|
|
|
|
|
|
|
for (i = 0; i < view->table->num_rows; i++)
|
|
|
|
{
|
|
|
|
HRESULT hr;
|
2012-06-27 11:34:23 +02:00
|
|
|
LONGLONG val = 0;
|
2014-01-28 13:26:16 +01:00
|
|
|
UINT type;
|
2012-06-15 15:47:54 +02:00
|
|
|
|
|
|
|
if (j >= len)
|
|
|
|
{
|
|
|
|
UINT *tmp;
|
|
|
|
len *= 2;
|
|
|
|
if (!(tmp = heap_realloc( view->result, len * sizeof(UINT) ))) return E_OUTOFMEMORY;
|
|
|
|
view->result = tmp;
|
|
|
|
}
|
2014-01-28 13:26:16 +01:00
|
|
|
if ((hr = eval_cond( view->table, i, view->cond, &val, &type )) != S_OK) return hr;
|
2012-06-15 15:47:54 +02:00
|
|
|
if (val) view->result[j++] = i;
|
|
|
|
}
|
|
|
|
view->count = j;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2013-06-04 13:27:48 +02:00
|
|
|
struct query *create_query(void)
|
2012-06-15 15:46:51 +02:00
|
|
|
{
|
|
|
|
struct query *query;
|
|
|
|
|
|
|
|
if (!(query = heap_alloc( sizeof(*query) ))) return NULL;
|
|
|
|
list_init( &query->mem );
|
2012-06-28 09:25:13 +02:00
|
|
|
query->refs = 1;
|
2012-06-15 15:46:51 +02:00
|
|
|
return query;
|
|
|
|
}
|
|
|
|
|
2013-06-04 13:27:48 +02:00
|
|
|
void free_query( struct query *query )
|
2012-06-15 15:46:51 +02:00
|
|
|
{
|
|
|
|
struct list *mem, *next;
|
|
|
|
|
2013-06-04 13:27:48 +02:00
|
|
|
if (!query) return;
|
2012-06-15 15:46:51 +02:00
|
|
|
destroy_view( query->view );
|
2013-06-04 13:27:48 +02:00
|
|
|
LIST_FOR_EACH_SAFE( mem, next, &query->mem ) { heap_free( mem ); }
|
2012-06-15 15:46:51 +02:00
|
|
|
heap_free( query );
|
|
|
|
}
|
|
|
|
|
2012-10-17 11:06:41 +02:00
|
|
|
struct query *addref_query( struct query *query )
|
2012-06-28 09:25:13 +02:00
|
|
|
{
|
|
|
|
InterlockedIncrement( &query->refs );
|
2012-10-17 11:06:41 +02:00
|
|
|
return query;
|
2012-06-28 09:25:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void release_query( struct query *query )
|
|
|
|
{
|
|
|
|
if (!InterlockedDecrement( &query->refs )) free_query( query );
|
|
|
|
}
|
|
|
|
|
2012-06-15 15:46:51 +02:00
|
|
|
HRESULT exec_query( const WCHAR *str, IEnumWbemClassObject **result )
|
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
struct query *query;
|
|
|
|
|
|
|
|
*result = NULL;
|
2012-06-28 09:25:13 +02:00
|
|
|
if (!(query = create_query())) return E_OUTOFMEMORY;
|
2012-06-15 15:46:51 +02:00
|
|
|
hr = parse_query( str, &query->view, &query->mem );
|
2012-06-15 15:47:54 +02:00
|
|
|
if (hr != S_OK) goto done;
|
|
|
|
hr = execute_view( query->view );
|
|
|
|
if (hr != S_OK) goto done;
|
2013-12-30 10:21:36 +01:00
|
|
|
hr = EnumWbemClassObject_create( query, (void **)result );
|
2012-06-15 15:47:54 +02:00
|
|
|
|
|
|
|
done:
|
2012-06-28 09:25:13 +02:00
|
|
|
release_query( query );
|
2012-06-15 15:46:51 +02:00
|
|
|
return hr;
|
|
|
|
}
|
2012-06-18 09:31:29 +02:00
|
|
|
|
2014-04-30 10:19:30 +02:00
|
|
|
BOOL is_selected_prop( const struct view *view, const WCHAR *name )
|
2012-06-18 09:31:29 +02:00
|
|
|
{
|
|
|
|
const struct property *prop = view->proplist;
|
|
|
|
|
|
|
|
if (!prop) return TRUE;
|
|
|
|
while (prop)
|
|
|
|
{
|
|
|
|
if (!strcmpiW( prop->name, name )) return TRUE;
|
|
|
|
prop = prop->next;
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2012-06-20 12:05:59 +02:00
|
|
|
static BOOL is_system_prop( const WCHAR *name )
|
|
|
|
{
|
|
|
|
return (name[0] == '_' && name[1] == '_');
|
|
|
|
}
|
|
|
|
|
|
|
|
static BSTR build_servername( const struct view *view )
|
|
|
|
{
|
|
|
|
WCHAR server[MAX_COMPUTERNAME_LENGTH + 1], *p;
|
|
|
|
DWORD len = sizeof(server)/sizeof(server[0]);
|
|
|
|
|
|
|
|
if (view->proplist) return NULL;
|
|
|
|
|
|
|
|
if (!(GetComputerNameW( server, &len ))) return NULL;
|
|
|
|
for (p = server; *p; p++) *p = toupperW( *p );
|
|
|
|
return SysAllocString( server );
|
|
|
|
}
|
|
|
|
|
|
|
|
static BSTR build_classname( const struct view *view )
|
|
|
|
{
|
|
|
|
return SysAllocString( view->table->name );
|
|
|
|
}
|
|
|
|
|
|
|
|
static BSTR build_namespace( const struct view *view )
|
|
|
|
{
|
|
|
|
static const WCHAR cimv2W[] = {'R','O','O','T','\\','C','I','M','V','2',0};
|
|
|
|
|
|
|
|
if (view->proplist) return NULL;
|
|
|
|
return SysAllocString( cimv2W );
|
|
|
|
}
|
|
|
|
|
2012-06-20 12:06:40 +02:00
|
|
|
static BSTR build_proplist( const struct view *view, UINT index, UINT count, UINT *len )
|
|
|
|
{
|
|
|
|
static const WCHAR fmtW[] = {'%','s','=','%','s',0};
|
|
|
|
UINT i, j, offset, row = view->result[index];
|
|
|
|
BSTR *values, ret = NULL;
|
|
|
|
|
|
|
|
if (!(values = heap_alloc( count * sizeof(BSTR) ))) return NULL;
|
|
|
|
|
|
|
|
*len = j = 0;
|
|
|
|
for (i = 0; i < view->table->num_cols; i++)
|
|
|
|
{
|
|
|
|
if (view->table->columns[i].type & COL_FLAG_KEY)
|
|
|
|
{
|
|
|
|
const WCHAR *name = view->table->columns[i].name;
|
|
|
|
|
|
|
|
values[j] = get_value_bstr( view->table, row, i );
|
|
|
|
*len += strlenW( fmtW ) + strlenW( name ) + strlenW( values[j] );
|
|
|
|
j++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ((ret = SysAllocStringLen( NULL, *len )))
|
|
|
|
{
|
|
|
|
offset = j = 0;
|
|
|
|
for (i = 0; i < view->table->num_cols; i++)
|
|
|
|
{
|
|
|
|
if (view->table->columns[i].type & COL_FLAG_KEY)
|
|
|
|
{
|
|
|
|
const WCHAR *name = view->table->columns[i].name;
|
|
|
|
|
|
|
|
offset += sprintfW( ret + offset, fmtW, name, values[j] );
|
|
|
|
if (j < count - 1) ret[offset++] = ',';
|
|
|
|
j++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (i = 0; i < count; i++) SysFreeString( values[i] );
|
|
|
|
heap_free( values );
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static UINT count_key_columns( const struct view *view )
|
|
|
|
{
|
|
|
|
UINT i, num_keys = 0;
|
|
|
|
|
|
|
|
for (i = 0; i < view->table->num_cols; i++)
|
|
|
|
{
|
|
|
|
if (view->table->columns[i].type & COL_FLAG_KEY) num_keys++;
|
|
|
|
}
|
|
|
|
return num_keys;
|
|
|
|
}
|
|
|
|
|
2012-06-20 12:05:59 +02:00
|
|
|
static BSTR build_relpath( const struct view *view, UINT index, const WCHAR *name )
|
|
|
|
{
|
2012-06-20 12:06:40 +02:00
|
|
|
static const WCHAR fmtW[] = {'%','s','.','%','s',0};
|
|
|
|
BSTR class, proplist, ret = NULL;
|
|
|
|
UINT num_keys, len;
|
|
|
|
|
2012-06-20 12:05:59 +02:00
|
|
|
if (view->proplist) return NULL;
|
2012-06-20 12:06:40 +02:00
|
|
|
|
|
|
|
if (!(class = build_classname( view ))) return NULL;
|
|
|
|
if (!(num_keys = count_key_columns( view ))) return class;
|
|
|
|
if (!(proplist = build_proplist( view, index, num_keys, &len ))) goto done;
|
|
|
|
|
|
|
|
len += strlenW( fmtW ) + SysStringLen( class );
|
|
|
|
if (!(ret = SysAllocStringLen( NULL, len ))) goto done;
|
|
|
|
sprintfW( ret, fmtW, class, proplist );
|
|
|
|
|
|
|
|
done:
|
|
|
|
SysFreeString( class );
|
|
|
|
SysFreeString( proplist );
|
|
|
|
return ret;
|
2012-06-20 12:05:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static BSTR build_path( const struct view *view, UINT index, const WCHAR *name )
|
|
|
|
{
|
|
|
|
static const WCHAR fmtW[] = {'\\','\\','%','s','\\','%','s',':','%','s',0};
|
|
|
|
BSTR server, namespace = NULL, relpath = NULL, ret = NULL;
|
|
|
|
UINT len;
|
|
|
|
|
|
|
|
if (view->proplist) return NULL;
|
|
|
|
|
|
|
|
if (!(server = build_servername( view ))) return NULL;
|
|
|
|
if (!(namespace = build_namespace( view ))) goto done;
|
|
|
|
if (!(relpath = build_relpath( view, index, name ))) goto done;
|
|
|
|
|
|
|
|
len = strlenW( fmtW ) + SysStringLen( server ) + SysStringLen( namespace ) + SysStringLen( relpath );
|
|
|
|
if (!(ret = SysAllocStringLen( NULL, len ))) goto done;
|
|
|
|
sprintfW( ret, fmtW, server, namespace, relpath );
|
|
|
|
|
|
|
|
done:
|
|
|
|
SysFreeString( server );
|
|
|
|
SysFreeString( namespace );
|
|
|
|
SysFreeString( relpath );
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2014-04-30 10:19:30 +02:00
|
|
|
BOOL is_method( const struct table *table, UINT column )
|
2012-07-13 11:35:09 +02:00
|
|
|
{
|
|
|
|
return table->columns[column].type & COL_FLAG_METHOD;
|
|
|
|
}
|
|
|
|
|
|
|
|
static UINT count_properties( const struct view *view )
|
|
|
|
{
|
|
|
|
UINT i, num_props = 0;
|
|
|
|
|
|
|
|
for (i = 0; i < view->table->num_cols; i++)
|
|
|
|
{
|
|
|
|
if (!is_method( view->table, i)) num_props++;
|
|
|
|
}
|
|
|
|
return num_props;
|
|
|
|
}
|
|
|
|
|
|
|
|
static UINT count_selected_properties( const struct view *view )
|
2012-06-20 12:05:59 +02:00
|
|
|
{
|
|
|
|
const struct property *prop = view->proplist;
|
|
|
|
UINT count;
|
|
|
|
|
2012-07-13 11:35:09 +02:00
|
|
|
if (!prop) return count_properties( view );
|
2012-06-20 12:05:59 +02:00
|
|
|
|
|
|
|
count = 1;
|
|
|
|
while ((prop = prop->next)) count++;
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT get_system_propval( const struct view *view, UINT index, const WCHAR *name,
|
2012-06-29 13:39:34 +02:00
|
|
|
VARIANT *ret, CIMTYPE *type, LONG *flavor )
|
2012-06-20 12:05:59 +02:00
|
|
|
{
|
|
|
|
static const WCHAR classW[] = {'_','_','C','L','A','S','S',0};
|
|
|
|
static const WCHAR genusW[] = {'_','_','G','E','N','U','S',0};
|
|
|
|
static const WCHAR pathW[] = {'_','_','P','A','T','H',0};
|
|
|
|
static const WCHAR namespaceW[] = {'_','_','N','A','M','E','S','P','A','C','E',0};
|
|
|
|
static const WCHAR propcountW[] = {'_','_','P','R','O','P','E','R','T','Y','_','C','O','U','N','T',0};
|
|
|
|
static const WCHAR relpathW[] = {'_','_','R','E','L','P','A','T','H',0};
|
|
|
|
static const WCHAR serverW[] = {'_','_','S','E','R','V','E','R',0};
|
|
|
|
|
2012-06-29 13:39:34 +02:00
|
|
|
if (flavor) *flavor = WBEM_FLAVOR_ORIGIN_SYSTEM;
|
|
|
|
|
2012-06-20 12:05:59 +02:00
|
|
|
if (!strcmpiW( name, classW ))
|
|
|
|
{
|
|
|
|
V_VT( ret ) = VT_BSTR;
|
|
|
|
V_BSTR( ret ) = build_classname( view );
|
|
|
|
if (type) *type = CIM_STRING;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
if (!strcmpiW( name, genusW ))
|
|
|
|
{
|
2012-06-29 13:39:34 +02:00
|
|
|
V_VT( ret ) = VT_I4;
|
|
|
|
V_I4( ret ) = WBEM_GENUS_INSTANCE; /* FIXME */
|
2012-06-20 12:05:59 +02:00
|
|
|
if (type) *type = CIM_SINT32;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
else if (!strcmpiW( name, namespaceW ))
|
|
|
|
{
|
|
|
|
V_VT( ret ) = VT_BSTR;
|
|
|
|
V_BSTR( ret ) = build_namespace( view );
|
|
|
|
if (type) *type = CIM_STRING;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
else if (!strcmpiW( name, pathW ))
|
|
|
|
{
|
|
|
|
V_VT( ret ) = VT_BSTR;
|
|
|
|
V_BSTR( ret ) = build_path( view, index, name );
|
|
|
|
if (type) *type = CIM_STRING;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
if (!strcmpiW( name, propcountW ))
|
|
|
|
{
|
2012-06-29 13:39:34 +02:00
|
|
|
V_VT( ret ) = VT_I4;
|
2012-07-13 11:35:09 +02:00
|
|
|
V_I4( ret ) = count_selected_properties( view );
|
2012-06-20 12:05:59 +02:00
|
|
|
if (type) *type = CIM_SINT32;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
else if (!strcmpiW( name, relpathW ))
|
|
|
|
{
|
|
|
|
V_VT( ret ) = VT_BSTR;
|
|
|
|
V_BSTR( ret ) = build_relpath( view, index, name );
|
|
|
|
if (type) *type = CIM_STRING;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
else if (!strcmpiW( name, serverW ))
|
|
|
|
{
|
|
|
|
V_VT( ret ) = VT_BSTR;
|
|
|
|
V_BSTR( ret ) = build_servername( view );
|
|
|
|
if (type) *type = CIM_STRING;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
FIXME("system property %s not implemented\n", debugstr_w(name));
|
|
|
|
return WBEM_E_NOT_FOUND;
|
|
|
|
}
|
|
|
|
|
2012-10-10 12:03:10 +02:00
|
|
|
VARTYPE to_vartype( CIMTYPE type )
|
2012-07-02 16:00:50 +02:00
|
|
|
{
|
2012-10-10 12:03:10 +02:00
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case CIM_BOOLEAN: return VT_BOOL;
|
|
|
|
case CIM_STRING:
|
|
|
|
case CIM_DATETIME: return VT_BSTR;
|
2014-08-04 23:29:16 +02:00
|
|
|
case CIM_SINT8: return VT_I1;
|
|
|
|
case CIM_UINT8: return VT_UI1;
|
2012-10-10 12:03:10 +02:00
|
|
|
case CIM_SINT16: return VT_I2;
|
|
|
|
case CIM_UINT16: return VT_UI2;
|
|
|
|
case CIM_SINT32: return VT_I4;
|
|
|
|
case CIM_UINT32: return VT_UI4;
|
|
|
|
case CIM_SINT64: return VT_I8;
|
|
|
|
case CIM_UINT64: return VT_UI8;
|
|
|
|
default:
|
|
|
|
ERR("unhandled type %u\n", type);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
SAFEARRAY *to_safearray( const struct array *array, CIMTYPE type )
|
|
|
|
{
|
|
|
|
SAFEARRAY *ret;
|
|
|
|
UINT size = get_type_size( type );
|
|
|
|
VARTYPE vartype = to_vartype( type );
|
|
|
|
LONG i;
|
|
|
|
|
2013-05-03 14:45:25 +02:00
|
|
|
if (!array || !(ret = SafeArrayCreateVector( vartype, 0, array->count ))) return NULL;
|
2012-10-10 12:03:10 +02:00
|
|
|
|
|
|
|
for (i = 0; i < array->count; i++)
|
|
|
|
{
|
|
|
|
void *ptr = (char *)array->ptr + i * size;
|
|
|
|
if (vartype == VT_BSTR)
|
|
|
|
{
|
|
|
|
BSTR str = SysAllocString( *(const WCHAR **)ptr );
|
|
|
|
if (!str || SafeArrayPutElement( ret, &i, str ) != S_OK)
|
|
|
|
{
|
|
|
|
SysFreeString( str );
|
|
|
|
SafeArrayDestroy( ret );
|
|
|
|
return NULL;
|
|
|
|
}
|
2015-04-22 12:13:55 +02:00
|
|
|
SysFreeString( str );
|
2012-10-10 12:03:10 +02:00
|
|
|
}
|
|
|
|
else if (SafeArrayPutElement( ret, &i, ptr ) != S_OK)
|
|
|
|
{
|
|
|
|
SafeArrayDestroy( ret );
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2012-10-12 14:26:12 +02:00
|
|
|
void set_variant( VARTYPE type, LONGLONG val, void *val_ptr, VARIANT *ret )
|
2012-10-10 12:03:10 +02:00
|
|
|
{
|
|
|
|
if (type & VT_ARRAY)
|
|
|
|
{
|
|
|
|
V_VT( ret ) = type;
|
|
|
|
V_ARRAY( ret ) = val_ptr;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
switch (type)
|
2012-07-02 16:00:50 +02:00
|
|
|
{
|
2012-07-30 15:04:03 +02:00
|
|
|
case VT_BOOL:
|
|
|
|
V_BOOL( ret ) = val;
|
2012-10-10 12:03:10 +02:00
|
|
|
break;
|
2012-07-02 16:00:50 +02:00
|
|
|
case VT_BSTR:
|
2012-10-10 12:03:10 +02:00
|
|
|
V_BSTR( ret ) = val_ptr;
|
|
|
|
break;
|
2014-08-04 23:29:16 +02:00
|
|
|
case VT_I1:
|
|
|
|
V_I1( ret ) = val;
|
|
|
|
break;
|
|
|
|
case VT_UI1:
|
|
|
|
V_UI1( ret ) = val;
|
|
|
|
break;
|
2012-07-02 16:00:50 +02:00
|
|
|
case VT_I2:
|
|
|
|
V_I2( ret ) = val;
|
2012-10-10 12:03:10 +02:00
|
|
|
break;
|
2012-07-02 16:00:50 +02:00
|
|
|
case VT_UI2:
|
|
|
|
V_UI2( ret ) = val;
|
2012-10-10 12:03:10 +02:00
|
|
|
break;
|
2012-07-02 16:00:50 +02:00
|
|
|
case VT_I4:
|
|
|
|
V_I4( ret ) = val;
|
2012-10-10 12:03:10 +02:00
|
|
|
break;
|
2012-07-02 16:00:50 +02:00
|
|
|
case VT_UI4:
|
|
|
|
V_UI4( ret ) = val;
|
2012-10-10 12:03:10 +02:00
|
|
|
break;
|
2012-07-13 11:34:42 +02:00
|
|
|
case VT_NULL:
|
2012-10-10 12:03:10 +02:00
|
|
|
break;
|
2012-07-02 16:00:50 +02:00
|
|
|
default:
|
2012-10-10 12:03:10 +02:00
|
|
|
ERR("unhandled variant type %u\n", type);
|
2012-07-02 16:00:50 +02:00
|
|
|
return;
|
|
|
|
}
|
2012-10-10 12:03:10 +02:00
|
|
|
V_VT( ret ) = type;
|
2012-07-02 16:00:50 +02:00
|
|
|
}
|
|
|
|
|
2012-06-29 13:39:34 +02:00
|
|
|
HRESULT get_propval( const struct view *view, UINT index, const WCHAR *name, VARIANT *ret,
|
|
|
|
CIMTYPE *type, LONG *flavor )
|
2012-06-18 09:31:29 +02:00
|
|
|
{
|
|
|
|
HRESULT hr;
|
2012-12-18 11:20:53 +01:00
|
|
|
UINT column, row;
|
2012-07-02 16:00:50 +02:00
|
|
|
VARTYPE vartype;
|
2012-10-10 12:03:10 +02:00
|
|
|
void *val_ptr = NULL;
|
2012-06-27 11:34:23 +02:00
|
|
|
LONGLONG val;
|
2012-06-18 09:31:29 +02:00
|
|
|
|
2012-06-29 13:39:34 +02:00
|
|
|
if (is_system_prop( name )) return get_system_propval( view, index, name, ret, type, flavor );
|
2013-01-25 17:33:24 +01:00
|
|
|
if (!view->count || !is_selected_prop( view, name )) return WBEM_E_NOT_FOUND;
|
2012-06-18 09:31:29 +02:00
|
|
|
|
|
|
|
hr = get_column_index( view->table, name, &column );
|
2012-07-13 11:35:09 +02:00
|
|
|
if (hr != S_OK || is_method( view->table, column )) return WBEM_E_NOT_FOUND;
|
2012-06-18 09:31:29 +02:00
|
|
|
|
2012-12-18 11:20:53 +01:00
|
|
|
row = view->result[index];
|
2012-06-18 09:31:29 +02:00
|
|
|
hr = get_value( view->table, row, column, &val );
|
|
|
|
if (hr != S_OK) return hr;
|
|
|
|
|
2012-12-18 11:20:53 +01:00
|
|
|
vartype = view->table->columns[column].vartype;
|
2012-10-10 12:03:10 +02:00
|
|
|
if (view->table->columns[column].type & CIM_FLAG_ARRAY)
|
|
|
|
{
|
|
|
|
CIMTYPE basetype = view->table->columns[column].type & CIM_TYPE_MASK;
|
|
|
|
|
|
|
|
val_ptr = to_safearray( (const struct array *)(INT_PTR)val, basetype );
|
|
|
|
if (!vartype) vartype = to_vartype( basetype ) | VT_ARRAY;
|
|
|
|
goto done;
|
|
|
|
}
|
2012-06-19 10:21:12 +02:00
|
|
|
switch (view->table->columns[column].type & COL_TYPE_MASK)
|
2012-06-18 09:31:29 +02:00
|
|
|
{
|
2012-07-30 15:04:03 +02:00
|
|
|
case CIM_BOOLEAN:
|
|
|
|
if (!vartype) vartype = VT_BOOL;
|
|
|
|
break;
|
2012-06-18 09:31:29 +02:00
|
|
|
case CIM_STRING:
|
|
|
|
case CIM_DATETIME:
|
2012-07-13 11:34:42 +02:00
|
|
|
if (val)
|
|
|
|
{
|
|
|
|
vartype = VT_BSTR;
|
2012-10-10 12:03:10 +02:00
|
|
|
val_ptr = SysAllocString( (const WCHAR *)(INT_PTR)val );
|
2012-07-13 11:34:42 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
vartype = VT_NULL;
|
2012-06-18 09:31:29 +02:00
|
|
|
break;
|
2014-08-04 23:29:16 +02:00
|
|
|
case CIM_SINT8:
|
|
|
|
if (!vartype) vartype = VT_I1;
|
|
|
|
break;
|
|
|
|
case CIM_UINT8:
|
|
|
|
if (!vartype) vartype = VT_UI1;
|
|
|
|
break;
|
2012-06-22 09:23:20 +02:00
|
|
|
case CIM_SINT16:
|
2012-07-02 16:00:50 +02:00
|
|
|
if (!vartype) vartype = VT_I2;
|
2012-06-22 09:23:20 +02:00
|
|
|
break;
|
|
|
|
case CIM_UINT16:
|
2012-07-02 16:00:50 +02:00
|
|
|
if (!vartype) vartype = VT_UI2;
|
2012-06-22 09:23:20 +02:00
|
|
|
break;
|
|
|
|
case CIM_SINT32:
|
2012-07-02 16:00:50 +02:00
|
|
|
if (!vartype) vartype = VT_I4;
|
2012-06-22 09:23:20 +02:00
|
|
|
break;
|
|
|
|
case CIM_UINT32:
|
2012-07-02 16:00:50 +02:00
|
|
|
if (!vartype) vartype = VT_UI4;
|
2012-06-22 09:23:20 +02:00
|
|
|
break;
|
2012-06-27 11:34:23 +02:00
|
|
|
case CIM_SINT64:
|
2012-07-02 16:00:50 +02:00
|
|
|
vartype = VT_BSTR;
|
2012-10-10 12:03:10 +02:00
|
|
|
val_ptr = get_value_bstr( view->table, row, column );
|
2012-06-27 11:34:23 +02:00
|
|
|
break;
|
|
|
|
case CIM_UINT64:
|
2012-07-02 16:00:50 +02:00
|
|
|
vartype = VT_BSTR;
|
2012-10-10 12:03:10 +02:00
|
|
|
val_ptr = get_value_bstr( view->table, row, column );
|
2012-06-27 11:34:23 +02:00
|
|
|
break;
|
2012-06-18 09:31:29 +02:00
|
|
|
default:
|
|
|
|
ERR("unhandled column type %u\n", view->table->columns[column].type);
|
|
|
|
return WBEM_E_FAILED;
|
|
|
|
}
|
2012-10-10 12:03:10 +02:00
|
|
|
|
|
|
|
done:
|
|
|
|
set_variant( vartype, val, val_ptr, ret );
|
2012-06-19 10:21:12 +02:00
|
|
|
if (type) *type = view->table->columns[column].type & COL_TYPE_MASK;
|
2012-06-29 13:39:34 +02:00
|
|
|
if (flavor) *flavor = 0;
|
2012-06-18 09:31:29 +02:00
|
|
|
return S_OK;
|
|
|
|
}
|
2012-06-19 10:19:38 +02:00
|
|
|
|
2012-10-10 12:03:10 +02:00
|
|
|
static CIMTYPE to_cimtype( VARTYPE type )
|
|
|
|
{
|
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case VT_BOOL: return CIM_BOOLEAN;
|
|
|
|
case VT_BSTR: return CIM_STRING;
|
2014-08-04 23:29:16 +02:00
|
|
|
case VT_I1: return CIM_SINT8;
|
|
|
|
case VT_UI1: return CIM_UINT8;
|
2012-10-10 12:03:10 +02:00
|
|
|
case VT_I2: return CIM_SINT16;
|
|
|
|
case VT_UI2: return CIM_UINT16;
|
|
|
|
case VT_I4: return CIM_SINT32;
|
|
|
|
case VT_UI4: return CIM_UINT32;
|
|
|
|
case VT_I8: return CIM_SINT64;
|
|
|
|
case VT_UI8: return CIM_UINT64;
|
|
|
|
default:
|
|
|
|
ERR("unhandled type %u\n", type);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct array *to_array( VARIANT *var, CIMTYPE *type )
|
|
|
|
{
|
|
|
|
struct array *ret;
|
|
|
|
LONG bound, i;
|
|
|
|
VARTYPE vartype;
|
|
|
|
CIMTYPE basetype;
|
|
|
|
UINT size;
|
|
|
|
|
|
|
|
if (SafeArrayGetVartype( V_ARRAY( var ), &vartype ) != S_OK) return NULL;
|
|
|
|
if (!(basetype = to_cimtype( vartype ))) return NULL;
|
|
|
|
if (SafeArrayGetUBound( V_ARRAY( var ), 1, &bound ) != S_OK) return NULL;
|
|
|
|
if (!(ret = heap_alloc( sizeof(struct array) ))) return NULL;
|
|
|
|
|
|
|
|
ret->count = bound + 1;
|
|
|
|
size = get_type_size( basetype );
|
2012-10-12 14:25:13 +02:00
|
|
|
if (!(ret->ptr = heap_alloc_zero( ret->count * size )))
|
2012-10-10 12:03:10 +02:00
|
|
|
{
|
|
|
|
heap_free( ret );
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
for (i = 0; i < ret->count; i++)
|
|
|
|
{
|
2012-10-12 14:25:13 +02:00
|
|
|
void *ptr = (char *)ret->ptr + i * size;
|
|
|
|
if (vartype == VT_BSTR)
|
|
|
|
{
|
|
|
|
BSTR str;
|
|
|
|
if (SafeArrayGetElement( V_ARRAY( var ), &i, &str ) != S_OK)
|
|
|
|
{
|
|
|
|
destroy_array( ret, basetype );
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
*(WCHAR **)ptr = heap_strdupW( str );
|
|
|
|
SysFreeString( str );
|
|
|
|
if (!*(WCHAR **)ptr)
|
|
|
|
{
|
|
|
|
destroy_array( ret, basetype );
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (SafeArrayGetElement( V_ARRAY( var ), &i, ptr ) != S_OK)
|
2012-10-10 12:03:10 +02:00
|
|
|
{
|
2012-10-12 14:25:13 +02:00
|
|
|
destroy_array( ret, basetype );
|
2012-10-10 12:03:10 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*type = basetype | CIM_FLAG_ARRAY;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT to_longlong( VARIANT *var, LONGLONG *val, CIMTYPE *type )
|
2012-07-25 13:12:10 +02:00
|
|
|
{
|
|
|
|
if (!var)
|
|
|
|
{
|
|
|
|
*val = 0;
|
|
|
|
return S_OK;
|
|
|
|
}
|
2012-10-10 12:03:10 +02:00
|
|
|
if (V_VT( var ) & VT_ARRAY)
|
|
|
|
{
|
|
|
|
*val = (INT_PTR)to_array( var, type );
|
|
|
|
if (!*val) return E_OUTOFMEMORY;
|
|
|
|
return S_OK;
|
|
|
|
}
|
2012-07-25 13:12:10 +02:00
|
|
|
switch (V_VT( var ))
|
|
|
|
{
|
2012-07-30 15:04:03 +02:00
|
|
|
case VT_BOOL:
|
|
|
|
*val = V_BOOL( var );
|
|
|
|
*type = CIM_BOOLEAN;
|
|
|
|
break;
|
2012-07-25 13:12:10 +02:00
|
|
|
case VT_BSTR:
|
2012-10-12 14:25:13 +02:00
|
|
|
*val = (INT_PTR)heap_strdupW( V_BSTR( var ) );
|
2012-07-25 13:12:10 +02:00
|
|
|
if (!*val) return E_OUTOFMEMORY;
|
|
|
|
*type = CIM_STRING;
|
|
|
|
break;
|
|
|
|
case VT_I2:
|
|
|
|
*val = V_I2( var );
|
|
|
|
*type = CIM_SINT16;
|
|
|
|
break;
|
|
|
|
case VT_UI2:
|
|
|
|
*val = V_UI2( var );
|
|
|
|
*type = CIM_UINT16;
|
|
|
|
break;
|
|
|
|
case VT_I4:
|
|
|
|
*val = V_I4( var );
|
|
|
|
*type = CIM_SINT32;
|
|
|
|
break;
|
|
|
|
case VT_UI4:
|
|
|
|
*val = V_UI4( var );
|
|
|
|
*type = CIM_UINT32;
|
|
|
|
break;
|
|
|
|
case VT_NULL:
|
|
|
|
*val = 0;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
ERR("unhandled type %u\n", V_VT( var ));
|
|
|
|
return WBEM_E_FAILED;
|
|
|
|
}
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT put_propval( const struct view *view, UINT index, const WCHAR *name, VARIANT *var, CIMTYPE type )
|
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
UINT column, row = view->result[index];
|
|
|
|
LONGLONG val;
|
|
|
|
|
|
|
|
hr = get_column_index( view->table, name, &column );
|
|
|
|
if (hr != S_OK)
|
|
|
|
{
|
|
|
|
FIXME("no support for creating new properties\n");
|
|
|
|
return WBEM_E_FAILED;
|
|
|
|
}
|
|
|
|
if (is_method( view->table, column ) || !(view->table->columns[column].type & COL_FLAG_DYNAMIC))
|
|
|
|
return WBEM_E_FAILED;
|
|
|
|
|
2012-10-10 12:03:10 +02:00
|
|
|
hr = to_longlong( var, &val, &type );
|
2012-07-25 13:12:10 +02:00
|
|
|
if (hr != S_OK) return hr;
|
|
|
|
|
|
|
|
return set_value( view->table, row, column, val, type );
|
|
|
|
}
|
|
|
|
|
2014-03-24 11:42:00 +01:00
|
|
|
HRESULT get_properties( const struct view *view, LONG flags, SAFEARRAY **props )
|
2012-06-19 10:19:38 +02:00
|
|
|
{
|
|
|
|
SAFEARRAY *sa;
|
|
|
|
BSTR str;
|
2014-05-13 13:41:35 +02:00
|
|
|
UINT i, num_props = count_selected_properties( view );
|
|
|
|
LONG j;
|
2012-06-19 10:19:38 +02:00
|
|
|
|
2012-07-13 11:35:09 +02:00
|
|
|
if (!(sa = SafeArrayCreateVector( VT_BSTR, 0, num_props ))) return E_OUTOFMEMORY;
|
2012-06-19 10:19:38 +02:00
|
|
|
|
2014-05-13 13:41:35 +02:00
|
|
|
for (i = 0, j = 0; i < view->table->num_cols; i++)
|
2012-06-19 10:19:38 +02:00
|
|
|
{
|
2014-03-24 11:42:00 +01:00
|
|
|
BOOL is_system;
|
|
|
|
|
2012-07-13 11:35:09 +02:00
|
|
|
if (is_method( view->table, i )) continue;
|
2014-04-30 10:18:39 +02:00
|
|
|
if (!is_selected_prop( view, view->table->columns[i].name )) continue;
|
2012-07-13 11:35:09 +02:00
|
|
|
|
2014-03-24 11:42:00 +01:00
|
|
|
is_system = is_system_prop( view->table->columns[i].name );
|
|
|
|
if ((flags & WBEM_FLAG_NONSYSTEM_ONLY) && is_system) continue;
|
|
|
|
else if ((flags & WBEM_FLAG_SYSTEM_ONLY) && !is_system) continue;
|
|
|
|
|
2012-06-19 10:19:38 +02:00
|
|
|
str = SysAllocString( view->table->columns[i].name );
|
2014-05-13 13:41:35 +02:00
|
|
|
if (!str || SafeArrayPutElement( sa, &j, str ) != S_OK)
|
2012-06-19 10:19:38 +02:00
|
|
|
{
|
|
|
|
SysFreeString( str );
|
|
|
|
SafeArrayDestroy( sa );
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
}
|
2015-04-22 12:13:55 +02:00
|
|
|
SysFreeString( str );
|
2014-05-13 13:41:35 +02:00
|
|
|
j++;
|
2012-06-19 10:19:38 +02:00
|
|
|
}
|
|
|
|
*props = sa;
|
|
|
|
return S_OK;
|
|
|
|
}
|