unrealircd

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

server-time.c (2581B)

      1 /*
      2  *   IRC - Internet Relay Chat, src/modules/server-time.c
      3  *   (C) 2019 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 	"server-time",
     28 	"5.0",
     29 	"server-time CAP",
     30 	"UnrealIRCd Team",
     31 	"unrealircd-6",
     32 	};
     33 
     34 /* Variables */
     35 long CAP_SERVER_TIME = 0L;
     36 
     37 int server_time_mtag_is_ok(Client *client, const char *name, const char *value);
     38 void mtag_add_or_inherit_time(Client *sender, MessageTag *recv_mtags, MessageTag **mtag_list, const char *signature);
     39 
     40 MOD_INIT()
     41 {
     42 	ClientCapabilityInfo cap;
     43 	ClientCapability *c;
     44 	MessageTagHandlerInfo mtag;
     45 
     46 	MARK_AS_OFFICIAL_MODULE(modinfo);
     47 
     48 	memset(&cap, 0, sizeof(cap));
     49 	cap.name = "server-time";
     50 	c = ClientCapabilityAdd(modinfo->handle, &cap, &CAP_SERVER_TIME);
     51 
     52 	memset(&mtag, 0, sizeof(mtag));
     53 	mtag.name = "time";
     54 	mtag.is_ok = server_time_mtag_is_ok;
     55 	mtag.clicap_handler = c;
     56 	MessageTagHandlerAdd(modinfo->handle, &mtag);
     57 
     58 	HookAddVoid(modinfo->handle, HOOKTYPE_NEW_MESSAGE, 0, mtag_add_or_inherit_time);
     59 
     60 	return MOD_SUCCESS;
     61 }
     62 
     63 MOD_LOAD()
     64 {
     65 	return MOD_SUCCESS;
     66 }
     67 
     68 MOD_UNLOAD()
     69 {
     70 	return MOD_SUCCESS;
     71 }
     72 
     73 /** This function verifies if the client sending
     74  * 'server-time' is permitted to do so and uses a permitted
     75  * syntax.
     76  * We simply allow server-time ONLY from servers.
     77  */
     78 int server_time_mtag_is_ok(Client *client, const char *name, const char *value)
     79 {
     80 	if (IsServer(client) && !BadPtr(value))
     81 		return 1;
     82 
     83 	return 0;
     84 }
     85 
     86 void mtag_add_or_inherit_time(Client *sender, MessageTag *recv_mtags, MessageTag **mtag_list, const char *signature)
     87 {
     88 	MessageTag *m = find_mtag(recv_mtags, "time");
     89 	if (m)
     90 	{
     91 		m = duplicate_mtag(m);
     92 	} else
     93 	{
     94 		m = safe_alloc(sizeof(MessageTag));
     95 		safe_strdup(m->name, "time");
     96 		safe_strdup(m->value, timestamp_iso8601_now());
     97 	}
     98 	AddListItem(m, *mtag_list);
     99 }