]> arthur.barton.de Git - ngircd-alex.git/commitdiff
- Loglevel und Meldungen nochmals geaendert. Level passen nun besser.
authorAlexander Barton <alex@barton.de>
Sun, 6 Jan 2002 15:18:14 +0000 (15:18 +0000)
committerAlexander Barton <alex@barton.de>
Sun, 6 Jan 2002 15:18:14 +0000 (15:18 +0000)
src/ngircd/client.c
src/ngircd/client.h
src/ngircd/conn.c
src/ngircd/conn.h

index 50dd469c6ec65af7f92f3bfa4db323962e00f1e8..b4ba8ae50bd1123a043b006601e5ae07b550f436 100644 (file)
@@ -9,7 +9,7 @@
  * Naehere Informationen entnehmen Sie bitter der Datei COPYING. Eine Liste
  * der an ngIRCd beteiligten Autoren finden Sie in der Datei AUTHORS.
  *
- * $Id: client.c,v 1.23 2002/01/05 23:26:05 alex Exp $
+ * $Id: client.c,v 1.24 2002/01/06 15:18:14 alex Exp $
  *
  * client.c: Management aller Clients
  *
@@ -21,6 +21,9 @@
  * Server gewesen, so existiert eine entsprechende CONNECTION-Struktur.
  *
  * $Log: client.c,v $
+ * Revision 1.24  2002/01/06 15:18:14  alex
+ * - Loglevel und Meldungen nochmals geaendert. Level passen nun besser.
+ *
  * Revision 1.23  2002/01/05 23:26:05  alex
  * - Vorbereitungen fuer Ident-Abfragen in Client-Strukturen.
  *
 #include "client.h"
 
 #include <imp.h>
+#include "ngircd.h"
 #include "channel.h"
 #include "conf.h"
 #include "conn.h"
@@ -166,7 +170,7 @@ GLOBAL VOID Client_Exit( VOID )
        CLIENT *c, *next;
        INT cnt;
 
-       Client_Destroy( This_Server );
+       Client_Destroy( This_Server, "Server going down.", NULL );
        
        cnt = 0;
        c = My_Clients;
@@ -178,7 +182,7 @@ GLOBAL VOID Client_Exit( VOID )
                c = next;
        }
        if( cnt ) Log( LOG_INFO, "Freed %d client structure%s.", cnt, cnt == 1 ? "" : "s" );
-} /* Client Exit */
+} /* Client_Exit */
 
 
 GLOBAL CLIENT *Client_ThisServer( VOID )
@@ -239,21 +243,26 @@ GLOBAL CLIENT *Client_New( CONN_ID Idx, CLIENT *Introducer, INT Type, CHAR *ID,
 } /* Client_New */
 
 
-GLOBAL VOID Client_Destroy( CLIENT *Client )
+GLOBAL VOID Client_Destroy( CLIENT *Client, CHAR *LogMsg, CHAR *FwdMsg )
 {
        /* Client entfernen. */
        
        CLIENT *last, *c;
+       CHAR *txt;
 
        assert( Client != NULL );
 
+       if( LogMsg ) txt = LogMsg;
+       else txt = FwdMsg;
+       if( ! txt ) txt = "Reason unknown.";
+
        last = NULL;
        c = My_Clients;
        while( c )
        {
                if(( Client->type == CLIENT_SERVER ) && ( c->introducer == Client ) && ( c != Client ))
                {
-                       Client_Destroy( c );
+                       Client_Destroy( c, LogMsg, FwdMsg );
                        last = NULL;
                        c = My_Clients;
                        continue;
@@ -268,13 +277,21 @@ GLOBAL VOID Client_Destroy( CLIENT *Client )
                                if( c->conn_id != NONE )
                                {
                                        /* Ein lokaler User. Andere Server informieren! */
-                                       Log( LOG_NOTICE, "User \"%s\" exited (connection %d).", c->id, c->conn_id );
-                                       IRC_WriteStrServersPrefix( NULL, c, "QUIT :" );
+                                       Log( LOG_NOTICE, "User \"%s\" unregistered (connection %d): %s", c->id, c->conn_id, txt );
+
+                                       if( FwdMsg ) IRC_WriteStrServersPrefix( NULL, c, "QUIT :%s", FwdMsg );
+                                       else IRC_WriteStrServersPrefix( NULL, c, "QUIT :" );
                                }
-                               else Log( LOG_DEBUG, "User \"%s\" exited.", c->id );
+                               else
+                               {
+                                       Log( LOG_DEBUG, "User \"%s\" unregistered: %s", c->id, txt );
+                               }
+                       }
+                       else if( c->type == CLIENT_SERVER )
+                       {
+                               if( c != This_Server ) Log( LOG_NOTICE, "Server \"%s\" unregistered: %s", c->id, txt );
                        }
-                       else if( c->type == CLIENT_SERVER ) Log( LOG_NOTICE, "Server \"%s\" exited.", c->id );
-                       else Log( LOG_NOTICE, "Unknown client \"%s\" exited.", c->id );
+                       else Log( LOG_NOTICE, "Unknown client \"%s\" unregistered: %s", c->id, txt );
 
                        free( c );
                        break;
@@ -661,8 +678,8 @@ GLOBAL BOOLEAN Client_CheckID( CLIENT *Client, CHAR *ID )
                {
                        /* die Server-ID gibt es bereits */
                        sprintf( str, "ID \"%s\" already registered!", ID );
-                       Log( LOG_ALERT, "%s (on connection %d)", str, Client->conn_id );
-                       Conn_Close( Client->conn_id, str );
+                       Log( LOG_ERR, "%s (on connection %d)", str, Client->conn_id );
+                       Conn_Close( Client->conn_id, str, str, TRUE );
                        return FALSE;
                }
                c = c->next;
index 4b159053e5393403cb6a903915798d8845ccba9b..2cddb54475b98c9754409da792129edf2c855fcc 100644 (file)
@@ -9,11 +9,14 @@
  * Naehere Informationen entnehmen Sie bitter der Datei COPYING. Eine Liste
  * der an ngIRCd beteiligten Autoren finden Sie in der Datei AUTHORS.
  *
- * $Id: client.h,v 1.16 2002/01/05 23:26:05 alex Exp $
+ * $Id: client.h,v 1.17 2002/01/06 15:18:14 alex Exp $
  *
  * client.h: Konfiguration des ngircd (Header)
  *
  * $Log: client.h,v $
+ * Revision 1.17  2002/01/06 15:18:14  alex
+ * - Loglevel und Meldungen nochmals geaendert. Level passen nun besser.
+ *
  * Revision 1.16  2002/01/05 23:26:05  alex
  * - Vorbereitungen fuer Ident-Abfragen in Client-Strukturen.
  *
@@ -120,7 +123,7 @@ GLOBAL CLIENT *Client_NewRemoteServer( CLIENT *Introducer, CHAR *Hostname, INT H
 GLOBAL CLIENT *Client_NewRemoteUser( CLIENT *Introducer, CHAR *Nick, INT Hops, CHAR *User, CHAR *Hostname, INT Token, CHAR *Modes, CHAR *Info, BOOLEAN Idented );
 GLOBAL CLIENT *Client_New( CONN_ID Idx, CLIENT *Introducer, INT Type, CHAR *ID, CHAR *User, CHAR *Hostname, CHAR *Info, INT Hops, INT Token, CHAR *Modes, BOOLEAN Idented );
 
-GLOBAL VOID Client_Destroy( CLIENT *Client );
+GLOBAL VOID Client_Destroy( CLIENT *Client, CHAR *LogMsg, CHAR *FwdMsg );
 
 GLOBAL CLIENT *Client_ThisServer( VOID );
 
index 989a65990642cdc6fca1a3c8836037953b461212..e0bd7b457151e5cec6981e5ab003447decd46937 100644 (file)
@@ -9,11 +9,14 @@
  * Naehere Informationen entnehmen Sie bitter der Datei COPYING. Eine Liste
  * der an ngIRCd beteiligten Autoren finden Sie in der Datei AUTHORS.
  *
- * $Id: conn.c,v 1.32 2002/01/05 23:25:25 alex Exp $
+ * $Id: conn.c,v 1.33 2002/01/06 15:18:14 alex Exp $
  *
  * connect.h: Verwaltung aller Netz-Verbindungen ("connections")
  *
  * $Log: conn.c,v $
+ * Revision 1.33  2002/01/06 15:18:14  alex
+ * - Loglevel und Meldungen nochmals geaendert. Level passen nun besser.
+ *
  * Revision 1.32  2002/01/05 23:25:25  alex
  * - Vorbereitungen fuer Ident-Abfragen bei neuen Client-Strukturen.
  *
@@ -242,6 +245,7 @@ GLOBAL VOID Conn_Exit( VOID )
        INT i;
 
        /* Sockets schliessen */
+       Log( LOG_DEBUG, "Shutting down all connections ..." );
        for( i = 0; i < My_Max_Fd + 1; i++ )
        {
                if( FD_ISSET( i, &My_Sockets ))
@@ -250,11 +254,11 @@ GLOBAL VOID Conn_Exit( VOID )
                        {
                                if( My_Connections[idx].sock == i ) break;
                        }
-                       if( idx < MAX_CONNECTIONS ) Conn_Close( idx, "Server going down ..." );
+                       if( idx < MAX_CONNECTIONS ) Conn_Close( idx, NULL, "Server going down", TRUE );
                        else if( FD_ISSET( i, &My_Listeners ))
                        {
                                close( i );
-                               Log( LOG_INFO, "Listening socket %d closed.", i );
+                               Log( LOG_DEBUG, "Listening socket %d closed.", i );
                        }
                        else
                        {
@@ -285,27 +289,27 @@ GLOBAL BOOLEAN Conn_NewListener( CONST INT Port )
        sock = socket( PF_INET, SOCK_STREAM, 0);
        if( sock < 0 )
        {
-               Log( LOG_ALERT, "Can't create socket: %s!", strerror( errno ));
+               Log( LOG_CRIT, "Can't create socket: %s!", strerror( errno ));
                return FALSE;
        }
 
        /* Socket-Optionen setzen */
        if( fcntl( sock, F_SETFL, O_NONBLOCK ) != 0 )
        {
-               Log( LOG_ALERT, "Can't enable non-blocking mode: %s!", strerror( errno ));
+               Log( LOG_CRIT, "Can't enable non-blocking mode: %s!", strerror( errno ));
                close( sock );
                return FALSE;
        }
        if( setsockopt( sock, SOL_SOCKET, SO_REUSEADDR, &on, (socklen_t)sizeof( on )) != 0)
        {
-               Log( LOG_CRIT, "Can't set socket options: %s!", strerror( errno ));
+               Log( LOG_ERR, "Can't set socket options: %s!", strerror( errno ));
                /* dieser Fehler kann ignoriert werden. */
        }
 
        /* an Port binden */
        if( bind( sock, (struct sockaddr *)&addr, (socklen_t)sizeof( addr )) != 0 )
        {
-               Log( LOG_ALERT, "Can't bind socket: %s!", strerror( errno ));
+               Log( LOG_CRIT, "Can't bind socket: %s!", strerror( errno ));
                close( sock );
                return FALSE;
        }
@@ -313,7 +317,7 @@ GLOBAL BOOLEAN Conn_NewListener( CONST INT Port )
        /* in "listen mode" gehen :-) */
        if( listen( sock, 10 ) != 0 )
        {
-               Log( LOG_ALERT, "Can't listen on soecket: %s!", strerror( errno ));
+               Log( LOG_CRIT, "Can't listen on soecket: %s!", strerror( errno ));
                close( sock );
                return FALSE;
        }
@@ -404,7 +408,7 @@ GLOBAL VOID Conn_Handler( INT Timeout )
                {
                        if( errno != EINTR )
                        {
-                               Log( LOG_ALERT, "select(): %s!", strerror( errno ));
+                               Log( LOG_EMERG, "select(): %s!", strerror( errno ));
                                Log( LOG_ALERT, PACKAGE" exiting due to fatal errors!" );
                                exit( 1 );
                        }
@@ -439,8 +443,8 @@ GLOBAL BOOLEAN Conn_WriteStr( CONN_ID Idx, CHAR *Format, ... )
        va_start( ap, Format );
        if( vsnprintf( buffer, COMMAND_LEN - 2, Format, ap ) == COMMAND_LEN - 2 )
        {
-               Log( LOG_ALERT, "String too long to send (connection %d)!", Idx );
-               Conn_Close( Idx, "Server error: String too long to send!" );
+               Log( LOG_CRIT, "Text too long to send (connection %d)!", Idx );
+               Conn_Close( Idx, "Text too long to send!", NULL, FALSE );
                return FALSE;
        }
 
@@ -478,7 +482,7 @@ GLOBAL BOOLEAN Conn_Write( CONN_ID Idx, CHAR *Data, INT Len )
        {
                /* der Puffer ist dummerweise voll ... */
                Log( LOG_NOTICE, "Write buffer overflow (connection %d)!", Idx );
-               Conn_Close( Idx, NULL );
+               Conn_Close( Idx, "Write buffer overflow!", NULL, FALSE );
                return FALSE;
        }
 
@@ -496,7 +500,7 @@ GLOBAL BOOLEAN Conn_Write( CONN_ID Idx, CHAR *Data, INT Len )
 } /* Conn_Write */
 
 
-GLOBAL VOID Conn_Close( CONN_ID Idx, CHAR *Msg )
+GLOBAL VOID Conn_Close( CONN_ID Idx, CHAR *LogMsg, CHAR *FwdMsg, BOOLEAN InformClient )
 {
        /* Verbindung schliessen. Evtl. noch von Resolver
         * Sub-Prozessen offene Pipes werden geschlossen. */
@@ -506,9 +510,10 @@ GLOBAL VOID Conn_Close( CONN_ID Idx, CHAR *Msg )
        assert( Idx >= 0 );
        assert( My_Connections[Idx].sock > NONE );
 
-       if( Msg )
+       if( InformClient )
        {
-               Conn_WriteStr( Idx, "ERROR :%s", Msg );
+               if( FwdMsg ) Conn_WriteStr( Idx, "ERROR :%s", FwdMsg );
+               else Conn_WriteStr( Idx, "ERROR :Closing connection." );
                if( My_Connections[Idx].sock == NONE ) return;
        }
 
@@ -522,7 +527,7 @@ GLOBAL VOID Conn_Close( CONN_ID Idx, CHAR *Msg )
        }
 
        c = Client_GetFromConn( Idx );
-       if( c ) Client_Destroy( c );
+       if( c ) Client_Destroy( c, LogMsg, FwdMsg );
 
        if( My_Connections[Idx].res_stat )
        {
@@ -577,8 +582,8 @@ LOCAL BOOLEAN Try_Write( CONN_ID Idx )
                /* Fehler! */
                if( errno != EINTR )
                {
-                       Log( LOG_ALERT, "select(): %s!", strerror( errno ));
-                       Conn_Close( Idx, NULL );
+                       Log( LOG_ALERT, "select() failed: %s!", strerror( errno ));
+                       Conn_Close( Idx, "Server error!", NULL, FALSE );
                        return FALSE;
                }
        }
@@ -637,8 +642,8 @@ LOCAL BOOLEAN Handle_Write( CONN_ID Idx )
        if( len < 0 )
        {
                /* Oops, ein Fehler! */
-               Log( LOG_ALERT, "Write error (buffer) on connection %d: %s!", Idx, strerror( errno ));
-               Conn_Close( Idx, NULL );
+               Log( LOG_ERR, "Write error (buffer) on connection %d: %s!", Idx, strerror( errno ));
+               Conn_Close( Idx, "Write error (buffer)!", NULL, FALSE );
                return FALSE;
        }
 
@@ -741,8 +746,8 @@ LOCAL VOID Read_Request( CONN_ID Idx )
        if( READBUFFER_LEN - My_Connections[Idx].rdatalen - 2 < 0 )
        {
                /* Der Lesepuffer ist voll */
-               Log( LOG_ALERT, "Read buffer overflow (connection %d): %d bytes!", Idx, My_Connections[Idx].rdatalen );
-               Conn_Close( Idx, "Read buffer overflow!" );
+               Log( LOG_ERR, "Read buffer overflow (connection %d): %d bytes!", Idx, My_Connections[Idx].rdatalen );
+               Conn_Close( Idx, "Read buffer overflow!", NULL, FALSE );
                return;
        }
 
@@ -752,15 +757,15 @@ LOCAL VOID Read_Request( CONN_ID Idx )
        {
                /* Socket wurde geschlossen */
                Log( LOG_INFO, "%s:%d is closing the connection ...", inet_ntoa( My_Connections[Idx].addr.sin_addr ), ntohs( My_Connections[Idx].addr.sin_port));
-               Conn_Close( Idx, NULL );
+               Conn_Close( Idx, "Socket closed.", NULL, FALSE );
                return;
        }
 
        if( len < 0 )
        {
                /* Fehler beim Lesen */
-               Log( LOG_ALERT, "Read error on connection %d: %s!", Idx, strerror( errno ));
-               Conn_Close( Idx, NULL );
+               Log( LOG_ERR, "Read error on connection %d: %s!", Idx, strerror( errno ));
+               Conn_Close( Idx, "Read error!", NULL, FALSE );
                return;
        }
 
@@ -812,8 +817,8 @@ LOCAL VOID Handle_Buffer( CONN_ID Idx )
                        /* Eine Anfrage darf(!) nicht laenger als 512 Zeichen
                        * (incl. CR+LF!) werden; vgl. RFC 2812. Wenn soetwas
                        * empfangen wird, wird der Client disconnectiert. */
-                       Log( LOG_ALERT, "Request too long (connection %d): %d bytes!", Idx, My_Connections[Idx].rdatalen );
-                       Conn_Close( Idx, "Request too long!" );
+                       Log( LOG_ERR, "Request too long (connection %d): %d bytes!", Idx, My_Connections[Idx].rdatalen );
+                       Conn_Close( Idx, NULL, "Request too long", TRUE );
                        return;
                }
                
@@ -853,8 +858,8 @@ LOCAL VOID Check_Connections( VOID )
                                if( My_Connections[i].lastping < time( NULL ) - Conf_PongTimeout )
                                {
                                        /* Timeout */
-                                       Log( LOG_INFO, "Connection %d: PING timeout.", i );
-                                       Conn_Close( i, "PING timeout" );
+                                       Log( LOG_DEBUG, "Connection %d: Ping timeout.", i );
+                                       Conn_Close( i, NULL, "Ping timeout", TRUE );
                                }
                        }
                        else if( My_Connections[i].lastdata < time( NULL ) - Conf_PingTimeout )
@@ -872,7 +877,7 @@ LOCAL VOID Check_Connections( VOID )
                        {
                                /* Timeout */
                                Log( LOG_INFO, "Connection %d: Timeout.", i );
-                               Conn_Close( i, "Timeout" );
+                               Conn_Close( i, NULL, "Timeout", TRUE );
                        }
                }
        }
@@ -982,14 +987,14 @@ LOCAL VOID New_Server( INT Server, CONN_ID Idx )
        if ( new_sock < 0 )
        {
                Init_Conn_Struct( Idx );
-               Log( LOG_ALERT, "Can't create socket: %s!", strerror( errno ));
+               Log( LOG_CRIT, "Can't create socket: %s!", strerror( errno ));
                return;
        }
        if( connect( new_sock, (struct sockaddr *)&new_addr, sizeof( new_addr )) < 0)
        {
                close( new_sock );
                Init_Conn_Struct( Idx );
-               Log( LOG_ALERT, "Can't connect socket: %s!", strerror( errno ));
+               Log( LOG_CRIT, "Can't connect socket: %s!", strerror( errno ));
                return;
        }
 
@@ -1050,7 +1055,7 @@ LOCAL RES_STAT *ResolveAddr( struct sockaddr_in *Addr )
        s = malloc( sizeof( RES_STAT ));
        if( ! s )
        {
-               Log( LOG_ALERT, "Resolver: Can't alloc memory!" );
+               Log( LOG_EMERG, "Resolver: Can't allocate memory!" );
                return NULL;
        }
 
@@ -1085,7 +1090,7 @@ LOCAL RES_STAT *ResolveAddr( struct sockaddr_in *Addr )
        {
                /* Fehler */
                free( s );
-               Log( LOG_ALERT, "Resolver: Can't fork: %s!", strerror( errno ));
+               Log( LOG_CRIT, "Resolver: Can't fork: %s!", strerror( errno ));
                return NULL;
        }
 } /* ResolveAddr */
@@ -1104,7 +1109,7 @@ LOCAL RES_STAT *ResolveName( CHAR *Host )
        s = malloc( sizeof( RES_STAT ));
        if( ! s )
        {
-               Log( LOG_ALERT, "Resolver: Can't alloc memory!" );
+               Log( LOG_EMERG, "Resolver: Can't allocate memory!" );
                return NULL;
        }
 
@@ -1139,7 +1144,7 @@ LOCAL RES_STAT *ResolveName( CHAR *Host )
        {
                /* Fehler */
                free( s );
-               Log( LOG_ALERT, "Resolver: Can't fork: %s!", strerror( errno ));
+               Log( LOG_CRIT, "Resolver: Can't fork: %s!", strerror( errno ));
                return NULL;
        }
 } /* ResolveName */
@@ -1166,7 +1171,7 @@ LOCAL VOID Do_ResolveAddr( struct sockaddr_in *Addr, INT w_fd )
        /* Antwort an Parent schreiben */
        if( write( w_fd, hostname, strlen( hostname ) + 1 ) != ( strlen( hostname ) + 1 ))
        {
-               Log_Resolver( LOG_ALERT, "Resolver: Can't write to parent: %s!", strerror( errno ));
+               Log_Resolver( LOG_CRIT, "Resolver: Can't write to parent: %s!", strerror( errno ));
                close( w_fd );
                return;
        }
@@ -1201,7 +1206,7 @@ LOCAL VOID Do_ResolveName( CHAR *Host, INT w_fd )
        /* Antwort an Parent schreiben */
        if( write( w_fd, ip, strlen( ip ) + 1 ) != ( strlen( ip ) + 1 ))
        {
-               Log_Resolver( LOG_ALERT, "Resolver: Can't write to parent: %s!", strerror( errno ));
+               Log_Resolver( LOG_CRIT, "Resolver: Can't write to parent: %s!", strerror( errno ));
                close( w_fd );
                return;
        }
@@ -1227,7 +1232,7 @@ LOCAL VOID Read_Resolver_Result( INT r_fd )
        {
                /* Fehler beim Lesen aus der Pipe */
                close( r_fd );
-               Log( LOG_ALERT, "Resolver: Can't read result: %s!", strerror( errno ));
+               Log( LOG_CRIT, "Resolver: Can't read result: %s!", strerror( errno ));
                return;
        }
        result[len] = '\0';
index 2e0ac8eb4644285e0f3d62e9c7a6bd8404086b3f..8344b29159ef2adb36230c1afd8eb66660d89b46 100644 (file)
@@ -9,11 +9,14 @@
  * Naehere Informationen entnehmen Sie bitter der Datei COPYING. Eine Liste
  * der an ngIRCd beteiligten Autoren finden Sie in der Datei AUTHORS.
  *
- * $Id: conn.h,v 1.9 2002/01/02 02:44:36 alex Exp $
+ * $Id: conn.h,v 1.10 2002/01/06 15:18:15 alex Exp $
  *
  * conn.h: Verwaltung aller Netz-Verbindungen ("connections") (Header)
  *
  * $Log: conn.h,v $
+ * Revision 1.10  2002/01/06 15:18:15  alex
+ * - Loglevel und Meldungen nochmals geaendert. Level passen nun besser.
+ *
  * Revision 1.9  2002/01/02 02:44:36  alex
  * - neue Defines fuer max. Anzahl Server und Operatoren.
  *
@@ -68,7 +71,7 @@ GLOBAL VOID Conn_Handler( INT Timeout );
 GLOBAL BOOLEAN Conn_Write( CONN_ID Idx, CHAR *Data, INT Len );
 GLOBAL BOOLEAN Conn_WriteStr( CONN_ID Idx, CHAR *Format, ... );
 
-GLOBAL VOID Conn_Close( CONN_ID Idx, CHAR *Msg );
+GLOBAL VOID Conn_Close( CONN_ID Idx, CHAR *LogMsg, CHAR *FwdMsg, BOOLEAN InformClient );
 
 GLOBAL VOID Conn_UpdateIdle( CONN_ID Idx );
 GLOBAL INT32 Conn_GetIdle( CONN_ID Idx );