diff --git a/CHANGELOG.md b/CHANGELOG.md index 3d2352903..22cfa576a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ - relay/weechat: add line id in buffer lines sent to clients - relay: display connection status in output of commands `/remote list` and `/remote listfull` - relay: add option `reconnect` in command `/remote` ([#2160](https://github.com/weechat/weechat/issues/2160)) +- irc: add support of message 569 (whois, connecting from) ([#2162](https://github.com/weechat/weechat/issues/2162)) - api: allow NULL value for key in hashtable - doc: rename doc "weechat_relay_protocol" to "weechat_relay_weechat" diff --git a/src/plugins/irc/irc-protocol.c b/src/plugins/irc/irc-protocol.c index f80ead19a..928f548a2 100644 --- a/src/plugins/irc/irc-protocol.c +++ b/src/plugins/irc/irc-protocol.c @@ -4414,26 +4414,35 @@ IRC_PROTOCOL_CALLBACK(306) IRC_PROTOCOL_CALLBACK(whois_nick_msg) { char *str_params; + int extra_param; IRC_PROTOCOL_MIN_PARAMS(2); if (ctxt->num_params >= 3) { - str_params = irc_protocol_string_params (ctxt->params, 2, ctxt->num_params - 1); + str_params = irc_protocol_string_params ( + ctxt->params, + (ctxt->num_params >= 4) ? 3 : 2, + ctxt->num_params - 1); + extra_param = (ctxt->num_params >= 4) + && (strcmp (ctxt->params[2], "*") != 0); weechat_printf_datetime_tags ( irc_msgbuffer_get_target_buffer ( ctxt->server, ctxt->params[1], ctxt->command, "whois", NULL), ctxt->date, ctxt->date_usec, irc_protocol_tags (ctxt, NULL), - "%s%s[%s%s%s] %s%s", + "%s%s[%s%s%s] %s%s%s%s%s", weechat_prefix ("network"), IRC_COLOR_CHAT_DELIMITERS, irc_nick_color_for_msg (ctxt->server, 1, NULL, ctxt->params[1]), ctxt->params[1], IRC_COLOR_CHAT_DELIMITERS, IRC_COLOR_RESET, - str_params); + str_params, + (extra_param) ? " (" : "", + (extra_param) ? ctxt->params[2] : "", + (extra_param) ? ")" : ""); free (str_params); } else @@ -5469,7 +5478,7 @@ IRC_PROTOCOL_CALLBACK(341) IRC_PROTOCOL_CALLBACK(344) { - char *str_host, *str_params; + char *str_host; IRC_PROTOCOL_MIN_PARAMS(3); @@ -5494,36 +5503,7 @@ IRC_PROTOCOL_CALLBACK(344) else { /* whois, geo info (UnrealIRCd) */ - if (ctxt->num_params >= 3) - { - str_params = irc_protocol_string_params ( - ctxt->params, - (ctxt->num_params >= 4) ? 3 : 2, - ctxt->num_params - 1); - weechat_printf_datetime_tags ( - irc_msgbuffer_get_target_buffer ( - ctxt->server, ctxt->params[1], ctxt->command, "whois", NULL), - ctxt->date, - ctxt->date_usec, - irc_protocol_tags (ctxt, NULL), - "%s%s[%s%s%s] %s%s%s%s%s", - weechat_prefix ("network"), - IRC_COLOR_CHAT_DELIMITERS, - irc_nick_color_for_msg (ctxt->server, 1, NULL, ctxt->params[1]), - ctxt->params[1], - IRC_COLOR_CHAT_DELIMITERS, - IRC_COLOR_RESET, - str_params, - (ctxt->num_params >= 4) ? " (" : "", - (ctxt->num_params >= 4) ? ctxt->params[2] : "", - (ctxt->num_params >= 4) ? ")" : ""); - free (str_params); - } - else - { - /* not enough arguments: use the default whois callback */ - irc_protocol_cb_whois_nick_msg (ctxt); - } + irc_protocol_cb_whois_nick_msg (ctxt); } return WEECHAT_RC_OK; @@ -8087,6 +8067,7 @@ irc_protocol_recv_command (struct t_irc_server *server, IRCB(501, 1, 0, generic_error), /* unknown mode flag */ IRCB(502, 1, 0, generic_error), /* can't chg mode for other users */ IRCB(524, 1, 0, help), /* HELP/HELPOP (help not found) */ + IRCB(569, 1, 0, whois_nick_msg), /* whois (connecting from) */ IRCB(671, 1, 0, whois_nick_msg), /* whois (secure connection) */ IRCB(704, 1, 0, help), /* start of HELP/HELPOP */ IRCB(705, 1, 0, help), /* body of HELP/HELPOP */ diff --git a/tests/unit/plugins/irc/test-irc-protocol.cpp b/tests/unit/plugins/irc/test-irc-protocol.cpp index 2ad635d04..1a93d41ad 100644 --- a/tests/unit/plugins/irc/test-irc-protocol.cpp +++ b/tests/unit/plugins/irc/test-irc-protocol.cpp @@ -4952,7 +4952,6 @@ TEST(IrcProtocolWithServer, 349) "irc_349,irc_numeric,nick_server,log3"); } - /* * Tests functions: * irc_protocol_cb_350 (whois, gateway) @@ -4973,7 +4972,7 @@ TEST(IrcProtocolWithServer, 350) CHECK_SRV("--", "[bob] something here", "irc_350,irc_numeric,nick_server,log3"); RECV(":server 350 alice bob * :something here"); - CHECK_SRV("--", "[bob] * something here", + CHECK_SRV("--", "[bob] something here", "irc_350,irc_numeric,nick_server,log3"); /* non-standard parameters (using default whois callback) */ @@ -5975,6 +5974,32 @@ TEST(IrcProtocolWithServer, 524) "irc_524,irc_numeric,notify_private,nick_server,log3"); } +/* + * Tests functions: + * irc_protocol_cb_569 (whois, connecting from) + */ + +TEST(IrcProtocolWithServer, 569) +{ + SRV_INIT_JOIN; + + /* not enough parameters */ + RECV(":server 569"); + CHECK_ERROR_PARAMS("569", 0, 2); + RECV(":server 569 alice"); + CHECK_ERROR_PARAMS("569", 1, 2); + + /* whois, connecting from (UnrealIRCd) */ + RECV(":server 569 alice bob 12345 :is connecting from AS12345 [Hoster]"); + CHECK_SRV("--", "[bob] is connecting from AS12345 [Hoster] (12345)", + "irc_569,irc_numeric,nick_server,log3"); + + /* whois, connecting from (UnrealIRCd), no ASN */ + RECV(":server 569 alice bob :is connecting from AS12345 [Hoster]"); + CHECK_SRV("--", "[bob] is connecting from AS12345 [Hoster]", + "irc_569,irc_numeric,nick_server,log3"); +} + /* * Tests functions: * irc_protocol_cb_704 (start of HELP/HELPOP)