diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/common/command.c | 513 | ||||
-rw-r--r-- | src/common/command.h | 47 | ||||
-rw-r--r-- | src/common/completion.c | 98 | ||||
-rw-r--r-- | src/common/completion.h | 2 | ||||
-rw-r--r-- | src/common/fifo.c | 3 | ||||
-rw-r--r-- | src/common/session.c | 12 | ||||
-rw-r--r-- | src/common/session.h | 5 | ||||
-rw-r--r-- | src/common/weechat.c | 7 | ||||
-rw-r--r-- | src/common/weechat.h | 2 | ||||
-rw-r--r-- | src/common/weeconfig.c | 159 | ||||
-rw-r--r-- | src/common/weeconfig.h | 3 | ||||
-rw-r--r-- | src/gui/curses/gui-display.c | 34 | ||||
-rw-r--r-- | src/gui/gui-action.c | 5 | ||||
-rw-r--r-- | src/gui/gui-common.c | 41 | ||||
-rw-r--r-- | src/gui/gui-keyboard.c | 4 | ||||
-rw-r--r-- | src/gui/gui.h | 1 | ||||
-rw-r--r-- | src/irc/irc-channel.c | 220 | ||||
-rw-r--r-- | src/irc/irc-dcc.c | 21 | ||||
-rw-r--r-- | src/irc/irc-display.c | 39 | ||||
-rw-r--r-- | src/irc/irc-recv.c | 8 | ||||
-rw-r--r-- | src/irc/irc-server.c | 121 | ||||
-rw-r--r-- | src/irc/irc.h | 26 | ||||
-rw-r--r-- | src/plugins/plugins-interface.c | 9 |
23 files changed, 1026 insertions, 354 deletions
diff --git a/src/common/command.c b/src/common/command.c index 50dc1349b..5e395dfe1 100644 --- a/src/common/command.c +++ b/src/common/command.c @@ -57,6 +57,12 @@ t_weechat_command weechat_commands[] = "server,channel: jump to buffer by server and/or channel name\n" "number: jump to buffer by number"), 0, MAX_ARGS, weechat_cmd_buffer, NULL }, + { "charset", N_("change charset for server or channel"), + N_("[(decode_iso | decode_utf | encode) charset]"), + N_("decode_iso: charset used for decoding ISO\n" + "decode_utf: charset used for decoding UTF\n" + " encode: charset used for encoding messages"), + 0, 2, weechat_cmd_charset, NULL }, { "clear", N_("clear window(s)"), N_("[-all]"), N_("-all: clear all windows"), @@ -500,7 +506,7 @@ free_exploded_string (char **exploded_string) */ int -exec_weechat_command (t_irc_server *server, char *string) +exec_weechat_command (t_gui_window *window, t_irc_server *server, char *string) { int i, argc, return_code, length1, length2; char *command, *pos, *ptr_args, *ptr_args_color, **argv, *alias_command; @@ -589,10 +595,10 @@ exec_weechat_command (t_irc_server *server, char *string) { if (weechat_commands[i].cmd_function_args) return_code = (int) (weechat_commands[i].cmd_function_args) - (argc, argv); + (window, argc, argv); else return_code = (int) (weechat_commands[i].cmd_function_1arg) - (ptr_args); + (window, ptr_args); if (return_code < 0) { irc_display_prefix (NULL, NULL, PREFIX_ERROR); @@ -693,12 +699,13 @@ exec_weechat_command (t_irc_server *server, char *string) alias_command[length1] = ' '; strcpy (alias_command + length1 + 1, ptr_args); } - (void) exec_weechat_command (server, alias_command); + (void) exec_weechat_command (window, server, alias_command); if (alias_command) free (alias_command); } else - (void) exec_weechat_command (server, ptr_alias->alias_command); + (void) exec_weechat_command (window, server, + ptr_alias->alias_command); free_exploded_string (argv); free (command); @@ -726,7 +733,7 @@ exec_weechat_command (t_irc_server *server, char *string) */ void -user_command (t_irc_server *server, t_gui_buffer *buffer, char *command) +user_command (t_gui_window *window, t_irc_server *server, char *command) { t_irc_nick *ptr_nick; int plugin_args_length; @@ -738,44 +745,44 @@ user_command (t_irc_server *server, t_gui_buffer *buffer, char *command) if ((command[0] == '/') && (command[1] != '/')) { /* WeeChat internal command (or IRC command) */ - (void) exec_weechat_command (server, command); + (void) exec_weechat_command (window, server, command); } else { - if (!buffer) - buffer = gui_current_window->buffer; + if (!window) + window = gui_current_window; if ((command[0] == '/') && (command[1] == '/')) command++; - if (server && (!BUFFER_IS_SERVER(buffer))) + if (server && (!BUFFER_IS_SERVER(window->buffer))) { command_with_colors = (cfg_irc_colors_send) ? (char *)gui_color_encode ((unsigned char *)command) : NULL; - if (CHANNEL(buffer)->dcc_chat) - dcc_chat_sendf ((t_irc_dcc *)(CHANNEL(buffer)->dcc_chat), + if (CHANNEL(window->buffer)->dcc_chat) + dcc_chat_sendf ((t_irc_dcc *)(CHANNEL(window->buffer)->dcc_chat), "%s\r\n", (command_with_colors) ? command_with_colors : command); else server_sendf (server, "PRIVMSG %s :%s\r\n", - CHANNEL(buffer)->name, + CHANNEL(window->buffer)->name, (command_with_colors) ? command_with_colors : command); command_with_colors2 = (command_with_colors) ? (char *)gui_color_decode ((unsigned char *)command_with_colors, 1) : NULL; - if (CHANNEL(buffer)->type == CHANNEL_TYPE_PRIVATE) + if (CHANNEL(window->buffer)->type == CHANNEL_TYPE_PRIVATE) { - gui_printf_type (CHANNEL(buffer)->buffer, + gui_printf_type (window->buffer, MSG_TYPE_NICK, "%s<%s%s%s> ", GUI_COLOR(COLOR_WIN_CHAT_DARK), GUI_COLOR(COLOR_WIN_NICK_SELF), server->nick, GUI_COLOR(COLOR_WIN_CHAT_DARK)); - gui_printf_type (CHANNEL(buffer)->buffer, + gui_printf_type (window->buffer, MSG_TYPE_MSG, "%s%s\n", GUI_COLOR(COLOR_WIN_CHAT), @@ -784,12 +791,12 @@ user_command (t_irc_server *server, t_gui_buffer *buffer, char *command) } else { - ptr_nick = nick_search (CHANNEL(buffer), server->nick); + ptr_nick = nick_search (CHANNEL(window->buffer), server->nick); if (ptr_nick) { - irc_display_nick (CHANNEL(buffer)->buffer, ptr_nick, NULL, + irc_display_nick (CHANNEL(window->buffer)->buffer, ptr_nick, NULL, MSG_TYPE_NICK, 1, 1, 0); - gui_printf (CHANNEL(buffer)->buffer, + gui_printf (CHANNEL(window->buffer)->buffer, "%s\n", (command_with_colors2) ? command_with_colors2 : command); @@ -853,11 +860,14 @@ user_command (t_irc_server *server, t_gui_buffer *buffer, char *command) */ int -weechat_cmd_alias (char *arguments) +weechat_cmd_alias (t_gui_window *window, char *arguments) { char *pos; t_weechat_alias *ptr_alias; + /* make gcc happy */ + (void) window; + if (arguments && arguments[0]) { /* Define new alias */ @@ -982,7 +992,7 @@ weechat_cmd_buffer_display_info (t_gui_buffer *buffer) */ int -weechat_cmd_buffer (int argc, char **argv) +weechat_cmd_buffer (t_gui_window *window, int argc, char **argv) { t_gui_buffer *ptr_buffer; t_irc_server *ptr_server; @@ -1028,13 +1038,13 @@ weechat_cmd_buffer (int argc, char **argv) if ((error) && (error[0] == '\0')) { if (argv[1][0] == '+') - gui_buffer_move_to_number (gui_current_window, - gui_current_window->buffer->number + ((int) number)); + gui_buffer_move_to_number (window, + window->buffer->number + ((int) number)); else if (argv[1][0] == '-') - gui_buffer_move_to_number (gui_current_window, - gui_current_window->buffer->number - ((int) number)); + gui_buffer_move_to_number (window, + window->buffer->number - ((int) number)); else - gui_buffer_move_to_number (gui_current_window, (int) number); + gui_buffer_move_to_number (window, (int) number); } else { @@ -1049,10 +1059,10 @@ weechat_cmd_buffer (int argc, char **argv) { /* close buffer (server or channel/private) */ - if ((!gui_current_window->buffer->next_buffer) - && (gui_current_window->buffer == gui_buffers) - && ((!gui_current_window->buffer->all_servers) - || (!SERVER(gui_current_window->buffer)))) + if ((!window->buffer->next_buffer) + && (window->buffer == gui_buffers) + && ((!window->buffer->all_servers) + || (!SERVER(window->buffer)))) { irc_display_prefix (NULL, NULL, PREFIX_ERROR); gui_printf (NULL, @@ -1060,9 +1070,9 @@ weechat_cmd_buffer (int argc, char **argv) WEECHAT_ERROR); return -1; } - if (BUFFER_IS_SERVER(gui_current_window->buffer)) + if (BUFFER_IS_SERVER(window->buffer)) { - if (SERVER(gui_current_window->buffer)->channels) + if (SERVER(window->buffer)->channels) { irc_display_prefix (NULL, NULL, PREFIX_ERROR); gui_printf (NULL, @@ -1071,43 +1081,43 @@ weechat_cmd_buffer (int argc, char **argv) WEECHAT_ERROR); return -1; } - server_disconnect (SERVER(gui_current_window->buffer), 0); - ptr_server = SERVER(gui_current_window->buffer); - if (!gui_current_window->buffer->all_servers) + server_disconnect (SERVER(window->buffer), 0); + ptr_server = SERVER(window->buffer); + if (!window->buffer->all_servers) { - gui_buffer_free (gui_current_window->buffer, 1); + gui_buffer_free (window->buffer, 1); ptr_server->buffer = NULL; } else { ptr_server->buffer = NULL; - gui_current_window->buffer->server = NULL; - gui_window_switch_server (gui_current_window); + window->buffer->server = NULL; + gui_window_switch_server (window); } } else { - if (SERVER(gui_current_window->buffer)) + if (SERVER(window->buffer)) { - if (SERVER(gui_current_window->buffer)->is_connected - && CHANNEL(gui_current_window->buffer) - && CHANNEL(gui_current_window->buffer)->nicks) - irc_cmd_send_part (SERVER(gui_current_window->buffer), NULL); + if (SERVER(window->buffer)->is_connected + && CHANNEL(window->buffer) + && CHANNEL(window->buffer)->nicks) + irc_cmd_send_part (SERVER(window->buffer), NULL); else { - ptr_channel = channel_search (SERVER(gui_current_window->buffer), - CHANNEL(gui_current_window->buffer)->name); + ptr_channel = channel_search (SERVER(window->buffer), + CHANNEL(window->buffer)->name); if (ptr_channel) - channel_free (SERVER(gui_current_window->buffer), + channel_free (SERVER(window->buffer), ptr_channel); - gui_buffer_free (gui_current_window->buffer, 1); + gui_buffer_free (window->buffer, 1); } } else - gui_buffer_free (gui_current_window->buffer, 1); + gui_buffer_free (window->buffer, 1); } - gui_draw_buffer_status (gui_current_window->buffer, 1); + gui_draw_buffer_status (window->buffer, 1); } else if (ascii_strcasecmp (argv[0], "notify") == 0) { @@ -1148,8 +1158,8 @@ weechat_cmd_buffer (int argc, char **argv) WEECHAT_ERROR, NOTIFY_LEVEL_MIN, NOTIFY_LEVEL_MAX); return -1; } - if ((!BUFFER_IS_CHANNEL(gui_current_window->buffer)) - && (!BUFFER_IS_PRIVATE(gui_current_window->buffer))) + if ((!BUFFER_IS_CHANNEL(window->buffer)) + && (!BUFFER_IS_PRIVATE(window->buffer))) { /* invalid buffer type (only ok on channel or private) */ irc_display_prefix (NULL, NULL, PREFIX_ERROR); @@ -1157,14 +1167,14 @@ weechat_cmd_buffer (int argc, char **argv) WEECHAT_ERROR); return -1; } - gui_current_window->buffer->notify_level = number; - channel_set_notify_level (SERVER(gui_current_window->buffer), - CHANNEL(gui_current_window->buffer), + window->buffer->notify_level = number; + channel_set_notify_level (SERVER(window->buffer), + CHANNEL(window->buffer), number); irc_display_prefix (NULL, NULL, PREFIX_INFO); gui_printf (NULL, _("New notify level for %s%s%s: %s%d %s"), GUI_COLOR(COLOR_WIN_CHAT_CHANNEL), - CHANNEL(gui_current_window->buffer)->name, + CHANNEL(window->buffer)->name, GUI_COLOR(COLOR_WIN_CHAT), GUI_COLOR(COLOR_WIN_CHAT_CHANNEL), number, @@ -1209,11 +1219,11 @@ weechat_cmd_buffer (int argc, char **argv) number = strtol (argv[0] + 1, &error, 10); if ((error) && (error[0] == '\0')) { - target_buffer = gui_current_window->buffer->number - (int) number; + target_buffer = window->buffer->number - (int) number; if (target_buffer < 1) target_buffer = (last_gui_buffer) ? last_gui_buffer->number + target_buffer : 1; - gui_buffer_switch_by_number (gui_current_window, + gui_buffer_switch_by_number (window, target_buffer); } } @@ -1224,10 +1234,10 @@ weechat_cmd_buffer (int argc, char **argv) number = strtol (argv[0] + 1, &error, 10); if ((error) && (error[0] == '\0')) { - target_buffer = gui_current_window->buffer->number + (int) number; + target_buffer = window->buffer->number + (int) number; if (last_gui_buffer && target_buffer > last_gui_buffer->number) target_buffer -= last_gui_buffer->number; - gui_buffer_switch_by_number (gui_current_window, + gui_buffer_switch_by_number (window, target_buffer); } } @@ -1237,7 +1247,7 @@ weechat_cmd_buffer (int argc, char **argv) error = NULL; number = strtol (argv[0], &error, 10); if ((error) && (error[0] == '\0')) - gui_buffer_switch_by_number (gui_current_window, (int) number); + gui_buffer_switch_by_number (window, (int) number); else { ptr_buffer = NULL; @@ -1252,7 +1262,7 @@ weechat_cmd_buffer (int argc, char **argv) } if (ptr_buffer) { - gui_switch_to_buffer (gui_current_window, ptr_buffer); + gui_switch_to_buffer (window, ptr_buffer); gui_redraw_buffer (ptr_buffer); } } @@ -1264,11 +1274,204 @@ weechat_cmd_buffer (int argc, char **argv) } /* + * weechat_cmd_charset_display: display charsets for current server or channel + */ + +void +weechat_cmd_charset_display (t_gui_window *window) +{ + char *server_item = "server", *ptr_item; + char *value, *string, *herited; + int length; + + if (BUFFER_IS_SERVER(window->buffer) || + BUFFER_IS_CHANNEL(window->buffer) || + BUFFER_IS_PRIVATE(window->buffer)) + { + if (BUFFER_IS_SERVER(window->buffer)) + { + gui_printf_nolog (NULL, _("Charsets for server %s%s%s: "), + GUI_COLOR(COLOR_WIN_CHAT_SERVER), + SERVER(window->buffer)->name, + GUI_COLOR(COLOR_WIN_CHAT)); + ptr_item = server_item; + } + else if (BUFFER_IS_CHANNEL(window->buffer)) + { + gui_printf_nolog (NULL, _("Charsets for channel %s%s%s: "), + GUI_COLOR(COLOR_WIN_CHAT_CHANNEL), + CHANNEL(window->buffer)->name, + GUI_COLOR(COLOR_WIN_CHAT)); + ptr_item = CHANNEL(window->buffer)->name; + } + else + { + gui_printf_nolog (NULL, _("Charsets for private %s%s%s: "), + GUI_COLOR(COLOR_WIN_CHAT_CHANNEL), + CHANNEL(window->buffer)->name, + GUI_COLOR(COLOR_WIN_CHAT)); + ptr_item = CHANNEL(window->buffer)->name; + } + + /* decode ISO */ + herited = NULL; + config_option_list_get_value (&(SERVER(window->buffer)->charset_decode_iso), + ptr_item, &value, &length); + if (value && (length > 0)) + { + string = strdup (value); + string[length] = '\0'; + } + else + { + string = strdup (""); + herited = channel_get_charset_decode_iso (SERVER(window->buffer), + CHANNEL(window->buffer)); + } + gui_printf (NULL, "decode_iso: \"%s%s%s\"", + GUI_COLOR(COLOR_WIN_CHAT_HOST), + string, + GUI_COLOR(COLOR_WIN_CHAT)); + if (herited) + { + gui_printf (NULL, _(" (inherited: \"%s%s%s\")"), + GUI_COLOR(COLOR_WIN_CHAT_HOST), + herited, + GUI_COLOR(COLOR_WIN_CHAT)); + free (herited); + } + gui_printf (NULL, ", "); + free (string); + + /* decode UTF */ + herited = NULL; + config_option_list_get_value (&(SERVER(window->buffer)->charset_decode_utf), + ptr_item, &value, &length); + if (value && (length > 0)) + { + string = strdup (value); + string[length] = '\0'; + } + else + { + string = strdup (""); + herited = channel_get_charset_decode_utf (SERVER(window->buffer), + CHANNEL(window->buffer)); + } + gui_printf (NULL, "decode_utf: \"%s%s%s\"", + GUI_COLOR(COLOR_WIN_CHAT_HOST), + string, + GUI_COLOR(COLOR_WIN_CHAT)); + if (herited) + { + gui_printf (NULL, _(" (inherited: \"%s%s%s\")"), + GUI_COLOR(COLOR_WIN_CHAT_HOST), + herited, + GUI_COLOR(COLOR_WIN_CHAT)); + free (herited); + } + gui_printf (NULL, ", "); + free (string); + + /* encode */ + herited = NULL; + config_option_list_get_value (&(SERVER(window->buffer)->charset_encode), + ptr_item, &value, &length); + if (value && (length > 0)) + { + string = strdup (value); + string[length] = '\0'; + } + else + { + string = strdup (""); + herited = channel_get_charset_encode (SERVER(window->buffer), + CHANNEL(window->buffer)); + } + gui_printf (NULL, "encode: \"%s%s%s\"", + GUI_COLOR(COLOR_WIN_CHAT_HOST), + string, + GUI_COLOR(COLOR_WIN_CHAT)); + if (herited) + { + gui_printf (NULL, _(" (inherited: \"%s%s%s\")"), + GUI_COLOR(COLOR_WIN_CHAT_HOST), + herited, + GUI_COLOR(COLOR_WIN_CHAT)); + free (herited); + } + gui_printf (NULL, "\n"); + free (string); + } +} + +/* + * weechat_cmd_charset_set: set a charset for server or channel + */ + +void +weechat_cmd_charset_set (t_gui_window *window, char **string, char *charset) +{ + if (BUFFER_IS_SERVER(window->buffer)) + { + if (charset) + config_option_list_set (string, "server", charset); + else + config_option_list_remove (string, "server"); + weechat_cmd_charset_display (window); + } + else if (BUFFER_IS_CHANNEL(window->buffer) || + BUFFER_IS_PRIVATE(window->buffer)) + { + if (charset) + config_option_list_set (string, CHANNEL(window->buffer)->name, charset); + else + config_option_list_remove (string, CHANNEL(window->buffer)->name); + weechat_cmd_charset_display (window); + } +} + +/* + * weechat_cmd_charset: change charset for server or channel + */ + +int +weechat_cmd_charset (t_gui_window *window, int argc, char **argv) +{ + if (argc == 0) + weechat_cmd_charset_display (window); + else + { + if (ascii_strcasecmp (argv[0], "decode_iso") == 0) + weechat_cmd_charset_set (window, + &(SERVER(window->buffer)->charset_decode_iso), + (argc > 1) ? argv[1] : NULL); + else if (ascii_strcasecmp (argv[0], "decode_utf") == 0) + weechat_cmd_charset_set (window, + &(SERVER(window->buffer)->charset_decode_utf), + (argc > 1) ? argv[1] : NULL); + else if (ascii_strcasecmp (argv[0], "encode") == 0) + weechat_cmd_charset_set (window, + &(SERVER(window->buffer)->charset_encode), + (argc > 1) ? argv[1] : NULL); + else + { + irc_display_prefix (NULL, NULL, PREFIX_ERROR); + gui_printf (NULL, + _("%s unknown option for \"%s\" command\n"), + WEECHAT_ERROR, "charset"); + return -1; + } + } + return 0; +} + +/* * weechat_cmd_clear: display or create alias */ int -weechat_cmd_clear (int argc, char **argv) +weechat_cmd_clear (t_gui_window *window, int argc, char **argv) { if (argc == 1) { @@ -1278,13 +1481,13 @@ weechat_cmd_clear (int argc, char **argv) { irc_display_prefix (NULL, NULL, PREFIX_ERROR); gui_printf (NULL, - _("unknown parameter \"%s\" for \"%s\" command\n"), - argv[0], "clear"); + _("%s unknown option for \"%s\" command\n"), + WEECHAT_ERROR, "clear"); return -1; } } else - gui_buffer_clear (gui_current_window->buffer); + gui_buffer_clear (window->buffer); return 0; } @@ -1293,14 +1496,14 @@ weechat_cmd_clear (int argc, char **argv) */ int -weechat_cmd_connect (int argc, char **argv) +weechat_cmd_connect (t_gui_window *window, int argc, char **argv) { t_irc_server *ptr_server; if (argc == 1) ptr_server = server_search (argv[0]); else - ptr_server = SERVER(gui_current_window->buffer); + ptr_server = SERVER(window->buffer); if (ptr_server) { @@ -1322,7 +1525,7 @@ weechat_cmd_connect (int argc, char **argv) } if (!ptr_server->buffer) { - if (!gui_buffer_new (gui_current_window, ptr_server, NULL, 0, 1)) + if (!gui_buffer_new (window, ptr_server, NULL, 0, 1)) return -1; } if (server_connect (ptr_server)) @@ -1384,8 +1587,11 @@ weechat_cmd_debug_display_windows (t_gui_window_tree *tree, int indent) */ int -weechat_cmd_debug (int argc, char **argv) +weechat_cmd_debug (t_gui_window *window, int argc, char **argv) { + /* make gcc happy */ + (void) window; + if (argc != 1) { irc_display_prefix (NULL, NULL, PREFIX_ERROR); @@ -1422,14 +1628,14 @@ weechat_cmd_debug (int argc, char **argv) */ int -weechat_cmd_disconnect (int argc, char **argv) +weechat_cmd_disconnect (t_gui_window *window, int argc, char **argv) { t_irc_server *ptr_server; if (argc == 1) ptr_server = server_search (argv[0]); else - ptr_server = SERVER(gui_current_window->buffer); + ptr_server = SERVER(window->buffer); if (ptr_server) { @@ -1449,7 +1655,7 @@ weechat_cmd_disconnect (int argc, char **argv) _("Auto-reconnection is cancelled\n")); } server_disconnect (ptr_server, 0); - gui_draw_buffer_status (gui_current_window->buffer, 1); + gui_draw_buffer_status (window->buffer, 1); } else { @@ -1465,14 +1671,17 @@ weechat_cmd_disconnect (int argc, char **argv) */ int -weechat_cmd_help (int argc, char **argv) +weechat_cmd_help (t_gui_window *window, int argc, char **argv) { int i; #ifdef PLUGINS t_weechat_plugin *ptr_plugin; t_plugin_handler *ptr_handler; #endif - + + /* make gcc happy */ + (void) window; + switch (argc) { case 0: @@ -1629,38 +1838,45 @@ weechat_cmd_help (int argc, char **argv) */ int -weechat_cmd_history (int argc, char **argv) { - - t_history *p; +weechat_cmd_history (t_gui_window *window, int argc, char **argv) +{ + t_history *ptr_history; int n; int n_total; - int n_user = cfg_history_display_default; - + int n_user; + + n_user = cfg_history_display_default; + if (argc == 1) { if (ascii_strcasecmp (argv[0], "clear") == 0) { - history_buffer_free (gui_current_window->buffer); + history_buffer_free (window->buffer); return 0; } else n_user = atoi (argv[0]); } - if (gui_current_window->buffer->history != NULL) + if (window->buffer->history != NULL) { - for(n_total = 1, p = gui_current_window->buffer->history; p->next_history != NULL; p = p->next_history, n_total++); - for(n=0; p != NULL; p=p->prev_history, n++) + n_total = 1; + for (ptr_history = window->buffer->history; + ptr_history->next_history; + ptr_history = ptr_history->next_history) + { + n_total++; + } + for (n = 0; ptr_history; ptr_history = ptr_history->prev_history) { - if (n_user > 0 && (n_total-n_user) > n) + if ((n_user > 0) && ((n_total - n_user) > n)) continue; - irc_display_prefix (NULL, gui_current_window->buffer, - PREFIX_INFO); - gui_printf_nolog (gui_current_window->buffer, - "%s\n", p->text); + irc_display_prefix (NULL, window->buffer, PREFIX_INFO); + gui_printf_nolog (window->buffer, "%s\n", ptr_history->text); + n++; } } - + return 0; } @@ -1697,7 +1913,7 @@ weechat_cmd_ignore_display (char *text, t_irc_ignore *ptr_ignore) */ int -weechat_cmd_ignore (int argc, char **argv) +weechat_cmd_ignore (t_gui_window *window, int argc, char **argv) { t_irc_ignore *ptr_ignore; int i; @@ -1733,18 +1949,18 @@ weechat_cmd_ignore (int argc, char **argv) break; case 1: ptr_ignore = ignore_add (argv[0], "*", "*", - (SERVER(gui_current_window->buffer)) ? - SERVER(gui_current_window->buffer)->name : "*"); + (SERVER(window->buffer)) ? + SERVER(window->buffer)->name : "*"); break; case 2: ptr_ignore = ignore_add (argv[0], argv[1], "*", - (SERVER(gui_current_window->buffer)) ? - SERVER(gui_current_window->buffer)->name : "*"); + (SERVER(window->buffer)) ? + SERVER(window->buffer)->name : "*"); break; case 3: ptr_ignore = ignore_add (argv[0], argv[1], argv[2], - (SERVER(gui_current_window->buffer)) ? - SERVER(gui_current_window->buffer)->name : "*"); + (SERVER(window->buffer)) ? + SERVER(window->buffer)->name : "*"); break; case 4: ptr_ignore = ignore_add (argv[0], argv[1], argv[2], argv[3]); @@ -1792,12 +2008,15 @@ weechat_cmd_key_display (t_gui_key *key, int new_key) */ int -weechat_cmd_key (char *arguments) +weechat_cmd_key (t_gui_window *window, char *arguments) { char *pos; int i; t_gui_key *ptr_key; + /* make gcc happy */ + (void) window; + if (arguments) { while (arguments[0] == ' ') @@ -1904,13 +2123,16 @@ weechat_cmd_key (char *arguments) */ int -weechat_cmd_plugin (int argc, char **argv) +weechat_cmd_plugin (t_gui_window *window, int argc, char **argv) { #ifdef PLUGINS t_weechat_plugin *ptr_plugin; t_plugin_handler *ptr_handler; int handler_found; + /* make gcc happy */ + (void) window; + switch (argc) { case 0: @@ -2032,8 +2254,11 @@ weechat_cmd_plugin (int argc, char **argv) */ int -weechat_cmd_save (int argc, char **argv) +weechat_cmd_save (t_gui_window *window, int argc, char **argv) { + /* make gcc happy */ + (void) window; + return (config_write ((argc == 1) ? argv[0] : NULL)); } @@ -2042,7 +2267,7 @@ weechat_cmd_save (int argc, char **argv) */ int -weechat_cmd_server (int argc, char **argv) +weechat_cmd_server (t_gui_window *window, int argc, char **argv) { int i; t_irc_server server, *ptr_server, *server_found, *new_server; @@ -2150,7 +2375,7 @@ weechat_cmd_server (int argc, char **argv) if (server_name) free (server_name); - gui_redraw_buffer (gui_current_window->buffer); + gui_redraw_buffer (window->buffer); return 0; } @@ -2286,7 +2511,8 @@ weechat_cmd_server (int argc, char **argv) server.ssl, server.password, server.nick1, server.nick2, server.nick3, server.username, server.realname, - server.command, 1, server.autojoin, 1, NULL); + server.command, 1, server.autojoin, 1, NULL, + NULL, NULL, NULL); if (new_server) { irc_display_prefix (NULL, NULL, PREFIX_INFO); @@ -2307,7 +2533,7 @@ weechat_cmd_server (int argc, char **argv) if (new_server->autoconnect) { - (void) gui_buffer_new (gui_current_window, new_server, NULL, 0, 1); + (void) gui_buffer_new (window, new_server, NULL, 0, 1); server_connect (new_server); } @@ -2391,6 +2617,9 @@ weechat_cmd_set_display_option (t_config_option *option, char *prefix, void *val GUI_COLOR(COLOR_WIN_CHAT_DARK)); free (value2); } + else + gui_printf (NULL, "%s\"\"", + GUI_COLOR(COLOR_WIN_CHAT_DARK)); gui_printf (NULL, "\n"); break; } @@ -2401,7 +2630,7 @@ weechat_cmd_set_display_option (t_config_option *option, char *prefix, void *val */ int -weechat_cmd_set (char *arguments) +weechat_cmd_set (t_gui_window *window, char *arguments) { char *option, *value, *pos; int i, j, section_displayed; @@ -2410,7 +2639,10 @@ weechat_cmd_set (char *arguments) char option_name[256]; void *ptr_option_value; int last_section, last_option, number_found; - + + /* make gcc happy */ + (void) window; + option = NULL; value = NULL; if (arguments && arguments[0]) @@ -2717,11 +2949,14 @@ weechat_cmd_set (char *arguments) */ int -weechat_cmd_unalias (char *arguments) +weechat_cmd_unalias (t_gui_window *window, char *arguments) { t_weelist *ptr_weelist; t_weechat_alias *ptr_alias; + /* make gcc happy */ + (void) window; + ptr_weelist = weelist_search (index_commands, arguments); if (!ptr_weelist) { @@ -2746,7 +2981,7 @@ weechat_cmd_unalias (char *arguments) */ int -weechat_cmd_unignore (int argc, char **argv) +weechat_cmd_unignore (t_gui_window *window, int argc, char **argv) { char *error; int number, ret; @@ -2756,7 +2991,7 @@ weechat_cmd_unignore (int argc, char **argv) { case 0: /* List all ignore */ - weechat_cmd_ignore (argc, argv); + weechat_cmd_ignore (window, argc, argv); return 0; break; case 1: @@ -2766,18 +3001,18 @@ weechat_cmd_unignore (int argc, char **argv) ret = ignore_search_free_by_number (number); else ret = ignore_search_free (argv[0], "*", "*", - (SERVER(gui_current_window->buffer)) ? - SERVER(gui_current_window->buffer)->name : "*"); + (SERVER(window->buffer)) ? + SERVER(window->buffer)->name : "*"); break; case 2: ret = ignore_search_free (argv[0], argv[1], "*", - (SERVER(gui_current_window->buffer)) ? - SERVER(gui_current_window->buffer)->name : "*"); + (SERVER(window->buffer)) ? + SERVER(window->buffer)->name : "*"); break; case 3: ret = ignore_search_free (argv[0], argv[1], argv[2], - (SERVER(gui_current_window->buffer)) ? - SERVER(gui_current_window->buffer)->name : "*"); + (SERVER(window->buffer)) ? + SERVER(window->buffer)->name : "*"); break; case 4: ret = ignore_search_free (argv[0], argv[1], argv[2], argv[3]); @@ -2812,7 +3047,7 @@ weechat_cmd_unignore (int argc, char **argv) */ int -weechat_cmd_upgrade (int argc, char **argv) +weechat_cmd_upgrade (t_gui_window *window, int argc, char **argv) { t_irc_server *ptr_server; int filename_length; @@ -2820,6 +3055,7 @@ weechat_cmd_upgrade (int argc, char **argv) char *exec_args[5] = { NULL, "-a", "--session", NULL, NULL }; /* make gcc happy */ + (void) window; (void) argc; (void) argv; @@ -2828,7 +3064,7 @@ weechat_cmd_upgrade (int argc, char **argv) { if (ptr_server->child_pid != 0) { - irc_display_prefix (NULL, gui_current_window->buffer, PREFIX_ERROR); + irc_display_prefix (NULL, NULL, PREFIX_ERROR); gui_printf_nolog (NULL, _("%s can't upgrade: connection to at least " "one server is pending"), @@ -2900,7 +3136,7 @@ weechat_cmd_upgrade (int argc, char **argv) */ int -weechat_cmd_uptime (int argc, char **argv) +weechat_cmd_uptime (t_gui_window *window, int argc, char **argv) { time_t running_time; int day, hour, min, sec; @@ -2913,8 +3149,8 @@ weechat_cmd_uptime (int argc, char **argv) sec = ((running_time % (60 * 60 * 24)) % (60 * 60)) % 60; if ((argc == 1) && (strcmp (argv[0], "-o") == 0) - && ((BUFFER_IS_CHANNEL(gui_current_window->buffer)) - || (BUFFER_IS_PRIVATE(gui_current_window->buffer)))) + && ((BUFFER_IS_CHANNEL(window->buffer)) + || (BUFFER_IS_PRIVATE(window->buffer)))) { snprintf (string, sizeof (string), _("WeeChat uptime: %d %s %02d:%02d:%02d, started on %s"), @@ -2925,15 +3161,12 @@ weechat_cmd_uptime (int argc, char **argv) sec, ctime (&weechat_start_time)); string[strlen (string) - 1] = '\0'; - user_command (SERVER(gui_current_window->buffer), - gui_current_window->buffer, - string); + user_command (window, SERVER(window->buffer), string); } else { - irc_display_prefix (NULL, gui_current_window->buffer, - PREFIX_INFO); - gui_printf_nolog (gui_current_window->buffer, + irc_display_prefix (NULL, window->buffer, PREFIX_INFO); + gui_printf_nolog (window->buffer, _("WeeChat uptime: %s%d %s%s " "%s%02d%s:%s%02d%s:%s%02d%s, " "started on %s%s"), @@ -2962,7 +3195,7 @@ weechat_cmd_uptime (int argc, char **argv) */ int -weechat_cmd_window (int argc, char **argv) +weechat_cmd_window (t_gui_window *window, int argc, char **argv) { t_gui_window *ptr_win; int i; @@ -3009,10 +3242,10 @@ weechat_cmd_window (int argc, char **argv) number = strtol (argv[1], &error, 10); if ((error) && (error[0] == '\0') && (number > 0) && (number < 100)) - gui_window_split_horiz (gui_current_window, number); + gui_window_split_horiz (window, number); } else - gui_window_split_horiz (gui_current_window, 50); + gui_window_split_horiz (window, 50); } else if (ascii_strcasecmp (argv[0], "splitv") == 0) { @@ -3023,10 +3256,10 @@ weechat_cmd_window (int argc, char **argv) number = strtol (argv[1], &error, 10); if ((error) && (error[0] == '\0') && (number > 0) && (number < 100)) - gui_window_split_vertic (gui_current_window, number); + gui_window_split_vertic (window, number); } else - gui_window_split_vertic (gui_current_window, 50); + gui_window_split_vertic (window, 50); } else if (ascii_strcasecmp (argv[0], "resize") == 0) { @@ -3037,7 +3270,7 @@ weechat_cmd_window (int argc, char **argv) number = strtol (argv[1], &error, 10); if ((error) && (error[0] == '\0') && (number > 0) && (number < 100)) - gui_window_resize (gui_current_window, number); + gui_window_resize (window, number); } } else if (ascii_strcasecmp (argv[0], "merge") == 0) @@ -3045,7 +3278,7 @@ weechat_cmd_window (int argc, char **argv) if (argc >= 2) { if (ascii_strcasecmp (argv[1], "all") == 0) - gui_window_merge_all (gui_current_window); + gui_window_merge_all (window); else { irc_display_prefix (NULL, NULL, PREFIX_ERROR); @@ -3057,7 +3290,7 @@ weechat_cmd_window (int argc, char **argv) } else { - if (!gui_window_merge (gui_current_window)) + if (!gui_window_merge (window)) { irc_display_prefix (NULL, NULL, PREFIX_ERROR); gui_printf (NULL, @@ -3075,20 +3308,20 @@ weechat_cmd_window (int argc, char **argv) error = NULL; number = strtol (argv[0] + 1, &error, 10); if ((error) && (error[0] == '\0')) - gui_window_switch_by_buffer (gui_current_window, number); + gui_window_switch_by_buffer (window, number); } else if (ascii_strcasecmp (argv[0], "-1") == 0) - gui_window_switch_previous (gui_current_window); + gui_window_switch_previous (window); else if (ascii_strcasecmp (argv[0], "+1") == 0) - gui_window_switch_next (gui_current_window); + gui_window_switch_next (window); else if (ascii_strcasecmp (argv[0], "up") == 0) - gui_window_switch_up (gui_current_window); + gui_window_switch_up (window); else if (ascii_strcasecmp (argv[0], "down") == 0) - gui_window_switch_down (gui_current_window); + gui_window_switch_down (window); else if (ascii_strcasecmp (argv[0], "left") == 0) - gui_window_switch_left (gui_current_window); + gui_window_switch_left (window); else if (ascii_strcasecmp (argv[0], "right") == 0) - gui_window_switch_right (gui_current_window); + gui_window_switch_right (window); else { irc_display_prefix (NULL, NULL, PREFIX_ERROR); diff --git a/src/common/command.h b/src/common/command.h index 3cbd599a5..10cd44c86 100644 --- a/src/common/command.h +++ b/src/common/command.h @@ -36,8 +36,8 @@ struct t_weechat_command char *arguments; char *arguments_description; int min_arg, max_arg; - int (*cmd_function_args)(int, char **); - int (*cmd_function_1arg)(char *); + int (*cmd_function_args)(t_gui_window *, int, char **); + int (*cmd_function_1arg)(t_gui_window *, char *); }; typedef struct t_weechat_alias t_weechat_alias; @@ -62,27 +62,28 @@ extern t_weechat_alias *alias_new (char *, char *); extern void alias_free_all (); extern char **explode_string (char *, char *, int, int *); extern void free_exploded_string (char **); -extern int exec_weechat_command (t_irc_server *, char *); -extern void user_command (t_irc_server *, t_gui_buffer *, char *); -extern int weechat_cmd_alias (char *); -extern int weechat_cmd_buffer (int, char **); -extern int weechat_cmd_clear (int, char **); -extern int weechat_cmd_connect (int, char **); -extern int weechat_cmd_debug (int, char **); -extern int weechat_cmd_disconnect (int, char **); -extern int weechat_cmd_help (int, char **); -extern int weechat_cmd_history (int, char **); +extern int exec_weechat_command (t_gui_window *, t_irc_server *, char *); +extern void user_command (t_gui_window *, t_irc_server *, char *); +extern int weechat_cmd_alias (t_gui_window *, char *); +extern int weechat_cmd_buffer (t_gui_window *, int, char **); +extern int weechat_cmd_charset (t_gui_window *, int, char **); +extern int weechat_cmd_clear (t_gui_window *, int, char **); +extern int weechat_cmd_connect (t_gui_window *, int, char **); +extern int weechat_cmd_debug (t_gui_window *, int, char **); +extern int weechat_cmd_disconnect (t_gui_window *, int, char **); +extern int weechat_cmd_help (t_gui_window *, int, char **); +extern int weechat_cmd_history (t_gui_window *, int, char **); extern void weechat_cmd_ignore_display (char *, t_irc_ignore *); -extern int weechat_cmd_ignore (int, char **); -extern int weechat_cmd_key (char *); -extern int weechat_cmd_plugin (int, char **); -extern int weechat_cmd_save (int, char **); -extern int weechat_cmd_server (int, char **); -extern int weechat_cmd_set (char *); -extern int weechat_cmd_unalias (char *); -extern int weechat_cmd_unignore (int, char **); -extern int weechat_cmd_upgrade (int, char **); -extern int weechat_cmd_uptime (int, char **); -extern int weechat_cmd_window (int, char **); +extern int weechat_cmd_ignore (t_gui_window *, int, char **); +extern int weechat_cmd_key (t_gui_window *, char *); +extern int weechat_cmd_plugin (t_gui_window *, int, char **); +extern int weechat_cmd_save (t_gui_window *, int, char **); +extern int weechat_cmd_server (t_gui_window *, int, char **); +extern int weechat_cmd_set (t_gui_window *, char *); +extern int weechat_cmd_unalias (t_gui_window *, char *); +extern int weechat_cmd_unignore (t_gui_window *, int, char **); +extern int weechat_cmd_upgrade (t_gui_window *, int, char **); +extern int weechat_cmd_uptime (t_gui_window *, int, char **); +extern int weechat_cmd_window (t_gui_window *, int, char **); #endif /* command.h */ diff --git a/src/common/completion.c b/src/common/completion.c index 8cf2a81b0..f681bd097 100644 --- a/src/common/completion.c +++ b/src/common/completion.c @@ -101,10 +101,10 @@ completion_stop (t_completion *completion) */ void -completion_build_list (t_completion *completion, void *channel) +completion_build_list (t_completion *completion, void *server, void *channel) { t_weelist *ptr_list; - int i, j; + int i, j, length; t_irc_server *ptr_server; t_irc_channel *ptr_channel; t_irc_nick *ptr_nick; @@ -155,6 +155,82 @@ completion_build_list (t_completion *completion, void *channel) "notify"); return; } + if (ascii_strcasecmp (completion->base_command, "charset") == 0) + { + if (completion->base_command_arg == 1) + { + weelist_add (&completion->completion_list, + &completion->last_completion, + "decode_iso"); + weelist_add (&completion->completion_list, + &completion->last_completion, + "decode_utf"); + weelist_add (&completion->completion_list, + &completion->last_completion, + "encode"); + } + else if (completion->base_command_arg == 2) + { + if (!server) + { + completion_stop (completion); + return; + } + pos = strchr (completion->args, ' '); + if (pos) + pos[0] = '\0'; + string2 = NULL; + if (ascii_strcasecmp (completion->args, "decode_iso") == 0) + { + config_option_list_get_value (&(((t_irc_server *)server)->charset_decode_iso), + (channel) ? ((t_irc_channel *)channel)->name : "server", + &string, &length); + if (string && (length > 0)) + { + string2 = strdup (string); + string2[length] = '\0'; + } + } + else if (ascii_strcasecmp (completion->args, "decode_utf") == 0) + { + config_option_list_get_value (&(((t_irc_server *)server)->charset_decode_utf), + (channel) ? ((t_irc_channel *)channel)->name : "server", + &string, &length); + if (string && (length > 0)) + { + string2 = strdup (string); + string2[length] = '\0'; + } + } + else if (ascii_strcasecmp (completion->args, "encode") == 0) + { + config_option_list_get_value (&(((t_irc_server *)server)->charset_encode), + (channel) ? ((t_irc_channel *)channel)->name : "server", + &string, &length); + if (string && (length > 0)) + { + string2 = strdup (string); + string2[length] = '\0'; + } + } + + if (string2) + { + weelist_add (&completion->completion_list, + &completion->last_completion, + string2); + free (string2); + } + else + completion_stop (completion); + + if (pos) + pos[0] = ' '; + } + else + completion_stop (completion); + return; + } if ((ascii_strcasecmp (completion->base_command, "clear") == 0) && (completion->base_command_arg == 1)) { @@ -672,11 +748,9 @@ completion_build_list (t_completion *completion, void *channel) string = (char *)gui_color_decode_for_user_entry ((unsigned char *)((t_irc_channel *)channel)->topic); else string = (char *)gui_color_decode ((unsigned char *)((t_irc_channel *)channel)->topic, 0); - string2 = weechat_convert_encoding ((local_utf8) ? - cfg_look_charset_decode_iso : cfg_look_charset_decode_utf, - (cfg_look_charset_internal && cfg_look_charset_internal[0]) ? - cfg_look_charset_internal : local_charset, - (string) ? string : ((t_irc_channel *)channel)->topic); + string2 = channel_iconv_decode ((t_irc_server *)server, + (t_irc_channel *)channel, + (string) ? string : ((t_irc_channel *)channel)->topic); weelist_add (&completion->completion_list, &completion->last_completion, (string2) ? string2 : ((t_irc_channel *)channel)->topic); @@ -697,8 +771,8 @@ completion_build_list (t_completion *completion, void *channel) */ void -completion_find_context (t_completion *completion, void *channel, char *buffer, - int size, int pos) +completion_find_context (t_completion *completion, void *server, void *channel, + char *buffer, int size, int pos) { int i, command, command_arg, pos_start, pos_end; @@ -808,7 +882,7 @@ completion_find_context (t_completion *completion, void *channel, char *buffer, for (i = pos_start; i <= pos_end; i++) completion->base_command[i - pos_start] = buffer[i]; completion->base_command[pos_end - pos_start + 1] = '\0'; - completion_build_list (completion, channel); + completion_build_list (completion, server, channel); } } @@ -1066,7 +1140,7 @@ completion_nick (t_completion *completion, t_irc_channel *channel) */ void -completion_search (t_completion *completion, void *channel, +completion_search (t_completion *completion, void *server, void *channel, char *buffer, int size, int pos) { char *old_word_found; @@ -1075,7 +1149,7 @@ completion_search (t_completion *completion, void *channel, if (pos != completion->position) { completion->word_found = NULL; - completion_find_context (completion, channel, buffer, size, pos); + completion_find_context (completion, server, channel, buffer, size, pos); } /* completion */ diff --git a/src/common/completion.h b/src/common/completion.h index a9451eed3..56464a3f7 100644 --- a/src/common/completion.h +++ b/src/common/completion.h @@ -54,6 +54,6 @@ struct t_completion extern void completion_init (t_completion *); extern void completion_free (t_completion *); -extern void completion_search (t_completion *, void *, char *, int, int); +extern void completion_search (t_completion *, void *, void *, char *, int, int); #endif /* completion.h */ diff --git a/src/common/fifo.c b/src/common/fifo.c index b4a690446..c53987796 100644 --- a/src/common/fifo.c +++ b/src/common/fifo.c @@ -174,7 +174,8 @@ fifo_exec (char *text) ptr_buffer = gui_buffers; } - user_command (ptr_server, ptr_buffer, pos_msg); + user_command (gui_buffer_find_window (ptr_buffer), + ptr_server, pos_msg); } /* diff --git a/src/common/session.c b/src/common/session.c index 0ac84d817..833ea874d 100644 --- a/src/common/session.c +++ b/src/common/session.c @@ -237,6 +237,9 @@ session_save_servers (FILE *file) rc = rc && (session_write_int (file, SESSION_SERV_LAG, ptr_server->lag)); rc = rc && (session_write_buf (file, SESSION_SERV_LAG_CHECK_TIME, &(ptr_server->lag_check_time), sizeof (struct timeval))); rc = rc && (session_write_buf (file, SESSION_SERV_LAG_NEXT_CHECK, &(ptr_server->lag_next_check), sizeof (time_t))); + rc = rc && (session_write_str (file, SESSION_SERV_CHARSET_DECODE_ISO, ptr_server->charset_decode_iso)); + rc = rc && (session_write_str (file, SESSION_SERV_CHARSET_DECODE_UTF, ptr_server->charset_decode_utf)); + rc = rc && (session_write_str (file, SESSION_SERV_CHARSET_ENCODE, ptr_server->charset_encode)); rc = rc && (session_write_id (file, SESSION_SERV_END)); if (!rc) @@ -832,6 +835,15 @@ session_load_server (FILE *file) case SESSION_SERV_LAG_NEXT_CHECK: rc = rc && (session_read_buf (file, &(session_current_server->lag_next_check), sizeof (time_t))); break; + case SESSION_SERV_CHARSET_DECODE_ISO: + rc = rc && (session_read_str (file, &(session_current_server->charset_decode_iso))); + break; + case SESSION_SERV_CHARSET_DECODE_UTF: + rc = rc && (session_read_str (file, &(session_current_server->charset_decode_utf))); + break; + case SESSION_SERV_CHARSET_ENCODE: + rc = rc && (session_read_str (file, &(session_current_server->charset_encode))); + break; default: weechat_log_printf (_("session: warning: ignoring value from " "server (object id: %d)\n")); diff --git a/src/common/session.h b/src/common/session.h index 666b7aca9..f0e29df72 100644 --- a/src/common/session.h +++ b/src/common/session.h @@ -84,7 +84,10 @@ enum t_session_server SESSION_SERV_AWAY_TIME, SESSION_SERV_LAG, SESSION_SERV_LAG_CHECK_TIME, - SESSION_SERV_LAG_NEXT_CHECK + SESSION_SERV_LAG_NEXT_CHECK, + SESSION_SERV_CHARSET_DECODE_ISO, + SESSION_SERV_CHARSET_DECODE_UTF, + SESSION_SERV_CHARSET_ENCODE }; enum t_session_channel diff --git a/src/common/weechat.c b/src/common/weechat.c index e076b4da3..d9f834853 100644 --- a/src/common/weechat.c +++ b/src/common/weechat.c @@ -209,11 +209,11 @@ weechat_log_printf (char *message, ...) } /* - * weechat_convert_encoding: convert string to another encoding + * weechat_iconv: convert string to another charset */ char * -weechat_convert_encoding (char *from_code, char *to_code, char *string) +weechat_iconv (char *from_code, char *to_code, char *string) { char *outbuf; @@ -584,7 +584,8 @@ weechat_parse_args (int argc, char *argv[]) server_tmp.ipv6, server_tmp.ssl, server_tmp.password, server_tmp.nick1, server_tmp.nick2, server_tmp.nick3, - NULL, NULL, NULL, 0, server_tmp.autojoin, 1, NULL)) + NULL, NULL, NULL, 0, server_tmp.autojoin, 1, NULL, + NULL, NULL, NULL)) fprintf (stderr, _("%s unable to create server ('%s'), ignored\n"), WEECHAT_WARNING, argv[i]); server_destroy (&server_tmp); diff --git a/src/common/weechat.h b/src/common/weechat.h index 379ab80da..273ecc4ad 100644 --- a/src/common/weechat.h +++ b/src/common/weechat.h @@ -109,7 +109,7 @@ extern int ascii_strcasecmp (char *, char *); extern int ascii_strncasecmp (char *, char *, int); extern void weechat_log_printf (char *, ...); extern void weechat_dump (int); -extern char *weechat_convert_encoding (char *, char *, char *); +extern char *weechat_iconv (char *, char *, char *); extern long get_timeval_diff (struct timeval *, struct timeval *); extern void weechat_shutdown (int, int); diff --git a/src/common/weeconfig.c b/src/common/weeconfig.c index bc86c20c5..3ff0bc16a 100644 --- a/src/common/weeconfig.c +++ b/src/common/weeconfig.c @@ -937,6 +937,21 @@ t_config_option weechat_options_server[] = N_("comma separated list of notify levels for channels of this server (format: #channel:1,..)"), OPTION_TYPE_STRING, 0, 0, 0, "", NULL, NULL, &(cfg_server.notify_levels), config_change_notify_levels }, + { "server_charset_decode_iso", N_("charset for decoding ISO on server and channels"), + N_("comma separated list of charsets for server and channels, " + "to decode ISO (format: server:charset,#channel:charset,..)"), + OPTION_TYPE_STRING, 0, 0, 0, + "", NULL, NULL, &(cfg_server.charset_decode_iso), config_change_noop }, + { "server_charset_decode_utf", N_("charset for decoding UTF on server and channels"), + N_("comma separated list of charsets for server and channels, " + "to decode UTF (format: server:charset,#channel:charset,..)"), + OPTION_TYPE_STRING, 0, 0, 0, + "", NULL, NULL, &(cfg_server.charset_decode_utf), config_change_noop }, + { "server_charset_encode", N_("charset for encoding messages on server and channels"), + N_("comma separated list of charsets for server and channels, " + "to encode messages (format: server:charset,#channel:charset,..)"), + OPTION_TYPE_STRING, 0, 0, 0, + "", NULL, NULL, &(cfg_server.charset_encode), config_change_noop }, { NULL, NULL, NULL, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL } }; @@ -951,12 +966,12 @@ t_config_option *weechat_options[CONFIG_NUMBER_SECTIONS] = /* - * get_pos_array_values: returns position of a string in an array of values - * returns -1 if not found, otherwise position + * config_get_pos_array_values: return position of a string in an array of values + * return -1 if not found, otherwise position */ int -get_pos_array_values (char **array, char *string) +config_get_pos_array_values (char **array, char *string) { int i; @@ -1240,7 +1255,8 @@ config_option_set_value (t_config_option *option, char *value) *(option->ptr_int) = int_value; break; case OPTION_TYPE_INT_WITH_STRING: - int_value = get_pos_array_values (option->array_values, value); + int_value = config_get_pos_array_values (option->array_values, + value); if (int_value < 0) return -1; *(option->ptr_int) = int_value; @@ -1259,6 +1275,116 @@ config_option_set_value (t_config_option *option, char *value) } /* + * config_option_list_remove: remove an item from a list for an option + * (for options with value like: "abc:1,def:blabla") + */ + +void +config_option_list_remove (char **string, char *item) +{ + char *name, *pos, *pos2; + + if (!string || !(*string)) + return; + + name = (char *) malloc (strlen (item) + 2); + strcpy (name, item); + strcat (name, ":"); + pos = strstr (*string, name); + free (name); + if (pos) + { + pos2 = pos + strlen (item); + if (pos2[0] == ':') + { + pos2++; + if (pos2[0]) + { + while (pos2[0] && (pos2[0] != ',')) + pos2++; + if (pos2[0] == ',') + pos2++; + if (!pos2[0] && (pos != (*string))) + pos--; + strcpy (pos, pos2); + if (!(*string)[0]) + { + free (*string); + *string = NULL; + } + else + (*string) = (char *) realloc (*string, strlen (*string) + 1); + } + } + } +} + +/* + * config_option_list_set: set an item from a list for an option + * (for options with value like: "abc:1,def:blabla") + */ + +void +config_option_list_set (char **string, char *item, char *value) +{ + config_option_list_remove (string, item); + + if (!(*string)) + { + (*string) = (char *) malloc (strlen (item) + 1 + strlen (value) + 1); + (*string)[0] = '\0'; + } + else + (*string) = (char *) realloc (*string, + strlen (*string) + 1 + + strlen (item) + 1 + strlen (value) + 1); + + if ((*string)[0]) + strcat (*string, ","); + strcat (*string, item); + strcat (*string, ":"); + strcat (*string, value); +} + +/* + * config_option_list_get_value: return position of item value in the list + * (for options with value like: "abc:1,def:blabla") + */ + +void +config_option_list_get_value (char **string, char *item, + char **pos_found, int *length) +{ + char *name, *pos, *pos2, *pos_comma; + + *pos_found = NULL; + *length = 0; + + if (!string || !(*string)) + return; + + name = (char *) malloc (strlen (item) + 2); + strcpy (name, item); + strcat (name, ":"); + pos = strstr (*string, name); + free (name); + if (pos) + { + pos2 = pos + strlen (item); + if (pos2[0] == ':') + { + pos2++; + *pos_found = pos2; + pos_comma = strchr (pos2, ','); + if (pos_comma) + *length = pos_comma - pos2; + else + *length = strlen (pos2); + } + } +} + +/* * config_get_server_option_ptr: get a pointer to a server config option */ @@ -1303,6 +1429,12 @@ config_get_server_option_ptr (t_irc_server *server, char *option_name) return (void *)(&server->autorejoin); if (ascii_strcasecmp (option_name, "server_notify_levels") == 0) return (void *)(&server->notify_levels); + if (ascii_strcasecmp (option_name, "server_charset_decode_iso") == 0) + return (void *)(&server->charset_decode_iso); + if (ascii_strcasecmp (option_name, "server_charset_decode_utf") == 0) + return (void *)(&server->charset_decode_utf); + if (ascii_strcasecmp (option_name, "server_charset_encode") == 0) + return (void *)(&server->charset_encode); /* option not found */ return NULL; } @@ -1357,7 +1489,8 @@ config_set_server_value (t_irc_server *server, char *option_name, *((int *)(ptr_data)) = int_value; break; case OPTION_TYPE_INT_WITH_STRING: - int_value = get_pos_array_values (ptr_option->array_values, value); + int_value = config_get_pos_array_values (ptr_option->array_values, + value); if (int_value < 0) return -2; *((int *)(ptr_data)) = int_value; @@ -1527,7 +1660,9 @@ config_allocate_server (char *filename, int line_number) cfg_server.password, cfg_server.nick1, cfg_server.nick2, cfg_server.nick3, cfg_server.username, cfg_server.realname, cfg_server.command, cfg_server.command_delay, cfg_server.autojoin, - cfg_server.autorejoin, cfg_server.notify_levels)) + cfg_server.autorejoin, cfg_server.notify_levels, + cfg_server.charset_decode_iso, cfg_server.charset_decode_utf, + cfg_server.charset_encode)) { server_free_all (); gui_printf (NULL, @@ -1566,7 +1701,7 @@ config_default_values () weechat_options[i][j].default_int; break; case OPTION_TYPE_INT_WITH_STRING: - int_value = get_pos_array_values ( + int_value = config_get_pos_array_values ( weechat_options[i][j].array_values, weechat_options[i][j].default_string); if (int_value < 0) @@ -2064,6 +2199,10 @@ config_create_default () fprintf (file, "server_command_delay = 0\n"); fprintf (file, "server_autojoin = \"\"\n"); fprintf (file, "server_autorejoin = on\n"); + fprintf (file, "server_notify_levels = \"\"\n"); + fprintf (file, "server_charset_decode_iso = \"\"\n"); + fprintf (file, "server_charset_decode_utf = \"\"\n"); + fprintf (file, "server_charset_encode = \"\"\n"); fclose (file); chmod (filename, 0600); @@ -2251,6 +2390,12 @@ config_write (char *config_name) (ptr_server->autorejoin) ? "on" : "off"); fprintf (file, "server_notify_levels = \"%s\"\n", (ptr_server->notify_levels) ? ptr_server->notify_levels : ""); + fprintf (file, "server_charset_decode_iso = \"%s\"\n", + (ptr_server->charset_decode_iso) ? ptr_server->charset_decode_iso : ""); + fprintf (file, "server_charset_decode_utf = \"%s\"\n", + (ptr_server->charset_decode_utf) ? ptr_server->charset_decode_utf : ""); + fprintf (file, "server_charset_encode = \"%s\"\n", + (ptr_server->charset_encode) ? ptr_server->charset_encode : ""); } } diff --git a/src/common/weeconfig.h b/src/common/weeconfig.h index 38096af2f..7df3d78cb 100644 --- a/src/common/weeconfig.h +++ b/src/common/weeconfig.h @@ -238,6 +238,9 @@ extern void config_change_fifo_pipe (); extern void config_change_notify_levels (); extern void config_change_log (); extern int config_option_set_value (t_config_option *, char *); +extern void config_option_list_remove (char **, char *); +extern void config_option_list_set (char **, char *, char *); +extern void config_option_list_get_value (char **, char *, char **, int *); extern t_config_option *config_option_search (char *); extern void config_option_search_option_value (char *, t_config_option **, void **); extern int config_set_value (char *, char *); diff --git a/src/gui/curses/gui-display.c b/src/gui/curses/gui-display.c index f9832e3ac..aa103abb9 100644 --- a/src/gui/curses/gui-display.c +++ b/src/gui/curses/gui-display.c @@ -806,11 +806,9 @@ gui_draw_buffer_title (t_gui_buffer *buffer, int erase) if (CHANNEL(buffer)->topic) { buf = (char *)gui_color_decode ((unsigned char *)(CHANNEL(buffer)->topic), 0); - buf2 = weechat_convert_encoding ((local_utf8) ? - cfg_look_charset_decode_iso : cfg_look_charset_decode_utf, - (cfg_look_charset_internal && cfg_look_charset_internal[0]) ? - cfg_look_charset_internal : local_charset, - (buf) ? buf : CHANNEL(buffer)->topic); + buf2 = channel_iconv_decode (SERVER(buffer), + CHANNEL(buffer), + (buf) ? buf : CHANNEL(buffer)->topic); mvwprintw (ptr_win->win_title, 0, 0, format, (buf2) ? buf2 : CHANNEL(buffer)->topic); if (buf) free (buf); @@ -1519,12 +1517,10 @@ gui_draw_buffer_chat (t_gui_buffer *buffer, int erase) mvwprintw (ptr_win->win_chat, i, 0, "%s %-16s ", (ptr_dcc == dcc_selected) ? "***" : " ", ptr_dcc->nick); - buf = weechat_convert_encoding ((local_utf8) ? - cfg_look_charset_decode_iso : cfg_look_charset_decode_utf, - (cfg_look_charset_internal && cfg_look_charset_internal[0]) ? - cfg_look_charset_internal : local_charset, - (DCC_IS_CHAT(ptr_dcc->type)) ? - _(ptr_dcc->filename) : ptr_dcc->filename); + buf = channel_iconv_decode (SERVER(buffer), + CHANNEL(buffer), + (DCC_IS_CHAT(ptr_dcc->type)) ? + _(ptr_dcc->filename) : ptr_dcc->filename); wprintw (ptr_win->win_chat, "%s", buf); free (buf); if (DCC_IS_FILE(ptr_dcc->type)) @@ -1543,11 +1539,9 @@ gui_draw_buffer_chat (t_gui_buffer *buffer, int erase) (DCC_IS_RECV(ptr_dcc->type)) ? "-->>" : "<<--"); gui_window_set_weechat_color (ptr_win->win_chat, COLOR_DCC_WAITING + ptr_dcc->status); - buf = weechat_convert_encoding ((local_utf8) ? - cfg_look_charset_decode_iso : cfg_look_charset_decode_utf, - (cfg_look_charset_internal && cfg_look_charset_internal[0]) ? - cfg_look_charset_internal : local_charset, - _(dcc_status_string[ptr_dcc->status])); + buf = channel_iconv_decode (SERVER(buffer), + CHANNEL(buffer), + _(dcc_status_string[ptr_dcc->status])); wprintw (ptr_win->win_chat, "%-10s", buf); free (buf); @@ -1604,11 +1598,9 @@ gui_draw_buffer_chat (t_gui_buffer *buffer, int erase) ptr_dcc->eta % 60); } sprintf (format, "%s %%s/s)", unit_format[num_unit]); - buf = weechat_convert_encoding ((local_utf8) ? - cfg_look_charset_decode_iso : cfg_look_charset_decode_utf, - (cfg_look_charset_internal && cfg_look_charset_internal[0]) ? - cfg_look_charset_internal : local_charset, - unit_name[num_unit]); + buf = channel_iconv_decode (SERVER(buffer), + CHANNEL(buffer), + unit_name[num_unit]); wprintw (ptr_win->win_chat, format, ((long double) ptr_dcc->bytes_per_sec) / ((long double)(unit_divide[num_unit])), buf); diff --git a/src/gui/gui-action.c b/src/gui/gui-action.c index ddfc8def8..e68e883f1 100644 --- a/src/gui/gui-action.c +++ b/src/gui/gui-action.c @@ -108,9 +108,7 @@ gui_action_return (t_gui_window *window) window->buffer->completion.position = -1; window->buffer->ptr_history = NULL; gui_draw_buffer_input (window->buffer, 0); - user_command (SERVER(window->buffer), - window->buffer, - command); + user_command (window, SERVER(window->buffer), command); free (command); } } @@ -128,6 +126,7 @@ gui_action_tab (t_gui_window *window) if (window->buffer->has_input) { completion_search (&(window->buffer->completion), + SERVER(window->buffer), CHANNEL(window->buffer), window->buffer->input_buffer, window->buffer->input_buffer_size, diff --git a/src/gui/gui-common.c b/src/gui/gui-common.c index af1e0f86b..85a59fdb5 100644 --- a/src/gui/gui-common.c +++ b/src/gui/gui-common.c @@ -322,6 +322,26 @@ gui_buffer_search (char *server, char *channel) } /* + * gui_buffer_find_window: find a window displaying buffer + */ + +t_gui_window * +gui_buffer_find_window (t_gui_buffer *buffer) +{ + t_gui_window *ptr_win; + + for (ptr_win = gui_windows; ptr_win; + ptr_win = ptr_win->next_window) + { + if (ptr_win->buffer == buffer) + return ptr_win; + } + + /* no window found */ + return NULL; +} + +/* * gui_buffer_servers_search: search servers buffer * (when same buffer is used for all servers) */ @@ -857,7 +877,7 @@ gui_printf_internal (t_gui_buffer *buffer, int display_time, int type, char *mes time_t time_seconds; struct tm *local_time; int time_first_digit, time_last_digit; - char *pos, *buf2; + char *buf2, *pos; int i; va_list argptr; static time_t seconds; @@ -898,12 +918,8 @@ gui_printf_internal (t_gui_buffer *buffer, int display_time, int type, char *mes if (!buf[0]) return; - if (!local_utf8 || !utf8_is_valid (buf)) - buf2 = weechat_convert_encoding ((local_utf8) ? - cfg_look_charset_decode_iso : cfg_look_charset_decode_utf, - (cfg_look_charset_internal && cfg_look_charset_internal[0]) ? - cfg_look_charset_internal : local_charset, - buf); + if (gui_init_ok) + buf2 = channel_iconv_decode (SERVER(buffer), CHANNEL(buffer), buf); else buf2 = strdup (buf); @@ -1015,16 +1031,7 @@ gui_infobar_printf (int time_displayed, int color, char *message, ...) buf2 = (char *)gui_color_decode ((unsigned char *)buffer, 0); if (buf2) - { - if (!local_utf8 || !utf8_is_valid (buf2)) - buf3 = weechat_convert_encoding ((local_utf8) ? - cfg_look_charset_decode_iso : cfg_look_charset_decode_utf, - (cfg_look_charset_internal && cfg_look_charset_internal[0]) ? - cfg_look_charset_internal : local_charset, - buf2); - else - buf3 = strdup (buf2); - } + buf3 = channel_iconv_decode (NULL, NULL, buf2); else buf3 = NULL; diff --git a/src/gui/gui-keyboard.c b/src/gui/gui-keyboard.c index 60d06e9db..556962f3c 100644 --- a/src/gui/gui-keyboard.c +++ b/src/gui/gui-keyboard.c @@ -517,8 +517,8 @@ gui_key_pressed (char *key_str) /* exact combo found => execute function or command */ gui_key_buffer[0] = '\0'; if (ptr_key->command) - user_command (SERVER(gui_current_window->buffer), - gui_current_window->buffer, + user_command (gui_current_window, + SERVER(gui_current_window->buffer), ptr_key->command); else (void)(ptr_key->function)(gui_current_window); diff --git a/src/gui/gui.h b/src/gui/gui.h index b19b82237..5515bb805 100644 --- a/src/gui/gui.h +++ b/src/gui/gui.h @@ -402,6 +402,7 @@ extern void gui_window_tree_node_to_leaf (t_gui_window_tree *, t_gui_window *); extern void gui_window_tree_free (t_gui_window_tree **); extern t_gui_window *gui_window_new (t_gui_window *, int, int, int, int, int, int); extern t_gui_buffer *gui_buffer_search (char *, char *); +extern t_gui_window *gui_buffer_find_window (t_gui_buffer *); extern t_gui_buffer *gui_buffer_new (t_gui_window *, void *, void *, int, int); extern void gui_buffer_clear (t_gui_buffer *); extern void gui_buffer_clear_all (); diff --git a/src/irc/irc-channel.c b/src/irc/irc-channel.c index 761e64fc7..6d2baa925 100644 --- a/src/irc/irc-channel.c +++ b/src/irc/irc-channel.c @@ -30,6 +30,8 @@ #include "../common/weechat.h" #include "irc.h" +#include "../common/utf8.h" +#include "../common/weeconfig.h" #include "../gui/gui.h" @@ -172,6 +174,143 @@ string_is_channel (char *string) } /* + * channel_get_charset_decode_iso: get decode iso value for channel + * if not found for channel, look for server + * if not found for server, look for global + */ + +char * +channel_get_charset_decode_iso (t_irc_server *server, t_irc_channel *channel) +{ + char *pos, *result; + int length; + + if (!server) + return (cfg_look_charset_decode_iso) ? + strdup (cfg_look_charset_decode_iso) : strdup (""); + + if (!channel) + return server_get_charset_decode_iso (server); + + config_option_list_get_value (&(server->charset_decode_iso), + channel->name, &pos, &length); + if (pos && (length > 0)) + { + result = strdup (pos); + result[length] = '\0'; + return result; + } + + return server_get_charset_decode_iso (server); +} + +/* + * channel_get_charset_decode_utf: get decode utf value for channel + * if not found for channel, look for server + * if not found for server, look for global + */ + +char * +channel_get_charset_decode_utf (t_irc_server *server, t_irc_channel *channel) +{ + char *pos, *result; + int length; + + if (!server) + return (cfg_look_charset_decode_utf) ? + strdup (cfg_look_charset_decode_utf) : strdup (""); + + if (!channel) + return server_get_charset_decode_utf (server); + + config_option_list_get_value (&(server->charset_decode_utf), + channel->name, &pos, &length); + if (pos && (length > 0)) + { + result = strdup (pos); + result[length] = '\0'; + return result; + } + + return server_get_charset_decode_utf (server); +} + +/* + * channel_get_charset_encode: get encode value for channel + * if not found for channel, look for server + * if not found for server, look for global + */ + +char * +channel_get_charset_encode (t_irc_server *server, t_irc_channel *channel) +{ + char *pos, *result; + int length; + + if (!server) + return (cfg_look_charset_encode) ? + strdup (cfg_look_charset_encode) : strdup (""); + + if (!channel) + return server_get_charset_encode (server); + + config_option_list_get_value (&(server->charset_encode), + channel->name, &pos, &length); + if (pos && (length > 0)) + { + result = strdup (pos); + result[length] = '\0'; + return result; + } + + return server_get_charset_encode (server); +} + +/* + * channel_iconv_decode: convert string to local charset + */ + +char * +channel_iconv_decode (t_irc_server *server, t_irc_channel *channel, char *string) +{ + char *from_charset, *string2; + + if (!local_utf8 || !utf8_is_valid (string)) + { + if (local_utf8) + from_charset = channel_get_charset_decode_iso (server, channel); + else + from_charset = channel_get_charset_decode_utf (server, channel); + string2 = weechat_iconv (from_charset, + (cfg_look_charset_internal && cfg_look_charset_internal[0]) ? + cfg_look_charset_internal : local_charset, + string); + free (from_charset); + return string2; + } + else + return strdup (string); +} + +/* + * + */ + +char * +channel_iconv_encode (t_irc_server *server, t_irc_channel *channel, char *string) +{ + char *to_charset, *string2; + + to_charset = channel_get_charset_encode (server, channel); + string2 = weechat_iconv ((cfg_look_charset_internal && cfg_look_charset_internal[0]) ? + cfg_look_charset_internal : local_charset, + to_charset, + string); + free (to_charset); + return string2; +} + +/* * channel_remove_away: remove away for all nicks on a channel */ @@ -306,96 +445,25 @@ channel_get_notify_level (t_irc_server *server, t_irc_channel *channel) } /* - * server_remove_notify_level: remove channel notify from list - */ - -void -channel_remove_notify_level (t_irc_server *server, t_irc_channel *channel) -{ - char *name, *pos, *pos2; - - if ((!server) || (!channel)) - return; - - name = (char *) malloc (strlen (channel->name) + 2); - strcpy (name, channel->name); - strcat (name, ":"); - pos = strstr (server->notify_levels, name); - free (name); - if (pos) - { - pos2 = pos + strlen (channel->name); - if (pos2[0] == ':') - { - pos2++; - if (pos2[0]) - { - pos2++; - if (pos2[0] == ',') - pos2++; - if (!pos2[0] && (pos != server->notify_levels)) - pos--; - strcpy (pos, pos2); - server->notify_levels = (char *) realloc (server->notify_levels, - strlen (server->notify_levels) + 1); - } - } - } -} - -/* * server_set_notify_level: set channel notify level */ void channel_set_notify_level (t_irc_server *server, t_irc_channel *channel, int notify) { - char *name, *pos, *pos2, level_string[2]; + char level_string[2]; if ((!server) || (!channel)) return; if (notify == NOTIFY_LEVEL_DEFAULT) - { - channel_remove_notify_level (server, channel); - return; - } - - if (!server->notify_levels) - { - server->notify_levels = (char *) malloc (strlen (channel->name) + 3); - server->notify_levels[0] = '\0'; - } + config_option_list_remove (&(server->notify_levels), channel->name); else { - name = (char *) malloc (strlen (channel->name) + 2); - strcpy (name, channel->name); - strcat (name, ":"); - pos = strstr (server->notify_levels, name); - free (name); - if (pos) - { - pos2 = pos + strlen (channel->name) + 1; - if (pos2[0]) - { - pos2[0] = '0' + notify; - return; - } - } - /* realloc notify list to add channel */ - server->notify_levels = (char *) realloc (server->notify_levels, - strlen (server->notify_levels) + 1 + - strlen (channel->name) + 2 + 1); + level_string[0] = notify + '0'; + level_string[1] = '\0'; + config_option_list_set (&(server->notify_levels), channel->name, level_string); } - - /* channel not in notify list => add it */ - if (server->notify_levels[0]) - strcat (server->notify_levels, ","); - strcat (server->notify_levels, channel->name); - strcat (server->notify_levels, ":"); - level_string[0] = notify + '0'; - level_string[1] = '\0'; - strcat (server->notify_levels, level_string); } /* diff --git a/src/irc/irc-dcc.c b/src/irc/irc-dcc.c index cdf7d08b1..422e4c85a 100644 --- a/src/irc/irc-dcc.c +++ b/src/irc/irc-dcc.c @@ -1120,10 +1120,9 @@ dcc_chat_sendf (t_irc_dcc *ptr_dcc, char *fmt, ...) gui_printf (ptr_dcc->server->buffer, "[DEBUG] Sending to remote host (DCC CHAT) >>> %s\n", buffer); buffer[size_buf - 2] = '\r'; #endif - buf2 = weechat_convert_encoding ((cfg_look_charset_internal && cfg_look_charset_internal[0]) ? - cfg_look_charset_internal : local_charset, - cfg_look_charset_encode, - buffer); + buf2 = channel_iconv_encode (ptr_dcc->server, + ptr_dcc->channel, + buffer); if (dcc_chat_send (ptr_dcc, buf2, strlen (buf2)) <= 0) { irc_display_prefix (ptr_dcc->server, ptr_dcc->server->buffer, @@ -1144,7 +1143,7 @@ void dcc_chat_recv (t_irc_dcc *ptr_dcc) { static char buffer[4096 + 2]; - char *buf2, *pos, *ptr_buf, *next_ptr_buf; + char *buf2, *pos, *ptr_buf, *ptr_buf2, *next_ptr_buf; char *ptr_buf_color; int num_read; @@ -1196,7 +1195,11 @@ dcc_chat_recv (t_irc_dcc *ptr_dcc) if (ptr_buf) { - ptr_buf_color = (char *)gui_color_decode ((unsigned char *)ptr_buf, + ptr_buf2 = channel_iconv_decode (ptr_dcc->server, + ptr_dcc->channel, + ptr_buf); + ptr_buf_color = (char *)gui_color_decode ((ptr_buf2) ? + (unsigned char *)ptr_buf2 : (unsigned char *)ptr_buf, cfg_irc_colors_receive); gui_printf_type (ptr_dcc->channel->buffer, MSG_TYPE_NICK, "%s<", GUI_COLOR(COLOR_WIN_CHAT_DARK)); @@ -1213,7 +1216,7 @@ dcc_chat_recv (t_irc_dcc *ptr_dcc) COLOR_WIN_INFOBAR_HIGHLIGHT, _("Private %s> %s"), ptr_dcc->nick, - (ptr_buf_color) ? ptr_buf_color : ptr_buf); + (ptr_buf_color) ? ptr_buf_color : ((ptr_buf2) ? ptr_buf2 : ptr_buf)); } else gui_printf_type (ptr_dcc->channel->buffer, MSG_TYPE_NICK, @@ -1228,13 +1231,15 @@ dcc_chat_recv (t_irc_dcc *ptr_dcc) (ptr_buf_color) ? ptr_buf_color : ptr_buf); if (ptr_buf_color) free (ptr_buf_color); + if (ptr_buf2) + free (ptr_buf2); } ptr_buf = next_ptr_buf; } if (buf2) -free (buf2); + free (buf2); } else { diff --git a/src/irc/irc-display.c b/src/irc/irc-display.c index b8be20219..05332ae63 100644 --- a/src/irc/irc-display.c +++ b/src/irc/irc-display.c @@ -185,27 +185,27 @@ irc_display_server (t_irc_server *server) _("connected") : _("not connected"), GUI_COLOR(COLOR_WIN_CHAT_DARK)); - gui_printf (NULL, " server_autoconnect . . . .: %s%s\n", + gui_printf (NULL, " server_autoconnect . . . . : %s%s\n", (server->autoconnect) ? _("on") : _("off"), (server->command_line) ? _(" (temporary server, will not be saved)") : ""); - gui_printf (NULL, " server_autoreconnect . . .: %s\n", + gui_printf (NULL, " server_autoreconnect . . . : %s\n", (server->autoreconnect) ? _("on") : _("off")); - gui_printf (NULL, " server_autoreconnect_delay: %d %s\n", + gui_printf (NULL, " server_autoreconnect_delay : %d %s\n", server->autoreconnect_delay, _("seconds")); - gui_printf (NULL, " server_address . . . . . .: %s\n", + gui_printf (NULL, " server_address . . . . . . : %s\n", server->address); - gui_printf (NULL, " server_port . . . . . . .: %d\n", + gui_printf (NULL, " server_port . . . . . . . : %d\n", server->port); - gui_printf (NULL, " server_ipv6 . . . . . . .: %s\n", + gui_printf (NULL, " server_ipv6 . . . . . . . : %s\n", (server->ipv6) ? _("on") : _("off")); - gui_printf (NULL, " server_ssl . . . . . . . .: %s\n", + gui_printf (NULL, " server_ssl . . . . . . . . : %s\n", (server->ssl) ? _("on") : _("off")); - gui_printf (NULL, " server_password . . . . .: %s\n", + gui_printf (NULL, " server_password . . . . . : %s\n", (server->password && server->password[0]) ? _("(hidden)") : ""); - gui_printf (NULL, " server_nick1/2/3 . . . . .: %s %s/ %s%s %s/ %s%s\n", + gui_printf (NULL, " server_nick1/2/3 . . . . . : %s %s/ %s%s %s/ %s%s\n", server->nick1, GUI_COLOR(COLOR_WIN_CHAT_DARK), GUI_COLOR(COLOR_WIN_CHAT), @@ -213,20 +213,29 @@ irc_display_server (t_irc_server *server) GUI_COLOR(COLOR_WIN_CHAT_DARK), GUI_COLOR(COLOR_WIN_CHAT), server->nick3); - gui_printf (NULL, " server_username . . . . .: %s\n", + gui_printf (NULL, " server_username . . . . . : %s\n", server->username); - gui_printf (NULL, " server_realname . . . . .: %s\n", + gui_printf (NULL, " server_realname . . . . . : %s\n", server->realname); - gui_printf (NULL, " server_command . . . . . .: %s\n", + gui_printf (NULL, " server_command . . . . . . : %s\n", (server->command && server->command[0]) ? server->command : ""); - gui_printf (NULL, " server_command_delay . . .: %d %s\n", + gui_printf (NULL, " server_command_delay . . . : %d %s\n", server->command_delay, _("seconds")); - gui_printf (NULL, " server_autojoin . . . . .: %s\n", + gui_printf (NULL, " server_autojoin . . . . . : %s\n", (server->autojoin && server->autojoin[0]) ? server->autojoin : ""); - gui_printf (NULL, " server_notify_levels . . .: %s\n", + gui_printf (NULL, " server_notify_levels . . . : %s\n", (server->notify_levels && server->notify_levels[0]) ? server->notify_levels : ""); + gui_printf (NULL, " server_charset_decode_iso. : %s\n", + (server->charset_decode_iso && server->charset_decode_iso[0]) ? + server->charset_decode_iso : ""); + gui_printf (NULL, " server_charset_decode_utf. : %s\n", + (server->charset_decode_utf && server->charset_decode_utf[0]) ? + server->charset_decode_utf : ""); + gui_printf (NULL, " server_charset_encode. . . : %s\n", + (server->charset_encode && server->charset_encode[0]) ? + server->charset_encode : ""); } diff --git a/src/irc/irc-recv.c b/src/irc/irc-recv.c index a19196315..bb0eeb359 100644 --- a/src/irc/irc-recv.c +++ b/src/irc/irc-recv.c @@ -2225,14 +2225,16 @@ irc_cmd_recv_quit (t_irc_server *server, char *host, char *nick, char *arguments pos = strchr (host, '!'); irc_display_prefix (server, ptr_channel->buffer, PREFIX_QUIT); gui_printf (ptr_channel->buffer, - _("%s%s %s(%s%s%s)%s has quit %s(%s%s%s)\n"), + _("%s%s %s(%s%s%s)%s has quit"), GUI_COLOR(COLOR_WIN_CHAT_NICK), nick, GUI_COLOR(COLOR_WIN_CHAT_DARK), GUI_COLOR(COLOR_WIN_CHAT_HOST), (pos) ? pos + 1 : "", GUI_COLOR(COLOR_WIN_CHAT_DARK), - GUI_COLOR(COLOR_WIN_CHAT), + GUI_COLOR(COLOR_WIN_CHAT)); + gui_printf (ptr_channel->buffer, + " %s(%s%s%s)\n", GUI_COLOR(COLOR_WIN_CHAT_DARK), GUI_COLOR(COLOR_WIN_CHAT), arguments, @@ -2447,7 +2449,7 @@ irc_cmd_recv_004 (t_irc_server *server, char *host, char *nick, char *arguments) /* execute command once connected */ if (server->command && server->command[0]) { - user_command(server, NULL, server->command); + user_command(NULL, server, server->command); if (server->command_delay > 0) sleep (server->command_delay); } diff --git a/src/irc/irc-server.c b/src/irc/irc-server.c index 2a4b6107e..33cf7afd0 100644 --- a/src/irc/irc-server.c +++ b/src/irc/irc-server.c @@ -84,6 +84,9 @@ server_init (t_irc_server *server) server->autojoin = NULL; server->autorejoin = 0; server->notify_levels = NULL; + server->charset_decode_iso = NULL; + server->charset_decode_utf = NULL; + server->charset_encode = NULL; /* internal vars */ server->child_pid = 0; @@ -294,6 +297,12 @@ server_destroy (t_irc_server *server) free (server->autojoin); if (server->notify_levels) free (server->notify_levels); + if (server->charset_decode_iso) + free (server->charset_decode_iso); + if (server->charset_decode_utf) + free (server->charset_decode_utf); + if (server->charset_encode) + free (server->charset_encode); if (server->unterminated_message) free (server->unterminated_message); if (server->nick) @@ -355,7 +364,8 @@ server_new (char *name, int autoconnect, int autoreconnect, int autoreconnect_de int command_line, char *address, int port, int ipv6, int ssl, char *password, char *nick1, char *nick2, char *nick3, char *username, char *realname, char *command, int command_delay, char *autojoin, - int autorejoin, char *notify_levels) + int autorejoin, char *notify_levels, char *charset_decode_iso, + char *charset_decode_utf, char *charset_encode) { t_irc_server *new_server; @@ -365,12 +375,16 @@ server_new (char *name, int autoconnect, int autoreconnect, int autoreconnect_de #ifdef DEBUG weechat_log_printf ("Creating new server (name:%s, address:%s, port:%d, pwd:%s, " "nick1:%s, nick2:%s, nick3:%s, username:%s, realname:%s, " - "command:%s, autojoin:%s, autorejoin:%s, notify_levels:%s)\n", + "command:%s, autojoin:%s, autorejoin:%s, notify_levels:%s, " + "decode_iso:%s, decode_utf:%s, encode:%s)\n", name, address, port, (password) ? password : "", (nick1) ? nick1 : "", (nick2) ? nick2 : "", (nick3) ? nick3 : "", (username) ? username : "", (realname) ? realname : "", (command) ? command : "", (autojoin) ? autojoin : "", - (autorejoin) ? "on" : "off", (notify_levels) ? notify_levels : ""); + (autorejoin) ? "on" : "off", (notify_levels) ? notify_levels : "", + (charset_decode_iso) ? charset_decode_iso : "", + (charset_decode_utf) ? charset_decode_utf : "", + (charset_encode) ? charset_encode : ""); #endif if ((new_server = server_alloc ())) @@ -400,6 +414,12 @@ server_new (char *name, int autoconnect, int autoreconnect, int autoreconnect_de new_server->autorejoin = autorejoin; new_server->notify_levels = (notify_levels) ? strdup (notify_levels) : NULL; + new_server->charset_decode_iso = + (charset_decode_iso) ? strdup (charset_decode_iso) : NULL; + new_server->charset_decode_utf = + (charset_decode_utf) ? strdup (charset_decode_utf) : NULL; + new_server->charset_encode = + (charset_encode) ? strdup (charset_encode) : NULL; } else return NULL; @@ -407,6 +427,90 @@ server_new (char *name, int autoconnect, int autoreconnect, int autoreconnect_de } /* + * server_get_charset_decode_iso: get decode iso value for server + * if not found for server, look for global + */ + +char * +server_get_charset_decode_iso (t_irc_server *server) +{ + char *pos, *result; + int length; + + if (!server) + return (cfg_look_charset_decode_iso) ? + strdup (cfg_look_charset_decode_iso) : strdup (""); + + config_option_list_get_value (&(server->charset_decode_iso), + "server", &pos, &length); + if (pos && (length > 0)) + { + result = strdup (pos); + result[length] = '\0'; + return result; + } + + return (cfg_look_charset_decode_iso) ? + strdup (cfg_look_charset_decode_iso) : strdup (""); +} + +/* + * server_get_charset_decode_utf: get decode utf value for server + * if not found for server, look for global + */ + +char * +server_get_charset_decode_utf (t_irc_server *server) +{ + char *pos, *result; + int length; + + if (!server) + return (cfg_look_charset_decode_utf) ? + strdup (cfg_look_charset_decode_utf) : strdup (""); + + config_option_list_get_value (&(server->charset_decode_utf), + "server", &pos, &length); + if (pos && (length > 0)) + { + result = strdup (pos); + result[length] = '\0'; + return result; + } + + return (cfg_look_charset_decode_utf) ? + strdup (cfg_look_charset_decode_utf) : strdup (""); +} + +/* + * server_get_charset_encode: get encode value for server + * if not found for server, look for global + */ + +char * +server_get_charset_encode (t_irc_server *server) +{ + char *pos, *result; + int length; + + if (!server) + return (cfg_look_charset_encode) ? + strdup (cfg_look_charset_encode) : strdup (""); + + config_option_list_get_value (&(server->charset_encode), + "server", &pos, &length); + if (pos && (length > 0)) + { + result = strdup (pos); + result[length] = '\0'; + return result; + } + + return (cfg_look_charset_encode) ? + strdup (cfg_look_charset_encode) : strdup (""); +} + +/* * server_send: send data to IRC server */ @@ -433,7 +537,6 @@ server_sendf (t_irc_server *server, char *fmt, ...) { va_list args; static char buffer[4096]; - char *buf2; int size_buf; if (!server) @@ -454,17 +557,12 @@ server_sendf (t_irc_server *server, char *fmt, ...) gui_printf (server->buffer, "[DEBUG] Sending to server >>> %s\n", buffer); buffer[size_buf - 2] = '\r'; #endif - buf2 = weechat_convert_encoding ((cfg_look_charset_internal && cfg_look_charset_internal[0]) ? - cfg_look_charset_internal : local_charset, - cfg_look_charset_encode, - buffer); - if (server_send (server, buf2, strlen (buf2)) <= 0) + if (server_send (server, buffer, strlen (buffer)) <= 0) { irc_display_prefix (server, server->buffer, PREFIX_ERROR); gui_printf (server->buffer, _("%s error sending data to IRC server\n"), WEECHAT_ERROR); } - free (buf2); } /* @@ -1782,6 +1880,9 @@ server_print_log (t_irc_server *server) weechat_log_printf (" autojoin. . . . . . : '%s'\n", server->autojoin); weechat_log_printf (" autorejoin. . . . . : %d\n", server->autorejoin); weechat_log_printf (" notify_levels . . . : %s\n", server->notify_levels); + weechat_log_printf (" charset_decode_iso. : %s\n", server->charset_decode_iso); + weechat_log_printf (" charset_decode_utf. : %s\n", server->charset_decode_utf); + weechat_log_printf (" charset_encode. . . : %s\n", server->charset_encode); weechat_log_printf (" child_pid . . . . . : %d\n", server->child_pid); weechat_log_printf (" child_read . . . . : %d\n", server->child_read); weechat_log_printf (" child_write . . . . : %d\n", server->child_write); diff --git a/src/irc/irc.h b/src/irc/irc.h index e2fdc00fb..28a10b13f 100644 --- a/src/irc/irc.h +++ b/src/irc/irc.h @@ -143,6 +143,9 @@ struct t_irc_server char *autojoin; /* channels to automatically join */ int autorejoin; /* auto rejoin channels when kicked */ char *notify_levels; /* channels notify levels */ + char *charset_decode_iso; /* channels charsets for decoding ISO */ + char *charset_decode_utf; /* channels charsets for decoding UTF */ + char *charset_encode; /* channels charsets for encoding msgs */ /* internal vars */ pid_t child_pid; /* pid of child process (connecting) */ @@ -301,7 +304,11 @@ extern void server_free (t_irc_server *); extern void server_free_all (); extern t_irc_server *server_new (char *, int, int, int, int, char *, int, int, int, char *, char *, char *, char *, char *, char *, - char *, int, char *, int, char *); + char *, int, char *, int, char *, char *, char *, + char *); +extern char *server_get_charset_decode_iso (t_irc_server *); +extern char *server_get_charset_decode_utf (t_irc_server *); +extern char *server_get_charset_encode (t_irc_server *); extern int server_send (t_irc_server *, char *, int); extern void server_sendf (t_irc_server *, char *, ...); extern void server_recv (t_irc_server *); @@ -336,13 +343,17 @@ extern void channel_free (t_irc_server *, t_irc_channel *); extern void channel_free_all (t_irc_server *); extern t_irc_channel *channel_search (t_irc_server *, char *); extern int string_is_channel (char *); +extern char *channel_get_charset_decode_iso (t_irc_server *, t_irc_channel *); +extern char *channel_get_charset_decode_utf (t_irc_server *, t_irc_channel *); +extern char *channel_get_charset_encode (t_irc_server *, t_irc_channel *); +extern char *channel_iconv_decode (t_irc_server *, t_irc_channel *, char *); +extern char *channel_iconv_encode (t_irc_server *, t_irc_channel *, char *); extern void channel_remove_away (t_irc_channel *); extern void channel_check_away (t_irc_server *, t_irc_channel *); extern void channel_set_away (t_irc_channel *, char *, int); extern int channel_create_dcc (t_irc_dcc *); extern void channel_remove_dcc (t_irc_dcc *); extern int channel_get_notify_level (t_irc_server *, t_irc_channel *); -extern void channel_remove_notify_level (t_irc_server *, t_irc_channel *); extern void channel_set_notify_level (t_irc_server *, t_irc_channel *, int); extern void channel_print_log (t_irc_channel *); @@ -387,12 +398,9 @@ extern void irc_display_mode (t_irc_server *, t_gui_buffer *, char *, char, char *, char *, char *, char *); extern void irc_display_server (t_irc_server *ptr_server); -/* IRC protocol (irc-commands.c) */ +/* IRC commands issued by user (irc-send.c) */ -extern int irc_is_highlight (char *, char *); -extern int irc_recv_command (t_irc_server *, char *, char *, char *, char *); extern void irc_login (t_irc_server *); -/* IRC commands issued by user */ extern int irc_cmd_send_admin (t_irc_server *, char *); extern int irc_cmd_send_ame (t_irc_server *, char *); extern int irc_cmd_send_amsg (t_irc_server *, char *); @@ -452,7 +460,11 @@ extern int irc_cmd_send_wallops (t_irc_server *, char *); extern int irc_cmd_send_who (t_irc_server *, char *); extern int irc_cmd_send_whois (t_irc_server *, char *); extern int irc_cmd_send_whowas (t_irc_server *, char *); -/* IRC commands executed when received from server */ + +/* IRC commands executed when received from server (irc-recv.c) */ + +extern int irc_is_highlight (char *, char *); +extern int irc_recv_command (t_irc_server *, char *, char *, char *, char *); extern int irc_cmd_recv_error (t_irc_server *, char *, char *, char *); extern int irc_cmd_recv_invite (t_irc_server *, char *, char *, char *); extern int irc_cmd_recv_join (t_irc_server *, char *, char *, char *); diff --git a/src/plugins/plugins-interface.c b/src/plugins/plugins-interface.c index 12083faf4..615ef89d6 100644 --- a/src/plugins/plugins-interface.c +++ b/src/plugins/plugins-interface.c @@ -288,11 +288,14 @@ weechat_plugin_exec_command (t_weechat_plugin *plugin, plugin_find_server_channel (server, channel, &ptr_server, &ptr_channel); if (ptr_server && ptr_channel) - user_command (ptr_server, ptr_channel->buffer, command); + user_command (gui_buffer_find_window (ptr_channel->buffer), + ptr_server, command); else if (ptr_server && (ptr_server->buffer)) - user_command (ptr_server, ptr_server->buffer, command); + user_command (gui_buffer_find_window (ptr_server->buffer), + ptr_server, command); else - user_command (NULL, gui_buffers, command); + user_command (gui_buffer_find_window (gui_buffers), + NULL, command); } /* |