diff options
Diffstat (limited to 'src/plugins/irc')
-rw-r--r-- | src/plugins/irc/Makefile.am | 4 | ||||
-rw-r--r-- | src/plugins/irc/irc-buffer.c | 117 | ||||
-rw-r--r-- | src/plugins/irc/irc-buffer.h | 24 | ||||
-rw-r--r-- | src/plugins/irc/irc-channel.c | 4 | ||||
-rw-r--r-- | src/plugins/irc/irc-command.c | 51 | ||||
-rw-r--r-- | src/plugins/irc/irc-command.h | 3 | ||||
-rw-r--r-- | src/plugins/irc/irc-input.c | 8 | ||||
-rw-r--r-- | src/plugins/irc/irc-input.h | 4 | ||||
-rw-r--r-- | src/plugins/irc/irc-protocol.c | 8 | ||||
-rw-r--r-- | src/plugins/irc/irc-server.c | 4 |
10 files changed, 104 insertions, 123 deletions
diff --git a/src/plugins/irc/Makefile.am b/src/plugins/irc/Makefile.am index 599886020..2314b8ba5 100644 --- a/src/plugins/irc/Makefile.am +++ b/src/plugins/irc/Makefile.am @@ -22,6 +22,8 @@ lib_LTLIBRARIES = irc.la irc_la_SOURCES = irc.c \ irc.h \ + irc-buffer.c \ + irc-buffer.h \ irc-channel.c \ irc-channel.h \ irc-color.c \ @@ -44,8 +46,6 @@ irc_la_SOURCES = irc.c \ irc-server.c \ irc-server.h -# irc-buffer.c \ -# irc-buffer.h \ # irc-dcc.c \ # irc-dcc.h \ # irc-log.c diff --git a/src/plugins/irc/irc-buffer.c b/src/plugins/irc/irc-buffer.c index 02384abfc..641d19a5a 100644 --- a/src/plugins/irc/irc-buffer.c +++ b/src/plugins/irc/irc-buffer.c @@ -26,76 +26,26 @@ #include <stdlib.h> #include <string.h> -#include "../../core/weechat.h" +#include "../weechat-plugin.h" #include "irc.h" -#include "../../core/utf8.h" -#include "../../core/weechat-config.h" -#include "../../gui/gui.h" +#include "irc-buffer.h" +#include "irc-channel.h" +#include "irc-command.h" +#include "irc-server.h" /* - * irc_buffer_data_create: create protocol data (for GUI buffer) - */ - -t_irc_buffer_data * -irc_buffer_data_create (t_irc_server *server) -{ - t_irc_buffer_data *buffer_data; - - buffer_data = (t_irc_buffer_data *)malloc (sizeof (t_irc_buffer_data)); - if (!buffer_data) - return NULL; - - buffer_data->server = server; - buffer_data->channel = NULL; - buffer_data->all_servers = irc_cfg_irc_one_server_buffer; - - return buffer_data; -} - -/* - * irc_buffer_data_free: free protocol data (in GUI buffer) - */ - -void -irc_buffer_data_free (t_gui_buffer *buffer) -{ - free ((t_irc_buffer_data *)buffer->protocol_data); -} - -/* - * irc_buffer_servers_search: search servers buffer - * (when same buffer is used for all servers) - */ - -t_gui_buffer * -irc_buffer_servers_search () -{ - t_gui_buffer *ptr_buffer; - - for (ptr_buffer = gui_buffers; ptr_buffer; - ptr_buffer = ptr_buffer->next_buffer) - { - if (IRC_BUFFER_ALL_SERVERS(ptr_buffer)) - return ptr_buffer; - - } - - /* buffer not found */ - return NULL; -} - -/* * irc_buffer_merge_servers: merge server buffers in one buffer */ +/* void irc_buffer_merge_servers (t_gui_window *window) { t_gui_buffer *ptr_buffer_server, *ptr_buffer, *new_ptr_buffer; t_irc_server *ptr_server; - /* new server buffer is the first server buffer found */ + // new server buffer is the first server buffer found for (ptr_buffer_server = gui_buffers; ptr_buffer_server; ptr_buffer_server = ptr_buffer_server->next_buffer) { @@ -105,7 +55,7 @@ irc_buffer_merge_servers (t_gui_window *window) break; } - /* no server buffer found */ + // no server buffer found if (!ptr_buffer_server) return; @@ -119,7 +69,7 @@ irc_buffer_merge_servers (t_gui_window *window) { ptr_server = IRC_BUFFER_SERVER(ptr_buffer); - /* add (by pointer artefact) lines from buffer found to server buffer */ + // add (by pointer artefact) lines from buffer found to server buffer if (ptr_buffer->lines) { if (ptr_buffer_server->lines) @@ -138,14 +88,14 @@ irc_buffer_merge_servers (t_gui_window *window) } } - /* free buffer but not lines, because they're now used by - our unique server buffer */ + // free buffer but not lines, because they're now used by + // our unique server buffer new_ptr_buffer = ptr_buffer->next_buffer; ptr_buffer->lines = NULL; gui_buffer_free (ptr_buffer, 1); ptr_buffer = new_ptr_buffer; - /* asociate server with new server buffer */ + // asociate server with new server buffer ptr_server->buffer = ptr_buffer_server; } else @@ -155,11 +105,13 @@ irc_buffer_merge_servers (t_gui_window *window) IRC_BUFFER_ALL_SERVERS(ptr_buffer_server) = 1; gui_window_redraw_buffer (window->buffer); } +*/ /* * irc_buffer_split_server: split the server buffer into many buffers (one by server) */ +/* void irc_buffer_split_server (t_gui_window *window) { @@ -207,3 +159,44 @@ irc_buffer_split_server (t_gui_window *window) gui_input_draw (window->buffer, 1); } } +*/ + +/* + * irc_buffer_close_cb: callback called when a buffer is closed + */ + +int +irc_buffer_close_cb (void *data, struct t_gui_buffer *buffer) +{ + IRC_GET_SERVER_CHANNEL(buffer); + + /* make C compiler happy */ + (void) data; + + if (ptr_channel) + { + /* send PART for channel if its buffer is closed */ + if (ptr_channel->type == IRC_CHANNEL_TYPE_CHANNEL) + { + irc_command_part_channel (ptr_server, ptr_channel->name, NULL); + irc_channel_free (ptr_server, ptr_channel); + } + } + else + { + if (ptr_server) + { + /* send PART on all channels for server, then disconnect from server */ + for (ptr_channel = ptr_server->channels; ptr_channel; + ptr_channel = ptr_channel->next_channel) + { + irc_command_part_channel (ptr_server, ptr_channel->name, NULL); + irc_channel_free (ptr_server, ptr_channel); + } + irc_server_disconnect (ptr_server, 0); + ptr_server->buffer = NULL; + } + } + + return WEECHAT_RC_OK; +} diff --git a/src/plugins/irc/irc-buffer.h b/src/plugins/irc/irc-buffer.h index 876187d9d..82dd14848 100644 --- a/src/plugins/irc/irc-buffer.h +++ b/src/plugins/irc/irc-buffer.h @@ -20,28 +20,6 @@ #ifndef __WEECHAT_IRC_BUFFER_H #define __WEECHAT_IRC_BUFFER_H 1 -#define IRC_BUFFER_SERVER(buffer) (((t_irc_buffer_data *)(buffer->protocol_data))->server) -#define IRC_BUFFER_CHANNEL(buffer) (((t_irc_buffer_data *)(buffer->protocol_data))->channel) -#define IRC_BUFFER_ALL_SERVERS(buffer) (((t_irc_buffer_data *)(buffer->protocol_data))->all_servers) - -#define IRC_BUFFER_GET_SERVER(buffer) \ - t_irc_server *ptr_server = IRC_BUFFER_SERVER(buffer) -#define IRC_BUFFER_GET_CHANNEL(buffer) \ - t_irc_channel *ptr_channel = IRC_BUFFER_CHANNEL(buffer) -#define IRC_BUFFER_GET_SERVER_CHANNEL(buffer) \ - t_irc_server *ptr_server = IRC_BUFFER_SERVER(buffer); \ - t_irc_channel *ptr_channel = IRC_BUFFER_CHANNEL(buffer) - -struct t_irc_buffer_data -{ - struct t_irc_server *server; - struct t_irc_channel *channel; - int all_servers; -}; - -extern struct t_irc_buffer_data *irc_buffer_data_create (struct t_irc_server *server); -extern void irc_buffer_data_free (struct t_gui_buffer *buffer); -extern void irc_buffer_merge_servers (struct t_gui_window *window); -extern void irc_buffer_split_server (struct t_gui_window *window); +extern int irc_buffer_close_cb (void *data, struct t_gui_buffer *buffer); #endif /* irc-buffer.h */ diff --git a/src/plugins/irc/irc-channel.c b/src/plugins/irc/irc-channel.c index bfb825854..ae2c409c0 100644 --- a/src/plugins/irc/irc-channel.c +++ b/src/plugins/irc/irc-channel.c @@ -30,6 +30,7 @@ #include "../weechat-plugin.h" #include "irc.h" #include "irc-channel.h" +#include "irc-buffer.h" #include "irc-config.h" #include "irc-dcc.h" #include "irc-nick.h" @@ -60,7 +61,8 @@ irc_channel_new (struct t_irc_server *server, int channel_type, /* create buffer for channel */ new_buffer = weechat_buffer_new (server->name, channel_name, - &irc_input_data, NULL); + &irc_input_data_cb, NULL, + &irc_buffer_close_cb, NULL); if (!new_buffer) { free (new_channel); diff --git a/src/plugins/irc/irc-command.c b/src/plugins/irc/irc-command.c index ea2a906b1..2e8c56feb 100644 --- a/src/plugins/irc/irc-command.c +++ b/src/plugins/irc/irc-command.c @@ -2103,6 +2103,35 @@ irc_command_oper (void *data, struct t_gui_buffer *buffer, int argc, } /* + * irc_command_part_channel: send a part message for a channel + */ + +void +irc_command_part_channel (struct t_irc_server *server, char *channel_name, + char *part_message) +{ + char *ptr_arg, *buf, *version; + + ptr_arg = (part_message) ? part_message : + (weechat_config_string (irc_config_irc_default_msg_part) + && weechat_config_string (irc_config_irc_default_msg_part)[0]) ? + weechat_config_string (irc_config_irc_default_msg_part) : NULL; + + if (ptr_arg) + { + version = weechat_info_get ("version"); + buf = weechat_string_replace (ptr_arg, "%v", (version) ? version : ""); + irc_server_sendf (server, "PART %s :%s", + channel_name, + (buf) ? buf : ptr_arg); + if (buf) + free (buf); + } + else + irc_server_sendf (server, "PART %s", channel_name); +} + +/* * irc_command_part: leave a channel or close a private window */ @@ -2110,7 +2139,7 @@ int irc_command_part (void *data, struct t_gui_buffer *buffer, int argc, char **argv, char **argv_eol) { - char *channel_name, *pos_args, *ptr_arg, *buf, *version; + char *channel_name, *pos_args; IRC_GET_SERVER_CHANNEL(buffer); if (!ptr_server || !ptr_server->is_connected) @@ -2157,31 +2186,13 @@ irc_command_part (void *data, struct t_gui_buffer *buffer, int argc, weechat_buffer_close (ptr_channel->buffer, 1); ptr_channel->buffer = NULL; irc_channel_free (ptr_server, ptr_channel); - //gui_status_draw (gui_current_window->buffer, 1); - //gui_input_draw (gui_current_window->buffer, 1); return WEECHAT_RC_OK; } channel_name = ptr_channel->name; pos_args = NULL; } - ptr_arg = (pos_args) ? pos_args : - (weechat_config_string (irc_config_irc_default_msg_part) - && weechat_config_string (irc_config_irc_default_msg_part)[0]) ? - weechat_config_string (irc_config_irc_default_msg_part) : NULL; - - if (ptr_arg) - { - version = weechat_info_get ("version"); - buf = weechat_string_replace (ptr_arg, "%v", (version) ? version : ""); - irc_server_sendf (ptr_server, "PART %s :%s", - channel_name, - (buf) ? buf : ptr_arg); - if (buf) - free (buf); - } - else - irc_server_sendf (ptr_server, "PART %s", channel_name); + irc_command_part_channel (ptr_server, channel_name, pos_args); return WEECHAT_RC_OK; } diff --git a/src/plugins/irc/irc-command.h b/src/plugins/irc/irc-command.h index 7aa0f6834..fbc346725 100644 --- a/src/plugins/irc/irc-command.h +++ b/src/plugins/irc/irc-command.h @@ -35,6 +35,9 @@ extern void irc_command_join_server (struct t_irc_server *server, char *arguments); extern void irc_command_mode_server (struct t_irc_server *server, char *arguments); +extern void irc_command_part_channel (struct t_irc_server *server, + char *channel_name, + char *part_message); extern void irc_command_quit_server (struct t_irc_server *server, char *arguments); extern void irc_command_init (); diff --git a/src/plugins/irc/irc-input.c b/src/plugins/irc/irc-input.c index fc0b6a450..93c8f026c 100644 --- a/src/plugins/irc/irc-input.c +++ b/src/plugins/irc/irc-input.c @@ -146,13 +146,13 @@ irc_input_send_user_message (struct t_gui_buffer *buffer, char *text) } /* - * irc_input_data: read data from user input - * Return: PROTOCOL_RC_OK if ok - * PROTOCOL_RC_KO if error + * irc_input_data_cb: callback for input data in a buffer + * Return: PROTOCOL_RC_OK if ok + * PROTOCOL_RC_KO if error */ int -irc_input_data (void *data, struct t_gui_buffer *buffer, char *input_data) +irc_input_data_cb (void *data, struct t_gui_buffer *buffer, char *input_data) { char *data_with_colors; diff --git a/src/plugins/irc/irc-input.h b/src/plugins/irc/irc-input.h index f7efa95a8..6310546ad 100644 --- a/src/plugins/irc/irc-input.h +++ b/src/plugins/irc/irc-input.h @@ -20,7 +20,7 @@ #ifndef __WEECHAT_IRC_INPUT_H #define __WEECHAT_IRC_INPUT_H 1 -extern int irc_input_data (void *data, struct t_gui_buffer *buffer, - char *input_data); +extern int irc_input_data_cb (void *data, struct t_gui_buffer *buffer, + char *input_data); #endif /* irc-input.h */ diff --git a/src/plugins/irc/irc-protocol.c b/src/plugins/irc/irc-protocol.c index 1b63781d9..285b71c04 100644 --- a/src/plugins/irc/irc-protocol.c +++ b/src/plugins/irc/irc-protocol.c @@ -1491,14 +1491,6 @@ irc_protocol_cmd_part (struct t_irc_server *server, char *irc_message, char *hos irc_nick_free (ptr_channel, ptr_nick); } } - else - { - weechat_printf (server->buffer, - _("%s%s: channel \"%s\" not found for \"%s\" " - "command"), - weechat_prefix ("error"), "irc", arguments, "part"); - return WEECHAT_RC_ERROR; - } return WEECHAT_RC_OK; } diff --git a/src/plugins/irc/irc-server.c b/src/plugins/irc/irc-server.c index 2d22f6cf9..96bb9729d 100644 --- a/src/plugins/irc/irc-server.c +++ b/src/plugins/irc/irc-server.c @@ -47,6 +47,7 @@ #include "../weechat-plugin.h" #include "irc.h" #include "irc-server.h" +#include "irc-buffer.h" #include "irc-channel.h" #include "irc-command.h" #include "irc-config.h" @@ -2263,7 +2264,8 @@ irc_server_connect (struct t_irc_server *server, int disable_autojoin) if (!server->buffer) { server->buffer = weechat_buffer_new (server->name, server->name, - NULL, NULL); + NULL, NULL, + &irc_buffer_close_cb, NULL); if (!server->buffer) return 0; weechat_buffer_set (server->buffer, "display", "1"); |