summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 85eaead)
raw | patch | inline | side by side (parent: 85eaead)
author | Sebastian Harl <sh@tokkee.org> | |
Tue, 7 Oct 2014 21:28:33 +0000 (23:28 +0200) | ||
committer | Sebastian Harl <sh@tokkee.org> | |
Tue, 7 Oct 2014 21:28:33 +0000 (23:28 +0200) |
diff --git a/src/core/store.c b/src/core/store.c
index 8cb30efaea88a250284cb569db2ae07b05d7fa12..f4f2b58f0d700c0df8967aafddd6429261732af8 100644 (file)
--- a/src/core/store.c
+++ b/src/core/store.c
int
sdb_store_get_field(sdb_store_obj_t *obj, int field, sdb_data_t *res)
{
+ sdb_data_t tmp;
+
if ((! obj) || (! res))
return -1;
switch (field) {
+ case SDB_FIELD_NAME:
+ tmp.type = SDB_TYPE_STRING;
+ tmp.data.string = strdup(SDB_OBJ(obj)->name);
+ if (! tmp.data.string)
+ return -1;
+ *res = tmp;
+ break;
case SDB_FIELD_LAST_UPDATE:
res->type = SDB_TYPE_DATETIME;
res->data.datetime = obj->last_update;
index 302736754ed8434421596b0801d08cc5ad33f27e..6aa4095bc5de2370f965e88500bc01f8c817cc8d 100644 (file)
--- a/src/core/store_lookup.c
+++ b/src/core/store_lookup.c
int
sdb_store_parse_field_name(const char *name)
{
- if (! strcasecmp(name, "last_update"))
+ if (! strcasecmp(name, "name"))
+ return SDB_FIELD_NAME;
+ else if (! strcasecmp(name, "last_update"))
return SDB_FIELD_LAST_UPDATE;
else if (! strcasecmp(name, "age"))
return SDB_FIELD_AGE;
index d5a76941c06255085215a77215c2cd17b0b89f3c..90416a2cc0699cc3df67d50ac516a1d415a9f058 100644 (file)
--- a/src/include/core/store.h
+++ b/src/include/core/store.h
* Queryable fields of a stored object.
*/
enum {
- SDB_FIELD_LAST_UPDATE = 1, /* datetime */
- SDB_FIELD_AGE, /* datetime */
- SDB_FIELD_INTERVAL, /* datetime */
- SDB_FIELD_BACKEND, /* string */
+ SDB_FIELD_NAME = 1, /* string */
+ SDB_FIELD_LAST_UPDATE, /* datetime */
+ SDB_FIELD_AGE, /* datetime */
+ SDB_FIELD_INTERVAL, /* datetime */
+ SDB_FIELD_BACKEND, /* string */
};
#define SDB_FIELD_TO_NAME(f) \
- (((f) == SDB_FIELD_LAST_UPDATE) ? "last-update" \
+ (((f) == SDB_FIELD_NAME) ? "name" \
+ : ((f) == SDB_FIELD_LAST_UPDATE) ? "last-update" \
: ((f) == SDB_FIELD_AGE) ? "age" \
: ((f) == SDB_FIELD_INTERVAL) ? "interval" \
: ((f) == SDB_FIELD_BACKEND) ? "backend" : "unknown")
index e5a0a74c4becffff53d479a174d60daf97bf2b4d..3b0e956e327404f11c42e96d8391dce60bb08b3b 100644 (file)
const sdb_data_t value;
int expected_lt, expected_le, expected_eq, expected_ge, expected_gt;
} golden_data[] = {
+ { "b", SDB_FIELD_NAME,
+ { SDB_TYPE_STRING, { .string = "a" } }, 0, 0, 0, 1, 1 },
+ { "b", SDB_FIELD_NAME,
+ { SDB_TYPE_STRING, { .string = "b" } }, 0, 1, 1, 1, 0 },
+ { "b", SDB_FIELD_NAME,
+ { SDB_TYPE_STRING, { .string = "c" } }, 1, 1, 0, 0, 0 },
/* last-update = 1 for all objects */
{ "a", SDB_FIELD_LAST_UPDATE,
{ SDB_TYPE_DATETIME, { .datetime = 1 } }, 0, 1, 1, 1, 0 },
status = sdb_store_matcher_matches(m, obj, /* filter */ NULL);
fail_unless(status == tests[j].expected,
- "sdb_store_matcher_matches(%s, <obj>, NULL) = %d; "
+ "sdb_store_matcher_matches(%s, <host '%s'>, NULL) = %d; "
"expected: %d",
sdb_store_matcher_tostring(m, m_str, sizeof(m_str)),
status, tests[j].expected);
const sdb_data_t *value;
int expected;
} golden_data[] = {
+ { "name", "<", &string, MATCHER_LT },
+ { "name", "<=", &string, MATCHER_LE },
+ { "name", "=", &string, MATCHER_EQ },
+ { "name", ">=", &string, MATCHER_GE },
+ { "name", ">", &string, MATCHER_GT },
+ { "name", "!=", &string, MATCHER_NOT },
{ "last_update", "<", &datetime, MATCHER_LT },
{ "last_update", "<=", &datetime, MATCHER_LE },
{ "last_update", "=", &datetime, MATCHER_EQ },
index 796c50cb1eddda2c6b030ccfc50ed73b23e3c83c..00e3c64389d3843321bb2fcbb396f8174fb0ed68 100644 (file)
--- a/t/unit/core/store_test.c
+++ b/t/unit/core/store_test.c
"{\"name\": \"h2\", \"last_update\": \"1970-01-01 00:00:00 +0000\", "
"\"update_interval\": \"0s\", \"backends\": []}"
"]" },
+ { { sdb_store_eq_matcher, SDB_FIELD_NAME,
+ { SDB_TYPE_STRING, { .string = "h1" } } }, 0,
+ "["
+ "{\"name\": \"h1\", \"last_update\": \"1970-01-01 00:00:00 +0000\", "
+ "\"update_interval\": \"0s\", \"backends\": [], "
+ "\"attributes\": [], \"metrics\": [], \"services\": []}"
+ "]" },
{ { sdb_store_gt_matcher, SDB_FIELD_LAST_UPDATE,
{ SDB_TYPE_DATETIME, { .datetime = 1 } } }, 0,
"["
"sdb_store_get_field(NULL, SDB_FIELD_LAST_UPDATE, <value>) = %d; "
"expected: <0");
+ check = sdb_store_get_field(host, SDB_FIELD_NAME, &value);
+ fail_unless(check == 0,
+ "sdb_store_get_field(<host>, SDB_FIELD_NAME, <value>) = "
+ "%d; expected: 0");
+ fail_unless((value.type == SDB_TYPE_STRING)
+ && (! strcmp(value.data.string, "host")),
+ "sdb_store_get_field(<host>, SDB_FIELD_NAME, <value>) "
+ "returned value {%d, %s}; expected {%d, host}",
+ value.type, value.data.string, SDB_TYPE_STRING);
+ sdb_data_free_datum(&value);
+
check = sdb_store_get_field(host, SDB_FIELD_LAST_UPDATE, &value);
fail_unless(check == 0,
"sdb_store_get_field(<host>, SDB_FIELD_LAST_UPDATE, <value>) = "