Code

sysdb: If available, use YAJL to pretty-print JSON output.
[sysdb.git] / src / tools / sysdb / command.c
index 440ba41e3b13832574ff0ca42472315023cd7f07..4de2b44e4fc79245027a22c5c2932bd82b46f742 100644 (file)
@@ -33,6 +33,7 @@
 
 #include "tools/sysdb/command.h"
 #include "tools/sysdb/input.h"
+#include "tools/sysdb/json.h"
 
 #include "frontend/proto.h"
 #include "utils/error.h"
@@ -89,7 +90,9 @@ data_printer(sdb_strbuf_t *buf)
        /* At the moment, we don't care about the result type. We simply print the
         * result without further parsing it. */
        sdb_strbuf_skip(buf, 0, sizeof(uint32_t));
-       printf("%s\n", sdb_strbuf_string(buf));
+       if (sdb_json_print(buf))
+               sdb_log(SDB_LOG_ERR, "Failed to print result");
+       printf("\n");
 } /* data_printer */
 
 static struct {
@@ -215,5 +218,25 @@ sdb_command_exec(sdb_input_t *input)
        return data;
 } /* sdb_command_exec */
 
+void
+sdb_command_print_server_version(sdb_input_t *input)
+{
+       sdb_strbuf_t *buf = sdb_strbuf_create(32);
+       uint32_t code = 0, version = 0;
+       const char *extra;
+
+       if ((sdb_client_rpc(input->client, SDB_CONNECTION_SERVER_VERSION,
+                                       0, NULL, &code, buf) < 0) || (code != SDB_CONNECTION_OK))
+               return;
+       if (sdb_strbuf_len(buf) < sizeof(version))
+               return;
+
+       sdb_proto_unmarshal_int32(SDB_STRBUF_STR(buf), &version);
+       extra = sdb_strbuf_string(buf) + sizeof(version);
+       sdb_log(SDB_LOG_INFO, "SysDB server %d.%d.%d%s",
+                       SDB_VERSION_DECODE((int)version), extra);
+       sdb_strbuf_destroy(buf);
+} /* sdb_command_print_server_version */
+
 /* vim: set tw=78 sw=4 ts=4 noexpandtab : */