From b1d0d9add668e008f5b59f8ae76d8167b223e056 Mon Sep 17 00:00:00 2001 From: Sebastian Harl Date: Thu, 19 Jun 2014 16:41:55 +0200 Subject: [PATCH] store_lookup: Removed the (now unused) host matcher. --- src/core/store-private.h | 9 -- src/core/store_lookup.c | 82 -------------- src/include/core/store.h | 8 -- t/unit/core/store_lookup_test.c | 189 +++++++++++++------------------- 4 files changed, 76 insertions(+), 212 deletions(-) diff --git a/src/core/store-private.h b/src/core/store-private.h index 05a9638..4228188 100644 --- a/src/core/store-private.h +++ b/src/core/store-private.h @@ -89,7 +89,6 @@ enum { MATCHER_NOT, MATCHER_NAME, MATCHER_ATTR, - MATCHER_HOST, }; /* match the name of something */ @@ -146,14 +145,6 @@ typedef struct { } attr_matcher_t; #define ATTR_M(m) ((attr_matcher_t *)(m)) -/* match hosts */ -typedef struct { - obj_matcher_t super; - /* match by attributes assigned to the host */ - attr_matcher_t *attr; -} host_matcher_t; -#define HOST_M(m) ((host_matcher_t *)(m)) - #ifdef __cplusplus } /* extern "C" */ #endif diff --git a/src/core/store_lookup.c b/src/core/store_lookup.c index f2d8cc7..f6905e9 100644 --- a/src/core/store_lookup.c +++ b/src/core/store_lookup.c @@ -173,24 +173,6 @@ attr_tostring(sdb_store_matcher_t *m, char *buf, size_t buflen) return buf; } /* attr_tostring */ -static char * -host_tostring(sdb_store_matcher_t *m, char *buf, size_t buflen) -{ - char name[buflen + 1], attr[buflen + 1]; - - if (! m) { - snprintf(buf, buflen, "HOST{}"); - return buf; - } - - assert(m->type == MATCHER_HOST); - snprintf(buf, buflen, "HOST{ NAME%s, %s }", - obj_name_tostring(&OBJ_M(m)->name, name, sizeof(name)), - attr_tostring(SDB_STORE_MATCHER(HOST_M(m)->attr), - attr, sizeof(attr))); - return buf; -} /* host_tostring */ - static int match_name(sdb_store_matcher_t *m, sdb_store_base_t *obj) { @@ -257,29 +239,6 @@ match_attr(sdb_store_matcher_t *m, sdb_store_base_t *obj) return status; } /* match_attr */ -/* match host specific values; - * always call this function through match_obj() */ -static int -match_host(sdb_store_matcher_t *m, sdb_store_base_t *obj) -{ - int status; - - assert(m && obj); - assert(m->type == MATCHER_HOST); - - if (obj->type != SDB_HOST) - return 0; - - status = match_obj_name(&OBJ_M(m)->name, obj->super.name); - if (! status) - return status; - - if (! HOST_M(m)->attr) - return 1; - - return match_attr(M(HOST_M(m)->attr), obj); -} /* match_host */ - /* generic matchers */ typedef int (*matcher_cb)(sdb_store_matcher_t *, sdb_store_base_t *); @@ -292,7 +251,6 @@ static matcher_cb matchers[] = { match_unary, match_name, match_attr, - match_host, }; typedef char *(*matcher_tostring_cb)(sdb_store_matcher_t *, char *, size_t); @@ -303,7 +261,6 @@ static matcher_tostring_cb matchers_tostring[] = { unary_tostring, name_tostring, attr_tostring, - host_tostring, }; static int @@ -411,31 +368,6 @@ attr_matcher_destroy(sdb_object_t *obj) name_matcher_destroy(&attr->value); } /* attr_matcher_destroy */ -static int -host_matcher_init(sdb_object_t *obj, va_list ap) -{ - attr_matcher_t *attr; - int status; - - status = obj_matcher_init(obj, ap); - if (status) - return status; - - attr = va_arg(ap, attr_matcher_t *); - sdb_object_ref(SDB_OBJ(attr)); - HOST_M(obj)->attr = attr; - - M(obj)->type = MATCHER_HOST; - return 0; -} /* host_matcher_init */ - -static void -host_matcher_destroy(sdb_object_t *obj) -{ - obj_matcher_destroy(obj); - sdb_object_deref(SDB_OBJ(HOST_M(obj)->attr)); -} /* host_matcher_destroy */ - static int op_matcher_init(sdb_object_t *obj, va_list ap) { @@ -496,12 +428,6 @@ static sdb_type_t attr_type = { /* destroy = */ attr_matcher_destroy, }; -static sdb_type_t host_type = { - /* size = */ sizeof(host_matcher_t), - /* init = */ host_matcher_init, - /* destroy = */ host_matcher_destroy, -}; - static sdb_type_t op_type = { /* size = */ sizeof(op_matcher_t), /* init = */ op_matcher_init, @@ -547,14 +473,6 @@ sdb_store_attr_matcher(const char *name, const char *value, _Bool re) name, value, NULL)); } /* sdb_store_attr_matcher */ -sdb_store_matcher_t * -sdb_store_host_matcher(const char *host_name, const char *host_name_re, - sdb_store_matcher_t *attr_matcher) -{ - return M(sdb_object_create("host-matcher", host_type, - host_name, host_name_re, attr_matcher)); -} /* sdb_store_host_matcher */ - sdb_store_matcher_t * sdb_store_matcher_parse_cmp(const char *obj_type, const char *attr, const char *op, const char *value) diff --git a/src/include/core/store.h b/src/include/core/store.h index e4dcd57..890482a 100644 --- a/src/include/core/store.h +++ b/src/include/core/store.h @@ -174,14 +174,6 @@ sdb_store_name_matcher(int type, const char *name, _Bool re); sdb_store_matcher_t * sdb_store_attr_matcher(const char *name, const char *value, _Bool re); -/* - * sdb_store_host_matcher: - * Creates a matcher matching hosts based on their name or its attributes. - */ -sdb_store_matcher_t * -sdb_store_host_matcher(const char *host_name, const char *host_name_re, - sdb_store_matcher_t *attr_matcher); - /* * sdb_store_matcher_parse_cmp: * Parse a simple compare expression (. ). diff --git a/t/unit/core/store_lookup_test.c b/t/unit/core/store_lookup_test.c index 4bbfcc2..918fbef 100644 --- a/t/unit/core/store_lookup_test.c +++ b/t/unit/core/store_lookup_test.c @@ -82,68 +82,46 @@ populate(void) } } /* populate */ -START_TEST(test_store_match) +START_TEST(test_store_match_name) { sdb_store_base_t *obj; struct { - const char *hostname; - const char *hostname_re; - - const char *attr_name; - const char *attr_value; + int type; + const char *name; _Bool re; int expected; } golden_data[] = { - { - /* host */ NULL, NULL, - /* attr */ NULL, NULL, 0, 1 - }, - { - /* host */ NULL, NULL, - /* attr */ NULL, NULL, 1, 1 - }, - { - /* host */ "a", NULL, - /* attr */ NULL, NULL, 0, 1 - }, - { - /* host */ "b", NULL, - /* attr */ NULL, NULL, 0, 0 - }, - { - /* host */ NULL, "^a$", - /* attr */ NULL, NULL, 0, 1 - }, - { - /* host */ NULL, "^b$", - /* attr */ NULL, NULL, 0, 0 - }, - { - /* host */ "a", "^a$", - /* attr */ NULL, NULL, 0, 1 - }, - { - /* host */ "a", "^b$", - /* attr */ NULL, NULL, 0, 0 - }, - { - /* host */ "b", "^a$", - /* attr */ NULL, NULL, 0, 0 - }, - { - /* host */ "a", "^a$", - /* attr */ "k1", NULL, 0, 1 - }, - { - /* host */ "a", "^a$", - /* attr */ NULL, "v1", 0, 1 - }, - { - /* host */ "a", "^a$", - /* attr */ NULL, "^v1$", 1, 1 - }, + { SDB_HOST, NULL, 0, 1 }, + { SDB_HOST, NULL, 1, 1 }, + { SDB_HOST, "a", 0, 1 }, + { SDB_HOST, "a", 1, 1 }, + { SDB_HOST, "b", 0, 0 }, + { SDB_HOST, "b", 1, 0 }, + { SDB_HOST, "^a$", 1, 1 }, + { SDB_HOST, "^b$", 1, 0 }, + { SDB_HOST, "^a$", 0, 0 }, + { SDB_HOST, "^b$", 0, 0 }, + { SDB_SERVICE, NULL, 0, 1 }, + { SDB_SERVICE, NULL, 1, 1 }, + { SDB_SERVICE, "s1", 0, 1 }, + { SDB_SERVICE, "s2", 0, 1 }, + { SDB_SERVICE, "s3", 0, 0 }, + { SDB_SERVICE, "s4", 0, 0 }, + { SDB_SERVICE, "^s1$", 1, 1 }, + { SDB_SERVICE, "^s1$", 0, 0 }, + { SDB_SERVICE, "x1", 0, 0 }, + { SDB_SERVICE, "x1", 1, 0 }, + { SDB_SERVICE, "x", 1, 0 }, + { SDB_ATTRIBUTE, NULL, 0, 1 }, + { SDB_ATTRIBUTE, NULL, 1, 1 }, + { SDB_ATTRIBUTE, "k1", 0, 1 }, + { SDB_ATTRIBUTE, "k2", 0, 0 }, + { SDB_ATTRIBUTE, "k3", 0, 0 }, + { SDB_ATTRIBUTE, "k", 1, 1 }, + { SDB_ATTRIBUTE, "1", 1, 1 }, + { SDB_ATTRIBUTE, "2", 1, 0 }, }; size_t i; @@ -153,37 +131,31 @@ START_TEST(test_store_match) "sdb_store_get_host(a) = NULL; expected: "); for (i = 0; i < SDB_STATIC_ARRAY_LEN(golden_data); ++i) { - sdb_store_matcher_t *h, *a, *n; + sdb_store_matcher_t *m, *n; char buf[1024]; int status; - a = sdb_store_attr_matcher(golden_data[i].attr_name, - golden_data[i].attr_value, golden_data[i].re); - fail_unless(a != NULL, - "sdb_store_attr_matcher() = NULL; expected: "); - - h = sdb_store_host_matcher(golden_data[i].hostname, - golden_data[i].hostname_re, a); - fail_unless(h != NULL, - "sdb_store_host_matcher() = NULL: expected: "); - /* pass ownership to the host matcher */ - sdb_object_deref(SDB_OBJ(a)); + m = sdb_store_name_matcher(golden_data[i].type, + golden_data[i].name, golden_data[i].re); + fail_unless(m != NULL, + "sdb_store_service_matcher(%d, %s, %d) = NULL; expected: ", + golden_data[i].type, golden_data[i].name, golden_data[i].re); - status = sdb_store_matcher_matches(h, obj); + status = sdb_store_matcher_matches(m, obj); fail_unless(status == golden_data[i].expected, - "sdb_store_matcher_matches({%s, ) = %d; expected: %d", - sdb_store_matcher_tostring(h, buf, sizeof(buf)), + "sdb_store_matcher_matches(%s, ) = %d; expected: %d", + sdb_store_matcher_tostring(m, buf, sizeof(buf)), status, golden_data[i].expected); - n = sdb_store_inv_matcher(h); + n = sdb_store_inv_matcher(m); fail_unless(n != NULL, "sdb_store_inv_matcher() = NULL; expected: "); - sdb_object_deref(SDB_OBJ(h)); + sdb_object_deref(SDB_OBJ(m)); /* now match the inverted set of objects */ status = sdb_store_matcher_matches(n, obj); fail_unless(status == !golden_data[i].expected, - "sdb_store_matcher_matches({%s, ) = %d; expected: %d", + "sdb_store_matcher_matches(%s, ) = %d; expected: %d", sdb_store_matcher_tostring(n, buf, sizeof(buf)), status, !golden_data[i].expected); @@ -194,46 +166,38 @@ START_TEST(test_store_match) } END_TEST -START_TEST(test_store_match_name) +START_TEST(test_store_match_attr) { sdb_store_base_t *obj; struct { - int type; - const char *name; + const char *attr_name; + const char *attr_value; _Bool re; int expected; } golden_data[] = { - { SDB_HOST, NULL, 0, 1 }, - { SDB_HOST, NULL, 1, 1 }, - { SDB_HOST, "a", 0, 1 }, - { SDB_HOST, "a", 1, 1 }, - { SDB_HOST, "b", 0, 0 }, - { SDB_HOST, "b", 1, 0 }, - { SDB_HOST, "^a$", 1, 1 }, - { SDB_HOST, "^b$", 1, 0 }, - { SDB_HOST, "^a$", 0, 0 }, - { SDB_HOST, "^b$", 0, 0 }, - { SDB_SERVICE, NULL, 0, 1 }, - { SDB_SERVICE, NULL, 1, 1 }, - { SDB_SERVICE, "s1", 0, 1 }, - { SDB_SERVICE, "s2", 0, 1 }, - { SDB_SERVICE, "s3", 0, 0 }, - { SDB_SERVICE, "s4", 0, 0 }, - { SDB_SERVICE, "^s1$", 1, 1 }, - { SDB_SERVICE, "^s1$", 0, 0 }, - { SDB_SERVICE, "x1", 0, 0 }, - { SDB_SERVICE, "x1", 1, 0 }, - { SDB_SERVICE, "x", 1, 0 }, - { SDB_ATTRIBUTE, NULL, 0, 1 }, - { SDB_ATTRIBUTE, NULL, 1, 1 }, - { SDB_ATTRIBUTE, "k1", 0, 1 }, - { SDB_ATTRIBUTE, "k2", 0, 0 }, - { SDB_ATTRIBUTE, "k3", 0, 0 }, - { SDB_ATTRIBUTE, "k", 1, 1 }, - { SDB_ATTRIBUTE, "1", 1, 1 }, - { SDB_ATTRIBUTE, "2", 1, 0 }, + { NULL, NULL, 0, 1 }, + { NULL, NULL, 1, 1 }, + { "k1", NULL, 0, 1 }, + { "k", NULL, 1, 0 }, + { "1", NULL, 1, 0 }, + { "k2", NULL, 0, 0 }, + { "k2", NULL, 1, 0 }, + { "k3", NULL, 0, 0 }, + { "k3", NULL, 1, 0 }, + { "k1", "v1", 0, 1 }, + { "k1", "v1", 1, 1 }, + { "k1", "v", 1, 1 }, + { "k1", "1", 1, 1 }, + { NULL, "v1", 0, 1 }, + { NULL, "^v1$", 1, 1 }, + { "k1", "v2", 0, 0 }, + { "k1", "v2", 1, 0 }, + { "k", "v1", 0, 0 }, + { "k", "v1", 1, 0 }, + { "k2", "1", 0, 0 }, + { "k2", "1", 1, 0 }, }; size_t i; @@ -247,15 +211,14 @@ START_TEST(test_store_match_name) char buf[1024]; int status; - m = sdb_store_name_matcher(golden_data[i].type, - golden_data[i].name, golden_data[i].re); + m = sdb_store_attr_matcher(golden_data[i].attr_name, + golden_data[i].attr_value, golden_data[i].re); fail_unless(m != NULL, - "sdb_store_service_matcher(%d, %s, %d) = NULL; expected: ", - golden_data[i].type, golden_data[i].name, golden_data[i].re); + "sdb_store_attr_matcher() = NULL; expected: "); status = sdb_store_matcher_matches(m, obj); fail_unless(status == golden_data[i].expected, - "sdb_store_matcher_matches(%s, ) = %d; expected: %d", + "sdb_store_matcher_matches({%s, ) = %d; expected: %d", sdb_store_matcher_tostring(m, buf, sizeof(buf)), status, golden_data[i].expected); @@ -267,7 +230,7 @@ START_TEST(test_store_match_name) /* now match the inverted set of objects */ status = sdb_store_matcher_matches(n, obj); fail_unless(status == !golden_data[i].expected, - "sdb_store_matcher_matches(%s, ) = %d; expected: %d", + "sdb_store_matcher_matches({%s, ) = %d; expected: %d", sdb_store_matcher_tostring(n, buf, sizeof(buf)), status, !golden_data[i].expected); @@ -282,8 +245,8 @@ START_TEST(test_store_match_op) { sdb_store_base_t *obj; - sdb_store_matcher_t *always = sdb_store_host_matcher(NULL, NULL, NULL); - sdb_store_matcher_t *never = sdb_store_host_matcher("a", "b", NULL); + sdb_store_matcher_t *always = sdb_store_name_matcher(SDB_HOST, "a", 0); + sdb_store_matcher_t *never = sdb_store_name_matcher(SDB_HOST, "z", 0); struct { const char *op; @@ -513,8 +476,8 @@ core_store_lookup_suite(void) tc = tcase_create("core"); tcase_add_checked_fixture(tc, populate, sdb_store_clear); - tcase_add_test(tc, test_store_match); tcase_add_test(tc, test_store_match_name); + tcase_add_test(tc, test_store_match_attr); tcase_add_test(tc, test_store_match_op); tcase_add_test(tc, test_parse_cmp); tcase_add_test(tc, test_lookup); -- 2.30.2