| 1 |
pippijn |
1.1 |
/* |
| 2 |
|
|
* flags.C: Functions to convert a flags table into a bitmask. |
| 3 |
|
|
* Rights to this code are documented in doc/LICENSE. |
| 4 |
|
|
* |
| 5 |
|
|
* Copyright © 2005-2007 Atheme Project (http://www.atheme.org) |
| 6 |
|
|
*/ |
| 7 |
|
|
|
| 8 |
|
|
static char const rcsid[] = "$Id"; |
| 9 |
|
|
|
| 10 |
|
|
#include "atheme.h" |
| 11 |
|
|
#include <account/chanacs.h> |
| 12 |
|
|
|
| 13 |
|
|
#define FLAGS_ADD 0x1 |
| 14 |
|
|
#define FLAGS_DEL 0x2 |
| 15 |
|
|
|
| 16 |
|
|
unsigned int ca_all = CA_ALL_ALL; |
| 17 |
|
|
|
| 18 |
|
|
static char flags_buf[128]; |
| 19 |
|
|
|
| 20 |
|
|
struct flags_table chanacs_flags[] = { |
| 21 |
|
|
{'v', CA_VOICE}, |
| 22 |
|
|
{'V', CA_AUTOVOICE}, |
| 23 |
|
|
{'o', CA_OP}, |
| 24 |
|
|
{'O', CA_AUTOOP}, |
| 25 |
|
|
{'t', CA_TOPIC}, |
| 26 |
|
|
{'s', CA_SET}, |
| 27 |
|
|
{'r', CA_REMOVE}, |
| 28 |
|
|
{'i', CA_INVITE}, |
| 29 |
|
|
{'R', CA_RECOVER}, |
| 30 |
|
|
{'f', CA_FLAGS}, |
| 31 |
|
|
{'h', CA_HALFOP}, |
| 32 |
|
|
{'H', CA_AUTOHALFOP}, |
| 33 |
|
|
{'A', CA_ACLVIEW}, |
| 34 |
|
|
{'b', CA_AKICK}, |
| 35 |
|
|
{0, 0} |
| 36 |
|
|
}; |
| 37 |
|
|
|
| 38 |
|
|
/* Construct bitmasks to be added and removed |
| 39 |
|
|
* Postcondition *addflags & *removeflags == 0 |
| 40 |
|
|
* -- jilles */ |
| 41 |
|
|
void |
| 42 |
|
|
flags_make_bitmasks (const char *string, struct flags_table table[], unsigned int *addflags, unsigned int *removeflags) |
| 43 |
|
|
{ |
| 44 |
|
|
int status = FLAGS_ADD; |
| 45 |
|
|
short i = 0; |
| 46 |
|
|
|
| 47 |
|
|
*addflags = *removeflags = 0; |
| 48 |
|
|
while (*string) |
| 49 |
|
|
{ |
| 50 |
|
|
switch (*string) |
| 51 |
|
|
{ |
| 52 |
|
|
case '+': |
| 53 |
|
|
status = FLAGS_ADD; |
| 54 |
|
|
break; |
| 55 |
|
|
|
| 56 |
|
|
case '-': |
| 57 |
|
|
status = FLAGS_DEL; |
| 58 |
|
|
break; |
| 59 |
|
|
|
| 60 |
|
|
case '=': |
| 61 |
|
|
*addflags = 0; |
| 62 |
|
|
*removeflags = 0xFFFFFFFF; |
| 63 |
|
|
status = FLAGS_ADD; |
| 64 |
|
|
break; |
| 65 |
|
|
|
| 66 |
|
|
case '*': |
| 67 |
|
|
if (status == FLAGS_ADD) |
| 68 |
|
|
{ |
| 69 |
|
|
*addflags = 0xFFFFFFFF; |
| 70 |
|
|
*removeflags = 0; |
| 71 |
|
|
|
| 72 |
|
|
/* If this is chanacs_flags[], remove the ban flag. */ |
| 73 |
|
|
if (table == chanacs_flags) |
| 74 |
|
|
{ |
| 75 |
|
|
*addflags &= CA_ALLPRIVS & ca_all; |
| 76 |
|
|
*removeflags |= CA_AKICK; |
| 77 |
|
|
} |
| 78 |
|
|
} |
| 79 |
|
|
else if (status == FLAGS_DEL) |
| 80 |
|
|
{ |
| 81 |
|
|
*addflags = 0; |
| 82 |
|
|
*removeflags = 0xFFFFFFFF; |
| 83 |
|
|
} |
| 84 |
|
|
break; |
| 85 |
|
|
|
| 86 |
|
|
default: |
| 87 |
|
|
for (i = 0; table[i].flag; i++) |
| 88 |
|
|
if (table[i].flag == *string) |
| 89 |
|
|
{ |
| 90 |
|
|
if (status == FLAGS_ADD) |
| 91 |
|
|
{ |
| 92 |
|
|
*addflags |= table[i].value; |
| 93 |
|
|
*removeflags &= ~table[i].value; |
| 94 |
|
|
} |
| 95 |
|
|
else if (status == FLAGS_DEL) |
| 96 |
|
|
{ |
| 97 |
|
|
*addflags &= ~table[i].value; |
| 98 |
|
|
*removeflags |= table[i].value; |
| 99 |
|
|
} |
| 100 |
|
|
} |
| 101 |
|
|
} |
| 102 |
|
|
|
| 103 |
|
|
(void) *string++; |
| 104 |
|
|
} |
| 105 |
|
|
|
| 106 |
|
|
return; |
| 107 |
|
|
} |
| 108 |
|
|
|
| 109 |
|
|
unsigned int |
| 110 |
|
|
flags_to_bitmask (const char *string, struct flags_table table[], unsigned int flags) |
| 111 |
|
|
{ |
| 112 |
|
|
int bitmask = (flags ? flags : 0x0); |
| 113 |
|
|
int status = FLAGS_ADD; |
| 114 |
|
|
short i = 0; |
| 115 |
|
|
|
| 116 |
|
|
while (*string) |
| 117 |
|
|
{ |
| 118 |
|
|
switch (*string) |
| 119 |
|
|
{ |
| 120 |
|
|
case '+': |
| 121 |
|
|
status = FLAGS_ADD; |
| 122 |
|
|
break; |
| 123 |
|
|
|
| 124 |
|
|
case '-': |
| 125 |
|
|
status = FLAGS_DEL; |
| 126 |
|
|
break; |
| 127 |
|
|
|
| 128 |
|
|
case '=': |
| 129 |
|
|
bitmask = 0; |
| 130 |
|
|
status = FLAGS_ADD; |
| 131 |
|
|
break; |
| 132 |
|
|
|
| 133 |
|
|
case '*': |
| 134 |
|
|
if (status == FLAGS_ADD) |
| 135 |
|
|
{ |
| 136 |
|
|
bitmask = 0xFFFFFFFF; |
| 137 |
|
|
|
| 138 |
|
|
/* If this is chanacs_flags[], do privs only */ |
| 139 |
|
|
if (table == chanacs_flags) |
| 140 |
|
|
bitmask &= CA_ALLPRIVS & ca_all; |
| 141 |
|
|
} |
| 142 |
|
|
else if (status == FLAGS_DEL) |
| 143 |
|
|
bitmask = 0; |
| 144 |
|
|
break; |
| 145 |
|
|
|
| 146 |
|
|
default: |
| 147 |
|
|
for (i = 0; table[i].flag; i++) |
| 148 |
|
|
if (table[i].flag == *string) |
| 149 |
|
|
{ |
| 150 |
|
|
if (status == FLAGS_ADD) |
| 151 |
|
|
bitmask |= table[i].value; |
| 152 |
|
|
else if (status == FLAGS_DEL) |
| 153 |
|
|
bitmask &= ~table[i].value; |
| 154 |
|
|
} |
| 155 |
|
|
} |
| 156 |
|
|
|
| 157 |
|
|
(void) *string++; |
| 158 |
|
|
} |
| 159 |
|
|
|
| 160 |
|
|
return bitmask; |
| 161 |
|
|
} |
| 162 |
|
|
|
| 163 |
|
|
char * |
| 164 |
|
|
bitmask_to_flags (unsigned int flags, struct flags_table table[]) |
| 165 |
|
|
{ |
| 166 |
|
|
char *bptr; |
| 167 |
|
|
short i = 0; |
| 168 |
|
|
|
| 169 |
|
|
bptr = flags_buf; |
| 170 |
|
|
|
| 171 |
|
|
*bptr++ = '+'; |
| 172 |
|
|
|
| 173 |
|
|
for (i = 0; table[i].flag; i++) |
| 174 |
|
|
if (table[i].value & flags) |
| 175 |
|
|
*bptr++ = table[i].flag; |
| 176 |
|
|
|
| 177 |
|
|
*bptr++ = '\0'; |
| 178 |
|
|
|
| 179 |
|
|
return flags_buf; |
| 180 |
|
|
} |
| 181 |
|
|
|
| 182 |
|
|
char * |
| 183 |
|
|
bitmask_to_flags2 (unsigned int addflags, unsigned int removeflags, struct flags_table table[]) |
| 184 |
|
|
{ |
| 185 |
|
|
char *bptr; |
| 186 |
|
|
short i = 0; |
| 187 |
|
|
|
| 188 |
|
|
bptr = flags_buf; |
| 189 |
|
|
|
| 190 |
|
|
if (removeflags) |
| 191 |
|
|
{ |
| 192 |
|
|
*bptr++ = '-'; |
| 193 |
|
|
for (i = 0; table[i].flag; i++) |
| 194 |
|
|
if (table[i].value & removeflags) |
| 195 |
|
|
*bptr++ = table[i].flag; |
| 196 |
|
|
} |
| 197 |
|
|
if (addflags) |
| 198 |
|
|
{ |
| 199 |
|
|
*bptr++ = '+'; |
| 200 |
|
|
for (i = 0; table[i].flag; i++) |
| 201 |
|
|
if (table[i].value & addflags) |
| 202 |
|
|
*bptr++ = table[i].flag; |
| 203 |
|
|
} |
| 204 |
|
|
|
| 205 |
|
|
*bptr++ = '\0'; |
| 206 |
|
|
|
| 207 |
|
|
return flags_buf; |
| 208 |
|
|
} |
| 209 |
|
|
|
| 210 |
|
|
/* flags a non-founder with +f and these flags is allowed to set -- jilles */ |
| 211 |
|
|
unsigned int |
| 212 |
|
|
allow_flags (unsigned int flags) |
| 213 |
|
|
{ |
| 214 |
|
|
flags &= ~CA_AKICK; |
| 215 |
|
|
if (flags & CA_REMOVE) |
| 216 |
|
|
flags |= CA_AKICK; |
| 217 |
|
|
if (flags & CA_OP) |
| 218 |
|
|
flags |= CA_AUTOOP; |
| 219 |
|
|
if (flags & CA_HALFOP) |
| 220 |
|
|
flags |= CA_AUTOHALFOP; |
| 221 |
|
|
if (flags & CA_VOICE) |
| 222 |
|
|
flags |= CA_AUTOVOICE; |
| 223 |
|
|
return flags; |
| 224 |
|
|
} |
| 225 |
|
|
|
| 226 |
|
|
void |
| 227 |
|
|
update_chanacs_flags (void) |
| 228 |
|
|
{ |
| 229 |
|
|
ca_all = CA_ALL_ALL; |
| 230 |
|
|
if (!ircd->uses_halfops) |
| 231 |
|
|
ca_all &= ~(CA_HALFOP | CA_AUTOHALFOP); |
| 232 |
|
|
} |
| 233 |
|
|
|
| 234 |
|
|
/* vim:cinoptions=>s,e0,n0,f0,{0,}0,^0,=s,ps,t0,c3,+s,(2s,us,)20,*30,gs,hs |
| 235 |
|
|
* vim:ts=8 |
| 236 |
|
|
* vim:sw=8 |
| 237 |
|
|
* vim:noexpandtab |
| 238 |
|
|
*/ |