unrealircd

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

typing-indicator.c (2660B)

      1 /*
      2  *   IRC - Internet Relay Chat, src/modules/typing-indicator.c
      3  *   (C) 2020 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 #include "unrealircd.h"
     24 
     25 ModuleHeader MOD_HEADER
     26   = {
     27 	"typing-indicator",
     28 	"5.0",
     29 	"+typing client tag",
     30 	"UnrealIRCd Team",
     31 	"unrealircd-6",
     32 	};
     33 
     34 int ti_mtag_is_ok(Client *client, const char *name, const char *value);
     35 void mtag_add_ti(Client *client, MessageTag *recv_mtags, MessageTag **mtag_list, const char *signature);
     36 
     37 MOD_INIT()
     38 {
     39 	MessageTagHandlerInfo mtag;
     40 
     41 	MARK_AS_OFFICIAL_MODULE(modinfo);
     42 
     43 	memset(&mtag, 0, sizeof(mtag));
     44 	mtag.name = "+typing";
     45 	mtag.is_ok = ti_mtag_is_ok;
     46 	mtag.flags = MTAG_HANDLER_FLAGS_NO_CAP_NEEDED;
     47 	MessageTagHandlerAdd(modinfo->handle, &mtag);
     48 
     49 	memset(&mtag, 0, sizeof(mtag));
     50 	mtag.name = "+draft/typing";
     51 	mtag.is_ok = ti_mtag_is_ok;
     52 	mtag.flags = MTAG_HANDLER_FLAGS_NO_CAP_NEEDED;
     53 	MessageTagHandlerAdd(modinfo->handle, &mtag);
     54 
     55 	HookAddVoid(modinfo->handle, HOOKTYPE_NEW_MESSAGE, 0, mtag_add_ti);
     56 
     57 	return MOD_SUCCESS;
     58 }
     59 
     60 MOD_LOAD()
     61 {
     62 	return MOD_SUCCESS;
     63 }
     64 
     65 MOD_UNLOAD()
     66 {
     67 	return MOD_SUCCESS;
     68 }
     69 
     70 /** This function verifies if the client sending the mtag is permitted to do so.
     71  */
     72 int ti_mtag_is_ok(Client *client, const char *name, const char *value)
     73 {
     74 	/* Require a non-empty parameter */
     75 	if (BadPtr(value))
     76 		return 0;
     77 
     78 	/* These are the only valid values: */
     79 	if (!strcmp(value, "active") || !strcmp(value, "paused") || !strcmp(value, "done"))
     80 		return 1;
     81 
     82 	/* All the rest is considered illegal */
     83 	return 0;
     84 }
     85 
     86 void mtag_add_ti(Client *client, MessageTag *recv_mtags, MessageTag **mtag_list, const char *signature)
     87 {
     88 	MessageTag *m;
     89 
     90 	if (IsUser(client))
     91 	{
     92 		m = find_mtag(recv_mtags, "+typing");
     93 		if (m)
     94 		{
     95 			m = duplicate_mtag(m);
     96 			AddListItem(m, *mtag_list);
     97 		}
     98 		m = find_mtag(recv_mtags, "+draft/typing");
     99 		if (m)
    100 		{
    101 			m = duplicate_mtag(m);
    102 			AddListItem(m, *mtag_list);
    103 		}
    104 	}
    105 }