unrealircd

- supernets unrealircd source & configuration
git clone git://git.acid.vegas/unrealircd.git
Log | Files | Refs | Archive | README | LICENSE

reply-tag.c (2804B)

      1 /*
      2  *   IRC - Internet Relay Chat, src/modules/reply-tag.c
      3  *   (C) 2021 Syzop & The UnrealIRCd Team
      4  *
      5  *   See file AUTHORS in IRC package for additional names of
      6  *   the programmers.
      7  *
      8  *   This program is free software; you can redistribute it and/or modify
      9  *   it under the terms of the GNU General Public License as published by
     10  *   the Free Software Foundation; either version 1, or (at your option)
     11  *   any later version.
     12  *
     13  *   This program is distributed in the hope that it will be useful,
     14  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
     15  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     16  *   GNU General Public License for more details.
     17  *
     18  *   You should have received a copy of the GNU General Public License
     19  *   along with this program; if not, write to the Free Software
     20  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
     21  */
     22 
     23 /* This implements https://ircv3.net/specs/client-tags/reply */
     24 
     25 #include "unrealircd.h"
     26 
     27 ModuleHeader MOD_HEADER
     28   = {
     29 	"reply-tag",
     30 	"5.0",
     31 	"+reply client tag",
     32 	"UnrealIRCd Team",
     33 	"unrealircd-6",
     34 	};
     35 
     36 int replytag_mtag_is_ok(Client *client, const char *name, const char *value);
     37 void mtag_add_replytag(Client *client, MessageTag *recv_mtags, MessageTag **mtag_list, const char *signature);
     38 
     39 MOD_INIT()
     40 {
     41 	MessageTagHandlerInfo mtag;
     42 
     43 	MARK_AS_OFFICIAL_MODULE(modinfo);
     44 
     45 #if 0
     46 	memset(&mtag, 0, sizeof(mtag));
     47 	mtag.name = "+reply";
     48 	mtag.is_ok = replytag_mtag_is_ok;
     49 	mtag.flags = MTAG_HANDLER_FLAGS_NO_CAP_NEEDED;
     50 	MessageTagHandlerAdd(modinfo->handle, &mtag);
     51 #endif
     52 
     53 	memset(&mtag, 0, sizeof(mtag));
     54 	mtag.name = "+draft/reply";
     55 	mtag.is_ok = replytag_mtag_is_ok;
     56 	mtag.flags = MTAG_HANDLER_FLAGS_NO_CAP_NEEDED;
     57 	MessageTagHandlerAdd(modinfo->handle, &mtag);
     58 
     59 	HookAddVoid(modinfo->handle, HOOKTYPE_NEW_MESSAGE, 0, mtag_add_replytag);
     60 
     61 	return MOD_SUCCESS;
     62 }
     63 
     64 MOD_LOAD()
     65 {
     66 	return MOD_SUCCESS;
     67 }
     68 
     69 MOD_UNLOAD()
     70 {
     71 	return MOD_SUCCESS;
     72 }
     73 
     74 /** This function verifies if the client sending the mtag is permitted to do so.
     75  */
     76 int replytag_mtag_is_ok(Client *client, const char *name, const char *value)
     77 {
     78 	const char *p;
     79 
     80 	/* Require a non-empty parameter */
     81 	if (BadPtr(value))
     82 		return 0;
     83 
     84 	/* All our PRIVMSG/NOTICE msgid's are of this size: */
     85 	if (strlen(value) != MSGIDLEN)
     86 		return 0;
     87 
     88 	for (p = value; *p; p++)
     89 		if (!isalnum(*p))
     90 			return 0; /* non-alphanumeric */
     91 
     92 	return 1; /* OK */
     93 }
     94 
     95 void mtag_add_replytag(Client *client, MessageTag *recv_mtags, MessageTag **mtag_list, const char *signature)
     96 {
     97 	MessageTag *m;
     98 
     99 	if (IsUser(client))
    100 	{
    101 #if 0
    102 		m = find_mtag(recv_mtags, "+reply");
    103 		if (m)
    104 		{
    105 			m = duplicate_mtag(m);
    106 			AddListItem(m, *mtag_list);
    107 		}
    108 #endif
    109 		m = find_mtag(recv_mtags, "+draft/reply");
    110 		if (m)
    111 		{
    112 			m = duplicate_mtag(m);
    113 			AddListItem(m, *mtag_list);
    114 		}
    115 	}
    116 }