mirror of https://git.48k.eu/ogserver
rest: add cache/fetch
Add POST cache/fetch request to request download of images in the client's cache. Resquest payload structure: { 'clients': ['10.141.10.21', '10.141.10.22'] 'image': 'windows.img' 'type': 'TIPTORRENT' 'repository': '12.141.10.2' } The clients listed in the 'clients' field will receive a cache/fetch POST request with the payload received by the server without the 'clients' field. The clients respond with the contents of their cache so the server can update the database.master v1.2.5-17
parent
6bc71b201d
commit
d383ff1c1a
|
@ -1110,6 +1110,9 @@ int og_agent_state_process_response(struct og_client *cli)
|
|||
case OG_CMD_CACHE_DELETE:
|
||||
err = og_resp_update_cache(root, cli);
|
||||
break;
|
||||
case OG_CMD_CACHE_FETCH:
|
||||
err = og_resp_update_cache(root, cli);
|
||||
break;
|
||||
default:
|
||||
err = -1;
|
||||
break;
|
||||
|
|
56
src/rest.c
56
src/rest.c
|
@ -270,6 +270,7 @@ static const char *og_cmd_to_uri[OG_CMD_MAX] = {
|
|||
[OG_CMD_RUN_SCHEDULE] = "run/schedule",
|
||||
[OG_CMD_IMAGES] = "images",
|
||||
[OG_CMD_CACHE_DELETE] = "cache/delete",
|
||||
[OG_CMD_CACHE_FETCH] = "cache/fetch",
|
||||
};
|
||||
|
||||
static bool og_client_is_busy(const struct og_client *cli,
|
||||
|
@ -4334,6 +4335,47 @@ static int og_cmd_cache_delete(json_t *element, struct og_msg_params *params,
|
|||
return og_send_request(OG_METHOD_POST, OG_CMD_CACHE_DELETE, params, body);
|
||||
}
|
||||
|
||||
static int og_cmd_cache_fetch(json_t *element, struct og_msg_params *params,
|
||||
char *buffer_reply)
|
||||
{
|
||||
json_t *value, *body, *image, *repository = NULL;
|
||||
const char *key;
|
||||
int err = 0;
|
||||
|
||||
if (json_typeof(element) != JSON_OBJECT)
|
||||
return -1;
|
||||
|
||||
json_object_foreach(element, key, value) {
|
||||
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;
|
||||
}
|
||||
|
||||
if (err < 0)
|
||||
return err;
|
||||
}
|
||||
|
||||
if (!og_msg_params_validate(params, OG_REST_PARAM_ADDR))
|
||||
return -1;
|
||||
|
||||
if (!image || !repository)
|
||||
return -1;
|
||||
|
||||
body = json_copy(element);
|
||||
json_object_del(body, "clients");
|
||||
|
||||
return og_send_request(OG_METHOD_POST, OG_CMD_CACHE_FETCH, params, body);
|
||||
}
|
||||
|
||||
static int og_cmd_setup(json_t *element, struct og_msg_params *params)
|
||||
{
|
||||
json_t *value, *clients;
|
||||
|
@ -8193,6 +8235,7 @@ struct {
|
|||
[OG_URI_IMAGE_RESTRICT] = { "image/restrict", },
|
||||
[OG_URI_CACHE_LIST] = { "cache/list", },
|
||||
[OG_URI_CACHE_DELETE] = { "cache/delete", },
|
||||
[OG_URI_CACHE_FETCH] = { "cache/fetch", },
|
||||
[OG_URI_PART_SETUP] = { "setup", },
|
||||
[OG_URI_RUN_SCHEDULE] = { "run/schedule", },
|
||||
[OG_URI_TASK_RUN] = { "task/run", },
|
||||
|
@ -8831,6 +8874,19 @@ int og_client_state_process_payload_rest(struct og_client *cli)
|
|||
goto err_process_rest_payload;
|
||||
}
|
||||
err = og_cmd_cache_delete(root, ¶ms, buf_reply);
|
||||
} else if (!strncmp(cmd, "cache/fetch", strlen("cache/fetch"))) {
|
||||
if (method != OG_METHOD_POST) {
|
||||
err = og_client_method_not_found(cli);
|
||||
goto err_process_rest_payload;
|
||||
}
|
||||
|
||||
if (!root) {
|
||||
syslog(LOG_ERR,
|
||||
"command cache fetch with no payload\n");
|
||||
err = og_client_bad_request(cli);
|
||||
goto err_process_rest_payload;
|
||||
}
|
||||
err = og_cmd_cache_fetch(root, ¶ms, buf_reply);
|
||||
} else if (!strncmp(cmd, "setup", strlen("setup"))) {
|
||||
if (method != OG_METHOD_POST) {
|
||||
err = og_client_method_not_found(cli);
|
||||
|
|
|
@ -42,6 +42,7 @@ enum og_cmd_type {
|
|||
OG_CMD_RUN_SCHEDULE,
|
||||
OG_CMD_IMAGES,
|
||||
OG_CMD_CACHE_DELETE,
|
||||
OG_CMD_CACHE_FETCH,
|
||||
OG_CMD_MAX
|
||||
};
|
||||
|
||||
|
@ -128,6 +129,7 @@ enum og_rest_uri {
|
|||
OG_URI_IMAGE_RESTRICT,
|
||||
OG_URI_CACHE_LIST,
|
||||
OG_URI_CACHE_DELETE,
|
||||
OG_URI_CACHE_FETCH,
|
||||
OG_URI_PART_SETUP,
|
||||
OG_URI_RUN_SCHEDULE,
|
||||
OG_URI_TASK_RUN,
|
||||
|
|
Loading…
Reference in New Issue