mirror of https://git.48k.eu/ogserver
#915 Fix create image payload parsing
Commit 141b0797e1
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.
master
parent
36f02324e0
commit
e16f36cdef
|
@ -88,6 +88,7 @@ struct og_msg_params {
|
|||
struct og_partition partition_setup[OG_PARTITION_MAX];
|
||||
struct og_sync_params sync_setup;
|
||||
struct og_schedule_time time;
|
||||
struct og_image image;
|
||||
const char *task_id;
|
||||
uint64_t flags;
|
||||
};
|
||||
|
|
22
src/rest.c
22
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, ¶ms->partition);
|
||||
params->flags |= OG_REST_PARAM_PARTITION;
|
||||
} else if (!strcmp(key, "name")) {
|
||||
err = og_json_parse_string(value, ¶ms->name);
|
||||
err = og_json_parse_string_copy(value,
|
||||
(char *)¶ms->image.name,
|
||||
sizeof(params->image.name));
|
||||
params->flags |= OG_REST_PARAM_NAME;
|
||||
} else if (!strcmp(key, "repository")) {
|
||||
err = og_json_parse_string(value, ¶ms->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 *)¶ms->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, ¶ms->image.group_id);
|
||||
} else if (!strcmp(key, "center_id")) {
|
||||
err = og_json_parse_uint64(value, &image.center_id);
|
||||
err = og_json_parse_uint64(value, ¶ms->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, ¶ms->image);
|
||||
|
||||
og_dbi_close(dbi);
|
||||
if (err < 0)
|
||||
|
|
Loading…
Reference in New Issue