wbemprox_private.h 10.3 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
/*
 * Copyright 2009 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
 */

19
#include "wine/debug.h"
20
#include "wine/list.h"
21
#include "wine/unicode.h"
22

23 24
IClientSecurity client_security DECLSPEC_HIDDEN;
struct list *table_list DECLSPEC_HIDDEN;
25

26 27
#define SIZEOF(array) (sizeof(array)/sizeof((array)[0]))

28 29 30 31 32 33 34
enum param_direction
{
    PARAM_OUT   = -1,
    PARAM_INOUT = 0,
    PARAM_IN    = 1
};

35 36
#define CIM_TYPE_MASK    0x00000fff

37 38
#define COL_TYPE_MASK    0x0000ffff
#define COL_FLAG_DYNAMIC 0x00010000
39
#define COL_FLAG_KEY     0x00020000
40 41
#define COL_FLAG_METHOD  0x00040000

42
typedef HRESULT (class_method)(IWbemClassObject *, IWbemClassObject *, IWbemClassObject **);
43

44 45 46 47 48 49 50 51 52 53 54 55
enum operator
{
    OP_EQ      = 1,
    OP_AND     = 2,
    OP_OR      = 3,
    OP_GT      = 4,
    OP_LT      = 5,
    OP_LE      = 6,
    OP_GE      = 7,
    OP_NE      = 8,
    OP_ISNULL  = 9,
    OP_NOTNULL = 10,
56 57
    OP_LIKE    = 11,
    OP_NOT     = 12
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
};

struct expr;
struct complex_expr
{
    enum operator op;
    struct expr *left;
    struct expr *right;
};

enum expr_type
{
    EXPR_COMPLEX = 1,
    EXPR_UNARY   = 2,
    EXPR_PROPVAL = 3,
    EXPR_SVAL    = 4,
    EXPR_IVAL    = 5,
    EXPR_BVAL    = 6
};

struct expr
{
    enum expr_type type;
    union
    {
        struct complex_expr expr;
        const struct property *propval;
        const WCHAR *sval;
        int ival;
    } u;
};

90 91 92
struct column
{
    const WCHAR *name;
93
    UINT type;
94
    VARTYPE vartype; /* 0 for default mapping */
95 96
};

97 98 99 100 101 102 103
enum fill_status
{
    FILL_STATUS_FAILED = -1,
    FILL_STATUS_UNFILTERED,
    FILL_STATUS_FILTERED
};

104 105
#define TABLE_FLAG_DYNAMIC 0x00000001

106 107 108 109 110 111
struct table
{
    const WCHAR *name;
    UINT num_cols;
    const struct column *columns;
    UINT num_rows;
112
    UINT num_rows_allocated;
113
    BYTE *data;
114
    enum fill_status (*fill)(struct table *, const struct expr *cond);
115 116
    UINT flags;
    struct list entry;
117
    LONG refs;
118 119
};

120 121 122 123 124 125 126
struct property
{
    const WCHAR *name;
    const WCHAR *class;
    const struct property *next;
};

127 128 129 130 131 132
struct array
{
    UINT count;
    void *ptr;
};

133 134 135
struct field
{
    UINT type;
136
    VARTYPE vartype; /* 0 for default mapping */
137 138 139 140
    union
    {
        LONGLONG ival;
        WCHAR *sval;
141
        struct array *aval;
142 143 144 145 146 147 148
    } u;
};

struct record
{
    UINT count;
    struct field *fields;
149
    struct table *table;
150 151
};

152 153 154
struct view
{
    const struct property *proplist;
155
    struct table *table;
156
    const struct expr *cond;
157 158
    UINT *result;
    UINT  count;
159 160 161 162
};

struct query
{
163
    LONG refs;
164 165 166 167
    struct view *view;
    struct list mem;
};

168 169
struct query *create_query(void) DECLSPEC_HIDDEN;
void free_query( struct query * ) DECLSPEC_HIDDEN;
170
struct query *addref_query( struct query * ) DECLSPEC_HIDDEN;
171
void release_query( struct query *query ) DECLSPEC_HIDDEN;
172 173 174 175 176
HRESULT exec_query( const WCHAR *, IEnumWbemClassObject ** ) DECLSPEC_HIDDEN;
HRESULT parse_query( const WCHAR *, struct view **, struct list * ) DECLSPEC_HIDDEN;
HRESULT create_view( const struct property *, const WCHAR *, const struct expr *,
                     struct view ** ) DECLSPEC_HIDDEN;
void destroy_view( struct view * ) DECLSPEC_HIDDEN;
177
HRESULT execute_view( struct view * ) DECLSPEC_HIDDEN;
178
void init_table_list( void ) DECLSPEC_HIDDEN;
179
struct table *grab_table( const WCHAR * ) DECLSPEC_HIDDEN;
180
struct table *addref_table( struct table * ) DECLSPEC_HIDDEN;
181
void release_table( struct table * ) DECLSPEC_HIDDEN;
182
struct table *create_table( const WCHAR *, UINT, const struct column *, UINT, UINT, BYTE *,
183
                            enum fill_status (*)(struct table *, const struct expr *) ) DECLSPEC_HIDDEN;
184 185
BOOL add_table( struct table * ) DECLSPEC_HIDDEN;
void free_columns( struct column *, UINT ) DECLSPEC_HIDDEN;
186
void free_row_values( const struct table *, UINT ) DECLSPEC_HIDDEN;
187
void clear_table( struct table * ) DECLSPEC_HIDDEN;
188
void free_table( struct table * ) DECLSPEC_HIDDEN;
189
UINT get_type_size( CIMTYPE ) DECLSPEC_HIDDEN;
190
HRESULT eval_cond( const struct table *, UINT, const struct expr *, LONGLONG *, UINT * ) DECLSPEC_HIDDEN;
191 192 193
HRESULT get_column_index( const struct table *, const WCHAR *, UINT * ) DECLSPEC_HIDDEN;
HRESULT get_value( const struct table *, UINT, UINT, LONGLONG * ) DECLSPEC_HIDDEN;
BSTR get_value_bstr( const struct table *, UINT, UINT ) DECLSPEC_HIDDEN;
194
HRESULT set_value( const struct table *, UINT, UINT, LONGLONG, CIMTYPE ) DECLSPEC_HIDDEN;
195
BOOL is_method( const struct table *, UINT ) DECLSPEC_HIDDEN;
196
HRESULT get_method( const struct table *, const WCHAR *, class_method ** ) DECLSPEC_HIDDEN;
197
HRESULT get_propval( const struct view *, UINT, const WCHAR *, VARIANT *,
198
                     CIMTYPE *, LONG * ) DECLSPEC_HIDDEN;
199
HRESULT put_propval( const struct view *, UINT, const WCHAR *, VARIANT *, CIMTYPE ) DECLSPEC_HIDDEN;
200 201
HRESULT to_longlong( VARIANT *, LONGLONG *, CIMTYPE * ) DECLSPEC_HIDDEN;
SAFEARRAY *to_safearray( const struct array *, CIMTYPE ) DECLSPEC_HIDDEN;
202
VARTYPE to_vartype( CIMTYPE ) DECLSPEC_HIDDEN;
203
void destroy_array( struct array *, CIMTYPE ) DECLSPEC_HIDDEN;
204
BOOL is_selected_prop( const struct view *, const WCHAR * ) DECLSPEC_HIDDEN;
205
HRESULT get_properties( const struct view *, LONG, SAFEARRAY ** ) DECLSPEC_HIDDEN;
206
HRESULT get_object( const WCHAR *, IWbemClassObject ** ) DECLSPEC_HIDDEN;
207
BSTR get_method_name( const WCHAR *, UINT ) DECLSPEC_HIDDEN;
208 209 210
void set_variant( VARTYPE, LONGLONG, void *, VARIANT * ) DECLSPEC_HIDDEN;
HRESULT create_signature( const WCHAR *, const WCHAR *, enum param_direction,
                          IWbemClassObject ** ) DECLSPEC_HIDDEN;
211

212 213
HRESULT WbemLocator_create(LPVOID *) DECLSPEC_HIDDEN;
HRESULT WbemServices_create(const WCHAR *, LPVOID *) DECLSPEC_HIDDEN;
214
HRESULT create_class_object(const WCHAR *, IEnumWbemClassObject *, UINT,
215
                            struct record *, IWbemClassObject **) DECLSPEC_HIDDEN;
216 217
HRESULT EnumWbemClassObject_create(struct query *, LPVOID *) DECLSPEC_HIDDEN;
HRESULT WbemQualifierSet_create(const WCHAR *, const WCHAR *, LPVOID *) DECLSPEC_HIDDEN;
218

219
HRESULT process_get_owner(IWbemClassObject *, IWbemClassObject *, IWbemClassObject **) DECLSPEC_HIDDEN;
220 221 222
HRESULT reg_enum_key(IWbemClassObject *, IWbemClassObject *, IWbemClassObject **) DECLSPEC_HIDDEN;
HRESULT reg_enum_values(IWbemClassObject *, IWbemClassObject *, IWbemClassObject **) DECLSPEC_HIDDEN;
HRESULT reg_get_stringvalue(IWbemClassObject *, IWbemClassObject *, IWbemClassObject **) DECLSPEC_HIDDEN;
223
HRESULT service_pause_service(IWbemClassObject *, IWbemClassObject *, IWbemClassObject **) DECLSPEC_HIDDEN;
224
HRESULT service_resume_service(IWbemClassObject *, IWbemClassObject *, IWbemClassObject **) DECLSPEC_HIDDEN;
225
HRESULT service_start_service(IWbemClassObject *, IWbemClassObject *, IWbemClassObject **) DECLSPEC_HIDDEN;
226
HRESULT service_stop_service(IWbemClassObject *, IWbemClassObject *, IWbemClassObject **) DECLSPEC_HIDDEN;
227
HRESULT security_get_sd(IWbemClassObject *, IWbemClassObject *, IWbemClassObject **) DECLSPEC_HIDDEN;
228
HRESULT security_set_sd(IWbemClassObject *, IWbemClassObject *, IWbemClassObject **) DECLSPEC_HIDDEN;
229

230 231 232 233 234 235
static void *heap_alloc( size_t len ) __WINE_ALLOC_SIZE(1);
static inline void *heap_alloc( size_t len )
{
    return HeapAlloc( GetProcessHeap(), 0, len );
}

236 237 238 239 240 241
static void *heap_realloc( void *mem, size_t len ) __WINE_ALLOC_SIZE(2);
static inline void *heap_realloc( void *mem, size_t len )
{
    return HeapReAlloc( GetProcessHeap(), 0, mem, len );
}

242 243 244 245 246 247
static void *heap_alloc_zero( size_t len ) __WINE_ALLOC_SIZE(1);
static inline void *heap_alloc_zero( size_t len )
{
    return HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, len );
}

248 249 250 251
static inline BOOL heap_free( void *mem )
{
    return HeapFree( GetProcessHeap(), 0, mem );
}
252 253 254 255 256 257 258 259

static inline WCHAR *heap_strdupW( const WCHAR *src )
{
    WCHAR *dst;
    if (!src) return NULL;
    if ((dst = heap_alloc( (strlenW( src ) + 1) * sizeof(WCHAR) ))) strcpyW( dst, src );
    return dst;
}
260

261
static const WCHAR class_processW[] = {'W','i','n','3','2','_','P','r','o','c','e','s','s',0};
262
static const WCHAR class_serviceW[] = {'W','i','n','3','2','_','S','e','r','v','i','c','e',0};
263
static const WCHAR class_stdregprovW[] = {'S','t','d','R','e','g','P','r','o','v',0};
264
static const WCHAR class_systemsecurityW[] = {'_','_','S','y','s','t','e','m','S','e','c','u','r','i','t','y',0};
265

266 267
static const WCHAR prop_nameW[] = {'N','a','m','e',0};

268 269
static const WCHAR method_enumkeyW[] = {'E','n','u','m','K','e','y',0};
static const WCHAR method_enumvaluesW[] = {'E','n','u','m','V','a','l','u','e','s',0};
270
static const WCHAR method_getownerW[] = {'G','e','t','O','w','n','e','r',0};
271
static const WCHAR method_getsdW[] = {'G','e','t','S','D',0};
272
static const WCHAR method_getstringvalueW[] = {'G','e','t','S','t','r','i','n','g','V','a','l','u','e',0};
273
static const WCHAR method_pauseserviceW[] = {'P','a','u','s','e','S','e','r','v','i','c','e',0};
274
static const WCHAR method_resumeserviceW[] = {'R','e','s','u','m','e','S','e','r','v','i','c','e',0};
275
static const WCHAR method_setsdW[] = {'S','e','t','S','D',0};
276
static const WCHAR method_startserviceW[] = {'S','t','a','r','t','S','e','r','v','i','c','e',0};
277
static const WCHAR method_stopserviceW[] = {'S','t','o','p','S','e','r','v','i','c','e',0};
278 279

static const WCHAR param_defkeyW[] = {'h','D','e','f','K','e','y',0};
280
static const WCHAR param_domainW[] = {'D','o','m','a','i','n',0};
281 282
static const WCHAR param_namesW[] = {'s','N','a','m','e','s',0};
static const WCHAR param_returnvalueW[] = {'R','e','t','u','r','n','V','a','l','u','e',0};
283
static const WCHAR param_sdW[] = {'S','D',0};
284 285
static const WCHAR param_subkeynameW[] = {'s','S','u','b','K','e','y','N','a','m','e',0};
static const WCHAR param_typesW[] = {'T','y','p','e','s',0};
286
static const WCHAR param_userW[] = {'U','s','e','r',0};
287 288
static const WCHAR param_valueW[] = {'s','V','a','l','u','e',0};
static const WCHAR param_valuenameW[] = {'s','V','a','l','u','e','N','a','m','e',0};