From bbca1a5a0fa59567fc3082263dc5e9b087e02da6 Mon Sep 17 00:00:00 2001 From: Will Storey Date: Mon, 27 Aug 2018 20:50:17 -0700 Subject: [PATCH 1/9] Revert "Revert "Flag topic as unset if it is zero length"" This reverts commit 817179a7606b616795cf67e24505526dded34381. --- .gitignore | 1 + src/irc/core/channel-events.c | 22 ++++++++++++---------- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/.gitignore b/.gitignore index 916457f8..1ab7df5f 100644 --- a/.gitignore +++ b/.gitignore @@ -59,6 +59,7 @@ tests/irc/core/test-irc.trs *.la *.lo *.o +*.swp *~ *.tar.bz2 diff --git a/src/irc/core/channel-events.c b/src/irc/core/channel-events.c index 46bbd5fa..4b74b322 100644 --- a/src/irc/core/channel-events.c +++ b/src/irc/core/channel-events.c @@ -126,23 +126,25 @@ static void channel_change_topic(IRC_SERVER_REC *server, const char *channel, chanrec = channel_find(SERVER(server), channel); if (chanrec == NULL) return; - /* the topic may be send out encoded, so we need to + + g_free_and_null(chanrec->topic); + g_free_and_null(chanrec->topic_by); + chanrec->topic_time = 0; + + /* the topic may be sent out encoded, so we need to recode it back or /topic will not work properly */ recoded = recode_in(SERVER(server), topic, channel); - if (topic != NULL) { - g_free_not_null(chanrec->topic); - chanrec->topic = recoded == NULL ? NULL : g_strdup(recoded); + if (recoded == NULL || *recoded == '\0') { + signal_emit("channel topic changed", 1, chanrec); + g_free(recoded); + return; } - g_free(recoded); - g_free_not_null(chanrec->topic_by); + chanrec->topic = recoded; chanrec->topic_by = g_strdup(setby); - - if (chanrec->topic_by == NULL) { + if (chanrec->topic_by != NULL) { /* ensure invariant topic_time > 0 <=> topic_by != NULL. this could be triggered by a topic command without sender */ - chanrec->topic_time = 0; - } else { chanrec->topic_time = settime; } From 04db359a6d0f6d8630c2439fb26b7420ecc48582 Mon Sep 17 00:00:00 2001 From: Will Storey Date: Thu, 9 Aug 2018 13:49:46 -0700 Subject: [PATCH 2/9] Handle topic info numeric separately from topic & topic numeric As we called the same function for the topic info numeric, we ended up losing the topic as that numeric does not include it. We now call a different function to handle this case more carefully. Fixes #903. --- src/irc/core/channel-events.c | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/src/irc/core/channel-events.c b/src/irc/core/channel-events.c index 4b74b322..e533a6f0 100644 --- a/src/irc/core/channel-events.c +++ b/src/irc/core/channel-events.c @@ -28,6 +28,9 @@ #include "irc-servers.h" #include "irc-channels.h" +static void set_topic_info(CHANNEL_REC *const, char const *const, + time_t const); + static void check_join_failure(IRC_SERVER_REC *server, const char *channel) { CHANNEL_REC *chanrec; @@ -141,14 +144,36 @@ static void channel_change_topic(IRC_SERVER_REC *server, const char *channel, } chanrec->topic = recoded; + set_topic_info(chanrec, setby, settime); + + signal_emit("channel topic changed", 1, chanrec); +} + +static void channel_change_topic_info(IRC_SERVER_REC *server, + const char *channel, const char *setby, time_t settime) +{ + CHANNEL_REC *chanrec; + + chanrec = channel_find(SERVER(server), channel); + if (chanrec == NULL) return; + + g_free_and_null(chanrec->topic_by); + chanrec->topic_time = 0; + + set_topic_info(chanrec, setby, settime); + + signal_emit("channel topic changed", 1, chanrec); +} + +static void set_topic_info(CHANNEL_REC *const chanrec, char const *const setby, + time_t const settime) +{ chanrec->topic_by = g_strdup(setby); if (chanrec->topic_by != NULL) { /* ensure invariant topic_time > 0 <=> topic_by != NULL. this could be triggered by a topic command without sender */ chanrec->topic_time = settime; } - - signal_emit("channel topic changed", 1, chanrec); } static void event_topic_get(IRC_SERVER_REC *server, const char *data) @@ -188,7 +213,7 @@ static void event_topic_info(IRC_SERVER_REC *server, const char *data) &topicby, &topictime); t = (time_t) atol(topictime); - channel_change_topic(server, channel, NULL, topicby, t); + channel_change_topic_info(server, channel, topicby, t); g_free(params); } From 2d6033542e0e47072d61ef442430c3014e3b430f Mon Sep 17 00:00:00 2001 From: Will Storey Date: Sat, 11 Aug 2018 10:48:00 -0700 Subject: [PATCH 3/9] Add functions to override irssi dir and config Setting up to test is easier this way. --- src/core/core.c | 10 ++++++++++ src/core/core.h | 3 +++ 2 files changed, 13 insertions(+) diff --git a/src/core/core.c b/src/core/core.c index 506d6a13..d87e86e2 100644 --- a/src/core/core.c +++ b/src/core/core.c @@ -73,12 +73,22 @@ const char *get_irssi_dir(void) return irssi_dir; } +void set_irssi_dir(char *const s) +{ + irssi_dir = s; +} + /* return full path for ~/.irssi/config */ const char *get_irssi_config(void) { return irssi_config_file; } +void set_irssi_config(char *const s) +{ + irssi_config_file = s; +} + static void sig_reload_config(int signo) { reload_config = TRUE; diff --git a/src/core/core.h b/src/core/core.h index 982dbaad..395e5c83 100644 --- a/src/core/core.h +++ b/src/core/core.h @@ -16,6 +16,9 @@ extern int irssi_init_finished; /* TRUE after "irssi init finished" signal is se extern int reload_config; /* TRUE after received SIGHUP. */ extern time_t client_start_time; +void set_irssi_dir(char *const); +void set_irssi_config(char *const); + void core_preinit(const char *path); void core_register_options(void); From 2ccb312b8b56db9585a4801184c064bfd3e3ff90 Mon Sep 17 00:00:00 2001 From: Will Storey Date: Sat, 11 Aug 2018 10:49:26 -0700 Subject: [PATCH 4/9] Expose functions for testing --- src/irc/core/Makefile.am | 1 + src/irc/core/channel-events.c | 7 ++++--- src/irc/core/channel-events.h | 12 ++++++++++++ 3 files changed, 17 insertions(+), 3 deletions(-) create mode 100644 src/irc/core/channel-events.h diff --git a/src/irc/core/Makefile.am b/src/irc/core/Makefile.am index 20caaeb1..c668faea 100644 --- a/src/irc/core/Makefile.am +++ b/src/irc/core/Makefile.am @@ -40,6 +40,7 @@ pkginc_irc_coredir=$(pkgincludedir)/src/irc/core pkginc_irc_core_HEADERS = \ bans.h \ ctcp.h \ + channel-events.h \ channel-rejoin.h \ irc.h \ irc-channels.h \ diff --git a/src/irc/core/channel-events.c b/src/irc/core/channel-events.c index e533a6f0..0cdb47fd 100644 --- a/src/irc/core/channel-events.c +++ b/src/irc/core/channel-events.c @@ -21,6 +21,7 @@ #include "module.h" #include "signals.h" #include "misc.h" +#include "channel-events.h" #include "channels-setup.h" #include "settings.h" #include "recode.h" @@ -176,7 +177,7 @@ static void set_topic_info(CHANNEL_REC *const chanrec, char const *const setby, } } -static void event_topic_get(IRC_SERVER_REC *server, const char *data) +void event_topic_get(IRC_SERVER_REC *server, const char *data) { char *params, *channel, *topic; @@ -187,7 +188,7 @@ static void event_topic_get(IRC_SERVER_REC *server, const char *data) g_free(params); } -static void event_topic(IRC_SERVER_REC *server, const char *data, +void event_topic(IRC_SERVER_REC *server, const char *data, const char *nick, const char *addr) { char *params, *channel, *topic, *mask; @@ -202,7 +203,7 @@ static void event_topic(IRC_SERVER_REC *server, const char *data, g_free(params); } -static void event_topic_info(IRC_SERVER_REC *server, const char *data) +void event_topic_info(IRC_SERVER_REC *server, const char *data) { char *params, *channel, *topicby, *topictime; time_t t; diff --git a/src/irc/core/channel-events.h b/src/irc/core/channel-events.h new file mode 100644 index 00000000..f0dea8b4 --- /dev/null +++ b/src/irc/core/channel-events.h @@ -0,0 +1,12 @@ +#ifndef __CHANNEL_EVENTS_H +#define __CHANNEL_EVENTS_H + +#include "irc.h" + +/* Not private for tests. */ +void event_topic_get(IRC_SERVER_REC *, const char *); +void event_topic(IRC_SERVER_REC *, const char *, + const char *, const char *); +void event_topic_info(IRC_SERVER_REC *, const char *); + +#endif From 6f38d67d87f2ef443172cca4d9ee82300d9f5ca4 Mon Sep 17 00:00:00 2001 From: Will Storey Date: Sat, 11 Aug 2018 10:49:47 -0700 Subject: [PATCH 5/9] Add tests for channel change events --- tests/irc/core/Makefile.am | 11 +- tests/irc/core/test-channel-events.c | 202 +++++++++++++++++++++++++++ 2 files changed, 209 insertions(+), 4 deletions(-) create mode 100644 tests/irc/core/test-channel-events.c diff --git a/tests/irc/core/Makefile.am b/tests/irc/core/Makefile.am index 86f1d547..f60da03f 100644 --- a/tests/irc/core/Makefile.am +++ b/tests/irc/core/Makefile.am @@ -8,21 +8,24 @@ AM_CPPFLAGS = \ -DSYSCONFDIR=\""$(sysconfdir)"\" \ $(GLIB_CFLAGS) -test_programs = test-irc +test_programs = test-channel-events test-irc -test_irc_CPPFLAGS = \ +CPPFLAGS = \ -I$(top_srcdir)/src/irc/core \ $(AM_CPPFLAGS) -test_irc_DEPENDENCIES = \ +DEPENDENCIES = \ ../../../src/core/libcore.a \ ../../../src/lib-config/libirssi_config.a -test_irc_LDADD = \ +LDADD = \ ../../../src/irc/core/libirc_core.a \ ../../../src/core/libcore.a \ ../../../src/lib-config/libirssi_config.a \ @PROG_LIBS@ +test_channel_events_SOURCES = \ + test-channel-events.c + test_irc_SOURCES = \ test-irc.c diff --git a/tests/irc/core/test-channel-events.c b/tests/irc/core/test-channel-events.c new file mode 100644 index 00000000..477e235c --- /dev/null +++ b/tests/irc/core/test-channel-events.c @@ -0,0 +1,202 @@ +/* + test-irc.c : irssi + + Copyright (C) 2018 Will Storey + + This program 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 2 of the License, or + (at your option) any later version. + + This program 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 this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +*/ + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define MODULE_NAME "test-channel-events" + +typedef struct { + char const *const description; + char const *const input; + char const *const topic; + char const *const topic_by; + time_t const topic_time; +} topic_test_case; + +static void test_event_topic_get(topic_test_case const *const); +static void test_event_topic(topic_test_case const *const); +static void test_event_topic_info(topic_test_case const *const); +static void setup(void); +static void teardown(void); + +static IRC_SERVER_REC *server; +static CHANNEL_REC *channel; + +topic_test_case const event_topic_get_test_cases[] = { + { + .description = "Normal 332 message with a topic with multiple words", + .input = "testnick #test :new topic", + .topic = "new topic", + .topic_by = NULL, + .topic_time = 0, + }, +}; + +topic_test_case const event_topic_info_test_cases[] = { + { + .description = "Normal 333 message", + .input = "testnick #test newnick!user@example.com 1533866229", + .topic = "initial topic", + .topic_by = "newnick!user@example.com", + .topic_time = 1533866229, + }, +}; + +topic_test_case const event_topic_test_cases[] = { + { + .description = "Normal TOPIC message", + .input = "#test :new topic", + .topic = "new topic", + .topic_by = "newnick!user@example.com", + .topic_time = 0, /* Dynamic */ + }, +}; + +int main(int argc, char **argv) +{ + int i, res; + + g_test_init(&argc, &argv, NULL); + + modules_init(); + signals_init(); + set_irssi_dir("/tmp/irssi"); + set_irssi_config("/tmp/irssi/config"); + settings_init(); + recode_init(); + + settings_add_str("lookandfeel", "term_charset", "UTF-8"); + recode_update_charset(); + + for (i = 0; i < G_N_ELEMENTS(event_topic_get_test_cases); i++) { + char *const name = g_strdup_printf("/test/event_topic_get/%d", i); + g_test_add_data_func(name, &event_topic_get_test_cases[i], + (GTestDataFunc)test_event_topic_get); + g_free(name); + } + + for (i = 0; i < G_N_ELEMENTS(event_topic_test_cases); i++) { + char *const name = g_strdup_printf("/test/event_topic/%d", i); + g_test_add_data_func(name, &event_topic_test_cases[i], + (GTestDataFunc)test_event_topic); + g_free(name); + } + + for (i = 0; i < G_N_ELEMENTS(event_topic_info_test_cases); i++) { + char *const name = g_strdup_printf("/test/event_topic_info/%d", i); + g_test_add_data_func(name, &event_topic_info_test_cases[i], + (GTestDataFunc)test_event_topic_info); + g_free(name); + } + +#if GLIB_CHECK_VERSION(2,38,0) + g_test_set_nonfatal_assertions(); +#endif + res = g_test_run(); + + recode_deinit(); + settings_deinit(); + signals_deinit(); + modules_deinit(); + + return res; +} + +static void test_event_topic_get(topic_test_case const *const test) +{ + setup(); + + event_topic_get(server, test->input); + + g_assert_cmpstr(channel->topic, ==, test->topic); + g_assert_cmpstr(channel->topic_by, ==, test->topic_by); + g_assert_cmpint(channel->topic_time, ==, test->topic_time); + + teardown(); +} + +static void test_event_topic(topic_test_case const *const test) +{ + time_t now; + + setup(); + + now = time(NULL); + event_topic(server, test->input, "newnick", "user@example.com"); + + g_assert_cmpstr(channel->topic, ==, test->topic); + g_assert_cmpstr(channel->topic_by, ==, test->topic_by); + g_assert_cmpint(channel->topic_time, >=, now); + + teardown(); +} + +static void test_event_topic_info(topic_test_case const *const test) +{ + setup(); + + event_topic_info(server, test->input); + + g_assert_cmpstr(channel->topic, ==, test->topic); + g_assert_cmpstr(channel->topic_by, ==, test->topic_by); + g_assert_cmpint(channel->topic_time, ==, test->topic_time); + + teardown(); +} + +static void setup(void) +{ + server = g_new0(IRC_SERVER_REC, 1); + MODULE_DATA_INIT(server); + server->type = module_get_uniq_id("SERVER", 0); + + channel = g_new0(CHANNEL_REC, 1); + channel->name = "#test"; + server->channels = g_slist_append(server->channels, channel); + + g_assert_nonnull(channel_find(SERVER(server), "#test")); + + channel->topic = g_strdup("initial topic"); + channel->topic_by = g_strdup("initialnick!user@example.com"); + channel->topic_time = 123; +} + +static void teardown(void) +{ + g_slist_free(server->channels); + MODULE_DATA_DEINIT(server); + g_free(server); + + g_free(channel->topic); + g_free(channel->topic_by); + g_free(channel); +} From 0edb64c4dc731065705f3303307f20b3ccb5674a Mon Sep 17 00:00:00 2001 From: Will Storey Date: Sat, 11 Aug 2018 10:52:39 -0700 Subject: [PATCH 6/9] Add test files to .gitignore --- .gitignore | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 1ab7df5f..ee1480cb 100644 --- a/.gitignore +++ b/.gitignore @@ -51,8 +51,23 @@ src/perl/*/Makefile.old src/fe-fuzz/crash-* src/fe-fuzz/oom-* -tests/irc/core/test-irc -tests/irc/core/test-irc.trs +/core +/tests/fe-common/core/test-formats +/tests/fe-common/core/test-formats.log +/tests/fe-common/core/test-formats.trs +/tests/fe-common/core/test-suite.log +/tests/irc/core/core +/tests/irc/core/test-channel-events +/tests/irc/core/test-channel-events.log +/tests/irc/core/test-channel-events.trs +/tests/irc/core/test-irc +/tests/irc/core/test-irc.log +/tests/irc/core/test-irc.trs +/tests/irc/core/test-suite.log +/tests/irc/flood/test-796 +/tests/irc/flood/test-796.log +/tests/irc/flood/test-796.trs +/tests/irc/flood/test-suite.log *.a *.bs From b11932d24f01703d07eb0f7a0de6c226ebcde195 Mon Sep 17 00:00:00 2001 From: Will Storey Date: Mon, 27 Aug 2018 21:04:23 -0700 Subject: [PATCH 7/9] Make channel event functions static again --- src/irc/core/channel-events.c | 6 +++--- src/irc/core/channel-events.h | 7 ++----- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/src/irc/core/channel-events.c b/src/irc/core/channel-events.c index 0cdb47fd..85d985ea 100644 --- a/src/irc/core/channel-events.c +++ b/src/irc/core/channel-events.c @@ -177,7 +177,7 @@ static void set_topic_info(CHANNEL_REC *const chanrec, char const *const setby, } } -void event_topic_get(IRC_SERVER_REC *server, const char *data) +static void event_topic_get(IRC_SERVER_REC *server, const char *data) { char *params, *channel, *topic; @@ -188,7 +188,7 @@ void event_topic_get(IRC_SERVER_REC *server, const char *data) g_free(params); } -void event_topic(IRC_SERVER_REC *server, const char *data, +static void event_topic(IRC_SERVER_REC *server, const char *data, const char *nick, const char *addr) { char *params, *channel, *topic, *mask; @@ -203,7 +203,7 @@ void event_topic(IRC_SERVER_REC *server, const char *data, g_free(params); } -void event_topic_info(IRC_SERVER_REC *server, const char *data) +static void event_topic_info(IRC_SERVER_REC *server, const char *data) { char *params, *channel, *topicby, *topictime; time_t t; diff --git a/src/irc/core/channel-events.h b/src/irc/core/channel-events.h index f0dea8b4..6d01c48e 100644 --- a/src/irc/core/channel-events.h +++ b/src/irc/core/channel-events.h @@ -3,10 +3,7 @@ #include "irc.h" -/* Not private for tests. */ -void event_topic_get(IRC_SERVER_REC *, const char *); -void event_topic(IRC_SERVER_REC *, const char *, - const char *, const char *); -void event_topic_info(IRC_SERVER_REC *, const char *); +void channel_events_init(void); +void channel_events_deinit(void); #endif From 7b09cac9ec0ce7e549ae8fecf4db8b8d811c18b1 Mon Sep 17 00:00:00 2001 From: Will Storey Date: Mon, 27 Aug 2018 21:04:54 -0700 Subject: [PATCH 8/9] Call functions via signals rather than directly This allows us to leave functions static. --- tests/irc/core/test-channel-events.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/tests/irc/core/test-channel-events.c b/tests/irc/core/test-channel-events.c index 477e235c..98c70ce8 100644 --- a/tests/irc/core/test-channel-events.c +++ b/tests/irc/core/test-channel-events.c @@ -93,6 +93,7 @@ int main(int argc, char **argv) set_irssi_config("/tmp/irssi/config"); settings_init(); recode_init(); + channel_events_init(); settings_add_str("lookandfeel", "term_charset", "UTF-8"); recode_update_charset(); @@ -123,6 +124,7 @@ int main(int argc, char **argv) #endif res = g_test_run(); + channel_events_deinit(); recode_deinit(); settings_deinit(); signals_deinit(); @@ -135,7 +137,7 @@ static void test_event_topic_get(topic_test_case const *const test) { setup(); - event_topic_get(server, test->input); + signal_emit("event 332", 2, server, test->input); g_assert_cmpstr(channel->topic, ==, test->topic); g_assert_cmpstr(channel->topic_by, ==, test->topic_by); @@ -151,7 +153,8 @@ static void test_event_topic(topic_test_case const *const test) setup(); now = time(NULL); - event_topic(server, test->input, "newnick", "user@example.com"); + signal_emit("event topic", 4, server, test->input, "newnick", + "user@example.com"); g_assert_cmpstr(channel->topic, ==, test->topic); g_assert_cmpstr(channel->topic_by, ==, test->topic_by); @@ -164,7 +167,7 @@ static void test_event_topic_info(topic_test_case const *const test) { setup(); - event_topic_info(server, test->input); + signal_emit("event 333", 2, server, test->input); g_assert_cmpstr(channel->topic, ==, test->topic); g_assert_cmpstr(channel->topic_by, ==, test->topic_by); From 8b1afbd3557e605f35cf4dab16d49cb4c89ca496 Mon Sep 17 00:00:00 2001 From: ailin-nemui Date: Sat, 6 Oct 2018 19:26:36 +0200 Subject: [PATCH 9/9] revert core changes --- src/core/core.c | 10 ------ src/core/core.h | 3 -- src/irc/core/channel-events.c | 53 +++++++--------------------- tests/irc/core/test-channel-events.c | 6 ++-- 4 files changed, 17 insertions(+), 55 deletions(-) diff --git a/src/core/core.c b/src/core/core.c index d87e86e2..506d6a13 100644 --- a/src/core/core.c +++ b/src/core/core.c @@ -73,22 +73,12 @@ const char *get_irssi_dir(void) return irssi_dir; } -void set_irssi_dir(char *const s) -{ - irssi_dir = s; -} - /* return full path for ~/.irssi/config */ const char *get_irssi_config(void) { return irssi_config_file; } -void set_irssi_config(char *const s) -{ - irssi_config_file = s; -} - static void sig_reload_config(int signo) { reload_config = TRUE; diff --git a/src/core/core.h b/src/core/core.h index 395e5c83..982dbaad 100644 --- a/src/core/core.h +++ b/src/core/core.h @@ -16,9 +16,6 @@ extern int irssi_init_finished; /* TRUE after "irssi init finished" signal is se extern int reload_config; /* TRUE after received SIGHUP. */ extern time_t client_start_time; -void set_irssi_dir(char *const); -void set_irssi_config(char *const); - void core_preinit(const char *path); void core_register_options(void); diff --git a/src/irc/core/channel-events.c b/src/irc/core/channel-events.c index 85d985ea..6ffe7364 100644 --- a/src/irc/core/channel-events.c +++ b/src/irc/core/channel-events.c @@ -29,9 +29,6 @@ #include "irc-servers.h" #include "irc-channels.h" -static void set_topic_info(CHANNEL_REC *const, char const *const, - time_t const); - static void check_join_failure(IRC_SERVER_REC *server, const char *channel) { CHANNEL_REC *chanrec; @@ -130,51 +127,27 @@ static void channel_change_topic(IRC_SERVER_REC *server, const char *channel, chanrec = channel_find(SERVER(server), channel); if (chanrec == NULL) return; - - g_free_and_null(chanrec->topic); - g_free_and_null(chanrec->topic_by); - chanrec->topic_time = 0; - - /* the topic may be sent out encoded, so we need to + /* the topic may be send out encoded, so we need to recode it back or /topic will not work properly */ recoded = recode_in(SERVER(server), topic, channel); - if (recoded == NULL || *recoded == '\0') { - signal_emit("channel topic changed", 1, chanrec); - g_free(recoded); - return; + if (topic != NULL) { + g_free_not_null(chanrec->topic); + chanrec->topic = recoded == NULL ? NULL : g_strdup(recoded); } + g_free(recoded); - chanrec->topic = recoded; - set_topic_info(chanrec, setby, settime); - - signal_emit("channel topic changed", 1, chanrec); -} - -static void channel_change_topic_info(IRC_SERVER_REC *server, - const char *channel, const char *setby, time_t settime) -{ - CHANNEL_REC *chanrec; - - chanrec = channel_find(SERVER(server), channel); - if (chanrec == NULL) return; - - g_free_and_null(chanrec->topic_by); - chanrec->topic_time = 0; - - set_topic_info(chanrec, setby, settime); - - signal_emit("channel topic changed", 1, chanrec); -} - -static void set_topic_info(CHANNEL_REC *const chanrec, char const *const setby, - time_t const settime) -{ + g_free_not_null(chanrec->topic_by); chanrec->topic_by = g_strdup(setby); - if (chanrec->topic_by != NULL) { + + if (chanrec->topic_by == NULL) { /* ensure invariant topic_time > 0 <=> topic_by != NULL. this could be triggered by a topic command without sender */ + chanrec->topic_time = 0; + } else { chanrec->topic_time = settime; } + + signal_emit("channel topic changed", 1, chanrec); } static void event_topic_get(IRC_SERVER_REC *server, const char *data) @@ -214,7 +187,7 @@ static void event_topic_info(IRC_SERVER_REC *server, const char *data) &topicby, &topictime); t = (time_t) atol(topictime); - channel_change_topic_info(server, channel, topicby, t); + channel_change_topic(server, channel, NULL, topicby, t); g_free(params); } diff --git a/tests/irc/core/test-channel-events.c b/tests/irc/core/test-channel-events.c index 98c70ce8..9f52c98d 100644 --- a/tests/irc/core/test-channel-events.c +++ b/tests/irc/core/test-channel-events.c @@ -31,6 +31,7 @@ #include #include #include +#include #define MODULE_NAME "test-channel-events" @@ -87,10 +88,11 @@ int main(int argc, char **argv) g_test_init(&argc, &argv, NULL); + core_preinit(*argv); + irssi_gui = IRSSI_GUI_NONE; + modules_init(); signals_init(); - set_irssi_dir("/tmp/irssi"); - set_irssi_config("/tmp/irssi/config"); settings_init(); recode_init(); channel_events_init();