diff options
author | Javier Sánchez Parra <jsanchez@soleta.eu> | 2020-09-09 11:27:45 +0200 |
---|---|---|
committer | OpenGnSys Support Team <soporte-og@soleta.eu> | 2020-09-10 14:48:26 +0200 |
commit | 0efc182c9ba71cb7a8afeeaea6593c52c35cc4ae (patch) | |
tree | 537c11d1c712a9ef10714b72a1642ec12fb545f0 | |
parent | a1aaad46fb480fd7bd3204d7e7f5ade15eb4d031 (diff) |
#1004 Handle new fields in /image/create response
ogClient now includes more information regarding the new image. This patch
modifies ogServer to support new elements sent in ogClient /image/create
response and store them in the database.
Example of new /image/create response:
{
"disk": "1",
"partition": "1",
"code": "131",
"id": "1",
"name": "ubuntu",
"repository": "192.168.56.10",
"software": "Ubuntu 18.04.5 LTS \naccountsservice 0.6.45\n...",
"clonator": "PARTCLONE",
"compressor": "LZOP",
"filesystem": "EXTFS",
"datasize": 2100000
}
New fields are "clonator", "compressor", "filesystem" and "datasize".
-rw-r--r-- | src/client.c | 51 | ||||
-rw-r--r-- | src/json.c | 9 | ||||
-rw-r--r-- | src/json.h | 1 |
3 files changed, 58 insertions, 3 deletions
diff --git a/src/client.c b/src/client.c index 60a84cb..0585a04 100644 --- a/src/client.c +++ b/src/client.c @@ -426,18 +426,47 @@ static int og_resp_refresh(json_t *data, struct og_client *cli) return 0; } +static int update_image_info(struct og_dbi *dbi, const char *image_id, + const char *clonator, const char *compressor, + const char *filesystem, const uint64_t datasize) +{ + const char *msglog; + dbi_result result; + + result = dbi_conn_queryf(dbi->conn, + "UPDATE imagenes" + " SET clonator='%s', compressor='%s'," + " filesystem='%s', datasize=%d" + " WHERE idimagen=%s", clonator, compressor, filesystem, + datasize, image_id); + + if (!result) { + dbi_conn_error(dbi->conn, &msglog); + syslog(LOG_ERR, "failed to query database (%s:%d) %s\n", + __func__, __LINE__, msglog); + return -1; + } + dbi_result_free(result); + + return 0; +} + static int og_resp_image_create(json_t *data, struct og_client *cli) { struct og_software_legacy soft_legacy; struct og_image_legacy img_legacy; + const char *compressor = NULL; + const char *filesystem = NULL; const char *partition = NULL; const char *software = NULL; const char *image_id = NULL; + const char *clonator = NULL; struct og_computer computer; const char *disk = NULL; const char *code = NULL; const char *name = NULL; const char *repo = NULL; + uint64_t datasize = 0; struct og_dbi *dbi; const char *key; json_t *value; @@ -462,6 +491,14 @@ static int og_resp_image_create(json_t *data, struct og_client *cli) err = og_json_parse_string(value, &name); else if (!strcmp(key, "repository")) err = og_json_parse_string(value, &repo); + else if (!strcmp(key, "clonator")) + err = og_json_parse_string(value, &clonator); + else if (!strcmp(key, "compressor")) + err = og_json_parse_string(value, &compressor); + else if (!strcmp(key, "filesystem")) + err = og_json_parse_string(value, &filesystem); + else if (!strcmp(key, "datasize")) + err = og_json_parse_uint64(value, &datasize); else return -1; @@ -470,7 +507,7 @@ static int og_resp_image_create(json_t *data, struct og_client *cli) } if (!software || !partition || !disk || !code || !image_id || !name || - !repo) { + !repo || !clonator || !compressor || !filesystem || !datasize) { syslog(LOG_ERR, "malformed response json\n"); return -1; } @@ -518,13 +555,21 @@ static int og_resp_image_create(json_t *data, struct og_client *cli) img_legacy.code, img_legacy.repo, soft_legacy.id); - og_dbi_close(dbi); - if (!res) { + og_dbi_close(dbi); syslog(LOG_ERR, "Problem updating client configuration\n"); return -1; } + res = update_image_info(dbi, image_id, clonator, compressor, + filesystem, datasize); + og_dbi_close(dbi); + + if (res) { + syslog(LOG_ERR, "Problem updating image info\n"); + return -1; + } + return 0; } @@ -18,6 +18,15 @@ int og_json_parse_string(json_t *element, const char **str) return 0; } +int og_json_parse_uint64(json_t *element, uint64_t *integer) +{ + if (json_typeof(element) != JSON_INTEGER) + return -1; + + *integer = json_integer_value(element); + return 0; +} + int og_json_parse_uint(json_t *element, uint32_t *integer) { if (json_typeof(element) != JSON_INTEGER) @@ -5,6 +5,7 @@ #include "schedule.h" int og_json_parse_string(json_t *element, const char **str); +int og_json_parse_uint64(json_t *element, uint64_t *integer); int og_json_parse_uint(json_t *element, uint32_t *integer); int og_json_parse_bool(json_t *element, bool *value); |