summaryrefslogtreecommitdiffstats
path: root/src/rest.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/rest.c')
-rw-r--r--src/rest.c51
1 files changed, 51 insertions, 0 deletions
diff --git a/src/rest.c b/src/rest.c
index bdb2f01..4b85701 100644
--- a/src/rest.c
+++ b/src/rest.c
@@ -269,6 +269,7 @@ static const char *og_cmd_to_uri[OG_CMD_MAX] = {
[OG_CMD_SETUP] = "setup",
[OG_CMD_RUN_SCHEDULE] = "run/schedule",
[OG_CMD_IMAGES] = "images",
+ [OG_CMD_CACHE_DELETE] = "cache/delete",
};
static bool og_client_is_busy(const struct og_client *cli,
@@ -3605,6 +3606,42 @@ static int og_cmd_cache_list(json_t *element, struct og_msg_params *params,
return 0;
}
+static int og_cmd_cache_delete(json_t *element, struct og_msg_params *params,
+ char *buffer_reply)
+{
+ json_t *value, *body, *image_arr = 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, "images")) {
+ if (json_typeof(value) != JSON_ARRAY) {
+ err = -1;
+ }
+ image_arr = value;
+ }
+
+ if (err < 0)
+ return err;
+ }
+
+ if (!og_msg_params_validate(params, OG_REST_PARAM_ADDR))
+ return -1;
+
+ if (!image_arr)
+ return -1;
+
+ body = json_copy(element);
+ json_object_del(body, "clients");
+
+ return og_send_request(OG_METHOD_POST, OG_CMD_CACHE_DELETE, params, body);
+}
+
static int og_cmd_setup(json_t *element, struct og_msg_params *params)
{
json_t *value, *clients;
@@ -7460,6 +7497,7 @@ struct {
[OG_URI_IMAGE_RESTORE] = { "image/restore", },
[OG_URI_IMAGE_DELETE] = { "image/delete", },
[OG_URI_CACHE_LIST] = { "cache/list", },
+ [OG_URI_CACHE_DELETE] = { "cache/delete", },
[OG_URI_PART_SETUP] = { "setup", },
[OG_URI_RUN_SCHEDULE] = { "run/schedule", },
[OG_URI_TASK_RUN] = { "task/run", },
@@ -8045,6 +8083,19 @@ int og_client_state_process_payload_rest(struct og_client *cli)
goto err_process_rest_payload;
}
err = og_cmd_cache_list(root, &params, buf_reply);
+ } else if (!strncmp(cmd, "cache/delete", strlen("cache/delete"))) {
+ if (method != OG_METHOD_POST) {
+ err = og_client_method_not_found(cli);
+ goto err_process_rest_payload;
+ }
+
+ if (!root) {
+ syslog(LOG_ERR,
+ "command cache list with no payload\n");
+ err = og_client_bad_request(cli);
+ goto err_process_rest_payload;
+ }
+ err = og_cmd_cache_delete(root, &params, buf_reply);
} else if (!strncmp(cmd, "setup", strlen("setup"))) {
if (method != OG_METHOD_POST) {
err = og_client_method_not_found(cli);