1
0
mirror of https://github.com/weechat/weechat.git synced 2026-06-12 14:14:48 +02:00

irc: ignore BATCH commands when capability "batch" is not enabled (issue #1292)

This commit is contained in:
Sébastien Helleu
2023-05-14 15:04:08 +02:00
parent 283c9d7ccf
commit 060cb48094
2 changed files with 122 additions and 3 deletions
+6 -1
View File
@@ -668,6 +668,10 @@ IRC_PROTOCOL_CALLBACK(batch)
IRC_PROTOCOL_MIN_PARAMS(1);
/* do nothing (but ignore BATCH) if capability "batch" is not enabled */
if (!weechat_hashtable_has_key (server->cap_list, "batch"))
return WEECHAT_RC_OK;
if (params[0][0] == '+')
{
/* start batch */
@@ -7784,7 +7788,8 @@ irc_protocol_recv_command (struct t_irc_server *server,
/* if message is not BATCH but has a batch tag, just store it for later */
if (!ignore_batch_tag
&& hash_tags
&& (weechat_strcasecmp (msg_command, "batch") != 0))
&& (weechat_strcasecmp (msg_command, "batch") != 0)
&& weechat_hashtable_has_key (server->cap_list, "batch"))
{
ptr_batch_ref = weechat_hashtable_get (hash_tags, "batch");
if (ptr_batch_ref)
+116 -2
View File
@@ -795,10 +795,124 @@ TEST(IrcProtocolWithServer, away)
/*
* Tests functions:
* irc_protocol_cb_batch
* irc_protocol_cb_batch (without batch cap)
*/
TEST(IrcProtocolWithServer, batch)
TEST(IrcProtocolWithServer, batch_without_batch_cap)
{
SRV_INIT_JOIN2;
/* not enough parameters */
RECV(":server BATCH");
CHECK_ERROR_PARAMS("batch", 0, 1);
RECV(":server BATCH +test");
CHECK_NO_MSG;
/* invalid reference: does not start with '+' or '-' */
RECV(":server BATCH zzz type");
CHECK_NO_MSG;
POINTERS_EQUAL(NULL, ptr_server->batches);
/* start batch without parameters */
RECV(":server BATCH +ref example");
CHECK_NO_MSG;
POINTERS_EQUAL(NULL, irc_batch_search (ptr_server, "ref"));
/* new messages with batch reference */
RECV("@batch=ref :bob!user_b@host_b PRIVMSG #test :this is a test");
CHECK_CHAN("bob this is a test");
RECV("@batch=ref :bob!user_b@host_b PRIVMSG #test :second test");
CHECK_CHAN("bob second test");
RECV("@batch=ref :bob!user_b@host_b PRIVMSG #test :third test");
CHECK_CHAN("bob third test");
/* end batch */
RECV(":server BATCH -ref");
CHECK_NO_MSG;
/* start batch with parameters */
RECV(":server BATCH +ref example param1 param2 param3");
CHECK_NO_MSG;
POINTERS_EQUAL(NULL, irc_batch_search (ptr_server, "ref"));
/* new messages with batch reference */
RECV("@batch=ref :bob!user_b@host_b PRIVMSG #test :test 1");
CHECK_CHAN("bob test 1");
RECV("@batch=ref :bob!user_b@host_b PRIVMSG #test :test 2");
CHECK_CHAN("bob test 2");
RECV("@batch=ref :bob!user_b@host_b PRIVMSG #test :test 3");
CHECK_CHAN("bob test 3");
/* end batch */
RECV(":server BATCH -ref");
CHECK_NO_MSG;
/* start/end batch without parameters */
RECV(":server BATCH +ref example");
RECV(":server BATCH -ref");
CHECK_NO_MSG;
POINTERS_EQUAL(NULL, irc_batch_search (ptr_server, "ref"));
/* interleaving batches */
RECV(":server BATCH +1 example");
CHECK_NO_MSG;
RECV("@batch=1 :bob!user_b@host_b PRIVMSG #test :message 1");
CHECK_CHAN("bob message 1");
RECV(":server BATCH +2 example");
CHECK_NO_MSG;
RECV("@batch=1 :bob!user_b@host_b PRIVMSG #test :message 2");
CHECK_CHAN("bob message 2");
RECV("@batch=2 :bob!user_b@host_b PRIVMSG #test :message 4");
CHECK_CHAN("bob message 4");
RECV("@batch=1 :bob!user_b@host_b PRIVMSG #test :message 3");
CHECK_CHAN("bob message 3");
RECV(":server BATCH -1");
CHECK_NO_MSG;
RECV("@batch=2 :bob!user_b@host_b PRIVMSG #test :message 5");
CHECK_CHAN("bob message 5");
RECV(":server BATCH -2");
CHECK_NO_MSG;
/* nested batch */
RECV(":server BATCH +ref1 example1");
CHECK_NO_MSG;
RECV("@batch=ref1 :server BATCH +ref2 example2");
RECV("@batch=ref1 :bob!user_b@host_b PRIVMSG #test :test ref1");
CHECK_CHAN("bob test ref1");
RECV("@batch=ref2 :bob!user_b@host_b PRIVMSG #test :test ref2");
CHECK_CHAN("bob test ref2");
RECV(":server BATCH -ref2");
CHECK_NO_MSG;
RECV(":server BATCH -ref1");
CHECK_NO_MSG;
/* multiline */
RECV(":server BATCH +ref draft/multiline #test");
CHECK_NO_MSG;
RECV("@batch=ref :bob!user_b@host_b PRIVMSG #test :line 1");
CHECK_CHAN("bob line 1");
RECV("@batch=ref :bob!user_b@host_b PRIVMSG #test :line 2");
CHECK_CHAN("bob line 2");
RECV(":server BATCH -ref");
CHECK_NO_MSG;
/* multiline with CTCP */
RECV(":server BATCH +ref draft/multiline #test");
CHECK_NO_MSG;
RECV("@batch=ref :bob!user_b@host_b PRIVMSG #test :\01ACTION is testing");
CHECK_CHAN(" * bob is testing");
RECV("@batch=ref :bob!user_b@host_b PRIVMSG #test :again\01");
CHECK_CHAN("bob again\01");
RECV(":server BATCH -ref");
CHECK_NO_MSG;
}
/*
* Tests functions:
* irc_protocol_cb_batch (with batch cap)
*/
TEST(IrcProtocolWithServer, batch_with_batch_cap)
{
struct t_irc_batch *ptr_batch;