diff --git a/ChangeLog.adoc b/ChangeLog.adoc index 2394fa8d2..c801da7ed 100644 --- a/ChangeLog.adoc +++ b/ChangeLog.adoc @@ -41,6 +41,7 @@ New features:: * alias: use lower case for default aliases, rename all aliases to lower case on upgrade (issue #1872) * irc: rename "ssl" options to "tls", connect with TLS and port 6697 by default * irc: add support of capabilities "batch" and "draft/multiline" (issue #1292, issue #1923) + * irc: add modifier "irc_cap_sync_req" (issue #1767) * irc: add support of "LINELEN" in message 005 (max message length in bytes) (issue #1927) * irc: add command `/rules` (issue #1864) * irc: add command `/knock` (issue #7) diff --git a/doc/en/weechat_plugin_api.en.adoc b/doc/en/weechat_plugin_api.en.adoc index 6729dc913..204146ac3 100644 --- a/doc/en/weechat_plugin_api.en.adoc +++ b/doc/en/weechat_plugin_api.en.adoc @@ -12343,6 +12343,11 @@ List of modifiers used by WeeChat and plugins: | New content of messages (number can be different), an empty string discards all messages in the batch. +| [[hook_modifier_irc_cap_sync_req]] irc_cap_sync_req | 4.0.0 +| Server name + "," + supported capabilities on server (separated by spaces) +| Capabilities to request (separated by spaces). +| New content of capabilities to request (separated by spaces). + | [[hook_modifier_irc_in_xxx]] irc_in_xxx ^(1)^ | | Server name | Content of message received from IRC server (before charset decoding). + diff --git a/doc/fr/weechat_plugin_api.fr.adoc b/doc/fr/weechat_plugin_api.fr.adoc index e9e8c6fe4..1ea118d91 100644 --- a/doc/fr/weechat_plugin_api.fr.adoc +++ b/doc/fr/weechat_plugin_api.fr.adoc @@ -12606,6 +12606,12 @@ Liste des modificateurs utilisés par WeeChat et les extensions : | Nouveau contenu des messages (le nombre peut être différent), une chaîne vide annule tous les messages du batch. +| [[hook_modifier_irc_cap_sync_req]] irc_cap_sync_req | 4.0.0 +| Nom de serveur + "," + capacités supportées par le serveur (séparées par + des espaces) +| Capacités à demander (séparées par des espaces). +| Nouveau contenu des capacités à demander (séparées par des espaces). + | [[hook_modifier_irc_in_xxx]] irc_in_xxx ^(1)^ | | Nom de serveur | Contenu du message reçu du serveur IRC (avant décodage du jeu de caractères). + diff --git a/doc/it/weechat_plugin_api.it.adoc b/doc/it/weechat_plugin_api.it.adoc index 4058c4060..cd625ede0 100644 --- a/doc/it/weechat_plugin_api.it.adoc +++ b/doc/it/weechat_plugin_api.it.adoc @@ -12885,6 +12885,12 @@ List of modifiers used by WeeChat and plugins: | New content of messages (number can be different), an empty string discards all messages in the batch. +// TRANSLATION MISSING +| [[hook_modifier_irc_cap_sync_req]] irc_cap_sync_req | 4.0.0 +| Server name + "," + supported capabilities on server (separated by spaces) +| Capabilities to request (separated by spaces). +| New content of capabilities to request (separated by spaces). + // TRANSLATION MISSING | [[hook_modifier_irc_in_xxx]] irc_in_xxx ^(1)^ | | Nome server diff --git a/doc/ja/weechat_plugin_api.ja.adoc b/doc/ja/weechat_plugin_api.ja.adoc index 829a9441c..39800b92f 100644 --- a/doc/ja/weechat_plugin_api.ja.adoc +++ b/doc/ja/weechat_plugin_api.ja.adoc @@ -12471,6 +12471,12 @@ WeeChat とプラグインが使う修飾子のリスト: | New content of messages (number can be different), an empty string discards all messages in the batch. +// TRANSLATION MISSING +| [[hook_modifier_irc_cap_sync_req]] irc_cap_sync_req | 4.0.0 +| Server name + "," + supported capabilities on server (separated by spaces) +| Capabilities to request (separated by spaces). +| New content of capabilities to request (separated by spaces). + // TRANSLATION MISSING | [[hook_modifier_irc_in_xxx]] irc_in_xxx ^(1)^ | | サーバ名 diff --git a/doc/sr/weechat_plugin_api.sr.adoc b/doc/sr/weechat_plugin_api.sr.adoc index b015dfce2..0529cec08 100644 --- a/doc/sr/weechat_plugin_api.sr.adoc +++ b/doc/sr/weechat_plugin_api.sr.adoc @@ -11938,6 +11938,12 @@ struct t_hook *weechat_hook_modifier (const char *modifier, | New content of messages (number can be different), an empty string discards all messages in the batch. +// TRANSLATION MISSING +| [[hook_modifier_irc_cap_sync_req]] irc_cap_sync_req | 4.0.0 +| Server name + "," + supported capabilities on server (separated by spaces) +| Capabilities to request (separated by spaces). +| New content of capabilities to request (separated by spaces). + | [[hook_modifier_irc_in_xxx]] irc_in_xxx ^(1)^ | | Име сервера | Садржај поруке примљене са IRC сервера (пре декодирања скупа карактера). + diff --git a/src/plugins/irc/irc-protocol.c b/src/plugins/irc/irc-protocol.c index 4e7d4d961..6da8efce4 100644 --- a/src/plugins/irc/irc-protocol.c +++ b/src/plugins/irc/irc-protocol.c @@ -793,6 +793,49 @@ irc_protocol_cap_to_enable (const char *capabilities, int sasl_requested) return weechat_string_dyn_free (str_caps, 0); } +/* + * Requests capabilities for IRC server after synchronization. + */ + +void +irc_protocol_cap_sync_req (struct t_irc_server *server, + const char *caps_server, + const char *caps_req) +{ + char modifier_data[4096], *new_caps_req; + const char *ptr_caps_req; + + snprintf (modifier_data, sizeof (modifier_data), + "%s,%s", + server->name, + (caps_server) ? caps_server : ""); + new_caps_req = weechat_hook_modifier_exec ("irc_cap_sync_req", + modifier_data, + caps_req); + + /* no changes in new caps requested */ + if (new_caps_req && (strcmp (caps_req, new_caps_req) == 0)) + { + free (new_caps_req); + new_caps_req = NULL; + } + + /* caps not dropped? */ + if (!new_caps_req || new_caps_req[0]) + { + ptr_caps_req = (new_caps_req) ? new_caps_req : caps_req; + weechat_printf ( + server->buffer, + _("%s%s: client capability, requesting: %s"), + weechat_prefix ("network"), IRC_PLUGIN_NAME, + ptr_caps_req); + irc_server_sendf (server, 0, NULL, "CAP REQ :%s", ptr_caps_req); + } + + if (new_caps_req) + free (new_caps_req); +} + /* * Synchronizes requested capabilities for IRC server. */ @@ -800,11 +843,14 @@ irc_protocol_cap_to_enable (const char *capabilities, int sasl_requested) void irc_protocol_cap_sync (struct t_irc_server *server, int sasl) { - char **caps_server, *caps_to_enable, **list_caps_to_enable, **cap_req; - const char *ptr_cap_option; + char *str_caps_server, **caps_server, *caps_to_enable; + char **list_caps_to_enable, **cap_req; + const char *ptr_caps_server, *ptr_cap_option; int sasl_requested, sasl_to_do, sasl_fail; int i, num_caps_server; + str_caps_server = NULL; + sasl_requested = (sasl) ? irc_server_sasl_enabled (server) : 0; sasl_to_do = 0; @@ -827,8 +873,11 @@ irc_protocol_cap_sync (struct t_irc_server *server, int sasl) NULL); if (list_caps_to_enable) { + ptr_caps_server = weechat_hashtable_get_string (server->cap_ls, "keys"); + str_caps_server = (ptr_caps_server) ? + weechat_string_replace (ptr_caps_server, ",", " ") : NULL; caps_server = weechat_string_split ( - weechat_hashtable_get_string (server->cap_ls, "keys"), + (ptr_caps_server) ? ptr_caps_server : "", ",", NULL, WEECHAT_STRING_SPLIT_STRIP_LEFT @@ -856,15 +905,7 @@ irc_protocol_cap_sync (struct t_irc_server *server, int sasl) weechat_string_free_split (caps_server); } - if (*cap_req[0]) - { - weechat_printf ( - server->buffer, - _("%s%s: client capability, requesting: %s"), - weechat_prefix ("network"), IRC_PLUGIN_NAME, - *cap_req); - irc_server_sendf (server, 0, NULL, "CAP REQ :%s", *cap_req); - } + irc_protocol_cap_sync_req (server, str_caps_server, *cap_req); if (sasl) { @@ -894,6 +935,8 @@ irc_protocol_cap_sync (struct t_irc_server *server, int sasl) weechat_string_free_split (list_caps_to_enable); } + if (str_caps_server) + free (str_caps_server); if (caps_to_enable) free (caps_to_enable); if (cap_req)