summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAlejandro Sirgo Rica <asirgo@soleta.eu>2024-10-11 11:22:33 +0200
committerAlejandro Sirgo Rica <asirgo@soleta.eu>2024-10-11 12:17:28 +0200
commit65b397f59fd39b742c56a9be7da4b8bce8b88eb1 (patch)
treef145482eef2d4360d64984089d03ef7f862b7bd2 /src
parentca3503b716a9189a4cadd8e75cc701fe5dd00c9e (diff)
rest: fix GET /session payload structurev1.2.5-22
Split partition data by client instead of a single array with every partition. Old payload structure: { 'sessions': [{'disk': 1, 'partition': 1, 'name': 'unknown'}, {'disk': 1, 'partition': 2, 'name': 'unknown'}, {'disk': 1, 'partition': 1, 'name': 'Ubuntu 22.04.4 LTS 64 bits'}] } New payload structure: { 'sessions': [ {'addr': '1.1.1.1', 'partitions': ['disk': 1, 'partition': 1, 'name': 'Ubuntu 22.04.4 LTS 64 bits']}, {'addr': '1.1.1.2', 'partitions': [{'disk': 1, 'partition': 1, 'name': 'unknown'}, {'disk': 1, 'partition': 2, 'name': 'unknown'}]} ] }
Diffstat (limited to 'src')
-rw-r--r--src/rest.c24
1 files changed, 22 insertions, 2 deletions
diff --git a/src/rest.c b/src/rest.c
index dee85e1..a0997a1 100644
--- a/src/rest.c
+++ b/src/rest.c
@@ -954,7 +954,7 @@ static int og_json_os_array_get(struct og_dbi *dbi, json_t *array, const char *i
static int og_cmd_get_session(json_t *element, struct og_msg_params *params,
char *buffer_reply)
{
- json_t *value, *root, *array;
+ json_t *value, *root, *array, *client_data, *partitions;
struct og_dbi *dbi;
const char *key;
int err = 0, i;
@@ -992,11 +992,31 @@ static int og_cmd_get_session(json_t *element, struct og_msg_params *params,
}
for (i = 0; i < params->ips_array_len; i++) {
- if (og_json_os_array_get(dbi, array, params->ips_array[i]) < 0) {
+ client_data = json_object();
+ if (!client_data) {
json_decref(array);
og_dbi_close(dbi);
return -1;
}
+ json_object_set_new(client_data, "addr", json_string(params->ips_array[i]));
+
+ partitions = json_array();
+ if (!partitions) {
+ json_decref(client_data);
+ json_decref(array);
+ og_dbi_close(dbi);
+ return -1;
+ }
+
+ if (og_json_os_array_get(dbi, partitions, params->ips_array[i]) < 0) {
+ json_decref(partitions);
+ json_decref(client_data);
+ json_decref(array);
+ og_dbi_close(dbi);
+ return -1;
+ }
+ json_object_set_new(client_data, "partitions", partitions);
+ json_array_append_new(array, client_data);
}
og_dbi_close(dbi);