remove or translate old comments

This commit is contained in:
Florian Westphal 2009-04-21 08:40:10 +02:00
parent 5e16b6df2d
commit 544b9884f4
13 changed files with 160 additions and 271 deletions

View File

@ -193,7 +193,6 @@ Init_New_Client(CONN_ID Idx, CLIENT *Introducer, CLIENT *TopServer,
client = New_Client_Struct( );
if( ! client ) return NULL;
/* Initialisieren */
client->starttime = time(NULL);
client->conn_id = Idx;
client->introducer = Introducer;
@ -211,11 +210,9 @@ Init_New_Client(CONN_ID Idx, CLIENT *Introducer, CLIENT *TopServer,
if( strchr( client->modes, 'a' ))
strlcpy( client->away, DEFAULT_AWAY_MSG, sizeof( client->away ));
/* Verketten */
client->next = (POINTER *)My_Clients;
My_Clients = client;
/* Adjust counters */
Adjust_Counters( client );
return client;
@ -225,7 +222,7 @@ Init_New_Client(CONN_ID Idx, CLIENT *Introducer, CLIENT *TopServer,
GLOBAL void
Client_Destroy( CLIENT *Client, const char *LogMsg, const char *FwdMsg, bool SendQuit )
{
/* Client entfernen. */
/* remove a client */
CLIENT *last, *c;
char msg[LINE_LEN];
@ -237,7 +234,7 @@ Client_Destroy( CLIENT *Client, const char *LogMsg, const char *FwdMsg, bool Sen
else txt = FwdMsg;
if( ! txt ) txt = "Reason unknown.";
/* Netz-Split-Nachricht vorbereiten (noch nicht optimal) */
/* netsplit message */
if( Client->type == CLIENT_SERVER ) {
strlcpy(msg, This_Server->id, sizeof (msg));
strlcat(msg, " ", sizeof (msg));
@ -250,8 +247,16 @@ Client_Destroy( CLIENT *Client, const char *LogMsg, const char *FwdMsg, bool Sen
{
if(( Client->type == CLIENT_SERVER ) && ( c->introducer == Client ) && ( c != Client ))
{
/* der Client, der geloescht wird ist ein Server. Der Client, den wir gerade
* pruefen, ist ein Child von diesem und muss daher auch entfernt werden */
/*
* The client that is about to be removed is a server,
* the client we are checking right now is a child of that
* server and thus has to be removed, too.
*
* Call Client_Destroy() recursively with the server as the
* new "object to be removed". This starts the cycle again, until
* all servers that are linked via the original server have been
* removed.
*/
Client_Destroy( c, NULL, msg, false );
last = NULL;
c = My_Clients;
@ -259,7 +264,7 @@ Client_Destroy( CLIENT *Client, const char *LogMsg, const char *FwdMsg, bool Sen
}
if( c == Client )
{
/* Wir haben den Client gefunden: entfernen */
/* found the client: remove it */
if( last ) last->next = c->next;
else My_Clients = (CLIENT *)c->next;
@ -273,7 +278,7 @@ Client_Destroy( CLIENT *Client, const char *LogMsg, const char *FwdMsg, bool Sen
else Log( LOG_NOTICE|LOG_snotice, "Server \"%s\" unregistered: %s", c->id, txt );
}
/* andere Server informieren */
/* inform other servers */
if( ! NGIRCd_SignalQuit )
{
if( FwdMsg ) IRC_WriteStrServersPrefix( Client_NextHop( c ), c, "SQUIT %s :%s", c->id, FwdMsg );

View File

@ -16,8 +16,6 @@
#include "portab.h"
static char UNUSED id[] = "$Id: conn-func.c,v 1.12 2008/03/11 14:05:27 alex Exp $";
#include "imp.h"
#include <assert.h>
#include <string.h>
@ -33,8 +31,6 @@ static char UNUSED id[] = "$Id: conn-func.c,v 1.12 2008/03/11 14:05:27 alex Exp
GLOBAL void
Conn_UpdateIdle( CONN_ID Idx )
{
/* Idle-Timer zuruecksetzen */
assert( Idx > NONE );
My_Connections[Idx].lastprivmsg = time( NULL );
}
@ -53,8 +49,7 @@ Conn_GetSignon(CONN_ID Idx)
GLOBAL time_t
Conn_GetIdle( CONN_ID Idx )
{
/* Idle-Time einer Verbindung liefern (in Sekunden) */
/* Return Idle-Timer of a connetion */
assert( Idx > NONE );
return time( NULL ) - My_Connections[Idx].lastprivmsg;
} /* Conn_GetIdle */
@ -63,8 +58,6 @@ Conn_GetIdle( CONN_ID Idx )
GLOBAL time_t
Conn_LastPing( CONN_ID Idx )
{
/* Zeitpunkt des letzten PING liefern */
assert( Idx > NONE );
return My_Connections[Idx].lastping;
} /* Conn_LastPing */
@ -73,11 +66,11 @@ Conn_LastPing( CONN_ID Idx )
GLOBAL void
Conn_SetPenalty( CONN_ID Idx, time_t Seconds )
{
/* Penalty-Delay fuer eine Verbindung (in Sekunden) setzen;
* waehrend dieser Zeit wird der entsprechende Socket vom Server
* bei Lese-Operationen komplett ignoriert. Der Delay kann mit
* dieser Funktion nur erhoeht, nicht aber verringert werden. */
/* set Penalty-Delay for a socket.
* during the penalty, the socket is ignored completely, no new
* data is read. This function only increases the penalty, it is
* not possible to decrease the penalty time.
*/
time_t t;
assert( Idx > NONE );
@ -105,8 +98,6 @@ Conn_ResetPenalty( CONN_ID Idx )
GLOBAL void
Conn_ClearFlags( void )
{
/* Alle Connection auf "nicht-markiert" setzen */
CONN_ID i;
for( i = 0; i < Pool_Size; i++ ) My_Connections[i].flag = 0;
@ -116,8 +107,6 @@ Conn_ClearFlags( void )
GLOBAL int
Conn_Flag( CONN_ID Idx )
{
/* Ist eine Connection markiert (true) oder nicht? */
assert( Idx > NONE );
return My_Connections[Idx].flag;
} /* Conn_Flag */
@ -206,12 +195,12 @@ Conn_StartTime( CONN_ID Idx )
return 0;
} /* Conn_StartTime */
/**
* return number of bytes queued for writing
*/
GLOBAL size_t
Conn_SendQ( CONN_ID Idx )
{
/* Laenge der Daten im Schreibbuffer liefern */
assert( Idx > NONE );
#ifdef ZLIB
if( My_Connections[Idx].options & CONN_ZIP )
@ -222,31 +211,36 @@ Conn_SendQ( CONN_ID Idx )
} /* Conn_SendQ */
/**
* return number of messages sent on this connection so far
*/
GLOBAL long
Conn_SendMsg( CONN_ID Idx )
{
/* Anzahl gesendeter Nachrichten liefern */
assert( Idx > NONE );
return My_Connections[Idx].msg_out;
} /* Conn_SendMsg */
/**
* return number of (uncompressed) bytes sent
* on this connection so far
*/
GLOBAL long
Conn_SendBytes( CONN_ID Idx )
{
/* Anzahl gesendeter Bytes (unkomprimiert) liefern */
assert( Idx > NONE );
return My_Connections[Idx].bytes_out;
} /* Conn_SendBytes */
/**
* return number of bytes pending in read buffer
*/
GLOBAL size_t
Conn_RecvQ( CONN_ID Idx )
{
/* Laenge der Daten im Lesebuffer liefern */
assert( Idx > NONE );
#ifdef ZLIB
if( My_Connections[Idx].options & CONN_ZIP )
@ -257,21 +251,24 @@ Conn_RecvQ( CONN_ID Idx )
} /* Conn_RecvQ */
/**
* return number of messages received on this connection so far
*/
GLOBAL long
Conn_RecvMsg( CONN_ID Idx )
{
/* Anzahl empfangener Nachrichten liefern */
assert( Idx > NONE );
return My_Connections[Idx].msg_in;
} /* Conn_RecvMsg */
/**
* return number of (uncompressed) bytes received on this
* connection so far
*/
GLOBAL long
Conn_RecvBytes( CONN_ID Idx )
{
/* Anzahl empfangener Bytes (unkomprimiert) liefern */
assert( Idx > NONE );
return My_Connections[Idx].bytes_in;
} /* Conn_RecvBytes */

View File

@ -11,19 +11,15 @@
* Connection compression using ZLIB
*/
#include "portab.h"
#define CONN_MODULE
#ifdef ZLIB
/* enable more zlib related debug messages: */
/* #define DEBUG_ZLIB */
static char UNUSED id[] = "$Id: conn-zip.c,v 1.16 2007/05/17 23:34:24 alex Exp $";
#include "imp.h"
#include <assert.h>
#include <string.h>
@ -41,7 +37,7 @@ static char UNUSED id[] = "$Id: conn-zip.c,v 1.16 2007/05/17 23:34:24 alex Exp $
GLOBAL bool
Zip_InitConn( CONN_ID Idx )
{
/* Kompression fuer Link initialisieren */
/* initialize zlib compression on this link */
assert( Idx > NONE );
@ -52,10 +48,8 @@ Zip_InitConn( CONN_ID Idx )
My_Connections[Idx].zip.in.zfree = NULL;
My_Connections[Idx].zip.in.data_type = Z_ASCII;
if( inflateInit( &My_Connections[Idx].zip.in ) != Z_OK )
{
/* Fehler! */
Log( LOG_ALERT, "Can't initialize compression on connection %d (zlib inflate)!", Idx );
if (inflateInit( &My_Connections[Idx].zip.in ) != Z_OK) {
Log(LOG_ALERT, "Can't initialize compression on connection %d (zlib inflate)!", Idx);
return false;
}
@ -65,17 +59,15 @@ Zip_InitConn( CONN_ID Idx )
My_Connections[Idx].zip.out.zfree = NULL;
My_Connections[Idx].zip.out.data_type = Z_ASCII;
if( deflateInit( &My_Connections[Idx].zip.out, Z_DEFAULT_COMPRESSION ) != Z_OK )
{
/* Fehler! */
Log( LOG_ALERT, "Can't initialize compression on connection %d (zlib deflate)!", Idx );
if (deflateInit( &My_Connections[Idx].zip.out, Z_DEFAULT_COMPRESSION ) != Z_OK) {
Log(LOG_ALERT, "Can't initialize compression on connection %d (zlib deflate)!", Idx);
return false;
}
My_Connections[Idx].zip.bytes_in = My_Connections[Idx].bytes_in;
My_Connections[Idx].zip.bytes_out = My_Connections[Idx].bytes_out;
Log( LOG_INFO, "Enabled link compression (zlib) on connection %d.", Idx );
Log(LOG_INFO, "Enabled link compression (zlib) on connection %d.", Idx);
Conn_OPTION_ADD( &My_Connections[Idx], CONN_ZIP );
return true;
@ -121,7 +113,7 @@ Zip_Buffer( CONN_ID Idx, const char *Data, size_t Len )
* Compress data in ZIP buffer and move result to the write buffer of
* the connection.
* @param Idx Connection handle.
* @retrun true on success, false otherwise.
* @return true on success, false otherwise.
*/
GLOBAL bool
Zip_Flush( CONN_ID Idx )
@ -184,13 +176,16 @@ Zip_Flush( CONN_ID Idx )
} /* Zip_Flush */
/**
* uncompress data and copy it to read buffer.
* Returns true if data has been unpacked or no
* compressed data is currently pending in the zread buffer.
* @param Idx Connection handle.
* @return true on success, false otherwise.
*/
GLOBAL bool
Unzip_Buffer( CONN_ID Idx )
{
/* Daten entpacken und in Lesepuffer kopieren. Bei Fehlern
* wird false geliefert, ansonsten true. Der Fall, dass keine
* Daten mehr zu entpacken sind, ist _kein_ Fehler! */
int result;
unsigned char unzipbuf[READBUFFER_LEN];
int unzipbuf_used = 0;
@ -221,8 +216,8 @@ Unzip_Buffer( CONN_ID Idx )
result = inflate( in, Z_SYNC_FLUSH );
if( result != Z_OK )
{
Log( LOG_ALERT, "Decompression error: %s (code=%d, ni=%d, ai=%d, no=%d, ao=%d)!?", in->msg, result, in->next_in, in->avail_in, in->next_out, in->avail_out );
Conn_Close( Idx, "Decompression error!", NULL, false );
Log(LOG_ALERT, "Decompression error: %s (code=%d, ni=%d, ai=%d, no=%d, ao=%d)!?", in->msg, result, in->next_in, in->avail_in, in->next_out, in->avail_out);
Conn_Close(Idx, "Decompression error!", NULL, false);
return false;
}
@ -249,21 +244,25 @@ Unzip_Buffer( CONN_ID Idx )
} /* Unzip_Buffer */
/**
* @param Idx Connection handle.
* @return amount of sent (compressed) bytes
*/
GLOBAL long
Zip_SendBytes( CONN_ID Idx )
{
/* Anzahl gesendeter Bytes (komprimiert!) liefern */
assert( Idx > NONE );
return My_Connections[Idx].zip.bytes_out;
} /* Zip_SendBytes */
/**
* @param Idx Connection handle.
* @return amount of received (compressed) bytes
*/
GLOBAL long
Zip_RecvBytes( CONN_ID Idx )
{
/* Anzahl gesendeter Bytes (komprimiert!) liefern */
assert( Idx > NONE );
return My_Connections[Idx].zip.bytes_in;
} /* Zip_RecvBytes */

View File

@ -304,8 +304,6 @@ cb_clientserver_ssl(int sock, short what)
GLOBAL void
Conn_Init( void )
{
/* Modul initialisieren: statische Strukturen "ausnullen". */
CONN_ID i;
/* Speicher fuer Verbindungs-Pool anfordern */
@ -341,9 +339,6 @@ Conn_Init( void )
GLOBAL void
Conn_Exit( void )
{
/* Modul abmelden: alle noch offenen Connections
* schliessen und freigeben. */
CONN_ID idx;
Conn_ExitListeners();
@ -1292,13 +1287,11 @@ New_Connection( int Sock )
static CONN_ID
Socket2Index( int Sock )
{
/* zum Socket passende Connection suchen */
assert( Sock >= 0 );
if( Sock >= Pool_Size || My_Connections[Sock].sock != Sock ) {
/* die Connection wurde vermutlich (wegen eines
* Fehlers) bereits wieder abgebaut ... */
/* the Connection was already closed again, likely due to
* an error. */
LogDebug("Socket2Index: can't get connection for socket %d!", Sock);
return NONE;
}

View File

@ -49,24 +49,23 @@ IRC_ADMIN(CLIENT *Client, REQUEST *Req )
assert( Client != NULL );
assert( Req != NULL );
/* Falsche Anzahl Parameter? */
if(( Req->argc > 1 )) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
/* Ziel suchen */
/* find target ... */
if( Req->argc == 1 ) target = Client_Search( Req->argv[0] );
else target = Client_ThisServer( );
/* Prefix ermitteln */
/* find Prefix */
if( Client_Type( Client ) == CLIENT_SERVER ) prefix = Client_Search( Req->prefix );
else prefix = Client;
if( ! prefix ) return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->prefix );
/* An anderen Server weiterleiten? */
/* forwad message to another server? */
if( target != Client_ThisServer( ))
{
if(( ! target ) || ( Client_Type( target ) != CLIENT_SERVER )) return IRC_WriteStrClient( prefix, ERR_NOSUCHSERVER_MSG, Client_ID( prefix ), Req->argv[0] );
/* forwarden */
/* forward */
IRC_WriteStrClientPrefix( target, prefix, "ADMIN %s", Req->argv[0] );
return CONNECTED;
}
@ -199,7 +198,6 @@ IRC_LINKS( CLIENT *Client, REQUEST *Req )
assert( Client != NULL );
assert( Req != NULL );
/* Falsche Anzahl Parameter? */
if(( Req->argc > 2 )) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
/* Server-Mask ermitteln */
@ -247,7 +245,6 @@ IRC_LUSERS( CLIENT *Client, REQUEST *Req )
assert( Client != NULL );
assert( Req != NULL );
/* Falsche Anzahl Parameter? */
if(( Req->argc > 2 )) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
/* Absender ermitteln */
@ -321,7 +318,6 @@ IRC_MOTD( CLIENT *Client, REQUEST *Req )
assert( Client != NULL );
assert( Req != NULL );
/* Falsche Anzahl Parameter? */
if( Req->argc > 1 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
/* From aus Prefix ermitteln */
@ -331,7 +327,7 @@ IRC_MOTD( CLIENT *Client, REQUEST *Req )
if( Req->argc == 1 )
{
/* an anderen Server forwarden */
/* forward? */
target = Client_Search( Req->argv[0] );
if(( ! target ) || ( Client_Type( target ) != CLIENT_SERVER )) return IRC_WriteStrClient( from, ERR_NOSUCHSERVER_MSG, Client_ID( from ), Req->argv[0] );
@ -357,23 +353,21 @@ IRC_NAMES( CLIENT *Client, REQUEST *Req )
assert( Client != NULL );
assert( Req != NULL );
/* Falsche Anzahl Parameter? */
if( Req->argc > 2 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
/* From aus Prefix ermitteln */
/* use prefix to determine "From" */
if( Client_Type( Client ) == CLIENT_SERVER ) from = Client_Search( Req->prefix );
else from = Client;
if( ! from ) return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->prefix );
if( Req->argc == 2 )
{
/* an anderen Server forwarden */
/* forward to another server? */
target = Client_Search( Req->argv[1] );
if(( ! target ) || ( Client_Type( target ) != CLIENT_SERVER )) return IRC_WriteStrClient( from, ERR_NOSUCHSERVER_MSG, Client_ID( from ), Req->argv[1] );
if( target != Client_ThisServer( ))
{
/* Ok, anderer Server ist das Ziel: forwarden */
if( target != Client_ThisServer( )) {
/* target is another server, forward */
return IRC_WriteStrClientPrefix( target, from, "NAMES %s :%s", Req->argv[0], Req->argv[1] );
}
}
@ -387,53 +381,48 @@ IRC_NAMES( CLIENT *Client, REQUEST *Req )
chan = Channel_Search( ptr );
if( chan )
{
/* Namen ausgeben */
/* print name */
if( ! IRC_Send_NAMES( from, chan )) return DISCONNECTED;
}
if( ! IRC_WriteStrClient( from, RPL_ENDOFNAMES_MSG, Client_ID( from ), ptr )) return DISCONNECTED;
/* naechsten Namen ermitteln */
/* get next channel name */
ptr = strtok( NULL, "," );
}
return CONNECTED;
}
/* alle Channels durchgehen */
chan = Channel_First( );
while( chan )
{
/* Namen ausgeben */
if( ! IRC_Send_NAMES( from, chan )) return DISCONNECTED;
/* naechster Channel */
chan = Channel_Next( chan );
}
/* Nun noch alle Clients ausgeben, die in keinem Channel sind */
/* Now print all clients which are not in any channel */
c = Client_First( );
snprintf( rpl, sizeof( rpl ), RPL_NAMREPLY_MSG, Client_ID( from ), "*", "*" );
while( c )
{
if(( Client_Type( c ) == CLIENT_USER ) && ( Channel_FirstChannelOf( c ) == NULL ) && ( ! strchr( Client_Modes( c ), 'i' )))
{
/* Okay, das ist ein User: anhaengen */
/* its a user, concatenate ... */
if( rpl[strlen( rpl ) - 1] != ':' ) strlcat( rpl, " ", sizeof( rpl ));
strlcat( rpl, Client_ID( c ), sizeof( rpl ));
if( strlen( rpl ) > ( LINE_LEN - CLIENT_NICK_LEN - 4 ))
{
/* Zeile wird zu lang: senden! */
/* Line is gwoing too long, send now */
if( ! IRC_WriteStrClient( from, "%s", rpl )) return DISCONNECTED;
snprintf( rpl, sizeof( rpl ), RPL_NAMREPLY_MSG, Client_ID( from ), "*", "*" );
}
}
/* naechster Client */
c = Client_Next( c );
}
if( rpl[strlen( rpl ) - 1] != ':')
{
/* es wurden User gefunden */
if( ! IRC_WriteStrClient( from, "%s", rpl )) return DISCONNECTED;
}
@ -489,11 +478,10 @@ IRC_STATS( CLIENT *Client, REQUEST *Req )
assert( Client != NULL );
assert( Req != NULL );
/* Falsche Anzahl Parameter? */
if (Req->argc > 2)
return IRC_WriteStrClient(Client, ERR_NEEDMOREPARAMS_MSG, Client_ID(Client), Req->command);
/* From aus Prefix ermitteln */
/* use prefix to determine "From" */
if (Client_Type(Client) == CLIENT_SERVER)
from = Client_Search(Req->prefix);
else
@ -503,13 +491,13 @@ IRC_STATS( CLIENT *Client, REQUEST *Req )
return IRC_WriteStrClient(Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->prefix);
if (Req->argc == 2) {
/* an anderen Server forwarden */
/* forward to another server? */
target = Client_Search( Req->argv[1] );
if(( ! target ) || ( Client_Type( target ) != CLIENT_SERVER ))
return IRC_WriteStrClient( from, ERR_NOSUCHSERVER_MSG, Client_ID( from ), Req->argv[1] );
if( target != Client_ThisServer()) {
/* Ok, anderer Server ist das Ziel: forwarden */
/* forward to another server */
return IRC_WriteStrClientPrefix( target, from, "STATS %s %s", Req->argv[0], Req->argv[1] );
}
}
@ -597,23 +585,19 @@ IRC_TIME( CLIENT *Client, REQUEST *Req )
assert( Client != NULL );
assert( Req != NULL );
/* Falsche Anzahl Parameter? */
if( Req->argc > 1 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
/* From aus Prefix ermitteln */
if( Client_Type( Client ) == CLIENT_SERVER ) from = Client_Search( Req->prefix );
else from = Client;
if( ! from ) return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->prefix );
if( Req->argc == 1 )
{
/* an anderen Server forwarden */
target = Client_Search( Req->argv[0] );
if(( ! target ) || ( Client_Type( target ) != CLIENT_SERVER )) return IRC_WriteStrClient( Client, ERR_NOSUCHSERVER_MSG, Client_ID( Client ), Req->argv[0] );
if( target != Client_ThisServer( ))
{
/* Ok, anderer Server ist das Ziel: forwarden */
return IRC_WriteStrClientPrefix( target, from, "TIME %s", Req->argv[0] );
}
}
@ -634,7 +618,6 @@ IRC_USERHOST( CLIENT *Client, REQUEST *Req )
assert( Client != NULL );
assert( Req != NULL );
/* Falsche Anzahl Parameter? */
if(( Req->argc < 1 )) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
if( Req->argc > 5 ) max = 5;
@ -646,7 +629,7 @@ IRC_USERHOST( CLIENT *Client, REQUEST *Req )
c = Client_Search( Req->argv[i] );
if( c && ( Client_Type( c ) == CLIENT_USER ))
{
/* Dieser Nick ist "online" */
/* This Nick is "online" */
strlcat( rpl, Client_ID( c ), sizeof( rpl ));
if( Client_HasMode( c, 'o' )) strlcat( rpl, "*", sizeof( rpl ));
strlcat( rpl, "=", sizeof( rpl ));
@ -684,7 +667,6 @@ IRC_VERSION( CLIENT *Client, REQUEST *Req )
assert( Client != NULL );
assert( Req != NULL );
/* Falsche Anzahl Parameter? */
if(( Req->argc > 1 )) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
/* Ziel suchen */

View File

@ -322,18 +322,18 @@ IRC_NICK( CLIENT *Client, REQUEST *Req )
info = Req->argv[0];
}
/* Nick ueberpruefen */
c = Client_Search(nick);
if(c) {
/* Der neue Nick ist auf diesem Server bereits registriert:
* sowohl der neue, als auch der alte Client muessen nun
* disconnectiert werden. */
/*
* the new nick is already present on this server:
* the new and the old one have to be disconnected now.
*/
Log( LOG_ERR, "Server %s introduces already registered nick \"%s\"!", Client_ID( Client ), Req->argv[0] );
Kill_Nick( Req->argv[0], "Nick collision" );
return CONNECTED;
}
/* Server, zu dem der Client connectiert ist, suchen */
/* Find the Server this client is connected to */
intr_c = Client_GetFromToken(Client, token);
if( ! intr_c )
{
@ -342,14 +342,11 @@ IRC_NICK( CLIENT *Client, REQUEST *Req )
return CONNECTED;
}
/* Neue Client-Struktur anlegen */
c = Client_NewRemoteUser(intr_c, nick, hops, user, hostname,
token, modes, info, true);
if( ! c )
{
/* Eine neue Client-Struktur konnte nicht angelegt werden.
* Der Client muss disconnectiert werden, damit der Netz-
* status konsistent bleibt. */
/* out of memory, need to disconnect client to keep network state consistent */
Log( LOG_ALERT, "Can't create client structure! (on connection %d)", Client_Conn( Client ));
Kill_Nick( Req->argv[0], "Server error" );
return CONNECTED;
@ -583,7 +580,6 @@ IRC_QUIT( CLIENT *Client, REQUEST *Req )
target = Client_Search( Req->prefix );
if( ! target )
{
/* Den Client kennen wir nicht (mehr), also nichts zu tun. */
Log( LOG_WARNING, "Got QUIT from %s for unknown client!?", Client_ID( Client ));
return CONNECTED;
}
@ -601,7 +597,7 @@ IRC_QUIT( CLIENT *Client, REQUEST *Req )
strlcat(quitmsg, "\"", sizeof quitmsg );
}
/* User, Service, oder noch nicht registriert */
/* User, Service, or not yet registered */
Conn_Close( Client_Conn( Client ), "Got QUIT command.", Req->argc == 1 ? quitmsg : NULL, true);
return DISCONNECTED;
@ -617,7 +613,6 @@ IRC_PING(CLIENT *Client, REQUEST *Req)
assert(Client != NULL);
assert(Req != NULL);
/* Wrong number of arguments? */
if (Req->argc < 1)
return IRC_WriteStrClient(Client, ERR_NOORIGIN_MSG,
Client_ID(Client));

View File

@ -671,12 +671,10 @@ IRC_AWAY( CLIENT *Client, REQUEST *Req )
assert( Client != NULL );
assert( Req != NULL );
/* Falsche Anzahl Parameter? */
if( Req->argc > 1 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
if(( Req->argc == 1 ) && (Req->argv[0][0] ))
{
/* AWAY setzen */
Client_SetAway( Client, Req->argv[0] );
Client_ModeAdd( Client, 'a' );
IRC_WriteStrServersPrefix( Client, Client, "MODE %s :+a", Client_ID( Client ));
@ -684,7 +682,6 @@ IRC_AWAY( CLIENT *Client, REQUEST *Req )
}
else
{
/* AWAY loeschen */
Client_ModeDel( Client, 'a' );
IRC_WriteStrServersPrefix( Client, Client, "MODE %s :-a", Client_ID( Client ));
return IRC_WriteStrClient( Client, RPL_UNAWAY_MSG, Client_ID( Client ));
@ -752,21 +749,19 @@ Del_Ban_Invite(int what, CLIENT *Prefix, CLIENT *Client, CHANNEL *Channel, const
static bool
Send_ListChange( char *Mode, CLIENT *Prefix, CLIENT *Client, CHANNEL *Channel, const char *Mask )
{
/* Bestaetigung an Client schicken & andere Server sowie Channel-User informieren */
bool ok;
if( Client_Type( Client ) == CLIENT_USER )
{
/* Bestaetigung an Client */
/* send confirmation to client */
ok = IRC_WriteStrClientPrefix( Client, Prefix, "MODE %s %s %s", Channel_Name( Channel ), Mode, Mask );
}
else ok = true;
/* an andere Server */
/* to other servers */
IRC_WriteStrServersPrefix( Client, Prefix, "MODE %s %s %s", Channel_Name( Channel ), Mode, Mask );
/* und lokale User im Channel */
/* and local users in channel */
IRC_WriteStrChannelPrefix( Client, Channel, Prefix, false, "MODE %s %s %s", Channel_Name( Channel ), Mode, Mask );
return ok;

View File

@ -14,8 +14,6 @@
#include "portab.h"
static char UNUSED id[] = "$Id: irc-oper.c,v 1.29 2007/08/02 10:14:26 fw Exp $";
#include "imp.h"
#include <assert.h>
#include <stdlib.h>
@ -55,10 +53,8 @@ IRC_OPER( CLIENT *Client, REQUEST *Req )
assert( Client != NULL );
assert( Req != NULL );
/* Falsche Anzahl Parameter? */
if( Req->argc != 2 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
/* Operator suchen */
for( i = 0; i < Conf_Oper_Count; i++)
{
if( Conf_Oper[i].name[0] && Conf_Oper[i].pwd[0] && ( strcmp( Conf_Oper[i].name, Req->argv[0] ) == 0 )) break;
@ -66,17 +62,14 @@ IRC_OPER( CLIENT *Client, REQUEST *Req )
if( i >= Conf_Oper_Count )
return Bad_OperPass(Client, Req->argv[0], "not configured");
/* Stimmt das Passwort? */
if( strcmp( Conf_Oper[i].pwd, Req->argv[1] ) != 0 )
return Bad_OperPass(Client, Conf_Oper[i].name, "Bad password");
/* Authorized Mask? */
if( Conf_Oper[i].mask && (! Match( Conf_Oper[i].mask, Client_Mask( Client ) )))
return Bad_OperPass(Client, Conf_Oper[i].mask, "hostmask check failed" );
if( ! Client_HasMode( Client, 'o' ))
{
/* noch kein o-Mode gesetzt */
Client_ModeAdd( Client, 'o' );
if( ! IRC_WriteStrClient( Client, "MODE %s :+o", Client_ID( Client ))) return DISCONNECTED;
IRC_WriteStrServersPrefix( NULL, Client, "MODE %s :+o", Client_ID( Client ));

View File

@ -70,40 +70,37 @@ IRC_SERVER( CLIENT *Client, REQUEST *Req )
LogDebug("Connection %d: got SERVER command (new server link) ...",
Client_Conn(Client));
/* Falsche Anzahl Parameter? */
if(( Req->argc != 2 ) && ( Req->argc != 3 )) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
/* Ist dieser Server bei uns konfiguriert? */
/* Ist this server configured on out side? */
for( i = 0; i < MAX_SERVERS; i++ ) if( strcasecmp( Req->argv[0], Conf_Server[i].name ) == 0 ) break;
if( i >= MAX_SERVERS )
{
/* Server ist nicht konfiguriert! */
Log( LOG_ERR, "Connection %d: Server \"%s\" not configured here!", Client_Conn( Client ), Req->argv[0] );
Conn_Close( Client_Conn( Client ), NULL, "Server not configured here", true);
return DISCONNECTED;
}
if( strcmp( Client_Password( Client ), Conf_Server[i].pwd_in ) != 0 )
{
/* Falsches Passwort */
/* wrong password */
Log( LOG_ERR, "Connection %d: Got bad password from server \"%s\"!", Client_Conn( Client ), Req->argv[0] );
Conn_Close( Client_Conn( Client ), NULL, "Bad password", true);
return DISCONNECTED;
}
/* Ist ein Server mit dieser ID bereits registriert? */
/* Is there a registered server with this ID? */
if( ! Client_CheckID( Client, Req->argv[0] )) return DISCONNECTED;
/* Server-Strukturen fuellen ;-) */
Client_SetID( Client, Req->argv[0] );
Client_SetHops( Client, 1 );
Client_SetInfo( Client, Req->argv[Req->argc - 1] );
/* Meldet sich der Server bei uns an (d.h., bauen nicht wir
* selber die Verbindung zu einem anderen Server auf)? */
/* Is this server registering on our side, or are we connecting to
* a remote server? */
con = Client_Conn( Client );
if( Client_Token( Client ) != TOKEN_OUTBOUND )
{
/* Eingehende Verbindung: Unseren SERVER- und PASS-Befehl senden */
/* Incoming connection, send user/pass */
ok = true;
if( ! IRC_WriteStrClient( Client, "PASS %s %s", Conf_Server[i].pwd_out, NGIRCd_ProtoID )) ok = false;
else ok = IRC_WriteStrClient( Client, "SERVER %s 1 :%s", Conf_ServerName, Conf_ServerInfo );
@ -117,8 +114,7 @@ IRC_SERVER( CLIENT *Client, REQUEST *Req )
}
else
{
/* Ausgehende verbindung, SERVER und PASS wurden von uns bereits
* an die Gegenseite uerbermittelt */
/* outgoing connect, we already sent SERVER and PASS to the peer */
Client_SetToken( Client, atoi( Req->argv[1] ));
}
@ -139,15 +135,9 @@ IRC_SERVER( CLIENT *Client, REQUEST *Req )
Client_SetType(Client, CLIENT_UNKNOWNSERVER);
#ifdef ZLIB
/* Kompression initialisieren, wenn erforderlich */
if( strchr( Client_Flags( Client ), 'Z' ))
{
if( ! Zip_InitConn( con ))
{
/* Fehler! */
Conn_Close( con, "Can't inizialize compression (zlib)!", NULL, false );
return DISCONNECTED;
}
if (strchr(Client_Flags(Client), 'Z') && !Zip_InitConn(con)) {
Conn_Close( con, "Can't inizialize compression (zlib)!", NULL, false );
return DISCONNECTED;
}
#endif
@ -171,43 +161,38 @@ IRC_SERVER( CLIENT *Client, REQUEST *Req )
}
else if( Client_Type( Client ) == CLIENT_SERVER )
{
/* Neuer Server wird im Netz angekuendigt */
/* New server is being introduced to the network */
/* Falsche Anzahl Parameter? */
if( Req->argc != 4 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
/* Ist ein Server mit dieser ID bereits registriert? */
/* check for existing server with same ID */
if( ! Client_CheckID( Client, Req->argv[0] )) return DISCONNECTED;
/* Ueberfluessige Hostnamen aus Info-Text entfernen */
/* remove superfluous hostnames from Info-Text */
ptr = strchr( Req->argv[3] + 2, '[' );
if( ! ptr ) ptr = Req->argv[3];
from = Client_Search( Req->prefix );
if( ! from )
{
/* Hm, Server, der diesen einfuehrt, ist nicht bekannt!? */
/* Uh, Server, that introduced the new server is unknown?! */
Log( LOG_ALERT, "Unknown ID in prefix of SERVER: \"%s\"! (on connection %d)", Req->prefix, Client_Conn( Client ));
Conn_Close( Client_Conn( Client ), NULL, "Unknown ID in prefix of SERVER", true);
return DISCONNECTED;
}
/* Neue Client-Struktur anlegen */
c = Client_NewRemoteServer( Client, Req->argv[0], from, atoi( Req->argv[1] ), atoi( Req->argv[2] ), ptr, true);
if( ! c )
{
/* Neue Client-Struktur konnte nicht angelegt werden */
if (!c) {
Log( LOG_ALERT, "Can't create client structure for server! (on connection %d)", Client_Conn( Client ));
Conn_Close( Client_Conn( Client ), NULL, "Can't allocate client structure for remote server", true);
return DISCONNECTED;
}
/* Log-Meldung zusammenbauen und ausgeben */
if(( Client_Hops( c ) > 1 ) && ( Req->prefix[0] )) snprintf( str, sizeof( str ), "connected to %s, ", Client_ID( from ));
else strcpy( str, "" );
Log( LOG_NOTICE|LOG_snotice, "Server \"%s\" registered (via %s, %s%d hop%s).", Client_ID( c ), Client_ID( Client ), str, Client_Hops( c ), Client_Hops( c ) > 1 ? "s": "" );
/* Andere Server informieren */
/* notify other servers */
IRC_WriteStrServersPrefix( Client, from, "SERVER %s %d %d :%s", Client_ID( c ), Client_Hops( c ) + 1, Client_MyToken( c ), Client_Info( c ));
return CONNECTED;
@ -228,7 +213,6 @@ IRC_NJOIN( CLIENT *Client, REQUEST *Req )
assert( Client != NULL );
assert( Req != NULL );
/* Falsche Anzahl Parameter? */
if( Req->argc != 2 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
strlcpy( nick_in, Req->argv[1], sizeof( nick_in ));
@ -240,7 +224,7 @@ IRC_NJOIN( CLIENT *Client, REQUEST *Req )
{
is_op = is_voiced = false;
/* Prefixe abschneiden */
/* cut off prefixes */
while(( *ptr == '@' ) || ( *ptr == '+' ))
{
if( *ptr == '@' ) is_op = true;
@ -258,14 +242,14 @@ IRC_NJOIN( CLIENT *Client, REQUEST *Req )
if( is_op ) Channel_UserModeAdd( chan, c, 'o' );
if( is_voiced ) Channel_UserModeAdd( chan, c, 'v' );
/* im Channel bekannt machen */
/* announce to channel... */
IRC_WriteStrChannelPrefix( Client, chan, c, false, "JOIN :%s", channame );
/* Channel-User-Modes setzen */
/* set Channel-User-Modes */
strlcpy( modes, Channel_UserModes( chan, c ), sizeof( modes ));
if( modes[0] )
{
/* Modes im Channel bekannt machen */
/* send modes to channel */
IRC_WriteStrChannelPrefix( Client, chan, Client, false, "MODE %s +%s %s", channame, modes, Client_ID( c ));
}
@ -276,11 +260,11 @@ IRC_NJOIN( CLIENT *Client, REQUEST *Req )
}
else Log( LOG_ERR, "Got NJOIN for unknown nick \"%s\" for channel \"%s\"!", ptr, channame );
/* naechsten Nick suchen */
/* search for next Nick */
ptr = strtok( NULL, "," );
}
/* an andere Server weiterleiten */
/* forward to other servers */
if( nick_out[0] != '\0' ) IRC_WriteStrServersPrefix( Client, Client_ThisServer( ), "NJOIN %s :%s", Req->argv[0], nick_out );
return CONNECTED;
@ -296,7 +280,6 @@ IRC_SQUIT( CLIENT *Client, REQUEST *Req )
assert( Client != NULL );
assert( Req != NULL );
/* Falsche Anzahl Parameter? */
if( Req->argc != 2 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
Log( LOG_DEBUG, "Got SQUIT from %s for \"%s\": \"%s\" ...", Client_ID( Client ), Req->argv[0], Req->argv[1] );
@ -304,7 +287,6 @@ IRC_SQUIT( CLIENT *Client, REQUEST *Req )
target = Client_Search( Req->argv[0] );
if( ! target )
{
/* Den Server kennen wir nicht (mehr), also nichts zu tun. */
Log( LOG_WARNING, "Got SQUIT from %s for unknown server \"%s\"!?", Client_ID( Client ), Req->argv[0] );
return CONNECTED;
}
@ -318,18 +300,17 @@ IRC_SQUIT( CLIENT *Client, REQUEST *Req )
if( Client_Conn( target ) > NONE )
{
/* dieser Server hat die Connection */
/* This server has the connection */
if( Req->argv[1][0] ) Conn_Close( Client_Conn( target ), msg, Req->argv[1], true);
else Conn_Close( Client_Conn( target ), msg, NULL, true);
return DISCONNECTED;
}
else
{
/* Verbindung hielt anderer Server */
/* connection was on another server */
Client_Destroy( target, msg, Req->argv[1], false );
return CONNECTED;
}
} /* IRC_SQUIT */
/* -eof- */

View File

@ -14,8 +14,6 @@
#include "portab.h"
static char UNUSED id[] = "$Id: irc-write.c,v 1.21 2006/08/12 11:56:24 fw Exp $";
#include "imp.h"
#include <assert.h>
#ifdef PROTOTYPES
@ -70,7 +68,7 @@ va_dcl
vsnprintf( buffer, 1000, Format, ap );
va_end( ap );
/* an den Client selber */
/* to the client itself */
ok = IRC_WriteStrClientPrefix( Client, Client_ThisServer( ), "%s", buffer );
return ok;
@ -89,7 +87,7 @@ char *Format;
va_dcl
#endif
{
/* Text an Clients, lokal bzw. remote, senden. */
/* send text to local and remote clients */
char buffer[1000];
va_list ap;
@ -141,6 +139,11 @@ va_dcl
} /* IRC_WriteStrChannel */
/**
* send message to all clients in the same channel, but only send message
* once per remote server.
*/
#ifdef PROTOTYPES
GLOBAL bool
IRC_WriteStrChannelPrefix( CLIENT *Client, CHANNEL *Chan, CLIENT *Prefix, bool Remote, char *Format, ... )
@ -177,8 +180,6 @@ va_dcl
Conn_ClearFlags( );
/* An alle Clients, die in den selben Channels sind.
* Dabei aber nur einmal je Remote-Server */
cl2chan = Channel_FirstMember( Chan );
while( cl2chan )
{
@ -192,7 +193,7 @@ va_dcl
if( c && ( c != Client ))
{
/* Ok, anderer Client */
/* Ok, another Client */
conn = Client_Conn( c );
if( Client_Type( c ) == CLIENT_SERVER ) Conn_SetFlag( conn, SEND_TO_SERVER );
else Conn_SetFlag( conn, SEND_TO_USER );
@ -200,16 +201,14 @@ va_dcl
cl2chan = Channel_NextMember( Chan, cl2chan );
}
/* Senden: alle Verbindungen durchgehen ... */
conn = Conn_First( );
while( conn != NONE )
{
/* muessen Daten ueber diese Verbindung verschickt werden? */
/* do we need to send data via this connection? */
if( Conn_Flag( conn ) == SEND_TO_SERVER) ok = Conn_WriteStr( conn, ":%s %s", Client_ID( Prefix ), buffer );
else if( Conn_Flag( conn ) == SEND_TO_USER ) ok = Conn_WriteStr( conn, ":%s %s", Client_Mask( Prefix ), buffer );
if( ! ok ) break;
/* naechste Verbindung testen */
conn = Conn_Next( conn );
}
@ -241,7 +240,6 @@ va_dcl
vsnprintf( buffer, 1000, Format, ap );
va_end( ap );
/* an den Client selber */
IRC_WriteStrServersPrefix( ExceptOf, Client_ThisServer( ), "%s", buffer );
} /* IRC_WriteStrServers */
@ -327,6 +325,10 @@ IRC_WriteStrServersPrefixFlag_CB(CLIENT *ExceptOf, CLIENT *Prefix, char Flag,
} /* IRC_WriteStrServersPrefixFlag */
/**
* send message to all clients that are in the same channels as the client sending this message.
* only send message once per reote server.
*/
#ifdef PROTOTYPES
GLOBAL bool
IRC_WriteStrRelatedPrefix( CLIENT *Client, CLIENT *Prefix, bool Remote, char *Format, ... )
@ -360,15 +362,11 @@ va_dcl
vsnprintf( buffer, 1000, Format, ap );
va_end( ap );
/* initialisieren */
Conn_ClearFlags( );
/* An alle Clients, die in einem Channel mit dem "Ausloeser" sind,
* den Text schicken. An Remote-Server aber jeweils nur einmal. */
chan_cl2chan = Channel_FirstChannelOf( Client );
while( chan_cl2chan )
{
/* Channel des Users durchsuchen */
chan = Channel_GetChannel( chan_cl2chan );
cl2chan = Channel_FirstMember( chan );
while( cl2chan )
@ -383,7 +381,6 @@ va_dcl
if( c && ( c != Client ))
{
/* Ok, anderer Client */
conn = Client_Conn( c );
if( Client_Type( c ) == CLIENT_SERVER ) Conn_SetFlag( conn, SEND_TO_SERVER );
else Conn_SetFlag( conn, SEND_TO_USER );
@ -391,20 +388,17 @@ va_dcl
cl2chan = Channel_NextMember( chan, cl2chan );
}
/* naechsten Channel */
chan_cl2chan = Channel_NextChannelOf( Client, chan_cl2chan );
}
/* Senden: alle Verbindungen durchgehen ... */
conn = Conn_First( );
while( conn != NONE )
{
/* muessen ueber diese Verbindung Daten gesendet werden? */
/* send data via this connection? */
if( Conn_Flag( conn ) == SEND_TO_SERVER ) ok = Conn_WriteStr( conn, ":%s %s", Client_ID( Prefix ), buffer );
else if( Conn_Flag( conn ) == SEND_TO_USER ) ok = Conn_WriteStr( conn, ":%s %s", Client_Mask( Prefix ), buffer );
if( ! ok ) break;
/* naechste Verbindung testen */
conn = Conn_Next( conn );
}
return ok;

View File

@ -81,14 +81,12 @@ Log_Init( bool Daemon_Mode )
#ifndef LOG_LOCAL5
#define LOG_LOCAL5 0
#endif
/* Syslog initialisieren */
openlog( PACKAGE_NAME, LOG_CONS|LOG_PID, LOG_LOCAL5 );
#endif
/* Hello World! */
Log( LOG_NOTICE, "%s started.", NGIRCd_Version );
/* Informationen uebern den "Operation Mode" */
/* Information about "Operation Mode" */
Init_Txt[0] = '\0';
#ifdef DEBUG
if( NGIRCd_Debug )
@ -122,17 +120,11 @@ Log_Init( bool Daemon_Mode )
#ifdef DEBUG
GLOBAL void
Log_InitErrorfile( void )
{
/* "Error-Log" initialisieren: stderr in Datei umlenken. Dort
* landen z.B. alle Ausgaben von assert()-Aufrufen. */
/* Dateiname zusammen bauen */
snprintf( Error_File, sizeof Error_File, "%s/%s-%ld.err", ERROR_DIR, PACKAGE_NAME, (long)getpid( ));
/* stderr umlenken */
fflush( stderr );
if( ! freopen( Error_File, "w", stderr ))
{
@ -140,17 +132,13 @@ Log_InitErrorfile( void )
return;
}
/* Einige Infos in das Error-File schreiben */
fputs( ctime( &NGIRCd_Start ), stderr );
fprintf( stderr, "%s started.\n", NGIRCd_Version );
fprintf( stderr, "Activating: %s\n\n", Init_Txt[0] ? Init_Txt : "-" );
fflush( stderr );
#ifdef DEBUG
Log( LOG_DEBUG, "Redirected stderr to \"%s\".", Error_File );
#endif
Log(LOG_DEBUG, "Redirected stderr to \"%s\".", Error_File);
} /* Log_InitErrfile */
#endif
@ -170,8 +158,7 @@ Log_Exit( void )
#endif
#ifdef SYSLOG
/* syslog abmelden */
closelog( );
closelog();
#endif
} /* Log_Exit */

View File

@ -110,14 +110,13 @@ main( int argc, const char *argv[] )
Fill_Version( );
/* Kommandozeile parsen */
/* parse conmmand line */
for( i = 1; i < argc; i++ )
{
ok = false;
if(( argv[i][0] == '-' ) && ( argv[i][1] == '-' ))
{
/* Lange Option */
/* long option */
if( strcmp( argv[i], "--config" ) == 0 )
{
if( i + 1 < argc )
@ -172,7 +171,7 @@ main( int argc, const char *argv[] )
}
else if(( argv[i][0] == '-' ) && ( argv[i][1] != '-' ))
{
/* Kurze Option */
/* short option */
for( n = 1; n < strlen( argv[i] ); n++ )
{
ok = false;
@ -241,7 +240,7 @@ main( int argc, const char *argv[] )
}
}
/* Debug-Level (fuer IRC-Befehl "VERSION") ermitteln */
/* Debug-Level (for IRCs "VERSION" command) */
NGIRCd_DebugLevel[0] = '\0';
#ifdef DEBUG
if( NGIRCd_Debug ) strcpy( NGIRCd_DebugLevel, "1" );
@ -254,7 +253,6 @@ main( int argc, const char *argv[] )
}
#endif
/* Soll nur die Konfigurations ueberprueft und ausgegeben werden? */
if( configtest )
{
Show_Version( ); puts( "" );
@ -297,12 +295,13 @@ main( int argc, const char *argv[] )
if( ! NGIRCd_NoDaemon ) Log_InitErrorfile( );
#endif
/* Signal-Handler initialisieren */
Initialize_Signal_Handler( );
/* Protokoll- und Server-Identifikation erzeugen. Die vom ngIRCd
* beim PASS-Befehl verwendete Syntax sowie die erweiterten Flags
* sind in doc/Protocol.txt beschrieben. */
/*
* create protocol and server identification.
* The syntax used by ngIRCd in PASS commands and the extended flags
* are described in doc/Protocol.txt
*/
#ifdef IRCPLUS
snprintf( NGIRCd_ProtoID, sizeof NGIRCd_ProtoID, "%s%s %s|%s:%s", PROTOVER, PROTOIRCPLUS, PACKAGE_NAME, PACKAGE_VERSION, IRCPLUSFLAGS );
#ifdef ZLIB
@ -318,10 +317,8 @@ main( int argc, const char *argv[] )
#endif
LogDebug("Protocol and server ID is \"%s\".", NGIRCd_ProtoID);
/* Vordefinierte Channels anlegen */
Channel_InitPredefined( );
/* Listen-Ports initialisieren */
if( Conn_InitListeners( ) < 1 )
{
Log( LOG_ALERT, "Server isn't listening on a single port!" );
@ -490,15 +487,9 @@ NGIRCd_Rehash( void )
static void
Initialize_Signal_Handler( void )
{
/* Signal-Handler initialisieren: einige Signale
* werden ignoriert, andere speziell behandelt. */
#ifdef HAVE_SIGACTION
/* sigaction() ist vorhanden */
struct sigaction saction;
/* Signal-Struktur initialisieren */
memset( &saction, 0, sizeof( saction ));
saction.sa_handler = Signal_Handler;
#ifdef SA_RESTART
@ -508,27 +499,22 @@ Initialize_Signal_Handler( void )
saction.sa_flags |= SA_NOCLDWAIT;
#endif
/* Signal-Handler einhaengen */
sigaction(SIGINT, &saction, NULL);
sigaction(SIGQUIT, &saction, NULL);
sigaction(SIGTERM, &saction, NULL);
sigaction(SIGHUP, &saction, NULL);
sigaction(SIGCHLD, &saction, NULL);
/* einige Signale ignorieren */
/* we handle write errors properly; ignore SIGPIPE */
saction.sa_handler = SIG_IGN;
sigaction(SIGPIPE, &saction, NULL);
#else
/* kein sigaction() vorhanden */
/* Signal-Handler einhaengen */
signal(SIGINT, Signal_Handler);
signal(SIGQUIT, Signal_Handler);
signal(SIGTERM, Signal_Handler);
signal(SIGHUP, Signal_Handler);
signal(SIGCHLD, Signal_Handler);
/* einige Signale ignorieren */
signal(SIGPIPE, SIG_IGN);
#endif
} /* Initialize_Signal_Handler */
@ -548,16 +534,17 @@ Signal_Handler( int Signal )
case SIGTERM:
case SIGINT:
case SIGQUIT:
/* wir soll(t)en uns wohl beenden ... */
/* shut down sever */
NGIRCd_SignalQuit = true;
break;
case SIGHUP:
/* Konfiguration neu einlesen: */
/* re-read configuration */
NGIRCd_SignalRehash = true;
break;
case SIGCHLD:
/* Child-Prozess wurde beendet. Zombies vermeiden: */
while( waitpid( -1, NULL, WNOHANG ) > 0);
/* child-process exited, avoid zombies */
while (waitpid( -1, NULL, WNOHANG) > 0)
;
break;
#ifdef DEBUG
default:

View File

@ -169,13 +169,12 @@ Parse_Request( CONN_ID Idx, char *Request )
Init_Request( &req );
/* Fuehrendes und folgendes "Geraffel" verwerfen */
/* remove leading & trailing whitespace */
ngt_TrimStr( Request );
/* gibt es ein Prefix? */
if( Request[0] == ':' )
{
/* Prefix vorhanden */
/* Prefix */
req.prefix = Request + 1;
ptr = strchr( Request, ' ' );
if( ! ptr )
@ -185,35 +184,30 @@ Parse_Request( CONN_ID Idx, char *Request )
}
*ptr = '\0';
#ifndef STRICT_RFC
/* multiple Leerzeichen als Trenner zwischen
* Prefix und Befehl ignorieren */
/* ignore multiple spaces between prefix and command */
while( *(ptr + 1) == ' ' ) ptr++;
#endif
start = ptr + 1;
}
else start = Request;
/* Befehl */
ptr = strchr( start, ' ' );
if( ptr )
{
*ptr = '\0';
#ifndef STRICT_RFC
/* multiple Leerzeichen als Trenner vor
* Parametern ignorieren */
/* ignore multiple spaces between parameters */
while( *(ptr + 1) == ' ' ) ptr++;
#endif
}
req.command = start;
/* Argumente, Parameter */
/* Arguments, Parameters */
if( ptr )
{
/* Prinzipiell gibt es welche :-) */
start = ptr + 1;
while( start )
{
/* Parameter-String "zerlegen" */
if( start[0] == ':' )
{
req.argv[req.argc] = start + 1;
@ -227,8 +221,6 @@ Parse_Request( CONN_ID Idx, char *Request )
{
*ptr = '\0';
#ifndef STRICT_RFC
/* multiple Leerzeichen als
* Parametertrenner ignorieren */
while( *(ptr + 1) == ' ' ) ptr++;
#endif
}
@ -244,7 +236,6 @@ Parse_Request( CONN_ID Idx, char *Request )
}
}
/* Daten validieren */
if( ! Validate_Prefix( Idx, &req, &closed )) return ! closed;
if( ! Validate_Command( Idx, &req, &closed )) return ! closed;
if( ! Validate_Args( Idx, &req, &closed )) return ! closed;
@ -283,39 +274,32 @@ Validate_Prefix( CONN_ID Idx, REQUEST *Req, bool *Closed )
*Closed = false;
/* ist ueberhaupt ein Prefix vorhanden? */
if( ! Req->prefix ) return true;
/* Client-Struktur der Connection ermitteln */
client = Conn_GetClient( Idx );
assert( client != NULL );
/* nur validieren, wenn bereits registrierte Verbindung */
/* only validate if this connection is already registered */
if(( Client_Type( client ) != CLIENT_USER ) && ( Client_Type( client ) != CLIENT_SERVER ) && ( Client_Type( client ) != CLIENT_SERVICE ))
{
/* noch nicht registrierte Verbindung.
* Das Prefix wird ignoriert. */
/* not registered, ignore prefix */
Req->prefix = NULL;
return true;
}
/* pruefen, ob der im Prefix angegebene Client bekannt ist */
/* check if client in prefix is known */
c = Client_Search( Req->prefix );
if( ! c )
{
/* im Prefix angegebener Client ist nicht bekannt */
Log( LOG_ERR, "Invalid prefix \"%s\", client not known (connection %d, command %s)!?", Req->prefix, Idx, Req->command );
if( ! Conn_WriteStr( Idx, "ERROR :Invalid prefix \"%s\", client not known!?", Req->prefix )) *Closed = true;
return false;
}
/* pruefen, ob der Client mit dem angegebenen Prefix in Richtung
* des Senders liegt, d.h. sicherstellen, dass das Prefix nicht
* gefaelscht ist */
/* check if the client named in the prefix is expected
* to come from that direction */
if( Client_NextHop( c ) != client )
{
/* das angegebene Prefix ist aus dieser Richtung, also
* aus der gegebenen Connection, ungueltig! */
Log( LOG_ERR, "Spoofed prefix \"%s\" from \"%s\" (connection %d, command %s)!", Req->prefix, Client_Mask( Conn_GetClient( Idx )), Idx, Req->command );
Conn_Close( Idx, NULL, "Spoofed prefix", true);
*Closed = true;
@ -456,8 +440,6 @@ Handle_Numeric(CLIENT *client, REQUEST *Req)
static bool
Handle_Request( CONN_ID Idx, REQUEST *Req )
{
/* Client-Request verarbeiten. Bei einem schwerwiegenden Fehler
* wird die Verbindung geschlossen und false geliefert. */
CLIENT *client;
bool result = true;
int client_type;
@ -479,7 +461,6 @@ Handle_Request( CONN_ID Idx, REQUEST *Req )
cmd = My_Commands;
while (cmd->name) {
/* Befehl suchen */
if (strcasecmp(Req->command, cmd->name) != 0) {
cmd++;
continue;