summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 6b13103)
raw | patch | inline | side by side (parent: 6b13103)
author | Sebastian Harl <sh@tokkee.org> | |
Sat, 25 Oct 2014 11:58:58 +0000 (13:58 +0200) | ||
committer | Sebastian Harl <sh@tokkee.org> | |
Sat, 25 Oct 2014 11:58:58 +0000 (13:58 +0200) |
It matches if any object of an iterable list matches, so this is a more
appropriate name.
appropriate name.
index 1e2c3ec5b4ef398be8a10f9420b26f53adac93b3..4c38f1570bca1d449a4478fa33119e410cf33136 100644 (file)
--- a/src/core/store-private.h
+++ b/src/core/store-private.h
MATCHER_OR,
MATCHER_AND,
MATCHER_NOT,
- MATCHER_SERVICE,
- MATCHER_METRIC,
- MATCHER_ATTRIBUTE,
+ MATCHER_ANY,
MATCHER_LT,
MATCHER_LE,
MATCHER_EQ,
: ((t) == MATCHER_AND) ? "AND" \
: ((t) == MATCHER_NOT) ? "NOT" \
: ((t) == MATCHER_NAME) ? "NAME" \
- : ((t) == MATCHER_SERVICE) ? "SERVICE" \
- : ((t) == MATCHER_METRIC) ? "METRIC" \
- : ((t) == MATCHER_ATTRIBUTE) ? "ATTRIBUTE" \
+ : ((t) == MATCHER_ANY) ? "ANY" \
: ((t) == MATCHER_LT) ? "<" \
: ((t) == MATCHER_LE) ? "<=" \
: ((t) == MATCHER_EQ) ? "=" \
} uop_matcher_t;
#define UOP_M(m) ((uop_matcher_t *)(m))
-/* child matcher */
+/* iter matcher */
typedef struct {
sdb_store_matcher_t super;
+ int type;
sdb_store_matcher_t *m;
-} child_matcher_t;
-#define CHILD_M(m) ((child_matcher_t *)(m))
+} iter_matcher_t;
+#define ITER_M(m) ((iter_matcher_t *)(m))
/* compare operator matcher */
typedef struct {
index 93fb347852ea969de3ff6bb199454d8560fac511..f95f8ca0bc6a0a4fec8cb724e56304290ab57c78 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;
- assert((m->type == MATCHER_SERVICE)
- || (m->type == MATCHER_METRIC)
- || (m->type == MATCHER_ATTRIBUTE));
+ assert(m->type == MATCHER_ANY);
/* TODO: support all object types */
if (obj->type != SDB_HOST)
/* 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))
+ if ((ITER_M(m)->m->type == MATCHER_NE)
+ || (ITER_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:
match_logical,
match_logical,
match_unary,
- match_child,
- match_child,
- match_child,
+ 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", child_type, type, m));
-} /* sdb_store_child_matcher */
+ return M(sdb_object_create("any-matcher", iter_type,
+ MATCHER_ANY, type, m));
+} /* sdb_store_iter_matcher */
sdb_store_matcher_t *
sdb_store_lt_matcher(sdb_store_expr_t *left, sdb_store_expr_t *right)
diff --git a/src/frontend/grammar.y b/src/frontend/grammar.y
index 3c813dcddb05d6ff54ac4a1d93fde958f4afab08..cfffdac5f35d6fac421a082e8d58c55c9dfc3091 100644 (file)
--- a/src/frontend/grammar.y
+++ b/src/frontend/grammar.y
$$ = m;
}
else {
- $$ = sdb_store_child_matcher(type, m);
+ $$ = sdb_store_any_matcher(type, m);
sdb_object_deref(SDB_OBJ(m));
}
index 97bb6e65cd56be1afff6a6da035a6ab0ae18803b..ed445c3a0533b53e40b3858e82ea0e4516188947 100644 (file)
--- a/src/include/core/store.h
+++ b/src/include/core/store.h
sdb_store_isnnull_matcher(sdb_store_expr_t *expr);
/*
- * sdb_store_child_matcher:
- * Creates a matcher matching an object's children of the specified type. It
- * matches if *any* of those children match 'm'.
+ * sdb_store_any_matcher:
+ * Creates a matcher iterating over objects of the specified type. It matches
+ * if *any* of those objects match 'm'.
*/
sdb_store_matcher_t *
-sdb_store_child_matcher(int type, sdb_store_matcher_t *m);
+sdb_store_any_matcher(int type, sdb_store_matcher_t *m);
/*
* sdb_store_lt_matcher, sdb_store_le_matcher, sdb_store_eq_matcher,
index 65cbc62d04ed53a4858ab577007800970e50071c..dbf313acaa6709119b84d2d6636b61b5b57b233c 100644 (file)
m = sdb_store_eq_matcher(obj, value);
if (golden_data[i].type != SDB_HOST) {
sdb_store_matcher_t *tmp;
- tmp = sdb_store_child_matcher(golden_data[i].type, m);
+ tmp = sdb_store_any_matcher(golden_data[i].type, m);
sdb_object_deref(SDB_OBJ(m));
m = tmp;
}
index b48ca2f1830dc607504addc46c5a725cb95a9dfd..1ca9f2ddfd37a95d2a4a1864bdb6f1699eebc91c 100644 (file)
{ "host = 'host' <garbage>", 13, MATCHER_EQ },
{ "host &^ 'localhost'", -1, -1 },
/* match hosts by service */
- { "service < 'name'", -1, MATCHER_SERVICE },
- { "service <= 'name'", -1, MATCHER_SERVICE },
- { "service = 'name'", -1, MATCHER_SERVICE },
- { "service != 'name'", -1, MATCHER_SERVICE },
- { "service >= 'name'", -1, MATCHER_SERVICE },
- { "service > 'name'", -1, MATCHER_SERVICE },
- { "service =~ 'pattern'", -1, MATCHER_SERVICE },
- { "service !~ 'pattern'", -1, MATCHER_SERVICE },
+ { "service < 'name'", -1, MATCHER_ANY },
+ { "service <= 'name'", -1, MATCHER_ANY },
+ { "service = 'name'", -1, MATCHER_ANY },
+ { "service != 'name'", -1, MATCHER_ANY },
+ { "service >= 'name'", -1, MATCHER_ANY },
+ { "service > 'name'", -1, MATCHER_ANY },
+ { "service =~ 'pattern'", -1, MATCHER_ANY },
+ { "service !~ 'pattern'", -1, MATCHER_ANY },
{ "service &^ 'name'", -1, -1 },
/* match hosts by metric */
- { "metric < 'name'", -1, MATCHER_METRIC },
- { "metric <= 'name'", -1, MATCHER_METRIC },
- { "metric = 'name'", -1, MATCHER_METRIC },
- { "metric != 'name'", -1, MATCHER_METRIC },
- { "metric >= 'name'", -1, MATCHER_METRIC },
- { "metric > 'name'", -1, MATCHER_METRIC },
- { "metric =~ 'pattern'", -1, MATCHER_METRIC },
- { "metric !~ 'pattern'", -1, MATCHER_METRIC },
+ { "metric < 'name'", -1, MATCHER_ANY },
+ { "metric <= 'name'", -1, MATCHER_ANY },
+ { "metric = 'name'", -1, MATCHER_ANY },
+ { "metric != 'name'", -1, MATCHER_ANY },
+ { "metric >= 'name'", -1, MATCHER_ANY },
+ { "metric > 'name'", -1, MATCHER_ANY },
+ { "metric =~ 'pattern'", -1, MATCHER_ANY },
+ { "metric !~ 'pattern'", -1, MATCHER_ANY },
/* match hosts by attribute */
- { "attribute < 'name'", -1, MATCHER_ATTRIBUTE },
- { "attribute <= 'name'", -1, MATCHER_ATTRIBUTE },
- { "attribute = 'name'", -1, MATCHER_ATTRIBUTE },
- { "attribute != 'name'", -1, MATCHER_ATTRIBUTE },
- { "attribute >= 'name'", -1, MATCHER_ATTRIBUTE },
- { "attribute > 'name'", -1, MATCHER_ATTRIBUTE },
- { "attribute =~ 'pattern'", -1, MATCHER_ATTRIBUTE },
- { "attribute !~ 'pattern'", -1, MATCHER_ATTRIBUTE },
+ { "attribute < 'name'", -1, MATCHER_ANY },
+ { "attribute <= 'name'", -1, MATCHER_ANY },
+ { "attribute = 'name'", -1, MATCHER_ANY },
+ { "attribute != 'name'", -1, MATCHER_ANY },
+ { "attribute >= 'name'", -1, MATCHER_ANY },
+ { "attribute > 'name'", -1, MATCHER_ANY },
+ { "attribute =~ 'pattern'", -1, MATCHER_ANY },
+ { "attribute !~ 'pattern'", -1, MATCHER_ANY },
{ "attribute &^ 'pattern'", -1, -1 },
/* composite expressions */
{ "host =~ 'pattern' AND "