]> arthur.barton.de Git - ngircd-alex.git/commitdiff
Add new irc-macros.h to project
authorAlexander Barton <alex@barton.de>
Sat, 9 Feb 2013 22:55:42 +0000 (23:55 +0100)
committerAlexander Barton <alex@barton.de>
Sat, 9 Feb 2013 22:55:42 +0000 (23:55 +0100)
This file prvides some macros for common tasks required by functions
implementing handlers for IRC commands:

 * _IRC_ARGC_LE_OR_RETURN_
 * _IRC_ARGC_GE_OR_RETURN_
 * _IRC_GET_SENDER_OR_RETURN_
 * _IRC_GET_TARGET_SERVER_OR_RETURN_

contrib/MacOSX/ngIRCd.xcodeproj/project.pbxproj
src/ngircd/Makefile.ng
src/ngircd/irc-macros.h [new file with mode: 0644]

index a2cad27cae528f51980965eb0d666564e42c8da0..02502cc65b2a4918ca8f9f67d9b1834771bc90aa 100644 (file)
 /* Begin PBXFileReference section */
                FA1A6BBC0D6857BB00AA8F71 /* misc-test.e */ = {isa = PBXFileReference; fileEncoding = 5; lastKnownFileType = text; path = "misc-test.e"; sourceTree = "<group>"; };
                FA1A6BBD0D6857D900AA8F71 /* who-test.e */ = {isa = PBXFileReference; fileEncoding = 5; lastKnownFileType = text; path = "who-test.e"; sourceTree = "<group>"; };
+               FA1DBB6716C707D200D4F838 /* irc-macros.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "irc-macros.h"; sourceTree = "<group>"; };
                FA2D564811EA158B00D37A35 /* pam.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = pam.h; sourceTree = "<group>"; };
                FA2D564911EA158B00D37A35 /* pam.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = pam.c; sourceTree = "<group>"; };
                FA2D567A11EA1AB300D37A35 /* libpam.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libpam.dylib; path = usr/lib/libpam.dylib; sourceTree = SDKROOT; };
-               FA322BBA0CEF72E4001761B3 /* ngIRCd */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = ngIRCd; sourceTree = BUILT_PRODUCTS_DIR; };
+               FA322BBA0CEF72E4001761B3 /* ngIRCd */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; name = ngIRCd; path = ngircd; sourceTree = BUILT_PRODUCTS_DIR; };
                FA322CD60CEF74B1001761B3 /* Makefile.am */ = {isa = PBXFileReference; fileEncoding = 5; lastKnownFileType = text; path = Makefile.am; sourceTree = "<group>"; };
                FA322CD90CEF74B1001761B3 /* array.c */ = {isa = PBXFileReference; fileEncoding = 5; lastKnownFileType = sourcecode.c.c; path = array.c; sourceTree = "<group>"; };
                FA322CDA0CEF74B1001761B3 /* array.h */ = {isa = PBXFileReference; fileEncoding = 5; lastKnownFileType = sourcecode.c.h; path = array.h; sourceTree = "<group>"; };
                                FA322CEF0CEF74B1001761B3 /* irc-info.h */,
                                FA322CF00CEF74B1001761B3 /* irc-login.c */,
                                FA322CF10CEF74B1001761B3 /* irc-login.h */,
+                               FA1DBB6716C707D200D4F838 /* irc-macros.h */,
                                FA4F1659164836B100DBD011 /* irc-metadata.c */,
                                FA4F165C164836BF00DBD011 /* irc-metadata.h */,
                                FA322CF20CEF74B1001761B3 /* irc-mode.c */,
index cdbd27c11b2f48728d5c8b7548eca1e468acebef..21e606d7433a675311c11be3b566c42d34b52c79 100644 (file)
@@ -86,6 +86,7 @@ noinst_HEADERS = \
        irc-encoding.h \
        irc-info.h \
        irc-login.h \
+       irc-macros.h \
        irc-metadata.h \
        irc-mode.h \
        irc-op.h \
diff --git a/src/ngircd/irc-macros.h b/src/ngircd/irc-macros.h
new file mode 100644 (file)
index 0000000..bd63ec4
--- /dev/null
@@ -0,0 +1,83 @@
+/*
+ * ngIRCd -- The Next Generation IRC Daemon
+ * Copyright (c)2001-2013 Alexander Barton (alex@barton.de).
+ *
+ * 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.
+ */
+
+/**
+ * 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) \
+if (Req->argc > Max) \
+       return IRC_WriteStrClient(Client, ERR_NEEDMOREPARAMS_MSG, \
+                                 Client_ID(Client), Req->command);
+
+/**
+ * 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) \
+if (Req->argc < Min) \
+       return IRC_WriteStrClient(Client, ERR_NEEDMOREPARAMS_MSG, \
+                                 Client_ID(Client), Req->command);
+
+/**
+ * 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) \
+               return IRC_WriteStrClient(Client, ERR_NOSUCHNICK_MSG, \
+                                         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) \
+                       return IRC_WriteStrClient(From, ERR_NOSUCHSERVER_MSG, \
+                                         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- */