#include "flags.h"
Go to the source code of this file.
Functions | |
void | init_flag_map () |
int | flag_to_str (flags_t *flags, char *str) |
static void | add_flag (unsigned long *longptr, int dir, int flag) |
int | flag_merge_str (flags_t *flags, const char *str) |
int | flag_from_str (flags_t *flags, const char *str) |
int | flag_match_subset (flags_t *left, flags_t *right) |
int | flag_match_exact (flags_t *left, flags_t *right) |
int | flag_match_partial (flags_t *left, flags_t *right) |
int | flag_match_single_char (flags_t *f, unsigned char c) |
void | global_sanity_check (flags_t *flags) |
void | channel_sanity_check (flags_t *flags) |
Variables | |
static const char | rcsid [] = "$Id: flags.c,v 1.11 2004-07-29 19:48:11 darko Exp $" |
unsigned long | flagmap [256] |
static void add_flag | ( | unsigned long * | longptr, | |
int | dir, | |||
int | flag | |||
) | [inline, static] |
void channel_sanity_check | ( | flags_t * | flags | ) |
Definition at line 181 of file flags.c.
References flags_t::builtin, and flagmap.
Referenced by user_set_flags(), and user_set_flags_str().
00182 { 00183 unsigned long builtin = flags->builtin; 00184 00185 /* Suspended op? Remove both +o and +d. User with enough access 00186 to remove his +d can just as easy give himself +o back */ 00187 if (builtin & flagmap['d'] && builtin & flagmap['o']) 00188 builtin &= ~(flagmap['d'] | flagmap['o']); 00189 /* Suspended halfop? Remove both +l */ 00190 if (builtin & flagmap['r'] && builtin & flagmap['l']) 00191 builtin &= ~(flagmap['r'] | flagmap['l']); 00192 /* Suspended voice? Remove both +v and +d */ 00193 if (builtin & flagmap['q'] && builtin & flagmap['v']) 00194 builtin &= ~(flagmap['q'] | flagmap['v']); 00195 /* Owner is also a master */ 00196 if (builtin & flagmap['n']) 00197 builtin |= flagmap['m']; 00198 /* Master is also an op */ 00199 if (builtin & flagmap['m']) 00200 builtin |= flagmap['o']; 00201 /* Op is also a halfop */ 00202 if (builtin & flagmap['o']) 00203 builtin |= flagmap['l']; 00204 00205 flags->builtin = builtin; 00206 }
int flag_from_str | ( | flags_t * | flags, | |
const char * | str | |||
) |
Definition at line 91 of file flags.c.
References flags_t::builtin, flag_merge_str(), and flags_t::udef.
Referenced by append_setting(), bind_entry_add(), bind_entry_modify(), MatchFlags(), MatchFlagsOr(), script_matchflags(), user_check_flags_str(), and user_check_partial_flags_str().
00092 { 00093 /* Always reset flags first. */ 00094 flags->builtin = flags->udef = 0; 00095 return flag_merge_str(flags, str); 00096 }
Definition at line 110 of file flags.c.
References flags_t::builtin, and flags_t::udef.
00111 { 00112 unsigned long builtin, udef; 00113 00114 builtin = left->builtin ^ right->builtin; 00115 udef = left->udef ^ right->udef; 00116 return !(builtin || udef); 00117 }
Definition at line 120 of file flags.c.
References flags_t::builtin, and flags_t::udef.
Referenced by attr_matches_user(), bind_vcheck_hits(), MatchFlagsOr(), script_matchflags(), and user_check_partial_flags().
00121 { 00122 unsigned long builtin, udef; 00123 00124 /* If no bits are on in right, it matches automatically. */ 00125 if (!(right->builtin | right->udef)) return(1); 00126 00127 builtin = left->builtin & right->builtin; 00128 udef = left->udef & right->udef; 00129 return (builtin || udef); 00130 }
int flag_match_single_char | ( | flags_t * | f, | |
unsigned char | c | |||
) |
Definition at line 132 of file flags.c.
References flags_t::builtin, flagmap, and flags_t::udef.
00133 { 00134 if (c >= 'a' && c <= 'z') 00135 return f->builtin & flagmap[c]; 00136 else if (c >= 'A' && c <= 'Z') 00137 return f->udef & flagmap[c]; 00138 else 00139 return 0; 00140 }
Definition at line 100 of file flags.c.
References flags_t::builtin, and flags_t::udef.
Referenced by attr_matches_user(), bind_vcheck_hits(), MatchFlags(), script_matchflags(), and user_check_flags().
00101 { 00102 unsigned long builtin, udef; 00103 00104 builtin = (left->builtin & right->builtin) == left->builtin; 00105 udef = (left->udef & right->udef) == left->udef; 00106 return (builtin && udef); 00107 }
int flag_merge_str | ( | flags_t * | flags, | |
const char * | str | |||
) |
Definition at line 67 of file flags.c.
References add_flag(), flags_t::builtin, and flags_t::udef.
Referenced by flag_from_str(), got352(), got353(), parse_chan_mode(), partyline_cmd_match_attr(), and user_set_flags_str().
00068 { 00069 int dir = 1; 00070 00071 /* If it doesn't start with +/-, then it's absolute. */ 00072 if (*str != '+' && *str != '-') { 00073 flags->builtin = flags->udef = 0; 00074 } 00075 00076 while (*str) { 00077 if (*str >= 'a' && *str <= 'z') { 00078 add_flag(&flags->builtin, dir, *str - 'a'); 00079 } 00080 else if (*str >= 'A' && *str <= 'Z') { 00081 add_flag(&flags->udef, dir, *str - 'A'); 00082 } 00083 else if (*str == '-') dir = -1; 00084 else if (*str == '+') dir = 1; 00085 str++; 00086 } 00087 00088 return 1; 00089 }
int flag_to_str | ( | flags_t * | flags, | |
char * | str | |||
) |
Definition at line 46 of file flags.c.
References flags_t::builtin, and flags_t::udef.
Referenced by channel_get_modes(), channel_get_prefix(), channel_mode(), check_flag_change(), GetFlags(), party_binds(), party_chattr(), party_whois(), save_walker(), and script_getflags().
00047 { 00048 int i, j; 00049 00050 j = 0; 00051 for (i = 0; i < 26; i++) { 00052 if (flags->builtin & (1 << i)) str[j++] = 'a' + i; 00053 } 00054 for (i = 0; i < 26; i++) { 00055 if (flags->udef & (1 << i)) str[j++] = 'A' + i; 00056 } 00057 str[j] = 0; 00058 return 1; 00059 }
void global_sanity_check | ( | flags_t * | flags | ) |
Definition at line 145 of file flags.c.
References flags_t::builtin, and flagmap.
Referenced by user_set_flags(), and user_set_flags_str().
00146 { 00147 unsigned long builtin = flags->builtin; 00148 00149 /* Suspended op? Remove both +o and +d. User with enough access 00150 to remove his +d can just as easy give himself +o back */ 00151 if (builtin & flagmap['d'] && builtin & flagmap['o']) 00152 builtin &= ~(flagmap['d'] | flagmap['o']); 00153 /* Suspended halfop? Remove both +l */ 00154 if (builtin & flagmap['r'] && builtin & flagmap['l']) 00155 builtin &= ~(flagmap['r'] | flagmap['l']); 00156 /* Suspended voice? Remove both +v and +d */ 00157 if (builtin & flagmap['q'] && builtin & flagmap['v']) 00158 builtin &= ~(flagmap['q'] | flagmap['v']); 00159 /* Owner is also a master */ 00160 if (builtin & flagmap['n']) 00161 builtin |= flagmap['m']; 00162 /* Master is botnet master, janitor and op */ 00163 if (builtin & flagmap['m']) 00164 builtin |= flagmap['t'] | flagmap['j'] | flagmap['o']; 00165 /* Botnet master needs partyline access */ 00166 if (builtin & flagmap['t']) 00167 builtin |= flagmap['p']; 00168 /* Janitor needs partyine access and file area */ 00169 if (builtin & flagmap['j']) 00170 builtin |= flagmap['x'] | flagmap['p']; 00171 /* Op is also a halfop */ 00172 if (builtin & flagmap['o']) 00173 builtin |= flagmap['l']; 00174 00175 flags->builtin = builtin; 00176 }
void init_flag_map | ( | ) |
Definition at line 28 of file flags.c.
References flagmap.
Referenced by main().
00029 { 00030 int i; 00031 00032 for (i = 0; i < 'A'; i++) 00033 flagmap[i] = 0; 00034 for (; i <= 'Z'; i++) 00035 flagmap[i] = 1 << (i - 'A'); 00036 for (; i < 'a'; i++) 00037 flagmap[i] = 0; 00038 for (; i <= 'z'; i++) 00039 flagmap[i] = 1 << (i - 'a'); 00040 /* extra space is reserved for future use */ 00041 for (; i < 256; i++) 00042 flagmap[i] = 0; 00043 }
unsigned long flagmap[256] |
Definition at line 26 of file flags.c.
Referenced by channel_sanity_check(), flag_match_single_char(), global_sanity_check(), init_flag_map(), and lookup_flag_by_name().
const char rcsid[] = "$Id: flags.c,v 1.11 2004-07-29 19:48:11 darko Exp $" [static] |