From 8dcfe72c396a6f0c4bafd2ed23ba52a475154ef2 Mon Sep 17 00:00:00 2001 From: Timothy Pearson Date: Sat, 23 Jun 2012 17:23:49 -0500 Subject: Fix a number of crashes and generally clean up the code --- servers/auth_server_lin/src/auth_conn.cpp | 59 ++++++++++++++++++++++++------- 1 file changed, 46 insertions(+), 13 deletions(-) (limited to 'servers/auth_server_lin/src/auth_conn.cpp') 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(); } } -- cgit v1.2.1