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