diff --git a/src/core/store_exec.c b/src/core/store_exec.c
index c377129b825e8c6e42a2a690e6953f3a21749337..6cf3a820bd3a013e770d3f172de2a1728649ff19 100644 (file)
--- a/src/core/store_exec.c
+++ b/src/core/store_exec.c
*/
typedef struct {
- sdb_store_json_formatter_t *f;
sdb_store_obj_t *current_host;
+
+ sdb_store_writer_t *w;
+ sdb_object_t *wd;
} iter_t;
static int
if (iter->current_host == obj->parent)
return 0;
iter->current_host = obj->parent;
- return sdb_store_json_emit(iter->f, obj->parent);
+ return sdb_store_emit(obj->parent, iter->w, iter->wd);
} /* maybe_emit_host */
static int
{
iter_t *iter = user_data;
maybe_emit_host(iter, obj);
- return sdb_store_json_emit(iter->f, obj);
+ return sdb_store_emit(obj, iter->w, iter->wd);
} /* list_tojson */
static int
{
iter_t *iter = user_data;
maybe_emit_host(iter, obj);
- return sdb_store_json_emit_full(iter->f, obj, filter);
+ return sdb_store_emit_full(obj, filter, iter->w, iter->wd);
} /* lookup_tojson */
/*
sdb_strbuf_memcpy(buf, &res_type, sizeof(uint32_t));
if (type != SDB_HOST)
- status = sdb_store_json_emit(f, obj->parent);
- if (status || sdb_store_json_emit_full(f, obj, filter)) {
+ status = sdb_store_emit(obj->parent,
+ &sdb_store_json_writer, SDB_OBJ(f));
+ if (status || sdb_store_emit_full(obj, filter,
+ &sdb_store_json_writer, SDB_OBJ(f))) {
sdb_log(SDB_LOG_ERR, "frontend: Failed to serialize "
"%s %s.%s to JSON", SDB_STORE_TYPE_TO_NAME(type),
hostname, name);
int type, sdb_store_matcher_t *filter)
{
uint32_t res_type = htonl(SDB_CONNECTION_LIST);
- iter_t iter = { NULL, NULL };
+ iter_t iter = { NULL, &sdb_store_json_writer, NULL };
+ sdb_store_json_formatter_t *f;
- iter.f = sdb_store_json_formatter(buf, type, SDB_WANT_ARRAY);
- if (! iter.f) {
+ f = sdb_store_json_formatter(buf, type, SDB_WANT_ARRAY);
+ if (! f) {
char err[1024];
sdb_log(SDB_LOG_ERR, "frontend: Failed to create "
"JSON formatter to handle LIST command: %s",
return -1;
}
+ iter.wd = SDB_OBJ(f);
sdb_strbuf_memcpy(buf, &res_type, sizeof(uint32_t));
if (sdb_store_scan(store, type, /* m = */ NULL, filter, list_tojson, &iter)) {
sdb_log(SDB_LOG_ERR, "frontend: Failed to serialize "
"store to JSON");
sdb_strbuf_sprintf(errbuf, "Out of memory");
- sdb_object_deref(SDB_OBJ(iter.f));
+ sdb_object_deref(SDB_OBJ(f));
return -1;
}
- sdb_store_json_finish(iter.f);
- sdb_object_deref(SDB_OBJ(iter.f));
+ sdb_store_json_finish(f);
+ sdb_object_deref(SDB_OBJ(f));
return SDB_CONNECTION_DATA;
} /* exec_list */
int type, sdb_store_matcher_t *m, sdb_store_matcher_t *filter)
{
uint32_t res_type = htonl(SDB_CONNECTION_LOOKUP);
- iter_t iter = { NULL, NULL };
+ iter_t iter = { NULL, &sdb_store_json_writer, NULL };
+ sdb_store_json_formatter_t *f;
- iter.f = sdb_store_json_formatter(buf, type, SDB_WANT_ARRAY);
- if (! iter.f) {
+ f = sdb_store_json_formatter(buf, type, SDB_WANT_ARRAY);
+ if (! f) {
char err[1024];
sdb_log(SDB_LOG_ERR, "frontend: Failed to create "
"JSON formatter to handle LOOKUP command: %s",
return -1;
}
+ iter.wd = SDB_OBJ(f);
sdb_strbuf_memcpy(buf, &res_type, sizeof(uint32_t));
-
if (sdb_store_scan(store, type, m, filter, lookup_tojson, &iter)) {
sdb_log(SDB_LOG_ERR, "frontend: Failed to lookup %ss",
SDB_STORE_TYPE_TO_NAME(type));
sdb_strbuf_sprintf(errbuf, "Failed to lookup %ss",
SDB_STORE_TYPE_TO_NAME(type));
- sdb_object_deref(SDB_OBJ(iter.f));
+ sdb_object_deref(SDB_OBJ(f));
return -1;
}
- sdb_store_json_finish(iter.f);
- sdb_object_deref(SDB_OBJ(iter.f));
+ sdb_store_json_finish(f);
+ sdb_object_deref(SDB_OBJ(f));
return SDB_CONNECTION_DATA;
} /* exec_lookup */