Basic parsing of failed login

This commit is contained in:
phl0 2018-10-22 23:05:46 +02:00
parent 784e8ce88e
commit 1746ec7998
No known key found for this signature in database
GPG key ID: 48EA1E640798CA9A
3 changed files with 28 additions and 7 deletions

View file

@ -234,7 +234,7 @@ int CDAPNETGateway::run()
return 1;
}
m_dapnetNetwork = new CDAPNETNetwork(dapnetAddress, dapnetPort, callsign, dapnetAuthKey, VERSION, debug);
m_dapnetNetwork = new CDAPNETNetwork(dapnetAddress, dapnetPort, callsign, dapnetAuthKey, VERSION, false, debug);
ret = m_dapnetNetwork->open();
if (!ret) {
m_pocsagNetwork->close();
@ -247,6 +247,8 @@ int CDAPNETGateway::run()
return 1;
}
LogMessage("Starting DAPNETGateway-%s", VERSION);
ret = m_dapnetNetwork->login();
if (!ret) {
m_pocsagNetwork->close();
@ -260,12 +262,8 @@ int CDAPNETGateway::run()
return 1;
}
::LogMessage("Logged into the DAPNET network");
std::vector<unsigned int> whiteList = m_conf.getWhiteList();
LogMessage("Starting DAPNETGateway-%s", VERSION);
for (;;) {
unsigned char buffer[200U];

View file

@ -29,11 +29,12 @@
const unsigned int BUFFER_LENGTH = 200U;
CDAPNETNetwork::CDAPNETNetwork(const std::string& address, unsigned int port, const std::string& callsign, const std::string& authKey, const char* version, bool debug) :
CDAPNETNetwork::CDAPNETNetwork(const std::string& address, unsigned int port, const std::string& callsign, const std::string& authKey, const char* version, bool loggedin, bool debug) :
m_socket(address, port),
m_callsign(callsign),
m_authKey(authKey),
m_version(version),
m_loggedin(false),
m_debug(debug),
m_message(NULL),
m_schedule(NULL)
@ -92,6 +93,11 @@ bool CDAPNETNetwork::read()
// Error
LogWarning("An error has been reported by DAPNET");
} else if (buffer[0U] == '2') {
// First time sync paket indicated successful login
if (!m_loggedin) {
m_loggedin = true;
LogMessage("Logged into the DAPNET network");
}
// Time synchronisation
char* p = ::strchr((char*)buffer, '\n');
if (p != NULL)
@ -110,6 +116,9 @@ bool CDAPNETNetwork::read()
} else if (buffer[0U] == '4') {
// Timeslot information
return parseSchedule(buffer);
} else if (buffer[0U] == '7') {
// Login failed
return parseFailedLogin(buffer);
} else if (buffer[0U] == '#') {
// A message
return parseMessage(buffer, length);
@ -250,3 +259,15 @@ bool CDAPNETNetwork::parseSchedule(unsigned char* data)
return write((unsigned char*)"+\r\n");
}
bool CDAPNETNetwork::parseFailedLogin(unsigned char* data)
{
assert(data != NULL);
char* p = ::strtok((char*)data + 2U, "\r\n");
assert(p != NULL);
LogMessage("Login failed: %s", p);
return write((unsigned char*)"+\r\n");
}

View file

@ -28,7 +28,7 @@
class CDAPNETNetwork {
public:
CDAPNETNetwork(const std::string& address, unsigned int port, const std::string& callsign, const std::string& authKey, const char* version, bool debug);
CDAPNETNetwork(const std::string& address, unsigned int port, const std::string& callsign, const std::string& authKey, const char* version, bool loggedin, bool debug);
~CDAPNETNetwork();
bool open();
@ -48,12 +48,14 @@ private:
std::string m_callsign;
std::string m_authKey;
const char* m_version;
bool m_loggedin;
bool m_debug;
CPOCSAGMessage* m_message;
bool* m_schedule;
bool parseMessage(unsigned char* data, unsigned int length);
bool parseSchedule(unsigned char* data);
bool parseFailedLogin(unsigned char* data);
bool write(unsigned char* data);
};