Add missing charset decoding/encoding for IRC DCC chat (bug #27482)

This commit is contained in:
Sebastien Helleu 2009-09-20 10:29:25 +02:00
parent d4c62d0dba
commit 6fb5084af5
6 changed files with 57 additions and 22 deletions

View File

@ -1,7 +1,7 @@
WeeChat ChangeLog
=================
FlashCode <flashcode@flashtux.org>
v0.3.1-dev, 2009-09-19
v0.3.1-dev, 2009-09-20
Version 0.3.1 (under dev!)
@ -13,6 +13,7 @@ Version 0.3.1 (under dev!)
* irc: add options for CTCP, to block/customize CTCP reply (task #9693)
* irc: add missing CTCP: clientinfo, finger, source, time, userinfo (task #7270)
* irc: improve error management on socket error (recv/send)
* xfer: add missing charset decoding/encoding for IRC DCC chat (bug #27482)
* gui: update hotlist when a buffer is closed (bug #27470)
* gui: fix /input history_global_next: reset input content when last command in
history is reached

View File

@ -845,7 +845,7 @@ irc_command_dcc (void *data, struct t_gui_buffer *buffer, int argc,
unsigned long address;
struct t_infolist *infolist;
struct t_infolist_item *item;
char plugin_id[128], str_address[128];
char plugin_id[128], str_address[128], charset_modifier[256];
IRC_GET_SERVER_CHANNEL(buffer);
IRC_COMMAND_CHECK_SERVER("dcc", 1);
@ -915,6 +915,9 @@ irc_command_dcc (void *data, struct t_gui_buffer *buffer, int argc,
weechat_infolist_new_var_string (item, "type", "chat_send");
weechat_infolist_new_var_string (item, "remote_nick", argv[2]);
weechat_infolist_new_var_string (item, "local_nick", ptr_server->nick);
snprintf (charset_modifier, sizeof (charset_modifier),
"irc.%s.%s", ptr_server->name, argv[2]);
weechat_infolist_new_var_string (item, "charset_modifier", charset_modifier);
snprintf (str_address, sizeof (str_address),
"%lu", address);
weechat_infolist_new_var_string (item, "address", str_address);

View File

@ -368,7 +368,7 @@ irc_ctcp_recv_dcc (struct t_irc_server *server, const char *nick,
char *dcc_args, *pos, *pos_file, *pos_addr, *pos_port, *pos_size, *pos_start_resume;
struct t_infolist *infolist;
struct t_infolist_item *item;
char plugin_id[128];
char plugin_id[128], charset_modifier[256];
if (!arguments || !arguments[0])
return;
@ -768,6 +768,9 @@ irc_ctcp_recv_dcc (struct t_irc_server *server, const char *nick,
weechat_infolist_new_var_string (item, "type", "chat_recv");
weechat_infolist_new_var_string (item, "remote_nick", nick);
weechat_infolist_new_var_string (item, "local_nick", server->nick);
snprintf (charset_modifier, sizeof (charset_modifier),
"irc.%s.%s", server->name, nick);
weechat_infolist_new_var_string (item, "charset_modifier", charset_modifier);
weechat_infolist_new_var_string (item, "proxy",
IRC_SERVER_OPTION_STRING(server, IRC_SERVER_OPTION_PROXY));
weechat_infolist_new_var_string (item, "address", pos_addr);

View File

@ -55,6 +55,7 @@ xfer_chat_sendf (struct t_xfer *xfer, const char *format, ...)
va_list args;
static char buffer[4096];
int size_buf;
char *ptr_msg, *msg_encoded;
if (!xfer || (xfer->sock < 0))
return;
@ -62,15 +63,18 @@ xfer_chat_sendf (struct t_xfer *xfer, const char *format, ...)
va_start (args, format);
size_buf = vsnprintf (buffer, sizeof (buffer) - 1, format, args);
va_end (args);
if (size_buf == 0)
return;
buffer[sizeof (buffer) - 1] = '\0';
if ((size_buf < 0) || (size_buf > (int) (sizeof (buffer) - 1)))
size_buf = strlen (buffer);
if (xfer_chat_send (xfer, buffer, strlen (buffer)) <= 0)
msg_encoded = (xfer->charset_modifier) ?
weechat_hook_modifier_exec ("charset_encode",
xfer->charset_modifier,
buffer) : NULL;
ptr_msg = (msg_encoded) ? msg_encoded : buffer;
if (xfer_chat_send (xfer, ptr_msg, strlen (ptr_msg)) <= 0)
{
weechat_printf (NULL,
_("%s%s: error sending data to \"%s\" via xfer chat"),
@ -78,6 +82,9 @@ xfer_chat_sendf (struct t_xfer *xfer, const char *format, ...)
xfer->remote_nick);
xfer_close (xfer, XFER_STATUS_FAILED);
}
if (msg_encoded)
free (msg_encoded);
}
/*
@ -90,7 +97,7 @@ xfer_chat_recv_cb (void *arg_xfer, int fd)
struct t_xfer *xfer;
static char buffer[4096 + 2];
char *buf2, *pos, *ptr_buf, *next_ptr_buf;
char *ptr_buf_without_weechat_colors, *ptr_buf_color;
char *ptr_buf_decoded, *ptr_buf_without_weechat_colors, *ptr_buf_color;
int num_read;
/* make C compiler happy */
@ -137,15 +144,23 @@ xfer_chat_recv_cb (void *arg_xfer, int fd)
if (ptr_buf)
{
ptr_buf_without_weechat_colors = weechat_string_remove_color (ptr_buf, "?");
ptr_buf_decoded = (xfer->charset_modifier) ?
weechat_hook_modifier_exec ("charset_decode",
xfer->charset_modifier,
ptr_buf) : NULL;
ptr_buf_without_weechat_colors = weechat_string_remove_color ((ptr_buf_decoded) ? ptr_buf_decoded : ptr_buf,
"?");
ptr_buf_color = weechat_hook_modifier_exec ("irc_color_decode",
"1",
(ptr_buf_without_weechat_colors) ?
ptr_buf_without_weechat_colors : ptr_buf);
ptr_buf_without_weechat_colors : ((ptr_buf_decoded) ? ptr_buf_decoded : ptr_buf));
weechat_printf_tags (xfer->buffer, "notify_message", "%s\t%s",
xfer->remote_nick,
(ptr_buf_color) ?
ptr_buf_color : ((ptr_buf_without_weechat_colors) ? ptr_buf_without_weechat_colors : ptr_buf));
ptr_buf_color : ((ptr_buf_without_weechat_colors) ?
ptr_buf_without_weechat_colors : ((ptr_buf_decoded) ? ptr_buf_decoded : ptr_buf)));
if (ptr_buf_decoded)
free (ptr_buf_decoded);
if (ptr_buf_without_weechat_colors)
free (ptr_buf_without_weechat_colors);
if (ptr_buf_color)

View File

@ -388,6 +388,8 @@ xfer_send_signal (struct t_xfer *xfer, const char *signal)
xfer->remote_nick);
weechat_infolist_new_var_string (item, "local_nick",
xfer->local_nick);
weechat_infolist_new_var_string (item, "charset_modifier",
xfer->charset_modifier);
weechat_infolist_new_var_string (item, "filename",
xfer->filename);
snprintf (str_long, sizeof (str_long), "%lu", xfer->size);
@ -432,6 +434,7 @@ xfer_alloc ()
new_xfer->port = 0;
new_xfer->remote_nick = NULL;
new_xfer->local_nick = NULL;
new_xfer->charset_modifier = NULL;
new_xfer->type = 0;
new_xfer->protocol = 0;
@ -478,9 +481,10 @@ xfer_alloc ()
*/
struct t_xfer *
xfer_new (const char *plugin_name, const char *plugin_id, enum t_xfer_type type,
enum t_xfer_protocol protocol, const char *remote_nick,
const char *local_nick, const char *filename,
xfer_new (const char *plugin_name, const char *plugin_id,
enum t_xfer_type type, enum t_xfer_protocol protocol,
const char *remote_nick, const char *local_nick,
const char *charset_modifier, const char *filename,
unsigned long size, const char *proxy, unsigned long address,
int port, int sock, const char *local_filename)
{
@ -508,6 +512,7 @@ xfer_new (const char *plugin_name, const char *plugin_id, enum t_xfer_type type,
new_xfer->protocol = protocol;
new_xfer->remote_nick = strdup (remote_nick);
new_xfer->local_nick = (local_nick) ? strdup (local_nick) : NULL;
new_xfer->charset_modifier = (charset_modifier) ? strdup (charset_modifier) : NULL;
if (XFER_IS_FILE(type))
new_xfer->filename = (filename) ? strdup (filename) : NULL;
else
@ -653,6 +658,8 @@ xfer_free (struct t_xfer *xfer)
free (xfer->remote_nick);
if (xfer->local_nick)
free (xfer->local_nick);
if (xfer->charset_modifier)
free (xfer->charset_modifier);
if (xfer->filename)
free (xfer->filename);
if (xfer->unterminated_message)
@ -674,11 +681,12 @@ xfer_free (struct t_xfer *xfer)
*/
int
xfer_add_cb (void *data, const char *signal, const char *type_data, void *signal_data)
xfer_add_cb (void *data, const char *signal, const char *type_data,
void *signal_data)
{
struct t_infolist *infolist;
const char *plugin_name, *plugin_id, *str_type, *str_protocol;
const char *remote_nick, *local_nick, *filename, *proxy;
const char *remote_nick, *local_nick, *charset_modifier, *filename, *proxy;
int type, protocol;
const char *weechat_dir;
char *dir1, *dir2, *filename2, *short_filename, *pos;
@ -728,6 +736,7 @@ xfer_add_cb (void *data, const char *signal, const char *type_data, void *signal
str_protocol = weechat_infolist_string (infolist, "protocol");
remote_nick = weechat_infolist_string (infolist, "remote_nick");
local_nick = weechat_infolist_string (infolist, "local_nick");
charset_modifier = weechat_infolist_string (infolist, "charset_modifier");
filename = weechat_infolist_string (infolist, "filename");
proxy = weechat_infolist_string (infolist, "proxy");
protocol = XFER_NO_PROTOCOL;
@ -999,13 +1008,13 @@ xfer_add_cb (void *data, const char *signal, const char *type_data, void *signal
/* add xfer entry and listen to socket if type is file or chat "send" */
if (XFER_IS_FILE(type))
ptr_xfer = xfer_new (plugin_name, plugin_id, type, protocol,
remote_nick, local_nick, short_filename,
file_size, proxy, local_addr, port, sock,
filename2);
remote_nick, local_nick, charset_modifier,
short_filename, file_size, proxy, local_addr,
port, sock, filename2);
else
ptr_xfer = xfer_new (plugin_name, plugin_id, type, protocol,
remote_nick, local_nick, NULL, 0, proxy,
local_addr, port, sock, NULL);
remote_nick, local_nick, charset_modifier, NULL,
0, proxy, local_addr, port, sock, NULL);
if (!ptr_xfer)
{
@ -1233,6 +1242,8 @@ xfer_add_to_infolist (struct t_infolist *infolist, struct t_xfer *xfer)
return 0;
if (!weechat_infolist_new_var_string (ptr_item, "local_nick", xfer->local_nick))
return 0;
if (!weechat_infolist_new_var_string (ptr_item, "charset_modifier", xfer->charset_modifier))
return 0;
if (!weechat_infolist_new_var_string (ptr_item, "filename", xfer->filename))
return 0;
snprintf (value, sizeof (value), "%lu", xfer->size);
@ -1329,6 +1340,7 @@ xfer_print_log ()
xfer_protocol_string[ptr_xfer->protocol]);
weechat_log_printf (" remote_nick . . . . : '%s'", ptr_xfer->remote_nick);
weechat_log_printf (" local_nick. . . . . : '%s'", ptr_xfer->local_nick);
weechat_log_printf (" charset_modifier. . : '%s'", ptr_xfer->charset_modifier);
weechat_log_printf (" filename. . . . . . : '%s'", ptr_xfer->filename);
weechat_log_printf (" size. . . . . . . . : %lu", ptr_xfer->size);
weechat_log_printf (" proxy . . . . . . . : '%s'", ptr_xfer->proxy);

View File

@ -113,6 +113,7 @@ struct t_xfer
enum t_xfer_protocol protocol; /* xfer protocol (for file transfer) */
char *remote_nick; /* remote nick */
char *local_nick; /* local nick */
char *charset_modifier; /* string for charset modifier_data */
char *filename; /* filename */
unsigned long size; /* file size */
char *proxy; /* proxy to use (optional) */