From: Sebastian Harl Date: Wed, 15 Oct 2014 13:57:24 +0000 (+0200) Subject: store: Added not-equal and not-regex matchers. X-Git-Tag: sysdb-0.6.0~115 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=26e53bce7d3f75e7dabed7238ca946e2c230ae3c;p=sysdb.git store: Added not-equal and not-regex matchers. --- diff --git a/src/core/store-private.h b/src/core/store-private.h index 1633d42..a64c220 100644 --- a/src/core/store-private.h +++ b/src/core/store-private.h @@ -175,9 +175,11 @@ enum { MATCHER_CMP_LT, MATCHER_CMP_LE, MATCHER_CMP_EQ, + MATCHER_CMP_NE, MATCHER_CMP_GE, MATCHER_CMP_GT, MATCHER_REGEX, + MATCHER_NREGEX, MATCHER_ISNULL, }; @@ -193,9 +195,11 @@ enum { : ((t) == MATCHER_LT) ? "<" \ : ((t) == MATCHER_LE) ? "<=" \ : ((t) == MATCHER_EQ) ? "=" \ + : ((t) == MATCHER_CMP_NE) ? "!=" \ : ((t) == MATCHER_GE) ? ">=" \ : ((t) == MATCHER_GT) ? ">" \ : ((t) == MATCHER_REGEX) ? "=~" \ + : ((t) == MATCHER_NREGEX) ? "!~" \ : ((t) == MATCHER_ISNULL) ? "IS NULL" \ : "UNKNOWN") diff --git a/src/core/store_lookup.c b/src/core/store_lookup.c index a86743e..cb3629c 100644 --- a/src/core/store_lookup.c +++ b/src/core/store_lookup.c @@ -435,6 +435,16 @@ match_cmp_eq(sdb_store_matcher_t *m, sdb_store_obj_t *obj, return (status != INT_MAX) && (! status); } /* match_cmp_eq */ +static int +match_cmp_ne(sdb_store_matcher_t *m, sdb_store_obj_t *obj, + sdb_store_matcher_t *filter) +{ + int status; + assert(m->type == MATCHER_CMP_NE); + status = cmp_expr(CMP_M(m)->left, CMP_M(m)->right, obj, filter); + return (status != INT_MAX) && status; +} /* match_cmp_ne */ + static int match_cmp_ge(sdb_store_matcher_t *m, sdb_store_obj_t *obj, sdb_store_matcher_t *filter) @@ -465,7 +475,8 @@ match_regex(sdb_store_matcher_t *m, sdb_store_obj_t *obj, regex_t regex; _Bool free_regex = 0; - assert(m->type == MATCHER_REGEX); + assert((m->type == MATCHER_REGEX) + || (m->type == MATCHER_NREGEX)); if (! CMP_M(m)->right->type) { assert(CMP_M(m)->right->data.type == SDB_TYPE_REGEX); @@ -508,6 +519,8 @@ match_regex(sdb_store_matcher_t *m, sdb_store_obj_t *obj, if (free_regex) regfree(®ex); sdb_data_free_datum(&v); + if (m->type == MATCHER_NREGEX) + return !status; return status; } /* match_regex */ @@ -544,9 +557,11 @@ matchers[] = { match_cmp_lt, match_cmp_le, match_cmp_eq, + match_cmp_ne, match_cmp_ge, match_cmp_gt, match_regex, + match_regex, match_isnull, }; @@ -1038,6 +1053,8 @@ matchers_tostring[] = { cmp_tostring, cmp_tostring, cmp_tostring, + cmp_tostring, + cmp_tostring, isnull_tostring, }; @@ -1168,6 +1185,13 @@ sdb_store_cmp_eq(sdb_store_expr_t *left, sdb_store_expr_t *right) MATCHER_CMP_EQ, left, right)); } /* sdb_store_cmp_eq */ +sdb_store_matcher_t * +sdb_store_cmp_ne(sdb_store_expr_t *left, sdb_store_expr_t *right) +{ + return M(sdb_object_create("ne-matcher", cmp_type, + MATCHER_CMP_NE, left, right)); +} /* sdb_store_cmp_ne */ + sdb_store_matcher_t * sdb_store_cmp_ge(sdb_store_expr_t *left, sdb_store_expr_t *right) { @@ -1201,6 +1225,16 @@ sdb_store_regex_matcher(sdb_store_expr_t *left, sdb_store_expr_t *right) MATCHER_REGEX, left, right)); } /* sdb_store_regex_matcher */ +sdb_store_matcher_t * +sdb_store_nregex_matcher(sdb_store_expr_t *left, sdb_store_expr_t *right) +{ + sdb_store_matcher_t *m = sdb_store_regex_matcher(left, right); + if (! m) + return NULL; + m->type = MATCHER_NREGEX; + return m; +} /* sdb_store_nregex_matcher */ + sdb_store_matcher_t * sdb_store_isnull_matcher(const char *attr_name) { diff --git a/src/include/core/store.h b/src/include/core/store.h index 1729f0c..5e57185 100644 --- a/src/include/core/store.h +++ b/src/include/core/store.h @@ -445,6 +445,8 @@ sdb_store_cmp_le(sdb_store_expr_t *left, sdb_store_expr_t *right); sdb_store_matcher_t * sdb_store_cmp_eq(sdb_store_expr_t *left, sdb_store_expr_t *right); sdb_store_matcher_t * +sdb_store_cmp_ne(sdb_store_expr_t *left, sdb_store_expr_t *right); +sdb_store_matcher_t * sdb_store_cmp_ge(sdb_store_expr_t *left, sdb_store_expr_t *right); sdb_store_matcher_t * sdb_store_cmp_gt(sdb_store_expr_t *left, sdb_store_expr_t *right); @@ -460,6 +462,14 @@ sdb_store_cmp_gt(sdb_store_expr_t *left, sdb_store_expr_t *right); sdb_store_matcher_t * sdb_store_regex_matcher(sdb_store_expr_t *left, sdb_store_expr_t *right); +/* + * sdb_store_nregex_matcher: + * Creates a regex matcher just like sdb_store_regex_matcher except that it + * matches in case the regular expression does not match. + */ +sdb_store_matcher_t * +sdb_store_nregex_matcher(sdb_store_expr_t *left, sdb_store_expr_t *right); + /* * sdb_store_parse_object_type_plural: * Parse the type name (plural) of a stored object.