From c60b69b54ea240cfed5b2e8939026159480168bb Mon Sep 17 00:00:00 2001 From: Bryan Biedenkapp Date: Wed, 10 Jan 2024 12:11:12 -0500 Subject: [PATCH] add conference FNE REST API to report the currently configured TGID list; --- src/fne/network/RESTAPI.cpp | 91 +++++++++++++++++++++++++++++++++++ src/fne/network/RESTAPI.h | 2 + src/fne/network/RESTDefines.h | 1 + src/remote/RESTClientMain.cpp | 7 ++- 4 files changed, 100 insertions(+), 1 deletion(-) diff --git a/src/fne/network/RESTAPI.cpp b/src/fne/network/RESTAPI.cpp index f450386a..a2d16bd7 100644 --- a/src/fne/network/RESTAPI.cpp +++ b/src/fne/network/RESTAPI.cpp @@ -257,6 +257,7 @@ void RESTAPI::initializeEndpoints() m_dispatcher.match(GET_VERSION).get(REST_API_BIND(RESTAPI::restAPI_GetVersion, this)); m_dispatcher.match(GET_STATUS).get(REST_API_BIND(RESTAPI::restAPI_GetStatus, this)); m_dispatcher.match(FNE_GET_PEERLIST).get(REST_API_BIND(RESTAPI::restAPI_GetPeerList, this)); + m_dispatcher.match(FNE_GET_TGID_LIST).get(REST_API_BIND(RESTAPI::restAPI_GetTGIDList, this)); m_dispatcher.match(FNE_GET_FORCE_UPDATE).get(REST_API_BIND(RESTAPI::restAPI_GetForceUpdate, this)); } @@ -492,6 +493,96 @@ void RESTAPI::restAPI_GetPeerList(const HTTPPayload& request, HTTPPayload& reply reply.payload(response); } +/// +/// +/// +/// +/// +/// +void RESTAPI::restAPI_GetTGIDList(const HTTPPayload& request, HTTPPayload& reply, const RequestMatch& match) +{ + if (!validateAuth(request, reply)) { + return; + } + + json::object response = json::object(); + setResponseDefaultStatus(response); + + json::array tgs = json::array(); + if (m_tidLookup != nullptr) { + if (m_tidLookup->groupVoice().size() > 0) { + for (auto entry : m_tidLookup->groupVoice()) { + json::object tg = json::object(); + + std::string tgName = entry.name(); + tg["name"].set(tgName); + bool invalid = entry.isInvalid(); + tg["invalid"].set(invalid); + + { + json::object source = json::object(); + uint32_t tgId = entry.source().tgId(); + source["tgid"].set(tgId); + uint8_t tgSlot = entry.source().tgSlot(); + source["slot"].set(tgSlot); + tg["source"].set(source); + } + + { + json::object config = json::object(); + bool active = entry.config().active(); + config["active"].set(active); + bool parrot = entry.config().parrot(); + config["parrot"].set(parrot); + + json::array inclusions = json::array(); + std::vector inclusion = entry.config().inclusion(); + if (inclusion.size() > 0) { + for (auto inclEntry : inclusion) { + uint32_t peerId = inclEntry; + inclusions.push_back(json::value((double)peerId)); + } + } + config["inclusion"].set(inclusions); + + json::array exclusions = json::array(); + std::vector exclusion = entry.config().exclusion(); + if (exclusion.size() > 0) { + for (auto exclEntry : exclusion) { + uint32_t peerId = exclEntry; + exclusions.push_back(json::value((double)peerId)); + } + } + config["exclusion"].set(exclusions); + + json::array rewrites = json::array(); + std::vector rewrite = entry.config().rewrite(); + if (rewrite.size() > 0) { + for (auto rewrEntry : rewrite) { + json::object rewrite = json::object(); + uint32_t peerId = rewrEntry.peerId(); + rewrite["peerId"].set(peerId); + uint32_t tgId = rewrEntry.tgId(); + rewrite["tgid"].set(tgId); + uint8_t tgSlot = rewrEntry.tgSlot(); + rewrite["slot"].set(tgSlot); + + exclusions.push_back(json::value(rewrite)); + } + } + config["rewrite"].set(rewrites); + tg["config"].set(config); + } + + tgs.push_back(json::value(tg)); + } + } + } + + response["tgs"].set(tgs); + reply.payload(response); +} + /// /// /// diff --git a/src/fne/network/RESTAPI.h b/src/fne/network/RESTAPI.h index de81b969..2300e5fe 100644 --- a/src/fne/network/RESTAPI.h +++ b/src/fne/network/RESTAPI.h @@ -110,6 +110,8 @@ private: void restAPI_GetStatus(const HTTPPayload& request, HTTPPayload& reply, const network::rest::RequestMatch& match); /// void restAPI_GetPeerList(const HTTPPayload& request, HTTPPayload& reply, const network::rest::RequestMatch& match); + /// + void restAPI_GetTGIDList(const HTTPPayload& request, HTTPPayload& reply, const network::rest::RequestMatch& match); /// void restAPI_GetForceUpdate(const HTTPPayload& request, HTTPPayload& reply, const network::rest::RequestMatch& match); diff --git a/src/fne/network/RESTDefines.h b/src/fne/network/RESTDefines.h index 2620f83c..b2fabce2 100644 --- a/src/fne/network/RESTDefines.h +++ b/src/fne/network/RESTDefines.h @@ -34,6 +34,7 @@ // --------------------------------------------------------------------------- #define FNE_GET_PEERLIST "/peerlist" +#define FNE_GET_TGID_LIST "/tgidlist" #define FNE_GET_FORCE_UPDATE "/force-update" diff --git a/src/remote/RESTClientMain.cpp b/src/remote/RESTClientMain.cpp index e0fabdcb..91a30d17 100644 --- a/src/remote/RESTClientMain.cpp +++ b/src/remote/RESTClientMain.cpp @@ -56,6 +56,7 @@ #define RCD_GET_VOICE_CH "voice-ch" #define RCD_FNE_GET_PEERLIST "fne-peerlist" +#define RCD_FNE_GET_TGIDLIST "fne-tgidlist" #define RCD_FNE_GET_FORCEUPDATE "fne-force-update" #define RCD_MODE "mdm-mode" @@ -192,7 +193,8 @@ void usage(const char* message, const char* arg) reply += " status Display current settings and operation mode\r\n"; reply += " voice-ch Retrieves the list of configured voice channels\r\n"; reply += "\r\n"; - reply += " peerlist Retrieves the list of connected peers (Conference FNE only)\r\n"; + reply += " fne-peerlist Retrieves the list of connected peers (Conference FNE only)\r\n"; + reply += " fne-tgidlist Retrieves the list of configured TGIDs (Conference FNE only)\r\n"; reply += " fne-force-update Forces the FNE to send list update (Conference FNE only)\r\n"; reply += "\r\n"; reply += " mdm-mode Set current mode of host (idle, lockout, dmr, p25, nxdn)\r\n"; @@ -439,6 +441,9 @@ int main(int argc, char** argv) else if (rcom == RCD_FNE_GET_PEERLIST) { retCode = client->send(HTTP_GET, FNE_GET_PEERLIST, json::object(), response); } + else if (rcom == RCD_FNE_GET_TGIDLIST) { + retCode = client->send(HTTP_GET, FNE_GET_TGID_LIST, json::object(), response); + } else if (rcom == RCD_FNE_GET_FORCEUPDATE) { retCode = client->send(HTTP_GET, FNE_GET_FORCE_UPDATE, json::object(), response); }