Add RID alias to RID ACL (#48)

* initial RID alias support

* don't use toggle for an RID update from the REST API
pull/49/head
Patrick W3AXL 2 years ago committed by GitHub
parent 987e944d4b
commit a279b33876
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -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)

@ -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());
}
/// <summary>
@ -73,13 +73,14 @@ void RadioIdLookup::toggleEntry(uint32_t id, bool enabled)
/// </summary>
/// <param name="id">Unique ID to add.</param>
/// <param name="enabled">Flag indicating if radio ID is enabled or not.</param>
void RadioIdLookup::addEntry(uint32_t id, bool enabled)
/// <param name="alias">Alias for the radio ID</param>
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;
// 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);
}
}
}
}

@ -33,7 +33,8 @@ namespace lookups
/// <summary>Initializes a new instance of the RadioId class.</summary>
RadioId() :
m_radioEnabled(false),
m_radioDefault(false)
m_radioDefault(false),
m_radioAlias("")
{
/* stub */
}
@ -42,7 +43,20 @@ namespace lookups
/// <param name="radioDefault"></param>
RadioId(bool radioEnabled, bool radioDefault) :
m_radioEnabled(radioEnabled),
m_radioDefault(radioDefault)
m_radioDefault(radioDefault),
m_radioAlias("")
{
/* stub */
}
/// <summary>Initializes a new instance of the RadioId class.</summary>
/// <param name="radioEnabled"></param>
/// <param name="radioDefault"></param>
/// <param name="radioAlias"></param>
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;
}
/// <summary>Sets flag values.</summary>
/// <param name="radioEnabled">Radio enabled.</param>
/// <param name="radioDefault">Radio default.</param>
/// <param name="radioAlias"></param>
void set(bool radioEnabled, bool radioDefault, const std::string& radioAlias)
{
m_radioEnabled = radioEnabled;
m_radioDefault = radioDefault;
m_radioAlias = radioAlias;
}
public:
/// <summary>Flag indicating if the radio is enabled.</summary>
__READONLY_PROPERTY_PLAIN(bool, radioEnabled);
/// <summary>Flag indicating if the radio is default.</summary>
__READONLY_PROPERTY_PLAIN(bool, radioDefault);
/// <summary>Alias for the radio.</summary>
__READONLY_PROPERTY_PLAIN(std::string, radioAlias);
};
// ---------------------------------------------------------------------------
@ -88,8 +116,9 @@ namespace lookups
/// <summary>Toggles the specified radio ID enabled or disabled.</summary>
void toggleEntry(uint32_t id, bool enabled);
/// <summary>Adds a new entry to the lookup table by the specified unique ID.</summary>
void addEntry(uint32_t id, bool enabled);
/// <summary>Adds a new entry to the lookup table by the specified unique ID, with an alias.</summary>
void addEntry(uint32_t id, bool enabled, const std::string& alias);
/// <summary>Erases an existing entry from the lookup table by the specified unique ID.</summary>
void eraseEntry(uint32_t id);
/// <summary>Finds a table entry in this lookup table.</summary>

@ -746,6 +746,8 @@ void RESTAPI::restAPI_GetRIDQuery(const HTTPPayload& request, HTTPPayload& reply
ridObj["id"].set<uint32_t>(rid);
bool enabled = entry.second.radioEnabled();
ridObj["enabled"].set<bool>(enabled);
std::string alias = entry.second.radioAlias();
ridObj["alias"].set<std::string>(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<bool>();
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<std::string>();
}
// 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;
}

Loading…
Cancel
Save

Powered by TurnKey Linux.