Merge pull request #10779 from barbudor/pr_stringops

add and fix new string ops in rules
This commit is contained in:
Theo Arends 2021-01-31 15:08:33 +01:00 committed by GitHub
commit 9b91208bb7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 18 additions and 4 deletions

View File

@ -99,8 +99,10 @@
#define COMPARE_OPERATOR_STRING_ENDS_WITH 8
#define COMPARE_OPERATOR_STRING_STARTS_WITH 9
#define COMPARE_OPERATOR_STRING_CONTAINS 10
#define MAXIMUM_COMPARE_OPERATOR COMPARE_OPERATOR_STRING_CONTAINS
const char kCompareOperators[] PROGMEM = "=\0>\0<\0|\0==!=>=<=$>$<$|";
#define COMPARE_OPERATOR_STRING_NOT_EQUAL 11
#define COMPARE_OPERATOR_STRING_NOT_CONTAINS 12
#define MAXIMUM_COMPARE_OPERATOR COMPARE_OPERATOR_STRING_NOT_CONTAINS
const char kCompareOperators[] PROGMEM = "=\0>\0<\0|\0==!=>=<=$>$<$|$!$^";
#ifdef USE_EXPRESSION
#include <LinkedList.h> // Import LinkedList library
@ -589,7 +591,13 @@ bool RulesRuleMatch(uint8_t rule_set, String &event, String &rule, bool stop_all
match = str_str_value.startsWith(rule_svalue);
break;
case COMPARE_OPERATOR_STRING_CONTAINS:
match = (str_str_value.indexOf(rule_svalue) > 0);
match = (str_str_value.indexOf(rule_svalue) >= 0);
break;
case COMPARE_OPERATOR_STRING_NOT_EQUAL:
match = (0!=strcasecmp(str_value, rule_svalue)); // Compare strings - this also works for hexadecimals
break;
case COMPARE_OPERATOR_STRING_NOT_CONTAINS:
match = (str_str_value.indexOf(rule_svalue) < 0);
break;
default:
match = true;
@ -1634,7 +1642,13 @@ bool evaluateComparisonExpression(const char *expression, int len)
bResult = leftExpr.startsWith(rightExpr);
break;
case COMPARE_OPERATOR_STRING_CONTAINS:
bResult = (leftExpr.indexOf(rightExpr) > 0);
bResult = (leftExpr.indexOf(rightExpr) >= 0);
break;
case COMPARE_OPERATOR_STRING_NOT_EQUAL:
bResult = !leftExpr.equalsIgnoreCase(rightExpr); // Compare strings - this also works for hexadecimals
break;
case COMPARE_OPERATOR_STRING_NOT_CONTAINS:
bResult = (leftExpr.indexOf(rightExpr) < 0);
break;
}
return bResult;