wbemprox: Add a partial Win32_BIOS class implementation.
[wine.git] / dlls / wbemprox / query.c
blob551cd2015766891b0b3096fa7f12e73e5cce0915
1 /*
2 * Copyright 2012 Hans Leidekker for CodeWeavers
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.
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.
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
19 #define COBJMACROS
21 #include "config.h"
22 #include <stdarg.h>
24 #include "windef.h"
25 #include "winbase.h"
26 #include "wbemcli.h"
28 #include "wine/debug.h"
29 #include "wbemprox_private.h"
31 WINE_DEFAULT_DEBUG_CHANNEL(wbemprox);
33 HRESULT create_view( const struct property *proplist, const WCHAR *class,
34 const struct expr *cond, struct view **ret )
36 struct view *view = heap_alloc( sizeof(struct view) );
38 if (!view) return E_OUTOFMEMORY;
39 view->proplist = proplist;
40 view->table = get_table( class );
41 view->cond = cond;
42 *ret = view;
43 return S_OK;
46 void destroy_view( struct view *view )
48 heap_free( view );
51 static struct query *alloc_query(void)
53 struct query *query;
55 if (!(query = heap_alloc( sizeof(*query) ))) return NULL;
56 list_init( &query->mem );
57 return query;
60 void free_query( struct query *query )
62 struct list *mem, *next;
64 destroy_view( query->view );
65 LIST_FOR_EACH_SAFE( mem, next, &query->mem )
67 heap_free( mem );
69 heap_free( query );
72 HRESULT exec_query( const WCHAR *str, IEnumWbemClassObject **result )
74 HRESULT hr;
75 struct query *query;
77 *result = NULL;
78 if (!(query = alloc_query())) return E_OUTOFMEMORY;
79 hr = parse_query( str, &query->view, &query->mem );
80 if (hr != S_OK)
82 free_query( query );
83 return hr;
85 hr = EnumWbemClassObject_create( NULL, query, (void **)result );
86 if (hr != S_OK) free_query( query );
87 return hr;