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( ); client = New_Client_Struct( );
if( ! client ) return NULL; if( ! client ) return NULL;
/* Initialisieren */
client->starttime = time(NULL); client->starttime = time(NULL);
client->conn_id = Idx; client->conn_id = Idx;
client->introducer = Introducer; client->introducer = Introducer;
@ -211,11 +210,9 @@ Init_New_Client(CONN_ID Idx, CLIENT *Introducer, CLIENT *TopServer,
if( strchr( client->modes, 'a' )) if( strchr( client->modes, 'a' ))
strlcpy( client->away, DEFAULT_AWAY_MSG, sizeof( client->away )); strlcpy( client->away, DEFAULT_AWAY_MSG, sizeof( client->away ));
/* Verketten */
client->next = (POINTER *)My_Clients; client->next = (POINTER *)My_Clients;
My_Clients = client; My_Clients = client;
/* Adjust counters */
Adjust_Counters( client ); Adjust_Counters( client );
return client; return client;
@ -225,7 +222,7 @@ Init_New_Client(CONN_ID Idx, CLIENT *Introducer, CLIENT *TopServer,
GLOBAL void GLOBAL void
Client_Destroy( CLIENT *Client, const char *LogMsg, const char *FwdMsg, bool SendQuit ) Client_Destroy( CLIENT *Client, const char *LogMsg, const char *FwdMsg, bool SendQuit )
{ {
/* Client entfernen. */ /* remove a client */
CLIENT *last, *c; CLIENT *last, *c;
char msg[LINE_LEN]; char msg[LINE_LEN];
@ -237,7 +234,7 @@ Client_Destroy( CLIENT *Client, const char *LogMsg, const char *FwdMsg, bool Sen
else txt = FwdMsg; else txt = FwdMsg;
if( ! txt ) txt = "Reason unknown."; if( ! txt ) txt = "Reason unknown.";
/* Netz-Split-Nachricht vorbereiten (noch nicht optimal) */ /* netsplit message */
if( Client->type == CLIENT_SERVER ) { if( Client->type == CLIENT_SERVER ) {
strlcpy(msg, This_Server->id, sizeof (msg)); strlcpy(msg, This_Server->id, sizeof (msg));
strlcat(msg, " ", 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 )) 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 ); Client_Destroy( c, NULL, msg, false );
last = NULL; last = NULL;
c = My_Clients; c = My_Clients;
@ -259,7 +264,7 @@ Client_Destroy( CLIENT *Client, const char *LogMsg, const char *FwdMsg, bool Sen
} }
if( c == Client ) if( c == Client )
{ {
/* Wir haben den Client gefunden: entfernen */ /* found the client: remove it */
if( last ) last->next = c->next; if( last ) last->next = c->next;
else My_Clients = (CLIENT *)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 ); else Log( LOG_NOTICE|LOG_snotice, "Server \"%s\" unregistered: %s", c->id, txt );
} }
/* andere Server informieren */ /* inform other servers */
if( ! NGIRCd_SignalQuit ) if( ! NGIRCd_SignalQuit )
{ {
if( FwdMsg ) IRC_WriteStrServersPrefix( Client_NextHop( c ), c, "SQUIT %s :%s", c->id, FwdMsg ); if( FwdMsg ) IRC_WriteStrServersPrefix( Client_NextHop( c ), c, "SQUIT %s :%s", c->id, FwdMsg );

View File

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

View File

@ -11,19 +11,15 @@
* Connection compression using ZLIB * Connection compression using ZLIB
*/ */
#include "portab.h" #include "portab.h"
#define CONN_MODULE #define CONN_MODULE
#ifdef ZLIB #ifdef ZLIB
/* enable more zlib related debug messages: */ /* enable more zlib related debug messages: */
/* #define DEBUG_ZLIB */ /* #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 "imp.h"
#include <assert.h> #include <assert.h>
#include <string.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 GLOBAL bool
Zip_InitConn( CONN_ID Idx ) Zip_InitConn( CONN_ID Idx )
{ {
/* Kompression fuer Link initialisieren */ /* initialize zlib compression on this link */
assert( Idx > NONE ); assert( Idx > NONE );
@ -52,10 +48,8 @@ Zip_InitConn( CONN_ID Idx )
My_Connections[Idx].zip.in.zfree = NULL; My_Connections[Idx].zip.in.zfree = NULL;
My_Connections[Idx].zip.in.data_type = Z_ASCII; My_Connections[Idx].zip.in.data_type = Z_ASCII;
if( inflateInit( &My_Connections[Idx].zip.in ) != Z_OK ) if (inflateInit( &My_Connections[Idx].zip.in ) != Z_OK) {
{ Log(LOG_ALERT, "Can't initialize compression on connection %d (zlib inflate)!", Idx);
/* Fehler! */
Log( LOG_ALERT, "Can't initialize compression on connection %d (zlib inflate)!", Idx );
return false; return false;
} }
@ -65,17 +59,15 @@ Zip_InitConn( CONN_ID Idx )
My_Connections[Idx].zip.out.zfree = NULL; My_Connections[Idx].zip.out.zfree = NULL;
My_Connections[Idx].zip.out.data_type = Z_ASCII; My_Connections[Idx].zip.out.data_type = Z_ASCII;
if( deflateInit( &My_Connections[Idx].zip.out, Z_DEFAULT_COMPRESSION ) != Z_OK ) 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);
/* Fehler! */
Log( LOG_ALERT, "Can't initialize compression on connection %d (zlib deflate)!", Idx );
return false; return false;
} }
My_Connections[Idx].zip.bytes_in = My_Connections[Idx].bytes_in; My_Connections[Idx].zip.bytes_in = My_Connections[Idx].bytes_in;
My_Connections[Idx].zip.bytes_out = My_Connections[Idx].bytes_out; 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 ); Conn_OPTION_ADD( &My_Connections[Idx], CONN_ZIP );
return true; 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 * Compress data in ZIP buffer and move result to the write buffer of
* the connection. * the connection.
* @param Idx Connection handle. * @param Idx Connection handle.
* @retrun true on success, false otherwise. * @return true on success, false otherwise.
*/ */
GLOBAL bool GLOBAL bool
Zip_Flush( CONN_ID Idx ) Zip_Flush( CONN_ID Idx )
@ -184,13 +176,16 @@ Zip_Flush( CONN_ID Idx )
} /* Zip_Flush */ } /* 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 GLOBAL bool
Unzip_Buffer( CONN_ID Idx ) 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; int result;
unsigned char unzipbuf[READBUFFER_LEN]; unsigned char unzipbuf[READBUFFER_LEN];
int unzipbuf_used = 0; int unzipbuf_used = 0;
@ -221,8 +216,8 @@ Unzip_Buffer( CONN_ID Idx )
result = inflate( in, Z_SYNC_FLUSH ); result = inflate( in, Z_SYNC_FLUSH );
if( result != Z_OK ) 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 ); 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 ); Conn_Close(Idx, "Decompression error!", NULL, false);
return false; return false;
} }
@ -249,21 +244,25 @@ Unzip_Buffer( CONN_ID Idx )
} /* Unzip_Buffer */ } /* Unzip_Buffer */
/**
* @param Idx Connection handle.
* @return amount of sent (compressed) bytes
*/
GLOBAL long GLOBAL long
Zip_SendBytes( CONN_ID Idx ) Zip_SendBytes( CONN_ID Idx )
{ {
/* Anzahl gesendeter Bytes (komprimiert!) liefern */
assert( Idx > NONE ); assert( Idx > NONE );
return My_Connections[Idx].zip.bytes_out; return My_Connections[Idx].zip.bytes_out;
} /* Zip_SendBytes */ } /* Zip_SendBytes */
/**
* @param Idx Connection handle.
* @return amount of received (compressed) bytes
*/
GLOBAL long GLOBAL long
Zip_RecvBytes( CONN_ID Idx ) Zip_RecvBytes( CONN_ID Idx )
{ {
/* Anzahl gesendeter Bytes (komprimiert!) liefern */
assert( Idx > NONE ); assert( Idx > NONE );
return My_Connections[Idx].zip.bytes_in; return My_Connections[Idx].zip.bytes_in;
} /* Zip_RecvBytes */ } /* Zip_RecvBytes */

View File

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

View File

@ -49,24 +49,23 @@ IRC_ADMIN(CLIENT *Client, REQUEST *Req )
assert( Client != NULL ); assert( Client != NULL );
assert( Req != 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 )) 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] ); if( Req->argc == 1 ) target = Client_Search( Req->argv[0] );
else target = Client_ThisServer( ); else target = Client_ThisServer( );
/* Prefix ermitteln */ /* find Prefix */
if( Client_Type( Client ) == CLIENT_SERVER ) prefix = Client_Search( Req->prefix ); if( Client_Type( Client ) == CLIENT_SERVER ) prefix = Client_Search( Req->prefix );
else prefix = Client; else prefix = Client;
if( ! prefix ) return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->prefix ); 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_ThisServer( ))
{ {
if(( ! target ) || ( Client_Type( target ) != CLIENT_SERVER )) return IRC_WriteStrClient( prefix, ERR_NOSUCHSERVER_MSG, Client_ID( prefix ), Req->argv[0] ); 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] ); IRC_WriteStrClientPrefix( target, prefix, "ADMIN %s", Req->argv[0] );
return CONNECTED; return CONNECTED;
} }
@ -199,7 +198,6 @@ IRC_LINKS( CLIENT *Client, REQUEST *Req )
assert( Client != NULL ); assert( Client != NULL );
assert( Req != NULL ); assert( Req != NULL );
/* Falsche Anzahl Parameter? */
if(( Req->argc > 2 )) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command ); if(( Req->argc > 2 )) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
/* Server-Mask ermitteln */ /* Server-Mask ermitteln */
@ -247,7 +245,6 @@ IRC_LUSERS( CLIENT *Client, REQUEST *Req )
assert( Client != NULL ); assert( Client != NULL );
assert( Req != NULL ); assert( Req != NULL );
/* Falsche Anzahl Parameter? */
if(( Req->argc > 2 )) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command ); if(( Req->argc > 2 )) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
/* Absender ermitteln */ /* Absender ermitteln */
@ -321,7 +318,6 @@ IRC_MOTD( CLIENT *Client, REQUEST *Req )
assert( Client != NULL ); assert( Client != NULL );
assert( Req != 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 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
/* From aus Prefix ermitteln */ /* From aus Prefix ermitteln */
@ -331,7 +327,7 @@ IRC_MOTD( CLIENT *Client, REQUEST *Req )
if( Req->argc == 1 ) if( Req->argc == 1 )
{ {
/* an anderen Server forwarden */ /* forward? */
target = Client_Search( Req->argv[0] ); 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] ); 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( Client != NULL );
assert( Req != NULL ); assert( Req != NULL );
/* Falsche Anzahl Parameter? */
if( Req->argc > 2 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command ); 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 ); if( Client_Type( Client ) == CLIENT_SERVER ) from = Client_Search( Req->prefix );
else from = Client; else from = Client;
if( ! from ) return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->prefix ); if( ! from ) return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->prefix );
if( Req->argc == 2 ) if( Req->argc == 2 )
{ {
/* an anderen Server forwarden */ /* forward to another server? */
target = Client_Search( Req->argv[1] ); 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_Type( target ) != CLIENT_SERVER )) return IRC_WriteStrClient( from, ERR_NOSUCHSERVER_MSG, Client_ID( from ), Req->argv[1] );
if( target != Client_ThisServer( )) if( target != Client_ThisServer( )) {
{ /* target is another server, forward */
/* Ok, anderer Server ist das Ziel: forwarden */
return IRC_WriteStrClientPrefix( target, from, "NAMES %s :%s", Req->argv[0], Req->argv[1] ); 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 ); chan = Channel_Search( ptr );
if( chan ) if( chan )
{ {
/* Namen ausgeben */ /* print name */
if( ! IRC_Send_NAMES( from, chan )) return DISCONNECTED; if( ! IRC_Send_NAMES( from, chan )) return DISCONNECTED;
} }
if( ! IRC_WriteStrClient( from, RPL_ENDOFNAMES_MSG, Client_ID( from ), ptr )) 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, "," ); ptr = strtok( NULL, "," );
} }
return CONNECTED; return CONNECTED;
} }
/* alle Channels durchgehen */
chan = Channel_First( ); chan = Channel_First( );
while( chan ) while( chan )
{ {
/* Namen ausgeben */
if( ! IRC_Send_NAMES( from, chan )) return DISCONNECTED; if( ! IRC_Send_NAMES( from, chan )) return DISCONNECTED;
/* naechster Channel */
chan = Channel_Next( chan ); 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( ); c = Client_First( );
snprintf( rpl, sizeof( rpl ), RPL_NAMREPLY_MSG, Client_ID( from ), "*", "*" ); snprintf( rpl, sizeof( rpl ), RPL_NAMREPLY_MSG, Client_ID( from ), "*", "*" );
while( c ) while( c )
{ {
if(( Client_Type( c ) == CLIENT_USER ) && ( Channel_FirstChannelOf( c ) == NULL ) && ( ! strchr( Client_Modes( c ), 'i' ))) 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 )); if( rpl[strlen( rpl ) - 1] != ':' ) strlcat( rpl, " ", sizeof( rpl ));
strlcat( rpl, Client_ID( c ), sizeof( rpl )); strlcat( rpl, Client_ID( c ), sizeof( rpl ));
if( strlen( rpl ) > ( LINE_LEN - CLIENT_NICK_LEN - 4 )) 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; if( ! IRC_WriteStrClient( from, "%s", rpl )) return DISCONNECTED;
snprintf( rpl, sizeof( rpl ), RPL_NAMREPLY_MSG, Client_ID( from ), "*", "*" ); snprintf( rpl, sizeof( rpl ), RPL_NAMREPLY_MSG, Client_ID( from ), "*", "*" );
} }
} }
/* naechster Client */
c = Client_Next( c ); c = Client_Next( c );
} }
if( rpl[strlen( rpl ) - 1] != ':') if( rpl[strlen( rpl ) - 1] != ':')
{ {
/* es wurden User gefunden */
if( ! IRC_WriteStrClient( from, "%s", rpl )) return DISCONNECTED; if( ! IRC_WriteStrClient( from, "%s", rpl )) return DISCONNECTED;
} }
@ -489,11 +478,10 @@ IRC_STATS( CLIENT *Client, REQUEST *Req )
assert( Client != NULL ); assert( Client != NULL );
assert( Req != NULL ); assert( Req != NULL );
/* Falsche Anzahl Parameter? */
if (Req->argc > 2) if (Req->argc > 2)
return IRC_WriteStrClient(Client, ERR_NEEDMOREPARAMS_MSG, Client_ID(Client), Req->command); 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) if (Client_Type(Client) == CLIENT_SERVER)
from = Client_Search(Req->prefix); from = Client_Search(Req->prefix);
else else
@ -503,13 +491,13 @@ IRC_STATS( CLIENT *Client, REQUEST *Req )
return IRC_WriteStrClient(Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->prefix); return IRC_WriteStrClient(Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->prefix);
if (Req->argc == 2) { if (Req->argc == 2) {
/* an anderen Server forwarden */ /* forward to another server? */
target = Client_Search( Req->argv[1] ); target = Client_Search( Req->argv[1] );
if(( ! target ) || ( Client_Type( target ) != CLIENT_SERVER )) if(( ! target ) || ( Client_Type( target ) != CLIENT_SERVER ))
return IRC_WriteStrClient( from, ERR_NOSUCHSERVER_MSG, Client_ID( from ), Req->argv[1] ); return IRC_WriteStrClient( from, ERR_NOSUCHSERVER_MSG, Client_ID( from ), Req->argv[1] );
if( target != Client_ThisServer()) { 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] ); 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( Client != NULL );
assert( Req != 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 ) 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 ); if( Client_Type( Client ) == CLIENT_SERVER ) from = Client_Search( Req->prefix );
else from = Client; else from = Client;
if( ! from ) return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->prefix ); if( ! from ) return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->prefix );
if( Req->argc == 1 ) if( Req->argc == 1 )
{ {
/* an anderen Server forwarden */
target = Client_Search( Req->argv[0] ); 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_Type( target ) != CLIENT_SERVER )) return IRC_WriteStrClient( Client, ERR_NOSUCHSERVER_MSG, Client_ID( Client ), Req->argv[0] );
if( target != Client_ThisServer( )) if( target != Client_ThisServer( ))
{ {
/* Ok, anderer Server ist das Ziel: forwarden */
return IRC_WriteStrClientPrefix( target, from, "TIME %s", Req->argv[0] ); return IRC_WriteStrClientPrefix( target, from, "TIME %s", Req->argv[0] );
} }
} }
@ -634,7 +618,6 @@ IRC_USERHOST( CLIENT *Client, REQUEST *Req )
assert( Client != NULL ); assert( Client != NULL );
assert( Req != 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 )) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
if( Req->argc > 5 ) max = 5; if( Req->argc > 5 ) max = 5;
@ -646,7 +629,7 @@ IRC_USERHOST( CLIENT *Client, REQUEST *Req )
c = Client_Search( Req->argv[i] ); c = Client_Search( Req->argv[i] );
if( c && ( Client_Type( c ) == CLIENT_USER )) if( c && ( Client_Type( c ) == CLIENT_USER ))
{ {
/* Dieser Nick ist "online" */ /* This Nick is "online" */
strlcat( rpl, Client_ID( c ), sizeof( rpl )); strlcat( rpl, Client_ID( c ), sizeof( rpl ));
if( Client_HasMode( c, 'o' )) strlcat( rpl, "*", sizeof( rpl )); if( Client_HasMode( c, 'o' )) strlcat( rpl, "*", sizeof( rpl ));
strlcat( rpl, "=", sizeof( rpl )); strlcat( rpl, "=", sizeof( rpl ));
@ -684,7 +667,6 @@ IRC_VERSION( CLIENT *Client, REQUEST *Req )
assert( Client != NULL ); assert( Client != NULL );
assert( Req != 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 )) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
/* Ziel suchen */ /* Ziel suchen */

View File

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

View File

@ -671,12 +671,10 @@ IRC_AWAY( CLIENT *Client, REQUEST *Req )
assert( Client != NULL ); assert( Client != NULL );
assert( Req != 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 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
if(( Req->argc == 1 ) && (Req->argv[0][0] )) if(( Req->argc == 1 ) && (Req->argv[0][0] ))
{ {
/* AWAY setzen */
Client_SetAway( Client, Req->argv[0] ); Client_SetAway( Client, Req->argv[0] );
Client_ModeAdd( Client, 'a' ); Client_ModeAdd( Client, 'a' );
IRC_WriteStrServersPrefix( Client, Client, "MODE %s :+a", Client_ID( Client )); IRC_WriteStrServersPrefix( Client, Client, "MODE %s :+a", Client_ID( Client ));
@ -684,7 +682,6 @@ IRC_AWAY( CLIENT *Client, REQUEST *Req )
} }
else else
{ {
/* AWAY loeschen */
Client_ModeDel( Client, 'a' ); Client_ModeDel( Client, 'a' );
IRC_WriteStrServersPrefix( Client, Client, "MODE %s :-a", Client_ID( Client )); IRC_WriteStrServersPrefix( Client, Client, "MODE %s :-a", Client_ID( Client ));
return IRC_WriteStrClient( Client, RPL_UNAWAY_MSG, 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 static bool
Send_ListChange( char *Mode, CLIENT *Prefix, CLIENT *Client, CHANNEL *Channel, const char *Mask ) 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; bool ok;
if( Client_Type( Client ) == CLIENT_USER ) 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 ); ok = IRC_WriteStrClientPrefix( Client, Prefix, "MODE %s %s %s", Channel_Name( Channel ), Mode, Mask );
} }
else ok = true; else ok = true;
/* an andere Server */ /* to other servers */
IRC_WriteStrServersPrefix( Client, Prefix, "MODE %s %s %s", Channel_Name( Channel ), Mode, Mask ); 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 ); IRC_WriteStrChannelPrefix( Client, Channel, Prefix, false, "MODE %s %s %s", Channel_Name( Channel ), Mode, Mask );
return ok; return ok;

View File

@ -14,8 +14,6 @@
#include "portab.h" #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 "imp.h"
#include <assert.h> #include <assert.h>
#include <stdlib.h> #include <stdlib.h>
@ -55,10 +53,8 @@ IRC_OPER( CLIENT *Client, REQUEST *Req )
assert( Client != NULL ); assert( Client != NULL );
assert( Req != NULL ); assert( Req != NULL );
/* Falsche Anzahl Parameter? */
if( Req->argc != 2 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command ); 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++) 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; 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 ) if( i >= Conf_Oper_Count )
return Bad_OperPass(Client, Req->argv[0], "not configured"); return Bad_OperPass(Client, Req->argv[0], "not configured");
/* Stimmt das Passwort? */
if( strcmp( Conf_Oper[i].pwd, Req->argv[1] ) != 0 ) if( strcmp( Conf_Oper[i].pwd, Req->argv[1] ) != 0 )
return Bad_OperPass(Client, Conf_Oper[i].name, "Bad password"); 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 ) ))) if( Conf_Oper[i].mask && (! Match( Conf_Oper[i].mask, Client_Mask( Client ) )))
return Bad_OperPass(Client, Conf_Oper[i].mask, "hostmask check failed" ); return Bad_OperPass(Client, Conf_Oper[i].mask, "hostmask check failed" );
if( ! Client_HasMode( Client, 'o' )) if( ! Client_HasMode( Client, 'o' ))
{ {
/* noch kein o-Mode gesetzt */
Client_ModeAdd( Client, 'o' ); Client_ModeAdd( Client, 'o' );
if( ! IRC_WriteStrClient( Client, "MODE %s :+o", Client_ID( Client ))) return DISCONNECTED; if( ! IRC_WriteStrClient( Client, "MODE %s :+o", Client_ID( Client ))) return DISCONNECTED;
IRC_WriteStrServersPrefix( NULL, Client, "MODE %s :+o", Client_ID( Client )); 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) ...", LogDebug("Connection %d: got SERVER command (new server link) ...",
Client_Conn(Client)); 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 ); 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; for( i = 0; i < MAX_SERVERS; i++ ) if( strcasecmp( Req->argv[0], Conf_Server[i].name ) == 0 ) break;
if( i >= MAX_SERVERS ) if( i >= MAX_SERVERS )
{ {
/* Server ist nicht konfiguriert! */
Log( LOG_ERR, "Connection %d: Server \"%s\" not configured here!", Client_Conn( Client ), Req->argv[0] ); 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); Conn_Close( Client_Conn( Client ), NULL, "Server not configured here", true);
return DISCONNECTED; return DISCONNECTED;
} }
if( strcmp( Client_Password( Client ), Conf_Server[i].pwd_in ) != 0 ) 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] ); 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); Conn_Close( Client_Conn( Client ), NULL, "Bad password", true);
return DISCONNECTED; 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; if( ! Client_CheckID( Client, Req->argv[0] )) return DISCONNECTED;
/* Server-Strukturen fuellen ;-) */
Client_SetID( Client, Req->argv[0] ); Client_SetID( Client, Req->argv[0] );
Client_SetHops( Client, 1 ); Client_SetHops( Client, 1 );
Client_SetInfo( Client, Req->argv[Req->argc - 1] ); Client_SetInfo( Client, Req->argv[Req->argc - 1] );
/* Meldet sich der Server bei uns an (d.h., bauen nicht wir /* Is this server registering on our side, or are we connecting to
* selber die Verbindung zu einem anderen Server auf)? */ * a remote server? */
con = Client_Conn( Client ); con = Client_Conn( Client );
if( Client_Token( Client ) != TOKEN_OUTBOUND ) if( Client_Token( Client ) != TOKEN_OUTBOUND )
{ {
/* Eingehende Verbindung: Unseren SERVER- und PASS-Befehl senden */ /* Incoming connection, send user/pass */
ok = true; ok = true;
if( ! IRC_WriteStrClient( Client, "PASS %s %s", Conf_Server[i].pwd_out, NGIRCd_ProtoID )) ok = false; 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 ); else ok = IRC_WriteStrClient( Client, "SERVER %s 1 :%s", Conf_ServerName, Conf_ServerInfo );
@ -117,8 +114,7 @@ IRC_SERVER( CLIENT *Client, REQUEST *Req )
} }
else else
{ {
/* Ausgehende verbindung, SERVER und PASS wurden von uns bereits /* outgoing connect, we already sent SERVER and PASS to the peer */
* an die Gegenseite uerbermittelt */
Client_SetToken( Client, atoi( Req->argv[1] )); Client_SetToken( Client, atoi( Req->argv[1] ));
} }
@ -139,16 +135,10 @@ IRC_SERVER( CLIENT *Client, REQUEST *Req )
Client_SetType(Client, CLIENT_UNKNOWNSERVER); Client_SetType(Client, CLIENT_UNKNOWNSERVER);
#ifdef ZLIB #ifdef ZLIB
/* Kompression initialisieren, wenn erforderlich */ if (strchr(Client_Flags(Client), 'Z') && !Zip_InitConn(con)) {
if( strchr( Client_Flags( Client ), 'Z' ))
{
if( ! Zip_InitConn( con ))
{
/* Fehler! */
Conn_Close( con, "Can't inizialize compression (zlib)!", NULL, false ); Conn_Close( con, "Can't inizialize compression (zlib)!", NULL, false );
return DISCONNECTED; return DISCONNECTED;
} }
}
#endif #endif
#ifdef IRCPLUS #ifdef IRCPLUS
@ -171,43 +161,38 @@ IRC_SERVER( CLIENT *Client, REQUEST *Req )
} }
else if( Client_Type( Client ) == CLIENT_SERVER ) 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 ); 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; 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, '[' ); ptr = strchr( Req->argv[3] + 2, '[' );
if( ! ptr ) ptr = Req->argv[3]; if( ! ptr ) ptr = Req->argv[3];
from = Client_Search( Req->prefix ); from = Client_Search( Req->prefix );
if( ! from ) 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 )); 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); Conn_Close( Client_Conn( Client ), NULL, "Unknown ID in prefix of SERVER", true);
return DISCONNECTED; return DISCONNECTED;
} }
/* Neue Client-Struktur anlegen */
c = Client_NewRemoteServer( Client, Req->argv[0], from, atoi( Req->argv[1] ), atoi( Req->argv[2] ), ptr, true); c = Client_NewRemoteServer( Client, Req->argv[0], from, atoi( Req->argv[1] ), atoi( Req->argv[2] ), ptr, true);
if( ! c ) if (!c) {
{
/* Neue Client-Struktur konnte nicht angelegt werden */
Log( LOG_ALERT, "Can't create client structure for server! (on connection %d)", Client_Conn( Client )); 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); Conn_Close( Client_Conn( Client ), NULL, "Can't allocate client structure for remote server", true);
return DISCONNECTED; 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 )); if(( Client_Hops( c ) > 1 ) && ( Req->prefix[0] )) snprintf( str, sizeof( str ), "connected to %s, ", Client_ID( from ));
else strcpy( str, "" ); 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": "" ); 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 )); IRC_WriteStrServersPrefix( Client, from, "SERVER %s %d %d :%s", Client_ID( c ), Client_Hops( c ) + 1, Client_MyToken( c ), Client_Info( c ));
return CONNECTED; return CONNECTED;
@ -228,7 +213,6 @@ IRC_NJOIN( CLIENT *Client, REQUEST *Req )
assert( Client != NULL ); assert( Client != NULL );
assert( Req != NULL ); assert( Req != NULL );
/* Falsche Anzahl Parameter? */
if( Req->argc != 2 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command ); 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 )); strlcpy( nick_in, Req->argv[1], sizeof( nick_in ));
@ -240,7 +224,7 @@ IRC_NJOIN( CLIENT *Client, REQUEST *Req )
{ {
is_op = is_voiced = false; is_op = is_voiced = false;
/* Prefixe abschneiden */ /* cut off prefixes */
while(( *ptr == '@' ) || ( *ptr == '+' )) while(( *ptr == '@' ) || ( *ptr == '+' ))
{ {
if( *ptr == '@' ) is_op = true; 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_op ) Channel_UserModeAdd( chan, c, 'o' );
if( is_voiced ) Channel_UserModeAdd( chan, c, 'v' ); if( is_voiced ) Channel_UserModeAdd( chan, c, 'v' );
/* im Channel bekannt machen */ /* announce to channel... */
IRC_WriteStrChannelPrefix( Client, chan, c, false, "JOIN :%s", channame ); 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 )); strlcpy( modes, Channel_UserModes( chan, c ), sizeof( modes ));
if( modes[0] ) 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 )); 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 ); 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, "," ); 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 ); if( nick_out[0] != '\0' ) IRC_WriteStrServersPrefix( Client, Client_ThisServer( ), "NJOIN %s :%s", Req->argv[0], nick_out );
return CONNECTED; return CONNECTED;
@ -296,7 +280,6 @@ IRC_SQUIT( CLIENT *Client, REQUEST *Req )
assert( Client != NULL ); assert( Client != NULL );
assert( Req != NULL ); assert( Req != NULL );
/* Falsche Anzahl Parameter? */
if( Req->argc != 2 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command ); 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] ); 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] ); target = Client_Search( Req->argv[0] );
if( ! target ) 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] ); Log( LOG_WARNING, "Got SQUIT from %s for unknown server \"%s\"!?", Client_ID( Client ), Req->argv[0] );
return CONNECTED; return CONNECTED;
} }
@ -318,18 +300,17 @@ IRC_SQUIT( CLIENT *Client, REQUEST *Req )
if( Client_Conn( target ) > NONE ) 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); if( Req->argv[1][0] ) Conn_Close( Client_Conn( target ), msg, Req->argv[1], true);
else Conn_Close( Client_Conn( target ), msg, NULL, true); else Conn_Close( Client_Conn( target ), msg, NULL, true);
return DISCONNECTED; return DISCONNECTED;
} }
else else
{ {
/* Verbindung hielt anderer Server */ /* connection was on another server */
Client_Destroy( target, msg, Req->argv[1], false ); Client_Destroy( target, msg, Req->argv[1], false );
return CONNECTED; return CONNECTED;
} }
} /* IRC_SQUIT */ } /* IRC_SQUIT */
/* -eof- */ /* -eof- */

View File

@ -14,8 +14,6 @@
#include "portab.h" #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 "imp.h"
#include <assert.h> #include <assert.h>
#ifdef PROTOTYPES #ifdef PROTOTYPES
@ -70,7 +68,7 @@ va_dcl
vsnprintf( buffer, 1000, Format, ap ); vsnprintf( buffer, 1000, Format, ap );
va_end( ap ); va_end( ap );
/* an den Client selber */ /* to the client itself */
ok = IRC_WriteStrClientPrefix( Client, Client_ThisServer( ), "%s", buffer ); ok = IRC_WriteStrClientPrefix( Client, Client_ThisServer( ), "%s", buffer );
return ok; return ok;
@ -89,7 +87,7 @@ char *Format;
va_dcl va_dcl
#endif #endif
{ {
/* Text an Clients, lokal bzw. remote, senden. */ /* send text to local and remote clients */
char buffer[1000]; char buffer[1000];
va_list ap; va_list ap;
@ -141,6 +139,11 @@ va_dcl
} /* IRC_WriteStrChannel */ } /* IRC_WriteStrChannel */
/**
* send message to all clients in the same channel, but only send message
* once per remote server.
*/
#ifdef PROTOTYPES #ifdef PROTOTYPES
GLOBAL bool GLOBAL bool
IRC_WriteStrChannelPrefix( CLIENT *Client, CHANNEL *Chan, CLIENT *Prefix, bool Remote, char *Format, ... ) IRC_WriteStrChannelPrefix( CLIENT *Client, CHANNEL *Chan, CLIENT *Prefix, bool Remote, char *Format, ... )
@ -177,8 +180,6 @@ va_dcl
Conn_ClearFlags( ); Conn_ClearFlags( );
/* An alle Clients, die in den selben Channels sind.
* Dabei aber nur einmal je Remote-Server */
cl2chan = Channel_FirstMember( Chan ); cl2chan = Channel_FirstMember( Chan );
while( cl2chan ) while( cl2chan )
{ {
@ -192,7 +193,7 @@ va_dcl
if( c && ( c != Client )) if( c && ( c != Client ))
{ {
/* Ok, anderer Client */ /* Ok, another Client */
conn = Client_Conn( c ); conn = Client_Conn( c );
if( Client_Type( c ) == CLIENT_SERVER ) Conn_SetFlag( conn, SEND_TO_SERVER ); if( Client_Type( c ) == CLIENT_SERVER ) Conn_SetFlag( conn, SEND_TO_SERVER );
else Conn_SetFlag( conn, SEND_TO_USER ); else Conn_SetFlag( conn, SEND_TO_USER );
@ -200,16 +201,14 @@ va_dcl
cl2chan = Channel_NextMember( Chan, cl2chan ); cl2chan = Channel_NextMember( Chan, cl2chan );
} }
/* Senden: alle Verbindungen durchgehen ... */
conn = Conn_First( ); conn = Conn_First( );
while( conn != NONE ) 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 ); 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 ); else if( Conn_Flag( conn ) == SEND_TO_USER ) ok = Conn_WriteStr( conn, ":%s %s", Client_Mask( Prefix ), buffer );
if( ! ok ) break; if( ! ok ) break;
/* naechste Verbindung testen */
conn = Conn_Next( conn ); conn = Conn_Next( conn );
} }
@ -241,7 +240,6 @@ va_dcl
vsnprintf( buffer, 1000, Format, ap ); vsnprintf( buffer, 1000, Format, ap );
va_end( ap ); va_end( ap );
/* an den Client selber */
IRC_WriteStrServersPrefix( ExceptOf, Client_ThisServer( ), "%s", buffer ); IRC_WriteStrServersPrefix( ExceptOf, Client_ThisServer( ), "%s", buffer );
} /* IRC_WriteStrServers */ } /* IRC_WriteStrServers */
@ -327,6 +325,10 @@ IRC_WriteStrServersPrefixFlag_CB(CLIENT *ExceptOf, CLIENT *Prefix, char Flag,
} /* IRC_WriteStrServersPrefixFlag */ } /* 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 #ifdef PROTOTYPES
GLOBAL bool GLOBAL bool
IRC_WriteStrRelatedPrefix( CLIENT *Client, CLIENT *Prefix, bool Remote, char *Format, ... ) IRC_WriteStrRelatedPrefix( CLIENT *Client, CLIENT *Prefix, bool Remote, char *Format, ... )
@ -360,15 +362,11 @@ va_dcl
vsnprintf( buffer, 1000, Format, ap ); vsnprintf( buffer, 1000, Format, ap );
va_end( ap ); va_end( ap );
/* initialisieren */
Conn_ClearFlags( ); 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 ); chan_cl2chan = Channel_FirstChannelOf( Client );
while( chan_cl2chan ) while( chan_cl2chan )
{ {
/* Channel des Users durchsuchen */
chan = Channel_GetChannel( chan_cl2chan ); chan = Channel_GetChannel( chan_cl2chan );
cl2chan = Channel_FirstMember( chan ); cl2chan = Channel_FirstMember( chan );
while( cl2chan ) while( cl2chan )
@ -383,7 +381,6 @@ va_dcl
if( c && ( c != Client )) if( c && ( c != Client ))
{ {
/* Ok, anderer Client */
conn = Client_Conn( c ); conn = Client_Conn( c );
if( Client_Type( c ) == CLIENT_SERVER ) Conn_SetFlag( conn, SEND_TO_SERVER ); if( Client_Type( c ) == CLIENT_SERVER ) Conn_SetFlag( conn, SEND_TO_SERVER );
else Conn_SetFlag( conn, SEND_TO_USER ); else Conn_SetFlag( conn, SEND_TO_USER );
@ -391,20 +388,17 @@ va_dcl
cl2chan = Channel_NextMember( chan, cl2chan ); cl2chan = Channel_NextMember( chan, cl2chan );
} }
/* naechsten Channel */
chan_cl2chan = Channel_NextChannelOf( Client, chan_cl2chan ); chan_cl2chan = Channel_NextChannelOf( Client, chan_cl2chan );
} }
/* Senden: alle Verbindungen durchgehen ... */
conn = Conn_First( ); conn = Conn_First( );
while( conn != NONE ) 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 ); 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 ); else if( Conn_Flag( conn ) == SEND_TO_USER ) ok = Conn_WriteStr( conn, ":%s %s", Client_Mask( Prefix ), buffer );
if( ! ok ) break; if( ! ok ) break;
/* naechste Verbindung testen */
conn = Conn_Next( conn ); conn = Conn_Next( conn );
} }
return ok; return ok;

View File

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

View File

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

View File

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