From: Vibhav Pant vibhavp@gmail.com
--- dlls/cfgmgr32/main.c | 97 +++++++++++++++---- dlls/cfgmgr32/tests/cfgmgr32.c | 8 +- .../tests/devices.c | 4 +- 3 files changed, 84 insertions(+), 25 deletions(-)
diff --git a/dlls/cfgmgr32/main.c b/dlls/cfgmgr32/main.c index 69004ea4b5c..5f2eabfc84f 100644 --- a/dlls/cfgmgr32/main.c +++ b/dlls/cfgmgr32/main.c @@ -17,6 +17,8 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA */
+ #include <assert.h> + #include "wine/debug.h" #include "wine/rbtree.h" #include "winreg.h" @@ -414,6 +416,9 @@ static HRESULT devprop_filter_eval_compare( const DEV_OBJECT *obj, const DEVPROP cmp = op & DEVPROP_OPERATOR_MODIFIER_IGNORE_CASE ? wcsicmp( prop->Buffer, cmp_prop->Buffer ) : wcscmp( prop->Buffer, cmp_prop->Buffer ); break; + case DEVPROP_TYPE_GUID: + /* Any other comparison operator other than DEVPROP_OPERATOR_EQUALS with GUIDs evaluates to false. */ + if (!(op & DEVPROP_OPERATOR_EQUALS)) break; default: cmp = memcmp( prop->Buffer, cmp_prop->Buffer, prop->BufferSize ); break; @@ -440,47 +445,101 @@ static HRESULT devprop_filter_eval_compare( const DEV_OBJECT *obj, const DEVPROP return ret ? S_OK : S_FALSE; }
-/* Return S_OK if the specified filter expressions match the object, S_FALSE if it doesn't. */ +/* Return S_OK if the specified filter expressions match the object, S_FALSE if it doesn't. + * op_outer_logical is the logical operator denoting the outer expression this sub-expression is inside. + * op_outer_logical can be DEVPROP_OPERATOR_NONE (in which case filters_len is used), or one of the logical _CLOSE + * operators (and filters_len gets ignored, and evaluation is stopped at the corresponding CLOSE operator). + * When op_outer_logical is not DEVPROP_OPERATOR_NONE, last_expr_idx gets set to the index where this sub-expression ends. */ static HRESULT devprop_filter_matches_object( const DEV_OBJECT *obj, ULONG filters_len, - const DEVPROP_FILTER_EXPRESSION *filters ) + const DEVPROP_OPERATOR op_outer_logical, + const DEVPROP_FILTER_EXPRESSION *filters, ULONG *last_expr_idx ) { + const DEVPROP_OPERATOR op_outer_close = op_outer_logical + (DEVPROP_OPERATOR_AND_CLOSE - DEVPROP_OPERATOR_AND_OPEN); HRESULT hr = S_OK; ULONG i;
- TRACE( "(%s, %lu, %p)\n", debugstr_DEV_OBJECT( obj ), filters_len, filters ); + TRACE( "(%s, %lu, %s, %p)\n", debugstr_DEV_OBJECT( obj ), filters_len, + debugstr_DEVPROP_OPERATOR( op_outer_logical ), filters );
- if (!filters_len) + if (op_outer_logical) + assert( op_outer_logical == DEVPROP_OPERATOR_AND_OPEN || op_outer_logical == DEVPROP_OPERATOR_OR_OPEN || + op_outer_logical == DEVPROP_OPERATOR_NOT_OPEN ); + else if (!filters_len) return S_OK;
- /* By default, the evaluation is performed by AND-ing all individual filter expressions. */ - for (i = 0; i < filters_len; i++) + for (i = 0; op_outer_logical ? filters[i].Operator != op_outer_close : i < filters_len; i++) { const DEVPROP_FILTER_EXPRESSION *filter = &filters[i]; - DEVPROP_OPERATOR op = filter->Operator; + DEVPROP_OPERATOR op = filter->Operator, logical;
- if (op == DEVPROP_OPERATOR_NONE) - { - hr = S_FALSE; - break; - } if (op & (DEVPROP_OPERATOR_MASK_LIST | DEVPROP_OPERATOR_MASK_ARRAY)) { FIXME( "Unsupported list/array operator: %s\n", debugstr_DEVPROP_OPERATOR( op ) ); continue; } - if (op & DEVPROP_OPERATOR_MASK_LOGICAL) + + logical = op & DEVPROP_OPERATOR_MASK_LOGICAL; + switch (logical) { - FIXME( "Unsupported logical operator: %s\n", debugstr_DEVPROP_OPERATOR( op ) ); - continue; + case DEVPROP_OPERATOR_NONE: + if (op == DEVPROP_OPERATOR_NONE) + hr = S_FALSE; + else if ((op & DEVPROP_OPERATOR_MASK_EVAL) && FAILED(hr = devprop_filter_eval_compare( obj, filter ))) + goto done; + break; + case DEVPROP_OPERATOR_AND_OPEN: + case DEVPROP_OPERATOR_OR_OPEN: + case DEVPROP_OPERATOR_NOT_OPEN: + { + DEVPROP_OPERATOR op_close = logical + (DEVPROP_OPERATOR_AND_CLOSE - DEVPROP_OPERATOR_AND_OPEN); + ULONG last_idx; + + /* Filter expression is validated, so we know there is atleast 1 non-logical expression + DEVPROP_OPERATOR_CLOSE_* after i. */ + hr = devprop_filter_matches_object( obj, 0, logical, &filters[i + 1], &last_idx ); + i += last_idx + 1; + if (FAILED( hr )) goto done; + assert( filters[i].Operator == op_close ); + break; + } + DEFAULT_UNREACHABLE; } - if (op & DEVPROP_OPERATOR_MASK_EVAL) + + /* See if we can short-circuit. */ + switch (op_outer_logical) { - hr = devprop_filter_eval_compare( obj, filter ); - if (FAILED( hr ) || hr == S_FALSE) + /* {NOT_OPEN, ..., NOT_CLOSE} is the same as {NOT_OPEN, AND_OPEN, ..., AND_CLOSE, NOT_CLOSE}, so we can + * short circuit here as well. */ + case DEVPROP_OPERATOR_NOT_OPEN: + case DEVPROP_OPERATOR_AND_OPEN: + if (hr == S_FALSE) + { + /* Skip to the end of this sub-expression. */ + while (filters[++i].Operator != op_outer_close) /* nothing */; + goto done; + } + break; + case DEVPROP_OPERATOR_NONE: + /* Same as AND. */ + if (hr == S_FALSE) goto done; + break; + case DEVPROP_OPERATOR_OR_OPEN: + if (hr == S_OK) + { + while (filters[++i].Operator != DEVPROP_OPERATOR_OR_CLOSE) /* nothing */; + goto done; + } break; + DEFAULT_UNREACHABLE; } }
+done: + if (SUCCEEDED( hr ) && op_outer_logical) + { + if (last_expr_idx) *last_expr_idx = i; + if (op_outer_logical == DEVPROP_OPERATOR_NOT_OPEN) + hr = (hr == S_OK) ? S_FALSE : S_OK; + } return hr; }
@@ -859,7 +918,7 @@ static HRESULT enum_dev_objects( DEV_OBJECT_TYPE type, ULONG props_len, const DE { if (filters_len) { - hr = devprop_filter_matches_object( &obj, filters_len, filters ); + hr = devprop_filter_matches_object( &obj, filters_len, DEVPROP_OPERATOR_NONE, filters, NULL ); /* Shrink pProperties to only the desired ones, unless DevQueryFlagAllProperties is set. */ if (!all_props) dev_object_remove_unwanted_props( &obj, props_len, props ); diff --git a/dlls/cfgmgr32/tests/cfgmgr32.c b/dlls/cfgmgr32/tests/cfgmgr32.c index 6b501cf4ea3..c902fecc006 100644 --- a/dlls/cfgmgr32/tests/cfgmgr32.c +++ b/dlls/cfgmgr32/tests/cfgmgr32.c @@ -1258,13 +1258,13 @@ static void test_DevGetObjects( void ) ok( hr == S_OK, "got hr %#lx\n", hr ); if (logical_op_test_cases[i].empty) { - todo_wine_if( len2 ) ok( !len2, "got len2 %lu\n", len2 ); - todo_wine_if( len2 ) ok( !objects, "got objects %p\n", objects ); + ok( !len2, "got len2 %lu\n", len2 ); + ok( !objects, "got objects %p\n", objects ); } else { - todo_wine_if( !len2 ) ok( len2 == len, "got len2 %lu != %lu\n", len2, len ); - todo_wine_if( !len2 ) ok( !!objects, "got objects %p\n", objects ); + ok( len2 == len, "got len2 %lu != %lu\n", len2, len ); + ok( !!objects, "got objects %p\n", objects ); } pDevFreeObjects( len2, objects );
diff --git a/dlls/windows.devices.enumeration/tests/devices.c b/dlls/windows.devices.enumeration/tests/devices.c index 433f9c33f2b..5c7e1fdc0f2 100644 --- a/dlls/windows.devices.enumeration/tests/devices.c +++ b/dlls/windows.devices.enumeration/tests/devices.c @@ -818,7 +818,7 @@ static void test_aqs_filters( void ) test_FindAllAsyncAqsFilter( statics, filters_empty, FALSE, FALSE ); test_CreateWatcherAqsFilter( statics, filters_empty, FALSE, FALSE, FALSE, FALSE );
- test_FindAllAsyncAqsFilter( statics, filters_boolean_op, FALSE, TRUE ); + test_FindAllAsyncAqsFilter( statics, filters_boolean_op, FALSE, FALSE ); test_CreateWatcherAqsFilter( statics, filters_boolean_op, FALSE, FALSE, FALSE, TRUE );
test_FindAllAsyncAqsFilter( statics, filters_simple, FALSE, FALSE ); @@ -827,7 +827,7 @@ static void test_aqs_filters( void ) test_FindAllAsyncAqsFilter( statics, filters_case_insensitive, TRUE, FALSE ); test_CreateWatcherAqsFilter( statics, filters_case_insensitive, TRUE, FALSE, FALSE, FALSE );
- test_FindAllAsyncAqsFilter( statics, filters_precedence, FALSE, TRUE ); + test_FindAllAsyncAqsFilter( statics, filters_precedence, FALSE, FALSE ); test_CreateWatcherAqsFilter( statics, filters_precedence, FALSE, FALSE, FALSE, TRUE );
test_FindAllAsyncAqsFilter( statics, filters_no_results, FALSE, FALSE );