From a9bc150da794417c94a58a24a0b79ed44923cce5 Mon Sep 17 00:00:00 2001 From: Bryan Biedenkapp Date: Thu, 4 Jul 2024 14:35:23 -0400 Subject: [PATCH] add IP address column to RID tables (this is *NOT* used yet, and is for future use); --- configs/rid_acl.example.dat | 4 ++-- src/common/lookups/RadioIdLookup.cpp | 35 +++++++++++++++++++++++----- src/common/lookups/RadioIdLookup.h | 33 +++++++++++++------------- 3 files changed, 48 insertions(+), 24 deletions(-) diff --git a/configs/rid_acl.example.dat b/configs/rid_acl.example.dat index b26ad5f5..97198cda 100644 --- a/configs/rid_acl.example.dat +++ b/configs/rid_acl.example.dat @@ -1,6 +1,6 @@ # # This file sets the valid Radio IDs allowed on a repeater. # -# Entry Format: "RID,Enabled (1 = Enabled / 0 = Disabled),Optional Alias," +# Entry Format: "RID,Enabled (1 = Enabled / 0 = Disabled),Optional Alias,Optional IP Address," # -#1234,1,RID Alias, +#1234,1,RID Alias,IP Address, diff --git a/src/common/lookups/RadioIdLookup.cpp b/src/common/lookups/RadioIdLookup.cpp index 29de6f81..c9417f99 100644 --- a/src/common/lookups/RadioIdLookup.cpp +++ b/src/common/lookups/RadioIdLookup.cpp @@ -56,13 +56,13 @@ void RadioIdLookup::toggleEntry(uint32_t id, bool enabled) /* Adds a new entry to the lookup table by the specified unique ID. */ -void RadioIdLookup::addEntry(uint32_t id, bool enabled, const std::string& alias) +void RadioIdLookup::addEntry(uint32_t id, bool enabled, const std::string& alias, const std::string& ipAddress) { if ((id == p25::defines::WUID_ALL) || (id == p25::defines::WUID_FNE)) { return; } - RadioId entry = RadioId(enabled, false, alias); + RadioId entry = RadioId(enabled, false, alias, ipAddress); std::lock_guard lock(m_mutex); try { @@ -70,7 +70,7 @@ void RadioIdLookup::addEntry(uint32_t id, bool enabled, const std::string& alias // if either the alias or the enabled flag doesn't match, update the entry if (_entry.radioEnabled() != enabled || _entry.radioAlias() != alias) { //LogDebug(LOG_HOST, "Updating existing RID %d (%s) in ACL", id, alias.c_str()); - _entry = RadioId(enabled, false, alias); + _entry = RadioId(enabled, false, alias, ipAddress); m_table[id] = _entry; } else { //LogDebug(LOG_HOST, "No changes made to RID %d (%s) in ACL", id, alias.c_str()); @@ -180,13 +180,23 @@ bool RadioIdLookup::load() // parse tokenized line uint32_t id = ::atoi(parsed[0].c_str()); bool radioEnabled = ::atoi(parsed[1].c_str()) == 1; + std::string alias = ""; + std::string ipAddress = ""; - // Check for an optional alias field + // check for an optional alias field if (parsed.size() >= 3) { - m_table[id] = RadioId(radioEnabled, false, parsed[2]); + alias = parsed[2]; + } + + // check for an optional IP address field + if (parsed.size() >= 4) { + ipAddress = parsed[3]; + } + + m_table[id] = RadioId(radioEnabled, false, alias, ipAddress); + if (alias != "") { LogDebug(LOG_HOST, "Loaded RID %u (%s) into RID lookup table", id, parsed[2].c_str()); } else { - m_table[id] = RadioId(radioEnabled, false); LogDebug(LOG_HOST, "Loaded RID %u into RID lookup table", id); } } @@ -226,23 +236,36 @@ bool RadioIdLookup::save() // String for writing std::string line; + // iterate over each entry in the RID lookup and write it to the open file for (auto& entry: m_table) { // Get the parameters uint32_t rid = entry.first; bool enabled = entry.second.radioEnabled(); std::string alias = entry.second.radioAlias(); + std::string ipAddress = entry.second.radioIPAddress(); + // Format into a string line = std::to_string(rid) + "," + std::to_string(enabled) + ","; + // Add the alias if we have one if (alias.length() > 0) { line += alias; line += ","; } + + // Add the IP address if we have one + if (ipAddress.length() > 0) { + line += ipAddress; + line += ","; + } + // Add the newline line += "\n"; + // Write to file file << line; + // Increment lines++; } diff --git a/src/common/lookups/RadioIdLookup.h b/src/common/lookups/RadioIdLookup.h index 59296074..32058be3 100644 --- a/src/common/lookups/RadioIdLookup.h +++ b/src/common/lookups/RadioIdLookup.h @@ -50,6 +50,7 @@ namespace lookups { /* stub */ } + /** * @brief Initializes a new instance of the RadioId class. * @param radioEnabled Flag indicating radio is enabled. @@ -58,7 +59,8 @@ namespace lookups RadioId(bool radioEnabled, bool radioDefault) : m_radioEnabled(radioEnabled), m_radioDefault(radioDefault), - m_radioAlias("") + m_radioAlias(""), + m_radioIPAddress("") { /* stub */ } @@ -68,11 +70,13 @@ namespace lookups * @param radioEnabled Flag indicating radio is enabled. * @param radioDefault Flag indicating this is a "default" (i.e. undefined) radio. * @param radioAlias Textual alias for the radio. + * @param ipAddress Textual IP Address for the radio. */ - RadioId(bool radioEnabled, bool radioDefault, const std::string& radioAlias) : + RadioId(bool radioEnabled, bool radioDefault, const std::string& radioAlias, const std::string& ipAddress = "") : m_radioEnabled(radioEnabled), m_radioDefault(radioDefault), - m_radioAlias(radioAlias) + m_radioAlias(radioAlias), + m_radioIPAddress(ipAddress) { /* stub */ } @@ -87,33 +91,25 @@ namespace lookups m_radioEnabled = data.m_radioEnabled; m_radioDefault = data.m_radioDefault; m_radioAlias = data.m_radioAlias; + m_radioIPAddress = data.m_radioIPAddress; } return *this; } - /** - * @brief Sets flag values. - * @param radioEnabled Flag indicating radio is enabled. - * @param radioDefault Flag indicating this is a "default" (i.e. undefined) radio. - */ - void set(bool radioEnabled, bool radioDefault) - { - m_radioEnabled = radioEnabled; - m_radioDefault = radioDefault; - } - /** * @brief Sets flag values. * @param radioEnabled Flag indicating radio is enabled. * @param radioDefault Flag indicating this is a "default" (i.e. undefined) radio. * @param radioAlias Textual alias for the radio. + * @param ipAddress Textual IP Address for the radio. */ - void set(bool radioEnabled, bool radioDefault, const std::string& radioAlias) + void set(bool radioEnabled, bool radioDefault, const std::string& radioAlias, const std::string& ipAddress = "") { m_radioEnabled = radioEnabled; m_radioDefault = radioDefault; m_radioAlias = radioAlias; + m_radioIPAddress = ipAddress; } public: @@ -129,6 +125,10 @@ namespace lookups * @brief Alias for the radio. */ __READONLY_PROPERTY_PLAIN(std::string, radioAlias); + /** + * @brief IP Address for the radio. + */ + __READONLY_PROPERTY_PLAIN(std::string, radioIPAddress); }; // --------------------------------------------------------------------------- @@ -167,8 +167,9 @@ namespace lookups * @param id Unique ID to add. * @param enabled Flag indicating if radio ID is enabled or not. * @param alias Alias for the radio ID + * @param ipAddress IP Address for Radio */ - void addEntry(uint32_t id, bool enabled, const std::string& alias); + void addEntry(uint32_t id, bool enabled, const std::string& alias, const std::string& ipAddress = ""); /** * @brief Erases an existing entry from the lookup table by the specified unique ID. * @param id Unique ID to erase.