Commit f6be2110 authored by Hans Leidekker's avatar Hans Leidekker Committed by Alexandre Julliard

wbemprox: Add support for parsing WQL queries.

parent 52363aef
......@@ -135,6 +135,8 @@ dlls/vbscript/parser.tab.c
dlls/vbscript/parser.tab.h
dlls/vbscript/vbscript_classes.h
dlls/vbscript/vbsglobal.h
dlls/wbemprox/wql.tab.c
dlls/wbemprox/wql.tab.h
dlls/windowscodecs/windowscodecs_wincodec.h
dlls/windowscodecs/windowscodecs_wincodec_p.c
dlls/wshom.ocx/tests/wshom.h
......
......@@ -4,9 +4,12 @@ IMPORTS = ole32 advapi32
C_SRCS = \
class.c \
main.c \
query.c \
services.c \
wbemlocator.c
IDL_R_SRCS = wbemprox.idl
BISON_SRCS = wql.y
@MAKE_DLL_RULES@
......@@ -35,6 +35,7 @@ struct enum_class_object
{
IEnumWbemClassObject IEnumWbemClassObject_iface;
LONG refs;
struct query *query;
};
static inline struct enum_class_object *impl_from_IEnumWbemClassObject(
......@@ -58,6 +59,7 @@ static ULONG WINAPI enum_class_object_Release(
if (!refs)
{
TRACE("destroying %p\n", ec);
free_query( ec->query );
heap_free( ec );
}
return refs;
......@@ -143,7 +145,7 @@ static const IEnumWbemClassObjectVtbl enum_class_object_vtbl =
};
HRESULT EnumWbemClassObject_create(
IUnknown *pUnkOuter, LPVOID *ppObj )
IUnknown *pUnkOuter, struct query *query, LPVOID *ppObj )
{
struct enum_class_object *ec;
......@@ -154,6 +156,7 @@ HRESULT EnumWbemClassObject_create(
ec->IEnumWbemClassObject_iface.lpVtbl = &enum_class_object_vtbl;
ec->refs = 1;
ec->query = query;
*ppObj = &ec->IEnumWbemClassObject_iface;
......
/*
* Copyright 2012 Hans Leidekker for CodeWeavers
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*/
#define COBJMACROS
#include "config.h"
#include <stdarg.h>
#include "windef.h"
#include "winbase.h"
#include "wbemcli.h"
#include "wine/debug.h"
#include "wbemprox_private.h"
WINE_DEFAULT_DEBUG_CHANNEL(wbemprox);
HRESULT create_view( const struct property *proplist, const WCHAR *class,
const struct expr *cond, struct view **ret )
{
struct view *view = heap_alloc( sizeof(struct view) );
if (!view) return E_OUTOFMEMORY;
view->proplist = proplist;
view->cond = cond;
*ret = view;
return S_OK;
}
void destroy_view( struct view *view )
{
heap_free( view );
}
static struct query *alloc_query(void)
{
struct query *query;
if (!(query = heap_alloc( sizeof(*query) ))) return NULL;
list_init( &query->mem );
return query;
}
void free_query( struct query *query )
{
struct list *mem, *next;
destroy_view( query->view );
LIST_FOR_EACH_SAFE( mem, next, &query->mem )
{
heap_free( mem );
}
heap_free( query );
}
HRESULT exec_query( const WCHAR *str, IEnumWbemClassObject **result )
{
HRESULT hr;
struct query *query;
*result = NULL;
if (!(query = alloc_query())) return E_OUTOFMEMORY;
hr = parse_query( str, &query->view, &query->mem );
if (hr != S_OK)
{
free_query( query );
return hr;
}
hr = EnumWbemClassObject_create( NULL, query, (void **)result );
if (hr != S_OK) free_query( query );
return hr;
}
......@@ -158,7 +158,7 @@ static ULONG WINAPI wbem_services_Release(
if (!refs)
{
TRACE("destroying %p\n", ws);
HeapFree( GetProcessHeap(), 0, ws );
heap_free( ws );
}
return refs;
}
......@@ -383,9 +383,14 @@ static HRESULT WINAPI wbem_services_ExecQuery(
IWbemContext *pCtx,
IEnumWbemClassObject **ppEnum )
{
FIXME("%p, %s, %s, 0x%08x, %p, %p\n", iface, debugstr_w(strQueryLanguage),
static const WCHAR wqlW[] = {'W','Q','L',0};
TRACE("%p, %s, %s, 0x%08x, %p, %p\n", iface, debugstr_w(strQueryLanguage),
debugstr_w(strQuery), lFlags, pCtx, ppEnum);
return WBEM_E_FAILED;
if (!strQueryLanguage || !strQuery) return WBEM_E_INVALID_PARAMETER;
if (strcmpiW( strQueryLanguage, wqlW )) return WBEM_E_INVALID_QUERY_TYPE;
return exec_query( strQuery, ppEnum );
}
static HRESULT WINAPI wbem_services_ExecQueryAsync(
......@@ -487,7 +492,7 @@ HRESULT WbemServices_create( IUnknown *pUnkOuter, LPVOID *ppObj )
TRACE("(%p,%p)\n", pUnkOuter, ppObj);
ws = HeapAlloc( GetProcessHeap(), 0, sizeof(*ws) );
ws = heap_alloc( sizeof(*ws) );
if (!ws) return E_OUTOFMEMORY;
ws->IWbemServices_iface.lpVtbl = &wbem_services_vtbl;
......
......@@ -16,8 +16,84 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include "wine/list.h"
#define SIZEOF(array) (sizeof(array)/sizeof((array)[0]))
struct property
{
const WCHAR *name;
const WCHAR *class;
const struct property *next;
};
enum operator
{
OP_EQ = 1,
OP_AND = 2,
OP_OR = 3,
OP_GT = 4,
OP_LT = 5,
OP_LE = 6,
OP_GE = 7,
OP_NE = 8,
OP_ISNULL = 9,
OP_NOTNULL = 10,
OP_LIKE = 11
};
struct expr;
struct complex_expr
{
enum operator op;
struct expr *left;
struct expr *right;
};
enum expr_type
{
EXPR_COMPLEX = 1,
EXPR_UNARY = 2,
EXPR_PROPVAL = 3,
EXPR_SVAL = 4,
EXPR_IVAL = 5,
EXPR_BVAL = 6
};
struct expr
{
enum expr_type type;
union
{
struct complex_expr expr;
const struct property *propval;
const WCHAR *sval;
int ival;
} u;
};
struct view
{
const struct property *proplist;
const struct expr *cond;
};
struct query
{
struct view *view;
struct list mem;
};
void free_query( struct query * ) DECLSPEC_HIDDEN;
HRESULT exec_query( const WCHAR *, IEnumWbemClassObject ** ) DECLSPEC_HIDDEN;
HRESULT parse_query( const WCHAR *, struct view **, struct list * ) DECLSPEC_HIDDEN;
HRESULT create_view( const struct property *, const WCHAR *, const struct expr *,
struct view ** ) DECLSPEC_HIDDEN;
void destroy_view( struct view * ) DECLSPEC_HIDDEN;
HRESULT WbemLocator_create(IUnknown *, LPVOID *) DECLSPEC_HIDDEN;
HRESULT WbemServices_create(IUnknown *, LPVOID *) DECLSPEC_HIDDEN;
HRESULT EnumWbemClassObject_create(IUnknown *, struct query *, LPVOID *) DECLSPEC_HIDDEN;
static void *heap_alloc( size_t len ) __WINE_ALLOC_SIZE(1);
static inline void *heap_alloc( size_t len )
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment