#include "portab.h"
-static char UNUSED id[] = "$Id: parse.c,v 1.62 2005/06/01 21:52:18 alex Exp $";
+static char UNUSED id[] = "$Id: parse.c,v 1.69 2007/11/21 12:16:36 alex Exp $";
/**
* @file
#include "irc-oper.h"
#include "irc-server.h"
#include "irc-write.h"
+#include "numeric.h"
#include "exp.h"
{ "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 },
{ NULL, NULL, 0x0, 0, 0, 0 } /* Ende-Marke */
};
+NUMERIC My_Numerics[] =
+{
+ { 005, IRC_Num_ISUPPORT },
+ { 376, IRC_Num_ENDOFMOTD },
+ { 0, NULL } /* end marker */
+};
-LOCAL void Init_Request PARAMS(( REQUEST *Req ));
-LOCAL bool Validate_Prefix PARAMS(( CONN_ID Idx, REQUEST *Req, bool *Closed ));
-LOCAL bool Validate_Command PARAMS(( CONN_ID Idx, REQUEST *Req, bool *Closed ));
-LOCAL bool Validate_Args PARAMS(( CONN_ID Idx, REQUEST *Req, bool *Closed ));
+static void Init_Request PARAMS(( REQUEST *Req ));
-LOCAL bool Handle_Request PARAMS(( CONN_ID Idx, REQUEST *Req ));
+static bool Validate_Prefix PARAMS(( CONN_ID Idx, REQUEST *Req, bool *Closed ));
+static bool Validate_Command PARAMS(( CONN_ID Idx, REQUEST *Req, bool *Closed ));
+static bool Validate_Args PARAMS(( CONN_ID Idx, REQUEST *Req, bool *Closed ));
+
+static bool Handle_Request PARAMS(( CONN_ID Idx, REQUEST *Req ));
/**
* Initialize request structure.
* @param Req Request structure to be initialized.
*/
-LOCAL void
+static void
Init_Request( REQUEST *Req )
{
/* Neue Request-Struktur initialisieren */
} /* Init_Request */
-LOCAL bool
+static bool
Validate_Prefix( CONN_ID Idx, REQUEST *Req, bool *Closed )
{
CLIENT *client, *c;
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 */
{
/* 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;
} /* Validate_Prefix */
-LOCAL bool
-Validate_Command( CONN_ID Idx, REQUEST *Req, bool *Closed )
+static bool
+Validate_Command( UNUSED CONN_ID Idx, UNUSED REQUEST *Req, bool *Closed )
{
assert( Idx >= 0 );
assert( Req != NULL );
} /* Validate_Comman */
-LOCAL bool
-Validate_Args( CONN_ID Idx, REQUEST *Req, bool *Closed )
+static bool
+Validate_Args( UNUSED CONN_ID Idx, UNUSED REQUEST *Req, bool *Closed )
{
assert( Idx >= 0 );
assert( Req != NULL );
} /* Validate_Args */
-LOCAL bool
+static bool
Handle_Request( CONN_ID Idx, REQUEST *Req )
{
/* Client-Request verarbeiten. Bei einem schwerwiegenden Fehler
char str[LINE_LEN];
bool result;
COMMAND *cmd;
+ NUMERIC *num;
int i;
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;
}
return IRC_WriteStrClient( client, ERR_NOTREGISTERED_MSG, Client_ID( client ));
}
}
+
+ if( Client_Type( client ) != CLIENT_USER &&
+ Client_Type( client ) != CLIENT_SERVER &&
+ Client_Type( client ) != CLIENT_SERVICE )
+ return true;
- /* Unbekannter Befehl */
- 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" );
- if( Client_Type( client ) != CLIENT_SERVER ) return IRC_WriteStrClient( client, ERR_UNKNOWNCOMMAND_MSG, Client_ID( client ), Req->command );
- else return true;
+ /* Unknown command and registered connection: generate error: */
+ 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" );
+
+ if (Client_Type(client) != CLIENT_SERVER) {
+ result = IRC_WriteStrClient(client, ERR_UNKNOWNCOMMAND_MSG,
+ Client_ID(client), Req->command);
+ Conn_SetPenalty(Idx, 1);
+ return result;
+ }
+
+ return true;
} /* Handle_Request */