From 6cbe69e89e716f81a71f7541e2e0f036b297a2fc Mon Sep 17 00:00:00 2001 From: OpenGnSys Support Team Date: Fri, 21 Jun 2024 15:04:47 +0200 Subject: rest: add cmd to shell/output Add "cmd" field to json that provides the original command string, so it is provided with the output and the return code. --- src/client.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'src/client.c') diff --git a/src/client.c b/src/client.c index 46baab8..3affaed 100644 --- a/src/client.c +++ b/src/client.c @@ -171,7 +171,7 @@ static int og_resp_probe(struct og_client *cli, json_t *data) static int og_resp_shell_run(struct og_client *cli, json_t *data) { - const char *output = NULL; + const char *cmd = NULL, *output = NULL; uint32_t retcode; const char *key; json_t *value; @@ -181,7 +181,11 @@ static int og_resp_shell_run(struct og_client *cli, json_t *data) return -1; json_object_foreach(data, key, value) { - if (!strcmp(key, "out")) { + if (!strcmp(key, "cmd")) { + err = og_json_parse_string(value, &cmd); + if (err < 0) + return err; + } else if (!strcmp(key, "out")) { err = og_json_parse_string(value, &output); if (err < 0) return err; @@ -199,7 +203,9 @@ static int og_resp_shell_run(struct og_client *cli, json_t *data) return -1; } + free((void *)cli->shell.cmd); free((void *)cli->shell.output); + cli->shell.cmd = strdup(cmd); cli->shell.output = strdup(output); cli->shell.retcode = retcode; -- cgit v1.2.3-18-g5258