diff options
author | Timothy Pearson <kb9vqf@pearsoncomputing.net> | 2012-07-07 16:23:30 -0500 |
---|---|---|
committer | Timothy Pearson <kb9vqf@pearsoncomputing.net> | 2012-07-07 16:23:30 -0500 |
commit | fc455268a511d91113f59c04b50fa08b7c37b554 (patch) | |
tree | d61462c8a4496fa788875918dc4113162382962b /servers/auth_server_lin | |
parent | 1b8ef84fb9f47b82d0da6fa6e1b9fe439bc6b05c (diff) | |
download | ulab-fc455268a511d91113f59c04b50fa08b7c37b554.tar.gz ulab-fc455268a511d91113f59c04b50fa08b7c37b554.zip |
Convert to frame based protocol
Finish FPGA programming server/client
Diffstat (limited to 'servers/auth_server_lin')
-rw-r--r-- | servers/auth_server_lin/src/auth_conn.cpp | 32 |
1 files changed, 29 insertions, 3 deletions
diff --git a/servers/auth_server_lin/src/auth_conn.cpp b/servers/auth_server_lin/src/auth_conn.cpp index 1356df4..cac5ba9 100644 --- a/servers/auth_server_lin/src/auth_conn.cpp +++ b/servers/auth_server_lin/src/auth_conn.cpp @@ -130,8 +130,10 @@ void AuthSocket::finishKerberosHandshake() { TQ_UINT32 protover = PROTOCOL_VERSION; TQDataStream ds(this); + ds.setPrintableData(true); ds << magicnum; ds << protover; + writeEndOfFrame(); enterCommandLoop(); return; @@ -150,6 +152,7 @@ int AuthSocket::servLoop() { if (m_servActive) { TQString command; TQDataStream ds(this); + ds.setPrintableData(true); TDEKerberosClientSocket::KerberosStatus krbstat; switch (m_servState) { @@ -162,6 +165,7 @@ int AuthSocket::servLoop() { if (!m_servClientTimeout->isActive()) { m_servClientSocket->close(); ds << TQString("ERRNOTAVL"); + writeEndOfFrame(); printf("[DEBUG] Connection failed to %s:%d for user %s@%s\n\r", m_srvServiceHostName.ascii(), m_srvServicePort, m_authenticatedUserName.ascii(), m_authenticatedRealmName.ascii()); fflush(stdout); m_servActive = false; delete m_servClientTimeout; @@ -187,6 +191,7 @@ int AuthSocket::servLoop() { else { m_servClientSocket->close(); ds << TQString("ERRNOTAVL"); + writeEndOfFrame(); printf("[DEBUG] Connection failed to %s:%d for user %s@%s\n\r", m_srvServiceHostName.ascii(), m_srvServicePort, m_authenticatedUserName.ascii(), m_authenticatedRealmName.ascii()); fflush(stdout); m_servActive = false; delete m_servClientTimeout; @@ -205,6 +210,7 @@ int AuthSocket::servLoop() { else { m_servClientSocket->close(); ds << TQString("ERRNOTAVL"); + writeEndOfFrame(); printf("[DEBUG] Connection failed to %s:%d for user %s@%s due to Kerberos failure\n\r", m_srvServiceHostName.ascii(), m_srvServicePort, m_authenticatedUserName.ascii(), m_authenticatedRealmName.ascii()); fflush(stdout); m_servActive = false; delete m_servClientTimeout; @@ -218,19 +224,23 @@ int AuthSocket::servLoop() { m_servClientTimeout->start(5000, TRUE); } if (m_servClientSocket->state() == TQSocket::Connected) { - if (m_servClientSocket->canReadData()) { + if (m_servClientSocket->canReadFrame()) { TQDataStream clientDS(m_servClientSocket); + clientDS.setPrintableData(true); TQString server_reply; clientDS >> server_reply; + m_servClientSocket->clearFrameTail(); if (server_reply == "OK") { ds << TQString("OK"); + writeEndOfFrame(); transferred_data = true; m_servState = 4; } else { m_servClientSocket->close(); ds << TQString("ERRNOTAVL"); + writeEndOfFrame(); printf("[DEBUG] Connection failed to %s:%d for user %s@%s due to remote server returning %s\n\r", m_srvServiceHostName.ascii(), m_srvServicePort, m_authenticatedUserName.ascii(), m_authenticatedRealmName.ascii(), server_reply.ascii()); fflush(stdout); m_servActive = false; delete m_servClientTimeout; @@ -243,6 +253,7 @@ int AuthSocket::servLoop() { // Timeout! m_servClientSocket->close(); ds << TQString("ERRNOTAVL"); + writeEndOfFrame(); printf("[DEBUG] Connection failed to %s:%d for user %s@%s\n\r", m_srvServiceHostName.ascii(), m_srvServicePort, m_authenticatedUserName.ascii(), m_authenticatedRealmName.ascii()); fflush(stdout); m_servActive = false; delete m_servClientTimeout; @@ -254,6 +265,7 @@ int AuthSocket::servLoop() { else { m_servClientSocket->close(); ds << TQString("ERRNOTAVL"); + writeEndOfFrame(); printf("[DEBUG] Connection failed to %s:%d for user %s@%s\n\r", m_srvServiceHostName.ascii(), m_srvServicePort, m_authenticatedUserName.ascii(), m_authenticatedRealmName.ascii()); fflush(stdout); m_servActive = false; delete m_servClientTimeout; @@ -279,6 +291,7 @@ int AuthSocket::servLoop() { else { m_servClientSocket->close(); ds << TQString("ERRNOTAVL"); + writeEndOfFrame(); printf("[DEBUG] Connection terminated by remote host %s:%d for user %s@%s\n\r", m_srvServiceHostName.ascii(), m_srvServicePort, m_authenticatedUserName.ascii(), m_authenticatedRealmName.ascii()); fflush(stdout); m_servActive = false; close(); @@ -316,12 +329,14 @@ void AuthSocket::commandLoop() { try { transferred_data = false; if (state() == TQSocket::Connected) { - if (canReadData()) { + if (canReadFrame()) { TQString command; TQDataStream ds(this); + ds.setPrintableData(true); transferred_data = true; ds >> command; + clearFrameTail(); if (command != "") { printf("[DEBUG] Got command %s from user %s@%s\n\r", command.ascii(), m_authenticatedUserName.ascii(), m_authenticatedRealmName.ascii()); fflush(stdout); if (command == "LIST") { @@ -378,13 +393,15 @@ void AuthSocket::commandLoop() { m_slist.append(st); } } - + ds << m_slist; + writeEndOfFrame(); } else if (command == "BIND") { // Get desired Station Type from client StationType st; ds >> st; + clearFrameTail(); // Attempt to bind to station matching desired Service Type list... m_stationID = -1; @@ -405,6 +422,7 @@ void AuthSocket::commandLoop() { if (m_stationID < 0) { ds << TQString("ERRUNAVAL"); + writeEndOfFrame(); } else { m_bound = true; @@ -418,16 +436,19 @@ void AuthSocket::commandLoop() { m_databaseActivityCursor->insert(); ds << TQString("OK"); + writeEndOfFrame(); } } else { ds << TQString("ERRPREVCN"); + writeEndOfFrame(); } } else if (command == "SERV") { // Get client library name from the client TQString libname; ds >> libname; + clearFrameTail(); printf("[DEBUG] SERV command parameter was %s from user %s@%s\n\r", libname.ascii(), m_authenticatedUserName.ascii(), m_authenticatedRealmName.ascii()); fflush(stdout); m_databaseActivityCursor->select(TQString("username='%1' AND realmname='%2'").arg(m_authenticatedUserName).arg(m_authenticatedRealmName)); @@ -437,10 +458,12 @@ void AuthSocket::commandLoop() { if (m_bound == true) { ds << TQString("ERRINVCMD"); + writeEndOfFrame(); } else { if (m_stationID < 0) { ds << TQString("ERRNOCONN"); + writeEndOfFrame(); } else { // Find the service ID for the specified client library name @@ -451,6 +474,7 @@ void AuthSocket::commandLoop() { } if (sid < 0) { ds << TQString("ERRNOSERV"); + writeEndOfFrame(); } else { // Attempt to connect to the backend server @@ -470,6 +494,7 @@ void AuthSocket::commandLoop() { } else { ds << TQString("ERRNOSERV"); + writeEndOfFrame(); } } } @@ -477,6 +502,7 @@ void AuthSocket::commandLoop() { } else { ds << TQString("ERRINVCMD"); + writeEndOfFrame(); } } } |