]> arthur.barton.de Git - ngircd-alex.git/commitdiff
Code cleanup of IRC_SQUIT() in preparation to deal with bug #73.
authorAlexander Barton <alex@barton.de>
Wed, 9 Apr 2008 17:49:34 +0000 (19:49 +0200)
committerAlexander Barton <alex@barton.de>
Wed, 30 Sep 2009 14:00:05 +0000 (16:00 +0200)
src/ngircd/irc-server.c

index 3c34c20a70fffca5af901b6aec2be1b6e022aa31..b75a34f9834abf6267d5ebb60faae753cff51a17 100644 (file)
@@ -266,44 +266,55 @@ IRC_NJOIN( CLIENT *Client, REQUEST *Req )
 } /* IRC_NJOIN */
 
 
+/**
+ * Handler for the IRC command "SQUIT".
+ * See RFC 2813 section 4.1.2 and RFC 2812 section 3.1.8.
+ */
 GLOBAL bool
-IRC_SQUIT( CLIENT *Client, REQUEST *Req )
+IRC_SQUIT(CLIENT * Client, REQUEST * Req)
 {
        CLIENT *target;
        char msg[LINE_LEN + 64];
 
-       assert( Client != NULL );
-       assert( Req != NULL );
+       assert(Client != NULL);
+       assert(Req != NULL);
 
-       if( Req->argc != 2 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
+       /* Bad number of arguments? */
+       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]);
 
-       target = Client_Search( Req->argv[0] );
-       if( ! target )
-       {
-               Log( LOG_WARNING, "Got SQUIT from %s for unknown server \"%s\"!?", Client_ID( Client ), Req->argv[0] );
+       target = Client_Search(Req->argv[0]);
+       if (!target) {
+               /* The server is (already) unknown */
+               Log(LOG_WARNING,
+                   "Got SQUIT from %s for unknown server \"%s\"!?",
+                   Client_ID(Client), Req->argv[0]);
                return CONNECTED;
        }
 
-       if( Req->argv[1][0] )
-       {
-               if( strlen( Req->argv[1] ) > LINE_LEN ) Req->argv[1][LINE_LEN] = '\0';
-               snprintf( msg, sizeof( msg ), "%s (SQUIT from %s).", Req->argv[1], Client_ID( Client ));
-       }
-       else snprintf( msg, sizeof( msg ), "Got SQUIT from %s.", Client_ID( Client ));
-
-       if( Client_Conn( target ) > NONE )
-       {
-               /* This server has the connection */
-               if( Req->argv[1][0] ) Conn_Close( Client_Conn( target ), msg, Req->argv[1], true);
-               else Conn_Close( Client_Conn( target ), msg, NULL, true);
+       if (Req->argv[1][0]) {
+               if (strlen(Req->argv[1]) > LINE_LEN)
+                       Req->argv[1][LINE_LEN] = '\0';
+               snprintf(msg, sizeof(msg), "%s (SQUIT from %s).", Req->argv[1],
+                        Client_ID(Client));
+       } else
+               snprintf(msg, sizeof(msg), "Got SQUIT from %s.",
+                        Client_ID(Client));
+
+       if (Client_Conn(target) > NONE) {
+               /* We are directly connected to this server */
+               if (Req->argv[1][0])
+                       Conn_Close(Client_Conn(target), msg, Req->argv[1],
+                                  true);
+               else
+                       Conn_Close(Client_Conn(target), msg, NULL, true);
                return DISCONNECTED;
-       }
-       else
-       {
-               /* connection was on another server */
-               Client_Destroy( target, msg, Req->argv[1], false );
+       } else {
+               Client_Destroy(target, msg, Req->argv[1], false);
                return CONNECTED;
        }
 } /* IRC_SQUIT */