summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 222a6b9)
raw | patch | inline | side by side (parent: 222a6b9)
author | Sebastian Harl <sh@tokkee.org> | |
Fri, 4 Jul 2014 19:06:21 +0000 (21:06 +0200) | ||
committer | Sebastian Harl <sh@tokkee.org> | |
Fri, 4 Jul 2014 19:06:21 +0000 (21:06 +0200) |
src/core/store.c | patch | blob | history | |
t/unit/core/store_test.c | patch | blob | history |
diff --git a/src/core/store.c b/src/core/store.c
index 1c04a77cb6a6c1ce252380211ee8bdb9de188309..605dfc08b71092756b732a0b77644548693a1586 100644 (file)
--- a/src/core/store.c
+++ b/src/core/store.c
* of the serialized data.
*/
static void
-store_obj_tojson(sdb_llist_t *list, int type, sdb_strbuf_t *buf)
+store_obj_tojson(sdb_llist_t *list, int type, sdb_strbuf_t *buf, int flags)
{
sdb_llist_iter_t *iter;
SDB_DOUBLE_QUOTED);
sdb_strbuf_append(buf, "\"value\": %s, ", tmp);
}
-
store_common_tojson(sobj, buf);
+
+ if ((sobj->type == SDB_SERVICE)
+ && (! (flags & SDB_SKIP_ATTRIBUTES))) {
+ sdb_strbuf_append(buf, ", \"attributes\": ");
+ store_obj_tojson(SVC(sobj)->attributes, SDB_ATTRIBUTE,
+ buf, flags);
+ }
sdb_strbuf_append(buf, "}");
if (sdb_llist_iter_has_next(iter))
if (! (flags & SDB_SKIP_ATTRIBUTES)) {
sdb_strbuf_append(buf, ", \"attributes\": ");
- store_obj_tojson(host->attributes, SDB_ATTRIBUTE, buf);
+ store_obj_tojson(host->attributes, SDB_ATTRIBUTE, buf, flags);
}
if (! (flags & SDB_SKIP_SERVICES)) {
sdb_strbuf_append(buf, ", \"services\": ");
- store_obj_tojson(host->services, SDB_SERVICE, buf);
+ store_obj_tojson(host->services, SDB_SERVICE, buf, flags);
}
sdb_strbuf_append(buf, "}");
index 1eb387e34b855f0625b110715f2d7e919e6d3892..0d0c56bce6df859074e64590cf910eea3bfa67f5 100644 (file)
--- a/t/unit/core/store_test.c
+++ b/t/unit/core/store_test.c
sdb_store_service("h2", "s1", 1);
sdb_store_service("h2", "s2", 1);
+
+ datum.type = SDB_TYPE_INTEGER;
+ datum.data.integer = 123;
+ sdb_store_service_attr("h2", "s2", "k1", &datum, 2);
+
+ /* don't overwrite */
+ datum.data.integer = 666;
+ sdb_store_service_attr("h2", "s2", "k1", &datum, 2);
} /* populate */
START_TEST(test_store_host)
"\"services\": ["
"{\"name\": \"s1\", "
"\"last_update\": \"1970-01-01 00:00:00 +0000\", "
- "\"update_interval\": \"0s\", \"backends\": []},"
+ "\"update_interval\": \"0s\", \"backends\": [], "
+ "\"attributes\": []},"
"{\"name\": \"s2\", "
"\"last_update\": \"1970-01-01 00:00:00 +0000\", "
- "\"update_interval\": \"0s\", \"backends\": []}"
+ "\"update_interval\": \"0s\", \"backends\": [], "
+ "\"attributes\": ["
+ "{\"name\": \"k1\", \"value\": 123, "
+ "\"last_update\": \"1970-01-01 00:00:00 +0000\", "
+ "\"update_interval\": \"0s\", \"backends\": []}"
+ "]}"
"]}"
"]}" },
{ SDB_SKIP_SERVICES,