From 4bdf963cdc53286afed1b750d22fde61aa55cb28 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Sat, 27 Feb 2016 02:31:38 -0600 Subject: [PATCH] modules: add cap_server_time, adding server-time cap support --- modules/Makefile.am | 1 + modules/Makefile.in | 73 ++++++++++++++++++++++----------------- modules/cap_server_time.c | 71 +++++++++++++++++++++++++++++++++++++ 3 files changed, 113 insertions(+), 32 deletions(-) create mode 100644 modules/cap_server_time.c diff --git a/modules/Makefile.am b/modules/Makefile.am index 975380a5..0475d084 100644 --- a/modules/Makefile.am +++ b/modules/Makefile.am @@ -9,6 +9,7 @@ auto_load_moddir=@moduledir@/autoload auto_load_mod_LTLIBRARIES = \ cap_account_tag.la \ + cap_server_time.la \ chm_nocolour.la \ chm_noctcp.la \ m_accept.la \ diff --git a/modules/Makefile.in b/modules/Makefile.in index ec4a5726..e771e4ae 100644 --- a/modules/Makefile.in +++ b/modules/Makefile.in @@ -141,6 +141,9 @@ AM_V_lt = $(am__v_lt_@AM_V@) am__v_lt_ = $(am__v_lt_@AM_DEFAULT_V@) am__v_lt_0 = --silent am__v_lt_1 = +cap_server_time_la_LIBADD = +cap_server_time_la_SOURCES = cap_server_time.c +cap_server_time_la_OBJECTS = cap_server_time.lo chm_nocolour_la_LIBADD = chm_nocolour_la_SOURCES = chm_nocolour.c chm_nocolour_la_OBJECTS = chm_nocolour.lo @@ -419,38 +422,39 @@ AM_V_CCLD = $(am__v_CCLD_@AM_V@) am__v_CCLD_ = $(am__v_CCLD_@AM_DEFAULT_V@) am__v_CCLD_0 = @echo " CCLD " $@; am__v_CCLD_1 = -SOURCES = cap_account_tag.c chm_nocolour.c chm_noctcp.c core/m_ban.c \ - core/m_die.c core/m_error.c core/m_join.c core/m_kick.c \ - core/m_kill.c core/m_message.c core/m_mode.c core/m_nick.c \ - core/m_part.c core/m_quit.c core/m_server.c core/m_squit.c \ - m_accept.c m_admin.c m_away.c m_cap.c m_capab.c m_certfp.c \ - m_challenge.c m_chghost.c m_close.c m_cmessage.c m_connect.c \ - m_dline.c m_encap.c m_etrace.c m_grant.c m_help.c m_info.c \ - m_invite.c m_ison.c m_kline.c m_knock.c m_links.c m_list.c \ - m_locops.c m_lusers.c m_map.c m_monitor.c m_motd.c m_names.c \ - m_oper.c m_operspy.c m_pass.c m_ping.c m_pong.c m_post.c \ - m_privs.c m_rehash.c m_restart.c m_resv.c m_sasl.c m_scan.c \ - m_services.c m_set.c m_signon.c m_snote.c m_starttls.c \ - m_stats.c m_svinfo.c m_tb.c m_testline.c m_testmask.c \ - m_tginfo.c m_time.c m_topic.c m_trace.c m_unreject.c m_user.c \ - m_userhost.c m_users.c m_version.c m_wallops.c m_who.c \ - m_whois.c m_whowas.c m_xline.c sno_routing.c -DIST_SOURCES = cap_account_tag.c chm_nocolour.c chm_noctcp.c \ - core/m_ban.c core/m_die.c core/m_error.c core/m_join.c \ - core/m_kick.c core/m_kill.c core/m_message.c core/m_mode.c \ - core/m_nick.c core/m_part.c core/m_quit.c core/m_server.c \ - core/m_squit.c m_accept.c m_admin.c m_away.c m_cap.c m_capab.c \ - m_certfp.c m_challenge.c m_chghost.c m_close.c m_cmessage.c \ - m_connect.c m_dline.c m_encap.c m_etrace.c m_grant.c m_help.c \ - m_info.c m_invite.c m_ison.c m_kline.c m_knock.c m_links.c \ - m_list.c m_locops.c m_lusers.c m_map.c m_monitor.c m_motd.c \ - m_names.c m_oper.c m_operspy.c m_pass.c m_ping.c m_pong.c \ - m_post.c m_privs.c m_rehash.c m_restart.c m_resv.c m_sasl.c \ - m_scan.c m_services.c m_set.c m_signon.c m_snote.c \ - m_starttls.c m_stats.c m_svinfo.c m_tb.c m_testline.c \ - m_testmask.c m_tginfo.c m_time.c m_topic.c m_trace.c \ - m_unreject.c m_user.c m_userhost.c m_users.c m_version.c \ - m_wallops.c m_who.c m_whois.c m_whowas.c m_xline.c \ +SOURCES = cap_account_tag.c cap_server_time.c chm_nocolour.c \ + chm_noctcp.c core/m_ban.c core/m_die.c core/m_error.c \ + core/m_join.c core/m_kick.c core/m_kill.c core/m_message.c \ + core/m_mode.c core/m_nick.c core/m_part.c core/m_quit.c \ + core/m_server.c core/m_squit.c m_accept.c m_admin.c m_away.c \ + m_cap.c m_capab.c m_certfp.c m_challenge.c m_chghost.c \ + m_close.c m_cmessage.c m_connect.c m_dline.c m_encap.c \ + m_etrace.c m_grant.c m_help.c m_info.c m_invite.c m_ison.c \ + m_kline.c m_knock.c m_links.c m_list.c m_locops.c m_lusers.c \ + m_map.c m_monitor.c m_motd.c m_names.c m_oper.c m_operspy.c \ + m_pass.c m_ping.c m_pong.c m_post.c m_privs.c m_rehash.c \ + m_restart.c m_resv.c m_sasl.c m_scan.c m_services.c m_set.c \ + m_signon.c m_snote.c m_starttls.c m_stats.c m_svinfo.c m_tb.c \ + m_testline.c m_testmask.c m_tginfo.c m_time.c m_topic.c \ + m_trace.c m_unreject.c m_user.c m_userhost.c m_users.c \ + m_version.c m_wallops.c m_who.c m_whois.c m_whowas.c m_xline.c \ + sno_routing.c +DIST_SOURCES = cap_account_tag.c cap_server_time.c chm_nocolour.c \ + chm_noctcp.c core/m_ban.c core/m_die.c core/m_error.c \ + core/m_join.c core/m_kick.c core/m_kill.c core/m_message.c \ + core/m_mode.c core/m_nick.c core/m_part.c core/m_quit.c \ + core/m_server.c core/m_squit.c m_accept.c m_admin.c m_away.c \ + m_cap.c m_capab.c m_certfp.c m_challenge.c m_chghost.c \ + m_close.c m_cmessage.c m_connect.c m_dline.c m_encap.c \ + m_etrace.c m_grant.c m_help.c m_info.c m_invite.c m_ison.c \ + m_kline.c m_knock.c m_links.c m_list.c m_locops.c m_lusers.c \ + m_map.c m_monitor.c m_motd.c m_names.c m_oper.c m_operspy.c \ + m_pass.c m_ping.c m_pong.c m_post.c m_privs.c m_rehash.c \ + m_restart.c m_resv.c m_sasl.c m_scan.c m_services.c m_set.c \ + m_signon.c m_snote.c m_starttls.c m_stats.c m_svinfo.c m_tb.c \ + m_testline.c m_testmask.c m_tginfo.c m_time.c m_topic.c \ + m_trace.c m_unreject.c m_user.c m_userhost.c m_users.c \ + m_version.c m_wallops.c m_who.c m_whois.c m_whowas.c m_xline.c \ sno_routing.c am__can_run_installinfo = \ case $$AM_UPDATE_INFO_DIR in \ @@ -664,6 +668,7 @@ AM_LDFLAGS = -module -export-dynamic -avoid-version -no-undefined \ auto_load_moddir = @moduledir@/autoload auto_load_mod_LTLIBRARIES = \ cap_account_tag.la \ + cap_server_time.la \ chm_nocolour.la \ chm_noctcp.la \ m_accept.la \ @@ -855,6 +860,9 @@ clean-moduleLTLIBRARIES: cap_account_tag.la: $(cap_account_tag_la_OBJECTS) $(cap_account_tag_la_DEPENDENCIES) $(EXTRA_cap_account_tag_la_DEPENDENCIES) $(AM_V_CCLD)$(LINK) -rpath $(auto_load_moddir) $(cap_account_tag_la_OBJECTS) $(cap_account_tag_la_LIBADD) $(LIBS) +cap_server_time.la: $(cap_server_time_la_OBJECTS) $(cap_server_time_la_DEPENDENCIES) $(EXTRA_cap_server_time_la_DEPENDENCIES) + $(AM_V_CCLD)$(LINK) -rpath $(auto_load_moddir) $(cap_server_time_la_OBJECTS) $(cap_server_time_la_LIBADD) $(LIBS) + chm_nocolour.la: $(chm_nocolour_la_OBJECTS) $(chm_nocolour_la_DEPENDENCIES) $(EXTRA_chm_nocolour_la_DEPENDENCIES) $(AM_V_CCLD)$(LINK) -rpath $(auto_load_moddir) $(chm_nocolour_la_OBJECTS) $(chm_nocolour_la_LIBADD) $(LIBS) @@ -1126,6 +1134,7 @@ distclean-compile: -rm -f *.tab.c @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cap_account_tag.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cap_server_time.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/chm_nocolour.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/chm_noctcp.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/m_accept.Plo@am__quote@ diff --git a/modules/cap_server_time.c b/modules/cap_server_time.c new file mode 100644 index 00000000..58795f3a --- /dev/null +++ b/modules/cap_server_time.c @@ -0,0 +1,71 @@ +/* + * charybdis: an advanced ircd. + * cap_server_time.c: implement the server-time IRCv3.2 capability + * + * Copyright (c) 2016 William Pitcock + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice is present in all copies. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include "stdinc.h" +#include "modules.h" +#include "hook.h" +#include "client.h" +#include "ircd.h" +#include "send.h" +#include "s_conf.h" +#include "s_user.h" +#include "s_serv.h" +#include "numeric.h" +#include "chmode.h" +#include "inline/stringops.h" + +static void cap_server_time_process(hook_data *); + +mapi_hfn_list_av1 cap_server_time_hfnlist[] = { + { "outbound_msgbuf", (hookfn) cap_server_time_process }, + { NULL, NULL } +}; + +unsigned int CLICAP_SERVER_TIME = 0; + +static void +cap_server_time_process(hook_data *data) +{ + static char buf[IRCD_BUFSIZE]; + time_t ts = rb_current_time(); + struct MsgBuf *msgbuf = data->arg1; + + strftime(buf, sizeof buf, "%Y-%m-%dT%H:%M:%SZ", gmtime(&ts)); + + msgbuf_append_tag(msgbuf, "time", buf, CLICAP_SERVER_TIME); +} + +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"); +} + +DECLARE_MODULE_AV1(cap_server_time, _modinit, _moddeinit, NULL, NULL, cap_server_time_hfnlist, "$Revision$");