diff options
author | Simmo Saan <simmo.saan@gmail.com> | 2018-09-09 20:46:05 +0300 |
---|---|---|
committer | Sébastien Helleu <flashcode@flashtux.org> | 2023-05-18 13:51:14 +0200 |
commit | 3c3bb933e928dfea0c21bd63a3b5409f5a0a8276 (patch) | |
tree | edcafad0071625ed2f3d738025fe54acf0e50302 /src | |
parent | 6edc88f7d6cb42d776b39f23e620060a910b490e (diff) | |
download | weechat-3c3bb933e928dfea0c21bd63a3b5409f5a0a8276.zip |
irc: optimize and reuse irc_channel_rejoin
Diffstat (limited to 'src')
-rw-r--r-- | src/plugins/irc/irc-channel.c | 33 | ||||
-rw-r--r-- | src/plugins/irc/irc-protocol.c | 25 |
2 files changed, 29 insertions, 29 deletions
diff --git a/src/plugins/irc/irc-channel.c b/src/plugins/irc/irc-channel.c index 072d8122d..ff3d2681a 100644 --- a/src/plugins/irc/irc-channel.c +++ b/src/plugins/irc/irc-channel.c @@ -1420,14 +1420,33 @@ void irc_channel_rejoin (struct t_irc_server *server, struct t_irc_channel *channel, int manual_join, int noswitch) { - char join_args[1024]; + char *join_string; + int length; - snprintf (join_args, sizeof (join_args), "%s%s%s", - channel->name, - (channel->key) ? " " : "", - (channel->key) ? channel->key : ""); - - irc_command_join_server (server, join_args, manual_join, noswitch); + if (channel->key) + { + length = strlen (channel->name) + 1 + strlen (channel->key) + 1; + join_string = malloc (length); + if (join_string) + { + snprintf (join_string, length, "%s %s", + channel->name, + channel->key); + irc_command_join_server (server, join_string, + manual_join, noswitch); + free (join_string); + } + else + { + irc_command_join_server (server, channel->name, + manual_join, noswitch); + } + } + else + { + irc_command_join_server (server, channel->name, + manual_join, noswitch); + } } /* diff --git a/src/plugins/irc/irc-protocol.c b/src/plugins/irc/irc-protocol.c index 20a960fb7..e495eecb2 100644 --- a/src/plugins/irc/irc-protocol.c +++ b/src/plugins/irc/irc-protocol.c @@ -2718,8 +2718,8 @@ IRC_PROTOCOL_CALLBACK(notice) IRC_PROTOCOL_CALLBACK(part) { - char *str_comment, *join_string; - int join_length, local_part, display_host; + char *str_comment; + int local_part, display_host; struct t_irc_channel *ptr_channel; struct t_irc_nick *ptr_nick; struct t_irc_channel_speaking *ptr_nick_speaking; @@ -2832,26 +2832,7 @@ IRC_PROTOCOL_CALLBACK(part) if (ptr_channel->cycle) { ptr_channel->cycle = 0; - if (ptr_channel->key) - { - join_length = strlen (ptr_channel->name) + 1 + - strlen (ptr_channel->key) + 1; - join_string = malloc (join_length); - if (join_string) - { - snprintf (join_string, join_length, "%s %s", - ptr_channel->name, - ptr_channel->key); - irc_command_join_server (server, join_string, 1, 1); - free (join_string); - } - else - irc_command_join_server (server, ptr_channel->name, - 1, 1); - } - else - irc_command_join_server (server, ptr_channel->name, - 1, 1); + irc_channel_rejoin (server, ptr_channel, 1, 1); } else { |