From 12a4519448b1dec527a5811580c936d8e6c8c669 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Helleu?= Date: Fri, 15 Oct 2021 20:00:07 +0200 Subject: [PATCH] irc: use parsed command parameters in "221" command callback --- src/plugins/irc/irc-protocol.c | 28 +++++++++++--------- tests/unit/plugins/irc/test-irc-protocol.cpp | 6 ++--- 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/src/plugins/irc/irc-protocol.c b/src/plugins/irc/irc-protocol.c index 183d24719..5d1a10645 100644 --- a/src/plugins/irc/irc-protocol.c +++ b/src/plugins/irc/irc-protocol.c @@ -3673,34 +3673,36 @@ IRC_PROTOCOL_CALLBACK(008) * Callback for the IRC command "221": user mode string. * * Command looks like: - * :server 221 nick :+s + * 221 nick :+s */ IRC_PROTOCOL_CALLBACK(221) { - IRC_PROTOCOL_MIN_ARGS(4); + char *str_params; + + IRC_PROTOCOL_MIN_PARAMS(2); + + str_params = irc_protocol_string_params (params, 1, num_params - 1); weechat_printf_date_tags ( - irc_msgbuffer_get_target_buffer (server, argv[2], command, NULL, NULL), + irc_msgbuffer_get_target_buffer (server, params[0], command, NULL, NULL), date, irc_protocol_tags (command, "irc_numeric", NULL, address), _("%sUser mode for %s%s%s is %s[%s%s%s]"), weechat_prefix ("network"), - irc_nick_color_for_msg (server, 1, NULL, argv[2]), - argv[2], + irc_nick_color_for_msg (server, 1, NULL, params[0]), + params[0], IRC_COLOR_RESET, IRC_COLOR_CHAT_DELIMITERS, IRC_COLOR_RESET, - (argv_eol[3][0] == ':') ? argv_eol[3] + 1 : argv_eol[3], + str_params, IRC_COLOR_CHAT_DELIMITERS); - if (irc_server_strcasecmp (server, argv[2], server->nick) == 0) - { - irc_mode_user_set ( - server, - (argv_eol[3][0] == ':') ? argv_eol[3] + 1 : argv_eol[3], - 1); - } + if (irc_server_strcasecmp (server, params[0], server->nick) == 0) + irc_mode_user_set (server, str_params, 1); + + if (str_params) + free (str_params); 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 baa7575f0..1dafc9469 100644 --- a/tests/unit/plugins/irc/test-irc-protocol.cpp +++ b/tests/unit/plugins/irc/test-irc-protocol.cpp @@ -2141,11 +2141,11 @@ TEST(IrcProtocolWithServer, 221) { SRV_INIT; - /* not enough arguments */ + /* not enough parameters */ RECV(":server 221"); - CHECK_ERROR_ARGS("221", 2, 4); + CHECK_ERROR_PARAMS("221", 0, 2); RECV(":server 221 alice"); - CHECK_ERROR_ARGS("221", 3, 4); + CHECK_ERROR_PARAMS("221", 1, 2); POINTERS_EQUAL(NULL, ptr_server->nick_modes);