ReactOS 0.4.15-dev-7842-g558ab78
query.c File Reference
#include <stdarg.h>
#include "windef.h"
#include "winbase.h"
#include "wbemcli.h"
#include "wine/debug.h"
#include "wbemprox_private.h"
Include dependency graph for query.c:

Go to the source code of this file.

Macros

#define COBJMACROS
 

Functions

 WINE_DEFAULT_DEBUG_CHANNEL (wbemprox)
 
static HRESULT append_table (struct view *view, struct table *table)
 
HRESULT create_view (enum view_type type, const WCHAR *path, const struct keyword *keywordlist, const WCHAR *class, const struct property *proplist, const struct expr *cond, struct view **ret)
 
void destroy_view (struct view *view)
 
static BOOL eval_like (const WCHAR *lstr, const WCHAR *rstr)
 
static HRESULT eval_strcmp (UINT op, const WCHAR *lstr, const WCHAR *rstr, LONGLONG *val)
 
static BOOL is_int (CIMTYPE type)
 
static BOOL is_strcmp (const struct complex_expr *expr, UINT ltype, UINT rtype)
 
static BOOL is_boolcmp (const struct complex_expr *expr, UINT ltype, UINT rtype)
 
static HRESULT eval_boolcmp (UINT op, LONGLONG lval, LONGLONG rval, UINT ltype, UINT rtype, LONGLONG *val)
 
static BOOL is_refcmp (const struct complex_expr *expr, UINT ltype, UINT rtype)
 
static HRESULT eval_refcmp (UINT op, const WCHAR *lstr, const WCHAR *rstr, LONGLONG *val)
 
static UINT resolve_type (UINT left, UINT right)
 
static const WCHARformat_int (WCHAR *buf, UINT len, CIMTYPE type, LONGLONG val)
 
static HRESULT eval_binary (const struct table *table, UINT row, const struct complex_expr *expr, LONGLONG *val, UINT *type)
 
static HRESULT eval_unary (const struct table *table, UINT row, const struct complex_expr *expr, LONGLONG *val, UINT *type)
 
static HRESULT eval_propval (const struct table *table, UINT row, const struct property *propval, LONGLONG *val, UINT *type)
 
HRESULT eval_cond (const struct table *table, UINT row, const struct expr *cond, LONGLONG *val, UINT *type)
 
static WCHARbuild_assoc_query (const WCHAR *class, UINT class_len)
 
static HRESULT create_assoc_enum (const WCHAR *class, UINT class_len, IEnumWbemClassObject **iter)
 
static WCHARbuild_antecedent_query (const WCHAR *assocclass, const WCHAR *dependent)
 
static BSTR build_servername (void)
 
static BSTR build_namespace (void)
 
static WCHARbuild_canonical_path (const WCHAR *relpath)
 
static HRESULT get_antecedent (const WCHAR *assocclass, const WCHAR *dependent, BSTR *ret)
 
static HRESULT do_query (const WCHAR *str, struct query **ret_query)
 
static HRESULT get_antecedent_table (const WCHAR *assocclass, const WCHAR *dependent, struct table **table)
 
static HRESULT exec_assoc_view (struct view *view)
 
static HRESULT exec_select_view (struct view *view)
 
HRESULT execute_view (struct view *view)
 
struct querycreate_query (void)
 
void free_query (struct query *query)
 
struct queryaddref_query (struct query *query)
 
void release_query (struct query *query)
 
HRESULT exec_query (const WCHAR *str, IEnumWbemClassObject **result)
 
BOOL is_result_prop (const struct view *view, const WCHAR *name)
 
static BOOL is_system_prop (const WCHAR *name)
 
static BSTR build_proplist (const struct table *table, UINT row, UINT count, UINT *len)
 
static UINT count_key_columns (const struct table *table)
 
static BSTR build_relpath (const struct view *view, UINT table_index, UINT result_index, const WCHAR *name)
 
static BSTR build_path (const struct view *view, UINT table_index, UINT result_index, const WCHAR *name)
 
BOOL is_method (const struct table *table, UINT column)
 
static UINT count_properties (const struct table *table)
 
static UINT count_result_properties (const struct view *view, UINT table_index)
 
static HRESULT get_system_propval (const struct view *view, UINT table_index, UINT result_index, const WCHAR *name, VARIANT *ret, CIMTYPE *type, LONG *flavor)
 
VARTYPE to_vartype (CIMTYPE type)
 
SAFEARRAYto_safearray (const struct array *array, CIMTYPE basetype)
 
void set_variant (VARTYPE type, LONGLONG val, void *val_ptr, VARIANT *ret)
 
static HRESULT map_view_index (const struct view *view, UINT index, UINT *table_index, UINT *result_index)
 
struct tableget_view_table (const struct view *view, UINT index)
 
HRESULT get_propval (const struct view *view, UINT index, const WCHAR *name, VARIANT *ret, CIMTYPE *type, LONG *flavor)
 
static CIMTYPE to_cimtype (VARTYPE type)
 
static struct arrayto_array (VARIANT *var, CIMTYPE *type)
 
HRESULT to_longlong (VARIANT *var, LONGLONG *val, CIMTYPE *type)
 
HRESULT put_propval (const struct view *view, UINT index, const WCHAR *name, VARIANT *var, CIMTYPE type)
 
HRESULT get_properties (const struct view *view, UINT index, LONG flags, SAFEARRAY **props)
 

Macro Definition Documentation

◆ COBJMACROS

#define COBJMACROS

Definition at line 19 of file query.c.

Function Documentation

◆ addref_query()

struct query * addref_query ( struct query query)

Definition at line 775 of file query.c.

776{
778 return query;
779}
#define InterlockedIncrement
Definition: armddk.h:53

Referenced by EnumWbemClassObject_create().

◆ append_table()

static HRESULT append_table ( struct view view,
struct table table 
)
static

Definition at line 35 of file query.c.

36{
37 struct table **tmp;
38 if (!(tmp = heap_realloc( view->table, (view->table_count + 1) * sizeof(*tmp) ))) return E_OUTOFMEMORY;
39 view->table = tmp;
41 return S_OK;
42}
static void * heap_realloc(void *mem, size_t len)
Definition: appwiz.h:71
#define E_OUTOFMEMORY
Definition: ddrawi.h:100
#define S_OK
Definition: intsafe.h:52
UINT table_count
struct table ** table

Referenced by create_view(), and exec_assoc_view().

◆ build_antecedent_query()

static WCHAR * build_antecedent_query ( const WCHAR assocclass,
const WCHAR dependent 
)
static

Definition at line 505 of file query.c.

506{
507 static const WCHAR fmtW[] =
508 {'S','E','L','E','C','T',' ','A','n','t','e','c','e','d','e','n','t',' ','F','R','O','M',' ','%','s',' ',
509 'W','H','E','R','E',' ','D','e','p','e','n','d','e','n','t','=','\'','%','s','\'',0};
510 UINT len = lstrlenW(assocclass) + lstrlenW(dependent) + ARRAY_SIZE(fmtW);
511 WCHAR *ret;
512
513 if (!(ret = heap_alloc( len * sizeof(WCHAR) ))) return NULL;
514 swprintf( ret, fmtW, assocclass, dependent );
515 return ret;
516}
static void * heap_alloc(size_t len)
Definition: appwiz.h:66
#define ARRAY_SIZE(A)
Definition: main.h:33
#define NULL
Definition: types.h:112
#define lstrlenW
Definition: compat.h:750
#define swprintf
Definition: precomp.h:40
GLenum GLsizei len
Definition: glext.h:6722
unsigned int UINT
Definition: ndis.h:50
int ret
__wchar_t WCHAR
Definition: xmlstorage.h:180

Referenced by get_antecedent().

◆ build_assoc_query()

static WCHAR * build_assoc_query ( const WCHAR class,
UINT  class_len 
)
static

Definition at line 481 of file query.c.

482{
483 static const WCHAR fmtW[] =
484 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ','_','_','A','S','S','O','C','I','A','T','O','R','S',
485 ' ','W','H','E','R','E',' ','C','l','a','s','s','=','\'','%','s','\'',0};
486 UINT len = class_len + ARRAY_SIZE(fmtW);
487 WCHAR *ret;
488
489 if (!(ret = heap_alloc( len * sizeof(WCHAR) ))) return NULL;
490 swprintf( ret, fmtW, class );
491 return ret;
492}

Referenced by create_assoc_enum().

◆ build_canonical_path()

static WCHAR * build_canonical_path ( const WCHAR relpath)
static

Definition at line 534 of file query.c.

535{
536 static const WCHAR fmtW[] = {'\\','\\','%','s','\\','%','s',':',0};
537 BSTR server, namespace;
538 WCHAR *ret;
539 UINT len, i;
540
541 if (!(server = build_servername())) return NULL;
542 if (!(namespace = build_namespace()))
543 {
545 return NULL;
546 }
547
548 len = ARRAY_SIZE( fmtW ) + SysStringLen( server ) + SysStringLen( namespace ) + lstrlenW( relpath );
549 if ((ret = heap_alloc( len * sizeof(WCHAR ) )))
550 {
551 len = swprintf( ret, fmtW, server, namespace );
552 for (i = 0; i < lstrlenW( relpath ); i ++)
553 {
554 if (relpath[i] == '\'') ret[len++] = '"';
555 else ret[len++] = relpath[i];
556 }
557 ret[len] = 0;
558 }
559
561 SysFreeString( namespace );
562 return ret;
563}
OLECHAR * BSTR
Definition: compat.h:2293
static BSTR build_namespace(void)
Definition: query.c:528
static BSTR build_servername(void)
Definition: query.c:518
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
UINT WINAPI SysStringLen(BSTR str)
Definition: oleaut.c:196
void WINAPI DECLSPEC_HOTPATCH SysFreeString(BSTR str)
Definition: oleaut.c:271
static rfbScreenInfoPtr server
Definition: vnc.c:74

Referenced by get_antecedent().

◆ build_namespace()

static BSTR build_namespace ( void  )
static

Definition at line 528 of file query.c.

529{
530 static const WCHAR cimv2W[] = {'R','O','O','T','\\','C','I','M','V','2',0};
531 return SysAllocString( cimv2W );
532}
BSTR WINAPI SysAllocString(LPCOLESTR str)
Definition: oleaut.c:238

Referenced by build_canonical_path(), build_path(), and get_system_propval().

◆ build_path()

static BSTR build_path ( const struct view view,
UINT  table_index,
UINT  result_index,
const WCHAR name 
)
static

Definition at line 894 of file query.c.

895{
896 static const WCHAR fmtW[] = {'\\','\\','%','s','\\','%','s',':','%','s',0};
897 BSTR server, namespace = NULL, relpath = NULL, ret = NULL;
898 UINT len;
899
900 if (view->proplist) return NULL;
901
902 if (!(server = build_servername())) return NULL;
903 if (!(namespace = build_namespace())) goto done;
904 if (!(relpath = build_relpath( view, table_index, result_index, name ))) goto done;
905
906 len = lstrlenW( fmtW ) + SysStringLen( server ) + SysStringLen( namespace ) + SysStringLen( relpath );
907 if (!(ret = SysAllocStringLen( NULL, len ))) goto done;
908 swprintf( ret, fmtW, server, namespace, relpath );
909
910done:
912 SysFreeString( namespace );
913 SysFreeString( relpath );
914 return ret;
915}
static BSTR build_relpath(const struct view *view, UINT table_index, UINT result_index, const WCHAR *name)
Definition: query.c:870
BSTR WINAPI SysAllocStringLen(const OLECHAR *str, unsigned int len)
Definition: oleaut.c:339
Definition: name.c:39
const struct property * proplist

Referenced by get_system_propval().

◆ build_proplist()

static BSTR build_proplist ( const struct table table,
UINT  row,
UINT  count,
UINT len 
)
static

Definition at line 821 of file query.c.

822{
823 static const WCHAR fmtW[] = {'%','s','=','%','s',0};
824 UINT i, j, offset;
825 BSTR *values, ret = NULL;
826
827 if (!(values = heap_alloc( count * sizeof(BSTR) ))) return NULL;
828
829 *len = j = 0;
830 for (i = 0; i < table->num_cols; i++)
831 {
832 if (table->columns[i].type & COL_FLAG_KEY)
833 {
834 const WCHAR *name = table->columns[i].name;
836 *len += lstrlenW( fmtW ) + lstrlenW( name ) + lstrlenW( values[j] );
837 j++;
838 }
839 }
840 if ((ret = SysAllocStringLen( NULL, *len )))
841 {
842 offset = j = 0;
843 for (i = 0; i < table->num_cols; i++)
844 {
845 if (table->columns[i].type & COL_FLAG_KEY)
846 {
847 const WCHAR *name = table->columns[i].name;
848 offset += swprintf( ret + offset, fmtW, name, values[j] );
849 if (j < count - 1) ret[offset++] = ',';
850 j++;
851 }
852 }
853 }
854 for (i = 0; i < count; i++) SysFreeString( values[i] );
855 heap_free( values );
856 return ret;
857}
static BOOL heap_free(void *mem)
Definition: appwiz.h:76
BSTR get_value_bstr(const struct table *table, UINT row, UINT column)
Definition: table.c:158
struct png_info_def *typedef unsigned char **typedef struct png_info_def *typedef struct png_info_def *typedef struct png_info_def *typedef unsigned char ** row
Definition: typeof.h:78
GLuint GLuint GLsizei count
Definition: gl.h:1545
GLboolean GLenum GLenum GLvoid * values
Definition: glext.h:5666
GLintptr offset
Definition: glext.h:5920
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint GLint GLint j
Definition: glfuncs.h:250
const struct column * columns
UINT num_cols
#define COL_FLAG_KEY

Referenced by build_relpath().

◆ build_relpath()

static BSTR build_relpath ( const struct view view,
UINT  table_index,
UINT  result_index,
const WCHAR name 
)
static

Definition at line 870 of file query.c.

871{
872 static const WCHAR fmtW[] = {'%','s','.','%','s',0};
873 BSTR class, proplist, ret = NULL;
874 struct table *table = view->table[table_index];
875 UINT row = view->result[result_index];
876 UINT num_keys, len;
877
878 if (view->proplist) return NULL;
879
880 if (!(class = SysAllocString( view->table[table_index]->name ))) return NULL;
881 if (!(num_keys = count_key_columns( table ))) return class;
882 if (!(proplist = build_proplist( table, row, num_keys, &len ))) goto done;
883
884 len += lstrlenW( fmtW ) + SysStringLen( class );
885 if (!(ret = SysAllocStringLen( NULL, len ))) goto done;
886 swprintf( ret, fmtW, class, proplist );
887
888done:
889 SysFreeString( class );
890 SysFreeString( proplist );
891 return ret;
892}
static BSTR build_proplist(const struct table *table, UINT row, UINT count, UINT *len)
Definition: query.c:821
static UINT count_key_columns(const struct table *table)
Definition: query.c:859
UINT * result

Referenced by build_path(), and get_system_propval().

◆ build_servername()

static BSTR build_servername ( void  )
static

Definition at line 518 of file query.c.

519{
522
523 if (!(GetComputerNameW( server, &len ))) return NULL;
524 for (p = server; *p; p++) *p = towupper( *p );
525 return SysAllocString( server );
526}
BOOL WINAPI GetComputerNameW(LPWSTR lpBuffer, LPDWORD lpnSize)
Definition: compname.c:446
unsigned long DWORD
Definition: ntddk_ex.h:95
GLfloat GLfloat p
Definition: glext.h:8902
#define towupper(c)
Definition: wctype.h:99
#define MAX_COMPUTERNAME_LENGTH
Definition: winbase.h:243

Referenced by build_canonical_path(), build_path(), and get_system_propval().

◆ count_key_columns()

static UINT count_key_columns ( const struct table table)
static

Definition at line 859 of file query.c.

860{
861 UINT i, num_keys = 0;
862
863 for (i = 0; i < table->num_cols; i++)
864 {
865 if (table->columns[i].type & COL_FLAG_KEY) num_keys++;
866 }
867 return num_keys;
868}

Referenced by build_relpath().

◆ count_properties()

static UINT count_properties ( const struct table table)
static

Definition at line 922 of file query.c.

923{
924 UINT i, num_props = 0;
925
926 for (i = 0; i < table->num_cols; i++)
927 {
928 if (!is_method( table, i )) num_props++;
929 }
930 return num_props;
931}
BOOL is_method(const struct table *table, UINT column)
Definition: query.c:917

Referenced by count_result_properties().

◆ count_result_properties()

static UINT count_result_properties ( const struct view view,
UINT  table_index 
)
static

Definition at line 933 of file query.c.

934{
935 const struct property *prop = view->proplist;
936 UINT count;
937
938 if (!prop) return count_properties( view->table[table_index] );
939
940 count = 1;
941 while ((prop = prop->next)) count++;
942 return count;
943}
static UINT count_properties(const struct table *table)
Definition: query.c:922
const struct property * next

Referenced by get_properties(), and get_system_propval().

◆ create_assoc_enum()

static HRESULT create_assoc_enum ( const WCHAR class,
UINT  class_len,
IEnumWbemClassObject **  iter 
)
static

Definition at line 494 of file query.c.

495{
496 WCHAR *query;
497 HRESULT hr;
498
499 if (!(query = build_assoc_query( class, class_len ))) return E_OUTOFMEMORY;
500 hr = exec_query( query, iter );
501 heap_free( query );
502 return hr;
503}
static WCHAR * build_assoc_query(const WCHAR *class, UINT class_len)
Definition: query.c:481
HRESULT exec_query(const WCHAR *str, IEnumWbemClassObject **result)
Definition: query.c:786
HRESULT hr
Definition: shlfolder.c:183

Referenced by exec_assoc_view().

◆ create_query()

struct query * create_query ( void  )

Definition at line 755 of file query.c.

756{
757 struct query *query;
758
759 if (!(query = heap_alloc( sizeof(*query) ))) return NULL;
760 list_init( &query->mem );
761 query->refs = 1;
762 return query;
763}
static void list_init(struct list_entry *head)
Definition: list.h:51
struct list mem

Referenced by do_query(), and exec_query().

◆ create_view()

HRESULT create_view ( enum view_type  type,
const WCHAR path,
const struct keyword keywordlist,
const WCHAR class,
const struct property proplist,
const struct expr cond,
struct view **  ret 
)

Definition at line 44 of file query.c.

46{
47 struct view *view = heap_alloc_zero( sizeof(*view) );
48
49 if (!view) return E_OUTOFMEMORY;
50
51 switch (type)
52 {
54 view->path = path;
56 break;
57
59 {
60 struct table *table = grab_table( class );
61 HRESULT hr;
62
63 if (table && (hr = append_table( view, table )) != S_OK)
64 {
65 heap_free( view );
66 return hr;
67 }
68 view->proplist = proplist;
69 view->cond = cond;
70 break;
71 }
72 default:
73 ERR( "unhandled type %u\n", type );
74 heap_free( view );
75 return E_INVALIDARG;
76 }
77
78 view->type = type;
79 *ret = view;
80 return S_OK;
81}
#define ERR(fmt,...)
Definition: debug.h:110
#define E_INVALIDARG
Definition: ddrawi.h:101
static HRESULT append_table(struct view *view, struct table *table)
Definition: query.c:35
struct table * grab_table(const WCHAR *name)
Definition: table.c:365
GLuint GLuint GLsizei GLenum type
Definition: gl.h:1545
const WCHAR * path
const struct expr * cond
const struct keyword * keywordlist
enum view_type type
@ VIEW_TYPE_ASSOCIATORS
@ VIEW_TYPE_SELECT

◆ destroy_view()

void destroy_view ( struct view view)

Definition at line 83 of file query.c.

84{
85 ULONG i;
86 if (!view) return;
87 for (i = 0; i < view->table_count; i++) release_table( view->table[i] );
90 heap_free( view );
91}
void release_table(struct table *table)
Definition: table.c:354
uint32_t ULONG
Definition: typedefs.h:59

Referenced by free_query().

◆ do_query()

static HRESULT do_query ( const WCHAR str,
struct query **  ret_query 
)
static

Definition at line 598 of file query.c.

599{
600 struct query *query;
601 HRESULT hr;
602
603 if (!(query = create_query())) return E_OUTOFMEMORY;
604 if ((hr = parse_query( str, &query->view, &query->mem )) != S_OK || (hr = execute_view( query->view )) != S_OK)
605 {
607 return hr;
608 }
609 *ret_query = query;
610 return S_OK;
611}
static BOOL parse_query(const WCHAR **ptr, parse_data *data, DWORD flags)
Definition: uri.c:2044
void release_query(struct query *query)
Definition: query.c:781
HRESULT execute_view(struct view *view)
Definition: query.c:739
struct query * create_query(void)
Definition: query.c:755
const WCHAR * str
struct view * view

Referenced by get_antecedent_table().

◆ eval_binary()

static HRESULT eval_binary ( const struct table table,
UINT  row,
const struct complex_expr expr,
LONGLONG val,
UINT type 
)
static

Definition at line 315 of file query.c.

317{
318 HRESULT lret, rret;
319 LONGLONG lval, rval;
320 UINT ltype, rtype;
321
322 lret = eval_cond( table, row, expr->left, &lval, &ltype );
323 rret = eval_cond( table, row, expr->right, &rval, &rtype );
324 if (lret != S_OK || rret != S_OK) return WBEM_E_INVALID_QUERY;
325
326 *type = resolve_type( ltype, rtype );
327
328 if (is_strcmp( expr, ltype, rtype ))
329 {
330 const WCHAR *lstr, *rstr;
331 WCHAR lbuf[21], rbuf[21];
332
333 if (is_int( ltype )) lstr = format_int( lbuf, ARRAY_SIZE( lbuf ), ltype, lval );
334 else lstr = (const WCHAR *)(INT_PTR)lval;
335
336 if (is_int( rtype )) rstr = format_int( rbuf, ARRAY_SIZE( rbuf ), rtype, rval );
337 else rstr = (const WCHAR *)(INT_PTR)rval;
338
339 return eval_strcmp( expr->op, lstr, rstr, val );
340 }
341 if (is_boolcmp( expr, ltype, rtype ))
342 {
343 return eval_boolcmp( expr->op, lval, rval, ltype, rtype, val );
344 }
345 if (is_refcmp( expr, ltype, rtype ))
346 {
347 return eval_refcmp( expr->op, (const WCHAR *)(INT_PTR)lval, (const WCHAR *)(INT_PTR)rval, val );
348 }
349
350 switch (expr->op)
351 {
352 case OP_EQ:
353 *val = (lval == rval);
354 break;
355 case OP_AND:
356 *val = (lval && rval);
357 break;
358 case OP_OR:
359 *val = (lval || rval);
360 break;
361 case OP_GT:
362 *val = (lval > rval);
363 break;
364 case OP_LT:
365 *val = (lval < rval);
366 break;
367 case OP_LE:
368 *val = (lval <= rval);
369 break;
370 case OP_GE:
371 *val = (lval >= rval);
372 break;
373 case OP_NE:
374 *val = (lval != rval);
375 break;
376 default:
377 ERR("unhandled operator %u\n", expr->op);
379 }
380 return S_OK;
381}
float rval
Definition: cylfrac.c:48
HRESULT eval_cond(const struct table *table, UINT row, const struct expr *cond, LONGLONG *val, UINT *type)
Definition: query.c:440
static BOOL is_strcmp(const struct complex_expr *expr, UINT ltype, UINT rtype)
Definition: query.c:166
static HRESULT eval_refcmp(UINT op, const WCHAR *lstr, const WCHAR *rstr, LONGLONG *val)
Definition: query.c:213
static BOOL is_int(CIMTYPE type)
Definition: query.c:148
static UINT resolve_type(UINT left, UINT right)
Definition: query.c:235
static BOOL is_refcmp(const struct complex_expr *expr, UINT ltype, UINT rtype)
Definition: query.c:206
static BOOL is_boolcmp(const struct complex_expr *expr, UINT ltype, UINT rtype)
Definition: query.c:175
static HRESULT eval_boolcmp(UINT op, LONGLONG lval, LONGLONG rval, UINT ltype, UINT rtype, LONGLONG *val)
Definition: query.c:184
static HRESULT eval_strcmp(UINT op, const WCHAR *lstr, const WCHAR *rstr, LONGLONG *val)
Definition: query.c:111
static const WCHAR * format_int(WCHAR *buf, UINT len, CIMTYPE type, LONGLONG val)
Definition: query.c:280
GLuint GLfloat * val
Definition: glext.h:7180
#define OP_LT
Definition: query.h:40
#define OP_GT
Definition: query.h:39
#define OP_EQ
Definition: query.h:36
#define OP_GE
Definition: query.h:42
#define OP_AND
Definition: query.h:37
#define OP_NE
Definition: query.h:43
#define OP_OR
Definition: query.h:38
#define OP_LE
Definition: query.h:41
LOCAL char * rstr(char *s1, char *s2)
Definition: tree.c:165
Definition: query.h:87
int32_t INT_PTR
Definition: typedefs.h:64
int64_t LONGLONG
Definition: typedefs.h:68
@ WBEM_E_INVALID_QUERY
Definition: wbemcli.idl:73

Referenced by eval_cond().

◆ eval_boolcmp()

static HRESULT eval_boolcmp ( UINT  op,
LONGLONG  lval,
LONGLONG  rval,
UINT  ltype,
UINT  rtype,
LONGLONG val 
)
static

Definition at line 184 of file query.c.

185{
186 static const WCHAR trueW[] = {'T','r','u','e',0};
187
188 if (ltype == CIM_STRING) lval = !wcsicmp( (const WCHAR *)(INT_PTR)lval, trueW ) ? -1 : 0;
189 else if (rtype == CIM_STRING) rval = !wcsicmp( (const WCHAR *)(INT_PTR)rval, trueW ) ? -1 : 0;
190
191 switch (op)
192 {
193 case OP_EQ:
194 *val = (lval == rval);
195 break;
196 case OP_NE:
197 *val = (lval != rval);
198 break;
199 default:
200 ERR("unhandled operator %u\n", op);
202 }
203 return S_OK;
204}
UINT op
Definition: effect.c:236
#define wcsicmp
Definition: compat.h:15
static const WCHAR trueW[]
Definition: json.c:33
@ CIM_STRING
Definition: wbemcli.idl:243

Referenced by eval_binary().

◆ eval_cond()

HRESULT eval_cond ( const struct table table,
UINT  row,
const struct expr cond,
LONGLONG val,
UINT type 
)

Definition at line 440 of file query.c.

441{
442 if (!cond)
443 {
444 *val = 1;
445 *type = CIM_UINT64;
446 return S_OK;
447 }
448 switch (cond->type)
449 {
450 case EXPR_COMPLEX:
451 return eval_binary( table, row, &cond->u.expr, val, type );
452
453 case EXPR_UNARY:
454 return eval_unary( table, row, &cond->u.expr, val, type );
455
456 case EXPR_PROPVAL:
457 return eval_propval( table, row, cond->u.propval, val, type );
458
459 case EXPR_SVAL:
460 *val = (INT_PTR)cond->u.sval;
461 *type = CIM_STRING;
462 return S_OK;
463
464 case EXPR_IVAL:
465 *val = cond->u.ival;
466 *type = CIM_UINT64;
467 return S_OK;
468
469 case EXPR_BVAL:
470 *val = cond->u.ival;
471 *type = CIM_BOOLEAN;
472 return S_OK;
473
474 default:
475 ERR("invalid expression type\n");
476 break;
477 }
479}
@ EXPR_PROPVAL
Definition: parser.h:273
static HRESULT eval_binary(const struct table *table, UINT row, const struct complex_expr *expr, LONGLONG *val, UINT *type)
Definition: query.c:315
static HRESULT eval_propval(const struct table *table, UINT row, const struct property *propval, LONGLONG *val, UINT *type)
Definition: query.c:425
static HRESULT eval_unary(const struct table *table, UINT row, const struct complex_expr *expr, LONGLONG *val, UINT *type)
Definition: query.c:383
#define EXPR_COMPLEX
Definition: query.h:47
#define EXPR_IVAL
Definition: query.h:50
#define EXPR_UNARY
Definition: query.h:57
#define EXPR_SVAL
Definition: query.h:51
struct complex_expr expr
Definition: query.h:91
const struct property * propval
union expr::@507 u
int type
Definition: query.h:88
LPCWSTR sval
Definition: query.h:94
INT ival
Definition: query.h:92
@ CIM_BOOLEAN
Definition: wbemcli.idl:244
@ CIM_UINT64
Definition: wbemcli.idl:251
@ EXPR_BVAL

Referenced by eval_binary(), eval_unary(), exec_select_view(), and match_row().

◆ eval_like()

static BOOL eval_like ( const WCHAR lstr,
const WCHAR rstr 
)
static

Definition at line 93 of file query.c.

94{
95 const WCHAR *p = lstr, *q = rstr;
96
97 while (*p && *q)
98 {
99 if (*q == '%')
100 {
101 while (*q == '%') q++;
102 if (!*q) return TRUE;
103 while (*p && *q && towupper( *p ) == towupper( *q )) { p++; q++; };
104 if (!*p && !*q) return TRUE;
105 }
106 if (*q != '%' && towupper( *p++ ) != towupper( *q++ )) return FALSE;
107 }
108 return TRUE;
109}
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
GLdouble GLdouble GLdouble GLdouble q
Definition: gl.h:2063

Referenced by eval_strcmp().

◆ eval_propval()

static HRESULT eval_propval ( const struct table table,
UINT  row,
const struct property propval,
LONGLONG val,
UINT type 
)
static

Definition at line 425 of file query.c.

428{
429 HRESULT hr;
430 UINT column;
431
432 hr = get_column_index( table, propval->name, &column );
433 if (hr != S_OK)
434 return hr;
435
437 return get_value( table, row, column, val );
438}
HRESULT get_value(const struct table *table, UINT row, UINT column, LONGLONG *val)
Definition: table.c:99
HRESULT get_column_index(const struct table *table, const WCHAR *name, UINT *column)
Definition: table.c:35
BSTR name
Definition: locator.c:107
#define CIM_TYPE_MASK

Referenced by eval_cond().

◆ eval_refcmp()

static HRESULT eval_refcmp ( UINT  op,
const WCHAR lstr,
const WCHAR rstr,
LONGLONG val 
)
static

Definition at line 213 of file query.c.

214{
215 if (!lstr || !rstr)
216 {
217 *val = 0;
218 return S_OK;
219 }
220 switch (op)
221 {
222 case OP_EQ:
223 *val = !wcsicmp( lstr, rstr );
224 break;
225 case OP_NE:
226 *val = wcsicmp( lstr, rstr );
227 break;
228 default:
229 ERR("unhandled operator %u\n", op);
231 }
232 return S_OK;
233}

Referenced by eval_binary().

◆ eval_strcmp()

static HRESULT eval_strcmp ( UINT  op,
const WCHAR lstr,
const WCHAR rstr,
LONGLONG val 
)
static

Definition at line 111 of file query.c.

112{
113 if (!lstr || !rstr)
114 {
115 *val = 0;
116 return S_OK;
117 }
118 switch (op)
119 {
120 case OP_EQ:
121 *val = !wcscmp( lstr, rstr );
122 break;
123 case OP_GT:
124 *val = wcscmp( lstr, rstr ) > 0;
125 break;
126 case OP_LT:
127 *val = wcscmp( lstr, rstr ) < 0;
128 break;
129 case OP_LE:
130 *val = wcscmp( lstr, rstr ) <= 0;
131 break;
132 case OP_GE:
133 *val = wcscmp( lstr, rstr ) >= 0;
134 break;
135 case OP_NE:
136 *val = wcscmp( lstr, rstr );
137 break;
138 case OP_LIKE:
139 *val = eval_like( lstr, rstr );
140 break;
141 default:
142 ERR("unhandled operator %u\n", op);
144 }
145 return S_OK;
146}
static BOOL eval_like(const WCHAR *lstr, const WCHAR *rstr)
Definition: query.c:93
_Check_return_ _CRTIMP int __cdecl wcscmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)
@ OP_LIKE

Referenced by eval_binary().

◆ eval_unary()

static HRESULT eval_unary ( const struct table table,
UINT  row,
const struct complex_expr expr,
LONGLONG val,
UINT type 
)
static

Definition at line 383 of file query.c.

386{
387 HRESULT hr;
388 UINT column;
389 LONGLONG lval;
390
391 if (expr->op == OP_NOT)
392 {
393 hr = eval_cond( table, row, expr->left, &lval, type );
394 if (hr != S_OK)
395 return hr;
396 *val = !lval;
397 return S_OK;
398 }
399
400 hr = get_column_index( table, expr->left->u.propval->name, &column );
401 if (hr != S_OK)
402 return hr;
403
404 hr = get_value( table, row, column, &lval );
405 if (hr != S_OK)
406 return hr;
407
408 switch (expr->op)
409 {
410 case OP_ISNULL:
411 *val = !lval;
412 break;
413 case OP_NOTNULL:
414 *val = lval;
415 break;
416 default:
417 ERR("unknown operator %u\n", expr->op);
419 }
420
422 return S_OK;
423}
#define OP_NOTNULL
Definition: query.h:45
#define OP_ISNULL
Definition: query.h:44
@ OP_NOT

Referenced by eval_cond().

◆ exec_assoc_view()

static HRESULT exec_assoc_view ( struct view view)
static

Definition at line 646 of file query.c.

647{
648 static const WCHAR assocclassW[] = {'A','s','s','o','c','C','l','a','s','s',0};
650 struct path *path;
651 HRESULT hr;
652
653 if (view->keywordlist) FIXME( "ignoring keywords\n" );
654 if ((hr = parse_path( view->path, &path )) != S_OK) return hr;
655
656 if ((hr = create_assoc_enum( path->class, path->class_len, &iter )) != S_OK) goto done;
657 for (;;)
658 {
659 ULONG count;
661 struct table *table;
662 VARIANT var;
663
664 IEnumWbemClassObject_Next( iter, WBEM_INFINITE, 1, &obj, &count );
665 if (!count) break;
666
667 if ((hr = IWbemClassObject_Get( obj, assocclassW, 0, &var, NULL, NULL )) != S_OK)
668 {
669 IWbemClassObject_Release( obj );
670 goto done;
671 }
672 IWbemClassObject_Release( obj );
673
675 VariantClear( &var );
676 if (hr != S_OK) goto done;
677
678 if (table && (hr = append_table( view, table )) != S_OK)
679 {
681 goto done;
682 }
683 }
684
685 if (view->table_count)
686 {
687 if (!(view->result = heap_alloc_zero( view->table_count * sizeof(UINT) ))) hr = E_OUTOFMEMORY;
689 }
690
691done:
692 if (iter) IEnumWbemClassObject_Release( iter );
693 free_path( path );
694 return hr;
695}
#define FIXME(fmt,...)
Definition: debug.h:111
static void free_path(struct btrfs_path *path)
Definition: btrfs.c:173
static HRESULT parse_path(const WCHAR *str, BSTR *server, BSTR *namespace, BSTR *relative)
Definition: main.c:309
static HRESULT get_antecedent_table(const WCHAR *assocclass, const WCHAR *dependent, struct table **table)
Definition: query.c:613
static HRESULT create_assoc_enum(const WCHAR *class, UINT class_len, IEnumWbemClassObject **iter)
Definition: query.c:494
const char * var
Definition: shader.c:5666
#define V_BSTR(A)
Definition: oleauto.h:226
UINT class_len
WCHAR * class
UINT result_count
HRESULT WINAPI DECLSPEC_HOTPATCH VariantClear(VARIANTARG *pVarg)
Definition: variant.c:648
@ WBEM_INFINITE
Definition: wbemcli.idl:189

Referenced by execute_view().

◆ exec_query()

HRESULT exec_query ( const WCHAR str,
IEnumWbemClassObject **  result 
)

Definition at line 786 of file query.c.

787{
788 HRESULT hr;
789 struct query *query;
790
791 *result = NULL;
792 if (!(query = create_query())) return E_OUTOFMEMORY;
793 hr = parse_query( str, &query->view, &query->mem );
794 if (hr != S_OK) goto done;
796 if (hr != S_OK) goto done;
798
799done:
801 return hr;
802}
HRESULT EnumWbemClassObject_create(struct query *query, LPVOID *ppObj)
Definition: class.c:199
GLuint64EXT * result
Definition: glext.h:11304

Referenced by async_exec_query(), create_assoc_enum(), create_instance_enum(), create_qualifier_enum(), create_signature(), get_antecedent(), test_associators(), test_select(), and wbem_services_ExecQuery().

◆ exec_select_view()

static HRESULT exec_select_view ( struct view view)
static

Definition at line 697 of file query.c.

698{
699 UINT i, j = 0, len;
701 struct table *table;
702
703 if (!view->table_count) return S_OK;
704
705 table = view->table[0];
706 if (table->fill)
707 {
709 status = table->fill( table, view->cond );
710 }
712 if (!table->num_rows) return S_OK;
713
714 len = min( table->num_rows, 16 );
715 if (!(view->result = heap_alloc( len * sizeof(UINT) ))) return E_OUTOFMEMORY;
716
717 for (i = 0; i < table->num_rows; i++)
718 {
719 HRESULT hr;
720 LONGLONG val = 0;
721 UINT type;
722
723 if (j >= len)
724 {
725 UINT *tmp;
726 len *= 2;
727 if (!(tmp = heap_realloc( view->result, len * sizeof(UINT) ))) return E_OUTOFMEMORY;
728 view->result = tmp;
729 }
730 if (status == FILL_STATUS_FILTERED) val = 1;
731 else if ((hr = eval_cond( table, i, view->cond, &val, &type )) != S_OK) return hr;
732 if (val) view->result[j++] = i;
733 }
734
736 return S_OK;
737}
void clear_table(struct table *table)
Definition: table.c:314
#define min(a, b)
Definition: monoChain.cc:55
Definition: ps.c:97
UINT num_rows
enum fill_status(* fill)(struct table *, const struct expr *cond)
@ WBEM_E_FAILED
Definition: wbemcli.idl:51
fill_status
@ FILL_STATUS_UNFILTERED
@ FILL_STATUS_FAILED
@ FILL_STATUS_FILTERED

Referenced by execute_view().

◆ execute_view()

HRESULT execute_view ( struct view view)

Definition at line 739 of file query.c.

740{
741 switch (view->type)
742 {
744 return exec_assoc_view( view );
745
746 case VIEW_TYPE_SELECT:
747 return exec_select_view( view );
748
749 default:
750 ERR( "unhandled type %u\n", view->type );
751 return E_INVALIDARG;
752 }
753}
static HRESULT exec_assoc_view(struct view *view)
Definition: query.c:646
static HRESULT exec_select_view(struct view *view)
Definition: query.c:697

Referenced by do_query(), exec_query(), get_diskdrivetodiskpartition_pairs(), get_logicaldisktopartition_pairs(), and wbem_services_ExecMethod().

◆ format_int()

static const WCHAR * format_int ( WCHAR buf,
UINT  len,
CIMTYPE  type,
LONGLONG  val 
)
static

Definition at line 280 of file query.c.

281{
282 static const WCHAR fmt_signedW[] = {'%','d',0};
283 static const WCHAR fmt_unsignedW[] = {'%','u',0};
284 static const WCHAR fmt_signed64W[] = {'%','I','6','4','d',0};
285 static const WCHAR fmt_unsigned64W[] = {'%','I','6','4','u',0};
286
287 switch (type)
288 {
289 case CIM_SINT8:
290 case CIM_SINT16:
291 case CIM_SINT32:
292 swprintf( buf, fmt_signedW, val );
293 return buf;
294
295 case CIM_UINT8:
296 case CIM_UINT16:
297 case CIM_UINT32:
298 swprintf( buf, fmt_unsignedW, val );
299 return buf;
300
301 case CIM_SINT64:
302 wsprintfW( buf, fmt_signed64W, val );
303 return buf;
304
305 case CIM_UINT64:
306 wsprintfW( buf, fmt_unsigned64W, val );
307 return buf;
308
309 default:
310 ERR( "unhandled type %u\n", type );
311 return NULL;
312 }
313}
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
@ CIM_UINT32
Definition: wbemcli.idl:249
@ CIM_UINT8
Definition: wbemcli.idl:247
@ CIM_SINT64
Definition: wbemcli.idl:250
@ CIM_UINT16
Definition: wbemcli.idl:248
@ CIM_SINT8
Definition: wbemcli.idl:246
@ CIM_SINT16
Definition: wbemcli.idl:239
@ CIM_SINT32
Definition: wbemcli.idl:240
int WINAPIV wsprintfW(_Out_ LPWSTR, _In_ _Printf_format_string_ LPCWSTR,...)

Referenced by eval_binary().

◆ free_query()

void free_query ( struct query query)

Definition at line 765 of file query.c.

766{
767 struct list *mem, *next;
768
769 if (!query) return;
772 heap_free( query );
773}
Definition: list.h:37
void destroy_view(struct view *view)
Definition: query.c:83
static unsigned __int64 next
Definition: rand_nt.c:6
#define LIST_FOR_EACH_SAFE(cursor, cursor2, list)
Definition: list.h:192
Definition: mem.c:156

Referenced by get_diskdrivetodiskpartition_pairs(), get_logicaldisktopartition_pairs(), release_query(), and wbem_services_ExecMethod().

◆ get_antecedent()

static HRESULT get_antecedent ( const WCHAR assocclass,
const WCHAR dependent,
BSTR ret 
)
static

Definition at line 565 of file query.c.

566{
567 static const WCHAR antecedentW[] = {'A','n','t','e','c','e','d','e','n','t',0};
568 WCHAR *fullpath, *str;
572 ULONG count;
573 VARIANT var;
574
575 if (!(fullpath = build_canonical_path( dependent ))) return E_OUTOFMEMORY;
576 if (!(str = build_antecedent_query( assocclass, fullpath ))) goto done;
577 if ((hr = exec_query( str, &iter )) != S_OK) goto done;
578
579 IEnumWbemClassObject_Next( iter, WBEM_INFINITE, 1, &obj, &count );
580 if (!count)
581 {
582 *ret = NULL;
583 goto done;
584 }
585
586 hr = IWbemClassObject_Get( obj, antecedentW, 0, &var, NULL, NULL );
587 IWbemClassObject_Release( obj );
588 if (hr != S_OK) goto done;
589 *ret = V_BSTR( &var );
590
591done:
592 if (iter) IEnumWbemClassObject_Release( iter );
593 heap_free( str );
594 heap_free( fullpath );
595 return hr;
596}
static WCHAR * build_canonical_path(const WCHAR *relpath)
Definition: query.c:534
static WCHAR * build_antecedent_query(const WCHAR *assocclass, const WCHAR *dependent)
Definition: query.c:505

Referenced by get_antecedent_table().

◆ get_antecedent_table()

static HRESULT get_antecedent_table ( const WCHAR assocclass,
const WCHAR dependent,
struct table **  table 
)
static

Definition at line 613 of file query.c.

614{
615 BSTR antecedent = NULL;
616 struct path *path = NULL;
617 WCHAR *str = NULL;
618 struct query *query = NULL;
619 HRESULT hr;
620
621 if ((hr = get_antecedent( assocclass, dependent, &antecedent )) != S_OK) return hr;
622 if (!antecedent)
623 {
624 *table = NULL;
625 return S_OK;
626 }
627 if ((hr = parse_path( antecedent, &path )) != S_OK) goto done;
628 if (!(str = query_from_path( path )))
629 {
631 goto done;
632 }
633
634 if ((hr = do_query( str, &query )) != S_OK) goto done;
635 if (query->view->table_count) *table = addref_table( query->view->table[0] );
636 else *table = NULL;
637
638done:
639 if (query) release_query( query );
640 free_path( path );
641 SysFreeString( antecedent );
642 heap_free( str );
643 return hr;
644}
static HRESULT get_antecedent(const WCHAR *assocclass, const WCHAR *dependent, BSTR *ret)
Definition: query.c:565
static HRESULT do_query(const WCHAR *str, struct query **ret_query)
Definition: query.c:598
WCHAR * query_from_path(const struct path *path)
Definition: services.c:421
struct table * addref_table(struct table *table)
Definition: table.c:359

Referenced by exec_assoc_view().

◆ get_properties()

HRESULT get_properties ( const struct view view,
UINT  index,
LONG  flags,
SAFEARRAY **  props 
)

Definition at line 1401 of file query.c.

1402{
1403 SAFEARRAY *sa;
1404 BSTR str;
1405 UINT i, table_index, result_index, num_props;
1406 struct table *table;
1407 HRESULT hr;
1408 LONG j;
1409
1410 if ((hr = map_view_index( view, index, &table_index, &result_index )) != S_OK) return hr;
1411
1412 num_props = count_result_properties( view, table_index );
1413 if (!(sa = SafeArrayCreateVector( VT_BSTR, 0, num_props ))) return E_OUTOFMEMORY;
1414
1415 table = view->table[table_index];
1416 for (i = 0, j = 0; i < table->num_cols; i++)
1417 {
1418 BOOL is_system;
1419
1420 if (is_method( table, i )) continue;
1421 if (!is_result_prop( view, table->columns[i].name )) continue;
1422
1423 is_system = is_system_prop( table->columns[i].name );
1424 if ((flags & WBEM_FLAG_NONSYSTEM_ONLY) && is_system) continue;
1425 else if ((flags & WBEM_FLAG_SYSTEM_ONLY) && !is_system) continue;
1426
1427 str = SysAllocString( table->columns[i].name );
1428 if (!str || SafeArrayPutElement( sa, &j, str ) != S_OK)
1429 {
1430 SysFreeString( str );
1432 return E_OUTOFMEMORY;
1433 }
1434 SysFreeString( str );
1435 j++;
1436 }
1437 *props = sa;
1438 return S_OK;
1439}
static struct sockaddr_in sa
Definition: adnsresfilter.c:69
@ VT_BSTR
Definition: compat.h:2303
SAFEARRAY *WINAPI SafeArrayCreateVector(VARTYPE vt, LONG lLbound, ULONG cElements)
Definition: safearray.c:677
HRESULT WINAPI SafeArrayDestroy(SAFEARRAY *psa)
Definition: safearray.c:1347
HRESULT WINAPI SafeArrayPutElement(SAFEARRAY *psa, LONG *rgIndices, void *pvData)
Definition: safearray.c:864
static BOOL is_system_prop(const WCHAR *name)
Definition: query.c:816
BOOL is_result_prop(const struct view *view, const WCHAR *name)
Definition: query.c:804
static HRESULT map_view_index(const struct view *view, UINT index, UINT *table_index, UINT *result_index)
Definition: query.c:1139
static UINT count_result_properties(const struct view *view, UINT table_index)
Definition: query.c:933
unsigned int BOOL
Definition: ntddk_ex.h:94
GLuint index
Definition: glext.h:6031
GLbitfield flags
Definition: glext.h:7161
long LONG
Definition: pedump.c:60
@ WBEM_FLAG_NONSYSTEM_ONLY
Definition: wbemcli.idl:204
@ WBEM_FLAG_SYSTEM_ONLY
Definition: wbemcli.idl:203
static const WCHAR props[]
Definition: wbemdisp.c:288

Referenced by class_object_GetNames().

◆ get_propval()

HRESULT get_propval ( const struct view view,
UINT  index,
const WCHAR name,
VARIANT ret,
CIMTYPE type,
LONG flavor 
)

Definition at line 1177 of file query.c.

1179{
1180 HRESULT hr;
1181 UINT column, row, table_index, result_index;
1182 struct table *table;
1183 VARTYPE vartype;
1184 void *val_ptr = NULL;
1185 LONGLONG val;
1186
1187 if ((hr = map_view_index( view, index, &table_index, &result_index )) != S_OK) return hr;
1188
1189 if (is_system_prop( name )) return get_system_propval( view, table_index, result_index, name, ret, type, flavor );
1191
1192 table = view->table[table_index];
1194 if (hr != S_OK || is_method( table, column )) return WBEM_E_NOT_FOUND;
1195
1196 row = view->result[result_index];
1197 hr = get_value( table, row, column, &val );
1198 if (hr != S_OK) return hr;
1199
1200 if (type) *type = table->columns[column].type & COL_TYPE_MASK;
1201 if (flavor) *flavor = 0;
1202
1203 if (!ret) return S_OK;
1204
1205 vartype = to_vartype( table->columns[column].type & CIM_TYPE_MASK );
1206 if (table->columns[column].type & CIM_FLAG_ARRAY)
1207 {
1208 CIMTYPE basetype = table->columns[column].type & CIM_TYPE_MASK;
1209
1210 val_ptr = to_safearray( (const struct array *)(INT_PTR)val, basetype );
1211 if (!val_ptr) vartype = VT_NULL;
1212 else vartype |= VT_ARRAY;
1213 set_variant( vartype, val, val_ptr, ret );
1214 return S_OK;
1215 }
1216
1217 switch (table->columns[column].type & COL_TYPE_MASK)
1218 {
1219 case CIM_STRING:
1220 case CIM_REFERENCE:
1221 case CIM_DATETIME:
1222 if (val)
1223 {
1224 vartype = VT_BSTR;
1225 val_ptr = SysAllocString( (const WCHAR *)(INT_PTR)val );
1226 }
1227 else
1228 vartype = VT_NULL;
1229 break;
1230 case CIM_SINT64:
1231 vartype = VT_BSTR;
1232 val_ptr = get_value_bstr( table, row, column );
1233 break;
1234 case CIM_UINT64:
1235 vartype = VT_BSTR;
1236 val_ptr = get_value_bstr( table, row, column );
1237 break;
1238 case CIM_BOOLEAN:
1239 case CIM_SINT8:
1240 case CIM_UINT8:
1241 case CIM_SINT16:
1242 case CIM_UINT16:
1243 case CIM_SINT32:
1244 case CIM_UINT32:
1245 case CIM_REAL32:
1246 break;
1247 default:
1248 ERR("unhandled column type %u\n", table->columns[column].type);
1249 return WBEM_E_FAILED;
1250 }
1251
1252 set_variant( vartype, val, val_ptr, ret );
1253 return S_OK;
1254}
unsigned short VARTYPE
Definition: compat.h:2254
@ VT_NULL
Definition: compat.h:2296
@ VT_ARRAY
Definition: compat.h:2341
VARTYPE to_vartype(CIMTYPE type)
Definition: query.c:1032
static HRESULT get_system_propval(const struct view *view, UINT table_index, UINT result_index, const WCHAR *name, VARIANT *ret, CIMTYPE *type, LONG *flavor)
Definition: query.c:945
SAFEARRAY * to_safearray(const struct array *array, CIMTYPE basetype)
Definition: query.c:1062
void set_variant(VARTYPE type, LONGLONG val, void *val_ptr, VARIANT *ret)
Definition: query.c:1093
@ CIM_REFERENCE
Definition: wbemcli.idl:253
@ CIM_DATETIME
Definition: wbemcli.idl:252
@ CIM_REAL32
Definition: wbemcli.idl:241
@ CIM_FLAG_ARRAY
Definition: wbemcli.idl:255
long CIMTYPE
Definition: wbemcli.idl:258
@ WBEM_E_NOT_FOUND
Definition: wbemcli.idl:52
#define COL_TYPE_MASK

Referenced by class_object_Get(), class_object_Next(), get_diskdrivetodiskpartition_pairs(), and get_logicaldisktopartition_pairs().

◆ get_system_propval()

static HRESULT get_system_propval ( const struct view view,
UINT  table_index,
UINT  result_index,
const WCHAR name,
VARIANT ret,
CIMTYPE type,
LONG flavor 
)
static

Definition at line 945 of file query.c.

947{
948 static const WCHAR classW[] = {'_','_','C','L','A','S','S',0};
949 static const WCHAR genusW[] = {'_','_','G','E','N','U','S',0};
950 static const WCHAR pathW[] = {'_','_','P','A','T','H',0};
951 static const WCHAR namespaceW[] = {'_','_','N','A','M','E','S','P','A','C','E',0};
952 static const WCHAR propcountW[] = {'_','_','P','R','O','P','E','R','T','Y','_','C','O','U','N','T',0};
953 static const WCHAR relpathW[] = {'_','_','R','E','L','P','A','T','H',0};
954 static const WCHAR serverW[] = {'_','_','S','E','R','V','E','R',0};
955
956 if (flavor) *flavor = WBEM_FLAVOR_ORIGIN_SYSTEM;
957
958 if (!wcsicmp( name, classW ))
959 {
960 if (ret)
961 {
962 V_VT( ret ) = VT_BSTR;
963 V_BSTR( ret ) = SysAllocString( view->table[table_index]->name );
964 }
965 if (type) *type = CIM_STRING;
966 return S_OK;
967 }
968 if (!wcsicmp( name, genusW ))
969 {
970 if (ret)
971 {
972 V_VT( ret ) = VT_I4;
973 V_I4( ret ) = WBEM_GENUS_INSTANCE; /* FIXME */
974 }
975 if (type) *type = CIM_SINT32;
976 return S_OK;
977 }
978 else if (!wcsicmp( name, namespaceW ))
979 {
980 if (ret)
981 {
982 V_VT( ret ) = VT_BSTR;
984 }
985 if (type) *type = CIM_STRING;
986 return S_OK;
987 }
988 else if (!wcsicmp( name, pathW ))
989 {
990 if (ret)
991 {
992 V_VT( ret ) = VT_BSTR;
993 V_BSTR( ret ) = build_path( view, table_index, result_index, name );
994 }
995 if (type) *type = CIM_STRING;
996 return S_OK;
997 }
998 if (!wcsicmp( name, propcountW ))
999 {
1000 if (ret)
1001 {
1002 V_VT( ret ) = VT_I4;
1003 V_I4( ret ) = count_result_properties( view, table_index );
1004 }
1005 if (type) *type = CIM_SINT32;
1006 return S_OK;
1007 }
1008 else if (!wcsicmp( name, relpathW ))
1009 {
1010 if (ret)
1011 {
1012 V_VT( ret ) = VT_BSTR;
1013 V_BSTR( ret ) = build_relpath( view, table_index, result_index, name );
1014 }
1015 if (type) *type = CIM_STRING;
1016 return S_OK;
1017 }
1018 else if (!wcsicmp( name, serverW ))
1019 {
1020 if (ret)
1021 {
1022 V_VT( ret ) = VT_BSTR;
1024 }
1025 if (type) *type = CIM_STRING;
1026 return S_OK;
1027 }
1028 FIXME("system property %s not implemented\n", debugstr_w(name));
1029 return WBEM_E_NOT_FOUND;
1030}
@ VT_I4
Definition: compat.h:2298
static BSTR build_path(const struct view *view, UINT table_index, UINT result_index, const WCHAR *name)
Definition: query.c:894
#define debugstr_w
Definition: kernel32.h:32
#define V_VT(A)
Definition: oleauto.h:211
#define V_I4(A)
Definition: oleauto.h:247
static const WCHAR classW[]
Definition: lex.c:40
@ WBEM_FLAVOR_ORIGIN_SYSTEM
Definition: wbemcli.idl:222
@ WBEM_GENUS_INSTANCE
Definition: wbemcli.idl:232

Referenced by get_propval().

◆ get_view_table()

struct table * get_view_table ( const struct view view,
UINT  index 
)

Definition at line 1161 of file query.c.

1162{
1163 switch (view->type)
1164 {
1165 case VIEW_TYPE_SELECT:
1166 return view->table[0];
1167
1169 return view->table[index];
1170
1171 default:
1172 ERR( "unhandled view type %u\n", view->type );
1173 return NULL;
1174 }
1175}
#define index(s, c)
Definition: various.h:29

Referenced by class_object_Next(), class_object_SpawnInstance(), enum_class_object_Next(), get_object_text(), and wbem_services_ExecMethod().

◆ is_boolcmp()

static BOOL is_boolcmp ( const struct complex_expr expr,
UINT  ltype,
UINT  rtype 
)
inlinestatic

Definition at line 175 of file query.c.

176{
177 if (ltype == CIM_BOOLEAN && expr->left->type == EXPR_PROPVAL &&
178 (expr->right->type == EXPR_SVAL || expr->right->type == EXPR_BVAL)) return TRUE;
179 else if (rtype == CIM_BOOLEAN && expr->right->type == EXPR_PROPVAL &&
180 (expr->left->type == EXPR_SVAL || expr->left->type == EXPR_BVAL)) return TRUE;
181 return FALSE;
182}

Referenced by eval_binary().

◆ is_int()

static BOOL is_int ( CIMTYPE  type)
static

Definition at line 148 of file query.c.

149{
150 switch (type)
151 {
152 case CIM_SINT8:
153 case CIM_SINT16:
154 case CIM_SINT32:
155 case CIM_SINT64:
156 case CIM_UINT8:
157 case CIM_UINT16:
158 case CIM_UINT32:
159 case CIM_UINT64:
160 return TRUE;
161 default:
162 return FALSE;
163 }
164}

Referenced by eval_binary(), and is_strcmp().

◆ is_method()

BOOL is_method ( const struct table table,
UINT  column 
)

Definition at line 917 of file query.c.

918{
919 return table->columns[column].type & COL_FLAG_METHOD;
920}
#define COL_FLAG_METHOD

Referenced by class_object_Next(), count_properties(), get_properties(), get_propval(), and put_propval().

◆ is_refcmp()

static BOOL is_refcmp ( const struct complex_expr expr,
UINT  ltype,
UINT  rtype 
)
inlinestatic

Definition at line 206 of file query.c.

207{
208 if (ltype == CIM_REFERENCE && expr->left->type == EXPR_PROPVAL && expr->right->type == EXPR_SVAL) return TRUE;
209 else if (rtype == CIM_REFERENCE && expr->right->type == EXPR_PROPVAL && expr->left->type == EXPR_SVAL) return TRUE;
210 return FALSE;
211}

Referenced by eval_binary().

◆ is_result_prop()

BOOL is_result_prop ( const struct view view,
const WCHAR name 
)

Definition at line 804 of file query.c.

805{
806 const struct property *prop = view->proplist;
807 if (!prop) return TRUE;
808 while (prop)
809 {
810 if (!wcsicmp( prop->name, name )) return TRUE;
811 prop = prop->next;
812 }
813 return FALSE;
814}

Referenced by class_object_Next(), get_properties(), and get_propval().

◆ is_strcmp()

static BOOL is_strcmp ( const struct complex_expr expr,
UINT  ltype,
UINT  rtype 
)
inlinestatic

Definition at line 166 of file query.c.

167{
168 if ((ltype == CIM_STRING || is_int( ltype )) && expr->left->type == EXPR_PROPVAL &&
169 expr->right->type == EXPR_SVAL) return TRUE;
170 else if ((rtype == CIM_STRING || is_int( rtype )) && expr->right->type == EXPR_PROPVAL &&
171 expr->left->type == EXPR_SVAL) return TRUE;
172 return FALSE;
173}

Referenced by eval_binary().

◆ is_system_prop()

static BOOL is_system_prop ( const WCHAR name)
static

Definition at line 816 of file query.c.

817{
818 return (name[0] == '_' && name[1] == '_');
819}

Referenced by get_properties(), and get_propval().

◆ map_view_index()

static HRESULT map_view_index ( const struct view view,
UINT  index,
UINT table_index,
UINT result_index 
)
static

Definition at line 1139 of file query.c.

1140{
1141 if (!view->table) return WBEM_E_NOT_FOUND;
1142
1143 switch (view->type)
1144 {
1145 case VIEW_TYPE_SELECT:
1146 *table_index = 0;
1147 *result_index = index;
1148 break;
1149
1151 *table_index = *result_index = index;
1152 break;
1153
1154 default:
1155 ERR( "unhandled view type %u\n", view->type );
1156 return WBEM_E_FAILED;
1157 }
1158 return S_OK;
1159}

Referenced by get_properties(), get_propval(), and put_propval().

◆ put_propval()

HRESULT put_propval ( const struct view view,
UINT  index,
const WCHAR name,
VARIANT var,
CIMTYPE  type 
)

Definition at line 1375 of file query.c.

1376{
1377 HRESULT hr;
1378 UINT row, column, table_index, result_index;
1379 struct table *table;
1380 LONGLONG val;
1381
1382 if ((hr = map_view_index( view, index, &table_index, &result_index )) != S_OK) return hr;
1383
1384 table = view->table[table_index];
1386 if (hr != S_OK)
1387 {
1388 FIXME("no support for creating new properties\n");
1389 return WBEM_E_FAILED;
1390 }
1391 if (is_method( table, column ) || !(table->columns[column].type & COL_FLAG_DYNAMIC))
1392 return WBEM_E_FAILED;
1393
1394 hr = to_longlong( var, &val, &type );
1395 if (hr != S_OK) return hr;
1396
1397 row = view->result[result_index];
1398 return set_value( table, row, column, val, type );
1399}
static HRESULT set_value(struct d3dx_parameter *param, const void *data, unsigned int bytes, void *dst_data)
Definition: effect.c:889
HRESULT to_longlong(VARIANT *var, LONGLONG *val, CIMTYPE *type)
Definition: query.c:1325
#define COL_FLAG_DYNAMIC

Referenced by class_object_Put().

◆ release_query()

void release_query ( struct query query)

Definition at line 781 of file query.c.

782{
784}
#define InterlockedDecrement
Definition: armddk.h:52
void free_query(struct query *query)
Definition: query.c:765

Referenced by do_query(), enum_class_object_Release(), exec_query(), and get_antecedent_table().

◆ resolve_type()

static UINT resolve_type ( UINT  left,
UINT  right 
)
static

Definition at line 235 of file query.c.

236{
237 switch (left)
238 {
239 case CIM_SINT8:
240 case CIM_SINT16:
241 case CIM_SINT32:
242 case CIM_SINT64:
243 case CIM_UINT8:
244 case CIM_UINT16:
245 case CIM_UINT32:
246 case CIM_UINT64:
247 switch (right)
248 {
249 case CIM_SINT8:
250 case CIM_SINT16:
251 case CIM_SINT32:
252 case CIM_SINT64:
253 case CIM_UINT8:
254 case CIM_UINT16:
255 case CIM_UINT32:
256 case CIM_UINT64:
257 return CIM_UINT64;
258 default: break;
259 }
260 break;
261
262 case CIM_STRING:
263 if (right == CIM_STRING) return CIM_STRING;
264 break;
265
266 case CIM_BOOLEAN:
267 if (right == CIM_BOOLEAN) return CIM_BOOLEAN;
268 break;
269
270 case CIM_REFERENCE:
271 if (right == CIM_REFERENCE) return CIM_REFERENCE;
272 break;
273
274 default:
275 break;
276 }
277 return CIM_ILLEGAL;
278}
GLdouble GLdouble right
Definition: glext.h:10859
GLint left
Definition: glext.h:7726
@ CIM_ILLEGAL
Definition: wbemcli.idl:237

Referenced by eval_binary().

◆ set_variant()

void set_variant ( VARTYPE  type,
LONGLONG  val,
void val_ptr,
VARIANT ret 
)

Definition at line 1093 of file query.c.

1094{
1095 if (type & VT_ARRAY)
1096 {
1097 V_VT( ret ) = type;
1098 V_ARRAY( ret ) = val_ptr;
1099 return;
1100 }
1101 switch (type)
1102 {
1103 case VT_BOOL:
1104 V_BOOL( ret ) = val;
1105 break;
1106 case VT_BSTR:
1107 V_BSTR( ret ) = val_ptr;
1108 break;
1109 case VT_I1:
1110 V_I1( ret ) = val;
1111 break;
1112 case VT_UI1:
1113 V_UI1( ret ) = val;
1114 break;
1115 case VT_I2:
1116 V_I2( ret ) = val;
1117 break;
1118 case VT_UI2:
1119 V_UI2( ret ) = val;
1120 break;
1121 case VT_I4:
1122 V_I4( ret ) = val;
1123 break;
1124 case VT_UI4:
1125 V_UI4( ret ) = val;
1126 break;
1127 case VT_NULL:
1128 break;
1129 case VT_R4:
1130 V_R4( ret ) = *(FLOAT *)&val;
1131 break;
1132 default:
1133 ERR("unhandled variant type %u\n", type);
1134 return;
1135 }
1136 V_VT( ret ) = type;
1137}
@ VT_R4
Definition: compat.h:2299
@ VT_UI2
Definition: compat.h:2312
@ VT_I1
Definition: compat.h:2310
@ VT_BOOL
Definition: compat.h:2306
@ VT_I2
Definition: compat.h:2297
@ VT_UI4
Definition: compat.h:2313
@ VT_UI1
Definition: compat.h:2311
#define V_UI1(A)
Definition: oleauto.h:266
#define V_BOOL(A)
Definition: oleauto.h:224
#define V_ARRAY(A)
Definition: oleauto.h:222
#define V_UI2(A)
Definition: oleauto.h:268
#define V_I1(A)
Definition: oleauto.h:243
#define V_R4(A)
Definition: oleauto.h:260
#define V_UI4(A)
Definition: oleauto.h:270
#define V_I2(A)
Definition: oleauto.h:245
float FLOAT
Definition: typedefs.h:69

Referenced by control_service(), create_key(), enum_key(), enum_values(), get_owner(), get_propval(), get_stringvalue(), security_get_sd(), security_set_sd(), start_service(), to_bstr_array(), to_byte_array(), and to_i4_array().

◆ to_array()

static struct array * to_array ( VARIANT var,
CIMTYPE type 
)
static

Definition at line 1277 of file query.c.

1278{
1279 struct array *ret;
1280 LONG bound, i;
1281 VARTYPE vartype;
1282 CIMTYPE basetype;
1283
1284 if (SafeArrayGetVartype( V_ARRAY( var ), &vartype ) != S_OK) return NULL;
1285 if (!(basetype = to_cimtype( vartype ))) return NULL;
1286 if (SafeArrayGetUBound( V_ARRAY( var ), 1, &bound ) != S_OK) return NULL;
1287 if (!(ret = heap_alloc( sizeof(struct array) ))) return NULL;
1288
1289 ret->count = bound + 1;
1290 ret->elem_size = get_type_size( basetype );
1291 if (!(ret->ptr = heap_alloc_zero( ret->count * ret->elem_size )))
1292 {
1293 heap_free( ret );
1294 return NULL;
1295 }
1296 for (i = 0; i < ret->count; i++)
1297 {
1298 void *ptr = (char *)ret->ptr + i * ret->elem_size;
1299 if (vartype == VT_BSTR)
1300 {
1301 BSTR str;
1302 if (SafeArrayGetElement( V_ARRAY( var ), &i, &str ) != S_OK)
1303 {
1304 destroy_array( ret, basetype );
1305 return NULL;
1306 }
1307 *(WCHAR **)ptr = heap_strdupW( str );
1308 SysFreeString( str );
1309 if (!*(WCHAR **)ptr)
1310 {
1311 destroy_array( ret, basetype );
1312 return NULL;
1313 }
1314 }
1315 else if (SafeArrayGetElement( V_ARRAY( var ), &i, ptr ) != S_OK)
1316 {
1317 destroy_array( ret, basetype );
1318 return NULL;
1319 }
1320 }
1321 *type = basetype | CIM_FLAG_ARRAY;
1322 return ret;
1323}
static WCHAR * heap_strdupW(const WCHAR *str)
Definition: propsheet.c:178
HRESULT WINAPI SafeArrayGetUBound(SAFEARRAY *psa, UINT nDim, LONG *plUbound)
Definition: safearray.c:1033
HRESULT WINAPI SafeArrayGetElement(SAFEARRAY *psa, LONG *rgIndices, void *pvData)
Definition: safearray.c:947
HRESULT WINAPI SafeArrayGetVartype(SAFEARRAY *psa, VARTYPE *pvt)
Definition: safearray.c:1534
unsigned int get_type_size(ULONG *pFlags, VARTYPE vt)
Definition: usrmarshal.c:209
void destroy_array(struct array *array, CIMTYPE type)
Definition: class.c:240
static CIMTYPE to_cimtype(VARTYPE type)
Definition: query.c:1256
if(dx< 0)
Definition: linetemp.h:194
static PVOID ptr
Definition: dispmode.c:27

Referenced by to_longlong().

◆ to_cimtype()

static CIMTYPE to_cimtype ( VARTYPE  type)
static

Definition at line 1256 of file query.c.

1257{
1258 switch (type)
1259 {
1260 case VT_BOOL: return CIM_BOOLEAN;
1261 case VT_BSTR: return CIM_STRING;
1262 case VT_I1: return CIM_SINT8;
1263 case VT_UI1: return CIM_UINT8;
1264 case VT_I2: return CIM_SINT16;
1265 case VT_UI2: return CIM_UINT16;
1266 case VT_I4: return CIM_SINT32;
1267 case VT_UI4: return CIM_UINT32;
1268 case VT_I8: return CIM_SINT64;
1269 case VT_UI8: return CIM_UINT64;
1270 default:
1271 ERR("unhandled type %u\n", type);
1272 break;
1273 }
1274 return 0;
1275}
@ VT_UI8
Definition: compat.h:2315
@ VT_I8
Definition: compat.h:2314

Referenced by to_array().

◆ to_longlong()

HRESULT to_longlong ( VARIANT var,
LONGLONG val,
CIMTYPE type 
)

Definition at line 1325 of file query.c.

1326{
1327 if (!var)
1328 {
1329 *val = 0;
1330 return S_OK;
1331 }
1332 if (V_VT( var ) & VT_ARRAY)
1333 {
1334 *val = (INT_PTR)to_array( var, type );
1335 if (!*val) return E_OUTOFMEMORY;
1336 return S_OK;
1337 }
1338 switch (V_VT( var ))
1339 {
1340 case VT_BOOL:
1341 *val = V_BOOL( var );
1342 *type = CIM_BOOLEAN;
1343 break;
1344 case VT_BSTR:
1345 *val = (INT_PTR)heap_strdupW( V_BSTR( var ) );
1346 if (!*val) return E_OUTOFMEMORY;
1347 *type = CIM_STRING;
1348 break;
1349 case VT_I2:
1350 *val = V_I2( var );
1351 *type = CIM_SINT16;
1352 break;
1353 case VT_UI2:
1354 *val = V_UI2( var );
1355 *type = CIM_UINT16;
1356 break;
1357 case VT_I4:
1358 *val = V_I4( var );
1359 *type = CIM_SINT32;
1360 break;
1361 case VT_UI4:
1362 *val = V_UI4( var );
1363 *type = CIM_UINT32;
1364 break;
1365 case VT_NULL:
1366 *val = 0;
1367 break;
1368 default:
1369 ERR("unhandled type %u\n", V_VT( var ));
1370 return WBEM_E_FAILED;
1371 }
1372 return S_OK;
1373}
static struct array * to_array(VARIANT *var, CIMTYPE *type)
Definition: query.c:1277

Referenced by put_propval(), and record_set_value().

◆ to_safearray()

SAFEARRAY * to_safearray ( const struct array array,
CIMTYPE  basetype 
)

Definition at line 1062 of file query.c.

1063{
1064 SAFEARRAY *ret;
1065 VARTYPE vartype = to_vartype( basetype );
1066 LONG i;
1067
1068 if (!array || !(ret = SafeArrayCreateVector( vartype, 0, array->count ))) return NULL;
1069
1070 for (i = 0; i < array->count; i++)
1071 {
1072 void *ptr = (char *)array->ptr + i * array->elem_size;
1073 if (vartype == VT_BSTR)
1074 {
1075 BSTR str = SysAllocString( *(const WCHAR **)ptr );
1076 if (!str || SafeArrayPutElement( ret, &i, str ) != S_OK)
1077 {
1078 SysFreeString( str );
1080 return NULL;
1081 }
1082 SysFreeString( str );
1083 }
1084 else if (SafeArrayPutElement( ret, &i, ptr ) != S_OK)
1085 {
1087 return NULL;
1088 }
1089 }
1090 return ret;
1091}
UINT elem_size
void * ptr

Referenced by get_propval(), and record_get_value().

◆ to_vartype()

VARTYPE to_vartype ( CIMTYPE  type)

Definition at line 1032 of file query.c.

1033{
1034 switch (type)
1035 {
1036 case CIM_BOOLEAN: return VT_BOOL;
1037
1038 case CIM_STRING:
1039 case CIM_REFERENCE:
1040 case CIM_DATETIME: return VT_BSTR;
1041
1042 case CIM_SINT8: return VT_I1;
1043 case CIM_UINT8: return VT_UI1;
1044 case CIM_SINT16: return VT_I2;
1045
1046 case CIM_UINT16:
1047 case CIM_SINT32:
1048 case CIM_UINT32: return VT_I4;
1049
1050 case CIM_SINT64: return VT_I8;
1051 case CIM_UINT64: return VT_UI8;
1052
1053 case CIM_REAL32: return VT_R4;
1054
1055 default:
1056 ERR("unhandled type %u\n", type);
1057 break;
1058 }
1059 return 0;
1060}

Referenced by get_propval(), record_get_value(), and to_safearray().

◆ WINE_DEFAULT_DEBUG_CHANNEL()

WINE_DEFAULT_DEBUG_CHANNEL ( wbemprox  )