36120c45b2b3f45aeb27af71d0551e89463deda9
[reactos.git] / reactos / dll / win32 / wbemprox / wbemprox_private.h
1 /*
2 * Copyright 2009 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 #include <config.h>
20
21 #include <stdarg.h>
22
23 #define _INC_WINDOWS
24 #define COM_NO_WINDOWS_H
25
26 #define COBJMACROS
27 #define NONAMELESSUNION
28 #define NONAMELESSSTRUCT
29
30 #include <ntstatus.h>
31 #define WIN32_NO_STATUS
32 #include <windef.h>
33 #include <winbase.h>
34 #include <winsvc.h>
35 #include <objbase.h>
36 #include <oleauto.h>
37 #include <wbemcli.h>
38
39 #include <wine/debug.h>
40 #include <wine/list.h>
41 #include <wine/unicode.h>
42
43 WINE_DEFAULT_DEBUG_CHANNEL(wbemprox);
44
45 IClientSecurity client_security;
46 struct list *table_list;
47
48 #define SIZEOF(array) (sizeof(array)/sizeof((array)[0]))
49
50 enum param_direction
51 {
52 PARAM_OUT = -1,
53 PARAM_INOUT = 0,
54 PARAM_IN = 1
55 };
56
57 #define CIM_TYPE_MASK 0x00000fff
58
59 #define COL_TYPE_MASK 0x0000ffff
60 #define COL_FLAG_DYNAMIC 0x00010000
61 #define COL_FLAG_KEY 0x00020000
62 #define COL_FLAG_METHOD 0x00040000
63
64 typedef HRESULT (class_method)(IWbemClassObject *, IWbemClassObject *, IWbemClassObject **);
65
66 enum operator
67 {
68 OP_EQ = 1,
69 OP_AND = 2,
70 OP_OR = 3,
71 OP_GT = 4,
72 OP_LT = 5,
73 OP_LE = 6,
74 OP_GE = 7,
75 OP_NE = 8,
76 OP_ISNULL = 9,
77 OP_NOTNULL = 10,
78 OP_LIKE = 11
79 };
80
81 struct expr;
82 struct complex_expr
83 {
84 enum operator op;
85 struct expr *left;
86 struct expr *right;
87 };
88
89 enum expr_type
90 {
91 EXPR_COMPLEX = 1,
92 EXPR_UNARY = 2,
93 EXPR_PROPVAL = 3,
94 EXPR_SVAL = 4,
95 EXPR_IVAL = 5,
96 EXPR_BVAL = 6
97 };
98
99 struct expr
100 {
101 enum expr_type type;
102 union
103 {
104 struct complex_expr expr;
105 const struct property *propval;
106 const WCHAR *sval;
107 int ival;
108 } u;
109 };
110
111 struct column
112 {
113 const WCHAR *name;
114 UINT type;
115 VARTYPE vartype; /* 0 for default mapping */
116 };
117
118 enum fill_status
119 {
120 FILL_STATUS_FAILED = -1,
121 FILL_STATUS_UNFILTERED,
122 FILL_STATUS_FILTERED
123 };
124
125 #define TABLE_FLAG_DYNAMIC 0x00000001
126
127 struct table
128 {
129 const WCHAR *name;
130 UINT num_cols;
131 const struct column *columns;
132 UINT num_rows;
133 UINT num_rows_allocated;
134 BYTE *data;
135 enum fill_status (*fill)(struct table *, const struct expr *cond);
136 UINT flags;
137 struct list entry;
138 LONG refs;
139 };
140
141 struct property
142 {
143 const WCHAR *name;
144 const WCHAR *class;
145 const struct property *next;
146 };
147
148 struct array
149 {
150 UINT count;
151 void *ptr;
152 };
153
154 struct field
155 {
156 UINT type;
157 VARTYPE vartype; /* 0 for default mapping */
158 union
159 {
160 LONGLONG ival;
161 WCHAR *sval;
162 struct array *aval;
163 } u;
164 };
165
166 struct record
167 {
168 UINT count;
169 struct field *fields;
170 struct table *table;
171 };
172
173 struct view
174 {
175 const struct property *proplist;
176 struct table *table;
177 const struct expr *cond;
178 UINT *result;
179 UINT count;
180 };
181
182 struct query
183 {
184 LONG refs;
185 struct view *view;
186 struct list mem;
187 };
188
189 struct query *create_query(void) DECLSPEC_HIDDEN;
190 void free_query( struct query * ) DECLSPEC_HIDDEN;
191 struct query *addref_query( struct query * ) DECLSPEC_HIDDEN;
192 void release_query( struct query *query ) DECLSPEC_HIDDEN;
193 HRESULT exec_query( const WCHAR *, IEnumWbemClassObject ** ) DECLSPEC_HIDDEN;
194 HRESULT parse_query( const WCHAR *, struct view **, struct list * ) DECLSPEC_HIDDEN;
195 HRESULT create_view( const struct property *, const WCHAR *, const struct expr *,
196 struct view ** ) DECLSPEC_HIDDEN;
197 void destroy_view( struct view * ) DECLSPEC_HIDDEN;
198 HRESULT execute_view( struct view * ) DECLSPEC_HIDDEN;
199 void init_table_list( void ) DECLSPEC_HIDDEN;
200 struct table *grab_table( const WCHAR * ) DECLSPEC_HIDDEN;
201 struct table *addref_table( struct table * ) DECLSPEC_HIDDEN;
202 void release_table( struct table * ) DECLSPEC_HIDDEN;
203 struct table *create_table( const WCHAR *, UINT, const struct column *, UINT, UINT, BYTE *,
204 enum fill_status (*)(struct table *, const struct expr *) ) DECLSPEC_HIDDEN;
205 BOOL add_table( struct table * ) DECLSPEC_HIDDEN;
206 void free_columns( struct column *, UINT ) DECLSPEC_HIDDEN;
207 void free_row_values( const struct table *, UINT ) DECLSPEC_HIDDEN;
208 void clear_table( struct table * ) DECLSPEC_HIDDEN;
209 void free_table( struct table * ) DECLSPEC_HIDDEN;
210 UINT get_type_size( CIMTYPE ) DECLSPEC_HIDDEN;
211 HRESULT eval_cond( const struct table *, UINT, const struct expr *, LONGLONG * ) DECLSPEC_HIDDEN;
212 HRESULT get_column_index( const struct table *, const WCHAR *, UINT * ) DECLSPEC_HIDDEN;
213 HRESULT get_value( const struct table *, UINT, UINT, LONGLONG * ) DECLSPEC_HIDDEN;
214 BSTR get_value_bstr( const struct table *, UINT, UINT ) DECLSPEC_HIDDEN;
215 HRESULT set_value( const struct table *, UINT, UINT, LONGLONG, CIMTYPE ) DECLSPEC_HIDDEN;
216 HRESULT get_method( const struct table *, const WCHAR *, class_method ** ) DECLSPEC_HIDDEN;
217 HRESULT get_propval( const struct view *, UINT, const WCHAR *, VARIANT *,
218 CIMTYPE *, LONG * ) DECLSPEC_HIDDEN;
219 HRESULT put_propval( const struct view *, UINT, const WCHAR *, VARIANT *, CIMTYPE ) DECLSPEC_HIDDEN;
220 HRESULT to_longlong( VARIANT *, LONGLONG *, CIMTYPE * ) DECLSPEC_HIDDEN;
221 SAFEARRAY *to_safearray( const struct array *, CIMTYPE ) DECLSPEC_HIDDEN;
222 VARTYPE to_vartype( CIMTYPE ) DECLSPEC_HIDDEN;
223 void destroy_array( struct array *, CIMTYPE ) DECLSPEC_HIDDEN;
224 HRESULT get_properties( const struct view *, SAFEARRAY ** ) DECLSPEC_HIDDEN;
225 HRESULT get_object( const WCHAR *, IWbemClassObject ** ) DECLSPEC_HIDDEN;
226 BSTR get_method_name( const WCHAR *, UINT ) DECLSPEC_HIDDEN;
227 BSTR get_property_name( const WCHAR *, UINT ) DECLSPEC_HIDDEN;
228 void set_variant( VARTYPE, LONGLONG, void *, VARIANT * ) DECLSPEC_HIDDEN;
229 HRESULT create_signature( const WCHAR *, const WCHAR *, enum param_direction,
230 IWbemClassObject ** ) DECLSPEC_HIDDEN;
231
232 HRESULT WbemLocator_create(IUnknown *, LPVOID *) DECLSPEC_HIDDEN;
233 HRESULT WbemServices_create(IUnknown *, const WCHAR *, LPVOID *) DECLSPEC_HIDDEN;
234 HRESULT create_class_object(const WCHAR *, IEnumWbemClassObject *, UINT,
235 struct record *, IWbemClassObject **) DECLSPEC_HIDDEN;
236 HRESULT EnumWbemClassObject_create(IUnknown *, struct query *, LPVOID *) DECLSPEC_HIDDEN;
237 HRESULT WbemQualifierSet_create(IUnknown *, const WCHAR *, const WCHAR *, LPVOID *) DECLSPEC_HIDDEN;
238
239 HRESULT process_get_owner(IWbemClassObject *, IWbemClassObject *, IWbemClassObject **) DECLSPEC_HIDDEN;
240 HRESULT reg_enum_key(IWbemClassObject *, IWbemClassObject *, IWbemClassObject **) DECLSPEC_HIDDEN;
241 HRESULT reg_enum_values(IWbemClassObject *, IWbemClassObject *, IWbemClassObject **) DECLSPEC_HIDDEN;
242 HRESULT reg_get_stringvalue(IWbemClassObject *, IWbemClassObject *, IWbemClassObject **) DECLSPEC_HIDDEN;
243 HRESULT service_pause_service(IWbemClassObject *, IWbemClassObject *, IWbemClassObject **) DECLSPEC_HIDDEN;
244 HRESULT service_resume_service(IWbemClassObject *, IWbemClassObject *, IWbemClassObject **) DECLSPEC_HIDDEN;
245 HRESULT service_start_service(IWbemClassObject *, IWbemClassObject *, IWbemClassObject **) DECLSPEC_HIDDEN;
246 HRESULT service_stop_service(IWbemClassObject *, IWbemClassObject *, IWbemClassObject **) DECLSPEC_HIDDEN;
247
248 static void *heap_alloc( size_t len ) __WINE_ALLOC_SIZE(1);
249 static inline void *heap_alloc( size_t len )
250 {
251 return HeapAlloc( GetProcessHeap(), 0, len );
252 }
253
254 static void *heap_realloc( void *mem, size_t len ) __WINE_ALLOC_SIZE(2);
255 static inline void *heap_realloc( void *mem, size_t len )
256 {
257 return HeapReAlloc( GetProcessHeap(), 0, mem, len );
258 }
259
260 static void *heap_alloc_zero( size_t len ) __WINE_ALLOC_SIZE(1);
261 static inline void *heap_alloc_zero( size_t len )
262 {
263 return HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, len );
264 }
265
266 static inline BOOL heap_free( void *mem )
267 {
268 return HeapFree( GetProcessHeap(), 0, mem );
269 }
270
271 static inline WCHAR *heap_strdupW( const WCHAR *src )
272 {
273 WCHAR *dst;
274 if (!src) return NULL;
275 if ((dst = heap_alloc( (strlenW( src ) + 1) * sizeof(WCHAR) ))) strcpyW( dst, src );
276 return dst;
277 }
278
279 static inline const char *debugstr_variant( const VARIANT *v )
280 {
281 if (!v) return "(null)";
282 switch (V_VT(v))
283 {
284 case VT_EMPTY:
285 return "{VT_EMPTY}";
286 case VT_NULL:
287 return "{VT_NULL}";
288 case VT_I4:
289 return wine_dbg_sprintf( "{VT_I4: %d}", V_I4(v) );
290 case VT_R8:
291 return wine_dbg_sprintf( "{VT_R8: %lf}", V_R8(v) );
292 case VT_BSTR:
293 return wine_dbg_sprintf( "{VT_BSTR: %s}", debugstr_w(V_BSTR(v)) );
294 case VT_DISPATCH:
295 return wine_dbg_sprintf( "{VT_DISPATCH: %p}", V_DISPATCH(v) );
296 case VT_BOOL:
297 return wine_dbg_sprintf( "{VT_BOOL: %x}", V_BOOL(v) );
298 case VT_UNKNOWN:
299 return wine_dbg_sprintf( "{VT_UNKNOWN: %p}", V_UNKNOWN(v) );
300 case VT_UINT:
301 return wine_dbg_sprintf( "{VT_UINT: %u}", V_UINT(v) );
302 case VT_BSTR|VT_BYREF:
303 return wine_dbg_sprintf( "{VT_BSTR|VT_BYREF: ptr %p, data %s}",
304 V_BSTRREF(v), V_BSTRREF(v) ? debugstr_w( *V_BSTRREF(v) ) : NULL );
305 default:
306 return wine_dbg_sprintf( "{vt %d}", V_VT(v) );
307 }
308 }
309
310 static const WCHAR class_processW[] = {'W','i','n','3','2','_','P','r','o','c','e','s','s',0};
311 static const WCHAR class_serviceW[] = {'W','i','n','3','2','_','S','e','r','v','i','c','e',0};
312 static const WCHAR class_stdregprovW[] = {'S','t','d','R','e','g','P','r','o','v',0};
313
314 static const WCHAR prop_nameW[] = {'N','a','m','e',0};
315
316 static const WCHAR method_enumkeyW[] = {'E','n','u','m','K','e','y',0};
317 static const WCHAR method_enumvaluesW[] = {'E','n','u','m','V','a','l','u','e','s',0};
318 static const WCHAR method_getownerW[] = {'G','e','t','O','w','n','e','r',0};
319 static const WCHAR method_getstringvalueW[] = {'G','e','t','S','t','r','i','n','g','V','a','l','u','e',0};
320 static const WCHAR method_pauseserviceW[] = {'P','a','u','s','e','S','e','r','v','i','c','e',0};
321 static const WCHAR method_resumeserviceW[] = {'R','e','s','u','m','e','S','e','r','v','i','c','e',0};
322 static const WCHAR method_startserviceW[] = {'S','t','a','r','t','S','e','r','v','i','c','e',0};
323 static const WCHAR method_stopserviceW[] = {'S','t','o','p','S','e','r','v','i','c','e',0};
324
325 static const WCHAR param_defkeyW[] = {'h','D','e','f','K','e','y',0};
326 static const WCHAR param_domainW[] = {'D','o','m','a','i','n',0};
327 static const WCHAR param_namesW[] = {'s','N','a','m','e','s',0};
328 static const WCHAR param_returnvalueW[] = {'R','e','t','u','r','n','V','a','l','u','e',0};
329 static const WCHAR param_subkeynameW[] = {'s','S','u','b','K','e','y','N','a','m','e',0};
330 static const WCHAR param_typesW[] = {'T','y','p','e','s',0};
331 static const WCHAR param_userW[] = {'U','s','e','r',0};
332 static const WCHAR param_valueW[] = {'s','V','a','l','u','e',0};
333 static const WCHAR param_valuenameW[] = {'s','V','a','l','u','e','N','a','m','e',0};