diff options
Diffstat (limited to 'src/plugins')
-rw-r--r-- | src/plugins/irc/irc-info.c | 11 | ||||
-rw-r--r-- | src/plugins/irc/irc-nick.c | 29 | ||||
-rw-r--r-- | src/plugins/irc/irc-nick.h | 3 |
3 files changed, 42 insertions, 1 deletions
diff --git a/src/plugins/irc/irc-info.c b/src/plugins/irc/irc-info.c index 0ae8ca560..3b45730cb 100644 --- a/src/plugins/irc/irc-info.c +++ b/src/plugins/irc/irc-info.c @@ -79,6 +79,12 @@ irc_info_get_info_cb (void *data, const char *info_name, return str_true; return NULL; } + else if (weechat_strcasecmp (info_name, "irc_is_nick") == 0) + { + if (irc_nick_is_nick (arguments)) + return str_true; + return NULL; + } else if (weechat_strcasecmp (info_name, "irc_nick") == 0) { ptr_server = irc_server_search (arguments); @@ -396,9 +402,12 @@ void irc_info_init () { /* info hooks */ - weechat_hook_info ("irc_is_channel", N_("1 if string is an IRC channel"), + weechat_hook_info ("irc_is_channel", N_("1 if string is a valid IRC channel name"), N_("channel name"), &irc_info_get_info_cb, NULL); + weechat_hook_info ("irc_is_nick", N_("1 if string is a valid IRC nick name"), + N_("nickname"), + &irc_info_get_info_cb, NULL); weechat_hook_info ("irc_nick", N_("get current nick on a server"), N_("server name"), &irc_info_get_info_cb, NULL); diff --git a/src/plugins/irc/irc-nick.c b/src/plugins/irc/irc-nick.c index 576f532d0..29b0b38e2 100644 --- a/src/plugins/irc/irc-nick.c +++ b/src/plugins/irc/irc-nick.c @@ -57,6 +57,35 @@ irc_nick_valid (struct t_irc_channel *channel, struct t_irc_nick *nick) } /* + * irc_nick_is_nick: check if string is a valid nick string (RFC 1459) + * return 1 if string valid nick + * 0 if not a valid nick + */ + +int +irc_nick_is_nick (const char *string) +{ + const char *ptr; + + if (!string || !string[0]) + return 0; + + /* first char must not be a number or hyphen */ + ptr = string; + if (strchr ("0123456789-", *ptr)) + return 0; + + while (ptr && ptr[0]) + { + if (!strchr (IRC_NICK_VALID_CHARS, *ptr)) + return 0; + ptr++; + } + + return 1; +} + +/* * irc_nick_find_color: find a color for a nick (according to nick letters) */ diff --git a/src/plugins/irc/irc-nick.h b/src/plugins/irc/irc-nick.h index adad7d957..f27ab1973 100644 --- a/src/plugins/irc/irc-nick.h +++ b/src/plugins/irc/irc-nick.h @@ -21,6 +21,8 @@ #define __WEECHAT_IRC_NICK_H 1 #define IRC_NICK_DEFAULT_PREFIXES_LIST "@%+~&!-" +#define IRC_NICK_VALID_CHARS "abcdefghijklmnopqrstuvwxyzABCDEFGHI" \ + "JKLMNOPQRSTUVWXYZ0123456789-[]\\`_^{|}" #define IRC_NICK_CHANOWNER 1 #define IRC_NICK_CHANADMIN 2 @@ -61,6 +63,7 @@ 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 (const char *string); extern const char *irc_nick_find_color (const char *nickname); extern void irc_nick_get_gui_infos (struct t_irc_nick *nick, char *prefix, int *prefix_color, |