0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-11-17 15:30:52 +01:00

Refactor chmode into namespace.

She's still a bit of a mess.
This commit is contained in:
Jason Volk 2016-08-16 20:01:20 -07:00
parent f112111e51
commit 03660fc4b0
43 changed files with 577 additions and 487 deletions

View file

@ -10,12 +10,14 @@ mapi_hfn_list_av1 adminonly_hfnlist[] = {
{ NULL, NULL } { NULL, NULL }
}; };
static unsigned int mymode; static chan::mode::type mymode;
static int static int
_modinit(void) _modinit(void)
{ {
mymode = cflag_add('A', CHM_D, chm_staff); using namespace chan::mode;
mymode = add('A', category::D, functor::staff);
if (mymode == 0) if (mymode == 0)
return -1; return -1;
@ -25,7 +27,7 @@ _modinit(void)
static void static void
_moddeinit(void) _moddeinit(void)
{ {
cflag_orphan('A'); chan::mode::orphan('A');
} }
DECLARE_MODULE_AV2(chm_adminonly, _modinit, _moddeinit, NULL, NULL, adminonly_hfnlist, NULL, NULL, chm_adminonly_desc); DECLARE_MODULE_AV2(chm_adminonly, _modinit, _moddeinit, NULL, NULL, adminonly_hfnlist, NULL, NULL, chm_adminonly_desc);
@ -38,7 +40,7 @@ h_can_join(hook_data_channel *data)
if((chptr->mode.mode & mymode) && !IsAdmin(source_p)) { if((chptr->mode.mode & mymode) && !IsAdmin(source_p)) {
sendto_one_numeric(source_p, 519, "%s :Cannot join channel (+A) - you are not an IRC server administrator", chptr->chname); sendto_one_numeric(source_p, 519, "%s :Cannot join channel (+A) - you are not an IRC server administrator", chptr->chname);
data->approved = ERR_CUSTOM; data->approved = chan::mode::ERR_CUSTOM;
} }
} }

View file

@ -11,12 +11,14 @@ mapi_hfn_list_av1 sslonly_hfnlist[] = {
{ NULL, NULL } { NULL, NULL }
}; };
static unsigned int mymode; static chan::mode::type mymode;
static int static int
_modinit(void) _modinit(void)
{ {
mymode = cflag_add('U', CHM_D, chm_simple); using namespace chan::mode;
mymode = add('U', category::D, functor::simple);
if (mymode == 0) if (mymode == 0)
return -1; return -1;
@ -27,7 +29,7 @@ _modinit(void)
static void static void
_moddeinit(void) _moddeinit(void)
{ {
cflag_orphan('U'); chan::mode::orphan('U');
} }
DECLARE_MODULE_AV2(chm_insecure, _modinit, _moddeinit, NULL, NULL, sslonly_hfnlist, NULL, NULL, chm_insecure_desc); DECLARE_MODULE_AV2(chm_insecure, _modinit, _moddeinit, NULL, NULL, sslonly_hfnlist, NULL, NULL, chm_insecure_desc);
@ -41,7 +43,7 @@ h_can_join(hook_data_channel *data)
if(!(chptr->mode.mode & mymode) && !IsSSLClient(source_p)) { if(!(chptr->mode.mode & mymode) && !IsSSLClient(source_p)) {
/* XXX This is equal to ERR_THROTTLE */ /* XXX This is equal to ERR_THROTTLE */
sendto_one_numeric(source_p, 480, "%s :Cannot join channel (-U) - SSL/TLS required", chptr->chname); sendto_one_numeric(source_p, 480, "%s :Cannot join channel (-U) - SSL/TLS required", chptr->chname);
data->approved = ERR_CUSTOM; data->approved = chan::mode::ERR_CUSTOM;
} }
} }

View file

@ -26,7 +26,7 @@ using namespace ircd;
static const char chm_nonotice_desc[] = static const char chm_nonotice_desc[] =
"Adds channel mode +T which blocks notices to the channel."; "Adds channel mode +T which blocks notices to the channel.";
static unsigned int mode_nonotice; static chan::mode::type mode_nonotice;
static void chm_nonotice_process(hook_data_privmsg_channel *); static void chm_nonotice_process(hook_data_privmsg_channel *);
@ -54,7 +54,9 @@ chm_nonotice_process(hook_data_privmsg_channel *data)
static int static int
_modinit(void) _modinit(void)
{ {
mode_nonotice = cflag_add('T', CHM_D, chm_simple); using namespace chan::mode;
mode_nonotice = add('T', category::D, functor::simple);
if (mode_nonotice == 0) if (mode_nonotice == 0)
return -1; return -1;
@ -64,7 +66,7 @@ _modinit(void)
static void static void
_moddeinit(void) _moddeinit(void)
{ {
cflag_orphan('T'); chan::mode::orphan('T');
} }
DECLARE_MODULE_AV2(chm_nonotice, _modinit, _moddeinit, NULL, NULL, chm_nonotice_hfnlist, NULL, NULL, chm_nonotice_desc); DECLARE_MODULE_AV2(chm_nonotice, _modinit, _moddeinit, NULL, NULL, chm_nonotice_hfnlist, NULL, NULL, chm_nonotice_desc);

View file

@ -1,4 +1,3 @@
using namespace ircd; using namespace ircd;
static const char chm_operonly_desc[] = static const char chm_operonly_desc[] =
@ -11,12 +10,14 @@ mapi_hfn_list_av1 operonly_hfnlist[] = {
{ NULL, NULL } { NULL, NULL }
}; };
static unsigned int mymode; static chan::mode::type mymode;
static int static int
_modinit(void) _modinit(void)
{ {
mymode = cflag_add('O', CHM_D, chm_staff); using namespace chan::mode;
mymode = add('O', category::D, functor::staff);
if (mymode == 0) if (mymode == 0)
return -1; return -1;
@ -27,7 +28,7 @@ _modinit(void)
static void static void
_moddeinit(void) _moddeinit(void)
{ {
cflag_orphan('O'); chan::mode::orphan('O');
} }
DECLARE_MODULE_AV2(chm_operonly, _modinit, _moddeinit, NULL, NULL, operonly_hfnlist, NULL, NULL, chm_operonly_desc); DECLARE_MODULE_AV2(chm_operonly, _modinit, _moddeinit, NULL, NULL, operonly_hfnlist, NULL, NULL, chm_operonly_desc);
@ -40,7 +41,7 @@ h_can_join(hook_data_channel *data)
if((chptr->mode.mode & mymode) && !IsOper(source_p)) { if((chptr->mode.mode & mymode) && !IsOper(source_p)) {
sendto_one_numeric(source_p, 520, "%s :Cannot join channel (+O) - you are not an IRC operator", chptr->chname); sendto_one_numeric(source_p, 520, "%s :Cannot join channel (+O) - you are not an IRC operator", chptr->chname);
data->approved = ERR_CUSTOM; data->approved = chan::mode::ERR_CUSTOM;
} }
} }

View file

@ -2,6 +2,7 @@
* Treat cmode +-O as +-iI $o. * Treat cmode +-O as +-iI $o.
*/ */
using namespace ircd::chan::mode;
using namespace ircd; using namespace ircd;
static const char chm_operonly_compat[] = static const char chm_operonly_compat[] =
@ -11,16 +12,16 @@ static int _modinit(void);
static void _moddeinit(void); static void _moddeinit(void);
static void chm_operonly(struct Client *source_p, struct Channel *chptr, static void chm_operonly(struct Client *source_p, struct Channel *chptr,
int alevel, int parc, int *parn, int alevel, int parc, int *parn,
const char **parv, int *errors, int dir, char c, long mode_type); const char **parv, int *errors, int dir, char c, type type);
DECLARE_MODULE_AV2(chm_operonly_compat, _modinit, _moddeinit, NULL, NULL, NULL, NULL, NULL, chm_operonly_compat); DECLARE_MODULE_AV2(chm_operonly_compat, _modinit, _moddeinit, NULL, NULL, NULL, NULL, NULL, chm_operonly_compat);
static int static int
_modinit(void) _modinit(void)
{ {
chmode_table['O'].set_func = chm_operonly; table['O'].type = type(0);
chmode_table['O'].mode_type = 0; table['O'].category = category::D;
chmode_table['O'].mode_class = ChmClass{CHM_D}; table['O'].set_func = chm_operonly;
return 0; return 0;
} }
@ -28,25 +29,23 @@ _modinit(void)
static void static void
_moddeinit(void) _moddeinit(void)
{ {
chmode_table['O'].set_func = chm_nosuch; table['O'].type = type(0);
chmode_table['O'].mode_type = 0; table['O'].category = category::D;
chmode_table['O'].mode_class = ChmClass(0); table['O'].set_func = functor::nosuch;
} }
static void static void
chm_operonly(struct Client *source_p, struct Channel *chptr, chm_operonly(struct Client *source_p, struct Channel *chptr,
int alevel, int parc, int *parn, int alevel, int parc, int *parn,
const char **parv, int *errors, int dir, char c, long mode_type) const char **parv, int *errors, int dir, char c, type type)
{ {
int newparn = 0; int newparn = 0;
const char *newparv[] = { "$o" }; const char *newparv[] = { "$o" };
if (MyClient(source_p)) { if (MyClient(source_p))
chm_simple(source_p, chptr, alevel, parc, parn, parv, {
errors, dir, 'i', MODE_INVITEONLY); functor::simple(source_p, chptr, alevel, parc, parn, parv, errors, dir, 'i', INVITEONLY);
chm_ban(source_p, chptr, alevel, 1, &newparn, newparv, functor::ban(source_p, chptr, alevel, 1, &newparn, newparv, errors, dir, 'I', INVEX);
errors, dir, 'I', CHFL_INVEX);
} else } else
chm_nosuch(source_p, chptr, alevel, parc, parn, parv, functor::nosuch(source_p, chptr, alevel, parc, parn, parv, errors, dir, c, type);
errors, dir, c, mode_type);
} }

View file

@ -15,12 +15,14 @@ mapi_hfn_list_av1 chm_operpeace_hfnlist[] = {
{ NULL, NULL } { NULL, NULL }
}; };
static unsigned int mymode; static chan::mode::type mymode;
static int static int
_modinit(void) _modinit(void)
{ {
mymode = cflag_add('M', CHM_D, chm_hidden); using namespace chan::mode;
mymode = add('M', category::D, functor::hidden);
if (mymode == 0) if (mymode == 0)
return -1; return -1;
@ -30,7 +32,7 @@ _modinit(void)
static void static void
_moddeinit(void) _moddeinit(void)
{ {
cflag_orphan('M'); chan::mode::orphan('M');
} }
DECLARE_MODULE_AV2(chm_operpeace, _modinit, _moddeinit, NULL, NULL, chm_operpeace_hfnlist, NULL, NULL, chm_operpeace_desc); DECLARE_MODULE_AV2(chm_operpeace, _modinit, _moddeinit, NULL, NULL, chm_operpeace_hfnlist, NULL, NULL, chm_operpeace_desc);

View file

@ -3,6 +3,9 @@
* -- jilles * -- jilles
*/ */
namespace chan = ircd::chan;
namespace mode = chan::mode;
using namespace mode;
using namespace ircd; using namespace ircd;
static const char chm_quietunreg_compat_desc[] = static const char chm_quietunreg_compat_desc[] =
@ -12,16 +15,16 @@ static int _modinit(void);
static void _moddeinit(void); static void _moddeinit(void);
static void chm_quietunreg(struct Client *source_p, struct Channel *chptr, static void chm_quietunreg(struct Client *source_p, struct Channel *chptr,
int alevel, int parc, int *parn, int alevel, int parc, int *parn,
const char **parv, int *errors, int dir, char c, long mode_type); const char **parv, int *errors, int dir, char c, type type);
DECLARE_MODULE_AV2(chm_quietunreg_compat, _modinit, _moddeinit, NULL, NULL, NULL, NULL, NULL, chm_quietunreg_compat_desc); DECLARE_MODULE_AV2(chm_quietunreg_compat, _modinit, _moddeinit, NULL, NULL, NULL, NULL, NULL, chm_quietunreg_compat_desc);
static int static int
_modinit(void) _modinit(void)
{ {
chmode_table['R'].set_func = chm_quietunreg; table['R'].type = type(0);
chmode_table['R'].mode_type = 0; table['R'].category = category::D;
chmode_table['R'].mode_class = CHM_D; table['R'].set_func = chm_quietunreg;
return 0; return 0;
} }
@ -29,23 +32,21 @@ _modinit(void)
static void static void
_moddeinit(void) _moddeinit(void)
{ {
chmode_table['R'].set_func = chm_nosuch; table['R'].type = type(0);
chmode_table['R'].mode_type = 0; table['R'].category = category(0);
chmode_table['R'].mode_class = ChmClass(0); table['R'].set_func = functor::nosuch;
} }
static void static void
chm_quietunreg(struct Client *source_p, struct Channel *chptr, chm_quietunreg(struct Client *source_p, struct Channel *chptr,
int alevel, int parc, int *parn, int alevel, int parc, int *parn,
const char **parv, int *errors, int dir, char c, long mode_type) const char **parv, int *errors, int dir, char c, type type)
{ {
int newparn = 0; int newparn = 0;
const char *newparv[] = { "$~a" }; const char *newparv[] = { "$~a" };
if (MyClient(source_p)) if (MyClient(source_p))
chm_ban(source_p, chptr, alevel, 1, &newparn, newparv, functor::ban(source_p, chptr, alevel, 1, &newparn, newparv, errors, dir, 'q', QUIET);
errors, dir, 'q', CHFL_QUIET);
else else
chm_nosuch(source_p, chptr, alevel, parc, parn, parv, functor::nosuch(source_p, chptr, alevel, parc, parn, parv, errors, dir, c, type);
errors, dir, c, mode_type);
} }

View file

@ -108,7 +108,9 @@ struct ConfEntry conf_spamfilter[] =
static static
int modinit(void) int modinit(void)
{ {
chm_spamfilter = cflag_add(MODE_SPAMFILTER, CHM_D, chm_simple); using namespace chan::mode;
chm_spamfilter = add(MODE_SPAMFILTER, category::D, functor::simple);
if(!chm_spamfilter) if(!chm_spamfilter)
return -1; return -1;
@ -121,7 +123,7 @@ static
void modfini(void) void modfini(void)
{ {
remove_top_conf("spamfilter"); remove_top_conf("spamfilter");
cflag_orphan(MODE_SPAMFILTER); chan::mode::orphan(MODE_SPAMFILTER);
} }

View file

@ -10,12 +10,14 @@ mapi_hfn_list_av1 sslonly_hfnlist[] = {
{ NULL, NULL } { NULL, NULL }
}; };
static unsigned int mymode; static chan::mode::type mymode;
static int static int
_modinit(void) _modinit(void)
{ {
mymode = cflag_add('S', CHM_D, chm_simple); using namespace chan::mode;
mymode = add('S', category::D, functor::simple);
if (mymode == 0) if (mymode == 0)
return -1; return -1;
@ -25,7 +27,7 @@ _modinit(void)
static void static void
_moddeinit(void) _moddeinit(void)
{ {
cflag_orphan('S'); chan::mode::orphan('S');
} }
DECLARE_MODULE_AV2(chm_sslonly, _modinit, _moddeinit, NULL, NULL, sslonly_hfnlist, NULL, NULL, chm_sslonly_desc); DECLARE_MODULE_AV2(chm_sslonly, _modinit, _moddeinit, NULL, NULL, sslonly_hfnlist, NULL, NULL, chm_sslonly_desc);
@ -39,7 +41,7 @@ h_can_join(hook_data_channel *data)
if((chptr->mode.mode & mymode) && !IsSSLClient(source_p)) { if((chptr->mode.mode & mymode) && !IsSSLClient(source_p)) {
/* XXX This is equal to ERR_THROTTLE */ /* XXX This is equal to ERR_THROTTLE */
sendto_one_numeric(source_p, 480, "%s :Cannot join channel (+S) - SSL/TLS required", chptr->chname); sendto_one_numeric(source_p, 480, "%s :Cannot join channel (+S) - SSL/TLS required", chptr->chname);
data->approved = ERR_CUSTOM; data->approved = chan::mode::ERR_CUSTOM;
} }
} }

View file

@ -2,6 +2,7 @@
* Treat cmode +-S as +-b $~z. * Treat cmode +-S as +-b $~z.
*/ */
using namespace ircd::chan::mode;
using namespace ircd; using namespace ircd;
static const char chm_sslonly_compat_desc[] = static const char chm_sslonly_compat_desc[] =
@ -11,16 +12,16 @@ static int _modinit(void);
static void _moddeinit(void); static void _moddeinit(void);
static void chm_sslonly(struct Client *source_p, struct Channel *chptr, static void chm_sslonly(struct Client *source_p, struct Channel *chptr,
int alevel, int parc, int *parn, int alevel, int parc, int *parn,
const char **parv, int *errors, int dir, char c, long mode_type); const char **parv, int *errors, int dir, char c, type type);
DECLARE_MODULE_AV2(chm_sslonly_compat, _modinit, _moddeinit, NULL, NULL, NULL, NULL, NULL, chm_sslonly_compat_desc); DECLARE_MODULE_AV2(chm_sslonly_compat, _modinit, _moddeinit, NULL, NULL, NULL, NULL, NULL, chm_sslonly_compat_desc);
static int static int
_modinit(void) _modinit(void)
{ {
chmode_table['S'].set_func = chm_sslonly; table['S'].type = type(0);
chmode_table['S'].mode_type = 0; table['S'].set_func = chm_sslonly;
chmode_table['S'].mode_class = ChmClass{CHM_D}; table['S'].category = category::D;
return 0; return 0;
} }
@ -28,23 +29,21 @@ _modinit(void)
static void static void
_moddeinit(void) _moddeinit(void)
{ {
chmode_table['S'].set_func = chm_nosuch; table['S'].type = type(0);
chmode_table['S'].mode_type = 0; table['S'].category = category(0);
chmode_table['S'].mode_class = ChmClass(0); table['S'].set_func = functor::nosuch;
} }
static void static void
chm_sslonly(struct Client *source_p, struct Channel *chptr, chm_sslonly(struct Client *source_p, struct Channel *chptr,
int alevel, int parc, int *parn, int alevel, int parc, int *parn,
const char **parv, int *errors, int dir, char c, long mode_type) const char **parv, int *errors, int dir, char c, type type)
{ {
int newparn = 0; int newparn = 0;
const char *newparv[] = { "$~z" }; const char *newparv[] = { "$~z" };
if (MyClient(source_p)) if (MyClient(source_p))
chm_ban(source_p, chptr, alevel, 1, &newparn, newparv, functor::ban(source_p, chptr, alevel, 1, &newparn, newparv, errors, dir, 'b', BAN);
errors, dir, 'b', CHFL_BAN);
else else
chm_nosuch(source_p, chptr, alevel, parc, parn, parv, functor::nosuch(source_p, chptr, alevel, parc, parn, parv, errors, dir, c, type);
errors, dir, c, mode_type);
} }

View file

@ -3,20 +3,23 @@
* -- jilles * -- jilles
*/ */
namespace chan = ircd::chan;
namespace mode = chan::mode;
namespace ext = mode::ext;
using namespace ircd; using namespace ircd;
static const char extb_desc[] = "Account ($a) extban type"; static const char extb_desc[] = "Account ($a) extban type";
static int _modinit(void); static int _modinit(void);
static void _moddeinit(void); static void _moddeinit(void);
static int eb_account(const char *data, struct Client *client_p, struct Channel *chptr, long mode_type); static int eb_account(const char *data, struct Client *client_p, struct Channel *chptr, mode::type);
DECLARE_MODULE_AV2(extb_account, _modinit, _moddeinit, NULL, NULL, NULL, NULL, NULL, extb_desc); DECLARE_MODULE_AV2(extb_account, _modinit, _moddeinit, NULL, NULL, NULL, NULL, NULL, extb_desc);
static int static int
_modinit(void) _modinit(void)
{ {
extban_table['a'] = eb_account; ext::table['a'] = eb_account;
return 0; return 0;
} }
@ -24,17 +27,18 @@ _modinit(void)
static void static void
_moddeinit(void) _moddeinit(void)
{ {
extban_table['a'] = NULL; ext::table['a'] = NULL;
} }
static int eb_account(const char *data, struct Client *client_p, static int eb_account(const char *data, struct Client *client_p,
struct Channel *chptr, long mode_type) struct Channel *chptr, mode::type type)
{ {
using namespace ext;
(void)chptr; (void)chptr;
/* $a alone matches any logged in user */ /* $a alone matches any logged in user */
if (data == NULL) if (data == NULL)
return EmptyString(client_p->user->suser) ? EXTBAN_NOMATCH : EXTBAN_MATCH; return EmptyString(client_p->user->suser) ? NOMATCH : MATCH;
/* $a:MASK matches users logged in under matching account */ /* $a:MASK matches users logged in under matching account */
return match(data, client_p->user->suser) ? EXTBAN_MATCH : EXTBAN_NOMATCH; return match(data, client_p->user->suser) ? MATCH : NOMATCH;
} }

View file

@ -4,20 +4,23 @@
* -- nenolod/jilles * -- nenolod/jilles
*/ */
namespace chan = ircd::chan;
namespace mode = chan::mode;
namespace ext = mode::ext;
using namespace ircd; using namespace ircd;
static const char extb_desc[] = "Can join ($j) extban type - matches users who are or are not banned from a specified channel"; static const char extb_desc[] = "Can join ($j) extban type - matches users who are or are not banned from a specified channel";
static int _modinit(void); static int _modinit(void);
static void _moddeinit(void); static void _moddeinit(void);
static int eb_canjoin(const char *data, struct Client *client_p, struct Channel *chptr, long mode_type); static int eb_canjoin(const char *data, struct Client *client_p, struct Channel *chptr, mode::type type);
DECLARE_MODULE_AV2(extb_canjoin, _modinit, _moddeinit, NULL, NULL, NULL, NULL, NULL, extb_desc); DECLARE_MODULE_AV2(extb_canjoin, _modinit, _moddeinit, NULL, NULL, NULL, NULL, NULL, extb_desc);
static int static int
_modinit(void) _modinit(void)
{ {
extban_table['j'] = eb_canjoin; ext::table['j'] = eb_canjoin;
return 0; return 0;
} }
@ -25,38 +28,39 @@ _modinit(void)
static void static void
_moddeinit(void) _moddeinit(void)
{ {
extban_table['j'] = NULL; ext::table['j'] = NULL;
} }
static int eb_canjoin(const char *data, struct Client *client_p, static int eb_canjoin(const char *data, struct Client *client_p,
struct Channel *chptr, long mode_type) struct Channel *chptr, mode::type type)
{ {
using namespace ext;
struct Channel *chptr2; struct Channel *chptr2;
int ret; int ret;
static int recurse = 0; static int recurse = 0;
(void)mode_type;
/* don't process a $j in a $j'ed list */ /* don't process a $j in a $j'ed list */
if (recurse) if (recurse)
return EXTBAN_INVALID; return INVALID;
if (data == NULL) if (data == NULL)
return EXTBAN_INVALID; return INVALID;
chptr2 = find_channel(data); chptr2 = find_channel(data);
/* must exist, and no point doing this with the same channel */ /* must exist, and no point doing this with the same channel */
if (chptr2 == NULL || chptr2 == chptr) if (chptr2 == NULL || chptr2 == chptr)
return EXTBAN_INVALID; return INVALID;
/* require consistent target */ /* require consistent target */
if (chptr->chname[0] == '#' && data[0] == '&') if (chptr->chname[0] == '#' && data[0] == '&')
return EXTBAN_INVALID; return INVALID;
/* this allows getting some information about ban exceptions /* this allows getting some information about ban exceptions
* but +s/+p doesn't seem the right criterion */ * but +s/+p doesn't seem the right criterion */
#if 0 #if 0
/* privacy! don't allow +s/+p channels to influence another channel */ /* privacy! don't allow +s/+p channels to influence another channel */
if (!PubChannel(chptr2)) if (!PubChannel(chptr2))
return EXTBAN_INVALID; return INVALID;
#endif #endif
recurse = 1; recurse = 1;
ret = is_banned(chptr2, client_p, NULL, NULL, NULL, NULL) == CHFL_BAN ? EXTBAN_MATCH : EXTBAN_NOMATCH; ret = is_banned(chptr2, client_p, NULL, NULL, NULL, NULL) == CHFL_BAN ? MATCH : NOMATCH;
recurse = 0; recurse = 0;
return ret; return ret;
} }

View file

@ -3,20 +3,23 @@
* -- jilles * -- jilles
*/ */
namespace chan = ircd::chan;
namespace mode = chan::mode;
namespace ext = mode::ext;
using namespace ircd; using namespace ircd;
static const char extb_desc[] = "Channel ($c) extban type"; static const char extb_desc[] = "Channel ($c) extban type";
static int _modinit(void); static int _modinit(void);
static void _moddeinit(void); static void _moddeinit(void);
static int eb_channel(const char *data, struct Client *client_p, struct Channel *chptr, long mode_type); static int eb_channel(const char *data, struct Client *client_p, struct Channel *chptr, mode::type type);
DECLARE_MODULE_AV2(extb_channel, _modinit, _moddeinit, NULL, NULL, NULL, NULL, NULL, extb_desc); DECLARE_MODULE_AV2(extb_channel, _modinit, _moddeinit, NULL, NULL, NULL, NULL, NULL, extb_desc);
static int static int
_modinit(void) _modinit(void)
{ {
extban_table['c'] = eb_channel; ext::table['c'] = eb_channel;
return 0; return 0;
} }
@ -24,26 +27,28 @@ _modinit(void)
static void static void
_moddeinit(void) _moddeinit(void)
{ {
extban_table['c'] = NULL; ext::table['c'] = NULL;
} }
static int eb_channel(const char *data, struct Client *client_p, static int eb_channel(const char *data, struct Client *client_p,
struct Channel *chptr, long mode_type) struct Channel *chptr, mode::type type)
{ {
using namespace ext;
struct Channel *chptr2; struct Channel *chptr2;
(void)chptr; (void)chptr;
(void)mode_type;
if (data == NULL) if (data == NULL)
return EXTBAN_INVALID; return INVALID;
chptr2 = find_channel(data); chptr2 = find_channel(data);
if (chptr2 == NULL) if (chptr2 == NULL)
return EXTBAN_INVALID; return INVALID;
/* require consistent target */ /* require consistent target */
if (chptr->chname[0] == '#' && data[0] == '&') if (chptr->chname[0] == '#' && data[0] == '&')
return EXTBAN_INVALID; return INVALID;
/* privacy! don't allow +s/+p channels to influence another channel */ /* privacy! don't allow +s/+p channels to influence another channel */
if (!PubChannel(chptr2) && chptr2 != chptr) if (!PubChannel(chptr2) && chptr2 != chptr)
return EXTBAN_INVALID; return INVALID;
return IsMember(client_p, chptr2) ? EXTBAN_MATCH : EXTBAN_NOMATCH; return IsMember(client_p, chptr2) ? MATCH : NOMATCH;
} }

View file

@ -37,19 +37,22 @@
* I suspect it is, but have done no load testing. * I suspect it is, but have done no load testing.
*/ */
namespace chan = ircd::chan;
namespace mode = chan::mode;
namespace ext = mode::ext;
using namespace ircd; using namespace ircd;
static const char extb_desc[] = "Combination ($&, $|) extban types"; static const char extb_desc[] = "Combination ($&, $|) extban types";
// #define MOD_DEBUG(s) sendto_realops_snomask(SNO_DEBUG, L_NETWIDE, (s)) // #define MOD_DEBUG(s) sendto_realops_snomask(SNO_DEBUG, L_NETWIDE, (s))
#define MOD_DEBUG(s) #define MOD_DEBUG(s)
#define RETURN_INVALID { recursion_depth--; return EXTBAN_INVALID; } #define RETURN_INVALID { recursion_depth--; return INVALID; }
static int _modinit(void); static int _modinit(void);
static void _moddeinit(void); static void _moddeinit(void);
static int eb_or(const char *data, struct Client *client_p, struct Channel *chptr, long mode_type); static int eb_or(const char *data, struct Client *client_p, struct Channel *chptr, mode::type);
static int eb_and(const char *data, struct Client *client_p, struct Channel *chptr, long mode_type); static int eb_and(const char *data, struct Client *client_p, struct Channel *chptr, mode::type);
static int eb_combi(const char *data, struct Client *client_p, struct Channel *chptr, long mode_type, bool is_and); static int eb_combi(const char *data, struct Client *client_p, struct Channel *chptr, mode::type, bool is_and);
static int recursion_depth = 0; static int recursion_depth = 0;
DECLARE_MODULE_AV2(extb_extended, _modinit, _moddeinit, NULL, NULL, NULL, NULL, NULL, extb_desc); DECLARE_MODULE_AV2(extb_extended, _modinit, _moddeinit, NULL, NULL, NULL, NULL, NULL, extb_desc);
@ -57,8 +60,8 @@ DECLARE_MODULE_AV2(extb_extended, _modinit, _moddeinit, NULL, NULL, NULL, NULL,
static int static int
_modinit(void) _modinit(void)
{ {
extban_table['&'] = eb_and; ext::table['&'] = eb_and;
extban_table['|'] = eb_or; ext::table['|'] = eb_or;
return 0; return 0;
} }
@ -66,25 +69,27 @@ _modinit(void)
static void static void
_moddeinit(void) _moddeinit(void)
{ {
extban_table['&'] = NULL; ext::table['&'] = NULL;
extban_table['|'] = NULL; ext::table['|'] = NULL;
} }
static int eb_or(const char *data, struct Client *client_p, static int eb_or(const char *data, struct Client *client_p,
struct Channel *chptr, long mode_type) struct Channel *chptr, mode::type type)
{ {
return eb_combi(data, client_p, chptr, mode_type, false); return eb_combi(data, client_p, chptr, type, false);
} }
static int eb_and(const char *data, struct Client *client_p, static int eb_and(const char *data, struct Client *client_p,
struct Channel *chptr, long mode_type) struct Channel *chptr, mode::type type)
{ {
return eb_combi(data, client_p, chptr, mode_type, true); return eb_combi(data, client_p, chptr, type, true);
} }
static int eb_combi(const char *data, struct Client *client_p, static int eb_combi(const char *data, struct Client *client_p,
struct Channel *chptr, long mode_type, bool is_and) struct Channel *chptr, mode::type type, bool is_and)
{ {
using namespace ext;
const char *p, *banend; const char *p, *banend;
bool have_result = false; bool have_result = false;
int allowed_nodes = 11; int allowed_nodes = 11;
@ -92,12 +97,12 @@ static int eb_combi(const char *data, struct Client *client_p,
if (recursion_depth >= 5) { if (recursion_depth >= 5) {
MOD_DEBUG("combo invalid: recursion depth too high"); MOD_DEBUG("combo invalid: recursion depth too high");
return EXTBAN_INVALID; return INVALID;
} }
if (EmptyString(data)) { if (EmptyString(data)) {
MOD_DEBUG("combo invalid: empty data"); MOD_DEBUG("combo invalid: empty data");
return EXTBAN_INVALID; return INVALID;
} }
datalen = strlen(data); datalen = strlen(data);
@ -106,7 +111,7 @@ static int eb_combi(const char *data, struct Client *client_p,
* could overflow the buffer used below, so... * could overflow the buffer used below, so...
*/ */
MOD_DEBUG("combo invalid: > BANLEN"); MOD_DEBUG("combo invalid: > BANLEN");
return EXTBAN_INVALID; return INVALID;
} }
banend = data + datalen; banend = data + datalen;
@ -115,7 +120,7 @@ static int eb_combi(const char *data, struct Client *client_p,
banend--; banend--;
if (*banend != ')') { if (*banend != ')') {
MOD_DEBUG("combo invalid: starting but no closing paren"); MOD_DEBUG("combo invalid: starting but no closing paren");
return EXTBAN_INVALID; return INVALID;
} }
} else { } else {
p = data; p = data;
@ -124,7 +129,7 @@ static int eb_combi(const char *data, struct Client *client_p,
/* Empty combibans are invalid. */ /* Empty combibans are invalid. */
if (banend == p) { if (banend == p) {
MOD_DEBUG("combo invalid: no data (after removing parens)"); MOD_DEBUG("combo invalid: no data (after removing parens)");
return EXTBAN_INVALID; return INVALID;
} }
/* Implementation note: /* Implementation note:
@ -142,7 +147,7 @@ static int eb_combi(const char *data, struct Client *client_p,
while (--allowed_nodes) { while (--allowed_nodes) {
bool invert = false; bool invert = false;
char *child_data, child_data_buf[BANLEN]; char *child_data, child_data_buf[BANLEN];
ExtbanFunc f; ext::func f;
if (*p == '~') { if (*p == '~') {
invert = true; invert = true;
@ -153,7 +158,7 @@ static int eb_combi(const char *data, struct Client *client_p,
} }
} }
f = extban_table[(unsigned char) *p++]; f = ext::table[uint8_t(*p++)];
if (!f) { if (!f) {
MOD_DEBUG("combo invalid: non-existant child extban"); MOD_DEBUG("combo invalid: non-existant child extban");
RETURN_INVALID; RETURN_INVALID;
@ -222,18 +227,18 @@ static int eb_combi(const char *data, struct Client *client_p,
} }
if (!have_result) { if (!have_result) {
int child_result = f(child_data, client_p, chptr, mode_type); int child_result = f(child_data, client_p, chptr, type);
if (child_result == EXTBAN_INVALID) { if (child_result == INVALID) {
MOD_DEBUG("combo invalid: child invalid"); MOD_DEBUG("combo invalid: child invalid");
RETURN_INVALID; RETURN_INVALID;
} }
/* Convert child_result to a plain boolean result */ /* Convert child_result to a plain boolean result */
if (invert) if (invert)
child_result = child_result == EXTBAN_NOMATCH; child_result = child_result == NOMATCH;
else else
child_result = child_result == EXTBAN_MATCH; child_result = child_result == MATCH;
if (is_and ? !child_result : child_result) if (is_and ? !child_result : child_result)
have_result = true; have_result = true;
@ -262,7 +267,7 @@ static int eb_combi(const char *data, struct Client *client_p,
recursion_depth--; recursion_depth--;
if (is_and) if (is_and)
return have_result ? EXTBAN_NOMATCH : EXTBAN_MATCH; return have_result ? NOMATCH : MATCH;
else else
return have_result ? EXTBAN_MATCH : EXTBAN_NOMATCH; return have_result ? MATCH : NOMATCH;
} }

View file

@ -4,20 +4,23 @@
* - nenolod * - nenolod
*/ */
namespace chan = ircd::chan;
namespace mode = chan::mode;
namespace ext = mode::ext;
using namespace ircd; using namespace ircd;
static const char extb_desc[] = "Extended mask ($x) extban type"; static const char extb_desc[] = "Extended mask ($x) extban type";
static int _modinit(void); static int _modinit(void);
static void _moddeinit(void); static void _moddeinit(void);
static int eb_extended(const char *data, struct Client *client_p, struct Channel *chptr, long mode_type); static int eb_extended(const char *data, struct Client *client_p, struct Channel *chptr, mode::type);
DECLARE_MODULE_AV2(extb_extended, _modinit, _moddeinit, NULL, NULL, NULL, NULL, NULL, extb_desc); DECLARE_MODULE_AV2(extb_extended, _modinit, _moddeinit, NULL, NULL, NULL, NULL, NULL, extb_desc);
static int static int
_modinit(void) _modinit(void)
{ {
extban_table['x'] = eb_extended; ext::table['x'] = eb_extended;
return 0; return 0;
} }
@ -25,31 +28,33 @@ _modinit(void)
static void static void
_moddeinit(void) _moddeinit(void)
{ {
extban_table['x'] = NULL; ext::table['x'] = NULL;
} }
static int eb_extended(const char *data, struct Client *client_p, static int eb_extended(const char *data, struct Client *client_p,
struct Channel *chptr, long mode_type) struct Channel *chptr, mode::type type)
{ {
using namespace ext;
char buf[BUFSIZE]; char buf[BUFSIZE];
int ret; int ret;
(void)chptr; (void)chptr;
if (data == NULL) if (data == NULL)
return EXTBAN_INVALID; return INVALID;
snprintf(buf, BUFSIZE, "%s!%s@%s#%s", snprintf(buf, BUFSIZE, "%s!%s@%s#%s",
client_p->name, client_p->username, client_p->host, client_p->info); client_p->name, client_p->username, client_p->host, client_p->info);
ret = match(data, buf) ? EXTBAN_MATCH : EXTBAN_NOMATCH; ret = match(data, buf) ? MATCH : NOMATCH;
if (ret == EXTBAN_NOMATCH && IsDynSpoof(client_p)) if (ret == NOMATCH && IsDynSpoof(client_p))
{ {
snprintf(buf, BUFSIZE, "%s!%s@%s#%s", snprintf(buf, BUFSIZE, "%s!%s@%s#%s",
client_p->name, client_p->username, client_p->orighost, client_p->info); client_p->name, client_p->username, client_p->orighost, client_p->info);
ret = match(data, buf) ? EXTBAN_MATCH : EXTBAN_NOMATCH; ret = match(data, buf) ? MATCH : NOMATCH;
} }
return ret; return ret;

View file

@ -3,32 +3,37 @@
* -- kaniini * -- kaniini
*/ */
namespace chan = ircd::chan;
namespace mode = chan::mode;
namespace ext = mode::ext;
using namespace ircd; using namespace ircd;
static const char extb_desc[] = "Hostmask ($m) extban type"; static const char extb_desc[] = "Hostmask ($m) extban type";
static int _modinit(void); static int _modinit(void);
static void _moddeinit(void); static void _moddeinit(void);
static int eb_hostmask(const char *data, struct Client *client_p, struct Channel *chptr, long mode_type); static int eb_hostmask(const char *data, struct Client *client_p, struct Channel *chptr, mode::type);
DECLARE_MODULE_AV2(extb_hostmask, _modinit, _moddeinit, NULL, NULL, NULL, NULL, NULL, extb_desc); DECLARE_MODULE_AV2(extb_hostmask, _modinit, _moddeinit, NULL, NULL, NULL, NULL, NULL, extb_desc);
static int static int
_modinit(void) _modinit(void)
{ {
extban_table['m'] = eb_hostmask; ext::table['m'] = eb_hostmask;
return 0; return 0;
} }
static void static void
_moddeinit(void) _moddeinit(void)
{ {
extban_table['m'] = NULL; ext::table['m'] = NULL;
} }
static int static int
eb_hostmask(const char *banstr, struct Client *client_p, struct Channel *chptr, long mode_type) eb_hostmask(const char *banstr, struct Client *client_p, struct Channel *chptr, mode::type type)
{ {
using namespace ext;
char src_host[NICKLEN + USERLEN + HOSTLEN + 6]; char src_host[NICKLEN + USERLEN + HOSTLEN + 6];
char src_iphost[NICKLEN + USERLEN + HOSTLEN + 6]; char src_iphost[NICKLEN + USERLEN + HOSTLEN + 6];
char src_althost[NICKLEN + USERLEN + HOSTLEN + 6]; char src_althost[NICKLEN + USERLEN + HOSTLEN + 6];
@ -62,5 +67,5 @@ eb_hostmask(const char *banstr, struct Client *client_p, struct Channel *chptr,
} }
#endif #endif
return match(banstr, s) || match(banstr, s2) || (s3 != NULL && match(banstr, s3)) || (s4 != NULL && match(banstr, s4)) ? EXTBAN_MATCH : EXTBAN_NOMATCH; return match(banstr, s) || match(banstr, s2) || (s3 != NULL && match(banstr, s3)) || (s4 != NULL && match(banstr, s4)) ? MATCH : NOMATCH;
} }

View file

@ -3,20 +3,23 @@
* -- jilles * -- jilles
*/ */
namespace chan = ircd::chan;
namespace mode = chan::mode;
namespace ext = mode::ext;
using namespace ircd; using namespace ircd;
static const char extb_desc[] = "Oper ($o) extban type"; static const char extb_desc[] = "Oper ($o) extban type";
static int _modinit(void); static int _modinit(void);
static void _moddeinit(void); static void _moddeinit(void);
static int eb_oper(const char *data, struct Client *client_p, struct Channel *chptr, long mode_type); static int eb_oper(const char *data, struct Client *client_p, struct Channel *chptr, mode::type);
DECLARE_MODULE_AV2(extb_oper, _modinit, _moddeinit, NULL, NULL, NULL, NULL, NULL, extb_desc); DECLARE_MODULE_AV2(extb_oper, _modinit, _moddeinit, NULL, NULL, NULL, NULL, NULL, extb_desc);
static int static int
_modinit(void) _modinit(void)
{ {
extban_table['o'] = eb_oper; ext::table['o'] = eb_oper;
return 0; return 0;
} }
@ -24,25 +27,25 @@ _modinit(void)
static void static void
_moddeinit(void) _moddeinit(void)
{ {
extban_table['o'] = NULL; ext::table['o'] = NULL;
} }
static int eb_oper(const char *data, struct Client *client_p, static int eb_oper(const char *data, struct Client *client_p,
struct Channel *chptr, long mode_type) struct Channel *chptr, mode::type type)
{ {
using namespace ext;
(void)chptr; (void)chptr;
(void)mode_type;
if (data != NULL) if (data != NULL)
{ {
struct PrivilegeSet *set = privilegeset_get(data); struct PrivilegeSet *set = privilegeset_get(data);
if (set != NULL && client_p->localClient->privset == set) if (set != NULL && client_p->localClient->privset == set)
return EXTBAN_MATCH; return MATCH;
/* $o:admin or whatever */ /* $o:admin or whatever */
return HasPrivilege(client_p, data) ? EXTBAN_MATCH : EXTBAN_NOMATCH; return HasPrivilege(client_p, data) ? MATCH : NOMATCH;
} }
return IsOper(client_p) ? EXTBAN_MATCH : EXTBAN_NOMATCH; return IsOper(client_p) ? MATCH : NOMATCH;
} }

View file

@ -3,20 +3,23 @@
* -- jilles * -- jilles
*/ */
namespace chan = ircd::chan;
namespace mode = chan::mode;
namespace ext = mode::ext;
using namespace ircd; using namespace ircd;
static const char extb_desc[] = "Realname/GECOS ($r) extban type"; static const char extb_desc[] = "Realname/GECOS ($r) extban type";
static int _modinit(void); static int _modinit(void);
static void _moddeinit(void); static void _moddeinit(void);
static int eb_realname(const char *data, struct Client *client_p, struct Channel *chptr, long mode_type); static int eb_realname(const char *data, struct Client *client_p, struct Channel *chptr, mode::type);
DECLARE_MODULE_AV2(extb_realname, _modinit, _moddeinit, NULL, NULL, NULL, NULL, NULL, extb_desc); DECLARE_MODULE_AV2(extb_realname, _modinit, _moddeinit, NULL, NULL, NULL, NULL, NULL, extb_desc);
static int static int
_modinit(void) _modinit(void)
{ {
extban_table['r'] = eb_realname; ext::table['r'] = eb_realname;
return 0; return 0;
} }
@ -24,18 +27,19 @@ _modinit(void)
static void static void
_moddeinit(void) _moddeinit(void)
{ {
extban_table['r'] = NULL; ext::table['r'] = NULL;
} }
static int eb_realname(const char *data, struct Client *client_p, static int eb_realname(const char *data, struct Client *client_p,
struct Channel *chptr, long mode_type) struct Channel *chptr, mode::type type)
{ {
using namespace ext;
(void)chptr; (void)chptr;
/* This type is not safe for exceptions */ /* This type is not safe for exceptions */
if (mode_type == CHFL_EXCEPTION || mode_type == CHFL_INVEX) if (type == CHFL_EXCEPTION || type == CHFL_INVEX)
return EXTBAN_INVALID; return INVALID;
if (data == NULL) if (data == NULL)
return EXTBAN_INVALID; return INVALID;
return match(data, client_p->info) ? EXTBAN_MATCH : EXTBAN_NOMATCH; return match(data, client_p->info) ? MATCH : NOMATCH;
} }

View file

@ -3,20 +3,23 @@
* -- jilles * -- jilles
*/ */
namespace chan = ircd::chan;
namespace mode = chan::mode;
namespace ext = mode::ext;
using namespace ircd; using namespace ircd;
static const char extb_desc[] = "Server ($s) extban type"; static const char extb_desc[] = "Server ($s) extban type";
static int _modinit(void); static int _modinit(void);
static void _moddeinit(void); static void _moddeinit(void);
static int eb_server(const char *data, struct Client *client_p, struct Channel *chptr, long mode_type); static int eb_server(const char *data, struct Client *client_p, struct Channel *chptr, mode::type);
DECLARE_MODULE_AV2(extb_server, _modinit, _moddeinit, NULL, NULL, NULL, NULL, NULL, extb_desc); DECLARE_MODULE_AV2(extb_server, _modinit, _moddeinit, NULL, NULL, NULL, NULL, NULL, extb_desc);
static int static int
_modinit(void) _modinit(void)
{ {
extban_table['s'] = eb_server; ext::table['s'] = eb_server;
return 0; return 0;
} }
@ -24,18 +27,19 @@ _modinit(void)
static void static void
_moddeinit(void) _moddeinit(void)
{ {
extban_table['s'] = NULL; ext::table['s'] = NULL;
} }
static int eb_server(const char *data, struct Client *client_p, static int eb_server(const char *data, struct Client *client_p,
struct Channel *chptr, long mode_type) struct Channel *chptr, mode::type type)
{ {
using namespace ext;
(void)chptr; (void)chptr;
/* This type is not safe for exceptions */ /* This type is not safe for exceptions */
if (mode_type == CHFL_EXCEPTION || mode_type == CHFL_INVEX) if (type == CHFL_EXCEPTION || type == CHFL_INVEX)
return EXTBAN_INVALID; return INVALID;
if (data == NULL) if (data == NULL)
return EXTBAN_INVALID; return INVALID;
return match(data, me.name) ? EXTBAN_MATCH : EXTBAN_NOMATCH; return match(data, me.name) ? MATCH : NOMATCH;
} }

View file

@ -1,19 +1,22 @@
/* SSL extban type: matches ssl users */ /* SSL extban type: matches ssl users */
namespace chan = ircd::chan;
namespace mode = chan::mode;
namespace ext = mode::ext;
using namespace ircd; using namespace ircd;
static const char extb_desc[] = "SSL/TLS ($z) extban type"; static const char extb_desc[] = "SSL/TLS ($z) extban type";
static int _modinit(void); static int _modinit(void);
static void _moddeinit(void); static void _moddeinit(void);
static int eb_ssl(const char *data, struct Client *client_p, struct Channel *chptr, long mode_type); static int eb_ssl(const char *data, struct Client *client_p, struct Channel *chptr, mode::type);
DECLARE_MODULE_AV2(extb_ssl, _modinit, _moddeinit, NULL, NULL, NULL, NULL, NULL, extb_desc); DECLARE_MODULE_AV2(extb_ssl, _modinit, _moddeinit, NULL, NULL, NULL, NULL, NULL, extb_desc);
static int static int
_modinit(void) _modinit(void)
{ {
extban_table['z'] = eb_ssl; ext::table['z'] = eb_ssl;
return 0; return 0;
} }
@ -21,16 +24,17 @@ _modinit(void)
static void static void
_moddeinit(void) _moddeinit(void)
{ {
extban_table['z'] = NULL; ext::table['z'] = NULL;
} }
static int eb_ssl(const char *data, struct Client *client_p, static int eb_ssl(const char *data, struct Client *client_p,
struct Channel *chptr, long mode_type) struct Channel *chptr, mode::type type)
{ {
using namespace ext;
(void)chptr; (void)chptr;
(void)mode_type;
if (data != NULL) if (data != NULL)
return EXTBAN_INVALID; return INVALID;
return IsSSLClient(client_p) ? EXTBAN_MATCH : EXTBAN_NOMATCH;
return IsSSLClient(client_p) ? MATCH : NOMATCH;
} }

View file

@ -3,20 +3,23 @@
* -- nenolod * -- nenolod
*/ */
namespace chan = ircd::chan;
namespace mode = chan::mode;
namespace ext = mode::ext;
using namespace ircd; using namespace ircd;
static const char extb_desc[] = "Usermode ($m) extban type"; static const char extb_desc[] = "Usermode ($m) extban type";
static int _modinit(void); static int _modinit(void);
static void _moddeinit(void); static void _moddeinit(void);
static int eb_usermode(const char *data, struct Client *client_p, struct Channel *chptr, long mode_type); static int eb_usermode(const char *data, struct Client *client_p, struct Channel *chptr, mode::type);
DECLARE_MODULE_AV2(extb_usermode, _modinit, _moddeinit, NULL, NULL, NULL, NULL, NULL, extb_desc); DECLARE_MODULE_AV2(extb_usermode, _modinit, _moddeinit, NULL, NULL, NULL, NULL, NULL, extb_desc);
static int static int
_modinit(void) _modinit(void)
{ {
extban_table['u'] = eb_usermode; ext::table['u'] = eb_usermode;
return 0; return 0;
} }
@ -24,12 +27,14 @@ _modinit(void)
static void static void
_moddeinit(void) _moddeinit(void)
{ {
extban_table['u'] = NULL; ext::table['u'] = NULL;
} }
static int eb_usermode(const char *data, struct Client *client_p, static int eb_usermode(const char *data, struct Client *client_p,
struct Channel *chptr, long mode_type) struct Channel *chptr, mode::type type)
{ {
using namespace ext;
int dir = MODE_ADD; int dir = MODE_ADD;
unsigned int modes_ack = 0, modes_nak = 0; unsigned int modes_ack = 0, modes_nak = 0;
const char *p; const char *p;
@ -38,7 +43,7 @@ static int eb_usermode(const char *data, struct Client *client_p,
/* $m must have a specified mode */ /* $m must have a specified mode */
if (data == NULL) if (data == NULL)
return EXTBAN_INVALID; return INVALID;
for (p = data; *p != '\0'; p++) for (p = data; *p != '\0'; p++)
{ {
@ -67,5 +72,5 @@ static int eb_usermode(const char *data, struct Client *client_p,
return ((client_p->umodes & modes_ack) == modes_ack && return ((client_p->umodes & modes_ack) == modes_ack &&
!(client_p->umodes & modes_nak)) ? !(client_p->umodes & modes_nak)) ?
EXTBAN_MATCH : EXTBAN_NOMATCH; MATCH : NOMATCH;
} }

View file

@ -30,8 +30,10 @@ static unsigned int mymode;
static int static int
_modinit(void) _modinit(void)
{ {
using namespace chan::mode;
/* initalize the +N cmode */ /* initalize the +N cmode */
mymode = cflag_add('N', CHM_D, chm_simple); mymode = add('N', category::D, functor::simple);
if (mymode == 0) if (mymode == 0)
return -1; return -1;
@ -42,7 +44,7 @@ static void
_moddeinit(void) _moddeinit(void)
{ {
/* orphan the +N cmode on modunload */ /* orphan the +N cmode on modunload */
cflag_orphan('N'); chan::mode::orphan('N');
} }
@ -145,7 +147,7 @@ m_displaymsg(struct MsgBuf *msgbuf_p, struct Client *source_p, const char *chann
return; return;
} }
if(!(chptr->mode.mode & chmode_flags['N'])) if(!(chptr->mode.mode & chan::mode::table['N'].type))
{ {
sendto_one_numeric(source_p, 573, "%s :Roleplay commands are not enabled on this channel.", chptr->chname); sendto_one_numeric(source_p, 573, "%s :Roleplay commands are not enabled on this channel.", chptr->chname);
return; return;

View file

@ -344,7 +344,7 @@ void hook_spamfilter_query(hook_data_privmsg_channel *const hook)
static static
void hook_channel_join(hook_data_channel_approval *const data) void hook_channel_join(hook_data_channel_approval *const data)
{ {
if(~data->chptr->mode.mode & chmode_table[(uint8_t)MODE_SPAMFILTER].mode_type) if(~data->chptr->mode.mode & chan::mode::table[uint8_t(MODE_SPAMFILTER)].type)
return; return;
if(!bloom[0]) if(!bloom[0])

View file

@ -40,7 +40,13 @@ namespace ircd {
#define ONLY_CHANOPS CHFL_CHANOP #define ONLY_CHANOPS CHFL_CHANOP
#define ONLY_CHANOPSVOICED (CHFL_CHANOP|CHFL_VOICE) #define ONLY_CHANOPSVOICED (CHFL_CHANOP|CHFL_VOICE)
/* mode structure for channels */ //TODO: will rm
#define CHFL_BAN 0x10000000 /* ban channel flag */
#define CHFL_EXCEPTION 0x20000000 /* exception to ban channel flag */
#define CHFL_INVEX 0x40000000
#define CHFL_QUIET 0x80000000
// mode structure for channels
struct Mode struct Mode
{ {
static constexpr size_t KEYLEN static constexpr size_t KEYLEN
@ -60,7 +66,7 @@ struct Mode
struct Channel struct Channel
{ {
rb_dlink_node node; rb_dlink_node node;
struct Mode mode; Mode mode;
char *mode_lock; char *mode_lock;
char *topic; char *topic;
char *topic_info; char *topic_info;
@ -116,21 +122,6 @@ struct Ban
rb_dlink_node node; rb_dlink_node node;
}; };
struct mode_letter
{
int mode;
char letter;
};
struct ChModeChange
{
char letter;
const char *arg;
const char *id;
int dir;
int mems;
};
/* can_send results */ /* can_send results */
#define CAN_SEND_NO 0 #define CAN_SEND_NO 0
#define CAN_SEND_NONOP 1 #define CAN_SEND_NONOP 1
@ -146,10 +137,11 @@ struct ChModeChange
#define MODE_ADD 1 #define MODE_ADD 1
#define MODE_DEL -1 #define MODE_DEL -1
#define SecretChannel(x) ((x) && ((x)->mode.mode & MODE_SECRET)) //TODO: will inline
#define HiddenChannel(x) ((x) && ((x)->mode.mode & MODE_PRIVATE)) #define SecretChannel(x) ((x) && ((x)->mode.mode & ircd::chan::mode::SECRET))
#define HiddenChannel(x) ((x) && ((x)->mode.mode & ircd::chan::mode::PRIVATE))
#define PubChannel(x) ((!x) || ((x)->mode.mode &\ #define PubChannel(x) ((!x) || ((x)->mode.mode &\
(MODE_PRIVATE | MODE_SECRET)) == 0) (ircd::chan::mode::PRIVATE | ircd::chan::mode::SECRET)) == 0)
/* channel visible */ /* channel visible */
#define ShowChannel(v,c) (PubChannel(c) || IsMember((v),(c))) #define ShowChannel(v,c) (PubChannel(c) || IsMember((v),(c)))
@ -212,7 +204,7 @@ extern void init_chcap_usage_counts(void);
extern void set_chcap_usage_counts(struct Client *serv_p); extern void set_chcap_usage_counts(struct Client *serv_p);
extern void unset_chcap_usage_counts(struct Client *serv_p); extern void unset_chcap_usage_counts(struct Client *serv_p);
extern void send_cap_mode_changes(struct Client *client_p, struct Client *source_p, extern void send_cap_mode_changes(struct Client *client_p, struct Client *source_p,
struct Channel *chptr, struct ChModeChange foo[], int); struct Channel *chptr, chan::mode::change foo[], int);
void resv_chan_forcepart(const char *name, const char *reason, int temp_time); void resv_chan_forcepart(const char *name, const char *reason, int temp_time);

View file

@ -26,102 +26,121 @@
#pragma once #pragma once
#define HAVE_IRCD_CHMODE_H #define HAVE_IRCD_CHMODE_H
/* something not included in messages.tab
* to change some hooks behaviour when needed
* -- dwr
*/
#define ERR_CUSTOM 1000
/* Maximum mode changes allowed per client, per server is different */
#define MAXMODEPARAMS 4
#define MAXMODEPARAMSSERV 10
#define MODEBUFLEN 200
#ifdef __cplusplus #ifdef __cplusplus
namespace ircd { namespace ircd {
/* Channel mode classification */
typedef enum
{
CHM_A, // Mode has a parameter apropos a list (or no param for xfer)
CHM_B, // Always has a parameter
CHM_C, // Only has a parameter on MODE_ADD
CHM_D, // Never has a parameter
}
ChmClass;
/* Channel mode mask */
#define MODE_PRIVATE 0x00000001
#define MODE_SECRET 0x00000002
#define MODE_MODERATED 0x00000004
#define MODE_TOPICLIMIT 0x00000008
#define MODE_INVITEONLY 0x00000010
#define MODE_NOPRIVMSGS 0x00000020
#define MODE_REGONLY 0x00000040
#define MODE_EXLIMIT 0x00000100 /* exempt from list limits, +b/+e/+I/+q */
#define MODE_PERMANENT 0x00000200 /* permanant channel, +P */
#define MODE_OPMODERATE 0x00000400 /* send rejected messages to ops */
#define MODE_FREEINVITE 0x00000800 /* allow free use of /invite */
#define MODE_FREETARGET 0x00001000 /* can be forwarded to without authorization */
#define MODE_DISFORWARD 0x00002000 /* disable channel forwarding */
#define CHFL_BAN 0x10000000 /* ban channel flag */
#define CHFL_EXCEPTION 0x20000000 /* exception to ban channel flag */
#define CHFL_INVEX 0x40000000
#define CHFL_QUIET 0x80000000
/* extban function results */
#define EXTBAN_INVALID -1 /* invalid mask, false even if negated */
#define EXTBAN_NOMATCH 0 /* valid mask, no match */
#define EXTBAN_MATCH 1 /* matches */
struct Client;
struct Channel; struct Channel;
struct Client;
typedef int (*ExtbanFunc) namespace chan {
(const char *data, struct Client *client_p, struct Channel *chptr, long mode_type); namespace mode {
typedef void (*ChmFunc) // Maximum mode changes allowed per client, per server is different
(struct Client *source_p, struct Channel *chptr, constexpr auto MAXPARAMS = 4;
int alevel, int parc, int *parn, const char **parv, int *errors, int dir, char c, long mode_type); constexpr auto MAXPARAMSSERV = 10;
constexpr auto BUFLEN = 200;
struct Chm // something not included in messages.tab to change some hooks behaviour when needed -- dwr
constexpr auto ERR_CUSTOM = 1000;
// Channel mode classification
enum class category
{ {
ChmFunc set_func; A, // Mode has a parameter apropos a list (or no param for xfer)
ChmClass mode_class; B, // Always has a parameter
unsigned long mode_type; C, // Only has a parameter on MODE_ADD
D, // Never has a parameter
}; };
enum type : uint
{
PRIVATE = 0x00000001,
SECRET = 0x00000002,
MODERATED = 0x00000004,
TOPICLIMIT = 0x00000008,
INVITEONLY = 0x00000010,
NOPRIVMSGS = 0x00000020,
REGONLY = 0x00000040,
EXLIMIT = 0x00000100, // exempt from list limits, +b/+e/+I/+q
PERMANENT = 0x00000200, // permanant channel, +P
OPMODERATE = 0x00000400, // send rejected messages to ops
FREEINVITE = 0x00000800, // allow free use of /invite
FREETARGET = 0x00001000, // can be forwarded to without authorization
DISFORWARD = 0x00002000, // disable channel forwarding
BAN = 0x10000000,
EXCEPTION = 0x20000000,
INVEX = 0x40000000,
QUIET = 0x80000000,
};
extern struct Chm chmode_table[256]; struct letter
extern ExtbanFunc extban_table[256]; {
extern char chmode_arity[2][256]; enum type type;
extern char chmode_class[4][256]; char letter;
extern int chmode_flags[256]; };
struct change
{
char letter;
const char *arg;
const char *id;
int dir;
int mems;
};
using func = void (*)(Client *, Channel *, int alevel, int parc, int *parn, const char **parv, int *errors, int dir, char c, type type);
struct mode
{
enum type type;
enum category category;
func set_func;
};
extern mode table[256];
extern char arity[2][256];
extern char categories[4][256];
namespace ext
{
// extban function results
enum result
{
INVALID = -1, // invalid mask, false even if negated
NOMATCH = 0, // valid mask, no match
MATCH = 1, // matches
};
using func = int (*)(const char *data, Client *, Channel *, type type);
extern func table[256];
}
#define CHM_FUNCTION(_NAME_) \ #define CHM_FUNCTION(_NAME_) \
void _NAME_(struct Client *source_p, struct Channel *chptr, \ void _NAME_(Client *source_p, Channel *chptr, \
int alevel, int parc, int *parn, const char **parv, \ int alevel, int parc, int *parn, const char **parv, \
int *errors, int dir, char c, long mode_type); int *errors, int dir, char c, type type);
CHM_FUNCTION(chm_nosuch) namespace functor
CHM_FUNCTION(chm_orphaned) {
CHM_FUNCTION(chm_simple) CHM_FUNCTION(nosuch)
CHM_FUNCTION(chm_ban) CHM_FUNCTION(orphaned)
CHM_FUNCTION(chm_hidden) CHM_FUNCTION(simple)
CHM_FUNCTION(chm_staff) CHM_FUNCTION(ban)
CHM_FUNCTION(chm_forward) CHM_FUNCTION(hidden)
CHM_FUNCTION(chm_throttle) CHM_FUNCTION(staff)
CHM_FUNCTION(chm_key) CHM_FUNCTION(forward)
CHM_FUNCTION(chm_limit) CHM_FUNCTION(throttle)
CHM_FUNCTION(chm_op) CHM_FUNCTION(key)
CHM_FUNCTION(chm_voice) CHM_FUNCTION(limit)
CHM_FUNCTION(op)
CHM_FUNCTION(voice)
}
unsigned int cflag_add(const unsigned char c, const ChmClass chmclass, const ChmFunc function); type add(const uint8_t &c, const category &category, const func &set_func);
void cflag_orphan(const unsigned char c); void orphan(const uint8_t &c);
void init(void);
void chmode_init(void);
} // namespace mode
} // namespace chan
} // namespace ircd } // namespace ircd
#endif // __cplusplus #endif // __cplusplus

View file

@ -42,13 +42,14 @@ namespace ircd
#include "listener.h" #include "listener.h"
#include "s_assert.h" #include "s_assert.h"
#include "chmode.h"
#include "channel.h"
#include "authproc.h" #include "authproc.h"
#include "bandbi.h" #include "bandbi.h"
#include "cache.h" #include "cache.h"
#include "capability.h" #include "capability.h"
#include "certfp.h" #include "certfp.h"
#include "channel.h"
#include "chmode.h"
#include "class.h" #include "class.h"
#include "client.h" #include "client.h"
#include "dns.h" #include "dns.h"

View file

@ -24,6 +24,8 @@
namespace ircd { namespace ircd {
using namespace chan;
struct config_channel_entry ConfigChannel; rb_dlink_list global_channel_list; static rb_bh struct config_channel_entry ConfigChannel; rb_dlink_list global_channel_list; static rb_bh
*channel_heap; static rb_bh *ban_heap; static rb_bh *topic_heap; static rb_bh *member_heap; *channel_heap; static rb_bh *ban_heap; static rb_bh *topic_heap; static rb_bh *member_heap;
@ -243,7 +245,7 @@ remove_user_from_channel(struct membership *msptr)
if(client_p->servptr == &me) if(client_p->servptr == &me)
rb_dlinkDelete(&msptr->locchannode, &chptr->locmembers); rb_dlinkDelete(&msptr->locchannode, &chptr->locmembers);
if(!(chptr->mode.mode & MODE_PERMANENT) && rb_dlink_list_length(&chptr->members) <= 0) if(!(chptr->mode.mode & mode::PERMANENT) && rb_dlink_list_length(&chptr->members) <= 0)
destroy_channel(chptr); destroy_channel(chptr);
rb_bh_free(member_heap, msptr); rb_bh_free(member_heap, msptr);
@ -278,7 +280,7 @@ remove_user_from_channels(struct Client *client_p)
if(client_p->servptr == &me) if(client_p->servptr == &me)
rb_dlinkDelete(&msptr->locchannode, &chptr->locmembers); rb_dlinkDelete(&msptr->locchannode, &chptr->locmembers);
if(!(chptr->mode.mode & MODE_PERMANENT) && rb_dlink_list_length(&chptr->members) <= 0) if(!(chptr->mode.mode & mode::PERMANENT) && rb_dlink_list_length(&chptr->members) <= 0)
destroy_channel(chptr); destroy_channel(chptr);
rb_bh_free(member_heap, msptr); rb_bh_free(member_heap, msptr);
@ -747,7 +749,7 @@ can_join(struct Client *source_p, struct Channel *chptr, const char *key, const
if(forward) if(forward)
*forward = chptr->mode.forward; *forward = chptr->mode.forward;
if(chptr->mode.mode & MODE_INVITEONLY) if(chptr->mode.mode & mode::INVITEONLY)
{ {
RB_DLINK_FOREACH(invite, source_p->user->invited.head) RB_DLINK_FOREACH(invite, source_p->user->invited.head)
{ {
@ -776,7 +778,7 @@ can_join(struct Client *source_p, struct Channel *chptr, const char *key, const
if(chptr->mode.limit && if(chptr->mode.limit &&
rb_dlink_list_length(&chptr->members) >= (unsigned long) chptr->mode.limit) rb_dlink_list_length(&chptr->members) >= (unsigned long) chptr->mode.limit)
i = ERR_CHANNELISFULL; i = ERR_CHANNELISFULL;
if(chptr->mode.mode & MODE_REGONLY && EmptyString(source_p->user->suser)) if(chptr->mode.mode & mode::REGONLY && EmptyString(source_p->user->suser))
i = ERR_NEEDREGGEDNICK; i = ERR_NEEDREGGEDNICK;
/* join throttling stuff --nenolod */ /* join throttling stuff --nenolod */
else if(chptr->mode.join_num > 0 && chptr->mode.join_time > 0) else if(chptr->mode.join_num > 0 && chptr->mode.join_time > 0)
@ -836,7 +838,7 @@ can_send(struct Channel *chptr, struct Client *source_p, struct membership *mspt
* they cant send. we dont check bans here because * they cant send. we dont check bans here because
* theres no possibility of caching them --fl * theres no possibility of caching them --fl
*/ */
if(chptr->mode.mode & MODE_NOPRIVMSGS || chptr->mode.mode & MODE_MODERATED) if(chptr->mode.mode & mode::NOPRIVMSGS || chptr->mode.mode & mode::MODERATED)
moduledata.approved = CAN_SEND_NO; moduledata.approved = CAN_SEND_NO;
else else
moduledata.approved = CAN_SEND_NONOP; moduledata.approved = CAN_SEND_NONOP;
@ -845,7 +847,7 @@ can_send(struct Channel *chptr, struct Client *source_p, struct membership *mspt
} }
} }
if(chptr->mode.mode & MODE_MODERATED) if(chptr->mode.mode & mode::MODERATED)
moduledata.approved = CAN_SEND_NO; moduledata.approved = CAN_SEND_NO;
if(MyClient(source_p)) if(MyClient(source_p))
@ -1167,9 +1169,9 @@ channel_modes(struct Channel *chptr, struct Client *client_p)
for (i = 0; i < 256; i++) for (i = 0; i < 256; i++)
{ {
if(chmode_table[i].set_func == chm_hidden && (!IsOper(client_p) || !IsClient(client_p))) if(mode::table[i].set_func == mode::functor::hidden && (!IsOper(client_p) || !IsClient(client_p)))
continue; continue;
if(chptr->mode.mode & chmode_flags[i]) if(chptr->mode.mode & mode::table[i].type)
*mbuf++ = i; *mbuf++ = i;
} }
@ -1231,7 +1233,7 @@ channel_modes(struct Channel *chptr, struct Client *client_p)
*/ */
void void
send_cap_mode_changes(struct Client *client_p, struct Client *source_p, send_cap_mode_changes(struct Client *client_p, struct Client *source_p,
struct Channel *chptr, struct ChModeChange mode_changes[], int mode_count) struct Channel *chptr, chan::mode::change mode_changes[], int mode_count)
{ {
static char modebuf[BUFSIZE]; static char modebuf[BUFSIZE];
static char parabuf[BUFSIZE]; static char parabuf[BUFSIZE];
@ -1273,7 +1275,7 @@ send_cap_mode_changes(struct Client *client_p, struct Client *source_p,
arglen = strlen(arg); arglen = strlen(arg);
/* dont even think about it! --fl */ /* dont even think about it! --fl */
if(arglen > MODEBUFLEN - 5) if(arglen > mode::BUFLEN - 5)
continue; continue;
} }
@ -1284,7 +1286,7 @@ send_cap_mode_changes(struct Client *client_p, struct Client *source_p,
* them as if they were the longest of the nick or uid at all times, * them as if they were the longest of the nick or uid at all times,
* which even then won't work as we don't always know the uid -A1kmm. * which even then won't work as we don't always know the uid -A1kmm.
*/ */
if(arg && ((mc == MAXMODEPARAMSSERV) || if(arg && ((mc == mode::MAXPARAMSSERV) ||
((mbl + pbl + arglen + 4) > (BUFSIZE - 3)))) ((mbl + pbl + arglen + 4) > (BUFSIZE - 3))))
{ {
if(nc != 0) if(nc != 0)

View file

@ -23,7 +23,8 @@
* USA * USA
*/ */
namespace ircd { namespace mode = ircd::chan::mode;
using namespace ircd;
/* bitmasks for error returns, so we send once per call */ /* bitmasks for error returns, so we send once per call */
#define SM_ERR_NOTS 0x00000001 /* No TS on channel */ #define SM_ERR_NOTS 0x00000001 /* No TS on channel */
@ -42,98 +43,99 @@ namespace ircd {
#define MAXMODES_SIMPLE 46 /* a-zA-Z except bqeIov */ #define MAXMODES_SIMPLE 46 /* a-zA-Z except bqeIov */
static struct ChModeChange mode_changes[BUFSIZE];
static int mode_count; static int mode_count;
static int mode_limit; static int mode_limit;
static int mode_limit_simple; static int mode_limit_simple;
static int mask_pos; static int mask_pos;
static int removed_mask_pos; static int removed_mask_pos;
extern int h_get_channel_access; static int h_get_channel_access;
mode::change mode_changes[BUFSIZE];
int chmode_flags[256]; // Table of mode flag integers mode::mode mode::table[256];
char chmode_arity[2][256]; // RPL_MYINFO (note that [0] is for 0 OR MORE params) char mode::arity[2][256]; // RPL_MYINFO (note that [0] is for 0 OR MORE params)
char chmode_class[4][256]; // RPL_ISUPPORT classification char mode::categories[4][256]; // RPL_ISUPPORT classification
struct Chm chmode_table[256];
static #pragma GCC diagnostic push
void chmode_table_init() #pragma GCC diagnostic ignored "-Wchar-subscripts"
static void
table_init()
{ {
using namespace mode;
using namespace functor;
// Leading tab only please: // Leading tab only please:
// <tab>chmode_table['X'] = {<sp>handler,<sp>class,<sp>flag<sp>}; // <tab>mode::table['X'] = {<sp>handler,<sp>class,<sp>flag<sp>};
chmode_table['C'] = { 0, CHM_D, 0 }; table['C'] = { type(0), category::D, nullptr };
chmode_table['F'] = { chm_simple, CHM_D, MODE_FREETARGET }; table['F'] = { FREETARGET, category::D, simple };
chmode_table['I'] = { chm_ban, CHM_A, CHFL_INVEX }; table['I'] = { INVEX, category::A, ban };
chmode_table['L'] = { chm_staff, CHM_D, MODE_EXLIMIT }; table['L'] = { EXLIMIT, category::D, staff };
chmode_table['P'] = { chm_staff, CHM_D, MODE_PERMANENT }; table['P'] = { PERMANENT, category::D, staff };
chmode_table['Q'] = { chm_simple, CHM_D, MODE_DISFORWARD }; table['Q'] = { DISFORWARD, category::D, simple };
table['b'] = { BAN, category::A, ban };
chmode_table['b'] = { chm_ban, CHM_A, CHFL_BAN }; table['e'] = { EXCEPTION, category::A, ban };
chmode_table['e'] = { chm_ban, CHM_A, CHFL_EXCEPTION }; table['f'] = { type(0), category::C, forward };
chmode_table['f'] = { chm_forward, CHM_C, 0 }; table['g'] = { FREEINVITE, category::D, simple };
chmode_table['g'] = { chm_simple, CHM_D, MODE_FREEINVITE }; table['i'] = { INVITEONLY, category::D, simple };
chmode_table['i'] = { chm_simple, CHM_D, MODE_INVITEONLY }; table['j'] = { type(0), category::C, throttle };
chmode_table['j'] = { chm_throttle, CHM_C, 0 }; table['k'] = { type(0), category::B, key };
chmode_table['k'] = { chm_key, CHM_B, 0 }; table['l'] = { type(0), category::C, limit };
chmode_table['l'] = { chm_limit, CHM_C, 0 }; table['m'] = { MODERATED, category::D, simple };
chmode_table['m'] = { chm_simple, CHM_D, MODE_MODERATED }; table['n'] = { NOPRIVMSGS, category::D, simple };
chmode_table['n'] = { chm_simple, CHM_D, MODE_NOPRIVMSGS }; table['o'] = { type(0), category::B, op };
chmode_table['o'] = { chm_op, CHM_B, 0 }; table['p'] = { PRIVATE, category::D, simple };
chmode_table['p'] = { chm_simple, CHM_D, MODE_PRIVATE }; table['q'] = { QUIET, category::A, ban };
chmode_table['q'] = { chm_ban, CHM_A, CHFL_QUIET }; table['r'] = { REGONLY, category::D, simple };
chmode_table['r'] = { chm_simple, CHM_D, MODE_REGONLY }; table['s'] = { SECRET, category::D, simple };
chmode_table['s'] = { chm_simple, CHM_D, MODE_SECRET }; table['t'] = { TOPICLIMIT, category::D, simple };
chmode_table['t'] = { chm_simple, CHM_D, MODE_TOPICLIMIT }; table['v'] = { type(0), category::B, voice };
chmode_table['v'] = { chm_voice, CHM_B, 0 }; table['z'] = { OPMODERATE, category::D, simple };
chmode_table['z'] = { chm_simple, CHM_D, MODE_OPMODERATE };
} }
#pragma GCC diagnostic pop
/* OPTIMIZE ME! -- dwr /* OPTIMIZE ME! -- dwr
* sure! --jzk */ * sure! --jzk */
void void
chmode_init(void) chan::mode::init()
{ {
chmode_table_init(); table_init();
/* Reset the state generated by earlier calls to this function */ categories[uint(category::A)][0] = '\0';
memset(chmode_flags, '\0', sizeof(chmode_flags)); categories[uint(category::B)][0] = '\0';
categories[uint(category::C)][0] = '\0';
categories[uint(category::D)][0] = '\0';
chmode_class[CHM_A][0] = '\0'; arity[0][0] = '\0';
chmode_class[CHM_B][0] = '\0'; arity[1][0] = '\0';
chmode_class[CHM_C][0] = '\0';
chmode_class[CHM_D][0] = '\0';
chmode_arity[0][0] = '\0';
chmode_arity[1][0] = '\0';
/* Filter out anything disabled by the configuraton */ /* Filter out anything disabled by the configuraton */
unsigned long disabled = 0; unsigned long disabled = 0;
if (!ConfigChannel.use_invex) disabled |= CHFL_INVEX; if (!ConfigChannel.use_invex) disabled |= INVEX;
if (!ConfigChannel.use_except) disabled |= CHFL_EXCEPTION; if (!ConfigChannel.use_except) disabled |= EXCEPTION;
if (!ConfigChannel.use_forward) disabled |= MODE_FREETARGET | MODE_DISFORWARD; if (!ConfigChannel.use_forward) disabled |= FREETARGET | DISFORWARD;
/* Construct the chmode data */ /* Construct the chmode data */
for (size_t i = 0; i < 256; i++) for (size_t i = 0; i < 256; i++)
{ {
if(!chmode_table[i].set_func) if (!table[i].set_func)
{ {
chmode_table[i].set_func = chm_nosuch; table[i].set_func = functor::nosuch;
chmode_table[i].mode_class = CHM_D; table[i].category = category::D;
continue; continue;
} }
if(chmode_table[i].mode_type & disabled || chmode_table[i].set_func == chm_nosuch) if (table[i].type & disabled || table[i].set_func == functor::nosuch)
continue; continue;
const char ch[2] = { char(i), '\0' }; const char ch[2] = { char(i), '\0' };
chmode_flags[i] = chmode_table[i].mode_type; const auto &cat(table[i].category);
rb_strlcat(chmode_class[chmode_table[i].mode_class], ch, 256); rb_strlcat(categories[uint(cat)], ch, 256);
rb_strlcat(chmode_arity[0], ch, 256); rb_strlcat(arity[0], ch, 256);
} }
/* Any non-CHM_D mode has parameters, this sets up RPL_MYINFO */ /* Any non-category::D mode has parameters, this sets up RPL_MYINFO */
for (size_t i = 0; i < 3; i++) for (size_t i = 0; i < 3; i++)
rb_strlcat(chmode_arity[1], chmode_class[i], 256); rb_strlcat(arity[1], categories[i], 256);
} }
/* /*
@ -144,49 +146,55 @@ chmode_init(void)
* 0 if no cflags are available * 0 if no cflags are available
* side effects - NONE * side effects - NONE
*/ */
static unsigned int static mode::type
find_cflag_slot(void) find_cflag_slot(void)
{ {
using namespace mode;
unsigned int all_cflags = 0, my_cflag = 0, i; unsigned int all_cflags = 0, my_cflag = 0, i;
for (i = 0; i < 256; i++) for (i = 0; i < 256; i++)
all_cflags |= chmode_flags[i]; all_cflags |= table[i].type;
for (my_cflag = 1; my_cflag && (all_cflags & my_cflag); for (my_cflag = 1; my_cflag && (all_cflags & my_cflag);
my_cflag <<= 1); my_cflag <<= 1);
return my_cflag; return type(my_cflag);
} }
unsigned int mode::type
cflag_add(const unsigned char c, const ChmClass mode_class, const ChmFunc function) mode::add(const uint8_t &c,
const category &category,
const func &set_func)
{ {
if(chmode_table[c].set_func && if(table[c].set_func &&
chmode_table[c].set_func != chm_nosuch && table[c].set_func != functor::nosuch &&
chmode_table[c].set_func != chm_orphaned) table[c].set_func != functor::orphaned)
return 0; return type(0);
if(chmode_table[c].set_func == chm_nosuch) if(table[c].set_func == functor::nosuch)
chmode_table[c].mode_type = find_cflag_slot(); table[c].type = find_cflag_slot();
if(chmode_table[c].mode_type == 0) if(!table[c].type)
return 0; return type(0);
chmode_table[c].set_func = function; table[c].category = category;
chmode_table[c].mode_class = mode_class; table[c].set_func = set_func;
chmode_init(); init();
return chmode_table[c].mode_type; return table[c].type;
} }
void void
cflag_orphan(const unsigned char c) mode::orphan(const uint8_t &c)
{ {
s_assert(chmode_flags[c] != 0); s_assert(table[c].type != 0);
chmode_table[c].set_func = chm_orphaned; table[c].set_func = functor::orphaned;
chmode_init(); init();
} }
namespace ircd {
int int
get_channel_access(struct Client *source_p, struct Channel *chptr, struct membership *msptr, int dir, const char *modestr) get_channel_access(struct Client *source_p, struct Channel *chptr, struct membership *msptr, int dir, const char *modestr)
{ {
@ -264,7 +272,7 @@ add_id(struct Client *source_p, struct Channel *chptr, const char *banid, const
*/ */
if(MyClient(source_p)) if(MyClient(source_p))
{ {
if((rb_dlink_list_length(&chptr->banlist) + rb_dlink_list_length(&chptr->exceptlist) + rb_dlink_list_length(&chptr->invexlist) + rb_dlink_list_length(&chptr->quietlist)) >= (unsigned long)(chptr->mode.mode & MODE_EXLIMIT ? ConfigChannel.max_bans_large : ConfigChannel.max_bans)) if((rb_dlink_list_length(&chptr->banlist) + rb_dlink_list_length(&chptr->exceptlist) + rb_dlink_list_length(&chptr->invexlist) + rb_dlink_list_length(&chptr->quietlist)) >= (unsigned long)(chptr->mode.mode & mode::EXLIMIT ? ConfigChannel.max_bans_large : ConfigChannel.max_bans))
{ {
sendto_one(source_p, form_str(ERR_BANLISTFULL), sendto_one(source_p, form_str(ERR_BANLISTFULL),
me.name, source_p->name, chptr->chname, realban); me.name, source_p->name, chptr->chname, realban);
@ -301,7 +309,7 @@ add_id(struct Client *source_p, struct Channel *chptr, const char *banid, const
rb_dlinkAdd(actualBan, &actualBan->node, list); rb_dlinkAdd(actualBan, &actualBan->node, list);
/* invalidate the can_send() cache */ /* invalidate the can_send() cache */
if(mode_type == CHFL_BAN || mode_type == CHFL_QUIET || mode_type == CHFL_EXCEPTION) if(mode_type == mode::BAN || mode_type == mode::QUIET || mode_type == mode::EXCEPTION)
chptr->bants = rb_current_time(); chptr->bants = rb_current_time();
return true; return true;
@ -331,7 +339,7 @@ del_id(struct Channel *chptr, const char *banid, rb_dlink_list * list, long mode
rb_dlinkDelete(&banptr->node, list); rb_dlinkDelete(&banptr->node, list);
/* invalidate the can_send() cache */ /* invalidate the can_send() cache */
if(mode_type == CHFL_BAN || mode_type == CHFL_QUIET || mode_type == CHFL_EXCEPTION) if(mode_type == mode::BAN || mode_type == mode::QUIET || mode_type == mode::EXCEPTION)
chptr->bants = rb_current_time(); chptr->bants = rb_current_time();
return banptr; return banptr;
@ -523,7 +531,7 @@ check_forward(struct Client *source_p, struct Channel *chptr,
form_str(ERR_NOSUCHCHANNEL), forward); form_str(ERR_NOSUCHCHANNEL), forward);
return false; return false;
} }
if(MyClient(source_p) && !(targptr->mode.mode & MODE_FREETARGET)) if(MyClient(source_p) && !(targptr->mode.mode & mode::FREETARGET))
{ {
if((msptr = find_channel_membership(targptr, source_p)) == NULL || if((msptr = find_channel_membership(targptr, source_p)) == NULL ||
get_channel_access(source_p, targptr, msptr, MODE_QUERY, NULL) < CHFL_CHANOP) get_channel_access(source_p, targptr, msptr, MODE_QUERY, NULL) < CHFL_CHANOP)
@ -587,9 +595,9 @@ fix_key_remote(char *arg)
* The handlers for each specific mode. * The handlers for each specific mode.
*/ */
void void
chm_nosuch(struct Client *source_p, struct Channel *chptr, mode::functor::nosuch(struct Client *source_p, struct Channel *chptr,
int alevel, int parc, int *parn, int alevel, int parc, int *parn,
const char **parv, int *errors, int dir, char c, long mode_type) const char **parv, int *errors, int dir, char c, type mode_type)
{ {
if(*errors & SM_ERR_UNKNOWN) if(*errors & SM_ERR_UNKNOWN)
return; return;
@ -598,9 +606,9 @@ chm_nosuch(struct Client *source_p, struct Channel *chptr,
} }
void void
chm_simple(struct Client *source_p, struct Channel *chptr, mode::functor::simple(struct Client *source_p, struct Channel *chptr,
int alevel, int parc, int *parn, int alevel, int parc, int *parn,
const char **parv, int *errors, int dir, char c, long mode_type) const char **parv, int *errors, int dir, char c, type mode_type)
{ {
if(!allow_mode_change(source_p, chptr, alevel, errors, c)) if(!allow_mode_change(source_p, chptr, alevel, errors, c))
return; return;
@ -637,9 +645,9 @@ chm_simple(struct Client *source_p, struct Channel *chptr,
} }
void void
chm_orphaned(struct Client *source_p, struct Channel *chptr, mode::functor::orphaned(struct Client *source_p, struct Channel *chptr,
int alevel, int parc, int *parn, int alevel, int parc, int *parn,
const char **parv, int *errors, int dir, char c, long mode_type) const char **parv, int *errors, int dir, char c, type mode_type)
{ {
if(MyClient(source_p)) if(MyClient(source_p))
return; return;
@ -667,9 +675,9 @@ chm_orphaned(struct Client *source_p, struct Channel *chptr,
} }
void void
chm_hidden(struct Client *source_p, struct Channel *chptr, mode::functor::hidden(struct Client *source_p, struct Channel *chptr,
int alevel, int parc, int *parn, int alevel, int parc, int *parn,
const char **parv, int *errors, int dir, char c, long mode_type) const char **parv, int *errors, int dir, char c, type mode_type)
{ {
if(!IsOper(source_p) && !IsServer(source_p)) if(!IsOper(source_p) && !IsServer(source_p))
{ {
@ -714,9 +722,9 @@ chm_hidden(struct Client *source_p, struct Channel *chptr,
} }
void void
chm_staff(struct Client *source_p, struct Channel *chptr, mode::functor::staff(struct Client *source_p, struct Channel *chptr,
int alevel, int parc, int *parn, int alevel, int parc, int *parn,
const char **parv, int *errors, int dir, char c, long mode_type) const char **parv, int *errors, int dir, char c, type mode_type)
{ {
if(!IsOper(source_p) && !IsServer(source_p)) if(!IsOper(source_p) && !IsServer(source_p))
{ {
@ -764,9 +772,9 @@ chm_staff(struct Client *source_p, struct Channel *chptr,
} }
void void
chm_ban(struct Client *source_p, struct Channel *chptr, mode::functor::ban(struct Client *source_p, struct Channel *chptr,
int alevel, int parc, int *parn, int alevel, int parc, int *parn,
const char **parv, int *errors, int dir, char c, long mode_type) const char **parv, int *errors, int dir, char c, type mode_type)
{ {
const char *mask, *raw_mask; const char *mask, *raw_mask;
char *forward; char *forward;
@ -843,8 +851,8 @@ chm_ban(struct Client *source_p, struct Channel *chptr,
/* non-ops cant see +eI lists.. */ /* non-ops cant see +eI lists.. */
/* note that this is still permitted if +e/+I are mlocked. */ /* note that this is still permitted if +e/+I are mlocked. */
if(alevel < CHFL_CHANOP && mode_type != CHFL_BAN && if(alevel < CHFL_CHANOP && mode_type != BAN &&
mode_type != CHFL_QUIET) mode_type != QUIET)
{ {
if(!(*errors & SM_ERR_NOOPS)) if(!(*errors & SM_ERR_NOOPS))
sendto_one(source_p, form_str(ERR_CHANOPRIVSNEEDED), sendto_one(source_p, form_str(ERR_CHANOPRIVSNEEDED),
@ -874,7 +882,7 @@ chm_ban(struct Client *source_p, struct Channel *chptr,
return; return;
if(MyClient(source_p) && (++mode_limit > MAXMODEPARAMS)) if(MyClient(source_p) && (++mode_limit > MAXPARAMS))
return; return;
raw_mask = parv[(*parn)]; raw_mask = parv[(*parn)];
@ -898,7 +906,7 @@ chm_ban(struct Client *source_p, struct Channel *chptr,
* also make sure it will always fit on a line with channel * also make sure it will always fit on a line with channel
* name etc. * name etc.
*/ */
if(strlen(mask) > MIN(BANLEN, MODEBUFLEN - 5)) if(strlen(mask) > MIN(BANLEN, BUFLEN - 5))
{ {
sendto_one_numeric(source_p, ERR_INVALIDBAN, sendto_one_numeric(source_p, ERR_INVALIDBAN,
form_str(ERR_INVALIDBAN), form_str(ERR_INVALIDBAN),
@ -978,7 +986,7 @@ chm_ban(struct Client *source_p, struct Channel *chptr,
else if(dir == MODE_DEL) else if(dir == MODE_DEL)
{ {
struct Ban *removed; struct Ban *removed;
static char buf[BANLEN * MAXMODEPARAMS]; static char buf[BANLEN * MAXPARAMS];
int old_removed_mask_pos = removed_mask_pos; int old_removed_mask_pos = removed_mask_pos;
if((removed = del_id(chptr, mask, list, mode_type)) == NULL) if((removed = del_id(chptr, mask, list, mode_type)) == NULL)
{ {
@ -1006,9 +1014,9 @@ chm_ban(struct Client *source_p, struct Channel *chptr,
} }
void void
chm_op(struct Client *source_p, struct Channel *chptr, mode::functor::op(struct Client *source_p, struct Channel *chptr,
int alevel, int parc, int *parn, int alevel, int parc, int *parn,
const char **parv, int *errors, int dir, char c, long mode_type) const char **parv, int *errors, int dir, char c, type mode_type)
{ {
struct membership *mstptr; struct membership *mstptr;
const char *opnick; const char *opnick;
@ -1046,7 +1054,7 @@ chm_op(struct Client *source_p, struct Channel *chptr,
return; return;
} }
if(MyClient(source_p) && (++mode_limit > MAXMODEPARAMS)) if(MyClient(source_p) && (++mode_limit > MAXPARAMS))
return; return;
if(dir == MODE_ADD) if(dir == MODE_ADD)
@ -1082,9 +1090,9 @@ chm_op(struct Client *source_p, struct Channel *chptr,
} }
void void
chm_voice(struct Client *source_p, struct Channel *chptr, mode::functor::voice(struct Client *source_p, struct Channel *chptr,
int alevel, int parc, int *parn, int alevel, int parc, int *parn,
const char **parv, int *errors, int dir, char c, long mode_type) const char **parv, int *errors, int dir, char c, type mode_type)
{ {
struct membership *mstptr; struct membership *mstptr;
const char *opnick; const char *opnick;
@ -1122,7 +1130,7 @@ chm_voice(struct Client *source_p, struct Channel *chptr,
return; return;
} }
if(MyClient(source_p) && (++mode_limit > MAXMODEPARAMS)) if(MyClient(source_p) && (++mode_limit > MAXPARAMS))
return; return;
if(dir == MODE_ADD) if(dir == MODE_ADD)
@ -1148,9 +1156,9 @@ chm_voice(struct Client *source_p, struct Channel *chptr,
} }
void void
chm_limit(struct Client *source_p, struct Channel *chptr, mode::functor::limit(struct Client *source_p, struct Channel *chptr,
int alevel, int parc, int *parn, int alevel, int parc, int *parn,
const char **parv, int *errors, int dir, char c, long mode_type) const char **parv, int *errors, int dir, char c, type mode_type)
{ {
const char *lstr; const char *lstr;
static char limitstr[30]; static char limitstr[30];
@ -1199,9 +1207,9 @@ chm_limit(struct Client *source_p, struct Channel *chptr,
} }
void void
chm_throttle(struct Client *source_p, struct Channel *chptr, mode::functor::throttle(struct Client *source_p, struct Channel *chptr,
int alevel, int parc, int *parn, int alevel, int parc, int *parn,
const char **parv, int *errors, int dir, char c, long mode_type) const char **parv, int *errors, int dir, char c, type mode_type)
{ {
int joins = 0, timeslice = 0; int joins = 0, timeslice = 0;
@ -1252,9 +1260,9 @@ chm_throttle(struct Client *source_p, struct Channel *chptr,
} }
void void
chm_forward(struct Client *source_p, struct Channel *chptr, mode::functor::forward(struct Client *source_p, struct Channel *chptr,
int alevel, int parc, int *parn, int alevel, int parc, int *parn,
const char **parv, int *errors, int dir, char c, long mode_type) const char **parv, int *errors, int dir, char c, type mode_type)
{ {
const char *forward; const char *forward;
@ -1328,9 +1336,9 @@ chm_forward(struct Client *source_p, struct Channel *chptr,
} }
void void
chm_key(struct Client *source_p, struct Channel *chptr, mode::functor::key(struct Client *source_p, struct Channel *chptr,
int alevel, int parc, int *parn, int alevel, int parc, int *parn,
const char **parv, int *errors, int dir, char c, long mode_type) const char **parv, int *errors, int dir, char c, type mode_type)
{ {
char *key; char *key;
@ -1405,8 +1413,8 @@ chm_key(struct Client *source_p, struct Channel *chptr,
* Extensively modified to be hotpluggable, 03/09/06 -- nenolod * Extensively modified to be hotpluggable, 03/09/06 -- nenolod
*/ */
void void
set_channel_mode(struct Client *client_p, struct Client *source_p, set_channel_mode(Client *client_p, Client *source_p,
struct Channel *chptr, struct membership *msptr, int parc, const char *parv[]) Channel *chptr, membership *msptr, int parc, const char *parv[])
{ {
static char modebuf[BUFSIZE]; static char modebuf[BUFSIZE];
static char parabuf[BUFSIZE]; static char parabuf[BUFSIZE];
@ -1420,7 +1428,7 @@ set_channel_mode(struct Client *client_p, struct Client *source_p,
int alevel; int alevel;
const char *ml = parv[0]; const char *ml = parv[0];
char c; char c;
struct Client *fakesource_p; Client *fakesource_p;
int reauthorized = 0; /* if we change from MODE_QUERY to MODE_ADD/MODE_DEL, then reauth once, ugly but it works */ int reauthorized = 0; /* if we change from MODE_QUERY to MODE_ADD/MODE_DEL, then reauth once, ugly but it works */
int flags_list[3] = { ALL_MEMBERS, ONLY_CHANOPS, ONLY_OPERS }; int flags_list[3] = { ALL_MEMBERS, ONLY_CHANOPS, ONLY_OPERS };
@ -1462,10 +1470,7 @@ set_channel_mode(struct Client *client_p, struct Client *source_p,
dir = MODE_QUERY; dir = MODE_QUERY;
break; break;
default: default:
chmode_table[(unsigned char) c].set_func(fakesource_p, chptr, alevel, mode::table[uint8_t(c)].set_func(fakesource_p, chptr, alevel, parc, &parn, parv, &errors, dir, c, mode::table[uint8_t(c)].type);
parc, &parn, parv,
&errors, dir, c,
chmode_table[(unsigned char) c].mode_type);
break; break;
} }
} }
@ -1500,17 +1505,17 @@ set_channel_mode(struct Client *client_p, struct Client *source_p,
{ {
arglen = strlen(mode_changes[i].arg); arglen = strlen(mode_changes[i].arg);
if(arglen > MODEBUFLEN - 5) if(arglen > mode::BUFLEN - 5)
continue; continue;
} }
else else
arglen = 0; arglen = 0;
/* if we're creeping over MAXMODEPARAMSSERV, or over /* if we're creeping over mode::MAXPARAMSSERV, or over
* bufsize (4 == +/-,modechar,two spaces) send now. * bufsize (4 == +/-,modechar,two spaces) send now.
*/ */
if(mode_changes[i].arg != NULL && if(mode_changes[i].arg != NULL &&
((paracount == MAXMODEPARAMSSERV) || ((paracount == mode::MAXPARAMSSERV) ||
((cur_len + paralen + arglen + 4) > (BUFSIZE - 3)))) ((cur_len + paralen + arglen + 4) > (BUFSIZE - 3))))
{ {
*mbuf = '\0'; *mbuf = '\0';

View file

@ -20,16 +20,19 @@
* USA * USA
*/ */
namespace ircd { namespace chan = ircd::chan;
namespace mode = chan::mode;
namespace ext = mode::ext;
using namespace ext;
ExtbanFunc extban_table[256] = { NULL }; ext::func ext::table[256] = { NULL };
int int
match_extban(const char *banstr, struct Client *client_p, struct Channel *chptr, long mode_type) ircd::match_extban(const char *banstr, struct Client *client_p, struct Channel *chptr, long mode_type)
{ {
const char *p; const char *p;
int invert = 0, result = EXTBAN_INVALID; int invert(0), result(INVALID);
ExtbanFunc f; func f;
if (*banstr != '$') if (*banstr != '$')
return 0; return 0;
@ -39,7 +42,7 @@ match_extban(const char *banstr, struct Client *client_p, struct Channel *chptr,
invert = 1; invert = 1;
p++; p++;
} }
f = extban_table[(unsigned char) rfc1459::tolower(*p)]; f = table[uint8_t(rfc1459::tolower(*p))];
if (*p != '\0') if (*p != '\0')
{ {
p++; p++;
@ -49,29 +52,29 @@ match_extban(const char *banstr, struct Client *client_p, struct Channel *chptr,
p = NULL; p = NULL;
} }
if (f != NULL) if (f != NULL)
result = f(p, client_p, chptr, mode_type); result = f(p, client_p, chptr, mode::type(mode_type));
else else
result = EXTBAN_INVALID; result = INVALID;
if (invert) if (invert)
return result == EXTBAN_NOMATCH; return result == NOMATCH;
else else
return result == EXTBAN_MATCH; return result == MATCH;
} }
int int
valid_extban(const char *banstr, struct Client *client_p, struct Channel *chptr, long mode_type) ircd::valid_extban(const char *banstr, struct Client *client_p, struct Channel *chptr, long mode_type)
{ {
const char *p; const char *p;
int result = EXTBAN_INVALID; int result(INVALID);
ExtbanFunc f; func f;
if (*banstr != '$') if (*banstr != '$')
return 0; return 0;
p = banstr + 1; p = banstr + 1;
if (*p == '~') if (*p == '~')
p++; p++;
f = extban_table[(unsigned char) rfc1459::tolower(*p)]; f = table[uint8_t(rfc1459::tolower(*p))];
if (*p != '\0') if (*p != '\0')
{ {
p++; p++;
@ -81,25 +84,23 @@ valid_extban(const char *banstr, struct Client *client_p, struct Channel *chptr,
p = NULL; p = NULL;
} }
if (f != NULL) if (f != NULL)
result = f(p, client_p, chptr, mode_type); result = f(p, client_p, chptr, mode::type(mode_type));
else else
result = EXTBAN_INVALID; result = INVALID;
return result != EXTBAN_INVALID; return result != INVALID;
} }
const char * const char *
get_extban_string(void) ircd::get_extban_string(void)
{ {
static char e[256]; static char e[256];
int i, j; int i, j;
j = 0; j = 0;
for (i = 1; i < 256; i++) for (i = 1; i < 256; i++)
if (i == rfc1459::tolower(i) && extban_table[i]) if (i == rfc1459::tolower(i) && table[i])
e[j++] = i; e[j++] = i;
e[j] = 0; e[j] = 0;
return e; return e;
} }
} // namespace ircd

View file

@ -635,7 +635,7 @@ charybdis_main(int argc, char * const argv[])
init_reject(); init_reject();
cache::init(); cache::init();
init_monitor(); init_monitor();
chmode_init(); chan::mode::init();
init_authd(); /* Start up authd. */ init_authd(); /* Start up authd. */
init_dns(); /* Start up DNS query system */ init_dns(); /* Start up DNS query system */

View file

@ -1866,12 +1866,12 @@ conf_set_channel_autochanmodes(void *data)
break; break;
default: default:
if (chmode_table[(unsigned char) *pm].set_func == chm_simple) if (chan::mode::table[uint8_t(*pm)].set_func == chan::mode::functor::simple)
{ {
if (what == MODE_ADD) if (what == MODE_ADD)
ConfigChannel.autochanmodes |= chmode_table[(unsigned char) *pm].mode_type; ConfigChannel.autochanmodes |= chan::mode::table[uint8_t(*pm)].type;
else else
ConfigChannel.autochanmodes &= ~chmode_table[(unsigned char) *pm].mode_type; ConfigChannel.autochanmodes &= ~chan::mode::table[uint8_t(*pm)].type;
} }
else else
{ {

View file

@ -752,7 +752,7 @@ set_default_conf(void)
ConfigChannel.disable_local_channels = false; ConfigChannel.disable_local_channels = false;
ConfigChannel.displayed_usercount = 3; ConfigChannel.displayed_usercount = 3;
ConfigChannel.autochanmodes = MODE_TOPICLIMIT | MODE_NOPRIVMSGS; ConfigChannel.autochanmodes = chan::mode::TOPICLIMIT | chan::mode::NOPRIVMSGS;
ConfigServerHide.flatten_links = 0; ConfigServerHide.flatten_links = 0;
ConfigServerHide.links_delay = 300; ConfigServerHide.links_delay = 300;
@ -803,7 +803,7 @@ read_conf(void)
/* Some global values are also loaded here. */ /* Some global values are also loaded here. */
check_class(); /* Make sure classes are valid */ check_class(); /* Make sure classes are valid */
privilegeset_delete_all_illegal(); privilegeset_delete_all_illegal();
chmode_init(); chan::mode::init();
} }
static void static void

View file

@ -1313,7 +1313,7 @@ user_welcome(struct Client *source_p)
sendto_one_numeric(source_p, RPL_YOURHOST, form_str(RPL_YOURHOST), sendto_one_numeric(source_p, RPL_YOURHOST, form_str(RPL_YOURHOST),
get_listener_name(source_p->localClient->listener), info::version.c_str()); get_listener_name(source_p->localClient->listener), info::version.c_str());
sendto_one_numeric(source_p, RPL_CREATED, form_str(RPL_CREATED), info::compiled.c_str()); sendto_one_numeric(source_p, RPL_CREATED, form_str(RPL_CREATED), info::compiled.c_str());
sendto_one_numeric(source_p, RPL_MYINFO, form_str(RPL_MYINFO), me.name, info::version.c_str(), umodebuf, chmode_arity[0], chmode_arity[1]); sendto_one_numeric(source_p, RPL_MYINFO, form_str(RPL_MYINFO), me.name, info::version.c_str(), umodebuf, chan::mode::arity[0], chan::mode::arity[1]);
show_isupport(source_p); show_isupport(source_p);

View file

@ -593,7 +593,7 @@ sendto_channel_opmod(struct Client *one, struct Client *source_p,
source_p->name, source_p->username, source_p->name, source_p->username,
source_p->host, command, chptr->chname, text); source_p->host, command, chptr->chname, text);
if (chptr->mode.mode & MODE_MODERATED) if (chptr->mode.mode & chan::mode::MODERATED)
rb_linebuf_putmsg(&rb_linebuf_old, NULL, NULL, rb_linebuf_putmsg(&rb_linebuf_old, NULL, NULL,
":%s %s %s :%s", ":%s %s %s :%s",
use_id(source_p), command, chptr->chname, text); use_id(source_p), command, chptr->chname, text);

View file

@ -227,13 +227,15 @@ isupport_umode(const void *ptr)
static const char * static const char *
isupport_chanmodes(const void *ptr) isupport_chanmodes(const void *ptr)
{ {
using namespace chan::mode;
static char result[80]; static char result[80];
snprintf(result, sizeof result, "%s,%s,%s,%s", snprintf(result, sizeof result, "%s,%s,%s,%s",
chmode_class[CHM_A], categories[uint(category::A)],
chmode_class[CHM_B], categories[uint(category::B)],
chmode_class[CHM_C], categories[uint(category::C)],
chmode_class[CHM_D]); categories[uint(category::D)]);
return result; return result;
} }
@ -302,7 +304,7 @@ isupport_nicklen(const void *ptr)
void void
init_isupport(void) init_isupport(void)
{ {
static int maxmodes = MAXMODEPARAMS; static int maxmodes = chan::mode::MAXPARAMS;
static int channellen = LOC_CHANNELLEN; static int channellen = LOC_CHANNELLEN;
static int topiclen = TOPICLEN; static int topiclen = TOPICLEN;
static int maxnicklen = NICKLEN - 1; static int maxnicklen = NICKLEN - 1;

View file

@ -27,7 +27,7 @@ static const char chm_nocolour_desc[] =
"Enables channel mode +c that filters colours and formatting from a channel"; "Enables channel mode +c that filters colours and formatting from a channel";
static char buf[BUFSIZE]; static char buf[BUFSIZE];
static unsigned int mode_nocolour; static chan::mode::type mode_nocolour;
static void chm_nocolour_process(hook_data_privmsg_channel *); static void chm_nocolour_process(hook_data_privmsg_channel *);
@ -55,7 +55,9 @@ chm_nocolour_process(hook_data_privmsg_channel *data)
static int static int
_modinit(void) _modinit(void)
{ {
mode_nocolour = cflag_add('c', CHM_D, chm_simple); using namespace chan::mode;
mode_nocolour = add('c', category::D, functor::simple);
if (mode_nocolour == 0) if (mode_nocolour == 0)
return -1; return -1;
@ -65,7 +67,9 @@ _modinit(void)
static void static void
_moddeinit(void) _moddeinit(void)
{ {
cflag_orphan('c'); using namespace chan::mode;
orphan('c');
} }
DECLARE_MODULE_AV2(chm_nocolour, _modinit, _moddeinit, NULL, NULL, chm_nocolour_hfnlist, NULL, NULL, chm_nocolour_desc); DECLARE_MODULE_AV2(chm_nocolour, _modinit, _moddeinit, NULL, NULL, chm_nocolour_hfnlist, NULL, NULL, chm_nocolour_desc);

View file

@ -26,7 +26,7 @@ using namespace ircd;
static const char chm_noctcp_desc[] = static const char chm_noctcp_desc[] =
"Adds channel mode +C, which blocks CTCP messages from a channel (except ACTION)"; "Adds channel mode +C, which blocks CTCP messages from a channel (except ACTION)";
static unsigned int mode_noctcp; static chan::mode::type mode_noctcp;
static void chm_noctcp_process(hook_data_privmsg_channel *); static void chm_noctcp_process(hook_data_privmsg_channel *);
@ -55,7 +55,9 @@ chm_noctcp_process(hook_data_privmsg_channel *data)
static int static int
_modinit(void) _modinit(void)
{ {
mode_noctcp = cflag_add('C', CHM_D, chm_simple); using namespace chan::mode;
mode_noctcp = add('C', category::D, functor::simple);
if (mode_noctcp == 0) if (mode_noctcp == 0)
return -1; return -1;
@ -65,7 +67,9 @@ _modinit(void)
static void static void
_moddeinit(void) _moddeinit(void)
{ {
cflag_orphan('C'); using namespace chan::mode;
orphan('C');
} }
DECLARE_MODULE_AV2(chm_noctcp, _modinit, _moddeinit, NULL, NULL, chm_noctcp_hfnlist, NULL, NULL, chm_noctcp_desc); DECLARE_MODULE_AV2(chm_noctcp, _modinit, _moddeinit, NULL, NULL, chm_noctcp_hfnlist, NULL, NULL, chm_noctcp_desc);

View file

@ -63,9 +63,9 @@ static void remove_our_modes(struct Channel *chptr, struct Client *source_p);
static void remove_ban_list(struct Channel *chptr, struct Client *source_p, static void remove_ban_list(struct Channel *chptr, struct Client *source_p,
rb_dlink_list * list, char c, int mems); rb_dlink_list * list, char c, int mems);
static char modebuf[MODEBUFLEN]; static char modebuf[chan::mode::BUFLEN];
static char parabuf[MODEBUFLEN]; static char parabuf[chan::mode::BUFLEN];
static const char *para[MAXMODEPARAMS]; static const char *para[chan::mode::MAXPARAMS];
static char *mbuf; static char *mbuf;
static int pargs; static int pargs;
@ -112,7 +112,7 @@ check_forward(struct Client *source_p, struct Channel *chptr,
if (hash_find_resv(chptr->chname)) if (hash_find_resv(chptr->chname))
return NULL; return NULL;
/* Don't forward to +Q channel */ /* Don't forward to +Q channel */
if (chptr->mode.mode & MODE_DISFORWARD) if (chptr->mode.mode & chan::mode::DISFORWARD)
return NULL; return NULL;
i = can_join(source_p, chptr, key, &next); i = can_join(source_p, chptr, key, &next);
@ -249,7 +249,7 @@ m_join(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p
if(moduledata.approved != 0) if(moduledata.approved != 0)
{ {
if(moduledata.approved != ERR_CUSTOM) if(moduledata.approved != chan::mode::ERR_CUSTOM)
send_join_error(source_p, send_join_error(source_p,
moduledata.approved, moduledata.approved,
name); name);
@ -297,7 +297,7 @@ m_join(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p
* see extensions/chm_operonly.c for other comments on this * see extensions/chm_operonly.c for other comments on this
* -- dwr * -- dwr
*/ */
if(i != ERR_CUSTOM) if(i != chan::mode::ERR_CUSTOM)
send_join_error(source_p, i, name); send_join_error(source_p, i, name);
continue; continue;
} }
@ -570,10 +570,8 @@ ms_sjoin(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source
return; return;
break; break;
default: default:
if(chmode_flags[(int) *s] != 0) if(chan::mode::table[uint8_t(*s)].type != 0)
{ mode.mode |= chan::mode::table[uint8_t(*s)].type;
mode.mode |= chmode_flags[(int) *s];
}
} }
} }
@ -625,7 +623,7 @@ ms_sjoin(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source
* -- jilles */ * -- jilles */
if (ConfigChannel.kick_on_split_riding && if (ConfigChannel.kick_on_split_riding &&
((!HasSentEob(source_p) && ((!HasSentEob(source_p) &&
mode.mode & MODE_INVITEONLY) || mode.mode & chan::mode::INVITEONLY) ||
(mode.key[0] != 0 && irccmp(mode.key, oldmode->key) != 0))) (mode.key[0] != 0 && irccmp(mode.key, oldmode->key) != 0)))
{ {
struct membership *msptr; struct membership *msptr;
@ -827,10 +825,10 @@ ms_sjoin(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source
/* a +ov user.. bleh */ /* a +ov user.. bleh */
if(fl & CHFL_VOICE) if(fl & CHFL_VOICE)
{ {
/* its possible the +o has filled up MAXMODEPARAMS, if so, start /* its possible the +o has filled up chan::mode::MAXPARAMS, if so, start
* a new buffer * a new buffer
*/ */
if(pargs >= MAXMODEPARAMS) if(pargs >= chan::mode::MAXPARAMS)
{ {
*mbuf = '\0'; *mbuf = '\0';
sendto_channel_local(ALL_MEMBERS, chptr, sendto_channel_local(ALL_MEMBERS, chptr,
@ -854,7 +852,7 @@ ms_sjoin(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source
para[pargs++] = target_p->name; para[pargs++] = target_p->name;
} }
if(pargs >= MAXMODEPARAMS) if(pargs >= chan::mode::MAXPARAMS)
{ {
*mbuf = '\0'; *mbuf = '\0';
sendto_channel_local(ALL_MEMBERS, chptr, sendto_channel_local(ALL_MEMBERS, chptr,
@ -899,7 +897,7 @@ ms_sjoin(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source
CheckEmpty(para[2]), CheckEmpty(para[3])); CheckEmpty(para[2]), CheckEmpty(para[3]));
} }
if(!joins && !(chptr->mode.mode & MODE_PERMANENT) && isnew) if(!joins && !(chptr->mode.mode & chan::mode::PERMANENT) && isnew)
{ {
destroy_channel(chptr); destroy_channel(chptr);
@ -1024,7 +1022,7 @@ set_final_mode(struct Mode *mode, struct Mode *oldmode)
/* ok, first get a list of modes we need to add */ /* ok, first get a list of modes we need to add */
for (i = 0; i < 256; i++) for (i = 0; i < 256; i++)
{ {
if((mode->mode & chmode_flags[i]) && !(oldmode->mode & chmode_flags[i])) if((mode->mode & chan::mode::table[i].type) && !(oldmode->mode & chan::mode::table[i].type))
{ {
if(dir != MODE_ADD) if(dir != MODE_ADD)
{ {
@ -1038,7 +1036,7 @@ set_final_mode(struct Mode *mode, struct Mode *oldmode)
/* now the ones we need to remove. */ /* now the ones we need to remove. */
for (i = 0; i < 256; i++) for (i = 0; i < 256; i++)
{ {
if((oldmode->mode & chmode_flags[i]) && !(mode->mode & chmode_flags[i])) if((oldmode->mode & chan::mode::table[i].type) && !(mode->mode & chan::mode::table[i].type))
{ {
if(dir != MODE_DEL) if(dir != MODE_DEL)
{ {
@ -1147,15 +1145,15 @@ remove_our_modes(struct Channel *chptr, struct Client *source_p)
{ {
struct membership *msptr; struct membership *msptr;
rb_dlink_node *ptr; rb_dlink_node *ptr;
char lmodebuf[MODEBUFLEN]; char lmodebuf[chan::mode::BUFLEN];
char *lpara[MAXMODEPARAMS]; char *lpara[chan::mode::MAXPARAMS];
int count = 0; int count = 0;
int i; int i;
mbuf = lmodebuf; mbuf = lmodebuf;
*mbuf++ = '-'; *mbuf++ = '-';
for(i = 0; i < MAXMODEPARAMS; i++) for(i = 0; i < chan::mode::MAXPARAMS; i++)
lpara[i] = NULL; lpara[i] = NULL;
RB_DLINK_FOREACH(ptr, chptr->members.head) RB_DLINK_FOREACH(ptr, chptr->members.head)
@ -1171,7 +1169,7 @@ remove_our_modes(struct Channel *chptr, struct Client *source_p)
/* +ov, might not fit so check. */ /* +ov, might not fit so check. */
if(is_voiced(msptr)) if(is_voiced(msptr))
{ {
if(count >= MAXMODEPARAMS) if(count >= chan::mode::MAXPARAMS)
{ {
*mbuf = '\0'; *mbuf = '\0';
sendto_channel_local(ALL_MEMBERS, chptr, sendto_channel_local(ALL_MEMBERS, chptr,
@ -1185,7 +1183,7 @@ remove_our_modes(struct Channel *chptr, struct Client *source_p)
*mbuf++ = '-'; *mbuf++ = '-';
count = 0; count = 0;
for(i = 0; i < MAXMODEPARAMS; i++) for(i = 0; i < chan::mode::MAXPARAMS; i++)
lpara[i] = NULL; lpara[i] = NULL;
} }
@ -1203,7 +1201,7 @@ remove_our_modes(struct Channel *chptr, struct Client *source_p)
else else
continue; continue;
if(count >= MAXMODEPARAMS) if(count >= chan::mode::MAXPARAMS)
{ {
*mbuf = '\0'; *mbuf = '\0';
sendto_channel_local(ALL_MEMBERS, chptr, sendto_channel_local(ALL_MEMBERS, chptr,
@ -1214,7 +1212,7 @@ remove_our_modes(struct Channel *chptr, struct Client *source_p)
*mbuf++ = '-'; *mbuf++ = '-';
count = 0; count = 0;
for(i = 0; i < MAXMODEPARAMS; i++) for(i = 0; i < chan::mode::MAXPARAMS; i++)
lpara[i] = NULL; lpara[i] = NULL;
} }
} }
@ -1265,7 +1263,7 @@ remove_ban_list(struct Channel *chptr, struct Client *source_p,
plen = strlen(banptr->banstr) + plen = strlen(banptr->banstr) +
(banptr->forward ? strlen(banptr->forward) + 1 : 0) + 2; (banptr->forward ? strlen(banptr->forward) + 1 : 0) + 2;
if(count >= MAXMODEPARAMS || (cur_len + plen) > BUFSIZE - 4) if(count >= chan::mode::MAXPARAMS || (cur_len + plen) > BUFSIZE - 4)
{ {
/* remove trailing space */ /* remove trailing space */
*mbuf = '\0'; *mbuf = '\0';

View file

@ -521,8 +521,8 @@ msg_channel(enum message_type msgtype,
"%s %s :%s", cmdname[msgtype], chptr->chname, text); "%s %s :%s", cmdname[msgtype], chptr->chname, text);
} }
} }
else if(chptr->mode.mode & MODE_OPMODERATE && else if(chptr->mode.mode & chan::mode::OPMODERATE &&
(!(chptr->mode.mode & MODE_NOPRIVMSGS) || (!(chptr->mode.mode & chan::mode::NOPRIVMSGS) ||
IsMember(source_p, chptr))) IsMember(source_p, chptr)))
{ {
if(MyClient(source_p) && !IsOper(source_p) && if(MyClient(source_p) && !IsOper(source_p) &&
@ -589,8 +589,8 @@ msg_channel_opmod(enum message_type msgtype,
return; return;
} }
if(chptr->mode.mode & MODE_OPMODERATE && if(chptr->mode.mode & chan::mode::OPMODERATE &&
(!(chptr->mode.mode & MODE_NOPRIVMSGS) || (!(chptr->mode.mode & chan::mode::NOPRIVMSGS) ||
IsMember(source_p, chptr))) IsMember(source_p, chptr)))
{ {
if(!flood_attack_channel(msgtype, source_p, chptr, chptr->chname)) if(!flood_attack_channel(msgtype, source_p, chptr, chptr->chname))

View file

@ -345,7 +345,7 @@ ms_bmask(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source
tlen = strlen(s); tlen = strlen(s);
/* I dont even want to begin parsing this.. */ /* I dont even want to begin parsing this.. */
if(tlen > MODEBUFLEN) if(tlen > chan::mode::BUFLEN)
break; break;
if((forward = strchr(s+1, '$')) != NULL) if((forward = strchr(s+1, '$')) != NULL)
@ -362,8 +362,8 @@ ms_bmask(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source
if(add_id(fakesource_p, chptr, s, forward, banlist, mode_type)) if(add_id(fakesource_p, chptr, s, forward, banlist, mode_type))
{ {
/* this new one wont fit.. */ /* this new one wont fit.. */
if(mlen + MAXMODEPARAMS + plen + tlen > BUFSIZE - 5 || if(mlen + chan::mode::MAXPARAMS + plen + tlen > BUFSIZE - 5 ||
modecount >= MAXMODEPARAMS) modecount >= chan::mode::MAXPARAMS)
{ {
*mbuf = '\0'; *mbuf = '\0';
*(pbuf - 1) = '\0'; *(pbuf - 1) = '\0';

View file

@ -131,7 +131,7 @@ m_invite(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source
/* unconditionally require ops, unless the channel is +g */ /* unconditionally require ops, unless the channel is +g */
/* treat remote clients as chanops */ /* treat remote clients as chanops */
if(MyClient(source_p) && !is_chanop(msptr) && if(MyClient(source_p) && !is_chanop(msptr) &&
!(chptr->mode.mode & MODE_FREEINVITE)) !(chptr->mode.mode & chan::mode::FREEINVITE))
{ {
sendto_one(source_p, form_str(ERR_CHANOPRIVSNEEDED), sendto_one(source_p, form_str(ERR_CHANOPRIVSNEEDED),
me.name, source_p->name, parv[2]); me.name, source_p->name, parv[2]);
@ -141,8 +141,8 @@ m_invite(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source
/* store invites when they could affect the ability to join /* store invites when they could affect the ability to join
* for +l/+j just check if the mode is set, this varies over time * for +l/+j just check if the mode is set, this varies over time
*/ */
if(chptr->mode.mode & MODE_INVITEONLY || if(chptr->mode.mode & chan::mode::INVITEONLY ||
(chptr->mode.mode & MODE_REGONLY && EmptyString(target_p->user->suser)) || (chptr->mode.mode & chan::mode::REGONLY && EmptyString(target_p->user->suser)) ||
chptr->mode.limit || chptr->mode.join_num) chptr->mode.limit || chptr->mode.join_num)
store_invite = 1; store_invite = 1;

View file

@ -96,7 +96,7 @@ m_knock(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_
return; return;
} }
if(!((chptr->mode.mode & MODE_INVITEONLY) || (*chptr->mode.key) || if(!((chptr->mode.mode & chan::mode::INVITEONLY) || (*chptr->mode.key) ||
(chptr->mode.limit && (chptr->mode.limit &&
rb_dlink_list_length(&chptr->members) >= (unsigned long)chptr->mode.limit))) rb_dlink_list_length(&chptr->members) >= (unsigned long)chptr->mode.limit)))
{ {
@ -153,7 +153,7 @@ m_knock(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_
chptr->last_knock = rb_current_time(); chptr->last_knock = rb_current_time();
if(ConfigChannel.use_knock) if(ConfigChannel.use_knock)
sendto_channel_local(chptr->mode.mode & MODE_FREEINVITE ? ALL_MEMBERS : ONLY_CHANOPS, sendto_channel_local(chptr->mode.mode & chan::mode::FREEINVITE ? ALL_MEMBERS : ONLY_CHANOPS,
chptr, form_str(RPL_KNOCK), chptr, form_str(RPL_KNOCK),
me.name, name, name, source_p->name, me.name, name, name, source_p->name,
source_p->username, source_p->host); source_p->username, source_p->host);

View file

@ -103,7 +103,7 @@ m_topic(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_
return; return;
} }
if(((chptr->mode.mode & MODE_TOPICLIMIT) == 0 || if(((chptr->mode.mode & chan::mode::TOPICLIMIT) == 0 ||
get_channel_access(source_p, chptr, msptr, MODE_ADD, NULL) >= CHFL_CHANOP) && get_channel_access(source_p, chptr, msptr, MODE_ADD, NULL) >= CHFL_CHANOP) &&
(!MyClient(source_p) || (!MyClient(source_p) ||
can_send(chptr, source_p, msptr))) can_send(chptr, source_p, msptr)))