Merge pull request #24 from Elemental-IRCd/chore/restyle-code

Change all code to a consistent style
This commit is contained in:
Sam Dodrill 2014-08-06 18:13:29 -07:00
commit 22db314d25
254 changed files with 44148 additions and 48443 deletions

View File

@ -40,8 +40,7 @@
#define COMMIT_INTERVAL 3 /* seconds */ #define COMMIT_INTERVAL 3 /* seconds */
typedef enum typedef enum {
{
BANDB_KLINE, BANDB_KLINE,
BANDB_DLINE, BANDB_DLINE,
BANDB_XLINE, BANDB_XLINE,
@ -81,12 +80,10 @@ parse_ban(bandb_type type, char *parv[], int parc)
const char *perm = NULL; const char *perm = NULL;
int para = 1; int para = 1;
if(type == BANDB_KLINE) if(type == BANDB_KLINE) {
{
if(parc != 7) if(parc != 7)
return; return;
} } else if(parc != 6)
else if(parc != 6)
return; return;
mask1 = parv[para++]; mask1 = parv[para++];
@ -99,8 +96,7 @@ parse_ban(bandb_type type, char *parv[], int parc)
perm = parv[para++]; perm = parv[para++];
reason = parv[para++]; reason = parv[para++];
if(!in_transaction) if(!in_transaction) {
{
rsdb_transaction(RSDB_TRANS_START); rsdb_transaction(RSDB_TRANS_START);
in_transaction = 1; in_transaction = 1;
rb_event_addonce("bandb_commit", bandb_commit, NULL, rb_event_addonce("bandb_commit", bandb_commit, NULL,
@ -118,12 +114,10 @@ parse_unban(bandb_type type, char *parv[], int parc)
const char *mask1 = NULL; const char *mask1 = NULL;
const char *mask2 = NULL; const char *mask2 = NULL;
if(type == BANDB_KLINE) if(type == BANDB_KLINE) {
{
if(parc != 3) if(parc != 3)
return; return;
} } else if(parc != 2)
else if(parc != 2)
return; return;
mask1 = parv[1]; mask1 = parv[1];
@ -131,8 +125,7 @@ parse_unban(bandb_type type, char *parv[], int parc)
if(type == BANDB_KLINE) if(type == BANDB_KLINE)
mask2 = parv[2]; mask2 = parv[2];
if(!in_transaction) if(!in_transaction) {
{
rsdb_transaction(RSDB_TRANS_START); rsdb_transaction(RSDB_TRANS_START);
in_transaction = 1; in_transaction = 1;
rb_event_addonce("bandb_commit", bandb_commit, NULL, rb_event_addonce("bandb_commit", bandb_commit, NULL,
@ -153,13 +146,11 @@ list_bans(void)
/* schedule a clear of anything already pending */ /* schedule a clear of anything already pending */
rb_helper_write_queue(bandb_helper, "C"); rb_helper_write_queue(bandb_helper, "C");
for(i = 0; i < LAST_BANDB_TYPE; i++) for(i = 0; i < LAST_BANDB_TYPE; i++) {
{
rsdb_exec_fetch(&table, "SELECT mask1,mask2,oper,reason FROM %s WHERE 1", rsdb_exec_fetch(&table, "SELECT mask1,mask2,oper,reason FROM %s WHERE 1",
bandb_table[i]); bandb_table[i]);
for(j = 0; j < table.row_count; j++) for(j = 0; j < table.row_count; j++) {
{
if(i == BANDB_KLINE) if(i == BANDB_KLINE)
rb_snprintf(buf, sizeof(buf), "%c %s %s %s :%s", rb_snprintf(buf, sizeof(buf), "%c %s %s %s :%s",
bandb_letter[i], table.row[j][0], bandb_letter[i], table.row[j][0],
@ -187,15 +178,13 @@ parse_request(rb_helper *helper)
int len; int len;
while((len = rb_helper_read(helper, readbuf, sizeof(readbuf))) > 0) while((len = rb_helper_read(helper, readbuf, sizeof(readbuf))) > 0) {
{
parc = rb_string_to_array(readbuf, parv, MAXPARA); parc = rb_string_to_array(readbuf, parv, MAXPARA);
if(parc < 1) if(parc < 1)
continue; continue;
switch (parv[0][0]) switch (parv[0][0]) {
{
case 'K': case 'K':
parse_ban(BANDB_KLINE, parv, parc); parse_ban(BANDB_KLINE, parv, parc);
break; break;
@ -299,8 +288,7 @@ main(int argc, char *argv[])
{ {
setup_signals(); setup_signals();
bandb_helper = rb_helper_child(parse_request, error_cb, NULL, NULL, NULL, 256, 256, 256, 256); /* XXX fix me */ bandb_helper = rb_helper_child(parse_request, error_cb, NULL, NULL, NULL, 256, 256, 256, 256); /* XXX fix me */
if(bandb_helper == NULL) if(bandb_helper == NULL) {
{
fprintf(stderr, fprintf(stderr,
"This is ircd-ratbox bandb. You aren't supposed to run me directly. Maybe you want bantool?\n"); "This is ircd-ratbox bandb. You aren't supposed to run me directly. Maybe you want bantool?\n");
fprintf(stderr, fprintf(stderr,
@ -321,8 +309,7 @@ check_schema(void)
struct rsdb_table table; struct rsdb_table table;
int i; int i;
for(i = 0; i < LAST_BANDB_TYPE; i++) for(i = 0; i < LAST_BANDB_TYPE; i++) {
{
rsdb_exec_fetch(&table, rsdb_exec_fetch(&table,
"SELECT name FROM sqlite_master WHERE type='table' AND name='%s'", "SELECT name FROM sqlite_master WHERE type='table' AND name='%s'",
bandb_table[i]); bandb_table[i]);

View File

@ -51,8 +51,7 @@
#define BT_VERSION "0.4.1" #define BT_VERSION "0.4.1"
typedef enum typedef enum {
{
BANDB_KLINE, BANDB_KLINE,
BANDB_KLINE_PERM, BANDB_KLINE_PERM,
BANDB_DLINE, BANDB_DLINE,
@ -84,8 +83,7 @@ static char me[PATH_MAX];
/* *INDENT-OFF* */ /* *INDENT-OFF* */
/* report counters */ /* report counters */
struct counter struct counter {
{
unsigned int klines; unsigned int klines;
unsigned int dlines; unsigned int dlines;
unsigned int xlines; unsigned int xlines;
@ -94,8 +92,7 @@ struct counter
} count = {0, 0, 0, 0, 0}; } count = {0, 0, 0, 0, 0};
/* flags set by command line options */ /* flags set by command line options */
struct flags struct flags {
{
int none; int none;
int export; int export;
int import; int import;
@ -140,10 +137,8 @@ main(int argc, char *argv[])
rb_strlcpy(me, argv[0], sizeof(me)); rb_strlcpy(me, argv[0], sizeof(me));
while((opt = getopt(argc, argv, "hieuspvwd")) != -1) while((opt = getopt(argc, argv, "hieuspvwd")) != -1) {
{ switch (opt) {
switch (opt)
{
case 'h': case 'h':
print_help(EXIT_SUCCESS); print_help(EXIT_SUCCESS);
break; break;
@ -185,8 +180,7 @@ main(int argc, char *argv[])
print_help(EXIT_FAILURE); print_help(EXIT_FAILURE);
if((flag.import && flag.export) || (flag.export && flag.wipe) if((flag.import && flag.export) || (flag.export && flag.wipe)
|| (flag.verify && flag.pretend) || (flag.export && flag.pretend)) || (flag.verify && flag.pretend) || (flag.export && flag.pretend)) {
{
fprintf(stderr, "* Error: Conflicting flags.\n"); fprintf(stderr, "* Error: Conflicting flags.\n");
if(flag.export && flag.pretend) if(flag.export && flag.pretend)
fprintf(stderr, "* There is nothing to 'pretend' when exporting.\n"); fprintf(stderr, "* There is nothing to 'pretend' when exporting.\n");
@ -204,10 +198,8 @@ main(int argc, char *argv[])
"* ircd-ratbox bantool v.%s ($Id: bantool.c 26164 2008-10-26 19:52:43Z androsyn $)\n", "* ircd-ratbox bantool v.%s ($Id: bantool.c 26164 2008-10-26 19:52:43Z androsyn $)\n",
BT_VERSION); BT_VERSION);
if(flag.pretend == NO) if(flag.pretend == NO) {
{ if(rsdb_init(db_error_cb) == -1) {
if(rsdb_init(db_error_cb) == -1)
{
fprintf(stderr, "* Error: Unable to open database\n"); fprintf(stderr, "* Error: Unable to open database\n");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
@ -216,8 +208,7 @@ main(int argc, char *argv[])
if(flag.vacuum) if(flag.vacuum)
db_reclaim_slack(); db_reclaim_slack();
if(flag.import && flag.wipe) if(flag.import && flag.wipe) {
{
flag.dupes_ok = YES; /* dont check for dupes if we are wiping the db clean */ flag.dupes_ok = YES; /* dont check for dupes if we are wiping the db clean */
for(i = 0; i < 3; i++) for(i = 0; i < 3; i++)
fprintf(stdout, fprintf(stdout,
@ -234,8 +225,7 @@ main(int argc, char *argv[])
fprintf(stdout, "* Allowing duplicate bans...\n"); fprintf(stdout, "* Allowing duplicate bans...\n");
/* checking for our files to import or export */ /* checking for our files to import or export */
for(i = 0; i < LAST_BANDB_TYPE; i++) for(i = 0; i < LAST_BANDB_TYPE; i++) {
{
rb_snprintf(conf, sizeof(conf), "%s/%s.conf%s", rb_snprintf(conf, sizeof(conf), "%s/%s.conf%s",
etc, bandb_table[i], bandb_suffix[i]); etc, bandb_table[i], bandb_suffix[i]);
@ -252,8 +242,7 @@ main(int argc, char *argv[])
rsdb_transaction(RSDB_TRANS_END); rsdb_transaction(RSDB_TRANS_END);
} }
if(flag.import) if(flag.import) {
{
if(count.error && flag.verbose) if(count.error && flag.verbose)
fprintf(stderr, "* I was unable to locate %i config files to import.\n", fprintf(stderr, "* I was unable to locate %i config files to import.\n",
count.error); count.error);
@ -306,8 +295,7 @@ export_config(const char *conf, int id)
bandb_table[id]); bandb_table[id]);
rsdb_exec_fetch(&table, sql); rsdb_exec_fetch(&table, sql);
if(table.row_count <= 0) if(table.row_count <= 0) {
{
rsdb_exec_fetch_end(&table); rsdb_exec_fetch_end(&table);
return; return;
} }
@ -316,18 +304,15 @@ export_config(const char *conf, int id)
fprintf(stdout, "* checking for %s: ", conf); /* debug */ fprintf(stdout, "* checking for %s: ", conf); /* debug */
/* open config for reading, or skip to the next */ /* open config for reading, or skip to the next */
if(!(fd = fopen(conf, "w"))) if(!(fd = fopen(conf, "w"))) {
{
if(flag.verbose) if(flag.verbose)
fprintf(stdout, "\tmissing.\n"); fprintf(stdout, "\tmissing.\n");
count.error++; count.error++;
return; return;
} }
for(j = 0; j < table.row_count; j++) for(j = 0; j < table.row_count; j++) {
{ switch (id) {
switch (id)
{
case BANDB_DLINE: case BANDB_DLINE:
case BANDB_DLINE_PERM: case BANDB_DLINE_PERM:
rb_snprintf(buf, sizeof(buf), rb_snprintf(buf, sizeof(buf),
@ -401,8 +386,7 @@ import_config(const char *conf, int id)
fprintf(stdout, "* checking for %s: ", conf); /* debug */ fprintf(stdout, "* checking for %s: ", conf); /* debug */
/* open config for reading, or skip to the next */ /* open config for reading, or skip to the next */
if(!(fd = fopen(conf, "r"))) if(!(fd = fopen(conf, "r"))) {
{
if(flag.verbose) if(flag.verbose)
fprintf(stdout, "%*s", strlen(bandb_suffix[id]) > 0 ? 10 : 15, fprintf(stdout, "%*s", strlen(bandb_suffix[id]) > 0 ? 10 : 15,
"missing.\n"); "missing.\n");
@ -421,8 +405,7 @@ import_config(const char *conf, int id)
* dline * dline
* "194.158.192.0/19","laptop scammers","","2005/3/17 05.33","stevoo!stevoo@efnet.port80.se{stevoo}",1111033988 * "194.158.192.0/19","laptop scammers","","2005/3/17 05.33","stevoo!stevoo@efnet.port80.se{stevoo}",1111033988
*/ */
while(fgets(line, sizeof(line), fd)) while(fgets(line, sizeof(line), fd)) {
{
if((p = strpbrk(line, "\r\n")) != NULL) if((p = strpbrk(line, "\r\n")) != NULL)
*p = '\0'; *p = '\0';
@ -436,8 +419,7 @@ import_config(const char *conf, int id)
continue; continue;
/* mask2 */ /* mask2 */
switch (id) switch (id) {
{
case BANDB_XLINE: case BANDB_XLINE:
case BANDB_XLINE_PERM: case BANDB_XLINE_PERM:
f_mask1 = escape_quotes(clean_gecos_field(f_mask1)); f_mask1 = escape_quotes(clean_gecos_field(f_mask1));
@ -463,8 +445,7 @@ import_config(const char *conf, int id)
continue; continue;
/* oper comment */ /* oper comment */
switch (id) switch (id) {
{
case BANDB_KLINE: case BANDB_KLINE:
case BANDB_KLINE_PERM: case BANDB_KLINE_PERM:
case BANDB_DLINE: case BANDB_DLINE:
@ -483,10 +464,8 @@ import_config(const char *conf, int id)
f_oper = "unknown"; f_oper = "unknown";
/* meh */ /* meh */
if(id == BANDB_KLINE || id == BANDB_KLINE_PERM) if(id == BANDB_KLINE || id == BANDB_KLINE_PERM) {
{ if(strstr(f_mask1, "!") != NULL) {
if(strstr(f_mask1, "!") != NULL)
{
fprintf(stderr, fprintf(stderr,
"* SKIPPING INVALID KLINE %s@%s set by %s\n", "* SKIPPING INVALID KLINE %s@%s set by %s\n",
f_mask1, f_mask2, f_oper); f_mask1, f_mask2, f_oper);
@ -501,8 +480,7 @@ import_config(const char *conf, int id)
else else
rb_snprintf(newreason, sizeof(newreason), "%s", f_reason); rb_snprintf(newreason, sizeof(newreason), "%s", f_reason);
if(flag.pretend == NO) if(flag.pretend == NO) {
{
if(flag.dupes_ok == NO) if(flag.dupes_ok == NO)
drop_dupes(f_mask1, f_mask2, bandb_table[id]); drop_dupes(f_mask1, f_mask2, bandb_table[id]);
@ -521,8 +499,7 @@ import_config(const char *conf, int id)
i++; i++;
} }
switch (bandb_letter[id]) switch (bandb_letter[id]) {
{
case 'K': case 'K':
count.klines += i; count.klines += i;
break; break;
@ -574,27 +551,20 @@ getfield(char *newline)
end = strchr(line, ','); end = strchr(line, ',');
while(1) while(1) {
{
/* no trailing , - last field */ /* no trailing , - last field */
if(end == NULL) if(end == NULL) {
{
end = line + strlen(line); end = line + strlen(line);
line = NULL; line = NULL;
if(*end == '"') if(*end == '"') {
{
*end = '\0'; *end = '\0';
return field; return field;
} } else
else
return NULL; return NULL;
} } else {
else
{
/* look for a ", to mark the end of a field.. */ /* look for a ", to mark the end of a field.. */
if(*(end - 1) == '"') if(*(end - 1) == '"') {
{
line = end + 1; line = end + 1;
end--; end--;
*end = '\0'; *end = '\0';
@ -622,10 +592,8 @@ strip_quotes(const char *string)
if(string == NULL) if(string == NULL)
return NULL; return NULL;
while(*string) while(*string) {
{ if(*string != '"') {
if(*string != '"')
{
*str++ = *string; *str++ = *string;
} }
string++; string++;
@ -646,15 +614,11 @@ escape_quotes(const char *string)
if(string == NULL) if(string == NULL)
return NULL; return NULL;
while(*string) while(*string) {
{ if(*string == '"') {
if(*string == '"')
{
*str++ = '\\'; *str++ = '\\';
*str++ = '"'; *str++ = '"';
} } else {
else
{
*str++ = *string; *str++ = *string;
} }
string++; string++;
@ -673,10 +637,8 @@ mangle_reason(const char *string)
if(string == NULL) if(string == NULL)
return NULL; return NULL;
while(*string) while(*string) {
{ switch (*string) {
switch (*string)
{
case '"': case '"':
*str = '\''; *str = '\'';
break; break;
@ -707,14 +669,11 @@ clean_gecos_field(const char *gecos)
if(gecos == NULL) if(gecos == NULL)
return NULL; return NULL;
while(*gecos) while(*gecos) {
{ if(*gecos == ' ') {
if(*gecos == ' ')
{
*str++ = '\\'; *str++ = '\\';
*str++ = 's'; *str++ = 's';
} } else
else
*str++ = *gecos; *str++ = *gecos;
gecos++; gecos++;
} }
@ -744,10 +703,8 @@ check_schema(void)
NULL NULL
}; };
for(i = 0; i < LAST_BANDB_TYPE; i++) for(i = 0; i < LAST_BANDB_TYPE; i++) {
{ if(!table_exists(bandb_table[i])) {
if(!table_exists(bandb_table[i]))
{
rsdb_exec(NULL, rsdb_exec(NULL,
"CREATE TABLE %s (mask1 TEXT, mask2 TEXT, oper TEXT, time INTEGER, perm INTEGER, reason TEXT)", "CREATE TABLE %s (mask1 TEXT, mask2 TEXT, oper TEXT, time INTEGER, perm INTEGER, reason TEXT)",
bandb_table[i]); bandb_table[i]);
@ -757,10 +714,8 @@ check_schema(void)
* i can't think of any better way to do this, other then attempt to * i can't think of any better way to do this, other then attempt to
* force the creation of column that may, or may not already exist. --dubkat * force the creation of column that may, or may not already exist. --dubkat
*/ */
else else {
{ for(j = 0; columns[j] != NULL; j++) {
for(j = 0; columns[j] != NULL; j++)
{
if(!strcmp(columns[j], "time") && !strcmp(columns[j], "perm")) if(!strcmp(columns[j], "time") && !strcmp(columns[j], "perm"))
rb_strlcpy(type, "INTEGER", sizeof(type)); rb_strlcpy(type, "INTEGER", sizeof(type));
else else
@ -817,8 +772,7 @@ wipe_schema(void)
{ {
int i; int i;
rsdb_transaction(RSDB_TRANS_START); rsdb_transaction(RSDB_TRANS_START);
for(i = 0; i < LAST_BANDB_TYPE; i++) for(i = 0; i < LAST_BANDB_TYPE; i++) {
{
rsdb_exec(NULL, "DROP TABLE %s", bandb_table[i]); rsdb_exec(NULL, "DROP TABLE %s", bandb_table[i]);
i++; /* double increment to skip over .perm */ i++; /* double increment to skip over .perm */
} }

View File

@ -6,15 +6,13 @@ typedef void rsdb_error_cb(const char *);
typedef int (*rsdb_callback) (int, const char **); typedef int (*rsdb_callback) (int, const char **);
typedef enum rsdb_transtype typedef enum rsdb_transtype {
{
RSDB_TRANS_START, RSDB_TRANS_START,
RSDB_TRANS_END RSDB_TRANS_END
} }
rsdb_transtype; rsdb_transtype;
struct rsdb_table struct rsdb_table {
{
char ***row; char ***row;
int row_count; int row_count;
int col_count; int col_count;

View File

@ -278,10 +278,8 @@ rs_vsnprintf(char *dest, const size_t bytes, const char *format, va_list args)
int written = 0; /* bytes written so far */ int written = 0; /* bytes written so far */
int maxbytes = bytes - 1; int maxbytes = bytes - 1;
while((ch = *format++) && (written < maxbytes)) while((ch = *format++) && (written < maxbytes)) {
{ if(ch == '%') {
if(ch == '%')
{
/* /*
* Advance past the % * Advance past the %
*/ */
@ -291,12 +289,10 @@ rs_vsnprintf(char *dest, const size_t bytes, const char *format, va_list args)
* Put the most common cases first - %s %d etc * Put the most common cases first - %s %d etc
*/ */
if(ch == 's') if(ch == 's') {
{
const char *str = va_arg(args, const char *); const char *str = va_arg(args, const char *);
while((*dest = *str)) while((*dest = *str)) {
{
++dest; ++dest;
++str; ++str;
@ -307,8 +303,7 @@ rs_vsnprintf(char *dest, const size_t bytes, const char *format, va_list args)
continue; continue;
} }
if(ch == 'd') if(ch == 'd') {
{
int num = va_arg(args, int); int num = va_arg(args, int);
int quotient; int quotient;
const char *str; const char *str;
@ -317,15 +312,13 @@ rs_vsnprintf(char *dest, const size_t bytes, const char *format, va_list args)
/* /*
* We have to special-case "0" unfortunately * We have to special-case "0" unfortunately
*/ */
if(num == 0) if(num == 0) {
{
*dest++ = '0'; *dest++ = '0';
++written; ++written;
continue; continue;
} }
if(num < 0) if(num < 0) {
{
*dest++ = '-'; *dest++ = '-';
if(++written >= maxbytes) if(++written >= maxbytes)
continue; continue;
@ -333,8 +326,7 @@ rs_vsnprintf(char *dest, const size_t bytes, const char *format, va_list args)
num = -num; num = -num;
} }
do do {
{
quotient = num / TABLE_MAX; quotient = num / TABLE_MAX;
/* /*
@ -369,13 +361,11 @@ rs_vsnprintf(char *dest, const size_t bytes, const char *format, va_list args)
str = IntTable[num - (quotient * TABLE_MAX)]; str = IntTable[num - (quotient * TABLE_MAX)];
while((*digitptr = *str)) while((*digitptr = *str)) {
{
++digitptr; ++digitptr;
++str; ++str;
} }
} } while((num = quotient) != 0);
while((num = quotient) != 0);
/* /*
* If the last quotient was a 1 or 2 digit number, there * If the last quotient was a 1 or 2 digit number, there
@ -385,8 +375,7 @@ rs_vsnprintf(char *dest, const size_t bytes, const char *format, va_list args)
while(*(digitptr - 1) == '0') while(*(digitptr - 1) == '0')
--digitptr; --digitptr;
while(digitptr != TempBuffer) while(digitptr != TempBuffer) {
{
*dest++ = *--digitptr; *dest++ = *--digitptr;
if(++written >= maxbytes) if(++written >= maxbytes)
break; break;
@ -395,8 +384,7 @@ rs_vsnprintf(char *dest, const size_t bytes, const char *format, va_list args)
continue; continue;
} /* if (ch == 'd') */ } /* if (ch == 'd') */
if(ch == 'c') if(ch == 'c') {
{
*dest++ = va_arg(args, int); *dest++ = va_arg(args, int);
++written; ++written;
@ -404,22 +392,19 @@ rs_vsnprintf(char *dest, const size_t bytes, const char *format, va_list args)
continue; continue;
} /* if (ch == 'c') */ } /* if (ch == 'c') */
if(ch == 'u') if(ch == 'u') {
{
unsigned int num = va_arg(args, unsigned int); unsigned int num = va_arg(args, unsigned int);
unsigned int quotient; unsigned int quotient;
const char *str; const char *str;
char *digitptr = TempBuffer; char *digitptr = TempBuffer;
if(num == 0) if(num == 0) {
{
*dest++ = '0'; *dest++ = '0';
++written; ++written;
continue; continue;
} }
do do {
{
quotient = num / TABLE_MAX; quotient = num / TABLE_MAX;
/* /*
@ -428,19 +413,16 @@ rs_vsnprintf(char *dest, const size_t bytes, const char *format, va_list args)
str = IntTable[num - (quotient * TABLE_MAX)]; str = IntTable[num - (quotient * TABLE_MAX)];
while((*digitptr = *str)) while((*digitptr = *str)) {
{
++digitptr; ++digitptr;
++str; ++str;
} }
} } while((num = quotient) != 0);
while((num = quotient) != 0);
while(*(digitptr - 1) == '0') while(*(digitptr - 1) == '0')
--digitptr; --digitptr;
while(digitptr != TempBuffer) while(digitptr != TempBuffer) {
{
*dest++ = *--digitptr; *dest++ = *--digitptr;
if(++written >= maxbytes) if(++written >= maxbytes)
break; break;
@ -449,8 +431,7 @@ rs_vsnprintf(char *dest, const size_t bytes, const char *format, va_list args)
continue; continue;
} /* if (ch == 'u') */ } /* if (ch == 'u') */
if(ch == 'Q') if(ch == 'Q') {
{
const char *arg = va_arg(args, const char *); const char *arg = va_arg(args, const char *);
if(arg == NULL) if(arg == NULL)
@ -458,8 +439,7 @@ rs_vsnprintf(char *dest, const size_t bytes, const char *format, va_list args)
const char *str = rsdb_quote(arg); const char *str = rsdb_quote(arg);
while((*dest = *str)) while((*dest = *str)) {
{
++dest; ++dest;
++str; ++str;
@ -470,10 +450,8 @@ rs_vsnprintf(char *dest, const size_t bytes, const char *format, va_list args)
continue; continue;
} }
if(ch == 'l') if(ch == 'l') {
{ if(*format == 'u') {
if(*format == 'u')
{
unsigned long num = va_arg(args, unsigned long); unsigned long num = va_arg(args, unsigned long);
unsigned long quotient; unsigned long quotient;
const char *str; const char *str;
@ -481,15 +459,13 @@ rs_vsnprintf(char *dest, const size_t bytes, const char *format, va_list args)
++format; ++format;
if(num == 0) if(num == 0) {
{
*dest++ = '0'; *dest++ = '0';
++written; ++written;
continue; continue;
} }
do do {
{
quotient = num / TABLE_MAX; quotient = num / TABLE_MAX;
/* /*
@ -498,29 +474,24 @@ rs_vsnprintf(char *dest, const size_t bytes, const char *format, va_list args)
str = IntTable[num - (quotient * TABLE_MAX)]; str = IntTable[num - (quotient * TABLE_MAX)];
while((*digitptr = *str)) while((*digitptr = *str)) {
{
++digitptr; ++digitptr;
++str; ++str;
} }
} } while((num = quotient) != 0);
while((num = quotient) != 0);
while(*(digitptr - 1) == '0') while(*(digitptr - 1) == '0')
--digitptr; --digitptr;
while(digitptr != TempBuffer) while(digitptr != TempBuffer) {
{
*dest++ = *--digitptr; *dest++ = *--digitptr;
if(++written >= maxbytes) if(++written >= maxbytes)
break; break;
} }
continue; continue;
} } else
else /* if (*format == 'u') */ if(*format == 'd') {
/* if (*format == 'u') */ if(*format == 'd')
{
long num = va_arg(args, long); long num = va_arg(args, long);
long quotient; long quotient;
const char *str; const char *str;
@ -528,15 +499,13 @@ rs_vsnprintf(char *dest, const size_t bytes, const char *format, va_list args)
++format; ++format;
if(num == 0) if(num == 0) {
{
*dest++ = '0'; *dest++ = '0';
++written; ++written;
continue; continue;
} }
if(num < 0) if(num < 0) {
{
*dest++ = '-'; *dest++ = '-';
if(++written >= maxbytes) if(++written >= maxbytes)
continue; continue;
@ -544,34 +513,28 @@ rs_vsnprintf(char *dest, const size_t bytes, const char *format, va_list args)
num = -num; num = -num;
} }
do do {
{
quotient = num / TABLE_MAX; quotient = num / TABLE_MAX;
str = IntTable[num - (quotient * TABLE_MAX)]; str = IntTable[num - (quotient * TABLE_MAX)];
while((*digitptr = *str)) while((*digitptr = *str)) {
{
++digitptr; ++digitptr;
++str; ++str;
} }
} } while((num = quotient) != 0);
while((num = quotient) != 0);
while(*(digitptr - 1) == '0') while(*(digitptr - 1) == '0')
--digitptr; --digitptr;
while(digitptr != TempBuffer) while(digitptr != TempBuffer) {
{
*dest++ = *--digitptr; *dest++ = *--digitptr;
if(++written >= maxbytes) if(++written >= maxbytes)
break; break;
} }
continue; continue;
} } else { /* if (*format == 'd') */
else /* if (*format == 'd') */
{
/* XXX error */ /* XXX error */
exit(1); exit(1);
} }
@ -579,8 +542,7 @@ rs_vsnprintf(char *dest, const size_t bytes, const char *format, va_list args)
} /* if (ch == 'l') */ } /* if (ch == 'l') */
if(ch != '%') if(ch != '%') {
{
/* XXX error */ /* XXX error */
exit(1); exit(1);
} /* if (ch != '%') */ } /* if (ch != '%') */

View File

@ -41,16 +41,14 @@ rsdb_error_cb *error_cb;
static void static void
mlog(const char *errstr, ...) mlog(const char *errstr, ...)
{ {
if(error_cb != NULL) if(error_cb != NULL) {
{
char buf[256]; char buf[256];
va_list ap; va_list ap;
va_start(ap, errstr); va_start(ap, errstr);
rb_vsnprintf(buf, sizeof(buf), errstr, ap); rb_vsnprintf(buf, sizeof(buf), errstr, ap);
va_end(ap); va_end(ap);
error_cb(buf); error_cb(buf);
} } else
else
exit(1); exit(1);
} }
@ -70,15 +68,13 @@ rsdb_init(rsdb_error_cb * ecb)
else else
rb_strlcpy(dbpath, DBPATH, sizeof(dbpath)); rb_strlcpy(dbpath, DBPATH, sizeof(dbpath));
if(sqlite3_open(dbpath, &rb_bandb) != SQLITE_OK) if(sqlite3_open(dbpath, &rb_bandb) != SQLITE_OK) {
{
rb_snprintf(errbuf, sizeof(errbuf), "Unable to open sqlite database: %s", rb_snprintf(errbuf, sizeof(errbuf), "Unable to open sqlite database: %s",
sqlite3_errmsg(rb_bandb)); sqlite3_errmsg(rb_bandb));
mlog(errbuf); mlog(errbuf);
return -1; return -1;
} }
if(access(dbpath, W_OK)) if(access(dbpath, W_OK)) {
{
rb_snprintf(errbuf, sizeof(errbuf), "Unable to open sqlite database for write: %s", strerror(errno)); rb_snprintf(errbuf, sizeof(errbuf), "Unable to open sqlite database for write: %s", strerror(errno));
mlog(errbuf); mlog(errbuf);
return -1; return -1;
@ -103,8 +99,7 @@ rsdb_quote(const char *src)
if(strlen(src) >= (sizeof(buf) / 2)) if(strlen(src) >= (sizeof(buf) / 2))
return NULL; return NULL;
while(*src) while(*src) {
{
if(*src == '\'') if(*src == '\'')
*p++ = '\''; *p++ = '\'';
@ -136,18 +131,14 @@ rsdb_exec(rsdb_callback cb, const char *format, ...)
i = rs_vsnprintf(buf, sizeof(buf), format, args); i = rs_vsnprintf(buf, sizeof(buf), format, args);
va_end(args); va_end(args);
if(i >= sizeof(buf)) if(i >= sizeof(buf)) {
{
mlog("fatal error: length problem with compiling sql"); mlog("fatal error: length problem with compiling sql");
} }
if((i = sqlite3_exec(rb_bandb, buf, (cb ? rsdb_callback_func : NULL), (void *)((uintptr_t)cb), &errmsg))) if((i = sqlite3_exec(rb_bandb, buf, (cb ? rsdb_callback_func : NULL), (void *)((uintptr_t)cb), &errmsg))) {
{ switch (i) {
switch (i)
{
case SQLITE_BUSY: case SQLITE_BUSY:
for(j = 0; j < 5; j++) for(j = 0; j < 5; j++) {
{
rb_sleep(0, 500000); rb_sleep(0, 500000);
if(!sqlite3_exec if(!sqlite3_exec
(rb_bandb, buf, (cb ? rsdb_callback_func : NULL), (void *)((uintptr_t)cb), &errmsg)) (rb_bandb, buf, (cb ? rsdb_callback_func : NULL), (void *)((uintptr_t)cb), &errmsg))
@ -180,26 +171,21 @@ rsdb_exec_fetch(struct rsdb_table *table, const char *format, ...)
retval = rs_vsnprintf(buf, sizeof(buf), format, args); retval = rs_vsnprintf(buf, sizeof(buf), format, args);
va_end(args); va_end(args);
if(retval >= sizeof(buf)) if(retval >= sizeof(buf)) {
{
mlog("fatal error: length problem with compiling sql"); mlog("fatal error: length problem with compiling sql");
} }
if((retval = if((retval =
sqlite3_get_table(rb_bandb, buf, &data, &table->row_count, &table->col_count, &errmsg))) sqlite3_get_table(rb_bandb, buf, &data, &table->row_count, &table->col_count, &errmsg))) {
{
int success = 0; int success = 0;
switch (retval) switch (retval) {
{
case SQLITE_BUSY: case SQLITE_BUSY:
for(i = 0; i < 5; i++) for(i = 0; i < 5; i++) {
{
rb_sleep(0, 500000); rb_sleep(0, 500000);
if(!sqlite3_get_table if(!sqlite3_get_table
(rb_bandb, buf, &data, &table->row_count, &table->col_count, (rb_bandb, buf, &data, &table->row_count, &table->col_count,
&errmsg)) &errmsg)) {
{
success++; success++;
break; break;
} }
@ -220,8 +206,7 @@ rsdb_exec_fetch(struct rsdb_table *table, const char *format, ...)
/* we need to be able to free data afterward */ /* we need to be able to free data afterward */
table->arg = data; table->arg = data;
if(table->row_count == 0) if(table->row_count == 0) {
{
table->row = NULL; table->row = NULL;
return; return;
} }
@ -229,12 +214,10 @@ rsdb_exec_fetch(struct rsdb_table *table, const char *format, ...)
/* sqlite puts the column names as the first row */ /* sqlite puts the column names as the first row */
pos = table->col_count; pos = table->col_count;
table->row = rb_malloc(sizeof(char **) * table->row_count); table->row = rb_malloc(sizeof(char **) * table->row_count);
for(i = 0; i < table->row_count; i++) for(i = 0; i < table->row_count; i++) {
{
table->row[i] = rb_malloc(sizeof(char *) * table->col_count); table->row[i] = rb_malloc(sizeof(char *) * table->col_count);
for(j = 0; j < table->col_count; j++) for(j = 0; j < table->col_count; j++) {
{
table->row[i][j] = data[pos++]; table->row[i][j] = data[pos++];
} }
} }
@ -245,8 +228,7 @@ rsdb_exec_fetch_end(struct rsdb_table *table)
{ {
int i; int i;
for(i = 0; i < table->row_count; i++) for(i = 0; i < table->row_count; i++) {
{
rb_free(table->row[i]); rb_free(table->row[i]);
} }
rb_free(table->row); rb_free(table->row);

View File

@ -31,8 +31,7 @@ h_can_create_channel_authenticated(hook_data_client_approval *data)
{ {
struct Client *source_p = data->client; struct Client *source_p = data->client;
if (!IsOper(source_p)) if (!IsOper(source_p)) {
{
sendto_one_notice(source_p, ":*** Channel creation is restricted to network staff only."); sendto_one_notice(source_p, ":*** Channel creation is restricted to network staff only.");
data->approved = ERR_NEEDREGGEDNICK; data->approved = ERR_NEEDREGGEDNICK;
} }

View File

@ -159,12 +159,9 @@ DECLARE_MODULE_AV1(
static int static int
munreg_test(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) munreg_test(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
{ {
if(parc < 2) if(parc < 2) {
{
sendto_one_notice(source_p, ":You are unregistered and sent no parameters"); sendto_one_notice(source_p, ":You are unregistered and sent no parameters");
} } else {
else
{
sendto_one_notice(source_p, ":You are unregistered and sent parameter: %s", parv[1]); sendto_one_notice(source_p, ":You are unregistered and sent parameter: %s", parv[1]);
} }
@ -181,12 +178,9 @@ munreg_test(struct Client *client_p, struct Client *source_p, int parc, const ch
static int static int
mclient_test(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) mclient_test(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
{ {
if(parc < 2) if(parc < 2) {
{
sendto_one_notice(source_p, ":You are a normal user, and sent no parameters"); sendto_one_notice(source_p, ":You are a normal user, and sent no parameters");
} } else {
else
{
sendto_one_notice(source_p, ":You are a normal user, and send parameters: %s", parv[1]); sendto_one_notice(source_p, ":You are a normal user, and send parameters: %s", parv[1]);
} }
@ -203,12 +197,9 @@ mclient_test(struct Client *client_p, struct Client *source_p, int parc, const c
static int static int
mrclient_test(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) mrclient_test(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
{ {
if(parc < 2) if(parc < 2) {
{
sendto_one_notice(source_p, ":You are a remote client, and sent no parameters"); sendto_one_notice(source_p, ":You are a remote client, and sent no parameters");
} } else {
else
{
sendto_one_notice(source_p, ":You are a remote client, and sent parameters: %s", parv[1]); sendto_one_notice(source_p, ":You are a remote client, and sent parameters: %s", parv[1]);
} }
return 0; return 0;
@ -221,12 +212,9 @@ mrclient_test(struct Client *client_p, struct Client *source_p, int parc, const
static int static int
mserver_test(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) mserver_test(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
{ {
if(parc < 2) if(parc < 2) {
{
sendto_one_notice(source_p, ":You are a server, and sent no parameters"); sendto_one_notice(source_p, ":You are a server, and sent no parameters");
} } else {
else
{
sendto_one_notice(source_p, ":You are a server, and sent parameters: %s", parv[1]); sendto_one_notice(source_p, ":You are a server, and sent parameters: %s", parv[1]);
} }
return 0; return 0;
@ -239,12 +227,9 @@ mserver_test(struct Client *client_p, struct Client *source_p, int parc, const c
static int static int
moper_test(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) moper_test(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
{ {
if(parc < 2) if(parc < 2) {
{
sendto_one_notice(source_p, ":You are an operator, and sent no parameters"); sendto_one_notice(source_p, ":You are an operator, and sent no parameters");
} } else {
else
{
sendto_one_notice(source_p, ":You are an operator, and sent parameters: %s", parv[1]); sendto_one_notice(source_p, ":You are an operator, and sent parameters: %s", parv[1]);
} }
return 0; return 0;

View File

@ -46,8 +46,7 @@ static int eb_extended(const char *data, struct Client *client_p,
ret = match(data, buf) ? EXTBAN_MATCH : EXTBAN_NOMATCH; ret = match(data, buf) ? EXTBAN_MATCH : EXTBAN_NOMATCH;
if (ret == EXTBAN_NOMATCH && IsDynSpoof(client_p)) if (ret == EXTBAN_NOMATCH && IsDynSpoof(client_p)) {
{
rb_snprintf(buf, BUFSIZE, "%s!%s@%s#%s", rb_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);

View File

@ -156,8 +156,7 @@ modfini(void)
rb_event_delete(hurt_expire_ev); rb_event_delete(hurt_expire_ev);
rb_event_delete(hurt_check_ev); rb_event_delete(hurt_check_ev);
RB_DLINK_FOREACH_SAFE (ptr, next_ptr, hurt_state.hurt_clients.head) RB_DLINK_FOREACH_SAFE (ptr, next_ptr, hurt_state.hurt_clients.head) {
{
rb_dlinkDestroy(ptr, &hurt_state.hurt_clients); rb_dlinkDestroy(ptr, &hurt_state.hurt_clients);
} }
} }
@ -207,23 +206,18 @@ mo_hurt(struct Client *client_p, struct Client *source_p,
} }
/* Is this a client? */ /* Is this a client? */
if (strchr(ip, '.') == NULL && strchr(ip, ':') == NULL) if (strchr(ip, '.') == NULL && strchr(ip, ':') == NULL) {
{
target_p = find_named_person(ip); target_p = find_named_person(ip);
if (target_p == NULL) if (target_p == NULL) {
{
sendto_one_numeric(source_p, ERR_NOSUCHNICK, sendto_one_numeric(source_p, ERR_NOSUCHNICK,
form_str(ERR_NOSUCHNICK), ip); form_str(ERR_NOSUCHNICK), ip);
return 0; return 0;
} }
ip = target_p->orighost; ip = target_p->orighost;
} } else {
else
{
if (!strncmp(ip, "*@", 2)) if (!strncmp(ip, "*@", 2))
ip += 2; ip += 2;
if (strchr(ip, '!') || strchr(ip, '@')) if (strchr(ip, '!') || strchr(ip, '@')) {
{
sendto_one_notice(source_p, ":Invalid HURT mask [%s]", sendto_one_notice(source_p, ":Invalid HURT mask [%s]",
ip); ip);
return 0; return 0;
@ -302,18 +296,15 @@ mo_heal(struct Client *client_p, struct Client *source_p,
{ {
struct Client *target_p; struct Client *target_p;
if (!IsOperUnkline(source_p)) if (!IsOperUnkline(source_p)) {
{
sendto_one(source_p, form_str(ERR_NOPRIVS), sendto_one(source_p, form_str(ERR_NOPRIVS),
me.name, source_p->name, "unkline"); me.name, source_p->name, "unkline");
return 0; return 0;
} }
if (nick_is_valid(parv[1])) if (nick_is_valid(parv[1])) {
{
target_p = find_named_person(parv[1]); target_p = find_named_person(parv[1]);
if (target_p == NULL) if (target_p == NULL) {
{
sendto_one_numeric(source_p, ERR_NOSUCHNICK, sendto_one_numeric(source_p, ERR_NOSUCHNICK,
form_str(ERR_NOSUCHNICK), parv[1]); form_str(ERR_NOSUCHNICK), parv[1]);
return 0; return 0;
@ -325,11 +316,8 @@ mo_heal(struct Client *client_p, struct Client *source_p,
get_id(source_p, target_p), get_id(source_p, target_p),
target_p->servptr->name, target_p->servptr->name,
get_id(target_p, target_p)); get_id(target_p, target_p));
} } else if (strchr(parv[1], '.')) {
else if (strchr(parv[1], '.')) if (hurt_find_exact(parv[1]) == NULL) {
{
if (hurt_find_exact(parv[1]) == NULL)
{
sendto_one_notice(source_p, ":Mask [%s] is not HURT", parv[1]); sendto_one_notice(source_p, ":Mask [%s] is not HURT", parv[1]);
return 0; return 0;
} }
@ -338,9 +326,7 @@ mo_heal(struct Client *client_p, struct Client *source_p,
get_oper_name(source_p), parv[1]); get_oper_name(source_p), parv[1]);
sendto_server(NULL, NULL, NOCAPS, NOCAPS, ":%s ENCAP * HEAL %s", sendto_server(NULL, NULL, NOCAPS, NOCAPS, ":%s ENCAP * HEAL %s",
source_p->name, parv[1]); source_p->name, parv[1]);
} } else {
else
{
sendto_one(source_p, ":[%s] is not a valid IP address/nick", parv[1]); sendto_one(source_p, ":[%s] is not a valid IP address/nick", parv[1]);
return 0; return 0;
} }
@ -361,22 +347,18 @@ me_heal(struct Client *client_p, struct Client *source_p,
if (parc < 2) if (parc < 2)
return 0; return 0;
if (nick_is_valid(parv[1])) if (nick_is_valid(parv[1])) {
{
target_p = find_person(parv[1]); target_p = find_person(parv[1]);
if (target_p != NULL && MyConnect(target_p)) if (target_p != NULL && MyConnect(target_p))
heal_nick(source_p, target_p); heal_nick(source_p, target_p);
} } else if (strchr(parv[1], '.')) { /* host or mask to remove ban for */
else if (strchr(parv[1], '.')) /* host or mask to remove ban for */
{
if (hurt_find_exact(parv[1]) == NULL) if (hurt_find_exact(parv[1]) == NULL)
return 0; return 0;
hurt_remove(parv[1]); hurt_remove(parv[1]);
sendto_realops_snomask(SNO_GENERAL, L_ALL, "%s removed HURT on %s", sendto_realops_snomask(SNO_GENERAL, L_ALL, "%s removed HURT on %s",
get_oper_name(source_p), parv[1]); get_oper_name(source_p), parv[1]);
} } else
else
return 0; return 0;
return 0; return 0;
@ -395,13 +377,11 @@ hurt_check_event(void *arg)
RB_DLINK_FOREACH_SAFE (ptr, next_ptr, hurt_state.hurt_clients.head) { RB_DLINK_FOREACH_SAFE (ptr, next_ptr, hurt_state.hurt_clients.head) {
client_p = ptr->data; client_p = ptr->data;
if (!EmptyString(client_p->user->suser)) if (!EmptyString(client_p->user->suser)) {
{
rb_dlinkDestroy(ptr, &hurt_state.hurt_clients); rb_dlinkDestroy(ptr, &hurt_state.hurt_clients);
sendto_one_notice(client_p, ":HURT restriction removed for this session"); sendto_one_notice(client_p, ":HURT restriction removed for this session");
client_p->localClient->target_last = rb_current_time(); /* don't ask --nenolod */ client_p->localClient->target_last = rb_current_time(); /* don't ask --nenolod */
} } else if (client_p->localClient->receiveM > hurt_state.cutoff)
else if (client_p->localClient->receiveM > hurt_state.cutoff)
exit_client(NULL, client_p, &me, hurt_state.exit_reason); exit_client(NULL, client_p, &me, hurt_state.exit_reason);
} }
} }
@ -414,12 +394,10 @@ hurt_expire_event(void *unused)
rb_dlink_node *ptr, *next_ptr; rb_dlink_node *ptr, *next_ptr;
hurt_t *hurt; hurt_t *hurt;
RB_DLINK_FOREACH_SAFE (ptr, next_ptr, hurt_confs.head) RB_DLINK_FOREACH_SAFE (ptr, next_ptr, hurt_confs.head) {
{
hurt = (hurt_t *) ptr->data; hurt = (hurt_t *) ptr->data;
if (hurt->expire <= rb_current_time()) if (hurt->expire <= rb_current_time()) {
{
rb_dlinkFindDestroy(hurt, &hurt_confs); rb_dlinkFindDestroy(hurt, &hurt_confs);
hurt_destroy(hurt); hurt_destroy(hurt);
} }
@ -450,8 +428,7 @@ new_local_user_hook(struct Client *source_p)
IsExemptKline(source_p)) IsExemptKline(source_p))
return; return;
if (hurt_find(source_p->sockhost) || hurt_find(source_p->orighost)) if (hurt_find(source_p->sockhost) || hurt_find(source_p->orighost)) {
{
source_p->localClient->target_last = rb_current_time() + 600; /* don't ask --nenolod */ source_p->localClient->target_last = rb_current_time() + 600; /* don't ask --nenolod */
SetTGChange(source_p); SetTGChange(source_p);
rb_dlinkAddAlloc(source_p, &hurt_state.hurt_clients); rb_dlinkAddAlloc(source_p, &hurt_state.hurt_clients);
@ -476,11 +453,9 @@ doing_stats_hook(hook_data_int *hdata)
return; return;
if((ConfigFileEntry.stats_k_oper_only == 2) && !IsOper(source_p)) if((ConfigFileEntry.stats_k_oper_only == 2) && !IsOper(source_p))
return; return;
if ((ConfigFileEntry.stats_k_oper_only == 1) && !IsOper(source_p)) if ((ConfigFileEntry.stats_k_oper_only == 1) && !IsOper(source_p)) {
{
hurt = hurt_find(source_p->sockhost); hurt = hurt_find(source_p->sockhost);
if (hurt != NULL) if (hurt != NULL) {
{
sendto_one_numeric(source_p, RPL_STATSKLINE, sendto_one_numeric(source_p, RPL_STATSKLINE,
form_str(RPL_STATSKLINE), 's', form_str(RPL_STATSKLINE), 's',
"*", hurt->ip, hurt->reason, "", ""); "*", hurt->ip, hurt->reason, "", "");
@ -488,8 +463,7 @@ doing_stats_hook(hook_data_int *hdata)
} }
hurt = hurt_find(source_p->orighost); hurt = hurt_find(source_p->orighost);
if (hurt != NULL) if (hurt != NULL) {
{
sendto_one_numeric(source_p, RPL_STATSKLINE, sendto_one_numeric(source_p, RPL_STATSKLINE,
form_str(RPL_STATSKLINE), 's', form_str(RPL_STATSKLINE), 's',
"*", hurt->ip, hurt->reason, "", ""); "*", hurt->ip, hurt->reason, "", "");
@ -498,8 +472,7 @@ doing_stats_hook(hook_data_int *hdata)
return; return;
} }
RB_DLINK_FOREACH(ptr, hurt_confs.head) RB_DLINK_FOREACH(ptr, hurt_confs.head) {
{
hurt = (hurt_t *) ptr->data; hurt = (hurt_t *) ptr->data;
sendto_one_numeric(source_p, RPL_STATSKLINE, sendto_one_numeric(source_p, RPL_STATSKLINE,
form_str(RPL_STATSKLINE), 's', form_str(RPL_STATSKLINE), 's',
@ -577,8 +550,7 @@ hurt_find_exact(const char *ip)
rb_dlink_node *ptr; rb_dlink_node *ptr;
hurt_t *hurt; hurt_t *hurt;
RB_DLINK_FOREACH(ptr, hurt_confs.head) RB_DLINK_FOREACH(ptr, hurt_confs.head) {
{
hurt = (hurt_t *) ptr->data; hurt = (hurt_t *) ptr->data;
if (!strcasecmp(ip, hurt->ip)) if (!strcasecmp(ip, hurt->ip))
@ -594,8 +566,7 @@ hurt_find(const char *ip)
rb_dlink_node *ptr; rb_dlink_node *ptr;
hurt_t *hurt; hurt_t *hurt;
RB_DLINK_FOREACH(ptr, hurt_confs.head) RB_DLINK_FOREACH(ptr, hurt_confs.head) {
{
hurt = (hurt_t *) ptr->data; hurt = (hurt_t *) ptr->data;
if (match(hurt->ip, ip)) if (match(hurt->ip, ip))
@ -618,17 +589,14 @@ hurt_remove(const char *ip)
static int static int
heal_nick(struct Client *source_p, struct Client *target_p) heal_nick(struct Client *source_p, struct Client *target_p)
{ {
if (rb_dlinkFindDestroy(target_p, &hurt_state.hurt_clients)) if (rb_dlinkFindDestroy(target_p, &hurt_state.hurt_clients)) {
{
sendto_realops_snomask(SNO_GENERAL, L_ALL, "%s used HEAL on %s", sendto_realops_snomask(SNO_GENERAL, L_ALL, "%s used HEAL on %s",
get_oper_name(source_p), get_client_name(target_p, HIDE_IP)); get_oper_name(source_p), get_client_name(target_p, HIDE_IP));
sendto_one_notice(target_p, ":HURT restriction temporarily removed by operator"); sendto_one_notice(target_p, ":HURT restriction temporarily removed by operator");
sendto_one_notice(source_p, ":HURT restriction on %s temporarily removed", target_p->name); sendto_one_notice(source_p, ":HURT restriction on %s temporarily removed", target_p->name);
target_p->localClient->target_last = rb_current_time(); /* don't ask --nenolod */ target_p->localClient->target_last = rb_current_time(); /* don't ask --nenolod */
return 1; return 1;
} } else {
else
{
sendto_one_notice(source_p, ":%s was not hurt", target_p->name); sendto_one_notice(source_p, ":%s was not hurt", target_p->name);
return 0; return 0;
} }

View File

@ -121,26 +121,19 @@ check_umode_change(void *vdata)
if (!((data->oldumodes ^ source_p->umodes) & user_modes['x'])) if (!((data->oldumodes ^ source_p->umodes) & user_modes['x']))
return; return;
if (source_p->umodes & user_modes['h']) if (source_p->umodes & user_modes['h']) {
{ if (IsIPSpoof(source_p) || source_p->localClient->mangledhost == NULL || (IsDynSpoof(source_p) && strcmp(source_p->host, source_p->localClient->mangledhost))) {
if (IsIPSpoof(source_p) || source_p->localClient->mangledhost == NULL || (IsDynSpoof(source_p) && strcmp(source_p->host, source_p->localClient->mangledhost)))
{
source_p->umodes &= ~user_modes['x']; source_p->umodes &= ~user_modes['x'];
return; return;
} }
if (strcmp(source_p->host, source_p->localClient->mangledhost)) if (strcmp(source_p->host, source_p->localClient->mangledhost)) {
{
distribute_hostchange(source_p, source_p->localClient->mangledhost); distribute_hostchange(source_p, source_p->localClient->mangledhost);
} } else /* not really nice, but we need to send this numeric here */
else /* not really nice, but we need to send this numeric here */
sendto_one_numeric(source_p, RPL_HOSTHIDDEN, "%s :is now your hidden host", sendto_one_numeric(source_p, RPL_HOSTHIDDEN, "%s :is now your hidden host",
source_p->host); source_p->host);
} } else if (!(source_p->umodes & user_modes['x'])) {
else if (!(source_p->umodes & user_modes['x']))
{
if (source_p->localClient->mangledhost != NULL && if (source_p->localClient->mangledhost != NULL &&
!strcmp(source_p->host, source_p->localClient->mangledhost)) !strcmp(source_p->host, source_p->localClient->mangledhost)) {
{
distribute_hostchange(source_p, source_p->orighost); distribute_hostchange(source_p, source_p->orighost);
} }
} }
@ -151,8 +144,7 @@ check_new_user(void *vdata)
{ {
struct Client *source_p = (void *)vdata; struct Client *source_p = (void *)vdata;
if (IsIPSpoof(source_p)) if (IsIPSpoof(source_p)) {
{
source_p->umodes &= ~user_modes['x']; source_p->umodes &= ~user_modes['x'];
return; return;
} }
@ -160,8 +152,7 @@ check_new_user(void *vdata)
do_host_cloak(source_p->orighost, source_p->localClient->mangledhost); do_host_cloak(source_p->orighost, source_p->localClient->mangledhost);
if (IsDynSpoof(source_p)) if (IsDynSpoof(source_p))
source_p->umodes &= ~user_modes['x']; source_p->umodes &= ~user_modes['x'];
if (source_p->umodes & user_modes['x']) if (source_p->umodes & user_modes['x']) {
{
rb_strlcpy(source_p->host, source_p->localClient->mangledhost, sizeof(source_p->host)); rb_strlcpy(source_p->host, source_p->localClient->mangledhost, sizeof(source_p->host));
if (irccmp(source_p->host, source_p->orighost)) if (irccmp(source_p->host, source_p->orighost))
SetDynSpoof(source_p); SetDynSpoof(source_p);

View File

@ -84,8 +84,7 @@ do_host_cloak_ip(const char *inbuf, char *outbuf)
rb_strlcpy(outbuf, inbuf, HOSTLEN + 1); rb_strlcpy(outbuf, inbuf, HOSTLEN + 1);
if (strchr(outbuf, ':')) if (strchr(outbuf, ':')) {
{
ipv6 = 1; ipv6 = 1;
/* Damn you IPv6... /* Damn you IPv6...
@ -99,14 +98,11 @@ do_host_cloak_ip(const char *inbuf, char *outbuf)
for (tptr = outbuf; *tptr != '\0'; tptr++) for (tptr = outbuf; *tptr != '\0'; tptr++)
if (*tptr == ':') if (*tptr == ':')
totalcount++; totalcount++;
} } else if (!strchr(outbuf, '.'))
else if (!strchr(outbuf, '.'))
return; return;
for (tptr = outbuf; *tptr != '\0'; tptr++) for (tptr = outbuf; *tptr != '\0'; tptr++) {
{ if (*tptr == ':' || *tptr == '.') {
if (*tptr == ':' || *tptr == '.')
{
sepcount++; sepcount++;
continue; continue;
} }
@ -136,8 +132,7 @@ do_host_cloak_host(const char *inbuf, char *outbuf)
* *
* numbers are not changed at this time, only letters. * numbers are not changed at this time, only letters.
*/ */
for (tptr = outbuf; *tptr != '\0'; tptr++) for (tptr = outbuf; *tptr != '\0'; tptr++) {
{
if (*tptr == '.') if (*tptr == '.')
break; break;
@ -151,8 +146,7 @@ do_host_cloak_host(const char *inbuf, char *outbuf)
} }
/* pass 2: scramble each number in the address */ /* pass 2: scramble each number in the address */
for (tptr = outbuf; *tptr != '\0'; tptr++) for (tptr = outbuf; *tptr != '\0'; tptr++) {
{
if (isdigit(*tptr)) if (isdigit(*tptr))
*tptr = '0' + (*tptr + accum) % 10; *tptr = '0' + (*tptr + accum) % 10;
@ -173,26 +167,19 @@ check_umode_change(void *vdata)
if (!((data->oldumodes ^ source_p->umodes) & user_modes['x'])) if (!((data->oldumodes ^ source_p->umodes) & user_modes['x']))
return; return;
if (source_p->umodes & user_modes['x']) if (source_p->umodes & user_modes['x']) {
{ if (IsIPSpoof(source_p) || source_p->localClient->mangledhost == NULL || (IsDynSpoof(source_p) && strcmp(source_p->host, source_p->localClient->mangledhost))) {
if (IsIPSpoof(source_p) || source_p->localClient->mangledhost == NULL || (IsDynSpoof(source_p) && strcmp(source_p->host, source_p->localClient->mangledhost)))
{
source_p->umodes &= ~user_modes['x']; source_p->umodes &= ~user_modes['x'];
return; return;
} }
if (strcmp(source_p->host, source_p->localClient->mangledhost)) if (strcmp(source_p->host, source_p->localClient->mangledhost)) {
{
distribute_hostchange(source_p, source_p->localClient->mangledhost); distribute_hostchange(source_p, source_p->localClient->mangledhost);
} } else /* not really nice, but we need to send this numeric here */
else /* not really nice, but we need to send this numeric here */
sendto_one_numeric(source_p, RPL_HOSTHIDDEN, "%s :is now your hidden host", sendto_one_numeric(source_p, RPL_HOSTHIDDEN, "%s :is now your hidden host",
source_p->host); source_p->host);
} } else if (!(source_p->umodes & user_modes['x'])) {
else if (!(source_p->umodes & user_modes['x']))
{
if (source_p->localClient->mangledhost != NULL && if (source_p->localClient->mangledhost != NULL &&
!strcmp(source_p->host, source_p->localClient->mangledhost)) !strcmp(source_p->host, source_p->localClient->mangledhost)) {
{
distribute_hostchange(source_p, source_p->orighost); distribute_hostchange(source_p, source_p->orighost);
} }
} }
@ -203,8 +190,7 @@ check_new_user(void *vdata)
{ {
struct Client *source_p = (void *)vdata; struct Client *source_p = (void *)vdata;
if (IsIPSpoof(source_p)) if (IsIPSpoof(source_p)) {
{
source_p->umodes &= ~user_modes['x']; source_p->umodes &= ~user_modes['x'];
return; return;
} }
@ -215,8 +201,7 @@ check_new_user(void *vdata)
do_host_cloak_host(source_p->orighost, source_p->localClient->mangledhost); do_host_cloak_host(source_p->orighost, source_p->localClient->mangledhost);
if (IsDynSpoof(source_p)) if (IsDynSpoof(source_p))
source_p->umodes &= ~user_modes['x']; source_p->umodes &= ~user_modes['x'];
if (source_p->umodes & user_modes['x']) if (source_p->umodes & user_modes['x']) {
{
rb_strlcpy(source_p->host, source_p->localClient->mangledhost, sizeof(source_p->host)); rb_strlcpy(source_p->host, source_p->localClient->mangledhost, sizeof(source_p->host));
if (irccmp(source_p->host, source_p->orighost)) if (irccmp(source_p->host, source_p->orighost))
SetDynSpoof(source_p); SetDynSpoof(source_p);

View File

@ -14,7 +14,8 @@ static int mclient_42(struct Client *client_p, struct Client *source_p, int parc
struct Message hgtg_msgtab = { struct Message hgtg_msgtab = {
"42", 0, 0, 0, MFLG_SLOW, "42", 0, 0, 0, MFLG_SLOW,
{ mg_ignore, {mclient_42, 0}, mg_ignore, mg_ignore, mg_ignore, {mclient_42, 0} {
mg_ignore, {mclient_42, 0}, mg_ignore, mg_ignore, mg_ignore, {mclient_42, 0}
} }
}; };

View File

@ -58,8 +58,7 @@ DECLARE_MODULE_AV1(adminwall, NULL, NULL, adminwall_clist, NULL, NULL, "$Revisio
static int static int
mo_adminwall(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) mo_adminwall(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
{ {
if(!IsAdmin(source_p)) if(!IsAdmin(source_p)) {
{
sendto_one(source_p, form_str(ERR_NOPRIVS), sendto_one(source_p, form_str(ERR_NOPRIVS),
me.name, source_p->name, "adminwall"); me.name, source_p->name, "adminwall");
return 0; return 0;

View File

@ -46,17 +46,14 @@ m_cycle(struct Client *client_p, struct Client *source_p, int parc, const char *
if(MyClient(source_p) && !IsFloodDone(source_p)) if(MyClient(source_p) && !IsFloodDone(source_p))
flood_endgrace(source_p); flood_endgrace(source_p);
while(name) while(name) {
{ if((chptr = find_channel(name)) == NULL) {
if((chptr = find_channel(name)) == NULL)
{
sendto_one_numeric(source_p, ERR_NOSUCHCHANNEL, form_str(ERR_NOSUCHCHANNEL), name); sendto_one_numeric(source_p, ERR_NOSUCHCHANNEL, form_str(ERR_NOSUCHCHANNEL), name);
return 0; return 0;
} }
msptr = find_channel_membership(chptr, source_p); msptr = find_channel_membership(chptr, source_p);
if(msptr == NULL) if(msptr == NULL) {
{
sendto_one_numeric(source_p, ERR_NOTONCHANNEL, form_str(ERR_NOTONCHANNEL), name); sendto_one_numeric(source_p, ERR_NOTONCHANNEL, form_str(ERR_NOTONCHANNEL), name);
return 0; return 0;
} }
@ -67,16 +64,13 @@ m_cycle(struct Client *client_p, struct Client *source_p, int parc, const char *
if((is_any_op(msptr) || !MyConnect(source_p) || if((is_any_op(msptr) || !MyConnect(source_p) ||
((can_send(chptr, source_p, msptr) > 0 && ((can_send(chptr, source_p, msptr) > 0 &&
(source_p->localClient->firsttime + (source_p->localClient->firsttime +
ConfigFileEntry.anti_spam_exit_message_time) < rb_current_time())))) ConfigFileEntry.anti_spam_exit_message_time) < rb_current_time())))) {
{
sendto_server(client_p, chptr, CAP_TS6, NOCAPS, sendto_server(client_p, chptr, CAP_TS6, NOCAPS,
":%s PART %s :Cycling", use_id(source_p), chptr->chname); ":%s PART %s :Cycling", use_id(source_p), chptr->chname);
sendto_channel_local(ALL_MEMBERS, chptr, ":%s!%s@%s PART %s :Cycling", sendto_channel_local(ALL_MEMBERS, chptr, ":%s!%s@%s PART %s :Cycling",
source_p->name, source_p->username, source_p->name, source_p->username,
source_p->host, chptr->chname); source_p->host, chptr->chname);
} } else {
else
{
sendto_server(client_p, chptr, CAP_TS6, NOCAPS, sendto_server(client_p, chptr, CAP_TS6, NOCAPS,
":%s PART %s", use_id(source_p), chptr->chname); ":%s PART %s", use_id(source_p), chptr->chname);
sendto_channel_local(ALL_MEMBERS, chptr, ":%s!%s@%s PART %s", sendto_channel_local(ALL_MEMBERS, chptr, ":%s!%s@%s PART %s",

View File

@ -62,39 +62,31 @@ m_findforwards(struct Client *client_p, struct Client *source_p, int parc, const
*p = '\0'; *p = '\0';
/* Allow ircops to search for forwards to nonexistent channels */ /* Allow ircops to search for forwards to nonexistent channels */
if(!IsOper(source_p)) if(!IsOper(source_p)) {
{ if((chptr = find_channel(parv[1])) == NULL || (msptr = find_channel_membership(chptr, source_p)) == NULL) {
if((chptr = find_channel(parv[1])) == NULL || (msptr = find_channel_membership(chptr, source_p)) == NULL)
{
sendto_one_numeric(source_p, ERR_NOTONCHANNEL, sendto_one_numeric(source_p, ERR_NOTONCHANNEL,
form_str(ERR_NOTONCHANNEL), parv[1]); form_str(ERR_NOTONCHANNEL), parv[1]);
return 0; return 0;
} }
if(!is_any_op(msptr)) if(!is_any_op(msptr)) {
{
sendto_one(source_p, form_str(ERR_CHANOPRIVSNEEDED), sendto_one(source_p, form_str(ERR_CHANOPRIVSNEEDED),
me.name, source_p->name, parv[1]); me.name, source_p->name, parv[1]);
return 0; return 0;
} }
if((last_used + ConfigFileEntry.pace_wait) > rb_current_time()) if((last_used + ConfigFileEntry.pace_wait) > rb_current_time()) {
{
sendto_one(source_p, form_str(RPL_LOAD2HI), sendto_one(source_p, form_str(RPL_LOAD2HI),
me.name, source_p->name, "FINDFORWARDS"); me.name, source_p->name, "FINDFORWARDS");
return 0; return 0;
} } else
else
last_used = rb_current_time(); last_used = rb_current_time();
} }
RB_DLINK_FOREACH(ptr, global_channel_list.head) RB_DLINK_FOREACH(ptr, global_channel_list.head) {
{
chptr = ptr->data; chptr = ptr->data;
if(chptr->mode.forward && !irccmp(chptr->mode.forward, parv[1])) if(chptr->mode.forward && !irccmp(chptr->mode.forward, parv[1])) {
{ if(p + strlen(chptr->chname) >= end - 13) {
if(p + strlen(chptr->chname) >= end - 13)
{
strcpy(p, "<truncated> "); strcpy(p, "<truncated> ");
p += 12; p += 12;
break; break;

View File

@ -74,8 +74,7 @@ mo_forcejoin(struct Client *client_p, struct Client *source_p, int parc, const c
char sjmode; char sjmode;
char *newch; char *newch;
if(!IsOperAdmin(source_p)) if(!IsOperAdmin(source_p)) {
{
sendto_one(source_p, form_str(ERR_NOPRIVS), me.name, source_p->name, "admin"); sendto_one(source_p, form_str(ERR_NOPRIVS), me.name, source_p->name, "admin");
return 0; return 0;
} }
@ -86,8 +85,7 @@ mo_forcejoin(struct Client *client_p, struct Client *source_p, int parc, const c
/* if target_p is not existant, print message /* if target_p is not existant, print message
* to source_p and bail - scuzzy * to source_p and bail - scuzzy
*/ */
if((target_p = find_client(parv[1])) == NULL) if((target_p = find_client(parv[1])) == NULL) {
{
sendto_one(source_p, form_str(ERR_NOSUCHNICK), me.name, source_p->name, parv[1]); sendto_one(source_p, form_str(ERR_NOSUCHNICK), me.name, source_p->name, parv[1]);
return 0; return 0;
} }
@ -106,20 +104,15 @@ mo_forcejoin(struct Client *client_p, struct Client *source_p, int parc, const c
source_p->name, source_p->username, source_p->host); source_p->name, source_p->username, source_p->host);
/* select our modes from parv[2] if they exist... (chanop) */ /* select our modes from parv[2] if they exist... (chanop) */
if(*parv[2] == '@') if(*parv[2] == '@') {
{
type = CHFL_CHANOP; type = CHFL_CHANOP;
mode = 'o'; mode = 'o';
sjmode = '@'; sjmode = '@';
} } else if(*parv[2] == '+') {
else if(*parv[2] == '+')
{
type = CHFL_VOICE; type = CHFL_VOICE;
mode = 'v'; mode = 'v';
sjmode = '+'; sjmode = '+';
} } else {
else
{
type = CHFL_PEON; type = CHFL_PEON;
mode = sjmode = '\0'; mode = sjmode = '\0';
} }
@ -127,10 +120,8 @@ mo_forcejoin(struct Client *client_p, struct Client *source_p, int parc, const c
if(mode != '\0') if(mode != '\0')
parv[2]++; parv[2]++;
if((chptr = find_channel(parv[2])) != NULL) if((chptr = find_channel(parv[2])) != NULL) {
{ if(IsMember(target_p, chptr)) {
if(IsMember(target_p, chptr))
{
/* debugging is fun... */ /* debugging is fun... */
sendto_one_notice(source_p, ":*** Notice -- %s is already in %s", sendto_one_notice(source_p, ":*** Notice -- %s is already in %s",
target_p->name, chptr->chname); target_p->name, chptr->chname);
@ -152,8 +143,7 @@ mo_forcejoin(struct Client *client_p, struct Client *source_p, int parc, const c
sendto_channel_local(ALL_MEMBERS, chptr, ":%s MODE %s +%c %s", sendto_channel_local(ALL_MEMBERS, chptr, ":%s MODE %s +%c %s",
me.name, chptr->chname, mode, target_p->name); me.name, chptr->chname, mode, target_p->name);
if(chptr->topic != NULL) if(chptr->topic != NULL) {
{
sendto_one(target_p, form_str(RPL_TOPIC), me.name, sendto_one(target_p, form_str(RPL_TOPIC), me.name,
target_p->name, chptr->chname, chptr->topic); target_p->name, chptr->chname, chptr->topic);
sendto_one(target_p, form_str(RPL_TOPICWHOTIME), sendto_one(target_p, form_str(RPL_TOPICWHOTIME),
@ -162,28 +152,23 @@ mo_forcejoin(struct Client *client_p, struct Client *source_p, int parc, const c
} }
channel_member_names(chptr, target_p, 1); channel_member_names(chptr, target_p, 1);
} } else {
else
{
newch = LOCAL_COPY(parv[2]); newch = LOCAL_COPY(parv[2]);
if(!check_channel_name(newch)) if(!check_channel_name(newch)) {
{
sendto_one(source_p, form_str(ERR_BADCHANNAME), me.name, sendto_one(source_p, form_str(ERR_BADCHANNAME), me.name,
source_p->name, (unsigned char *) newch); source_p->name, (unsigned char *) newch);
return 0; return 0;
} }
/* channel name must begin with & or # */ /* channel name must begin with & or # */
if(!IsChannelName(newch)) if(!IsChannelName(newch)) {
{
sendto_one(source_p, form_str(ERR_BADCHANNAME), me.name, sendto_one(source_p, form_str(ERR_BADCHANNAME), me.name,
source_p->name, (unsigned char *) newch); source_p->name, (unsigned char *) newch);
return 0; return 0;
} }
/* newch can't be longer than CHANNELLEN */ /* newch can't be longer than CHANNELLEN */
if(strlen(newch) > CHANNELLEN) if(strlen(newch) > CHANNELLEN) {
{
sendto_one_notice(source_p, ":Channel name is too long"); sendto_one_notice(source_p, ":Channel name is too long");
return 0; return 0;
} }

View File

@ -65,11 +65,11 @@ DECLARE_MODULE_AV1(identify, NULL, NULL, identify_clist, NULL, NULL, "$Revision:
char *reconstruct_parv(int parc, const char *parv[]) char *reconstruct_parv(int parc, const char *parv[])
{ {
static char tmpbuf[BUFSIZE]; int i; static char tmpbuf[BUFSIZE];
int i;
rb_strlcpy(tmpbuf, parv[0], BUFSIZE); rb_strlcpy(tmpbuf, parv[0], BUFSIZE);
for (i = 1; i < parc; i++) for (i = 1; i < parc; i++) {
{
rb_strlcat(tmpbuf, " ", BUFSIZE); rb_strlcat(tmpbuf, " ", BUFSIZE);
rb_strlcat(tmpbuf, parv[i], BUFSIZE); rb_strlcat(tmpbuf, parv[i], BUFSIZE);
} }
@ -81,19 +81,15 @@ static int m_identify(struct Client *client_p, struct Client *source_p, int parc
const char *nick; const char *nick;
struct Client *target_p; struct Client *target_p;
if (parc < 2 || EmptyString(parv[1])) if (parc < 2 || EmptyString(parv[1])) {
{
sendto_one(source_p, form_str(ERR_NOTEXTTOSEND), me.name, source_p->name); sendto_one(source_p, form_str(ERR_NOTEXTTOSEND), me.name, source_p->name);
return 0; return 0;
} }
nick = parv[1][0] == '#' ? SVS_chanserv_NICK : SVS_nickserv_NICK; nick = parv[1][0] == '#' ? SVS_chanserv_NICK : SVS_nickserv_NICK;
if ((target_p = find_named_person(nick)) && IsService(target_p)) if ((target_p = find_named_person(nick)) && IsService(target_p)) {
{
sendto_one(target_p, ":%s PRIVMSG %s :IDENTIFY %s", get_id(source_p, target_p), get_id(target_p, target_p), reconstruct_parv(parc - 1, &parv[1])); sendto_one(target_p, ":%s PRIVMSG %s :IDENTIFY %s", get_id(source_p, target_p), get_id(target_p, target_p), reconstruct_parv(parc - 1, &parv[1]));
} } else {
else
{
sendto_one_numeric(source_p, ERR_SERVICESDOWN, form_str(ERR_SERVICESDOWN), nick); sendto_one_numeric(source_p, ERR_SERVICESDOWN, form_str(ERR_SERVICESDOWN), nick);
} }
return 0; return 0;

View File

@ -26,7 +26,7 @@ static char *generate_random_salt(char *, int);
static char *generate_poor_salt(char *, int); static char *generate_poor_salt(char *, int);
static char saltChars[] = "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; static char saltChars[] = "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
/* 0 .. 63, ascii - 64 */ /* 0 .. 63, ascii - 64 */
struct Message mkpasswd_msgtab = { struct Message mkpasswd_msgtab = {
"MKPASSWD", 0, 0, 0, MFLG_SLOW, "MKPASSWD", 0, 0, 0, MFLG_SLOW,
@ -50,8 +50,7 @@ m_mkpasswd(struct Client *client_p, struct Client *source_p, int parc, const cha
const char *hashtype; const char *hashtype;
const char hashdefault[] = "SHA512"; const char hashdefault[] = "SHA512";
if(EmptyString(parv[1])) if(EmptyString(parv[1])) {
{
sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS), me.name, source_p->name, "MKPASSWD"); sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS), me.name, source_p->name, "MKPASSWD");
return 0; return 0;
} }
@ -61,13 +60,11 @@ m_mkpasswd(struct Client *client_p, struct Client *source_p, int parc, const cha
else else
hashtype = parv[2]; hashtype = parv[2];
if((last_used + ConfigFileEntry.pace_wait) > rb_current_time()) if((last_used + ConfigFileEntry.pace_wait) > rb_current_time()) {
{
/* safe enough to give this on a local connect only */ /* safe enough to give this on a local connect only */
sendto_one(source_p, form_str(RPL_LOAD2HI), me.name, source_p->name, "MKPASSWD"); sendto_one(source_p, form_str(RPL_LOAD2HI), me.name, source_p->name, "MKPASSWD");
return 0; return 0;
} } else
else
last_used = rb_current_time(); last_used = rb_current_time();
if(!irccmp(hashtype, "SHA256")) if(!irccmp(hashtype, "SHA256"))
@ -76,8 +73,7 @@ m_mkpasswd(struct Client *client_p, struct Client *source_p, int parc, const cha
salt = make_sha512_salt(16); salt = make_sha512_salt(16);
else if(!irccmp(hashtype, "MD5")) else if(!irccmp(hashtype, "MD5"))
salt = make_md5_salt(8); salt = make_md5_salt(8);
else else {
{
sendto_one_notice(source_p, sendto_one_notice(source_p,
":MKPASSWD syntax error: MKPASSWD pass [SHA256|SHA512|MD5]"); ":MKPASSWD syntax error: MKPASSWD pass [SHA256|SHA512|MD5]");
return 0; return 0;
@ -98,8 +94,7 @@ mo_mkpasswd(struct Client *client_p, struct Client *source_p, int parc, const ch
const char *hashtype; const char *hashtype;
const char hashdefault[] = "SHA512"; const char hashdefault[] = "SHA512";
if(EmptyString(parv[1])) if(EmptyString(parv[1])) {
{
sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS), me.name, source_p->name, "MKPASSWD"); sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS), me.name, source_p->name, "MKPASSWD");
return 0; return 0;
} }
@ -115,8 +110,7 @@ mo_mkpasswd(struct Client *client_p, struct Client *source_p, int parc, const ch
salt = make_sha512_salt(16); salt = make_sha512_salt(16);
else if(!irccmp(hashtype, "MD5")) else if(!irccmp(hashtype, "MD5"))
salt = make_md5_salt(8); salt = make_md5_salt(8);
else else {
{
sendto_one_notice(source_p, sendto_one_notice(source_p,
":MKPASSWD syntax error: MKPASSWD pass [SHA256|SHA512|MD5]"); ":MKPASSWD syntax error: MKPASSWD pass [SHA256|SHA512|MD5]");
return 0; return 0;
@ -130,8 +124,7 @@ char *
make_md5_salt(int length) make_md5_salt(int length)
{ {
static char salt[21]; static char salt[21];
if(length > 16) if(length > 16) {
{
printf("MD5 salt length too long\n"); printf("MD5 salt length too long\n");
exit(0); exit(0);
} }
@ -148,8 +141,7 @@ char *
make_sha256_salt(int length) make_sha256_salt(int length)
{ {
static char salt[21]; static char salt[21];
if(length > 16) if(length > 16) {
{
printf("SHA256 salt length too long\n"); printf("SHA256 salt length too long\n");
exit(0); exit(0);
} }
@ -166,8 +158,7 @@ char *
make_sha512_salt(int length) make_sha512_salt(int length)
{ {
static char salt[21]; static char salt[21];
if(length > 16) if(length > 16) {
{
printf("SHA512 salt length too long\n"); printf("SHA512 salt length too long\n");
exit(0); exit(0);
} }
@ -185,8 +176,7 @@ generate_poor_salt(char *salt, int length)
{ {
int i; int i;
srand(time(NULL)); srand(time(NULL));
for(i = 0; i < length; i++) for(i = 0; i < length; i++) {
{
salt[i] = saltChars[rand() % 64]; salt[i] = saltChars[rand() % 64];
} }
return (salt); return (salt);
@ -197,19 +187,16 @@ generate_random_salt(char *salt, int length)
{ {
char *buf; char *buf;
int fd, i; int fd, i;
if((fd = open("/dev/random", O_RDONLY)) < 0) if((fd = open("/dev/random", O_RDONLY)) < 0) {
{
return (generate_poor_salt(salt, length)); return (generate_poor_salt(salt, length));
} }
buf = calloc(1, length); buf = calloc(1, length);
if(read(fd, buf, length) != length) if(read(fd, buf, length) != length) {
{
free(buf); free(buf);
return (generate_poor_salt(salt, length)); return (generate_poor_salt(salt, length));
} }
for(i = 0; i < length; i++) for(i = 0; i < length; i++) {
{
salt[i] = saltChars[abs(buf[i]) % 64]; salt[i] = saltChars[abs(buf[i]) % 64];
} }
free(buf); free(buf);

View File

@ -25,15 +25,13 @@ mo_oaccept(struct Client *client_p, struct Client *source_p, int parc, const cha
struct Client *target_p; struct Client *target_p;
char text[10]; char text[10];
if(!(target_p = find_client(parv[1]))) if(!(target_p = find_client(parv[1]))) {
{
sendto_one(source_p, form_str(ERR_NOSUCHNICK), parv[1]); sendto_one(source_p, form_str(ERR_NOSUCHNICK), parv[1]);
return 0; return 0;
} }
/* If we don't check for this, and some idiot tries to OACCEPT a server... */ /* If we don't check for this, and some idiot tries to OACCEPT a server... */
if(!IsPerson(target_p)) if(!IsPerson(target_p)) {
{
sendto_one_notice(source_p, ":That is a server, not a user. What are you doing?"); sendto_one_notice(source_p, ":That is a server, not a user. What are you doing?");
return 0; return 0;
} }
@ -42,10 +40,8 @@ mo_oaccept(struct Client *client_p, struct Client *source_p, int parc, const cha
/* Provide a nice error message if you try to OACCEPT someone /* Provide a nice error message if you try to OACCEPT someone
* who you've already OACCEPTed. */ * who you've already OACCEPTed. */
DICTIONARY_FOREACH(md, &iter, target_p->user->metadata) DICTIONARY_FOREACH(md, &iter, target_p->user->metadata) {
{ if(!strcmp(md->value, "OACCEPT") && !strcmp(md->name, text)) {
if(!strcmp(md->value, "OACCEPT") && !strcmp(md->name, text))
{
sendto_one_notice(source_p, ":You're already on %s's OACCEPT list", target_p->name); sendto_one_notice(source_p, ":You're already on %s's OACCEPT list", target_p->name);
return 0; return 0;
} }

View File

@ -58,27 +58,23 @@ mo_ojoin(struct Client *client_p, struct Client *source_p, int parc, const char
int move_me = 0; int move_me = 0;
/* admins only */ /* admins only */
if(!IsOperAdmin(source_p)) if(!IsOperAdmin(source_p)) {
{
sendto_one(source_p, form_str(ERR_NOPRIVS), me.name, source_p->name, "admin"); sendto_one(source_p, form_str(ERR_NOPRIVS), me.name, source_p->name, "admin");
return 0; return 0;
} }
if(*parv[1] == '@' || *parv[1] == '%' || *parv[1] == '+' || *parv[1] == '!' || *parv[1] == '~') if(*parv[1] == '@' || *parv[1] == '%' || *parv[1] == '+' || *parv[1] == '!' || *parv[1] == '~') {
{
parv[1]++; parv[1]++;
move_me = 1; move_me = 1;
} }
if((chptr = find_channel(parv[1])) == NULL) if((chptr = find_channel(parv[1])) == NULL) {
{
sendto_one_numeric(source_p, ERR_NOSUCHCHANNEL, sendto_one_numeric(source_p, ERR_NOSUCHCHANNEL,
form_str(ERR_NOSUCHCHANNEL), parv[1]); form_str(ERR_NOSUCHCHANNEL), parv[1]);
return 0; return 0;
} }
if(IsMember(source_p, chptr)) if(IsMember(source_p, chptr)) {
{
sendto_one_notice(source_p, ":Please part %s before using OJOIN", parv[1]); sendto_one_notice(source_p, ":Please part %s before using OJOIN", parv[1]);
return 0; return 0;
} }
@ -97,8 +93,7 @@ mo_ojoin(struct Client *client_p, struct Client *source_p, int parc, const char
me.name, parv[1], me.name, parv[1],
source_p->name, source_p->username, source_p->host); source_p->name, source_p->username, source_p->host);
if(*parv[1] == '~' && ConfigChannel.use_owner) if(*parv[1] == '~' && ConfigChannel.use_owner) {
{
add_user_to_channel(chptr, source_p, CHFL_OWNER); add_user_to_channel(chptr, source_p, CHFL_OWNER);
sendto_server(client_p, chptr, CAP_TS6, NOCAPS, sendto_server(client_p, chptr, CAP_TS6, NOCAPS,
":%s SJOIN %ld %s + :~%s", ":%s SJOIN %ld %s + :~%s",
@ -108,9 +103,7 @@ mo_ojoin(struct Client *client_p, struct Client *source_p, int parc, const char
source_p->username, source_p->host, chptr->chname); source_p->username, source_p->host, chptr->chname);
sendto_channel_local(ALL_MEMBERS, chptr, ":%s MODE %s +y %s", sendto_channel_local(ALL_MEMBERS, chptr, ":%s MODE %s +y %s",
me.name, chptr->chname, source_p->name); me.name, chptr->chname, source_p->name);
} } else if(*parv[1] == '!' && ConfigChannel.use_admin) {
else if(*parv[1] == '!' && ConfigChannel.use_admin)
{
add_user_to_channel(chptr, source_p, CHFL_ADMIN); add_user_to_channel(chptr, source_p, CHFL_ADMIN);
sendto_server(client_p, chptr, CAP_TS6, NOCAPS, sendto_server(client_p, chptr, CAP_TS6, NOCAPS,
":%s SJOIN %ld %s + :!%s", ":%s SJOIN %ld %s + :!%s",
@ -121,9 +114,7 @@ mo_ojoin(struct Client *client_p, struct Client *source_p, int parc, const char
sendto_channel_local(ALL_MEMBERS, chptr, ":%s MODE %s +a %s", sendto_channel_local(ALL_MEMBERS, chptr, ":%s MODE %s +a %s",
me.name, chptr->chname, source_p->name); me.name, chptr->chname, source_p->name);
} } else if(*parv[1] == '@') {
else if(*parv[1] == '@')
{
add_user_to_channel(chptr, source_p, CHFL_CHANOP); add_user_to_channel(chptr, source_p, CHFL_CHANOP);
sendto_server(client_p, chptr, CAP_TS6, NOCAPS, sendto_server(client_p, chptr, CAP_TS6, NOCAPS,
":%s SJOIN %ld %s + :@%s", ":%s SJOIN %ld %s + :@%s",
@ -134,9 +125,7 @@ mo_ojoin(struct Client *client_p, struct Client *source_p, int parc, const char
sendto_channel_local(ALL_MEMBERS, chptr, ":%s MODE %s +o %s", sendto_channel_local(ALL_MEMBERS, chptr, ":%s MODE %s +o %s",
me.name, chptr->chname, source_p->name); me.name, chptr->chname, source_p->name);
} } else if(*parv[1] == '%' && ConfigChannel.use_halfop) {
else if(*parv[1] == '%' && ConfigChannel.use_halfop)
{
add_user_to_channel(chptr, source_p, CHFL_HALFOP); add_user_to_channel(chptr, source_p, CHFL_HALFOP);
sendto_server(client_p, chptr, CAP_TS6, NOCAPS, sendto_server(client_p, chptr, CAP_TS6, NOCAPS,
":%s SJOIN %ld %s + :%s%s", ":%s SJOIN %ld %s + :%s%s",
@ -146,9 +135,7 @@ mo_ojoin(struct Client *client_p, struct Client *source_p, int parc, const char
source_p->username, source_p->host, chptr->chname); source_p->username, source_p->host, chptr->chname);
sendto_channel_local(ALL_MEMBERS, chptr, ":%s MODE %s +h %s", sendto_channel_local(ALL_MEMBERS, chptr, ":%s MODE %s +h %s",
me.name, chptr->chname, source_p->name); me.name, chptr->chname, source_p->name);
} } else if(*parv[1] == '+') {
else if(*parv[1] == '+')
{
add_user_to_channel(chptr, source_p, CHFL_VOICE); add_user_to_channel(chptr, source_p, CHFL_VOICE);
sendto_server(client_p, chptr, CAP_TS6, NOCAPS, sendto_server(client_p, chptr, CAP_TS6, NOCAPS,
":%s SJOIN %ld %s + :+%s", ":%s SJOIN %ld %s + :+%s",
@ -158,9 +145,7 @@ mo_ojoin(struct Client *client_p, struct Client *source_p, int parc, const char
source_p->username, source_p->host, chptr->chname); source_p->username, source_p->host, chptr->chname);
sendto_channel_local(ALL_MEMBERS, chptr, ":%s MODE %s +v %s", sendto_channel_local(ALL_MEMBERS, chptr, ":%s MODE %s +v %s",
me.name, chptr->chname, source_p->name); me.name, chptr->chname, source_p->name);
} } else {
else
{
add_user_to_channel(chptr, source_p, CHFL_PEON); add_user_to_channel(chptr, source_p, CHFL_PEON);
sendto_server(client_p, chptr, CAP_TS6, NOCAPS, sendto_server(client_p, chptr, CAP_TS6, NOCAPS,
":%s JOIN %ld %s +", ":%s JOIN %ld %s +",
@ -171,8 +156,7 @@ mo_ojoin(struct Client *client_p, struct Client *source_p, int parc, const char
} }
/* send the topic... */ /* send the topic... */
if(chptr->topic != NULL) if(chptr->topic != NULL) {
{
sendto_one(source_p, form_str(RPL_TOPIC), me.name, sendto_one(source_p, form_str(RPL_TOPIC), me.name,
source_p->name, chptr->chname, chptr->topic); source_p->name, chptr->chname, chptr->topic);
sendto_one(source_p, form_str(RPL_TOPICWHOTIME), me.name, sendto_one(source_p, form_str(RPL_TOPICWHOTIME), me.name,

View File

@ -70,8 +70,7 @@ mo_okick(struct Client *client_p, struct Client *source_p, int parc, const char
char text[10]; char text[10];
static char buf[BUFSIZE]; static char buf[BUFSIZE];
if(*parv[2] == '\0') if(*parv[2] == '\0') {
{
sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS), me.name, source_p->name, "KICK"); sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS), me.name, source_p->name, "KICK");
return 0; return 0;
} }
@ -90,8 +89,7 @@ mo_okick(struct Client *client_p, struct Client *source_p, int parc, const char
name = LOCAL_COPY(parv[1]); name = LOCAL_COPY(parv[1]);
chptr = find_channel(name); chptr = find_channel(name);
if(!chptr) if(!chptr) {
{
sendto_one_numeric(source_p, ERR_NOSUCHCHANNEL, form_str(ERR_NOSUCHCHANNEL), name); sendto_one_numeric(source_p, ERR_NOSUCHCHANNEL, form_str(ERR_NOSUCHCHANNEL), name);
return 0; return 0;
} }
@ -100,19 +98,16 @@ mo_okick(struct Client *client_p, struct Client *source_p, int parc, const char
if((p = strchr(parv[2], ','))) if((p = strchr(parv[2], ',')))
*p = '\0'; *p = '\0';
user = LOCAL_COPY(parv[2]); // strtoken(&p2, parv[2], ","); user = LOCAL_COPY(parv[2]); // strtoken(&p2, parv[2], ",");
if(!(who = find_chasing(source_p, user, &chasing))) if(!(who = find_chasing(source_p, user, &chasing))) {
{
return 0; return 0;
} }
if((target_p = find_client(user)) == NULL) if((target_p = find_client(user)) == NULL) {
{
sendto_one(source_p, form_str(ERR_NOSUCHNICK), me.name, source_p->name, user); sendto_one(source_p, form_str(ERR_NOSUCHNICK), me.name, source_p->name, user);
return 0; return 0;
} }
if((msptr = find_channel_membership(chptr, target_p)) == NULL) if((msptr = find_channel_membership(chptr, target_p)) == NULL) {
{
sendto_one(source_p, form_str(ERR_USERNOTINCHANNEL), sendto_one(source_p, form_str(ERR_USERNOTINCHANNEL),
me.name, source_p->name, parv[1], parv[2]); me.name, source_p->name, parv[1], parv[2]);
return 0; return 0;

View File

@ -66,8 +66,7 @@ static void list_named_channel(struct Client *source_p, const char *name);
static int static int
mo_olist(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) mo_olist(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
{ {
if(!IsOperSpy(source_p)) if(!IsOperSpy(source_p)) {
{
sendto_one(source_p, form_str(ERR_NOPRIVS), sendto_one(source_p, form_str(ERR_NOPRIVS),
me.name, source_p->name, "oper_spy"); me.name, source_p->name, "oper_spy");
sendto_one(source_p, form_str(RPL_LISTEND), sendto_one(source_p, form_str(RPL_LISTEND),
@ -101,8 +100,7 @@ list_all_channels(struct Client *source_p)
report_operspy(source_p, "LIST", NULL); report_operspy(source_p, "LIST", NULL);
sendto_one(source_p, form_str(RPL_LISTSTART), me.name, source_p->name); sendto_one(source_p, form_str(RPL_LISTSTART), me.name, source_p->name);
RB_DLINK_FOREACH(ptr, global_channel_list.head) RB_DLINK_FOREACH(ptr, global_channel_list.head) {
{
chptr = ptr->data; chptr = ptr->data;
sendto_one(source_p, ":%s 322 %s %s %lu :[%s] %s", sendto_one(source_p, ":%s 322 %s %s %lu :[%s] %s",

View File

@ -66,15 +66,13 @@ mo_omode(struct Client *client_p, struct Client *source_p, int parc, const char
int wasonchannel; int wasonchannel;
/* admins only */ /* admins only */
if(!IsOperAdmin(source_p)) if(!IsOperAdmin(source_p)) {
{
sendto_one(source_p, form_str(ERR_NOPRIVS), me.name, source_p->name, "admin"); sendto_one(source_p, form_str(ERR_NOPRIVS), me.name, source_p->name, "admin");
return 0; return 0;
} }
/* Now, try to find the channel in question */ /* Now, try to find the channel in question */
if(!IsChanPrefix(parv[1][0]) || !check_channel_name(parv[1])) if(!IsChanPrefix(parv[1][0]) || !check_channel_name(parv[1])) {
{
sendto_one_numeric(source_p, ERR_BADCHANNAME, sendto_one_numeric(source_p, ERR_BADCHANNAME,
form_str(ERR_BADCHANNAME), parv[1]); form_str(ERR_BADCHANNAME), parv[1]);
return 0; return 0;
@ -82,8 +80,7 @@ mo_omode(struct Client *client_p, struct Client *source_p, int parc, const char
chptr = find_channel(parv[1]); chptr = find_channel(parv[1]);
if(chptr == NULL) if(chptr == NULL) {
{
sendto_one_numeric(source_p, ERR_NOSUCHCHANNEL, sendto_one_numeric(source_p, ERR_NOSUCHCHANNEL,
form_str(ERR_NOSUCHCHANNEL), parv[1]); form_str(ERR_NOSUCHCHANNEL), parv[1]);
return 0; return 0;
@ -93,15 +90,13 @@ mo_omode(struct Client *client_p, struct Client *source_p, int parc, const char
msptr = find_channel_membership(chptr, source_p); msptr = find_channel_membership(chptr, source_p);
wasonchannel = msptr != NULL; wasonchannel = msptr != NULL;
if (is_any_op(msptr)) if (is_any_op(msptr)) {
{
sendto_one_notice(source_p, ":Use a normal MODE you idiot"); sendto_one_notice(source_p, ":Use a normal MODE you idiot");
return 0; return 0;
} }
params[0] = '\0'; params[0] = '\0';
for (i = 2; i < parc; i++) for (i = 2; i < parc; i++) {
{
if (i != 2) if (i != 2)
rb_strlcat(params, " ", sizeof params); rb_strlcat(params, " ", sizeof params);
rb_strlcat(params, parv[i], sizeof params); rb_strlcat(params, parv[i], sizeof params);
@ -123,11 +118,9 @@ mo_omode(struct Client *client_p, struct Client *source_p, int parc, const char
set_channel_mode(client_p, source_p->servptr, chptr, msptr, set_channel_mode(client_p, source_p->servptr, chptr, msptr,
parc - 2, parv + 2); parc - 2, parv + 2);
#else #else
if (parc == 4 && !strcmp(parv[2], "+y") && !irccmp(parv[3], source_p->name)) if (parc == 4 && !strcmp(parv[2], "+y") && !irccmp(parv[3], source_p->name)) {
{
/* Ownering themselves */ /* Ownering themselves */
if (!wasonchannel) if (!wasonchannel) {
{
sendto_one_numeric(source_p, ERR_USERNOTINCHANNEL, sendto_one_numeric(source_p, ERR_USERNOTINCHANNEL,
form_str(ERR_USERNOTINCHANNEL), parv[3], chptr->chname); form_str(ERR_USERNOTINCHANNEL), parv[3], chptr->chname);
return 0; return 0;
@ -139,12 +132,9 @@ mo_omode(struct Client *client_p, struct Client *source_p, int parc, const char
me.id, (long) chptr->channelts, parv[1], me.id, (long) chptr->channelts, parv[1],
source_p->id); source_p->id);
msptr->flags |= CHFL_OWNER; msptr->flags |= CHFL_OWNER;
} } else if (parc == 4 && !strcmp(parv[2], "+a") && !irccmp(parv[3], source_p->name)) {
else if (parc == 4 && !strcmp(parv[2], "+a") && !irccmp(parv[3], source_p->name))
{
/* Admining themselves */ /* Admining themselves */
if (!wasonchannel) if (!wasonchannel) {
{
sendto_one_numeric(source_p, ERR_USERNOTINCHANNEL, sendto_one_numeric(source_p, ERR_USERNOTINCHANNEL,
form_str(ERR_USERNOTINCHANNEL), parv[3], chptr->chname); form_str(ERR_USERNOTINCHANNEL), parv[3], chptr->chname);
return 0; return 0;
@ -156,12 +146,9 @@ mo_omode(struct Client *client_p, struct Client *source_p, int parc, const char
me.id, (long) chptr->channelts, parv[1], me.id, (long) chptr->channelts, parv[1],
source_p->id); source_p->id);
msptr->flags |= CHFL_ADMIN; msptr->flags |= CHFL_ADMIN;
} } else if (parc == 4 && !strcmp(parv[2], "+o") && !irccmp(parv[3], source_p->name)) {
else if (parc == 4 && !strcmp(parv[2], "+o") && !irccmp(parv[3], source_p->name))
{
/* Opping themselves */ /* Opping themselves */
if (!wasonchannel) if (!wasonchannel) {
{
sendto_one_numeric(source_p, ERR_USERNOTINCHANNEL, sendto_one_numeric(source_p, ERR_USERNOTINCHANNEL,
form_str(ERR_USERNOTINCHANNEL), parv[3], chptr->chname); form_str(ERR_USERNOTINCHANNEL), parv[3], chptr->chname);
return 0; return 0;
@ -173,12 +160,9 @@ mo_omode(struct Client *client_p, struct Client *source_p, int parc, const char
me.id, (long) chptr->channelts, parv[1], me.id, (long) chptr->channelts, parv[1],
source_p->id); source_p->id);
msptr->flags |= CHFL_CHANOP; msptr->flags |= CHFL_CHANOP;
} } else if (parc == 4 && !strcmp(parv[2], "+h") && !irccmp(parv[3], source_p->name)) {
else if (parc == 4 && !strcmp(parv[2], "+h") && !irccmp(parv[3], source_p->name))
{
/* Halfopping themselves */ /* Halfopping themselves */
if (!wasonchannel) if (!wasonchannel) {
{
sendto_one_numeric(source_p, ERR_USERNOTINCHANNEL, sendto_one_numeric(source_p, ERR_USERNOTINCHANNEL,
form_str(ERR_USERNOTINCHANNEL), parv[3], chptr->chname); form_str(ERR_USERNOTINCHANNEL), parv[3], chptr->chname);
return 0; return 0;
@ -190,17 +174,14 @@ mo_omode(struct Client *client_p, struct Client *source_p, int parc, const char
me.id, (long) chptr->channelts, parv[1], me.id, (long) chptr->channelts, parv[1],
source_p->id); source_p->id);
msptr->flags |= CHFL_HALFOP; msptr->flags |= CHFL_HALFOP;
} } else if (ConfigChannel.use_owner) {
else if (ConfigChannel.use_owner)
{
/* I hope this is correct. /* I hope this is correct.
* -- Kabaka */ * -- Kabaka */
/* Hack it so set_channel_mode() will accept */ /* Hack it so set_channel_mode() will accept */
if (wasonchannel) if (wasonchannel)
msptr->flags |= CHFL_OWNER; msptr->flags |= CHFL_OWNER;
else else {
{
add_user_to_channel(chptr, source_p, CHFL_CHANOP); add_user_to_channel(chptr, source_p, CHFL_CHANOP);
msptr = find_channel_membership(chptr, source_p); msptr = find_channel_membership(chptr, source_p);
} }
@ -210,14 +191,11 @@ mo_omode(struct Client *client_p, struct Client *source_p, int parc, const char
msptr->flags &= ~CHFL_OWNER; msptr->flags &= ~CHFL_OWNER;
else else
remove_user_from_channel(msptr); remove_user_from_channel(msptr);
} } else if (ConfigChannel.use_admin) {
else if (ConfigChannel.use_admin)
{
/* Hack it so set_channel_mode() will accept */ /* Hack it so set_channel_mode() will accept */
if (wasonchannel) if (wasonchannel)
msptr->flags |= CHFL_ADMIN; msptr->flags |= CHFL_ADMIN;
else else {
{
add_user_to_channel(chptr, source_p, CHFL_CHANOP); add_user_to_channel(chptr, source_p, CHFL_CHANOP);
msptr = find_channel_membership(chptr, source_p); msptr = find_channel_membership(chptr, source_p);
} }
@ -230,15 +208,12 @@ mo_omode(struct Client *client_p, struct Client *source_p, int parc, const char
msptr->flags &= ~CHFL_ADMIN; msptr->flags &= ~CHFL_ADMIN;
else else
remove_user_from_channel(msptr); remove_user_from_channel(msptr);
} } else {
else
{
/* CHFL_ADMIN is only useful if admin is enabled /* CHFL_ADMIN is only useful if admin is enabled
* so hack it with op if it is not. */ * so hack it with op if it is not. */
if (wasonchannel) if (wasonchannel)
msptr->flags |= CHFL_CHANOP; msptr->flags |= CHFL_CHANOP;
else else {
{
add_user_to_channel(chptr, source_p, CHFL_CHANOP); add_user_to_channel(chptr, source_p, CHFL_CHANOP);
msptr = find_channel_membership(chptr, source_p); msptr = find_channel_membership(chptr, source_p);
} }

View File

@ -58,25 +58,21 @@ mo_opme(struct Client *client_p, struct Client *source_p, int parc, const char *
rb_dlink_node *ptr; rb_dlink_node *ptr;
/* admins only */ /* admins only */
if(!IsOperAdmin(source_p)) if(!IsOperAdmin(source_p)) {
{
sendto_one(source_p, form_str(ERR_NOPRIVS), me.name, source_p->name, "admin"); sendto_one(source_p, form_str(ERR_NOPRIVS), me.name, source_p->name, "admin");
return 0; return 0;
} }
if((chptr = find_channel(parv[1])) == NULL) if((chptr = find_channel(parv[1])) == NULL) {
{
sendto_one_numeric(source_p, ERR_NOSUCHCHANNEL, sendto_one_numeric(source_p, ERR_NOSUCHCHANNEL,
form_str(ERR_NOSUCHCHANNEL), parv[1]); form_str(ERR_NOSUCHCHANNEL), parv[1]);
return 0; return 0;
} }
RB_DLINK_FOREACH(ptr, chptr->members.head) RB_DLINK_FOREACH(ptr, chptr->members.head) {
{
msptr = ptr->data; msptr = ptr->data;
if(is_chanop(msptr) || is_admin(msptr) || is_owner(msptr)) if(is_chanop(msptr) || is_admin(msptr) || is_owner(msptr)) {
{
sendto_one_notice(source_p, ":%s Channel is not opless", parv[1]); sendto_one_notice(source_p, ":%s Channel is not opless", parv[1]);
return 0; return 0;
} }
@ -96,8 +92,7 @@ mo_opme(struct Client *client_p, struct Client *source_p, int parc, const char *
parv[1], get_oper_name(source_p)); parv[1], get_oper_name(source_p));
/* dont send stuff for local channels remotely. */ /* dont send stuff for local channels remotely. */
if(*chptr->chname != '&') if(*chptr->chname != '&') {
{
sendto_server(NULL, NULL, NOCAPS, NOCAPS, sendto_server(NULL, NULL, NOCAPS, NOCAPS,
":%s WALLOPS :OPME called for [%s] by %s!%s@%s", ":%s WALLOPS :OPME called for [%s] by %s!%s@%s",
me.name, parv[1], source_p->name, source_p->username, source_p->host); me.name, parv[1], source_p->name, source_p->username, source_p->host);

View File

@ -139,27 +139,23 @@ m_displaymsg(struct Client *source_p, const char *channel, int underline, int ac
char *nick3 = rb_strdup(nick); char *nick3 = rb_strdup(nick);
char text2[BUFSIZE]; char text2[BUFSIZE];
if((chptr = find_channel(channel)) == NULL) if((chptr = find_channel(channel)) == NULL) {
{
sendto_one(source_p, form_str(ERR_NOSUCHCHANNEL), channel); sendto_one(source_p, form_str(ERR_NOSUCHCHANNEL), channel);
return 0; return 0;
} }
if(!(msptr = find_channel_membership(chptr, source_p))) if(!(msptr = find_channel_membership(chptr, source_p))) {
{
sendto_one_numeric(source_p, ERR_NOTONCHANNEL, sendto_one_numeric(source_p, ERR_NOTONCHANNEL,
form_str(ERR_NOTONCHANNEL), chptr->chname); form_str(ERR_NOTONCHANNEL), chptr->chname);
return 0; return 0;
} }
if(!(chptr->mode.mode & chmode_flags['N'])) if(!(chptr->mode.mode & chmode_flags['N'])) {
{
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 0; return 0;
} }
if(!can_send(chptr, source_p, msptr)) if(!can_send(chptr, source_p, msptr)) {
{
sendto_one_numeric(source_p, 573, "%s :Cannot send to channel.", chptr->chname); sendto_one_numeric(source_p, 573, "%s :Cannot send to channel.", chptr->chname);
return 0; return 0;
} }
@ -169,8 +165,7 @@ m_displaymsg(struct Client *source_p, const char *channel, int underline, int ac
return 0; return 0;
/* enforce target change on roleplay commands */ /* enforce target change on roleplay commands */
if(!is_chanop_voiced(msptr) && !IsOper(source_p) && !add_channel_target(source_p, chptr)) if(!is_chanop_voiced(msptr) && !IsOper(source_p) && !add_channel_target(source_p, chptr)) {
{
sendto_one(source_p, form_str(ERR_TARGCHANGE), sendto_one(source_p, form_str(ERR_TARGCHANGE),
me.name, source_p->name, chptr->chname); me.name, source_p->name, chptr->chname);
return 0; return 0;
@ -183,8 +178,7 @@ m_displaymsg(struct Client *source_p, const char *channel, int underline, int ac
/* don't allow nicks to be empty after stripping /* don't allow nicks to be empty after stripping
* this prevents nastiness like fake factions, etc. */ * this prevents nastiness like fake factions, etc. */
if(EmptyString(nick3)) if(EmptyString(nick3)) {
{
sendto_one_numeric(source_p, 573, "%s :No visible non-stripped characters in nick.", chptr->chname); sendto_one_numeric(source_p, 573, "%s :No visible non-stripped characters in nick.", chptr->chname);
return 0; return 0;
} }

View File

@ -69,8 +69,7 @@ static const char *expand_xline(const char *mask)
return NULL; return NULL;
p = mask; p = mask;
q = buf; q = buf;
while (*p != '\0') while (*p != '\0') {
{
if (*p == ' ') if (*p == ' ')
*q++ = '\\', *q++ = 's'; *q++ = '\\', *q++ = 's';
else else
@ -89,20 +88,17 @@ static int mo_sendbans(struct Client *client_p, struct Client *source_p, int par
const char *target, *mask2; const char *target, *mask2;
struct Client *server_p; struct Client *server_p;
if (!IsOperRemoteBan(source_p)) if (!IsOperRemoteBan(source_p)) {
{
sendto_one(source_p, form_str(ERR_NOPRIVS), sendto_one(source_p, form_str(ERR_NOPRIVS),
me.name, source_p->name, "remoteban"); me.name, source_p->name, "remoteban");
return 0; return 0;
} }
if (!IsOperXline(source_p)) if (!IsOperXline(source_p)) {
{
sendto_one(source_p, form_str(ERR_NOPRIVS), sendto_one(source_p, form_str(ERR_NOPRIVS),
me.name, source_p->name, "xline"); me.name, source_p->name, "xline");
return 0; return 0;
} }
if (!IsOperResv(source_p)) if (!IsOperResv(source_p)) {
{
sendto_one(source_p, form_str(ERR_NOPRIVS), sendto_one(source_p, form_str(ERR_NOPRIVS),
me.name, source_p->name, "resv"); me.name, source_p->name, "resv");
return 0; return 0;
@ -110,16 +106,14 @@ static int mo_sendbans(struct Client *client_p, struct Client *source_p, int par
target = parv[1]; target = parv[1];
count = 0; count = 0;
RB_DLINK_FOREACH(ptr, global_serv_list.head) RB_DLINK_FOREACH(ptr, global_serv_list.head) {
{
server_p = ptr->data; server_p = ptr->data;
if (IsMe(server_p)) if (IsMe(server_p))
continue; continue;
if (match(target, server_p->name)) if (match(target, server_p->name))
count++; count++;
} }
if (count == 0) if (count == 0) {
{
sendto_one_numeric(source_p, ERR_NOSUCHSERVER, sendto_one_numeric(source_p, ERR_NOSUCHSERVER,
form_str(ERR_NOSUCHSERVER), target); form_str(ERR_NOSUCHSERVER), target);
return 0; return 0;
@ -130,8 +124,7 @@ static int mo_sendbans(struct Client *client_p, struct Client *source_p, int par
source_p->name, source_p->username, source_p->host, source_p->name, source_p->username, source_p->host,
target); target);
RB_DLINK_FOREACH(ptr, resv_conf_list.head) RB_DLINK_FOREACH(ptr, resv_conf_list.head) {
{
aconf = ptr->data; aconf = ptr->data;
if (aconf->hold) if (aconf->hold)
continue; continue;
@ -141,8 +134,7 @@ static int mo_sendbans(struct Client *client_p, struct Client *source_p, int par
target, aconf->host, aconf->passwd); target, aconf->host, aconf->passwd);
} }
HASH_WALK(i, R_MAX, ptr, resvTable) HASH_WALK(i, R_MAX, ptr, resvTable) {
{
aconf = ptr->data; aconf = ptr->data;
if (aconf->hold) if (aconf->hold)
continue; continue;
@ -153,14 +145,12 @@ static int mo_sendbans(struct Client *client_p, struct Client *source_p, int par
} }
HASH_WALK_END HASH_WALK_END
RB_DLINK_FOREACH(ptr, xline_conf_list.head) RB_DLINK_FOREACH(ptr, xline_conf_list.head) {
{
aconf = ptr->data; aconf = ptr->data;
if (aconf->hold) if (aconf->hold)
continue; continue;
mask2 = expand_xline(aconf->host); mask2 = expand_xline(aconf->host);
if (mask2 == NULL) if (mask2 == NULL) {
{
sendto_one_notice(source_p, ":Skipping xline [%s]", sendto_one_notice(source_p, ":Skipping xline [%s]",
aconf->host); aconf->host);
continue; continue;

View File

@ -77,8 +77,7 @@ mr_webirc(struct Client *client_p, struct Client *source_p, int parc, const char
struct ConfItem *aconf; struct ConfItem *aconf;
const char *encr; const char *encr;
if (!strchr(parv[4], '.') && !strchr(parv[4], ':')) if (!strchr(parv[4], '.') && !strchr(parv[4], ':')) {
{
sendto_one(source_p, "NOTICE * :Invalid IP"); sendto_one(source_p, "NOTICE * :Invalid IP");
return 0; return 0;
} }
@ -90,14 +89,12 @@ mr_webirc(struct Client *client_p, struct Client *source_p, int parc, const char
client_p->localClient->ip.ss_family, NULL); client_p->localClient->ip.ss_family, NULL);
if (aconf == NULL || !(aconf->status & CONF_CLIENT)) if (aconf == NULL || !(aconf->status & CONF_CLIENT))
return 0; return 0;
if (!IsConfDoSpoofIp(aconf) || irccmp(aconf->info.name, "webirc.")) if (!IsConfDoSpoofIp(aconf) || irccmp(aconf->info.name, "webirc.")) {
{
/* XXX */ /* XXX */
sendto_one(source_p, "NOTICE * :Not a CGI:IRC auth block"); sendto_one(source_p, "NOTICE * :Not a CGI:IRC auth block");
return 0; return 0;
} }
if (EmptyString(aconf->passwd)) if (EmptyString(aconf->passwd)) {
{
sendto_one(source_p, "NOTICE * :CGI:IRC auth blocks must have a password"); sendto_one(source_p, "NOTICE * :CGI:IRC auth blocks must have a password");
return 0; return 0;
} }
@ -109,8 +106,7 @@ mr_webirc(struct Client *client_p, struct Client *source_p, int parc, const char
else else
encr = parv[1]; encr = parv[1];
if (strcmp(encr, aconf->passwd)) if (strcmp(encr, aconf->passwd)) {
{
sendto_one(source_p, "NOTICE * :CGI:IRC password incorrect"); sendto_one(source_p, "NOTICE * :CGI:IRC password incorrect");
return 0; return 0;
} }
@ -127,10 +123,8 @@ mr_webirc(struct Client *client_p, struct Client *source_p, int parc, const char
/* Check dlines now, klines will be checked on registration */ /* Check dlines now, klines will be checked on registration */
if((aconf = find_dline((struct sockaddr *)&source_p->localClient->ip, if((aconf = find_dline((struct sockaddr *)&source_p->localClient->ip,
source_p->localClient->ip.ss_family))) source_p->localClient->ip.ss_family))) {
{ if(!(aconf->status & CONF_EXEMPTDLINE)) {
if(!(aconf->status & CONF_EXEMPTDLINE))
{
exit_client(client_p, source_p, &me, "D-lined"); exit_client(client_p, source_p, &me, "D-lined");
return 0; return 0;
} }

View File

@ -26,8 +26,7 @@ h_nl_umode_changed(hook_data_umode_changed *hdata)
{ {
struct Client *source_p = hdata->client; struct Client *source_p = hdata->client;
if (MyClient(source_p) && source_p->umodes & UMODE_LOCOPS) if (MyClient(source_p) && source_p->umodes & UMODE_LOCOPS) {
{
source_p->umodes &= ~UMODE_LOCOPS; source_p->umodes &= ~UMODE_LOCOPS;
} }
} }

View File

@ -29,8 +29,7 @@ h_noi_umode_changed(hook_data_umode_changed *hdata)
struct Client *source_p = hdata->client; struct Client *source_p = hdata->client;
if (MyClient(source_p) && IsOper(source_p) && !IsOperInvis(source_p) && if (MyClient(source_p) && IsOper(source_p) && !IsOperInvis(source_p) &&
IsInvisible(source_p)) IsInvisible(source_p)) {
{
ClearInvisible(source_p); ClearInvisible(source_p);
/* If they tried /umode +i, complain; do not complain /* If they tried /umode +i, complain; do not complain
* if they opered up while invisible -- jilles */ * if they opered up while invisible -- jilles */

View File

@ -34,27 +34,20 @@ h_gla_client_exit(hook_data_client_exit *hdata)
if (MyConnect(source_p) || !IsClient(source_p)) if (MyConnect(source_p) || !IsClient(source_p))
return; return;
if (!strcmp(hdata->comment, "Bad user info")) if (!strcmp(hdata->comment, "Bad user info")) {
{
sendto_realops_snomask_from(SNO_GENERAL, L_ALL, source_p->servptr, sendto_realops_snomask_from(SNO_GENERAL, L_ALL, source_p->servptr,
"XLINE active for %s[%s@%s]", "XLINE active for %s[%s@%s]",
source_p->name, source_p->username, source_p->host); source_p->name, source_p->username, source_p->host);
} } else if (ConfigFileEntry.kline_reason != NULL &&
else if (ConfigFileEntry.kline_reason != NULL && !strcmp(hdata->comment, ConfigFileEntry.kline_reason)) {
!strcmp(hdata->comment, ConfigFileEntry.kline_reason))
{
sendto_realops_snomask_from(SNO_GENERAL, L_ALL, source_p->servptr, sendto_realops_snomask_from(SNO_GENERAL, L_ALL, source_p->servptr,
"K/DLINE active for %s[%s@%s]", "K/DLINE active for %s[%s@%s]",
source_p->name, source_p->username, source_p->host); source_p->name, source_p->username, source_p->host);
} } else if (!strncmp(hdata->comment, "Temporary K-line ", 17)) {
else if (!strncmp(hdata->comment, "Temporary K-line ", 17))
{
sendto_realops_snomask_from(SNO_GENERAL, L_ALL, source_p->servptr, sendto_realops_snomask_from(SNO_GENERAL, L_ALL, source_p->servptr,
"K/DLINE active for %s[%s@%s]", "K/DLINE active for %s[%s@%s]",
source_p->name, source_p->username, source_p->host); source_p->name, source_p->username, source_p->host);
} } else if (!strncmp(hdata->comment, "Temporary D-line ", 17)) {
else if (!strncmp(hdata->comment, "Temporary D-line ", 17))
{
sendto_realops_snomask_from(SNO_GENERAL, L_ALL, source_p->servptr, sendto_realops_snomask_from(SNO_GENERAL, L_ALL, source_p->servptr,
"K/DLINE active for %s[%s@%s]", "K/DLINE active for %s[%s@%s]",
source_p->name, source_p->username, source_p->host); source_p->name, source_p->username, source_p->host);

View File

@ -52,8 +52,7 @@ show_whois(hook_data_client *data)
IsOper(target_p) && IsOper(target_p) &&
#endif #endif
(source_p != target_p) && (source_p != target_p) &&
(target_p->snomask & snomask_modes['W'])) (target_p->snomask & snomask_modes['W'])) {
{
sendto_one_notice(target_p, sendto_one_notice(target_p,
":*** Notice -- %s (%s@%s) is doing a whois on you [%s]", ":*** Notice -- %s (%s@%s) is doing a whois on you [%s]",
source_p->name, source_p->name,

View File

@ -41,8 +41,7 @@ show_stats(hook_data_int *data)
{ {
char statchar = (char) data->arg2; char statchar = (char) data->arg2;
if(statchar == 'L' || statchar == 'l') if(statchar == 'L' || statchar == 'l') {
{
const char *name = data->arg1; const char *name = data->arg1;
if(!EmptyString(name)) if(!EmptyString(name))
@ -58,9 +57,7 @@ show_stats(hook_data_int *data)
statchar, data->client->name, statchar, data->client->name,
data->client->username, data->client->username,
data->client->host, data->client->servptr->name); data->client->host, data->client->servptr->name);
} } else {
else
{
sendto_realops_snomask(SNO_SPY, L_ALL, sendto_realops_snomask(SNO_SPY, L_ALL,
"STATS %c requested by %s (%s@%s) [%s]", "STATS %c requested by %s (%s@%s) [%s]",
statchar, data->client->name, data->client->username, statchar, data->client->name, data->client->username,

View File

@ -17,7 +17,8 @@
#include "version.h" #include "version.h"
IRCDVar myIrcd[] = { IRCDVar myIrcd[] = {
{"Elemental-IRCd 6.5", /* ircd name */ {
"Elemental-IRCd 6.5", /* ircd name */
"+oiS", /* nickserv mode */ "+oiS", /* nickserv mode */
"+oiS", /* chanserv mode */ "+oiS", /* chanserv mode */
"+oiS", /* memoserv mode */ "+oiS", /* memoserv mode */
@ -145,7 +146,8 @@ IRCDCAPAB myIrcdcap[] = {
0, /* TLKEXT */ 0, /* TLKEXT */
0, /* DODKEY */ 0, /* DODKEY */
0, /* DOZIP */ 0, /* DOZIP */
0, 0, 0} 0, 0, 0
}
}; };
/*******************************************************************/ /*******************************************************************/
@ -780,44 +782,82 @@ void moduleAddIRCDMsgs(void)
TS6SID = sstrdup(Numeric); TS6SID = sstrdup(Numeric);
} }
m = createMessage("401", anope_event_null); addCoreMessage(IRCD,m); m = createMessage("401", anope_event_null);
m = createMessage("402", anope_event_null); addCoreMessage(IRCD,m); addCoreMessage(IRCD,m);
m = createMessage("436", anope_event_436); addCoreMessage(IRCD,m); m = createMessage("402", anope_event_null);
m = createMessage("AWAY", anope_event_away); addCoreMessage(IRCD,m); addCoreMessage(IRCD,m);
m = createMessage("INVITE", anope_event_invite); addCoreMessage(IRCD,m); m = createMessage("436", anope_event_436);
m = createMessage("JOIN", anope_event_join); addCoreMessage(IRCD,m); addCoreMessage(IRCD,m);
m = createMessage("KICK", anope_event_kick); addCoreMessage(IRCD,m); m = createMessage("AWAY", anope_event_away);
m = createMessage("KILL", anope_event_kill); addCoreMessage(IRCD,m); addCoreMessage(IRCD,m);
m = createMessage("MODE", anope_event_mode); addCoreMessage(IRCD,m); m = createMessage("INVITE", anope_event_invite);
m = createMessage("TMODE", anope_event_tmode); addCoreMessage(IRCD,m); addCoreMessage(IRCD,m);
m = createMessage("MOTD", anope_event_motd); addCoreMessage(IRCD,m); m = createMessage("JOIN", anope_event_join);
m = createMessage("NICK", anope_event_nick); addCoreMessage(IRCD,m); addCoreMessage(IRCD,m);
m = createMessage("BMASK", anope_event_bmask); addCoreMessage(IRCD,m); m = createMessage("KICK", anope_event_kick);
m = createMessage("UID", anope_event_nick); addCoreMessage(IRCD,m); addCoreMessage(IRCD,m);
m = createMessage("NOTICE", anope_event_notice); addCoreMessage(IRCD,m); m = createMessage("KILL", anope_event_kill);
m = createMessage("PART", anope_event_part); addCoreMessage(IRCD,m); addCoreMessage(IRCD,m);
m = createMessage("PASS", anope_event_pass); addCoreMessage(IRCD,m); m = createMessage("MODE", anope_event_mode);
m = createMessage("PING", anope_event_ping); addCoreMessage(IRCD,m); addCoreMessage(IRCD,m);
m = createMessage("PRIVMSG", anope_event_privmsg); addCoreMessage(IRCD,m); m = createMessage("TMODE", anope_event_tmode);
m = createMessage("QUIT", anope_event_quit); addCoreMessage(IRCD,m); addCoreMessage(IRCD,m);
m = createMessage("SERVER", anope_event_server); addCoreMessage(IRCD,m); m = createMessage("MOTD", anope_event_motd);
m = createMessage("SQUIT", anope_event_squit); addCoreMessage(IRCD,m); addCoreMessage(IRCD,m);
m = createMessage("TOPIC", anope_event_topic); addCoreMessage(IRCD,m); m = createMessage("NICK", anope_event_nick);
m = createMessage("TB", anope_event_tburst); addCoreMessage(IRCD,m); addCoreMessage(IRCD,m);
m = createMessage("USER", anope_event_null); addCoreMessage(IRCD,m); m = createMessage("BMASK", anope_event_bmask);
m = createMessage("WALLOPS", anope_event_null); addCoreMessage(IRCD,m); addCoreMessage(IRCD,m);
m = createMessage("WHOIS", anope_event_whois); addCoreMessage(IRCD,m); m = createMessage("UID", anope_event_nick);
m = createMessage("SVSMODE", anope_event_null); addCoreMessage(IRCD,m); addCoreMessage(IRCD,m);
m = createMessage("SVSNICK", anope_event_null); addCoreMessage(IRCD,m); m = createMessage("NOTICE", anope_event_notice);
m = createMessage("CAPAB", anope_event_capab); addCoreMessage(IRCD,m); addCoreMessage(IRCD,m);
m = createMessage("SJOIN", anope_event_sjoin); addCoreMessage(IRCD,m); m = createMessage("PART", anope_event_part);
m = createMessage("SVINFO", anope_event_svinfo); addCoreMessage(IRCD,m); addCoreMessage(IRCD,m);
m = createMessage("ADMIN", anope_event_admin); addCoreMessage(IRCD,m); m = createMessage("PASS", anope_event_pass);
m = createMessage("ERROR", anope_event_error); addCoreMessage(IRCD,m); addCoreMessage(IRCD,m);
m = createMessage("421", anope_event_null); addCoreMessage(IRCD,m); m = createMessage("PING", anope_event_ping);
m = createMessage("ENCAP", anope_event_null); addCoreMessage(IRCD,m); addCoreMessage(IRCD,m);
m = createMessage("SID", anope_event_sid); addCoreMessage(IRCD,m); m = createMessage("PRIVMSG", anope_event_privmsg);
m = createMessage("EUID", anope_event_euid); addCoreMessage(IRCD,m); addCoreMessage(IRCD,m);
m = createMessage("QUIT", anope_event_quit);
addCoreMessage(IRCD,m);
m = createMessage("SERVER", anope_event_server);
addCoreMessage(IRCD,m);
m = createMessage("SQUIT", anope_event_squit);
addCoreMessage(IRCD,m);
m = createMessage("TOPIC", anope_event_topic);
addCoreMessage(IRCD,m);
m = createMessage("TB", anope_event_tburst);
addCoreMessage(IRCD,m);
m = createMessage("USER", anope_event_null);
addCoreMessage(IRCD,m);
m = createMessage("WALLOPS", anope_event_null);
addCoreMessage(IRCD,m);
m = createMessage("WHOIS", anope_event_whois);
addCoreMessage(IRCD,m);
m = createMessage("SVSMODE", anope_event_null);
addCoreMessage(IRCD,m);
m = createMessage("SVSNICK", anope_event_null);
addCoreMessage(IRCD,m);
m = createMessage("CAPAB", anope_event_capab);
addCoreMessage(IRCD,m);
m = createMessage("SJOIN", anope_event_sjoin);
addCoreMessage(IRCD,m);
m = createMessage("SVINFO", anope_event_svinfo);
addCoreMessage(IRCD,m);
m = createMessage("ADMIN", anope_event_admin);
addCoreMessage(IRCD,m);
m = createMessage("ERROR", anope_event_error);
addCoreMessage(IRCD,m);
m = createMessage("421", anope_event_null);
addCoreMessage(IRCD,m);
m = createMessage("ENCAP", anope_event_null);
addCoreMessage(IRCD,m);
m = createMessage("SID", anope_event_sid);
addCoreMessage(IRCD,m);
m = createMessage("EUID", anope_event_euid);
addCoreMessage(IRCD,m);
} }
/* *INDENT-ON* */ /* *INDENT-ON* */

View File

@ -3,8 +3,7 @@
void init_bandb(void); void init_bandb(void);
typedef enum typedef enum {
{
BANDB_KLINE, BANDB_KLINE,
BANDB_DLINE, BANDB_DLINE,
BANDB_XLINE, BANDB_XLINE,

View File

@ -14,15 +14,13 @@
struct Client; struct Client;
struct cachefile struct cachefile {
{
char name[CACHEFILELEN]; char name[CACHEFILELEN];
rb_dlink_list contents; rb_dlink_list contents;
int flags; int flags;
}; };
struct cacheline struct cacheline {
{
char data[CACHELINELEN]; char data[CACHELINELEN];
rb_dlink_node linenode; rb_dlink_node linenode;
}; };

View File

@ -35,8 +35,7 @@
struct Client; struct Client;
/* mode structure for channels */ /* mode structure for channels */
struct Mode struct Mode {
{
unsigned int mode; unsigned int mode;
int limit; int limit;
char key[KEYLEN]; char key[KEYLEN];
@ -46,8 +45,7 @@ struct Mode
}; };
/* channel structure */ /* channel structure */
struct Channel struct Channel {
{
rb_dlink_node node; rb_dlink_node node;
struct Mode mode; struct Mode mode;
char *mode_lock; char *mode_lock;
@ -79,8 +77,7 @@ struct Channel
char *chname; char *chname;
}; };
struct membership struct membership {
{
rb_dlink_node channode; rb_dlink_node channode;
rb_dlink_node locchannode; rb_dlink_node locchannode;
rb_dlink_node usernode; rb_dlink_node usernode;
@ -93,22 +90,19 @@ struct membership
}; };
#define BANLEN 195 #define BANLEN 195
struct Ban struct Ban {
{
char *banstr; char *banstr;
char *who; char *who;
time_t when; time_t when;
rb_dlink_node node; rb_dlink_node node;
}; };
struct mode_letter struct mode_letter {
{
int mode; int mode;
char letter; char letter;
}; };
struct ChModeChange struct ChModeChange {
{
char letter; char letter;
const char *arg; const char *arg;
const char *id; const char *id;
@ -120,8 +114,7 @@ struct ChModeChange
struct Client *client; struct Client *client;
}; };
struct ChCapCombo struct ChCapCombo {
{
int count; int count;
int cap_yes; int cap_yes;
int cap_no; int cap_no;
@ -131,8 +124,7 @@ typedef void (*ChannelModeFunc)(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, long mode_type);
struct ChannelMode struct ChannelMode {
{
ChannelModeFunc set_func; ChannelModeFunc set_func;
long mode_type; long mode_type;
}; };

View File

@ -30,8 +30,7 @@ struct ConfItem;
struct Client; struct Client;
struct _patricia_tree_t; struct _patricia_tree_t;
struct Class struct Class {
{
struct Class *next; struct Class *next;
char *class_name; char *class_name;
int max_total; int max_total;

View File

@ -76,8 +76,7 @@ struct scache_entry;
/* /*
* Client structures * Client structures
*/ */
struct User struct User {
{
rb_dlink_list channel; /* chain of channel pointer blocks */ rb_dlink_list channel; /* chain of channel pointer blocks */
rb_dlink_list invited; /* chain of invite pointer blocks */ rb_dlink_list invited; /* chain of invite pointer blocks */
char *away; /* pointer to away message */ char *away; /* pointer to away message */
@ -88,8 +87,7 @@ struct User
char suser[NICKLEN+1]; char suser[NICKLEN+1];
}; };
struct Server struct Server {
{
struct User *user; /* who activated this connection */ struct User *user; /* who activated this connection */
char by[NICKLEN]; char by[NICKLEN];
rb_dlink_list servers; rb_dlink_list servers;
@ -99,8 +97,7 @@ struct Server
struct scache_entry *nameinfo; struct scache_entry *nameinfo;
}; };
struct ZipStats struct ZipStats {
{
unsigned long long in; unsigned long long in;
unsigned long long in_wire; unsigned long long in_wire;
unsigned long long out; unsigned long long out;
@ -109,8 +106,7 @@ struct ZipStats
double out_ratio; double out_ratio;
}; };
struct Client struct Client {
{
rb_dlink_node node; rb_dlink_node node;
rb_dlink_node lnode; rb_dlink_node lnode;
struct User *user; /* ...defined, if this is a User */ struct User *user; /* ...defined, if this is a User */
@ -170,8 +166,7 @@ struct Client
char *certfp; /* client certificate fingerprint */ char *certfp; /* client certificate fingerprint */
}; };
struct LocalUser struct LocalUser {
{
rb_dlink_node tnode; /* This is the node for the local list type the client is on*/ rb_dlink_node tnode; /* This is the node for the local list type the client is on*/
/* /*
* The following fields are allocated only for local clients * The following fields are allocated only for local clients
@ -286,8 +281,7 @@ struct LocalUser
struct ev_entry *override_timeout_event; struct ev_entry *override_timeout_event;
}; };
struct PreClient struct PreClient {
{
char spoofnick[NICKLEN + 1]; char spoofnick[NICKLEN + 1];
char spoofuser[USERLEN + 1]; char spoofuser[USERLEN + 1];
char spoofhost[HOSTLEN + 1]; char spoofhost[HOSTLEN + 1];
@ -302,8 +296,7 @@ struct PreClient
struct rb_sockaddr_storage lip; /* address of our side of the connection */ struct rb_sockaddr_storage lip; /* address of our side of the connection */
}; };
struct ListClient struct ListClient {
{
unsigned int hash_indice; unsigned int hash_indice;
unsigned int users_min, users_max; unsigned int users_min, users_max;
time_t created_min, created_max, topic_min, topic_max; time_t created_min, created_max, topic_min, topic_max;

View File

@ -6,8 +6,7 @@
#ifndef INCLUDED_HOOK_H #ifndef INCLUDED_HOOK_H
#define INCLUDED_HOOK_H #define INCLUDED_HOOK_H
typedef struct typedef struct {
{
char *name; char *name;
rb_dlink_list hooks; rb_dlink_list hooks;
} hook; } hook;
@ -36,64 +35,55 @@ void add_hook(const char *name, hookfn fn);
void remove_hook(const char *name, hookfn fn); void remove_hook(const char *name, hookfn fn);
void call_hook(int id, void *arg); void call_hook(int id, void *arg);
typedef struct typedef struct {
{
struct Client *client; struct Client *client;
const void *arg1; const void *arg1;
const void *arg2; const void *arg2;
} hook_data; } hook_data;
typedef struct typedef struct {
{
struct Client *client; struct Client *client;
const void *arg1; const void *arg1;
int arg2; int arg2;
} hook_data_int; } hook_data_int;
typedef struct typedef struct {
{
struct Client *client; struct Client *client;
struct Client *target; struct Client *target;
} hook_data_client; } hook_data_client;
typedef struct typedef struct {
{
struct Client *client; struct Client *client;
struct Channel *chptr; struct Channel *chptr;
int approved; int approved;
} hook_data_channel; } hook_data_channel;
typedef struct typedef struct {
{
struct Client *client; struct Client *client;
struct Channel *chptr; struct Channel *chptr;
char *key; char *key;
} hook_data_channel_activity; } hook_data_channel_activity;
typedef struct typedef struct {
{
struct Client *client; struct Client *client;
struct Channel *chptr; struct Channel *chptr;
struct Client *target; struct Client *target;
int approved; int approved;
} hook_data_channel_approval; } hook_data_channel_approval;
typedef struct typedef struct {
{
struct Client *client; struct Client *client;
int approved; int approved;
} hook_data_client_approval; } hook_data_client_approval;
typedef struct typedef struct {
{
struct Client *local_link; /* local client originating this, or NULL */ struct Client *local_link; /* local client originating this, or NULL */
struct Client *target; /* dying client */ struct Client *target; /* dying client */
struct Client *from; /* causing client (could be &me or target) */ struct Client *from; /* causing client (could be &me or target) */
const char *comment; const char *comment;
} hook_data_client_exit; } hook_data_client_exit;
typedef struct typedef struct {
{
struct Client *client; struct Client *client;
unsigned int oldumodes; unsigned int oldumodes;
unsigned int oldsnomask; unsigned int oldsnomask;

View File

@ -26,8 +26,7 @@
#ifndef INCLUDE_hostmask_h #ifndef INCLUDE_hostmask_h
#define INCLUDE_hostmask_h 1 #define INCLUDE_hostmask_h 1
enum enum {
{
HM_HOST, HM_HOST,
HM_IPV4 HM_IPV4
#ifdef RB_IPV6 #ifdef RB_IPV6
@ -70,15 +69,12 @@ int match_ipv4(struct sockaddr *, struct sockaddr *, int);
extern struct AddressRec *atable[ATABLE_SIZE]; extern struct AddressRec *atable[ATABLE_SIZE];
struct AddressRec struct AddressRec {
{
/* masktype: HM_HOST, HM_IPV4, HM_IPV6 -A1kmm */ /* masktype: HM_HOST, HM_IPV4, HM_IPV6 -A1kmm */
int masktype; int masktype;
union union {
{ struct {
struct
{
/* Pointer into ConfItem... -A1kmm */ /* Pointer into ConfItem... -A1kmm */
struct rb_sockaddr_storage addr; struct rb_sockaddr_storage addr;
int bits; int bits;

View File

@ -36,16 +36,13 @@ strip_colour(char *string)
/* c is source, c2 is target */ /* c is source, c2 is target */
for(; c && *c; c++) for(; c && *c; c++)
switch (*c) switch (*c) {
{
case 3: case 3:
if(isdigit(c[1])) if(isdigit(c[1])) {
{
c++; c++;
if(isdigit(c[1])) if(isdigit(c[1]))
c++; c++;
if(c[1] == ',' && isdigit(c[2])) if(c[1] == ',' && isdigit(c[2])) {
{
c += 2; c += 2;
if(isdigit(c[1])) if(isdigit(c[1]))
c++; c++;
@ -87,16 +84,13 @@ strip_unprintable(char *string)
/* c is source, c2 is target */ /* c is source, c2 is target */
for(; c && *c; c++) for(; c && *c; c++)
switch (*c) switch (*c) {
{
case 3: case 3:
if(isdigit(c[1])) if(isdigit(c[1])) {
{
c++; c++;
if(isdigit(c[1])) if(isdigit(c[1]))
c++; c++;
if(c[1] == ',' && isdigit(c[2])) if(c[1] == ',' && isdigit(c[2])) {
{
c += 2; c += 2;
if(isdigit(c[1])) if(isdigit(c[1]))
c++; c++;

View File

@ -29,16 +29,14 @@ struct Dictionary; /* defined in src/dictionary.c */
typedef int (*DCF)(const char *a, const char *b); typedef int (*DCF)(const char *a, const char *b);
struct DictionaryElement struct DictionaryElement {
{
struct DictionaryElement *left, *right, *prev, *next; struct DictionaryElement *left, *right, *prev, *next;
void *data; void *data;
const char *key; const char *key;
int position; int position;
}; };
struct DictionaryIter struct DictionaryIter {
{
struct DictionaryElement *cur, *next; struct DictionaryElement *cur, *next;
}; };

View File

@ -31,8 +31,7 @@
struct Client; struct Client;
struct rb_dlink_list; struct rb_dlink_list;
struct SetOptions struct SetOptions {
{
int maxclients; /* max clients allowed */ int maxclients; /* max clients allowed */
int autoconn; /* autoconn enabled for all servers? */ int autoconn; /* autoconn enabled for all servers? */
@ -47,15 +46,13 @@ struct SetOptions
char adminstring[REALLEN]; char adminstring[REALLEN];
}; };
struct Metadata struct Metadata {
{
const char *name; const char *name;
const char *value; const char *value;
time_t timevalue; time_t timevalue;
}; };
struct Counter struct Counter {
{
int oper; /* Opers */ int oper; /* Opers */
int total; /* total clients */ int total; /* total clients */
int invisi; /* invisible clients */ int invisi; /* invisible clients */

View File

@ -94,7 +94,7 @@
#endif #endif
#define HOSTLEN 63 /* Length of hostname. Updated to */ #define HOSTLEN 63 /* Length of hostname. Updated to */
/* comply with RFC1123 */ /* comply with RFC1123 */
#define USERLEN 10 #define USERLEN 10
#define REALLEN 50 #define REALLEN 50

View File

@ -26,8 +26,7 @@
#ifndef __GETOPT_H_INCLUDED__ #ifndef __GETOPT_H_INCLUDED__
#define __GETOPT_H_INCLUDED__ #define __GETOPT_H_INCLUDED__
struct lgetopt struct lgetopt {
{
const char *opt; /* name of the argument */ const char *opt; /* name of the argument */
void *argloc; /* where we store the argument to it (-option argument) */ void *argloc; /* where we store the argument to it (-option argument) */
enum enum

View File

@ -37,8 +37,7 @@
#include <dlfcn.h> #include <dlfcn.h>
struct ircd_symbol struct ircd_symbol {
{
char *sym; /* name of symbol to be bound to ptr */ char *sym; /* name of symbol to be bound to ptr */
void *ptr; /* ptr to symbol in library */ void *ptr; /* ptr to symbol in library */
}; };

View File

@ -30,8 +30,7 @@
struct Client; struct Client;
struct Listener struct Listener {
{
struct Listener *next; /* list node pointer */ struct Listener *next; /* list node pointer */
const char *name; /* listener name */ const char *name; /* listener name */
rb_fde_t *F; /* file descriptor */ rb_fde_t *F; /* file descriptor */

View File

@ -35,8 +35,7 @@
#include "ircd_defs.h" #include "ircd_defs.h"
typedef enum ilogfile typedef enum ilogfile {
{
L_MAIN, L_MAIN,
L_USER, L_USER,
L_FUSER, L_FUSER,

View File

@ -28,8 +28,7 @@
#include "config.h" #include "config.h"
typedef struct Information typedef struct Information {
{
const char *name; /* name of item */ const char *name; /* name of item */
const char *strvalue; /* value of item if it's a boolean */ const char *strvalue; /* value of item if it's a boolean */
int intvalue; /* value of item if it's an integer */ int intvalue; /* value of item if it's an integer */
@ -64,11 +63,15 @@ Info MyInformation[] = {
#endif /* UH PATH */ #endif /* UH PATH */
#ifdef SOMAXCONN #ifdef SOMAXCONN
{"RATBOX_SOMAXCONN", "", SOMAXCONN, {
"Maximum Queue Length of Pending Connections"}, "RATBOX_SOMAXCONN", "", SOMAXCONN,
"Maximum Queue Length of Pending Connections"
},
#else #else
{"RATBOX_SOMAXCONN", "", RATBOX_SOMAXCONN, {
"Maximum Queue Length of Pending Connections"}, "RATBOX_SOMAXCONN", "", RATBOX_SOMAXCONN,
"Maximum Queue Length of Pending Connections"
},
#endif /* SOMAXCONN */ #endif /* SOMAXCONN */
#ifdef RB_IPV6 #ifdef RB_IPV6
@ -77,11 +80,15 @@ Info MyInformation[] = {
{"IPV6", "OFF", 0, "IPv6 Support"}, {"IPV6", "OFF", 0, "IPv6 Support"},
#endif #endif
{"JOIN_LEAVE_COUNT_EXPIRE_TIME", "", JOIN_LEAVE_COUNT_EXPIRE_TIME, {
"Anti SpamBot Parameter"}, "JOIN_LEAVE_COUNT_EXPIRE_TIME", "", JOIN_LEAVE_COUNT_EXPIRE_TIME,
"Anti SpamBot Parameter"
},
{"KILLCHASETIMELIMIT", "", KILLCHASETIMELIMIT, {
"Nick Change Tracker for KILL"}, "KILLCHASETIMELIMIT", "", KILLCHASETIMELIMIT,
"Nick Change Tracker for KILL"
},
#ifdef LPATH #ifdef LPATH
{"LPATH", LPATH, 0, "Path to Log File"}, {"LPATH", LPATH, 0, "Path to Log File"},
@ -91,11 +98,15 @@ Info MyInformation[] = {
{"MAX_BUFFER", "", MAX_BUFFER, "Maximum Buffer Connections Allowed"}, {"MAX_BUFFER", "", MAX_BUFFER, "Maximum Buffer Connections Allowed"},
{"MAX_JOIN_LEAVE_COUNT", "", MAX_JOIN_LEAVE_COUNT, {
"Anti SpamBot Parameter"}, "MAX_JOIN_LEAVE_COUNT", "", MAX_JOIN_LEAVE_COUNT,
"Anti SpamBot Parameter"
},
{"MIN_JOIN_LEAVE_TIME", "", MIN_JOIN_LEAVE_TIME, {
"Anti SpamBot Parameter"}, "MIN_JOIN_LEAVE_TIME", "", MIN_JOIN_LEAVE_TIME,
"Anti SpamBot Parameter"
},
#ifdef MPATH #ifdef MPATH
{"MPATH", MPATH, 0, "Path to MOTD File"}, {"MPATH", MPATH, 0, "Path to MOTD File"},
@ -103,8 +114,10 @@ Info MyInformation[] = {
{"MPATH", "NONE", 0, "Path to MOTD File"}, {"MPATH", "NONE", 0, "Path to MOTD File"},
#endif /* MPATH */ #endif /* MPATH */
{"NICKNAMEHISTORYLENGTH", "", NICKNAMEHISTORYLENGTH, {
"Size of WHOWAS Array"}, "NICKNAMEHISTORYLENGTH", "", NICKNAMEHISTORYLENGTH,
"Size of WHOWAS Array"
},
#ifdef OPATH #ifdef OPATH
{"OPATH", OPATH, 0, "Path to Operator MOTD File"}, {"OPATH", OPATH, 0, "Path to Operator MOTD File"},
@ -112,8 +125,10 @@ Info MyInformation[] = {
{"OPATH", "NONE", 0, "Path to Operator MOTD File"}, {"OPATH", "NONE", 0, "Path to Operator MOTD File"},
#endif /* OPATH */ #endif /* OPATH */
{"OPER_SPAM_COUNTDOWN", "", OPER_SPAM_COUNTDOWN, {
"Anti SpamBot Parameter"}, "OPER_SPAM_COUNTDOWN", "", OPER_SPAM_COUNTDOWN,
"Anti SpamBot Parameter"
},
#ifdef HAVE_LIBCRYPTO #ifdef HAVE_LIBCRYPTO
{"HAVE_LIBCRYPTO", "ON", 0, "Enable OpenSSL CHALLENGE Support"}, {"HAVE_LIBCRYPTO", "ON", 0, "Enable OpenSSL CHALLENGE Support"},
@ -141,10 +156,14 @@ Info MyInformation[] = {
{"SPATH", "NONE", 0, "Path to Server Executable"}, {"SPATH", "NONE", 0, "Path to Server Executable"},
#endif /* SPATH */ #endif /* SPATH */
{"TS_MAX_DELTA_DEFAULT", "", TS_MAX_DELTA_DEFAULT, {
"Maximum Allowed TS Delta from another Server"}, "TS_MAX_DELTA_DEFAULT", "", TS_MAX_DELTA_DEFAULT,
{"TS_WARN_DELTA_DEFAULT", "", TS_WARN_DELTA_DEFAULT, "Maximum Allowed TS Delta from another Server"
"Maximum TS Delta before Sending Warning"}, },
{
"TS_WARN_DELTA_DEFAULT", "", TS_WARN_DELTA_DEFAULT,
"Maximum TS Delta before Sending Warning"
},
#ifdef USE_IODEBUG_HOOKS #ifdef USE_IODEBUG_HOOKS
{"USE_IODEBUG_HOOKS", "YES", 0, "IO Debugging support"}, {"USE_IODEBUG_HOOKS", "YES", 0, "IO Debugging support"},
#else #else

View File

@ -41,8 +41,7 @@
#include "msg.h" #include "msg.h"
#include "hook.h" #include "hook.h"
struct module struct module {
{
char *name; char *name;
const char *version; const char *version;
void *address; void *address;
@ -51,8 +50,7 @@ struct module
void * mapi_header; /* actually struct mapi_mheader_av<mapi_version> */ void * mapi_header; /* actually struct mapi_mheader_av<mapi_version> */
}; };
struct module_path struct module_path {
{
char path[MAXPATHLEN]; char path[MAXPATHLEN];
}; };
@ -65,20 +63,17 @@ struct module_path
typedef struct Message* mapi_clist_av1; typedef struct Message* mapi_clist_av1;
typedef struct typedef struct {
{
const char * hapi_name; const char * hapi_name;
int * hapi_id; int * hapi_id;
} mapi_hlist_av1; } mapi_hlist_av1;
typedef struct typedef struct {
{
const char * hapi_name; const char * hapi_name;
hookfn fn; hookfn fn;
} mapi_hfn_list_av1; } mapi_hfn_list_av1;
struct mapi_mheader_av1 struct mapi_mheader_av1 {
{
int mapi_version; /* Module API version */ int mapi_version; /* Module API version */
int (*mapi_register) (void); /* Register function; int (*mapi_register) (void); /* Register function;
ret -1 = failure (unload) */ ret -1 = failure (unload) */

View File

@ -11,8 +11,7 @@
struct rb_bh; struct rb_bh;
struct monitor struct monitor {
{
struct monitor *hnext; struct monitor *hnext;
char name[NICKLEN]; char name[NICKLEN];
rb_dlink_list users; rb_dlink_list users;

View File

@ -31,8 +31,7 @@
struct Client; struct Client;
/* MessageHandler */ /* MessageHandler */
typedef enum HandlerType typedef enum HandlerType {
{
UNREGISTERED_HANDLER, UNREGISTERED_HANDLER,
CLIENT_HANDLER, CLIENT_HANDLER,
RCLIENT_HANDLER, RCLIENT_HANDLER,
@ -50,15 +49,13 @@ HandlerType;
*/ */
typedef int (*MessageHandler) (struct Client *, struct Client *, int, const char *[]); typedef int (*MessageHandler) (struct Client *, struct Client *, int, const char *[]);
struct MessageEntry struct MessageEntry {
{
MessageHandler handler; MessageHandler handler;
int min_para; int min_para;
}; };
/* Message table structure */ /* Message table structure */
struct Message struct Message {
{
const char *cmd; const char *cmd;
unsigned int count; /* number of times command used */ unsigned int count; /* number of times command used */
unsigned int rcount; /* number of times command used by server */ unsigned int rcount; /* number of times command used by server */

View File

@ -5,8 +5,7 @@
#ifndef _NEWCONF_H_INCLUDED #ifndef _NEWCONF_H_INCLUDED
#define _NEWCONF_H_INCLUDED #define _NEWCONF_H_INCLUDED
struct ConfEntry struct ConfEntry {
{
const char *cf_name; const char *cf_name;
int cf_type; int cf_type;
void (*cf_func) (void *); void (*cf_func) (void *);
@ -14,8 +13,7 @@ struct ConfEntry
void *cf_arg; void *cf_arg;
}; };
struct TopConf struct TopConf {
{
const char *tc_name; const char *tc_name;
int (*tc_sfunc) (struct TopConf *); int (*tc_sfunc) (struct TopConf *);
int (*tc_efunc) (struct TopConf *); int (*tc_efunc) (struct TopConf *);
@ -37,12 +35,10 @@ struct TopConf
#define CF_FLIST 0x1000 #define CF_FLIST 0x1000
#define CF_MFLAG 0xFF00 #define CF_MFLAG 0xFF00
typedef struct conf_parm_t_stru typedef struct conf_parm_t_stru {
{
struct conf_parm_t_stru *next; struct conf_parm_t_stru *next;
int type; int type;
union union {
{
char *string; char *string;
int number; int number;
struct conf_parm_t_stru *list; struct conf_parm_t_stru *list;

View File

@ -18,14 +18,12 @@
*/ */
#define IRCD_MAXNS 10 #define IRCD_MAXNS 10
struct DNSReply struct DNSReply {
{
char *h_name; char *h_name;
struct rb_sockaddr_storage addr; struct rb_sockaddr_storage addr;
}; };
struct DNSQuery struct DNSQuery {
{
void *ptr; /* pointer used by callback to identify request */ void *ptr; /* pointer used by callback to identify request */
void (*callback)(void* vptr, struct DNSReply *reply); /* callback to call */ void (*callback)(void* vptr, struct DNSReply *reply); /* callback to call */
}; };

View File

@ -34,8 +34,7 @@
#define RRFIXEDSZ 10 #define RRFIXEDSZ 10
#define HFIXEDSZ 12 #define HFIXEDSZ 12
typedef struct typedef struct {
{
unsigned id :16; /* query identification number */ unsigned id :16; /* query identification number */
#ifdef WORDS_BIGENDIAN #ifdef WORDS_BIGENDIAN
/* fields in third byte */ /* fields in third byte */

View File

@ -43,8 +43,7 @@ struct hostent;
/* used by new parser */ /* used by new parser */
/* yacc/lex love globals!!! */ /* yacc/lex love globals!!! */
struct ip_value struct ip_value {
{
struct rb_sockaddr_storage ip; struct rb_sockaddr_storage ip;
int ip_mask; int ip_mask;
int type; int type;
@ -53,13 +52,11 @@ struct ip_value
extern FILE *conf_fbfile_in; extern FILE *conf_fbfile_in;
extern char conf_line_in[256]; extern char conf_line_in[256];
struct ConfItem struct ConfItem {
{
unsigned int status; /* If CONF_ILLEGAL, delete when no clients */ unsigned int status; /* If CONF_ILLEGAL, delete when no clients */
unsigned int flags; unsigned int flags;
int clients; /* Number of *LOCAL* clients using this */ int clients; /* Number of *LOCAL* clients using this */
union union {
{
char *name; /* IRC name, nick, server name, or original u@h */ char *name; /* IRC name, nick, server name, or original u@h */
const char *oper; const char *oper;
} info; } info;
@ -137,8 +134,7 @@ struct ConfItem
/* flag definitions for opers now in client.h */ /* flag definitions for opers now in client.h */
struct config_file_entry struct config_file_entry {
{
const char *dpath; /* DPATH if set from command line */ const char *dpath; /* DPATH if set from command line */
const char *configfile; const char *configfile;
@ -236,8 +232,7 @@ struct config_file_entry
int away_interval; int away_interval;
}; };
struct config_channel_entry struct config_channel_entry {
{
char * autochanmodes; char * autochanmodes;
char * exemptchanops; char * exemptchanops;
char * disabledmodes; char * disabledmodes;
@ -276,16 +271,14 @@ struct config_channel_entry
int exempt_cmode_K; int exempt_cmode_K;
}; };
struct config_server_hide struct config_server_hide {
{
int flatten_links; int flatten_links;
int links_delay; int links_delay;
int hidden; int hidden;
int disable_hidden; int disable_hidden;
}; };
struct server_info struct server_info {
{
char *name; char *name;
char sid[4]; char sid[4];
char *description; char *description;
@ -310,15 +303,13 @@ struct server_info
int ssld_count; int ssld_count;
}; };
struct admin_info struct admin_info {
{
char *name; char *name;
char *description; char *description;
char *email; char *email;
}; };
struct alias_entry struct alias_entry {
{
char *name; char *name;
char *target; char *target;
int flags; /* reserved for later use */ int flags; /* reserved for later use */
@ -339,8 +330,7 @@ extern rb_dlink_list service_list;
extern rb_dlink_list prop_bans; extern rb_dlink_list prop_bans;
typedef enum temp_list typedef enum temp_list {
{
TEMP_MIN, TEMP_MIN,
TEMP_HOUR, TEMP_HOUR,
TEMP_DAY, TEMP_DAY,

View File

@ -59,8 +59,7 @@ extern void init_s_newconf(void);
extern void clear_s_newconf(void); extern void clear_s_newconf(void);
extern void clear_s_newconf_bans(void); extern void clear_s_newconf_bans(void);
typedef struct typedef struct {
{
char *ip; char *ip;
time_t expiry; time_t expiry;
rb_patricia_node_t *pnode; rb_patricia_node_t *pnode;
@ -71,8 +70,7 @@ void add_tgchange(const char *host);
tgchange *find_tgchange(const char *host); tgchange *find_tgchange(const char *host);
/* shared/cluster/hub/leaf confs */ /* shared/cluster/hub/leaf confs */
struct remote_conf struct remote_conf {
{
char *username; char *username;
char *host; char *host;
char *server; char *server;
@ -107,8 +105,7 @@ struct remote_conf
#define CONF_HUB 0x0001 #define CONF_HUB 0x0001
#define CONF_LEAF 0x0002 #define CONF_LEAF 0x0002
struct oper_conf struct oper_conf {
{
char *name; char *name;
char *username; char *username;
char *host; char *host;
@ -181,8 +178,7 @@ extern struct oper_conf *find_oper_conf(const char *username, const char *host,
extern const char *get_oper_privs(int flags); extern const char *get_oper_privs(int flags);
struct server_conf struct server_conf {
{
char *name; char *name;
char *host; char *host;
char *passwd; char *passwd;
@ -240,8 +236,7 @@ extern int valid_wild_card_simple(const char *);
extern int clean_resv_nick(const char *); extern int clean_resv_nick(const char *);
time_t valid_temp_time(const char *p); time_t valid_temp_time(const char *p);
struct nd_entry struct nd_entry {
{
char name[NICKLEN+1]; char name[NICKLEN+1];
time_t expire; time_t expire;
rb_dlink_node lnode; /* node in ll */ rb_dlink_node lnode; /* node in ll */

View File

@ -46,8 +46,7 @@ struct server_conf;
struct Channel; struct Channel;
/* Capabilities */ /* Capabilities */
struct Capability struct Capability {
{
const char *name; /* name of capability */ const char *name; /* name of capability */
unsigned int cap; /* mask value */ unsigned int cap; /* mask value */
unsigned int required; /* 1 if required, 0 if not */ unsigned int required; /* 1 if required, 0 if not */

View File

@ -39,8 +39,7 @@ struct Client;
/* /*
* statistics structures * statistics structures
*/ */
struct ServerStatistics struct ServerStatistics {
{
unsigned int is_cl; /* number of client connections */ unsigned int is_cl; /* number of client connections */
unsigned int is_sv; /* number of server connections */ unsigned int is_sv; /* number of server connections */
unsigned int is_ni; /* connection but no idea who it was */ unsigned int is_ni; /* connection but no idea who it was */

View File

@ -39,7 +39,7 @@
# include <alloca.h> # include <alloca.h>
# else # else
# ifdef _AIX # ifdef _AIX
#pragma alloca #pragma alloca
# else # else
# ifndef alloca /* predefined by HP cc +Olibcalls */ # ifndef alloca /* predefined by HP cc +Olibcalls */
char *alloca (); char *alloca ();

View File

@ -45,8 +45,7 @@ struct Client;
also removed away information. *tough* also removed away information. *tough*
- Dianora - Dianora
*/ */
struct Whowas struct Whowas {
{
int hashv; int hashv;
char name[NICKLEN + 1]; char name[NICKLEN + 1];
char username[USERLEN + 1]; char username[USERLEN + 1];
@ -93,8 +92,8 @@ void off_history(struct Client *);
** one found... ** one found...
*/ */
struct Client *get_history(const char *, time_t); struct Client *get_history(const char *, time_t);
/* Nick name */ /* Nick name */
/* Time limit in seconds */ /* Time limit in seconds */
/* /*
** for debugging...counts related structures stored in whowas array. ** for debugging...counts related structures stored in whowas array.

View File

@ -44,13 +44,13 @@
#ifdef HAVE_WRITEV #ifdef HAVE_WRITEV
#ifndef UIO_MAXIOV #ifndef UIO_MAXIOV
# if defined(__FreeBSD__) || defined(__APPLE__) || defined(__NetBSD__) # if defined(__FreeBSD__) || defined(__APPLE__) || defined(__NetBSD__)
/* FreeBSD 4.7 defines it in sys/uio.h only if _KERNEL is specified */ /* FreeBSD 4.7 defines it in sys/uio.h only if _KERNEL is specified */
# define RB_UIO_MAXIOV 1024 # define RB_UIO_MAXIOV 1024
# elif defined(__sgi) # elif defined(__sgi)
/* IRIX 6.5 has sysconf(_SC_IOV_MAX) which might return 512 or bigger */ /* IRIX 6.5 has sysconf(_SC_IOV_MAX) which might return 512 or bigger */
# define RB_UIO_MAXIOV 512 # define RB_UIO_MAXIOV 512
# elif defined(__sun) # elif defined(__sun)
/* Solaris (and SunOS?) defines IOV_MAX instead */ /* Solaris (and SunOS?) defines IOV_MAX instead */
# ifndef IOV_MAX # ifndef IOV_MAX
# define RB_UIO_MAXIOV 16 # define RB_UIO_MAXIOV 16
# else # else
@ -68,8 +68,7 @@
#else #else
#define RB_UIO_MAXIOV 16 #define RB_UIO_MAXIOV 16
#endif #endif
struct conndata struct conndata {
{
/* We don't need the host here ? */ /* We don't need the host here ? */
struct rb_sockaddr_storage S; struct rb_sockaddr_storage S;
struct rb_sockaddr_storage hostaddr; struct rb_sockaddr_storage hostaddr;
@ -79,8 +78,7 @@ struct conndata
/* We'd also add the retry count here when we get to that -- adrian */ /* We'd also add the retry count here when we get to that -- adrian */
}; };
struct acceptdata struct acceptdata {
{
struct rb_sockaddr_storage S; struct rb_sockaddr_storage S;
rb_socklen_t addrlen; rb_socklen_t addrlen;
ACCB *callback; ACCB *callback;
@ -95,8 +93,7 @@ struct acceptdata
#define ClearFDOpen(F) (F->flags &= ~FLAG_OPEN) #define ClearFDOpen(F) (F->flags &= ~FLAG_OPEN)
struct _fde struct _fde {
{
/* New-school stuff, again pretty much ripped from squid */ /* New-school stuff, again pretty much ripped from squid */
/* /*
* Yes, this gives us only one pending read and one pending write per * Yes, this gives us only one pending read and one pending write per
@ -123,8 +120,7 @@ struct _fde
typedef void (*comm_event_cb_t) (void *); typedef void (*comm_event_cb_t) (void *);
#ifdef USE_TIMER_CREATE #ifdef USE_TIMER_CREATE
typedef struct timer_data typedef struct timer_data {
{
timer_t td_timer_id; timer_t td_timer_id;
comm_event_cb_t td_cb; comm_event_cb_t td_cb;
void *td_udata; void *td_udata;
@ -148,8 +144,7 @@ rb_find_fd(int fd)
if(hlist->head == NULL) if(hlist->head == NULL)
return NULL; return NULL;
RB_DLINK_FOREACH(ptr, hlist->head) RB_DLINK_FOREACH(ptr, hlist->head) {
{
rb_fde_t *F = ptr->data; rb_fde_t *F = ptr->data;
if(F->fd == fd) if(F->fd == fd)
return F; return F;

View File

@ -22,8 +22,7 @@
* *
*/ */
struct ev_entry struct ev_entry {
{
rb_dlink_node node; rb_dlink_node node;
EVH *func; EVH *func;
void *arg; void *arg;

View File

@ -48,8 +48,7 @@ typedef void ACCB(rb_fde_t *, int status, struct sockaddr *addr, rb_socklen_t le
/* callback for pre-accept callback */ /* callback for pre-accept callback */
typedef int ACPRE(rb_fde_t *, struct sockaddr *addr, rb_socklen_t len, void *); typedef int ACPRE(rb_fde_t *, struct sockaddr *addr, rb_socklen_t len, void *);
enum enum {
{
RB_OK, RB_OK,
RB_ERR_BIND, RB_ERR_BIND,
RB_ERR_DNS, RB_ERR_DNS,
@ -78,8 +77,7 @@ enum
#define RB_RW_SSL_NEED_WRITE -4 /* SSL Needs write */ #define RB_RW_SSL_NEED_WRITE -4 /* SSL Needs write */
struct rb_iovec struct rb_iovec {
{
void *iov_base; void *iov_base;
size_t iov_len; size_t iov_len;
}; };
@ -154,8 +152,7 @@ uint8_t rb_get_type(rb_fde_t *F);
const char *rb_get_iotype(void); const char *rb_get_iotype(void);
typedef enum typedef enum {
{
RB_PRNG_EGD, RB_PRNG_EGD,
RB_PRNG_FILE, RB_PRNG_FILE,
#ifdef _WIN32 #ifdef _WIN32

View File

@ -47,8 +47,8 @@ void rb_helper_restart(rb_helper *helper);
void void
rb_helper_write(rb_helper *helper, const char *format, ...) rb_helper_write(rb_helper *helper, const char *format, ...)
__attribute((format(printf, 2, 3))); __attribute((format(printf, 2, 3)));
void rb_helper_write_queue(rb_helper *helper, const char *format, ...) void rb_helper_write_queue(rb_helper *helper, const char *format, ...)
__attribute((format(printf, 2, 3))); __attribute((format(printf, 2, 3)));
#else #else
void rb_helper_write(rb_helper *helper, const char *format, ...); void rb_helper_write(rb_helper *helper, const char *format, ...);
void rb_helper_write_queue(rb_helper *helper, const char *format, ...); void rb_helper_write_queue(rb_helper *helper, const char *format, ...);

View File

@ -41,8 +41,7 @@ struct _buf_head;
/* How big we want a buffer - 510 data bytes, plus space for a '\0' */ /* How big we want a buffer - 510 data bytes, plus space for a '\0' */
#define BUF_DATA_SIZE 511 #define BUF_DATA_SIZE 511
typedef struct _buf_line typedef struct _buf_line {
{
char buf[BUF_DATA_SIZE + 2]; char buf[BUF_DATA_SIZE + 2];
uint8_t terminated; /* Whether we've terminated the buffer */ uint8_t terminated; /* Whether we've terminated the buffer */
uint8_t raw; /* Whether this linebuf may hold 8-bit data */ uint8_t raw; /* Whether this linebuf may hold 8-bit data */
@ -50,8 +49,7 @@ typedef struct _buf_line
int refcount; /* how many linked lists are we in? */ int refcount; /* how many linked lists are we in? */
} buf_line_t; } buf_line_t;
typedef struct _buf_head typedef struct _buf_head {
{
rb_dlink_list list; /* the actual dlink list */ rb_dlink_list list; /* the actual dlink list */
int len; /* length of all the data */ int len; /* length of all the data */
int alloclen; /* Actual allocated data length */ int alloclen; /* Actual allocated data length */

View File

@ -29,13 +29,11 @@
#define MAXLINE 1024 #define MAXLINE 1024
#define BIT_TEST(f, b) ((f) & (b)) #define BIT_TEST(f, b) ((f) & (b))
typedef struct _rb_prefix_t typedef struct _rb_prefix_t {
{
unsigned short family; /* AF_INET | AF_INET6 */ unsigned short family; /* AF_INET | AF_INET6 */
unsigned short bitlen; /* same as mask? */ unsigned short bitlen; /* same as mask? */
int ref_count; /* reference count */ int ref_count; /* reference count */
union union {
{
struct in_addr sin; struct in_addr sin;
#ifdef RB_IPV6 #ifdef RB_IPV6
struct in6_addr sin6; struct in6_addr sin6;
@ -46,8 +44,7 @@ typedef struct _rb_prefix_t
rb_prefix_t; rb_prefix_t;
typedef struct _rb_patricia_node_t typedef struct _rb_patricia_node_t {
{
unsigned int bit; /* flag if this node used */ unsigned int bit; /* flag if this node used */
rb_prefix_t *prefix; /* who we are in patricia tree */ rb_prefix_t *prefix; /* who we are in patricia tree */
struct _rb_patricia_node_t *l, *r; /* left and right children */ struct _rb_patricia_node_t *l, *r; /* left and right children */
@ -56,8 +53,7 @@ typedef struct _rb_patricia_node_t
} }
rb_patricia_node_t; rb_patricia_node_t;
typedef struct _rb_patricia_tree_t typedef struct _rb_patricia_tree_t {
{
rb_patricia_node_t *head; rb_patricia_node_t *head;
unsigned int maxbits; /* for IP, 32 bit addresses */ unsigned int maxbits; /* for IP, 32 bit addresses */
int num_active_node; /* for debug purpose */ int num_active_node; /* for debug purpose */

View File

@ -42,11 +42,11 @@
int int
rb_sprintf(char *str, const char *fmt, ...) rb_sprintf(char *str, const char *fmt, ...)
__attribute((format(printf, 2, 3))); __attribute((format(printf, 2, 3)));
int rb_snprintf(char *str, const size_t size, const char *, ...) int rb_snprintf(char *str, const size_t size, const char *, ...)
__attribute__ ((format(printf, 3, 4))); __attribute__ ((format(printf, 3, 4)));
int rb_sprintf_append(char *str, const char *format, ...) __attribute((format(printf, 2, 3))); int rb_sprintf_append(char *str, const char *format, ...) __attribute((format(printf, 2, 3)));
int rb_snprintf_append(char *str, size_t len, const char *format, ...) int rb_snprintf_append(char *str, size_t len, const char *format, ...)
__attribute__ ((format(printf, 3, 4))); __attribute__ ((format(printf, 3, 4)));
#else #else
int rb_sprintf(char *str, const char *format, ...); int rb_sprintf(char *str, const char *format, ...);
int rb_snprintf(char *str, const size_t size, const char *, ...); int rb_snprintf(char *str, const size_t size, const char *, ...);

View File

@ -44,16 +44,14 @@ int rb_string_to_array(char *string, char **parv, int maxpara);
typedef struct _rb_dlink_node rb_dlink_node; typedef struct _rb_dlink_node rb_dlink_node;
typedef struct _rb_dlink_list rb_dlink_list; typedef struct _rb_dlink_list rb_dlink_list;
struct _rb_dlink_node struct _rb_dlink_node {
{
void *data; void *data;
rb_dlink_node *prev; rb_dlink_node *prev;
rb_dlink_node *next; rb_dlink_node *next;
}; };
struct _rb_dlink_list struct _rb_dlink_list {
{
rb_dlink_node *head; rb_dlink_node *head;
rb_dlink_node *tail; rb_dlink_node *tail;
unsigned long length; unsigned long length;
@ -161,12 +159,9 @@ rb_dlinkAddBefore(rb_dlink_node *b, void *data, rb_dlink_node *m, rb_dlink_list
assert(list != NULL); assert(list != NULL);
/* Shortcut - if its the first one, call rb_dlinkAdd only */ /* Shortcut - if its the first one, call rb_dlinkAdd only */
if(b == list->head) if(b == list->head) {
{
rb_dlinkAdd(data, m, list); rb_dlinkAdd(data, m, list);
} } else {
else
{
m->data = data; m->data = data;
b->prev->next = m; b->prev->next = m;
m->prev = b->prev; m->prev = b->prev;
@ -251,8 +246,7 @@ rb_dlinkFindDelete(void *data, rb_dlink_list *list)
rb_dlink_node *m; rb_dlink_node *m;
assert(list != NULL); assert(list != NULL);
assert(data != NULL); assert(data != NULL);
RB_DLINK_FOREACH(m, list->head) RB_DLINK_FOREACH(m, list->head) {
{
if(m->data != data) if(m->data != data)
continue; continue;
@ -282,8 +276,7 @@ rb_dlinkFindDestroy(void *data, rb_dlink_list *list)
assert(data != NULL); assert(data != NULL);
ptr = rb_dlinkFindDelete(data, list); ptr = rb_dlinkFindDelete(data, list);
if(ptr != NULL) if(ptr != NULL) {
{
rb_free_rb_dlink_node(ptr); rb_free_rb_dlink_node(ptr);
return 1; return 1;
} }
@ -304,8 +297,7 @@ rb_dlinkFind(void *data, rb_dlink_list *list)
assert(list != NULL); assert(list != NULL);
assert(data != NULL); assert(data != NULL);
RB_DLINK_FOREACH(ptr, list->head) RB_DLINK_FOREACH(ptr, list->head) {
{
if(ptr->data == data) if(ptr->data == data)
return (ptr); return (ptr);
} }
@ -324,8 +316,7 @@ rb_dlinkMoveList(rb_dlink_list *from, rb_dlink_list *to)
return; return;
/* case two, nothing in to list */ /* case two, nothing in to list */
if(to->head == NULL) if(to->head == NULL) {
{
to->head = from->head; to->head = from->head;
to->tail = from->tail; to->tail = from->tail;
from->head = from->tail = NULL; from->head = from->tail = NULL;

View File

@ -40,8 +40,7 @@
struct arc4_stream struct arc4_stream {
{
uint8_t i; uint8_t i;
uint8_t j; uint8_t j;
uint8_t s[256]; uint8_t s[256];
@ -75,8 +74,7 @@ arc4_addrandom(struct arc4_stream *as, uint8_t *dat, int datlen)
uint8_t si; uint8_t si;
as->i--; as->i--;
for(n = 0; n < 256; n++) for(n = 0; n < 256; n++) {
{
as->i = (as->i + 1); as->i = (as->i + 1);
si = as->s[as->i]; si = as->s[as->i];
as->j = (as->j + si + dat[n % datlen]); as->j = (as->j + si + dat[n % datlen]);
@ -111,7 +109,8 @@ arc4_stir(struct arc4_stream *as)
struct rusage buf; struct rusage buf;
getrusage(RUSAGE_SELF, &buf); getrusage(RUSAGE_SELF, &buf);
arc4_addrandom(as, (void *)&buf, sizeof(buf)); arc4_addrandom(as, (void *)&buf, sizeof(buf));
memset(&buf, 0, sizeof(buf))} memset(&buf, 0, sizeof(buf))
}
#endif #endif
#if !defined(_WIN32) #if !defined(_WIN32)
@ -119,8 +118,7 @@ arc4_stir(struct arc4_stream *as)
uint8_t rnd[128]; uint8_t rnd[128];
int fd; int fd;
fd = open("/dev/urandom", O_RDONLY); fd = open("/dev/urandom", O_RDONLY);
if(fd != -1) if(fd != -1) {
{
read(fd, rnd, sizeof(rnd)); read(fd, rnd, sizeof(rnd));
close(fd); close(fd);
arc4_addrandom(as, (void *)rnd, sizeof(rnd)); arc4_addrandom(as, (void *)rnd, sizeof(rnd));
@ -131,19 +129,16 @@ arc4_stir(struct arc4_stream *as)
#else #else
{ {
LARGE_INTEGER performanceCount; LARGE_INTEGER performanceCount;
if(QueryPerformanceCounter(&performanceCount)) if(QueryPerformanceCounter(&performanceCount)) {
{
arc4_addrandom(as, (void *)&performanceCount, sizeof(performanceCount)); arc4_addrandom(as, (void *)&performanceCount, sizeof(performanceCount));
} }
lib = LoadLibrary("ADVAPI32.DLL"); lib = LoadLibrary("ADVAPI32.DLL");
if(lib) if(lib) {
{
uint8_t rnd[128]; uint8_t rnd[128];
BOOLEAN(APIENTRY * pfn) (void *, ULONG) = BOOLEAN(APIENTRY * pfn) (void *, ULONG) =
(BOOLEAN(APIENTRY *) (void *, ULONG))GetProcAddress(lib, (BOOLEAN(APIENTRY *) (void *, ULONG))GetProcAddress(lib,
"SystemFunction036"); "SystemFunction036");
if(pfn) if(pfn) {
{
if(pfn(rnd, sizeof(rnd)) == TRUE) if(pfn(rnd, sizeof(rnd)) == TRUE)
arc4_addrandom(as, (void *)rnd, sizeof(rnd)); arc4_addrandom(as, (void *)rnd, sizeof(rnd));
memset(&rnd, 0, sizeof(rnd)); memset(&rnd, 0, sizeof(rnd));
@ -192,8 +187,7 @@ arc4_getword(struct arc4_stream *as)
void void
arc4random_stir(void) arc4random_stir(void)
{ {
if(!rs_initialized) if(!rs_initialized) {
{
arc4_init(&rs); arc4_init(&rs);
rs_initialized = 1; rs_initialized = 1;
} }

View File

@ -73,8 +73,7 @@
static uintptr_t offset_pad; static uintptr_t offset_pad;
/* status information for an allocated block in heap */ /* status information for an allocated block in heap */
struct rb_heap_block struct rb_heap_block {
{
size_t alloc_size; size_t alloc_size;
rb_dlink_node node; rb_dlink_node node;
unsigned long free_count; unsigned long free_count;
@ -83,8 +82,7 @@ struct rb_heap_block
typedef struct rb_heap_block rb_heap_block; typedef struct rb_heap_block rb_heap_block;
/* information for the root node of the heap */ /* information for the root node of the heap */
struct rb_bh struct rb_bh {
{
rb_dlink_node hlist; rb_dlink_node hlist;
size_t elemSize; /* Size of each element to be stored */ size_t elemSize; /* Size of each element to be stored */
unsigned long elemsPerBlock; /* Number of elements per block */ unsigned long elemsPerBlock; /* Number of elements per block */
@ -152,8 +150,7 @@ rb_init_bh(void)
* fix your shit * fix your shit
*/ */
#ifdef __sparc__ #ifdef __sparc__
if((offset_pad % __alignof__(long long)) != 0) if((offset_pad % __alignof__(long long)) != 0) {
{
offset_pad += __alignof__(long long); offset_pad += __alignof__(long long);
offset_pad &= ~(__alignof__(long long) - 1); offset_pad &= ~(__alignof__(long long) - 1);
} }
@ -207,8 +204,7 @@ static void
rb_bh_gc_event(void *unused) rb_bh_gc_event(void *unused)
{ {
rb_dlink_node *ptr; rb_dlink_node *ptr;
RB_DLINK_FOREACH(ptr, heap_lists->head) RB_DLINK_FOREACH(ptr, heap_lists->head) {
{
rb_bh_gc(ptr->data); rb_bh_gc(ptr->data);
} }
} }
@ -237,14 +233,12 @@ newblock(rb_bh *bh)
b->alloc_size = bh->elemsPerBlock * bh->elemSize; b->alloc_size = bh->elemsPerBlock * bh->elemSize;
b->elems = get_block(b->alloc_size); b->elems = get_block(b->alloc_size);
if(rb_unlikely(b->elems == NULL)) if(rb_unlikely(b->elems == NULL)) {
{
return (1); return (1);
} }
offset = (uintptr_t)b->elems; offset = (uintptr_t)b->elems;
/* Setup our blocks now */ /* Setup our blocks now */
for(i = 0; i < bh->elemsPerBlock; i++, offset += bh->elemSize) for(i = 0; i < bh->elemsPerBlock; i++, offset += bh->elemSize) {
{
*((void **)offset) = b; *((void **)offset) = b;
node = (void *)(offset + offset_pad); node = (void *)(offset + offset_pad);
rb_dlinkAdd((void *)offset, node, &bh->free_list); rb_dlinkAdd((void *)offset, node, &bh->free_list);
@ -278,8 +272,7 @@ rb_bh_create(size_t elemsize, int elemsperblock, const char *desc)
lrb_assert(elemsize >= sizeof(rb_dlink_node)); lrb_assert(elemsize >= sizeof(rb_dlink_node));
/* Catch idiotic requests up front */ /* Catch idiotic requests up front */
if((elemsize == 0) || (elemsperblock <= 0)) if((elemsize == 0) || (elemsperblock <= 0)) {
{
rb_bh_fail("Attempting to rb_bh_create idiotic sizes"); rb_bh_fail("Attempting to rb_bh_create idiotic sizes");
} }
@ -290,8 +283,7 @@ rb_bh_create(size_t elemsize, int elemsperblock, const char *desc)
bh = rb_malloc(sizeof(rb_bh)); bh = rb_malloc(sizeof(rb_bh));
#ifndef NOBALLOC #ifndef NOBALLOC
elemsize += offset_pad; elemsize += offset_pad;
if((elemsize % sizeof(void *)) != 0) if((elemsize % sizeof(void *)) != 0) {
{
/* Pad to even pointer boundary */ /* Pad to even pointer boundary */
elemsize += sizeof(void *); elemsize += sizeof(void *);
elemsize &= ~(sizeof(void *) - 1); elemsize &= ~(sizeof(void *) - 1);
@ -305,8 +297,7 @@ rb_bh_create(size_t elemsize, int elemsperblock, const char *desc)
#ifndef NOBALLOC #ifndef NOBALLOC
/* Be sure our malloc was successful */ /* Be sure our malloc was successful */
if(newblock(bh)) if(newblock(bh)) {
{
if(bh != NULL) if(bh != NULL)
free(bh); free(bh);
rb_lib_log("newblock() failed"); rb_lib_log("newblock() failed");
@ -314,8 +305,7 @@ rb_bh_create(size_t elemsize, int elemsperblock, const char *desc)
} }
#endif /* !NOBALLOC */ #endif /* !NOBALLOC */
if(bh == NULL) if(bh == NULL) {
{
rb_bh_fail("bh == NULL when it shouldn't be"); rb_bh_fail("bh == NULL when it shouldn't be");
} }
rb_dlinkAdd(bh, &bh->hlist, heap_lists); rb_dlinkAdd(bh, &bh->hlist, heap_lists);
@ -343,26 +333,22 @@ rb_bh_alloc(rb_bh *bh)
void *ptr; void *ptr;
#endif #endif
lrb_assert(bh != NULL); lrb_assert(bh != NULL);
if(rb_unlikely(bh == NULL)) if(rb_unlikely(bh == NULL)) {
{
rb_bh_fail("Cannot allocate if bh == NULL"); rb_bh_fail("Cannot allocate if bh == NULL");
} }
#ifdef NOBALLOC #ifdef NOBALLOC
return (rb_malloc(bh->elemSize)); return (rb_malloc(bh->elemSize));
#else #else
if(bh->free_list.head == NULL) if(bh->free_list.head == NULL) {
{
/* Allocate new block and assign */ /* Allocate new block and assign */
/* newblock returns 1 if unsuccessful, 0 if not */ /* newblock returns 1 if unsuccessful, 0 if not */
if(rb_unlikely(newblock(bh))) if(rb_unlikely(newblock(bh))) {
{
rb_lib_log("newblock() failed"); rb_lib_log("newblock() failed");
rb_outofmemory(); /* Well that didn't work either...bail */ rb_outofmemory(); /* Well that didn't work either...bail */
} }
if(bh->free_list.head == NULL) if(bh->free_list.head == NULL) {
{
rb_lib_log("out of memory after newblock()..."); rb_lib_log("out of memory after newblock()...");
rb_outofmemory(); rb_outofmemory();
} }
@ -400,14 +386,12 @@ rb_bh_free(rb_bh *bh, void *ptr)
lrb_assert(bh != NULL); lrb_assert(bh != NULL);
lrb_assert(ptr != NULL); lrb_assert(ptr != NULL);
if(rb_unlikely(bh == NULL)) if(rb_unlikely(bh == NULL)) {
{
rb_lib_log("balloc.c:rb_bhFree() bh == NULL"); rb_lib_log("balloc.c:rb_bhFree() bh == NULL");
return (1); return (1);
} }
if(rb_unlikely(ptr == NULL)) if(rb_unlikely(ptr == NULL)) {
{
rb_lib_log("balloc.rb_bhFree() ptr == NULL"); rb_lib_log("balloc.rb_bhFree() ptr == NULL");
return (1); return (1);
} }
@ -420,8 +404,7 @@ rb_bh_free(rb_bh *bh, void *ptr)
/* XXX */ /* XXX */
if(rb_unlikely if(rb_unlikely
(!((uintptr_t)ptr >= (uintptr_t)block->elems (!((uintptr_t)ptr >= (uintptr_t)block->elems
&& (uintptr_t)ptr < (uintptr_t)block->elems + (uintptr_t)block->alloc_size))) && (uintptr_t)ptr < (uintptr_t)block->elems + (uintptr_t)block->alloc_size))) {
{
rb_bh_fail("rb_bh_free() bogus pointer"); rb_bh_fail("rb_bh_free() bogus pointer");
} }
block->free_count++; block->free_count++;
@ -453,8 +436,7 @@ rb_bh_destroy(rb_bh *bh)
return (1); return (1);
#ifndef NOBALLOC #ifndef NOBALLOC
RB_DLINK_FOREACH_SAFE(ptr, next, bh->block_list.head) RB_DLINK_FOREACH_SAFE(ptr, next, bh->block_list.head) {
{
b = ptr->data; b = ptr->data;
free_block(b->elems, b->alloc_size); free_block(b->elems, b->alloc_size);
rb_free(b); rb_free(b);
@ -474,8 +456,7 @@ rb_bh_usage(rb_bh *bh, size_t *bused, size_t *bfree, size_t *bmemusage, const ch
#ifndef NOBALLOC #ifndef NOBALLOC
size_t used, freem, memusage; size_t used, freem, memusage;
if(bh == NULL) if(bh == NULL) {
{
return; return;
} }
@ -514,8 +495,7 @@ rb_bh_usage_all(rb_bh_usage_cb *cb, void *data)
if(cb == NULL) if(cb == NULL)
return; return;
RB_DLINK_FOREACH(ptr, heap_lists->head) RB_DLINK_FOREACH(ptr, heap_lists->head) {
{
bh = (rb_bh *)ptr->data; bh = (rb_bh *)ptr->data;
freem = rb_dlink_list_length(&bh->free_list); freem = rb_dlink_list_length(&bh->free_list);
used = (rb_dlink_list_length(&bh->block_list) * bh->elemsPerBlock) - freem; used = (rb_dlink_list_length(&bh->block_list) * bh->elemsPerBlock) - freem;
@ -535,8 +515,7 @@ rb_bh_total_usage(size_t *total_alloc, size_t *total_used)
size_t total_memory = 0, used_memory = 0, used, freem; size_t total_memory = 0, used_memory = 0, used, freem;
rb_bh *bh; rb_bh *bh;
RB_DLINK_FOREACH(ptr, heap_lists->head) RB_DLINK_FOREACH(ptr, heap_lists->head) {
{
bh = (rb_bh *)ptr->data; bh = (rb_bh *)ptr->data;
freem = rb_dlink_list_length(&bh->free_list); freem = rb_dlink_list_length(&bh->free_list);
used = (rb_dlink_list_length(&bh->block_list) * bh->elemsPerBlock) - freem; used = (rb_dlink_list_length(&bh->block_list) * bh->elemsPerBlock) - freem;
@ -559,32 +538,27 @@ rb_bh_gc(rb_bh *bh)
unsigned long i; unsigned long i;
uintptr_t offset; uintptr_t offset;
if(bh == NULL) if(bh == NULL) {
{
/* somebody is smoking some craq..(probably lee, but don't tell him that) */ /* somebody is smoking some craq..(probably lee, but don't tell him that) */
return (1); return (1);
} }
if((rb_dlink_list_length(&bh->free_list) < bh->elemsPerBlock) if((rb_dlink_list_length(&bh->free_list) < bh->elemsPerBlock)
|| rb_dlink_list_length(&bh->block_list) == 1) || rb_dlink_list_length(&bh->block_list) == 1) {
{
/* There couldn't possibly be an entire free block. Return. */ /* There couldn't possibly be an entire free block. Return. */
return (0); return (0);
} }
RB_DLINK_FOREACH_SAFE(ptr, next, bh->block_list.head) RB_DLINK_FOREACH_SAFE(ptr, next, bh->block_list.head) {
{
b = ptr->data; b = ptr->data;
if(rb_dlink_list_length(&bh->block_list) == 1) if(rb_dlink_list_length(&bh->block_list) == 1)
return (0); return (0);
if(b->free_count == bh->elemsPerBlock) if(b->free_count == bh->elemsPerBlock) {
{
/* i'm seriously going to hell for this.. */ /* i'm seriously going to hell for this.. */
offset = (uintptr_t)b->elems; offset = (uintptr_t)b->elems;
for(i = 0; i < bh->elemsPerBlock; i++, offset += (uintptr_t)bh->elemSize) for(i = 0; i < bh->elemsPerBlock; i++, offset += (uintptr_t)bh->elemSize) {
{
rb_dlinkDelete((rb_dlink_node *)(offset + offset_pad), rb_dlinkDelete((rb_dlink_node *)(offset + offset_pad),
&bh->free_list); &bh->free_list);
} }

File diff suppressed because it is too large Load Diff

View File

@ -41,10 +41,8 @@ rb_crypt(const char *key, const char *salt)
{ {
/* First, check if we are supposed to be using a replacement /* First, check if we are supposed to be using a replacement
* hash instead of DES... */ * hash instead of DES... */
if(salt[0] == '$' && (salt[2] == '$' || salt[3] == '$')) if(salt[0] == '$' && (salt[2] == '$' || salt[3] == '$')) {
{ switch(salt[1]) {
switch(salt[1])
{
case '1': case '1':
return rb_md5_crypt(key, salt); return rb_md5_crypt(key, salt);
break; break;
@ -62,8 +60,7 @@ rb_crypt(const char *key, const char *salt)
return NULL; return NULL;
break; break;
}; };
} } else
else
return rb_des_crypt(key, salt); return rb_des_crypt(key, salt);
} }
@ -209,42 +206,50 @@ static const uint8_t sbox[8][64] = {
14, 4, 13, 1, 2, 15, 11, 8, 3, 10, 6, 12, 5, 9, 0, 7, 14, 4, 13, 1, 2, 15, 11, 8, 3, 10, 6, 12, 5, 9, 0, 7,
0, 15, 7, 4, 14, 2, 13, 1, 10, 6, 12, 11, 9, 5, 3, 8, 0, 15, 7, 4, 14, 2, 13, 1, 10, 6, 12, 11, 9, 5, 3, 8,
4, 1, 14, 8, 13, 6, 2, 11, 15, 12, 9, 7, 3, 10, 5, 0, 4, 1, 14, 8, 13, 6, 2, 11, 15, 12, 9, 7, 3, 10, 5, 0,
15, 12, 8, 2, 4, 9, 1, 7, 5, 11, 3, 14, 10, 0, 6, 13}, 15, 12, 8, 2, 4, 9, 1, 7, 5, 11, 3, 14, 10, 0, 6, 13
},
{ {
15, 1, 8, 14, 6, 11, 3, 4, 9, 7, 2, 13, 12, 0, 5, 10, 15, 1, 8, 14, 6, 11, 3, 4, 9, 7, 2, 13, 12, 0, 5, 10,
3, 13, 4, 7, 15, 2, 8, 14, 12, 0, 1, 10, 6, 9, 11, 5, 3, 13, 4, 7, 15, 2, 8, 14, 12, 0, 1, 10, 6, 9, 11, 5,
0, 14, 7, 11, 10, 4, 13, 1, 5, 8, 12, 6, 9, 3, 2, 15, 0, 14, 7, 11, 10, 4, 13, 1, 5, 8, 12, 6, 9, 3, 2, 15,
13, 8, 10, 1, 3, 15, 4, 2, 11, 6, 7, 12, 0, 5, 14, 9}, 13, 8, 10, 1, 3, 15, 4, 2, 11, 6, 7, 12, 0, 5, 14, 9
},
{ {
10, 0, 9, 14, 6, 3, 15, 5, 1, 13, 12, 7, 11, 4, 2, 8, 10, 0, 9, 14, 6, 3, 15, 5, 1, 13, 12, 7, 11, 4, 2, 8,
13, 7, 0, 9, 3, 4, 6, 10, 2, 8, 5, 14, 12, 11, 15, 1, 13, 7, 0, 9, 3, 4, 6, 10, 2, 8, 5, 14, 12, 11, 15, 1,
13, 6, 4, 9, 8, 15, 3, 0, 11, 1, 2, 12, 5, 10, 14, 7, 13, 6, 4, 9, 8, 15, 3, 0, 11, 1, 2, 12, 5, 10, 14, 7,
1, 10, 13, 0, 6, 9, 8, 7, 4, 15, 14, 3, 11, 5, 2, 12}, 1, 10, 13, 0, 6, 9, 8, 7, 4, 15, 14, 3, 11, 5, 2, 12
},
{ {
7, 13, 14, 3, 0, 6, 9, 10, 1, 2, 8, 5, 11, 12, 4, 15, 7, 13, 14, 3, 0, 6, 9, 10, 1, 2, 8, 5, 11, 12, 4, 15,
13, 8, 11, 5, 6, 15, 0, 3, 4, 7, 2, 12, 1, 10, 14, 9, 13, 8, 11, 5, 6, 15, 0, 3, 4, 7, 2, 12, 1, 10, 14, 9,
10, 6, 9, 0, 12, 11, 7, 13, 15, 1, 3, 14, 5, 2, 8, 4, 10, 6, 9, 0, 12, 11, 7, 13, 15, 1, 3, 14, 5, 2, 8, 4,
3, 15, 0, 6, 10, 1, 13, 8, 9, 4, 5, 11, 12, 7, 2, 14}, 3, 15, 0, 6, 10, 1, 13, 8, 9, 4, 5, 11, 12, 7, 2, 14
},
{ {
2, 12, 4, 1, 7, 10, 11, 6, 8, 5, 3, 15, 13, 0, 14, 9, 2, 12, 4, 1, 7, 10, 11, 6, 8, 5, 3, 15, 13, 0, 14, 9,
14, 11, 2, 12, 4, 7, 13, 1, 5, 0, 15, 10, 3, 9, 8, 6, 14, 11, 2, 12, 4, 7, 13, 1, 5, 0, 15, 10, 3, 9, 8, 6,
4, 2, 1, 11, 10, 13, 7, 8, 15, 9, 12, 5, 6, 3, 0, 14, 4, 2, 1, 11, 10, 13, 7, 8, 15, 9, 12, 5, 6, 3, 0, 14,
11, 8, 12, 7, 1, 14, 2, 13, 6, 15, 0, 9, 10, 4, 5, 3}, 11, 8, 12, 7, 1, 14, 2, 13, 6, 15, 0, 9, 10, 4, 5, 3
},
{ {
12, 1, 10, 15, 9, 2, 6, 8, 0, 13, 3, 4, 14, 7, 5, 11, 12, 1, 10, 15, 9, 2, 6, 8, 0, 13, 3, 4, 14, 7, 5, 11,
10, 15, 4, 2, 7, 12, 9, 5, 6, 1, 13, 14, 0, 11, 3, 8, 10, 15, 4, 2, 7, 12, 9, 5, 6, 1, 13, 14, 0, 11, 3, 8,
9, 14, 15, 5, 2, 8, 12, 3, 7, 0, 4, 10, 1, 13, 11, 6, 9, 14, 15, 5, 2, 8, 12, 3, 7, 0, 4, 10, 1, 13, 11, 6,
4, 3, 2, 12, 9, 5, 15, 10, 11, 14, 1, 7, 6, 0, 8, 13}, 4, 3, 2, 12, 9, 5, 15, 10, 11, 14, 1, 7, 6, 0, 8, 13
},
{ {
4, 11, 2, 14, 15, 0, 8, 13, 3, 12, 9, 7, 5, 10, 6, 1, 4, 11, 2, 14, 15, 0, 8, 13, 3, 12, 9, 7, 5, 10, 6, 1,
13, 0, 11, 7, 4, 9, 1, 10, 14, 3, 5, 12, 2, 15, 8, 6, 13, 0, 11, 7, 4, 9, 1, 10, 14, 3, 5, 12, 2, 15, 8, 6,
1, 4, 11, 13, 12, 3, 7, 14, 10, 15, 6, 8, 0, 5, 9, 2, 1, 4, 11, 13, 12, 3, 7, 14, 10, 15, 6, 8, 0, 5, 9, 2,
6, 11, 13, 8, 1, 4, 10, 7, 9, 5, 0, 15, 14, 2, 3, 12}, 6, 11, 13, 8, 1, 4, 10, 7, 9, 5, 0, 15, 14, 2, 3, 12
},
{ {
13, 2, 8, 4, 6, 15, 11, 1, 10, 9, 3, 14, 5, 0, 12, 7, 13, 2, 8, 4, 6, 15, 11, 1, 10, 9, 3, 14, 5, 0, 12, 7,
1, 15, 13, 8, 10, 3, 7, 4, 12, 5, 6, 11, 0, 14, 9, 2, 1, 15, 13, 8, 10, 3, 7, 4, 12, 5, 6, 11, 0, 14, 9, 2,
7, 11, 4, 1, 9, 12, 14, 2, 0, 6, 10, 13, 15, 3, 5, 8, 7, 11, 4, 1, 9, 12, 14, 2, 0, 6, 10, 13, 15, 3, 5, 8,
2, 1, 14, 7, 4, 10, 8, 13, 15, 12, 9, 0, 3, 5, 6, 11} 2, 1, 14, 7, 4, 10, 8, 13, 15, 12, 9, 0, 3, 5, 6, 11
}
}; };
static const uint8_t pbox[32] = { static const uint8_t pbox[32] = {
@ -305,8 +310,7 @@ rb_des_init(void)
* Invert the S-boxes, reordering the input bits. * Invert the S-boxes, reordering the input bits.
*/ */
for(i = 0; i < 8; i++) for(i = 0; i < 8; i++)
for(j = 0; j < 64; j++) for(j = 0; j < 64; j++) {
{
b = (j & 0x20) | ((j & 1) << 4) | ((j >> 1) & 0xf); b = (j & 0x20) | ((j & 1) << 4) | ((j >> 1) & 0xf);
u_sbox[i][j] = sbox[i][b]; u_sbox[i][j] = sbox[i][b];
} }
@ -326,8 +330,7 @@ rb_des_init(void)
* Set up the initial & final permutations into a useful form, and * Set up the initial & final permutations into a useful form, and
* initialise the inverted key permutation. * initialise the inverted key permutation.
*/ */
for(i = 0; i < 64; i++) for(i = 0; i < 64; i++) {
{
init_perm[final_perm[i] = IP[i] - 1] = (uint8_t)i; init_perm[final_perm[i] = IP[i] - 1] = (uint8_t)i;
inv_key_perm[i] = 255; inv_key_perm[i] = 255;
} }
@ -336,8 +339,7 @@ rb_des_init(void)
* Invert the key permutation and initialise the inverted key * Invert the key permutation and initialise the inverted key
* compression permutation. * compression permutation.
*/ */
for(i = 0; i < 56; i++) for(i = 0; i < 56; i++) {
{
inv_key_perm[key_perm[i] - 1] = (uint8_t)i; inv_key_perm[key_perm[i] - 1] = (uint8_t)i;
inv_comp_perm[i] = 255; inv_comp_perm[i] = 255;
} }
@ -345,8 +347,7 @@ rb_des_init(void)
/* /*
* Invert the key compression permutation. * Invert the key compression permutation.
*/ */
for(i = 0; i < 48; i++) for(i = 0; i < 48; i++) {
{
inv_comp_perm[comp_perm[i] - 1] = (uint8_t)i; inv_comp_perm[comp_perm[i] - 1] = (uint8_t)i;
} }
@ -354,19 +355,15 @@ rb_des_init(void)
* Set up the OR-mask arrays for the initial and final permutations, * Set up the OR-mask arrays for the initial and final permutations,
* and for the key initial and compression permutations. * and for the key initial and compression permutations.
*/ */
for(k = 0; k < 8; k++) for(k = 0; k < 8; k++) {
{ for(i = 0; i < 256; i++) {
for(i = 0; i < 256; i++)
{
*(il = &ip_maskl[k][i]) = 0L; *(il = &ip_maskl[k][i]) = 0L;
*(ir = &ip_maskr[k][i]) = 0L; *(ir = &ip_maskr[k][i]) = 0L;
*(fl = &fp_maskl[k][i]) = 0L; *(fl = &fp_maskl[k][i]) = 0L;
*(fr = &fp_maskr[k][i]) = 0L; *(fr = &fp_maskr[k][i]) = 0L;
for(j = 0; j < 8; j++) for(j = 0; j < 8; j++) {
{
inbit = 8 * k + j; inbit = 8 * k + j;
if(i & bits8[j]) if(i & bits8[j]) {
{
if((obit = init_perm[inbit]) < 32) if((obit = init_perm[inbit]) < 32)
*il |= bits32[obit]; *il |= bits32[obit];
else else
@ -378,15 +375,12 @@ rb_des_init(void)
} }
} }
} }
for(i = 0; i < 128; i++) for(i = 0; i < 128; i++) {
{
*(il = &key_perm_maskl[k][i]) = 0L; *(il = &key_perm_maskl[k][i]) = 0L;
*(ir = &key_perm_maskr[k][i]) = 0L; *(ir = &key_perm_maskr[k][i]) = 0L;
for(j = 0; j < 7; j++) for(j = 0; j < 7; j++) {
{
inbit = 8 * k + j; inbit = 8 * k + j;
if(i & bits8[j + 1]) if(i & bits8[j + 1]) {
{
if((obit = inv_key_perm[inbit]) == 255) if((obit = inv_key_perm[inbit]) == 255)
continue; continue;
if(obit < 28) if(obit < 28)
@ -397,11 +391,9 @@ rb_des_init(void)
} }
*(il = &comp_maskl[k][i]) = 0L; *(il = &comp_maskl[k][i]) = 0L;
*(ir = &comp_maskr[k][i]) = 0L; *(ir = &comp_maskr[k][i]) = 0L;
for(j = 0; j < 7; j++) for(j = 0; j < 7; j++) {
{
inbit = 7 * k + j; inbit = 7 * k + j;
if(i & bits8[j + 1]) if(i & bits8[j + 1]) {
{
if((obit = inv_comp_perm[inbit]) == 255) if((obit = inv_comp_perm[inbit]) == 255)
continue; continue;
if(obit < 24) if(obit < 24)
@ -421,11 +413,9 @@ rb_des_init(void)
un_pbox[pbox[i] - 1] = (uint8_t)i; un_pbox[pbox[i] - 1] = (uint8_t)i;
for(b = 0; b < 4; b++) for(b = 0; b < 4; b++)
for(i = 0; i < 256; i++) for(i = 0; i < 256; i++) {
{
*(p = &psbox[b][i]) = 0L; *(p = &psbox[b][i]) = 0L;
for(j = 0; j < 8; j++) for(j = 0; j < 8; j++) {
{
if(i & bits8[j]) if(i & bits8[j])
*p |= bits32[un_pbox[8 * b + j]]; *p |= bits32[un_pbox[8 * b + j]];
} }
@ -448,8 +438,7 @@ rb_setup_salt(long salt)
saltbits = 0L; saltbits = 0L;
saltbit = 1; saltbit = 1;
obit = 0x800000; obit = 0x800000;
for(i = 0; i < 24; i++) for(i = 0; i < 24; i++) {
{
if(salt & saltbit) if(salt & saltbit)
saltbits |= obit; saltbits |= obit;
saltbit <<= 1; saltbit <<= 1;
@ -468,8 +457,7 @@ rb_des_setkey(const char *key)
rawkey0 = ntohl(*(const uint32_t *)key); rawkey0 = ntohl(*(const uint32_t *)key);
rawkey1 = ntohl(*(const uint32_t *)(key + 4)); rawkey1 = ntohl(*(const uint32_t *)(key + 4));
if((rawkey0 | rawkey1) && rawkey0 == old_rawkey0 && rawkey1 == old_rawkey1) if((rawkey0 | rawkey1) && rawkey0 == old_rawkey0 && rawkey1 == old_rawkey1) {
{
/* /*
* Already setup for this key. * Already setup for this key.
* This optimisation fails on a zero key (which is weak and * This optimisation fails on a zero key (which is weak and
@ -504,8 +492,7 @@ rb_des_setkey(const char *key)
* Rotate subkeys and do compression permutation. * Rotate subkeys and do compression permutation.
*/ */
shifts = 0; shifts = 0;
for(round = 0; round < 16; round++) for(round = 0; round < 16; round++) {
{
uint32_t t0, t1; uint32_t t0, t1;
shifts += key_shifts[round]; shifts += key_shifts[round];
@ -544,20 +531,15 @@ rb_do_des(uint32_t l_in, uint32_t r_in, uint32_t *l_out, uint32_t *r_out, int co
uint32_t f, r48l, r48r; uint32_t f, r48l, r48r;
int round; int round;
if(count == 0) if(count == 0) {
{
return (1); return (1);
} } else if(count > 0) {
else if(count > 0)
{
/* /*
* Encrypting * Encrypting
*/ */
kl1 = en_keysl; kl1 = en_keysl;
kr1 = en_keysr; kr1 = en_keysr;
} } else {
else
{
/* /*
* Decrypting * Decrypting
*/ */
@ -584,16 +566,14 @@ rb_do_des(uint32_t l_in, uint32_t r_in, uint32_t *l_out, uint32_t *r_out, int co
| ip_maskr[5][(r_in >> 16) & 0xff] | ip_maskr[5][(r_in >> 16) & 0xff]
| ip_maskr[6][(r_in >> 8) & 0xff] | ip_maskr[7][r_in & 0xff]; | ip_maskr[6][(r_in >> 8) & 0xff] | ip_maskr[7][r_in & 0xff];
while(count--) while(count--) {
{
/* /*
* Do each round. * Do each round.
*/ */
kl = kl1; kl = kl1;
kr = kr1; kr = kr1;
round = 16; round = 16;
while(round--) while(round--) {
{
/* /*
* Expand R to 48 bits (simulate the E-box). * Expand R to 48 bits (simulate the E-box).
*/ */
@ -665,8 +645,7 @@ rb_des_crypt(const char *key, const char *setting)
* and padding with zeros. * and padding with zeros.
*/ */
q = (uint8_t *)keybuf; q = (uint8_t *)keybuf;
while(q - (uint8_t *)keybuf - 8) while(q - (uint8_t *)keybuf - 8) {
{
*q++ = *key << 1; *q++ = *key << 1;
if(*(q - 1)) if(*(q - 1))
key++; key++;
@ -859,7 +838,7 @@ static unsigned char PADDING[64] = {
static void static void
MD5Init (context) MD5Init (context)
MD5_CTX *context; MD5_CTX *context;
{ {
context->count[0] = context->count[1] = 0; context->count[0] = context->count[1] = 0;
@ -879,9 +858,9 @@ MD5Init (context)
static void static void
MD5Update (context, in, inputLen) MD5Update (context, in, inputLen)
MD5_CTX *context; MD5_CTX *context;
const void *in; const void *in;
unsigned int inputLen; unsigned int inputLen;
{ {
unsigned int i, idx, partLen; unsigned int i, idx, partLen;
const unsigned char *input = in; const unsigned char *input = in;
@ -907,8 +886,7 @@ MD5Update (context, in, inputLen)
MD5Transform (context->state, &input[i]); MD5Transform (context->state, &input[i]);
idx = 0; idx = 0;
} } else
else
i = 0; i = 0;
/* Buffer remaining input */ /* Buffer remaining input */
@ -922,7 +900,7 @@ MD5Update (context, in, inputLen)
static void static void
MD5Pad (context) MD5Pad (context)
MD5_CTX *context; MD5_CTX *context;
{ {
unsigned char bits[8]; unsigned char bits[8];
unsigned int idx, padLen; unsigned int idx, padLen;
@ -946,8 +924,8 @@ MD5Pad (context)
static void static void
MD5Final (digest, context) MD5Final (digest, context)
unsigned char digest[16]; unsigned char digest[16];
MD5_CTX *context; MD5_CTX *context;
{ {
/* Do padding. */ /* Do padding. */
MD5Pad (context); MD5Pad (context);
@ -963,8 +941,8 @@ MD5Final (digest, context)
static void static void
MD5Transform (state, block) MD5Transform (state, block)
uint32_t state[4]; uint32_t state[4];
const unsigned char block[64]; const unsigned char block[64];
{ {
uint32_t a = state[0], b = state[1], c = state[2], d = state[3], x[16]; uint32_t a = state[0], b = state[1], c = state[2], d = state[3], x[16];
@ -1163,17 +1141,23 @@ rb_md5_crypt(const char *pw, const char *salt)
p = passwd + strlen(passwd); p = passwd + strlen(passwd);
l = (final[ 0]<<16) | (final[ 6]<<8) | final[12]; l = (final[ 0]<<16) | (final[ 6]<<8) | final[12];
_crypt_to64(p, l, 4); p += 4; _crypt_to64(p, l, 4);
p += 4;
l = (final[ 1]<<16) | (final[ 7]<<8) | final[13]; l = (final[ 1]<<16) | (final[ 7]<<8) | final[13];
_crypt_to64(p, l, 4); p += 4; _crypt_to64(p, l, 4);
p += 4;
l = (final[ 2]<<16) | (final[ 8]<<8) | final[14]; l = (final[ 2]<<16) | (final[ 8]<<8) | final[14];
_crypt_to64(p, l, 4); p += 4; _crypt_to64(p, l, 4);
p += 4;
l = (final[ 3]<<16) | (final[ 9]<<8) | final[15]; l = (final[ 3]<<16) | (final[ 9]<<8) | final[15];
_crypt_to64(p, l, 4); p += 4; _crypt_to64(p, l, 4);
p += 4;
l = (final[ 4]<<16) | (final[10]<<8) | final[ 5]; l = (final[ 4]<<16) | (final[10]<<8) | final[ 5];
_crypt_to64(p, l, 4); p += 4; _crypt_to64(p, l, 4);
p += 4;
l = final[11]; l = final[11];
_crypt_to64(p, l, 2); p += 2; _crypt_to64(p, l, 2);
p += 2;
*p = '\0'; *p = '\0';
/* Don't leave anything around in vm they could use. */ /* Don't leave anything around in vm they could use. */
@ -1187,8 +1171,7 @@ rb_md5_crypt(const char *pw, const char *salt)
Released into the Public Domain by Ulrich Drepper <drepper@redhat.com>. */ Released into the Public Domain by Ulrich Drepper <drepper@redhat.com>. */
/* Structure to save state of computation between the single steps. */ /* Structure to save state of computation between the single steps. */
struct sha256_ctx struct sha256_ctx {
{
uint32_t H[8]; uint32_t H[8];
uint32_t total[2]; uint32_t total[2];
@ -1253,8 +1236,7 @@ static void rb_sha256_process_block(const void *buffer, size_t len, struct sha25
/* Process all bytes in the buffer with 64 bytes in each round of /* Process all bytes in the buffer with 64 bytes in each round of
the loop. */ the loop. */
while (nwords > 0) while (nwords > 0) {
{
uint32_t W[64]; uint32_t W[64];
uint32_t a_save = a; uint32_t a_save = a;
uint32_t b_save = b; uint32_t b_save = b;
@ -1267,20 +1249,19 @@ static void rb_sha256_process_block(const void *buffer, size_t len, struct sha25
unsigned int t; unsigned int t;
/* Operators defined in FIPS 180-2:4.1.2. */ /* Operators defined in FIPS 180-2:4.1.2. */
#define SHA256_Ch(x, y, z) ((x & y) ^ (~x & z)) #define SHA256_Ch(x, y, z) ((x & y) ^ (~x & z))
#define SHA256_Maj(x, y, z) ((x & y) ^ (x & z) ^ (y & z)) #define SHA256_Maj(x, y, z) ((x & y) ^ (x & z) ^ (y & z))
#define SHA256_S0(x) (SHA256_CYCLIC (x, 2) ^ SHA256_CYCLIC (x, 13) ^ SHA256_CYCLIC (x, 22)) #define SHA256_S0(x) (SHA256_CYCLIC (x, 2) ^ SHA256_CYCLIC (x, 13) ^ SHA256_CYCLIC (x, 22))
#define SHA256_S1(x) (SHA256_CYCLIC (x, 6) ^ SHA256_CYCLIC (x, 11) ^ SHA256_CYCLIC (x, 25)) #define SHA256_S1(x) (SHA256_CYCLIC (x, 6) ^ SHA256_CYCLIC (x, 11) ^ SHA256_CYCLIC (x, 25))
#define SHA256_R0(x) (SHA256_CYCLIC (x, 7) ^ SHA256_CYCLIC (x, 18) ^ (x >> 3)) #define SHA256_R0(x) (SHA256_CYCLIC (x, 7) ^ SHA256_CYCLIC (x, 18) ^ (x >> 3))
#define SHA256_R1(x) (SHA256_CYCLIC (x, 17) ^ SHA256_CYCLIC (x, 19) ^ (x >> 10)) #define SHA256_R1(x) (SHA256_CYCLIC (x, 17) ^ SHA256_CYCLIC (x, 19) ^ (x >> 10))
/* It is unfortunate that C does not provide an operator for /* It is unfortunate that C does not provide an operator for
cyclic rotation. Hope the C compiler is smart enough. */ cyclic rotation. Hope the C compiler is smart enough. */
#define SHA256_CYCLIC(w, s) ((w >> s) | (w << (32 - s))) #define SHA256_CYCLIC(w, s) ((w >> s) | (w << (32 - s)))
/* Compute the message schedule according to FIPS 180-2:6.2.2 step 2. */ /* Compute the message schedule according to FIPS 180-2:6.2.2 step 2. */
for (t = 0; t < 16; ++t) for (t = 0; t < 16; ++t) {
{
W[t] = SHA256_SWAP(*words); W[t] = SHA256_SWAP(*words);
++words; ++words;
} }
@ -1288,8 +1269,7 @@ static void rb_sha256_process_block(const void *buffer, size_t len, struct sha25
W[t] = SHA256_R1(W[t - 2]) + W[t - 7] + SHA256_R0(W[t - 15]) + W[t - 16]; W[t] = SHA256_R1(W[t - 2]) + W[t - 7] + SHA256_R0(W[t - 15]) + W[t - 16];
/* The actual computation according to FIPS 180-2:6.2.2 step 3. */ /* The actual computation according to FIPS 180-2:6.2.2 step 3. */
for (t = 0; t < 64; ++t) for (t = 0; t < 64; ++t) {
{
uint32_t T1 = h + SHA256_S1(e) + SHA256_Ch(e, f, g) + SHA256_K[t] + W[t]; uint32_t T1 = h + SHA256_S1(e) + SHA256_Ch(e, f, g) + SHA256_K[t] + W[t];
uint32_t T2 = SHA256_S0(a) + SHA256_Maj(a, b, c); uint32_t T2 = SHA256_S0(a) + SHA256_Maj(a, b, c);
h = g; h = g;
@ -1387,16 +1367,14 @@ static void rb_sha256_process_bytes(const void *buffer, size_t len, struct sha25
{ {
/* When we already have some bits in our internal buffer concatenate /* When we already have some bits in our internal buffer concatenate
both inputs first. */ both inputs first. */
if (ctx->buflen != 0) if (ctx->buflen != 0) {
{
size_t left_over = ctx->buflen; size_t left_over = ctx->buflen;
size_t add = 128 - left_over > len ? len : 128 - left_over; size_t add = 128 - left_over > len ? len : 128 - left_over;
memcpy(&ctx->buffer[left_over], buffer, add); memcpy(&ctx->buffer[left_over], buffer, add);
ctx->buflen += add; ctx->buflen += add;
if (ctx->buflen > 64) if (ctx->buflen > 64) {
{
rb_sha256_process_block(ctx->buffer, ctx->buflen & ~63, ctx); rb_sha256_process_block(ctx->buffer, ctx->buflen & ~63, ctx);
ctx->buflen &= 63; ctx->buflen &= 63;
@ -1409,24 +1387,21 @@ static void rb_sha256_process_bytes(const void *buffer, size_t len, struct sha25
} }
/* Process available complete blocks. */ /* Process available complete blocks. */
if (len >= 64) if (len >= 64) {
{
/* To check alignment gcc has an appropriate operator. Other /* To check alignment gcc has an appropriate operator. Other
compilers don't. */ compilers don't. */
#if __GNUC__ >= 2 #if __GNUC__ >= 2
# define SHA256_UNALIGNED_P(p) (((uintptr_t) p) % __alignof__ (uint32_t) != 0) # define SHA256_UNALIGNED_P(p) (((uintptr_t) p) % __alignof__ (uint32_t) != 0)
#else #else
# define SHA256_UNALIGNED_P(p) (((uintptr_t) p) % sizeof (uint32_t) != 0) # define SHA256_UNALIGNED_P(p) (((uintptr_t) p) % sizeof (uint32_t) != 0)
#endif #endif
if (SHA256_UNALIGNED_P(buffer)) if (SHA256_UNALIGNED_P(buffer))
while (len > 64) while (len > 64) {
{
rb_sha256_process_block(memcpy(ctx->buffer, buffer, 64), 64, ctx); rb_sha256_process_block(memcpy(ctx->buffer, buffer, 64), 64, ctx);
buffer = (const char *)buffer + 64; buffer = (const char *)buffer + 64;
len -= 64; len -= 64;
} }
else else {
{
rb_sha256_process_block(buffer, len & ~63, ctx); rb_sha256_process_block(buffer, len & ~63, ctx);
buffer = (const char *)buffer + (len & ~63); buffer = (const char *)buffer + (len & ~63);
len &= 63; len &= 63;
@ -1434,14 +1409,12 @@ static void rb_sha256_process_bytes(const void *buffer, size_t len, struct sha25
} }
/* Move remaining bytes into internal buffer. */ /* Move remaining bytes into internal buffer. */
if (len > 0) if (len > 0) {
{
size_t left_over = ctx->buflen; size_t left_over = ctx->buflen;
memcpy(&ctx->buffer[left_over], buffer, len); memcpy(&ctx->buffer[left_over], buffer, len);
left_over += len; left_over += len;
if (left_over >= 64) if (left_over >= 64) {
{
rb_sha256_process_block(ctx->buffer, 64, ctx); rb_sha256_process_block(ctx->buffer, 64, ctx);
left_over -= 64; left_over -= 64;
memcpy(ctx->buffer, &ctx->buffer[64], left_over); memcpy(ctx->buffer, &ctx->buffer[64], left_over);
@ -1491,13 +1464,11 @@ static char *rb_sha256_crypt_r(const char *key, const char *salt, char *buffer,
/* Skip salt prefix. */ /* Skip salt prefix. */
salt += sizeof(sha256_salt_prefix) - 1; salt += sizeof(sha256_salt_prefix) - 1;
if (strncmp(salt, sha256_rounds_prefix, sizeof(sha256_rounds_prefix) - 1) == 0) if (strncmp(salt, sha256_rounds_prefix, sizeof(sha256_rounds_prefix) - 1) == 0) {
{
const char *num = salt + sizeof(sha256_rounds_prefix) - 1; const char *num = salt + sizeof(sha256_rounds_prefix) - 1;
char *endp; char *endp;
unsigned long int srounds = strtoul(num, &endp, 10); unsigned long int srounds = strtoul(num, &endp, 10);
if (*endp == '$') if (*endp == '$') {
{
salt = endp + 1; salt = endp + 1;
rounds = MAX(SHA256_ROUNDS_MIN, MIN(srounds, SHA256_ROUNDS_MAX)); rounds = MAX(SHA256_ROUNDS_MIN, MIN(srounds, SHA256_ROUNDS_MAX));
rounds_custom = 1; rounds_custom = 1;
@ -1507,16 +1478,14 @@ static char *rb_sha256_crypt_r(const char *key, const char *salt, char *buffer,
salt_len = MIN(strcspn(salt, "$"), SHA256_SALT_LEN_MAX); salt_len = MIN(strcspn(salt, "$"), SHA256_SALT_LEN_MAX);
key_len = strlen(key); key_len = strlen(key);
if ((key - (char *)0) % __alignof__(uint32_t) != 0) if ((key - (char *)0) % __alignof__(uint32_t) != 0) {
{
char *tmp = (char *)alloca(key_len + __alignof__(uint32_t)); char *tmp = (char *)alloca(key_len + __alignof__(uint32_t));
key = copied_key = key = copied_key =
memcpy(tmp + __alignof__(uint32_t) memcpy(tmp + __alignof__(uint32_t)
- (tmp - (char *)0) % __alignof__(uint32_t), key, key_len); - (tmp - (char *)0) % __alignof__(uint32_t), key, key_len);
} }
if ((salt - (char *)0) % __alignof__(uint32_t) != 0) if ((salt - (char *)0) % __alignof__(uint32_t) != 0) {
{
char *tmp = (char *)alloca(salt_len + __alignof__(uint32_t)); char *tmp = (char *)alloca(salt_len + __alignof__(uint32_t));
salt = copied_salt = salt = copied_salt =
memcpy(tmp + __alignof__(uint32_t) memcpy(tmp + __alignof__(uint32_t)
@ -1580,8 +1549,7 @@ static char *rb_sha256_crypt_r(const char *key, const char *salt, char *buffer,
/* Create byte sequence P. */ /* Create byte sequence P. */
cp = p_bytes = alloca(key_len); cp = p_bytes = alloca(key_len);
for (cnt = key_len; cnt >= 32; cnt -= 32) for (cnt = key_len; cnt >= 32; cnt -= 32) {
{
memcpy(cp, temp_result, 32); memcpy(cp, temp_result, 32);
cp += 32; cp += 32;
} }
@ -1599,8 +1567,7 @@ static char *rb_sha256_crypt_r(const char *key, const char *salt, char *buffer,
/* Create byte sequence S. */ /* Create byte sequence S. */
cp = s_bytes = alloca(salt_len); cp = s_bytes = alloca(salt_len);
for (cnt = salt_len; cnt >= 32; cnt -= 32) for (cnt = salt_len; cnt >= 32; cnt -= 32) {
{
memcpy(cp, temp_result, 32); memcpy(cp, temp_result, 32);
cp += 32; cp += 32;
} }
@ -1608,8 +1575,7 @@ static char *rb_sha256_crypt_r(const char *key, const char *salt, char *buffer,
/* Repeatedly run the collected hash value through SHA256 to burn /* Repeatedly run the collected hash value through SHA256 to burn
CPU cycles. */ CPU cycles. */
for (cnt = 0; cnt < rounds; ++cnt) for (cnt = 0; cnt < rounds; ++cnt) {
{
/* New context. */ /* New context. */
rb_sha256_init_ctx(&ctx); rb_sha256_init_ctx(&ctx);
@ -1645,8 +1611,7 @@ static char *rb_sha256_crypt_r(const char *key, const char *salt, char *buffer,
cp = buffer + MAX(0, buflen); cp = buffer + MAX(0, buflen);
buflen -= sizeof(sha256_salt_prefix) - 1; buflen -= sizeof(sha256_salt_prefix) - 1;
if (rounds_custom) if (rounds_custom) {
{
int n = snprintf(cp, MAX(0, buflen), "%s%zu$", int n = snprintf(cp, MAX(0, buflen), "%s%zu$",
sha256_rounds_prefix, rounds); sha256_rounds_prefix, rounds);
cp += n; cp += n;
@ -1659,8 +1624,7 @@ static char *rb_sha256_crypt_r(const char *key, const char *salt, char *buffer,
cp += salt_len; cp += salt_len;
buflen -= MIN((size_t) MAX(0, buflen), salt_len); buflen -= MIN((size_t) MAX(0, buflen), salt_len);
if (buflen > 0) if (buflen > 0) {
{
*cp++ = '$'; *cp++ = '$';
--buflen; --buflen;
} }
@ -1676,12 +1640,10 @@ static char *rb_sha256_crypt_r(const char *key, const char *salt, char *buffer,
b64_from_24bit(alt_result[18], alt_result[28], alt_result[8], 4); b64_from_24bit(alt_result[18], alt_result[28], alt_result[8], 4);
b64_from_24bit(alt_result[9], alt_result[19], alt_result[29], 4); b64_from_24bit(alt_result[9], alt_result[19], alt_result[29], 4);
b64_from_24bit(0, alt_result[31], alt_result[30], 3); b64_from_24bit(0, alt_result[31], alt_result[30], 3);
if (buflen <= 0) if (buflen <= 0) {
{
errno = ERANGE; errno = ERANGE;
buffer = NULL; buffer = NULL;
} } else
else
*cp = '\0'; /* Terminate the string. */ *cp = '\0'; /* Terminate the string. */
/* Clear the buffer for the intermediate result so that people /* Clear the buffer for the intermediate result so that people
@ -1728,8 +1690,7 @@ static char *rb_sha256_crypt(const char *key, const char *salt)
} }
/* Structure to save state of computation between the single steps. */ /* Structure to save state of computation between the single steps. */
struct sha512_ctx struct sha512_ctx {
{
uint64_t H[8]; uint64_t H[8];
uint64_t total[2]; uint64_t total[2];
@ -1827,8 +1788,7 @@ static void rb_sha512_process_block(const void *buffer, size_t len, struct sha51
/* Process all bytes in the buffer with 128 bytes in each round of /* Process all bytes in the buffer with 128 bytes in each round of
the loop. */ the loop. */
while (nwords > 0) while (nwords > 0) {
{
uint64_t W[80]; uint64_t W[80];
uint64_t a_save = a; uint64_t a_save = a;
uint64_t b_save = b; uint64_t b_save = b;
@ -1841,20 +1801,19 @@ static void rb_sha512_process_block(const void *buffer, size_t len, struct sha51
unsigned int t; unsigned int t;
/* Operators defined in FIPS 180-2:4.1.2. */ /* Operators defined in FIPS 180-2:4.1.2. */
#define SHA512_Ch(x, y, z) ((x & y) ^ (~x & z)) #define SHA512_Ch(x, y, z) ((x & y) ^ (~x & z))
#define SHA512_Maj(x, y, z) ((x & y) ^ (x & z) ^ (y & z)) #define SHA512_Maj(x, y, z) ((x & y) ^ (x & z) ^ (y & z))
#define SHA512_S0(x) (SHA512_CYCLIC (x, 28) ^ SHA512_CYCLIC (x, 34) ^ SHA512_CYCLIC (x, 39)) #define SHA512_S0(x) (SHA512_CYCLIC (x, 28) ^ SHA512_CYCLIC (x, 34) ^ SHA512_CYCLIC (x, 39))
#define SHA512_S1(x) (SHA512_CYCLIC (x, 14) ^ SHA512_CYCLIC (x, 18) ^ SHA512_CYCLIC (x, 41)) #define SHA512_S1(x) (SHA512_CYCLIC (x, 14) ^ SHA512_CYCLIC (x, 18) ^ SHA512_CYCLIC (x, 41))
#define SHA512_R0(x) (SHA512_CYCLIC (x, 1) ^ SHA512_CYCLIC (x, 8) ^ (x >> 7)) #define SHA512_R0(x) (SHA512_CYCLIC (x, 1) ^ SHA512_CYCLIC (x, 8) ^ (x >> 7))
#define SHA512_R1(x) (SHA512_CYCLIC (x, 19) ^ SHA512_CYCLIC (x, 61) ^ (x >> 6)) #define SHA512_R1(x) (SHA512_CYCLIC (x, 19) ^ SHA512_CYCLIC (x, 61) ^ (x >> 6))
/* It is unfortunate that C does not provide an operator for /* It is unfortunate that C does not provide an operator for
cyclic rotation. Hope the C compiler is smart enough. */ cyclic rotation. Hope the C compiler is smart enough. */
#define SHA512_CYCLIC(w, s) ((w >> s) | (w << (64 - s))) #define SHA512_CYCLIC(w, s) ((w >> s) | (w << (64 - s)))
/* Compute the message schedule according to FIPS 180-2:6.3.2 step 2. */ /* Compute the message schedule according to FIPS 180-2:6.3.2 step 2. */
for (t = 0; t < 16; ++t) for (t = 0; t < 16; ++t) {
{
W[t] = SHA512_SWAP(*words); W[t] = SHA512_SWAP(*words);
++words; ++words;
} }
@ -1862,8 +1821,7 @@ static void rb_sha512_process_block(const void *buffer, size_t len, struct sha51
W[t] = SHA512_R1(W[t - 2]) + W[t - 7] + SHA512_R0(W[t - 15]) + W[t - 16]; W[t] = SHA512_R1(W[t - 2]) + W[t - 7] + SHA512_R0(W[t - 15]) + W[t - 16];
/* The actual computation according to FIPS 180-2:6.3.2 step 3. */ /* The actual computation according to FIPS 180-2:6.3.2 step 3. */
for (t = 0; t < 80; ++t) for (t = 0; t < 80; ++t) {
{
uint64_t T1 = h + SHA512_S1(e) + SHA512_Ch(e, f, g) + SHA512_K[t] + W[t]; uint64_t T1 = h + SHA512_S1(e) + SHA512_Ch(e, f, g) + SHA512_K[t] + W[t];
uint64_t T2 = SHA512_S0(a) + SHA512_Maj(a, b, c); uint64_t T2 = SHA512_S0(a) + SHA512_Maj(a, b, c);
h = g; h = g;
@ -1961,16 +1919,14 @@ static void rb_sha512_process_bytes(const void *buffer, size_t len, struct sha51
{ {
/* When we already have some bits in our internal buffer concatenate /* When we already have some bits in our internal buffer concatenate
both inputs first. */ both inputs first. */
if (ctx->buflen != 0) if (ctx->buflen != 0) {
{
size_t left_over = ctx->buflen; size_t left_over = ctx->buflen;
size_t add = 256 - left_over > len ? len : 256 - left_over; size_t add = 256 - left_over > len ? len : 256 - left_over;
memcpy(&ctx->buffer[left_over], buffer, add); memcpy(&ctx->buffer[left_over], buffer, add);
ctx->buflen += add; ctx->buflen += add;
if (ctx->buflen > 128) if (ctx->buflen > 128) {
{
rb_sha512_process_block(ctx->buffer, ctx->buflen & ~127, ctx); rb_sha512_process_block(ctx->buffer, ctx->buflen & ~127, ctx);
ctx->buflen &= 127; ctx->buflen &= 127;
@ -1983,25 +1939,23 @@ static void rb_sha512_process_bytes(const void *buffer, size_t len, struct sha51
} }
/* Process available complete blocks. */ /* Process available complete blocks. */
if (len >= 128) if (len >= 128) {
{ #if !_STRING_ARCH_unaligned
#if !_STRING_ARCH_unaligned
/* To check alignment gcc has an appropriate operator. Other /* To check alignment gcc has an appropriate operator. Other
compilers don't. */ compilers don't. */
# if __GNUC__ >= 2 # if __GNUC__ >= 2
# define SHA512_UNALIGNED_P(p) (((uintptr_t) p) % __alignof__ (uint64_t) != 0) # define SHA512_UNALIGNED_P(p) (((uintptr_t) p) % __alignof__ (uint64_t) != 0)
# else # else
# define SHA512_UNALIGNED_P(p) (((uintptr_t) p) % sizeof (uint64_t) != 0) # define SHA512_UNALIGNED_P(p) (((uintptr_t) p) % sizeof (uint64_t) != 0)
# endif # endif
if (SHA512_UNALIGNED_P(buffer)) if (SHA512_UNALIGNED_P(buffer))
while (len > 128) while (len > 128) {
{
rb_sha512_process_block(memcpy(ctx->buffer, buffer, 128), 128, ctx); rb_sha512_process_block(memcpy(ctx->buffer, buffer, 128), 128, ctx);
buffer = (const char *)buffer + 128; buffer = (const char *)buffer + 128;
len -= 128; len -= 128;
} }
else else
#endif #endif
{ {
rb_sha512_process_block(buffer, len & ~127, ctx); rb_sha512_process_block(buffer, len & ~127, ctx);
buffer = (const char *)buffer + (len & ~127); buffer = (const char *)buffer + (len & ~127);
@ -2010,14 +1964,12 @@ static void rb_sha512_process_bytes(const void *buffer, size_t len, struct sha51
} }
/* Move remaining bytes into internal buffer. */ /* Move remaining bytes into internal buffer. */
if (len > 0) if (len > 0) {
{
size_t left_over = ctx->buflen; size_t left_over = ctx->buflen;
memcpy(&ctx->buffer[left_over], buffer, len); memcpy(&ctx->buffer[left_over], buffer, len);
left_over += len; left_over += len;
if (left_over >= 128) if (left_over >= 128) {
{
rb_sha512_process_block(ctx->buffer, 128, ctx); rb_sha512_process_block(ctx->buffer, 128, ctx);
left_over -= 128; left_over -= 128;
memcpy(ctx->buffer, &ctx->buffer[128], left_over); memcpy(ctx->buffer, &ctx->buffer[128], left_over);
@ -2067,13 +2019,11 @@ static char *rb_sha512_crypt_r(const char *key, const char *salt, char *buffer,
/* Skip salt prefix. */ /* Skip salt prefix. */
salt += sizeof(sha512_salt_prefix) - 1; salt += sizeof(sha512_salt_prefix) - 1;
if (strncmp(salt, sha512_rounds_prefix, sizeof(sha512_rounds_prefix) - 1) == 0) if (strncmp(salt, sha512_rounds_prefix, sizeof(sha512_rounds_prefix) - 1) == 0) {
{
const char *num = salt + sizeof(sha512_rounds_prefix) - 1; const char *num = salt + sizeof(sha512_rounds_prefix) - 1;
char *endp; char *endp;
unsigned long int srounds = strtoul(num, &endp, 10); unsigned long int srounds = strtoul(num, &endp, 10);
if (*endp == '$') if (*endp == '$') {
{
salt = endp + 1; salt = endp + 1;
rounds = MAX(SHA512_ROUNDS_MIN, MIN(srounds, SHA512_ROUNDS_MAX)); rounds = MAX(SHA512_ROUNDS_MIN, MIN(srounds, SHA512_ROUNDS_MAX));
rounds_custom = 1; rounds_custom = 1;
@ -2083,16 +2033,14 @@ static char *rb_sha512_crypt_r(const char *key, const char *salt, char *buffer,
salt_len = MIN(strcspn(salt, "$"), SHA512_SALT_LEN_MAX); salt_len = MIN(strcspn(salt, "$"), SHA512_SALT_LEN_MAX);
key_len = strlen(key); key_len = strlen(key);
if ((key - (char *)0) % __alignof__(uint64_t) != 0) if ((key - (char *)0) % __alignof__(uint64_t) != 0) {
{
char *tmp = (char *)alloca(key_len + __alignof__(uint64_t)); char *tmp = (char *)alloca(key_len + __alignof__(uint64_t));
key = copied_key = key = copied_key =
memcpy(tmp + __alignof__(uint64_t) memcpy(tmp + __alignof__(uint64_t)
- (tmp - (char *)0) % __alignof__(uint64_t), key, key_len); - (tmp - (char *)0) % __alignof__(uint64_t), key, key_len);
} }
if ((salt - (char *)0) % __alignof__(uint64_t) != 0) if ((salt - (char *)0) % __alignof__(uint64_t) != 0) {
{
char *tmp = (char *)alloca(salt_len + __alignof__(uint64_t)); char *tmp = (char *)alloca(salt_len + __alignof__(uint64_t));
salt = copied_salt = salt = copied_salt =
memcpy(tmp + __alignof__(uint64_t) memcpy(tmp + __alignof__(uint64_t)
@ -2156,8 +2104,7 @@ static char *rb_sha512_crypt_r(const char *key, const char *salt, char *buffer,
/* Create byte sequence P. */ /* Create byte sequence P. */
cp = p_bytes = alloca(key_len); cp = p_bytes = alloca(key_len);
for (cnt = key_len; cnt >= 64; cnt -= 64) for (cnt = key_len; cnt >= 64; cnt -= 64) {
{
memcpy(cp, temp_result, 64); memcpy(cp, temp_result, 64);
cp += 64; cp += 64;
} }
@ -2175,8 +2122,7 @@ static char *rb_sha512_crypt_r(const char *key, const char *salt, char *buffer,
/* Create byte sequence S. */ /* Create byte sequence S. */
cp = s_bytes = alloca(salt_len); cp = s_bytes = alloca(salt_len);
for (cnt = salt_len; cnt >= 64; cnt -= 64) for (cnt = salt_len; cnt >= 64; cnt -= 64) {
{
memcpy(cp, temp_result, 64); memcpy(cp, temp_result, 64);
cp += 64; cp += 64;
} }
@ -2184,8 +2130,7 @@ static char *rb_sha512_crypt_r(const char *key, const char *salt, char *buffer,
/* Repeatedly run the collected hash value through SHA512 to burn /* Repeatedly run the collected hash value through SHA512 to burn
CPU cycles. */ CPU cycles. */
for (cnt = 0; cnt < rounds; ++cnt) for (cnt = 0; cnt < rounds; ++cnt) {
{
/* New context. */ /* New context. */
rb_sha512_init_ctx(&ctx); rb_sha512_init_ctx(&ctx);
@ -2221,8 +2166,7 @@ static char *rb_sha512_crypt_r(const char *key, const char *salt, char *buffer,
cp = buffer + MAX(0, buflen); cp = buffer + MAX(0, buflen);
buflen -= sizeof(sha512_salt_prefix) - 1; buflen -= sizeof(sha512_salt_prefix) - 1;
if (rounds_custom) if (rounds_custom) {
{
int n = snprintf(cp, MAX(0, buflen), "%s%zu$", int n = snprintf(cp, MAX(0, buflen), "%s%zu$",
sha512_rounds_prefix, rounds); sha512_rounds_prefix, rounds);
cp += n; cp += n;
@ -2235,8 +2179,7 @@ static char *rb_sha512_crypt_r(const char *key, const char *salt, char *buffer,
cp = buffer + salt_len; cp = buffer + salt_len;
buflen -= MIN((size_t) MAX(0, buflen), salt_len); buflen -= MIN((size_t) MAX(0, buflen), salt_len);
if (buflen > 0) if (buflen > 0) {
{
*cp++ = '$'; *cp++ = '$';
--buflen; --buflen;
} }
@ -2264,12 +2207,10 @@ static char *rb_sha512_crypt_r(const char *key, const char *salt, char *buffer,
b64_from_24bit(alt_result[62], alt_result[20], alt_result[41], 4); b64_from_24bit(alt_result[62], alt_result[20], alt_result[41], 4);
b64_from_24bit(0, 0, alt_result[63], 2); b64_from_24bit(0, 0, alt_result[63], 2);
if (buflen <= 0) if (buflen <= 0) {
{
errno = ERANGE; errno = ERANGE;
buffer = NULL; buffer = NULL;
} } else
else
*cp = '\0'; /* Terminate the string. */ *cp = '\0'; /* Terminate the string. */
/* Clear the buffer for the intermediate result so that people /* Clear the buffer for the intermediate result so that people
@ -2305,8 +2246,7 @@ static char *rb_sha512_crypt(const char *key, const char *salt)
int needed = (sizeof(sha512_salt_prefix) - 1 int needed = (sizeof(sha512_salt_prefix) - 1
+ sizeof(sha512_rounds_prefix) + 9 + 1 + strlen(salt) + 1 + 86 + 1); + sizeof(sha512_rounds_prefix) + 9 + 1 + strlen(salt) + 1 + 86 + 1);
if (buflen < needed) if (buflen < needed) {
{
char *new_buffer = (char *)realloc(buffer, needed); char *new_buffer = (char *)realloc(buffer, needed);
if (new_buffer == NULL) if (new_buffer == NULL)
return NULL; return NULL;
@ -2374,7 +2314,7 @@ typedef struct BlowfishContext {
void Blowfish_initstate(blf_ctx *); void Blowfish_initstate(blf_ctx *);
void Blowfish_expand0state(blf_ctx *, const uint8_t *, uint16_t); void Blowfish_expand0state(blf_ctx *, const uint8_t *, uint16_t);
void Blowfish_expandstate void Blowfish_expandstate
(blf_ctx *, const uint8_t *, uint16_t, const uint8_t *, uint16_t); (blf_ctx *, const uint8_t *, uint16_t, const uint8_t *, uint16_t);
uint32_t Blowfish_stream2word(const uint8_t *, uint16_t, uint16_t *); uint32_t Blowfish_stream2word(const uint8_t *, uint16_t, uint16_t *);
void blf_enc(blf_ctx *, uint32_t *, uint16_t); void blf_enc(blf_ctx *, uint32_t *, uint16_t);
@ -2411,14 +2351,22 @@ Blowfish_encipher(blf_ctx *c, uint32_t *xl, uint32_t *xr)
Xr = *xr; Xr = *xr;
Xl ^= p[0]; Xl ^= p[0];
BLFRND(s, p, Xr, Xl, 1); BLFRND(s, p, Xl, Xr, 2); BLFRND(s, p, Xr, Xl, 1);
BLFRND(s, p, Xr, Xl, 3); BLFRND(s, p, Xl, Xr, 4); BLFRND(s, p, Xl, Xr, 2);
BLFRND(s, p, Xr, Xl, 5); BLFRND(s, p, Xl, Xr, 6); BLFRND(s, p, Xr, Xl, 3);
BLFRND(s, p, Xr, Xl, 7); BLFRND(s, p, Xl, Xr, 8); BLFRND(s, p, Xl, Xr, 4);
BLFRND(s, p, Xr, Xl, 9); BLFRND(s, p, Xl, Xr, 10); BLFRND(s, p, Xr, Xl, 5);
BLFRND(s, p, Xr, Xl, 11); BLFRND(s, p, Xl, Xr, 12); BLFRND(s, p, Xl, Xr, 6);
BLFRND(s, p, Xr, Xl, 13); BLFRND(s, p, Xl, Xr, 14); BLFRND(s, p, Xr, Xl, 7);
BLFRND(s, p, Xr, Xl, 15); BLFRND(s, p, Xl, Xr, 16); BLFRND(s, p, Xl, Xr, 8);
BLFRND(s, p, Xr, Xl, 9);
BLFRND(s, p, Xl, Xr, 10);
BLFRND(s, p, Xr, Xl, 11);
BLFRND(s, p, Xl, Xr, 12);
BLFRND(s, p, Xr, Xl, 13);
BLFRND(s, p, Xl, Xr, 14);
BLFRND(s, p, Xr, Xl, 15);
BLFRND(s, p, Xl, Xr, 16);
*xl = Xr ^ p[17]; *xl = Xr ^ p[17];
*xr = Xl; *xr = Xl;
@ -2428,7 +2376,7 @@ void
Blowfish_initstate(blf_ctx *c) Blowfish_initstate(blf_ctx *c)
{ {
/* P-box and S-box tables initialized with digits of Pi */ /* P-box and S-box tables initialized with digits of Pi */
const blf_ctx bf_initstate = const blf_ctx bf_initstate =
@ -2497,7 +2445,8 @@ Blowfish_initstate(blf_ctx *c)
0xd60f573f, 0xbc9bc6e4, 0x2b60a476, 0x81e67400, 0xd60f573f, 0xbc9bc6e4, 0x2b60a476, 0x81e67400,
0x08ba6fb5, 0x571be91f, 0xf296ec6b, 0x2a0dd915, 0x08ba6fb5, 0x571be91f, 0xf296ec6b, 0x2a0dd915,
0xb6636521, 0xe7b9f9b6, 0xff34052e, 0xc5855664, 0xb6636521, 0xe7b9f9b6, 0xff34052e, 0xc5855664,
0x53b02d5d, 0xa99f8fa1, 0x08ba4799, 0x6e85076a}, 0x53b02d5d, 0xa99f8fa1, 0x08ba4799, 0x6e85076a
},
{ {
0x4b7a70e9, 0xb5b32944, 0xdb75092e, 0xc4192623, 0x4b7a70e9, 0xb5b32944, 0xdb75092e, 0xc4192623,
0xad6ea6b0, 0x49a7df7d, 0x9cee60b8, 0x8fedb266, 0xad6ea6b0, 0x49a7df7d, 0x9cee60b8, 0x8fedb266,
@ -2562,7 +2511,8 @@ Blowfish_initstate(blf_ctx *c)
0x9e447a2e, 0xc3453484, 0xfdd56705, 0x0e1e9ec9, 0x9e447a2e, 0xc3453484, 0xfdd56705, 0x0e1e9ec9,
0xdb73dbd3, 0x105588cd, 0x675fda79, 0xe3674340, 0xdb73dbd3, 0x105588cd, 0x675fda79, 0xe3674340,
0xc5c43465, 0x713e38d8, 0x3d28f89e, 0xf16dff20, 0xc5c43465, 0x713e38d8, 0x3d28f89e, 0xf16dff20,
0x153e21e7, 0x8fb03d4a, 0xe6e39f2b, 0xdb83adf7}, 0x153e21e7, 0x8fb03d4a, 0xe6e39f2b, 0xdb83adf7
},
{ {
0xe93d5a68, 0x948140f7, 0xf64c261c, 0x94692934, 0xe93d5a68, 0x948140f7, 0xf64c261c, 0x94692934,
0x411520f7, 0x7602d4f7, 0xbcf46b2e, 0xd4a20068, 0x411520f7, 0x7602d4f7, 0xbcf46b2e, 0xd4a20068,
@ -2627,7 +2577,8 @@ Blowfish_initstate(blf_ctx *c)
0xed545578, 0x08fca5b5, 0xd83d7cd3, 0x4dad0fc4, 0xed545578, 0x08fca5b5, 0xd83d7cd3, 0x4dad0fc4,
0x1e50ef5e, 0xb161e6f8, 0xa28514d9, 0x6c51133c, 0x1e50ef5e, 0xb161e6f8, 0xa28514d9, 0x6c51133c,
0x6fd5c7e7, 0x56e14ec4, 0x362abfce, 0xddc6c837, 0x6fd5c7e7, 0x56e14ec4, 0x362abfce, 0xddc6c837,
0xd79a3234, 0x92638212, 0x670efa8e, 0x406000e0}, 0xd79a3234, 0x92638212, 0x670efa8e, 0x406000e0
},
{ {
0x3a39ce37, 0xd3faf5cf, 0xabc27737, 0x5ac52d1b, 0x3a39ce37, 0xd3faf5cf, 0xabc27737, 0x5ac52d1b,
0x5cb0679e, 0x4fa33742, 0xd3822740, 0x99bc9bbe, 0x5cb0679e, 0x4fa33742, 0xd3822740, 0x99bc9bbe,
@ -2692,7 +2643,8 @@ Blowfish_initstate(blf_ctx *c)
0x85cbfe4e, 0x8ae88dd8, 0x7aaaf9b0, 0x4cf9aa7e, 0x85cbfe4e, 0x8ae88dd8, 0x7aaaf9b0, 0x4cf9aa7e,
0x1948c25c, 0x02fb8a8c, 0x01c36ae4, 0xd6ebe1f9, 0x1948c25c, 0x02fb8a8c, 0x01c36ae4, 0xd6ebe1f9,
0x90d4f869, 0xa65cdea0, 0x3f09252d, 0xc208e69f, 0x90d4f869, 0xa65cdea0, 0x3f09252d, 0xc208e69f,
0xb74e6132, 0xce77e25b, 0x578fdfe3, 0x3ac372e6} 0xb74e6132, 0xce77e25b, 0x578fdfe3, 0x3ac372e6
}
}, },
{ {
0x243f6a88, 0x85a308d3, 0x13198a2e, 0x03707344, 0x243f6a88, 0x85a308d3, 0x13198a2e, 0x03707344,
@ -2700,7 +2652,8 @@ Blowfish_initstate(blf_ctx *c)
0x452821e6, 0x38d01377, 0xbe5466cf, 0x34e90c6c, 0x452821e6, 0x38d01377, 0xbe5466cf, 0x34e90c6c,
0xc0ac29b7, 0xc97c50dd, 0x3f84d5b5, 0xb5470917, 0xc0ac29b7, 0xc97c50dd, 0x3f84d5b5, 0xb5470917,
0x9216d5d9, 0x8979fb1b 0x9216d5d9, 0x8979fb1b
} }; }
};
*c = bf_initstate; *c = bf_initstate;
@ -2855,10 +2808,9 @@ static char encrypted[512]; /* Shouldn't grow more than this */
static char error[] = ":"; static char error[] = ":";
static const uint8_t Base64Code[] = static const uint8_t Base64Code[] =
"./ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; "./ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
static const uint8_t index_64[128] = static const uint8_t index_64[128] = {
{
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
@ -2933,8 +2885,7 @@ rb_blowfish_crypt(const char *key, const char *salt)
/* If it starts with the magic string, then skip that */ /* If it starts with the magic string, then skip that */
if(!strncmp(salt, magic, strlen(magic))) { if(!strncmp(salt, magic, strlen(magic))) {
salt += strlen(magic); salt += strlen(magic);
} } else if (*salt == '$') {
else if (*salt == '$') {
/* Discard "$" identifier */ /* Discard "$" identifier */
salt++; salt++;

View File

@ -78,8 +78,7 @@ devpoll_update_events(rb_fde_t *F, short filter, PF * handler)
int cur_mask = fdmask[fd]; int cur_mask = fdmask[fd];
PF *cur_handler; PF *cur_handler;
fdmask[fd] = 0; fdmask[fd] = 0;
switch (filter) switch (filter) {
{
case RB_SELECT_READ: case RB_SELECT_READ:
cur_handler = F->read_handler; cur_handler = F->read_handler;
if(handler) if(handler)
@ -109,19 +108,16 @@ devpoll_update_events(rb_fde_t *F, short filter, PF * handler)
update_required++; update_required++;
if(cur_mask != fdmask[fd]) if(cur_mask != fdmask[fd])
update_required++; update_required++;
if(update_required) if(update_required) {
{
/* /*
* Ok, we can call devpoll_write_update() here now to re-build the * Ok, we can call devpoll_write_update() here now to re-build the
* fd struct. If we end up with nothing on this fd, it won't write * fd struct. If we end up with nothing on this fd, it won't write
* anything. * anything.
*/ */
if(fdmask[fd]) if(fdmask[fd]) {
{
devpoll_write_update(fd, POLLREMOVE); devpoll_write_update(fd, POLLREMOVE);
devpoll_write_update(fd, fdmask[fd]); devpoll_write_update(fd, fdmask[fd]);
} } else
else
devpoll_write_update(fd, POLLREMOVE); devpoll_write_update(fd, POLLREMOVE);
} }
} }
@ -144,8 +140,7 @@ int
rb_init_netio_devpoll(void) rb_init_netio_devpoll(void)
{ {
dpfd = open("/dev/poll", O_RDWR); dpfd = open("/dev/poll", O_RDWR);
if(dpfd < 0) if(dpfd < 0) {
{
return errno; return errno;
} }
maxfd = getdtablesize() - 2; /* This makes more sense than HARD_FDLIMIT */ maxfd = getdtablesize() - 2; /* This makes more sense than HARD_FDLIMIT */
@ -165,14 +160,12 @@ rb_setselect_devpoll(rb_fde_t *F, unsigned int type, PF * handler, void *client_
{ {
lrb_assert(IsFDOpen(F)); lrb_assert(IsFDOpen(F));
if(type & RB_SELECT_READ) if(type & RB_SELECT_READ) {
{
devpoll_update_events(F, RB_SELECT_READ, handler); devpoll_update_events(F, RB_SELECT_READ, handler);
F->read_handler = handler; F->read_handler = handler;
F->read_data = client_data; F->read_data = client_data;
} }
if(type & RB_SELECT_WRITE) if(type & RB_SELECT_WRITE) {
{
devpoll_update_events(F, RB_SELECT_WRITE, handler); devpoll_update_events(F, RB_SELECT_WRITE, handler);
F->write_handler = handler; F->write_handler = handler;
F->write_data = client_data; F->write_data = client_data;
@ -201,10 +194,8 @@ rb_select_devpoll(long delay)
struct pollfd pollfds[maxfd]; struct pollfd pollfds[maxfd];
struct dvpoll dopoll; struct dvpoll dopoll;
do do {
{ for(;;) {
for(;;)
{
dopoll.dp_timeout = delay; dopoll.dp_timeout = delay;
dopoll.dp_nfds = maxfd; dopoll.dp_nfds = maxfd;
dopoll.dp_fds = &pollfds[0]; dopoll.dp_fds = &pollfds[0];
@ -221,17 +212,14 @@ rb_select_devpoll(long delay)
if(num == 0) if(num == 0)
continue; continue;
for(i = 0; i < num; i++) for(i = 0; i < num; i++) {
{
int fd = dopoll.dp_fds[i].fd; int fd = dopoll.dp_fds[i].fd;
PF *hdl = NULL; PF *hdl = NULL;
rb_fde_t *F = rb_find_fd(fd); rb_fde_t *F = rb_find_fd(fd);
if((dopoll.dp_fds[i].revents & (POLLRDNORM | POLLIN | POLLHUP | if((dopoll.dp_fds[i].revents & (POLLRDNORM | POLLIN | POLLHUP |
POLLERR)) POLLERR))
&& (dopoll.dp_fds[i].events & (POLLRDNORM | POLLIN))) && (dopoll.dp_fds[i].events & (POLLRDNORM | POLLIN))) {
{ if((hdl = F->read_handler) != NULL) {
if((hdl = F->read_handler) != NULL)
{
F->read_handler = NULL; F->read_handler = NULL;
hdl(F, F->read_data); hdl(F, F->read_data);
/* /*
@ -248,10 +236,8 @@ rb_select_devpoll(long delay)
continue; /* Read handler closed us..go on to do something more useful */ continue; /* Read handler closed us..go on to do something more useful */
if((dopoll.dp_fds[i].revents & (POLLWRNORM | POLLOUT | POLLHUP | if((dopoll.dp_fds[i].revents & (POLLWRNORM | POLLOUT | POLLHUP |
POLLERR)) POLLERR))
&& (dopoll.dp_fds[i].events & (POLLWRNORM | POLLOUT))) && (dopoll.dp_fds[i].events & (POLLWRNORM | POLLOUT))) {
{ if((hdl = F->write_handler) != NULL) {
if((hdl = F->write_handler) != NULL)
{
F->write_handler = NULL; F->write_handler = NULL;
hdl(F, F->write_data); hdl(F, F->write_data);
/* See above similar code in the read case */ /* See above similar code in the read case */
@ -262,8 +248,7 @@ rb_select_devpoll(long delay)
} }
} }
return RB_OK; return RB_OK;
} } while(0);
while(0);
/* XXX Get here, we broke! */ /* XXX Get here, we broke! */
return 0; return 0;
} }

View File

@ -47,8 +47,7 @@
#endif #endif
#define RTSIGNAL SIGRTMIN #define RTSIGNAL SIGRTMIN
struct epoll_info struct epoll_info {
{
int ep; int ep;
struct epoll_event *pfd; struct epoll_event *pfd;
int pfd_size; int pfd_size;
@ -72,8 +71,7 @@ rb_init_netio_epoll(void)
ep_info = rb_malloc(sizeof(struct epoll_info)); ep_info = rb_malloc(sizeof(struct epoll_info));
ep_info->pfd_size = getdtablesize(); ep_info->pfd_size = getdtablesize();
ep_info->ep = epoll_create(ep_info->pfd_size); ep_info->ep = epoll_create(ep_info->pfd_size);
if(ep_info->ep < 0) if(ep_info->ep < 0) {
{
return -1; return -1;
} }
rb_open(ep_info->ep, RB_FD_UNKNOWN, "epoll file descriptor"); rb_open(ep_info->ep, RB_FD_UNKNOWN, "epoll file descriptor");
@ -105,8 +103,7 @@ rb_setselect_epoll(rb_fde_t *F, unsigned int type, PF * handler, void *client_da
lrb_assert(IsFDOpen(F)); lrb_assert(IsFDOpen(F));
/* Update the list, even though we're not using it .. */ /* Update the list, even though we're not using it .. */
if(type & RB_SELECT_READ) if(type & RB_SELECT_READ) {
{
if(handler != NULL) if(handler != NULL)
F->pflags |= EPOLLIN; F->pflags |= EPOLLIN;
else else
@ -115,8 +112,7 @@ rb_setselect_epoll(rb_fde_t *F, unsigned int type, PF * handler, void *client_da
F->read_data = client_data; F->read_data = client_data;
} }
if(type & RB_SELECT_WRITE) if(type & RB_SELECT_WRITE) {
{
if(handler != NULL) if(handler != NULL)
F->pflags |= EPOLLOUT; F->pflags |= EPOLLOUT;
else else
@ -143,8 +139,7 @@ rb_setselect_epoll(rb_fde_t *F, unsigned int type, PF * handler, void *client_da
if(op == EPOLL_CTL_ADD || op == EPOLL_CTL_MOD) if(op == EPOLL_CTL_ADD || op == EPOLL_CTL_MOD)
ep_event.events |= EPOLLET; ep_event.events |= EPOLLET;
if(epoll_ctl(ep_info->ep, op, F->fd, &ep_event) != 0) if(epoll_ctl(ep_info->ep, op, F->fd, &ep_event) != 0) {
{
rb_lib_log("rb_setselect_epoll(): epoll_ctl failed: %s", strerror(errno)); rb_lib_log("rb_setselect_epoll(): epoll_ctl failed: %s", strerror(errno));
abort(); abort();
} }
@ -182,34 +177,29 @@ rb_select_epoll(long delay)
if(num <= 0) if(num <= 0)
return RB_OK; return RB_OK;
for(i = 0; i < num; i++) for(i = 0; i < num; i++) {
{
PF *hdl; PF *hdl;
rb_fde_t *F = ep_info->pfd[i].data.ptr; rb_fde_t *F = ep_info->pfd[i].data.ptr;
old_flags = F->pflags; old_flags = F->pflags;
if(ep_info->pfd[i].events & (EPOLLIN | EPOLLHUP | EPOLLERR)) if(ep_info->pfd[i].events & (EPOLLIN | EPOLLHUP | EPOLLERR)) {
{
hdl = F->read_handler; hdl = F->read_handler;
data = F->read_data; data = F->read_data;
F->read_handler = NULL; F->read_handler = NULL;
F->read_data = NULL; F->read_data = NULL;
if(hdl) if(hdl) {
{
hdl(F, data); hdl(F, data);
} }
} }
if(!IsFDOpen(F)) if(!IsFDOpen(F))
continue; continue;
if(ep_info->pfd[i].events & (EPOLLOUT | EPOLLHUP | EPOLLERR)) if(ep_info->pfd[i].events & (EPOLLOUT | EPOLLHUP | EPOLLERR)) {
{
hdl = F->write_handler; hdl = F->write_handler;
data = F->write_data; data = F->write_data;
F->write_handler = NULL; F->write_handler = NULL;
F->write_data = NULL; F->write_data = NULL;
if(hdl) if(hdl) {
{
hdl(F, data); hdl(F, data);
} }
} }
@ -224,8 +214,7 @@ rb_select_epoll(long delay)
if(F->write_handler != NULL) if(F->write_handler != NULL)
flags |= EPOLLOUT; flags |= EPOLLOUT;
if(old_flags != flags) if(old_flags != flags) {
{
if(flags == 0) if(flags == 0)
op = EPOLL_CTL_DEL; op = EPOLL_CTL_DEL;
else else
@ -235,8 +224,7 @@ rb_select_epoll(long delay)
if(op == EPOLL_CTL_MOD || op == EPOLL_CTL_ADD) if(op == EPOLL_CTL_MOD || op == EPOLL_CTL_ADD)
ep_event.events |= EPOLLET; ep_event.events |= EPOLLET;
if(epoll_ctl(ep_info->ep, op, F->fd, &ep_event) != 0) if(epoll_ctl(ep_info->ep, op, F->fd, &ep_event) != 0) {
{
rb_lib_log("rb_select_epoll(): epoll_ctl failed: %s", rb_lib_log("rb_select_epoll(): epoll_ctl failed: %s",
strerror(errno)); strerror(errno));
} }
@ -263,15 +251,13 @@ rb_epoll_supports_event(void)
return 0; return 0;
/* Check for openvz..it has a broken timerfd.. */ /* Check for openvz..it has a broken timerfd.. */
if(stat("/proc/user_beancounters", &st) == 0) if(stat("/proc/user_beancounters", &st) == 0) {
{
can_do_event = -1; can_do_event = -1;
return 0; return 0;
} }
#ifdef USE_TIMERFD_CREATE #ifdef USE_TIMERFD_CREATE
if((fd = timerfd_create(CLOCK_REALTIME, 0)) >= 0) if((fd = timerfd_create(CLOCK_REALTIME, 0)) >= 0) {
{
close(fd); close(fd);
can_do_event = 1; can_do_event = 1;
can_do_timerfd = 1; can_do_timerfd = 1;
@ -281,16 +267,14 @@ rb_epoll_supports_event(void)
ev.sigev_signo = SIGVTALRM; ev.sigev_signo = SIGVTALRM;
ev.sigev_notify = SIGEV_SIGNAL; ev.sigev_notify = SIGEV_SIGNAL;
if(timer_create(CLOCK_REALTIME, &ev, &timer) != 0) if(timer_create(CLOCK_REALTIME, &ev, &timer) != 0) {
{
can_do_event = -1; can_do_event = -1;
return 0; return 0;
} }
timer_delete(timer); timer_delete(timer);
sigemptyset(&set); sigemptyset(&set);
fd = signalfd(-1, &set, 0); fd = signalfd(-1, &set, 0);
if(fd < 0) if(fd < 0) {
{
can_do_event = -1; can_do_event = -1;
return 0; return 0;
} }
@ -301,8 +285,7 @@ rb_epoll_supports_event(void)
/* bleh..work around a glibc header bug on 32bit systems */ /* bleh..work around a glibc header bug on 32bit systems */
struct our_signalfd_siginfo struct our_signalfd_siginfo {
{
uint32_t signo; uint32_t signo;
int32_t err; int32_t err;
int32_t code; int32_t code;
@ -332,30 +315,25 @@ signalfd_handler(rb_fde_t *F, void *data)
struct ev_entry *ev; struct ev_entry *ev;
int ret, x; int ret, x;
for(x = 0; x < SIGFDIOV_COUNT; x++) for(x = 0; x < SIGFDIOV_COUNT; x++) {
{
iov[x].iov_base = &fdsig[x]; iov[x].iov_base = &fdsig[x];
iov[x].iov_len = sizeof(struct our_signalfd_siginfo); iov[x].iov_len = sizeof(struct our_signalfd_siginfo);
} }
while(1) while(1) {
{
ret = readv(rb_get_fd(F), iov, SIGFDIOV_COUNT); ret = readv(rb_get_fd(F), iov, SIGFDIOV_COUNT);
if(ret == 0 || (ret < 0 && !rb_ignore_errno(errno))) if(ret == 0 || (ret < 0 && !rb_ignore_errno(errno))) {
{
rb_close(F); rb_close(F);
rb_epoll_init_event(); rb_epoll_init_event();
return; return;
} }
if(ret < 0) if(ret < 0) {
{
rb_setselect(F, RB_SELECT_READ, signalfd_handler, NULL); rb_setselect(F, RB_SELECT_READ, signalfd_handler, NULL);
return; return;
} }
for(x = 0; x < ret / (int)sizeof(struct our_signalfd_siginfo); x++) for(x = 0; x < ret / (int)sizeof(struct our_signalfd_siginfo); x++) {
{
#if __WORDSIZE == 32 && defined(__sparc__) #if __WORDSIZE == 32 && defined(__sparc__)
uint32_t *q = (uint32_t *)&fdsig[x].svptr; uint32_t *q = (uint32_t *)&fdsig[x].svptr;
ev = (struct ev_entry *)q[0]; ev = (struct ev_entry *)q[0];
@ -378,16 +356,14 @@ rb_epoll_init_event(void)
rb_fde_t *F; rb_fde_t *F;
int sfd; int sfd;
rb_epoll_supports_event(); rb_epoll_supports_event();
if(!can_do_timerfd) if(!can_do_timerfd) {
{
sigemptyset(&ss); sigemptyset(&ss);
sigaddset(&ss, RTSIGNAL); sigaddset(&ss, RTSIGNAL);
sigprocmask(SIG_BLOCK, &ss, 0); sigprocmask(SIG_BLOCK, &ss, 0);
sigemptyset(&ss); sigemptyset(&ss);
sigaddset(&ss, RTSIGNAL); sigaddset(&ss, RTSIGNAL);
sfd = signalfd(-1, &ss, 0); sfd = signalfd(-1, &ss, 0);
if(sfd == -1) if(sfd == -1) {
{
can_do_event = -1; can_do_event = -1;
return; return;
} }
@ -411,8 +387,7 @@ rb_epoll_sched_event_signalfd(struct ev_entry *event, int when)
ev.sigev_signo = RTSIGNAL; ev.sigev_signo = RTSIGNAL;
ev.sigev_value.sival_ptr = event; ev.sigev_value.sival_ptr = event;
if(timer_create(CLOCK_REALTIME, &ev, id) < 0) if(timer_create(CLOCK_REALTIME, &ev, id) < 0) {
{
rb_lib_log("timer_create: %s\n", strerror(errno)); rb_lib_log("timer_create: %s\n", strerror(errno));
return 0; return 0;
} }
@ -422,8 +397,7 @@ rb_epoll_sched_event_signalfd(struct ev_entry *event, int when)
if(event->frequency != 0) if(event->frequency != 0)
ts.it_interval = ts.it_value; ts.it_interval = ts.it_value;
if(timer_settime(*id, 0, &ts, NULL) < 0) if(timer_settime(*id, 0, &ts, NULL) < 0) {
{
rb_lib_log("timer_settime: %s\n", strerror(errno)); rb_lib_log("timer_settime: %s\n", strerror(errno));
return 0; return 0;
} }
@ -438,16 +412,14 @@ rb_read_timerfd(rb_fde_t *F, void *data)
int retlen; int retlen;
uint64_t count; uint64_t count;
if(event == NULL) if(event == NULL) {
{
rb_close(F); rb_close(F);
return; return;
} }
retlen = rb_read(F, &count, sizeof(count)); retlen = rb_read(F, &count, sizeof(count));
if(retlen == 0 || (retlen < 0 && !rb_ignore_errno(errno))) if(retlen == 0 || (retlen < 0 && !rb_ignore_errno(errno))) {
{
rb_close(F); rb_close(F);
rb_lib_log("rb_read_timerfd: timerfd[%s] closed on error: %s", event->name, rb_lib_log("rb_read_timerfd: timerfd[%s] closed on error: %s", event->name,
strerror(errno)); strerror(errno));
@ -466,8 +438,7 @@ rb_epoll_sched_event_timerfd(struct ev_entry *event, int when)
int fd; int fd;
rb_fde_t *F; rb_fde_t *F;
if((fd = timerfd_create(CLOCK_REALTIME, 0)) < 0) if((fd = timerfd_create(CLOCK_REALTIME, 0)) < 0) {
{
rb_lib_log("timerfd_create: %s\n", strerror(errno)); rb_lib_log("timerfd_create: %s\n", strerror(errno));
return 0; return 0;
} }
@ -478,8 +449,7 @@ rb_epoll_sched_event_timerfd(struct ev_entry *event, int when)
if(event->frequency != 0) if(event->frequency != 0)
ts.it_interval = ts.it_value; ts.it_interval = ts.it_value;
if(timerfd_settime(fd, 0, &ts, NULL) < 0) if(timerfd_settime(fd, 0, &ts, NULL) < 0) {
{
rb_lib_log("timerfd_settime: %s\n", strerror(errno)); rb_lib_log("timerfd_settime: %s\n", strerror(errno));
close(fd); close(fd);
return 0; return 0;
@ -499,8 +469,7 @@ int
rb_epoll_sched_event(struct ev_entry *event, int when) rb_epoll_sched_event(struct ev_entry *event, int when)
{ {
#ifdef USE_TIMERFD_CREATE #ifdef USE_TIMERFD_CREATE
if(can_do_timerfd) if(can_do_timerfd) {
{
return rb_epoll_sched_event_timerfd(event, when); return rb_epoll_sched_event_timerfd(event, when);
} }
#endif #endif
@ -511,8 +480,7 @@ void
rb_epoll_unsched_event(struct ev_entry *event) rb_epoll_unsched_event(struct ev_entry *event)
{ {
#ifdef USE_TIMERFD_CREATE #ifdef USE_TIMERFD_CREATE
if(can_do_timerfd) if(can_do_timerfd) {
{
rb_close((rb_fde_t *)event->comm_ptr); rb_close((rb_fde_t *)event->comm_ptr);
event->comm_ptr = NULL; event->comm_ptr = NULL;
return; return;

View File

@ -65,8 +65,7 @@ rb_event_find(EVH * func, void *arg)
{ {
rb_dlink_node *ptr; rb_dlink_node *ptr;
struct ev_entry *ev; struct ev_entry *ev;
RB_DLINK_FOREACH(ptr, event_list.head) RB_DLINK_FOREACH(ptr, event_list.head) {
{
ev = ptr->data; ev = ptr->data;
if((ev->func == func) && (ev->arg == arg)) if((ev->func == func) && (ev->arg == arg))
return ev; return ev;
@ -96,8 +95,7 @@ rb_event_add(const char *name, EVH * func, void *arg, time_t when)
ev->next = when; ev->next = when;
ev->frequency = when; ev->frequency = when;
if((ev->when < event_time_min) || (event_time_min == -1)) if((ev->when < event_time_min) || (event_time_min == -1)) {
{
event_time_min = ev->when; event_time_min = ev->when;
} }
rb_dlinkAdd(ev, &ev->node, &event_list); rb_dlinkAdd(ev, &ev->node, &event_list);
@ -170,8 +168,7 @@ rb_event_find_delete(EVH * func, void *arg)
struct ev_entry * struct ev_entry *
rb_event_addish(const char *name, EVH * func, void *arg, time_t delta_ish) rb_event_addish(const char *name, EVH * func, void *arg, time_t delta_ish)
{ {
if(delta_ish >= 3.0) if(delta_ish >= 3.0) {
{
const time_t two_third = (2 * delta_ish) / 3; const time_t two_third = (2 * delta_ish) / 3;
delta_ish = two_third + ((rand() % 1000) * two_third) / 1000; delta_ish = two_third + ((rand() % 1000) * two_third) / 1000;
/* /*
@ -188,8 +185,7 @@ rb_run_event(struct ev_entry *ev)
{ {
rb_strlcpy(last_event_ran, ev->name, sizeof(last_event_ran)); rb_strlcpy(last_event_ran, ev->name, sizeof(last_event_ran));
ev->func(ev->arg); ev->func(ev->arg);
if(!ev->frequency) if(!ev->frequency) {
{
rb_io_unsched_event(ev); rb_io_unsched_event(ev);
rb_dlinkDelete(&ev->node, &event_list); rb_dlinkDelete(&ev->node, &event_list);
rb_free(ev); rb_free(ev);
@ -217,29 +213,22 @@ rb_event_run(void)
return; return;
event_time_min = -1; event_time_min = -1;
RB_DLINK_FOREACH_SAFE(ptr, next, event_list.head) RB_DLINK_FOREACH_SAFE(ptr, next, event_list.head) {
{
ev = ptr->data; ev = ptr->data;
if(ev->when <= rb_current_time()) if(ev->when <= rb_current_time()) {
{
rb_strlcpy(last_event_ran, ev->name, sizeof(last_event_ran)); rb_strlcpy(last_event_ran, ev->name, sizeof(last_event_ran));
ev->func(ev->arg); ev->func(ev->arg);
/* event is scheduled more than once */ /* event is scheduled more than once */
if(ev->frequency) if(ev->frequency) {
{
ev->when = rb_current_time() + ev->frequency; ev->when = rb_current_time() + ev->frequency;
if((ev->when < event_time_min) || (event_time_min == -1)) if((ev->when < event_time_min) || (event_time_min == -1))
event_time_min = ev->when; event_time_min = ev->when;
} } else {
else
{
rb_dlinkDelete(&ev->node, &event_list); rb_dlinkDelete(&ev->node, &event_list);
rb_free(ev); rb_free(ev);
} }
} } else {
else
{
if((ev->when < event_time_min) || (event_time_min == -1)) if((ev->when < event_time_min) || (event_time_min == -1))
event_time_min = ev->when; event_time_min = ev->when;
} }
@ -255,8 +244,7 @@ rb_event_io_register_all(void)
if(!rb_io_supports_event()) if(!rb_io_supports_event())
return; return;
RB_DLINK_FOREACH(ptr, event_list.head) RB_DLINK_FOREACH(ptr, event_list.head) {
{
ev = ptr->data; ev = ptr->data;
rb_io_sched_event(ev, ev->next); rb_io_sched_event(ev, ev->next);
} }
@ -290,8 +278,7 @@ rb_dump_events(void (*func) (char *, void *), void *ptr)
rb_strlcpy(buf, "Operation Next Execution", len); rb_strlcpy(buf, "Operation Next Execution", len);
func(buf, ptr); func(buf, ptr);
RB_DLINK_FOREACH(dptr, event_list.head) RB_DLINK_FOREACH(dptr, event_list.head) {
{
ev = dptr->data; ev = dptr->data;
rb_snprintf(buf, len, "%-28s %-4ld seconds", ev->name, rb_snprintf(buf, len, "%-28s %-4ld seconds", ev->name,
ev->when - (long)rb_current_time()); ev->when - (long)rb_current_time());
@ -310,8 +297,7 @@ rb_set_back_events(time_t by)
{ {
rb_dlink_node *ptr; rb_dlink_node *ptr;
struct ev_entry *ev; struct ev_entry *ev;
RB_DLINK_FOREACH(ptr, event_list.head) RB_DLINK_FOREACH(ptr, event_list.head) {
{
ev = ptr->data; ev = ptr->data;
if(ev->when > by) if(ev->when > by)
ev->when -= by; ev->when -= by;

View File

@ -45,8 +45,7 @@ rb_ssl_shutdown(rb_fde_t *F)
int i; int i;
if(F == NULL || F->ssl == NULL) if(F == NULL || F->ssl == NULL)
return; return;
for(i = 0; i < 4; i++) for(i = 0; i < 4; i++) {
{
if(gnutls_bye(SSL_P(F), GNUTLS_SHUT_RDWR) == GNUTLS_E_SUCCESS) if(gnutls_bye(SSL_P(F), GNUTLS_SHUT_RDWR) == GNUTLS_E_SUCCESS)
break; break;
} }
@ -81,10 +80,8 @@ do_ssl_handshake(rb_fde_t *F, PF * callback)
int flags; int flags;
ret = gnutls_handshake(SSL_P(F)); ret = gnutls_handshake(SSL_P(F));
if(ret < 0) if(ret < 0) {
{ if((ret == GNUTLS_E_INTERRUPTED && rb_ignore_errno(errno)) || ret == GNUTLS_E_AGAIN) {
if((ret == GNUTLS_E_INTERRUPTED && rb_ignore_errno(errno)) || ret == GNUTLS_E_AGAIN)
{
if(gnutls_record_get_direction(SSL_P(F)) == 0) if(gnutls_record_get_direction(SSL_P(F)) == 0)
flags = RB_SELECT_READ; flags = RB_SELECT_READ;
else else
@ -145,8 +142,7 @@ rb_ssl_start_accepted(rb_fde_t *new_F, ACCB * cb, void *data, int timeout)
gnutls_dh_set_prime_bits(*ssl, 1024); gnutls_dh_set_prime_bits(*ssl, 1024);
gnutls_transport_set_ptr(*ssl, (gnutls_transport_ptr_t) (long int)new_F->fd); gnutls_transport_set_ptr(*ssl, (gnutls_transport_ptr_t) (long int)new_F->fd);
gnutls_certificate_server_set_request(*ssl, GNUTLS_CERT_REQUEST); gnutls_certificate_server_set_request(*ssl, GNUTLS_CERT_REQUEST);
if(do_ssl_handshake(new_F, rb_ssl_tryaccept)) if(do_ssl_handshake(new_F, rb_ssl_tryaccept)) {
{
struct acceptdata *ad = new_F->accept; struct acceptdata *ad = new_F->accept;
new_F->accept = NULL; new_F->accept = NULL;
ad->callback(new_F, RB_OK, (struct sockaddr *)&ad->S, ad->addrlen, ad->data); ad->callback(new_F, RB_OK, (struct sockaddr *)&ad->S, ad->addrlen, ad->data);
@ -177,8 +173,7 @@ rb_ssl_accept_setup(rb_fde_t *F, rb_fde_t *new_F, struct sockaddr *st, int addrl
gnutls_dh_set_prime_bits(SSL_P(new_F), 1024); gnutls_dh_set_prime_bits(SSL_P(new_F), 1024);
gnutls_transport_set_ptr(SSL_P(new_F), (gnutls_transport_ptr_t) (long int)rb_get_fd(new_F)); gnutls_transport_set_ptr(SSL_P(new_F), (gnutls_transport_ptr_t) (long int)rb_get_fd(new_F));
gnutls_certificate_server_set_request(SSL_P(new_F), GNUTLS_CERT_REQUEST); gnutls_certificate_server_set_request(SSL_P(new_F), GNUTLS_CERT_REQUEST);
if(do_ssl_handshake(F, rb_ssl_tryaccept)) if(do_ssl_handshake(F, rb_ssl_tryaccept)) {
{
struct acceptdata *ad = F->accept; struct acceptdata *ad = F->accept;
F->accept = NULL; F->accept = NULL;
ad->callback(F, RB_OK, (struct sockaddr *)&ad->S, ad->addrlen, ad->data); ad->callback(F, RB_OK, (struct sockaddr *)&ad->S, ad->addrlen, ad->data);
@ -200,14 +195,11 @@ rb_ssl_read_or_write(int r_or_w, rb_fde_t *F, void *rbuf, const void *wbuf, size
else else
ret = gnutls_record_send(*ssl, wbuf, count); ret = gnutls_record_send(*ssl, wbuf, count);
if(ret < 0) if(ret < 0) {
{ switch (ret) {
switch (ret)
{
case GNUTLS_E_AGAIN: case GNUTLS_E_AGAIN:
case GNUTLS_E_INTERRUPTED: case GNUTLS_E_INTERRUPTED:
if(rb_ignore_errno(errno)) if(rb_ignore_errno(errno)) {
{
if(gnutls_record_get_direction(*ssl) == 0) if(gnutls_record_get_direction(*ssl) == 0)
return RB_RW_SSL_NEED_READ; return RB_RW_SSL_NEED_READ;
else else
@ -246,8 +238,7 @@ rb_init_ssl(void)
{ {
gnutls_global_init(); gnutls_global_init();
if(gnutls_certificate_allocate_credentials(&x509) != GNUTLS_E_SUCCESS) if(gnutls_certificate_allocate_credentials(&x509) != GNUTLS_E_SUCCESS) {
{
rb_lib_log("rb_init_ssl: Unable to allocate SSL/TLS certificate credentials"); rb_lib_log("rb_init_ssl: Unable to allocate SSL/TLS certificate credentials");
return 0; return 0;
} }
@ -291,20 +282,17 @@ rb_setup_ssl_server(const char *cert, const char *keyfile, const char *dhfile)
{ {
int ret; int ret;
gnutls_datum_t *d_cert, *d_key; gnutls_datum_t *d_cert, *d_key;
if(cert == NULL) if(cert == NULL) {
{
rb_lib_log("rb_setup_ssl_server: No certificate file"); rb_lib_log("rb_setup_ssl_server: No certificate file");
return 0; return 0;
} }
if((d_cert = rb_load_file_into_datum_t(cert)) == NULL) if((d_cert = rb_load_file_into_datum_t(cert)) == NULL) {
{
rb_lib_log("rb_setup_ssl_server: Error loading certificate: %s", strerror(errno)); rb_lib_log("rb_setup_ssl_server: Error loading certificate: %s", strerror(errno));
return 0; return 0;
} }
if((d_key = rb_load_file_into_datum_t(keyfile)) == NULL) if((d_key = rb_load_file_into_datum_t(keyfile)) == NULL) {
{
rb_lib_log("rb_setup_ssl_server: Error loading key: %s", strerror(errno)); rb_lib_log("rb_setup_ssl_server: Error loading key: %s", strerror(errno));
return 0; return 0;
} }
@ -312,8 +300,7 @@ rb_setup_ssl_server(const char *cert, const char *keyfile, const char *dhfile)
if((ret = if((ret =
gnutls_certificate_set_x509_key_mem(x509, d_cert, d_key, gnutls_certificate_set_x509_key_mem(x509, d_cert, d_key,
GNUTLS_X509_FMT_PEM)) != GNUTLS_E_SUCCESS) GNUTLS_X509_FMT_PEM)) != GNUTLS_E_SUCCESS) {
{
rb_lib_log("rb_setup_ssl_server: Error loading certificate or key file: %s", rb_lib_log("rb_setup_ssl_server: Error loading certificate or key file: %s",
gnutls_strerror(ret)); gnutls_strerror(ret));
return 0; return 0;
@ -321,15 +308,12 @@ rb_setup_ssl_server(const char *cert, const char *keyfile, const char *dhfile)
rb_free_datum_t(d_cert); rb_free_datum_t(d_cert);
rb_free_datum_t(d_key); rb_free_datum_t(d_key);
if(dhfile != NULL) if(dhfile != NULL) {
{ if(gnutls_dh_params_init(&dh_params) == GNUTLS_E_SUCCESS) {
if(gnutls_dh_params_init(&dh_params) == GNUTLS_E_SUCCESS)
{
gnutls_datum_t *data; gnutls_datum_t *data;
int xret; int xret;
data = rb_load_file_into_datum_t(dhfile); data = rb_load_file_into_datum_t(dhfile);
if(data != NULL) if(data != NULL) {
{
xret = gnutls_dh_params_import_pkcs3(dh_params, data, xret = gnutls_dh_params_import_pkcs3(dh_params, data,
GNUTLS_X509_FMT_PEM); GNUTLS_X509_FMT_PEM);
if(xret < 0) if(xret < 0)
@ -339,8 +323,7 @@ rb_setup_ssl_server(const char *cert, const char *keyfile, const char *dhfile)
rb_free_datum_t(data); rb_free_datum_t(data);
} }
gnutls_certificate_set_dh_params(x509, dh_params); gnutls_certificate_set_dh_params(x509, dh_params);
} } else
else
rb_lib_log("rb_setup_ssl_server: Unable to setup DH parameters"); rb_lib_log("rb_setup_ssl_server: Unable to setup DH parameters");
} }
return 1; return 1;
@ -357,8 +340,7 @@ rb_ssl_listen(rb_fde_t *F, int backlog, int defer_accept)
return result; return result;
} }
struct ssl_connect struct ssl_connect {
{
CNCB *callback; CNCB *callback;
void *data; void *data;
int timeout; int timeout;
@ -387,8 +369,7 @@ rb_ssl_tryconn_cb(rb_fde_t *F, void *data)
ret = do_ssl_handshake(F, rb_ssl_tryconn_cb); ret = do_ssl_handshake(F, rb_ssl_tryconn_cb);
switch (ret) switch (ret) {
{
case -1: case -1:
rb_ssl_connect_realcb(F, RB_ERROR_SSL, sconn); rb_ssl_connect_realcb(F, RB_ERROR_SSL, sconn);
break; break;
@ -407,8 +388,7 @@ static void
rb_ssl_tryconn(rb_fde_t *F, int status, void *data) rb_ssl_tryconn(rb_fde_t *F, int status, void *data)
{ {
struct ssl_connect *sconn = data; struct ssl_connect *sconn = data;
if(status != RB_OK) if(status != RB_OK) {
{
rb_ssl_connect_realcb(F, status, sconn); rb_ssl_connect_realcb(F, status, sconn);
return; return;
} }
@ -424,8 +404,7 @@ rb_ssl_tryconn(rb_fde_t *F, int status, void *data)
gnutls_dh_set_prime_bits(SSL_P(F), 1024); gnutls_dh_set_prime_bits(SSL_P(F), 1024);
gnutls_transport_set_ptr(SSL_P(F), (gnutls_transport_ptr_t) (long int)F->fd); gnutls_transport_set_ptr(SSL_P(F), (gnutls_transport_ptr_t) (long int)F->fd);
if(do_ssl_handshake(F, rb_ssl_tryconn_cb)) if(do_ssl_handshake(F, rb_ssl_tryconn_cb)) {
{
rb_ssl_connect_realcb(F, RB_OK, sconn); rb_ssl_connect_realcb(F, RB_OK, sconn);
} }
} }
@ -471,8 +450,7 @@ rb_ssl_start_connected(rb_fde_t *F, CNCB * callback, void *data, int timeout)
rb_settimeout(F, sconn->timeout, rb_ssl_tryconn_timeout_cb, sconn); rb_settimeout(F, sconn->timeout, rb_ssl_tryconn_timeout_cb, sconn);
if(do_ssl_handshake(F, rb_ssl_tryconn_cb)) if(do_ssl_handshake(F, rb_ssl_tryconn_cb)) {
{
rb_ssl_connect_realcb(F, RB_OK, sconn); rb_ssl_connect_realcb(F, RB_OK, sconn);
} }
} }
@ -521,20 +499,17 @@ rb_get_ssl_certfp(rb_fde_t *F, uint8_t certfp[RB_SSL_CERTFP_LEN])
cert_list_size = 0; cert_list_size = 0;
cert_list = gnutls_certificate_get_peers(SSL_P(F), &cert_list_size); cert_list = gnutls_certificate_get_peers(SSL_P(F), &cert_list_size);
if (cert_list == NULL) if (cert_list == NULL) {
{
gnutls_x509_crt_deinit(cert); gnutls_x509_crt_deinit(cert);
return 0; return 0;
} }
if (gnutls_x509_crt_import(cert, &cert_list[0], GNUTLS_X509_FMT_DER) < 0) if (gnutls_x509_crt_import(cert, &cert_list[0], GNUTLS_X509_FMT_DER) < 0) {
{
gnutls_x509_crt_deinit(cert); gnutls_x509_crt_deinit(cert);
return 0; return 0;
} }
if (gnutls_x509_crt_get_fingerprint(cert, GNUTLS_DIG_SHA1, digest, &digest_size) < 0) if (gnutls_x509_crt_get_fingerprint(cert, GNUTLS_DIG_SHA1, digest, &digest_size) < 0) {
{
gnutls_x509_crt_deinit(cert); gnutls_x509_crt_deinit(cert);
return 0; return 0;
} }

View File

@ -24,8 +24,7 @@
#include <ratbox_lib.h> #include <ratbox_lib.h>
#include <commio-int.h> #include <commio-int.h>
struct _rb_helper struct _rb_helper {
{
char *path; char *path;
buf_head_t sendq; buf_head_t sendq;
buf_head_t recvq; buf_head_t recvq;
@ -62,8 +61,7 @@ rb_helper_child(rb_helper_cb * read_cb, rb_helper_cb * error_cb, log_cb * ilog,
maxfd = (int)strtol(tmaxfd, NULL, 10); maxfd = (int)strtol(tmaxfd, NULL, 10);
#ifndef _WIN32 #ifndef _WIN32
for(x = 0; x < maxfd; x++) for(x = 0; x < maxfd; x++) {
{
if(x != ifd && x != ofd) if(x != ifd && x != ofd)
close(x); close(x);
} }
@ -119,14 +117,12 @@ rb_helper_start(const char *name, const char *fullpath, rb_helper_cb * read_cb,
helper = rb_malloc(sizeof(rb_helper)); helper = rb_malloc(sizeof(rb_helper));
rb_snprintf(buf, sizeof(buf), "%s helper - read", name); rb_snprintf(buf, sizeof(buf), "%s helper - read", name);
if(rb_pipe(&in_f[0], &in_f[1], buf) < 0) if(rb_pipe(&in_f[0], &in_f[1], buf) < 0) {
{
rb_free(helper); rb_free(helper);
return NULL; return NULL;
} }
rb_snprintf(buf, sizeof(buf), "%s helper - write", name); rb_snprintf(buf, sizeof(buf), "%s helper - write", name);
if(rb_pipe(&out_f[0], &out_f[1], buf) < 0) if(rb_pipe(&out_f[0], &out_f[1], buf) < 0) {
{
rb_free(helper); rb_free(helper);
return NULL; return NULL;
} }
@ -154,8 +150,7 @@ rb_helper_start(const char *name, const char *fullpath, rb_helper_cb * read_cb,
pid = rb_spawn_process(fullpath, (const char **)parv); pid = rb_spawn_process(fullpath, (const char **)parv);
if(pid == -1) if(pid == -1) {
{
rb_close(in_f[0]); rb_close(in_f[0]);
rb_close(in_f[1]); rb_close(in_f[1]);
rb_close(out_f[0]); rb_close(out_f[0]);
@ -194,12 +189,10 @@ rb_helper_write_sendq(rb_fde_t *F, void *helper_ptr)
rb_helper *helper = helper_ptr; rb_helper *helper = helper_ptr;
int retlen; int retlen;
if(rb_linebuf_len(&helper->sendq) > 0) if(rb_linebuf_len(&helper->sendq) > 0) {
{
while((retlen = rb_linebuf_flush(F, &helper->sendq)) > 0) while((retlen = rb_linebuf_flush(F, &helper->sendq)) > 0)
;; ;;
if(retlen == 0 || (retlen < 0 && !rb_ignore_errno(errno))) if(retlen == 0 || (retlen < 0 && !rb_ignore_errno(errno))) {
{
rb_helper_restart(helper); rb_helper_restart(helper);
return; return;
} }
@ -244,14 +237,12 @@ rb_helper_read_cb(rb_fde_t *F, void *data)
if(helper == NULL) if(helper == NULL)
return; return;
while((length = rb_read(helper->ifd, buf, sizeof(buf))) > 0) while((length = rb_read(helper->ifd, buf, sizeof(buf))) > 0) {
{
rb_linebuf_parse(&helper->recvq, buf, length, 0); rb_linebuf_parse(&helper->recvq, buf, length, 0);
helper->read_cb(helper); helper->read_cb(helper);
} }
if(length == 0 || (length < 0 && !rb_ignore_errno(errno))) if(length == 0 || (length < 0 && !rb_ignore_errno(errno))) {
{
rb_helper_restart(helper); rb_helper_restart(helper);
return; return;
} }
@ -289,8 +280,7 @@ void
rb_helper_loop(rb_helper *helper, long delay) rb_helper_loop(rb_helper *helper, long delay)
{ {
rb_helper_run(helper); rb_helper_run(helper);
while(1) while(1) {
{
rb_lib_loop(delay); rb_lib_loop(delay);
} }
} }

View File

@ -73,8 +73,7 @@ kq_update_events(rb_fde_t *F, short filter, PF * handler)
PF *cur_handler; PF *cur_handler;
int kep_flags; int kep_flags;
switch (filter) switch (filter) {
{
case EVFILT_READ: case EVFILT_READ:
cur_handler = F->read_handler; cur_handler = F->read_handler;
break; break;
@ -87,25 +86,20 @@ kq_update_events(rb_fde_t *F, short filter, PF * handler)
break; break;
} }
if((cur_handler == NULL && handler != NULL) || (cur_handler != NULL && handler == NULL)) if((cur_handler == NULL && handler != NULL) || (cur_handler != NULL && handler == NULL)) {
{
struct kevent *kep; struct kevent *kep;
kep = kqlst + kqoff; kep = kqlst + kqoff;
if(handler != NULL) if(handler != NULL) {
{
kep_flags = EV_ADD | EV_ONESHOT; kep_flags = EV_ADD | EV_ONESHOT;
} } else {
else
{
kep_flags = EV_DELETE; kep_flags = EV_DELETE;
} }
EV_SET(kep, (uintptr_t)F->fd, filter, kep_flags, 0, 0, (void *)F); EV_SET(kep, (uintptr_t)F->fd, filter, kep_flags, 0, 0, (void *)F);
if(++kqoff == kqmax) if(++kqoff == kqmax) {
{
int ret, i; int ret, i;
/* Add them one at a time, because there may be /* Add them one at a time, because there may be
@ -116,8 +110,7 @@ kq_update_events(rb_fde_t *F, short filter, PF * handler)
* because that would also return events we cannot * because that would also return events we cannot
* process at this point. * process at this point.
*/ */
for(i = 0; i < kqoff; i++) for(i = 0; i < kqoff; i++) {
{
ret = kevent(kq, kqlst + i, 1, NULL, 0, &zero_timespec); ret = kevent(kq, kqlst + i, 1, NULL, 0, &zero_timespec);
/* jdc -- someone needs to do error checking... */ /* jdc -- someone needs to do error checking... */
/* EBADF is normal here -- jilles */ /* EBADF is normal here -- jilles */
@ -146,8 +139,7 @@ int
rb_init_netio_kqueue(void) rb_init_netio_kqueue(void)
{ {
kq = kqueue(); kq = kqueue();
if(kq < 0) if(kq < 0) {
{
return errno; return errno;
} }
kqmax = getdtablesize(); kqmax = getdtablesize();
@ -171,14 +163,12 @@ rb_setselect_kqueue(rb_fde_t *F, unsigned int type, PF * handler, void *client_d
{ {
lrb_assert(IsFDOpen(F)); lrb_assert(IsFDOpen(F));
if(type & RB_SELECT_READ) if(type & RB_SELECT_READ) {
{
kq_update_events(F, EVFILT_READ, handler); kq_update_events(F, EVFILT_READ, handler);
F->read_handler = handler; F->read_handler = handler;
F->read_data = client_data; F->read_data = client_data;
} }
if(type & RB_SELECT_WRITE) if(type & RB_SELECT_WRITE) {
{
kq_update_events(F, EVFILT_WRITE, handler); kq_update_events(F, EVFILT_WRITE, handler);
F->write_handler = handler; F->write_handler = handler;
F->write_data = client_data; F->write_data = client_data;
@ -209,19 +199,15 @@ rb_select_kqueue(long delay)
rb_fde_t *F; rb_fde_t *F;
if(delay < 0) if(delay < 0) {
{
pt = NULL; pt = NULL;
} } else {
else
{
pt = &poll_time; pt = &poll_time;
poll_time.tv_sec = delay / 1000; poll_time.tv_sec = delay / 1000;
poll_time.tv_nsec = (delay % 1000) * 1000000; poll_time.tv_nsec = (delay % 1000) * 1000000;
} }
for(;;) for(;;) {
{
num = kevent(kq, kqlst, kqoff, kqout, kqmax, pt); num = kevent(kq, kqlst, kqoff, kqout, kqmax, pt);
kqoff = 0; kqoff = 0;
@ -243,24 +229,20 @@ rb_select_kqueue(long delay)
if(num == 0) if(num == 0)
return RB_OK; /* No error.. */ return RB_OK; /* No error.. */
for(i = 0; i < num; i++) for(i = 0; i < num; i++) {
{
PF *hdl = NULL; PF *hdl = NULL;
if(kqout[i].flags & EV_ERROR) if(kqout[i].flags & EV_ERROR) {
{
errno = kqout[i].data; errno = kqout[i].data;
/* XXX error == bad! -- adrian */ /* XXX error == bad! -- adrian */
continue; /* XXX! */ continue; /* XXX! */
} }
switch (kqout[i].filter) switch (kqout[i].filter) {
{
case EVFILT_READ: case EVFILT_READ:
F = kqout[i].udata; F = kqout[i].udata;
if((hdl = F->read_handler) != NULL) if((hdl = F->read_handler) != NULL) {
{
F->read_handler = NULL; F->read_handler = NULL;
hdl(F, F->read_data); hdl(F, F->read_data);
} }
@ -269,8 +251,7 @@ rb_select_kqueue(long delay)
case EVFILT_WRITE: case EVFILT_WRITE:
F = kqout[i].udata; F = kqout[i].udata;
if((hdl = F->write_handler) != NULL) if((hdl = F->write_handler) != NULL) {
{
F->write_handler = NULL; F->write_handler = NULL;
hdl(F, F->write_data); hdl(F, F->write_data);
} }
@ -308,8 +289,7 @@ rb_kqueue_supports_event(void)
EV_SET(&kv, (uintptr_t)0x0, EVFILT_TIMER, EV_ADD | EV_ONESHOT, 0, 1, 0); EV_SET(&kv, (uintptr_t)0x0, EVFILT_TIMER, EV_ADD | EV_ONESHOT, 0, 1, 0);
if(kevent(xkq, &kv, 1, NULL, 0, NULL) < 0) if(kevent(xkq, &kv, 1, NULL, 0, NULL) < 0) {
{
can_do_event = -1; can_do_event = -1;
close(xkq); close(xkq);
return 0; return 0;

View File

@ -114,8 +114,7 @@ rb_linebuf_done_line(buf_head_t * bufhead, buf_line_t * bufline, rb_dlink_node *
bufline->refcount--; bufline->refcount--;
lrb_assert(bufline->refcount >= 0); lrb_assert(bufline->refcount >= 0);
if(bufline->refcount == 0) if(bufline->refcount == 0) {
{
/* and finally, deallocate the buf */ /* and finally, deallocate the buf */
--bufline_count; --bufline_count;
lrb_assert(bufline_count >= 0); lrb_assert(bufline_count >= 0);
@ -133,8 +132,7 @@ rb_linebuf_skip_crlf(char *ch, int len)
int orig_len = len; int orig_len = len;
/* First, skip until the first non-CRLF */ /* First, skip until the first non-CRLF */
for(; len; len--, ch++) for(; len; len--, ch++) {
{
if(*ch == '\r') if(*ch == '\r')
break; break;
else if(*ch == '\n') else if(*ch == '\n')
@ -142,8 +140,7 @@ rb_linebuf_skip_crlf(char *ch, int len)
} }
/* Then, skip until the last CRLF */ /* Then, skip until the last CRLF */
for(; len; len--, ch++) for(; len; len--, ch++) {
{
if((*ch != '\r') && (*ch != '\n')) if((*ch != '\r') && (*ch != '\n'))
break; break;
} }
@ -173,8 +170,7 @@ rb_linebuf_newbuf(buf_head_t * bufhead)
void void
rb_linebuf_donebuf(buf_head_t * bufhead) rb_linebuf_donebuf(buf_head_t * bufhead)
{ {
while(bufhead->list.head != NULL) while(bufhead->list.head != NULL) {
{
rb_linebuf_done_line(bufhead, (buf_line_t *) bufhead->list.head->data, rb_linebuf_done_line(bufhead, (buf_line_t *) bufhead->list.head->data,
bufhead->list.head); bufhead->list.head);
} }
@ -221,13 +217,11 @@ rb_linebuf_copy_line(buf_head_t * bufhead, buf_line_t * bufline, char *data, int
return -1; return -1;
/* This is the ~overflow case..This doesn't happen often.. */ /* This is the ~overflow case..This doesn't happen often.. */
if(cpylen > (BUF_DATA_SIZE - bufline->len - 1)) if(cpylen > (BUF_DATA_SIZE - bufline->len - 1)) {
{
memcpy(bufch, ch, (BUF_DATA_SIZE - bufline->len - 1)); memcpy(bufch, ch, (BUF_DATA_SIZE - bufline->len - 1));
bufline->buf[BUF_DATA_SIZE - 1] = '\0'; bufline->buf[BUF_DATA_SIZE - 1] = '\0';
bufch = bufline->buf + BUF_DATA_SIZE - 2; bufch = bufline->buf + BUF_DATA_SIZE - 2;
while(cpylen && (*bufch == '\r' || *bufch == '\n')) while(cpylen && (*bufch == '\r' || *bufch == '\n')) {
{
*bufch = '\0'; *bufch = '\0';
cpylen--; cpylen--;
bufch--; bufch--;
@ -243,8 +237,7 @@ rb_linebuf_copy_line(buf_head_t * bufhead, buf_line_t * bufline, char *data, int
*bufch = '\0'; *bufch = '\0';
bufch--; bufch--;
if(*bufch != '\r' && *bufch != '\n') if(*bufch != '\r' && *bufch != '\n') {
{
/* No linefeed, bail for the next time */ /* No linefeed, bail for the next time */
bufhead->len += cpylen; bufhead->len += cpylen;
bufline->len += cpylen; bufline->len += cpylen;
@ -253,8 +246,7 @@ rb_linebuf_copy_line(buf_head_t * bufhead, buf_line_t * bufline, char *data, int
} }
/* Yank the CRLF off this, replace with a \0 */ /* Yank the CRLF off this, replace with a \0 */
while(cpylen && (*bufch == '\r' || *bufch == '\n')) while(cpylen && (*bufch == '\r' || *bufch == '\n')) {
{
*bufch = '\0'; *bufch = '\0';
cpylen--; cpylen--;
bufch--; bufch--;
@ -294,8 +286,7 @@ rb_linebuf_copy_raw(buf_head_t * bufhead, buf_line_t * bufline, char *data, int
return -1; return -1;
/* This is the overflow case..This doesn't happen often.. */ /* This is the overflow case..This doesn't happen often.. */
if(cpylen > (BUF_DATA_SIZE - bufline->len - 1)) if(cpylen > (BUF_DATA_SIZE - bufline->len - 1)) {
{
clen = BUF_DATA_SIZE - bufline->len - 1; clen = BUF_DATA_SIZE - bufline->len - 1;
memcpy(bufch, ch, clen); memcpy(bufch, ch, clen);
bufline->buf[BUF_DATA_SIZE - 1] = '\0'; bufline->buf[BUF_DATA_SIZE - 1] = '\0';
@ -311,8 +302,7 @@ rb_linebuf_copy_raw(buf_head_t * bufhead, buf_line_t * bufline, char *data, int
*bufch = '\0'; *bufch = '\0';
bufch--; bufch--;
if(*bufch != '\r' && *bufch != '\n') if(*bufch != '\r' && *bufch != '\n') {
{
/* No linefeed, bail for the next time */ /* No linefeed, bail for the next time */
bufhead->len += cpylen; bufhead->len += cpylen;
bufline->len += cpylen; bufline->len += cpylen;
@ -352,8 +342,7 @@ rb_linebuf_parse(buf_head_t * bufhead, char *data, int len, int raw)
int linecnt = 0; int linecnt = 0;
/* First, if we have a partial buffer, try to squeze data into it */ /* First, if we have a partial buffer, try to squeze data into it */
if(bufhead->list.tail != NULL) if(bufhead->list.tail != NULL) {
{
/* Check we're doing the partial buffer thing */ /* Check we're doing the partial buffer thing */
bufline = bufhead->list.tail->data; bufline = bufhead->list.tail->data;
/* just try, the worst it could do is *reject* us .. */ /* just try, the worst it could do is *reject* us .. */
@ -377,8 +366,7 @@ rb_linebuf_parse(buf_head_t * bufhead, char *data, int len, int raw)
} }
/* Next, the loop */ /* Next, the loop */
while(len > 0) while(len > 0) {
{
/* We obviously need a new buffer, so .. */ /* We obviously need a new buffer, so .. */
bufline = rb_linebuf_new_line(bufhead); bufline = rb_linebuf_new_line(bufhead);
@ -434,18 +422,15 @@ rb_linebuf_get(buf_head_t * bufhead, char *buf, int buflen, int partial, int raw
/* if we left extraneous '\r\n' characters in the string, /* if we left extraneous '\r\n' characters in the string,
* and we don't want to read the raw data, clean up the string. * and we don't want to read the raw data, clean up the string.
*/ */
if(bufline->raw && !raw) if(bufline->raw && !raw) {
{
/* skip leading EOL characters */ /* skip leading EOL characters */
while(cpylen && (*start == '\r' || *start == '\n')) while(cpylen && (*start == '\r' || *start == '\n')) {
{
start++; start++;
cpylen--; cpylen--;
} }
/* skip trailing EOL characters */ /* skip trailing EOL characters */
ch = &start[cpylen - 1]; ch = &start[cpylen - 1];
while(cpylen && (*ch == '\r' || *ch == '\n')) while(cpylen && (*ch == '\r' || *ch == '\n')) {
{
ch--; ch--;
cpylen--; cpylen--;
} }
@ -478,8 +463,7 @@ rb_linebuf_attach(buf_head_t * bufhead, buf_head_t * new)
rb_dlink_node *ptr; rb_dlink_node *ptr;
buf_line_t *line; buf_line_t *line;
RB_DLINK_FOREACH(ptr, new->list.head) RB_DLINK_FOREACH(ptr, new->list.head) {
{
line = ptr->data; line = ptr->data;
rb_dlinkAddTailAlloc(line, &bufhead->list); rb_dlinkAddTailAlloc(line, &bufhead->list);
@ -512,8 +496,7 @@ rb_linebuf_putmsg(buf_head_t * bufhead, const char *format, va_list * va_args,
/* make sure the previous line is terminated */ /* make sure the previous line is terminated */
#ifndef NDEBUG #ifndef NDEBUG
if(bufhead->list.tail) if(bufhead->list.tail) {
{
bufline = bufhead->list.tail->data; bufline = bufhead->list.tail->data;
lrb_assert(bufline->terminated); lrb_assert(bufline->terminated);
} }
@ -521,39 +504,31 @@ rb_linebuf_putmsg(buf_head_t * bufhead, const char *format, va_list * va_args,
/* Create a new line */ /* Create a new line */
bufline = rb_linebuf_new_line(bufhead); bufline = rb_linebuf_new_line(bufhead);
if(prefixfmt != NULL) if(prefixfmt != NULL) {
{
va_start(prefix_args, prefixfmt); va_start(prefix_args, prefixfmt);
len = rb_vsnprintf(bufline->buf, BUF_DATA_SIZE, prefixfmt, prefix_args); len = rb_vsnprintf(bufline->buf, BUF_DATA_SIZE, prefixfmt, prefix_args);
va_end(prefix_args); va_end(prefix_args);
} }
if(va_args != NULL) if(va_args != NULL) {
{
len += rb_vsnprintf((bufline->buf + len), (BUF_DATA_SIZE - len), format, *va_args); len += rb_vsnprintf((bufline->buf + len), (BUF_DATA_SIZE - len), format, *va_args);
} }
bufline->terminated = 1; bufline->terminated = 1;
/* Truncate the data if required */ /* Truncate the data if required */
if(rb_unlikely(len > 510)) if(rb_unlikely(len > 510)) {
{
len = 510; len = 510;
bufline->buf[len++] = '\r'; bufline->buf[len++] = '\r';
bufline->buf[len++] = '\n'; bufline->buf[len++] = '\n';
} } else if(rb_unlikely(len == 0)) {
else if(rb_unlikely(len == 0))
{
bufline->buf[len++] = '\r'; bufline->buf[len++] = '\r';
bufline->buf[len++] = '\n'; bufline->buf[len++] = '\n';
bufline->buf[len] = '\0'; bufline->buf[len] = '\0';
} } else {
else
{
/* Chop trailing CRLF's .. */ /* Chop trailing CRLF's .. */
while((bufline->buf[len] == '\r') || (bufline->buf[len] == '\n') while((bufline->buf[len] == '\r') || (bufline->buf[len] == '\n')
|| (bufline->buf[len] == '\0')) || (bufline->buf[len] == '\0')) {
{
len--; len--;
} }
@ -574,8 +549,7 @@ rb_linebuf_putbuf(buf_head_t * bufhead, const char *buffer)
/* make sure the previous line is terminated */ /* make sure the previous line is terminated */
#ifndef NDEBUG #ifndef NDEBUG
if(bufhead->list.tail) if(bufhead->list.tail) {
{
bufline = bufhead->list.tail->data; bufline = bufhead->list.tail->data;
lrb_assert(bufline->terminated); lrb_assert(bufline->terminated);
} }
@ -589,24 +563,18 @@ rb_linebuf_putbuf(buf_head_t * bufhead, const char *buffer)
bufline->terminated = 1; bufline->terminated = 1;
/* Truncate the data if required */ /* Truncate the data if required */
if(rb_unlikely(len > 510)) if(rb_unlikely(len > 510)) {
{
len = 510; len = 510;
bufline->buf[len++] = '\r'; bufline->buf[len++] = '\r';
bufline->buf[len++] = '\n'; bufline->buf[len++] = '\n';
} } else if(rb_unlikely(len == 0)) {
else if(rb_unlikely(len == 0))
{
bufline->buf[len++] = '\r'; bufline->buf[len++] = '\r';
bufline->buf[len++] = '\n'; bufline->buf[len++] = '\n';
bufline->buf[len] = '\0'; bufline->buf[len] = '\0';
} } else {
else
{
/* Chop trailing CRLF's .. */ /* Chop trailing CRLF's .. */
while((bufline->buf[len] == '\r') || (bufline->buf[len] == '\n') while((bufline->buf[len] == '\r') || (bufline->buf[len] == '\n')
|| (bufline->buf[len] == '\0')) || (bufline->buf[len] == '\0')) {
{
len--; len--;
} }
@ -630,8 +598,7 @@ rb_linebuf_put(buf_head_t * bufhead, const char *format, ...)
/* make sure the previous line is terminated */ /* make sure the previous line is terminated */
#ifndef NDEBUG #ifndef NDEBUG
if(bufhead->list.tail) if(bufhead->list.tail) {
{
bufline = bufhead->list.tail->data; bufline = bufhead->list.tail->data;
lrb_assert(bufline->terminated); lrb_assert(bufline->terminated);
} }
@ -639,8 +606,7 @@ rb_linebuf_put(buf_head_t * bufhead, const char *format, ...)
/* Create a new line */ /* Create a new line */
bufline = rb_linebuf_new_line(bufhead); bufline = rb_linebuf_new_line(bufhead);
if(rb_unlikely(format != NULL)) if(rb_unlikely(format != NULL)) {
{
va_start(args, format); va_start(args, format);
len = rb_vsnprintf(bufline->buf, BUF_DATA_SIZE, format, args); len = rb_vsnprintf(bufline->buf, BUF_DATA_SIZE, format, args);
va_end(args); va_end(args);
@ -649,24 +615,18 @@ rb_linebuf_put(buf_head_t * bufhead, const char *format, ...)
bufline->terminated = 1; bufline->terminated = 1;
/* Truncate the data if required */ /* Truncate the data if required */
if(rb_unlikely(len > 510)) if(rb_unlikely(len > 510)) {
{
len = 510; len = 510;
bufline->buf[len++] = '\r'; bufline->buf[len++] = '\r';
bufline->buf[len++] = '\n'; bufline->buf[len++] = '\n';
} } else if(rb_unlikely(len == 0)) {
else if(rb_unlikely(len == 0))
{
bufline->buf[len++] = '\r'; bufline->buf[len++] = '\r';
bufline->buf[len++] = '\n'; bufline->buf[len++] = '\n';
bufline->buf[len] = '\0'; bufline->buf[len] = '\0';
} } else {
else
{
/* Chop trailing CRLF's .. */ /* Chop trailing CRLF's .. */
while((bufline->buf[len] == '\r') || (bufline->buf[len] == '\n') while((bufline->buf[len] == '\r') || (bufline->buf[len] == '\n')
|| (bufline->buf[len] == '\0')) || (bufline->buf[len] == '\0')) {
{
len--; len--;
} }
@ -699,13 +659,12 @@ rb_linebuf_flush(rb_fde_t *F, buf_head_t * bufhead)
buf_line_t *bufline; buf_line_t *bufline;
int retval; int retval;
/* /*
* autoconf checks for this..but really just want to use it if we have a * autoconf checks for this..but really just want to use it if we have a
* native version even if libircd provides a fake version... * native version even if libircd provides a fake version...
*/ */
#ifdef HAVE_WRITEV #ifdef HAVE_WRITEV
if(!rb_fd_ssl(F)) if(!rb_fd_ssl(F)) {
{
rb_dlink_node *ptr; rb_dlink_node *ptr;
int x = 0, y; int x = 0, y;
int xret; int xret;
@ -713,8 +672,7 @@ rb_linebuf_flush(rb_fde_t *F, buf_head_t * bufhead)
memset(vec, 0, sizeof(vec)); memset(vec, 0, sizeof(vec));
/* Check we actually have a first buffer */ /* Check we actually have a first buffer */
if(bufhead->list.head == NULL) if(bufhead->list.head == NULL) {
{
/* nope, so we return none .. */ /* nope, so we return none .. */
errno = EWOULDBLOCK; errno = EWOULDBLOCK;
return -1; return -1;
@ -723,8 +681,7 @@ rb_linebuf_flush(rb_fde_t *F, buf_head_t * bufhead)
ptr = bufhead->list.head; ptr = bufhead->list.head;
bufline = ptr->data; bufline = ptr->data;
if(!bufline->terminated) if(!bufline->terminated) {
{
errno = EWOULDBLOCK; errno = EWOULDBLOCK;
return -1; return -1;
@ -734,8 +691,7 @@ rb_linebuf_flush(rb_fde_t *F, buf_head_t * bufhead)
vec[x++].iov_len = bufline->len - bufhead->writeofs; vec[x++].iov_len = bufline->len - bufhead->writeofs;
ptr = ptr->next; ptr = ptr->next;
do do {
{
if(ptr == NULL) if(ptr == NULL)
break; break;
@ -747,11 +703,9 @@ rb_linebuf_flush(rb_fde_t *F, buf_head_t * bufhead)
vec[x].iov_len = bufline->len; vec[x].iov_len = bufline->len;
ptr = ptr->next; ptr = ptr->next;
} } while(++x < RB_UIO_MAXIOV);
while(++x < RB_UIO_MAXIOV);
if(x == 0) if(x == 0) {
{
errno = EWOULDBLOCK; errno = EWOULDBLOCK;
return -1; return -1;
} }
@ -762,19 +716,15 @@ rb_linebuf_flush(rb_fde_t *F, buf_head_t * bufhead)
ptr = bufhead->list.head; ptr = bufhead->list.head;
for(y = 0; y < x; y++) for(y = 0; y < x; y++) {
{
bufline = ptr->data; bufline = ptr->data;
if(xret >= bufline->len - bufhead->writeofs) if(xret >= bufline->len - bufhead->writeofs) {
{
xret -= bufline->len - bufhead->writeofs; xret -= bufline->len - bufhead->writeofs;
ptr = ptr->next; ptr = ptr->next;
rb_linebuf_done_line(bufhead, bufline, bufhead->list.head); rb_linebuf_done_line(bufhead, bufline, bufhead->list.head);
bufhead->writeofs = 0; bufhead->writeofs = 0;
} } else {
else
{
bufhead->writeofs += xret; bufhead->writeofs += xret;
break; break;
} }
@ -787,8 +737,7 @@ rb_linebuf_flush(rb_fde_t *F, buf_head_t * bufhead)
/* this is the non-writev case */ /* this is the non-writev case */
/* Check we actually have a first buffer */ /* Check we actually have a first buffer */
if(bufhead->list.head == NULL) if(bufhead->list.head == NULL) {
{
/* nope, so we return none .. */ /* nope, so we return none .. */
errno = EWOULDBLOCK; errno = EWOULDBLOCK;
return -1; return -1;
@ -797,8 +746,7 @@ rb_linebuf_flush(rb_fde_t *F, buf_head_t * bufhead)
bufline = bufhead->list.head->data; bufline = bufhead->list.head->data;
/* And that its actually full .. */ /* And that its actually full .. */
if(!bufline->terminated) if(!bufline->terminated) {
{
errno = EWOULDBLOCK; errno = EWOULDBLOCK;
return -1; return -1;
} }
@ -814,8 +762,7 @@ rb_linebuf_flush(rb_fde_t *F, buf_head_t * bufhead)
/* if we've written everything *and* the CRLF, deallocate and update /* if we've written everything *and* the CRLF, deallocate and update
bufhead */ bufhead */
if(bufhead->writeofs == bufline->len) if(bufhead->writeofs == bufline->len) {
{
bufhead->writeofs = 0; bufhead->writeofs = 0;
lrb_assert(bufhead->len >= 0); lrb_assert(bufhead->len >= 0);
rb_linebuf_done_line(bufhead, bufline, bufhead->list.head); rb_linebuf_done_line(bufhead, bufline, bufhead->list.head);

View File

@ -75,8 +75,7 @@ rb_get_random(void *buf, size_t length)
{ {
uint32_t rnd = 0, i; uint32_t rnd = 0, i;
uint8_t *xbuf = buf; uint8_t *xbuf = buf;
for(i = 0; i < length; i++) for(i = 0; i < length; i++) {
{
if(i % 4 == 0) if(i % 4 == 0)
rnd = arc4random(); rnd = arc4random();
xbuf[i] = rnd; xbuf[i] = rnd;

View File

@ -60,8 +60,7 @@ rb_ssl_shutdown(rb_fde_t *F)
return; return;
SSL_set_shutdown((SSL *) F->ssl, SSL_RECEIVED_SHUTDOWN); SSL_set_shutdown((SSL *) F->ssl, SSL_RECEIVED_SHUTDOWN);
for(i = 0; i < 4; i++) for(i = 0; i < 4; i++) {
{
if(SSL_shutdown((SSL *) F->ssl)) if(SSL_shutdown((SSL *) F->ssl))
break; break;
} }
@ -92,8 +91,7 @@ rb_ssl_timeout(rb_fde_t *F, void *notused)
static void static void
rb_ssl_info_callback(SSL * ssl, int where, int ret) rb_ssl_info_callback(SSL * ssl, int where, int ret)
{ {
if(where & SSL_CB_HANDSHAKE_START) if(where & SSL_CB_HANDSHAKE_START) {
{
rb_fde_t *F = SSL_get_ex_data(ssl, libratbox_index); rb_fde_t *F = SSL_get_ex_data(ssl, libratbox_index);
if(F == NULL) if(F == NULL)
return; return;
@ -116,12 +114,9 @@ rb_ssl_tryaccept(rb_fde_t *F, void *data)
int flags; int flags;
struct acceptdata *ad; struct acceptdata *ad;
if(!SSL_is_init_finished((SSL *) F->ssl)) if(!SSL_is_init_finished((SSL *) F->ssl)) {
{ if((ssl_err = SSL_accept((SSL *) F->ssl)) <= 0) {
if((ssl_err = SSL_accept((SSL *) F->ssl)) <= 0) switch (ssl_err = SSL_get_error((SSL *) F->ssl, ssl_err)) {
{
switch (ssl_err = SSL_get_error((SSL *) F->ssl, ssl_err))
{
case SSL_ERROR_WANT_READ: case SSL_ERROR_WANT_READ:
case SSL_ERROR_WANT_WRITE: case SSL_ERROR_WANT_WRITE:
if(ssl_err == SSL_ERROR_WANT_WRITE) if(ssl_err == SSL_ERROR_WANT_WRITE)
@ -157,15 +152,12 @@ static void
rb_ssl_accept_common(rb_fde_t *new_F) rb_ssl_accept_common(rb_fde_t *new_F)
{ {
int ssl_err; int ssl_err;
if((ssl_err = SSL_accept((SSL *) new_F->ssl)) <= 0) if((ssl_err = SSL_accept((SSL *) new_F->ssl)) <= 0) {
{ switch (ssl_err = SSL_get_error((SSL *) new_F->ssl, ssl_err)) {
switch (ssl_err = SSL_get_error((SSL *) new_F->ssl, ssl_err))
{
case SSL_ERROR_SYSCALL: case SSL_ERROR_SYSCALL:
if(rb_ignore_errno(errno)) if(rb_ignore_errno(errno))
case SSL_ERROR_WANT_READ: case SSL_ERROR_WANT_READ:
case SSL_ERROR_WANT_WRITE: case SSL_ERROR_WANT_WRITE: {
{
new_F->ssl_errno = get_last_err(); new_F->ssl_errno = get_last_err();
rb_setselect(new_F, RB_SELECT_READ | RB_SELECT_WRITE, rb_setselect(new_F, RB_SELECT_READ | RB_SELECT_WRITE,
rb_ssl_tryaccept, NULL); rb_ssl_tryaccept, NULL);
@ -176,9 +168,7 @@ rb_ssl_accept_common(rb_fde_t *new_F)
new_F->accept->callback(new_F, RB_ERROR_SSL, NULL, 0, new_F->accept->data); new_F->accept->callback(new_F, RB_ERROR_SSL, NULL, 0, new_F->accept->data);
return; return;
} }
} } else {
else
{
rb_ssl_tryaccept(new_F, NULL); rb_ssl_tryaccept(new_F, NULL);
} }
} }
@ -233,10 +223,8 @@ rb_ssl_read_or_write(int r_or_w, rb_fde_t *F, void *rbuf, const void *wbuf, size
else else
ret = (ssize_t) SSL_write(ssl, wbuf, (int)count); ret = (ssize_t) SSL_write(ssl, wbuf, (int)count);
if(ret < 0) if(ret < 0) {
{ switch (SSL_get_error(ssl, ret)) {
switch (SSL_get_error(ssl, ret))
{
case SSL_ERROR_WANT_READ: case SSL_ERROR_WANT_READ:
errno = EAGAIN; errno = EAGAIN;
return RB_RW_SSL_NEED_READ; return RB_RW_SSL_NEED_READ;
@ -247,8 +235,7 @@ rb_ssl_read_or_write(int r_or_w, rb_fde_t *F, void *rbuf, const void *wbuf, size
return 0; return 0;
case SSL_ERROR_SYSCALL: case SSL_ERROR_SYSCALL:
err = get_last_err(); err = get_last_err();
if(err == 0) if(err == 0) {
{
F->ssl_errno = 0; F->ssl_errno = 0;
return RB_RW_IO_ERROR; return RB_RW_IO_ERROR;
} }
@ -258,8 +245,7 @@ rb_ssl_read_or_write(int r_or_w, rb_fde_t *F, void *rbuf, const void *wbuf, size
break; break;
} }
F->ssl_errno = err; F->ssl_errno = err;
if(err > 0) if(err > 0) {
{
errno = EIO; /* not great but... */ errno = EIO; /* not great but... */
return RB_RW_SSL_ERROR; return RB_RW_SSL_ERROR;
} }
@ -304,8 +290,7 @@ rb_init_ssl(void)
SSL_library_init(); SSL_library_init();
libratbox_index = SSL_get_ex_new_index(0, libratbox_data, NULL, NULL, NULL); libratbox_index = SSL_get_ex_new_index(0, libratbox_data, NULL, NULL, NULL);
ssl_server_ctx = SSL_CTX_new(SSLv23_server_method()); ssl_server_ctx = SSL_CTX_new(SSLv23_server_method());
if(ssl_server_ctx == NULL) if(ssl_server_ctx == NULL) {
{
rb_lib_log("rb_init_openssl: Unable to initialize OpenSSL server context: %s", rb_lib_log("rb_init_openssl: Unable to initialize OpenSSL server context: %s",
get_ssl_error(ERR_get_error())); get_ssl_error(ERR_get_error()));
ret = 0; ret = 0;
@ -316,8 +301,7 @@ rb_init_ssl(void)
ssl_client_ctx = SSL_CTX_new(TLSv1_client_method()); ssl_client_ctx = SSL_CTX_new(TLSv1_client_method());
if(ssl_client_ctx == NULL) if(ssl_client_ctx == NULL) {
{
rb_lib_log("rb_init_openssl: Unable to initialize OpenSSL client context: %s", rb_lib_log("rb_init_openssl: Unable to initialize OpenSSL client context: %s",
get_ssl_error(ERR_get_error())); get_ssl_error(ERR_get_error()));
ret = 0; ret = 0;
@ -331,43 +315,36 @@ rb_setup_ssl_server(const char *cert, const char *keyfile, const char *dhfile)
{ {
DH *dh; DH *dh;
unsigned long err; unsigned long err;
if(cert == NULL) if(cert == NULL) {
{
rb_lib_log("rb_setup_ssl_server: No certificate file"); rb_lib_log("rb_setup_ssl_server: No certificate file");
return 0; return 0;
} }
if(!SSL_CTX_use_certificate_chain_file(ssl_server_ctx, cert) || !SSL_CTX_use_certificate_chain_file(ssl_client_ctx, cert)) if(!SSL_CTX_use_certificate_chain_file(ssl_server_ctx, cert) || !SSL_CTX_use_certificate_chain_file(ssl_client_ctx, cert)) {
{
err = ERR_get_error(); err = ERR_get_error();
rb_lib_log("rb_setup_ssl_server: Error loading certificate file [%s]: %s", cert, rb_lib_log("rb_setup_ssl_server: Error loading certificate file [%s]: %s", cert,
get_ssl_error(err)); get_ssl_error(err));
return 0; return 0;
} }
if(keyfile == NULL) if(keyfile == NULL) {
{
rb_lib_log("rb_setup_ssl_server: No key file"); rb_lib_log("rb_setup_ssl_server: No key file");
return 0; return 0;
} }
if(!SSL_CTX_use_PrivateKey_file(ssl_server_ctx, keyfile, SSL_FILETYPE_PEM) || !SSL_CTX_use_PrivateKey_file(ssl_client_ctx, keyfile, SSL_FILETYPE_PEM)) if(!SSL_CTX_use_PrivateKey_file(ssl_server_ctx, keyfile, SSL_FILETYPE_PEM) || !SSL_CTX_use_PrivateKey_file(ssl_client_ctx, keyfile, SSL_FILETYPE_PEM)) {
{
err = ERR_get_error(); err = ERR_get_error();
rb_lib_log("rb_setup_ssl_server: Error loading keyfile [%s]: %s", keyfile, rb_lib_log("rb_setup_ssl_server: Error loading keyfile [%s]: %s", keyfile,
get_ssl_error(err)); get_ssl_error(err));
return 0; return 0;
} }
if(dhfile != NULL) if(dhfile != NULL) {
{
/* DH parameters aren't necessary, but they are nice..if they didn't pass one..that is their problem */ /* DH parameters aren't necessary, but they are nice..if they didn't pass one..that is their problem */
BIO *bio = BIO_new_file(dhfile, "r"); BIO *bio = BIO_new_file(dhfile, "r");
if(bio != NULL) if(bio != NULL) {
{
dh = PEM_read_bio_DHparams(bio, NULL, NULL, NULL); dh = PEM_read_bio_DHparams(bio, NULL, NULL, NULL);
if(dh == NULL) if(dh == NULL) {
{
err = ERR_get_error(); err = ERR_get_error();
rb_lib_log rb_lib_log
("rb_setup_ssl_server: Error loading DH params file [%s]: %s", ("rb_setup_ssl_server: Error loading DH params file [%s]: %s",
@ -377,9 +354,7 @@ rb_setup_ssl_server(const char *cert, const char *keyfile, const char *dhfile)
} }
BIO_free(bio); BIO_free(bio);
SSL_CTX_set_tmp_dh(ssl_server_ctx, dh); SSL_CTX_set_tmp_dh(ssl_server_ctx, dh);
} } else {
else
{
err = ERR_get_error(); err = ERR_get_error();
rb_lib_log("rb_setup_ssl_server: Error loading DH params file [%s]: %s", rb_lib_log("rb_setup_ssl_server: Error loading DH params file [%s]: %s",
dhfile, get_ssl_error(err)); dhfile, get_ssl_error(err));
@ -399,8 +374,7 @@ rb_ssl_listen(rb_fde_t *F, int backlog, int defer_accept)
return result; return result;
} }
struct ssl_connect struct ssl_connect {
{
CNCB *callback; CNCB *callback;
void *data; void *data;
int timeout; int timeout;
@ -426,17 +400,13 @@ rb_ssl_tryconn_cb(rb_fde_t *F, void *data)
{ {
struct ssl_connect *sconn = data; struct ssl_connect *sconn = data;
int ssl_err; int ssl_err;
if(!SSL_is_init_finished((SSL *) F->ssl)) if(!SSL_is_init_finished((SSL *) F->ssl)) {
{ if((ssl_err = SSL_connect((SSL *) F->ssl)) <= 0) {
if((ssl_err = SSL_connect((SSL *) F->ssl)) <= 0) switch (ssl_err = SSL_get_error((SSL *) F->ssl, ssl_err)) {
{
switch (ssl_err = SSL_get_error((SSL *) F->ssl, ssl_err))
{
case SSL_ERROR_SYSCALL: case SSL_ERROR_SYSCALL:
if(rb_ignore_errno(errno)) if(rb_ignore_errno(errno))
case SSL_ERROR_WANT_READ: case SSL_ERROR_WANT_READ:
case SSL_ERROR_WANT_WRITE: case SSL_ERROR_WANT_WRITE: {
{
F->ssl_errno = get_last_err(); F->ssl_errno = get_last_err();
rb_setselect(F, RB_SELECT_READ | RB_SELECT_WRITE, rb_setselect(F, RB_SELECT_READ | RB_SELECT_WRITE,
rb_ssl_tryconn_cb, sconn); rb_ssl_tryconn_cb, sconn);
@ -447,9 +417,7 @@ rb_ssl_tryconn_cb(rb_fde_t *F, void *data)
rb_ssl_connect_realcb(F, RB_ERROR_SSL, sconn); rb_ssl_connect_realcb(F, RB_ERROR_SSL, sconn);
return; return;
} }
} } else {
else
{
rb_ssl_connect_realcb(F, RB_OK, sconn); rb_ssl_connect_realcb(F, RB_OK, sconn);
} }
} }
@ -460,8 +428,7 @@ rb_ssl_tryconn(rb_fde_t *F, int status, void *data)
{ {
struct ssl_connect *sconn = data; struct ssl_connect *sconn = data;
int ssl_err; int ssl_err;
if(status != RB_OK) if(status != RB_OK) {
{
rb_ssl_connect_realcb(F, status, sconn); rb_ssl_connect_realcb(F, status, sconn);
return; return;
} }
@ -471,15 +438,12 @@ rb_ssl_tryconn(rb_fde_t *F, int status, void *data)
SSL_set_fd((SSL *) F->ssl, F->fd); SSL_set_fd((SSL *) F->ssl, F->fd);
rb_setup_ssl_cb(F); rb_setup_ssl_cb(F);
rb_settimeout(F, sconn->timeout, rb_ssl_tryconn_timeout_cb, sconn); rb_settimeout(F, sconn->timeout, rb_ssl_tryconn_timeout_cb, sconn);
if((ssl_err = SSL_connect((SSL *) F->ssl)) <= 0) if((ssl_err = SSL_connect((SSL *) F->ssl)) <= 0) {
{ switch (ssl_err = SSL_get_error((SSL *) F->ssl, ssl_err)) {
switch (ssl_err = SSL_get_error((SSL *) F->ssl, ssl_err))
{
case SSL_ERROR_SYSCALL: case SSL_ERROR_SYSCALL:
if(rb_ignore_errno(errno)) if(rb_ignore_errno(errno))
case SSL_ERROR_WANT_READ: case SSL_ERROR_WANT_READ:
case SSL_ERROR_WANT_WRITE: case SSL_ERROR_WANT_WRITE: {
{
F->ssl_errno = get_last_err(); F->ssl_errno = get_last_err();
rb_setselect(F, RB_SELECT_READ | RB_SELECT_WRITE, rb_setselect(F, RB_SELECT_READ | RB_SELECT_WRITE,
rb_ssl_tryconn_cb, sconn); rb_ssl_tryconn_cb, sconn);
@ -490,9 +454,7 @@ rb_ssl_tryconn(rb_fde_t *F, int status, void *data)
rb_ssl_connect_realcb(F, RB_ERROR_SSL, sconn); rb_ssl_connect_realcb(F, RB_ERROR_SSL, sconn);
return; return;
} }
} } else {
else
{
rb_ssl_connect_realcb(F, RB_OK, sconn); rb_ssl_connect_realcb(F, RB_OK, sconn);
} }
} }
@ -534,15 +496,12 @@ rb_ssl_start_connected(rb_fde_t *F, CNCB * callback, void *data, int timeout)
SSL_set_fd((SSL *) F->ssl, F->fd); SSL_set_fd((SSL *) F->ssl, F->fd);
rb_setup_ssl_cb(F); rb_setup_ssl_cb(F);
rb_settimeout(F, sconn->timeout, rb_ssl_tryconn_timeout_cb, sconn); rb_settimeout(F, sconn->timeout, rb_ssl_tryconn_timeout_cb, sconn);
if((ssl_err = SSL_connect((SSL *) F->ssl)) <= 0) if((ssl_err = SSL_connect((SSL *) F->ssl)) <= 0) {
{ switch (ssl_err = SSL_get_error((SSL *) F->ssl, ssl_err)) {
switch (ssl_err = SSL_get_error((SSL *) F->ssl, ssl_err))
{
case SSL_ERROR_SYSCALL: case SSL_ERROR_SYSCALL:
if(rb_ignore_errno(errno)) if(rb_ignore_errno(errno))
case SSL_ERROR_WANT_READ: case SSL_ERROR_WANT_READ:
case SSL_ERROR_WANT_WRITE: case SSL_ERROR_WANT_WRITE: {
{
F->ssl_errno = get_last_err(); F->ssl_errno = get_last_err();
rb_setselect(F, RB_SELECT_READ | RB_SELECT_WRITE, rb_setselect(F, RB_SELECT_READ | RB_SELECT_WRITE,
rb_ssl_tryconn_cb, sconn); rb_ssl_tryconn_cb, sconn);
@ -553,9 +512,7 @@ rb_ssl_start_connected(rb_fde_t *F, CNCB * callback, void *data, int timeout)
rb_ssl_connect_realcb(F, RB_ERROR_SSL, sconn); rb_ssl_connect_realcb(F, RB_ERROR_SSL, sconn);
return; return;
} }
} } else {
else
{
rb_ssl_connect_realcb(F, RB_OK, sconn); rb_ssl_connect_realcb(F, RB_OK, sconn);
} }
} }
@ -563,8 +520,7 @@ rb_ssl_start_connected(rb_fde_t *F, CNCB * callback, void *data, int timeout)
int int
rb_init_prng(const char *path, prng_seed_t seed_type) rb_init_prng(const char *path, prng_seed_t seed_type)
{ {
if(seed_type == RB_PRNG_DEFAULT) if(seed_type == RB_PRNG_DEFAULT) {
{
#ifdef _WIN32 #ifdef _WIN32
RAND_screen(); RAND_screen();
#endif #endif
@ -573,8 +529,7 @@ rb_init_prng(const char *path, prng_seed_t seed_type)
if(path == NULL) if(path == NULL)
return RAND_status(); return RAND_status();
switch (seed_type) switch (seed_type) {
{
case RB_PRNG_EGD: case RB_PRNG_EGD:
if(RAND_egd(path) == -1) if(RAND_egd(path) == -1)
return -1; return -1;
@ -600,8 +555,7 @@ rb_get_random(void *buf, size_t length)
{ {
int ret; int ret;
if((ret = RAND_bytes(buf, length)) == 0) if((ret = RAND_bytes(buf, length)) == 0) {
{
/* remove the error from the queue */ /* remove the error from the queue */
ERR_get_error(); ERR_get_error();
} }
@ -634,14 +588,12 @@ rb_get_ssl_certfp(rb_fde_t *F, uint8_t certfp[RB_SSL_CERTFP_LEN])
return 0; return 0;
cert = SSL_get_peer_certificate((SSL *) F->ssl); cert = SSL_get_peer_certificate((SSL *) F->ssl);
if(cert != NULL) if(cert != NULL) {
{
res = SSL_get_verify_result((SSL *) F->ssl); res = SSL_get_verify_result((SSL *) F->ssl);
if(res == X509_V_OK || if(res == X509_V_OK ||
res == X509_V_ERR_SELF_SIGNED_CERT_IN_CHAIN || res == X509_V_ERR_SELF_SIGNED_CERT_IN_CHAIN ||
res == X509_V_ERR_UNABLE_TO_VERIFY_LEAF_SIGNATURE || res == X509_V_ERR_UNABLE_TO_VERIFY_LEAF_SIGNATURE ||
res == X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT) res == X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT) {
{
memcpy(certfp, cert->sha1_hash, RB_SSL_CERTFP_LEN); memcpy(certfp, cert->sha1_hash, RB_SSL_CERTFP_LEN);
X509_free(cert); X509_free(cert);
return 1; return 1;

View File

@ -53,8 +53,7 @@ static int
comp_with_mask(void *addr, void *dest, unsigned int mask) comp_with_mask(void *addr, void *dest, unsigned int mask)
{ {
if( /* mask/8 == 0 || */ memcmp(addr, dest, mask / 8) == 0) if( /* mask/8 == 0 || */ memcmp(addr, dest, mask / 8) == 0) {
{
int n = mask / 8; int n = mask / 8;
int m = ((-1) << (8 - (mask % 8))); int m = ((-1) << (8 - (mask % 8)));
@ -69,14 +68,12 @@ static char *
prefix_toa2x(rb_prefix_t *prefix, char *buf, int buf_len, int with_len) prefix_toa2x(rb_prefix_t *prefix, char *buf, int buf_len, int with_len)
{ {
static char tmp[6]; static char tmp[6];
if(prefix == NULL) if(prefix == NULL) {
{
rb_strlcpy(buf, "(NULL)", buf_len); rb_strlcpy(buf, "(NULL)", buf_len);
return (buf); return (buf);
} }
inet_ntop(prefix->family, &prefix->add.sin, buf, buf_len); inet_ntop(prefix->family, &prefix->add.sin, buf, buf_len);
if(with_len) if(with_len) {
{
rb_snprintf(tmp, sizeof(tmp), "/%d", prefix->bitlen); rb_snprintf(tmp, sizeof(tmp), "/%d", prefix->bitlen);
strcat(buf, tmp); strcat(buf, tmp);
} }
@ -115,37 +112,29 @@ New_Prefix2(int family, void *dest, int bitlen, rb_prefix_t *prefix)
#endif #endif
#ifdef RB_IPV6 #ifdef RB_IPV6
if(family == AF_INET6) if(family == AF_INET6) {
{
default_bitlen = 128; default_bitlen = 128;
if(prefix == NULL) if(prefix == NULL) {
{
prefix = rb_malloc(sizeof(rb_prefix_t)); prefix = rb_malloc(sizeof(rb_prefix_t));
dynamic_allocated++; dynamic_allocated++;
} }
memcpy(&prefix->add.sin6, dest, 16); memcpy(&prefix->add.sin6, dest, 16);
} } else
else
#endif /* RB_IPV6 */ #endif /* RB_IPV6 */
if(family == AF_INET) if(family == AF_INET) {
{ if(prefix == NULL) {
if(prefix == NULL)
{
prefix = rb_malloc(sizeof(rb_prefix_t)); prefix = rb_malloc(sizeof(rb_prefix_t));
dynamic_allocated++; dynamic_allocated++;
} }
memcpy(&prefix->add.sin, dest, 4); memcpy(&prefix->add.sin, dest, 4);
} } else {
else
{
return (NULL); return (NULL);
} }
prefix->bitlen = (bitlen >= 0) ? bitlen : default_bitlen; prefix->bitlen = (bitlen >= 0) ? bitlen : default_bitlen;
prefix->family = family; prefix->family = family;
prefix->ref_count = 0; prefix->ref_count = 0;
if(dynamic_allocated) if(dynamic_allocated) {
{
prefix->ref_count++; prefix->ref_count++;
} }
return (prefix); return (prefix);
@ -175,27 +164,23 @@ ascii2prefix(int family, const char *string)
return (NULL); return (NULL);
/* easy way to handle both families */ /* easy way to handle both families */
if(family == 0) if(family == 0) {
{
family = AF_INET; family = AF_INET;
#ifdef RB_IPV6 #ifdef RB_IPV6
if(strchr(string, ':')) if(strchr(string, ':'))
family = AF_INET6; family = AF_INET6;
#endif /* RB_IPV6 */ #endif /* RB_IPV6 */
} }
if(family == AF_INET) if(family == AF_INET) {
{
maxbitlen = 32; maxbitlen = 32;
} }
#ifdef RB_IPV6 #ifdef RB_IPV6
else if(family == AF_INET6) else if(family == AF_INET6) {
{
maxbitlen = 128; maxbitlen = 128;
} }
#endif /* RB_IPV6 */ #endif /* RB_IPV6 */
if((cp = strchr(string, '/')) != NULL) if((cp = strchr(string, '/')) != NULL) {
{
bitlen = atol(cp + 1); bitlen = atol(cp + 1);
/* *cp = '\0'; */ /* *cp = '\0'; */
/* copy the string to save. Avoid destroying the string */ /* copy the string to save. Avoid destroying the string */
@ -205,21 +190,17 @@ ascii2prefix(int family, const char *string)
string = save; string = save;
if(bitlen <= 0 || bitlen > maxbitlen) if(bitlen <= 0 || bitlen > maxbitlen)
bitlen = maxbitlen; bitlen = maxbitlen;
} } else {
else
{
bitlen = maxbitlen; bitlen = maxbitlen;
} }
if(family == AF_INET) if(family == AF_INET) {
{
if((result = rb_inet_pton(AF_INET, string, &sinaddr)) <= 0) if((result = rb_inet_pton(AF_INET, string, &sinaddr)) <= 0)
return (NULL); return (NULL);
return (New_Prefix(AF_INET, &sinaddr, bitlen)); return (New_Prefix(AF_INET, &sinaddr, bitlen));
} }
#ifdef RB_IPV6 #ifdef RB_IPV6
else if(family == AF_INET6) else if(family == AF_INET6) {
{
if((result = rb_inet_pton(AF_INET6, string, &sinaddr6)) <= 0) if((result = rb_inet_pton(AF_INET6, string, &sinaddr6)) <= 0)
return (NULL); return (NULL);
return (New_Prefix(AF_INET6, &sinaddr6, bitlen)); return (New_Prefix(AF_INET6, &sinaddr6, bitlen));
@ -234,8 +215,7 @@ Ref_Prefix(rb_prefix_t *prefix)
{ {
if(prefix == NULL) if(prefix == NULL)
return (NULL); return (NULL);
if(prefix->ref_count == 0) if(prefix->ref_count == 0) {
{
/* make a copy in case of a static prefix */ /* make a copy in case of a static prefix */
return (New_Prefix2(prefix->family, &prefix->add, prefix->bitlen, NULL)); return (New_Prefix2(prefix->family, &prefix->add, prefix->bitlen, NULL));
} }
@ -253,8 +233,7 @@ Deref_Prefix(rb_prefix_t *prefix)
prefix->ref_count--; prefix->ref_count--;
assert(prefix->ref_count >= 0); assert(prefix->ref_count >= 0);
if(prefix->ref_count <= 0) if(prefix->ref_count <= 0) {
{
rb_free(prefix); rb_free(prefix);
return; return;
} }
@ -291,49 +270,36 @@ void
rb_clear_patricia(rb_patricia_tree_t *patricia, void (*func) (void *)) rb_clear_patricia(rb_patricia_tree_t *patricia, void (*func) (void *))
{ {
assert(patricia); assert(patricia);
if(patricia->head) if(patricia->head) {
{
rb_patricia_node_t *Xstack[RB_PATRICIA_MAXBITS + 1]; rb_patricia_node_t *Xstack[RB_PATRICIA_MAXBITS + 1];
rb_patricia_node_t **Xsp = Xstack; rb_patricia_node_t **Xsp = Xstack;
rb_patricia_node_t *Xrn = patricia->head; rb_patricia_node_t *Xrn = patricia->head;
while(Xrn) while(Xrn) {
{
rb_patricia_node_t *l = Xrn->l; rb_patricia_node_t *l = Xrn->l;
rb_patricia_node_t *r = Xrn->r; rb_patricia_node_t *r = Xrn->r;
if(Xrn->prefix) if(Xrn->prefix) {
{
Deref_Prefix(Xrn->prefix); Deref_Prefix(Xrn->prefix);
if(Xrn->data && func) if(Xrn->data && func)
func(Xrn->data); func(Xrn->data);
} } else {
else
{
assert(Xrn->data == NULL); assert(Xrn->data == NULL);
} }
rb_free(Xrn); rb_free(Xrn);
patricia->num_active_node--; patricia->num_active_node--;
if(l) if(l) {
{ if(r) {
if(r)
{
*Xsp++ = r; *Xsp++ = r;
} }
Xrn = l; Xrn = l;
} } else if(r) {
else if(r)
{
Xrn = r; Xrn = r;
} } else if(Xsp != Xstack) {
else if(Xsp != Xstack)
{
Xrn = *(--Xsp); Xrn = *(--Xsp);
} } else {
else
{
Xrn = (rb_patricia_node_t *)0; Xrn = (rb_patricia_node_t *)0;
} }
} }
@ -361,8 +327,7 @@ rb_patricia_process(rb_patricia_tree_t *patricia, void (*func) (rb_prefix_t *, v
rb_patricia_node_t *node; rb_patricia_node_t *node;
assert(func); assert(func);
RB_PATRICIA_WALK(patricia->head, node) RB_PATRICIA_WALK(patricia->head, node) {
{
func(node->prefix, node->data); func(node->prefix, node->data);
} }
RB_PATRICIA_WALK_END; RB_PATRICIA_WALK_END;
@ -386,11 +351,9 @@ rb_patricia_search_exact(rb_patricia_tree_t *patricia, rb_prefix_t *prefix)
addr = rb_prefix_touchar(prefix); addr = rb_prefix_touchar(prefix);
bitlen = prefix->bitlen; bitlen = prefix->bitlen;
while(node->bit < bitlen) while(node->bit < bitlen) {
{
if(BIT_TEST(addr[node->bit >> 3], 0x80 >> (node->bit & 0x07))) if(BIT_TEST(addr[node->bit >> 3], 0x80 >> (node->bit & 0x07))) {
{
#ifdef PATRICIA_DEBUG #ifdef PATRICIA_DEBUG
if(node->prefix) if(node->prefix)
fprintf(stderr, fprintf(stderr,
@ -401,9 +364,7 @@ rb_patricia_search_exact(rb_patricia_tree_t *patricia, rb_prefix_t *prefix)
"patricia_search_exact: take right at %d\n", node->bit); "patricia_search_exact: take right at %d\n", node->bit);
#endif /* PATRICIA_DEBUG */ #endif /* PATRICIA_DEBUG */
node = node->r; node = node->r;
} } else {
else
{
#ifdef PATRICIA_DEBUG #ifdef PATRICIA_DEBUG
if(node->prefix) if(node->prefix)
fprintf(stderr, fprintf(stderr,
@ -431,8 +392,7 @@ rb_patricia_search_exact(rb_patricia_tree_t *patricia, rb_prefix_t *prefix)
return (NULL); return (NULL);
assert(node->bit == bitlen); assert(node->bit == bitlen);
assert(node->bit == node->prefix->bitlen); assert(node->bit == node->prefix->bitlen);
if(comp_with_mask(prefix_tochar(node->prefix), prefix_tochar(prefix), bitlen)) if(comp_with_mask(prefix_tochar(node->prefix), prefix_tochar(prefix), bitlen)) {
{
#ifdef PATRICIA_DEBUG #ifdef PATRICIA_DEBUG
fprintf(stderr, "patricia_search_exact: found %s/%d\n", fprintf(stderr, "patricia_search_exact: found %s/%d\n",
prefix_toa(node->prefix), node->prefix->bitlen); prefix_toa(node->prefix), node->prefix->bitlen);
@ -463,11 +423,9 @@ rb_patricia_search_best2(rb_patricia_tree_t *patricia, rb_prefix_t *prefix, int
addr = rb_prefix_touchar(prefix); addr = rb_prefix_touchar(prefix);
bitlen = prefix->bitlen; bitlen = prefix->bitlen;
while(node->bit < bitlen) while(node->bit < bitlen) {
{
if(node->prefix) if(node->prefix) {
{
#ifdef PATRICIA_DEBUG #ifdef PATRICIA_DEBUG
fprintf(stderr, fprintf(stderr,
"patricia_search_best: push %s/%d\n", "patricia_search_best: push %s/%d\n",
@ -476,8 +434,7 @@ rb_patricia_search_best2(rb_patricia_tree_t *patricia, rb_prefix_t *prefix, int
stack[cnt++] = node; stack[cnt++] = node;
} }
if(BIT_TEST(addr[node->bit >> 3], 0x80 >> (node->bit & 0x07))) if(BIT_TEST(addr[node->bit >> 3], 0x80 >> (node->bit & 0x07))) {
{
#ifdef PATRICIA_DEBUG #ifdef PATRICIA_DEBUG
if(node->prefix) if(node->prefix)
fprintf(stderr, fprintf(stderr,
@ -488,9 +445,7 @@ rb_patricia_search_best2(rb_patricia_tree_t *patricia, rb_prefix_t *prefix, int
"patricia_search_best: take right at %d\n", node->bit); "patricia_search_best: take right at %d\n", node->bit);
#endif /* PATRICIA_DEBUG */ #endif /* PATRICIA_DEBUG */
node = node->r; node = node->r;
} } else {
else
{
#ifdef PATRICIA_DEBUG #ifdef PATRICIA_DEBUG
if(node->prefix) if(node->prefix)
fprintf(stderr, fprintf(stderr,
@ -523,16 +478,14 @@ rb_patricia_search_best2(rb_patricia_tree_t *patricia, rb_prefix_t *prefix, int
if(cnt <= 0) if(cnt <= 0)
return (NULL); return (NULL);
while(--cnt >= 0) while(--cnt >= 0) {
{
node = stack[cnt]; node = stack[cnt];
#ifdef PATRICIA_DEBUG #ifdef PATRICIA_DEBUG
fprintf(stderr, "patricia_search_best: pop %s/%d\n", fprintf(stderr, "patricia_search_best: pop %s/%d\n",
prefix_toa(node->prefix), node->prefix->bitlen); prefix_toa(node->prefix), node->prefix->bitlen);
#endif /* PATRICIA_DEBUG */ #endif /* PATRICIA_DEBUG */
if(comp_with_mask(prefix_tochar(node->prefix), if(comp_with_mask(prefix_tochar(node->prefix),
prefix_tochar(prefix), node->prefix->bitlen)) prefix_tochar(prefix), node->prefix->bitlen)) {
{
#ifdef PATRICIA_DEBUG #ifdef PATRICIA_DEBUG
fprintf(stderr, fprintf(stderr,
"patricia_search_best: found %s/%d\n", "patricia_search_best: found %s/%d\n",
@ -564,8 +517,7 @@ rb_patricia_lookup(rb_patricia_tree_t *patricia, rb_prefix_t *prefix)
assert(prefix); assert(prefix);
assert(prefix->bitlen <= patricia->maxbits); assert(prefix->bitlen <= patricia->maxbits);
if(patricia->head == NULL) if(patricia->head == NULL) {
{
node = rb_malloc(sizeof(rb_patricia_node_t)); node = rb_malloc(sizeof(rb_patricia_node_t));
node->bit = prefix->bitlen; node->bit = prefix->bitlen;
node->prefix = Ref_Prefix(prefix); node->prefix = Ref_Prefix(prefix);
@ -586,12 +538,10 @@ rb_patricia_lookup(rb_patricia_tree_t *patricia, rb_prefix_t *prefix)
bitlen = prefix->bitlen; bitlen = prefix->bitlen;
node = patricia->head; node = patricia->head;
while(node->bit < bitlen || node->prefix == NULL) while(node->bit < bitlen || node->prefix == NULL) {
{
if(node->bit < patricia->maxbits && if(node->bit < patricia->maxbits &&
BIT_TEST(addr[node->bit >> 3], 0x80 >> (node->bit & 0x07))) BIT_TEST(addr[node->bit >> 3], 0x80 >> (node->bit & 0x07))) {
{
if(node->r == NULL) if(node->r == NULL)
break; break;
#ifdef PATRICIA_DEBUG #ifdef PATRICIA_DEBUG
@ -603,9 +553,7 @@ rb_patricia_lookup(rb_patricia_tree_t *patricia, rb_prefix_t *prefix)
fprintf(stderr, "patricia_lookup: take right at %d\n", node->bit); fprintf(stderr, "patricia_lookup: take right at %d\n", node->bit);
#endif /* PATRICIA_DEBUG */ #endif /* PATRICIA_DEBUG */
node = node->r; node = node->r;
} } else {
else
{
if(node->l == NULL) if(node->l == NULL)
break; break;
#ifdef PATRICIA_DEBUG #ifdef PATRICIA_DEBUG
@ -632,16 +580,13 @@ rb_patricia_lookup(rb_patricia_tree_t *patricia, rb_prefix_t *prefix)
/* find the first bit different */ /* find the first bit different */
check_bit = (node->bit < bitlen) ? node->bit : bitlen; check_bit = (node->bit < bitlen) ? node->bit : bitlen;
differ_bit = 0; differ_bit = 0;
for(i = 0; i * 8 < check_bit; i++) for(i = 0; i * 8 < check_bit; i++) {
{ if((r = (addr[i] ^ test_addr[i])) == 0) {
if((r = (addr[i] ^ test_addr[i])) == 0)
{
differ_bit = (i + 1) * 8; differ_bit = (i + 1) * 8;
continue; continue;
} }
/* I know the better way, but for now */ /* I know the better way, but for now */
for(j = 0; j < 8; j++) for(j = 0; j < 8; j++) {
{
if(BIT_TEST(r, (0x80 >> j))) if(BIT_TEST(r, (0x80 >> j)))
break; break;
} }
@ -657,8 +602,7 @@ rb_patricia_lookup(rb_patricia_tree_t *patricia, rb_prefix_t *prefix)
#endif /* PATRICIA_DEBUG */ #endif /* PATRICIA_DEBUG */
parent = node->parent; parent = node->parent;
while(parent && parent->bit >= differ_bit) while(parent && parent->bit >= differ_bit) {
{
node = parent; node = parent;
parent = node->parent; parent = node->parent;
#ifdef PATRICIA_DEBUG #ifdef PATRICIA_DEBUG
@ -670,10 +614,8 @@ rb_patricia_lookup(rb_patricia_tree_t *patricia, rb_prefix_t *prefix)
#endif /* PATRICIA_DEBUG */ #endif /* PATRICIA_DEBUG */
} }
if(differ_bit == bitlen && node->bit == bitlen) if(differ_bit == bitlen && node->bit == bitlen) {
{ if(node->prefix) {
if(node->prefix)
{
#ifdef PATRICIA_DEBUG #ifdef PATRICIA_DEBUG
fprintf(stderr, "patricia_lookup: found %s/%d\n", fprintf(stderr, "patricia_lookup: found %s/%d\n",
prefix_toa(node->prefix), node->prefix->bitlen); prefix_toa(node->prefix), node->prefix->bitlen);
@ -698,17 +640,13 @@ rb_patricia_lookup(rb_patricia_tree_t *patricia, rb_prefix_t *prefix)
new_node->data = NULL; new_node->data = NULL;
patricia->num_active_node++; patricia->num_active_node++;
if(node->bit == differ_bit) if(node->bit == differ_bit) {
{
new_node->parent = node; new_node->parent = node;
if(node->bit < patricia->maxbits && if(node->bit < patricia->maxbits &&
BIT_TEST(addr[node->bit >> 3], 0x80 >> (node->bit & 0x07))) BIT_TEST(addr[node->bit >> 3], 0x80 >> (node->bit & 0x07))) {
{
assert(node->r == NULL); assert(node->r == NULL);
node->r = new_node; node->r = new_node;
} } else {
else
{
assert(node->l == NULL); assert(node->l == NULL);
node->l = new_node; node->l = new_node;
} }
@ -720,29 +658,20 @@ rb_patricia_lookup(rb_patricia_tree_t *patricia, rb_prefix_t *prefix)
return (new_node); return (new_node);
} }
if(bitlen == differ_bit) if(bitlen == differ_bit) {
{
if(bitlen < patricia->maxbits && if(bitlen < patricia->maxbits &&
BIT_TEST(test_addr[bitlen >> 3], 0x80 >> (bitlen & 0x07))) BIT_TEST(test_addr[bitlen >> 3], 0x80 >> (bitlen & 0x07))) {
{
new_node->r = node; new_node->r = node;
} } else {
else
{
new_node->l = node; new_node->l = node;
} }
new_node->parent = node->parent; new_node->parent = node->parent;
if(node->parent == NULL) if(node->parent == NULL) {
{
assert(patricia->head == node); assert(patricia->head == node);
patricia->head = new_node; patricia->head = new_node;
} } else if(node->parent->r == node) {
else if(node->parent->r == node)
{
node->parent->r = new_node; node->parent->r = new_node;
} } else {
else
{
node->parent->l = new_node; node->parent->l = new_node;
} }
node->parent = new_node; node->parent = new_node;
@ -751,9 +680,7 @@ rb_patricia_lookup(rb_patricia_tree_t *patricia, rb_prefix_t *prefix)
"patricia_lookup: new_node #3 %s/%d (parent)\n", "patricia_lookup: new_node #3 %s/%d (parent)\n",
prefix_toa(prefix), prefix->bitlen); prefix_toa(prefix), prefix->bitlen);
#endif /* PATRICIA_DEBUG */ #endif /* PATRICIA_DEBUG */
} } else {
else
{
glue = rb_malloc(sizeof(rb_patricia_node_t)); glue = rb_malloc(sizeof(rb_patricia_node_t));
glue->bit = differ_bit; glue->bit = differ_bit;
glue->prefix = NULL; glue->prefix = NULL;
@ -761,29 +688,21 @@ rb_patricia_lookup(rb_patricia_tree_t *patricia, rb_prefix_t *prefix)
glue->data = NULL; glue->data = NULL;
patricia->num_active_node++; patricia->num_active_node++;
if(differ_bit < patricia->maxbits && if(differ_bit < patricia->maxbits &&
BIT_TEST(addr[differ_bit >> 3], 0x80 >> (differ_bit & 0x07))) BIT_TEST(addr[differ_bit >> 3], 0x80 >> (differ_bit & 0x07))) {
{
glue->r = new_node; glue->r = new_node;
glue->l = node; glue->l = node;
} } else {
else
{
glue->r = node; glue->r = node;
glue->l = new_node; glue->l = new_node;
} }
new_node->parent = glue; new_node->parent = glue;
if(node->parent == NULL) if(node->parent == NULL) {
{
assert(patricia->head == node); assert(patricia->head == node);
patricia->head = glue; patricia->head = glue;
} } else if(node->parent->r == node) {
else if(node->parent->r == node)
{
node->parent->r = glue; node->parent->r = glue;
} } else {
else
{
node->parent->l = glue; node->parent->l = glue;
} }
node->parent = glue; node->parent = glue;
@ -805,8 +724,7 @@ rb_patricia_remove(rb_patricia_tree_t *patricia, rb_patricia_node_t *node)
assert(patricia); assert(patricia);
assert(node); assert(node);
if(node->r && node->l) if(node->r && node->l) {
{
#ifdef PATRICIA_DEBUG #ifdef PATRICIA_DEBUG
fprintf(stderr, "patricia_remove: #0 %s/%d (r & l)\n", fprintf(stderr, "patricia_remove: #0 %s/%d (r & l)\n",
prefix_toa(node->prefix), node->prefix->bitlen); prefix_toa(node->prefix), node->prefix->bitlen);
@ -822,8 +740,7 @@ rb_patricia_remove(rb_patricia_tree_t *patricia, rb_patricia_node_t *node)
return; return;
} }
if(node->r == NULL && node->l == NULL) if(node->r == NULL && node->l == NULL) {
{
#ifdef PATRICIA_DEBUG #ifdef PATRICIA_DEBUG
fprintf(stderr, "patricia_remove: #1 %s/%d (!r & !l)\n", fprintf(stderr, "patricia_remove: #1 %s/%d (!r & !l)\n",
prefix_toa(node->prefix), node->prefix->bitlen); prefix_toa(node->prefix), node->prefix->bitlen);
@ -833,20 +750,16 @@ rb_patricia_remove(rb_patricia_tree_t *patricia, rb_patricia_node_t *node)
rb_free(node); rb_free(node);
patricia->num_active_node--; patricia->num_active_node--;
if(parent == NULL) if(parent == NULL) {
{
assert(patricia->head == node); assert(patricia->head == node);
patricia->head = NULL; patricia->head = NULL;
return; return;
} }
if(parent->r == node) if(parent->r == node) {
{
parent->r = NULL; parent->r = NULL;
child = parent->l; child = parent->l;
} } else {
else
{
assert(parent->l == node); assert(parent->l == node);
parent->l = NULL; parent->l = NULL;
child = parent->r; child = parent->r;
@ -857,17 +770,12 @@ rb_patricia_remove(rb_patricia_tree_t *patricia, rb_patricia_node_t *node)
/* we need to remove parent too */ /* we need to remove parent too */
if(parent->parent == NULL) if(parent->parent == NULL) {
{
assert(patricia->head == parent); assert(patricia->head == parent);
patricia->head = child; patricia->head = child;
} } else if(parent->parent->r == parent) {
else if(parent->parent->r == parent)
{
parent->parent->r = child; parent->parent->r = child;
} } else {
else
{
assert(parent->parent->l == parent); assert(parent->parent->l == parent);
parent->parent->l = child; parent->parent->l = child;
} }
@ -880,12 +788,9 @@ rb_patricia_remove(rb_patricia_tree_t *patricia, rb_patricia_node_t *node)
fprintf(stderr, "patricia_remove: #2 %s/%d (r ^ l)\n", fprintf(stderr, "patricia_remove: #2 %s/%d (r ^ l)\n",
prefix_toa(node->prefix), node->prefix->bitlen); prefix_toa(node->prefix), node->prefix->bitlen);
#endif /* PATRICIA_DEBUG */ #endif /* PATRICIA_DEBUG */
if(node->r) if(node->r) {
{
child = node->r; child = node->r;
} } else {
else
{
assert(node->l); assert(node->l);
child = node->l; child = node->l;
} }
@ -896,19 +801,15 @@ rb_patricia_remove(rb_patricia_tree_t *patricia, rb_patricia_node_t *node)
rb_free(node); rb_free(node);
patricia->num_active_node--; patricia->num_active_node--;
if(parent == NULL) if(parent == NULL) {
{
assert(patricia->head == node); assert(patricia->head == node);
patricia->head = child; patricia->head = child;
return; return;
} }
if(parent->r == node) if(parent->r == node) {
{
parent->r = child; parent->r = child;
} } else {
else
{
assert(parent->l == node); assert(parent->l == node);
parent->l = child; parent->l = child;
} }
@ -947,17 +848,13 @@ make_and_lookup(rb_patricia_tree_t *tree, const char *string)
rb_prefix_t *prefix; rb_prefix_t *prefix;
rb_patricia_node_t *node; rb_patricia_node_t *node;
if((prefix = ascii2prefix(AF_INET, string)) != NULL) if((prefix = ascii2prefix(AF_INET, string)) != NULL) {
{
node = rb_patricia_lookup(tree, prefix); node = rb_patricia_lookup(tree, prefix);
} } else
else
#ifdef RB_IPV6 #ifdef RB_IPV6
if((prefix = ascii2prefix(AF_INET6, string)) != NULL) if((prefix = ascii2prefix(AF_INET6, string)) != NULL) {
{
node = rb_patricia_lookup(tree, prefix); node = rb_patricia_lookup(tree, prefix);
} } else
else
#endif #endif
return NULL; return NULL;
#ifdef PATRICIA_DEBUG #ifdef PATRICIA_DEBUG
@ -973,15 +870,13 @@ try_search_exact(rb_patricia_tree_t *tree, char *string)
{ {
rb_prefix_t *prefix; rb_prefix_t *prefix;
rb_patricia_node_t *node; rb_patricia_node_t *node;
if((prefix = ascii2prefix(AF_INET, string)) != NULL) if((prefix = ascii2prefix(AF_INET, string)) != NULL) {
{
node = rb_patricia_search_exact(tree, prefix); node = rb_patricia_search_exact(tree, prefix);
Deref_Prefix(prefix); Deref_Prefix(prefix);
return (node); return (node);
} }
#ifdef RB_IPV6 #ifdef RB_IPV6
else if((prefix = ascii2prefix(AF_INET6, string)) != NULL) else if((prefix = ascii2prefix(AF_INET6, string)) != NULL) {
{
node = rb_patricia_search_exact(tree, prefix); node = rb_patricia_search_exact(tree, prefix);
Deref_Prefix(prefix); Deref_Prefix(prefix);
return (node); return (node);
@ -1014,22 +909,18 @@ rb_match_ip(rb_patricia_tree_t *tree, struct sockaddr *ip)
family = AF_INET; family = AF_INET;
ipptr = &((struct sockaddr_in *)ip)->sin_addr; ipptr = &((struct sockaddr_in *)ip)->sin_addr;
#else #else
if(ip->sa_family == AF_INET6) if(ip->sa_family == AF_INET6) {
{
len = 128; len = 128;
family = AF_INET6; family = AF_INET6;
ipptr = &((struct sockaddr_in6 *)ip)->sin6_addr; ipptr = &((struct sockaddr_in6 *)ip)->sin6_addr;
} } else {
else
{
len = 32; len = 32;
family = AF_INET; family = AF_INET;
ipptr = &((struct sockaddr_in *)ip)->sin_addr; ipptr = &((struct sockaddr_in *)ip)->sin_addr;
} }
#endif #endif
if((prefix = New_Prefix(family, ipptr, len)) != NULL) if((prefix = New_Prefix(family, ipptr, len)) != NULL) {
{
node = rb_patricia_search_best(tree, prefix); node = rb_patricia_search_best(tree, prefix);
Deref_Prefix(prefix); Deref_Prefix(prefix);
return (node); return (node);
@ -1051,15 +942,12 @@ rb_match_ip_exact(rb_patricia_tree_t *tree, struct sockaddr *ip, unsigned int le
family = AF_INET; family = AF_INET;
ipptr = &((struct sockaddr_in *)ip)->sin_addr; ipptr = &((struct sockaddr_in *)ip)->sin_addr;
#else #else
if(ip->sa_family == AF_INET6) if(ip->sa_family == AF_INET6) {
{
if(len > 128) if(len > 128)
len = 128; len = 128;
family = AF_INET6; family = AF_INET6;
ipptr = &((struct sockaddr_in6 *)ip)->sin6_addr; ipptr = &((struct sockaddr_in6 *)ip)->sin6_addr;
} } else {
else
{
if(len > 32) if(len > 32)
len = 32; len = 32;
family = AF_INET; family = AF_INET;
@ -1067,8 +955,7 @@ rb_match_ip_exact(rb_patricia_tree_t *tree, struct sockaddr *ip, unsigned int le
} }
#endif #endif
if((prefix = New_Prefix(family, ipptr, len)) != NULL) if((prefix = New_Prefix(family, ipptr, len)) != NULL) {
{
node = rb_patricia_search_exact(tree, prefix); node = rb_patricia_search_exact(tree, prefix);
Deref_Prefix(prefix); Deref_Prefix(prefix);
return (node); return (node);
@ -1084,19 +971,15 @@ rb_match_string(rb_patricia_tree_t *tree, const char *string)
rb_patricia_node_t *node; rb_patricia_node_t *node;
rb_prefix_t *prefix; rb_prefix_t *prefix;
if((prefix = ascii2prefix(AF_INET, string)) != NULL) if((prefix = ascii2prefix(AF_INET, string)) != NULL) {
{
node = rb_patricia_search_best(tree, prefix); node = rb_patricia_search_best(tree, prefix);
Deref_Prefix(prefix); Deref_Prefix(prefix);
} } else
else
#ifdef RB_IPV6 #ifdef RB_IPV6
if((prefix = ascii2prefix(AF_INET6, string)) != NULL) if((prefix = ascii2prefix(AF_INET6, string)) != NULL) {
{
node = rb_patricia_search_best(tree, prefix); node = rb_patricia_search_best(tree, prefix);
Deref_Prefix(prefix); Deref_Prefix(prefix);
} } else
else
#endif #endif
return NULL; return NULL;
return node; return node;
@ -1107,19 +990,15 @@ rb_match_exact_string(rb_patricia_tree_t *tree, const char *string)
{ {
rb_prefix_t *prefix; rb_prefix_t *prefix;
rb_patricia_node_t *node; rb_patricia_node_t *node;
if((prefix = ascii2prefix(AF_INET, string)) != NULL) if((prefix = ascii2prefix(AF_INET, string)) != NULL) {
{
node = rb_patricia_search_exact(tree, prefix); node = rb_patricia_search_exact(tree, prefix);
Deref_Prefix(prefix); Deref_Prefix(prefix);
} } else
else
#ifdef RB_IPV6 #ifdef RB_IPV6
if((prefix = ascii2prefix(AF_INET6, string)) != NULL) if((prefix = ascii2prefix(AF_INET6, string)) != NULL) {
{
node = rb_patricia_search_exact(tree, prefix); node = rb_patricia_search_exact(tree, prefix);
Deref_Prefix(prefix); Deref_Prefix(prefix);
} } else
else
#endif #endif
return NULL; return NULL;
return node; return node;

View File

@ -39,8 +39,7 @@
#define POLLWRNORM POLLOUT #define POLLWRNORM POLLOUT
#endif #endif
struct _pollfd_list struct _pollfd_list {
{
struct pollfd *pollfds; struct pollfd *pollfds;
int maxindex; /* highest FD number */ int maxindex; /* highest FD number */
int allocated; /* number of pollfds allocated */ int allocated; /* number of pollfds allocated */
@ -69,8 +68,7 @@ rb_init_netio_poll(void)
int fd; int fd;
pollfd_list.pollfds = rb_malloc(rb_getmaxconnect() * (sizeof(struct pollfd))); pollfd_list.pollfds = rb_malloc(rb_getmaxconnect() * (sizeof(struct pollfd)));
pollfd_list.allocated = rb_getmaxconnect(); pollfd_list.allocated = rb_getmaxconnect();
for(fd = 0; fd < rb_getmaxconnect(); fd++) for(fd = 0; fd < rb_getmaxconnect(); fd++) {
{
pollfd_list.pollfds[fd].fd = -1; pollfd_list.pollfds[fd].fd = -1;
} }
pollfd_list.maxindex = 0; pollfd_list.maxindex = 0;
@ -80,16 +78,14 @@ rb_init_netio_poll(void)
static void static void
resize_pollarray(int fd) resize_pollarray(int fd)
{ {
if(rb_unlikely(fd >= pollfd_list.allocated)) if(rb_unlikely(fd >= pollfd_list.allocated)) {
{
int x, old_value = pollfd_list.allocated; int x, old_value = pollfd_list.allocated;
pollfd_list.allocated += 1024; pollfd_list.allocated += 1024;
pollfd_list.pollfds = pollfd_list.pollfds =
rb_realloc(pollfd_list.pollfds, rb_realloc(pollfd_list.pollfds,
pollfd_list.allocated * (sizeof(struct pollfd))); pollfd_list.allocated * (sizeof(struct pollfd)));
memset(&pollfd_list.pollfds[old_value + 1], 0, sizeof(struct pollfd) * 1024); memset(&pollfd_list.pollfds[old_value + 1], 0, sizeof(struct pollfd) * 1024);
for(x = old_value + 1; x < pollfd_list.allocated; x++) for(x = old_value + 1; x < pollfd_list.allocated; x++) {
{
pollfd_list.pollfds[x].fd = -1; pollfd_list.pollfds[x].fd = -1;
} }
} }
@ -107,8 +103,7 @@ rb_setselect_poll(rb_fde_t *F, unsigned int type, PF * handler, void *client_dat
if(F == NULL) if(F == NULL)
return; return;
if(type & RB_SELECT_READ) if(type & RB_SELECT_READ) {
{
F->read_handler = handler; F->read_handler = handler;
F->read_data = client_data; F->read_data = client_data;
if(handler != NULL) if(handler != NULL)
@ -116,8 +111,7 @@ rb_setselect_poll(rb_fde_t *F, unsigned int type, PF * handler, void *client_dat
else else
F->pflags &= ~POLLRDNORM; F->pflags &= ~POLLRDNORM;
} }
if(type & RB_SELECT_WRITE) if(type & RB_SELECT_WRITE) {
{
F->write_handler = handler; F->write_handler = handler;
F->write_data = client_data; F->write_data = client_data;
if(handler != NULL) if(handler != NULL)
@ -127,19 +121,15 @@ rb_setselect_poll(rb_fde_t *F, unsigned int type, PF * handler, void *client_dat
} }
resize_pollarray(F->fd); resize_pollarray(F->fd);
if(F->pflags <= 0) if(F->pflags <= 0) {
{
pollfd_list.pollfds[F->fd].events = 0; pollfd_list.pollfds[F->fd].events = 0;
pollfd_list.pollfds[F->fd].fd = -1; pollfd_list.pollfds[F->fd].fd = -1;
if(F->fd == pollfd_list.maxindex) if(F->fd == pollfd_list.maxindex) {
{
while(pollfd_list.maxindex >= 0 while(pollfd_list.maxindex >= 0
&& pollfd_list.pollfds[pollfd_list.maxindex].fd == -1) && pollfd_list.pollfds[pollfd_list.maxindex].fd == -1)
pollfd_list.maxindex--; pollfd_list.maxindex--;
} }
} } else {
else
{
pollfd_list.pollfds[F->fd].events = F->pflags; pollfd_list.pollfds[F->fd].events = F->pflags;
pollfd_list.pollfds[F->fd].fd = F->fd; pollfd_list.pollfds[F->fd].fd = F->fd;
if(F->fd > pollfd_list.maxindex) if(F->fd > pollfd_list.maxindex)
@ -175,8 +165,7 @@ rb_select_poll(long delay)
num = poll(pollfd_list.pollfds, pollfd_list.maxindex + 1, delay); num = poll(pollfd_list.pollfds, pollfd_list.maxindex + 1, delay);
rb_set_time(); rb_set_time();
if(num < 0) if(num < 0) {
{
if(!rb_ignore_errno(errno)) if(!rb_ignore_errno(errno))
return RB_OK; return RB_OK;
else else
@ -186,8 +175,7 @@ rb_select_poll(long delay)
return RB_OK; return RB_OK;
/* XXX we *could* optimise by falling out after doing num fds ... */ /* XXX we *could* optimise by falling out after doing num fds ... */
for(ci = 0; ci < pollfd_list.maxindex + 1; ci++) for(ci = 0; ci < pollfd_list.maxindex + 1; ci++) {
{
rb_fde_t *F; rb_fde_t *F;
pfd = &pollfd_list.pollfds[ci]; pfd = &pollfd_list.pollfds[ci];
@ -200,8 +188,7 @@ rb_select_poll(long delay)
if(F == NULL) if(F == NULL)
continue; continue;
if(revents & (POLLRDNORM | POLLIN | POLLHUP | POLLERR)) if(revents & (POLLRDNORM | POLLIN | POLLHUP | POLLERR)) {
{
hdl = F->read_handler; hdl = F->read_handler;
data = F->read_data; data = F->read_data;
F->read_handler = NULL; F->read_handler = NULL;
@ -210,8 +197,7 @@ rb_select_poll(long delay)
hdl(F, data); hdl(F, data);
} }
if(IsFDOpen(F) && (revents & (POLLWRNORM | POLLOUT | POLLHUP | POLLERR))) if(IsFDOpen(F) && (revents & (POLLWRNORM | POLLOUT | POLLHUP | POLLERR))) {
{
hdl = F->write_handler; hdl = F->write_handler;
data = F->write_data; data = F->write_data;
F->write_handler = NULL; F->write_handler = NULL;

View File

@ -57,8 +57,7 @@ rb_setup_fd_ports(rb_fde_t *F)
int int
rb_init_netio_ports(void) rb_init_netio_ports(void)
{ {
if((pe = port_create()) < 0) if((pe = port_create()) < 0) {
{
return errno; return errno;
} }
pemax = getdtablesize(); pemax = getdtablesize();
@ -81,13 +80,11 @@ rb_setselect_ports(rb_fde_t *F, unsigned int type, PF * handler, void *client_da
lrb_assert(IsFDOpen(F)); lrb_assert(IsFDOpen(F));
int old_flags = F->pflags; int old_flags = F->pflags;
if(type & RB_SELECT_READ) if(type & RB_SELECT_READ) {
{
F->read_handler = handler; F->read_handler = handler;
F->read_data = client_data; F->read_data = client_data;
} }
if(type & RB_SELECT_WRITE) if(type & RB_SELECT_WRITE) {
{
F->write_handler = handler; F->write_handler = handler;
F->write_data = client_data; F->write_data = client_data;
} }
@ -100,8 +97,7 @@ rb_setselect_ports(rb_fde_t *F, unsigned int type, PF * handler, void *client_da
if(old_flags == 0 && F->pflags == 0) if(old_flags == 0 && F->pflags == 0)
return; return;
else if(F->pflags <= 0) else if(F->pflags <= 0) {
{
port_dissociate(pe, PORT_SOURCE_FD, F->fd); port_dissociate(pe, PORT_SOURCE_FD, F->fd);
return; return;
} }
@ -128,8 +124,7 @@ rb_select_ports(long delay)
struct timespec *p = NULL; struct timespec *p = NULL;
struct ev_entry *ev; struct ev_entry *ev;
if(delay >= 0) if(delay >= 0) {
{
poll_time.tv_sec = delay / 1000; poll_time.tv_sec = delay / 1000;
poll_time.tv_nsec = (delay % 1000) * 1000000; poll_time.tv_nsec = (delay % 1000) * 1000000;
p = &poll_time; p = &poll_time;
@ -142,25 +137,20 @@ rb_select_ports(long delay)
if(i == -1) if(i == -1)
return RB_OK; return RB_OK;
for(i = 0; i < nget; i++) for(i = 0; i < nget; i++) {
{ if(pelst[i].portev_source == PORT_SOURCE_FD) {
if(pelst[i].portev_source == PORT_SOURCE_FD)
{
fd = pelst[i].portev_object; fd = pelst[i].portev_object;
PF *hdl = NULL; PF *hdl = NULL;
rb_fde_t *F = pelst[i].portev_user; rb_fde_t *F = pelst[i].portev_user;
if((pelst[i].portev_events & (POLLIN | POLLHUP | POLLERR)) && (hdl = F->read_handler)) if((pelst[i].portev_events & (POLLIN | POLLHUP | POLLERR)) && (hdl = F->read_handler)) {
{
F->read_handler = NULL; F->read_handler = NULL;
hdl(F, F->read_data); hdl(F, F->read_data);
} }
if((pelst[i].portev_events & (POLLOUT | POLLHUP | POLLERR)) && (hdl = F->write_handler)) if((pelst[i].portev_events & (POLLOUT | POLLHUP | POLLERR)) && (hdl = F->write_handler)) {
{
F->write_handler = NULL; F->write_handler = NULL;
hdl(F, F->write_data); hdl(F, F->write_data);
} }
} else if(pelst[i].portev_source == PORT_SOURCE_TIMER) } else if(pelst[i].portev_source == PORT_SOURCE_TIMER) {
{
ev = (struct ev_entry *)pelst[i].portev_user; ev = (struct ev_entry *)pelst[i].portev_user;
rb_run_event(ev); rb_run_event(ev);
} }
@ -199,8 +189,7 @@ rb_ports_sched_event(struct ev_entry *event, int when)
not.portnfy_port = pe; not.portnfy_port = pe;
not.portnfy_user = event; not.portnfy_user = event;
if(timer_create(CLOCK_REALTIME, &ev, id) < 0) if(timer_create(CLOCK_REALTIME, &ev, id) < 0) {
{
rb_lib_log("timer_create: %s\n", strerror(errno)); rb_lib_log("timer_create: %s\n", strerror(errno));
return 0; return 0;
} }
@ -211,8 +200,7 @@ rb_ports_sched_event(struct ev_entry *event, int when)
if(event->frequency != 0) if(event->frequency != 0)
ts.it_interval = ts.it_value; ts.it_interval = ts.it_value;
if(timer_settime(*id, 0, &ts, NULL) < 0) if(timer_settime(*id, 0, &ts, NULL) < 0) {
{
rb_lib_log("timer_settime: %s\n", strerror(errno)); rb_lib_log("timer_settime: %s\n", strerror(errno));
return 0; return 0;
} }

View File

@ -69,19 +69,15 @@ rb_ctime(const time_t t, char *buf, size_t len)
#else #else
tp = gmtime(&t); tp = gmtime(&t);
#endif #endif
if(buf == NULL) if(buf == NULL) {
{
p = timex; p = timex;
tlen = sizeof(timex); tlen = sizeof(timex);
} } else {
else
{
p = buf; p = buf;
tlen = len; tlen = len;
} }
if(rb_unlikely(tp == NULL)) if(rb_unlikely(tp == NULL)) {
{
rb_strlcpy(p, "", tlen); rb_strlcpy(p, "", tlen);
return (p); return (p);
} }
@ -105,8 +101,7 @@ rb_date(const time_t t, char *buf, size_t len)
gm = gmtime(&t); gm = gmtime(&t);
#endif #endif
if(rb_unlikely(gm == NULL)) if(rb_unlikely(gm == NULL)) {
{
rb_strlcpy(buf, "", len); rb_strlcpy(buf, "", len);
return (buf); return (buf);
} }
@ -170,8 +165,7 @@ rb_set_time(void)
{ {
struct timeval newtime; struct timeval newtime;
if(rb_unlikely(rb_gettimeofday(&newtime, NULL) == -1)) if(rb_unlikely(rb_gettimeofday(&newtime, NULL) == -1)) {
{
rb_lib_log("Clock Failure (%s)", strerror(errno)); rb_lib_log("Clock Failure (%s)", strerror(errno));
rb_lib_restart("Clock Failure"); rb_lib_restart("Clock Failure");
} }
@ -207,8 +201,7 @@ rb_lib_init(log_cb * ilog, restart_cb * irestart, die_cb * idie, int closeall, i
rb_fdlist_init(closeall, maxcon, fd_heap_size); rb_fdlist_init(closeall, maxcon, fd_heap_size);
rb_init_netio(); rb_init_netio();
rb_init_rb_dlink_nodes(dh_size); rb_init_rb_dlink_nodes(dh_size);
if(rb_io_supports_event()) if(rb_io_supports_event()) {
{
rb_io_init_event(); rb_io_init_event();
} }
} }
@ -219,8 +212,7 @@ rb_lib_loop(long delay)
time_t next; time_t next;
rb_set_time(); rb_set_time();
if(rb_io_supports_event()) if(rb_io_supports_event()) {
{
if(delay == 0) if(delay == 0)
delay = -1; delay = -1;
while(1) while(1)
@ -228,23 +220,18 @@ rb_lib_loop(long delay)
} }
while(1) while(1) {
{ if(delay == 0) {
if(delay == 0) if((next = rb_event_next()) > 0) {
{
if((next = rb_event_next()) > 0)
{
next -= rb_current_time(); next -= rb_current_time();
if(next <= 0) if(next <= 0)
next = 1000; next = 1000;
else else
next *= 1000; next *= 1000;
} } else
else
next = -1; next = -1;
rb_select(next); rb_select(next);
} } else
else
rb_select(delay); rb_select(delay);
rb_event_run(); rb_event_run();
} }
@ -262,8 +249,7 @@ rb_strtok_r(char *s, const char *delim, char **save)
/* Scan leading delimiters. */ /* Scan leading delimiters. */
s += strspn(s, delim); s += strspn(s, delim);
if(*s == '\0') if(*s == '\0') {
{
*save = s; *save = s;
return NULL; return NULL;
} }
@ -273,8 +259,7 @@ rb_strtok_r(char *s, const char *delim, char **save)
if(s == NULL) if(s == NULL)
*save = (token + strlen(token)); *save = (token + strlen(token));
else else {
{
*s = '\0'; *s = '\0';
*save = s + 1; *save = s + 1;
} }
@ -289,8 +274,8 @@ rb_strtok_r(char *s, const char *delim, char **save)
#endif #endif
static const char base64_table[] = static const char base64_table[] = {
{ 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
@ -325,16 +310,14 @@ rb_base64_encode(const unsigned char *str, int length)
unsigned char *p; unsigned char *p;
unsigned char *result; unsigned char *result;
if((length + 2) < 0 || ((length + 2) / 3) >= (1 << (sizeof(int) * 8 - 2))) if((length + 2) < 0 || ((length + 2) / 3) >= (1 << (sizeof(int) * 8 - 2))) {
{
return NULL; return NULL;
} }
result = rb_malloc(((length + 2) / 3) * 5); result = rb_malloc(((length + 2) / 3) * 5);
p = result; p = result;
while(length > 2) while(length > 2) {
{
*p++ = base64_table[current[0] >> 2]; *p++ = base64_table[current[0] >> 2];
*p++ = base64_table[((current[0] & 0x03) << 4) + (current[1] >> 4)]; *p++ = base64_table[((current[0] & 0x03) << 4) + (current[1] >> 4)];
*p++ = base64_table[((current[1] & 0x0f) << 2) + (current[2] >> 6)]; *p++ = base64_table[((current[1] & 0x0f) << 2) + (current[2] >> 6)];
@ -344,17 +327,13 @@ rb_base64_encode(const unsigned char *str, int length)
length -= 3; length -= 3;
} }
if(length != 0) if(length != 0) {
{
*p++ = base64_table[current[0] >> 2]; *p++ = base64_table[current[0] >> 2];
if(length > 1) if(length > 1) {
{
*p++ = base64_table[((current[0] & 0x03) << 4) + (current[1] >> 4)]; *p++ = base64_table[((current[0] & 0x03) << 4) + (current[1] >> 4)];
*p++ = base64_table[(current[1] & 0x0f) << 2]; *p++ = base64_table[(current[1] & 0x0f) << 2];
*p++ = base64_pad; *p++ = base64_pad;
} } else {
else
{
*p++ = base64_table[(current[0] & 0x03) << 4]; *p++ = base64_table[(current[0] & 0x03) << 4];
*p++ = base64_pad; *p++ = base64_pad;
*p++ = base64_pad; *p++ = base64_pad;
@ -373,8 +352,7 @@ rb_base64_decode(const unsigned char *str, int length, int *ret)
result = rb_malloc(length + 1); result = rb_malloc(length + 1);
while((ch = *current++) != '\0' && length-- > 0) while((ch = *current++) != '\0' && length-- > 0) {
{
if(ch == base64_pad) if(ch == base64_pad)
break; break;
@ -382,8 +360,7 @@ rb_base64_decode(const unsigned char *str, int length, int *ret)
if(ch < 0) if(ch < 0)
continue; continue;
switch (i % 4) switch (i % 4) {
{
case 0: case 0:
result[j] = ch << 2; result[j] = ch << 2;
break; break;
@ -404,10 +381,8 @@ rb_base64_decode(const unsigned char *str, int length, int *ret)
k = j; k = j;
if(ch == base64_pad) if(ch == base64_pad) {
{ switch (i % 4) {
switch (i % 4)
{
case 1: case 1:
free(result); free(result);
return NULL; return NULL;

View File

@ -27,16 +27,14 @@
#include <commio-int.h> #include <commio-int.h>
#define RAWBUF_SIZE 1024 #define RAWBUF_SIZE 1024
struct _rawbuf struct _rawbuf {
{
rb_dlink_node node; rb_dlink_node node;
uint8_t data[RAWBUF_SIZE]; uint8_t data[RAWBUF_SIZE];
int len; int len;
uint8_t flushing; uint8_t flushing;
}; };
struct _rawbuf_head struct _rawbuf_head {
{
rb_dlink_list list; rb_dlink_list list;
int len; int len;
int written; int written;
@ -80,20 +78,17 @@ rb_rawbuf_flush_writev(rawbuf_head_t * rb, rb_fde_t *F)
struct rb_iovec vec[RB_UIO_MAXIOV]; struct rb_iovec vec[RB_UIO_MAXIOV];
memset(vec, 0, sizeof(vec)); memset(vec, 0, sizeof(vec));
if(rb->list.head == NULL) if(rb->list.head == NULL) {
{
errno = EAGAIN; errno = EAGAIN;
return -1; return -1;
} }
RB_DLINK_FOREACH(ptr, rb->list.head) RB_DLINK_FOREACH(ptr, rb->list.head) {
{
if(x >= RB_UIO_MAXIOV) if(x >= RB_UIO_MAXIOV)
break; break;
buf = ptr->data; buf = ptr->data;
if(buf->flushing) if(buf->flushing) {
{
vec[x].iov_base = buf->data + rb->written; vec[x].iov_base = buf->data + rb->written;
vec[x++].iov_len = buf->len - rb->written; vec[x++].iov_len = buf->len - rb->written;
continue; continue;
@ -103,8 +98,7 @@ rb_rawbuf_flush_writev(rawbuf_head_t * rb, rb_fde_t *F)
} }
if(x == 0) if(x == 0) {
{
errno = EAGAIN; errno = EAGAIN;
return -1; return -1;
} }
@ -112,15 +106,12 @@ rb_rawbuf_flush_writev(rawbuf_head_t * rb, rb_fde_t *F)
if(retval <= 0) if(retval <= 0)
return retval; return retval;
RB_DLINK_FOREACH_SAFE(ptr, next, rb->list.head) RB_DLINK_FOREACH_SAFE(ptr, next, rb->list.head) {
{
buf = ptr->data; buf = ptr->data;
if(y++ >= x) if(y++ >= x)
break; break;
if(buf->flushing) if(buf->flushing) {
{ if(xret >= buf->len - rb->written) {
if(xret >= buf->len - rb->written)
{
xret -= buf->len - rb->written; xret -= buf->len - rb->written;
rb->len -= buf->len - rb->written; rb->len -= buf->len - rb->written;
rb_rawbuf_done(rb, buf); rb_rawbuf_done(rb, buf);
@ -128,14 +119,11 @@ rb_rawbuf_flush_writev(rawbuf_head_t * rb, rb_fde_t *F)
} }
} }
if(xret >= buf->len) if(xret >= buf->len) {
{
xret -= buf->len; xret -= buf->len;
rb->len -= buf->len; rb->len -= buf->len;
rb_rawbuf_done(rb, buf); rb_rawbuf_done(rb, buf);
} } else {
else
{
buf->flushing = 1; buf->flushing = 1;
rb->written = xret; rb->written = xret;
rb->len -= xret; rb->len -= xret;
@ -151,8 +139,7 @@ rb_rawbuf_flush(rawbuf_head_t * rb, rb_fde_t *F)
{ {
rawbuf_t *buf; rawbuf_t *buf;
int retval; int retval;
if(rb->list.head == NULL) if(rb->list.head == NULL) {
{
errno = EAGAIN; errno = EAGAIN;
return -1; return -1;
} }
@ -161,8 +148,7 @@ rb_rawbuf_flush(rawbuf_head_t * rb, rb_fde_t *F)
return rb_rawbuf_flush_writev(rb, F); return rb_rawbuf_flush_writev(rb, F);
buf = rb->list.head->data; buf = rb->list.head->data;
if(!buf->flushing) if(!buf->flushing) {
{
buf->flushing = 1; buf->flushing = 1;
rb->written = 0; rb->written = 0;
} }
@ -172,8 +158,7 @@ rb_rawbuf_flush(rawbuf_head_t * rb, rb_fde_t *F)
return retval; return retval;
rb->written += retval; rb->written += retval;
if(rb->written == buf->len) if(rb->written == buf->len) {
{
rb->written = 0; rb->written = 0;
rb_dlinkDelete(&buf->node, &rb->list); rb_dlinkDelete(&buf->node, &rb->list);
rb_bh_free(rawbuf_heap, buf); rb_bh_free(rawbuf_heap, buf);
@ -193,8 +178,7 @@ rb_rawbuf_append(rawbuf_head_t * rb, void *data, int len)
if(rb->list.tail != NULL) if(rb->list.tail != NULL)
buf = rb->list.tail->data; buf = rb->list.tail->data;
if(buf != NULL && buf->len < RAWBUF_SIZE && !buf->flushing) if(buf != NULL && buf->len < RAWBUF_SIZE && !buf->flushing) {
{
buf = (rawbuf_t *) rb->list.tail->data; buf = (rawbuf_t *) rb->list.tail->data;
clen = RAWBUF_SIZE - buf->len; clen = RAWBUF_SIZE - buf->len;
ptr = (void *)(buf->data + buf->len); ptr = (void *)(buf->data + buf->len);
@ -211,8 +195,7 @@ rb_rawbuf_append(rawbuf_head_t * rb, void *data, int len)
} }
while(len > 0) while(len > 0) {
{
buf = rb_rawbuf_newbuf(rb); buf = rb_rawbuf_newbuf(rb);
if(len >= RAWBUF_SIZE) if(len >= RAWBUF_SIZE)
@ -252,8 +235,7 @@ rb_rawbuf_get(rawbuf_head_t * rb, void *data, int len)
memcpy(data, ptr, cpylen); memcpy(data, ptr, cpylen);
if(cpylen == buf->len) if(cpylen == buf->len) {
{
rb->written = 0; rb->written = 0;
rb_rawbuf_done(rb, buf); rb_rawbuf_done(rb, buf);
rb->len -= len; rb->len -= len;
@ -286,8 +268,7 @@ void
rb_free_rawbuffer(rawbuf_head_t * rb) rb_free_rawbuffer(rawbuf_head_t * rb)
{ {
rb_dlink_node *ptr, *next; rb_dlink_node *ptr, *next;
RB_DLINK_FOREACH_SAFE(ptr, next, rb->list.head) RB_DLINK_FOREACH_SAFE(ptr, next, rb->list.head) {
{
rb_rawbuf_done(rb, ptr->data); rb_rawbuf_done(rb, ptr->data);
} }
rb_free(rb); rb_free(rb);

View File

@ -71,43 +71,31 @@ static void
select_update_selectfds(rb_fde_t *F, short event, PF * handler) select_update_selectfds(rb_fde_t *F, short event, PF * handler)
{ {
/* Update the read / write set */ /* Update the read / write set */
if(event & RB_SELECT_READ) if(event & RB_SELECT_READ) {
{ if(handler) {
if(handler)
{
MY_FD_SET(F->fd, &select_readfds); MY_FD_SET(F->fd, &select_readfds);
F->pflags |= RB_SELECT_READ; F->pflags |= RB_SELECT_READ;
} } else {
else
{
MY_FD_CLR(F->fd, &select_readfds); MY_FD_CLR(F->fd, &select_readfds);
F->pflags &= ~RB_SELECT_READ; F->pflags &= ~RB_SELECT_READ;
} }
} }
if(event & RB_SELECT_WRITE) if(event & RB_SELECT_WRITE) {
{ if(handler) {
if(handler)
{
MY_FD_SET(F->fd, &select_writefds); MY_FD_SET(F->fd, &select_writefds);
F->pflags |= RB_SELECT_WRITE; F->pflags |= RB_SELECT_WRITE;
} } else {
else
{
MY_FD_CLR(F->fd, &select_writefds); MY_FD_CLR(F->fd, &select_writefds);
F->pflags &= ~RB_SELECT_WRITE; F->pflags &= ~RB_SELECT_WRITE;
} }
} }
if(F->pflags & (RB_SELECT_READ | RB_SELECT_WRITE)) if(F->pflags & (RB_SELECT_READ | RB_SELECT_WRITE)) {
{ if(F->fd > rb_maxfd) {
if(F->fd > rb_maxfd)
{
rb_maxfd = F->fd; rb_maxfd = F->fd;
} }
} } else if(F->fd <= rb_maxfd) {
else if(F->fd <= rb_maxfd)
{
while(rb_maxfd >= 0 && !FD_ISSET(rb_maxfd, &select_readfds) while(rb_maxfd >= 0 && !FD_ISSET(rb_maxfd, &select_readfds)
&& !FD_ISSET(rb_maxfd, &select_writefds)) && !FD_ISSET(rb_maxfd, &select_writefds))
rb_maxfd--; rb_maxfd--;
@ -153,14 +141,12 @@ rb_setselect_select(rb_fde_t *F, unsigned int type, PF * handler, void *client_d
{ {
lrb_assert(IsFDOpen(F)); lrb_assert(IsFDOpen(F));
if(type & RB_SELECT_READ) if(type & RB_SELECT_READ) {
{
F->read_handler = handler; F->read_handler = handler;
F->read_data = client_data; F->read_data = client_data;
select_update_selectfds(F, RB_SELECT_READ, handler); select_update_selectfds(F, RB_SELECT_READ, handler);
} }
if(type & RB_SELECT_WRITE) if(type & RB_SELECT_WRITE) {
{
F->write_handler = handler; F->write_handler = handler;
F->write_data = client_data; F->write_data = client_data;
select_update_selectfds(F, RB_SELECT_WRITE, handler); select_update_selectfds(F, RB_SELECT_WRITE, handler);
@ -192,8 +178,7 @@ rb_select_select(long delay)
memcpy(&tmpreadfds, &select_readfds, sizeof(fd_set)); memcpy(&tmpreadfds, &select_readfds, sizeof(fd_set));
memcpy(&tmpwritefds, &select_writefds, sizeof(fd_set)); memcpy(&tmpwritefds, &select_writefds, sizeof(fd_set));
for(;;) for(;;) {
{
to.tv_sec = 0; to.tv_sec = 0;
to.tv_usec = delay * 1000; to.tv_usec = delay * 1000;
num = select(rb_maxfd + 1, &tmpreadfds, &tmpwritefds, NULL, &to); num = select(rb_maxfd + 1, &tmpreadfds, &tmpwritefds, NULL, &to);
@ -212,13 +197,11 @@ rb_select_select(long delay)
return 0; return 0;
/* XXX we *could* optimise by falling out after doing num fds ... */ /* XXX we *could* optimise by falling out after doing num fds ... */
for(fd = 0; fd < rb_maxfd + 1; fd++) for(fd = 0; fd < rb_maxfd + 1; fd++) {
{
F = rb_find_fd(fd); F = rb_find_fd(fd);
if(F == NULL) if(F == NULL)
continue; continue;
if(FD_ISSET(fd, &tmpreadfds)) if(FD_ISSET(fd, &tmpreadfds)) {
{
hdl = F->read_handler; hdl = F->read_handler;
F->read_handler = NULL; F->read_handler = NULL;
if(hdl) if(hdl)
@ -228,8 +211,7 @@ rb_select_select(long delay)
if(!IsFDOpen(F)) if(!IsFDOpen(F))
continue; /* Read handler closed us..go on */ continue; /* Read handler closed us..go on */
if(FD_ISSET(fd, &tmpwritefds)) if(FD_ISSET(fd, &tmpwritefds)) {
{
hdl = F->write_handler; hdl = F->write_handler;
F->write_handler = NULL; F->write_handler = NULL;
if(hdl) if(hdl)

View File

@ -53,8 +53,7 @@
#define RTSIGTIM (SIGRTMIN+1) #define RTSIGTIM (SIGRTMIN+1)
struct _pollfd_list struct _pollfd_list {
{
struct pollfd *pollfds; struct pollfd *pollfds;
int maxindex; /* highest FD number */ int maxindex; /* highest FD number */
int allocated; int allocated;
@ -80,8 +79,7 @@ rb_init_netio_sigio(void)
int fd; int fd;
pollfd_list.pollfds = rb_malloc(rb_getmaxconnect() * (sizeof(struct pollfd))); pollfd_list.pollfds = rb_malloc(rb_getmaxconnect() * (sizeof(struct pollfd)));
pollfd_list.allocated = rb_getmaxconnect(); pollfd_list.allocated = rb_getmaxconnect();
for(fd = 0; fd < rb_getmaxconnect(); fd++) for(fd = 0; fd < rb_getmaxconnect(); fd++) {
{
pollfd_list.pollfds[fd].fd = -1; pollfd_list.pollfds[fd].fd = -1;
} }
@ -102,16 +100,14 @@ rb_init_netio_sigio(void)
static inline void static inline void
resize_pollarray(int fd) resize_pollarray(int fd)
{ {
if(rb_unlikely(fd >= pollfd_list.allocated)) if(rb_unlikely(fd >= pollfd_list.allocated)) {
{
int x, old_value = pollfd_list.allocated; int x, old_value = pollfd_list.allocated;
pollfd_list.allocated += 1024; pollfd_list.allocated += 1024;
pollfd_list.pollfds = pollfd_list.pollfds =
rb_realloc(pollfd_list.pollfds, rb_realloc(pollfd_list.pollfds,
pollfd_list.allocated * (sizeof(struct pollfd))); pollfd_list.allocated * (sizeof(struct pollfd)));
memset(&pollfd_list.pollfds[old_value + 1], 0, sizeof(struct pollfd) * 1024); memset(&pollfd_list.pollfds[old_value + 1], 0, sizeof(struct pollfd) * 1024);
for(x = old_value + 1; x < pollfd_list.allocated; x++) for(x = old_value + 1; x < pollfd_list.allocated; x++) {
{
pollfd_list.pollfds[x].fd = -1; pollfd_list.pollfds[x].fd = -1;
} }
} }
@ -135,8 +131,7 @@ rb_setup_fd_sigio(rb_fde_t *F)
if(flags == -1) if(flags == -1)
return 0; return 0;
/* if set async, clear it so we can reset it in the kernel :/ */ /* if set async, clear it so we can reset it in the kernel :/ */
if(flags & O_ASYNC) if(flags & O_ASYNC) {
{
flags &= ~O_ASYNC; flags &= ~O_ASYNC;
fcntl(fd, F_SETFL, flags); fcntl(fd, F_SETFL, flags);
} }
@ -166,8 +161,7 @@ rb_setselect_sigio(rb_fde_t *F, unsigned int type, PF * handler, void *client_da
if(F == NULL) if(F == NULL)
return; return;
if(type & RB_SELECT_READ) if(type & RB_SELECT_READ) {
{
F->read_handler = handler; F->read_handler = handler;
F->read_data = client_data; F->read_data = client_data;
if(handler != NULL) if(handler != NULL)
@ -175,8 +169,7 @@ rb_setselect_sigio(rb_fde_t *F, unsigned int type, PF * handler, void *client_da
else else
F->pflags &= ~POLLRDNORM; F->pflags &= ~POLLRDNORM;
} }
if(type & RB_SELECT_WRITE) if(type & RB_SELECT_WRITE) {
{
F->write_handler = handler; F->write_handler = handler;
F->write_data = client_data; F->write_data = client_data;
if(handler != NULL) if(handler != NULL)
@ -187,19 +180,15 @@ rb_setselect_sigio(rb_fde_t *F, unsigned int type, PF * handler, void *client_da
resize_pollarray(F->fd); resize_pollarray(F->fd);
if(F->pflags <= 0) if(F->pflags <= 0) {
{
pollfd_list.pollfds[F->fd].events = 0; pollfd_list.pollfds[F->fd].events = 0;
pollfd_list.pollfds[F->fd].fd = -1; pollfd_list.pollfds[F->fd].fd = -1;
if(F->fd == pollfd_list.maxindex) if(F->fd == pollfd_list.maxindex) {
{
while(pollfd_list.maxindex >= 0 while(pollfd_list.maxindex >= 0
&& pollfd_list.pollfds[pollfd_list.maxindex].fd == -1) && pollfd_list.pollfds[pollfd_list.maxindex].fd == -1)
pollfd_list.maxindex--; pollfd_list.maxindex--;
} }
} } else {
else
{
pollfd_list.pollfds[F->fd].events = F->pflags; pollfd_list.pollfds[F->fd].events = F->pflags;
pollfd_list.pollfds[F->fd].fd = F->fd; pollfd_list.pollfds[F->fd].fd = F->fd;
if(F->fd > pollfd_list.maxindex) if(F->fd > pollfd_list.maxindex)
@ -237,36 +226,28 @@ rb_select_sigio(long delay)
siginfo_t si; siginfo_t si;
struct timespec timeout; struct timespec timeout;
if(rb_sigio_supports_event() || delay >= 0) if(rb_sigio_supports_event() || delay >= 0) {
{
timeout.tv_sec = (delay / 1000); timeout.tv_sec = (delay / 1000);
timeout.tv_nsec = (delay % 1000) * 1000000; timeout.tv_nsec = (delay % 1000) * 1000000;
} }
for(;;) for(;;) {
{ if(!sigio_is_screwed) {
if(!sigio_is_screwed) if(can_do_event || delay < 0) {
{
if(can_do_event || delay < 0)
{
sig = sigwaitinfo(&our_sigset, &si); sig = sigwaitinfo(&our_sigset, &si);
} } else
else
sig = sigtimedwait(&our_sigset, &si, &timeout); sig = sigtimedwait(&our_sigset, &si, &timeout);
if(sig > 0) if(sig > 0) {
{
if(sig == SIGIO) if(sig == SIGIO) {
{
rb_lib_log rb_lib_log
("Kernel RT Signal queue overflowed. Is ulimit -i too small(or perhaps /proc/sys/kernel/rtsig-max on old kernels)"); ("Kernel RT Signal queue overflowed. Is ulimit -i too small(or perhaps /proc/sys/kernel/rtsig-max on old kernels)");
sigio_is_screwed = 1; sigio_is_screwed = 1;
break; break;
} }
#ifdef SIGIO_SCHED_EVENT #ifdef SIGIO_SCHED_EVENT
if(sig == RTSIGTIM && can_do_event) if(sig == RTSIGTIM && can_do_event) {
{
struct ev_entry *ev = (struct ev_entry *)si.si_ptr; struct ev_entry *ev = (struct ev_entry *)si.si_ptr;
if(ev == NULL) if(ev == NULL)
continue; continue;
@ -282,8 +263,7 @@ rb_select_sigio(long delay)
if(F == NULL) if(F == NULL)
continue; continue;
if(revents & (POLLRDNORM | POLLIN | POLLHUP | POLLERR)) if(revents & (POLLRDNORM | POLLIN | POLLHUP | POLLERR)) {
{
hdl = F->read_handler; hdl = F->read_handler;
data = F->read_data; data = F->read_data;
F->read_handler = NULL; F->read_handler = NULL;
@ -292,8 +272,7 @@ rb_select_sigio(long delay)
hdl(F, data); hdl(F, data);
} }
if(revents & (POLLWRNORM | POLLOUT | POLLHUP | POLLERR)) if(revents & (POLLWRNORM | POLLOUT | POLLHUP | POLLERR)) {
{
hdl = F->write_handler; hdl = F->write_handler;
data = F->write_data; data = F->write_data;
F->write_handler = NULL; F->write_handler = NULL;
@ -301,17 +280,14 @@ rb_select_sigio(long delay)
if(hdl) if(hdl)
hdl(F, data); hdl(F, data);
} }
} } else
else
break; break;
} } else
else
break; break;
} }
if(!sigio_is_screwed) /* We don't need to proceed */ if(!sigio_is_screwed) { /* We don't need to proceed */
{
rb_set_time(); rb_set_time();
return 0; return 0;
} }
@ -323,8 +299,7 @@ rb_select_sigio(long delay)
num = poll(pollfd_list.pollfds, pollfd_list.maxindex + 1, delay); num = poll(pollfd_list.pollfds, pollfd_list.maxindex + 1, delay);
rb_set_time(); rb_set_time();
if(num < 0) if(num < 0) {
{
if(!rb_ignore_errno(errno)) if(!rb_ignore_errno(errno))
return RB_OK; return RB_OK;
else else
@ -334,8 +309,7 @@ rb_select_sigio(long delay)
return RB_OK; return RB_OK;
/* XXX we *could* optimise by falling out after doing num fds ... */ /* XXX we *could* optimise by falling out after doing num fds ... */
for(ci = 0; ci < pollfd_list.maxindex + 1; ci++) for(ci = 0; ci < pollfd_list.maxindex + 1; ci++) {
{
if(((revents = pollfd_list.pollfds[ci].revents) == 0) if(((revents = pollfd_list.pollfds[ci].revents) == 0)
|| (pollfd_list.pollfds[ci].fd) == -1) || (pollfd_list.pollfds[ci].fd) == -1)
continue; continue;
@ -343,8 +317,7 @@ rb_select_sigio(long delay)
F = rb_find_fd(fd); F = rb_find_fd(fd);
if(F == NULL) if(F == NULL)
continue; continue;
if(revents & (POLLRDNORM | POLLIN | POLLHUP | POLLERR)) if(revents & (POLLRDNORM | POLLIN | POLLHUP | POLLERR)) {
{
hdl = F->read_handler; hdl = F->read_handler;
data = F->read_data; data = F->read_data;
F->read_handler = NULL; F->read_handler = NULL;
@ -353,8 +326,7 @@ rb_select_sigio(long delay)
hdl(F, data); hdl(F, data);
} }
if(IsFDOpen(F) && (revents & (POLLWRNORM | POLLOUT | POLLHUP | POLLERR))) if(IsFDOpen(F) && (revents & (POLLWRNORM | POLLOUT | POLLHUP | POLLERR))) {
{
hdl = F->write_handler; hdl = F->write_handler;
data = F->write_data; data = F->write_data;
F->write_handler = NULL; F->write_handler = NULL;
@ -392,8 +364,7 @@ rb_sigio_supports_event(void)
ev.sigev_signo = SIGVTALRM; ev.sigev_signo = SIGVTALRM;
ev.sigev_notify = SIGEV_SIGNAL; ev.sigev_notify = SIGEV_SIGNAL;
if(timer_create(CLOCK_REALTIME, &ev, &timer) != 0) if(timer_create(CLOCK_REALTIME, &ev, &timer) != 0) {
{
can_do_event = -1; can_do_event = -1;
return 0; return 0;
} }
@ -418,8 +389,7 @@ rb_sigio_sched_event(struct ev_entry *event, int when)
ev.sigev_signo = RTSIGTIM; ev.sigev_signo = RTSIGTIM;
ev.sigev_value.sival_ptr = event; ev.sigev_value.sival_ptr = event;
if(timer_create(CLOCK_REALTIME, &ev, id) < 0) if(timer_create(CLOCK_REALTIME, &ev, id) < 0) {
{
rb_lib_log("timer_create: %s\n", strerror(errno)); rb_lib_log("timer_create: %s\n", strerror(errno));
return 0; return 0;
} }
@ -429,8 +399,7 @@ rb_sigio_sched_event(struct ev_entry *event, int when)
if(event->frequency != 0) if(event->frequency != 0)
ts.it_interval = ts.it_value; ts.it_interval = ts.it_value;
if(timer_settime(*id, 0, &ts, NULL) < 0) if(timer_settime(*id, 0, &ts, NULL) < 0) {
{
rb_lib_log("timer_settime: %s\n", strerror(errno)); rb_lib_log("timer_settime: %s\n", strerror(errno));
return 0; return 0;
} }

View File

@ -59,22 +59,19 @@ put_dec_trunc(char *buf, unsigned q)
d0 = d0 - 10 * q; d0 = d0 - 10 * q;
*buf++ = d0 + '0'; /* least significant digit */ *buf++ = d0 + '0'; /* least significant digit */
d1 = q + 9 * d3 + 5 * d2 + d1; d1 = q + 9 * d3 + 5 * d2 + d1;
if(d1 != 0) if(d1 != 0) {
{
q = (d1 * 0xcd) >> 11; q = (d1 * 0xcd) >> 11;
d1 = d1 - 10 * q; d1 = d1 - 10 * q;
*buf++ = d1 + '0'; /* next digit */ *buf++ = d1 + '0'; /* next digit */
d2 = q + 2 * d2; d2 = q + 2 * d2;
if((d2 != 0) || (d3 != 0)) if((d2 != 0) || (d3 != 0)) {
{
q = (d2 * 0xd) >> 7; q = (d2 * 0xd) >> 7;
d2 = d2 - 10 * q; d2 = d2 - 10 * q;
*buf++ = d2 + '0'; /* next digit */ *buf++ = d2 + '0'; /* next digit */
d3 = q + 4 * d3; d3 = q + 4 * d3;
if(d3 != 0) if(d3 != 0) {
{
q = (d3 * 0xcd) >> 11; q = (d3 * 0xcd) >> 11;
d3 = d3 - 10 * q; d3 = d3 - 10 * q;
*buf++ = d3 + '0'; /* next digit */ *buf++ = d3 + '0'; /* next digit */
@ -131,8 +128,7 @@ put_dec_full(char *buf, unsigned q)
static char * static char *
put_dec(char *buf, unsigned long long int num) put_dec(char *buf, unsigned long long int num)
{ {
while(1) while(1) {
{
unsigned rem; unsigned rem;
if(num < 100000) if(num < 100000)
return put_dec_trunc(buf, num); return put_dec_trunc(buf, num);
@ -168,27 +164,20 @@ number(char *const buf, const size_t size, size_t idx, unsigned long long int nu
if(base < 2 || base > 36) if(base < 2 || base > 36)
return idx; return idx;
sign = 0; sign = 0;
if(type & SIGN) if(type & SIGN) {
{ if((signed long long int)num < 0) {
if((signed long long int)num < 0)
{
sign = '-'; sign = '-';
num = -(signed long long int)num; num = -(signed long long int)num;
field_width--; field_width--;
} } else if(type & PLUS) {
else if(type & PLUS)
{
sign = '+'; sign = '+';
field_width--; field_width--;
} } else if(type & SPACE) {
else if(type & SPACE)
{
sign = ' '; sign = ' ';
field_width--; field_width--;
} }
} }
if(need_pfx) if(need_pfx) {
{
field_width--; field_width--;
if(base == 16) if(base == 16)
field_width--; field_width--;
@ -203,21 +192,18 @@ number(char *const buf, const size_t size, size_t idx, unsigned long long int nu
tmp[i++] = digits[do_div(num,base)]; tmp[i++] = digits[do_div(num,base)];
} while (num != 0); } while (num != 0);
*/ */
else if(base != 10) else if(base != 10) {
{ /* 8 or 16 */ /* 8 or 16 */
int mask = base - 1; int mask = base - 1;
int shift = 3; int shift = 3;
if(base == 16) if(base == 16)
shift = 4; shift = 4;
do do {
{
tmp[i++] = digits[((unsigned char)num) & mask]; tmp[i++] = digits[((unsigned char)num) & mask];
num >>= shift; num >>= shift;
} } while(num);
while(num); } else {
} /* base 10 */
else
{ /* base 10 */
i = put_dec(tmp, num) - tmp; i = put_dec(tmp, num) - tmp;
} }
@ -226,63 +212,53 @@ number(char *const buf, const size_t size, size_t idx, unsigned long long int nu
precision = i; precision = i;
/* leading space padding */ /* leading space padding */
field_width -= precision; field_width -= precision;
if(!(type & (ZEROPAD + LEFT))) if(!(type & (ZEROPAD + LEFT))) {
{ while(--field_width >= 0) {
while(--field_width >= 0)
{
if(idx < size) if(idx < size)
buf[idx] = ' '; buf[idx] = ' ';
++idx; ++idx;
} }
} }
/* sign */ /* sign */
if(sign) if(sign) {
{
if(idx < size) if(idx < size)
buf[idx] = sign; buf[idx] = sign;
++idx; ++idx;
} }
/* "0x" / "0" prefix */ /* "0x" / "0" prefix */
if(need_pfx) if(need_pfx) {
{
if(idx < size) if(idx < size)
buf[idx] = '0'; buf[idx] = '0';
++idx; ++idx;
if(base == 16) if(base == 16) {
{
if(idx < size) if(idx < size)
buf[idx] = digits[16]; /* for arbitrary base: digits[33]; */ buf[idx] = digits[16]; /* for arbitrary base: digits[33]; */
++idx; ++idx;
} }
} }
/* zero or space padding */ /* zero or space padding */
if(!(type & LEFT)) if(!(type & LEFT)) {
{
char c = (type & ZEROPAD) ? '0' : ' '; char c = (type & ZEROPAD) ? '0' : ' ';
while(--field_width >= 0) while(--field_width >= 0) {
{
if(idx < size) if(idx < size)
buf[idx] = c; buf[idx] = c;
++idx; ++idx;
} }
} }
/* hmm even more zero padding? */ /* hmm even more zero padding? */
while(i <= --precision) while(i <= --precision) {
{
if(idx < size) if(idx < size)
buf[idx] = '0'; buf[idx] = '0';
++idx; ++idx;
} }
/* actual digits of result */ /* actual digits of result */
while(--i >= 0) while(--i >= 0) {
{
if(idx < size) if(idx < size)
buf[idx] = tmp[i]; buf[idx] = tmp[i];
++idx; ++idx;
} }
/* trailing space padding */ /* trailing space padding */
while(--field_width >= 0) while(--field_width >= 0) {
{
if(idx < size) if(idx < size)
buf[idx] = ' '; buf[idx] = ' ';
++idx; ++idx;
@ -330,17 +306,14 @@ rb_vsnprintf(char *buf, size_t size, const char *fmt, va_list args)
/* Reject out-of-range values early. Large positive sizes are /* Reject out-of-range values early. Large positive sizes are
used for unknown buffer sizes. */ used for unknown buffer sizes. */
if(rb_unlikely(size > INT_MAX)) if(rb_unlikely(size > INT_MAX)) {
{
return 0; return 0;
} }
idx = 0; idx = 0;
for(; *fmt; ++fmt) for(; *fmt; ++fmt) {
{ if(*fmt != '%') {
if(*fmt != '%')
{
if(idx < size) if(idx < size)
buf[idx] = *fmt; buf[idx] = *fmt;
++idx; ++idx;
@ -349,10 +322,9 @@ rb_vsnprintf(char *buf, size_t size, const char *fmt, va_list args)
/* process flags */ /* process flags */
flags = 0; flags = 0;
repeat: repeat:
++fmt; /* this also skips first '%' */ ++fmt; /* this also skips first '%' */
switch (*fmt) switch (*fmt) {
{
case '-': case '-':
flags |= LEFT; flags |= LEFT;
goto repeat; goto repeat;
@ -374,13 +346,11 @@ rb_vsnprintf(char *buf, size_t size, const char *fmt, va_list args)
field_width = -1; field_width = -1;
if(isdigit(*fmt)) if(isdigit(*fmt))
field_width = skip_atoi(&fmt); field_width = skip_atoi(&fmt);
else if(*fmt == '*') else if(*fmt == '*') {
{
++fmt; ++fmt;
/* it's the next argument */ /* it's the next argument */
field_width = va_arg(args, int); field_width = va_arg(args, int);
if(field_width < 0) if(field_width < 0) {
{
field_width = -field_width; field_width = -field_width;
flags |= LEFT; flags |= LEFT;
} }
@ -388,13 +358,11 @@ rb_vsnprintf(char *buf, size_t size, const char *fmt, va_list args)
/* get the precision */ /* get the precision */
precision = -1; precision = -1;
if(*fmt == '.') if(*fmt == '.') {
{
++fmt; ++fmt;
if(isdigit(*fmt)) if(isdigit(*fmt))
precision = skip_atoi(&fmt); precision = skip_atoi(&fmt);
else if(*fmt == '*') else if(*fmt == '*') {
{
++fmt; ++fmt;
/* it's the next argument */ /* it's the next argument */
precision = va_arg(args, int); precision = va_arg(args, int);
@ -406,12 +374,10 @@ rb_vsnprintf(char *buf, size_t size, const char *fmt, va_list args)
/* get the conversion qualifier */ /* get the conversion qualifier */
qualifier = -1; qualifier = -1;
if(*fmt == 'h' || *fmt == 'l' || *fmt == 'L' || if(*fmt == 'h' || *fmt == 'l' || *fmt == 'L' ||
*fmt == 'Z' || *fmt == 'z' || *fmt == 't') *fmt == 'Z' || *fmt == 'z' || *fmt == 't') {
{
qualifier = *fmt; qualifier = *fmt;
++fmt; ++fmt;
if(qualifier == 'l' && *fmt == 'l') if(qualifier == 'l' && *fmt == 'l') {
{
qualifier = 'L'; qualifier = 'L';
++fmt; ++fmt;
} }
@ -420,13 +386,10 @@ rb_vsnprintf(char *buf, size_t size, const char *fmt, va_list args)
/* default base */ /* default base */
base = 10; base = 10;
switch (*fmt) switch (*fmt) {
{
case 'c': case 'c':
if(!(flags & LEFT)) if(!(flags & LEFT)) {
{ while(--field_width > 0) {
while(--field_width > 0)
{
if(idx < size) if(idx < size)
buf[idx] = ' '; buf[idx] = ' ';
++idx; ++idx;
@ -436,8 +399,7 @@ rb_vsnprintf(char *buf, size_t size, const char *fmt, va_list args)
if(idx < size) if(idx < size)
buf[idx] = c; buf[idx] = c;
++idx; ++idx;
while(--field_width > 0) while(--field_width > 0) {
{
if(idx < size) if(idx < size)
buf[idx] = ' '; buf[idx] = ' ';
++idx; ++idx;
@ -446,30 +408,25 @@ rb_vsnprintf(char *buf, size_t size, const char *fmt, va_list args)
case 's': case 's':
s = va_arg(args, char *); s = va_arg(args, char *);
if(s == NULL) if(s == NULL) {
{
abort(); /* prefer blowing up vs corrupt data */ abort(); /* prefer blowing up vs corrupt data */
} }
len = rb_strnlen(s, precision); len = rb_strnlen(s, precision);
if(!(flags & LEFT)) if(!(flags & LEFT)) {
{ while(len < field_width--) {
while(len < field_width--)
{
if(idx < size) if(idx < size)
buf[idx] = ' '; buf[idx] = ' ';
++idx; ++idx;
} }
} }
for(i = 0; i < len; ++i) for(i = 0; i < len; ++i) {
{
if(idx < size) if(idx < size)
buf[idx] = *s; buf[idx] = *s;
++idx; ++idx;
++s; ++s;
} }
while(len < field_width--) while(len < field_width--) {
{
if(idx < size) if(idx < size)
buf[idx] = ' '; buf[idx] = ' ';
++idx; ++idx;
@ -477,8 +434,7 @@ rb_vsnprintf(char *buf, size_t size, const char *fmt, va_list args)
continue; continue;
case 'p': case 'p':
if(field_width == -1) if(field_width == -1) {
{
field_width = 2 * sizeof(void *); field_width = 2 * sizeof(void *);
flags |= ZEROPAD; flags |= ZEROPAD;
} }
@ -491,18 +447,13 @@ rb_vsnprintf(char *buf, size_t size, const char *fmt, va_list args)
case 'n': case 'n':
/* FIXME: /* FIXME:
* What does C99 say about the overflow case here? */ * What does C99 say about the overflow case here? */
if(qualifier == 'l') if(qualifier == 'l') {
{
long *ip = va_arg(args, long *); long *ip = va_arg(args, long *);
*ip = idx; *ip = idx;
} } else if(qualifier == 'Z' || qualifier == 'z') {
else if(qualifier == 'Z' || qualifier == 'z')
{
size_t *ip = va_arg(args, size_t *); size_t *ip = va_arg(args, size_t *);
*ip = idx; *ip = idx;
} } else {
else
{
int *ip = va_arg(args, int *); int *ip = va_arg(args, int *);
*ip = idx; *ip = idx;
} }
@ -535,50 +486,37 @@ rb_vsnprintf(char *buf, size_t size, const char *fmt, va_list args)
if(idx < size) if(idx < size)
buf[idx] = '%'; buf[idx] = '%';
++idx; ++idx;
if(*fmt) if(*fmt) {
{
if(idx < size) if(idx < size)
buf[idx] = *fmt; buf[idx] = *fmt;
++idx; ++idx;
} } else {
else
{
--fmt; --fmt;
} }
continue; continue;
} }
if(qualifier == 'L') if(qualifier == 'L')
num = va_arg(args, long long int); num = va_arg(args, long long int);
else if(qualifier == 'l') else if(qualifier == 'l') {
{
num = va_arg(args, unsigned long); num = va_arg(args, unsigned long);
if(flags & SIGN) if(flags & SIGN)
num = (signed long)num; num = (signed long)num;
} } else if(qualifier == 'Z' || qualifier == 'z') {
else if(qualifier == 'Z' || qualifier == 'z')
{
num = va_arg(args, size_t); num = va_arg(args, size_t);
} } else if(qualifier == 't') {
else if(qualifier == 't')
{
num = va_arg(args, ptrdiff_t); num = va_arg(args, ptrdiff_t);
} } else if(qualifier == 'h') {
else if(qualifier == 'h')
{
num = (unsigned short)va_arg(args, int); num = (unsigned short)va_arg(args, int);
if(flags & SIGN) if(flags & SIGN)
num = (signed short)num; num = (signed short)num;
} } else {
else
{
num = va_arg(args, unsigned int); num = va_arg(args, unsigned int);
if(flags & SIGN) if(flags & SIGN)
num = (signed int)num; num = (signed int)num;
} }
idx = number(buf, size, idx, num, base, field_width, precision, flags); idx = number(buf, size, idx, num, base, field_width, precision, flags);
} }
if(size > 0) if(size > 0) {
{
if(idx < size) if(idx < size)
buf[idx] = '\0'; buf[idx] = '\0';
else else
@ -694,8 +632,7 @@ rb_vsnprintf_append(char *str, size_t len, const char *format, va_list ap)
return 0; return 0;
x = strlen(str); x = strlen(str);
if(len < x) if(len < x) {
{
str[len - 1] = '\0'; str[len - 1] = '\0';
return len - 1; return len - 1;
} }

View File

@ -101,33 +101,26 @@ rb_string_to_array(char *string, char **parv, int maxpara)
if(*xbuf == '\0') /* ignore all-space args */ if(*xbuf == '\0') /* ignore all-space args */
return x; return x;
do do {
{ if(*xbuf == ':') { /* Last parameter */
if(*xbuf == ':') /* Last parameter */
{
xbuf++; xbuf++;
parv[x++] = xbuf; parv[x++] = xbuf;
parv[x] = NULL; parv[x] = NULL;
return x; return x;
} } else {
else
{
parv[x++] = xbuf; parv[x++] = xbuf;
parv[x] = NULL; parv[x] = NULL;
if((p = strchr(xbuf, ' ')) != NULL) if((p = strchr(xbuf, ' ')) != NULL) {
{
*p++ = '\0'; *p++ = '\0';
xbuf = p; xbuf = p;
} } else
else
return x; return x;
} }
while(*xbuf == ' ') while(*xbuf == ' ')
xbuf++; xbuf++;
if(*xbuf == '\0') if(*xbuf == '\0')
return x; return x;
} } while(x < maxpara - 1);
while(x < maxpara - 1);
if(*p == ':') if(*p == ':')
p++; p++;
@ -167,8 +160,7 @@ rb_strlcpy(char *dest, const char *src, size_t size)
{ {
size_t ret = strlen(src); size_t ret = strlen(src);
if(size) if(size) {
{
size_t len = (ret >= size) ? size - 1 : ret; size_t len = (ret >= size) ? size - 1 : ret;
memcpy(dest, src, len); memcpy(dest, src, len);
dest[len] = '\0'; dest[len] = '\0';
@ -229,8 +221,7 @@ rb_dirname (const char *path)
char *s; char *s;
s = strrchr(path, '/'); s = strrchr(path, '/');
if(s == NULL) if(s == NULL) {
{
return rb_strdup("."); return rb_strdup(".");
} }

View File

@ -60,8 +60,7 @@ rb_spawn_process(const char *path, const char **argv)
#endif #endif
error = posix_spawn(&pid, path, NULL, &spattr, arghack, myenviron); error = posix_spawn(&pid, path, NULL, &spattr, arghack, myenviron);
posix_spawnattr_destroy(&spattr); posix_spawnattr_destroy(&spattr);
if (error != 0) if (error != 0) {
{
errno = error; errno = error;
pid = -1; pid = -1;
} }
@ -72,8 +71,7 @@ pid_t
rb_spawn_process(const char *path, const char **argv) rb_spawn_process(const char *path, const char **argv)
{ {
pid_t pid; pid_t pid;
if(!(pid = vfork())) if(!(pid = vfork())) {
{
execv(path, (const void *)argv); /* make gcc shut up */ execv(path, (const void *)argv); /* make gcc shut up */
_exit(1); /* if we're still here, we're screwed */ _exit(1); /* if we're still here, we're screwed */
} }
@ -85,8 +83,7 @@ rb_spawn_process(const char *path, const char **argv)
int int
rb_gettimeofday(struct timeval *tv, void *tz) rb_gettimeofday(struct timeval *tv, void *tz)
{ {
if(tv == NULL) if(tv == NULL) {
{
errno = EFAULT; errno = EFAULT;
return -1; return -1;
} }

View File

@ -38,8 +38,7 @@ static HWND hwnd;
* having gettimeofday is nice... * having gettimeofday is nice...
*/ */
typedef union typedef union {
{
unsigned __int64 ft_i64; unsigned __int64 ft_i64;
FILETIME ft_val; FILETIME ft_val;
} FT_t; } FT_t;
@ -100,26 +99,20 @@ rb_waitpid(int pid, int *status, int flags)
DWORD waitcode; DWORD waitcode;
hProcess = OpenProcess(PROCESS_ALL_ACCESS, TRUE, pid); hProcess = OpenProcess(PROCESS_ALL_ACCESS, TRUE, pid);
if(hProcess) if(hProcess) {
{
waitcode = WaitForSingleObject(hProcess, timeout); waitcode = WaitForSingleObject(hProcess, timeout);
if(waitcode == WAIT_TIMEOUT) if(waitcode == WAIT_TIMEOUT) {
{
CloseHandle(hProcess); CloseHandle(hProcess);
return 0; return 0;
} } else if(waitcode == WAIT_OBJECT_0) {
else if(waitcode == WAIT_OBJECT_0) if(GetExitCodeProcess(hProcess, &waitcode)) {
{
if(GetExitCodeProcess(hProcess, &waitcode))
{
*status = (int)((waitcode & 0xff) << 8); *status = (int)((waitcode & 0xff) << 8);
CloseHandle(hProcess); CloseHandle(hProcess);
return pid; return pid;
} }
} }
CloseHandle(hProcess); CloseHandle(hProcess);
} } else
else
errno = ECHILD; errno = ECHILD;
return -1; return -1;
@ -130,12 +123,9 @@ rb_setenv(const char *name, const char *value, int overwrite)
{ {
char *buf; char *buf;
int len; int len;
if(!overwrite) if(!overwrite) {
{ if((buf = getenv(name)) != NULL) {
if((buf = getenv(name)) != NULL) if(strlen(buf) > 0) {
{
if(strlen(buf) > 0)
{
return 0; return 0;
} }
} }
@ -157,10 +147,8 @@ rb_kill(int pid, int sig)
int ret = -1; int ret = -1;
hProcess = OpenProcess(PROCESS_ALL_ACCESS, TRUE, pid); hProcess = OpenProcess(PROCESS_ALL_ACCESS, TRUE, pid);
if(hProcess) if(hProcess) {
{ switch (sig) {
switch (sig)
{
case 0: case 0:
ret = 0; ret = 0;
break; break;
@ -171,8 +159,7 @@ rb_kill(int pid, int sig)
break; break;
} }
CloseHandle(hProcess); CloseHandle(hProcess);
} } else
else
errno = EINVAL; errno = EINVAL;
return ret; return ret;
@ -194,8 +181,7 @@ static int
make_wsaprotocol_info(pid_t process, rb_fde_t *F, WSAPROTOCOL_INFO * inf) make_wsaprotocol_info(pid_t process, rb_fde_t *F, WSAPROTOCOL_INFO * inf)
{ {
WSAPROTOCOL_INFO info; WSAPROTOCOL_INFO info;
if(!WSADuplicateSocket((SOCKET) rb_get_fd(F), process, &info)) if(!WSADuplicateSocket((SOCKET) rb_get_fd(F), process, &info)) {
{
memcpy(inf, &info, sizeof(WSAPROTOCOL_INFO)); memcpy(inf, &info, sizeof(WSAPROTOCOL_INFO));
return 1; return 1;
} }
@ -208,8 +194,7 @@ make_fde_from_wsaprotocol_info(void *data)
WSAPROTOCOL_INFO *info = data; WSAPROTOCOL_INFO *info = data;
SOCKET t; SOCKET t;
t = WSASocket(FROM_PROTOCOL_INFO, FROM_PROTOCOL_INFO, FROM_PROTOCOL_INFO, info, 0, 0); t = WSASocket(FROM_PROTOCOL_INFO, FROM_PROTOCOL_INFO, FROM_PROTOCOL_INFO, info, 0, 0);
if(t == INVALID_SOCKET) if(t == INVALID_SOCKET) {
{
rb_get_errno(); rb_get_errno();
return NULL; return NULL;
} }
@ -228,13 +213,11 @@ rb_send_fd_buf(rb_fde_t *xF, rb_fde_t **F, int count, void *data, size_t datasiz
int i; int i;
uint32_t magic = MAGIC_CONTROL; uint32_t magic = MAGIC_CONTROL;
void *ptr; void *ptr;
if(count > 4) if(count > 4) {
{
errno = EINVAL; errno = EINVAL;
return -1; return -1;
} }
if(bufsize > sizeof(fd_buf)) if(bufsize > sizeof(fd_buf)) {
{
errno = EINVAL; errno = EINVAL;
return -1; return -1;
} }
@ -246,8 +229,7 @@ rb_send_fd_buf(rb_fde_t *xF, rb_fde_t **F, int count, void *data, size_t datasiz
*((uint8_t *)ptr) = count; *((uint8_t *)ptr) = count;
ptr = (void *)((uintptr_t)ptr + (uintptr_t)sizeof(uint8_t)); ptr = (void *)((uintptr_t)ptr + (uintptr_t)sizeof(uint8_t));
for(i = 0; i < count; i++) for(i = 0; i < count; i++) {
{
make_wsaprotocol_info(pid, F[i], (WSAPROTOCOL_INFO *) ptr); make_wsaprotocol_info(pid, F[i], (WSAPROTOCOL_INFO *) ptr);
ptr = (void *)((uintptr_t)ptr + (uintptr_t)sizeof(WSAPROTOCOL_INFO)); ptr = (void *)((uintptr_t)ptr + (uintptr_t)sizeof(WSAPROTOCOL_INFO));
} }
@ -275,27 +257,23 @@ rb_recv_fd_buf(rb_fde_t *F, void *data, size_t datasize, rb_fde_t **xF, int nfds
ssize_t ret; ssize_t ret;
memset(fd_buf, 0, sizeof(fd_buf)); /* some paranoia here... */ memset(fd_buf, 0, sizeof(fd_buf)); /* some paranoia here... */
ret = rb_read(F, fd_buf, sizeof(fd_buf)); ret = rb_read(F, fd_buf, sizeof(fd_buf));
if(ret <= 0) if(ret <= 0) {
{
return ret; return ret;
} }
if(ret < (ssize_t) minsize) if(ret < (ssize_t) minsize) {
{
errno = EINVAL; errno = EINVAL;
return -1; return -1;
} }
ptr = fd_buf; ptr = fd_buf;
memcpy(&magic, ptr, sizeof(uint32_t)); memcpy(&magic, ptr, sizeof(uint32_t));
if(magic != MAGIC_CONTROL) if(magic != MAGIC_CONTROL) {
{
errno = EAGAIN; errno = EAGAIN;
return -1; return -1;
} }
ptr = (void *)((uintptr_t)ptr + (uintptr_t)sizeof(uint32_t)); ptr = (void *)((uintptr_t)ptr + (uintptr_t)sizeof(uint32_t));
memcpy(&count, ptr, sizeof(uint8_t)); memcpy(&count, ptr, sizeof(uint8_t));
ptr = (void *)((uintptr_t)ptr + (uintptr_t)sizeof(uint8_t)); ptr = (void *)((uintptr_t)ptr + (uintptr_t)sizeof(uint8_t));
for(i = 0; i < count && i < (unsigned int)nfds; i++) for(i = 0; i < count && i < (unsigned int)nfds; i++) {
{
rb_fde_t *tF = make_fde_from_wsaprotocol_info(ptr); rb_fde_t *tF = make_fde_from_wsaprotocol_info(ptr);
if(tF == NULL) if(tF == NULL)
return -1; return -1;
@ -315,22 +293,16 @@ rb_process_events(HWND nhwnd, UINT umsg, WPARAM wparam, LPARAM lparam)
rb_fde_t *F; rb_fde_t *F;
PF *hdl; PF *hdl;
void *data; void *data;
switch (umsg) switch (umsg) {
{ case WM_SOCKET: {
case WM_SOCKET:
{
F = rb_find_fd(wparam); F = rb_find_fd(wparam);
if(F != NULL && IsFDOpen(F)) if(F != NULL && IsFDOpen(F)) {
{ switch (WSAGETSELECTEVENT(lparam)) {
switch (WSAGETSELECTEVENT(lparam))
{
case FD_ACCEPT: case FD_ACCEPT:
case FD_CLOSE: case FD_CLOSE:
case FD_READ: case FD_READ: {
{ if((hdl = F->read_handler) != NULL) {
if((hdl = F->read_handler) != NULL)
{
F->read_handler = NULL; F->read_handler = NULL;
data = F->read_data; data = F->read_data;
F->read_data = NULL; F->read_data = NULL;
@ -340,10 +312,8 @@ rb_process_events(HWND nhwnd, UINT umsg, WPARAM wparam, LPARAM lparam)
} }
case FD_CONNECT: case FD_CONNECT:
case FD_WRITE: case FD_WRITE: {
{ if((hdl = F->write_handler) != NULL) {
if((hdl = F->write_handler) != NULL)
{
F->write_handler = NULL; F->write_handler = NULL;
data = F->write_data; data = F->write_data;
F->write_data = NULL; F->write_data = NULL;
@ -355,8 +325,7 @@ rb_process_events(HWND nhwnd, UINT umsg, WPARAM wparam, LPARAM lparam)
} }
return 0; return 0;
} }
case WM_DESTROY: case WM_DESTROY: {
{
PostQuitMessage(0); PostQuitMessage(0);
return 0; return 0;
} }
@ -410,13 +379,10 @@ rb_setup_fd_win32(rb_fde_t *F)
return 0; return 0;
SetHandleInformation((HANDLE) F->fd, HANDLE_FLAG_INHERIT, 0); SetHandleInformation((HANDLE) F->fd, HANDLE_FLAG_INHERIT, 0);
switch (F->type) switch (F->type) {
{ case RB_FD_SOCKET: {
case RB_FD_SOCKET:
{
u_long nonb = 1; u_long nonb = 1;
if(ioctlsocket((SOCKET) F->fd, FIONBIO, &nonb) == -1) if(ioctlsocket((SOCKET) F->fd, FIONBIO, &nonb) == -1) {
{
rb_get_errno(); rb_get_errno();
return 0; return 0;
} }
@ -436,8 +402,7 @@ rb_setselect_win32(rb_fde_t *F, unsigned int type, PF * handler, void *client_da
lrb_assert(IsFDOpen(F)); lrb_assert(IsFDOpen(F));
/* Update the list, even though we're not using it .. */ /* Update the list, even though we're not using it .. */
if(type & RB_SELECT_READ) if(type & RB_SELECT_READ) {
{
if(handler != NULL) if(handler != NULL)
F->pflags |= FD_CLOSE | FD_READ | FD_ACCEPT; F->pflags |= FD_CLOSE | FD_READ | FD_ACCEPT;
else else
@ -446,8 +411,7 @@ rb_setselect_win32(rb_fde_t *F, unsigned int type, PF * handler, void *client_da
F->read_data = client_data; F->read_data = client_data;
} }
if(type & RB_SELECT_WRITE) if(type & RB_SELECT_WRITE) {
{
if(handler != NULL) if(handler != NULL)
F->pflags |= FD_WRITE | FD_CONNECT; F->pflags |= FD_WRITE | FD_CONNECT;
else else
@ -459,8 +423,7 @@ rb_setselect_win32(rb_fde_t *F, unsigned int type, PF * handler, void *client_da
if(old_flags == 0 && F->pflags == 0) if(old_flags == 0 && F->pflags == 0)
return; return;
if(F->pflags != old_flags) if(F->pflags != old_flags) {
{
WSAAsyncSelect(F->fd, hwnd, WM_SOCKET, F->pflags); WSAAsyncSelect(F->fd, hwnd, WM_SOCKET, F->pflags);
} }
@ -473,8 +436,7 @@ int
rb_select_win32(long delay) rb_select_win32(long delay)
{ {
MSG msg; MSG msg;
if(has_set_timer == 0) if(has_set_timer == 0) {
{
/* XXX should probably have this handle all the events /* XXX should probably have this handle all the events
* instead of busy looping * instead of busy looping
*/ */
@ -482,8 +444,7 @@ rb_select_win32(long delay)
has_set_timer = 1; has_set_timer = 1;
} }
if(GetMessage(&msg, NULL, 0, 0) == FALSE) if(GetMessage(&msg, NULL, 0, 0) == FALSE) {
{
rb_lib_die("GetMessage failed..byebye"); rb_lib_die("GetMessage failed..byebye");
} }
rb_set_time(); rb_set_time();
@ -499,8 +460,7 @@ rb_select_win32(long delay)
static const char * static const char *
_rb_strerror(int error) _rb_strerror(int error)
{ {
switch (error) switch (error) {
{
case 0: case 0:
return "Success"; return "Success";
case WSAEINTR: case WSAEINTR:

View File

@ -89,15 +89,13 @@ ms_ban(struct Client *client_p, struct Client *source_p, int parc, const char *p
int act; int act;
int valid; int valid;
if (strlen(parv[1]) != 1) if (strlen(parv[1]) != 1) {
{
sendto_realops_snomask(SNO_GENERAL, L_NETWIDE, sendto_realops_snomask(SNO_GENERAL, L_NETWIDE,
"Unknown BAN type %s from %s", "Unknown BAN type %s from %s",
parv[1], source_p->name); parv[1], source_p->name);
return 0; return 0;
} }
switch (parv[1][0]) switch (parv[1][0]) {
{
case 'K': case 'K':
ntype = CONF_KILL; ntype = CONF_KILL;
stype = "K-Line"; stype = "K-Line";
@ -125,14 +123,12 @@ ms_ban(struct Client *client_p, struct Client *source_p, int parc, const char *p
else else
oper = parv[7]; oper = parv[7];
ptr = find_prop_ban(ntype, parv[2], parv[3]); ptr = find_prop_ban(ntype, parv[2], parv[3]);
if (ptr != NULL) if (ptr != NULL) {
{
/* We already know about this ban mask. */ /* We already know about this ban mask. */
aconf = ptr->data; aconf = ptr->data;
if (aconf->created > created || if (aconf->created > created ||
(aconf->created == created && (aconf->created == created &&
aconf->lifetime >= lifetime)) aconf->lifetime >= lifetime)) {
{
if (IsPerson(source_p)) if (IsPerson(source_p))
sendto_one_notice(source_p, sendto_one_notice(source_p,
":Your %s [%s%s%s] has been superseded", ":Your %s [%s%s%s] has been superseded",
@ -166,9 +162,7 @@ ms_ban(struct Client *client_p, struct Client *source_p, int parc, const char *p
aconf->passwd = NULL; aconf->passwd = NULL;
rb_free(aconf->spasswd); rb_free(aconf->spasswd);
aconf->spasswd = NULL; aconf->spasswd = NULL;
} } else {
else
{
/* New ban mask. */ /* New ban mask. */
aconf = make_conf(); aconf = make_conf();
aconf->status = CONF_ILLEGAL | ntype; aconf->status = CONF_ILLEGAL | ntype;
@ -185,8 +179,7 @@ ms_ban(struct Client *client_p, struct Client *source_p, int parc, const char *p
aconf->hold = hold; aconf->hold = hold;
if (ntype != CONF_KILL || (p = strchr(parv[parc - 1], '|')) == NULL) if (ntype != CONF_KILL || (p = strchr(parv[parc - 1], '|')) == NULL)
aconf->passwd = rb_strdup(parv[parc - 1]); aconf->passwd = rb_strdup(parv[parc - 1]);
else else {
{
aconf->passwd = rb_strndup(parv[parc - 1], p - parv[parc - 1] + 1); aconf->passwd = rb_strndup(parv[parc - 1], p - parv[parc - 1] + 1);
aconf->spasswd = rb_strdup(p + 1); aconf->spasswd = rb_strdup(p + 1);
} }
@ -197,8 +190,7 @@ ms_ban(struct Client *client_p, struct Client *source_p, int parc, const char *p
/* We only reject *@* and the like here. /* We only reject *@* and the like here.
* Otherwise malformed bans are fairly harmless and can be removed. * Otherwise malformed bans are fairly harmless and can be removed.
*/ */
switch (ntype) switch (ntype) {
{
case CONF_KILL: case CONF_KILL:
valid = valid_wild_card(aconf->user, aconf->host); valid = valid_wild_card(aconf->user, aconf->host);
break; break;
@ -209,8 +201,7 @@ ms_ban(struct Client *client_p, struct Client *source_p, int parc, const char *p
valid = valid_wild_card_simple(aconf->host); valid = valid_wild_card_simple(aconf->host);
break; break;
} }
if (act && hold != created && !valid) if (act && hold != created && !valid) {
{
sendto_realops_snomask(SNO_GENERAL, L_ALL, sendto_realops_snomask(SNO_GENERAL, L_ALL,
"Ignoring global %d min. %s from %s%s%s for [%s%s%s]: too few non-wildcard characters", "Ignoring global %d min. %s from %s%s%s for [%s%s%s]: too few non-wildcard characters",
(int)((hold - rb_current_time()) / 60), (int)((hold - rb_current_time()) / 60),
@ -229,9 +220,7 @@ ms_ban(struct Client *client_p, struct Client *source_p, int parc, const char *p
aconf->user ? "@" : "", aconf->user ? "@" : "",
aconf->host); aconf->host);
/* Propagate it, but do not apply it locally. */ /* Propagate it, but do not apply it locally. */
} } else if (act && hold != created) {
else if (act && hold != created)
{
/* Keep the notices in sync with modules/m_kline.c etc. */ /* Keep the notices in sync with modules/m_kline.c etc. */
sendto_realops_snomask(SNO_GENERAL, L_ALL, sendto_realops_snomask(SNO_GENERAL, L_ALL,
"%s added global %d min. %s%s%s for [%s%s%s] [%s]", "%s added global %d min. %s%s%s for [%s%s%s] [%s]",
@ -252,9 +241,7 @@ ms_ban(struct Client *client_p, struct Client *source_p, int parc, const char *p
aconf->host, aconf->host,
parv[parc - 1]); parv[parc - 1]);
aconf->status &= ~CONF_ILLEGAL; aconf->status &= ~CONF_ILLEGAL;
} } else if (act) {
else if (act)
{
sendto_realops_snomask(SNO_GENERAL, L_ALL, sendto_realops_snomask(SNO_GENERAL, L_ALL,
"%s has removed the global %s for: [%s%s%s]%s%s", "%s has removed the global %s for: [%s%s%s]%s%s",
IsServer(source_p) ? source_p->name : get_oper_name(source_p), IsServer(source_p) ? source_p->name : get_oper_name(source_p),
@ -275,41 +262,34 @@ ms_ban(struct Client *client_p, struct Client *source_p, int parc, const char *p
* If CONF_ILLEGAL is not set, add the ban to the type-specific data * If CONF_ILLEGAL is not set, add the ban to the type-specific data
* structure and take action on matched clients/channels. * structure and take action on matched clients/channels.
*/ */
switch (ntype) switch (ntype) {
{
case CONF_KILL: case CONF_KILL:
if (aconf->status & CONF_ILLEGAL) if (aconf->status & CONF_ILLEGAL)
remove_reject_mask(aconf->user, aconf->host); remove_reject_mask(aconf->user, aconf->host);
else else {
{
add_conf_by_address(aconf->host, CONF_KILL, aconf->user, NULL, aconf); add_conf_by_address(aconf->host, CONF_KILL, aconf->user, NULL, aconf);
if(ConfigFileEntry.kline_delay || if(ConfigFileEntry.kline_delay ||
(IsServer(source_p) && (IsServer(source_p) &&
!HasSentEob(source_p))) !HasSentEob(source_p))) {
{ if(kline_queued == 0) {
if(kline_queued == 0)
{
rb_event_addonce("check_klines", check_klines_event, NULL, rb_event_addonce("check_klines", check_klines_event, NULL,
ConfigFileEntry.kline_delay); ConfigFileEntry.kline_delay);
kline_queued = 1; kline_queued = 1;
} }
} } else
else
check_klines(); check_klines();
} }
break; break;
case CONF_XLINE: case CONF_XLINE:
if (aconf->status & CONF_ILLEGAL) if (aconf->status & CONF_ILLEGAL)
remove_reject_mask(aconf->host, NULL); remove_reject_mask(aconf->host, NULL);
else else {
{
rb_dlinkAddAlloc(aconf, &xline_conf_list); rb_dlinkAddAlloc(aconf, &xline_conf_list);
check_xlines(); check_xlines();
} }
break; break;
case CONF_RESV_CHANNEL: case CONF_RESV_CHANNEL:
if (!(aconf->status & CONF_ILLEGAL)) if (!(aconf->status & CONF_ILLEGAL)) {
{
add_to_resv_hash(aconf->host, aconf); add_to_resv_hash(aconf->host, aconf);
resv_chan_forcepart(aconf->host, aconf->passwd, hold - rb_current_time()); resv_chan_forcepart(aconf->host, aconf->passwd, hold - rb_current_time());
} }

View File

@ -56,29 +56,24 @@ DECLARE_MODULE_AV1(die, NULL, NULL, die_clist, NULL, NULL, "$Revision: 3295 $");
static int static int
mo_die(struct Client *client_p __unused, struct Client *source_p, int parc, const char *parv[]) mo_die(struct Client *client_p __unused, struct Client *source_p, int parc, const char *parv[])
{ {
if(!IsOperDie(source_p)) if(!IsOperDie(source_p)) {
{
sendto_one(source_p, form_str(ERR_NOPRIVS), me.name, source_p->name, "die"); sendto_one(source_p, form_str(ERR_NOPRIVS), me.name, source_p->name, "die");
return 0; return 0;
} }
if(parc < 2 || EmptyString(parv[1])) if(parc < 2 || EmptyString(parv[1])) {
{
sendto_one_notice(source_p, ":Need server name /die %s", me.name); sendto_one_notice(source_p, ":Need server name /die %s", me.name);
return 0; return 0;
} }
if(parc > 2) if(parc > 2) {
{
/* Remote die. Pass it along. */ /* Remote die. Pass it along. */
struct Client *server_p = find_server(NULL, parv[2]); struct Client *server_p = find_server(NULL, parv[2]);
if (!server_p) if (!server_p) {
{
sendto_one_numeric(source_p, ERR_NOSUCHSERVER, form_str(ERR_NOSUCHSERVER), parv[2]); sendto_one_numeric(source_p, ERR_NOSUCHSERVER, form_str(ERR_NOSUCHSERVER), parv[2]);
return 0; return 0;
} }
if (!IsMe(server_p)) if (!IsMe(server_p)) {
{
sendto_one(server_p, ":%s ENCAP %s DIE %s", source_p->name, parv[2], parv[1]); sendto_one(server_p, ":%s ENCAP %s DIE %s", source_p->name, parv[2], parv[1]);
return 0; return 0;
} }
@ -90,8 +85,7 @@ mo_die(struct Client *client_p __unused, struct Client *source_p, int parc, cons
static int static int
me_die(struct Client *client_p __unused, struct Client *source_p, int parc, const char *parv[]) me_die(struct Client *client_p __unused, struct Client *source_p, int parc, const char *parv[])
{ {
if(!find_shared_conf(source_p->username, source_p->host, source_p->servptr->name, SHARED_DIE)) if(!find_shared_conf(source_p->username, source_p->host, source_p->servptr->name, SHARED_DIE)) {
{
sendto_one_notice(source_p, ":*** You do not have an appropriate shared block to " sendto_one_notice(source_p, ":*** You do not have an appropriate shared block to "
"remotely shut down this server."); "remotely shut down this server.");
return 0; return 0;
@ -104,8 +98,7 @@ static int
do_die(struct Client *source_p, const char *servername) do_die(struct Client *source_p, const char *servername)
{ {
/* this makes sure both servernames match otherwise weirdness will occur */ /* this makes sure both servernames match otherwise weirdness will occur */
if(irccmp(servername, me.name)) if(irccmp(servername, me.name)) {
{
sendto_one_notice(source_p, ":Mismatch on /die %s", me.name); sendto_one_notice(source_p, ":Mismatch on /die %s", me.name);
return 0; return 0;
} }

View File

@ -94,16 +94,14 @@ m_error(struct Client *client_p, struct Client *source_p, int parc, const char *
para = (parc > 1 && *parv[1] != '\0') ? parv[1] : "<>"; para = (parc > 1 && *parv[1] != '\0') ? parv[1] : "<>";
if (IsAnyServer(client_p)) if (IsAnyServer(client_p)) {
{
ilog(L_SERVER, "Received ERROR message from %s: %s", ilog(L_SERVER, "Received ERROR message from %s: %s",
log_client_name(source_p, SHOW_IP), para); log_client_name(source_p, SHOW_IP), para);
} }
if(is_safe_error(para)) if(is_safe_error(para))
hideit = 0; hideit = 0;
if(IsAnyServer(client_p)) if(IsAnyServer(client_p)) {
{
if (hideit < 2) if (hideit < 2)
sendto_realops_snomask(SNO_GENERAL, hideit ? L_ADMIN : (is_remote_connect(client_p) ? L_NETWIDE : L_ALL), sendto_realops_snomask(SNO_GENERAL, hideit ? L_ADMIN : (is_remote_connect(client_p) ? L_NETWIDE : L_ALL),
"ERROR :from %s -- %s", "ERROR :from %s -- %s",
@ -135,13 +133,10 @@ ms_error(struct Client *client_p, struct Client *source_p, int parc, const char
if(hideit == 2) if(hideit == 2)
return 0; return 0;
if(client_p == source_p) if(client_p == source_p) {
{
sendto_realops_snomask(SNO_GENERAL, hideit ? L_ADMIN : L_ALL, "ERROR :from %s -- %s", sendto_realops_snomask(SNO_GENERAL, hideit ? L_ADMIN : L_ALL, "ERROR :from %s -- %s",
client_p->name, para); client_p->name, para);
} } else {
else
{
sendto_realops_snomask(SNO_GENERAL, hideit ? L_ADMIN : L_ALL, "ERROR :from %s via %s -- %s", sendto_realops_snomask(SNO_GENERAL, hideit ? L_ADMIN : L_ALL, "ERROR :from %s via %s -- %s",
source_p->name, client_p->name, para); source_p->name, client_p->name, para);
} }

View File

@ -138,8 +138,7 @@ ms_join(struct Client *client_p, struct Client *source_p, int parc, const char *
rb_dlink_node *ptr, *next_ptr; rb_dlink_node *ptr, *next_ptr;
/* special case for join 0 */ /* special case for join 0 */
if((parv[1][0] == '0') && (parv[1][1] == '\0') && parc == 2) if((parv[1][0] == '0') && (parv[1][1] == '\0') && parc == 2) {
{
do_join_0(client_p, source_p); do_join_0(client_p, source_p);
return 0; return 0;
} }
@ -166,8 +165,7 @@ ms_join(struct Client *client_p, struct Client *source_p, int parc, const char *
oldts = chptr->channelts; oldts = chptr->channelts;
#ifdef IGNORE_BOGUS_TS #ifdef IGNORE_BOGUS_TS
if(newts < 800000000) if(newts < 800000000) {
{
sendto_realops_snomask(SNO_DEBUG, L_ALL, sendto_realops_snomask(SNO_DEBUG, L_ALL,
"*** Bogus TS %ld on %s ignored from %s", "*** Bogus TS %ld on %s ignored from %s",
(long) newts, chptr->chname, client_p->name); (long) newts, chptr->chname, client_p->name);
@ -175,8 +173,7 @@ ms_join(struct Client *client_p, struct Client *source_p, int parc, const char *
} }
#else #else
/* making a channel TS0 */ /* making a channel TS0 */
if(!isnew && !newts && oldts) if(!isnew && !newts && oldts) {
{
sendto_channel_local(ALL_MEMBERS, chptr, sendto_channel_local(ALL_MEMBERS, chptr,
":%s NOTICE %s :*** Notice -- TS for %s changed from %ld to 0", ":%s NOTICE %s :*** Notice -- TS for %s changed from %ld to 0",
me.name, chptr->chname, chptr->chname, (long) oldts); me.name, chptr->chname, chptr->chname, (long) oldts);
@ -192,22 +189,18 @@ ms_join(struct Client *client_p, struct Client *source_p, int parc, const char *
chptr->channelts = 0; chptr->channelts = 0;
else if(newts == oldts) else if(newts == oldts)
; ;
else if(newts < oldts) else if(newts < oldts) {
{
keep_our_modes = NO; keep_our_modes = NO;
chptr->channelts = newts; chptr->channelts = newts;
} } else
else
keep_new_modes = NO; keep_new_modes = NO;
/* Lost the TS, other side wins, so remove modes on this side */ /* Lost the TS, other side wins, so remove modes on this side */
if(!keep_our_modes) if(!keep_our_modes) {
{
set_final_mode(&mode, &chptr->mode); set_final_mode(&mode, &chptr->mode);
chptr->mode = mode; chptr->mode = mode;
remove_our_modes(chptr, source_p); remove_our_modes(chptr, source_p);
RB_DLINK_FOREACH_SAFE(ptr, next_ptr, chptr->invites.head) RB_DLINK_FOREACH_SAFE(ptr, next_ptr, chptr->invites.head) {
{
del_invite(chptr, ptr->data); del_invite(chptr, ptr->data);
} }
/* If setting -j, clear join throttle state -- jilles */ /* If setting -j, clear join throttle state -- jilles */
@ -235,12 +228,10 @@ ms_join(struct Client *client_p, struct Client *source_p, int parc, const char *
set_channel_mlock(client_p, source_p, chptr, NULL, FALSE); set_channel_mlock(client_p, source_p, chptr, NULL, FALSE);
} }
if(!IsMember(source_p, chptr)) if(!IsMember(source_p, chptr)) {
{
add_user_to_channel(chptr, source_p, CHFL_PEON); add_user_to_channel(chptr, source_p, CHFL_PEON);
if (chptr->mode.join_num && if (chptr->mode.join_num &&
rb_current_time() - chptr->join_delta >= chptr->mode.join_time) rb_current_time() - chptr->join_delta >= chptr->mode.join_time) {
{
chptr->join_count = 0; chptr->join_count = 0;
chptr->join_delta = rb_current_time(); chptr->join_delta = rb_current_time();
} }
@ -309,10 +300,8 @@ ms_sjoin(struct Client *client_p, struct Client *source_p, int parc, const char
newts = atol(parv[1]); newts = atol(parv[1]);
s = parv[3]; s = parv[3];
while (*s) while (*s) {
{ switch (*(s++)) {
switch (*(s++))
{
case 'f': case 'f':
rb_strlcpy(mode.forward, parv[4 + args], sizeof(mode.forward)); rb_strlcpy(mode.forward, parv[4 + args], sizeof(mode.forward));
args++; args++;
@ -340,22 +329,19 @@ ms_sjoin(struct Client *client_p, struct Client *source_p, int parc, const char
return 0; return 0;
break; break;
default: default:
if(chmode_flags[(int) *s] != 0) if(chmode_flags[(int) *s] != 0) {
{
mode.mode |= chmode_flags[(int) *s]; mode.mode |= chmode_flags[(int) *s];
} }
} }
} }
if(parv[args + 4]) if(parv[args + 4]) {
{
s = parv[args + 4]; s = parv[args + 4];
/* remove any leading spaces */ /* remove any leading spaces */
while (*s == ' ') while (*s == ' ')
s++; s++;
} } else
else
s = ""; s = "";
if((chptr = get_or_create_channel(source_p, parv[2], &isnew)) == NULL) if((chptr = get_or_create_channel(source_p, parv[2], &isnew)) == NULL)
@ -366,8 +352,7 @@ ms_sjoin(struct Client *client_p, struct Client *source_p, int parc, const char
oldmode = &chptr->mode; oldmode = &chptr->mode;
#ifdef IGNORE_BOGUS_TS #ifdef IGNORE_BOGUS_TS
if(newts < 800000000) if(newts < 800000000) {
{
sendto_realops_snomask(SNO_DEBUG, L_ALL, sendto_realops_snomask(SNO_DEBUG, L_ALL,
"*** Bogus TS %ld on %s ignored from %s", "*** Bogus TS %ld on %s ignored from %s",
(long) newts, chptr->chname, client_p->name); (long) newts, chptr->chname, client_p->name);
@ -375,8 +360,7 @@ ms_sjoin(struct Client *client_p, struct Client *source_p, int parc, const char
newts = (oldts == 0) ? oldts : 800000000; newts = (oldts == 0) ? oldts : 800000000;
} }
#else #else
if(!isnew && !newts && oldts) if(!isnew && !newts && oldts) {
{
sendto_channel_local(ALL_MEMBERS, chptr, sendto_channel_local(ALL_MEMBERS, chptr,
":%s NOTICE %s :*** Notice -- TS for %s " ":%s NOTICE %s :*** Notice -- TS for %s "
"changed from %ld to 0", "changed from %ld to 0",
@ -394,8 +378,7 @@ ms_sjoin(struct Client *client_p, struct Client *source_p, int parc, const char
chptr->channelts = 0; chptr->channelts = 0;
else if(newts == oldts) else if(newts == oldts)
; ;
else if(newts < oldts) else if(newts < oldts) {
{
/* If configured, kick people trying to join +i/+k /* If configured, kick people trying to join +i/+k
* channels by recreating them on split servers. * channels by recreating them on split servers.
* If the source has sent EOB, assume this is some * If the source has sent EOB, assume this is some
@ -407,14 +390,12 @@ ms_sjoin(struct Client *client_p, struct Client *source_p, int parc, const char
if (ConfigChannel.kick_on_split_riding && if (ConfigChannel.kick_on_split_riding &&
((!HasSentEob(source_p) && ((!HasSentEob(source_p) &&
mode.mode & MODE_INVITEONLY) || mode.mode & 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;
struct Client *who; struct Client *who;
int l = rb_dlink_list_length(&chptr->members); int l = rb_dlink_list_length(&chptr->members);
RB_DLINK_FOREACH_SAFE(ptr, next_ptr, chptr->locmembers.head) RB_DLINK_FOREACH_SAFE(ptr, next_ptr, chptr->locmembers.head) {
{
msptr = ptr->data; msptr = ptr->data;
who = msptr->client_p; who = msptr->client_p;
sendto_one(who, ":%s KICK %s %s :Net Rider", sendto_one(who, ":%s KICK %s %s :Net Rider",
@ -428,8 +409,7 @@ ms_sjoin(struct Client *client_p, struct Client *source_p, int parc, const char
if (--l == 0) if (--l == 0)
break; break;
} }
if (l == 0) if (l == 0) {
{
/* Channel was emptied, create a new one */ /* Channel was emptied, create a new one */
if((chptr = get_or_create_channel(source_p, parv[2], &isnew)) == NULL) if((chptr = get_or_create_channel(source_p, parv[2], &isnew)) == NULL)
return 0; /* oops! */ return 0; /* oops! */
@ -439,14 +419,12 @@ ms_sjoin(struct Client *client_p, struct Client *source_p, int parc, const char
} }
keep_our_modes = NO; keep_our_modes = NO;
chptr->channelts = newts; chptr->channelts = newts;
} } else
else
keep_new_modes = NO; keep_new_modes = NO;
if(!keep_new_modes) if(!keep_new_modes)
mode = *oldmode; mode = *oldmode;
else if(keep_our_modes) else if(keep_our_modes) {
{
mode.mode |= oldmode->mode; mode.mode |= oldmode->mode;
if(oldmode->limit > mode.limit) if(oldmode->limit > mode.limit)
mode.limit = oldmode->limit; mode.limit = oldmode->limit;
@ -454,16 +432,13 @@ ms_sjoin(struct Client *client_p, struct Client *source_p, int parc, const char
strcpy(mode.key, oldmode->key); strcpy(mode.key, oldmode->key);
if(oldmode->join_num > mode.join_num || if(oldmode->join_num > mode.join_num ||
(oldmode->join_num == mode.join_num && (oldmode->join_num == mode.join_num &&
oldmode->join_time > mode.join_time)) oldmode->join_time > mode.join_time)) {
{
mode.join_num = oldmode->join_num; mode.join_num = oldmode->join_num;
mode.join_time = oldmode->join_time; mode.join_time = oldmode->join_time;
} }
if(irccmp(mode.forward, oldmode->forward) < 0) if(irccmp(mode.forward, oldmode->forward) < 0)
strcpy(mode.forward, oldmode->forward); strcpy(mode.forward, oldmode->forward);
} } else {
else
{
/* If setting -j, clear join throttle state -- jilles */ /* If setting -j, clear join throttle state -- jilles */
if (!mode.join_num) if (!mode.join_num)
chptr->join_count = chptr->join_delta = 0; chptr->join_count = chptr->join_delta = 0;
@ -473,11 +448,9 @@ ms_sjoin(struct Client *client_p, struct Client *source_p, int parc, const char
chptr->mode = mode; chptr->mode = mode;
/* Lost the TS, other side wins, so remove modes on this side */ /* Lost the TS, other side wins, so remove modes on this side */
if(!keep_our_modes) if(!keep_our_modes) {
{
remove_our_modes(chptr, fakesource_p); remove_our_modes(chptr, fakesource_p);
RB_DLINK_FOREACH_SAFE(ptr, next_ptr, chptr->invites.head) RB_DLINK_FOREACH_SAFE(ptr, next_ptr, chptr->invites.head) {
{
del_invite(chptr, ptr->data); del_invite(chptr, ptr->data);
} }
@ -535,41 +508,29 @@ ms_sjoin(struct Client *client_p, struct Client *source_p, int parc, const char
* first space to \0, so s is just the first nick, and point p to the * first space to \0, so s is just the first nick, and point p to the
* second nick * second nick
*/ */
if((p = strchr(s, ' ')) != NULL) if((p = strchr(s, ' ')) != NULL) {
{
*p++ = '\0'; *p++ = '\0';
} }
*mbuf++ = '+'; *mbuf++ = '+';
while (s) while (s) {
{
fl = 0; fl = 0;
for (i = 0; i < 4; i++) for (i = 0; i < 4; i++) {
{ if(*s == '~') {
if(*s == '~')
{
fl |= CHFL_OWNER; fl |= CHFL_OWNER;
s++; s++;
} } else if(*s == '!') {
else if(*s == '!')
{
fl |= CHFL_ADMIN; fl |= CHFL_ADMIN;
s++; s++;
} } else if(*s == '@') {
else if(*s == '@')
{
fl |= CHFL_CHANOP; fl |= CHFL_CHANOP;
s++; s++;
} } else if(*s == '%') {
else if(*s == '%')
{
fl |= CHFL_HALFOP; fl |= CHFL_HALFOP;
s++; s++;
} } else if(*s == '+') {
else if(*s == '+')
{
fl |= CHFL_VOICE; fl |= CHFL_VOICE;
s++; s++;
} }
@ -583,42 +544,34 @@ ms_sjoin(struct Client *client_p, struct Client *source_p, int parc, const char
/* we assume for these we can fit at least one nick/uid in.. */ /* we assume for these we can fit at least one nick/uid in.. */
/* check we can fit another status+nick+space into a buffer */ /* check we can fit another status+nick+space into a buffer */
if((mlen_uid + len_uid + IDLEN + 3) > (BUFSIZE - 3)) if((mlen_uid + len_uid + IDLEN + 3) > (BUFSIZE - 3)) {
{
*(ptr_uid - 1) = '\0'; *(ptr_uid - 1) = '\0';
sendto_server(client_p->from, NULL, CAP_TS6, NOCAPS, "%s", buf_uid); sendto_server(client_p->from, NULL, CAP_TS6, NOCAPS, "%s", buf_uid);
ptr_uid = buf_uid + mlen_uid; ptr_uid = buf_uid + mlen_uid;
len_uid = 0; len_uid = 0;
} }
if(keep_new_modes) if(keep_new_modes) {
{ if(fl & CHFL_OWNER) {
if(fl & CHFL_OWNER)
{
*ptr_uid++ = '~'; *ptr_uid++ = '~';
len_nick++; len_nick++;
len_uid++; len_uid++;
} } else if(fl & CHFL_ADMIN) {
else if(fl & CHFL_ADMIN)
{
*ptr_uid++ = '!'; *ptr_uid++ = '!';
len_nick++; len_nick++;
len_uid++; len_uid++;
} }
if(fl & CHFL_CHANOP) if(fl & CHFL_CHANOP) {
{
*ptr_uid++ = '@'; *ptr_uid++ = '@';
len_nick++; len_nick++;
len_uid++; len_uid++;
} }
if(fl & CHFL_HALFOP) if(fl & CHFL_HALFOP) {
{
*ptr_uid++ = '%'; *ptr_uid++ = '%';
len_nick++; len_nick++;
len_uid++; len_uid++;
} }
if(fl & CHFL_VOICE) if(fl & CHFL_VOICE) {
{
*ptr_uid++ = '+'; *ptr_uid++ = '+';
len_nick++; len_nick++;
len_uid++; len_uid++;
@ -633,8 +586,7 @@ ms_sjoin(struct Client *client_p, struct Client *source_p, int parc, const char
if(!keep_new_modes) if(!keep_new_modes)
fl = 0; fl = 0;
if(!IsMember(target_p, chptr)) if(!IsMember(target_p, chptr)) {
{
add_user_to_channel(chptr, target_p, fl); add_user_to_channel(chptr, target_p, fl);
sendto_channel_local(ALL_MEMBERS, chptr, ":%s!%s@%s JOIN :%s", sendto_channel_local(ALL_MEMBERS, chptr, ":%s!%s@%s JOIN :%s",
target_p->name, target_p->name,
@ -645,18 +597,15 @@ ms_sjoin(struct Client *client_p, struct Client *source_p, int parc, const char
/* If anyone can think of a way to do this that doesn't make babies cry /* If anyone can think of a way to do this that doesn't make babies cry
* I would love to hear it - Taros */ * I would love to hear it - Taros */
if(fl & CHFL_OWNER) if(fl & CHFL_OWNER) {
{
*mbuf++ = 'y'; *mbuf++ = 'y';
para[pargs++] = target_p->name; para[pargs++] = target_p->name;
if(fl & CHFL_ADMIN) if(fl & CHFL_ADMIN) {
{
/* its possible the +y has filled up MAXMODEPARAMS, if so, start /* its possible the +y has filled up MAXMODEPARAMS, if so, start
* a new buffer * a new buffer
*/ */
if(pargs >= MAXMODEPARAMS) if(pargs >= MAXMODEPARAMS) {
{
*mbuf = '\0'; *mbuf = '\0';
sendto_channel_local(ALL_MEMBERS, chptr, sendto_channel_local(ALL_MEMBERS, chptr,
":%s MODE %s %s %s %s %s %s", ":%s MODE %s %s %s %s %s %s",
@ -672,13 +621,11 @@ ms_sjoin(struct Client *client_p, struct Client *source_p, int parc, const char
*mbuf++ = 'a'; *mbuf++ = 'a';
para[pargs++] = target_p->name; para[pargs++] = target_p->name;
} }
if(fl & CHFL_CHANOP) if(fl & CHFL_CHANOP) {
{
/* its possible the +y has filled up MAXMODEPARAMS, if so, start /* its possible the +y has filled up MAXMODEPARAMS, if so, start
* a new buffer * a new buffer
*/ */
if(pargs >= MAXMODEPARAMS) if(pargs >= MAXMODEPARAMS) {
{
*mbuf = '\0'; *mbuf = '\0';
sendto_channel_local(ALL_MEMBERS, chptr, sendto_channel_local(ALL_MEMBERS, chptr,
":%s MODE %s %s %s %s %s %s", ":%s MODE %s %s %s %s %s %s",
@ -694,13 +641,11 @@ ms_sjoin(struct Client *client_p, struct Client *source_p, int parc, const char
*mbuf++ = 'o'; *mbuf++ = 'o';
para[pargs++] = target_p->name; para[pargs++] = target_p->name;
} }
if(fl & CHFL_HALFOP) if(fl & CHFL_HALFOP) {
{
/* its possible the +y has filled up MAXMODEPARAMS, if so, start /* its possible the +y has filled up MAXMODEPARAMS, if so, start
* a new buffer * a new buffer
*/ */
if(pargs >= MAXMODEPARAMS) if(pargs >= MAXMODEPARAMS) {
{
*mbuf = '\0'; *mbuf = '\0';
sendto_channel_local(ALL_MEMBERS, chptr, sendto_channel_local(ALL_MEMBERS, chptr,
":%s MODE %s %s %s %s %s %s", ":%s MODE %s %s %s %s %s %s",
@ -716,13 +661,11 @@ ms_sjoin(struct Client *client_p, struct Client *source_p, int parc, const char
*mbuf++ = 'h'; *mbuf++ = 'h';
para[pargs++] = target_p->name; para[pargs++] = target_p->name;
} }
if(fl & CHFL_VOICE) if(fl & CHFL_VOICE) {
{
/* its possible the +y has filled up MAXMODEPARAMS, if so, start /* its possible the +y has filled up MAXMODEPARAMS, if so, start
* a new buffer * a new buffer
*/ */
if(pargs >= MAXMODEPARAMS) if(pargs >= MAXMODEPARAMS) {
{
*mbuf = '\0'; *mbuf = '\0';
sendto_channel_local(ALL_MEMBERS, chptr, sendto_channel_local(ALL_MEMBERS, chptr,
":%s MODE %s %s %s %s %s %s", ":%s MODE %s %s %s %s %s %s",
@ -738,19 +681,15 @@ ms_sjoin(struct Client *client_p, struct Client *source_p, int parc, const char
*mbuf++ = 'v'; *mbuf++ = 'v';
para[pargs++] = target_p->name; para[pargs++] = target_p->name;
} }
} } else if(fl & CHFL_ADMIN) {
else if(fl & CHFL_ADMIN)
{
*mbuf++ = 'a'; *mbuf++ = 'a';
para[pargs++] = target_p->name; para[pargs++] = target_p->name;
if(fl & CHFL_CHANOP) if(fl & CHFL_CHANOP) {
{
/* its possible the +a has filled up MAXMODEPARAMS, if so, start /* its possible the +a has filled up MAXMODEPARAMS, if so, start
* a new buffer * a new buffer
*/ */
if(pargs >= MAXMODEPARAMS) if(pargs >= MAXMODEPARAMS) {
{
*mbuf = '\0'; *mbuf = '\0';
sendto_channel_local(ALL_MEMBERS, chptr, sendto_channel_local(ALL_MEMBERS, chptr,
":%s MODE %s %s %s %s %s %s", ":%s MODE %s %s %s %s %s %s",
@ -766,13 +705,11 @@ ms_sjoin(struct Client *client_p, struct Client *source_p, int parc, const char
*mbuf++ = 'o'; *mbuf++ = 'o';
para[pargs++] = target_p->name; para[pargs++] = target_p->name;
} }
if(fl & CHFL_HALFOP) if(fl & CHFL_HALFOP) {
{
/* its possible the +a has filled up MAXMODEPARAMS, if so, start /* its possible the +a has filled up MAXMODEPARAMS, if so, start
* a new buffer * a new buffer
*/ */
if(pargs >= MAXMODEPARAMS) if(pargs >= MAXMODEPARAMS) {
{
*mbuf = '\0'; *mbuf = '\0';
sendto_channel_local(ALL_MEMBERS, chptr, sendto_channel_local(ALL_MEMBERS, chptr,
":%s MODE %s %s %s %s %s %s", ":%s MODE %s %s %s %s %s %s",
@ -788,13 +725,11 @@ ms_sjoin(struct Client *client_p, struct Client *source_p, int parc, const char
*mbuf++ = 'h'; *mbuf++ = 'h';
para[pargs++] = target_p->name; para[pargs++] = target_p->name;
} }
if(fl & CHFL_VOICE) if(fl & CHFL_VOICE) {
{
/* its possible the +a has filled up MAXMODEPARAMS, if so, start /* its possible the +a has filled up MAXMODEPARAMS, if so, start
* a new buffer * a new buffer
*/ */
if(pargs >= MAXMODEPARAMS) if(pargs >= MAXMODEPARAMS) {
{
*mbuf = '\0'; *mbuf = '\0';
sendto_channel_local(ALL_MEMBERS, chptr, sendto_channel_local(ALL_MEMBERS, chptr,
":%s MODE %s %s %s %s %s %s", ":%s MODE %s %s %s %s %s %s",
@ -810,19 +745,15 @@ ms_sjoin(struct Client *client_p, struct Client *source_p, int parc, const char
*mbuf++ = 'v'; *mbuf++ = 'v';
para[pargs++] = target_p->name; para[pargs++] = target_p->name;
} }
} } else if(fl & CHFL_CHANOP) {
else if(fl & CHFL_CHANOP)
{
*mbuf++ = 'o'; *mbuf++ = 'o';
para[pargs++] = target_p->name; para[pargs++] = target_p->name;
if(fl & CHFL_HALFOP) if(fl & CHFL_HALFOP) {
{
/* its possible the +o has filled up MAXMODEPARAMS, if so, start /* its possible the +o has filled up MAXMODEPARAMS, if so, start
* a new buffer * a new buffer
*/ */
if(pargs >= MAXMODEPARAMS) if(pargs >= MAXMODEPARAMS) {
{
*mbuf = '\0'; *mbuf = '\0';
sendto_channel_local(ALL_MEMBERS, chptr, sendto_channel_local(ALL_MEMBERS, chptr,
":%s MODE %s %s %s %s %s %s", ":%s MODE %s %s %s %s %s %s",
@ -838,13 +769,11 @@ ms_sjoin(struct Client *client_p, struct Client *source_p, int parc, const char
*mbuf++ = 'h'; *mbuf++ = 'h';
para[pargs++] = target_p->name; para[pargs++] = target_p->name;
} }
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 MAXMODEPARAMS, if so, start
* a new buffer * a new buffer
*/ */
if(pargs >= MAXMODEPARAMS) if(pargs >= MAXMODEPARAMS) {
{
*mbuf = '\0'; *mbuf = '\0';
sendto_channel_local(ALL_MEMBERS, chptr, sendto_channel_local(ALL_MEMBERS, chptr,
":%s MODE %s %s %s %s %s %s", ":%s MODE %s %s %s %s %s %s",
@ -860,19 +789,15 @@ ms_sjoin(struct Client *client_p, struct Client *source_p, int parc, const char
*mbuf++ = 'v'; *mbuf++ = 'v';
para[pargs++] = target_p->name; para[pargs++] = target_p->name;
} }
} } else if(fl & CHFL_HALFOP) {
else if(fl & CHFL_HALFOP)
{
*mbuf++ = 'h'; *mbuf++ = 'h';
para[pargs++] = target_p->name; para[pargs++] = target_p->name;
if(fl & CHFL_VOICE) if(fl & CHFL_VOICE) {
{
/* its possible the +h has filled up MAXMODEPARAMS, if so, start /* its possible the +h has filled up MAXMODEPARAMS, if so, start
* a new buffer * a new buffer
*/ */
if(pargs >= MAXMODEPARAMS) if(pargs >= MAXMODEPARAMS) {
{
*mbuf = '\0'; *mbuf = '\0';
sendto_channel_local(ALL_MEMBERS, chptr, sendto_channel_local(ALL_MEMBERS, chptr,
":%s MODE %s %s %s %s %s %s", ":%s MODE %s %s %s %s %s %s",
@ -888,15 +813,12 @@ ms_sjoin(struct Client *client_p, struct Client *source_p, int parc, const char
*mbuf++ = 'v'; *mbuf++ = 'v';
para[pargs++] = target_p->name; para[pargs++] = target_p->name;
} }
} } else if(fl & CHFL_VOICE) {
else if(fl & CHFL_VOICE)
{
*mbuf++ = 'v'; *mbuf++ = 'v';
para[pargs++] = target_p->name; para[pargs++] = target_p->name;
} }
if(pargs >= MAXMODEPARAMS) if(pargs >= MAXMODEPARAMS) {
{
*mbuf = '\0'; *mbuf = '\0';
sendto_channel_local(ALL_MEMBERS, chptr, sendto_channel_local(ALL_MEMBERS, chptr,
":%s MODE %s %s %s %s %s %s", ":%s MODE %s %s %s %s %s %s",
@ -909,7 +831,7 @@ ms_sjoin(struct Client *client_p, struct Client *source_p, int parc, const char
pargs = 0; pargs = 0;
} }
nextnick: nextnick:
/* p points to the next nick */ /* p points to the next nick */
s = p; s = p;
@ -924,15 +846,13 @@ ms_sjoin(struct Client *client_p, struct Client *source_p, int parc, const char
* we cant check it for spaces.. if there are no spaces, then when * we cant check it for spaces.. if there are no spaces, then when
* we next get here, s will be NULL * we next get here, s will be NULL
*/ */
if(s && ((p = strchr(s, ' ')) != NULL)) if(s && ((p = strchr(s, ' ')) != NULL)) {
{
*p++ = '\0'; *p++ = '\0';
} }
} }
*mbuf = '\0'; *mbuf = '\0';
if(pargs) if(pargs) {
{
sendto_channel_local(ALL_MEMBERS, chptr, sendto_channel_local(ALL_MEMBERS, chptr,
":%s MODE %s %s %s %s %s %s", ":%s MODE %s %s %s %s %s %s",
fakesource_p->name, chptr->chname, modebuf, fakesource_p->name, chptr->chname, modebuf,
@ -940,16 +860,14 @@ ms_sjoin(struct Client *client_p, struct Client *source_p, int parc, const char
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 & MODE_PERMANENT) && isnew) {
{
destroy_channel(chptr); destroy_channel(chptr);
return 0; return 0;
} }
/* Keep the colon if we're sending an SJOIN without nicks -- jilles */ /* Keep the colon if we're sending an SJOIN without nicks -- jilles */
if (joins) if (joins) {
{
*(ptr_uid - 1) = '\0'; *(ptr_uid - 1) = '\0';
} }
@ -968,23 +886,16 @@ set_final_mode(struct Mode *mode, struct Mode *oldmode)
int i; int i;
/* 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 & chmode_flags[i]) && !(oldmode->mode & chmode_flags[i])) if (chmode_table[i].set_func == chm_hidden) {
{ if(odir != MODE_ADD) {
if (chmode_table[i].set_func == chm_hidden)
{
if(odir != MODE_ADD)
{
*ombuf++ = '+'; *ombuf++ = '+';
odir = MODE_ADD; odir = MODE_ADD;
} }
*ombuf++ = i; *ombuf++ = i;
} } else {
else if(dir != MODE_ADD) {
{
if(dir != MODE_ADD)
{
*mbuf++ = '+'; *mbuf++ = '+';
dir = MODE_ADD; dir = MODE_ADD;
} }
@ -995,23 +906,16 @@ 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 & chmode_flags[i]) && !(mode->mode & chmode_flags[i])) if(chmode_table[i].set_func == chm_hidden) {
{ if(odir != MODE_DEL) {
if(chmode_table[i].set_func == chm_hidden)
{
if(odir != MODE_DEL)
{
*ombuf++ = '-'; *ombuf++ = '-';
odir = MODE_DEL; odir = MODE_DEL;
} }
*ombuf++ = i; *ombuf++ = i;
} } else {
else if(dir != MODE_DEL) {
{
if(dir != MODE_DEL)
{
*mbuf++ = '-'; *mbuf++ = '-';
dir = MODE_DEL; dir = MODE_DEL;
} }
@ -1020,19 +924,15 @@ set_final_mode(struct Mode *mode, struct Mode *oldmode)
} }
} }
if(oldmode->limit && !mode->limit) if(oldmode->limit && !mode->limit) {
{ if(dir != MODE_DEL) {
if(dir != MODE_DEL)
{
*mbuf++ = '-'; *mbuf++ = '-';
dir = MODE_DEL; dir = MODE_DEL;
} }
*mbuf++ = 'l'; *mbuf++ = 'l';
} }
if(oldmode->key[0] && !mode->key[0]) if(oldmode->key[0] && !mode->key[0]) {
{ if(dir != MODE_DEL) {
if(dir != MODE_DEL)
{
*mbuf++ = '-'; *mbuf++ = '-';
dir = MODE_DEL; dir = MODE_DEL;
} }
@ -1040,28 +940,22 @@ set_final_mode(struct Mode *mode, struct Mode *oldmode)
len = rb_sprintf(pbuf, "%s ", oldmode->key); len = rb_sprintf(pbuf, "%s ", oldmode->key);
pbuf += len; pbuf += len;
} }
if(oldmode->join_num && !mode->join_num) if(oldmode->join_num && !mode->join_num) {
{ if(dir != MODE_DEL) {
if(dir != MODE_DEL)
{
*mbuf++ = '-'; *mbuf++ = '-';
dir = MODE_DEL; dir = MODE_DEL;
} }
*mbuf++ = 'j'; *mbuf++ = 'j';
} }
if(oldmode->forward[0] && !mode->forward[0]) if(oldmode->forward[0] && !mode->forward[0]) {
{ if(dir != MODE_DEL) {
if(dir != MODE_DEL)
{
*mbuf++ = '-'; *mbuf++ = '-';
dir = MODE_DEL; dir = MODE_DEL;
} }
*mbuf++ = 'f'; *mbuf++ = 'f';
} }
if(mode->limit && oldmode->limit != mode->limit) if(mode->limit && oldmode->limit != mode->limit) {
{ if(dir != MODE_ADD) {
if(dir != MODE_ADD)
{
*mbuf++ = '+'; *mbuf++ = '+';
dir = MODE_ADD; dir = MODE_ADD;
} }
@ -1069,10 +963,8 @@ set_final_mode(struct Mode *mode, struct Mode *oldmode)
len = rb_sprintf(pbuf, "%d ", mode->limit); len = rb_sprintf(pbuf, "%d ", mode->limit);
pbuf += len; pbuf += len;
} }
if(mode->key[0] && strcmp(oldmode->key, mode->key)) if(mode->key[0] && strcmp(oldmode->key, mode->key)) {
{ if(dir != MODE_ADD) {
if(dir != MODE_ADD)
{
*mbuf++ = '+'; *mbuf++ = '+';
dir = MODE_ADD; dir = MODE_ADD;
} }
@ -1080,10 +972,8 @@ set_final_mode(struct Mode *mode, struct Mode *oldmode)
len = rb_sprintf(pbuf, "%s ", mode->key); len = rb_sprintf(pbuf, "%s ", mode->key);
pbuf += len; pbuf += len;
} }
if(mode->join_num && (oldmode->join_num != mode->join_num || oldmode->join_time != mode->join_time)) if(mode->join_num && (oldmode->join_num != mode->join_num || oldmode->join_time != mode->join_time)) {
{ if(dir != MODE_ADD) {
if(dir != MODE_ADD)
{
*mbuf++ = '+'; *mbuf++ = '+';
dir = MODE_ADD; dir = MODE_ADD;
} }
@ -1091,10 +981,8 @@ set_final_mode(struct Mode *mode, struct Mode *oldmode)
len = rb_sprintf(pbuf, "%d:%d ", mode->join_num, mode->join_time); len = rb_sprintf(pbuf, "%d:%d ", mode->join_num, mode->join_time);
pbuf += len; pbuf += len;
} }
if(mode->forward[0] && strcmp(oldmode->forward, mode->forward) && ConfigChannel.use_forward) if(mode->forward[0] && strcmp(oldmode->forward, mode->forward) && ConfigChannel.use_forward) {
{ if(dir != MODE_ADD) {
if(dir != MODE_ADD)
{
*mbuf++ = '+'; *mbuf++ = '+';
dir = MODE_ADD; dir = MODE_ADD;
} }
@ -1128,24 +1016,20 @@ remove_our_modes(struct Channel *chptr, struct Client *source_p)
for(i = 0; i < MAXMODEPARAMS; i++) for(i = 0; i < MAXMODEPARAMS; i++)
lpara[i] = NULL; lpara[i] = NULL;
RB_DLINK_FOREACH(ptr, chptr->members.head) RB_DLINK_FOREACH(ptr, chptr->members.head) {
{
msptr = ptr->data; msptr = ptr->data;
/* If anyone can think of a way to do this that doesn't make babies cry /* If anyone can think of a way to do this that doesn't make babies cry
* I would love to hear it - Taros */ * I would love to hear it - Taros */
if(is_owner(msptr)) if(is_owner(msptr)) {
{
msptr->flags &= ~CHFL_ADMIN; msptr->flags &= ~CHFL_ADMIN;
lpara[count++] = msptr->client_p->name; lpara[count++] = msptr->client_p->name;
*mbuf++ = 'y'; *mbuf++ = 'y';
/* Make sure it fits if +h, +o, or +v are involved */ /* Make sure it fits if +h, +o, or +v are involved */
if(is_admin(msptr)) if(is_admin(msptr)) {
{ if(count >= MAXMODEPARAMS) {
if(count >= MAXMODEPARAMS)
{
*mbuf = '\0'; *mbuf = '\0';
sendto_channel_local(ALL_MEMBERS, chptr, sendto_channel_local(ALL_MEMBERS, chptr,
":%s MODE %s %s %s %s %s %s", ":%s MODE %s %s %s %s %s %s",
@ -1166,10 +1050,8 @@ remove_our_modes(struct Channel *chptr, struct Client *source_p)
lpara[count++] = msptr->client_p->name; lpara[count++] = msptr->client_p->name;
*mbuf++ = 'a'; *mbuf++ = 'a';
} }
if(is_chanop(msptr)) if(is_chanop(msptr)) {
{ if(count >= MAXMODEPARAMS) {
if(count >= MAXMODEPARAMS)
{
*mbuf = '\0'; *mbuf = '\0';
sendto_channel_local(ALL_MEMBERS, chptr, sendto_channel_local(ALL_MEMBERS, chptr,
":%s MODE %s %s %s %s %s %s", ":%s MODE %s %s %s %s %s %s",
@ -1190,10 +1072,8 @@ remove_our_modes(struct Channel *chptr, struct Client *source_p)
lpara[count++] = msptr->client_p->name; lpara[count++] = msptr->client_p->name;
*mbuf++ = 'o'; *mbuf++ = 'o';
} }
if(is_halfop(msptr)) if(is_halfop(msptr)) {
{ if(count >= MAXMODEPARAMS) {
if(count >= MAXMODEPARAMS)
{
*mbuf = '\0'; *mbuf = '\0';
sendto_channel_local(ALL_MEMBERS, chptr, sendto_channel_local(ALL_MEMBERS, chptr,
":%s MODE %s %s %s %s %s %s", ":%s MODE %s %s %s %s %s %s",
@ -1213,10 +1093,8 @@ remove_our_modes(struct Channel *chptr, struct Client *source_p)
lpara[count++] = msptr->client_p->name; lpara[count++] = msptr->client_p->name;
*mbuf++ = 'h'; *mbuf++ = 'h';
} }
if(is_voiced(msptr)) if(is_voiced(msptr)) {
{ if(count >= MAXMODEPARAMS) {
if(count >= MAXMODEPARAMS)
{
*mbuf = '\0'; *mbuf = '\0';
sendto_channel_local(ALL_MEMBERS, chptr, sendto_channel_local(ALL_MEMBERS, chptr,
":%s MODE %s %s %s %s %s %s", ":%s MODE %s %s %s %s %s %s",
@ -1236,18 +1114,14 @@ remove_our_modes(struct Channel *chptr, struct Client *source_p)
msptr->flags &= ~CHFL_VOICE; msptr->flags &= ~CHFL_VOICE;
lpara[count++] = msptr->client_p->name; lpara[count++] = msptr->client_p->name;
*mbuf++ = 'v'; *mbuf++ = 'v';
} } else if(is_admin(msptr)) {
else if(is_admin(msptr))
{
msptr->flags &= ~CHFL_ADMIN; msptr->flags &= ~CHFL_ADMIN;
lpara[count++] = msptr->client_p->name; lpara[count++] = msptr->client_p->name;
*mbuf++ = 'a'; *mbuf++ = 'a';
/* Make sure it fits if +h, +o, or +v are involved */ /* Make sure it fits if +h, +o, or +v are involved */
if(is_chanop(msptr)) if(is_chanop(msptr)) {
{ if(count >= MAXMODEPARAMS) {
if(count >= MAXMODEPARAMS)
{
*mbuf = '\0'; *mbuf = '\0';
sendto_channel_local(ALL_MEMBERS, chptr, sendto_channel_local(ALL_MEMBERS, chptr,
":%s MODE %s %s %s %s %s %s", ":%s MODE %s %s %s %s %s %s",
@ -1268,10 +1142,8 @@ remove_our_modes(struct Channel *chptr, struct Client *source_p)
lpara[count++] = msptr->client_p->name; lpara[count++] = msptr->client_p->name;
*mbuf++ = 'o'; *mbuf++ = 'o';
} }
if(is_halfop(msptr)) if(is_halfop(msptr)) {
{ if(count >= MAXMODEPARAMS) {
if(count >= MAXMODEPARAMS)
{
*mbuf = '\0'; *mbuf = '\0';
sendto_channel_local(ALL_MEMBERS, chptr, sendto_channel_local(ALL_MEMBERS, chptr,
":%s MODE %s %s %s %s %s %s", ":%s MODE %s %s %s %s %s %s",
@ -1292,10 +1164,8 @@ remove_our_modes(struct Channel *chptr, struct Client *source_p)
lpara[count++] = msptr->client_p->name; lpara[count++] = msptr->client_p->name;
*mbuf++ = 'h'; *mbuf++ = 'h';
} }
if(is_voiced(msptr)) if(is_voiced(msptr)) {
{ if(count >= MAXMODEPARAMS) {
if(count >= MAXMODEPARAMS)
{
*mbuf = '\0'; *mbuf = '\0';
sendto_channel_local(ALL_MEMBERS, chptr, sendto_channel_local(ALL_MEMBERS, chptr,
":%s MODE %s %s %s %s %s %s", ":%s MODE %s %s %s %s %s %s",
@ -1317,18 +1187,14 @@ remove_our_modes(struct Channel *chptr, struct Client *source_p)
*mbuf++ = 'v'; *mbuf++ = 'v';
} }
} }
} } else if(is_admin(msptr)) {
else if(is_admin(msptr))
{
msptr->flags &= ~CHFL_ADMIN; msptr->flags &= ~CHFL_ADMIN;
lpara[count++] = msptr->client_p->name; lpara[count++] = msptr->client_p->name;
*mbuf++ = 'a'; *mbuf++ = 'a';
/* Make sure it fits if +h, +o, or +v are involved */ /* Make sure it fits if +h, +o, or +v are involved */
if(is_chanop(msptr)) if(is_chanop(msptr)) {
{ if(count >= MAXMODEPARAMS) {
if(count >= MAXMODEPARAMS)
{
*mbuf = '\0'; *mbuf = '\0';
sendto_channel_local(ALL_MEMBERS, chptr, sendto_channel_local(ALL_MEMBERS, chptr,
":%s MODE %s %s %s %s %s %s", ":%s MODE %s %s %s %s %s %s",
@ -1349,10 +1215,8 @@ remove_our_modes(struct Channel *chptr, struct Client *source_p)
lpara[count++] = msptr->client_p->name; lpara[count++] = msptr->client_p->name;
*mbuf++ = 'o'; *mbuf++ = 'o';
} }
if(is_halfop(msptr)) if(is_halfop(msptr)) {
{ if(count >= MAXMODEPARAMS) {
if(count >= MAXMODEPARAMS)
{
*mbuf = '\0'; *mbuf = '\0';
sendto_channel_local(ALL_MEMBERS, chptr, sendto_channel_local(ALL_MEMBERS, chptr,
":%s MODE %s %s %s %s %s %s", ":%s MODE %s %s %s %s %s %s",
@ -1373,10 +1237,8 @@ remove_our_modes(struct Channel *chptr, struct Client *source_p)
lpara[count++] = msptr->client_p->name; lpara[count++] = msptr->client_p->name;
*mbuf++ = 'h'; *mbuf++ = 'h';
} }
if(is_voiced(msptr)) if(is_voiced(msptr)) {
{ if(count >= MAXMODEPARAMS) {
if(count >= MAXMODEPARAMS)
{
*mbuf = '\0'; *mbuf = '\0';
sendto_channel_local(ALL_MEMBERS, chptr, sendto_channel_local(ALL_MEMBERS, chptr,
":%s MODE %s %s %s %s %s %s", ":%s MODE %s %s %s %s %s %s",
@ -1397,18 +1259,14 @@ remove_our_modes(struct Channel *chptr, struct Client *source_p)
lpara[count++] = msptr->client_p->name; lpara[count++] = msptr->client_p->name;
*mbuf++ = 'v'; *mbuf++ = 'v';
} }
} } else if(is_chanop(msptr)) {
else if(is_chanop(msptr))
{
msptr->flags &= ~CHFL_CHANOP; msptr->flags &= ~CHFL_CHANOP;
lpara[count++] = msptr->client_p->name; lpara[count++] = msptr->client_p->name;
*mbuf++ = 'o'; *mbuf++ = 'o';
/* Make sure it fits if +h or +v are involved */ /* Make sure it fits if +h or +v are involved */
if(is_halfop(msptr)) if(is_halfop(msptr)) {
{ if(count >= MAXMODEPARAMS) {
if(count >= MAXMODEPARAMS)
{
*mbuf = '\0'; *mbuf = '\0';
sendto_channel_local(ALL_MEMBERS, chptr, sendto_channel_local(ALL_MEMBERS, chptr,
":%s MODE %s %s %s %s %s %s", ":%s MODE %s %s %s %s %s %s",
@ -1429,10 +1287,8 @@ remove_our_modes(struct Channel *chptr, struct Client *source_p)
lpara[count++] = msptr->client_p->name; lpara[count++] = msptr->client_p->name;
*mbuf++ = 'h'; *mbuf++ = 'h';
} }
if(is_voiced(msptr)) if(is_voiced(msptr)) {
{ if(count >= MAXMODEPARAMS) {
if(count >= MAXMODEPARAMS)
{
*mbuf = '\0'; *mbuf = '\0';
sendto_channel_local(ALL_MEMBERS, chptr, sendto_channel_local(ALL_MEMBERS, chptr,
":%s MODE %s %s %s %s %s %s", ":%s MODE %s %s %s %s %s %s",
@ -1453,18 +1309,14 @@ remove_our_modes(struct Channel *chptr, struct Client *source_p)
lpara[count++] = msptr->client_p->name; lpara[count++] = msptr->client_p->name;
*mbuf++ = 'v'; *mbuf++ = 'v';
} }
} } else if(is_halfop(msptr)) {
else if(is_halfop(msptr))
{
msptr->flags &= ~CHFL_HALFOP; msptr->flags &= ~CHFL_HALFOP;
lpara[count++] = msptr->client_p->name; lpara[count++] = msptr->client_p->name;
*mbuf++ = 'h'; *mbuf++ = 'h';
/* +hv, might not fit so check. */ /* +hv, might not fit so check. */
if(is_voiced(msptr)) if(is_voiced(msptr)) {
{ if(count >= MAXMODEPARAMS) {
if(count >= MAXMODEPARAMS)
{
*mbuf = '\0'; *mbuf = '\0';
sendto_channel_local(ALL_MEMBERS, chptr, sendto_channel_local(ALL_MEMBERS, chptr,
":%s MODE %s %s %s %s %s %s", ":%s MODE %s %s %s %s %s %s",
@ -1485,18 +1337,14 @@ remove_our_modes(struct Channel *chptr, struct Client *source_p)
lpara[count++] = msptr->client_p->name; lpara[count++] = msptr->client_p->name;
*mbuf++ = 'v'; *mbuf++ = 'v';
} }
} } else if(is_voiced(msptr)) {
else if(is_voiced(msptr))
{
msptr->flags &= ~CHFL_VOICE; msptr->flags &= ~CHFL_VOICE;
lpara[count++] = msptr->client_p->name; lpara[count++] = msptr->client_p->name;
*mbuf++ = 'v'; *mbuf++ = 'v';
} } else
else
continue; continue;
if(count >= MAXMODEPARAMS) if(count >= MAXMODEPARAMS) {
{
*mbuf = '\0'; *mbuf = '\0';
sendto_channel_local(ALL_MEMBERS, chptr, sendto_channel_local(ALL_MEMBERS, chptr,
":%s MODE %s %s %s %s %s %s", ":%s MODE %s %s %s %s %s %s",
@ -1511,8 +1359,7 @@ remove_our_modes(struct Channel *chptr, struct Client *source_p)
} }
} }
if(count != 0) if(count != 0) {
{
*mbuf = '\0'; *mbuf = '\0';
sendto_channel_local(ALL_MEMBERS, chptr, sendto_channel_local(ALL_MEMBERS, chptr,
":%s MODE %s %s %s %s %s %s", ":%s MODE %s %s %s %s %s %s",
@ -1549,15 +1396,13 @@ remove_ban_list(struct Channel *chptr, struct Client *source_p,
cur_len = mlen = rb_sprintf(lmodebuf, ":%s MODE %s -", source_p->name, chptr->chname); cur_len = mlen = rb_sprintf(lmodebuf, ":%s MODE %s -", source_p->name, chptr->chname);
mbuf = lmodebuf + mlen; mbuf = lmodebuf + mlen;
RB_DLINK_FOREACH_SAFE(ptr, next_ptr, list->head) RB_DLINK_FOREACH_SAFE(ptr, next_ptr, list->head) {
{
banptr = ptr->data; banptr = ptr->data;
/* trailing space, and the mode letter itself */ /* trailing space, and the mode letter itself */
plen = strlen(banptr->banstr) + 2; plen = strlen(banptr->banstr) + 2;
if(count >= MAXMODEPARAMS || (cur_len + plen) > BUFSIZE - 4) if(count >= MAXMODEPARAMS || (cur_len + plen) > BUFSIZE - 4) {
{
/* remove trailing space */ /* remove trailing space */
*mbuf = '\0'; *mbuf = '\0';
*(pbuf - 1) = '\0'; *(pbuf - 1) = '\0';

View File

@ -82,38 +82,31 @@ m_kick(struct Client *client_p, struct Client *source_p, int parc, const char *p
name = parv[1]; name = parv[1];
chptr = find_channel(name); chptr = find_channel(name);
if(chptr == NULL) if(chptr == NULL) {
{
sendto_one_numeric(source_p, ERR_NOSUCHCHANNEL, form_str(ERR_NOSUCHCHANNEL), name); sendto_one_numeric(source_p, ERR_NOSUCHCHANNEL, form_str(ERR_NOSUCHCHANNEL), name);
return 0; return 0;
} }
user = parv[2]; /* strtoken(&p2, parv[2], ","); */ user = parv[2]; /* strtoken(&p2, parv[2], ","); */
if(!(who = find_chasing(source_p, user, &chasing))) if(!(who = find_chasing(source_p, user, &chasing))) {
{
return 0; return 0;
} }
if(!IsServer(source_p)) if(!IsServer(source_p)) {
{
msptr = find_channel_membership(chptr, source_p); msptr = find_channel_membership(chptr, source_p);
if((msptr == NULL) && MyConnect(source_p)) if((msptr == NULL) && MyConnect(source_p)) {
{
sendto_one_numeric(source_p, ERR_NOTONCHANNEL, sendto_one_numeric(source_p, ERR_NOTONCHANNEL,
form_str(ERR_NOTONCHANNEL), name); form_str(ERR_NOTONCHANNEL), name);
return 0; return 0;
} }
if(!can_kick_deop(msptr, find_channel_membership(chptr, who))) if(!can_kick_deop(msptr, find_channel_membership(chptr, who))) {
{ if(MyConnect(source_p)) {
if(MyConnect(source_p))
{
if(IsOverride(source_p)) if(IsOverride(source_p))
is_override = 1; is_override = 1;
else else {
{
sendto_one(source_p, ":%s 482 %s %s :You do not have the proper privileges to kick this user", sendto_one(source_p, ":%s 482 %s %s :You do not have the proper privileges to kick this user",
me.name, source_p->name, name); me.name, source_p->name, name);
return 0; return 0;
@ -121,8 +114,7 @@ m_kick(struct Client *client_p, struct Client *source_p, int parc, const char *p
} }
/* If its a TS 0 channel, do it the old way */ /* If its a TS 0 channel, do it the old way */
else if(chptr->channelts == 0) else if(chptr->channelts == 0) {
{
sendto_one(source_p, form_str(ERR_CHANOPRIVSNEEDED), sendto_one(source_p, form_str(ERR_CHANOPRIVSNEEDED),
get_id(&me, source_p), get_id(source_p, source_p), name); get_id(&me, source_p), get_id(source_p, source_p), name);
return 0; return 0;
@ -156,17 +148,14 @@ m_kick(struct Client *client_p, struct Client *source_p, int parc, const char *p
msptr = find_channel_membership(chptr, who); msptr = find_channel_membership(chptr, who);
if(msptr != NULL) if(msptr != NULL) {
{ if(MyClient(source_p) && IsService(who)) {
if(MyClient(source_p) && IsService(who))
{
sendto_one(source_p, form_str(ERR_ISCHANSERVICE), sendto_one(source_p, form_str(ERR_ISCHANSERVICE),
me.name, source_p->name, who->name, chptr->chname); me.name, source_p->name, who->name, chptr->chname);
return 0; return 0;
} }
if(MyClient(source_p) && chptr->mode.mode & MODE_NOKICK) if(MyClient(source_p) && chptr->mode.mode & MODE_NOKICK) {
{
sendto_one_numeric(source_p, ERR_NOKICK, sendto_one_numeric(source_p, ERR_NOKICK,
form_str(ERR_NOKICK), form_str(ERR_NOKICK),
chptr->chname); chptr->chname);
@ -174,8 +163,7 @@ m_kick(struct Client *client_p, struct Client *source_p, int parc, const char *p
} }
//NOTE: Will not stop kicks from services. //NOTE: Will not stop kicks from services.
if (MyClient(source_p) && chptr->mode.mode & MODE_NOOPERKICK && IsOper(who)) if (MyClient(source_p) && chptr->mode.mode & MODE_NOOPERKICK && IsOper(who)) {
{
sendto_realops_snomask(SNO_GENERAL, L_NETWIDE, sendto_realops_snomask(SNO_GENERAL, L_NETWIDE,
"Overriding KICK from %s on %s in %s (channel is +M)", "Overriding KICK from %s on %s in %s (channel is +M)",
source_p->name, who->name, chptr->chname); source_p->name, who->name, chptr->chname);
@ -185,8 +173,7 @@ m_kick(struct Client *client_p, struct Client *source_p, int parc, const char *p
return 0; return 0;
} }
if(MyClient(source_p)) if(MyClient(source_p)) {
{
hook_data_channel_approval hookdata; hook_data_channel_approval hookdata;
hookdata.client = source_p; hookdata.client = source_p;
@ -204,8 +191,7 @@ m_kick(struct Client *client_p, struct Client *source_p, int parc, const char *p
if(strlen(comment) > (size_t) REASONLEN) if(strlen(comment) > (size_t) REASONLEN)
comment[REASONLEN] = '\0'; comment[REASONLEN] = '\0';
if(is_override) if(is_override) {
{
sendto_wallops_flags(UMODE_WALLOP, &me, sendto_wallops_flags(UMODE_WALLOP, &me,
"%s is overriding KICK [%s] on [%s] [%s]", "%s is overriding KICK [%s] on [%s] [%s]",
get_oper_name(source_p), who->name, chptr->chname, comment); get_oper_name(source_p), who->name, chptr->chname, comment);
@ -240,8 +226,7 @@ m_kick(struct Client *client_p, struct Client *source_p, int parc, const char *p
/* we don't need to track NOREJOIN stuff unless it's our client being kicked */ /* we don't need to track NOREJOIN stuff unless it's our client being kicked */
if(MyClient(who) && chptr->mode.mode & MODE_NOREJOIN) if(MyClient(who) && chptr->mode.mode & MODE_NOREJOIN)
channel_metadata_time_add(chptr, text, rb_current_time(), "KICKNOREJOIN"); channel_metadata_time_add(chptr, text, rb_current_time(), "KICKNOREJOIN");
} } else if (MyClient(source_p))
else if (MyClient(source_p))
sendto_one_numeric(source_p, ERR_USERNOTINCHANNEL, sendto_one_numeric(source_p, ERR_USERNOTINCHANNEL,
form_str(ERR_USERNOTINCHANNEL), user, name); form_str(ERR_USERNOTINCHANNEL), user, name);

View File

@ -70,32 +70,27 @@ mo_kill(struct Client *client_p, struct Client *source_p, int parc, const char *
user = parv[1]; user = parv[1];
if(!IsOperLocalKill(source_p)) if(!IsOperLocalKill(source_p)) {
{
sendto_one(source_p, form_str(ERR_NOPRIVS), me.name, source_p->name, "local_kill"); sendto_one(source_p, form_str(ERR_NOPRIVS), me.name, source_p->name, "local_kill");
return 0; return 0;
} }
if(!EmptyString(parv[2])) if(!EmptyString(parv[2])) {
{
char *s; char *s;
s = LOCAL_COPY(parv[2]); s = LOCAL_COPY(parv[2]);
if(strlen(s) > (size_t) KILLLEN) if(strlen(s) > (size_t) KILLLEN)
s[KILLLEN] = '\0'; s[KILLLEN] = '\0';
reason = s; reason = s;
} } else
else
reason = "<No reason given>"; reason = "<No reason given>";
if((target_p = find_named_person(user)) == NULL) if((target_p = find_named_person(user)) == NULL) {
{
/* /*
** If the user has recently changed nick, automatically ** If the user has recently changed nick, automatically
** rewrite the KILL for this new nickname--this keeps ** rewrite the KILL for this new nickname--this keeps
** servers in synch when nick change and kill collide ** servers in synch when nick change and kill collide
*/ */
if((target_p = get_history(user, (long) KILLCHASETIMELIMIT)) == NULL) if((target_p = get_history(user, (long) KILLCHASETIMELIMIT)) == NULL) {
{
if (strchr(user, '.')) if (strchr(user, '.'))
sendto_one_numeric(source_p, ERR_CANTKILLSERVER, form_str(ERR_CANTKILLSERVER)); sendto_one_numeric(source_p, ERR_CANTKILLSERVER, form_str(ERR_CANTKILLSERVER));
else else
@ -106,8 +101,7 @@ mo_kill(struct Client *client_p, struct Client *source_p, int parc, const char *
sendto_one_notice(source_p, ":KILL changed from %s to %s", user, target_p->name); sendto_one_notice(source_p, ":KILL changed from %s to %s", user, target_p->name);
} }
if(!MyConnect(target_p) && (!IsOperGlobalKill(source_p))) if(!MyConnect(target_p) && (!IsOperGlobalKill(source_p))) {
{
sendto_one_notice(source_p, ":Nick %s is not on your server " sendto_one_notice(source_p, ":Nick %s is not on your server "
"and you do not have the global_kill flag", "and you do not have the global_kill flag",
target_p->name); target_p->name);
@ -136,8 +130,7 @@ mo_kill(struct Client *client_p, struct Client *source_p, int parc, const char *
** back. ** back.
** Suicide kills are NOT passed on --SRB ** Suicide kills are NOT passed on --SRB
*/ */
if(!MyConnect(target_p)) if(!MyConnect(target_p)) {
{
relay_kill(client_p, source_p, target_p, inpath, reason); relay_kill(client_p, source_p, target_p, inpath, reason);
/* /*
** Set FLAGS_KILLED. This prevents exit_one_client from sending ** Set FLAGS_KILLED. This prevents exit_one_client from sending
@ -173,39 +166,32 @@ ms_kill(struct Client *client_p, struct Client *source_p, int parc, const char *
user = parv[1]; user = parv[1];
if(EmptyString(parv[2])) if(EmptyString(parv[2])) {
{
reason = default_reason; reason = default_reason;
/* hyb6 takes the nick of the killer from the path *sigh* --fl_ */ /* hyb6 takes the nick of the killer from the path *sigh* --fl_ */
path = source_p->name; path = source_p->name;
} } else {
else
{
char *s = LOCAL_COPY(parv[2]), *t; char *s = LOCAL_COPY(parv[2]), *t;
t = strchr(s, ' '); t = strchr(s, ' ');
if(t) if(t) {
{
*t = '\0'; *t = '\0';
t++; t++;
reason = t; reason = t;
} } else
else
reason = default_reason; reason = default_reason;
path = s; path = s;
} }
if((target_p = find_person(user)) == NULL) if((target_p = find_person(user)) == NULL) {
{
/* /*
* If the user has recently changed nick, but only if its * If the user has recently changed nick, but only if its
* not an uid, automatically rewrite the KILL for this new nickname. * not an uid, automatically rewrite the KILL for this new nickname.
* --this keeps servers in synch when nick change and kill collide * --this keeps servers in synch when nick change and kill collide
*/ */
if(IsDigit(*user) || (!(target_p = get_history(user, (long) KILLCHASETIMELIMIT)))) if(IsDigit(*user) || (!(target_p = get_history(user, (long) KILLCHASETIMELIMIT)))) {
{
sendto_one_numeric(source_p, ERR_NOSUCHNICK, sendto_one_numeric(source_p, ERR_NOSUCHNICK,
form_str(ERR_NOSUCHNICK), IsDigit(*user) ? "*" : user); form_str(ERR_NOSUCHNICK), IsDigit(*user) ? "*" : user);
return 0; return 0;
@ -214,20 +200,16 @@ ms_kill(struct Client *client_p, struct Client *source_p, int parc, const char *
chasing = 1; chasing = 1;
} }
if(IsServer(target_p) || IsMe(target_p)) if(IsServer(target_p) || IsMe(target_p)) {
{
sendto_one_numeric(source_p, ERR_CANTKILLSERVER, form_str(ERR_CANTKILLSERVER)); sendto_one_numeric(source_p, ERR_CANTKILLSERVER, form_str(ERR_CANTKILLSERVER));
return 0; return 0;
} }
if(MyConnect(target_p)) if(MyConnect(target_p)) {
{ if(IsServer(source_p)) {
if(IsServer(source_p))
{
sendto_one(target_p, ":%s KILL %s :%s", sendto_one(target_p, ":%s KILL %s :%s",
source_p->name, target_p->name, reason); source_p->name, target_p->name, reason);
} } else
else
sendto_one(target_p, ":%s!%s@%s KILL %s :%s", sendto_one(target_p, ":%s!%s@%s KILL %s :%s",
source_p->name, source_p->username, source_p->host, source_p->name, source_p->username, source_p->host,
target_p->name, reason); target_p->name, reason);
@ -238,8 +220,7 @@ ms_kill(struct Client *client_p, struct Client *source_p, int parc, const char *
/* path must contain at least 2 !'s, or bitchx falsely declares it /* path must contain at least 2 !'s, or bitchx falsely declares it
* local --fl * local --fl
*/ */
if(IsOper(source_p)) /* send it normally */ if(IsOper(source_p)) { /* send it normally */
{
sendto_realops_snomask(IsService(source_p) ? SNO_SKILL : SNO_GENERAL, L_ALL, sendto_realops_snomask(IsService(source_p) ? SNO_SKILL : SNO_GENERAL, L_ALL,
"Received KILL message for %s!%s@%s. From %s Path: %s!%s!%s!%s %s", "Received KILL message for %s!%s@%s. From %s Path: %s!%s!%s!%s %s",
target_p->name, target_p->username, target_p->orighost, source_p->name, target_p->name, target_p->username, target_p->orighost, source_p->name,
@ -250,9 +231,7 @@ ms_kill(struct Client *client_p, struct Client *source_p, int parc, const char *
MyConnect(target_p) ? 'O' : 'R', get_oper_name(source_p), MyConnect(target_p) ? 'O' : 'R', get_oper_name(source_p),
target_p->name, target_p->username, target_p->host, target_p->name, target_p->username, target_p->host,
target_p->servptr->name, reason); target_p->servptr->name, reason);
} } else {
else
{
sendto_realops_snomask(SNO_SKILL, L_ALL, sendto_realops_snomask(SNO_SKILL, L_ALL,
"Received KILL message for %s!%s@%s. From %s %s", "Received KILL message for %s!%s@%s. From %s %s",
target_p->name, target_p->username, target_p->orighost, target_p->name, target_p->username, target_p->orighost,
@ -290,8 +269,7 @@ relay_kill(struct Client *one, struct Client *source_p,
else else
rb_snprintf(buffer, sizeof(buffer), "%s %s", inpath, reason); rb_snprintf(buffer, sizeof(buffer), "%s %s", inpath, reason);
RB_DLINK_FOREACH(ptr, serv_list.head) RB_DLINK_FOREACH(ptr, serv_list.head) {
{
client_p = ptr->data; client_p = ptr->data;
if(!client_p || client_p == one) if(!client_p || client_p == one)

View File

@ -80,8 +80,7 @@ mapi_clist_av1 message_clist[] = { &privmsg_msgtab, &notice_msgtab, NULL };
DECLARE_MODULE_AV1(message, modinit, moddeinit, message_clist, NULL, NULL, "$Revision: 3173 $"); DECLARE_MODULE_AV1(message, modinit, moddeinit, message_clist, NULL, NULL, "$Revision: 3173 $");
struct entity struct entity {
{
void *ptr; void *ptr;
int type; int type;
int flags; int flags;
@ -176,16 +175,14 @@ m_message(int p_or_n,
{ {
int i; int i;
if(parc < 2 || EmptyString(parv[1])) if(parc < 2 || EmptyString(parv[1])) {
{
if(p_or_n != NOTICE) if(p_or_n != NOTICE)
sendto_one(source_p, form_str(ERR_NORECIPIENT), me.name, sendto_one(source_p, form_str(ERR_NORECIPIENT), me.name,
source_p->name, command); source_p->name, command);
return 0; return 0;
} }
if(parc < 3 || EmptyString(parv[2])) if(parc < 3 || EmptyString(parv[2])) {
{
if(p_or_n != NOTICE) if(p_or_n != NOTICE)
sendto_one(source_p, form_str(ERR_NOTEXTTOSEND), me.name, source_p->name); sendto_one(source_p, form_str(ERR_NOTEXTTOSEND), me.name, source_p->name);
return 0; return 0;
@ -197,15 +194,12 @@ m_message(int p_or_n,
if(MyClient(source_p) && !IsFloodDone(source_p) && irccmp(source_p->name, parv[1])) if(MyClient(source_p) && !IsFloodDone(source_p) && irccmp(source_p->name, parv[1]))
flood_endgrace(source_p); flood_endgrace(source_p);
if(build_target_list(p_or_n, command, client_p, source_p, parv[1], parv[2]) < 0) if(build_target_list(p_or_n, command, client_p, source_p, parv[1], parv[2]) < 0) {
{
return 0; return 0;
} }
for(i = 0; i < ntargets; i++) for(i = 0; i < ntargets; i++) {
{ switch (targets[i].type) {
switch (targets[i].type)
{
case ENTITY_CHANNEL: case ENTITY_CHANNEL:
msg_channel(p_or_n, command, client_p, source_p, msg_channel(p_or_n, command, client_p, source_p,
(struct Channel *) targets[i].ptr, parv[2]); (struct Channel *) targets[i].ptr, parv[2]);
@ -263,26 +257,21 @@ build_target_list(int p_or_n, const char *command, struct Client *client_p,
ntargets = 0; ntargets = 0;
for(nick = rb_strtok_r(target_list, ",", &p); nick; nick = rb_strtok_r(NULL, ",", &p)) for(nick = rb_strtok_r(target_list, ",", &p); nick; nick = rb_strtok_r(NULL, ",", &p)) {
{
char *with_prefix; char *with_prefix;
/* /*
* channels are privmsg'd a lot more than other clients, moved up * channels are privmsg'd a lot more than other clients, moved up
* here plain old channel msg? * here plain old channel msg?
*/ */
if(IsChanPrefix(*nick)) if(IsChanPrefix(*nick)) {
{
/* ignore send of local channel to a server (should not happen) */ /* ignore send of local channel to a server (should not happen) */
if(IsServer(client_p) && *nick == '&') if(IsServer(client_p) && *nick == '&')
continue; continue;
if((chptr = find_channel(nick)) != NULL) if((chptr = find_channel(nick)) != NULL) {
{ if(!duplicate_ptr(chptr)) {
if(!duplicate_ptr(chptr)) if(ntargets >= ConfigFileEntry.max_targets) {
{
if(ntargets >= ConfigFileEntry.max_targets)
{
sendto_one(source_p, form_str(ERR_TOOMANYTARGETS), sendto_one(source_p, form_str(ERR_TOOMANYTARGETS),
me.name, source_p->name, nick); me.name, source_p->name, nick);
return (1); return (1);
@ -306,12 +295,9 @@ build_target_list(int p_or_n, const char *command, struct Client *client_p,
target_p = find_person(nick); target_p = find_person(nick);
/* look for a privmsg to another client */ /* look for a privmsg to another client */
if(target_p) if(target_p) {
{ if(!duplicate_ptr(target_p)) {
if(!duplicate_ptr(target_p)) if(ntargets >= ConfigFileEntry.max_targets) {
{
if(ntargets >= ConfigFileEntry.max_targets)
{
sendto_one(source_p, form_str(ERR_TOOMANYTARGETS), sendto_one(source_p, form_str(ERR_TOOMANYTARGETS),
me.name, source_p->name, nick); me.name, source_p->name, nick);
return (1); return (1);
@ -328,8 +314,7 @@ build_target_list(int p_or_n, const char *command, struct Client *client_p,
type = 0; type = 0;
with_prefix = nick; with_prefix = nick;
/* allow %+@ if someone wants to do that */ /* allow %+@ if someone wants to do that */
for(;;) for(;;) {
{
if(*nick == '@') if(*nick == '@')
type |= CHFL_CHANOP; type |= CHFL_CHANOP;
else if(*nick == '+') else if(*nick == '+')
@ -339,11 +324,9 @@ build_target_list(int p_or_n, const char *command, struct Client *client_p,
nick++; nick++;
} }
if(type != 0) if(type != 0) {
{
/* no recipient.. */ /* no recipient.. */
if(EmptyString(nick)) if(EmptyString(nick)) {
{
sendto_one(source_p, form_str(ERR_NORECIPIENT), sendto_one(source_p, form_str(ERR_NORECIPIENT),
me.name, source_p->name, command); me.name, source_p->name, command);
continue; continue;
@ -353,14 +336,12 @@ build_target_list(int p_or_n, const char *command, struct Client *client_p,
* if the channel is found, fine, if not report an error * if the channel is found, fine, if not report an error
*/ */
if((chptr = find_channel(nick)) != NULL) if((chptr = find_channel(nick)) != NULL) {
{
struct membership *msptr; struct membership *msptr;
msptr = find_channel_membership(chptr, source_p); msptr = find_channel_membership(chptr, source_p);
if(!IsServer(source_p) && !IsService(source_p) && !is_chanop_voiced(msptr)) if(!IsServer(source_p) && !IsService(source_p) && !is_chanop_voiced(msptr)) {
{
sendto_one(source_p, form_str(ERR_CHANOPRIVSNEEDED), sendto_one(source_p, form_str(ERR_CHANOPRIVSNEEDED),
get_id(&me, source_p), get_id(&me, source_p),
get_id(source_p, source_p), get_id(source_p, source_p),
@ -368,10 +349,8 @@ build_target_list(int p_or_n, const char *command, struct Client *client_p,
return (-1); return (-1);
} }
if(!duplicate_ptr(chptr)) if(!duplicate_ptr(chptr)) {
{ if(ntargets >= ConfigFileEntry.max_targets) {
if(ntargets >= ConfigFileEntry.max_targets)
{
sendto_one(source_p, form_str(ERR_TOOMANYTARGETS), sendto_one(source_p, form_str(ERR_TOOMANYTARGETS),
me.name, source_p->name, nick); me.name, source_p->name, nick);
return (1); return (1);
@ -380,9 +359,7 @@ build_target_list(int p_or_n, const char *command, struct Client *client_p,
targets[ntargets].type = ENTITY_CHANOPS_ON_CHANNEL; targets[ntargets].type = ENTITY_CHANOPS_ON_CHANNEL;
targets[ntargets++].flags = type; targets[ntargets++].flags = type;
} }
} } else if(p_or_n != NOTICE) {
else if(p_or_n != NOTICE)
{
sendto_one_numeric(source_p, ERR_NOSUCHNICK, sendto_one_numeric(source_p, ERR_NOSUCHNICK,
form_str(ERR_NOSUCHNICK), nick); form_str(ERR_NOSUCHNICK), nick);
} }
@ -390,15 +367,11 @@ build_target_list(int p_or_n, const char *command, struct Client *client_p,
continue; continue;
} }
if(IsServer(client_p) && *nick == '=' && nick[1] == '#') if(IsServer(client_p) && *nick == '=' && nick[1] == '#') {
{
nick++; nick++;
if((chptr = find_channel(nick)) != NULL) if((chptr = find_channel(nick)) != NULL) {
{ if(!duplicate_ptr(chptr)) {
if(!duplicate_ptr(chptr)) if(ntargets >= ConfigFileEntry.max_targets) {
{
if(ntargets >= ConfigFileEntry.max_targets)
{
sendto_one(source_p, form_str(ERR_TOOMANYTARGETS), sendto_one(source_p, form_str(ERR_TOOMANYTARGETS),
me.name, source_p->name, nick); me.name, source_p->name, nick);
return (1); return (1);
@ -416,15 +389,13 @@ build_target_list(int p_or_n, const char *command, struct Client *client_p,
continue; continue;
} }
if(strchr(nick, '@') || (IsOper(source_p) && (*nick == '$'))) if(strchr(nick, '@') || (IsOper(source_p) && (*nick == '$'))) {
{
handle_special(p_or_n, command, client_p, source_p, nick, text); handle_special(p_or_n, command, client_p, source_p, nick, text);
continue; continue;
} }
/* no matching anything found - error if not NOTICE */ /* no matching anything found - error if not NOTICE */
if(p_or_n != NOTICE) if(p_or_n != NOTICE) {
{
/* dont give this numeric when source is local, /* dont give this numeric when source is local,
* because its misleading --anfl * because its misleading --anfl
*/ */
@ -488,22 +459,18 @@ msg_channel(int p_or_n, const char *command,
struct membership *msptr = find_channel_membership(chptr, source_p); struct membership *msptr = find_channel_membership(chptr, source_p);
struct Metadata *md; struct Metadata *md;
if(MyClient(source_p)) if(MyClient(source_p)) {
{
/* idle time shouldnt be reset by notices --fl */ /* idle time shouldnt be reset by notices --fl */
if(p_or_n != NOTICE) if(p_or_n != NOTICE)
source_p->localClient->last = rb_current_time(); source_p->localClient->last = rb_current_time();
} }
if(chptr->mode.mode & MODE_NOREPEAT) if(chptr->mode.mode & MODE_NOREPEAT) {
{
rb_strlcpy(text2, text, BUFSIZE); rb_strlcpy(text2, text, BUFSIZE);
strip_unprintable(text2); strip_unprintable(text2);
md = channel_metadata_find(chptr, "NOREPEAT"); md = channel_metadata_find(chptr, "NOREPEAT");
if(md && (!ConfigChannel.exempt_cmode_K || !is_any_op(msptr))) if(md && (!ConfigChannel.exempt_cmode_K || !is_any_op(msptr))) {
{ if(!(strcmp(md->value, text2))) {
if(!(strcmp(md->value, text2)))
{
if(p_or_n != NOTICE) if(p_or_n != NOTICE)
sendto_one_numeric(source_p, 404, "%s :Cannot send to channel - Message blocked due to repeating (+K set)", chptr->chname); sendto_one_numeric(source_p, 404, "%s :Cannot send to channel - Message blocked due to repeating (+K set)", chptr->chname);
return; return;
@ -514,40 +481,34 @@ msg_channel(int p_or_n, const char *command,
} }
// Must be processed before chmode c --SnoFox // Must be processed before chmode c --SnoFox
if (strlen(text) > 10 && chptr->mode.mode & MODE_NOCAPS && (!ConfigChannel.exempt_cmode_G || !is_any_op(msptr))) if (strlen(text) > 10 && chptr->mode.mode & MODE_NOCAPS && (!ConfigChannel.exempt_cmode_G || !is_any_op(msptr))) {
{
rb_strlcpy(text2, text, BUFSIZE); rb_strlcpy(text2, text, BUFSIZE);
strip_unprintable(text2); strip_unprintable(text2);
// Don't count the "ACTION" part of action as part of the message --SnoFox // Don't count the "ACTION" part of action as part of the message --SnoFox
if (p_or_n != NOTICE && *text == '\001' && if (p_or_n != NOTICE && *text == '\001' &&
!strncasecmp(text + 1, "ACTION ", 7)) !strncasecmp(text + 1, "ACTION ", 7)) {
{
contor = 7; contor = 7;
} else { } else {
contor = 0; contor = 0;
} }
for(; contor < strlen(text2); contor++) for(; contor < strlen(text2); contor++) {
{
if(IsUpper(text2[contor]) && !isdigit(text2[contor])) if(IsUpper(text2[contor]) && !isdigit(text2[contor]))
caps++; caps++;
len++; len++;
} }
/* Added divide by 0 check --alxbl */ /* Added divide by 0 check --alxbl */
if(len != 0 && ((caps*100)/(len)) >= 50) if(len != 0 && ((caps*100)/(len)) >= 50) {
{
sendto_one_numeric(source_p, 404, "%s :Cannot send to channel - Your message contains mostly capital letters (+G set)", chptr->chname); sendto_one_numeric(source_p, 404, "%s :Cannot send to channel - Your message contains mostly capital letters (+G set)", chptr->chname);
return; return;
} }
} }
if(chptr->mode.mode & MODE_NOCOLOR && (!ConfigChannel.exempt_cmode_c || !is_any_op(msptr))) if(chptr->mode.mode & MODE_NOCOLOR && (!ConfigChannel.exempt_cmode_c || !is_any_op(msptr))) {
{
rb_strlcpy(text2, text, BUFSIZE); rb_strlcpy(text2, text, BUFSIZE);
strip_colour(text2); strip_colour(text2);
text = text2; text = text2;
if (EmptyString(text)) if (EmptyString(text)) {
{
/* could be empty after colour stripping and /* could be empty after colour stripping and
* that would cause problems later */ * that would cause problems later */
if(p_or_n != NOTICE) if(p_or_n != NOTICE)
@ -557,65 +518,51 @@ msg_channel(int p_or_n, const char *command,
} }
/* chanops and voiced can flood their own channel with impunity */ /* chanops and voiced can flood their own channel with impunity */
if((result = can_send(chptr, source_p, NULL))) if((result = can_send(chptr, source_p, NULL))) {
{
if(result != CAN_SEND_OPV && MyClient(source_p) && if(result != CAN_SEND_OPV && MyClient(source_p) &&
!IsOper(source_p) && !IsOper(source_p) &&
!add_channel_target(source_p, chptr)) !add_channel_target(source_p, chptr)) {
{
sendto_one(source_p, form_str(ERR_TARGCHANGE), sendto_one(source_p, form_str(ERR_TARGCHANGE),
me.name, source_p->name, chptr->chname); me.name, source_p->name, chptr->chname);
return; return;
} }
if(result == CAN_SEND_OPV || if(result == CAN_SEND_OPV ||
!flood_attack_channel(p_or_n, source_p, chptr, chptr->chname)) !flood_attack_channel(p_or_n, source_p, chptr, chptr->chname)) {
{ if (p_or_n != PRIVMSG && chptr->mode.mode & MODE_NONOTICE && (!ConfigChannel.exempt_cmode_T || !is_any_op(msptr))) {
if (p_or_n != PRIVMSG && chptr->mode.mode & MODE_NONOTICE && (!ConfigChannel.exempt_cmode_T || !is_any_op(msptr)))
{
sendto_one_numeric(source_p, 404, "%s :Cannot send to channel - Notices are disallowed (+T set)", chptr->chname); sendto_one_numeric(source_p, 404, "%s :Cannot send to channel - Notices are disallowed (+T set)", chptr->chname);
return; return;
} }
if (p_or_n != NOTICE && chptr->mode.mode & MODE_NOACTION && if (p_or_n != NOTICE && chptr->mode.mode & MODE_NOACTION &&
!strncasecmp(text + 1, "ACTION", 6) && !strncasecmp(text + 1, "ACTION", 6) &&
(!ConfigChannel.exempt_cmode_D || !is_any_op(msptr))) (!ConfigChannel.exempt_cmode_D || !is_any_op(msptr))) {
{
sendto_one_numeric(source_p, 404, "%s :Cannot send to channel - ACTIONs are disallowed (+D set)", chptr->chname); sendto_one_numeric(source_p, 404, "%s :Cannot send to channel - ACTIONs are disallowed (+D set)", chptr->chname);
return; return;
} }
if (p_or_n != NOTICE && *text == '\001' && if (p_or_n != NOTICE && *text == '\001' &&
strncasecmp(text + 1, "ACTION ", 7)) strncasecmp(text + 1, "ACTION ", 7)) {
{ if (chptr->mode.mode & MODE_NOCTCP && (!ConfigChannel.exempt_cmode_C || !is_any_op(msptr))) {
if (chptr->mode.mode & MODE_NOCTCP && (!ConfigChannel.exempt_cmode_C || !is_any_op(msptr)))
{
sendto_one_numeric(source_p, 404, "%s :Cannot send to channel - CTCPs to this channel are disallowed (+C set)", chptr->chname); sendto_one_numeric(source_p, 404, "%s :Cannot send to channel - CTCPs to this channel are disallowed (+C set)", chptr->chname);
return; return;
} } else if (rb_dlink_list_length(&chptr->locmembers) > (unsigned)(GlobalSetOptions.floodcount / 2))
else if (rb_dlink_list_length(&chptr->locmembers) > (unsigned)(GlobalSetOptions.floodcount / 2))
source_p->large_ctcp_sent = rb_current_time(); source_p->large_ctcp_sent = rb_current_time();
} }
sendto_channel_flags(client_p, ALL_MEMBERS, source_p, chptr, sendto_channel_flags(client_p, ALL_MEMBERS, source_p, chptr,
"%s %s :%s", command, chptr->chname, text); "%s %s :%s", command, chptr->chname, text);
} }
} } else if(chptr->mode.mode & MODE_OPMODERATE &&
else if(chptr->mode.mode & MODE_OPMODERATE &&
(!(chptr->mode.mode & MODE_NOPRIVMSGS) || (!(chptr->mode.mode & MODE_NOPRIVMSGS) ||
IsMember(source_p, chptr))) IsMember(source_p, chptr))) {
{
if(MyClient(source_p) && !IsOper(source_p) && if(MyClient(source_p) && !IsOper(source_p) &&
!add_channel_target(source_p, chptr)) !add_channel_target(source_p, chptr)) {
{
sendto_one(source_p, form_str(ERR_TARGCHANGE), sendto_one(source_p, form_str(ERR_TARGCHANGE),
me.name, source_p->name, chptr->chname); me.name, source_p->name, chptr->chname);
return; return;
} }
if(!flood_attack_channel(p_or_n, source_p, chptr, chptr->chname)) if(!flood_attack_channel(p_or_n, source_p, chptr, chptr->chname)) {
{
sendto_channel_opmod(client_p, source_p, chptr, sendto_channel_opmod(client_p, source_p, chptr,
command, text); command, text);
} }
} } else {
else
{
if(p_or_n != NOTICE) if(p_or_n != NOTICE)
sendto_one_numeric(source_p, ERR_CANNOTSENDTOCHAN, sendto_one_numeric(source_p, ERR_CANNOTSENDTOCHAN,
form_str(ERR_CANNOTSENDTOCHAN), chptr->chname); form_str(ERR_CANNOTSENDTOCHAN), chptr->chname);
@ -641,13 +588,11 @@ msg_channel_opmod(int p_or_n, const char *command,
{ {
char text2[BUFSIZE]; char text2[BUFSIZE];
if(chptr->mode.mode & MODE_NOCOLOR) if(chptr->mode.mode & MODE_NOCOLOR) {
{
rb_strlcpy(text2, text, BUFSIZE); rb_strlcpy(text2, text, BUFSIZE);
strip_colour(text2); strip_colour(text2);
text = text2; text = text2;
if (EmptyString(text)) if (EmptyString(text)) {
{
/* could be empty after colour stripping and /* could be empty after colour stripping and
* that would cause problems later */ * that would cause problems later */
if(p_or_n != NOTICE) if(p_or_n != NOTICE)
@ -658,16 +603,12 @@ msg_channel_opmod(int p_or_n, const char *command,
if(chptr->mode.mode & MODE_OPMODERATE && if(chptr->mode.mode & MODE_OPMODERATE &&
(!(chptr->mode.mode & MODE_NOPRIVMSGS) || (!(chptr->mode.mode & MODE_NOPRIVMSGS) ||
IsMember(source_p, chptr))) IsMember(source_p, chptr))) {
{ if(!flood_attack_channel(p_or_n, source_p, chptr, chptr->chname)) {
if(!flood_attack_channel(p_or_n, source_p, chptr, chptr->chname))
{
sendto_channel_opmod(client_p, source_p, chptr, sendto_channel_opmod(client_p, source_p, chptr,
command, text); command, text);
} }
} } else {
else
{
if(p_or_n != NOTICE) if(p_or_n != NOTICE)
sendto_one_numeric(source_p, ERR_CANNOTSENDTOCHAN, sendto_one_numeric(source_p, ERR_CANNOTSENDTOCHAN,
form_str(ERR_CANNOTSENDTOCHAN), chptr->chname); form_str(ERR_CANNOTSENDTOCHAN), chptr->chname);
@ -695,19 +636,15 @@ msg_channel_flags(int p_or_n, const char *command, struct Client *client_p,
int type; int type;
char c; char c;
if(flags & CHFL_VOICE) if(flags & CHFL_VOICE) {
{
type = ONLY_CHANOPSVOICED; type = ONLY_CHANOPSVOICED;
c = '+'; c = '+';
} } else {
else
{
type = ONLY_CHANOPS; type = ONLY_CHANOPS;
c = '@'; c = '@';
} }
if(MyClient(source_p)) if(MyClient(source_p)) {
{
/* idletime shouldnt be reset by notice --fl */ /* idletime shouldnt be reset by notice --fl */
if(p_or_n != NOTICE) if(p_or_n != NOTICE)
source_p->localClient->last = rb_current_time(); source_p->localClient->last = rb_current_time();
@ -723,12 +660,10 @@ expire_tgchange(void *unused)
tgchange *target; tgchange *target;
rb_dlink_node *ptr, *next_ptr; rb_dlink_node *ptr, *next_ptr;
RB_DLINK_FOREACH_SAFE(ptr, next_ptr, tgchange_list.head) RB_DLINK_FOREACH_SAFE(ptr, next_ptr, tgchange_list.head) {
{
target = ptr->data; target = ptr->data;
if(target->expiry < rb_current_time()) if(target->expiry < rb_current_time()) {
{
rb_dlinkDelete(ptr, &tgchange_list); rb_dlinkDelete(ptr, &tgchange_list);
rb_patricia_remove(tgchange_tree, target->pnode); rb_patricia_remove(tgchange_tree, target->pnode);
rb_free(target->ip); rb_free(target->ip);
@ -759,8 +694,7 @@ msg_client(int p_or_n, const char *command,
int oaccept = 0; int oaccept = 0;
char text3[10]; char text3[10];
if(MyClient(source_p)) if(MyClient(source_p)) {
{
/* /*
* XXX: Controversial? Allow target users to send replies * XXX: Controversial? Allow target users to send replies
* through a +g. Rationale is that people can presently use +g * through a +g. Rationale is that people can presently use +g
@ -770,16 +704,12 @@ msg_client(int p_or_n, const char *command,
if(p_or_n != NOTICE && MyClient(source_p) && if(p_or_n != NOTICE && MyClient(source_p) &&
IsSetCallerId(source_p) && IsSetCallerId(source_p) &&
IsSetSCallerId(source_p) && IsSetSCallerId(source_p) &&
!accept_message(target_p, source_p)) !accept_message(target_p, source_p)) {
{
if(rb_dlink_list_length(&source_p->localClient->allow_list) < if(rb_dlink_list_length(&source_p->localClient->allow_list) <
ConfigFileEntry.max_accept) ConfigFileEntry.max_accept) {
{
rb_dlinkAddAlloc(target_p, &source_p->localClient->allow_list); rb_dlinkAddAlloc(target_p, &source_p->localClient->allow_list);
rb_dlinkAddAlloc(source_p, &target_p->on_allow_list); rb_dlinkAddAlloc(source_p, &target_p->on_allow_list);
} } else {
else
{
sendto_one_numeric(source_p, ERR_OWNMODE, sendto_one_numeric(source_p, ERR_OWNMODE,
form_str(ERR_OWNMODE), form_str(ERR_OWNMODE),
target_p->name, "+g"); target_p->name, "+g");
@ -801,10 +731,8 @@ msg_client(int p_or_n, const char *command,
* targets just by ctcping them * targets just by ctcping them
*/ */
if((p_or_n != NOTICE || *text != '\001') && if((p_or_n != NOTICE || *text != '\001') &&
ConfigFileEntry.target_change && do_floodcount) ConfigFileEntry.target_change && do_floodcount) {
{ if(!add_target(source_p, target_p)) {
if(!add_target(source_p, target_p))
{
sendto_one(source_p, form_str(ERR_TARGCHANGE), sendto_one(source_p, form_str(ERR_TARGCHANGE),
me.name, source_p->name, target_p->name); me.name, source_p->name, target_p->name);
return; return;
@ -818,9 +746,7 @@ msg_client(int p_or_n, const char *command,
if (do_floodcount && if (do_floodcount &&
flood_attack_client(p_or_n, source_p, target_p)) flood_attack_client(p_or_n, source_p, target_p))
return; return;
} } else if(source_p->from == target_p->from) {
else if(source_p->from == target_p->from)
{
sendto_realops_snomask(SNO_DEBUG, L_ALL, sendto_realops_snomask(SNO_DEBUG, L_ALL,
"Send message to %s[%s] dropped from %s(Fake Dir)", "Send message to %s[%s] dropped from %s(Fake Dir)",
target_p->name, target_p->from->name, source_p->name); target_p->name, target_p->from->name, source_p->name);
@ -831,10 +757,8 @@ msg_client(int p_or_n, const char *command,
sendto_one_numeric(source_p, RPL_AWAY, form_str(RPL_AWAY), sendto_one_numeric(source_p, RPL_AWAY, form_str(RPL_AWAY),
target_p->name, target_p->user->away); target_p->name, target_p->user->away);
if(MyClient(target_p)) if(MyClient(target_p)) {
{ if (IsSetNoCTCP(target_p) && p_or_n != NOTICE && *text == '\001' && strncasecmp(text + 1, "ACTION", 6)) {
if (IsSetNoCTCP(target_p) && p_or_n != NOTICE && *text == '\001' && strncasecmp(text + 1, "ACTION", 6))
{
sendto_one_numeric(source_p, ERR_NOCTCP, sendto_one_numeric(source_p, ERR_NOCTCP,
form_str(ERR_NOCTCP), form_str(ERR_NOCTCP),
target_p->name); target_p->name);
@ -842,56 +766,43 @@ msg_client(int p_or_n, const char *command,
/* If opers want to go through +g, they should load oaccept.*/ /* If opers want to go through +g, they should load oaccept.*/
else if(!IsServer(source_p) && !IsService(source_p) && (IsSetCallerId(target_p) || else if(!IsServer(source_p) && !IsService(source_p) && (IsSetCallerId(target_p) ||
(IsSetSCallerId(target_p) && !has_common_channel(source_p, target_p)) || (IsSetSCallerId(target_p) && !has_common_channel(source_p, target_p)) ||
(IsSetRegOnlyMsg(target_p) && !source_p->user->suser[0]))) (IsSetRegOnlyMsg(target_p) && !source_p->user->suser[0]))) {
{ if (IsOper(source_p)) {
if (IsOper(source_p))
{
rb_snprintf(text3, sizeof(text3), "O%s", source_p->id); rb_snprintf(text3, sizeof(text3), "O%s", source_p->id);
DICTIONARY_FOREACH(md, &iter, target_p->user->metadata) DICTIONARY_FOREACH(md, &iter, target_p->user->metadata) {
{ if(!strcmp(md->value, "OACCEPT") && !strcmp(md->name, text3)) {
if(!strcmp(md->value, "OACCEPT") && !strcmp(md->name, text3))
{
oaccept = 1; oaccept = 1;
break; break;
} }
} }
} }
/* Here is the anti-flood bot/spambot code -db */ /* Here is the anti-flood bot/spambot code -db */
if(accept_message(source_p, target_p) || oaccept) if(accept_message(source_p, target_p) || oaccept) {
{
add_reply_target(target_p, source_p); add_reply_target(target_p, source_p);
sendto_one(target_p, ":%s!%s@%s %s %s :%s", sendto_one(target_p, ":%s!%s@%s %s %s :%s",
source_p->name, source_p->name,
source_p->username, source_p->username,
source_p->host, command, target_p->name, text); source_p->host, command, target_p->name, text);
} } else if (IsSetRegOnlyMsg(target_p) && !source_p->user->suser[0]) {
else if (IsSetRegOnlyMsg(target_p) && !source_p->user->suser[0])
{
if (p_or_n != NOTICE) if (p_or_n != NOTICE)
sendto_one_numeric(source_p, ERR_NONONREG, sendto_one_numeric(source_p, ERR_NONONREG,
form_str(ERR_NONONREG), form_str(ERR_NONONREG),
target_p->name); target_p->name);
} } else if (IsSetSCallerId(target_p) && !has_common_channel(source_p, target_p)) {
else if (IsSetSCallerId(target_p) && !has_common_channel(source_p, target_p))
{
if (p_or_n != NOTICE) if (p_or_n != NOTICE)
sendto_one_numeric(source_p, ERR_NOCOMMONCHAN, sendto_one_numeric(source_p, ERR_NOCOMMONCHAN,
form_str(ERR_NOCOMMONCHAN), form_str(ERR_NOCOMMONCHAN),
target_p->name); target_p->name);
} } else {
else
{
/* check for accept, flag recipient incoming message */ /* check for accept, flag recipient incoming message */
if(p_or_n != NOTICE) if(p_or_n != NOTICE) {
{
sendto_one_numeric(source_p, ERR_TARGUMODEG, sendto_one_numeric(source_p, ERR_TARGUMODEG,
form_str(ERR_TARGUMODEG), form_str(ERR_TARGUMODEG),
target_p->name); target_p->name);
} }
if((target_p->localClient->last_caller_id_time + if((target_p->localClient->last_caller_id_time +
ConfigFileEntry.caller_id_wait) < rb_current_time()) ConfigFileEntry.caller_id_wait) < rb_current_time()) {
{
if(p_or_n != NOTICE) if(p_or_n != NOTICE)
sendto_one_numeric(source_p, RPL_TARGNOTIFY, sendto_one_numeric(source_p, RPL_TARGNOTIFY,
form_str(RPL_TARGNOTIFY), form_str(RPL_TARGNOTIFY),
@ -905,14 +816,11 @@ msg_client(int p_or_n, const char *command,
target_p->localClient->last_caller_id_time = rb_current_time(); target_p->localClient->last_caller_id_time = rb_current_time();
} }
} }
} } else {
else
{
add_reply_target(target_p, source_p); add_reply_target(target_p, source_p);
sendto_anywhere(target_p, source_p, command, ":%s", text); sendto_anywhere(target_p, source_p, command, ":%s", text);
} }
} } else
else
sendto_anywhere(target_p, source_p, command, ":%s", text); sendto_anywhere(target_p, source_p, command, ":%s", text);
return; return;
@ -937,25 +845,20 @@ flood_attack_client(int p_or_n, struct Client *source_p, struct Client *target_p
* and msg user@server. * and msg user@server.
* -- jilles * -- jilles
*/ */
if(GlobalSetOptions.floodcount && IsClient(source_p) && source_p != target_p && !IsService(target_p) && (!IsOper(source_p) || !ConfigFileEntry.true_no_oper_flood)) if(GlobalSetOptions.floodcount && IsClient(source_p) && source_p != target_p && !IsService(target_p) && (!IsOper(source_p) || !ConfigFileEntry.true_no_oper_flood)) {
{ if((target_p->first_received_message_time + 1) < rb_current_time()) {
if((target_p->first_received_message_time + 1) < rb_current_time())
{
delta = rb_current_time() - target_p->first_received_message_time; delta = rb_current_time() - target_p->first_received_message_time;
target_p->received_number_of_privmsgs -= delta; target_p->received_number_of_privmsgs -= delta;
target_p->first_received_message_time = rb_current_time(); target_p->first_received_message_time = rb_current_time();
if(target_p->received_number_of_privmsgs <= 0) if(target_p->received_number_of_privmsgs <= 0) {
{
target_p->received_number_of_privmsgs = 0; target_p->received_number_of_privmsgs = 0;
target_p->flood_noticed = 0; target_p->flood_noticed = 0;
} }
} }
if((target_p->received_number_of_privmsgs >= if((target_p->received_number_of_privmsgs >=
GlobalSetOptions.floodcount) || target_p->flood_noticed) GlobalSetOptions.floodcount) || target_p->flood_noticed) {
{ if(target_p->flood_noticed == 0) {
if(target_p->flood_noticed == 0)
{
sendto_realops_snomask(SNO_BOTS, L_NETWIDE, sendto_realops_snomask(SNO_BOTS, L_NETWIDE,
"Possible Flooder %s[%s@%s] on %s target: %s", "Possible Flooder %s[%s@%s] on %s target: %s",
source_p->name, source_p->username, source_p->name, source_p->username,
@ -974,8 +877,7 @@ flood_attack_client(int p_or_n, struct Client *source_p, struct Client *target_p
":%s NOTICE %s :*** Message to %s throttled due to flooding", ":%s NOTICE %s :*** Message to %s throttled due to flooding",
me.name, source_p->name, target_p->name); me.name, source_p->name, target_p->name);
return 1; return 1;
} } else
else
target_p->received_number_of_privmsgs++; target_p->received_number_of_privmsgs++;
} }
@ -1010,19 +912,15 @@ handle_special(int p_or_n, const char *command, struct Client *client_p,
* NOTE: users can send to user@server, but not user%host@server * NOTE: users can send to user@server, but not user%host@server
* or opers@server * or opers@server
*/ */
if((server = strchr(nick, '@')) != NULL) if((server = strchr(nick, '@')) != NULL) {
{ if((target_p = find_server(source_p, server + 1)) == NULL) {
if((target_p = find_server(source_p, server + 1)) == NULL)
{
sendto_one_numeric(source_p, ERR_NOSUCHSERVER, sendto_one_numeric(source_p, ERR_NOSUCHSERVER,
form_str(ERR_NOSUCHSERVER), server + 1); form_str(ERR_NOSUCHSERVER), server + 1);
return; return;
} }
if(!IsOper(source_p)) if(!IsOper(source_p)) {
{ if(strchr(nick, '%') || (strncmp(nick, "opers", 5) == 0)) {
if(strchr(nick, '%') || (strncmp(nick, "opers", 5) == 0))
{
sendto_one_numeric(source_p, ERR_NOSUCHNICK, sendto_one_numeric(source_p, ERR_NOSUCHNICK,
form_str(ERR_NOSUCHNICK), nick); form_str(ERR_NOSUCHNICK), nick);
return; return;
@ -1030,16 +928,14 @@ handle_special(int p_or_n, const char *command, struct Client *client_p,
} }
/* somewhere else.. */ /* somewhere else.. */
if(!IsMe(target_p)) if(!IsMe(target_p)) {
{
sendto_one(target_p, ":%s %s %s :%s", sendto_one(target_p, ":%s %s %s :%s",
get_id(source_p, target_p), command, nick, text); get_id(source_p, target_p), command, nick, text);
return; return;
} }
/* Check if someones msg'ing opers@our.server */ /* Check if someones msg'ing opers@our.server */
if(strncmp(nick, "opers@", 6) == 0) if(strncmp(nick, "opers@", 6) == 0) {
{
sendto_realops_snomask(SNO_GENERAL, L_ALL, "To opers: From: %s: %s", sendto_realops_snomask(SNO_GENERAL, L_ALL, "To opers: From: %s: %s",
source_p->name, text); source_p->name, text);
return; return;
@ -1062,27 +958,23 @@ handle_special(int p_or_n, const char *command, struct Client *client_p,
* *
* Armin, 8Jun90 (gruner@informatik.tu-muenchen.de) * Armin, 8Jun90 (gruner@informatik.tu-muenchen.de)
*/ */
if(IsOper(source_p) && *nick == '$') if(IsOper(source_p) && *nick == '$') {
{
if((*(nick + 1) == '$' || *(nick + 1) == '#')) if((*(nick + 1) == '$' || *(nick + 1) == '#'))
nick++; nick++;
else if(MyOper(source_p)) else if(MyOper(source_p)) {
{
sendto_one(source_p, sendto_one(source_p,
":%s NOTICE %s :The command %s %s is no longer supported, please use $%s", ":%s NOTICE %s :The command %s %s is no longer supported, please use $%s",
me.name, source_p->name, command, nick, nick); me.name, source_p->name, command, nick, nick);
return; return;
} }
if(MyClient(source_p) && !IsOperMassNotice(source_p)) if(MyClient(source_p) && !IsOperMassNotice(source_p)) {
{
sendto_one(source_p, form_str(ERR_NOPRIVS), sendto_one(source_p, form_str(ERR_NOPRIVS),
me.name, source_p->name, "mass_notice"); me.name, source_p->name, "mass_notice");
return; return;
} }
if((s = strrchr(nick, '.')) == NULL) if((s = strrchr(nick, '.')) == NULL) {
{
sendto_one_numeric(source_p, ERR_NOTOPLEVEL, sendto_one_numeric(source_p, ERR_NOTOPLEVEL,
form_str(ERR_NOTOPLEVEL), nick); form_str(ERR_NOTOPLEVEL), nick);
return; return;
@ -1090,8 +982,7 @@ handle_special(int p_or_n, const char *command, struct Client *client_p,
while(*++s) while(*++s)
if(*s == '.' || *s == '*' || *s == '?') if(*s == '.' || *s == '*' || *s == '?')
break; break;
if(*s == '*' || *s == '?') if(*s == '*' || *s == '?') {
{
sendto_one_numeric(source_p, ERR_WILDTOPLEVEL, sendto_one_numeric(source_p, ERR_WILDTOPLEVEL,
form_str(ERR_WILDTOPLEVEL), nick); form_str(ERR_WILDTOPLEVEL), nick);
return; return;

Some files were not shown because too many files have changed in this diff Show More