Code

sysdb/json: Only include YAJL headers if they're actually available.
[sysdb.git] / src / tools / sysdb / json.c
index 703b22e8ef1ed5087ab6af48000d14054657a32f..fdd4194167d6f5ced06562933f38914b31fbcbdd 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;