From d591e9699c11eda7087f072892a8be53eaa7d88b Mon Sep 17 00:00:00 2001 From: Felix Fietkau Date: Sat, 8 Jun 2013 22:34:17 +0200 Subject: [PATCH] format output as json --- CMakeLists.txt | 3 ++- commands.c | 25 +++++++++---------------- 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 #include +#include #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) -- 2.25.1