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

wbemprox: Rewrite IWbemServices::ExecMethod with low-level functions so we can…

wbemprox: Rewrite IWbemServices::ExecMethod with low-level functions so we can reuse the object instance.
parent 9a14d5d0
...@@ -238,7 +238,7 @@ HRESULT eval_cond( const struct table *table, UINT row, const struct expr *cond, ...@@ -238,7 +238,7 @@ HRESULT eval_cond( const struct table *table, UINT row, const struct expr *cond,
return WBEM_E_INVALID_QUERY; return WBEM_E_INVALID_QUERY;
} }
static HRESULT execute_view( struct view *view ) HRESULT execute_view( struct view *view )
{ {
UINT i, j = 0, len; UINT i, j = 0, len;
...@@ -272,7 +272,7 @@ static HRESULT execute_view( struct view *view ) ...@@ -272,7 +272,7 @@ static HRESULT execute_view( struct view *view )
return S_OK; return S_OK;
} }
static struct query *create_query(void) struct query *create_query(void)
{ {
struct query *query; struct query *query;
...@@ -282,15 +282,13 @@ static struct query *create_query(void) ...@@ -282,15 +282,13 @@ static struct query *create_query(void)
return query; return query;
} }
static void free_query( struct query *query ) void free_query( struct query *query )
{ {
struct list *mem, *next; struct list *mem, *next;
if (!query) return;
destroy_view( query->view ); destroy_view( query->view );
LIST_FOR_EACH_SAFE( mem, next, &query->mem ) LIST_FOR_EACH_SAFE( mem, next, &query->mem ) { heap_free( mem ); }
{
heap_free( mem );
}
heap_free( query ); heap_free( query );
} }
......
...@@ -377,7 +377,7 @@ static void free_path( struct path *path ) ...@@ -377,7 +377,7 @@ static void free_path( struct path *path )
heap_free( path ); heap_free( path );
} }
static HRESULT create_instance_enum( const struct path *path, IEnumWbemClassObject **iter ) static WCHAR *query_from_path( const struct path *path )
{ {
static const WCHAR selectW[] = static const WCHAR selectW[] =
{'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ','%','s',' ', {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ','%','s',' ',
...@@ -385,22 +385,30 @@ static HRESULT create_instance_enum( const struct path *path, IEnumWbemClassObje ...@@ -385,22 +385,30 @@ static HRESULT create_instance_enum( const struct path *path, IEnumWbemClassObje
static const WCHAR select_allW[] = static const WCHAR select_allW[] =
{'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',0}; {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',0};
WCHAR *query; WCHAR *query;
HRESULT hr;
UINT len; UINT len;
if (path->filter) if (path->filter)
{ {
len = path->class_len + path->filter_len + SIZEOF(selectW); len = path->class_len + path->filter_len + SIZEOF(selectW);
if (!(query = heap_alloc( len * sizeof(WCHAR) ))) return E_OUTOFMEMORY; if (!(query = heap_alloc( len * sizeof(WCHAR) ))) return NULL;
sprintfW( query, selectW, path->class, path->filter ); sprintfW( query, selectW, path->class, path->filter );
} }
else else
{ {
len = path->class_len + SIZEOF(select_allW); len = path->class_len + SIZEOF(select_allW);
if (!(query = heap_alloc( len * sizeof(WCHAR) ))) return E_OUTOFMEMORY; if (!(query = heap_alloc( len * sizeof(WCHAR) ))) return NULL;
strcpyW( query, select_allW ); strcpyW( query, select_allW );
strcatW( query, path->class ); strcatW( query, path->class );
} }
return query;
}
static HRESULT create_instance_enum( const struct path *path, IEnumWbemClassObject **iter )
{
WCHAR *query;
HRESULT hr;
if (!(query = query_from_path( path ))) return E_OUTOFMEMORY;
hr = exec_query( query, iter ); hr = exec_query( query, iter );
heap_free( query ); heap_free( query );
return hr; return hr;
...@@ -778,10 +786,12 @@ static HRESULT WINAPI wbem_services_ExecMethod( ...@@ -778,10 +786,12 @@ static HRESULT WINAPI wbem_services_ExecMethod(
IWbemClassObject **ppOutParams, IWbemClassObject **ppOutParams,
IWbemCallResult **ppCallResult ) IWbemCallResult **ppCallResult )
{ {
IWbemClassObject *obj; IEnumWbemClassObject *result = NULL;
struct table *table; IWbemClassObject *obj = NULL;
class_method *func; struct query *query = NULL;
struct path *path; struct path *path;
WCHAR *str;
class_method *func;
HRESULT hr; HRESULT hr;
TRACE("%p, %s, %s, %08x, %p, %p, %p, %p\n", iface, debugstr_w(strObjectPath), TRACE("%p, %s, %s, %08x, %p, %p, %p, %p\n", iface, debugstr_w(strObjectPath),
...@@ -789,28 +799,40 @@ static HRESULT WINAPI wbem_services_ExecMethod( ...@@ -789,28 +799,40 @@ static HRESULT WINAPI wbem_services_ExecMethod(
if (lFlags) FIXME("flags %08x not supported\n", lFlags); if (lFlags) FIXME("flags %08x not supported\n", lFlags);
if ((hr = get_object( strObjectPath, &obj ))) return hr; if ((hr = parse_path( strObjectPath, &path )) != S_OK) return hr;
if ((hr = parse_path( strObjectPath, &path )) != S_OK) if (!(str = query_from_path( path )))
{ {
IWbemClassObject_Release( obj ); hr = E_OUTOFMEMORY;
return hr; goto done;
}
table = grab_table( path->class );
free_path( path );
if (!table)
{
IWbemClassObject_Release( obj );
return WBEM_E_NOT_FOUND;
} }
hr = get_method( table, strMethodName, &func ); if (!(query = create_query()))
release_table( table );
if (hr != S_OK)
{ {
IWbemClassObject_Release( obj ); hr = E_OUTOFMEMORY;
return hr; goto done;
} }
hr = parse_query( str, &query->view, &query->mem );
if (hr != S_OK) goto done;
hr = execute_view( query->view );
if (hr != S_OK) goto done;
hr = EnumWbemClassObject_create( NULL, query, (void **)&result );
if (hr != S_OK) goto done;
hr = create_class_object( query->view->table->name, result, 0, NULL, &obj );
if (hr != S_OK) goto done;
hr = get_method( query->view->table, strMethodName, &func );
if (hr != S_OK) goto done;
hr = func( obj, pInParams, ppOutParams ); hr = func( obj, pInParams, ppOutParams );
IWbemClassObject_Release( obj );
done:
if (result) IEnumWbemClassObject_Release( result );
if (obj) IWbemClassObject_Release( obj );
free_query( query );
free_path( path );
heap_free( str );
return hr; return hr;
} }
......
...@@ -163,6 +163,8 @@ struct query ...@@ -163,6 +163,8 @@ struct query
struct list mem; struct list mem;
}; };
struct query *create_query(void) DECLSPEC_HIDDEN;
void free_query( struct query * ) DECLSPEC_HIDDEN;
struct query *addref_query( struct query * ) DECLSPEC_HIDDEN; struct query *addref_query( struct query * ) DECLSPEC_HIDDEN;
void release_query( struct query *query ) DECLSPEC_HIDDEN; void release_query( struct query *query ) DECLSPEC_HIDDEN;
HRESULT exec_query( const WCHAR *, IEnumWbemClassObject ** ) DECLSPEC_HIDDEN; HRESULT exec_query( const WCHAR *, IEnumWbemClassObject ** ) DECLSPEC_HIDDEN;
...@@ -170,6 +172,7 @@ HRESULT parse_query( const WCHAR *, struct view **, struct list * ) DECLSPEC_HID ...@@ -170,6 +172,7 @@ HRESULT parse_query( const WCHAR *, struct view **, struct list * ) DECLSPEC_HID
HRESULT create_view( const struct property *, const WCHAR *, const struct expr *, HRESULT create_view( const struct property *, const WCHAR *, const struct expr *,
struct view ** ) DECLSPEC_HIDDEN; struct view ** ) DECLSPEC_HIDDEN;
void destroy_view( struct view * ) DECLSPEC_HIDDEN; void destroy_view( struct view * ) DECLSPEC_HIDDEN;
HRESULT execute_view( struct view * ) DECLSPEC_HIDDEN;
void init_table_list( void ) DECLSPEC_HIDDEN; void init_table_list( void ) DECLSPEC_HIDDEN;
struct table *grab_table( const WCHAR * ) DECLSPEC_HIDDEN; struct table *grab_table( const WCHAR * ) DECLSPEC_HIDDEN;
struct table *addref_table( struct table * ) DECLSPEC_HIDDEN; struct table *addref_table( struct table * ) DECLSPEC_HIDDEN;
......
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