diff options
-rw-r--r-- | src/plugins/irc/irc-command.c | 62 | ||||
-rw-r--r-- | src/plugins/irc/irc-join.c | 67 | ||||
-rw-r--r-- | src/plugins/irc/irc-join.h | 10 | ||||
-rw-r--r-- | tests/unit/plugins/irc/test-irc-join.cpp | 68 |
4 files changed, 76 insertions, 131 deletions
diff --git a/src/plugins/irc/irc-command.c b/src/plugins/irc/irc-command.c index 648ad3930..a968d983c 100644 --- a/src/plugins/irc/irc-command.c +++ b/src/plugins/irc/irc-command.c @@ -903,6 +903,8 @@ IRC_COMMAND_CALLBACK(auth) IRC_COMMAND_CALLBACK(autojoin) { struct t_irc_channel *ptr_channel2; + const char *ptr_autojoin; + char *old_autojoin; int i; IRC_BUFFER_GET_SERVER_CHANNEL(buffer); @@ -914,6 +916,10 @@ IRC_COMMAND_CALLBACK(autojoin) WEECHAT_COMMAND_MIN_ARGS(2, ""); + ptr_autojoin = IRC_SERVER_OPTION_STRING(ptr_server, + IRC_SERVER_OPTION_AUTOJOIN); + old_autojoin = strdup ((ptr_autojoin) ? ptr_autojoin : ""); + /* add channel(s) */ if (weechat_strcasecmp (argv[1], "add") == 0) { @@ -927,10 +933,10 @@ IRC_COMMAND_CALLBACK(autojoin) _("%s%s: \"%s\" command can only be executed in a channel " "buffer"), weechat_prefix ("error"), IRC_PLUGIN_NAME, "autojoin add"); - return WEECHAT_RC_OK; + goto end; } irc_join_add_channel_to_autojoin (ptr_server, ptr_channel->name, - ptr_channel->key, 1); + ptr_channel->key); } for (i = 2; i < argc; i++) { @@ -939,23 +945,22 @@ IRC_COMMAND_CALLBACK(autojoin) { irc_join_add_channel_to_autojoin (ptr_server, ptr_channel2->name, - ptr_channel2->key, - 1); + ptr_channel2->key); } else { - irc_join_add_channel_to_autojoin (ptr_server, argv[i], NULL, 1); + irc_join_add_channel_to_autojoin (ptr_server, argv[i], NULL); } } - return WEECHAT_RC_OK; + goto end; } /* add raw channel(s) */ if (weechat_strcasecmp (argv[1], "addraw") == 0) { WEECHAT_COMMAND_MIN_ARGS(3, "addraw"); - irc_join_add_channels_to_autojoin (ptr_server, argv_eol[2], 1); - return WEECHAT_RC_OK; + irc_join_add_channels_to_autojoin (ptr_server, argv_eol[2]); + goto end; } /* delete channel(s) */ @@ -971,25 +976,47 @@ IRC_COMMAND_CALLBACK(autojoin) _("%s%s: \"%s\" command can only be executed in a channel " "buffer"), weechat_prefix ("error"), IRC_PLUGIN_NAME, "autojoin add"); - return WEECHAT_RC_OK; + goto end; } irc_join_remove_channel_from_autojoin (ptr_server, - ptr_channel->name, - 1); + ptr_channel->name); } for (i = 2; i < argc; i++) { - irc_join_remove_channel_from_autojoin (ptr_server, argv[i], 1); + irc_join_remove_channel_from_autojoin (ptr_server, argv[i]); } - return WEECHAT_RC_OK; + goto end; } /* save currently joined channels */ if (weechat_strcasecmp (argv[1], "save") == 0) { - irc_join_save_channels_to_autojoin (ptr_server, 1); - return WEECHAT_RC_OK; + irc_join_save_channels_to_autojoin (ptr_server); + goto end; + } + +end: + ptr_autojoin = IRC_SERVER_OPTION_STRING(ptr_server, + IRC_SERVER_OPTION_AUTOJOIN); + if ((old_autojoin && !ptr_autojoin) || (!old_autojoin && ptr_autojoin) + || (strcmp (old_autojoin, ptr_autojoin) != 0)) + { + if (old_autojoin && old_autojoin[0]) + { + weechat_printf (ptr_server->buffer, + _("Autojoin changed from \"%s\" to \"%s\""), + old_autojoin, + ptr_autojoin); + } + else + { + weechat_printf (ptr_server->buffer, + _("Autojoin changed from empty value to \"%s\""), + ptr_autojoin); + } } + if (old_autojoin) + free (old_autojoin); return WEECHAT_RC_OK; } @@ -2869,7 +2896,7 @@ irc_command_join_server (struct t_irc_server *server, const char *arguments, if (save_autojoin) { irc_join_add_channel_to_autojoin (server, pos_channel, - ptr_key, 0); + ptr_key); } } } @@ -4253,8 +4280,7 @@ IRC_COMMAND_CALLBACK(part) { for (i = 0; i < num_channels; i++) { - irc_join_remove_channel_from_autojoin (ptr_server, - channels[i], 0); + irc_join_remove_channel_from_autojoin (ptr_server, channels[i]); } weechat_string_free_split (channels); } diff --git a/src/plugins/irc/irc-join.c b/src/plugins/irc/irc-join.c index 48df3f374..7e350b530 100644 --- a/src/plugins/irc/irc-join.c +++ b/src/plugins/irc/irc-join.c @@ -352,58 +352,12 @@ irc_join_add_channels (struct t_irc_server *server, } /* - * Sets server autojoin option. - * - * If verbose == 1, displays a message on the server buffer with old and new - * autojoin value. - */ - -void -irc_join_set_autojoin (struct t_irc_server *server, const char *autojoin, - int verbose) -{ - const char *ptr_old_autojoin; - char *old_autojoin; - - if (!server) - return; - - ptr_old_autojoin = IRC_SERVER_OPTION_STRING(server, IRC_SERVER_OPTION_AUTOJOIN); - old_autojoin = (ptr_old_autojoin && ptr_old_autojoin[0]) ? - strdup (ptr_old_autojoin) : NULL; - - weechat_config_option_set (server->options[IRC_SERVER_OPTION_AUTOJOIN], - autojoin, 1); - - if (verbose) - { - if (old_autojoin) - { - weechat_printf (server->buffer, - _("Autojoin changed from \"%s\" to \"%s\""), - old_autojoin, - autojoin); - } - else - { - weechat_printf (server->buffer, - _("Autojoin changed from empty value to \"%s\""), - autojoin); - } - } - - if (old_autojoin) - free (old_autojoin); -} - -/* * Adds a channel with optional key to the autojoin option of a server. */ void irc_join_add_channel_to_autojoin (struct t_irc_server *server, - const char *channel_name, const char *key, - int verbose) + const char *channel_name, const char *key) { char *new_autojoin; @@ -417,7 +371,8 @@ irc_join_add_channel_to_autojoin (struct t_irc_server *server, key); if (new_autojoin) { - irc_join_set_autojoin (server, new_autojoin, verbose); + weechat_config_option_set (server->options[IRC_SERVER_OPTION_AUTOJOIN], + new_autojoin, 1); free (new_autojoin); } } @@ -428,7 +383,7 @@ irc_join_add_channel_to_autojoin (struct t_irc_server *server, void irc_join_add_channels_to_autojoin (struct t_irc_server *server, - const char *join, int verbose) + const char *join) { char *new_autojoin; @@ -438,7 +393,8 @@ irc_join_add_channels_to_autojoin (struct t_irc_server *server, join); if (new_autojoin) { - irc_join_set_autojoin (server, new_autojoin, verbose); + weechat_config_option_set (server->options[IRC_SERVER_OPTION_AUTOJOIN], + new_autojoin, 1); free (new_autojoin); } } @@ -496,8 +452,7 @@ irc_join_remove_channel (struct t_irc_server *server, void irc_join_remove_channel_from_autojoin (struct t_irc_server *server, - const char *channel_name, - int verbose) + const char *channel_name) { char *new_autojoin; @@ -510,7 +465,8 @@ irc_join_remove_channel_from_autojoin (struct t_irc_server *server, channel_name); if (new_autojoin) { - irc_join_set_autojoin (server, new_autojoin, verbose); + weechat_config_option_set (server->options[IRC_SERVER_OPTION_AUTOJOIN], + new_autojoin, 1); free (new_autojoin); } } @@ -520,7 +476,7 @@ irc_join_remove_channel_from_autojoin (struct t_irc_server *server, */ void -irc_join_save_channels_to_autojoin (struct t_irc_server *server, int verbose) +irc_join_save_channels_to_autojoin (struct t_irc_server *server) { struct t_arraylist *arraylist; struct t_irc_channel *ptr_channel; @@ -554,7 +510,8 @@ irc_join_save_channels_to_autojoin (struct t_irc_server *server, int verbose) new_autojoin = irc_join_build_string (arraylist); if (new_autojoin) { - irc_join_set_autojoin (server, new_autojoin, verbose); + weechat_config_option_set (server->options[IRC_SERVER_OPTION_AUTOJOIN], + new_autojoin, 1); free (new_autojoin); } diff --git a/src/plugins/irc/irc-join.h b/src/plugins/irc/irc-join.h index bdc53d51b..eb1d396fd 100644 --- a/src/plugins/irc/irc-join.h +++ b/src/plugins/irc/irc-join.h @@ -38,16 +38,14 @@ extern char *irc_join_add_channels (struct t_irc_server *server, const char *join, const char *join2); extern void irc_join_add_channel_to_autojoin (struct t_irc_server *server, const char *channel_name, - const char *key, int verbose); + const char *key); extern void irc_join_add_channels_to_autojoin (struct t_irc_server *server, - const char *join, int verbose); + const char *join); extern char *irc_join_remove_channel (struct t_irc_server *server, const char *join, const char *channel_name); extern void irc_join_remove_channel_from_autojoin (struct t_irc_server *server, - const char *channel_name, - int verbose); -extern void irc_join_save_channels_to_autojoin (struct t_irc_server *server, - int verbose); + const char *channel_name); +extern void irc_join_save_channels_to_autojoin (struct t_irc_server *server); #endif /* WEECHAT_PLUGIN_IRC_JOIN_H */ diff --git a/tests/unit/plugins/irc/test-irc-join.cpp b/tests/unit/plugins/irc/test-irc-join.cpp index 7d59894c2..43e9c0d5c 100644 --- a/tests/unit/plugins/irc/test-irc-join.cpp +++ b/tests/unit/plugins/irc/test-irc-join.cpp @@ -336,117 +336,81 @@ TEST(IrcJoin, AddRemoveChannelsAutojoin) server = irc_server_alloc ("my_ircd"); CHECK(server); - irc_join_remove_channel_from_autojoin (server, "#xyz", 0); + irc_join_remove_channel_from_autojoin (server, "#xyz"); STRCMP_EQUAL( "", CONFIG_STRING(server->options[IRC_SERVER_OPTION_AUTOJOIN])); - irc_join_add_channel_to_autojoin (server, "#xyz", NULL, 0); + irc_join_add_channel_to_autojoin (server, "#xyz", NULL); STRCMP_EQUAL( "#xyz", CONFIG_STRING(server->options[IRC_SERVER_OPTION_AUTOJOIN])); - irc_join_add_channel_to_autojoin (server, NULL, NULL, 0); + irc_join_add_channel_to_autojoin (server, NULL, NULL); STRCMP_EQUAL( "#xyz", CONFIG_STRING(server->options[IRC_SERVER_OPTION_AUTOJOIN])); - irc_join_add_channel_to_autojoin (server, "#abc", "key_abc", 0); + irc_join_add_channel_to_autojoin (server, "#abc", "key_abc"); STRCMP_EQUAL( "#abc,#xyz key_abc", CONFIG_STRING(server->options[IRC_SERVER_OPTION_AUTOJOIN])); - irc_join_add_channel_to_autojoin (server, "#def", "key_def", 0); + irc_join_add_channel_to_autojoin (server, "#def", "key_def"); STRCMP_EQUAL( "#abc,#def,#xyz key_abc,key_def", CONFIG_STRING(server->options[IRC_SERVER_OPTION_AUTOJOIN])); - irc_join_add_channel_to_autojoin (server, "#ghi", NULL, 0); + irc_join_add_channel_to_autojoin (server, "#ghi", NULL); STRCMP_EQUAL( "#abc,#def,#xyz,#ghi key_abc,key_def", CONFIG_STRING(server->options[IRC_SERVER_OPTION_AUTOJOIN])); - irc_join_add_channel_to_autojoin (server, "#jkl", "", 0); + irc_join_add_channel_to_autojoin (server, "#jkl", ""); STRCMP_EQUAL( "#abc,#def,#xyz,#ghi,#jkl key_abc,key_def", CONFIG_STRING(server->options[IRC_SERVER_OPTION_AUTOJOIN])); - irc_join_remove_channel_from_autojoin (server, "#def", 0); + irc_join_remove_channel_from_autojoin (server, "#def"); STRCMP_EQUAL( "#abc,#xyz,#ghi,#jkl key_abc", CONFIG_STRING(server->options[IRC_SERVER_OPTION_AUTOJOIN])); - irc_join_remove_channel_from_autojoin (server, "#ghi", 0); + irc_join_remove_channel_from_autojoin (server, "#ghi"); STRCMP_EQUAL( "#abc,#xyz,#jkl key_abc", CONFIG_STRING(server->options[IRC_SERVER_OPTION_AUTOJOIN])); - irc_join_remove_channel_from_autojoin (server, "#abc", 0); + irc_join_remove_channel_from_autojoin (server, "#abc"); STRCMP_EQUAL( "#xyz,#jkl", CONFIG_STRING(server->options[IRC_SERVER_OPTION_AUTOJOIN])); - irc_join_remove_channel_from_autojoin (server, "#jkl", 0); + irc_join_remove_channel_from_autojoin (server, "#jkl"); STRCMP_EQUAL( "#xyz", CONFIG_STRING(server->options[IRC_SERVER_OPTION_AUTOJOIN])); - irc_join_remove_channel_from_autojoin (server, "#xyz", 0); + irc_join_remove_channel_from_autojoin (server, "#xyz"); STRCMP_EQUAL( "", CONFIG_STRING(server->options[IRC_SERVER_OPTION_AUTOJOIN])); - irc_join_remove_channel_from_autojoin (server, NULL, 0); + irc_join_remove_channel_from_autojoin (server, NULL); STRCMP_EQUAL( "", CONFIG_STRING(server->options[IRC_SERVER_OPTION_AUTOJOIN])); - irc_join_add_channels_to_autojoin (server, "#abc,#def key_abc", 0); + irc_join_add_channels_to_autojoin (server, "#abc,#def key_abc"); STRCMP_EQUAL( "#abc,#def key_abc", CONFIG_STRING(server->options[IRC_SERVER_OPTION_AUTOJOIN])); - irc_join_add_channels_to_autojoin (server, "#xyz,#ghi key_xyz", 0); + irc_join_add_channels_to_autojoin (server, "#xyz,#ghi key_xyz"); STRCMP_EQUAL( "#abc,#xyz,#def,#ghi key_abc,key_xyz", CONFIG_STRING(server->options[IRC_SERVER_OPTION_AUTOJOIN])); - record_start (); - irc_join_remove_channel_from_autojoin (server, "#xyz", 1); - STRCMP_EQUAL( - "#abc,#def,#ghi key_abc", - CONFIG_STRING(server->options[IRC_SERVER_OPTION_AUTOJOIN])); - CHECK(record_search ("core.weechat", - "Autojoin changed from " - "\"#abc,#xyz,#def,#ghi key_abc,key_xyz\" to " - "\"#abc,#def,#ghi key_abc\"")); - record_stop (); - - record_start (); - irc_join_add_channel_to_autojoin (server, "#xyz", NULL, 1); - STRCMP_EQUAL( - "#abc,#def,#ghi,#xyz key_abc", - CONFIG_STRING(server->options[IRC_SERVER_OPTION_AUTOJOIN])); - CHECK(record_search ("core.weechat", - "Autojoin changed from " - "\"#abc,#def,#ghi key_abc\" to " - "\"#abc,#def,#ghi,#xyz key_abc\"")); - record_stop (); - - irc_join_remove_channel_from_autojoin (server, "#abc", 0); - irc_join_remove_channel_from_autojoin (server, "#def", 0); - irc_join_remove_channel_from_autojoin (server, "#ghi", 0); - irc_join_remove_channel_from_autojoin (server, "#xyz", 0); - - record_start (); - irc_join_add_channel_to_autojoin (server, "#abc", NULL, 1); - STRCMP_EQUAL( - "#abc", - CONFIG_STRING(server->options[IRC_SERVER_OPTION_AUTOJOIN])); - CHECK(record_search ("core.weechat", - "Autojoin changed from empty value to \"#abc\"")); - record_stop (); - irc_server_free (server); } @@ -469,7 +433,7 @@ TEST(IrcJoin, SaveChannelsToAutojoin) "#test2", 0, 0); channel->key = strdup ("key2"); - irc_join_save_channels_to_autojoin (server, 0); + irc_join_save_channels_to_autojoin (server); STRCMP_EQUAL( "#test2,#test1 key2", CONFIG_STRING(server->options[IRC_SERVER_OPTION_AUTOJOIN])); |