diff --git a/ChangeLog b/ChangeLog index 629087dab..4c1de1f4f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,10 +1,11 @@ WeeChat - Wee Enhanced Environment for Chat =========================================== -ChangeLog - 2007-03-06 +ChangeLog - 2007-03-12 Version 0.2.4 (under dev!): + * improved password hiding, code cleanup (bug #19229) * added new return code in plugin API to force highlight (for message handlers only) * fixed bug with server buffer when "look_one_server_buffer" is ON and diff --git a/src/common/command.c b/src/common/command.c index 528cacb4d..b96cac9e6 100644 --- a/src/common/command.c +++ b/src/common/command.c @@ -2968,7 +2968,7 @@ weechat_cmd_server (t_irc_server *server, t_irc_channel *channel, void weechat_cmd_set_display_option (t_config_option *option, char *prefix, void *value) { - char *color_name, *pos_nickserv, *pos_pwd, *value2; + char *color_name, *value2; gui_printf (NULL, " %s%s%s%s = ", (prefix) ? prefix : "", @@ -3009,32 +3009,22 @@ weechat_cmd_set_display_option (t_config_option *option, char *prefix, void *val if (*((char **)value)) { value2 = strdup (*((char **)value)); - pos_nickserv = NULL; - pos_pwd = NULL; - pos_nickserv = strstr (value2, "nickserv"); - if (pos_nickserv) + if (value2) { - pos_pwd = strstr (value2, "identify "); - if (!pos_pwd) - pos_pwd = strstr (value2, "register "); - } - if (cfg_log_hide_nickserv_pwd && pos_nickserv && pos_pwd) - { - pos_pwd += 9; - while (pos_pwd[0]) + if (cfg_log_hide_nickserv_pwd) { - pos_pwd[0] = '*'; - pos_pwd++; + irc_hide_password (value2, 1); + if (strcmp (*((char **)value), value2) != 0) + gui_printf (NULL, _("%s(password hidden) "), + GUI_COLOR(COLOR_WIN_CHAT)); } - gui_printf (NULL, _("%s(password hidden) "), - GUI_COLOR(COLOR_WIN_CHAT)); + gui_printf (NULL, "%s\"%s%s%s\"", + GUI_COLOR(COLOR_WIN_CHAT_DARK), + GUI_COLOR(COLOR_WIN_CHAT_HOST), + value2, + GUI_COLOR(COLOR_WIN_CHAT_DARK)); + free (value2); } - gui_printf (NULL, "%s\"%s%s%s\"", - GUI_COLOR(COLOR_WIN_CHAT_DARK), - GUI_COLOR(COLOR_WIN_CHAT_HOST), - value2, - GUI_COLOR(COLOR_WIN_CHAT_DARK)); - free (value2); } else gui_printf (NULL, "%s\"\"", diff --git a/src/common/history.c b/src/common/history.c index 37749dd69..8e260b7d9 100644 --- a/src/common/history.c +++ b/src/common/history.c @@ -31,6 +31,7 @@ #include "history.h" #include "util.h" #include "weeconfig.h" +#include "../irc/irc.h" #include "../gui/gui.h" @@ -40,32 +41,6 @@ t_history *history_global_ptr = NULL; int num_history_global = 0; -/* - * history_hide_password: hide a nickserv password - */ - -void -history_hide_password (char *string) -{ - char *pos_pwd; - - if (strstr (string, "nickserv ")) - { - pos_pwd = strstr (string, "identify "); - if (!pos_pwd) - pos_pwd = strstr (string, "register "); - if (pos_pwd) - { - pos_pwd += 9; - while (pos_pwd[0]) - { - pos_pwd[0] = '*'; - pos_pwd++; - } - } - } -} - /* * history_buffer_add: add a text/command to buffer's history */ @@ -87,7 +62,7 @@ history_buffer_add (void *buffer, char *string) { new_history->text = strdup (string); if (cfg_log_hide_nickserv_pwd) - history_hide_password (new_history->text); + irc_hide_password (new_history->text, 1); if (((t_gui_buffer *)(buffer))->history) ((t_gui_buffer *)(buffer))->history->prev_history = new_history; @@ -137,7 +112,7 @@ history_global_add (char *string) { new_history->text = strdup (string); if (cfg_log_hide_nickserv_pwd) - history_hide_password (new_history->text); + irc_hide_password (new_history->text, 1); if (history_global) history_global->prev_history = new_history; diff --git a/src/irc/irc-display.c b/src/irc/irc-display.c index 248a54132..bb9288be3 100644 --- a/src/irc/irc-display.c +++ b/src/irc/irc-display.c @@ -372,6 +372,8 @@ irc_display_mode (t_irc_server *server, t_gui_buffer *buffer, void irc_display_server (t_irc_server *server) { + char *string; + gui_printf (NULL, "\n"); gui_printf (NULL, _("%sServer: %s%s %s[%s%s%s]\n"), GUI_COLOR(COLOR_WIN_CHAT), @@ -417,9 +419,22 @@ irc_display_server (t_irc_server *server) server->realname); gui_printf (NULL, " server_hostname . . . . . : %s\n", (server->hostname) ? server->hostname : ""); - gui_printf (NULL, " server_command . . . . . . : %s\n", - (server->command && server->command[0]) ? - server->command : ""); + if (server->command && server->command[0]) + string = strdup (server->command); + else + string = NULL; + if (string) + { + if (cfg_log_hide_nickserv_pwd) + irc_hide_password (string, 1); + gui_printf (NULL, " server_command . . . . . . : %s\n", + string); + free (string); + } + else + gui_printf (NULL, " server_command . . . . . . : %s\n", + (server->command && server->command[0]) ? + server->command : ""); gui_printf (NULL, " server_command_delay . . . : %d %s\n", server->command_delay, _("seconds")); diff --git a/src/irc/irc-send.c b/src/irc/irc-send.c index 60fbf09c9..2027e5381 100644 --- a/src/irc/irc-send.c +++ b/src/irc/irc-send.c @@ -44,6 +44,58 @@ #include "../gui/gui.h" +/* + * irc_hide_password: hide IRC password(s) in a string + */ + +void +irc_hide_password (char *string, int look_for_nickserv) +{ + char *pos_nickserv, *pos, *pos_pwd; + + pos = string; + while (1) + { + if (look_for_nickserv) + { + pos_nickserv = strstr (pos, "nickserv "); + if (!pos_nickserv) + return; + pos = pos_nickserv + 9; + while (pos[0] == ' ') + pos++; + if ((strncmp (pos, "identify ", 9) == 0) + || (strncmp (pos, "register ", 9) == 0)) + pos_pwd = pos + 9; + else + pos_pwd = NULL; + } + else + { + pos_pwd = strstr (pos, "identify "); + if (!pos_pwd) + pos_pwd = strstr (pos, "register "); + if (!pos_pwd) + return; + pos_pwd += 9; + } + + if (pos_pwd) + { + while (pos_pwd[0] == ' ') + pos_pwd++; + + while (pos_pwd[0] && (pos_pwd[0] != ';') && (pos_pwd[0] != ' ') + && (pos_pwd[0] != '"')) + { + pos_pwd[0] = '*'; + pos_pwd++; + } + pos = pos_pwd; + } + } +} + /* * irc_login: login to irc server */ @@ -1189,7 +1241,7 @@ irc_cmd_send_msg (t_irc_server *server, t_irc_channel *channel, t_gui_window *window; t_gui_buffer *buffer; char *pos, *pos_comma; - char *msg_pwd_hidden, *pos_pwd; + char *msg_pwd_hidden; t_irc_channel *ptr_channel; t_irc_nick *ptr_nick; char *string; @@ -1274,20 +1326,7 @@ irc_cmd_send_msg (t_irc_server *server, t_irc_channel *channel, { msg_pwd_hidden = strdup (pos); if (cfg_log_hide_nickserv_pwd) - { - pos_pwd = strstr (msg_pwd_hidden, "identify "); - if (!pos_pwd) - pos_pwd = strstr (msg_pwd_hidden, "register "); - if (pos_pwd) - { - pos_pwd += 9; - while (pos_pwd[0]) - { - pos_pwd[0] = '*'; - pos_pwd++; - } - } - } + irc_hide_password (msg_pwd_hidden, 0); irc_display_prefix (server, server->buffer, PREFIX_SERVER); gui_printf_type (server->buffer, MSG_TYPE_NICK, "%s-%s%s%s- ", diff --git a/src/irc/irc.h b/src/irc/irc.h index bd67df0ab..234e97e73 100644 --- a/src/irc/irc.h +++ b/src/irc/irc.h @@ -472,6 +472,7 @@ extern void irc_display_server (t_irc_server *ptr_server); /* IRC commands issued by user (irc-send.c) */ extern void irc_login (t_irc_server *); +extern void irc_hide_password (char *, int); extern int irc_cmd_send_admin (t_irc_server *, t_irc_channel *, char *); extern int irc_cmd_send_ame (t_irc_server *, t_irc_channel *, char *); extern int irc_cmd_send_amsg (t_irc_server *, t_irc_channel *, char *); diff --git a/weechat/ChangeLog b/weechat/ChangeLog index 629087dab..4c1de1f4f 100644 --- a/weechat/ChangeLog +++ b/weechat/ChangeLog @@ -1,10 +1,11 @@ WeeChat - Wee Enhanced Environment for Chat =========================================== -ChangeLog - 2007-03-06 +ChangeLog - 2007-03-12 Version 0.2.4 (under dev!): + * improved password hiding, code cleanup (bug #19229) * added new return code in plugin API to force highlight (for message handlers only) * fixed bug with server buffer when "look_one_server_buffer" is ON and diff --git a/weechat/src/common/command.c b/weechat/src/common/command.c index 528cacb4d..b96cac9e6 100644 --- a/weechat/src/common/command.c +++ b/weechat/src/common/command.c @@ -2968,7 +2968,7 @@ weechat_cmd_server (t_irc_server *server, t_irc_channel *channel, void weechat_cmd_set_display_option (t_config_option *option, char *prefix, void *value) { - char *color_name, *pos_nickserv, *pos_pwd, *value2; + char *color_name, *value2; gui_printf (NULL, " %s%s%s%s = ", (prefix) ? prefix : "", @@ -3009,32 +3009,22 @@ weechat_cmd_set_display_option (t_config_option *option, char *prefix, void *val if (*((char **)value)) { value2 = strdup (*((char **)value)); - pos_nickserv = NULL; - pos_pwd = NULL; - pos_nickserv = strstr (value2, "nickserv"); - if (pos_nickserv) + if (value2) { - pos_pwd = strstr (value2, "identify "); - if (!pos_pwd) - pos_pwd = strstr (value2, "register "); - } - if (cfg_log_hide_nickserv_pwd && pos_nickserv && pos_pwd) - { - pos_pwd += 9; - while (pos_pwd[0]) + if (cfg_log_hide_nickserv_pwd) { - pos_pwd[0] = '*'; - pos_pwd++; + irc_hide_password (value2, 1); + if (strcmp (*((char **)value), value2) != 0) + gui_printf (NULL, _("%s(password hidden) "), + GUI_COLOR(COLOR_WIN_CHAT)); } - gui_printf (NULL, _("%s(password hidden) "), - GUI_COLOR(COLOR_WIN_CHAT)); + gui_printf (NULL, "%s\"%s%s%s\"", + GUI_COLOR(COLOR_WIN_CHAT_DARK), + GUI_COLOR(COLOR_WIN_CHAT_HOST), + value2, + GUI_COLOR(COLOR_WIN_CHAT_DARK)); + free (value2); } - gui_printf (NULL, "%s\"%s%s%s\"", - GUI_COLOR(COLOR_WIN_CHAT_DARK), - GUI_COLOR(COLOR_WIN_CHAT_HOST), - value2, - GUI_COLOR(COLOR_WIN_CHAT_DARK)); - free (value2); } else gui_printf (NULL, "%s\"\"", diff --git a/weechat/src/common/history.c b/weechat/src/common/history.c index 37749dd69..8e260b7d9 100644 --- a/weechat/src/common/history.c +++ b/weechat/src/common/history.c @@ -31,6 +31,7 @@ #include "history.h" #include "util.h" #include "weeconfig.h" +#include "../irc/irc.h" #include "../gui/gui.h" @@ -40,32 +41,6 @@ t_history *history_global_ptr = NULL; int num_history_global = 0; -/* - * history_hide_password: hide a nickserv password - */ - -void -history_hide_password (char *string) -{ - char *pos_pwd; - - if (strstr (string, "nickserv ")) - { - pos_pwd = strstr (string, "identify "); - if (!pos_pwd) - pos_pwd = strstr (string, "register "); - if (pos_pwd) - { - pos_pwd += 9; - while (pos_pwd[0]) - { - pos_pwd[0] = '*'; - pos_pwd++; - } - } - } -} - /* * history_buffer_add: add a text/command to buffer's history */ @@ -87,7 +62,7 @@ history_buffer_add (void *buffer, char *string) { new_history->text = strdup (string); if (cfg_log_hide_nickserv_pwd) - history_hide_password (new_history->text); + irc_hide_password (new_history->text, 1); if (((t_gui_buffer *)(buffer))->history) ((t_gui_buffer *)(buffer))->history->prev_history = new_history; @@ -137,7 +112,7 @@ history_global_add (char *string) { new_history->text = strdup (string); if (cfg_log_hide_nickserv_pwd) - history_hide_password (new_history->text); + irc_hide_password (new_history->text, 1); if (history_global) history_global->prev_history = new_history; diff --git a/weechat/src/irc/irc-display.c b/weechat/src/irc/irc-display.c index 248a54132..bb9288be3 100644 --- a/weechat/src/irc/irc-display.c +++ b/weechat/src/irc/irc-display.c @@ -372,6 +372,8 @@ irc_display_mode (t_irc_server *server, t_gui_buffer *buffer, void irc_display_server (t_irc_server *server) { + char *string; + gui_printf (NULL, "\n"); gui_printf (NULL, _("%sServer: %s%s %s[%s%s%s]\n"), GUI_COLOR(COLOR_WIN_CHAT), @@ -417,9 +419,22 @@ irc_display_server (t_irc_server *server) server->realname); gui_printf (NULL, " server_hostname . . . . . : %s\n", (server->hostname) ? server->hostname : ""); - gui_printf (NULL, " server_command . . . . . . : %s\n", - (server->command && server->command[0]) ? - server->command : ""); + if (server->command && server->command[0]) + string = strdup (server->command); + else + string = NULL; + if (string) + { + if (cfg_log_hide_nickserv_pwd) + irc_hide_password (string, 1); + gui_printf (NULL, " server_command . . . . . . : %s\n", + string); + free (string); + } + else + gui_printf (NULL, " server_command . . . . . . : %s\n", + (server->command && server->command[0]) ? + server->command : ""); gui_printf (NULL, " server_command_delay . . . : %d %s\n", server->command_delay, _("seconds")); diff --git a/weechat/src/irc/irc-send.c b/weechat/src/irc/irc-send.c index 60fbf09c9..2027e5381 100644 --- a/weechat/src/irc/irc-send.c +++ b/weechat/src/irc/irc-send.c @@ -44,6 +44,58 @@ #include "../gui/gui.h" +/* + * irc_hide_password: hide IRC password(s) in a string + */ + +void +irc_hide_password (char *string, int look_for_nickserv) +{ + char *pos_nickserv, *pos, *pos_pwd; + + pos = string; + while (1) + { + if (look_for_nickserv) + { + pos_nickserv = strstr (pos, "nickserv "); + if (!pos_nickserv) + return; + pos = pos_nickserv + 9; + while (pos[0] == ' ') + pos++; + if ((strncmp (pos, "identify ", 9) == 0) + || (strncmp (pos, "register ", 9) == 0)) + pos_pwd = pos + 9; + else + pos_pwd = NULL; + } + else + { + pos_pwd = strstr (pos, "identify "); + if (!pos_pwd) + pos_pwd = strstr (pos, "register "); + if (!pos_pwd) + return; + pos_pwd += 9; + } + + if (pos_pwd) + { + while (pos_pwd[0] == ' ') + pos_pwd++; + + while (pos_pwd[0] && (pos_pwd[0] != ';') && (pos_pwd[0] != ' ') + && (pos_pwd[0] != '"')) + { + pos_pwd[0] = '*'; + pos_pwd++; + } + pos = pos_pwd; + } + } +} + /* * irc_login: login to irc server */ @@ -1189,7 +1241,7 @@ irc_cmd_send_msg (t_irc_server *server, t_irc_channel *channel, t_gui_window *window; t_gui_buffer *buffer; char *pos, *pos_comma; - char *msg_pwd_hidden, *pos_pwd; + char *msg_pwd_hidden; t_irc_channel *ptr_channel; t_irc_nick *ptr_nick; char *string; @@ -1274,20 +1326,7 @@ irc_cmd_send_msg (t_irc_server *server, t_irc_channel *channel, { msg_pwd_hidden = strdup (pos); if (cfg_log_hide_nickserv_pwd) - { - pos_pwd = strstr (msg_pwd_hidden, "identify "); - if (!pos_pwd) - pos_pwd = strstr (msg_pwd_hidden, "register "); - if (pos_pwd) - { - pos_pwd += 9; - while (pos_pwd[0]) - { - pos_pwd[0] = '*'; - pos_pwd++; - } - } - } + irc_hide_password (msg_pwd_hidden, 0); irc_display_prefix (server, server->buffer, PREFIX_SERVER); gui_printf_type (server->buffer, MSG_TYPE_NICK, "%s-%s%s%s- ", diff --git a/weechat/src/irc/irc.h b/weechat/src/irc/irc.h index bd67df0ab..234e97e73 100644 --- a/weechat/src/irc/irc.h +++ b/weechat/src/irc/irc.h @@ -472,6 +472,7 @@ extern void irc_display_server (t_irc_server *ptr_server); /* IRC commands issued by user (irc-send.c) */ extern void irc_login (t_irc_server *); +extern void irc_hide_password (char *, int); extern int irc_cmd_send_admin (t_irc_server *, t_irc_channel *, char *); extern int irc_cmd_send_ame (t_irc_server *, t_irc_channel *, char *); extern int irc_cmd_send_amsg (t_irc_server *, t_irc_channel *, char *);