X-Git-Url: https://jfr.im/git/solanum.git/blobdiff_plain/4bdf963cdc53286afed1b750d22fde61aa55cb28..f57d88bc71c1a5f7bdd9c3a77b04bc9e6535b63f:/modules/cap_server_time.c diff --git a/modules/cap_server_time.c b/modules/cap_server_time.c index 58795f3a..1fd383fd 100644 --- a/modules/cap_server_time.c +++ b/modules/cap_server_time.c @@ -1,5 +1,5 @@ /* - * charybdis: an advanced ircd. + * Solanum: a slightly advanced ircd * cap_server_time.c: implement the server-time IRCv3.2 capability * * Copyright (c) 2016 William Pitcock @@ -34,38 +34,37 @@ #include "chmode.h" #include "inline/stringops.h" +static const char cap_server_time_desc[] = + "Provides the server-time client capability"; + static void cap_server_time_process(hook_data *); +unsigned int CLICAP_SERVER_TIME = 0; mapi_hfn_list_av1 cap_server_time_hfnlist[] = { { "outbound_msgbuf", (hookfn) cap_server_time_process }, { NULL, NULL } }; - -unsigned int CLICAP_SERVER_TIME = 0; +mapi_cap_list_av2 cap_server_time_cap_list[] = { + { MAPI_CAP_CLIENT, "server-time", NULL, &CLICAP_SERVER_TIME }, + { 0, NULL, NULL, NULL } +}; static void cap_server_time_process(hook_data *data) { - static char buf[IRCD_BUFSIZE]; - time_t ts = rb_current_time(); + static char buf[BUFSIZE]; struct MsgBuf *msgbuf = data->arg1; + struct timeval tv; - strftime(buf, sizeof buf, "%Y-%m-%dT%H:%M:%SZ", gmtime(&ts)); + if (!rb_gettimeofday(&tv, NULL)) { + if (strftime(buf, sizeof(buf), "%Y-%m-%dT%H:%M:%S.", gmtime(&tv.tv_sec)) == 0) + return; - msgbuf_append_tag(msgbuf, "time", buf, CLICAP_SERVER_TIME); -} + if (rb_snprintf_append(buf, sizeof(buf), "%03uZ", (int)tv.tv_usec / 1000) < 0) + return; -static int -_modinit(void) -{ - CLICAP_SERVER_TIME = capability_put(cli_capindex, "server-time", NULL); - return 0; -} - -static void -_moddeinit(void) -{ - capability_orphan(cli_capindex, "server-time"); + msgbuf_append_tag(msgbuf, "time", buf, CLICAP_SERVER_TIME); + } } -DECLARE_MODULE_AV1(cap_server_time, _modinit, _moddeinit, NULL, NULL, cap_server_time_hfnlist, "$Revision$"); +DECLARE_MODULE_AV2(cap_server_time, NULL, NULL, NULL, NULL, cap_server_time_hfnlist, cap_server_time_cap_list, NULL, cap_server_time_desc);