diff options
author | Timothy Pearson <kb9vqf@pearsoncomputing.net> | 2012-06-25 22:55:11 -0500 |
---|---|---|
committer | Timothy Pearson <kb9vqf@pearsoncomputing.net> | 2012-06-25 22:55:11 -0500 |
commit | fbfb9b1a49003013f646f81b344d5d3a44255c44 (patch) | |
tree | 489ff7bceb3f5d0f2001610f74bbfdf09e29d881 /servers/fpga_server_lin/src | |
parent | 256a66b6b05eecf7e7cf0b842f4809fb49d190a0 (diff) | |
download | ulab-fbfb9b1a49003013f646f81b344d5d3a44255c44.tar.gz ulab-fbfb9b1a49003013f646f81b344d5d3a44255c44.zip |
Add fpga server skeleton for future development
Diffstat (limited to 'servers/fpga_server_lin/src')
-rw-r--r-- | servers/fpga_server_lin/src/Makefile.am | 11 | ||||
-rw-r--r-- | servers/fpga_server_lin/src/fpga_conn.cpp | 132 | ||||
-rw-r--r-- | servers/fpga_server_lin/src/fpga_conn.h | 89 | ||||
-rw-r--r-- | servers/fpga_server_lin/src/main.cpp | 63 |
4 files changed, 295 insertions, 0 deletions
diff --git a/servers/fpga_server_lin/src/Makefile.am b/servers/fpga_server_lin/src/Makefile.am new file mode 100644 index 0000000..6224e0c --- /dev/null +++ b/servers/fpga_server_lin/src/Makefile.am @@ -0,0 +1,11 @@ +INCLUDES= $(all_includes) $(KDE_INCLUDES)/tde -I/usr/include/sasl +KDE_CXXFLAGS = $(USE_EXCEPTIONS) + +bin_PROGRAMS = remotefpga_fpgaserver + +remotefpga_fpgaserver_SOURCES = main.cpp fpga_conn.cpp + +remotefpga_fpgaserver_METASOURCES = AUTO +remotefpga_fpgaserver_LDFLAGS = $(all_libraries) $(KDE_RPATH) $(LIB_QT) -lDCOP $(LIB_TDECORE) $(LIB_TDEUI) -ltdefx $(LIB_KIO) -lktexteditor -ltdekrbsocket -ltqtrla + +KDE_OPTIONS = nofinal diff --git a/servers/fpga_server_lin/src/fpga_conn.cpp b/servers/fpga_server_lin/src/fpga_conn.cpp new file mode 100644 index 0000000..499d067 --- /dev/null +++ b/servers/fpga_server_lin/src/fpga_conn.cpp @@ -0,0 +1,132 @@ +/* + * Remote Laboratory FPGA Server + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + * (c) 2012 Timothy Pearson + * Raptor Engineering + * http://www.raptorengineeringinc.com + */ + +#include <stdlib.h> + +#include <klocale.h> + +#include "fpga_conn.h" + +/* exception handling */ +struct exit_exception { + int c; + exit_exception(int c):c(c) { } +}; + +/* + The FPGASocket 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. +*/ +FPGASocket::FPGASocket(int sock, TQObject *parent, const char *name) : + TDEKerberosServerSocket(parent, name), m_criticalSection(0), m_stationID(-1), m_config(static_cast<FPGAServer*>(parent)->m_config), m_database(NULL), m_databaseStationsCursor(NULL) { + + setServiceName("remotefpga"); + + line = 0; + connect(this, SIGNAL(connectionClosed()), SLOT(connectionClosedHandler())); + setSocket(sock); +} + +FPGASocket::~FPGASocket() { + // +} + +void FPGASocket::close() { + TDEKerberosServerSocket::close(); + connectionClosedHandler(); +} + +void FPGASocket::connectionClosedHandler() { + printf("[DEBUG] Connection from %s closed\n\r", m_remoteHost.ascii()); + + if (m_criticalSection > 0) { + throw exit_exception(-1); + } +} + +int FPGASocket::initiateKerberosHandshake() { + if (setUsingKerberos(true) == 0) { + TQDataStream ds(this); + ds << TQString("OK"); + + return 0; + } + else { + return -1; + } +} + +void FPGASocket::enterCommandLoop() { + // RAJA FIXME +} + +/* + The FPGAServer class handles new connections to the server. For every + client that connects, it creates a new FPGASocket -- that instance is now + responsible for the communication with that client. +*/ +FPGAServer::FPGAServer(TQObject* parent, int port, KSimpleConfig* config) : + TQServerSocket( port, 1, parent ), m_config(config), m_numberOfConnections(0) { + + if ( !ok() ) { + printf("[ERROR] Failed to bind to port %d\n\r", port); + exit(1); + } + + socketDevice()->setAddressReusable(false); + + printf("[INFO] Server started on port %d\n\r", port); fflush(stdout); +} + +FPGAServer::~FPGAServer() { + // +} + +void FPGAServer::newConnection(int socket) { + FPGASocket *s = new FPGASocket(socket, this); + s->m_remoteHost = s->peerAddress().toString(); + printf("[DEBUG] New connection from %s\n\r", s->m_remoteHost.ascii()); + if (m_numberOfConnections > 0) { + printf("[DEBUG] Connection from %s closed due to multiple access attempt\n\r", m_remoteHost.ascii()); + s->close(); + delete s; + s = NULL; + } + if (s->initiateKerberosHandshake() != 0) { + printf("[DEBUG] Connection from %s closed due to Kerberos failure\n\r", m_remoteHost.ascii()); + s->close(); + delete s; + s = NULL; + } + else { + m_numberOfConnections++; + connect(s, SIGNAL(connectionClosed()), s, SLOT(deleteLater())); + connect(s, SIGNAL(connectionClosed()), this, SLOT(remoteConnectionClosed())); + emit newConnect(s); + s->enterCommandLoop(); + } +} + +void FPGAServer::remoteConnectionClosed() { + m_numberOfConnections--; +}
\ No newline at end of file diff --git a/servers/fpga_server_lin/src/fpga_conn.h b/servers/fpga_server_lin/src/fpga_conn.h new file mode 100644 index 0000000..1edded2 --- /dev/null +++ b/servers/fpga_server_lin/src/fpga_conn.h @@ -0,0 +1,89 @@ +/* + * Remote Laboratory FPGA Server + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + * (c) 2012 Timothy Pearson + * Raptor Engineering + * http://www.raptorengineeringinc.com + */ + +#include <tqsocket.h> +#include <tqserversocket.h> +#include <tqapplication.h> +#include <tqvbox.h> +#include <tqtextview.h> +#include <tqlabel.h> +#include <tqpushbutton.h> +#include <tqtextstream.h> + +#include <ksimpleconfig.h> + +#include <tdekrbserversocket.h> + +#include <tqtrla.h> + +#define MAGIC_NUMBER 1 +#define PROTOCOL_VERSION 1 + +class FPGASocket : public TDEKerberosServerSocket +{ + Q_OBJECT + + public: + FPGASocket(int sock, TQObject *parent=0, const char *name=0); + ~FPGASocket(); + + public: + void close(); + int initiateKerberosHandshake(); + void enterCommandLoop(); + + private slots: + void connectionClosedHandler(); + + private: + int line; + int m_criticalSection; + TQString m_remoteHost; + + KSimpleConfig* m_config; + + friend class FPGAServer; +}; + +class FPGAServer : public TQServerSocket +{ + Q_OBJECT + + public: + FPGAServer(TQObject* parent=0, int port=0, KSimpleConfig* config=0); + ~FPGAServer(); + + void newConnection(int socket); + + private slots: + void remoteConnectionClosed(); + + signals: + void newConnect(FPGASocket*); + + private: + KSimpleConfig* m_config; + int m_numberOfConnections; + + friend class FPGASocket; + +};
\ No newline at end of file diff --git a/servers/fpga_server_lin/src/main.cpp b/servers/fpga_server_lin/src/main.cpp new file mode 100644 index 0000000..fa30af4 --- /dev/null +++ b/servers/fpga_server_lin/src/main.cpp @@ -0,0 +1,63 @@ +/*************************************************************************** + * Copyright (C) 2012 by Timothy Pearson * + * kb9vqf@pearsoncomputing.net * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + +#include <sys/types.h> +#include <sys/socket.h> +#include <netdb.h> +#include <pwd.h> +#include <limits.h> +#include <stdio.h> +#include <unistd.h> +#include <stdlib.h> + +#include <kapplication.h> +#include <kstartupinfo.h> +#include <kcmdlineargs.h> +#include <kaboutdata.h> + +#include <ksimpleconfig.h> + +#include <tqdatetime.h> +#include <tqfile.h> + +#include "fpga_conn.h" + +static const char description[] = I18N_NOOP("RemoteFPGA Kerberos Authentication Server"); + +static const char version[] = "v0.0.1"; + +int main(int argc, char *argv[]) +{ + KAboutData aboutData( "remotefpga_auth_server", I18N_NOOP("RemoteFPGA AuthServer"), + version, description, KAboutData::License_GPL, + "(c) 2012, Timothy Pearson"); + aboutData.addAuthor("Timothy Pearson",0, "kb9vqf@pearsoncomputing.net"); + KCmdLineArgs::init( argc, argv, &aboutData ); + KApplication::disableAutoDcopRegistration(); + + KApplication app(false, false); + + KStartupInfo::appStarted(); + + KSimpleConfig config("./remotefpga_fpgaserver.conf", false); + AuthServer authsvr(0, config); + return app.exec(); + +} |