summaryrefslogtreecommitdiffstats
path: root/src/rest.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/rest.c')
-rw-r--r--src/rest.c37
1 files changed, 25 insertions, 12 deletions
diff --git a/src/rest.c b/src/rest.c
index 1a243e4..f4b5918 100644
--- a/src/rest.c
+++ b/src/rest.c
@@ -4377,7 +4377,10 @@ static int og_cmd_cache_delete(json_t *element, struct og_msg_params *params,
static int og_cmd_cache_fetch(json_t *element, struct og_msg_params *params,
char *buffer_reply)
{
- json_t *value, *body, *image, *repository = NULL;
+ char repository_ip[OG_DB_IP_MAXLEN + 1] = {};
+ json_t *value, *body;
+ struct og_dbi *dbi;
+
const char *key;
int err = 0;
@@ -4388,29 +4391,39 @@ static int og_cmd_cache_fetch(json_t *element, struct og_msg_params *params,
if (!strcmp(key, "clients")) {
err = og_json_parse_clients(value, params);
} else if (!strcmp(key, "image")) {
- if (json_typeof(value) != JSON_STRING) {
- err = -1;
- }
- image = value;
- } else if (!strcmp(key, "repository")) {
- if (json_typeof(value) != JSON_STRING) {
- err = -1;
- }
- repository = value;
+ err = og_json_parse_string(value, &params->name);
+ params->flags |= OG_REST_PARAM_NAME;
+ } else if (!strcmp(key, "repository_id")) {
+ err = og_json_parse_uint64(value, &params->image.repo_id);
+ params->flags |= OG_REST_PARAM_REPO;
}
if (err < 0)
return err;
}
- if (!og_msg_params_validate(params, OG_REST_PARAM_ADDR))
+ if (!og_msg_params_validate(params, OG_REST_PARAM_NAME |
+ OG_REST_PARAM_ADDR |
+ OG_REST_PARAM_REPO))
return -1;
- if (!image || !repository)
+ dbi = og_dbi_open(&ogconfig.db);
+ if (!dbi) {
+ syslog(LOG_ERR,
+ "cannot open connection database (%s:%d)\n",
+ __func__, __LINE__);
return -1;
+ }
+
+ err = og_dbi_get_repository_ip(dbi, params->image.repo_id,
+ params->ips_array[0], repository_ip);
+ og_dbi_close(dbi);
+ if (err < 0)
+ return err;
body = json_copy(element);
json_object_del(body, "clients");
+ json_object_set_new(body, "repository", json_string(repository_ip));
return og_send_request(OG_METHOD_POST, OG_CMD_CACHE_FETCH, params, body);
}