]> arthur.barton.de Git - ngircd-alex.git/blobdiff - src/ngircd/irc-login.c
Enhanced ISUPPORT message (numeric 005).
[ngircd-alex.git] / src / ngircd / irc-login.c
index c20621d67c304e4b04501530732b6fdbbc30437c..6516086ac189c204e9fa17c1211a3c032c40250c 100644 (file)
@@ -14,7 +14,7 @@
 
 #include "portab.h"
 
-static char UNUSED id[] = "$Id: irc-login.c,v 1.46 2005/07/31 20:13:08 alex Exp $";
+static char UNUSED id[] = "$Id: irc-login.c,v 1.51 2006/10/01 19:03:05 alex Exp $";
 
 #include "imp.h"
 #include <assert.h>
@@ -268,13 +268,13 @@ IRC_NICK( CLIENT *Client, REQUEST *Req )
                                                   "NICK :%s", Req->argv[0] );
                        IRC_WriteStrRelatedPrefix( target, target, false,
                                                   "NICK :%s", Req->argv[0] );
-                       
+
                        /* Register old nickname for WHOWAS queries */
                        Client_RegisterWhowas( target );
-                               
+
                        /* Save new nickname */
                        Client_SetID( target, Req->argv[0] );
-                       
+
                        IRC_SetPenalty( target, 2 );
                }
 
@@ -427,71 +427,128 @@ IRC_QUIT( CLIENT *Client, REQUEST *Req )
 
 
 GLOBAL bool
-IRC_PING( CLIENT *Client, REQUEST *Req )
+IRC_PING(CLIENT *Client, REQUEST *Req)
 {
        CLIENT *target, *from;
 
-       assert( Client != NULL );
-       assert( Req != NULL );
+       assert(Client != NULL);
+       assert(Req != NULL);
 
-       /* Falsche Anzahl Parameter? */
-       if( Req->argc < 1 ) return IRC_WriteStrClient( Client, ERR_NOORIGIN_MSG, Client_ID( Client ));
+       /* Wrong number of arguments? */
+       if (Req->argc < 1)
+               return IRC_WriteStrClient(Client, ERR_NOORIGIN_MSG,
+                                         Client_ID(Client));
 #ifdef STRICT_RFC
-       if( Req->argc > 2 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
+       /* Don't ignore additional arguments when in "strict" mode */
+       if (Req->argc > 2)
+                return IRC_WriteStrClient(Client, ERR_NEEDMOREPARAMS_MSG,
+                                          Client_ID(Client), Req->command);
 #endif
 
-       if( Req->argc > 1 )
-       {
-               /* es wurde ein Ziel-Client angegeben */
-               target = Client_Search( Req->argv[1] );
-               if(( ! target ) || ( Client_Type( target ) != CLIENT_SERVER )) return IRC_WriteStrClient( Client, ERR_NOSUCHSERVER_MSG, Client_ID( Client ), Req->argv[1] );
-               if( target != Client_ThisServer( ))
-               {
-                       /* ok, forwarden */
-                       if( Client_Type( Client ) == CLIENT_SERVER ) from = Client_Search( Req->prefix );
-                       else from = Client;
-                       if( ! from ) return IRC_WriteStrClient( Client, ERR_NOSUCHSERVER_MSG, Client_ID( Client ), Req->prefix );
-                       return IRC_WriteStrClientPrefix( target, from, "PING %s :%s", Client_ID( from ), Req->argv[1] );
+       if (Req->argc > 1) {
+               /* A target has been specified ... */
+               target = Client_Search(Req->argv[1]);
+
+               if (!target || Client_Type(target) != CLIENT_SERVER)
+                       return IRC_WriteStrClient(Client, ERR_NOSUCHSERVER_MSG,
+                                       Client_ID(Client), Req->argv[1]);
+
+               if (target != Client_ThisServer()) {
+                       /* Ok, we have to forward the PING */
+                       if (Client_Type(Client) == CLIENT_SERVER)
+                               from = Client_Search(Req->prefix);
+                       else
+                               from = Client;
+                       if (!from)
+                               return IRC_WriteStrClient(Client,
+                                               ERR_NOSUCHSERVER_MSG,
+                                               Client_ID(Client), Req->prefix);
+
+                       return IRC_WriteStrClientPrefix(target, from,
+                                       "PING %s :%s", Req->argv[0],
+                                       Req->argv[1] );
                }
        }
 
-       Log( LOG_DEBUG, "Connection %d: got PING, sending PONG ...", Client_Conn( Client ));
-       return IRC_WriteStrClient( Client, "PONG %s :%s", Client_ID( Client_ThisServer( )), Client_ID( Client ));
+       if (Client_Type(Client) == CLIENT_SERVER) {
+               if (Req->prefix)
+                       from = Client_Search(Req->prefix);
+               else
+                       from = Client;
+       } else
+               from = Client_ThisServer();
+       if (!from)
+               return IRC_WriteStrClient(Client, ERR_NOSUCHSERVER_MSG,
+                                       Client_ID(Client), Req->prefix);
+
+       Log(LOG_DEBUG, "Connection %d: got PING, sending PONG ...",
+           Client_Conn(Client));
+
+#ifdef STRICT_RFC
+       return IRC_WriteStrClient(Client, "PONG %s :%s",
+               Client_ID(from), Client_ID(Client));
+#else
+       /* Some clients depend on the argument being returned in the PONG
+         * reply (not mentioned in any RFC, though) */
+       return IRC_WriteStrClient(Client, "PONG %s :%s",
+               Client_ID(from), Req->argv[0]);
+#endif
 } /* IRC_PING */
 
 
 GLOBAL bool
-IRC_PONG( CLIENT *Client, REQUEST *Req )
+IRC_PONG(CLIENT *Client, REQUEST *Req)
 {
        CLIENT *target, *from;
+       char *s;
 
-       assert( Client != NULL );
-       assert( Req != NULL );
-
-       /* Falsche Anzahl Parameter? */
-       if( Req->argc < 1 ) return IRC_WriteStrClient( Client, ERR_NOORIGIN_MSG, Client_ID( Client ));
-       if( Req->argc > 2 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
+       assert(Client != NULL);
+       assert(Req != NULL);
 
-       /* forwarden? */
-       if( Req->argc == 2 )
-       {
-               target = Client_Search( Req->argv[1] );
-               if(( ! target ) || ( Client_Type( target ) != CLIENT_SERVER )) return IRC_WriteStrClient( Client, ERR_NOSUCHSERVER_MSG, Client_ID( Client ), Req->argv[1] );
-               if( target != Client_ThisServer( ))
-               {
-                       /* ok, forwarden */
-                       if( Client_Type( Client ) == CLIENT_SERVER ) from = Client_Search( Req->prefix );
-                       else from = Client;
-                       if( ! from ) return IRC_WriteStrClient( Client, ERR_NOSUCHSERVER_MSG, Client_ID( Client ), Req->prefix );
-                       return IRC_WriteStrClientPrefix( target, from, "PONG %s :%s", Client_ID( from ), Req->argv[1] );
+       /* Wrong number of arguments? */
+       if (Req->argc < 1)
+               return IRC_WriteStrClient(Client, ERR_NOORIGIN_MSG,
+                                         Client_ID(Client));
+       if (Req->argc > 2)
+               return IRC_WriteStrClient(Client, ERR_NEEDMOREPARAMS_MSG,
+                                         Client_ID(Client), Req->command);
+
+       /* Forward? */
+       if (Req->argc == 2 && Client_Type(Client) == CLIENT_SERVER) {
+               target = Client_Search(Req->argv[0]);
+               if (!target)
+                       return IRC_WriteStrClient(Client, ERR_NOSUCHSERVER_MSG,
+                                       Client_ID(Client), Req->argv[0]);
+
+               from = Client_Search(Req->prefix);
+
+               if (target != Client_ThisServer() && target != from) {
+                       /* Ok, we have to forward the message. */
+                       if (!from)
+                               return IRC_WriteStrClient(Client,
+                                               ERR_NOSUCHSERVER_MSG,
+                                               Client_ID(Client), Req->prefix);
+
+                       if (Client_Type(Client_NextHop(target)) != CLIENT_SERVER)
+                               s = Client_ID(from);
+                       else
+                               s = Req->argv[0];
+                       return IRC_WriteStrClientPrefix(target, from,
+                                "PONG %s :%s", s, Req->argv[1]);
                }
        }
 
-       /* Der Connection-Timestamp wurde schon beim Lesen aus dem Socket
-        * aktualisiert, daher muss das hier nicht mehr gemacht werden. */
+       /* The connection timestamp has already been updated when the data has
+        * been read from so socket, so we don't need to update it here. */
 
-       if( Client_Conn( Client ) > NONE ) Log( LOG_DEBUG, "Connection %d: received PONG. Lag: %ld seconds.", Client_Conn( Client ), time( NULL ) - Conn_LastPing( Client_Conn( Client )));
-       else Log( LOG_DEBUG, "Connection %d: received PONG.", Client_Conn( Client ));
+       if (Client_Conn(Client) > NONE)
+               Log(LOG_DEBUG,
+                       "Connection %d: received PONG. Lag: %ld seconds.",
+                       Client_Conn(Client),
+                       time(NULL) - Conn_LastPing(Client_Conn(Client)));
+       else
+                Log(LOG_DEBUG,
+                       "Connection %d: received PONG.", Client_Conn(Client));
 
        return CONNECTED;
 } /* IRC_PONG */
@@ -541,9 +598,15 @@ Hello_User( CLIENT *Client )
        if( ! IRC_WriteStrClient( Client, RPL_MYINFO_MSG, Client_ID( Client ), Client_ID( Client_ThisServer( )), PACKAGE_VERSION, USERMODES, CHANMODES )) return false;
 #endif
 
-       /* Features */
-       if( ! IRC_WriteStrClient( Client, RPL_ISUPPORT_MSG, Client_ID( Client ), CLIENT_NICK_LEN - 1,
-                       COMMAND_LEN - 23, CLIENT_AWAY_LEN - 1, Conf_MaxJoins )) return DISCONNECTED;
+       /* Features supported by this server (005 numeric, ISUPPORT),
+        * see <http://www.irc.org/tech_docs/005.html> for details. */
+       if (! IRC_WriteStrClient(Client, RPL_ISUPPORT1_MSG, Client_ID(Client),
+                       Conf_MaxJoins))
+               return DISCONNECTED;
+       if (! IRC_WriteStrClient(Client, RPL_ISUPPORT2_MSG, Client_ID(Client),
+                       CHANNEL_NAME_LEN-1, CLIENT_NICK_LEN-1, COMMAND_LEN-23,
+                       CLIENT_AWAY_LEN-1, COMMAND_LEN-113))
+               return DISCONNECTED;
 
        Client_SetType( Client, CLIENT_USER );