ReactOS 0.4.15-dev-7953-g1f49173
table.c
Go to the documentation of this file.
1/*
2 * Copyright 2012 Hans Leidekker for CodeWeavers
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
17 */
18
19#define COBJMACROS
20
21#include <stdarg.h>
22#ifdef __REACTOS__
23#include <wchar.h>
24#endif
25
26#include "windef.h"
27#include "winbase.h"
28#include "wbemcli.h"
29
30#include "wine/debug.h"
31#include "wbemprox_private.h"
32
34
36{
37 UINT i;
38 for (i = 0; i < table->num_cols; i++)
39 {
40 if (!wcsicmp( table->columns[i].name, name ))
41 {
42 *column = i;
43 return S_OK;
44 }
45 }
47}
48
50{
51 if (type & CIM_FLAG_ARRAY) return sizeof(void *);
52
53 switch (type)
54 {
55 case CIM_BOOLEAN:
56 return sizeof(int);
57 case CIM_SINT8:
58 case CIM_UINT8:
59 return sizeof(INT8);
60 case CIM_SINT16:
61 case CIM_UINT16:
62 return sizeof(INT16);
63 case CIM_SINT32:
64 case CIM_UINT32:
65 return sizeof(INT32);
66 case CIM_SINT64:
67 case CIM_UINT64:
68 return sizeof(INT64);
69 case CIM_DATETIME:
70 case CIM_REFERENCE:
71 case CIM_STRING:
72 return sizeof(WCHAR *);
73 case CIM_REAL32:
74 return sizeof(FLOAT);
75 default:
76 ERR("unhandled type %u\n", type);
77 break;
78 }
79 return sizeof(LONGLONG);
80}
81
82static UINT get_column_size( const struct table *table, UINT column )
83{
85}
86
87static UINT get_column_offset( const struct table *table, UINT column )
88{
89 UINT i, offset = 0;
90 for (i = 0; i < column; i++) offset += get_column_size( table, i );
91 return offset;
92}
93
94static UINT get_row_size( const struct table *table )
95{
97}
98
100{
101 UINT col_offset, row_size;
102 const BYTE *ptr;
103
104 col_offset = get_column_offset( table, column );
105 row_size = get_row_size( table );
106 ptr = table->data + row * row_size + col_offset;
107
108 if (table->columns[column].type & CIM_FLAG_ARRAY)
109 {
110 *val = (INT_PTR)*(const void **)ptr;
111 return S_OK;
112 }
113 switch (table->columns[column].type & COL_TYPE_MASK)
114 {
115 case CIM_BOOLEAN:
116 *val = *(const int *)ptr;
117 break;
118 case CIM_DATETIME:
119 case CIM_REFERENCE:
120 case CIM_STRING:
121 *val = (INT_PTR)*(const WCHAR **)ptr;
122 break;
123 case CIM_SINT8:
124 *val = *(const INT8 *)ptr;
125 break;
126 case CIM_UINT8:
127 *val = *(const UINT8 *)ptr;
128 break;
129 case CIM_SINT16:
130 *val = *(const INT16 *)ptr;
131 break;
132 case CIM_UINT16:
133 *val = *(const UINT16 *)ptr;
134 break;
135 case CIM_SINT32:
136 *val = *(const INT32 *)ptr;
137 break;
138 case CIM_UINT32:
139 *val = *(const UINT32 *)ptr;
140 break;
141 case CIM_SINT64:
142 *val = *(const INT64 *)ptr;
143 break;
144 case CIM_UINT64:
145 *val = *(const UINT64 *)ptr;
146 break;
147 case CIM_REAL32:
148 memcpy( val, ptr, sizeof(FLOAT) );
149 break;
150 default:
151 ERR("invalid column type %u\n", table->columns[column].type & COL_TYPE_MASK);
152 *val = 0;
153 break;
154 }
155 return S_OK;
156}
157
159{
160 static const WCHAR fmt_signedW[] = {'%','d',0};
161 static const WCHAR fmt_unsignedW[] = {'%','u',0};
162 static const WCHAR fmt_signed64W[] = {'%','I','6','4','d',0};
163 static const WCHAR fmt_unsigned64W[] = {'%','I','6','4','u',0};
164 static const WCHAR fmt_strW[] = {'\"','%','s','\"',0};
165 static const WCHAR trueW[] = {'T','R','U','E',0};
166 static const WCHAR falseW[] = {'F','A','L','S','E',0};
168 BSTR ret;
169 WCHAR number[22];
170 UINT len;
171
172 if (table->columns[column].type & CIM_FLAG_ARRAY)
173 {
174 FIXME("array to string conversion not handled\n");
175 return NULL;
176 }
177 if (get_value( table, row, column, &val ) != S_OK) return NULL;
178
179 switch (table->columns[column].type & COL_TYPE_MASK)
180 {
181 case CIM_BOOLEAN:
182 if (val) return SysAllocString( trueW );
183 else return SysAllocString( falseW );
184
185 case CIM_DATETIME:
186 case CIM_REFERENCE:
187 case CIM_STRING:
188 if (!val) return NULL;
189 len = lstrlenW( (const WCHAR *)(INT_PTR)val ) + 2;
190 if (!(ret = SysAllocStringLen( NULL, len ))) return NULL;
191 swprintf( ret, fmt_strW, (const WCHAR *)(INT_PTR)val );
192 return ret;
193
194 case CIM_SINT16:
195 case CIM_SINT32:
196 swprintf( number, fmt_signedW, val );
197 return SysAllocString( number );
198
199 case CIM_UINT16:
200 case CIM_UINT32:
201 swprintf( number, fmt_unsignedW, val );
202 return SysAllocString( number );
203
204 case CIM_SINT64:
205 wsprintfW( number, fmt_signed64W, val );
206 return SysAllocString( number );
207
208 case CIM_UINT64:
209 wsprintfW( number, fmt_unsigned64W, val );
210 return SysAllocString( number );
211
212 default:
213 FIXME("unhandled column type %u\n", table->columns[column].type & COL_TYPE_MASK);
214 break;
215 }
216 return NULL;
217}
218
220 CIMTYPE type )
221{
222 UINT col_offset, row_size;
223 BYTE *ptr;
224
225 if ((table->columns[column].type & COL_TYPE_MASK) != type) return WBEM_E_TYPE_MISMATCH;
226
227 col_offset = get_column_offset( table, column );
228 row_size = get_row_size( table );
229 ptr = table->data + row * row_size + col_offset;
230
231 switch (table->columns[column].type & COL_TYPE_MASK)
232 {
233 case CIM_DATETIME:
234 case CIM_REFERENCE:
235 case CIM_STRING:
236 *(WCHAR **)ptr = (WCHAR *)(INT_PTR)val;
237 break;
238 case CIM_SINT8:
239 *(INT8 *)ptr = val;
240 break;
241 case CIM_UINT8:
242 *(UINT8 *)ptr = val;
243 break;
244 case CIM_SINT16:
245 *(INT16 *)ptr = val;
246 break;
247 case CIM_UINT16:
248 *(UINT16 *)ptr = val;
249 break;
250 case CIM_SINT32:
251 *(INT32 *)ptr = val;
252 break;
253 case CIM_UINT32:
254 *(UINT32 *)ptr = val;
255 break;
256 case CIM_SINT64:
257 *(INT64 *)ptr = val;
258 break;
259 case CIM_UINT64:
260 *(UINT64 *)ptr = val;
261 break;
262 default:
263 FIXME("unhandled column type %u\n", type);
264 return WBEM_E_FAILED;
265 }
266 return S_OK;
267}
268
270{
271 UINT i, j;
272
273 for (i = 0; i < table->num_rows; i++)
274 {
275 for (j = 0; j < table->num_cols; j++)
276 {
277 if (table->columns[j].type & COL_FLAG_METHOD && !wcscmp( table->columns[j].name, name ))
278 {
279 HRESULT hr;
281
282 if ((hr = get_value( table, i, j, &val )) != S_OK) return hr;
284 return S_OK;
285 }
286 }
287 }
289
290}
291
292void free_row_values( const struct table *table, UINT row )
293{
294 UINT i, type;
296
297 for (i = 0; i < table->num_cols; i++)
298 {
299 if (!(table->columns[i].type & COL_FLAG_DYNAMIC)) continue;
300
301 type = table->columns[i].type & COL_TYPE_MASK;
303 {
304 if (get_value( table, row, i, &val ) == S_OK) heap_free( (void *)(INT_PTR)val );
305 }
306 else if (type & CIM_FLAG_ARRAY)
307 {
308 if (get_value( table, row, i, &val ) == S_OK)
310 }
311 }
312}
313
314void clear_table( struct table *table )
315{
316 UINT i;
317
318 if (!table->data) return;
319
320 for (i = 0; i < table->num_rows; i++) free_row_values( table, i );
321 if (table->fill)
322 {
323 table->num_rows = 0;
325 heap_free( table->data );
326 table->data = NULL;
327 }
328}
329
330void free_columns( struct column *columns, UINT num_cols )
331{
332 UINT i;
333
334 for (i = 0; i < num_cols; i++) { heap_free( (WCHAR *)columns[i].name ); }
335 heap_free( columns );
336}
337
338void free_table( struct table *table )
339{
340 if (!table) return;
341
344 {
345 TRACE("destroying %p\n", table);
346 heap_free( (WCHAR *)table->name );
348 heap_free( table->data );
350 heap_free( table );
351 }
352}
353
354void release_table( struct table *table )
355{
357}
358
359struct table *addref_table( struct table *table )
360{
362 return table;
363}
364
365struct table *grab_table( const WCHAR *name )
366{
367 struct table *table;
368
370 {
371 if (name && !wcsicmp( table->name, name ))
372 {
373 TRACE("returning %p\n", table);
374 return addref_table( table );
375 }
376 }
377 return NULL;
378}
379
380struct table *create_table( const WCHAR *name, UINT num_cols, const struct column *columns,
381 UINT num_rows, UINT num_allocated, BYTE *data,
382 enum fill_status (*fill)(struct table *, const struct expr *cond) )
383{
384 struct table *table;
385
386 if (!(table = heap_alloc( sizeof(*table) ))) return NULL;
391 table->num_rows_allocated = num_allocated;
392 table->data = data;
393 table->fill = fill;
395 table->refs = 0;
396 list_init( &table->entry );
397 return table;
398}
399
401{
402 struct table *iter;
403
404 LIST_FOR_EACH_ENTRY( iter, table_list, struct table, entry )
405 {
406 if (!wcsicmp( iter->name, table->name ))
407 {
408 TRACE("table %s already exists\n", debugstr_w(table->name));
409 return FALSE;
410 }
411 }
413 TRACE("added %p\n", table);
414 return TRUE;
415}
416
418{
419 struct table *table;
420 UINT i, count = 0;
421 BSTR ret;
422
423 if (!(table = grab_table( class ))) return NULL;
424
425 for (i = 0; i < table->num_cols; i++)
426 {
427 if (table->columns[i].type & COL_FLAG_METHOD)
428 {
429 if (index == count)
430 {
431 ret = SysAllocString( table->columns[i].name );
433 return ret;
434 }
435 count++;
436 }
437 }
439 return NULL;
440}
unsigned short UINT16
signed int INT32
signed short INT16
unsigned long long UINT64
signed char INT8
unsigned char UINT8
unsigned int UINT32
signed long long INT64
_STLP_MOVE_TO_STD_NAMESPACE void fill(_ForwardIter __first, _ForwardIter __last, const _Tp &__val)
Definition: _algobase.h:449
static void * heap_alloc(size_t len)
Definition: appwiz.h:66
static BOOL heap_free(void *mem)
Definition: appwiz.h:76
#define InterlockedIncrement
Definition: armddk.h:53
#define InterlockedDecrement
Definition: armddk.h:52
#define WINE_DEFAULT_DEBUG_CHANNEL(t)
Definition: precomp.h:23
static void list_remove(struct list_entry *entry)
Definition: list.h:90
static void list_add_tail(struct list_entry *head, struct list_entry *entry)
Definition: list.h:83
static void list_init(struct list_entry *head)
Definition: list.h:51
#define FIXME(fmt,...)
Definition: debug.h:111
#define ERR(fmt,...)
Definition: debug.h:110
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
static WCHAR * heap_strdupW(const WCHAR *str)
Definition: propsheet.c:178
OLECHAR * BSTR
Definition: compat.h:2293
#define wcsicmp
Definition: compat.h:15
#define lstrlenW
Definition: compat.h:750
static void free_table(MSITABLE *table)
Definition: table.c:362
void destroy_array(struct array *array, CIMTYPE type)
Definition: class.c:240
struct list * table_list
Definition: main.c:38
HRESULT get_value(const struct table *table, UINT row, UINT column, LONGLONG *val)
Definition: table.c:99
static UINT get_column_offset(const struct table *table, UINT column)
Definition: table.c:87
struct table * create_table(const WCHAR *name, UINT num_cols, const struct column *columns, UINT num_rows, UINT num_allocated, BYTE *data, enum fill_status(*fill)(struct table *, const struct expr *cond))
Definition: table.c:380
static UINT get_row_size(const struct table *table)
Definition: table.c:94
void free_row_values(const struct table *table, UINT row)
Definition: table.c:292
void clear_table(struct table *table)
Definition: table.c:314
struct table * grab_table(const WCHAR *name)
Definition: table.c:365
HRESULT set_value(const struct table *table, UINT row, UINT column, LONGLONG val, CIMTYPE type)
Definition: table.c:219
static UINT get_column_size(const struct table *table, UINT column)
Definition: table.c:82
UINT get_type_size(CIMTYPE type)
Definition: table.c:49
struct table * addref_table(struct table *table)
Definition: table.c:359
BOOL add_table(struct table *table)
Definition: table.c:400
BSTR get_method_name(const WCHAR *class, UINT index)
Definition: table.c:417
HRESULT get_column_index(const struct table *table, const WCHAR *name, UINT *column)
Definition: table.c:35
void release_table(struct table *table)
Definition: table.c:354
BSTR get_value_bstr(const struct table *table, UINT row, UINT column)
Definition: table.c:158
void free_columns(struct column *columns, UINT num_cols)
Definition: table.c:330
HRESULT get_method(const struct table *table, const WCHAR *name, class_method **func)
Definition: table.c:269
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
unsigned int(__cdecl typeof(jpeg_read_scanlines))(struct jpeg_decompress_struct *
Definition: typeof.h:31
#define swprintf
Definition: precomp.h:40
unsigned int BOOL
Definition: ntddk_ex.h:94
GLuint GLuint GLsizei GLenum type
Definition: gl.h:1545
GLuint GLuint GLsizei count
Definition: gl.h:1545
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
GLenum func
Definition: glext.h:6028
GLuint index
Definition: glext.h:6031
GLuint GLfloat * val
Definition: glext.h:7180
GLenum GLsizei len
Definition: glext.h:6722
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 i
Definition: glfuncs.h:248
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
#define FLOAT
Definition: i386-dis.c:525
#define S_OK
Definition: intsafe.h:52
uint32_t entry
Definition: isohybrid.c:63
int JSAMPARRAY int int num_rows
Definition: jpegint.h:421
int JSAMPARRAY int int JDIMENSION num_cols
Definition: jpegint.h:421
static const WCHAR falseW[]
Definition: json.c:34
static const WCHAR trueW[]
Definition: json.c:33
#define debugstr_w
Definition: kernel32.h:32
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
static PVOID ptr
Definition: dispmode.c:27
static unsigned int number
Definition: dsound.c:1479
unsigned int UINT
Definition: ndis.h:50
BSTR WINAPI SysAllocString(LPCOLESTR str)
Definition: oleaut.c:238
BSTR WINAPI SysAllocStringLen(const OLECHAR *str, unsigned int len)
Definition: oleaut.c:339
_Check_return_ _CRTIMP int __cdecl wcscmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)
#define LIST_FOR_EACH_ENTRY(elem, list, type, field)
Definition: list.h:198
HRESULT hr
Definition: shlfolder.c:183
#define TRACE(s)
Definition: solgame.cpp:4
Definition: query.h:87
Definition: name.c:39
UINT num_rows
enum fill_status(* fill)(struct table *, const struct expr *cond)
const struct column * columns
const WCHAR * name
UINT num_cols
UINT num_rows_allocated
struct list entry
BYTE * data
int32_t INT_PTR
Definition: typedefs.h:64
float FLOAT
Definition: typedefs.h:69
int64_t LONGLONG
Definition: typedefs.h:68
@ CIM_REFERENCE
Definition: wbemcli.idl:253
@ CIM_UINT32
Definition: wbemcli.idl:249
@ CIM_UINT8
Definition: wbemcli.idl:247
@ CIM_BOOLEAN
Definition: wbemcli.idl:244
@ CIM_SINT64
Definition: wbemcli.idl:250
@ CIM_UINT16
Definition: wbemcli.idl:248
@ CIM_DATETIME
Definition: wbemcli.idl:252
@ CIM_REAL32
Definition: wbemcli.idl:241
@ CIM_UINT64
Definition: wbemcli.idl:251
@ CIM_SINT8
Definition: wbemcli.idl:246
@ CIM_SINT16
Definition: wbemcli.idl:239
@ CIM_STRING
Definition: wbemcli.idl:243
@ CIM_SINT32
Definition: wbemcli.idl:240
@ CIM_FLAG_ARRAY
Definition: wbemcli.idl:255
long CIMTYPE
Definition: wbemcli.idl:258
@ WBEM_E_INVALID_METHOD
Definition: wbemcli.idl:96
@ WBEM_E_INVALID_QUERY
Definition: wbemcli.idl:73
@ WBEM_E_FAILED
Definition: wbemcli.idl:51
@ WBEM_E_TYPE_MISMATCH
Definition: wbemcli.idl:55
#define COL_FLAG_DYNAMIC
HRESULT() class_method(IWbemClassObject *, IWbemClassObject *, IWbemClassObject **)
#define COL_TYPE_MASK
#define CIM_TYPE_MASK
#define TABLE_FLAG_DYNAMIC
fill_status
#define COL_FLAG_METHOD
int ret
int WINAPIV wsprintfW(_Out_ LPWSTR, _In_ _Printf_format_string_ LPCWSTR,...)
__wchar_t WCHAR
Definition: xmlstorage.h:180
unsigned char BYTE
Definition: xxhash.c:193