X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=src%2Fcore%2Fstore_lookup.c;h=513b6a64a7a824c5263eec708945c14a3812cfe6;hb=99d12b86d046b983801fd9381d5b9cea0200a64c;hp=3a99f80a2ac0d89e21eddce60ad722734dd2baa1;hpb=914a0b5636a32a97c50f73e14ac7be16b2686860;p=sysdb.git diff --git a/src/core/store_lookup.c b/src/core/store_lookup.c index 3a99f80..513b6a6 100644 --- a/src/core/store_lookup.c +++ b/src/core/store_lookup.c @@ -109,32 +109,24 @@ match_unary(sdb_store_matcher_t *m, sdb_store_obj_t *obj, } /* match_unary */ static int -match_child(sdb_store_matcher_t *m, sdb_store_obj_t *obj, +match_iter(sdb_store_matcher_t *m, sdb_store_obj_t *obj, sdb_store_matcher_t *filter) { sdb_avltree_iter_t *iter = NULL; int status; - int all = 0; + int all = (int)(m->type == MATCHER_ALL); - assert((m->type == MATCHER_SERVICE) - || (m->type == MATCHER_METRIC) - || (m->type == MATCHER_ATTRIBUTE)); + assert((m->type == MATCHER_ANY) || (m->type == MATCHER_ALL)); /* TODO: support all object types */ if (obj->type != SDB_HOST) return 0; - /* negated matchers should only match if the respective positive matchers - * do not match; that is if the negated matcher matchers *all* children */ - if ((CHILD_M(m)->m->type == MATCHER_NE) - || (CHILD_M(m)->m->type == MATCHER_NREGEX)) - all = 1; - - if (m->type == MATCHER_SERVICE) + if (ITER_M(m)->type == SDB_SERVICE) iter = sdb_avltree_get_iter(HOST(obj)->services); - else if (m->type == MATCHER_METRIC) + else if (ITER_M(m)->type == SDB_METRIC) iter = sdb_avltree_get_iter(HOST(obj)->metrics); - else if (m->type == MATCHER_ATTRIBUTE) + else if (ITER_M(m)->type == SDB_ATTRIBUTE) iter = sdb_avltree_get_iter(HOST(obj)->attributes); status = all; @@ -143,7 +135,7 @@ match_child(sdb_store_matcher_t *m, sdb_store_obj_t *obj, if (filter && (! sdb_store_matcher_matches(filter, child, NULL))) continue; - if (sdb_store_matcher_matches(CHILD_M(m)->m, child, filter)) { + if (sdb_store_matcher_matches(ITER_M(m)->m, child, filter)) { if (! all) { status = 1; break; @@ -155,7 +147,7 @@ match_child(sdb_store_matcher_t *m, sdb_store_obj_t *obj, } sdb_avltree_iter_destroy(iter); return status; -} /* match_child */ +} /* match_iter */ /* * cmp_expr: @@ -184,6 +176,8 @@ cmp_expr(sdb_store_expr_t *e1, sdb_store_expr_t *e2, status = INT_MAX; else if (v1.type == v2.type) status = sdb_data_cmp(&v1, &v2); + else if ((e1->data_type >= 0) && (e2->data_type >= 0)) + status = INT_MAX; else status = sdb_data_strcmp(&v1, &v2); @@ -366,9 +360,8 @@ matchers[] = { match_logical, match_logical, match_unary, - match_child, - match_child, - match_child, + match_iter, + match_iter, match_lt, match_le, match_eq, @@ -413,23 +406,24 @@ op_matcher_destroy(sdb_object_t *obj) } /* op_matcher_destroy */ static int -child_matcher_init(sdb_object_t *obj, va_list ap) +iter_matcher_init(sdb_object_t *obj, va_list ap) { M(obj)->type = va_arg(ap, int); - CHILD_M(obj)->m = va_arg(ap, sdb_store_matcher_t *); + ITER_M(obj)->type = va_arg(ap, int); + ITER_M(obj)->m = va_arg(ap, sdb_store_matcher_t *); - if (! CHILD_M(obj)->m) + if (! ITER_M(obj)->m) return -1; - sdb_object_ref(SDB_OBJ(CHILD_M(obj)->m)); + sdb_object_ref(SDB_OBJ(ITER_M(obj)->m)); return 0; -} /* child_matcher_init */ +} /* iter_matcher_init */ static void -child_matcher_destroy(sdb_object_t *obj) +iter_matcher_destroy(sdb_object_t *obj) { - sdb_object_deref(SDB_OBJ(CHILD_M(obj)->m)); -} /* child_matcher_destroy */ + sdb_object_deref(SDB_OBJ(ITER_M(obj)->m)); +} /* iter_matcher_destroy */ static int cmp_matcher_init(sdb_object_t *obj, va_list ap) @@ -506,10 +500,10 @@ static sdb_type_t uop_type = { /* destroy = */ uop_matcher_destroy, }; -static sdb_type_t child_type = { - /* size = */ sizeof(child_matcher_t), - /* init = */ child_matcher_init, - /* destroy = */ child_matcher_destroy, +static sdb_type_t iter_type = { + /* size = */ sizeof(iter_matcher_t), + /* init = */ iter_matcher_init, + /* destroy = */ iter_matcher_destroy, }; static sdb_type_t cmp_type = { @@ -529,18 +523,24 @@ static sdb_type_t isnull_type = { */ sdb_store_matcher_t * -sdb_store_child_matcher(int type, sdb_store_matcher_t *m) -{ - if (type == SDB_SERVICE) - type = MATCHER_SERVICE; - else if (type == SDB_METRIC) - type = MATCHER_METRIC; - else if (type == SDB_ATTRIBUTE) - type = MATCHER_ATTRIBUTE; - else +sdb_store_any_matcher(int type, sdb_store_matcher_t *m) +{ + if ((type != SDB_SERVICE) && (type != SDB_METRIC) + && (type != SDB_ATTRIBUTE)) + return NULL; + return M(sdb_object_create("any-matcher", iter_type, + MATCHER_ANY, type, m)); +} /* sdb_store_any_matcher */ + +sdb_store_matcher_t * +sdb_store_all_matcher(int type, sdb_store_matcher_t *m) +{ + if ((type != SDB_SERVICE) && (type != SDB_METRIC) + && (type != SDB_ATTRIBUTE)) return NULL; - return M(sdb_object_create("any-matcher", child_type, type, m)); -} /* sdb_store_child_matcher */ + return M(sdb_object_create("all-matcher", iter_type, + MATCHER_ALL, type, m)); +} /* sdb_store_all_matcher */ sdb_store_matcher_t * sdb_store_lt_matcher(sdb_store_expr_t *left, sdb_store_expr_t *right)