From: Sebastian Harl Date: Thu, 23 Oct 2014 05:27:30 +0000 (+0200) Subject: store: Removed unused old sdb_store_attr_matcher(). X-Git-Tag: sysdb-0.6.0~74 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=643b6cdd66f789baac6a4f13d1466f7688e22670;p=sysdb.git store: Removed unused old sdb_store_attr_matcher(). --- diff --git a/src/core/store-private.h b/src/core/store-private.h index 717f893..550668d 100644 --- a/src/core/store-private.h +++ b/src/core/store-private.h @@ -135,7 +135,6 @@ enum { MATCHER_AND, MATCHER_NOT, MATCHER_NAME, - MATCHER_ATTR, MATCHER_SERVICE, MATCHER_METRIC, MATCHER_ATTRIBUTE, @@ -157,7 +156,6 @@ enum { : ((t) == MATCHER_AND) ? "AND" \ : ((t) == MATCHER_NOT) ? "NOT" \ : ((t) == MATCHER_NAME) ? "NAME" \ - : ((t) == MATCHER_ATTR) ? "ATTR" \ : ((t) == MATCHER_SERVICE) ? "SERVICE" \ : ((t) == MATCHER_METRIC) ? "METRIC" \ : ((t) == MATCHER_ATTRIBUTE) ? "ATTRIBUTE" \ @@ -233,14 +231,6 @@ typedef struct { } name_matcher_t; #define NAME_M(m) ((name_matcher_t *)(m)) -/* match attributes */ -typedef struct { - sdb_store_matcher_t super; - char *name; - string_matcher_t value; -} attr_matcher_t; -#define ATTR_M(m) ((attr_matcher_t *)(m)) - typedef struct { sdb_store_matcher_t super; sdb_store_expr_t *expr; diff --git a/src/core/store_lookup.c b/src/core/store_lookup.c index 7f96057..e2ae066 100644 --- a/src/core/store_lookup.c +++ b/src/core/store_lookup.c @@ -74,31 +74,6 @@ scan_iter(sdb_store_obj_t *obj, void *user_data) return 0; } /* scan_iter */ -static sdb_attribute_t * -attr_get(sdb_host_t *host, const char *name, sdb_store_matcher_t *filter) -{ - sdb_avltree_iter_t *iter = NULL; - sdb_attribute_t *attr = NULL; - - iter = sdb_avltree_get_iter(host->attributes); - while (sdb_avltree_iter_has_next(iter)) { - sdb_attribute_t *a = ATTR(sdb_avltree_iter_get_next(iter)); - - if (strcasecmp(name, SDB_OBJ(a)->name)) - continue; - - assert(STORE_OBJ(a)->type == SDB_ATTRIBUTE); - attr = a; - break; - } - sdb_avltree_iter_destroy(iter); - - if (filter && (! sdb_store_matcher_matches(filter, STORE_OBJ(attr), - NULL))) - return NULL; - return attr; -} /* attr_get */ - /* * matcher implementations */ @@ -190,29 +165,6 @@ match_name(sdb_store_matcher_t *m, sdb_store_obj_t *obj, return status; } /* match_name */ -static int -match_attr(sdb_store_matcher_t *m, sdb_store_obj_t *obj, - sdb_store_matcher_t *filter) -{ - sdb_attribute_t *attr; - - assert(m->type == MATCHER_ATTR); - assert(ATTR_M(m)->name); - - if (obj->type != SDB_HOST) - return 0; - - attr = attr_get(HOST(obj), ATTR_M(m)->name, filter); - if (attr) { - char buf[sdb_data_strlen(&attr->value) + 1]; - if (sdb_data_format(&attr->value, buf, sizeof(buf), SDB_UNQUOTED) <= 0) - return 0; - if (match_string(&ATTR_M(m)->value, buf)) - return 1; - } - return 0; -} /* match_attr */ - static int match_child(sdb_store_matcher_t *m, sdb_store_obj_t *obj, sdb_store_matcher_t *filter) @@ -460,7 +412,6 @@ matchers[] = { match_logical, match_unary, match_name, - match_attr, match_child, match_child, match_child, @@ -530,31 +481,6 @@ name_matcher_destroy(sdb_object_t *obj) string_matcher_destroy(&m->name); } /* name_matcher_destroy */ -static int -attr_matcher_init(sdb_object_t *obj, va_list ap) -{ - attr_matcher_t *attr = ATTR_M(obj); - const char *name = va_arg(ap, const char *); - - M(obj)->type = MATCHER_ATTR; - if (name) { - attr->name = strdup(name); - if (! attr->name) - return -1; - } - return string_matcher_init(&attr->value, ap); -} /* attr_matcher_init */ - -static void -attr_matcher_destroy(sdb_object_t *obj) -{ - attr_matcher_t *attr = ATTR_M(obj); - if (attr->name) - free(attr->name); - attr->name = NULL; - string_matcher_destroy(&attr->value); -} /* attr_matcher_destroy */ - static int op_matcher_init(sdb_object_t *obj, va_list ap) { @@ -669,12 +595,6 @@ static sdb_type_t name_type = { /* destroy = */ name_matcher_destroy, }; -static sdb_type_t attr_type = { - /* size = */ sizeof(attr_matcher_t), - /* init = */ attr_matcher_init, - /* destroy = */ attr_matcher_destroy, -}; - static sdb_type_t op_type = { /* size = */ sizeof(op_matcher_t), /* init = */ op_matcher_init, @@ -726,23 +646,6 @@ sdb_store_name_matcher(int type, const char *name, _Bool re) return m; } /* sdb_store_name_matcher */ -sdb_store_matcher_t * -sdb_store_attr_matcher(const char *name, const char *value, _Bool re) -{ - sdb_store_matcher_t *m; - - if (! name) - return NULL; - - if (re) - m = M(sdb_object_create("attr-matcher", attr_type, - name, NULL, value)); - else - m = M(sdb_object_create("attr-matcher", attr_type, - name, value, NULL)); - return m; -} /* sdb_store_attr_matcher */ - sdb_store_matcher_t * sdb_store_child_matcher(int type, sdb_store_matcher_t *m) { diff --git a/src/include/core/store.h b/src/include/core/store.h index a3bb2b7..ab12162 100644 --- a/src/include/core/store.h +++ b/src/include/core/store.h @@ -367,15 +367,6 @@ sdb_store_expr_eval(sdb_store_expr_t *expr, sdb_store_obj_t *obj, sdb_store_matcher_t * sdb_store_name_matcher(int type, const char *name, _Bool re); -/* - * sdb_store_attr_matcher: - * Creates a matcher matching attributes based on their value. If 're' is - * true, the specified name is treated as a POSIX extended regular expression. - * Else, the exact name has to match (case-insensitive). - */ -sdb_store_matcher_t * -sdb_store_attr_matcher(const char *name, const char *value, _Bool re); - /* * sdb_store_isnull_matcher: * Creates a matcher matching NULL values. diff --git a/t/unit/core/store_lookup_test.c b/t/unit/core/store_lookup_test.c index d80a599..007fd05 100644 --- a/t/unit/core/store_lookup_test.c +++ b/t/unit/core/store_lookup_test.c @@ -198,81 +198,6 @@ START_TEST(test_store_match_name) } END_TEST -START_TEST(test_store_match_attr) -{ - sdb_store_obj_t *obj; - - struct { - const char *attr_name; - const char *attr_value; - _Bool re; - - int expected; - } golden_data[] = { - { "k1", NULL, 0, 1 }, - { "k", NULL, 1, 0 }, - { "1", NULL, 1, 0 }, - { "k3", NULL, 0, 0 }, - { "k3", NULL, 1, 0 }, - { "k1", "v1", 0, 1 }, - { "k1", "v1", 1, 1 }, - { "k1", "^v1$", 1, 1 }, - { "k1", "v", 1, 1 }, - { "k1", "1", 1, 1 }, - { "k1", "v2", 0, 0 }, - { "k1", "v2", 1, 0 }, - { "k", "v1", 0, 0 }, - { "k", "v1", 1, 0 }, - { "k3", "1", 0, 0 }, - { "k3", "1", 1, 0 }, - }; - - size_t i; - - obj = sdb_store_get_host("a"); - fail_unless(obj != NULL, - "sdb_store_get_host(a) = NULL; expected: "); - - fail_unless(sdb_store_attr_matcher(NULL, "re", 0) == NULL, - "sdb_store_attr_matcher(NULL, \"re\", 0) = ; expected: NULL"); - fail_unless(sdb_store_attr_matcher(NULL, "re", 1) == NULL, - "sdb_store_attr_matcher(NULL, \"re\", 1) = ; expected: NULL"); - - for (i = 0; i < SDB_STATIC_ARRAY_LEN(golden_data); ++i) { - sdb_store_matcher_t *m, *n; - int status; - - 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_attr_matcher() = NULL; expected: "); - - status = sdb_store_matcher_matches(m, obj, /* filter */ NULL); - fail_unless(status == golden_data[i].expected, - "sdb_store_matcher_matches(attribute[%s] = %s, " - ", NULL) = %d; expected: %d", golden_data[i].attr_name, - golden_data[i].attr_value, status, golden_data[i].expected); - - n = sdb_store_inv_matcher(m); - fail_unless(n != NULL, - "sdb_store_inv_matcher() = NULL; expected: "); - sdb_object_deref(SDB_OBJ(m)); - - /* now match the inverted set of objects */ - status = sdb_store_matcher_matches(n, obj, /* filter */ NULL); - fail_unless(status == !golden_data[i].expected, - "sdb_store_matcher_matches(attribute[%s] = %s, " - ", NULL) = %d; expected: %d", - golden_data[i].attr_name, golden_data[i].attr_value, - status, !golden_data[i].expected); - - sdb_object_deref(SDB_OBJ(n)); - } - - sdb_object_deref(SDB_OBJ(obj)); -} -END_TEST - START_TEST(test_cmp_attr) { sdb_store_obj_t *host; @@ -672,6 +597,7 @@ START_TEST(test_scan) const char *filter; int expected; } golden_data[] = { + /* TODO: check the name of the expected hosts */ { "host = 'a'", NULL, 1 }, { "host = 'a'", "host = 'x'", 0 }, /* filter never matches */ { "host = 'a'", @@ -696,10 +622,19 @@ START_TEST(test_scan) { "attribute = 'k1'", "host = 'x'", 0 }, /* filter never matches */ { "attribute = 'k1'", "NOT attribute['x'] = ''", 2 }, /* filter always matches */ + { "attribute =~ 'k'", NULL, 2 }, + { "attribute =~ '1'", NULL, 2 }, + { "attribute =~ '2'", NULL, 1 }, { "attribute = 'x'", NULL, 0 }, + { "attribute =~ 'x'", NULL, 0 }, { "attribute['k1'] = 'v1'", NULL, 1 }, + { "attribute['k1'] =~ 'v1'", NULL, 1 }, + { "attribute['k1'] =~ '^v1$'", NULL, 1 }, { "attribute['k1'] =~ 'v'", NULL, 2 }, + { "attribute['k1'] =~ '1'", NULL, 1 }, { "attribute['k1'] !~ 'v'", NULL, 1 }, + { "attribute['k1'] = 'v2'", NULL, 1 }, + { "attribute['k1'] =~ 'v2'", NULL, 1 }, { "attribute['x1'] =~ 'v'", NULL, 0 }, { "attribute['x1'] =~ 'NULL'", NULL, 0 }, { "attribute['x1'] !~ 'v'", NULL, 3 }, @@ -766,7 +701,6 @@ 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_name); - tcase_add_test(tc, test_store_match_attr); tcase_add_test(tc, test_cmp_attr); tcase_add_test(tc, test_cmp_obj); tcase_add_test(tc, test_store_match_op);