summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSébastien Helleu <flashcode@flashtux.org>2015-08-22 09:47:01 +0200
committerSébastien Helleu <flashcode@flashtux.org>2015-08-22 09:47:01 +0200
commitd05ebd18c1156c30635751cafc41750ea4374b64 (patch)
tree11f2899cfb851a4994fe0a092252c497fca9147c
parent0443ef49e783d0cdb3092c2a11ed0b2fc18b826c (diff)
downloadweechat-d05ebd18c1156c30635751cafc41750ea4374b64.zip
irc: add hex dump of messages in raw buffer
The dump of messages is displyed when the debug is enabled for irc plugin (level 2 or more), for example: /debug set irc 2
-rw-r--r--ChangeLog.asciidoc2
-rw-r--r--src/plugins/irc/irc-raw.c138
-rw-r--r--src/plugins/irc/irc-raw.h1
3 files changed, 85 insertions, 56 deletions
diff --git a/ChangeLog.asciidoc b/ChangeLog.asciidoc
index ce0a25ecf..1856ff10f 100644
--- a/ChangeLog.asciidoc
+++ b/ChangeLog.asciidoc
@@ -21,6 +21,8 @@ https://weechat.org/files/releasenotes/ReleaseNotes-devel.html[release notes]
* api: add function string_hex_dump()
* api: add argument "length" in function utf8_is_valid()
+* irc: add hex dump of messages in raw buffer when debug is enabled for irc
+ plugin (level 2 or more)
=== Bugs fixed
diff --git a/src/plugins/irc/irc-raw.c b/src/plugins/irc/irc-raw.c
index 6c4955669..58a55afce 100644
--- a/src/plugins/irc/irc-raw.c
+++ b/src/plugins/irc/irc-raw.c
@@ -229,73 +229,85 @@ irc_raw_message_add (struct t_irc_server *server, int flags,
int pos_buf, pos_buf2, char_size, i;
struct t_irc_raw_message *new_raw_message;
- buf = weechat_iconv_to_internal (NULL, message);
- buf2 = malloc ((strlen (buf) * 4) + 1);
- if (buf2)
+ buf = NULL;
+ buf2 = NULL;
+
+ if (flags & IRC_RAW_FLAG_BINARY)
+ {
+ buf = weechat_string_hex_dump (message, strlen (message), 16,
+ " > ", NULL);
+ snprintf (prefix, sizeof (prefix), " ");
+ }
+ else
{
- ptr_buf = (buf) ? (unsigned char *)buf : (unsigned char *)message;
- pos_buf = 0;
- pos_buf2 = 0;
- while (ptr_buf[pos_buf])
+ buf = weechat_iconv_to_internal (NULL, message);
+ buf2 = malloc ((strlen (buf) * 4) + 1);
+ if (buf2)
{
- if ((ptr_buf[pos_buf] < 32)
- || !weechat_utf8_is_valid ((const char *)(ptr_buf + pos_buf),
- 1, NULL))
+ ptr_buf = (buf) ? (unsigned char *)buf : (unsigned char *)message;
+ pos_buf = 0;
+ pos_buf2 = 0;
+ while (ptr_buf[pos_buf])
{
- buf2[pos_buf2++] = '\\';
- buf2[pos_buf2++] = 'x';
- buf2[pos_buf2++] = hexa[ptr_buf[pos_buf] / 16];
- buf2[pos_buf2++] = hexa[ptr_buf[pos_buf] % 16];
- pos_buf++;
- }
- else
- {
- char_size = weechat_utf8_char_size ((const char *)(ptr_buf + pos_buf));
- for (i = 0; i < char_size; i++)
+ if ((ptr_buf[pos_buf] < 32)
+ || !weechat_utf8_is_valid ((const char *)(ptr_buf + pos_buf),
+ 1, NULL))
{
- buf2[pos_buf2++] = ptr_buf[pos_buf++];
+ buf2[pos_buf2++] = '\\';
+ buf2[pos_buf2++] = 'x';
+ buf2[pos_buf2++] = hexa[ptr_buf[pos_buf] / 16];
+ buf2[pos_buf2++] = hexa[ptr_buf[pos_buf] % 16];
+ pos_buf++;
+ }
+ else
+ {
+ char_size = weechat_utf8_char_size ((const char *)(ptr_buf + pos_buf));
+ for (i = 0; i < char_size; i++)
+ {
+ buf2[pos_buf2++] = ptr_buf[pos_buf++];
+ }
}
}
+ buf2[pos_buf2] = '\0';
}
- buf2[pos_buf2] = '\0';
- }
- /* build prefix with arrow */
- prefix_arrow[0] = '\0';
- switch (flags & (IRC_RAW_FLAG_RECV | IRC_RAW_FLAG_SEND
- | IRC_RAW_FLAG_MODIFIED | IRC_RAW_FLAG_REDIRECT))
- {
- case IRC_RAW_FLAG_RECV:
- strcpy (prefix_arrow, IRC_RAW_PREFIX_RECV);
- break;
- case IRC_RAW_FLAG_RECV | IRC_RAW_FLAG_MODIFIED:
- strcpy (prefix_arrow, IRC_RAW_PREFIX_RECV_MODIFIED);
- break;
- case IRC_RAW_FLAG_RECV | IRC_RAW_FLAG_REDIRECT:
- strcpy (prefix_arrow, IRC_RAW_PREFIX_RECV_REDIRECT);
- break;
- case IRC_RAW_FLAG_SEND:
- strcpy (prefix_arrow, IRC_RAW_PREFIX_SEND);
- break;
- case IRC_RAW_FLAG_SEND | IRC_RAW_FLAG_MODIFIED:
- strcpy (prefix_arrow, IRC_RAW_PREFIX_SEND_MODIFIED);
- break;
- default:
- if (flags & IRC_RAW_FLAG_RECV)
+ /* build prefix with arrow */
+ prefix_arrow[0] = '\0';
+ switch (flags & (IRC_RAW_FLAG_RECV | IRC_RAW_FLAG_SEND
+ | IRC_RAW_FLAG_MODIFIED | IRC_RAW_FLAG_REDIRECT))
+ {
+ case IRC_RAW_FLAG_RECV:
strcpy (prefix_arrow, IRC_RAW_PREFIX_RECV);
- else
+ break;
+ case IRC_RAW_FLAG_RECV | IRC_RAW_FLAG_MODIFIED:
+ strcpy (prefix_arrow, IRC_RAW_PREFIX_RECV_MODIFIED);
+ break;
+ case IRC_RAW_FLAG_RECV | IRC_RAW_FLAG_REDIRECT:
+ strcpy (prefix_arrow, IRC_RAW_PREFIX_RECV_REDIRECT);
+ break;
+ case IRC_RAW_FLAG_SEND:
strcpy (prefix_arrow, IRC_RAW_PREFIX_SEND);
- break;
- }
+ break;
+ case IRC_RAW_FLAG_SEND | IRC_RAW_FLAG_MODIFIED:
+ strcpy (prefix_arrow, IRC_RAW_PREFIX_SEND_MODIFIED);
+ break;
+ default:
+ if (flags & IRC_RAW_FLAG_RECV)
+ strcpy (prefix_arrow, IRC_RAW_PREFIX_RECV);
+ else
+ strcpy (prefix_arrow, IRC_RAW_PREFIX_SEND);
+ break;
+ }
- snprintf (prefix, sizeof (prefix), "%s%s%s%s%s",
- (server) ? weechat_color ("chat_server") : "",
- (server) ? server->name : "",
- (server) ? " " : "",
- (flags & IRC_RAW_FLAG_SEND) ?
- weechat_color ("chat_prefix_quit") :
- weechat_color ("chat_prefix_join"),
- prefix_arrow);
+ snprintf (prefix, sizeof (prefix), "%s%s%s%s%s",
+ (server) ? weechat_color ("chat_server") : "",
+ (server) ? server->name : "",
+ (server) ? " " : "",
+ (flags & IRC_RAW_FLAG_SEND) ?
+ weechat_color ("chat_prefix_quit") :
+ weechat_color ("chat_prefix_join"),
+ prefix_arrow);
+ }
new_raw_message = irc_raw_message_add_to_list (time (NULL),
prefix,
@@ -334,6 +346,20 @@ irc_raw_print (struct t_irc_server *server, int flags,
if (weechat_config_integer (irc_config_look_raw_messages) == 0)
irc_raw_message_free (new_raw_message);
}
+
+ if (weechat_irc_plugin->debug >= 2)
+ {
+ new_raw_message = irc_raw_message_add (server,
+ flags | IRC_RAW_FLAG_BINARY,
+ message);
+ if (new_raw_message)
+ {
+ if (irc_raw_buffer)
+ irc_raw_message_print (new_raw_message);
+ if (weechat_config_integer (irc_config_look_raw_messages) == 0)
+ irc_raw_message_free (new_raw_message);
+ }
+ }
}
/*
diff --git a/src/plugins/irc/irc-raw.h b/src/plugins/irc/irc-raw.h
index 0dc25d0ba..82fc529b0 100644
--- a/src/plugins/irc/irc-raw.h
+++ b/src/plugins/irc/irc-raw.h
@@ -32,6 +32,7 @@
#define IRC_RAW_FLAG_SEND 2
#define IRC_RAW_FLAG_MODIFIED 4
#define IRC_RAW_FLAG_REDIRECT 8
+#define IRC_RAW_FLAG_BINARY 16
struct t_irc_raw_message
{