m_Clients and m_Peers are std::shared_ptr

pull/1/head
Tom Early 5 years ago
parent 4b15c147aa
commit 23d39e4594

@ -45,10 +45,8 @@ CBmPeer::CBmPeer(const CCallsign &callsign, const CIp &ip, const char *modules,
// and construct all xlx clients // and construct all xlx clients
for ( unsigned i = 0; i < ::strlen(modules); i++ ) for ( unsigned i = 0; i < ::strlen(modules); i++ )
{ {
// create // create and append to vector
CBmClient *client = new CBmClient(callsign, ip, modules[i]); m_Clients.push_back(std::make_shared<CBmClient>(callsign, ip, modules[i]));
// and append to vector
m_Clients.push_back(client);
} }
} }
@ -57,7 +55,7 @@ CBmPeer::CBmPeer(const CBmPeer &peer)
{ {
for ( auto it=peer.cbegin(); it!=peer.cend(); it++ ) for ( auto it=peer.cbegin(); it!=peer.cend(); it++ )
{ {
CBmClient *client = new CBmClient((const CBmClient &)*(*it)); std::shared_ptr<CBmClient> client(new CBmClient((const CBmClient &)*(*it)));
m_Clients.push_back(client); m_Clients.push_back(client);
} }

@ -37,8 +37,8 @@ CBPTC19696::~CBPTC19696()
// The main decode function // The main decode function
void CBPTC19696::decode(const unsigned char* in, unsigned char* out) void CBPTC19696::decode(const unsigned char* in, unsigned char* out)
{ {
assert(in != NULL); assert(in != nullptr);
assert(out != NULL); assert(out != nullptr);
// Get the raw binary // Get the raw binary
decodeExtractBinary(in); decodeExtractBinary(in);
@ -56,8 +56,8 @@ void CBPTC19696::decode(const unsigned char* in, unsigned char* out)
// The main encode function // The main encode function
void CBPTC19696::encode(const unsigned char* in, unsigned char* out) void CBPTC19696::encode(const unsigned char* in, unsigned char* out)
{ {
assert(in != NULL); assert(in != nullptr);
assert(out != NULL); assert(out != nullptr);
// Extract Data // Extract Data
encodeExtractData(in); encodeExtractData(in);

@ -78,7 +78,7 @@ CCallsign::CCallsign(const char *sz, uint32 dmrid)
g_DmridDir.Lock(); g_DmridDir.Lock();
{ {
const CCallsign *callsign = g_DmridDir.FindCallsign(m_uiDmrid); const CCallsign *callsign = g_DmridDir.FindCallsign(m_uiDmrid);
if ( callsign != NULL ) if ( callsign != nullptr )
{ {
::memcpy(m_Callsign, callsign->m_Callsign, sizeof(m_Callsign)); ::memcpy(m_Callsign, callsign->m_Callsign, sizeof(m_Callsign));
} }
@ -125,7 +125,7 @@ bool CCallsign::IsValid(void) const
// is an letter or space // is an letter or space
valid &= IsLetter(m_Module) || IsSpace(m_Module); 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 // if station does is not dmr registered
// done // done
@ -206,7 +206,7 @@ void CCallsign::SetDmrid(uint32 dmrid, bool UpdateCallsign)
g_DmridDir.Lock(); g_DmridDir.Lock();
{ {
const CCallsign *callsign = g_DmridDir.FindCallsign(dmrid); const CCallsign *callsign = g_DmridDir.FindCallsign(dmrid);
if ( callsign != NULL ) if ( callsign != nullptr )
{ {
::memcpy(m_Callsign, callsign->m_Callsign, sizeof(m_Callsign)); ::memcpy(m_Callsign, callsign->m_Callsign, sizeof(m_Callsign));
} }
@ -220,7 +220,7 @@ void CCallsign::SetDmrid(const uint8 *buffer, bool UpdateCallsign)
char sz[9]; char sz[9];
::memcpy(sz, buffer, 8); ::memcpy(sz, buffer, 8);
sz[8] = 0; sz[8] = 0;
SetDmrid((uint32)::strtol(sz, NULL, 16), UpdateCallsign); SetDmrid((uint32)::strtol(sz, nullptr, 16), UpdateCallsign);
} }
#endif #endif

@ -34,7 +34,7 @@
CCallsignList::CCallsignList() CCallsignList::CCallsignList()
{ {
m_Filename = NULL; m_Filename = nullptr;
::memset(&m_LastModTime, 0, sizeof(time_t)); ::memset(&m_LastModTime, 0, sizeof(time_t));
} }
@ -65,13 +65,13 @@ bool CCallsignList::LoadFromFile(const char *filename)
if ( (::strlen(szt) > 0) && (szt[0] != '#') ) if ( (::strlen(szt) > 0) && (szt[0] != '#') )
{ {
// 1st token is callsign // 1st token is callsign
if ( (szt = ::strtok(szt, " ,\t")) != NULL ) if ( (szt = ::strtok(szt, " ,\t")) != nullptr )
{ {
CCallsign callsign(szt); CCallsign callsign(szt);
// 2nd token is modules list // 2nd token is modules list
szt = ::strtok(NULL, " ,\t"); szt = ::strtok(nullptr, " ,\t");
// if token absent, use wildcard // if token absent, use wildcard
if ( szt == NULL ) if ( szt == nullptr )
{ {
szt = szStar; szt = szStar;
} }
@ -106,7 +106,7 @@ bool CCallsignList::ReloadFromFile(void)
{ {
bool ok = false; bool ok = false;
if ( m_Filename != NULL ) if ( m_Filename != nullptr )
{ {
ok = LoadFromFile(m_Filename); 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; bool ok = false;
if ( m_Filename != NULL ) if ( m_Filename != nullptr )
{ {
struct stat fileStat; struct stat fileStat;
if( ::stat(m_Filename, &fileStat) != -1 ) if( ::stat(m_Filename, &fileStat) != -1 )

@ -40,7 +40,7 @@ CCallsignListItem::CCallsignListItem(const CCallsign &callsign, const CIp &ip, c
m_Callsign = callsign; m_Callsign = callsign;
::memset(m_szUrl, 0, sizeof(m_szUrl)); ::memset(m_szUrl, 0, sizeof(m_szUrl));
m_Ip = ip; m_Ip = ip;
if ( modules != NULL ) if ( modules != nullptr )
{ {
::memset(m_Modules, 0, sizeof(m_Modules)); ::memset(m_Modules, 0, sizeof(m_Modules));
if ( modules[0] == '*' ) if ( modules[0] == '*' )
@ -70,7 +70,7 @@ CCallsignListItem::CCallsignListItem(const CCallsign &callsign, const char *url,
m_Callsign = callsign; m_Callsign = callsign;
::strncpy(m_szUrl, url, URL_MAXLEN); ::strncpy(m_szUrl, url, URL_MAXLEN);
m_Ip = CIp(m_szUrl); m_Ip = CIp(m_szUrl);
if ( modules != NULL ) if ( modules != nullptr )
{ {
::memset(m_Modules, 0, sizeof(m_Modules)); ::memset(m_Modules, 0, sizeof(m_Modules));
if ( modules[0] == '*' ) if ( modules[0] == '*' )
@ -119,14 +119,14 @@ bool CCallsignListItem::HasSameCallsignWithWildcard(const CCallsign &callsign) c
bool CCallsignListItem::HasModuleListed(char module) const 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 CCallsignListItem::CheckListedModules(char *Modules) const
{ {
bool listed = false; bool listed = false;
if ( Modules != NULL ) if ( Modules != nullptr )
{ {
// build a list of common modules // build a list of common modules
char list[27]; char list[27];

@ -35,8 +35,8 @@ CClient::CClient()
m_ReflectorModule = ' '; m_ReflectorModule = ' ';
m_ModuleMastered = ' '; m_ModuleMastered = ' ';
m_LastKeepaliveTime.Now(); m_LastKeepaliveTime.Now();
m_ConnectTime = std::time(NULL); m_ConnectTime = std::time(nullptr);
m_LastHeardTime = std::time(NULL); m_LastHeardTime = std::time(nullptr);
} }
CClient::CClient(const CCallsign &callsign, const CIp &ip, char reflectorModule) 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_Ip = ip;
m_ModuleMastered = ' '; m_ModuleMastered = ' ';
m_LastKeepaliveTime.Now(); m_LastKeepaliveTime.Now();
m_ConnectTime = std::time(NULL); m_ConnectTime = std::time(nullptr);
m_LastHeardTime = std::time(NULL); m_LastHeardTime = std::time(nullptr);
} }
CClient::CClient(const CClient &client) CClient::CClient(const CClient &client)

@ -78,7 +78,7 @@ public:
virtual bool IsAMaster(void) const { return (m_ModuleMastered != ' '); } virtual bool IsAMaster(void) const { return (m_ModuleMastered != ' '); }
virtual void SetMasterOfModule(char c) { m_ModuleMastered = c; } virtual void SetMasterOfModule(char c) { m_ModuleMastered = c; }
virtual void NotAMaster(void) { m_ModuleMastered = ' '; } 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 // reporting
virtual void WriteXml(std::ofstream &); virtual void WriteXml(std::ofstream &);

@ -42,10 +42,6 @@ CClients::CClients()
CClients::~CClients() CClients::~CClients()
{ {
m_Mutex.lock(); m_Mutex.lock();
for ( auto it=begin(); it!=end(); it++ )
{
delete *it;
}
m_Clients.clear(); m_Clients.clear();
m_Mutex.unlock(); m_Mutex.unlock();
} }
@ -53,7 +49,7 @@ CClients::~CClients()
//////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////
// manage Clients // manage Clients
void CClients::AddClient(CClient *client) void CClients::AddClient(std::shared_ptr<CClient>client)
{ {
// first check if client already exists // first check if client already exists
for ( auto it=begin(); it!=end(); it++ ) for ( auto it=begin(); it!=end(); it++ )
@ -64,7 +60,6 @@ void CClients::AddClient(CClient *client)
// on function return // on function return
{ {
// delete new one // delete new one
delete client;
return; return;
} }
} }
@ -82,7 +77,7 @@ void CClients::AddClient(CClient *client)
g_Reflector.OnClientsChanged(); g_Reflector.OnClientsChanged();
} }
void CClients::RemoveClient(CClient *client) void CClients::RemoveClient(std::shared_ptr<CClient>client)
{ {
// look for the client // look for the client
bool found = false; bool found = false;
@ -101,7 +96,6 @@ void CClients::RemoveClient(CClient *client)
std::cout << " on module " << (*it)->GetReflectorModule(); std::cout << " on module " << (*it)->GetReflectorModule();
} }
std::cout << std::endl; std::cout << std::endl;
delete *it;
m_Clients.erase(it); m_Clients.erase(it);
// notify // notify
g_Reflector.OnClientsChanged(); g_Reflector.OnClientsChanged();
@ -111,7 +105,7 @@ void CClients::RemoveClient(CClient *client)
} }
} }
bool CClients::IsClient(CClient *client) const bool CClients::IsClient(std::shared_ptr<CClient>client) const
{ {
for ( auto it=cbegin(); it!=cend(); it++ ) for ( auto it=cbegin(); it!=cend(); it++ )
{ {
@ -124,7 +118,7 @@ bool CClients::IsClient(CClient *client) const
//////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////
// find Clients // find Clients
CClient *CClients::FindClient(const CIp &Ip) std::shared_ptr<CClient>CClients::FindClient(const CIp &Ip)
{ {
// find client // find client
for ( auto it=begin(); it!=end(); it++ ) for ( auto it=begin(); it!=end(); it++ )
@ -136,10 +130,10 @@ CClient *CClients::FindClient(const CIp &Ip)
} }
// done // done
return NULL; return nullptr;
} }
CClient *CClients::FindClient(const CIp &Ip, int Protocol) std::shared_ptr<CClient>CClients::FindClient(const CIp &Ip, int Protocol)
{ {
// find client // find client
for ( auto it=begin(); it!=end(); it++ ) for ( auto it=begin(); it!=end(); it++ )
@ -151,10 +145,10 @@ CClient *CClients::FindClient(const CIp &Ip, int Protocol)
} }
// done // done
return NULL; return nullptr;
} }
CClient *CClients::FindClient(const CIp &Ip, int Protocol, char ReflectorModule) std::shared_ptr<CClient>CClients::FindClient(const CIp &Ip, int Protocol, char ReflectorModule)
{ {
// find client // find client
for ( auto it=begin(); it!=end(); it++ ) for ( auto it=begin(); it!=end(); it++ )
@ -168,10 +162,10 @@ CClient *CClients::FindClient(const CIp &Ip, int Protocol, char ReflectorModule)
} }
// done // done
return NULL; return nullptr;
} }
CClient *CClients::FindClient(const CCallsign &Callsign, const CIp &Ip, int Protocol) std::shared_ptr<CClient>CClients::FindClient(const CCallsign &Callsign, const CIp &Ip, int Protocol)
{ {
// find client // find client
for ( auto it=begin(); it!=end(); it++ ) 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_ptr<CClient>CClients::FindClient(const CCallsign &Callsign, char module, const CIp &Ip, int Protocol)
{ {
// find client // find client
for ( auto it=begin(); it!=end(); it++ ) 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_ptr<CClient>CClients::FindClient(const CCallsign &Callsign, int Protocol)
{ {
// find client // find client
for ( auto it=begin(); it!=end(); it++ ) 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 // iterate on clients
CClient *CClients::FindNextClient(int Protocol, std::list<CClient *>::iterator &it) std::shared_ptr<CClient>CClients::FindNextClient(int Protocol, std::list<std::shared_ptr<CClient>>::iterator &it)
{ {
while ( it != end() ) while ( it != end() )
{ {
@ -232,10 +226,10 @@ CClient *CClients::FindNextClient(int Protocol, std::list<CClient *>::iterator &
} }
it++; it++;
} }
return NULL; return nullptr;
} }
CClient *CClients::FindNextClient(const CIp &Ip, int Protocol, std::list<CClient *>::iterator &it) std::shared_ptr<CClient>CClients::FindNextClient(const CIp &Ip, int Protocol, std::list<std::shared_ptr<CClient>>::iterator &it)
{ {
while ( it != end() ) while ( it != end() )
{ {
@ -246,10 +240,10 @@ CClient *CClients::FindNextClient(const CIp &Ip, int Protocol, std::list<CClient
} }
it++; it++;
} }
return NULL; return nullptr;
} }
CClient *CClients::FindNextClient(const CCallsign &Callsign, const CIp &Ip, int Protocol, std::list<CClient *>::iterator &it) std::shared_ptr<CClient>CClients::FindNextClient(const CCallsign &Callsign, const CIp &Ip, int Protocol, std::list<std::shared_ptr<CClient>>::iterator &it)
{ {
while ( it != end() ) while ( it != end() )
{ {
@ -261,5 +255,5 @@ CClient *CClients::FindNextClient(const CCallsign &Callsign, const CIp &Ip, int
} }
it++; it++;
} }
return NULL; return nullptr;
} }

@ -51,33 +51,33 @@ public:
// manage Clients // manage Clients
int GetSize(void) const { return (int)m_Clients.size(); } int GetSize(void) const { return (int)m_Clients.size(); }
void AddClient(CClient *); void AddClient(std::shared_ptr<CClient>);
void RemoveClient(CClient *); void RemoveClient(std::shared_ptr<CClient>);
bool IsClient(CClient *) const; bool IsClient(std::shared_ptr<CClient>) const;
// pass-thru // pass-thru
std::list<CClient *>::iterator begin() { return m_Clients.begin(); } std::list<std::shared_ptr<CClient>>::iterator begin() { return m_Clients.begin(); }
std::list<CClient *>::iterator end() { return m_Clients.end(); } std::list<std::shared_ptr<CClient>>::iterator end() { return m_Clients.end(); }
std::list<CClient *>::const_iterator cbegin() const { return m_Clients.cbegin(); } std::list<std::shared_ptr<CClient>>::const_iterator cbegin() const { return m_Clients.cbegin(); }
std::list<CClient *>::const_iterator cend() const { return m_Clients.cend(); } std::list<std::shared_ptr<CClient>>::const_iterator cend() const { return m_Clients.cend(); }
// find clients // find clients
CClient *FindClient(const CIp &); std::shared_ptr<CClient>FindClient(const CIp &);
CClient *FindClient(const CIp &, int); std::shared_ptr<CClient>FindClient(const CIp &, int);
CClient *FindClient(const CIp &, int, char); std::shared_ptr<CClient>FindClient(const CIp &, int, char);
CClient *FindClient(const CCallsign &, const CIp &, int); std::shared_ptr<CClient>FindClient(const CCallsign &, const CIp &, int);
CClient *FindClient(const CCallsign &, char, const CIp &, int); std::shared_ptr<CClient>FindClient(const CCallsign &, char, const CIp &, int);
CClient *FindClient(const CCallsign &, int); std::shared_ptr<CClient>FindClient(const CCallsign &, int);
// iterate on clients // iterate on clients
CClient *FindNextClient(int, std::list<CClient *>::iterator &); std::shared_ptr<CClient>FindNextClient(int, std::list<std::shared_ptr<CClient>>::iterator &);
CClient *FindNextClient(const CIp &, int, std::list<CClient *>::iterator &); std::shared_ptr<CClient>FindNextClient(const CIp &, int, std::list<std::shared_ptr<CClient>>::iterator &);
CClient *FindNextClient(const CCallsign &, const CIp &, int, std::list<CClient *>::iterator &); std::shared_ptr<CClient>FindNextClient(const CCallsign &, const CIp &, int, std::list<std::shared_ptr<CClient>>::iterator &);
protected: protected:
// data // data
std::mutex m_Mutex; std::mutex m_Mutex;
std::list<CClient *> m_Clients; std::list<std::shared_ptr<CClient>> m_Clients;
}; };

@ -39,7 +39,7 @@
CCodecStream::CCodecStream(CPacketStream *PacketStream, uint16 uiId, uint8 uiCodecIn, uint8 uiCodecOut) CCodecStream::CCodecStream(CPacketStream *PacketStream, uint16 uiId, uint8 uiCodecIn, uint8 uiCodecOut)
{ {
keep_running = true; keep_running = true;
m_pThread = NULL; m_pThread = nullptr;
m_uiStreamId = uiId; m_uiStreamId = uiId;
m_uiPid = 0; m_uiPid = 0;
m_uiCodecIn = uiCodecIn; m_uiCodecIn = uiCodecIn;
@ -64,11 +64,11 @@ CCodecStream::~CCodecStream()
// kill threads // kill threads
keep_running = false; keep_running = false;
if ( m_pThread != NULL ) if ( m_pThread != nullptr )
{ {
m_pThread->join(); m_pThread->join();
delete m_pThread; delete m_pThread;
m_pThread = NULL; m_pThread = nullptr;
} }
// empty local queue // empty local queue
@ -141,11 +141,11 @@ void CCodecStream::Close(void)
m_Socket.Close(); m_Socket.Close();
// kill threads // kill threads
if ( m_pThread != NULL ) if ( m_pThread != nullptr )
{ {
m_pThread->join(); m_pThread->join();
delete m_pThread; delete m_pThread;
m_pThread = NULL; m_pThread = nullptr;
} }
} }

@ -120,7 +120,7 @@ const uint16_t CCITT16_TABLE2[] = {
bool CCRC::checkFiveBit(bool* in, unsigned int tcrc) bool CCRC::checkFiveBit(bool* in, unsigned int tcrc)
{ {
assert(in != NULL); assert(in != nullptr);
unsigned int crc; unsigned int crc;
encodeFiveBit(in, crc); encodeFiveBit(in, crc);
@ -130,7 +130,7 @@ bool CCRC::checkFiveBit(bool* in, unsigned int tcrc)
void CCRC::encodeFiveBit(const bool* in, unsigned int& tcrc) void CCRC::encodeFiveBit(const bool* in, unsigned int& tcrc)
{ {
assert(in != NULL); assert(in != nullptr);
unsigned short total = 0U; unsigned short total = 0U;
for (unsigned int i = 0U; i < 72U; i += 8U) { for (unsigned int i = 0U; i < 72U; i += 8U) {
@ -146,7 +146,7 @@ void CCRC::encodeFiveBit(const bool* in, unsigned int& tcrc)
void CCRC::addCCITT162(unsigned char *in, unsigned int length) void CCRC::addCCITT162(unsigned char *in, unsigned int length)
{ {
assert(in != NULL); assert(in != nullptr);
assert(length > 2U); assert(length > 2U);
union { union {
@ -167,7 +167,7 @@ void CCRC::addCCITT162(unsigned char *in, unsigned int length)
bool CCRC::checkCCITT162(const unsigned char *in, unsigned int length) bool CCRC::checkCCITT162(const unsigned char *in, unsigned int length)
{ {
assert(in != NULL); assert(in != nullptr);
assert(length > 2U); assert(length > 2U);
union { union {
@ -187,7 +187,7 @@ bool CCRC::checkCCITT162(const unsigned char *in, unsigned int length)
void CCRC::addCCITT161(unsigned char *in, unsigned int length) void CCRC::addCCITT161(unsigned char *in, unsigned int length)
{ {
assert(in != NULL); assert(in != nullptr);
assert(length > 2U); assert(length > 2U);
union { union {
@ -208,7 +208,7 @@ void CCRC::addCCITT161(unsigned char *in, unsigned int length)
bool CCRC::checkCCITT161(const unsigned char *in, unsigned int length) bool CCRC::checkCCITT161(const unsigned char *in, unsigned int length)
{ {
assert(in != NULL); assert(in != nullptr);
assert(length > 2U); assert(length > 2U);
union { union {
@ -228,7 +228,7 @@ bool CCRC::checkCCITT161(const unsigned char *in, unsigned int length)
unsigned char CCRC::crc8(const unsigned char *in, unsigned int length) unsigned char CCRC::crc8(const unsigned char *in, unsigned int length)
{ {
assert(in != NULL); assert(in != nullptr);
uint8_t crc = 0U; uint8_t crc = 0U;
@ -240,7 +240,7 @@ unsigned char CCRC::crc8(const unsigned char *in, unsigned int length)
unsigned char CCRC::addCRC(const unsigned char* in, unsigned int length) unsigned char CCRC::addCRC(const unsigned char* in, unsigned int length)
{ {
assert(in != NULL); assert(in != nullptr);
unsigned char crc = 0U; unsigned char crc = 0U;

@ -113,11 +113,8 @@ void CDcsProtocol::Task(void)
EncodeConnectAckPacket(Callsign, ToLinkModule, &Buffer); EncodeConnectAckPacket(Callsign, ToLinkModule, &Buffer);
Send(Buffer, Ip); Send(Buffer, Ip);
// create the client // create the client and append
CDcsClient *client = new CDcsClient(Callsign, Ip, ToLinkModule); g_Reflector.GetClients()->AddClient(std::make_shared<CDcsClient>(Callsign, Ip, ToLinkModule));
// and append
g_Reflector.GetClients()->AddClient(client);
g_Reflector.ReleaseClients(); g_Reflector.ReleaseClients();
} }
else else
@ -143,8 +140,8 @@ void CDcsProtocol::Task(void)
// find client // find client
CClients *clients = g_Reflector.GetClients(); CClients *clients = g_Reflector.GetClients();
CClient *client = clients->FindClient(Ip, PROTOCOL_DCS); std::shared_ptr<CClient>client = clients->FindClient(Ip, PROTOCOL_DCS);
if ( client != NULL ) if ( client != nullptr )
{ {
// remove it // remove it
clients->RemoveClient(client); clients->RemoveClient(client);
@ -161,8 +158,8 @@ void CDcsProtocol::Task(void)
// find all clients with that callsign & ip and keep them alive // find all clients with that callsign & ip and keep them alive
CClients *clients = g_Reflector.GetClients(); CClients *clients = g_Reflector.GetClients();
auto it = clients->begin(); auto it = clients->begin();
CClient *client = NULL; std::shared_ptr<CClient>client = nullptr;
while ( (client = clients->FindNextClient(Callsign, Ip, PROTOCOL_DCS, it)) != NULL ) while ( (client = clients->FindNextClient(Callsign, Ip, PROTOCOL_DCS, it)) != nullptr )
{ {
client->Alive(); client->Alive();
} }
@ -206,19 +203,19 @@ bool CDcsProtocol::OnDvHeaderPacketIn(CDvHeaderPacket *Header, const CIp &Ip)
// find the stream // find the stream
CPacketStream *stream = GetStream(Header->GetStreamId()); CPacketStream *stream = GetStream(Header->GetStreamId());
if ( stream == NULL ) if ( stream == nullptr )
{ {
// no stream open yet, open a new one // no stream open yet, open a new one
CCallsign via(Header->GetRpt1Callsign()); CCallsign via(Header->GetRpt1Callsign());
// find this client // find this client
CClient *client = g_Reflector.GetClients()->FindClient(Ip, PROTOCOL_DCS); std::shared_ptr<CClient>client = g_Reflector.GetClients()->FindClient(Ip, PROTOCOL_DCS);
if ( client != NULL ) if ( client != nullptr )
{ {
// get client callsign // get client callsign
via = client->GetCallsign(); via = client->GetCallsign();
// and try to open the stream // 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 // keep the handle
m_Streams.push_back(stream); 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 // and push it to all our clients linked to the module and who are not streaming in
CClients *clients = g_Reflector.GetClients(); CClients *clients = g_Reflector.GetClients();
auto it = clients->begin(); auto it = clients->begin();
CClient *client = NULL; std::shared_ptr<CClient>client = nullptr;
while ( (client = clients->FindNextClient(PROTOCOL_DCS, it)) != NULL ) while ( (client = clients->FindNextClient(PROTOCOL_DCS, it)) != nullptr )
{ {
// is this client busy ? // is this client busy ?
if ( !client->IsAMaster() && (client->GetReflectorModule() == packet->GetModuleId()) ) if ( !client->IsAMaster() && (client->GetReflectorModule() == packet->GetModuleId()) )
@ -335,8 +332,8 @@ void CDcsProtocol::HandleKeepalives(void)
// iterate on clients // iterate on clients
CClients *clients = g_Reflector.GetClients(); CClients *clients = g_Reflector.GetClients();
auto it = clients->begin(); auto it = clients->begin();
CClient *client = NULL; std::shared_ptr<CClient>client = nullptr;
while ( (client = clients->FindNextClient(PROTOCOL_DCS, it)) != NULL ) while ( (client = clients->FindNextClient(PROTOCOL_DCS, it)) != nullptr )
{ {
// encode client's specific keepalive packet // encode client's specific keepalive packet
CBuffer keepalive2; CBuffer keepalive2;
@ -419,27 +416,24 @@ bool CDcsProtocol::IsValidDvPacket(const CBuffer &Buffer, CDvHeaderPacket **head
uint8 tag[] = { '0','0','0','1' }; uint8 tag[] = { '0','0','0','1' };
bool valid = false; bool valid = false;
*header = NULL; *header = nullptr;
*frame = NULL; *frame = nullptr;
if ( (Buffer.size() >= 100) && (Buffer.Compare(tag, sizeof(tag)) == 0) ) if ( (Buffer.size() >= 100) && (Buffer.Compare(tag, sizeof(tag)) == 0) )
{ {
// get the header // get the header
*header = new CDvHeaderPacket((struct dstar_header *)&(Buffer.data()[4]), *header = new CDvHeaderPacket((struct dstar_header *)&(Buffer.data()[4]), *((uint16 *)&(Buffer.data()[43])), 0x80);
*((uint16 *)&(Buffer.data()[43])), 0x80);
// get the frame // get the frame
if ( ((Buffer.data()[45]) & 0x40) != 0 ) if ( ((Buffer.data()[45]) & 0x40) != 0 )
{ {
// it's the last frame // it's the last frame
*frame = new CDvLastFramePacket((struct dstar_dvframe *)&(Buffer.data()[46]), *frame = new CDvLastFramePacket((struct dstar_dvframe *)&(Buffer.data()[46]), *((uint16 *)&(Buffer.data()[43])), Buffer.data()[45]);
*((uint16 *)&(Buffer.data()[43])), Buffer.data()[45]);
} }
else else
{ {
// it's a regular DV frame // it's a regular DV frame
*frame = new CDvFramePacket((struct dstar_dvframe *)&(Buffer.data()[46]), *frame = new CDvFramePacket((struct dstar_dvframe *)&(Buffer.data()[46]), *((uint16 *)&(Buffer.data()[43])), Buffer.data()[45]);
*((uint16 *)&(Buffer.data()[43])), Buffer.data()[45]);
} }
// check validity of packets // check validity of packets
@ -447,8 +441,8 @@ bool CDcsProtocol::IsValidDvPacket(const CBuffer &Buffer, CDvHeaderPacket **head
{ {
delete *header; delete *header;
delete *frame; delete *frame;
*header = NULL; *header = nullptr;
*frame = NULL; *frame = nullptr;
} }
else else
{ {
@ -480,7 +474,7 @@ void CDcsProtocol::EncodeKeepAlivePacket(CBuffer *Buffer)
Buffer->Set(GetReflectorCallsign()); Buffer->Set(GetReflectorCallsign());
} }
void CDcsProtocol::EncodeKeepAlivePacket(CBuffer *Buffer, CClient *Client) void CDcsProtocol::EncodeKeepAlivePacket(CBuffer *Buffer, std::shared_ptr<CClient>Client)
{ {
uint8 tag[] = { 0x0A,0x00,0x20,0x20 }; uint8 tag[] = { 0x0A,0x00,0x20,0x20 };
@ -519,7 +513,7 @@ void CDcsProtocol::EncodeConnectNackPacket(const CCallsign &Callsign, char Refle
Buffer->Append(tag, sizeof(tag)); Buffer->Append(tag, sizeof(tag));
} }
void CDcsProtocol::EncodeDisconnectPacket(CBuffer *Buffer, CClient *Client) void CDcsProtocol::EncodeDisconnectPacket(CBuffer *Buffer, std::shared_ptr<CClient>Client)
{ {
Buffer->Set((uint8 *)(const char *)Client->GetCallsign(), CALLSIGN_LEN-1); Buffer->Set((uint8 *)(const char *)Client->GetCallsign(), CALLSIGN_LEN-1);
Buffer->Append((uint8)' '); Buffer->Append((uint8)' ');

@ -75,10 +75,10 @@ protected:
// packet encoding helpers // packet encoding helpers
void EncodeKeepAlivePacket(CBuffer *); void EncodeKeepAlivePacket(CBuffer *);
void EncodeKeepAlivePacket(CBuffer *, CClient *); void EncodeKeepAlivePacket(CBuffer *, std::shared_ptr<CClient>);
void EncodeConnectAckPacket(const CCallsign &, char, CBuffer *); void EncodeConnectAckPacket(const CCallsign &, char, CBuffer *);
void EncodeConnectNackPacket(const CCallsign &, char, CBuffer *); void EncodeConnectNackPacket(const CCallsign &, char, CBuffer *);
void EncodeDisconnectPacket(CBuffer *, CClient *); void EncodeDisconnectPacket(CBuffer *, std::shared_ptr<CClient>);
void EncodeDvPacket(const CDvHeaderPacket &, const CDvFramePacket &, uint32, CBuffer *) const; void EncodeDvPacket(const CDvHeaderPacket &, const CDvFramePacket &, uint32, CBuffer *) const;
void EncodeDvLastPacket(const CDvHeaderPacket &, const CDvFramePacket &, uint32, CBuffer *) const; void EncodeDvLastPacket(const CDvHeaderPacket &, const CDvFramePacket &, uint32, CBuffer *) const;

@ -46,10 +46,8 @@ CDextraPeer::CDextraPeer(const CCallsign &callsign, const CIp &ip, const char *m
// and construct the DExtra clients // and construct the DExtra clients
for ( unsigned i = 0; i < ::strlen(modules); i++ ) for ( unsigned i = 0; i < ::strlen(modules); i++ )
{ {
// create // create and append to vector
CDextraClient *client = new CDextraClient(callsign, ip, modules[i], version.GetMajor()); m_Clients.push_back(std::make_shared<CDextraClient>(callsign, ip, modules[i], version.GetMajor()));
// and append to vector
m_Clients.push_back(client);
} }
} }
@ -58,7 +56,7 @@ CDextraPeer::CDextraPeer(const CDextraPeer &peer)
{ {
for ( auto it=peer.cbegin(); it!=peer.cend(); it++ ) for ( auto it=peer.cbegin(); it!=peer.cend(); it++ )
{ {
CDextraClient *client = new CDextraClient((const CDextraClient &)*(*it)); std::shared_ptr<CDextraClient> client(new CDextraClient((const CDextraClient &)*(*it)));
m_Clients.push_back(client); m_Clients.push_back(client);
} }

@ -75,14 +75,14 @@ void CDextraProtocol::Task(void)
#endif #endif
{ {
// crack the packet // crack the packet
if ( (Frame = IsValidDvFramePacket(Buffer)) != NULL ) if ( (Frame = IsValidDvFramePacket(Buffer)) != nullptr )
{ {
//std::cout << "DExtra DV frame" << std::endl; //std::cout << "DExtra DV frame" << std::endl;
// handle it // handle it
OnDvFramePacketIn(Frame, &Ip); 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 << *Header << std::endl;
//std::cout << "DExtra DV header:" << std::endl; //std::cout << "DExtra DV header:" << std::endl;
@ -98,7 +98,7 @@ void CDextraProtocol::Task(void)
delete Header; delete Header;
} }
} }
else if ( (LastFrame = IsValidDvLastFramePacket(Buffer)) != NULL ) else if ( (LastFrame = IsValidDvLastFramePacket(Buffer)) != nullptr )
{ {
//std::cout << "DExtra DV last frame" << std::endl; //std::cout << "DExtra DV last frame" << std::endl;
@ -118,21 +118,19 @@ void CDextraProtocol::Task(void)
// is this an ack for a link request? // is this an ack for a link request?
CPeerCallsignList *list = g_GateKeeper.GetPeerList(); CPeerCallsignList *list = g_GateKeeper.GetPeerList();
CCallsignListItem *item = list->FindListItem(Callsign); 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; std::cout << "DExtra ack packet for module " << ToLinkModule << " from " << Callsign << " at " << Ip << std::endl;
// already connected ? // already connected ?
CPeers *peers = g_Reflector.GetPeers(); 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 // create the new peer
// this also create one client per module // 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 // append the peer to reflector peer list
// this also add all new clients to reflector client list // this also add all new clients to reflector client list
peers->AddPeer(peer); peers->AddPeer(std::make_shared<CDextraPeer>(Callsign, Ip, std::string(1, ToLinkModule).c_str(), CVersion(2, 0, 0)));
} }
g_Reflector.ReleasePeers(); g_Reflector.ReleasePeers();
} }
@ -142,11 +140,8 @@ void CDextraProtocol::Task(void)
EncodeConnectAckPacket(&Buffer, ProtRev); EncodeConnectAckPacket(&Buffer, ProtRev);
Send(Buffer, Ip); Send(Buffer, Ip);
// create the client // create the client and append
CDextraClient *client = new CDextraClient(Callsign, Ip, ToLinkModule, ProtRev); g_Reflector.GetClients()->AddClient(std::make_shared<CDextraClient>(Callsign, Ip, ToLinkModule, ProtRev));
// and append
g_Reflector.GetClients()->AddClient(client);
g_Reflector.ReleaseClients(); g_Reflector.ReleaseClients();
} }
g_GateKeeper.ReleasePeerList(); g_GateKeeper.ReleasePeerList();
@ -173,8 +168,8 @@ void CDextraProtocol::Task(void)
// find client & remove it // find client & remove it
CClients *clients = g_Reflector.GetClients(); CClients *clients = g_Reflector.GetClients();
CClient *client = clients->FindClient(Ip, PROTOCOL_DEXTRA); std::shared_ptr<CClient>client = clients->FindClient(Ip, PROTOCOL_DEXTRA);
if ( client != NULL ) if ( client != nullptr )
{ {
// ack disconnect packet // ack disconnect packet
if ( client->GetProtocolRevision() == 1 ) if ( client->GetProtocolRevision() == 1 )
@ -198,8 +193,8 @@ void CDextraProtocol::Task(void)
// find all clients with that callsign & ip and keep them alive // find all clients with that callsign & ip and keep them alive
CClients *clients = g_Reflector.GetClients(); CClients *clients = g_Reflector.GetClients();
auto it = clients->begin(); auto it = clients->begin();
CClient *client = NULL; std::shared_ptr<CClient>client = nullptr;
while ( (client = clients->FindNextClient(Callsign, Ip, PROTOCOL_DEXTRA, it)) != NULL ) while ( (client = clients->FindNextClient(Callsign, Ip, PROTOCOL_DEXTRA, it)) != nullptr )
{ {
client->Alive(); 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 // and push it to all our clients linked to the module and who are not streaming in
CClients *clients = g_Reflector.GetClients(); CClients *clients = g_Reflector.GetClients();
auto it = clients->begin(); auto it = clients->begin();
CClient *client = NULL; std::shared_ptr<CClient>client = nullptr;
while ( (client = clients->FindNextClient(PROTOCOL_DEXTRA, it)) != NULL ) while ( (client = clients->FindNextClient(PROTOCOL_DEXTRA, it)) != nullptr )
{ {
// is this client busy ? // is this client busy ?
if ( !client->IsAMaster() && (client->GetReflectorModule() == packet->GetModuleId()) ) if ( !client->IsAMaster() && (client->GetReflectorModule() == packet->GetModuleId()) )
@ -296,8 +291,8 @@ void CDextraProtocol::HandleKeepalives(void)
// iterate on clients // iterate on clients
CClients *clients = g_Reflector.GetClients(); CClients *clients = g_Reflector.GetClients();
auto it = clients->begin(); auto it = clients->begin();
CClient *client = NULL; std::shared_ptr<CClient>client = nullptr;
while ( (client = clients->FindNextClient(PROTOCOL_DEXTRA, it)) != NULL ) while ( (client = clients->FindNextClient(PROTOCOL_DEXTRA, it)) != nullptr )
{ {
// send keepalive // send keepalive
Send(keepalive, client->GetIp()); Send(keepalive, client->GetIp());
@ -312,8 +307,8 @@ void CDextraProtocol::HandleKeepalives(void)
else if ( !client->IsAlive() ) else if ( !client->IsAlive() )
{ {
CPeers *peers = g_Reflector.GetPeers(); CPeers *peers = g_Reflector.GetPeers();
CPeer *peer = peers->FindPeer(client->GetCallsign(), client->GetIp(), PROTOCOL_DEXTRA); std::shared_ptr<CPeer>peer = peers->FindPeer(client->GetCallsign(), client->GetIp(), PROTOCOL_DEXTRA);
if ( peer != NULL && peer->GetReflectorModules()[0] == client->GetReflectorModule() ) if ( peer != nullptr && peer->GetReflectorModules()[0] == client->GetReflectorModule() )
{ {
// no, but this is a peer client, so it will be handled below // no, but this is a peer client, so it will be handled below
} }
@ -337,8 +332,8 @@ void CDextraProtocol::HandleKeepalives(void)
// iterate on peers // iterate on peers
CPeers *peers = g_Reflector.GetPeers(); CPeers *peers = g_Reflector.GetPeers();
auto pit = peers->begin(); auto pit = peers->begin();
CPeer *peer = NULL; std::shared_ptr<CPeer>peer = nullptr;
while ( (peer = peers->FindNextPeer(PROTOCOL_DEXTRA, pit)) != NULL ) while ( (peer = peers->FindNextPeer(PROTOCOL_DEXTRA, pit)) != nullptr )
{ {
// keepalives are sent between clients // keepalives are sent between clients
@ -377,10 +372,10 @@ void CDextraProtocol::HandlePeerLinks(void)
// check if all our connected peers are still listed by gatekeeper // check if all our connected peers are still listed by gatekeeper
// if not, disconnect // if not, disconnect
auto pit = peers->begin(); auto pit = peers->begin();
CPeer *peer = NULL; std::shared_ptr<CPeer>peer = nullptr;
while ( (peer = peers->FindNextPeer(PROTOCOL_DEXTRA, pit)) != NULL ) while ( (peer = peers->FindNextPeer(PROTOCOL_DEXTRA, pit)) != nullptr )
{ {
if ( list->FindListItem(peer->GetCallsign()) == NULL ) if ( list->FindListItem(peer->GetCallsign()) == nullptr )
{ {
// send disconnect packet // send disconnect packet
EncodeDisconnectPacket(&buffer, peer->GetReflectorModules()[0]); EncodeDisconnectPacket(&buffer, peer->GetReflectorModules()[0]);
@ -399,7 +394,7 @@ void CDextraProtocol::HandlePeerLinks(void)
continue; continue;
if ( strlen((*it).GetModules()) != 2 ) if ( strlen((*it).GetModules()) != 2 )
continue; 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 // resolve again peer's IP in case it's a dynamic IP
(*it).ResolveIp(); (*it).ResolveIp();
@ -424,14 +419,14 @@ bool CDextraProtocol::OnDvHeaderPacketIn(CDvHeaderPacket *Header, const CIp &Ip)
// find the stream // find the stream
CPacketStream *stream = GetStream(Header->GetStreamId()); CPacketStream *stream = GetStream(Header->GetStreamId());
if ( stream == NULL ) if ( stream == nullptr )
{ {
// no stream open yet, open a new one // no stream open yet, open a new one
CCallsign via(Header->GetRpt1Callsign()); CCallsign via(Header->GetRpt1Callsign());
// find this client // find this client
CClient *client = g_Reflector.GetClients()->FindClient(Ip, PROTOCOL_DEXTRA); std::shared_ptr<CClient>client = g_Reflector.GetClients()->FindClient(Ip, PROTOCOL_DEXTRA);
if ( client != NULL ) if ( client != nullptr )
{ {
// get client callsign // get client callsign
via = client->GetCallsign(); via = client->GetCallsign();
@ -443,7 +438,7 @@ bool CDextraProtocol::OnDvHeaderPacketIn(CDvHeaderPacket *Header, const CIp &Ip)
Header->SetRpt2Module(client->GetReflectorModule()); Header->SetRpt2Module(client->GetReflectorModule());
} }
// and try to open the stream // 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 // keep the handle
m_Streams.push_back(stream); m_Streams.push_back(stream);
@ -531,7 +526,7 @@ bool CDextraProtocol::IsValidKeepAlivePacket(const CBuffer &Buffer, CCallsign *c
CDvHeaderPacket *CDextraProtocol::IsValidDvHeaderPacket(const CBuffer &Buffer) CDvHeaderPacket *CDextraProtocol::IsValidDvHeaderPacket(const CBuffer &Buffer)
{ {
CDvHeaderPacket *header = NULL; CDvHeaderPacket *header = nullptr;
if ( (Buffer.size() == 56) && (Buffer.Compare((uint8 *)"DSVT", 4) == 0) && if ( (Buffer.size() == 56) && (Buffer.Compare((uint8 *)"DSVT", 4) == 0) &&
(Buffer.data()[4] == 0x10) && (Buffer.data()[8] == 0x20) ) (Buffer.data()[4] == 0x10) && (Buffer.data()[8] == 0x20) )
@ -543,7 +538,7 @@ CDvHeaderPacket *CDextraProtocol::IsValidDvHeaderPacket(const CBuffer &Buffer)
if ( !header->IsValid() ) if ( !header->IsValid() )
{ {
delete header; delete header;
header = NULL; header = nullptr;
} }
} }
return header; return header;
@ -551,7 +546,7 @@ CDvHeaderPacket *CDextraProtocol::IsValidDvHeaderPacket(const CBuffer &Buffer)
CDvFramePacket *CDextraProtocol::IsValidDvFramePacket(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) && if ( (Buffer.size() == 27) && (Buffer.Compare((uint8 *)"DSVT", 4) == 0) &&
(Buffer.data()[4] == 0x20) && (Buffer.data()[8] == 0x20) && (Buffer.data()[4] == 0x20) && (Buffer.data()[8] == 0x20) &&
@ -564,7 +559,7 @@ CDvFramePacket *CDextraProtocol::IsValidDvFramePacket(const CBuffer &Buffer)
if ( !dvframe->IsValid() ) if ( !dvframe->IsValid() )
{ {
delete dvframe; delete dvframe;
dvframe = NULL; dvframe = nullptr;
} }
} }
return dvframe; return dvframe;
@ -572,7 +567,7 @@ CDvFramePacket *CDextraProtocol::IsValidDvFramePacket(const CBuffer &Buffer)
CDvLastFramePacket *CDextraProtocol::IsValidDvLastFramePacket(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) && if ( (Buffer.size() == 27) && (Buffer.Compare((uint8 *)"DSVT", 4) == 0) &&
(Buffer.data()[4] == 0x20) && (Buffer.data()[8] == 0x20) && (Buffer.data()[4] == 0x20) && (Buffer.data()[8] == 0x20) &&
@ -585,7 +580,7 @@ CDvLastFramePacket *CDextraProtocol::IsValidDvLastFramePacket(const CBuffer &Buf
if ( !dvframe->IsValid() ) if ( !dvframe->IsValid() )
{ {
delete dvframe; delete dvframe;
dvframe = NULL; dvframe = nullptr;
} }
} }
return dvframe; return dvframe;

@ -35,18 +35,18 @@
CDmridDir::CDmridDir() CDmridDir::CDmridDir()
{ {
keep_running = true; keep_running = true;
m_pThread = NULL; m_pThread = nullptr;
} }
CDmridDir::~CDmridDir() CDmridDir::~CDmridDir()
{ {
// kill threads // kill threads
keep_running = false; keep_running = false;
if ( m_pThread != NULL ) if ( m_pThread != nullptr )
{ {
m_pThread->join(); m_pThread->join();
delete m_pThread; delete m_pThread;
m_pThread = NULL; m_pThread = nullptr;
} }
} }
@ -71,11 +71,11 @@ bool CDmridDir::Init(void)
void CDmridDir::Close(void) void CDmridDir::Close(void)
{ {
keep_running = false; keep_running = false;
if ( m_pThread != NULL ) if ( m_pThread != nullptr )
{ {
m_pThread->join(); m_pThread->join();
delete m_pThread; delete m_pThread;
m_pThread = NULL; m_pThread = nullptr;
} }
} }
@ -128,7 +128,7 @@ const CCallsign *CDmridDir::FindCallsign(uint32 dmrid)
{ {
return &(found->second); return &(found->second);
} }
return NULL; return nullptr;
} }
uint32 CDmridDir::FindDmrid(const CCallsign &callsign) uint32 CDmridDir::FindDmrid(const CCallsign &callsign)

@ -115,15 +115,15 @@ bool CDmridDirFile::RefreshContent(const CBuffer &buffer)
char *ptr2; char *ptr2;
// get next line // get next line
while ( (ptr2 = ::strchr(ptr1, '\n')) != NULL ) while ( (ptr2 = ::strchr(ptr1, '\n')) != nullptr )
{ {
*ptr2 = 0; *ptr2 = 0;
// get items // get items
char *dmrid; char *dmrid;
char *callsign; 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 // new entry
uint32 ui = atoi(dmrid); uint32 ui = atoi(dmrid);

@ -57,15 +57,15 @@ bool CDmridDirHttp::RefreshContent(const CBuffer &buffer)
char *ptr1 = (char *)buffer.data(); char *ptr1 = (char *)buffer.data();
char *ptr2; char *ptr2;
// get next line // get next line
while ( (ptr2 = ::strchr(ptr1, '\n')) != NULL ) while ( (ptr2 = ::strchr(ptr1, '\n')) != nullptr )
{ {
*ptr2 = 0; *ptr2 = 0;
// get items // get items
char *dmrid; char *dmrid;
char *callsign; 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 // new entry
uint32 ui = atoi(dmrid); uint32 ui = atoi(dmrid);
@ -109,7 +109,7 @@ bool CDmridDirHttp::HttpGet(const char *hostname, const char *filename, int port
struct sockaddr_in servaddr; struct sockaddr_in servaddr;
struct hostent *hp; struct hostent *hp;
::memset(&servaddr,0,sizeof(servaddr)); ::memset(&servaddr,0,sizeof(servaddr));
if( (hp = gethostbyname(hostname)) != NULL ) if( (hp = gethostbyname(hostname)) != nullptr )
{ {
// dns resolved // dns resolved
::memcpy((char *)&servaddr.sin_addr.s_addr, (char *)hp->h_addr, hp->h_length); ::memcpy((char *)&servaddr.sin_addr.s_addr, (char *)hp->h_addr, hp->h_length);
@ -140,7 +140,7 @@ bool CDmridDirHttp::HttpGet(const char *hostname, const char *filename, int port
{ {
char buf[1440]; char buf[1440];
ssize_t len = 0; 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) || ((ret < 0) && (errno == EINPROGRESS)) )
//if ( ret >= 0 ) //if ( ret >= 0 )
//{ //{

@ -57,7 +57,7 @@ static uint8 g_DmrSyncMSData[] = { 0x0D,0x5D,0x7F,0x77,0xFD,0x75,0x70 };
bool CDmrmmdvmProtocol::Init(void) bool CDmrmmdvmProtocol::Init(void)
{ {
// base class // base class
if (! Initialize(NULL, DMRMMDVM_PORT, DMR_IPV4, DMR_IPV6)) if (! Initialize(nullptr, DMRMMDVM_PORT, DMR_IPV4, DMR_IPV6))
return false; return false;
// update time // update time
@ -165,17 +165,14 @@ void CDmrmmdvmProtocol::Task(void)
// add client if needed // add client if needed
CClients *clients = g_Reflector.GetClients(); CClients *clients = g_Reflector.GetClients();
CClient *client = clients->FindClient(Callsign, Ip, PROTOCOL_DMRMMDVM); std::shared_ptr<CClient>client = clients->FindClient(Callsign, Ip, PROTOCOL_DMRMMDVM);
// client already connected ? // client already connected ?
if ( client == NULL ) if ( client == nullptr )
{ {
std::cout << "DMRmmdvm login from " << Callsign << " at " << Ip << std::endl; std::cout << "DMRmmdvm login from " << Callsign << " at " << Ip << std::endl;
// create the client // create the client and append
CDmrmmdvmClient *newclient = new CDmrmmdvmClient(Callsign, Ip); clients->AddClient(std::make_shared<CDmrmmdvmClient>(Callsign, Ip));
// and append
clients->AddClient(newclient);
} }
else else
{ {
@ -198,8 +195,8 @@ void CDmrmmdvmProtocol::Task(void)
// find client & remove it // find client & remove it
CClients *clients = g_Reflector.GetClients(); CClients *clients = g_Reflector.GetClients();
CClient *client = clients->FindClient(Ip, PROTOCOL_DMRMMDVM); std::shared_ptr<CClient>client = clients->FindClient(Ip, PROTOCOL_DMRMMDVM);
if ( client != NULL ) if ( client != nullptr )
{ {
clients->RemoveClient(client); clients->RemoveClient(client);
} }
@ -220,8 +217,8 @@ void CDmrmmdvmProtocol::Task(void)
// find all clients with that callsign & ip and keep them alive // find all clients with that callsign & ip and keep them alive
CClients *clients = g_Reflector.GetClients(); CClients *clients = g_Reflector.GetClients();
auto it = clients->begin(); auto it = clients->begin();
CClient *client = NULL; std::shared_ptr<CClient>client = nullptr;
while ( (client = clients->FindNextClient(Callsign, Ip, PROTOCOL_DMRMMDVM, it)) != NULL ) while ( (client = clients->FindNextClient(Callsign, Ip, PROTOCOL_DMRMMDVM, it)) != nullptr )
{ {
// acknowledge // acknowledge
EncodeKeepAlivePacket(&Buffer, client); EncodeKeepAlivePacket(&Buffer, client);
@ -285,12 +282,12 @@ bool CDmrmmdvmProtocol::OnDvHeaderPacketIn(CDvHeaderPacket *Header, const CIp &I
// find the stream // find the stream
CPacketStream *stream = GetStream(Header->GetStreamId()); CPacketStream *stream = GetStream(Header->GetStreamId());
if ( stream == NULL ) if ( stream == nullptr )
{ {
// no stream open yet, open a new one // no stream open yet, open a new one
// firstfind this client // firstfind this client
CClient *client = g_Reflector.GetClients()->FindClient(Ip, PROTOCOL_DMRMMDVM); std::shared_ptr<CClient>client = g_Reflector.GetClients()->FindClient(Ip, PROTOCOL_DMRMMDVM);
if ( client != NULL ) if ( client != nullptr )
{ {
// process cmd if any // process cmd if any
if ( !client->HasReflectorModule() ) 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) ) if ( g_Reflector.IsValidModule(Header->GetRpt2Module()) && (CallType == DMR_GROUP_CALL) )
{ {
// yes, try to open the stream // 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 // keep the handle
m_Streams.push_back(stream); 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 // and push it to all our clients linked to the module and who are not streaming in
CClients *clients = g_Reflector.GetClients(); CClients *clients = g_Reflector.GetClients();
auto it = clients->begin(); auto it = clients->begin();
CClient *client = NULL; std::shared_ptr<CClient>client = nullptr;
while ( (client = clients->FindNextClient(PROTOCOL_DMRMMDVM, it)) != NULL ) while ( (client = clients->FindNextClient(PROTOCOL_DMRMMDVM, it)) != nullptr )
{ {
// is this client busy ? // is this client busy ?
if ( !client->IsAMaster() && (client->GetReflectorModule() == packet->GetModuleId()) ) if ( !client->IsAMaster() && (client->GetReflectorModule() == packet->GetModuleId()) )
@ -476,8 +473,8 @@ void CDmrmmdvmProtocol::HandleKeepalives(void)
// iterate on clients // iterate on clients
CClients *clients = g_Reflector.GetClients(); CClients *clients = g_Reflector.GetClients();
auto it = clients->begin(); auto it = clients->begin();
CClient *client = NULL; std::shared_ptr<CClient>client = nullptr;
while ( (client = clients->FindNextClient(PROTOCOL_DMRMMDVM, it)) != NULL ) while ( (client = clients->FindNextClient(PROTOCOL_DMRMMDVM, it)) != nullptr )
{ {
// is this client busy ? // is this client busy ?
if ( client->IsAMaster() ) if ( client->IsAMaster() )
@ -628,7 +625,7 @@ bool CDmrmmdvmProtocol::IsValidDvHeaderPacket(const CBuffer &Buffer, CDvHeaderPa
uint8 tag[] = { 'D','M','R','D' }; uint8 tag[] = { 'D','M','R','D' };
bool valid = false; bool valid = false;
*header = NULL; *header = nullptr;
*cmd = CMD_NONE; *cmd = CMD_NONE;
if ( (Buffer.size() == 55) && (Buffer.Compare(tag, sizeof(tag)) == 0) ) if ( (Buffer.size() == 55) && (Buffer.Compare(tag, sizeof(tag)) == 0) )
@ -695,7 +692,7 @@ bool CDmrmmdvmProtocol::IsValidDvHeaderPacket(const CBuffer &Buffer, CDvHeaderPa
if ( !valid ) if ( !valid )
{ {
delete *header; delete *header;
*header = NULL; *header = nullptr;
} }
} }
} }
@ -709,9 +706,9 @@ bool CDmrmmdvmProtocol::IsValidDvFramePacket(const CBuffer &Buffer, CDvFramePack
uint8 tag[] = { 'D','M','R','D' }; uint8 tag[] = { 'D','M','R','D' };
bool valid = false; bool valid = false;
frames[0] = NULL; frames[0] = nullptr;
frames[1] = NULL; frames[1] = nullptr;
frames[2] = NULL; frames[2] = nullptr;
if ( (Buffer.size() == 55) && (Buffer.Compare(tag, sizeof(tag)) == 0) ) 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' }; uint8 tag[] = { 'D','M','R','D' };
bool valid = false; bool valid = false;
*frame = NULL; *frame = nullptr;
if ( (Buffer.size() == 55) && (Buffer.Compare(tag, sizeof(tag)) == 0) ) if ( (Buffer.size() == 55) && (Buffer.Compare(tag, sizeof(tag)) == 0) )
{ {
@ -834,7 +831,7 @@ bool CDmrmmdvmProtocol::IsValidDvLastFramePacket(const CBuffer &Buffer, CDvLastF
//////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////
// packet encoding helpers // packet encoding helpers
void CDmrmmdvmProtocol::EncodeKeepAlivePacket(CBuffer *Buffer, CClient *Client) void CDmrmmdvmProtocol::EncodeKeepAlivePacket(CBuffer *Buffer, std::shared_ptr<CClient>Client)
{ {
uint8 tag[] = { 'M','S','T','P','O','N','G' }; 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)); Buffer->Set(tag, sizeof(tag));
} }
void CDmrmmdvmProtocol::EncodeClosePacket(CBuffer *Buffer, CClient *Client) void CDmrmmdvmProtocol::EncodeClosePacket(CBuffer *Buffer, std::shared_ptr<CClient>Client)
{ {
uint8 tag[] = { 'M','S','T','C','L' }; uint8 tag[] = { 'M','S','T','C','L' };
@ -1168,7 +1165,7 @@ void CDmrmmdvmProtocol::ReplaceEMBInBuffer(CBuffer *buffer, uint8 uiDmrPacketId)
// voice packet F // voice packet F
else else
{ {
// NULL // nullptr
uint8 emb[2]; uint8 emb[2];
emb[0] = (DMRMMDVM_REFLECTOR_COLOUR << 4) & 0xF0; emb[0] = (DMRMMDVM_REFLECTOR_COLOUR << 4) & 0xF0;
//emb[0] |= PI ? 0x08U : 0x00; //emb[0] |= PI ? 0x08U : 0x00;

@ -95,11 +95,11 @@ protected:
bool IsValidDvLastFramePacket(const CBuffer &, CDvLastFramePacket **); bool IsValidDvLastFramePacket(const CBuffer &, CDvLastFramePacket **);
// packet encoding helpers // packet encoding helpers
void EncodeKeepAlivePacket(CBuffer *, CClient *); void EncodeKeepAlivePacket(CBuffer *, std::shared_ptr<CClient>);
void EncodeAckPacket(CBuffer *, const CCallsign &); void EncodeAckPacket(CBuffer *, const CCallsign &);
void EncodeConnectAckPacket(CBuffer *, const CCallsign &, uint32); void EncodeConnectAckPacket(CBuffer *, const CCallsign &, uint32);
void EncodeNackPacket(CBuffer *, const CCallsign &); void EncodeNackPacket(CBuffer *, const CCallsign &);
void EncodeClosePacket(CBuffer *, CClient *); void EncodeClosePacket(CBuffer *, std::shared_ptr<CClient>);
bool EncodeDvHeaderPacket(const CDvHeaderPacket &, uint8, CBuffer *) const; bool EncodeDvHeaderPacket(const CDvHeaderPacket &, uint8, CBuffer *) const;
void EncodeDvPacket(const CDvHeaderPacket &, const CDvFramePacket &, const CDvFramePacket &, const CDvFramePacket &, uint8, CBuffer *) const; void EncodeDvPacket(const CDvHeaderPacket &, const CDvFramePacket &, const CDvFramePacket &, const CDvFramePacket &, uint8, CBuffer *) const;
void EncodeDvLastPacket(const CDvHeaderPacket &, uint8, CBuffer *) const; void EncodeDvLastPacket(const CDvHeaderPacket &, uint8, CBuffer *) const;

@ -50,7 +50,7 @@ static uint8 g_DmrSyncMSData[] = { 0x0D,0x5D,0x7F,0x77,0xFD,0x75,0x70 };
bool CDmrplusProtocol::Init() bool CDmrplusProtocol::Init()
{ {
// base class // base class
if (! Initialize(NULL, DMRPLUS_PORT, DMR_IPV4, DMR_IPV6)) if (! Initialize(nullptr, DMRPLUS_PORT, DMR_IPV4, DMR_IPV6))
return false; return false;
// update time // update time
@ -140,17 +140,14 @@ void CDmrplusProtocol::Task(void)
// add client if needed // add client if needed
CClients *clients = g_Reflector.GetClients(); CClients *clients = g_Reflector.GetClients();
CClient *client = clients->FindClient(Callsign, Ip, PROTOCOL_DMRPLUS); std::shared_ptr<CClient>client = clients->FindClient(Callsign, Ip, PROTOCOL_DMRPLUS);
// client already connected ? // client already connected ?
if ( client == NULL ) if ( client == nullptr )
{ {
std::cout << "DMRplus connect packet for module " << ToLinkModule << " from " << Callsign << " at " << Ip << std::endl; std::cout << "DMRplus connect packet for module " << ToLinkModule << " from " << Callsign << " at " << Ip << std::endl;
// create the client // create the client and append
CDmrplusClient *newclient = new CDmrplusClient(Callsign, Ip, ToLinkModule); clients->AddClient(std::make_shared<CDmrplusClient>(Callsign, Ip, ToLinkModule));
// and append
clients->AddClient(newclient);
} }
else else
{ {
@ -173,8 +170,8 @@ void CDmrplusProtocol::Task(void)
// find client & remove it // find client & remove it
CClients *clients = g_Reflector.GetClients(); CClients *clients = g_Reflector.GetClients();
CClient *client = clients->FindClient(Ip, PROTOCOL_DMRPLUS); std::shared_ptr<CClient>client = clients->FindClient(Ip, PROTOCOL_DMRPLUS);
if ( client != NULL ) if ( client != nullptr )
{ {
clients->RemoveClient(client); clients->RemoveClient(client);
} }
@ -213,15 +210,15 @@ bool CDmrplusProtocol::OnDvHeaderPacketIn(CDvHeaderPacket *Header, const CIp &Ip
// find the stream // find the stream
CPacketStream *stream = GetStream(Header->GetStreamId()); CPacketStream *stream = GetStream(Header->GetStreamId());
if ( stream == NULL ) if ( stream == nullptr )
{ {
// no stream open yet, open a new one // no stream open yet, open a new one
// find this client // find this client
CClient *client = g_Reflector.GetClients()->FindClient(Ip, PROTOCOL_DMRPLUS); std::shared_ptr<CClient>client = g_Reflector.GetClients()->FindClient(Ip, PROTOCOL_DMRPLUS);
if ( client != NULL ) if ( client != nullptr )
{ {
// and try to open the stream // 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 // keep the handle
m_Streams.push_back(stream); 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 // and push it to all our clients linked to the module and who are not streaming in
CClients *clients = g_Reflector.GetClients(); CClients *clients = g_Reflector.GetClients();
auto it = clients->begin(); auto it = clients->begin();
CClient *client = NULL; std::shared_ptr<CClient>client = nullptr;
while ( (client = clients->FindNextClient(PROTOCOL_DMRPLUS, it)) != NULL ) while ( (client = clients->FindNextClient(PROTOCOL_DMRPLUS, it)) != nullptr )
{ {
// is this client busy ? // is this client busy ?
if ( !client->IsAMaster() && (client->GetReflectorModule() == packet->GetModuleId()) ) 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 // and push it to all our clients linked to the module and who are not streaming in
CClients *clients = g_Reflector.GetClients(); CClients *clients = g_Reflector.GetClients();
auto it = clients->begin(); auto it = clients->begin();
CClient *client = NULL; std::shared_ptr<CClient>client = nullptr;
while ( (client = clients->FindNextClient(PROTOCOL_DMRPLUS, it)) != NULL ) while ( (client = clients->FindNextClient(PROTOCOL_DMRPLUS, it)) != nullptr )
{ {
// is this client busy ? // is this client busy ?
if ( !client->IsAMaster() && (client->GetReflectorModule() == module) ) if ( !client->IsAMaster() && (client->GetReflectorModule() == module) )
@ -377,8 +374,8 @@ void CDmrplusProtocol::HandleKeepalives(void)
// iterate on clients // iterate on clients
CClients *clients = g_Reflector.GetClients(); CClients *clients = g_Reflector.GetClients();
auto it = clients->begin(); auto it = clients->begin();
CClient *client = NULL; std::shared_ptr<CClient>client = nullptr;
while ( (client = clients->FindNextClient(PROTOCOL_DMRPLUS, it)) != NULL ) while ( (client = clients->FindNextClient(PROTOCOL_DMRPLUS, it)) != nullptr )
{ {
// is this client busy ? // is this client busy ?
if ( client->IsAMaster() ) 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 CDmrplusProtocol::IsValidDvHeaderPacket(const CIp &Ip, const CBuffer &Buffer, CDvHeaderPacket **Header)
{ {
bool valid = false; bool valid = false;
*Header = NULL; *Header = nullptr;
uint8 uiPacketType = Buffer.data()[8]; uint8 uiPacketType = Buffer.data()[8];
if ( (Buffer.size() == 72) && ( uiPacketType == 2 ) ) if ( (Buffer.size() == 72) && ( uiPacketType == 2 ) )
@ -480,7 +477,7 @@ bool CDmrplusProtocol::IsValidDvHeaderPacket(const CIp &Ip, const CBuffer &Buffe
if ( !valid ) if ( !valid )
{ {
delete *Header; 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 CDmrplusProtocol::IsValidDvFramePacket(const CIp &Ip, const CBuffer &Buffer, CDvFramePacket **frames)
{ {
bool valid = false; bool valid = false;
frames[0] = NULL; frames[0] = nullptr;
frames[1] = NULL; frames[1] = nullptr;
frames[2] = NULL; frames[2] = nullptr;
uint8 uiPacketType = Buffer.data()[8]; uint8 uiPacketType = Buffer.data()[8];
if ( (Buffer.size() == 72) && ((uiPacketType == 1) || (uiPacketType == 3)) ) if ( (Buffer.size() == 72) && ((uiPacketType == 1) || (uiPacketType == 3)) )
@ -816,7 +813,7 @@ void CDmrplusProtocol::ReplaceEMBInBuffer(CBuffer *buffer, uint8 uiDmrPacketId)
// voice packet F // voice packet F
else else
{ {
// NULL // nullptr
uint8 emb[2]; uint8 emb[2];
emb[0] = (DMRMMDVM_REFLECTOR_COLOUR << 4) & 0xF0; emb[0] = (DMRMMDVM_REFLECTOR_COLOUR << 4) & 0xF0;
//emb[0] |= PI ? 0x08U : 0x00; //emb[0] |= PI ? 0x08U : 0x00;

@ -73,14 +73,14 @@ void CDplusProtocol::Task(void)
#endif #endif
{ {
// crack the packet // crack the packet
if ( (Frame = IsValidDvFramePacket(Buffer)) != NULL ) if ( (Frame = IsValidDvFramePacket(Buffer)) != nullptr )
{ {
//std::cout << "DPlus DV frame" << std::endl; //std::cout << "DPlus DV frame" << std::endl;
// handle it // handle it
OnDvFramePacketIn(Frame, &Ip); 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; //std::cout << "DPlus DV header:" << std::endl << *Header << std::endl;
@ -95,7 +95,7 @@ void CDplusProtocol::Task(void)
delete Header; delete Header;
} }
} }
else if ( (LastFrame = IsValidDvLastFramePacket(Buffer)) != NULL ) else if ( (LastFrame = IsValidDvLastFramePacket(Buffer)) != nullptr )
{ {
//std::cout << "DPlus DV last frame" << std::endl; //std::cout << "DPlus DV last frame" << std::endl;
@ -120,11 +120,8 @@ void CDplusProtocol::Task(void)
EncodeLoginAckPacket(&Buffer); EncodeLoginAckPacket(&Buffer);
Send(Buffer, Ip); Send(Buffer, Ip);
// create the client // create the client and append
CDplusClient *client = new CDplusClient(Callsign, Ip); g_Reflector.GetClients()->AddClient(std::make_shared<CDplusClient>(Callsign, Ip));
// and append
g_Reflector.GetClients()->AddClient(client);
g_Reflector.ReleaseClients(); g_Reflector.ReleaseClients();
} }
else else
@ -141,8 +138,8 @@ void CDplusProtocol::Task(void)
// find client // find client
CClients *clients = g_Reflector.GetClients(); CClients *clients = g_Reflector.GetClients();
CClient *client = clients->FindClient(Ip, PROTOCOL_DPLUS); std::shared_ptr<CClient>client = clients->FindClient(Ip, PROTOCOL_DPLUS);
if ( client != NULL ) if ( client != nullptr )
{ {
// remove it // remove it
clients->RemoveClient(client); clients->RemoveClient(client);
@ -159,8 +156,8 @@ void CDplusProtocol::Task(void)
// find all clients with that callsign & ip and keep them alive // find all clients with that callsign & ip and keep them alive
CClients *clients = g_Reflector.GetClients(); CClients *clients = g_Reflector.GetClients();
auto it = clients->begin(); auto it = clients->begin();
CClient *client = NULL; std::shared_ptr<CClient>client = nullptr;
while ( (client = clients->FindNextClient(Ip, PROTOCOL_DPLUS, it)) != NULL ) while ( (client = clients->FindNextClient(Ip, PROTOCOL_DPLUS, it)) != nullptr )
{ {
client->Alive(); client->Alive();
} }
@ -198,7 +195,7 @@ bool CDplusProtocol::OnDvHeaderPacketIn(CDvHeaderPacket *Header, const CIp &Ip)
// find the stream // find the stream
CPacketStream *stream = GetStream(Header->GetStreamId()); CPacketStream *stream = GetStream(Header->GetStreamId());
if ( stream == NULL ) if ( stream == nullptr )
{ {
// no stream open yet, open a new one // no stream open yet, open a new one
CCallsign via(Header->GetRpt1Callsign()); CCallsign via(Header->GetRpt1Callsign());
@ -207,8 +204,8 @@ bool CDplusProtocol::OnDvHeaderPacketIn(CDvHeaderPacket *Header, const CIp &Ip)
if ( g_Reflector.IsValidModule(Header->GetRpt1Module()) ) if ( g_Reflector.IsValidModule(Header->GetRpt1Module()) )
{ {
// find this client // find this client
CClient *client = g_Reflector.GetClients()->FindClient(Ip, PROTOCOL_DPLUS); std::shared_ptr<CClient>client = g_Reflector.GetClients()->FindClient(Ip, PROTOCOL_DPLUS);
if ( client != NULL ) if ( client != nullptr )
{ {
// now we know if it's a dextra dongle or a genuine dplus node // now we know if it's a dextra dongle or a genuine dplus node
if ( Header->GetRpt2Callsign().HasSameCallsignWithWildcard(CCallsign("XRF*")) ) if ( Header->GetRpt2Callsign().HasSameCallsignWithWildcard(CCallsign("XRF*")) )
@ -223,7 +220,7 @@ bool CDplusProtocol::OnDvHeaderPacketIn(CDvHeaderPacket *Header, const CIp &Ip)
// get client callsign // get client callsign
via = client->GetCallsign(); via = client->GetCallsign();
// and try to open the stream // 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 // keep the handle
m_Streams.push_back(stream); m_Streams.push_back(stream);
@ -293,8 +290,8 @@ void CDplusProtocol::HandleQueue(void)
// it's client who decide which stream he's interrrested in // it's client who decide which stream he's interrrested in
CClients *clients = g_Reflector.GetClients(); CClients *clients = g_Reflector.GetClients();
auto it = clients->begin(); auto it = clients->begin();
CClient *client = NULL; std::shared_ptr<CClient>client = nullptr;
while ( (client = clients->FindNextClient(PROTOCOL_DPLUS, it)) != NULL ) while ( (client = clients->FindNextClient(PROTOCOL_DPLUS, it)) != nullptr )
{ {
// is this client busy ? // is this client busy ?
if ( !client->IsAMaster() ) if ( !client->IsAMaster() )
@ -305,7 +302,7 @@ void CDplusProtocol::HandleQueue(void)
if ( packet->IsDvHeader() ) if ( packet->IsDvHeader() )
{ {
// sending header in Dplus is client specific // sending header in Dplus is client specific
SendDvHeader((CDvHeaderPacket *)packet, (CDplusClient *)client); SendDvHeader((CDvHeaderPacket *)packet, (CDplusClient *)client.get());
} }
else if ( packet->IsDvFrame() ) else if ( packet->IsDvFrame() )
{ {
@ -318,7 +315,7 @@ void CDplusProtocol::HandleQueue(void)
// yes, clone it // yes, clone it
CDvHeaderPacket packet2(m_StreamsCache[iModId].m_dvHeader); CDvHeaderPacket packet2(m_StreamsCache[iModId].m_dvHeader);
// and send it // and send it
SendDvHeader(&packet2, (CDplusClient *)client); SendDvHeader(&packet2, (CDplusClient *)client.get());
} }
} }
else else
@ -387,8 +384,8 @@ void CDplusProtocol::HandleKeepalives(void)
// iterate on clients // iterate on clients
CClients *clients = g_Reflector.GetClients(); CClients *clients = g_Reflector.GetClients();
auto it = clients->begin(); auto it = clients->begin();
CClient *client = NULL; std::shared_ptr<CClient>client = nullptr;
while ( (client = clients->FindNextClient(PROTOCOL_DPLUS, it)) != NULL ) while ( (client = clients->FindNextClient(PROTOCOL_DPLUS, it)) != nullptr )
{ {
// send keepalive // send keepalive
//std::cout << "Sending DPlus packet @ " << client->GetIp() << std::endl; //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 *CDplusProtocol::IsValidDvHeaderPacket(const CBuffer &Buffer)
{ {
CDvHeaderPacket *header = NULL; CDvHeaderPacket *header = nullptr;
if ( (Buffer.size() == 58) && if ( (Buffer.size() == 58) &&
(Buffer.data()[0] == 0x3A) && (Buffer.data()[1] == 0x80) && (Buffer.data()[0] == 0x3A) && (Buffer.data()[1] == 0x80) &&
@ -466,7 +463,7 @@ CDvHeaderPacket *CDplusProtocol::IsValidDvHeaderPacket(const CBuffer &Buffer)
if ( !header->IsValid() ) if ( !header->IsValid() )
{ {
delete header; delete header;
header = NULL; header = nullptr;
} }
} }
return header; return header;
@ -474,7 +471,7 @@ CDvHeaderPacket *CDplusProtocol::IsValidDvHeaderPacket(const CBuffer &Buffer)
CDvFramePacket *CDplusProtocol::IsValidDvFramePacket(const CBuffer &Buffer) CDvFramePacket *CDplusProtocol::IsValidDvFramePacket(const CBuffer &Buffer)
{ {
CDvFramePacket *dvframe = NULL; CDvFramePacket *dvframe = nullptr;
if ( (Buffer.size() == 29) && if ( (Buffer.size() == 29) &&
(Buffer.data()[0] == 0x1D) && (Buffer.data()[1] == 0x80) && (Buffer.data()[0] == 0x1D) && (Buffer.data()[1] == 0x80) &&
@ -488,7 +485,7 @@ CDvFramePacket *CDplusProtocol::IsValidDvFramePacket(const CBuffer &Buffer)
if ( !dvframe->IsValid() ) if ( !dvframe->IsValid() )
{ {
delete dvframe; delete dvframe;
dvframe = NULL; dvframe = nullptr;
} }
} }
return dvframe; return dvframe;
@ -496,7 +493,7 @@ CDvFramePacket *CDplusProtocol::IsValidDvFramePacket(const CBuffer &Buffer)
CDvLastFramePacket *CDplusProtocol::IsValidDvLastFramePacket(const CBuffer &Buffer) CDvLastFramePacket *CDplusProtocol::IsValidDvLastFramePacket(const CBuffer &Buffer)
{ {
CDvLastFramePacket *dvframe = NULL; CDvLastFramePacket *dvframe = nullptr;
if ( (Buffer.size() == 32) && if ( (Buffer.size() == 32) &&
(Buffer.Compare((uint8 *)"DSVT", 2, 4) == 0) && (Buffer.Compare((uint8 *)"DSVT", 2, 4) == 0) &&
@ -510,7 +507,7 @@ CDvLastFramePacket *CDplusProtocol::IsValidDvLastFramePacket(const CBuffer &Buff
if ( !dvframe->IsValid() ) if ( !dvframe->IsValid() )
{ {
delete dvframe; delete dvframe;
dvframe = NULL; dvframe = nullptr;
} }
} }
return dvframe; return dvframe;

@ -111,7 +111,7 @@ const uint8 *CDvFramePacket::GetAmbe(uint8 uiCodec) const
#ifndef NO_XLX #ifndef NO_XLX
case CODEC_AMBE2PLUS: return m_uiAmbePlus; case CODEC_AMBE2PLUS: return m_uiAmbePlus;
#endif #endif
default: return NULL; default: return nullptr;
} }
} }

@ -96,25 +96,25 @@ bool CG3Protocol::Init(void)
void CG3Protocol::Close(void) void CG3Protocol::Close(void)
{ {
if (m_pPresenceThread != NULL) if (m_pPresenceThread != nullptr)
{ {
m_pPresenceThread->join(); m_pPresenceThread->join();
delete m_pPresenceThread; delete m_pPresenceThread;
m_pPresenceThread = NULL; m_pPresenceThread = nullptr;
} }
if (m_pConfigThread != NULL) if (m_pConfigThread != nullptr)
{ {
m_pConfigThread->join(); m_pConfigThread->join();
delete m_pConfigThread; delete m_pConfigThread;
m_pConfigThread = NULL; m_pConfigThread = nullptr;
} }
if (m_pIcmpThread != NULL) if (m_pIcmpThread != nullptr)
{ {
m_pIcmpThread->join(); m_pIcmpThread->join();
delete m_pIcmpThread; delete m_pIcmpThread;
m_pIcmpThread = NULL; m_pIcmpThread = nullptr;
} }
} }
@ -188,8 +188,8 @@ void CG3Protocol::PresenceTask(void)
CClients *clients = g_Reflector.GetClients(); CClients *clients = g_Reflector.GetClients();
auto it = clients->begin(); auto it = clients->begin();
CClient *extant = NULL; std::shared_ptr<CClient>extant = nullptr;
while ( (extant = clients->FindNextClient(PROTOCOL_G3, it)) != NULL ) while ( (extant = clients->FindNextClient(PROTOCOL_G3, it)) != nullptr )
{ {
CIp ClIp = extant->GetIp(); CIp ClIp = extant->GetIp();
if (ClIp.GetAddr() == Ip.GetAddr()) if (ClIp.GetAddr() == Ip.GetAddr())
@ -198,12 +198,12 @@ void CG3Protocol::PresenceTask(void)
} }
} }
if (extant == NULL) if (extant == nullptr)
{ {
it = clients->begin(); it = clients->begin();
// do we already have a client with the same call (IP changed)? // 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)) if (extant->GetCallsign().HasSameCallsign(Terminal))
@ -363,8 +363,8 @@ void CG3Protocol::IcmpTask(void)
{ {
CClients *clients = g_Reflector.GetClients(); CClients *clients = g_Reflector.GetClients();
auto it = clients->begin(); auto it = clients->begin();
CClient *client = NULL; std::shared_ptr<CClient>client = nullptr;
while ( (client = clients->FindNextClient(PROTOCOL_G3, it)) != NULL ) while ( (client = clients->FindNextClient(PROTOCOL_G3, it)) != nullptr )
{ {
CIp ClientIp = client->GetIp(); CIp ClientIp = client->GetIp();
if (ClientIp.GetAddr() == Ip.GetAddr()) if (ClientIp.GetAddr() == Ip.GetAddr())
@ -396,11 +396,11 @@ void CG3Protocol::Task(void)
if ( m_Socket4.Receive(Buffer, Ip, 20) ) if ( m_Socket4.Receive(Buffer, Ip, 20) )
{ {
CIp ClIp; CIp ClIp;
CIp *BaseIp = NULL; CIp *BaseIp = nullptr;
CClients *clients = g_Reflector.GetClients(); CClients *clients = g_Reflector.GetClients();
auto it = clients->begin(); auto it = clients->begin();
CClient *client = NULL; std::shared_ptr<CClient>client = nullptr;
while ( (client = clients->FindNextClient(PROTOCOL_G3, it)) != NULL ) while ( (client = clients->FindNextClient(PROTOCOL_G3, it)) != nullptr )
{ {
ClIp = client->GetIp(); ClIp = client->GetIp();
if (ClIp.GetAddr() == Ip.GetAddr()) if (ClIp.GetAddr() == Ip.GetAddr())
@ -415,17 +415,17 @@ void CG3Protocol::Task(void)
} }
g_Reflector.ReleaseClients(); g_Reflector.ReleaseClients();
if (BaseIp != NULL) if (BaseIp != nullptr)
{ {
// crack the packet // crack the packet
if ( (Frame = IsValidDvFramePacket(Buffer)) != NULL ) if ( (Frame = IsValidDvFramePacket(Buffer)) != nullptr )
{ {
//std::cout << "Terminal DV frame" << std::endl; //std::cout << "Terminal DV frame" << std::endl;
// handle it // handle it
OnDvFramePacketIn(Frame, BaseIp); OnDvFramePacketIn(Frame, BaseIp);
} }
else if ( (Header = IsValidDvHeaderPacket(Buffer)) != NULL ) else if ( (Header = IsValidDvHeaderPacket(Buffer)) != nullptr )
{ {
//std::cout << "Terminal DV header" << std::endl; //std::cout << "Terminal DV header" << std::endl;
@ -440,7 +440,7 @@ void CG3Protocol::Task(void)
delete Header; delete Header;
} }
} }
else if ( (LastFrame = IsValidDvLastFramePacket(Buffer)) != NULL ) else if ( (LastFrame = IsValidDvLastFramePacket(Buffer)) != nullptr )
{ {
//std::cout << "Terminal DV last frame" << std::endl; //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 // and push it to all our clients linked to the module and who are not streaming in
CClients *clients = g_Reflector.GetClients(); CClients *clients = g_Reflector.GetClients();
auto it = clients->begin(); auto it = clients->begin();
CClient *client = NULL; std::shared_ptr<CClient>client = nullptr;
while ( (client = clients->FindNextClient(PROTOCOL_G3, it)) != NULL ) while ( (client = clients->FindNextClient(PROTOCOL_G3, it)) != nullptr )
{ {
// is this client busy ? // is this client busy ?
if ( !client->IsAMaster() && (client->GetReflectorModule() == packet->GetModuleId()) ) if ( !client->IsAMaster() && (client->GetReflectorModule() == packet->GetModuleId()) )
@ -537,8 +537,8 @@ void CG3Protocol::HandleKeepalives(void)
// iterate on clients // iterate on clients
CClients *clients = g_Reflector.GetClients(); CClients *clients = g_Reflector.GetClients();
auto it = clients->begin(); auto it = clients->begin();
CClient *client = NULL; std::shared_ptr<CClient>client = nullptr;
while ( (client = clients->FindNextClient(PROTOCOL_G3, it)) != NULL ) while ( (client = clients->FindNextClient(PROTOCOL_G3, it)) != nullptr )
{ {
if (!client->IsAlive()) if (!client->IsAlive())
{ {
@ -563,7 +563,7 @@ bool CG3Protocol::OnDvHeaderPacketIn(CDvHeaderPacket *Header, const CIp &Ip)
// find the stream // find the stream
CPacketStream *stream = GetStream(Header->GetStreamId(), &Ip); CPacketStream *stream = GetStream(Header->GetStreamId(), &Ip);
if ( stream == NULL ) if ( stream == nullptr )
{ {
// no stream open yet, open a new one // no stream open yet, open a new one
CCallsign via(Header->GetRpt1Callsign()); CCallsign via(Header->GetRpt1Callsign());
@ -571,8 +571,8 @@ bool CG3Protocol::OnDvHeaderPacketIn(CDvHeaderPacket *Header, const CIp &Ip)
// find this client // find this client
CClients *clients = g_Reflector.GetClients(); CClients *clients = g_Reflector.GetClients();
auto it = clients->begin(); auto it = clients->begin();
CClient *client = NULL; std::shared_ptr<CClient>client = nullptr;
while ( (client = clients->FindNextClient(PROTOCOL_G3, it)) != NULL ) while ( (client = clients->FindNextClient(PROTOCOL_G3, it)) != nullptr )
{ {
CIp ClIp = client->GetIp(); CIp ClIp = client->GetIp();
if (ClIp.GetAddr() == Ip.GetAddr()) 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 // move it to the proper module
@ -599,7 +599,7 @@ bool CG3Protocol::OnDvHeaderPacketIn(CDvHeaderPacket *Header, const CIp &Ip)
// drop if invalid module // drop if invalid module
delete Header; delete Header;
g_Reflector.ReleaseClients(); g_Reflector.ReleaseClients();
return NULL; return nullptr;
} }
} }
@ -607,7 +607,7 @@ bool CG3Protocol::OnDvHeaderPacketIn(CDvHeaderPacket *Header, const CIp &Ip)
via = client->GetCallsign(); via = client->GetCallsign();
// and try to open the stream // 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 // keep the handle
m_Streams.push_back(stream); m_Streams.push_back(stream);
@ -653,7 +653,7 @@ bool CG3Protocol::OnDvHeaderPacketIn(CDvHeaderPacket *Header, const CIp &Ip)
CDvHeaderPacket *CG3Protocol::IsValidDvHeaderPacket(const CBuffer &Buffer) CDvHeaderPacket *CG3Protocol::IsValidDvHeaderPacket(const CBuffer &Buffer)
{ {
CDvHeaderPacket *header = NULL; CDvHeaderPacket *header = nullptr;
if ( (Buffer.size() == 56) && (Buffer.Compare((uint8 *)"DSVT", 4) == 0) && if ( (Buffer.size() == 56) && (Buffer.Compare((uint8 *)"DSVT", 4) == 0) &&
(Buffer.data()[4] == 0x10) && (Buffer.data()[8] == 0x20) ) (Buffer.data()[4] == 0x10) && (Buffer.data()[8] == 0x20) )
@ -665,7 +665,7 @@ CDvHeaderPacket *CG3Protocol::IsValidDvHeaderPacket(const CBuffer &Buffer)
if ( !header->IsValid() ) if ( !header->IsValid() )
{ {
delete header; delete header;
header = NULL; header = nullptr;
} }
} }
return header; return header;
@ -673,7 +673,7 @@ CDvHeaderPacket *CG3Protocol::IsValidDvHeaderPacket(const CBuffer &Buffer)
CDvFramePacket *CG3Protocol::IsValidDvFramePacket(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) && if ( (Buffer.size() == 27) && (Buffer.Compare((uint8 *)"DSVT", 4) == 0) &&
(Buffer.data()[4] == 0x20) && (Buffer.data()[8] == 0x20) && (Buffer.data()[4] == 0x20) && (Buffer.data()[8] == 0x20) &&
@ -686,7 +686,7 @@ CDvFramePacket *CG3Protocol::IsValidDvFramePacket(const CBuffer &Buffer)
if ( !dvframe->IsValid() ) if ( !dvframe->IsValid() )
{ {
delete dvframe; delete dvframe;
dvframe = NULL; dvframe = nullptr;
} }
} }
return dvframe; return dvframe;
@ -694,7 +694,7 @@ CDvFramePacket *CG3Protocol::IsValidDvFramePacket(const CBuffer &Buffer)
CDvLastFramePacket *CG3Protocol::IsValidDvLastFramePacket(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) && if ( (Buffer.size() == 27) && (Buffer.Compare((uint8 *)"DSVT", 4) == 0) &&
(Buffer.data()[4] == 0x20) && (Buffer.data()[8] == 0x20) && (Buffer.data()[4] == 0x20) && (Buffer.data()[8] == 0x20) &&
@ -707,7 +707,7 @@ CDvLastFramePacket *CG3Protocol::IsValidDvLastFramePacket(const CBuffer &Buffer)
if ( !dvframe->IsValid() ) if ( !dvframe->IsValid() )
{ {
delete dvframe; delete dvframe;
dvframe = NULL; dvframe = nullptr;
} }
} }
return dvframe; return dvframe;
@ -787,8 +787,8 @@ void CG3Protocol::NeedReload(void)
// we have new options - iterate on clients for potential removal // we have new options - iterate on clients for potential removal
CClients *clients = g_Reflector.GetClients(); CClients *clients = g_Reflector.GetClients();
auto it = clients->begin(); auto it = clients->begin();
CClient *client = NULL; std::shared_ptr<CClient>client = nullptr;
while ( (client = clients->FindNextClient(PROTOCOL_G3, it)) != NULL ) while ( (client = clients->FindNextClient(PROTOCOL_G3, it)) != nullptr )
{ {
char module = client->GetReflectorModule(); char module = client->GetReflectorModule();
if (!strchr(m_Modules.c_str(), module) && !strchr(m_Modules.c_str(), '*')) 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 ((::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) if (::strncmp(szt, "address", 7) == 0)
{ {

@ -37,7 +37,7 @@ CGateKeeper g_GateKeeper;
CGateKeeper::CGateKeeper() CGateKeeper::CGateKeeper()
{ {
keep_running = true; keep_running = true;
m_pThread = NULL; m_pThread = nullptr;
} }
//////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////
@ -47,11 +47,11 @@ CGateKeeper::~CGateKeeper()
{ {
// kill threads // kill threads
keep_running = false; keep_running = false;
if ( m_pThread != NULL ) if ( m_pThread != nullptr )
{ {
m_pThread->join(); m_pThread->join();
delete m_pThread; delete m_pThread;
m_pThread = NULL; m_pThread = nullptr;
} }
} }
@ -79,11 +79,11 @@ bool CGateKeeper::Init(void)
void CGateKeeper::Close(void) void CGateKeeper::Close(void)
{ {
keep_running = false; keep_running = false;
if ( m_pThread != NULL ) if ( m_pThread != nullptr )
{ {
m_pThread->join(); m_pThread->join();
delete m_pThread; delete m_pThread;
m_pThread = NULL; m_pThread = nullptr;
} }
} }

@ -48,7 +48,7 @@ public:
void Close(void); void Close(void);
// authorizations // 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; bool MayTransmit(const CCallsign &, const CIp &, int = PROTOCOL_ANY, char = ' ') const;
// peer list handeling // peer list handeling

@ -237,7 +237,7 @@ unsigned int CGolay2087::getSyndrome1987(unsigned int pattern)
unsigned char CGolay2087::decode(const unsigned char* data) 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 code = (data[0U] << 11) + (data[1U] << 3) + (data[2U] >> 5);
unsigned int syndrome = getSyndrome1987(code); unsigned int syndrome = getSyndrome1987(code);
@ -251,7 +251,7 @@ unsigned char CGolay2087::decode(const unsigned char* data)
void CGolay2087::encode(unsigned char* data) void CGolay2087::encode(unsigned char* data)
{ {
assert(data != NULL); assert(data != nullptr);
unsigned int value = data[0U]; unsigned int value = data[0U];

@ -1096,7 +1096,7 @@ unsigned int CGolay24128::decode24128(unsigned int code)
unsigned int CGolay24128::decode24128(unsigned char* bytes) unsigned int CGolay24128::decode24128(unsigned char* bytes)
{ {
assert(bytes != NULL); assert(bytes != nullptr);
unsigned int code = bytes[0U]; unsigned int code = bytes[0U];
code <<= 8; code <<= 8;

@ -24,7 +24,7 @@
// Hamming (15,11,3) check a boolean data array // Hamming (15,11,3) check a boolean data array
bool CHamming::decode15113_1(bool* d) bool CHamming::decode15113_1(bool* d)
{ {
assert(d != NULL); assert(d != nullptr);
// Calculate the parity it should have // Calculate the parity it should have
bool c0 = d[0] ^ d[1] ^ d[2] ^ d[3] ^ d[4] ^ d[5] ^ d[6]; bool c0 = d[0] ^ d[1] ^ d[2] ^ d[3] ^ d[4] ^ d[5] ^ d[6];
@ -66,7 +66,7 @@ bool CHamming::decode15113_1(bool* d)
void CHamming::encode15113_1(bool* d) void CHamming::encode15113_1(bool* d)
{ {
assert(d != NULL); assert(d != nullptr);
// Calculate the checksum this row should have // Calculate the checksum this row should have
d[11] = d[0] ^ d[1] ^ d[2] ^ d[3] ^ d[4] ^ d[5] ^ d[6]; d[11] = d[0] ^ d[1] ^ d[2] ^ d[3] ^ d[4] ^ d[5] ^ d[6];
@ -78,7 +78,7 @@ void CHamming::encode15113_1(bool* d)
// Hamming (15,11,3) check a boolean data array // Hamming (15,11,3) check a boolean data array
bool CHamming::decode15113_2(bool* d) bool CHamming::decode15113_2(bool* d)
{ {
assert(d != NULL); assert(d != nullptr);
// Calculate the checksum this row should have // Calculate the checksum this row should have
bool c0 = d[0] ^ d[1] ^ d[2] ^ d[3] ^ d[5] ^ d[7] ^ d[8]; bool c0 = d[0] ^ d[1] ^ d[2] ^ d[3] ^ d[5] ^ d[7] ^ d[8];
@ -119,7 +119,7 @@ bool CHamming::decode15113_2(bool* d)
void CHamming::encode15113_2(bool* d) void CHamming::encode15113_2(bool* d)
{ {
assert(d != NULL); assert(d != nullptr);
// Calculate the checksum this row should have // Calculate the checksum this row should have
d[11] = d[0] ^ d[1] ^ d[2] ^ d[3] ^ d[5] ^ d[7] ^ d[8]; d[11] = d[0] ^ d[1] ^ d[2] ^ d[3] ^ d[5] ^ d[7] ^ d[8];
@ -131,7 +131,7 @@ void CHamming::encode15113_2(bool* d)
// Hamming (13,9,3) check a boolean data array // Hamming (13,9,3) check a boolean data array
bool CHamming::decode1393(bool* d) bool CHamming::decode1393(bool* d)
{ {
assert(d != NULL); assert(d != nullptr);
// Calculate the checksum this column should have // Calculate the checksum this column should have
bool c0 = d[0] ^ d[1] ^ d[3] ^ d[5] ^ d[6]; bool c0 = d[0] ^ d[1] ^ d[3] ^ d[5] ^ d[6];
@ -170,7 +170,7 @@ bool CHamming::decode1393(bool* d)
void CHamming::encode1393(bool* d) void CHamming::encode1393(bool* d)
{ {
assert(d != NULL); assert(d != nullptr);
// Calculate the checksum this column should have // Calculate the checksum this column should have
d[9] = d[0] ^ d[1] ^ d[3] ^ d[5] ^ d[6]; d[9] = d[0] ^ d[1] ^ d[3] ^ d[5] ^ d[6];
@ -182,7 +182,7 @@ void CHamming::encode1393(bool* d)
// Hamming (10,6,3) check a boolean data array // Hamming (10,6,3) check a boolean data array
bool CHamming::decode1063(bool* d) bool CHamming::decode1063(bool* d)
{ {
assert(d != NULL); assert(d != nullptr);
// Calculate the checksum this column should have // Calculate the checksum this column should have
bool c0 = d[0] ^ d[1] ^ d[2] ^ d[5]; bool c0 = d[0] ^ d[1] ^ d[2] ^ d[5];
@ -218,7 +218,7 @@ bool CHamming::decode1063(bool* d)
void CHamming::encode1063(bool* d) void CHamming::encode1063(bool* d)
{ {
assert(d != NULL); assert(d != nullptr);
// Calculate the checksum this column should have // Calculate the checksum this column should have
d[6] = d[0] ^ d[1] ^ d[2] ^ d[5]; d[6] = d[0] ^ d[1] ^ d[2] ^ d[5];
@ -230,7 +230,7 @@ void CHamming::encode1063(bool* d)
// A Hamming (16,11,4) Check // A Hamming (16,11,4) Check
bool CHamming::decode16114(bool* d) bool CHamming::decode16114(bool* d)
{ {
assert(d != NULL); assert(d != nullptr);
// Calculate the checksum this column should have // Calculate the checksum this column should have
bool c0 = d[0] ^ d[1] ^ d[2] ^ d[3] ^ d[5] ^ d[7] ^ d[8]; bool c0 = d[0] ^ d[1] ^ d[2] ^ d[3] ^ d[5] ^ d[7] ^ d[8];
@ -278,7 +278,7 @@ bool CHamming::decode16114(bool* d)
void CHamming::encode16114(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[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[12] = d[1] ^ d[2] ^ d[3] ^ d[4] ^ d[6] ^ d[8] ^ d[9];
@ -290,7 +290,7 @@ void CHamming::encode16114(bool* d)
// A Hamming (17,12,3) Check // A Hamming (17,12,3) Check
bool CHamming::decode17123(bool* d) bool CHamming::decode17123(bool* d)
{ {
assert(d != NULL); assert(d != nullptr);
// Calculate the checksum this column should have // Calculate the checksum this column should have
bool c0 = d[0] ^ d[1] ^ d[2] ^ d[3] ^ d[6] ^ d[7] ^ d[9]; bool c0 = d[0] ^ d[1] ^ d[2] ^ d[3] ^ d[6] ^ d[7] ^ d[9];
@ -339,7 +339,7 @@ bool CHamming::decode17123(bool* d)
void CHamming::encode17123(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[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[13] = d[0] ^ d[1] ^ d[2] ^ d[3] ^ d[4] ^ d[7] ^ d[8] ^ d[10];

@ -39,7 +39,7 @@ CIp::CIp(const char *address, int family, int type, uint16_t port) : is_set(true
bzero(&hints, sizeof(struct addrinfo)); bzero(&hints, sizeof(struct addrinfo));
hints.ai_family = family; hints.ai_family = family;
hints.ai_socktype = type; 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); memcpy(&addr, result->ai_addr, result->ai_addrlen);
addr.ss_family = result->ai_family; addr.ss_family = result->ai_family;
freeaddrinfo(result); freeaddrinfo(result);

@ -36,10 +36,10 @@ public:
// constructors // constructors
CIp(); CIp();
CIp(const char *address, int family = AF_UNSPEC, int type = SOCK_DGRAM, uint16_t port = 0U); 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 // 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 // comparison operators
bool operator==(const CIp &rhs) const; bool operator==(const CIp &rhs) const;

@ -33,16 +33,16 @@ CPacketStream::CPacketStream()
m_bOpen = false; m_bOpen = false;
m_uiStreamId = 0; m_uiStreamId = 0;
m_uiPacketCntr = 0; m_uiPacketCntr = 0;
m_OwnerClient = NULL; m_OwnerClient = nullptr;
#ifdef TRANSCODER_IP #ifdef TRANSCODER_IP
m_CodecStream = NULL; m_CodecStream = nullptr;
#endif #endif
} }
//////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////
// open / close // open / close
bool CPacketStream::Open(const CDvHeaderPacket &DvHeader, CClient *client) bool CPacketStream::Open(const CDvHeaderPacket &DvHeader, std::shared_ptr<CClient>client)
{ {
bool ok = false; bool ok = false;
@ -72,10 +72,10 @@ void CPacketStream::Close(void)
// update status // update status
m_bOpen = false; m_bOpen = false;
m_uiStreamId = 0; m_uiStreamId = 0;
m_OwnerClient = NULL; m_OwnerClient = nullptr;
#ifdef TRANSCODER_IP #ifdef TRANSCODER_IP
g_Transcoder.ReleaseStream(m_CodecStream); g_Transcoder.ReleaseStream(m_CodecStream);
m_CodecStream = NULL; m_CodecStream = nullptr;
#endif #endif
} }
@ -89,7 +89,7 @@ void CPacketStream::Push(CPacket *Packet)
Packet->UpdatePids(m_uiPacketCntr++); Packet->UpdatePids(m_uiPacketCntr++);
// transcoder avaliable ? // transcoder avaliable ?
#ifdef TRANSCODER_IP #ifdef TRANSCODER_IP
if ( m_CodecStream != NULL ) if ( m_CodecStream != nullptr )
{ {
// todo: verify no possibilty of double lock here // todo: verify no possibilty of double lock here
m_CodecStream->Lock(); m_CodecStream->Lock();
@ -123,7 +123,7 @@ bool CPacketStream::IsEmpty(void) const
#ifdef TRANSCODER_IP #ifdef TRANSCODER_IP
bool bEmpty = empty(); bool bEmpty = empty();
// also check no packets still in Codec stream's queue // also check no packets still in Codec stream's queue
if ( bEmpty && (m_CodecStream != NULL) ) if ( bEmpty && (m_CodecStream != nullptr) )
{ {
bEmpty = m_CodecStream->IsEmpty(); bEmpty = m_CodecStream->IsEmpty();
} }
@ -140,9 +140,9 @@ bool CPacketStream::IsEmpty(void) const
const CIp *CPacketStream::GetOwnerIp(void) const CIp *CPacketStream::GetOwnerIp(void)
{ {
if ( m_OwnerClient != NULL ) if ( m_OwnerClient != nullptr )
{ {
return &(m_OwnerClient->GetIp()); return &(m_OwnerClient->GetIp());
} }
return NULL; return nullptr;
} }

@ -48,7 +48,7 @@ public:
virtual ~CPacketStream() {} virtual ~CPacketStream() {}
// open / close // open / close
bool Open(const CDvHeaderPacket &, CClient *); bool Open(const CDvHeaderPacket &, std::shared_ptr<CClient>);
void Close(void); void Close(void);
// push & pop // push & pop
@ -57,7 +57,7 @@ public:
bool IsEmpty(void) const; bool IsEmpty(void) const;
// get // get
CClient *GetOwnerClient(void) { return m_OwnerClient; } std::shared_ptr<CClient> GetOwnerClient(void) { return m_OwnerClient; }
const CIp *GetOwnerIp(void); const CIp *GetOwnerIp(void);
bool IsExpired(void) const { return (m_LastPacketTime.DurationSinceNow() > STREAM_TIMEOUT); } bool IsExpired(void) const { return (m_LastPacketTime.DurationSinceNow() > STREAM_TIMEOUT); }
bool IsOpen(void) const { return m_bOpen; } bool IsOpen(void) const { return m_bOpen; }
@ -69,7 +69,7 @@ protected:
bool m_bOpen; bool m_bOpen;
uint16 m_uiStreamId; uint16 m_uiStreamId;
uint32 m_uiPacketCntr; uint32 m_uiPacketCntr;
CClient *m_OwnerClient; std::shared_ptr<CClient> m_OwnerClient;
CTimePoint m_LastPacketTime; CTimePoint m_LastPacketTime;
CDvHeaderPacket m_DvHeader; CDvHeaderPacket m_DvHeader;
#ifdef TRANSCODER_IP #ifdef TRANSCODER_IP

@ -36,8 +36,8 @@
CPeer::CPeer() CPeer::CPeer()
{ {
::memset(m_ReflectorModules, 0, sizeof(m_ReflectorModules)); ::memset(m_ReflectorModules, 0, sizeof(m_ReflectorModules));
m_ConnectTime = std::time(NULL); m_ConnectTime = std::time(nullptr);
m_LastHeardTime = std::time(NULL); m_LastHeardTime = std::time(nullptr);
} }
CPeer::CPeer(const CCallsign &callsign, const CIp &ip, const char *modules, const CVersion &version) 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); ::strncpy(m_ReflectorModules, modules, sizeof(m_ReflectorModules)-1);
m_Version = version; m_Version = version;
m_LastKeepaliveTime.Now(); m_LastKeepaliveTime.Now();
m_ConnectTime = std::time(NULL); m_ConnectTime = std::time(nullptr);
m_LastHeardTime = std::time(NULL); m_LastHeardTime = std::time(nullptr);
} }
CPeer::CPeer(const CPeer &peer) CPeer::CPeer(const CPeer &peer)
@ -68,10 +68,6 @@ CPeer::CPeer(const CPeer &peer)
CPeer::~CPeer() CPeer::~CPeer()
{ {
for ( auto it=begin(); it!=end(); it++ )
{
delete *it;
}
m_Clients.clear(); m_Clients.clear();
} }

@ -68,17 +68,17 @@ public:
virtual bool IsAMaster(void) const; virtual bool IsAMaster(void) const;
virtual void Alive(void); virtual void Alive(void);
virtual bool IsAlive(void) const { return false; } 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 // clients access
int GetNbClients(void) const { return (int)m_Clients.size(); } int GetNbClients(void) const { return (int)m_Clients.size(); }
void ClearClients(void) { m_Clients.clear(); } void ClearClients(void) { m_Clients.clear(); }
// pass-thru // pass-thru
std::list<CClient *>::iterator begin() { return m_Clients.begin(); } std::list<std::shared_ptr<CClient>>::iterator begin() { return m_Clients.begin(); }
std::list<CClient *>::iterator end() { return m_Clients.end(); } std::list<std::shared_ptr<CClient>>::iterator end() { return m_Clients.end(); }
std::list<CClient *>::const_iterator cbegin() const { return m_Clients.cbegin(); } std::list<std::shared_ptr<CClient>>::const_iterator cbegin() const { return m_Clients.cbegin(); }
std::list<CClient *>::const_iterator cend() const { return m_Clients.cend(); } std::list<std::shared_ptr<CClient>>::const_iterator cend() const { return m_Clients.cend(); }
// reporting // reporting
virtual void WriteXml(std::ofstream &); virtual void WriteXml(std::ofstream &);
@ -90,7 +90,7 @@ protected:
CIp m_Ip; CIp m_Ip;
char m_ReflectorModules[27]; char m_ReflectorModules[27];
CVersion m_Version; CVersion m_Version;
std::list<CClient *> m_Clients; std::list<std::shared_ptr<CClient>> m_Clients;
// status // status
CTimePoint m_LastKeepaliveTime; CTimePoint m_LastKeepaliveTime;

@ -53,15 +53,15 @@ bool CPeerCallsignList::LoadFromFile(const char *filename)
if ( (::strlen(szt) > 0) && (szt[0] != '#') ) if ( (::strlen(szt) > 0) && (szt[0] != '#') )
{ {
// 1st token is callsign // 1st token is callsign
if ( (szt = ::strtok(szt, " ,\t")) != NULL ) if ( (szt = ::strtok(szt, " ,\t")) != nullptr )
{ {
CCallsign callsign(szt); CCallsign callsign(szt);
// 2nd token is ip // 2nd token is ip
char *szip; char *szip;
if ( (szip = ::strtok(NULL, " ,\t")) != NULL ) if ( (szip = ::strtok(nullptr, " ,\t")) != nullptr )
{ {
// 3rd token is modules list // 3rd token is modules list
if ( (szt = ::strtok(NULL, " ,\t")) != NULL ) if ( (szt = ::strtok(nullptr, " ,\t")) != nullptr )
{ {
// and load // and load
m_Callsigns.push_back(CCallsignListItem(callsign, szip, szt)); m_Callsigns.push_back(CCallsignListItem(callsign, szip, szt));

@ -40,8 +40,6 @@ CPeers::CPeers() {}
CPeers::~CPeers() CPeers::~CPeers()
{ {
m_Mutex.lock(); m_Mutex.lock();
for (auto it=begin(); it!=end(); it++ )
delete *it;
m_Peers.clear(); m_Peers.clear();
m_Mutex.unlock(); m_Mutex.unlock();
} }
@ -49,7 +47,7 @@ CPeers::~CPeers()
//////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////
// manage peers // manage peers
void CPeers::AddPeer(CPeer *peer) void CPeers::AddPeer(std::shared_ptr<CPeer>peer)
{ {
// first check if peer already exists // first check if peer already exists
for ( auto it=begin(); it!=end(); it++ ) for ( auto it=begin(); it!=end(); it++ )
@ -60,7 +58,6 @@ void CPeers::AddPeer(CPeer *peer)
// on function return // on function return
{ {
// delete new one // delete new one
delete peer;
return; return;
} }
} }
@ -82,7 +79,7 @@ void CPeers::AddPeer(CPeer *peer)
g_Reflector.OnPeersChanged(); g_Reflector.OnPeersChanged();
} }
void CPeers::RemovePeer(CPeer *peer) void CPeers::RemovePeer(std::shared_ptr<CPeer>peer)
{ {
// look for the client // look for the client
for ( auto pit=begin(); pit!=end(); /*increment done in body */ ) for ( auto pit=begin(); pit!=end(); /*increment done in body */ )
@ -103,9 +100,7 @@ void CPeers::RemovePeer(CPeer *peer)
g_Reflector.ReleaseClients(); g_Reflector.ReleaseClients();
// remove it // remove it
std::cout << "Peer " << (*pit)->GetCallsign() << " at " << (*pit)->GetIp() std::cout << "Peer " << (*pit)->GetCallsign() << " at " << (*pit)->GetIp() << " removed" << std::endl;
<< " removed" << std::endl;
delete *pit;
pit = m_Peers.erase(pit); pit = m_Peers.erase(pit);
// notify // notify
g_Reflector.OnPeersChanged(); g_Reflector.OnPeersChanged();
@ -120,7 +115,7 @@ void CPeers::RemovePeer(CPeer *peer)
//////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////
// find peers // find peers
CPeer *CPeers::FindPeer(const CIp &Ip, int Protocol) std::shared_ptr<CPeer>CPeers::FindPeer(const CIp &Ip, int Protocol)
{ {
for ( auto it=begin(); it!=end(); it++ ) 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_ptr<CPeer>CPeers::FindPeer(const CCallsign &Callsign, const CIp &Ip, int Protocol)
{ {
for ( auto it=begin(); it!=end(); it++ ) 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_ptr<CPeer>CPeers::FindPeer(const CCallsign &Callsign, int Protocol)
{ {
for ( auto it=begin(); it!=end(); it++ ) 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 // iterate on peers
CPeer *CPeers::FindNextPeer(int Protocol, std::list<CPeer *>::iterator &it) std::shared_ptr<CPeer>CPeers::FindNextPeer(int Protocol, std::list<std::shared_ptr<CPeer>>::iterator &it)
{ {
while ( it!=end() ) while ( it!=end() )
{ {
@ -176,5 +171,5 @@ CPeer *CPeers::FindNextPeer(int Protocol, std::list<CPeer *>::iterator &it)
} }
it++; it++;
} }
return NULL; return nullptr;
} }

@ -51,27 +51,27 @@ public:
// manage peers // manage peers
int GetSize(void) const { return (int)m_Peers.size(); } int GetSize(void) const { return (int)m_Peers.size(); }
void AddPeer(CPeer *); void AddPeer(std::shared_ptr<CPeer>);
void RemovePeer(CPeer *); void RemovePeer(std::shared_ptr<CPeer>);
// pass-thru // pass-thru
std::list<CPeer *>::iterator begin() { return m_Peers.begin(); } std::list<std::shared_ptr<CPeer>>::iterator begin() { return m_Peers.begin(); }
std::list<CPeer *>::iterator end() { return m_Peers.end(); } std::list<std::shared_ptr<CPeer>>::iterator end() { return m_Peers.end(); }
std::list<CPeer *>::const_iterator cbegin() const { return m_Peers.cbegin(); } std::list<std::shared_ptr<CPeer>>::const_iterator cbegin() const { return m_Peers.cbegin(); }
std::list<CPeer *>::const_iterator cend() const { return m_Peers.cend(); } std::list<std::shared_ptr<CPeer>>::const_iterator cend() const { return m_Peers.cend(); }
// find peers // find peers
CPeer *FindPeer(const CIp &, int); std::shared_ptr<CPeer>FindPeer(const CIp &, int);
CPeer *FindPeer(const CCallsign &, const CIp &, int); std::shared_ptr<CPeer>FindPeer(const CCallsign &, const CIp &, int);
CPeer *FindPeer(const CCallsign &, int); std::shared_ptr<CPeer>FindPeer(const CCallsign &, int);
// iterate on peers // iterate on peers
CPeer *FindNextPeer(int, std::list<CPeer *>::iterator &); std::shared_ptr<CPeer>FindNextPeer(int, std::list<std::shared_ptr<CPeer>>::iterator &);
protected: protected:
// data // data
std::mutex m_Mutex; std::mutex m_Mutex;
std::list<CPeer *> m_Peers; std::list<std::shared_ptr<CPeer>> m_Peers;
}; };

@ -33,7 +33,7 @@
// constructor // 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 // kill threads
keep_running = false; keep_running = false;
if ( m_pThread != NULL ) if ( m_pThread != nullptr )
{ {
m_pThread->join(); m_pThread->join();
delete m_pThread; delete m_pThread;
m_pThread = NULL; m_pThread = nullptr;
} }
// Close sockets // Close sockets
@ -108,7 +108,7 @@ bool CProtocol::Initialize(const char *type, const uint16 port, const bool has_i
// start thread; // start thread;
m_pThread = new std::thread(CProtocol::Thread, this); 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; std::cerr << "Could not start DCS thread!" << std::endl;
m_Socket4.Close(); m_Socket4.Close();
@ -131,11 +131,11 @@ void CProtocol::Thread(CProtocol *This)
void CProtocol::Close(void) void CProtocol::Close(void)
{ {
keep_running = false; keep_running = false;
if ( m_pThread != NULL ) if ( m_pThread != nullptr )
{ {
m_pThread->join(); m_pThread->join();
delete m_pThread; delete m_pThread;
m_pThread = NULL; m_pThread = nullptr;
} }
m_Socket4.Close(); m_Socket4.Close();
m_Socket6.Close(); m_Socket6.Close();
@ -176,7 +176,7 @@ void CProtocol::OnDvFramePacketIn(CDvFramePacket *Frame, const CIp *Ip)
{ {
// find the stream // find the stream
CPacketStream *stream = GetStream(Frame->GetStreamId(), Ip); 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; std::cout << "Deleting orphaned Frame with ID " << Frame->GetStreamId() << " on " << *Ip << std::endl;
delete Frame; delete Frame;
@ -195,7 +195,7 @@ void CProtocol::OnDvLastFramePacketIn(CDvLastFramePacket *Frame, const CIp *Ip)
{ {
// find the stream // find the stream
CPacketStream *stream = GetStream(Frame->GetStreamId(), Ip); 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; std::cout << "Deleting orphaned Last Frame with ID " << Frame->GetStreamId() << " on " << *Ip << std::endl;
delete Frame; delete Frame;
@ -221,8 +221,8 @@ CPacketStream *CProtocol::GetStream(uint16 uiStreamId, const CIp *Ip)
{ {
if ( (*it)->GetStreamId() == uiStreamId ) if ( (*it)->GetStreamId() == uiStreamId )
{ {
// if Ip not NULL, also check if IP match // if Ip not nullptr, also check if IP match
if ( (Ip != NULL) && ((*it)->GetOwnerIp() != NULL) ) if ( (Ip != nullptr) && ((*it)->GetOwnerIp() != nullptr) )
{ {
if ( *Ip == *((*it)->GetOwnerIp()) ) if ( *Ip == *((*it)->GetOwnerIp()) )
{ {
@ -232,7 +232,7 @@ CPacketStream *CProtocol::GetStream(uint16 uiStreamId, const CIp *Ip)
} }
} }
// done // done
return NULL; return nullptr;
} }
void CProtocol::CheckStreamsTimeout(void) void CProtocol::CheckStreamsTimeout(void)

@ -100,11 +100,11 @@ protected:
// stream helpers // stream helpers
virtual bool OnDvHeaderPacketIn(CDvHeaderPacket *, const CIp &) { return false; } virtual bool OnDvHeaderPacketIn(CDvHeaderPacket *, const CIp &) { return false; }
virtual void OnDvFramePacketIn(CDvFramePacket *, const CIp * = NULL); virtual void OnDvFramePacketIn(CDvFramePacket *, const CIp * = nullptr);
virtual void OnDvLastFramePacketIn(CDvLastFramePacket *, const CIp * = NULL); virtual void OnDvLastFramePacketIn(CDvLastFramePacket *, const CIp * = nullptr);
// stream handle helpers // stream handle helpers
CPacketStream *GetStream(uint16, const CIp * = NULL); CPacketStream *GetStream(uint16, const CIp * = nullptr);
void CheckStreamsTimeout(void); void CheckStreamsTimeout(void);
// queue helper // queue helper

@ -91,7 +91,7 @@ unsigned int CQR1676::getSyndrome1576(unsigned int pattern)
// Compute the EMB against a precomputed list of correct words // Compute the EMB against a precomputed list of correct words
void CQR1676::encode(unsigned char* data) void CQR1676::encode(unsigned char* data)
{ {
assert(data != NULL); assert(data != nullptr);
unsigned int value = (data[0U] >> 1) & 0x7FU; unsigned int value = (data[0U] >> 1) & 0x7FU;
unsigned int cksum = ENCODING_TABLE_1676[value]; unsigned int cksum = ENCODING_TABLE_1676[value];
@ -102,7 +102,7 @@ void CQR1676::encode(unsigned char* data)
unsigned char CQR1676::decode(const unsigned char* data) 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 code = (data[0U] << 7) + (data[1U] >> 1);
unsigned int syndrome = getSyndrome1576(code); unsigned int syndrome = getSyndrome1576(code);

@ -39,11 +39,11 @@
CReflector::CReflector() CReflector::CReflector()
{ {
keep_running = true; keep_running = true;
m_XmlReportThread = NULL; m_XmlReportThread = nullptr;
m_JsonReportThread = NULL; m_JsonReportThread = nullptr;
for ( int i = 0; i < NB_OF_MODULES; i++ ) for ( int i = 0; i < NB_OF_MODULES; i++ )
{ {
m_RouterThreads[i] = NULL; m_RouterThreads[i] = nullptr;
} }
#ifdef DEBUG_DUMPFILE #ifdef DEBUG_DUMPFILE
m_DebugFile.open("/Users/jeanluc/Desktop/xlxdebug.txt"); m_DebugFile.open("/Users/jeanluc/Desktop/xlxdebug.txt");
@ -56,11 +56,11 @@ CReflector::CReflector(const CCallsign &callsign)
m_DebugFile.close(); m_DebugFile.close();
#endif #endif
keep_running = true; keep_running = true;
m_XmlReportThread = NULL; m_XmlReportThread = nullptr;
m_JsonReportThread = NULL; m_JsonReportThread = nullptr;
for ( int i = 0; i < NB_OF_MODULES; i++ ) for ( int i = 0; i < NB_OF_MODULES; i++ )
{ {
m_RouterThreads[i] = NULL; m_RouterThreads[i] = nullptr;
} }
m_Callsign = callsign; m_Callsign = callsign;
} }
@ -71,19 +71,19 @@ CReflector::CReflector(const CCallsign &callsign)
CReflector::~CReflector() CReflector::~CReflector()
{ {
keep_running = false; keep_running = false;
if ( m_XmlReportThread != NULL ) if ( m_XmlReportThread != nullptr )
{ {
m_XmlReportThread->join(); m_XmlReportThread->join();
delete m_XmlReportThread; delete m_XmlReportThread;
} }
if ( m_JsonReportThread != NULL ) if ( m_JsonReportThread != nullptr )
{ {
m_JsonReportThread->join(); m_JsonReportThread->join();
delete m_JsonReportThread; delete m_JsonReportThread;
} }
for ( int i = 0; i < NB_OF_MODULES; i++ ) for ( int i = 0; i < NB_OF_MODULES; i++ )
{ {
if ( m_RouterThreads[i] != NULL ) if ( m_RouterThreads[i] != nullptr )
{ {
m_RouterThreads[i]->join(); m_RouterThreads[i]->join();
delete m_RouterThreads[i]; delete m_RouterThreads[i];
@ -145,27 +145,27 @@ void CReflector::Stop(void)
keep_running = false; keep_running = false;
// stop & delete report threads // stop & delete report threads
if ( m_XmlReportThread != NULL ) if ( m_XmlReportThread != nullptr )
{ {
m_XmlReportThread->join(); m_XmlReportThread->join();
delete m_XmlReportThread; delete m_XmlReportThread;
m_XmlReportThread = NULL; m_XmlReportThread = nullptr;
} }
if ( m_JsonReportThread != NULL ) if ( m_JsonReportThread != nullptr )
{ {
m_JsonReportThread->join(); m_JsonReportThread->join();
delete m_JsonReportThread; delete m_JsonReportThread;
m_JsonReportThread = NULL; m_JsonReportThread = nullptr;
} }
// stop & delete all router thread // stop & delete all router thread
for ( int i = 0; i < NB_OF_MODULES; i++ ) for ( int i = 0; i < NB_OF_MODULES; i++ )
{ {
if ( m_RouterThreads[i] != NULL ) if ( m_RouterThreads[i] != nullptr )
{ {
m_RouterThreads[i]->join(); m_RouterThreads[i]->join();
delete m_RouterThreads[i]; delete m_RouterThreads[i];
m_RouterThreads[i] = NULL; m_RouterThreads[i] = nullptr;
} }
} }
@ -195,14 +195,14 @@ bool CReflector::IsStreaming(char module)
return false; return false;
} }
CPacketStream *CReflector::OpenStream(CDvHeaderPacket *DvHeader, CClient *client) CPacketStream *CReflector::OpenStream(CDvHeaderPacket *DvHeader, std::shared_ptr<CClient>client)
{ {
CPacketStream *retStream = NULL; CPacketStream *retStream = nullptr;
// clients MUST have bee locked by the caller // clients MUST have bee locked by the caller
// so we can freely access it within the fuction // so we can freely access it within the fuction
// check sid is not NULL // check sid is not nullptr
if ( DvHeader->GetStreamId() != 0 ) if ( DvHeader->GetStreamId() != 0 )
{ {
// check if client is valid candidate // check if client is valid candidate
@ -215,7 +215,7 @@ CPacketStream *CReflector::OpenStream(CDvHeaderPacket *DvHeader, CClient *client
// get the module's queue // get the module's queue
char module = DvHeader->GetRpt2Module(); char module = DvHeader->GetRpt2Module();
CPacketStream *stream = GetStream(module); CPacketStream *stream = GetStream(module);
if ( stream != NULL ) if ( stream != nullptr )
{ {
// lock it // lock it
stream->Lock(); stream->Lock();
@ -259,7 +259,7 @@ CPacketStream *CReflector::OpenStream(CDvHeaderPacket *DvHeader, CClient *client
void CReflector::CloseStream(CPacketStream *stream) void CReflector::CloseStream(CPacketStream *stream)
{ {
// //
if ( stream != NULL ) if ( stream != nullptr )
{ {
// wait queue is empty // wait queue is empty
// this waits forever // this waits forever
@ -286,8 +286,8 @@ void CReflector::CloseStream(CPacketStream *stream)
stream->Lock(); stream->Lock();
// get and check the master // get and check the master
CClient *client = stream->GetOwnerClient(); std::shared_ptr<CClient>client = stream->GetOwnerClient();
if ( client != NULL ) if ( client != nullptr )
{ {
// client no longer a master // client no longer a master
client->NotAMaster(); client->NotAMaster();
@ -336,12 +336,12 @@ void CReflector::RouterThread(CReflector *This, CPacketStream *streamIn)
} }
else else
{ {
packet = NULL; packet = nullptr;
} }
streamIn->Unlock(); streamIn->Unlock();
// route it // route it
if ( packet != NULL ) if ( packet != nullptr )
{ {
// set origin // set origin
packet->SetModuleId(uiModuleId); packet->SetModuleId(uiModuleId);
@ -368,7 +368,7 @@ void CReflector::RouterThread(CReflector *This, CPacketStream *streamIn)
} }
// done // done
delete packet; delete packet;
packet = NULL; packet = nullptr;
} }
else else
{ {
@ -566,7 +566,7 @@ int CReflector::GetModuleIndex(char module) const
CPacketStream *CReflector::GetStream(char module) CPacketStream *CReflector::GetStream(char module)
{ {
CPacketStream *stream = NULL; CPacketStream *stream = nullptr;
int i = GetModuleIndex(module); int i = GetModuleIndex(module);
if ( i >= 0 ) if ( i >= 0 )
{ {

@ -87,7 +87,7 @@ public:
void ReleasePeers(void) { m_Peers.Unlock(); } void ReleasePeers(void) { m_Peers.Unlock(); }
// stream opening & closing // stream opening & closing
CPacketStream *OpenStream(CDvHeaderPacket *, CClient *); CPacketStream *OpenStream(CDvHeaderPacket *, std::shared_ptr<CClient>);
bool IsStreaming(char); bool IsStreaming(char);
void CloseStream(CPacketStream *); void CloseStream(CPacketStream *);

@ -101,8 +101,8 @@ static unsigned char gmult(unsigned char a, unsigned char b)
*/ */
void CRS129::encode(const unsigned char* msg, unsigned int nbytes, unsigned char* parity) void CRS129::encode(const unsigned char* msg, unsigned int nbytes, unsigned char* parity)
{ {
assert(msg != NULL); assert(msg != nullptr);
assert(parity != NULL); assert(parity != nullptr);
for (unsigned int i = 0U; i < NPAR + 1U; i++) for (unsigned int i = 0U; i < NPAR + 1U; i++)
parity[i] = 0x00U; parity[i] = 0x00U;
@ -120,11 +120,10 @@ void CRS129::encode(const unsigned char* msg, unsigned int nbytes, unsigned char
// Reed-Solomon (12,9) check // Reed-Solomon (12,9) check
bool CRS129::check(const unsigned char* in) bool CRS129::check(const unsigned char* in)
{ {
assert(in != NULL); assert(in != nullptr);
unsigned char parity[4U]; unsigned char parity[4U];
encode(in, 9U, parity); encode(in, 9U, parity);
return in[9U] == parity[2U] && in[10U] == parity[1U] && in[11U] == parity[0U]; return in[9U] == parity[2U] && in[10U] == parity[1U] && in[11U] == parity[0U];
} }

@ -47,7 +47,7 @@ CTranscoder g_Transcoder;
CTranscoder::CTranscoder() CTranscoder::CTranscoder()
{ {
keep_running = true; keep_running = true;
m_pThread = NULL; m_pThread = nullptr;
m_bConnected = false; m_bConnected = false;
m_LastKeepaliveTime.Now(); m_LastKeepaliveTime.Now();
m_LastActivityTime.Now(); m_LastActivityTime.Now();
@ -133,11 +133,11 @@ void CTranscoder::Close(void)
// kill threads // kill threads
keep_running = false; keep_running = false;
if ( m_pThread != NULL ) if ( m_pThread != nullptr )
{ {
m_pThread->join(); m_pThread->join();
delete m_pThread; delete m_pThread;
m_pThread = NULL; m_pThread = nullptr;
} }
} }
@ -208,7 +208,7 @@ CCodecStream *CTranscoder::GetStream(CPacketStream *PacketStream, uint8 uiCodecI
{ {
CBuffer Buffer; CBuffer Buffer;
CCodecStream *stream = NULL; CCodecStream *stream = nullptr;
// do we need transcoding // do we need transcoding
if ( uiCodecIn != CODEC_NONE ) if ( uiCodecIn != CODEC_NONE )
@ -245,7 +245,7 @@ CCodecStream *CTranscoder::GetStream(CPacketStream *PacketStream, uint8 uiCodecI
m_Socket.Send(Buffer, m_Ip, TRANSCODER_PORT); m_Socket.Send(Buffer, m_Ip, TRANSCODER_PORT);
// and delete // and delete
delete stream; delete stream;
stream = NULL; stream = nullptr;
} }
} }
else else
@ -267,7 +267,7 @@ void CTranscoder::ReleaseStream(CCodecStream *stream)
{ {
CBuffer Buffer; CBuffer Buffer;
if ( stream != NULL ) if ( stream != nullptr )
{ {
// look for the stream // look for the stream
bool found = false; bool found = false;

@ -100,7 +100,7 @@ int CUdpMsgSocket::Receive(CBuffer *Buffer, CIp *Ip, int timeout)
// get local IP // get local IP
struct cmsghdr *Cmsg; 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) if (Cmsg->cmsg_level == IPPROTO_IP && Cmsg->cmsg_type == IP_PKTINFO)
{ {

@ -32,7 +32,7 @@
CUser::CUser() 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) 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_Rpt1 = rpt1;
m_Rpt2 = rpt2; m_Rpt2 = rpt2;
m_Xlx = xlx; m_Xlx = xlx;
m_LastHeardTime = std::time(NULL); m_LastHeardTime = std::time(nullptr);
} }
CUser::CUser(const CUser &user) CUser::CUser(const CUser &user)

@ -42,7 +42,7 @@ public:
~CUser() {} ~CUser() {}
// operation // operation
void HeardNow(void) { m_LastHeardTime = std::time(NULL); } void HeardNow(void) { m_LastHeardTime = std::time(nullptr); }
// operators // operators
bool operator ==(const CUser &) const; bool operator ==(const CUser &) const;

@ -18,7 +18,7 @@
void CUtils::byteToBitsBE(unsigned char byte, bool* bits) void CUtils::byteToBitsBE(unsigned char byte, bool* bits)
{ {
assert(bits != NULL); assert(bits != nullptr);
bits[0U] = (byte & 0x80U) == 0x80U; bits[0U] = (byte & 0x80U) == 0x80U;
bits[1U] = (byte & 0x40U) == 0x40U; bits[1U] = (byte & 0x40U) == 0x40U;
@ -32,7 +32,7 @@ void CUtils::byteToBitsBE(unsigned char byte, bool* bits)
void CUtils::byteToBitsLE(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[0U] = (byte & 0x01U) == 0x01U;
bits[1U] = (byte & 0x02U) == 0x02U; bits[1U] = (byte & 0x02U) == 0x02U;
@ -46,7 +46,7 @@ void CUtils::byteToBitsLE(unsigned char byte, bool* bits)
void CUtils::bitsToByteBE(const bool* bits, unsigned char& byte) void CUtils::bitsToByteBE(const bool* bits, unsigned char& byte)
{ {
assert(bits != NULL); assert(bits != nullptr);
byte = bits[0U] ? 0x80U : 0x00U; byte = bits[0U] ? 0x80U : 0x00U;
byte |= bits[1U] ? 0x40U : 0x00U; byte |= bits[1U] ? 0x40U : 0x00U;
@ -60,7 +60,7 @@ void CUtils::bitsToByteBE(const bool* bits, unsigned char& byte)
void CUtils::bitsToByteLE(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[0U] ? 0x01U : 0x00U;
byte |= bits[1U] ? 0x02U : 0x00U; byte |= bits[1U] ? 0x02U : 0x00U;

@ -41,7 +41,7 @@ CWiresxCmdHandler::CWiresxCmdHandler()
{ {
m_seqNo = 0; m_seqNo = 0;
keep_running = true; keep_running = true;
m_pThread = NULL; m_pThread = nullptr;
} }
@ -52,11 +52,11 @@ CWiresxCmdHandler::~CWiresxCmdHandler()
{ {
// kill threads // kill threads
keep_running = false; keep_running = false;
if ( m_pThread != NULL ) if ( m_pThread != nullptr )
{ {
m_pThread->join(); m_pThread->join();
delete m_pThread; delete m_pThread;
m_pThread = NULL; m_pThread = nullptr;
} }
// empty queue // empty queue
@ -91,11 +91,11 @@ bool CWiresxCmdHandler::Init(void)
void CWiresxCmdHandler::Close(void) void CWiresxCmdHandler::Close(void)
{ {
keep_running = false; keep_running = false;
if ( m_pThread != NULL ) if ( m_pThread != nullptr )
{ {
m_pThread->join(); m_pThread->join();
delete m_pThread; 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 // find our client and the module it's currentlink linked to
cModule = ' '; cModule = ' ';
CClients *clients = g_Reflector.GetClients(); CClients *clients = g_Reflector.GetClients();
CClient *client = clients->FindClient(Cmd.GetCallsign(), Cmd.GetIp(), PROTOCOL_YSF); std::shared_ptr<CClient>client = clients->FindClient(Cmd.GetCallsign(), Cmd.GetIp(), PROTOCOL_YSF);
if ( client != NULL ) if ( client != nullptr )
{ {
cModule = client->GetReflectorModule(); cModule = client->GetReflectorModule();
} }
@ -186,8 +186,8 @@ void CWiresxCmdHandler::Task(void)
ReplyToWiresxConnReqPacket(Cmd.GetIp(), Info, cModule); ReplyToWiresxConnReqPacket(Cmd.GetIp(), Info, cModule);
// change client's module // change client's module
CClients *clients = g_Reflector.GetClients(); CClients *clients = g_Reflector.GetClients();
CClient *client = clients->FindClient(Cmd.GetCallsign(), Cmd.GetIp(), PROTOCOL_YSF); std::shared_ptr<CClient>client = clients->FindClient(Cmd.GetCallsign(), Cmd.GetIp(), PROTOCOL_YSF);
if ( client != NULL ) if ( client != nullptr )
{ {
client->SetReflectorModule(cModule); client->SetReflectorModule(cModule);
} }
@ -205,8 +205,8 @@ void CWiresxCmdHandler::Task(void)
// change client's module // change client's module
{ {
CClients *clients = g_Reflector.GetClients(); CClients *clients = g_Reflector.GetClients();
CClient *client = clients->FindClient(Cmd.GetCallsign(), Cmd.GetIp(), PROTOCOL_YSF); std::shared_ptr<CClient>client = clients->FindClient(Cmd.GetCallsign(), Cmd.GetIp(), PROTOCOL_YSF);
if ( client != NULL ) if ( client != nullptr )
{ {
client->SetReflectorModule(' '); client->SetReflectorModule(' ');
} }

@ -48,10 +48,8 @@ CXlxPeer::CXlxPeer(const CCallsign &callsign, const CIp &ip, const char *modules
// and construct all xlx clients // and construct all xlx clients
for ( unsigned i = 0; i < ::strlen(modules); i++ ) for ( unsigned i = 0; i < ::strlen(modules); i++ )
{ {
// create // create and append to vector
CXlxClient *client = new CXlxClient(callsign, ip, modules[i], protrev); m_Clients.push_back(std::make_shared<CXlxClient>(callsign, ip, modules[i], protrev));
// and append to vector
m_Clients.push_back(client);
} }
} }
@ -60,9 +58,8 @@ CXlxPeer::CXlxPeer(const CXlxPeer &peer)
{ {
for ( auto it=peer.cbegin(); it!=peer.cend(); it++ ) for ( auto it=peer.cbegin(); it!=peer.cend(); it++ )
{ {
CXlxClient *client = new CXlxClient((const CXlxClient &)*(*it)); std::shared_ptr<CXlxClient> client(new CXlxClient((const CXlxClient &)*(*it)));
m_Clients.push_back(client); m_Clients.push_back(client);
} }
} }

@ -74,14 +74,14 @@ void CXlxProtocol::Task(void)
#endif #endif
{ {
// crack the packet // crack the packet
if ( (Frame = IsValidDvFramePacket(Buffer)) != NULL ) if ( (Frame = IsValidDvFramePacket(Buffer)) != nullptr )
{ {
//std::cout << "XLX (DExtra) DV frame" << std::endl; //std::cout << "XLX (DExtra) DV frame" << std::endl;
// handle it // handle it
OnDvFramePacketIn(Frame, &Ip); 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:" << std::endl << *Header << std::endl;
//std::cout << "XLX (DExtra) DV header on module " << Header->GetRpt2Module() << std::endl; //std::cout << "XLX (DExtra) DV header on module " << Header->GetRpt2Module() << std::endl;
@ -97,7 +97,7 @@ void CXlxProtocol::Task(void)
delete Header; delete Header;
} }
} }
else if ( (LastFrame = IsValidDvLastFramePacket(Buffer)) != NULL ) else if ( (LastFrame = IsValidDvLastFramePacket(Buffer)) != nullptr )
{ {
//std::cout << "XLX (DExtra) DV last frame" << std::endl; //std::cout << "XLX (DExtra) DV last frame" << std::endl;
@ -122,7 +122,7 @@ void CXlxProtocol::Task(void)
{ {
// already connected ? // already connected ?
CPeers *peers = g_Reflector.GetPeers(); CPeers *peers = g_Reflector.GetPeers();
if ( peers->FindPeer(Callsign, Ip, PROTOCOL_XLX) == NULL ) if ( peers->FindPeer(Callsign, Ip, PROTOCOL_XLX) == nullptr )
{ {
// acknowledge the request // acknowledge the request
EncodeConnectAckPacket(&Buffer, Modules); EncodeConnectAckPacket(&Buffer, Modules);
@ -157,11 +157,11 @@ void CXlxProtocol::Task(void)
{ {
// already connected ? // already connected ?
CPeers *peers = g_Reflector.GetPeers(); 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 // create the new peer
// this also create one client per module // this also create one client per module
CPeer *peer = CreateNewPeer(Callsign, Ip, Modules, Version); std::shared_ptr<CPeer>peer = CreateNewPeer(Callsign, Ip, Modules, Version);
// append the peer to reflector peer list // append the peer to reflector peer list
// this also add all new clients to reflector client list // this also add all new clients to reflector client list
@ -176,8 +176,8 @@ void CXlxProtocol::Task(void)
// find peer // find peer
CPeers *peers = g_Reflector.GetPeers(); CPeers *peers = g_Reflector.GetPeers();
CPeer *peer = peers->FindPeer(Ip, PROTOCOL_XLX); std::shared_ptr<CPeer>peer = peers->FindPeer(Ip, PROTOCOL_XLX);
if ( peer != NULL ) if ( peer != nullptr )
{ {
// remove it from reflector peer list // remove it from reflector peer list
// this also remove all concerned clients from reflector client list // this also remove all concerned clients from reflector client list
@ -196,8 +196,8 @@ void CXlxProtocol::Task(void)
// find peer // find peer
CPeers *peers = g_Reflector.GetPeers(); CPeers *peers = g_Reflector.GetPeers();
CPeer *peer = peers->FindPeer(Ip, PROTOCOL_XLX); std::shared_ptr<CPeer>peer = peers->FindPeer(Ip, PROTOCOL_XLX);
if ( peer != NULL ) if ( peer != nullptr )
{ {
// keep it alive // keep it alive
peer->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 // and push it to all our clients linked to the module and who are not streaming in
CClients *clients = g_Reflector.GetClients(); CClients *clients = g_Reflector.GetClients();
auto it = clients->begin(); auto it = clients->begin();
CClient *client = NULL; std::shared_ptr<CClient>client = nullptr;
while ( (client = clients->FindNextClient(PROTOCOL_XLX, it)) != NULL ) while ( (client = clients->FindNextClient(PROTOCOL_XLX, it)) != nullptr )
{ {
// is this client busy ? // is this client busy ?
if ( !client->IsAMaster() && (client->GetReflectorModule() == packet->GetModuleId()) ) if ( !client->IsAMaster() && (client->GetReflectorModule() == packet->GetModuleId()) )
@ -322,8 +322,8 @@ void CXlxProtocol::HandleKeepalives(void)
// iterate on peers // iterate on peers
CPeers *peers = g_Reflector.GetPeers(); CPeers *peers = g_Reflector.GetPeers();
auto pit = peers->begin(); auto pit = peers->begin();
CPeer *peer = NULL; std::shared_ptr<CPeer>peer = nullptr;
while ( (peer = peers->FindNextPeer(PROTOCOL_XLX, pit)) != NULL ) while ( (peer = peers->FindNextPeer(PROTOCOL_XLX, pit)) != nullptr )
{ {
// send keepalive // send keepalive
Send(keepalive, peer->GetIp()); Send(keepalive, peer->GetIp());
@ -364,10 +364,10 @@ void CXlxProtocol::HandlePeerLinks(void)
// check if all our connected peers are still listed by gatekeeper // check if all our connected peers are still listed by gatekeeper
// if not, disconnect // if not, disconnect
auto pit = peers->begin(); auto pit = peers->begin();
CPeer *peer = NULL; std::shared_ptr<CPeer>peer = nullptr;
while ( (peer = peers->FindNextPeer(PROTOCOL_XLX, pit)) != NULL ) while ( (peer = peers->FindNextPeer(PROTOCOL_XLX, pit)) != nullptr )
{ {
if ( list->FindListItem(peer->GetCallsign()) == NULL ) if ( list->FindListItem(peer->GetCallsign()) == nullptr )
{ {
// send disconnect packet // send disconnect packet
EncodeDisconnectPacket(&buffer); EncodeDisconnectPacket(&buffer);
@ -384,7 +384,7 @@ void CXlxProtocol::HandlePeerLinks(void)
{ {
if ( (*it).GetCallsign().HasSameCallsignWithWildcard(CCallsign("XRF*")) ) if ( (*it).GetCallsign().HasSameCallsignWithWildcard(CCallsign("XRF*")) )
continue; 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 // resolve again peer's IP in case it's a dynamic IP
(*it).ResolveIp(); (*it).ResolveIp();
@ -417,15 +417,15 @@ bool CXlxProtocol::OnDvHeaderPacketIn(CDvHeaderPacket *Header, const CIp &Ip)
// find the stream // find the stream
CPacketStream *stream = GetStream(Header->GetStreamId()); CPacketStream *stream = GetStream(Header->GetStreamId());
if ( stream == NULL ) if ( stream == nullptr )
{ {
// no stream open yet, open a new one // no stream open yet, open a new one
// find this client // find this client
CClient *client = g_Reflector.GetClients()->FindClient(Ip, PROTOCOL_XLX, Header->GetRpt2Module()); std::shared_ptr<CClient>client = g_Reflector.GetClients()->FindClient(Ip, PROTOCOL_XLX, Header->GetRpt2Module());
if ( client != NULL ) if ( client != nullptr )
{ {
// and try to open the stream // 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 // keep the handle
m_Streams.push_back(stream); m_Streams.push_back(stream);
@ -550,13 +550,13 @@ bool CXlxProtocol::IsValidNackPacket(const CBuffer &Buffer, CCallsign *callsign)
CDvFramePacket *CXlxProtocol::IsValidDvFramePacket(const CBuffer &Buffer) CDvFramePacket *CXlxProtocol::IsValidDvFramePacket(const CBuffer &Buffer)
{ {
CDvFramePacket *dvframe = NULL; CDvFramePacket *dvframe = nullptr;
// base class first (protocol revision 1 and lower) // base class first (protocol revision 1 and lower)
dvframe = CDextraProtocol::IsValidDvFramePacket(Buffer); dvframe = CDextraProtocol::IsValidDvFramePacket(Buffer);
// otherwise try protocol revision 2 // otherwise try protocol revision 2
if ( (dvframe == NULL) && if ( (dvframe == nullptr) &&
(Buffer.size() == 45) && (Buffer.Compare((uint8 *)"DSVT", 4) == 0) && (Buffer.size() == 45) && (Buffer.Compare((uint8 *)"DSVT", 4) == 0) &&
(Buffer.data()[4] == 0x20) && (Buffer.data()[8] == 0x20) && (Buffer.data()[4] == 0x20) && (Buffer.data()[8] == 0x20) &&
((Buffer.data()[14] & 0x40) == 0) ) ((Buffer.data()[14] & 0x40) == 0) )
@ -574,7 +574,7 @@ CDvFramePacket *CXlxProtocol::IsValidDvFramePacket(const CBuffer &Buffer)
if ( !dvframe->IsValid() ) if ( !dvframe->IsValid() )
{ {
delete dvframe; delete dvframe;
dvframe = NULL; dvframe = nullptr;
} }
} }
@ -584,13 +584,13 @@ CDvFramePacket *CXlxProtocol::IsValidDvFramePacket(const CBuffer &Buffer)
CDvLastFramePacket *CXlxProtocol::IsValidDvLastFramePacket(const CBuffer &Buffer) CDvLastFramePacket *CXlxProtocol::IsValidDvLastFramePacket(const CBuffer &Buffer)
{ {
CDvLastFramePacket *dvframe = NULL; CDvLastFramePacket *dvframe = nullptr;
// base class first (protocol revision 1 and lower) // base class first (protocol revision 1 and lower)
dvframe = CDextraProtocol::IsValidDvLastFramePacket(Buffer); dvframe = CDextraProtocol::IsValidDvLastFramePacket(Buffer);
// otherwise try protocol revision 2 // otherwise try protocol revision 2
if ( (dvframe == NULL) && if ( (dvframe == nullptr) &&
(Buffer.size() == 45) && (Buffer.Compare((uint8 *)"DSVT", 4) == 0) && (Buffer.size() == 45) && (Buffer.Compare((uint8 *)"DSVT", 4) == 0) &&
(Buffer.data()[4] == 0x20) && (Buffer.data()[8] == 0x20) && (Buffer.data()[4] == 0x20) && (Buffer.data()[8] == 0x20) &&
((Buffer.data()[14] & 0x40) != 0) ) ((Buffer.data()[14] & 0x40) != 0) )
@ -608,7 +608,7 @@ CDvLastFramePacket *CXlxProtocol::IsValidDvLastFramePacket(const CBuffer &Buffer
if ( !dvframe->IsValid() ) if ( !dvframe->IsValid() )
{ {
delete dvframe; delete dvframe;
dvframe = NULL; dvframe = nullptr;
} }
} }
@ -746,20 +746,15 @@ int CXlxProtocol::GetConnectingPeerProtocolRevision(const CCallsign &Callsign, c
return protrev; return protrev;
} }
CPeer *CXlxProtocol::CreateNewPeer(const CCallsign &Callsign, const CIp &Ip, char *Modules, const CVersion &Version) std::shared_ptr<CPeer> CXlxProtocol::CreateNewPeer(const CCallsign &Callsign, const CIp &Ip, char *Modules, const CVersion &Version)
{ {
CPeer *peer = NULL;
// BM ? // BM ?
if ( Callsign.HasSameCallsignWithWildcard(CCallsign("BM*")) ) if ( Callsign.HasSameCallsignWithWildcard(CCallsign("BM*")) )
{ {
peer = new CBmPeer(Callsign, Ip, Modules, Version); return std::make_shared<CBmPeer>(Callsign, Ip, Modules, Version);
} }
else else
{ {
peer = new CXlxPeer(Callsign, Ip, Modules, Version); return std::make_shared<CXlxPeer>(Callsign, Ip, Modules, Version);
} }
// done
return peer;
} }

@ -56,8 +56,8 @@ protected:
// stream helpers // stream helpers
bool OnDvHeaderPacketIn(CDvHeaderPacket *, const CIp &); bool OnDvHeaderPacketIn(CDvHeaderPacket *, const CIp &);
void OnDvFramePacketIn(CDvFramePacket *, const CIp * = NULL); void OnDvFramePacketIn(CDvFramePacket *, const CIp * = nullptr);
void OnDvLastFramePacketIn(CDvLastFramePacket *, const CIp * = NULL); void OnDvLastFramePacketIn(CDvLastFramePacket *, const CIp * = nullptr);
// packet decoding helpers // packet decoding helpers
bool IsValidKeepAlivePacket(const CBuffer &, CCallsign *); bool IsValidKeepAlivePacket(const CBuffer &, CCallsign *);
@ -79,7 +79,7 @@ protected:
// protocol revision helper // protocol revision helper
int GetConnectingPeerProtocolRevision(const CCallsign &, const CVersion &); int GetConnectingPeerProtocolRevision(const CCallsign &, const CVersion &);
CPeer *CreateNewPeer(const CCallsign &, const CIp &, char *, const CVersion &); std::shared_ptr<CPeer>CreateNewPeer(const CCallsign &, const CIp &, char *, const CVersion &);
protected: protected:
// time // time

@ -36,12 +36,12 @@ const uint32_t M = 2U;
const unsigned int K = 5U; const unsigned int K = 5U;
CYSFConvolution::CYSFConvolution() : CYSFConvolution::CYSFConvolution() :
m_metrics1(NULL), m_metrics1(nullptr),
m_metrics2(NULL), m_metrics2(nullptr),
m_oldMetrics(NULL), m_oldMetrics(nullptr),
m_newMetrics(NULL), m_newMetrics(nullptr),
m_decisions(NULL), m_decisions(nullptr),
m_dp(NULL) m_dp(nullptr)
{ {
m_metrics1 = new uint16_t[16U]; m_metrics1 = new uint16_t[16U];
m_metrics2 = new uint16_t[16U]; m_metrics2 = new uint16_t[16U];
@ -98,7 +98,7 @@ void CYSFConvolution::decode(uint8_t s0, uint8_t s1)
void CYSFConvolution::chainback(unsigned char* out, unsigned int nBits) void CYSFConvolution::chainback(unsigned char* out, unsigned int nBits)
{ {
assert(out != NULL); assert(out != nullptr);
uint32_t state = 0U; uint32_t state = 0U;
@ -115,8 +115,8 @@ void CYSFConvolution::chainback(unsigned char* out, unsigned int nBits)
void CYSFConvolution::encode(const unsigned char* in, unsigned char* out, unsigned int nBits) const void CYSFConvolution::encode(const unsigned char* in, unsigned char* out, unsigned int nBits) const
{ {
assert(in != NULL); assert(in != nullptr);
assert(out != NULL); assert(out != nullptr);
assert(nBits > 0U); assert(nBits > 0U);
uint8_t d1 = 0U, d2 = 0U, d3 = 0U, d4 = 0U; uint8_t d1 = 0U, d2 = 0U, d3 = 0U, d4 = 0U;

@ -56,7 +56,7 @@ const unsigned int INTERLEAVE_TABLE[] = {
38U, 78U, 118U, 158U, 198U}; 38U, 78U, 118U, 158U, 198U};
CYSFFICH::CYSFFICH() : CYSFFICH::CYSFFICH() :
m_fich(NULL) m_fich(nullptr)
{ {
m_fich = new unsigned char[6U]; m_fich = new unsigned char[6U];
::memset(m_fich, 0U, 6U); ::memset(m_fich, 0U, 6U);
@ -69,7 +69,7 @@ CYSFFICH::~CYSFFICH()
bool CYSFFICH::decode(const unsigned char* bytes) bool CYSFFICH::decode(const unsigned char* bytes)
{ {
assert(bytes != NULL); assert(bytes != nullptr);
CYSFConvolution viterbi; CYSFConvolution viterbi;
viterbi.start(); viterbi.start();
@ -105,7 +105,7 @@ bool CYSFFICH::decode(const unsigned char* bytes)
void CYSFFICH::encode(unsigned char* bytes) void CYSFFICH::encode(unsigned char* bytes)
{ {
assert(bytes != NULL); assert(bytes != nullptr);
CCRC::addCCITT162(m_fich, 6U); CCRC::addCCITT162(m_fich, 6U);
@ -301,8 +301,7 @@ void CYSFFICH::setBT(unsigned char bt)
void CYSFFICH::load(const unsigned char* fich) void CYSFFICH::load(const unsigned char* fich)
{ {
assert(fich != NULL); assert(fich != nullptr);
::memcpy(m_fich, fich, 4U); ::memcpy(m_fich, fich, 4U);
} }

@ -34,18 +34,18 @@
CYsfNodeDir::CYsfNodeDir() CYsfNodeDir::CYsfNodeDir()
{ {
keep_running = true; keep_running = true;
m_pThread = NULL; m_pThread = nullptr;
} }
CYsfNodeDir::~CYsfNodeDir() CYsfNodeDir::~CYsfNodeDir()
{ {
// kill threads // kill threads
keep_running = false; keep_running = false;
if ( m_pThread != NULL ) if ( m_pThread != nullptr )
{ {
m_pThread->join(); m_pThread->join();
delete m_pThread; delete m_pThread;
m_pThread = NULL; m_pThread = nullptr;
} }
} }
@ -70,11 +70,11 @@ bool CYsfNodeDir::Init(void)
void CYsfNodeDir::Close(void) void CYsfNodeDir::Close(void)
{ {
keep_running = false; keep_running = false;
if ( m_pThread != NULL ) if ( m_pThread != nullptr )
{ {
m_pThread->join(); m_pThread->join();
delete m_pThread; delete m_pThread;
m_pThread = NULL; m_pThread = nullptr;
} }
} }

@ -113,18 +113,18 @@ bool CYsfNodeDirFile::RefreshContent(const CBuffer &buffer)
char *ptr2; char *ptr2;
// get next line // get next line
while ( (ptr2 = ::strchr(ptr1, '\n')) != NULL ) while ( (ptr2 = ::strchr(ptr1, '\n')) != nullptr )
{ {
*ptr2 = 0; *ptr2 = 0;
// get items // get items
char *callsign; char *callsign;
char *txfreq; char *txfreq;
char *rxfreq; 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 // new entry
CCallsign cs(callsign); CCallsign cs(callsign);

@ -56,18 +56,18 @@ bool CYsfNodeDirHttp::RefreshContent(const CBuffer &buffer)
char *ptr2; char *ptr2;
// get next line // get next line
while ( (ptr2 = ::strchr(ptr1, '\n')) != NULL ) while ( (ptr2 = ::strchr(ptr1, '\n')) != nullptr )
{ {
*ptr2 = 0; *ptr2 = 0;
// get items // get items
char *callsign; char *callsign;
char *txfreq; char *txfreq;
char *rxfreq; 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 // new entry
CCallsign cs(callsign); CCallsign cs(callsign);
@ -112,7 +112,7 @@ bool CYsfNodeDirHttp::HttpGet(const char *hostname, const char *filename, int po
struct sockaddr_in servaddr; struct sockaddr_in servaddr;
struct hostent *hp; struct hostent *hp;
::memset(&servaddr,0,sizeof(servaddr)); ::memset(&servaddr,0,sizeof(servaddr));
if( (hp = gethostbyname(hostname)) != NULL ) if( (hp = gethostbyname(hostname)) != nullptr )
{ {
// dns resolved // dns resolved
::memcpy((char *)&servaddr.sin_addr.s_addr, (char *)hp->h_addr, hp->h_length); ::memcpy((char *)&servaddr.sin_addr.s_addr, (char *)hp->h_addr, hp->h_length);
@ -143,7 +143,7 @@ bool CYsfNodeDirHttp::HttpGet(const char *hostname, const char *filename, int po
{ {
char buf[1440]; char buf[1440];
ssize_t len = 0; 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) || ((ret < 0) && (errno == EINPROGRESS)) )
//if ( ret >= 0 ) //if ( ret >= 0 )
//{ //{

@ -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]) #define READ_BIT1(p,i) (p[(i)>>3] & BIT_MASK_TABLE[(i)&7])
CYSFPayload::CYSFPayload() : CYSFPayload::CYSFPayload() :
m_uplink(NULL), m_uplink(nullptr),
m_downlink(NULL), m_downlink(nullptr),
m_source(NULL), m_source(nullptr),
m_dest(NULL) m_dest(nullptr)
{ {
} }
@ -95,7 +95,7 @@ CYSFPayload::~CYSFPayload()
bool CYSFPayload::processHeaderData(unsigned char* data) bool CYSFPayload::processHeaderData(unsigned char* data)
{ {
assert(data != NULL); assert(data != nullptr);
data += YSF_SYNC_LENGTH_BYTES + YSF_FICH_LENGTH_BYTES; data += YSF_SYNC_LENGTH_BYTES + YSF_FICH_LENGTH_BYTES;
@ -129,12 +129,12 @@ bool CYSFPayload::processHeaderData(unsigned char* data)
for (unsigned int i = 0U; i < 20U; i++) for (unsigned int i = 0U; i < 20U; i++)
output[i] ^= WHITENING_DATA[i]; output[i] ^= WHITENING_DATA[i];
if (m_dest == NULL) { if (m_dest == nullptr) {
m_dest = new unsigned char[YSF_CALLSIGN_LENGTH]; m_dest = new unsigned char[YSF_CALLSIGN_LENGTH];
::memcpy(m_dest, output + 0U, 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]; m_source = new unsigned char[YSF_CALLSIGN_LENGTH];
::memcpy(m_source, output + YSF_CALLSIGN_LENGTH, YSF_CALLSIGN_LENGTH); ::memcpy(m_source, output + YSF_CALLSIGN_LENGTH, YSF_CALLSIGN_LENGTH);
} }
@ -199,10 +199,10 @@ bool CYSFPayload::processHeaderData(unsigned char* data)
for (unsigned int i = 0U; i < 20U; i++) for (unsigned int i = 0U; i < 20U; i++)
output[i] ^= WHITENING_DATA[i]; output[i] ^= WHITENING_DATA[i];
if (m_downlink != NULL) if (m_downlink != nullptr)
::memcpy(output + 0U, m_downlink, YSF_CALLSIGN_LENGTH); ::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); ::memcpy(output + YSF_CALLSIGN_LENGTH, m_uplink, YSF_CALLSIGN_LENGTH);
for (unsigned int i = 0U; i < 20U; i++) for (unsigned int i = 0U; i < 20U; i++)
@ -244,8 +244,8 @@ bool CYSFPayload::processHeaderData(unsigned char* data)
bool CYSFPayload::readDataFRModeData1(const unsigned char* data, unsigned char* dt) bool CYSFPayload::readDataFRModeData1(const unsigned char* data, unsigned char* dt)
{ {
assert(data != NULL); assert(data != nullptr);
assert(dt != NULL); assert(dt != nullptr);
::memset(dt, ' ', 20U); ::memset(dt, ' ', 20U);
@ -291,8 +291,8 @@ bool CYSFPayload::readDataFRModeData1(const unsigned char* data, unsigned char*
bool CYSFPayload::readDataFRModeData2(const unsigned char* data, unsigned char* dt) bool CYSFPayload::readDataFRModeData2(const unsigned char* data, unsigned char* dt)
{ {
assert(data != NULL); assert(data != nullptr);
assert(dt != NULL); assert(dt != nullptr);
::memset(dt, ' ', 20U); ::memset(dt, ' ', 20U);
@ -382,8 +382,8 @@ void CYSFPayload::writeVDMode2Data(unsigned char* data, const unsigned char* dt)
bool CYSFPayload::readVDMode1Data(const unsigned char* data, unsigned char* dt) bool CYSFPayload::readVDMode1Data(const unsigned char* data, unsigned char* dt)
{ {
assert(data != NULL); assert(data != nullptr);
assert(dt != NULL); assert(dt != nullptr);
data += YSF_SYNC_LENGTH_BYTES + YSF_FICH_LENGTH_BYTES; data += YSF_SYNC_LENGTH_BYTES + YSF_FICH_LENGTH_BYTES;
@ -428,8 +428,8 @@ bool CYSFPayload::readVDMode1Data(const unsigned char* data, unsigned char* dt)
bool CYSFPayload::readVDMode2Data(const unsigned char* data, unsigned char* dt) bool CYSFPayload::readVDMode2Data(const unsigned char* data, unsigned char* dt)
{ {
assert(data != NULL); assert(data != nullptr);
assert(dt != NULL); assert(dt != nullptr);
data += YSF_SYNC_LENGTH_BYTES + YSF_FICH_LENGTH_BYTES; data += YSF_SYNC_LENGTH_BYTES + YSF_FICH_LENGTH_BYTES;
@ -473,9 +473,9 @@ bool CYSFPayload::readVDMode2Data(const unsigned char* data, unsigned char* dt)
void CYSFPayload::writeHeader(unsigned char* data, const unsigned char* csd1, const unsigned char* csd2) void CYSFPayload::writeHeader(unsigned char* data, const unsigned char* csd1, const unsigned char* csd2)
{ {
assert(data != NULL); assert(data != nullptr);
assert(csd1 != NULL); assert(csd1 != nullptr);
assert(csd2 != NULL); assert(csd2 != nullptr);
writeDataFRModeData1(csd1, data); writeDataFRModeData1(csd1, data);
@ -484,8 +484,8 @@ void CYSFPayload::writeHeader(unsigned char* data, const unsigned char* csd1, co
void CYSFPayload::writeDataFRModeData1(const unsigned char* dt, unsigned char* data) void CYSFPayload::writeDataFRModeData1(const unsigned char* dt, unsigned char* data)
{ {
assert(dt != NULL); assert(dt != nullptr);
assert(data != NULL); assert(data != nullptr);
data += YSF_SYNC_LENGTH_BYTES + YSF_FICH_LENGTH_BYTES; data += YSF_SYNC_LENGTH_BYTES + YSF_FICH_LENGTH_BYTES;
@ -528,8 +528,8 @@ void CYSFPayload::writeDataFRModeData1(const unsigned char* dt, unsigned char* d
void CYSFPayload::writeDataFRModeData2(const unsigned char* dt, unsigned char* data) void CYSFPayload::writeDataFRModeData2(const unsigned char* dt, unsigned char* data)
{ {
assert(dt != NULL); assert(dt != nullptr);
assert(data != NULL); assert(data != nullptr);
data += YSF_SYNC_LENGTH_BYTES + YSF_FICH_LENGTH_BYTES; data += YSF_SYNC_LENGTH_BYTES + YSF_FICH_LENGTH_BYTES;
@ -621,6 +621,6 @@ void CYSFPayload::reset()
delete[] m_source; delete[] m_source;
delete[] m_dest; delete[] m_dest;
m_source = NULL; m_source = nullptr;
m_dest = NULL; m_dest = nullptr;
} }

@ -166,14 +166,14 @@ void CYsfProtocol::Task(void)
// add client if needed // add client if needed
CClients *clients = g_Reflector.GetClients(); CClients *clients = g_Reflector.GetClients();
CClient *client = clients->FindClient(Callsign, Ip, PROTOCOL_YSF); std::shared_ptr<CClient>client = clients->FindClient(Callsign, Ip, PROTOCOL_YSF);
// client already connected ? // client already connected ?
if ( client == NULL ) if ( client == nullptr )
{ {
std::cout << "YSF connect packet from " << Callsign << " at " << Ip << std::endl; std::cout << "YSF connect packet from " << Callsign << " at " << Ip << std::endl;
// create the client // create the client
CYsfClient *newclient = new CYsfClient(Callsign, Ip); auto newclient = std::make_shared<CYsfClient>(Callsign, Ip);
// aautolink, if enabled // aautolink, if enabled
#if YSF_AUTOLINK_ENABLE #if YSF_AUTOLINK_ENABLE
@ -241,14 +241,14 @@ bool CYsfProtocol::OnDvHeaderPacketIn(CDvHeaderPacket *Header, const CIp &Ip)
// find the stream // find the stream
CPacketStream *stream = GetStream(Header->GetStreamId()); CPacketStream *stream = GetStream(Header->GetStreamId());
if ( stream == NULL ) if ( stream == nullptr )
{ {
// no stream open yet, open a new one // no stream open yet, open a new one
CCallsign via(Header->GetRpt1Callsign()); CCallsign via(Header->GetRpt1Callsign());
// find this client // find this client
CClient *client = g_Reflector.GetClients()->FindClient(Ip, PROTOCOL_YSF); std::shared_ptr<CClient>client = g_Reflector.GetClients()->FindClient(Ip, PROTOCOL_YSF);
if ( client != NULL ) if ( client != nullptr )
{ {
// get client callsign // get client callsign
via = client->GetCallsign(); via = client->GetCallsign();
@ -256,7 +256,7 @@ bool CYsfProtocol::OnDvHeaderPacketIn(CDvHeaderPacket *Header, const CIp &Ip)
Header->SetRpt2Module(client->GetReflectorModule()); Header->SetRpt2Module(client->GetReflectorModule());
// and try to open the stream // 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 // keep the handle
m_Streams.push_back(stream); 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 // and push it to all our clients linked to the module and who are not streaming in
CClients *clients = g_Reflector.GetClients(); CClients *clients = g_Reflector.GetClients();
auto it = clients->begin(); auto it = clients->begin();
CClient *client = NULL; std::shared_ptr<CClient>client = nullptr;
while ( (client = clients->FindNextClient(PROTOCOL_YSF, it)) != NULL ) while ( (client = clients->FindNextClient(PROTOCOL_YSF, it)) != nullptr )
{ {
// is this client busy ? // is this client busy ?
if ( !client->IsAMaster() && (client->GetReflectorModule() == packet->GetModuleId()) ) if ( !client->IsAMaster() && (client->GetReflectorModule() == packet->GetModuleId()) )
@ -382,8 +382,8 @@ void CYsfProtocol::HandleKeepalives(void)
// iterate on clients // iterate on clients
CClients *clients = g_Reflector.GetClients(); CClients *clients = g_Reflector.GetClients();
auto it = clients->begin(); auto it = clients->begin();
CClient *client = NULL; std::shared_ptr<CClient>client = nullptr;
while ( (client = clients->FindNextClient(PROTOCOL_YSF, it)) != NULL ) while ( (client = clients->FindNextClient(PROTOCOL_YSF, it)) != nullptr )
{ {
// is this client busy ? // is this client busy ?
if ( client->IsAMaster() ) 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 CYsfProtocol::IsValidDvHeaderPacket(const CIp &Ip, const CYSFFICH &Fich, const CBuffer &Buffer, CDvHeaderPacket **header, CDvFramePacket **frames)
{ {
bool valid = false; bool valid = false;
*header = NULL; *header = nullptr;
frames[0] = NULL; frames[0] = nullptr;
frames[1] = NULL; frames[1] = nullptr;
// DV header ? // DV header ?
if ( Fich.getFI() == YSF_FI_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 // check validity of packets
if ( ((*header) == NULL) || !(*header)->IsValid() || if ( ((*header) == nullptr) || !(*header)->IsValid() ||
(frames[0] == NULL) || !(frames[0]->IsValid()) || (frames[0] == nullptr) || !(frames[0]->IsValid()) ||
(frames[1] == NULL) || !(frames[1]->IsValid()) ) (frames[1] == nullptr) || !(frames[1]->IsValid()) )
{ {
delete *header; delete *header;
*header = NULL; *header = nullptr;
delete frames[0]; delete frames[0];
delete frames[1]; delete frames[1];
frames[0] = NULL; frames[0] = nullptr;
frames[1] = NULL; frames[1] = nullptr;
} }
else 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 CYsfProtocol::IsValidDvFramePacket(const CIp &Ip, const CYSFFICH &Fich, const CBuffer &Buffer, CDvFramePacket **frames)
{ {
bool valid = false; bool valid = false;
frames[0] = NULL; frames[0] = nullptr;
frames[1] = NULL; frames[1] = nullptr;
frames[2] = NULL; frames[2] = nullptr;
frames[3] = NULL; frames[3] = nullptr;
frames[4] = NULL; frames[4] = nullptr;
// is it DV frame ? // is it DV frame ?
if ( Fich.getFI() == YSF_FI_COMMUNICATIONS ) 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); frames[4] = new CDvFramePacket(ambe4, uiStreamId, Fich.getFN(), 4, fid);
// check validity of packets // check validity of packets
if ( (frames[0] == NULL) || !(frames[0]->IsValid()) || if ( (frames[0] == nullptr) || !(frames[0]->IsValid()) ||
(frames[1] == NULL) || !(frames[1]->IsValid()) || (frames[1] == nullptr) || !(frames[1]->IsValid()) ||
(frames[2] == NULL) || !(frames[2]->IsValid()) || (frames[2] == nullptr) || !(frames[2]->IsValid()) ||
(frames[3] == NULL) || !(frames[3]->IsValid()) || (frames[3] == nullptr) || !(frames[3]->IsValid()) ||
(frames[4] == NULL) || !(frames[4]->IsValid()) ) (frames[4] == nullptr) || !(frames[4]->IsValid()) )
{ {
delete frames[0]; delete frames[0];
delete frames[1]; delete frames[1];
delete frames[2]; delete frames[2];
delete frames[3]; delete frames[3];
delete frames[4]; delete frames[4];
frames[0] = NULL; frames[0] = nullptr;
frames[1] = NULL; frames[1] = nullptr;
frames[2] = NULL; frames[2] = nullptr;
frames[3] = NULL; frames[3] = nullptr;
frames[4] = NULL; frames[4] = nullptr;
} }
else 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 CYsfProtocol::IsValidDvLastFramePacket(const CIp &Ip, const CYSFFICH &Fich, const CBuffer &Buffer, CDvFramePacket **frames)
{ {
bool valid = false; bool valid = false;
frames[0] = NULL; frames[0] = nullptr;
frames[1] = NULL; frames[1] = nullptr;
// DV header ? // DV header ?
if ( Fich.getFI() == YSF_FI_TERMINATOR ) if ( Fich.getFI() == YSF_FI_TERMINATOR )
@ -586,14 +586,14 @@ bool CYsfProtocol::IsValidDvLastFramePacket(const CIp &Ip, const CYSFFICH &Fich,
} }
// check validity of packets // check validity of packets
if ( (frames[0] == NULL) || !(frames[0]->IsValid()) || if ( (frames[0] == nullptr) || !(frames[0]->IsValid()) ||
(frames[1] == NULL) || !(frames[1]->IsValid()) ) (frames[1] == nullptr) || !(frames[1]->IsValid()) )
{ {
delete frames[0]; delete frames[0];
delete frames[1]; delete frames[1];
frames[0] = NULL; frames[0] = nullptr;
frames[1] = NULL; frames[1] = nullptr;
} }
else else
{ {

@ -104,7 +104,7 @@ protected:
// DV packet encoding helpers // DV packet encoding helpers
void EncodeConnectAckPacket(CBuffer *) const; void EncodeConnectAckPacket(CBuffer *) const;
//void EncodeConnectNackPacket(const CCallsign &, char, CBuffer *); //void EncodeConnectNackPacket(const CCallsign &, char, CBuffer *);
//void EncodeDisconnectPacket(CBuffer *, CClient *); //void EncodeDisconnectPacket(CBuffer *, std::shared_ptr<CClient>);
bool EncodeDvHeaderPacket(const CDvHeaderPacket &, CBuffer *) const; bool EncodeDvHeaderPacket(const CDvHeaderPacket &, CBuffer *) const;
bool EncodeDvPacket(const CDvHeaderPacket &, const CDvFramePacket *, CBuffer *) const; bool EncodeDvPacket(const CDvHeaderPacket &, const CDvFramePacket *, CBuffer *) const;
bool EncodeDvLastPacket(const CDvHeaderPacket &, CBuffer *) const; bool EncodeDvLastPacket(const CDvHeaderPacket &, CBuffer *) const;

@ -34,6 +34,7 @@
#include <chrono> #include <chrono>
#include <thread> #include <thread>
#include <mutex> #include <mutex>
#include <memory>
#include <atomic> #include <atomic>
#include <condition_variable> #include <condition_variable>
#include <ctime> #include <ctime>

Loading…
Cancel
Save

Powered by TurnKey Linux.