]> jfr.im git - solanum.git/blob - modules/cap_server_time.c
Replace RPL_WHOISTEXT(337) with RPL_WHOISSPECIAL(320) (#419)
[solanum.git] / modules / cap_server_time.c
1 /*
2 * Solanum: a slightly advanced ircd
3 * cap_server_time.c: implement the server-time IRCv3.2 capability
4 *
5 * Copyright (c) 2016 Ariadne Conill <ariadne@dereferenced.org>
6 *
7 * Permission to use, copy, modify, and/or distribute this software for any
8 * purpose with or without fee is hereby granted, provided that the above
9 * copyright notice and this permission notice is present in all copies.
10 *
11 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
12 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
13 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
14 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
15 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
16 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
17 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
18 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
19 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
20 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
21 * POSSIBILITY OF SUCH DAMAGE.
22 */
23
24 #include "stdinc.h"
25 #include "modules.h"
26 #include "hook.h"
27 #include "client.h"
28 #include "ircd.h"
29 #include "send.h"
30 #include "s_conf.h"
31 #include "s_user.h"
32 #include "s_serv.h"
33 #include "numeric.h"
34 #include "chmode.h"
35 #include "inline/stringops.h"
36
37 static const char cap_server_time_desc[] =
38 "Provides the server-time client capability";
39
40 static void cap_server_time_process(void *);
41 unsigned int CLICAP_SERVER_TIME = 0;
42
43 mapi_hfn_list_av1 cap_server_time_hfnlist[] = {
44 { "outbound_msgbuf", cap_server_time_process },
45 { NULL, NULL }
46 };
47 mapi_cap_list_av2 cap_server_time_cap_list[] = {
48 { MAPI_CAP_CLIENT, "server-time", NULL, &CLICAP_SERVER_TIME },
49 { 0, NULL, NULL, NULL }
50 };
51
52 static void
53 cap_server_time_process(void *data_)
54 {
55 hook_data *data = data_;
56 static char buf[BUFSIZE];
57 struct MsgBuf *msgbuf = data->arg1;
58 struct timeval tv;
59
60 if (!rb_gettimeofday(&tv, NULL)) {
61 if (strftime(buf, sizeof(buf), "%Y-%m-%dT%H:%M:%S.", gmtime(&tv.tv_sec)) == 0)
62 return;
63
64 if (rb_snprintf_append(buf, sizeof(buf), "%03uZ", (int)tv.tv_usec / 1000) < 0)
65 return;
66
67 msgbuf_append_tag(msgbuf, "time", buf, CLICAP_SERVER_TIME);
68 }
69 }
70
71 DECLARE_MODULE_AV2(cap_server_time, NULL, NULL, NULL, NULL, cap_server_time_hfnlist, cap_server_time_cap_list, NULL, cap_server_time_desc);