2007-01-25 07:40:21 +01:00
|
|
|
/*
|
|
|
|
* charybdis: A slightly useful ircd.
|
|
|
|
* extban.c: extended ban types ($type:data)
|
|
|
|
*
|
|
|
|
* Copyright (C) 2006 charybdis development team
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
|
|
|
* USA
|
|
|
|
*/
|
|
|
|
|
2016-08-17 05:01:20 +02:00
|
|
|
namespace chan = ircd::chan;
|
|
|
|
namespace mode = chan::mode;
|
|
|
|
namespace ext = mode::ext;
|
|
|
|
using namespace ext;
|
2016-08-13 05:05:54 +02:00
|
|
|
|
2016-08-17 05:01:20 +02:00
|
|
|
ext::func ext::table[256] = { NULL };
|
2007-01-25 07:40:21 +01:00
|
|
|
|
|
|
|
int
|
2016-08-22 03:57:43 +02:00
|
|
|
chan::match_extban(const char *banstr, client::client *client_p, chan *chptr, long mode_type)
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
|
|
|
const char *p;
|
2016-08-17 05:01:20 +02:00
|
|
|
int invert(0), result(INVALID);
|
|
|
|
func f;
|
2007-01-25 07:40:21 +01:00
|
|
|
|
|
|
|
if (*banstr != '$')
|
|
|
|
return 0;
|
|
|
|
p = banstr + 1;
|
|
|
|
if (*p == '~')
|
|
|
|
{
|
|
|
|
invert = 1;
|
|
|
|
p++;
|
|
|
|
}
|
2016-08-17 05:01:20 +02:00
|
|
|
f = table[uint8_t(rfc1459::tolower(*p))];
|
2007-01-25 07:40:21 +01:00
|
|
|
if (*p != '\0')
|
|
|
|
{
|
|
|
|
p++;
|
|
|
|
if (*p == ':')
|
|
|
|
p++;
|
|
|
|
else
|
|
|
|
p = NULL;
|
|
|
|
}
|
|
|
|
if (f != NULL)
|
2016-08-17 05:01:20 +02:00
|
|
|
result = f(p, client_p, chptr, mode::type(mode_type));
|
2007-01-25 07:40:21 +01:00
|
|
|
else
|
2016-08-17 05:01:20 +02:00
|
|
|
result = INVALID;
|
2007-01-25 07:40:21 +01:00
|
|
|
|
|
|
|
if (invert)
|
2016-08-17 05:01:20 +02:00
|
|
|
return result == NOMATCH;
|
2007-01-25 07:40:21 +01:00
|
|
|
else
|
2016-08-17 05:01:20 +02:00
|
|
|
return result == MATCH;
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2016-08-22 03:57:43 +02:00
|
|
|
chan::valid_extban(const char *banstr, client::client *client_p, chan *chptr, long mode_type)
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
|
|
|
const char *p;
|
2016-08-17 05:01:20 +02:00
|
|
|
int result(INVALID);
|
|
|
|
func f;
|
2007-01-25 07:40:21 +01:00
|
|
|
|
|
|
|
if (*banstr != '$')
|
|
|
|
return 0;
|
|
|
|
p = banstr + 1;
|
|
|
|
if (*p == '~')
|
|
|
|
p++;
|
2016-08-17 05:01:20 +02:00
|
|
|
f = table[uint8_t(rfc1459::tolower(*p))];
|
2007-01-25 07:40:21 +01:00
|
|
|
if (*p != '\0')
|
|
|
|
{
|
|
|
|
p++;
|
|
|
|
if (*p == ':')
|
|
|
|
p++;
|
|
|
|
else
|
|
|
|
p = NULL;
|
|
|
|
}
|
|
|
|
if (f != NULL)
|
2016-08-17 05:01:20 +02:00
|
|
|
result = f(p, client_p, chptr, mode::type(mode_type));
|
2007-01-25 07:40:21 +01:00
|
|
|
else
|
2016-08-17 05:01:20 +02:00
|
|
|
result = INVALID;
|
2007-01-25 07:40:21 +01:00
|
|
|
|
2016-08-17 05:01:20 +02:00
|
|
|
return result != INVALID;
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
const char *
|
2016-08-18 07:33:38 +02:00
|
|
|
chan::get_extban_string(void)
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
|
|
|
static char e[256];
|
|
|
|
int i, j;
|
|
|
|
|
|
|
|
j = 0;
|
|
|
|
for (i = 1; i < 256; i++)
|
2016-08-17 05:01:20 +02:00
|
|
|
if (i == rfc1459::tolower(i) && table[i])
|
2007-01-25 07:40:21 +01:00
|
|
|
e[j++] = i;
|
|
|
|
e[j] = 0;
|
|
|
|
return e;
|
|
|
|
}
|