Merge pull request #21 from hacknix/master

RIC Blacklist
This commit is contained in:
Florian (DF2ET) 2018-12-10 20:54:14 +01:00 committed by GitHub
commit 14b86da9ea
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 31 additions and 1 deletions

View file

@ -107,6 +107,15 @@ bool CConf::read()
m_whiteList.push_back(ric);
p = ::strtok(NULL, ",\r\n");
}
} else if (::strcmp(key, "BlackList") == 0) {
char* p = ::strtok(value, ",\r\n");
while (p != NULL) {
unsigned int ric = (unsigned int)::atoi(p);
if (ric > 0U)
m_blackList.push_back(ric);
p = ::strtok(NULL, ",\r\n");
}
} else if (::strcmp(key,"BlacklistRegexfile") == 0)
m_blacklistRegexfile = value;
else if (::strcmp(key,"WhitelistRegexfile") == 0)
@ -161,6 +170,11 @@ std::vector<uint32_t> CConf::getWhiteList() const
return m_whiteList;
}
std::vector<uint32_t> CConf::getBlackList() const
{
return m_blackList;
}
std::string CConf::getblacklistRegexfile() const
{
return m_blacklistRegexfile;

3
Conf.h
View file

@ -33,6 +33,7 @@ public:
// The General section
std::string getCallsign() const;
std::vector<unsigned int> getWhiteList() const;
std::vector<unsigned int> getBlackList() const;
std::string getblacklistRegexfile() const;
std::string getwhitelistRegexfile() const;
std::string getRptAddress() const;
@ -58,6 +59,8 @@ private:
std::string m_callsign;
std::vector<unsigned int> m_whiteList;
std::vector<unsigned int> m_blackList;
std::string m_blacklistRegexfile;
std::string m_whitelistRegexfile;
std::string m_rptAddress;

View file

@ -267,6 +267,8 @@ int CDAPNETGateway::run()
}
std::vector<unsigned int> whiteList = m_conf.getWhiteList();
std::vector<unsigned int> blackList = m_conf.getBlackList();
std::vector<std::regex> regexBlacklist;
std::vector<std::regex> regexWhitelist;
@ -312,6 +314,7 @@ int CDAPNETGateway::run()
CPOCSAGMessage* message = m_dapnetNetwork->readMessage();
if (message != NULL) {
bool found = true;
bool blackListRIC = false;
bool blacklistRegexmatch = false;
bool whitelistRegexmatch = true;
@ -319,6 +322,15 @@ int CDAPNETGateway::run()
if (!whiteList.empty())
found = std::find(whiteList.begin(), whiteList.end(), message->m_ric) != whiteList.end();
// If we have a black list of RICs, use it.
if (!blackList.empty())
blackListRIC = std::find(blackList.begin(), blackList.end(), message->m_ric) != blackList.end();
if (blackListRIC)
LogDebug("Blacklist match: Not queueing message to %07u, type %u, message: \"%.*s\"", message->m_ric, message->m_type, message->m_length, message->m_message);
std::string messageBody(reinterpret_cast<char*>(message->m_message));
//If we have a list of blacklist REGEXes, use them
if (!regexBlacklist.empty()) {
@ -343,7 +355,7 @@ int CDAPNETGateway::run()
}
}
if (found && !blacklistRegexmatch && whitelistRegexmatch) {
if (found && !blackListRIC && !blacklistRegexmatch && whitelistRegexmatch) {
switch (message->m_functional) {
case FUNCTIONAL_ALPHANUMERIC:
LogDebug("Queueing message to %07u, type %u, func Alphanumeric: \"%.*s\"", message->m_ric, message->m_type, message->m_length, message->m_message);

View file

@ -1,6 +1,7 @@
[General]
Callsign=g9bf
# WhiteList=12345,78901
# BlackList=
#BlacklistRegexfile=/tmp/blregexes.txt
#WhitelistRegexfile=/tmp/wlregexes.txt
RptAddress=127.0.0.1