summaryrefslogtreecommitdiff
path: root/src/plugins/irc
diff options
context:
space:
mode:
authorSébastien Helleu <flashcode@flashtux.org>2021-08-08 18:37:15 +0200
committerSébastien Helleu <flashcode@flashtux.org>2021-08-08 18:37:15 +0200
commit8e676edd1a5a1ab91279d55a2181757ad36b5ced (patch)
treee8c3778b3027636bcd90285d5cd520f8653f2b01 /src/plugins/irc
parent415ea95eb42d061d350fe5b3b3cb9b00f05c6915 (diff)
downloadweechat-8e676edd1a5a1ab91279d55a2181757ad36b5ced.zip
irc: save CLIENTTAGDENY from message 005 in server, do not send typing messages if "typing" client tag is denied
Diffstat (limited to 'src/plugins/irc')
-rw-r--r--src/plugins/irc/irc-protocol.c13
-rw-r--r--src/plugins/irc/irc-server.c86
-rw-r--r--src/plugins/irc/irc-server.h6
-rw-r--r--src/plugins/irc/irc-typing.c9
-rw-r--r--src/plugins/irc/irc-upgrade.c17
5 files changed, 130 insertions, 1 deletions
diff --git a/src/plugins/irc/irc-protocol.c b/src/plugins/irc/irc-protocol.c
index 70a78348f..808f14f31 100644
--- a/src/plugins/irc/irc-protocol.c
+++ b/src/plugins/irc/irc-protocol.c
@@ -3567,6 +3567,19 @@ IRC_PROTOCOL_CALLBACK(005)
pos2[0] = ' ';
}
+ /* save client tag deny */
+ pos = strstr (argv_eol[3], "CLIENTTAGDENY=");
+ if (pos)
+ {
+ pos += 14;
+ pos2 = strchr (pos, ' ');
+ if (pos2)
+ pos2[0] = '\0';
+ irc_server_set_clienttagdeny (server, pos);
+ if (pos2)
+ pos2[0] = ' ';
+ }
+
/* save whole message (concatenate to existing isupport, if any) */
pos_start = NULL;
pos = strstr (argv_eol[3], " :");
diff --git a/src/plugins/irc/irc-server.c b/src/plugins/irc/irc-server.c
index 71586e0a6..75519fb0e 100644
--- a/src/plugins/irc/irc-server.c
+++ b/src/plugins/irc/irc-server.c
@@ -1116,6 +1116,72 @@ irc_server_set_prefix_modes_chars (struct t_irc_server *server,
}
/*
+ * Sets "clienttagdeny", "clienttagdeny_count", "clienttagdeny_array" and
+ * "typing_allowed" in server using value of CLIENTTAGDENY in IRC message 005.
+ * The masks in array start with "!" for a tag that is allowed (not denied).
+ *
+ * For example, if clienttagdeny is "*,-foo,-example/bar":
+ * clienttagdeny is set to "*,-foo,-example/bar"
+ * clienttagdeny_count is set to 3
+ * clienttagdeny_array is set to ["*", "!foo", "!example/bar"]
+ * typing_allowed is set to 0
+ *
+ * For example, if clienttagdeny is "*,-typing":
+ * clienttagdeny is set to "*,-typing"
+ * clienttagdeny_count is set to 2
+ * clienttagdeny_array is set to ["*", "!typing"]
+ * typing_allowed is set to 1
+ */
+
+void
+irc_server_set_clienttagdeny (struct t_irc_server *server,
+ const char *clienttagdeny)
+{
+ int i, typing_denied;
+
+ if (!server)
+ return;
+
+ /* free previous values */
+ if (server->clienttagdeny)
+ {
+ free (server->clienttagdeny);
+ server->clienttagdeny = NULL;
+ }
+ if (server->clienttagdeny_array)
+ {
+ weechat_string_free_split (server->clienttagdeny_array);
+ server->clienttagdeny_array = NULL;
+ }
+ server->clienttagdeny_count = 0;
+ server->typing_allowed = 1;
+
+ /* assign new values */
+ if (!clienttagdeny || !clienttagdeny[0])
+ return;
+ server->clienttagdeny = strdup (clienttagdeny);
+ server->clienttagdeny_array = weechat_string_split (
+ clienttagdeny, ",", NULL,
+ WEECHAT_STRING_SPLIT_STRIP_LEFT
+ | WEECHAT_STRING_SPLIT_STRIP_RIGHT
+ | WEECHAT_STRING_SPLIT_COLLAPSE_SEPS,
+ 0, &server->clienttagdeny_count);
+ if (server->clienttagdeny_array)
+ {
+ for (i = 0; i < server->clienttagdeny_count; i++)
+ {
+ if (server->clienttagdeny_array[i][0] == '-')
+ server->clienttagdeny_array[i][0] = '!';
+ }
+ }
+ typing_denied = weechat_string_match_list (
+ "typing",
+ (const char **)server->clienttagdeny_array,
+ 1);
+ server->typing_allowed = (typing_denied) ? 0 : 1;
+}
+
+/*
* Sets lag in server buffer (local variable), update bar item "lag"
* and send signal "irc_server_lag_changed" for the server.
*/
@@ -1530,6 +1596,10 @@ irc_server_alloc (const char *name)
new_server->chanmodes = NULL;
new_server->monitor = 0;
new_server->monitor_time = 0;
+ new_server->clienttagdeny = NULL;
+ new_server->clienttagdeny_count = 0;
+ new_server->clienttagdeny_array = NULL;
+ new_server->typing_allowed = 1;
new_server->reconnect_delay = 0;
new_server->reconnect_start = 0;
new_server->command_time = 0;
@@ -2088,6 +2158,10 @@ irc_server_free_data (struct t_irc_server *server)
free (server->chantypes);
if (server->chanmodes)
free (server->chanmodes);
+ if (server->clienttagdeny)
+ free (server->clienttagdeny);
+ if (server->clienttagdeny_array)
+ weechat_string_free_split (server->clienttagdeny_array);
if (server->away_message)
free (server->away_message);
if (server->cmd_list_regexp)
@@ -5985,6 +6059,10 @@ irc_server_hdata_server_cb (const void *pointer, void *data,
WEECHAT_HDATA_VAR(struct t_irc_server, chanmodes, STRING, 0, NULL, NULL);
WEECHAT_HDATA_VAR(struct t_irc_server, monitor, INTEGER, 0, NULL, NULL);
WEECHAT_HDATA_VAR(struct t_irc_server, monitor_time, TIME, 0, NULL, NULL);
+ WEECHAT_HDATA_VAR(struct t_irc_server, clienttagdeny, STRING, 0, NULL, NULL);
+ WEECHAT_HDATA_VAR(struct t_irc_server, clienttagdeny_count, INTEGER, 0, NULL, NULL);
+ WEECHAT_HDATA_VAR(struct t_irc_server, clienttagdeny_array, STRING, 0, "clienttagdeny_count", NULL);
+ WEECHAT_HDATA_VAR(struct t_irc_server, typing_allowed, INTEGER, 0, NULL, NULL);
WEECHAT_HDATA_VAR(struct t_irc_server, reconnect_delay, INTEGER, 0, NULL, NULL);
WEECHAT_HDATA_VAR(struct t_irc_server, reconnect_start, TIME, 0, NULL, NULL);
WEECHAT_HDATA_VAR(struct t_irc_server, command_time, TIME, 0, NULL, NULL);
@@ -6240,6 +6318,10 @@ irc_server_add_to_infolist (struct t_infolist *infolist,
return 0;
if (!weechat_infolist_new_var_time (ptr_item, "monitor_time", server->monitor_time))
return 0;
+ if (!weechat_infolist_new_var_string (ptr_item, "clienttagdeny", server->clienttagdeny))
+ return 0;
+ if (!weechat_infolist_new_var_integer (ptr_item, "typing_allowed", server->typing_allowed))
+ return 0;
if (!weechat_infolist_new_var_integer (ptr_item, "reconnect_delay", server->reconnect_delay))
return 0;
if (!weechat_infolist_new_var_time (ptr_item, "reconnect_start", server->reconnect_start))
@@ -6633,6 +6715,10 @@ irc_server_print_log ()
weechat_log_printf (" chanmodes . . . . . . . . : '%s'", ptr_server->chanmodes);
weechat_log_printf (" monitor . . . . . . . . . : %d", ptr_server->monitor);
weechat_log_printf (" monitor_time. . . . . . . : %lld", (long long)ptr_server->monitor_time);
+ weechat_log_printf (" clienttagdeny . . . . . . : '%s'", ptr_server->clienttagdeny);
+ weechat_log_printf (" clienttagdeny_count . . . : %d", ptr_server->clienttagdeny_count);
+ weechat_log_printf (" clienttagdeny_array . . . : 0x%lx", ptr_server->clienttagdeny_array);
+ weechat_log_printf (" typing_allowed . . . . . : %d", ptr_server->typing_allowed);
weechat_log_printf (" reconnect_delay . . . . . : %d", ptr_server->reconnect_delay);
weechat_log_printf (" reconnect_start . . . . . : %lld", (long long)ptr_server->reconnect_start);
weechat_log_printf (" command_time. . . . . . . : %lld", (long long)ptr_server->command_time);
diff --git a/src/plugins/irc/irc-server.h b/src/plugins/irc/irc-server.h
index 7b1ffa5a9..45bb1d991 100644
--- a/src/plugins/irc/irc-server.h
+++ b/src/plugins/irc/irc-server.h
@@ -232,6 +232,10 @@ struct t_irc_server
/* (eg "beI,k,l,imnpstaqr") */
int monitor; /* monitor limit from msg 005 (eg 100) */
time_t monitor_time; /* time for monitoring nicks (on connect)*/
+ char *clienttagdeny; /* list of blocked client-only tags */
+ int clienttagdeny_count; /* number of masks in clienttagdeny */
+ char **clienttagdeny_array; /* masks expanded from clienttagdeny */
+ int typing_allowed; /* typing not excluded by clienttagdeny? */
int reconnect_delay; /* current reconnect delay (growing) */
time_t reconnect_start; /* this time + delay = reconnect time */
time_t command_time; /* this time + command_delay = time to */
@@ -332,6 +336,8 @@ extern const char *irc_server_get_isupport_value (struct t_irc_server *server,
extern const char *irc_server_get_chantypes (struct t_irc_server *server);
extern void irc_server_set_prefix_modes_chars (struct t_irc_server *server,
const char *prefix);
+extern void irc_server_set_clienttagdeny (struct t_irc_server *server,
+ const char *clienttagdeny);
extern void irc_server_set_lag (struct t_irc_server *server);
extern void irc_server_set_tls_version (struct t_irc_server *server);
extern const char *irc_server_get_prefix_modes (struct t_irc_server *server);
diff --git a/src/plugins/irc/irc-typing.c b/src/plugins/irc/irc-typing.c
index 49ecc1502..396460b13 100644
--- a/src/plugins/irc/irc-typing.c
+++ b/src/plugins/irc/irc-typing.c
@@ -60,6 +60,10 @@ irc_typing_signal_typing_self_cb (const void *pointer, void *data,
if (!ptr_server || !ptr_channel)
return WEECHAT_RC_OK;
+ /* typing not allowed on server? */
+ if (!ptr_server->typing_allowed)
+ return WEECHAT_RC_OK;
+
/* typing works only if capability "message-tags" is enabled */
if (!weechat_hashtable_has_key (ptr_server->cap_list, "message-tags"))
return WEECHAT_RC_OK;
@@ -94,8 +98,11 @@ irc_typing_send_to_targets (struct t_irc_server *server)
struct t_irc_channel *ptr_channel;
time_t current_time;
- if (!weechat_config_boolean (irc_config_look_typing_status_self))
+ if (!weechat_config_boolean (irc_config_look_typing_status_self)
+ || !server->typing_allowed)
+ {
return;
+ }
current_time = time (NULL);
diff --git a/src/plugins/irc/irc-upgrade.c b/src/plugins/irc/irc-upgrade.c
index 1f90e36c1..81cdda27a 100644
--- a/src/plugins/irc/irc-upgrade.c
+++ b/src/plugins/irc/irc-upgrade.c
@@ -564,6 +564,23 @@ irc_upgrade_read_cb (const void *pointer, void *data,
irc_upgrade_current_server->monitor = (int)number;
}
}
+ /* "clienttagdeny" is new in WeeChat 3.3 */
+ if (weechat_infolist_search_var (infolist, "clienttagdeny"))
+ {
+ irc_server_set_clienttagdeny (irc_upgrade_current_server,
+ weechat_infolist_string (infolist, "clienttagdeny"));
+ }
+ else
+ {
+ /* WeeChat <= 3.2 */
+ str = irc_server_get_isupport_value (irc_upgrade_current_server,
+ "CLIENTTAGDENY");
+ if (str)
+ {
+ irc_server_set_clienttagdeny (irc_upgrade_current_server,
+ str);
+ }
+ }
irc_upgrade_current_server->reconnect_delay = weechat_infolist_integer (infolist, "reconnect_delay");
irc_upgrade_current_server->reconnect_start = weechat_infolist_time (infolist, "reconnect_start");
irc_upgrade_current_server->command_time = weechat_infolist_time (infolist, "command_time");