wbemprox: Store the class name in the class object.
[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 };
61
62 struct property
63 {
64     const WCHAR *name;
65     const WCHAR *class;
66     const struct property *next;
67 };
68
69 enum operator
70 {
71     OP_EQ      = 1,
72     OP_AND     = 2,
73     OP_OR      = 3,
74     OP_GT      = 4,
75     OP_LT      = 5,
76     OP_LE      = 6,
77     OP_GE      = 7,
78     OP_NE      = 8,
79     OP_ISNULL  = 9,
80     OP_NOTNULL = 10,
81     OP_LIKE    = 11
82 };
83
84 struct expr;
85 struct complex_expr
86 {
87     enum operator op;
88     struct expr *left;
89     struct expr *right;
90 };
91
92 enum expr_type
93 {
94     EXPR_COMPLEX = 1,
95     EXPR_UNARY   = 2,
96     EXPR_PROPVAL = 3,
97     EXPR_SVAL    = 4,
98     EXPR_IVAL    = 5,
99     EXPR_BVAL    = 6
100 };
101
102 struct expr
103 {
104     enum expr_type type;
105     union
106     {
107         struct complex_expr expr;
108         const struct property *propval;
109         const WCHAR *sval;
110         int ival;
111     } u;
112 };
113
114 struct view
115 {
116     const struct property *proplist;
117     struct table *table;
118     const struct expr *cond;
119     UINT *result;
120     UINT  count;
121 };
122
123 struct query
124 {
125     LONG refs;
126     struct view *view;
127     struct list mem;
128 };
129
130 void addref_query( struct query * ) DECLSPEC_HIDDEN;
131 void release_query( struct query *query ) DECLSPEC_HIDDEN;
132 HRESULT exec_query( const WCHAR *, IEnumWbemClassObject ** ) DECLSPEC_HIDDEN;
133 HRESULT parse_query( const WCHAR *, struct view **, struct list * ) DECLSPEC_HIDDEN;
134 HRESULT create_view( const struct property *, const WCHAR *, const struct expr *,
135                      struct view ** ) DECLSPEC_HIDDEN;
136 void destroy_view( struct view * ) DECLSPEC_HIDDEN;
137 void init_table_list( void ) DECLSPEC_HIDDEN;
138 struct table *get_table( const WCHAR * ) DECLSPEC_HIDDEN;
139 struct table *create_table( const WCHAR *, UINT, const struct column *, UINT,
140                             BYTE *, void (*)(struct table *)) DECLSPEC_HIDDEN;
141 BOOL add_table( struct table * ) DECLSPEC_HIDDEN;
142 void free_columns( struct column *, UINT ) DECLSPEC_HIDDEN;
143 void free_table( struct table * ) DECLSPEC_HIDDEN;
144 UINT get_type_size( CIMTYPE ) DECLSPEC_HIDDEN;
145 HRESULT get_column_index( const struct table *, const WCHAR *, UINT * ) DECLSPEC_HIDDEN;
146 HRESULT get_value( const struct table *, UINT, UINT, LONGLONG * ) DECLSPEC_HIDDEN;
147 BSTR get_value_bstr( const struct table *, UINT, UINT ) DECLSPEC_HIDDEN;
148 HRESULT set_value( const struct table *, UINT, UINT, LONGLONG, CIMTYPE ) DECLSPEC_HIDDEN;
149 HRESULT get_propval( const struct view *, UINT, const WCHAR *, VARIANT *,
150                      CIMTYPE *, LONG * ) DECLSPEC_HIDDEN;
151 HRESULT put_propval( const struct view *, UINT, const WCHAR *, VARIANT *, CIMTYPE ) DECLSPEC_HIDDEN;
152 HRESULT get_properties( const struct view *, SAFEARRAY ** ) DECLSPEC_HIDDEN;
153 HRESULT get_object( const WCHAR *, IWbemClassObject ** ) DECLSPEC_HIDDEN;
154
155 HRESULT WbemLocator_create(IUnknown *, LPVOID *) DECLSPEC_HIDDEN;
156 HRESULT WbemServices_create(IUnknown *, const WCHAR *, LPVOID *) DECLSPEC_HIDDEN;
157 HRESULT create_class_object(const WCHAR *, IEnumWbemClassObject *, UINT,
158                             IWbemClassObject **) DECLSPEC_HIDDEN;
159 HRESULT EnumWbemClassObject_create(IUnknown *, struct query *, LPVOID *) DECLSPEC_HIDDEN;
160
161 static void *heap_alloc( size_t len ) __WINE_ALLOC_SIZE(1);
162 static inline void *heap_alloc( size_t len )
163 {
164     return HeapAlloc( GetProcessHeap(), 0, len );
165 }
166
167 static void *heap_realloc( void *mem, size_t len ) __WINE_ALLOC_SIZE(2);
168 static inline void *heap_realloc( void *mem, size_t len )
169 {
170     return HeapReAlloc( GetProcessHeap(), 0, mem, len );
171 }
172
173 static void *heap_alloc_zero( size_t len ) __WINE_ALLOC_SIZE(1);
174 static inline void *heap_alloc_zero( size_t len )
175 {
176     return HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, len );
177 }
178
179 static inline BOOL heap_free( void *mem )
180 {
181     return HeapFree( GetProcessHeap(), 0, mem );
182 }
183
184 static inline WCHAR *heap_strdupW( const WCHAR *src )
185 {
186     WCHAR *dst;
187     if (!src) return NULL;
188     if ((dst = heap_alloc( (strlenW( src ) + 1) * sizeof(WCHAR) ))) strcpyW( dst, src );
189     return dst;
190 }