K&R formating and warnings fixed.

ki4klf
ac2ie 12 years ago
parent dd4fb774e2
commit 90862645f6

@ -28,7 +28,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
class IRCApplication
{
public:
public:
virtual void userJoin (const wxString& nick, const wxString& name, const wxString& host) = 0;
virtual void userLeave (const wxString& nick) = 0;

@ -64,12 +64,9 @@ IRCClient::IRCClient( IRCApplication * app, const wxString& update_channel,
this -> app = app;
if (localAddr.IsEmpty())
{
if (localAddr.IsEmpty()) {
safeStringCopy(local_addr, "0.0.0.0", sizeof local_addr);
}
else
{
} else {
safeStringCopy(local_addr, localAddr.mb_str(), sizeof local_addr);
}
@ -89,16 +86,14 @@ IRCClient::~IRCClient()
bool IRCClient::startWork()
{
if (Create() != wxTHREAD_NO_ERROR)
{
if (Create() != wxTHREAD_NO_ERROR) {
wxLogError(wxT("IRCClient::startWork: Could not create the worker thread!"));
return false;
}
terminateThread = false;
if (Run() != wxTHREAD_NO_ERROR)
{
if (Run() != wxTHREAD_NO_ERROR) {
wxLogError(wxT("IRCClient::startWork: Could not run the worker thread!"));
return false;
}
@ -135,38 +130,30 @@ wxThread::ExitCode IRCClient::Entry ()
result = getAllIPV4Addresses(local_addr, 0, &numAddr, &myaddr, 1);
if ((result != 0) || (numAddr != 1))
{
if ((result != 0) || (numAddr != 1)) {
wxLogVerbose(wxT("IRCClient::Entry: local address not parseable, using 0.0.0.0"));
memset(&myaddr, 0x00, sizeof(struct sockaddr_in));
}
while (true)
{
while (true) {
if (timer > 0)
{
if (timer > 0) {
timer --;
}
switch (state)
{
switch (state) {
case 0:
if (terminateThread)
{
if (terminateThread) {
wxLogVerbose(wxT("IRCClient::Entry: thread terminated at state=%d"), state);
return 0;
}
if (timer == 0)
{
if (timer == 0) {
timer = 30;
if (getAllIPV4Addresses(host_name, port, &numAddr, addr, MAXIPV4ADDR) == 0)
{
if (getAllIPV4Addresses(host_name, port, &numAddr, addr, MAXIPV4ADDR) == 0) {
wxLogVerbose(wxT("IRCClient::Entry: number of DNS entries %d"), numAddr);
if (numAddr > 0)
{
if (numAddr > 0) {
currentAddr = 0;
state = 1;
timer = 0;
@ -176,57 +163,47 @@ wxThread::ExitCode IRCClient::Entry ()
break;
case 1:
if (terminateThread)
{
if (terminateThread) {
wxLogVerbose(wxT("IRCClient::Entry: thread terminated at state=%d"), state);
return 0;
}
if (timer == 0)
{
if (timer == 0) {
sock = socket( PF_INET, SOCK_STREAM, IPPROTO_TCP);
if (sock < 0)
{
if (sock < 0) {
wxLogSysError(wxT("IRCClient::Entry: socket"));
timer = 30;
state = 0;
}
else
{
} else {
#if defined(__WINDOWS__)
u_long nonBlock = 1UL;
if (ioctlsocket( sock, FIONBIO, &nonBlock ) != 0)
{
if (ioctlsocket( sock, FIONBIO, &nonBlock ) != 0) {
wxLogSysError(wxT("IRCClient::Entry: ioctlsocket"));
closesocket(sock);
timer = 30;
state = 0;
}
#else
if (fcntl( sock, F_SETFL, O_NONBLOCK ) < 0)
{
if (fcntl( sock, F_SETFL, O_NONBLOCK ) < 0) {
wxLogSysError(wxT("IRCClient::Entry: fcntl"));
close(sock);
timer = 30;
state = 0;
}
#endif
else
{
else {
unsigned char * h = (unsigned char *) &(myaddr.sin_addr);
int res;
if ((h[0] != 0) || (h[1] != 0) || (h[2] != 0) || (h[3] != 0))
{
if ((h[0] != 0) || (h[1] != 0) || (h[2] != 0) || (h[3] != 0)) {
wxLogVerbose(wxT("IRCClient::Entry: bind: local address %d.%d.%d.%d"),
h[0], h[1], h[2], h[3]);
}
res = bind(sock, (struct sockaddr *) &myaddr, sizeof (struct sockaddr_in));
if (res != 0)
{
if (res != 0) {
wxLogSysError(wxT("IRCClient::Entry: bind"));
#if defined(__WINDOWS__)
@ -246,13 +223,10 @@ wxThread::ExitCode IRCClient::Entry ()
res = connect(sock, (struct sockaddr *) (addr + currentAddr), sizeof (struct sockaddr_in));
if (res == 0)
{
if (res == 0) {
wxLogVerbose(wxT("IRCClient::Entry: connected"));
state = 4;
}
else
{
} else {
#if defined(__WINDOWS__)
if (WSAGetLastError() == WSAEWOULDBLOCK)
#else
@ -262,9 +236,7 @@ wxThread::ExitCode IRCClient::Entry ()
wxLogVerbose(wxT("IRCClient::Entry: connect in progress"));
state = 3;
timer = 10; // 5 second timeout
}
else
{
} else {
wxLogSysError(wxT("IRCClient::Entry: connect"));
#if defined(__WINDOWS__)
closesocket(sock);
@ -272,13 +244,10 @@ wxThread::ExitCode IRCClient::Entry ()
close(sock);
#endif
currentAddr ++;
if (currentAddr >= numAddr)
{
if (currentAddr >= numAddr) {
state = 0;
timer = 30;
}
else
{
} else {
state = 1;
timer = 4;
}
@ -289,8 +258,7 @@ wxThread::ExitCode IRCClient::Entry ()
}
break;
case 3:
{
case 3: {
struct timeval tv;
tv.tv_sec = 0;
tv.tv_usec = 0;
@ -300,8 +268,7 @@ wxThread::ExitCode IRCClient::Entry ()
int res;
res = select(sock+1, NULL, &myset, NULL, &tv);
if (res < 0)
{
if (res < 0) {
wxLogSysError(wxT("IRCClient::Entry: select"));
#if defined(__WINDOWS__)
closesocket(sock);
@ -310,9 +277,7 @@ wxThread::ExitCode IRCClient::Entry ()
#endif
state = 0;
timer = 30;
}
else if (res > 0) // connect is finished
{
} else if (res > 0) { // connect is finished
#if defined(__WINDOWS__)
int val_len;
#else
@ -322,8 +287,7 @@ wxThread::ExitCode IRCClient::Entry ()
val_len = sizeof value;
if (getsockopt(sock, SOL_SOCKET, SO_ERROR, (char *) &value, &val_len) < 0)
{
if (getsockopt(sock, SOL_SOCKET, SO_ERROR, (char *) &value, &val_len) < 0) {
wxLogSysError(wxT("IRCClient::Entry: getsockopt"));
#if defined(__WINDOWS__)
closesocket(sock);
@ -332,11 +296,8 @@ wxThread::ExitCode IRCClient::Entry ()
#endif
state = 0;
timer = 30;
}
else
{
if (value != 0)
{
} else {
if (value != 0) {
wxLogWarning(wxT("IRCClient::Entry: SO_ERROR=%d"), value);
#if defined(__WINDOWS__)
closesocket(sock);
@ -344,27 +305,21 @@ wxThread::ExitCode IRCClient::Entry ()
close(sock);
#endif
currentAddr ++;
if (currentAddr >= numAddr)
{
if (currentAddr >= numAddr) {
state = 0;
timer = 30;
}
else
{
} else {
state = 1;
timer = 2;
}
}
else
{
} else {
wxLogVerbose(wxT("IRCClient::Entry: connected2"));
state = 4;
}
}
}
else if (timer == 0)
{ // select timeout and timer timeout
} else if (timer == 0) {
// select timeout and timer timeout
wxLogVerbose(wxT("IRCClient::Entry: connect timeout"));
#if defined(__WINDOWS__)
closesocket(sock);
@ -372,13 +327,10 @@ wxThread::ExitCode IRCClient::Entry ()
close(sock);
#endif
currentAddr ++;
if (currentAddr >= numAddr)
{
if (currentAddr >= numAddr) {
state = 0;
timer = 30;
}
else
{
} else {
state = 1; // open new socket
timer = 2;
}
@ -387,8 +339,7 @@ wxThread::ExitCode IRCClient::Entry ()
}
break;
case 4:
{
case 4: {
recvQ = new IRCMessageQueue();
sendQ = new IRCMessageQueue();
@ -404,26 +355,19 @@ wxThread::ExitCode IRCClient::Entry ()
case 5:
if (terminateThread)
{
if (terminateThread) {
state = 6;
}
else
{
} else {
if (recvQ -> isEOF())
{
if (recvQ -> isEOF()) {
timer = 0;
state = 6;
}
else if (proto -> processQueues(recvQ, sendQ) == false)
{
} else if (proto -> processQueues(recvQ, sendQ) == false) {
timer = 0;
state = 6;
}
while ((state == 5) && sendQ->messageAvailable())
{
while ((state == 5) && sendQ->messageAvailable()) {
IRCMessage * m = sendQ -> getMessage();
wxString out;
@ -434,24 +378,20 @@ wxThread::ExitCode IRCClient::Entry ()
safeStringCopy(buf, out.mb_str(wxConvUTF8), sizeof buf);
int len = strlen(buf);
if (buf[len - 1] == 10) // is there a NL char at the end?
{
if (buf[len - 1] == 10) { // is there a NL char at the end?
int r = send(sock, buf, len, 0);
if (r != len)
{
if (r != len) {
wxLogVerbose(wxT("IRCClient::Entry: short write %d < %d"), r, len);
timer = 0;
state = 6;
}
/* else
/* else
{
wxLogVerbose(wxT("write %d bytes (") + out + wxT(")"), len );
} */
}
else
{
} else {
wxLogVerbose(wxT("IRCClient::Entry: no NL at end, len=%d"), len);
timer = 0;
@ -463,10 +403,8 @@ wxThread::ExitCode IRCClient::Entry ()
}
break;
case 6:
{
if (app != NULL)
{
case 6: {
if (app != NULL) {
app->setSendQ(NULL);
app->userListReset();
}
@ -486,8 +424,7 @@ wxThread::ExitCode IRCClient::Entry ()
close(sock);
#endif
if (terminateThread) // request to end the thread
{
if (terminateThread) { // request to end the thread
wxLogVerbose(wxT("IRCClient::Entry: thread terminated at state=%d"), state);
return 0;
}

@ -33,7 +33,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
class IRCClient : public wxThread
{
public:
public:
IRCClient( IRCApplication * app, const wxString& update_channel,
const wxString& hostName, unsigned int port, const wxString& callsign, const wxString& password,
@ -47,13 +47,13 @@ class IRCClient : public wxThread
void stopWork();
protected:
protected:
virtual wxThread::ExitCode Entry();
private:
private:
char host_name[100];
char local_addr[100];

@ -28,8 +28,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <wx/wx.h>
struct CIRCDDBPrivate
{
struct CIRCDDBPrivate {
IRCClient * client;
IRCDDBApp * app;
};
@ -56,7 +55,7 @@ CIRCDDB::~CIRCDDB()
}
// A false return implies a network error, or unable to log in
// A false return implies a network error, or unable to log in
bool CIRCDDB::open()
{
wxLogVerbose(wxT("start"));
@ -97,32 +96,27 @@ bool CIRCDDB::sendHeard( const wxString& myCall, const wxString& myCallExt,
const wxString& rpt2, unsigned char flag1,
unsigned char flag2, unsigned char flag3 )
{
if (myCall.Len() != 8)
{
if (myCall.Len() != 8) {
wxLogVerbose(wxT("CIRCDDB::sendHeard:myCall: len != 8"));
return false;
}
if (myCallExt.Len() != 4)
{
if (myCallExt.Len() != 4) {
wxLogVerbose(wxT("CIRCDDB::sendHeard:myCallExt: len != 4"));
return false;
}
if (yourCall.Len() != 8)
{
if (yourCall.Len() != 8) {
wxLogVerbose(wxT("CIRCDDB::sendHeard:yourCall: len != 8"));
return false;
}
if (rpt1.Len() != 8)
{
if (rpt1.Len() != 8) {
wxLogVerbose(wxT("CIRCDDB::sendHeard:rpt1: len != 8"));
return false;
}
if (rpt2.Len() != 8)
{
if (rpt2.Len() != 8) {
wxLogVerbose(wxT("CIRCDDB::sendHeard:rpt2: len != 8"));
return false;
}
@ -140,64 +134,52 @@ bool CIRCDDB::sendHeardWithTXMsg( const wxString& myCall, const wxString& myCall
const wxString& network_destination,
const wxString& tx_message )
{
if (myCall.Len() != 8)
{
if (myCall.Len() != 8) {
wxLogVerbose(wxT("CIRCDDB::sendHeard:myCall: len != 8"));
return false;
}
if (myCallExt.Len() != 4)
{
if (myCallExt.Len() != 4) {
wxLogVerbose(wxT("CIRCDDB::sendHeard:myCallExt: len != 4"));
return false;
}
if (yourCall.Len() != 8)
{
if (yourCall.Len() != 8) {
wxLogVerbose(wxT("CIRCDDB::sendHeard:yourCall: len != 8"));
return false;
}
if (rpt1.Len() != 8)
{
if (rpt1.Len() != 8) {
wxLogVerbose(wxT("CIRCDDB::sendHeard:rpt1: len != 8"));
return false;
}
if (rpt2.Len() != 8)
{
if (rpt2.Len() != 8) {
wxLogVerbose(wxT("CIRCDDB::sendHeard:rpt2: len != 8"));
return false;
}
wxString dest = network_destination;
if (dest.Len() == 0)
{
if (dest.Len() == 0) {
dest = wxT(" ");
}
if (dest.Len() != 8)
{
if (dest.Len() != 8) {
wxLogVerbose(wxT("CIRCDDB::sendHeard:network_destination: len != 8"));
return false;
}
wxString msg;
if (tx_message.Len() == 20)
{
if (tx_message.Len() == 20) {
unsigned int i;
for (i=0; i < tx_message.Len(); i++)
{
for (i=0; i < tx_message.Len(); i++) {
wxChar ch = tx_message.GetChar(i);
if ((ch > 32) && (ch < 127))
{
if ((ch > 32) && (ch < 127)) {
msg.Append(ch);
}
else
{
} else {
msg.Append(wxT('_'));
}
}
@ -217,73 +199,59 @@ bool CIRCDDB::sendHeardWithTXStats( const wxString& myCall, const wxString& myCa
int num_dv_silent_frames,
int num_bit_errors )
{
if ((num_dv_frames <= 0) || (num_dv_frames > 65535))
{
if ((num_dv_frames <= 0) || (num_dv_frames > 65535)) {
wxLogVerbose(wxT("CIRCDDB::sendHeard:num_dv_frames not in range 1-65535"));
return false;
}
if (num_dv_silent_frames > num_dv_frames)
{
if (num_dv_silent_frames > num_dv_frames) {
wxLogVerbose(wxT("CIRCDDB::sendHeard:num_dv_silent_frames > num_dv_frames"));
return false;
}
if (num_bit_errors > (4*num_dv_frames)) // max 4 bit errors per frame
{
if (num_bit_errors > (4*num_dv_frames)) { // max 4 bit errors per frame
wxLogVerbose(wxT("CIRCDDB::sendHeard:num_bit_errors > (4*num_dv_frames)"));
return false;
}
if (myCall.Len() != 8)
{
if (myCall.Len() != 8) {
wxLogVerbose(wxT("CIRCDDB::sendHeard:myCall: len != 8"));
return false;
}
if (myCallExt.Len() != 4)
{
if (myCallExt.Len() != 4) {
wxLogVerbose(wxT("CIRCDDB::sendHeard:myCallExt: len != 4"));
return false;
}
if (yourCall.Len() != 8)
{
if (yourCall.Len() != 8) {
wxLogVerbose(wxT("CIRCDDB::sendHeard:yourCall: len != 8"));
return false;
}
if (rpt1.Len() != 8)
{
if (rpt1.Len() != 8) {
wxLogVerbose(wxT("CIRCDDB::sendHeard:rpt1: len != 8"));
return false;
}
if (rpt2.Len() != 8)
{
if (rpt2.Len() != 8) {
wxLogVerbose(wxT("CIRCDDB::sendHeard:rpt2: len != 8"));
return false;
}
wxString stats = wxString::Format(wxT("%04x"), num_dv_frames);
if (num_dv_silent_frames >= 0)
{
if (num_dv_silent_frames >= 0) {
wxString s = wxString::Format(wxT("%02x"), (num_dv_silent_frames * 100) / num_dv_frames);
stats.Append(s);
if (num_bit_errors >= 0)
{
if (num_bit_errors >= 0) {
s = wxString::Format(wxT("%02x"), (num_bit_errors * 125) / (num_dv_frames * 3));
stats.Append(s);
}
else
{
} else {
stats.Append(wxT("__"));
}
}
else
{
} else {
stats.Append(wxT("____"));
}
@ -298,8 +266,7 @@ bool CIRCDDB::sendHeardWithTXStats( const wxString& myCall, const wxString& myCa
// Send query for a gateway/reflector, a false return implies a network error
bool CIRCDDB::findGateway(const wxString& gatewayCallsign)
{
if (gatewayCallsign.Len() != 8)
{
if (gatewayCallsign.Len() != 8) {
wxLogVerbose(wxT("CIRCDDB::findGateway: len != 8"));
return false;
}
@ -310,8 +277,7 @@ bool CIRCDDB::findGateway(const wxString& gatewayCallsign)
bool CIRCDDB::findRepeater(const wxString& repeaterCallsign)
{
if (repeaterCallsign.Len() != 8)
{
if (repeaterCallsign.Len() != 8) {
wxLogVerbose(wxT("CIRCDDB::findRepeater: len != 8"));
return false;
}
@ -322,8 +288,7 @@ bool CIRCDDB::findRepeater(const wxString& repeaterCallsign)
// Send query for a user, a false return implies a network error
bool CIRCDDB::findUser(const wxString& userCallsign)
{
if (userCallsign.Len() != 8)
{
if (userCallsign.Len() != 8) {
wxLogVerbose(wxT("CIRCDDB::findUser: len != 8"));
return false;
}
@ -341,32 +306,28 @@ IRCDDB_RESPONSE_TYPE CIRCDDB::getMessageType()
// Get a gateway message, as a result of IDRT_REPEATER returned from getMessageType()
// A false return implies a network error
bool CIRCDDB::receiveRepeater(wxString& repeaterCallsign, wxString& gatewayCallsign, wxString& address, DSTAR_PROTOCOL& protocol)
bool CIRCDDB::receiveRepeater(wxString& repeaterCallsign, wxString& gatewayCallsign, wxString& address, DSTAR_PROTOCOL& /*protocol*/)
{
IRCDDB_RESPONSE_TYPE rt = d->app->getReplyMessageType();
if (rt != IDRT_REPEATER)
{
if (rt != IDRT_REPEATER) {
wxLogError(wxT("CIRCDDB::receiveRepeater: unexpected response type"));
return false;
}
IRCMessage * m = d->app->getReplyMessage();
if (m == NULL)
{
if (m == NULL) {
wxLogError(wxT("CIRCDDB::receiveRepeater: no message"));
return false;
}
if (!m->getCommand().IsSameAs(wxT("IDRT_REPEATER")))
{
if (!m->getCommand().IsSameAs(wxT("IDRT_REPEATER"))) {
wxLogError(wxT("CIRCDDB::receiveRepeater: wrong message type"));
return false;
}
if (m->getParamCount() != 3)
{
if (m->getParamCount() != 3) {
wxLogError(wxT("CIRCDDB::receiveRepeater: unexpected number of message parameters"));
return false;
}
@ -382,32 +343,28 @@ bool CIRCDDB::receiveRepeater(wxString& repeaterCallsign, wxString& gatewayCalls
// Get a gateway message, as a result of IDRT_GATEWAY returned from getMessageType()
// A false return implies a network error
bool CIRCDDB::receiveGateway(wxString& gatewayCallsign, wxString& address, DSTAR_PROTOCOL& protocol)
bool CIRCDDB::receiveGateway(wxString& gatewayCallsign, wxString& address, DSTAR_PROTOCOL& /*protocol*/)
{
IRCDDB_RESPONSE_TYPE rt = d->app->getReplyMessageType();
if (rt != IDRT_GATEWAY)
{
if (rt != IDRT_GATEWAY) {
wxLogError(wxT("CIRCDDB::receiveGateway: unexpected response type"));
return false;
}
IRCMessage * m = d->app->getReplyMessage();
if (m == NULL)
{
if (m == NULL) {
wxLogError(wxT("CIRCDDB::receiveGateway: no message"));
return false;
}
if (!m->getCommand().IsSameAs(wxT("IDRT_GATEWAY")))
{
if (!m->getCommand().IsSameAs(wxT("IDRT_GATEWAY"))) {
wxLogError(wxT("CIRCDDB::receiveGateway: wrong message type"));
return false;
}
if (m->getParamCount() != 2)
{
if (m->getParamCount() != 2) {
wxLogError(wxT("CIRCDDB::receiveGateway: unexpected number of message parameters"));
return false;
}
@ -433,28 +390,24 @@ bool CIRCDDB::receiveUser(wxString& userCallsign, wxString& repeaterCallsign, wx
{
IRCDDB_RESPONSE_TYPE rt = d->app->getReplyMessageType();
if (rt != IDRT_USER)
{
if (rt != IDRT_USER) {
wxLogError(wxT("CIRCDDB::receiveUser: unexpected response type"));
return false;
}
IRCMessage * m = d->app->getReplyMessage();
if (m == NULL)
{
if (m == NULL) {
wxLogError(wxT("CIRCDDB::receiveUser: no message"));
return false;
}
if (!m->getCommand().IsSameAs(wxT("IDRT_USER")))
{
if (!m->getCommand().IsSameAs(wxT("IDRT_USER"))) {
wxLogError(wxT("CIRCDDB::receiveUser: wrong message type"));
return false;
}
if (m->getParamCount() != 5)
{
if (m->getParamCount() != 5) {
wxLogError(wxT("CIRCDDB::receiveUser: unexpected number of message parameters"));
return false;
}

@ -41,7 +41,8 @@ enum DSTAR_PROTOCOL {
struct CIRCDDBPrivate;
class CIRCDDB {
class CIRCDDB
{
public:
CIRCDDB(const wxString& hostName, unsigned int port, const wxString& callsign, const wxString& password,
const wxString& versionInfo, const wxString& localAddr = wxEmptyString );

@ -44,7 +44,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
class IRCDDBAppUserObject
{
public:
public:
wxString nick;
wxString name;
@ -52,13 +52,11 @@ class IRCDDBAppUserObject
bool op;
unsigned int usn;
IRCDDBAppUserObject ()
{
IRCDDBAppUserObject () {
IRCDDBAppUserObject (wxT(""), wxT(""), wxT(""));
}
IRCDDBAppUserObject ( const wxString& n, const wxString& nm, const wxString& h )
{
IRCDDBAppUserObject ( const wxString& n, const wxString& nm, const wxString& h ) {
nick = n;
name = nm;
host = h;
@ -78,24 +76,21 @@ WX_DECLARE_STRING_HASH_MAP( IRCDDBAppUserObject, IRCDDBAppUserMap );
class IRCDDBAppRptrObject
{
public:
public:
wxString arearp_cs;
wxDateTime lastChanged;
wxString zonerp_cs;
IRCDDBAppRptrObject ()
{
IRCDDBAppRptrObject () {
}
IRCDDBAppRptrObject (wxDateTime& dt, wxString& repeaterCallsign, wxString& gatewayCallsign)
{
IRCDDBAppRptrObject (wxDateTime& dt, wxString& repeaterCallsign, wxString& gatewayCallsign) {
arearp_cs = repeaterCallsign;
lastChanged = dt;
zonerp_cs = gatewayCallsign;
if (dt.IsLaterThan(maxTime))
{
if (dt.IsLaterThan(maxTime)) {
maxTime = dt;
}
}
@ -112,15 +107,14 @@ WX_DECLARE_STRING_HASH_MAP( wxString, IRCDDBAppModuleMap );
class IRCDDBAppPrivate
{
public:
public:
IRCDDBAppPrivate()
: tablePattern(wxT("^[0-9]$")),
datePattern(wxT("^20[0-9][0-9]-((1[0-2])|(0[1-9]))-((3[01])|([12][0-9])|(0[1-9]))$")),
timePattern(wxT("^((2[0-3])|([01][0-9])):[0-5][0-9]:[0-5][0-9]$")),
dbPattern(wxT("^[0-9A-Z_]{8}$")),
modulePattern(wxT("^[ABCD]D?$"))
{
modulePattern(wxT("^[ABCD]D?$")) {
wdTimer = 0;
wdCounter = 0;
}
@ -190,8 +184,7 @@ IRCDDBApp::IRCDDBApp( const wxString& u_chan )
IRCDDBApp::~IRCDDBApp()
{
if (d->sendQ != NULL)
{
if (d->sendQ != NULL) {
delete d->sendQ;
}
delete d;
@ -239,8 +232,7 @@ void IRCDDBApp::rptrQRG( const wxString& module, double txFrequency, double dupl
double range, double agl )
{
if (d->modulePattern.Matches(module))
{
if (d->modulePattern.Matches(module)) {
wxString f = module + wxT(" ") + wxString::Format(wxT("%011.5f %+010.5f %06.2f %06.1f"),
txFrequency, duplexShift, range / 1609.344, agl );
@ -257,16 +249,13 @@ void IRCDDBApp::rptrQRG( const wxString& module, double txFrequency, double dupl
void IRCDDBApp::kickWatchdog( const wxString& s )
{
if (s.Len() > 0)
{
if (s.Len() > 0) {
wxRegEx nonValid(wxT("[^[:graph:]]"));
d->wdInfo = s;
nonValid.Replace(& d->wdInfo, wxEmptyString);
if (d->wdInfo.Len() > 0)
{
if (d->wdTimer == 0)
{
if (d->wdInfo.Len() > 0) {
if (d->wdTimer == 0) {
d->wdTimer ++;
}
@ -284,23 +273,17 @@ int IRCDDBApp::getConnectionState()
IRCDDB_RESPONSE_TYPE IRCDDBApp::getReplyMessageType()
{
IRCMessage * m = d->replyQ.peekFirst();
if (m == NULL)
{
if (m == NULL) {
return IDRT_NONE;
}
wxString msgType = m->getCommand();
if (msgType.IsSameAs(wxT("IDRT_USER")))
{
if (msgType.IsSameAs(wxT("IDRT_USER"))) {
return IDRT_USER;
}
else if (msgType.IsSameAs(wxT("IDRT_REPEATER")))
{
} else if (msgType.IsSameAs(wxT("IDRT_REPEATER"))) {
return IDRT_REPEATER;
}
else if (msgType.IsSameAs(wxT("IDRT_GATEWAY")))
{
} else if (msgType.IsSameAs(wxT("IDRT_GATEWAY"))) {
return IDRT_GATEWAY;
}
@ -320,16 +303,14 @@ IRCMessage * IRCDDBApp::getReplyMessage()
bool IRCDDBApp::startWork()
{
if (Create() != wxTHREAD_NO_ERROR)
{
if (Create() != wxTHREAD_NO_ERROR) {
wxLogError(wxT("IRCClient::startWork: Could not create the worker thread!"));
return false;
}
d->terminateThread = false;
if (Run() != wxTHREAD_NO_ERROR)
{
if (Run() != wxTHREAD_NO_ERROR) {
wxLogError(wxT("IRCClient::startWork: Could not run the worker thread!"));
return false;
}
@ -358,16 +339,13 @@ void IRCDDBApp::userJoin (const wxString& nick, const wxString& name, const wxSt
// wxLogVerbose(wxT("add %d: (") + u.nick + wxT(") (") + u.host + wxT(")"), d->user.size());
if (d->initReady)
{
if (d->initReady) {
int hyphenPos = nick.Find(wxT('-'));
if ((hyphenPos >= 4) && (hyphenPos <= 6))
{
if ((hyphenPos >= 4) && (hyphenPos <= 6)) {
wxString gatewayCallsign = nick.Mid(0, hyphenPos).Upper();
while (gatewayCallsign.Length() < 7)
{
while (gatewayCallsign.Length() < 7) {
gatewayCallsign.Append(wxT(' '));
}
@ -397,22 +375,18 @@ void IRCDDBApp::userLeave (const wxString& nick)
// wxLogVerbose(wxT("rm %d: ") + nick, d->user.size());
if (d->currentServer.Len() > 0)
{
if (d->user.count(d->myNick) != 1)
{
if (d->currentServer.Len() > 0) {
if (d->user.count(d->myNick) != 1) {
wxLogVerbose(wxT("IRCDDBApp::userLeave: could not find own nick"));
return;
}
IRCDDBAppUserObject me = d->user[d->myNick];
if (me.op == false)
{
if (me.op == false) {
// if I am not op, then look for new server
if (d->currentServer.IsSameAs(lnick))
{
if (d->currentServer.IsSameAs(lnick)) {
// currentServer = null;
d->state = 2; // choose new server
d->timer = 200;
@ -454,13 +428,11 @@ bool IRCDDBApp::findServerUser()
IRCDDBAppUserMap::iterator it;
for( it = d->user.begin(); it != d->user.end(); ++it )
{
for( it = d->user.begin(); it != d->user.end(); ++it ) {
IRCDDBAppUserObject u = it->second;
if (u.nick.StartsWith(wxT("s-")) && u.op && !d->myNick.IsSameAs(u.nick)
&& u.nick.IsSameAs(d->bestServer))
{
&& u.nick.IsSameAs(d->bestServer)) {
d->currentServer = u.nick;
found = true;
break;
@ -470,15 +442,12 @@ bool IRCDDBApp::findServerUser()
if (found)
return true;
if (d->bestServer.Len() == 8)
{
for( it = d->user.begin(); it != d->user.end(); ++it )
{
if (d->bestServer.Len() == 8) {
for( it = d->user.begin(); it != d->user.end(); ++it ) {
IRCDDBAppUserObject u = it->second;
if (u.nick.StartsWith(d->bestServer.Mid(0,7)) && u.op &&
!d->myNick.IsSameAs(u.nick) )
{
!d->myNick.IsSameAs(u.nick) ) {
d->currentServer = u.nick;
found = true;
break;
@ -489,12 +458,10 @@ bool IRCDDBApp::findServerUser()
if (found)
return true;
for( it = d->user.begin(); it != d->user.end(); ++it )
{
for( it = d->user.begin(); it != d->user.end(); ++it ) {
IRCDDBAppUserObject u = it->second;
if (u.nick.StartsWith(wxT("s-")) && u.op && !d->myNick.IsSameAs(u.nick))
{
if (u.nick.StartsWith(wxT("s-")) && u.op && !d->myNick.IsSameAs(u.nick)) {
d->currentServer = u.nick;
found = true;
break;
@ -511,8 +478,7 @@ void IRCDDBApp::userChanOp (const wxString& nick, bool op)
wxString lnick = nick;
lnick.MakeLower();
if (d->user.count(lnick) == 1)
{
if (d->user.count(lnick) == 1) {
d->user[lnick].op = op;
}
}
@ -538,17 +504,14 @@ wxString IRCDDBApp::getIPAddress(wxString& zonerp_cs)
int j;
for (j=1; j <= 4; j++)
{
for (j=1; j <= 4; j++) {
// int i = 0;
wxString ircUser = gw.Strip() + wxString::Format(wxT("-%d"), j);
if (d->user.count(ircUser) == 1)
{
if (d->user.count(ircUser) == 1) {
IRCDDBAppUserObject o = d->user[ ircUser ];
if (o.usn >= max_usn)
{
if (o.usn >= max_usn) {
max_usn = o.usn;
ipAddr = o.host;
}
@ -589,10 +552,8 @@ static void findReflector( const wxString& rptrCall, IRCDDBAppPrivate * d )
safeStringCopy(host_name, host.mb_str(wxConvUTF8), sizeof host_name);
if (getAllIPV4Addresses(host_name, 0, &numAddr, addr, MAXIPV4ADDR) == 0)
{
if (numAddr > 0)
{
if (getAllIPV4Addresses(host_name, 0, &numAddr, addr, MAXIPV4ADDR) == 0) {
if (numAddr > 0) {
unsigned char * a = (unsigned char *) &addr[0].sin_addr;
ipAddr = wxString::Format(wxT("%d.%d.%d.%d"), a[0], a[1], a[2], a[3]);
@ -612,8 +573,7 @@ static void findReflector( const wxString& rptrCall, IRCDDBAppPrivate * d )
bool IRCDDBApp::findRepeater(const wxString& rptrCall)
{
if (rptrCall.StartsWith(wxT("XRF")) || rptrCall.StartsWith(wxT("REF")))
{
if (rptrCall.StartsWith(wxT("XRF")) || rptrCall.StartsWith(wxT("REF"))) {
findReflector(rptrCall, d);
return true;
}
@ -627,8 +587,7 @@ bool IRCDDBApp::findRepeater(const wxString& rptrCall)
wxString s = wxT("NONE");
if (d->rptrMap.count(arearp_cs) == 1)
{
if (d->rptrMap.count(arearp_cs) == 1) {
IRCDDBAppRptrObject o = d->rptrMap[arearp_cs];
zonerp_cs = o.zonerp_cs;
zonerp_cs.Replace(wxT("_"), wxT(" "));
@ -676,8 +635,7 @@ bool IRCDDBApp::sendHeard(const wxString& myCall, const wxString& myCallExt,
wxString srv = d->currentServer;
IRCMessageQueue * q = getSendQ();
if ((srv.Len() > 0) && (d->state >= 6) && (q != NULL))
{
if ((srv.Len() > 0) && (d->state >= 6) && (q != NULL)) {
wxString cmd = wxT("UPDATE ");
cmd.Append( getCurrentTime() );
@ -688,8 +646,7 @@ bool IRCDDBApp::sendHeard(const wxString& myCall, const wxString& myCallExt,
cmd.Append(wxT(" "));
cmd.Append(r1);
cmd.Append(wxT(" "));
if (!statsMsg)
{
if (!statsMsg) {
cmd.Append(wxT("0 "));
}
cmd.Append(r2);
@ -703,18 +660,14 @@ bool IRCDDBApp::sendHeard(const wxString& myCall, const wxString& myCallExt,
cmd.Append(wxT(" "));
cmd.Append(myext);
if (statsMsg)
{
if (statsMsg) {
cmd.Append(wxT(" # "));
cmd.Append(tx_stats);
}
else
{
} else {
cmd.Append(wxT(" 00 "));
cmd.Append(dest);
if (tx_msg.Len() == 20)
{
if (tx_msg.Len() == 20) {
cmd.Append(wxT(" "));
cmd.Append(tx_msg);
}
@ -725,9 +678,7 @@ bool IRCDDBApp::sendHeard(const wxString& myCall, const wxString& myCallExt,
q->putMessage(m);
return true;
}
else
{
} else {
return false;
}
}
@ -737,8 +688,7 @@ bool IRCDDBApp::findUser(const wxString& usrCall)
wxString srv = d->currentServer;
IRCMessageQueue * q = getSendQ();
if ((srv.Len() > 0) && (d->state >= 6) && (q != NULL))
{
if ((srv.Len() > 0) && (d->state >= 6) && (q != NULL)) {
wxString usr = usrCall;
usr.Replace(wxT(" "), wxT("_"));
@ -747,9 +697,7 @@ bool IRCDDBApp::findUser(const wxString& usrCall)
wxT("FIND ") + usr );
q->putMessage(m);
}
else
{
} else {
IRCMessage * m2 = new IRCMessage(wxT("IDRT_USER"));
m2->addParam(usrCall);
m2->addParam(wxT(""));
@ -765,8 +713,7 @@ bool IRCDDBApp::findUser(const wxString& usrCall)
void IRCDDBApp::msgChannel (IRCMessage * m)
{
if (m->getPrefixNick().StartsWith(wxT("s-")) && (m->numParams >= 2)) // server msg
{
if (m->getPrefixNick().StartsWith(wxT("s-")) && (m->numParams >= 2)) { // server msg
doUpdate(m->params[1]);
}
}
@ -778,44 +725,35 @@ void IRCDDBApp::doNotFound ( wxString& msg, wxString& retval )
wxStringTokenizer tkz(msg);
if (!tkz.HasMoreTokens())
{
if (!tkz.HasMoreTokens()) {
return; // no text in message
}
wxString tk = tkz.GetNextToken();
if (d->tablePattern.Matches(tk))
{
if (d->tablePattern.Matches(tk)) {
long i;
if (tk.ToLong(&i))
{
if (tk.ToLong(&i)) {
tableID = i;
if ((tableID < 0) || (tableID >= numberOfTables))
{
if ((tableID < 0) || (tableID >= numberOfTables)) {
wxLogVerbose(wxT("invalid table ID %d"), tableID);
return;
}
}
else
{
} else {
return; // not a valid number
}
if (!tkz.HasMoreTokens())
{
if (!tkz.HasMoreTokens()) {
return; // received nothing but the tableID
}
tk = tkz.GetNextToken();
}
if (tableID == 0)
{
if (! d->dbPattern.Matches(tk))
{
if (tableID == 0) {
if (! d->dbPattern.Matches(tk)) {
return; // no valid key
}
@ -829,100 +767,82 @@ void IRCDDBApp::doUpdate ( wxString& msg )
wxStringTokenizer tkz(msg);
if (!tkz.HasMoreTokens())
{
if (!tkz.HasMoreTokens()) {
return; // no text in message
}
wxString tk = tkz.GetNextToken();
if (d->tablePattern.Matches(tk))
{
if (d->tablePattern.Matches(tk)) {
long i;
if (tk.ToLong(&i))
{
if (tk.ToLong(&i)) {
tableID = i;
if ((tableID < 0) || (tableID >= numberOfTables))
{
if ((tableID < 0) || (tableID >= numberOfTables)) {
wxLogVerbose(wxT("invalid table ID %d"), tableID);
return;
}
}
else
{
} else {
return; // not a valid number
}
if (!tkz.HasMoreTokens())
{
if (!tkz.HasMoreTokens()) {
return; // received nothing but the tableID
}
tk = tkz.GetNextToken();
}
if (d->datePattern.Matches(tk))
{
if (!tkz.HasMoreTokens())
{
if (d->datePattern.Matches(tk)) {
if (!tkz.HasMoreTokens()) {
return; // nothing after date string
}
wxString timeToken = tkz.GetNextToken();
if (! d->timePattern.Matches(timeToken))
{
if (! d->timePattern.Matches(timeToken)) {
return; // no time string after date string
}
wxDateTime dt;
if (dt.ParseFormat(tk + wxT(" ") + timeToken, wxT("%Y-%m-%d %H:%M:%S")) == NULL)
{
if (dt.ParseFormat(tk + wxT(" ") + timeToken, wxT("%Y-%m-%d %H:%M:%S")) == NULL) {
return; // date+time parsing failed
}
if ((tableID == 0) || (tableID == 1))
{
if (!tkz.HasMoreTokens())
{
if ((tableID == 0) || (tableID == 1)) {
if (!tkz.HasMoreTokens()) {
return; // nothing after time string
}
wxString key = tkz.GetNextToken();
if (! d->dbPattern.Matches(key))
{
if (! d->dbPattern.Matches(key)) {
return; // no valid key
}
if (!tkz.HasMoreTokens())
{
if (!tkz.HasMoreTokens()) {
return; // nothing after time string
}
wxString value = tkz.GetNextToken();
if (! d->dbPattern.Matches(value))
{
if (! d->dbPattern.Matches(value)) {
return; // no valid key
}
//wxLogVerbose(wxT("TABLE %d ") + key + wxT(" ") + value, tableID );
if (tableID == 1)
{
if (tableID == 1) {
wxMutexLocker lock(d->rptrMapMutex);
IRCDDBAppRptrObject newRptr(dt, key, value);
d->rptrMap[key] = newRptr;
if (d->initReady)
{
if (d->initReady) {
wxString arearp_cs = key;
wxString zonerp_cs = value;
@ -936,9 +856,7 @@ void IRCDDBApp::doUpdate ( wxString& msg )
m2->addParam(getIPAddress(value));
d->replyQ.putMessage(m2);
}
}
else if ((tableID == 0) && d->initReady)
{
} else if ((tableID == 0) && d->initReady) {
wxMutexLocker lock(d->rptrMapMutex);
wxString userCallsign = key;
@ -949,8 +867,7 @@ void IRCDDBApp::doUpdate ( wxString& msg )
userCallsign.Replace(wxT("_"), wxT(" "));
arearp_cs.Replace(wxT("_"), wxT(" "));
if (d->rptrMap.count(value) == 1)
{
if (d->rptrMap.count(value) == 1) {
IRCDDBAppRptrObject o = d->rptrMap[value];
zonerp_cs = o.zonerp_cs;
zonerp_cs.Replace(wxT("_"), wxT(" "));
@ -978,23 +895,15 @@ void IRCDDBApp::doUpdate ( wxString& msg )
static wxString getTableIDString( int tableID, bool spaceBeforeNumber )
{
if (tableID == 0)
{
if (tableID == 0) {
return wxT("");
}
else if ((tableID > 0) && (tableID < numberOfTables))
{
if (spaceBeforeNumber)
{
} else if ((tableID > 0) && (tableID < numberOfTables)) {
if (spaceBeforeNumber) {
return wxString::Format(wxT(" %d"),tableID);
}
else
{
} else {
return wxString::Format(wxT("%d "),tableID);
}
}
else
{
} else {
return wxT(" TABLE_ID_OUT_OF_RANGE ");
}
}
@ -1003,45 +912,33 @@ static wxString getTableIDString( int tableID, bool spaceBeforeNumber )
void IRCDDBApp::msgQuery (IRCMessage * m)
{
if (m->getPrefixNick().StartsWith(wxT("s-")) && (m->numParams >= 2)) // server msg
{
if (m->getPrefixNick().StartsWith(wxT("s-")) && (m->numParams >= 2)) { // server msg
wxString msg = m->params[1];
wxStringTokenizer tkz(msg);
if (!tkz.HasMoreTokens())
{
if (!tkz.HasMoreTokens()) {
return; // no text in message
}
wxString cmd = tkz.GetNextToken();
if (cmd.IsSameAs(wxT("UPDATE")))
{
if (cmd.IsSameAs(wxT("UPDATE"))) {
wxString restOfLine = tkz.GetString();
doUpdate(restOfLine);
}
else if (cmd.IsSameAs(wxT("LIST_END")))
{
if (d->state == 5) // if in sendlist processing state
{
} else if (cmd.IsSameAs(wxT("LIST_END"))) {
if (d->state == 5) { // if in sendlist processing state
d->state = 3; // get next table
}
}
else if (cmd.IsSameAs(wxT("LIST_MORE")))
{
if (d->state == 5) // if in sendlist processing state
{
} else if (cmd.IsSameAs(wxT("LIST_MORE"))) {
if (d->state == 5) { // if in sendlist processing state
d->state = 4; // send next SENDLIST
}
}
else if (cmd.IsSameAs(wxT("NOT_FOUND")))
{
} else if (cmd.IsSameAs(wxT("NOT_FOUND"))) {
wxString callsign;
wxString restOfLine = tkz.GetString();
doNotFound(restOfLine, callsign);
if (callsign.Len() > 0)
{
if (callsign.Len() > 0) {
callsign.Replace(wxT("_"), wxT(" "));
IRCMessage * m2 = new IRCMessage(wxT("IDRT_USER"));
@ -1071,8 +968,7 @@ IRCMessageQueue * IRCDDBApp::getSendQ()
static wxString getLastEntryTime(int tableID)
{
if (tableID == 1)
{
if (tableID == 1) {
wxString max = IRCDDBAppRptrObject::maxTime.Format( wxT("%Y-%m-%d %H:%M:%S") );
return max;
}
@ -1092,20 +988,16 @@ wxThread::ExitCode IRCDDBApp::Entry()
int sendlistTableID = 0;
while (!d->terminateThread)
{
while (!d->terminateThread) {
if (d->timer > 0)
{
if (d->timer > 0) {
d->timer --;
}
switch(d->state)
{
switch(d->state) {
case 0: // wait for network to start
if (getSendQ() != NULL)
{
if (getSendQ() != NULL) {
d->state = 1;
}
break;
@ -1118,28 +1010,21 @@ wxThread::ExitCode IRCDDBApp::Entry()
case 2: // choose server
wxLogVerbose(wxT("IRCDDBApp: state=2 choose new 's-'-user"));
if (getSendQ() == NULL)
{
if (getSendQ() == NULL) {
d->state = 10;
}
else
{
if (findServerUser())
{
} else {
if (findServerUser()) {
sendlistTableID = numberOfTables;
d->state = 3; // next: send "SENDLIST"
}
else if (d->timer == 0)
{
} else if (d->timer == 0) {
d->state = 10;
IRCMessage * m = new IRCMessage(wxT("QUIT"));
m->addParam(wxT("no op user with 's-' found."));
IRCMessageQueue * q = getSendQ();
if (q != NULL)
{
if (q != NULL) {
q->putMessage(m);
}
}
@ -1147,19 +1032,13 @@ wxThread::ExitCode IRCDDBApp::Entry()
break;
case 3:
if (getSendQ() == NULL)
{
if (getSendQ() == NULL) {
d->state = 10; // disconnect DB
}
else
{
} else {
sendlistTableID --;
if (sendlistTableID < 0)
{
if (sendlistTableID < 0) {
d->state = 6; // end of sendlist
}
else
{
} else {
wxLogVerbose(wxT("IRCDDBApp: state=3 tableID=%d"), sendlistTableID);
d->state = 4; // send "SENDLIST"
d->timer = 900; // 15 minutes max for update
@ -1168,48 +1047,37 @@ wxThread::ExitCode IRCDDBApp::Entry()
break;
case 4:
if (getSendQ() == NULL)
{
if (getSendQ() == NULL) {
d->state = 10; // disconnect DB
}
else
{
if (needsDatabaseUpdate(sendlistTableID))
{
} else {
if (needsDatabaseUpdate(sendlistTableID)) {
IRCMessage * m = new IRCMessage(d->currentServer,
wxT("SENDLIST") + getTableIDString(sendlistTableID, true)
+ wxT(" ") + getLastEntryTime(sendlistTableID) );
IRCMessageQueue * q = getSendQ();
if (q != NULL)
{
if (q != NULL) {
q->putMessage(m);
}
d->state = 5; // wait for answers
}
else
{
} else {
d->state = 3; // don't send SENDLIST for this table, go to next table
}
}
break;
case 5: // sendlist processing
if (getSendQ() == NULL)
{
if (getSendQ() == NULL) {
d->state = 10; // disconnect DB
}
else if (d->timer == 0)
{
} else if (d->timer == 0) {
d->state = 10; // disconnect DB
IRCMessage * m = new IRCMessage(wxT("QUIT"));
m->addParam(wxT("timeout SENDLIST"));
IRCMessageQueue * q = getSendQ();
if (q != NULL)
{
if (q != NULL) {
q->putMessage(m);
}
@ -1217,12 +1085,9 @@ wxThread::ExitCode IRCDDBApp::Entry()
break;
case 6:
if (getSendQ() == NULL)
{
if (getSendQ() == NULL) {
d->state = 10; // disconnect DB
}
else
{
} else {
wxLogVerbose(wxT( "IRCDDBApp: state=6 initialization completed"));
d->infoTimer = 2;
@ -1234,37 +1099,30 @@ wxThread::ExitCode IRCDDBApp::Entry()
case 7: // standby state after initialization
if (getSendQ() == NULL)
{
if (getSendQ() == NULL) {
d->state = 10; // disconnect DB
}
if (d->infoTimer > 0)
{
if (d->infoTimer > 0) {
d->infoTimer --;
if (d->infoTimer == 0)
{
if (d->rptrLocation.Len() > 0)
{
if (d->infoTimer == 0) {
if (d->rptrLocation.Len() > 0) {
IRCMessage * m = new IRCMessage(d->currentServer,
wxT("IRCDDB QTH: ") + d->rptrLocation);
IRCMessageQueue * q = getSendQ();
if (q != NULL)
{
if (q != NULL) {
q->putMessage(m);
}
}
if (d->rptrInfoURL.Len() > 0)
{
if (d->rptrInfoURL.Len() > 0) {
IRCMessage * m = new IRCMessage(d->currentServer,
wxT("IRCDDB URL: ") + d->rptrInfoURL);
IRCMessageQueue * q = getSendQ();
if (q != NULL)
{
if (q != NULL) {
q->putMessage(m);
}
}
@ -1272,26 +1130,22 @@ wxThread::ExitCode IRCDDBApp::Entry()
wxMutexLocker lock(d->moduleMapMutex);
IRCDDBAppModuleMap::iterator it;
for( it = d->moduleMap.begin(); it != d->moduleMap.end(); ++it )
{
for( it = d->moduleMap.begin(); it != d->moduleMap.end(); ++it ) {
wxString value = it->second;
IRCMessage * m = new IRCMessage(d->currentServer,
wxT("IRCDDB QRG: ") + value);
IRCMessageQueue * q = getSendQ();
if (q != NULL)
{
if (q != NULL) {
q->putMessage(m);
}
}
}
}
if (d->wdTimer > 0)
{
if (d->wdTimer > 0) {
d->wdTimer --;
if (d->wdTimer == 0)
{
if (d->wdTimer == 0) {
d->wdTimer = 900; // 15 minutes
IRCMessage * m = new IRCMessage(d->currentServer,
@ -1300,8 +1154,7 @@ wxThread::ExitCode IRCDDBApp::Entry()
wxString::Format(wxT(" %d"), d->wdCounter ));
IRCMessageQueue * q = getSendQ();
if (q != NULL)
{
if (q != NULL) {
q->putMessage(m);
d->wdCounter = 0;
}

@ -32,7 +32,7 @@ class IRCDDBAppPrivate;
class IRCDDBApp : public IRCApplication, wxThread
{
public:
public:
IRCDDBApp(const wxString& update_channel);
virtual ~IRCDDBApp();
@ -83,10 +83,10 @@ class IRCDDBApp : public IRCApplication, wxThread
void kickWatchdog( const wxString& wdInfo );
protected:
protected:
virtual wxThread::ExitCode Entry();
private:
private:
void doUpdate ( wxString& msg );
void doNotFound ( wxString& msg, wxString& retval );
wxString getIPAddress( wxString& zonerp_cs );

@ -76,19 +76,16 @@ void IRCMessage::parsePrefix()
{
unsigned int i;
for (i=0; i < 3; i++)
{
for (i=0; i < 3; i++) {
prefixComponents.Add(wxT(""));
}
int state = 0;
for (i=0; i < prefix.Len(); i++)
{
for (i=0; i < prefix.Len(); i++) {
wxChar c = prefix.GetChar(i);
switch (c)
{
switch (c) {
case wxT('!'):
state = 1; // next is name
break;
@ -108,8 +105,7 @@ void IRCMessage::parsePrefix()
wxString& IRCMessage::getPrefixNick()
{
if (!prefixParsed)
{
if (!prefixParsed) {
parsePrefix();
}
@ -118,8 +114,7 @@ wxString& IRCMessage::getPrefixNick()
wxString& IRCMessage::getPrefixName()
{
if (!prefixParsed)
{
if (!prefixParsed) {
parsePrefix();
}
@ -128,8 +123,7 @@ wxString& IRCMessage::getPrefixName()
wxString& IRCMessage::getPrefixHost()
{
if (!prefixParsed)
{
if (!prefixParsed) {
parsePrefix();
}
@ -140,8 +134,7 @@ void IRCMessage::composeMessage ( wxString& output )
{
#if defined(DEBUG_IRC)
wxString d = wxT("T [") + prefix + wxT("] [") + command + wxT("]");
for (int i=0; i < numParams; i++)
{
for (int i=0; i < numParams; i++) {
d.Append(wxT(" [") + params[i] + wxT("]") );
}
d.Replace(wxT("%"), wxT("%%"), true);
@ -151,21 +144,16 @@ void IRCMessage::composeMessage ( wxString& output )
wxString o;
if (prefix.Len() > 0)
{
if (prefix.Len() > 0) {
o = wxT(":") + prefix + wxT(" ");
}
o.Append(command);
for (int i=0; i < numParams; i++)
{
if (i == (numParams - 1))
{
for (int i=0; i < numParams; i++) {
if (i == (numParams - 1)) {
o.Append(wxT(" :") + params[i]);
}
else
{
} else {
o.Append(wxT(" ") + params[i]);
}
}

@ -27,7 +27,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
class IRCMessage
{
public:
public:
IRCMessage();
@ -59,7 +59,7 @@ class IRCMessage
int getParamCount();
private:
private:
void parsePrefix();

@ -32,8 +32,7 @@ IRCMessageQueue::IRCMessageQueue()
IRCMessageQueue::~IRCMessageQueue()
{
while (messageAvailable())
{
while (messageAvailable()) {
IRCMessage * m = getMessage();
delete m;
@ -67,8 +66,7 @@ IRCMessage * IRCMessageQueue::peekFirst()
IRCMessageQueueItem * k = first;
if ( k == NULL )
{
if ( k == NULL ) {
return NULL;
}
@ -82,8 +80,7 @@ IRCMessage * IRCMessageQueue::getMessage()
IRCMessageQueueItem * k;
if (first == NULL)
{
if (first == NULL) {
return NULL;
}
@ -91,12 +88,9 @@ IRCMessage * IRCMessageQueue::getMessage()
first = k -> next;
if (k -> next == NULL)
{
if (k -> next == NULL) {
last = NULL;
}
else
{
} else {
k -> next -> prev = NULL;
}
@ -120,12 +114,9 @@ void IRCMessageQueue::putMessage( IRCMessage * m )
k -> prev = last;
k -> next = NULL;
if (last == NULL)
{
if (last == NULL) {
first = k;
}
else
{
} else {
last -> next = k;
}

@ -29,14 +29,12 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
class IRCMessageQueueItem
{
public:
IRCMessageQueueItem( IRCMessage * m )
{
public:
IRCMessageQueueItem( IRCMessage * m ) {
msg = m;
}
~IRCMessageQueueItem()
{
~IRCMessageQueueItem() {
}
IRCMessage * msg;
@ -48,7 +46,7 @@ class IRCMessageQueueItem
class IRCMessageQueue
{
public:
public:
IRCMessageQueue();
~IRCMessageQueue();
@ -65,7 +63,7 @@ class IRCMessageQueue
void putMessage ( IRCMessage * m );
private:
private:
bool eof;

@ -37,8 +37,7 @@ IRCProtocol::IRCProtocol ( IRCApplication * app,
this->versionInfo = wxT("CIRCDDB:");
this->versionInfo.Append(wxT(CIRCDDB_VERSION));
if (versionInfo.Len() > 0)
{
if (versionInfo.Len() > 0) {
this->versionInfo.Append(wxT(" "));
this->versionInfo.Append(versionInfo);
}
@ -46,8 +45,7 @@ IRCProtocol::IRCProtocol ( IRCApplication * app,
int hyphenPos = callsign.find(wxT('-'));
if (hyphenPos == wxNOT_FOUND)
{
if (hyphenPos == wxNOT_FOUND) {
wxString n;
n = callsign + wxT("-1");
@ -58,9 +56,7 @@ IRCProtocol::IRCProtocol ( IRCApplication * app,
nicks.Add(n);
n = callsign + wxT("-4");
nicks.Add(n);
}
else
{
} else {
nicks.Add(callsign);
}
@ -87,18 +83,14 @@ void IRCProtocol::chooseNewNick()
void IRCProtocol::setNetworkReady( bool b )
{
if (b == true)
{
if (state != 0)
{
if (b == true) {
if (state != 0) {
wxLogError(wxT("IRCProtocol::setNetworkReady: unexpected state"));
}
state = 1;
chooseNewNick();
}
else
{
} else {
state = 0;
}
}
@ -106,19 +98,16 @@ void IRCProtocol::setNetworkReady( bool b )
bool IRCProtocol::processQueues ( IRCMessageQueue * recvQ, IRCMessageQueue * sendQ )
{
if (timer > 0)
{
if (timer > 0) {
timer --;
}
while (recvQ->messageAvailable())
{
while (recvQ->messageAvailable()) {
IRCMessage * m = recvQ -> getMessage();
#if defined(DEBUG_IRC)
wxString d = wxT("R [") + m->prefix + wxT("] [") + m->command + wxT("]");
for (int i=0; i < m->numParams; i++)
{
for (int i=0; i < m->numParams; i++) {
d.Append(wxT(" [") + m->params[i] + wxT("]") );
}
d.Replace(wxT("%"), wxT("%%"), true);
@ -126,170 +115,111 @@ bool IRCProtocol::processQueues ( IRCMessageQueue * recvQ, IRCMessageQueue * sen
wxLogVerbose(d);
#endif
if (m->command.IsSameAs(wxT("004")))
{
if (state == 4)
{
if (m->params.GetCount() > 1)
{
if (m->command.IsSameAs(wxT("004"))) {
if (state == 4) {
if (m->params.GetCount() > 1) {
wxRegEx serverNamePattern(wxT("^grp[1-9]s[1-9].ircDDB$"));
if (serverNamePattern.Matches( m->params[1] ))
{
if (serverNamePattern.Matches( m->params[1] )) {
app->setBestServer(wxT("s-") + m->params[1].Mid(0,6));
}
}
state = 5; // next: JOIN
app->setCurrentNick(currentNick);
}
}
else if (m->command.IsSameAs(wxT("PING")))
{
} else if (m->command.IsSameAs(wxT("PING"))) {
IRCMessage * m2 = new IRCMessage();
m2->command = wxT("PONG");
if (m->params.GetCount() > 0)
{
if (m->params.GetCount() > 0) {
m2->numParams = 1;
m2->params.Add( m->params[0] );
}
sendQ -> putMessage(m2);
}
else if (m->command.IsSameAs(wxT("JOIN")))
{
if ((m->numParams >= 1) && m->params[0].IsSameAs(channel))
{
if (m->getPrefixNick().IsSameAs(currentNick) && (state == 6))
{
if (debugChannel.Len() > 0)
{
} else if (m->command.IsSameAs(wxT("JOIN"))) {
if ((m->numParams >= 1) && m->params[0].IsSameAs(channel)) {
if (m->getPrefixNick().IsSameAs(currentNick) && (state == 6)) {
if (debugChannel.Len() > 0) {
state = 7; // next: join debug_channel
}
else
{
} else {
state = 10; // next: WHO *
}
}
else if (app != NULL)
{
} else if (app != NULL) {
app->userJoin( m->getPrefixNick(), m->getPrefixName(), m->getPrefixHost());
}
}
if ((m->numParams >= 1) && m->params[0].IsSameAs(debugChannel))
{
if (m->getPrefixNick().IsSameAs(currentNick) && (state == 8))
{
if ((m->numParams >= 1) && m->params[0].IsSameAs(debugChannel)) {
if (m->getPrefixNick().IsSameAs(currentNick) && (state == 8)) {
state = 10; // next: WHO *
}
}
}
else if (m->command.IsSameAs(wxT("PONG")))
{
if (state == 12)
{
} else if (m->command.IsSameAs(wxT("PONG"))) {
if (state == 12) {
timer = pingTimer;
state = 11;
}
}
else if (m->command.IsSameAs(wxT("PART")))
{
if ((m->numParams >= 1) && m->params[0].IsSameAs(channel))
{
if (app != NULL)
{
} else if (m->command.IsSameAs(wxT("PART"))) {
if ((m->numParams >= 1) && m->params[0].IsSameAs(channel)) {
if (app != NULL) {
app->userLeave( m->getPrefixNick() );
}
}
}
else if (m->command.IsSameAs(wxT("KICK")))
{
if ((m->numParams >= 2) && m->params[0].IsSameAs(channel))
{
if (m->params[1].IsSameAs(currentNick))
{
} else if (m->command.IsSameAs(wxT("KICK"))) {
if ((m->numParams >= 2) && m->params[0].IsSameAs(channel)) {
if (m->params[1].IsSameAs(currentNick)) {
// i was kicked!!
delete m;
return false;
}
else if (app != NULL)
{
} else if (app != NULL) {
app->userLeave( m->params[1] );
}
}
}
else if (m->command.IsSameAs(wxT("QUIT")))
{
if (app != NULL)
{
} else if (m->command.IsSameAs(wxT("QUIT"))) {
if (app != NULL) {
app->userLeave( m->getPrefixNick() );
}
}
else if (m->command.IsSameAs(wxT("MODE")))
{
if ((m->numParams >= 3) && m->params[0].IsSameAs(channel))
{
if (app != NULL)
{
} else if (m->command.IsSameAs(wxT("MODE"))) {
if ((m->numParams >= 3) && m->params[0].IsSameAs(channel)) {
if (app != NULL) {
size_t i;
wxString mode = m->params[1];
for (i = 1; (i < mode.Len()) && ((size_t) m->numParams >= (i+2)); i++)
{
if ( mode[i] == wxT('o') )
{
if ( mode[0] == wxT('+') )
{
for (i = 1; (i < mode.Len()) && ((size_t) m->numParams >= (i+2)); i++) {
if ( mode[i] == wxT('o') ) {
if ( mode[0] == wxT('+') ) {
app->userChanOp(m->params[i+1], true);
}
else if ( mode[0] == wxT('-') )
{
} else if ( mode[0] == wxT('-') ) {
app->userChanOp(m->params[i+1], false);
}
}
} // for
}
}
}
else if (m->command.IsSameAs(wxT("PRIVMSG")))
{
if ((m->numParams == 2) && (app != NULL))
{
if (m->params[0].IsSameAs(channel))
{
} else if (m->command.IsSameAs(wxT("PRIVMSG"))) {
if ((m->numParams == 2) && (app != NULL)) {
if (m->params[0].IsSameAs(channel)) {
app->msgChannel(m);
}
else if (m->params[0].IsSameAs(currentNick))
{
} else if (m->params[0].IsSameAs(currentNick)) {
app->msgQuery(m);
}
}
}
else if (m->command.IsSameAs(wxT("352"))) // WHO list
{
} else if (m->command.IsSameAs(wxT("352"))) { // WHO list
if ((m->numParams >= 7) && m->params[0].IsSameAs(currentNick)
&& m->params[1].IsSameAs(channel))
{
if (app != NULL)
{
&& m->params[1].IsSameAs(channel)) {
if (app != NULL) {
app->userJoin( m->params[5], m->params[2], m->params[3]);
app->userChanOp ( m->params[5], m->params[6].IsSameAs(wxT("H@")));
}
}
}
else if (m->command.IsSameAs(wxT("433"))) // nick collision
{
if (state == 2)
{
} else if (m->command.IsSameAs(wxT("433"))) { // nick collision
if (state == 2) {
state = 3; // nick collision, choose new nick
timer = 10; // wait 5 seconds..
}
}
else if (m->command.IsSameAs(wxT("332")) ||
m->command.IsSameAs(wxT("TOPIC"))) // topic
{
} else if (m->command.IsSameAs(wxT("332")) ||
m->command.IsSameAs(wxT("TOPIC"))) { // topic
if ((m->numParams == 2) && (app != NULL) &&
m->params[0].IsSameAs(channel) )
{
m->params[0].IsSameAs(channel) ) {
app->setTopic(m->params[1]);
}
}
@ -299,8 +229,7 @@ bool IRCProtocol::processQueues ( IRCMessageQueue * recvQ, IRCMessageQueue * sen
IRCMessage * m;
switch (state)
{
switch (state) {
case 1:
m = new IRCMessage();
m->command = wxT("PASS");
@ -319,8 +248,7 @@ bool IRCProtocol::processQueues ( IRCMessageQueue * recvQ, IRCMessageQueue * sen
break;
case 2:
if (timer == 0)
{
if (timer == 0) {
m = new IRCMessage();
m->command = wxT("USER");
m->numParams = 4;
@ -336,8 +264,7 @@ bool IRCProtocol::processQueues ( IRCMessageQueue * recvQ, IRCMessageQueue * sen
break;
case 3:
if (timer == 0)
{
if (timer == 0) {
chooseNewNick();
m = new IRCMessage();
m->command = wxT("NICK");
@ -351,8 +278,7 @@ bool IRCProtocol::processQueues ( IRCMessageQueue * recvQ, IRCMessageQueue * sen
break;
case 4:
if (timer == 0)
{
if (timer == 0) {
// no login message received -> disconnect
return false;
}
@ -370,16 +296,14 @@ bool IRCProtocol::processQueues ( IRCMessageQueue * recvQ, IRCMessageQueue * sen
break;
case 6:
if (timer == 0)
{
if (timer == 0) {
// no join message received -> disconnect
return false;
}
break;
case 7:
if (debugChannel.Len() == 0)
{
if (debugChannel.Len() == 0) {
return false; // this state cannot be processed if there is no debug_channel
}
@ -394,8 +318,7 @@ bool IRCProtocol::processQueues ( IRCMessageQueue * recvQ, IRCMessageQueue * sen
break;
case 8:
if (timer == 0)
{
if (timer == 0) {
// no join message received -> disconnect
return false;
}
@ -412,15 +335,13 @@ bool IRCProtocol::processQueues ( IRCMessageQueue * recvQ, IRCMessageQueue * sen
timer = pingTimer;
state = 11; // wait for timer and then send ping
if (app != NULL)
{
if (app != NULL) {
app->setSendQ(sendQ); // this switches the application on
}
break;
case 11:
if (timer == 0)
{
if (timer == 0) {
m = new IRCMessage();
m->command = wxT("PING");
m->numParams = 1;
@ -433,8 +354,7 @@ bool IRCProtocol::processQueues ( IRCMessageQueue * recvQ, IRCMessageQueue * sen
break;
case 12:
if (timer == 0)
{
if (timer == 0) {
// no pong message received -> disconnect
return false;
}

@ -30,7 +30,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
class IRCProtocol
{
public:
public:
IRCProtocol ( IRCApplication * app,
const wxString& callsign, const wxString& password, const wxString& channel,
const wxString& versionInfo );
@ -41,7 +41,7 @@ class IRCProtocol
bool processQueues ( IRCMessageQueue * recvQ, IRCMessageQueue * sendQ );
private:
private:
void chooseNewNick();
wxArrayString nicks;

@ -54,16 +54,14 @@ IRCReceiver::~IRCReceiver()
bool IRCReceiver::startWork()
{
if (Create() != wxTHREAD_NO_ERROR)
{
if (Create() != wxTHREAD_NO_ERROR) {
wxLogError(wxT("IRCReceiver::startWork: Could not create the worker thread!"));
return false;
}
terminateThread = false;
if (Run() != wxTHREAD_NO_ERROR)
{
if (Run() != wxTHREAD_NO_ERROR) {
wxLogError(wxT("IRCReceiver::startWork: Could not run the worker thread!"));
return false;
}
@ -95,35 +93,25 @@ static int doRead( int sock, char * buf, int buf_size )
res = select(sock+1, &rdset, NULL, &errset, &tv);
if ( res < 0 )
{
if ( res < 0 ) {
wxLogSysError(wxT("IRCReceiver::doRead: select"));
return -1;
}
else if ( res > 0 )
{
if (FD_ISSET(sock, &errset))
{
} else if ( res > 0 ) {
if (FD_ISSET(sock, &errset)) {
wxLogVerbose(wxT("IRCReceiver::doRead: select (FD_ISSET(sock, exceptfds))"));
return -1;
}
if (FD_ISSET(sock, &rdset))
{
if (FD_ISSET(sock, &rdset)) {
res = recv(sock, buf, buf_size, 0);
if (res < 0)
{
if (res < 0) {
wxLogSysError(wxT("IRCReceiver::doRead: read"));
return -1;
}
else if (res == 0)
{
} else if (res == 0) {
wxLogVerbose(wxT("IRCReceiver::doRead: EOF read==0"));
return -1;
}
else
{
} else {
return res;
}
}
@ -140,96 +128,70 @@ wxThread::ExitCode IRCReceiver::Entry ()
int i;
int state = 0;
while (!terminateThread)
{
while (!terminateThread) {
// wxLogVerbose(wxT("IRCReceiver: tick"));
char buf[200];
int r = doRead( sock, buf, sizeof buf );
if (r < 0)
{
if (r < 0) {
recvQ -> signalEOF();
delete m; // delete unfinished IRCMessage
break;
}
for (i=0; i < r; i++)
{
for (i=0; i < r; i++) {
char b = buf[i];
if (b > 0)
{
if (b == 10)
{
if (b > 0) {
if (b == 10) {
recvQ -> putMessage(m);
m = new IRCMessage();
state = 0;
}
else if (b == 13)
{
} else if (b == 13) {
// do nothing
}
else switch (state)
{
} else switch (state) {
case 0:
if (b == ':')
{
if (b == ':') {
state = 1; // prefix
}
else if (b == 32)
{
} else if (b == 32) {
// do nothing
}
else
{
} else {
m -> command.Append(wxChar(b));
state = 2; // command
}
break;
case 1:
if (b == 32)
{
if (b == 32) {
state = 2; // command is next
}
else
{
} else {
m -> prefix.Append(wxChar(b));
}
break;
case 2:
if (b == 32)
{
if (b == 32) {
state = 3; // params
m -> numParams = 1;
m -> params.Add(wxT(""));
}
else
{
} else {
m -> command.Append(wxChar(b));
}
break;
case 3:
if (b == 32)
{
if (b == 32) {
m -> numParams ++;
if (m -> numParams >= 15)
{
if (m -> numParams >= 15) {
state = 5; // ignore the rest
}
m -> params.Add(wxT(""));
}
else if ((b == ':') && (m -> params[ m -> numParams-1 ].Len() == 0))
{
} else if ((b == ':') && (m -> params[ m -> numParams-1 ].Len() == 0)) {
state = 4; // rest of line is this param
}
else
{
} else {
m -> params[ m -> numParams-1 ].Append(wxChar(b));
}
break;

@ -31,7 +31,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
class IRCReceiver : public wxThread
{
public:
public:
IRCReceiver(int sock, IRCMessageQueue * q);
@ -43,13 +43,13 @@ class IRCReceiver : public wxThread
void stopWork();
protected:
protected:
virtual wxThread::ExitCode Entry();
private:
private:
bool terminateThread;

@ -55,23 +55,18 @@ int getAllIPV4Addresses ( const char * name, unsigned short port,
int r = getaddrinfo( name, NULL, &hints, &res );
if (r == 0)
{
if (r == 0) {
struct addrinfo * rp;
unsigned int numAddr = 0;
for (rp = res; rp != NULL; rp = rp->ai_next)
{
if (rp->ai_family == AF_INET)
{
for (rp = res; rp != NULL; rp = rp->ai_next) {
if (rp->ai_family == AF_INET) {
numAddr ++;
}
}
if (numAddr > 0)
{
if (numAddr > max_addr)
{
if (numAddr > 0) {
if (numAddr > max_addr) {
numAddr = max_addr;
}
@ -79,15 +74,12 @@ int getAllIPV4Addresses ( const char * name, unsigned short port,
unsigned int i;
for (i=0; i < numAddr; i++)
{
for (i=0; i < numAddr; i++) {
shuffle[i] = i;
}
for (i=0; i < (numAddr - 1); i++)
{
if (rand() & 1)
{
for (i=0; i < (numAddr - 1); i++) {
if (rand() & 1) {
int tmp;
tmp = shuffle[i];
shuffle[i] = shuffle[i+1];
@ -95,10 +87,8 @@ int getAllIPV4Addresses ( const char * name, unsigned short port,
}
}
for (i=(numAddr - 1); i > 0; i--)
{
if (rand() & 1)
{
for (i=(numAddr - 1); i > 0; i--) {
if (rand() & 1) {
int tmp;
tmp = shuffle[i];
shuffle[i] = shuffle[i-1];
@ -106,10 +96,8 @@ int getAllIPV4Addresses ( const char * name, unsigned short port,
}
}
for (rp = res, i=0 ; (rp != NULL) && (i < numAddr); rp = rp->ai_next)
{
if (rp->ai_family == AF_INET)
{
for (rp = res, i=0 ; (rp != NULL) && (i < numAddr); rp = rp->ai_next) {
if (rp->ai_family == AF_INET) {
memcpy( addr+shuffle[i], rp->ai_addr, sizeof (struct sockaddr_in) );
addr[shuffle[i]].sin_port = htons(port);
@ -127,9 +115,7 @@ int getAllIPV4Addresses ( const char * name, unsigned short port,
return 0;
}
else
{
} else {
wxString e( gai_strerror(r), wxConvUTF8);
wxLogWarning(wxT("getaddrinfo: ") + e );
@ -148,8 +134,7 @@ void safeStringCopy (char * dest, const char * src, unsigned int buf_size)
{
unsigned int i = 0;
while (i < (buf_size - 1) && (src[i] != 0))
{
while (i < (buf_size - 1) && (src[i] != 0)) {
dest[i] = src[i];
i++;
}

@ -22,8 +22,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "dstar_dv.h"
#include "golay23.h"
int bit_pos1[] =
{
int bit_pos1[] = {
0, 0, 1, 1, 2, 2,
0, 0, 1, 1, 2, 2,
0, 0, 1, 1, 2, 2,
@ -39,8 +38,7 @@ int bit_pos1[] =
0, 0, 1, 1, 2, 2
};
int bit_pos2[] =
{
int bit_pos2[] = {
23, 11,
23, 11,
23, 11,
@ -100,8 +98,7 @@ static void init_prng(void)
{
int i;
for (i=0; i < 4096; i++)
{
for (i=0; i < 4096; i++) {
int mask = 0x800000;
int j;
int pr;
@ -109,12 +106,10 @@ static void init_prng(void)
prng[i] = 0;
pr = i << 4;
for (j=0; j < 24; j++)
{
for (j=0; j < 24; j++) {
pr = ((173 * pr) + 13849) & 0xFFFF;
if ((pr & 0x8000) != 0)
{
if ((pr & 0x8000) != 0) {
prng[i] |= mask;
}
@ -133,8 +128,7 @@ void dstar_dv_init(void)
decoding_table[0] = 0;
decoding_table[1] = 1;
temp = 1;
for (i=2; i<= 23; i++)
{
for (i=2; i<= 23; i++) {
temp = temp << 1;
decoding_table[get_syndrome(temp)] = temp;
}
@ -143,8 +137,7 @@ void dstar_dv_init(void)
a[2] = 2;
temp = arr2int(a,2);
decoding_table[get_syndrome(temp)] = temp;
for (i=1; i<253; i++)
{
for (i=1; i<253; i++) {
nextcomb(23,2,a);
temp = arr2int(a,2);
decoding_table[get_syndrome(temp)] = temp;
@ -155,8 +148,7 @@ void dstar_dv_init(void)
a[3] = 3;
temp = arr2int(a,3);
decoding_table[get_syndrome(temp)] = temp;
for (i=1; i<1771; i++)
{
for (i=1; i<1771; i++) {
nextcomb(23,3,a);
temp = arr2int(a,3);
decoding_table[get_syndrome(temp)] = temp;
@ -175,26 +167,22 @@ static int golay2412 (int data, int *decoded)
int parity_corr = 0;
int i;
for (i = 0; i < 23; i++)
{
for (i = 0; i < 23; i++) {
int mask = 1 << i;
int bit_rcvd = block & mask;
int bit_corr = corrected_block & mask;
if (bit_corr != 0)
{
if (bit_corr != 0) {
parity_corr ++;
}
if (bit_rcvd != bit_corr)
{
if (bit_rcvd != bit_corr) {
errs ++;
}
}
if ((parity_corr & 0x01) != (data & 0x01))
{
if ((parity_corr & 0x01) != (data & 0x01)) {
errs ++;
}
@ -210,13 +198,11 @@ int dstar_dv_decode_first_block (const unsigned char * d, int * errs)
int i;
int data;
for (i=0; i < 3; i++)
{
for (i=0; i < 3; i++) {
bits[i] = 0;
}
for (i=0; i < 72; i++)
{
for (i=0; i < 72; i++) {
bits[ bit_pos1[i] ] |= (d[ i >> 3 ] & (0x80 >> (i & 0x07))) ? (1 << bit_pos2[i]) : 0;
}
@ -232,13 +218,11 @@ int dstar_dv_decode (const unsigned char * d, int data[3])
int i;
int errs;
for (i=0; i < 3; i++)
{
for (i=0; i < 3; i++) {
bits[i] = 0;
}
for (i=0; i < 72; i++)
{
for (i=0; i < 72; i++) {
bits[ bit_pos1[i] ] |= (d[ i >> 3 ] & (0x80 >> (i & 0x07))) ? (1 << bit_pos2[i]) : 0;
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

@ -46,23 +46,11 @@ static void calcPFCS(unsigned char rawbytes[58]);
static time_t tNow = 0;
static short streamid_raw = 0;
/***
static char silence[12] =
{
0x4e,0x8d,0x32,0x88,0x26,0x1a,0x3f,0x61,0xe8,
0x70,0x4f,0x93
};
***/
static char silence[12] =
{
0xfa,0x87,0x1e,0x32,0x30,0x2f,0xea,0x45,0x66,
0x70,0x4f,0x93
};
//static unsigned char silence[12] = { 0x4e,0x8d,0x32,0x88,0x26,0x1a,0x3f,0x61,0xe8,0x70,0x4f,0x93 };
static unsigned char silence[12] = { 0xfa,0x87,0x1e,0x32,0x30,0x2f,0xea,0x45,0x66,0x70,0x4f,0x93 };
static unsigned short crc_tabccitt[256] =
{
static unsigned short crc_tabccitt[256] = {
0x0000,0x1189,0x2312,0x329b,0x4624,0x57ad,0x6536,0x74bf,
0x8c48,0x9dc1,0xaf5a,0xbed3,0xca6c,0xdbe5,0xe97e,0xf8f7,
0x1081,0x0108,0x3393,0x221a,0x56a5,0x472c,0x75b7,0x643e,
@ -104,8 +92,7 @@ static void calcPFCS(unsigned char rawbytes[58])
unsigned short tmp, short_c;
short int i;
for (i = 17; i < 56 ; i++)
{
for (i = 17; i < 56 ; i++) {
short_c = 0x00ff & (unsigned short)rawbytes[i];
tmp = (crc_dstar_ffff & 0x00ff) ^ short_c;
crc_dstar_ffff = (crc_dstar_ffff >> 8) ^ crc_tabccitt[tmp];
@ -123,14 +110,13 @@ static bool dst_open(char *ip, int port)
int reuse = 1;
sockDst = socket(PF_INET,SOCK_DGRAM,0);
if (sockDst == -1)
{
if (sockDst == -1) {
printf("Failed to create DSTAR socket\n");
return false;
}
if (setsockopt(sockDst,SOL_SOCKET,SO_REUSEADDR, (char *)&reuse, sizeof(reuse)) == -1)
{
close(sockDst); sockDst = -1;
if (setsockopt(sockDst,SOL_SOCKET,SO_REUSEADDR, (char *)&reuse, sizeof(reuse)) == -1) {
close(sockDst);
sockDst = -1;
printf("setsockopt DSTAR REUSE failed\n");
return false;
}
@ -145,8 +131,7 @@ static bool dst_open(char *ip, int port)
static void dst_close()
{
if (sockDst != -1)
{
if (sockDst != -1) {
close(sockDst);
sockDst = -1;
}
@ -161,8 +146,7 @@ int main(int argc, char **argv)
char RADIO_ID[21];
short int i;
if (argc != 10)
{
if (argc != 10) {
printf("Usage: g2link_test <IPaddress> <port> <textMessage> <repeaterCallsign> <module> <delay_between> <delay_before> <MYCALL> <YRCALL>\n");
printf("Example: g2link_test 127.0.0.1 19000 \"HELLO\" KJ4NHF B 20 2 KI4LKF XRF005AL\n");
printf("Where...\n\n");
@ -179,8 +163,7 @@ int main(int argc, char **argv)
return 0;
}
if (strlen(argv[4]) > 6)
{
if (strlen(argv[4]) > 6) {
printf("repeaterCallsign can not be more than 6 characters, %s is invalid\n", argv[4]);
return 0;
}
@ -188,8 +171,7 @@ int main(int argc, char **argv)
argv[4][i] = toupper(argv[4][i]);
if (strlen(argv[8]) > 8)
{
if (strlen(argv[8]) > 8) {
printf("MYCALL can not be nore than 8 characters, %s is invalid\n", argv[8]);
return 0;
}
@ -197,16 +179,14 @@ int main(int argc, char **argv)
argv[8][i] = toupper(argv[8][i]);
if (strlen(argv[9]) > 8)
{
if (strlen(argv[9]) > 8) {
printf("YRCALL can not be nore than 8 characters, %s is invalid\n", argv[9]);
return 0;
}
for (i = 0; i < 8; i++)
argv[9][i] = toupper(argv[9][i]);
if ((argv[5][0] != 'A') && (argv[5][0] != 'B') && (argv[5][0] != 'C'))
{
if ((argv[5][0] != 'A') && (argv[5][0] != 'B') && (argv[5][0] != 'C')) {
printf("module must be one of A B C\n");
return 0;
}
@ -226,8 +206,7 @@ int main(int argc, char **argv)
time(&tNow);
srand(tNow + getpid());
if (dst_open(argv[1], atoi(argv[2])))
{
if (dst_open(argv[1], atoi(argv[2]))) {
streamid_raw = (short)(::rand() & 0xFFFF);
memcpy(dstar_buf,"DSTR", 4);
dstar_buf[5] = (unsigned char)(G2_COUNTER & 0xff);
@ -242,11 +221,9 @@ int main(int argc, char **argv)
dstar_buf[12] = 0x01;
if (argv[5][0] == 'A')
dstar_buf[13] = 0x03;
else
if (argv[5][0] == 'B')
else if (argv[5][0] == 'B')
dstar_buf[13] = 0x01;
else
if (argv[5][0] == 'C')
else if (argv[5][0] == 'C')
dstar_buf[13] = 0x02;
else
dstar_buf[13] = 0x00;

@ -29,8 +29,7 @@ static FILE *fp = NULL;
static time_t tNow = 0;
static short streamid_raw = 0;
static unsigned short crc_tabccitt[256] =
{
static unsigned short crc_tabccitt[256] = {
0x0000,0x1189,0x2312,0x329b,0x4624,0x57ad,0x6536,0x74bf,
0x8c48,0x9dc1,0xaf5a,0xbed3,0xca6c,0xdbe5,0xe97e,0xf8f7,
0x1081,0x0108,0x3393,0x221a,0x56a5,0x472c,0x75b7,0x643e,
@ -73,8 +72,7 @@ static void calcPFCS(unsigned char rawbytes[58])
unsigned short tmp, short_c;
short int i;
for (i = 17; i < 56 ; i++)
{
for (i = 17; i < 56 ; i++) {
short_c = 0x00ff & (unsigned short)rawbytes[i];
tmp = (crc_dstar_ffff & 0x00ff) ^ short_c;
crc_dstar_ffff = (crc_dstar_ffff >> 8) ^ crc_tabccitt[tmp];
@ -93,14 +91,13 @@ static bool dst_open(char *ip, int port)
int reuse = 1;
sockDst = socket(PF_INET,SOCK_DGRAM,0);
if (sockDst == -1)
{
if (sockDst == -1) {
printf("Failed to create DSTAR socket\n");
return false;
}
if (setsockopt(sockDst,SOL_SOCKET,SO_REUSEADDR, (char *)&reuse, sizeof(reuse)) == -1)
{
close(sockDst); sockDst = -1;
if (setsockopt(sockDst,SOL_SOCKET,SO_REUSEADDR, (char *)&reuse, sizeof(reuse)) == -1) {
close(sockDst);
sockDst = -1;
printf("setsockopt DSTAR REUSE failed\n");
return false;
}
@ -115,8 +112,7 @@ static bool dst_open(char *ip, int port)
static void dst_close()
{
if (sockDst != -1)
{
if (sockDst != -1) {
close(sockDst);
sockDst = -1;
}
@ -135,8 +131,7 @@ int main(int argc, char **argv)
char RADIO_ID[21];
short int TEXT_idx = 0;
if (argc != 10)
{
if (argc != 10) {
printf("Usage: g2link_test_audio <IPaddress> <port> <dvtoolFile> <repeaterCallsign> <module> <delay_between> <delay_before> <MYCALL> <YRCALL>\n");
printf("Example: g2link_test_audio 127.0.0.1 19000 somefile.dvtool KJ4NHF B 19 2 KI4LKF CQCQCQ\n");
printf("Where...\n");
@ -152,30 +147,26 @@ int main(int argc, char **argv)
return 0;
}
if (strlen(argv[4]) > 6)
{
if (strlen(argv[4]) > 6) {
printf("repeaterCallsign can not be more than 6 characters, %s is invalid\n", argv[4]);
return 0;
}
for (i = 0; i < strlen(argv[4]); i++)
argv[4][i] = toupper(argv[4][i]);
if ((argv[5][0] != 'A') && (argv[5][0] != 'B') && (argv[5][0] != 'C'))
{
if ((argv[5][0] != 'A') && (argv[5][0] != 'B') && (argv[5][0] != 'C')) {
printf("module must be one of A B C\n");
return 0;
}
if (strlen(argv[8]) > 8)
{
if (strlen(argv[8]) > 8) {
printf("No more than 8 characters in MYCALL\n");
return 0;
}
for (i = 0; i < strlen(argv[8]); i++)
argv[8][i] = toupper(argv[8][i]);
if (strlen(argv[9]) > 8)
{
if (strlen(argv[9]) > 8) {
printf("No more than 8 characters in YRCALL\n");
return 0;
}
@ -184,22 +175,19 @@ int main(int argc, char **argv)
fp = fopen(argv[3], "rb");
if (!fp)
{
if (!fp) {
printf("Failed to open file %s for reading\n", argv[3]);
return 0;
}
/* stupid DVTOOL + 4 byte num_of_records */
nread = fread(dstar_buf, 10, 1, fp);
if (nread != 1)
{
if (nread != 1) {
printf("Cant read first 10 bytes\n");
fclose(fp);
return 0;
}
if (memcmp(dstar_buf, "DVTOOL", 6) != 0)
{
if (memcmp(dstar_buf, "DVTOOL", 6) != 0) {
printf("DVTOOL not found\n");
fclose(fp);
return 0;
@ -216,57 +204,46 @@ int main(int argc, char **argv)
time(&tNow);
srand(tNow + getpid());
if (dst_open(argv[1], atoi(argv[2])))
{
while (true)
{
if (dst_open(argv[1], atoi(argv[2]))) {
while (true) {
/* 2 byte length */
nread = fread(&rlen, 2, 1, fp);
if (nread != 1)
{
if (nread != 1) {
printf("End-Of-File\n");
break;
}
if (rlen == 56)
streamid_raw = (short)(::rand() & 0xFFFF);
else
if (rlen == 27)
else if (rlen == 27)
;
else
{
else {
printf("Not 56-byte and not 27-byte\n");
break;
}
/* read the packet */
nread = fread(dstar_buf, rlen, 1, fp);
if (nread == 1)
{
if (memcmp(dstar_buf, "DSVT", 4) != 0)
{
if (nread == 1) {
if (memcmp(dstar_buf, "DSVT", 4) != 0) {
printf("DVST not found\n");
break;
}
if (dstar_buf[8] != 0x20)
{
if (dstar_buf[8] != 0x20) {
printf("Not Voice type\n");
break;
}
if (dstar_buf[4] == 0x10)
;
else
if (dstar_buf[4] == 0x20)
else if (dstar_buf[4] == 0x20)
;
else
{
else {
printf("Not a valid record type\n");
break;
}
if (rlen == 56)
{
if (rlen == 56) {
memcpy(rptr_buf, "DSTR", 4);
rptr_buf[5] = (unsigned char)(G2_COUNTER & 0xff);
rptr_buf[4] = (unsigned char)((G2_COUNTER >> 8) & 0xff);
@ -305,74 +282,47 @@ int main(int argc, char **argv)
memcpy(rptr_buf + 52, "TEST", 4);
calcPFCS(rptr_buf);
}
else
{
} else {
rptr_buf[5] = (unsigned char)(G2_COUNTER & 0xff);
rptr_buf[4] = (unsigned char)((G2_COUNTER >> 8) & 0xff);
rptr_buf[9] = 0x13;
if ((dstar_buf[24] != 0x55) ||
(dstar_buf[25] != 0x2d) ||
(dstar_buf[26] != 0x16))
{
if (TEXT_idx == 0)
{
(dstar_buf[26] != 0x16)) {
if (TEXT_idx == 0) {
dstar_buf[24] = '@' ^ 0x70;
dstar_buf[25] = RADIO_ID[TEXT_idx++] ^ 0x4f;
dstar_buf[26] = RADIO_ID[TEXT_idx++] ^ 0x93;
}
else
if (TEXT_idx == 2)
{
} else if (TEXT_idx == 2) {
dstar_buf[24] = RADIO_ID[TEXT_idx++] ^ 0x70;
dstar_buf[25] = RADIO_ID[TEXT_idx++] ^ 0x4f;
dstar_buf[26] = RADIO_ID[TEXT_idx++] ^ 0x93;
}
else
if (TEXT_idx == 5)
{
} else if (TEXT_idx == 5) {
dstar_buf[24] = 'A' ^ 0x70;
dstar_buf[25] = RADIO_ID[TEXT_idx++] ^ 0x4f;
dstar_buf[26] = RADIO_ID[TEXT_idx++] ^ 0x93;
}
else
if (TEXT_idx == 7)
{
} else if (TEXT_idx == 7) {
dstar_buf[24] = RADIO_ID[TEXT_idx++] ^ 0x70;
dstar_buf[25] = RADIO_ID[TEXT_idx++] ^ 0x4f;
dstar_buf[26] = RADIO_ID[TEXT_idx++] ^ 0x93;
}
else
if (TEXT_idx == 10)
{
} else if (TEXT_idx == 10) {
dstar_buf[24] = 'B' ^ 0x70;
dstar_buf[25] = RADIO_ID[TEXT_idx++] ^ 0x4f;
dstar_buf[26] = RADIO_ID[TEXT_idx++] ^ 0x93;
}
else
if (TEXT_idx == 12)
{
} else if (TEXT_idx == 12) {
dstar_buf[24] = RADIO_ID[TEXT_idx++] ^ 0x70;
dstar_buf[25] = RADIO_ID[TEXT_idx++] ^ 0x4f;
dstar_buf[26] = RADIO_ID[TEXT_idx++] ^ 0x93;
}
else
if (TEXT_idx == 15)
{
} else if (TEXT_idx == 15) {
dstar_buf[24] = 'C' ^ 0x70;
dstar_buf[25] = RADIO_ID[TEXT_idx++] ^ 0x4f;
dstar_buf[26] = RADIO_ID[TEXT_idx++] ^ 0x93;
}
else
if (TEXT_idx == 17)
{
} else if (TEXT_idx == 17) {
dstar_buf[24] = RADIO_ID[TEXT_idx++] ^ 0x70;
dstar_buf[25] = RADIO_ID[TEXT_idx++] ^ 0x4f;
dstar_buf[26] = RADIO_ID[TEXT_idx++] ^ 0x93;
}
else
{
} else {
dstar_buf[24] = 0x70;
dstar_buf[25] = 0x4f;
dstar_buf[26] = 0x93;

@ -15,7 +15,9 @@ rm -f gwys.va2uv.txt
wget -nv -O gwys.va3uv.txt http://www.va3uv.com/gwys.txt
if [ -e gwys.va3uv.txt ]; then
awk '$1~/^REF|XRF/&&$2~/[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+/{print $1, $2, 20001}' gwys.va3uv.txt > gwys.txt
# Move DPlus and DExtra to port 20001
awk '$1~/^REF|XRF/{print $1, $2, 20001}' gwys.va3uv.txt > gwys.txt
# Get the DCS reflectors too
awk '$1~/^DCS/{print $1, $2, $3}' gwys.va3uv.txt >> gwys.txt
else
echo "Could not get gateways list from www.va3uv.com!"

@ -17,7 +17,6 @@ REF019 208.87.120.144 20001
REF020 50.199.88.20 20001
REF024 69.41.0.15 20001
REF025 173.10.178.226 20001
REF026 206.12.104.8 20001
REF027 194.116.29.72 20001
REF028 193.190.240.229 20001
REF029 129.123.7.138 20001
@ -31,7 +30,6 @@ REF037 208.111.3.181 20001
REF038 66.6.171.227 20001
REF039 208.93.191.20 20001
REF045 195.251.201.194 20001
REF046 208.111.3.182 20001
REF047 157.7.142.13 20001
REF048 208.88.66.244 20001
REF050 75.147.26.195 20001
@ -68,7 +66,7 @@ XRF021 74.204.50.67 20001
XRF023 141.75.245.225 20001
XRF025 63.133.189.2 20001
XRF026 139.13.100.34 20001
XRF027 194.116.29.66 20001
XRF027 194.116.29.78 20001
XRF028 193.190.240.228 20001
XRF031 83.241.141.245 20001
XRF033 46.226.178.81 20001
@ -87,11 +85,12 @@ XRF123 213.126.90.100 20001
XRF310 199.167.193.147 20001
XRF333 37.187.103.98 20001
XRF353 94.173.206.53 20001
XRF444 71.40.84.59 20001
XRF444 70.125.157.44 20001
XRF500 125.63.57.138 20001
XRF555 199.167.193.205 20001
XRF559 98.239.113.175 20001
XRF580 67.20.31.79 20001
XRF603 74.104.179.159 20001
XRF666 125.63.57.138 20001
XRF719 199.227.117.121 20001
XRF727 108.33.72.83 20001
XRF777 62.167.15.53 20001
@ -101,3 +100,28 @@ XRF858 198.57.255.30 20001
XRF901 199.167.196.109 20001
XRF905 199.212.121.20 20001
XRF978 74.104.179.159 20001
DCS001 dcs001.xreflector.net 30051
DCS002 dcs002.xreflector.net 30051
DCS003 dcs003.xreflector.net 30051
DCS004 dcs004.xreflector.net 30051
DCS005 dcs005.xreflector.net 30051
DCS006 dcs006.xreflector.net 30051
DCS007 dcs007.xreflector.net 30051
DCS008 dcs008.xreflector.net 30051
DCS009 dcs009.xreflector.net 30051
DCS010 dcs010.xreflector.net 30051
DCS011 dcs011.xreflector.net 30051
DCS012 dcs012.xreflector.net 30051
DCS013 dcs013.xreflector.net 30051
DCS014 dcs014.xreflector.net 30051
DCS015 dcs015.xreflector.net 30051
DCS016 dcs016.xreflector.net 30051
DCS017 dcs017.xreflector.net 30051
DCS018 dcs018.xreflector.net 30051
DCS019 dcs019.xreflector.net 30051
DCS020 dcs020.xreflector.net 30051
DCS021 dcs021.xreflector.net 30051
DCS022 dcs022.xreflector.net 30051
DCS023 dcs023.xreflector.net 30051
DCS024 dcs024.xreflector.net 30051
DCS025 dcs025.xreflector.net 30051

Loading…
Cancel
Save

Powered by TurnKey Linux.