From 61f7dd746ee75924b186ec7a71d6301449e5e089 Mon Sep 17 00:00:00 2001 From: Valerie Pond <79415174+ValwareIRC@users.noreply.github.com> Date: Fri, 13 May 2022 06:39:41 +0100 Subject: [PATCH] Add IRCv3 +draft/channel-context (#205) https://github.com/delthas/ircv3-specifications/blob/feature-channel/client-tags/channel-context.md --- Makefile.windows | 4 ++ doc/conf/modules.default.conf | 1 + src/modules/Makefile.in | 2 +- src/modules/channel-context.c | 95 +++++++++++++++++++++++++++++++++++ 4 files changed, 101 insertions(+), 1 deletion(-) create mode 100644 src/modules/channel-context.c diff --git a/Makefile.windows b/Makefile.windows index b8c405df5..877b5f1a9 100644 --- a/Makefile.windows +++ b/Makefile.windows @@ -381,6 +381,7 @@ DLL_FILES=\ src/modules/trace.dll \ src/modules/tsctl.dll \ src/modules/typing-indicator.dll \ + src/modules/channel-context.dll \ src/modules/umode2.dll \ src/modules/unreal_server_compat.dll \ src/modules/unsqline.dll \ @@ -1214,6 +1215,9 @@ src/modules/tsctl.dll: src/modules/tsctl.c $(INCLUDES) src/modules/typing-indicator.dll: src/modules/typing-indicator.c $(INCLUDES) $(CC) $(MODCFLAGS) src/modules/typing-indicator.c /Fesrc/modules/ /Fosrc/modules/ /Fdsrc/modules/typing-indicator.pdb $(MODLFLAGS) +src/modules/channel-context.dll: src/modules/channel-context.c $(INCLUDES) + $(CC) $(MODCFLAGS) src/modules/channel-context.c /Fesrc/modules/ /Fosrc/modules/ /Fdsrc/modules/channel-context.pdb $(MODLFLAGS) + src/modules/umode2.dll: src/modules/umode2.c $(INCLUDES) $(CC) $(MODCFLAGS) src/modules/umode2.c /Fesrc/modules/ /Fosrc/modules/ /Fdsrc/modules/umode2.pdb $(MODLFLAGS) diff --git a/doc/conf/modules.default.conf b/doc/conf/modules.default.conf index 2994633bd..4877ee352 100644 --- a/doc/conf/modules.default.conf +++ b/doc/conf/modules.default.conf @@ -218,6 +218,7 @@ loadmodule "echo-message"; /* shows clients if their messages are altered/filter loadmodule "labeled-response"; /* correlate requests and responses easily */ loadmodule "bot-tag"; /* indicate the message comes from a bot (draft/bot) */ loadmodule "typing-indicator"; /* typing indicator in PM and channels (+typing) */ +loadmodule "channel-context"; loadmodule "reply-tag"; /* indicate to which message you are responding (+draft/reply) */ loadmodule "clienttagdeny"; /* informs clients about supported client-only message tags */ loadmodule "sts"; /* strict transport policy (set::tls::sts-policy) */ diff --git a/src/modules/Makefile.in b/src/modules/Makefile.in index 1fd736792..02204b331 100644 --- a/src/modules/Makefile.in +++ b/src/modules/Makefile.in @@ -73,7 +73,7 @@ MODULES= \ message-ids.so plaintext-policy.so server-time.so sts.so \ echo-message.so userip-tag.so userhost-tag.so geoip-tag.so \ bot-tag.so reply-tag.so json-log-tag.so \ - typing-indicator.so \ + typing-indicator.so channel-context.so \ ident_lookup.so history.so chathistory.so \ targetfloodprot.so clienttagdeny.so watch-backend.so \ monitor.so slog.so tls_cipher.so operinfo.so \ diff --git a/src/modules/channel-context.c b/src/modules/channel-context.c new file mode 100644 index 000000000..23194e2de --- /dev/null +++ b/src/modules/channel-context.c @@ -0,0 +1,95 @@ +/* + * IRC - Internet Relay Chat, src/modules/channel-context.c + * (C) 2022 Valware & The UnrealIRCd Team + * + * See file AUTHORS in IRC package for additional names of + * the programmers. + * + * 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 1, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +#include "unrealircd.h" + +ModuleHeader MOD_HEADER + = { + "channel-context", + "1.0", + "Channel Context (IRCv3)", + "UnrealIRCd team", + "unrealircd-6", + }; + +int chancontext_mtag_is_ok(Client *client, const char *name, const char *value); +void mtag_add_chancontext(Client *client, MessageTag *recv_mtags, MessageTag **mtag_list, const char *signature); + +MOD_INIT() +{ + MessageTagHandlerInfo mtag; + + MARK_AS_OFFICIAL_MODULE(modinfo); + + memset(&mtag, 0, sizeof(mtag)); + mtag.is_ok = chancontext_mtag_is_ok; + mtag.flags = MTAG_HANDLER_FLAGS_NO_CAP_NEEDED; + mtag.name = "+draft/channel-context"; + MessageTagHandlerAdd(modinfo->handle, &mtag); + + HookAddVoid(modinfo->handle, HOOKTYPE_NEW_MESSAGE, 0, mtag_add_chancontext); + + return MOD_SUCCESS; +} + +MOD_LOAD() +{ + return MOD_SUCCESS; +} + +MOD_UNLOAD() +{ + return MOD_SUCCESS; +} + +int chancontext_mtag_is_ok(Client *client, const char *name, const char *value) +{ + Channel *channel; + + if (BadPtr(value)) + return 0; + + channel = find_channel(value); + + if (!channel) + return 0; + + if (!IsMember(client, channel) && !IsULine(client)) + return 0; + + return 1; +} + +void mtag_add_chancontext(Client *client, MessageTag *recv_mtags, MessageTag **mtag_list, const char *signature) +{ + MessageTag *m; + + if (IsUser(client)) + { + m = find_mtag(recv_mtags, "+draft/channel-context"); + if (m) + { + m = duplicate_mtag(m); + AddListItem(m, *mtag_list); + } + } +}