diff options
author | Sebastien Helleu <flashcode@flashtux.org> | 2011-11-12 10:56:52 +0100 |
---|---|---|
committer | Sebastien Helleu <flashcode@flashtux.org> | 2011-11-12 10:56:52 +0100 |
commit | e3b7c8fdb775b76b7c042a74813f32876601c617 (patch) | |
tree | 573e14cedda82f1ab1ccb9593b6f448b07db00d5 | |
parent | 491412b314f6a9db9de5d24daee7196bf5dfbdf5 (diff) | |
download | weechat-e3b7c8fdb775b76b7c042a74813f32876601c617.zip |
irc: add case insensitive string comparison based on casemapping of server (rfc1459, strict-rfc1459, ascii) (bug #34239)
-rw-r--r-- | ChangeLog | 2 | ||||
-rw-r--r-- | src/plugins/irc/irc-bar-item.c | 4 | ||||
-rw-r--r-- | src/plugins/irc/irc-channel.c | 22 | ||||
-rw-r--r-- | src/plugins/irc/irc-channel.h | 9 | ||||
-rw-r--r-- | src/plugins/irc/irc-command.c | 6 | ||||
-rw-r--r-- | src/plugins/irc/irc-completion.c | 12 | ||||
-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-ignore.c | 5 | ||||
-rw-r--r-- | src/plugins/irc/irc-info.c | 3 | ||||
-rw-r--r-- | src/plugins/irc/irc-input.c | 8 | ||||
-rw-r--r-- | src/plugins/irc/irc-mode.c | 3 | ||||
-rw-r--r-- | src/plugins/irc/irc-nick.c | 17 | ||||
-rw-r--r-- | src/plugins/irc/irc-nick.h | 3 | ||||
-rw-r--r-- | src/plugins/irc/irc-notify.c | 10 | ||||
-rw-r--r-- | src/plugins/irc/irc-protocol.c | 96 | ||||
-rw-r--r-- | src/plugins/irc/irc-server.c | 93 | ||||
-rw-r--r-- | src/plugins/irc/irc-server.h | 17 | ||||
-rw-r--r-- | src/plugins/irc/irc-upgrade.c | 3 |
19 files changed, 240 insertions, 82 deletions
@@ -23,6 +23,8 @@ Version 0.3.7 (under dev!) * core: enable background process under Cygwin to connect to servers, fix reconnection problem (bug #34626) * api: add new functions strcasecmp_range and strncasecmp_range +* irc: add case insensitive string comparison based on casemapping of server + (rfc1459, strict-rfc1459, ascii) (bug #34239) * irc: display channel voice notices received in channel buffer (bug #34762), display channel/op notices sent in channel buffer * irc: add option irc.color.mirc_remap to remap mirc colors in messages to diff --git a/src/plugins/irc/irc-bar-item.c b/src/plugins/irc/irc-bar-item.c index fd166842b..3f072542c 100644 --- a/src/plugins/irc/irc-bar-item.c +++ b/src/plugins/irc/irc-bar-item.c @@ -452,7 +452,7 @@ irc_bar_item_input_prompt (void *data, struct t_gui_bar_item *item, && channel && (channel->type == IRC_CHANNEL_TYPE_CHANNEL)) { - ptr_nick = irc_nick_search (channel, server->nick); + ptr_nick = irc_nick_search (server, channel, server->nick); if (ptr_nick) { if (ptr_nick->prefix[0] != ' ') @@ -532,7 +532,7 @@ irc_bar_item_focus_buffer_nicklist (void *data, nick = weechat_hashtable_get (info, "nick"); if (nick) { - ptr_nick = irc_nick_search (ptr_channel, nick); + ptr_nick = irc_nick_search (ptr_server, ptr_channel, nick); if (ptr_nick && ptr_nick->host) { weechat_hashtable_set (info, "irc_host", ptr_nick->host); diff --git a/src/plugins/irc/irc-channel.c b/src/plugins/irc/irc-channel.c index 48d133d45..82d48b4c6 100644 --- a/src/plugins/irc/irc-channel.c +++ b/src/plugins/irc/irc-channel.c @@ -361,7 +361,7 @@ irc_channel_search (struct t_irc_server *server, const char *channel_name) for (ptr_channel = server->channels; ptr_channel; ptr_channel = ptr_channel->next_channel) { - if (weechat_strcasecmp (ptr_channel->name, channel_name) == 0) + if (irc_server_strcasecmp (server, ptr_channel->name, channel_name) == 0) return ptr_channel; } return NULL; @@ -439,7 +439,7 @@ irc_channel_set_away (struct t_irc_server *server, if (channel->type == IRC_CHANNEL_TYPE_CHANNEL) { - ptr_nick = irc_nick_search (channel, nick_name); + ptr_nick = irc_nick_search (server, channel, nick_name); if (ptr_nick) irc_nick_set_away (server, channel, ptr_nick, is_away); } @@ -531,7 +531,8 @@ irc_channel_nick_speaking_rename (struct t_irc_channel *channel, */ struct t_irc_channel_speaking * -irc_channel_nick_speaking_time_search (struct t_irc_channel *channel, +irc_channel_nick_speaking_time_search (struct t_irc_server *server, + struct t_irc_channel *channel, const char *nick_name, int check_time) { @@ -544,7 +545,7 @@ irc_channel_nick_speaking_time_search (struct t_irc_channel *channel, for (ptr_nick = channel->nicks_speaking_time; ptr_nick; ptr_nick = ptr_nick->next_nick) { - if (strcmp (ptr_nick->nick, nick_name) == 0) + if (irc_server_strcasecmp (server, ptr_nick->nick, nick_name) == 0) { if (check_time && (ptr_nick->time_last_message < time_limit)) return NULL; @@ -622,13 +623,15 @@ irc_channel_nick_speaking_time_remove_old (struct t_irc_channel *channel) */ void -irc_channel_nick_speaking_time_add (struct t_irc_channel *channel, +irc_channel_nick_speaking_time_add (struct t_irc_server *server, + struct t_irc_channel *channel, const char *nick_name, time_t time_last_message) { struct t_irc_channel_speaking *ptr_nick, *new_nick; - ptr_nick = irc_channel_nick_speaking_time_search (channel, nick_name, 0); + ptr_nick = irc_channel_nick_speaking_time_search (server, channel, + nick_name, 0); if (ptr_nick) irc_channel_nick_speaking_time_free (channel, ptr_nick); @@ -655,7 +658,8 @@ irc_channel_nick_speaking_time_add (struct t_irc_channel *channel, */ void -irc_channel_nick_speaking_time_rename (struct t_irc_channel *channel, +irc_channel_nick_speaking_time_rename (struct t_irc_server *server, + struct t_irc_channel *channel, const char *old_nick, const char *new_nick) { @@ -663,7 +667,7 @@ irc_channel_nick_speaking_time_rename (struct t_irc_channel *channel, if (channel->nicks_speaking_time) { - ptr_nick = irc_channel_nick_speaking_time_search (channel, old_nick, 0); + ptr_nick = irc_channel_nick_speaking_time_search (server, channel, old_nick, 0); if (ptr_nick) { free (ptr_nick->nick); @@ -749,7 +753,7 @@ irc_channel_display_nick_back_in_pv (struct t_irc_server *server, { if ((ptr_channel->type == IRC_CHANNEL_TYPE_PRIVATE) && ptr_channel->has_quit_server - && (strcmp (ptr_channel->name, (nick) ? nick->name : nickname) == 0)) + && (irc_server_strcasecmp (server, ptr_channel->name, (nick) ? nick->name : nickname) == 0)) { if (weechat_config_boolean (irc_config_look_display_pv_back)) { diff --git a/src/plugins/irc/irc-channel.h b/src/plugins/irc/irc-channel.h index 379fed2cf..79a700a90 100644 --- a/src/plugins/irc/irc-channel.h +++ b/src/plugins/irc/irc-channel.h @@ -102,14 +102,17 @@ extern void irc_channel_nick_speaking_add (struct t_irc_channel *channel, extern void irc_channel_nick_speaking_rename (struct t_irc_channel *channel, const char *old_nick, const char *new_nick); -extern struct t_irc_channel_speaking *irc_channel_nick_speaking_time_search (struct t_irc_channel *channel, +extern struct t_irc_channel_speaking *irc_channel_nick_speaking_time_search (struct t_irc_server *server, + struct t_irc_channel *channel, const char *nick_name, int check_time); extern void irc_channel_nick_speaking_time_remove_old (struct t_irc_channel *channel); -extern void irc_channel_nick_speaking_time_add (struct t_irc_channel *channel, +extern void irc_channel_nick_speaking_time_add (struct t_irc_server *server, + struct t_irc_channel *channel, const char *nick_name, time_t time_last_message); -extern void irc_channel_nick_speaking_time_rename (struct t_irc_channel *channel, +extern void irc_channel_nick_speaking_time_rename (struct t_irc_server *server, + struct t_irc_channel *channel, const char *old_nick, const char *new_nick); extern void irc_channel_rejoin (struct t_irc_server *server, diff --git a/src/plugins/irc/irc-command.c b/src/plugins/irc/irc-command.c index b593c3c0c..ceaa18bd3 100644 --- a/src/plugins/irc/irc-command.c +++ b/src/plugins/irc/irc-command.c @@ -4457,7 +4457,7 @@ irc_command_version (void *data, struct t_gui_buffer *buffer, int argc, if (argc > 1) { if (ptr_channel && (ptr_channel->type == IRC_CHANNEL_TYPE_CHANNEL) - && irc_nick_search (ptr_channel, argv[1])) + && irc_nick_search (ptr_server, ptr_channel, argv[1])) { irc_server_sendf (ptr_server, IRC_SERVER_SEND_OUTQ_PRIO_HIGH, NULL, "PRIVMSG %s :\01VERSION\01", argv[1]); @@ -4612,7 +4612,9 @@ irc_command_wallchops (void *data, struct t_gui_buffer *buffer, int argc, ptr_nick = ptr_nick->next_nick) { if (irc_nick_is_op (ptr_server, ptr_nick) - && (strcmp (ptr_nick->name, ptr_server->nick) != 0)) + && (irc_server_strcasecmp (ptr_server, + ptr_nick->name, + ptr_server->nick) != 0)) { irc_server_sendf (ptr_server, IRC_SERVER_SEND_OUTQ_PRIO_HIGH, NULL, diff --git a/src/plugins/irc/irc-completion.c b/src/plugins/irc/irc-completion.c index b3e705d59..ea8b885ca 100644 --- a/src/plugins/irc/irc-completion.c +++ b/src/plugins/irc/irc-completion.c @@ -257,6 +257,7 @@ irc_completion_channel_cb (void *data, const char *completion_item, void irc_completion_channel_nicks_add_speakers (struct t_gui_completion *completion, + struct t_irc_server *server, struct t_irc_channel *channel, int highlight) { @@ -269,7 +270,7 @@ irc_completion_channel_nicks_add_speakers (struct t_gui_completion *completion, for (i = 0; i < list_size; i++) { nick = weechat_list_string (weechat_list_get (channel->nicks_speaking[highlight], i)); - if (nick && irc_nick_search (channel, nick)) + if (nick && irc_nick_search (server, channel, nick)) { weechat_hook_completion_list_add (completion, nick, @@ -314,12 +315,12 @@ irc_completion_channel_nicks_cb (void *data, const char *completion_item, /* add recent speakers on channel */ if (weechat_config_integer (irc_config_look_nick_completion_smart) == IRC_CONFIG_NICK_COMPLETION_SMART_SPEAKERS) { - irc_completion_channel_nicks_add_speakers (completion, ptr_channel, 0); + irc_completion_channel_nicks_add_speakers (completion, ptr_server, ptr_channel, 0); } /* add nicks whose make highlights on me recently on this channel */ if (weechat_config_integer (irc_config_look_nick_completion_smart) == IRC_CONFIG_NICK_COMPLETION_SMART_SPEAKERS_HIGHLIGHTS) { - irc_completion_channel_nicks_add_speakers (completion, ptr_channel, 1); + irc_completion_channel_nicks_add_speakers (completion, ptr_server, ptr_channel, 1); } /* add self nick at the end */ weechat_hook_completion_list_add (completion, @@ -429,8 +430,9 @@ irc_completion_channel_topic_cb (void *data, const char *completion_item, if (ptr_channel && ptr_channel->topic && ptr_channel->topic[0]) { - if (weechat_strncasecmp (ptr_channel->topic, ptr_channel->name, - strlen (ptr_channel->name)) == 0) + if (irc_server_strncasecmp (ptr_server, ptr_channel->topic, + ptr_channel->name, + strlen (ptr_channel->name)) == 0) { /* * if topic starts with channel name, add another channel name diff --git a/src/plugins/irc/irc-config.c b/src/plugins/irc/irc-config.c index d711ff34d..4f2ba8007 100644 --- a/src/plugins/irc/irc-config.c +++ b/src/plugins/irc/irc-config.c @@ -187,7 +187,8 @@ irc_config_compute_nick_colors () for (ptr_nick = ptr_channel->nicks; ptr_nick; ptr_nick = ptr_nick->next_nick) { - if (weechat_strcasecmp (ptr_nick->name, ptr_server->nick) != 0) + if (irc_server_strcasecmp (ptr_server, ptr_nick->name, + ptr_server->nick) != 0) { if (ptr_nick->color) free (ptr_nick->color); diff --git a/src/plugins/irc/irc-ctcp.c b/src/plugins/irc/irc-ctcp.c index d853058e3..77646b160 100644 --- a/src/plugins/irc/irc-ctcp.c +++ b/src/plugins/irc/irc-ctcp.c @@ -903,7 +903,7 @@ irc_ctcp_recv (struct t_irc_server *server, const char *command, { if (channel) { - ptr_nick = irc_nick_search (channel, nick); + ptr_nick = irc_nick_search (server, channel, nick); irc_channel_nick_speaking_add (channel, nick, @@ -911,7 +911,7 @@ irc_ctcp_recv (struct t_irc_server *server, const char *command, weechat_string_has_highlight (pos_args, server->nick) : 0); irc_channel_nick_speaking_time_remove_old (channel); - irc_channel_nick_speaking_time_add (channel, nick, + irc_channel_nick_speaking_time_add (server, channel, nick, time (NULL)); weechat_printf_tags (channel->buffer, @@ -928,7 +928,7 @@ irc_ctcp_recv (struct t_irc_server *server, const char *command, } else { - nick_is_me = (strcmp (server->nick, nick) == 0); + nick_is_me = (irc_server_strcasecmp (server, server->nick, nick) == 0); ptr_channel = irc_channel_search (server, remote_nick); if (!ptr_channel) { diff --git a/src/plugins/irc/irc-ignore.c b/src/plugins/irc/irc-ignore.c index 4657d12f4..d5aed56c5 100644 --- a/src/plugins/irc/irc-ignore.c +++ b/src/plugins/irc/irc-ignore.c @@ -198,8 +198,11 @@ irc_ignore_check (struct t_irc_server *server, const char *channel, * if nick is the same as server, then we will not ignore * (it is possible when connected to an irc proxy) */ - if (nick && server->nick && (strcmp (server->nick, nick) == 0)) + if (nick && server->nick + && (irc_server_strcasecmp (server, server->nick, nick) == 0)) + { return 0; + } for (ptr_ignore = irc_ignore_list; ptr_ignore; ptr_ignore = ptr_ignore->next_ignore) diff --git a/src/plugins/irc/irc-info.c b/src/plugins/irc/irc-info.c index 2be3bf3e9..f92be37c5 100644 --- a/src/plugins/irc/irc-info.c +++ b/src/plugins/irc/irc-info.c @@ -428,7 +428,8 @@ irc_info_get_infolist_cb (void *data, const char *infolist_name, } if (!pointer && (argc >= 3)) { - pointer = irc_nick_search (ptr_channel, argv[2]); + pointer = irc_nick_search (ptr_server, ptr_channel, + argv[2]); if (!pointer) { weechat_string_free_split (argv); diff --git a/src/plugins/irc/irc-input.c b/src/plugins/irc/irc-input.c index 97d40c4cb..9bae845b8 100644 --- a/src/plugins/irc/irc-input.c +++ b/src/plugins/irc/irc-input.c @@ -54,10 +54,12 @@ irc_input_user_message_display (struct t_gui_buffer *buffer, const char *text) if (ptr_channel) { + ptr_nick = NULL; if (ptr_channel->type == IRC_CHANNEL_TYPE_CHANNEL) - ptr_nick = irc_nick_search (ptr_channel, ptr_server->nick); - else - ptr_nick = NULL; + { + ptr_nick = irc_nick_search (ptr_server, ptr_channel, + ptr_server->nick); + } weechat_printf_tags (buffer, irc_protocol_tags ("privmsg", diff --git a/src/plugins/irc/irc-mode.c b/src/plugins/irc/irc-mode.c index 86fd13290..5dab62551 100644 --- a/src/plugins/irc/irc-mode.c +++ b/src/plugins/irc/irc-mode.c @@ -142,7 +142,8 @@ irc_mode_channel_set (struct t_irc_server *server, argv[current_arg] : NULL; if (ptr_arg) { - ptr_nick = irc_nick_search (channel, ptr_arg); + ptr_nick = irc_nick_search (server, channel, + ptr_arg); if (ptr_nick) { irc_nick_set_mode (server, channel, ptr_nick, diff --git a/src/plugins/irc/irc-nick.c b/src/plugins/irc/irc-nick.c index 9d94e28c3..19c85a086 100644 --- a/src/plugins/irc/irc-nick.c +++ b/src/plugins/irc/irc-nick.c @@ -447,7 +447,7 @@ irc_nick_get_color_for_nicklist (struct t_irc_server *server, if (weechat_config_boolean(irc_config_look_color_nicks_in_nicklist)) { - if (weechat_strcasecmp (nick->name, server->nick) == 0) + if (irc_server_strcasecmp (server, nick->name, server->nick) == 0) return nick_color_self; else return irc_nick_find_color_name (nick->name); @@ -582,7 +582,7 @@ irc_nick_new (struct t_irc_server *server, struct t_irc_channel *channel, int length; /* nick already exists on this channel? */ - ptr_nick = irc_nick_search (channel, nickname); + ptr_nick = irc_nick_search (server, channel, nickname); if (ptr_nick) { /* remove old nick from nicklist */ @@ -616,7 +616,7 @@ irc_nick_new (struct t_irc_server *server, struct t_irc_channel *channel, new_nick->prefix[1] = '\0'; irc_nick_set_prefixes (server, new_nick, prefixes); new_nick->away = away; - if (weechat_strcasecmp (new_nick->name, server->nick) == 0) + if (irc_server_strcasecmp (server, new_nick->name, server->nick) == 0) new_nick->color = strdup (IRC_COLOR_CHAT_NICK_SELF); else new_nick->color = strdup (irc_nick_find_color (new_nick->name)); @@ -655,7 +655,7 @@ irc_nick_change (struct t_irc_server *server, struct t_irc_channel *channel, irc_nick_nicklist_remove (server, channel, nick); /* update nicks speaking */ - nick_is_me = (strcmp (nick->name, server->nick) == 0) ? 1 : 0; + nick_is_me = (irc_server_strcasecmp (server, nick->name, server->nick) == 0) ? 1 : 0; if (!nick_is_me) irc_channel_nick_speaking_rename (channel, nick->name, new_nick); @@ -699,7 +699,7 @@ irc_nick_set_mode (struct t_irc_server *server, struct t_irc_channel *channel, /* add nick in nicklist */ irc_nick_nicklist_add (server, channel, nick); - if (strcmp (nick->name, server->nick) == 0) + if (irc_server_strcasecmp (server, nick->name, server->nick) == 0) weechat_bar_item_update ("input_prompt"); } @@ -772,11 +772,12 @@ irc_nick_free_all (struct t_irc_server *server, struct t_irc_channel *channel) } /* - * irc_nick_search: returns pointer on a nick + * irc_nick_search: search nick in a channel */ struct t_irc_nick * -irc_nick_search (struct t_irc_channel *channel, const char *nickname) +irc_nick_search (struct t_irc_server *server, struct t_irc_channel *channel, + const char *nickname) { struct t_irc_nick *ptr_nick; @@ -786,7 +787,7 @@ irc_nick_search (struct t_irc_channel *channel, const char *nickname) for (ptr_nick = channel->nicks; ptr_nick; ptr_nick = ptr_nick->next_nick) { - if (weechat_strcasecmp (ptr_nick->name, nickname) == 0) + if (irc_server_strcasecmp (server, ptr_nick->name, nickname) == 0) return ptr_nick; } diff --git a/src/plugins/irc/irc-nick.h b/src/plugins/irc/irc-nick.h index f6ee95c9c..b3a31c525 100644 --- a/src/plugins/irc/irc-nick.h +++ b/src/plugins/irc/irc-nick.h @@ -75,7 +75,8 @@ extern void irc_nick_free (struct t_irc_server *server, struct t_irc_nick *nick); extern void irc_nick_free_all (struct t_irc_server *server, struct t_irc_channel *channel); -extern struct t_irc_nick *irc_nick_search (struct t_irc_channel *channel, +extern struct t_irc_nick *irc_nick_search (struct t_irc_server *server, + struct t_irc_channel *channel, const char *nickname); extern void irc_nick_count (struct t_irc_server *server, struct t_irc_channel *channel, int *total, diff --git a/src/plugins/irc/irc-notify.c b/src/plugins/irc/irc-notify.c index bbdb43788..75b7362cd 100644 --- a/src/plugins/irc/irc-notify.c +++ b/src/plugins/irc/irc-notify.c @@ -102,7 +102,7 @@ irc_notify_search (struct t_irc_server *server, const char *nick) for (ptr_notify = server->notify_list; ptr_notify; ptr_notify = ptr_notify->next_notify) { - if (strcmp (ptr_notify->nick, nick) == 0) + if (irc_server_strcasecmp (server, ptr_notify->nick, nick) == 0) return ptr_notify; } @@ -629,7 +629,9 @@ irc_notify_hsignal_cb (void *data, const char *signal, ptr_notify; ptr_notify = ptr_notify->next_notify) { - if (strcmp (ptr_notify->nick, nicks_recv[j]) == 0) + if (irc_server_strcasecmp (ptr_server, + ptr_notify->nick, + nicks_recv[j]) == 0) { irc_notify_set_is_on_server (ptr_notify, 1); ptr_notify->ison_received = 1; @@ -652,7 +654,9 @@ irc_notify_hsignal_cb (void *data, const char *signal, nick_was_sent = 0; for (j = 0; j < num_nicks_sent; j++) { - if (strcmp (nicks_sent[j], ptr_notify->nick) == 0) + if (irc_server_strcasecmp (ptr_server, + nicks_sent[j], + ptr_notify->nick) == 0) { nick_was_sent = 1; break; diff --git a/src/plugins/irc/irc-protocol.c b/src/plugins/irc/irc-protocol.c index 37ad92b61..ec126cb32 100644 --- a/src/plugins/irc/irc-protocol.c +++ b/src/plugins/irc/irc-protocol.c @@ -365,7 +365,7 @@ IRC_PROTOCOL_CALLBACK(generic_error) IRC_PROTOCOL_MIN_ARGS(4); - first_arg = (strcmp (argv[2], server->nick) == 0) ? 3 : 2; + first_arg = (irc_server_strcasecmp (server, argv[2], server->nick) == 0) ? 3 : 2; if ((argv[first_arg][0] != ':') && argv[first_arg + 1]) { @@ -393,7 +393,8 @@ IRC_PROTOCOL_CALLBACK(generic_error) "%s%s%s%s%s%s", weechat_prefix ("network"), (ptr_channel && chan_nick - && (strcmp (chan_nick, ptr_channel->name) == 0)) ? + && (irc_server_strcasecmp (server, chan_nick, + ptr_channel->name) == 0)) ? IRC_COLOR_CHAT_CHANNEL : "", (chan_nick) ? chan_nick : "", IRC_COLOR_RESET, @@ -456,7 +457,7 @@ IRC_PROTOCOL_CALLBACK(join) IRC_PROTOCOL_MIN_ARGS(3); IRC_PROTOCOL_CHECK_HOST; - local_join = (strcmp (nick, server->nick) == 0); + local_join = (irc_server_strcasecmp (server, nick, server->nick) == 0); pos_channel = (argv[2][0] == ':') ? argv[2] + 1 : argv[2]; @@ -502,7 +503,7 @@ IRC_PROTOCOL_CALLBACK(join) { ptr_nick_speaking = ((weechat_config_boolean (irc_config_look_smart_filter)) && (weechat_config_boolean (irc_config_look_smart_filter_join))) ? - irc_channel_nick_speaking_time_search (ptr_channel, nick, 1) : NULL; + irc_channel_nick_speaking_time_search (server, ptr_channel, nick, 1) : NULL; display_host = (local_join) ? weechat_config_boolean (irc_config_look_display_host_join_local) : weechat_config_boolean (irc_config_look_display_host_join); @@ -564,8 +565,8 @@ IRC_PROTOCOL_CALLBACK(kick) if (!ptr_channel) return WEECHAT_RC_OK; - ptr_nick = irc_nick_search (ptr_channel, nick); - ptr_nick_kicked = irc_nick_search (ptr_channel, argv[3]); + ptr_nick = irc_nick_search (server, ptr_channel, nick); + ptr_nick_kicked = irc_nick_search (server, ptr_channel, argv[3]); if (!ignored) { @@ -605,7 +606,7 @@ IRC_PROTOCOL_CALLBACK(kick) } } - if (strcmp (argv[3], server->nick) == 0) + if (irc_server_strcasecmp (server, argv[3], server->nick) == 0) { /* * my nick was kicked => free all nicks, channel is not active any @@ -667,8 +668,8 @@ IRC_PROTOCOL_CALLBACK(kill) for (ptr_channel = server->channels; ptr_channel; ptr_channel = ptr_channel->next_channel) { - ptr_nick = irc_nick_search (ptr_channel, nick); - ptr_nick_killed = irc_nick_search (ptr_channel, argv[2]); + ptr_nick = irc_nick_search (server, ptr_channel, nick); + ptr_nick_killed = irc_nick_search (server, ptr_channel, argv[2]); if (!ignored) { @@ -704,7 +705,7 @@ IRC_PROTOCOL_CALLBACK(kill) } } - if (strcmp (argv[2], server->nick) == 0) + if (irc_server_strcasecmp (server, argv[2], server->nick) == 0) { /* * my nick was killed => free all nicks, channel is not active any @@ -758,7 +759,7 @@ IRC_PROTOCOL_CALLBACK(mode) "MODE %s", ptr_channel->name); } } - ptr_nick = irc_nick_search (ptr_channel, nick); + ptr_nick = irc_nick_search (server, ptr_channel, nick); if (!ignored) { ptr_buffer = (ptr_channel) ? ptr_channel->buffer : server->buffer; @@ -825,7 +826,7 @@ IRC_PROTOCOL_CALLBACK(nick) new_nick = (argv[2][0] == ':') ? argv[2] + 1 : argv[2]; - local_nick = (strcmp (nick, server->nick) == 0) ? 1 : 0; + local_nick = (irc_server_strcasecmp (server, nick, server->nick) == 0) ? 1 : 0; if (local_nick) irc_server_set_nick (server, new_nick); @@ -839,7 +840,7 @@ IRC_PROTOCOL_CALLBACK(nick) { case IRC_CHANNEL_TYPE_PRIVATE: /* rename private window if this is with "old nick" */ - if ((weechat_strcasecmp (ptr_channel->name, nick) == 0) + if ((irc_server_strcasecmp (server, ptr_channel->name, nick) == 0) && !irc_channel_search (server, new_nick)) { free (ptr_channel->name); @@ -859,7 +860,7 @@ IRC_PROTOCOL_CALLBACK(nick) break; case IRC_CHANNEL_TYPE_CHANNEL: /* rename nick in nicklist if found */ - ptr_nick = irc_nick_search (ptr_channel, nick); + ptr_nick = irc_nick_search (server, ptr_channel, nick); if (ptr_nick) { ptr_nick_found = ptr_nick; @@ -892,7 +893,7 @@ IRC_PROTOCOL_CALLBACK(nick) { ptr_nick_speaking = ((weechat_config_boolean (irc_config_look_smart_filter)) && (weechat_config_boolean (irc_config_look_smart_filter_nick))) ? - irc_channel_nick_speaking_time_search (ptr_channel, nick, 1) : NULL; + irc_channel_nick_speaking_time_search (server, ptr_channel, nick, 1) : NULL; weechat_printf_tags (ptr_channel->buffer, irc_protocol_tags (command, (!weechat_config_boolean (irc_config_look_smart_filter) @@ -913,7 +914,7 @@ IRC_PROTOCOL_CALLBACK(nick) } irc_channel_nick_speaking_rename (ptr_channel, nick, new_nick); - irc_channel_nick_speaking_time_rename (ptr_channel, + irc_channel_nick_speaking_time_rename (server, ptr_channel, nick, new_nick); } @@ -999,7 +1000,7 @@ IRC_PROTOCOL_CALLBACK(notice) { /* notice for channel */ ptr_channel = irc_channel_search (server, pos_target); - ptr_nick = irc_nick_search (ptr_channel, nick); + ptr_nick = irc_nick_search (server, ptr_channel, nick); weechat_printf_tags ((ptr_channel) ? ptr_channel->buffer : server->buffer, irc_protocol_tags (command, "notify_message", @@ -1080,7 +1081,7 @@ IRC_PROTOCOL_CALLBACK(notice) * if notice is sent from myself (for example another WeeChat * via relay), then display message of outgoing notice */ - if (nick && strcmp (server->nick, nick) == 0) + if (nick && (irc_server_strcasecmp (server, server->nick, nick) == 0)) { weechat_printf_tags (ptr_buffer, irc_protocol_tags (command, @@ -1180,10 +1181,10 @@ IRC_PROTOCOL_CALLBACK(part) (argv[2][0] == ':') ? argv[2] + 1 : argv[2]); if (ptr_channel) { - ptr_nick = irc_nick_search (ptr_channel, nick); + ptr_nick = irc_nick_search (server, ptr_channel, nick); if (ptr_nick) { - local_part = (strcmp (nick, server->nick) == 0); + local_part = (irc_server_strcasecmp (server, nick, server->nick) == 0); /* display part message */ if (!ignored) @@ -1193,7 +1194,7 @@ IRC_PROTOCOL_CALLBACK(part) { ptr_nick_speaking = ((weechat_config_boolean (irc_config_look_smart_filter)) && (weechat_config_boolean (irc_config_look_smart_filter_quit))) ? - irc_channel_nick_speaking_time_search (ptr_channel, nick, 1) : NULL; + irc_channel_nick_speaking_time_search (server, ptr_channel, nick, 1) : NULL; } display_host = weechat_config_boolean (irc_config_look_display_host_quit); if (pos_comment) @@ -1402,7 +1403,7 @@ IRC_PROTOCOL_CALLBACK(privmsg) } /* other message */ - ptr_nick = irc_nick_search (ptr_channel, nick); + ptr_nick = irc_nick_search (server, ptr_channel, nick); if (ptr_nick && !ptr_nick->host) ptr_nick->host = strdup (address); @@ -1422,13 +1423,13 @@ IRC_PROTOCOL_CALLBACK(privmsg) weechat_string_has_highlight (pos_args, server->nick)); irc_channel_nick_speaking_time_remove_old (ptr_channel); - irc_channel_nick_speaking_time_add (ptr_channel, nick, + irc_channel_nick_speaking_time_add (server, ptr_channel, nick, time (NULL)); } } else { - nick_is_me = (strcmp (server->nick, nick) == 0); + nick_is_me = (irc_server_strcasecmp (server, server->nick, nick) == 0); remote_nick = (nick_is_me) ? argv[2] : nick; @@ -1514,20 +1515,21 @@ IRC_PROTOCOL_CALLBACK(quit) if (ptr_channel->type == IRC_CHANNEL_TYPE_PRIVATE) ptr_nick = NULL; else - ptr_nick = irc_nick_search (ptr_channel, nick); + ptr_nick = irc_nick_search (server, ptr_channel, nick); - if (ptr_nick || (weechat_strcasecmp (ptr_channel->name, nick) == 0)) + if (ptr_nick + || (irc_server_strcasecmp (server, ptr_channel->name, nick) == 0)) { /* display quit message */ if (!irc_ignore_check (server, ptr_channel->name, nick, host)) { - local_quit = (strcmp (nick, server->nick) == 0); + local_quit = (irc_server_strcasecmp (server, nick, server->nick) == 0); ptr_nick_speaking = NULL; if (ptr_channel->type == IRC_CHANNEL_TYPE_CHANNEL) { ptr_nick_speaking = ((weechat_config_boolean (irc_config_look_smart_filter)) && (weechat_config_boolean (irc_config_look_smart_filter_quit))) ? - irc_channel_nick_speaking_time_search (ptr_channel, nick, 1) : NULL; + irc_channel_nick_speaking_time_search (server, ptr_channel, nick, 1) : NULL; } if (ptr_channel->type == IRC_CHANNEL_TYPE_PRIVATE) { @@ -1612,7 +1614,7 @@ IRC_PROTOCOL_CALLBACK(server_mode_reason) IRC_PROTOCOL_MIN_ARGS(3); /* skip nickname if at beginning of server message */ - if (strcmp (server->nick, argv[2]) == 0) + if (irc_server_strcasecmp (server, server->nick, argv[2]) == 0) { pos_mode = argv[3]; pos_args = (argc > 4) ? ((argv_eol[4][0] == ':') ? argv_eol[4] + 1 : argv_eol[4]) : NULL; @@ -1645,7 +1647,7 @@ IRC_PROTOCOL_CALLBACK(numeric) IRC_PROTOCOL_MIN_ARGS(3); - if (weechat_strcasecmp (server->nick, argv[2]) == 0) + if (irc_server_strcasecmp (server, server->nick, argv[2]) == 0) { pos_args = (argc > 3) ? ((argv_eol[3][0] == ':') ? argv_eol[3] + 1 : argv_eol[3]) : NULL; @@ -1696,7 +1698,7 @@ IRC_PROTOCOL_CALLBACK(topic) ((argv_eol[3][0] == ':') ? argv_eol[3] + 1 : argv_eol[3]) : NULL; ptr_channel = irc_channel_search (server, argv[2]); - ptr_nick = irc_nick_search (ptr_channel, nick); + ptr_nick = irc_nick_search (server, ptr_channel, nick); ptr_buffer = (ptr_channel) ? ptr_channel->buffer : server->buffer; if (!ignored) @@ -1855,7 +1857,7 @@ IRC_PROTOCOL_CALLBACK(001) IRC_PROTOCOL_MIN_ARGS(3); - if (strcmp (server->nick, argv[2]) != 0) + if (irc_server_strcasecmp (server, server->nick, argv[2]) != 0) irc_server_set_nick (server, argv[2]); irc_protocol_cb_numeric (server, @@ -1927,7 +1929,7 @@ IRC_PROTOCOL_CALLBACK(001) IRC_PROTOCOL_CALLBACK(005) { char *pos, *pos2, *pos_start, *error, *isupport2; - int length_isupport, length, nick_max_length; + int length_isupport, length, nick_max_length, casemapping; /* * 005 message looks like: @@ -1972,6 +1974,21 @@ IRC_PROTOCOL_CALLBACK(005) pos2[0] = ' '; } + /* save casemapping */ + pos = strstr (argv_eol[3], "CASEMAPPING="); + if (pos) + { + pos += 12; + pos2 = strchr (pos, ' '); + if (pos2) + pos2[0] = '\0'; + casemapping = irc_server_search_casemapping (pos); + if (casemapping >= 0) + server->casemapping = casemapping; + if (pos2) + pos2[0] = ' '; + } + /* save whole message (concatenate to existing isupport, if any) */ pos_start = NULL; pos = strstr (argv_eol[3], " :"); @@ -2950,7 +2967,8 @@ IRC_PROTOCOL_CALLBACK(333) topic_address = NULL; ptr_channel = irc_channel_search (server, argv[3]); - ptr_nick = (ptr_channel) ? irc_nick_search (ptr_channel, topic_nick) : NULL; + ptr_nick = (ptr_channel) ? + irc_nick_search (server, ptr_channel, topic_nick) : NULL; arg_date = (argc > 5) ? 5 : 4; datetime = (time_t)(atol ((argv_eol[arg_date][0] == ':') ? argv_eol[arg_date] + 1 : argv_eol[arg_date])); @@ -3451,7 +3469,8 @@ IRC_PROTOCOL_CALLBACK(352) } ptr_channel = irc_channel_search (server, argv[3]); - ptr_nick = (ptr_channel) ? irc_nick_search (ptr_channel, argv[7]) : NULL; + ptr_nick = (ptr_channel) ? + irc_nick_search (server, ptr_channel, argv[7]) : NULL; /* update host for nick */ if (ptr_nick) @@ -3563,7 +3582,7 @@ IRC_PROTOCOL_CALLBACK(353) /* add or update nick on channel */ if (nickname) { - ptr_nick = irc_nick_search (ptr_channel, nickname); + ptr_nick = irc_nick_search (server, ptr_channel, nickname); away = (ptr_nick && ptr_nick->away) ? 1 : 0; prefixes = (pos_nick > pos_nick_orig) ? weechat_strndup (pos_nick_orig, pos_nick - pos_nick_orig) : NULL; @@ -3690,7 +3709,7 @@ IRC_PROTOCOL_CALLBACK(366) nickname = weechat_infolist_string (infolist, "name"); if (weechat_config_boolean (irc_config_look_color_nicks_in_names)) { - if (weechat_strcasecmp (nickname, server->nick) == 0) + if (irc_server_strcasecmp (server, nickname, server->nick) == 0) strcat (string, IRC_COLOR_CHAT_NICK_SELF); else strcat (string, irc_nick_find_color (nickname)); @@ -4023,7 +4042,8 @@ IRC_PROTOCOL_CALLBACK(437) if (!server->is_connected) { - if ((argc >= 4) && (strcmp (server->nick, argv[3]) == 0)) + if ((argc >= 4) + && (irc_server_strcasecmp (server, server->nick, argv[3]) == 0)) { ptr_buffer = irc_msgbuffer_get_target_buffer (server, NULL, command, NULL, NULL); diff --git a/src/plugins/irc/irc-server.c b/src/plugins/irc/irc-server.c index 6f5c84055..c6811c0f8 100644 --- a/src/plugins/irc/irc-server.c +++ b/src/plugins/irc/irc-server.c @@ -93,6 +93,9 @@ char *irc_server_option_default[IRC_SERVER_NUM_OPTIONS] = "", }; +char *irc_server_casemapping_string[IRC_SERVER_NUM_CASEMAPPING] = +{ "rfc1459", "strict-rfc1459", "ascii" }; + char *irc_server_prefix_modes_default = "qaohvu"; char *irc_server_prefix_chars_default = "~&@%+-"; @@ -158,6 +161,87 @@ irc_server_search_option (const char *option_name) } /* + * irc_server_search_casemapping: search casemapping with string + */ + +int +irc_server_search_casemapping (const char *casemapping) +{ + int i; + + for (i = 0; i < IRC_SERVER_NUM_CASEMAPPING; i++) + { + if (weechat_strcasecmp (irc_server_casemapping_string[i], casemapping) == 0) + return i; + } + + /* casemapping not found */ + return -1; +} + +/* + * irc_server_strcasecmp: case insensitive string comparison on server + * (depends on casemapping) + */ + +int +irc_server_strcasecmp (struct t_irc_server *server, + const char *string1, const char *string2) +{ + int casemapping, rc; + + casemapping = (server) ? server->casemapping : IRC_SERVER_CASEMAPPING_RFC1459; + rc = 0; + switch (casemapping) + { + case IRC_SERVER_CASEMAPPING_RFC1459: + rc = weechat_strcasecmp_range (string1, string2, 30); + break; + case IRC_SERVER_CASEMAPPING_STRICT_RFC1459: + rc = weechat_strcasecmp_range (string1, string2, 29); + break; + case IRC_SERVER_CASEMAPPING_ASCII: + rc = weechat_strcasecmp (string1, string2); + break; + default: + rc = weechat_strcasecmp_range (string1, string2, 30); + break; + } + return rc; +} + +/* + * irc_server_strncasecmp: case insensitive string comparison on server for max + * chars (depends on casemapping) + */ + +int +irc_server_strncasecmp (struct t_irc_server *server, + const char *string1, const char *string2, int max) +{ + int casemapping, rc; + + casemapping = (server) ? server->casemapping : IRC_SERVER_CASEMAPPING_RFC1459; + rc = 0; + switch (casemapping) + { + case IRC_SERVER_CASEMAPPING_RFC1459: + rc = weechat_strncasecmp_range (string1, string2, max, 30); + break; + case IRC_SERVER_CASEMAPPING_STRICT_RFC1459: + rc = weechat_strncasecmp_range (string1, string2, max, 29); + break; + case IRC_SERVER_CASEMAPPING_ASCII: + rc = weechat_strncasecmp (string1, string2, max); + break; + default: + rc = weechat_strncasecmp_range (string1, string2, max, 30); + break; + } + return rc; +} + +/* * irc_server_sasl_enabled: return 1 if SASL is enabled on server * 0 if SASL is NOT enabled on server */ @@ -634,6 +718,7 @@ irc_server_alloc (const char *name) new_server->prefix_modes = NULL; new_server->prefix_chars = NULL; new_server->nick_max_length = 0; + new_server->casemapping = IRC_SERVER_CASEMAPPING_RFC1459; new_server->reconnect_delay = 0; new_server->reconnect_start = 0; new_server->command_time = 0; @@ -4079,6 +4164,7 @@ irc_server_hdata_server_cb (void *data, const char *hdata_name) WEECHAT_HDATA_VAR(struct t_irc_server, prefix_modes, STRING, NULL); WEECHAT_HDATA_VAR(struct t_irc_server, prefix_chars, STRING, NULL); WEECHAT_HDATA_VAR(struct t_irc_server, nick_max_length, INTEGER, NULL); + WEECHAT_HDATA_VAR(struct t_irc_server, casemapping, INTEGER, NULL); WEECHAT_HDATA_VAR(struct t_irc_server, reconnect_delay, INTEGER, NULL); WEECHAT_HDATA_VAR(struct t_irc_server, reconnect_start, TIME, NULL); WEECHAT_HDATA_VAR(struct t_irc_server, command_time, TIME, NULL); @@ -4266,6 +4352,10 @@ irc_server_add_to_infolist (struct t_infolist *infolist, return 0; if (!weechat_infolist_new_var_integer (ptr_item, "nick_max_length", server->nick_max_length)) return 0; + if (!weechat_infolist_new_var_integer (ptr_item, "casemapping", server->casemapping)) + return 0; + if (!weechat_infolist_new_var_string (ptr_item, "casemapping_string", irc_server_casemapping_string[server->casemapping])) + return 0; if (!weechat_infolist_new_var_integer (ptr_item, "reconnect_delay", server->reconnect_delay)) return 0; if (!weechat_infolist_new_var_time (ptr_item, "reconnect_start", server->reconnect_start)) @@ -4568,6 +4658,9 @@ irc_server_print_log () weechat_log_printf (" prefix_modes . . . . : '%s'", ptr_server->prefix_modes); weechat_log_printf (" prefix_chars . . . . : '%s'", ptr_server->prefix_chars); weechat_log_printf (" nick_max_length. . . : %d", ptr_server->nick_max_length); + weechat_log_printf (" casemapping. . . . . : %d (%s)", + ptr_server->casemapping, + irc_server_casemapping_string[ptr_server->casemapping]); weechat_log_printf (" reconnect_delay. . . : %d", ptr_server->reconnect_delay); weechat_log_printf (" reconnect_start. . . : %ld", ptr_server->reconnect_start); weechat_log_printf (" command_time . . . . : %ld", ptr_server->command_time); diff --git a/src/plugins/irc/irc-server.h b/src/plugins/irc/irc-server.h index 67d431829..698d89e29 100644 --- a/src/plugins/irc/irc-server.h +++ b/src/plugins/irc/irc-server.h @@ -102,6 +102,16 @@ enum t_irc_server_option #define IRC_SERVER_SEND_OUTQ_PRIO_LOW 2 #define IRC_SERVER_SEND_RETURN_HASHTABLE 4 +/* casemapping (string comparisons for nicks/channels) */ +enum t_irc_server_casemapping +{ + IRC_SERVER_CASEMAPPING_RFC1459 = 0, /* A-Z [ \ ] ^ ==> a-z { | } ~ */ + IRC_SERVER_CASEMAPPING_STRICT_RFC1459, /* A-Z [ \ ] ==> a-z { | } */ + IRC_SERVER_CASEMAPPING_ASCII, /* A-Z ==> a-z */ + /* number of casemapping */ + IRC_SERVER_NUM_CASEMAPPING, +}; + /* output queue of messages to server (for sending slowly to server) */ struct t_irc_outqueue @@ -156,6 +166,7 @@ struct t_irc_server char *prefix_modes; /* prefix modes from msg 005 (eg "aohv") */ char *prefix_chars; /* prefix chars from msg 005 (eg "&@%+") */ int nick_max_length; /* max lenth of nick (from msg 005) */ + int casemapping; /* casemapping from msg 005 */ int reconnect_delay; /* current reconnect delay (growing) */ time_t reconnect_start; /* this time + delay = reconnect time */ time_t command_time; /* this time + command_delay = time to */ @@ -208,6 +219,12 @@ extern char *irc_server_option_default[]; extern int irc_server_valid (struct t_irc_server *server); extern int irc_server_search_option (const char *option_name); +extern int irc_server_search_casemapping (const char *casemapping); +extern int irc_server_strcasecmp (struct t_irc_server *server, + const char *string1, const char *string2); +extern int irc_server_strncasecmp (struct t_irc_server *server, + const char *string1, const char *string2, + int max); extern int irc_server_sasl_enabled (struct t_irc_server *server); extern char *irc_server_get_name_without_port (const char *name); extern void irc_server_set_addresses (struct t_irc_server *server, diff --git a/src/plugins/irc/irc-upgrade.c b/src/plugins/irc/irc-upgrade.c index 231421066..00d40b3e7 100644 --- a/src/plugins/irc/irc-upgrade.c +++ b/src/plugins/irc/irc-upgrade.c @@ -446,7 +446,8 @@ irc_upgrade_read_cb (void *data, break; snprintf (option_name, sizeof (option_name), "nick_speaking_time_time_%05d", index); - irc_channel_nick_speaking_time_add (irc_upgrade_current_channel, + irc_channel_nick_speaking_time_add (irc_upgrade_current_server, + irc_upgrade_current_channel, nick, weechat_infolist_time (infolist, option_name)); |