2013-02-09 23:55:42 +01:00
|
|
|
/*
|
|
|
|
* ngIRCd -- The Next Generation IRC Daemon
|
2013-08-06 23:36:10 +02:00
|
|
|
* Copyright (c)2001-2013 Alexander Barton (alex@barton.de) and Contributors.
|
2013-02-09 23:55:42 +01:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
* Please read the file COPYING, README and AUTHORS for more information.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __irc_macros_h__
|
|
|
|
#define __irc_macros_h__
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @file
|
|
|
|
* Macros for functions that handle IRC commands.
|
|
|
|
*/
|
|
|
|
|
2013-02-24 16:20:27 +01:00
|
|
|
/**
|
|
|
|
* Make sure that number of passed parameters is equal to Count.
|
|
|
|
*
|
|
|
|
* If there are not exactly Count parameters, send an error to the client and
|
|
|
|
* return from the function.
|
|
|
|
*/
|
|
|
|
#define _IRC_ARGC_EQ_OR_RETURN_(Client, Req, Count) \
|
2013-07-30 22:08:04 +02:00
|
|
|
if (Req->argc != Count) { \
|
2013-11-06 19:28:09 +01:00
|
|
|
return IRC_WriteErrClient(Client, ERR_NEEDMOREPARAMS_MSG, \
|
2013-07-30 22:08:04 +02:00
|
|
|
Client_ID(Client), Req->command); \
|
|
|
|
}
|
2013-02-24 16:20:27 +01:00
|
|
|
|
2013-02-09 23:55:42 +01:00
|
|
|
/**
|
|
|
|
* Make sure that number of passed parameters is less or equal than Max.
|
|
|
|
*
|
|
|
|
* If there are more than Max parameters, send an error to the client and
|
|
|
|
* return from the function.
|
|
|
|
*/
|
|
|
|
#define _IRC_ARGC_LE_OR_RETURN_(Client, Req, Max) \
|
2013-07-30 22:08:04 +02:00
|
|
|
if (Req->argc > Max) { \
|
2013-11-06 19:28:09 +01:00
|
|
|
return IRC_WriteErrClient(Client, ERR_NEEDMOREPARAMS_MSG, \
|
2013-07-30 22:08:04 +02:00
|
|
|
Client_ID(Client), Req->command); \
|
|
|
|
}
|
2013-02-09 23:55:42 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Make sure that number of passed parameters is greater or equal than Min.
|
|
|
|
*
|
|
|
|
* If there aren't at least Min parameters, send an error to the client and
|
|
|
|
* return from the function.
|
|
|
|
*/
|
|
|
|
#define _IRC_ARGC_GE_OR_RETURN_(Client, Req, Min) \
|
2013-07-30 22:08:04 +02:00
|
|
|
if (Req->argc < Min) { \
|
2013-11-06 19:28:09 +01:00
|
|
|
return IRC_WriteErrClient(Client, ERR_NEEDMOREPARAMS_MSG, \
|
2013-07-30 22:08:04 +02:00
|
|
|
Client_ID(Client), Req->command); \
|
|
|
|
}
|
2013-02-09 23:55:42 +01:00
|
|
|
|
2013-02-24 16:14:13 +01:00
|
|
|
/**
|
|
|
|
* Make sure that number of passed parameters is in between Min and Max.
|
|
|
|
*
|
|
|
|
* If there aren't at least Min parameters or if there are more than Max
|
|
|
|
* parameters, send an error to the client and return from the function.
|
|
|
|
*/
|
|
|
|
#define _IRC_ARGC_BETWEEN_OR_RETURN_(Client, Req, Min, Max) \
|
2013-07-30 22:08:04 +02:00
|
|
|
if (Req->argc < Min || Req->argc > Max) { \
|
2013-11-06 19:28:09 +01:00
|
|
|
return IRC_WriteErrClient(Client, ERR_NEEDMOREPARAMS_MSG, \
|
2013-07-30 22:08:04 +02:00
|
|
|
Client_ID(Client), Req->command); \
|
|
|
|
}
|
2013-02-24 16:14:13 +01:00
|
|
|
|
2013-02-09 23:55:42 +01:00
|
|
|
/**
|
|
|
|
* Get sender of an IRC command.
|
|
|
|
*
|
|
|
|
* The sender is either stored in the prefix if the command has been
|
|
|
|
* received from a server or set to the client. If the sender is invalid,
|
|
|
|
* send an error to the client and return from the function.
|
|
|
|
*/
|
|
|
|
#define _IRC_GET_SENDER_OR_RETURN_(Sender, Req, Client) \
|
|
|
|
if (Client_Type(Client) == CLIENT_SERVER) \
|
|
|
|
Sender = Client_Search(Req->prefix); \
|
|
|
|
else \
|
|
|
|
Sender = Client; \
|
|
|
|
if (!Sender) \
|
2013-11-07 11:45:34 +01:00
|
|
|
return IRC_WriteErrClient(Client, ERR_NOSUCHNICK_MSG, \
|
2013-02-09 23:55:42 +01:00
|
|
|
Client_ID(Client), Req->prefix);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get target of an IRC command and make sure that it is a server.
|
|
|
|
*
|
|
|
|
* Set the target to the local server if no target parameter is given in the
|
|
|
|
* received command, and send an error to the client and return from the
|
|
|
|
* function if the given target isn't resolvable to a server: the target
|
|
|
|
* parameter can be a server name, a nick name (then the target is set to
|
|
|
|
* the server to which this nick is connected), or a mask matching at least
|
|
|
|
* one server name in the network.
|
|
|
|
*/
|
|
|
|
#define _IRC_GET_TARGET_SERVER_OR_RETURN_(Target, Req, Argc, From) \
|
|
|
|
if (Req->argc > Argc) { \
|
|
|
|
Target = Client_Search(Req->argv[Argc]); \
|
|
|
|
if (!Target) \
|
|
|
|
Target = Client_SearchServer(Req->argv[Argc]); \
|
|
|
|
if (!Target) \
|
2013-11-07 11:45:34 +01:00
|
|
|
return IRC_WriteErrClient(From, ERR_NOSUCHSERVER_MSG, \
|
2013-02-09 23:55:42 +01:00
|
|
|
Client_ID(From), Req->argv[Argc]); \
|
|
|
|
if (Client_Type(Target) != CLIENT_SERVER) \
|
|
|
|
Target = Client_Introducer(Target); \
|
|
|
|
} else \
|
|
|
|
Target = Client_ThisServer();
|
|
|
|
|
|
|
|
#endif /* __irc_macros_h__ */
|
|
|
|
|
|
|
|
/* -eof- */
|