1
0
mirror of https://github.com/weechat/weechat.git synced 2026-07-04 16:53:14 +02:00

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").
This commit is contained in:
Sebastien Helleu
2008-02-22 14:29:34 +01:00
parent 3187d9627b
commit c5a30be877
34 changed files with 509 additions and 468 deletions
+5 -9
View File
@@ -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)
+2
View File
@@ -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 \
+1
View File
@@ -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,
+1 -13
View File
@@ -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);
}
/*
+1 -7
View File
@@ -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,
+168
View File
@@ -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);
}
+34
View File
@@ -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 */
+8 -19
View File
@@ -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
+44 -44
View File
@@ -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"
@@ -355,6 +356,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);
}
/*
+1
View File
@@ -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);
+3 -60
View File
@@ -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,68 +53,11 @@ 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 */