summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/rest.c49
1 files changed, 49 insertions, 0 deletions
diff --git a/src/rest.c b/src/rest.c
index 8f9c61e..c1161eb 100644
--- a/src/rest.c
+++ b/src/rest.c
@@ -5689,6 +5689,52 @@ static int og_cmd_post_server(json_t *element,
return ret;
}
+static int og_cmd_delete_server(json_t *element,
+ struct og_msg_params *params)
+{
+ const char *key, *msglog;
+ struct og_dbi *dbi;
+ dbi_result result;
+ json_t *value;
+ int err = 0;
+
+ json_object_foreach(element, key, value) {
+ if (!strcmp(key, "id")) {
+ err = og_json_parse_string(value, &params->id);
+ params->flags |= OG_REST_PARAM_ID;
+ }
+
+ if (err < 0)
+ return err;
+ }
+
+ if (!og_msg_params_validate(params, OG_REST_PARAM_ID))
+ return -1;
+
+ dbi = og_dbi_open(&ogconfig.db);
+ if (!dbi) {
+ syslog(LOG_ERR, "cannot open conection database (%s:%d)\n",
+ __func__, __LINE__);
+ return -1;
+ }
+
+ result = dbi_conn_queryf(dbi->conn,
+ "DELETE FROM entornos WHERE identorno='%s'",
+ params->id);
+
+ if (!result) {
+ dbi_conn_error(dbi->conn, &msglog);
+ syslog(LOG_ERR, "failed to delete server (%s:%d) %s\n",
+ __func__, __LINE__, msglog);
+ og_dbi_close(dbi);
+ return -1;
+ }
+
+ dbi_result_free(result);
+ og_dbi_close(dbi);
+ return 0;
+}
+
static int og_dbi_update_oglive(struct og_dbi *dbi, const char *mac,
const char * oglive)
{
@@ -6526,6 +6572,9 @@ int og_client_state_process_payload_rest(struct og_client *cli)
case OG_METHOD_GET:
err = og_cmd_get_servers(buf_reply);
break;
+ case OG_METHOD_DELETE:
+ err = og_cmd_delete_server(root, &params);
+ break;
case OG_METHOD_POST:
if (!root) {
syslog(LOG_ERR, "address add command with no payload\n");