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 <stdarg.h>
|
|
|
|
|
|
|
|
#include "windef.h"
|
|
|
|
#include "winbase.h"
|
|
|
|
#include "wbemcli.h"
|
|
|
|
|
|
|
|
#include "wine/debug.h"
|
|
|
|
#include "wbemprox_private.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(wbemprox);
|
|
|
|
|
2019-09-10 17:09:14 +02:00
|
|
|
static HRESULT append_table( struct view *view, struct table *table )
|
|
|
|
{
|
|
|
|
struct table **tmp;
|
|
|
|
if (!(tmp = heap_realloc( view->table, (view->table_count + 1) * sizeof(*tmp) ))) return E_OUTOFMEMORY;
|
|
|
|
view->table = tmp;
|
|
|
|
view->table[view->table_count++] = table;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT create_view( enum view_type type, const WCHAR *path, const struct keyword *keywordlist, const WCHAR *class,
|
2019-06-24 15:15:35 +02:00
|
|
|
const struct property *proplist, const struct expr *cond, struct view **ret )
|
2012-06-18 09:32:02 +02:00
|
|
|
{
|
2019-06-24 15:15:35 +02:00
|
|
|
struct view *view = heap_alloc_zero( sizeof(*view) );
|
2012-06-18 09:32:02 +02:00
|
|
|
|
|
|
|
if (!view) return E_OUTOFMEMORY;
|
2019-09-10 17:09:14 +02:00
|
|
|
|
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case VIEW_TYPE_ASSOCIATORS:
|
|
|
|
view->path = path;
|
|
|
|
view->keywordlist = keywordlist;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case VIEW_TYPE_SELECT:
|
|
|
|
{
|
|
|
|
struct table *table = grab_table( class );
|
|
|
|
HRESULT hr;
|
|
|
|
|
2019-10-04 21:58:42 +02:00
|
|
|
if (table && (hr = append_table( view, table )) != S_OK)
|
|
|
|
{
|
|
|
|
heap_free( view );
|
|
|
|
return hr;
|
|
|
|
}
|
2019-09-10 17:09:14 +02:00
|
|
|
view->proplist = proplist;
|
|
|
|
view->cond = cond;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
ERR( "unhandled type %u\n", type );
|
|
|
|
heap_free( view );
|
|
|
|
return E_INVALIDARG;
|
|
|
|
}
|
|
|
|
|
|
|
|
view->type = type;
|
2012-06-18 09:32:02 +02:00
|
|
|
*ret = view;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void destroy_view( struct view *view )
|
|
|
|
{
|
2019-09-10 17:09:14 +02:00
|
|
|
ULONG i;
|
2013-02-25 11:03:33 +01:00
|
|
|
if (!view) return;
|
2019-09-10 17:09:14 +02:00
|
|
|
for (i = 0; i < view->table_count; i++) release_table( view->table[i] );
|
|
|
|
heap_free( 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;
|
2019-07-04 09:27:39 +02:00
|
|
|
while (*p && *q && towupper( *p ) == towupper( *q )) { p++; q++; };
|
2015-08-14 14:58:13 +02:00
|
|
|
if (!*p && !*q) return TRUE;
|
2012-06-15 15:47:54 +02:00
|
|
|
}
|
2019-07-04 09:27:39 +02:00
|
|
|
if (*q != '%' && towupper( *p++ ) != towupper( *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:
|
2019-07-04 09:27:39 +02:00
|
|
|
*val = !wcscmp( lstr, rstr );
|
2012-07-11 14:02:16 +02:00
|
|
|
break;
|
|
|
|
case OP_GT:
|
2019-07-04 09:27:39 +02:00
|
|
|
*val = wcscmp( lstr, rstr ) > 0;
|
2012-07-11 14:02:16 +02:00
|
|
|
break;
|
|
|
|
case OP_LT:
|
2019-07-04 09:27:39 +02:00
|
|
|
*val = wcscmp( lstr, rstr ) < 0;
|
2012-07-11 14:02:16 +02:00
|
|
|
break;
|
|
|
|
case OP_LE:
|
2019-07-04 09:27:39 +02:00
|
|
|
*val = wcscmp( lstr, rstr ) <= 0;
|
2012-07-11 14:02:16 +02:00
|
|
|
break;
|
|
|
|
case OP_GE:
|
2019-07-04 09:27:39 +02:00
|
|
|
*val = wcscmp( lstr, rstr ) >= 0;
|
2012-07-11 14:02:16 +02:00
|
|
|
break;
|
|
|
|
case OP_NE:
|
2019-07-04 09:27:39 +02:00
|
|
|
*val = wcscmp( lstr, rstr );
|
2012-07-11 14:02:16 +02:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2015-12-23 11:07:36 +01:00
|
|
|
static BOOL is_int( CIMTYPE type )
|
2012-07-11 14:02:16 +02:00
|
|
|
{
|
2015-12-23 11:07:36 +01:00
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
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 TRUE;
|
|
|
|
default:
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline BOOL is_strcmp( const struct complex_expr *expr, UINT ltype, UINT rtype )
|
|
|
|
{
|
|
|
|
if ((ltype == CIM_STRING || is_int( ltype )) && expr->left->type == EXPR_PROPVAL &&
|
|
|
|
expr->right->type == EXPR_SVAL) return TRUE;
|
|
|
|
else if ((rtype == CIM_STRING || is_int( rtype )) && expr->right->type == EXPR_PROPVAL &&
|
|
|
|
expr->left->type == EXPR_SVAL) return TRUE;
|
|
|
|
return FALSE;
|
2012-07-11 14:02:16 +02:00
|
|
|
}
|
|
|
|
|
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 )
|
|
|
|
{
|
2020-04-20 10:38:10 +02:00
|
|
|
if (ltype == CIM_STRING) lval = !wcsicmp( (const WCHAR *)(INT_PTR)lval, L"True" ) ? -1 : 0;
|
|
|
|
else if (rtype == CIM_STRING) rval = !wcsicmp( (const WCHAR *)(INT_PTR)rval, L"True" ) ? -1 : 0;
|
2014-01-28 13:26:16 +01:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2019-09-10 17:09:09 +02:00
|
|
|
static inline BOOL is_refcmp( const struct complex_expr *expr, UINT ltype, UINT rtype )
|
|
|
|
{
|
|
|
|
if (ltype == CIM_REFERENCE && expr->left->type == EXPR_PROPVAL && expr->right->type == EXPR_SVAL) return TRUE;
|
|
|
|
else if (rtype == CIM_REFERENCE && expr->right->type == EXPR_PROPVAL && expr->left->type == EXPR_SVAL) return TRUE;
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT eval_refcmp( UINT op, const WCHAR *lstr, const WCHAR *rstr, LONGLONG *val )
|
|
|
|
{
|
|
|
|
if (!lstr || !rstr)
|
|
|
|
{
|
|
|
|
*val = 0;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
switch (op)
|
|
|
|
{
|
|
|
|
case OP_EQ:
|
|
|
|
*val = !wcsicmp( lstr, rstr );
|
|
|
|
break;
|
|
|
|
case OP_NE:
|
|
|
|
*val = wcsicmp( lstr, rstr );
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
ERR("unhandled operator %u\n", op);
|
|
|
|
return WBEM_E_INVALID_QUERY;
|
|
|
|
}
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2014-01-28 13:26:16 +01:00
|
|
|
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;
|
|
|
|
|
2019-09-10 17:09:09 +02:00
|
|
|
case CIM_REFERENCE:
|
|
|
|
if (right == CIM_REFERENCE) return CIM_REFERENCE;
|
|
|
|
break;
|
|
|
|
|
2014-01-28 13:26:16 +01:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return CIM_ILLEGAL;
|
|
|
|
}
|
|
|
|
|
2019-07-04 09:27:39 +02:00
|
|
|
static const WCHAR *format_int( WCHAR *buf, UINT len, CIMTYPE type, LONGLONG val )
|
2015-12-23 11:07:36 +01:00
|
|
|
{
|
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case CIM_SINT8:
|
|
|
|
case CIM_SINT16:
|
|
|
|
case CIM_SINT32:
|
2020-04-20 10:38:10 +02:00
|
|
|
swprintf( buf, len, L"%d", val );
|
2015-12-23 11:07:36 +01:00
|
|
|
return buf;
|
|
|
|
|
|
|
|
case CIM_UINT8:
|
|
|
|
case CIM_UINT16:
|
|
|
|
case CIM_UINT32:
|
2020-04-20 10:38:10 +02:00
|
|
|
swprintf( buf, len, L"%u", val );
|
2015-12-23 11:07:36 +01:00
|
|
|
return buf;
|
|
|
|
|
|
|
|
case CIM_SINT64:
|
2020-04-20 10:38:10 +02:00
|
|
|
wsprintfW( buf, L"%I64d", val );
|
2015-12-23 11:07:36 +01:00
|
|
|
return buf;
|
|
|
|
|
|
|
|
case CIM_UINT64:
|
2020-04-20 10:38:10 +02:00
|
|
|
wsprintfW( buf, L"%I64u", val );
|
2015-12-23 11:07:36 +01:00
|
|
|
return buf;
|
|
|
|
|
|
|
|
default:
|
|
|
|
ERR( "unhandled type %u\n", type );
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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 );
|
|
|
|
|
2015-12-23 11:07:36 +01:00
|
|
|
if (is_strcmp( expr, ltype, rtype ))
|
2012-07-11 14:02:16 +02:00
|
|
|
{
|
2015-12-23 11:07:36 +01:00
|
|
|
const WCHAR *lstr, *rstr;
|
|
|
|
WCHAR lbuf[21], rbuf[21];
|
|
|
|
|
2019-07-04 09:27:39 +02:00
|
|
|
if (is_int( ltype )) lstr = format_int( lbuf, ARRAY_SIZE( lbuf ), ltype, lval );
|
2015-12-23 11:07:36 +01:00
|
|
|
else lstr = (const WCHAR *)(INT_PTR)lval;
|
|
|
|
|
2019-07-04 09:27:39 +02:00
|
|
|
if (is_int( rtype )) rstr = format_int( rbuf, ARRAY_SIZE( rbuf ), rtype, rval );
|
2015-12-23 11:07:36 +01:00
|
|
|
else rstr = (const WCHAR *)(INT_PTR)rval;
|
2012-07-11 14:02:16 +02:00
|
|
|
|
|
|
|
return eval_strcmp( expr->op, lstr, rstr, val );
|
|
|
|
}
|
2019-09-10 17:09:09 +02:00
|
|
|
if (is_boolcmp( expr, ltype, rtype ))
|
|
|
|
{
|
|
|
|
return eval_boolcmp( expr->op, lval, rval, ltype, rtype, val );
|
|
|
|
}
|
|
|
|
if (is_refcmp( expr, ltype, rtype ))
|
|
|
|
{
|
|
|
|
return eval_refcmp( expr->op, (const WCHAR *)(INT_PTR)lval, (const WCHAR *)(INT_PTR)rval, 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;
|
|
|
|
}
|
|
|
|
|
2019-09-10 17:09:14 +02:00
|
|
|
static WCHAR *build_assoc_query( const WCHAR *class, UINT class_len )
|
|
|
|
{
|
2020-04-20 10:38:10 +02:00
|
|
|
static const WCHAR fmtW[] = L"SELECT * FROM __ASSOCIATORS WHERE Class='%s'";
|
2019-09-10 17:09:14 +02:00
|
|
|
UINT len = class_len + ARRAY_SIZE(fmtW);
|
|
|
|
WCHAR *ret;
|
|
|
|
|
|
|
|
if (!(ret = heap_alloc( len * sizeof(WCHAR) ))) return NULL;
|
|
|
|
swprintf( ret, len, fmtW, class );
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT create_assoc_enum( const WCHAR *class, UINT class_len, IEnumWbemClassObject **iter )
|
|
|
|
{
|
|
|
|
WCHAR *query;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
if (!(query = build_assoc_query( class, class_len ))) return E_OUTOFMEMORY;
|
|
|
|
hr = exec_query( query, iter );
|
|
|
|
heap_free( query );
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
static WCHAR *build_antecedent_query( const WCHAR *assocclass, const WCHAR *dependent )
|
|
|
|
{
|
2020-04-20 10:38:10 +02:00
|
|
|
static const WCHAR fmtW[] = L"SELECT Antecedent FROM %s WHERE Dependent='%s'";
|
2019-09-10 17:09:14 +02:00
|
|
|
UINT len = lstrlenW(assocclass) + lstrlenW(dependent) + ARRAY_SIZE(fmtW);
|
|
|
|
WCHAR *ret;
|
|
|
|
|
|
|
|
if (!(ret = heap_alloc( len * sizeof(WCHAR) ))) return NULL;
|
|
|
|
swprintf( ret, len, fmtW, assocclass, dependent );
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static BSTR build_servername(void)
|
|
|
|
{
|
|
|
|
WCHAR server[MAX_COMPUTERNAME_LENGTH + 1], *p;
|
|
|
|
DWORD len = ARRAY_SIZE( server );
|
|
|
|
|
|
|
|
if (!(GetComputerNameW( server, &len ))) return NULL;
|
|
|
|
for (p = server; *p; p++) *p = towupper( *p );
|
|
|
|
return SysAllocString( server );
|
|
|
|
}
|
|
|
|
|
|
|
|
static BSTR build_namespace(void)
|
|
|
|
{
|
2020-04-20 10:38:10 +02:00
|
|
|
return SysAllocString( L"ROOT\\CIMV2" );
|
2019-09-10 17:09:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static WCHAR *build_canonical_path( const WCHAR *relpath )
|
|
|
|
{
|
|
|
|
BSTR server, namespace;
|
|
|
|
WCHAR *ret;
|
|
|
|
UINT len, i;
|
|
|
|
|
|
|
|
if (!(server = build_servername())) return NULL;
|
|
|
|
if (!(namespace = build_namespace()))
|
|
|
|
{
|
|
|
|
SysFreeString( server );
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2020-04-20 10:38:10 +02:00
|
|
|
len = ARRAY_SIZE( L"\\\\%s\\%s:" ) + SysStringLen( server ) + SysStringLen( namespace ) + lstrlenW( relpath );
|
2019-09-10 17:09:14 +02:00
|
|
|
if ((ret = heap_alloc( len * sizeof(WCHAR ) )))
|
|
|
|
{
|
2020-04-20 10:38:10 +02:00
|
|
|
len = swprintf( ret, len, L"\\\\%s\\%s:", server, namespace );
|
2019-09-10 17:09:14 +02:00
|
|
|
for (i = 0; i < lstrlenW( relpath ); i ++)
|
|
|
|
{
|
|
|
|
if (relpath[i] == '\'') ret[len++] = '"';
|
|
|
|
else ret[len++] = relpath[i];
|
|
|
|
}
|
|
|
|
ret[len] = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
SysFreeString( server );
|
|
|
|
SysFreeString( namespace );
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT get_antecedent( const WCHAR *assocclass, const WCHAR *dependent, BSTR *ret )
|
|
|
|
{
|
|
|
|
WCHAR *fullpath, *str;
|
|
|
|
IEnumWbemClassObject *iter = NULL;
|
|
|
|
IWbemClassObject *obj;
|
|
|
|
HRESULT hr = E_OUTOFMEMORY;
|
|
|
|
ULONG count;
|
|
|
|
VARIANT var;
|
|
|
|
|
|
|
|
if (!(fullpath = build_canonical_path( dependent ))) return E_OUTOFMEMORY;
|
|
|
|
if (!(str = build_antecedent_query( assocclass, fullpath ))) goto done;
|
|
|
|
if ((hr = exec_query( str, &iter )) != S_OK) goto done;
|
|
|
|
|
|
|
|
IEnumWbemClassObject_Next( iter, WBEM_INFINITE, 1, &obj, &count );
|
|
|
|
if (!count)
|
|
|
|
{
|
|
|
|
*ret = NULL;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2020-04-20 10:38:10 +02:00
|
|
|
hr = IWbemClassObject_Get( obj, L"Antecedent", 0, &var, NULL, NULL );
|
2019-09-10 17:09:14 +02:00
|
|
|
IWbemClassObject_Release( obj );
|
|
|
|
if (hr != S_OK) goto done;
|
|
|
|
*ret = V_BSTR( &var );
|
|
|
|
|
|
|
|
done:
|
|
|
|
if (iter) IEnumWbemClassObject_Release( iter );
|
|
|
|
heap_free( str );
|
|
|
|
heap_free( fullpath );
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT do_query( const WCHAR *str, struct query **ret_query )
|
|
|
|
{
|
|
|
|
struct query *query;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
if (!(query = create_query())) return E_OUTOFMEMORY;
|
|
|
|
if ((hr = parse_query( str, &query->view, &query->mem )) != S_OK || (hr = execute_view( query->view )) != S_OK)
|
|
|
|
{
|
|
|
|
release_query( query );
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
*ret_query = query;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT get_antecedent_table( const WCHAR *assocclass, const WCHAR *dependent, struct table **table )
|
|
|
|
{
|
|
|
|
BSTR antecedent = NULL;
|
|
|
|
struct path *path = NULL;
|
|
|
|
WCHAR *str = NULL;
|
|
|
|
struct query *query = NULL;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
if ((hr = get_antecedent( assocclass, dependent, &antecedent )) != S_OK) return hr;
|
|
|
|
if (!antecedent)
|
|
|
|
{
|
|
|
|
*table = NULL;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
if ((hr = parse_path( antecedent, &path )) != S_OK) goto done;
|
|
|
|
if (!(str = query_from_path( path )))
|
|
|
|
{
|
|
|
|
hr = E_OUTOFMEMORY;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((hr = do_query( str, &query )) != S_OK) goto done;
|
|
|
|
if (query->view->table_count) *table = addref_table( query->view->table[0] );
|
|
|
|
else *table = NULL;
|
|
|
|
|
|
|
|
done:
|
|
|
|
if (query) release_query( query );
|
|
|
|
free_path( path );
|
|
|
|
SysFreeString( antecedent );
|
2019-10-04 21:58:39 +02:00
|
|
|
heap_free( str );
|
2019-09-10 17:09:14 +02:00
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT exec_assoc_view( struct view *view )
|
|
|
|
{
|
|
|
|
IEnumWbemClassObject *iter = NULL;
|
|
|
|
struct path *path;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
if (view->keywordlist) FIXME( "ignoring keywords\n" );
|
|
|
|
if ((hr = parse_path( view->path, &path )) != S_OK) return hr;
|
|
|
|
|
|
|
|
if ((hr = create_assoc_enum( path->class, path->class_len, &iter )) != S_OK) goto done;
|
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
ULONG count;
|
|
|
|
IWbemClassObject *obj;
|
|
|
|
struct table *table;
|
|
|
|
VARIANT var;
|
|
|
|
|
|
|
|
IEnumWbemClassObject_Next( iter, WBEM_INFINITE, 1, &obj, &count );
|
|
|
|
if (!count) break;
|
|
|
|
|
2020-04-20 10:38:10 +02:00
|
|
|
if ((hr = IWbemClassObject_Get( obj, L"AssocClass", 0, &var, NULL, NULL )) != S_OK)
|
2019-09-10 17:09:14 +02:00
|
|
|
{
|
|
|
|
IWbemClassObject_Release( obj );
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
IWbemClassObject_Release( obj );
|
|
|
|
|
|
|
|
hr = get_antecedent_table( V_BSTR(&var), view->path, &table );
|
|
|
|
VariantClear( &var );
|
|
|
|
if (hr != S_OK) goto done;
|
|
|
|
|
|
|
|
if (table && (hr = append_table( view, table )) != S_OK)
|
|
|
|
{
|
|
|
|
release_table( table );
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (view->table_count)
|
|
|
|
{
|
|
|
|
if (!(view->result = heap_alloc_zero( view->table_count * sizeof(UINT) ))) hr = E_OUTOFMEMORY;
|
|
|
|
else view->result_count = view->table_count;
|
|
|
|
}
|
|
|
|
|
|
|
|
done:
|
|
|
|
if (iter) IEnumWbemClassObject_Release( iter );
|
|
|
|
free_path( path );
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT exec_select_view( struct view *view )
|
2012-06-15 15:47:54 +02:00
|
|
|
{
|
|
|
|
UINT i, j = 0, len;
|
2019-08-28 14:14:26 +02:00
|
|
|
enum fill_status status = FILL_STATUS_UNFILTERED;
|
2019-09-10 17:09:14 +02:00
|
|
|
struct table *table;
|
2012-06-15 15:47:54 +02:00
|
|
|
|
2019-09-10 17:09:14 +02:00
|
|
|
if (!view->table_count) return S_OK;
|
|
|
|
|
|
|
|
table = view->table[0];
|
|
|
|
if (table->fill)
|
2013-05-22 10:08:17 +02:00
|
|
|
{
|
2019-09-10 17:09:14 +02:00
|
|
|
clear_table( table );
|
|
|
|
status = table->fill( table, view->cond );
|
2013-05-22 10:08:17 +02:00
|
|
|
}
|
2019-08-28 14:14:26 +02:00
|
|
|
if (status == FILL_STATUS_FAILED) return WBEM_E_FAILED;
|
2019-09-10 17:09:14 +02:00
|
|
|
if (!table->num_rows) return S_OK;
|
2012-06-15 15:47:54 +02:00
|
|
|
|
2019-09-10 17:09:14 +02:00
|
|
|
len = min( table->num_rows, 16 );
|
2012-06-15 15:47:54 +02:00
|
|
|
if (!(view->result = heap_alloc( len * sizeof(UINT) ))) return E_OUTOFMEMORY;
|
|
|
|
|
2019-09-10 17:09:14 +02:00
|
|
|
for (i = 0; i < table->num_rows; i++)
|
2012-06-15 15:47:54 +02:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
2019-08-28 14:14:26 +02:00
|
|
|
if (status == FILL_STATUS_FILTERED) val = 1;
|
2019-09-10 17:09:14 +02:00
|
|
|
else if ((hr = eval_cond( table, i, view->cond, &val, &type )) != S_OK) return hr;
|
2012-06-15 15:47:54 +02:00
|
|
|
if (val) view->result[j++] = i;
|
|
|
|
}
|
2019-09-10 17:09:14 +02:00
|
|
|
|
|
|
|
view->result_count = j;
|
2012-06-15 15:47:54 +02:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2019-09-10 17:09:14 +02:00
|
|
|
HRESULT execute_view( struct view *view )
|
|
|
|
{
|
|
|
|
switch (view->type)
|
|
|
|
{
|
|
|
|
case VIEW_TYPE_ASSOCIATORS:
|
|
|
|
return exec_assoc_view( view );
|
|
|
|
|
|
|
|
case VIEW_TYPE_SELECT:
|
|
|
|
return exec_select_view( view );
|
|
|
|
|
|
|
|
default:
|
|
|
|
ERR( "unhandled type %u\n", view->type );
|
|
|
|
return E_INVALIDARG;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2019-09-10 17:09:14 +02:00
|
|
|
BOOL is_result_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)
|
|
|
|
{
|
2019-07-04 09:27:39 +02:00
|
|
|
if (!wcsicmp( prop->name, name )) return TRUE;
|
2012-06-18 09:31:29 +02:00
|
|
|
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] == '_');
|
|
|
|
}
|
|
|
|
|
2019-09-10 17:09:14 +02:00
|
|
|
static BSTR build_proplist( const struct table *table, UINT row, UINT count, UINT *len )
|
2012-06-20 12:06:40 +02:00
|
|
|
{
|
2019-09-10 17:09:14 +02:00
|
|
|
UINT i, j, offset;
|
2012-06-20 12:06:40 +02:00
|
|
|
BSTR *values, ret = NULL;
|
|
|
|
|
|
|
|
if (!(values = heap_alloc( count * sizeof(BSTR) ))) return NULL;
|
|
|
|
|
|
|
|
*len = j = 0;
|
2019-09-10 17:09:14 +02:00
|
|
|
for (i = 0; i < table->num_cols; i++)
|
2012-06-20 12:06:40 +02:00
|
|
|
{
|
2019-09-10 17:09:14 +02:00
|
|
|
if (table->columns[i].type & COL_FLAG_KEY)
|
2012-06-20 12:06:40 +02:00
|
|
|
{
|
2019-09-10 17:09:14 +02:00
|
|
|
const WCHAR *name = table->columns[i].name;
|
|
|
|
values[j] = get_value_bstr( table, row, i );
|
2020-04-20 10:38:10 +02:00
|
|
|
*len += lstrlenW( L"%s=%s" ) + lstrlenW( name ) + lstrlenW( values[j] );
|
2012-06-20 12:06:40 +02:00
|
|
|
j++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ((ret = SysAllocStringLen( NULL, *len )))
|
|
|
|
{
|
|
|
|
offset = j = 0;
|
2019-09-10 17:09:14 +02:00
|
|
|
for (i = 0; i < table->num_cols; i++)
|
2012-06-20 12:06:40 +02:00
|
|
|
{
|
2019-09-10 17:09:14 +02:00
|
|
|
if (table->columns[i].type & COL_FLAG_KEY)
|
2012-06-20 12:06:40 +02:00
|
|
|
{
|
2019-09-10 17:09:14 +02:00
|
|
|
const WCHAR *name = table->columns[i].name;
|
2020-04-20 10:38:10 +02:00
|
|
|
offset += swprintf( ret + offset, *len - offset, L"%s=%s", name, values[j] );
|
2012-06-20 12:06:40 +02:00
|
|
|
if (j < count - 1) ret[offset++] = ',';
|
|
|
|
j++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (i = 0; i < count; i++) SysFreeString( values[i] );
|
|
|
|
heap_free( values );
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2019-09-10 17:09:14 +02:00
|
|
|
static UINT count_key_columns( const struct table *table )
|
2012-06-20 12:06:40 +02:00
|
|
|
{
|
|
|
|
UINT i, num_keys = 0;
|
|
|
|
|
2019-09-10 17:09:14 +02:00
|
|
|
for (i = 0; i < table->num_cols; i++)
|
2012-06-20 12:06:40 +02:00
|
|
|
{
|
2019-09-10 17:09:14 +02:00
|
|
|
if (table->columns[i].type & COL_FLAG_KEY) num_keys++;
|
2012-06-20 12:06:40 +02:00
|
|
|
}
|
|
|
|
return num_keys;
|
|
|
|
}
|
|
|
|
|
2019-09-10 17:09:14 +02:00
|
|
|
static BSTR build_relpath( const struct view *view, UINT table_index, UINT result_index, const WCHAR *name )
|
2012-06-20 12:05:59 +02:00
|
|
|
{
|
2012-06-20 12:06:40 +02:00
|
|
|
BSTR class, proplist, ret = NULL;
|
2019-09-10 17:09:14 +02:00
|
|
|
struct table *table = view->table[table_index];
|
|
|
|
UINT row = view->result[result_index];
|
2012-06-20 12:06:40 +02:00
|
|
|
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
|
|
|
|
2019-09-10 17:09:14 +02:00
|
|
|
if (!(class = SysAllocString( view->table[table_index]->name ))) return NULL;
|
|
|
|
if (!(num_keys = count_key_columns( table ))) return class;
|
|
|
|
if (!(proplist = build_proplist( table, row, num_keys, &len ))) goto done;
|
2012-06-20 12:06:40 +02:00
|
|
|
|
2020-04-20 10:38:10 +02:00
|
|
|
len += lstrlenW( L"%s.%s" ) + SysStringLen( class );
|
2012-06-20 12:06:40 +02:00
|
|
|
if (!(ret = SysAllocStringLen( NULL, len ))) goto done;
|
2020-04-20 10:38:10 +02:00
|
|
|
swprintf( ret, len, L"%s.%s", class, proplist );
|
2012-06-20 12:06:40 +02:00
|
|
|
|
|
|
|
done:
|
|
|
|
SysFreeString( class );
|
|
|
|
SysFreeString( proplist );
|
|
|
|
return ret;
|
2012-06-20 12:05:59 +02:00
|
|
|
}
|
|
|
|
|
2019-09-10 17:09:14 +02:00
|
|
|
static BSTR build_path( const struct view *view, UINT table_index, UINT result_index, const WCHAR *name )
|
2012-06-20 12:05:59 +02:00
|
|
|
{
|
|
|
|
BSTR server, namespace = NULL, relpath = NULL, ret = NULL;
|
|
|
|
UINT len;
|
|
|
|
|
|
|
|
if (view->proplist) return NULL;
|
|
|
|
|
2019-09-10 17:09:14 +02:00
|
|
|
if (!(server = build_servername())) return NULL;
|
|
|
|
if (!(namespace = build_namespace())) goto done;
|
|
|
|
if (!(relpath = build_relpath( view, table_index, result_index, name ))) goto done;
|
2012-06-20 12:05:59 +02:00
|
|
|
|
2020-04-20 10:38:10 +02:00
|
|
|
len = lstrlenW( L"\\\\%s\\%s:%s" ) + SysStringLen( server ) + SysStringLen( namespace ) + SysStringLen( relpath );
|
2012-06-20 12:05:59 +02:00
|
|
|
if (!(ret = SysAllocStringLen( NULL, len ))) goto done;
|
2020-04-20 10:38:10 +02:00
|
|
|
swprintf( ret, len, L"\\\\%s\\%s:%s", server, namespace, relpath );
|
2012-06-20 12:05:59 +02:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2019-09-10 17:09:14 +02:00
|
|
|
static UINT count_properties( const struct table *table )
|
2012-07-13 11:35:09 +02:00
|
|
|
{
|
|
|
|
UINT i, num_props = 0;
|
|
|
|
|
2019-09-10 17:09:14 +02:00
|
|
|
for (i = 0; i < table->num_cols; i++)
|
2012-07-13 11:35:09 +02:00
|
|
|
{
|
2019-09-10 17:09:14 +02:00
|
|
|
if (!is_method( table, i )) num_props++;
|
2012-07-13 11:35:09 +02:00
|
|
|
}
|
|
|
|
return num_props;
|
|
|
|
}
|
|
|
|
|
2019-09-10 17:09:14 +02:00
|
|
|
static UINT count_result_properties( const struct view *view, UINT table_index )
|
2012-06-20 12:05:59 +02:00
|
|
|
{
|
|
|
|
const struct property *prop = view->proplist;
|
|
|
|
UINT count;
|
|
|
|
|
2019-09-10 17:09:14 +02:00
|
|
|
if (!prop) return count_properties( view->table[table_index] );
|
2012-06-20 12:05:59 +02:00
|
|
|
|
|
|
|
count = 1;
|
|
|
|
while ((prop = prop->next)) count++;
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
2019-09-10 17:09:14 +02:00
|
|
|
static HRESULT get_system_propval( const struct view *view, UINT table_index, UINT result_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
|
|
|
{
|
2012-06-29 13:39:34 +02:00
|
|
|
if (flavor) *flavor = WBEM_FLAVOR_ORIGIN_SYSTEM;
|
|
|
|
|
2020-04-20 10:38:10 +02:00
|
|
|
if (!wcsicmp( name, L"__CLASS" ))
|
2012-06-20 12:05:59 +02:00
|
|
|
{
|
2018-10-09 15:25:03 +02:00
|
|
|
if (ret)
|
|
|
|
{
|
|
|
|
V_VT( ret ) = VT_BSTR;
|
2019-09-10 17:09:14 +02:00
|
|
|
V_BSTR( ret ) = SysAllocString( view->table[table_index]->name );
|
2018-10-09 15:25:03 +02:00
|
|
|
}
|
2012-06-20 12:05:59 +02:00
|
|
|
if (type) *type = CIM_STRING;
|
|
|
|
return S_OK;
|
|
|
|
}
|
2020-04-20 10:38:10 +02:00
|
|
|
if (!wcsicmp( name, L"__GENUS" ))
|
2012-06-20 12:05:59 +02:00
|
|
|
{
|
2018-10-09 15:25:03 +02:00
|
|
|
if (ret)
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
2020-09-30 12:37:39 +02:00
|
|
|
if (!wcsicmp( name, L"__NAMESPACE" ))
|
2012-06-20 12:05:59 +02:00
|
|
|
{
|
2018-10-09 15:25:03 +02:00
|
|
|
if (ret)
|
|
|
|
{
|
|
|
|
V_VT( ret ) = VT_BSTR;
|
2019-09-10 17:09:14 +02:00
|
|
|
V_BSTR( ret ) = view->proplist ? NULL : build_namespace();
|
2020-09-30 12:37:39 +02:00
|
|
|
if (!V_BSTR( ret )) V_VT( ret ) = VT_NULL;
|
2018-10-09 15:25:03 +02:00
|
|
|
}
|
2012-06-20 12:05:59 +02:00
|
|
|
if (type) *type = CIM_STRING;
|
|
|
|
return S_OK;
|
|
|
|
}
|
2020-09-30 12:37:39 +02:00
|
|
|
if (!wcsicmp( name, L"__PATH" ))
|
2012-06-20 12:05:59 +02:00
|
|
|
{
|
2018-10-09 15:25:03 +02:00
|
|
|
if (ret)
|
|
|
|
{
|
|
|
|
V_VT( ret ) = VT_BSTR;
|
2019-09-10 17:09:14 +02:00
|
|
|
V_BSTR( ret ) = build_path( view, table_index, result_index, name );
|
2020-09-30 12:37:39 +02:00
|
|
|
if (!V_BSTR( ret )) V_VT( ret ) = VT_NULL;
|
2018-10-09 15:25:03 +02:00
|
|
|
}
|
2012-06-20 12:05:59 +02:00
|
|
|
if (type) *type = CIM_STRING;
|
|
|
|
return S_OK;
|
|
|
|
}
|
2020-04-20 10:38:10 +02:00
|
|
|
if (!wcsicmp( name, L"__PROPERTY_COUNT" ))
|
2012-06-20 12:05:59 +02:00
|
|
|
{
|
2018-10-09 15:25:03 +02:00
|
|
|
if (ret)
|
|
|
|
{
|
|
|
|
V_VT( ret ) = VT_I4;
|
2019-09-10 17:09:14 +02:00
|
|
|
V_I4( ret ) = count_result_properties( view, table_index );
|
2018-10-09 15:25:03 +02:00
|
|
|
}
|
2012-06-20 12:05:59 +02:00
|
|
|
if (type) *type = CIM_SINT32;
|
|
|
|
return S_OK;
|
|
|
|
}
|
2020-09-30 12:37:39 +02:00
|
|
|
if (!wcsicmp( name, L"__RELPATH" ))
|
2012-06-20 12:05:59 +02:00
|
|
|
{
|
2018-10-09 15:25:03 +02:00
|
|
|
if (ret)
|
|
|
|
{
|
|
|
|
V_VT( ret ) = VT_BSTR;
|
2019-09-10 17:09:14 +02:00
|
|
|
V_BSTR( ret ) = build_relpath( view, table_index, result_index, name );
|
2020-09-30 12:37:39 +02:00
|
|
|
if (!V_BSTR( ret )) V_VT( ret ) = VT_NULL;
|
2018-10-09 15:25:03 +02:00
|
|
|
}
|
2012-06-20 12:05:59 +02:00
|
|
|
if (type) *type = CIM_STRING;
|
|
|
|
return S_OK;
|
|
|
|
}
|
2020-09-30 12:37:39 +02:00
|
|
|
if (!wcsicmp( name, L"__SERVER" ))
|
2012-06-20 12:05:59 +02:00
|
|
|
{
|
2018-10-09 15:25:03 +02:00
|
|
|
if (ret)
|
|
|
|
{
|
|
|
|
V_VT( ret ) = VT_BSTR;
|
2019-09-10 17:09:14 +02:00
|
|
|
V_BSTR( ret ) = view->proplist ? NULL : build_servername();
|
2020-09-30 12:37:39 +02:00
|
|
|
if (!V_BSTR( ret )) V_VT( ret ) = VT_NULL;
|
2018-10-09 15:25:03 +02:00
|
|
|
}
|
2012-06-20 12:05:59 +02:00
|
|
|
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)
|
|
|
|
{
|
2019-09-19 19:33:29 +02:00
|
|
|
case CIM_BOOLEAN: return VT_BOOL;
|
|
|
|
|
2012-10-10 12:03:10 +02:00
|
|
|
case CIM_STRING:
|
2019-07-05 11:14:50 +02:00
|
|
|
case CIM_REFERENCE:
|
2019-09-19 19:33:29 +02:00
|
|
|
case CIM_DATETIME: return VT_BSTR;
|
|
|
|
|
|
|
|
case CIM_SINT8: return VT_I1;
|
|
|
|
case CIM_UINT8: return VT_UI1;
|
|
|
|
case CIM_SINT16: return VT_I2;
|
|
|
|
|
|
|
|
case CIM_UINT16:
|
|
|
|
case CIM_SINT32:
|
|
|
|
case CIM_UINT32: return VT_I4;
|
|
|
|
|
|
|
|
case CIM_SINT64: return VT_I8;
|
|
|
|
case CIM_UINT64: return VT_UI8;
|
|
|
|
|
|
|
|
case CIM_REAL32: return VT_R4;
|
|
|
|
|
2012-10-10 12:03:10 +02:00
|
|
|
default:
|
|
|
|
ERR("unhandled type %u\n", type);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-09-19 19:33:29 +02:00
|
|
|
SAFEARRAY *to_safearray( const struct array *array, CIMTYPE basetype )
|
2012-10-10 12:03:10 +02:00
|
|
|
{
|
|
|
|
SAFEARRAY *ret;
|
2019-09-19 19:33:29 +02:00
|
|
|
VARTYPE vartype = to_vartype( basetype );
|
2012-10-10 12:03:10 +02:00
|
|
|
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++)
|
|
|
|
{
|
2019-08-27 16:35:55 +02:00
|
|
|
void *ptr = (char *)array->ptr + i * array->elem_size;
|
2012-10-10 12:03:10 +02:00
|
|
|
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;
|
2019-09-10 17:09:14 +02:00
|
|
|
case VT_R4:
|
|
|
|
V_R4( ret ) = *(FLOAT *)&val;
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2019-09-10 17:09:14 +02:00
|
|
|
static HRESULT map_view_index( const struct view *view, UINT index, UINT *table_index, UINT *result_index )
|
|
|
|
{
|
2019-09-19 19:33:28 +02:00
|
|
|
if (!view->table) return WBEM_E_NOT_FOUND;
|
|
|
|
|
2019-09-10 17:09:14 +02:00
|
|
|
switch (view->type)
|
|
|
|
{
|
|
|
|
case VIEW_TYPE_SELECT:
|
|
|
|
*table_index = 0;
|
|
|
|
*result_index = index;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case VIEW_TYPE_ASSOCIATORS:
|
|
|
|
*table_index = *result_index = index;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
ERR( "unhandled view type %u\n", view->type );
|
|
|
|
return WBEM_E_FAILED;
|
|
|
|
}
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct table *get_view_table( const struct view *view, UINT index )
|
|
|
|
{
|
|
|
|
switch (view->type)
|
|
|
|
{
|
|
|
|
case VIEW_TYPE_SELECT:
|
|
|
|
return view->table[0];
|
|
|
|
|
|
|
|
case VIEW_TYPE_ASSOCIATORS:
|
|
|
|
return view->table[index];
|
|
|
|
|
|
|
|
default:
|
|
|
|
ERR( "unhandled view type %u\n", view->type );
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
2019-09-10 17:09:14 +02:00
|
|
|
UINT column, row, table_index, result_index;
|
|
|
|
struct table *table;
|
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
|
|
|
|
2019-09-10 17:09:14 +02:00
|
|
|
if ((hr = map_view_index( view, index, &table_index, &result_index )) != S_OK) return hr;
|
2012-06-18 09:31:29 +02:00
|
|
|
|
2019-09-10 17:09:14 +02:00
|
|
|
if (is_system_prop( name )) return get_system_propval( view, table_index, result_index, name, ret, type, flavor );
|
|
|
|
if (!view->result_count || !is_result_prop( view, name )) return WBEM_E_NOT_FOUND;
|
2012-06-18 09:31:29 +02:00
|
|
|
|
2019-09-10 17:09:14 +02:00
|
|
|
table = view->table[table_index];
|
|
|
|
hr = get_column_index( table, name, &column );
|
|
|
|
if (hr != S_OK || is_method( table, column )) return WBEM_E_NOT_FOUND;
|
|
|
|
|
|
|
|
row = view->result[result_index];
|
|
|
|
hr = get_value( table, row, column, &val );
|
2012-06-18 09:31:29 +02:00
|
|
|
if (hr != S_OK) return hr;
|
|
|
|
|
2019-09-10 17:09:14 +02:00
|
|
|
if (type) *type = table->columns[column].type & COL_TYPE_MASK;
|
2018-10-09 15:25:03 +02:00
|
|
|
if (flavor) *flavor = 0;
|
|
|
|
|
|
|
|
if (!ret) return S_OK;
|
|
|
|
|
2019-09-19 19:33:29 +02:00
|
|
|
vartype = to_vartype( table->columns[column].type & CIM_TYPE_MASK );
|
2019-09-10 17:09:14 +02:00
|
|
|
if (table->columns[column].type & CIM_FLAG_ARRAY)
|
2012-10-10 12:03:10 +02:00
|
|
|
{
|
2019-09-10 17:09:14 +02:00
|
|
|
CIMTYPE basetype = table->columns[column].type & CIM_TYPE_MASK;
|
2012-10-10 12:03:10 +02:00
|
|
|
|
|
|
|
val_ptr = to_safearray( (const struct array *)(INT_PTR)val, basetype );
|
2015-12-23 11:07:39 +01:00
|
|
|
if (!val_ptr) vartype = VT_NULL;
|
2019-09-19 19:33:29 +02:00
|
|
|
else vartype |= VT_ARRAY;
|
2018-10-09 15:25:03 +02:00
|
|
|
set_variant( vartype, val, val_ptr, ret );
|
|
|
|
return S_OK;
|
2012-10-10 12:03:10 +02:00
|
|
|
}
|
2018-10-09 15:25:03 +02:00
|
|
|
|
2019-09-10 17:09:14 +02:00
|
|
|
switch (table->columns[column].type & COL_TYPE_MASK)
|
2012-06-18 09:31:29 +02:00
|
|
|
{
|
|
|
|
case CIM_STRING:
|
2019-07-05 11:14:50 +02:00
|
|
|
case CIM_REFERENCE:
|
2012-06-18 09:31:29 +02:00
|
|
|
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;
|
2012-06-27 11:34:23 +02:00
|
|
|
case CIM_SINT64:
|
2012-07-02 16:00:50 +02:00
|
|
|
vartype = VT_BSTR;
|
2019-09-10 17:09:14 +02:00
|
|
|
val_ptr = get_value_bstr( 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;
|
2019-09-10 17:09:14 +02:00
|
|
|
val_ptr = get_value_bstr( table, row, column );
|
|
|
|
break;
|
2019-09-19 19:33:29 +02:00
|
|
|
case CIM_BOOLEAN:
|
|
|
|
case CIM_SINT8:
|
|
|
|
case CIM_UINT8:
|
|
|
|
case CIM_SINT16:
|
|
|
|
case CIM_UINT16:
|
|
|
|
case CIM_SINT32:
|
|
|
|
case CIM_UINT32:
|
2019-09-10 17:09:14 +02:00
|
|
|
case CIM_REAL32:
|
2012-06-27 11:34:23 +02:00
|
|
|
break;
|
2012-06-18 09:31:29 +02:00
|
|
|
default:
|
2019-09-10 17:09:14 +02:00
|
|
|
ERR("unhandled column type %u\n", table->columns[column].type);
|
2012-06-18 09:31:29 +02:00
|
|
|
return WBEM_E_FAILED;
|
|
|
|
}
|
2012-10-10 12:03:10 +02:00
|
|
|
|
|
|
|
set_variant( vartype, val, val_ptr, ret );
|
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;
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
2019-08-27 16:35:55 +02:00
|
|
|
ret->count = bound + 1;
|
|
|
|
ret->elem_size = get_type_size( basetype );
|
|
|
|
if (!(ret->ptr = heap_alloc_zero( ret->count * ret->elem_size )))
|
2012-10-10 12:03:10 +02:00
|
|
|
{
|
|
|
|
heap_free( ret );
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
for (i = 0; i < ret->count; i++)
|
|
|
|
{
|
2019-08-27 16:35:55 +02:00
|
|
|
void *ptr = (char *)ret->ptr + i * ret->elem_size;
|
2012-10-12 14:25:13 +02:00
|
|
|
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;
|
2019-09-10 17:09:14 +02:00
|
|
|
UINT row, column, table_index, result_index;
|
|
|
|
struct table *table;
|
2012-07-25 13:12:10 +02:00
|
|
|
LONGLONG val;
|
|
|
|
|
2019-09-10 17:09:14 +02:00
|
|
|
if ((hr = map_view_index( view, index, &table_index, &result_index )) != S_OK) return hr;
|
|
|
|
|
|
|
|
table = view->table[table_index];
|
|
|
|
hr = get_column_index( table, name, &column );
|
2012-07-25 13:12:10 +02:00
|
|
|
if (hr != S_OK)
|
|
|
|
{
|
|
|
|
FIXME("no support for creating new properties\n");
|
|
|
|
return WBEM_E_FAILED;
|
|
|
|
}
|
2019-09-10 17:09:14 +02:00
|
|
|
if (is_method( table, column ) || !(table->columns[column].type & COL_FLAG_DYNAMIC))
|
2012-07-25 13:12:10 +02:00
|
|
|
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;
|
|
|
|
|
2019-09-10 17:09:14 +02:00
|
|
|
row = view->result[result_index];
|
|
|
|
return set_value( table, row, column, val, type );
|
2012-07-25 13:12:10 +02:00
|
|
|
}
|
|
|
|
|
2019-09-10 17:09:14 +02:00
|
|
|
HRESULT get_properties( const struct view *view, UINT index, LONG flags, SAFEARRAY **props )
|
2012-06-19 10:19:38 +02:00
|
|
|
{
|
2020-10-22 21:25:49 +02:00
|
|
|
static const WCHAR * const system_props[] =
|
|
|
|
{ L"__GENUS", L"__CLASS", L"__RELPATH", L"__PROPERTY_COUNT", L"__SERVER", L"__NAMESPACE", L"__PATH" };
|
2012-06-19 10:19:38 +02:00
|
|
|
SAFEARRAY *sa;
|
|
|
|
BSTR str;
|
2020-10-22 21:25:49 +02:00
|
|
|
UINT i, table_index, result_index, count = 0;
|
2019-09-10 17:09:14 +02:00
|
|
|
struct table *table;
|
|
|
|
HRESULT hr;
|
2020-10-22 21:25:49 +02:00
|
|
|
LONG j = 0;
|
2012-06-19 10:19:38 +02:00
|
|
|
|
2019-09-10 17:09:14 +02:00
|
|
|
if ((hr = map_view_index( view, index, &table_index, &result_index )) != S_OK) return hr;
|
|
|
|
table = view->table[table_index];
|
2014-03-24 11:42:00 +01:00
|
|
|
|
2020-10-22 21:25:49 +02:00
|
|
|
if (!(flags & WBEM_FLAG_NONSYSTEM_ONLY)) count += ARRAY_SIZE(system_props);
|
|
|
|
if (!(flags & WBEM_FLAG_SYSTEM_ONLY))
|
|
|
|
{
|
|
|
|
for (i = 0; i < table->num_cols; i++)
|
|
|
|
{
|
|
|
|
if (!is_method( table, i ) && is_result_prop( view, table->columns[i].name )) count++;
|
|
|
|
}
|
|
|
|
}
|
2012-07-13 11:35:09 +02:00
|
|
|
|
2020-10-22 21:25:49 +02:00
|
|
|
if (!(sa = SafeArrayCreateVector( VT_BSTR, 0, count ))) return E_OUTOFMEMORY;
|
2014-03-24 11:42:00 +01:00
|
|
|
|
2020-10-22 21:25:49 +02:00
|
|
|
if (!(flags & WBEM_FLAG_NONSYSTEM_ONLY))
|
|
|
|
{
|
|
|
|
for (j = 0; j < ARRAY_SIZE(system_props); j++)
|
|
|
|
{
|
|
|
|
str = SysAllocString( system_props[j] );
|
|
|
|
if (!str || SafeArrayPutElement( sa, &j, str ) != S_OK)
|
|
|
|
{
|
|
|
|
SysFreeString( str );
|
|
|
|
SafeArrayDestroy( sa );
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
}
|
|
|
|
SysFreeString( str );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!(flags & WBEM_FLAG_SYSTEM_ONLY))
|
|
|
|
{
|
|
|
|
for (i = 0; i < table->num_cols; i++)
|
2012-06-19 10:19:38 +02:00
|
|
|
{
|
2020-10-22 21:25:49 +02:00
|
|
|
if (is_method( table, i ) || !is_result_prop( view, table->columns[i].name )) continue;
|
|
|
|
|
|
|
|
str = SysAllocString( table->columns[i].name );
|
|
|
|
if (!str || SafeArrayPutElement( sa, &j, str ) != S_OK)
|
|
|
|
{
|
|
|
|
SysFreeString( str );
|
|
|
|
SafeArrayDestroy( sa );
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
}
|
2012-06-19 10:19:38 +02:00
|
|
|
SysFreeString( str );
|
2020-10-22 21:25:49 +02:00
|
|
|
j++;
|
2012-06-19 10:19:38 +02:00
|
|
|
}
|
|
|
|
}
|
2020-10-22 21:25:49 +02:00
|
|
|
|
2012-06-19 10:19:38 +02:00
|
|
|
*props = sa;
|
|
|
|
return S_OK;
|
|
|
|
}
|