diff options
author | Sebastien Helleu <flashcode@flashtux.org> | 2008-02-22 14:29:34 +0100 |
---|---|---|
committer | Sebastien Helleu <flashcode@flashtux.org> | 2008-02-22 14:29:34 +0100 |
commit | c5a30be877975e32b1c7c12e00b15e0f49e8ac2e (patch) | |
tree | f2af940ea991776705d8b4c842f117d608c1c32b /src/plugins | |
parent | 3187d9627b46193d18ee4e90721d8b059cc95d70 (diff) | |
download | weechat-c5a30be877975e32b1c7c12e00b15e0f49e8ac2e.zip |
New "irc/debug" buffer (replaces old IRC raw buffer), improved status bar display, fixed nick in input for IRC buffers
The "irc/debug" buffer is displayed when IRC debug is enabled (with "/debug irc" thru debug plugin).
If the buffer is closed, it is reopen when new messages are written, until debug is disabled by user (with "/debug irc").
Diffstat (limited to 'src/plugins')
-rw-r--r-- | src/plugins/irc/CMakeLists.txt | 14 | ||||
-rw-r--r-- | src/plugins/irc/Makefile.am | 2 | ||||
-rw-r--r-- | src/plugins/irc/irc-channel.c | 1 | ||||
-rw-r--r-- | src/plugins/irc/irc-command.c | 14 | ||||
-rw-r--r-- | src/plugins/irc/irc-dcc.c | 8 | ||||
-rw-r--r-- | src/plugins/irc/irc-debug.c | 168 | ||||
-rw-r--r-- | src/plugins/irc/irc-debug.h | 34 | ||||
-rw-r--r-- | src/plugins/irc/irc-protocol.c | 27 | ||||
-rw-r--r-- | src/plugins/irc/irc-server.c | 88 | ||||
-rw-r--r-- | src/plugins/irc/irc-server.h | 1 | ||||
-rw-r--r-- | src/plugins/irc/irc.c | 63 |
11 files changed, 268 insertions, 152 deletions
diff --git a/src/plugins/irc/CMakeLists.txt b/src/plugins/irc/CMakeLists.txt index af1a20736..1eabff5d9 100644 --- a/src/plugins/irc/CMakeLists.txt +++ b/src/plugins/irc/CMakeLists.txt @@ -14,15 +14,11 @@ # along with this program. If not, see <http://www.gnu.org/licenses/>. # -SET(LIB_PROTOCOL_IRC_SRC irc.c irc.h irc-channel.c irc-channel.h irc-command.c -irc-command.h irc-completion.c irc-completion.h irc-config.c irc-config.h -irc-server.c irc-server.h) - -#SET(LIB_PROTOCOL_IRC_SRC irc.c irc.h irc-buffer.c irc-buffer.h irc-channel.c -#irc-channel.h irc-command.c irc-command.h irc-completion.c irc-completion.h -#irc-color.c irc-color.h irc-config.c irc-config.h irc-dcc.c irc-dcc.h -#irc-display.c irc-input.c irc-log.c irc-mode.c irc-nick.c irc-nick.h -#irc-protocol.c irc-protocol.h irc-server.c irc-server.h) +SET(LIB_PROTOCOL_IRC_SRC irc.c irc.h irc-buffer.c irc-buffer.h irc-channel.c +irc-channel.h irc-color.c irc-color.h irc-command.c irc-command.h +irc-completion.c irc-completion.h irc-config.c irc-config.h irc-debug.c +irc-debug.h irc-display.c irc-display.h irc-input.c irc-mode.c irc-mode.h +irc-nick.c irc-nick.h irc-protocol.c irc-protocol.h irc-server.c irc-server.h) CHECK_INCLUDE_FILES("regex.h" HAVE_REGEX_H) CHECK_FUNCTION_EXISTS(regexec HAVE_REGEXEC) diff --git a/src/plugins/irc/Makefile.am b/src/plugins/irc/Makefile.am index e09178e09..0589f5da8 100644 --- a/src/plugins/irc/Makefile.am +++ b/src/plugins/irc/Makefile.am @@ -34,6 +34,8 @@ irc_la_SOURCES = irc.c \ irc-completion.h \ irc-config.c \ irc-config.h \ + irc-debug.c \ + irc-debug.h \ irc-display.c \ irc-display.h \ irc-input.c \ diff --git a/src/plugins/irc/irc-channel.c b/src/plugins/irc/irc-channel.c index 938485fe2..cd18fe33e 100644 --- a/src/plugins/irc/irc-channel.c +++ b/src/plugins/irc/irc-channel.c @@ -70,6 +70,7 @@ irc_channel_new (struct t_irc_server *server, int channel_type, } if (channel_type == IRC_CHANNEL_TYPE_CHANNEL) { + weechat_buffer_set (new_buffer, "nick", server->nick); weechat_buffer_set (new_buffer, "nicklist", "1"); weechat_buffer_set (new_buffer, "nicklist_display_groups", "0"); weechat_nicklist_add_group (new_buffer, NULL, IRC_NICK_GROUP_OP, diff --git a/src/plugins/irc/irc-command.c b/src/plugins/irc/irc-command.c index 74646e2a5..80723a07a 100644 --- a/src/plugins/irc/irc-command.c +++ b/src/plugins/irc/irc-command.c @@ -1928,25 +1928,13 @@ irc_command_names (void *data, struct t_gui_buffer *buffer, int argc, void irc_send_nick_server (struct t_irc_server *server, char *nickname) { - struct t_irc_channel *ptr_channel; - if (!server) return; if (server->is_connected) irc_server_sendf (server, "NICK %s", nickname); else - { - if (server->nick) - free (server->nick); - server->nick = strdup (nickname); - //gui_input_draw (server->buffer, 1); - for (ptr_channel = server->channels; ptr_channel; - ptr_channel = ptr_channel->next_channel) - { - //gui_input_draw (ptr_channel->buffer, 1); - } - } + irc_server_set_nick (server, nickname); } /* diff --git a/src/plugins/irc/irc-dcc.c b/src/plugins/irc/irc-dcc.c index 021221d9a..dd3a06077 100644 --- a/src/plugins/irc/irc-dcc.c +++ b/src/plugins/irc/irc-dcc.c @@ -1216,13 +1216,7 @@ irc_dcc_chat_sendf (struct t_irc_dcc *dcc, char *format, ...) buffer[sizeof (buffer) - 1] = '\0'; if ((size_buf < 0) || (size_buf > (int) (sizeof (buffer) - 1))) size_buf = strlen (buffer); -#ifdef DEBUG - buffer[size_buf - 2] = '\0'; - gui_chat_printf (dcc->server->buffer, - "[DEBUG] Sending to remote host (DCC CHAT) >>> %s\n", - buffer); - buffer[size_buf - 2] = '\r'; -#endif + if (irc_dcc_chat_send (dcc, buffer, strlen (buffer)) <= 0) { gui_chat_printf_error (dcc->server->buffer, diff --git a/src/plugins/irc/irc-debug.c b/src/plugins/irc/irc-debug.c new file mode 100644 index 000000000..67b4bbfb9 --- /dev/null +++ b/src/plugins/irc/irc-debug.c @@ -0,0 +1,168 @@ +/* + * Copyright (c) 2003-2008 by FlashCode <flashcode@flashtux.org> + * See README for License detail, AUTHORS for developers list. + * + * 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 3 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, see <http://www.gnu.org/licenses/>. + */ + +/* irc-debug.c: debug functions for IRC plugin */ + + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include <stdlib.h> +#include <string.h> + +#include "../weechat-plugin.h" +#include "irc.h" +#include "irc-debug.h" +#include "irc-server.h" + + +int irc_debug = 0; +struct t_gui_buffer *irc_debug_buffer = NULL; + + +/* + * irc_debug_buffer_close_cb: callback called when IRC debug buffer is closed + */ + +int +irc_debug_buffer_close_cb (void *data, struct t_gui_buffer *buffer) +{ + /* make C compiler happy */ + (void) data; + (void) buffer; + + irc_debug_buffer = NULL; + + return WEECHAT_RC_OK; +} + +/* + * irc_debug_printf: print a message on IRC debug buffer + */ + +void +irc_debug_printf (struct t_irc_server *server, int send, int modified, + char *message) +{ + char *buf; + + if (!irc_debug || !message) + return; + + if (!irc_debug_buffer) + { + /* search for irc debug buffer */ + irc_debug_buffer = weechat_buffer_search ("irc", "debug"); + if (!irc_debug_buffer) + { + irc_debug_buffer = weechat_buffer_new ("irc", "debug", + NULL, NULL, + &irc_debug_buffer_close_cb, NULL); + /* failed to create buffer ? then exit */ + if (!irc_debug_buffer) + return; + + weechat_buffer_set (irc_debug_buffer, + "title", _("IRC debug messages")); + } + } + + buf = weechat_iconv_to_internal (NULL, message); + + weechat_printf (irc_debug_buffer, + "%s%s%s%s%s\t%s", + (server) ? weechat_color ("color_chat_server") : "", + (server) ? server->name : "", + (server) ? " " : "", + (send) ? + weechat_color ("color_chat_prefix_quit") : + weechat_color ("color_chat_prefix_join"), + (send) ? + ((modified) ? IRC_DEBUG_PREFIX_SEND_MOD : IRC_DEBUG_PREFIX_SEND) : + ((modified) ? IRC_DEBUG_PREFIX_RECV_MOD : IRC_DEBUG_PREFIX_RECV), + (buf) ? buf : message); + if (buf) + free (buf); +} + +/* + * irc_debug_signal_debug_cb: callback for "debug" signal + */ + +int +irc_debug_signal_debug_cb (void *data, char *signal, char *type_data, + void *signal_data) +{ + /* make C compiler happy */ + (void) data; + (void) signal; + + if (strcmp (type_data, WEECHAT_HOOK_SIGNAL_STRING) == 0) + { + if (weechat_strcasecmp ((char *)signal_data, "irc") == 0) + irc_debug ^= 1; + } + + if (irc_debug) + weechat_printf (NULL, _("%s: debug enabled"), "irc"); + else + weechat_printf (NULL, _("%s: debug disabled"), "irc"); + + return WEECHAT_RC_OK; +} + +/* + * irc_debug_signal_debug_dump_cb: dump IRC data in WeeChat log file + */ + +int +irc_debug_signal_debug_dump_cb (void *data, char *signal, char *type_data, + void *signal_data) +{ + /* make C compiler happy */ + (void) data; + (void) signal; + (void) type_data; + (void) signal_data; + + weechat_log_printf (""); + weechat_log_printf ("***** \"%s\" plugin dump *****", + weechat_plugin->name); + + irc_server_print_log (); + + //irc_dcc_print_log (); + + weechat_log_printf (""); + weechat_log_printf ("***** End of \"%s\" plugin dump *****", + weechat_plugin->name); + + return WEECHAT_RC_OK; +} + +/* + * irc_debug_init: initialize debug for IRC plugin + */ + +void +irc_debug_init () +{ + weechat_hook_signal ("debug", &irc_debug_signal_debug_cb, NULL); + weechat_hook_signal ("debug_dump", &irc_debug_signal_debug_dump_cb, NULL); +} diff --git a/src/plugins/irc/irc-debug.h b/src/plugins/irc/irc-debug.h new file mode 100644 index 000000000..421c21b9a --- /dev/null +++ b/src/plugins/irc/irc-debug.h @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2003-2008 by FlashCode <flashcode@flashtux.org> + * See README for License detail, AUTHORS for developers list. + * + * 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 3 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, see <http://www.gnu.org/licenses/>. + */ + + +#ifndef __WEECHAT_IRC_DEBUG_H +#define __WEECHAT_IRC_DEBUG_H 1 + +#define IRC_DEBUG_PREFIX_RECV "-->" +#define IRC_DEBUG_PREFIX_RECV_MOD "==>" +#define IRC_DEBUG_PREFIX_SEND "<--" +#define IRC_DEBUG_PREFIX_SEND_MOD "<==" + +struct t_irc_server; + +extern void irc_debug_printf (struct t_irc_server *server, int send, + int modified, char *message); +extern void irc_debug_init (); + +#endif /* irc-debug.h */ diff --git a/src/plugins/irc/irc-protocol.c b/src/plugins/irc/irc-protocol.c index ef8f657c7..45c85a16c 100644 --- a/src/plugins/irc/irc-protocol.c +++ b/src/plugins/irc/irc-protocol.c @@ -1140,17 +1140,7 @@ irc_protocol_cmd_nick (struct t_irc_server *server, char *irc_message, char *hos } if (strcmp (server->nick, nick) == 0) - { - free (server->nick); - server->nick = strdup (arguments); - - for (ptr_channel = server->channels; ptr_channel; - ptr_channel = ptr_channel->next_channel) - { - weechat_buffer_set (ptr_channel->buffer, "nick", - server->nick); - } - } + irc_server_set_nick (server, arguments); return WEECHAT_RC_OK; } @@ -2677,10 +2667,7 @@ irc_protocol_cmd_001 (struct t_irc_server *server, char *irc_message, char *host if (pos) pos[0] = '\0'; if (strcmp (server->nick, arguments) != 0) - { - free (server->nick); - server->nick = strdup (arguments); - } + irc_server_set_nick (server, arguments); irc_protocol_cmd_server_msg (server, irc_message, host, nick, arguments, ignore, highlight); @@ -5288,8 +5275,9 @@ irc_protocol_cmd_432 (struct t_irc_server *server, int argc, char **argv, "trying nickname #%d (\"%s\")"), weechat_prefix ("info"), "irc", server->nick, nick_to_use + 1, server->nicks_array[nick_to_use]); - free (server->nick); - server->nick = strdup (server->nicks_array[nick_to_use]); + + irc_server_set_nick (server, server->nicks_array[nick_to_use]); + irc_server_sendf (server, "NICK %s", server->nick); } @@ -5343,8 +5331,9 @@ irc_protocol_cmd_433 (struct t_irc_server *server, int argc, char **argv, "trying nickname #%d (\"%s\")"), weechat_prefix ("info"), "irc", server->nick, nick_to_use + 1, server->nicks_array[nick_to_use]); - free (server->nick); - server->nick = strdup (server->nicks_array[nick_to_use]); + + irc_server_set_nick (server, server->nicks_array[nick_to_use]); + irc_server_sendf (server, "NICK %s", server->nick); } else diff --git a/src/plugins/irc/irc-server.c b/src/plugins/irc/irc-server.c index 5249dfe8f..bd1d257f4 100644 --- a/src/plugins/irc/irc-server.c +++ b/src/plugins/irc/irc-server.c @@ -51,6 +51,7 @@ #include "irc-channel.h" #include "irc-command.h" #include "irc-config.h" +#include "irc-debug.h" #include "irc-nick.h" #include "irc-protocol.h" @@ -356,6 +357,28 @@ irc_server_set_nicks (struct t_irc_server *server, char *nicks) } /* + * irc_server_set_nick: set nickname for a server + */ + +void +irc_server_set_nick (struct t_irc_server *server, char *nick) +{ + struct t_irc_channel *ptr_channel; + + if (server->nick) + free (server->nick); + server->nick = (nick) ? strdup (nick) : NULL; + + weechat_buffer_set (server->buffer, "nick", nick); + + for (ptr_channel = server->channels; ptr_channel; + ptr_channel = ptr_channel->next_channel) + { + weechat_buffer_set (ptr_channel->buffer, "nick", nick); + } +} + +/* * irc_server_init_with_config_options: init a server with config options * (called when reading config file) */ @@ -944,8 +967,8 @@ irc_server_outqueue_send (struct t_irc_server *server) pos = strchr (server->outqueue->message_before_mod, '\r'); if (pos) pos[0] = '\0'; - //gui_chat_printf_raw_data (server, 1, 0, - // server->outqueue->message_before_mod); + irc_debug_printf (server, 1, 0, + server->outqueue->message_before_mod); if (pos) pos[0] = '\r'; } @@ -954,8 +977,8 @@ irc_server_outqueue_send (struct t_irc_server *server) pos = strchr (server->outqueue->message_after_mod, '\r'); if (pos) pos[0] = '\0'; - //gui_chat_printf_raw_data (server, 1, server->outqueue->modified, - // server->outqueue->message_after_mod); + irc_debug_printf (server, 1, server->outqueue->modified, + server->outqueue->message_after_mod); if (pos) pos[0] = '\r'; } @@ -980,13 +1003,7 @@ irc_server_send_one_msg (struct t_irc_server *server, char *message) time_t time_now; rc = 1; - - if (irc_debug) - { - weechat_printf (server->buffer, - "[DEBUG] Sending to server >>> %s", - message); - } + /*new_msg = plugin_modifier_exec (PLUGIN_MODIFIER_IRC_OUT, server->name, message) @@ -1034,10 +1051,10 @@ irc_server_send_one_msg (struct t_irc_server *server, char *message) } else { - //if (first_message) - // gui_chat_printf_raw_data (server, 1, 0, message); - //if (new_msg) - // gui_chat_printf_raw_data (server, 1, 1, ptr_msg); + if (first_message) + irc_debug_printf (server, 1, 0, message); + if (new_msg) + irc_debug_printf (server, 1, 1, ptr_msg); if (irc_server_send (server, buffer, strlen (buffer)) <= 0) rc = 0; else @@ -1057,8 +1074,8 @@ irc_server_send_one_msg (struct t_irc_server *server, char *message) first_message = 0; } } - //else - // gui_chat_printf_raw_data (server, 1, 1, _("(message dropped)")); + else + irc_debug_printf (server, 1, 1, _("(message dropped)")); if (new_msg) free (new_msg); @@ -1347,26 +1364,13 @@ irc_server_msgq_flush () { if (irc_recv_msgq->data) { - if (irc_debug) - { - weechat_printf (irc_recv_msgq->server->buffer, - "[DEBUG] %s", - irc_recv_msgq->data); - } ptr_data = irc_recv_msgq->data; while (ptr_data[0] == ' ') ptr_data++; if (ptr_data[0]) { - //gui_chat_printf_raw_data (irc_recv_msgq->server, 0, 0, - // ptr_data); - if (irc_debug) - { - weechat_printf (irc_recv_msgq->server->buffer, - "[DEBUG] data received from server: %s", - ptr_data); - } + irc_debug_printf (irc_recv_msgq->server, 0, 0, ptr_data); /*new_msg = plugin_modifier_exec (PLUGIN_MODIFIER_IRC_IN, irc_recv_msgq->server->name, ptr_data);*/ @@ -1391,9 +1395,9 @@ irc_server_msgq_flush () if (pos) pos[0] = '\0'; - //if (new_msg) - // gui_chat_printf_raw_data (irc_recv_msgq->server, - // 0, 1, ptr_msg); + if (new_msg) + irc_debug_printf (irc_recv_msgq->server, 0, 1, + ptr_msg); irc_server_parse_message (ptr_msg, &nick, &host, &command, &channel, @@ -1474,9 +1478,9 @@ irc_server_msgq_flush () ptr_msg = NULL; } } - //else - // gui_chat_printf_raw_data (irc_recv_msgq->server, 0, 1, - // _("(message dropped)")); + else + irc_debug_printf (irc_recv_msgq->server, 0, 1, + _("(message dropped)")); if (new_msg) free (new_msg); } @@ -1724,7 +1728,8 @@ irc_server_login (struct t_irc_server *server) irc_server_sendf (server, "PASS %s", server->password); if (!server->nick) - server->nick = strdup (server->nicks_array[0]); + irc_server_set_nick (server, server->nicks_array[0]); + irc_server_sendf (server, "NICK %s\n" "USER %s %s %s :%s", @@ -2678,12 +2683,7 @@ irc_server_disconnect (struct t_irc_server *server, int reconnect) /* discard current nick if no reconnection asked */ if (!reconnect && server->nick) - { - free (server->nick); - server->nick = NULL; - } - - //gui_window_redraw_buffer (weechat_current_buffer); + irc_server_set_nick (server, NULL); } /* diff --git a/src/plugins/irc/irc-server.h b/src/plugins/irc/irc-server.h index 10f331711..e21b044ff 100644 --- a/src/plugins/irc/irc-server.h +++ b/src/plugins/irc/irc-server.h @@ -139,6 +139,7 @@ extern struct t_irc_message *irc_recv_msgq, *irc_msgq_last_msg; extern void irc_server_init (struct t_irc_server *server); extern int irc_server_init_with_url (struct t_irc_server *server, char *irc_url); +extern void irc_server_set_nick (struct t_irc_server *server, char *nick); extern void irc_server_init_with_config_options (struct t_irc_server *server, struct t_config_section *section, int config_reload); diff --git a/src/plugins/irc/irc.c b/src/plugins/irc/irc.c index 5181fff73..53fa94036 100644 --- a/src/plugins/irc/irc.c +++ b/src/plugins/irc/irc.c @@ -35,6 +35,7 @@ #include "irc-command.h" #include "irc-completion.h" #include "irc-config.h" +#include "irc-debug.h" #include "irc-server.h" #include "irc-channel.h" #include "irc-nick.h" @@ -52,69 +53,12 @@ struct t_weechat_plugin *weechat_irc_plugin = NULL; struct t_hook *irc_hook_timer = NULL; struct t_hook *irc_hook_timer_check_away = NULL; -int irc_debug = 0; - #ifdef HAVE_GNUTLS gnutls_certificate_credentials gnutls_xcred; /* gnutls client credentials */ #endif /* - * irc_signal_debug_cb: callback for "debug" signal - */ - -int -irc_signal_debug_cb (void *data, char *signal, char *type_data, - void *signal_data) -{ - /* make C compiler happy */ - (void) data; - (void) signal; - - if (strcmp (type_data, WEECHAT_HOOK_SIGNAL_STRING) == 0) - { - if (weechat_strcasecmp ((char *)signal_data, "irc") == 0) - irc_debug ^= 1; - } - - if (irc_debug) - weechat_printf (NULL, _("%s: debug enabled"), "irc"); - else - weechat_printf (NULL, _("%s: debug disabled"), "irc"); - - return WEECHAT_RC_OK; -} - -/* - * irc_signal_debug_dump_cb: dump IRC data in WeeChat log file - */ - -int -irc_signal_debug_dump_cb (void *data, char *signal, char *type_data, - void *signal_data) -{ - /* make C compiler happy */ - (void) data; - (void) signal; - (void) type_data; - (void) signal_data; - - weechat_log_printf (""); - weechat_log_printf ("***** \"%s\" plugin dump *****", - weechat_plugin->name); - - irc_server_print_log (); - - //irc_dcc_print_log (); - - weechat_log_printf (""); - weechat_log_printf ("***** End of \"%s\" plugin dump *****", - weechat_plugin->name); - - return WEECHAT_RC_OK; -} - -/* * irc_create_directories: create directories for IRC plugin */ @@ -140,7 +84,7 @@ irc_create_directories () } /* - * irc_siangl_quit_cb: callback for "quit" signal + * irc_signal_quit_cb: callback for "quit" signal */ int @@ -192,8 +136,7 @@ weechat_plugin_init (struct t_weechat_plugin *plugin) irc_command_init (); /* hook some signals */ - weechat_hook_signal ("debug", &irc_signal_debug_cb, NULL); - weechat_hook_signal ("debug_dump", &irc_signal_debug_dump_cb, NULL); + irc_debug_init (); weechat_hook_signal ("quit", &irc_signal_quit_cb, NULL); /* hook completions */ |