index 3a99f80a2ac0d89e21eddce60ad722734dd2baa1..513b6a64a7a824c5263eec708945c14a3812cfe6 100644 (file)
--- a/src/core/store_lookup.c
+++ b/src/core/store_lookup.c
} /* 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;
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;
}
sdb_avltree_iter_destroy(iter);
return status;
-} /* match_child */
+} /* match_iter */
/*
* cmp_expr:
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);
match_logical,
match_logical,
match_unary,
- match_child,
- match_child,
- match_child,
+ match_iter,
+ match_iter,
match_lt,
match_le,
match_eq,
} /* 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)
/* 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 = {
*/
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)