diff options
-rw-r--r-- | ChangeLog.adoc | 1 | ||||
-rw-r--r-- | doc/en/weechat_dev.en.adoc | 1 | ||||
-rw-r--r-- | doc/fr/weechat_dev.fr.adoc | 1 | ||||
-rw-r--r-- | doc/ja/weechat_dev.ja.adoc | 2 | ||||
-rw-r--r-- | doc/sr/weechat_dev.sr.adoc | 2 | ||||
-rw-r--r-- | src/plugins/irc/irc-buffer.c | 28 | ||||
-rw-r--r-- | src/plugins/irc/irc-buffer.h | 3 | ||||
-rw-r--r-- | src/plugins/irc/irc-channel.c | 9 | ||||
-rw-r--r-- | src/plugins/irc/irc-protocol.c | 11 | ||||
-rw-r--r-- | src/plugins/irc/irc-server.c | 7 | ||||
-rw-r--r-- | tests/CMakeLists.txt | 1 | ||||
-rw-r--r-- | tests/Makefile.am | 3 | ||||
-rw-r--r-- | tests/unit/plugins/irc/test-irc-buffer.cpp | 102 |
13 files changed, 152 insertions, 19 deletions
diff --git a/ChangeLog.adoc b/ChangeLog.adoc index c648a800c..df539ecbc 100644 --- a/ChangeLog.adoc +++ b/ChangeLog.adoc @@ -31,6 +31,7 @@ Bug fixes:: * core: fix access to integer/long/time arrays in hdata * api: fix search of option when the section is not given in functions config_search_option and config_search_section_option + * irc: fix join of channels with name longer than 127 chars (issue #1717) * irc: fix parsing of parameters in all IRC messages (issue #1666) * irc: fix parsing of CAP message when there is no prefix (issue #1707) * irc: fix parsing of TAGMSG message when there is a colon before the channel diff --git a/doc/en/weechat_dev.en.adoc b/doc/en/weechat_dev.en.adoc index 566f65301..d4f5a1995 100644 --- a/doc/en/weechat_dev.en.adoc +++ b/doc/en/weechat_dev.en.adoc @@ -425,6 +425,7 @@ WeeChat "core" is located in following directories: | test-gui-nick.cpp | Tests: nicks. | plugins/ | Root of unit tests for plugins. | irc/ | Root of unit tests for IRC plugin. +| test-irc-buffer.cpp | Tests: IRC buffers. | test-irc-channel.cpp | Tests: IRC channels. | test-irc-color.cpp | Tests: IRC colors. | test-irc-config.cpp | Tests: IRC configuration. diff --git a/doc/fr/weechat_dev.fr.adoc b/doc/fr/weechat_dev.fr.adoc index e69f1fa25..56ad60ea7 100644 --- a/doc/fr/weechat_dev.fr.adoc +++ b/doc/fr/weechat_dev.fr.adoc @@ -427,6 +427,7 @@ Le cœur de WeeChat est situé dans les répertoires suivants : | test-gui-nick.cpp | Tests : pseudos. | plugins/ | Racine des tests unitaires pour les extensions. | irc/ | Racine des tests unitaires pour l'extension IRC. +| test-irc-buffer.cpp | Tests : tampons IRC. | test-irc-channel.cpp | Tests : canaux IRC. | test-irc-color.cpp | Tests : couleurs IRC. | test-irc-config.cpp | Tests : configuration IRC. diff --git a/doc/ja/weechat_dev.ja.adoc b/doc/ja/weechat_dev.ja.adoc index 24c5dec4d..091ad1fbf 100644 --- a/doc/ja/weechat_dev.ja.adoc +++ b/doc/ja/weechat_dev.ja.adoc @@ -453,6 +453,8 @@ WeeChat "core" は以下のディレクトリに配置されています: | plugins/ | プラグインの単体テストを収める最上位ディレクトリ | irc/ | IRC プラグインの単体テストを収める最上位ディレクトリ // TRANSLATION MISSING +| test-irc-buffer.cpp | Tests: IRC buffers. +// TRANSLATION MISSING | test-irc-channel.cpp | Tests: IRC channels. | test-irc-color.cpp | Tests: IRC colors. | test-irc-config.cpp | テスト: IRC 設定 diff --git a/doc/sr/weechat_dev.sr.adoc b/doc/sr/weechat_dev.sr.adoc index 2f90e386e..f1fac4d92 100644 --- a/doc/sr/weechat_dev.sr.adoc +++ b/doc/sr/weechat_dev.sr.adoc @@ -426,6 +426,8 @@ WeeChat „језгро” се налази у следећим директо | test-gui-nick.cpp | Тестови: надимци. | plugins/ | Корен unit тестова додатака. | irc/ | Корен unit тестова IRC додатка. +// TRANSLATION MISSING +| test-irc-buffer.cpp | Tests: IRC buffers. | test-irc-channel.cpp | Тестови: IRC канали. | test-irc-color.cpp | Тестови: IRC боје. | test-irc-config.cpp | Тестови: IRC конфигурација. diff --git a/src/plugins/irc/irc-buffer.c b/src/plugins/irc/irc-buffer.c index 3394b96df..a2689d57e 100644 --- a/src/plugins/irc/irc-buffer.c +++ b/src/plugins/irc/irc-buffer.c @@ -85,26 +85,38 @@ irc_buffer_get_server_and_channel (struct t_gui_buffer *buffer, /* * Builds buffer name with a server and a channel. + * + * Note: result must be freed after use. */ -const char * +char * irc_buffer_build_name (const char *server, const char *channel) { - static char buffer[128]; + char **buffer; - buffer[0] = '\0'; + buffer = weechat_string_dyn_alloc (128); if (!server && !channel) - return buffer; + goto end; if (server && channel) - snprintf (buffer, sizeof (buffer), "%s.%s", server, channel); + { + weechat_string_dyn_concat (buffer, server, -1); + weechat_string_dyn_concat (buffer, ".", -1); + weechat_string_dyn_concat (buffer, channel, -1); + } else if (server) - snprintf (buffer, sizeof (buffer), "server.%s", server); + { + weechat_string_dyn_concat (buffer, "server.", -1); + weechat_string_dyn_concat (buffer, server, -1); + } else - snprintf (buffer, sizeof (buffer), "%s", channel); + { + weechat_string_dyn_concat (buffer, channel, -1); + } - return buffer; +end: + return weechat_string_dyn_free (buffer, 0); } /* diff --git a/src/plugins/irc/irc-buffer.h b/src/plugins/irc/irc-buffer.h index e5e7fdad4..2a4b35c99 100644 --- a/src/plugins/irc/irc-buffer.h +++ b/src/plugins/irc/irc-buffer.h @@ -46,8 +46,7 @@ struct t_irc_channel; extern void irc_buffer_get_server_and_channel (struct t_gui_buffer *buffer, struct t_irc_server **server, struct t_irc_channel **channel); -extern const char *irc_buffer_build_name (const char *server, - const char *channel); +extern char *irc_buffer_build_name (const char *server, const char *channel); extern int irc_buffer_close_cb (const void *pointer, void *data, struct t_gui_buffer *buffer); extern int irc_buffer_nickcmp_cb (const void *pointer, void *data, diff --git a/src/plugins/irc/irc-channel.c b/src/plugins/irc/irc-channel.c index 36e79c5a5..88c9effbc 100644 --- a/src/plugins/irc/irc-channel.c +++ b/src/plugins/irc/irc-channel.c @@ -245,8 +245,8 @@ irc_channel_create_buffer (struct t_irc_server *server, struct t_gui_buffer *ptr_buffer, *ptr_buffer_for_merge; int buffer_created, current_buffer_number, buffer_position; int manual_join, noswitch; - char str_number[32], *channel_name_lower; - const char *buffer_name, *short_name, *localvar_channel; + char str_number[32], *channel_name_lower, *buffer_name; + const char *short_name, *localvar_channel; buffer_created = 0; @@ -294,7 +294,7 @@ irc_channel_create_buffer (struct t_irc_server *server, &irc_input_data_cb, NULL, NULL, &irc_buffer_close_cb, NULL, NULL); if (!ptr_buffer) - return NULL; + goto end; if (weechat_buffer_get_integer (ptr_buffer, "layout_number") < 1) { @@ -432,6 +432,9 @@ irc_channel_create_buffer (struct t_irc_server *server, } } +end: + if (buffer_name) + free (buffer_name); return ptr_buffer; } diff --git a/src/plugins/irc/irc-protocol.c b/src/plugins/irc/irc-protocol.c index 5b48634cf..ae15a00a2 100644 --- a/src/plugins/irc/irc-protocol.c +++ b/src/plugins/irc/irc-protocol.c @@ -1896,8 +1896,7 @@ IRC_PROTOCOL_CALLBACK(nick) { struct t_irc_channel *ptr_channel; struct t_irc_nick *ptr_nick, *ptr_nick_found; - char *old_color, str_tags[512]; - const char *buffer_name; + char *old_color, str_tags[512], *buffer_name; int local_nick, smart_filter; struct t_irc_channel_speaking *ptr_nick_speaking; @@ -1969,6 +1968,8 @@ IRC_PROTOCOL_CALLBACK(nick) weechat_buffer_set (ptr_channel->buffer, "localvar_set_channel", ptr_channel->name); + if (buffer_name) + free (buffer_name); } break; case IRC_CHANNEL_TYPE_CHANNEL: @@ -6355,8 +6356,8 @@ IRC_PROTOCOL_CALLBACK(470) { struct t_gui_buffer *ptr_buffer; struct t_gui_lines *own_lines; - const char *buffer_name, *short_name, *localvar_channel; - char *old_channel_lower, *new_channel_lower; + const char *short_name, *localvar_channel; + char *old_channel_lower, *new_channel_lower, *buffer_name; int lines_count; irc_protocol_cb_generic_error (server, date, irc_message, @@ -6386,6 +6387,8 @@ IRC_PROTOCOL_CALLBACK(470) buffer_name = irc_buffer_build_name (server->name, params[2]); weechat_buffer_set (ptr_buffer, "name", buffer_name); weechat_buffer_set (ptr_buffer, "localvar_set_channel", params[2]); + if (buffer_name) + free (buffer_name); /* * check if logger backlog should be displayed for the new channel diff --git a/src/plugins/irc/irc-server.c b/src/plugins/irc/irc-server.c index c136171e2..abcba968c 100644 --- a/src/plugins/irc/irc-server.c +++ b/src/plugins/irc/irc-server.c @@ -2302,7 +2302,8 @@ irc_server_rename (struct t_irc_server *server, const char *new_name) { int length; char *mask, *pos_option, *new_option_name, charset_modifier[256]; - const char *buffer_name, *option_name; + char *buffer_name; + const char *option_name; struct t_infolist *infolist; struct t_config_option *ptr_option; struct t_irc_channel *ptr_channel; @@ -2366,6 +2367,8 @@ irc_server_rename (struct t_irc_server *server, const char *new_name) weechat_buffer_set (ptr_channel->buffer, "name", buffer_name); weechat_buffer_set (ptr_channel->buffer, "localvar_set_server", server->name); + if (buffer_name) + free (buffer_name); } } if (server->buffer) @@ -2381,6 +2384,8 @@ irc_server_rename (struct t_irc_server *server, const char *new_name) "irc.%s", server->name); weechat_buffer_set (server->buffer, "localvar_set_charset_modifier", charset_modifier); + if (buffer_name) + free (buffer_name); } return 1; diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 8cbf9d43a..9b6e8bd59 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -54,6 +54,7 @@ set(LIB_WEECHAT_UNIT_TESTS_PLUGINS_SRC unit/plugins/test-plugins.cpp) if(ENABLE_IRC) list(APPEND LIB_WEECHAT_UNIT_TESTS_PLUGINS_SRC + unit/plugins/irc/test-irc-buffer.cpp unit/plugins/irc/test-irc-channel.cpp unit/plugins/irc/test-irc-color.cpp unit/plugins/irc/test-irc-config.cpp diff --git a/tests/Makefile.am b/tests/Makefile.am index 4e30a512a..cfd820cfd 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -69,7 +69,8 @@ tests_SOURCES = tests.cpp \ lib_LTLIBRARIES = lib_weechat_unit_tests_plugins.la if PLUGIN_IRC -tests_irc = unit/plugins/irc/test-irc-channel.cpp \ +tests_irc = unit/plugins/irc/test-irc-buffer.cpp \ + unit/plugins/irc/test-irc-channel.cpp \ unit/plugins/irc/test-irc-color.cpp \ unit/plugins/irc/test-irc-config.cpp \ unit/plugins/irc/test-irc-ignore.cpp \ diff --git a/tests/unit/plugins/irc/test-irc-buffer.cpp b/tests/unit/plugins/irc/test-irc-buffer.cpp new file mode 100644 index 000000000..987643fec --- /dev/null +++ b/tests/unit/plugins/irc/test-irc-buffer.cpp @@ -0,0 +1,102 @@ +/* + * test-irc-buffer.cpp - test IRC buffer functions + * + * Copyright (C) 2021 Sébastien Helleu <flashcode@flashtux.org> + * + * This file is part of WeeChat, the extensible chat client. + * + * WeeChat is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * WeeChat is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with WeeChat. If not, see <http://www.gnu.org/licenses/>. + */ + +#include "CppUTest/TestHarness.h" + +extern "C" +{ +#include "tests/tests.h" +#include "src/plugins/irc/irc-buffer.h" +} + +#define CHANNEL_300 "#this_channel_name_has_300_chars_xxxxxxxxxxxxxxxxxxxxx" \ + "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" \ + "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" \ + "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" \ + "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx_END" + +TEST_GROUP(IrcBuffer) +{ +}; + +/* + * Tests functions: + * irc_buffer_get_server_and_channel + */ + +TEST(IrcBuffer, GetServerAndChannel) +{ + /* TODO: write tests */ +} + +/* + * Tests functions: + * irc_buffer_build_name + */ + +TEST(IrcBuffer, BuildName) +{ + char *str; + + WEE_TEST_STR("", irc_buffer_build_name (NULL, NULL)); + WEE_TEST_STR(".", irc_buffer_build_name ("", "")); + + /* only server */ + WEE_TEST_STR("server.libera", irc_buffer_build_name ("libera", NULL)); + + /* only channel */ + WEE_TEST_STR("#chan1", irc_buffer_build_name (NULL, "#chan1")); + + /* server and channel */ + WEE_TEST_STR("libera.#chan1", irc_buffer_build_name ("libera", "#chan1")); + WEE_TEST_STR("libera." CHANNEL_300, + irc_buffer_build_name ("libera", CHANNEL_300)); +} + +/* + * Tests functions: + * irc_buffer_close_server_channels + */ + +TEST(IrcBuffer, CloseServerChannels) +{ + /* TODO: write tests */ +} + +/* + * Tests functions: + * irc_buffer_search_server_lowest_number + */ + +TEST(IrcBuffer, SearchServerLowestNumber) +{ + /* TODO: write tests */ +} + +/* + * Tests functions: + * irc_buffer_search_private_lowest_number + */ + +TEST(IrcBuffer, SearchPrivateLowestNumber) +{ + /* TODO: write tests */ +} |