From 23d39e4594ae4e886d5d09a558154b2636669be8 Mon Sep 17 00:00:00 2001 From: Tom Early Date: Thu, 23 Jul 2020 08:01:00 -0700 Subject: [PATCH] m_Clients and m_Peers are std::shared_ptr --- src/cbmpeer.cpp | 8 +- src/cbptc19696.cpp | 92 +++++------ src/ccallsign.cpp | 8 +- src/ccallsignlist.cpp | 14 +- src/ccallsignlistitem.cpp | 8 +- src/cclient.cpp | 8 +- src/cclient.h | 20 +-- src/cclients.cpp | 48 +++--- src/cclients.h | 34 ++-- src/ccodecstream.cpp | 10 +- src/ccrc.cpp | 72 ++++----- src/cdcsprotocol.cpp | 52 +++---- src/cdcsprotocol.h | 4 +- src/cdextrapeer.cpp | 8 +- src/cdextraprotocol.cpp | 73 ++++----- src/cdmriddir.cpp | 12 +- src/cdmriddirfile.cpp | 32 ++-- src/cdmriddirhttp.cpp | 32 ++-- src/cdmrmmdvmprotocol.cpp | 55 ++++--- src/cdmrmmdvmprotocol.h | 4 +- src/cdmrplusprotocol.cpp | 49 +++--- src/cdplusprotocol.cpp | 53 +++---- src/cdvframepacket.cpp | 2 +- src/cg3protocol.cpp | 78 +++++----- src/cgatekeeper.cpp | 10 +- src/cgatekeeper.h | 2 +- src/cgolay2087.cpp | 22 +-- src/cgolay24128.cpp | 16 +- src/chamming.cpp | 100 ++++++------ src/cip.cpp | 2 +- src/cip.h | 4 +- src/cpacketstream.cpp | 18 +-- src/cpacketstream.h | 6 +- src/cpeer.cpp | 12 +- src/cpeer.h | 12 +- src/cpeercallsignlist.cpp | 6 +- src/cpeers.cpp | 27 ++-- src/cpeers.h | 22 +-- src/cprotocol.cpp | 22 +-- src/cprotocol.h | 6 +- src/cprotocols.h | 2 +- src/cqr1676.cpp | 20 +-- src/creflector.cpp | 52 +++---- src/creflector.h | 2 +- src/crs129.cpp | 23 ++- src/ctranscoder.cpp | 12 +- src/cudpmsgsocket.cpp | 2 +- src/cuser.cpp | 10 +- src/cuser.h | 8 +- src/cutils.cpp | 16 +- src/cwiresxcmdhandler.cpp | 22 +-- src/cxlxpeer.cpp | 9 +- src/cxlxprotocol.cpp | 67 ++++---- src/cxlxprotocol.h | 6 +- src/cysfconvolution.cpp | 54 +++---- src/cysffich.cpp | 47 +++--- src/cysfnodedir.cpp | 10 +- src/cysfnodedirfile.cpp | 36 ++--- src/cysfnodedirhttp.cpp | 38 ++--- src/cysfpayload.cpp | 316 +++++++++++++++++++------------------- src/cysfprotocol.cpp | 82 +++++----- src/cysfprotocol.h | 34 ++-- src/main.h | 1 + 63 files changed, 942 insertions(+), 990 deletions(-) diff --git a/src/cbmpeer.cpp b/src/cbmpeer.cpp index 646328c..b6c336d 100644 --- a/src/cbmpeer.cpp +++ b/src/cbmpeer.cpp @@ -45,10 +45,8 @@ CBmPeer::CBmPeer(const CCallsign &callsign, const CIp &ip, const char *modules, // and construct all xlx clients for ( unsigned i = 0; i < ::strlen(modules); i++ ) { - // create - CBmClient *client = new CBmClient(callsign, ip, modules[i]); - // and append to vector - m_Clients.push_back(client); + // create and append to vector + m_Clients.push_back(std::make_shared(callsign, ip, modules[i])); } } @@ -57,7 +55,7 @@ CBmPeer::CBmPeer(const CBmPeer &peer) { for ( auto it=peer.cbegin(); it!=peer.cend(); it++ ) { - CBmClient *client = new CBmClient((const CBmClient &)*(*it)); + std::shared_ptr client(new CBmClient((const CBmClient &)*(*it))); m_Clients.push_back(client); } diff --git a/src/cbptc19696.cpp b/src/cbptc19696.cpp index fb55052..226fbb0 100644 --- a/src/cbptc19696.cpp +++ b/src/cbptc19696.cpp @@ -37,18 +37,18 @@ CBPTC19696::~CBPTC19696() // The main decode function void CBPTC19696::decode(const unsigned char* in, unsigned char* out) { - assert(in != NULL); - assert(out != NULL); - + assert(in != nullptr); + assert(out != nullptr); + // Get the raw binary decodeExtractBinary(in); - + // Deinterleave decodeDeInterleave(); - + // Error check decodeErrorCheck(); - + // Extract Data decodeExtractData(out); } @@ -56,18 +56,18 @@ void CBPTC19696::decode(const unsigned char* in, unsigned char* out) // The main encode function void CBPTC19696::encode(const unsigned char* in, unsigned char* out) { - assert(in != NULL); - assert(out != NULL); - + assert(in != nullptr); + assert(out != nullptr); + // Extract Data encodeExtractData(in); - + // Error check encodeErrorCheck(); - + // Deinterleave encodeInterleave(); - + // Get the raw binary encodeExtractBinary(out); } @@ -88,13 +88,13 @@ void CBPTC19696::decodeExtractBinary(const unsigned char* in) CUtils::byteToBitsBE(in[10U], m_rawData + 80U); CUtils::byteToBitsBE(in[11U], m_rawData + 88U); CUtils::byteToBitsBE(in[12U], m_rawData + 96U); - + // Handle the two bits bool bits[8U]; CUtils::byteToBitsBE(in[20U], bits); m_rawData[98U] = bits[6U]; m_rawData[99U] = bits[7U]; - + // Second block CUtils::byteToBitsBE(in[21U], m_rawData + 100U); CUtils::byteToBitsBE(in[22U], m_rawData + 108U); @@ -115,7 +115,7 @@ void CBPTC19696::decodeDeInterleave() { for (unsigned int i = 0U; i < 196U; i++) m_deInterData[i] = false; - + // The first bit is R(3) which is not used so can be ignored for (unsigned int a = 0U; a < 196U; a++) { // Calculate the interleave sequence @@ -132,7 +132,7 @@ void CBPTC19696::decodeErrorCheck() unsigned int count = 0U; do { fixing = false; - + // Run through each of the 15 columns bool col[13U]; for (unsigned int c = 0U; c < 15U; c++) { @@ -141,25 +141,25 @@ void CBPTC19696::decodeErrorCheck() col[a] = m_deInterData[pos]; pos = pos + 15U; } - + if (CHamming::decode1393(col)) { unsigned int pos = c + 1U; for (unsigned int a = 0U; a < 13U; a++) { m_deInterData[pos] = col[a]; pos = pos + 15U; } - + fixing = true; } } - + // Run through each of the 9 rows containing data for (unsigned int r = 0U; r < 9U; r++) { unsigned int pos = (r * 15U) + 1U; if (CHamming::decode15113_2(m_deInterData + pos)) fixing = true; } - + count++; } while (fixing && count < 5U); } @@ -171,31 +171,31 @@ void CBPTC19696::decodeExtractData(unsigned char* data) const unsigned int pos = 0U; for (unsigned int a = 4U; a <= 11U; a++, pos++) bData[pos] = m_deInterData[a]; - + for (unsigned int a = 16U; a <= 26U; a++, pos++) bData[pos] = m_deInterData[a]; - + for (unsigned int a = 31U; a <= 41U; a++, pos++) bData[pos] = m_deInterData[a]; - + for (unsigned int a = 46U; a <= 56U; a++, pos++) bData[pos] = m_deInterData[a]; - + for (unsigned int a = 61U; a <= 71U; a++, pos++) bData[pos] = m_deInterData[a]; - + for (unsigned int a = 76U; a <= 86U; a++, pos++) bData[pos] = m_deInterData[a]; - + for (unsigned int a = 91U; a <= 101U; a++, pos++) bData[pos] = m_deInterData[a]; - + for (unsigned int a = 106U; a <= 116U; a++, pos++) bData[pos] = m_deInterData[a]; - + for (unsigned int a = 121U; a <= 131U; a++, pos++) bData[pos] = m_deInterData[a]; - + CUtils::bitsToByteBE(bData + 0U, data[0U]); CUtils::bitsToByteBE(bData + 8U, data[1U]); CUtils::bitsToByteBE(bData + 16U, data[2U]); @@ -226,35 +226,35 @@ void CBPTC19696::encodeExtractData(const unsigned char* in) CUtils::byteToBitsBE(in[9U], bData + 72U); CUtils::byteToBitsBE(in[10U], bData + 80U); CUtils::byteToBitsBE(in[11U], bData + 88U); - + for (unsigned int i = 0U; i < 196U; i++) m_deInterData[i] = false; - + unsigned int pos = 0U; for (unsigned int a = 4U; a <= 11U; a++, pos++) m_deInterData[a] = bData[pos]; - + for (unsigned int a = 16U; a <= 26U; a++, pos++) m_deInterData[a] = bData[pos]; - + for (unsigned int a = 31U; a <= 41U; a++, pos++) m_deInterData[a] = bData[pos]; - + for (unsigned int a = 46U; a <= 56U; a++, pos++) m_deInterData[a] = bData[pos]; - + for (unsigned int a = 61U; a <= 71U; a++, pos++) m_deInterData[a] = bData[pos]; - + for (unsigned int a = 76U; a <= 86U; a++, pos++) m_deInterData[a] = bData[pos]; - + for (unsigned int a = 91U; a <= 101U; a++, pos++) m_deInterData[a] = bData[pos]; - + for (unsigned int a = 106U; a <= 116U; a++, pos++) m_deInterData[a] = bData[pos]; - + for (unsigned int a = 121U; a <= 131U; a++, pos++) m_deInterData[a] = bData[pos]; } @@ -262,13 +262,13 @@ void CBPTC19696::encodeExtractData(const unsigned char* in) // Check each row with a Hamming (15,11,3) code and each column with a Hamming (13,9,3) code void CBPTC19696::encodeErrorCheck() { - + // Run through each of the 9 rows containing data for (unsigned int r = 0U; r < 9U; r++) { unsigned int pos = (r * 15U) + 1U; CHamming::encode15113_2(m_deInterData + pos); } - + // Run through each of the 15 columns bool col[13U]; for (unsigned int c = 0U; c < 15U; c++) { @@ -277,9 +277,9 @@ void CBPTC19696::encodeErrorCheck() col[a] = m_deInterData[pos]; pos = pos + 15U; } - + CHamming::encode1393(col); - + pos = c + 1U; for (unsigned int a = 0U; a < 13U; a++) { m_deInterData[pos] = col[a]; @@ -293,7 +293,7 @@ void CBPTC19696::encodeInterleave() { for (unsigned int i = 0U; i < 196U; i++) m_rawData[i] = false; - + // The first bit is R(3) which is not used so can be ignored for (unsigned int a = 0U; a < 196U; a++) { // Calculate the interleave sequence @@ -318,13 +318,13 @@ void CBPTC19696::encodeExtractBinary(unsigned char* data) CUtils::bitsToByteBE(m_rawData + 72U, data[9U]); CUtils::bitsToByteBE(m_rawData + 80U, data[10U]); CUtils::bitsToByteBE(m_rawData + 88U, data[11U]); - + // Handle the two bits unsigned char byte; CUtils::bitsToByteBE(m_rawData + 96U, byte); data[12U] = (data[12U] & 0x3FU) | ((byte >> 0) & 0xC0U); data[20U] = (data[20U] & 0xFCU) | ((byte >> 4) & 0x03U); - + // Second block CUtils::bitsToByteBE(m_rawData + 100U, data[21U]); CUtils::bitsToByteBE(m_rawData + 108U, data[22U]); diff --git a/src/ccallsign.cpp b/src/ccallsign.cpp index 5dc4694..52dd9bd 100644 --- a/src/ccallsign.cpp +++ b/src/ccallsign.cpp @@ -78,7 +78,7 @@ CCallsign::CCallsign(const char *sz, uint32 dmrid) g_DmridDir.Lock(); { const CCallsign *callsign = g_DmridDir.FindCallsign(m_uiDmrid); - if ( callsign != NULL ) + if ( callsign != nullptr ) { ::memcpy(m_Callsign, callsign->m_Callsign, sizeof(m_Callsign)); } @@ -125,7 +125,7 @@ bool CCallsign::IsValid(void) const // is an letter or space valid &= IsLetter(m_Module) || IsSpace(m_Module); - // dmrid is not tested, as it can be NULL + // dmrid is not tested, as it can be nullptr // if station does is not dmr registered // done @@ -206,7 +206,7 @@ void CCallsign::SetDmrid(uint32 dmrid, bool UpdateCallsign) g_DmridDir.Lock(); { const CCallsign *callsign = g_DmridDir.FindCallsign(dmrid); - if ( callsign != NULL ) + if ( callsign != nullptr ) { ::memcpy(m_Callsign, callsign->m_Callsign, sizeof(m_Callsign)); } @@ -220,7 +220,7 @@ void CCallsign::SetDmrid(const uint8 *buffer, bool UpdateCallsign) char sz[9]; ::memcpy(sz, buffer, 8); sz[8] = 0; - SetDmrid((uint32)::strtol(sz, NULL, 16), UpdateCallsign); + SetDmrid((uint32)::strtol(sz, nullptr, 16), UpdateCallsign); } #endif diff --git a/src/ccallsignlist.cpp b/src/ccallsignlist.cpp index a233735..0169084 100644 --- a/src/ccallsignlist.cpp +++ b/src/ccallsignlist.cpp @@ -34,7 +34,7 @@ CCallsignList::CCallsignList() { - m_Filename = NULL; + m_Filename = nullptr; ::memset(&m_LastModTime, 0, sizeof(time_t)); } @@ -65,13 +65,13 @@ bool CCallsignList::LoadFromFile(const char *filename) if ( (::strlen(szt) > 0) && (szt[0] != '#') ) { // 1st token is callsign - if ( (szt = ::strtok(szt, " ,\t")) != NULL ) + if ( (szt = ::strtok(szt, " ,\t")) != nullptr ) { CCallsign callsign(szt); // 2nd token is modules list - szt = ::strtok(NULL, " ,\t"); + szt = ::strtok(nullptr, " ,\t"); // if token absent, use wildcard - if ( szt == NULL ) + if ( szt == nullptr ) { szt = szStar; } @@ -106,7 +106,7 @@ bool CCallsignList::ReloadFromFile(void) { bool ok = false; - if ( m_Filename != NULL ) + if ( m_Filename != nullptr ) { ok = LoadFromFile(m_Filename); } @@ -185,7 +185,7 @@ CCallsignListItem *CCallsignList::FindListItem(const CCallsign &Callsign) } } - return NULL; + return nullptr; } @@ -217,7 +217,7 @@ bool CCallsignList::GetLastModTime(time_t *time) { bool ok = false; - if ( m_Filename != NULL ) + if ( m_Filename != nullptr ) { struct stat fileStat; if( ::stat(m_Filename, &fileStat) != -1 ) diff --git a/src/ccallsignlistitem.cpp b/src/ccallsignlistitem.cpp index a7d8a76..bd8aa96 100644 --- a/src/ccallsignlistitem.cpp +++ b/src/ccallsignlistitem.cpp @@ -40,7 +40,7 @@ CCallsignListItem::CCallsignListItem(const CCallsign &callsign, const CIp &ip, c m_Callsign = callsign; ::memset(m_szUrl, 0, sizeof(m_szUrl)); m_Ip = ip; - if ( modules != NULL ) + if ( modules != nullptr ) { ::memset(m_Modules, 0, sizeof(m_Modules)); if ( modules[0] == '*' ) @@ -70,7 +70,7 @@ CCallsignListItem::CCallsignListItem(const CCallsign &callsign, const char *url, m_Callsign = callsign; ::strncpy(m_szUrl, url, URL_MAXLEN); m_Ip = CIp(m_szUrl); - if ( modules != NULL ) + if ( modules != nullptr ) { ::memset(m_Modules, 0, sizeof(m_Modules)); if ( modules[0] == '*' ) @@ -119,14 +119,14 @@ bool CCallsignListItem::HasSameCallsignWithWildcard(const CCallsign &callsign) c bool CCallsignListItem::HasModuleListed(char module) const { - return (::strchr(m_Modules, (int)module) != NULL); + return (::strchr(m_Modules, (int)module) != nullptr); } bool CCallsignListItem::CheckListedModules(char *Modules) const { bool listed = false; - if ( Modules != NULL ) + if ( Modules != nullptr ) { // build a list of common modules char list[27]; diff --git a/src/cclient.cpp b/src/cclient.cpp index 99b20ad..c2d2d3e 100644 --- a/src/cclient.cpp +++ b/src/cclient.cpp @@ -35,8 +35,8 @@ CClient::CClient() m_ReflectorModule = ' '; m_ModuleMastered = ' '; m_LastKeepaliveTime.Now(); - m_ConnectTime = std::time(NULL); - m_LastHeardTime = std::time(NULL); + m_ConnectTime = std::time(nullptr); + m_LastHeardTime = std::time(nullptr); } CClient::CClient(const CCallsign &callsign, const CIp &ip, char reflectorModule) @@ -46,8 +46,8 @@ CClient::CClient(const CCallsign &callsign, const CIp &ip, char reflectorModule) m_Ip = ip; m_ModuleMastered = ' '; m_LastKeepaliveTime.Now(); - m_ConnectTime = std::time(NULL); - m_LastHeardTime = std::time(NULL); + m_ConnectTime = std::time(nullptr); + m_LastHeardTime = std::time(nullptr); } CClient::CClient(const CClient &client) diff --git a/src/cclient.h b/src/cclient.h index 3fa2590..4fcb2cc 100644 --- a/src/cclient.h +++ b/src/cclient.h @@ -19,7 +19,7 @@ // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License -// along with Foobar. If not, see . +// along with Foobar. If not, see . // ---------------------------------------------------------------------------- #ifndef cclient_h @@ -43,13 +43,13 @@ public: CClient(); CClient(const CCallsign &, const CIp &, char = ' '); CClient(const CClient &); - + // destructor virtual ~CClient() {}; - + // operators bool operator ==(const CClient &) const; - + // get const CCallsign &GetCallsign(void) const { return m_Callsign; } const CIp &GetIp(void) const { return m_Ip; } @@ -57,11 +57,11 @@ public: char GetModule(void) const { return m_Callsign.GetModule(); } bool HasReflectorModule(void) const { return m_ReflectorModule != ' '; } char GetReflectorModule(void) const { return m_ReflectorModule; } - + // set void SetModule(char c) { m_Callsign.SetModule(c); } void SetReflectorModule(char c) { m_ReflectorModule = c; } - + // identity virtual int GetProtocol(void) const { return PROTOCOL_NONE; } virtual int GetProtocolRevision(void) const { return 0; } @@ -71,15 +71,15 @@ public: virtual bool IsPeer(void) const { return false; } virtual bool IsDextraDongle(void) const { return false; } virtual void SetDextraDongle(void) { } - + // status virtual void Alive(void); virtual bool IsAlive(void) const { return false; } virtual bool IsAMaster(void) const { return (m_ModuleMastered != ' '); } virtual void SetMasterOfModule(char c) { m_ModuleMastered = c; } virtual void NotAMaster(void) { m_ModuleMastered = ' '; } - virtual void Heard(void) { m_LastHeardTime = std::time(NULL); } - + virtual void Heard(void) { m_LastHeardTime = std::time(nullptr); } + // reporting virtual void WriteXml(std::ofstream &); virtual void GetJsonObject(char *); @@ -88,7 +88,7 @@ protected: // data CCallsign m_Callsign; CIp m_Ip; - + // linked to char m_ReflectorModule; diff --git a/src/cclients.cpp b/src/cclients.cpp index f34e4c8..ebbefdd 100644 --- a/src/cclients.cpp +++ b/src/cclients.cpp @@ -42,10 +42,6 @@ CClients::CClients() CClients::~CClients() { m_Mutex.lock(); - for ( auto it=begin(); it!=end(); it++ ) - { - delete *it; - } m_Clients.clear(); m_Mutex.unlock(); } @@ -53,7 +49,7 @@ CClients::~CClients() //////////////////////////////////////////////////////////////////////////////////////// // manage Clients -void CClients::AddClient(CClient *client) +void CClients::AddClient(std::shared_ptrclient) { // first check if client already exists for ( auto it=begin(); it!=end(); it++ ) @@ -64,7 +60,6 @@ void CClients::AddClient(CClient *client) // on function return { // delete new one - delete client; return; } } @@ -82,7 +77,7 @@ void CClients::AddClient(CClient *client) g_Reflector.OnClientsChanged(); } -void CClients::RemoveClient(CClient *client) +void CClients::RemoveClient(std::shared_ptrclient) { // look for the client bool found = false; @@ -101,7 +96,6 @@ void CClients::RemoveClient(CClient *client) std::cout << " on module " << (*it)->GetReflectorModule(); } std::cout << std::endl; - delete *it; m_Clients.erase(it); // notify g_Reflector.OnClientsChanged(); @@ -111,7 +105,7 @@ void CClients::RemoveClient(CClient *client) } } -bool CClients::IsClient(CClient *client) const +bool CClients::IsClient(std::shared_ptrclient) const { for ( auto it=cbegin(); it!=cend(); it++ ) { @@ -124,7 +118,7 @@ bool CClients::IsClient(CClient *client) const //////////////////////////////////////////////////////////////////////////////////////// // find Clients -CClient *CClients::FindClient(const CIp &Ip) +std::shared_ptrCClients::FindClient(const CIp &Ip) { // find client for ( auto it=begin(); it!=end(); it++ ) @@ -136,10 +130,10 @@ CClient *CClients::FindClient(const CIp &Ip) } // done - return NULL; + return nullptr; } -CClient *CClients::FindClient(const CIp &Ip, int Protocol) +std::shared_ptrCClients::FindClient(const CIp &Ip, int Protocol) { // find client for ( auto it=begin(); it!=end(); it++ ) @@ -151,10 +145,10 @@ CClient *CClients::FindClient(const CIp &Ip, int Protocol) } // done - return NULL; + return nullptr; } -CClient *CClients::FindClient(const CIp &Ip, int Protocol, char ReflectorModule) +std::shared_ptrCClients::FindClient(const CIp &Ip, int Protocol, char ReflectorModule) { // find client for ( auto it=begin(); it!=end(); it++ ) @@ -168,10 +162,10 @@ CClient *CClients::FindClient(const CIp &Ip, int Protocol, char ReflectorModule) } // done - return NULL; + return nullptr; } -CClient *CClients::FindClient(const CCallsign &Callsign, const CIp &Ip, int Protocol) +std::shared_ptrCClients::FindClient(const CCallsign &Callsign, const CIp &Ip, int Protocol) { // find client for ( auto it=begin(); it!=end(); it++ ) @@ -184,10 +178,10 @@ CClient *CClients::FindClient(const CCallsign &Callsign, const CIp &Ip, int Prot } } - return NULL; + return nullptr; } -CClient *CClients::FindClient(const CCallsign &Callsign, char module, const CIp &Ip, int Protocol) +std::shared_ptrCClients::FindClient(const CCallsign &Callsign, char module, const CIp &Ip, int Protocol) { // find client for ( auto it=begin(); it!=end(); it++ ) @@ -201,10 +195,10 @@ CClient *CClients::FindClient(const CCallsign &Callsign, char module, const CIp } } - return NULL; + return nullptr; } -CClient *CClients::FindClient(const CCallsign &Callsign, int Protocol) +std::shared_ptrCClients::FindClient(const CCallsign &Callsign, int Protocol) { // find client for ( auto it=begin(); it!=end(); it++ ) @@ -216,13 +210,13 @@ CClient *CClients::FindClient(const CCallsign &Callsign, int Protocol) } } - return NULL; + return nullptr; } //////////////////////////////////////////////////////////////////////////////////////// // iterate on clients -CClient *CClients::FindNextClient(int Protocol, std::list::iterator &it) +std::shared_ptrCClients::FindNextClient(int Protocol, std::list>::iterator &it) { while ( it != end() ) { @@ -232,10 +226,10 @@ CClient *CClients::FindNextClient(int Protocol, std::list::iterator & } it++; } - return NULL; + return nullptr; } -CClient *CClients::FindNextClient(const CIp &Ip, int Protocol, std::list::iterator &it) +std::shared_ptrCClients::FindNextClient(const CIp &Ip, int Protocol, std::list>::iterator &it) { while ( it != end() ) { @@ -246,10 +240,10 @@ CClient *CClients::FindNextClient(const CIp &Ip, int Protocol, std::list::iterator &it) +std::shared_ptrCClients::FindNextClient(const CCallsign &Callsign, const CIp &Ip, int Protocol, std::list>::iterator &it) { while ( it != end() ) { @@ -261,5 +255,5 @@ CClient *CClients::FindNextClient(const CCallsign &Callsign, const CIp &Ip, int } it++; } - return NULL; + return nullptr; } diff --git a/src/cclients.h b/src/cclients.h index 8c7e3a3..37c5ab3 100644 --- a/src/cclients.h +++ b/src/cclients.h @@ -51,33 +51,33 @@ public: // manage Clients int GetSize(void) const { return (int)m_Clients.size(); } - void AddClient(CClient *); - void RemoveClient(CClient *); - bool IsClient(CClient *) const; + void AddClient(std::shared_ptr); + void RemoveClient(std::shared_ptr); + bool IsClient(std::shared_ptr) const; // pass-thru - std::list::iterator begin() { return m_Clients.begin(); } - std::list::iterator end() { return m_Clients.end(); } - std::list::const_iterator cbegin() const { return m_Clients.cbegin(); } - std::list::const_iterator cend() const { return m_Clients.cend(); } + std::list>::iterator begin() { return m_Clients.begin(); } + std::list>::iterator end() { return m_Clients.end(); } + std::list>::const_iterator cbegin() const { return m_Clients.cbegin(); } + std::list>::const_iterator cend() const { return m_Clients.cend(); } // find clients - CClient *FindClient(const CIp &); - CClient *FindClient(const CIp &, int); - CClient *FindClient(const CIp &, int, char); - CClient *FindClient(const CCallsign &, const CIp &, int); - CClient *FindClient(const CCallsign &, char, const CIp &, int); - CClient *FindClient(const CCallsign &, int); + std::shared_ptrFindClient(const CIp &); + std::shared_ptrFindClient(const CIp &, int); + std::shared_ptrFindClient(const CIp &, int, char); + std::shared_ptrFindClient(const CCallsign &, const CIp &, int); + std::shared_ptrFindClient(const CCallsign &, char, const CIp &, int); + std::shared_ptrFindClient(const CCallsign &, int); // iterate on clients - CClient *FindNextClient(int, std::list::iterator &); - CClient *FindNextClient(const CIp &, int, std::list::iterator &); - CClient *FindNextClient(const CCallsign &, const CIp &, int, std::list::iterator &); + std::shared_ptrFindNextClient(int, std::list>::iterator &); + std::shared_ptrFindNextClient(const CIp &, int, std::list>::iterator &); + std::shared_ptrFindNextClient(const CCallsign &, const CIp &, int, std::list>::iterator &); protected: // data std::mutex m_Mutex; - std::list m_Clients; + std::list> m_Clients; }; diff --git a/src/ccodecstream.cpp b/src/ccodecstream.cpp index 5354f5c..1803cdd 100644 --- a/src/ccodecstream.cpp +++ b/src/ccodecstream.cpp @@ -39,7 +39,7 @@ CCodecStream::CCodecStream(CPacketStream *PacketStream, uint16 uiId, uint8 uiCodecIn, uint8 uiCodecOut) { keep_running = true; - m_pThread = NULL; + m_pThread = nullptr; m_uiStreamId = uiId; m_uiPid = 0; m_uiCodecIn = uiCodecIn; @@ -64,11 +64,11 @@ CCodecStream::~CCodecStream() // kill threads keep_running = false; - if ( m_pThread != NULL ) + if ( m_pThread != nullptr ) { m_pThread->join(); delete m_pThread; - m_pThread = NULL; + m_pThread = nullptr; } // empty local queue @@ -141,11 +141,11 @@ void CCodecStream::Close(void) m_Socket.Close(); // kill threads - if ( m_pThread != NULL ) + if ( m_pThread != nullptr ) { m_pThread->join(); delete m_pThread; - m_pThread = NULL; + m_pThread = nullptr; } } diff --git a/src/ccrc.cpp b/src/ccrc.cpp index a69ed8d..934b7cd 100644 --- a/src/ccrc.cpp +++ b/src/ccrc.cpp @@ -120,127 +120,127 @@ const uint16_t CCITT16_TABLE2[] = { bool CCRC::checkFiveBit(bool* in, unsigned int tcrc) { - assert(in != NULL); - + assert(in != nullptr); + unsigned int crc; encodeFiveBit(in, crc); - + return crc == tcrc; } void CCRC::encodeFiveBit(const bool* in, unsigned int& tcrc) { - assert(in != NULL); - + assert(in != nullptr); + unsigned short total = 0U; for (unsigned int i = 0U; i < 72U; i += 8U) { unsigned char c; CUtils::bitsToByteBE(in + i, c); total += c; } - + total %= 31U; - + tcrc = total; } void CCRC::addCCITT162(unsigned char *in, unsigned int length) { - assert(in != NULL); + assert(in != nullptr); assert(length > 2U); - + union { uint16_t crc16; uint8_t crc8[2U]; }; - + crc16 = 0U; - + for (unsigned i = 0U; i < (length - 2U); i++) crc16 = (uint16_t(crc8[0U]) << 8) ^ CCITT16_TABLE2[crc8[1U] ^ in[i]]; - + crc16 = ~crc16; - + in[length - 1U] = crc8[0U]; in[length - 2U] = crc8[1U]; } bool CCRC::checkCCITT162(const unsigned char *in, unsigned int length) { - assert(in != NULL); + assert(in != nullptr); assert(length > 2U); - + union { uint16_t crc16; uint8_t crc8[2U]; }; - + crc16 = 0U; - + for (unsigned i = 0U; i < (length - 2U); i++) crc16 = (uint16_t(crc8[0U]) << 8) ^ CCITT16_TABLE2[crc8[1U] ^ in[i]]; - + crc16 = ~crc16; - + return crc8[0U] == in[length - 1U] && crc8[1U] == in[length - 2U]; } void CCRC::addCCITT161(unsigned char *in, unsigned int length) { - assert(in != NULL); + assert(in != nullptr); assert(length > 2U); - + union { uint16_t crc16; uint8_t crc8[2U]; }; - + crc16 = 0xFFFFU; - + for (unsigned int i = 0U; i < (length - 2U); i++) crc16 = uint16_t(crc8[1U]) ^ CCITT16_TABLE1[crc8[0U] ^ in[i]]; - + crc16 = ~crc16; - + in[length - 2U] = crc8[0U]; in[length - 1U] = crc8[1U]; } bool CCRC::checkCCITT161(const unsigned char *in, unsigned int length) { - assert(in != NULL); + assert(in != nullptr); assert(length > 2U); - + union { uint16_t crc16; uint8_t crc8[2U]; }; - + crc16 = 0xFFFFU; - + for (unsigned int i = 0U; i < (length - 2U); i++) crc16 = uint16_t(crc8[1U]) ^ CCITT16_TABLE1[crc8[0U] ^ in[i]]; - + crc16 = ~crc16; - + return crc8[0U] == in[length - 2U] && crc8[1U] == in[length - 1U]; } unsigned char CCRC::crc8(const unsigned char *in, unsigned int length) { - assert(in != NULL); - + assert(in != nullptr); + uint8_t crc = 0U; - + for (unsigned int i = 0U; i < length; i++) crc = CRC8_TABLE[crc ^ in[i]]; - + return crc; } unsigned char CCRC::addCRC(const unsigned char* in, unsigned int length) { - assert(in != NULL); + assert(in != nullptr); unsigned char crc = 0U; diff --git a/src/cdcsprotocol.cpp b/src/cdcsprotocol.cpp index 4fb4c9d..f7cca2f 100644 --- a/src/cdcsprotocol.cpp +++ b/src/cdcsprotocol.cpp @@ -113,11 +113,8 @@ void CDcsProtocol::Task(void) EncodeConnectAckPacket(Callsign, ToLinkModule, &Buffer); Send(Buffer, Ip); - // create the client - CDcsClient *client = new CDcsClient(Callsign, Ip, ToLinkModule); - - // and append - g_Reflector.GetClients()->AddClient(client); + // create the client and append + g_Reflector.GetClients()->AddClient(std::make_shared(Callsign, Ip, ToLinkModule)); g_Reflector.ReleaseClients(); } else @@ -143,8 +140,8 @@ void CDcsProtocol::Task(void) // find client CClients *clients = g_Reflector.GetClients(); - CClient *client = clients->FindClient(Ip, PROTOCOL_DCS); - if ( client != NULL ) + std::shared_ptrclient = clients->FindClient(Ip, PROTOCOL_DCS); + if ( client != nullptr ) { // remove it clients->RemoveClient(client); @@ -161,8 +158,8 @@ void CDcsProtocol::Task(void) // find all clients with that callsign & ip and keep them alive CClients *clients = g_Reflector.GetClients(); auto it = clients->begin(); - CClient *client = NULL; - while ( (client = clients->FindNextClient(Callsign, Ip, PROTOCOL_DCS, it)) != NULL ) + std::shared_ptrclient = nullptr; + while ( (client = clients->FindNextClient(Callsign, Ip, PROTOCOL_DCS, it)) != nullptr ) { client->Alive(); } @@ -206,19 +203,19 @@ bool CDcsProtocol::OnDvHeaderPacketIn(CDvHeaderPacket *Header, const CIp &Ip) // find the stream CPacketStream *stream = GetStream(Header->GetStreamId()); - if ( stream == NULL ) + if ( stream == nullptr ) { // no stream open yet, open a new one CCallsign via(Header->GetRpt1Callsign()); // find this client - CClient *client = g_Reflector.GetClients()->FindClient(Ip, PROTOCOL_DCS); - if ( client != NULL ) + std::shared_ptrclient = g_Reflector.GetClients()->FindClient(Ip, PROTOCOL_DCS); + if ( client != nullptr ) { // get client callsign via = client->GetCallsign(); // and try to open the stream - if ( (stream = g_Reflector.OpenStream(Header, client)) != NULL ) + if ( (stream = g_Reflector.OpenStream(Header, client)) != nullptr ) { // keep the handle m_Streams.push_back(stream); @@ -300,8 +297,8 @@ void CDcsProtocol::HandleQueue(void) // and push it to all our clients linked to the module and who are not streaming in CClients *clients = g_Reflector.GetClients(); auto it = clients->begin(); - CClient *client = NULL; - while ( (client = clients->FindNextClient(PROTOCOL_DCS, it)) != NULL ) + std::shared_ptrclient = nullptr; + while ( (client = clients->FindNextClient(PROTOCOL_DCS, it)) != nullptr ) { // is this client busy ? if ( !client->IsAMaster() && (client->GetReflectorModule() == packet->GetModuleId()) ) @@ -335,8 +332,8 @@ void CDcsProtocol::HandleKeepalives(void) // iterate on clients CClients *clients = g_Reflector.GetClients(); auto it = clients->begin(); - CClient *client = NULL; - while ( (client = clients->FindNextClient(PROTOCOL_DCS, it)) != NULL ) + std::shared_ptrclient = nullptr; + while ( (client = clients->FindNextClient(PROTOCOL_DCS, it)) != nullptr ) { // encode client's specific keepalive packet CBuffer keepalive2; @@ -419,27 +416,24 @@ bool CDcsProtocol::IsValidDvPacket(const CBuffer &Buffer, CDvHeaderPacket **head uint8 tag[] = { '0','0','0','1' }; bool valid = false; - *header = NULL; - *frame = NULL; + *header = nullptr; + *frame = nullptr; if ( (Buffer.size() >= 100) && (Buffer.Compare(tag, sizeof(tag)) == 0) ) { // get the header - *header = new CDvHeaderPacket((struct dstar_header *)&(Buffer.data()[4]), - *((uint16 *)&(Buffer.data()[43])), 0x80); + *header = new CDvHeaderPacket((struct dstar_header *)&(Buffer.data()[4]), *((uint16 *)&(Buffer.data()[43])), 0x80); // get the frame if ( ((Buffer.data()[45]) & 0x40) != 0 ) { // it's the last frame - *frame = new CDvLastFramePacket((struct dstar_dvframe *)&(Buffer.data()[46]), - *((uint16 *)&(Buffer.data()[43])), Buffer.data()[45]); + *frame = new CDvLastFramePacket((struct dstar_dvframe *)&(Buffer.data()[46]), *((uint16 *)&(Buffer.data()[43])), Buffer.data()[45]); } else { // it's a regular DV frame - *frame = new CDvFramePacket((struct dstar_dvframe *)&(Buffer.data()[46]), - *((uint16 *)&(Buffer.data()[43])), Buffer.data()[45]); + *frame = new CDvFramePacket((struct dstar_dvframe *)&(Buffer.data()[46]), *((uint16 *)&(Buffer.data()[43])), Buffer.data()[45]); } // check validity of packets @@ -447,8 +441,8 @@ bool CDcsProtocol::IsValidDvPacket(const CBuffer &Buffer, CDvHeaderPacket **head { delete *header; delete *frame; - *header = NULL; - *frame = NULL; + *header = nullptr; + *frame = nullptr; } else { @@ -480,7 +474,7 @@ void CDcsProtocol::EncodeKeepAlivePacket(CBuffer *Buffer) Buffer->Set(GetReflectorCallsign()); } -void CDcsProtocol::EncodeKeepAlivePacket(CBuffer *Buffer, CClient *Client) +void CDcsProtocol::EncodeKeepAlivePacket(CBuffer *Buffer, std::shared_ptrClient) { uint8 tag[] = { 0x0A,0x00,0x20,0x20 }; @@ -519,7 +513,7 @@ void CDcsProtocol::EncodeConnectNackPacket(const CCallsign &Callsign, char Refle Buffer->Append(tag, sizeof(tag)); } -void CDcsProtocol::EncodeDisconnectPacket(CBuffer *Buffer, CClient *Client) +void CDcsProtocol::EncodeDisconnectPacket(CBuffer *Buffer, std::shared_ptrClient) { Buffer->Set((uint8 *)(const char *)Client->GetCallsign(), CALLSIGN_LEN-1); Buffer->Append((uint8)' '); diff --git a/src/cdcsprotocol.h b/src/cdcsprotocol.h index 36501ff..3791fcd 100644 --- a/src/cdcsprotocol.h +++ b/src/cdcsprotocol.h @@ -75,10 +75,10 @@ protected: // packet encoding helpers void EncodeKeepAlivePacket(CBuffer *); - void EncodeKeepAlivePacket(CBuffer *, CClient *); + void EncodeKeepAlivePacket(CBuffer *, std::shared_ptr); void EncodeConnectAckPacket(const CCallsign &, char, CBuffer *); void EncodeConnectNackPacket(const CCallsign &, char, CBuffer *); - void EncodeDisconnectPacket(CBuffer *, CClient *); + void EncodeDisconnectPacket(CBuffer *, std::shared_ptr); void EncodeDvPacket(const CDvHeaderPacket &, const CDvFramePacket &, uint32, CBuffer *) const; void EncodeDvLastPacket(const CDvHeaderPacket &, const CDvFramePacket &, uint32, CBuffer *) const; diff --git a/src/cdextrapeer.cpp b/src/cdextrapeer.cpp index e169010..8be01d9 100644 --- a/src/cdextrapeer.cpp +++ b/src/cdextrapeer.cpp @@ -46,10 +46,8 @@ CDextraPeer::CDextraPeer(const CCallsign &callsign, const CIp &ip, const char *m // and construct the DExtra clients for ( unsigned i = 0; i < ::strlen(modules); i++ ) { - // create - CDextraClient *client = new CDextraClient(callsign, ip, modules[i], version.GetMajor()); - // and append to vector - m_Clients.push_back(client); + // create and append to vector + m_Clients.push_back(std::make_shared(callsign, ip, modules[i], version.GetMajor())); } } @@ -58,7 +56,7 @@ CDextraPeer::CDextraPeer(const CDextraPeer &peer) { for ( auto it=peer.cbegin(); it!=peer.cend(); it++ ) { - CDextraClient *client = new CDextraClient((const CDextraClient &)*(*it)); + std::shared_ptr client(new CDextraClient((const CDextraClient &)*(*it))); m_Clients.push_back(client); } diff --git a/src/cdextraprotocol.cpp b/src/cdextraprotocol.cpp index 5f05cbd..8b52b11 100644 --- a/src/cdextraprotocol.cpp +++ b/src/cdextraprotocol.cpp @@ -75,14 +75,14 @@ void CDextraProtocol::Task(void) #endif { // crack the packet - if ( (Frame = IsValidDvFramePacket(Buffer)) != NULL ) + if ( (Frame = IsValidDvFramePacket(Buffer)) != nullptr ) { //std::cout << "DExtra DV frame" << std::endl; // handle it OnDvFramePacketIn(Frame, &Ip); } - else if ( (Header = IsValidDvHeaderPacket(Buffer)) != NULL ) + else if ( (Header = IsValidDvHeaderPacket(Buffer)) != nullptr ) { //std::cout << "DExtra DV header:" << std::endl << *Header << std::endl; //std::cout << "DExtra DV header:" << std::endl; @@ -98,7 +98,7 @@ void CDextraProtocol::Task(void) delete Header; } } - else if ( (LastFrame = IsValidDvLastFramePacket(Buffer)) != NULL ) + else if ( (LastFrame = IsValidDvLastFramePacket(Buffer)) != nullptr ) { //std::cout << "DExtra DV last frame" << std::endl; @@ -118,21 +118,19 @@ void CDextraProtocol::Task(void) // is this an ack for a link request? CPeerCallsignList *list = g_GateKeeper.GetPeerList(); CCallsignListItem *item = list->FindListItem(Callsign); - if ( item != NULL && Callsign.GetModule() == item->GetModules()[1] && ToLinkModule == item->GetModules()[0] ) + if ( item != nullptr && Callsign.GetModule() == item->GetModules()[1] && ToLinkModule == item->GetModules()[0] ) { std::cout << "DExtra ack packet for module " << ToLinkModule << " from " << Callsign << " at " << Ip << std::endl; // already connected ? CPeers *peers = g_Reflector.GetPeers(); - if ( peers->FindPeer(Callsign, Ip, PROTOCOL_DEXTRA) == NULL ) + if ( peers->FindPeer(Callsign, Ip, PROTOCOL_DEXTRA) == nullptr ) { // create the new peer // this also create one client per module - CPeer *peer = new CDextraPeer(Callsign, Ip, std::string(1, ToLinkModule).c_str(), CVersion(2, 0, 0)); - // append the peer to reflector peer list // this also add all new clients to reflector client list - peers->AddPeer(peer); + peers->AddPeer(std::make_shared(Callsign, Ip, std::string(1, ToLinkModule).c_str(), CVersion(2, 0, 0))); } g_Reflector.ReleasePeers(); } @@ -142,11 +140,8 @@ void CDextraProtocol::Task(void) EncodeConnectAckPacket(&Buffer, ProtRev); Send(Buffer, Ip); - // create the client - CDextraClient *client = new CDextraClient(Callsign, Ip, ToLinkModule, ProtRev); - - // and append - g_Reflector.GetClients()->AddClient(client); + // create the client and append + g_Reflector.GetClients()->AddClient(std::make_shared(Callsign, Ip, ToLinkModule, ProtRev)); g_Reflector.ReleaseClients(); } g_GateKeeper.ReleasePeerList(); @@ -173,8 +168,8 @@ void CDextraProtocol::Task(void) // find client & remove it CClients *clients = g_Reflector.GetClients(); - CClient *client = clients->FindClient(Ip, PROTOCOL_DEXTRA); - if ( client != NULL ) + std::shared_ptrclient = clients->FindClient(Ip, PROTOCOL_DEXTRA); + if ( client != nullptr ) { // ack disconnect packet if ( client->GetProtocolRevision() == 1 ) @@ -198,8 +193,8 @@ void CDextraProtocol::Task(void) // find all clients with that callsign & ip and keep them alive CClients *clients = g_Reflector.GetClients(); auto it = clients->begin(); - CClient *client = NULL; - while ( (client = clients->FindNextClient(Callsign, Ip, PROTOCOL_DEXTRA, it)) != NULL ) + std::shared_ptrclient = nullptr; + while ( (client = clients->FindNextClient(Callsign, Ip, PROTOCOL_DEXTRA, it)) != nullptr ) { client->Alive(); } @@ -258,8 +253,8 @@ void CDextraProtocol::HandleQueue(void) // and push it to all our clients linked to the module and who are not streaming in CClients *clients = g_Reflector.GetClients(); auto it = clients->begin(); - CClient *client = NULL; - while ( (client = clients->FindNextClient(PROTOCOL_DEXTRA, it)) != NULL ) + std::shared_ptrclient = nullptr; + while ( (client = clients->FindNextClient(PROTOCOL_DEXTRA, it)) != nullptr ) { // is this client busy ? if ( !client->IsAMaster() && (client->GetReflectorModule() == packet->GetModuleId()) ) @@ -296,8 +291,8 @@ void CDextraProtocol::HandleKeepalives(void) // iterate on clients CClients *clients = g_Reflector.GetClients(); auto it = clients->begin(); - CClient *client = NULL; - while ( (client = clients->FindNextClient(PROTOCOL_DEXTRA, it)) != NULL ) + std::shared_ptrclient = nullptr; + while ( (client = clients->FindNextClient(PROTOCOL_DEXTRA, it)) != nullptr ) { // send keepalive Send(keepalive, client->GetIp()); @@ -312,8 +307,8 @@ void CDextraProtocol::HandleKeepalives(void) else if ( !client->IsAlive() ) { CPeers *peers = g_Reflector.GetPeers(); - CPeer *peer = peers->FindPeer(client->GetCallsign(), client->GetIp(), PROTOCOL_DEXTRA); - if ( peer != NULL && peer->GetReflectorModules()[0] == client->GetReflectorModule() ) + std::shared_ptrpeer = peers->FindPeer(client->GetCallsign(), client->GetIp(), PROTOCOL_DEXTRA); + if ( peer != nullptr && peer->GetReflectorModules()[0] == client->GetReflectorModule() ) { // no, but this is a peer client, so it will be handled below } @@ -337,8 +332,8 @@ void CDextraProtocol::HandleKeepalives(void) // iterate on peers CPeers *peers = g_Reflector.GetPeers(); auto pit = peers->begin(); - CPeer *peer = NULL; - while ( (peer = peers->FindNextPeer(PROTOCOL_DEXTRA, pit)) != NULL ) + std::shared_ptrpeer = nullptr; + while ( (peer = peers->FindNextPeer(PROTOCOL_DEXTRA, pit)) != nullptr ) { // keepalives are sent between clients @@ -377,10 +372,10 @@ void CDextraProtocol::HandlePeerLinks(void) // check if all our connected peers are still listed by gatekeeper // if not, disconnect auto pit = peers->begin(); - CPeer *peer = NULL; - while ( (peer = peers->FindNextPeer(PROTOCOL_DEXTRA, pit)) != NULL ) + std::shared_ptrpeer = nullptr; + while ( (peer = peers->FindNextPeer(PROTOCOL_DEXTRA, pit)) != nullptr ) { - if ( list->FindListItem(peer->GetCallsign()) == NULL ) + if ( list->FindListItem(peer->GetCallsign()) == nullptr ) { // send disconnect packet EncodeDisconnectPacket(&buffer, peer->GetReflectorModules()[0]); @@ -399,7 +394,7 @@ void CDextraProtocol::HandlePeerLinks(void) continue; if ( strlen((*it).GetModules()) != 2 ) continue; - if ( peers->FindPeer((*it).GetCallsign(), PROTOCOL_DEXTRA) == NULL ) + if ( peers->FindPeer((*it).GetCallsign(), PROTOCOL_DEXTRA) == nullptr ) { // resolve again peer's IP in case it's a dynamic IP (*it).ResolveIp(); @@ -424,14 +419,14 @@ bool CDextraProtocol::OnDvHeaderPacketIn(CDvHeaderPacket *Header, const CIp &Ip) // find the stream CPacketStream *stream = GetStream(Header->GetStreamId()); - if ( stream == NULL ) + if ( stream == nullptr ) { // no stream open yet, open a new one CCallsign via(Header->GetRpt1Callsign()); // find this client - CClient *client = g_Reflector.GetClients()->FindClient(Ip, PROTOCOL_DEXTRA); - if ( client != NULL ) + std::shared_ptrclient = g_Reflector.GetClients()->FindClient(Ip, PROTOCOL_DEXTRA); + if ( client != nullptr ) { // get client callsign via = client->GetCallsign(); @@ -443,7 +438,7 @@ bool CDextraProtocol::OnDvHeaderPacketIn(CDvHeaderPacket *Header, const CIp &Ip) Header->SetRpt2Module(client->GetReflectorModule()); } // and try to open the stream - if ( (stream = g_Reflector.OpenStream(Header, client)) != NULL ) + if ( (stream = g_Reflector.OpenStream(Header, client)) != nullptr ) { // keep the handle m_Streams.push_back(stream); @@ -531,7 +526,7 @@ bool CDextraProtocol::IsValidKeepAlivePacket(const CBuffer &Buffer, CCallsign *c CDvHeaderPacket *CDextraProtocol::IsValidDvHeaderPacket(const CBuffer &Buffer) { - CDvHeaderPacket *header = NULL; + CDvHeaderPacket *header = nullptr; if ( (Buffer.size() == 56) && (Buffer.Compare((uint8 *)"DSVT", 4) == 0) && (Buffer.data()[4] == 0x10) && (Buffer.data()[8] == 0x20) ) @@ -543,7 +538,7 @@ CDvHeaderPacket *CDextraProtocol::IsValidDvHeaderPacket(const CBuffer &Buffer) if ( !header->IsValid() ) { delete header; - header = NULL; + header = nullptr; } } return header; @@ -551,7 +546,7 @@ CDvHeaderPacket *CDextraProtocol::IsValidDvHeaderPacket(const CBuffer &Buffer) CDvFramePacket *CDextraProtocol::IsValidDvFramePacket(const CBuffer &Buffer) { - CDvFramePacket *dvframe = NULL; + CDvFramePacket *dvframe = nullptr; if ( (Buffer.size() == 27) && (Buffer.Compare((uint8 *)"DSVT", 4) == 0) && (Buffer.data()[4] == 0x20) && (Buffer.data()[8] == 0x20) && @@ -564,7 +559,7 @@ CDvFramePacket *CDextraProtocol::IsValidDvFramePacket(const CBuffer &Buffer) if ( !dvframe->IsValid() ) { delete dvframe; - dvframe = NULL; + dvframe = nullptr; } } return dvframe; @@ -572,7 +567,7 @@ CDvFramePacket *CDextraProtocol::IsValidDvFramePacket(const CBuffer &Buffer) CDvLastFramePacket *CDextraProtocol::IsValidDvLastFramePacket(const CBuffer &Buffer) { - CDvLastFramePacket *dvframe = NULL; + CDvLastFramePacket *dvframe = nullptr; if ( (Buffer.size() == 27) && (Buffer.Compare((uint8 *)"DSVT", 4) == 0) && (Buffer.data()[4] == 0x20) && (Buffer.data()[8] == 0x20) && @@ -585,7 +580,7 @@ CDvLastFramePacket *CDextraProtocol::IsValidDvLastFramePacket(const CBuffer &Buf if ( !dvframe->IsValid() ) { delete dvframe; - dvframe = NULL; + dvframe = nullptr; } } return dvframe; diff --git a/src/cdmriddir.cpp b/src/cdmriddir.cpp index 32ef787..4ced138 100644 --- a/src/cdmriddir.cpp +++ b/src/cdmriddir.cpp @@ -35,18 +35,18 @@ CDmridDir::CDmridDir() { keep_running = true; - m_pThread = NULL; + m_pThread = nullptr; } CDmridDir::~CDmridDir() { // kill threads keep_running = false; - if ( m_pThread != NULL ) + if ( m_pThread != nullptr ) { m_pThread->join(); delete m_pThread; - m_pThread = NULL; + m_pThread = nullptr; } } @@ -71,11 +71,11 @@ bool CDmridDir::Init(void) void CDmridDir::Close(void) { keep_running = false; - if ( m_pThread != NULL ) + if ( m_pThread != nullptr ) { m_pThread->join(); delete m_pThread; - m_pThread = NULL; + m_pThread = nullptr; } } @@ -128,7 +128,7 @@ const CCallsign *CDmridDir::FindCallsign(uint32 dmrid) { return &(found->second); } - return NULL; + return nullptr; } uint32 CDmridDir::FindDmrid(const CCallsign &callsign) diff --git a/src/cdmriddirfile.cpp b/src/cdmriddirfile.cpp index 29a921b..61dcb5f 100644 --- a/src/cdmriddirfile.cpp +++ b/src/cdmriddirfile.cpp @@ -56,7 +56,7 @@ bool CDmridDirFile::Init(void) bool CDmridDirFile::NeedReload(void) { bool needReload = false; - + time_t time; if ( GetLastModTime(&time) ) { @@ -70,7 +70,7 @@ bool CDmridDirFile::LoadContent(CBuffer *buffer) bool ok = false; std::ifstream file; std::streampos size; - + // open file file.open(DMRIDDB_PATH, std::ios::in | std::ios::binary | std::ios::ate); if ( file.is_open() ) @@ -83,18 +83,18 @@ bool CDmridDirFile::LoadContent(CBuffer *buffer) buffer->resize((int)size+1); file.seekg (0, std::ios::beg); file.read((char *)buffer->data(), (int)size); - + // close file file.close(); - + // update time GetLastModTime(&m_LastModTime); - + // done ok = true; } } - + // done return ok; } @@ -102,28 +102,28 @@ bool CDmridDirFile::LoadContent(CBuffer *buffer) bool CDmridDirFile::RefreshContent(const CBuffer &buffer) { bool ok = false; - + // clear directory m_CallsignMap.clear(); m_DmridMap.clear(); - + // scan buffer if ( buffer.size() > 0 ) { // crack it char *ptr1 = (char *)buffer.data(); char *ptr2; - + // get next line - while ( (ptr2 = ::strchr(ptr1, '\n')) != NULL ) + while ( (ptr2 = ::strchr(ptr1, '\n')) != nullptr ) { *ptr2 = 0; // get items char *dmrid; char *callsign; - if ( ((dmrid = ::strtok(ptr1, ";")) != NULL) && IsValidDmrid(dmrid) ) + if ( ((dmrid = ::strtok(ptr1, ";")) != nullptr) && IsValidDmrid(dmrid) ) { - if ( ((callsign = ::strtok(NULL, ";")) != NULL) ) + if ( ((callsign = ::strtok(nullptr, ";")) != nullptr) ) { // new entry uint32 ui = atoi(dmrid); @@ -138,14 +138,14 @@ bool CDmridDirFile::RefreshContent(const CBuffer &buffer) // next line ptr1 = ptr2+1; } - + // done ok = true; } - + // report std::cout << "Read " << m_DmridMap.size() << " DMR ids from file " << DMRIDDB_PATH << std::endl; - + // done return ok; } @@ -154,7 +154,7 @@ bool CDmridDirFile::RefreshContent(const CBuffer &buffer) bool CDmridDirFile::GetLastModTime(time_t *time) { bool ok = false; - + struct stat fileStat; if( ::stat(DMRIDDB_PATH, &fileStat) != -1 ) { diff --git a/src/cdmriddirhttp.cpp b/src/cdmriddirhttp.cpp index f92246a..6a4fbb2 100644 --- a/src/cdmriddirhttp.cpp +++ b/src/cdmriddirhttp.cpp @@ -50,22 +50,22 @@ bool CDmridDirHttp::RefreshContent(const CBuffer &buffer) // clear directory m_CallsignMap.clear(); m_DmridMap.clear(); - + // scan file if ( buffer.size() > 0 ) { char *ptr1 = (char *)buffer.data(); char *ptr2; // get next line - while ( (ptr2 = ::strchr(ptr1, '\n')) != NULL ) + while ( (ptr2 = ::strchr(ptr1, '\n')) != nullptr ) { *ptr2 = 0; // get items char *dmrid; char *callsign; - if ( ((dmrid = ::strtok(ptr1, ";")) != NULL) && IsValidDmrid(dmrid) ) + if ( ((dmrid = ::strtok(ptr1, ";")) != nullptr) && IsValidDmrid(dmrid) ) { - if ( ((callsign = ::strtok(NULL, ";")) != NULL) ) + if ( ((callsign = ::strtok(nullptr, ";")) != nullptr) ) { // new entry uint32 ui = atoi(dmrid); @@ -83,10 +83,10 @@ bool CDmridDirHttp::RefreshContent(const CBuffer &buffer) // done ok = true; } - + // report std::cout << "Read " << m_DmridMap.size() << " DMR ids from xlxapi.rlx.lu database " << std::endl; - + // done return ok; } @@ -101,7 +101,7 @@ bool CDmridDirHttp::HttpGet(const char *hostname, const char *filename, int port { bool ok = false; int sock_id; - + // open socket if ( (sock_id = ::socket(AF_INET, SOCK_STREAM, 0)) >= 0 ) { @@ -109,13 +109,13 @@ bool CDmridDirHttp::HttpGet(const char *hostname, const char *filename, int port struct sockaddr_in servaddr; struct hostent *hp; ::memset(&servaddr,0,sizeof(servaddr)); - if( (hp = gethostbyname(hostname)) != NULL ) + if( (hp = gethostbyname(hostname)) != nullptr ) { // dns resolved ::memcpy((char *)&servaddr.sin_addr.s_addr, (char *)hp->h_addr, hp->h_length); servaddr.sin_port = htons(port); servaddr.sin_family = AF_INET; - + // connect if ( ::connect(sock_id, (struct sockaddr *)&servaddr, sizeof(servaddr)) == 0) { @@ -124,7 +124,7 @@ bool CDmridDirHttp::HttpGet(const char *hostname, const char *filename, int port ::sprintf(request, "GET /%s HTTP/1.0\r\nFrom: %s\r\nUser-Agent: xlxd\r\n\r\n", filename, (const char *)g_Reflector.GetCallsign()); ::write(sock_id, request, strlen(request)); - + // config receive timeouts fd_set read_set; struct timeval timeout; @@ -132,7 +132,7 @@ bool CDmridDirHttp::HttpGet(const char *hostname, const char *filename, int port timeout.tv_usec = 0; FD_ZERO(&read_set); FD_SET(sock_id, &read_set); - + // get the reply back buffer->clear(); bool done = false; @@ -140,7 +140,7 @@ bool CDmridDirHttp::HttpGet(const char *hostname, const char *filename, int port { char buf[1440]; ssize_t len = 0; - select(sock_id+1, &read_set, NULL, NULL, &timeout); + select(sock_id+1, &read_set, nullptr, nullptr, &timeout); //if ( (ret > 0) || ((ret < 0) && (errno == EINPROGRESS)) ) //if ( ret >= 0 ) //{ @@ -153,10 +153,10 @@ bool CDmridDirHttp::HttpGet(const char *hostname, const char *filename, int port } //} done = (len <= 0); - + } while (!done); buffer->Append((uint8)0); - + // and disconnect close(sock_id); } @@ -169,13 +169,13 @@ bool CDmridDirHttp::HttpGet(const char *hostname, const char *filename, int port { std::cout << "Host " << hostname << " not found" << std::endl; } - + } else { std::cout << "Failed to open wget socket" << std::endl; } - + // done return ok; } diff --git a/src/cdmrmmdvmprotocol.cpp b/src/cdmrmmdvmprotocol.cpp index 54b6c00..8be9c81 100644 --- a/src/cdmrmmdvmprotocol.cpp +++ b/src/cdmrmmdvmprotocol.cpp @@ -57,7 +57,7 @@ static uint8 g_DmrSyncMSData[] = { 0x0D,0x5D,0x7F,0x77,0xFD,0x75,0x70 }; bool CDmrmmdvmProtocol::Init(void) { // base class - if (! Initialize(NULL, DMRMMDVM_PORT, DMR_IPV4, DMR_IPV6)) + if (! Initialize(nullptr, DMRMMDVM_PORT, DMR_IPV4, DMR_IPV6)) return false; // update time @@ -165,17 +165,14 @@ void CDmrmmdvmProtocol::Task(void) // add client if needed CClients *clients = g_Reflector.GetClients(); - CClient *client = clients->FindClient(Callsign, Ip, PROTOCOL_DMRMMDVM); + std::shared_ptrclient = clients->FindClient(Callsign, Ip, PROTOCOL_DMRMMDVM); // client already connected ? - if ( client == NULL ) + if ( client == nullptr ) { std::cout << "DMRmmdvm login from " << Callsign << " at " << Ip << std::endl; - // create the client - CDmrmmdvmClient *newclient = new CDmrmmdvmClient(Callsign, Ip); - - // and append - clients->AddClient(newclient); + // create the client and append + clients->AddClient(std::make_shared(Callsign, Ip)); } else { @@ -198,8 +195,8 @@ void CDmrmmdvmProtocol::Task(void) // find client & remove it CClients *clients = g_Reflector.GetClients(); - CClient *client = clients->FindClient(Ip, PROTOCOL_DMRMMDVM); - if ( client != NULL ) + std::shared_ptrclient = clients->FindClient(Ip, PROTOCOL_DMRMMDVM); + if ( client != nullptr ) { clients->RemoveClient(client); } @@ -220,8 +217,8 @@ void CDmrmmdvmProtocol::Task(void) // find all clients with that callsign & ip and keep them alive CClients *clients = g_Reflector.GetClients(); auto it = clients->begin(); - CClient *client = NULL; - while ( (client = clients->FindNextClient(Callsign, Ip, PROTOCOL_DMRMMDVM, it)) != NULL ) + std::shared_ptrclient = nullptr; + while ( (client = clients->FindNextClient(Callsign, Ip, PROTOCOL_DMRMMDVM, it)) != nullptr ) { // acknowledge EncodeKeepAlivePacket(&Buffer, client); @@ -285,12 +282,12 @@ bool CDmrmmdvmProtocol::OnDvHeaderPacketIn(CDvHeaderPacket *Header, const CIp &I // find the stream CPacketStream *stream = GetStream(Header->GetStreamId()); - if ( stream == NULL ) + if ( stream == nullptr ) { // no stream open yet, open a new one // firstfind this client - CClient *client = g_Reflector.GetClients()->FindClient(Ip, PROTOCOL_DMRMMDVM); - if ( client != NULL ) + std::shared_ptrclient = g_Reflector.GetClients()->FindClient(Ip, PROTOCOL_DMRMMDVM); + if ( client != nullptr ) { // process cmd if any if ( !client->HasReflectorModule() ) @@ -330,7 +327,7 @@ bool CDmrmmdvmProtocol::OnDvHeaderPacketIn(CDvHeaderPacket *Header, const CIp &I if ( g_Reflector.IsValidModule(Header->GetRpt2Module()) && (CallType == DMR_GROUP_CALL) ) { // yes, try to open the stream - if ( (stream = g_Reflector.OpenStream(Header, client)) != NULL ) + if ( (stream = g_Reflector.OpenStream(Header, client)) != nullptr ) { // keep the handle m_Streams.push_back(stream); @@ -444,8 +441,8 @@ void CDmrmmdvmProtocol::HandleQueue(void) // and push it to all our clients linked to the module and who are not streaming in CClients *clients = g_Reflector.GetClients(); auto it = clients->begin(); - CClient *client = NULL; - while ( (client = clients->FindNextClient(PROTOCOL_DMRMMDVM, it)) != NULL ) + std::shared_ptrclient = nullptr; + while ( (client = clients->FindNextClient(PROTOCOL_DMRMMDVM, it)) != nullptr ) { // is this client busy ? if ( !client->IsAMaster() && (client->GetReflectorModule() == packet->GetModuleId()) ) @@ -476,8 +473,8 @@ void CDmrmmdvmProtocol::HandleKeepalives(void) // iterate on clients CClients *clients = g_Reflector.GetClients(); auto it = clients->begin(); - CClient *client = NULL; - while ( (client = clients->FindNextClient(PROTOCOL_DMRMMDVM, it)) != NULL ) + std::shared_ptrclient = nullptr; + while ( (client = clients->FindNextClient(PROTOCOL_DMRMMDVM, it)) != nullptr ) { // is this client busy ? if ( client->IsAMaster() ) @@ -628,7 +625,7 @@ bool CDmrmmdvmProtocol::IsValidDvHeaderPacket(const CBuffer &Buffer, CDvHeaderPa uint8 tag[] = { 'D','M','R','D' }; bool valid = false; - *header = NULL; + *header = nullptr; *cmd = CMD_NONE; if ( (Buffer.size() == 55) && (Buffer.Compare(tag, sizeof(tag)) == 0) ) @@ -695,7 +692,7 @@ bool CDmrmmdvmProtocol::IsValidDvHeaderPacket(const CBuffer &Buffer, CDvHeaderPa if ( !valid ) { delete *header; - *header = NULL; + *header = nullptr; } } } @@ -709,9 +706,9 @@ bool CDmrmmdvmProtocol::IsValidDvFramePacket(const CBuffer &Buffer, CDvFramePack uint8 tag[] = { 'D','M','R','D' }; bool valid = false; - frames[0] = NULL; - frames[1] = NULL; - frames[2] = NULL; + frames[0] = nullptr; + frames[1] = nullptr; + frames[2] = nullptr; if ( (Buffer.size() == 55) && (Buffer.Compare(tag, sizeof(tag)) == 0) ) { @@ -778,7 +775,7 @@ bool CDmrmmdvmProtocol::IsValidDvLastFramePacket(const CBuffer &Buffer, CDvLastF uint8 tag[] = { 'D','M','R','D' }; bool valid = false; - *frame = NULL; + *frame = nullptr; if ( (Buffer.size() == 55) && (Buffer.Compare(tag, sizeof(tag)) == 0) ) { @@ -834,7 +831,7 @@ bool CDmrmmdvmProtocol::IsValidDvLastFramePacket(const CBuffer &Buffer, CDvLastF //////////////////////////////////////////////////////////////////////////////////////// // packet encoding helpers -void CDmrmmdvmProtocol::EncodeKeepAlivePacket(CBuffer *Buffer, CClient *Client) +void CDmrmmdvmProtocol::EncodeKeepAlivePacket(CBuffer *Buffer, std::shared_ptrClient) { uint8 tag[] = { 'M','S','T','P','O','N','G' }; @@ -865,7 +862,7 @@ void CDmrmmdvmProtocol::EncodeNackPacket(CBuffer *Buffer, const CCallsign &Calls Buffer->Set(tag, sizeof(tag)); } -void CDmrmmdvmProtocol::EncodeClosePacket(CBuffer *Buffer, CClient *Client) +void CDmrmmdvmProtocol::EncodeClosePacket(CBuffer *Buffer, std::shared_ptrClient) { uint8 tag[] = { 'M','S','T','C','L' }; @@ -1168,7 +1165,7 @@ void CDmrmmdvmProtocol::ReplaceEMBInBuffer(CBuffer *buffer, uint8 uiDmrPacketId) // voice packet F else { - // NULL + // nullptr uint8 emb[2]; emb[0] = (DMRMMDVM_REFLECTOR_COLOUR << 4) & 0xF0; //emb[0] |= PI ? 0x08U : 0x00; diff --git a/src/cdmrmmdvmprotocol.h b/src/cdmrmmdvmprotocol.h index 0155b9a..71d31f4 100644 --- a/src/cdmrmmdvmprotocol.h +++ b/src/cdmrmmdvmprotocol.h @@ -95,11 +95,11 @@ protected: bool IsValidDvLastFramePacket(const CBuffer &, CDvLastFramePacket **); // packet encoding helpers - void EncodeKeepAlivePacket(CBuffer *, CClient *); + void EncodeKeepAlivePacket(CBuffer *, std::shared_ptr); void EncodeAckPacket(CBuffer *, const CCallsign &); void EncodeConnectAckPacket(CBuffer *, const CCallsign &, uint32); void EncodeNackPacket(CBuffer *, const CCallsign &); - void EncodeClosePacket(CBuffer *, CClient *); + void EncodeClosePacket(CBuffer *, std::shared_ptr); bool EncodeDvHeaderPacket(const CDvHeaderPacket &, uint8, CBuffer *) const; void EncodeDvPacket(const CDvHeaderPacket &, const CDvFramePacket &, const CDvFramePacket &, const CDvFramePacket &, uint8, CBuffer *) const; void EncodeDvLastPacket(const CDvHeaderPacket &, uint8, CBuffer *) const; diff --git a/src/cdmrplusprotocol.cpp b/src/cdmrplusprotocol.cpp index 1f98981..5323412 100644 --- a/src/cdmrplusprotocol.cpp +++ b/src/cdmrplusprotocol.cpp @@ -50,7 +50,7 @@ static uint8 g_DmrSyncMSData[] = { 0x0D,0x5D,0x7F,0x77,0xFD,0x75,0x70 }; bool CDmrplusProtocol::Init() { // base class - if (! Initialize(NULL, DMRPLUS_PORT, DMR_IPV4, DMR_IPV6)) + if (! Initialize(nullptr, DMRPLUS_PORT, DMR_IPV4, DMR_IPV6)) return false; // update time @@ -140,17 +140,14 @@ void CDmrplusProtocol::Task(void) // add client if needed CClients *clients = g_Reflector.GetClients(); - CClient *client = clients->FindClient(Callsign, Ip, PROTOCOL_DMRPLUS); + std::shared_ptrclient = clients->FindClient(Callsign, Ip, PROTOCOL_DMRPLUS); // client already connected ? - if ( client == NULL ) + if ( client == nullptr ) { std::cout << "DMRplus connect packet for module " << ToLinkModule << " from " << Callsign << " at " << Ip << std::endl; - // create the client - CDmrplusClient *newclient = new CDmrplusClient(Callsign, Ip, ToLinkModule); - - // and append - clients->AddClient(newclient); + // create the client and append + clients->AddClient(std::make_shared(Callsign, Ip, ToLinkModule)); } else { @@ -173,8 +170,8 @@ void CDmrplusProtocol::Task(void) // find client & remove it CClients *clients = g_Reflector.GetClients(); - CClient *client = clients->FindClient(Ip, PROTOCOL_DMRPLUS); - if ( client != NULL ) + std::shared_ptrclient = clients->FindClient(Ip, PROTOCOL_DMRPLUS); + if ( client != nullptr ) { clients->RemoveClient(client); } @@ -213,15 +210,15 @@ bool CDmrplusProtocol::OnDvHeaderPacketIn(CDvHeaderPacket *Header, const CIp &Ip // find the stream CPacketStream *stream = GetStream(Header->GetStreamId()); - if ( stream == NULL ) + if ( stream == nullptr ) { // no stream open yet, open a new one // find this client - CClient *client = g_Reflector.GetClients()->FindClient(Ip, PROTOCOL_DMRPLUS); - if ( client != NULL ) + std::shared_ptrclient = g_Reflector.GetClients()->FindClient(Ip, PROTOCOL_DMRPLUS); + if ( client != nullptr ) { // and try to open the stream - if ( (stream = g_Reflector.OpenStream(Header, client)) != NULL ) + if ( (stream = g_Reflector.OpenStream(Header, client)) != nullptr ) { // keep the handle m_Streams.push_back(stream); @@ -318,8 +315,8 @@ void CDmrplusProtocol::HandleQueue(void) // and push it to all our clients linked to the module and who are not streaming in CClients *clients = g_Reflector.GetClients(); auto it = clients->begin(); - CClient *client = NULL; - while ( (client = clients->FindNextClient(PROTOCOL_DMRPLUS, it)) != NULL ) + std::shared_ptrclient = nullptr; + while ( (client = clients->FindNextClient(PROTOCOL_DMRPLUS, it)) != nullptr ) { // is this client busy ? if ( !client->IsAMaster() && (client->GetReflectorModule() == packet->GetModuleId()) ) @@ -347,8 +344,8 @@ void CDmrplusProtocol::SendBufferToClients(const CBuffer &buffer, uint8 module) // and push it to all our clients linked to the module and who are not streaming in CClients *clients = g_Reflector.GetClients(); auto it = clients->begin(); - CClient *client = NULL; - while ( (client = clients->FindNextClient(PROTOCOL_DMRPLUS, it)) != NULL ) + std::shared_ptrclient = nullptr; + while ( (client = clients->FindNextClient(PROTOCOL_DMRPLUS, it)) != nullptr ) { // is this client busy ? if ( !client->IsAMaster() && (client->GetReflectorModule() == module) ) @@ -377,8 +374,8 @@ void CDmrplusProtocol::HandleKeepalives(void) // iterate on clients CClients *clients = g_Reflector.GetClients(); auto it = clients->begin(); - CClient *client = NULL; - while ( (client = clients->FindNextClient(PROTOCOL_DMRPLUS, it)) != NULL ) + std::shared_ptrclient = nullptr; + while ( (client = clients->FindNextClient(PROTOCOL_DMRPLUS, it)) != nullptr ) { // is this client busy ? if ( client->IsAMaster() ) @@ -449,7 +446,7 @@ bool CDmrplusProtocol::IsValidDisconnectPacket(const CBuffer &Buffer, CCallsign bool CDmrplusProtocol::IsValidDvHeaderPacket(const CIp &Ip, const CBuffer &Buffer, CDvHeaderPacket **Header) { bool valid = false; - *Header = NULL; + *Header = nullptr; uint8 uiPacketType = Buffer.data()[8]; if ( (Buffer.size() == 72) && ( uiPacketType == 2 ) ) @@ -480,7 +477,7 @@ bool CDmrplusProtocol::IsValidDvHeaderPacket(const CIp &Ip, const CBuffer &Buffe if ( !valid ) { delete *Header; - *Header = NULL; + *Header = nullptr; } } } @@ -491,9 +488,9 @@ bool CDmrplusProtocol::IsValidDvHeaderPacket(const CIp &Ip, const CBuffer &Buffe bool CDmrplusProtocol::IsValidDvFramePacket(const CIp &Ip, const CBuffer &Buffer, CDvFramePacket **frames) { bool valid = false; - frames[0] = NULL; - frames[1] = NULL; - frames[2] = NULL; + frames[0] = nullptr; + frames[1] = nullptr; + frames[2] = nullptr; uint8 uiPacketType = Buffer.data()[8]; if ( (Buffer.size() == 72) && ((uiPacketType == 1) || (uiPacketType == 3)) ) @@ -816,7 +813,7 @@ void CDmrplusProtocol::ReplaceEMBInBuffer(CBuffer *buffer, uint8 uiDmrPacketId) // voice packet F else { - // NULL + // nullptr uint8 emb[2]; emb[0] = (DMRMMDVM_REFLECTOR_COLOUR << 4) & 0xF0; //emb[0] |= PI ? 0x08U : 0x00; diff --git a/src/cdplusprotocol.cpp b/src/cdplusprotocol.cpp index 9624f6a..a4dfce6 100644 --- a/src/cdplusprotocol.cpp +++ b/src/cdplusprotocol.cpp @@ -73,14 +73,14 @@ void CDplusProtocol::Task(void) #endif { // crack the packet - if ( (Frame = IsValidDvFramePacket(Buffer)) != NULL ) + if ( (Frame = IsValidDvFramePacket(Buffer)) != nullptr ) { //std::cout << "DPlus DV frame" << std::endl; // handle it OnDvFramePacketIn(Frame, &Ip); } - else if ( (Header = IsValidDvHeaderPacket(Buffer)) != NULL ) + else if ( (Header = IsValidDvHeaderPacket(Buffer)) != nullptr ) { //std::cout << "DPlus DV header:" << std::endl << *Header << std::endl; @@ -95,7 +95,7 @@ void CDplusProtocol::Task(void) delete Header; } } - else if ( (LastFrame = IsValidDvLastFramePacket(Buffer)) != NULL ) + else if ( (LastFrame = IsValidDvLastFramePacket(Buffer)) != nullptr ) { //std::cout << "DPlus DV last frame" << std::endl; @@ -120,11 +120,8 @@ void CDplusProtocol::Task(void) EncodeLoginAckPacket(&Buffer); Send(Buffer, Ip); - // create the client - CDplusClient *client = new CDplusClient(Callsign, Ip); - - // and append - g_Reflector.GetClients()->AddClient(client); + // create the client and append + g_Reflector.GetClients()->AddClient(std::make_shared(Callsign, Ip)); g_Reflector.ReleaseClients(); } else @@ -141,8 +138,8 @@ void CDplusProtocol::Task(void) // find client CClients *clients = g_Reflector.GetClients(); - CClient *client = clients->FindClient(Ip, PROTOCOL_DPLUS); - if ( client != NULL ) + std::shared_ptrclient = clients->FindClient(Ip, PROTOCOL_DPLUS); + if ( client != nullptr ) { // remove it clients->RemoveClient(client); @@ -159,8 +156,8 @@ void CDplusProtocol::Task(void) // find all clients with that callsign & ip and keep them alive CClients *clients = g_Reflector.GetClients(); auto it = clients->begin(); - CClient *client = NULL; - while ( (client = clients->FindNextClient(Ip, PROTOCOL_DPLUS, it)) != NULL ) + std::shared_ptrclient = nullptr; + while ( (client = clients->FindNextClient(Ip, PROTOCOL_DPLUS, it)) != nullptr ) { client->Alive(); } @@ -198,7 +195,7 @@ bool CDplusProtocol::OnDvHeaderPacketIn(CDvHeaderPacket *Header, const CIp &Ip) // find the stream CPacketStream *stream = GetStream(Header->GetStreamId()); - if ( stream == NULL ) + if ( stream == nullptr ) { // no stream open yet, open a new one CCallsign via(Header->GetRpt1Callsign()); @@ -207,8 +204,8 @@ bool CDplusProtocol::OnDvHeaderPacketIn(CDvHeaderPacket *Header, const CIp &Ip) if ( g_Reflector.IsValidModule(Header->GetRpt1Module()) ) { // find this client - CClient *client = g_Reflector.GetClients()->FindClient(Ip, PROTOCOL_DPLUS); - if ( client != NULL ) + std::shared_ptrclient = g_Reflector.GetClients()->FindClient(Ip, PROTOCOL_DPLUS); + if ( client != nullptr ) { // now we know if it's a dextra dongle or a genuine dplus node if ( Header->GetRpt2Callsign().HasSameCallsignWithWildcard(CCallsign("XRF*")) ) @@ -223,7 +220,7 @@ bool CDplusProtocol::OnDvHeaderPacketIn(CDvHeaderPacket *Header, const CIp &Ip) // get client callsign via = client->GetCallsign(); // and try to open the stream - if ( (stream = g_Reflector.OpenStream(Header, client)) != NULL ) + if ( (stream = g_Reflector.OpenStream(Header, client)) != nullptr ) { // keep the handle m_Streams.push_back(stream); @@ -293,8 +290,8 @@ void CDplusProtocol::HandleQueue(void) // it's client who decide which stream he's interrrested in CClients *clients = g_Reflector.GetClients(); auto it = clients->begin(); - CClient *client = NULL; - while ( (client = clients->FindNextClient(PROTOCOL_DPLUS, it)) != NULL ) + std::shared_ptrclient = nullptr; + while ( (client = clients->FindNextClient(PROTOCOL_DPLUS, it)) != nullptr ) { // is this client busy ? if ( !client->IsAMaster() ) @@ -305,7 +302,7 @@ void CDplusProtocol::HandleQueue(void) if ( packet->IsDvHeader() ) { // sending header in Dplus is client specific - SendDvHeader((CDvHeaderPacket *)packet, (CDplusClient *)client); + SendDvHeader((CDvHeaderPacket *)packet, (CDplusClient *)client.get()); } else if ( packet->IsDvFrame() ) { @@ -318,7 +315,7 @@ void CDplusProtocol::HandleQueue(void) // yes, clone it CDvHeaderPacket packet2(m_StreamsCache[iModId].m_dvHeader); // and send it - SendDvHeader(&packet2, (CDplusClient *)client); + SendDvHeader(&packet2, (CDplusClient *)client.get()); } } else @@ -387,8 +384,8 @@ void CDplusProtocol::HandleKeepalives(void) // iterate on clients CClients *clients = g_Reflector.GetClients(); auto it = clients->begin(); - CClient *client = NULL; - while ( (client = clients->FindNextClient(PROTOCOL_DPLUS, it)) != NULL ) + std::shared_ptrclient = nullptr; + while ( (client = clients->FindNextClient(PROTOCOL_DPLUS, it)) != nullptr ) { // send keepalive //std::cout << "Sending DPlus packet @ " << client->GetIp() << std::endl; @@ -452,7 +449,7 @@ bool CDplusProtocol::IsValidKeepAlivePacket(const CBuffer &Buffer) CDvHeaderPacket *CDplusProtocol::IsValidDvHeaderPacket(const CBuffer &Buffer) { - CDvHeaderPacket *header = NULL; + CDvHeaderPacket *header = nullptr; if ( (Buffer.size() == 58) && (Buffer.data()[0] == 0x3A) && (Buffer.data()[1] == 0x80) && @@ -466,7 +463,7 @@ CDvHeaderPacket *CDplusProtocol::IsValidDvHeaderPacket(const CBuffer &Buffer) if ( !header->IsValid() ) { delete header; - header = NULL; + header = nullptr; } } return header; @@ -474,7 +471,7 @@ CDvHeaderPacket *CDplusProtocol::IsValidDvHeaderPacket(const CBuffer &Buffer) CDvFramePacket *CDplusProtocol::IsValidDvFramePacket(const CBuffer &Buffer) { - CDvFramePacket *dvframe = NULL; + CDvFramePacket *dvframe = nullptr; if ( (Buffer.size() == 29) && (Buffer.data()[0] == 0x1D) && (Buffer.data()[1] == 0x80) && @@ -488,7 +485,7 @@ CDvFramePacket *CDplusProtocol::IsValidDvFramePacket(const CBuffer &Buffer) if ( !dvframe->IsValid() ) { delete dvframe; - dvframe = NULL; + dvframe = nullptr; } } return dvframe; @@ -496,7 +493,7 @@ CDvFramePacket *CDplusProtocol::IsValidDvFramePacket(const CBuffer &Buffer) CDvLastFramePacket *CDplusProtocol::IsValidDvLastFramePacket(const CBuffer &Buffer) { - CDvLastFramePacket *dvframe = NULL; + CDvLastFramePacket *dvframe = nullptr; if ( (Buffer.size() == 32) && (Buffer.Compare((uint8 *)"DSVT", 2, 4) == 0) && @@ -510,7 +507,7 @@ CDvLastFramePacket *CDplusProtocol::IsValidDvLastFramePacket(const CBuffer &Buff if ( !dvframe->IsValid() ) { delete dvframe; - dvframe = NULL; + dvframe = nullptr; } } return dvframe; diff --git a/src/cdvframepacket.cpp b/src/cdvframepacket.cpp index c30be55..39d9a5b 100644 --- a/src/cdvframepacket.cpp +++ b/src/cdvframepacket.cpp @@ -111,7 +111,7 @@ const uint8 *CDvFramePacket::GetAmbe(uint8 uiCodec) const #ifndef NO_XLX case CODEC_AMBE2PLUS: return m_uiAmbePlus; #endif - default: return NULL; + default: return nullptr; } } diff --git a/src/cg3protocol.cpp b/src/cg3protocol.cpp index 95bc307..d27abea 100644 --- a/src/cg3protocol.cpp +++ b/src/cg3protocol.cpp @@ -96,25 +96,25 @@ bool CG3Protocol::Init(void) void CG3Protocol::Close(void) { - if (m_pPresenceThread != NULL) + if (m_pPresenceThread != nullptr) { m_pPresenceThread->join(); delete m_pPresenceThread; - m_pPresenceThread = NULL; + m_pPresenceThread = nullptr; } - if (m_pConfigThread != NULL) + if (m_pConfigThread != nullptr) { m_pConfigThread->join(); delete m_pConfigThread; - m_pConfigThread = NULL; + m_pConfigThread = nullptr; } - if (m_pIcmpThread != NULL) + if (m_pIcmpThread != nullptr) { m_pIcmpThread->join(); delete m_pIcmpThread; - m_pIcmpThread = NULL; + m_pIcmpThread = nullptr; } } @@ -188,8 +188,8 @@ void CG3Protocol::PresenceTask(void) CClients *clients = g_Reflector.GetClients(); auto it = clients->begin(); - CClient *extant = NULL; - while ( (extant = clients->FindNextClient(PROTOCOL_G3, it)) != NULL ) + std::shared_ptrextant = nullptr; + while ( (extant = clients->FindNextClient(PROTOCOL_G3, it)) != nullptr ) { CIp ClIp = extant->GetIp(); if (ClIp.GetAddr() == Ip.GetAddr()) @@ -198,12 +198,12 @@ void CG3Protocol::PresenceTask(void) } } - if (extant == NULL) + if (extant == nullptr) { it = clients->begin(); // do we already have a client with the same call (IP changed)? - while ( (extant = clients->FindNextClient(PROTOCOL_G3, it)) != NULL ) + while ( (extant = clients->FindNextClient(PROTOCOL_G3, it)) != nullptr ) { { if (extant->GetCallsign().HasSameCallsign(Terminal)) @@ -363,8 +363,8 @@ void CG3Protocol::IcmpTask(void) { CClients *clients = g_Reflector.GetClients(); auto it = clients->begin(); - CClient *client = NULL; - while ( (client = clients->FindNextClient(PROTOCOL_G3, it)) != NULL ) + std::shared_ptrclient = nullptr; + while ( (client = clients->FindNextClient(PROTOCOL_G3, it)) != nullptr ) { CIp ClientIp = client->GetIp(); if (ClientIp.GetAddr() == Ip.GetAddr()) @@ -396,11 +396,11 @@ void CG3Protocol::Task(void) if ( m_Socket4.Receive(Buffer, Ip, 20) ) { CIp ClIp; - CIp *BaseIp = NULL; + CIp *BaseIp = nullptr; CClients *clients = g_Reflector.GetClients(); auto it = clients->begin(); - CClient *client = NULL; - while ( (client = clients->FindNextClient(PROTOCOL_G3, it)) != NULL ) + std::shared_ptrclient = nullptr; + while ( (client = clients->FindNextClient(PROTOCOL_G3, it)) != nullptr ) { ClIp = client->GetIp(); if (ClIp.GetAddr() == Ip.GetAddr()) @@ -415,17 +415,17 @@ void CG3Protocol::Task(void) } g_Reflector.ReleaseClients(); - if (BaseIp != NULL) + if (BaseIp != nullptr) { // crack the packet - if ( (Frame = IsValidDvFramePacket(Buffer)) != NULL ) + if ( (Frame = IsValidDvFramePacket(Buffer)) != nullptr ) { //std::cout << "Terminal DV frame" << std::endl; // handle it OnDvFramePacketIn(Frame, BaseIp); } - else if ( (Header = IsValidDvHeaderPacket(Buffer)) != NULL ) + else if ( (Header = IsValidDvHeaderPacket(Buffer)) != nullptr ) { //std::cout << "Terminal DV header" << std::endl; @@ -440,7 +440,7 @@ void CG3Protocol::Task(void) delete Header; } } - else if ( (LastFrame = IsValidDvLastFramePacket(Buffer)) != NULL ) + else if ( (LastFrame = IsValidDvLastFramePacket(Buffer)) != nullptr ) { //std::cout << "Terminal DV last frame" << std::endl; @@ -501,8 +501,8 @@ void CG3Protocol::HandleQueue(void) // and push it to all our clients linked to the module and who are not streaming in CClients *clients = g_Reflector.GetClients(); auto it = clients->begin(); - CClient *client = NULL; - while ( (client = clients->FindNextClient(PROTOCOL_G3, it)) != NULL ) + std::shared_ptrclient = nullptr; + while ( (client = clients->FindNextClient(PROTOCOL_G3, it)) != nullptr ) { // is this client busy ? if ( !client->IsAMaster() && (client->GetReflectorModule() == packet->GetModuleId()) ) @@ -537,8 +537,8 @@ void CG3Protocol::HandleKeepalives(void) // iterate on clients CClients *clients = g_Reflector.GetClients(); auto it = clients->begin(); - CClient *client = NULL; - while ( (client = clients->FindNextClient(PROTOCOL_G3, it)) != NULL ) + std::shared_ptrclient = nullptr; + while ( (client = clients->FindNextClient(PROTOCOL_G3, it)) != nullptr ) { if (!client->IsAlive()) { @@ -563,7 +563,7 @@ bool CG3Protocol::OnDvHeaderPacketIn(CDvHeaderPacket *Header, const CIp &Ip) // find the stream CPacketStream *stream = GetStream(Header->GetStreamId(), &Ip); - if ( stream == NULL ) + if ( stream == nullptr ) { // no stream open yet, open a new one CCallsign via(Header->GetRpt1Callsign()); @@ -571,8 +571,8 @@ bool CG3Protocol::OnDvHeaderPacketIn(CDvHeaderPacket *Header, const CIp &Ip) // find this client CClients *clients = g_Reflector.GetClients(); auto it = clients->begin(); - CClient *client = NULL; - while ( (client = clients->FindNextClient(PROTOCOL_G3, it)) != NULL ) + std::shared_ptrclient = nullptr; + while ( (client = clients->FindNextClient(PROTOCOL_G3, it)) != nullptr ) { CIp ClIp = client->GetIp(); if (ClIp.GetAddr() == Ip.GetAddr()) @@ -581,7 +581,7 @@ bool CG3Protocol::OnDvHeaderPacketIn(CDvHeaderPacket *Header, const CIp &Ip) } } - if ( client != NULL ) + if ( client != nullptr ) { // move it to the proper module @@ -599,7 +599,7 @@ bool CG3Protocol::OnDvHeaderPacketIn(CDvHeaderPacket *Header, const CIp &Ip) // drop if invalid module delete Header; g_Reflector.ReleaseClients(); - return NULL; + return nullptr; } } @@ -607,7 +607,7 @@ bool CG3Protocol::OnDvHeaderPacketIn(CDvHeaderPacket *Header, const CIp &Ip) via = client->GetCallsign(); // and try to open the stream - if ( (stream = g_Reflector.OpenStream(Header, client)) != NULL ) + if ( (stream = g_Reflector.OpenStream(Header, client)) != nullptr ) { // keep the handle m_Streams.push_back(stream); @@ -653,7 +653,7 @@ bool CG3Protocol::OnDvHeaderPacketIn(CDvHeaderPacket *Header, const CIp &Ip) CDvHeaderPacket *CG3Protocol::IsValidDvHeaderPacket(const CBuffer &Buffer) { - CDvHeaderPacket *header = NULL; + CDvHeaderPacket *header = nullptr; if ( (Buffer.size() == 56) && (Buffer.Compare((uint8 *)"DSVT", 4) == 0) && (Buffer.data()[4] == 0x10) && (Buffer.data()[8] == 0x20) ) @@ -665,7 +665,7 @@ CDvHeaderPacket *CG3Protocol::IsValidDvHeaderPacket(const CBuffer &Buffer) if ( !header->IsValid() ) { delete header; - header = NULL; + header = nullptr; } } return header; @@ -673,7 +673,7 @@ CDvHeaderPacket *CG3Protocol::IsValidDvHeaderPacket(const CBuffer &Buffer) CDvFramePacket *CG3Protocol::IsValidDvFramePacket(const CBuffer &Buffer) { - CDvFramePacket *dvframe = NULL; + CDvFramePacket *dvframe = nullptr; if ( (Buffer.size() == 27) && (Buffer.Compare((uint8 *)"DSVT", 4) == 0) && (Buffer.data()[4] == 0x20) && (Buffer.data()[8] == 0x20) && @@ -686,7 +686,7 @@ CDvFramePacket *CG3Protocol::IsValidDvFramePacket(const CBuffer &Buffer) if ( !dvframe->IsValid() ) { delete dvframe; - dvframe = NULL; + dvframe = nullptr; } } return dvframe; @@ -694,7 +694,7 @@ CDvFramePacket *CG3Protocol::IsValidDvFramePacket(const CBuffer &Buffer) CDvLastFramePacket *CG3Protocol::IsValidDvLastFramePacket(const CBuffer &Buffer) { - CDvLastFramePacket *dvframe = NULL; + CDvLastFramePacket *dvframe = nullptr; if ( (Buffer.size() == 27) && (Buffer.Compare((uint8 *)"DSVT", 4) == 0) && (Buffer.data()[4] == 0x20) && (Buffer.data()[8] == 0x20) && @@ -707,7 +707,7 @@ CDvLastFramePacket *CG3Protocol::IsValidDvLastFramePacket(const CBuffer &Buffer) if ( !dvframe->IsValid() ) { delete dvframe; - dvframe = NULL; + dvframe = nullptr; } } return dvframe; @@ -787,8 +787,8 @@ void CG3Protocol::NeedReload(void) // we have new options - iterate on clients for potential removal CClients *clients = g_Reflector.GetClients(); auto it = clients->begin(); - CClient *client = NULL; - while ( (client = clients->FindNextClient(PROTOCOL_G3, it)) != NULL ) + std::shared_ptrclient = nullptr; + while ( (client = clients->FindNextClient(PROTOCOL_G3, it)) != nullptr ) { char module = client->GetReflectorModule(); if (!strchr(m_Modules.c_str(), module) && !strchr(m_Modules.c_str(), '*')) @@ -820,9 +820,9 @@ void CG3Protocol::ReadOptions(void) if ((::strlen(szt) > 0) && szt[0] != '#') { - if ((szt = ::strtok(szt, " ,\t")) != NULL) + if ((szt = ::strtok(szt, " ,\t")) != nullptr) { - if ((szval = ::strtok(NULL, " ,\t")) != NULL) + if ((szval = ::strtok(nullptr, " ,\t")) != nullptr) { if (::strncmp(szt, "address", 7) == 0) { diff --git a/src/cgatekeeper.cpp b/src/cgatekeeper.cpp index 6d0b6f8..056ba78 100644 --- a/src/cgatekeeper.cpp +++ b/src/cgatekeeper.cpp @@ -37,7 +37,7 @@ CGateKeeper g_GateKeeper; CGateKeeper::CGateKeeper() { keep_running = true; - m_pThread = NULL; + m_pThread = nullptr; } //////////////////////////////////////////////////////////////////////////////////////// @@ -47,11 +47,11 @@ CGateKeeper::~CGateKeeper() { // kill threads keep_running = false; - if ( m_pThread != NULL ) + if ( m_pThread != nullptr ) { m_pThread->join(); delete m_pThread; - m_pThread = NULL; + m_pThread = nullptr; } } @@ -79,11 +79,11 @@ bool CGateKeeper::Init(void) void CGateKeeper::Close(void) { keep_running = false; - if ( m_pThread != NULL ) + if ( m_pThread != nullptr ) { m_pThread->join(); delete m_pThread; - m_pThread = NULL; + m_pThread = nullptr; } } diff --git a/src/cgatekeeper.h b/src/cgatekeeper.h index eef20f7..10561ba 100644 --- a/src/cgatekeeper.h +++ b/src/cgatekeeper.h @@ -48,7 +48,7 @@ public: void Close(void); // authorizations - bool MayLink(const CCallsign &, const CIp &, int, char * = NULL) const; + bool MayLink(const CCallsign &, const CIp &, int, char * = nullptr) const; bool MayTransmit(const CCallsign &, const CIp &, int = PROTOCOL_ANY, char = ' ') const; // peer list handeling diff --git a/src/cgolay2087.cpp b/src/cgolay2087.cpp index 7ff6f92..7bdebd3 100644 --- a/src/cgolay2087.cpp +++ b/src/cgolay2087.cpp @@ -222,41 +222,41 @@ unsigned int CGolay2087::getSyndrome1987(unsigned int pattern) */ { unsigned int aux = X18; - + if (pattern >= X11) { while (pattern & MASK8) { while (!(aux & pattern)) aux = aux >> 1; - + pattern ^= (aux / X11) * GENPOL; } } - + return pattern; } unsigned char CGolay2087::decode(const unsigned char* data) { - assert(data != NULL); - + assert(data != nullptr); + unsigned int code = (data[0U] << 11) + (data[1U] << 3) + (data[2U] >> 5); unsigned int syndrome = getSyndrome1987(code); unsigned int error_pattern = DECODING_TABLE_1987[syndrome]; - + if (error_pattern != 0x00U) code ^= error_pattern; - + return code >> 11; } void CGolay2087::encode(unsigned char* data) { - assert(data != NULL); - + assert(data != nullptr); + unsigned int value = data[0U]; - + unsigned int cksum = ENCODING_TABLE_2087[value]; - + data[1U] = cksum & 0xFFU; data[2U] = cksum >> 8; } diff --git a/src/cgolay24128.cpp b/src/cgolay24128.cpp index d65c330..4dfcba5 100644 --- a/src/cgolay24128.cpp +++ b/src/cgolay24128.cpp @@ -1056,16 +1056,16 @@ static unsigned int get_syndrome_23127(unsigned int pattern) */ { unsigned int aux = X22; - + if (pattern >= X11) { while (pattern & MASK12) { while (!(aux & pattern)) aux = aux >> 1; - + pattern ^= (aux / X11) * GENPOL; } } - + return pattern; } @@ -1083,9 +1083,9 @@ unsigned int CGolay24128::decode23127(unsigned int code) { unsigned int syndrome = ::get_syndrome_23127(code); unsigned int error_pattern = DECODING_TABLE_23127[syndrome]; - + code ^= error_pattern; - + return code >> 11; } @@ -1096,13 +1096,13 @@ unsigned int CGolay24128::decode24128(unsigned int code) unsigned int CGolay24128::decode24128(unsigned char* bytes) { - assert(bytes != NULL); - + assert(bytes != nullptr); + unsigned int code = bytes[0U]; code <<= 8; code |= bytes[1U]; code <<= 8; code |= bytes[2U]; - + return decode23127(code >> 1); } diff --git a/src/chamming.cpp b/src/chamming.cpp index 8a9b5f8..f6fa10a 100644 --- a/src/chamming.cpp +++ b/src/chamming.cpp @@ -24,20 +24,20 @@ // Hamming (15,11,3) check a boolean data array bool CHamming::decode15113_1(bool* d) { - assert(d != NULL); - + assert(d != nullptr); + // Calculate the parity it should have bool c0 = d[0] ^ d[1] ^ d[2] ^ d[3] ^ d[4] ^ d[5] ^ d[6]; bool c1 = d[0] ^ d[1] ^ d[2] ^ d[3] ^ d[7] ^ d[8] ^ d[9]; bool c2 = d[0] ^ d[1] ^ d[4] ^ d[5] ^ d[7] ^ d[8] ^ d[10]; bool c3 = d[0] ^ d[2] ^ d[4] ^ d[6] ^ d[7] ^ d[9] ^ d[10]; - + unsigned char n = 0U; n |= (c0 != d[11]) ? 0x01U : 0x00U; n |= (c1 != d[12]) ? 0x02U : 0x00U; n |= (c2 != d[13]) ? 0x04U : 0x00U; n |= (c3 != d[14]) ? 0x08U : 0x00U; - + switch (n) { // Parity bit errors @@ -45,7 +45,7 @@ bool CHamming::decode15113_1(bool* d) case 0x02U: d[12] = !d[12]; return true; case 0x04U: d[13] = !d[13]; return true; case 0x08U: d[14] = !d[14]; return true; - + // Data bit errors case 0x0FU: d[0] = !d[0]; return true; case 0x07U: d[1] = !d[1]; return true; @@ -58,7 +58,7 @@ bool CHamming::decode15113_1(bool* d) case 0x06U: d[8] = !d[8]; return true; case 0x0AU: d[9] = !d[9]; return true; case 0x0CU: d[10] = !d[10]; return true; - + // No bit errors default: return false; } @@ -66,8 +66,8 @@ bool CHamming::decode15113_1(bool* d) void CHamming::encode15113_1(bool* d) { - assert(d != NULL); - + assert(d != nullptr); + // Calculate the checksum this row should have d[11] = d[0] ^ d[1] ^ d[2] ^ d[3] ^ d[4] ^ d[5] ^ d[6]; d[12] = d[0] ^ d[1] ^ d[2] ^ d[3] ^ d[7] ^ d[8] ^ d[9]; @@ -78,27 +78,27 @@ void CHamming::encode15113_1(bool* d) // Hamming (15,11,3) check a boolean data array bool CHamming::decode15113_2(bool* d) { - assert(d != NULL); - + assert(d != nullptr); + // Calculate the checksum this row should have bool c0 = d[0] ^ d[1] ^ d[2] ^ d[3] ^ d[5] ^ d[7] ^ d[8]; bool c1 = d[1] ^ d[2] ^ d[3] ^ d[4] ^ d[6] ^ d[8] ^ d[9]; bool c2 = d[2] ^ d[3] ^ d[4] ^ d[5] ^ d[7] ^ d[9] ^ d[10]; bool c3 = d[0] ^ d[1] ^ d[2] ^ d[4] ^ d[6] ^ d[7] ^ d[10]; - + unsigned char n = 0x00U; n |= (c0 != d[11]) ? 0x01U : 0x00U; n |= (c1 != d[12]) ? 0x02U : 0x00U; n |= (c2 != d[13]) ? 0x04U : 0x00U; n |= (c3 != d[14]) ? 0x08U : 0x00U; - + switch (n) { // Parity bit errors case 0x01U: d[11] = !d[11]; return true; case 0x02U: d[12] = !d[12]; return true; case 0x04U: d[13] = !d[13]; return true; case 0x08U: d[14] = !d[14]; return true; - + // Data bit errors case 0x09U: d[0] = !d[0]; return true; case 0x0BU: d[1] = !d[1]; return true; @@ -111,7 +111,7 @@ bool CHamming::decode15113_2(bool* d) case 0x03U: d[8] = !d[8]; return true; case 0x06U: d[9] = !d[9]; return true; case 0x0CU: d[10] = !d[10]; return true; - + // No bit errors default: return false; } @@ -119,8 +119,8 @@ bool CHamming::decode15113_2(bool* d) void CHamming::encode15113_2(bool* d) { - assert(d != NULL); - + assert(d != nullptr); + // Calculate the checksum this row should have d[11] = d[0] ^ d[1] ^ d[2] ^ d[3] ^ d[5] ^ d[7] ^ d[8]; d[12] = d[1] ^ d[2] ^ d[3] ^ d[4] ^ d[6] ^ d[8] ^ d[9]; @@ -131,27 +131,27 @@ void CHamming::encode15113_2(bool* d) // Hamming (13,9,3) check a boolean data array bool CHamming::decode1393(bool* d) { - assert(d != NULL); - + assert(d != nullptr); + // Calculate the checksum this column should have bool c0 = d[0] ^ d[1] ^ d[3] ^ d[5] ^ d[6]; bool c1 = d[0] ^ d[1] ^ d[2] ^ d[4] ^ d[6] ^ d[7]; bool c2 = d[0] ^ d[1] ^ d[2] ^ d[3] ^ d[5] ^ d[7] ^ d[8]; bool c3 = d[0] ^ d[2] ^ d[4] ^ d[5] ^ d[8]; - + unsigned char n = 0x00U; n |= (c0 != d[9]) ? 0x01U : 0x00U; n |= (c1 != d[10]) ? 0x02U : 0x00U; n |= (c2 != d[11]) ? 0x04U : 0x00U; n |= (c3 != d[12]) ? 0x08U : 0x00U; - + switch (n) { // Parity bit errors case 0x01U: d[9] = !d[9]; return true; case 0x02U: d[10] = !d[10]; return true; case 0x04U: d[11] = !d[11]; return true; case 0x08U: d[12] = !d[12]; return true; - + // Data bit erros case 0x0FU: d[0] = !d[0]; return true; case 0x07U: d[1] = !d[1]; return true; @@ -162,7 +162,7 @@ bool CHamming::decode1393(bool* d) case 0x03U: d[6] = !d[6]; return true; case 0x06U: d[7] = !d[7]; return true; case 0x0CU: d[8] = !d[8]; return true; - + // No bit errors default: return false; } @@ -170,8 +170,8 @@ bool CHamming::decode1393(bool* d) void CHamming::encode1393(bool* d) { - assert(d != NULL); - + assert(d != nullptr); + // Calculate the checksum this column should have d[9] = d[0] ^ d[1] ^ d[3] ^ d[5] ^ d[6]; d[10] = d[0] ^ d[1] ^ d[2] ^ d[4] ^ d[6] ^ d[7]; @@ -182,27 +182,27 @@ void CHamming::encode1393(bool* d) // Hamming (10,6,3) check a boolean data array bool CHamming::decode1063(bool* d) { - assert(d != NULL); - + assert(d != nullptr); + // Calculate the checksum this column should have bool c0 = d[0] ^ d[1] ^ d[2] ^ d[5]; bool c1 = d[0] ^ d[1] ^ d[3] ^ d[5]; bool c2 = d[0] ^ d[2] ^ d[3] ^ d[4]; bool c3 = d[1] ^ d[2] ^ d[3] ^ d[4]; - + unsigned char n = 0x00U; n |= (c0 != d[6]) ? 0x01U : 0x00U; n |= (c1 != d[7]) ? 0x02U : 0x00U; n |= (c2 != d[8]) ? 0x04U : 0x00U; n |= (c3 != d[9]) ? 0x08U : 0x00U; - + switch (n) { // Parity bit errors case 0x01U: d[6] = !d[6]; return true; case 0x02U: d[7] = !d[7]; return true; case 0x04U: d[8] = !d[8]; return true; case 0x08U: d[9] = !d[9]; return true; - + // Data bit erros case 0x07U: d[0] = !d[0]; return true; case 0x0BU: d[1] = !d[1]; return true; @@ -210,7 +210,7 @@ bool CHamming::decode1063(bool* d) case 0x0EU: d[3] = !d[3]; return true; case 0x0CU: d[4] = !d[4]; return true; case 0x03U: d[5] = !d[5]; return true; - + // No bit errors default: return false; } @@ -218,8 +218,8 @@ bool CHamming::decode1063(bool* d) void CHamming::encode1063(bool* d) { - assert(d != NULL); - + assert(d != nullptr); + // Calculate the checksum this column should have d[6] = d[0] ^ d[1] ^ d[2] ^ d[5]; d[7] = d[0] ^ d[1] ^ d[3] ^ d[5]; @@ -230,15 +230,15 @@ void CHamming::encode1063(bool* d) // A Hamming (16,11,4) Check bool CHamming::decode16114(bool* d) { - assert(d != NULL); - + assert(d != nullptr); + // Calculate the checksum this column should have bool c0 = d[0] ^ d[1] ^ d[2] ^ d[3] ^ d[5] ^ d[7] ^ d[8]; bool c1 = d[1] ^ d[2] ^ d[3] ^ d[4] ^ d[6] ^ d[8] ^ d[9]; bool c2 = d[2] ^ d[3] ^ d[4] ^ d[5] ^ d[7] ^ d[9] ^ d[10]; bool c3 = d[0] ^ d[1] ^ d[2] ^ d[4] ^ d[6] ^ d[7] ^ d[10]; bool c4 = d[0] ^ d[2] ^ d[5] ^ d[6] ^ d[8] ^ d[9] ^ d[10]; - + // Compare these with the actual bits unsigned char n = 0x00U; n |= (c0 != d[11]) ? 0x01U : 0x00U; @@ -246,7 +246,7 @@ bool CHamming::decode16114(bool* d) n |= (c2 != d[13]) ? 0x04U : 0x00U; n |= (c3 != d[14]) ? 0x08U : 0x00U; n |= (c4 != d[15]) ? 0x10U : 0x00U; - + switch (n) { // Parity bit errors case 0x01U: d[11] = !d[11]; return true; @@ -254,7 +254,7 @@ bool CHamming::decode16114(bool* d) case 0x04U: d[13] = !d[13]; return true; case 0x08U: d[14] = !d[14]; return true; case 0x10U: d[15] = !d[15]; return true; - + // Data bit errors case 0x19U: d[0] = !d[0]; return true; case 0x0BU: d[1] = !d[1]; return true; @@ -267,10 +267,10 @@ bool CHamming::decode16114(bool* d) case 0x13U: d[8] = !d[8]; return true; case 0x16U: d[9] = !d[9]; return true; case 0x1CU: d[10] = !d[10]; return true; - + // No bit errors case 0x00U: return true; - + // Unrecoverable errors default: return false; } @@ -278,8 +278,8 @@ bool CHamming::decode16114(bool* d) void CHamming::encode16114(bool* d) { - assert(d != NULL); - + assert(d != nullptr); + d[11] = d[0] ^ d[1] ^ d[2] ^ d[3] ^ d[5] ^ d[7] ^ d[8]; d[12] = d[1] ^ d[2] ^ d[3] ^ d[4] ^ d[6] ^ d[8] ^ d[9]; d[13] = d[2] ^ d[3] ^ d[4] ^ d[5] ^ d[7] ^ d[9] ^ d[10]; @@ -290,15 +290,15 @@ void CHamming::encode16114(bool* d) // A Hamming (17,12,3) Check bool CHamming::decode17123(bool* d) { - assert(d != NULL); - + assert(d != nullptr); + // Calculate the checksum this column should have bool c0 = d[0] ^ d[1] ^ d[2] ^ d[3] ^ d[6] ^ d[7] ^ d[9]; bool c1 = d[0] ^ d[1] ^ d[2] ^ d[3] ^ d[4] ^ d[7] ^ d[8] ^ d[10]; bool c2 = d[1] ^ d[2] ^ d[3] ^ d[4] ^ d[5] ^ d[8] ^ d[9] ^ d[11]; bool c3 = d[0] ^ d[1] ^ d[4] ^ d[5] ^ d[7] ^ d[10]; bool c4 = d[0] ^ d[1] ^ d[2] ^ d[5] ^ d[6] ^ d[8] ^ d[11]; - + // Compare these with the actual bits unsigned char n = 0x00U; n |= (c0 != d[12]) ? 0x01U : 0x00U; @@ -306,7 +306,7 @@ bool CHamming::decode17123(bool* d) n |= (c2 != d[14]) ? 0x04U : 0x00U; n |= (c3 != d[15]) ? 0x08U : 0x00U; n |= (c4 != d[16]) ? 0x10U : 0x00U; - + switch (n) { // Parity bit errors case 0x01U: d[12] = !d[12]; return true; @@ -314,7 +314,7 @@ bool CHamming::decode17123(bool* d) case 0x04U: d[14] = !d[14]; return true; case 0x08U: d[15] = !d[15]; return true; case 0x10U: d[16] = !d[16]; return true; - + // Data bit errors case 0x1BU: d[0] = !d[0]; return true; case 0x1FU: d[1] = !d[1]; return true; @@ -328,10 +328,10 @@ bool CHamming::decode17123(bool* d) case 0x05U: d[9] = !d[9]; return true; case 0x0AU: d[10] = !d[10]; return true; case 0x14U: d[11] = !d[11]; return true; - + // No bit errors case 0x00U: return true; - + // Unrecoverable errors default: return false; } @@ -339,8 +339,8 @@ bool CHamming::decode17123(bool* d) void CHamming::encode17123(bool* d) { - assert(d != NULL); - + assert(d != nullptr); + d[12] = d[0] ^ d[1] ^ d[2] ^ d[3] ^ d[6] ^ d[7] ^ d[9]; d[13] = d[0] ^ d[1] ^ d[2] ^ d[3] ^ d[4] ^ d[7] ^ d[8] ^ d[10]; d[14] = d[1] ^ d[2] ^ d[3] ^ d[4] ^ d[5] ^ d[8] ^ d[9] ^ d[11]; diff --git a/src/cip.cpp b/src/cip.cpp index c479553..ba8307c 100644 --- a/src/cip.cpp +++ b/src/cip.cpp @@ -39,7 +39,7 @@ CIp::CIp(const char *address, int family, int type, uint16_t port) : is_set(true bzero(&hints, sizeof(struct addrinfo)); hints.ai_family = family; hints.ai_socktype = type; - if (0 == getaddrinfo(address, (port ? std::to_string(port).c_str() : NULL), &hints, &result)) { + if (0 == getaddrinfo(address, (port ? std::to_string(port).c_str() : nullptr), &hints, &result)) { memcpy(&addr, result->ai_addr, result->ai_addrlen); addr.ss_family = result->ai_family; freeaddrinfo(result); diff --git a/src/cip.h b/src/cip.h index ea969a2..3277783 100644 --- a/src/cip.h +++ b/src/cip.h @@ -36,10 +36,10 @@ public: // constructors CIp(); CIp(const char *address, int family = AF_UNSPEC, int type = SOCK_DGRAM, uint16_t port = 0U); - CIp(const int family, const uint16_t port = 0U, const char *address = NULL); + CIp(const int family, const uint16_t port = 0U, const char *address = nullptr); // initializer for empty constructor - void Initialize(const int family, const uint16_t port = 0U, const char *address = NULL); + void Initialize(const int family, const uint16_t port = 0U, const char *address = nullptr); // comparison operators bool operator==(const CIp &rhs) const; diff --git a/src/cpacketstream.cpp b/src/cpacketstream.cpp index db8b24a..9475471 100644 --- a/src/cpacketstream.cpp +++ b/src/cpacketstream.cpp @@ -33,16 +33,16 @@ CPacketStream::CPacketStream() m_bOpen = false; m_uiStreamId = 0; m_uiPacketCntr = 0; - m_OwnerClient = NULL; + m_OwnerClient = nullptr; #ifdef TRANSCODER_IP - m_CodecStream = NULL; + m_CodecStream = nullptr; #endif } //////////////////////////////////////////////////////////////////////////////////////// // open / close -bool CPacketStream::Open(const CDvHeaderPacket &DvHeader, CClient *client) +bool CPacketStream::Open(const CDvHeaderPacket &DvHeader, std::shared_ptrclient) { bool ok = false; @@ -72,10 +72,10 @@ void CPacketStream::Close(void) // update status m_bOpen = false; m_uiStreamId = 0; - m_OwnerClient = NULL; + m_OwnerClient = nullptr; #ifdef TRANSCODER_IP g_Transcoder.ReleaseStream(m_CodecStream); - m_CodecStream = NULL; + m_CodecStream = nullptr; #endif } @@ -89,7 +89,7 @@ void CPacketStream::Push(CPacket *Packet) Packet->UpdatePids(m_uiPacketCntr++); // transcoder avaliable ? #ifdef TRANSCODER_IP - if ( m_CodecStream != NULL ) + if ( m_CodecStream != nullptr ) { // todo: verify no possibilty of double lock here m_CodecStream->Lock(); @@ -123,7 +123,7 @@ bool CPacketStream::IsEmpty(void) const #ifdef TRANSCODER_IP bool bEmpty = empty(); // also check no packets still in Codec stream's queue - if ( bEmpty && (m_CodecStream != NULL) ) + if ( bEmpty && (m_CodecStream != nullptr) ) { bEmpty = m_CodecStream->IsEmpty(); } @@ -140,9 +140,9 @@ bool CPacketStream::IsEmpty(void) const const CIp *CPacketStream::GetOwnerIp(void) { - if ( m_OwnerClient != NULL ) + if ( m_OwnerClient != nullptr ) { return &(m_OwnerClient->GetIp()); } - return NULL; + return nullptr; } diff --git a/src/cpacketstream.h b/src/cpacketstream.h index 8050b6b..c7619f5 100644 --- a/src/cpacketstream.h +++ b/src/cpacketstream.h @@ -48,7 +48,7 @@ public: virtual ~CPacketStream() {} // open / close - bool Open(const CDvHeaderPacket &, CClient *); + bool Open(const CDvHeaderPacket &, std::shared_ptr); void Close(void); // push & pop @@ -57,7 +57,7 @@ public: bool IsEmpty(void) const; // get - CClient *GetOwnerClient(void) { return m_OwnerClient; } + std::shared_ptr GetOwnerClient(void) { return m_OwnerClient; } const CIp *GetOwnerIp(void); bool IsExpired(void) const { return (m_LastPacketTime.DurationSinceNow() > STREAM_TIMEOUT); } bool IsOpen(void) const { return m_bOpen; } @@ -69,7 +69,7 @@ protected: bool m_bOpen; uint16 m_uiStreamId; uint32 m_uiPacketCntr; - CClient *m_OwnerClient; + std::shared_ptr m_OwnerClient; CTimePoint m_LastPacketTime; CDvHeaderPacket m_DvHeader; #ifdef TRANSCODER_IP diff --git a/src/cpeer.cpp b/src/cpeer.cpp index 1b4d580..b31dbba 100644 --- a/src/cpeer.cpp +++ b/src/cpeer.cpp @@ -36,8 +36,8 @@ CPeer::CPeer() { ::memset(m_ReflectorModules, 0, sizeof(m_ReflectorModules)); - m_ConnectTime = std::time(NULL); - m_LastHeardTime = std::time(NULL); + m_ConnectTime = std::time(nullptr); + m_LastHeardTime = std::time(nullptr); } CPeer::CPeer(const CCallsign &callsign, const CIp &ip, const char *modules, const CVersion &version) @@ -48,8 +48,8 @@ CPeer::CPeer(const CCallsign &callsign, const CIp &ip, const char *modules, cons ::strncpy(m_ReflectorModules, modules, sizeof(m_ReflectorModules)-1); m_Version = version; m_LastKeepaliveTime.Now(); - m_ConnectTime = std::time(NULL); - m_LastHeardTime = std::time(NULL); + m_ConnectTime = std::time(nullptr); + m_LastHeardTime = std::time(nullptr); } CPeer::CPeer(const CPeer &peer) @@ -68,10 +68,6 @@ CPeer::CPeer(const CPeer &peer) CPeer::~CPeer() { - for ( auto it=begin(); it!=end(); it++ ) - { - delete *it; - } m_Clients.clear(); } diff --git a/src/cpeer.h b/src/cpeer.h index dc2da68..dbfcb7f 100644 --- a/src/cpeer.h +++ b/src/cpeer.h @@ -68,17 +68,17 @@ public: virtual bool IsAMaster(void) const; virtual void Alive(void); virtual bool IsAlive(void) const { return false; } - virtual void Heard(void) { m_LastHeardTime = std::time(NULL); } + virtual void Heard(void) { m_LastHeardTime = std::time(nullptr); } // clients access int GetNbClients(void) const { return (int)m_Clients.size(); } void ClearClients(void) { m_Clients.clear(); } // pass-thru - std::list::iterator begin() { return m_Clients.begin(); } - std::list::iterator end() { return m_Clients.end(); } - std::list::const_iterator cbegin() const { return m_Clients.cbegin(); } - std::list::const_iterator cend() const { return m_Clients.cend(); } + std::list>::iterator begin() { return m_Clients.begin(); } + std::list>::iterator end() { return m_Clients.end(); } + std::list>::const_iterator cbegin() const { return m_Clients.cbegin(); } + std::list>::const_iterator cend() const { return m_Clients.cend(); } // reporting virtual void WriteXml(std::ofstream &); @@ -90,7 +90,7 @@ protected: CIp m_Ip; char m_ReflectorModules[27]; CVersion m_Version; - std::list m_Clients; + std::list> m_Clients; // status CTimePoint m_LastKeepaliveTime; diff --git a/src/cpeercallsignlist.cpp b/src/cpeercallsignlist.cpp index 1a605e0..b78fd32 100644 --- a/src/cpeercallsignlist.cpp +++ b/src/cpeercallsignlist.cpp @@ -53,15 +53,15 @@ bool CPeerCallsignList::LoadFromFile(const char *filename) if ( (::strlen(szt) > 0) && (szt[0] != '#') ) { // 1st token is callsign - if ( (szt = ::strtok(szt, " ,\t")) != NULL ) + if ( (szt = ::strtok(szt, " ,\t")) != nullptr ) { CCallsign callsign(szt); // 2nd token is ip char *szip; - if ( (szip = ::strtok(NULL, " ,\t")) != NULL ) + if ( (szip = ::strtok(nullptr, " ,\t")) != nullptr ) { // 3rd token is modules list - if ( (szt = ::strtok(NULL, " ,\t")) != NULL ) + if ( (szt = ::strtok(nullptr, " ,\t")) != nullptr ) { // and load m_Callsigns.push_back(CCallsignListItem(callsign, szip, szt)); diff --git a/src/cpeers.cpp b/src/cpeers.cpp index f631a22..cfbd4ec 100644 --- a/src/cpeers.cpp +++ b/src/cpeers.cpp @@ -40,8 +40,6 @@ CPeers::CPeers() {} CPeers::~CPeers() { m_Mutex.lock(); - for (auto it=begin(); it!=end(); it++ ) - delete *it; m_Peers.clear(); m_Mutex.unlock(); } @@ -49,7 +47,7 @@ CPeers::~CPeers() //////////////////////////////////////////////////////////////////////////////////////// // manage peers -void CPeers::AddPeer(CPeer *peer) +void CPeers::AddPeer(std::shared_ptrpeer) { // first check if peer already exists for ( auto it=begin(); it!=end(); it++ ) @@ -60,7 +58,6 @@ void CPeers::AddPeer(CPeer *peer) // on function return { // delete new one - delete peer; return; } } @@ -82,7 +79,7 @@ void CPeers::AddPeer(CPeer *peer) g_Reflector.OnPeersChanged(); } -void CPeers::RemovePeer(CPeer *peer) +void CPeers::RemovePeer(std::shared_ptrpeer) { // look for the client for ( auto pit=begin(); pit!=end(); /*increment done in body */ ) @@ -103,9 +100,7 @@ void CPeers::RemovePeer(CPeer *peer) g_Reflector.ReleaseClients(); // remove it - std::cout << "Peer " << (*pit)->GetCallsign() << " at " << (*pit)->GetIp() - << " removed" << std::endl; - delete *pit; + std::cout << "Peer " << (*pit)->GetCallsign() << " at " << (*pit)->GetIp() << " removed" << std::endl; pit = m_Peers.erase(pit); // notify g_Reflector.OnPeersChanged(); @@ -120,7 +115,7 @@ void CPeers::RemovePeer(CPeer *peer) //////////////////////////////////////////////////////////////////////////////////////// // find peers -CPeer *CPeers::FindPeer(const CIp &Ip, int Protocol) +std::shared_ptrCPeers::FindPeer(const CIp &Ip, int Protocol) { for ( auto it=begin(); it!=end(); it++ ) { @@ -130,10 +125,10 @@ CPeer *CPeers::FindPeer(const CIp &Ip, int Protocol) } } - return NULL; + return nullptr; } -CPeer *CPeers::FindPeer(const CCallsign &Callsign, const CIp &Ip, int Protocol) +std::shared_ptrCPeers::FindPeer(const CCallsign &Callsign, const CIp &Ip, int Protocol) { for ( auto it=begin(); it!=end(); it++ ) { @@ -145,10 +140,10 @@ CPeer *CPeers::FindPeer(const CCallsign &Callsign, const CIp &Ip, int Protocol) } } - return NULL; + return nullptr; } -CPeer *CPeers::FindPeer(const CCallsign &Callsign, int Protocol) +std::shared_ptrCPeers::FindPeer(const CCallsign &Callsign, int Protocol) { for ( auto it=begin(); it!=end(); it++ ) { @@ -159,14 +154,14 @@ CPeer *CPeers::FindPeer(const CCallsign &Callsign, int Protocol) } } - return NULL; + return nullptr; } //////////////////////////////////////////////////////////////////////////////////////// // iterate on peers -CPeer *CPeers::FindNextPeer(int Protocol, std::list::iterator &it) +std::shared_ptrCPeers::FindNextPeer(int Protocol, std::list>::iterator &it) { while ( it!=end() ) { @@ -176,5 +171,5 @@ CPeer *CPeers::FindNextPeer(int Protocol, std::list::iterator &it) } it++; } - return NULL; + return nullptr; } diff --git a/src/cpeers.h b/src/cpeers.h index d9b037f..8dfe644 100644 --- a/src/cpeers.h +++ b/src/cpeers.h @@ -51,27 +51,27 @@ public: // manage peers int GetSize(void) const { return (int)m_Peers.size(); } - void AddPeer(CPeer *); - void RemovePeer(CPeer *); + void AddPeer(std::shared_ptr); + void RemovePeer(std::shared_ptr); // pass-thru - std::list::iterator begin() { return m_Peers.begin(); } - std::list::iterator end() { return m_Peers.end(); } - std::list::const_iterator cbegin() const { return m_Peers.cbegin(); } - std::list::const_iterator cend() const { return m_Peers.cend(); } + std::list>::iterator begin() { return m_Peers.begin(); } + std::list>::iterator end() { return m_Peers.end(); } + std::list>::const_iterator cbegin() const { return m_Peers.cbegin(); } + std::list>::const_iterator cend() const { return m_Peers.cend(); } // find peers - CPeer *FindPeer(const CIp &, int); - CPeer *FindPeer(const CCallsign &, const CIp &, int); - CPeer *FindPeer(const CCallsign &, int); + std::shared_ptrFindPeer(const CIp &, int); + std::shared_ptrFindPeer(const CCallsign &, const CIp &, int); + std::shared_ptrFindPeer(const CCallsign &, int); // iterate on peers - CPeer *FindNextPeer(int, std::list::iterator &); + std::shared_ptrFindNextPeer(int, std::list>::iterator &); protected: // data std::mutex m_Mutex; - std::list m_Peers; + std::list> m_Peers; }; diff --git a/src/cprotocol.cpp b/src/cprotocol.cpp index f45cc91..9204154 100644 --- a/src/cprotocol.cpp +++ b/src/cprotocol.cpp @@ -33,7 +33,7 @@ // constructor -CProtocol::CProtocol() : keep_running(true), m_pThread(NULL) {} +CProtocol::CProtocol() : keep_running(true), m_pThread(nullptr) {} //////////////////////////////////////////////////////////////////////////////////////// @@ -43,11 +43,11 @@ CProtocol::~CProtocol() { // kill threads keep_running = false; - if ( m_pThread != NULL ) + if ( m_pThread != nullptr ) { m_pThread->join(); delete m_pThread; - m_pThread = NULL; + m_pThread = nullptr; } // Close sockets @@ -108,7 +108,7 @@ bool CProtocol::Initialize(const char *type, const uint16 port, const bool has_i // start thread; m_pThread = new std::thread(CProtocol::Thread, this); - if (m_pThread == NULL) + if (m_pThread == nullptr) { std::cerr << "Could not start DCS thread!" << std::endl; m_Socket4.Close(); @@ -131,11 +131,11 @@ void CProtocol::Thread(CProtocol *This) void CProtocol::Close(void) { keep_running = false; - if ( m_pThread != NULL ) + if ( m_pThread != nullptr ) { m_pThread->join(); delete m_pThread; - m_pThread = NULL; + m_pThread = nullptr; } m_Socket4.Close(); m_Socket6.Close(); @@ -176,7 +176,7 @@ void CProtocol::OnDvFramePacketIn(CDvFramePacket *Frame, const CIp *Ip) { // find the stream CPacketStream *stream = GetStream(Frame->GetStreamId(), Ip); - if ( stream == NULL ) + if ( stream == nullptr ) { std::cout << "Deleting orphaned Frame with ID " << Frame->GetStreamId() << " on " << *Ip << std::endl; delete Frame; @@ -195,7 +195,7 @@ void CProtocol::OnDvLastFramePacketIn(CDvLastFramePacket *Frame, const CIp *Ip) { // find the stream CPacketStream *stream = GetStream(Frame->GetStreamId(), Ip); - if ( stream == NULL ) + if ( stream == nullptr ) { std::cout << "Deleting orphaned Last Frame with ID " << Frame->GetStreamId() << " on " << *Ip << std::endl; delete Frame; @@ -221,8 +221,8 @@ CPacketStream *CProtocol::GetStream(uint16 uiStreamId, const CIp *Ip) { if ( (*it)->GetStreamId() == uiStreamId ) { - // if Ip not NULL, also check if IP match - if ( (Ip != NULL) && ((*it)->GetOwnerIp() != NULL) ) + // if Ip not nullptr, also check if IP match + if ( (Ip != nullptr) && ((*it)->GetOwnerIp() != nullptr) ) { if ( *Ip == *((*it)->GetOwnerIp()) ) { @@ -232,7 +232,7 @@ CPacketStream *CProtocol::GetStream(uint16 uiStreamId, const CIp *Ip) } } // done - return NULL; + return nullptr; } void CProtocol::CheckStreamsTimeout(void) diff --git a/src/cprotocol.h b/src/cprotocol.h index 1d7a939..92b4165 100644 --- a/src/cprotocol.h +++ b/src/cprotocol.h @@ -100,11 +100,11 @@ protected: // stream helpers virtual bool OnDvHeaderPacketIn(CDvHeaderPacket *, const CIp &) { return false; } - virtual void OnDvFramePacketIn(CDvFramePacket *, const CIp * = NULL); - virtual void OnDvLastFramePacketIn(CDvLastFramePacket *, const CIp * = NULL); + virtual void OnDvFramePacketIn(CDvFramePacket *, const CIp * = nullptr); + virtual void OnDvLastFramePacketIn(CDvLastFramePacket *, const CIp * = nullptr); // stream handle helpers - CPacketStream *GetStream(uint16, const CIp * = NULL); + CPacketStream *GetStream(uint16, const CIp * = nullptr); void CheckStreamsTimeout(void); // queue helper diff --git a/src/cprotocols.h b/src/cprotocols.h index 3f0124b..452efdc 100644 --- a/src/cprotocols.h +++ b/src/cprotocols.h @@ -51,7 +51,7 @@ public: protected: // data - std::mutex m_Mutex; + std::mutex m_Mutex; std::list m_Protocols; }; diff --git a/src/cqr1676.cpp b/src/cqr1676.cpp index a05ea3e..6ea3e31 100644 --- a/src/cqr1676.cpp +++ b/src/cqr1676.cpp @@ -75,40 +75,40 @@ unsigned int CQR1676::getSyndrome1576(unsigned int pattern) */ { unsigned int aux = X14; - + if (pattern >= X8) { while (pattern & MASK7) { while (!(aux & pattern)) aux = aux >> 1; - + pattern ^= (aux / X8) * GENPOL; } } - + return pattern; } // Compute the EMB against a precomputed list of correct words void CQR1676::encode(unsigned char* data) { - assert(data != NULL); - + assert(data != nullptr); + unsigned int value = (data[0U] >> 1) & 0x7FU; unsigned int cksum = ENCODING_TABLE_1676[value]; - + data[0U] = cksum >> 8; data[1U] = cksum & 0xFFU; } unsigned char CQR1676::decode(const unsigned char* data) { - assert(data != NULL); - + assert(data != nullptr); + unsigned int code = (data[0U] << 7) + (data[1U] >> 1); unsigned int syndrome = getSyndrome1576(code); unsigned int error_pattern = DECODING_TABLE_1576[syndrome]; - + code ^= error_pattern; - + return code >> 7; } diff --git a/src/creflector.cpp b/src/creflector.cpp index 7dc1a09..acc6863 100644 --- a/src/creflector.cpp +++ b/src/creflector.cpp @@ -39,11 +39,11 @@ CReflector::CReflector() { keep_running = true; - m_XmlReportThread = NULL; - m_JsonReportThread = NULL; + m_XmlReportThread = nullptr; + m_JsonReportThread = nullptr; for ( int i = 0; i < NB_OF_MODULES; i++ ) { - m_RouterThreads[i] = NULL; + m_RouterThreads[i] = nullptr; } #ifdef DEBUG_DUMPFILE m_DebugFile.open("/Users/jeanluc/Desktop/xlxdebug.txt"); @@ -56,11 +56,11 @@ CReflector::CReflector(const CCallsign &callsign) m_DebugFile.close(); #endif keep_running = true; - m_XmlReportThread = NULL; - m_JsonReportThread = NULL; + m_XmlReportThread = nullptr; + m_JsonReportThread = nullptr; for ( int i = 0; i < NB_OF_MODULES; i++ ) { - m_RouterThreads[i] = NULL; + m_RouterThreads[i] = nullptr; } m_Callsign = callsign; } @@ -71,19 +71,19 @@ CReflector::CReflector(const CCallsign &callsign) CReflector::~CReflector() { keep_running = false; - if ( m_XmlReportThread != NULL ) + if ( m_XmlReportThread != nullptr ) { m_XmlReportThread->join(); delete m_XmlReportThread; } - if ( m_JsonReportThread != NULL ) + if ( m_JsonReportThread != nullptr ) { m_JsonReportThread->join(); delete m_JsonReportThread; } for ( int i = 0; i < NB_OF_MODULES; i++ ) { - if ( m_RouterThreads[i] != NULL ) + if ( m_RouterThreads[i] != nullptr ) { m_RouterThreads[i]->join(); delete m_RouterThreads[i]; @@ -145,27 +145,27 @@ void CReflector::Stop(void) keep_running = false; // stop & delete report threads - if ( m_XmlReportThread != NULL ) + if ( m_XmlReportThread != nullptr ) { m_XmlReportThread->join(); delete m_XmlReportThread; - m_XmlReportThread = NULL; + m_XmlReportThread = nullptr; } - if ( m_JsonReportThread != NULL ) + if ( m_JsonReportThread != nullptr ) { m_JsonReportThread->join(); delete m_JsonReportThread; - m_JsonReportThread = NULL; + m_JsonReportThread = nullptr; } // stop & delete all router thread for ( int i = 0; i < NB_OF_MODULES; i++ ) { - if ( m_RouterThreads[i] != NULL ) + if ( m_RouterThreads[i] != nullptr ) { m_RouterThreads[i]->join(); delete m_RouterThreads[i]; - m_RouterThreads[i] = NULL; + m_RouterThreads[i] = nullptr; } } @@ -195,14 +195,14 @@ bool CReflector::IsStreaming(char module) return false; } -CPacketStream *CReflector::OpenStream(CDvHeaderPacket *DvHeader, CClient *client) +CPacketStream *CReflector::OpenStream(CDvHeaderPacket *DvHeader, std::shared_ptrclient) { - CPacketStream *retStream = NULL; + CPacketStream *retStream = nullptr; // clients MUST have bee locked by the caller // so we can freely access it within the fuction - // check sid is not NULL + // check sid is not nullptr if ( DvHeader->GetStreamId() != 0 ) { // check if client is valid candidate @@ -215,7 +215,7 @@ CPacketStream *CReflector::OpenStream(CDvHeaderPacket *DvHeader, CClient *client // get the module's queue char module = DvHeader->GetRpt2Module(); CPacketStream *stream = GetStream(module); - if ( stream != NULL ) + if ( stream != nullptr ) { // lock it stream->Lock(); @@ -259,7 +259,7 @@ CPacketStream *CReflector::OpenStream(CDvHeaderPacket *DvHeader, CClient *client void CReflector::CloseStream(CPacketStream *stream) { // - if ( stream != NULL ) + if ( stream != nullptr ) { // wait queue is empty // this waits forever @@ -286,8 +286,8 @@ void CReflector::CloseStream(CPacketStream *stream) stream->Lock(); // get and check the master - CClient *client = stream->GetOwnerClient(); - if ( client != NULL ) + std::shared_ptrclient = stream->GetOwnerClient(); + if ( client != nullptr ) { // client no longer a master client->NotAMaster(); @@ -336,12 +336,12 @@ void CReflector::RouterThread(CReflector *This, CPacketStream *streamIn) } else { - packet = NULL; + packet = nullptr; } streamIn->Unlock(); // route it - if ( packet != NULL ) + if ( packet != nullptr ) { // set origin packet->SetModuleId(uiModuleId); @@ -368,7 +368,7 @@ void CReflector::RouterThread(CReflector *This, CPacketStream *streamIn) } // done delete packet; - packet = NULL; + packet = nullptr; } else { @@ -566,7 +566,7 @@ int CReflector::GetModuleIndex(char module) const CPacketStream *CReflector::GetStream(char module) { - CPacketStream *stream = NULL; + CPacketStream *stream = nullptr; int i = GetModuleIndex(module); if ( i >= 0 ) { diff --git a/src/creflector.h b/src/creflector.h index 872ac1d..485ca6a 100644 --- a/src/creflector.h +++ b/src/creflector.h @@ -87,7 +87,7 @@ public: void ReleasePeers(void) { m_Peers.Unlock(); } // stream opening & closing - CPacketStream *OpenStream(CDvHeaderPacket *, CClient *); + CPacketStream *OpenStream(CDvHeaderPacket *, std::shared_ptr); bool IsStreaming(char); void CloseStream(CPacketStream *); diff --git a/src/crs129.cpp b/src/crs129.cpp index 182a438..39e8d4e 100644 --- a/src/crs129.cpp +++ b/src/crs129.cpp @@ -87,10 +87,10 @@ static unsigned char gmult(unsigned char a, unsigned char b) { if (a == 0U || b == 0U) return 0U; - + unsigned int i = LOG_TABLE[a]; unsigned int j = LOG_TABLE[b]; - + return EXP_TABLE[i + j]; } @@ -101,18 +101,18 @@ static unsigned char gmult(unsigned char a, unsigned char b) */ void CRS129::encode(const unsigned char* msg, unsigned int nbytes, unsigned char* parity) { - assert(msg != NULL); - assert(parity != NULL); - + assert(msg != nullptr); + assert(parity != nullptr); + for (unsigned int i = 0U; i < NPAR + 1U; i++) parity[i] = 0x00U; - + for (unsigned int i = 0U; i < nbytes; i++) { unsigned char dbyte = msg[i] ^ parity[NPAR - 1U]; - + for (int j = NPAR - 1; j > 0; j--) parity[j] = parity[j - 1] ^ ::gmult(POLY[j], dbyte); - + parity[0] = ::gmult(POLY[0], dbyte); } } @@ -120,11 +120,10 @@ void CRS129::encode(const unsigned char* msg, unsigned int nbytes, unsigned char // Reed-Solomon (12,9) check bool CRS129::check(const unsigned char* in) { - assert(in != NULL); - + assert(in != nullptr); + unsigned char parity[4U]; encode(in, 9U, parity); - + return in[9U] == parity[2U] && in[10U] == parity[1U] && in[11U] == parity[0U]; } - diff --git a/src/ctranscoder.cpp b/src/ctranscoder.cpp index 6c28335..2ec6809 100644 --- a/src/ctranscoder.cpp +++ b/src/ctranscoder.cpp @@ -47,7 +47,7 @@ CTranscoder g_Transcoder; CTranscoder::CTranscoder() { keep_running = true; - m_pThread = NULL; + m_pThread = nullptr; m_bConnected = false; m_LastKeepaliveTime.Now(); m_LastActivityTime.Now(); @@ -133,11 +133,11 @@ void CTranscoder::Close(void) // kill threads keep_running = false; - if ( m_pThread != NULL ) + if ( m_pThread != nullptr ) { m_pThread->join(); delete m_pThread; - m_pThread = NULL; + m_pThread = nullptr; } } @@ -208,7 +208,7 @@ CCodecStream *CTranscoder::GetStream(CPacketStream *PacketStream, uint8 uiCodecI { CBuffer Buffer; - CCodecStream *stream = NULL; + CCodecStream *stream = nullptr; // do we need transcoding if ( uiCodecIn != CODEC_NONE ) @@ -245,7 +245,7 @@ CCodecStream *CTranscoder::GetStream(CPacketStream *PacketStream, uint8 uiCodecI m_Socket.Send(Buffer, m_Ip, TRANSCODER_PORT); // and delete delete stream; - stream = NULL; + stream = nullptr; } } else @@ -267,7 +267,7 @@ void CTranscoder::ReleaseStream(CCodecStream *stream) { CBuffer Buffer; - if ( stream != NULL ) + if ( stream != nullptr ) { // look for the stream bool found = false; diff --git a/src/cudpmsgsocket.cpp b/src/cudpmsgsocket.cpp index 39b09ec..2178981 100644 --- a/src/cudpmsgsocket.cpp +++ b/src/cudpmsgsocket.cpp @@ -100,7 +100,7 @@ int CUdpMsgSocket::Receive(CBuffer *Buffer, CIp *Ip, int timeout) // get local IP struct cmsghdr *Cmsg; - for (Cmsg = CMSG_FIRSTHDR(&Msg); Cmsg != NULL; Cmsg = CMSG_NXTHDR(&Msg, Cmsg)) + for (Cmsg = CMSG_FIRSTHDR(&Msg); Cmsg != nullptr; Cmsg = CMSG_NXTHDR(&Msg, Cmsg)) { if (Cmsg->cmsg_level == IPPROTO_IP && Cmsg->cmsg_type == IP_PKTINFO) { diff --git a/src/cuser.cpp b/src/cuser.cpp index 6cf6024..502827b 100644 --- a/src/cuser.cpp +++ b/src/cuser.cpp @@ -19,7 +19,7 @@ // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License -// along with Foobar. If not, see . +// along with Foobar. If not, see . // ---------------------------------------------------------------------------- #include "main.h" @@ -32,7 +32,7 @@ CUser::CUser() { - m_LastHeardTime = std::time(NULL); + m_LastHeardTime = std::time(nullptr); } CUser::CUser(const CCallsign &my, const CCallsign &rpt1, const CCallsign &rpt2, const CCallsign &xlx) @@ -41,7 +41,7 @@ CUser::CUser(const CCallsign &my, const CCallsign &rpt1, const CCallsign &rpt2, m_Rpt1 = rpt1; m_Rpt2 = rpt2; m_Xlx = xlx; - m_LastHeardTime = std::time(NULL); + m_LastHeardTime = std::time(nullptr); } CUser::CUser(const CUser &user) @@ -93,12 +93,12 @@ void CUser::GetJsonObject(char *Buffer) char mbstr[100]; char my[16]; char rpt1[16]; - + if (std::strftime(mbstr, sizeof(mbstr), "%A %c", std::localtime(&m_LastHeardTime))) { m_My.GetCallsignString(my); m_Rpt1.GetCallsignString(rpt1); - + ::sprintf(sz, "{\"callsign\":\"%s\",\"node\":\"%s\",\"module\":\"%c\",\"time\":\"%s\"}", my, rpt1, diff --git a/src/cuser.h b/src/cuser.h index b111ae4..1ef667a 100644 --- a/src/cuser.h +++ b/src/cuser.h @@ -19,7 +19,7 @@ // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License -// along with Foobar. If not, see . +// along with Foobar. If not, see . // ---------------------------------------------------------------------------- #ifndef cuser_h @@ -37,12 +37,12 @@ public: CUser(); CUser(const CCallsign &, const CCallsign &, const CCallsign &, const CCallsign &); CUser(const CUser &); - + // destructor ~CUser() {} - + // operation - void HeardNow(void) { m_LastHeardTime = std::time(NULL); } + void HeardNow(void) { m_LastHeardTime = std::time(nullptr); } // operators bool operator ==(const CUser &) const; diff --git a/src/cutils.cpp b/src/cutils.cpp index d86d79b..32108a9 100644 --- a/src/cutils.cpp +++ b/src/cutils.cpp @@ -18,8 +18,8 @@ void CUtils::byteToBitsBE(unsigned char byte, bool* bits) { - assert(bits != NULL); - + assert(bits != nullptr); + bits[0U] = (byte & 0x80U) == 0x80U; bits[1U] = (byte & 0x40U) == 0x40U; bits[2U] = (byte & 0x20U) == 0x20U; @@ -32,8 +32,8 @@ void CUtils::byteToBitsBE(unsigned char byte, bool* bits) void CUtils::byteToBitsLE(unsigned char byte, bool* bits) { - assert(bits != NULL); - + assert(bits != nullptr); + bits[0U] = (byte & 0x01U) == 0x01U; bits[1U] = (byte & 0x02U) == 0x02U; bits[2U] = (byte & 0x04U) == 0x04U; @@ -46,8 +46,8 @@ void CUtils::byteToBitsLE(unsigned char byte, bool* bits) void CUtils::bitsToByteBE(const bool* bits, unsigned char& byte) { - assert(bits != NULL); - + assert(bits != nullptr); + byte = bits[0U] ? 0x80U : 0x00U; byte |= bits[1U] ? 0x40U : 0x00U; byte |= bits[2U] ? 0x20U : 0x00U; @@ -60,8 +60,8 @@ void CUtils::bitsToByteBE(const bool* bits, unsigned char& byte) void CUtils::bitsToByteLE(const bool* bits, unsigned char& byte) { - assert(bits != NULL); - + assert(bits != nullptr); + byte = bits[0U] ? 0x01U : 0x00U; byte |= bits[1U] ? 0x02U : 0x00U; byte |= bits[2U] ? 0x04U : 0x00U; diff --git a/src/cwiresxcmdhandler.cpp b/src/cwiresxcmdhandler.cpp index c38809c..5d6334e 100644 --- a/src/cwiresxcmdhandler.cpp +++ b/src/cwiresxcmdhandler.cpp @@ -41,7 +41,7 @@ CWiresxCmdHandler::CWiresxCmdHandler() { m_seqNo = 0; keep_running = true; - m_pThread = NULL; + m_pThread = nullptr; } @@ -52,11 +52,11 @@ CWiresxCmdHandler::~CWiresxCmdHandler() { // kill threads keep_running = false; - if ( m_pThread != NULL ) + if ( m_pThread != nullptr ) { m_pThread->join(); delete m_pThread; - m_pThread = NULL; + m_pThread = nullptr; } // empty queue @@ -91,11 +91,11 @@ bool CWiresxCmdHandler::Init(void) void CWiresxCmdHandler::Close(void) { keep_running = false; - if ( m_pThread != NULL ) + if ( m_pThread != nullptr ) { m_pThread->join(); delete m_pThread; - m_pThread = NULL; + m_pThread = nullptr; } } @@ -156,8 +156,8 @@ void CWiresxCmdHandler::Task(void) // find our client and the module it's currentlink linked to cModule = ' '; CClients *clients = g_Reflector.GetClients(); - CClient *client = clients->FindClient(Cmd.GetCallsign(), Cmd.GetIp(), PROTOCOL_YSF); - if ( client != NULL ) + std::shared_ptrclient = clients->FindClient(Cmd.GetCallsign(), Cmd.GetIp(), PROTOCOL_YSF); + if ( client != nullptr ) { cModule = client->GetReflectorModule(); } @@ -186,8 +186,8 @@ void CWiresxCmdHandler::Task(void) ReplyToWiresxConnReqPacket(Cmd.GetIp(), Info, cModule); // change client's module CClients *clients = g_Reflector.GetClients(); - CClient *client = clients->FindClient(Cmd.GetCallsign(), Cmd.GetIp(), PROTOCOL_YSF); - if ( client != NULL ) + std::shared_ptrclient = clients->FindClient(Cmd.GetCallsign(), Cmd.GetIp(), PROTOCOL_YSF); + if ( client != nullptr ) { client->SetReflectorModule(cModule); } @@ -205,8 +205,8 @@ void CWiresxCmdHandler::Task(void) // change client's module { CClients *clients = g_Reflector.GetClients(); - CClient *client = clients->FindClient(Cmd.GetCallsign(), Cmd.GetIp(), PROTOCOL_YSF); - if ( client != NULL ) + std::shared_ptrclient = clients->FindClient(Cmd.GetCallsign(), Cmd.GetIp(), PROTOCOL_YSF); + if ( client != nullptr ) { client->SetReflectorModule(' '); } diff --git a/src/cxlxpeer.cpp b/src/cxlxpeer.cpp index 02f943a..7e85630 100644 --- a/src/cxlxpeer.cpp +++ b/src/cxlxpeer.cpp @@ -48,10 +48,8 @@ CXlxPeer::CXlxPeer(const CCallsign &callsign, const CIp &ip, const char *modules // and construct all xlx clients for ( unsigned i = 0; i < ::strlen(modules); i++ ) { - // create - CXlxClient *client = new CXlxClient(callsign, ip, modules[i], protrev); - // and append to vector - m_Clients.push_back(client); + // create and append to vector + m_Clients.push_back(std::make_shared(callsign, ip, modules[i], protrev)); } } @@ -60,9 +58,8 @@ CXlxPeer::CXlxPeer(const CXlxPeer &peer) { for ( auto it=peer.cbegin(); it!=peer.cend(); it++ ) { - CXlxClient *client = new CXlxClient((const CXlxClient &)*(*it)); + std::shared_ptr client(new CXlxClient((const CXlxClient &)*(*it))); m_Clients.push_back(client); - } } diff --git a/src/cxlxprotocol.cpp b/src/cxlxprotocol.cpp index 4a42012..312dddc 100644 --- a/src/cxlxprotocol.cpp +++ b/src/cxlxprotocol.cpp @@ -74,14 +74,14 @@ void CXlxProtocol::Task(void) #endif { // crack the packet - if ( (Frame = IsValidDvFramePacket(Buffer)) != NULL ) + if ( (Frame = IsValidDvFramePacket(Buffer)) != nullptr ) { //std::cout << "XLX (DExtra) DV frame" << std::endl; // handle it OnDvFramePacketIn(Frame, &Ip); } - else if ( (Header = IsValidDvHeaderPacket(Buffer)) != NULL ) + else if ( (Header = IsValidDvHeaderPacket(Buffer)) != nullptr ) { //std::cout << "XLX (DExtra) DV header:" << std::endl << *Header << std::endl; //std::cout << "XLX (DExtra) DV header on module " << Header->GetRpt2Module() << std::endl; @@ -97,7 +97,7 @@ void CXlxProtocol::Task(void) delete Header; } } - else if ( (LastFrame = IsValidDvLastFramePacket(Buffer)) != NULL ) + else if ( (LastFrame = IsValidDvLastFramePacket(Buffer)) != nullptr ) { //std::cout << "XLX (DExtra) DV last frame" << std::endl; @@ -122,7 +122,7 @@ void CXlxProtocol::Task(void) { // already connected ? CPeers *peers = g_Reflector.GetPeers(); - if ( peers->FindPeer(Callsign, Ip, PROTOCOL_XLX) == NULL ) + if ( peers->FindPeer(Callsign, Ip, PROTOCOL_XLX) == nullptr ) { // acknowledge the request EncodeConnectAckPacket(&Buffer, Modules); @@ -157,11 +157,11 @@ void CXlxProtocol::Task(void) { // already connected ? CPeers *peers = g_Reflector.GetPeers(); - if ( peers->FindPeer(Callsign, Ip, PROTOCOL_XLX) == NULL ) + if ( peers->FindPeer(Callsign, Ip, PROTOCOL_XLX) == nullptr ) { // create the new peer // this also create one client per module - CPeer *peer = CreateNewPeer(Callsign, Ip, Modules, Version); + std::shared_ptrpeer = CreateNewPeer(Callsign, Ip, Modules, Version); // append the peer to reflector peer list // this also add all new clients to reflector client list @@ -176,8 +176,8 @@ void CXlxProtocol::Task(void) // find peer CPeers *peers = g_Reflector.GetPeers(); - CPeer *peer = peers->FindPeer(Ip, PROTOCOL_XLX); - if ( peer != NULL ) + std::shared_ptrpeer = peers->FindPeer(Ip, PROTOCOL_XLX); + if ( peer != nullptr ) { // remove it from reflector peer list // this also remove all concerned clients from reflector client list @@ -196,8 +196,8 @@ void CXlxProtocol::Task(void) // find peer CPeers *peers = g_Reflector.GetPeers(); - CPeer *peer = peers->FindPeer(Ip, PROTOCOL_XLX); - if ( peer != NULL ) + std::shared_ptrpeer = peers->FindPeer(Ip, PROTOCOL_XLX); + if ( peer != nullptr ) { // keep it alive peer->Alive(); @@ -268,8 +268,8 @@ void CXlxProtocol::HandleQueue(void) // and push it to all our clients linked to the module and who are not streaming in CClients *clients = g_Reflector.GetClients(); auto it = clients->begin(); - CClient *client = NULL; - while ( (client = clients->FindNextClient(PROTOCOL_XLX, it)) != NULL ) + std::shared_ptrclient = nullptr; + while ( (client = clients->FindNextClient(PROTOCOL_XLX, it)) != nullptr ) { // is this client busy ? if ( !client->IsAMaster() && (client->GetReflectorModule() == packet->GetModuleId()) ) @@ -322,8 +322,8 @@ void CXlxProtocol::HandleKeepalives(void) // iterate on peers CPeers *peers = g_Reflector.GetPeers(); auto pit = peers->begin(); - CPeer *peer = NULL; - while ( (peer = peers->FindNextPeer(PROTOCOL_XLX, pit)) != NULL ) + std::shared_ptrpeer = nullptr; + while ( (peer = peers->FindNextPeer(PROTOCOL_XLX, pit)) != nullptr ) { // send keepalive Send(keepalive, peer->GetIp()); @@ -364,10 +364,10 @@ void CXlxProtocol::HandlePeerLinks(void) // check if all our connected peers are still listed by gatekeeper // if not, disconnect auto pit = peers->begin(); - CPeer *peer = NULL; - while ( (peer = peers->FindNextPeer(PROTOCOL_XLX, pit)) != NULL ) + std::shared_ptrpeer = nullptr; + while ( (peer = peers->FindNextPeer(PROTOCOL_XLX, pit)) != nullptr ) { - if ( list->FindListItem(peer->GetCallsign()) == NULL ) + if ( list->FindListItem(peer->GetCallsign()) == nullptr ) { // send disconnect packet EncodeDisconnectPacket(&buffer); @@ -384,7 +384,7 @@ void CXlxProtocol::HandlePeerLinks(void) { if ( (*it).GetCallsign().HasSameCallsignWithWildcard(CCallsign("XRF*")) ) continue; - if ( peers->FindPeer((*it).GetCallsign(), PROTOCOL_XLX) == NULL ) + if ( peers->FindPeer((*it).GetCallsign(), PROTOCOL_XLX) == nullptr ) { // resolve again peer's IP in case it's a dynamic IP (*it).ResolveIp(); @@ -417,15 +417,15 @@ bool CXlxProtocol::OnDvHeaderPacketIn(CDvHeaderPacket *Header, const CIp &Ip) // find the stream CPacketStream *stream = GetStream(Header->GetStreamId()); - if ( stream == NULL ) + if ( stream == nullptr ) { // no stream open yet, open a new one // find this client - CClient *client = g_Reflector.GetClients()->FindClient(Ip, PROTOCOL_XLX, Header->GetRpt2Module()); - if ( client != NULL ) + std::shared_ptrclient = g_Reflector.GetClients()->FindClient(Ip, PROTOCOL_XLX, Header->GetRpt2Module()); + if ( client != nullptr ) { // and try to open the stream - if ( (stream = g_Reflector.OpenStream(Header, client)) != NULL ) + if ( (stream = g_Reflector.OpenStream(Header, client)) != nullptr ) { // keep the handle m_Streams.push_back(stream); @@ -550,13 +550,13 @@ bool CXlxProtocol::IsValidNackPacket(const CBuffer &Buffer, CCallsign *callsign) CDvFramePacket *CXlxProtocol::IsValidDvFramePacket(const CBuffer &Buffer) { - CDvFramePacket *dvframe = NULL; + CDvFramePacket *dvframe = nullptr; // base class first (protocol revision 1 and lower) dvframe = CDextraProtocol::IsValidDvFramePacket(Buffer); // otherwise try protocol revision 2 - if ( (dvframe == NULL) && + if ( (dvframe == nullptr) && (Buffer.size() == 45) && (Buffer.Compare((uint8 *)"DSVT", 4) == 0) && (Buffer.data()[4] == 0x20) && (Buffer.data()[8] == 0x20) && ((Buffer.data()[14] & 0x40) == 0) ) @@ -574,7 +574,7 @@ CDvFramePacket *CXlxProtocol::IsValidDvFramePacket(const CBuffer &Buffer) if ( !dvframe->IsValid() ) { delete dvframe; - dvframe = NULL; + dvframe = nullptr; } } @@ -584,13 +584,13 @@ CDvFramePacket *CXlxProtocol::IsValidDvFramePacket(const CBuffer &Buffer) CDvLastFramePacket *CXlxProtocol::IsValidDvLastFramePacket(const CBuffer &Buffer) { - CDvLastFramePacket *dvframe = NULL; + CDvLastFramePacket *dvframe = nullptr; // base class first (protocol revision 1 and lower) dvframe = CDextraProtocol::IsValidDvLastFramePacket(Buffer); // otherwise try protocol revision 2 - if ( (dvframe == NULL) && + if ( (dvframe == nullptr) && (Buffer.size() == 45) && (Buffer.Compare((uint8 *)"DSVT", 4) == 0) && (Buffer.data()[4] == 0x20) && (Buffer.data()[8] == 0x20) && ((Buffer.data()[14] & 0x40) != 0) ) @@ -608,7 +608,7 @@ CDvLastFramePacket *CXlxProtocol::IsValidDvLastFramePacket(const CBuffer &Buffer if ( !dvframe->IsValid() ) { delete dvframe; - dvframe = NULL; + dvframe = nullptr; } } @@ -746,20 +746,15 @@ int CXlxProtocol::GetConnectingPeerProtocolRevision(const CCallsign &Callsign, c return protrev; } -CPeer *CXlxProtocol::CreateNewPeer(const CCallsign &Callsign, const CIp &Ip, char *Modules, const CVersion &Version) +std::shared_ptr CXlxProtocol::CreateNewPeer(const CCallsign &Callsign, const CIp &Ip, char *Modules, const CVersion &Version) { - CPeer *peer = NULL; - // BM ? if ( Callsign.HasSameCallsignWithWildcard(CCallsign("BM*")) ) { - peer = new CBmPeer(Callsign, Ip, Modules, Version); + return std::make_shared(Callsign, Ip, Modules, Version); } else { - peer = new CXlxPeer(Callsign, Ip, Modules, Version); + return std::make_shared(Callsign, Ip, Modules, Version); } - - // done - return peer; } diff --git a/src/cxlxprotocol.h b/src/cxlxprotocol.h index b36a469..7fe4597 100644 --- a/src/cxlxprotocol.h +++ b/src/cxlxprotocol.h @@ -56,8 +56,8 @@ protected: // stream helpers bool OnDvHeaderPacketIn(CDvHeaderPacket *, const CIp &); - void OnDvFramePacketIn(CDvFramePacket *, const CIp * = NULL); - void OnDvLastFramePacketIn(CDvLastFramePacket *, const CIp * = NULL); + void OnDvFramePacketIn(CDvFramePacket *, const CIp * = nullptr); + void OnDvLastFramePacketIn(CDvLastFramePacket *, const CIp * = nullptr); // packet decoding helpers bool IsValidKeepAlivePacket(const CBuffer &, CCallsign *); @@ -79,7 +79,7 @@ protected: // protocol revision helper int GetConnectingPeerProtocolRevision(const CCallsign &, const CVersion &); - CPeer *CreateNewPeer(const CCallsign &, const CIp &, char *, const CVersion &); + std::shared_ptrCreateNewPeer(const CCallsign &, const CIp &, char *, const CVersion &); protected: // time diff --git a/src/cysfconvolution.cpp b/src/cysfconvolution.cpp index f397ec0..6a1f0cf 100644 --- a/src/cysfconvolution.cpp +++ b/src/cysfconvolution.cpp @@ -36,12 +36,12 @@ const uint32_t M = 2U; const unsigned int K = 5U; CYSFConvolution::CYSFConvolution() : -m_metrics1(NULL), -m_metrics2(NULL), -m_oldMetrics(NULL), -m_newMetrics(NULL), -m_decisions(NULL), -m_dp(NULL) +m_metrics1(nullptr), +m_metrics2(nullptr), +m_oldMetrics(nullptr), +m_newMetrics(nullptr), +m_decisions(nullptr), +m_dp(nullptr) { m_metrics1 = new uint16_t[16U]; m_metrics2 = new uint16_t[16U]; @@ -59,7 +59,7 @@ void CYSFConvolution::start() { ::memset(m_metrics1, 0x00U, NUM_OF_STATES * sizeof(uint16_t)); ::memset(m_metrics2, 0x00U, NUM_OF_STATES * sizeof(uint16_t)); - + m_oldMetrics = m_metrics1; m_newMetrics = m_metrics2; m_dp = m_decisions; @@ -68,29 +68,29 @@ void CYSFConvolution::start() void CYSFConvolution::decode(uint8_t s0, uint8_t s1) { *m_dp = 0U; - + for (uint8_t i = 0U; i < NUM_OF_STATES_D2; i++) { uint8_t j = i * 2U; - + uint16_t metric = (BRANCH_TABLE1[i] ^ s0) + (BRANCH_TABLE2[i] ^ s1); - + uint16_t m0 = m_oldMetrics[i] + metric; uint16_t m1 = m_oldMetrics[i + NUM_OF_STATES_D2] + (M - metric); uint8_t decision0 = (m0 >= m1) ? 1U : 0U; m_newMetrics[j + 0U] = decision0 != 0U ? m1 : m0; - + m0 = m_oldMetrics[i] + (M - metric); m1 = m_oldMetrics[i + NUM_OF_STATES_D2] + metric; uint8_t decision1 = (m0 >= m1) ? 1U : 0U; m_newMetrics[j + 1U] = decision1 != 0U ? m1 : m0; - + *m_dp |= (uint64_t(decision1) << (j + 1U)) | (uint64_t(decision0) << (j + 0U)); } - + ++m_dp; - + assert((m_dp - m_decisions) <= 180); - + uint16_t* tmp = m_oldMetrics; m_oldMetrics = m_newMetrics; m_newMetrics = tmp; @@ -98,43 +98,43 @@ void CYSFConvolution::decode(uint8_t s0, uint8_t s1) void CYSFConvolution::chainback(unsigned char* out, unsigned int nBits) { - assert(out != NULL); - + assert(out != nullptr); + uint32_t state = 0U; - + while (nBits-- > 0) { --m_dp; - + uint32_t i = state >> (9 - K); uint8_t bit = uint8_t(*m_dp >> i) & 1; state = (bit << 7) | (state >> 1); - + WRITE_BIT1(out, nBits, bit != 0U); } } void CYSFConvolution::encode(const unsigned char* in, unsigned char* out, unsigned int nBits) const { - assert(in != NULL); - assert(out != NULL); + assert(in != nullptr); + assert(out != nullptr); assert(nBits > 0U); - + uint8_t d1 = 0U, d2 = 0U, d3 = 0U, d4 = 0U; uint32_t k = 0U; for (unsigned int i = 0U; i < nBits; i++) { uint8_t d = READ_BIT1(in, i) ? 1U : 0U; - + uint8_t g1 = (d + d3 + d4) & 1; uint8_t g2 = (d + d1 + d2 + d4) & 1; - + d4 = d3; d3 = d2; d2 = d1; d1 = d; - + WRITE_BIT1(out, k, g1 != 0U); k++; - + WRITE_BIT1(out, k, g2 != 0U); k++; } diff --git a/src/cysffich.cpp b/src/cysffich.cpp index 36a093b..aea571c 100644 --- a/src/cysffich.cpp +++ b/src/cysffich.cpp @@ -56,7 +56,7 @@ const unsigned int INTERLEAVE_TABLE[] = { 38U, 78U, 118U, 158U, 198U}; CYSFFICH::CYSFFICH() : -m_fich(NULL) +m_fich(nullptr) { m_fich = new unsigned char[6U]; ::memset(m_fich, 0U, 6U); @@ -69,56 +69,56 @@ CYSFFICH::~CYSFFICH() bool CYSFFICH::decode(const unsigned char* bytes) { - assert(bytes != NULL); - + assert(bytes != nullptr); + CYSFConvolution viterbi; viterbi.start(); - + // Deinterleave the FICH and send bits to the Viterbi decoder for (unsigned int i = 0U; i < 100U; i++) { unsigned int n = INTERLEAVE_TABLE[i]; uint8_t s0 = READ_BIT1(bytes, n) ? 1U : 0U; - + n++; uint8_t s1 = READ_BIT1(bytes, n) ? 1U : 0U; - + viterbi.decode(s0, s1); } - + unsigned char output[13U]; viterbi.chainback(output, 96U); - + unsigned int b0 = CGolay24128::decode24128(output + 0U); unsigned int b1 = CGolay24128::decode24128(output + 3U); unsigned int b2 = CGolay24128::decode24128(output + 6U); unsigned int b3 = CGolay24128::decode24128(output + 9U); - + m_fich[0U] = (b0 >> 4) & 0xFFU; m_fich[1U] = ((b0 << 4) & 0xF0U) | ((b1 >> 8) & 0x0FU); m_fich[2U] = (b1 >> 0) & 0xFFU; m_fich[3U] = (b2 >> 4) & 0xFFU; m_fich[4U] = ((b2 << 4) & 0xF0U) | ((b3 >> 8) & 0x0FU); m_fich[5U] = (b3 >> 0) & 0xFFU; - + return CCRC::checkCCITT162(m_fich, 6U); } void CYSFFICH::encode(unsigned char* bytes) { - assert(bytes != NULL); - + assert(bytes != nullptr); + CCRC::addCCITT162(m_fich, 6U); - + unsigned int b0 = ((m_fich[0U] << 4) & 0xFF0U) | ((m_fich[1U] >> 4) & 0x00FU); unsigned int b1 = ((m_fich[1U] << 8) & 0xF00U) | ((m_fich[2U] >> 0) & 0x0FFU); unsigned int b2 = ((m_fich[3U] << 4) & 0xFF0U) | ((m_fich[4U] >> 4) & 0x00FU); unsigned int b3 = ((m_fich[4U] << 8) & 0xF00U) | ((m_fich[5U] >> 0) & 0x0FFU); - + unsigned int c0 = CGolay24128::encode24128(b0); unsigned int c1 = CGolay24128::encode24128(b1); unsigned int c2 = CGolay24128::encode24128(b2); unsigned int c3 = CGolay24128::encode24128(b3); - + unsigned char conv[13U]; conv[0U] = (c0 >> 16) & 0xFFU; conv[1U] = (c0 >> 8) & 0xFFU; @@ -133,23 +133,23 @@ void CYSFFICH::encode(unsigned char* bytes) conv[10U] = (c3 >> 8) & 0xFFU; conv[11U] = (c3 >> 0) & 0xFFU; conv[12U] = 0x00U; - + CYSFConvolution convolution; unsigned char convolved[25U]; convolution.encode(conv, convolved, 100U); - + unsigned int j = 0U; for (unsigned int i = 0U; i < 100U; i++) { unsigned int n = INTERLEAVE_TABLE[i]; - + bool s0 = READ_BIT1(convolved, j) != 0U; j++; - + bool s1 = READ_BIT1(convolved, j) != 0U; j++; - + WRITE_BIT1(bytes, n, s0); - + n++; WRITE_BIT1(bytes, n, s1); } @@ -301,8 +301,7 @@ void CYSFFICH::setBT(unsigned char bt) void CYSFFICH::load(const unsigned char* fich) { - assert(fich != NULL); - + assert(fich != nullptr); + ::memcpy(m_fich, fich, 4U); } - diff --git a/src/cysfnodedir.cpp b/src/cysfnodedir.cpp index 39e2e24..1762a51 100644 --- a/src/cysfnodedir.cpp +++ b/src/cysfnodedir.cpp @@ -34,18 +34,18 @@ CYsfNodeDir::CYsfNodeDir() { keep_running = true; - m_pThread = NULL; + m_pThread = nullptr; } CYsfNodeDir::~CYsfNodeDir() { // kill threads keep_running = false; - if ( m_pThread != NULL ) + if ( m_pThread != nullptr ) { m_pThread->join(); delete m_pThread; - m_pThread = NULL; + m_pThread = nullptr; } } @@ -70,11 +70,11 @@ bool CYsfNodeDir::Init(void) void CYsfNodeDir::Close(void) { keep_running = false; - if ( m_pThread != NULL ) + if ( m_pThread != nullptr ) { m_pThread->join(); delete m_pThread; - m_pThread = NULL; + m_pThread = nullptr; } } diff --git a/src/cysfnodedirfile.cpp b/src/cysfnodedirfile.cpp index 46da902..ac2cf2e 100644 --- a/src/cysfnodedirfile.cpp +++ b/src/cysfnodedirfile.cpp @@ -55,7 +55,7 @@ bool CYsfNodeDirFile::Init(void) bool CYsfNodeDirFile::NeedReload(void) { bool needReload = false; - + time_t time; if ( GetLastModTime(&time) ) { @@ -69,7 +69,7 @@ bool CYsfNodeDirFile::LoadContent(CBuffer *buffer) bool ok = false; std::ifstream file; std::streampos size; - + // open file file.open(YSFNODEDB_PATH, std::ios::in | std::ios::binary | std::ios::ate); if ( file.is_open() ) @@ -82,18 +82,18 @@ bool CYsfNodeDirFile::LoadContent(CBuffer *buffer) buffer->resize((int)size+1); file.seekg (0, std::ios::beg); file.read((char *)buffer->data(), (int)size); - + // close file file.close(); - + // update time GetLastModTime(&m_LastModTime); - + // done ok = true; } } - + // done return ok; } @@ -101,30 +101,30 @@ bool CYsfNodeDirFile::LoadContent(CBuffer *buffer) bool CYsfNodeDirFile::RefreshContent(const CBuffer &buffer) { bool ok = false; - + // clear directory clear(); - - // scan buffer + + // scan buffer if ( buffer.size() > 0 ) { // crack it char *ptr1 = (char *)buffer.data(); char *ptr2; - + // get next line - while ( (ptr2 = ::strchr(ptr1, '\n')) != NULL ) + while ( (ptr2 = ::strchr(ptr1, '\n')) != nullptr ) { *ptr2 = 0; // get items char *callsign; char *txfreq; char *rxfreq; - if ( ((callsign = ::strtok(ptr1, ";")) != NULL) ) + if ( ((callsign = ::strtok(ptr1, ";")) != nullptr) ) { - if ( ((txfreq = ::strtok(NULL, ";")) != NULL) ) + if ( ((txfreq = ::strtok(nullptr, ";")) != nullptr) ) { - if ( ((rxfreq = ::strtok(NULL, ";")) != NULL) ) + if ( ((rxfreq = ::strtok(nullptr, ";")) != nullptr) ) { // new entry CCallsign cs(callsign); @@ -139,15 +139,15 @@ bool CYsfNodeDirFile::RefreshContent(const CBuffer &buffer) // next line ptr1 = ptr2+1; } - + // done ok = true; } - + // report std::cout << "Read " << size() << " YSF nodes from file " << YSFNODEDB_PATH << std::endl; - + // done return ok; } @@ -156,7 +156,7 @@ bool CYsfNodeDirFile::RefreshContent(const CBuffer &buffer) bool CYsfNodeDirFile::GetLastModTime(time_t *time) { bool ok = false; - + struct stat fileStat; if( ::stat(YSFNODEDB_PATH, &fileStat) != -1 ) { diff --git a/src/cysfnodedirhttp.cpp b/src/cysfnodedirhttp.cpp index 739e66a..8018976 100644 --- a/src/cysfnodedirhttp.cpp +++ b/src/cysfnodedirhttp.cpp @@ -47,27 +47,27 @@ bool CYsfNodeDirHttp::RefreshContent(const CBuffer &buffer) // clear directory clear(); - + // scan buffer if ( buffer.size() > 0 ) { // crack it char *ptr1 = (char *)buffer.data(); char *ptr2; - + // get next line - while ( (ptr2 = ::strchr(ptr1, '\n')) != NULL ) + while ( (ptr2 = ::strchr(ptr1, '\n')) != nullptr ) { *ptr2 = 0; // get items char *callsign; char *txfreq; char *rxfreq; - if ( ((callsign = ::strtok(ptr1, ";")) != NULL) ) + if ( ((callsign = ::strtok(ptr1, ";")) != nullptr) ) { - if ( ((txfreq = ::strtok(NULL, ";")) != NULL) ) + if ( ((txfreq = ::strtok(nullptr, ";")) != nullptr) ) { - if ( ((rxfreq = ::strtok(NULL, ";")) != NULL) ) + if ( ((rxfreq = ::strtok(nullptr, ";")) != nullptr) ) { // new entry CCallsign cs(callsign); @@ -82,14 +82,14 @@ bool CYsfNodeDirHttp::RefreshContent(const CBuffer &buffer) // next line ptr1 = ptr2+1; } - + // done ok = true; } - + // report std::cout << "Read " << size() << " YSF nodes from xlxapi.rlx.lu database " << std::endl; - + // done return ok; } @@ -104,7 +104,7 @@ bool CYsfNodeDirHttp::HttpGet(const char *hostname, const char *filename, int po { bool ok = false; int sock_id; - + // open socket if ( (sock_id = ::socket(AF_INET, SOCK_STREAM, 0)) >= 0 ) { @@ -112,13 +112,13 @@ bool CYsfNodeDirHttp::HttpGet(const char *hostname, const char *filename, int po struct sockaddr_in servaddr; struct hostent *hp; ::memset(&servaddr,0,sizeof(servaddr)); - if( (hp = gethostbyname(hostname)) != NULL ) + if( (hp = gethostbyname(hostname)) != nullptr ) { // dns resolved ::memcpy((char *)&servaddr.sin_addr.s_addr, (char *)hp->h_addr, hp->h_length); servaddr.sin_port = htons(port); servaddr.sin_family = AF_INET; - + // connect if ( ::connect(sock_id, (struct sockaddr *)&servaddr, sizeof(servaddr)) == 0) { @@ -127,7 +127,7 @@ bool CYsfNodeDirHttp::HttpGet(const char *hostname, const char *filename, int po ::sprintf(request, "GET /%s HTTP/1.0\r\nFrom: %s\r\nUser-Agent: xlxd\r\n\r\n", filename, (const char *)g_Reflector.GetCallsign()); ::write(sock_id, request, strlen(request)); - + // config receive timeouts fd_set read_set; struct timeval timeout; @@ -135,7 +135,7 @@ bool CYsfNodeDirHttp::HttpGet(const char *hostname, const char *filename, int po timeout.tv_usec = 0; FD_ZERO(&read_set); FD_SET(sock_id, &read_set); - + // get the reply back buffer->clear(); bool done = false; @@ -143,7 +143,7 @@ bool CYsfNodeDirHttp::HttpGet(const char *hostname, const char *filename, int po { char buf[1440]; ssize_t len = 0; - select(sock_id+1, &read_set, NULL, NULL, &timeout); + select(sock_id+1, &read_set, nullptr, nullptr, &timeout); //if ( (ret > 0) || ((ret < 0) && (errno == EINPROGRESS)) ) //if ( ret >= 0 ) //{ @@ -156,10 +156,10 @@ bool CYsfNodeDirHttp::HttpGet(const char *hostname, const char *filename, int po } //} done = (len <= 0); - + } while (!done); buffer->Append((uint8)0); - + // and disconnect close(sock_id); } @@ -172,13 +172,13 @@ bool CYsfNodeDirHttp::HttpGet(const char *hostname, const char *filename, int po { std::cout << "Host " << hostname << " not found" << std::endl; } - + } else { std::cout << "Failed to open wget socket" << std::endl; } - + // done return ok; } diff --git a/src/cysfpayload.cpp b/src/cysfpayload.cpp index dd240ac..a3ffaae 100644 --- a/src/cysfpayload.cpp +++ b/src/cysfpayload.cpp @@ -78,10 +78,10 @@ const unsigned char BIT_MASK_TABLE[] = {0x80U, 0x40U, 0x20U, 0x10U, 0x08U, 0x04U #define READ_BIT1(p,i) (p[(i)>>3] & BIT_MASK_TABLE[(i)&7]) CYSFPayload::CYSFPayload() : -m_uplink(NULL), -m_downlink(NULL), -m_source(NULL), -m_dest(NULL) +m_uplink(nullptr), +m_downlink(nullptr), +m_source(nullptr), +m_dest(nullptr) { } @@ -95,76 +95,76 @@ CYSFPayload::~CYSFPayload() bool CYSFPayload::processHeaderData(unsigned char* data) { - assert(data != NULL); - + assert(data != nullptr); + data += YSF_SYNC_LENGTH_BYTES + YSF_FICH_LENGTH_BYTES; - + unsigned char dch[45U]; - + unsigned char* p1 = data; unsigned char* p2 = dch; for (unsigned int i = 0U; i < 5U; i++) { ::memcpy(p2, p1, 9U); p1 += 18U; p2 += 9U; } - + CYSFConvolution conv; conv.start(); - + for (unsigned int i = 0U; i < 180U; i++) { unsigned int n = INTERLEAVE_TABLE_9_20[i]; uint8_t s0 = READ_BIT1(dch, n) ? 1U : 0U; - + n++; uint8_t s1 = READ_BIT1(dch, n) ? 1U : 0U; - + conv.decode(s0, s1); } - + unsigned char output[23U]; conv.chainback(output, 176U); - + bool valid1 = CCRC::checkCCITT162(output, 22U); if (valid1) { for (unsigned int i = 0U; i < 20U; i++) output[i] ^= WHITENING_DATA[i]; - - if (m_dest == NULL) { + + if (m_dest == nullptr) { m_dest = new unsigned char[YSF_CALLSIGN_LENGTH]; ::memcpy(m_dest, output + 0U, YSF_CALLSIGN_LENGTH); } - - if (m_source == NULL) { + + if (m_source == nullptr) { m_source = new unsigned char[YSF_CALLSIGN_LENGTH]; ::memcpy(m_source, output + YSF_CALLSIGN_LENGTH, YSF_CALLSIGN_LENGTH); } - + for (unsigned int i = 0U; i < 20U; i++) output[i] ^= WHITENING_DATA[i]; - + CCRC::addCCITT162(output, 22U); output[22U] = 0x00U; - + unsigned char convolved[45U]; conv.encode(output, convolved, 180U); - + unsigned char bytes[45U]; unsigned int j = 0U; for (unsigned int i = 0U; i < 180U; i++) { unsigned int n = INTERLEAVE_TABLE_9_20[i]; - + bool s0 = READ_BIT1(convolved, j) != 0U; j++; - + bool s1 = READ_BIT1(convolved, j) != 0U; j++; - + WRITE_BIT1(bytes, n, s0); - + n++; WRITE_BIT1(bytes, n, s1); } - + p1 = data; p2 = bytes; for (unsigned int i = 0U; i < 5U; i++) { @@ -172,65 +172,65 @@ bool CYSFPayload::processHeaderData(unsigned char* data) p1 += 18U; p2 += 9U; } } - + p1 = data + 9U; p2 = dch; for (unsigned int i = 0U; i < 5U; i++) { ::memcpy(p2, p1, 9U); p1 += 18U; p2 += 9U; } - + conv.start(); - + for (unsigned int i = 0U; i < 180U; i++) { unsigned int n = INTERLEAVE_TABLE_9_20[i]; uint8_t s0 = READ_BIT1(dch, n) ? 1U : 0U; - + n++; uint8_t s1 = READ_BIT1(dch, n) ? 1U : 0U; - + conv.decode(s0, s1); } - + conv.chainback(output, 176U); - + bool valid2 = CCRC::checkCCITT162(output, 22U); if (valid2) { for (unsigned int i = 0U; i < 20U; i++) output[i] ^= WHITENING_DATA[i]; - - if (m_downlink != NULL) + + if (m_downlink != nullptr) ::memcpy(output + 0U, m_downlink, YSF_CALLSIGN_LENGTH); - - if (m_uplink != NULL) + + if (m_uplink != nullptr) ::memcpy(output + YSF_CALLSIGN_LENGTH, m_uplink, YSF_CALLSIGN_LENGTH); - + for (unsigned int i = 0U; i < 20U; i++) output[i] ^= WHITENING_DATA[i]; - + CCRC::addCCITT162(output, 22U); output[22U] = 0x00U; - + unsigned char convolved[45U]; conv.encode(output, convolved, 180U); - + unsigned char bytes[45U]; unsigned int j = 0U; for (unsigned int i = 0U; i < 180U; i++) { unsigned int n = INTERLEAVE_TABLE_9_20[i]; - + bool s0 = READ_BIT1(convolved, j) != 0U; j++; - + bool s1 = READ_BIT1(convolved, j) != 0U; j++; - + WRITE_BIT1(bytes, n, s0); - + n++; WRITE_BIT1(bytes, n, s1); } - + p1 = data + 9U; p2 = bytes; for (unsigned int i = 0U; i < 5U; i++) { @@ -238,139 +238,139 @@ bool CYSFPayload::processHeaderData(unsigned char* data) p1 += 18U; p2 += 9U; } } - + return valid1; } bool CYSFPayload::readDataFRModeData1(const unsigned char* data, unsigned char* dt) { - assert(data != NULL); - assert(dt != NULL); - + assert(data != nullptr); + assert(dt != nullptr); + ::memset(dt, ' ', 20U); - + data += YSF_SYNC_LENGTH_BYTES + YSF_FICH_LENGTH_BYTES; - + unsigned char dch[45U]; - + const unsigned char* p1 = data; unsigned char* p2 = dch; for (unsigned int i = 0U; i < 5U; i++) { ::memcpy(p2, p1, 9U); p1 += 18U; p2 += 9U; } - + CYSFConvolution conv; conv.start(); - + for (unsigned int i = 0U; i < 180U; i++) { unsigned int n = INTERLEAVE_TABLE_9_20[i]; uint8_t s0 = READ_BIT1(dch, n) ? 1U : 0U; - + n++; uint8_t s1 = READ_BIT1(dch, n) ? 1U : 0U; - + conv.decode(s0, s1); } - + unsigned char output[23U]; conv.chainback(output, 176U); - + bool ret = CCRC::checkCCITT162(output, 22U); if (ret) { for (unsigned int i = 0U; i < 20U; i++) output[i] ^= WHITENING_DATA[i]; - + // CUtils::dump(1U, "FR Mode Data 1", output, 20U); - + ::memcpy(dt, output, 20U); } - + return ret; } bool CYSFPayload::readDataFRModeData2(const unsigned char* data, unsigned char* dt) { - assert(data != NULL); - assert(dt != NULL); - + assert(data != nullptr); + assert(dt != nullptr); + ::memset(dt, ' ', 20U); - + data += YSF_SYNC_LENGTH_BYTES + YSF_FICH_LENGTH_BYTES; - + unsigned char dch[45U]; - + const unsigned char* p1 = data + 9U; unsigned char* p2 = dch; for (unsigned int i = 0U; i < 5U; i++) { ::memcpy(p2, p1, 9U); p1 += 18U; p2 += 9U; } - + CYSFConvolution conv; conv.start(); - + for (unsigned int i = 0U; i < 180U; i++) { unsigned int n = INTERLEAVE_TABLE_9_20[i]; uint8_t s0 = READ_BIT1(dch, n) ? 1U : 0U; - + n++; uint8_t s1 = READ_BIT1(dch, n) ? 1U : 0U; - + conv.decode(s0, s1); } - + unsigned char output[23U]; conv.chainback(output, 176U); - + bool ret = CCRC::checkCCITT162(output, 22U); if (ret) { for (unsigned int i = 0U; i < 20U; i++) output[i] ^= WHITENING_DATA[i]; - + // CUtils::dump(1U, "FR Mode Data 2", output, 20U); - + ::memcpy(dt, output, 20U); } - + return ret; } void CYSFPayload::writeVDMode2Data(unsigned char* data, const unsigned char* dt) { data += YSF_SYNC_LENGTH_BYTES + YSF_FICH_LENGTH_BYTES; - + unsigned char dt_tmp[13]; ::memcpy(dt_tmp, dt, YSF_CALLSIGN_LENGTH); - + for (unsigned int i = 0U; i < 10U; i++) dt_tmp[i] ^= WHITENING_DATA[i]; - + CCRC::addCCITT162(dt_tmp, 12U); dt_tmp[12U] = 0x00U; - + unsigned char convolved[25U]; CYSFConvolution conv; conv.start(); conv.encode(dt_tmp, convolved, 100U); - + unsigned char bytes[25U]; unsigned int j = 0U; for (unsigned int i = 0U; i < 100U; i++) { unsigned int n = INTERLEAVE_TABLE_5_20[i]; - + bool s0 = READ_BIT1(convolved, j) != 0U; j++; - + bool s1 = READ_BIT1(convolved, j) != 0U; j++; - + WRITE_BIT1(bytes, n, s0); - + n++; WRITE_BIT1(bytes, n, s1); } - + unsigned char* p1 = data; unsigned char* p2 = bytes; for (unsigned int i = 0U; i < 5U; i++) { @@ -382,142 +382,142 @@ void CYSFPayload::writeVDMode2Data(unsigned char* data, const unsigned char* dt) bool CYSFPayload::readVDMode1Data(const unsigned char* data, unsigned char* dt) { - assert(data != NULL); - assert(dt != NULL); - + assert(data != nullptr); + assert(dt != nullptr); + data += YSF_SYNC_LENGTH_BYTES + YSF_FICH_LENGTH_BYTES; - + unsigned char dch[45U]; - + const unsigned char* p1 = data; unsigned char* p2 = dch; for (unsigned int i = 0U; i < 5U; i++) { ::memcpy(p2, p1, 9U); p1 += 18U; p2 += 9U; } - + CYSFConvolution conv; conv.start(); - + for (unsigned int i = 0U; i < 180U; i++) { unsigned int n = INTERLEAVE_TABLE_9_20[i]; uint8_t s0 = READ_BIT1(dch, n) ? 1U : 0U; - + n++; uint8_t s1 = READ_BIT1(dch, n) ? 1U : 0U; - + conv.decode(s0, s1); } - + unsigned char output[23U]; conv.chainback(output, 176U); - + bool ret = CCRC::checkCCITT162(output, 22U); if (ret) { for (unsigned int i = 0U; i < 20U; i++) output[i] ^= WHITENING_DATA[i]; - + // CUtils::dump(1U, "V/D Mode 1 Data", output, 20U); - + ::memcpy(dt, output, 20U); } - + return ret; } bool CYSFPayload::readVDMode2Data(const unsigned char* data, unsigned char* dt) { - assert(data != NULL); - assert(dt != NULL); - + assert(data != nullptr); + assert(dt != nullptr); + data += YSF_SYNC_LENGTH_BYTES + YSF_FICH_LENGTH_BYTES; - + unsigned char dch[25U]; - + const unsigned char* p1 = data; unsigned char* p2 = dch; for (unsigned int i = 0U; i < 5U; i++) { ::memcpy(p2, p1, 5U); p1 += 18U; p2 += 5U; } - + CYSFConvolution conv; conv.start(); - + for (unsigned int i = 0U; i < 100U; i++) { unsigned int n = INTERLEAVE_TABLE_5_20[i]; uint8_t s0 = READ_BIT1(dch, n) ? 1U : 0U; - + n++; uint8_t s1 = READ_BIT1(dch, n) ? 1U : 0U; - + conv.decode(s0, s1); } - + unsigned char output[13U]; conv.chainback(output, 96U); - + bool ret = CCRC::checkCCITT162(output, 12U); if (ret) { for (unsigned int i = 0U; i < 10U; i++) output[i] ^= WHITENING_DATA[i]; - + // CUtils::dump(1U, "V/D Mode 2 Data", output, YSF_CALLSIGN_LENGTH); - + ::memcpy(dt, output, YSF_CALLSIGN_LENGTH); } - + return ret; } void CYSFPayload::writeHeader(unsigned char* data, const unsigned char* csd1, const unsigned char* csd2) { - assert(data != NULL); - assert(csd1 != NULL); - assert(csd2 != NULL); - + assert(data != nullptr); + assert(csd1 != nullptr); + assert(csd2 != nullptr); + writeDataFRModeData1(csd1, data); - + writeDataFRModeData2(csd2, data); } void CYSFPayload::writeDataFRModeData1(const unsigned char* dt, unsigned char* data) { - assert(dt != NULL); - assert(data != NULL); - + assert(dt != nullptr); + assert(data != nullptr); + data += YSF_SYNC_LENGTH_BYTES + YSF_FICH_LENGTH_BYTES; - + unsigned char output[25U]; for (unsigned int i = 0U; i < 20U; i++) output[i] = dt[i] ^ WHITENING_DATA[i]; - + CCRC::addCCITT162(output, 22U); output[22U] = 0x00U; - + unsigned char convolved[45U]; - + CYSFConvolution conv; conv.encode(output, convolved, 180U); - + unsigned char bytes[45U]; unsigned int j = 0U; for (unsigned int i = 0U; i < 180U; i++) { unsigned int n = INTERLEAVE_TABLE_9_20[i]; - + bool s0 = READ_BIT1(convolved, j) != 0U; j++; - + bool s1 = READ_BIT1(convolved, j) != 0U; j++; - + WRITE_BIT1(bytes, n, s0); - + n++; WRITE_BIT1(bytes, n, s1); } - + unsigned char* p1 = data; unsigned char* p2 = bytes; for (unsigned int i = 0U; i < 5U; i++) { @@ -528,40 +528,40 @@ void CYSFPayload::writeDataFRModeData1(const unsigned char* dt, unsigned char* d void CYSFPayload::writeDataFRModeData2(const unsigned char* dt, unsigned char* data) { - assert(dt != NULL); - assert(data != NULL); - + assert(dt != nullptr); + assert(data != nullptr); + data += YSF_SYNC_LENGTH_BYTES + YSF_FICH_LENGTH_BYTES; - + unsigned char output[25U]; for (unsigned int i = 0U; i < 20U; i++) output[i] = dt[i] ^ WHITENING_DATA[i]; - + CCRC::addCCITT162(output, 22U); output[22U] = 0x00U; - + unsigned char convolved[45U]; - + CYSFConvolution conv; conv.encode(output, convolved, 180U); - + unsigned char bytes[45U]; unsigned int j = 0U; for (unsigned int i = 0U; i < 180U; i++) { unsigned int n = INTERLEAVE_TABLE_9_20[i]; - + bool s0 = READ_BIT1(convolved, j) != 0U; j++; - + bool s1 = READ_BIT1(convolved, j) != 0U; j++; - + WRITE_BIT1(bytes, n, s0); - + n++; WRITE_BIT1(bytes, n, s1); } - + unsigned char* p1 = data + 9U; unsigned char* p2 = bytes; for (unsigned int i = 0U; i < 5U; i++) { @@ -573,10 +573,10 @@ void CYSFPayload::writeDataFRModeData2(const unsigned char* dt, unsigned char* d void CYSFPayload::setUplink(const std::string& callsign) { m_uplink = new unsigned char[YSF_CALLSIGN_LENGTH]; - + std::string uplink = callsign; uplink.resize(YSF_CALLSIGN_LENGTH, ' '); - + for (unsigned int i = 0U; i < YSF_CALLSIGN_LENGTH; i++) m_uplink[i] = uplink.at(i); } @@ -584,10 +584,10 @@ void CYSFPayload::setUplink(const std::string& callsign) void CYSFPayload::setDownlink(const std::string& callsign) { m_downlink = new unsigned char[YSF_CALLSIGN_LENGTH]; - + std::string downlink = callsign; downlink.resize(YSF_CALLSIGN_LENGTH, ' '); - + for (unsigned int i = 0U; i < YSF_CALLSIGN_LENGTH; i++) m_downlink[i] = downlink.at(i); } @@ -595,24 +595,24 @@ void CYSFPayload::setDownlink(const std::string& callsign) std::string CYSFPayload::getSource() { std::string tmp; - + if (m_dest) tmp.assign((const char *)m_source, YSF_CALLSIGN_LENGTH); else tmp = ""; - + return tmp; } std::string CYSFPayload::getDest() { std::string tmp; - + if (m_dest) tmp.assign((const char *)m_dest, YSF_CALLSIGN_LENGTH); else tmp = ""; - + return tmp; } @@ -620,7 +620,7 @@ void CYSFPayload::reset() { delete[] m_source; delete[] m_dest; - - m_source = NULL; - m_dest = NULL; + + m_source = nullptr; + m_dest = nullptr; } diff --git a/src/cysfprotocol.cpp b/src/cysfprotocol.cpp index b513dc6..acd9fbe 100644 --- a/src/cysfprotocol.cpp +++ b/src/cysfprotocol.cpp @@ -166,14 +166,14 @@ void CYsfProtocol::Task(void) // add client if needed CClients *clients = g_Reflector.GetClients(); - CClient *client = clients->FindClient(Callsign, Ip, PROTOCOL_YSF); + std::shared_ptrclient = clients->FindClient(Callsign, Ip, PROTOCOL_YSF); // client already connected ? - if ( client == NULL ) + if ( client == nullptr ) { std::cout << "YSF connect packet from " << Callsign << " at " << Ip << std::endl; // create the client - CYsfClient *newclient = new CYsfClient(Callsign, Ip); + auto newclient = std::make_shared(Callsign, Ip); // aautolink, if enabled #if YSF_AUTOLINK_ENABLE @@ -241,14 +241,14 @@ bool CYsfProtocol::OnDvHeaderPacketIn(CDvHeaderPacket *Header, const CIp &Ip) // find the stream CPacketStream *stream = GetStream(Header->GetStreamId()); - if ( stream == NULL ) + if ( stream == nullptr ) { // no stream open yet, open a new one CCallsign via(Header->GetRpt1Callsign()); // find this client - CClient *client = g_Reflector.GetClients()->FindClient(Ip, PROTOCOL_YSF); - if ( client != NULL ) + std::shared_ptrclient = g_Reflector.GetClients()->FindClient(Ip, PROTOCOL_YSF); + if ( client != nullptr ) { // get client callsign via = client->GetCallsign(); @@ -256,7 +256,7 @@ bool CYsfProtocol::OnDvHeaderPacketIn(CDvHeaderPacket *Header, const CIp &Ip) Header->SetRpt2Module(client->GetReflectorModule()); // and try to open the stream - if ( (stream = g_Reflector.OpenStream(Header, client)) != NULL ) + if ( (stream = g_Reflector.OpenStream(Header, client)) != nullptr ) { // keep the handle m_Streams.push_back(stream); @@ -350,8 +350,8 @@ void CYsfProtocol::HandleQueue(void) // and push it to all our clients linked to the module and who are not streaming in CClients *clients = g_Reflector.GetClients(); auto it = clients->begin(); - CClient *client = NULL; - while ( (client = clients->FindNextClient(PROTOCOL_YSF, it)) != NULL ) + std::shared_ptrclient = nullptr; + while ( (client = clients->FindNextClient(PROTOCOL_YSF, it)) != nullptr ) { // is this client busy ? if ( !client->IsAMaster() && (client->GetReflectorModule() == packet->GetModuleId()) ) @@ -382,8 +382,8 @@ void CYsfProtocol::HandleKeepalives(void) // iterate on clients CClients *clients = g_Reflector.GetClients(); auto it = clients->begin(); - CClient *client = NULL; - while ( (client = clients->FindNextClient(PROTOCOL_YSF, it)) != NULL ) + std::shared_ptrclient = nullptr; + while ( (client = clients->FindNextClient(PROTOCOL_YSF, it)) != nullptr ) { // is this client busy ? if ( client->IsAMaster() ) @@ -441,9 +441,9 @@ bool CYsfProtocol::IsValidDvPacket(const CBuffer &Buffer, CYSFFICH *Fich) bool CYsfProtocol::IsValidDvHeaderPacket(const CIp &Ip, const CYSFFICH &Fich, const CBuffer &Buffer, CDvHeaderPacket **header, CDvFramePacket **frames) { bool valid = false; - *header = NULL; - frames[0] = NULL; - frames[1] = NULL; + *header = nullptr; + frames[0] = nullptr; + frames[1] = nullptr; // DV header ? if ( Fich.getFI() == YSF_FI_HEADER ) @@ -482,17 +482,17 @@ bool CYsfProtocol::IsValidDvHeaderPacket(const CIp &Ip, const CYSFFICH &Fich, co } // check validity of packets - if ( ((*header) == NULL) || !(*header)->IsValid() || - (frames[0] == NULL) || !(frames[0]->IsValid()) || - (frames[1] == NULL) || !(frames[1]->IsValid()) ) + if ( ((*header) == nullptr) || !(*header)->IsValid() || + (frames[0] == nullptr) || !(frames[0]->IsValid()) || + (frames[1] == nullptr) || !(frames[1]->IsValid()) ) { delete *header; - *header = NULL; + *header = nullptr; delete frames[0]; delete frames[1]; - frames[0] = NULL; - frames[1] = NULL; + frames[0] = nullptr; + frames[1] = nullptr; } else { @@ -508,11 +508,11 @@ bool CYsfProtocol::IsValidDvHeaderPacket(const CIp &Ip, const CYSFFICH &Fich, co bool CYsfProtocol::IsValidDvFramePacket(const CIp &Ip, const CYSFFICH &Fich, const CBuffer &Buffer, CDvFramePacket **frames) { bool valid = false; - frames[0] = NULL; - frames[1] = NULL; - frames[2] = NULL; - frames[3] = NULL; - frames[4] = NULL; + frames[0] = nullptr; + frames[1] = nullptr; + frames[2] = nullptr; + frames[3] = nullptr; + frames[4] = nullptr; // is it DV frame ? if ( Fich.getFI() == YSF_FI_COMMUNICATIONS ) @@ -538,22 +538,22 @@ bool CYsfProtocol::IsValidDvFramePacket(const CIp &Ip, const CYSFFICH &Fich, con frames[4] = new CDvFramePacket(ambe4, uiStreamId, Fich.getFN(), 4, fid); // check validity of packets - if ( (frames[0] == NULL) || !(frames[0]->IsValid()) || - (frames[1] == NULL) || !(frames[1]->IsValid()) || - (frames[2] == NULL) || !(frames[2]->IsValid()) || - (frames[3] == NULL) || !(frames[3]->IsValid()) || - (frames[4] == NULL) || !(frames[4]->IsValid()) ) + if ( (frames[0] == nullptr) || !(frames[0]->IsValid()) || + (frames[1] == nullptr) || !(frames[1]->IsValid()) || + (frames[2] == nullptr) || !(frames[2]->IsValid()) || + (frames[3] == nullptr) || !(frames[3]->IsValid()) || + (frames[4] == nullptr) || !(frames[4]->IsValid()) ) { delete frames[0]; delete frames[1]; delete frames[2]; delete frames[3]; delete frames[4]; - frames[0] = NULL; - frames[1] = NULL; - frames[2] = NULL; - frames[3] = NULL; - frames[4] = NULL; + frames[0] = nullptr; + frames[1] = nullptr; + frames[2] = nullptr; + frames[3] = nullptr; + frames[4] = nullptr; } else { @@ -568,8 +568,8 @@ bool CYsfProtocol::IsValidDvFramePacket(const CIp &Ip, const CYSFFICH &Fich, con bool CYsfProtocol::IsValidDvLastFramePacket(const CIp &Ip, const CYSFFICH &Fich, const CBuffer &Buffer, CDvFramePacket **frames) { bool valid = false; - frames[0] = NULL; - frames[1] = NULL; + frames[0] = nullptr; + frames[1] = nullptr; // DV header ? if ( Fich.getFI() == YSF_FI_TERMINATOR ) @@ -586,14 +586,14 @@ bool CYsfProtocol::IsValidDvLastFramePacket(const CIp &Ip, const CYSFFICH &Fich, } // check validity of packets - if ( (frames[0] == NULL) || !(frames[0]->IsValid()) || - (frames[1] == NULL) || !(frames[1]->IsValid()) ) + if ( (frames[0] == nullptr) || !(frames[0]->IsValid()) || + (frames[1] == nullptr) || !(frames[1]->IsValid()) ) { delete frames[0]; delete frames[1]; - frames[0] = NULL; - frames[1] = NULL; + frames[0] = nullptr; + frames[1] = nullptr; } else { diff --git a/src/cysfprotocol.h b/src/cysfprotocol.h index 77725e9..b71f306 100644 --- a/src/cysfprotocol.h +++ b/src/cysfprotocol.h @@ -60,7 +60,7 @@ class CYsfStreamCacheItem public: CYsfStreamCacheItem() {} ~CYsfStreamCacheItem() {} - + CDvHeaderPacket m_dvHeader; CDvFramePacket m_dvFrames[5]; @@ -72,27 +72,27 @@ class CYsfProtocol : public CProtocol public: // constructor CYsfProtocol(); - + // destructor virtual ~CYsfProtocol() {}; - + // initialization bool Init(void); void Close(void); - + // task void Task(void); - + protected: // queue helper void HandleQueue(void); - + // keepalive helpers void HandleKeepalives(void); - + // stream helpers bool OnDvHeaderPacketIn(CDvHeaderPacket *, const CIp &); - + // DV packet decoding helpers bool IsValidConnectPacket(const CBuffer &, CCallsign *); //bool IsValidDisconnectPacket(const CBuffer &, CCallsign *); @@ -100,41 +100,41 @@ protected: bool IsValidDvHeaderPacket(const CIp &, const CYSFFICH &, const CBuffer &, CDvHeaderPacket **, CDvFramePacket **); bool IsValidDvFramePacket(const CIp &, const CYSFFICH &, const CBuffer &, CDvFramePacket **); bool IsValidDvLastFramePacket(const CIp &, const CYSFFICH &, const CBuffer &, CDvFramePacket **); - + // DV packet encoding helpers void EncodeConnectAckPacket(CBuffer *) const; //void EncodeConnectNackPacket(const CCallsign &, char, CBuffer *); - //void EncodeDisconnectPacket(CBuffer *, CClient *); + //void EncodeDisconnectPacket(CBuffer *, std::shared_ptr); bool EncodeDvHeaderPacket(const CDvHeaderPacket &, CBuffer *) const; bool EncodeDvPacket(const CDvHeaderPacket &, const CDvFramePacket *, CBuffer *) const; bool EncodeDvLastPacket(const CDvHeaderPacket &, CBuffer *) const; // Wires-X packet decoding helpers bool IsValidwirexPacket(const CBuffer &, CYSFFICH *, CCallsign *, int *, int*); - + // server status packet decoding helpers bool IsValidServerStatusPacket(const CBuffer &) const; uint32 CalcHash(const uint8 *, int) const; - + // server status packet encoding helpers bool EncodeServerStatusPacket(CBuffer *) const; - + // uiStreamId helpers uint32 IpToStreamId(const CIp &) const; - + // debug bool DebugTestDecodePacket(const CBuffer &); bool DebugDumpHeaderPacket(const CBuffer &); bool DebugDumpDvPacket(const CBuffer &); bool DebugDumpLastDvPacket(const CBuffer &); - + protected: // for keep alive CTimePoint m_LastKeepaliveTime; - + // for queue header caches std::array m_StreamsCache; - + // for wires-x CWiresxCmdHandler m_WiresxCmdHandler; unsigned char m_seqNo; diff --git a/src/main.h b/src/main.h index 55de495..26b25d0 100644 --- a/src/main.h +++ b/src/main.h @@ -34,6 +34,7 @@ #include #include #include +#include #include #include #include