2 * ngIRCd -- The Next Generation IRC Daemon
3 * Copyright (c)2001-2013 Alexander Barton (alex@barton.de).
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 * Please read the file COPYING, README and AUTHORS for more information.
12 #ifndef __irc_macros_h__
13 #define __irc_macros_h__
17 * Macros for functions that handle IRC commands.
21 * Make sure that number of passed parameters is equal to Count.
23 * If there are not exactly Count parameters, send an error to the client and
24 * return from the function.
26 #define _IRC_ARGC_EQ_OR_RETURN_(Client, Req, Count) \
27 if (Req->argc != Count) \
28 return IRC_WriteStrClient(Client, ERR_NEEDMOREPARAMS_MSG, \
29 Client_ID(Client), Req->command);
32 * Make sure that number of passed parameters is less or equal than Max.
34 * If there are more than Max parameters, send an error to the client and
35 * return from the function.
37 #define _IRC_ARGC_LE_OR_RETURN_(Client, Req, Max) \
38 if (Req->argc > Max) \
39 return IRC_WriteStrClient(Client, ERR_NEEDMOREPARAMS_MSG, \
40 Client_ID(Client), Req->command);
43 * Make sure that number of passed parameters is greater or equal than Min.
45 * If there aren't at least Min parameters, send an error to the client and
46 * return from the function.
48 #define _IRC_ARGC_GE_OR_RETURN_(Client, Req, Min) \
49 if (Req->argc < Min) \
50 return IRC_WriteStrClient(Client, ERR_NEEDMOREPARAMS_MSG, \
51 Client_ID(Client), Req->command);
54 * Make sure that number of passed parameters is in between Min and Max.
56 * If there aren't at least Min parameters or if there are more than Max
57 * parameters, send an error to the client and return from the function.
59 #define _IRC_ARGC_BETWEEN_OR_RETURN_(Client, Req, Min, Max) \
60 if (Req->argc < Min || Req->argc > Max) \
61 return IRC_WriteStrClient(Client, ERR_NEEDMOREPARAMS_MSG, \
62 Client_ID(Client), Req->command);
65 * Get sender of an IRC command.
67 * The sender is either stored in the prefix if the command has been
68 * received from a server or set to the client. If the sender is invalid,
69 * send an error to the client and return from the function.
71 #define _IRC_GET_SENDER_OR_RETURN_(Sender, Req, Client) \
72 if (Client_Type(Client) == CLIENT_SERVER) \
73 Sender = Client_Search(Req->prefix); \
77 return IRC_WriteStrClient(Client, ERR_NOSUCHNICK_MSG, \
78 Client_ID(Client), Req->prefix);
81 * Get target of an IRC command and make sure that it is a server.
83 * Set the target to the local server if no target parameter is given in the
84 * received command, and send an error to the client and return from the
85 * function if the given target isn't resolvable to a server: the target
86 * parameter can be a server name, a nick name (then the target is set to
87 * the server to which this nick is connected), or a mask matching at least
88 * one server name in the network.
90 #define _IRC_GET_TARGET_SERVER_OR_RETURN_(Target, Req, Argc, From) \
91 if (Req->argc > Argc) { \
92 Target = Client_Search(Req->argv[Argc]); \
94 Target = Client_SearchServer(Req->argv[Argc]); \
96 return IRC_WriteStrClient(From, ERR_NOSUCHSERVER_MSG, \
97 Client_ID(From), Req->argv[Argc]); \
98 if (Client_Type(Target) != CLIENT_SERVER) \
99 Target = Client_Introducer(Target); \
101 Target = Client_ThisServer();
103 #endif /* __irc_macros_h__ */