about summary refs log tree commit diff
path: root/reply.c
diff options
context:
space:
mode:
authorNakidai <nakidai@disroot.org>2026-01-07 05:59:01 +0300
committerNakidai <nakidai@disroot.org>2026-01-07 05:59:01 +0300
commit8469256066dc37ac89c2258677f9d47adfca2031 (patch)
treee019879792c079cdf0582a16d166f97597814339 /reply.c
parent5cbbb8342feea527bfe3a5650d7c6a461254964a (diff)
downloadlibreircd-8469256066dc37ac89c2258677f9d47adfca2031.tar.gz
libreircd-8469256066dc37ac89c2258677f9d47adfca2031.zip
Add comments for some macros
Diffstat (limited to 'reply.c')
-rw-r--r--reply.c32
1 files changed, 29 insertions, 3 deletions
diff --git a/reply.c b/reply.c
index 06d9f92..eaa56f4 100644
--- a/reply.c
+++ b/reply.c
@@ -32,8 +32,29 @@
 #define GET_M(_0,_1,_2,_3,_4,_5,_6,_7,NAME,...) NAME
 #define ARGS(_0, ...) GET_M(_0,__VA_ARGS__,M7,M6,M5,M4,M3,M2,M1,M0,)(__VA_ARGS__,)
 
+/*
+ * REPLY macro allows to write less boilerplate for each IRC reply
+ * For example,
+ * | REPLY(401, WRITE(
+ * | 	":%s 401 %s %s :No such nick/channel",
+ * | 	hostname,
+ * | 	getnick(peer),
+ * | 	name
+ * | ), name, _);
+ * is unrolled into
+ * | {
+ * | 	const char *name = va_arg(ap, const char *);
+ * | 	return WRITE(
+ * | 		":%s 401 %s %s :No such nick/channel",
+ * | 		hostname,
+ * | 		getnick(peer),
+ * | 		name
+ * | 	);
+ * | }
+ *
+ * Note the `_' argument, it's present as C doesn't support empty __VA_ARGS__
+ */
 #define REPLY(n, action, ...) case n: { ARGS(,__VA_ARGS__); return action; }
-#define WRITE(fmt, ...) writef(peer->fd, fmt, __VA_ARGS__)
 
 
 static int
@@ -41,6 +62,7 @@ vreply(const struct Peer *peer, int number, va_list ap)
 {
 	switch (number)
 	{
+#define WRITE(...) writef(peer->fd, __VA_ARGS__)
 	REPLY(1, WRITE(
 		":%s 001 %s Welcome to the Internet Relay Network %s!%s@%s",
 		hostname,
@@ -111,13 +133,17 @@ vreply(const struct Peer *peer, int number, va_list ap)
 		getnick(peer)
 	), _);
 	REPLY(471, WRITE(
-		peer->fd,
 		":%s 471 %s %s :Cannot join channel (+l)",
 		hostname,
 		getnick(peer),
 		channel
 	), channel, _);
-	default: warnx("YOU FUCKING STUPID SHIT IMPLEMENT REPLY #%d NOW!!!", number); return -1;
+	default: warn("unknown reply: %d", number); WRITE(
+		":%s 421 %s err :Reply %d is not implemented yet",
+		hostname,
+		getnick(peer),
+		number
+	);
 	}
 }