From b0af45ebf920955095b9fdeaddbde0107c6e519f Mon Sep 17 00:00:00 2001 From: Sebastian Harl Date: Thu, 19 Jun 2014 15:09:23 +0200 Subject: [PATCH] store_lookup: Removed the (now unused) service matcher. --- src/core/store-private.h | 11 --- src/core/store_lookup.c | 132 +------------------------------- src/include/core/store.h | 12 +-- t/unit/core/store_lookup_test.c | 84 +++----------------- 4 files changed, 15 insertions(+), 224 deletions(-) diff --git a/src/core/store-private.h b/src/core/store-private.h index cda9835..64a70c3 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_SERVICE, MATCHER_HOST, }; @@ -146,19 +145,9 @@ typedef struct { } attr_matcher_t; #define ATTR_M(m) ((attr_matcher_t *)(m)) -/* match services */ -typedef struct { - obj_matcher_t super; - /* match by attributes assigned to the service */ - attr_matcher_t *attr; -} service_matcher_t; -#define SERVICE_M(m) ((service_matcher_t *)(m)) - /* match hosts */ typedef struct { obj_matcher_t super; - /* match by services assigned to the host */ - service_matcher_t *service; /* match by attributes assigned to the host */ attr_matcher_t *attr; } host_matcher_t; diff --git a/src/core/store_lookup.c b/src/core/store_lookup.c index b5b40e6..1fe45df 100644 --- a/src/core/store_lookup.c +++ b/src/core/store_lookup.c @@ -176,28 +176,10 @@ attr_tostring(sdb_store_matcher_t *m, char *buf, size_t buflen) return buf; } /* attr_tostring */ -static char * -service_tostring(sdb_store_matcher_t *m, char *buf, size_t buflen) -{ - char name[buflen + 1], attr[buflen + 1]; - - if (! m) { - snprintf(buf, buflen, "SERVICE{}"); - return buf; - } - - assert(m->type == MATCHER_SERVICE); - snprintf(buf, buflen, "SERVICE{ NAME%s, %s }", - obj_name_tostring(&OBJ_M(m)->name, name, sizeof(name)), - attr_tostring(SDB_STORE_MATCHER(SERVICE_M(m)->attr), - attr, sizeof(attr))); - return buf; -} /* service_tostring */ - static char * host_tostring(sdb_store_matcher_t *m, char *buf, size_t buflen) { - char name[buflen + 1], service[buflen + 1], attr[buflen + 1]; + char name[buflen + 1], attr[buflen + 1]; if (! m) { snprintf(buf, buflen, "HOST{}"); @@ -205,10 +187,8 @@ host_tostring(sdb_store_matcher_t *m, char *buf, size_t buflen) } assert(m->type == MATCHER_HOST); - snprintf(buf, buflen, "HOST{ NAME%s, %s, %s }", + snprintf(buf, buflen, "HOST{ NAME%s, %s }", obj_name_tostring(&OBJ_M(m)->name, name, sizeof(name)), - service_tostring(SDB_STORE_MATCHER(HOST_M(m)->service), - service, sizeof(service)), attr_tostring(SDB_STORE_MATCHER(HOST_M(m)->attr), attr, sizeof(attr))); return buf; @@ -268,70 +248,19 @@ match_attr(attr_matcher_t *m, sdb_store_base_t *obj) } } /* match_attr */ -/* match service specific values; - * always call this function through match_obj() */ -static int -match_service(service_matcher_t *m, sdb_store_base_t *obj) -{ - sdb_llist_iter_t *iter; - - assert(m && obj); - - if (obj->type != SDB_SERVICE) - return 0; - - if (! m->attr) - return 1; - - iter = sdb_llist_get_iter(SDB_STORE_OBJ(obj)->attributes); - while (sdb_llist_iter_has_next(iter)) { - sdb_store_base_t *attr = STORE_BASE(sdb_llist_iter_get_next(iter)); - - /* if any of the attributes matches we found a matching service */ - if (match_obj(M(m->attr), attr)) { - sdb_llist_iter_destroy(iter); - return 1; - } - } - sdb_llist_iter_destroy(iter); - return 0; -} /* match_service */ - /* match host specific values; * always call this function through match_obj() */ static int match_host(host_matcher_t *m, sdb_store_base_t *obj) { sdb_llist_iter_t *iter; - int status; assert(m && obj); if (obj->type != SDB_HOST) return 0; - if (m->service) { - iter = sdb_llist_get_iter(SDB_STORE_OBJ(obj)->children); - status = 0; - } - else { - iter = NULL; - status = 1; - } - while (sdb_llist_iter_has_next(iter)) { - sdb_store_base_t *service = STORE_BASE(sdb_llist_iter_get_next(iter)); - - /* found a matching service */ - if (match_obj(M(m->service), service)) { - status = 1; - break; - } - } - sdb_llist_iter_destroy(iter); - - if (! status) - return status; - else if (! m->attr) + if (! m->attr) return 1; iter = sdb_llist_get_iter(SDB_STORE_OBJ(obj)->attributes); @@ -361,7 +290,6 @@ static matcher_cb matchers[] = { match_name, match_obj, match_obj, - match_obj, }; typedef char *(*matcher_tostring_cb)(sdb_store_matcher_t *, char *, size_t); @@ -372,7 +300,6 @@ static matcher_tostring_cb matchers_tostring[] = { unary_tostring, name_tostring, attr_tostring, - service_tostring, host_tostring, }; @@ -418,9 +345,6 @@ match_obj(sdb_store_matcher_t *m, sdb_store_base_t *obj) case MATCHER_ATTR: return match_attr(ATTR_M(m), obj); break; - case MATCHER_SERVICE: - return match_service(SERVICE_M(m), obj); - break; case MATCHER_HOST: return match_host(HOST_M(m), obj); break; @@ -507,36 +431,9 @@ attr_matcher_destroy(sdb_object_t *obj) name_matcher_destroy(&attr->value); } /* attr_matcher_destroy */ -static int -service_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)); - SERVICE_M(obj)->attr = attr; - - M(obj)->type = MATCHER_SERVICE; - return 0; -} /* service_matcher_init */ - -static void -service_matcher_destroy(sdb_object_t *obj) -{ - obj_matcher_destroy(obj); - sdb_object_deref(SDB_OBJ(SERVICE_M(obj)->attr)); -} /* service_matcher_destroy */ - static int host_matcher_init(sdb_object_t *obj, va_list ap) { - service_matcher_t *service; attr_matcher_t *attr; int status; @@ -544,11 +441,7 @@ host_matcher_init(sdb_object_t *obj, va_list ap) if (status) return status; - service = va_arg(ap, service_matcher_t *); attr = va_arg(ap, attr_matcher_t *); - - sdb_object_ref(SDB_OBJ(service)); - HOST_M(obj)->service = service; sdb_object_ref(SDB_OBJ(attr)); HOST_M(obj)->attr = attr; @@ -560,7 +453,6 @@ static void host_matcher_destroy(sdb_object_t *obj) { obj_matcher_destroy(obj); - sdb_object_deref(SDB_OBJ(HOST_M(obj)->service)); sdb_object_deref(SDB_OBJ(HOST_M(obj)->attr)); } /* host_matcher_destroy */ @@ -624,12 +516,6 @@ static sdb_type_t attr_type = { /* destroy = */ attr_matcher_destroy, }; -static sdb_type_t service_type = { - /* size = */ sizeof(service_matcher_t), - /* init = */ service_matcher_init, - /* destroy = */ service_matcher_destroy, -}; - static sdb_type_t host_type = { /* size = */ sizeof(host_matcher_t), /* init = */ host_matcher_init, @@ -679,21 +565,12 @@ sdb_store_attr_matcher(const char *attr_name, const char *attr_name_re, attr_name, attr_name_re, attr_value, attr_value_re)); } /* sdb_store_attr_matcher */ -sdb_store_matcher_t * -sdb_store_service_matcher(const char *service_name, const char *service_name_re, - sdb_store_matcher_t *attr_matcher) -{ - return M(sdb_object_create("service-matcher", service_type, - service_name, service_name_re, attr_matcher)); -} /* sdb_store_service_matcher */ - sdb_store_matcher_t * sdb_store_host_matcher(const char *host_name, const char *host_name_re, - sdb_store_matcher_t *service_matcher, sdb_store_matcher_t *attr_matcher) { return M(sdb_object_create("host-matcher", host_type, - host_name, host_name_re, service_matcher, attr_matcher)); + host_name, host_name_re, attr_matcher)); } /* sdb_store_host_matcher */ sdb_store_matcher_t * @@ -740,7 +617,6 @@ sdb_store_matcher_parse_cmp(const char *obj_type, const char *attr, m = sdb_store_name_matcher(type, value, re); else if (type == SDB_ATTRIBUTE) { m = sdb_store_host_matcher(/* name = */ NULL, NULL, - /* service = */ NULL, sdb_store_attr_matcher(attr, NULL, matcher, matcher_re)); /* pass ownership to the host matcher */ diff --git a/src/include/core/store.h b/src/include/core/store.h index 68ee3aa..856e19c 100644 --- a/src/include/core/store.h +++ b/src/include/core/store.h @@ -175,22 +175,12 @@ sdb_store_matcher_t * sdb_store_attr_matcher(const char *attr_name, const char *attr_name_re, const char *attr_value, const char *attr_value_re); -/* - * sdb_store_service_matcher: - * Creates a matcher matching services based on their name or attributes. - */ -sdb_store_matcher_t * -sdb_store_service_matcher(const char *service_name, const char *service_name_re, - sdb_store_matcher_t *attr_matcher); - /* * sdb_store_host_matcher: - * Creates a matcher matching hosts based on their name, services assigned to - * the host, or its attributes. + * 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 *service_matcher, sdb_store_matcher_t *attr_matcher); /* diff --git a/t/unit/core/store_lookup_test.c b/t/unit/core/store_lookup_test.c index efd2071..1a55d87 100644 --- a/t/unit/core/store_lookup_test.c +++ b/t/unit/core/store_lookup_test.c @@ -90,9 +90,6 @@ START_TEST(test_store_match) const char *hostname; const char *hostname_re; - const char *service_name; - const char *service_name_re; - const char *attr_name; const char *attr_name_re; const char *attr_value; @@ -102,107 +99,54 @@ START_TEST(test_store_match) } golden_data[] = { { /* host */ NULL, NULL, - /* svc */ NULL, NULL, /* attr */ NULL, NULL, NULL, NULL, 1 }, { /* host */ "a", NULL, - /* svc */ NULL, NULL, /* attr */ NULL, NULL, NULL, NULL, 1 }, { /* host */ "b", NULL, - /* svc */ NULL, NULL, /* attr */ NULL, NULL, NULL, NULL, 0 }, { /* host */ NULL, "^a$", - /* svc */ NULL, NULL, /* attr */ NULL, NULL, NULL, NULL, 1 }, { /* host */ NULL, "^b$", - /* svc */ NULL, NULL, /* attr */ NULL, NULL, NULL, NULL, 0 }, { /* host */ "a", "^a$", - /* svc */ NULL, NULL, /* attr */ NULL, NULL, NULL, NULL, 1 }, { /* host */ "a", "^b$", - /* svc */ NULL, NULL, /* attr */ NULL, NULL, NULL, NULL, 0 }, { /* host */ "b", "^a$", - /* svc */ NULL, NULL, - /* attr */ NULL, NULL, NULL, NULL, 0 - }, - { - /* host */ "a", "^a$", - /* svc */ "s1", NULL, - /* attr */ NULL, NULL, NULL, NULL, 1 - }, - { - /* host */ "a", "^a$", - /* svc */ NULL, "^s1$", - /* attr */ NULL, NULL, NULL, NULL, 1 - }, - { - /* host */ "a", "^a$", - /* svc */ "s1", "^s1$", - /* attr */ NULL, NULL, NULL, NULL, 1 - }, - { - /* host */ "a", "^a$", - /* svc */ "x1", NULL, /* attr */ NULL, NULL, NULL, NULL, 0 }, { /* host */ "a", "^a$", - /* svc */ NULL, "x", - /* attr */ NULL, NULL, NULL, NULL, 0 - }, - { - /* host */ "a", "^a$", - /* svc */ "x1", "x", - /* attr */ NULL, NULL, NULL, NULL, 0 - }, - { - /* host */ "a", "^a$", - /* svc */ "s1", "x", - /* attr */ NULL, NULL, NULL, NULL, 0 - }, - { - /* host */ "a", "^a$", - /* svc */ "x1", "s", - /* attr */ NULL, NULL, NULL, NULL, 0 - }, - { - /* host */ "a", "^a$", - /* svc */ "s1", "^s1$", /* attr */ "k1", NULL, NULL, NULL, 1 }, { /* host */ "a", "^a$", - /* svc */ "s1", "^s1$", /* attr */ NULL, "^k", NULL, NULL, 1 }, { /* host */ "a", "^a$", - /* svc */ "s1", "^s1$", /* attr */ NULL, NULL, "v1", NULL, 1 }, { /* host */ "a", "^a$", - /* svc */ "s1", "^s1$", /* attr */ NULL, NULL, NULL, "^v1$", 1 }, { /* host */ "a", "^a$", - /* svc */ "s1", "^s1$", /* attr */ "k1", "1", "v1", "1", 1 }, }; @@ -214,14 +158,9 @@ 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, *s, *a, *n; + sdb_store_matcher_t *h, *a, *n; int status; - s = sdb_store_service_matcher(golden_data[i].service_name, - golden_data[i].service_name_re, NULL); - fail_unless(s != NULL, - "sdb_store_service_matcher() = NULL; expected: "); - a = sdb_store_attr_matcher(golden_data[i].attr_name, golden_data[i].attr_name_re, golden_data[i].attr_value, golden_data[i].attr_value_re); @@ -229,19 +168,17 @@ START_TEST(test_store_match) "sdb_store_attr_matcher() = NULL; expected: "); h = sdb_store_host_matcher(golden_data[i].hostname, - golden_data[i].hostname_re, s, a); + 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(s)); sdb_object_deref(SDB_OBJ(a)); status = sdb_store_matcher_matches(h, obj); fail_unless(status == golden_data[i].expected, - "sdb_store_matcher_matches({{%s, %s},{%s, %s}," + "sdb_store_matcher_matches({{%s, %s}," "{%s, %s, %s, %s}}, ) = %d; expected: %d", golden_data[i].hostname, golden_data[i].hostname_re, - golden_data[i].service_name, golden_data[i].service_name_re, golden_data[i].attr_name, golden_data[i].attr_name_re, golden_data[i].attr_value, golden_data[i].attr_value_re, status, golden_data[i].expected); @@ -254,10 +191,9 @@ START_TEST(test_store_match) /* 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(NOT{{%s, %s},{%s, %s}," + "sdb_store_matcher_matches(NOT{{%s, %s}," "{%s, %s, %s, %s}}, ) = %d; expected: %d", golden_data[i].hostname, golden_data[i].hostname_re, - golden_data[i].service_name, golden_data[i].service_name_re, golden_data[i].attr_name, golden_data[i].attr_name_re, golden_data[i].attr_value, golden_data[i].attr_value_re, status, !golden_data[i].expected); @@ -357,8 +293,8 @@ START_TEST(test_store_match_op) { sdb_store_base_t *obj; - sdb_store_matcher_t *always = sdb_store_host_matcher(NULL, NULL, NULL, NULL); - sdb_store_matcher_t *never = sdb_store_host_matcher("a", "b", NULL, NULL); + sdb_store_matcher_t *always = sdb_store_host_matcher(NULL, NULL, NULL); + sdb_store_matcher_t *never = sdb_store_host_matcher("a", "b", NULL); struct { const char *op; @@ -533,21 +469,21 @@ START_TEST(test_lookup) { "attribute.name = 'x'", 0, "OBJ\\[attribute\\]\\{ NAME\\{ 'x', \\(nil\\) \\}" }, { "attribute.k1 = 'v1'", 1, - "HOST\\{ NAME\\{ NULL, \\(nil\\) \\}, SERVICE\\{\\}, ATTR\\{ " + "HOST\\{ NAME\\{ NULL, \\(nil\\) \\}, ATTR\\{ " "NAME\\{ 'k1', \\(nil\\) }, VALUE\\{ 'v1', \\(nil\\) \\} " "\\} \\}" }, { "attribute.k1 != 'v1'", 2, - "\\(NOT, HOST\\{ NAME\\{ NULL, \\(nil\\) \\}, SERVICE\\{\\}, ATTR\\{ " + "\\(NOT, HOST\\{ NAME\\{ NULL, \\(nil\\) \\}, ATTR\\{ " "NAME\\{ 'k1', \\(nil\\) }, VALUE\\{ 'v1', \\(nil\\) \\} " "\\} \\})" }, { "attribute.k1 != 'v2'", 3, - "\\(NOT, HOST\\{ NAME\\{ NULL, \\(nil\\) \\}, SERVICE\\{\\}, ATTR\\{ " + "\\(NOT, HOST\\{ NAME\\{ NULL, \\(nil\\) \\}, ATTR\\{ " "NAME\\{ 'k1', \\(nil\\) }, VALUE\\{ 'v2', \\(nil\\) \\} " "\\} \\})" }, { "attribute.name != 'x' " "AND attribute.y !~ 'x'", 3, "\\(AND, \\(NOT, OBJ\\[attribute\\]\\{ NAME\\{ 'x', \\(nil\\) \\} " - "\\}\\), \\(NOT, HOST\\{ NAME\\{ NULL, \\(nil\\) \\}, SERVICE\\{\\}, ATTR\\{ " + "\\}\\), \\(NOT, HOST\\{ NAME\\{ NULL, \\(nil\\) \\}, ATTR\\{ " "NAME\\{ 'y', \\(nil\\) }, VALUE\\{ NULL, "PTR_RE" \\} " "\\} \\}\\)\\)" }, }; -- 2.30.2