[BACK]Return to irc-macros.h CVS log [TXT][DIR] Up to [local] / ircnowd / src / ngircd

Annotation of ircnowd/src/ngircd/irc-macros.h, Revision 1.1

1.1     ! tomglok     1: /*
        !             2:  * ngIRCd -- The Next Generation IRC Daemon
        !             3:  * Copyright (c)2001-2015 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:        return IRC_WriteErrClient(Client, ERR_NEEDMOREPARAMS_MSG, \
        !            29:                                  Client_ID(Client), Req->command); \
        !            30: }
        !            31:
        !            32: /**
        !            33:  * Make sure that number of passed parameters is less or equal than Max.
        !            34:  *
        !            35:  * If there are more than Max parameters, send an error to the client and
        !            36:  * return from the function.
        !            37:  */
        !            38: #define _IRC_ARGC_LE_OR_RETURN_(Client, Req, Max) \
        !            39: if (Req->argc > Max) { \
        !            40:        return IRC_WriteErrClient(Client, ERR_NEEDMOREPARAMS_MSG, \
        !            41:                                  Client_ID(Client), Req->command); \
        !            42: }
        !            43:
        !            44: /**
        !            45:  * Make sure that number of passed parameters is greater or equal than Min.
        !            46:  *
        !            47:  * If there aren't at least Min parameters, send an error to the client and
        !            48:  * return from the function.
        !            49:  */
        !            50: #define _IRC_ARGC_GE_OR_RETURN_(Client, Req, Min) \
        !            51: if (Req->argc < Min) { \
        !            52:        return IRC_WriteErrClient(Client, ERR_NEEDMOREPARAMS_MSG, \
        !            53:                                  Client_ID(Client), Req->command); \
        !            54: }
        !            55:
        !            56: /**
        !            57:  * Make sure that number of passed parameters is in between Min and Max.
        !            58:  *
        !            59:  * If there aren't at least Min parameters or if there are more than Max
        !            60:  * parameters, send an error to the client and return from the function.
        !            61:  */
        !            62: #define _IRC_ARGC_BETWEEN_OR_RETURN_(Client, Req, Min, Max) \
        !            63: if (Req->argc < Min || Req->argc > Max) { \
        !            64:        return IRC_WriteErrClient(Client, ERR_NEEDMOREPARAMS_MSG, \
        !            65:                                  Client_ID(Client), Req->command); \
        !            66: }
        !            67:
        !            68: /**
        !            69:  * Make sure that the command has a prefix.
        !            70:  *
        !            71:  * If there is no prefix, send an error to the client and return from
        !            72:  * the function.
        !            73:  */
        !            74: #define _IRC_REQUIRE_PREFIX_OR_RETURN_(Client, Req) \
        !            75: if (!Req->prefix) { \
        !            76:        return IRC_WriteErrClient(Client, ERR_NEEDMOREPARAMS_MSG, \
        !            77:                                  Client_ID(Client), Req->command); \
        !            78: }
        !            79:
        !            80: /**
        !            81:  * Get sender of an IRC command.
        !            82:  *
        !            83:  * The sender is either stored in the prefix if the command has been
        !            84:  * received from a server or set to the client. If the sender is invalid,
        !            85:  * send an error to the client and return from the function.
        !            86:  */
        !            87: #define _IRC_GET_SENDER_OR_RETURN_(Sender, Req, Client) \
        !            88:        if (Client_Type(Client) == CLIENT_SERVER) { \
        !            89:                if (!Req->prefix) \
        !            90:                        return IRC_WriteErrClient(Client, ERR_NEEDMOREPARAMS_MSG, \
        !            91:                                                  Client_ID(Client), Req->command); \
        !            92:                Sender = Client_Search(Req->prefix); \
        !            93:        } else \
        !            94:                Sender = Client; \
        !            95:        if (!Sender) \
        !            96:                return IRC_WriteErrClient(Client, ERR_NOSUCHNICK_MSG, \
        !            97:                                          Client_ID(Client), \
        !            98:                                          Req->prefix ? Req->prefix : "(none)");
        !            99:
        !           100: /**
        !           101:  * Get target of an IRC command and make sure that it is a server.
        !           102:  *
        !           103:  * Set the target to the local server if no target parameter is given in the
        !           104:  * received command, and send an error to the client and return from the
        !           105:  * function if the given target isn't resolvable to a server: the target
        !           106:  * parameter can be a server name, a nick name (then the target is set to
        !           107:  * the server to which this nick is connected), or a mask matching at least
        !           108:  * one server name in the network.
        !           109:  */
        !           110: #define _IRC_GET_TARGET_SERVER_OR_RETURN_(Target, Req, Argc, From) \
        !           111:        if (Req->argc > Argc) { \
        !           112:                Target = Client_Search(Req->argv[Argc]); \
        !           113:                if (!Target) \
        !           114:                        Target = Client_SearchServer(Req->argv[Argc]); \
        !           115:                if (!Target) \
        !           116:                        return IRC_WriteErrClient(From, ERR_NOSUCHSERVER_MSG, \
        !           117:                                          Client_ID(From), Req->argv[Argc]); \
        !           118:                if (Client_Type(Target) != CLIENT_SERVER) \
        !           119:                        Target = Client_Introducer(Target); \
        !           120:        } else \
        !           121:                Target = Client_ThisServer();
        !           122:
        !           123: #endif /* __irc_macros_h__ */
        !           124:
        !           125: /* -eof- */

CVSweb