format output as json
[project/uqmi.git] / commands.c
index 044760e..680b75d 100644 (file)
@@ -5,6 +5,7 @@
 #include <unistd.h>
 
 #include <libubox/blobmsg.h>
+#include <libubox/blobmsg_json.h>
 
 #include "uqmi.h"
 #include "commands.h"
@@ -96,6 +97,7 @@ cmd_set_client_id_prepare(struct qmi_dev *qmi, struct qmi_request *req, struct q
 #include "commands-wds.c"
 #include "commands-dms.c"
 #include "commands-nas.c"
+#include "commands-wms.c"
 
 #define __uqmi_command(_name, _optname, _arg, _type) \
        [__UQMI_COMMAND_##_name] = { \
@@ -124,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)