From 10a1c9bda4032d39bdcc217e7468a39a38febbf2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Helleu?= Date: Sat, 16 Oct 2021 09:54:34 +0200 Subject: [PATCH] irc: use parsed command parameters in "327" command callback --- src/plugins/irc/irc-protocol.c | 35 +++++++++++--------- tests/unit/plugins/irc/test-irc-protocol.cpp | 10 +++--- 2 files changed, 24 insertions(+), 21 deletions(-) diff --git a/src/plugins/irc/irc-protocol.c b/src/plugins/irc/irc-protocol.c index 4b34dc772..9a78f642e 100644 --- a/src/plugins/irc/irc-protocol.c +++ b/src/plugins/irc/irc-protocol.c @@ -4353,23 +4353,23 @@ IRC_PROTOCOL_CALLBACK(324) * Callback for the IRC command "327": whois, host. * * Command looks like: - * :server 327 mynick nick host ip :real hostname/ip + * 327 mynick nick host ip :real hostname/ip */ IRC_PROTOCOL_CALLBACK(327) { - char *pos_realname; + char *str_realname; struct t_gui_buffer *ptr_buffer; - IRC_PROTOCOL_MIN_ARGS(6); + IRC_PROTOCOL_MIN_PARAMS(4); - pos_realname = (argc > 6) ? - ((argv_eol[6][0] == ':') ? argv_eol[6] + 1 : argv_eol[6]) : NULL; + str_realname = (num_params > 4) ? + irc_protocol_string_params (params, 4, num_params - 1) : NULL; - ptr_buffer = irc_msgbuffer_get_target_buffer (server, argv[3], + ptr_buffer = irc_msgbuffer_get_target_buffer (server, params[1], command, "whois", NULL); - if (pos_realname && pos_realname[0]) + if (str_realname && str_realname[0]) { weechat_printf_date_tags ( ptr_buffer, @@ -4378,15 +4378,15 @@ IRC_PROTOCOL_CALLBACK(327) "%s%s[%s%s%s] %s%s %s %s(%s%s%s)", weechat_prefix ("network"), IRC_COLOR_CHAT_DELIMITERS, - irc_nick_color_for_msg (server, 1, NULL, argv[3]), - argv[3], + irc_nick_color_for_msg (server, 1, NULL, params[1]), + params[1], IRC_COLOR_CHAT_DELIMITERS, IRC_COLOR_CHAT_HOST, - argv[4], - argv[5], + params[2], + params[3], IRC_COLOR_CHAT_DELIMITERS, IRC_COLOR_RESET, - pos_realname, + str_realname, IRC_COLOR_CHAT_DELIMITERS); } else @@ -4398,14 +4398,17 @@ IRC_PROTOCOL_CALLBACK(327) "%s%s[%s%s%s] %s%s %s", weechat_prefix ("network"), IRC_COLOR_CHAT_DELIMITERS, - irc_nick_color_for_msg (server, 1, NULL, argv[3]), - argv[3], + irc_nick_color_for_msg (server, 1, NULL, params[1]), + params[1], IRC_COLOR_CHAT_DELIMITERS, IRC_COLOR_CHAT_HOST, - argv[4], - argv[5]); + params[2], + params[3]); } + if (str_realname) + free (str_realname); + return WEECHAT_RC_OK; } diff --git a/tests/unit/plugins/irc/test-irc-protocol.cpp b/tests/unit/plugins/irc/test-irc-protocol.cpp index e903f2e31..8099906df 100644 --- a/tests/unit/plugins/irc/test-irc-protocol.cpp +++ b/tests/unit/plugins/irc/test-irc-protocol.cpp @@ -2672,15 +2672,15 @@ TEST(IrcProtocolWithServer, 327) { SRV_INIT; - /* not enough arguments */ + /* not enough parameters */ RECV(":server 327"); - CHECK_ERROR_ARGS("327", 2, 6); + CHECK_ERROR_PARAMS("327", 0, 4); RECV(":server 327 alice"); - CHECK_ERROR_ARGS("327", 3, 6); + CHECK_ERROR_PARAMS("327", 1, 4); RECV(":server 327 alice bob"); - CHECK_ERROR_ARGS("327", 4, 6); + CHECK_ERROR_PARAMS("327", 2, 4); RECV(":server 327 alice bob host"); - CHECK_ERROR_ARGS("327", 5, 6); + CHECK_ERROR_PARAMS("327", 3, 4); RECV(":server 327 alice bob host 1.2.3.4"); CHECK_SRV("-- [bob] host 1.2.3.4");