From eda8ad9de54a645b979d5b1fdd46638876a4c578 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Helleu?= Date: Sun, 10 Oct 2021 22:31:19 +0200 Subject: irc: use parsed command parameters in "generic_error" command callback --- src/plugins/irc/irc-protocol.c | 46 ++++++++++++++++++++++-------------------- 1 file changed, 24 insertions(+), 22 deletions(-) (limited to 'src') diff --git a/src/plugins/irc/irc-protocol.c b/src/plugins/irc/irc-protocol.c index 03879b982..4030f3821 100644 --- a/src/plugins/irc/irc-protocol.c +++ b/src/plugins/irc/irc-protocol.c @@ -1255,39 +1255,38 @@ IRC_PROTOCOL_CALLBACK(error) * command "ERROR"). * * Command looks like: - * :server 404 nick #channel :Cannot send to channel + * 404 nick #channel :Cannot send to channel */ IRC_PROTOCOL_CALLBACK(generic_error) { - int first_arg; - char *chan_nick, *args; + int arg_error; + char *str_params; + const char *pos_chan_nick; struct t_irc_channel *ptr_channel; struct t_gui_buffer *ptr_buffer; - IRC_PROTOCOL_MIN_ARGS(4); + IRC_PROTOCOL_MIN_PARAMS(1); - first_arg = (irc_server_strcasecmp (server, argv[2], server->nick) == 0) ? 3 : 2; + arg_error = (irc_server_strcasecmp (server, params[0], server->nick) == 0) ? + 1 : 0; - if ((argv[first_arg][0] != ':') && argv[first_arg + 1]) - { - chan_nick = argv[first_arg]; - args = argv_eol[first_arg + 1]; - } - else + pos_chan_nick = NULL; + if (params[arg_error + 1] + && irc_channel_is_channel (server, params[arg_error])) { - chan_nick = NULL; - args = argv_eol[first_arg]; + pos_chan_nick = params[arg_error]; + arg_error++; } - if (args[0] == ':') - args++; ptr_channel = NULL; - if (chan_nick) - ptr_channel = irc_channel_search (server, chan_nick); + if (pos_chan_nick) + ptr_channel = irc_channel_search (server, pos_chan_nick); ptr_buffer = (ptr_channel) ? ptr_channel->buffer : server->buffer; + str_params = irc_protocol_string_params (params, arg_error); + weechat_printf_date_tags ( irc_msgbuffer_get_target_buffer ( server, NULL, command, @@ -1298,14 +1297,17 @@ IRC_PROTOCOL_CALLBACK(generic_error) irc_protocol_tags (command, NULL, NULL, NULL), "%s%s%s%s%s%s", weechat_prefix ("network"), - (ptr_channel && chan_nick - && (irc_server_strcasecmp (server, chan_nick, + (ptr_channel && pos_chan_nick + && (irc_server_strcasecmp (server, pos_chan_nick, ptr_channel->name) == 0)) ? IRC_COLOR_CHAT_CHANNEL : "", - (chan_nick) ? chan_nick : "", + (pos_chan_nick) ? pos_chan_nick : "", IRC_COLOR_RESET, - (chan_nick) ? ": " : "", - args); + (pos_chan_nick) ? ": " : "", + str_params); + + if (str_params) + free (str_params); return WEECHAT_RC_OK; } -- cgit v1.2.3