]> 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 5329e3c331a2c7b9b8e8bb376f42b056d10d1185..a1348fe2d45333acfa69b4d106b71e205f55d29b 100644 (file)
@@ -9,87 +9,36 @@
  * 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.16 2002/01/05 23:23:20 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.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.
- *
- * Revision 1.12  2002/01/03 02:24:49  alex
- * - neue Befehle NJOIN und SERVER begonnen.
- *
- * Revision 1.11  2002/01/02 02:43:22  alex
- * - Copyright-Texte aktualisiert.
- * - neuer Befehl ERROR.
- *
- * Revision 1.10  2001/12/31 15:33:13  alex
- * - neuer Befehl NAMES, kleinere Bugfixes.
- * - Bug bei PING behoben: war zu restriktiv implementiert :-)
- *
- * Revision 1.9  2001/12/31 02:18:51  alex
- * - viele neue Befehle (WHOIS, ISON, OPER, DIE, RESTART),
- * - neuen Header "defines.h" mit (fast) allen Konstanten.
- * - Code Cleanups und viele "kleine" Aenderungen & Bugfixes.
- *
- * Revision 1.8  2001/12/29 03:08:19  alex
- * - Fuehrende und folgende Leerzeichen etc. in Requests werden geloescht.
- * - Logmeldungen (mal wieder) ein wenig angepasst.
- *
- * Revision 1.7  2001/12/27 19:13:21  alex
- * - neue Befehle NOTICE und PRIVMSG.
- * - Debug-Logging ein wenig reduziert.
- *
- * Revision 1.6  2001/12/26 14:45:37  alex
- * - "Code Cleanups".
- *
- * Revision 1.5  2001/12/26 03:23:03  alex
- * - PING/PONG-Befehle implementiert.
- *
- * Revision 1.4  2001/12/25 22:04:26  alex
- * - Aenderungen an den Debug- und Logging-Funktionen.
- *
- * Revision 1.3  2001/12/25 19:18:36  alex
- * - Gross- und Kleinschreibung der IRC-Befehle wird ignoriert.
- * - bessere Debug-Ausgaben.
- *
- * 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"
 
 
@@ -104,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
@@ -127,7 +66,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 );
@@ -143,6 +82,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;
@@ -151,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" );
@@ -173,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++;
@@ -264,14 +224,32 @@ LOCAL BOOLEAN Handle_Request( CONN_ID Idx, REQUEST *Req )
                /* Befehl ist ein Statuscode */
 
                /* Zielserver ermitteln */
-               if(( Client_Type( client ) == CLIENT_SERVER ) && ( Req->argc > 0 )) target = Client_GetFromID( Req->argv[0] );
+               if(( Client_Type( client ) == CLIENT_SERVER ) && ( Req->argc > 0 )) target = Client_Search( Req->argv[0] );
                else target = NULL;
-               if( ! target ) return TRUE;
+               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] ) return TRUE;
-               else prefix = Client_GetFromID( Req->prefix );
-               if( ! prefix ) return TRUE;
+               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 );
@@ -305,9 +283,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 );
+       else if( strcasecmp( Req->command, "LIST" ) == 0 ) return IRC_LIST( client, Req );
        
        /* Unbekannter Befehl */
-       if( Client_Type( client ) != CLIENT_SERVER ) IRC_WriteStrClient( client, Client_ThisServer( ), ERR_UNKNOWNCOMMAND_MSG, Client_ID( client ), 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;