From: Sebastian Harl Date: Sun, 27 Jul 2014 15:35:38 +0000 (+0200) Subject: store, frontend: Renamed sdb_store_lookup() to sdb_store_scan(). X-Git-Tag: sysdb-0.3.0~30 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=2ced8af7848867b7589a7c068f5f51c47dc7ea01;p=sysdb.git store, frontend: Renamed sdb_store_lookup() to sdb_store_scan(). It does a full scan of the entire store, so lookup sounds a bit euphemistic. --- diff --git a/src/core/store_lookup.c b/src/core/store_lookup.c index a3efb46..0bb157c 100644 --- a/src/core/store_lookup.c +++ b/src/core/store_lookup.c @@ -57,21 +57,21 @@ typedef struct { sdb_store_matcher_t *m; sdb_store_lookup_cb cb; void *user_data; -} lookup_iter_data_t; +} scan_iter_data_t; /* * private helper functions */ static int -lookup_iter(sdb_store_obj_t *obj, void *user_data) +scan_iter(sdb_store_obj_t *obj, void *user_data) { - lookup_iter_data_t *d = user_data; + scan_iter_data_t *d = user_data; if (sdb_store_matcher_matches(d->m, obj)) return d->cb(obj, d->user_data); return 0; -} /* lookup_iter */ +} /* scan_iter */ static sdb_attribute_t * attr_get(sdb_host_t *host, const char *name) @@ -891,15 +891,15 @@ sdb_store_matcher_tostring(sdb_store_matcher_t *m, char *buf, size_t buflen) } /* sdb_store_matcher_tostring */ int -sdb_store_lookup(sdb_store_matcher_t *m, sdb_store_lookup_cb cb, +sdb_store_scan(sdb_store_matcher_t *m, sdb_store_lookup_cb cb, void *user_data) { - lookup_iter_data_t data = { m, cb, user_data }; + scan_iter_data_t data = { m, cb, user_data }; if (! cb) return -1; - return sdb_store_iterate(lookup_iter, &data); -} /* sdb_store_lookup */ + return sdb_store_iterate(scan_iter, &data); +} /* sdb_store_scan */ /* vim: set tw=78 sw=4 ts=4 noexpandtab : */ diff --git a/src/frontend/query.c b/src/frontend/query.c index d7476d3..2a6aecf 100644 --- a/src/frontend/query.c +++ b/src/frontend/query.c @@ -166,7 +166,7 @@ sdb_fe_lookup(sdb_conn_t *conn, sdb_store_matcher_t *m) sdb_strbuf_append(buf, "["); - if (sdb_store_lookup(m, lookup_tojson, buf)) { + if (sdb_store_scan(m, lookup_tojson, buf)) { sdb_log(SDB_LOG_ERR, "frontend: Failed to lookup hosts"); sdb_strbuf_sprintf(conn->errbuf, "Failed to lookup hosts"); sdb_strbuf_destroy(buf); diff --git a/src/include/core/store.h b/src/include/core/store.h index 7a9dc44..4e8d468 100644 --- a/src/include/core/store.h +++ b/src/include/core/store.h @@ -295,16 +295,17 @@ sdb_store_matcher_tostring(sdb_store_matcher_t *m, char *buf, size_t buflen); typedef int (*sdb_store_lookup_cb)(sdb_store_obj_t *obj, void *user_data); /* - * sdb_store_lookup: + * sdb_store_scan: * Look up objects in the store. The specified callback function is called for - * each object in the store matching 'm'. + * each object in the store matching 'm'. The function performs a full scan of + * all hosts stored in the database. * * Returns: * - 0 on success * - a negative value else */ int -sdb_store_lookup(sdb_store_matcher_t *m, sdb_store_lookup_cb cb, +sdb_store_scan(sdb_store_matcher_t *m, sdb_store_lookup_cb cb, void *user_data); /* diff --git a/t/unit/core/store_lookup_test.c b/t/unit/core/store_lookup_test.c index 7ecaaf0..351ae18 100644 --- a/t/unit/core/store_lookup_test.c +++ b/t/unit/core/store_lookup_test.c @@ -491,22 +491,22 @@ START_TEST(test_parse_cmp) END_TEST static int -lookup_cb(sdb_store_obj_t *obj, void *user_data) +scan_cb(sdb_store_obj_t *obj, void *user_data) { int *i = user_data; fail_unless(obj != NULL, - "sdb_store_lookup callback received NULL obj; expected: " + "sdb_store_scan callback received NULL obj; expected: " ""); fail_unless(i != NULL, - "sdb_store_lookup callback received NULL user_data; " + "sdb_store_scan callback received NULL user_data; " "expected: "); ++(*i); return 0; -} /* lookup_cb */ +} /* scan_cb */ -START_TEST(test_lookup) +START_TEST(test_scan) { #define PTR_RE "0x[0-9a-f]+" struct { @@ -569,11 +569,11 @@ START_TEST(test_lookup) size_t i; n = 0; - check = sdb_store_lookup(NULL, lookup_cb, &n); + check = sdb_store_scan(NULL, scan_cb, &n); fail_unless(check == 0, - "sdb_store_lookup() = %d; expected: 0", check); + "sdb_store_scan() = %d; expected: 0", check); fail_unless(n == 3, - "sdb_store_lookup called callback %d times; expected: 3", (int)n); + "sdb_store_scan called callback %d times; expected: 3", (int)n); for (i = 0; i < SDB_STATIC_ARRAY_LEN(golden_data); ++i) { sdb_store_matcher_t *m; @@ -591,9 +591,9 @@ START_TEST(test_lookup) golden_data[i].tostring_re); n = 0; - sdb_store_lookup(m, lookup_cb, &n); + sdb_store_scan(m, scan_cb, &n); fail_unless(n == golden_data[i].expected, - "sdb_store_lookup(matcher{%s}) found %d hosts; expected: %d", + "sdb_store_scan(matcher{%s}) found %d hosts; expected: %d", golden_data[i].query, n, golden_data[i].expected); sdb_object_deref(SDB_OBJ(m)); } @@ -613,7 +613,7 @@ core_store_lookup_suite(void) tcase_add_test(tc, test_store_cond); tcase_add_test(tc, test_store_match_op); tcase_add_test(tc, test_parse_cmp); - tcase_add_test(tc, test_lookup); + tcase_add_test(tc, test_scan); suite_add_tcase(s, tc); return s;