Browse Source

irc: save CLIENTTAGDENY from message 005 in server, do not send typing messages if "typing" client tag is denied

master
Sébastien Helleu 3 months ago
parent
commit
8e676edd1a
  1. 13
      src/plugins/irc/irc-protocol.c
  2. 86
      src/plugins/irc/irc-server.c
  3. 6
      src/plugins/irc/irc-server.h
  4. 9
      src/plugins/irc/irc-typing.c
  5. 17
      src/plugins/irc/irc-upgrade.c
  6. 68
      tests/unit/plugins/irc/test-irc-server.cpp

13
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], " :");

86
src/plugins/irc/irc-server.c

@ -1115,6 +1115,72 @@ irc_server_set_prefix_modes_chars (struct t_irc_server *server,
irc_nick_realloc_prefixes (server, old_length_chars, length_chars);
}
/*
* 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);

6
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);

9
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);

17
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");

68
tests/unit/plugins/irc/test-irc-server.cpp

@ -249,6 +249,74 @@ TEST(IrcServer, SetPrefixModesChars)
/* TODO: write tests */
}
/*
* Tests functions:
* irc_server_set_clienttagdeny
*/
TEST(IrcServer, SetClienttagdeny)
{
struct t_irc_server *server;
server = irc_server_alloc ("test_clienttagdeny");
CHECK(server);
POINTERS_EQUAL(NULL, server->clienttagdeny);
LONGS_EQUAL(0, server->clienttagdeny_count);
POINTERS_EQUAL(NULL, server->clienttagdeny_array);
LONGS_EQUAL(1, server->typing_allowed);
irc_server_set_clienttagdeny (server, "*");
irc_server_set_clienttagdeny (server, NULL);
POINTERS_EQUAL(NULL, server->clienttagdeny);
LONGS_EQUAL(0, server->clienttagdeny_count);
POINTERS_EQUAL(NULL, server->clienttagdeny_array);
LONGS_EQUAL(1, server->typing_allowed);
irc_server_set_clienttagdeny (server, "*");
irc_server_set_clienttagdeny (server, "");
POINTERS_EQUAL(NULL, server->clienttagdeny);
LONGS_EQUAL(0, server->clienttagdeny_count);
POINTERS_EQUAL(NULL, server->clienttagdeny_array);
LONGS_EQUAL(1, server->typing_allowed);
irc_server_set_clienttagdeny (server, "*");
STRCMP_EQUAL("*", server->clienttagdeny);
LONGS_EQUAL(1, server->clienttagdeny_count);
STRCMP_EQUAL("*", server->clienttagdeny_array[0]);
POINTERS_EQUAL(NULL, server->clienttagdeny_array[1]);
LONGS_EQUAL(0, server->typing_allowed);
irc_server_set_clienttagdeny (server, "*,-foo");
STRCMP_EQUAL("*,-foo", server->clienttagdeny);
LONGS_EQUAL(2, server->clienttagdeny_count);
STRCMP_EQUAL("*", server->clienttagdeny_array[0]);
STRCMP_EQUAL("!foo", server->clienttagdeny_array[1]);
POINTERS_EQUAL(NULL, server->clienttagdeny_array[2]);
LONGS_EQUAL(0, server->typing_allowed);
irc_server_set_clienttagdeny (server, "*,-foo,-example/bar");
STRCMP_EQUAL("*,-foo,-example/bar", server->clienttagdeny);
LONGS_EQUAL(3, server->clienttagdeny_count);
STRCMP_EQUAL("*", server->clienttagdeny_array[0]);
STRCMP_EQUAL("!foo", server->clienttagdeny_array[1]);
STRCMP_EQUAL("!example/bar", server->clienttagdeny_array[2]);
POINTERS_EQUAL(NULL, server->clienttagdeny_array[3]);
LONGS_EQUAL(0, server->typing_allowed);
irc_server_set_clienttagdeny (server, "*,-foo,-example/bar,-typing");
STRCMP_EQUAL("*,-foo,-example/bar,-typing", server->clienttagdeny);
LONGS_EQUAL(4, server->clienttagdeny_count);
STRCMP_EQUAL("*", server->clienttagdeny_array[0]);
STRCMP_EQUAL("!foo", server->clienttagdeny_array[1]);
STRCMP_EQUAL("!example/bar", server->clienttagdeny_array[2]);
STRCMP_EQUAL("!typing", server->clienttagdeny_array[3]);
POINTERS_EQUAL(NULL, server->clienttagdeny_array[4]);
LONGS_EQUAL(1, server->typing_allowed);
irc_server_free (server);
}
/*
* Tests functions:
* irc_server_set_lag

Loading…
Cancel
Save