summaryrefslogtreecommitdiffstats
path: root/src/dbi.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/dbi.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/dbi.c')
-rw-r--r--src/dbi.c37
1 files changed, 37 insertions, 0 deletions
diff --git a/src/dbi.c b/src/dbi.c
index 7c7a5d0..ba4c113 100644
--- a/src/dbi.c
+++ b/src/dbi.c
@@ -129,6 +129,43 @@ int og_dbi_get_computer_info(struct og_dbi *dbi, struct og_computer *computer,
return 0;
}
+int og_dbi_get_room_info(struct og_dbi *dbi, struct og_room *room,
+ uint32_t room_id)
+{
+ const char *msglog;
+ dbi_result result;
+
+ result = dbi_conn_queryf(dbi->conn,
+ "SELECT nombreaula, router, netmask "
+ "FROM aulas WHERE idaula=%d AND grupoid=0",
+ room_id);
+ if (!result) {
+ dbi_conn_error(dbi->conn, &msglog);
+ syslog(LOG_ERR, "failed to query database (%s:%d) %s\n",
+ __func__, __LINE__, msglog);
+ return -1;
+ }
+
+ if (!dbi_result_next_row(result)) {
+ syslog(LOG_ERR, "room does not exist in database (%s:%d)\n",
+ __func__, __LINE__);
+ dbi_result_free(result);
+ return -1;
+ }
+
+ room->id = room_id;
+ snprintf(room->name, sizeof(room->name), "%s",
+ dbi_result_get_string(result, "nombreaula"));
+ snprintf(room->gateway, sizeof(room->gateway), "%s",
+ dbi_result_get_string(result, "router"));
+ snprintf(room->netmask, sizeof(room->netmask), "%s",
+ dbi_result_get_string(result, "netmask"));
+
+ dbi_result_free(result);
+
+ return 0;
+}
+
#define OG_UNASSIGNED_SW_ID 0
#define OG_IMAGE_DEFAULT_TYPE 1 /* monolithic */