[srvx-commits] CVS: services/src tools.h,1.11,1.12 tools.c,1.91,1.92 proto_ircu_p10.c,1.19,1.20 prot
Brought to you by:
entrope
From: Entrope <en...@us...> - 2001-08-24 20:33:48
|
Update of /cvsroot/srvx/services/src In directory usw-pr-cvs1:/tmp/cvs-serv10154/src Modified Files: tools.h tools.c proto_ircu_p10.c proto_bahamut.c opserv.c main.c chanserv.c Log Message: change make_usermode and make_chanmode to be generic tools Index: tools.h =================================================================== RCS file: /cvsroot/srvx/services/src/tools.h,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -r1.11 -r1.12 *** tools.h 2001/08/19 03:06:09 1.11 --- tools.h 2001/08/24 20:33:45 1.12 *************** *** 35,39 **** void reg_oper_func(oper_func_t handler); ! void tools_cleanup(void); int getusermodes(char *sender); --- 35,39 ---- void reg_oper_func(oper_func_t handler); ! void tools_init(void); int getusermodes(char *sender); *************** *** 84,89 **** void string_buffer_replace(struct string_buffer *buf, unsigned int from, unsigned int len, const char *repl); ! int make_chanmode(struct chanNode *chan, char *out, int len); ! int make_usermode(struct userNode *user, char *out, int len); char *intoa(unsigned long addr); --- 84,89 ---- void string_buffer_replace(struct string_buffer *buf, unsigned int from, unsigned int len, const char *repl); ! int make_chanmode(struct chanNode *chan, char *out, unsigned int len); ! int make_usermode(struct userNode *user, char *out, unsigned int len); char *intoa(unsigned long addr); Index: tools.c =================================================================== RCS file: /cvsroot/srvx/services/src/tools.c,v retrieving revision 1.91 retrieving revision 1.92 diff -C2 -r1.91 -r1.92 *** tools.c 2001/08/19 03:06:09 1.91 --- tools.c 2001/08/24 20:33:45 1.92 *************** *** 88,106 **** } ! static const char *user_modes = PROTO_USER_MODE_CHARS; static unsigned char user_inverse_modes[256]; ! static const char *channel_modes = PROTO_CHANNEL_MODE_CHARS; static unsigned char channel_inverse_modes[256]; void mod_usermode(struct userNode *user, const char *mode_change) { int add = 1; if (!user || !mode_change || !*mode_change) return; while (1) { #define do_user_mode(FLAG) do { if (add) user->modes |= FLAG; else user->modes &= ~FLAG; } while (0) ! switch (*mode_change++) { ! /* TODO: update this to include the new Bahamut channel modes, ! * but to only support them #if (PROTOCOL_CHANMODE_BITS & MODE_foo) ! */ case 0: return; case '+': add = 1; break; --- 88,116 ---- } ! static const unsigned char *user_modes = PROTO_USER_MODE_CHARS; static unsigned char user_inverse_modes[256]; ! static const unsigned char *channel_modes = PROTO_CHANNEL_MODE_CHARS; static unsigned char channel_inverse_modes[256]; + static void + tools_build_inverse_modes(void) { + unsigned int nn; + for (nn=0; user_modes[nn]; nn++) { + user_inverse_modes[user_modes[nn]] = nn + 1; + } + for (nn=0; channel_modes[nn]; nn++) { + channel_inverse_modes[channel_modes[nn]] = nn + 1; + } + } + void mod_usermode(struct userNode *user, const char *mode_change) { int add = 1; + unsigned char modechar; + if (!user || !mode_change || !*mode_change) return; while (1) { #define do_user_mode(FLAG) do { if (add) user->modes |= FLAG; else user->modes &= ~FLAG; } while (0) ! switch (modechar = *mode_change++) { case 0: return; case '+': add = 1; break; *************** *** 124,133 **** if (add) invis_clients++; else invis_clients--; break; ! case 'w': do_user_mode(FLAGS_WALLOP); break; ! case 's': do_user_mode(FLAGS_SERVNOTICE); break; ! case 'd': do_user_mode(FLAGS_DEAF); break; ! case 'k': do_user_mode(FLAGS_SERVICE); break; ! case 'g': do_user_mode(FLAGS_GLOBAL); break; ! case 'h': do_user_mode(FLAGS_HELPER); break; } #undef do_user_mode --- 134,141 ---- if (add) invis_clients++; else invis_clients--; break; ! default: ! if (user_inverse_modes[modechar]) { ! do_user_mode((1 << (user_inverse_modes[modechar]-1))); ! } } #undef do_user_mode *************** *** 136,142 **** int ! make_usermode(struct userNode *user, char *out, int len) { ! /* TODO */ } --- 144,156 ---- int ! make_usermode(struct userNode *user, char *out, unsigned int len) { ! unsigned int nn, jj; ! len--; /* to allow for \0 at end */ ! for (nn=jj=0; user_modes[nn] && (jj<len); nn++) { ! if (user->modes & (1 << nn)) out[jj++] = user_modes[nn]; ! } ! out[jj++] = 0; ! return 1; } *************** *** 146,149 **** --- 160,164 ---- int add = 1, n; const char *word = mode_change; + unsigned char modechar; if (!mode_change || !*mode_change) return; *************** *** 151,158 **** while (*word == ' ') word++; while (1) { ! /* TODO: update this to include the new Bahamut channel modes, ! * but to only support them #if (PROTOCOL_CHANMODE_BITS & MODE_foo) ! */ ! switch (*mode_change++) { case 0: case ' ': --- 166,170 ---- while (*word == ' ') word++; while (1) { ! switch (modechar = *mode_change++) { case 0: case ' ': *************** *** 160,171 **** case '+': add = 1; break; case '-': add = 0; break; - #define do_chan_mode(FLAG) do { if (add) channel->modes |= FLAG; else channel->modes &= ~FLAG; } while (0) - case 'n': do_chan_mode(MODE_NOPRIVMSGS); break; - case 't': do_chan_mode(MODE_TOPICLIMIT); break; - case 's': do_chan_mode(MODE_SECRET); break; - case 'p': do_chan_mode(MODE_PRIVATE); break; - case 'i': do_chan_mode(MODE_INVITEONLY); break; - case 'm': do_chan_mode(MODE_MODERATED); break; - #undef do_chan_mode case 'k': if (add) { --- 172,175 ---- *************** *** 176,180 **** channel->key[n] = *word++; } - channel->key[n] = 0; } --- 180,183 ---- *************** *** 195,198 **** --- 198,211 ---- channel->limit = 0; } + break; + default: + if ((n = channel_inverse_modes[modechar])) { + if (add) { + channel->modes |= 1 << (n-1); + } else { + channel->modes &= ~(1 << (n-1)); + } + } + break; } } *************** *** 200,206 **** int ! make_chanmode(struct chanMode *chan, char *out, int len) { ! } --- 213,241 ---- int ! make_chanmode(struct chanNode *channel, char *out, unsigned int len) { ! unsigned int nn, jj; ! len--; /* to allow for \0 at end */ ! for (nn=jj=0; channel_modes[nn] && (jj<len); nn++) { ! if (channel->modes & (1 << nn)) out[jj++] = channel_modes[nn]; ! } ! if (channel->limit || channel->key[0]) { ! if (jj < len-2) { ! if (channel->limit) out[jj++] = 'l'; ! if (channel->key[0]) out[jj++] = 'k'; ! if (channel->limit) { ! if (jj < len) out[jj++] = ' '; ! jj += snprintf(out+jj, len-jj, "%d", channel->limit); ! if (jj >= len) jj = len-1; ! } ! if (channel->key[0]) { ! if (jj < len) out[jj++] = ' '; ! jj += snprintf(out+jj, len-jj, "%s", channel->key); ! if (jj >= len) jj = len-1; ! } ! } ! } ! out[jj++] = 0; ! return 1; } *************** *** 208,266 **** verify_chanmode(const char *modes) { ! const char *word = modes; ! int add = -1, res, limit; ! ! res = 1; if (!modes) return 0; if (!*modes) return 1; ! while (*word != ' ' && *word) word++; while (*word == ' ') word++; while (1) { ! switch (*modes++) { case 0: case ' ': ! return (add == -1) ? 0 : 1; ! case '+': ! add = 1; ! break; ! case '-': ! add = 0; ! break; ! case 'n': ! case 't': ! case 's': ! case 'p': ! case 'i': ! case 'm': ! break; ! case 'k': ! if(add && !*word) ! { ! return 0; ! } break; case 'l': ! if(add && !*word) ! { ! return 0; ! } ! ! limit = strtoul(word, NULL, 0); ! ! if(add && (!limit || limit < 0)) ! { ! return 0; ! } ! break; default: ! return 0; } } - - return 0; } --- 243,274 ---- verify_chanmode(const char *modes) { ! const char *word; ! int add = 1; ! unsigned char modechar; if (!modes) return 0; if (!*modes) return 1; ! if ((*modes != '+') && (*modes != '-')) return 0; ! word = modes; while (*word != ' ' && *word) word++; while (*word == ' ') word++; while (1) { ! switch (modechar = *modes++) { case 0: case ' ': ! return 1; ! case '+': add = 1; break; ! case '-': add = 0; break; case 'k': ! if (add && !*word) return 0; break; case 'l': ! if (add && (!*word || (strtoul(word, NULL, 0) <= 0))) return 0; break; default: ! if (!channel_inverse_modes[modechar]) return 0; ! break; } } } *************** *** 873,879 **** } ! void tools_cleanup(void) { if (of_list) free(of_list); } --- 881,895 ---- } ! static void tools_cleanup(void) { if (of_list) free(of_list); } + + void + tools_init(void) + { + tools_build_inverse_modes(); + reg_exit_func(tools_cleanup); + } + Index: proto_ircu_p10.c =================================================================== RCS file: /cvsroot/srvx/services/src/proto_ircu_p10.c,v retrieving revision 1.19 retrieving revision 1.20 diff -C2 -r1.19 -r1.20 *** proto_ircu_p10.c 2001/08/19 03:06:09 1.19 --- proto_ircu_p10.c 2001/08/24 20:33:45 1.20 *************** *** 316,335 **** inttobase64(b64ip, user->ip, 6); if (user->modes) { ! int modelen = 0; ! char modes[9]; ! ! if (IsOper(user)) modes[modelen++] = 'o'; ! if (IsInvisible(user)) modes[modelen++] = 'i'; ! if (IsWallOp(user)) modes[modelen++] = 'w'; ! if (IsService(user)) modes[modelen++] = 'k'; ! if (IsServNotice(user)) modes[modelen++] = 's'; ! if (IsDeaf(user)) modes[modelen++] = 'd'; ! if (IsGlobal(user)) modes[modelen++] = 'g'; ! if (IsHelper(user)) modes[modelen++] = 'h'; ! modes[modelen] = 0; ! ! /* we don't need to put the + in modes because it's in the format string. */ ! putsock("%s %s %s %d "FMT_TIME_T" %s %s +%s %s %s :%s", user->uplink->proto.numeric, CMD_NICK, user->nick, user->uplink->hops+1, user->timestamp, user->username, user->hostname, modes, b64ip, user->proto.numeric, user->info); } else { --- 316,323 ---- inttobase64(b64ip, user->ip, 6); if (user->modes) { ! char modes[16]; ! make_usermode(user, modes, sizeof(modes)); ! putsock("%s %s %s %d "FMT_TIME_T" %s %s %s %s %s :%s", user->uplink->proto.numeric, CMD_NICK, user->nick, user->uplink->hops+1, user->timestamp, user->username, user->hostname, modes, b64ip, user->proto.numeric, user->info); } else { *************** *** 453,495 **** } - int - irc_make_chanmode(struct chanNode *chan, char *out) - { - int pos = 0; - - if (!chan->modes) { - out[0] = 0; - return 0; - } - - out[pos++] = '+'; - #define do_chan_mode(MODE,CHAR) if (chan->modes & MODE) out[pos++] = CHAR - do_chan_mode(MODE_PRIVATE, 'p'); - do_chan_mode(MODE_SECRET, 's'); - do_chan_mode(MODE_MODERATED, 'm'); - do_chan_mode(MODE_TOPICLIMIT, 't'); - do_chan_mode(MODE_INVITEONLY, 'i'); - do_chan_mode(MODE_NOPRIVMSGS, 'n'); - #undef do_chan_mode - if (chan->key[0]) out[pos++] = 'k'; - if (chan->limit) out[pos++] = 'l'; - if (chan->key[0]) { - int len = strlen(chan->key); - out[pos++] = ' '; - memcpy(out+pos, chan->key, len); - pos += len; - } - if (chan->limit) { - out[pos++] = ' '; - pos += sprintf(out+pos, "%d", chan->limit); - } - out[pos++] = 0; - return pos; - } - void irc_burst(struct chanNode *chan) { ! char burst_line[512]; int pos, base_len, len; struct modeNode *mn; --- 441,448 ---- } void irc_burst(struct chanNode *chan) { ! char burst_line[510]; int pos, base_len, len; struct modeNode *mn; *************** *** 499,503 **** base_len = sprintf(burst_line, "%s %s %s " FMT_TIME_T " ", self->proto.numeric, CMD_BURST, chan->name, chan->timestamp); ! len = irc_make_chanmode(chan, burst_line+base_len); pos = base_len + len - 1; burst_line[pos++] = ' '; --- 452,456 ---- base_len = sprintf(burst_line, "%s %s %s " FMT_TIME_T " ", self->proto.numeric, CMD_BURST, chan->name, chan->timestamp); ! len = make_chanmode(chan, burst_line+base_len, sizeof(burst_line)-base_len); pos = base_len + len - 1; burst_line[pos++] = ' '; *************** *** 579,585 **** irc_mode(struct userNode *from, struct chanNode *target, const char *modes) { ! struct userMode *mn; const char *src; ! src = ((mn = GetUserMode(target)) && (mn->modes & MODE_CHANOP)) ? from->proto.numeric : self->proto.numeric; putsock("%s %s %s %s "FMT_TIME_T, src, CMD_MODE, target->name, modes, target->timestamp); } --- 532,542 ---- irc_mode(struct userNode *from, struct chanNode *target, const char *modes) { ! struct modeNode *mn; const char *src; ! if ((mn = GetUserMode(target, from)) && (mn->modes & MODE_CHANOP)) { ! src = from->proto.numeric; ! } else { ! src = self->proto.numeric; ! } putsock("%s %s %s %s "FMT_TIME_T, src, CMD_MODE, target->name, modes, target->timestamp); } *************** *** 616,620 **** irc_stats(struct userNode *from, struct server *target, char type) { ! putsock("%s STATS %c :%s", from->numeric, type, target->numeric); } --- 573,577 ---- irc_stats(struct userNode *from, struct server *target, char type) { ! putsock("%s STATS %c :%s", from->proto.numeric, type, target->proto.numeric); } Index: proto_bahamut.c =================================================================== RCS file: /cvsroot/srvx/services/src/proto_bahamut.c,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -r1.9 -r1.10 *** proto_bahamut.c 2001/08/19 03:06:09 1.9 --- proto_bahamut.c 2001/08/24 20:33:45 1.10 *************** *** 214,233 **** irc_user(struct userNode *user) { ! int modelen; ! char modes[9]; ! modelen = 0; ! if (IsOper(user)) modes[modelen++] = 'o'; ! if (IsInvisible(user)) modes[modelen++] = 'i'; ! if (IsWallOp(user)) modes[modelen++] = 'w'; ! if (IsService(user)) modes[modelen++] = 'k'; ! if (IsServNotice(user)) modes[modelen++] = 's'; ! if (IsDeaf(user)) modes[modelen++] = 'd'; ! if (IsGlobal(user)) modes[modelen++] = 'g'; ! if (IsHelper(user)) modes[modelen++] = 'h'; ! modes[modelen] = 0; ! /* we don't need to put the + in modes because it is in this format string. */ ! putsock("%s %s %d "FMT_TIME_T" +%s %s %s %s %lu :%s", CMD_NICK, user->nick, user->uplink->hops+1, user->timestamp, modes, user->username, user->hostname, user->uplink->name, user->ip, user->info); --- 214,222 ---- irc_user(struct userNode *user) { ! char modes[16]; ! make_usermode(user, modes, sizeof(modes)); ! putsock("%s %s %d "FMT_TIME_T" %s %s %s %s %lu :%s", CMD_NICK, user->nick, user->uplink->hops+1, user->timestamp, modes, user->username, user->hostname, user->uplink->name, user->ip, user->info); *************** *** 343,381 **** } - int - irc_make_chanmode(struct chanNode *chan, char *out) - { - int pos = 0; - - if (!chan->modes) { - out[0] = 0; - return 0; - } - - out[pos++] = '+'; - #define do_chan_mode(MODE,CHAR) if (chan->modes & MODE) out[pos++] = CHAR - do_chan_mode(MODE_PRIVATE, 'p'); - do_chan_mode(MODE_SECRET, 's'); - do_chan_mode(MODE_MODERATED, 'm'); - do_chan_mode(MODE_TOPICLIMIT, 't'); - do_chan_mode(MODE_INVITEONLY, 'i'); - do_chan_mode(MODE_NOPRIVMSGS, 'n'); - #undef do_chan_mode - if (chan->key[0]) out[pos++] = 'k'; - if (chan->limit) out[pos++] = 'l'; - if (chan->key[0]) { - int len = strlen(chan->key); - out[pos++] = ' '; - memcpy(out+pos, chan->key, len); - pos += len; - } - if (chan->limit) { - out[pos++] = ' '; - pos += sprintf(out+pos, "%d", chan->limit); - } - out[pos++] = 0; - return pos; - } - void irc_quit(struct userNode *user, const char *message) --- 332,335 ---- *************** *** 547,551 **** (void)key; (void)extra; base_len = snprintf(burst_line, sizeof(burst_line), ":%s SJOIN "FMT_TIME_T" %s ", self->name, channel->timestamp, channel->name); ! pos = base_len + irc_make_chanmode(channel, burst_line+base_len) - 1; burst_line[pos++] = ' '; burst_line[pos++] = ':'; --- 501,505 ---- (void)key; (void)extra; base_len = snprintf(burst_line, sizeof(burst_line), ":%s SJOIN "FMT_TIME_T" %s ", self->name, channel->timestamp, channel->name); ! pos = base_len + make_chanmode(channel, burst_line+base_len, sizeof(burst_line)-base_len) - 1; burst_line[pos++] = ' '; burst_line[pos++] = ':'; Index: opserv.c =================================================================== RCS file: /cvsroot/srvx/services/src/opserv.c,v retrieving revision 1.208 retrieving revision 1.209 diff -C2 -r1.208 -r1.209 *** opserv.c 2001/08/19 03:06:09 1.208 --- opserv.c 2001/08/24 20:33:45 1.209 *************** *** 144,147 **** --- 144,148 ---- #define OSMSG_WHOIS_HOST "Host : %s@%s" #define OSMSG_WHOIS_IP "Real IP : %ld.%ld.%ld.%ld" + #define OSMSG_WHOIS_MODES "Modes : %s" #define OSMSG_WHOIS_INFO "Info : %s" #define OSMSG_WHOIS_NUMERIC "Numeric : %s" *************** *** 530,534 **** opserv_notice(user, "%s", buffer); strcpy(buffer, "Modes: "); ! irc_make_chanmode(channel, buffer+strlen(buffer)); opserv_notice(user, "%s", buffer); if (channel->topic_time > 1) { --- 531,535 ---- opserv_notice(user, "%s", buffer); strcpy(buffer, "Modes: "); ! make_chanmode(channel, buffer+strlen(buffer), sizeof(buffer)-strlen(buffer)); opserv_notice(user, "%s", buffer); if (channel->topic_time > 1) { *************** *** 668,672 **** OPSERV_NEED_CHANNEL(); (void)argc; ! if (irc_make_chanmode(channel, buffer)) { channel->modes = 0; buffer[0] = '-'; --- 669,673 ---- OPSERV_NEED_CHANNEL(); (void)argc; ! if (make_chanmode(channel, buffer, sizeof(buffer))) { channel->modes = 0; buffer[0] = '-'; *************** *** 1220,1224 **** unsigned long ip; char buffer[128]; - int bpos, herelen; OPSERV_MIN_PARMS(2, false); --- 1221,1224 ---- *************** *** 1233,1249 **** opserv_notice(user, OSMSG_WHOIS_IP, (ip >> 24) & 255, (ip >> 16) & 255, (ip >> 8) & 255, ip & 255); if (target->modes) { ! bpos = 0; ! #define buffer_cat(str) (herelen = strlen(str), memcpy(buffer+bpos, str, herelen), bpos += herelen) ! buffer_cat("Modes : +"); ! if (IsInvisible(target)) buffer_cat("i"); ! if (IsWallOp(target)) buffer_cat("w"); ! if (IsOper(target)) buffer_cat("o"); ! if (IsGlobal(target)) buffer_cat("g"); ! if (IsServNotice(target)) buffer_cat("s"); ! if (IsHelper(target)) buffer_cat("h"); ! if (IsService(target)) buffer_cat("k"); ! if (IsDeaf(target)) buffer_cat("d"); ! buffer[bpos] = 0; ! if (buffer[11]) opserv_notice(user, buffer); } opserv_notice(user, OSMSG_WHOIS_INFO, target->info); --- 1233,1238 ---- opserv_notice(user, OSMSG_WHOIS_IP, (ip >> 24) & 255, (ip >> 16) & 255, (ip >> 8) & 255, ip & 255); if (target->modes) { ! make_usermode(target, buffer, sizeof(buffer)); ! opserv_notice(user, OSMSG_WHOIS_MODES, buffer); } opserv_notice(user, OSMSG_WHOIS_INFO, target->info); Index: main.c =================================================================== RCS file: /cvsroot/srvx/services/src/main.c,v retrieving revision 1.108 retrieving revision 1.109 diff -C2 -r1.108 -r1.109 *** main.c 2001/08/19 03:06:09 1.108 --- main.c 2001/08/24 20:33:45 1.109 *************** *** 539,544 **** reg_exit_func(main_cleanup); reg_exit_func(conf_close); - reg_exit_func(tools_cleanup); tmp = conf_server_ping_freq(); if (tmp != -1) ping_freq = tmp; --- 539,544 ---- reg_exit_func(main_cleanup); reg_exit_func(conf_close); + tools_init(); tmp = conf_server_ping_freq(); if (tmp != -1) ping_freq = tmp; Index: chanserv.c =================================================================== RCS file: /cvsroot/srvx/services/src/chanserv.c,v retrieving revision 1.180 retrieving revision 1.181 diff -C2 -r1.180 -r1.181 *** chanserv.c 2001/08/19 03:06:09 1.180 --- chanserv.c 2001/08/24 20:33:45 1.181 *************** *** 3255,3259 **** (void)argc;(void)argv; ! irc_make_chanmode(channel, modes); chanserv_notice(user, CSMSG_PEEK_INFO, channel->name); --- 3255,3259 ---- (void)argc;(void)argv; ! make_chanmode(channel, modes, sizeof(modes)); chanserv_notice(user, CSMSG_PEEK_INFO, channel->name); |