]> arthur.barton.de Git - ngircd-alex.git/blob - src/ngircd/irc-macros.h
New function IRC_KillClient() to kill clients
[ngircd-alex.git] / src / ngircd / irc-macros.h
1 /*
2  * ngIRCd -- The Next Generation IRC Daemon
3  * Copyright (c)2001-2013 Alexander Barton (alex@barton.de) and Contributors.
4  *
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.
10  */
11
12 #ifndef __irc_macros_h__
13 #define __irc_macros_h__
14
15 /**
16  * @file
17  * Macros for functions that handle IRC commands.
18  */
19
20 /**
21  * Make sure that number of passed parameters is equal to Count.
22  *
23  * If there are not exactly Count parameters, send an error to the client and
24  * return from the function.
25  */
26 #define _IRC_ARGC_EQ_OR_RETURN_(Client, Req, Count) \
27 if (Req->argc != Count) { \
28         IRC_SetPenalty(Client, 2); \
29         return IRC_WriteStrClient(Client, ERR_NEEDMOREPARAMS_MSG, \
30                                   Client_ID(Client), Req->command); \
31 }
32
33 /**
34  * Make sure that number of passed parameters is less or equal than Max.
35  *
36  * If there are more than Max parameters, send an error to the client and
37  * return from the function.
38  */
39 #define _IRC_ARGC_LE_OR_RETURN_(Client, Req, Max) \
40 if (Req->argc > Max) { \
41         IRC_SetPenalty(Client, 2); \
42         return IRC_WriteStrClient(Client, ERR_NEEDMOREPARAMS_MSG, \
43                                   Client_ID(Client), Req->command); \
44 }
45
46 /**
47  * Make sure that number of passed parameters is greater or equal than Min.
48  *
49  * If there aren't at least Min parameters, send an error to the client and
50  * return from the function.
51  */
52 #define _IRC_ARGC_GE_OR_RETURN_(Client, Req, Min) \
53 if (Req->argc < Min) { \
54         IRC_SetPenalty(Client, 2); \
55         return IRC_WriteStrClient(Client, ERR_NEEDMOREPARAMS_MSG, \
56                                   Client_ID(Client), Req->command); \
57 }
58
59 /**
60  * Make sure that number of passed parameters is in between Min and Max.
61  *
62  * If there aren't at least Min parameters or if there are more than Max
63  * parameters, send an error to the client and return from the function.
64  */
65 #define _IRC_ARGC_BETWEEN_OR_RETURN_(Client, Req, Min, Max) \
66 if (Req->argc < Min || Req->argc > Max) { \
67         IRC_SetPenalty(Client, 2); \
68         return IRC_WriteStrClient(Client, ERR_NEEDMOREPARAMS_MSG, \
69                                   Client_ID(Client), Req->command); \
70 }
71
72 /**
73  * Get sender of an IRC command.
74  *
75  * The sender is either stored in the prefix if the command has been
76  * received from a server or set to the client. If the sender is invalid,
77  * send an error to the client and return from the function.
78  */
79 #define _IRC_GET_SENDER_OR_RETURN_(Sender, Req, Client) \
80         if (Client_Type(Client) == CLIENT_SERVER) \
81                 Sender = Client_Search(Req->prefix); \
82         else \
83                 Sender = Client; \
84         if (!Sender) \
85                 return IRC_WriteStrClient(Client, ERR_NOSUCHNICK_MSG, \
86                                           Client_ID(Client), Req->prefix);
87
88 /**
89  * Get target of an IRC command and make sure that it is a server.
90  *
91  * Set the target to the local server if no target parameter is given in the
92  * received command, and send an error to the client and return from the
93  * function if the given target isn't resolvable to a server: the target
94  * parameter can be a server name, a nick name (then the target is set to
95  * the server to which this nick is connected), or a mask matching at least
96  * one server name in the network.
97  */
98 #define _IRC_GET_TARGET_SERVER_OR_RETURN_(Target, Req, Argc, From) \
99         if (Req->argc > Argc) { \
100                 Target = Client_Search(Req->argv[Argc]); \
101                 if (!Target) \
102                         Target = Client_SearchServer(Req->argv[Argc]); \
103                 if (!Target) \
104                         return IRC_WriteStrClient(From, ERR_NOSUCHSERVER_MSG, \
105                                           Client_ID(From), Req->argv[Argc]); \
106                 if (Client_Type(Target) != CLIENT_SERVER) \
107                         Target = Client_Introducer(Target); \
108         } else \
109                 Target = Client_ThisServer();
110
111 #endif  /* __irc_macros_h__ */
112
113 /* -eof- */