diff options
Diffstat (limited to 'src/plugins/irc/irc-raw.c')
-rw-r--r-- | src/plugins/irc/irc-raw.c | 145 |
1 files changed, 87 insertions, 58 deletions
diff --git a/src/plugins/irc/irc-raw.c b/src/plugins/irc/irc-raw.c index 598e2abee..fb560eea6 100644 --- a/src/plugins/irc/irc-raw.c +++ b/src/plugins/irc/irc-raw.c @@ -1,7 +1,7 @@ /* * irc-raw.c - functions for IRC raw data messages * - * Copyright (C) 2003-2015 Sébastien Helleu <flashcode@flashtux.org> + * Copyright (C) 2003-2016 Sébastien Helleu <flashcode@flashtux.org> * * This file is part of WeeChat, the extensible chat client. * @@ -72,9 +72,10 @@ irc_raw_open (int switch_to_buffer) IRC_RAW_BUFFER_NAME); if (!irc_raw_buffer) { - irc_raw_buffer = weechat_buffer_new (IRC_RAW_BUFFER_NAME, - &irc_input_data_cb, NULL, - &irc_buffer_close_cb, NULL); + irc_raw_buffer = weechat_buffer_new ( + IRC_RAW_BUFFER_NAME, + &irc_input_data_cb, NULL, NULL, + &irc_buffer_close_cb, NULL, NULL); /* failed to create buffer ? then return */ if (!irc_raw_buffer) @@ -229,71 +230,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) + 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", + (flags & IRC_RAW_FLAG_SEND) ? + weechat_color ("chat_prefix_quit") : + weechat_color ("chat_prefix_join"), + prefix_arrow, + (server) ? weechat_color ("chat_server") : "", + (server) ? " " : "", + (server) ? server->name : ""); + } new_raw_message = irc_raw_message_add_to_list (time (NULL), prefix, @@ -332,6 +347,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); + } + } } /* |