diff options
author | Sébastien Helleu <flashcode@flashtux.org> | 2023-08-24 09:05:35 +0200 |
---|---|---|
committer | Sébastien Helleu <flashcode@flashtux.org> | 2023-08-24 09:24:51 +0200 |
commit | 6aa66b536373fa4c07cd542cf6ce9ffcd771cb83 (patch) | |
tree | d4485a37df5c63406c10f5399c8daccf9d280919 /src/plugins/irc | |
parent | c2426e88c9583fab1d58d7d26e3bbe9d500ea570 (diff) | |
download | weechat-6aa66b536373fa4c07cd542cf6ce9ffcd771cb83.zip |
irc: compute color in case insensitive way (closes #194)
Reintroduce infos "irc_nick_color" and "irc_nick_color_name" (that were
marked deprecated since version 1.5).
A server name is added in the two infos and is optional, for backward
compatibility.
Diffstat (limited to 'src/plugins/irc')
-rw-r--r-- | src/plugins/irc/irc-config.c | 3 | ||||
-rw-r--r-- | src/plugins/irc/irc-ctcp.c | 6 | ||||
-rw-r--r-- | src/plugins/irc/irc-info.c | 54 | ||||
-rw-r--r-- | src/plugins/irc/irc-nick.c | 39 | ||||
-rw-r--r-- | src/plugins/irc/irc-nick.h | 9 | ||||
-rw-r--r-- | src/plugins/irc/irc-protocol.c | 21 |
6 files changed, 99 insertions, 33 deletions
diff --git a/src/plugins/irc/irc-config.c b/src/plugins/irc/irc-config.c index 3a90efdfa..a3b25ac91 100644 --- a/src/plugins/irc/irc-config.c +++ b/src/plugins/irc/irc-config.c @@ -246,7 +246,8 @@ irc_config_compute_nick_colors () { if (ptr_nick->color) free (ptr_nick->color); - ptr_nick->color = irc_nick_find_color (ptr_nick->name); + ptr_nick->color = irc_nick_find_color (ptr_server, + ptr_nick->name); } } if (ptr_channel->pv_remote_nick_color) diff --git a/src/plugins/irc/irc-ctcp.c b/src/plugins/irc/irc-ctcp.c index c5568787c..a46c8bd86 100644 --- a/src/plugins/irc/irc-ctcp.c +++ b/src/plugins/irc/irc-ctcp.c @@ -1241,7 +1241,7 @@ irc_ctcp_recv (struct t_irc_server *server, time_t date, if (ptr_nick) nick_color = strdup (ptr_nick->color); else if (nick) - nick_color = irc_nick_find_color (nick); + nick_color = irc_nick_find_color (server, nick); else nick_color = strdup (IRC_COLOR_CHAT_NICK); if (irc_server_prefix_char_statusmsg (server, target[0])) @@ -1336,7 +1336,9 @@ irc_ctcp_recv (struct t_irc_server *server, time_t date, "%s%s%s%s%s%s", weechat_prefix ("action"), (nick_is_me) ? - IRC_COLOR_CHAT_NICK_SELF : irc_nick_color_for_pv (ptr_channel, nick), + IRC_COLOR_CHAT_NICK_SELF : irc_nick_color_for_pv (server, + ptr_channel, + nick), nick, (pos_args) ? IRC_COLOR_RESET : "", (pos_args) ? " " : "", diff --git a/src/plugins/irc/irc-info.c b/src/plugins/irc/irc-info.c index a95d95f1f..e3318d416 100644 --- a/src/plugins/irc/irc-info.c +++ b/src/plugins/irc/irc-info.c @@ -197,6 +197,10 @@ irc_info_info_irc_nick_color_cb (const void *pointer, void *data, const char *info_name, const char *arguments) { + char *pos_comma, *server; + const char *pos_nick; + struct t_irc_server *ptr_server; + /* make C compiler happy */ (void) pointer; (void) data; @@ -205,7 +209,21 @@ irc_info_info_irc_nick_color_cb (const void *pointer, void *data, if (!arguments || !arguments[0]) return NULL; - return irc_nick_find_color (arguments); + ptr_server = NULL; + pos_nick = arguments; + pos_comma = strchr (arguments, ','); + if (pos_comma) + { + pos_nick = pos_comma + 1; + server = weechat_strndup (arguments, pos_comma - arguments); + if (server) + { + ptr_server = irc_server_search (server); + free (server); + } + } + + return irc_nick_find_color (ptr_server, pos_nick); } /* @@ -217,6 +235,10 @@ irc_info_info_irc_nick_color_name_cb (const void *pointer, void *data, const char *info_name, const char *arguments) { + char *pos_comma, *server; + const char *pos_nick; + struct t_irc_server *ptr_server; + /* make C compiler happy */ (void) pointer; (void) data; @@ -225,7 +247,21 @@ irc_info_info_irc_nick_color_name_cb (const void *pointer, void *data, if (!arguments || !arguments[0]) return NULL; - return irc_nick_find_color_name (arguments); + ptr_server = NULL; + pos_nick = arguments; + pos_comma = strchr (arguments, ','); + if (pos_comma) + { + pos_nick = pos_comma + 1; + server = weechat_strndup (arguments, pos_comma - arguments); + if (server) + { + ptr_server = irc_server_search (server); + free (server); + } + } + + return irc_nick_find_color_name (ptr_server, pos_nick); } /* @@ -1223,15 +1259,17 @@ irc_info_init () &irc_info_info_irc_nick_from_host_cb, NULL, NULL); weechat_hook_info ( "irc_nick_color", - N_("get nick color code " - "(*deprecated* since version 1.5, replaced by \"nick_color\")"), - N_("nickname"), + N_("get nick color code (nick is first converted to lower case, " + "following the value of CASEMAPPING on the server, " + "defaulting to \"rfc1459\" if the server is not given)"), + N_("server,nickname (server is optional)"), &irc_info_info_irc_nick_color_cb, NULL, NULL); weechat_hook_info ( "irc_nick_color_name", - N_("get nick color name " - "(*deprecated* since version 1.5, replaced by \"nick_color_name\")"), - N_("nickname"), + N_("get nick color name (nick is first converted to lower case, " + "following the value of CASEMAPPING on the server, " + "defaulting to \"rfc1459\" if the server is not given)"), + N_("server,nickname (server is optional)"), &irc_info_info_irc_nick_color_name_cb, NULL, NULL); weechat_hook_info ( "irc_buffer", diff --git a/src/plugins/irc/irc-nick.c b/src/plugins/irc/irc-nick.c index 509171af7..f593c9312 100644 --- a/src/plugins/irc/irc-nick.c +++ b/src/plugins/irc/irc-nick.c @@ -139,9 +139,17 @@ irc_nick_is_nick (struct t_irc_server *server, const char *string) */ char * -irc_nick_find_color (const char *nickname) +irc_nick_find_color (struct t_irc_server *server, const char *nickname) { - return weechat_info_get ("nick_color", nickname); + char *nickname_lower, *result; + + nickname_lower = irc_server_string_tolower (server, nickname); + if (!nickname_lower) + return NULL; + + result = weechat_info_get ("nick_color", nickname_lower); + free (nickname_lower); + return result; } /* @@ -151,9 +159,17 @@ irc_nick_find_color (const char *nickname) */ char * -irc_nick_find_color_name (const char *nickname) +irc_nick_find_color_name (struct t_irc_server *server, const char *nickname) { - return weechat_info_get ("nick_color_name", nickname); + char *nickname_lower, *result; + + nickname_lower = irc_server_string_tolower (server, nickname); + if (!nickname_lower) + return NULL; + + result = weechat_info_get ("nick_color_name", nickname_lower); + free (nickname_lower); + return result; } /* @@ -397,7 +413,7 @@ irc_nick_get_color_for_nicklist (struct t_irc_server *server, if (irc_server_strcasecmp (server, nick->name, server->nick) == 0) return strdup (nick_color_self); else - return irc_nick_find_color_name (nick->name); + return irc_nick_find_color_name (server, nick->name); } return strdup (nick_color_bar_fg); @@ -595,7 +611,7 @@ irc_nick_new (struct t_irc_server *server, struct t_irc_channel *channel, if (irc_server_strcasecmp (server, new_nick->name, server->nick) == 0) new_nick->color = strdup (IRC_COLOR_CHAT_NICK_SELF); else - new_nick->color = irc_nick_find_color (new_nick->name); + new_nick->color = irc_nick_find_color (server, new_nick->name); /* add nick to end of list */ new_nick->prev_nick = channel->last_nick; @@ -644,7 +660,7 @@ irc_nick_change (struct t_irc_server *server, struct t_irc_channel *channel, if (nick_is_me) nick->color = strdup (IRC_COLOR_CHAT_NICK_SELF); else - nick->color = irc_nick_find_color (nick->name); + nick->color = irc_nick_find_color (server, nick->name); /* add nick in nicklist */ irc_nick_nicklist_add (server, channel, nick); @@ -964,7 +980,7 @@ irc_nick_as_prefix (struct t_irc_server *server, struct t_irc_nick *nick, else if (nick) color = strdup (nick->color); else if (nickname) - color = irc_nick_find_color (nickname); + color = irc_nick_find_color (server, nickname); else color = strdup (IRC_COLOR_CHAT_NICK); @@ -1007,7 +1023,7 @@ irc_nick_color_for_msg (struct t_irc_server *server, int server_message, { return IRC_COLOR_CHAT_NICK_SELF; } - color_found = irc_nick_find_color (nickname); + color_found = irc_nick_find_color (server, nickname); index_color = (index_color + 1) % 16; snprintf (color[index_color], sizeof (color[index_color]), "%s", @@ -1025,12 +1041,13 @@ irc_nick_color_for_msg (struct t_irc_server *server, int server_message, */ const char * -irc_nick_color_for_pv (struct t_irc_channel *channel, const char *nickname) +irc_nick_color_for_pv (struct t_irc_server *server, + struct t_irc_channel *channel, const char *nickname) { if (weechat_config_boolean (irc_config_look_color_pv_nick_like_channel)) { if (!channel->pv_remote_nick_color) - channel->pv_remote_nick_color = irc_nick_find_color (nickname); + channel->pv_remote_nick_color = irc_nick_find_color (server, nickname); if (channel->pv_remote_nick_color) return channel->pv_remote_nick_color; } diff --git a/src/plugins/irc/irc-nick.h b/src/plugins/irc/irc-nick.h index de647386c..a9b649eb6 100644 --- a/src/plugins/irc/irc-nick.h +++ b/src/plugins/irc/irc-nick.h @@ -49,8 +49,10 @@ struct t_irc_nick extern int irc_nick_valid (struct t_irc_channel *channel, struct t_irc_nick *nick); extern int irc_nick_is_nick (struct t_irc_server *server, const char *string); -extern char *irc_nick_find_color (const char *nickname); -extern char *irc_nick_find_color_name (const char *nickname); +extern char *irc_nick_find_color (struct t_irc_server *server, + const char *nickname); +extern char *irc_nick_find_color_name (struct t_irc_server *server, + const char *nickname); extern void irc_nick_set_host (struct t_irc_nick *nick, const char *host); extern int irc_nick_is_op (struct t_irc_server *server, struct t_irc_nick *nick); @@ -103,7 +105,8 @@ extern const char *irc_nick_color_for_msg (struct t_irc_server *server, int server_message, struct t_irc_nick *nick, const char *nickname); -extern const char * irc_nick_color_for_pv (struct t_irc_channel *channel, +extern const char * irc_nick_color_for_pv (struct t_irc_server *server, + struct t_irc_channel *channel, const char *nickname); extern char *irc_nick_default_ban_mask (struct t_irc_nick *nick); extern struct t_hdata *irc_nick_hdata_nick_cb (const void *pointer, diff --git a/src/plugins/irc/irc-protocol.c b/src/plugins/irc/irc-protocol.c index c5fb1e2a4..048d47ffc 100644 --- a/src/plugins/irc/irc-protocol.c +++ b/src/plugins/irc/irc-protocol.c @@ -2310,8 +2310,8 @@ IRC_PROTOCOL_CALLBACK(nick) { if (weechat_config_boolean (irc_config_look_color_pv_nick_like_channel)) { - old_color = irc_nick_find_color (nick); - new_color = irc_nick_find_color (params[0]); + old_color = irc_nick_find_color (server, nick); + new_color = irc_nick_find_color (server, params[0]); } else { @@ -3190,6 +3190,7 @@ IRC_PROTOCOL_CALLBACK(privmsg) else { color = irc_nick_find_color_name ( + server, (ptr_nick) ? ptr_nick->name : nick); str_color = irc_color_for_tags (color); if (color) @@ -3297,7 +3298,7 @@ IRC_PROTOCOL_CALLBACK(privmsg) { if (weechat_config_boolean (irc_config_look_color_pv_nick_like_channel)) { - color = irc_nick_find_color_name (nick); + color = irc_nick_find_color_name (server, nick); str_color = irc_color_for_tags (color); if (color) free (color); @@ -3336,7 +3337,9 @@ IRC_PROTOCOL_CALLBACK(privmsg) irc_nick_as_prefix ( server, NULL, nick, (nick_is_me) ? - IRC_COLOR_CHAT_NICK_SELF : irc_nick_color_for_pv (ptr_channel, nick)), + IRC_COLOR_CHAT_NICK_SELF : irc_nick_color_for_pv (server, + ptr_channel, + nick)), (msg_args2) ? msg_args2 : msg_args); if (msg_args2) free (msg_args2); @@ -3429,7 +3432,8 @@ IRC_PROTOCOL_CALLBACK(quit) _("%s%s%s%s%s%s%s%s%s%s has quit %s(%s%s%s)"), weechat_prefix ("quit"), (ptr_channel->type == IRC_CHANNEL_TYPE_PRIVATE) ? - irc_nick_color_for_pv (ptr_channel, nick) : irc_nick_color_for_msg (server, 1, ptr_nick, nick), + irc_nick_color_for_pv (server, ptr_channel, nick) : + irc_nick_color_for_msg (server, 1, ptr_nick, nick), nick, IRC_COLOR_CHAT_DELIMITERS, (display_host) ? " (" : "", @@ -3463,7 +3467,8 @@ IRC_PROTOCOL_CALLBACK(quit) _("%s%s%s%s%s%s%s%s%s%s has quit"), weechat_prefix ("quit"), (ptr_channel->type == IRC_CHANNEL_TYPE_PRIVATE) ? - irc_nick_color_for_pv (ptr_channel, nick) : irc_nick_color_for_msg (server, 1, ptr_nick, nick), + irc_nick_color_for_pv (server, ptr_channel, nick) : + irc_nick_color_for_msg (server, 1, ptr_nick, nick), nick, IRC_COLOR_CHAT_DELIMITERS, (display_host) ? " (" : "", @@ -6292,7 +6297,7 @@ IRC_PROTOCOL_CALLBACK(353) } else { - color = irc_nick_find_color (nickname); + color = irc_nick_find_color (server, nickname); weechat_string_dyn_concat (str_nicks, color, -1); if (color) free (color); @@ -6551,7 +6556,7 @@ IRC_PROTOCOL_CALLBACK(366) } else { - color = irc_nick_find_color (nickname); + color = irc_nick_find_color (server, nickname); weechat_string_dyn_concat (str_nicks, color, -1); if (color) free (color); |