winemac: Implement support for owned windows.
[wine] / dlls / 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 "wine/list.h"
20 #include "wine/unicode.h"
21
22 IClientSecurity client_security;
23 struct list *table_list;
24
25 #define SIZEOF(array) (sizeof(array)/sizeof((array)[0]))
26
27 enum param_direction
28 {
29     PARAM_OUT   = -1,
30     PARAM_INOUT = 0,
31     PARAM_IN    = 1
32 };
33
34 #define CIM_TYPE_MASK    0x00000fff
35
36 #define COL_TYPE_MASK    0x0000ffff
37 #define COL_FLAG_DYNAMIC 0x00010000
38 #define COL_FLAG_KEY     0x00020000
39 #define COL_FLAG_METHOD  0x00040000
40
41 typedef HRESULT (class_method)(IWbemClassObject *, IWbemClassObject *, IWbemClassObject **);
42
43 struct column
44 {
45     const WCHAR *name;
46     UINT type;
47     VARTYPE vartype; /* 0 for default mapping */
48 };
49
50 #define TABLE_FLAG_DYNAMIC 0x00000001
51
52 struct table
53 {
54     const WCHAR *name;
55     UINT num_cols;
56     const struct column *columns;
57     UINT num_rows;
58     BYTE *data;
59     void (*fill)(struct table *);
60     UINT flags;
61     struct list entry;
62     LONG refs;
63 };
64
65 struct property
66 {
67     const WCHAR *name;
68     const WCHAR *class;
69     const struct property *next;
70 };
71
72 struct array
73 {
74     UINT count;
75     void *ptr;
76 };
77
78 struct field
79 {
80     UINT type;
81     VARTYPE vartype; /* 0 for default mapping */
82     union
83     {
84         LONGLONG ival;
85         WCHAR *sval;
86         struct array *aval;
87     } u;
88 };
89
90 struct record
91 {
92     UINT count;
93     struct field *fields;
94     struct table *table;
95 };
96
97 enum operator
98 {
99     OP_EQ      = 1,
100     OP_AND     = 2,
101     OP_OR      = 3,
102     OP_GT      = 4,
103     OP_LT      = 5,
104     OP_LE      = 6,
105     OP_GE      = 7,
106     OP_NE      = 8,
107     OP_ISNULL  = 9,
108     OP_NOTNULL = 10,
109     OP_LIKE    = 11
110 };
111
112 struct expr;
113 struct complex_expr
114 {
115     enum operator op;
116     struct expr *left;
117     struct expr *right;
118 };
119
120 enum expr_type
121 {
122     EXPR_COMPLEX = 1,
123     EXPR_UNARY   = 2,
124     EXPR_PROPVAL = 3,
125     EXPR_SVAL    = 4,
126     EXPR_IVAL    = 5,
127     EXPR_BVAL    = 6
128 };
129
130 struct expr
131 {
132     enum expr_type type;
133     union
134     {
135         struct complex_expr expr;
136         const struct property *propval;
137         const WCHAR *sval;
138         int ival;
139     } u;
140 };
141
142 struct view
143 {
144     const struct property *proplist;
145     struct table *table;
146     const struct expr *cond;
147     UINT *result;
148     UINT  count;
149 };
150
151 struct query
152 {
153     LONG refs;
154     struct view *view;
155     struct list mem;
156 };
157
158 struct query *addref_query( struct query * ) DECLSPEC_HIDDEN;
159 void release_query( struct query *query ) DECLSPEC_HIDDEN;
160 HRESULT exec_query( const WCHAR *, IEnumWbemClassObject ** ) DECLSPEC_HIDDEN;
161 HRESULT parse_query( const WCHAR *, struct view **, struct list * ) DECLSPEC_HIDDEN;
162 HRESULT create_view( const struct property *, const WCHAR *, const struct expr *,
163                      struct view ** ) DECLSPEC_HIDDEN;
164 void destroy_view( struct view * ) DECLSPEC_HIDDEN;
165 void init_table_list( void ) DECLSPEC_HIDDEN;
166 struct table *grab_table( const WCHAR * ) DECLSPEC_HIDDEN;
167 struct table *addref_table( struct table * ) DECLSPEC_HIDDEN;
168 void release_table( struct table * ) DECLSPEC_HIDDEN;
169 struct table *create_table( const WCHAR *, UINT, const struct column *, UINT,
170                             BYTE *, void (*)(struct table *)) DECLSPEC_HIDDEN;
171 BOOL add_table( struct table * ) DECLSPEC_HIDDEN;
172 void free_columns( struct column *, UINT ) DECLSPEC_HIDDEN;
173 void free_table( struct table * ) DECLSPEC_HIDDEN;
174 UINT get_type_size( CIMTYPE ) DECLSPEC_HIDDEN;
175 HRESULT get_column_index( const struct table *, const WCHAR *, UINT * ) DECLSPEC_HIDDEN;
176 HRESULT get_value( const struct table *, UINT, UINT, LONGLONG * ) DECLSPEC_HIDDEN;
177 BSTR get_value_bstr( const struct table *, UINT, UINT ) DECLSPEC_HIDDEN;
178 HRESULT set_value( const struct table *, UINT, UINT, LONGLONG, CIMTYPE ) DECLSPEC_HIDDEN;
179 HRESULT get_method( const struct table *, const WCHAR *, class_method ** ) DECLSPEC_HIDDEN;
180 HRESULT get_propval( const struct view *, UINT, const WCHAR *, VARIANT *,
181                      CIMTYPE *, LONG * ) DECLSPEC_HIDDEN;
182 HRESULT put_propval( const struct view *, UINT, const WCHAR *, VARIANT *, CIMTYPE ) DECLSPEC_HIDDEN;
183 HRESULT to_longlong( VARIANT *, LONGLONG *, CIMTYPE * ) DECLSPEC_HIDDEN;
184 SAFEARRAY *to_safearray( const struct array *, CIMTYPE ) DECLSPEC_HIDDEN;
185 VARTYPE to_vartype( CIMTYPE ) DECLSPEC_HIDDEN;
186 void destroy_array( struct array *, CIMTYPE ) DECLSPEC_HIDDEN;
187 HRESULT get_properties( const struct view *, SAFEARRAY ** ) DECLSPEC_HIDDEN;
188 HRESULT get_object( const WCHAR *, IWbemClassObject ** ) DECLSPEC_HIDDEN;
189 BSTR get_method_name( const WCHAR *, UINT ) DECLSPEC_HIDDEN;
190 BSTR get_property_name( const WCHAR *, UINT ) DECLSPEC_HIDDEN;
191 void set_variant( VARTYPE, LONGLONG, void *, VARIANT * ) DECLSPEC_HIDDEN;
192 HRESULT create_signature( const WCHAR *, const WCHAR *, enum param_direction,
193                           IWbemClassObject ** ) DECLSPEC_HIDDEN;
194
195 HRESULT WbemLocator_create(IUnknown *, LPVOID *) DECLSPEC_HIDDEN;
196 HRESULT WbemServices_create(IUnknown *, const WCHAR *, LPVOID *) DECLSPEC_HIDDEN;
197 HRESULT create_class_object(const WCHAR *, IEnumWbemClassObject *, UINT,
198                             struct record *, IWbemClassObject **) DECLSPEC_HIDDEN;
199 HRESULT EnumWbemClassObject_create(IUnknown *, struct query *, LPVOID *) DECLSPEC_HIDDEN;
200
201 HRESULT reg_enum_key(IWbemClassObject *, IWbemClassObject *, IWbemClassObject **) DECLSPEC_HIDDEN;
202 HRESULT reg_enum_values(IWbemClassObject *, IWbemClassObject *, IWbemClassObject **) DECLSPEC_HIDDEN;
203 HRESULT reg_get_stringvalue(IWbemClassObject *, IWbemClassObject *, IWbemClassObject **) DECLSPEC_HIDDEN;
204 HRESULT service_pause_service(IWbemClassObject *, IWbemClassObject *, IWbemClassObject **) DECLSPEC_HIDDEN;
205 HRESULT service_resume_service(IWbemClassObject *, IWbemClassObject *, IWbemClassObject **) DECLSPEC_HIDDEN;
206 HRESULT service_start_service(IWbemClassObject *, IWbemClassObject *, IWbemClassObject **) DECLSPEC_HIDDEN;
207 HRESULT service_stop_service(IWbemClassObject *, IWbemClassObject *, IWbemClassObject **) DECLSPEC_HIDDEN;
208
209 static void *heap_alloc( size_t len ) __WINE_ALLOC_SIZE(1);
210 static inline void *heap_alloc( size_t len )
211 {
212     return HeapAlloc( GetProcessHeap(), 0, len );
213 }
214
215 static void *heap_realloc( void *mem, size_t len ) __WINE_ALLOC_SIZE(2);
216 static inline void *heap_realloc( void *mem, size_t len )
217 {
218     return HeapReAlloc( GetProcessHeap(), 0, mem, len );
219 }
220
221 static void *heap_alloc_zero( size_t len ) __WINE_ALLOC_SIZE(1);
222 static inline void *heap_alloc_zero( size_t len )
223 {
224     return HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, len );
225 }
226
227 static inline BOOL heap_free( void *mem )
228 {
229     return HeapFree( GetProcessHeap(), 0, mem );
230 }
231
232 static inline WCHAR *heap_strdupW( const WCHAR *src )
233 {
234     WCHAR *dst;
235     if (!src) return NULL;
236     if ((dst = heap_alloc( (strlenW( src ) + 1) * sizeof(WCHAR) ))) strcpyW( dst, src );
237     return dst;
238 }
239
240 static const WCHAR class_serviceW[] = {'W','i','n','3','2','_','S','e','r','v','i','c','e',0};
241 static const WCHAR class_stdregprovW[] = {'S','t','d','R','e','g','P','r','o','v',0};
242
243 static const WCHAR prop_nameW[] = {'N','a','m','e',0};
244
245 static const WCHAR method_enumkeyW[] = {'E','n','u','m','K','e','y',0};
246 static const WCHAR method_enumvaluesW[] = {'E','n','u','m','V','a','l','u','e','s',0};
247 static const WCHAR method_getstringvalueW[] = {'G','e','t','S','t','r','i','n','g','V','a','l','u','e',0};
248 static const WCHAR method_pauseserviceW[] = {'P','a','u','s','e','S','e','r','v','i','c','e',0};
249 static const WCHAR method_resumeserviceW[] = {'R','e','s','u','m','e','S','e','r','v','i','c','e',0};
250 static const WCHAR method_startserviceW[] = {'S','t','a','r','t','S','e','r','v','i','c','e',0};
251 static const WCHAR method_stopserviceW[] = {'S','t','o','p','S','e','r','v','i','c','e',0};
252
253 static const WCHAR param_defkeyW[] = {'h','D','e','f','K','e','y',0};
254 static const WCHAR param_namesW[] = {'s','N','a','m','e','s',0};
255 static const WCHAR param_returnvalueW[] = {'R','e','t','u','r','n','V','a','l','u','e',0};
256 static const WCHAR param_subkeynameW[] = {'s','S','u','b','K','e','y','N','a','m','e',0};
257 static const WCHAR param_typesW[] = {'T','y','p','e','s',0};
258 static const WCHAR param_valueW[] = {'s','V','a','l','u','e',0};
259 static const WCHAR param_valuenameW[] = {'s','V','a','l','u','e','N','a','m','e',0};