]> arthur.barton.de Git - ngircd.git/blobdiff - src/ngircd/parse.c
[Parser]: Don't use Client_Type after command has been processed.
[ngircd.git] / src / ngircd / parse.c
index 5896a027718d8544fdb987fd38f45dcdac14b8aa..f77d5b08d88ba062327825c28447145e60933156 100644 (file)
@@ -12,7 +12,7 @@
 
 #include "portab.h"
 
-static char UNUSED id[] = "$Id: parse.c,v 1.66 2005/09/04 23:42:24 alex Exp $";
+static char UNUSED id[] = "$Id: parse.c,v 1.69.2.1 2008/02/05 13:11:20 fw Exp $";
 
 /**
  * @file
@@ -48,6 +48,7 @@ static char UNUSED id[] = "$Id: parse.c,v 1.66 2005/09/04 23:42:24 alex Exp $";
 #include "irc-oper.h"
 #include "irc-server.h"
 #include "irc-write.h"
+#include "numeric.h"
 
 #include "exp.h"
 
@@ -93,6 +94,7 @@ COMMAND My_Commands[] =
        { "USER", IRC_USER, 0xFFFF, 0, 0, 0 },
        { "USERHOST", IRC_USERHOST, CLIENT_USER, 0, 0, 0 },
        { "VERSION", IRC_VERSION, CLIENT_USER|CLIENT_SERVER, 0, 0, 0 },
+       { "WALLOPS", IRC_WALLOPS, CLIENT_USER|CLIENT_SERVER, 0, 0, 0 },
        { "WHO", IRC_WHO, CLIENT_USER, 0, 0, 0 },
        { "WHOIS", IRC_WHOIS, CLIENT_USER|CLIENT_SERVER, 0, 0, 0 },
        { "WHOWAS", IRC_WHOWAS, CLIENT_USER|CLIENT_SERVER, 0, 0, 0 },
@@ -102,6 +104,13 @@ COMMAND My_Commands[] =
        { NULL, NULL, 0x0, 0, 0, 0 } /* Ende-Marke */
 };
 
+NUMERIC My_Numerics[] =
+{
+       { 005, IRC_Num_ISUPPORT },
+       { 376, IRC_Num_ENDOFMOTD },
+       { 0, NULL } /* end marker */
+};
+
 
 static void Init_Request PARAMS(( REQUEST *Req ));
 
@@ -277,7 +286,7 @@ Validate_Prefix( CONN_ID Idx, REQUEST *Req, bool *Closed )
        if( ! Req->prefix ) return true;
 
        /* Client-Struktur der Connection ermitteln */
-       client = Client_GetFromConn( Idx );
+       client = Conn_GetClient( Idx );
        assert( client != NULL );
 
        /* nur validieren, wenn bereits registrierte Verbindung */
@@ -306,7 +315,7 @@ Validate_Prefix( CONN_ID Idx, REQUEST *Req, bool *Closed )
        {
                /* 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( Client_GetFromConn( 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);
                *Closed = true;
                return false;
@@ -348,34 +357,55 @@ Handle_Request( CONN_ID Idx, REQUEST *Req )
        char str[LINE_LEN];
        bool result;
        COMMAND *cmd;
-       int i;
+       NUMERIC *num;
+       int i, client_type;
 
        assert( Idx >= 0 );
        assert( Req != NULL );
        assert( Req->command != NULL );
 
-       client = Client_GetFromConn( Idx );
+       client = Conn_GetClient( Idx );
        assert( client != NULL );
 
-       /* Statuscode? */
-       if(( Client_Type( client ) == CLIENT_SERVER ) && ( strlen( Req->command ) == 3 ) && ( atoi( Req->command ) > 100 ))
-       {
-               /* Command is a status code from an other server */
+       /* Numeric? */
+       if ((Client_Type(client) == CLIENT_SERVER ||
+            Client_Type(client) == CLIENT_UNKNOWNSERVER)
+           && strlen(Req->command) == 3 && atoi(Req->command) > 1) {
+               /* Command is a status code ("numeric") from an other server */
 
                /* Determine target */
-               if( Req->argc > 0 ) target = Client_Search( Req->argv[0] );
-               else target = NULL;
-               if( ! target )
-               {
+               if (Req->argc > 0)
+                       target = Client_Search( Req->argv[0] );
+               else
+                       target = NULL;
+               if (!target) {
                        /* Status code without target!? */
-                       if( Req->argc > 0 ) Log( LOG_WARNING, "Unknown target for status code %s: \"%s\"", Req->command, Req->argv[0] );
-                       else Log( LOG_WARNING, "Unknown target for status code %s!", Req->command );
+                       if (Req->argc > 0)
+                               Log(LOG_WARNING,
+                                   "Unknown target for status code %s: \"%s\"",
+                                   Req->command, Req->argv[0]);
+                       else
+                               Log(LOG_WARNING,
+                                   "Unknown target for status code %s!",
+                                   Req->command);
                        return true;
                }
-               if( target == Client_ThisServer( ))
-               {
-                       /* This server is the target, ignore it */
-                       Log( LOG_DEBUG, "Ignored status code %s from \"%s\".", Req->command, Client_ID( client ));
+               if (target == Client_ThisServer()) {
+                       /* This server is the target of the numeric */
+                       i = atoi(Req->command);
+
+                       num = My_Numerics;
+                       while (num->numeric > 0) {
+                               if (i != num->numeric) {
+                                       num++;
+                                       continue;
+                               }
+                               result = (num->function)(client, Req);
+                               return result;
+                       }
+                       
+                       LogDebug("Ignored status code %s from \"%s\".",
+                                Req->command, Client_ID(client));
                        return true;
                }
 
@@ -406,6 +436,7 @@ Handle_Request( CONN_ID Idx, REQUEST *Req )
        }
 
        cmd = My_Commands;
+       client_type = Client_Type(client);
        while( cmd->name )
        {
                /* Befehl suchen */
@@ -414,7 +445,7 @@ Handle_Request( CONN_ID Idx, REQUEST *Req )
                        cmd++; continue;
                }
 
-               if( Client_Type( client ) & cmd->type )
+               if( client_type & cmd->type )
                {
                        /* Command is allowed for this client: call it and count produced bytes */
                        Conn_ResetWCounter( );
@@ -422,7 +453,7 @@ Handle_Request( CONN_ID Idx, REQUEST *Req )
                        cmd->bytes += Conn_WCounter( );
 
                        /* Adjust counters */
-                       if( Client_Type( client ) != CLIENT_SERVER ) cmd->lcount++;
+                       if( client_type != CLIENT_SERVER ) cmd->lcount++;
                        else cmd->rcount++;
 
                        return result;