X-Git-Url: http://git.archive.openwrt.org/?p=project%2Fuqmi.git;a=blobdiff_plain;f=commands.c;h=468051156c4abaa93d9017dd28a83ed223ce5dec;hp=680b75dd0b1fb9c5446eb33dd632e814f8ba1a12;hb=4ab698d5b6e27dece939c858aae070f5beda71a1;hpb=d591e9699c11eda7087f072892a8be53eaa7d88b;ds=sidebyside diff --git a/commands.c b/commands.c index 680b75d..4680511 100644 --- a/commands.c +++ b/commands.c @@ -11,6 +11,7 @@ #include "commands.h" static struct blob_buf status; +bool single_line = false; static void no_cb(struct qmi_dev *qmi, struct qmi_request *req, struct qmi_msg *msg) { @@ -128,7 +129,10 @@ static void uqmi_print_result(struct blob_attr *data) { char *str; - str = blobmsg_format_json_indent(data, true, 0); + if (!blob_len(data)) + return; + + str = blobmsg_format_json_indent(blob_data(data), false, single_line ? -1 : 0); if (!str) return; @@ -153,7 +157,7 @@ static bool __uqmi_run_commands(struct qmi_dev *qmi, bool option) blob_buf_init(&status, 0); if (cmds[i].handler->type > QMI_SERVICE_CTL && qmi_service_connect(qmi, cmds[i].handler->type, -1)) { - blobmsg_printf(&status, "error", "failed to connect to service"); + uqmi_add_error("Failed to connect to service"); res = QMI_CMD_EXIT; } else { res = cmds[i].handler->prepare(qmi, &req, (void *) buf, cmds[i].arg); @@ -162,8 +166,10 @@ static bool __uqmi_run_commands(struct qmi_dev *qmi, bool option) if (res == QMI_CMD_REQUEST) { qmi_request_start(qmi, &req, (void *) buf, cmds[i].handler->cb); req.no_error_cb = true; - if (qmi_request_wait(qmi, &req)) - blobmsg_add_string(&status, "error", qmi_get_error_str(req.ret)); + if (qmi_request_wait(qmi, &req)) { + uqmi_add_error(qmi_get_error_str(req.ret)); + do_break = true; + } } else if (res == QMI_CMD_EXIT) { do_break = true; } @@ -175,11 +181,22 @@ static bool __uqmi_run_commands(struct qmi_dev *qmi, bool option) return true; } -void uqmi_run_commands(struct qmi_dev *qmi) +int uqmi_add_error(const char *msg) +{ + blobmsg_add_string(&status, NULL, msg); + return QMI_CMD_EXIT; +} + +bool uqmi_run_commands(struct qmi_dev *qmi) { - if (__uqmi_run_commands(qmi, true)) - __uqmi_run_commands(qmi, false); + bool ret; + + ret = __uqmi_run_commands(qmi, true) && + __uqmi_run_commands(qmi, false); + free(cmds); cmds = NULL; n_cmds = 0; + + return ret; }