add IP address column to RID tables (this is *NOT* used yet, and is for future use);

pull/61/head
Bryan Biedenkapp 2 years ago
parent 93e1531308
commit a9bc150da7

@ -1,6 +1,6 @@
# #
# This file sets the valid Radio IDs allowed on a repeater. # This file sets the valid Radio IDs allowed on a repeater.
# #
# Entry Format: "RID,Enabled (1 = Enabled / 0 = Disabled),Optional Alias,<newline>" # Entry Format: "RID,Enabled (1 = Enabled / 0 = Disabled),Optional Alias,Optional IP Address,<newline>"
# #
#1234,1,RID Alias, #1234,1,RID Alias,IP Address,

@ -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. */ /* 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)) { if ((id == p25::defines::WUID_ALL) || (id == p25::defines::WUID_FNE)) {
return; return;
} }
RadioId entry = RadioId(enabled, false, alias); RadioId entry = RadioId(enabled, false, alias, ipAddress);
std::lock_guard<std::mutex> lock(m_mutex); std::lock_guard<std::mutex> lock(m_mutex);
try { 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 either the alias or the enabled flag doesn't match, update the entry
if (_entry.radioEnabled() != enabled || _entry.radioAlias() != alias) { if (_entry.radioEnabled() != enabled || _entry.radioAlias() != alias) {
//LogDebug(LOG_HOST, "Updating existing RID %d (%s) in ACL", id, alias.c_str()); //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; m_table[id] = _entry;
} else { } else {
//LogDebug(LOG_HOST, "No changes made to RID %d (%s) in ACL", id, alias.c_str()); //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 // parse tokenized line
uint32_t id = ::atoi(parsed[0].c_str()); uint32_t id = ::atoi(parsed[0].c_str());
bool radioEnabled = ::atoi(parsed[1].c_str()) == 1; 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) { 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()); LogDebug(LOG_HOST, "Loaded RID %u (%s) into RID lookup table", id, parsed[2].c_str());
} else { } else {
m_table[id] = RadioId(radioEnabled, false);
LogDebug(LOG_HOST, "Loaded RID %u into RID lookup table", id); LogDebug(LOG_HOST, "Loaded RID %u into RID lookup table", id);
} }
} }
@ -226,23 +236,36 @@ bool RadioIdLookup::save()
// String for writing // String for writing
std::string line; std::string line;
// iterate over each entry in the RID lookup and write it to the open file // iterate over each entry in the RID lookup and write it to the open file
for (auto& entry: m_table) { for (auto& entry: m_table) {
// Get the parameters // Get the parameters
uint32_t rid = entry.first; uint32_t rid = entry.first;
bool enabled = entry.second.radioEnabled(); bool enabled = entry.second.radioEnabled();
std::string alias = entry.second.radioAlias(); std::string alias = entry.second.radioAlias();
std::string ipAddress = entry.second.radioIPAddress();
// Format into a string // Format into a string
line = std::to_string(rid) + "," + std::to_string(enabled) + ","; line = std::to_string(rid) + "," + std::to_string(enabled) + ",";
// Add the alias if we have one // Add the alias if we have one
if (alias.length() > 0) { if (alias.length() > 0) {
line += alias; line += alias;
line += ","; line += ",";
} }
// Add the IP address if we have one
if (ipAddress.length() > 0) {
line += ipAddress;
line += ",";
}
// Add the newline // Add the newline
line += "\n"; line += "\n";
// Write to file // Write to file
file << line; file << line;
// Increment // Increment
lines++; lines++;
} }

@ -50,6 +50,7 @@ namespace lookups
{ {
/* stub */ /* stub */
} }
/** /**
* @brief Initializes a new instance of the RadioId class. * @brief Initializes a new instance of the RadioId class.
* @param radioEnabled Flag indicating radio is enabled. * @param radioEnabled Flag indicating radio is enabled.
@ -58,7 +59,8 @@ namespace lookups
RadioId(bool radioEnabled, bool radioDefault) : RadioId(bool radioEnabled, bool radioDefault) :
m_radioEnabled(radioEnabled), m_radioEnabled(radioEnabled),
m_radioDefault(radioDefault), m_radioDefault(radioDefault),
m_radioAlias("") m_radioAlias(""),
m_radioIPAddress("")
{ {
/* stub */ /* stub */
} }
@ -68,11 +70,13 @@ namespace lookups
* @param radioEnabled Flag indicating radio is enabled. * @param radioEnabled Flag indicating radio is enabled.
* @param radioDefault Flag indicating this is a "default" (i.e. undefined) radio. * @param radioDefault Flag indicating this is a "default" (i.e. undefined) radio.
* @param radioAlias Textual alias for the 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_radioEnabled(radioEnabled),
m_radioDefault(radioDefault), m_radioDefault(radioDefault),
m_radioAlias(radioAlias) m_radioAlias(radioAlias),
m_radioIPAddress(ipAddress)
{ {
/* stub */ /* stub */
} }
@ -87,33 +91,25 @@ namespace lookups
m_radioEnabled = data.m_radioEnabled; m_radioEnabled = data.m_radioEnabled;
m_radioDefault = data.m_radioDefault; m_radioDefault = data.m_radioDefault;
m_radioAlias = data.m_radioAlias; m_radioAlias = data.m_radioAlias;
m_radioIPAddress = data.m_radioIPAddress;
} }
return *this; 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. * @brief Sets flag values.
* @param radioEnabled Flag indicating radio is enabled. * @param radioEnabled Flag indicating radio is enabled.
* @param radioDefault Flag indicating this is a "default" (i.e. undefined) radio. * @param radioDefault Flag indicating this is a "default" (i.e. undefined) radio.
* @param radioAlias Textual alias for the 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_radioEnabled = radioEnabled;
m_radioDefault = radioDefault; m_radioDefault = radioDefault;
m_radioAlias = radioAlias; m_radioAlias = radioAlias;
m_radioIPAddress = ipAddress;
} }
public: public:
@ -129,6 +125,10 @@ namespace lookups
* @brief Alias for the radio. * @brief Alias for the radio.
*/ */
__READONLY_PROPERTY_PLAIN(std::string, radioAlias); __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 id Unique ID to add.
* @param enabled Flag indicating if radio ID is enabled or not. * @param enabled Flag indicating if radio ID is enabled or not.
* @param alias Alias for the radio ID * @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. * @brief Erases an existing entry from the lookup table by the specified unique ID.
* @param id Unique ID to erase. * @param id Unique ID to erase.

Loading…
Cancel
Save

Powered by TurnKey Linux.