2007-01-25 06:40:21 +00:00
|
|
|
/*
|
2020-10-15 14:51:12 +00:00
|
|
|
* Solanum: a slightly advanced ircd
|
2007-01-25 06:40:21 +00:00
|
|
|
* m_list_safelist.c: Version of /list that uses the safelist code.
|
|
|
|
*
|
2021-06-01 16:40:02 +00:00
|
|
|
* Copyright (c) 2006 Ariadne Conill <ariadne@dereferenced.org>
|
2007-01-25 06:40:21 +00:00
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions are
|
|
|
|
* met:
|
|
|
|
*
|
|
|
|
* 1. Redistributions of source code must retain the above copyright notice,
|
|
|
|
* this list of conditions and the following disclaimer.
|
|
|
|
*
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* 3. The name of the author may not be used to endorse or promote products
|
|
|
|
* derived from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
|
|
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
|
|
* DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
|
|
|
|
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
|
|
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
|
|
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
|
|
|
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
|
|
|
|
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "stdinc.h"
|
|
|
|
#include "channel.h"
|
|
|
|
#include "client.h"
|
|
|
|
#include "hash.h"
|
2008-04-20 05:47:38 +00:00
|
|
|
#include "match.h"
|
2007-01-25 06:40:21 +00:00
|
|
|
#include "ircd.h"
|
|
|
|
#include "numeric.h"
|
|
|
|
#include "s_conf.h"
|
2011-01-06 02:57:27 +00:00
|
|
|
#include "s_newconf.h"
|
2007-01-25 06:40:21 +00:00
|
|
|
#include "s_serv.h"
|
2011-01-06 08:40:08 +00:00
|
|
|
#include "supported.h"
|
2007-01-25 06:40:21 +00:00
|
|
|
#include "send.h"
|
|
|
|
#include "msg.h"
|
|
|
|
#include "parse.h"
|
|
|
|
#include "modules.h"
|
2012-04-28 22:44:33 +00:00
|
|
|
#include "inline/stringops.h"
|
2013-09-10 05:35:56 +00:00
|
|
|
#include "s_assert.h"
|
|
|
|
#include "logger.h"
|
2016-03-06 20:17:19 +00:00
|
|
|
#include "rb_radixtree.h"
|
2016-01-21 03:26:55 +00:00
|
|
|
|
2016-03-09 07:29:41 +00:00
|
|
|
static const char list_desc[] = "Provides the LIST command to clients to view non-hidden channels";
|
2007-01-25 06:40:21 +00:00
|
|
|
|
2008-04-01 20:18:48 +00:00
|
|
|
static rb_dlink_list safelisting_clients = { NULL, NULL, 0 };
|
2007-01-25 06:40:21 +00:00
|
|
|
|
2016-03-09 07:37:03 +00:00
|
|
|
static struct ev_entry *iterate_clients_ev = NULL;
|
|
|
|
|
2007-01-25 06:40:21 +00:00
|
|
|
static int _modinit(void);
|
|
|
|
static void _moddeinit(void);
|
|
|
|
|
2016-03-09 07:37:03 +00:00
|
|
|
static void m_list(struct MsgBuf *, struct Client *, struct Client *, int, const char **);
|
|
|
|
static void mo_list(struct MsgBuf *, struct Client *, struct Client *, int, const char **);
|
2007-01-25 06:40:21 +00:00
|
|
|
|
2012-04-28 22:44:33 +00:00
|
|
|
static void list_one_channel(struct Client *source_p, struct Channel *chptr, int visible);
|
|
|
|
|
2016-01-21 03:26:55 +00:00
|
|
|
static void safelist_one_channel(struct Client *source_p, struct Channel *chptr, struct ListClient *params);
|
2021-08-20 03:09:40 +00:00
|
|
|
static void safelist_check_cliexit(void *);
|
2007-01-25 06:40:21 +00:00
|
|
|
static void safelist_client_instantiate(struct Client *, struct ListClient *);
|
|
|
|
static void safelist_client_release(struct Client *);
|
|
|
|
static void safelist_iterate_client(struct Client *source_p);
|
|
|
|
static void safelist_iterate_clients(void *unused);
|
2011-05-23 03:30:49 +00:00
|
|
|
static void safelist_channel_named(struct Client *source_p, const char *name, int operspy);
|
2007-01-25 06:40:21 +00:00
|
|
|
|
|
|
|
struct Message list_msgtab = {
|
2016-02-19 22:42:40 +00:00
|
|
|
"LIST", 0, 0, 0, 0,
|
2007-01-25 06:40:21 +00:00
|
|
|
{mg_unreg, {m_list, 0}, mg_ignore, mg_ignore, mg_ignore, {mo_list, 0}}
|
|
|
|
};
|
|
|
|
|
|
|
|
mapi_clist_av1 list_clist[] = { &list_msgtab, NULL };
|
|
|
|
|
|
|
|
mapi_hfn_list_av1 list_hfnlist[] = {
|
2021-08-20 03:09:40 +00:00
|
|
|
{"client_exit", safelist_check_cliexit},
|
2007-01-25 06:40:21 +00:00
|
|
|
{NULL, NULL}
|
|
|
|
};
|
|
|
|
|
2016-03-07 08:34:00 +00:00
|
|
|
DECLARE_MODULE_AV2(list, _modinit, _moddeinit, list_clist, NULL, list_hfnlist, NULL, NULL, list_desc);
|
2008-04-01 21:12:16 +00:00
|
|
|
|
2007-01-25 06:40:21 +00:00
|
|
|
static int _modinit(void)
|
|
|
|
{
|
2008-04-01 21:12:16 +00:00
|
|
|
iterate_clients_ev = rb_event_add("safelist_iterate_clients", safelist_iterate_clients, NULL, 3);
|
2007-01-25 06:40:21 +00:00
|
|
|
|
2011-01-06 08:40:08 +00:00
|
|
|
/* ELIST=[tokens]:
|
|
|
|
*
|
|
|
|
* M = mask search
|
|
|
|
* N = !mask search
|
|
|
|
* U = user count search (< >)
|
|
|
|
* C = creation time search (C> C<)
|
|
|
|
* T = topic search (T> T<)
|
|
|
|
*/
|
|
|
|
add_isupport("SAFELIST", isupport_string, "");
|
2021-10-18 17:26:05 +00:00
|
|
|
add_isupport("ELIST", isupport_string, "CMNTU");
|
2011-01-06 08:40:08 +00:00
|
|
|
|
2007-01-25 06:40:21 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void _moddeinit(void)
|
|
|
|
{
|
2008-04-01 21:12:16 +00:00
|
|
|
rb_event_delete(iterate_clients_ev);
|
2011-01-06 08:40:08 +00:00
|
|
|
|
|
|
|
delete_isupport("SAFELIST");
|
|
|
|
delete_isupport("ELIST");
|
2007-01-25 06:40:21 +00:00
|
|
|
}
|
|
|
|
|
2021-08-20 03:09:40 +00:00
|
|
|
static void safelist_check_cliexit(void *data)
|
2007-01-25 06:40:21 +00:00
|
|
|
{
|
2021-08-20 03:09:40 +00:00
|
|
|
hook_data_client_exit * hdata = data;
|
2007-01-25 06:40:21 +00:00
|
|
|
/* Cancel the safelist request if we are disconnecting
|
|
|
|
* from the server. That way it doesn't core. :P --nenolod
|
|
|
|
*/
|
|
|
|
if (MyClient(hdata->target) && hdata->target->localClient->safelist_data != NULL)
|
|
|
|
{
|
|
|
|
safelist_client_release(hdata->target);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* m_list()
|
|
|
|
* parv[1] = channel
|
|
|
|
*
|
|
|
|
* XXX - With SAFELIST, do we really need to continue pacing?
|
|
|
|
* In theory, the server cannot be lagged by this. --nenolod
|
|
|
|
*/
|
2016-03-09 07:37:03 +00:00
|
|
|
static void
|
|
|
|
m_list(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
|
2007-01-25 06:40:21 +00:00
|
|
|
{
|
|
|
|
static time_t last_used = 0L;
|
|
|
|
|
|
|
|
if (source_p->localClient->safelist_data != NULL)
|
|
|
|
{
|
|
|
|
sendto_one_notice(source_p, ":/LIST aborted");
|
|
|
|
safelist_client_release(source_p);
|
2016-03-09 07:37:03 +00:00
|
|
|
return;
|
2007-01-25 06:40:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (parc < 2 || !IsChannelName(parv[1]))
|
|
|
|
{
|
|
|
|
/* pace this due to the sheer traffic involved */
|
2008-04-01 23:53:20 +00:00
|
|
|
if (((last_used + ConfigFileEntry.pace_wait) > rb_current_time()))
|
2007-01-25 06:40:21 +00:00
|
|
|
{
|
|
|
|
sendto_one(source_p, form_str(RPL_LOAD2HI), me.name, source_p->name, "LIST");
|
|
|
|
sendto_one(source_p, form_str(RPL_LISTEND), me.name, source_p->name);
|
2016-03-09 07:37:03 +00:00
|
|
|
return;
|
2007-01-25 06:40:21 +00:00
|
|
|
}
|
|
|
|
else
|
2008-04-01 23:53:20 +00:00
|
|
|
last_used = rb_current_time();
|
2007-01-25 06:40:21 +00:00
|
|
|
}
|
|
|
|
|
2024-06-06 00:33:19 +00:00
|
|
|
<<<<<<< .merge_file_PyqEuU
|
2018-10-27 19:47:25 +00:00
|
|
|
/* Disable LIST for a configured timespan after connect and send configured fake
|
|
|
|
* channels instead.
|
|
|
|
* Exempts: Opers, identifed users and users with spambot_exempt flag
|
|
|
|
*/
|
|
|
|
if (((source_p->localClient->firsttime + ConfigFileEntry.listfake_wait) > rb_current_time())
|
|
|
|
&& !IsOper(source_p) && !IsExemptSpambot(source_p) &&
|
|
|
|
!(source_p->user != NULL && !EmptyString(source_p->user->suser)))
|
|
|
|
{
|
|
|
|
struct fakechannel_entry *fakechannel;
|
|
|
|
struct DictionaryIter iter;
|
|
|
|
|
|
|
|
sendto_one(source_p, form_str(RPL_LISTSTART), me.name, source_p->name);
|
|
|
|
|
|
|
|
DICTIONARY_FOREACH(fakechannel, &iter, fakechannel_dict)
|
|
|
|
{
|
|
|
|
sendto_one(source_p, form_str(RPL_LIST), me.name, source_p->name,
|
|
|
|
"",
|
|
|
|
fakechannel->name,
|
|
|
|
(rand() % fakechannel->users_max + fakechannel->users_min),
|
|
|
|
fakechannel->topic);
|
|
|
|
}
|
|
|
|
|
|
|
|
sendto_one(source_p, form_str(RPL_LISTEND), me.name, source_p->name);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-01-25 06:40:21 +00:00
|
|
|
return mo_list(client_p, source_p, parc, parv);
|
2024-06-06 00:33:19 +00:00
|
|
|
=======
|
2016-03-09 07:37:03 +00:00
|
|
|
mo_list(msgbuf_p, client_p, source_p, parc, parv);
|
2024-06-06 00:33:19 +00:00
|
|
|
>>>>>>> .merge_file_yv6CiZ
|
2007-01-25 06:40:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* mo_list()
|
|
|
|
* parv[1] = channel
|
|
|
|
*/
|
2016-03-09 07:37:03 +00:00
|
|
|
static void
|
|
|
|
mo_list(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
|
2007-01-25 06:40:21 +00:00
|
|
|
{
|
2011-01-06 05:15:36 +00:00
|
|
|
struct ListClient *params;
|
2011-05-23 03:30:49 +00:00
|
|
|
char *p;
|
|
|
|
char *args = NULL;
|
2007-01-25 06:40:21 +00:00
|
|
|
int i;
|
2011-05-23 03:30:49 +00:00
|
|
|
int operspy = 0;
|
2007-01-25 06:40:21 +00:00
|
|
|
|
|
|
|
if (source_p->localClient->safelist_data != NULL)
|
|
|
|
{
|
|
|
|
sendto_one_notice(source_p, ":/LIST aborted");
|
|
|
|
safelist_client_release(source_p);
|
2016-03-09 07:37:03 +00:00
|
|
|
return;
|
2007-01-25 06:40:21 +00:00
|
|
|
}
|
|
|
|
|
2011-05-23 03:30:49 +00:00
|
|
|
if (parc > 1)
|
|
|
|
{
|
|
|
|
args = LOCAL_COPY(parv[1]);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (args && *args == '!' && IsOperSpy(source_p))
|
|
|
|
{
|
|
|
|
args++;
|
|
|
|
report_operspy(source_p, "LIST", args);
|
|
|
|
operspy = 1;
|
|
|
|
}
|
|
|
|
|
2011-01-06 05:15:36 +00:00
|
|
|
/* Single channel. */
|
2021-10-19 12:30:03 +00:00
|
|
|
if (args && IsChannelName(args) && !strpbrk(args, "*?, "))
|
2011-01-06 05:15:36 +00:00
|
|
|
{
|
2011-05-23 03:30:49 +00:00
|
|
|
safelist_channel_named(source_p, args, operspy);
|
2016-03-09 07:37:03 +00:00
|
|
|
return;
|
2011-01-06 05:15:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Multiple channels, possibly with parameters. */
|
|
|
|
params = rb_malloc(sizeof(struct ListClient));
|
|
|
|
|
2015-12-27 04:23:28 +00:00
|
|
|
params->users_min = ConfigChannel.displayed_usercount;
|
2011-01-06 05:15:36 +00:00
|
|
|
params->users_max = INT_MAX;
|
2011-05-23 03:30:49 +00:00
|
|
|
params->operspy = operspy;
|
2014-03-03 04:25:47 +00:00
|
|
|
params->created_min = params->topic_min =
|
2011-01-06 05:15:36 +00:00
|
|
|
params->created_max = params->topic_max = 0;
|
2021-10-18 17:26:05 +00:00
|
|
|
params->mask = NULL;
|
|
|
|
params->nomask = NULL;
|
2007-01-25 06:40:21 +00:00
|
|
|
|
2011-05-23 03:30:49 +00:00
|
|
|
if (args && !EmptyString(args))
|
2007-01-25 06:40:21 +00:00
|
|
|
{
|
2011-01-06 02:57:27 +00:00
|
|
|
/* Cancel out default minimum. */
|
2011-01-06 05:15:36 +00:00
|
|
|
params->users_min = 0;
|
2007-01-25 06:40:21 +00:00
|
|
|
|
2011-01-06 05:15:36 +00:00
|
|
|
for (i = 0; i < 7; i++)
|
2007-01-25 06:40:21 +00:00
|
|
|
{
|
|
|
|
if ((p = strchr(args, ',')) != NULL)
|
|
|
|
*p++ = '\0';
|
|
|
|
|
|
|
|
if (*args == '<')
|
|
|
|
{
|
|
|
|
args++;
|
2021-10-19 22:56:22 +00:00
|
|
|
if (!IsDigit(*args)) goto fail;
|
|
|
|
|
|
|
|
params->users_max = atoi(args);
|
|
|
|
if (params->users_max == 0)
|
|
|
|
params->users_max = INT_MAX;
|
|
|
|
else
|
|
|
|
params->users_max--;
|
2007-01-25 06:40:21 +00:00
|
|
|
}
|
|
|
|
else if (*args == '>')
|
|
|
|
{
|
|
|
|
args++;
|
|
|
|
if (IsDigit(*args))
|
2011-01-06 05:15:36 +00:00
|
|
|
params->users_min = atoi(args) + 1;
|
2021-10-19 22:56:22 +00:00
|
|
|
else if (args[0] == '-' && IsDigit(args[1]))
|
2011-01-06 05:15:36 +00:00
|
|
|
params->users_min = 0;
|
2021-10-19 22:56:22 +00:00
|
|
|
else
|
|
|
|
goto fail;
|
2011-01-06 05:15:36 +00:00
|
|
|
}
|
|
|
|
else if (*args == 'C' || *args == 'c')
|
|
|
|
{
|
|
|
|
args++;
|
|
|
|
if (*args == '>')
|
|
|
|
{
|
|
|
|
/* Creation time earlier than last x minutes. */
|
|
|
|
args++;
|
2021-10-19 22:56:22 +00:00
|
|
|
if (!IsDigit(*args)) goto fail;
|
|
|
|
params->created_max = rb_current_time() - (60 * atoi(args));
|
2011-01-06 05:15:36 +00:00
|
|
|
}
|
|
|
|
else if (*args == '<')
|
|
|
|
{
|
|
|
|
/* Creation time within last x minutes. */
|
|
|
|
args++;
|
2021-10-19 22:56:22 +00:00
|
|
|
if (!IsDigit(*args)) goto fail;
|
|
|
|
params->created_min = rb_current_time() - (60 * atoi(args));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
goto fail;
|
2011-01-06 05:15:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (*args == 'T' || *args == 't')
|
|
|
|
{
|
|
|
|
args++;
|
|
|
|
if (*args == '>')
|
|
|
|
{
|
|
|
|
/* Topic change time earlier than last x minutes. */
|
|
|
|
args++;
|
2021-10-19 22:56:22 +00:00
|
|
|
if (!IsDigit(*args)) goto fail;
|
|
|
|
params->topic_max = rb_current_time() - (60 * atoi(args));
|
2011-01-06 05:15:36 +00:00
|
|
|
}
|
|
|
|
else if (*args == '<')
|
|
|
|
{
|
|
|
|
/* Topic change time within last x minutes. */
|
|
|
|
args++;
|
2021-10-19 22:56:22 +00:00
|
|
|
if (!IsDigit(*args)) goto fail;
|
|
|
|
params->topic_min = rb_current_time() - (60 * atoi(args));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
goto fail;
|
2011-01-06 05:15:36 +00:00
|
|
|
}
|
2007-01-25 06:40:21 +00:00
|
|
|
}
|
2021-10-18 17:26:05 +00:00
|
|
|
else if (*args == '!')
|
|
|
|
{
|
|
|
|
args++;
|
|
|
|
rb_free(params->nomask);
|
|
|
|
params->nomask = rb_strdup(args);
|
|
|
|
}
|
|
|
|
else if (*args == '?' || *args == '*' || IsChanPrefix(*args))
|
|
|
|
{
|
|
|
|
rb_free(params->mask);
|
|
|
|
params->mask = rb_strdup(args);
|
|
|
|
}
|
2021-10-19 22:56:22 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
goto fail;
|
|
|
|
}
|
2007-01-25 06:40:21 +00:00
|
|
|
|
|
|
|
if (EmptyString(p))
|
|
|
|
break;
|
|
|
|
else
|
|
|
|
args = p;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-01-06 05:15:36 +00:00
|
|
|
safelist_client_instantiate(source_p, params);
|
2021-10-19 22:56:22 +00:00
|
|
|
return;
|
2007-01-25 06:40:21 +00:00
|
|
|
|
2021-10-19 22:56:22 +00:00
|
|
|
fail:
|
|
|
|
rb_free(params);
|
|
|
|
sendto_one(source_p, form_str(RPL_LISTSTART), me.name, source_p->name);
|
|
|
|
sendto_one_notice(source_p, ":Invalid parameters for /LIST");
|
|
|
|
sendto_one(source_p, form_str(RPL_LISTEND), me.name, source_p->name);
|
2007-01-25 06:40:21 +00:00
|
|
|
}
|
|
|
|
|
2012-04-28 22:44:33 +00:00
|
|
|
/*
|
|
|
|
* list_one_channel()
|
|
|
|
*
|
|
|
|
* inputs - client pointer, channel pointer, whether normally visible
|
|
|
|
* outputs - none
|
|
|
|
* side effects - a channel is listed
|
|
|
|
*/
|
|
|
|
static void list_one_channel(struct Client *source_p, struct Channel *chptr,
|
|
|
|
int visible)
|
|
|
|
{
|
|
|
|
char topic[TOPICLEN + 1];
|
|
|
|
|
|
|
|
if (chptr->topic != NULL)
|
|
|
|
rb_strlcpy(topic, chptr->topic, sizeof topic);
|
|
|
|
else
|
|
|
|
topic[0] = '\0';
|
|
|
|
strip_colour(topic);
|
|
|
|
sendto_one(source_p, form_str(RPL_LIST), me.name, source_p->name,
|
|
|
|
visible ? "" : "!",
|
|
|
|
chptr->chname, rb_dlink_list_length(&chptr->members),
|
|
|
|
topic);
|
|
|
|
}
|
|
|
|
|
2007-01-25 06:40:21 +00:00
|
|
|
/*
|
|
|
|
* safelist_sendq_exceeded()
|
|
|
|
*
|
|
|
|
* inputs - pointer to client that needs checking
|
2016-03-09 07:37:03 +00:00
|
|
|
* outputs - true if a client has exceeded the reserved
|
|
|
|
* sendq limit, false if not
|
2007-01-25 06:40:21 +00:00
|
|
|
* side effects - none
|
|
|
|
*
|
|
|
|
* When safelisting, we only use half of the SendQ at any
|
|
|
|
* given time.
|
|
|
|
*/
|
2016-03-09 07:37:03 +00:00
|
|
|
static bool safelist_sendq_exceeded(struct Client *client_p)
|
2007-01-25 06:40:21 +00:00
|
|
|
{
|
2016-03-09 07:37:03 +00:00
|
|
|
return rb_linebuf_len(&client_p->localClient->buf_sendq) > (get_sendq(client_p) / 2);
|
2007-01-25 06:40:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* safelist_client_instantiate()
|
|
|
|
*
|
|
|
|
* inputs - pointer to Client to be listed,
|
2011-01-06 05:15:36 +00:00
|
|
|
* pointer to ListClient for params
|
2007-01-25 06:40:21 +00:00
|
|
|
* outputs - none
|
|
|
|
* side effects - the safelist process begins for a
|
|
|
|
* client.
|
|
|
|
*
|
|
|
|
* Please do not ever call this on a non-local client.
|
|
|
|
* If you do, you will get SIGSEGV.
|
|
|
|
*/
|
|
|
|
static void safelist_client_instantiate(struct Client *client_p, struct ListClient *params)
|
|
|
|
{
|
2021-10-19 12:30:03 +00:00
|
|
|
struct Channel *chptr;
|
|
|
|
|
2007-01-25 06:40:21 +00:00
|
|
|
s_assert(MyClient(client_p));
|
|
|
|
s_assert(params != NULL);
|
|
|
|
|
2011-01-06 05:15:36 +00:00
|
|
|
client_p->localClient->safelist_data = params;
|
2007-01-25 06:40:21 +00:00
|
|
|
|
|
|
|
sendto_one(client_p, form_str(RPL_LISTSTART), me.name, client_p->name);
|
|
|
|
|
|
|
|
/* pop the client onto the queue for processing */
|
2008-04-01 21:12:16 +00:00
|
|
|
rb_dlinkAddAlloc(client_p, &safelisting_clients);
|
2007-01-25 06:40:21 +00:00
|
|
|
|
|
|
|
/* give the user some initial data to work with */
|
2021-10-19 12:30:03 +00:00
|
|
|
if (params->mask && (chptr = find_channel(params->mask)))
|
|
|
|
{
|
|
|
|
bool visible = !SecretChannel(chptr) || IsMember(client_p, chptr);
|
|
|
|
if (visible || params->operspy)
|
|
|
|
list_one_channel(client_p, chptr, visible);
|
|
|
|
}
|
2007-01-25 06:40:21 +00:00
|
|
|
safelist_iterate_client(client_p);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* safelist_client_release()
|
|
|
|
*
|
|
|
|
* inputs - pointer to Client being listed on
|
|
|
|
* outputs - none
|
|
|
|
* side effects - the client is no longer being
|
|
|
|
* listed
|
|
|
|
*/
|
|
|
|
static void safelist_client_release(struct Client *client_p)
|
|
|
|
{
|
2016-03-09 07:37:03 +00:00
|
|
|
if(!MyClient(client_p))
|
|
|
|
return;
|
|
|
|
|
2007-01-25 06:40:21 +00:00
|
|
|
s_assert(MyClient(client_p));
|
|
|
|
|
2008-04-01 20:54:08 +00:00
|
|
|
rb_dlinkFindDestroy(client_p, &safelisting_clients);
|
2007-01-25 06:40:21 +00:00
|
|
|
|
2016-01-21 03:26:55 +00:00
|
|
|
rb_free(client_p->localClient->safelist_data->chname);
|
2021-10-18 17:26:05 +00:00
|
|
|
rb_free(client_p->localClient->safelist_data->mask);
|
|
|
|
rb_free(client_p->localClient->safelist_data->nomask);
|
2008-04-01 22:47:17 +00:00
|
|
|
rb_free(client_p->localClient->safelist_data);
|
2007-01-25 06:40:21 +00:00
|
|
|
|
|
|
|
client_p->localClient->safelist_data = NULL;
|
|
|
|
|
|
|
|
sendto_one(client_p, form_str(RPL_LISTEND), me.name, client_p->name);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* safelist_channel_named()
|
|
|
|
*
|
2011-05-23 03:30:49 +00:00
|
|
|
* inputs - client pointer, channel name, operspy
|
2007-01-25 06:40:21 +00:00
|
|
|
* outputs - none
|
|
|
|
* side effects - a named channel is listed
|
|
|
|
*/
|
2011-05-23 03:30:49 +00:00
|
|
|
static void safelist_channel_named(struct Client *source_p, const char *name, int operspy)
|
2007-01-25 06:40:21 +00:00
|
|
|
{
|
|
|
|
struct Channel *chptr;
|
|
|
|
char *p;
|
2011-05-23 22:30:45 +00:00
|
|
|
int visible;
|
2007-01-25 06:40:21 +00:00
|
|
|
|
|
|
|
sendto_one(source_p, form_str(RPL_LISTSTART), me.name, source_p->name);
|
|
|
|
|
2011-05-23 03:30:49 +00:00
|
|
|
if ((p = strchr(name, ',')))
|
2007-01-25 06:40:21 +00:00
|
|
|
*p = '\0';
|
|
|
|
|
2011-05-23 03:30:49 +00:00
|
|
|
if (*name == '\0')
|
2007-01-25 06:40:21 +00:00
|
|
|
{
|
|
|
|
sendto_one_numeric(source_p, ERR_NOSUCHNICK, form_str(ERR_NOSUCHNICK), name);
|
|
|
|
sendto_one(source_p, form_str(RPL_LISTEND), me.name, source_p->name);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-05-23 03:30:49 +00:00
|
|
|
chptr = find_channel(name);
|
2007-01-25 06:40:21 +00:00
|
|
|
|
|
|
|
if (chptr == NULL)
|
|
|
|
{
|
2011-05-23 03:30:49 +00:00
|
|
|
sendto_one_numeric(source_p, ERR_NOSUCHNICK, form_str(ERR_NOSUCHNICK), name);
|
2007-01-25 06:40:21 +00:00
|
|
|
sendto_one(source_p, form_str(RPL_LISTEND), me.name, source_p->name);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-05-23 22:30:45 +00:00
|
|
|
visible = !SecretChannel(chptr) || IsMember(source_p, chptr);
|
|
|
|
if (visible || operspy)
|
2012-04-28 22:44:33 +00:00
|
|
|
list_one_channel(source_p, chptr, visible);
|
2007-01-25 06:40:21 +00:00
|
|
|
|
|
|
|
sendto_one(source_p, form_str(RPL_LISTEND), me.name, source_p->name);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* safelist_one_channel()
|
|
|
|
*
|
|
|
|
* inputs - client pointer and channel pointer
|
|
|
|
* outputs - none
|
|
|
|
* side effects - a channel is listed if it meets the
|
|
|
|
* requirements
|
|
|
|
*/
|
2016-01-21 03:26:55 +00:00
|
|
|
static void safelist_one_channel(struct Client *source_p, struct Channel *chptr, struct ListClient *params)
|
2007-01-25 06:40:21 +00:00
|
|
|
{
|
2011-05-23 22:30:45 +00:00
|
|
|
int visible;
|
2007-01-25 06:40:21 +00:00
|
|
|
|
2011-05-23 22:30:45 +00:00
|
|
|
visible = !SecretChannel(chptr) || IsMember(source_p, chptr);
|
2016-01-10 05:34:52 +00:00
|
|
|
if (!visible && !params->operspy)
|
2007-01-25 06:40:21 +00:00
|
|
|
return;
|
|
|
|
|
2016-01-10 05:34:52 +00:00
|
|
|
if ((unsigned int)chptr->members.length < params->users_min
|
|
|
|
|| (unsigned int)chptr->members.length > params->users_max)
|
2007-01-25 06:40:21 +00:00
|
|
|
return;
|
|
|
|
|
2016-01-10 05:34:52 +00:00
|
|
|
if (params->topic_min && chptr->topic_time < params->topic_min)
|
2011-01-06 05:15:36 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
/* If a topic TS is provided, don't show channels without a topic set. */
|
2016-01-10 05:34:52 +00:00
|
|
|
if (params->topic_max && (chptr->topic_time > params->topic_max
|
2011-01-06 05:15:36 +00:00
|
|
|
|| chptr->topic_time == 0))
|
|
|
|
return;
|
|
|
|
|
2016-01-10 05:34:52 +00:00
|
|
|
if (params->created_min && chptr->channelts < params->created_min)
|
2011-01-06 05:15:36 +00:00
|
|
|
return;
|
|
|
|
|
2016-01-10 05:34:52 +00:00
|
|
|
if (params->created_max && chptr->channelts > params->created_max)
|
2011-01-06 05:15:36 +00:00
|
|
|
return;
|
|
|
|
|
2021-10-19 12:30:03 +00:00
|
|
|
if (params->mask && (!irccmp(params->mask, chptr->chname) || !match(params->mask, chptr->chname)))
|
2021-10-18 17:26:05 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
if (params->nomask && match(params->nomask, chptr->chname))
|
2011-01-06 05:15:36 +00:00
|
|
|
return;
|
|
|
|
|
2012-04-28 22:44:33 +00:00
|
|
|
list_one_channel(source_p, chptr, visible);
|
2007-01-25 06:40:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* safelist_iterate_client()
|
|
|
|
*
|
|
|
|
* inputs - client pointer
|
|
|
|
* outputs - none
|
|
|
|
* side effects - the client's sendq is filled up again
|
|
|
|
*/
|
|
|
|
static void safelist_iterate_client(struct Client *source_p)
|
|
|
|
{
|
2016-01-21 03:26:55 +00:00
|
|
|
struct Channel *chptr;
|
2016-03-23 13:32:22 +00:00
|
|
|
rb_radixtree_iteration_state iter;
|
2007-01-25 06:40:21 +00:00
|
|
|
|
2016-03-06 20:17:19 +00:00
|
|
|
RB_RADIXTREE_FOREACH_FROM(chptr, &iter, channel_tree, source_p->localClient->safelist_data->chname)
|
2007-01-25 06:40:21 +00:00
|
|
|
{
|
2016-03-09 07:37:03 +00:00
|
|
|
if (safelist_sendq_exceeded(source_p->from))
|
2007-01-25 06:40:21 +00:00
|
|
|
{
|
2016-01-22 21:07:55 +00:00
|
|
|
rb_free(source_p->localClient->safelist_data->chname);
|
2016-01-21 03:26:55 +00:00
|
|
|
source_p->localClient->safelist_data->chname = rb_strdup(chptr->chname);
|
2016-01-22 21:07:55 +00:00
|
|
|
|
2007-01-25 06:40:21 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-01-21 03:26:55 +00:00
|
|
|
safelist_one_channel(source_p, chptr, source_p->localClient->safelist_data);
|
2007-01-25 06:40:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
safelist_client_release(source_p);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void safelist_iterate_clients(void *unused)
|
|
|
|
{
|
2008-04-01 20:18:48 +00:00
|
|
|
rb_dlink_node *n, *n2;
|
2007-01-25 06:40:21 +00:00
|
|
|
|
2014-03-03 04:25:47 +00:00
|
|
|
RB_DLINK_FOREACH_SAFE(n, n2, safelisting_clients.head)
|
2007-01-25 06:40:21 +00:00
|
|
|
safelist_iterate_client((struct Client *)n->data);
|
|
|
|
}
|