Code

Fix detection of libyajl and fix compilation if it's missing.
[sysdb.git] / src / tools / sysdb / json.c
index 703b22e8ef1ed5087ab6af48000d14054657a32f..4f36179b02c823161487c6c0351c9c841351824c 100644 (file)
 #include "utils/strbuf.h"
 #include "tools/sysdb/json.h"
 
-#include <yajl/yajl_parse.h>
-#include <yajl/yajl_gen.h>
+#ifdef HAVE_LIBYAJL
+#      include <yajl/yajl_parse.h>
+#      include <yajl/yajl_gen.h>
+#endif
 
 #include <unistd.h>
 #include <stdio.h>
@@ -107,7 +109,7 @@ printer(void __attribute__((unused)) *ctx, const char *str, size_t len)
  */
 
 int
-sdb_json_print(sdb_strbuf_t *buf)
+sdb_json_print(sdb_input_t *input, sdb_strbuf_t *buf)
 {
 #ifdef HAVE_LIBYAJL
        const unsigned char *json;
@@ -119,6 +121,12 @@ sdb_json_print(sdb_strbuf_t *buf)
 
        int ret = 0;
 
+       if (!input->interactive) {
+               /* no formatting */
+               printf("%s\n", sdb_strbuf_string(buf));
+               return 0;
+       }
+
        gen = yajl_gen_alloc(/* alloc_funcs */ NULL);
        if (! gen)
                return -1;
@@ -150,6 +158,7 @@ sdb_json_print(sdb_strbuf_t *buf)
        yajl_free(h);
        return ret;
 #else /* HAVE_LIBYAJL */
+       (void)input;
        printf("%s\n", sdb_strbuf_string(buf));
        return 0;
 #endif /* HAVE_LIBYAJL */