From a4d1dfa8f436366dbe6544ae7480ba8986f81a05 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Helleu?= Date: Sat, 5 Mar 2016 10:59:37 +0100 Subject: [PATCH] relay: do not execute any command received from an irc relay client (closes #699) --- ChangeLog.asciidoc | 2 + doc/en/weechat_plugin_api.en.asciidoc | 19 ++++--- doc/fr/weechat_plugin_api.fr.asciidoc | 21 ++++---- doc/it/weechat_plugin_api.it.asciidoc | 22 +++++---- doc/ja/weechat_plugin_api.ja.asciidoc | 20 +++++--- src/plugins/irc/irc-input.c | 71 +++++++++++++++++---------- src/plugins/relay/irc/relay-irc.c | 24 +++++---- 7 files changed, 109 insertions(+), 70 deletions(-) diff --git a/ChangeLog.asciidoc b/ChangeLog.asciidoc index 0e39db9d4..72607e8fa 100644 --- a/ChangeLog.asciidoc +++ b/ChangeLog.asciidoc @@ -42,6 +42,8 @@ https://weechat.org/files/releasenotes/ReleaseNotes-devel.html[release notes] keep_eol is 2 and the string ends with separators * irc: add missing completion "*" for target in command /msg * irc: fix /msg command with multiple targets including "*" +* relay: do not execute any command received in a PRIVMSG message from an irc + relay client (issue #699) * relay: fix the max number of clients connected on a port, allow value 0 for "no limit" (issue #669) * relay: fix decoding of multiple frames in a single websocket message, diff --git a/doc/en/weechat_plugin_api.en.asciidoc b/doc/en/weechat_plugin_api.en.asciidoc index c4a87d81a..5d7ecc68d 100644 --- a/doc/en/weechat_plugin_api.en.asciidoc +++ b/doc/en/weechat_plugin_api.en.asciidoc @@ -8834,7 +8834,7 @@ weechat.hook_signal_send("python_script_remove", WEECHAT_HOOK_SIGNAL_STRING, [[signal_irc_input_send]] ===== Signal irc_input_send -_WeeChat ≥ 0.3.4._ +_WeeChat ≥ 0.3.4, updated in 1.5._ The signal "irc_input_send" can be sent to simulate input in an irc buffer (server, channel or private). @@ -8845,9 +8845,12 @@ Argument is a string with following format: * semicolon * channel name (optional) * semicolon -* flags used when sending message (optional, default is 1): -** '1': queue with high priority (like user messages) -** '2': queue with low priority (like messages automatically sent by WeeChat) +* comma-separated list of options (optional): +** 'priority_high': queue with high priority (like user messages); this is the + default priority +** 'priority_low': queue with low priority (like messages automatically sent by + WeeChat) +** 'user_message': force user message (don't execute a command) * semicolon * comma-separated list of tags used when sending message (optional) * semicolon @@ -8859,11 +8862,11 @@ C examples: ---- /* say "Hello!" on freenode server, #weechat channel */ weechat_hook_signal_send ("irc_input_send", WEECHAT_HOOK_SIGNAL_STRING, - "freenode;#weechat;1;;Hello!"); + "freenode;#weechat;priority_high,user_message;;Hello!"); /* send command "/whois FlashCode" on freenode server, with low priority */ weechat_hook_signal_send ("irc_input_send", WEECHAT_HOOK_SIGNAL_STRING, - "freenode;;2;;/whois FlashCode"); + "freenode;;priority_low;;/whois FlashCode"); ---- Script (Python): @@ -8872,11 +8875,11 @@ Script (Python): ---- # say "Hello!" on freenode server, #weechat channel weechat.hook_signal_send("irc_input_send", weechat.WEECHAT_HOOK_SIGNAL_STRING, - "freenode;#weechat;1;;Hello!") + "freenode;#weechat;priority_high,user_message;;Hello!") # send command "/whois FlashCode" on freenode server, with low priority weechat.hook_signal_send("irc_input_send", weechat.WEECHAT_HOOK_SIGNAL_STRING, - "freenode;;2;;/whois FlashCode") + "freenode;;priority_low;;/whois FlashCode") ---- ==== hook_hsignal diff --git a/doc/fr/weechat_plugin_api.fr.asciidoc b/doc/fr/weechat_plugin_api.fr.asciidoc index 2898dbc2e..ff5ca9fa4 100644 --- a/doc/fr/weechat_plugin_api.fr.asciidoc +++ b/doc/fr/weechat_plugin_api.fr.asciidoc @@ -8991,7 +8991,7 @@ weechat.hook_signal_send("python_script_remove", WEECHAT_HOOK_SIGNAL_STRING, [[signal_irc_input_send]] ===== Signal irc_input_send -_WeeChat ≥ 0.3.4._ +_WeeChat ≥ 0.3.4, mis à jour dans la 1.5._ Le signal "irc_input_send" peut être envoyé pour simuler une entrée de texte dans un tampon irc (serveur, canal ou privé). @@ -9002,11 +9002,12 @@ Le paramètre est une chaîne avec le format suivant : * point-virgule * nom de canal (optionnel) * point-virgule -* drapeaux utilisés lors de l'envoi du message (optionnel, 1 par - défaut) : -** '1' : file d'attente avec haute priorité (comme les messages utilisateur) -** '2' : file d'attente avec basse priorité (comme les messages envoyés - automatiquement par WeeChat) +* liste d'options séparées par des virgules (optionnel) : +** 'priority_high' : file d'attente avec haute priorité (comme les messages + utilisateur) ; c'est la priorité par défaut +** 'priority_low' : file d'attente avec basse priorité (comme les messages + envoyés automatiquement par WeeChat) +** 'user_message' : forcer un message utilisateur (ne pas exécuter de commande) * point-virgule * liste d'étiquettes (séparées par des virgules) utilisées lors de l'envoi du message (optionnel) @@ -9019,11 +9020,11 @@ Exemples en C : ---- /* dis "Bonjour !" sur le serveur freenode, canal #weechat */ weechat_hook_signal_send ("irc_input_send", WEECHAT_HOOK_SIGNAL_STRING, - "freenode;#weechat;1;;Bonjour !"); + "freenode;#weechat;priority_high,user_message;;Bonjour !"); /* envoie la commande "/whois FlashCode" sur le canal freenode, en basse priorité */ weechat_hook_signal_send ("irc_input_send", WEECHAT_HOOK_SIGNAL_STRING, - "freenode;;2;;/whois FlashCode"); + "freenode;;priority_low;;/whois FlashCode"); ---- Script (Python) : @@ -9032,11 +9033,11 @@ Script (Python) : ---- # dis "Bonjour !" sur le serveur freenode, canal #weechat weechat.hook_signal_send("irc_input_send", weechat.WEECHAT_HOOK_SIGNAL_STRING, - "freenode;#weechat;1;;Bonjour !") + "freenode;#weechat;priority_high,user_message;;Bonjour !") # envoie la commande "/whois FlashCode" sur le canal freenode, en basse priorité weechat.hook_signal_send("irc_input_send", weechat.WEECHAT_HOOK_SIGNAL_STRING, - "freenode;;2;;/whois FlashCode") + "freenode;;priority_low;;/whois FlashCode") ---- ==== hook_hsignal diff --git a/doc/it/weechat_plugin_api.it.asciidoc b/doc/it/weechat_plugin_api.it.asciidoc index af24643fd..134171f1a 100644 --- a/doc/it/weechat_plugin_api.it.asciidoc +++ b/doc/it/weechat_plugin_api.it.asciidoc @@ -9115,7 +9115,8 @@ weechat.hook_signal_send("python_script_remove", WEECHAT_HOOK_SIGNAL_STRING, [[signal_irc_input_send]] ===== Signal irc_input_send -_WeeChat ≥ 0.3.4._ +// TRANSLATION MISSING +_WeeChat ≥ 0.3.4, updated in 1.5._ Il segnale "irc_input_send" può essere inviato per simulare input in un buffer irc (server, canale o privato). @@ -9126,10 +9127,13 @@ L'argomento è una stringa con il seguente formato: * punto e virgola * nome canale (opzionale) * punto e virgola -* flag usate per l'invio del messaggio (opzionale, la predefinita è 1): -** '1': coda con la priorità maggiore (come i messaggi utente) -** '2': coda con la priorità minore (come i messaggi inviati automaticamente - da WeeChat) +// TRANSLATION MISSING +* comma-separated list of options (optional): +** 'priority_high': queue with high priority (like user messages); this is the + default priority +** 'priority_low': queue with low priority (like messages automatically sent by + WeeChat) +** 'user_message': force user message (don't execute a command) * punto e virgola * elenco separato da virgole di tag usate per l'invio di un messaggio (opzionale) @@ -9142,11 +9146,11 @@ Esempi in C: ---- /* dice "Hello!" sul server freenode, canale #weechat */ weechat_hook_signal_send ("irc_input_send", WEECHAT_HOOK_SIGNAL_STRING, - "freenode;#weechat;1;;Hello!"); + "freenode;#weechat;priority_high,user_message;;Hello!"); /* invia il comando "/whois FlashCode" sul server freenode, con priorità minore */ weechat_hook_signal_send ("irc_input_send", WEECHAT_HOOK_SIGNAL_STRING, - "freenode;;2;;/whois FlashCode"); + "freenode;;priority_low;;/whois FlashCode"); ---- Script (Python): @@ -9155,11 +9159,11 @@ Script (Python): ---- # dice "Hello!" sul server freenode server, canale #weechat weechat.hook_signal_send("irc_input_send", weechat.WEECHAT_HOOK_SIGNAL_STRING, - "freenode;#weechat;1;;Hello!") + "freenode;#weechat;priority_high,user_message;;Hello!") # invia il comando "/whois FlashCode" sul server freenode, con priorità minore weechat.hook_signal_send("irc_input_send", weechat.WEECHAT_HOOK_SIGNAL_STRING, - "freenode;;2;;/whois FlashCode") + "freenode;;priority_low;;/whois FlashCode") ---- ==== hook_hsignal diff --git a/doc/ja/weechat_plugin_api.ja.asciidoc b/doc/ja/weechat_plugin_api.ja.asciidoc index e82504c90..a66636629 100644 --- a/doc/ja/weechat_plugin_api.ja.asciidoc +++ b/doc/ja/weechat_plugin_api.ja.asciidoc @@ -8833,7 +8833,7 @@ weechat.hook_signal_send("python_script_remove", WEECHAT_HOOK_SIGNAL_STRING, [[signal_irc_input_send]] ===== irc_input_send シグナル -_WeeChat バージョン 0.3.4 以上で利用可。_ +_WeeChat バージョン 0.3.4 以上で利用可。バージョン 1.5 で更新。_ irc バッファ(サーバ、チャンネル、プライベート) への入力をシミュレートするにはシグナル "irc_input_send" を送信してください。 @@ -8844,9 +8844,13 @@ irc バッファ(サーバ、チャンネル、プライベート) * セミコロン * チャンネル名 (任意) * セミコロン -* メッセージを送信する際に使うフラグ (任意、デフォルトは 1): -** '1': 高い優先度を持つキュー (ユーザメッセージなどと同等) -** '2': 低い優先度を持つキュー (WeeChat が自動的に送信するメッセージと同等) +// TRANSLATION MISSING +* comma-separated list of options (optional): +** 'priority_high': queue with high priority (like user messages); this is the + default priority +** 'priority_low': queue with low priority (like messages automatically sent by + WeeChat) +** 'user_message': force user message (don't execute a command) * セミコロン * メッセージを送信する際に使うタグのコンマ区切りリスト (任意) * セミコロン @@ -8858,11 +8862,11 @@ C 言語での使用例: ---- /* say "Hello!" on freenode server, #weechat channel */ weechat_hook_signal_send ("irc_input_send", WEECHAT_HOOK_SIGNAL_STRING, - "freenode;#weechat;1;;Hello!"); + "freenode;#weechat;priority_high,user_message;;Hello!"); /* send command "/whois FlashCode" on freenode server, with low priority */ weechat_hook_signal_send ("irc_input_send", WEECHAT_HOOK_SIGNAL_STRING, - "freenode;;2;;/whois FlashCode"); + "freenode;;priority_low;;/whois FlashCode"); ---- スクリプト (Python) での使用例: @@ -8871,11 +8875,11 @@ weechat_hook_signal_send ("irc_input_send", WEECHAT_HOOK_SIGNAL_STRING, ---- # say "Hello!" on freenode server, #weechat channel weechat.hook_signal_send("irc_input_send", weechat.WEECHAT_HOOK_SIGNAL_STRING, - "freenode;#weechat;1;;Hello!") + "freenode;#weechat;priority_high,user_message;;Hello!") # send command "/whois FlashCode" on freenode server, with low priority weechat.hook_signal_send("irc_input_send", weechat.WEECHAT_HOOK_SIGNAL_STRING, - "freenode;;2;;/whois FlashCode") + "freenode;;priority_low;;/whois FlashCode") ---- ==== hook_hsignal diff --git a/src/plugins/irc/irc-input.c b/src/plugins/irc/irc-input.c index 81cbcc044..caa330474 100644 --- a/src/plugins/irc/irc-input.c +++ b/src/plugins/irc/irc-input.c @@ -189,7 +189,8 @@ irc_input_send_user_message (struct t_gui_buffer *buffer, int flags, */ int -irc_input_data (struct t_gui_buffer *buffer, const char *input_data, int flags) +irc_input_data (struct t_gui_buffer *buffer, const char *input_data, int flags, + int force_user_message) { const char *ptr_data; char *data_with_colors, *msg; @@ -207,7 +208,8 @@ irc_input_data (struct t_gui_buffer *buffer, const char *input_data, int flags) * if send unknown commands is enabled and that input data is a * command, then send this command to IRC server */ - if (weechat_config_boolean (irc_config_network_send_unknown_commands) + if (!force_user_message + && weechat_config_boolean (irc_config_network_send_unknown_commands) && !weechat_string_input_for_buffer (input_data)) { if (ptr_server) @@ -220,9 +222,13 @@ irc_input_data (struct t_gui_buffer *buffer, const char *input_data, int flags) if (ptr_channel) { - ptr_data = weechat_string_input_for_buffer (input_data); - if (!ptr_data) - ptr_data = input_data; + ptr_data = input_data; + if (!force_user_message) + { + ptr_data = weechat_string_input_for_buffer (input_data); + if (!ptr_data) + ptr_data = input_data; + } data_with_colors = irc_color_encode ( ptr_data, weechat_config_boolean (irc_config_network_colors_send)); @@ -259,7 +265,8 @@ irc_input_data_cb (void *data, struct t_gui_buffer *buffer, /* make C compiler happy */ (void) data; - return irc_input_data (buffer, input_data, IRC_SERVER_SEND_OUTQ_PRIO_HIGH); + return irc_input_data (buffer, input_data, + IRC_SERVER_SEND_OUTQ_PRIO_HIGH, 0); } /* @@ -268,10 +275,13 @@ irc_input_data_cb (void *data, struct t_gui_buffer *buffer, * This signal can be used by other plugins/scripts, it simulates input or * command from user on an IRC buffer (it is used for example by Relay plugin). * - * Format of signal_data (string) is "server;channel;flags;tags;text" + * Format of signal_data (string) is "server;channel;options;tags;text" * server: server name (required) * channel: channel name (optional) - * flags: flags for irc_server_sendf() (optional) + * options: comma-separated list of options (optional): + * "priority_high": send with high priority (default) + * "priority_low": send with low priority + * "user_message": force user message (don't execute a command) * tags: tags for irc_server_sendf() (optional) * text: text or command (required). */ @@ -281,10 +291,9 @@ irc_input_send_cb (void *data, const char *signal, const char *type_data, void *signal_data) { const char *ptr_string, *ptr_message; - char *pos_semicol1, *pos_semicol2, *pos_semicol3, *pos_semicol4, *error; - char *server, *channel, *flags, *tags; - long flags_value; - char *data_with_colors; + char *pos_semicol1, *pos_semicol2, *pos_semicol3, *pos_semicol4; + char *server, *channel, *options, *tags, *data_with_colors, **list_options; + int i, num_options, flags, force_user_message; struct t_irc_server *ptr_server; struct t_irc_channel *ptr_channel; struct t_gui_buffer *ptr_buffer; @@ -298,7 +307,9 @@ irc_input_send_cb (void *data, const char *signal, server = NULL; channel = NULL; - flags = NULL; + options = NULL; + flags = IRC_SERVER_SEND_OUTQ_PRIO_HIGH; + force_user_message = 0; tags = NULL; ptr_message = NULL; ptr_server = NULL; @@ -324,8 +335,8 @@ irc_input_send_cb (void *data, const char *signal, { if (pos_semicol3 > pos_semicol2 + 1) { - flags = weechat_strndup (pos_semicol2 + 1, - pos_semicol3 - pos_semicol2 - 1); + options = weechat_strndup (pos_semicol2 + 1, + pos_semicol3 - pos_semicol2 - 1); } pos_semicol4 = strchr (pos_semicol3 + 1, ';'); if (pos_semicol4) @@ -341,13 +352,22 @@ irc_input_send_cb (void *data, const char *signal, } } - flags_value = IRC_SERVER_SEND_OUTQ_PRIO_HIGH; - if (flags) + if (options && options[0]) { - error = NULL; - flags_value = strtol (flags, &error, 10); - if (flags_value < 0) - flags_value = IRC_SERVER_SEND_OUTQ_PRIO_HIGH; + list_options = weechat_string_split (options, ",", 0, 0, &num_options); + if (list_options) + { + for (i = 0; i < num_options; i++) + { + if (strcmp (list_options[i], "priority_high") == 0) + flags = IRC_SERVER_SEND_OUTQ_PRIO_HIGH; + else if (strcmp (list_options[i], "priority_low") == 0) + flags = IRC_SERVER_SEND_OUTQ_PRIO_LOW; + else if (strcmp (list_options[i], "user_message") == 0) + force_user_message = 1; + } + weechat_string_free_split (list_options); + } } if (server && ptr_message) @@ -367,10 +387,11 @@ irc_input_send_cb (void *data, const char *signal, irc_server_set_send_default_tags (tags); /* send text to buffer, or execute command */ - if (weechat_string_input_for_buffer (ptr_message)) + if (force_user_message + || weechat_string_input_for_buffer (ptr_message)) { /* text as input */ - irc_input_data (ptr_buffer, ptr_message, flags_value); + irc_input_data (ptr_buffer, ptr_message, flags, 1); } else { @@ -394,8 +415,8 @@ irc_input_send_cb (void *data, const char *signal, free (server); if (channel) free (channel); - if (flags) - free (flags); + if (options) + free (options); if (tags) free (tags); diff --git a/src/plugins/relay/irc/relay-irc.c b/src/plugins/relay/irc/relay-irc.c index 00754f45e..63c930bc8 100644 --- a/src/plugins/relay/irc/relay-irc.c +++ b/src/plugins/relay/irc/relay-irc.c @@ -1118,7 +1118,7 @@ relay_irc_send_join_channels (struct t_relay_client *client) void relay_irc_input_send (struct t_relay_client *client, const char *irc_channel, - int flags, const char *format, ...) + char *options, const char *format, ...) { char buf_beginning[1024], *buf; int length_beginning, length_vbuffer; @@ -1128,10 +1128,10 @@ relay_irc_input_send (struct t_relay_client *client, const char *irc_channel, return; snprintf (buf_beginning, sizeof (buf_beginning), - "%s;%s;%d;relay_client_%d;", + "%s;%s;%s;relay_client_%d;", client->protocol_args, (irc_channel) ? irc_channel : "", - flags, + options, client->id); length_beginning = strlen (buf_beginning); @@ -1567,10 +1567,10 @@ relay_irc_recv (struct t_relay_client *client, const char *data) } if (irc_args2[0] == ':') irc_args2++; - relay_irc_input_send (client, NULL, 1, + relay_irc_input_send (client, NULL, + "priority_high", "/notice %s %s", - target, - irc_args2); + target, irc_args2); free (target); } } @@ -1591,12 +1591,15 @@ relay_irc_recv (struct t_relay_client *client, const char *data) irc_is_channel = weechat_info_get ("irc_is_channel", irc_channel); if (irc_is_channel && (strcmp (irc_is_channel, "1") == 0)) { - relay_irc_input_send (client, irc_channel, 1, - "%s", irc_args2); + relay_irc_input_send (client, irc_channel, + "priority_high,user_message", + "%s", + irc_args2); } else { - relay_irc_input_send (client, NULL, 1, + relay_irc_input_send (client, NULL, + "priority_high", "/query %s %s", irc_channel, irc_args2); } @@ -1723,7 +1726,8 @@ relay_irc_recv (struct t_relay_client *client, const char *data) weechat_hashtable_free (hash_redirect); } /* send the IRC message to server */ - relay_irc_input_send (client, NULL, 1, + relay_irc_input_send (client, NULL, + "priority_high", "/quote %s", data); }