From c08ea56c7b454a176ae50efff335f5799b08fc32 Mon Sep 17 00:00:00 2001 From: Peter Rajnoha Date: Wed, 30 Apr 2014 12:29:48 +0200 Subject: selout: make regex selection to work without quotes and recognize regex op before equal op --- libdm/libdm-report.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/libdm/libdm-report.c b/libdm/libdm-report.c index 47f4d4fba..aceb31059 100644 --- a/libdm/libdm-report.c +++ b/libdm/libdm-report.c @@ -87,15 +87,20 @@ struct op_def { #define FLD_CMP_LT 0x00008000 #define FLD_CMP_REGEX 0x00010000 +/* + * When defining operators, always define longer one before + * shorter one if one is a prefix of another! + * (e.g. =~ comes before =) + */ static struct op_def _op_cmp[] = { + { "=~", FLD_CMP_REGEX, "Matching regular expression" }, + { "!~", FLD_CMP_REGEX|FLD_CMP_NOT, "Not matching regular expression" }, { "=", FLD_CMP_EQUAL, "Equal to" }, { "!=", FLD_CMP_NOT|FLD_CMP_EQUAL, "Not equal" }, { ">=", FLD_CMP_GT|FLD_CMP_EQUAL, "Greater than or equal to" }, { ">", FLD_CMP_GT, "Greater than" }, { "<=", FLD_CMP_LT|FLD_CMP_EQUAL, "Lesser than or equal to" }, { "<", FLD_CMP_LT, "Lesser than" }, - { "=~", FLD_CMP_REGEX, "Matching regular expression" }, - { "!~", FLD_CMP_REGEX|FLD_CMP_NOT, "Not matching regular expression" }, { NULL, 0, NULL } }; @@ -1145,15 +1150,18 @@ static const char *_tok_regex(const struct dm_report_field_type *ft, case '(': c = ')'; break; case '{': c = '}'; break; case '[': c = ']'; break; - default: c = *s; + default: c = 0; } s = _tok_string(s + 1, begin, end, c); - if (!*s) { - log_error("Missing end quote of regex for field %s", ft->id); - return NULL; + if ((c = *s)) { + if (c && (c != ')') && (c != '}') && (c != ']')) + { + log_error("Missing end quote of regex for field %s", ft->id); + return NULL; + } + s++; } - s++; *flags |= DM_REPORT_FIELD_TYPE_STRING; -- cgit v1.2.1