summaryrefslogtreecommitdiffstats
path: root/src/rest.c
diff options
context:
space:
mode:
authorOpenGnSys Support Team <soporte-og@soleta.eu>2023-11-30 20:06:07 +0100
committerOpenGnSys Support Team <soporte-og@soleta.eu>2023-11-30 20:20:07 +0100
commitedac32bb986e8dab23a14a79317c2109bc523270 (patch)
tree61354e3e6106ea9f28cf75d3c09e456376c4c213 /src/rest.c
parent1ce56240323c21e3e3251dfd6173cb45ae959574 (diff)
rest: add GET /room/info
Add GET /room/info to obtain room information, this includes the name, gateway and netmask. curl -X GET -H "Authorization: $API_KEY" http://127.0.0.1:8888/room/info -d '{ "id" : 1 }
Diffstat (limited to 'src/rest.c')
-rw-r--r--src/rest.c75
1 files changed, 75 insertions, 0 deletions
diff --git a/src/rest.c b/src/rest.c
index f177e4c..bd28b67 100644
--- a/src/rest.c
+++ b/src/rest.c
@@ -2038,6 +2038,67 @@ static int og_cmd_post_client_delete(json_t *element,
return 0;
}
+static int og_cmd_get_room_info(json_t *element,
+ struct og_msg_params *params,
+ char *buffer_reply)
+{
+ struct og_room room = {};
+ json_t *value, *root;
+ struct og_dbi *dbi;
+ uint32_t room_id;
+ const char *key;
+ int err = 0;
+
+ struct og_buffer og_buffer = {
+ .data = buffer_reply
+ };
+
+ json_object_foreach(element, key, value) {
+ if (!strcmp(key, "id")) {
+ err = og_json_parse_uint(value, &room_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;
+ }
+
+ if (og_dbi_get_room_info(dbi, &room, room_id)) {
+ og_dbi_close(dbi);
+ return -1;
+ }
+
+ og_dbi_close(dbi);
+
+ root = json_object();
+ if (!root)
+ return -1;
+
+ json_object_set_new(root, "id", json_integer(room.id));
+ json_object_set_new(root, "name", json_string(room.name));
+ json_object_set_new(root, "gateway", json_string(room.gateway));
+ json_object_set_new(root, "netmask", json_string(room.netmask));
+
+ if (json_dump_callback(root, og_json_dump_clients, &og_buffer, 0)) {
+ json_decref(root);
+ return -1;
+ }
+
+ json_decref(root);
+ return 0;
+}
+
+
static int og_cmd_stop(json_t *element, struct og_msg_params *params)
{
const char *key;
@@ -6516,6 +6577,7 @@ struct {
[OG_URI_CENTER_DELETE] = { "center/delete", },
[OG_URI_ROOM_ADD] = { "room/add", },
[OG_URI_ROOM_DELETE] = { "room/delete", },
+ [OG_URI_ROOM_INFO] = { "room/info", },
[OG_URI_PROC_ADD] = { "procedure/add", },
[OG_URI_PROC_UPDATE] = { "procedure/update", },
[OG_URI_PROC_RUN] = { "procedure/run", },
@@ -7164,6 +7226,19 @@ int og_client_state_process_payload_rest(struct og_client *cli)
goto err_process_rest_payload;
}
err = og_cmd_post_room_delete(root, &params);
+ } else if (!strncmp(cmd, "room/info", strlen("room/info"))) {
+ if (method != OG_METHOD_GET) {
+ err = og_client_method_not_found(cli);
+ goto err_process_rest_payload;
+ }
+ if (!root) {
+ syslog(LOG_ERR,
+ "command room info with no payload\n");
+ err = og_client_bad_request(cli);
+ goto err_process_rest_payload;
+ }
+
+ err = og_cmd_get_room_info(root, &params, buf_reply);
} else if (!strncmp(cmd, "procedure/add", strlen("procedure/add"))) {
if (method != OG_METHOD_POST) {
err = og_client_method_not_found(cli);