|
@@ -5,18 +5,17 @@
|
|
|
|
|
|
// Inhalt der NewsServer Klasse aus NewsServer.h
|
|
|
// Konstruktor
|
|
|
-NewsServer::NewsServer( InitDatei *zIni )
|
|
|
+NewsServer::NewsServer( InitDatei* zIni )
|
|
|
: Thread()
|
|
|
{
|
|
|
Network::Start( 100 );
|
|
|
std::cout << "IS: Verbindung mit Datenbank wird hergestellt...\n";
|
|
|
db = new NSDatenbank( zIni );
|
|
|
- klientAnzahl = 0;
|
|
|
klients = new RCArray< NSKlient >();
|
|
|
empfangen = 0;
|
|
|
gesendet = 0;
|
|
|
fehler = new Text();
|
|
|
- ini = dynamic_cast<InitDatei *>( zIni->getThis() );
|
|
|
+ ini = dynamic_cast<InitDatei*>(zIni->getThis());
|
|
|
id = *zIni->zWert( "ServerId" );
|
|
|
server = new Server();
|
|
|
aServer = new SSLServer();
|
|
@@ -60,18 +59,18 @@ void NewsServer::runn()
|
|
|
{
|
|
|
while( !end && aServer->isConnected() )
|
|
|
{
|
|
|
- SSLSKlient *klient;
|
|
|
+ SSLSKlient* klient;
|
|
|
klient = aServer->getKlient();
|
|
|
if( end && klient )
|
|
|
{
|
|
|
klient->trenne();
|
|
|
- klient = (SSLSKlient *)klient->release();
|
|
|
+ klient = (SSLSKlient*)klient->release();
|
|
|
Sleep( 1000 );
|
|
|
return;
|
|
|
}
|
|
|
if( !klient )
|
|
|
continue;
|
|
|
- NSAKlient *clHandle = new NSAKlient( klient, dynamic_cast<NewsServer *>( getThis() ) );
|
|
|
+ NSAKlient* clHandle = new NSAKlient( klient, dynamic_cast<NewsServer*>(getThis()) );
|
|
|
clHandle->start();
|
|
|
}
|
|
|
}
|
|
@@ -80,15 +79,14 @@ void NewsServer::thread()
|
|
|
{
|
|
|
while( server->isConnected() )
|
|
|
{
|
|
|
- SKlient *klient;
|
|
|
+ SKlient* klient;
|
|
|
klient = server->getKlient();
|
|
|
if( !klient )
|
|
|
continue;
|
|
|
Framework::getThreadRegister()->cleanUpClosedThreads();
|
|
|
- NSKlient *clHandle = new NSKlient( klient, dynamic_cast<NewsServer *>( getThis() ) );
|
|
|
+ NSKlient* clHandle = new NSKlient( klient, dynamic_cast<NewsServer*>(getThis()) );
|
|
|
EnterCriticalSection( &cs );
|
|
|
- klients->set( clHandle, klientAnzahl );
|
|
|
- klientAnzahl++;
|
|
|
+ klients->add( clHandle );
|
|
|
LeaveCriticalSection( &cs );
|
|
|
clHandle->start();
|
|
|
}
|
|
@@ -102,15 +100,14 @@ void NewsServer::close()
|
|
|
warteAufThread( 1000 );
|
|
|
#endif
|
|
|
EnterCriticalSection( &cs );
|
|
|
- for( int i = 0; i < klientAnzahl; i++ )
|
|
|
+ for( int i = 0; i < klients->getEintragAnzahl(); i++ )
|
|
|
klients->z( i )->absturz();
|
|
|
- klients = ( RCArray<NSKlient>* )klients->release();
|
|
|
- klientAnzahl = 0;
|
|
|
+ klients = (RCArray<NSKlient>*)klients->release();
|
|
|
LeaveCriticalSection( &cs );
|
|
|
ende();
|
|
|
run = 0;
|
|
|
end = 1;
|
|
|
- Klient *klient = new Klient();
|
|
|
+ Klient* klient = new Klient();
|
|
|
klient->verbinde( aServer->getPort(), "127.0.0.1" );
|
|
|
Sleep( 500 );
|
|
|
aServer->trenne();
|
|
@@ -208,13 +205,12 @@ bool NewsServer::absturzKlient( int klientId )
|
|
|
{
|
|
|
bool gefunden = 0;
|
|
|
EnterCriticalSection( &cs );
|
|
|
- for( int i = 0; i < klientAnzahl; i++ )
|
|
|
+ for( int i = 0; i < klients->getEintragAnzahl(); i++ )
|
|
|
{
|
|
|
if( klients->z( i )->getKlientNummer() == klientId )
|
|
|
{
|
|
|
klients->z( i )->absturz();
|
|
|
klients->remove( i );
|
|
|
- klientAnzahl--;
|
|
|
gefunden = 1;
|
|
|
break;
|
|
|
}
|
|
@@ -223,16 +219,15 @@ bool NewsServer::absturzKlient( int klientId )
|
|
|
return gefunden;
|
|
|
}
|
|
|
|
|
|
-bool NewsServer::removeKlient( NSKlient *zKlient )
|
|
|
+bool NewsServer::removeKlient( NSKlient* zKlient )
|
|
|
{
|
|
|
bool gefunden = 0;
|
|
|
EnterCriticalSection( &cs );
|
|
|
- for( int i = 0; i < klientAnzahl; i++ )
|
|
|
+ for( int i = 0; i < klients->getEintragAnzahl(); i++ )
|
|
|
{
|
|
|
if( klients->z( i ) == zKlient )
|
|
|
{
|
|
|
klients->remove( i );
|
|
|
- klientAnzahl--;
|
|
|
gefunden = 1;
|
|
|
break;
|
|
|
}
|
|
@@ -257,19 +252,19 @@ bool NewsServer::istAn() const
|
|
|
return db->serverIstNichtPausiert( id );
|
|
|
}
|
|
|
|
|
|
-Server *NewsServer::zServer() const
|
|
|
+Server* NewsServer::zServer() const
|
|
|
{
|
|
|
return server;
|
|
|
}
|
|
|
|
|
|
-NSDatenbank *NewsServer::zDB() const
|
|
|
+NSDatenbank* NewsServer::zDB() const
|
|
|
{
|
|
|
return db;
|
|
|
}
|
|
|
|
|
|
bool NewsServer::hatClients() const
|
|
|
{
|
|
|
- return klientAnzahl > 0;
|
|
|
+ return klients->hat( 0 );
|
|
|
}
|
|
|
|
|
|
int NewsServer::getId() const
|
|
@@ -277,7 +272,7 @@ int NewsServer::getId() const
|
|
|
return id;
|
|
|
}
|
|
|
|
|
|
-char *NewsServer::getLetzterFehler() const
|
|
|
+char* NewsServer::getLetzterFehler() const
|
|
|
{
|
|
|
return fehler->getText();
|
|
|
}
|
|
@@ -285,7 +280,7 @@ char *NewsServer::getLetzterFehler() const
|
|
|
|
|
|
// Inhalt der NSAKlient Klasse aus NewsServer.h
|
|
|
// Konstruktor
|
|
|
-NSAKlient::NSAKlient( SSLSKlient *klient, NewsServer *ns )
|
|
|
+NSAKlient::NSAKlient( SSLSKlient* klient, NewsServer* ns )
|
|
|
: Thread()
|
|
|
{
|
|
|
this->klient = klient;
|
|
@@ -323,14 +318,14 @@ void NSAKlient::thread()
|
|
|
{
|
|
|
klient->sende( "\1", 1 );
|
|
|
unsigned char nLen = 0;
|
|
|
- klient->getNachricht( (char *)&nLen, 1 );
|
|
|
- char *n = new char[ nLen + 1 ];
|
|
|
+ klient->getNachricht( (char*)&nLen, 1 );
|
|
|
+ char* n = new char[ nLen + 1 ];
|
|
|
n[ (int)nLen ] = 0;
|
|
|
if( nLen )
|
|
|
klient->getNachricht( n, nLen );
|
|
|
unsigned char pLen = 0;
|
|
|
- klient->getNachricht( (char *)&pLen, 1 );
|
|
|
- char *p = new char[ pLen + 1 ];
|
|
|
+ klient->getNachricht( (char*)&pLen, 1 );
|
|
|
+ char* p = new char[ pLen + 1 ];
|
|
|
p[ (int)pLen ] = 0;
|
|
|
if( pLen )
|
|
|
klient->getNachricht( p, pLen );
|
|
@@ -367,7 +362,7 @@ void NSAKlient::thread()
|
|
|
{
|
|
|
if( !ns->serverStarten() )
|
|
|
{
|
|
|
- Text *err = new Text();
|
|
|
+ Text* err = new Text();
|
|
|
err->append( ns->getLetzterFehler() );
|
|
|
errorZuKlient( err->getText() );
|
|
|
err->release();
|
|
@@ -390,7 +385,7 @@ void NSAKlient::thread()
|
|
|
klient->sende( "\1", 1 );
|
|
|
else
|
|
|
{
|
|
|
- Text *err = new Text();
|
|
|
+ Text* err = new Text();
|
|
|
err->append( ns->getLetzterFehler() );
|
|
|
errorZuKlient( err->getText() );
|
|
|
err->release();
|
|
@@ -414,7 +409,7 @@ void NSAKlient::thread()
|
|
|
ok = 1;
|
|
|
else
|
|
|
{
|
|
|
- Text *err = new Text();
|
|
|
+ Text* err = new Text();
|
|
|
err->append( ns->getLetzterFehler() );
|
|
|
errorZuKlient( err->getText() );
|
|
|
err->release();
|
|
@@ -499,7 +494,7 @@ void NSAKlient::thread()
|
|
|
klient->sende( "\1", 1 );
|
|
|
else
|
|
|
{
|
|
|
- Text *err = new Text();
|
|
|
+ Text* err = new Text();
|
|
|
err->append( ns->getLetzterFehler() );
|
|
|
errorZuKlient( err->getText() );
|
|
|
err->release();
|
|
@@ -521,14 +516,14 @@ void NSAKlient::thread()
|
|
|
{
|
|
|
klient->sende( "\1", 1 );
|
|
|
int maxC = 0;
|
|
|
- klient->getNachricht( (char *)&maxC, 4 );
|
|
|
+ klient->getNachricht( (char*)&maxC, 4 );
|
|
|
if( ns->zDB()->adminHatRecht( adminId, Admin_Recht::NSMCChange ) )
|
|
|
{
|
|
|
if( ns->setMaxKlients( maxC ) )
|
|
|
klient->sende( "\1", 1 );
|
|
|
else
|
|
|
{
|
|
|
- Text *err = new Text();
|
|
|
+ Text* err = new Text();
|
|
|
err->append( ns->getLetzterFehler() );
|
|
|
errorZuKlient( err->getText() );
|
|
|
err->release();
|
|
@@ -543,7 +538,7 @@ void NSAKlient::thread()
|
|
|
{
|
|
|
klient->sende( "\1", 1 );
|
|
|
int klientId = 0;
|
|
|
- klient->getNachricht( (char *)&klientId, 4 );
|
|
|
+ klient->getNachricht( (char*)&klientId, 4 );
|
|
|
if( klientId && ns->absturzKlient( klientId ) )
|
|
|
klient->sende( "\1", 1 );
|
|
|
else
|
|
@@ -565,7 +560,7 @@ void NSAKlient::thread()
|
|
|
delete this;
|
|
|
}
|
|
|
|
|
|
-void NSAKlient::errorZuKlient( const char *nachricht ) const // sendet eine Fehlernachricht zum Klient
|
|
|
+void NSAKlient::errorZuKlient( const char* nachricht ) const // sendet eine Fehlernachricht zum Klient
|
|
|
{
|
|
|
klient->sende( "\3", 1 );
|
|
|
char len = (char)textLength( nachricht );
|
|
@@ -576,13 +571,13 @@ void NSAKlient::errorZuKlient( const char *nachricht ) const // sendet eine Fehl
|
|
|
|
|
|
// Inhalt der NSKlient aus NewsServer.h
|
|
|
// Konstruktor
|
|
|
-NSKlient::NSKlient( SKlient *klient, NewsServer *ns )
|
|
|
+NSKlient::NSKlient( SKlient* klient, NewsServer* ns )
|
|
|
: Thread()
|
|
|
{
|
|
|
this->klient = klient;
|
|
|
unsigned char key[ 20 ] = { 4, 150, 243, 145, 204, 71, 253, 88, 4, 51, 189, 207, 189, 248, 231, 40, 106, 7, 182, 5 };
|
|
|
- klient->setSendeKey( (char *)key, 20 );
|
|
|
- klient->setEmpfangKey( (char *)key, 20 );
|
|
|
+ klient->setSendeKey( (char*)key, 20 );
|
|
|
+ klient->setEmpfangKey( (char*)key, 20 );
|
|
|
klientNummer = 0;
|
|
|
this->ns = ns;
|
|
|
}
|
|
@@ -615,7 +610,7 @@ void NSKlient::thread()
|
|
|
switch( c )
|
|
|
{
|
|
|
case 1: // Klient identifikation
|
|
|
- klient->getNachrichtEncrypted( (char *)&klientNummer, 4 );
|
|
|
+ klient->getNachrichtEncrypted( (char*)&klientNummer, 4 );
|
|
|
if( !ns->zDB()->proveKlient( klientNummer, ns->getId() ) )
|
|
|
{
|
|
|
klientNummer = 0;
|
|
@@ -623,7 +618,7 @@ void NSKlient::thread()
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- Text *key = ns->zDB()->getKlientKey( klientNummer );
|
|
|
+ Text* key = ns->zDB()->getKlientKey( klientNummer );
|
|
|
if( !key )
|
|
|
errorZuKlient( "Es konnte kein Key ermittelt werden." );
|
|
|
else
|
|
@@ -646,7 +641,7 @@ void NSKlient::thread()
|
|
|
if( 1 )
|
|
|
{
|
|
|
int klientId = 0;
|
|
|
- klient->getNachrichtEncrypted( (char *)&klientId, 4 );
|
|
|
+ klient->getNachrichtEncrypted( (char*)&klientId, 4 );
|
|
|
if( klientId && ns->absturzKlient( klientId ) )
|
|
|
klient->sendeEncrypted( "\1", 1 );
|
|
|
else
|
|
@@ -677,11 +672,11 @@ void NSKlient::thread()
|
|
|
{
|
|
|
klient->sendeEncrypted( "\1", 1 );
|
|
|
unsigned char len = 0;
|
|
|
- klient->getNachrichtEncrypted( (char *)&len, 1 );
|
|
|
- char *n = new char[ len + 1 ];
|
|
|
+ klient->getNachrichtEncrypted( (char*)&len, 1 );
|
|
|
+ char* n = new char[ len + 1 ];
|
|
|
n[ (int)len ] = 0;
|
|
|
klient->getNachrichtEncrypted( n, len );
|
|
|
- Text *pfad = new Text( "../news/" );
|
|
|
+ Text* pfad = new Text( "../news/" );
|
|
|
pfad->append( n );
|
|
|
delete[] n;
|
|
|
if( !DateiExistiert( pfad->getText() ) )
|
|
@@ -691,9 +686,9 @@ void NSKlient::thread()
|
|
|
break;
|
|
|
}
|
|
|
klient->sendeEncrypted( "\1", 1 );
|
|
|
- Datei *dat = new Datei();
|
|
|
+ Datei* dat = new Datei();
|
|
|
dat->setDatei( pfad );
|
|
|
- RCArray< Text > *list = dat->getDateiListe();
|
|
|
+ RCArray< Text >* list = dat->getDateiListe();
|
|
|
int dAnz = list->getEintragAnzahl();
|
|
|
for( int i = 0; i < dAnz; i++ )
|
|
|
{
|
|
@@ -704,21 +699,21 @@ void NSKlient::thread()
|
|
|
i--;
|
|
|
}
|
|
|
}
|
|
|
- klient->sendeEncrypted( (char *)&dAnz, 4 );
|
|
|
+ klient->sendeEncrypted( (char*)&dAnz, 4 );
|
|
|
for( int i = 0; i < dAnz; i++ )
|
|
|
{
|
|
|
- Text *pf = new Text( dat->zPfad()->getText() );
|
|
|
+ Text* pf = new Text( dat->zPfad()->getText() );
|
|
|
pf->append( "/" );
|
|
|
pf->append( list->z( i )->getText() );
|
|
|
- Datei *d = new Datei();
|
|
|
+ Datei* d = new Datei();
|
|
|
d->setDatei( pf );
|
|
|
d->open( Datei::Style::lesen );
|
|
|
char nl = (char)list->z( i )->getLength();
|
|
|
klient->sendeEncrypted( &nl, 1 );
|
|
|
klient->sendeEncrypted( list->z( i )->getText(), nl );
|
|
|
__int64 gr = d->getSize();
|
|
|
- klient->sendeEncrypted( (char *)&gr, 8 );
|
|
|
- char *bytes = new char[ 2048 ];
|
|
|
+ klient->sendeEncrypted( (char*)&gr, 8 );
|
|
|
+ char* bytes = new char[ 2048 ];
|
|
|
while( gr > 0 )
|
|
|
{
|
|
|
int len = gr > 2048 ? 2048 : (int)gr;
|
|
@@ -763,7 +758,7 @@ void NSKlient::thread()
|
|
|
}
|
|
|
|
|
|
// constant
|
|
|
-void NSKlient::errorZuKlient( const char *nachricht ) const // sendet eine Fehlernachricht zum Klient
|
|
|
+void NSKlient::errorZuKlient( const char* nachricht ) const // sendet eine Fehlernachricht zum Klient
|
|
|
{
|
|
|
klient->sendeEncrypted( "\3", 1 );
|
|
|
char len = (char)textLength( nachricht );
|