From 28ab2aa9b0fe22c4d4658f37799e2735b7370ef2 Mon Sep 17 00:00:00 2001 From: Javier Hernandez Date: Mon, 8 Jan 2024 11:14:42 +0100 Subject: rest: Use mask to differentiate folder types marker tells us if this folder to group rooms or computers. this is a woraround because the database has two tables to store room and computer folders, there is no unique id. the tables cannot be merged yet because of the legacy web console, to overcome this limitation, add a marker that provides a unique id to differentiate room and computer folder. this assumes only 65535 room folders are possible because the marker is 0x000010000 (65536) --- src/rest.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/rest.c b/src/rest.c index 8bde175..0ecfcbd 100644 --- a/src/rest.c +++ b/src/rest.c @@ -3943,14 +3943,20 @@ static int og_dbi_scope_get_computers_from_computers(const struct og_dbi *dbi, char *query, const uint32_t group_id); +#define OG_COMPUTER_FOLDER_MARKER 0x00010000 + static int og_dbi_scope_get_computers(const struct og_dbi *dbi, json_t *array, - char *query) + char *query, bool in_room) { const char *msglog, *computers_name; json_t *computers, *scope_array; uint32_t computers_id; + uint32_t marker = 0; dbi_result result; + if (in_room) + marker = OG_COMPUTER_FOLDER_MARKER; + result = dbi_conn_queryf(dbi->conn, query); if (!result) { dbi_conn_error(dbi->conn, &msglog); @@ -3974,7 +3980,7 @@ static int og_dbi_scope_get_computers(const struct og_dbi *dbi, json_t *array, json_string(computers_name)); json_object_set_new(computers, "type", json_string("folder")); json_object_set_new(computers, "id", - json_integer(computers_id)); + json_integer(computers_id | marker)); json_object_set_new(computers, "scope", json_array()); json_array_append(array, computers); json_decref(computers); @@ -4018,7 +4024,7 @@ static int og_dbi_scope_get_computers_from_room(const struct og_dbi *dbi, if (ret <= 0 || ret >= OG_QUERY_MAXLEN) return -1; - return og_dbi_scope_get_computers(dbi, array, query); + return og_dbi_scope_get_computers(dbi, array, query, true); } static int og_dbi_scope_get_computers_from_computers(const struct og_dbi *dbi, @@ -4033,7 +4039,7 @@ static int og_dbi_scope_get_computers_from_computers(const struct og_dbi *dbi, if (ret <= 0 || ret >= OG_QUERY_MAXLEN) return -1; - return og_dbi_scope_get_computers(dbi, array, query); + return og_dbi_scope_get_computers(dbi, array, query, false); } static int og_dbi_scope_get_room(const struct og_dbi *dbi, json_t *array, -- cgit v1.2.3-18-g5258