summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 1cea8dc)
raw | patch | inline | side by side (parent: 1cea8dc)
author | Sebastian Harl <sh@tokkee.org> | |
Sun, 27 Jul 2014 15:35:38 +0000 (17:35 +0200) | ||
committer | Sebastian Harl <sh@tokkee.org> | |
Sun, 27 Jul 2014 15:35:38 +0000 (17:35 +0200) |
It does a full scan of the entire store, so lookup sounds a bit euphemistic.
src/core/store_lookup.c | patch | blob | history | |
src/frontend/query.c | patch | blob | history | |
src/include/core/store.h | patch | blob | history | |
t/unit/core/store_lookup_test.c | patch | blob | history |
index a3efb4669c182ee66938ac3554ba79c10d577d84..0bb157c76e7a49162e3832f5b9ae0e013372485a 100644 (file)
--- a/src/core/store_lookup.c
+++ b/src/core/store_lookup.c
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)
} /* 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 d7476d345d48791f7cac512daca7ebfcfae49782..2a6aecff6b1513856f22c9929646bb64c34367c7 100644 (file)
--- a/src/frontend/query.c
+++ b/src/frontend/query.c
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);
index 7a9dc44bbc887cd00583675ed841d8c9c70ec30f..4e8d468c4263f0e57cd2f26d301aedf0006102a7 100644 (file)
--- a/src/include/core/store.h
+++ b/src/include/core/store.h
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);
/*
index 7ecaaf0c3706fb535909cf8488c23dc158234e99..351ae18da7dfd899c918c897da267503597d644b 100644 (file)
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: "
"<store base obj>");
fail_unless(i != NULL,
- "sdb_store_lookup callback received NULL user_data; "
+ "sdb_store_scan callback received NULL user_data; "
"expected: <pointer to data>");
++(*i);
return 0;
-} /* lookup_cb */
+} /* scan_cb */
-START_TEST(test_lookup)
+START_TEST(test_scan)
{
#define PTR_RE "0x[0-9a-f]+"
struct {
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;
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));
}
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;