diff options
author | Sebastien Helleu <flashcode@flashtux.org> | 2012-01-06 11:24:01 +0100 |
---|---|---|
committer | Sebastien Helleu <flashcode@flashtux.org> | 2012-01-06 11:24:01 +0100 |
commit | 4cde51a27ffbc45d05a6ff658bffbd5497af5472 (patch) | |
tree | 1376a3c54e99c6956eb4ad25e490f77ad10934c4 /src | |
parent | 4e870c71cbb2883e1952804b26d64d6e5425c03e (diff) | |
download | weechat-4cde51a27ffbc45d05a6ff658bffbd5497af5472.zip |
irc: use redirection to get channel modes after update of modes on channel, display output of /mode #channel
Diffstat (limited to 'src')
-rw-r--r-- | src/plugins/irc/irc-channel.c | 18 | ||||
-rw-r--r-- | src/plugins/irc/irc-channel.h | 3 | ||||
-rw-r--r-- | src/plugins/irc/irc-protocol.c | 162 | ||||
-rw-r--r-- | src/plugins/irc/irc-protocol.h | 2 | ||||
-rw-r--r-- | src/plugins/irc/irc-upgrade.c | 1 | ||||
-rw-r--r-- | src/plugins/irc/irc.c | 5 |
6 files changed, 138 insertions, 53 deletions
diff --git a/src/plugins/irc/irc-channel.c b/src/plugins/irc/irc-channel.c index dfdf3be4e..1cae45ad2 100644 --- a/src/plugins/irc/irc-channel.c +++ b/src/plugins/irc/irc-channel.c @@ -266,7 +266,6 @@ irc_channel_new (struct t_irc_server *server, int channel_type, new_channel->has_quit_server = 0; new_channel->cycle = 0; new_channel->part = 0; - new_channel->display_creation_date = 0; new_channel->nick_completion_reset = 0; new_channel->pv_remote_nick_color = NULL; new_channel->hook_autorejoin = NULL; @@ -347,6 +346,19 @@ irc_channel_set_topic (struct t_irc_channel *channel, const char *topic) } /* + * irc_channel_set_modes: set modes for a channel + */ + +void +irc_channel_set_modes (struct t_irc_channel *channel, const char *modes) +{ + if (channel->modes) + free (channel->modes); + + channel->modes = (modes) ? strdup (modes) : NULL; +} + +/* * irc_channel_search: returns pointer on a channel with name */ @@ -870,7 +882,6 @@ irc_channel_hdata_channel_cb (void *data, const char *hdata_name) WEECHAT_HDATA_VAR(struct t_irc_channel, has_quit_server, INTEGER, NULL); WEECHAT_HDATA_VAR(struct t_irc_channel, cycle, INTEGER, NULL); WEECHAT_HDATA_VAR(struct t_irc_channel, part, INTEGER, NULL); - WEECHAT_HDATA_VAR(struct t_irc_channel, display_creation_date, INTEGER, NULL); WEECHAT_HDATA_VAR(struct t_irc_channel, nick_completion_reset, INTEGER, NULL); WEECHAT_HDATA_VAR(struct t_irc_channel, pv_remote_nick_color, STRING, NULL); WEECHAT_HDATA_VAR(struct t_irc_channel, hook_autorejoin, POINTER, NULL); @@ -969,8 +980,6 @@ irc_channel_add_to_infolist (struct t_infolist *infolist, return 0; if (!weechat_infolist_new_var_integer (ptr_item, "part", channel->part)) return 0; - if (!weechat_infolist_new_var_integer (ptr_item, "display_creation_date", channel->display_creation_date)) - return 0; if (!weechat_infolist_new_var_integer (ptr_item, "nick_completion_reset", channel->nick_completion_reset)) return 0; for (i = 0; i < 2; i++) @@ -1038,7 +1047,6 @@ irc_channel_print_log (struct t_irc_channel *channel) weechat_log_printf (" has_quit_server. . . . . : %d", channel->has_quit_server); weechat_log_printf (" cycle. . . . . . . . . . : %d", channel->cycle); weechat_log_printf (" part . . . . . . . . . . : %d", channel->part); - weechat_log_printf (" display_creation_date. . : %d", channel->display_creation_date); weechat_log_printf (" nick_completion_reset. . : %d", channel->nick_completion_reset); weechat_log_printf (" pv_remote_nick_color . . : '%s'", channel->pv_remote_nick_color); weechat_log_printf (" hook_autorejoin. . . . . : 0x%lx", channel->hook_autorejoin); diff --git a/src/plugins/irc/irc-channel.h b/src/plugins/irc/irc-channel.h index 08845214a..4ebb558bb 100644 --- a/src/plugins/irc/irc-channel.h +++ b/src/plugins/irc/irc-channel.h @@ -53,7 +53,6 @@ struct t_irc_channel /* display message when he's back */ int cycle; /* currently cycling (/part + /join) */ int part; /* /part done on channel? */ - int display_creation_date; /* 1 for displaying creation date */ int nick_completion_reset; /* 1 for resetting nick completion */ /* there was some join/part on chan */ char *pv_remote_nick_color; /* color for remote nick in pv */ @@ -82,6 +81,8 @@ extern struct t_irc_channel *irc_channel_new (struct t_irc_server *server, int auto_switch); extern void irc_channel_set_topic (struct t_irc_channel *channel, const char *topic); +extern void irc_channel_set_modes (struct t_irc_channel *channel, + const char *modes); extern void irc_channel_free (struct t_irc_server *server, struct t_irc_channel *channel); extern void irc_channel_free_all (struct t_irc_server *server); diff --git a/src/plugins/irc/irc-protocol.c b/src/plugins/irc/irc-protocol.c index 10b692779..bb5e8582f 100644 --- a/src/plugins/irc/irc-protocol.c +++ b/src/plugins/irc/irc-protocol.c @@ -487,12 +487,9 @@ IRC_PROTOCOL_CALLBACK(join) } } - /* remove topic and display channel creation date if joining new channel */ + /* remove topic if joining new channel */ if (!ptr_channel->nicks) - { irc_channel_set_topic (ptr_channel, NULL); - ptr_channel->display_creation_date = 1; - } /* add nick in channel */ ptr_nick = irc_nick_new (server, ptr_channel, nick, NULL, 0); @@ -731,6 +728,7 @@ IRC_PROTOCOL_CALLBACK(mode) struct t_irc_channel *ptr_channel; struct t_irc_nick *ptr_nick; struct t_gui_buffer *ptr_buffer; + struct t_hashtable *hashtable; /* * MODE message looks like: @@ -747,10 +745,36 @@ IRC_PROTOCOL_CALLBACK(mode) ptr_channel = irc_channel_search (server, argv[2]); if (ptr_channel) { - if (irc_mode_channel_set (server, ptr_channel, pos_modes)) + if (ptr_channel->modes) + { + if (irc_mode_channel_set (server, ptr_channel, pos_modes)) + { + hashtable = weechat_hashtable_new (8, + WEECHAT_HASHTABLE_STRING, + WEECHAT_HASHTABLE_STRING, + NULL, + NULL); + if (hashtable) + { + weechat_hashtable_set (hashtable, "server", server->name); + weechat_hashtable_set (hashtable, "pattern", "mode_channel"); + weechat_hashtable_set (hashtable, "signal", "mode"); + weechat_hashtable_set (hashtable, "string", ptr_channel->name); + weechat_hook_hsignal_send ("irc_redirect_command", hashtable); + irc_server_sendf (server, IRC_SERVER_SEND_OUTQ_PRIO_LOW, + NULL, "MODE %s", ptr_channel->name); + weechat_hashtable_free (hashtable); + } + else + { + irc_server_sendf (server, IRC_SERVER_SEND_OUTQ_PRIO_LOW, + NULL, "MODE %s", ptr_channel->name); + } + } + } + else { - irc_server_sendf (server, IRC_SERVER_SEND_OUTQ_PRIO_LOW, NULL, - "MODE %s", ptr_channel->name); + (void) irc_mode_channel_set (server, ptr_channel, pos_modes); } } ptr_nick = irc_nick_search (server, ptr_channel, nick); @@ -2605,39 +2629,26 @@ IRC_PROTOCOL_CALLBACK(324) ptr_channel = irc_channel_search (server, argv[3]); if (ptr_channel) { + irc_channel_set_modes (ptr_channel, ((argc > 4) ? argv_eol[4] : NULL)); if (argc > 4) { - if (ptr_channel->modes) - free (ptr_channel->modes); - ptr_channel->modes = strdup (argv_eol[4]); irc_mode_channel_set (server, ptr_channel, ptr_channel->modes); } - else - { - if (ptr_channel->modes) - { - free (ptr_channel->modes); - ptr_channel->modes = NULL; - } - } - } - else - { - weechat_printf_tags (irc_msgbuffer_get_target_buffer (server, NULL, - command, NULL, - NULL), - irc_protocol_tags (command, "irc_numeric", NULL), - _("%sMode %s%s %s[%s%s%s]"), - weechat_prefix ("network"), - IRC_COLOR_CHAT_CHANNEL, - argv[3], - IRC_COLOR_CHAT_DELIMITERS, - IRC_COLOR_RESET, - (argc > 4) ? - ((argv_eol[4][0] == ':') ? argv_eol[4] + 1 : argv_eol[4]) : "", - IRC_COLOR_CHAT_DELIMITERS); } + weechat_printf_tags (irc_msgbuffer_get_target_buffer (server, NULL, + command, NULL, + (ptr_channel) ? ptr_channel->buffer : NULL), + irc_protocol_tags (command, "irc_numeric", NULL), + _("%sMode %s%s %s[%s%s%s]"), + weechat_prefix ("network"), + IRC_COLOR_CHAT_CHANNEL, + argv[3], + IRC_COLOR_CHAT_DELIMITERS, + IRC_COLOR_RESET, + (argc > 4) ? + ((argv_eol[4][0] == ':') ? argv_eol[4] + 1 : argv_eol[4]) : "", + IRC_COLOR_CHAT_DELIMITERS); return WEECHAT_RC_OK; } @@ -2757,18 +2768,14 @@ IRC_PROTOCOL_CALLBACK(329) if (ptr_channel) { - if (ptr_channel->display_creation_date) - { - weechat_printf_tags (irc_msgbuffer_get_target_buffer (server, NULL, - command, NULL, - ptr_channel->buffer), - irc_protocol_tags (command, "irc_numeric", NULL), - /* TRANSLATORS: "%s" after "created on" is a date */ - _("%sChannel created on %s"), - weechat_prefix ("network"), - weechat_util_get_time_string (&datetime)); - ptr_channel->display_creation_date = 0; - } + weechat_printf_tags (irc_msgbuffer_get_target_buffer (server, NULL, + command, NULL, + ptr_channel->buffer), + irc_protocol_tags (command, "irc_numeric", NULL), + /* TRANSLATORS: "%s" after "created on" is a date */ + _("%sChannel created on %s"), + weechat_prefix ("network"), + weechat_util_get_time_string (&datetime)); } else { @@ -4209,6 +4216,69 @@ IRC_PROTOCOL_CALLBACK(sasl_end) } /* + * irc_protocol_redirection_mode_cb: callback for redirection of "mode" command + */ + +int +irc_protocol_redirection_mode_cb (void *data, const char *signal, + struct t_hashtable *hashtable) +{ + const char *output, *server; + char **messages, *command, *arguments, **argv, **argv_eol; + int num_messages, argc, i; + struct t_irc_server *ptr_server; + struct t_irc_channel *ptr_channel; + + /* make C compiler happy */ + (void) data; + (void) signal; + + output = weechat_hashtable_get (hashtable, "output"); + server = weechat_hashtable_get (hashtable, "server"); + if (!output || !server) + return WEECHAT_RC_OK; + + ptr_server = irc_server_search (server); + if (!ptr_server) + return WEECHAT_RC_OK; + + messages = weechat_string_split (output, "\n", 0, 0, &num_messages); + if (messages) + { + for (i = 0; i < num_messages; i++) + { + irc_message_parse (ptr_server, messages[i], NULL, NULL, + &command, NULL, &arguments); + if (command && (strcmp (command, "324") == 0) && arguments) + { + argv = weechat_string_split (arguments, " ", 0, 0, &argc); + argv_eol = weechat_string_split (arguments, " ", 1, 0, NULL); + if (argv && argv_eol && (argc >= 2)) + { + ptr_channel = irc_channel_search (ptr_server, argv[1]); + if (ptr_channel) + { + irc_channel_set_modes (ptr_channel, + (argc >= 3) ? argv_eol[2] : NULL); + if (argc >= 3) + { + irc_mode_channel_set (ptr_server, ptr_channel, + ptr_channel->modes); + } + } + } + if (argv) + weechat_string_free_split (argv); + if (argv_eol) + weechat_string_free_split (argv_eol); + } + } + weechat_string_free_split (messages); + } + return WEECHAT_RC_OK; +} + +/* * irc_protocol_recv_command: executes action when receiving IRC command * return: 0 = all ok, command executed * -1 = command failed diff --git a/src/plugins/irc/irc-protocol.h b/src/plugins/irc/irc-protocol.h index b27741043..714939d91 100644 --- a/src/plugins/irc/irc-protocol.h +++ b/src/plugins/irc/irc-protocol.h @@ -79,6 +79,8 @@ struct t_irc_protocol_msg extern const char *irc_protocol_tags (const char *command, const char *tags, const char *nick); +extern int irc_protocol_redirection_mode_cb (void *data, const char *signal, + struct t_hashtable *hashtable); extern void irc_protocol_recv_command (struct t_irc_server *server, const char *irc_message, const char *msg_command, diff --git a/src/plugins/irc/irc-upgrade.c b/src/plugins/irc/irc-upgrade.c index 6d4b5226b..0172b3c82 100644 --- a/src/plugins/irc/irc-upgrade.c +++ b/src/plugins/irc/irc-upgrade.c @@ -423,7 +423,6 @@ irc_upgrade_read_cb (void *data, irc_upgrade_current_channel->has_quit_server = weechat_infolist_integer (infolist, "has_quit_server"); irc_upgrade_current_channel->cycle = weechat_infolist_integer (infolist, "cycle"); irc_upgrade_current_channel->part = weechat_infolist_integer (infolist, "part"); - irc_upgrade_current_channel->display_creation_date = weechat_infolist_integer (infolist, "display_creation_date"); irc_upgrade_current_channel->nick_completion_reset = weechat_infolist_integer (infolist, "nick_completion_reset"); for (i = 0; i < 2; i++) { diff --git a/src/plugins/irc/irc.c b/src/plugins/irc/irc.c index 3ebaacd1b..b80545374 100644 --- a/src/plugins/irc/irc.c +++ b/src/plugins/irc/irc.c @@ -40,6 +40,7 @@ #include "irc-input.h" #include "irc-nick.h" #include "irc-notify.h" +#include "irc-protocol.h" #include "irc-raw.h" #include "irc-redirect.h" #include "irc-server.h" @@ -184,6 +185,10 @@ weechat_plugin_init (struct t_weechat_plugin *plugin, int argc, char *argv[]) weechat_hook_hsignal ("irc_redirect_pattern", &irc_redirect_pattern_hsignal_cb, NULL); weechat_hook_hsignal ("irc_redirect_command", &irc_redirect_command_hsignal_cb, NULL); + /* hook hsignal for redirection of "mode" output */ + weechat_hook_hsignal ("irc_redirection_mode_mode_channel", + &irc_protocol_redirection_mode_cb, NULL); + /* modifiers */ weechat_hook_modifier ("irc_color_decode", &irc_color_modifier_cb, NULL); weechat_hook_modifier ("irc_color_encode", &irc_color_modifier_cb, NULL); |