Fix a number of problems

master
Timothy Pearson 13 years ago
parent e3bfbdc4e4
commit 8392c61105

@ -6,30 +6,34 @@
<Action name="connect_server"/> <Action name="connect_server"/>
<Action name="disconnect_server"/> <Action name="disconnect_server"/>
</Menu> </Menu>
<Menu name="fpgaMenu"> <Menu name="dutMenu">
<text>Instrumentation</text> <text>Device Under Test</text>
<Action name="fpga_viewer"/> <ActionList name="dutMenu_actionlist"/>
</Menu> </Menu>
<Menu name="instrumentMenu"> <Menu name="instrumentMenu">
<text>Instrumentation</text> <text>Instrumentation</text>
<Action name="oscilloscope"/> <ActionList name="instrumentMenu_actionlist"/>
<Action name="frequency_generator"/> </Menu>
<Action name="spectrum_analyzer"/> <Menu name="serviceMenu">
<text>Services</text>
<ActionList name="serviceMenu_actionlist"/>
</Menu> </Menu>
</MenuBar> </MenuBar>
<ToolBar name="connectionToolBar" fullWidth="true" noMerge="1"> <ToolBar name="connectionToolBar" fullWidth="true" noMerge="1">
<text>Instrumentation Toolbar</text> <text>Connection</text>
<Action name="connect_server"/> <Action name="connect_server"/>
<Action name="disconnect_server"/> <Action name="disconnect_server"/>
</ToolBar> </ToolBar>
<ToolBar name="fpgaToolBar" fullWidth="true" noMerge="1"> <ToolBar name="dutToolBar" fullWidth="true" noMerge="1">
<text>Instrumentation Toolbar</text> <text>Device Under Test</text>
<Action name="fpga_viewer"/> <ActionList name="dutToolBar_actionlist"/>
</ToolBar> </ToolBar>
<ToolBar name="instrumentToolBar" fullWidth="true" noMerge="1"> <ToolBar name="instrumentToolBar" fullWidth="true" noMerge="1">
<text>Instrumentation Toolbar</text> <text>Instrumentation</text>
<Action name="oscilloscope"/> <ActionList name="instrumentToolBar_actionlist"/>
<Action name="frequency_generator"/> </ToolBar>
<Action name="spectrum_analyzer"/> <ToolBar name="serviceToolBar" fullWidth="true" noMerge="1">
<text>Services</text>
<ActionList name="serviceToolBar_actionlist"/>
</ToolBar> </ToolBar>
</kpartgui> </kpartgui>

@ -45,8 +45,6 @@ RemoteMDI::RemoteMDI()
KStdAction::keyBindings(TQT_TQOBJECT(this), TQT_SLOT(configKeys()), ac); KStdAction::keyBindings(TQT_TQOBJECT(this), TQT_SLOT(configKeys()), ac);
connect_action = new KAction(i18n("Connect to Server"), "connect_creating", KShortcut(), TQT_TQOBJECT(this), TQT_SLOT(connectToServer()), ac, "connect_server"); connect_action = new KAction(i18n("Connect to Server"), "connect_creating", KShortcut(), TQT_TQOBJECT(this), TQT_SLOT(connectToServer()), ac, "connect_server");
disconnect_action = new KAction(i18n("Disconnect from Server"), "connect_no", KShortcut(), TQT_TQOBJECT(this), TQT_SLOT(disconnectFromServer()), ac, "disconnect_server"); disconnect_action = new KAction(i18n("Disconnect from Server"), "connect_no", KShortcut(), TQT_TQOBJECT(this), TQT_SLOT(disconnectFromServer()), ac, "disconnect_server");
inst_fpgaviewer_menu = new KAction(i18n("Launch Spectrum Analyzer"), "remote", KShortcut(), TQT_TQOBJECT(this), TQT_SLOT(startSpectrumAnalyzer()), ac, "spectrum_analyzer");
inst_sa_menu = new KAction(i18n("Launch FPGA Viewer"), "remote", KShortcut(), TQT_TQOBJECT(this), TQT_SLOT(startFPGAViewer()), ac, "fpga_viewer");
// Add Window menu // Add Window menu
if ( !isFakingSDIApplication() ) { if ( !isFakingSDIApplication() ) {
@ -65,6 +63,8 @@ RemoteMDI::RemoteMDI()
// Create the status bar // Create the status bar
statusBar()->message(i18n("No view!")); statusBar()->message(i18n("No view!"));
processActions();
processLockouts(); processLockouts();
} }
@ -82,6 +82,61 @@ RemoteMDI::~RemoteMDI()
} }
} }
void RemoteMDI::processActions() {
// Add dynamic actions
// RAJA FIXME
KActionCollection *const ac = actionCollection();
TQPtrList<KAction> dut_actions;
inst_fpgaviewer_menu = new KAction(i18n("Launch FPGA Viewer"), "remote", KShortcut(), TQT_TQOBJECT(this), TQT_SLOT(startModule()), ac, "libremotelab_fpgaviewer");
dut_actions.append(inst_fpgaviewer_menu);
unplugActionList("dutMenu_actionlist");
unplugActionList("dutToolBar_actionlist");
plugActionList("dutMenu_actionlist", dut_actions);
plugActionList("dutToolBar_actionlist", dut_actions);
TQPtrList<KAction> instrument_actions;
inst_sa_menu = new KAction(i18n("Launch Spectrum Analyzer"), "remote", KShortcut(), TQT_TQOBJECT(this), TQT_SLOT(startModule()), ac, "libremotelab_commanalyzer");
instrument_actions.append(inst_sa_menu);
unplugActionList("instrumentMenu_actionlist");
unplugActionList("instrumentToolBar_actionlist");
plugActionList("instrumentMenu_actionlist", instrument_actions);
plugActionList("instrumentToolBar_actionlist", instrument_actions);
TQPtrList<KAction> service_actions;
// Nothing here yet!
unplugActionList("serviceMenu_actionlist");
unplugActionList("serviceToolBar_actionlist");
plugActionList("serviceMenu_actionlist", service_actions);
plugActionList("serviceToolBar_actionlist", service_actions);
}
void RemoteMDI::startModule() {
const KAction* sendingAction = dynamic_cast<const KAction*>(sender());
if (sendingAction) {
// RAJA FIXME
bool serviceFound = false;
ServiceType st;
for (ServiceList::Iterator it(m_activeStation.services.begin()); it != m_activeStation.services.end(); ++it) {
st = *it;
if (st.clientLibrary == sendingAction->name()) {
serviceFound = true;
}
}
if (!serviceFound) {
KMessageBox::error(this, i18n("<qt>The active laboratory workspace does not support the requested service</qt>"), i18n("Service Unavailable"));
return;
}
RemoteLab::InstrumentView* view = new RemoteLab::InstrumentView(sendingAction->name(), st.name, (mdiMode() == KMdi::ToplevelMode) ? 0 : this);
openNewWindow(view);
if (m_serverHost != "") {
view->connectServer(m_serverHost);
}
}
}
void RemoteMDI::connectToServer() { void RemoteMDI::connectToServer() {
if (m_rsvSvrSocket) { if (m_rsvSvrSocket) {
if (m_rsvSvrSocket->state() != TQSocket::Idle) { if (m_rsvSvrSocket->state() != TQSocket::Idle) {
@ -102,9 +157,15 @@ void RemoteMDI::connectToServer() {
if (m_serverHost != "") { if (m_serverHost != "") {
m_rsvSvrSocket->setServerFQDN(m_serverHost); m_rsvSvrSocket->setServerFQDN(m_serverHost);
m_rsvSvrSocket->connectToHost(m_serverHost, 4004); m_rsvSvrSocket->connectToHost(m_serverHost, 4004);
TQTimer connectionTimeout;
connectionTimeout.start(5000, TRUE);
while ((m_rsvSvrSocket->state() == TQSocket::Connecting) || (m_rsvSvrSocket->state() == TQSocket::HostLookup)) { while ((m_rsvSvrSocket->state() == TQSocket::Connecting) || (m_rsvSvrSocket->state() == TQSocket::HostLookup)) {
tqApp->processEvents(); tqApp->processEvents();
if (!connectionTimeout.isActive()) {
break;
}
} }
connectionTimeout.stop();
if (m_rsvSvrSocket->state() == TQSocket::Connected) { if (m_rsvSvrSocket->state() == TQSocket::Connected) {
printf("[DEBUG] Initial connection established...\n\r"); fflush(stdout); printf("[DEBUG] Initial connection established...\n\r"); fflush(stdout);
if (m_rsvSvrSocket->setUsingKerberos(true) != 0) { if (m_rsvSvrSocket->setUsingKerberos(true) != 0) {
@ -170,12 +231,17 @@ void RemoteMDI::promptForStationType() {
ds >> result; ds >> result;
printf("[RAJA DEBUG 100.0] '%s'\n\r", result.ascii()); fflush(stdout); printf("[RAJA DEBUG 100.0] '%s'\n\r", result.ascii()); fflush(stdout);
if (result == "OK") { if (result == "OK") {
// Success, do nothing // Success!
m_activeStation = select.m_selectedStation;
} }
else if (result == "ERRUNAVAL") { else if (result == "ERRUNAVAL") {
KMessageBox::error(this, i18n("<qt>No stations of the specified type are currently available<p>Please try again later</qt>"), i18n("Insufficient Laboratory Resources")); KMessageBox::error(this, i18n("<qt>No stations of the specified type are currently available<p>Please try again later</qt>"), i18n("Insufficient Laboratory Resources"));
disconnectFromServer(); disconnectFromServer();
} }
else if (result == "ERRPREVCN") {
KMessageBox::error(this, i18n("<qt>You are already connected to a laboratory station<p>Please disconnect and try again</qt>"), i18n("Multiple Connections Detected"));
disconnectFromServer();
}
else { else {
KMessageBox::error(this, i18n("<qt>Unknown server error<p>Please reconnect and try again</qt>"), i18n("Internal Error")); KMessageBox::error(this, i18n("<qt>Unknown server error<p>Please reconnect and try again</qt>"), i18n("Internal Error"));
disconnectFromServer(); disconnectFromServer();
@ -204,9 +270,8 @@ void RemoteMDI::disconnectFromServer() {
if (m_rsvSvrSocket) { if (m_rsvSvrSocket) {
m_rsvSvrSocket->clearPendingData(); m_rsvSvrSocket->clearPendingData();
m_rsvSvrSocket->close(); m_rsvSvrSocket->close();
while (m_rsvSvrSocket->state() == TQSocket::Closing) { delete m_rsvSvrSocket;
tqApp->processEvents(); m_rsvSvrSocket = NULL;
}
} }
connect_action->setEnabled(true); connect_action->setEnabled(true);
@ -249,22 +314,6 @@ void RemoteMDI::setServerHost(TQString server) {
m_serverHost = server; m_serverHost = server;
} }
void RemoteMDI::startSpectrumAnalyzer() {
RemoteLab::InstrumentView* saview = new RemoteLab::InstrumentView("libremotelab_commanalyzer", i18n("Communications Analyzer"), (mdiMode() == KMdi::ToplevelMode) ? 0 : this);
openNewWindow(saview);
if (m_serverHost != "") {
saview->connectServer(m_serverHost);
}
}
void RemoteMDI::startFPGAViewer() {
RemoteLab::InstrumentView* fpgaview = new RemoteLab::InstrumentView("libremotelab_fpgaviewer", i18n("FPGA Viewer"), (mdiMode() == KMdi::ToplevelMode) ? 0 : this);
openNewWindow(fpgaview);
if (m_serverHost != "") {
fpgaview->connectServer(m_serverHost);
}
}
void RemoteMDI::openNewWindow(KMdiChildView *view) { void RemoteMDI::openNewWindow(KMdiChildView *view) {
// Add a child view // Add a child view
m_children++; m_children++;

@ -63,8 +63,8 @@ class RemoteMDI : public KMdiMainFrm
void promptForStationType(); void promptForStationType();
void connectionClosedHandler(); void connectionClosedHandler();
void processLockouts(); void processLockouts();
void startSpectrumAnalyzer(); void processActions();
void startFPGAViewer(); void startModule();
protected: protected:
virtual bool queryClose(); virtual bool queryClose();
@ -79,6 +79,7 @@ class RemoteMDI : public KMdiMainFrm
KAction *disconnect_action; KAction *disconnect_action;
KAction *inst_sa_menu; KAction *inst_sa_menu;
KAction *inst_fpgaviewer_menu; KAction *inst_fpgaviewer_menu;
StationType m_activeStation;
}; };
#endif // _REMOTEMDI_H_ #endif // _REMOTEMDI_H_

@ -35,7 +35,7 @@ void InstrumentView::init() {
KLibFactory *factory = KLibLoader::self()->factory(m_libraryName.ascii()); KLibFactory *factory = KLibLoader::self()->factory(m_libraryName.ascii());
if (!factory) { if (!factory) {
KMessageBox::error( this, i18n("TDE could not find the %1 part, or it could not be started. Did you 'make install'?").arg(m_libraryName) ); KMessageBox::error( this, i18n("TDE could not find the %1 Part, or the Remote Laboratory Communications Analyzer Part could not be started. Did you make install?").arg(m_libraryName) );
TQTimer::singleShot(0, this, SLOT(close())); TQTimer::singleShot(0, this, SLOT(close()));
} }
else { else {
@ -58,7 +58,9 @@ void InstrumentView::closeConnections() {
void InstrumentView::connectServer(TQString server) { void InstrumentView::connectServer(TQString server) {
if (m_instrumentPart) { if (m_instrumentPart) {
m_instrumentPart->openURL(KURL(server)); if (m_instrumentPart->openURL(KURL(server))) {
close();
}
} }
} }

@ -55,14 +55,15 @@ struct exit_exception {
namespace RemoteLab { namespace RemoteLab {
typedef KParts::GenericFactory<RemoteLab::FPGAViewPart> Factory; typedef KParts::GenericFactory<RemoteLab::FPGAViewPart> Factory;
K_EXPORT_COMPONENT_FACTORY( libremotelab_fpgaviewer, RemoteLab::Factory ) #define CLIENT_LIBRARY "libremotelab_fpgaviewer"
K_EXPORT_COMPONENT_FACTORY(libremotelab_fpgaviewer, RemoteLab::Factory)
FPGAViewPart::FPGAViewPart(TQWidget *parentWidget, const char *widgetName, TQObject *parent, const char *name, const TQStringList&) FPGAViewPart::FPGAViewPart(TQWidget *parentWidget, const char *widgetName, TQObject *parent, const char *name, const TQStringList&)
: ReadOnlyPart( parent, name ), m_socket(0), m_base(0) : ReadOnlyPart( parent, name ), m_socket(0), m_base(0)
{ {
// Initialize mutex // Initialize mutex
m_instrumentMutex = new TQMutex(false); m_connectionMutex = new TQMutex(false);
// Initialize kpart // Initialize kpart
setInstance(Factory::instance()); setInstance(Factory::instance());
@ -74,19 +75,36 @@ FPGAViewPart::FPGAViewPart(TQWidget *parentWidget, const char *widgetName, TQObj
// Create widgets // Create widgets
m_base = new FPGAViewBase(widget()); m_base = new FPGAViewBase(widget());
processLockouts();
TQTimer::singleShot(0, this, TQT_SLOT(postInit())); TQTimer::singleShot(0, this, TQT_SLOT(postInit()));
} }
FPGAViewPart::~FPGAViewPart() { FPGAViewPart::~FPGAViewPart() {
if (m_connectionMutex->locked()) {
throw exit_exception(-1);
}
if (m_socket) { if (m_socket) {
m_socket->clearPendingData();
m_socket->close(); m_socket->close();
while (m_socket->state() == TQSocket::Closing) {
tqApp->processEvents();
}
delete m_socket; delete m_socket;
m_socket = NULL;
} }
delete m_connectionMutex;
}
delete m_instrumentMutex; void FPGAViewPart::processLockouts() {
if ((m_socket) && (m_socket->state() == TQSocket::Connected)) {
widget()->setEnabled(true);
}
else {
widget()->setEnabled(false);
}
}
void FPGAViewPart::connectionClosed() {
closeURL();
} }
void FPGAViewPart::postInit() { void FPGAViewPart::postInit() {
@ -94,23 +112,27 @@ void FPGAViewPart::postInit() {
} }
bool FPGAViewPart::openURL(const KURL &url) { bool FPGAViewPart::openURL(const KURL &url) {
return connectToServer(url.url()); int ret;
ret = connectToServer(url.url());
processLockouts();
return (ret != 0);
} }
bool FPGAViewPart::closeURL() { bool FPGAViewPart::closeURL() {
if (m_connectionMutex->locked()) {
throw exit_exception(-1);
}
if (m_socket) { if (m_socket) {
m_socket->clearPendingData();
m_socket->close(); m_socket->close();
delete m_socket;
while (m_socket->state() != TQSocket::Idle) { m_socket = NULL;
tqApp->processEvents();
}
} }
m_url = KURL(); processLockouts();
if (m_instrumentMutex->locked()) { m_url = KURL();
throw exit_exception(-1);
}
return true; return true;
} }
@ -133,13 +155,54 @@ int FPGAViewPart::connectToServer(TQString server) {
KMessageBox::error(0, i18n("<qt>Unable to establish Kerberos protocol with remote server<p>Please verify that you currently hold a valid Kerberos ticket</qt>"), i18n("Connection Failed")); KMessageBox::error(0, i18n("<qt>Unable to establish Kerberos protocol with remote server<p>Please verify that you currently hold a valid Kerberos ticket</qt>"), i18n("Connection Failed"));
return -1; return -1;
} }
TQDataStream ds(m_socket); connect(m_socket, SIGNAL(connectionClosed()), this, SLOT(connectionClosed()));
// RAJA FIXME try {
// How do we know which service to request? m_connectionMutex->lock();
// ds << TQString("SERV"); TQString response;
// ds << TQDataStream ds(m_socket);
// Read magic number and proto version from server
TQ_UINT32 magicnum;
TQ_UINT32 protover;
ds >> magicnum;
ds >> protover;
printf("[DEBUG] Got magic number %d and protocol version %d\n\r", magicnum, protover); fflush(stdout);
// Request connection to backend server
ds << TQString("SERV");
ds << TQString(CLIENT_LIBRARY);
ds >> response;
printf("[RAJA DEBUG 400.0] Got '%s' from the server\n\r", response.ascii()); fflush(stdout);
if (response == "OK") {
m_connectionMutex->unlock();
return 0;
}
else if (response == "ERRNOCONN") {
KMessageBox::error(0, i18n("<qt>Unable to establish connection with backend server<p>Please verify that you are currently connected to a workspace</qt>"), i18n("Connection Failed"));
m_connectionMutex->unlock();
return -1;
}
else if (response == "ERRNOTAVL") {
KMessageBox::error(0, i18n("<qt>The backend server is not available at this time<p>Please try a different workspace, or try again later</qt>"), i18n("Connection Failed"));
m_connectionMutex->unlock();
return -1;
}
else if (response == "ERRNOSERV") {
KMessageBox::error(0, i18n("<qt>The active laboratory workspace does not support the requested service</qt>"), i18n("Service Unavailable"));
m_connectionMutex->unlock();
return -1;
}
else {
KMessageBox::error(0, i18n("<qt>Unable to establish connection with remote server</qt>"), i18n("Connection Failed"));
m_connectionMutex->unlock();
return -1;
}
return 0; m_connectionMutex->unlock();
return 0;
}
catch (exit_exception& e) {
m_connectionMutex->unlock();
return -1;
}
} }
void FPGAViewPart::updateDisplay() { void FPGAViewPart::updateDisplay() {

@ -59,11 +59,13 @@ namespace RemoteLab
private slots: private slots:
void postInit(); void postInit();
void updateDisplay(); void updateDisplay();
void processLockouts();
void connectionClosed();
private: private:
TDEKerberosClientSocket* m_socket; TDEKerberosClientSocket* m_socket;
FPGAViewBase* m_base; FPGAViewBase* m_base;
TQMutex* m_instrumentMutex; TQMutex* m_connectionMutex;
TQTimer* m_updateTimer; TQTimer* m_updateTimer;
}; };
} }

@ -44,6 +44,8 @@ TQDataStream &operator<<( TQDataStream &s, const ServiceType &st )
s << st.type; s << st.type;
s << st.name; s << st.name;
s << st.description; s << st.description;
s << st.clientLibrary;
s << st.version;
return s; return s;
} }
@ -60,6 +62,8 @@ TQDataStream &operator>>( TQDataStream &s, ServiceType &st )
s >> st.type; s >> st.type;
s >> st.name; s >> st.name;
s >> st.description; s >> st.description;
s >> st.clientLibrary;
s >> st.version;
return s; return s;
} }

@ -29,6 +29,8 @@ class ServiceType
TQ_UINT32 type; TQ_UINT32 type;
TQString name; TQString name;
TQString description; TQString description;
TQString clientLibrary;
int version;
}; };
#ifndef QT_NO_DATASTREAM #ifndef QT_NO_DATASTREAM

@ -28,7 +28,7 @@ The client may terminate the connection at any time, or provide invalid data to
After initial negotiation, the server must enter command mode. In this mode the server expects to receive a command string. The following commands are currently supported: After initial negotiation, the server must enter command mode. In this mode the server expects to receive a command string. The following commands are currently supported:
LIST LIST
BIND <StationType 'Type ID'> BIND <StationType 'Type ID'>
SERV <ServiceType 'Service ID'> SERV <TQString 'Client Library Name'>
QUIT QUIT
If an invalid command is specified, the server should respond with a string containing the case-sensitive text "ERRINVCMD". If an invalid command is specified, the server should respond with a string containing the case-sensitive text "ERRINVCMD".
@ -44,17 +44,17 @@ Descriptions should be constructed from station service type flags as known to t
BIND <StationType 'Type ID'>: BIND <StationType 'Type ID'>:
Connects to a specified laboratory station Connects to a specified laboratory station
If a station with the specified Service ID list is available, the server must mark that station as in use by the authenticated user, must return the case-sensitive text "OK", and should block all commands other than QUIT. If a station with the specified Service ID list is not available, the server must respond with a string containing the case-sensitive text "ERRUNAVAL" and must re-enter command mode. If a station with the specified Service ID list is available, the server must mark that station as in use by the authenticated user, must return the case-sensitive text "OK", and should block all commands other than QUIT. If a station with the specified Service ID list is not available, the server must respond with a string containing the case-sensitive text "ERRUNAVAL" and must re-enter command mode. If the specified user is already connected to a laboratory station, the server must return the case-sensitive text "ERRPREVCN", and should block all commands other than QUIT.
Example: BIND Example: BIND
StationType StationType
SERV <TQ_UINT32 'Service ID'> SERV <TQString 'Client Library Name'>
Requests a connection to the specified backend server on the laboratory station Requests a connection to the specified backend server on the laboratory station
If BIND was previously commanded on this connection, the server must respond with a string containing the case-sensitive text "ERRINVCMD". If no station has been reserved for this user via a call to BIND on an active connection, the server must respond with a string containing the case-sensitive text "ERRNOCONN". If the backend server is not available, i.e. a connection attempt or attempts have failed to establish a connection, the server should respond with the string "ERRNOTAVL" and must close the client connection. Otherwise, the server must return a string containing the case-sensitive text "OK" and then immediately enter binary pass-through mode between the backend server and the client. If BIND was previously commanded on this connection, the server must respond with a string containing the case-sensitive text "ERRINVCMD". If no station has been reserved for this user via a call to BIND on an active connection, the server must respond with a string containing the case-sensitive text "ERRNOCONN". If the backend server is not available, i.e. a connection attempt or attempts have failed to establish a connection, the server should respond with the string "ERRNOTAVL" and must close the client connection. If the backend service is not available in the active laboratory workspace, the server should respond with the string "ERRNOSERV" and must close the client connection. Otherwise, the server must return a string containing the case-sensitive text "OK" and then immediately enter binary pass-through mode between the backend server and the client.
Example: SERV Example: SERV
ServiceType libremotelab_fpgaviewer
QUIT: QUIT:
Gracefully terminates the connection. Gracefully terminates the connection.

@ -22,6 +22,8 @@
#include <stdlib.h> #include <stdlib.h>
#include <tqtimer.h>
#include <klocale.h> #include <klocale.h>
#include "auth_conn.h" #include "auth_conn.h"
@ -165,6 +167,8 @@ int AuthSocket::enterCommandLoop() {
if (m_databaseServiceTypesCursor->next()) { if (m_databaseServiceTypesCursor->next()) {
svt.name = m_databaseServiceTypesCursor->value("name").toString(); svt.name = m_databaseServiceTypesCursor->value("name").toString();
svt.description = m_databaseServiceTypesCursor->value("description").toString(); svt.description = m_databaseServiceTypesCursor->value("description").toString();
svt.clientLibrary = m_databaseServiceTypesCursor->value("client_library").toString();
svt.version = m_databaseServiceTypesCursor->value("version").toInt();
} }
if (svt.name == "") { if (svt.name == "") {
svt.name = i18n("<unknown>"); svt.name = i18n("<unknown>");
@ -189,34 +193,45 @@ int AuthSocket::enterCommandLoop() {
// Attempt to bind to station matching desired Service Type list... // Attempt to bind to station matching desired Service Type list...
m_stationID = -1; m_stationID = -1;
for (StationList::Iterator it(m_slist.begin()); it != m_slist.end(); ++it) { // Ensure that this user is not already connected
if ((*it).services == st.services) { int activeID = -1;
m_stationID = (*it).id; m_databaseActivityCursor->select(TQString("username='%1' AND realmname='%2'").arg(m_authenticatedUserName).arg(m_authenticatedRealmName));
break; if (m_databaseActivityCursor->next()) {
} activeID = m_databaseActivityCursor->value("station").toInt();
} }
if (activeID < 0) {
for (StationList::Iterator it(m_slist.begin()); it != m_slist.end(); ++it) {
if ((*it).services == st.services) {
m_stationID = (*it).id;
break;
}
}
if (m_stationID < 0) { if (m_stationID < 0) {
ds << TQString("ERRUNAVAL"); ds << TQString("ERRUNAVAL");
} }
else { else {
m_bound = true; m_bound = true;
// Update database // Update database
TQSqlRecord *buffer = m_databaseActivityCursor->primeInsert(); TQSqlRecord *buffer = m_databaseActivityCursor->primeInsert();
buffer->setValue("station", m_stationID); buffer->setValue("station", m_stationID);
buffer->setValue("username", m_authenticatedUserName); buffer->setValue("username", m_authenticatedUserName);
buffer->setValue("realmname", m_authenticatedRealmName); buffer->setValue("realmname", m_authenticatedRealmName);
buffer->setValue("logontime", TQDateTime::currentDateTime().toTime_t()); buffer->setValue("logontime", TQDateTime::currentDateTime().toTime_t());
m_databaseActivityCursor->insert(); m_databaseActivityCursor->insert();
ds << TQString("OK"); ds << TQString("OK");
}
}
else {
ds << TQString("ERRPREVCN");
} }
} }
else if (command == "SERV") { else if (command == "SERV") {
// Get desired Service ID from client // Get client library name from the client
TQ_UINT32 sid; TQString libname;
ds >> sid; ds >> libname;
m_databaseActivityCursor->select(TQString("username='%1' AND realmname='%2'").arg(m_authenticatedUserName).arg(m_authenticatedRealmName)); m_databaseActivityCursor->select(TQString("username='%1' AND realmname='%2'").arg(m_authenticatedUserName).arg(m_authenticatedRealmName));
if (m_databaseActivityCursor->next()) { if (m_databaseActivityCursor->next()) {
@ -226,45 +241,98 @@ int AuthSocket::enterCommandLoop() {
if (m_bound == true) { if (m_bound == true) {
ds << TQString("ERRINVCMD"); ds << TQString("ERRINVCMD");
} }
else {
if (m_stationID < 0) { if (m_stationID < 0) {
ds << TQString("ERRNOCONN"); ds << TQString("ERRNOCONN");
}
// Attempt to connect to the backend server
m_databaseServicesCursor->select(TQString("pk=%1 AND station=%2").arg(sid).arg(m_stationID));
if (m_databaseServicesCursor->next()) {
TQString serviceHostName = m_databaseServicesCursor->value("hostname").toString();
int servicePort = m_databaseServicesCursor->value("port").toInt();
TDEKerberosClientSocket clientSocket;
clientSocket.setServiceName("remotefpga");
clientSocket.setServerFQDN(serviceHostName);
clientSocket.connectToHost(serviceHostName, servicePort);
while ((clientSocket.state() == TQSocket::Connecting) || (clientSocket.state() == TQSocket::HostLookup)) {
tqApp->processEvents();
} }
if (clientSocket.state() == TQSocket::Connected) { else {
if (clientSocket.setUsingKerberos(true) != 0) { // Find the service ID for the specified client library name
clientSocket.close(); TQ_INT32 sid = -1;
ds << TQString("ERRNOTAVL"); m_databaseServiceTypesCursor->select(TQString("client_library='%1'").arg(libname));
printf("[DEBUG] Connection failed to %s:%d for user %s@%s due to Kerberos failure\n\r", serviceHostName.ascii(), servicePort, m_authenticatedUserName.ascii(), m_authenticatedRealmName.ascii()); fflush(stdout); if (m_databaseServiceTypesCursor->next()) {
sid = m_databaseServiceTypesCursor->value("serviceid").toInt();
}
if (sid < 0) {
ds << TQString("ERRNOSERV");
} }
else { else {
printf("[RAJA DEBUG 600.0] Connect OK!\n\r"); fflush(stdout); // Attempt to connect to the backend server
// RAJA FIXME m_databaseServicesCursor->select(TQString("pk=%1 AND station=%2").arg(sid).arg(m_stationID));
if (m_databaseServicesCursor->next()) {
TQString serviceHostName = m_databaseServicesCursor->value("hostname").toString();
int servicePort = m_databaseServicesCursor->value("port").toInt();
TDEKerberosClientSocket clientSocket;
clientSocket.setServiceName("remotefpga");
clientSocket.setServerFQDN(serviceHostName);
clientSocket.connectToHost(serviceHostName, servicePort);
TQTimer connectionTimeout;
connectionTimeout.start(5000, TRUE);
while ((clientSocket.state() == TQSocket::Connecting) || (clientSocket.state() == TQSocket::HostLookup)) {
tqApp->processEvents();
if (!connectionTimeout.isActive()) {
break;
}
}
connectionTimeout.stop();
if (clientSocket.state() == TQSocket::Connected) {
if (clientSocket.setUsingKerberos(true) != 0) {
clientSocket.close();
ds << TQString("ERRNOTAVL");
printf("[DEBUG] Connection failed to %s:%d for user %s@%s due to Kerberos failure\n\r", serviceHostName.ascii(), servicePort, m_authenticatedUserName.ascii(), m_authenticatedRealmName.ascii()); fflush(stdout);
}
else {
TQDataStream clientDS(&clientSocket);
TQString server_reply;
connectionTimeout.start(5000, TRUE);
while ((!clientSocket.canReadLine()) && (clientSocket.state() == TQSocket::Connected)) {
tqApp->processEvents();
if (!connectionTimeout.isActive()) {
break;
}
}
connectionTimeout.stop();
if ((clientSocket.canReadLine()) && (clientSocket.state() == TQSocket::Connected)) {
clientDS >> server_reply;
}
if (server_reply == "OK") {
ds << TQString("OK");
TQByteArray ba(8192);
TQ_ULONG reclen;
while ((state() == TQSocket::Connected) && (clientSocket.state() == TQSocket::Connected)) {
// RAJA FIXME
if (canReadLine()) {
reclen = readBlock(ba.data(), 8192);
clientSocket.writeBlock(ba.data(), reclen);
}
if (clientSocket.canReadLine()) {
reclen = clientSocket.readBlock(ba.data(), 8192);
writeBlock(ba.data(), reclen);
}
tqApp->processEvents();
}
clientSocket.close();
}
else {
clientSocket.close();
ds << TQString("ERRNOTAVL");
printf("[DEBUG] Connection failed to %s:%d for user %s@%s due to remote server returning %s\n\r", serviceHostName.ascii(), servicePort, m_authenticatedUserName.ascii(), m_authenticatedRealmName.ascii(), server_reply.ascii()); fflush(stdout);
}
}
}
else {
clientSocket.close();
ds << TQString("ERRNOTAVL");
printf("[DEBUG] Connection failed to %s:%d for user %s@%s\n\r", serviceHostName.ascii(), servicePort, m_authenticatedUserName.ascii(), m_authenticatedRealmName.ascii()); fflush(stdout);
}
}
else {
ds << TQString("ERRNOSERV");
}
} }
} }
else {
clientSocket.close();
ds << TQString("ERRNOTAVL");
printf("[DEBUG] Connection failed to %s:%d for user %s@%s\n\r", serviceHostName.ascii(), servicePort, m_authenticatedUserName.ascii(), m_authenticatedRealmName.ascii()); fflush(stdout);
}
}
else {
ds << TQString("ERRNOTAVL");
} }
} }
else { else {

Loading…
Cancel
Save