]> arthur.barton.de Git - ngircd-alex.git/blobdiff - src/ngircd/parse.c
- Sourcen auf weitere Module fuer IRC-Befehle aufgesplitted.
[ngircd-alex.git] / src / ngircd / parse.c
index ef8459645acb10a63f9d6bc37f4997cdd8f413e1..44b853e06f62a9dedd79d60c7b929a3a454e3cd9 100644 (file)
@@ -9,11 +9,60 @@
  * Naehere Informationen entnehmen Sie bitter der Datei COPYING. Eine Liste
  * der an ngIRCd beteiligten Autoren finden Sie in der Datei AUTHORS.
  *
- * $Id: parse.c,v 1.13 2002/01/04 01:20:02 alex Exp $
+ * $Id: parse.c,v 1.29 2002/03/03 17:17:38 alex Exp $
  *
  * parse.c: Parsen der Client-Anfragen
  *
  * $Log: parse.c,v $
+ * Revision 1.29  2002/03/03 17:17:38  alex
+ * - Sourcen auf weitere Module fuer IRC-Befehle aufgesplitted.
+ * - IRC-Befehl WHO implementiert.
+ *
+ * Revision 1.28  2002/02/27 23:25:31  alex
+ * - Anpassungen an Aufteilung von irc.d, Init- und Exit-Funktionen entfernt.
+ *
+ * Revision 1.27  2002/02/27 20:33:13  alex
+ * - Channel-Topics implementiert.
+ *
+ * Revision 1.26  2002/02/27 18:23:46  alex
+ * - IRC-Befehl "AWAY" implementert.
+ *
+ * Revision 1.25  2002/02/26 20:52:15  alex
+ * - Fehler bei Fehlermeldung wg. unbekanntem Prefix behoben.
+ *
+ * Revision 1.24  2002/02/23 21:39:48  alex
+ * - IRC-Befehl KILL sowie Kills bei Nick Collsisions implementiert.
+ *
+ * Revision 1.23  2002/02/17 23:38:58  alex
+ * - neuer IRC-Befehl VERSION implementiert: IRC_VERSION().
+ *
+ * Revision 1.22  2002/01/21 00:01:37  alex
+ * - neue Befehle JOIN und PART.
+ *
+ * Revision 1.21  2002/01/18 11:12:11  alex
+ * - der Sniffer wird nun nur noch aktiviert, wenn auf Kommandozeile angegeben.
+ *
+ * Revision 1.20  2002/01/11 23:50:55  alex
+ * - LINKS implementiert, LUSERS begonnen.
+ *
+ * Revision 1.19  2002/01/09 01:08:42  alex
+ * - Parses handhabt Leerzeichen zw. Parametern nun etwas "lockerer".
+ *
+ * Revision 1.18  2002/01/07 15:29:11  alex
+ * - Status-Codes an den Server selber werden ignoriert, besseres Logging.
+ *
+ * Revision 1.17  2002/01/06 17:41:44  alex
+ * - die Fehlermeldung "unbekannter Befehl" hatte ein falsches Format.
+ *
+ * Revision 1.16  2002/01/05 23:23:20  alex
+ * - generisches Forwarding von Zahlen-Statuscodes implementiert.
+ *
+ * Revision 1.15  2002/01/05 01:42:08  alex
+ * - an Server werden keine ERRORS mehr wegen unbekannter Befehle geschickt.
+ *
+ * Revision 1.14  2002/01/04 17:56:45  alex
+ * - neuer Befehl SQUIT.
+ *
  * Revision 1.13  2002/01/04 01:20:02  alex
  * - Client-Strukruren werden nur noch ueber Funktionen angesprochen.
  *
 
 #include <imp.h>
 #include <assert.h>
+#include <stdlib.h>
 #include <stdio.h>
 #include <string.h>
 
+#include "ngircd.h"
 #include "client.h"
 #include "conn.h"
 #include "irc.h"
+#include "irc-channel.h"
+#include "irc-login.h"
+#include "irc-mode.h"
+#include "irc-oper.h"
+#include "irc-server.h"
+#include "irc-write.h"
 #include "log.h"
 #include "messages.h"
 #include "tool.h"
@@ -94,16 +151,6 @@ LOCAL BOOLEAN Validate_Args( REQUEST *Req );
 LOCAL BOOLEAN Handle_Request( CONN_ID Idx, REQUEST *Req );
 
 
-GLOBAL VOID Parse_Init( VOID )
-{
-} /* Parse_Init */
-
-
-GLOBAL VOID Parse_Exit( VOID )
-{
-} /* Parse_Exit */
-
-
 GLOBAL BOOLEAN Parse_Request( CONN_ID Idx, CHAR *Request )
 {
        /* Client-Request parsen. Bei einem schwerwiegenden Fehler wird
@@ -117,7 +164,7 @@ GLOBAL BOOLEAN Parse_Request( CONN_ID Idx, CHAR *Request )
        assert( Request != NULL );
 
 #ifdef SNIFFER
-       Log( LOG_DEBUG, " <- connection %d: '%s'.", Idx, Request );
+       if( NGIRCd_Sniffer ) Log( LOG_DEBUG, " <- connection %d: '%s'.", Idx, Request );
 #endif
        
        Init_Request( &req );
@@ -133,6 +180,11 @@ GLOBAL BOOLEAN Parse_Request( CONN_ID Idx, CHAR *Request )
                ptr = strchr( Request, ' ' );
                if( ! ptr ) return Parse_Error( Idx, "Prefix without command!?" );
                *ptr = '\0';
+#ifndef STRICT_RFC
+               /* multiple Leerzeichen als Trenner zwischen
+                * Prefix und Befehl ignorieren */
+               while( *(ptr + 1) == ' ' ) ptr++;
+#endif
                start = ptr + 1;
        }
        else start = Request;
@@ -141,7 +193,15 @@ GLOBAL BOOLEAN Parse_Request( CONN_ID Idx, CHAR *Request )
 
        /* Befehl */
        ptr = strchr( start, ' ' );
-       if( ptr ) *ptr = '\0';
+       if( ptr )
+       {
+               *ptr = '\0';
+#ifndef STRICT_RFC
+               /* multiple Leerzeichen als Trenner vor
+               *Parametertrennern ignorieren */
+               while( *(ptr + 1) == ' ' ) ptr++;
+#endif
+       }
        req.command = start;
 
        if( ! Validate_Command( &req )) return Parse_Error( Idx, "Invalid command" );
@@ -163,7 +223,15 @@ GLOBAL BOOLEAN Parse_Request( CONN_ID Idx, CHAR *Request )
                        {
                                req.argv[req.argc] = start;
                                ptr = strchr( start, ' ' );
-                               if( ptr ) *ptr = '\0';
+                               if( ptr )
+                               {
+                                       *ptr = '\0';
+#ifndef STRICT_RFC
+                                       /* multiple Leerzeichen als
+                                        * Parametertrenner ignorieren */
+                                       while( *(ptr + 1) == ' ' ) ptr++;
+#endif
+                               }
                        }
                        
                        req.argc++;
@@ -237,7 +305,9 @@ LOCAL BOOLEAN Handle_Request( CONN_ID Idx, REQUEST *Req )
        /* Client-Request verarbeiten. Bei einem schwerwiegenden Fehler
         * wird die Verbindung geschlossen und FALSE geliefert. */
 
-       CLIENT *client;
+       CLIENT *client, *target, *prefix;
+       CHAR str[LINE_LEN];
+       INT i;
 
        assert( Idx >= 0 );
        assert( Req != NULL );
@@ -246,12 +316,57 @@ LOCAL BOOLEAN Handle_Request( CONN_ID Idx, REQUEST *Req )
        client = Client_GetFromConn( Idx );
        assert( client != NULL );
 
+       /* Statuscode, der geforwarded werden muss? */
+       if(( strlen( Req->command ) == 3 ) && ( atoi( Req->command ) > 100 ))
+       {
+               /* Befehl ist ein Statuscode */
+
+               /* Zielserver ermitteln */
+               if(( Client_Type( client ) == CLIENT_SERVER ) && ( Req->argc > 0 )) target = Client_GetFromID( Req->argv[0] );
+               else target = NULL;
+               if( ! target )
+               {
+                       if( Req->argc > 0 ) Log( LOG_WARNING, "Unknown target for status code: \"%s\"", Req->argv[0] );
+                       else Log( LOG_WARNING, "Unknown target for status code!" );
+                       return TRUE;
+               }
+               if( target == Client_ThisServer( ))
+               {
+                       Log( LOG_DEBUG, "Ignored status code %s from \"%s\".", Req->command, Client_ID( client ));
+                       return TRUE;
+               }
+
+               /* Quell-Client ermitteln */
+               if( ! Req->prefix[0] )
+               {
+                       Log( LOG_WARNING, "Got status code without prefix!?" );
+                       return TRUE;
+               }
+               else prefix = Client_GetFromID( Req->prefix );
+               if( ! prefix )
+               {
+                       Log( LOG_WARNING, "Got status code from unknown source: \"%s\"", Req->prefix );
+                       return TRUE;
+               }
+
+               /* Statuscode weiterleiten */
+               strcpy( str, Req->command );
+               for( i = 0; i < Req->argc; i++ )
+               {
+                       if( i < Req->argc - 1 ) strcat( str, " " );
+                       else strcat( str, " :" );
+                       strcat( str, Req->argv[i] );
+               }
+               return IRC_WriteStrClientPrefix( target, prefix, str );
+       }
+
        if( strcasecmp( Req->command, "PASS" ) == 0 ) return IRC_PASS( client, Req );
        else if( strcasecmp( Req->command, "NICK" ) == 0 ) return IRC_NICK( client, Req );
        else if( strcasecmp( Req->command, "USER" ) == 0 ) return IRC_USER( client, Req );
        else if( strcasecmp( Req->command, "SERVER" ) == 0 ) return IRC_SERVER( client, Req );
        else if( strcasecmp( Req->command, "NJOIN" ) == 0 ) return IRC_NJOIN( client, Req );
        else if( strcasecmp( Req->command, "QUIT" ) == 0 ) return IRC_QUIT( client, Req );
+       else if( strcasecmp( Req->command, "SQUIT" ) == 0 ) return IRC_SQUIT( client, Req );
        else if( strcasecmp( Req->command, "PING" ) == 0 ) return IRC_PING( client, Req );
        else if( strcasecmp( Req->command, "PONG" ) == 0 ) return IRC_PONG( client, Req );
        else if( strcasecmp( Req->command, "MOTD" ) == 0 ) return IRC_MOTD( client, Req );
@@ -266,10 +381,19 @@ LOCAL BOOLEAN Handle_Request( CONN_ID Idx, REQUEST *Req )
        else if( strcasecmp( Req->command, "DIE" ) == 0 ) return IRC_DIE( client, Req );
        else if( strcasecmp( Req->command, "RESTART" ) == 0 ) return IRC_RESTART( client, Req );
        else if( strcasecmp( Req->command, "ERROR" ) == 0 ) return IRC_ERROR( client, Req );
+       else if( strcasecmp( Req->command, "LUSERS" ) == 0 ) return IRC_LUSERS( client, Req );
+       else if( strcasecmp( Req->command, "LINKS" ) == 0 ) return IRC_LINKS( client, Req );
+       else if( strcasecmp( Req->command, "JOIN" ) == 0 ) return IRC_JOIN( client, Req );
+       else if( strcasecmp( Req->command, "PART" ) == 0 ) return IRC_PART( client, Req );
+       else if( strcasecmp( Req->command, "VERSION" ) == 0 ) return IRC_VERSION( client, Req );
+       else if( strcasecmp( Req->command, "KILL" ) == 0 ) return IRC_KILL( client, Req );
+       else if( strcasecmp( Req->command, "AWAY" ) == 0 ) return IRC_AWAY( client, Req );
+       else if( strcasecmp( Req->command, "TOPIC" ) == 0 ) return IRC_TOPIC( client, Req );
+       else if( strcasecmp( Req->command, "WHO" ) == 0 ) return IRC_WHO( client, Req );
        
        /* Unbekannter Befehl */
-       IRC_WriteStrClient( client, Client_ThisServer( ), ERR_UNKNOWNCOMMAND_MSG, Client_ID( client ), Req->command );
-       Log( LOG_DEBUG, "User \"%s\": Unknown command \"%s\", %d %s,%s prefix.", Client_Mask( client ), Req->command, Req->argc, Req->argc == 1 ? "parameter" : "parameters", Req->prefix ? "" : " no" );
+       if( Client_Type( client ) != CLIENT_SERVER ) IRC_WriteStrClient( client, ERR_UNKNOWNCOMMAND_MSG, Client_ID( client ), Req->command );
+       Log( LOG_DEBUG, "Connection %d: Unknown command \"%s\", %d %s,%s prefix.", Client_Conn( client ), Req->command, Req->argc, Req->argc == 1 ? "parameter" : "parameters", Req->prefix ? "" : " no" );
 
        return TRUE;
 } /* Handle_Request */