diff options
author | OpenGnSys Support Team <soporte-og@soleta.eu> | 2024-10-31 00:05:42 +0100 |
---|---|---|
committer | OpenGnSys Support Team <soporte-og@soleta.eu> | 2024-10-31 00:37:03 +0100 |
commit | 16cc22df3eec0acca53df3178be22f862bf9fa99 (patch) | |
tree | 6cf547f442a62d3cdf84a1d8e1051e16cd131497 | |
parent | 2febb50a92adb91e88825a7839c1f055c10ba6cf (diff) |
src: place last client command information in struct
just a preparation, no functional changes are intended.
-rw-r--r-- | src/client.c | 22 | ||||
-rw-r--r-- | src/rest.c | 8 | ||||
-rw-r--r-- | src/rest.h | 8 |
3 files changed, 20 insertions, 18 deletions
diff --git a/src/client.c b/src/client.c index d1288c4..b634251 100644 --- a/src/client.c +++ b/src/client.c @@ -1332,7 +1332,7 @@ static int og_clear_image_placeholder() int og_agent_state_process_response(struct og_client *cli) { - enum og_cmd_type cmd_type = cli->last_cmd; + enum og_cmd_type cmd_type = cli->last_cmd.type; int ret, err = -1, code; json_error_t json_err; bool success; @@ -1359,7 +1359,7 @@ int og_agent_state_process_response(struct og_client *cli) case 500: ret = 0; success = false; - cli->last_cmd = OG_CMD_UNSPEC; + cli->last_cmd.type = OG_CMD_UNSPEC; syslog(LOG_ERR, "Client %s:%hu reports failure to process command\n", inet_ntoa(cli->addr.sin_addr), ntohs(cli->addr.sin_port)); /* ... cancel pending actions related to this task for this client here */ @@ -1379,21 +1379,21 @@ int og_agent_state_process_response(struct og_client *cli) } if (success) - cli->last_cmd_result = OG_SUCCESS; + cli->last_cmd.result = OG_SUCCESS; else - cli->last_cmd_result = OG_FAILURE; + cli->last_cmd.result = OG_FAILURE; if (!success && cmd_type == OG_CMD_IMAGE_CREATE) og_clear_image_placeholder(); if (code != 200 && code != 103) { - cli->last_cmd_id = 0; + cli->last_cmd.id = 0; return ret; } if (!cli->content_length) { - cli->last_cmd_id = 0; - cli->last_cmd = OG_CMD_UNSPEC; + cli->last_cmd.id = 0; + cli->last_cmd.type = OG_CMD_UNSPEC; return 0; } @@ -1412,7 +1412,7 @@ int og_agent_state_process_response(struct og_client *cli) return err; } - switch (cli->last_cmd) { + switch (cli->last_cmd.type) { case OG_CMD_SHELL_RUN: err = og_resp_shell_run(cli, root); break; @@ -1452,12 +1452,12 @@ int og_agent_state_process_response(struct og_client *cli) if (err < 0) { err = 0; success = false; - cli->last_cmd_result = OG_FAILURE; + cli->last_cmd.result = OG_FAILURE; /* ... cancel pending actions related to this task for this client here */ } - cli->last_cmd_id = 0; - cli->last_cmd = OG_CMD_UNSPEC; + cli->last_cmd.id = 0; + cli->last_cmd.type = OG_CMD_UNSPEC; return err; } @@ -122,7 +122,7 @@ static struct og_client *og_client_find(const char *ip) static const char *og_client_status(const struct og_client *cli) { - switch (cli->last_cmd) { + switch (cli->last_cmd.type) { case OG_CMD_UNSPEC: break; default: @@ -244,7 +244,7 @@ static bool og_client_is_busy(const struct og_client *cli, case OG_CMD_STOP: break; default: - if (cli->last_cmd != OG_CMD_UNSPEC) + if (cli->last_cmd.type != OG_CMD_UNSPEC) return true; break; } @@ -319,7 +319,7 @@ int og_send_request(enum og_rest_method method, enum og_cmd_type type, if (send(client_sd, buf, strlen(buf), 0) < 0) continue; - cli->last_cmd = type; + cli->last_cmd.type = type; } json_decref((json_t *)data); @@ -396,7 +396,7 @@ static int og_json_client_append(json_t *array, struct og_client *client) } json_object_set_new(object, "state", state); json_object_set_new(object, "speed", json_integer(client->speed)); - last_cmd = og_json_client_cmd_result(client->last_cmd_result); + last_cmd = og_json_client_cmd_result(client->last_cmd.result); json_object_set_new(object, "last_cmd", last_cmd); json_array_append_new(array, object); @@ -66,9 +66,11 @@ struct og_client { int content_length; char auth_token[64]; enum og_client_status status; - enum og_cmd_type last_cmd; - unsigned int last_cmd_id; - enum og_cmd_result last_cmd_result; + struct { + enum og_cmd_type type; + unsigned int id; + enum og_cmd_result result; + } last_cmd; uint32_t speed; uint32_t seq; struct { |