|
@@ -4,6 +4,7 @@
|
|
|
#include <iostream>
|
|
|
#include <Klient.h>
|
|
|
#include <Globals.h>
|
|
|
+#include <AsynchronCall.h>
|
|
|
|
|
|
// Inhalt der MainServer Klasse aus MainServer.h
|
|
|
// Konstruktor
|
|
@@ -17,6 +18,9 @@ MainServer::MainServer( InitDatei *zDat )
|
|
|
empfangen = 0;
|
|
|
gesendet = 0;
|
|
|
dat = zDat->getThis();
|
|
|
+ serverSSL = new SSLServer();
|
|
|
+ serverSSL->setCertificateFile( zDat->zWert( "SSLCert" )->getText() );
|
|
|
+ serverSSL->setCertificateFile( zDat->zWert( "SSLKey" )->getText() );
|
|
|
server = new Server();
|
|
|
aServer = new Server();
|
|
|
std::cout << "MS: Starten des Admin Servers...\n";
|
|
@@ -36,6 +40,8 @@ MainServer::MainServer( InitDatei *zDat )
|
|
|
MainServer::~MainServer()
|
|
|
{
|
|
|
ende();
|
|
|
+ serverSSL->trenne();
|
|
|
+ serverSSL->release();
|
|
|
server->trenne();
|
|
|
server->release();
|
|
|
aServer->trenne();
|
|
@@ -69,6 +75,22 @@ void MainServer::runn()
|
|
|
|
|
|
void MainServer::thread()
|
|
|
{
|
|
|
+ SSLServer *sslServer = serverSSL;
|
|
|
+ int *cl = &clients;
|
|
|
+ MainServer *ms = this;
|
|
|
+ AsynchronCall( [ sslServer, cl, ms ]()
|
|
|
+ {
|
|
|
+ while( 1 )
|
|
|
+ {
|
|
|
+ SSLSKlient *klient = sslServer->getKlient();
|
|
|
+ if( !klient )
|
|
|
+ break;
|
|
|
+ Framework::getThreadRegister()->cleanUpClosedThreads();
|
|
|
+ MSKlientSSL *clHandle = new MSKlientSSL( klient, ms->getThis() );
|
|
|
+ clHandle->start();
|
|
|
+ (*cl)++;
|
|
|
+ }
|
|
|
+ } );
|
|
|
while( 1 )
|
|
|
{
|
|
|
SKlient *klient;
|
|
@@ -85,6 +107,7 @@ void MainServer::thread()
|
|
|
|
|
|
void MainServer::close()
|
|
|
{
|
|
|
+ serverSSL->trenne();
|
|
|
server->trenne();
|
|
|
#ifdef WIN32
|
|
|
warteAufThread( 1000 );
|
|
@@ -104,6 +127,7 @@ bool MainServer::serverStarten()
|
|
|
if( run )
|
|
|
return 1;
|
|
|
bool ret = server->verbinde( (unsigned short)TextZuInt( dat->zWert( "ServerPort" )->getText(), 10 ), 10 );
|
|
|
+ ret &= serverSSL->verbinde( (unsigned short)TextZuInt( dat->zWert( "SSLPort" )->getText(), 10 ), 10 );
|
|
|
start();
|
|
|
return ret;
|
|
|
}
|
|
@@ -113,6 +137,7 @@ void MainServer::serverBeenden()
|
|
|
if( !run )
|
|
|
return;
|
|
|
server->trenne();
|
|
|
+ serverSSL->trenne();
|
|
|
#ifdef WIN32
|
|
|
warteAufThread( 1000 );
|
|
|
#endif
|
|
@@ -153,6 +178,11 @@ bool MainServer::hatClients() const
|
|
|
return clients > 0;
|
|
|
}
|
|
|
|
|
|
+InitDatei *MainServer::zInit() const
|
|
|
+{
|
|
|
+ return dat;
|
|
|
+}
|
|
|
+
|
|
|
// Reference Counting
|
|
|
MainServer *MainServer::getThis()
|
|
|
{
|
|
@@ -372,6 +402,87 @@ void MSAKlient::errorZuKlient( const char *nachricht ) const // sendet eine Fehl
|
|
|
}
|
|
|
|
|
|
|
|
|
+// Konstruktor
|
|
|
+MSKlientSSL::MSKlientSSL( SSLSKlient *klient, MainServer *ms )
|
|
|
+{
|
|
|
+ this->klient = klient;
|
|
|
+ klientNummer = 0;
|
|
|
+ this->ms = ms;
|
|
|
+}
|
|
|
+
|
|
|
+// Destruktor
|
|
|
+MSKlientSSL::~MSKlientSSL()
|
|
|
+{
|
|
|
+ ms->clientTrennung();
|
|
|
+ ms->release();
|
|
|
+ klient->release();
|
|
|
+}
|
|
|
+
|
|
|
+// nicht constant
|
|
|
+void MSKlientSSL::thread()
|
|
|
+{
|
|
|
+ while( 1 )
|
|
|
+ {
|
|
|
+ char c = 0;
|
|
|
+ if( !klient->getNachricht( &c, 1 ) )
|
|
|
+ break;
|
|
|
+ else
|
|
|
+ {
|
|
|
+ bool br = 0;
|
|
|
+ switch( c )
|
|
|
+ {
|
|
|
+ case 1: // Client Identifikation
|
|
|
+ if( !klientNummer )
|
|
|
+ {
|
|
|
+ bool ret1 = 0;
|
|
|
+ klientNummer = ms->zDB()->getNextClientId();
|
|
|
+ Text *key = ms->zDB()->getKlientKey( klientNummer );
|
|
|
+ if( key )
|
|
|
+ {
|
|
|
+ int port = TextZuInt( ms->zInit()->zWert( "ServerPort" )->getText(), 10 );
|
|
|
+ klient->sende( "\1", 1 );
|
|
|
+ klient->sende( (char*)&port, 4 );
|
|
|
+ klient->sende( (char*)&klientNummer, 4 );
|
|
|
+ char len = (char)key->getLength();
|
|
|
+ klient->sende( &len, 1 );
|
|
|
+ if( len )
|
|
|
+ klient->sende( key->getText(), len );
|
|
|
+ key->release();
|
|
|
+ }
|
|
|
+ else
|
|
|
+ errorZuKlient( "Es konnte kein Schlüssel ermittelt werden." );
|
|
|
+ }
|
|
|
+ else
|
|
|
+ errorZuKlient( "Du besitzt bereits eine Klient Nummer." );
|
|
|
+ break;
|
|
|
+ case 3: // Verbindungsende
|
|
|
+ br = 1;
|
|
|
+ klient->sende( "\1", 1 );
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ errorZuKlient( "Unbekannte Nachricht!\0" );
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ if( br )
|
|
|
+ break;
|
|
|
+ ms->addEmpfangen( klient->getDownloadBytes( 1 ) );
|
|
|
+ ms->addGesendet( klient->getUploadBytes( 1 ) );
|
|
|
+ }
|
|
|
+ }
|
|
|
+ ms->addEmpfangen( klient->getDownloadBytes( 1 ) );
|
|
|
+ ms->addGesendet( klient->getUploadBytes( 1 ) );
|
|
|
+ delete this;
|
|
|
+}
|
|
|
+
|
|
|
+void MSKlientSSL::errorZuKlient( const char *nachricht ) const // sendet eine Fehlernachricht zum Klient
|
|
|
+{
|
|
|
+ klient->sende( "\3", 1 );
|
|
|
+ char len = (char)textLength( nachricht );
|
|
|
+ klient->sende( &len, 1 );
|
|
|
+ klient->sende( nachricht, len );
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
// Inhalt der MSKlient Klasse aus MainServer.h
|
|
|
// Konstruktor
|
|
|
MSKlient::MSKlient( SKlient *klient, MainServer *ms )
|