From c54bb115aad74f9f59e67ad7996332aabe64b8f8 Mon Sep 17 00:00:00 2001 From: dequis Date: Sat, 5 Dec 2015 23:34:12 -0300 Subject: IRCv3 userhost-in-names capability Easiest part of ircv3.2 --- irc.h | 1 + irc_cap.c | 1 + irc_send.c | 13 +++++++++++-- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/irc.h b/irc.h index 9374473c..350719f5 100644 --- a/irc.h +++ b/irc.h @@ -71,6 +71,7 @@ typedef enum { CAP_MULTI_PREFIX = (1 << 1), CAP_EXTENDED_JOIN = (1 << 2), CAP_AWAY_NOTIFY = (1 << 3), + CAP_USERHOST_IN_NAMES = (1 << 4), } irc_cap_flag_t; struct irc_user; diff --git a/irc_cap.c b/irc_cap.c index 65d9b2ef..42f70529 100644 --- a/irc_cap.c +++ b/irc_cap.c @@ -41,6 +41,7 @@ static const cap_info_t supported_caps[] = { {"multi-prefix", CAP_MULTI_PREFIX}, {"extended-join", CAP_EXTENDED_JOIN}, {"away-notify", CAP_AWAY_NOTIFY}, + {"userhost-in-names", CAP_USERHOST_IN_NAMES}, {NULL}, }; diff --git a/irc_send.c b/irc_send.c index 954c5322..4511d667 100644 --- a/irc_send.c +++ b/irc_send.c @@ -207,6 +207,7 @@ void irc_send_names(irc_channel_t *ic) { GSList *l; GString *namelist = g_string_sized_new(IRC_NAMES_LEN); + gboolean uhnames = (ic->irc->caps & CAP_USERHOST_IN_NAMES); /* RFCs say there is no error reply allowed on NAMES, so when the channel is invalid, just give an empty reply. */ @@ -216,6 +217,10 @@ void irc_send_names(irc_channel_t *ic) size_t extra_len = strlen(iu->nick); char prefix; + if (uhnames) { + extra_len += strlen(iu->user) + strlen(iu->host) + 2; + } + if (namelist->len + extra_len > IRC_NAMES_LEN - 4) { irc_send_num(ic->irc, 353, "= %s :%s", ic->name, namelist->str); g_string_truncate(namelist, 0); @@ -225,8 +230,12 @@ void irc_send_names(irc_channel_t *ic) g_string_append_c(namelist, prefix); } - g_string_append(namelist, iu->nick); - g_string_append_c(namelist, ' '); + if (uhnames) { + g_string_append_printf(namelist, "%s!%s@%s ", iu->nick, iu->user, iu->host); + } else { + g_string_append(namelist, iu->nick); + g_string_append_c(namelist, ' '); + } } if (namelist->len) { -- cgit v1.2.3