diff options
author | Timothy Pearson <kb9vqf@pearsoncomputing.net> | 2012-06-23 17:23:49 -0500 |
---|---|---|
committer | Timothy Pearson <kb9vqf@pearsoncomputing.net> | 2012-06-23 17:23:49 -0500 |
commit | 8dcfe72c396a6f0c4bafd2ed23ba52a475154ef2 (patch) | |
tree | a0a77ec1d7d7cd826e1f2ba92ea4f96351bae5e3 /servers/auth_server_lin/src/auth_conn.cpp | |
parent | b48b26b86975d2166a4da7fc41086facefb3c4f2 (diff) | |
download | ulab-8dcfe72c396a6f0c4bafd2ed23ba52a475154ef2.tar.gz ulab-8dcfe72c396a6f0c4bafd2ed23ba52a475154ef2.zip |
Fix a number of crashes and generally clean up the code
Diffstat (limited to 'servers/auth_server_lin/src/auth_conn.cpp')
-rw-r--r-- | servers/auth_server_lin/src/auth_conn.cpp | 59 |
1 files changed, 46 insertions, 13 deletions
diff --git a/servers/auth_server_lin/src/auth_conn.cpp b/servers/auth_server_lin/src/auth_conn.cpp index 013b9bd..396218a 100644 --- a/servers/auth_server_lin/src/auth_conn.cpp +++ b/servers/auth_server_lin/src/auth_conn.cpp @@ -24,18 +24,23 @@ #include "auth_conn.h" +/* exception handling */ +struct exit_exception { + int c; + exit_exception(int c):c(c) { } +}; + /* The AuthSocket class provides a socket that is connected with a client. For every client that connects to the server, the server creates a new instance of this class. */ AuthSocket::AuthSocket(int sock, TQObject *parent, const char *name) : - TDEKerberosServerSocket( parent, name ) { + TDEKerberosServerSocket( parent, name ), m_criticalSection(0) { setServiceName("remotefpga"); line = 0; - connect(this, SIGNAL(connectionClosed()), SLOT(deleteLater())); connect(this, SIGNAL(connectionClosed()), SLOT(connectionClosedHandler())); setSocket( sock ); } @@ -45,17 +50,18 @@ AuthSocket::~AuthSocket() { } void AuthSocket::close() { - TQSocket::close(); + TDEKerberosServerSocket::close(); connectionClosedHandler(); } void AuthSocket::connectionClosedHandler() { printf("[DEBUG] Connection from %s closed\n\r", m_remoteHost.ascii()); + if (m_criticalSection > 0) { + throw exit_exception(-1); + } } int AuthSocket::initiateKerberosHandshake() { - bool user_authorized = false; - if (setUsingKerberos(true) == 0) { TQ_UINT32 magicnum = MAGIC_NUMBER; TQ_UINT32 protover = PROTOCOL_VERSION; @@ -64,14 +70,6 @@ int AuthSocket::initiateKerberosHandshake() { ds << magicnum; ds << protover; - // RAJA FIXME - if (user_authorized == 1) { - // Send list of available servers... - writeBlock("OK�", strlen("OK�")); - } - - writeBlock("TESTING", strlen("TESTING")); - return 0; } else { @@ -79,6 +77,37 @@ int AuthSocket::initiateKerberosHandshake() { } } +int AuthSocket::enterCommandLoop() { + m_criticalSection++; + try { + TQString command; + TQDataStream ds(this); + + while (state() == TQSocket::Connected) { + ds >> command; +printf("[RAJA DEBUG 500.0] Got command %s\n\r", command.ascii()); fflush(stdout); + if (command == "LIST") { + // Send list of available servers... + // RAJA FIXME + StationList slist; + ds << slist; + } + else { + ds << "ERRINVCMD"; + } + tqApp->processEvents(); + } + + m_criticalSection--; + return 0; + } + catch (...) { + m_criticalSection--; + return -1; + } + +} + /* The AuthServer class handles new connections to the server. For every client that connects, it creates a new AuthSocket -- that instance is now @@ -103,8 +132,12 @@ void AuthServer::newConnection(int socket) { printf("[DEBUG] New connection from %s\n\r", s->m_remoteHost.ascii()); if (s->initiateKerberosHandshake() != 0) { s->close(); + delete s; + s = NULL; } else { + connect(s, SIGNAL(connectionClosed()), s, SLOT(deleteLater())); emit newConnect(s); + s->enterCommandLoop(); } } |