From e59bbbb40a61379646edddb631f77bebe5dacf31 Mon Sep 17 00:00:00 2001 From: Sebastien Helleu Date: Thu, 25 Mar 2010 10:39:07 +0100 Subject: Add "irc_is_nick" for function info_get to check if a string is a valid IRC nick name (patch #7133) --- ChangeLog | 4 +++- doc/en/autogen/plugin_api/infos.txt | 4 +++- doc/fr/autogen/plugin_api/infos.txt | 4 +++- doc/it/autogen/plugin_api/infos.txt | 4 +++- po/cs.po | 15 ++++++++++----- po/de.po | 15 ++++++++++----- po/es.po | 17 +++++++++++------ po/fr.po | 17 ++++++++++------- po/hu.po | 16 ++++++++++------ po/it.po | 15 ++++++++++----- po/pl.po | 17 +++++++++++------ po/ru.po | 16 ++++++++++------ po/weechat.pot | 13 ++++++++----- src/plugins/irc/irc-info.c | 11 ++++++++++- src/plugins/irc/irc-nick.c | 29 +++++++++++++++++++++++++++++ src/plugins/irc/irc-nick.h | 3 +++ 16 files changed, 144 insertions(+), 56 deletions(-) diff --git a/ChangeLog b/ChangeLog index 865468190..d8edd9c3a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,7 +1,7 @@ WeeChat ChangeLog ================= FlashCode -v0.3.2-dev, 2010-03-24 +v0.3.2-dev, 2010-03-25 Version 0.3.2 (under dev!) @@ -31,6 +31,8 @@ Version 0.3.2 (under dev!) * gui: fix bug with cursor when position is last char of terminal * api: add "version_number" for function info_get to get WeeChat version as number +* api: add "irc_is_nick" for function info_get to check if a string is a valid + IRC nick name (patch #7133) * api: add functions "string_encode_base64" and "string_decode_base64", fix bug with base64 encoding * api: add functions "string_match", "string_has_highlight" and diff --git a/doc/en/autogen/plugin_api/infos.txt b/doc/en/autogen/plugin_api/infos.txt index 32933937c..c674f7485 100644 --- a/doc/en/autogen/plugin_api/infos.txt +++ b/doc/en/autogen/plugin_api/infos.txt @@ -6,7 +6,9 @@ | irc | irc_buffer | get buffer pointer for an IRC server/channel/nick | server,channel,nick (channel and nicks are optional) -| irc | irc_is_channel | 1 if string is an IRC channel | channel name +| irc | irc_is_channel | 1 if string is a valid IRC channel name | channel name + +| irc | irc_is_nick | 1 if string is a valid IRC nick name | nickname | irc | irc_nick | get current nick on a server | server name diff --git a/doc/fr/autogen/plugin_api/infos.txt b/doc/fr/autogen/plugin_api/infos.txt index cead0fda5..3f7c48121 100644 --- a/doc/fr/autogen/plugin_api/infos.txt +++ b/doc/fr/autogen/plugin_api/infos.txt @@ -6,7 +6,9 @@ | irc | irc_buffer | retourne le pointeur vers le tampon pour un serveur/canal/pseudo IRC | serveur,canal,pseudo (canal et pseudo sont optionnels) -| irc | irc_is_channel | 1 si la chaîne est un canal IRC | nom de canal +| irc | irc_is_channel | 1 si la chaîne est un nom de canal IRC valide | nom de canal + +| irc | irc_is_nick | 1 si la chaîne est un pseudo IRC valide | pseudo | irc | irc_nick | retourne le pseudo utilisé actuellement sur un serveur | nom de serveur diff --git a/doc/it/autogen/plugin_api/infos.txt b/doc/it/autogen/plugin_api/infos.txt index e697c3540..caaaa2b54 100644 --- a/doc/it/autogen/plugin_api/infos.txt +++ b/doc/it/autogen/plugin_api/infos.txt @@ -6,7 +6,9 @@ | irc | irc_buffer | ottiene puntatore al buffer per un server/canale/nick IRC | server,canale,nick (canale e nick sono opzionali) -| irc | irc_is_channel | 1 se la stringa è un canale IRC | nome canale +| irc | irc_is_channel | 1 if string is a valid IRC channel name | nome canale + +| irc | irc_is_nick | 1 if string is a valid IRC nick name | nick | irc | irc_nick | ottiene nick corrente su un server | nome server diff --git a/po/cs.po b/po/cs.po index a27536f82..5d7e30d6a 100644 --- a/po/cs.po +++ b/po/cs.po @@ -6,7 +6,7 @@ msgid "" msgstr "" "Project-Id-Version: WeeChat 0.3.2-dev\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2010-03-24 19:36+0100\n" +"POT-Creation-Date: 2010-03-25 10:20+0100\n" "PO-Revision-Date: 2010-03-23 10:19+0100\n" "Last-Translator: Jiri Golembiovsky \n" "Language-Team: weechat-dev \n" @@ -4533,12 +4533,20 @@ msgstr[0] "kanál" msgstr[1] "kanály" msgstr[2] "kanálů" -msgid "1 if string is an IRC channel" +#, fuzzy +msgid "1 if string is a valid IRC channel name" msgstr "1 pokud je řetězec IRC kanál" msgid "channel name" msgstr "jméno kanálu" +#, fuzzy +msgid "1 if string is a valid IRC nick name" +msgstr "1 pokud je řetězec IRC kanál" + +msgid "nickname" +msgstr "přezdívka" + msgid "get current nick on a server" msgstr "získat aktuální přezdívku na serveru" @@ -4554,9 +4562,6 @@ msgstr "IRC host (jako `:nick!name@server.com`)" msgid "get nick color" msgstr "získat barvu barva přezdívky" -msgid "nickname" -msgstr "přezdívka" - msgid "get buffer pointer for an IRC server/channel/nick" msgstr "získat ukazatel bufferu pro IRC server/kanál/přezdívku" diff --git a/po/de.po b/po/de.po index 00725db4a..829c49e91 100644 --- a/po/de.po +++ b/po/de.po @@ -10,7 +10,7 @@ msgid "" msgstr "" "Project-Id-Version: WeeChat 0.3.2-dev\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2010-03-24 19:36+0100\n" +"POT-Creation-Date: 2010-03-25 10:20+0100\n" "PO-Revision-Date: 2010-03-23 15:44+0100\n" "Last-Translator: Nils G \n" "Language-Team: weechat-dev \n" @@ -4734,12 +4734,20 @@ msgid_plural "channels" msgstr[0] "Channel" msgstr[1] "Channels" -msgid "1 if string is an IRC channel" +#, fuzzy +msgid "1 if string is a valid IRC channel name" msgstr "1, falls die Zeichenkette ein IRC-Channel ist" msgid "channel name" msgstr "Channelname" +#, fuzzy +msgid "1 if string is a valid IRC nick name" +msgstr "1, falls die Zeichenkette ein IRC-Channel ist" + +msgid "nickname" +msgstr "Nickname" + msgid "get current nick on a server" msgstr "Aktuellen Nicknamen für den Server erhalten" @@ -4755,9 +4763,6 @@ msgstr "IRC host (in der Form `:nick!name@server.com`)" msgid "get nick color" msgstr "Hole Farbe für Nick" -msgid "nickname" -msgstr "Nickname" - msgid "get buffer pointer for an IRC server/channel/nick" msgstr "hole Buffer Pointer für einen IRC Server/Channel/Nick" diff --git a/po/es.po b/po/es.po index d64b4f3ec..cadd74c0c 100644 --- a/po/es.po +++ b/po/es.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: WeeChat 0.3.2-dev\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2010-03-24 19:36+0100\n" +"POT-Creation-Date: 2010-03-25 10:20+0100\n" "PO-Revision-Date: 2010-03-23 10:20+0100\n" "Last-Translator: Elián Hanisch \n" "Language-Team: weechat-dev \n" @@ -4576,13 +4576,22 @@ msgid_plural "channels" msgstr[0] "canal" msgstr[1] "canales" -msgid "1 if string is an IRC channel" +#, fuzzy +msgid "1 if string is a valid IRC channel name" msgstr "1 si la cadena es un canal IRC" #, fuzzy msgid "channel name" msgstr "canal modo" +#, fuzzy +msgid "1 if string is a valid IRC nick name" +msgstr "1 si la cadena es un canal IRC" + +#, fuzzy +msgid "nickname" +msgstr "[-all] apodo" + msgid "get current nick on a server" msgstr "devuelve el apodo actual en el servidor" @@ -4599,10 +4608,6 @@ msgstr "" msgid "get nick color" msgstr "obtiene el color del apodo" -#, fuzzy -msgid "nickname" -msgstr "[-all] apodo" - #, fuzzy msgid "get buffer pointer for an IRC server/channel/nick" msgstr "devuelve el puntero del buffer de un canal/servidor IRC" diff --git a/po/fr.po b/po/fr.po index ca0c05ba5..412741580 100644 --- a/po/fr.po +++ b/po/fr.po @@ -6,8 +6,8 @@ msgid "" msgstr "" "Project-Id-Version: WeeChat 0.3.2-dev\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2010-03-24 19:36+0100\n" -"PO-Revision-Date: 2010-03-24 19:39+0100\n" +"POT-Creation-Date: 2010-03-25 10:20+0100\n" +"PO-Revision-Date: 2010-03-25 10:24+0100\n" "Last-Translator: FlashCode \n" "Language-Team: weechat-dev \n" "MIME-Version: 1.0\n" @@ -4683,12 +4683,18 @@ msgid_plural "channels" msgstr[0] "canal" msgstr[1] "canaux" -msgid "1 if string is an IRC channel" -msgstr "1 si la chaîne est un canal IRC" +msgid "1 if string is a valid IRC channel name" +msgstr "1 si la chaîne est un nom de canal IRC valide" msgid "channel name" msgstr "nom de canal" +msgid "1 if string is a valid IRC nick name" +msgstr "1 si la chaîne est un pseudo IRC valide" + +msgid "nickname" +msgstr "pseudo" + msgid "get current nick on a server" msgstr "retourne le pseudo utilisé actuellement sur un serveur" @@ -4704,9 +4710,6 @@ msgstr "host IRC (comme `:pseudo!nom@serveur.com`)" msgid "get nick color" msgstr "retourne la couleur du pseudo" -msgid "nickname" -msgstr "pseudo" - msgid "get buffer pointer for an IRC server/channel/nick" msgstr "retourne le pointeur vers le tampon pour un serveur/canal/pseudo IRC" diff --git a/po/hu.po b/po/hu.po index 011afcb81..a4c474ad6 100644 --- a/po/hu.po +++ b/po/hu.po @@ -12,7 +12,7 @@ msgid "" msgstr "" "Project-Id-Version: WeeChat 0.3.2-dev\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2010-03-24 19:36+0100\n" +"POT-Creation-Date: 2010-03-25 10:20+0100\n" "PO-Revision-Date: 2010-03-23 10:20+0100\n" "Last-Translator: Andras Voroskoi \n" "Language-Team: weechat-dev \n" @@ -4409,13 +4409,21 @@ msgstr[0] "%d szoba" msgstr[1] "%d szoba" #, fuzzy -msgid "1 if string is an IRC channel" +msgid "1 if string is a valid IRC channel name" msgstr "felhasználók listája a szobában" #, fuzzy msgid "channel name" msgstr "%d szoba" +#, fuzzy +msgid "1 if string is a valid IRC nick name" +msgstr "felhasználók listája a szobában" + +#, fuzzy +msgid "nickname" +msgstr "[-all] név" + #, fuzzy msgid "get current nick on a server" msgstr "aktuális név megváltoztatása" @@ -4435,10 +4443,6 @@ msgstr "" msgid "get nick color" msgstr "üzenetek színe" -#, fuzzy -msgid "nickname" -msgstr "[-all] név" - #, fuzzy msgid "get buffer pointer for an IRC server/channel/nick" msgstr "szobák listája ahová be akarunk lépni csatlakozás után" diff --git a/po/it.po b/po/it.po index 3ff4f9f0d..084bbdc8a 100644 --- a/po/it.po +++ b/po/it.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: Weechat 0.3.2-dev\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2010-03-24 19:36+0100\n" +"POT-Creation-Date: 2010-03-25 10:20+0100\n" "PO-Revision-Date: 2010-03-24 14:20+0100\n" "Last-Translator: Marco Paolone \n" "Language-Team: weechat-dev \n" @@ -4639,12 +4639,20 @@ msgid_plural "channels" msgstr[0] "canale" msgstr[1] "canali" -msgid "1 if string is an IRC channel" +#, fuzzy +msgid "1 if string is a valid IRC channel name" msgstr "1 se la stringa è un canale IRC" msgid "channel name" msgstr "nome canale" +#, fuzzy +msgid "1 if string is a valid IRC nick name" +msgstr "1 se la stringa è un canale IRC" + +msgid "nickname" +msgstr "nick" + msgid "get current nick on a server" msgstr "ottiene nick corrente su un server" @@ -4660,9 +4668,6 @@ msgstr "host IRC (come `:nick!nome@server.com`)" msgid "get nick color" msgstr "riceve colore del nick" -msgid "nickname" -msgstr "nick" - msgid "get buffer pointer for an IRC server/channel/nick" msgstr "ottiene puntatore al buffer per un server/canale/nick IRC" diff --git a/po/pl.po b/po/pl.po index 871ceac3b..030b025a2 100644 --- a/po/pl.po +++ b/po/pl.po @@ -9,7 +9,7 @@ msgid "" msgstr "" "Project-Id-Version: WeeChat 0.3.0-dev\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2010-03-24 19:36+0100\n" +"POT-Creation-Date: 2010-03-25 10:20+0100\n" "PO-Revision-Date: 2010-03-23 10:20+0100\n" "Last-Translator: Krzysztof Koroscik \n" "Language-Team: Polish\n" @@ -4571,13 +4571,22 @@ msgstr[0] "kanał" msgstr[1] "kanały" msgstr[2] "kanałów" -msgid "1 if string is an IRC channel" +#, fuzzy +msgid "1 if string is a valid IRC channel name" msgstr "1 jeśli ciąg jest w kanale IRC" #, fuzzy msgid "channel name" msgstr "kanał atrybuty" +#, fuzzy +msgid "1 if string is a valid IRC nick name" +msgstr "1 jeśli ciąg jest w kanale IRC" + +#, fuzzy +msgid "nickname" +msgstr "[-all] nick" + msgid "get current nick on a server" msgstr "pobiera aktualny nick z serwera" @@ -4594,10 +4603,6 @@ msgstr "" msgid "get nick color" msgstr "pobiera kolor nicka" -#, fuzzy -msgid "nickname" -msgstr "[-all] nick" - #, fuzzy msgid "get buffer pointer for an IRC server/channel/nick" msgstr "pobiera wskaźnik bufora kanału/serwera IRC" diff --git a/po/ru.po b/po/ru.po index bb8611802..0c1e6cfc8 100644 --- a/po/ru.po +++ b/po/ru.po @@ -6,7 +6,7 @@ msgid "" msgstr "" "Project-Id-Version: WeeChat 0.3.2-dev\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2010-03-24 19:36+0100\n" +"POT-Creation-Date: 2010-03-25 10:20+0100\n" "PO-Revision-Date: 2010-03-23 10:20+0100\n" "Last-Translator: Pavel Shevchuk \n" "Language-Team: weechat-dev \n" @@ -4411,13 +4411,21 @@ msgstr[1] "%d каналов" msgstr[2] "%d каналов" #, fuzzy -msgid "1 if string is an IRC channel" +msgid "1 if string is a valid IRC channel name" msgstr "список ников на канале" #, fuzzy msgid "channel name" msgstr "%d канал" +#, fuzzy +msgid "1 if string is a valid IRC nick name" +msgstr "список ников на канале" + +#, fuzzy +msgid "nickname" +msgstr "[-all] ник" + #, fuzzy msgid "get current nick on a server" msgstr "сменить текущий ник" @@ -4437,10 +4445,6 @@ msgstr "" msgid "get nick color" msgstr "цвет чата" -#, fuzzy -msgid "nickname" -msgstr "[-all] ник" - #, fuzzy msgid "get buffer pointer for an IRC server/channel/nick" msgstr "Список каналов, на которые заходить при соединении с сервером" diff --git a/po/weechat.pot b/po/weechat.pot index 1a82db401..c4d88f53a 100644 --- a/po/weechat.pot +++ b/po/weechat.pot @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2010-03-24 19:36+0100\n" +"POT-Creation-Date: 2010-03-25 10:20+0100\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -3771,12 +3771,18 @@ msgid_plural "channels" msgstr[0] "" msgstr[1] "" -msgid "1 if string is an IRC channel" +msgid "1 if string is a valid IRC channel name" msgstr "" msgid "channel name" msgstr "" +msgid "1 if string is a valid IRC nick name" +msgstr "" + +msgid "nickname" +msgstr "" + msgid "get current nick on a server" msgstr "" @@ -3792,9 +3798,6 @@ msgstr "" msgid "get nick color" msgstr "" -msgid "nickname" -msgstr "" - msgid "get buffer pointer for an IRC server/channel/nick" msgstr "" 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 @@ -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) */ 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, -- cgit v1.2.3