jscript: Get rid of BSTR in date.c.
[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 COL_TYPE_MASK    0x0000ffff
35 #define COL_FLAG_DYNAMIC 0x00010000
36 #define COL_FLAG_KEY     0x00020000
37 #define COL_FLAG_METHOD  0x00040000
38
39 typedef HRESULT (class_method)(IWbemClassObject *, IWbemClassObject **);
40
41 struct column
42 {
43     const WCHAR *name;
44     UINT type;
45     VARTYPE vartype; /* 0 for default mapping */
46 };
47
48 #define TABLE_FLAG_DYNAMIC 0x00000001
49
50 struct table
51 {
52     const WCHAR *name;
53     UINT num_cols;
54     const struct column *columns;
55     UINT num_rows;
56     BYTE *data;
57     void (*fill)(struct table *);
58     UINT flags;
59     struct list entry;
60     LONG refs;
61 };
62
63 struct property
64 {
65     const WCHAR *name;
66     const WCHAR *class;
67     const struct property *next;
68 };
69
70 struct array
71 {
72     UINT count;
73     void *ptr;
74 };
75
76 struct field
77 {
78     UINT type;
79     union
80     {
81         LONGLONG ival;
82         WCHAR *sval;
83         struct array *aval;
84     } u;
85 };
86
87 struct record
88 {
89     UINT count;
90     struct field *fields;
91 };
92
93 enum operator
94 {
95     OP_EQ      = 1,
96     OP_AND     = 2,
97     OP_OR      = 3,
98     OP_GT      = 4,
99     OP_LT      = 5,
100     OP_LE      = 6,
101     OP_GE      = 7,
102     OP_NE      = 8,
103     OP_ISNULL  = 9,
104     OP_NOTNULL = 10,
105     OP_LIKE    = 11
106 };
107
108 struct expr;
109 struct complex_expr
110 {
111     enum operator op;
112     struct expr *left;
113     struct expr *right;
114 };
115
116 enum expr_type
117 {
118     EXPR_COMPLEX = 1,
119     EXPR_UNARY   = 2,
120     EXPR_PROPVAL = 3,
121     EXPR_SVAL    = 4,
122     EXPR_IVAL    = 5,
123     EXPR_BVAL    = 6
124 };
125
126 struct expr
127 {
128     enum expr_type type;
129     union
130     {
131         struct complex_expr expr;
132         const struct property *propval;
133         const WCHAR *sval;
134         int ival;
135     } u;
136 };
137
138 struct view
139 {
140     const struct property *proplist;
141     struct table *table;
142     const struct expr *cond;
143     UINT *result;
144     UINT  count;
145 };
146
147 struct query
148 {
149     LONG refs;
150     struct view *view;
151     struct list mem;
152 };
153
154 void addref_query( struct query * ) DECLSPEC_HIDDEN;
155 void release_query( struct query *query ) DECLSPEC_HIDDEN;
156 HRESULT exec_query( const WCHAR *, IEnumWbemClassObject ** ) DECLSPEC_HIDDEN;
157 HRESULT parse_query( const WCHAR *, struct view **, struct list * ) DECLSPEC_HIDDEN;
158 HRESULT create_view( const struct property *, const WCHAR *, const struct expr *,
159                      struct view ** ) DECLSPEC_HIDDEN;
160 void destroy_view( struct view * ) DECLSPEC_HIDDEN;
161 void init_table_list( void ) DECLSPEC_HIDDEN;
162 struct table *grab_table( const WCHAR * ) DECLSPEC_HIDDEN;
163 void release_table( struct table * ) DECLSPEC_HIDDEN;
164 struct table *create_table( const WCHAR *, UINT, const struct column *, UINT,
165                             BYTE *, void (*)(struct table *)) DECLSPEC_HIDDEN;
166 BOOL add_table( struct table * ) DECLSPEC_HIDDEN;
167 void free_columns( struct column *, UINT ) DECLSPEC_HIDDEN;
168 void free_table( struct table * ) DECLSPEC_HIDDEN;
169 UINT get_type_size( CIMTYPE ) DECLSPEC_HIDDEN;
170 HRESULT get_column_index( const struct table *, const WCHAR *, UINT * ) DECLSPEC_HIDDEN;
171 HRESULT get_value( const struct table *, UINT, UINT, LONGLONG * ) DECLSPEC_HIDDEN;
172 BSTR get_value_bstr( const struct table *, UINT, UINT ) DECLSPEC_HIDDEN;
173 HRESULT set_value( const struct table *, UINT, UINT, LONGLONG, CIMTYPE ) DECLSPEC_HIDDEN;
174 HRESULT get_method( const struct table *, const WCHAR *, class_method ** ) DECLSPEC_HIDDEN;
175 HRESULT get_propval( const struct view *, UINT, const WCHAR *, VARIANT *,
176                      CIMTYPE *, LONG * ) DECLSPEC_HIDDEN;
177 HRESULT put_propval( const struct view *, UINT, const WCHAR *, VARIANT *, CIMTYPE ) DECLSPEC_HIDDEN;
178 HRESULT to_longlong( VARIANT *, LONGLONG *, CIMTYPE * ) DECLSPEC_HIDDEN;
179 SAFEARRAY *to_safearray( const struct array *, CIMTYPE ) DECLSPEC_HIDDEN;
180 HRESULT get_properties( const struct view *, SAFEARRAY ** ) DECLSPEC_HIDDEN;
181 HRESULT get_object( const WCHAR *, IWbemClassObject ** ) DECLSPEC_HIDDEN;
182 BSTR get_method_name( const WCHAR *, UINT ) DECLSPEC_HIDDEN;
183 BSTR get_property_name( const WCHAR *, UINT ) DECLSPEC_HIDDEN;
184
185 HRESULT WbemLocator_create(IUnknown *, LPVOID *) DECLSPEC_HIDDEN;
186 HRESULT WbemServices_create(IUnknown *, const WCHAR *, LPVOID *) DECLSPEC_HIDDEN;
187 HRESULT create_class_object(const WCHAR *, IEnumWbemClassObject *, UINT,
188                             struct record *, IWbemClassObject **) DECLSPEC_HIDDEN;
189 HRESULT EnumWbemClassObject_create(IUnknown *, struct query *, LPVOID *) DECLSPEC_HIDDEN;
190
191 static void *heap_alloc( size_t len ) __WINE_ALLOC_SIZE(1);
192 static inline void *heap_alloc( size_t len )
193 {
194     return HeapAlloc( GetProcessHeap(), 0, len );
195 }
196
197 static void *heap_realloc( void *mem, size_t len ) __WINE_ALLOC_SIZE(2);
198 static inline void *heap_realloc( void *mem, size_t len )
199 {
200     return HeapReAlloc( GetProcessHeap(), 0, mem, len );
201 }
202
203 static void *heap_alloc_zero( size_t len ) __WINE_ALLOC_SIZE(1);
204 static inline void *heap_alloc_zero( size_t len )
205 {
206     return HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, len );
207 }
208
209 static inline BOOL heap_free( void *mem )
210 {
211     return HeapFree( GetProcessHeap(), 0, mem );
212 }
213
214 static inline WCHAR *heap_strdupW( const WCHAR *src )
215 {
216     WCHAR *dst;
217     if (!src) return NULL;
218     if ((dst = heap_alloc( (strlenW( src ) + 1) * sizeof(WCHAR) ))) strcpyW( dst, src );
219     return dst;
220 }