diff --git a/AUTHORS.md b/AUTHORS.md index 49cb022c..99bde41e 100644 --- a/AUTHORS.md +++ b/AUTHORS.md @@ -2,6 +2,7 @@ - Bryan Biedenkapp (https://github.com/gatekeep) - Natalie Moore (https://github.com/jelimoore) +- Patrick McDonnell (https://github.com/W3AXL) - Build Chain and Helper Tools - K4YT3X (https://github.com/k4yt3x) diff --git a/src/common/lookups/RadioIdLookup.cpp b/src/common/lookups/RadioIdLookup.cpp index c75a975b..d4043a9e 100644 --- a/src/common/lookups/RadioIdLookup.cpp +++ b/src/common/lookups/RadioIdLookup.cpp @@ -49,23 +49,23 @@ void RadioIdLookup::toggleEntry(uint32_t id, bool enabled) RadioId rid = find(id); if (!rid.radioEnabled() && rid.radioDefault()) { if (enabled) { - LogMessage(LOG_HOST, "Added enabled RID %u to RID ACL table", id); + LogMessage(LOG_HOST, "Added enabled RID %u (%s) to RID ACL table", id, rid.radioAlias().c_str()); } else { - LogMessage(LOG_HOST, "Added disabled RID %u to RID ACL table", id); + LogMessage(LOG_HOST, "Added disabled RID %u (%s) to RID ACL table", id, rid.radioAlias().c_str()); } } if (!rid.radioEnabled() && !rid.radioDefault()) { if (enabled) { - LogMessage(LOG_HOST, "Enabled RID %u in RID ACL table", id); + LogMessage(LOG_HOST, "Enabled RID %u (%s) in RID ACL table", id, rid.radioAlias().c_str()); } else { - LogMessage(LOG_HOST, "Disabled RID %u in RID ACL table", id); + LogMessage(LOG_HOST, "Disabled RID %u (%s) in RID ACL table", id, rid.radioAlias().c_str()); } } - addEntry(id, enabled); + addEntry(id, enabled, rid.radioAlias()); } /// @@ -73,13 +73,14 @@ void RadioIdLookup::toggleEntry(uint32_t id, bool enabled) /// /// Unique ID to add. /// Flag indicating if radio ID is enabled or not. -void RadioIdLookup::addEntry(uint32_t id, bool enabled) +/// Alias for the radio ID +void RadioIdLookup::addEntry(uint32_t id, bool enabled, const std::string& alias) { if ((id == p25::P25_WUID_ALL) || (id == p25::P25_WUID_FNE)) { return; } - RadioId entry = RadioId(enabled, false); + RadioId entry = RadioId(enabled, false, alias); m_mutex.lock(); { @@ -88,7 +89,7 @@ void RadioIdLookup::addEntry(uint32_t id, bool enabled) // if the enabled value doesn't match -- override with the intended if (_entry.radioEnabled() != enabled) { - _entry = RadioId(enabled, false); + _entry = RadioId(enabled, false, alias); m_table[id] = _entry; } } catch (...) { @@ -188,6 +189,7 @@ bool RadioIdLookup::load() std::string line; while (std::getline(file, line)) { if (line.length() > 0) { + // Skip comments with # if (line.at(0) == '#') continue; @@ -214,7 +216,14 @@ bool RadioIdLookup::load() bool radioEnabled = ::atoi(parsed[1].c_str()) == 1; bool radioDefault = false; - m_table[id] = RadioId(radioEnabled, radioDefault); + // Check for an optional alias field + if (parsed.size() >= 3) { + m_table[id] = RadioId(radioEnabled, radioDefault, parsed[2]); + LogDebug(LOG_HOST, "Loaded RID %u (%s) into RID lookup table", id, parsed[2].c_str()); + } else { + m_table[id] = RadioId(radioEnabled, radioDefault); + LogDebug(LOG_HOST, "Loaded RID %u into RID lookup table", id); + } } } } diff --git a/src/common/lookups/RadioIdLookup.h b/src/common/lookups/RadioIdLookup.h index f8ee427c..a7d0acb0 100644 --- a/src/common/lookups/RadioIdLookup.h +++ b/src/common/lookups/RadioIdLookup.h @@ -33,7 +33,8 @@ namespace lookups /// Initializes a new instance of the RadioId class. RadioId() : m_radioEnabled(false), - m_radioDefault(false) + m_radioDefault(false), + m_radioAlias("") { /* stub */ } @@ -42,7 +43,20 @@ namespace lookups /// RadioId(bool radioEnabled, bool radioDefault) : m_radioEnabled(radioEnabled), - m_radioDefault(radioDefault) + m_radioDefault(radioDefault), + m_radioAlias("") + { + /* stub */ + } + + /// Initializes a new instance of the RadioId class. + /// + /// + /// + RadioId(bool radioEnabled, bool radioDefault, const std::string& radioAlias) : + m_radioEnabled(radioEnabled), + m_radioDefault(radioDefault), + m_radioAlias(radioAlias) { /* stub */ } @@ -53,6 +67,7 @@ namespace lookups if (this != &data) { m_radioEnabled = data.m_radioEnabled; m_radioDefault = data.m_radioDefault; + m_radioAlias = data.m_radioAlias; } return *this; @@ -67,11 +82,24 @@ namespace lookups m_radioDefault = radioDefault; } + /// Sets flag values. + /// Radio enabled. + /// Radio default. + /// + void set(bool radioEnabled, bool radioDefault, const std::string& radioAlias) + { + m_radioEnabled = radioEnabled; + m_radioDefault = radioDefault; + m_radioAlias = radioAlias; + } + public: /// Flag indicating if the radio is enabled. __READONLY_PROPERTY_PLAIN(bool, radioEnabled); /// Flag indicating if the radio is default. __READONLY_PROPERTY_PLAIN(bool, radioDefault); + /// Alias for the radio. + __READONLY_PROPERTY_PLAIN(std::string, radioAlias); }; // --------------------------------------------------------------------------- @@ -88,8 +116,9 @@ namespace lookups /// Toggles the specified radio ID enabled or disabled. void toggleEntry(uint32_t id, bool enabled); - /// Adds a new entry to the lookup table by the specified unique ID. - void addEntry(uint32_t id, bool enabled); + /// Adds a new entry to the lookup table by the specified unique ID, with an alias. + void addEntry(uint32_t id, bool enabled, const std::string& alias); + /// Erases an existing entry from the lookup table by the specified unique ID. void eraseEntry(uint32_t id); /// Finds a table entry in this lookup table. diff --git a/src/fne/network/RESTAPI.cpp b/src/fne/network/RESTAPI.cpp index b27e9d3d..d1390622 100644 --- a/src/fne/network/RESTAPI.cpp +++ b/src/fne/network/RESTAPI.cpp @@ -746,6 +746,8 @@ void RESTAPI::restAPI_GetRIDQuery(const HTTPPayload& request, HTTPPayload& reply ridObj["id"].set(rid); bool enabled = entry.second.radioEnabled(); ridObj["enabled"].set(enabled); + std::string alias = entry.second.radioAlias(); + ridObj["alias"].set(alias); rids.push_back(json::value(ridObj)); } @@ -789,14 +791,15 @@ void RESTAPI::restAPI_PutRIDAdd(const HTTPPayload& request, HTTPPayload& reply, bool enabled = req["enabled"].get(); - RadioId radioId = m_ridLookup->find(rid); - if (radioId.radioDefault()) { - m_ridLookup->addEntry(rid, enabled); - } - else { - m_ridLookup->toggleEntry(rid, enabled); + std::string alias = ""; + // Check if we were provided an alias in the request + if (req.find("alias") != req.end()) { + alias = req["alias"].get(); } + // The addEntry function will automatically update an existing entry, so no need to check for an exisitng one here + m_ridLookup->addEntry(rid, enabled, alias); + if (m_network != nullptr) { m_network->m_forceListUpdate = true; }