From d9789e522fd6120c7140a6d970503cc6433a6851 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Helleu?= Date: Thu, 25 May 2023 21:51:00 +0200 Subject: [PATCH] irc: fix duplicated CTCP messages displayed when capability "echo-message" is enabled (issue #139) --- po/cs.po | 10 +-- po/de.po | 10 +-- po/es.po | 10 +-- po/fr.po | 10 +-- po/hu.po | 10 +-- po/it.po | 10 +-- po/ja.po | 10 +-- po/pl.po | 10 +-- po/pt.po | 10 +-- po/pt_BR.po | 10 +-- po/ru.po | 10 +-- po/sr.po | 10 +-- po/tr.po | 10 +-- po/weechat.pot | 10 +-- src/plugins/irc/irc-command.c | 30 +------- src/plugins/irc/irc-ctcp.c | 47 ++++++++++++ src/plugins/irc/irc-ctcp.h | 6 ++ src/plugins/irc/irc-protocol.c | 80 +++++++++++++++++--- tests/unit/plugins/irc/test-irc-protocol.cpp | 16 ++++ 19 files changed, 211 insertions(+), 108 deletions(-) diff --git a/po/cs.po b/po/cs.po index 86cc68d3a..af7e98653 100644 --- a/po/cs.po +++ b/po/cs.po @@ -21,7 +21,7 @@ msgid "" msgstr "" "Project-Id-Version: WeeChat\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2023-05-23 15:52+0200\n" +"POT-Creation-Date: 2023-05-25 22:15+0200\n" "PO-Revision-Date: 2023-05-01 20:23+0200\n" "Last-Translator: Ondřej Súkup \n" "Language-Team: weechat-dev \n" @@ -6782,10 +6782,6 @@ msgstr "" "%s%s: příkaz \"%s\" může být spuštěn pouze v bufferu kanálu nebo soukromého " "rozhovoru" -#, c-format -msgid "%sCTCP query to %s%s%s: %s%s%s%s%s" -msgstr "%sCTCP dotaz pro %s%s%s: %s%s%s%s%s" - #, c-format msgid "%s%s: \"%s\" command can not be executed on a server buffer" msgstr "%s%s: \"%s\" příkaz nemůže být spuštěn v bufferu serveru" @@ -9519,6 +9515,10 @@ msgstr "%s%s: neznámý DCC CHAT typ obdržen od %s%s%s: \"%s\"" msgid "%sUnknown CTCP requested by %s%s%s: %s%s%s%s%s" msgstr "%sNeznámý CTCP požadavek od %s%s%s: %s%s%s%s%s" +#, c-format +msgid "%sCTCP query to %s%s%s: %s%s%s%s%s" +msgstr "%sCTCP dotaz pro %s%s%s: %s%s%s%s%s" + msgid "1 if string is a valid IRC channel name for server" msgstr "1 pokud je řetězec validní jméno IRC kanálu na serveru" diff --git a/po/de.po b/po/de.po index ff6c6f0b4..788d14d34 100644 --- a/po/de.po +++ b/po/de.po @@ -26,7 +26,7 @@ msgid "" msgstr "" "Project-Id-Version: WeeChat\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2023-05-23 15:52+0200\n" +"POT-Creation-Date: 2023-05-25 22:15+0200\n" "PO-Revision-Date: 2023-05-14 15:49+0200\n" "Last-Translator: Nils Görs \n" "Language-Team: German \n" @@ -8592,10 +8592,6 @@ msgstr "" "%s%s: Der Befehl \"%s\" kann nur in einem Kanal- oder einem privaten Buffer " "ausgeführt werden" -#, c-format -msgid "%sCTCP query to %s%s%s: %s%s%s%s%s" -msgstr "%sCTCP Anfrage an %s%s%s: %s%s%s%s%s" - #, c-format msgid "%s%s: \"%s\" command can not be executed on a server buffer" msgstr "" @@ -11885,6 +11881,10 @@ msgstr "%s%s: unbekannter DCC CHAT-Typ empfangen von %s%s%s: \"%s\"" msgid "%sUnknown CTCP requested by %s%s%s: %s%s%s%s%s" msgstr "%sunbekannte CTCP Anfrage von %s%s%s: %s%s%s%s%s" +#, c-format +msgid "%sCTCP query to %s%s%s: %s%s%s%s%s" +msgstr "%sCTCP Anfrage an %s%s%s: %s%s%s%s%s" + msgid "1 if string is a valid IRC channel name for server" msgstr "" "1, falls die Zeichenkette ein gültiger IRC-Kanalname für den Server ist" diff --git a/po/es.po b/po/es.po index f47239cde..1f0e70f9c 100644 --- a/po/es.po +++ b/po/es.po @@ -22,7 +22,7 @@ msgid "" msgstr "" "Project-Id-Version: WeeChat\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2023-05-23 15:52+0200\n" +"POT-Creation-Date: 2023-05-25 22:15+0200\n" "PO-Revision-Date: 2023-05-01 20:23+0200\n" "Last-Translator: Santiago Forero \n" "Language-Team: weechat-dev \n" @@ -7421,10 +7421,6 @@ msgstr "" "%s%s: el comando \"%s\" sólo puede ser ejecutado en un canal o conversación " "privada" -#, c-format -msgid "%sCTCP query to %s%s%s: %s%s%s%s%s" -msgstr "%sconsulta CTCP a %s%s%s: %s%s%s%s%s" - #, c-format msgid "%s%s: \"%s\" command can not be executed on a server buffer" msgstr "%s%s: el comando \"%s\" no puede ejecutarse en el buffer del servidor" @@ -10238,6 +10234,10 @@ msgstr "%s%s: tipo de DCC CHAT desconocido recibido de %s%s%s: \"%s\"" msgid "%sUnknown CTCP requested by %s%s%s: %s%s%s%s%s" msgstr "%sCTCP desconocido solicitado por %s%s%s: %s%s%s%s%s" +#, c-format +msgid "%sCTCP query to %s%s%s: %s%s%s%s%s" +msgstr "%sconsulta CTCP a %s%s%s: %s%s%s%s%s" + msgid "1 if string is a valid IRC channel name for server" msgstr "1 si la cadena es un nombre de canal IRC válido para el servidor" diff --git a/po/fr.po b/po/fr.po index eaf76bda9..6bcc1a58f 100644 --- a/po/fr.po +++ b/po/fr.po @@ -21,7 +21,7 @@ msgid "" msgstr "" "Project-Id-Version: WeeChat\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2023-05-23 15:52+0200\n" +"POT-Creation-Date: 2023-05-25 22:15+0200\n" "PO-Revision-Date: 2023-05-23 21:22+0200\n" "Last-Translator: Sébastien Helleu \n" "Language-Team: weechat-dev \n" @@ -8393,10 +8393,6 @@ msgstr "" "%s%s : la commande \"%s\" peut seulement être exécutée dans un tampon canal " "ou privé" -#, c-format -msgid "%sCTCP query to %s%s%s: %s%s%s%s%s" -msgstr "%sDemande CTCP vers %s%s%s : %s%s%s%s%s" - #, c-format msgid "%s%s: \"%s\" command can not be executed on a server buffer" msgstr "" @@ -11580,6 +11576,10 @@ msgstr "%s%s : type de DCC CHAT inconnu reçu de %s%s%s : \"%s\"" msgid "%sUnknown CTCP requested by %s%s%s: %s%s%s%s%s" msgstr "%sCTCP inconnu demandé par %s%s%s : %s%s%s%s%s" +#, c-format +msgid "%sCTCP query to %s%s%s: %s%s%s%s%s" +msgstr "%sDemande CTCP vers %s%s%s : %s%s%s%s%s" + msgid "1 if string is a valid IRC channel name for server" msgstr "1 si la chaîne est un nom de canal IRC valide pour le serveur" diff --git a/po/hu.po b/po/hu.po index 45fd96f51..a1d1c0102 100644 --- a/po/hu.po +++ b/po/hu.po @@ -20,7 +20,7 @@ msgid "" msgstr "" "Project-Id-Version: WeeChat\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2023-05-23 15:52+0200\n" +"POT-Creation-Date: 2023-05-25 22:15+0200\n" "PO-Revision-Date: 2023-05-01 20:23+0200\n" "Last-Translator: Andras Voroskoi \n" "Language-Team: weechat-dev \n" @@ -6274,10 +6274,6 @@ msgid "" "%s%s: \"%s\" command can only be executed in a channel or private buffer" msgstr "%s \"%s\" parancs csak a szobaablakban futtatható\n" -#, fuzzy, c-format -msgid "%sCTCP query to %s%s%s: %s%s%s%s%s" -msgstr "%s Szerver: %s%s %s[%s%s%s]\n" - #, fuzzy, c-format msgid "%s%s: \"%s\" command can not be executed on a server buffer" msgstr "%s \"%s\" parancs nem futtatható a szerverablakban\n" @@ -8960,6 +8956,10 @@ msgstr "%s usmeretlen DCC CHAT típus érkezett a következőtől:" msgid "%sUnknown CTCP requested by %s%s%s: %s%s%s%s%s" msgstr "Ismeretlen CTCP %s%s%s érkezett innen: %s%s" +#, fuzzy, c-format +msgid "%sCTCP query to %s%s%s: %s%s%s%s%s" +msgstr "%s Szerver: %s%s %s[%s%s%s]\n" + #, fuzzy msgid "1 if string is a valid IRC channel name for server" msgstr "felhasználók listája a szobában" diff --git a/po/it.po b/po/it.po index 6c01f6fb4..215265fda 100644 --- a/po/it.po +++ b/po/it.po @@ -20,7 +20,7 @@ msgid "" msgstr "" "Project-Id-Version: WeeChat\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2023-05-23 15:52+0200\n" +"POT-Creation-Date: 2023-05-25 22:15+0200\n" "PO-Revision-Date: 2023-05-01 20:23+0200\n" "Last-Translator: Esteban I. Ruiz Moreno \n" "Language-Team: weechat-dev \n" @@ -7118,10 +7118,6 @@ msgstr "" "%s%s: il comando \"%s\" può essere eseguito soltanto in un canale o in un " "buffer privato" -#, c-format -msgid "%sCTCP query to %s%s%s: %s%s%s%s%s" -msgstr "%sRichiesta CTCP a %s%s%s: %s%s%s%s%s" - #, c-format msgid "%s%s: \"%s\" command can not be executed on a server buffer" msgstr "%s%s: il comando \"%s\" non può essere eseguito sul buffer del server" @@ -9970,6 +9966,10 @@ msgstr "%s%s: tipo di DCC CHAT sconosciuto ricevuto da %s%s%s: \"%s\"" msgid "%sUnknown CTCP requested by %s%s%s: %s%s%s%s%s" msgstr "%sCTCP sconosciuto richiesto da %s%s%s: %s%s%s%s%s" +#, c-format +msgid "%sCTCP query to %s%s%s: %s%s%s%s%s" +msgstr "%sRichiesta CTCP a %s%s%s: %s%s%s%s%s" + msgid "1 if string is a valid IRC channel name for server" msgstr "1 se la stringa è il nome di un canale IRC valido per il server" diff --git a/po/ja.po b/po/ja.po index ec365f561..b5631418b 100644 --- a/po/ja.po +++ b/po/ja.po @@ -20,7 +20,7 @@ msgid "" msgstr "" "Project-Id-Version: WeeChat\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2023-05-23 15:52+0200\n" +"POT-Creation-Date: 2023-05-25 22:15+0200\n" "PO-Revision-Date: 2023-05-01 20:23+0200\n" "Last-Translator: AYANOKOUZI, Ryuunosuke \n" "Language-Team: Japanese \n" "Language-Team: Polish \n" @@ -8854,10 +8854,6 @@ msgid "" msgstr "" "%s%s: komenda \"%s\" może być wykonana tylko na kanale lub prywatnym buforze" -#, c-format -msgid "%sCTCP query to %s%s%s: %s%s%s%s%s" -msgstr "%sZapytanie CTCP do %s%s%s: %s%s%s%s%s" - #, c-format msgid "%s%s: \"%s\" command can not be executed on a server buffer" msgstr "%s%s: komenda \"%s\" nie można być wykonana w buforze serwera" @@ -12149,6 +12145,10 @@ msgstr "%s%s: nieznany typ DCC CHAT otrzymano od %s%s%s: \"%s\"" msgid "%sUnknown CTCP requested by %s%s%s: %s%s%s%s%s" msgstr "%sNieznane zażądane CTCP przez %s%s%s: %s%s%s%s%s" +#, c-format +msgid "%sCTCP query to %s%s%s: %s%s%s%s%s" +msgstr "%sZapytanie CTCP do %s%s%s: %s%s%s%s%s" + msgid "1 if string is a valid IRC channel name for server" msgstr "1 jeśli ciąg jest poprawną nazwą kanału IRC dla serwera" diff --git a/po/pt.po b/po/pt.po index 1f807d514..52f93428e 100644 --- a/po/pt.po +++ b/po/pt.po @@ -20,7 +20,7 @@ msgid "" msgstr "" "Project-Id-Version: WeeChat\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2023-05-23 15:52+0200\n" +"POT-Creation-Date: 2023-05-25 22:15+0200\n" "PO-Revision-Date: 2023-05-01 20:23+0200\n" "Last-Translator: Vasco Almeida \n" "Language-Team: Portuguese <>\n" @@ -7880,10 +7880,6 @@ msgid "" msgstr "" "%s%s: o comando \"%s\" só pode ser executado num buffer de canal ou privado" -#, c-format -msgid "%sCTCP query to %s%s%s: %s%s%s%s%s" -msgstr "%sconsulta CTCP a %s%s%s: %s%s%s%s%s" - #, c-format msgid "%s%s: \"%s\" command can not be executed on a server buffer" msgstr "%s%s: o comando \"%s\" não pode ser executado num buffer de servidor" @@ -10923,6 +10919,10 @@ msgstr "%s%s: tipo desconhecido de DCC CHAT recebido de %s%s%s: \"%s\"" msgid "%sUnknown CTCP requested by %s%s%s: %s%s%s%s%s" msgstr "%spedido CTCP desconhecido por %s%s%s: %s%s%s%s%s" +#, c-format +msgid "%sCTCP query to %s%s%s: %s%s%s%s%s" +msgstr "%sconsulta CTCP a %s%s%s: %s%s%s%s%s" + msgid "1 if string is a valid IRC channel name for server" msgstr "1 se a cadeia for o nome dum canal de IRC válido no servidor" diff --git a/po/pt_BR.po b/po/pt_BR.po index 9ee12b5cb..680e852f6 100644 --- a/po/pt_BR.po +++ b/po/pt_BR.po @@ -21,7 +21,7 @@ msgid "" msgstr "" "Project-Id-Version: WeeChat\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2023-05-23 15:52+0200\n" +"POT-Creation-Date: 2023-05-25 22:15+0200\n" "PO-Revision-Date: 2023-05-01 20:23+0200\n" "Last-Translator: Érico Nogueira \n" "Language-Team: weechat-dev \n" @@ -7018,10 +7018,6 @@ msgid "" "%s%s: \"%s\" command can only be executed in a channel or private buffer" msgstr "" -#, c-format -msgid "%sCTCP query to %s%s%s: %s%s%s%s%s" -msgstr "" - #, c-format msgid "%s%s: \"%s\" command can not be executed on a server buffer" msgstr "" @@ -9504,6 +9500,10 @@ msgstr "" msgid "%sUnknown CTCP requested by %s%s%s: %s%s%s%s%s" msgstr "%sRequisição CTCP desconhecida por %s%s%s: %s%s%s%s%s" +#, c-format +msgid "%sCTCP query to %s%s%s: %s%s%s%s%s" +msgstr "" + msgid "1 if string is a valid IRC channel name for server" msgstr "1 se string é um nome de canal IRC válido para o servidor" diff --git a/po/ru.po b/po/ru.po index 600e7421b..dfa393fc5 100644 --- a/po/ru.po +++ b/po/ru.po @@ -21,7 +21,7 @@ msgid "" msgstr "" "Project-Id-Version: WeeChat\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2023-05-23 15:52+0200\n" +"POT-Creation-Date: 2023-05-25 22:15+0200\n" "PO-Revision-Date: 2023-05-01 20:23+0200\n" "Last-Translator: Aleksey V Zapparov AKA ixti \n" "Language-Team: weechat-dev \n" @@ -6312,10 +6312,6 @@ msgid "" msgstr "" "%s \"%s\" команда может быть выполнена только в буфере канала или привата\n" -#, fuzzy, c-format -msgid "%sCTCP query to %s%s%s: %s%s%s%s%s" -msgstr "%sСервер: %s%s %s[%s%s%s]\n" - #, fuzzy, c-format msgid "%s%s: \"%s\" command can not be executed on a server buffer" msgstr "%s \"%s\" команда может быть выполнена только в буфере сервера\n" @@ -8997,6 +8993,10 @@ msgstr "%s неизвестный режим DCC CHAT получен от " msgid "%sUnknown CTCP requested by %s%s%s: %s%s%s%s%s" msgstr "Получен неизвестный CTCP %s%s%s от %s%s" +#, fuzzy, c-format +msgid "%sCTCP query to %s%s%s: %s%s%s%s%s" +msgstr "%sСервер: %s%s %s[%s%s%s]\n" + #, fuzzy msgid "1 if string is a valid IRC channel name for server" msgstr "список ников на канале" diff --git a/po/sr.po b/po/sr.po index c9b811eee..a1aab5ff8 100644 --- a/po/sr.po +++ b/po/sr.po @@ -20,7 +20,7 @@ msgid "" msgstr "" "Project-Id-Version: WeeChat\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2023-05-23 15:52+0200\n" +"POT-Creation-Date: 2023-05-25 22:15+0200\n" "PO-Revision-Date: 2023-05-14 15:29+0200\n" "Last-Translator: Ivan Pešić \n" "Language-Team: weechat-dev \n" @@ -8211,10 +8211,6 @@ msgid "" msgstr "" "%s%s: команда „%s” може да се изврши само у каналу или приватном баферу" -#, c-format -msgid "%sCTCP query to %s%s%s: %s%s%s%s%s" -msgstr "%sCTCP упит за %s%s%s: %s%s%s%s%s" - #, c-format msgid "%s%s: \"%s\" command can not be executed on a server buffer" msgstr "%s%s: команда „%s” не може да се изврши у серверском баферу" @@ -11342,6 +11338,10 @@ msgstr "%s%s: примљен је непознати DCC CHAT тип од %s%s%s msgid "%sUnknown CTCP requested by %s%s%s: %s%s%s%s%s" msgstr "%sСтигао је непознати CTCP од %s%s%s: %s%s%s%s%s" +#, c-format +msgid "%sCTCP query to %s%s%s: %s%s%s%s%s" +msgstr "%sCTCP упит за %s%s%s: %s%s%s%s%s" + msgid "1 if string is a valid IRC channel name for server" msgstr "1 ако је стринг важеће име IRC канала за сервер" diff --git a/po/tr.po b/po/tr.po index 583189fbf..4db5baf2d 100644 --- a/po/tr.po +++ b/po/tr.po @@ -20,7 +20,7 @@ msgid "" msgstr "" "Project-Id-Version: WeeChat\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2023-05-23 15:52+0200\n" +"POT-Creation-Date: 2023-05-25 22:15+0200\n" "PO-Revision-Date: 2023-05-01 20:23+0200\n" "Last-Translator: Emir SARI \n" "Language-Team: weechat-dev \n" @@ -8457,10 +8457,6 @@ msgid "" msgstr "" "%s%s: \"%s\" komutu, yalnızca bir kanalda veya özel arabellekte yürütülebilir" -#, c-format -msgid "%sCTCP query to %s%s%s: %s%s%s%s%s" -msgstr "%s%s%s%s konumuna CTCP sorgusu: %s%s%s%s%s" - #, c-format msgid "%s%s: \"%s\" command can not be executed on a server buffer" msgstr "%s%s: \"%s\" komutu, bir sunucu arabelleğinde yürütülemez" @@ -11710,6 +11706,10 @@ msgstr "%s%s: %s%s%s konumundan bilinmeyen DCC CHAT türü alındı: \"%s\"" msgid "%sUnknown CTCP requested by %s%s%s: %s%s%s%s%s" msgstr "%s%s%s%s tarafından bilinmeyen CTCP istendi: %s%s%s%s%s" +#, c-format +msgid "%sCTCP query to %s%s%s: %s%s%s%s%s" +msgstr "%s%s%s%s konumuna CTCP sorgusu: %s%s%s%s%s" + msgid "1 if string is a valid IRC channel name for server" msgstr "1 eğer dizi sunucu için geçerli bir IRC kanal adıysa" diff --git a/po/weechat.pot b/po/weechat.pot index fb3107501..8c3490dfc 100644 --- a/po/weechat.pot +++ b/po/weechat.pot @@ -21,7 +21,7 @@ msgid "" msgstr "" "Project-Id-Version: WeeChat\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2023-05-23 15:52+0200\n" +"POT-Creation-Date: 2023-05-25 22:15+0200\n" "PO-Revision-Date: 2014-08-16 10:27+0200\n" "Last-Translator: Sébastien Helleu \n" "Language-Team: weechat-dev \n" @@ -5778,10 +5778,6 @@ msgid "" "%s%s: \"%s\" command can only be executed in a channel or private buffer" msgstr "" -#, c-format -msgid "%sCTCP query to %s%s%s: %s%s%s%s%s" -msgstr "" - #, c-format msgid "%s%s: \"%s\" command can not be executed on a server buffer" msgstr "" @@ -8042,6 +8038,10 @@ msgstr "" msgid "%sUnknown CTCP requested by %s%s%s: %s%s%s%s%s" msgstr "" +#, c-format +msgid "%sCTCP query to %s%s%s: %s%s%s%s%s" +msgstr "" + msgid "1 if string is a valid IRC channel name for server" msgstr "" diff --git a/src/plugins/irc/irc-command.c b/src/plugins/irc/irc-command.c index c7a21f9e9..4b4bf607c 100644 --- a/src/plugins/irc/irc-command.c +++ b/src/plugins/irc/irc-command.c @@ -35,6 +35,7 @@ #include "../weechat-plugin.h" #include "irc.h" #include "irc-command.h" +#include "irc-ctcp.h" #include "irc-buffer.h" #include "irc-channel.h" #include "irc-color.h" @@ -1909,36 +1910,13 @@ IRC_COMMAND_CALLBACK(ctcp) if (ctcp_target) { - irc_server_sendf (ptr_server, IRC_SERVER_SEND_OUTQ_PRIO_HIGH, NULL, - "PRIVMSG %s :\01%s%s%s\01", - ctcp_target, - ctcp_type, - (ctcp_args) ? " " : "", - (ctcp_args) ? ctcp_args : ""); /* display message only if capability "echo-message" is NOT enabled */ if (!weechat_hashtable_has_key (ptr_server->cap_list, "echo-message")) { - weechat_printf_date_tags ( - irc_msgbuffer_get_target_buffer ( - ptr_server, ctcp_target, NULL, "ctcp", NULL), - 0, - irc_protocol_tags ( - ptr_server, - "privmsg", - NULL, - "irc_ctcp,self_msg,notify_none,no_highlight", - NULL, NULL), - _("%sCTCP query to %s%s%s: %s%s%s%s%s"), - weechat_prefix ("network"), - irc_nick_color_for_msg (ptr_server, 0, NULL, ctcp_target), - ctcp_target, - IRC_COLOR_RESET, - IRC_COLOR_CHAT_CHANNEL, - ctcp_type, - IRC_COLOR_RESET, - (ctcp_args) ? " " : "", - (ctcp_args) ? ctcp_args : ""); + irc_ctcp_display_send (ptr_server, ctcp_target, ctcp_type, + ctcp_args); } + irc_ctcp_send (ptr_server, ctcp_target, ctcp_type, ctcp_args); } } diff --git a/src/plugins/irc/irc-ctcp.c b/src/plugins/irc/irc-ctcp.c index 6def77a39..5026dee14 100644 --- a/src/plugins/irc/irc-ctcp.c +++ b/src/plugins/irc/irc-ctcp.c @@ -1255,3 +1255,50 @@ irc_ctcp_recv (struct t_irc_server *server, time_t date, free (dup_arguments); } + +/* + * Displays an outgoing CTCP. + */ + +void +irc_ctcp_display_send (struct t_irc_server *server, + const char *target, const char *type, const char *args) +{ + weechat_printf_date_tags ( + irc_msgbuffer_get_target_buffer ( + server, target, NULL, "ctcp", NULL), + 0, + irc_protocol_tags ( + server, + "privmsg", + NULL, + "irc_ctcp,self_msg,notify_none,no_highlight", + NULL, NULL), + _("%sCTCP query to %s%s%s: %s%s%s%s%s"), + weechat_prefix ("network"), + irc_nick_color_for_msg (server, 0, NULL, target), + target, + IRC_COLOR_RESET, + IRC_COLOR_CHAT_CHANNEL, + type, + IRC_COLOR_RESET, + (args && args[0]) ? " " : "", + (args && args[0]) ? args : ""); +} + +/* + * Sends a CTCP to a target. + */ + +void +irc_ctcp_send (struct t_irc_server *server, + const char *target, const char *type, const char *args) +{ + irc_server_sendf (server, + IRC_SERVER_SEND_OUTQ_PRIO_HIGH, NULL, + "PRIVMSG %s :\01%s%s%s\01", + target, + type, + (args) ? " " : "", + (args) ? args : ""); +} diff --git a/src/plugins/irc/irc-ctcp.h b/src/plugins/irc/irc-ctcp.h index 27ed38500..beafb1c45 100644 --- a/src/plugins/irc/irc-ctcp.h +++ b/src/plugins/irc/irc-ctcp.h @@ -49,5 +49,11 @@ extern void irc_ctcp_recv (struct t_irc_server *server, time_t date, const char *address, const char *nick, const char *remote_nick, const char *arguments, const char *message); +extern void irc_ctcp_display_send (struct t_irc_server *server, + const char *target, const char *type, + const char *args); +extern void irc_ctcp_send (struct t_irc_server *server, + const char *target, const char *type, + const char *args); #endif /* WEECHAT_PLUGIN_IRC_CTCP_H */ diff --git a/src/plugins/irc/irc-protocol.c b/src/plugins/irc/irc-protocol.c index d5ef2e489..56f63ba2a 100644 --- a/src/plugins/irc/irc-protocol.c +++ b/src/plugins/irc/irc-protocol.c @@ -2947,6 +2947,48 @@ IRC_PROTOCOL_CALLBACK(pong) return WEECHAT_RC_OK; } +/* + * Displays a CTCP sent, that was received by PRIVMSG if the origin nick + * is self. + * + * Parameter "arguments" is the message arguments, for example: + * + * \01VERSION\01 + * \01TEST some arguments\01 + */ + +void +irc_protocol_privmsg_display_ctcp_send (struct t_irc_server *server, + const char *target, + const char *arguments) +{ + const char *pos_space, *pos_end; + char *ctcp_type, *ctcp_args; + + if (!arguments || !arguments[0]) + return; + + pos_end = strchr (arguments + 1, '\01'); + if (!pos_end) + return; + + pos_space = strchr (arguments + 1, ' '); + + ctcp_type = weechat_strndup ( + arguments + 1, + (pos_space) ? + pos_space - arguments - 1 : pos_end - arguments - 1); + ctcp_args = (pos_space) ? + weechat_strndup (pos_space + 1, pos_end - pos_space - 1) : NULL; + + irc_ctcp_display_send (server, target, ctcp_type, ctcp_args); + + if (ctcp_type) + free (ctcp_type); + if (ctcp_args) + free (ctcp_args); +} + /* * Callback for the IRC command "PRIVMSG". * @@ -2984,15 +3026,13 @@ IRC_PROTOCOL_CALLBACK(privmsg) pos_target = params[0]; status_msg = 0; is_channel = irc_channel_is_channel (server, pos_target); - if (!is_channel) + if (!is_channel + && irc_channel_is_channel (server, pos_target + 1) + && irc_server_prefix_char_statusmsg (server, pos_target[0])) { - if (irc_channel_is_channel (server, pos_target + 1) - && irc_server_prefix_char_statusmsg (server, pos_target[0])) - { - is_channel = 1; - status_msg = 1; - pos_target++; - } + is_channel = 1; + status_msg = 1; + pos_target++; } /* receiver is a channel ? */ @@ -3010,8 +3050,16 @@ IRC_PROTOCOL_CALLBACK(privmsg) /* CTCP to channel */ if (msg_args[0] == '\01') { - irc_ctcp_recv (server, date, tags, command, ptr_channel, - address, nick, NULL, msg_args, irc_message); + if (nick_is_me) + { + irc_protocol_privmsg_display_ctcp_send (server, pos_target, + msg_args); + } + else + { + irc_ctcp_recv (server, date, tags, command, ptr_channel, + address, nick, NULL, msg_args, irc_message); + } goto end; } @@ -3106,8 +3154,16 @@ IRC_PROTOCOL_CALLBACK(privmsg) /* CTCP to user */ if (msg_args[0] == '\01') { - irc_ctcp_recv (server, date, tags, command, NULL, - address, nick, remote_nick, msg_args, irc_message); + if (nick_is_me) + { + irc_protocol_privmsg_display_ctcp_send (server, remote_nick, + msg_args); + } + else + { + irc_ctcp_recv (server, date, tags, command, NULL, + address, nick, remote_nick, msg_args, irc_message); + } goto end; } diff --git a/tests/unit/plugins/irc/test-irc-protocol.cpp b/tests/unit/plugins/irc/test-irc-protocol.cpp index b16818381..50549d984 100644 --- a/tests/unit/plugins/irc/test-irc-protocol.cpp +++ b/tests/unit/plugins/irc/test-irc-protocol.cpp @@ -2381,6 +2381,14 @@ TEST(IrcProtocolWithServer, privmsg) RECV(":bob!user@host PRIVMSG #test :\01VERSION\01"); RECV(":bob!user@host PRIVMSG #test :\01DCC SEND file.txt 1 2 3\01"); + /* + * valid CTCP to channel from self nick + * (case of bouncer of if echo-message capability is enabled) + */ + RECV(":alice!user@host PRIVMSG #test :\01VERSION\01"); + CHECK_SRV("--", "CTCP query to #test: VERSION", + "irc_privmsg,irc_ctcp,self_msg,notify_none,no_highlight,log1"); + /* valid CTCP to user */ RECV(":bob!user@host PRIVMSG alice :\01TEST\01"); CHECK_SENT(NULL); @@ -2415,6 +2423,14 @@ TEST(IrcProtocolWithServer, privmsg) "), name: file.txt, 3 bytes (protocol: dcc)"); CHECK_SENT(NULL); + /* + * valid CTCP to channel from self nick + * (case of bouncer of if echo-message capability is enabled) + */ + RECV(":alice!user@host PRIVMSG bob :\01VERSION\01"); + CHECK_SRV("--", "CTCP query to bob: VERSION", + "irc_privmsg,irc_ctcp,self_msg,notify_none,no_highlight,log1"); + /* close xfer buffer */ if (xfer_buffer) gui_buffer_close (xfer_buffer);