| 1371 | } |
| 1372 | |
| 1373 | bool EvaluateFilterSet(ICaptureContext &ctx, const rdcarray<EventFilter> &filters, bool all, |
| 1374 | uint32_t eid, const SDChunk *chunk, const ActionDescription *action, |
| 1375 | QString name) |
| 1376 | { |
| 1377 | if(filters.empty()) |
| 1378 | return true; |
| 1379 | |
| 1380 | bool accept = false; |
| 1381 | |
| 1382 | bool anyMust = false; |
| 1383 | for(const EventFilter &filter : filters) |
| 1384 | anyMust |= (filter.type == MatchType::MustMatch); |
| 1385 | |
| 1386 | // if there are MustMatch filters we ignore normals for the sake of matching. We also default |
| 1387 | // to acceptance so that if they all pass then we match. This handles cases like +foo -bar which |
| 1388 | // would return the default on a string like "foothing" which would return a false match if we |
| 1389 | // didn't do this |
| 1390 | if(anyMust) |
| 1391 | accept = true; |
| 1392 | |
| 1393 | // if any top-level filter matches, we match |
| 1394 | for(const EventFilter &filter : filters) |
| 1395 | { |
| 1396 | // ignore normal filters when we have must matches. Only consider must/can't |
| 1397 | if(anyMust && filter.type == MatchType::Normal) |
| 1398 | continue; |
| 1399 | |
| 1400 | // if we've already accepted and this is a normal filter and we are in non-all mode, it won't |
| 1401 | // change the result so don't bother running the filter. |
| 1402 | if(accept && !all && filter.type == MatchType::Normal) |
| 1403 | continue; |
| 1404 | |
| 1405 | bool match = filter.callback(&ctx, rdcstr(), rdcstr(), eid, chunk, action, name); |
| 1406 | |
| 1407 | // in normal mode, if it matches it should be included (unless a subsequent filter excludes |
| 1408 | // it) |
| 1409 | if(filter.type == MatchType::Normal) |
| 1410 | { |
| 1411 | if(match) |
| 1412 | accept = true; |
| 1413 | |
| 1414 | // in all mode, if any normal filters fails then we fail the whole thing |
| 1415 | if(all && !match) |
| 1416 | return false; |
| 1417 | } |
| 1418 | else if(filter.type == MatchType::CantMatch) |
| 1419 | { |
| 1420 | // if we matched a can't match (e.g -foo) then we can't accept this row |
| 1421 | if(match) |
| 1422 | return false; |
| 1423 | } |
| 1424 | else if(filter.type == MatchType::MustMatch) |
| 1425 | { |
| 1426 | // similarly if we *didn't* match a must match (e.g +foo) then we can't accept this row |
| 1427 | if(!match) |
| 1428 | return false; |
| 1429 | } |
| 1430 | } |
no test coverage detected