summaryrefslogtreecommitdiffstats
path: root/src/rest.c
diff options
context:
space:
mode:
authorJose M. Guisado <jguisado@soleta.eu>2021-10-19 07:54:35 +0000
committerJose M. Guisado <jguisado@soleta.eu>2021-10-19 07:54:35 +0000
commite16f36cdef55d6a2598e25144f583dfad0c9c793 (patch)
tree8d9d70e21c40a588ca7db4ef7025b56dc2189473 /src/rest.c
parent36f02324e05fc06ad9ce566c3b79c5d5bdfa0dd1 (diff)
#915 Fix create image payload parsing
Commit 141b0797e17f616d6 introduced command scheduling rest api to ogserver. Part of this changeset included og_json_parse_create_image as a utility funtion to parse the json payload of a "create image" command. og_json_parse_create_image did not include the parsing of optional parameters "description", "center_id" and "group_id". New components like ogCP or ogCLI use these parameters. Fix this by adding a struct og_image member to the struct og_msg_params and assigning it when processing a "create image" command. This could be extended to further payload parsing for image related commands in the future.
Diffstat (limited to 'src/rest.c')
-rw-r--r--src/rest.c22
1 files changed, 10 insertions, 12 deletions
diff --git a/src/rest.c b/src/rest.c
index bbe3f52..41f9b62 100644
--- a/src/rest.c
+++ b/src/rest.c
@@ -2044,9 +2044,8 @@ static int og_cmd_images(char *buffer_reply)
int og_json_parse_create_image(json_t *element,
struct og_msg_params *params)
{
- struct og_image image = {};
- json_t *value;
const char *key;
+ json_t *value;
int err = 0;
if (json_typeof(element) != JSON_OBJECT)
@@ -2060,7 +2059,9 @@ int og_json_parse_create_image(json_t *element,
err = og_json_parse_string(value, &params->partition);
params->flags |= OG_REST_PARAM_PARTITION;
} else if (!strcmp(key, "name")) {
- err = og_json_parse_string(value, &params->name);
+ err = og_json_parse_string_copy(value,
+ (char *)&params->image.name,
+ sizeof(params->image.name));
params->flags |= OG_REST_PARAM_NAME;
} else if (!strcmp(key, "repository")) {
err = og_json_parse_string(value, &params->repository);
@@ -2075,12 +2076,12 @@ int og_json_parse_create_image(json_t *element,
params->flags |= OG_REST_PARAM_CODE;
} else if (!strcmp(key, "description")) {
err = og_json_parse_string_copy(value,
- image.description,
- sizeof(image.description));
+ (char *)&params->image.description,
+ sizeof(params->image.description));
} else if (!strcmp(key, "group_id")) {
- err = og_json_parse_uint64(value, &image.group_id);
+ err = og_json_parse_uint64(value, &params->image.group_id);
} else if (!strcmp(key, "center_id")) {
- err = og_json_parse_uint64(value, &image.center_id);
+ err = og_json_parse_uint64(value, &params->image.center_id);
}
if (err < 0)
@@ -2093,7 +2094,6 @@ int og_json_parse_create_image(json_t *element,
static int og_cmd_create_image(json_t *element, struct og_msg_params *params)
{
char new_image_id[OG_DB_INT_MAXLEN + 1];
- struct og_image image = {};
struct og_dbi *dbi;
json_t *clients;
int err = 0;
@@ -2112,9 +2112,7 @@ static int og_cmd_create_image(json_t *element, struct og_msg_params *params)
return -1;
/* If there is a description, this means the image is not in the DB. */
- if (image.description[0]) {
- snprintf(image.name, sizeof(image.name), "%s", params->name);
-
+ if (params->image.description[0]) {
dbi = og_dbi_open(&ogconfig.db);
if (!dbi) {
syslog(LOG_ERR,
@@ -2123,7 +2121,7 @@ static int og_cmd_create_image(json_t *element, struct og_msg_params *params)
return -1;
}
- err = og_dbi_add_image(dbi, &image);
+ err = og_dbi_add_image(dbi, &params->image);
og_dbi_close(dbi);
if (err < 0)