summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFelix Fietkau <nbd@openwrt.org>2013-06-08 22:34:17 +0200
committerFelix Fietkau <nbd@openwrt.org>2013-06-08 22:36:09 +0200
commitd591e9699c11eda7087f072892a8be53eaa7d88b (patch)
tree31009a8da63ea94a5383cc69a08fcdccfa35100b
parent75abe029f3d264520f0e4065e3ebe895d941db38 (diff)
format output as json
-rw-r--r--CMakeLists.txt3
-rw-r--r--commands.c25
2 files changed, 11 insertions, 17 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index ce2e147..a09865f 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -7,7 +7,8 @@ SET(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "")
SET(SOURCES main.c dev.c commands.c qmi-message.c)
-SET(LIBS ubox)
+FIND_LIBRARY(json json-c json)
+SET(LIBS ubox blobmsg_json ${json})
IF(DEBUG_PACKET)
ADD_DEFINITIONS(-DDEBUG_PACKET)
diff --git a/commands.c b/commands.c
index 43b9ca9..680b75d 100644
--- a/commands.c
+++ b/commands.c
@@ -5,6 +5,7 @@
#include <unistd.h>
#include <libubox/blobmsg.h>
+#include <libubox/blobmsg_json.h>
#include "uqmi.h"
#include "commands.h"
@@ -125,22 +126,14 @@ void uqmi_add_command(char *arg, int cmd)
static void uqmi_print_result(struct blob_attr *data)
{
- struct blob_attr *cur;
- int rem;
-
- blob_for_each_attr(cur, data, rem) {
- switch (blobmsg_type(cur)) {
- case BLOBMSG_TYPE_STRING:
- printf("%s=%s\n", blobmsg_name(cur), (char *) blobmsg_data(cur));
- break;
- case BLOBMSG_TYPE_INT32:
- printf("%s=%d\n", blobmsg_name(cur), (int32_t) blobmsg_get_u32(cur));
- break;
- case BLOBMSG_TYPE_INT8:
- printf("%s=%s\n", blobmsg_name(cur), blobmsg_get_u8(cur) ? "true" : "false");
- break;
- }
- }
+ char *str;
+
+ str = blobmsg_format_json_indent(data, true, 0);
+ if (!str)
+ return;
+
+ printf("%s\n", str);
+ free(str);
}
static bool __uqmi_run_commands(struct qmi_dev *qmi, bool option)