1
0
mirror of https://github.com/weechat/weechat.git synced 2026-06-25 20:36:38 +02:00

Add "irc_is_nick" for function info_get to check if a string is a valid IRC nick name (patch #7133)

This commit is contained in:
Sebastien Helleu
2010-03-25 10:39:07 +01:00
parent 96e6ae3fc3
commit e59bbbb40a
16 changed files with 144 additions and 56 deletions
+10 -1
View File
@@ -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);
+29
View File
@@ -56,6 +56,35 @@ irc_nick_valid (struct t_irc_channel *channel, struct t_irc_nick *nick)
return 0;
}
/*
* 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)
*/
+3
View File
@@ -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,