summaryrefslogtreecommitdiffstats
path: root/src/rest.c
diff options
context:
space:
mode:
authorOpenGnSys Support Team <soporte-og@soleta.eu>2020-08-14 12:37:36 +0200
committerOpenGnSys Support Team <soporte-og@soleta.eu>2020-08-14 12:48:21 +0200
commitca545d39bd68d156a0dddbab204e743202dbfba3 (patch)
tree59c1f02c30eb18237c3602d64fe8acee30fd94d0 /src/rest.c
parent060e31cb53386282f1995937c18fe39855865046 (diff)
#998 disable incremental image API
This API is not supported by ogClient yet and it uses the obsolete socket hydra API.
Diffstat (limited to 'src/rest.c')
-rw-r--r--src/rest.c473
1 files changed, 0 insertions, 473 deletions
diff --git a/src/rest.c b/src/rest.c
index 2256788..e9b09cd 100644
--- a/src/rest.c
+++ b/src/rest.c
@@ -29,49 +29,6 @@
struct ev_loop *og_loop;
-static TRAMA *og_msg_alloc(char *data, unsigned int len)
-{
- TRAMA *ptrTrama;
-
- ptrTrama = calloc(1, sizeof(TRAMA));
- if (!ptrTrama) {
- syslog(LOG_ERR, "OOM\n");
- return NULL;
- }
-
- initParametros(ptrTrama, len);
- memcpy(ptrTrama, "@JMMLCAMDJ_MCDJ", LONGITUD_CABECERATRAMA);
- memcpy(ptrTrama->parametros, data, len);
- ptrTrama->lonprm = len;
-
- return ptrTrama;
-}
-
-static void og_msg_free(TRAMA *ptrTrama)
-{
- free(ptrTrama->parametros);
- free(ptrTrama);
-}
-
-static bool og_send_cmd(char *ips_array[], int ips_array_len,
- const char *state, TRAMA *ptrTrama)
-{
- int i, idx;
-
- for (i = 0; i < ips_array_len; i++) {
- if (clienteDisponible(ips_array[i], &idx)) { // Si el cliente puede recibir comandos
- int sock = tbsockets[idx].cli ? tbsockets[idx].cli->io.fd : -1;
-
- strcpy(tbsockets[idx].estado, state); // Actualiza el estado del cliente
- if (sock >= 0 && !mandaTrama(&sock, ptrTrama)) {
- syslog(LOG_ERR, "failed to send response to %s:%s\n",
- ips_array[i], strerror(errno));
- }
- }
- }
- return true;
-}
-
#define OG_REST_PARAM_ADDR (1UL << 0)
#define OG_REST_PARAM_MAC (1UL << 1)
#define OG_REST_PARAM_WOL_TYPE (1UL << 2)
@@ -195,58 +152,6 @@ static int og_json_parse_clients(json_t *element, struct og_msg_params *params)
return 0;
}
-static int og_json_parse_sync_params(json_t *element,
- struct og_msg_params *params)
-{
- const char *key;
- json_t *value;
- int err = 0;
-
- json_object_foreach(element, key, value) {
- if (!strcmp(key, "sync")) {
- err = og_json_parse_string(value, &params->sync_setup.sync);
- params->flags |= OG_REST_PARAM_SYNC_SYNC;
- } else if (!strcmp(key, "diff")) {
- err = og_json_parse_string(value, &params->sync_setup.diff);
- params->flags |= OG_REST_PARAM_SYNC_DIFF;
- } else if (!strcmp(key, "remove")) {
- err = og_json_parse_string(value, &params->sync_setup.remove);
- params->flags |= OG_REST_PARAM_SYNC_REMOVE;
- } else if (!strcmp(key, "compress")) {
- err = og_json_parse_string(value, &params->sync_setup.compress);
- params->flags |= OG_REST_PARAM_SYNC_COMPRESS;
- } else if (!strcmp(key, "cleanup")) {
- err = og_json_parse_string(value, &params->sync_setup.cleanup);
- params->flags |= OG_REST_PARAM_SYNC_CLEANUP;
- } else if (!strcmp(key, "cache")) {
- err = og_json_parse_string(value, &params->sync_setup.cache);
- params->flags |= OG_REST_PARAM_SYNC_CACHE;
- } else if (!strcmp(key, "cleanup_cache")) {
- err = og_json_parse_string(value, &params->sync_setup.cleanup_cache);
- params->flags |= OG_REST_PARAM_SYNC_CLEANUP_CACHE;
- } else if (!strcmp(key, "remove_dst")) {
- err = og_json_parse_string(value, &params->sync_setup.remove_dst);
- params->flags |= OG_REST_PARAM_SYNC_REMOVE_DST;
- } else if (!strcmp(key, "diff_id")) {
- err = og_json_parse_string(value, &params->sync_setup.diff_id);
- params->flags |= OG_REST_PARAM_SYNC_DIFF_ID;
- } else if (!strcmp(key, "diff_name")) {
- err = og_json_parse_string(value, &params->sync_setup.diff_name);
- params->flags |= OG_REST_PARAM_SYNC_DIFF_NAME;
- } else if (!strcmp(key, "path")) {
- err = og_json_parse_string(value, &params->sync_setup.path);
- params->flags |= OG_REST_PARAM_SYNC_PATH;
- } else if (!strcmp(key, "method")) {
- err = og_json_parse_string(value, &params->sync_setup.method);
- params->flags |= OG_REST_PARAM_SYNC_METHOD;
- }
-
- if (err != 0)
- return err;
- }
- return err;
-}
-
static int og_json_parse_partition_setup(json_t *element,
struct og_msg_params *params)
{
@@ -1456,344 +1361,6 @@ static int og_cmd_run_schedule(json_t *element, struct og_msg_params *params)
NULL);
}
-static int og_cmd_create_basic_image(json_t *element, struct og_msg_params *params)
-{
- char buf[4096] = {};
- int err = 0, len;
- const char *key;
- json_t *value;
- TRAMA *msg;
-
- 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, "disk")) {
- err = og_json_parse_string(value, &params->disk);
- params->flags |= OG_REST_PARAM_DISK;
- } else if (!strcmp(key, "partition")) {
- err = og_json_parse_string(value, &params->partition);
- params->flags |= OG_REST_PARAM_PARTITION;
- } else if (!strcmp(key, "code")) {
- err = og_json_parse_string(value, &params->code);
- params->flags |= OG_REST_PARAM_CODE;
- } else if (!strcmp(key, "id")) {
- err = og_json_parse_string(value, &params->id);
- params->flags |= OG_REST_PARAM_ID;
- } else if (!strcmp(key, "name")) {
- err = og_json_parse_string(value, &params->name);
- params->flags |= OG_REST_PARAM_NAME;
- } else if (!strcmp(key, "repository")) {
- err = og_json_parse_string(value, &params->repository);
- params->flags |= OG_REST_PARAM_REPO;
- } else if (!strcmp(key, "sync_params")) {
- err = og_json_parse_sync_params(value, params);
- }
-
- if (err < 0)
- break;
- }
-
- if (!og_msg_params_validate(params, OG_REST_PARAM_ADDR |
- OG_REST_PARAM_DISK |
- OG_REST_PARAM_PARTITION |
- OG_REST_PARAM_CODE |
- OG_REST_PARAM_ID |
- OG_REST_PARAM_NAME |
- OG_REST_PARAM_REPO |
- OG_REST_PARAM_SYNC_SYNC |
- OG_REST_PARAM_SYNC_DIFF |
- OG_REST_PARAM_SYNC_REMOVE |
- OG_REST_PARAM_SYNC_COMPRESS |
- OG_REST_PARAM_SYNC_CLEANUP |
- OG_REST_PARAM_SYNC_CACHE |
- OG_REST_PARAM_SYNC_CLEANUP_CACHE |
- OG_REST_PARAM_SYNC_REMOVE_DST))
- return -1;
-
- len = snprintf(buf, sizeof(buf),
- "nfn=CrearImagenBasica\rdsk=%s\rpar=%s\rcpt=%s\ridi=%s\r"
- "nci=%s\ripr=%s\rrti=\rmsy=%s\rwhl=%s\reli=%s\rcmp=%s\rbpi=%s\r"
- "cpc=%s\rbpc=%s\rnba=%s\r",
- params->disk, params->partition, params->code, params->id,
- params->name, params->repository, params->sync_setup.sync,
- params->sync_setup.diff, params->sync_setup.remove,
- params->sync_setup.compress, params->sync_setup.cleanup,
- params->sync_setup.cache, params->sync_setup.cleanup_cache,
- params->sync_setup.remove_dst);
-
- msg = og_msg_alloc(buf, len);
- if (!msg)
- return -1;
-
- og_send_cmd((char **)params->ips_array, params->ips_array_len,
- CLIENTE_OCUPADO, msg);
-
- og_msg_free(msg);
-
- return 0;
-}
-
-static int og_cmd_create_incremental_image(json_t *element, struct og_msg_params *params)
-{
- char buf[4096] = {};
- int err = 0, len;
- const char *key;
- json_t *value;
- TRAMA *msg;
-
- 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, "disk")) {
- err = og_json_parse_string(value, &params->disk);
- params->flags |= OG_REST_PARAM_DISK;
- } else if (!strcmp(key, "partition")) {
- err = og_json_parse_string(value, &params->partition);
- params->flags |= OG_REST_PARAM_PARTITION;
- } else if (!strcmp(key, "id")) {
- err = og_json_parse_string(value, &params->id);
- params->flags |= OG_REST_PARAM_ID;
- } else if (!strcmp(key, "name")) {
- err = og_json_parse_string(value, &params->name);
- params->flags |= OG_REST_PARAM_NAME;
- } else if (!strcmp(key, "repository")) {
- err = og_json_parse_string(value, &params->repository);
- params->flags |= OG_REST_PARAM_REPO;
- } else if (!strcmp(key, "sync_params")) {
- err = og_json_parse_sync_params(value, params);
- }
-
- if (err < 0)
- break;
- }
-
- if (!og_msg_params_validate(params, OG_REST_PARAM_ADDR |
- OG_REST_PARAM_DISK |
- OG_REST_PARAM_PARTITION |
- OG_REST_PARAM_ID |
- OG_REST_PARAM_NAME |
- OG_REST_PARAM_REPO |
- OG_REST_PARAM_SYNC_SYNC |
- OG_REST_PARAM_SYNC_PATH |
- OG_REST_PARAM_SYNC_DIFF |
- OG_REST_PARAM_SYNC_DIFF_ID |
- OG_REST_PARAM_SYNC_DIFF_NAME |
- OG_REST_PARAM_SYNC_REMOVE |
- OG_REST_PARAM_SYNC_COMPRESS |
- OG_REST_PARAM_SYNC_CLEANUP |
- OG_REST_PARAM_SYNC_CACHE |
- OG_REST_PARAM_SYNC_CLEANUP_CACHE |
- OG_REST_PARAM_SYNC_REMOVE_DST))
- return -1;
-
- len = snprintf(buf, sizeof(buf),
- "nfn=CrearSoftIncremental\rdsk=%s\rpar=%s\ridi=%s\rnci=%s\r"
- "rti=%s\ripr=%s\ridf=%s\rncf=%s\rmsy=%s\rwhl=%s\reli=%s\rcmp=%s\r"
- "bpi=%s\rcpc=%s\rbpc=%s\rnba=%s\r",
- params->disk, params->partition, params->id, params->name,
- params->sync_setup.path, params->repository, params->sync_setup.diff_id,
- params->sync_setup.diff_name, params->sync_setup.sync,
- params->sync_setup.diff, params->sync_setup.remove_dst,
- params->sync_setup.compress, params->sync_setup.cleanup,
- params->sync_setup.cache, params->sync_setup.cleanup_cache,
- params->sync_setup.remove_dst);
-
- msg = og_msg_alloc(buf, len);
- if (!msg)
- return -1;
-
- og_send_cmd((char **)params->ips_array, params->ips_array_len,
- CLIENTE_OCUPADO, msg);
-
- og_msg_free(msg);
-
- return 0;
-}
-
-static int og_cmd_restore_basic_image(json_t *element, struct og_msg_params *params)
-{
- char buf[4096] = {};
- int err = 0, len;
- const char *key;
- json_t *value;
- TRAMA *msg;
-
- 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, "disk")) {
- err = og_json_parse_string(value, &params->disk);
- params->flags |= OG_REST_PARAM_DISK;
- } else if (!strcmp(key, "partition")) {
- err = og_json_parse_string(value, &params->partition);
- params->flags |= OG_REST_PARAM_PARTITION;
- } else if (!strcmp(key, "id")) {
- err = og_json_parse_string(value, &params->id);
- params->flags |= OG_REST_PARAM_ID;
- } else if (!strcmp(key, "name")) {
- err = og_json_parse_string(value, &params->name);
- params->flags |= OG_REST_PARAM_NAME;
- } else if (!strcmp(key, "repository")) {
- err = og_json_parse_string(value, &params->repository);
- params->flags |= OG_REST_PARAM_REPO;
- } else if (!strcmp(key, "profile")) {
- err = og_json_parse_string(value, &params->profile);
- params->flags |= OG_REST_PARAM_PROFILE;
- } else if (!strcmp(key, "type")) {
- err = og_json_parse_string(value, &params->type);
- params->flags |= OG_REST_PARAM_TYPE;
- } else if (!strcmp(key, "sync_params")) {
- err = og_json_parse_sync_params(value, params);
- }
-
- if (err < 0)
- break;
- }
-
- if (!og_msg_params_validate(params, OG_REST_PARAM_ADDR |
- OG_REST_PARAM_DISK |
- OG_REST_PARAM_PARTITION |
- OG_REST_PARAM_ID |
- OG_REST_PARAM_NAME |
- OG_REST_PARAM_REPO |
- OG_REST_PARAM_PROFILE |
- OG_REST_PARAM_TYPE |
- OG_REST_PARAM_SYNC_PATH |
- OG_REST_PARAM_SYNC_METHOD |
- OG_REST_PARAM_SYNC_SYNC |
- OG_REST_PARAM_SYNC_DIFF |
- OG_REST_PARAM_SYNC_REMOVE |
- OG_REST_PARAM_SYNC_COMPRESS |
- OG_REST_PARAM_SYNC_CLEANUP |
- OG_REST_PARAM_SYNC_CACHE |
- OG_REST_PARAM_SYNC_CLEANUP_CACHE |
- OG_REST_PARAM_SYNC_REMOVE_DST))
- return -1;
-
- len = snprintf(buf, sizeof(buf),
- "nfn=RestaurarImagenBasica\rdsk=%s\rpar=%s\ridi=%s\rnci=%s\r"
- "ipr=%s\rifs=%s\rrti=%s\rmet=%s\rmsy=%s\rtpt=%s\rwhl=%s\r"
- "eli=%s\rcmp=%s\rbpi=%s\rcpc=%s\rbpc=%s\rnba=%s\r",
- params->disk, params->partition, params->id, params->name,
- params->repository, params->profile, params->sync_setup.path,
- params->sync_setup.method, params->sync_setup.sync, params->type,
- params->sync_setup.diff, params->sync_setup.remove,
- params->sync_setup.compress, params->sync_setup.cleanup,
- params->sync_setup.cache, params->sync_setup.cleanup_cache,
- params->sync_setup.remove_dst);
-
- msg = og_msg_alloc(buf, len);
- if (!msg)
- return -1;
-
- og_send_cmd((char **)params->ips_array, params->ips_array_len,
- CLIENTE_OCUPADO, msg);
-
- og_msg_free(msg);
-
- return 0;
-}
-
-static int og_cmd_restore_incremental_image(json_t *element, struct og_msg_params *params)
-{
- char buf[4096] = {};
- int err = 0, len;
- const char *key;
- json_t *value;
- TRAMA *msg;
-
- 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, "disk")) {
- err = og_json_parse_string(value, &params->disk);
- params->flags |= OG_REST_PARAM_DISK;
- } else if (!strcmp(key, "partition")) {
- err = og_json_parse_string(value, &params->partition);
- params->flags |= OG_REST_PARAM_PARTITION;
- } else if (!strcmp(key, "id")) {
- err = og_json_parse_string(value, &params->id);
- params->flags |= OG_REST_PARAM_ID;
- } else if (!strcmp(key, "name")) {
- err = og_json_parse_string(value, &params->name);
- params->flags |= OG_REST_PARAM_NAME;
- } else if (!strcmp(key, "repository")) {
- err = og_json_parse_string(value, &params->repository);
- params->flags |= OG_REST_PARAM_REPO;
- } else if (!strcmp(key, "profile")) {
- err = og_json_parse_string(value, &params->profile);
- params->flags |= OG_REST_PARAM_PROFILE;
- } else if (!strcmp(key, "type")) {
- err = og_json_parse_string(value, &params->type);
- params->flags |= OG_REST_PARAM_TYPE;
- } else if (!strcmp(key, "sync_params")) {
- err = og_json_parse_sync_params(value, params);
- }
-
- if (err < 0)
- break;
- }
-
- if (!og_msg_params_validate(params, OG_REST_PARAM_ADDR |
- OG_REST_PARAM_DISK |
- OG_REST_PARAM_PARTITION |
- OG_REST_PARAM_ID |
- OG_REST_PARAM_NAME |
- OG_REST_PARAM_REPO |
- OG_REST_PARAM_PROFILE |
- OG_REST_PARAM_TYPE |
- OG_REST_PARAM_SYNC_DIFF_ID |
- OG_REST_PARAM_SYNC_DIFF_NAME |
- OG_REST_PARAM_SYNC_PATH |
- OG_REST_PARAM_SYNC_METHOD |
- OG_REST_PARAM_SYNC_SYNC |
- OG_REST_PARAM_SYNC_DIFF |
- OG_REST_PARAM_SYNC_REMOVE |
- OG_REST_PARAM_SYNC_COMPRESS |
- OG_REST_PARAM_SYNC_CLEANUP |
- OG_REST_PARAM_SYNC_CACHE |
- OG_REST_PARAM_SYNC_CLEANUP_CACHE |
- OG_REST_PARAM_SYNC_REMOVE_DST))
- return -1;
-
- len = snprintf(buf, sizeof(buf),
- "nfn=RestaurarSoftIncremental\rdsk=%s\rpar=%s\ridi=%s\rnci=%s\r"
- "ipr=%s\rifs=%s\ridf=%s\rncf=%s\rrti=%s\rmet=%s\rmsy=%s\r"
- "tpt=%s\rwhl=%s\reli=%s\rcmp=%s\rbpi=%s\rcpc=%s\rbpc=%s\r"
- "nba=%s\r",
- params->disk, params->partition, params->id, params->name,
- params->repository, params->profile, params->sync_setup.diff_id,
- params->sync_setup.diff_name, params->sync_setup.path,
- params->sync_setup.method, params->sync_setup.sync, params->type,
- params->sync_setup.diff, params->sync_setup.remove,
- params->sync_setup.compress, params->sync_setup.cleanup,
- params->sync_setup.cache, params->sync_setup.cleanup_cache,
- params->sync_setup.remove_dst);
-
- msg = og_msg_alloc(buf, len);
- if (!msg)
- return -1;
-
- og_send_cmd((char **)params->ips_array, params->ips_array_len,
- CLIENTE_OCUPADO, msg);
-
- og_msg_free(msg);
-
- return 0;
-}
-
static LIST_HEAD(cmd_list);
const struct og_cmd *og_cmd_find(const char *client_ip)
@@ -3542,26 +3109,6 @@ int og_client_state_process_payload_rest(struct og_client *cli)
return og_client_bad_request(cli);
}
err = og_cmd_software(root, &params);
- } else if (!strncmp(cmd, "image/create/basic",
- strlen("image/create/basic"))) {
- if (method != OG_METHOD_POST)
- return og_client_method_not_found(cli);
-
- if (!root) {
- syslog(LOG_ERR, "command create with no payload\n");
- return og_client_bad_request(cli);
- }
- err = og_cmd_create_basic_image(root, &params);
- } else if (!strncmp(cmd, "image/create/incremental",
- strlen("image/create/incremental"))) {
- if (method != OG_METHOD_POST)
- return og_client_method_not_found(cli);
-
- if (!root) {
- syslog(LOG_ERR, "command create with no payload\n");
- return og_client_bad_request(cli);
- }
- err = og_cmd_create_incremental_image(root, &params);
} else if (!strncmp(cmd, "image/create", strlen("image/create"))) {
if (method != OG_METHOD_POST)
return og_client_method_not_found(cli);
@@ -3571,26 +3118,6 @@ int og_client_state_process_payload_rest(struct og_client *cli)
return og_client_bad_request(cli);
}
err = og_cmd_create_image(root, &params);
- } else if (!strncmp(cmd, "image/restore/basic",
- strlen("image/restore/basic"))) {
- if (method != OG_METHOD_POST)
- return og_client_method_not_found(cli);
-
- if (!root) {
- syslog(LOG_ERR, "command create with no payload\n");
- return og_client_bad_request(cli);
- }
- err = og_cmd_restore_basic_image(root, &params);
- } else if (!strncmp(cmd, "image/restore/incremental",
- strlen("image/restore/incremental"))) {
- if (method != OG_METHOD_POST)
- return og_client_method_not_found(cli);
-
- if (!root) {
- syslog(LOG_ERR, "command create with no payload\n");
- return og_client_bad_request(cli);
- }
- err = og_cmd_restore_incremental_image(root, &params);
} else if (!strncmp(cmd, "image/restore", strlen("image/restore"))) {
if (method != OG_METHOD_POST)
return og_client_method_not_found(cli);