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,18 +37,18 @@ 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);
// Deinterleave // Deinterleave
decodeDeInterleave(); decodeDeInterleave();
// Error check // Error check
decodeErrorCheck(); decodeErrorCheck();
// Extract Data // Extract Data
decodeExtractData(out); decodeExtractData(out);
} }
@ -56,18 +56,18 @@ 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);
// Error check // Error check
encodeErrorCheck(); encodeErrorCheck();
// Deinterleave // Deinterleave
encodeInterleave(); encodeInterleave();
// Get the raw binary // Get the raw binary
encodeExtractBinary(out); encodeExtractBinary(out);
} }
@ -88,13 +88,13 @@ void CBPTC19696::decodeExtractBinary(const unsigned char* in)
CUtils::byteToBitsBE(in[10U], m_rawData + 80U); CUtils::byteToBitsBE(in[10U], m_rawData + 80U);
CUtils::byteToBitsBE(in[11U], m_rawData + 88U); CUtils::byteToBitsBE(in[11U], m_rawData + 88U);
CUtils::byteToBitsBE(in[12U], m_rawData + 96U); CUtils::byteToBitsBE(in[12U], m_rawData + 96U);
// Handle the two bits // Handle the two bits
bool bits[8U]; bool bits[8U];
CUtils::byteToBitsBE(in[20U], bits); CUtils::byteToBitsBE(in[20U], bits);
m_rawData[98U] = bits[6U]; m_rawData[98U] = bits[6U];
m_rawData[99U] = bits[7U]; m_rawData[99U] = bits[7U];
// Second block // Second block
CUtils::byteToBitsBE(in[21U], m_rawData + 100U); CUtils::byteToBitsBE(in[21U], m_rawData + 100U);
CUtils::byteToBitsBE(in[22U], m_rawData + 108U); CUtils::byteToBitsBE(in[22U], m_rawData + 108U);
@ -115,7 +115,7 @@ void CBPTC19696::decodeDeInterleave()
{ {
for (unsigned int i = 0U; i < 196U; i++) for (unsigned int i = 0U; i < 196U; i++)
m_deInterData[i] = false; m_deInterData[i] = false;
// The first bit is R(3) which is not used so can be ignored // The first bit is R(3) which is not used so can be ignored
for (unsigned int a = 0U; a < 196U; a++) { for (unsigned int a = 0U; a < 196U; a++) {
// Calculate the interleave sequence // Calculate the interleave sequence
@ -132,7 +132,7 @@ void CBPTC19696::decodeErrorCheck()
unsigned int count = 0U; unsigned int count = 0U;
do { do {
fixing = false; fixing = false;
// Run through each of the 15 columns // Run through each of the 15 columns
bool col[13U]; bool col[13U];
for (unsigned int c = 0U; c < 15U; c++) { for (unsigned int c = 0U; c < 15U; c++) {
@ -141,25 +141,25 @@ void CBPTC19696::decodeErrorCheck()
col[a] = m_deInterData[pos]; col[a] = m_deInterData[pos];
pos = pos + 15U; pos = pos + 15U;
} }
if (CHamming::decode1393(col)) { if (CHamming::decode1393(col)) {
unsigned int pos = c + 1U; unsigned int pos = c + 1U;
for (unsigned int a = 0U; a < 13U; a++) { for (unsigned int a = 0U; a < 13U; a++) {
m_deInterData[pos] = col[a]; m_deInterData[pos] = col[a];
pos = pos + 15U; pos = pos + 15U;
} }
fixing = true; fixing = true;
} }
} }
// Run through each of the 9 rows containing data // Run through each of the 9 rows containing data
for (unsigned int r = 0U; r < 9U; r++) { for (unsigned int r = 0U; r < 9U; r++) {
unsigned int pos = (r * 15U) + 1U; unsigned int pos = (r * 15U) + 1U;
if (CHamming::decode15113_2(m_deInterData + pos)) if (CHamming::decode15113_2(m_deInterData + pos))
fixing = true; fixing = true;
} }
count++; count++;
} while (fixing && count < 5U); } while (fixing && count < 5U);
} }
@ -171,31 +171,31 @@ void CBPTC19696::decodeExtractData(unsigned char* data) const
unsigned int pos = 0U; unsigned int pos = 0U;
for (unsigned int a = 4U; a <= 11U; a++, pos++) for (unsigned int a = 4U; a <= 11U; a++, pos++)
bData[pos] = m_deInterData[a]; bData[pos] = m_deInterData[a];
for (unsigned int a = 16U; a <= 26U; a++, pos++) for (unsigned int a = 16U; a <= 26U; a++, pos++)
bData[pos] = m_deInterData[a]; bData[pos] = m_deInterData[a];
for (unsigned int a = 31U; a <= 41U; a++, pos++) for (unsigned int a = 31U; a <= 41U; a++, pos++)
bData[pos] = m_deInterData[a]; bData[pos] = m_deInterData[a];
for (unsigned int a = 46U; a <= 56U; a++, pos++) for (unsigned int a = 46U; a <= 56U; a++, pos++)
bData[pos] = m_deInterData[a]; bData[pos] = m_deInterData[a];
for (unsigned int a = 61U; a <= 71U; a++, pos++) for (unsigned int a = 61U; a <= 71U; a++, pos++)
bData[pos] = m_deInterData[a]; bData[pos] = m_deInterData[a];
for (unsigned int a = 76U; a <= 86U; a++, pos++) for (unsigned int a = 76U; a <= 86U; a++, pos++)
bData[pos] = m_deInterData[a]; bData[pos] = m_deInterData[a];
for (unsigned int a = 91U; a <= 101U; a++, pos++) for (unsigned int a = 91U; a <= 101U; a++, pos++)
bData[pos] = m_deInterData[a]; bData[pos] = m_deInterData[a];
for (unsigned int a = 106U; a <= 116U; a++, pos++) for (unsigned int a = 106U; a <= 116U; a++, pos++)
bData[pos] = m_deInterData[a]; bData[pos] = m_deInterData[a];
for (unsigned int a = 121U; a <= 131U; a++, pos++) for (unsigned int a = 121U; a <= 131U; a++, pos++)
bData[pos] = m_deInterData[a]; bData[pos] = m_deInterData[a];
CUtils::bitsToByteBE(bData + 0U, data[0U]); CUtils::bitsToByteBE(bData + 0U, data[0U]);
CUtils::bitsToByteBE(bData + 8U, data[1U]); CUtils::bitsToByteBE(bData + 8U, data[1U]);
CUtils::bitsToByteBE(bData + 16U, data[2U]); CUtils::bitsToByteBE(bData + 16U, data[2U]);
@ -226,35 +226,35 @@ void CBPTC19696::encodeExtractData(const unsigned char* in)
CUtils::byteToBitsBE(in[9U], bData + 72U); CUtils::byteToBitsBE(in[9U], bData + 72U);
CUtils::byteToBitsBE(in[10U], bData + 80U); CUtils::byteToBitsBE(in[10U], bData + 80U);
CUtils::byteToBitsBE(in[11U], bData + 88U); CUtils::byteToBitsBE(in[11U], bData + 88U);
for (unsigned int i = 0U; i < 196U; i++) for (unsigned int i = 0U; i < 196U; i++)
m_deInterData[i] = false; m_deInterData[i] = false;
unsigned int pos = 0U; unsigned int pos = 0U;
for (unsigned int a = 4U; a <= 11U; a++, pos++) for (unsigned int a = 4U; a <= 11U; a++, pos++)
m_deInterData[a] = bData[pos]; m_deInterData[a] = bData[pos];
for (unsigned int a = 16U; a <= 26U; a++, pos++) for (unsigned int a = 16U; a <= 26U; a++, pos++)
m_deInterData[a] = bData[pos]; m_deInterData[a] = bData[pos];
for (unsigned int a = 31U; a <= 41U; a++, pos++) for (unsigned int a = 31U; a <= 41U; a++, pos++)
m_deInterData[a] = bData[pos]; m_deInterData[a] = bData[pos];
for (unsigned int a = 46U; a <= 56U; a++, pos++) for (unsigned int a = 46U; a <= 56U; a++, pos++)
m_deInterData[a] = bData[pos]; m_deInterData[a] = bData[pos];
for (unsigned int a = 61U; a <= 71U; a++, pos++) for (unsigned int a = 61U; a <= 71U; a++, pos++)
m_deInterData[a] = bData[pos]; m_deInterData[a] = bData[pos];
for (unsigned int a = 76U; a <= 86U; a++, pos++) for (unsigned int a = 76U; a <= 86U; a++, pos++)
m_deInterData[a] = bData[pos]; m_deInterData[a] = bData[pos];
for (unsigned int a = 91U; a <= 101U; a++, pos++) for (unsigned int a = 91U; a <= 101U; a++, pos++)
m_deInterData[a] = bData[pos]; m_deInterData[a] = bData[pos];
for (unsigned int a = 106U; a <= 116U; a++, pos++) for (unsigned int a = 106U; a <= 116U; a++, pos++)
m_deInterData[a] = bData[pos]; m_deInterData[a] = bData[pos];
for (unsigned int a = 121U; a <= 131U; a++, pos++) for (unsigned int a = 121U; a <= 131U; a++, pos++)
m_deInterData[a] = bData[pos]; m_deInterData[a] = bData[pos];
} }
@ -262,13 +262,13 @@ void CBPTC19696::encodeExtractData(const unsigned char* in)
// Check each row with a Hamming (15,11,3) code and each column with a Hamming (13,9,3) code // Check each row with a Hamming (15,11,3) code and each column with a Hamming (13,9,3) code
void CBPTC19696::encodeErrorCheck() void CBPTC19696::encodeErrorCheck()
{ {
// Run through each of the 9 rows containing data // Run through each of the 9 rows containing data
for (unsigned int r = 0U; r < 9U; r++) { for (unsigned int r = 0U; r < 9U; r++) {
unsigned int pos = (r * 15U) + 1U; unsigned int pos = (r * 15U) + 1U;
CHamming::encode15113_2(m_deInterData + pos); CHamming::encode15113_2(m_deInterData + pos);
} }
// Run through each of the 15 columns // Run through each of the 15 columns
bool col[13U]; bool col[13U];
for (unsigned int c = 0U; c < 15U; c++) { for (unsigned int c = 0U; c < 15U; c++) {
@ -277,9 +277,9 @@ void CBPTC19696::encodeErrorCheck()
col[a] = m_deInterData[pos]; col[a] = m_deInterData[pos];
pos = pos + 15U; pos = pos + 15U;
} }
CHamming::encode1393(col); CHamming::encode1393(col);
pos = c + 1U; pos = c + 1U;
for (unsigned int a = 0U; a < 13U; a++) { for (unsigned int a = 0U; a < 13U; a++) {
m_deInterData[pos] = col[a]; m_deInterData[pos] = col[a];
@ -293,7 +293,7 @@ void CBPTC19696::encodeInterleave()
{ {
for (unsigned int i = 0U; i < 196U; i++) for (unsigned int i = 0U; i < 196U; i++)
m_rawData[i] = false; m_rawData[i] = false;
// The first bit is R(3) which is not used so can be ignored // The first bit is R(3) which is not used so can be ignored
for (unsigned int a = 0U; a < 196U; a++) { for (unsigned int a = 0U; a < 196U; a++) {
// Calculate the interleave sequence // Calculate the interleave sequence
@ -318,13 +318,13 @@ void CBPTC19696::encodeExtractBinary(unsigned char* data)
CUtils::bitsToByteBE(m_rawData + 72U, data[9U]); CUtils::bitsToByteBE(m_rawData + 72U, data[9U]);
CUtils::bitsToByteBE(m_rawData + 80U, data[10U]); CUtils::bitsToByteBE(m_rawData + 80U, data[10U]);
CUtils::bitsToByteBE(m_rawData + 88U, data[11U]); CUtils::bitsToByteBE(m_rawData + 88U, data[11U]);
// Handle the two bits // Handle the two bits
unsigned char byte; unsigned char byte;
CUtils::bitsToByteBE(m_rawData + 96U, byte); CUtils::bitsToByteBE(m_rawData + 96U, byte);
data[12U] = (data[12U] & 0x3FU) | ((byte >> 0) & 0xC0U); data[12U] = (data[12U] & 0x3FU) | ((byte >> 0) & 0xC0U);
data[20U] = (data[20U] & 0xFCU) | ((byte >> 4) & 0x03U); data[20U] = (data[20U] & 0xFCU) | ((byte >> 4) & 0x03U);
// Second block // Second block
CUtils::bitsToByteBE(m_rawData + 100U, data[21U]); CUtils::bitsToByteBE(m_rawData + 100U, data[21U]);
CUtils::bitsToByteBE(m_rawData + 108U, data[22U]); CUtils::bitsToByteBE(m_rawData + 108U, data[22U]);

@ -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)

@ -19,7 +19,7 @@
// GNU General Public License for more details. // GNU General Public License for more details.
// //
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with Foobar. If not, see <http://www.gnu.org/licenses/>. // along with Foobar. If not, see <http://www.gnu.org/licenses/>.
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
#ifndef cclient_h #ifndef cclient_h
@ -43,13 +43,13 @@ public:
CClient(); CClient();
CClient(const CCallsign &, const CIp &, char = ' '); CClient(const CCallsign &, const CIp &, char = ' ');
CClient(const CClient &); CClient(const CClient &);
// destructor // destructor
virtual ~CClient() {}; virtual ~CClient() {};
// operators // operators
bool operator ==(const CClient &) const; bool operator ==(const CClient &) const;
// get // get
const CCallsign &GetCallsign(void) const { return m_Callsign; } const CCallsign &GetCallsign(void) const { return m_Callsign; }
const CIp &GetIp(void) const { return m_Ip; } const CIp &GetIp(void) const { return m_Ip; }
@ -57,11 +57,11 @@ public:
char GetModule(void) const { return m_Callsign.GetModule(); } char GetModule(void) const { return m_Callsign.GetModule(); }
bool HasReflectorModule(void) const { return m_ReflectorModule != ' '; } bool HasReflectorModule(void) const { return m_ReflectorModule != ' '; }
char GetReflectorModule(void) const { return m_ReflectorModule; } char GetReflectorModule(void) const { return m_ReflectorModule; }
// set // set
void SetModule(char c) { m_Callsign.SetModule(c); } void SetModule(char c) { m_Callsign.SetModule(c); }
void SetReflectorModule(char c) { m_ReflectorModule = c; } void SetReflectorModule(char c) { m_ReflectorModule = c; }
// identity // identity
virtual int GetProtocol(void) const { return PROTOCOL_NONE; } virtual int GetProtocol(void) const { return PROTOCOL_NONE; }
virtual int GetProtocolRevision(void) const { return 0; } virtual int GetProtocolRevision(void) const { return 0; }
@ -71,15 +71,15 @@ public:
virtual bool IsPeer(void) const { return false; } virtual bool IsPeer(void) const { return false; }
virtual bool IsDextraDongle(void) const { return false; } virtual bool IsDextraDongle(void) const { return false; }
virtual void SetDextraDongle(void) { } virtual void SetDextraDongle(void) { }
// status // status
virtual void Alive(void); virtual void Alive(void);
virtual bool IsAlive(void) const { return false; } virtual bool IsAlive(void) const { return false; }
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 &);
virtual void GetJsonObject(char *); virtual void GetJsonObject(char *);
@ -88,7 +88,7 @@ protected:
// data // data
CCallsign m_Callsign; CCallsign m_Callsign;
CIp m_Ip; CIp m_Ip;
// linked to // linked to
char m_ReflectorModule; char m_ReflectorModule;

@ -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,127 +120,127 @@ 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);
return crc == tcrc; return crc == 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) {
unsigned char c; unsigned char c;
CUtils::bitsToByteBE(in + i, c); CUtils::bitsToByteBE(in + i, c);
total += c; total += c;
} }
total %= 31U; total %= 31U;
tcrc = total; tcrc = total;
} }
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 {
uint16_t crc16; uint16_t crc16;
uint8_t crc8[2U]; uint8_t crc8[2U];
}; };
crc16 = 0U; crc16 = 0U;
for (unsigned i = 0U; i < (length - 2U); i++) for (unsigned i = 0U; i < (length - 2U); i++)
crc16 = (uint16_t(crc8[0U]) << 8) ^ CCITT16_TABLE2[crc8[1U] ^ in[i]]; crc16 = (uint16_t(crc8[0U]) << 8) ^ CCITT16_TABLE2[crc8[1U] ^ in[i]];
crc16 = ~crc16; crc16 = ~crc16;
in[length - 1U] = crc8[0U]; in[length - 1U] = crc8[0U];
in[length - 2U] = crc8[1U]; in[length - 2U] = crc8[1U];
} }
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 {
uint16_t crc16; uint16_t crc16;
uint8_t crc8[2U]; uint8_t crc8[2U];
}; };
crc16 = 0U; crc16 = 0U;
for (unsigned i = 0U; i < (length - 2U); i++) for (unsigned i = 0U; i < (length - 2U); i++)
crc16 = (uint16_t(crc8[0U]) << 8) ^ CCITT16_TABLE2[crc8[1U] ^ in[i]]; crc16 = (uint16_t(crc8[0U]) << 8) ^ CCITT16_TABLE2[crc8[1U] ^ in[i]];
crc16 = ~crc16; crc16 = ~crc16;
return crc8[0U] == in[length - 1U] && crc8[1U] == in[length - 2U]; return crc8[0U] == in[length - 1U] && crc8[1U] == in[length - 2U];
} }
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 {
uint16_t crc16; uint16_t crc16;
uint8_t crc8[2U]; uint8_t crc8[2U];
}; };
crc16 = 0xFFFFU; crc16 = 0xFFFFU;
for (unsigned int i = 0U; i < (length - 2U); i++) for (unsigned int i = 0U; i < (length - 2U); i++)
crc16 = uint16_t(crc8[1U]) ^ CCITT16_TABLE1[crc8[0U] ^ in[i]]; crc16 = uint16_t(crc8[1U]) ^ CCITT16_TABLE1[crc8[0U] ^ in[i]];
crc16 = ~crc16; crc16 = ~crc16;
in[length - 2U] = crc8[0U]; in[length - 2U] = crc8[0U];
in[length - 1U] = crc8[1U]; in[length - 1U] = crc8[1U];
} }
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 {
uint16_t crc16; uint16_t crc16;
uint8_t crc8[2U]; uint8_t crc8[2U];
}; };
crc16 = 0xFFFFU; crc16 = 0xFFFFU;
for (unsigned int i = 0U; i < (length - 2U); i++) for (unsigned int i = 0U; i < (length - 2U); i++)
crc16 = uint16_t(crc8[1U]) ^ CCITT16_TABLE1[crc8[0U] ^ in[i]]; crc16 = uint16_t(crc8[1U]) ^ CCITT16_TABLE1[crc8[0U] ^ in[i]];
crc16 = ~crc16; crc16 = ~crc16;
return crc8[0U] == in[length - 2U] && crc8[1U] == in[length - 1U]; return crc8[0U] == in[length - 2U] && crc8[1U] == in[length - 1U];
} }
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;
for (unsigned int i = 0U; i < length; i++) for (unsigned int i = 0U; i < length; i++)
crc = CRC8_TABLE[crc ^ in[i]]; crc = CRC8_TABLE[crc ^ in[i]];
return crc; return crc;
} }
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)

@ -56,7 +56,7 @@ bool CDmridDirFile::Init(void)
bool CDmridDirFile::NeedReload(void) bool CDmridDirFile::NeedReload(void)
{ {
bool needReload = false; bool needReload = false;
time_t time; time_t time;
if ( GetLastModTime(&time) ) if ( GetLastModTime(&time) )
{ {
@ -70,7 +70,7 @@ bool CDmridDirFile::LoadContent(CBuffer *buffer)
bool ok = false; bool ok = false;
std::ifstream file; std::ifstream file;
std::streampos size; std::streampos size;
// open file // open file
file.open(DMRIDDB_PATH, std::ios::in | std::ios::binary | std::ios::ate); file.open(DMRIDDB_PATH, std::ios::in | std::ios::binary | std::ios::ate);
if ( file.is_open() ) if ( file.is_open() )
@ -83,18 +83,18 @@ bool CDmridDirFile::LoadContent(CBuffer *buffer)
buffer->resize((int)size+1); buffer->resize((int)size+1);
file.seekg (0, std::ios::beg); file.seekg (0, std::ios::beg);
file.read((char *)buffer->data(), (int)size); file.read((char *)buffer->data(), (int)size);
// close file // close file
file.close(); file.close();
// update time // update time
GetLastModTime(&m_LastModTime); GetLastModTime(&m_LastModTime);
// done // done
ok = true; ok = true;
} }
} }
// done // done
return ok; return ok;
} }
@ -102,28 +102,28 @@ bool CDmridDirFile::LoadContent(CBuffer *buffer)
bool CDmridDirFile::RefreshContent(const CBuffer &buffer) bool CDmridDirFile::RefreshContent(const CBuffer &buffer)
{ {
bool ok = false; bool ok = false;
// clear directory // clear directory
m_CallsignMap.clear(); m_CallsignMap.clear();
m_DmridMap.clear(); m_DmridMap.clear();
// scan buffer // scan buffer
if ( buffer.size() > 0 ) if ( buffer.size() > 0 )
{ {
// crack it // crack it
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);
@ -138,14 +138,14 @@ bool CDmridDirFile::RefreshContent(const CBuffer &buffer)
// next line // next line
ptr1 = ptr2+1; ptr1 = ptr2+1;
} }
// done // done
ok = true; ok = true;
} }
// report // report
std::cout << "Read " << m_DmridMap.size() << " DMR ids from file " << DMRIDDB_PATH << std::endl; std::cout << "Read " << m_DmridMap.size() << " DMR ids from file " << DMRIDDB_PATH << std::endl;
// done // done
return ok; return ok;
} }
@ -154,7 +154,7 @@ bool CDmridDirFile::RefreshContent(const CBuffer &buffer)
bool CDmridDirFile::GetLastModTime(time_t *time) bool CDmridDirFile::GetLastModTime(time_t *time)
{ {
bool ok = false; bool ok = false;
struct stat fileStat; struct stat fileStat;
if( ::stat(DMRIDDB_PATH, &fileStat) != -1 ) if( ::stat(DMRIDDB_PATH, &fileStat) != -1 )
{ {

@ -50,22 +50,22 @@ bool CDmridDirHttp::RefreshContent(const CBuffer &buffer)
// clear directory // clear directory
m_CallsignMap.clear(); m_CallsignMap.clear();
m_DmridMap.clear(); m_DmridMap.clear();
// scan file // scan file
if ( buffer.size() > 0 ) if ( buffer.size() > 0 )
{ {
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);
@ -83,10 +83,10 @@ bool CDmridDirHttp::RefreshContent(const CBuffer &buffer)
// done // done
ok = true; ok = true;
} }
// report // report
std::cout << "Read " << m_DmridMap.size() << " DMR ids from xlxapi.rlx.lu database " << std::endl; std::cout << "Read " << m_DmridMap.size() << " DMR ids from xlxapi.rlx.lu database " << std::endl;
// done // done
return ok; return ok;
} }
@ -101,7 +101,7 @@ bool CDmridDirHttp::HttpGet(const char *hostname, const char *filename, int port
{ {
bool ok = false; bool ok = false;
int sock_id; int sock_id;
// open socket // open socket
if ( (sock_id = ::socket(AF_INET, SOCK_STREAM, 0)) >= 0 ) if ( (sock_id = ::socket(AF_INET, SOCK_STREAM, 0)) >= 0 )
{ {
@ -109,13 +109,13 @@ bool CDmridDirHttp::HttpGet(const char *hostname, const char *filename, int port
struct sockaddr_in servaddr; struct 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);
servaddr.sin_port = htons(port); servaddr.sin_port = htons(port);
servaddr.sin_family = AF_INET; servaddr.sin_family = AF_INET;
// connect // connect
if ( ::connect(sock_id, (struct sockaddr *)&servaddr, sizeof(servaddr)) == 0) if ( ::connect(sock_id, (struct sockaddr *)&servaddr, sizeof(servaddr)) == 0)
{ {
@ -124,7 +124,7 @@ bool CDmridDirHttp::HttpGet(const char *hostname, const char *filename, int port
::sprintf(request, "GET /%s HTTP/1.0\r\nFrom: %s\r\nUser-Agent: xlxd\r\n\r\n", ::sprintf(request, "GET /%s HTTP/1.0\r\nFrom: %s\r\nUser-Agent: xlxd\r\n\r\n",
filename, (const char *)g_Reflector.GetCallsign()); filename, (const char *)g_Reflector.GetCallsign());
::write(sock_id, request, strlen(request)); ::write(sock_id, request, strlen(request));
// config receive timeouts // config receive timeouts
fd_set read_set; fd_set read_set;
struct timeval timeout; struct timeval timeout;
@ -132,7 +132,7 @@ bool CDmridDirHttp::HttpGet(const char *hostname, const char *filename, int port
timeout.tv_usec = 0; timeout.tv_usec = 0;
FD_ZERO(&read_set); FD_ZERO(&read_set);
FD_SET(sock_id, &read_set); FD_SET(sock_id, &read_set);
// get the reply back // get the reply back
buffer->clear(); buffer->clear();
bool done = false; bool done = false;
@ -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 )
//{ //{
@ -153,10 +153,10 @@ bool CDmridDirHttp::HttpGet(const char *hostname, const char *filename, int port
} }
//} //}
done = (len <= 0); done = (len <= 0);
} while (!done); } while (!done);
buffer->Append((uint8)0); buffer->Append((uint8)0);
// and disconnect // and disconnect
close(sock_id); close(sock_id);
} }
@ -169,13 +169,13 @@ bool CDmridDirHttp::HttpGet(const char *hostname, const char *filename, int port
{ {
std::cout << "Host " << hostname << " not found" << std::endl; std::cout << "Host " << hostname << " not found" << std::endl;
} }
} }
else else
{ {
std::cout << "Failed to open wget socket" << std::endl; std::cout << "Failed to open wget socket" << std::endl;
} }
// done // done
return ok; return ok;
} }

@ -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

@ -222,41 +222,41 @@ unsigned int CGolay2087::getSyndrome1987(unsigned int pattern)
*/ */
{ {
unsigned int aux = X18; unsigned int aux = X18;
if (pattern >= X11) { if (pattern >= X11) {
while (pattern & MASK8) { while (pattern & MASK8) {
while (!(aux & pattern)) while (!(aux & pattern))
aux = aux >> 1; aux = aux >> 1;
pattern ^= (aux / X11) * GENPOL; pattern ^= (aux / X11) * GENPOL;
} }
} }
return pattern; return 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);
unsigned int error_pattern = DECODING_TABLE_1987[syndrome]; unsigned int error_pattern = DECODING_TABLE_1987[syndrome];
if (error_pattern != 0x00U) if (error_pattern != 0x00U)
code ^= error_pattern; code ^= error_pattern;
return code >> 11; return code >> 11;
} }
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];
unsigned int cksum = ENCODING_TABLE_2087[value]; unsigned int cksum = ENCODING_TABLE_2087[value];
data[1U] = cksum & 0xFFU; data[1U] = cksum & 0xFFU;
data[2U] = cksum >> 8; data[2U] = cksum >> 8;
} }

@ -1056,16 +1056,16 @@ static unsigned int get_syndrome_23127(unsigned int pattern)
*/ */
{ {
unsigned int aux = X22; unsigned int aux = X22;
if (pattern >= X11) { if (pattern >= X11) {
while (pattern & MASK12) { while (pattern & MASK12) {
while (!(aux & pattern)) while (!(aux & pattern))
aux = aux >> 1; aux = aux >> 1;
pattern ^= (aux / X11) * GENPOL; pattern ^= (aux / X11) * GENPOL;
} }
} }
return pattern; return pattern;
} }
@ -1083,9 +1083,9 @@ unsigned int CGolay24128::decode23127(unsigned int code)
{ {
unsigned int syndrome = ::get_syndrome_23127(code); unsigned int syndrome = ::get_syndrome_23127(code);
unsigned int error_pattern = DECODING_TABLE_23127[syndrome]; unsigned int error_pattern = DECODING_TABLE_23127[syndrome];
code ^= error_pattern; code ^= error_pattern;
return code >> 11; return code >> 11;
} }
@ -1096,13 +1096,13 @@ 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;
code |= bytes[1U]; code |= bytes[1U];
code <<= 8; code <<= 8;
code |= bytes[2U]; code |= bytes[2U];
return decode23127(code >> 1); return decode23127(code >> 1);
} }

@ -24,20 +24,20 @@
// 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];
bool c1 = d[0] ^ d[1] ^ d[2] ^ d[3] ^ d[7] ^ d[8] ^ d[9]; bool c1 = d[0] ^ d[1] ^ d[2] ^ d[3] ^ d[7] ^ d[8] ^ d[9];
bool c2 = d[0] ^ d[1] ^ d[4] ^ d[5] ^ d[7] ^ d[8] ^ d[10]; bool c2 = d[0] ^ d[1] ^ d[4] ^ d[5] ^ d[7] ^ d[8] ^ d[10];
bool c3 = d[0] ^ d[2] ^ d[4] ^ d[6] ^ d[7] ^ d[9] ^ d[10]; bool c3 = d[0] ^ d[2] ^ d[4] ^ d[6] ^ d[7] ^ d[9] ^ d[10];
unsigned char n = 0U; unsigned char n = 0U;
n |= (c0 != d[11]) ? 0x01U : 0x00U; n |= (c0 != d[11]) ? 0x01U : 0x00U;
n |= (c1 != d[12]) ? 0x02U : 0x00U; n |= (c1 != d[12]) ? 0x02U : 0x00U;
n |= (c2 != d[13]) ? 0x04U : 0x00U; n |= (c2 != d[13]) ? 0x04U : 0x00U;
n |= (c3 != d[14]) ? 0x08U : 0x00U; n |= (c3 != d[14]) ? 0x08U : 0x00U;
switch (n) switch (n)
{ {
// Parity bit errors // Parity bit errors
@ -45,7 +45,7 @@ bool CHamming::decode15113_1(bool* d)
case 0x02U: d[12] = !d[12]; return true; case 0x02U: d[12] = !d[12]; return true;
case 0x04U: d[13] = !d[13]; return true; case 0x04U: d[13] = !d[13]; return true;
case 0x08U: d[14] = !d[14]; return true; case 0x08U: d[14] = !d[14]; return true;
// Data bit errors // Data bit errors
case 0x0FU: d[0] = !d[0]; return true; case 0x0FU: d[0] = !d[0]; return true;
case 0x07U: d[1] = !d[1]; return true; case 0x07U: d[1] = !d[1]; return true;
@ -58,7 +58,7 @@ bool CHamming::decode15113_1(bool* d)
case 0x06U: d[8] = !d[8]; return true; case 0x06U: d[8] = !d[8]; return true;
case 0x0AU: d[9] = !d[9]; return true; case 0x0AU: d[9] = !d[9]; return true;
case 0x0CU: d[10] = !d[10]; return true; case 0x0CU: d[10] = !d[10]; return true;
// No bit errors // No bit errors
default: return false; default: return false;
} }
@ -66,8 +66,8 @@ 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];
d[12] = d[0] ^ d[1] ^ d[2] ^ d[3] ^ d[7] ^ d[8] ^ d[9]; d[12] = d[0] ^ d[1] ^ d[2] ^ d[3] ^ d[7] ^ d[8] ^ d[9];
@ -78,27 +78,27 @@ void CHamming::encode15113_1(bool* d)
// Hamming (15,11,3) check a boolean data array // 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];
bool c1 = d[1] ^ d[2] ^ d[3] ^ d[4] ^ d[6] ^ d[8] ^ d[9]; bool c1 = d[1] ^ d[2] ^ d[3] ^ d[4] ^ d[6] ^ d[8] ^ d[9];
bool c2 = d[2] ^ d[3] ^ d[4] ^ d[5] ^ d[7] ^ d[9] ^ d[10]; bool c2 = d[2] ^ d[3] ^ d[4] ^ d[5] ^ d[7] ^ d[9] ^ d[10];
bool c3 = d[0] ^ d[1] ^ d[2] ^ d[4] ^ d[6] ^ d[7] ^ d[10]; bool c3 = d[0] ^ d[1] ^ d[2] ^ d[4] ^ d[6] ^ d[7] ^ d[10];
unsigned char n = 0x00U; unsigned char n = 0x00U;
n |= (c0 != d[11]) ? 0x01U : 0x00U; n |= (c0 != d[11]) ? 0x01U : 0x00U;
n |= (c1 != d[12]) ? 0x02U : 0x00U; n |= (c1 != d[12]) ? 0x02U : 0x00U;
n |= (c2 != d[13]) ? 0x04U : 0x00U; n |= (c2 != d[13]) ? 0x04U : 0x00U;
n |= (c3 != d[14]) ? 0x08U : 0x00U; n |= (c3 != d[14]) ? 0x08U : 0x00U;
switch (n) { switch (n) {
// Parity bit errors // Parity bit errors
case 0x01U: d[11] = !d[11]; return true; case 0x01U: d[11] = !d[11]; return true;
case 0x02U: d[12] = !d[12]; return true; case 0x02U: d[12] = !d[12]; return true;
case 0x04U: d[13] = !d[13]; return true; case 0x04U: d[13] = !d[13]; return true;
case 0x08U: d[14] = !d[14]; return true; case 0x08U: d[14] = !d[14]; return true;
// Data bit errors // Data bit errors
case 0x09U: d[0] = !d[0]; return true; case 0x09U: d[0] = !d[0]; return true;
case 0x0BU: d[1] = !d[1]; return true; case 0x0BU: d[1] = !d[1]; return true;
@ -111,7 +111,7 @@ bool CHamming::decode15113_2(bool* d)
case 0x03U: d[8] = !d[8]; return true; case 0x03U: d[8] = !d[8]; return true;
case 0x06U: d[9] = !d[9]; return true; case 0x06U: d[9] = !d[9]; return true;
case 0x0CU: d[10] = !d[10]; return true; case 0x0CU: d[10] = !d[10]; return true;
// No bit errors // No bit errors
default: return false; default: return false;
} }
@ -119,8 +119,8 @@ 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];
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];
@ -131,27 +131,27 @@ 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];
bool c1 = d[0] ^ d[1] ^ d[2] ^ d[4] ^ d[6] ^ d[7]; bool c1 = d[0] ^ d[1] ^ d[2] ^ d[4] ^ d[6] ^ d[7];
bool c2 = d[0] ^ d[1] ^ d[2] ^ d[3] ^ d[5] ^ d[7] ^ d[8]; bool c2 = d[0] ^ d[1] ^ d[2] ^ d[3] ^ d[5] ^ d[7] ^ d[8];
bool c3 = d[0] ^ d[2] ^ d[4] ^ d[5] ^ d[8]; bool c3 = d[0] ^ d[2] ^ d[4] ^ d[5] ^ d[8];
unsigned char n = 0x00U; unsigned char n = 0x00U;
n |= (c0 != d[9]) ? 0x01U : 0x00U; n |= (c0 != d[9]) ? 0x01U : 0x00U;
n |= (c1 != d[10]) ? 0x02U : 0x00U; n |= (c1 != d[10]) ? 0x02U : 0x00U;
n |= (c2 != d[11]) ? 0x04U : 0x00U; n |= (c2 != d[11]) ? 0x04U : 0x00U;
n |= (c3 != d[12]) ? 0x08U : 0x00U; n |= (c3 != d[12]) ? 0x08U : 0x00U;
switch (n) { switch (n) {
// Parity bit errors // Parity bit errors
case 0x01U: d[9] = !d[9]; return true; case 0x01U: d[9] = !d[9]; return true;
case 0x02U: d[10] = !d[10]; return true; case 0x02U: d[10] = !d[10]; return true;
case 0x04U: d[11] = !d[11]; return true; case 0x04U: d[11] = !d[11]; return true;
case 0x08U: d[12] = !d[12]; return true; case 0x08U: d[12] = !d[12]; return true;
// Data bit erros // Data bit erros
case 0x0FU: d[0] = !d[0]; return true; case 0x0FU: d[0] = !d[0]; return true;
case 0x07U: d[1] = !d[1]; return true; case 0x07U: d[1] = !d[1]; return true;
@ -162,7 +162,7 @@ bool CHamming::decode1393(bool* d)
case 0x03U: d[6] = !d[6]; return true; case 0x03U: d[6] = !d[6]; return true;
case 0x06U: d[7] = !d[7]; return true; case 0x06U: d[7] = !d[7]; return true;
case 0x0CU: d[8] = !d[8]; return true; case 0x0CU: d[8] = !d[8]; return true;
// No bit errors // No bit errors
default: return false; default: return false;
} }
@ -170,8 +170,8 @@ 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];
d[10] = d[0] ^ d[1] ^ d[2] ^ d[4] ^ d[6] ^ d[7]; d[10] = d[0] ^ d[1] ^ d[2] ^ d[4] ^ d[6] ^ d[7];
@ -182,27 +182,27 @@ void CHamming::encode1393(bool* d)
// Hamming (10,6,3) check a boolean data array // 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];
bool c1 = d[0] ^ d[1] ^ d[3] ^ d[5]; bool c1 = d[0] ^ d[1] ^ d[3] ^ d[5];
bool c2 = d[0] ^ d[2] ^ d[3] ^ d[4]; bool c2 = d[0] ^ d[2] ^ d[3] ^ d[4];
bool c3 = d[1] ^ d[2] ^ d[3] ^ d[4]; bool c3 = d[1] ^ d[2] ^ d[3] ^ d[4];
unsigned char n = 0x00U; unsigned char n = 0x00U;
n |= (c0 != d[6]) ? 0x01U : 0x00U; n |= (c0 != d[6]) ? 0x01U : 0x00U;
n |= (c1 != d[7]) ? 0x02U : 0x00U; n |= (c1 != d[7]) ? 0x02U : 0x00U;
n |= (c2 != d[8]) ? 0x04U : 0x00U; n |= (c2 != d[8]) ? 0x04U : 0x00U;
n |= (c3 != d[9]) ? 0x08U : 0x00U; n |= (c3 != d[9]) ? 0x08U : 0x00U;
switch (n) { switch (n) {
// Parity bit errors // Parity bit errors
case 0x01U: d[6] = !d[6]; return true; case 0x01U: d[6] = !d[6]; return true;
case 0x02U: d[7] = !d[7]; return true; case 0x02U: d[7] = !d[7]; return true;
case 0x04U: d[8] = !d[8]; return true; case 0x04U: d[8] = !d[8]; return true;
case 0x08U: d[9] = !d[9]; return true; case 0x08U: d[9] = !d[9]; return true;
// Data bit erros // Data bit erros
case 0x07U: d[0] = !d[0]; return true; case 0x07U: d[0] = !d[0]; return true;
case 0x0BU: d[1] = !d[1]; return true; case 0x0BU: d[1] = !d[1]; return true;
@ -210,7 +210,7 @@ bool CHamming::decode1063(bool* d)
case 0x0EU: d[3] = !d[3]; return true; case 0x0EU: d[3] = !d[3]; return true;
case 0x0CU: d[4] = !d[4]; return true; case 0x0CU: d[4] = !d[4]; return true;
case 0x03U: d[5] = !d[5]; return true; case 0x03U: d[5] = !d[5]; return true;
// No bit errors // No bit errors
default: return false; default: return false;
} }
@ -218,8 +218,8 @@ 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];
d[7] = d[0] ^ d[1] ^ d[3] ^ d[5]; d[7] = d[0] ^ d[1] ^ d[3] ^ d[5];
@ -230,15 +230,15 @@ void CHamming::encode1063(bool* d)
// A Hamming (16,11,4) Check // 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];
bool c1 = d[1] ^ d[2] ^ d[3] ^ d[4] ^ d[6] ^ d[8] ^ d[9]; bool c1 = d[1] ^ d[2] ^ d[3] ^ d[4] ^ d[6] ^ d[8] ^ d[9];
bool c2 = d[2] ^ d[3] ^ d[4] ^ d[5] ^ d[7] ^ d[9] ^ d[10]; bool c2 = d[2] ^ d[3] ^ d[4] ^ d[5] ^ d[7] ^ d[9] ^ d[10];
bool c3 = d[0] ^ d[1] ^ d[2] ^ d[4] ^ d[6] ^ d[7] ^ d[10]; bool c3 = d[0] ^ d[1] ^ d[2] ^ d[4] ^ d[6] ^ d[7] ^ d[10];
bool c4 = d[0] ^ d[2] ^ d[5] ^ d[6] ^ d[8] ^ d[9] ^ d[10]; bool c4 = d[0] ^ d[2] ^ d[5] ^ d[6] ^ d[8] ^ d[9] ^ d[10];
// Compare these with the actual bits // Compare these with the actual bits
unsigned char n = 0x00U; unsigned char n = 0x00U;
n |= (c0 != d[11]) ? 0x01U : 0x00U; n |= (c0 != d[11]) ? 0x01U : 0x00U;
@ -246,7 +246,7 @@ bool CHamming::decode16114(bool* d)
n |= (c2 != d[13]) ? 0x04U : 0x00U; n |= (c2 != d[13]) ? 0x04U : 0x00U;
n |= (c3 != d[14]) ? 0x08U : 0x00U; n |= (c3 != d[14]) ? 0x08U : 0x00U;
n |= (c4 != d[15]) ? 0x10U : 0x00U; n |= (c4 != d[15]) ? 0x10U : 0x00U;
switch (n) { switch (n) {
// Parity bit errors // Parity bit errors
case 0x01U: d[11] = !d[11]; return true; case 0x01U: d[11] = !d[11]; return true;
@ -254,7 +254,7 @@ bool CHamming::decode16114(bool* d)
case 0x04U: d[13] = !d[13]; return true; case 0x04U: d[13] = !d[13]; return true;
case 0x08U: d[14] = !d[14]; return true; case 0x08U: d[14] = !d[14]; return true;
case 0x10U: d[15] = !d[15]; return true; case 0x10U: d[15] = !d[15]; return true;
// Data bit errors // Data bit errors
case 0x19U: d[0] = !d[0]; return true; case 0x19U: d[0] = !d[0]; return true;
case 0x0BU: d[1] = !d[1]; return true; case 0x0BU: d[1] = !d[1]; return true;
@ -267,10 +267,10 @@ bool CHamming::decode16114(bool* d)
case 0x13U: d[8] = !d[8]; return true; case 0x13U: d[8] = !d[8]; return true;
case 0x16U: d[9] = !d[9]; return true; case 0x16U: d[9] = !d[9]; return true;
case 0x1CU: d[10] = !d[10]; return true; case 0x1CU: d[10] = !d[10]; return true;
// No bit errors // No bit errors
case 0x00U: return true; case 0x00U: return true;
// Unrecoverable errors // Unrecoverable errors
default: return false; default: return false;
} }
@ -278,8 +278,8 @@ 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];
d[13] = d[2] ^ d[3] ^ d[4] ^ d[5] ^ d[7] ^ d[9] ^ d[10]; d[13] = d[2] ^ d[3] ^ d[4] ^ d[5] ^ d[7] ^ d[9] ^ d[10];
@ -290,15 +290,15 @@ void CHamming::encode16114(bool* d)
// A Hamming (17,12,3) Check // 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];
bool c1 = d[0] ^ d[1] ^ d[2] ^ d[3] ^ d[4] ^ d[7] ^ d[8] ^ d[10]; bool c1 = d[0] ^ d[1] ^ d[2] ^ d[3] ^ d[4] ^ d[7] ^ d[8] ^ d[10];
bool c2 = d[1] ^ d[2] ^ d[3] ^ d[4] ^ d[5] ^ d[8] ^ d[9] ^ d[11]; bool c2 = d[1] ^ d[2] ^ d[3] ^ d[4] ^ d[5] ^ d[8] ^ d[9] ^ d[11];
bool c3 = d[0] ^ d[1] ^ d[4] ^ d[5] ^ d[7] ^ d[10]; bool c3 = d[0] ^ d[1] ^ d[4] ^ d[5] ^ d[7] ^ d[10];
bool c4 = d[0] ^ d[1] ^ d[2] ^ d[5] ^ d[6] ^ d[8] ^ d[11]; bool c4 = d[0] ^ d[1] ^ d[2] ^ d[5] ^ d[6] ^ d[8] ^ d[11];
// Compare these with the actual bits // Compare these with the actual bits
unsigned char n = 0x00U; unsigned char n = 0x00U;
n |= (c0 != d[12]) ? 0x01U : 0x00U; n |= (c0 != d[12]) ? 0x01U : 0x00U;
@ -306,7 +306,7 @@ bool CHamming::decode17123(bool* d)
n |= (c2 != d[14]) ? 0x04U : 0x00U; n |= (c2 != d[14]) ? 0x04U : 0x00U;
n |= (c3 != d[15]) ? 0x08U : 0x00U; n |= (c3 != d[15]) ? 0x08U : 0x00U;
n |= (c4 != d[16]) ? 0x10U : 0x00U; n |= (c4 != d[16]) ? 0x10U : 0x00U;
switch (n) { switch (n) {
// Parity bit errors // Parity bit errors
case 0x01U: d[12] = !d[12]; return true; case 0x01U: d[12] = !d[12]; return true;
@ -314,7 +314,7 @@ bool CHamming::decode17123(bool* d)
case 0x04U: d[14] = !d[14]; return true; case 0x04U: d[14] = !d[14]; return true;
case 0x08U: d[15] = !d[15]; return true; case 0x08U: d[15] = !d[15]; return true;
case 0x10U: d[16] = !d[16]; return true; case 0x10U: d[16] = !d[16]; return true;
// Data bit errors // Data bit errors
case 0x1BU: d[0] = !d[0]; return true; case 0x1BU: d[0] = !d[0]; return true;
case 0x1FU: d[1] = !d[1]; return true; case 0x1FU: d[1] = !d[1]; return true;
@ -328,10 +328,10 @@ bool CHamming::decode17123(bool* d)
case 0x05U: d[9] = !d[9]; return true; case 0x05U: d[9] = !d[9]; return true;
case 0x0AU: d[10] = !d[10]; return true; case 0x0AU: d[10] = !d[10]; return true;
case 0x14U: d[11] = !d[11]; return true; case 0x14U: d[11] = !d[11]; return true;
// No bit errors // No bit errors
case 0x00U: return true; case 0x00U: return true;
// Unrecoverable errors // Unrecoverable errors
default: return false; default: return false;
} }
@ -339,8 +339,8 @@ 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];
d[14] = d[1] ^ d[2] ^ d[3] ^ d[4] ^ d[5] ^ d[8] ^ d[9] ^ d[11]; d[14] = d[1] ^ d[2] ^ d[3] ^ d[4] ^ d[5] ^ d[8] ^ d[9] ^ d[11];

@ -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

@ -51,7 +51,7 @@ public:
protected: protected:
// data // data
std::mutex m_Mutex; std::mutex m_Mutex;
std::list<CProtocol *> m_Protocols; std::list<CProtocol *> m_Protocols;
}; };

@ -75,40 +75,40 @@ unsigned int CQR1676::getSyndrome1576(unsigned int pattern)
*/ */
{ {
unsigned int aux = X14; unsigned int aux = X14;
if (pattern >= X8) { if (pattern >= X8) {
while (pattern & MASK7) { while (pattern & MASK7) {
while (!(aux & pattern)) while (!(aux & pattern))
aux = aux >> 1; aux = aux >> 1;
pattern ^= (aux / X8) * GENPOL; pattern ^= (aux / X8) * GENPOL;
} }
} }
return pattern; return 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];
data[0U] = cksum >> 8; data[0U] = cksum >> 8;
data[1U] = cksum & 0xFFU; data[1U] = cksum & 0xFFU;
} }
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);
unsigned int error_pattern = DECODING_TABLE_1576[syndrome]; unsigned int error_pattern = DECODING_TABLE_1576[syndrome];
code ^= error_pattern; code ^= error_pattern;
return code >> 7; return code >> 7;
} }

@ -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 *);

@ -87,10 +87,10 @@ static unsigned char gmult(unsigned char a, unsigned char b)
{ {
if (a == 0U || b == 0U) if (a == 0U || b == 0U)
return 0U; return 0U;
unsigned int i = LOG_TABLE[a]; unsigned int i = LOG_TABLE[a];
unsigned int j = LOG_TABLE[b]; unsigned int j = LOG_TABLE[b];
return EXP_TABLE[i + j]; return EXP_TABLE[i + j];
} }
@ -101,18 +101,18 @@ static unsigned char gmult(unsigned char a, unsigned char b)
*/ */
void CRS129::encode(const unsigned char* msg, unsigned int nbytes, unsigned char* parity) 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;
for (unsigned int i = 0U; i < nbytes; i++) { for (unsigned int i = 0U; i < nbytes; i++) {
unsigned char dbyte = msg[i] ^ parity[NPAR - 1U]; unsigned char dbyte = msg[i] ^ parity[NPAR - 1U];
for (int j = NPAR - 1; j > 0; j--) for (int j = NPAR - 1; j > 0; j--)
parity[j] = parity[j - 1] ^ ::gmult(POLY[j], dbyte); parity[j] = parity[j - 1] ^ ::gmult(POLY[j], dbyte);
parity[0] = ::gmult(POLY[0], dbyte); parity[0] = ::gmult(POLY[0], dbyte);
} }
} }
@ -120,11 +120,10 @@ void CRS129::encode(const unsigned char* msg, unsigned int nbytes, unsigned char
// Reed-Solomon (12,9) check // 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)
{ {

@ -19,7 +19,7 @@
// GNU General Public License for more details. // GNU General Public License for more details.
// //
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with Foobar. If not, see <http://www.gnu.org/licenses/>. // along with Foobar. If not, see <http://www.gnu.org/licenses/>.
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
#include "main.h" #include "main.h"
@ -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)
@ -93,12 +93,12 @@ void CUser::GetJsonObject(char *Buffer)
char mbstr[100]; char mbstr[100];
char my[16]; char my[16];
char rpt1[16]; char rpt1[16];
if (std::strftime(mbstr, sizeof(mbstr), "%A %c", std::localtime(&m_LastHeardTime))) if (std::strftime(mbstr, sizeof(mbstr), "%A %c", std::localtime(&m_LastHeardTime)))
{ {
m_My.GetCallsignString(my); m_My.GetCallsignString(my);
m_Rpt1.GetCallsignString(rpt1); m_Rpt1.GetCallsignString(rpt1);
::sprintf(sz, "{\"callsign\":\"%s\",\"node\":\"%s\",\"module\":\"%c\",\"time\":\"%s\"}", ::sprintf(sz, "{\"callsign\":\"%s\",\"node\":\"%s\",\"module\":\"%c\",\"time\":\"%s\"}",
my, my,
rpt1, rpt1,

@ -19,7 +19,7 @@
// GNU General Public License for more details. // GNU General Public License for more details.
// //
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with Foobar. If not, see <http://www.gnu.org/licenses/>. // along with Foobar. If not, see <http://www.gnu.org/licenses/>.
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
#ifndef cuser_h #ifndef cuser_h
@ -37,12 +37,12 @@ public:
CUser(); CUser();
CUser(const CCallsign &, const CCallsign &, const CCallsign &, const CCallsign &); CUser(const CCallsign &, const CCallsign &, const CCallsign &, const CCallsign &);
CUser(const CUser &); CUser(const CUser &);
// destructor // destructor
~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,8 +18,8 @@
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;
bits[2U] = (byte & 0x20U) == 0x20U; bits[2U] = (byte & 0x20U) == 0x20U;
@ -32,8 +32,8 @@ void CUtils::byteToBitsBE(unsigned char byte, bool* bits)
void CUtils::byteToBitsLE(unsigned char byte, bool* bits) 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;
bits[2U] = (byte & 0x04U) == 0x04U; bits[2U] = (byte & 0x04U) == 0x04U;
@ -46,8 +46,8 @@ void CUtils::byteToBitsLE(unsigned char byte, bool* bits)
void CUtils::bitsToByteBE(const bool* bits, unsigned char& byte) 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;
byte |= bits[2U] ? 0x20U : 0x00U; byte |= bits[2U] ? 0x20U : 0x00U;
@ -60,8 +60,8 @@ void CUtils::bitsToByteBE(const bool* bits, unsigned char& byte)
void CUtils::bitsToByteLE(const bool* bits, unsigned char& byte) 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;
byte |= bits[2U] ? 0x04U : 0x00U; byte |= bits[2U] ? 0x04U : 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];
@ -59,7 +59,7 @@ void CYSFConvolution::start()
{ {
::memset(m_metrics1, 0x00U, NUM_OF_STATES * sizeof(uint16_t)); ::memset(m_metrics1, 0x00U, NUM_OF_STATES * sizeof(uint16_t));
::memset(m_metrics2, 0x00U, NUM_OF_STATES * sizeof(uint16_t)); ::memset(m_metrics2, 0x00U, NUM_OF_STATES * sizeof(uint16_t));
m_oldMetrics = m_metrics1; m_oldMetrics = m_metrics1;
m_newMetrics = m_metrics2; m_newMetrics = m_metrics2;
m_dp = m_decisions; m_dp = m_decisions;
@ -68,29 +68,29 @@ void CYSFConvolution::start()
void CYSFConvolution::decode(uint8_t s0, uint8_t s1) void CYSFConvolution::decode(uint8_t s0, uint8_t s1)
{ {
*m_dp = 0U; *m_dp = 0U;
for (uint8_t i = 0U; i < NUM_OF_STATES_D2; i++) { for (uint8_t i = 0U; i < NUM_OF_STATES_D2; i++) {
uint8_t j = i * 2U; uint8_t j = i * 2U;
uint16_t metric = (BRANCH_TABLE1[i] ^ s0) + (BRANCH_TABLE2[i] ^ s1); uint16_t metric = (BRANCH_TABLE1[i] ^ s0) + (BRANCH_TABLE2[i] ^ s1);
uint16_t m0 = m_oldMetrics[i] + metric; uint16_t m0 = m_oldMetrics[i] + metric;
uint16_t m1 = m_oldMetrics[i + NUM_OF_STATES_D2] + (M - metric); uint16_t m1 = m_oldMetrics[i + NUM_OF_STATES_D2] + (M - metric);
uint8_t decision0 = (m0 >= m1) ? 1U : 0U; uint8_t decision0 = (m0 >= m1) ? 1U : 0U;
m_newMetrics[j + 0U] = decision0 != 0U ? m1 : m0; m_newMetrics[j + 0U] = decision0 != 0U ? m1 : m0;
m0 = m_oldMetrics[i] + (M - metric); m0 = m_oldMetrics[i] + (M - metric);
m1 = m_oldMetrics[i + NUM_OF_STATES_D2] + metric; m1 = m_oldMetrics[i + NUM_OF_STATES_D2] + metric;
uint8_t decision1 = (m0 >= m1) ? 1U : 0U; uint8_t decision1 = (m0 >= m1) ? 1U : 0U;
m_newMetrics[j + 1U] = decision1 != 0U ? m1 : m0; m_newMetrics[j + 1U] = decision1 != 0U ? m1 : m0;
*m_dp |= (uint64_t(decision1) << (j + 1U)) | (uint64_t(decision0) << (j + 0U)); *m_dp |= (uint64_t(decision1) << (j + 1U)) | (uint64_t(decision0) << (j + 0U));
} }
++m_dp; ++m_dp;
assert((m_dp - m_decisions) <= 180); assert((m_dp - m_decisions) <= 180);
uint16_t* tmp = m_oldMetrics; uint16_t* tmp = m_oldMetrics;
m_oldMetrics = m_newMetrics; m_oldMetrics = m_newMetrics;
m_newMetrics = tmp; m_newMetrics = tmp;
@ -98,43 +98,43 @@ void CYSFConvolution::decode(uint8_t s0, uint8_t s1)
void CYSFConvolution::chainback(unsigned char* out, unsigned int nBits) void CYSFConvolution::chainback(unsigned char* out, unsigned int nBits)
{ {
assert(out != NULL); assert(out != nullptr);
uint32_t state = 0U; uint32_t state = 0U;
while (nBits-- > 0) { while (nBits-- > 0) {
--m_dp; --m_dp;
uint32_t i = state >> (9 - K); uint32_t i = state >> (9 - K);
uint8_t bit = uint8_t(*m_dp >> i) & 1; uint8_t bit = uint8_t(*m_dp >> i) & 1;
state = (bit << 7) | (state >> 1); state = (bit << 7) | (state >> 1);
WRITE_BIT1(out, nBits, bit != 0U); WRITE_BIT1(out, nBits, bit != 0U);
} }
} }
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;
uint32_t k = 0U; uint32_t k = 0U;
for (unsigned int i = 0U; i < nBits; i++) { for (unsigned int i = 0U; i < nBits; i++) {
uint8_t d = READ_BIT1(in, i) ? 1U : 0U; uint8_t d = READ_BIT1(in, i) ? 1U : 0U;
uint8_t g1 = (d + d3 + d4) & 1; uint8_t g1 = (d + d3 + d4) & 1;
uint8_t g2 = (d + d1 + d2 + d4) & 1; uint8_t g2 = (d + d1 + d2 + d4) & 1;
d4 = d3; d4 = d3;
d3 = d2; d3 = d2;
d2 = d1; d2 = d1;
d1 = d; d1 = d;
WRITE_BIT1(out, k, g1 != 0U); WRITE_BIT1(out, k, g1 != 0U);
k++; k++;
WRITE_BIT1(out, k, g2 != 0U); WRITE_BIT1(out, k, g2 != 0U);
k++; k++;
} }

@ -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,56 +69,56 @@ 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();
// Deinterleave the FICH and send bits to the Viterbi decoder // Deinterleave the FICH and send bits to the Viterbi decoder
for (unsigned int i = 0U; i < 100U; i++) { for (unsigned int i = 0U; i < 100U; i++) {
unsigned int n = INTERLEAVE_TABLE[i]; unsigned int n = INTERLEAVE_TABLE[i];
uint8_t s0 = READ_BIT1(bytes, n) ? 1U : 0U; uint8_t s0 = READ_BIT1(bytes, n) ? 1U : 0U;
n++; n++;
uint8_t s1 = READ_BIT1(bytes, n) ? 1U : 0U; uint8_t s1 = READ_BIT1(bytes, n) ? 1U : 0U;
viterbi.decode(s0, s1); viterbi.decode(s0, s1);
} }
unsigned char output[13U]; unsigned char output[13U];
viterbi.chainback(output, 96U); viterbi.chainback(output, 96U);
unsigned int b0 = CGolay24128::decode24128(output + 0U); unsigned int b0 = CGolay24128::decode24128(output + 0U);
unsigned int b1 = CGolay24128::decode24128(output + 3U); unsigned int b1 = CGolay24128::decode24128(output + 3U);
unsigned int b2 = CGolay24128::decode24128(output + 6U); unsigned int b2 = CGolay24128::decode24128(output + 6U);
unsigned int b3 = CGolay24128::decode24128(output + 9U); unsigned int b3 = CGolay24128::decode24128(output + 9U);
m_fich[0U] = (b0 >> 4) & 0xFFU; m_fich[0U] = (b0 >> 4) & 0xFFU;
m_fich[1U] = ((b0 << 4) & 0xF0U) | ((b1 >> 8) & 0x0FU); m_fich[1U] = ((b0 << 4) & 0xF0U) | ((b1 >> 8) & 0x0FU);
m_fich[2U] = (b1 >> 0) & 0xFFU; m_fich[2U] = (b1 >> 0) & 0xFFU;
m_fich[3U] = (b2 >> 4) & 0xFFU; m_fich[3U] = (b2 >> 4) & 0xFFU;
m_fich[4U] = ((b2 << 4) & 0xF0U) | ((b3 >> 8) & 0x0FU); m_fich[4U] = ((b2 << 4) & 0xF0U) | ((b3 >> 8) & 0x0FU);
m_fich[5U] = (b3 >> 0) & 0xFFU; m_fich[5U] = (b3 >> 0) & 0xFFU;
return CCRC::checkCCITT162(m_fich, 6U); return CCRC::checkCCITT162(m_fich, 6U);
} }
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);
unsigned int b0 = ((m_fich[0U] << 4) & 0xFF0U) | ((m_fich[1U] >> 4) & 0x00FU); unsigned int b0 = ((m_fich[0U] << 4) & 0xFF0U) | ((m_fich[1U] >> 4) & 0x00FU);
unsigned int b1 = ((m_fich[1U] << 8) & 0xF00U) | ((m_fich[2U] >> 0) & 0x0FFU); unsigned int b1 = ((m_fich[1U] << 8) & 0xF00U) | ((m_fich[2U] >> 0) & 0x0FFU);
unsigned int b2 = ((m_fich[3U] << 4) & 0xFF0U) | ((m_fich[4U] >> 4) & 0x00FU); unsigned int b2 = ((m_fich[3U] << 4) & 0xFF0U) | ((m_fich[4U] >> 4) & 0x00FU);
unsigned int b3 = ((m_fich[4U] << 8) & 0xF00U) | ((m_fich[5U] >> 0) & 0x0FFU); unsigned int b3 = ((m_fich[4U] << 8) & 0xF00U) | ((m_fich[5U] >> 0) & 0x0FFU);
unsigned int c0 = CGolay24128::encode24128(b0); unsigned int c0 = CGolay24128::encode24128(b0);
unsigned int c1 = CGolay24128::encode24128(b1); unsigned int c1 = CGolay24128::encode24128(b1);
unsigned int c2 = CGolay24128::encode24128(b2); unsigned int c2 = CGolay24128::encode24128(b2);
unsigned int c3 = CGolay24128::encode24128(b3); unsigned int c3 = CGolay24128::encode24128(b3);
unsigned char conv[13U]; unsigned char conv[13U];
conv[0U] = (c0 >> 16) & 0xFFU; conv[0U] = (c0 >> 16) & 0xFFU;
conv[1U] = (c0 >> 8) & 0xFFU; conv[1U] = (c0 >> 8) & 0xFFU;
@ -133,23 +133,23 @@ void CYSFFICH::encode(unsigned char* bytes)
conv[10U] = (c3 >> 8) & 0xFFU; conv[10U] = (c3 >> 8) & 0xFFU;
conv[11U] = (c3 >> 0) & 0xFFU; conv[11U] = (c3 >> 0) & 0xFFU;
conv[12U] = 0x00U; conv[12U] = 0x00U;
CYSFConvolution convolution; CYSFConvolution convolution;
unsigned char convolved[25U]; unsigned char convolved[25U];
convolution.encode(conv, convolved, 100U); convolution.encode(conv, convolved, 100U);
unsigned int j = 0U; unsigned int j = 0U;
for (unsigned int i = 0U; i < 100U; i++) { for (unsigned int i = 0U; i < 100U; i++) {
unsigned int n = INTERLEAVE_TABLE[i]; unsigned int n = INTERLEAVE_TABLE[i];
bool s0 = READ_BIT1(convolved, j) != 0U; bool s0 = READ_BIT1(convolved, j) != 0U;
j++; j++;
bool s1 = READ_BIT1(convolved, j) != 0U; bool s1 = READ_BIT1(convolved, j) != 0U;
j++; j++;
WRITE_BIT1(bytes, n, s0); WRITE_BIT1(bytes, n, s0);
n++; n++;
WRITE_BIT1(bytes, n, s1); WRITE_BIT1(bytes, n, s1);
} }
@ -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;
} }
} }

@ -55,7 +55,7 @@ bool CYsfNodeDirFile::Init(void)
bool CYsfNodeDirFile::NeedReload(void) bool CYsfNodeDirFile::NeedReload(void)
{ {
bool needReload = false; bool needReload = false;
time_t time; time_t time;
if ( GetLastModTime(&time) ) if ( GetLastModTime(&time) )
{ {
@ -69,7 +69,7 @@ bool CYsfNodeDirFile::LoadContent(CBuffer *buffer)
bool ok = false; bool ok = false;
std::ifstream file; std::ifstream file;
std::streampos size; std::streampos size;
// open file // open file
file.open(YSFNODEDB_PATH, std::ios::in | std::ios::binary | std::ios::ate); file.open(YSFNODEDB_PATH, std::ios::in | std::ios::binary | std::ios::ate);
if ( file.is_open() ) if ( file.is_open() )
@ -82,18 +82,18 @@ bool CYsfNodeDirFile::LoadContent(CBuffer *buffer)
buffer->resize((int)size+1); buffer->resize((int)size+1);
file.seekg (0, std::ios::beg); file.seekg (0, std::ios::beg);
file.read((char *)buffer->data(), (int)size); file.read((char *)buffer->data(), (int)size);
// close file // close file
file.close(); file.close();
// update time // update time
GetLastModTime(&m_LastModTime); GetLastModTime(&m_LastModTime);
// done // done
ok = true; ok = true;
} }
} }
// done // done
return ok; return ok;
} }
@ -101,30 +101,30 @@ bool CYsfNodeDirFile::LoadContent(CBuffer *buffer)
bool CYsfNodeDirFile::RefreshContent(const CBuffer &buffer) bool CYsfNodeDirFile::RefreshContent(const CBuffer &buffer)
{ {
bool ok = false; bool ok = false;
// clear directory // clear directory
clear(); clear();
// scan buffer // scan buffer
if ( buffer.size() > 0 ) if ( buffer.size() > 0 )
{ {
// crack it // crack it
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 *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);
@ -139,15 +139,15 @@ bool CYsfNodeDirFile::RefreshContent(const CBuffer &buffer)
// next line // next line
ptr1 = ptr2+1; ptr1 = ptr2+1;
} }
// done // done
ok = true; ok = true;
} }
// report // report
std::cout << "Read " << size() << " YSF nodes from file " << YSFNODEDB_PATH << std::endl; std::cout << "Read " << size() << " YSF nodes from file " << YSFNODEDB_PATH << std::endl;
// done // done
return ok; return ok;
} }
@ -156,7 +156,7 @@ bool CYsfNodeDirFile::RefreshContent(const CBuffer &buffer)
bool CYsfNodeDirFile::GetLastModTime(time_t *time) bool CYsfNodeDirFile::GetLastModTime(time_t *time)
{ {
bool ok = false; bool ok = false;
struct stat fileStat; struct stat fileStat;
if( ::stat(YSFNODEDB_PATH, &fileStat) != -1 ) if( ::stat(YSFNODEDB_PATH, &fileStat) != -1 )
{ {

@ -47,27 +47,27 @@ bool CYsfNodeDirHttp::RefreshContent(const CBuffer &buffer)
// clear directory // clear directory
clear(); clear();
// scan buffer // scan buffer
if ( buffer.size() > 0 ) if ( buffer.size() > 0 )
{ {
// crack it // crack it
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 *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);
@ -82,14 +82,14 @@ bool CYsfNodeDirHttp::RefreshContent(const CBuffer &buffer)
// next line // next line
ptr1 = ptr2+1; ptr1 = ptr2+1;
} }
// done // done
ok = true; ok = true;
} }
// report // report
std::cout << "Read " << size() << " YSF nodes from xlxapi.rlx.lu database " << std::endl; std::cout << "Read " << size() << " YSF nodes from xlxapi.rlx.lu database " << std::endl;
// done // done
return ok; return ok;
} }
@ -104,7 +104,7 @@ bool CYsfNodeDirHttp::HttpGet(const char *hostname, const char *filename, int po
{ {
bool ok = false; bool ok = false;
int sock_id; int sock_id;
// open socket // open socket
if ( (sock_id = ::socket(AF_INET, SOCK_STREAM, 0)) >= 0 ) if ( (sock_id = ::socket(AF_INET, SOCK_STREAM, 0)) >= 0 )
{ {
@ -112,13 +112,13 @@ bool CYsfNodeDirHttp::HttpGet(const char *hostname, const char *filename, int po
struct sockaddr_in servaddr; struct 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);
servaddr.sin_port = htons(port); servaddr.sin_port = htons(port);
servaddr.sin_family = AF_INET; servaddr.sin_family = AF_INET;
// connect // connect
if ( ::connect(sock_id, (struct sockaddr *)&servaddr, sizeof(servaddr)) == 0) if ( ::connect(sock_id, (struct sockaddr *)&servaddr, sizeof(servaddr)) == 0)
{ {
@ -127,7 +127,7 @@ bool CYsfNodeDirHttp::HttpGet(const char *hostname, const char *filename, int po
::sprintf(request, "GET /%s HTTP/1.0\r\nFrom: %s\r\nUser-Agent: xlxd\r\n\r\n", ::sprintf(request, "GET /%s HTTP/1.0\r\nFrom: %s\r\nUser-Agent: xlxd\r\n\r\n",
filename, (const char *)g_Reflector.GetCallsign()); filename, (const char *)g_Reflector.GetCallsign());
::write(sock_id, request, strlen(request)); ::write(sock_id, request, strlen(request));
// config receive timeouts // config receive timeouts
fd_set read_set; fd_set read_set;
struct timeval timeout; struct timeval timeout;
@ -135,7 +135,7 @@ bool CYsfNodeDirHttp::HttpGet(const char *hostname, const char *filename, int po
timeout.tv_usec = 0; timeout.tv_usec = 0;
FD_ZERO(&read_set); FD_ZERO(&read_set);
FD_SET(sock_id, &read_set); FD_SET(sock_id, &read_set);
// get the reply back // get the reply back
buffer->clear(); buffer->clear();
bool done = false; bool done = false;
@ -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 )
//{ //{
@ -156,10 +156,10 @@ bool CYsfNodeDirHttp::HttpGet(const char *hostname, const char *filename, int po
} }
//} //}
done = (len <= 0); done = (len <= 0);
} while (!done); } while (!done);
buffer->Append((uint8)0); buffer->Append((uint8)0);
// and disconnect // and disconnect
close(sock_id); close(sock_id);
} }
@ -172,13 +172,13 @@ bool CYsfNodeDirHttp::HttpGet(const char *hostname, const char *filename, int po
{ {
std::cout << "Host " << hostname << " not found" << std::endl; std::cout << "Host " << hostname << " not found" << std::endl;
} }
} }
else else
{ {
std::cout << "Failed to open wget socket" << std::endl; std::cout << "Failed to open wget socket" << std::endl;
} }
// done // done
return ok; return ok;
} }

@ -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,76 +95,76 @@ 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;
unsigned char dch[45U]; unsigned char dch[45U];
unsigned char* p1 = data; unsigned char* p1 = data;
unsigned char* p2 = dch; unsigned char* p2 = dch;
for (unsigned int i = 0U; i < 5U; i++) { for (unsigned int i = 0U; i < 5U; i++) {
::memcpy(p2, p1, 9U); ::memcpy(p2, p1, 9U);
p1 += 18U; p2 += 9U; p1 += 18U; p2 += 9U;
} }
CYSFConvolution conv; CYSFConvolution conv;
conv.start(); conv.start();
for (unsigned int i = 0U; i < 180U; i++) { for (unsigned int i = 0U; i < 180U; i++) {
unsigned int n = INTERLEAVE_TABLE_9_20[i]; unsigned int n = INTERLEAVE_TABLE_9_20[i];
uint8_t s0 = READ_BIT1(dch, n) ? 1U : 0U; uint8_t s0 = READ_BIT1(dch, n) ? 1U : 0U;
n++; n++;
uint8_t s1 = READ_BIT1(dch, n) ? 1U : 0U; uint8_t s1 = READ_BIT1(dch, n) ? 1U : 0U;
conv.decode(s0, s1); conv.decode(s0, s1);
} }
unsigned char output[23U]; unsigned char output[23U];
conv.chainback(output, 176U); conv.chainback(output, 176U);
bool valid1 = CCRC::checkCCITT162(output, 22U); bool valid1 = CCRC::checkCCITT162(output, 22U);
if (valid1) { if (valid1) {
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);
} }
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];
CCRC::addCCITT162(output, 22U); CCRC::addCCITT162(output, 22U);
output[22U] = 0x00U; output[22U] = 0x00U;
unsigned char convolved[45U]; unsigned char convolved[45U];
conv.encode(output, convolved, 180U); conv.encode(output, convolved, 180U);
unsigned char bytes[45U]; unsigned char bytes[45U];
unsigned int j = 0U; unsigned int j = 0U;
for (unsigned int i = 0U; i < 180U; i++) { for (unsigned int i = 0U; i < 180U; i++) {
unsigned int n = INTERLEAVE_TABLE_9_20[i]; unsigned int n = INTERLEAVE_TABLE_9_20[i];
bool s0 = READ_BIT1(convolved, j) != 0U; bool s0 = READ_BIT1(convolved, j) != 0U;
j++; j++;
bool s1 = READ_BIT1(convolved, j) != 0U; bool s1 = READ_BIT1(convolved, j) != 0U;
j++; j++;
WRITE_BIT1(bytes, n, s0); WRITE_BIT1(bytes, n, s0);
n++; n++;
WRITE_BIT1(bytes, n, s1); WRITE_BIT1(bytes, n, s1);
} }
p1 = data; p1 = data;
p2 = bytes; p2 = bytes;
for (unsigned int i = 0U; i < 5U; i++) { for (unsigned int i = 0U; i < 5U; i++) {
@ -172,65 +172,65 @@ bool CYSFPayload::processHeaderData(unsigned char* data)
p1 += 18U; p2 += 9U; p1 += 18U; p2 += 9U;
} }
} }
p1 = data + 9U; p1 = data + 9U;
p2 = dch; p2 = dch;
for (unsigned int i = 0U; i < 5U; i++) { for (unsigned int i = 0U; i < 5U; i++) {
::memcpy(p2, p1, 9U); ::memcpy(p2, p1, 9U);
p1 += 18U; p2 += 9U; p1 += 18U; p2 += 9U;
} }
conv.start(); conv.start();
for (unsigned int i = 0U; i < 180U; i++) { for (unsigned int i = 0U; i < 180U; i++) {
unsigned int n = INTERLEAVE_TABLE_9_20[i]; unsigned int n = INTERLEAVE_TABLE_9_20[i];
uint8_t s0 = READ_BIT1(dch, n) ? 1U : 0U; uint8_t s0 = READ_BIT1(dch, n) ? 1U : 0U;
n++; n++;
uint8_t s1 = READ_BIT1(dch, n) ? 1U : 0U; uint8_t s1 = READ_BIT1(dch, n) ? 1U : 0U;
conv.decode(s0, s1); conv.decode(s0, s1);
} }
conv.chainback(output, 176U); conv.chainback(output, 176U);
bool valid2 = CCRC::checkCCITT162(output, 22U); bool valid2 = CCRC::checkCCITT162(output, 22U);
if (valid2) { if (valid2) {
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++)
output[i] ^= WHITENING_DATA[i]; output[i] ^= WHITENING_DATA[i];
CCRC::addCCITT162(output, 22U); CCRC::addCCITT162(output, 22U);
output[22U] = 0x00U; output[22U] = 0x00U;
unsigned char convolved[45U]; unsigned char convolved[45U];
conv.encode(output, convolved, 180U); conv.encode(output, convolved, 180U);
unsigned char bytes[45U]; unsigned char bytes[45U];
unsigned int j = 0U; unsigned int j = 0U;
for (unsigned int i = 0U; i < 180U; i++) { for (unsigned int i = 0U; i < 180U; i++) {
unsigned int n = INTERLEAVE_TABLE_9_20[i]; unsigned int n = INTERLEAVE_TABLE_9_20[i];
bool s0 = READ_BIT1(convolved, j) != 0U; bool s0 = READ_BIT1(convolved, j) != 0U;
j++; j++;
bool s1 = READ_BIT1(convolved, j) != 0U; bool s1 = READ_BIT1(convolved, j) != 0U;
j++; j++;
WRITE_BIT1(bytes, n, s0); WRITE_BIT1(bytes, n, s0);
n++; n++;
WRITE_BIT1(bytes, n, s1); WRITE_BIT1(bytes, n, s1);
} }
p1 = data + 9U; p1 = data + 9U;
p2 = bytes; p2 = bytes;
for (unsigned int i = 0U; i < 5U; i++) { for (unsigned int i = 0U; i < 5U; i++) {
@ -238,139 +238,139 @@ bool CYSFPayload::processHeaderData(unsigned char* data)
p1 += 18U; p2 += 9U; p1 += 18U; p2 += 9U;
} }
} }
return valid1; return valid1;
} }
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);
data += YSF_SYNC_LENGTH_BYTES + YSF_FICH_LENGTH_BYTES; data += YSF_SYNC_LENGTH_BYTES + YSF_FICH_LENGTH_BYTES;
unsigned char dch[45U]; unsigned char dch[45U];
const unsigned char* p1 = data; const unsigned char* p1 = data;
unsigned char* p2 = dch; unsigned char* p2 = dch;
for (unsigned int i = 0U; i < 5U; i++) { for (unsigned int i = 0U; i < 5U; i++) {
::memcpy(p2, p1, 9U); ::memcpy(p2, p1, 9U);
p1 += 18U; p2 += 9U; p1 += 18U; p2 += 9U;
} }
CYSFConvolution conv; CYSFConvolution conv;
conv.start(); conv.start();
for (unsigned int i = 0U; i < 180U; i++) { for (unsigned int i = 0U; i < 180U; i++) {
unsigned int n = INTERLEAVE_TABLE_9_20[i]; unsigned int n = INTERLEAVE_TABLE_9_20[i];
uint8_t s0 = READ_BIT1(dch, n) ? 1U : 0U; uint8_t s0 = READ_BIT1(dch, n) ? 1U : 0U;
n++; n++;
uint8_t s1 = READ_BIT1(dch, n) ? 1U : 0U; uint8_t s1 = READ_BIT1(dch, n) ? 1U : 0U;
conv.decode(s0, s1); conv.decode(s0, s1);
} }
unsigned char output[23U]; unsigned char output[23U];
conv.chainback(output, 176U); conv.chainback(output, 176U);
bool ret = CCRC::checkCCITT162(output, 22U); bool ret = CCRC::checkCCITT162(output, 22U);
if (ret) { if (ret) {
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];
// CUtils::dump(1U, "FR Mode Data 1", output, 20U); // CUtils::dump(1U, "FR Mode Data 1", output, 20U);
::memcpy(dt, output, 20U); ::memcpy(dt, output, 20U);
} }
return ret; return ret;
} }
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);
data += YSF_SYNC_LENGTH_BYTES + YSF_FICH_LENGTH_BYTES; data += YSF_SYNC_LENGTH_BYTES + YSF_FICH_LENGTH_BYTES;
unsigned char dch[45U]; unsigned char dch[45U];
const unsigned char* p1 = data + 9U; const unsigned char* p1 = data + 9U;
unsigned char* p2 = dch; unsigned char* p2 = dch;
for (unsigned int i = 0U; i < 5U; i++) { for (unsigned int i = 0U; i < 5U; i++) {
::memcpy(p2, p1, 9U); ::memcpy(p2, p1, 9U);
p1 += 18U; p2 += 9U; p1 += 18U; p2 += 9U;
} }
CYSFConvolution conv; CYSFConvolution conv;
conv.start(); conv.start();
for (unsigned int i = 0U; i < 180U; i++) { for (unsigned int i = 0U; i < 180U; i++) {
unsigned int n = INTERLEAVE_TABLE_9_20[i]; unsigned int n = INTERLEAVE_TABLE_9_20[i];
uint8_t s0 = READ_BIT1(dch, n) ? 1U : 0U; uint8_t s0 = READ_BIT1(dch, n) ? 1U : 0U;
n++; n++;
uint8_t s1 = READ_BIT1(dch, n) ? 1U : 0U; uint8_t s1 = READ_BIT1(dch, n) ? 1U : 0U;
conv.decode(s0, s1); conv.decode(s0, s1);
} }
unsigned char output[23U]; unsigned char output[23U];
conv.chainback(output, 176U); conv.chainback(output, 176U);
bool ret = CCRC::checkCCITT162(output, 22U); bool ret = CCRC::checkCCITT162(output, 22U);
if (ret) { if (ret) {
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];
// CUtils::dump(1U, "FR Mode Data 2", output, 20U); // CUtils::dump(1U, "FR Mode Data 2", output, 20U);
::memcpy(dt, output, 20U); ::memcpy(dt, output, 20U);
} }
return ret; return ret;
} }
void CYSFPayload::writeVDMode2Data(unsigned char* data, const unsigned char* dt) void CYSFPayload::writeVDMode2Data(unsigned char* data, const unsigned char* dt)
{ {
data += YSF_SYNC_LENGTH_BYTES + YSF_FICH_LENGTH_BYTES; data += YSF_SYNC_LENGTH_BYTES + YSF_FICH_LENGTH_BYTES;
unsigned char dt_tmp[13]; unsigned char dt_tmp[13];
::memcpy(dt_tmp, dt, YSF_CALLSIGN_LENGTH); ::memcpy(dt_tmp, dt, YSF_CALLSIGN_LENGTH);
for (unsigned int i = 0U; i < 10U; i++) for (unsigned int i = 0U; i < 10U; i++)
dt_tmp[i] ^= WHITENING_DATA[i]; dt_tmp[i] ^= WHITENING_DATA[i];
CCRC::addCCITT162(dt_tmp, 12U); CCRC::addCCITT162(dt_tmp, 12U);
dt_tmp[12U] = 0x00U; dt_tmp[12U] = 0x00U;
unsigned char convolved[25U]; unsigned char convolved[25U];
CYSFConvolution conv; CYSFConvolution conv;
conv.start(); conv.start();
conv.encode(dt_tmp, convolved, 100U); conv.encode(dt_tmp, convolved, 100U);
unsigned char bytes[25U]; unsigned char bytes[25U];
unsigned int j = 0U; unsigned int j = 0U;
for (unsigned int i = 0U; i < 100U; i++) { for (unsigned int i = 0U; i < 100U; i++) {
unsigned int n = INTERLEAVE_TABLE_5_20[i]; unsigned int n = INTERLEAVE_TABLE_5_20[i];
bool s0 = READ_BIT1(convolved, j) != 0U; bool s0 = READ_BIT1(convolved, j) != 0U;
j++; j++;
bool s1 = READ_BIT1(convolved, j) != 0U; bool s1 = READ_BIT1(convolved, j) != 0U;
j++; j++;
WRITE_BIT1(bytes, n, s0); WRITE_BIT1(bytes, n, s0);
n++; n++;
WRITE_BIT1(bytes, n, s1); WRITE_BIT1(bytes, n, s1);
} }
unsigned char* p1 = data; unsigned char* p1 = data;
unsigned char* p2 = bytes; unsigned char* p2 = bytes;
for (unsigned int i = 0U; i < 5U; i++) { for (unsigned int i = 0U; i < 5U; i++) {
@ -382,142 +382,142 @@ void CYSFPayload::writeVDMode2Data(unsigned char* data, const unsigned char* dt)
bool CYSFPayload::readVDMode1Data(const unsigned char* data, unsigned char* dt) 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;
unsigned char dch[45U]; unsigned char dch[45U];
const unsigned char* p1 = data; const unsigned char* p1 = data;
unsigned char* p2 = dch; unsigned char* p2 = dch;
for (unsigned int i = 0U; i < 5U; i++) { for (unsigned int i = 0U; i < 5U; i++) {
::memcpy(p2, p1, 9U); ::memcpy(p2, p1, 9U);
p1 += 18U; p2 += 9U; p1 += 18U; p2 += 9U;
} }
CYSFConvolution conv; CYSFConvolution conv;
conv.start(); conv.start();
for (unsigned int i = 0U; i < 180U; i++) { for (unsigned int i = 0U; i < 180U; i++) {
unsigned int n = INTERLEAVE_TABLE_9_20[i]; unsigned int n = INTERLEAVE_TABLE_9_20[i];
uint8_t s0 = READ_BIT1(dch, n) ? 1U : 0U; uint8_t s0 = READ_BIT1(dch, n) ? 1U : 0U;
n++; n++;
uint8_t s1 = READ_BIT1(dch, n) ? 1U : 0U; uint8_t s1 = READ_BIT1(dch, n) ? 1U : 0U;
conv.decode(s0, s1); conv.decode(s0, s1);
} }
unsigned char output[23U]; unsigned char output[23U];
conv.chainback(output, 176U); conv.chainback(output, 176U);
bool ret = CCRC::checkCCITT162(output, 22U); bool ret = CCRC::checkCCITT162(output, 22U);
if (ret) { if (ret) {
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];
// CUtils::dump(1U, "V/D Mode 1 Data", output, 20U); // CUtils::dump(1U, "V/D Mode 1 Data", output, 20U);
::memcpy(dt, output, 20U); ::memcpy(dt, output, 20U);
} }
return ret; return ret;
} }
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;
unsigned char dch[25U]; unsigned char dch[25U];
const unsigned char* p1 = data; const unsigned char* p1 = data;
unsigned char* p2 = dch; unsigned char* p2 = dch;
for (unsigned int i = 0U; i < 5U; i++) { for (unsigned int i = 0U; i < 5U; i++) {
::memcpy(p2, p1, 5U); ::memcpy(p2, p1, 5U);
p1 += 18U; p2 += 5U; p1 += 18U; p2 += 5U;
} }
CYSFConvolution conv; CYSFConvolution conv;
conv.start(); conv.start();
for (unsigned int i = 0U; i < 100U; i++) { for (unsigned int i = 0U; i < 100U; i++) {
unsigned int n = INTERLEAVE_TABLE_5_20[i]; unsigned int n = INTERLEAVE_TABLE_5_20[i];
uint8_t s0 = READ_BIT1(dch, n) ? 1U : 0U; uint8_t s0 = READ_BIT1(dch, n) ? 1U : 0U;
n++; n++;
uint8_t s1 = READ_BIT1(dch, n) ? 1U : 0U; uint8_t s1 = READ_BIT1(dch, n) ? 1U : 0U;
conv.decode(s0, s1); conv.decode(s0, s1);
} }
unsigned char output[13U]; unsigned char output[13U];
conv.chainback(output, 96U); conv.chainback(output, 96U);
bool ret = CCRC::checkCCITT162(output, 12U); bool ret = CCRC::checkCCITT162(output, 12U);
if (ret) { if (ret) {
for (unsigned int i = 0U; i < 10U; i++) for (unsigned int i = 0U; i < 10U; i++)
output[i] ^= WHITENING_DATA[i]; output[i] ^= WHITENING_DATA[i];
// CUtils::dump(1U, "V/D Mode 2 Data", output, YSF_CALLSIGN_LENGTH); // CUtils::dump(1U, "V/D Mode 2 Data", output, YSF_CALLSIGN_LENGTH);
::memcpy(dt, output, YSF_CALLSIGN_LENGTH); ::memcpy(dt, output, YSF_CALLSIGN_LENGTH);
} }
return ret; return ret;
} }
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);
writeDataFRModeData2(csd2, data); writeDataFRModeData2(csd2, data);
} }
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;
unsigned char output[25U]; unsigned char output[25U];
for (unsigned int i = 0U; i < 20U; i++) for (unsigned int i = 0U; i < 20U; i++)
output[i] = dt[i] ^ WHITENING_DATA[i]; output[i] = dt[i] ^ WHITENING_DATA[i];
CCRC::addCCITT162(output, 22U); CCRC::addCCITT162(output, 22U);
output[22U] = 0x00U; output[22U] = 0x00U;
unsigned char convolved[45U]; unsigned char convolved[45U];
CYSFConvolution conv; CYSFConvolution conv;
conv.encode(output, convolved, 180U); conv.encode(output, convolved, 180U);
unsigned char bytes[45U]; unsigned char bytes[45U];
unsigned int j = 0U; unsigned int j = 0U;
for (unsigned int i = 0U; i < 180U; i++) { for (unsigned int i = 0U; i < 180U; i++) {
unsigned int n = INTERLEAVE_TABLE_9_20[i]; unsigned int n = INTERLEAVE_TABLE_9_20[i];
bool s0 = READ_BIT1(convolved, j) != 0U; bool s0 = READ_BIT1(convolved, j) != 0U;
j++; j++;
bool s1 = READ_BIT1(convolved, j) != 0U; bool s1 = READ_BIT1(convolved, j) != 0U;
j++; j++;
WRITE_BIT1(bytes, n, s0); WRITE_BIT1(bytes, n, s0);
n++; n++;
WRITE_BIT1(bytes, n, s1); WRITE_BIT1(bytes, n, s1);
} }
unsigned char* p1 = data; unsigned char* p1 = data;
unsigned char* p2 = bytes; unsigned char* p2 = bytes;
for (unsigned int i = 0U; i < 5U; i++) { for (unsigned int i = 0U; i < 5U; i++) {
@ -528,40 +528,40 @@ void CYSFPayload::writeDataFRModeData1(const unsigned char* dt, unsigned char* d
void CYSFPayload::writeDataFRModeData2(const unsigned char* dt, unsigned char* data) 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;
unsigned char output[25U]; unsigned char output[25U];
for (unsigned int i = 0U; i < 20U; i++) for (unsigned int i = 0U; i < 20U; i++)
output[i] = dt[i] ^ WHITENING_DATA[i]; output[i] = dt[i] ^ WHITENING_DATA[i];
CCRC::addCCITT162(output, 22U); CCRC::addCCITT162(output, 22U);
output[22U] = 0x00U; output[22U] = 0x00U;
unsigned char convolved[45U]; unsigned char convolved[45U];
CYSFConvolution conv; CYSFConvolution conv;
conv.encode(output, convolved, 180U); conv.encode(output, convolved, 180U);
unsigned char bytes[45U]; unsigned char bytes[45U];
unsigned int j = 0U; unsigned int j = 0U;
for (unsigned int i = 0U; i < 180U; i++) { for (unsigned int i = 0U; i < 180U; i++) {
unsigned int n = INTERLEAVE_TABLE_9_20[i]; unsigned int n = INTERLEAVE_TABLE_9_20[i];
bool s0 = READ_BIT1(convolved, j) != 0U; bool s0 = READ_BIT1(convolved, j) != 0U;
j++; j++;
bool s1 = READ_BIT1(convolved, j) != 0U; bool s1 = READ_BIT1(convolved, j) != 0U;
j++; j++;
WRITE_BIT1(bytes, n, s0); WRITE_BIT1(bytes, n, s0);
n++; n++;
WRITE_BIT1(bytes, n, s1); WRITE_BIT1(bytes, n, s1);
} }
unsigned char* p1 = data + 9U; unsigned char* p1 = data + 9U;
unsigned char* p2 = bytes; unsigned char* p2 = bytes;
for (unsigned int i = 0U; i < 5U; i++) { for (unsigned int i = 0U; i < 5U; i++) {
@ -573,10 +573,10 @@ void CYSFPayload::writeDataFRModeData2(const unsigned char* dt, unsigned char* d
void CYSFPayload::setUplink(const std::string& callsign) void CYSFPayload::setUplink(const std::string& callsign)
{ {
m_uplink = new unsigned char[YSF_CALLSIGN_LENGTH]; m_uplink = new unsigned char[YSF_CALLSIGN_LENGTH];
std::string uplink = callsign; std::string uplink = callsign;
uplink.resize(YSF_CALLSIGN_LENGTH, ' '); uplink.resize(YSF_CALLSIGN_LENGTH, ' ');
for (unsigned int i = 0U; i < YSF_CALLSIGN_LENGTH; i++) for (unsigned int i = 0U; i < YSF_CALLSIGN_LENGTH; i++)
m_uplink[i] = uplink.at(i); m_uplink[i] = uplink.at(i);
} }
@ -584,10 +584,10 @@ void CYSFPayload::setUplink(const std::string& callsign)
void CYSFPayload::setDownlink(const std::string& callsign) void CYSFPayload::setDownlink(const std::string& callsign)
{ {
m_downlink = new unsigned char[YSF_CALLSIGN_LENGTH]; m_downlink = new unsigned char[YSF_CALLSIGN_LENGTH];
std::string downlink = callsign; std::string downlink = callsign;
downlink.resize(YSF_CALLSIGN_LENGTH, ' '); downlink.resize(YSF_CALLSIGN_LENGTH, ' ');
for (unsigned int i = 0U; i < YSF_CALLSIGN_LENGTH; i++) for (unsigned int i = 0U; i < YSF_CALLSIGN_LENGTH; i++)
m_downlink[i] = downlink.at(i); m_downlink[i] = downlink.at(i);
} }
@ -595,24 +595,24 @@ void CYSFPayload::setDownlink(const std::string& callsign)
std::string CYSFPayload::getSource() std::string CYSFPayload::getSource()
{ {
std::string tmp; std::string tmp;
if (m_dest) if (m_dest)
tmp.assign((const char *)m_source, YSF_CALLSIGN_LENGTH); tmp.assign((const char *)m_source, YSF_CALLSIGN_LENGTH);
else else
tmp = ""; tmp = "";
return tmp; return tmp;
} }
std::string CYSFPayload::getDest() std::string CYSFPayload::getDest()
{ {
std::string tmp; std::string tmp;
if (m_dest) if (m_dest)
tmp.assign((const char *)m_dest, YSF_CALLSIGN_LENGTH); tmp.assign((const char *)m_dest, YSF_CALLSIGN_LENGTH);
else else
tmp = ""; tmp = "";
return tmp; return tmp;
} }
@ -620,7 +620,7 @@ 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
{ {

@ -60,7 +60,7 @@ class CYsfStreamCacheItem
public: public:
CYsfStreamCacheItem() {} CYsfStreamCacheItem() {}
~CYsfStreamCacheItem() {} ~CYsfStreamCacheItem() {}
CDvHeaderPacket m_dvHeader; CDvHeaderPacket m_dvHeader;
CDvFramePacket m_dvFrames[5]; CDvFramePacket m_dvFrames[5];
@ -72,27 +72,27 @@ class CYsfProtocol : public CProtocol
public: public:
// constructor // constructor
CYsfProtocol(); CYsfProtocol();
// destructor // destructor
virtual ~CYsfProtocol() {}; virtual ~CYsfProtocol() {};
// initialization // initialization
bool Init(void); bool Init(void);
void Close(void); void Close(void);
// task // task
void Task(void); void Task(void);
protected: protected:
// queue helper // queue helper
void HandleQueue(void); void HandleQueue(void);
// keepalive helpers // keepalive helpers
void HandleKeepalives(void); void HandleKeepalives(void);
// stream helpers // stream helpers
bool OnDvHeaderPacketIn(CDvHeaderPacket *, const CIp &); bool OnDvHeaderPacketIn(CDvHeaderPacket *, const CIp &);
// DV packet decoding helpers // DV packet decoding helpers
bool IsValidConnectPacket(const CBuffer &, CCallsign *); bool IsValidConnectPacket(const CBuffer &, CCallsign *);
//bool IsValidDisconnectPacket(const CBuffer &, CCallsign *); //bool IsValidDisconnectPacket(const CBuffer &, CCallsign *);
@ -100,41 +100,41 @@ protected:
bool IsValidDvHeaderPacket(const CIp &, const CYSFFICH &, const CBuffer &, CDvHeaderPacket **, CDvFramePacket **); bool IsValidDvHeaderPacket(const CIp &, const CYSFFICH &, const CBuffer &, CDvHeaderPacket **, CDvFramePacket **);
bool IsValidDvFramePacket(const CIp &, const CYSFFICH &, const CBuffer &, CDvFramePacket **); bool IsValidDvFramePacket(const CIp &, const CYSFFICH &, const CBuffer &, CDvFramePacket **);
bool IsValidDvLastFramePacket(const CIp &, const CYSFFICH &, const CBuffer &, CDvFramePacket **); bool IsValidDvLastFramePacket(const CIp &, const CYSFFICH &, const CBuffer &, CDvFramePacket **);
// 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;
// Wires-X packet decoding helpers // Wires-X packet decoding helpers
bool IsValidwirexPacket(const CBuffer &, CYSFFICH *, CCallsign *, int *, int*); bool IsValidwirexPacket(const CBuffer &, CYSFFICH *, CCallsign *, int *, int*);
// server status packet decoding helpers // server status packet decoding helpers
bool IsValidServerStatusPacket(const CBuffer &) const; bool IsValidServerStatusPacket(const CBuffer &) const;
uint32 CalcHash(const uint8 *, int) const; uint32 CalcHash(const uint8 *, int) const;
// server status packet encoding helpers // server status packet encoding helpers
bool EncodeServerStatusPacket(CBuffer *) const; bool EncodeServerStatusPacket(CBuffer *) const;
// uiStreamId helpers // uiStreamId helpers
uint32 IpToStreamId(const CIp &) const; uint32 IpToStreamId(const CIp &) const;
// debug // debug
bool DebugTestDecodePacket(const CBuffer &); bool DebugTestDecodePacket(const CBuffer &);
bool DebugDumpHeaderPacket(const CBuffer &); bool DebugDumpHeaderPacket(const CBuffer &);
bool DebugDumpDvPacket(const CBuffer &); bool DebugDumpDvPacket(const CBuffer &);
bool DebugDumpLastDvPacket(const CBuffer &); bool DebugDumpLastDvPacket(const CBuffer &);
protected: protected:
// for keep alive // for keep alive
CTimePoint m_LastKeepaliveTime; CTimePoint m_LastKeepaliveTime;
// for queue header caches // for queue header caches
std::array<CYsfStreamCacheItem, NB_OF_MODULES> m_StreamsCache; std::array<CYsfStreamCacheItem, NB_OF_MODULES> m_StreamsCache;
// for wires-x // for wires-x
CWiresxCmdHandler m_WiresxCmdHandler; CWiresxCmdHandler m_WiresxCmdHandler;
unsigned char m_seqNo; unsigned char m_seqNo;

@ -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.