wbemprox: Implement IEnumWbemClassObject::Clone.
[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
24 #define SIZEOF(array) (sizeof(array)/sizeof((array)[0]))
25
26 #define COL_TYPE_MASK    0x0000ffff
27 #define COL_FLAG_DYNAMIC 0x00010000
28 #define COL_FLAG_KEY     0x00020000
29
30 struct column
31 {
32     const WCHAR *name;
33     UINT type;
34 };
35
36 struct table
37 {
38     const WCHAR *name;
39     UINT num_cols;
40     const struct column *columns;
41     UINT num_rows;
42     BYTE *data;
43     void (*fill)(struct table *);
44 };
45
46 struct property
47 {
48     const WCHAR *name;
49     const WCHAR *class;
50     const struct property *next;
51 };
52
53 enum operator
54 {
55     OP_EQ      = 1,
56     OP_AND     = 2,
57     OP_OR      = 3,
58     OP_GT      = 4,
59     OP_LT      = 5,
60     OP_LE      = 6,
61     OP_GE      = 7,
62     OP_NE      = 8,
63     OP_ISNULL  = 9,
64     OP_NOTNULL = 10,
65     OP_LIKE    = 11
66 };
67
68 struct expr;
69 struct complex_expr
70 {
71     enum operator op;
72     struct expr *left;
73     struct expr *right;
74 };
75
76 enum expr_type
77 {
78     EXPR_COMPLEX = 1,
79     EXPR_UNARY   = 2,
80     EXPR_PROPVAL = 3,
81     EXPR_SVAL    = 4,
82     EXPR_IVAL    = 5,
83     EXPR_BVAL    = 6
84 };
85
86 struct expr
87 {
88     enum expr_type type;
89     union
90     {
91         struct complex_expr expr;
92         const struct property *propval;
93         const WCHAR *sval;
94         int ival;
95     } u;
96 };
97
98 struct view
99 {
100     const struct property *proplist;
101     struct table *table;
102     const struct expr *cond;
103     UINT *result;
104     UINT  count;
105 };
106
107 struct query
108 {
109     LONG refs;
110     struct view *view;
111     struct list mem;
112 };
113
114 void addref_query( struct query * ) DECLSPEC_HIDDEN;
115 void release_query( struct query *query ) DECLSPEC_HIDDEN;
116 HRESULT exec_query( const WCHAR *, IEnumWbemClassObject ** ) DECLSPEC_HIDDEN;
117 HRESULT parse_query( const WCHAR *, struct view **, struct list * ) DECLSPEC_HIDDEN;
118 HRESULT create_view( const struct property *, const WCHAR *, const struct expr *,
119                      struct view ** ) DECLSPEC_HIDDEN;
120 void destroy_view( struct view * ) DECLSPEC_HIDDEN;
121 struct table *get_table( const WCHAR * ) DECLSPEC_HIDDEN;
122 HRESULT get_propval( const struct view *, UINT, const WCHAR *, VARIANT *,
123                      CIMTYPE * ) DECLSPEC_HIDDEN;
124 HRESULT get_properties( const struct view *, SAFEARRAY ** ) DECLSPEC_HIDDEN;
125
126 HRESULT WbemLocator_create(IUnknown *, LPVOID *) DECLSPEC_HIDDEN;
127 HRESULT WbemServices_create(IUnknown *, const WCHAR *, LPVOID *) DECLSPEC_HIDDEN;
128 HRESULT WbemClassObject_create(IUnknown *, IEnumWbemClassObject *, UINT, LPVOID *) DECLSPEC_HIDDEN;
129 HRESULT EnumWbemClassObject_create(IUnknown *, struct query *, LPVOID *) DECLSPEC_HIDDEN;
130
131 static void *heap_alloc( size_t len ) __WINE_ALLOC_SIZE(1);
132 static inline void *heap_alloc( size_t len )
133 {
134     return HeapAlloc( GetProcessHeap(), 0, len );
135 }
136
137 static void *heap_realloc( void *mem, size_t len ) __WINE_ALLOC_SIZE(2);
138 static inline void *heap_realloc( void *mem, size_t len )
139 {
140     return HeapReAlloc( GetProcessHeap(), 0, mem, len );
141 }
142
143 static inline BOOL heap_free( void *mem )
144 {
145     return HeapFree( GetProcessHeap(), 0, mem );
146 }
147
148 static inline WCHAR *heap_strdupW( const WCHAR *src )
149 {
150     WCHAR *dst;
151     if (!src) return NULL;
152     if ((dst = heap_alloc( (strlenW( src ) + 1) * sizeof(WCHAR) ))) strcpyW( dst, src );
153     return dst;
154 }