diff --git a/src/ccallsign.cpp b/src/ccallsign.cpp index 410a0c0..a928b94 100644 --- a/src/ccallsign.cpp +++ b/src/ccallsign.cpp @@ -209,7 +209,7 @@ bool CCallsign::HasSameCallsign(const CCallsign &Callsign) const return (::memcmp(m_Callsign, Callsign.m_Callsign, sizeof(m_Callsign)) == 0); } -bool CCallsign::HasSameCallsignWithWidlcard(const CCallsign &callsign) const +bool CCallsign::HasSameCallsignWithWildcard(const CCallsign &callsign) const { bool same = true; bool done = false; diff --git a/src/ccallsign.h b/src/ccallsign.h index 07c9f69..e1c7f3f 100644 --- a/src/ccallsign.h +++ b/src/ccallsign.h @@ -69,7 +69,7 @@ public: // compare bool HasSameCallsign(const CCallsign &) const; - bool HasSameCallsignWithWidlcard(const CCallsign &) const; + bool HasSameCallsignWithWildcard(const CCallsign &) const; bool HasSameModule(const CCallsign &) const; // operators diff --git a/src/ccallsignlist.cpp b/src/ccallsignlist.cpp index cddf346..5d68b93 100644 --- a/src/ccallsignlist.cpp +++ b/src/ccallsignlist.cpp @@ -44,6 +44,7 @@ bool CCallsignList::LoadFromFile(const char *filename) { bool ok = false; char sz[256]; + char szStar[2] = "*"; // and load std::ifstream file (filename); @@ -58,10 +59,24 @@ bool CCallsignList::LoadFromFile(const char *filename) { // remove leading & trailing spaces char *szt = TrimWhiteSpaces(sz); - // and load if not comment + + // crack it if ( (::strlen(szt) > 0) && (szt[0] != '#') ) { - push_back(CCallsignListItem(CCallsign(szt), CIp(), NULL)); + // 1st token is callsign + if ( (szt = ::strtok(szt, " ,\t")) != NULL ) + { + CCallsign callsign(szt); + // 2nd token is modules list + szt = ::strtok(NULL, " ,\t"); + // if token absent, use wildcard + if ( szt == NULL ) + { + szt = szStar; + } + // and add to list + push_back(CCallsignListItem(callsign, CIp(), szt)); + } } } // close file @@ -112,18 +127,33 @@ bool CCallsignList::NeedReload(void) //////////////////////////////////////////////////////////////////////////////////////// // compare -bool CCallsignList::IsCallsignListed(const CCallsign &callsign) const +bool CCallsignList::IsCallsignListedWithWildcard(const CCallsign &callsign) const { bool listed = false; for ( int i = 0; (i < size()) && !listed; i++ ) { - listed = (data()[i]).HasSameCallsignWithWidlcard(callsign); + listed = (data()[i]).HasSameCallsignWithWildcard(callsign); } return listed; } +bool CCallsignList::IsCallsignListedWithWildcard(const CCallsign &callsign, char module) const +{ + bool listed = false; + + for ( int i = 0; (i < size()) && !listed; i++ ) + { + const CCallsignListItem *item = &(data()[i]); + listed = (item->HasSameCallsignWithWildcard(callsign) && + ((module == ' ') || item->HasModuleListed(module)) ); + + } + + return listed; +} + bool CCallsignList::IsCallsignListed(const CCallsign &callsign, char module) const { bool listed = false; diff --git a/src/ccallsignlist.h b/src/ccallsignlist.h index 90b7c96..b0f5362 100644 --- a/src/ccallsignlist.h +++ b/src/ccallsignlist.h @@ -51,7 +51,8 @@ public: bool NeedReload(void); // compare - bool IsCallsignListed(const CCallsign &) const; + bool IsCallsignListedWithWildcard(const CCallsign &) const; + bool IsCallsignListedWithWildcard(const CCallsign &, char) const; bool IsCallsignListed(const CCallsign &, char) const; bool IsCallsignListed(const CCallsign &, char*) const; diff --git a/src/ccallsignlistitem.cpp b/src/ccallsignlistitem.cpp index 34e4129..fb1a9b4 100644 --- a/src/ccallsignlistitem.cpp +++ b/src/ccallsignlistitem.cpp @@ -43,7 +43,17 @@ CCallsignListItem::CCallsignListItem(const CCallsign &callsign, const CIp &ip, c if ( modules != NULL ) { :: memset(m_Modules, 0, sizeof(m_Modules)); - ::memcpy(m_Modules, modules, MIN(strlen(modules), sizeof(m_Modules)-1)); + if ( modules[0] == '*' ) + { + for ( char i = 0; i < NB_OF_MODULES; i++ ) + { + m_Modules[i] = 'A' + i; + } + } + else + { + ::memcpy(m_Modules, modules, MIN(strlen(modules), sizeof(m_Modules)-1)); + } } } @@ -55,7 +65,17 @@ CCallsignListItem::CCallsignListItem(const CCallsign &callsign, const char *url, if ( modules != NULL ) { :: memset(m_Modules, 0, sizeof(m_Modules)); - ::memcpy(m_Modules, modules, MIN(strlen(modules), sizeof(m_Modules)-1)); + if ( modules[0] == '*' ) + { + for ( char i = 0; i < NB_OF_MODULES; i++ ) + { + m_Modules[i] = 'A' + i; + } + } + else + { + ::memcpy(m_Modules, modules, MIN(strlen(modules), sizeof(m_Modules)-1)); + } } } @@ -76,9 +96,9 @@ bool CCallsignListItem::HasSameCallsign(const CCallsign &callsign) const return m_Callsign.HasSameCallsign(callsign); } -bool CCallsignListItem::HasSameCallsignWithWidlcard(const CCallsign &callsign) const +bool CCallsignListItem::HasSameCallsignWithWildcard(const CCallsign &callsign) const { - return m_Callsign.HasSameCallsignWithWidlcard(callsign); + return m_Callsign.HasSameCallsignWithWildcard(callsign); } bool CCallsignListItem::HasModuleListed(char module) const diff --git a/src/ccallsignlistitem.h b/src/ccallsignlistitem.h index fef2192..341b059 100644 --- a/src/ccallsignlistitem.h +++ b/src/ccallsignlistitem.h @@ -51,7 +51,7 @@ public: // compare bool HasSameCallsign(const CCallsign &) const; - bool HasSameCallsignWithWidlcard(const CCallsign &) const; + bool HasSameCallsignWithWildcard(const CCallsign &) const; bool HasModuleListed(char) const; bool CheckListedModules(char*) const; diff --git a/src/cdcsprotocol.cpp b/src/cdcsprotocol.cpp index 871a435..cbbae76 100644 --- a/src/cdcsprotocol.cpp +++ b/src/cdcsprotocol.cpp @@ -91,7 +91,7 @@ void CDcsProtocol::Task(void) //std::cout << "DCS DV packet" << std::endl; // callsign muted? - if ( g_GateKeeper.MayTransmit(Header->GetMyCallsign(), Ip, PROTOCOL_DCS) ) + if ( g_GateKeeper.MayTransmit(Header->GetMyCallsign(), Ip, PROTOCOL_DCS, Header->GetRpt2Module()) ) { // handle it if ( !OnDvHeaderPacketIn(Header, Ip) ) diff --git a/src/cdextraprotocol.cpp b/src/cdextraprotocol.cpp index 99d1375..6237bc4 100644 --- a/src/cdextraprotocol.cpp +++ b/src/cdextraprotocol.cpp @@ -88,7 +88,7 @@ void CDextraProtocol::Task(void) //std::cout << "DExtra DV header:" << std::endl; // callsign muted? - if ( g_GateKeeper.MayTransmit(Header->GetMyCallsign(), Ip, PROTOCOL_DEXTRA) ) + if ( g_GateKeeper.MayTransmit(Header->GetMyCallsign(), Ip, PROTOCOL_DEXTRA, Header->GetRpt2Module()) ) { // handle it OnDvHeaderPacketIn(Header, Ip); @@ -363,7 +363,7 @@ bool CDextraProtocol::IsValidConnectPacket(const CBuffer &Buffer, CCallsign *cal { *revision = 1; } - else if ( callsign->HasSameCallsignWithWidlcard(CCallsign("XRF*")) ) + else if ( callsign->HasSameCallsignWithWildcard(CCallsign("XRF*")) ) { *revision = 2; } diff --git a/src/cdplusprotocol.cpp b/src/cdplusprotocol.cpp index 08d3c3d..25a9951 100644 --- a/src/cdplusprotocol.cpp +++ b/src/cdplusprotocol.cpp @@ -99,7 +99,7 @@ void CDplusProtocol::Task(void) //std::cout << "DPlus DV header:" << std::endl << *Header << std::endl; // callsign muted? - if ( g_GateKeeper.MayTransmit(Header->GetMyCallsign(), Ip, PROTOCOL_DPLUS) ) + if ( g_GateKeeper.MayTransmit(Header->GetMyCallsign(), Ip, PROTOCOL_DPLUS, Header->GetRpt2Module()) ) { // handle it OnDvHeaderPacketIn(Header, Ip); @@ -225,7 +225,7 @@ bool CDplusProtocol::OnDvHeaderPacketIn(CDvHeaderPacket *Header, const CIp &Ip) if ( client != NULL ) { // now we know if it's a dextra dongle or a genuine dplus node - if ( Header->GetRpt2Callsign().HasSameCallsignWithWidlcard(CCallsign("XRF*")) ) + if ( Header->GetRpt2Callsign().HasSameCallsignWithWildcard(CCallsign("XRF*")) ) { client->SetDextraDongle(); } diff --git a/src/cgatekeeper.cpp b/src/cgatekeeper.cpp index 56f55be..09264ef 100644 --- a/src/cgatekeeper.cpp +++ b/src/cgatekeeper.cpp @@ -138,7 +138,7 @@ bool CGateKeeper::MayTransmit(const CCallsign &callsign, const CIp &ip, int prot case PROTOCOL_DPLUS: case PROTOCOL_DCS: // first check is IP & callsigned listed OK - ok &= IsNodeListedOk(callsign, ip); + ok &= IsNodeListedOk(callsign, ip, module); // todo: then apply any protocol specific authorisation for the operation break; @@ -193,7 +193,7 @@ void CGateKeeper::Thread(CGateKeeper *This) //////////////////////////////////////////////////////////////////////////////////////// // operation helpers -bool CGateKeeper::IsNodeListedOk(const CCallsign &callsign, const CIp &ip) const +bool CGateKeeper::IsNodeListedOk(const CCallsign &callsign, const CIp &ip, char module) const { bool ok = true; @@ -207,13 +207,13 @@ bool CGateKeeper::IsNodeListedOk(const CCallsign &callsign, const CIp &ip) const const_cast(m_NodeWhiteList).Lock(); if ( !m_NodeWhiteList.empty() ) { - ok = m_NodeWhiteList.IsCallsignListed(callsign); + ok = m_NodeWhiteList.IsCallsignListedWithWildcard(callsign, module); } const_cast(m_NodeWhiteList).Unlock(); // then check if not blacklisted const_cast(m_NodeBlackList).Lock(); - ok &= !m_NodeBlackList.IsCallsignListed(callsign); + ok &= !m_NodeBlackList.IsCallsignListedWithWildcard(callsign); const_cast(m_NodeBlackList).Unlock(); } diff --git a/src/cgatekeeper.h b/src/cgatekeeper.h index 599b198..9ee7504 100644 --- a/src/cgatekeeper.h +++ b/src/cgatekeeper.h @@ -60,7 +60,7 @@ protected: static void Thread(CGateKeeper *); // operation helpers - bool IsNodeListedOk(const CCallsign &, const CIp &) const; + bool IsNodeListedOk(const CCallsign &, const CIp &, char = ' ') const; bool IsPeerListedOk(const CCallsign &, const CIp &, char) const; bool IsPeerListedOk(const CCallsign &, const CIp &, char *) const; diff --git a/src/creflector.cpp b/src/creflector.cpp index a094daa..90e0fef 100644 --- a/src/creflector.cpp +++ b/src/creflector.cpp @@ -349,10 +349,12 @@ void CReflector::XmlReportThread(CReflector *This) // and close file xmlFile.close(); } +#ifndef NO_ERROR_ON_XML_OPEN_FAIL else { std::cout << "Failed to open " << XML_PATH << std::endl; } +#endif // and wait a bit CTimePoint::TaskSleepFor(XML_UPDATE_PERIOD * 1000); diff --git a/src/main.h b/src/main.h index 3229fd8..d3bdeac 100644 --- a/src/main.h +++ b/src/main.h @@ -48,12 +48,13 @@ #define VERSION_MAJOR 1 #define VERSION_MINOR 3 -#define VERSION_REVISION 8 +#define VERSION_REVISION 9 // global ------------------------------------------------------ #define RUN_AS_DAEMON #define JSON_MONITOR +//#define NO_ERROR_ON_XML_OPEN_FAIL // reflector ---------------------------------------------------