]> arthur.barton.de Git - ngircd-alex.git/blobdiff - src/ngircd/client.c
Fixed spelling mistake :-)
[ngircd-alex.git] / src / ngircd / client.c
index 70f6be6c704dc94fb73daf855226f4b5b1bd90d6..5260f146116899eb55842e8c92946904c0ca9dc4 100644 (file)
@@ -17,7 +17,7 @@
 
 #include "portab.h"
 
-static char UNUSED id[] = "$Id: client.c,v 1.69 2002/12/26 16:48:14 alex Exp $";
+static char UNUSED id[] = "$Id: client.c,v 1.74 2003/03/31 15:54:21 alex Exp $";
 
 #include "imp.h"
 #include <assert.h>
@@ -59,6 +59,10 @@ LOCAL CLIENT *New_Client_Struct PARAMS(( VOID ));
 LOCAL VOID Generate_MyToken PARAMS(( CLIENT *Client ));
 LOCAL VOID Adjust_Counters PARAMS(( CLIENT *Client ));
 
+#ifndef Client_DestroyNow
+GLOBAL VOID Client_DestroyNow PARAMS((CLIENT *Client ));
+#endif
+
 
 LONG Max_Users = 0, My_Max_Users = 0;
 
@@ -72,7 +76,7 @@ Client_Init( VOID )
        if( ! This_Server )
        {
                Log( LOG_EMERG, "Can't allocate client structure for server! Going down." );
-               Log( LOG_ALERT, "%s exiting due to fatal errors!", PACKAGE );
+               Log( LOG_ALERT, "%s exiting due to fatal errors!", PACKAGE_NAME );
                exit( 1 );
        }
 
@@ -86,7 +90,7 @@ Client_Init( VOID )
 
        gethostname( This_Server->host, CLIENT_HOST_LEN );
        h = gethostbyname( This_Server->host );
-       if( h ) strcpy( This_Server->host, h->h_name );
+       if( h ) strlcpy( This_Server->host, h->h_name, sizeof( This_Server->host ));
 
        Client_SetID( This_Server, Conf_ServerName );
        Client_SetInfo( This_Server, Conf_ServerInfo );
@@ -175,7 +179,7 @@ Client_New( CONN_ID Idx, CLIENT *Introducer, CLIENT *TopServer, INT Type, CHAR *
        if( Type == CLIENT_SERVER ) Generate_MyToken( client );
 
        /* ist der User away? */
-       if( strchr( client->modes, 'a' )) strcpy( client->away, DEFAULT_AWAY_MSG );
+       if( strchr( client->modes, 'a' )) strlcpy( client->away, DEFAULT_AWAY_MSG, sizeof( client->away ));
 
        /* Verketten */
        client->next = (POINTER *)My_Clients;
@@ -203,7 +207,7 @@ Client_Destroy( CLIENT *Client, CHAR *LogMsg, CHAR *FwdMsg, BOOLEAN SendQuit )
        if( ! txt ) txt = "Reason unknown.";
 
        /* Netz-Split-Nachricht vorbereiten (noch nicht optimal) */
-       if( Client->type == CLIENT_SERVER ) sprintf( msg, "%s: lost server %s", This_Server->id, Client->id );
+       if( Client->type == CLIENT_SERVER ) snprintf( msg, sizeof( msg ), "%s: lost server %s", This_Server->id, Client->id );
 
        last = NULL;
        c = My_Clients;
@@ -292,6 +296,35 @@ Client_Destroy( CLIENT *Client, CHAR *LogMsg, CHAR *FwdMsg, BOOLEAN SendQuit )
 } /* Client_Destroy */
 
 
+GLOBAL VOID
+Client_DestroyNow( CLIENT *Client )
+{
+       /* Destroy client structure immediately. This function is only
+        * intended for the connection layer to remove client structures
+        * of connections that can't be established! */
+
+       CLIENT *last, *c;
+
+       assert( Client != NULL );
+
+       last = NULL;
+       c = My_Clients;
+       while( c )
+       {
+               if( c == Client )
+               {
+                       /* Wir haben den Client gefunden: entfernen */
+                       if( last ) last->next = c->next;
+                       else My_Clients = (CLIENT *)c->next;
+                       free( c );
+                       break;
+               }
+               last = c;
+               c = (CLIENT *)c->next;
+       }
+} /* Client_DestroyNow */
+
+
 GLOBAL VOID
 Client_SetHostname( CLIENT *Client, CHAR *Hostname )
 {
@@ -387,23 +420,13 @@ Client_SetPassword( CLIENT *Client, CHAR *Pwd )
 GLOBAL VOID
 Client_SetAway( CLIENT *Client, CHAR *Txt )
 {
-       /* Von einem Client gelieferte AWAY-Nachricht */
+       /* Set AWAY reason of client */
 
        assert( Client != NULL );
+       assert( Txt != NULL );
 
-       if( Txt )
-       {
-               /* Client AWAY setzen */
-               strlcpy( Client->away, Txt, sizeof( Client->away ));
-               Client_ModeAdd( Client, 'a' );
-               Log( LOG_DEBUG, "User \"%s\" is away: %s", Client_Mask( Client ), Txt );
-       }
-       else
-       {
-               /* AWAY loeschen */
-               Client_ModeDel( Client, 'a' );
-               Log( LOG_DEBUG, "User \"%s\" is no longer away.", Client_Mask( Client ));
-       }
+       strlcpy( Client->away, Txt, sizeof( Client->away ));
+       Log( LOG_DEBUG, "User \"%s\" is away: %s", Client_Mask( Client ), Txt );
 } /* Client_SetAway */
 
 
@@ -799,7 +822,7 @@ Client_CheckID( CLIENT *Client, CHAR *ID )
                if( strcasecmp( c->id, ID ) == 0 )
                {
                        /* die Server-ID gibt es bereits */
-                       sprintf( str, "ID \"%s\" already registered", ID );
+                       snprintf( str, sizeof( str ), "ID \"%s\" already registered", ID );
                        if( Client->conn_id != c->conn_id ) Log( LOG_ERR, "%s (on connection %d)!", str, c->conn_id );
                        else Log( LOG_ERR, "%s (via network)!", str );
                        Conn_Close( Client->conn_id, str, str, TRUE );