1
0
Fork 0

Fix bugs and simplify the blocking code.

master
Jonathan Naylor 4 years ago
parent d0602d9aa6
commit 6c3af73383

@ -84,8 +84,11 @@ void CBlockList::clock(unsigned int ms)
bool CBlockList::loadFile() bool CBlockList::loadFile()
{ {
FILE* fp = ::fopen(m_file.c_str(), "rt"); FILE* fp = ::fopen(m_file.c_str(), "rt");
if (fp == NULL) if (fp == NULL) {
m_callsigns.clear();
LogInfo("Loaded %u callsigns from the block list", m_callsigns.size());
return false; return false;
}
char buffer[BUFFER_SIZE]; char buffer[BUFFER_SIZE];
@ -112,7 +115,6 @@ bool CBlockList::loadFile()
// Read the callsigns into the array // Read the callsigns into the array
m_callsigns.clear(); m_callsigns.clear();
unsigned int n = 0U;
while (::fgets(buffer, BUFFER_SIZE, fp) != NULL) { while (::fgets(buffer, BUFFER_SIZE, fp) != NULL) {
char* p; char* p;
@ -129,13 +131,12 @@ bool CBlockList::loadFile()
}); });
m_callsigns.push_back(callsign); m_callsigns.push_back(callsign);
n++;
} }
} }
::fclose(fp); ::fclose(fp);
LogInfo("Loaded %u callsigns from the block list", n); LogInfo("Loaded %u callsigns from the block list", m_callsigns.size());
return true; return true;
} }

@ -200,7 +200,6 @@ void CYSFReflector::run()
unsigned char dst[YSF_CALLSIGN_LENGTH]; unsigned char dst[YSF_CALLSIGN_LENGTH];
bool blocked = false; bool blocked = false;
bool checked = false;
for (;;) { for (;;) {
unsigned char buffer[200U]; unsigned char buffer[200U];
@ -237,58 +236,49 @@ void CYSFReflector::run()
} }
network.setCount(m_repeaters.size()); network.setCount(m_repeaters.size());
} else if (::memcmp(buffer + 0U, "YSFD", 4U) == 0 && rpt != NULL) { } else if (::memcmp(buffer + 0U, "YSFD", 4U) == 0 && rpt != NULL) {
// Check for a change of user if (!watchdogTimer.isRunning()) {
if (watchdogTimer.isRunning() && ::memcmp(tag, buffer + 4U, YSF_CALLSIGN_LENGTH) == 0) { ::memcpy(tag, buffer + 4U, YSF_CALLSIGN_LENGTH);
if (::memcmp(buffer + 14U, " ", YSF_CALLSIGN_LENGTH) != 0 && ::memcmp(src, "??????????", YSF_CALLSIGN_LENGTH) == 0)
checked = false;
if (::memcmp(buffer + 24U, " ", YSF_CALLSIGN_LENGTH) != 0 && ::memcmp(dst, "??????????", YSF_CALLSIGN_LENGTH) == 0) if (::memcmp(buffer + 14U, " ", YSF_CALLSIGN_LENGTH) != 0)
checked = false; ::memcpy(src, buffer + 14U, YSF_CALLSIGN_LENGTH);
} else
::memcpy(src, "??????????", YSF_CALLSIGN_LENGTH);
// Is this user allowed? if (::memcmp(buffer + 24U, " ", YSF_CALLSIGN_LENGTH) != 0)
if (!checked) { ::memcpy(dst, buffer + 24U, YSF_CALLSIGN_LENGTH);
blocked = blockList.check(buffer + 14U); else
checked = true; ::memcpy(dst, "??????????", YSF_CALLSIGN_LENGTH);
blocked = blockList.check(src);
if (blocked) if (blocked)
LogDebug("Data from %10.10s at %10.10s blocked", buffer + 14U, buffer + 4U); LogMessage("Data from %10.10s at %10.10s blocked", src, tag);
} else
LogMessage("Received data from %10.10s to %10.10s at %10.10s", src, dst, tag);
if (!blocked) { } else {
if (!watchdogTimer.isRunning()) { if (::memcmp(tag, buffer + 4U, YSF_CALLSIGN_LENGTH) == 0) {
::memcpy(tag, buffer + 4U, YSF_CALLSIGN_LENGTH); bool changed = false;
if (::memcmp(buffer + 14U, " ", YSF_CALLSIGN_LENGTH) != 0) if (::memcmp(buffer + 14U, " ", YSF_CALLSIGN_LENGTH) != 0 && ::memcmp(src, "??????????", YSF_CALLSIGN_LENGTH) == 0) {
::memcpy(src, buffer + 14U, YSF_CALLSIGN_LENGTH); ::memcpy(src, buffer + 14U, YSF_CALLSIGN_LENGTH);
else changed = true;
::memcpy(src, "??????????", YSF_CALLSIGN_LENGTH); }
if (::memcmp(buffer + 24U, " ", YSF_CALLSIGN_LENGTH) != 0) if (::memcmp(buffer + 24U, " ", YSF_CALLSIGN_LENGTH) != 0 && ::memcmp(dst, "??????????", YSF_CALLSIGN_LENGTH) == 0) {
::memcpy(dst, buffer + 24U, YSF_CALLSIGN_LENGTH); ::memcpy(dst, buffer + 24U, YSF_CALLSIGN_LENGTH);
else changed = true;
::memcpy(dst, "??????????", YSF_CALLSIGN_LENGTH); }
LogMessage("Received data from %10.10s to %10.10s at %10.10s", src, dst, buffer + 4U); if (changed) {
} else { blocked = blockList.check(src);
if (::memcmp(tag, buffer + 4U, YSF_CALLSIGN_LENGTH) == 0) { if (blocked)
bool changed = false; LogMessage("Data from %10.10s at %10.10s blocked", src, tag);
else
if (::memcmp(buffer + 14U, " ", YSF_CALLSIGN_LENGTH) != 0 && ::memcmp(src, "??????????", YSF_CALLSIGN_LENGTH) == 0) { LogMessage("Received data from %10.10s to %10.10s at %10.10s", src, dst, tag);
::memcpy(src, buffer + 14U, YSF_CALLSIGN_LENGTH);
changed = true;
}
if (::memcmp(buffer + 24U, " ", YSF_CALLSIGN_LENGTH) != 0 && ::memcmp(dst, "??????????", YSF_CALLSIGN_LENGTH) == 0) {
::memcpy(dst, buffer + 24U, YSF_CALLSIGN_LENGTH);
changed = true;
}
if (changed)
LogMessage("Received data from %10.10s to %10.10s at %10.10s", src, dst, buffer + 4U);
} }
} }
}
if (!blocked) {
watchdogTimer.start(); watchdogTimer.start();
for (std::vector<CYSFRepeater*>::const_iterator it = m_repeaters.begin(); it != m_repeaters.end(); ++it) { for (std::vector<CYSFRepeater*>::const_iterator it = m_repeaters.begin(); it != m_repeaters.end(); ++it) {
@ -297,9 +287,6 @@ void CYSFReflector::run()
} }
if ((buffer[34U] & 0x01U) == 0x01U) { if ((buffer[34U] & 0x01U) == 0x01U) {
blocked = false;
checked = false;
LogMessage("Received end of transmission"); LogMessage("Received end of transmission");
watchdogTimer.stop(); watchdogTimer.stop();
} }
@ -336,9 +323,6 @@ void CYSFReflector::run()
watchdogTimer.clock(ms); watchdogTimer.clock(ms);
if (watchdogTimer.isRunning() && watchdogTimer.hasExpired()) { if (watchdogTimer.isRunning() && watchdogTimer.hasExpired()) {
checked = false;
blocked = false;
LogMessage("Network watchdog has expired"); LogMessage("Network watchdog has expired");
watchdogTimer.stop(); watchdogTimer.stop();
} }

Loading…
Cancel
Save