]> arthur.barton.de Git - ngircd-alex.git/blobdiff - src/ngircd/parse.c
- Neue IRC-Funktion LIST implementiert.
[ngircd-alex.git] / src / ngircd / parse.c
index cd3d95d4bdfc5bf8509037a225527f204fc73514..a1348fe2d45333acfa69b4d106b71e205f55d29b 100644 (file)
@@ -1,44 +1,44 @@
 /*
  * ngIRCd -- The Next Generation IRC Daemon
- * Copyright (c)2001 by Alexander Barton (alex@barton.de)
+ * Copyright (c)2001,2002 by Alexander Barton (alex@barton.de)
  *
  * Dieses Programm ist freie Software. Sie koennen es unter den Bedingungen
  * der GNU General Public License (GPL), wie von der Free Software Foundation
  * herausgegeben, weitergeben und/oder modifizieren, entweder unter Version 2
  * der Lizenz oder (wenn Sie es wuenschen) jeder spaeteren Version.
  * Naehere Informationen entnehmen Sie bitter der Datei COPYING. Eine Liste
- * der an comBase beteiligten Autoren finden Sie in der Datei AUTHORS.
+ * der an ngIRCd beteiligten Autoren finden Sie in der Datei AUTHORS.
  *
- * $Id: parse.c,v 1.2 2001/12/23 21:56:47 alex Exp $
+ * $Id: parse.c,v 1.32 2002/04/23 19:50:27 alex Exp $
  *
  * parse.c: Parsen der Client-Anfragen
- *
- * $Log: parse.c,v $
- * Revision 1.2  2001/12/23 21:56:47  alex
- * - bessere Debug-Ausgaben,
- * - Bug im Parameter-Parser behoben (bei "langem" Parameter)
- * - erste IRC-Befehle werden erkannt :-)
- *
- * Revision 1.1  2001/12/21 23:53:16  alex
- * - Modul zum Parsen von Client-Requests begonnen.
  */
 
 
-#include <portab.h>
-#include "global.h"
+#include "portab.h"
 
-#include <imp.h>
+#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 "defines.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"
 
-#include <exp.h>
+#include "exp.h"
 #include "parse.h"
 
 
@@ -53,16 +53,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
@@ -75,20 +65,28 @@ GLOBAL BOOLEAN Parse_Request( CONN_ID Idx, CHAR *Request )
        assert( Idx >= 0 );
        assert( Request != NULL );
 
-#ifdef DEBUG
-       Log( LOG_DEBUG, " <- connection %d: '%s'.", Idx, Request );
+#ifdef SNIFFER
+       if( NGIRCd_Sniffer ) Log( LOG_DEBUG, " <- connection %d: '%s'.", Idx, Request );
 #endif
        
        Init_Request( &req );
 
+       /* Fuehrendes und folgendes "Geraffel" verwerfen */
+       ngt_TrimStr( Request );
+
        /* gibt es ein Prefix? */
        if( Request[0] == ':' )
        {
                /* Prefix vorhanden */
                req.prefix = Request + 1;
                ptr = strchr( Request, ' ' );
-               if( ! ptr ) return Parse_Error( Idx, "Invalid prefix (command missing!?)" );
+               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;
@@ -97,7 +95,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" );
@@ -119,7 +125,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++;
@@ -133,7 +147,7 @@ GLOBAL BOOLEAN Parse_Request( CONN_ID Idx, CHAR *Request )
        }
        
        if( ! Validate_Args( &req )) return Parse_Error( Idx, "Invalid argument(s)" );
-       
+
        return Handle_Request( Idx, &req );
 } /* Parse_Request */
 
@@ -159,13 +173,11 @@ LOCAL BOOLEAN Parse_Error( CONN_ID Idx, CHAR *Error )
         * TRUE: Connection wurde durch diese Funktion nicht geschlossen,
         * FALSE: Connection wurde terminiert. */
        
-       CHAR msg[256];
-       
        assert( Idx >= 0 );
        assert( Error != NULL );
 
-       sprintf( msg, "Parse error: %s!", Error );
-       return Conn_WriteStr( Idx, msg );
+       Log( LOG_DEBUG, "Connection %d: Parse error: %s", Idx, Error );
+       return Conn_WriteStr( Idx, "ERROR :Parse error: %s", Error );
 } /* Parse_Error */
 
 
@@ -195,25 +207,96 @@ 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 );
        assert( Req->command != NULL );
 
-#ifdef DEBUG
-       Log( LOG_DEBUG, "    connection %d: '%s', %d %s,%s prefix.", Idx, Req->command, Req->argc, Req->argc == 1 ? "parameter" : "parameters", Req->prefix ? "" : " no" );
-#endif
-
        client = Client_GetFromConn( Idx );
        assert( client != NULL );
 
-       if( strcmp( Req->command, "PASS" ) == 0 ) return IRC_PASS( client, Req );
-       else if( strcmp( Req->command, "NICK" ) == 0 ) return IRC_NICK( client, Req );
-       else if( strcmp( Req->command, "USER" ) == 0 ) return IRC_USER( client, Req );
+       /* 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_Search( 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_Search( 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 );
+       else if( strcasecmp( Req->command, "PRIVMSG" ) == 0 ) return IRC_PRIVMSG( client, Req );
+       else if( strcasecmp( Req->command, "NOTICE" ) == 0 ) return IRC_NOTICE( client, Req );
+       else if( strcasecmp( Req->command, "MODE" ) == 0 ) return IRC_MODE( client, Req );
+       else if( strcasecmp( Req->command, "NAMES" ) == 0 ) return IRC_NAMES( client, Req );
+       else if( strcasecmp( Req->command, "ISON" ) == 0 ) return IRC_ISON( client, Req );
+       else if( strcasecmp( Req->command, "WHOIS" ) == 0 ) return IRC_WHOIS( client, Req );
+       else if( strcasecmp( Req->command, "USERHOST" ) == 0 ) return IRC_USERHOST( client, Req );
+       else if( strcasecmp( Req->command, "OPER" ) == 0 ) return IRC_OPER( client, 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 );
+       else if( strcasecmp( Req->command, "LIST" ) == 0 ) return IRC_LIST( client, Req );
+       
        /* Unbekannter Befehl */
-       Conn_WriteStr( Idx, ERR_UNKNOWNCOMMAND_MSG, Req->command );
+       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 */