Browse Source

* Huge commit that introduces countless bugs I'm sure.
* Now initializing variables when NEEDED, not immediately at the beginning of every function
where the funciton might return before using them
* Added sock_t
* Fixes several misc bugs


svn: 1338

Bryan Drewery 21 years ago
parent
commit
5fecc94dd5
82 changed files with 2421 additions and 2627 deletions
  1. 1 1
      autotools/configure.ac
  2. 6 0
      config.h.in
  3. 3 1
      configure
  4. 1 1
      doc/UPDATES
  5. 8 11
      src/auth.c
  6. 12 14
      src/base64.c
  7. 2 3
      src/bg.c
  8. 9 5
      src/binary.c
  9. 4 5
      src/botcmd.c
  10. 57 76
      src/botmsg.c
  11. 79 90
      src/botnet.c
  12. 1 1
      src/botnet.h
  13. 16 12
      src/cfg.c
  14. 2 1
      src/cfg.h
  15. 13 13
      src/chan.h
  16. 13 19
      src/chanprog.c
  17. 238 245
      src/cmds.c
  18. 32 12
      src/compat/snprintf.c
  19. 0 1
      src/conf.c
  20. 4 2
      src/core_binds.c
  21. 13 17
      src/crypt.c
  22. 2 1
      src/crypt.h
  23. 108 126
      src/dcc.c
  24. 13 13
      src/dcc.h
  25. 35 33
      src/dccutil.c
  26. 3 1
      src/dccutil.h
  27. 12 24
      src/debug.c
  28. 7 7
      src/debug.h
  29. 12 16
      src/dns.c
  30. 7 7
      src/dns.h
  31. 15 11
      src/flags.c
  32. 1 2
      src/garble.c
  33. 33 36
      src/log.c
  34. 2 1
      src/log.h
  35. 32 44
      src/main.c
  36. 3 2
      src/main.h
  37. 10 7
      src/match.c
  38. 63 71
      src/misc.c
  39. 5 5
      src/misc.h
  40. 14 8
      src/misc_file.c
  41. 91 100
      src/mod/channels.mod/channels.c
  42. 15 15
      src/mod/channels.mod/channels.h
  43. 37 25
      src/mod/channels.mod/cmdschan.c
  44. 32 24
      src/mod/channels.mod/tclchan.c
  45. 72 86
      src/mod/channels.mod/userchan.c
  46. 11 9
      src/mod/compress.mod/compress.c
  47. 14 18
      src/mod/console.mod/console.c
  48. 1 1
      src/mod/console.mod/console.h
  49. 13 17
      src/mod/ctcp.mod/ctcp.c
  50. 5 5
      src/mod/dns.mod/coredns.c
  51. 1 1
      src/mod/dns.mod/dns.c
  52. 2 2
      src/mod/dns.mod/dns.h
  53. 210 208
      src/mod/irc.mod/chan.c
  54. 116 109
      src/mod/irc.mod/cmdsirc.c
  55. 124 146
      src/mod/irc.mod/irc.c
  56. 12 11
      src/mod/irc.mod/irc.h
  57. 64 65
      src/mod/irc.mod/mode.c
  58. 12 15
      src/mod/notes.mod/cmdsnote.c
  59. 18 12
      src/mod/notes.mod/notes.c
  60. 2 1
      src/mod/server.mod/cmdsserv.c
  61. 59 54
      src/mod/server.mod/server.c
  62. 9 10
      src/mod/server.mod/server.h
  63. 58 103
      src/mod/server.mod/servmsg.c
  64. 118 138
      src/mod/share.mod/share.c
  65. 23 23
      src/mod/transfer.mod/transfer.c
  66. 6 6
      src/mod/transfer.mod/transfer.h
  67. 13 15
      src/mod/update.mod/update.c
  68. 130 176
      src/net.c
  69. 25 24
      src/net.h
  70. 1 3
      src/response.c
  71. 26 18
      src/shell.c
  72. 2 2
      src/stringfix.c
  73. 2 2
      src/tandem.h
  74. 21 24
      src/tclhash.c
  75. 1 1
      src/thread.c
  76. 8 6
      src/traffic.h
  77. 1 2
      src/types.h
  78. 57 71
      src/userent.c
  79. 63 69
      src/userrec.c
  80. 3 3
      src/userrec.h
  81. 34 44
      src/users.c
  82. 18 18
      src/users.h

+ 1 - 1
autotools/configure.ac

@@ -73,7 +73,7 @@ AC_HEADER_TIME
 AC_HEADER_STAT
 #checkpoint
 AC_CACHE_SAVE 
-AC_CHECK_HEADERS([arpa/inet.h fcntl.h limits.h locale.h netdb.h netinet/in.h])
+AC_CHECK_HEADERS([stdarg.h std_arg.h arpa/inet.h fcntl.h limits.h locale.h netdb.h netinet/in.h])
 AC_CHECK_HEADERS([sys/file.h sys/ioctl.h sys/param.h sys/socket.h wchar.h])
 
 #checkpoint

+ 6 - 0
config.h.in

@@ -120,12 +120,18 @@
    zero-length file name argument. */
 #undef HAVE_STAT_EMPTY_STRING_BUG
 
+/* Define to 1 if you have the <stdarg.h> header file. */
+#undef HAVE_STDARG_H
+
 /* Define to 1 if you have the <stdint.h> header file. */
 #undef HAVE_STDINT_H
 
 /* Define to 1 if you have the <stdlib.h> header file. */
 #undef HAVE_STDLIB_H
 
+/* Define to 1 if you have the <std_arg.h> header file. */
+#undef HAVE_STD_ARG_H
+
 /* Define to 1 if you have the `strcasecmp' function. */
 #undef HAVE_STRCASECMP
 

+ 3 - 1
configure

@@ -5449,7 +5449,9 @@ rm -f confcache
 
 
 
-for ac_header in arpa/inet.h fcntl.h limits.h locale.h netdb.h netinet/in.h
+
+
+for ac_header in stdarg.h std_arg.h arpa/inet.h fcntl.h limits.h locale.h netdb.h netinet/in.h
 do
 as_ac_Header=`echo "ac_cv_header_$ac_header" | $as_tr_sh`
 if eval "test \"\${$as_ac_Header+set}\" = set"; then

+ 1 - 1
doc/UPDATES

@@ -39,7 +39,7 @@ This is a summary of ChangeLog basically.
 * Fixed cmd_comment to work like cmd_whois/match with regards to accessing higher level users.
 * Added proper support for $b/$u 
 * msg_cmd_PASS/cmd_adduser/+user were flawed. Displayed wrong length of ACTUAL set pass
-* cmd_mop wasn't ignoring users without a pass set correctly.
+* closed-private and ban-time were mixed up in the saving/loading process.
 
 1.1.9
 

+ 8 - 11
src/auth.c

@@ -49,11 +49,12 @@ init_auth_max()
 static void
 expire_auths()
 {
-  int i = 0, idle = 0;
-
   if (!ischanhub())
     return;
-  for (i = 0; i < auth_total; i++) {
+
+  time_t idle = 0;
+
+  for (int i = 0; i < auth_total; i++) {
     if (auth[i].authed) {
       idle = now - auth[i].atime;
       if (idle >= (60 * 60)) {
@@ -102,25 +103,21 @@ makebdhash(char *randstring)
 int
 new_auth(void)
 {
-  int i = auth_total;
-
   if (auth_total == max_auth)
     return -1;
 
-  auth_total++;
-  egg_bzero((char *) &auth[i], sizeof(struct auth_t));
-  return i;
+  egg_bzero((struct auth_t *) &auth[auth_total], sizeof(struct auth_t));
+  return auth_total++;
 }
 
 /* returns 0 if not found, -1 if problem, and > 0 if found. */
 int
 findauth(char *host)
 {
-  int i = 0;
-
   if (!host || !host[0])
     return -1;
-  for (i = 0; i < auth_total; i++) {
+
+  for (int i = 0; i < auth_total; i++) {
     if (!auth[i].host) {
       putlog(LOG_MISC, "*", "AUTH ENTRY: %d HAS NO HOST??", i);
       continue;

+ 12 - 14
src/base64.c

@@ -28,9 +28,8 @@ static const char base64r[256] = {
 char *
 b64enc(const unsigned char *data, size_t len)
 {
-  char *dest = NULL;
+  char *dest = (char *) calloc(1, (len << 2) / 3 + 4 + 1);
 
-  dest = (char *) calloc(1, (len << 2) / 3 + 4 + 1);
   b64enc_buf(data, len, dest);
   return (dest);
 }
@@ -38,15 +37,15 @@ b64enc(const unsigned char *data, size_t len)
 void
 b64enc_buf(const unsigned char *data, size_t len, char *dest)
 {
-  size_t i, t;
-
 #define DB(x) ((unsigned char) (x + i < len ? data[x + i] : 0))
-    for (i = 0, t = 0; i < len; i += 3, t += 4) {
-      dest[t] = base64[DB(0) >> 2];
-      dest[t + 1] = base64[((DB(0) & 3) << 4) | (DB(1) >> 4)];
-      dest[t + 2] = base64[((DB(1) & 0x0F) << 2) | (DB(2) >> 6)];
-      dest[t + 3] = base64[(DB(2) & 0x3F)];
-    }
+  register size_t t, i;
+
+  for (i = 0, t = 0; i < len; i += 3, t += 4) {
+    dest[t] = base64[DB(0) >> 2];
+    dest[t + 1] = base64[((DB(0) & 3) << 4) | (DB(1) >> 4)];
+    dest[t + 2] = base64[((DB(1) & 0x0F) << 2) | (DB(2) >> 6)];
+    dest[t + 3] = base64[(DB(2) & 0x3F)];
+  }
 #undef DB
   dest[t] = 0;
 }
@@ -54,9 +53,8 @@ b64enc_buf(const unsigned char *data, size_t len, char *dest)
 char *
 b64dec(const unsigned char *data, size_t *len)
 {
-  char *dest = NULL;
+  char *dest = (char *) calloc(1, ((*len * 3) >> 2) + 6 + 1);
 
-  dest = (char *) calloc(1, ((*len * 3) >> 2) + 6 + 1);
   b64dec_buf(data, len, dest);
   return (dest);
 }
@@ -64,9 +62,9 @@ b64dec(const unsigned char *data, size_t *len)
 void
 b64dec_buf(const unsigned char *data, size_t *len, char *dest)
 {
-  size_t t, i;
-
 #define DB(x) ((unsigned char) (x + i < *len ? base64r[(unsigned char) data[x + i]] : 0))
+  register size_t t, i;
+
   for (i = 0, t = 0; i < *len; i += 4, t += 3) {
     dest[t] = (DB(0) << 2) + (DB(1) >> 4);
     dest[t + 1] = ((DB(1) & 0x0F) << 4) + (DB(2) >> 2);

+ 2 - 3
src/bg.c

@@ -29,12 +29,11 @@ static void init_watcher(pid_t);
 pid_t
 do_fork()
 {
-  pid_t pid = 0;
-
   if (daemon(1, 1))
     fatal(strerror(errno), 0);
 
-  pid = getpid();
+  pid_t pid = getpid();
+
   writepid(conf.bot->pid_file, pid);
   lastfork = now;
 #ifndef CYGWIN_HACKS

+ 9 - 5
src/binary.c

@@ -67,9 +67,9 @@ bin_md5(const char *fname, int todo, MD5_CTX * ctx)
   OPENSSL_cleanse(&ctx, sizeof(ctx));
 
   if (todo == WRITE_MD5) {
+    Tempfile *newbin = new Tempfile("bin");
     char *fname_bak = NULL;
     size_t size = 0, i = 0;
-    Tempfile *newbin = new Tempfile("bin");
 
     size = strlen(fname) + 2;
     fname_bak = (char *) calloc(1, size);
@@ -131,14 +131,15 @@ static int
 readcfg(const char *cfgfile)
 {
   FILE *f = NULL;
-  char *buffer = NULL, *p = NULL;
-  int skip = 0, line = 0;
 
-  f = fopen(cfgfile, "r");
-  if (!f) {
+  if ((f = fopen(cfgfile, "r")) == NULL) {
     printf("Error: Can't open '%s' for reading\n", cfgfile);
     exit(1);
   }
+
+  char *buffer = NULL, *p = NULL;
+  int skip = 0, line = 0;
+
   printf("Reading '%s' ", cfgfile);
   while ((!feof(f)) && ((buffer = step_thru_file(f)) != NULL)) {
     line++;
@@ -243,7 +244,9 @@ static void edpack(settings_t *incfg, const char *hash, int what)
   dofield(incfg->owneremail);
   dofield(incfg->hubs);
   /* -- DYNAMIC -- */
+//printf("BOTS: %s\n", incfg->bots);
   dofield(incfg->bots);
+//printf("EBOTS: %s\n", incfg->bots);
   dofield(incfg->uid);
   dofield(incfg->autouname);
   dofield(incfg->pscloak);
@@ -304,6 +307,7 @@ check_sum(const char *fname, const char *cfgfile)
       fatal("Binary not initialized.", 0);
 
     readcfg(cfgfile);
+
 /* tellconfig(&settings); */
     if (bin_md5(fname, WRITE_MD5, &ctx))
       printf("* Wrote settings to binary.\n"); 

+ 4 - 5
src/botcmd.c

@@ -60,9 +60,9 @@ int base64_to_int(char *buf)
 
 static void fake_alert(int idx, char *item, char *extra)
 {
-  static unsigned long lastfake;	/* The last time fake_alert was used */
+  static time_t lastfake;	/* The last time fake_alert was used */
 
-  if (now - lastfake > 10) {	
+  if ((now - lastfake) > 10) {	
     /* Don't fake_alert more than once every 10secs */
     dprintf(idx, "ct %s NOTICE: %s (%s != %s).\n", conf.bot->nick, NET_FAKEREJECT, item, extra);
     putlog(LOG_BOTS, "*", "%s %s (%s != %s).", dcc[idx].nick, NET_FAKEREJECT, item, extra);
@@ -121,9 +121,8 @@ static void bot_chan2(int idx, char *msg)
 
 void bot_cmdpass(int idx, char *par)
 {
-  char *p = NULL;
+  char *p = strchr(par, ' ');
 
-  p = strchr(par, ' ');
   if (p) {
     *p++ = 0;
     botnet_send_cmdpass(idx, par, p);
@@ -1202,7 +1201,7 @@ void send_remote_simul(int idx, char *bot, char *cmd, char *par)
 {
   char msg[SGRAB - 110] = "";
 
-  egg_snprintf(msg, sizeof msg, "r-s %d %s %d %s %lu %s %s", idx, dcc[idx].nick, dcc[idx].u.chat->con_flags, 
+  egg_snprintf(msg, sizeof msg, "r-s %d %s %d %s %zu %s %s", idx, dcc[idx].nick, dcc[idx].u.chat->con_flags, 
                dcc[idx].u.chat->con_chan, dcc[idx].status, cmd, par);
   putbot(bot, msg);
 }

+ 57 - 76
src/botmsg.c

@@ -42,32 +42,37 @@ static char tobase64array[64] =
 char *int_to_base64(unsigned int val)
 {
   static char buf_base64[12] = "";
-  int i = 11;
 
   buf_base64[11] = 0;
   if (!val) {
     buf_base64[10] = 'A';
     return buf_base64 + 10;
   }
+
+  int i = 11;
+
   while (val) {
     i--;
     buf_base64[i] = tobase64array[val & 0x3f];
     val = val >> 6;
   }
+
   return buf_base64 + i;
 }
 
 char *int_to_base10(int val)
 {
   static char buf_base10[17] = "";
-  int p = 0;
-  int i = 16;
 
   buf_base10[16] = 0;
   if (!val) {
     buf_base10[15] = '0';
     return buf_base10 + 15;
   }
+
+  int p = 0;
+  int i = 16;
+
   if (val < 0) {
     p = 1;
     val *= -1;
@@ -87,13 +92,15 @@ char *int_to_base10(int val)
 char *unsigned_int_to_base10(unsigned int val)
 {
   static char buf_base10[16] = "";
-  int i = 15;
 
   buf_base10[15] = 0;
   if (!val) {
     buf_base10[14] = '0';
     return buf_base10 + 14;
   }
+
+  int i = 15;
+
   while (val) {
     i--;
     buf_base10[i] = '0' + (val % 10);
@@ -158,9 +165,7 @@ size_t simple_sprintf (char *buf, const char *format, ...)
  */
 static void send_tand_but(int x, char *buf, size_t len)
 {
-  int i;
-
-  for (i = 0; i < dcc_total; i++) {
+  for (int i = 0; i < dcc_total; i++) {
     if ((dcc[i].type == &DCC_BOT) && i != x) {
       tputs(dcc[i].sock, buf, len);
     }
@@ -170,9 +175,8 @@ static void send_tand_but(int x, char *buf, size_t len)
 void botnet_send_cmdpass(int idx, char *cmd, char *pass)
 {
   if (tands > 0) {
-    char *buf = NULL;
+    char *buf = (char *) calloc(1, strlen(cmd) + strlen(pass) + 5 + 1);
 
-    buf = (char *) calloc(1, strlen(cmd) + strlen(pass) + 5 + 1);
     sprintf(buf, "cp %s %s\n", cmd, pass);
     send_tand_but(idx, buf, strlen(buf));
     free(buf);
@@ -210,7 +214,8 @@ void botnet_send_cmd_broad(int idx, char * fbot, int fromidx, char * cmd) {
 
 void botnet_send_cmdreply(char * fbot, char * bot, char * to, char * toidx, char * ln) {
   int i = nextbot(bot);
-  if (i>=0) {
+
+  if (i >= 0) {
     egg_snprintf(OBUF, sizeof OBUF, "rr %s %s %s %s %s\n", bot, fbot, to, toidx, ln);
     tputs(dcc[i].sock, OBUF, strlen(OBUF));
   } else if (!strcmp(bot, conf.bot->nick)) {
@@ -227,9 +232,9 @@ void botnet_send_bye()
 
 void botnet_send_chan(int idx, char *botnick, char *user, int chan, char *data)
 {
-  size_t len;
-
   if ((tands > 0) && (chan < GLOBAL_CHANS)) {
+    size_t len;
+
     if (user) {
       len = simple_sprintf(OBUF, "c %s@%s %D %s\n", user, botnick, chan, data);
     } else {
@@ -241,9 +246,9 @@ void botnet_send_chan(int idx, char *botnick, char *user, int chan, char *data)
 
 void botnet_send_act(int idx, char *botnick, char *user, int chan, char *data)
 {
-  size_t len;
-
   if ((tands > 0) && (chan < GLOBAL_CHANS)) {
+    size_t len;
+
     if (user) {
       len = simple_sprintf(OBUF, "a %s@%s %D %s\n", user, botnick, chan, data);
     } else {
@@ -255,10 +260,9 @@ void botnet_send_act(int idx, char *botnick, char *user, int chan, char *data)
 
 void botnet_send_chat(int idx, char *botnick, char *data)
 {
-  size_t len;
-
   if (tands > 0) {
-    len = simple_sprintf(OBUF, "ct %s %s\n", botnick, data);
+    size_t len = simple_sprintf(OBUF, "ct %s %s\n", botnick, data);
+
     send_tand_but(idx, OBUF, len);
   }
 }
@@ -295,71 +299,62 @@ void botnet_send_priv (int idx, char *from, char *to, char *tobot, char *format,
 
 void botnet_send_who(int idx, char *from, char *to, int chan)
 {
-  size_t len;
+  size_t len = simple_sprintf(OBUF, "w %s %s %D\n", from, to, chan);
 
-  len = simple_sprintf(OBUF, "w %s %s %D\n", from, to, chan);
   tputs(dcc[idx].sock, OBUF, len);
 }
 
 void botnet_send_unlink(int idx, char *who, char *via, char *bot, char *reason)
 {
-  size_t len;
+  size_t len = simple_sprintf(OBUF, "ul %s %s %s %s\n", who, via, bot, reason);
 
-  len = simple_sprintf(OBUF, "ul %s %s %s %s\n", who, via, bot, reason);
   tputs(dcc[idx].sock, OBUF, len);
 }
 
 void botnet_send_link(int idx, char *who, char *via, char *bot)
 {
-  size_t len;
+  size_t len = simple_sprintf(OBUF, "l %s %s %s\n", who, via, bot);
 
-  len = simple_sprintf(OBUF, "l %s %s %s\n", who, via, bot);
   tputs(dcc[idx].sock, OBUF, len);
 }
 
 void botnet_send_unlinked(int idx, char *bot, char *args)
 {
-  size_t len;
-
   if (tands > 0) {
-    len = simple_sprintf(OBUF, "un %s %s\n", bot, args ? args : "");
+    size_t len = simple_sprintf(OBUF, "un %s %s\n", bot, args ? args : "");
+
     send_tand_but(idx, OBUF, len);
   }
 }
 
 void botnet_send_nlinked(int idx, char *bot, char *next, char flag, int vlocalhub, time_t vbuildts, char *vversion)
 {
-  size_t len;
-
   if (tands > 0) {
-    len = simple_sprintf(OBUF, "n %s %s %cD0gc %d %d %s\n", bot, next, flag, vlocalhub, vbuildts, vversion ? vversion : "");
+    size_t len = simple_sprintf(OBUF, "n %s %s %cD0gc %d %d %s\n", bot, next, flag, 
+                                       vlocalhub, vbuildts, vversion ? vversion : "");
     send_tand_but(idx, OBUF, len);
   }
 }
 
 void botnet_send_traced(int idx, char *bot, char *buf)
 {
-  size_t len;
+  size_t len = simple_sprintf(OBUF, "td %s %s\n", bot, buf);
 
-  len = simple_sprintf(OBUF, "td %s %s\n", bot, buf);
   tputs(dcc[idx].sock, OBUF, len);
 }
 
 void botnet_send_trace(int idx, char *to, char *from, char *buf)
 {
-  size_t len;
+  size_t len = simple_sprintf(OBUF, "t %s %s %s:%s\n", to, from, buf, conf.bot->nick);
 
-  len = simple_sprintf(OBUF, "t %s %s %s:%s\n", to, from, buf, conf.bot->nick);
   tputs(dcc[idx].sock, OBUF, len);
 }
 
 void botnet_send_update(int idx, tand_t * ptr)
 {
-  size_t len;
-
   if (tands > 0) {
     /* the D0gc is a lingering hack which probably will never be able to come out. */
-    len = simple_sprintf(OBUF, "u %s %cD0gc %d %d %s\n", ptr->bot, ptr->share, ptr->localhub, 
+    size_t len = simple_sprintf(OBUF, "u %s %cD0gc %d %d %s\n", ptr->bot, ptr->share, ptr->localhub, 
                                                           ptr->buildts, ptr->version ? ptr->version : "");
     send_tand_but(idx, OBUF, len);
   }
@@ -393,140 +388,126 @@ void putallbots(char *par)
 
 void putbot(char *bot, char *par)
 {
-  int i;
-  char msg[SGRAB - 110] = "";
-
   if (!bot || !par || !bot[0] || !par[0])
     return;
-  i = nextbot(bot);
+
+  int i = nextbot(bot);
+
   if (i < 0)
     return;
-  strncpyz(msg, par, sizeof msg);
-  botnet_send_zapf(i, conf.bot->nick, bot, msg);
+
+  botnet_send_zapf(i, conf.bot->nick, bot, par);
 }
 
 void botnet_send_zapf(int idx, char *a, char *b, char *c)
 {
-  size_t len;
+  size_t len = simple_sprintf(OBUF, "z %s %s %s\n", a, b, c);
 
-  len = simple_sprintf(OBUF, "z %s %s %s\n", a, b, c);
   tputs(dcc[idx].sock, OBUF, len);
 }
 
 void botnet_send_zapf_broad(int idx, char *a, char *b, char *c)
 {
-  size_t len;
-
   if (tands > 0) {
-    len = simple_sprintf(OBUF, "zb %s %s%s%s\n", a, b ? b : "", b ? " " : "", c);
+    size_t len = simple_sprintf(OBUF, "zb %s %s%s%s\n", a, b ? b : "", b ? " " : "", c);
     send_tand_but(idx, OBUF, len);
   }
 }
 
 void botnet_send_cfg(int idx, struct cfg_entry * entry) {
-  size_t len;
+  size_t len = simple_sprintf(OBUF, "cg %s %s\n", entry->name, entry->gdata ? entry->gdata : "");
 
-  len = simple_sprintf(OBUF, "cg %s %s\n", entry->name, entry->gdata ? entry->gdata : "");
   tputs(dcc[idx].sock, OBUF, len);
 }
 
 void botnet_send_cfg_broad(int idx, struct cfg_entry * entry) {
-  size_t len;
-
   if (tands > 0) {
-    len = simple_sprintf(OBUF, "cgb %s %s\n", entry->name, entry->gdata ? entry->gdata : "");
+    size_t len = simple_sprintf(OBUF, "cgb %s %s\n", entry->name, entry->gdata ? entry->gdata : "");
+
     send_tand_but(idx, OBUF, len);
   }
 }
 
 void botnet_send_idle(int idx, char *bot, int sock, int idle, char *away)
 {
-  size_t len;
-
   if (tands > 0) {
-    len = simple_sprintf(OBUF, "i %s %D %D %s\n", bot, sock, idle, away ? away : "");
+    size_t len = simple_sprintf(OBUF, "i %s %D %D %s\n", bot, sock, idle, away ? away : "");
+
     send_tand_but(idx, OBUF, len);
   }
 }
 
 void botnet_send_away(int idx, char *bot, int sock, char *msg, int linking)
 {
-  size_t len;
-
   if (tands > 0) {
-    len = simple_sprintf(OBUF, "aw %s%s %D %s\n", ((idx >= 0) && linking) ? "!" : "", bot, sock, msg ? msg : "");
+    size_t len = simple_sprintf(OBUF, "aw %s%s %D %s\n", ((idx >= 0) && linking) ? "!" : "", bot, sock, msg ? msg : "");
+
     send_tand_but(idx, OBUF, len);
   }
 }
 
 void botnet_send_join_idx(int useridx)
 {
-  size_t len;
-
   if (tands > 0) {
-    len = simple_sprintf(OBUF, "j %s %s %D %c%D %s\n",
+    size_t len = simple_sprintf(OBUF, "j %s %s %D %c%D %s\n",
 		       conf.bot->nick, dcc[useridx].nick,
 		       dcc[useridx].u.chat->channel, geticon(useridx),
 		       dcc[useridx].sock, dcc[useridx].host);
+
     send_tand_but(-1, OBUF, len);
   }
 }
 
 void botnet_send_join_party(int idx, int linking, int useridx)
 {
-  size_t len;
-
   if (tands > 0) {
-    len = simple_sprintf(OBUF, "j %s%s %s %D %c%D %s\n", linking ? "!" : "",
+    size_t len = simple_sprintf(OBUF, "j %s%s %s %D %c%D %s\n", linking ? "!" : "",
 		       party[useridx].bot, party[useridx].nick,
 		       party[useridx].chan, party[useridx].flag,
 		       party[useridx].sock,
 		       party[useridx].from ? party[useridx].from : "");
+
     send_tand_but(idx, OBUF, len);
   }
 }
 
 void botnet_send_part_idx(int useridx, char *reason)
 {
-  size_t len;
-
   if (tands > 0) {
-    len = simple_sprintf(OBUF, "pt %s %s %D %s\n", conf.bot->nick,
+    size_t len = simple_sprintf(OBUF, "pt %s %s %D %s\n", conf.bot->nick,
 			 dcc[useridx].nick, dcc[useridx].sock,
 			 reason ? reason : "");
+
     send_tand_but(-1, OBUF, len);
   }
 }
 
 void botnet_send_part_party(int idx, int partyidx, char *reason, int silent)
 {
-  size_t len;
-
   if (tands > 0) {
-    len = simple_sprintf(OBUF, "pt %s%s %s %D %s\n",
+    size_t len = simple_sprintf(OBUF, "pt %s%s %s %D %s\n",
 		       silent ? "!" : "", party[partyidx].bot,
 		       party[partyidx].nick, party[partyidx].sock,
 		       reason ? reason : "");
+
     send_tand_but(idx, OBUF, len);
   }
 }
 
 void botnet_send_nkch(int useridx, char *oldnick)
 {
-  size_t len;
-
   if (tands > 0) {
-    len = simple_sprintf(OBUF, "nc %s %D %s\n", conf.bot->nick, dcc[useridx].sock, dcc[useridx].nick);
+    size_t len = simple_sprintf(OBUF, "nc %s %D %s\n", conf.bot->nick, dcc[useridx].sock, dcc[useridx].nick);
+
     send_tand_but(-1, OBUF, len);
   }
 }
 
 void botnet_send_nkch_part(int butidx, int useridx, char *oldnick)
 {
-  size_t len;
-
   if (tands > 0) {
-    len = simple_sprintf(OBUF, "nc %s %D %s\n", party[useridx].bot, party[useridx].sock, party[useridx].nick);
+    size_t len = simple_sprintf(OBUF, "nc %s %D %s\n", party[useridx].bot, party[useridx].sock, party[useridx].nick);
+
     send_tand_but(butidx, OBUF, len);
   }
 }

+ 79 - 90
src/botnet.c

@@ -172,9 +172,7 @@ int addparty(char *bot, char *nick, int chan, char flag, int sock,
  */
 void partystat(char *bot, int sock, int add, int rem)
 {
-  int i;
-
-  for (i = 0; i < parties; i++) {
+  for (int i = 0; i < parties; i++) {
     if ((!egg_strcasecmp(party[i].bot, bot)) &&
 	(party[i].sock == sock)) {
       party[i].status |= add;
@@ -187,9 +185,7 @@ void partystat(char *bot, int sock, int add, int rem)
  */
 void partysetidle(char *bot, int sock, int secs)
 {
-  int i;
-
-  for (i = 0; i < parties; i++) {
+  for (int i = 0; i < parties; i++) {
     if ((!egg_strcasecmp(party[i].bot, bot)) &&
 	(party[i].sock == sock)) {
       party[i].timer = (now - (time_t) secs);
@@ -201,9 +197,7 @@ void partysetidle(char *bot, int sock, int secs)
  */
 int getparty(char *bot, int sock)
 {
-  int i;
-
-  for (i = 0; i < parties; i++) {
+  for (int i = 0; i < parties; i++) {
     if (!egg_strcasecmp(party[i].bot, bot) &&
 	(party[i].sock == sock)) {
       return i;
@@ -214,13 +208,12 @@ int getparty(char *bot, int sock)
 
 /* Un-idle someone
  */
-int partyidle(char *bot, char *nick)
+bool partyidle(char *bot, char *nick)
 {
-  int i, ok = 0;
+  bool ok = 0;
 
-  for (i = 0; i < parties; i++) {
-    if ((!egg_strcasecmp(party[i].bot, bot)) &&
-	(!egg_strcasecmp(party[i].nick, nick))) {
+  for (int i = 0; i < parties; i++) {
+    if ((!egg_strcasecmp(party[i].bot, bot)) && (!egg_strcasecmp(party[i].nick, nick))) {
       party[i].timer = now;
       ok = 1;
     }
@@ -233,9 +226,8 @@ int partyidle(char *bot, char *nick)
 int partynick(char *bot, int sock, char *nick)
 {
   char work[HANDLEN + 1] = "";
-  int i;
 
-  for (i = 0; i < parties; i++) {
+  for (int i = 0; i < parties; i++) {
     if (!egg_strcasecmp(party[i].bot, bot) && (party[i].sock == sock)) {
       strcpy(work, party[i].nick);
       strncpy(party[i].nick, nick, HANDLEN);
@@ -251,9 +243,7 @@ int partynick(char *bot, int sock, char *nick)
  */
 void partyaway(char *bot, int sock, char *msg)
 {
-  int i;
-
-  for (i = 0; i < parties; i++) {
+  for (int i = 0; i < parties; i++) {
     if ((!egg_strcasecmp(party[i].bot, bot)) &&
 	(party[i].sock == sock)) {
       if (party[i].away)
@@ -271,7 +261,6 @@ void partyaway(char *bot, int sock, char *msg)
 void rembot(const char *whoin)
 {
   tand_t **ptr = &tandbot, *ptr2 = NULL;
-  struct userrec *u = NULL;
   char *who = strdup(whoin);
 
   while (*ptr) {
@@ -283,8 +272,9 @@ void rembot(const char *whoin)
     /* May have just .unlink *'d */
     return;
 
-  u = get_user_by_handle(userlist, (char *) who);
-  if (u != NULL)
+  struct userrec *u = get_user_by_handle(userlist, (char *) who);
+
+  if (u)
     touch_laston(u, "unlinked", now);
 
   ptr2 = *ptr;
@@ -298,9 +288,7 @@ void rembot(const char *whoin)
 
 void remparty(char *bot, int sock)
 {
-  int i;
-
-  for (i = 0; i < parties; i++)
+  for (int i = 0; i < parties; i++)
     if ((!egg_strcasecmp(party[i].bot, bot)) &&
 	(party[i].sock == sock)) {
       parties--;
@@ -326,9 +314,7 @@ void remparty(char *bot, int sock)
  */
 void rempartybot(char *bot)
 {
-  int i;
-
-  for (i = 0; i < parties; i++)
+  for (int i = 0; i < parties; i++)
     if (!egg_strcasecmp(party[i].bot, bot)) {
       remparty(bot, party[i].sock);
       i--;
@@ -339,10 +325,11 @@ void rempartybot(char *bot)
  */
 void unvia(int idx, tand_t *who)
 {
-  tand_t *bot = NULL, *bot2 = NULL;
-
   if (!who)
     return;			/* Safety */
+
+  tand_t *bot = NULL, *bot2 = NULL;
+
   rempartybot(who->bot);
   bot = tandbot;
   while (bot) {
@@ -384,16 +371,16 @@ void besthub(char *hub)
  */
 int nextbot(char *who)
 {
-  int j;
   tand_t *bot = findbot(who);
 
   if (!bot)
     return -1;
 
-  for (j = 0; j < dcc_total; j++)
-    if (bot->via && !egg_strcasecmp(bot->via->bot, dcc[j].nick) &&
-	(dcc[j].type == &DCC_BOT))
+  for (int j = 0; j < dcc_total; j++) {
+    if (bot->via && !egg_strcasecmp(bot->via->bot, dcc[j].nick) && (dcc[j].type == &DCC_BOT))
       return j;
+  }
+
   return -1;			/* We're not connected to 'via' */
 }
 
@@ -419,12 +406,10 @@ void answer_local_whom(int idx, int chan)
   int i, t, nicklen, botnicklen, total = 0;
 
   if (chan == (-1))
-    dprintf(idx, "%s (+: %s, *: %s)\n", BOT_BOTNETUSERS, BOT_PARTYLINE,
-	    BOT_LOCALCHAN);
-  else if (chan > 0) {
-      dprintf(idx, "%s %s%d:\n", BOT_USERSONCHAN,
-	      (chan < GLOBAL_CHANS) ? "" : "*", chan % GLOBAL_CHANS);
-  }
+    dprintf(idx, "%s (+: %s, *: %s)\n", BOT_BOTNETUSERS, BOT_PARTYLINE, BOT_LOCALCHAN);
+  else if (chan > 0)
+    dprintf(idx, "%s %s%d:\n", BOT_USERSONCHAN, (chan < GLOBAL_CHANS) ? "" : "*", chan % GLOBAL_CHANS);
+
   /* Find longest nick and botnick */
   nicklen = botnicklen = 0;
   for (i = 0; i < dcc_total; i++)
@@ -572,17 +557,17 @@ tell_bots(int idx, int up)
  */
 void tell_bottree(int idx)
 {
+  if (tands == 0) {
+    dprintf(idx, "%s\n", BOT_NOBOTSLINKED);
+    return;
+  }
+
   char s[161] = "", work[1024] = "";
   tand_t *last[20] = { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
                        NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL};
   tand_t *thisbot = NULL, *bot = NULL, *bot2 = NULL;
   int lev = 0, more = 1, mark[20], ok, cnt, i = 0, imark, tothops = 0;
 
-  if (tands == 0) {
-    dprintf(idx, "%s\n", BOT_NOBOTSLINKED);
-    return;
-  }
-
   for (bot = tandbot; bot; bot = bot->next)
     if (!bot->uplink) {
       if (i) {
@@ -726,17 +711,17 @@ void dump_links(int z)
   char x[1024] = "";
 #ifdef HUB
   tand_t *bot = NULL;
+  char *p = NULL;
 
   for (bot = tandbot; bot; bot = bot->next) {
-    char *p = NULL;
-
     if (bot->uplink == (tand_t *) 1)
       p = conf.bot->nick;
     else
       p = bot->uplink->bot;
+
     l = simple_sprintf(x, "n %s %s %cD0gc %d %d %s\n", bot->bot, p, bot->share, bot->localhub, 
                                                         bot->buildts, bot->version ? bot->version : "");
-     tputs(dcc[z].sock, x, l);
+    tputs(dcc[z].sock, x, l);
   }
 #endif /* HUB */
 
@@ -772,11 +757,12 @@ int in_chain(char *who)
 
 int bots_in_subtree(tand_t *bot)
 {
+  if (!bot)
+    return 0;
+
   int nr = 1;
   tand_t *b = NULL;
 
-  if (!bot)
-    return 0;
   for (b = tandbot; b; b = b->next) {
     if (b->bot && (b->uplink == bot)) {
       nr += bots_in_subtree(b);
@@ -787,12 +773,12 @@ int bots_in_subtree(tand_t *bot)
 
 int users_in_subtree(tand_t *bot)
 {
-  int i, nr;
-  tand_t *b = NULL;
-
-  nr = 0;
   if (!bot)
     return 0;
+
+  int i, nr = 0;
+  tand_t *b = NULL;
+
   for (i = 0; i < parties; i++)
     if (!egg_strcasecmp(party[i].bot, bot->bot))
       nr++;
@@ -909,11 +895,8 @@ static void botlink_resolve_failure(int);
  */
 int botlink(char *linker, int idx, char *nick)
 {
-  struct bot_addr *bi = NULL;
-  struct userrec *u = NULL;
-  register int i;
+  struct userrec *u = get_user_by_handle(userlist, nick);
 
-  u = get_user_by_handle(userlist, nick);
   if (!u || !u->bot) {
     if (idx >= 0)
       dprintf(idx, "%s %s\n", nick, BOT_BOTUNKNOWN);
@@ -924,6 +907,8 @@ int botlink(char *linker, int idx, char *nick)
     if (idx >= 0)
       dprintf(idx, "%s\n", BOT_ALREADYLINKED);
   } else {
+    register int i;
+
     for (i = 0; i < dcc_total; i++)
       if ((dcc[i].user == u) &&
 	  ((dcc[i].type == &DCC_FORK_BOT) ||
@@ -933,7 +918,8 @@ int botlink(char *linker, int idx, char *nick)
 	return 0;
       }
     /* Address to connect to is in 'info' */
-    bi = (struct bot_addr *) get_user(&USERENTRY_BOTADDR, u);
+    struct bot_addr *bi = (struct bot_addr *) get_user(&USERENTRY_BOTADDR, u);
+
     if (!bi || !strlen(bi->address) || !bi->telnet_port || (bi->telnet_port <= 0)) {
       if (idx >= 0) {
 	dprintf(idx, "%s '%s'.\n", BOT_NOTELNETADDY, nick);
@@ -1081,11 +1067,8 @@ static void tandem_relay_resolve_success(int);
  */
 void tandem_relay(int idx, char *nick, register int i)
 {
-  struct userrec *u = NULL;
-  struct bot_addr *bi = NULL;
-  struct chat_info *ci = NULL;
+  struct userrec *u = get_user_by_handle(userlist, nick);
 
-  u = get_user_by_handle(userlist, nick);
   if (!u || !u->bot) {
     dprintf(idx, "%s %s\n", nick, BOT_BOTUNKNOWN);
     return;
@@ -1094,8 +1077,10 @@ void tandem_relay(int idx, char *nick, register int i)
     dprintf(idx, "%s\n", BOT_CANTRELAYMYSELF);
     return;
   }
+
   /* Address to connect to is in 'info' */
-  bi = (struct bot_addr *) get_user(&USERENTRY_BOTADDR, u);
+  struct bot_addr *bi = (struct bot_addr *) get_user(&USERENTRY_BOTADDR, u);
+
   if (!bi || !strlen(bi->address) || !bi->relay_port || (bi->relay_port <= 0)) {
     dprintf(idx, "%s '%s'.\n", BOT_NOTELNETADDY, nick);
     dprintf(idx, "%s .chaddr %s %s\n",
@@ -1131,7 +1116,9 @@ void tandem_relay(int idx, char *nick, register int i)
 #endif /* HUB */
   dprintf(idx, "%s\n", BOT_BYEINFO1);
   dcc[idx].type = &DCC_PRE_RELAY;
-  ci = dcc[idx].u.chat;
+
+  struct chat_info *ci = dcc[idx].u.chat;
+
   dcc[idx].u.relay = (struct relay_info *) calloc(1, sizeof(struct relay_info));
   dcc[idx].u.relay->chat = ci;
   dcc[idx].u.relay->old_status = dcc[idx].status;
@@ -1154,7 +1141,6 @@ void tandem_relay(int idx, char *nick, register int i)
 
 static void tandem_relay_resolve_failure(int idx)
 {
-  struct chat_info *ci = NULL;
   register int uidx = (-1), i;
 
   for (i = 0; i < dcc_total; i++)
@@ -1170,7 +1156,9 @@ static void tandem_relay_resolve_failure(int idx)
     lostdcc(idx);
     return;
   }
-  ci = dcc[uidx].u.relay->chat;
+
+  struct chat_info *ci = dcc[uidx].u.relay->chat;
+
   dprintf(uidx, "%s %s.\n", BOT_CANTLINKTO, dcc[idx].nick);
   dcc[uidx].status = dcc[uidx].u.relay->old_status;
   free(dcc[uidx].u.relay);
@@ -1209,9 +1197,9 @@ static void tandem_relay_resolve_success(int i)
 
 /* Input from user before connect is ready
  */
-static void pre_relay(int idx, char *buf, register int i)
+static void pre_relay(int idx, char *buf, register size_t len)
 {
-  register int tidx = (-1);
+  register int tidx = (-1), i;
 
   for (i = 0; i < dcc_total; i++)
     if ((dcc[i].type == &DCC_FORK_RELAY) &&
@@ -1300,10 +1288,9 @@ static void failed_pre_relay(int idx)
   lostdcc(idx);
 }
 
-static void cont_tandem_relay(int idx, char *buf, register int i)
+static void cont_tandem_relay(int idx, char *buf, register size_t len)
 {
-  register int uidx = (-1);
-  struct relay_info *ri = NULL;
+  register int uidx = (-1), i;
 
   for (i = 0; i < dcc_total; i++)
     if ((dcc[i].type == &DCC_PRE_RELAY) &&
@@ -1323,7 +1310,9 @@ static void cont_tandem_relay(int idx, char *buf, register int i)
   dprintf(uidx, "%s\n\n", BOT_BYEINFO2);
   putlog(LOG_MISC, "*", "%s %s -> %s", BOT_RELAYLINK,
 	 dcc[uidx].nick, dcc[idx].nick);
-  ri = dcc[uidx].u.relay;	/* YEAH */
+
+  struct relay_info *ri = dcc[uidx].u.relay;	/* YEAH */
+
   dcc[uidx].type = &DCC_CHAT;
   dcc[uidx].u.chat = ri->chat;
   if (dcc[uidx].u.chat->channel >= 0) {
@@ -1340,7 +1329,6 @@ static void cont_tandem_relay(int idx, char *buf, register int i)
 static void eof_dcc_relay(int idx)
 {
   register int j;
-  struct chat_info *ci = NULL;
 
   for (j = 0; j < dcc_total; j++)
     if (dcc[j].sock == dcc[idx].u.relay->sock)
@@ -1357,7 +1345,9 @@ static void eof_dcc_relay(int idx)
   putlog(LOG_MISC, "*", "%s: %s -> %s", BOT_ENDRELAY1, dcc[j].nick,
 	 dcc[idx].nick);
   dprintf(j, "\n\n*** %s %s\n", BOT_ENDRELAY2, conf.bot->nick);
-  ci = dcc[j].u.relay->chat;
+
+  struct chat_info *ci = dcc[j].u.relay->chat;
+
   free(dcc[j].u.relay);
   dcc[j].u.chat = ci;
   dcc[j].type = &DCC_CHAT;
@@ -1386,7 +1376,7 @@ static void eof_dcc_relaying(int idx)
   lostdcc(j);			/* Drop connection to the bot */
 }
 
-static void dcc_relay(int idx, char *buf, int j)
+static void dcc_relay(int idx, char *buf, size_t j)
 {
   unsigned char *p = (unsigned char *) buf;
   int mark;
@@ -1425,10 +1415,8 @@ static void dcc_relay(int idx, char *buf, int j)
     dprintf(-dcc[idx].u.relay->sock, "%s\r\n", buf);
 }
 
-static void dcc_relaying(int idx, char *buf, int j)
+static void dcc_relaying(int idx, char *buf, size_t j)
 {
-  struct chat_info *ci = NULL;
-
   if (egg_strcasecmp(buf, "*bye*")) {
     dprintf(-dcc[idx].u.relay->sock, "%s\n", buf);
     return;
@@ -1449,7 +1437,9 @@ static void dcc_relaying(int idx, char *buf, int j)
     if (dcc[idx].u.relay->chat->channel < GLOBAL_CHANS)
       botnet_send_join_idx(idx);
   }
-  ci = dcc[idx].u.relay->chat;
+
+  struct chat_info *ci = dcc[idx].u.relay->chat;
+
   free(dcc[idx].u.relay);
   dcc[idx].u.chat = ci;
   dcc[idx].type = &DCC_CHAT;
@@ -1625,12 +1615,9 @@ void check_botnet_pings()
 void zapfbot(int idx)
 {
   char s[1024] = "";
-  int bots, users;
-  tand_t *bot = NULL;
+  tand_t *bot = findbot(dcc[idx].nick);
+  int bots = bots_in_subtree(bot), users = users_in_subtree(bot);
 
-  bot = findbot(dcc[idx].nick);
-  bots = bots_in_subtree(bot);
-  users = users_in_subtree(bot);
   simple_sprintf(s, "%s: %s (lost %d bot%s and %d user%s)", BOT_BOTDROPPED,
   		 dcc[idx].nick, bots, (bots != 1) ? "s" : "", users,
 		 (users != 1) ? "s" : "");
@@ -1642,16 +1629,18 @@ void zapfbot(int idx)
 
 static int get_role(char *bot)
 {
-  int rl, i;
-  struct bot_addr *ba = NULL;
-  int r[5] = { 0, 0, 0, 0, 0 };
-  struct userrec *u = NULL, *u2 = NULL;
+  struct userrec *u2 = NULL;
 
   if (!(u2 = get_user_by_handle(userlist, bot)))
     return 1;
   if (bot_hublevel(u2) != 999)
     return 0;
 
+  int rl, i;
+  struct bot_addr *ba = NULL;
+  int r[5] = { 0, 0, 0, 0, 0 };
+  struct userrec *u = NULL;
+
   for (u = userlist; u; u = u->next) {
     if (u->bot && bot_hublevel(u) == 999) {
       if (strcmp(u->handle, bot)) {
@@ -1676,7 +1665,7 @@ void lower_bot_linked(int idx)
 {
   char tmp[6] = "";
 
-  egg_snprintf(tmp, sizeof tmp, "rl %d", get_role(dcc[idx].nick));
+  simple_sprintf(tmp, "rl %d", get_role(dcc[idx].nick));
   putbot(dcc[idx].nick, tmp);
 }
 

+ 1 - 1
src/botnet.h

@@ -33,7 +33,7 @@ int addparty(char *, char *, int, char, int, char *, int *);
 void remparty(char *, int);
 void partystat(char *, int, int, int);
 int partynick(char *, int, char *);
-int partyidle(char *, char *);
+bool partyidle(char *, char *);
 void partysetidle(char *, int, int);
 void partyaway(char *, int, char *);
 void botnet_send_cmdpass(int, char *, char *);

+ 16 - 12
src/cfg.c

@@ -30,7 +30,8 @@
 
 #include "stat.h"
 
-int 				cfg_count = 0, cfg_noshare = 0;
+int 				cfg_count = 0;
+bool				cfg_noshare = 0;
 struct cfg_entry 		**cfg = NULL;
 char 				cmdprefix = '+';	/* This is the prefix for msg/channel cmds */
 struct cmd_pass 		*cmdpass = NULL;
@@ -171,13 +172,13 @@ struct cfg_entry CFG_CMDPREFIX = {
 
 void deflag_user(struct userrec *u, int why, char *msg, struct chanset_t *chan)
 {
+  if (!u)
+    return;
+
   char tmp[256] = "", tmp2[1024] = "";
   struct flag_record fr = {FR_GLOBAL | FR_CHAN, 0, 0, 0 };
   int which = 0;
 
-  if (!u)
-    return;
-
   switch (why) {
   case DEFLAG_BADCOOKIE:
     strcpy(tmp, "Bad op cookie");
@@ -356,8 +357,6 @@ struct cfg_entry CFG_PROCESSLIST = {
 
 #ifdef LEAF
 static void servers_changed(struct cfg_entry * entry, int * valid) {
-  char *slist = NULL, *p = NULL;
-
   if (!strcmp(entry->name, "servers")) {
     if (conf.bot->host6 || conf.bot->ip6) /* we want to use the servers6 entry. */
       return;
@@ -365,6 +364,9 @@ static void servers_changed(struct cfg_entry * entry, int * valid) {
     if (!conf.bot->host6 && !conf.bot->ip6) /* we probably want to use the normal server list.. */
       return;
   }
+
+  char *slist = NULL, *p = NULL;
+
   slist = (char *) (entry->ldata ? entry->ldata : (entry->gdata ? entry->gdata : ""));
   if (serverlist) {
     clearq(serverlist);
@@ -505,10 +507,9 @@ static void getin_describe(struct cfg_entry *cfgent, int idx)
 
 static void getin_changed(struct cfg_entry *cfgent, int *valid)
 {
-  int i;
-
   if (!cfgent->gdata)
     return;
+
   *valid = 0;
   if (!strcmp(cfgent->name, "op-requests")) {
     int L,
@@ -543,7 +544,9 @@ static void getin_changed(struct cfg_entry *cfgent, int *valid)
     *valid = 1;
     return;
   }
-  i = atoi(cfgent->gdata);
+
+  int i = atoi(cfgent->gdata);
+
   if (!strcmp(cfgent->name, "op-bots")) {
     if ((i < 1) || (i > 10))
       return;
@@ -643,17 +646,18 @@ void add_cfg(struct cfg_entry *entry)
 
 static struct cfg_entry *check_can_set_cfg(char *target, char *entryname)
 {
-  int i;
-  struct userrec *u = NULL;
   struct cfg_entry *entry = NULL;
 
-  for (i = 0; i < cfg_count; i++)
+  for (int i = 0; i < cfg_count; i++)
     if (!strcmp(cfg[i]->name, entryname)) {
       entry = cfg[i];
       break;
     }
   if (!entry)
     return 0;
+
+  struct userrec *u = NULL;
+
   if (target) {
     if (!(entry->flags & CFGF_LOCAL))
       return 0;

+ 2 - 1
src/cfg.h

@@ -42,7 +42,8 @@ void set_cmd_pass(char *, int);
 extern struct cmd_pass            *cmdpass;
 
 extern char			cmdprefix;
-extern int			cfg_count, cfg_noshare;
+extern int			cfg_count;
+extern bool			cfg_noshare;
 extern struct cfg_entry		**cfg;
 
 #define OP_BOTS (CFG_OPBOTS.gdata ? atoi(CFG_OPBOTS.gdata) : 1)

+ 13 - 13
src/chan.h

@@ -141,22 +141,22 @@ struct chanset_t {
   uint32_t status;
   uint32_t ircnet_status;
   int flood_pub_thr;
-  int flood_pub_time;
+  time_t flood_pub_time;
   int flood_join_thr;
-  int flood_join_time;
+  time_t flood_join_time;
   int flood_deop_thr;
-  int flood_deop_time;
+  time_t flood_deop_time;
   int flood_kick_thr;
-  int flood_kick_time;
+  time_t flood_kick_time;
   int flood_ctcp_thr;
-  int flood_ctcp_time;
+  time_t flood_ctcp_time;
   int flood_nick_thr;
-  int flood_nick_time;
+  time_t flood_nick_time;
   int limitraise;
   int closed_ban;
   int closed_private;
   int bad_cookie;
-  int cookie_time_slack;
+  time_t cookie_time_slack;
   int manop;
   int mdop;
   int mop;
@@ -166,9 +166,9 @@ struct chanset_t {
   int idle_kick;
   int stopnethack_mode;
   int revenge_mode;
-  int ban_time;
-  int invite_time;
-  int exempt_time;
+  time_t ban_time;
+  time_t invite_time;
+  time_t exempt_time;
 
   /* desired channel modes: */
   int mode_pls_prot;		/* modes to enforce			*/
@@ -176,8 +176,8 @@ struct chanset_t {
   int limit_prot;		/* desired limit			*/
   /* queued mode changes: */
   int limit;			/* new limit to set			*/
-  int bytes;			/* total bytes so far			*/
-  int cbytes;
+  size_t bytes;			/* total bytes so far			*/
+  size_t cbytes;
   int compat;			/* to prevent mixing old/new modes	*/
   int floodnum[FLOOD_CHAN_MAX];
   int opreqtime[5];             /* remember when ops was requested */
@@ -290,7 +290,7 @@ struct msgq_head {
 /* Used to queue a lot of things */
 struct msgq {
   struct msgq *next;
-  int len;
+  size_t len;
   char *msg;
 };
 

+ 13 - 19
src/chanprog.c

@@ -50,11 +50,11 @@ int     		my_port;
  */
 void rmspace(char *s)
 {
-  register char *p = NULL, *q = NULL;
-
   if (!s || !*s)
     return;
 
+  register char *p = NULL, *q = NULL;
+
   /* Remove trailing whitespaces. */
   for (q = s + strlen(s) - 1; q >= s && egg_isspace(*q); q--);
   *(q + 1) = 0;
@@ -203,7 +203,6 @@ void checkchans(int which)
 {
   struct chanset_t *chan = NULL, *chan_next = NULL;
 
-  sdprintf("checkchans(%d)", which);
   if (which == 0 || which == 2) {
     for (chan = chanset; chan; chan = chan->next) {
       if (which == 0) {
@@ -232,7 +231,6 @@ void tell_verbose_uptime(int idx)
   time_t now2, hr, min;
 
   now2 = now - online_since;
-  s[0] = 0;
   if (now2 > 86400) {
     /* days */
     sprintf(s, "%d day", (int) (now2 / 86400));
@@ -361,18 +359,16 @@ void tell_settings(int idx)
   if (owner[0])
     dprintf(idx, "%s: %s\n", MISC_PERMOWNER, owner);
 #endif /* HUB */
-  dprintf(idx, "Ignores last %d mins\n", ignore_time);
+  dprintf(idx, "Ignores last %li mins\n", ignore_time);
 }
 
 void reaffirm_owners()
 {
-  char *p = NULL, *q = NULL, s[121] = "";
-  struct userrec *u = NULL;
-
   /* Make sure perm owners are +a */
   if (owner[0]) {
-    q = owner;
-    p = strchr(q, ',');
+    char *q = owner, *p = strchr(q, ','), s[121] = "";
+    struct userrec *u = NULL;
+
     while (p) {
       strncpyz(s, q, (p - q) + 1);
       rmspace(s);
@@ -532,6 +528,7 @@ void chanprog()
 
   if (!conf.bot->nick)
     fatal("I don't have a nickname!!\n", 0);
+  sdprintf("I am: %s", conf.bot->nick);
 #ifdef HUB
   loading = 1;
   checkchans(0);
@@ -590,9 +587,8 @@ void chanprog()
  */
 void reload()
 {
-  FILE *f = NULL;
+  FILE *f = fopen(userfile, "r");
 
-  f = fopen(userfile, "r");
   if (f == NULL) {
     putlog(LOG_MISC, "*", MISC_CANTRELOADUSER);
     return;
@@ -617,23 +613,21 @@ void reload()
  */
 int isowner(char *name)
 {
-  char *pa = NULL, *pb = NULL;
-  char nl, pl;
-
   if (!owner || !*owner)
     return (0);
   if (!name || !*name)
     return (0);
-  nl = strlen(name);
-  pa = owner;
-  pb = owner;
+
+  char *pa = owner, *pb = owner;
+  size_t nl = strlen(name), pl;
+
   while (1) {
     while (1) {
       if ((*pb == 0) || (*pb == ',') || (*pb == ' '))
 	break;
       pb++;
     }
-    pl = (unsigned int) pb - (unsigned int) pa;
+    pl = pb - pa;
     if (pl == nl && !egg_strncasecmp(pa, name, nl))
       return (1);
     while (1) {

File diff suppressed because it is too large
+ 238 - 245
src/cmds.c


+ 32 - 12
src/compat/snprintf.c

@@ -139,7 +139,7 @@ static void dopr_outch(char *buffer, size_t * currlen, size_t maxlen,
 #define DP_C_LDOUBLE 3
 
 #define char_to_int(p) (p - '0')
-#define MAX(p,q) ((p >= q) ? p : q)
+#define MAXIMUM(p,q) ((p >= q) ? p : q)
 
 static void dopr(char *buffer, size_t maxlen, const char *format,
 		 va_list args)
@@ -233,6 +233,14 @@ static void dopr(char *buffer, size_t maxlen, const char *format,
     case DP_S_MOD:
       /* Currently, we don't support Long Long, bummer */
       switch (ch) {
+      case 'z':		/* size_t */
+      case 'Z':
+        if (sizeof (size_t) > sizeof (unsigned long int))
+          cflags = DP_C_LDOUBLE;
+        else if (sizeof (size_t) > sizeof (unsigned int))
+          cflags = DP_C_LONG;
+        ch = *format++;
+        break;
       case 'h':
 	cflags = DP_C_SHORT;
 	ch = *format++;
@@ -258,9 +266,15 @@ static void dopr(char *buffer, size_t maxlen, const char *format,
 	  value = va_arg(args, short int);
 	else if (cflags == DP_C_LONG)
 	  value = va_arg(args, long int);
+        else if (cflags == DP_C_LDOUBLE)
+          fvalue = va_arg(args, LDOUBLE);
 	else
 	  value = va_arg(args, int);
-	fmtint(buffer, &currlen, maxlen, value, 10, min, max, flags);
+
+        if (cflags == DP_C_LDOUBLE)
+          fmtfp(buffer, &currlen, maxlen, fvalue, min, max, flags);
+        else         
+          fmtint(buffer, &currlen, maxlen, value, 10, min, max, flags);
 	break;
       case 'o':
 	flags |= DP_F_UNSIGNED;
@@ -278,9 +292,16 @@ static void dopr(char *buffer, size_t maxlen, const char *format,
 	  value = va_arg(args, unsigned short int);
 	else if (cflags == DP_C_LONG)
 	  value = va_arg(args, unsigned long int);
+        else if (cflags == DP_C_LDOUBLE)
+          fvalue = (unsigned) va_arg(args, LDOUBLE);
 	else
 	  value = va_arg(args, unsigned int);
-	fmtint(buffer, &currlen, maxlen, value, 10, min, max, flags);
+
+        if (cflags == DP_C_LDOUBLE)
+          fmtfp(buffer, &currlen, maxlen, fvalue, min, max, flags);
+        else         
+          fmtint(buffer, &currlen, maxlen, value, 10, min, max, flags);
+
 	break;
       case 'X':
 	flags |= DP_F_UP;
@@ -328,9 +349,8 @@ static void dopr(char *buffer, size_t maxlen, const char *format,
 	fmtstr(buffer, &currlen, maxlen, strvalue, flags, min, max);
 	break;
       case 'p':
-	strvalue = va_arg(args, void *);
-	fmtint(buffer, &currlen, maxlen, (long) strvalue, 16, min, max,
-	       flags);
+	strvalue = (char *) va_arg(args, void *);
+	fmtint(buffer, &currlen, maxlen, (long) strvalue, 16, min, max, flags);
 	break;
       case 'n':
 	if (cflags == DP_C_SHORT) {
@@ -452,13 +472,13 @@ static void fmtint(char *buffer, size_t * currlen, size_t maxlen,
   convert[place] = 0;
 
   zpadlen = max - place;
-  spadlen = min - MAX(max, place) - (signvalue ? 1 : 0);
+  spadlen = min - MAXIMUM(max, place) - (signvalue ? 1 : 0);
   if (zpadlen < 0)
     zpadlen = 0;
   if (spadlen < 0)
     spadlen = 0;
   if (flags & DP_F_ZERO) {
-    zpadlen = MAX(zpadlen, spadlen);
+    zpadlen = MAXIMUM(zpadlen, spadlen);
     spadlen = 0;
   }
   if (flags & DP_F_MINUS)
@@ -523,14 +543,14 @@ static LDOUBLE pow10(int exp)
 
 static long round(LDOUBLE value)
 {
-  long intpart;
+  LDOUBLE intpart;
 
   intpart = value;
   value = value - intpart;
   if (value >= 0.5)
     intpart++;
 
-  return intpart;
+  return (long) intpart;
 }
 
 static void fmtfp(char *buffer, size_t * currlen, size_t maxlen,
@@ -569,7 +589,7 @@ static void fmtfp(char *buffer, size_t * currlen, size_t maxlen,
     caps = 1;			/* Should characters be upper case? */
 #endif
 
-  intpart = ufvalue;
+  intpart = (long) ufvalue;
 
   /*
    * Sorry, we only support 9 digits past the decimal because of our
@@ -585,7 +605,7 @@ static void fmtfp(char *buffer, size_t * currlen, size_t maxlen,
 
   if (fracpart >= pow10(max)) {
     intpart++;
-    fracpart -= pow10(max);
+    fracpart -= (long) pow10(max);
   }
 
   /* Convert integer part */

+ 0 - 1
src/conf.c

@@ -294,7 +294,6 @@ checkpid(char *nick, conf_bot * bot)
   FILE *f = NULL;
   char buf[DIRMAX] = "", s[11] = "", *tmpnick = NULL, *tmp_ptr = NULL;
 
-
   tmpnick = tmp_ptr = strdup(nick);
 
   if (tmpnick[0] == '/')

+ 4 - 2
src/core_binds.c

@@ -37,7 +37,7 @@ void core_binds_init()
 void check_bind_dcc(const char *cmd, int idx, const char *text)
 {
   struct flag_record fr = {FR_GLOBAL | FR_CHAN, 0, 0, 0 };
-  int x, hits, found = 0;
+  bool found = 0;
   bind_entry_t *entry = NULL;
   bind_table_t *table = NULL;
   char *args = strdup(text);
@@ -77,7 +77,9 @@ void check_bind_dcc(const char *cmd, int idx, const char *text)
     }
   }
 
-  x = check_bind_hits(BT_dcc, cmd, &fr, &hits, idx, args);
+  int hits = 0;
+
+  check_bind_hits(BT_dcc, cmd, &fr, &hits, idx, args);
 
   if (hits != 1)
     putlog(LOG_CMDS, "*", "! #%s# %s %s", dcc[idx].nick, cmd, args);

+ 13 - 17
src/crypt.c

@@ -99,10 +99,9 @@ char *encrypt_string(const char *keydata, char *in)
 
 char *decrypt_string(const char *keydata, char *in)
 {
-  size_t len = 0;
+  size_t len = strlen(in);
   char *buf = NULL, *res = NULL;
 
-  len = strlen(in);
   if (keydata && *keydata) {
     buf = b64dec((const unsigned char *) in, &len);
     res = (char *) decrypt_binary(keydata, (unsigned char *) buf, len);
@@ -131,10 +130,9 @@ void encrypt_pass(char *s1, char *s2)
 int lfprintf (FILE *stream, const char *format, ...)
 {
   va_list va;
-  char buf[2048], *ln = NULL, *nln = NULL, *tmp = NULL;
+  char buf[2048] = "", *ln = NULL, *nln = NULL, *tmp = NULL;
   int res;
 
-  buf[0] = 0;
   va_start(va, format);
   egg_vsnprintf(buf, sizeof buf, format, va);
   va_end(va);
@@ -156,9 +154,8 @@ int lfprintf (FILE *stream, const char *format, ...)
 
 void Encrypt_File(char *infile, char *outfile)
 {
-  char *buf = NULL;
   FILE *f = NULL, *f2 = NULL;
-  int std = 0;
+  bool std = 0;
 
   if (!strcmp(outfile, "STDOUT"))
     std = 1;
@@ -173,7 +170,7 @@ void Encrypt_File(char *infile, char *outfile)
     printf("----------------------------------START----------------------------------\n");
   }
 
-  buf = (char *) calloc(1, 1024);
+  char *buf = (char *) calloc(1, 1024);
   while (fgets(buf, 1024, f) != NULL) {
     remove_crlf(buf);
 
@@ -194,9 +191,8 @@ void Encrypt_File(char *infile, char *outfile)
 
 void Decrypt_File(char *infile, char *outfile)
 {
-  char *buf = NULL;
   FILE *f = NULL, *f2 = NULL;
-  int std = 0;
+  bool std = 0;
 
   if (!strcmp(outfile, "STDOUT"))
     std = 1;
@@ -211,7 +207,7 @@ void Decrypt_File(char *infile, char *outfile)
     printf("----------------------------------START----------------------------------\n");
   }
 
-  buf = (char *) calloc(1, 2048);
+  char *buf = (char *) calloc(1, 2048);
   while (fgets(buf, 2048, f) != NULL) {
     char *temps = NULL;
 
@@ -251,15 +247,16 @@ char *MD5(const char *string)
 char *
 MD5FILE(const char *bin)
 {
-  static char     md5string[MD5_HASH_LENGTH + 1] = "";
-  unsigned char   md5out[MD5_HASH_LENGTH + 1] = "", buffer[1024] = "";
-  MD5_CTX ctx;
-  size_t binsize = 0, len = 0;
   FILE *f = NULL;
 
   if (!(f = fopen(bin, "rb")))
     return "";
 
+  static char     md5string[MD5_HASH_LENGTH + 1] = "";
+  unsigned char   md5out[MD5_HASH_LENGTH + 1] = "", buffer[1024] = "";
+  MD5_CTX ctx;
+  size_t binsize = 0, len = 0;
+
   MD5_Init(&ctx);
   while ((len = fread(buffer, 1, sizeof buffer, f))) {
     binsize += len;
@@ -287,12 +284,11 @@ char *SHA1(const char *string)
 }
 
 /* convert binary hashes to hex */
-char *btoh(const unsigned char *md, int len)
+char *btoh(const unsigned char *md, size_t len)
 {
-  int i;
   char buf[100] = "", *ret = NULL;
 
-  for (i = 0; i < len; i+=4) {
+  for (size_t i = 0; i < len; i+=4) {
     sprintf(&(buf[i << 1]), "%02x", md[i]);
     sprintf(&(buf[(i + 1) << 1]), "%02x", md[i + 1]);
     sprintf(&(buf[(i + 2) << 1]), "%02x", md[i + 2]);

+ 2 - 1
src/crypt.h

@@ -7,6 +7,7 @@
 #  include "config.h"
 #endif
 
+#include <sys/types.h>
 #include "src/crypto/crypto.h"
 
 #define SHA_HASH_LENGTH (SHA_DIGEST_LENGTH << 1)
@@ -24,6 +25,6 @@ char *decryptit (char *);
 int lfprintf (FILE *, const char *, ...) __attribute__((format(printf, 2, 3)));
 void Encrypt_File(char *, char *);
 void Decrypt_File(char *, char *);
-char *btoh(const unsigned char *, int);
+char *btoh(const unsigned char *, size_t);
 
 #endif /* !_CRYPT_H */

+ 108 - 126
src/dcc.c

@@ -43,27 +43,27 @@ struct dcc_t *dcc = NULL;       /* DCC list                                */
 time_t timesync = 0;
 int dcc_total = 0;              /* Total dcc's                             */
 
-static int password_timeout = 20;       /* Time to wait for a password from a user */
-static int auth_timeout = 40;
-static int bot_timeout = 15;    /* Bot timeout value                       */
-static int identtimeout = 15;   /* Timeout value for ident lookups         */
-static int dupwait_timeout = 5; /* Timeout for rejecting duplicate entries */
+static time_t password_timeout = 20;       /* Time to wait for a password from a user */
+static time_t auth_timeout = 40;
+static time_t bot_timeout = 15;    /* Bot timeout value                       */
+static time_t identtimeout = 15;   /* Timeout value for ident lookups         */
+static time_t dupwait_timeout = 5; /* Timeout for rejecting duplicate entries */
 
 #ifdef LEAF
-static int protect_telnet = 0;  /* Even bother with ident lookups :)       */
+static bool protect_telnet = 0;  /* Even bother with ident lookups :)       */
 #else /* !LEAF */
-static int protect_telnet = 1;
+static bool protect_telnet = 1;
 #endif /* LEAF */
 static int flood_telnet_thr = 10;       /* Number of telnet connections to be
                                          * considered a flood                      */
-static int flood_telnet_time = 5;       /* In how many seconds?                    */
+static time_t flood_telnet_time = 5;       /* In how many seconds?                    */
 
 static void dcc_telnet_hostresolved(int);
 static void dcc_telnet_got_ident(int, char *);
-static void dcc_telnet_pass(int, int);
+static void dcc_telnet_pass(int, size_t);
 
 static void
-strip_telnet(int sock, char *buf, int *len)
+strip_telnet(sock_t sock, char *buf, size_t *len)
 {
   unsigned char *p = (unsigned char *) buf, *o = (unsigned char *) buf;
   int mark;
@@ -125,10 +125,9 @@ send_timesync(int idx)
     dprintf(idx, "ts %li\n", timesync + now);
   else {
     char s[15] = "";
-    int i;
 
     sprintf(s, "ts %li\n", timesync + now);
-    for (i = 0; i < dcc_total; i++) {
+    for (int i = 0; i < dcc_total; i++) {
       if ((dcc[i].type == &DCC_BOT) && (bot_aggressive_to(dcc[i].user))) {
         dprintf(i, s);
       }
@@ -140,7 +139,6 @@ send_timesync(int idx)
 static void
 greet_new_bot(int idx)
 {
-  int i;
   char *sysname = NULL;
   struct utsname un;
 
@@ -172,7 +170,7 @@ greet_new_bot(int idx)
 
   dprintf(idx, "si %s %s %s", conf.username ? conf.username : "*", un.sysname ? un.sysname : "*",
           un.nodename ? un.nodename : "*");
-  for (i = 0; i < dcc_total; i++) {
+  for (int i = 0; i < dcc_total; i++) {
     if (dcc[i].type == &DCC_FORK_BOT) {
       killsock(dcc[i].sock);
       lostdcc(i);
@@ -183,10 +181,6 @@ greet_new_bot(int idx)
 static void
 bot_version(int idx, char *par)
 {
-  char x[1024] = "", *vversion = NULL;
-  int l, vlocalhub = 0;
-  time_t vbuildts = 0;
-
   dcc[idx].timeval = now;
   if (in_chain(dcc[idx].nick)) {
     dprintf(idx, "error Sorry, already connected.\n");
@@ -195,6 +189,7 @@ bot_version(int idx, char *par)
     lostdcc(idx);
     return;
   }
+
   if ((par[0] >= '0') && (par[0] <= '9')) {
     char *work = NULL;
 
@@ -205,7 +200,9 @@ bot_version(int idx, char *par)
     dcc[idx].u.bot->numver = 0;
 
   dprintf(idx, "tb %s\n", conf.bot->nick);
-  l = atoi(newsplit(&par));
+
+  size_t l = atol(newsplit(&par));
+
   if (l != HANDLEN) {
     putlog(LOG_BOTS, "*", "Non-matching handle lengths with %s, they use %d characters.", dcc[idx].nick, l);
     dprintf(idx, "error Non-matching handle length: mine %d, yours %d\n", HANDLEN, l);
@@ -214,6 +211,11 @@ bot_version(int idx, char *par)
     lostdcc(idx);
     return;
   }
+
+  char x[1024] = "", *vversion = NULL;
+  int vlocalhub = 0;
+  time_t vbuildts = 0;
+
   strncpyz(dcc[idx].u.bot->version, par, 120);
   newsplit(&par);               /* 'ver' */
   newsplit(&par);               /* handlen */
@@ -259,9 +261,7 @@ failed_link(int idx)
   if (dcc[idx].u.bot->numver >= (-1))
     putlog(LOG_BOTS, "*", DCC_LINKFAIL, dcc[idx].nick);
   if (dcc[idx].sock != -1) {
-    int i = 0;
-    
-    for (i = 0; i < MAXSOCKS; i++)
+    for (int i = 0; i < MAXSOCKS; i++)
       if (dcc[idx].sock == socklist[i].sock) {
         killsock(dcc[idx].sock);
         dcc[idx].sock = -1; 
@@ -273,22 +273,19 @@ failed_link(int idx)
 }
 
 static void
-cont_link(int idx, char *buf, int ii)
+cont_link(int idx, char *buf, size_t ii)
 {
   /* Now set the initial link key (incoming only, we're not sending more until we get an OK)... */
-  struct sockaddr_in sa;
-  char tmp[301] = "";
-  int i, snum = -1;
-  socklen_t socklen;
-
-  for (i = 0; i < MAXSOCKS; i++) {
-    if ((socklist[i].sock == dcc[idx].sock) && !(socklist[i].flags & SOCK_UNUSED)) {
-      snum = i;
-    }
-  }
+
+  sock_t snum = findanysnum(dcc[idx].sock);
+
   if (snum >= 0) {
+    struct sockaddr_in sa;
+    socklen_t socklen = sizeof(sa);
+    char tmp[301] = "";
+
     /* If we're already connected somewhere, unlink and idle a sec */
-    for (i = 0; i < dcc_total; i++) {
+    for (int i = 0; i < dcc_total; i++) {
       if ((dcc[i].type == &DCC_BOT) && (!bot_aggressive_to(dcc[i].user))) {
         putlog(LOG_BOTS, "*", "Unlinking %s - restructure", dcc[i].nick);
         botnet_send_unlinked(i, dcc[i].nick, "Restructure");
@@ -302,17 +299,15 @@ cont_link(int idx, char *buf, int ii)
     dcc[idx].type = &DCC_BOT_NEW;
     dcc[idx].u.bot->numver = 0;
     dprintf(idx, "%s\n", conf.bot->nick);
-    socklen = sizeof(sa);
 
     /* initkey-gen leaf */
     /* bdhash myport hubnick mynick */
+    egg_bzero(&sa, socklen);
     getsockname(socklist[snum].sock, (struct sockaddr *) &sa, &socklen);
     egg_snprintf(tmp, sizeof tmp, "%s@%4x@%s@%s", settings.bdhash, sa.sin_port, dcc[idx].nick, conf.bot->nick);
     strncpyz(socklist[snum].ikey, SHA1(tmp), sizeof(socklist[snum].ikey));
-    /*
-     * putlog(LOG_DEBUG, "@", "Link hash for %s: %s", dcc[idx].nick, tmp);
-     * putlog(LOG_DEBUG, "@", "initkey (%d): %s", strlen(socklist[snum].ikey), socklist[snum].ikey);
-     */
+    putlog(LOG_DEBUG, "@", "Link hash for %s: %s", dcc[idx].nick, tmp);
+    putlog(LOG_DEBUG, "@", "initkey (%d): %s", strlen(socklist[snum].ikey), socklist[snum].ikey);
     /* We've send our conf.bot->nick and set the key for the link on the sock, wait for 'elink' back to verify key */
     socklist[snum].encstatus = 1;
     socklist[snum].gz = 1;
@@ -325,11 +320,10 @@ cont_link(int idx, char *buf, int ii)
 }
 
 static void
-dcc_bot_new(int idx, char *buf, int x)
+dcc_bot_new(int idx, char *buf, size_t x)
 {
 /*  struct userrec *u = get_user_by_handle(userlist, dcc[idx].nick); */
   char *code = NULL;
-  int i;
 
   strip_telnet(dcc[idx].sock, buf, &x);
   code = newsplit(&buf);
@@ -338,22 +332,14 @@ dcc_bot_new(int idx, char *buf, int x)
   } else if (!egg_strcasecmp(code, "v")) {
     bot_version(idx, buf);
   } else if (!egg_strcasecmp(code, "elink")) {
-    int snum = -1;
+    sock_t snum = findanysnum(dcc[idx].sock);
 
     /* putlog(LOG_DEBUG, "*", "Got elink: %s %s", code, buf); */
     /* Set the socket key and we're linked */
-    for (i = 0; i < MAXSOCKS; i++) {
-      if (!(socklist[i].flags & SOCK_UNUSED) && (socklist[i].sock == dcc[idx].sock)) {
-        snum = i;
-        break;
-      }
-    }
 
     if (snum >= 0) {
-      char *tmp = NULL, *p = NULL;
+      char *tmp = decrypt_string(settings.salt2, newsplit(&buf));
 
-      p = newsplit(&buf);
-      tmp = decrypt_string(settings.salt2, p);
       strncpyz(socklist[snum].okey, tmp, sizeof(socklist[snum].okey));
       strncpyz(socklist[snum].ikey, socklist[snum].okey, sizeof(socklist[snum].ikey));
       socklist[snum].iseed = atoi(buf);
@@ -428,7 +414,7 @@ struct dcc_table DCC_BOT_NEW = {
 extern botcmd_t C_bot[];
 
 static void
-dcc_bot(int idx, char *code, int i)
+dcc_bot(int idx, char *code, size_t i)
 {
   char *msg = NULL;
   int f;
@@ -448,6 +434,7 @@ dcc_bot(int idx, char *code, int i)
     msg++;
   } else
     msg = "";
+
   for (f = i = 0; C_bot[i].name && !f; i++) {
     int y = egg_strcasecmp(code, C_bot[i].name);
 
@@ -482,9 +469,7 @@ eof_dcc_bot(int idx)
 static void
 display_dcc_bot(int idx, char *buf)
 {
-  size_t i;
-
-  i = simple_sprintf(buf, "bot   flags: ");
+  size_t i = simple_sprintf(buf, "bot   flags: ");
 
   buf[i++] = b_status(idx) & STAT_PINGED ? 'P' : 'p';
   buf[i++] = b_status(idx) & STAT_SHARE ? 'U' : 'u';
@@ -539,7 +524,7 @@ struct dcc_table DCC_FORK_BOT = {
 };
 
 static void
-dcc_identd(int idx, char *buf, int atr)
+dcc_identd(int idx, char *buf, size_t atr)
 {
   char outbuf[1024] = "";
 
@@ -578,11 +563,11 @@ struct dcc_table DCC_IDENTD = {
 };
 
 static void
-dcc_identd_connect(int idx, char *buf, int atr)
+dcc_identd_connect(int idx, char *buf, size_t atr)
 {
-  IP ip;
+  in_addr_t ip;
   port_t port;
-  int j = 0, sock;
+  sock_t j, sock;
   char s[UHOSTLEN + 1] = "";
 
   if (dcc_total + 1 > max_dcc) {
@@ -627,15 +612,16 @@ struct dcc_table DCC_IDENTD_CONNECT = {
 };
 
 static void
-dcc_chat_secpass(int idx, char *buf, int atr)
+dcc_chat_secpass(int idx, char *buf, size_t atr)
 {
   int badauth = 0;
 
   if (dccauth) {
-    char check[MD5_HASH_LENGTH + 7] = "";
-
     if (!atr)
       return;
+
+    char check[MD5_HASH_LENGTH + 7] = "";
+
     strip_telnet(dcc[idx].sock, buf, &atr);
     atr = dcc[idx].user ? dcc[idx].user->flags : 0;
     egg_snprintf(check, sizeof check, "+Auth %s", dcc[idx].hash);
@@ -739,7 +725,7 @@ kill_dcc_general(int idx, void *x)
 
   if (p) {
     if (p->buffer) {
-      struct msgq *r, *q;
+      struct msgq *r = NULL, *q = NULL;
 
       for (r = dcc[idx].u.chat->buffer; r; r = q) {
         q = r->next;
@@ -829,7 +815,6 @@ strip_mirc_codes(int flags, char *text)
 static void
 append_line(int idx, char *line)
 {
-  int l = strlen(line);
   struct msgq *p = NULL, *q = NULL;
   struct chat_info *c = (dcc[idx].type == &DCC_CHAT) ? dcc[idx].u.chat : dcc[idx].u.file->chat;
 
@@ -845,6 +830,9 @@ append_line(int idx, char *line)
     do_boot(idx, conf.bot->nick, "too many pages - senq full");
     return;
   }
+
+  size_t l = strlen(line);
+
   if ((c->line_count < c->max_line) && (c->buffer == NULL)) {
     c->line_count++;
     tputs(dcc[idx].sock, line, l);
@@ -897,7 +885,7 @@ static struct dcc_table DCC_CHAT_SECPASS = {
 };
 
 static void
-dcc_chat_pass(int idx, char *buf, int atr)
+dcc_chat_pass(int idx, char *buf, size_t atr)
 {
   if (!atr)
     return;
@@ -1010,20 +998,21 @@ eof_dcc_chat(int idx)
 }
 
 static void
-dcc_chat(int idx, char *buf, int i)
+dcc_chat(int idx, char *buf, size_t len)
 {
-  int nathan = 0, doron = 0, fixed = 0;
-  char *v = NULL, *d = NULL;
+  int i = 0;
 
-  strip_telnet(dcc[idx].sock, buf, &i);
+  strip_telnet(dcc[idx].sock, buf, &len);
   if (buf[0] && (buf[0] != settings.dcc_prefix[0]) && !(dcc[idx].user && (dcc[idx].user->flags & USER_NOFLOOD)) &&
       detect_dcc_flood(&dcc[idx].timeval, dcc[idx].u.chat, idx))
     return;
+
   dcc[idx].timeval = now;
   if (buf[0]) {
+    int nathan = 0, doron = 0, fixed = 0;
+    char *v = buf, *d = buf;
+
     /* Check for beeps and cancel annoying ones */
-    v = buf;
-    d = buf;
     while (*v)
       switch (*v) {
         case 1:			/* CTCP ?! */
@@ -1133,10 +1122,9 @@ dcc_chat(int idx, char *buf, int i)
 static void
 display_dcc_chat(int idx, char *buf)
 {
-  size_t i;
+  size_t i = simple_sprintf(buf, "chat  flags: ");
   int colori = 0;
 
-  i = simple_sprintf(buf, "chat  flags: ");
   buf[i++] = dcc[idx].status & STAT_CHAT ? 'C' : 'c';
   buf[i++] = dcc[idx].status & STAT_PARTY ? 'P' : 'p';
   buf[i++] = dcc[idx].status & STAT_TELNET ? 'T' : 't';
@@ -1170,7 +1158,7 @@ static time_t lasttelnettime;
 
 /* A modified detect_flood for incoming telnet flood protection.
  */
-static int
+static bool
 detect_telnet_flood(char *floodhost)
 {
   struct flag_record fr = { FR_GLOBAL | FR_CHAN | FR_ANYWH, 0, 0, 0 };
@@ -1204,14 +1192,15 @@ detect_telnet_flood(char *floodhost)
 }
 
 static void
-dcc_telnet(int idx, char *buf, int i)
+dcc_telnet(int idx, char *buf, size_t ii)
 {
-  IP ip;
+  in_addr_t ip;
   port_t port;
-  int j = 0, sock;
-  char s[UHOSTLEN + 1] = "", x[1024] = "";
+  char s[UHOSTLEN + 1] = "";
 
   if (dcc_total + 1 > max_dcc) {
+    sock_t j;
+
     j = answer(dcc[idx].sock, s, &ip, &port, 0);
     if (j != -1) {
       dprintf(-j, "Sorry, too many connections already.\r\n");
@@ -1219,7 +1208,9 @@ dcc_telnet(int idx, char *buf, int i)
     }
     return;
   }
-  sock = answer(dcc[idx].sock, s, &ip, &port, 0);
+
+  sock_t sock = answer(dcc[idx].sock, s, &ip, &port, 0);
+
   while ((sock == -1) && (errno == EAGAIN))
     sock = answer(sock, s, &ip, &port, 0);
 /*. ssl_link ACCEPT_SSL should go here!!!! */
@@ -1241,6 +1232,9 @@ dcc_telnet(int idx, char *buf, int i)
     return;
   }
 
+  char x[1024] = "";
+  int i;
+
   sprintf(x, "-telnet!telnet@%s", iptostr(htonl(ip)));
   if (match_ignore(x) || detect_telnet_flood(x)) {
     killsock(sock);
@@ -1275,8 +1269,8 @@ static void
 dcc_telnet_hostresolved(int i)
 {
   int idx;
-  int j = 0, sock;
-  char s[UHOSTLEN] = "", s2[UHOSTLEN + 20] = "";
+  sock_t j = 0, sock;
+  char s2[UHOSTLEN + 20] = "";
 
 #ifdef USE_IPV6
   if (sockprotocol(dcc[i].sock) == AF_INET6 && dcc[i].addr6[0])
@@ -1306,7 +1300,7 @@ dcc_telnet_hostresolved(int i)
   if (dcc[idx].host[0] == '@') {
     /* Restrict by hostname */
     if (!wild_match(dcc[idx].host + 1, dcc[i].host)) {
-      putlog(LOG_BOTS, "*", DCC_BADHOST, s);
+      putlog(LOG_BOTS, "*", DCC_BADHOST, dcc[i].host);
       killsock(dcc[i].sock);
       lostdcc(i);
       return;
@@ -1324,7 +1318,9 @@ dcc_telnet_hostresolved(int i)
 #endif /* USE_IPV6 */
     sock = open_telnet(iptostr(htonl(dcc[i].addr)), 113);
   putlog(LOG_MISC, "*", DCC_TELCONN, dcc[i].host, dcc[i].port);
-  s[0] = 0;
+
+  char s[UHOSTLEN] = "";
+
   if (sock < 0) {
     if (sock == -2)
       strcpy(s, "DNS lookup failed for ident");
@@ -1389,7 +1385,7 @@ eof_dcc_dupwait(int idx)
 }
 
 static void
-dcc_dupwait(int idx, char *buf, int i)
+dcc_dupwait(int idx, char *buf, size_t i)
 {
   /* We just ignore any data at this point. */
   return;
@@ -1401,10 +1397,10 @@ dcc_dupwait(int idx, char *buf, int i)
 static void
 timeout_dupwait(int idx)
 {
-  char x[100] = "";
-
   /* Still duplicate? */
   if (in_chain(dcc[idx].nick)) {
+    char x[UHOSTLEN] = "";
+
     egg_snprintf(x, sizeof x, "%s!%s", dcc[idx].nick, dcc[idx].host);
     putlog(LOG_BOTS, "*", DCC_DUPLICATE, x);
     killsock(dcc[idx].sock);
@@ -1453,10 +1449,8 @@ struct dcc_table DCC_DUPWAIT = {
 void
 dupwait_notify(const char *who)
 {
-  register int idx;
-
   Assert(who);
-  for (idx = 0; idx < dcc_total; idx++)
+  for (register int idx = 0; idx < dcc_total; idx++)
     if ((dcc[idx].type == &DCC_DUPWAIT) && !egg_strcasecmp(dcc[idx].nick, who)) {
       dcc_telnet_pass(idx, dcc[idx].u.dupwait->atr);
       break;
@@ -1464,11 +1458,8 @@ dupwait_notify(const char *who)
 }
 
 static void
-dcc_telnet_id(int idx, char *buf, int atr)
+dcc_telnet_id(int idx, char *buf, size_t atr)
 {
-  int ok = 0;
-  struct flag_record fr = { FR_GLOBAL | FR_CHAN | FR_ANYWH, 0, 0, 0 };
-
   strip_telnet(dcc[idx].sock, buf, &atr);
   buf[HANDLEN] = 0;
   /* Toss out bad nicknames */
@@ -1480,6 +1471,10 @@ dcc_telnet_id(int idx, char *buf, int atr)
     lostdcc(idx);
     return;
   }
+
+  bool ok = 0;
+  struct flag_record fr = { FR_GLOBAL | FR_CHAN | FR_ANYWH, 0, 0, 0 };
+
   dcc[idx].user = get_user_by_handle(userlist, buf);
   get_user_flagrec(dcc[idx].user, &fr, NULL);
 
@@ -1513,9 +1508,8 @@ dcc_telnet_id(int idx, char *buf, int atr)
       lostdcc(idx);
       return;
     } else if (in_chain(dcc[idx].nick)) {
-      struct chat_info *ci;
+      struct chat_info *ci = dcc[idx].u.chat;
 
-      ci = dcc[idx].u.chat;
       dcc[idx].type = &DCC_DUPWAIT;
       dcc[idx].u.dupwait = (struct dupwait_info *) calloc(1, sizeof(struct dupwait_info));
       dcc[idx].u.dupwait->chat = ci;
@@ -1527,9 +1521,8 @@ dcc_telnet_id(int idx, char *buf, int atr)
 }
 
 static void
-dcc_telnet_pass(int idx, int atr)
+dcc_telnet_pass(int idx, size_t atr)
 {
-  int ok = 0, i, ok2;
   struct flag_record fr = { FR_GLOBAL | FR_CHAN | FR_ANYWH, 0, 0, 0 };
 
   get_user_flagrec(dcc[idx].user, &fr, NULL);
@@ -1541,17 +1534,18 @@ dcc_telnet_pass(int idx, int atr)
     lostdcc(idx);
     return;
   }
-  ok = 0;
+
+  bool ok = 0, ok2 = 1;
+
   if (dcc[idx].type == &DCC_DUPWAIT) {
-    struct chat_info *ci;
+    struct chat_info *ci = dcc[idx].u.dupwait->chat;
 
-    ci = dcc[idx].u.dupwait->chat;
     free(dcc[idx].u.dupwait);
     dcc[idx].u.chat = ci;
   }
   dcc[idx].type = &DCC_CHAT_PASS;
   dcc[idx].timeval = now;
-  ok2 = 1;
+
 #ifdef HUB
   if (!glob_huba(fr))
     ok2 = 0;
@@ -1574,15 +1568,8 @@ dcc_telnet_pass(int idx, int atr)
   }
 
   if (glob_bot(fr)) {
-    int snum = -1;
+    sock_t snum = findanysnum(dcc[idx].sock);
 
-    for (i = 0; i < MAXSOCKS; i++) {
-      if (!(socklist[i].flags & SOCK_UNUSED)
-          && (socklist[i].sock == dcc[idx].sock)) {
-        snum = i;
-        break;
-      }
-    }
     if (snum >= 0) {
       char initkey[33] = "", *tmp2 = NULL;
       char tmp[256] = "";
@@ -1664,7 +1651,7 @@ struct dcc_table DCC_TELNET_ID = {
 };
 
 static void
-dcc_socket(int idx, char *buf, int len)
+dcc_socket(int idx, char *buf, size_t len)
 {
 }
 
@@ -1714,7 +1701,7 @@ struct dcc_table DCC_LOST = {
 };
 
 void
-dcc_identwait(int idx, char *buf, int len)
+dcc_identwait(int idx, char *buf, size_t len)
 {
   /* Ignore anything now */
 }
@@ -1722,10 +1709,8 @@ dcc_identwait(int idx, char *buf, int len)
 void
 eof_dcc_identwait(int idx)
 {
-  int i;
-
   putlog(LOG_MISC, "*", DCC_LOSTCONN, dcc[idx].host, dcc[idx].port);
-  for (i = 0; i < dcc_total; i++)
+  for (int i = 0; i < dcc_total; i++)
     if ((dcc[i].type == &DCC_IDENT) && (dcc[i].u.ident_sock == dcc[idx].sock)) {
       killsock(dcc[i].sock);    /* Cleanup ident socket */
       dcc[i].u.other = 0;
@@ -1757,10 +1742,9 @@ struct dcc_table DCC_IDENTWAIT = {
 };
 
 void
-dcc_ident(int idx, char *buf, int len)
+dcc_ident(int idx, char *buf, size_t len)
 {
   char ident_response[512] = "", uid[512] = "", buf1[UHOSTLEN] = "";
-  int i;
 
   sscanf(buf, "%*[^:]:%[^:]:%*[^:]:%[^\n]\n", ident_response, uid);
   rmspace(ident_response);
@@ -1770,7 +1754,7 @@ dcc_ident(int idx, char *buf, int len)
   }
   rmspace(uid);
   uid[20] = 0;                  /* 20 character ident max */
-  for (i = 0; i < dcc_total; i++)
+  for (int i = 0; i < dcc_total; i++)
     if ((dcc[i].type == &DCC_IDENTWAIT) && (dcc[i].sock == dcc[idx].u.ident_sock)) {
       simple_sprintf(buf1, "%s@%s", uid, dcc[idx].host);
       dcc_telnet_got_ident(i, buf1);
@@ -1784,9 +1768,8 @@ void
 eof_dcc_ident(int idx)
 {
   char buf[UHOSTLEN] = "";
-  int i;
 
-  for (i = 0; i < dcc_total; i++)
+  for (int i = 0; i < dcc_total; i++)
     if ((dcc[i].type == &DCC_IDENTWAIT) && (dcc[i].sock == dcc[idx].u.ident_sock)) {
       putlog(LOG_MISC, "*", DCC_EOFIDENT);
       simple_sprintf(buf, "telnet@%s", dcc[idx].host);
@@ -1800,7 +1783,7 @@ eof_dcc_ident(int idx)
 static void
 display_dcc_ident(int idx, char *buf)
 {
-  sprintf(buf, "idnt  (sock %d)", dcc[idx].u.ident_sock);
+  sprintf(buf, "idnt  (sock %li)", dcc[idx].u.ident_sock);
 }
 
 struct dcc_table DCC_IDENT = {
@@ -1820,7 +1803,6 @@ static void
 dcc_telnet_got_ident(int i, char *host)
 {
   int idx;
-  char x[1024] = "";
 
   for (idx = 0; idx < dcc_total; idx++)
     if ((dcc[idx].type == &DCC_TELNET) && (dcc[idx].sock == dcc[i].u.ident_sock))
@@ -1832,6 +1814,8 @@ dcc_telnet_got_ident(int i, char *host)
     lostdcc(i);
     return;
   }
+  char x[1024] = "";
+
   strncpyz(dcc[i].host, host, UHOSTLEN);
   egg_snprintf(x, sizeof x, "-telnet!%s", dcc[i].host);
 
@@ -1842,10 +1826,9 @@ dcc_telnet_got_ident(int i, char *host)
   }
 
   if (protect_telnet) {
-    struct userrec *u;
-    int ok = 1;
+    struct userrec *u = get_user_by_host(x);
+    bool ok = 1;
 
-    u = get_user_by_host(x);
     /* Not a user or +p & require p OR +o */
     if (!u)
       ok = 0;
@@ -1880,8 +1863,7 @@ dcc_telnet_got_ident(int i, char *host)
   egg_bzero(dcc[i].u.chat, sizeof(struct chat_info));
 
   /* Copy acceptable-nick/host mask */
-  dcc[i].status =
-    (STAT_TELNET | STAT_ECHO | STAT_COLOR | STAT_BANNER | STAT_CHANNELS | STAT_BOTS | STAT_WHOM);
+  dcc[i].status = (STAT_TELNET | STAT_ECHO | STAT_COLOR | STAT_BANNER | STAT_CHANNELS | STAT_BOTS | STAT_WHOM);
 
   /* Copy acceptable-nick/host mask */
   strncpyz(dcc[i].nick, dcc[idx].host, HANDLEN);

+ 13 - 13
src/dcc.h

@@ -15,8 +15,8 @@ struct dcc_table {
   char *name;
   int flags;
   void (*eof) (int);
-  void (*activity) (int, char *, int);
-  int *timeout_val;
+  void (*activity) (int, char *, size_t);
+  time_t *timeout_val;
   void (*timeout) (int);
   void (*display) (int, char *);
   void (*kill) (int, void *);
@@ -36,18 +36,18 @@ struct dcc_t {
     struct relay_info *relay;
     struct dns_info *dns;
     struct dupwait_info *dupwait;
-    int ident_sock;
+    sock_t ident_sock;
     void *other;
   } u;                          /* Special use depending on type        */
 
-  IP addr;                      /* IP address in host byte order         */
+  in_addr_t addr;                      /* IP address in host byte order         */
   time_t simultime;             /* the time when the simul dcc is initiated, expires after a number of seconds */
   time_t timeval;               /* Use for any timing stuff
                                    - this is used for timeout checking  */
   time_t pingtime;
-  unsigned long status;         /* A LOT of dcc types have status
+  size_t status;         /* A LOT of dcc types have status
                                    thingos, this makes it more avaliabe */
-  long sock;                    /* This should be a long to keep 64-bit
+  sock_t sock;                    /* This should be a long to keep 64-bit
                                    machines sane                         */
   int ssl;                      /* use ssl on this dcc? */
   int simul;                    /* this will hold the idx on the remote bot to return result. */
@@ -87,18 +87,18 @@ struct file_info {
 
 struct xfer_info {
   FILE *f;                      /* pointer to file being sent/received     */
-  unsigned long int length;
-  unsigned long int acked;
-  unsigned long int offset;     /* offset from beginning of file, during
+  size_t length;
+  size_t acked;
+  size_t offset;     /* offset from beginning of file, during
+
                                    resend.                                 */
-  unsigned long int block_pending;  	/* bytes of this DCC block which weren't
-                                   sent yet.                               */
+  size_t block_pending;  	/* bytes of this DCC block which weren't sent yet. */
+  size_t sofar;          /* how much of the byte count received     */
   unsigned int type;            /* xfer connection type, see enum below    */
   time_t start_time;            /* Time when a xfer was started.           */
   char *filename;
   char *origname;
   unsigned short ack_type;      /* type of ack                             */
-  unsigned char sofar;          /* how much of the byte count received     */
   char dir[DIRLEN];             /* used when uploads go to the current dir */
   char from[NICKLEN];           /* [GET] user who offered the file         */
   char buf[4];                  /* you only need 5 bytes!                  */
@@ -115,7 +115,7 @@ struct bot_info {
 
 struct relay_info {
   struct chat_info *chat;
-  long sock;
+  sock_t sock;
   int old_status;
   port_t port;
 };

+ 35 - 33
src/dccutil.c

@@ -29,7 +29,7 @@
 
 static struct portmap 	*root = NULL;
 
-int	connect_timeout = 15;		/* How long to wait before a telnet
+time_t	connect_timeout = 15;		/* How long to wait before a telnet
 					   connection times out */
 #ifdef HUB
 int         max_dcc = 200;
@@ -79,7 +79,7 @@ char *add_cr(char *buf)
 void dprintf(int idx, const char *format, ...)
 {
   static char buf[1024] = "";
-  int len;
+  size_t len;
   va_list va;
 
   va_start(va, format);
@@ -126,11 +126,11 @@ void dprintf(int idx, const char *format, ...)
     return;
   } else { /* normal chat text */
     if (coloridx(idx)) {
-      int i, schar = 0;
       static int cflags;
+      int schar = 0;
       char buf3[1024] = "", buf2[1024] = "", c = 0;
 
-      for (i = 0 ; i < len ; i++) {
+      for (size_t i = 0 ; i < len ; i++) {
         c = buf[i];
         buf2[0] = 0;
  
@@ -208,11 +208,9 @@ void dprintf(int idx, const char *format, ...)
     if (dcc[idx].simul > 0 && !dcc[idx].msgc) {
       bounce_simul(idx, buf);
     } else if (dcc[idx].msgc > 0) {
-      char *ircbuf = NULL;
-      size_t size = 0;
-      
-      size = strlen(dcc[idx].simulbot) + strlen(buf) + 20;
-      ircbuf = (char *) calloc(1, size);
+      size_t size = strlen(dcc[idx].simulbot) + strlen(buf) + 20;
+      char *ircbuf = (char *) calloc(1, size);
+
       egg_snprintf(ircbuf, size, "PRIVMSG %s :%s", dcc[idx].simulbot, buf);
       tputs(dcc[idx].sock, ircbuf, strlen(ircbuf));
       free(ircbuf);
@@ -232,7 +230,6 @@ void dprintf(int idx, const char *format, ...)
 
 void chatout(const char *format, ...)
 {
-  int i;
   char s[1025] = "", *p = NULL;
   va_list va;
 
@@ -243,7 +240,7 @@ void chatout(const char *format, ...)
   if ((p = strrchr(s, '\n')))
     *p++ = 0;
 
-  for (i = 0; i < dcc_total; i++)
+  for (int i = 0; i < dcc_total; i++)
     if ((dcc[i].type == &DCC_CHAT) && !(dcc[i].simul))
       if (dcc[i].u.chat->channel >= 0)
         dprintf(i, "%s\n", s);
@@ -253,7 +250,6 @@ void chatout(const char *format, ...)
  */
 void chanout_but(int x, int chan, const char *format, ...)
 {
-  int i;
   char s[1025] = "", *p = NULL;
   va_list va;
 
@@ -264,7 +260,7 @@ void chanout_but(int x, int chan, const char *format, ...)
   if ((p = strrchr(s, '\n')))
     *p = 0;
 
-  for (i = 0; i < dcc_total; i++)
+  for (int i = 0; i < dcc_total; i++)
     if ((dcc[i].type == &DCC_CHAT) && (i != x) && !(dcc[i].simul))
       if (dcc[i].u.chat->channel == chan)
         dprintf(i, "%s\n", s);
@@ -272,7 +268,8 @@ void chanout_but(int x, int chan, const char *format, ...)
 
 void dcc_chatter(int idx)
 {
-  int i, j;
+  int i;
+  sock_t j;
   struct flag_record fr = {FR_GLOBAL | FR_CHAN | FR_ANYWH, 0, 0, 0 };
 
   strcpy(dcc[idx].u.chat->con_chan, "***");
@@ -311,6 +308,7 @@ void dcc_chatter(int idx)
   }
 
   j = dcc[idx].sock;
+
   dcc[idx].u.chat->channel = 234567;
   /* Still there? */
 
@@ -353,7 +351,8 @@ void lostdcc(int n)
 {
 
   /* Make sure it's a valid dcc index. */
-  if (n < 0 || n >= max_dcc) return;
+  if (n < 0 || n >= max_dcc) 
+    return;
 
   if (dcc[n].type && dcc[n].type->kill)
     dcc[n].type->kill(n, dcc[n].u.other);
@@ -392,9 +391,7 @@ void removedcc(int n)
  */
 void dcc_remove_lost(void)
 {
-  int i;
-
-  for (i = 0; i < dcc_total; i++) {
+  for (int i = 0; i < dcc_total; i++) {
     if (dcc[i].type == &DCC_LOST) {
       dcc[i].type = NULL;
       dcc[i].sock = -1;
@@ -413,7 +410,8 @@ void dcc_remove_lost(void)
  */
 void tell_dcc(int idx)
 {
-  int i, j, nicklen = 0;
+  int i;
+  size_t j, nicklen = 0;
   char other[160] = "", format[81] = "";
 
   /* calculate max nicklen */
@@ -421,7 +419,8 @@ void tell_dcc(int idx)
       if(strlen(dcc[i].nick) > (unsigned) nicklen)
           nicklen = strlen(dcc[i].nick);
   }
-  if(nicklen < 9) nicklen = 9;
+  if(nicklen < 9) 
+    nicklen = 9;
   
   egg_snprintf(format, sizeof format, "%%-4s %%-4s %%-8s %%-5s %%-%us %%-40s %%s\n", nicklen);
   dprintf(idx, format, "SOCK", "IDX", "ADDR",     "PORT",  "NICK", "HOST", "TYPE");
@@ -558,11 +557,11 @@ void changeover_dcc(int i, struct dcc_table *type, int xtra_size)
 
 int detect_dcc_flood(time_t * timer, struct chat_info *chat, int idx)
 {
-  time_t t;
-
   if (!dcc_flood_thr)
     return 0;
-  t = now;
+
+  time_t t = now;
+
   if (*timer != t) {
     *timer = t;
     chat->msgs_per_sec = 0;
@@ -626,13 +625,17 @@ void do_boot(int idx, char *by, char *reason)
   return;
 }
 
-int listen_all(int lport, int off)
+port_t listen_all(port_t lport, bool off)
 {
-  int i, idx = (-1);
+  if (!lport)
+    return 0;
+
+  int idx = (-1);
   port_t port, realport;
 #ifdef USE_IPV6
-  int i6 = 0;
+  sock_t i6 = 0;
 #endif /* USE_IPV6 */
+  sock_t i;
   struct portmap *pmap = NULL, *pold = NULL;
 
   port = realport = lport;
@@ -642,9 +645,9 @@ int listen_all(int lport, int off)
       break;
     }
 
-  for (i = 0; i < dcc_total; i++) {
-    if ((dcc[i].type == &DCC_TELNET) && (dcc[i].port == port)) {
-      idx = i;
+  for (int ii = 0; ii < dcc_total; ii++) {
+    if ((dcc[ii].type == &DCC_TELNET) && (dcc[ii].port == port)) {
+      idx = ii;
 
       if (off) {
         if (pmap) {
@@ -735,7 +738,8 @@ int listen_all(int lport, int off)
 
 void identd_open()
 {
-  int idx = -1, i = -1;
+  int idx;
+  sock_t i = -1;
   port_t port = 113;
 
   for (idx = 0; idx < dcc_total; idx++)
@@ -773,9 +777,7 @@ void identd_open()
 
 void identd_close()
 {
-  int idx;
-
-  for (idx = 0; idx < dcc_total; idx++) {
+  for (int idx = 0; idx < dcc_total; idx++) {
     if (dcc[idx].type == &DCC_IDENTD_CONNECT) {
       killsock(dcc[idx].sock);
       lostdcc(idx);

+ 3 - 1
src/dccutil.h

@@ -46,7 +46,9 @@ void do_boot(int, char *, char *);
 int detect_dcc_flood(time_t *, struct chat_info *, int);
 void identd_open();
 void identd_close();
+port_t listen_all(port_t, bool);
 
-extern int		max_dcc, connect_timeout;
+extern int		max_dcc;
+extern time_t		connect_timeout;
 
 #endif /* !_DCCUTIL_H */

+ 12 - 24
src/debug.c

@@ -29,7 +29,7 @@
 #include <sys/mman.h>
 #define PAGESIZE 4096
 
-int		sdebug = 0;             /* enable debug output? */
+bool		sdebug = 0;             /* enable debug output? */
 
 
 #ifdef DEBUG_CONTEXT
@@ -74,8 +74,7 @@ void setlimits()
 
 void init_debug()
 {
-  int i = 0;
-  for (i = 0; i < 16; i ++)
+  for (int i = 0; i < 16; i ++)
     Context;
 
 #ifdef DEBUG_CONTEXT
@@ -107,7 +106,7 @@ void sdprintf (char *format, ...)
 
 static void write_debug()
 {
-  int x;
+  sock_t x;
   char s[25] = "", tmpout[150] = "", buf[DIRMAX] = "";
   int y;
 
@@ -352,15 +351,11 @@ void init_signals()
 
 #ifdef DEBUG_CONTEXT
 /* Context */
-void eggContext(const char *file, int line, const char *module)
+void eggContext(const char *file, int line)
 {
-  char x[31] = "", *p = NULL;
+  char x[31] = "", *p = strrchr(file, '/');
 
-  p = strrchr(file, '/');
-  if (!module) {
-    strncpyz(x, p ? p + 1 : file, sizeof x);
-  } else
-    egg_snprintf(x, 31, "%s:%s", module, p ? p + 1 : file);
+  strncpyz(x, p ? p + 1 : file, sizeof x);
   cx_ptr = ((cx_ptr + 1) & 15);
   strcpy(cx_file[cx_ptr], x);
   cx_line[cx_ptr] = line;
@@ -369,16 +364,11 @@ void eggContext(const char *file, int line, const char *module)
 
 /* Called from the ContextNote macro.
  */
-void eggContextNote(const char *file, int line, const char *module, const char *note)
+void eggContextNote(const char *file, int line, const char *note)
 {
-  char x[31] = "", *p = NULL;
+  char x[31] = "", *p = strrchr(file, '/');
 
-  p = strrchr(file, '/');
-  if (!module) {
-    strncpyz(x, p ? p + 1 : file, sizeof x);
-  } else {
-    egg_snprintf(x, 31, "%s:%s", module, p ? p + 1 : file);
-  }
+  strncpyz(x, p ? p + 1 : file, sizeof x);
   cx_ptr = ((cx_ptr + 1) & 15);
   strcpy(cx_file[cx_ptr], x);
   cx_line[cx_ptr] = line;
@@ -389,12 +379,10 @@ void eggContextNote(const char *file, int line, const char *module, const char *
 #ifdef DEBUG_ASSERT
 /* Called from the Assert macro.
  */
-void eggAssert(const char *file, int line, const char *module)
+void eggAssert(const char *file, int line)
 {
-  if (!module)
-    putlog(LOG_MISC, "*", "* In file %s, line %u", file, line);
-  else
-    putlog(LOG_MISC, "*", "* In file %s:%s, line %u", module, file, line);
+  putlog(LOG_MISC, "*", "* In file %s, line %u", file, line);
+
 #ifdef DEBUG_CONTEXT
   write_debug();
 #endif /* DEBUG_CONTEXT */

+ 7 - 7
src/debug.h

@@ -16,8 +16,8 @@
  *    Handy aliases for memory tracking and core dumps
  */
 #ifdef DEBUG_CONTEXT
-#  define Context               eggContext(__FILE__, __LINE__, NULL)
-#  define ContextNote(note)     eggContextNote(__FILE__, __LINE__, NULL, note)
+#  define Context               eggContext(__FILE__, __LINE__)
+#  define ContextNote(note)     eggContextNote(__FILE__, __LINE__, note)
 #else
 #  define Context               {}
 #  define ContextNote(note)     {}
@@ -26,7 +26,7 @@
 #ifdef DEBUG_ASSERT
 #  define Assert(expr)  do {                                            \
         if (!(expr))                                                    \
-                eggAssert(__FILE__, __LINE__, NULL);                    \
+                eggAssert(__FILE__, __LINE__);                          \
 } while (0)
 #else
 #  define Assert(expr)  do {    } while (0)
@@ -39,15 +39,15 @@
 #define debug4(x,a1,a2,a3,a4)   putlog(LOG_DEBUG,"*",x,a1,a2,a3,a4)
 
 
-extern int		sdebug;
+extern bool		sdebug;
 
 void stackdump(int);
 void setlimits();
 void sdprintf (char *, ...) __attribute__((format(printf, 1, 2)));
 void init_signals();
 void init_debug();
-void eggContext(const char *, int, const char *);
-void eggContextNote(const char *, int, const char *, const char *);
-void eggAssert(const char *, int, const char *);
+void eggContext(const char *, int);
+void eggContextNote(const char *, int, const char *);
+void eggAssert(const char *, int);
 
 #endif /* !_DEBUG_H */

+ 12 - 16
src/dns.c

@@ -27,7 +27,7 @@ devent_t	*dns_events = NULL;
  *   DCC functions
  */
 
-void dcc_dnswait(int idx, char *buf, int len)
+void dcc_dnswait(int idx, char *buf, size_t len)
 {
   /* Ignore anything now. */
 }
@@ -80,11 +80,9 @@ struct dcc_table DCC_DNSWAIT =
 /* Walk through every dcc entry and look for waiting DNS requests
  * of RES_HOSTBYIP for our IP address.
  */
-static void dns_dcchostbyip(IP ip, char *hostn, int ok, void *other)
+static void dns_dcchostbyip(in_addr_t ip, char *hostn, int ok, void *other)
 {
-  int idx;
-
-  for (idx = 0; idx < dcc_total; idx++) {
+  for (int idx = 0; idx < dcc_total; idx++) {
     if ((dcc[idx].type == &DCC_DNSWAIT) &&
         (dcc[idx].u.dns->dns_type == RES_HOSTBYIP) &&
         (dcc[idx].u.dns->ip == ip)) {
@@ -103,11 +101,9 @@ static void dns_dcchostbyip(IP ip, char *hostn, int ok, void *other)
 /* Walk through every dcc entry and look for waiting DNS requests
  * of RES_IPBYHOST for our hostname.
  */
-static void dns_dccipbyhost(IP ip, char *hostn, int ok, void *other)
+static void dns_dccipbyhost(in_addr_t ip, char *hostn, int ok, void *other)
 {
-  int idx;
-
-  for (idx = 0; idx < dcc_total; idx++) {
+  for (int idx = 0; idx < dcc_total; idx++) {
     if ((dcc[idx].type == &DCC_DNSWAIT) &&
         (dcc[idx].u.dns->dns_type == RES_IPBYHOST) &&
         !egg_strcasecmp(dcc[idx].u.dns->host, hostn)) {
@@ -158,7 +154,7 @@ void dcc_dnsipbyhost(char *hostn)
   dns_ipbyhost(hostn);
 }
 
-void dcc_dnshostbyip(IP ip)
+void dcc_dnshostbyip(in_addr_t ip)
 {
   devent_t *de = NULL;
 
@@ -191,7 +187,7 @@ void dcc_dnshostbyip(IP ip)
  *    Event functions
  */
 
-void call_hostbyip(IP ip, char *hostn, int ok)
+void call_hostbyip(in_addr_t ip, char *hostn, int ok)
 {
   devent_t *de = dns_events, *ode = NULL, *nde = NULL;
 
@@ -219,7 +215,7 @@ void call_hostbyip(IP ip, char *hostn, int ok)
   }
 }
 
-void call_ipbyhost(char *hostn, IP ip, int ok)
+void call_ipbyhost(char *hostn, in_addr_t ip, int ok)
 {
   devent_t *de = dns_events, *ode = NULL, *nde = NULL;
 
@@ -256,10 +252,10 @@ void call_ipbyhost(char *hostn, IP ip, int ok)
  *    Async DNS emulation functions
  */
 
-void block_dns_hostbyip(IP ip)
+void block_dns_hostbyip(in_addr_t ip)
 {
   struct hostent *hp = NULL;
-  IP addr = htonl(ip);
+  in_addr_t addr = htonl(ip);
   static char s[UHOSTLEN] = "";
 
   if (!setjmp(alarmret)) {
@@ -291,7 +287,7 @@ void block_dns_ipbyhost(char *host)
   if (!setjmp(alarmret)) {
     struct hostent *hp = NULL;
     struct in_addr *in = NULL;
-    IP ip = 0;
+    in_addr_t ip = 0;
 
     alarm(resolve_timeout);
     hp = gethostbyname(host);
@@ -299,7 +295,7 @@ void block_dns_ipbyhost(char *host)
 
     if (hp) {
       in = (struct in_addr *) (hp->h_addr_list[0]);
-      ip = (IP) (in->s_addr);
+      ip = (in_addr_t) (in->s_addr);
       call_ipbyhost(host, ntohl(ip), 1);
       return;
     }

+ 7 - 7
src/dns.h

@@ -18,7 +18,7 @@
 struct dns_info {
   struct dcc_table *type;       /* type of the dcc table we are making the
                                    lookup for                              */
-  IP ip;                        /* IP address                              */
+  in_addr_t ip;                        /* IP address                              */
   int ibuf;                     /* temporary buffer for one integer        */
   void (*dns_success)(int);     /* is called if the dns request succeeds   */
   void (*dns_failure)(int);     /* is called if it fails                   */
@@ -31,7 +31,7 @@ struct dns_info {
 
 typedef struct {
   char *name;
-  void (*event)(IP, char *, int, void *);
+  void (*event)(in_addr_t, char *, int, void *);
 } devent_type;
 
 typedef struct {
@@ -43,18 +43,18 @@ typedef struct devent_str {
   struct devent_str *next;	/* Pointer to next dns_event	  */
   devent_type	*type;
   union {
-    IP		ip_addr;	/* IP address			  */
+    in_addr_t		ip_addr;	/* IP address			  */
     char	*hostname; 	/* Hostname			  */
   } res_data;
   void		*other;		/* Data specific to the event type */
   u_8bit_t	lookup;		/* RES_IPBYHOST or RES_HOSTBYIP	  */
 } devent_t;
 
-void block_dns_hostbyip(IP);
+void block_dns_hostbyip(in_addr_t);
 void block_dns_ipbyhost(char *);
-void call_hostbyip(IP, char *, int);
-void call_ipbyhost(char *, IP, int);
-void dcc_dnshostbyip(IP);
+void call_hostbyip(in_addr_t, char *, int);
+void call_ipbyhost(char *, in_addr_t, int);
+void dcc_dnshostbyip(in_addr_t);
 void dcc_dnsipbyhost(char *);
 
 

+ 15 - 11
src/flags.c

@@ -103,10 +103,11 @@ chan_sanity_check(flag_t chatr)
 char
 geticon(int idx)
 {
-  struct flag_record fr = { FR_GLOBAL | FR_CHAN | FR_ANYWH, 0, 0, 0 };
-
   if (!dcc[idx].user)
     return '-';
+
+  struct flag_record fr = { FR_GLOBAL | FR_CHAN | FR_ANYWH, 0, 0, 0 };
+
   get_user_flagrec(dcc[idx].user, &fr, NULL);
   if (glob_admin(fr))
     return '^';
@@ -302,13 +303,15 @@ flagrec_eq(struct flag_record *req, struct flag_record *have)
 void
 set_user_flagrec(struct userrec *u, struct flag_record *fr, const char *chname)
 {
+  if (!u)
+    return;
+
   struct chanuserrec *cr = NULL;
-  int oldflags = fr->match;
+  flag_t oldflags = fr->match;
   char buffer[100] = "";
   struct chanset_t *ch;
 
-  if (!u)
-    return;
+
   if (oldflags & FR_GLOBAL) {
     u->flags = fr->global;
 
@@ -348,14 +351,13 @@ set_user_flagrec(struct userrec *u, struct flag_record *fr, const char *chname)
 void
 get_user_flagrec(struct userrec *u, struct flag_record *fr, const char *chname)
 {
-  struct chanuserrec *cr = NULL;
-
   fr->bot = 0;
   if (!u) {
     fr->global = fr->chan = 0;
 
     return;
   }
+
   if (u->bot)
     fr->bot = 1;
   if (fr->match & FR_GLOBAL) {
@@ -365,6 +367,8 @@ get_user_flagrec(struct userrec *u, struct flag_record *fr, const char *chname)
   }
 
   if (fr->match & FR_CHAN) {
+    struct chanuserrec *cr = NULL;
+
     if ((fr->match & FR_ANYWH) || (fr->match & FR_ANYCH)) {
       if (fr->match & FR_ANYWH)
         fr->chan = u->flags;
@@ -490,11 +494,11 @@ ischanhub()
 int
 dovoice(struct chanset_t *chan)
 {
-  struct flag_record fr = { FR_GLOBAL | FR_CHAN, 0, 0, 0 };
-
   if (!chan)
     return 0;
 
+  struct flag_record fr = { FR_GLOBAL | FR_CHAN, 0, 0, 0 };
+
   get_user_flagrec(conf.bot->u, &fr, chan->dname);
   if (glob_dovoice(fr) || chan_dovoice(fr))
     return 1;
@@ -504,11 +508,11 @@ dovoice(struct chanset_t *chan)
 int
 dolimit(struct chanset_t *chan)
 {
-  struct flag_record fr = { FR_GLOBAL | FR_CHAN, 0, 0, 0 };
-
   if (!chan)
     return 0;
 
+  struct flag_record fr = { FR_GLOBAL | FR_CHAN, 0, 0, 0 };
+
   get_user_flagrec(conf.bot->u, &fr, chan->dname);
   if (glob_dolimit(fr) || chan_dolimit(fr))
     return 1;

+ 1 - 2
src/garble.c

@@ -18,7 +18,6 @@ int garble_ptr = (-1);
 
 char *degarble(int len, char *g)
 {
-  int i;
   unsigned char x = 0;
 
   garble_ptr++;
@@ -28,7 +27,7 @@ char *degarble(int len, char *g)
     free(garble_buffer[garble_ptr]);
   garble_buffer[garble_ptr] = (unsigned char *) calloc(1, len + 1);
   x = 0xFF;
-  for (i = 0; i < len; i++) {
+  for (int i = 0; i < len; i++) {
     garble_buffer[garble_ptr][i] = g[i] ^ x;
     x = garble_buffer[garble_ptr][i];
   }

+ 33 - 36
src/log.c

@@ -23,35 +23,35 @@
 #include <stdarg.h>
 
 int	conmask = LOG_MODES | LOG_CMDS | LOG_MISC; /* Console mask */
-int	debug_output = 1;      /* Disply output to server to LOG_SERVEROUT */
-int 	use_console_r = 1;      /* Allow users to set their console +r  */
+bool	debug_output = 1;      /* Disply output to server to LOG_SERVEROUT */
+bool 	use_console_r = 1;      /* Allow users to set their console +r  */
 
 typedef struct {
 	int flag;
-	unsigned char c;
 	char *type;
+	unsigned char c;
 } logmode_mapping_t;
 
 static logmode_mapping_t logmode_mappings[] = {
-	{LOG_MSGS, 'm', "msgs"},
-	{LOG_PUBLIC, 'p', "public"},
-	{LOG_JOIN, 'j', "joins"},
-	{LOG_MODES, 'k', "kicks/modes"},
-	{LOG_CMDS, 'c', "cmds"},
-	{LOG_MISC, 'o', "misc"},
-	{LOG_BOTS, 'b', "bots"},
-	{LOG_RAW, 'r', "raw"},
-	{LOG_WALL, 'w', "wallops"},
-	{LOG_FILES, 'x', "files"},
-	{LOG_SERV, 's', "server"},
-	{LOG_DEBUG, 'd', "debug"},
-	{LOG_SRVOUT, 'v', "server output"},
-	{LOG_BOTNET, 't', "botnet traffic"},
-	{LOG_BOTSHARE, 'h', "share traffic"},
-	{LOG_ERRORS, 'e', "errors"},
-	{LOG_GETIN, 'g', "getin"},
-	{LOG_WARN, 'u', "warnings"},
-	{0, 0, NULL}
+	{LOG_MSGS, "msgs", 'm'},
+	{LOG_PUBLIC, "public", 'p'},
+	{LOG_JOIN, "joins", 'j'},
+	{LOG_MODES, "kicks/modes", 'k'},
+	{LOG_CMDS, "cmds", 'c'},
+	{LOG_MISC, "misc", 'o'},
+	{LOG_BOTS, "bots", 'b'},
+	{LOG_RAW, "raw", 'r'},
+	{LOG_WALL, "wallops", 'w'},
+	{LOG_FILES, "files", 'x'},
+	{LOG_SERV, "server", 's'},
+	{LOG_DEBUG, "debug", 'd'},
+	{LOG_SRVOUT, "server output", 'v'},
+	{LOG_BOTNET, "botnet traffic", 't'},
+	{LOG_BOTSHARE, "share traffic", 'h'},
+	{LOG_ERRORS, "errors", 'e'},
+	{LOG_GETIN, "getin", 'g'},
+	{LOG_WARN, "warnings", 'u'},
+	{0, NULL, 0}
 };
 #define LOG_LEVELS 18 		/* change this if you change the levels */
 
@@ -62,6 +62,7 @@ int logmodes(const char *s)
 {
 	logmode_mapping_t *mapping = NULL;
 	int modes = 0;
+
 	while (*s) {
 		if (*s == '*') return(LOG_ALL);
 		for (mapping = logmode_mappings; mapping->type; mapping++) {
@@ -136,20 +137,10 @@ void logidx(int idx, const char *format, ...)
  */
 void putlog(int type, const char *chname, const char *format, ...)
 {
-  int idx = 0;
-  char va_out[LOGLINEMAX + 1] = "", out[LOGLINEMAX + 1] = "", *p = NULL;
-#ifdef HUB
-  char stamp[34] = "";
-  struct tm *t = NULL;
-#endif /* HUB */
+  char va_out[LOGLINEMAX + 1] = "";
   va_list va;
 
   va_start(va, format);
-#ifdef HUB
-  t = gmtime(&now);
-
-  egg_strftime(stamp, sizeof(stamp), LOG_TS, t);
-#endif /* HUB */
 
   /* No need to check if out should be null-terminated here,
    * just do it! <cybah>
@@ -162,14 +153,20 @@ void putlog(int type, const char *chname, const char *format, ...)
     return;
   }
 
+  char *p = NULL;
+
   if ((p = strchr(va_out, '\n')))		/* make sure no trailing newline */
      *p = 0;
 
-
+  int idx = 0;
+  char out[LOGLINEMAX + 1] = "";
 #ifdef HUB
+  char stamp[34] = "";
+  struct tm *t = gmtime(&now);
+
+  egg_strftime(stamp, sizeof(stamp), LOG_TS, t);
   /* Place the timestamp in the string to be printed */
-  if (stamp[0])
-    egg_snprintf(out, sizeof out, "%s %s", stamp, va_out);
+  egg_snprintf(out, sizeof out, "%s %s", stamp, va_out);
 #endif /* HUB */
 #ifdef LEAF
   egg_snprintf(out, sizeof out, "%s", va_out);

+ 2 - 1
src/log.h

@@ -35,6 +35,7 @@ char *masktype(int);
 char *maskname(int);
 void irc_log(struct chanset_t *, const char *, ...) __attribute__((format(printf, 2, 3)));
 
-extern int		conmask, debug_output, use_console_r;
+extern int		conmask;
+extern bool		debug_output, use_console_r;
 
 #endif /* !_LOG_H */

+ 32 - 44
src/main.c

@@ -67,15 +67,15 @@ char *mymd5 = bdhash;
 const time_t 	buildts = CVSBUILD;		/* build timestamp (UTC) */
 const char	egg_version[1024] = "1.2";
 
-int 	localhub = 1; 		/* we set this to 0 if we get a -B */
+bool 	localhub = 1; 		/* we set this to 0 if we get a -B */
 int 	role;
-int 	loading = 0;
+bool 	loading = 0;
 int	default_flags = 0;	/* Default user flags and */
 int	default_uflags = 0;	/* Default userdefinied flags for people
 				   who say 'hello' or for .adduser */
-int	backgrd = 1;		/* Run in the background? */
+bool	backgrd = 1;		/* Run in the background? */
 uid_t   myuid;
-int	term_z = 0;		/* Foreground: use the terminal as a party line? */
+bool	term_z = 0;		/* Foreground: use the terminal as a party line? */
 int 	updating = 0; 		/* this is set when the binary is called from itself. */
 char 	tempdir[DIRMAX] = "";
 char 	*binname = NULL;
@@ -84,24 +84,22 @@ time_t	online_since;		/* Unix-time that the bot loaded up */
 char	owner[121] = "";	/* Permanent owner(s) of the bot */
 char	version[81] = "";	/* Version info (long form) */
 char	ver[41] = "";		/* Version info (short form) */
-int	use_stderr = 1;		/* Send stuff to stderr instead of logfiles? */
+bool	use_stderr = 1;		/* Send stuff to stderr instead of logfiles? */
 char	quit_msg[1024];		/* quit message */
 time_t	now;			/* duh, now :) */
 
 #define fork_interval atoi( CFG_FORKINTERVAL.ldata ? CFG_FORKINTERVAL.ldata : CFG_FORKINTERVAL.gdata ? CFG_FORKINTERVAL.gdata : "0")
-static int	do_confedit = 0;		/* show conf menu if -C */
+static bool do_confedit = 0;		/* show conf menu if -C */
 #ifdef LEAF
-static char    do_killbot[21] = "";
+static char do_killbot[21] = "";
 #endif /* LEAF */
 static char *update_bin = NULL;
-static int 	checktrace = 1;		/* Check for trace when starting up? */
+static bool checktrace = 1;		/* Check for trace when starting up? */
 
 
 static char *getfullbinname(const char *argv_zero)
 {
-  char cwd[DIRMAX] = "", *bin = NULL, *p = NULL, *p2 = NULL;
-
-  bin = strdup(argv_zero);
+  char *bin = strdup(argv_zero);
 
   if (bin[0] == '/')
 #ifdef CYGWIN_HACKS
@@ -110,14 +108,16 @@ static char *getfullbinname(const char *argv_zero)
     return bin;
 #endif /* CYGWIN_HACKS */
 
+  char cwd[DIRMAX] = "";
+
   if (!getcwd(cwd, DIRMAX))
     fatal("getcwd() failed", 0);
 
   if (cwd[strlen(cwd) - 1] == '/')
     cwd[strlen(cwd) - 1] = 0;
 
-  p = bin;
-  p2 = strchr(p, '/');
+  char *p = bin, *p2 = strchr(p, '/');
+
   while (p) {
     if (p2)
       *p2++ = 0;
@@ -146,8 +146,6 @@ static char *getfullbinname(const char *argv_zero)
 
 void fatal(const char *s, int recoverable)
 {
-  int i = 0;
-
 #ifdef LEAF
   nuke_server((char *) s);
 #endif /* LEAF */
@@ -164,7 +162,7 @@ void fatal(const char *s, int recoverable)
   listen_all(my_port, 1); /* close the listening port... */
 #endif /* HUB */
 
-  for (i = 0; i < dcc_total; i++)
+  for (int i = 0; i < dcc_total; i++)
     if (dcc[i].sock >= 0)
       killsock(dcc[i].sock);
 
@@ -177,9 +175,7 @@ void fatal(const char *s, int recoverable)
 
 static void check_expired_dcc()
 {
-  int i;
-
-  for (i = 0; i < dcc_total; i++)
+  for (int i = 0; i < dcc_total; i++)
     if (dcc[i].type && dcc[i].type->timeout_val &&
 	((now - dcc[i].timeval) > *(dcc[i].type->timeout_val))) {
       if (dcc[i].type->timeout)
@@ -195,9 +191,7 @@ static void check_expired_dcc()
 
 /* this also expires irc dcc_cmd auths */
 static void expire_simuls() {
-  int idx = 0;
-
-  for (idx = 0; idx < dcc_total; idx++) {
+  for (int idx = 0; idx < dcc_total; idx++) {
     if (dcc[idx].simul > 0) {
       if ((now - dcc[idx].simultime) >= 20) { /* expire simuls after 20 seconds (re-uses idx, so it wont fill up) */
         dcc[idx].simul = -1;
@@ -388,7 +382,7 @@ static void dtx_arg(int argc, char *argv[])
 }
 
 /* Timer info */
-static int		lastmin = 99;
+static time_t		lastmin = 99;
 static struct tm	nowtm;
 
 void core_10secondly()
@@ -445,7 +439,7 @@ static void event_resettraffic()
 static void core_secondly()
 {
   static int cnt = 0;
-  int miltime;
+  time_t miltime;
 
 #ifdef CRAZY_TRACE 
   if (!attached) crazy_trace();
@@ -461,19 +455,19 @@ static void core_secondly()
 
   egg_memcpy(&nowtm, gmtime(&now), sizeof(struct tm));
   if (nowtm.tm_min != lastmin) {
-    int i = 0;
+    time_t i = 0;
 
     /* Once a minute */
     lastmin = (lastmin + 1) % 60;
     /* In case for some reason more than 1 min has passed: */
     while (nowtm.tm_min != lastmin) {
       /* Timer drift, dammit */
-      debug2("timer: drift (lastmin=%d, now=%d)", lastmin, nowtm.tm_min);
+      debug2("timer: drift (lastmin=%lu, now=%d)", lastmin, nowtm.tm_min);
       i++;
       lastmin = (lastmin + 1) % 60;
     }
     if (i > 1)
-      putlog(LOG_MISC, "*", "(!) timer drift -- spun %d minutes", i);
+      putlog(LOG_MISC, "*", "(!) timer drift -- spun %lu minutes", i);
     miltime = (nowtm.tm_hour * 100) + (nowtm.tm_min);
     if (((int) (nowtm.tm_min / 5) * 5) == (nowtm.tm_min)) {	/* 5 min */
 /* 	flushlogs(); */
@@ -521,7 +515,7 @@ static void core_halfhourly()
 /* FIXME: Remove after 1.2 */
 static void startup_checks() {
   int enc = CONF_ENC;
-  int old_hack = 0;
+  bool old_hack = 0;
 
   /* for compatability with old conf files 
    * only check/use conf file if it exists and settings.uname is empty.
@@ -592,7 +586,6 @@ static void startup_checks() {
   else if (settings.uname[0])
     bin_to_conf();
 
-
 #ifndef CYGWIN_HACKS
   if (do_confedit)
     confedit();		/* this will exit() */
@@ -640,7 +633,7 @@ static void startup_checks() {
     ContextNote("realpath(): Success");
     /* running from wrong dir, or wrong bin name.. lets try to fix that :) */
     if (strcmp(binname, newbin) && strcmp(newbin, real)) { 		/* if wrong path and new path != current */
-      int ok = 1;
+      bool ok = 1;
 
       sdprintf("real: %s", real);
       sdprintf("wrong dir, is: %s :: %s", binname, newbin);
@@ -724,11 +717,9 @@ void transfer_init();
 
 int main(int argc, char **argv)
 {
-//printf("YAY!\n\n\n\n\n\n\n\n");
-//exit(0);
   egg_timeval_t egg_timeval_now;
 
-  Context;
+  Context;		/* FIXME: wtf is this here for?, probably some old hack to fix a corrupt heap */
 /*
   char *out = NULL;
 printf("ret: %d\n", system("c:/wraith/leaf.exe"));
@@ -754,10 +745,8 @@ printf("out: %s\n", out);
 
 #ifdef STOP_UAC
   {
-    int nvpair[2];
+    int nvpair[2] = { SSIN_UACPROC, UAC_NOPRINT };
 
-    nvpair[0] = SSIN_UACPROC;
-    nvpair[1] = UAC_NOPRINT;
     setsysinfo(SSI_NVPAIRS, (char *) nvpair, 1, NULL, 0);
   }
 #endif
@@ -867,10 +856,9 @@ printf("out: %s\n", out);
 
 #if defined(LEAF) && defined(__linux__)
   if (conf.pscloak) {
-    int argi;
     const char *p = response(RES_PSCLOAK);
 
-    for (argi = 0; argi < argc; argi++)
+    for (int argi = 0; argi < argc; argi++)
       egg_memset(argv[argi], 0, strlen(argv[argi]));
 
     strcpy(argv[0], p);
@@ -953,7 +941,7 @@ printf("out: %s\n", out);
   debug0("main: entering loop");
 
   while (1) {
-    int socket_cleanup = 0, i, xx, status = 0;
+    int socket_cleanup = 0, status = 0, xx, i = 0;
     char buf[SGRAB + 10] = "";
 
 #ifndef CYGWIN_HACKS
@@ -981,12 +969,10 @@ printf("out: %s\n", out);
     } else
       socket_cleanup--;
 
-    xx = sockgets(buf, &i); 
+    xx = sockgets(buf, &i);
 
     if (xx >= 0) {		/* Non-error */
-      int idx;
-
-      for (idx = 0; idx < dcc_total; idx++)
+      for (int idx = 0; idx < dcc_total; idx++) {
 	if (dcc[idx].sock == xx) {
 	  if (dcc[idx].type && dcc[idx].type->activity) {
 	    /* Traffic stats */
@@ -1013,12 +999,13 @@ printf("out: %s\n", out);
 		   dcc[idx].type->name, dcc[idx].sock);
 	  break;
 	}
+      }
     } else if (xx == -1) {	/* EOF from someone */
       int idx;
 
       if (i == STDOUT && !backgrd)
 	fatal("END OF FILE ON TERMINAL", 0);
-      for (idx = 0; idx < dcc_total; idx++)
+      for (idx = 0; idx < dcc_total; idx++) {
 	if (dcc[idx].sock == i) {
 	  if (dcc[idx].type && dcc[idx].type->eof)
 	    dcc[idx].type->eof(idx);
@@ -1031,6 +1018,7 @@ printf("out: %s\n", out);
 	  }
 	  idx = dcc_total + 1;
 	}
+      }
       if (idx == dcc_total) {
 	putlog(LOG_MISC, "*", "(@) EOF socket %d, not a dcc socket, not anything.", i);
 	close(i);

+ 3 - 2
src/main.h

@@ -3,8 +3,9 @@
 
 #include <sys/types.h>
 
-extern int		localhub, role, loading, default_flags, default_uflags,
-			backgrd, term_z, updating, use_stderr;
+extern int		role, default_flags, default_uflags,
+			updating;
+extern bool		use_stderr, backgrd, localhub, term_z, loading;
 extern char		tempdir[], *binname, owner[], version[], ver[], quit_msg[];
 extern char		*mymd5;
 extern time_t		online_since, now;

+ 10 - 7
src/match.c

@@ -37,14 +37,14 @@
 
 int wild_match_per(register char *m, register char *n)
 {
-  char *ma = m, *lsm = NULL, *lsn = NULL, *lpm = NULL, *lpn = NULL;
-  int match = 1, saved = 0, space;
-  register int sofar = 0;
-
   /* null strings should never match */
   if ((m == 0) || (n == 0) || (!*n))
     return NOMATCH;
 
+  char *ma = m, *lsm = NULL, *lsn = NULL, *lpm = NULL, *lpn = NULL;
+  int match = 1, saved = 0, space;
+  register int sofar = 0;
+
   while (*n) {
     if (*m == WILDT) {          /* Match >=1 space */
       space = 0;                /* Don't need any spaces */
@@ -132,13 +132,16 @@ int wild_match_per(register char *m, register char *n)
 
 int wild_match(register char *m, register char *n)
 {
-  char *ma = m, *na = n, *lsm = NULL, *lsn = NULL;
-  int match = 1;
-  register int sofar = 0;
+  char *ma = m, *na = n;
 
   /* null strings should never match */
   if ((ma == 0) || (na == 0) || (!*ma) || (!*na))
     return NOMATCH;
+
+  char *lsm = NULL, *lsn = NULL;
+  int match = 1;
+  register int sofar = 0;
+
   /* find the end of each string */
   while (*(++m));
   m--;

+ 63 - 71
src/misc.c

@@ -37,8 +37,8 @@
 #include <stdarg.h>
 
 int		server_lag = 0;	/* GUESS! */
-int		use_invites = 1;            /* Jason/drummer */
-int		use_exempts = 1;            /* Jason/drummer */
+bool		use_invites = 1;            /* Jason/drummer */
+bool		use_exempts = 1;            /* Jason/drummer */
 
 /*
  *    Misc functions
@@ -66,7 +66,7 @@ int		use_exempts = 1;            /* Jason/drummer */
  *
  *	<Cybah>
  */
-int egg_strcatn(char *dst, const char *src, size_t max)
+size_t egg_strcatn(char *dst, const char *src, size_t max)
 {
   size_t tmpmax = 0;
 
@@ -96,7 +96,7 @@ int egg_strcatn(char *dst, const char *src, size_t max)
   return tmpmax - max;
 }
 
-int my_strcpy(register char *a, register char *b)
+size_t my_strcpy(register char *a, register char *b)
 {
   register char *c = b;
 
@@ -110,9 +110,7 @@ int my_strcpy(register char *a, register char *b)
  */
 void splitc(char *first, char *rest, char divider)
 {
-  char *p = NULL;
-
-  p = strchr(rest, divider);
+  char *p = strchr(rest, divider);
 
   if (p == NULL) {
     if (first != rest && first)
@@ -143,9 +141,7 @@ void splitc(char *first, char *rest, char divider)
  */
 void splitcn(char *first, char *rest, char divider, size_t max)
 {
-  char *p = NULL;
-
-  p = strchr(rest, divider);
+  char *p = strchr(rest, divider);
 
   if (p == NULL) {
     if (first != rest && first)
@@ -189,11 +185,11 @@ void remove_crlf(char *line)
 
 char *newsplit(char **rest)
 {
-  register char *o = NULL, *r = NULL;
-
   if (!rest)
     return *rest = "";
-  o = *rest;
+
+  register char *o = *rest, *r = NULL;
+
   while (*o == ' ')
     o++;
   r = o;
@@ -309,13 +305,14 @@ void maskhost(const char *s, char *nw)
  */
 void dumplots(int idx, const char *prefix, char *data)
 {
-  char		*p = data, *q = NULL, *n = NULL, c = 0;
-  const size_t max_data_len = 500 - strlen(prefix);
-
   if (!*data) {
     dprintf(idx, "%s\n", prefix);
     return;
   }
+
+  char *p = data, *q = NULL, *n = NULL, c = 0;
+  const size_t max_data_len = 500 - strlen(prefix);
+
   while (strlen(p) > max_data_len) {
     q = p + max_data_len;
     /* Search for embedded linefeed first */
@@ -387,15 +384,16 @@ void days(time_t mynow, time_t then, char *out)
  */
 void daysdur(time_t mynow, time_t then, char *out)
 {
-  char s[81] = "";
-  int hrs, mins;
-
   if (mynow - then > 86400) {
     int mydays = (mynow - then) / 86400;
 
     sprintf(out, "for %d day%s", mydays, (mydays == 1) ? "" : "s");
     return;
   }
+
+  char s[81] = "";
+  int hrs, mins;
+
   strcpy(out, "for ");
   mynow -= then;
   hrs = (int) (mynow / 3600);
@@ -470,7 +468,7 @@ void show_channels(int idx, char *handle)
   else
     u = dcc[idx].user;
 
-  for (chan = chanset;chan;chan = chan->next) {
+  for (chan = chanset;chan ;chan = chan->next) {
     get_user_flagrec(u, &fr, chan->dname);
     if (l < strlen(chan->dname)) {
       l = strlen(chan->dname);
@@ -505,11 +503,11 @@ void show_channels(int idx, char *handle)
 
 /* Create a string with random letters and digits
  */
-void make_rand_str(char *s, int len)
+void make_rand_str(char *s, size_t len)
 {
-  int j, r = 0;
+  int r = 0;
 
-  for (j = 0; j < len; j++) {
+  for (size_t j = 0; j < len; j++) {
     r = randint(4);
     if (r == 0)
       s[j] = '0' + randint(10);
@@ -535,15 +533,13 @@ void make_rand_str(char *s, int len)
  */
 char *str_escape(const char *str, const char divc, const char mask)
 {
-  const int	 len = strlen(str);
-  int		 buflen = (2 * len), blen = 0;
+  const size_t	 len = strlen(str);
+  size_t	 buflen = (2 * len), blen = 0;
   char		*buf = NULL, *b = NULL;
   const char	*s = NULL;
 
   b = buf = (char *) calloc(1, buflen + 1);
 
-  if (!buf)
-    return NULL;
   for (s = str; *s; s++) {
     /* Resize buffer. */
     if ((buflen - blen) <= 3) {
@@ -625,7 +621,6 @@ char *strchr_unescape(char *str, const char divc, register const char esc_char)
 void str_unescape(char *str, register const char esc_char)
 {
   strchr_unescape(str, 0, esc_char);
-
   return;
 }
 
@@ -671,16 +666,15 @@ restart(int idx)
 
 int updatebin(int idx, char *par, int secs)
 {
-  char *path = NULL, *newbin = NULL, old[DIRMAX] = "", testbuf[DIRMAX] = "";
-  int i;
-
-  path = par;
-
   if (!par || !par[0]) {
     logidx(idx, "Not enough parameters.");
     return 1;
   }
-  path = (char *) calloc(1, strlen(binname) + strlen(par) + 2);
+
+  char *path = (char *) calloc(1, strlen(binname) + strlen(par) + 2);
+  char *newbin = NULL, old[DIRMAX] = "", testbuf[DIRMAX] = "";
+  int i;
+
   strcpy(path, binname);
   newbin = strrchr(path, '/');
   if (!newbin) {
@@ -803,13 +797,13 @@ int bot_aggressive_to(struct userrec *u)
 
 int goodpass(char *pass, int idx, char *nick)
 {
-  char tell[501] = "";
-  int i, nalpha = 0, lcase = 0, ucase = 0, ocase = 0, tc;
-
   if (!pass[0]) 
     return 0;
 
-  for (i = 0; i < (signed) strlen(pass); i++) {
+  char tell[501] = "";
+  int nalpha = 0, lcase = 0, ucase = 0, ocase = 0, tc;
+
+  for (int i = 0; i < (signed) strlen(pass); i++) {
     tc = (int) pass[i];
     if (tc < 58 && tc > 47)
       ocase++; /* number */
@@ -861,19 +855,18 @@ int goodpass(char *pass, int idx, char *nick)
 
 char *replace(const char *string, const char *oldie, const char *newbie)
 {
-  static char newstring[1024] = "";
-  unsigned int str_index, newstr_index, oldie_index;
-  size_t new_len, old_len, end, cpy_len;
+  if (string == NULL) 
+    return "";
+
   char *c = NULL;
 
-  if (string == NULL) return "";
-  if ((c = (char *) strstr(string, oldie)) == NULL) return (char *) string;
-  new_len = strlen(newbie);
-  old_len = strlen(oldie);
-  end = strlen(string) - old_len;
-  oldie_index = c - string;
-  newstr_index = 0;
-  str_index = 0;
+  if ((c = (char *) strstr(string, oldie)) == NULL) 
+    return (char *) string;
+
+  static char newstring[1024] = "";
+  const size_t new_len = strlen(newbie), old_len = strlen(oldie), end = (strlen(string) - old_len);
+  size_t str_index = 0, newstr_index = 0, oldie_index = c - string, cpy_len;
+
   while(str_index <= end && c != NULL) {
     cpy_len = oldie_index-str_index;
     strncpy(newstring + newstr_index, string + str_index, cpy_len);
@@ -892,10 +885,10 @@ char *replace(const char *string, const char *oldie, const char *newbie)
 void showhelp(int idx, struct flag_record *flags, char *string)
 {
   struct flag_record fr = {FR_GLOBAL | FR_CHAN, 0, 0, 0 };
-  char *helpstr = NULL, tmp[2] = "", flagstr[10] = "";
-  int ok = 1;
+  char *helpstr = (char *) calloc(1, strlen(string) + 1000 + 1);
+  char tmp[2] = "", flagstr[10] = "";
+  bool ok = 1;
 
-  helpstr = (char *) calloc(1, strlen(string) + 1000 + 1);
   while (string && string[0]) {
     if (*string == '%') {
       if (!strncmp(string + 1, "{+", 2)) {
@@ -964,22 +957,23 @@ void showhelp(int idx, struct flag_record *flags, char *string)
 }
 
 /* Arrange the N elements of ARRAY in random order. */
-static void shuffleArray(char *array[], int n)
+static void shuffleArray(char *array[], size_t n)
 {
-  int i;
+  size_t j = 0;
+  char *temp = NULL;
 
-  for (i = 0; i < n; i++) {
-    int j = i + random() / (RAND_MAX / (n - i) + 1);
-    char *t = array[j];
+  for (size_t i = 0; i < n; i++) {
+    j = i + random() / (RAND_MAX / (n - i) + 1);
+    temp = array[j];
     array[j] = array[i];
-    array[i] = t;
+    array[i] = temp;
   }
 }
 
 void shuffle(char *string, char *delim)
 {
   char *array[501], *str = NULL, *work = NULL;
-  int len = 0, i = 0;
+  size_t len = 0;
 
   egg_bzero(&array, sizeof array);
   work = strdup(string);
@@ -993,7 +987,7 @@ void shuffle(char *string, char *delim)
   }
   shuffleArray(array, len);
   string[0] = 0;
-  for (i = 0; i < len; i++) {
+  for (size_t i = 0; i < len; i++) {
     strcat(string, array[i]);
     if (i != len - 1)
       strcat(string, delim);
@@ -1082,9 +1076,8 @@ color(int idx, int type, int which)
 char *
 strtolower(char *s)
 {
-  char *p = NULL;
-  
-  p = s;
+  char *p = s;
+
   while (*p) {
     *p = tolower(*p);
     p++;
@@ -1095,9 +1088,8 @@ strtolower(char *s)
 char *
 strtoupper(char *s)
 {
-  char *p = NULL;
-  
-  p = s;
+  char *p = s;
+
   while (*p) {
     *p = toupper(*p);
     p++;
@@ -1108,12 +1100,12 @@ strtoupper(char *s)
   
 char *step_thru_file(FILE *fd)
 {
-  char tempBuf[1024] = "", *retStr = NULL;
-
   if (fd == NULL) {
     return NULL;
   }
-  retStr = NULL;
+
+  char tempBuf[1024] = "", *retStr = NULL;
+
   while (!feof(fd)) {
     fgets(tempBuf, sizeof(tempBuf), fd);
     if (!feof(fd)) {
@@ -1135,9 +1127,9 @@ char *step_thru_file(FILE *fd)
 
 char *trim(char *string)
 {
-  char *ibuf = NULL, *obuf = NULL;
-
   if (string) {
+    char *ibuf = NULL, *obuf = NULL;
+
     for (ibuf = obuf = string; *ibuf; ) {
       while (*ibuf && (isspace (*ibuf)))
         ibuf++;

+ 5 - 5
src/misc.h

@@ -18,13 +18,12 @@ int coloridx(int);
 const char *color(int, int, int);
 void shuffle(char *, char *);
 void showhelp(int, struct flag_record *, char *);
-int listen_all(int, int);
 char *replace(const char *, const char *, const char *);
 int goodpass(char *, int, char *);
 int bot_aggressive_to(struct userrec *);
 int updatebin(int, char *, int);
-int egg_strcatn(char *dst, const char *src, size_t max);
-int my_strcpy(char *, char *);
+size_t egg_strcatn(char *dst, const char *src, size_t max);
+size_t my_strcpy(char *, char *);
 void maskhost(const char *, char *);
 char *stristr(char *, char *);
 void splitc(char *, char *, char);
@@ -40,7 +39,7 @@ void daysdur(time_t, time_t, char *);
 void show_motd(int);
 void show_channels(int, char *);
 void show_banner(int);
-void make_rand_str(char *, int);
+void make_rand_str(char *, size_t);
 char *str_escape(const char *, const char, const char);
 char *strchr_unescape(char *, const char, register const char);
 void str_unescape(char *, register const char);
@@ -53,7 +52,8 @@ char *trim(char *);
 int skipline(char *, int *);
 
 
-extern int		server_lag, use_invites, use_exempts;
+extern int		server_lag;
+extern bool		use_invites, use_exempts;
 
 #endif /* !_MISC_H_ */
 

+ 14 - 8
src/misc_file.c

@@ -24,9 +24,7 @@
  */
 int copyfile(const char *oldpath, const char *newpath)
 {
-  int fi, fo, x;
-  char buf[512] = "";
-  struct stat st;
+  sock_t fi;
 
 #ifndef CYGWIN_HACKS
   fi = open(oldpath, O_RDONLY, 0);
@@ -35,15 +33,24 @@ int copyfile(const char *oldpath, const char *newpath)
 #endif
   if (fi < 0)
     return 1;
+
+  struct stat st;
+
   fstat(fi, &st);
   if (!(st.st_mode & S_IFREG))
     return 3;
+
+  sock_t fo;
+
   fo = creat(newpath, (int) (st.st_mode & 0600));
   if (fo < 0) {
     close(fi);
     return 2;
   }
-  for (x = 1; x > 0;) {
+
+  char buf[512] = "";
+
+  for (ssize_t x = 1; x > 0;) {
     x = read(fi, buf, 512);
     if (x > 0) {
       if (write(fo, buf, x) < x) {	/* Couldn't write */
@@ -64,8 +71,6 @@ int copyfile(const char *oldpath, const char *newpath)
 
 int movefile(const char *oldpath, const char *newpath)
 {
-  int ret;
-
 #ifdef HAVE_RENAME
   /* Try to use rename first */
   if (!rename(oldpath, newpath))
@@ -75,7 +80,8 @@ int movefile(const char *oldpath, const char *newpath)
   /* If that fails, fall back to just copying and then
    * deleting the file.
    */
-  ret = copyfile(oldpath, newpath);
+  int ret = copyfile(oldpath, newpath);
+
   if (!ret)
     unlink(oldpath);
   return ret;
@@ -159,7 +165,7 @@ Tempfile::Tempfile()
 
 Tempfile::Tempfile(const char *prefix)
 {
-  len = strlen(tempdir) + 1 + strlen(prefix) + 6 + 1;
+  len = strlen(tempdir) + 1 + strlen(prefix) + 1 + 6 + 1;
   file = new char[len];
   sprintf(file, "%s.%s-XXXXXX", tempdir, prefix);
 

+ 91 - 100
src/mod/channels.mod/channels.c

@@ -32,32 +32,32 @@
 
 #include <sys/stat.h>
 
-static int 			use_info;
+static bool 			use_info;
 static char 			glob_chanmode[64];		/* Default chanmode (drummer,990731) */
 static int 			global_stopnethack_mode;
 static int 			global_revenge_mode;
 static int 			global_idle_kick;		/* Default idle-kick setting. */
-static int 			global_ban_time;
-static int 			global_exempt_time;
-static int 			global_invite_time;
+static time_t 			global_ban_time;
+static time_t			global_exempt_time;
+static time_t 			global_invite_time;
 
 /* Global channel settings (drummer/dw) */
-char 				glob_chanset[512] = "", cfg_glob_chanset[512] = "";
+char glob_chanset[512] = "", cfg_glob_chanset[512] = "";
 static char *lastdeletedmask = NULL;
 
 /* Global flood settings */
 static int 			gfld_chan_thr;
-static int 			gfld_chan_time;
+static time_t 			gfld_chan_time;
 static int 			gfld_deop_thr;
-static int 			gfld_deop_time;
+static time_t 			gfld_deop_time;
 static int 			gfld_kick_thr;
-static int 			gfld_kick_time;
+static time_t 			gfld_kick_time;
 static int 			gfld_join_thr;
-static int 			gfld_join_time;
+static time_t 			gfld_join_time;
 static int 			gfld_ctcp_thr;
-static int 			gfld_ctcp_time;
-static int 			gfld_nick_thr;
-static int 			gfld_nick_time;
+static time_t 			gfld_ctcp_time;
+static int			gfld_nick_thr;
+static time_t 			gfld_nick_time;
 
 static int 			killed_bots = 0;
 
@@ -72,26 +72,28 @@ static void
 check_should_close()
 {
   char *p = CFG_CLOSETHRESHOLD.gdata;
-  tand_t *bot = NULL;
-  int H, L, hc, lc;
-  struct chanset_t *chan = NULL;
 
   if (!p)
     return;
-  H = atoi(p);
+
+  int H = atoi(p);
+
   p = strchr(p, ':');
   if (!p)
     return;
+
   p++;
-  L = atoi(p);
+
+  int L = atoi(p);
+
   if ((H <= 0) || (L <= 0))
     return;
-  hc = 1;
-  lc = 0;
-  for (bot = tandbot; bot; bot = bot->next) {
-    struct userrec *u = get_user_by_handle(userlist, bot->bot);
 
-    if (u) {
+  int hc = 1, lc = 0;
+  struct userrec *u = NULL;
+
+  for (tand_t *bot = tandbot; bot; bot = bot->next) {
+    if ((u = get_user_by_handle(userlist, bot->bot))) {
       if (bot_hublevel(u) < 999)
         hc++;
       else
@@ -99,7 +101,7 @@ check_should_close()
     }
   }
   if ((hc >= H) && (lc <= L)) {
-    for (chan = chanset; chan; chan = chan->next) {
+    for (struct chanset_t *chan = chanset; chan; chan = chan->next) {
       if (!channel_closed(chan)) {
         do_chanset(NULL, chan, "+closed chanmode +stni", DO_LOCAL | DO_NET);
 #ifdef G_BACKUP
@@ -113,14 +115,14 @@ check_should_close()
 
 static void got_cset(char *botnick, char *code, char *par)
 {
-  int all = 0;
+  if (!par || !par[0])
+   return;
+
+  bool all = 0;
   char *chname = NULL;
   struct chanset_t *chan = NULL;
 
-  if (!par || !par[0])
-   return;
-  else {
-   if (par[0] == '*' && par[1] == ' ') {
+  if (par[0] == '*' && par[1] == ' ') {
     all = 1;
     newsplit(&par);
    } else {
@@ -132,7 +134,7 @@ static void got_cset(char *botnick, char *code, char *par)
     if (!(chan = findchan_by_dname(chname)))
       return;
    }
-  }
+
   if (all)
    chan = chanset;
 
@@ -157,10 +159,8 @@ parsebots(char *bots, char *botn) {
   if (!strcmp(bots, "*")) {
     return 1;
   } else {
-    char *list = NULL, *bot = NULL;
+    char *list = strdup(bots), *bot = strtok(list, ",");
 
-    list = strdup(bots);
-    bot = strtok(list, ",");
     while(bot && *bot) {
       if (!egg_strcasecmp(bot, botn))
         return 1;
@@ -173,18 +173,18 @@ parsebots(char *bots, char *botn) {
 
 static void got_cpart(char *botnick, char *code, char *par)
 {
-  char *chname = NULL, *bots = NULL;
-  struct chanset_t *chan = NULL;
-  int match = 0;
-
   if (!par[0])
    return;
 
-  chname = newsplit(&par);
+  char *chname = newsplit(&par);
+  struct chanset_t *chan = NULL;
+
   if (!(chan = findchan_by_dname(chname)))
    return;
 
-  bots = newsplit(&par);
+  char *bots = newsplit(&par);
+  int match = 0;
+
   /* if bots is '*' just remove_channel */
   if (!strcmp(bots, "*"))
     match = 0;
@@ -203,27 +203,24 @@ static void got_cpart(char *botnick, char *code, char *par)
 
 static void got_cjoin(char *botnick, char *code, char *par)
 {
-  char *chname = NULL, *options = NULL;
-#ifdef LEAF 
-  char *bots = NULL;
-  int match = 0, inactive = 0;
-#endif /* LEAF */
-  struct chanset_t *chan = NULL;
-
   if (!par[0])
    return;
 
-  chname = newsplit(&par);
-  chan = findchan_by_dname(chname);
-  
+  char *chname = newsplit(&par), *options = NULL;
+  struct chanset_t *chan = findchan_by_dname(chname);
+
   /* ALL hubs should add the channel, leaf should check the list for a match */
 #ifdef LEAF
-  bots = newsplit(&par);
+  bool inactive = 0;
+  char *bots = newsplit(&par);
+  int match = parsebots(bots, conf.bot->nick);
+
   if (strstr(par, "+inactive"))
     inactive = 1;
-  match = parsebots(bots, conf.bot->nick);
+
   if (chan && !match)
     return;
+
   if (!match) {
     size_t size = strlen(par) + 12 + 1;
 
@@ -235,12 +232,17 @@ static void got_cjoin(char *botnick, char *code, char *par)
     return;
   } else
 #endif /* LEAF */
+#ifdef HUB
+    newsplit(&par);	/* hubs ignore the botmatch param */
+#endif /* HUB */
     options = par;
   if (chan)
     return;
 sdprintf("OPTIONS: %s", options);
-  if (channel_add(NULL, chname, options) == ERROR) /* drummer */
-    putlog(LOG_BOTS, "@", "Invalid channel or channel options from %s for %s", botnick, chname);
+  char result[1024] = "";
+
+  if (channel_add(result, chname, options) == ERROR) /* drummer */
+    putlog(LOG_BOTS, "@", "Invalid channel or channel options from %s for %s: %s", botnick, chname, result);
 #ifdef HUB
   else
     write_userfile(-1);
@@ -254,16 +256,17 @@ sdprintf("OPTIONS: %s", options);
 #ifdef LEAF
 static void got_cycle(char *botnick, char *code, char *par)
 {
-  char *chname = NULL;
-  struct chanset_t *chan = NULL;
-  int delay = 10;
-
   if (!par[0])
    return;
 
-  chname = newsplit(&par);
+  char *chname = newsplit(&par);
+  struct chanset_t *chan = NULL;
+
   if (!(chan = findchan_by_dname(chname)))
    return;
+
+  time_t delay = 10;
+
   if (par[0])
     delay = atoi(newsplit(&par));
   
@@ -274,13 +277,12 @@ static void got_cycle(char *botnick, char *code, char *par)
 
 static void got_down(char *botnick, char *code, char *par)
 {
-  char *chname = NULL;
-  struct chanset_t *chan = NULL;
-
   if (!par[0])
    return;
 
-  chname = newsplit(&par);
+  char *chname = newsplit(&par);
+  struct chanset_t *chan = NULL;
+
   if (!(chan = findchan_by_dname(chname)))
    return;
  
@@ -291,17 +293,14 @@ static void got_down(char *botnick, char *code, char *par)
 
 static void got_role(char *botnick, char *code, char *par)
 {
-  role = atoi(newsplit(&par));
-  putlog(LOG_DEBUG, "@", "Got role index %d", role);
+  putlog(LOG_DEBUG, "@", "Got role index %d", atoi(newsplit(&par)));
 }
 
 void got_kl(char *botnick, char *code, char *par)
 {
   killed_bots++;
   if (kill_threshold && (killed_bots = kill_threshold)) {
-    struct chanset_t *ch = NULL;
-
-    for (ch = chanset; ch; ch = ch->next)
+    for (struct chanset_t *ch = chanset; ch; ch = ch->next)
       do_chanset(NULL, ch, "+closed +bitch +backup", DO_LOCAL | DO_NET);
   /* FIXME: we should randomize nick here ... */
   }
@@ -407,11 +406,11 @@ static void
 channels_timers()
 {
   static int cnt = 0;
-  struct chanset_t *chan = NULL, *chan_n = NULL;
+  struct chanset_t *chan_n = NULL;
 
   cnt += 10;		/* function is called every 10 seconds */
   
-  for (chan = chanset; chan; chan = chan_n) {
+  for (struct chanset_t *chan = chanset; chan; chan = chan_n) {
     chan_n = chan->next;
 
     if ((cnt % 10) == 0) {
@@ -431,28 +430,18 @@ channels_timers()
 
 static void got_sj(int idx, char *code, char *par) 
 {
-  char *chname = NULL;
-  time_t delay;
-  struct chanset_t *chan = NULL;
+  struct chanset_t *chan = findchan_by_dname(newsplit(&par));
 
-  chname = newsplit(&par);
-  delay = ((atoi(par) + now) - server_lag);
-  chan = findchan_by_dname(chname);
   if (chan)
-    chan->channel.jointime = delay;
+    chan->channel.jointime = ((atoi(par) + now) - server_lag);
 }
 
 static void got_sp(int idx, char *code, char *par) 
 {
-  char *chname = NULL;
-  time_t delay;
-  struct chanset_t *chan = NULL;
+  struct chanset_t *chan = findchan_by_dname(newsplit(&par));
 
-  chname = newsplit(&par);
-  delay = ((atoi(par) + now) - server_lag);
-  chan = findchan_by_dname(chname);
   if (chan)
-    chan->channel.parttime = delay;
+    chan->channel.parttime = ((atoi(par) + now) - server_lag);
 }
 /* got_jn
  * We get this when a bot is opped in a +take chan
@@ -461,11 +450,13 @@ static void got_sp(int idx, char *code, char *par)
 
 static void got_jn(int idx, char *code, char *par)
 {
+  char *chname = newsplit(&par);
+
+  if (!chname || !chname[0]) 
+    return;
+
   struct chanset_t *chan = NULL;
-  char *chname = NULL;
 
-  chname = newsplit(&par);
-  if (!chname || !chname[0]) return;
   if (!(chan = findchan_by_dname(chname))) return;
   if (chan->channel.jointime && channel_inactive(chan)) {
     chan->status &= ~CHAN_INACTIVE;
@@ -571,9 +562,10 @@ static void set_mode_protect(struct chanset_t *chan, char *set)
 static void get_mode_protect(struct chanset_t *chan, char *s)
 {
   char *p = s, s1[121] = "";
-  int ok = 0, i, tst;
+  int tst;
+  bool ok = 0;
 
-  for (i = 0; i < 2; i++) {
+  for (int i = 0; i < 2; i++) {
     ok = 0;
     if (i == 0) {
       tst = chan->mode_pls_prot;
@@ -633,7 +625,7 @@ static void get_mode_protect(struct chanset_t *chan, char *s)
 
 /* Returns true if this is one of the channel masks
  */
-int ismodeline(masklist *m, const char *username)
+bool ismodeline(masklist *m, const char *username)
 {
   for (; m && m->mask[0]; m = m->next)  
     if (!rfc_casecmp(m->mask, username))
@@ -643,7 +635,7 @@ int ismodeline(masklist *m, const char *username)
 
 /* Returns true if user matches one of the masklist -- drummer
  */
-int ismasked(masklist *m, const char *username)
+bool ismasked(masklist *m, const char *username)
 {
   for (; m && m->mask[0]; m = m->next)
     if (wild_match(m->mask, (char *) username))
@@ -653,11 +645,11 @@ int ismasked(masklist *m, const char *username)
 
 /* Unlink chanset element from chanset list.
  */
-static inline int chanset_unlink(struct chanset_t *chan)
+static inline bool chanset_unlink(struct chanset_t *chan)
 {
-  struct chanset_t *c = NULL, *c_old = NULL;
+  struct chanset_t *c_old = NULL;
 
-  for (c = chanset; c; c_old = c, c = c->next) {
+  for (struct chanset_t *c = chanset; c; c_old = c, c = c->next) {
     if (c == chan) {
       if (c_old)
 	c_old->next = c->next;
@@ -676,7 +668,7 @@ static inline int chanset_unlink(struct chanset_t *chan)
  */
 void remove_channel(struct chanset_t *chan)
 {
-   int		 i;
+   int i;
    
    irc_log(chan, "Parting");
    /* Remove the channel from the list, so that noone can pull it
@@ -721,7 +713,8 @@ void remove_channel(struct chanset_t *chan)
 static int channels_chon(char *handle, int idx)
 {
   struct flag_record fr = {FR_CHAN | FR_ANYWH | FR_GLOBAL, 0, 0, 0 };
-  int find, found = 0;
+  int find;
+  bool found = 0;
   struct chanset_t *chan = chanset;
 
   if (dcc[idx].type == &DCC_CHAT) {
@@ -764,12 +757,11 @@ static cmd_t my_chon[] =
 
 void channels_report(int idx, int details)
 {
-  struct chanset_t *chan = NULL;
   int i;
   char s[1024] = "", s2[100] = "";
   struct flag_record fr = {FR_CHAN | FR_GLOBAL, 0, 0, 0 };
 
-  for (chan = chanset; chan; chan = chan->next) {
+  for (struct chanset_t *chan = chanset; chan; chan = chan->next) {
     if (idx != DP_STDOUT)
       get_user_flagrec(dcc[idx].user, &fr, chan->dname);
     if (!privchan(fr, chan, PRIV_OP) && ((idx == DP_STDOUT) || glob_master(fr) || chan_master(fr))) {
@@ -881,9 +873,9 @@ void channels_report(int idx, int details)
         if (chan->revenge_mode)
           dprintf(idx, "      revenge-mode %d\n",
                   chan->revenge_mode);
-       dprintf(idx, "    Bans last %d mins.\n", chan->ban_time);
-       dprintf(idx, "    Exemptions last %d mins.\n", chan->exempt_time);
-       dprintf(idx, "    Invitations last %d mins.\n", chan->invite_time);
+       dprintf(idx, "    Bans last %lu mins.\n", chan->ban_time);
+       dprintf(idx, "    Exemptions last %lu mins.\n", chan->exempt_time);
+       dprintf(idx, "    Invitations last %lu mins.\n", chan->invite_time);
       }
     }
   }
@@ -970,4 +962,3 @@ void channels_init()
   add_builtins("bot", channels_bot);
   add_builtins("chon", my_chon);
 }
-

+ 15 - 15
src/mod/channels.mod/channels.h

@@ -15,11 +15,11 @@
 
 #define PLSMNS(x) (x ? '+' : '-')
 
-static void tell_bans(int idx, int show_inact, char *match);
 
 static void check_expired_masks(void);
-static void tell_exempts (int idx, int show_inact, char * match);
-static void tell_invites (int idx, int show_inact, char * match);
+static void tell_bans(int idx, bool show_inact, char *match);
+static void tell_exempts (int idx, bool show_inact, char * match);
+static void tell_invites (int idx, bool show_inact, char * match);
 static void get_mode_protect(struct chanset_t *chan, char *s);
 static void set_mode_protect(struct chanset_t *chan, char *set);
 
@@ -32,25 +32,25 @@ void set_handle_chaninfo(struct userrec *, char *, char *, char *);
 struct chanuserrec *get_chanrec(struct userrec *u, char *);
 struct chanuserrec *add_chanrec(struct userrec *u, char *);
 void del_chanrec(struct userrec *, char *);
-int write_bans(FILE *, int);
-int write_config (FILE *, int);
-int write_exempts (FILE *, int);
-int write_chans (FILE *, int);
-int write_invites (FILE *, int);
-int expired_mask(struct chanset_t *, char *);
+bool write_bans(FILE *, int);
+bool write_config (FILE *, int);
+bool write_exempts (FILE *, int);
+bool write_chans (FILE *, int);
+bool write_invites (FILE *, int);
+bool expired_mask(struct chanset_t *, char *);
 void set_handle_laston(char *, struct userrec *, time_t);
 int u_delmask(char type, struct chanset_t *c, char *who, int doit);
-int u_addmask(char type, struct chanset_t *, char *, char *, char *, time_t, int);
+bool u_addmask(char type, struct chanset_t *, char *, char *, char *, time_t, int);
 int u_sticky_mask(maskrec *, char *);
-int u_setsticky_mask(struct chanset_t *, maskrec *, char *, int, const char *);
+int u_setsticky_mask(struct chanset_t *, maskrec *, char *, bool, const char *);
 int SplitList(char *, const char *, int *, const char ***);
 int channel_modify(char *, struct chanset_t *, int, char **);
 int channel_add(char *, char *, char *);
-void clear_channel(struct chanset_t *, int);
+void clear_channel(struct chanset_t *, bool);
 int u_equals_mask(maskrec *, char *);
-int u_match_mask(struct maskrec *, char *);
-int ismasked(masklist *, const char *);
-int ismodeline(masklist *, const char *);
+bool u_match_mask(struct maskrec *, char *);
+bool ismasked(masklist *, const char *);
+bool ismodeline(masklist *, const char *);
 void channels_report(int, int);
 #ifdef HUB
 void channels_writeuserfile();

+ 37 - 25
src/mod/channels.mod/cmdschan.c

@@ -12,16 +12,18 @@ static struct flag_record victim = {FR_GLOBAL | FR_CHAN, 0, 0, 0 };
 
 static void cmd_pls_mask(const char type, int idx, char *par)
 {
-  char *chname = NULL, *who = NULL, s[UHOSTLEN] = "", s1[UHOSTLEN] = "", *p = NULL, *p_expire = NULL;
   const char *cmd = (type == 'b' ? "ban" : type == 'e' ? "exempt" : "invite");
-  unsigned long int expire_time = 0, expire_foo;
-  int sticky = 0;
-  struct chanset_t *chan = NULL;
 
   if (!par[0]) {
     dprintf(idx, "Usage: +%s <hostmask> [channel] [%%<XdXhXm>] [reason]\n", cmd);
     return;
   }
+
+  char *chname = NULL, *who = NULL, s[UHOSTLEN] = "", s1[UHOSTLEN] = "", *p = NULL, *p_expire = NULL;
+  unsigned long int expire_time = 0, expire_foo;
+  int sticky = 0;
+  struct chanset_t *chan = NULL;
+
   who = newsplit(&par);
   if (par[0] && strchr(CHANMETA, par[0]))
     chname = newsplit(&par);
@@ -173,16 +175,18 @@ static void cmd_pls_invite(int idx, char *par)
 
 static void cmd_mns_mask(const char type, int idx, char *par)
 {
-  int i = 0, j;
-  struct chanset_t *chan = NULL;
-  char s[UHOSTLEN] = "", *who = NULL, *chname = NULL, *mask = NULL;
   const char *cmd = (type == 'b' ? "ban" : type == 'e' ? "exempt" : "invite");
-  masklist *m = NULL;
 
   if (!par[0]) {
     dprintf(idx, "Usage: -%s <hostmask> [channel]\n", cmd);
     return;
   }
+
+  int i = 0, j;
+  struct chanset_t *chan = NULL;
+  char s[UHOSTLEN] = "", *who = NULL, *chname = NULL, *mask = NULL;
+  masklist *m = NULL;
+
   who = newsplit(&par);
   if (par[0] && strchr(CHANMETA, par[0]))
     chname = newsplit(&par);
@@ -343,14 +347,13 @@ static void cmd_invites(int idx, char *par)
 
 static void cmd_info(int idx, char *par)
 {
-  char s[512] = "", *chname = NULL, *s1 = NULL;
-  int locked = 0;
-
   if (!use_info) {
     dprintf(idx, "Info storage is turned off.\n");
     return;
   }
-  s1 = (char *) get_user(&USERENTRY_INFO, dcc[idx].user);
+  char s[512] = "", *chname = NULL, *s1 = (char *) get_user(&USERENTRY_INFO, dcc[idx].user);
+  bool locked = 0;
+
   if (s1 && s1[0] == '@')
     locked = 1;
   if (par[0] && strchr(CHANMETA, par[0])) {
@@ -413,23 +416,27 @@ static void cmd_info(int idx, char *par)
 
 static void cmd_chinfo(int idx, char *par)
 {
-  char *handle = NULL, *chname = NULL;
-  struct userrec *u1 = NULL;
-
   if (!use_info) {
     dprintf(idx, "Info storage is turned off.\n");
     return;
   }
-  handle = newsplit(&par);
+
+  char *handle = newsplit(&par);
+
   if (!handle[0]) {
     dprintf(idx, "Usage: chinfo <handle> [channel] <new-info>\n");
     return;
   }
-  u1 = get_user_by_handle(userlist, handle);
+
+  struct userrec *u1 = get_user_by_handle(userlist, handle);
+
   if (!u1) {
     dprintf(idx, "No such user.\n");
     return;
   }
+
+  char *chname = NULL;
+
   if (par[0] && strchr(CHANMETA, par[0])) {
     chname = newsplit(&par);
     if (!findchan_by_dname(chname)) {
@@ -953,8 +960,13 @@ static void pls_chan(int idx, char *par, char *bot)
   }
 
   chname = newsplit(&par);
-  sprintf(buf, "cjoin %s %s %s", chname, bot ? bot : "*", par);		/* +chan makes all bots join */
-
+  sprintf(buf, "cjoin %s %s", chname, bot ? bot : "*");		/* +chan makes all bots join */
+  if (par[0]) {
+    strcat(buf, " ");
+    strcat(buf, par);
+    strcat(buf, " ");
+  }
+    
   if (!bot && findchan_by_dname(chname)) {
     putallbots(buf);
     dprintf(idx, "That channel already exists!\n");
@@ -980,11 +992,11 @@ static void pls_chan(int idx, char *par, char *bot)
         char tmp[51] = "";
 
         sprintf(tmp, "addedby %s addedts %li", dcc[idx].nick, now);
-        if (buf[0])
-          sprintf(buf, "%s %s", buf, tmp);
-        else
-          sprintf(buf, "%s", tmp);
-        do_chanset(NULL, chan, tmp, DO_LOCAL);
+        if (buf[0]) {
+          strcat(buf, " ");
+          strcat(buf, tmp);
+        }
+        do_chanset(NULL, chan, buf[0] ? buf : tmp, DO_LOCAL);
         dprintf(idx, "Channel %s added to the botnet.\n", chname);
       } else {
         dprintf(idx, "Channel %s added to the bot: %s\n", chname, bot);
@@ -1278,7 +1290,7 @@ static void cmd_chaninfo(int idx, char *par)
 	    chan->flood_pub_thr, chan->flood_ctcp_thr,
 	    chan->flood_join_thr, chan->flood_kick_thr,
 	    chan->flood_deop_thr, chan->flood_nick_thr);
-    dprintf(idx, "  time  :          %3d  %3d  %3d  %3d  %3d  %3d\n",
+    dprintf(idx, "  time  :          %3lu  %3lu  %3lu  %3lu  %3lu  %3lu\n",
 	    chan->flood_pub_time, chan->flood_ctcp_time,
 	    chan->flood_join_time, chan->flood_kick_time,
 	    chan->flood_deop_time, chan->flood_nick_time);

+ 32 - 24
src/mod/channels.mod/tclchan.c

@@ -3,16 +3,16 @@
  *
  */
 
-static int FindElement(char *resultBuf, const char *list, int listLength, 
+static int FindElement(char *resultBuf, const char *list, size_t listLength, 
                        const char **elementPtr, const char **nextPtr, 
-                       int *sizePtr, int *bracePtr)
+                       size_t *sizePtr, int *bracePtr)
 {
     const char *p = list;
     const char *elemStart = NULL;	/* Points to first byte of first element. */
-    const char *limit = NULL;		/* Points just after list's last byte. */
+    const char *limit = (list + listLength);		/* Points just after list's last byte. */
     int openBraces = 0;   	/* Brace nesting level during parse. */
     int inQuotes = 0;
-    int size = 0;               /* lint. */
+    size_t size = 0;               /* lint. */
     const char *p2 = NULL;
 
     /*
@@ -21,7 +21,6 @@ static int FindElement(char *resultBuf, const char *list, int listLength,
      * a list element.
      */
 
-    limit = (list + listLength);
     while ((p < limit) && egg_isspace(*p)) { /* INTL: ISO space. */
         p++;
     }
@@ -217,7 +216,9 @@ int SplitList(char *resultBuf, const char *list, int *argcPtr, const char ***arg
     const char *l = NULL;
     const char *element = NULL;
     char *p = NULL;
-    int length, size, i = 0, result, elSize, brace;
+    int result, brace;
+    size_t size = 2;		/* initialized to 1 for NULL pointer */
+    size_t length, elSize, i = 0;
 
     /*
      * Figure out how much space to allocate.  There must be enough
@@ -226,12 +227,11 @@ int SplitList(char *resultBuf, const char *list, int *argcPtr, const char ***arg
      * the number of space characters in the list.
      */
 
-    for (size = 1, l = list; *l != 0; l++) {
+    for (l = list; *l != 0; l++) {
         if (egg_isspace(*l)) { /* INTL: ISO space. */
             size++;
         }
     }
-    size++;                     /* Leave space for final NULL pointer. */
 
     argv = (const char **) calloc(1, (unsigned) ((size * sizeof(char *)) + (l - list) + 1 + 15));	/* 15 cuz the tcl src is hard to follow */
 
@@ -285,7 +285,7 @@ int SplitList(char *resultBuf, const char *list, int *argcPtr, const char ***arg
  */
 int channel_modify(char *result, struct chanset_t *chan, int items, char **item)
 {
-  int i, x = 0;
+  bool error = 0;
 #ifdef LEAF
   int old_status = chan->status,
       old_mode_mns_prot = chan->mode_mns_prot,
@@ -293,7 +293,7 @@ int channel_modify(char *result, struct chanset_t *chan, int items, char **item)
 #endif /* LEAF */
   char s[121] = "";
 
-  for (i = 0; i < items; i++) {
+  for (register int i = 0; i < items; i++) {
 /* Chanchar template
     } else if (!strcmp(item[i], "temp")) {
       i++;
@@ -593,7 +593,8 @@ int channel_modify(char *result, struct chanset_t *chan, int items, char **item)
     else if (!strcmp(item[i], "-clearbans"))  ;
     else if (!strncmp(item[i], "need-", 5))   ;
     else if (!strncmp(item[i], "flood-", 6)) {
-      int *pthr = NULL, *ptime = NULL;
+      int *pthr = NULL;
+      time_t *ptime = NULL;
       char *p = NULL;
 
       if (!strcmp(item[i] + 6, "chan")) {
@@ -638,7 +639,7 @@ int channel_modify(char *result, struct chanset_t *chan, int items, char **item)
     } else {
       if (result && item[i][0]) /* ignore "" */
         sprintf(result, "illegal channel option: %s", item[i]);
-      x++;
+      error = 1;
     }
   }
 #ifdef LEAF
@@ -660,7 +661,7 @@ int channel_modify(char *result, struct chanset_t *chan, int items, char **item)
     recheck_channel_modes(chan);
   }
 #endif /* LEAF */
-  if (x > 0)
+  if (error)
     return ERROR;
   return OK;
 }
@@ -674,14 +675,14 @@ static void init_masklist(masklist *m)
 
 /* Initialize out the channel record.
  */
-static void init_channel(struct chanset_t *chan, int reset)
+static void init_channel(struct chanset_t *chan, bool reset)
 {
   chan->channel.maxmembers = 0;
   chan->channel.mode = 0;
   chan->channel.members = 0;
-  if (!reset) {
+
+  if (!reset)
     chan->channel.key = (char *) calloc(1, 1);
-  }
 
   chan->channel.ban = (masklist *) calloc(1, sizeof(masklist));
   init_masklist(chan->channel.ban);
@@ -714,7 +715,7 @@ static void clear_masklist(masklist *m)
 
 /* Clear out channel data from memory.
  */
-void clear_channel(struct chanset_t *chan, int reset)
+void clear_channel(struct chanset_t *chan, bool reset)
 {
   memberlist *m = NULL, *m1 = NULL;
 
@@ -740,11 +741,6 @@ void clear_channel(struct chanset_t *chan, int reset)
  */
 int channel_add(char *result, char *newname, char *options)
 {
-  struct chanset_t *chan = NULL;
-  int items = 0, ret = OK, join = 0;
-  char buf[3001] = "";
-  const char **item = NULL;
-
   if (!newname || !newname[0] || !strchr(CHANMETA, newname[0])) {
     if (result)
       sprintf(result, "invalid channel prefix");
@@ -756,6 +752,11 @@ int channel_add(char *result, char *newname, char *options)
       sprintf(result, "invalid channel name");
     return ERROR;
   }
+
+  const char **item = NULL;
+  int items = 0;
+  char buf[3001] = "";
+
   simple_sprintf(buf, "chanmode { %s } ", glob_chanmode);
   strcat(buf, glob_chanset);
   strcat(buf, cfg_glob_chanset);
@@ -766,6 +767,12 @@ int channel_add(char *result, char *newname, char *options)
   if (SplitList(result, buf, &items, &item) != OK)
     return ERROR;
 
+#ifdef LEAF
+  bool join = 0;
+#endif /* LEAF */
+  struct chanset_t *chan = NULL;
+  int ret = OK;
+
   if ((chan = findchan_by_dname(newname))) {
     /* Already existing channel, maybe a reload of the channel file */
     chan->status &= ~CHAN_FLAGGED;	/* don't delete me! :) */
@@ -813,17 +820,18 @@ int channel_add(char *result, char *newname, char *options)
     /* Initialize chan->channel info */
     init_channel(chan, 0);
     list_append((struct list_type **) &chanset, (struct list_type *) chan);
+#ifdef LEAF
     /* Channel name is stored in xtra field for sharebot stuff */
     join = 1;
+#endif /* LEAF */
   }
   /* If loading is set, we're loading the userfile. Ignore errors while
    * reading userfile and just return OK. This is for compatability
    * if a user goes back to an eggdrop that no-longer supports certain
    * (channel) options.
    */
-  if ((channel_modify(result, chan, items, (char **) item) != OK) && !loading) {
+  if ((channel_modify(result, chan, items, (char **) item) != OK) && !loading)
     ret = ERROR;
-  }
 
   free(item);
 #ifdef LEAF

+ 72 - 86
src/mod/channels.mod/userchan.c

@@ -5,13 +5,9 @@
 
 extern struct cmd_pass *cmdpass;
 
-int force_expire = 0;
-
 struct chanuserrec *get_chanrec(struct userrec *u, char *chname)
 {
-  struct chanuserrec *ch = NULL;
-
-  for (ch = u->chanrec; ch; ch = ch->next) 
+  for (register struct chanuserrec *ch = u->chanrec; ch; ch = ch->next) 
     if (!rfc_casecmp(ch->channel, chname))
       return ch;
   return NULL;
@@ -19,10 +15,8 @@ struct chanuserrec *get_chanrec(struct userrec *u, char *chname)
 
 struct chanuserrec *add_chanrec(struct userrec *u, char *chname)
 {
-  struct chanuserrec *ch = NULL;
-
   if (findchan_by_dname(chname)) {
-    ch = (struct chanuserrec *) calloc(1, sizeof(struct chanuserrec));
+    struct chanuserrec *ch = (struct chanuserrec *) calloc(1, sizeof(struct chanuserrec));
 
     ch->next = u->chanrec;
     u->chanrec = ch;
@@ -33,15 +27,15 @@ struct chanuserrec *add_chanrec(struct userrec *u, char *chname)
     ch->channel[80] = 0;
     if (!noshare)
       shareout("+cr %s %s\n", u->handle, chname);
+    return ch;
   }
-  return ch;
+  return NULL;
 }
 
 void add_chanrec_by_handle(struct userrec *bu, char *hand, char *chname)
 {
-  struct userrec *u = NULL;
+  struct userrec *u = get_user_by_handle(bu, hand);
 
-  u = get_user_by_handle(bu, hand);
   if (!u)
     return;
   if (!get_chanrec(u, chname))
@@ -50,15 +44,15 @@ void add_chanrec_by_handle(struct userrec *bu, char *hand, char *chname)
 
 void get_handle_chaninfo(char *handle, char *chname, char *s)
 {
-  struct userrec *u = NULL;
-  struct chanuserrec *ch = NULL;
+  struct userrec *u = get_user_by_handle(userlist, handle);
 
-  u = get_user_by_handle(userlist, handle);
   if (u == NULL) {
     s[0] = 0;
     return;
   }
-  ch = get_chanrec(u, chname);
+
+  struct chanuserrec *ch = get_chanrec(u, chname);
+
   if (ch == NULL) {
     s[0] = 0;
     return;
@@ -73,14 +67,13 @@ void get_handle_chaninfo(char *handle, char *chname, char *s)
 
 void set_handle_chaninfo(struct userrec *bu, char *handle, char *chname, char *info)
 {
-  struct userrec *u = NULL;
-  struct chanuserrec *ch = NULL;
-  struct chanset_t *cst = NULL;
+  struct userrec *u = get_user_by_handle(bu, handle);
 
-  u = get_user_by_handle(bu, handle);
   if (!u)
     return;
-  ch = get_chanrec(u, chname);
+
+  struct chanuserrec *ch = get_chanrec(u, chname);
+
   if (!ch) {
     add_chanrec_by_handle(bu, handle, chname);
     ch = get_chanrec(u, chname);
@@ -95,7 +88,7 @@ void set_handle_chaninfo(struct userrec *bu, char *handle, char *chname, char *i
     ch->info = strdup(info);
   } else
     ch->info = NULL;
-  cst = findchan_by_dname(chname);
+
   if ((!noshare) && (bu == userlist)) {
     shareout("chchinfo %s %s %s\n", handle, chname, info ? info : "");
   }
@@ -125,12 +118,12 @@ void del_chanrec(struct userrec *u, char *chname)
 
 void set_handle_laston(char *chan, struct userrec *u, time_t n)
 {
-  struct chanuserrec *ch = NULL;
-
   if (!u)
     return;
   touch_laston(u, chan, n);
-  ch = get_chanrec(u, chan);
+
+  struct chanuserrec *ch = get_chanrec(u, chan);
+
   if (!ch)
     return;
   ch->laston = n;
@@ -148,7 +141,7 @@ int u_sticky_mask(maskrec *u, char *uhost)
 
 /* Set sticky attribute for a mask.
  */
-int u_setsticky_mask(struct chanset_t *chan, maskrec *u, char *uhost, int sticky, const char *botcmd)
+int u_setsticky_mask(struct chanset_t *chan, maskrec *u, char *uhost, bool sticky, const char *botcmd)
 {
   int j;
 
@@ -204,7 +197,7 @@ int u_equals_mask(maskrec *u, char *mask)
   return 0;
 }
 
-int u_match_mask(maskrec *rec, char *mask)
+bool u_match_mask(maskrec *rec, char *mask)
 {
   for (; rec; rec = rec->next)
     if (wild_match(rec->mask, mask))
@@ -274,7 +267,7 @@ int u_delmask(char type, struct chanset_t *c, char *who, int doit)
 
 /* Note: If first char of note is '*' it's a sticky mask.
  */
-int u_addmask(char type, struct chanset_t *chan, char *who, char *from, char *note, time_t expire_time, int flags)
+bool u_addmask(char type, struct chanset_t *chan, char *who, char *from, char *note, time_t expire_time, int flags)
 {
   char host[1024] = "", s[1024] = "";
   maskrec *p = NULL, *l = NULL, **u = NULL;
@@ -369,7 +362,7 @@ int u_addmask(char type, struct chanset_t *chan, char *who, char *from, char *no
 
 /* Take host entry from ban list and display it ban-style.
  */
-static void display_ban(int idx, int number, maskrec *ban, struct chanset_t *chan, int show_inact)
+static void display_ban(int idx, int number, maskrec *ban, struct chanset_t *chan, bool show_inact)
 {
   char dates[81] = "", s[41] = "";
 
@@ -416,7 +409,7 @@ static void display_ban(int idx, int number, maskrec *ban, struct chanset_t *cha
 
 /* Take host entry from exempt list and display it ban-style.
  */
-static void display_exempt(int idx, int number, maskrec *exempt, struct chanset_t *chan, int show_inact)
+static void display_exempt(int idx, int number, maskrec *exempt, struct chanset_t *chan, bool show_inact)
 {
   char dates[81] = "", s[41] = "";
 
@@ -463,7 +456,7 @@ static void display_exempt(int idx, int number, maskrec *exempt, struct chanset_
 
 /* Take host entry from invite list and display it ban-style.
  */
-static void display_invite (int idx, int number, maskrec *invite, struct chanset_t *chan, int show_inact)
+static void display_invite (int idx, int number, maskrec *invite, struct chanset_t *chan, bool show_inact)
 {
   char dates[81] = "", s[41] = "";
 
@@ -508,7 +501,7 @@ static void display_invite (int idx, int number, maskrec *invite, struct chanset
     dprintf(idx, "        %s\n", dates);
 }
 
-static void tell_bans(int idx, int show_inact, char *match)
+static void tell_bans(int idx, bool show_inact, char *match)
 {
   int k = 1;
   char *chname = NULL;
@@ -606,7 +599,7 @@ static void tell_bans(int idx, int show_inact, char *match)
     dprintf(idx, "%s.\n", BANS_USEBANSALL);
 }
 
-static void tell_exempts(int idx, int show_inact, char *match)
+static void tell_exempts(int idx, bool show_inact, char *match)
 {
   int k = 1;
   char *chname = NULL;
@@ -705,7 +698,7 @@ static void tell_exempts(int idx, int show_inact, char *match)
     dprintf(idx, "%s.\n", EXEMPTS_USEEXEMPTSALL);
 }
 
-static void tell_invites(int idx, int show_inact, char *match)
+static void tell_invites(int idx, bool show_inact, char *match)
 {
   int k = 1;
   char *chname = NULL;
@@ -804,21 +797,19 @@ static void tell_invites(int idx, int show_inact, char *match)
     dprintf(idx, "%s.\n", INVITES_USEINVITESALL);
 }
 
-int write_config(FILE *f, int idx)
+bool write_config(FILE *f, int idx)
 {
-  int i = 0;
-  struct cmd_pass *cp = NULL;
   putlog(LOG_DEBUG, "@", "Writing config entries...");
   if (lfprintf(f, CONFIG_NAME " - -\n") == EOF) /* Daemus */
       return 0;
-  for (i = 0; i < cfg_count; i++) {
+  for (int i = 0; i < cfg_count; i++) {
     if ((cfg[i]->flags & CFGF_GLOBAL) && (cfg[i]->gdata)) {
       if (lfprintf(f, "@ %s %s\n", cfg[i]->name, cfg[i]->gdata ? cfg[i]->gdata : "") == EOF)
         return 0;
     }
   }
 
-  for (cp = cmdpass; cp; cp = cp->next)
+  for (struct cmd_pass *cp = cmdpass; cp; cp = cp->next)
     if (lfprintf(f, "- %s %s\n", cp->name, cp->pass) == EOF)
       return 0;
 
@@ -826,17 +817,15 @@ int write_config(FILE *f, int idx)
 }
 /* Write the ban lists and the ignore list to a file.
  */
-int write_bans(FILE *f, int idx)
+bool write_bans(FILE *f, int idx)
 {
-  struct chanset_t *chan = NULL;
-  maskrec *b = NULL;
-  struct igrec *i = NULL;
-  char *mask = NULL;
-
   if (global_ign)
     if (lfprintf(f, IGNORE_NAME " - -\n") == EOF)	/* Daemus */
       return 0;
-  for (i = global_ign; i; i = i->next) {
+
+  char *mask = NULL;
+
+  for (struct igrec *i = global_ign; i; i = i->next) {
     mask = str_escape(i->igmask, ':', '\\');
     if (!mask ||
 	lfprintf(f, "- %s:%s%lu:%s:%lu:%s\n", mask,
@@ -852,6 +841,9 @@ int write_bans(FILE *f, int idx)
   if (global_bans)
     if (lfprintf(f, BAN_NAME " - -\n") == EOF)	/* Daemus */
       return 0;
+
+  maskrec *b = NULL;
+
   for (b = global_bans; b; b = b->next) {
     mask = str_escape(b->mask, ':', '\\');
     if (!mask ||
@@ -866,7 +858,7 @@ int write_bans(FILE *f, int idx)
     }
     free(mask);
   }
-  for (chan = chanset; chan; chan = chan->next) {
+  for (struct chanset_t *chan = chanset; chan; chan = chan->next) {
     if (lfprintf(f, "::%s bans\n", chan->dname) == EOF)
       return 0;
     for (b = chan->bans; b; b = b->next) {
@@ -888,15 +880,15 @@ int write_bans(FILE *f, int idx)
 }
 /* Write the exemptlists to a file.
  */
-int write_exempts(FILE *f, int idx)
+bool write_exempts(FILE *f, int idx)
 {
-  struct chanset_t *chan = NULL;
-  maskrec *e = NULL;
-  char *mask = NULL;
-
   if (global_exempts)
     if (lfprintf(f, EXEMPT_NAME " - -\n") == EOF) /* Daemus */
       return 0;
+
+  maskrec *e = NULL;
+  char *mask = NULL;
+
   for (e = global_exempts; e; e = e->next) {
     mask = str_escape(e->mask, ':', '\\');
     if (!mask ||
@@ -911,7 +903,7 @@ int write_exempts(FILE *f, int idx)
     }
     free(mask);
   }
-  for (chan = chanset;chan;chan=chan->next) {
+  for (struct chanset_t *chan = chanset;chan ;chan = chan->next) {
     if (lfprintf(f, "&&%s exempts\n", chan->dname) == EOF)
       return 0;
     for (e = chan->exempts; e; e = e->next) {
@@ -934,15 +926,16 @@ int write_exempts(FILE *f, int idx)
 
 /* Write the invitelists to a file.
  */
-int write_invites(FILE *f, int idx)
+bool write_invites(FILE *f, int idx)
 {
-  struct chanset_t *chan = NULL;
-  maskrec *ir = NULL;
-  char *mask = NULL;
 
   if (global_invites)
     if (lfprintf(f, INVITE_NAME " - -\n") == EOF) /* Daemus */
       return 0;
+
+  maskrec *ir = NULL;
+  char *mask = NULL;
+
   for (ir = global_invites; ir; ir = ir->next)  {
     mask = str_escape(ir->mask, ':', '\\');
     if (!mask ||
@@ -957,7 +950,7 @@ int write_invites(FILE *f, int idx)
     }
     free(mask);
   }
-  for (chan = chanset; chan; chan = chan->next) {
+  for (struct chanset_t *chan = chanset; chan; chan = chan->next) {
     if (lfprintf(f, "$$%s invites\n", chan->dname) == EOF)
       return 0;
     for (ir = chan->invites; ir; ir = ir->next) {
@@ -980,17 +973,16 @@ int write_invites(FILE *f, int idx)
 
 /* Write the channels to the userfile
  */
-int write_chans(FILE *f, int idx)
+bool write_chans(FILE *f, int idx)
 {
-  char w[1024] = "";
-  struct chanset_t *chan = NULL;
-
   putlog(LOG_DEBUG, "*", "Writing channels..");
 
   if (lfprintf(f, CHANS_NAME " - -\n") == EOF) /* Daemus */
     return 0;
 
-  for (chan = chanset; chan; chan = chan->next) {
+  char w[1024] = "";
+
+  for (struct chanset_t *chan = chanset; chan; chan = chan->next) {
     char inactive = 0;
 
     putlog(LOG_DEBUG, "*", "writing channel %s to userfile..", chan->dname);
@@ -1005,11 +997,15 @@ int write_chans(FILE *f, int idx)
 
     if (lfprintf(f, "\
 + channel add %s { chanmode { %s } addedby %s addedts %lu idle-kick %d \
-bad-cookie %d cookie-time-slack %d manop %d mdop %d mop %d \
-limit %d stopnethack-mode %d revenge-mode %d flood-chan %d:%d \
-flood-ctcp %d:%d flood-join %d:%d flood-kick %d:%d flood-deop %d:%d \
-flood-nick %d:%d closed-ban %d closed-private %d ban-time %d \
-exempt-time %d invite-time %d ",
+bad-cookie %d cookie-time-slack %lu manop %d mdop %d mop %d \
+limit %d stopnethack-mode %d revenge-mode %d flood-chan %d:%lu \
+flood-ctcp %d:%lu flood-join %d:%lu flood-kick %d:%lu flood-deop %d:%lu \
+flood-nick %d:%lu closed-ban %d closed-private %d ban-time %lu \
+exempt-time %lu invite-time %lu \
+%cenforcebans %cdynamicbans %cuserban %cbitch %cprotectops %crevenge \
+%crevengebot %cprivate %ccycle %cinactive %cdynamicexempts %cuserexempts \
+%cdynamicinvites %cuserinvites %cnodesynch %cclosed %ctake %cmanop %cvoice \
+%cfastop %cautoop }\n",
 	chan->dname,
 	w,
         chan->added_by,
@@ -1038,18 +1034,10 @@ exempt-time %d invite-time %d ",
  *      chan->temp,
  * also include temp %d in dprintf
  */
-        chan->ban_time,
         chan->closed_private,
+        chan->ban_time,
         chan->exempt_time,
-        chan->invite_time
-        ) == EOF)
-          return 0;
-
-     if (lfprintf(f, "\
-%cenforcebans %cdynamicbans %cuserbans \
-%cbitch %cprotectops %crevenge %crevengebot %cprivate %ccycle \
-%cinactive %cdynamicexempts %cuserexempts %cdynamicinvites %cuserinvites \
-%cnodesynch %cclosed %ctake %cmanop %cvoice %cfastop %cautoop }\n",
+        chan->invite_time,
  	PLSMNS(channel_enforcebans(chan)),
 	PLSMNS(channel_dynamicbans(chan)),
 	PLSMNS(!channel_nouserbans(chan)),
@@ -1114,16 +1102,12 @@ void channels_writeuserfile()
  * Returns 1 if a mask on `chan' by `who' may be expired and 0 if
  * not.
  */
-int expired_mask(struct chanset_t *chan, char *who)
+bool expired_mask(struct chanset_t *chan, char *who)
 {
   memberlist *m = NULL, *m2 = NULL;
   char buf[UHOSTLEN] = "", *snick = NULL, *sfrom = NULL;
   struct userrec *u = NULL;
 
-  /* Always expire masks, regardless of who set it? */
-  if (force_expire)
-    return 1;
-
   strcpy(buf, who);
   sfrom = buf;
   snick = splitnick(&sfrom);
@@ -1207,13 +1191,14 @@ static void check_expired_bans(void)
  */
 static void check_expired_exempts(void)
 {
+  if (!use_exempts)
+    return;
+
   maskrec *u = NULL, *u2 = NULL;
   struct chanset_t *chan = NULL;
   masklist *b = NULL, *e = NULL;
   int match;
 
-  if (!use_exempts)
-    return;
   for (u = global_exempts; u; u = u2) {
     u2 = u->next;
     if (!(u->flags & MASKREC_PERM) && (now >= u->expire)) {
@@ -1284,12 +1269,13 @@ static void check_expired_exempts(void)
  */
 static void check_expired_invites(void)
 {
+  if (!use_invites)
+    return;
+
   maskrec *u = NULL, *u2 = NULL;
   struct chanset_t *chan = NULL;
   masklist *b = NULL;
 
-  if (!use_invites)
-    return;
   for (u = global_invites; u; u = u2) {
     u2 = u->next;
     if (!(u->flags & MASKREC_PERM) && (now >= u->expire)) {

+ 11 - 9
src/mod/compress.mod/compress.c

@@ -67,13 +67,13 @@ static int is_compressedfile(char *filename);
 
 static int is_compressedfile(char *filename)
 {
+  if (!is_file(filename))
+    return COMPF_FAILED;
+
   char buf1[50] = "", buf2[50] = "";
   FILE *fin = NULL;
   register int len1, len2, i;
 
-  if (!is_file(filename))
-    return COMPF_FAILED;
-
   /* Read data with zlib routines.
    */
   fin = gzopen(filename, "rb");
@@ -114,15 +114,16 @@ static int is_compressedfile(char *filename)
  */
 static int uncompress_to_file(char *f_src, char *f_target)
 {
-  char buf[BUFLEN] = "";
-  int len;
-  FILE *fin = NULL, *fout = NULL;
-
   if (!is_file(f_src)) {
     putlog(LOG_MISC, "*", "Failed to uncompress file `%s': not a file.",
 	   f_src);
     return COMPF_ERROR;
   }
+
+  char buf[BUFLEN] = "";
+  int len;
+  FILE *fin = NULL, *fout = NULL;
+
   fin = gzopen(f_src, "rb");
   if (!fin) {
     putlog(LOG_MISC, "*", "Failed to uncompress file `%s': gzopen failed.",
@@ -181,7 +182,8 @@ inline static void adjust_mode_num(int *mode)
  */
 static int compress_to_file_mmap(FILE *fout, FILE *fin)
 {
-    int	len, ifd = fileno(fin);
+    size_t len;
+    int ifd = fileno(fin);
     char *buf = NULL;
     struct stat st;
 
@@ -215,7 +217,7 @@ static int compress_to_file(char *f_src, char *f_target, int mode_num)
 {
   char buf[BUFLEN] = "", mode[5] = "";
   FILE *fin = NULL, *fout = NULL;
-  int len;
+  size_t len;
 
   adjust_mode_num(&mode_num);
   egg_snprintf(mode, sizeof mode, "wb%d", mode_num);

+ 14 - 18
src/mod/console.mod/console.c

@@ -36,15 +36,12 @@ struct console_info {
   int whom;
 };
 
-static int
+static bool
 console_unpack(struct userrec *u, struct user_entry *e)
 {
-  struct console_info *ci = NULL;
-  char *par = NULL, *arg = NULL;
-
-  ci = (struct console_info *) calloc(1, sizeof(struct console_info));
+  struct console_info *ci = (struct console_info *) calloc(1, sizeof(struct console_info));
+  char *par = e->u.list->extra, *arg = NULL;
 
-  par = e->u.list->extra;
   arg = newsplit(&par);
   ci->channel = strdup(arg);
   arg = newsplit(&par);
@@ -73,7 +70,7 @@ console_unpack(struct userrec *u, struct user_entry *e)
   return 1;
 }
 
-static int
+static bool
 console_kill(struct user_entry *e)
 {
   struct console_info *i = (struct console_info *) e->u.extra;
@@ -85,7 +82,7 @@ console_kill(struct user_entry *e)
 }
 
 #ifdef HUB
-static int
+static bool
 console_write_userfile(FILE * f, struct userrec *u, struct user_entry *e)
 {
   struct console_info *i = (struct console_info *) e->u.extra;
@@ -99,7 +96,7 @@ console_write_userfile(FILE * f, struct userrec *u, struct user_entry *e)
 }
 #endif /* HUB */
 
-static int
+static bool
 console_set(struct userrec *u, struct user_entry *e, void *buf)
 {
   struct console_info *ci = (struct console_info *) e->u.extra;
@@ -128,12 +125,11 @@ console_set(struct userrec *u, struct user_entry *e, void *buf)
   return 1;
 }
 
-static int
+static bool
 console_gotshare(struct userrec *u, struct user_entry *e, char *par, int idx)
 {
   struct console_info *ci = (struct console_info *) e->u.extra;
   char *arg = NULL;
-  int i;
 
   arg = newsplit(&par);
   if (ci) {
@@ -165,7 +161,7 @@ console_gotshare(struct userrec *u, struct user_entry *e, char *par, int idx)
 
   e->u.extra = ci;
   /* now let's propogate to the dcc list */
-  for (i = 0; i < dcc_total; i++) {
+  for (int i = 0; i < dcc_total; i++) {
     if ((dcc[i].type == &DCC_CHAT) && !strcmp(dcc[i].user->handle, u->handle)) {
       if (ci->channel && ci->channel[0])
         strcpy(dcc[i].u.chat->con_chan, ci->channel);
@@ -245,9 +241,9 @@ static struct user_entry_type USERENTRY_CONSOLE = {
 static int
 console_chon(char *handle, int idx)
 {
-  struct console_info *i = (struct console_info *) get_user(&USERENTRY_CONSOLE, dcc[idx].user);
-
   if (dcc[idx].type == &DCC_CHAT) {
+    struct console_info *i = (struct console_info *) get_user(&USERENTRY_CONSOLE, dcc[idx].user);
+
     if (i) {
       if (i->channel && i->channel[0])
         strcpy(dcc[idx].u.chat->con_chan, i->channel);
@@ -312,9 +308,9 @@ console_store(int idx, char *par)
 {
   struct console_info *i = (struct console_info *) get_user(&USERENTRY_CONSOLE, dcc[idx].user);
 
-  if (!i) {
+  if (!i) 
     i = (struct console_info *) calloc(1, sizeof(struct console_info));
-  }
+  
   if (i->channel)
     free(i->channel);
   i->channel = strdup(dcc[idx].u.chat->con_chan);
@@ -370,12 +366,12 @@ console_store(int idx, char *par)
 }
 
 /* cmds.c:cmd_console calls this, better than chof bind - drummer,07/25/1999 */
-int
+void
 console_dostore(int idx)
 {
   if (console_autosave)
     console_store(idx, NULL);
-  return 0;
+  return;
 }
 
 static cmd_t mychon[] = {

+ 1 - 1
src/mod/console.mod/console.h

@@ -18,6 +18,6 @@
 #define CONSOLE_NO		"no"
 #define CONSOLE_COLOR		"Color:"
 
-int console_dostore(int);
+void console_dostore(int);
 
 #endif				/* _EGG_MOD_CONSOLE_CONSOLE_H */

+ 13 - 17
src/mod/ctcp.mod/ctcp.c

@@ -338,8 +338,6 @@ void sendaway()
 
 static void ctcp_minutely()
 {
-  int i;
-
   if (server_online) {
     if ((cloak_awaytime == 0) && (cloak_heretime == 0)) {
       cloak_heretime = now;
@@ -364,7 +362,7 @@ static void ctcp_minutely()
   }
 
   if (listen_time <= 0) {
-    for (i = 0; i < dcc_total; i++) {
+    for (int i = 0; i < dcc_total; i++) {
       if ((dcc[i].type->flags & DCT_LISTEN) && (!strcmp(dcc[i].nick, "(telnet)") || !strcmp(dcc[i].nick, "(telnet6)"))) {
         putlog(LOG_DEBUG, "*", "Closing listening port %d %s", dcc[i].port, dcc[i].nick);
 
@@ -379,14 +377,12 @@ static void ctcp_minutely()
 
 static int ctcp_FINGER(char *nick, char *uhost, struct userrec *u, char *object, char *keyword, char *text)
 {
-  time_t idletime;
+  time_t idletime = 0;
 
   if (cloak_awaytime)
     idletime = now - cloak_awaytime;
   else if (cloak_heretime)
     idletime = now - cloak_heretime;
-  else
-    idletime = 0;
   dprintf(DP_HELP, "NOTICE %s :\001%s %s (%s@%s) Idle %li second%s\001\n", nick, keyword, "",
                    conf.username ? conf.username : conf.bot->nick, 
                    (strchr(botuserhost, '@') + 1), idletime, idletime == 1 ? "" : "s");
@@ -403,7 +399,6 @@ static int ctcp_ECHO(char *nick, char *uhost, struct userrec *u, char *object, c
 }
 static int ctcp_PING(char *nick, char *uhost, struct userrec *u, char *object, char *keyword, char *text)
 {
-
   if (strlen(text) <= 80)       /* bitchx ignores > 80 */
     dprintf(DP_HELP, "NOTICE %s :\001%s %s\001\n", nick, keyword, text);
   return BIND_RET_BREAK;
@@ -449,16 +444,15 @@ static int ctcp_VERSION(char *nick, char *uhost, struct userrec *u, char *object
 
 static int ctcp_WHOAMI(char *nick, char *uhost, struct userrec *u, char *object, char *keyword, char *text)
 {
-
   dprintf(DP_HELP, "NOTICE %s :\002BitchX\002: Access Denied\n", nick);
   return BIND_RET_BREAK;
 }
 
 static int ctcp_OP(char *nick, char *uhost, struct userrec *u, char *object, char *keyword, char *text)
 {
-  char chan[256] = "", *p = NULL;
-
   if (text[0]) {
+    char chan[256] = "", *p = NULL;
+
     strncpyz(chan, text, sizeof(chan));
     p = strchr(chan, ' ');
     if (p)
@@ -470,10 +464,10 @@ static int ctcp_OP(char *nick, char *uhost, struct userrec *u, char *object, cha
 
 static int ctcp_INVITE_UNBAN(char *nick, char *uhost, struct userrec *u, char *object, char *keyword, char *text)
 {
-  struct chanset_t *chan = chanset;
-  char chname[256] = "", *p = NULL;
-
   if (text[0] == '#') {
+    struct chanset_t *chan = chanset;
+    char chname[256] = "", *p = NULL;
+
     strncpyz(chname, text, sizeof(chname));
     p = strchr(chname, ' ');
     if (p)
@@ -576,7 +570,6 @@ static int ctcp_TIME(char *nick, char *uhost, struct userrec *u, char *object, c
 
 static int ctcp_CHAT(char *nick, char *uhost, struct userrec *u, char *object, char *keyword, char *text)
 {
-  int i, ix = (-1);
 
   if (!ischanhub()) 
     return BIND_RET_LOG;
@@ -586,7 +579,9 @@ static int ctcp_CHAT(char *nick, char *uhost, struct userrec *u, char *object, c
       return BIND_RET_BREAK;
     }
 
-    for (i = 0; i < dcc_total; i++) {
+    int ix = -1;
+
+    for (int i = 0; i < dcc_total; i++) {
       if ((dcc[i].type->flags & DCT_LISTEN) && (!strcmp(dcc[i].nick, "(telnet)")))
         ix = i;
     }
@@ -634,11 +629,12 @@ static void cloak_describe(struct cfg_entry *cfgent, int idx)
 static void cloak_changed(struct cfg_entry *cfgent, int *valid)
 {
   char *p = NULL;
-  int i;
 
   if (!(p = cfgent->ldata ? cfgent->ldata : cfgent->gdata))
     return;
-  i = atoi(p);
+
+  int i = atoi(p);
+
 #ifdef LEAF
   if (i == 0)
     i = randint(CLOAK_COUNT) + 1;

+ 5 - 5
src/mod/dns.mod/coredns.c

@@ -152,7 +152,7 @@ static struct resolve *ipbash[BASH_SIZE];
 static struct resolve *hostbash[BASH_SIZE];
 static struct resolve *expireresolves = NULL;
 
-static IP localhost;
+static in_addr_t localhost;
 
 static long idseed = 0xdeadbeef;
 static long aseed;
@@ -229,7 +229,7 @@ inline static u_32bit_t getidbash(u_16bit_t id)
 
 /* Return the hash bucket number for ip.
  */
-inline static u_32bit_t getipbash(IP ip)
+inline static u_32bit_t getipbash(in_addr_t ip)
 {
     return (u_32bit_t) BASH_MODULO(ip);
 }
@@ -517,7 +517,7 @@ static struct resolve *findhost(char *hostn)
 
 /* Find request structure using the ip.
  */
-static struct resolve *findip(IP ip)
+static struct resolve *findip(in_addr_t ip)
 {
     struct resolve *rp = NULL;
     u_32bit_t bashnum;
@@ -823,7 +823,7 @@ static void parserespacket(u_8bit_t *s, size_t l)
 				ddebug1(RES_ERR "Unsupported rdata format for \"A\" type. (%u bytes)", rdatalength);
 				return;
 			    }
-			    egg_memcpy(&rp->ip, (IP *) c, sizeof(IP));
+			    egg_memcpy(&rp->ip, (in_addr_t *) c, sizeof(in_addr_t));
 			    linkresolveip(rp);
 			    passrp(rp, ttl, T_A);
 			    return;
@@ -985,7 +985,7 @@ static void dns_check_expires(void)
 
 /* Start searching for a host-name, using it's ip-address.
  */
-void dns_hostbyip(IP ip)
+void dns_hostbyip(in_addr_t ip)
 {
     struct resolve *rp = NULL;
 

+ 1 - 1
src/mod/dns.mod/dns.c

@@ -75,7 +75,7 @@ static void eof_dns_socket(int idx)
     lostdcc(idx);
 }
 
-static void dns_socket(int idx, char *buf, int len)
+static void dns_socket(int idx, char *buf, size_t len)
 {
   dns_ack();
 }

+ 2 - 2
src/mod/dns.mod/dns.h

@@ -33,7 +33,7 @@ struct resolve {
     struct resolve	*previoushost;
     time_t		expiretime;
     char		*hostn;
-    IP			ip;
+    in_addr_t			ip;
     u_16bit_t		id;
     u_8bit_t		state;
     u_8bit_t		sends;
@@ -58,7 +58,7 @@ enum resolve_states {
 #define ddebug4(x, x1, x2, x3, x4) sdprintf(x, x1, x2, x3, x4)
 
 int dns_report(int, int);
-void dns_hostbyip(IP);
+void dns_hostbyip(in_addr_t);
 void dns_ipbyhost(char *);
 
 #endif	/* _EGG_MOD_DNS_DNS_H */

+ 210 - 208
src/mod/irc.mod/chan.c

@@ -23,15 +23,13 @@ static char   last_invchan[300] = "";
  */
 static memberlist *newmember(struct chanset_t *chan, char * nick)
 {
-  memberlist *x = NULL, *lx = NULL, *n = NULL;
+  memberlist *x = x = chan->channel.member, *lx = NULL, *n = (memberlist *) calloc(1, sizeof(memberlist));
 
-  x = chan->channel.member;
-  lx = NULL;
   while (x && x->nick[0] && (rfc_casecmp(x->nick, nick)<0)) {
     lx = x;
     x = x->next;
   }
-  n = (memberlist *) calloc(1, sizeof(memberlist));
+
   n->next = NULL;
   strncpyz(n->nick, nick, sizeof(n->nick));
   n->split = 0L;
@@ -53,12 +51,11 @@ static memberlist *newmember(struct chanset_t *chan, char * nick)
  */
 static void update_idle(char *chname, char *nick)
 {
-  memberlist *m = NULL;
-  struct chanset_t *chan = NULL;
+  struct chanset_t *chan = findchan_by_dname(chname);
 
-  chan = findchan_by_dname(chname);
   if (chan) {
-    m = ismember(chan, nick);
+    memberlist *m = ismember(chan, nick);
+
     if (m)
       m->last = now;
   }
@@ -69,11 +66,10 @@ static void update_idle(char *chname, char *nick)
 static char *getchanmode(struct chanset_t *chan)
 {
   static char s[121] = "";
-  int atr, i;
+  int atr = chan->channel.mode;
+  size_t i = 1;
 
   s[0] = '+';
-  i = 1;
-  atr = chan->channel.mode;
   if (atr & CHANINV)
     s[i++] = 'i';
   if (atr & CHANPRIV)
@@ -112,13 +108,12 @@ static char *getchanmode(struct chanset_t *chan)
 
 static void check_exemptlist(struct chanset_t *chan, char *from)
 {
-  masklist *e = NULL;
-  int ok = 0;
-
   if (!use_exempts)
     return;
 
-  for (e = chan->channel.exempt; e->mask[0]; e = e->next)
+  bool ok = 0;
+
+  for (masklist *e = chan->channel.exempt; e->mask[0]; e = e->next)
     if (wild_match(e->mask, from)) {
       add_mode(chan, '-', 'e', e->mask);
       ok = 1;
@@ -127,15 +122,16 @@ static void check_exemptlist(struct chanset_t *chan, char *from)
     flush_mode(chan, QUICK);
 }
 
-void priority_do(struct chanset_t * chan, int opsonly, int action) 
+void priority_do(struct chanset_t * chan, bool opsonly, int action) 
 {
-  memberlist *m = NULL;
-  int ops = 0, targets = 0, bpos = 0, tpos = 0, ft = 0, ct = 0, actions = 0, sent = 0;
-
   if (!me_op(chan))
     return;
   if (channel_pending(chan) || !shouldjoin(chan) || !channel_active(chan))
     return;
+
+  memberlist *m = NULL;
+  int ops = 0, targets = 0, bpos = 0, tpos = 0, ft = 0, ct = 0, actions = 0, sent = 0;
+
   for (m = chan->channel.member; m && m->nick[0]; m = m->next) {
     if (!m->user) {
       char s[256] = "";
@@ -327,24 +323,22 @@ static void do_mask(struct chanset_t *chan, masklist *m, char *mask, char Mode)
 /* This is a clone of detect_flood, but works for channel specificity now
  * and handles kick & deop as well.
  */
-static int detect_chan_flood(char *floodnick, char *floodhost, char *from,
+static bool detect_chan_flood(char *floodnick, char *floodhost, char *from,
 			     struct chanset_t *chan, int which, char *victim)
 {
-  char h[UHOSTLEN] = "", ftype[12] = "", *p = NULL;
-  struct userrec *u = NULL;
-  memberlist *m = NULL;
-  int thr = 0, lapse = 0;
-  struct flag_record fr = {FR_GLOBAL | FR_CHAN, 0, 0, 0 };
-
   if (!chan || (which < 0) || (which >= FLOOD_CHAN_MAX))
     return 0;
-  m = ismember(chan, floodnick);
+
   /* Do not punish non-existant channel members and IRC services like
    * ChanServ
    */
+  memberlist *m = ismember(chan, floodnick);
+
   if (!m && (which != FLOOD_JOIN))
     return 0;
 
+  struct flag_record fr = {FR_GLOBAL | FR_CHAN, 0, 0, 0 };
+
   get_user_flagrec(get_user_by_host(from), &fr, chan->dname);
   if (glob_bot(fr) ||
       ((which == FLOOD_DEOP) &&
@@ -355,6 +349,11 @@ static int detect_chan_flood(char *floodnick, char *floodhost, char *from,
        (chk_noflood(fr))))
     return 0;
 
+  char h[UHOSTLEN] = "", ftype[12] = "", *p = NULL;
+  struct userrec *u = NULL;
+  int thr = 0;
+  time_t lapse = 0;
+
   /* Determine how many are necessary to make a flood. */
   switch (which) {
   case FLOOD_PRIVMSG:
@@ -514,10 +513,10 @@ static int detect_chan_flood(char *floodnick, char *floodhost, char *from,
 static void refresh_ban_kick(struct chanset_t *, char *, char *);
 static void doban(struct chanset_t *chan, memberlist *m)
 {
-  char s[UHOSTLEN] = "", *s1 = NULL;
-
   if (!chan || !m) return;
 
+  char s[UHOSTLEN] = "", *s1 = NULL;
+
   sprintf(s, "%s!%s", m->nick, m->userhost);
 
   if (!(use_exempts &&
@@ -552,16 +551,14 @@ static char *quickban(struct chanset_t *chan, char *uhost)
  */
 static void kick_all(struct chanset_t *chan, char *hostmask, const char *comment, int bantype)
 {
-  memberlist *m = NULL;
-  int flushed;
-
   if (!me_op(chan))
     return;
-  flushed = 0;
-  for (m = chan->channel.member; m && m->nick[0]; m = m->next) {
-    char s[UHOSTLEN] = "";
-    struct flag_record fr = {FR_GLOBAL | FR_CHAN, 0, 0, 0 };
 
+  int flushed = 0;
+  char s[UHOSTLEN] = "";
+  struct flag_record fr = {FR_GLOBAL | FR_CHAN, 0, 0, 0 };
+
+  for (memberlist *m = chan->channel.member; m && m->nick[0]; m = m->next) {
     sprintf(s, "%s!%s", m->nick, m->userhost);
     get_user_flagrec(m->user ? m->user : get_user_by_host(s), &fr, chan->dname);
     if (me_op(chan) &&
@@ -586,16 +583,16 @@ static void kick_all(struct chanset_t *chan, char *hostmask, const char *comment
  */
 static void refresh_ban_kick(struct chanset_t *chan, char *user, char *nick)
 {
-  register maskrec *b = NULL;
-  memberlist *m = NULL;
-  int cycle;
+  memberlist *m = ismember(chan, nick);
 
-  m = ismember(chan, nick);
   if (!m || chan_sentkick(m))
     return;
+
+  register maskrec *b = NULL;
+
   /* Check global bans in first cycle and channel bans
      in second cycle. */
-  for (cycle = 0; cycle < 2; cycle++) {
+  for (int cycle = 0; cycle < 2; cycle++) {
     for (b = cycle ? chan->bans : global_bans; b; b = b->next) {
       if (wild_match(b->mask, user)) {
 	struct flag_record	fr = {FR_GLOBAL | FR_CHAN, 0, 0, 0 };
@@ -629,11 +626,10 @@ static void refresh_exempt(struct chanset_t *chan, char *user)
 {
   maskrec *e = NULL;
   masklist *b = NULL;
-  int cycle;
 
   /* Check global exempts in first cycle and channel exempts
      in second cycle. */
-  for (cycle = 0; cycle < 2; cycle++) {
+  for (int cycle = 0; cycle < 2; cycle++) {
     for (e = cycle ? chan->exempts : global_exempts; e; e = e->next) {
       if (wild_match(user, e->mask) || wild_match(e->mask,user)) {
         for (b = chan->channel.ban; b && b->mask[0]; b = b->next) {
@@ -652,11 +648,10 @@ static void refresh_exempt(struct chanset_t *chan, char *user)
 static void refresh_invite(struct chanset_t *chan, char *user)
 {
   maskrec *i = NULL;
-  int cycle;
 
   /* Check global invites in first cycle and channel invites
      in second cycle. */
-  for (cycle = 0; cycle < 2; cycle++) {
+  for (int cycle = 0; cycle < 2; cycle++) {
     for (i = cycle ? chan->invites : global_invites; i; i = i->next) {
       if (wild_match(i->mask, user) &&
 	  ((i->flags & MASKREC_STICKY) || (chan->channel.mode & CHANINV))) {
@@ -674,14 +669,14 @@ static void refresh_invite(struct chanset_t *chan, char *user)
  */
 static void enforce_bans(struct chanset_t *chan)
 {
-  char me[UHOSTLEN] = "";
-  masklist *b = NULL;
-
   if (!me_op(chan))
     return;			/* Can't do it :( */
+
+  char me[UHOSTLEN] = "";
+
   simple_sprintf(me, "%s!%s", botname, botuserhost);
   /* Go through all bans, kicking the users. */
-  for (b = chan->channel.ban; b && b->mask[0]; b = b->next) {
+  for (masklist *b = chan->channel.ban; b && b->mask[0]; b = b->next) {
     if (!wild_match(b->mask, me))
       if (!isexempted(chan, b->mask) && !(chan->ircnet_status & CHAN_ASKED_EXEMPTS))
 	kick_all(chan, b->mask, IRC_YOUREBANNED, 1);
@@ -696,11 +691,10 @@ static void enforce_bans(struct chanset_t *chan)
 static void recheck_bans(struct chanset_t *chan)
 {
   maskrec *u = NULL;
-  int cycle;
 
   /* Check global bans in first cycle and channel bans
      in second cycle. */
-  for (cycle = 0; cycle < 2; cycle++) {
+  for (int cycle = 0; cycle < 2; cycle++) {
     for (u = cycle ? chan->bans : global_bans; u; u = u->next)
       if (!isbanned(chan, u->mask) && (!channel_dynamicbans(chan) ||
 				       (u->flags & MASKREC_STICKY)))
@@ -717,11 +711,10 @@ static void recheck_exempts(struct chanset_t *chan)
 {
   maskrec *e = NULL;
   masklist *b = NULL;
-  int cycle;
 
   /* Check global exempts in first cycle and channel exempts
      in second cycle. */
-  for (cycle = 0; cycle < 2; cycle++) {
+  for (int cycle = 0; cycle < 2; cycle++) {
     for (e = cycle ? chan->exempts : global_exempts; e; e = e->next) {
       if (!isexempted(chan, e->mask) &&
           (!channel_dynamicexempts(chan) || (e->flags & MASKREC_STICKY)))
@@ -745,11 +738,10 @@ static void recheck_exempts(struct chanset_t *chan)
 static void recheck_invites(struct chanset_t *chan)
 {
   maskrec *ir = NULL;
-  int cycle;
 
   /* Check global invites in first cycle and channel invites
      in second cycle. */
-  for (cycle = 0; cycle < 2; cycle++)  {
+  for (int cycle = 0; cycle < 2; cycle++)  {
     for (ir = cycle ? chan->invites : global_invites; ir; ir = ir->next) {
       /* If invite isn't set and (channel is not dynamic invites and not invite
        * only) or invite is sticky.
@@ -792,14 +784,14 @@ static void resetmasks(struct chanset_t *chan, masklist *m, maskrec *mrec, maskr
   }
 }
 
-void check_this_ban(struct chanset_t *chan, char *banmask, int sticky)
+void check_this_ban(struct chanset_t *chan, char *banmask, bool sticky)
 {
-  memberlist *m = NULL;
-  char user[UHOSTLEN] = "";
-
   if (!me_op(chan))
     return;
-  for (m = chan->channel.member; m && m->nick[0]; m = m->next) {
+
+  char user[UHOSTLEN] = "";
+
+  for (memberlist *m = chan->channel.member; m && m->nick[0]; m = m->next) {
     sprintf(user, "%s!%s", m->nick, m->userhost);
     if (wild_match(banmask, user) &&
         !(use_exempts &&
@@ -812,13 +804,13 @@ void check_this_ban(struct chanset_t *chan, char *banmask, int sticky)
     add_mode(chan, '+', 'b', banmask);
 }
 
-void check_this_exempt(struct chanset_t *chan, char *mask, int sticky)
+void check_this_exempt(struct chanset_t *chan, char *mask, bool sticky)
 {
   if (!isexempted(chan, mask) && (!channel_dynamicexempts(chan) || sticky))
     add_mode(chan, '+', 'e', mask);
 }
 
-void check_this_invite(struct chanset_t *chan, char *mask, int sticky)
+void check_this_invite(struct chanset_t *chan, char *mask, bool sticky)
 {
   if (!isinvited(chan, mask) && (!channel_dynamicinvites(chan) || sticky))
     add_mode(chan, '+', 'I', mask);
@@ -907,12 +899,13 @@ void recheck_channel_modes(struct chanset_t *chan)
 
 static void check_this_member(struct chanset_t *chan, char *nick, struct flag_record *fr)
 {
-  memberlist *m = NULL;
-  char s[UHOSTLEN] = "", *p = NULL;
+  memberlist *m = ismember(chan, nick);
 
-  m = ismember(chan, nick);
   if (!m || match_my_nick(nick) || !me_op(chan))
     return;
+
+  char s[UHOSTLEN] = "";
+
   if (me_op(chan)) {
     /* +d or bitch and not an op
      * we dont check private because +private does not imply bitch. */
@@ -951,9 +944,10 @@ static void check_this_member(struct chanset_t *chan, char *nick, struct flag_re
       refresh_ban_kick(chan, s, m->nick);
     /* are they +k ? */
     if (!chan_sentkick(m) && (chan_kick(*fr) || glob_kick(*fr)) && me_op(chan)) {
+      char *p = (char *) get_user(&USERENTRY_COMMENT, m->user);
+
       check_exemptlist(chan, s);
       quickban(chan, m->userhost);
-      p = (char *) get_user(&USERENTRY_COMMENT, m->user);
       dprintf(DP_SERVER, "KICK %s %s :%s%s\n", chan->name, m->nick, bankickprefix, p ? p : response(RES_KUSER));
       m->flags |= SENTKICK;
     }
@@ -965,10 +959,9 @@ void check_this_user(char *hand, int del, char *host)
   char s[UHOSTLEN] = "";
   memberlist *m = NULL;
   struct userrec *u = NULL;
-  struct chanset_t *chan = NULL;
   struct flag_record fr = {FR_GLOBAL | FR_CHAN, 0, 0, 0 };
 
-  for (chan = chanset; chan; chan = chan->next)
+  for (struct chanset_t *chan = chanset; chan; chan = chan->next)
     for (m = chan->channel.member; m && m->nick[0]; m = m->next) {
       sprintf(s, "%s!%s", m->nick, m->userhost);
       u = m->user ? m->user : get_user_by_host(s);
@@ -982,14 +975,17 @@ void check_this_user(char *hand, int del, char *host)
 }
 
 static void enforce_bitch(struct chanset_t *chan) {
-  if (!chan || !me_op(chan)) return;
+  if (!chan || !me_op(chan)) 
+    return;
   priority_do(chan, 1, PRIO_DEOP);
 }
 
 void enforce_closed(struct chanset_t *chan) {
+  if (!chan || !me_op(chan)) 
+    return;
+
   char buf[1024] = "";
 
-  if (!chan || !me_op(chan)) return;
   if (!(chan->channel.mode & CHANINV))
     strcat(buf, "i");
   if (chan->closed_private && !(chan->channel.mode & CHANPRIV))
@@ -1002,19 +998,16 @@ void enforce_closed(struct chanset_t *chan) {
 static char *
 take_massopline(char *op, char **to_op)
 {
-  char *nick = NULL, *modes = NULL, *nicks = NULL, *ret = NULL;
-  int i = 0, useop = 0;
-
-  nicks = (char *) calloc(1, 51);
-  modes = (char *) calloc(1, 10);
+  char *nicks = (char *) calloc(1, 51), *modes = (char *) calloc(1, 10), *ret = (char *) calloc(1, 61), *nick;
+  bool useop = 0;
 
-  for (i = 0; i < 4; i++) {
+  for (int i = 0; i < 4; i++) {
     nick = NULL;
     if (*to_op[0] || op) {
       /* if 'op' then use it, then move on to to_op */
       if (!useop && op) {
         nick = op;
-        useop++;
+        useop = 1;
       } else if (*to_op[0])
         nick = newsplit(to_op);
       if (nick) {
@@ -1025,7 +1018,6 @@ take_massopline(char *op, char **to_op)
     }
   }
   
-  ret = (char *) calloc(1, 61);
   strcat(ret, modes);
   strcat(ret, " ");
   strcat(ret, nicks);
@@ -1036,18 +1028,18 @@ take_massopline(char *op, char **to_op)
 }
 
 static char *
-take_makeline(char *op, char *deops, int deopn)
+take_makeline(char *op, char *deops, unsigned int deopn)
 {
-  int pos = 0, i = 0, n = 0, opn = op ? 1 : 0;
-  char *ret = NULL;
-
-  n = opn + deopn;		/* op + deops */
-  ret = (char *) calloc(1, 101);
-  pos = randint(deopn);
+  bool opn = op ? 1 : 0;
+  unsigned int n = opn + deopn;		/* op + deops */
+  unsigned int pos = randint(deopn), i;
+  char *ret = (char *) calloc(1, 101);
   
   for (i = 0; i < n; i++) {
-    if (opn && i == pos)      strcat(ret, "+o");
-    else if (deopn)           strcat(ret, "-o");
+    if (opn && i == pos)
+      strcat(ret, "+o");
+    else if (deopn)
+      strcat(ret, "-o");
   }
 
   strcat(ret, " ");
@@ -1068,18 +1060,18 @@ take_makeline(char *op, char *deops, int deopn)
 static void
 do_take(struct chanset_t *chan)
 {
-  memberlist *m = NULL;
-  char work[512] = "", *to_op = NULL, *to_deop = NULL, *to_op_ptr = NULL, *to_deop_ptr = NULL;
-  int lines = 0;
-
-  to_op = to_op_ptr = (char *) calloc(1, 2048);
-  to_deop = to_deop_ptr = (char *) calloc(1, 2048);
+  char work[512] = "", *op, *modeline, deops[201] = "";;
+  unsigned int lines = 0, deopn, i;
+  char *to_op = (char *) calloc(1, 2048), *to_op_ptr = to_op;
+  char *to_deop = (char *) calloc(1, 2048), *to_deop_ptr = to_deop;
+  bool hasop, isbot;
 
-  for (m = chan->channel.member; m && m->nick[0]; m = m->next) {
-    int hasop = (m->flags & CHANOP), isbot = 0;
+  for (memberlist *m = chan->channel.member; m && m->nick[0]; m = m->next) {
+    hasop = (m->flags & CHANOP);
+    isbot = 0;
 
     if (m->user && m->user->bot)
-      isbot++;
+      isbot = 1;
 
     if (rfc_casecmp(m->nick, botname)) {
       if (isbot && !hasop) {
@@ -1097,15 +1089,18 @@ do_take(struct chanset_t *chan)
   putlog(LOG_MISC, "*", "op: %s", to_op);
   putlog(LOG_MISC, "*", "deop: %s", to_deop);
   */
+
   while (to_op[0] || to_deop[0]) {
-    int deopn = 0, i = 0;
-    char *op = NULL, *modeline = NULL, deops[201] = "";
+    deopn = 0;
+    op = NULL;
+    modeline = NULL;
+    deops[0] = 0;
 
     if (to_op[0])
       op = newsplit(&to_op);
 
-    for (i = 0; i < (signed) modesperline; i ++) {
-      if (to_deop[0] && ((i < ((signed) modesperline - 1)) || (!op))) {
+    for (i = 0; i < modesperline; i ++) {
+      if (to_deop[0] && ((i < (modesperline - 1)) || (!op))) {
         deopn++; 
         strcat(deops, newsplit(&to_deop)); 
         strcat(deops, " "); 
@@ -1155,23 +1150,24 @@ time_t last_eI; /* this will stop +e and +I from being checked over and over if
  */
 void recheck_channel(struct chanset_t *chan, int dobans)
 {
-  memberlist *m = NULL;
-  char s[UHOSTLEN] = "";
-  struct flag_record fr = {FR_GLOBAL | FR_CHAN, 0, 0, 0 };
   static int stacking = 0;
-  int stop_reset = 0, botops = 0, nonbotops = 0, botnonops = 0;
-
 
   if (stacking)
     return;			/* wewps */
   if (!userlist || loading)                /* Bot doesnt know anybody */
     return;                     /* ... it's better not to deop everybody */
+
+  memberlist *m = NULL;
+  char s[UHOSTLEN] = "";
+  struct flag_record fr = {FR_GLOBAL | FR_CHAN, 0, 0, 0 };
+  int stop_reset = 0, botops = 0, nonbotops = 0, botnonops = 0;
+
   stacking++;
 
   putlog(LOG_DEBUG, "*", "recheck_channel %s", chan->dname);
 
   for (m = chan->channel.member; m && m->nick[0]; m = m->next) {
-    int hasop = chan_hasop(m);
+    bool hasop = chan_hasop(m);
 
     if (m) {
       if (m->user && m->user->bot && (m->user->flags & USER_OP)) {
@@ -1261,21 +1257,25 @@ void recheck_channel(struct chanset_t *chan, int dobans)
  */
 static int got324(char *from, char *msg)
 {
-  int i = 1, ok =0;
-  char *p = NULL, *q = NULL, *chname = NULL;
-  struct chanset_t *chan = NULL;
+  char *chname = NULL;
 
   newsplit(&msg);
   chname = newsplit(&msg);
   if (match_my_nick(chname))
       return 0;
 
-  chan = findchan(chname);
+  struct chanset_t *chan = findchan(chname);
+
   if (!chan) {
     putlog(LOG_MISC, "*", "%s: %s", IRC_UNEXPECTEDMODE, chname);
     dprintf(DP_SERVER, "PART %s\n", chname);
     return 0;
   }
+
+  int i = 1;
+  bool ok = 0;
+  char *p = NULL, *q = NULL;
+
   if (chan->status & CHAN_ASKEDMODES)
     ok = 1;
   chan->status &= ~CHAN_ASKEDMODES;
@@ -1354,7 +1354,7 @@ static int got324(char *from, char *msg)
   return 0;
 }
 
-static void memberlist_reposition(struct chanset_t * chan, memberlist * target) {
+static void memberlist_reposition(struct chanset_t *chan, memberlist *target) {
   /* Move target from it's current position to it's correct sorted position */
   memberlist *old = NULL, *m = NULL;
   if (chan->channel.member == target) {
@@ -1395,10 +1395,11 @@ static int got352or4(struct chanset_t *chan, char *user, char *host, char *serve
 {
   struct flag_record fr = { FR_GLOBAL | FR_CHAN, 0, 0, 0 };
   char userhost[UHOSTLEN] = "";
-  memberlist *m = NULL;
-  int waschanop;
+  memberlist *m = ismember(chan, nick);	/* in my channel list copy? */
+  bool waschanop;
+  struct chanset_t *ch = NULL;
+  memberlist *ml = NULL;
 
-  m = ismember(chan, nick);	/* In my channel list copy? */
   if (!m) {			/* Nope, so update */
     m = newmember(chan, nick);	/* Get a new channel entry */
     m->joined = m->split = m->delay = 0L;	/* Don't know when he joined */
@@ -1408,8 +1409,6 @@ static int got352or4(struct chanset_t *chan, char *user, char *host, char *serve
   strcpy(m->nick, nick);	/* Store the nick in list */
 
   if (server) {
-    struct chanset_t *ch = NULL;
-    memberlist *ml = NULL;
     strncpyz(m->server, server, SERVLEN);
     /* Propagate server to other channel memlists... might save us a WHO #chan */
     for (ch = chanset; ch; ch = ch->next) {
@@ -1425,18 +1424,14 @@ static int got352or4(struct chanset_t *chan, char *user, char *host, char *serve
   } else
     m->server[0] = 0;
 
-  {
-    struct chanset_t *ch = NULL;
-    memberlist *ml = NULL;
-    m->hops = hops;
-    /* Propagate hops to other channel memlists... might save us a WHO #chan */
-    for (ch = chanset; ch; ch = ch->next) {
-      if (ch != chan) {
-        for (ml = ch->channel.member; ml && ml->nick[0]; ml = ml->next) {
-          if (!strcmp(ml->nick, m->nick)) {
-            ml->hops = m->hops;
-            break;
-          }
+  m->hops = hops;
+  /* Propagate hops to other channel memlists... might save us a WHO #chan */
+  for (ch = chanset; ch; ch = ch->next) {
+    if (ch != chan) {
+      for (ml = ch->channel.member; ml && ml->nick[0]; ml = ml->next) {
+        if (!strcmp(ml->nick, m->nick)) {
+          ml->hops = m->hops;
+          break;
         }
       }
     }
@@ -1512,16 +1507,18 @@ static int got352or4(struct chanset_t *chan, char *user, char *host, char *serve
  */
 static int got352(char *from, char *msg)
 {
-  char *nick = NULL, *user = NULL, *host = NULL, *chname = NULL, *flags = NULL, *server = NULL, *hops = NULL;
+  char *chname = NULL;
   struct chanset_t *chan = NULL;
 
   newsplit(&msg);		/* Skip my nick - effeciently */
   chname = newsplit(&msg);	/* Grab the channel */
   chan = findchan(chname);	/* See if I'm on channel */
   if (chan) {			/* Am I? */
+    char *nick = NULL, *user = NULL, *host = NULL, *flags = NULL, *server = NULL, *hops = NULL;
+
     user = newsplit(&msg);	/* Grab the user */
     host = newsplit(&msg);	/* Grab the host */
-    server = newsplit(&msg);      /* And the server */
+    server = newsplit(&msg);    /* And the server */
     nick = newsplit(&msg);	/* Grab the nick */
     flags = newsplit(&msg);	/* Grab the flags */
     hops = newsplit(&msg);	/* grab server hops */
@@ -1535,15 +1532,15 @@ static int got352(char *from, char *msg)
  */
 static int got354(char *from, char *msg)
 {
-  char *nick = NULL, *user = NULL, *host = NULL, *chname = NULL, *flags = NULL, *hops = NULL;
-  struct chanset_t *chan = NULL;
-
   if (use_354) {
     newsplit(&msg);		/* Skip my nick - effeciently */
     if (msg[0] && (strchr(CHANMETA, msg[0]) != NULL)) {
-      chname = newsplit(&msg);	/* Grab the channel */
-      chan = findchan(chname);	/* See if I'm on channel */
+      char *chname = newsplit(&msg);	/* Grab the channel */
+      struct chanset_t *chan = findchan(chname);	/* See if I'm on channel */
+
       if (chan) {		/* Am I? */
+        char *nick = NULL, *user = NULL, *host = NULL, *flags = NULL, *hops = NULL;
+
 	user = newsplit(&msg);	/* Grab the user */
 	host = newsplit(&msg);	/* Grab the host */
 	nick = newsplit(&msg);	/* Grab the nick */
@@ -1600,19 +1597,19 @@ static int got315(char *from, char *msg)
  */
 static int got367(char *from, char *origmsg)
 {
-  char *ban = NULL, *who = NULL, *chname = NULL, buf[511] = "", *msg = NULL;
+  char *chname = NULL, buf[511] = "", *msg = NULL;
   struct chanset_t *chan = NULL;
 
-  strncpy(buf, origmsg, 510);
-  buf[510] = 0;
+  strncpyz(buf, origmsg, sizeof(buf));
   msg = buf;
   newsplit(&msg);
   chname = newsplit(&msg);
   chan = findchan(chname);
   if (!chan || !(channel_pending(chan) || channel_active(chan)))
     return 0;
-  ban = newsplit(&msg);
-  who = newsplit(&msg);
+  
+  char *ban = newsplit(&msg), *who = newsplit(&msg);
+
   /* Extended timestamp format? */
   if (who[0])
     newban(chan, ban, who);
@@ -1646,22 +1643,22 @@ static int got368(char *from, char *msg)
  */
 static int got348(char *from, char *origmsg)
 {
-  char *exempt = NULL, *who = NULL, *chname = NULL, buf[511] = "", *msg = NULL;
-  struct chanset_t *chan = NULL;
-
   if (use_exempts == 0)
     return 0;
 
-  strncpy(buf, origmsg, 510);
-  buf[510] = 0;
+  char *chname = NULL, buf[511] = "", *msg = NULL;
+  struct chanset_t *chan = NULL;
+
+  strncpyz(buf, origmsg, sizeof(buf));
   msg = buf;
   newsplit(&msg);
   chname = newsplit(&msg);
   chan = findchan(chname);
   if (!chan || !(channel_pending(chan) || channel_active(chan)))
     return 0;
-  exempt = newsplit(&msg);
-  who = newsplit(&msg);
+  
+  char *exempt = newsplit(&msg), *who = newsplit(&msg);
+
   /* Extended timestamp format? */
   if (who[0])
     newexempt(chan, exempt, who);
@@ -1675,10 +1672,10 @@ static int got348(char *from, char *origmsg)
  */
 static int got349(char *from, char *msg)
 {
-  struct chanset_t *chan = NULL;
-  char *chname = NULL;
-
   if (use_exempts == 1) {
+    struct chanset_t *chan = NULL;
+    char *chname = NULL;
+
     newsplit(&msg);
     chname = newsplit(&msg);
     chan = findchan(chname);
@@ -1710,21 +1707,22 @@ static void got353(char *from, char *msg)
  */
 static int got346(char *from, char *origmsg)
 {
-  char *invite = NULL, *who = NULL, *chname = NULL, buf[511] = "", *msg = NULL;
+  if (use_invites == 0)
+    return 0;
+
+  char *chname = NULL, buf[511] = "", *msg = NULL;
   struct chanset_t *chan = NULL;
 
-  strncpy(buf, origmsg, 510);
-  buf[510] = 0;
+  strncpyz(buf, origmsg, sizeof(buf));
   msg = buf;
-  if (use_invites == 0)
-    return 0;
   newsplit(&msg);
   chname = newsplit(&msg);
   chan = findchan(chname);
   if (!chan || !(channel_pending(chan) || channel_active(chan)))
     return 0;
-  invite = newsplit(&msg);
-  who = newsplit(&msg);
+  
+  char *invite = newsplit(&msg), *who = newsplit(&msg);
+
   /* Extended timestamp format? */
   if (who[0])
     newinvite(chan, invite, who);
@@ -1738,10 +1736,10 @@ static int got346(char *from, char *origmsg)
  */
 static int got347(char *from, char *msg)
 {
-  struct chanset_t *chan = NULL;
-  char *chname = NULL;
-
   if (use_invites == 1) {
+    struct chanset_t *chan = NULL;
+    char *chname = NULL;
+
     newsplit(&msg);
     chname = newsplit(&msg);
     chan = findchan(chname);
@@ -1983,19 +1981,18 @@ static void set_topic(struct chanset_t *chan, char *k)
  */
 static int gottopic(char *from, char *msg)
 {
-  char *nick = NULL, *chname = NULL;
-  memberlist *m = NULL;
+  char *chname = newsplit(&msg), *nick = NULL;
   struct chanset_t *chan = NULL;
   struct userrec *u = NULL;
 
-  chname = newsplit(&msg);
   fixcolon(msg);
   u = get_user_by_host(from);
   nick = splitnick(&from);
   chan = findchan(chname);
   if (chan) {
+    memberlist *m = ismember(chan, nick);
+
     irc_log(chan, "%s!%s changed topic to: %s", nick, from, msg);
-    m = ismember(chan, nick);
     if (m != NULL)
       m->last = now;
     set_topic(chan, msg);
@@ -2319,21 +2316,18 @@ static int gotpart(char *from, char *msg)
  */
 static int gotkick(char *from, char *origmsg)
 {
-  char *nick = NULL, *whodid = NULL, *chname = NULL, s1[UHOSTLEN] = "", buf[UHOSTLEN] = "", *uhost = buf;
-  char buf2[511] = "", *msg = NULL;
-  memberlist *m = NULL;
+  char buf2[511], *msg = buf2, *chname = NULL;
   struct chanset_t *chan = NULL;
-  struct userrec *u = NULL;
-  struct flag_record fr = {FR_GLOBAL | FR_CHAN, 0, 0, 0 };
 
-  strncpy(buf2, origmsg, 510);
-  buf2[510] = 0;
+  strncpyz(buf2, origmsg, sizeof(buf2));
   msg = buf2;
   chname = newsplit(&msg);
   chan = findchan(chname);
   if (!chan)
     return 0;
-  nick = newsplit(&msg);
+
+  char *nick = newsplit(&msg);
+
   if (match_my_nick(nick) && channel_pending(chan) && shouldjoin(chan)) {
     chan->status &= ~(CHAN_ACTIVE | CHAN_PEND);
     dprintf(DP_MODE, "JOIN %s %s\n",
@@ -2343,6 +2337,11 @@ static int gotkick(char *from, char *origmsg)
     return 0; /* rejoin if kicked before getting needed info <Wcc[08/08/02]> */
   }
   if (channel_active(chan)) {
+    char *whodid = NULL, s1[UHOSTLEN] = "", buf[UHOSTLEN] = "", *uhost = buf;
+    memberlist *m = NULL;
+    struct userrec *u = NULL;
+    struct flag_record fr = {FR_GLOBAL | FR_CHAN, 0, 0, 0 };
+
     chan->channel.fighting++;
     fixcolon(msg);
     u = get_user_by_host(from);
@@ -2366,7 +2365,7 @@ static int gotkick(char *from, char *origmsg)
       return 0;
 
     if ((m = ismember(chan, nick))) {
-      struct userrec *u2;
+      struct userrec *u2 = NULL;
 
       simple_sprintf(s1, "%s!%s", m->nick, m->userhost);
       u2 = get_user_by_host(s1);
@@ -2397,7 +2396,7 @@ static int gotnick(char *from, char *msg)
 {
   char *nick = NULL, *chname = NULL, s1[UHOSTLEN] = "", buf[UHOSTLEN] = "", *uhost = buf;
   memberlist *m = NULL, *mm = NULL;
-  struct chanset_t *chan = NULL, *oldchan = NULL;
+  struct chanset_t *oldchan = NULL;
   struct userrec *u = NULL;
   struct flag_record fr = {FR_GLOBAL | FR_CHAN, 0, 0, 0 };
 
@@ -2406,7 +2405,7 @@ static int gotnick(char *from, char *msg)
   fixcolon(msg);
   irc_log(NULL, "[%s] Nick change: %s -> %s", samechans(nick, ","), nick, msg);
   clear_chanlist_member(nick);	/* Cache for nick 'nick' is meaningless now. */
-  for (chan = chanset; chan; chan = chan->next) {
+  for (struct chanset_t *chan = chanset; chan; chan = chan->next) {
     oldchan = chan;
     chname = chan->dname; 
     m = ismember(chan, nick);
@@ -2461,15 +2460,13 @@ static int gotnick(char *from, char *msg)
 
 void check_should_cycle(struct chanset_t *chan)
 {
-  /*
-     If there are other ops split off and i'm the only op on this side of split, cycle
-   */
-  memberlist *ml = NULL;
-  int localops = 0, localbotops = 0, splitops = 0, splitbotops = 0, localnonops = 0;
-
   if (!me_op(chan))
     return;
-  for (ml = chan->channel.member; ml && ml->nick[0]; ml = ml->next) {
+
+  //If there are other ops split off and i'm the only op on this side of split, cycle
+  int localops = 0, localbotops = 0, splitops = 0, splitbotops = 0, localnonops = 0;
+
+  for (memberlist *ml = chan->channel.member; ml && ml->nick[0]; ml = ml->next) {
     if (chan_hasop(ml)) {
       if (chan_issplit(ml)) {
         splitops++;
@@ -2510,7 +2507,7 @@ static int gotquit(char *from, char *msg)
   int split = 0;
   char from2[NICKMAX + UHOSTMAX + 1] = "";
   memberlist *m = NULL;
-  struct chanset_t *chan = NULL, *oldchan = NULL;
+  struct chanset_t *oldchan = NULL;
   struct userrec *u = NULL;
 
   strcpy(from2,from);
@@ -2523,7 +2520,7 @@ static int gotquit(char *from, char *msg)
    */
   p = strchr(msg, ' ');
   if (p && (p == strrchr(msg, ' '))) {
-    char *z1, *z2;
+    char *z1 = NULL, *z2 = NULL;
 
     *p = 0;
     z1 = strchr(p + 1, '.');
@@ -2542,7 +2539,7 @@ static int gotquit(char *from, char *msg)
   else
     irc_log(NULL, "[%s] Quits %s (%s)", samechans(nick, ","), nick, from);
 
-  for (chan = chanset; chan; chan = chan->next) {
+  for (struct chanset_t *chan = chanset; chan; chan = chan->next) {
     oldchan = chan;
     chname = chan->dname;
     m = ismember(chan, nick);
@@ -2587,23 +2584,22 @@ static int gotquit(char *from, char *msg)
  */
 static int gotmsg(char *from, char *msg)
 {
-  char *to = NULL, *realto = NULL, buf[UHOSTLEN] = "", *nick = NULL, buf2[512] = "", *uhost = buf;
-  char *p = NULL, *p1 = NULL, *code = NULL, *ctcp = NULL;
-  int ctcp_count = 0;
-  struct chanset_t *chan = NULL;
-  int ignoring;
-  struct userrec *u = NULL;
-  memberlist *m = NULL;
-  struct flag_record fr = {FR_GLOBAL | FR_CHAN, 0, 0, 0 };
-
   if (!strchr("&#!+@$", msg[0]))
     return 0;
-  ignoring = match_ignore(from);
-  to = newsplit(&msg);
-  realto = (to[0] == '@') ? to + 1 : to;
-  chan = findchan(realto);
+
+  bool ignoring = match_ignore(from);
+  char *to = newsplit(&msg), *realto = (to[0] == '@') ? to + 1 : to;
+  struct chanset_t *chan = findchan(realto);
+
   if (!chan)
     return 0;			/* Private msg to an unknown channel?? */
+
+
+  char buf[UHOSTLEN] = "", *nick = NULL, buf2[512] = "", *uhost = buf, *p = NULL, *p1 = NULL, *code = NULL, *ctcp = NULL;
+  int ctcp_count = 0;
+  struct userrec *u = NULL;
+  struct flag_record fr = {FR_GLOBAL | FR_CHAN, 0, 0, 0 };
+
   fixcolon(msg);
   strcpy(uhost, from);
   nick = splitnick(&uhost);
@@ -2611,9 +2607,10 @@ static int gotmsg(char *from, char *msg)
   /* Only check if flood-ctcp is active */
   detect_autokick(nick, uhost, chan, msg);
   if (flud_ctcp_thr && detect_avalanche(msg)) {
+    memberlist *m = ismember(chan, nick);
+
     u = get_user_by_host(from);
     get_user_flagrec(u, &fr, chan->dname);
-    m = ismember(chan, nick);
     /* Discard -- kick user if it was to the channel */
     if (m && me_op(chan) && 
 	!chan_sentkick(m) &&
@@ -2712,6 +2709,7 @@ static int gotmsg(char *from, char *msg)
   if (msg[0]) {
     int botmatch = 0, i = 0;
     char *my_msg = NULL, *my_ptr = NULL, *fword = NULL;
+
     /* Check even if we're ignoring the host. (modified by Eule 17.7.99) */
     detect_chan_flood(nick, uhost, from, chan, FLOOD_PRIVMSG, NULL);
     
@@ -2747,29 +2745,33 @@ static int gotmsg(char *from, char *msg)
  */
 static int gotnotice(char *from, char *msg)
 {
-  char *to = NULL, *realto = NULL, *nick = NULL, buf2[512] = "", *p = NULL, *p1 = NULL, buf[512] = "", *uhost = buf;
-  char *ctcp = NULL, *code = NULL;
-  struct userrec *u = NULL;
-  memberlist *m = NULL;
-  struct chanset_t *chan = NULL;
-  struct flag_record fr = {FR_GLOBAL | FR_CHAN, 0, 0, 0 };
-  int ignoring;
-
   if (!strchr(CHANMETA "@", *msg))
     return 0;
+  
+  bool ignoring = match_ignore(from);
+  char *to = newsplit(&msg), *realto = (*to == '@') ? to + 1 : to;
+  struct chanset_t *chan = findchan(realto); 
+
   ignoring = match_ignore(from);
   to = newsplit(&msg);
   realto = (*to == '@') ? to + 1 : to;
   chan = findchan(realto);
   if (!chan)
     return 0;			/* Notice to an unknown channel?? */
+
+  char *nick = NULL, buf2[512] = "", *p = NULL, *p1 = NULL, buf[512] = "", *uhost = buf;
+  char *ctcp = NULL, *code = NULL;
+  struct userrec *u = NULL;
+  struct flag_record fr = {FR_GLOBAL | FR_CHAN, 0, 0, 0 };
+
   fixcolon(msg);
   strcpy(uhost, from);
   nick = splitnick(&uhost);
   u = get_user_by_host(from);
   if (flud_ctcp_thr && detect_avalanche(msg)) {
+    memberlist *m = ismember(chan, nick);
+
     get_user_flagrec(u, &fr, chan->dname);
-    m = ismember(chan, nick);
     /* Discard -- kick user if it was to the channel */
     if (me_op(chan) && m && !chan_sentkick(m) &&
 	!(use_exempts && ban_fun &&

+ 116 - 109
src/mod/irc.mod/cmdsirc.c

@@ -51,9 +51,8 @@ static char *getnick(char *handle, struct chanset_t *chan)
 {
   char s[UHOSTLEN] = "";
   struct userrec *u = NULL;
-  register memberlist *m = NULL;
 
-  for (m = chan->channel.member; m && m->nick[0]; m = m->next) {
+  for (register memberlist *m = chan->channel.member; m && m->nick[0]; m = m->next) {
     egg_snprintf(s, sizeof s, "%s!%s", m->nick, m->userhost);
     if ((u = get_user_by_host(s)) && !egg_strcasecmp(u->handle, handle))
       return m->nick;
@@ -63,14 +62,14 @@ static char *getnick(char *handle, struct chanset_t *chan)
 
 static void cmd_act(int idx, char *par)
 {
-  char *chname = NULL;
-  struct chanset_t *chan = NULL;
-  memberlist *m = NULL;
-
   if (!par[0]) {
     dprintf(idx, "Usage: act [channel] <action>\n");
     return;
   }
+
+  char *chname = NULL;
+  struct chanset_t *chan = NULL;
+
   if (strchr(CHANMETA, par[0]) != NULL)
     chname = newsplit(&par);
   else
@@ -79,13 +78,15 @@ static void cmd_act(int idx, char *par)
   if (!chan || !has_op(idx, chan))
     return;
 
-  get_user_flagrec(dcc[idx].user, &user, chan->dname);
+  memberlist *m = ismember(chan, botname);
 
-  m = ismember(chan, botname);
   if (!m) {
     dprintf(idx, "Cannot say to %s: I'm not on that channel.\n", chan->dname);
     return;
   }
+
+  get_user_flagrec(dcc[idx].user, &user, chan->dname);
+
   if ((chan->channel.mode & CHANMODER) && !me_op(chan) && !me_voice(chan)) {
     dprintf(idx, "Cannot say to %s: It is moderated.\n", chan->dname);
     return;
@@ -99,28 +100,28 @@ static void cmd_act(int idx, char *par)
 
 static void cmd_msg(int idx, char *par)
 {
-  char *nick = NULL;
-
-  nick = newsplit(&par);
-  if (!par[0]) 
+  if (!par[0]) {
     dprintf(idx, "Usage: msg <nick> <message>\n");
-  else {
-    putlog(LOG_CMDS, "*", "#%s# msg %s %s", dcc[idx].nick, nick, par);
-    dprintf(DP_HELP, "PRIVMSG %s :%s\n", nick, par);
-    dprintf(idx, "Msg to %s: %s\n", nick, par);
+    return;
   }
+
+  char *nick = newsplit(&par);
+
+  putlog(LOG_CMDS, "*", "#%s# msg %s %s", dcc[idx].nick, nick, par);
+  dprintf(DP_HELP, "PRIVMSG %s :%s\n", nick, par);
+  dprintf(idx, "Msg to %s: %s\n", nick, par);
 }
 
 static void cmd_say(int idx, char *par)
 {
-  char *chname = NULL;
-  struct chanset_t *chan = NULL;
-  memberlist *m = NULL;
-
   if (!par[0]) {
     dprintf(idx, "Usage: say [channel] <message>\n");
     return;
   }
+
+  char *chname = NULL;
+  struct chanset_t *chan = NULL;
+
   if (strchr(CHANMETA, par[0]) != NULL)
     chname = newsplit(&par);
   else
@@ -129,13 +130,15 @@ static void cmd_say(int idx, char *par)
   if (!chan || !has_op(idx, chan))
     return;
 
-  get_user_flagrec(dcc[idx].user, &user, chan->dname);
+  memberlist *m = ismember(chan, botname);
 
-  m = ismember(chan, botname);
   if (!m) {
     dprintf(idx, "Cannot say to %s: I'm not on that channel.\n", chan->dname);
     return;
   }
+
+  get_user_flagrec(dcc[idx].user, &user, chan->dname);
+
   if ((chan->channel.mode & CHANMODER) && !me_op(chan) && !me_voice(chan)) {
     dprintf(idx, "Cannot say to %s: It is moderated.\n", chan->dname);
     return;
@@ -147,19 +150,19 @@ static void cmd_say(int idx, char *par)
 
 static void cmd_swhois(int idx, char *par)
 {
-  char *server = NULL, *nick = NULL;
-
   if (!par[0]) {
     dprintf(idx, "Usage: swhois [server/nick] nick\n");
     return;
   }
 
+
   putlog(LOG_CMDS, "*", "#%s# swhois %s", dcc[idx].nick, par);
   if (!server_online) {
     dprintf(idx, "I am currently not connected!\n");
     return;
   }
-  server = newsplit(&par);
+  char *server = newsplit(&par), *nick = NULL;
+
   if (par[0])
     nick = newsplit(&par);
 
@@ -169,16 +172,15 @@ static void cmd_swhois(int idx, char *par)
 
 static void cmd_kickban(int idx, char *par)
 {
-  struct chanset_t *chan = NULL;
-  char *chname = NULL, *nick = NULL, *s1 = NULL, s[UHOSTLEN] = "", bantype = 0;
-  int all = 0;
-  memberlist *m = NULL;
-
   if (!par[0]) {
     dprintf(idx, "Usage: kickban [channel|*] [-|@]<nick> [reason]\n");
     return;
   }
 
+  struct chanset_t *chan = NULL;
+  char *chname = NULL;
+  bool all = 0;
+
   if (par[0] == '*' && par[1] == ' ') {
     all = 1;
     newsplit(&par);
@@ -192,9 +194,11 @@ static void cmd_kickban(int idx, char *par)
       return;
   }
 
+
   putlog(LOG_CMDS, "*", "#%s# (%s) kickban %s", dcc[idx].nick, all ? "*" : chan->dname, par);
 
-  nick = newsplit(&par);
+  char *nick = newsplit(&par), bantype = 0;
+
   if ((nick[0] == '@') || (nick[0] == '-')) {
     bantype = nick[0];
     nick++;
@@ -204,10 +208,13 @@ static void cmd_kickban(int idx, char *par)
     return;
   }
 
+  memberlist *m = NULL;
+  char *s1 = NULL, s[UHOSTLEN] = "";
+  struct userrec *u = NULL;
+
   if (all)
     chan = chanset;
   while (chan) {
-    struct userrec *u = NULL;
 
     get_user_flagrec(dcc[idx].user, &user, chan->dname);
 
@@ -298,12 +305,10 @@ static void cmd_kickban(int idx, char *par)
 
 static void cmd_voice(int idx, char *par)
 {
+  char *nick = newsplit(&par);
   struct chanset_t *chan = NULL;
-  char *nick = NULL, s[UHOSTLEN] = "";
-  int all = 0;
-  memberlist *m = NULL;
+  bool all = 0;
 
-  nick = newsplit(&par);
   if (par[0] == '*' && !par[1]) {
     all = 1;
     newsplit(&par);
@@ -312,6 +317,10 @@ static void cmd_voice(int idx, char *par)
     if (!chan || !has_op(idx, chan))
       return;
   }
+
+  char s[UHOSTLEN] = "";
+  memberlist *m = NULL;
+
   if (all)
     chan = chanset;
   putlog(LOG_CMDS, "*", "#%s# (%s) voice %s", dcc[idx].nick, all ? "*" : chan->dname , nick);
@@ -367,11 +376,9 @@ static void cmd_voice(int idx, char *par)
 static void cmd_devoice(int idx, char *par)
 {
   struct chanset_t *chan = NULL;
-  char *nick = NULL, s[UHOSTLEN] = "";
-  int all = 0;
-  memberlist *m = NULL;
+  char *nick = newsplit(&par);
+  bool all = 0;
 
-  nick = newsplit(&par);
   if (par[0] == '*' && !par[1]) {
     all = 1;
     newsplit(&par);
@@ -380,6 +387,10 @@ static void cmd_devoice(int idx, char *par)
     if (!chan || !has_op(idx, chan))
       return;
   }
+
+  char s[UHOSTLEN] = "";
+  memberlist *m = NULL;
+
   if (all)
     chan = chanset;
   putlog(LOG_CMDS, "*", "#%s# (%s) devoice %s", dcc[idx].nick, all ? "*" : chan->dname, nick);
@@ -434,11 +445,9 @@ static void cmd_devoice(int idx, char *par)
 static void cmd_op(int idx, char *par)
 {
   struct chanset_t *chan = NULL;
-  char *nick = NULL, s[UHOSTLEN] = "";
-  int all = 0;
-  memberlist *m = NULL;
+  char *nick = newsplit(&par);
+  bool all = 0;
 
-  nick = newsplit(&par);
   if (par[0] == '*' && !par[1]) {
     all = 1;
     newsplit(&par);
@@ -447,13 +456,16 @@ static void cmd_op(int idx, char *par)
     if (!chan || !has_op(idx, chan))
       return;
   }
+
+  char s[UHOSTLEN] = "";
+  memberlist *m = NULL;
+  struct userrec *u = NULL;
+
   if (all)
     chan = chanset;
   putlog(LOG_CMDS, "*", "#%s# (%s) op %s", dcc[idx].nick, all ? "*" : chan->dname, nick);
 
   while (chan) {
-    struct userrec *u = NULL;
-
   get_user_flagrec(dcc[idx].user, &user, chan->dname);
   if (!nick[0] && !(nick = getnick(dcc[idx].nick, chan))) {
     if (all) goto next;
@@ -781,11 +793,9 @@ void mdop_request(char *botnick, char *code, char *par)
 static void cmd_deop(int idx, char *par)
 {
   struct chanset_t *chan = NULL;
-  char *nick = NULL, s[UHOSTLEN] = "";
-  int all = 0;
-  memberlist *m = NULL;
+  char *nick = newsplit(&par);
+  bool all = 0;
 
-  nick = newsplit(&par);
   if (par[0] == '*' && !par[1]) {
     all = 1;
     newsplit(&par);
@@ -793,15 +803,17 @@ static void cmd_deop(int idx, char *par)
     chan = get_channel(idx, par);
     if (!chan || !has_op(idx, chan))
       return;
-
   }
+
+  char s[UHOSTLEN] = "";
+  memberlist *m = NULL;
+  struct userrec *u = NULL;
+
   if (all)
     chan = chanset;
   putlog(LOG_CMDS, "*", "#%s# (%s) deop %s", dcc[idx].nick, all ? "*" : chan->dname, nick);
 
   while (chan) {
-    struct userrec *u = NULL;
-
     get_user_flagrec(dcc[idx].user, &user, chan->dname);
     if (!nick[0] && !(nick = getnick(dcc[idx].nick, chan))) {
       if (all) goto next;  
@@ -867,16 +879,15 @@ static void cmd_deop(int idx, char *par)
 
 static void cmd_kick(int idx, char *par)
 {
-  struct chanset_t *chan = NULL;
-  char *chname = NULL, *nick = NULL, s[UHOSTLEN] = "";
-  int all = 0;
-  memberlist *m = NULL;
-
   if (!par[0]) {
     dprintf(idx, "Usage: kick [channel|*] <nick> [reason]\n");
     return;
   }
 
+  struct chanset_t *chan = NULL;
+  char *chname = NULL;
+  bool all = 0;
+
   if (par[0] == '*' && par[1] == ' ') {
     all = 1;
     newsplit(&par);
@@ -892,18 +903,22 @@ static void cmd_kick(int idx, char *par)
 
   putlog(LOG_CMDS, "*", "#%s# (%s) kick %s", dcc[idx].nick, all ? "*" : chan->dname, par);
 
-  nick = newsplit(&par);
+  char *nick = newsplit(&par);
+
   if (!par[0])
     par = "request";
   if (match_my_nick(nick)) {
     dprintf(idx, "I'm not going to kick myself.\n");
     return;
   }
+
+  char s[UHOSTLEN] = "";
+  memberlist *m = NULL;
+  struct userrec *u = NULL;
+
   if (all)
     chan = chanset;
   while (chan) {
-    struct userrec *u = NULL;
-
     get_user_flagrec(dcc[idx].user, &user, chan->dname);
 
     if (privchan(user, chan, PRIV_OP)) {
@@ -1002,7 +1017,7 @@ static void cmd_getkey(int idx, char *par)
 static void cmd_mop(int idx, char *par)
 {
   struct chanset_t *chan = NULL;
-  int found = 0, all = 0;
+  bool found = 0, all = 0;
 
   if (par[0] == '*' && !par[1]) {
     get_user_flagrec(dcc[idx].user, &user, NULL);
@@ -1015,8 +1030,7 @@ static void cmd_mop(int idx, char *par)
     newsplit(&par);
   } else {
     if (par[0] && (strchr(CHANMETA, par[0]) != NULL)) {
-      char *chname = newsplit(&par);
-      chan = get_channel(idx, chname);
+      chan = get_channel(idx, newsplit(&par));
     } else
       chan = get_channel(idx, "");
   }
@@ -1025,9 +1039,11 @@ static void cmd_mop(int idx, char *par)
     return;
 
   putlog(LOG_CMDS, "*", "#%s# (%s) mop %s", dcc[idx].nick, all ? "*" : chan->dname, par);
-  while (chan) {
-    memberlist *m = NULL;
 
+  memberlist *m = NULL;
+  char s[256] = "";
+
+  while (chan) {
     get_user_flagrec(dcc[idx].user, &user, chan->dname);
     if (privchan(user, chan, PRIV_OP)) {
       if (all) goto next;
@@ -1047,8 +1063,6 @@ static void cmd_mop(int idx, char *par)
     if (channel_active(chan) && !channel_pending(chan)) {
       for (m = chan->channel.member; m && m->nick[0]; m = m->next) {
         if (!m->user) {
-          char s[256] = "";
-
           sprintf(s, "%s!%s", m->nick, m->userhost);
           m->user = get_user_by_host(s);
         }
@@ -1079,18 +1093,19 @@ static void cmd_mop(int idx, char *par)
 
 static void cmd_find(int idx, char *par)
 {
-  struct chanset_t *chan = NULL, **cfound = NULL;
-  memberlist *m = NULL, **found = NULL;
-  struct userrec *u2 = NULL;
-  int fcount = 0, tr = 0;
-
-  putlog(LOG_CMDS, "*", "#%s# find %s", dcc[idx].nick, par);
-
   if (!par[0]) {
     dprintf(idx, "Usage: find <nick!ident@host.com> (wildcard * allowed)\n");
     return;
   }
 
+  putlog(LOG_CMDS, "*", "#%s# find %s", dcc[idx].nick, par);
+
+  struct chanset_t *chan = NULL, **cfound = NULL;
+  memberlist *m = NULL, **found = NULL;
+  struct userrec *u2 = NULL;
+  int fcount = 0;
+  bool tr = 0;
+
   /* make a list of members in found[] */
   for (chan = chanset; chan; chan = chan->next) {
 
@@ -1159,7 +1174,7 @@ static void cmd_invite(int idx, char *par)
 {
   struct chanset_t *chan = NULL;
   memberlist *m = NULL;
-  int all = 0;
+  bool all = 0;
   char *nick = NULL;
 
   if (!par[0])
@@ -1220,12 +1235,10 @@ static void cmd_invite(int idx, char *par)
 
 static void cmd_authed(int idx, char *par)
 {
-  int i = 0;
-  
   putlog(LOG_CMDS, "*", "#%s# authed", dcc[idx].nick);
 
   dprintf(idx, "Authed:\n");
-  for (i = 0; i < auth_total; i++) {
+  for (int i = 0; i < auth_total; i++) {
    if (auth[i].authed)
      dprintf(idx, " %d. %s!%s at %li\n", i, auth[i].nick, auth[i].host, auth[i].authtime);
   }
@@ -1233,16 +1246,17 @@ static void cmd_authed(int idx, char *par)
 
 static void cmd_channel(int idx, char *par)
 {
-  char handle[HANDLEN + 1] = "", s[UHOSTLEN] = "", s1[UHOSTLEN] = "", atrflag = 0, chanflag[2] = "";
   struct chanset_t *chan = NULL;
-  memberlist *m = NULL;
-  unsigned int maxnicklen, maxhandlen;
-  char format[81] = "";
 
   chan = get_channel(idx, par);
   if (!chan || !has_op(idx, chan))
     return;
 
+  char handle[HANDLEN + 1] = "", s[UHOSTLEN] = "", s1[UHOSTLEN] = "", atrflag = 0, chanflag[2] = "";
+  memberlist *m = NULL;
+  size_t maxnicklen, maxhandlen;
+  char format[81] = "";
+
   get_user_flagrec(dcc[idx].user, &user, chan->dname);
 
   putlog(LOG_CMDS, "*", "#%s# (%s) channel", dcc[idx].nick, chan->dname);
@@ -1276,7 +1290,6 @@ static void cmd_channel(int idx, char *par)
 			maxnicklen, maxhandlen);
     dprintf(idx, format, "NICKNAME", "HANDLE", " JOIN", "  HOPS", "IDLE", "USER@HOST");
     for (m = chan->channel.member; m && m->nick[0]; m = m->next) {
-      int hops = m->hops;
       if (m->joined > 0) {
 	if ((now - (m->joined)) > 86400)
 	  egg_strftime(s, 6, "%d%b", gmtime(&(m->joined)));
@@ -1356,7 +1369,7 @@ static void cmd_channel(int idx, char *par)
         egg_snprintf(format, sizeof format, 
 			"%%c%%c%%-%us %%-%us   %%d %%s %%c     <- netsplit, %%lus\n", 
 			maxnicklen, maxhandlen);
-	dprintf(idx, format, chanflag[0],chanflag[1], m->nick, handle, s, hops, atrflag,
+	dprintf(idx, format, chanflag[0],chanflag[1], m->nick, handle, s, m->hops, atrflag,
 		now - (m->split));
       } else if (!rfc_casecmp(m->nick, botname)) {
         egg_snprintf(format, sizeof format, 
@@ -1375,7 +1388,7 @@ static void cmd_channel(int idx, char *par)
 	  strncpyz(s1, "   ", sizeof s1);
 	egg_snprintf(format, sizeof format, "%%c%%c%%-%us %%-%us %%s %%c   %%d %%s  %%s\n", 
 			maxnicklen, maxhandlen);
-	dprintf(idx, format, chanflag[0], chanflag[1], m->nick,	handle, s, atrflag, hops,
+	dprintf(idx, format, chanflag[0], chanflag[1], m->nick,	handle, s, atrflag, m->hops,
                      s1, m->userhost);
       }
       if (chan_fakeop(m))
@@ -1396,8 +1409,7 @@ static void cmd_topic(int idx, char *par)
   struct chanset_t *chan = NULL;
 
   if (par[0] && (strchr(CHANMETA, par[0]) != NULL)) {
-    char *chname = newsplit(&par);
-    chan = get_channel(idx, chname);
+    chan = get_channel(idx, newsplit(&par));
   } else
     chan = get_channel(idx, "");
 
@@ -1430,10 +1442,8 @@ static void cmd_topic(int idx, char *par)
 
 static void cmd_resetbans(int idx, char *par)
 {
-  struct chanset_t *chan = NULL;
-  char *chname = newsplit(&par);
+  struct chanset_t *chan = get_channel(idx, newsplit(&par));
 
-  chan = get_channel(idx, chname);
   if (!chan || !has_op(idx, chan))
     return;
 
@@ -1446,10 +1456,8 @@ static void cmd_resetbans(int idx, char *par)
 
 static void cmd_resetexempts(int idx, char *par)
 {
-  struct chanset_t *chan = NULL;
-  char *chname = newsplit(&par);
+  struct chanset_t *chan = get_channel(idx, newsplit(&par));
 
-  chan = get_channel(idx, chname);
   if (!chan || !has_op(idx, chan))
     return;
 
@@ -1462,10 +1470,8 @@ static void cmd_resetexempts(int idx, char *par)
 
 static void cmd_resetinvites(int idx, char *par)
 {
-  struct chanset_t *chan = NULL;
-  char *chname = newsplit(&par);
+  struct chanset_t *chan = get_channel(idx, newsplit(&par));
 
-  chan = get_channel(idx, chname);
   if (!chan || !has_op(idx, chan))
     return;
   get_user_flagrec(dcc[idx].user, &user, chan->dname);
@@ -1477,21 +1483,22 @@ static void cmd_resetinvites(int idx, char *par)
 
 static void cmd_adduser(int idx, char *par)
 {
+  if ((!par[0]) || ((par[0] =='!') && (!par[1]))) {
+    dprintf(idx, "Usage: adduser <nick> [handle]\n");
+    return;
+  }
+
   char *nick = NULL, *hand = NULL;
   struct chanset_t *chan = NULL;
   struct userrec *u = NULL;
   memberlist *m = NULL;
   char s[UHOSTLEN] = "", s1[UHOSTLEN] = "", s2[MAXPASSLEN + 1] = "", s3[MAXPASSLEN + 1] = "", tmp[50] = "";
   int atr = dcc[idx].user ? dcc[idx].user->flags : 0;
-  int statichost = 0;
+  bool statichost = 0;
   char *p1 = s1;
 
   putlog(LOG_CMDS, "*", "#%s# adduser %s", dcc[idx].nick, par);
 
-  if ((!par[0]) || ((par[0] =='!') && (!par[1]))) {
-    dprintf(idx, "Usage: adduser <nick> [handle]\n");
-    return;
-  }
   nick = newsplit(&par);
 
   /* This flag allows users to have static host (added by drummer, 20Apr99) */
@@ -1502,10 +1509,9 @@ static void cmd_adduser(int idx, char *par)
   if (!par[0]) {
     hand = nick;
   } else {
-    char *p;
-    int ok = 1;
+    bool ok = 1;
 
-    for (p = par; *p; p++)
+    for (char *p = par; *p; p++)
       if ((*p <= 32) || (*p >= 127))
 	ok = 0;
     if (!ok) {
@@ -1581,15 +1587,16 @@ static void cmd_adduser(int idx, char *par)
 
 static void cmd_deluser(int idx, char *par)
 {
+  if (!par[0]) {
+    dprintf(idx, "Usage: deluser <nick>\n");
+    return;
+  }
+
   char *nick = NULL, s[UHOSTLEN] = "";
   struct chanset_t *chan = NULL;
   memberlist *m = NULL;
   struct userrec *u = NULL;
 
-  if (!par[0]) {
-    dprintf(idx, "Usage: deluser <nick>\n");
-    return;
-  }
   nick = newsplit(&par);
 
   for (chan = chanset; chan; chan = chan->next) {

+ 124 - 146
src/mod/irc.mod/irc.c

@@ -36,28 +36,26 @@
 #define PRIO_DEOP 1
 #define PRIO_KICK 2
 
-int host_synced = 0;
-
 static int net_type = 0;
-static int wait_split = 300;    /* Time to wait for user to return from
+static time_t wait_split = 300;    /* Time to wait for user to return from
                                  * net-split. */
 int max_bans;                   /* Modified by net-type 1-4 */
 int max_exempts;
 int max_invites;
 int max_modes;                  /* Modified by net-type 1-4 */
-static int bounce_bans = 0;
-static int bounce_exempts = 0;
-static int bounce_invites = 0;
-static int bounce_modes = 0;
+static bool bounce_bans = 0;
+static bool bounce_exempts = 0;
+static bool bounce_invites = 0;
+static bool bounce_modes = 0;
 unsigned int modesperline;      /* Number of modes per line to send. */
-static int mode_buf_len = 200;  /* Maximum bytes to send in 1 mode. */
-int use_354 = 0;                /* Use ircu's short 354 /who
+static size_t mode_buf_len = 200;  /* Maximum bytes to send in 1 mode. */
+bool use_354 = 0;                /* Use ircu's short 354 /who
                                  * responses. */
-static int kick_fun = 0;
-static int ban_fun = 1;
-static int keepnick = 1;        /* Keep nick */
-static int prevent_mixing = 1;  /* To prevent mixing old/new modes */
-static int include_lk = 1;      /* For correct calculation
+static bool kick_fun = 0;
+static bool ban_fun = 1;
+static bool keepnick = 1;        /* Keep nick */
+static bool prevent_mixing = 1;  /* To prevent mixing old/new modes */
+static bool include_lk = 1;      /* For correct calculation
                                  * in real_add_mode. */
 
 #include "chan.c"
@@ -68,15 +66,14 @@ static int include_lk = 1;      /* For correct calculation
 static void
 detect_autokick(char *nick, char *uhost, struct chanset_t *chan, char *msg)
 {
-  struct flag_record fr = { FR_GLOBAL | FR_CHAN, 0, 0, 0 };
-  struct userrec *u = NULL;
-  int i = 0, tot = 0;
-
   if (!nick || !nick[0] || !uhost || !uhost[0] || !chan || !msg || !msg[0])
     return;
 
-  tot = strlen(msg);
-  u = get_user_by_host(uhost);
+  struct flag_record fr = { FR_GLOBAL | FR_CHAN, 0, 0, 0 };
+  struct userrec *u = get_user_by_host(uhost);
+  int i = 0;
+  //size_t tot = strlen(msg);
+
   get_user_flagrec(u, &fr, chan->dname);
 
   for (; *msg; ++msg) {
@@ -164,32 +161,14 @@ checkcookie(char *chn, char *bnick, char *cookie)
 void
 getin_request(char *botnick, char *code, char *par)
 {
-
-  char *tmp = NULL,
-    *chname = NULL,
-    *nck = NULL, *hst = NULL, *ip4 = NULL, *ip6 = NULL, *what = NULL, *p = NULL, *p2 = NULL, *p3 = NULL;
-  struct chanset_t *chan = NULL;
-  memberlist *mem = NULL;
-  struct userrec *u = NULL;
-  char nick[NICKLEN] = "";
-  char host[UHOSTLEN] = "";
-  char ip4host[UHOSTLEN] = "";
-  char ip6host[UHOSTLEN] = "";
-  char s[256] = "", s2[16] = "";
-  int lim, curlim, sendi = 0;
-  struct maskrec **mr = NULL, *tmr = NULL;
-  struct maskstruct *b = NULL;
-  struct flag_record fr = { FR_GLOBAL | FR_CHAN, 0, 0, 0 };
-
   if (!server_online)
     return;
 
   if (!par[0] || !par)
     return;
 
-  what = newsplit(&par);
-
-  chname = newsplit(&par);
+  struct chanset_t *chan = NULL;
+  char *what = newsplit(&par), *chname = newsplit(&par);
 
   if (!chname[0] || !chname)
     return;
@@ -199,11 +178,16 @@ getin_request(char *botnick, char *code, char *par)
     return;
   }
 
-  nck = newsplit(&par);
+  char *nck = newsplit(&par);
+
   if (!nck[0])
     return;
 
-  hst = newsplit(&par);
+  struct userrec *u = NULL;
+  memberlist *mem = NULL;
+  char *hst = newsplit(&par), *ip4 = NULL, *ip6 = NULL, *tmp = NULL;
+  char nick[NICKLEN] = "", host[UHOSTLEN] = "", ip4host[UHOSTLEN] = "", ip6host[UHOSTLEN] = "";
+  struct flag_record fr = { FR_GLOBAL | FR_CHAN, 0, 0, 0 };
 
   if (nck[0]) {
     strncpyz(nick, nck, sizeof(nick));
@@ -311,10 +295,6 @@ getin_request(char *botnick, char *code, char *par)
 
     putlog(LOG_GETIN, "*", "opreq from %s/%s on %s - Opped", botnick, nick, chan->dname);
   } else if (what[0] == 'i') {
-    strcpy(s, getchanmode(chan));
-    p = (char *) &s;
-    p2 = newsplit(&p);
-    p3 = newsplit(&p);
     if (!nick[0]) {
       putlog(LOG_GETIN, "*", "inreq from %s/??? for %s - No nick specified - SHOULD NOT HAPPEN", botnick,
              chname);
@@ -350,16 +330,28 @@ getin_request(char *botnick, char *code, char *par)
              chan->dname);
       return;
     }
+
+    char s[256] = "", *p = NULL, *p2 = NULL, *p3 = NULL;
+    bool sendi = 0;
+
+    strcpy(s, getchanmode(chan));
+    p = (char *) &s;
+    p2 = newsplit(&p);
+    p3 = newsplit(&p);
+
     if (strchr(p2, 'l')) {
       if (!me_op(chan))
         putlog(LOG_GETIN, "*", "inreq from %s/%s for %s - I haven't got ops", botnick, nick, chan->dname);
       else {
-        lim = chan->channel.members + 5;
+        int lim = chan->channel.members + 5, curlim;
+
         if (!*p)
           curlim = atoi(p3);
         else
           curlim = atoi(p);
         if (curlim > 0 && curlim < lim) {
+          char s2[16] = "";
+
           sendi = 1;
           simple_sprintf(s2, "%d", lim);
           add_mode(chan, '+', 'l', s2);
@@ -368,6 +360,9 @@ getin_request(char *botnick, char *code, char *par)
         }
       }
     }
+
+    struct maskrec **mr = NULL, *tmr = NULL;
+
     mr = &global_bans;
     while (*mr) {
       if (wild_match((*mr)->mask, host) || wild_match((*mr)->mask, ip4host) ||
@@ -411,7 +406,7 @@ getin_request(char *botnick, char *code, char *par)
         mr = &((*mr)->next);
       }
     }
-    for (b = chan->channel.ban; b->mask[0]; b = b->next) {
+    for (struct maskstruct *b = chan->channel.ban; b->mask[0]; b = b->next) {
       if (wild_match(b->mask, host) || wild_match(b->mask, ip4host) || wild_match(b->mask, ip6host)) {
         add_mode(chan, '-', 'b', b->mask);
         putlog(LOG_GETIN, "*", "inreq from %s/%s for %s - Removed active ban %s", botnick, nick, chan->dname,
@@ -458,23 +453,20 @@ getin_request(char *botnick, char *code, char *par)
 void
 check_hostmask()
 {
-  char s[UHOSTLEN + 2] = "", *tmp = NULL;
-  struct list_type *q = NULL;
-
   if (!server_online || !botuserhost[0])
     return;
 
-  checked_hostmask = 1;
+  char s[UHOSTLEN + 2] = "", *tmp = botuserhost;
 
-  tmp = botuserhost;
+  checked_hostmask = 1;
 
-  if (tmp[0] == '~') {
+  if (tmp[0] == '~' && !strict_host) {
     tmp++;
-    sprintf(s, "*!*%s", tmp);
+    sprintf(s, "*!?%s", tmp);
   } else
     sprintf(s, "*!%s", tmp);
 
-  for (q = (struct list_type *) get_user(&USERENTRY_HOSTS, conf.bot->u); q; q = q->next) {
+  for (struct list_type *q = (struct list_type *) get_user(&USERENTRY_HOSTS, conf.bot->u); q; q = q->next) {
     if (!egg_strcasecmp(q->extra, s))
       return;
   }
@@ -486,12 +478,6 @@ check_hostmask()
 static void
 request_op(struct chanset_t *chan)
 {
-  int i = 0, my_exp = 0, first = 100, n, cnt, i2;
-  memberlist *ml = NULL;
-  memberlist *botops[MAX_BOTS];
-  char s[100] = "", *l = NULL, myserv[SERVLEN] = "";
-  struct flag_record fr = { FR_GLOBAL | FR_CHAN, 0, 0, 0 };
-
   if (!chan || (chan && (channel_pending(chan) || !shouldjoin(chan) || !channel_active(chan) || me_op(chan))))
     return;
 
@@ -508,8 +494,11 @@ request_op(struct chanset_t *chan)
     putlog(LOG_GETIN, "*", "Not asking for ops on %s - I'm too lagged", chan->dname);
     return;
   }
+
+  int i = 0, my_exp = 0, first = 100;
+  time_t n = now;
+
   /* max OPREQ_COUNT requests per OPREQ_SECONDS sec */
-  n = now;
   while (i < 5) {
     if (n - chan->opreqtime[i] > OPREQ_SECONDS) {
       if (first > i)
@@ -527,6 +516,12 @@ request_op(struct chanset_t *chan)
   if (!checked_hostmask)
     check_hostmask();           /* check, and update hostmask */
 
+  int cnt = OP_BOTS, i2;
+  memberlist *ml = NULL;
+  memberlist *botops[MAX_BOTS];
+  char myserv[SERVLEN] = "";
+  struct flag_record fr = { FR_GLOBAL | FR_CHAN, 0, 0, 0 };
+
   for (i = 0, ml = chan->channel.member; (i < MAX_BOTS) && ml && ml->nick[0]; ml = ml->next) {
     /* If bot, linked, global op & !split & chanop & (chan is reserver | bot isn't +a) -> 
      * add to temp list */
@@ -546,10 +541,11 @@ request_op(struct chanset_t *chan)
     return;
   }
 
+  char *l = (char *) calloc(1, cnt * 50), s[100] = "";
+
   /* first scan for bots on my server, ask first found for ops */
-  cnt = OP_BOTS;
   sprintf(s, "gi o %s %s", chan->dname, botname);
-  l = (char *) calloc(1, cnt * 50);
+
   for (i2 = 0; i2 < i; i2++) {
     if (botops[i2]->server && (!strcmp(botops[i2]->server, myserv))) {
       putbot(botops[i2]->user->handle, s);
@@ -596,13 +592,11 @@ request_op(struct chanset_t *chan)
 static void
 request_in(struct chanset_t *chan)
 {
-  char s[255] = "", *l = NULL;
   int i = 0;
-  int cnt, n;
-  struct userrec *botops[MAX_BOTS], *u = NULL;
+  struct userrec *botops[MAX_BOTS];
   struct flag_record fr = { FR_GLOBAL | FR_CHAN | FR_ANYWH, 0, 0, 0 };
 
-  for (u = userlist; u && (i < MAX_BOTS); u = u->next) {
+  for (struct userrec *u = userlist; u && (i < MAX_BOTS); u = u->next) {
     get_user_flagrec(u, &fr, NULL);
     if (bot_hublevel(u) == 999 && glob_bot(fr) && chk_op(fr, chan)
 #ifdef G_BACKUP
@@ -616,12 +610,14 @@ request_in(struct chanset_t *chan)
     putlog(LOG_GETIN, "*", "No bots linked, can't request help to join %s", chan->dname);
     return;
   }
+
+  char s[255] = "", *l = (char *) calloc(1, IN_BOTS * 30);
+  int cnt = IN_BOTS, n;
+
   if (!checked_hostmask)
     check_hostmask();           /* check, and update hostmask */
-  cnt = IN_BOTS;
   sprintf(s, "gi i %s %s %s!%s %s %s", chan->dname, botname, botname, botuserhost,
           myipstr(4) ? myipstr(4) : ".", myipstr(6) ? myipstr(6) : ".");
-  l = (char *) calloc(1, cnt * 30);
   while (cnt) {
     n = randint(i);
     if (botops[n]) {
@@ -647,9 +643,9 @@ request_in(struct chanset_t *chan)
 /* Contains the logic to decide wether we want to punish someone. Returns
  * true (1) if we want to, false (0) if not.
  */
-static int
+static bool
 want_to_revenge(struct chanset_t *chan, struct userrec *u,
-                struct userrec *u2, char *badnick, char *victimstr, int mevictim)
+                struct userrec *u2, char *badnick, char *victimstr, bool mevictim)
 {
   struct flag_record fr = { FR_GLOBAL | FR_CHAN, 0, 0, 0 };
 
@@ -686,15 +682,16 @@ want_to_revenge(struct chanset_t *chan, struct userrec *u,
  */
 static void
 punish_badguy(struct chanset_t *chan, char *whobad,
-              struct userrec *u, char *badnick, char *victimstr, int mevictim, int type)
+              struct userrec *u, char *badnick, char *victimstr, bool mevictim, int type)
 {
-  char reason[1024] = "", ct[81] = "", *kick_msg = NULL;
-  memberlist *m = NULL;
-  struct flag_record fr = { FR_GLOBAL | FR_CHAN, 0, 0, 0 };
+  memberlist *m = ismember(chan, badnick);
 
-  m = ismember(chan, badnick);
   if (!m)
     return;
+
+  char reason[1024] = "", ct[81] = "", *kick_msg = NULL;
+  struct flag_record fr = { FR_GLOBAL | FR_CHAN, 0, 0, 0 };
+
   get_user_flagrec(u, &fr, chan->dname);
 
   /* Get current time into a string */
@@ -804,16 +801,13 @@ punish_badguy(struct chanset_t *chan, char *whobad,
 static void
 maybe_revenge(struct chanset_t *chan, char *whobad, char *whovictim, int type)
 {
-  char *badnick = NULL, *victimstr = NULL;
-  int mevictim;
-  struct userrec *u = NULL, *u2 = NULL;
-
   if (!chan || (type < 0))
     return;
 
   /* Get info about offender */
-  u = get_user_by_host(whobad);
-  badnick = splitnick(&whobad);
+  struct userrec *u = get_user_by_host(whobad), *u2 = NULL;
+  char *badnick = splitnick(&whobad), *victimstr = NULL;
+  bool mevictim;
 
   /* Get info about victim */
   u2 = get_user_by_host(whovictim);
@@ -846,7 +840,7 @@ my_setkey(struct chanset_t *chan, char *k)
  * m should be chan->channel.(exempt|invite|ban)
  */
 static void
-new_mask(masklist * m, char *s, char *who)
+new_mask(masklist *m, char *s, char *who)
 {
   for (; m && m->mask[0] && rfc_casecmp(m->mask, s); m = m->next) ;
   if (m->mask[0])
@@ -865,7 +859,8 @@ new_mask(masklist * m, char *s, char *who)
 
 /* Removes a nick from the channel member list (returns 1 if successful)
  */
-static int
+/* FIXME: This passing of FILE:LINE is unnecesary, an OLD bug may still exist from the malloc->calloc patch */
+static bool
 real_killmember(struct chanset_t *chan, char *nick, const char *file, int line)
 {
   memberlist *x = NULL, *old = NULL;
@@ -904,12 +899,11 @@ real_killmember(struct chanset_t *chan, char *nick, const char *file, int line)
 
 /* Check if I am a chanop. Returns boolean 1 or 0.
  */
-int
+bool
 me_op(struct chanset_t *chan)
 {
-  memberlist *mx = NULL;
+  memberlist *mx = ismember(chan, botname);
 
-  mx = ismember(chan, botname);
   if (!mx)
     return 0;
   if (chan_hasop(mx))
@@ -920,12 +914,11 @@ me_op(struct chanset_t *chan)
 
 /* Check whether I'm voice. Returns boolean 1 or 0.
  */
-static int
+static bool
 me_voice(struct chanset_t *chan)
 {
-  memberlist *mx = NULL;
+  memberlist *mx = ismember(chan, botname);
 
-  mx = ismember(chan, botname);
   if (!mx)
     return 0;
   if (chan_hasvoice(mx))
@@ -937,7 +930,7 @@ me_voice(struct chanset_t *chan)
 
 /* Check if there are any ops on the channel. Returns boolean 1 or 0.
  */
-static int
+static bool
 any_ops(struct chanset_t *chan)
 {
   memberlist *x = NULL;
@@ -955,16 +948,17 @@ any_ops(struct chanset_t *chan)
 static void
 reset_chan_info(struct chanset_t *chan)
 {
-  int opped = 0;
-
   /* Don't reset the channel if we're already resetting it */
   if (!shouldjoin(chan)) {
     dprintf(DP_MODE, "PART %s\n", chan->name);
     return;
   }
+
   if (!channel_pending(chan)) {
+    bool opped = 0;
+
     if (me_op(chan))
-      opped += 1;
+      opped = 1;
     free(chan->channel.key);
     chan->channel.key = (char *) calloc(1, 1);
     clear_channel(chan, 1);
@@ -1001,14 +995,15 @@ reset_chan_info(struct chanset_t *chan)
 static void
 check_lonely_channel(struct chanset_t *chan)
 {
+  if (channel_pending(chan) || !channel_active(chan) || me_op(chan) ||
+      !shouldjoin(chan) || (chan->channel.mode & CHANANON))
+    return;
+
   memberlist *m = NULL;
   char s[UHOSTLEN] = "";
   int i = 0;
   static int whined = 0;
 
-  if (channel_pending(chan) || !channel_active(chan) || me_op(chan) ||
-      !shouldjoin(chan) || (chan->channel.mode & CHANANON))
-    return;
   /* Count non-split channel members */
   for (m = chan->channel.member; m && m->nick[0]; m = m->next)
     if (!chan_issplit(m))
@@ -1029,7 +1024,7 @@ check_lonely_channel(struct chanset_t *chan)
     /* Other people here, but none are ops. If there are other bots make
      * them LEAVE!
      */
-    int ok = 1;
+    bool ok = 1;
     struct userrec *u = NULL;
 
     if (!whined) {
@@ -1075,9 +1070,7 @@ warn_pls_take(struct chanset_t *chan)
 static void
 check_servers(struct chanset_t *chan)
 {
-  memberlist *m = NULL;
-
-  for (m = chan->channel.member; m && m->nick[0]; m = m->next) {
+  for (memberlist *m = chan->channel.member; m && m->nick[0]; m = m->next) {
     if (!match_my_nick(m->nick) && chan_hasop(m) &&
         (!m->server || (m->server && !m->server[0]) || (m->hops == -1))) {
       putlog(LOG_DEBUG, "*", "Updating WHO for '%s' because '%s' is missing data.", chan->dname, m->nick);
@@ -1108,18 +1101,15 @@ check_netfight(struct chanset_t *chan)
 void
 raise_limit(struct chanset_t *chan)
 {
-  int nl, i, ul, ll;
-
   if (!chan || !me_op(chan))
     return;
 
-  nl = chan->channel.members + chan->limitraise;  /* new limit */
-
-  i = chan->limitraise >> 2;		/* DIV 4 */
-
+  int nl = chan->channel.members + chan->limitraise;	/* new limit */
+  int i = chan->limitraise >> 2;			/* DIV 4 */
   /* if the newlimit will be in the range made by these vars, dont change. */
-  ul = nl + i;                  /* upper limit range */
-  ll = nl - i;                  /* lower limit range */
+  int ul = nl + i;					/* upper limit */
+  int ll = nl - i;					/* lower limit */
+
   if ((chan->channel.maxmembers > ll) && (chan->channel.maxmembers < ul))
     return;                     /* the current limit is in the range, so leave it. */
 
@@ -1135,12 +1125,12 @@ raise_limit(struct chanset_t *chan)
 static void
 check_expired_chanstuff(struct chanset_t *chan)
 {
-  masklist *b = NULL, *e = NULL;
-  memberlist *m = NULL, *n = NULL;
-  char s[UHOSTLEN] = "";
-  struct flag_record fr = { FR_GLOBAL | FR_CHAN, 0, 0, 0 };
-
   if (channel_active(chan)) {
+    masklist *b = NULL, *e = NULL;
+    memberlist *m = NULL, *n = NULL;
+    char s[UHOSTLEN] = "";
+    struct flag_record fr = { FR_GLOBAL | FR_CHAN, 0, 0, 0 };
+
     if (me_op(chan)) {
       if (channel_dynamicbans(chan) && chan->ban_time)
         for (b = chan->channel.ban; b->mask[0]; b = b->next)
@@ -1217,15 +1207,13 @@ check_expired_chanstuff(struct chanset_t *chan)
           }
 
           if (m->user) {
-            struct flag_record fr2 = { FR_GLOBAL | FR_CHAN, 0, 0, 0 };
-
-            get_user_flagrec(m->user, &fr2, chan->dname);
-            if (!glob_bot(fr2)) {
-              if (!(m->flags & EVOICE) && !privchan(fr2, chan, PRIV_VOICE) &&
-                  ((channel_voice(chan) && !chk_devoice(fr2)) ||
-                   (!channel_voice(chan) && chk_voice(fr2, chan)))) {
+            get_user_flagrec(m->user, &fr, chan->dname);
+            if (!glob_bot(fr)) {
+              if (!(m->flags & EVOICE) && !privchan(fr, chan, PRIV_VOICE) &&
+                  ((channel_voice(chan) && !chk_devoice(fr)) ||
+                   (!channel_voice(chan) && chk_voice(fr, chan)))) {
                 add_mode(chan, '+', 'v', m->nick);
-              } else if ((chk_devoice(fr2) || (m->flags & EVOICE))) {
+              } else if ((chk_devoice(fr) || (m->flags & EVOICE))) {
                 add_mode(chan, '-', 'v', m->nick);
               }
             }
@@ -1245,9 +1233,7 @@ check_expired_chanstuff(struct chanset_t *chan)
 void
 irc_minutely()
 {
-  struct chanset_t *chan = NULL;
-
-  for (chan = chanset; chan; chan = chan->next) {
+  for (register struct chanset_t *chan = chanset; chan; chan = chan->next) {
     warn_pls_take(chan);
     if (server_online) {
       check_netfight(chan);
@@ -1279,15 +1265,12 @@ check_bind_pubc(char *cmd, char *nick, char *from, struct userrec *u, char *args
 void
 flush_modes()
 {
-  struct chanset_t *chan = NULL;
-  memberlist *m = NULL;
-
   if (!modesperline)		/* Haven't received 005 yet :) */
     return;
 
-  if (modesperline > MODES_PER_LINE_MAX)
-    modesperline = MODES_PER_LINE_MAX;
-  for (chan = chanset; chan; chan = chan->next) {
+  memberlist *m = NULL;
+
+  for (register struct chanset_t *chan = chanset; chan; chan = chan->next) {
     for (m = chan->channel.member; m && m->nick[0]; m = m->next) {
       if (m->delay && m->delay <= now) {
         m->delay = 0L;
@@ -1311,13 +1294,11 @@ irc_report(int idx, int details)
 {
   struct flag_record fr = { FR_GLOBAL | FR_CHAN, 0, 0, 0 };
   char ch[1024] = "", q[160] = "", *p = NULL;
-  int k;
+  int k = 10;
   size_t len;
-  struct chanset_t *chan = NULL;
 
   strcpy(q, "Channels: ");
-  k = 10;
-  for (chan = chanset; chan; chan = chan->next) {
+  for (struct chanset_t *chan = chanset; chan; chan = chan->next) {
     if (idx != DP_STDOUT)
       get_user_flagrec(dcc[idx].user, &fr, chan->dname);
 
@@ -1381,22 +1362,19 @@ static cmd_t irc_bot[] = {
 static void
 getin_5secondly()
 {
-  if (server_online) {
-    struct chanset_t *chan = NULL;
+  if (!server_online)
+    return;
 
-    for (chan = chanset; chan; chan = chan->next) {
-      if ((!channel_pending(chan) && channel_active(chan)) && !me_op(chan))
-        request_op(chan);
-    }
+  for (register struct chanset_t *chan = chanset; chan; chan = chan->next) {
+    if ((!channel_pending(chan) && channel_active(chan)) && !me_op(chan))
+      request_op(chan);
   }
 }
 
 void
 irc_init()
 {
-  struct chanset_t *chan = NULL;
-
-  for (chan = chanset; chan; chan = chan->next) {
+  for (struct chanset_t *chan = chanset; chan; chan = chan->next) {
     if (shouldjoin(chan))
       dprintf(DP_MODE, "JOIN %s %s\n", (chan->name[0]) ? chan->name : chan->dname, chan->key_prot);
     chan->status &= ~(CHAN_ACTIVE | CHAN_PEND | CHAN_ASKEDBANS);

+ 12 - 11
src/mod/irc.mod/irc.h

@@ -25,8 +25,8 @@ enum { BC_NOCOOKIE = 1, BC_SLACK, BC_HASH };
 static int check_bind_pubc(char *, char *, char *, struct userrec *, char *, char *);
 static char *makecookie(char *, char *);
 static int checkcookie(char *, char *, char *);
-static int me_voice(struct chanset_t *);
-static int any_ops(struct chanset_t *);
+static bool me_voice(struct chanset_t *);
+static bool any_ops(struct chanset_t *);
 static char *getchanmode(struct chanset_t *);
 static void flush_mode(struct chanset_t *, int);
 
@@ -39,20 +39,20 @@ static void flush_mode(struct chanset_t *, int);
 
 static void detect_autokick(char *, char *, struct chanset_t *, char *);
 /* static int target_priority(struct chanset_t *, memberlist *, int); */
-static int do_op(char *, struct chanset_t *, int, int);
+static bool do_op(char *, struct chanset_t *, time_t, bool);
 static void request_op(struct chanset_t *);
 static void request_in(struct chanset_t *);
 static void reset_chan_info(struct chanset_t *);
 static void my_setkey(struct chanset_t *, char *);
 static void maybe_revenge(struct chanset_t *, char *, char *, int);
-static int detect_chan_flood(char *, char *, char *, struct chanset_t *, int,
+static bool detect_chan_flood(char *, char *, char *, struct chanset_t *, int,
 			     char *);
 static void new_mask(masklist *, char *, char *);
 static void doban(struct chanset_t *, memberlist *);
 static char *quickban(struct chanset_t *, char *);
 static void got_op(struct chanset_t *chan, char *nick, char *from, char *who,
  		   struct userrec *opu, struct flag_record *opper);
-static int real_killmember(struct chanset_t *chan, char *nick, const char *file, int line);
+static bool real_killmember(struct chanset_t *chan, char *nick, const char *file, int line);
 #define killmember(chan, nick)        real_killmember((chan), (nick), __FILE__,__LINE__)
 static void check_lonely_channel(struct chanset_t *chan);
 static int gotmode(char *, char *);
@@ -62,13 +62,13 @@ static int gotmode(char *, char *);
 
 #endif /* MAKING_IRC */
 
-void real_add_mode(struct chanset_t *, const char, const char, const char *, int);
+void real_add_mode(struct chanset_t *, const char, const char, const char *, bool);
 #define add_mode(chan, pls, mode, nick) real_add_mode(chan, pls, mode, nick, 0)
 #define add_cookie(chan, nick) real_add_mode(chan, '+', 'o', nick, 1)
-int me_op(struct chanset_t *);
-void check_this_ban(struct chanset_t *, char *, int);
-void check_this_exempt(struct chanset_t *, char *, int);
-void check_this_invite(struct chanset_t *, char *, int);
+bool me_op(struct chanset_t *);
+void check_this_ban(struct chanset_t *, char *, bool);
+void check_this_exempt(struct chanset_t *, char *, bool);
+void check_this_invite(struct chanset_t *, char *, bool);
 void check_this_user(char *, int, char *);
 void raise_limit(struct chanset_t *);
 void enforce_closed(struct chanset_t *);
@@ -77,7 +77,8 @@ void recheck_channel_modes(struct chanset_t *);
 void irc_report(int, int);
 void flush_modes();
 
-extern int		max_bans, max_exempts, max_invites, max_modes, use_354;
+extern int		max_bans, max_exempts, max_invites, max_modes;
+extern bool		use_354;
 extern unsigned int	modesperline;
 #endif				/* _EGG_MOD_IRC_IRC_H */
 

+ 64 - 65
src/mod/irc.mod/mode.c

@@ -8,7 +8,7 @@
  */
 
 /* Reversing this mode? */
-static int reversing = 0;
+static bool reversing = 0;
 
 #  define PLUS    BIT0
 #  define MINUS   BIT1
@@ -21,8 +21,8 @@ static int reversing = 0;
 static struct flag_record user = { FR_GLOBAL | FR_CHAN, 0, 0, 0 };
 static struct flag_record victim = { FR_GLOBAL | FR_CHAN, 0, 0, 0 };
 
-static int
-do_op(char *nick, struct chanset_t *chan, int delay, int force)
+static bool
+do_op(char *nick, struct chanset_t *chan, time_t delay, bool force)
 {
   memberlist *m = ismember(chan, nick);
 
@@ -40,16 +40,12 @@ do_op(char *nick, struct chanset_t *chan, int delay, int force)
 static void
 flush_cookies(struct chanset_t *chan, int pri)
 {
-  char *p = NULL, out[512] = "", post[512] = "";
-  size_t postsize = sizeof(post);
-  unsigned int i = 0;
-
-  p = out;
-  post[0] = 0, postsize--;
+  char out[512] = "", *p = out, post[512] = "";
+  size_t postsize = sizeof(post) - 1;
 
   chan->cbytes = 0;
 
-  for (i = 0; i < (modesperline - 1); i++) {
+  for (unsigned int i = 0; i < (modesperline - 1); i++) {
     if (chan->ccmode[i].op && postsize > strlen(chan->ccmode[i].op)) {
 
       *p++ = '+';
@@ -68,9 +64,9 @@ flush_cookies(struct chanset_t *chan, int pri)
   *p = 0;
 
   if (post[0]) {
-    char *cookie = NULL;
     /* remove the trailing space... */
     size_t myindex = (sizeof(post) - 1) - postsize;
+    char *cookie;
 
     if (myindex > 0 && post[myindex - 1] == ' ')
       post[myindex - 1] = 0;
@@ -78,7 +74,7 @@ flush_cookies(struct chanset_t *chan, int pri)
     egg_strcatn(out, " ", sizeof(out));
     egg_strcatn(out, post, sizeof(out));
     egg_strcatn(out, " ", sizeof(out));
-
+    
     cookie = makecookie(chan->dname, botname);
     egg_strcatn(out, cookie, sizeof(out));
     free(cookie);
@@ -98,19 +94,17 @@ flush_cookies(struct chanset_t *chan, int pri)
 static void
 flush_mode(struct chanset_t *chan, int pri)
 {
-  char *p = NULL, out[512] = "", post[512] = "";
-  size_t postsize = sizeof(post);
-  int plus = 2;                 /* 0 = '-', 1 = '+', 2 = none */
-  unsigned int i = 0;
-
   if (!modesperline)            /* Haven't received 005 yet :) */
     return;
 
+  char out[512] = "", *p = out, post[512] = "";
+  size_t postsize = sizeof(post) - 1;
+  int plus = 2;                 /* 0 = '-', 1 = '+', 2 = none */
+  unsigned int i = 0;
+
   flush_cookies(chan, pri);
 
 /* dequeue_op_deop(chan); */
-  p = out;
-  post[0] = 0, postsize--;
 
 /* now does +o first.. */
   if (chan->mns[0]) {
@@ -238,17 +232,13 @@ flush_mode(struct chanset_t *chan, int pri)
 /* Queue a channel mode change
  */
 void
-real_add_mode(struct chanset_t *chan, const char plus, const char mode, const char *op, int cookie)
+real_add_mode(struct chanset_t *chan, const char plus, const char mode, const char *op, bool cookie)
 {
-  int type, modes, l;
-  unsigned int i;
-  masklist *m = NULL;
-  memberlist *mx = NULL;
-  char s[21] = "";
-
   if (!me_op(chan))
     return;
 
+  memberlist *mx = NULL;
+
   if (mode == 'o' || mode == 'v') {
     mx = ismember(chan, op);
     if (!mx)
@@ -275,6 +265,11 @@ real_add_mode(struct chanset_t *chan, const char plus, const char mode, const ch
     }
   }
 
+  int type, modes, l;
+  unsigned int i;
+  masklist *m = NULL;
+  char s[21] = "";
+
   if (chan->compat == 0) {
     if (mode == 'e' || mode == 'I')
       chan->compat = 2;
@@ -444,13 +439,7 @@ static void
 got_op(struct chanset_t *chan, char *nick, char *from,
        char *who, struct userrec *opu, struct flag_record *opper)
 {
-  memberlist *m = NULL;
-  char s[UHOSTLEN] = "";
-  struct userrec *u;
-  int check_chan = 0;
-  int snm = chan->stopnethack_mode;
-
-  m = ismember(chan, who);
+  memberlist *m = ismember(chan, who);
   if (!m) {
     if (channel_pending(chan))
       return;
@@ -459,6 +448,10 @@ got_op(struct chanset_t *chan, char *nick, char *from,
     return;
   }
 
+  char s[UHOSTLEN] = "";
+  struct userrec *u;
+  bool check_chan = 0;
+
   /* Did *I* just get opped? */
   if (!me_op(chan) && match_my_nick(who))
     check_chan = 1;
@@ -508,6 +501,8 @@ got_op(struct chanset_t *chan, char *nick, char *from,
   } else if (reversing && !match_my_nick(who))
     add_mode(chan, '-', 'o', who);
   if (!nick[0] && me_op(chan) && !match_my_nick(who)) {
+    int snm = chan->stopnethack_mode;
+
     if (chk_deop(victim)) {
       m->flags |= FAKEOP;
       add_mode(chan, '-', 'o', who);
@@ -538,9 +533,7 @@ got_op(struct chanset_t *chan, char *nick, char *from,
   m->flags |= WASOP;
   if (check_chan) {
     /* tell other bots to set jointime to 0 and join */
-    char *buf = NULL;
-
-    buf = (char *) calloc(1, strlen(chan->dname) + 3 + 1);
+    char *buf = (char *) calloc(1, strlen(chan->dname) + 3 + 1);
 
     sprintf(buf, "jn %s", chan->dname);
     putallbots(buf);
@@ -552,11 +545,8 @@ got_op(struct chanset_t *chan, char *nick, char *from,
 static void
 got_deop(struct chanset_t *chan, char *nick, char *from, char *who, struct userrec *opu)
 {
-  memberlist *m = NULL;
-  char s[UHOSTLEN] = "", s1[UHOSTLEN] = "";
-  struct userrec *u = NULL;
+  memberlist *m = ismember(chan, who);
 
-  m = ismember(chan, who);
   if (!m) {
     if (channel_pending(chan))
       return;
@@ -565,6 +555,9 @@ got_deop(struct chanset_t *chan, char *nick, char *from, char *who, struct userr
     return;
   }
 
+  char s[UHOSTLEN] = "", s1[UHOSTLEN] = "";
+  struct userrec *u = NULL;
+
   simple_sprintf(s, "%s!%s", m->nick, m->userhost);
   simple_sprintf(s1, "%s!%s", nick, from);
   u = get_user_by_host(s);
@@ -582,7 +575,7 @@ got_deop(struct chanset_t *chan, char *nick, char *from, char *who, struct userr
 
   /* Deop'd someone on my oplist? */
   if (me_op(chan)) {
-    int ok = 1;
+    bool ok = 1;
 
     /* if they aren't d|d then check if they are something we should protect */
     if (!glob_deop(victim) && !chan_deop(victim)) {
@@ -633,9 +626,7 @@ got_deop(struct chanset_t *chan, char *nick, char *from, char *who, struct userr
 static void
 got_ban(struct chanset_t *chan, char *nick, char *from, char *who)
 {
-  char me[UHOSTLEN] = "", s[UHOSTLEN] = "", s1[UHOSTLEN] = "";
-  memberlist *m = NULL;
-  struct userrec *u = NULL;
+  char me[UHOSTLEN] = "", s[UHOSTLEN] = "";
 
   egg_snprintf(me, sizeof me, "%s!%s", botname, botuserhost);
   egg_snprintf(s, sizeof s, "%s!%s", nick, from);
@@ -649,13 +640,18 @@ got_ban(struct chanset_t *chan, char *nick, char *from, char *who)
     reversing = 1;
     return;
   }
+
+  struct userrec *u = NULL;
+
   if (!match_my_nick(nick)) {
     if (channel_nouserbans(chan) && nick[0] && !glob_bot(user)) {
       add_mode(chan, '-', 'b', who);
       return;
     }
     /* remove bans on ops unless a master/bot set it */
-    for (m = chan->channel.member; m && m->nick[0]; m = m->next) {
+    char s1[UHOSTLEN] = "";
+
+    for (memberlist *m = chan->channel.member; m && m->nick[0]; m = m->next) {
       egg_snprintf(s1, sizeof s1, "%s!%s", m->nick, m->userhost);
       if (wild_match(who, s1)) {
         u = get_user_by_host(s1);
@@ -862,18 +858,15 @@ got_uninvite(struct chanset_t *chan, char *nick, char *from, char *who, struct u
 static int
 gotmode(char *from, char *msg)
 {
-  char *nick = NULL, *ch = NULL, *op = NULL, *chg = NULL, s[UHOSTLEN] = "", ms2[3] = "";
-  int z, isserver = 0;
-  struct userrec *u = NULL;
-  memberlist *m = NULL;
-  struct chanset_t *chan = NULL;
-
   /* Usermode changes? */
   if (msg[0] && (strchr(CHANMETA, msg[0]) != NULL)) {
-    ch = newsplit(&msg);
+    char *ch = newsplit(&msg);
+
     if (match_my_nick(ch))
       return 0;
-    chan = findchan(ch);
+
+    struct chanset_t *chan = findchan(ch);
+
     if (!chan) {
       putlog(LOG_MISC, "*", CHAN_FORCEJOIN, ch);
       dprintf(DP_SERVER, "PART %s\n", ch);
@@ -882,11 +875,17 @@ gotmode(char *from, char *msg)
 
     /* let's pre-emptively check for mass op/deop, manual ops and cookieops */
 
-    if (!strchr(from, '!'))
-      isserver++;
-
     if ((channel_active(chan) || channel_pending(chan))) {
-      z = strlen(msg);
+
+      bool isserver = 0;
+      char *nick = NULL, *op = NULL, *chg = NULL, s[UHOSTLEN] = "", ms2[3] = "";
+      size_t z = strlen(msg);
+      struct userrec *u = NULL;
+      memberlist *m = NULL;
+
+      if (!strchr(from, '!'))
+        isserver = 1;
+
       if (msg[--z] == ' ')      /* I hate cosmetic bugs :P -poptix */
         msg[z] = 0;
 
@@ -900,17 +899,17 @@ gotmode(char *from, char *msg)
       }
 
       if (!isserver) {
-        char **modes = NULL;
-        char tmp[1024] = "", *wptr = NULL, *p = NULL, work[1024] = "", sign = '+';
-        int modecnt = 0, i = 0, n = 0, ops = 0, deops = 0, bans = 0, unbans = 0, me_opped = 0;
+        char **modes = (char **) calloc(modesperline + 1, sizeof(char *));
+        char tmp[1024] = "", *p = NULL, work[1024] = "", *wptr = work, sign = '+', *mp;
+        int modecnt = 0, i = 0, n = 0, ops = 0, deops = 0, bans = 0, unbans = 0;
+        bool me_opped = 0;
 
         /* Split up the mode: #chan modes param param param param */
         strncpyz(work, msg, sizeof(work));
-        wptr = work;
         p = newsplit(&wptr);
-        modes = (char **) calloc(modesperline + 1, sizeof(char *));
         while (*p) {            /* +MODES PARAM PARAM PARAM ... */
-          char *mp = NULL;
+          mp = NULL;
+
           if (*p == '+')
             sign = '+';
           else if (*p == '-')
@@ -1288,7 +1287,7 @@ gotmode(char *from, char *msg)
               putlog(LOG_MISC, chan->dname, CHAN_BADCHANMODE, chan->dname, op);
               dprintf(DP_MODE, "WHO %s\n", op);
             } else {
-              int dv = 0;
+              bool dv = 0;
 
               simple_sprintf(s, "%s!%s", m->nick, m->userhost);
               get_user_flagrec(m->user ? m->user : get_user_by_host(s), &victim, chan->dname);
@@ -1297,7 +1296,7 @@ gotmode(char *from, char *msg)
                 if (m->flags & EVOICE) {
 /* FIXME: This is a lame check, we need to expand on this more */
                   if (!chan_master(user) && !glob_master(user)) {
-                    dv++;
+                    dv = 1;
                   } else {
                     m->flags &= ~EVOICE;
                   }

+ 12 - 15
src/mod/notes.mod/cmdsnote.c

@@ -6,26 +6,25 @@
 
 static void cmd_fwd(int idx, char *par)
 {
-  char *handle = NULL;
-  struct userrec *u1 = NULL;
-
   if (!par[0]) {
     dprintf(idx, "%s: fwd <handle> [user@bot]\n", NOTES_USAGE);
     return;
   }
-  handle = newsplit(&par);
-  u1 = get_user_by_handle(userlist, handle);
+
+  struct userrec *u1 = get_user_by_handle(userlist, newsplit(&par));
+
   if (!u1) {
     dprintf(idx, "%s\n", NOTES_NO_SUCH_USER);
     return;
   }
-  if ((u1->flags & USER_OWNER) && egg_strcasecmp(handle, dcc[idx].nick)) {
+
+  if ((u1->flags & USER_OWNER) && egg_strcasecmp(u1->handle, dcc[idx].nick)) {
     dprintf(idx, "%s\n", NOTES_FWD_OWNER);
     return;
   }
   if (!par[0]) {
-    putlog(LOG_CMDS, "*", "#%s# fwd %s", dcc[idx].nick, handle);
-    dprintf(idx, NOTES_FWD_FOR, handle);
+    putlog(LOG_CMDS, "*", "#%s# fwd %s", dcc[idx].nick, u1->handle);
+    dprintf(idx, NOTES_FWD_FOR, u1->handle);
     set_user(&USERENTRY_FWD, u1, NULL);
     return;
   }
@@ -34,15 +33,13 @@ static void cmd_fwd(int idx, char *par)
     dprintf(idx, "%s\n", NOTES_FWD_BOTNAME);
     return;
   }
-  putlog(LOG_CMDS, "*", "#%s# fwd %s %s", dcc[idx].nick, handle, par);
-  dprintf(idx, NOTES_FWD_CHANGED, handle, par);
+  putlog(LOG_CMDS, "*", "#%s# fwd %s %s", dcc[idx].nick, u1->handle, par);
+  dprintf(idx, NOTES_FWD_CHANGED, u1->handle, par);
   set_user(&USERENTRY_FWD, u1, par);
 }
 
 static void cmd_notes(int idx, char *par)
 {
-  char *fcn = NULL;
-
   if (!par[0]) {
     dprintf(idx, "%s: notes index\n", NOTES_USAGE);
     dprintf(idx, "       notes read <# or ALL>\n");
@@ -51,7 +48,8 @@ static void cmd_notes(int idx, char *par)
     dprintf(idx, "       ex: notes erase 2-4;8;16-\n");
     return;
   }
-  fcn = newsplit(&par);
+  char *fcn = newsplit(&par);
+
   if (!egg_strcasecmp(fcn, "index"))
     notes_read(dcc[idx].nick, "", "+", idx);
   else if (!egg_strcasecmp(fcn, "read")) {
@@ -73,10 +71,9 @@ static void cmd_notes(int idx, char *par)
 
 static void cmd_note(int idx, char *par)
 {
-  char handle[512] = "", *p = NULL;
+  char handle[512] = "", *p = newsplit(&par);
   int echo;
 
-  p = newsplit(&par);
   if (!par[0]) {
     dprintf(idx, "%s: note <to-whom> <message>\n", NOTES_USAGE);
     return;

+ 18 - 12
src/mod/notes.mod/notes.c

@@ -61,15 +61,18 @@ void fwd_display(int idx, struct user_entry *e, struct userrec *u)
  */
 int num_notes(const char *user)
 {
-  int tot = 0;
-  FILE *f = NULL;
-  char s[513] = "", *to = NULL, *s1 = NULL;
-
   if (!notefile[0])
     return 0;
+
+  FILE *f = NULL;
+
   f = fopen(notefile, "r");
   if (f == NULL)
     return 0;
+
+  int tot = 0;
+  char s[513] = "", *to = NULL, *s1 = NULL;
+
   while (!feof(f)) {
     fgets(s, 512, f);
     if (!feof(f)) {
@@ -92,14 +95,15 @@ int num_notes(const char *user)
  */
 static void notes_change(const char *oldnick, const char *newnick)
 {
-  FILE *f = NULL, *g = NULL;
-  char s[513] = "", *to = NULL, *s1 = NULL;
-  int tot = 0;
-
   if (!egg_strcasecmp(oldnick, newnick))
     return;
   if (!notefile[0])
     return;
+
+  FILE *f = NULL, *g = NULL;
+  char s[513] = "", *to = NULL, *s1 = NULL;
+  int tot = 0;
+
   f = fopen(notefile, "r");
   if (f == NULL)
     return;
@@ -141,12 +145,13 @@ static void notes_change(const char *oldnick, const char *newnick)
  */
 static void expire_notes()
 {
+  if (!notefile[0])
+    return;
+
   FILE *f = NULL, *g = NULL;
   char s[513] = "", *to = NULL, *from = NULL, *ts = NULL, *s1 = NULL;
   int tot = 0, lapse;
 
-  if (!notefile[0])
-    return;
   f = fopen(notefile, "r");
   if (f == NULL)
     return;
@@ -559,8 +564,6 @@ void notes_del(const char *hand, const char *nick, const char *sdl, int idx)
  */
 static int msg_notes(char *nick, char *host, struct userrec *u, char *par)
 {
-  char *pwd = NULL, *fcn = NULL;
-
   if (!u)
     return 0;
   if (u->bot)
@@ -574,6 +577,9 @@ static int msg_notes(char *nick, char *host, struct userrec *u, char *par)
     dprintf(DP_HELP, "NOTICE %s :       ex: NOTES mypass ERASE 2-4;8;16-\n", nick);
     return 1;
   }
+
+  char *pwd = NULL, *fcn = NULL;
+
   if (!u_pass_match(u, "-")) {
     /* they have a password set */
     pwd = newsplit(&par);

+ 2 - 1
src/mod/server.mod/cmdsserv.c

@@ -81,7 +81,8 @@ static void cmd_clearqueue(int idx, char *par)
     msgq_clear(&modeq);
     msgq_clear(&mq);
     msgq_clear(&hq);
-    double_warned = burst = 0;
+    double_warned = 0;
+    burst = 0;
     dprintf(idx, "Removed %d message%s from all queues.\n", msgs, 
         (msgs != 1) ? "s" : "");
   } else if (!egg_strcasecmp(par, "mode")) {

+ 59 - 54
src/mod/server.mod/server.c

@@ -26,64 +26,62 @@
 #include "server.h"
 #include <stdarg.h>
 
-int checked_hostmask;	/* Used in request_op()/check_hostmask() cleared on connect */
+bool strict_servernames;
+bool checked_hostmask;	/* Used in request_op()/check_hostmask() cleared on connect */
 int ctcp_mode;
-int serv;		/* sock # of server currently */
+sock_t serv;		/* sock # of server currently */
 int servidx;		/* idx of server */
 char newserver[121] = "";	/* new server? */
-int newserverport;		/* new server port? */
+port_t newserverport;		/* new server port? */
 char newserverpass[121] = "";	/* new server password? */
 static char serverpass[121] = "";
 static time_t trying_server;	/* trying to connect to a server right now? */
 static int curserv;		/* current position in server list: */
 int flud_thr;		/* msg flood threshold */
-int flud_time;		/* msg flood time */
+time_t flud_time;		/* msg flood time */
 int flud_ctcp_thr;	/* ctcp flood threshold */
-int flud_ctcp_time;	/* ctcp flood time */
+time_t flud_ctcp_time;	/* ctcp flood time */
 char botuserhost[121] = "";	/* bot's user@host (refreshed whenever the
 				   bot joins a channel) */
 				/* may not be correct user@host BUT it's
 				   how the server sees it */
-static int keepnick;		/* keep trying to regain my intended
+static bool keepnick = 1;		/* keep trying to regain my intended
 				   nickname? */
-static int nick_juped = 0;	/* True if origbotname is juped(RPL437) (dw) */
-static int serverror_quit;	/* Disconnect from server if ERROR
-				   messages received? */
-int quiet_reject;	/* Quietly reject dcc chat or sends from
+static bool nick_juped = 0;	/* True if origbotname is juped(RPL437) (dw) */
+bool quiet_reject;	/* Quietly reject dcc chat or sends from
 				   users without access? */
-static int waiting_for_awake;	/* set when i unidle myself, cleared when
+static time_t waiting_for_awake;	/* set when i unidle myself, cleared when
 				   i get the response */
 time_t server_online;	/* server connection time */
 char botrealname[121] = "";	/* realname of bot */
-static int server_timeout;	/* server timeout for connecting */
-static int strict_servernames;	/* don't update server list */
+static time_t server_timeout;	/* server timeout for connecting */
 struct server_list *serverlist = NULL;	/* old-style queue, still used by
 					   server list */
-int cycle_time;			/* cycle time till next server connect */
+time_t cycle_time;			/* cycle time till next server connect */
 port_t default_port;		/* default IRC port */
 static char oldnick[NICKLEN] = "";	/* previous nickname *before* rehash */
-int trigger_on_ignore;	/* trigger bindings if user is ignored ? */
+bool trigger_on_ignore;	/* trigger bindings if user is ignored ? */
 int answer_ctcp;		/* answer how many stacked ctcp's ? */
-static int check_mode_r;	/* check for IRCNET +r modes */
+static bool check_mode_r;	/* check for IRCNET +r modes */
 static int net_type;
-static int resolvserv;		/* in the process of resolving a server host */
-static int double_mode;		/* allow a msgs to be twice in a queue? */
-static int double_server;
-static int double_help;
-static int double_warned;
-static int lastpingtime;	/* IRCNet LAGmeter support -- drummer */
+static bool resolvserv;		/* in the process of resolving a server host */
+static bool double_mode;		/* allow a msgs to be twice in a queue? */
+static bool double_server;
+static bool double_help;
+static bool double_warned;
+static time_t lastpingtime;	/* IRCNet LAGmeter support -- drummer */
 static char stackablecmds[511] = "";
 static char stackable2cmds[511] = "";
 static time_t last_time;
-static int use_penalties;
+static bool use_penalties;
 static int use_fastdeq;
-int nick_len;			/* Maximal nick length allowed on the network. */
+size_t nick_len = 9;			/* Maximal nick length allowed on the network. */
 
 static void empty_msgq(void);
 static void next_server(int *, char *, port_t *, char *);
 static void disconnect_server(int, int);
 static int calc_penalty(char *);
-static int fast_deq(int);
+static bool fast_deq(int);
 static char *splitnicks(char **);
 static void msgq_clear(struct msgq_head *qh);
 static int stack_limit;
@@ -126,8 +124,7 @@ static int burst;
  */
 static void deq_msg()
 {
-  struct msgq *q = NULL;
-  int ok = 0;
+  bool ok = 0;
 
   /* now < last_time tested 'cause clock adjustments could mess it up */
   if ((now - last_time) >= msgrate || now < (last_time - 90)) {
@@ -138,6 +135,9 @@ static void deq_msg()
   }
   if (serv < 0)
     return;
+
+  struct msgq *q = NULL;
+
   /* Send upto 4 msgs to server if the *critical queue* has anything in it */
   if (modeq.head) {
     while (modeq.head && (burst < 4) && ((last_time - now) < MAXPENALTY)) {
@@ -210,12 +210,12 @@ static void deq_msg()
 
 static int calc_penalty(char * msg)
 {
+  if (!use_penalties && net_type != NETT_UNDERNET && net_type != NETT_HYBRID_EFNET)
+    return 0;
+
   char *cmd = NULL, *par1 = NULL, *par2 = NULL, *par3 = NULL;
   register int penalty, i, ii;
 
-  if (!use_penalties &&
-      net_type != NETT_UNDERNET && net_type != NETT_HYBRID_EFNET)
-    return 0;
   if (msg[strlen(msg) - 1] == '\n')
     msg[strlen(msg) - 1] = '\0';
   cmd = newsplit(&msg);
@@ -341,11 +341,11 @@ static int calc_penalty(char * msg)
 
 char *splitnicks(char **rest)
 {
-  register char *o = NULL, *r = NULL;
-
   if (!rest)
     return *rest = "";
-  o = *rest;
+
+  register char *o = *rest, *r = NULL;
+
   while (*o == ' ')
     o++;
   r = o;
@@ -357,16 +357,19 @@ char *splitnicks(char **rest)
   return r;
 }
 
-static int fast_deq(int which)
+static bool fast_deq(int which)
 {
+  if (!use_fastdeq)
+    return 0;
+
   struct msgq_head *h = NULL;
   struct msgq *m = NULL, *nm = NULL;
   char msgstr[511] = "", nextmsgstr[511] = "", tosend[511] = "", victims[511] = "", stackable[511] = "",
        *msg = NULL, *nextmsg = NULL, *cmd = NULL, *nextcmd = NULL, *to = NULL, *nextto = NULL, *stckbl = NULL;
-  int len, doit = 0, found = 0, cmd_count = 0, stack_method = 1;
+  int cmd_count = 0, stack_method = 1;
+  size_t len;
+  bool found = 0, doit = 0;
 
-  if (!use_fastdeq)
-    return 0;
   switch (which) {
     case DP_MODE:
       h = &modeq;
@@ -491,13 +494,14 @@ static void empty_msgq()
  */
 void queue_server(int which, char *buf, int len)
 {
+  /* Don't even BOTHER if there's no server online. */
+  if (serv < 0)
+    return;
+
   struct msgq_head *h = NULL, tempq;
   struct msgq *q = NULL, *tq = NULL, *tqq = NULL;
   int doublemsg = 0, qnext = 0;
 
-  /* Don't even BOTHER if there's no server online. */
-  if (serv < 0)
-    return;
   /* No queue for PING and PONG - drummer */
   if (!egg_strncasecmp(buf, "PING", 4) || !egg_strncasecmp(buf, "PONG", 4)) {
     if (buf[1] == 'I' || buf[1] == 'i')
@@ -727,10 +731,12 @@ void clearq(struct server_list *xx)
 static void next_server(int *ptr, char *servname, port_t *port, char *pass)
 {
   struct server_list *x = serverlist;
-  int i = 0;
 
   if (x == NULL)
     return;
+
+  int i = 0;
+
   /* -1  -->  Go to specified server */
   if (*ptr == (-1)) {
     for (; x; x = x->next) {
@@ -822,22 +828,25 @@ static void dcc_chat_hostresolved(int);
  */
 static int ctcp_DCC_CHAT(char *nick, char *from, struct userrec *u, char *object, char *keyword, char *text)
 {
-  char *action = NULL, *param = NULL, *ip = NULL, *prt = NULL;
-  int i, ok;
-  struct flag_record fr = {FR_GLOBAL | FR_CHAN | FR_ANYWH, 0, 0, 0 };
-  
   if (!ischanhub())
     return BIND_RET_LOG;
 
+  char *action = NULL, *param = NULL, *ip = NULL, *prt = NULL;
+
   action = newsplit(&text);
   param = newsplit(&text);
   ip = newsplit(&text);
   prt = newsplit(&text);
+
   if (egg_strcasecmp(action, "CHAT") || egg_strcasecmp(object, botname) || !u)
     return BIND_RET_LOG;
 
+  int i;
+  bool ok = 1;
+  struct flag_record fr = {FR_GLOBAL | FR_CHAN | FR_ANYWH, 0, 0, 0 };
+
   get_user_flagrec(u, &fr, 0);
-  ok = 1;
+
   if (ischanhub() && !glob_chuba(fr))
    ok = 0;
   if (dcc_total == max_dcc) {
@@ -899,7 +908,6 @@ static int ctcp_DCC_CHAT(char *nick, char *from, struct userrec *u, char *object
 static void dcc_chat_hostresolved(int i)
 {
   char buf[512] = "", ip[512] = "";
-  int ok;
   struct flag_record fr = {FR_GLOBAL | FR_CHAN | FR_ANYWH, 0, 0, 0 };
 
   egg_snprintf(buf, sizeof buf, "%d", dcc[i].port);
@@ -936,13 +944,13 @@ static void dcc_chat_hostresolved(int i)
     killsock(dcc[i].sock);
     lostdcc(i);
   } else {
+    bool ok = 1;
 #ifdef HAVE_SSL
     ssl_link(dcc[i].sock, CONNECT_SSL);
 #endif /* HAVE_SSL */
     changeover_dcc(i, &DCC_CHAT_PASS, sizeof(struct chat_info));
     dcc[i].status = STAT_ECHO;
     get_user_flagrec(dcc[i].user, &fr, 0);
-    ok = 1;
     if (ischanhub() && !glob_chuba(fr))
      ok = 0;
     if (ok)
@@ -1036,16 +1044,16 @@ void server_report(int idx, int details)
     dprintf(idx, "    %s %d%%, %d msgs\n", IRC_HELPQUEUE,
            (int) ((float) (hq.tot * 100.0) / (float) maxqmsg), (int) hq.tot);
   if (details) {
-    dprintf(idx, "    Flood is: %d msg/%ds, %d ctcp/%ds\n",
+    dprintf(idx, "    Flood is: %d msg/%lus, %d ctcp/%lus\n",
 	    flud_thr, flud_time, flud_ctcp_thr, flud_ctcp_time);
   }
 }
 
 static void msgq_clear(struct msgq_head *qh)
 {
-  register struct msgq	*q = NULL, *qq = NULL;
+  register struct msgq *qq = NULL;
 
-  for (q = qh->head; q; q = qq) {
+  for (register struct msgq *q = qh->head; q; q = qq) {
     qq = q->next;
     free(q->msg);
     free(q);
@@ -1077,8 +1085,6 @@ void server_init()
   flud_ctcp_thr = 3;
   flud_ctcp_time = 60;
   botuserhost[0] = 0;
-  keepnick = 1;
-  serverror_quit = 1;
   quiet_reject = 1;
   waiting_for_awake = 0;
   server_online = 0;
@@ -1104,7 +1110,6 @@ void server_init()
   resolvserv = 0;
   lastpingtime = 0;
   last_time = 0;
-  nick_len = 9;
   stack_limit = 4;
 
   BT_msgc = bind_table_add("msgc", 5, "ssUss", MATCH_FLAGS, 0); 

+ 9 - 10
src/mod/server.mod/server.h

@@ -40,16 +40,13 @@ enum {
 #define IRC_CANTCHANGENICK "Can't change nickname on %s.  Is my nickname banned?"
 #endif		/* _EGG_MOD_SERVER_SERVER_H */
 
-void nuke_server(char *);
-int match_my_nick(char *);
-
 extern bind_table_t	*BT_ctcp, *BT_ctcr, *BT_msgc;
-extern int 		serv, servidx, cycle_time, newserverport,
-			nick_len, checked_hostmask, ctcp_mode, quiet_reject,
-			flud_thr, flud_time, flud_ctcp_thr, flud_ctcp_time,
-			answer_ctcp, trigger_on_ignore;
-extern port_t		default_port;
-extern time_t		server_online;
+extern sock_t		serv;
+extern size_t		nick_len;
+extern bool		checked_hostmask, quiet_reject, trigger_on_ignore;
+extern int 		servidx, ctcp_mode, flud_thr, flud_ctcp_thr, answer_ctcp;
+extern port_t		default_port, newserverport;
+extern time_t		server_online, cycle_time, flud_time, flud_ctcp_time;
 extern char		cursrvname[], botrealname[], botuserhost[], ctcp_reply[],
 			newserver[], newserverpass[], curnetwork[];
 extern struct server_list *serverlist;
@@ -59,12 +56,14 @@ int check_bind_ctcpr(char *, char *, struct userrec *, char *, char *, char *, b
 #define check_bind_ctcp(a, b, c, d, e, f) check_bind_ctcpr(a, b, c, d, e, f, BT_ctcp)
 #define check_bind_ctcr(a, b, c, d, e, f) check_bind_ctcpr(a, b, c, d, e, f, BT_ctcr)
 
-int detect_avalanche(char *);
+bool detect_avalanche(char *);
 void server_report(int, int);
 void server_init();
 void queue_server(int, char *, int);
 void server_die();
 void add_server(char *);
 void clearq(struct server_list *);
+void nuke_server(char *);
+bool match_my_nick(char *);
 
 #endif /*leaf*/

+ 58 - 103
src/mod/server.mod/servmsg.c

@@ -53,7 +53,7 @@ static int gotfake433(char *from)
     } else if (rolls < len) {
         /* fun BX style rolling, WEEEE */
         char tmp = 0;
-        int i = 0;
+        size_t i = 0;
 
         altnick_char = 0;
         use_chr = 0;
@@ -159,7 +159,7 @@ int check_bind_ctcpr(char *nick, char *uhost, struct userrec *u,
 }
 
 
-int match_my_nick(char *nick)
+bool match_my_nick(char *nick)
 {
   return (!rfc_casecmp(nick, botname));
 }
@@ -169,8 +169,6 @@ int match_my_nick(char *nick)
 static int got001(char *from, char *msg)
 {
   struct server_list *x = NULL;
-  int i;
-  struct chanset_t *chan = NULL;
 
   server_online = now;
   checked_hostmask = 0;
@@ -186,7 +184,7 @@ static int got001(char *from, char *msg)
   if (x == NULL)
     return 0;			/* Uh, no server list */
 
-  for (chan = chanset; chan; chan = chan->next) {
+  for (register struct chanset_t *chan = chanset; chan; chan = chan->next) {
     chan->status &= ~(CHAN_ACTIVE | CHAN_PEND);
     if (shouldjoin(chan))
       dprintf(DP_SERVER, "JOIN %s %s\n", (chan->name[0]) ? chan->name : chan->dname,
@@ -194,7 +192,7 @@ static int got001(char *from, char *msg)
   }
   if (egg_strcasecmp(from, dcc[servidx].host)) {
     putlog(LOG_MISC, "*", "(%s claims to be %s; updating server list)", dcc[servidx].host, from);
-    for (i = curserv; i > 0 && x != NULL; i--)
+    for (int i = curserv; i > 0 && x != NULL; i--)
       x = x->next;
     if (x == NULL) {
       putlog(LOG_MISC, "*", "Invalid server list!");
@@ -218,20 +216,23 @@ static int got001(char *from, char *msg)
 static int
 got005(char *from, char *msg)
 {
-  char *tmp = NULL;
+  char *tmp = NULL, *p, *p2;
 
   newsplit(&msg); /* nick */
 
   while ((tmp = newsplit(&msg))[0]) {
-    char *p = NULL;
+    p = NULL;
 
     if ((p = strchr(tmp, '=')))
       *p++ = 0;
     if (!egg_strcasecmp(tmp, ":are"))
       break;
-    else if (!egg_strcasecmp(tmp, "MODES"))
+    else if (!egg_strcasecmp(tmp, "MODES")) {
       modesperline = atoi(p);
-    else if (!egg_strcasecmp(tmp, "NICKLEN"))
+
+      if (modesperline > MODES_PER_LINE_MAX)
+        modesperline = MODES_PER_LINE_MAX;
+    } else if (!egg_strcasecmp(tmp, "NICKLEN"))
       nick_len = atoi(p);
     else if (!egg_strcasecmp(tmp, "NETWORK"))
       strncpyz(curnetwork, p, 120);
@@ -250,7 +251,7 @@ got005(char *from, char *msg)
       max_invites = max_bans;
     }
     else if (!egg_strcasecmp(tmp, "MAXLIST")) {
-      char *p2 = NULL;
+      p2 = NULL;
       
       if ((p2 = strchr(p, ':'))) {
         *p2++ = 0;
@@ -281,8 +282,8 @@ static int got442(char *from, char *msg)
 {
   char *chname = NULL;
   struct chanset_t *chan = NULL;
-  struct server_list *x = NULL;
   int i;
+  struct server_list *x = NULL;
 
   for (x = serverlist, i = 0; x; x = x->next, i++)
     if (i == curserv) {
@@ -326,20 +327,21 @@ static time_t lastmsgtime[FLOOD_GLOBAL_MAX];
 
 /* Do on NICK, PRIVMSG, NOTICE and JOIN.
  */
-static int detect_flood(char *floodnick, char *floodhost, char *from, int which)
+static bool detect_flood(char *floodnick, char *floodhost, char *from, int which)
 {
-  char *p = NULL, ftype[10] = "", h[1024] = "";
-  struct userrec *u = NULL;
-  int thr = 0, lapse = 0, atr;
+  struct userrec *u = get_user_by_host(from);
+  int atr = u ? u->flags : 0;
 
-  u = get_user_by_host(from);
-  atr = u ? u->flags : 0;
   if ((u && u->bot) || (atr & USER_NOFLOOD))
     return 0;
 
   if (findauth(floodhost) > -1) 
     return 0;
 
+  char *p = NULL, ftype[10] = "", h[1024] = "";
+  int thr = 0;
+  time_t lapse = 0;
+
   /* Determine how many are necessary to make a flood */
   switch (which) {
   case FLOOD_PRIVMSG:
@@ -397,12 +399,11 @@ static int detect_flood(char *floodnick, char *floodhost, char *from, int which)
 /* Check for more than 8 control characters in a line.
  * This could indicate: beep flood CTCP avalanche.
  */
-int detect_avalanche(char *msg)
+bool detect_avalanche(char *msg)
 {
   int count = 0;
-  unsigned char *p = NULL;
 
-  for (p = (unsigned char *) msg; (*p) && (count < 8); p++)
+  for (unsigned char *p = (unsigned char *) msg; (*p) && (count < 8); p++)
     if ((*p == 7) || (*p == 1))
       count++;
   if (count >= 8)
@@ -415,17 +416,18 @@ int detect_avalanche(char *msg)
  */
 static int gotmsg(char *from, char *msg)
 {
-  char *to = NULL, buf[UHOSTLEN] = "", *nick = NULL, ctcpbuf[512] = "", *uhost = buf, 
-       *ctcp = NULL, *p = NULL, *p1 = NULL, *code = NULL;
-  struct userrec *u = NULL;
-  int ctcp_count = 0, i = 0, ignoring = 0;
-
   if (msg[0] && ((strchr(CHANMETA, *msg) != NULL) ||
      (*msg == '@')))           /* Notice to a channel, not handled here */
     return 0;
 
-  ignoring = match_ignore(from);
+  char *to = NULL, buf[UHOSTLEN] = "", *nick = NULL, ctcpbuf[512] = "", *uhost = buf, 
+       *ctcp = NULL, *p = NULL, *p1 = NULL, *code = NULL;
+  struct userrec *u = NULL;
+  int ctcp_count = 0, i = 0;
+  bool ignoring = match_ignore(from);
+
   to = newsplit(&msg);
+
   fixcolon(msg);
   /* Only check if flood-ctcp is active */
   strcpy(uhost, from);
@@ -560,7 +562,8 @@ static int gotmsg(char *from, char *msg)
           putlog(LOG_MSGS, "*", "[%s] %c%s %s", from, cmdprefix, my_code, msg);
       } else if ((my_code[0] != cmdprefix || !my_code[1] || i == -1 || !(auth[i].authed))) {
         if (!ignoring) {
-          int doit = 1;
+          bool doit = 1;
+
           if (!egg_strcasecmp(my_code, "op") || !egg_strcasecmp(my_code, "pass") || !egg_strcasecmp(my_code, "invite") 
               || !egg_strcasecmp(my_code, "ident")
                || !egg_strcasecmp(my_code, msgop) || !egg_strcasecmp(my_code, msgpass) 
@@ -592,15 +595,15 @@ static int gotmsg(char *from, char *msg)
  */
 static int gotnotice(char *from, char *msg)
 {
+  if (msg[0] && ((strchr(CHANMETA, *msg) != NULL) ||
+      (*msg == '@')))           /* Notice to a channel, not handled here */
+    return 0;
+
   char *to = NULL, *nick = NULL, ctcpbuf[512] = "", *p = NULL, *p1 = NULL, buf[512] = "", 
        *uhost = buf, *ctcp = NULL, *ctcpmsg = NULL, *ptr = NULL;
   struct userrec *u = NULL;
-  int ignoring;
+  bool ignoring = match_ignore(from);
 
-  if (msg[0] && ((strchr(CHANMETA, *msg) != NULL) ||
-      (*msg == '@')))           /* Notice to a channel, not handled here */
-    return 0;
-  ignoring = match_ignore(from);
   to = newsplit(&msg);
   fixcolon(msg);
   strcpy(uhost, from);
@@ -696,10 +699,9 @@ static void minutely_checks()
   /* Only check if we have already successfully logged in.  */
   if (server_online) {
     static int count = 4;
-    int ok = 0;
-    struct chanset_t *chan = NULL;
+    bool ok = 0;
 
-    for (chan = chanset; chan; chan = chan->next) {
+    for (register struct chanset_t *chan = chanset; chan; chan = chan->next) {
       if (channel_active(chan) && chan->channel.members == 1) {
         ok = 1;
         break;
@@ -734,17 +736,17 @@ static int gotpong(char *from, char *msg)
  */
 static void got303(char *from, char *msg)
 {
+  if (!keepnick || !strncmp(botname, origbotname, strlen(botname)))
+    return;
+
   char *tmp = NULL;
-  int ison_orig = 0;
 
-  if (!keepnick ||
-      !strncmp(botname, origbotname, strlen(botname))) {
-    return;
-  }
   newsplit(&msg);
   fixcolon(msg);
   tmp = newsplit(&msg);
   if (tmp[0] && !rfc_casecmp(botname, tmp)) {
+    bool ison_orig = 0;
+
     while ((tmp = newsplit(&msg))[0]) { /* no, it's NOT == */
       if (!rfc_casecmp(tmp, origbotname))
         ison_orig = 1;
@@ -868,10 +870,8 @@ static int goterror(char *from, char *msg)
   if (msg[0] == ':')
     msg++;       
   putlog(LOG_SERV, "*", "-ERROR from server- %s", msg);
-  if (serverror_quit) {
-    putlog(LOG_SERV, "*", "Disconnecting from server.");
-    nuke_server("Bah, stupid error messages.");
-  }
+  putlog(LOG_SERV, "*", "Disconnecting from server.");
+  nuke_server("Bah, stupid error messages.");
   return 1;
 }
 
@@ -958,10 +958,8 @@ static void eof_server(int idx)
 {
   putlog(LOG_SERV, "*", "Disconnected from %s", dcc[idx].host);
   if (ischanhub() && auth_total > 0) {
-    int i = 0;
-
     putlog(LOG_DEBUG, "*", "Removing %d auth entries.", auth_total);
-    for (i = 0; i < auth_total; i++)
+    for (int i = 0; i < auth_total; i++)
       removeauth(i);  
   }
   disconnect_server(idx, DO_LOST);
@@ -976,10 +974,8 @@ static void connect_server(void);
 
 static void kill_server(int idx, void *x)
 {
-  struct chanset_t *chan = NULL;
-
   disconnect_server(idx, NO_LOST);	/* eof_server will lostdcc() it. */
-  for (chan = chanset; chan; chan = chan->next)
+  for (struct chanset_t *chan = chanset; chan; chan = chan->next)
      clear_channel(chan, 1);
   /* A new server connection will be automatically initiated in
      about 2 seconds. */
@@ -991,7 +987,7 @@ static void timeout_server(int idx)
   disconnect_server(idx, DO_LOST);
 }
 
-static void server_activity(int, char *, int);
+static void server_activity(int, char *, size_t);
 
 static struct dcc_table SERVER_SOCKET =
 {
@@ -1007,43 +1003,7 @@ static struct dcc_table SERVER_SOCKET =
   NULL
 };
 
-int isop(char *mode)
-{
-  int state = 0, cnt = 0;
-  char *p = NULL;
-
-  p = mode;
-  while ((*p) && (*p != ' ')) {
-    if (*p == '-')
-      state = 1;
-    else if (*p == '+')
-      state = 0;
-    else if ((!state) && (*p == 'o'))
-      cnt++;
-    p++;
-  }
-  return (cnt >= 1);
-}
-
-int ismdop(char *mode)
-{
-  int state = 0, cnt = 0;
-  char *p = NULL;
-
-  p = mode;
-  while ((*p) && (*p != ' ')) {
-    if (*p == '-')
-      state = 1;
-    else if (*p == '+')
-      state = 0;
-    else if ((state) && (*p == 'o'))
-      cnt++;
-    p++;
-  }
-  return (cnt >= 3);
-}
-
-static void server_activity(int idx, char *msg, int len)
+static void server_activity(int idx, char *msg, size_t len)
 {
   char *from = NULL, *code = NULL;
 
@@ -1064,11 +1024,12 @@ static void server_activity(int idx, char *msg, int len)
     SERVER_SOCKET.timeout_val = 0;
   }
   waiting_for_awake = 0;
-  from = "";
   if (msg[0] == ':') {
     msg++;
     from = newsplit(&msg);
-  }
+  } else
+    from = "";
+ 
   code = newsplit(&msg);
 
   if (use_console_r) {
@@ -1094,10 +1055,7 @@ static int gotping(char *from, char *msg)
 
 static int gotkick(char *from, char *msg)
 {
-  char *nick = NULL;
-
-  nick = from;
-  if (rfc_casecmp(nick, botname))
+  if (!match_my_nick(from))
     /* Not my kick, I don't need to bother about it. */
     return 0;
   if (use_penalties) {
@@ -1114,10 +1072,10 @@ static int got318_369(char *, char *, int);
 static int whoispenalty(char *from, char *msg)
 {
   struct server_list *x = serverlist;
-  int i, ii;
 
   if (x && use_penalties) {
-    i = ii = 0;
+    int i = 0, ii = 0;
+
     for (; x; x = x->next) {
       if (i == curserv) {
         if ((strict_servernames == 1) || !x->realname) {
@@ -1148,13 +1106,12 @@ irc_whois(char *nick, char *format, ...)
 {
   char va_out[2001] = "";
   va_list va;
-  int idx;
 
   va_start(va, format);
   egg_vsnprintf(va_out, sizeof(va_out) - 1, format, va);
   va_end(va);
 
-  for (idx = 0; idx < dcc_total; idx++)
+  for (int idx = 0; idx < dcc_total; idx++)
     if (dcc[idx].whois[0] && !rfc_casecmp(nick, dcc[idx].whois))
       dprintf(idx, "%s\n", va_out);
 }
@@ -1272,14 +1229,13 @@ static int got369(char *from, char *msg)
 static int got318_369(char *from, char *msg, int whowas)
 {
   char *nick = NULL;
-  int idx;
 
   newsplit(&msg);
   nick = newsplit(&msg);
   fixcolon(msg);
 
   irc_whois(nick, "%s", msg);
-  for (idx = 0; idx < dcc_total; idx++) {
+  for (int idx = 0; idx < dcc_total; idx++) {
     if (dcc[idx].whois[0] && !rfc_casecmp(dcc[idx].whois, nick) &&
        ((!whowas && !dcc[idx].whowas) || (whowas && dcc[idx].whowas))) {
       dcc[idx].whois[0] = 0;
@@ -1294,13 +1250,12 @@ static int got318_369(char *from, char *msg, int whowas)
 static int got401(char *from, char *msg)
 {
   char *nick = NULL;
-  int idx;
 
   newsplit(&msg);
   nick = newsplit(&msg);
   fixcolon(msg);
   irc_whois(nick, "%s", msg);
-  for (idx = 0; idx < dcc_total; idx++)
+  for (int idx = 0; idx < dcc_total; idx++)
     if (dcc[idx].whois[0] && !rfc_casecmp(dcc[idx].whois, nick))
       dcc[idx].whowas = 1;
 

+ 118 - 138
src/mod/share.mod/share.c

@@ -39,8 +39,8 @@ struct delay_mode {
   struct chanset_t *chan;
   int plsmns;
   int mode;
-  char *mask;
   int seconds;
+  char *mask;
 };
 
 static struct delay_mode *start_delay = NULL;
@@ -63,9 +63,7 @@ static void cancel_user_xfer(int, void *);
 static void
 add_delay(struct chanset_t *chan, int plsmns, int mode, char *mask)
 {
-  struct delay_mode *d = NULL;
-
-  d = (struct delay_mode *) calloc(1, sizeof(struct delay_mode));
+  struct delay_mode *d = (struct delay_mode *) calloc(1, sizeof(struct delay_mode));
 
   d->chan = chan;
   d->plsmns = plsmns;
@@ -81,9 +79,9 @@ add_delay(struct chanset_t *chan, int plsmns, int mode, char *mask)
 static void
 del_delay(struct delay_mode *delay)
 {
-  struct delay_mode *d = NULL, *old = NULL;
+  struct delay_mode *old = NULL;
 
-  for (d = start_delay; d; old = d, d = d->next) {
+  for (struct delay_mode *d = start_delay; d; old = d, d = d->next) {
     if (d == delay) {
       if (old)
         old->next = d->next;
@@ -100,9 +98,9 @@ del_delay(struct delay_mode *delay)
 static void
 check_delay()
 {
-  struct delay_mode *d = NULL, *dnext = NULL;
+  struct delay_mode *dnext = NULL;
 
-  for (d = start_delay; d; d = dnext) {
+  for (struct delay_mode *d = start_delay; d; d = dnext) {
     dnext = d->next;
     if (d->seconds <= now) {
 #  ifdef LEAF
@@ -122,10 +120,10 @@ check_delay()
 static void
 share_stick_ban(int idx, char *par)
 {
-  char *host = NULL, *val = NULL;
-  int yn;
-
   if (dcc[idx].status & STAT_SHARE) {
+    char *host = NULL, *val = NULL;
+    bool yn;
+
     host = newsplit(&par);
     val = newsplit(&par);
     yn = atoi(val);
@@ -168,10 +166,10 @@ share_stick_ban(int idx, char *par)
 static void
 share_stick_exempt(int idx, char *par)
 {
-  char *host = NULL, *val = NULL;
-  int yn;
-
   if (dcc[idx].status & STAT_SHARE) {
+    char *host = NULL, *val = NULL;
+    bool yn;
+
     host = newsplit(&par);
     val = newsplit(&par);
     yn = atoi(val);
@@ -203,10 +201,10 @@ share_stick_exempt(int idx, char *par)
 static void
 share_stick_invite(int idx, char *par)
 {
-  char *host = NULL, *val = NULL;
-  int yn;
-
   if (dcc[idx].status & STAT_SHARE) {
+    char *host = NULL, *val = NULL;
+    bool yn;
+
     host = newsplit(&par);
     val = newsplit(&par);
     yn = atoi(val);
@@ -236,10 +234,10 @@ share_stick_invite(int idx, char *par)
 static void
 share_chhand(int idx, char *par)
 {
-  char *hand = NULL;
-  struct userrec *u = NULL;
-
   if (dcc[idx].status & STAT_SHARE) {
+    char *hand = NULL;
+    struct userrec *u = NULL;
+
     hand = newsplit(&par);
     u = get_user_by_handle(userlist, hand);
     if (u) {
@@ -255,13 +253,13 @@ share_chhand(int idx, char *par)
 static void
 share_chattr(int idx, char *par)
 {
-  char *hand = NULL, *atr = NULL, s[100] = "";
-  struct chanset_t *cst = NULL;
-  struct userrec *u = NULL;
-  struct flag_record fr2;
-  flag_t ofl;
-
   if (dcc[idx].status & STAT_SHARE) {
+    char *hand = NULL, *atr = NULL, s[100] = "";
+    struct chanset_t *cst = NULL;
+    struct userrec *u = NULL;
+    struct flag_record fr2;
+    flag_t ofl;
+
     hand = newsplit(&par);
     u = get_user_by_handle(userlist, hand);
     if (u) {
@@ -319,11 +317,11 @@ share_chattr(int idx, char *par)
 static void
 share_pls_chrec(int idx, char *par)
 {
-  char *user = NULL;
-  struct chanset_t *chan = NULL;
-  struct userrec *u = NULL;
-
   if (dcc[idx].status & STAT_SHARE) {
+    char *user = NULL;
+    struct chanset_t *chan = NULL;
+    struct userrec *u = NULL;
+
     user = newsplit(&par);
     if ((u = get_user_by_handle(userlist, user))) {
       chan = findchan_by_dname(par);
@@ -341,11 +339,11 @@ share_pls_chrec(int idx, char *par)
 static void
 share_mns_chrec(int idx, char *par)
 {
-  char *user = NULL;
-  struct chanset_t *chan = NULL;
-  struct userrec *u = NULL;
-
   if (dcc[idx].status & STAT_SHARE) {
+    char *user = NULL;
+    struct chanset_t *chan = NULL;
+    struct userrec *u = NULL;
+
     user = newsplit(&par);
     if ((u = get_user_by_handle(userlist, user))) {
       chan = findchan_by_dname(par);
@@ -361,21 +359,22 @@ share_mns_chrec(int idx, char *par)
 static void
 share_newuser(int idx, char *par)
 {
-  char *nick = NULL, *host = NULL, *pass = NULL, s[100] = "";
-  struct userrec *u = NULL;
-
   if (dcc[idx].status & STAT_SHARE) {
-    int isbot = 0;
+    char *nick = NULL, *host = NULL, *pass = NULL;
+    bool isbot = 0;
+    struct userrec *u = NULL;
 
     nick = newsplit(&par);
     host = newsplit(&par);
     pass = newsplit(&par);
     
     if (nick[0] == '-') {
-      isbot++;
+      isbot = 1;
       nick++;
     }    
     if (!(u = get_user_by_handle(userlist, nick))) {
+      char s[100] = "";
+
       fr.global = 0;
 
       fr.match = FR_GLOBAL;
@@ -392,7 +391,7 @@ share_newuser(int idx, char *par)
       build_flags(s, &fr, 0);
 /* FIXME: remove after 1.2 */
       if (fr.global & USER_BOT) {
-        isbot++;
+        isbot = 1;
         fr.global &= ~USER_BOT;
       }
 
@@ -432,10 +431,10 @@ share_killuser(int idx, char *par)
 static void
 share_pls_host(int idx, char *par)
 {
-  char *hand = NULL;
-  struct userrec *u = NULL;
-
   if (dcc[idx].status & STAT_SHARE) {
+    char *hand = NULL;
+    struct userrec *u = NULL;
+
     hand = newsplit(&par);
     if ((u = get_user_by_handle(userlist, hand))) {
       shareout_but(idx, "+h %s %s\n", hand, par);
@@ -478,10 +477,10 @@ share_pls_bothost(int idx, char *par)
 static void
 share_mns_host(int idx, char *par)
 {
-  char *hand = NULL;
-  struct userrec *u = NULL;
-
   if (dcc[idx].status & STAT_SHARE) {
+    char *hand = NULL;
+    struct userrec *u = NULL;
+
     hand = newsplit(&par);
     if ((u = get_user_by_handle(userlist, hand))) {
       shareout_but(idx, "-h %s %s\n", hand, par);
@@ -500,12 +499,12 @@ share_mns_host(int idx, char *par)
 static void
 share_change(int idx, char *par)
 {
-  char *key = NULL, *hand = NULL;
-  struct userrec *u = NULL;
-  struct user_entry_type *uet = NULL;
-  struct user_entry *e = NULL;
-
   if (dcc[idx].status & STAT_SHARE) {
+    char *key = NULL, *hand = NULL;
+    struct userrec *u = NULL;
+    struct user_entry_type *uet = NULL;
+    struct user_entry *e = NULL;
+
     key = newsplit(&par);
     hand = newsplit(&par);
 
@@ -550,11 +549,11 @@ share_change(int idx, char *par)
 static void
 share_chchinfo(int idx, char *par)
 {
-  char *hand = NULL, *chan = NULL;
-  struct chanset_t *cst = NULL;
-  struct userrec *u = NULL;
-
   if (dcc[idx].status & STAT_SHARE) {
+    char *hand = NULL, *chan = NULL;
+    struct chanset_t *cst = NULL;
+    struct userrec *u = NULL;
+
     hand = newsplit(&par);
     if ((u = get_user_by_handle(userlist, hand))) {
       chan = newsplit(&par);
@@ -631,10 +630,10 @@ share_mns_invite(int idx, char *par)
 static void
 share_mns_banchan(int idx, char *par)
 {
-  char *chname = NULL;
-  struct chanset_t *chan = NULL;
-
   if (dcc[idx].status & STAT_SHARE) {
+    char *chname = NULL;
+    struct chanset_t *chan = NULL;
+
     chname = newsplit(&par);
     chan = findchan_by_dname(chname);
     shareout_but(idx, "-bc %s %s\n", chname, par);
@@ -655,10 +654,10 @@ share_mns_banchan(int idx, char *par)
 static void
 share_mns_exemptchan(int idx, char *par)
 {
-  char *chname = NULL;
-  struct chanset_t *chan = NULL;
-
   if (dcc[idx].status & STAT_SHARE) {
+    char *chname = NULL;
+    struct chanset_t *chan = NULL;
+
     chname = newsplit(&par);
     chan = findchan_by_dname(chname);
     shareout_but(idx, "-ec %s %s\n", chname, par);
@@ -680,10 +679,10 @@ share_mns_exemptchan(int idx, char *par)
 static void
 share_mns_invitechan(int idx, char *par)
 {
-  char *chname = NULL;
-  struct chanset_t *chan = NULL;
-
   if (dcc[idx].status & STAT_SHARE) {
+    char *chname = NULL;
+    struct chanset_t *chan = NULL;
+
     chname = newsplit(&par);
     chan = findchan_by_dname(chname);
     shareout_but(idx, "-invc %s %s\n", chname, par);
@@ -718,15 +717,11 @@ share_mns_ignore(int idx, char *par)
 static void
 share_pls_ban(int idx, char *par)
 {
-#ifdef LEAF
-  struct chanset_t *chan = NULL;
-#endif /* LEAF */
-  time_t expire_time;
-  char *ban = NULL, *tm = NULL, *from = NULL;
-  int flags = 0;
-
   if (dcc[idx].status & STAT_SHARE) {
-    int stick = 0;
+    time_t expire_time;
+    char *ban = NULL, *tm = NULL, *from = NULL;
+    int flags = 0;
+    bool stick = 0;
 
     shareout_but(idx, "+b %s\n", par);
     noshare = 1;
@@ -748,7 +743,7 @@ share_pls_ban(int idx, char *par)
     putlog(LOG_CMDS, "@", "%s: global ban %s (%s:%s)", dcc[idx].nick, ban, from, par);
     noshare = 0;
 #ifdef LEAF
-    for (chan = chanset; chan != NULL; chan = chan->next)
+    for (struct chanset_t *chan = chanset; chan != NULL; chan = chan->next)
       check_this_ban(chan, ban, stick);
 #endif /* LEAF */
   }
@@ -757,13 +752,12 @@ share_pls_ban(int idx, char *par)
 static void
 share_pls_banchan(int idx, char *par)
 {
-  time_t expire_time;
-  int flags = 0;
-  struct chanset_t *chan = NULL;
-  char *ban = NULL, *tm = NULL, *chname = NULL, *from = NULL;
-
   if (dcc[idx].status & STAT_SHARE) {
-    int stick = 0;
+    time_t expire_time;
+    int flags = 0;
+    char *ban = NULL, *tm = NULL, *chname = NULL, *from = NULL;
+    bool stick = 0;
+    struct chanset_t *chan = NULL;
 
     ban = newsplit(&par);
     tm = newsplit(&par);
@@ -797,15 +791,11 @@ share_pls_banchan(int idx, char *par)
 static void
 share_pls_exempt(int idx, char *par)
 {
-  time_t expire_time;
-  char *exempt = NULL, *tm = NULL, *from = NULL;
-  int flags = 0;
-
   if (dcc[idx].status & STAT_SHARE) {
-#ifdef LEAF
-    struct chanset_t *chan = NULL;
-#endif /* LEAF */
-    int stick = 0;
+    time_t expire_time;
+    char *exempt = NULL, *tm = NULL, *from = NULL;
+    int flags = 0;
+    bool stick = 0;
 
     shareout_but(idx, "+e %s\n", par);
     noshare = 1;
@@ -827,7 +817,7 @@ share_pls_exempt(int idx, char *par)
     putlog(LOG_CMDS, "@", "%s: global exempt %s (%s:%s)", dcc[idx].nick, exempt, from, par);
     noshare = 0;
 #ifdef LEAF
-    for (chan = chanset; chan != NULL; chan = chan->next)
+    for (struct chanset_t *chan = chanset; chan != NULL; chan = chan->next)
       check_this_exempt(chan, exempt, stick);
 #endif /* LEAF */
   }
@@ -838,13 +828,12 @@ share_pls_exempt(int idx, char *par)
 static void
 share_pls_exemptchan(int idx, char *par)
 {
-  time_t expire_time;
-  int flags = 0;
-  struct chanset_t *chan = NULL;
-  char *exempt = NULL, *tm = NULL, *chname = NULL, *from = NULL;
-
   if (dcc[idx].status & STAT_SHARE) {
-    int stick = 0;
+    time_t expire_time;
+    int flags = 0;
+    struct chanset_t *chan = NULL;
+    char *exempt = NULL, *tm = NULL, *chname = NULL, *from = NULL;
+    bool stick = 0;
 
     exempt = newsplit(&par);
     tm = newsplit(&par);
@@ -878,15 +867,11 @@ share_pls_exemptchan(int idx, char *par)
 static void
 share_pls_invite(int idx, char *par)
 {
-  time_t expire_time;
-  char *invite = NULL, *tm = NULL, *from = NULL;
-  int flags = 0;
-
   if (dcc[idx].status & STAT_SHARE) {
-#ifdef LEAF
-    struct chanset_t *chan = NULL;
-#endif /* LEAF */
-    int stick = 0;
+    time_t expire_time;
+    char *invite = NULL, *tm = NULL, *from = NULL;
+    int flags = 0;
+    bool stick = 0;
 
     shareout_but(idx, "+inv %s\n", par);
     noshare = 1;
@@ -908,7 +893,7 @@ share_pls_invite(int idx, char *par)
     putlog(LOG_CMDS, "@", "%s: global invite %s (%s:%s)", dcc[idx].nick, invite, from, par);
     noshare = 0;
 #ifdef LEAF
-    for (chan = chanset; chan != NULL; chan = chan->next)
+    for (struct chanset_t *chan = chanset; chan != NULL; chan = chan->next)
       check_this_invite(chan, invite, stick);
 #endif /* LEAF */
   }
@@ -919,13 +904,12 @@ share_pls_invite(int idx, char *par)
 static void
 share_pls_invitechan(int idx, char *par)
 {
-  time_t expire_time;
-  int flags = 0;
-  struct chanset_t *chan = NULL;
-  char *invite = NULL, *tm = NULL, *chname = NULL, *from = NULL;
-
   if (dcc[idx].status & STAT_SHARE) {
-    int stick = 0;
+    time_t expire_time;
+    int flags = 0;
+    struct chanset_t *chan = NULL;
+    char *invite = NULL, *tm = NULL, *chname = NULL, *from = NULL;
+    bool stick = 0;
 
     invite = newsplit(&par);
     tm = newsplit(&par);
@@ -959,10 +943,10 @@ share_pls_invitechan(int idx, char *par)
 static void
 share_pls_ignore(int idx, char *par)
 {
-  time_t expire_time;
-  char *ign = NULL, *from = NULL, *ts = NULL;
-
   if (dcc[idx].status & STAT_SHARE) {
+    time_t expire_time;
+    char *ign = NULL, *from = NULL, *ts = NULL;
+
     shareout_but(idx, "+i %s\n", par);
     noshare = 1;
     ign = newsplit(&par);
@@ -1017,14 +1001,14 @@ share_ufyes(int idx, char *par)
 static void
 share_userfileq(int idx, char *par)
 {
-  int ok = 1, i;
-
   if (bot_aggressive_to(dcc[idx].user)) {
     putlog(LOG_ERRORS, "*", "%s offered user transfer - I'm supposed to be aggressive to it", dcc[idx].nick);
     dprintf(idx, "s un I have you marked for Agressive sharing.\n");
     botunlink(-2, dcc[idx].nick, "I'm aggressive to you");
   } else {
-    for (i = 0; i < dcc_total; i++)
+    bool ok = 1;
+
+    for (int i = 0; i < dcc_total; i++)
       if (dcc[i].type->flags & DCT_BOT) {
         if ((dcc[i].status & STAT_SHARE) && (dcc[i].status & STAT_AGGRESSIVE) && (i != idx)) {
           ok = 0;
@@ -1054,7 +1038,8 @@ share_ufsend(int idx, char *par)
 {
   char *ip = NULL, *port = NULL;
   char s[1024] = "";
-  int i, sock;
+  int i;
+  sock_t sock;
   FILE *f = NULL;
 
   egg_snprintf(s, sizeof s, "%s.share.%s.%li.users", tempdir, conf.bot->nick, now);
@@ -1109,18 +1094,16 @@ share_version(int idx, char *par)
   if (bot_aggressive_to(dcc[idx].user)) {
     dprintf(idx, "s u?\n");
     dcc[idx].status |= STAT_OFFERED;
-  }                             /*else
-                                 * higher_bot_linked(idx); */
+  }
+  // else higher_bot_linked(idx);
 }
 
 #ifdef HUB
 void
 hook_read_userfile()
 {
-  int i;
-
   if (!noshare) {
-    for (i = 0; i < dcc_total; i++)
+    for (int i = 0; i < dcc_total; i++) {
       if ((dcc[i].type->flags & DCT_BOT) && (dcc[i].status & STAT_SHARE) && !(dcc[i].status & STAT_AGGRESSIVE)
           && (1)) {
         /* Cancel any existing transfers */
@@ -1129,6 +1112,7 @@ hook_read_userfile()
         dprintf(i, "s u?\n");
         dcc[i].status |= STAT_OFFERED;
       }
+    }
   }
 }
 #endif /* HUB */
@@ -1200,12 +1184,11 @@ static botcmd_t C_share[] = {
 void
 sharein(int idx, char *msg)
 {
-  char *code = NULL;
-  int f, i;
+  char *code = newsplit(&msg);
+  int y, f = 0, i = 0;
 
-  code = newsplit(&msg);
   for (f = 0, i = 0; C_share[i].name && !f; i++) {
-    int y = egg_strcasecmp(code, C_share[i].name);
+    y = egg_strcasecmp(code, C_share[i].name);
 
     if (!y)
       /* Found a match */
@@ -1218,8 +1201,8 @@ sharein(int idx, char *msg)
 void
 shareout(const char *format, ...)
 {
-  int i, l;
   char s[601] = "";
+  int l;
   va_list va;
 
   va_start(va, format);
@@ -1229,16 +1212,17 @@ shareout(const char *format, ...)
     s[2 + (l = 509)] = 0;
   va_end(va);
 
-  for (i = 0; i < dcc_total; i++)
+  for (int i = 0; i < dcc_total; i++) {
     if ((dcc[i].type->flags & DCT_BOT) && (dcc[i].status & STAT_SHARE) && !(dcc[i].status & (STAT_GETTING | STAT_SENDING))) {
       tputs(dcc[i].sock, s, l + 2);
     }
+  }
 }
 
 static void
 shareout_but(int x, const char *format, ...)
 {
-  int i, l;
+  int l;
   char s[601] = "";
   va_list va;
 
@@ -1249,7 +1233,7 @@ shareout_but(int x, const char *format, ...)
     s[2 + (l = 509)] = 0;
   va_end(va);
 
-  for (i = 0; i < dcc_total; i++)
+  for (int i = 0; i < dcc_total; i++)
     if ((dcc[i].type->flags & DCT_BOT) && (i != x) &&
         (dcc[i].status & STAT_SHARE) && (!(dcc[i].status & STAT_GETTING)) &&
         (!(dcc[i].status & STAT_SENDING))) {
@@ -1263,10 +1247,8 @@ shareout_but(int x, const char *format, ...)
 static void
 check_expired_tbufs()
 {
-  int i;
-
   /* Resend userfile requests */
-  for (i = 0; i < dcc_total; i++) {
+  for (int i = 0; i < dcc_total; i++) {
     if (dcc[i].type->flags & DCT_BOT) {
       if (dcc[i].status & STAT_OFFERED) {
         if (now - dcc[i].timeval > 120) {
@@ -1285,19 +1267,17 @@ check_expired_tbufs()
   }
 }
 
-static int
+static bool
 write_tmp_userfile(char *fn, const struct userrec *bu, int idx)
 {
   FILE *f = NULL;
-  struct userrec *u = NULL;
   int ok = 0;
 
   if ((f = fopen(fn, "wb"))) {
-    time_t tt;
+    time_t tt = now;
     char s1[81] = "";
 
     fixmod(fn);
-    tt = now;
     strcpy(s1, ctime(&tt));
     lfprintf(f, "#4v: %s -- %s -- written %s", ver, conf.bot->nick, s1);
 
@@ -1308,7 +1288,7 @@ write_tmp_userfile(char *fn, const struct userrec *bu, int idx)
     ok += write_invites(f, idx);
     if (ok != 5)
       ok = 0;
-    for (u = (struct userrec *) bu; u && ok; u = u->next) {
+    for (struct userrec *u = (struct userrec *) bu; u && ok; u = u->next) {
       if (!write_user(u, f, idx))
         ok = 0;
     }
@@ -1499,7 +1479,7 @@ start_sending_users(int idx)
     dcc[idx].status |= STAT_SENDING;
     i = dcc_total - 1;
     strcpy(dcc[i].host, dcc[idx].nick); /* Store bot's nick */
-    dprintf(idx, "s us %lu %d %lu\n", iptolong(natip[0] ? (IP) inet_addr(natip) : getmyip()), dcc[i].port,
+    dprintf(idx, "s us %lu %d %u\n", iptolong(natip[0] ? (in_addr_t) inet_addr(natip) : getmyip()), dcc[i].port,
             dcc[i].u.xfer->length);
 
     /* Unlink the file. We don't really care whether this causes problems

+ 23 - 23
src/mod/transfer.mod/transfer.c

@@ -33,13 +33,13 @@
 extern int		bupdating;
 
 #ifdef HUB
-static int copy_to_tmp = 1;	/* Copy files to /tmp before transmitting? */
+static bool copy_to_tmp = 1;	/* Copy files to /tmp before transmitting? */
 #endif /* HUB */
-static int wait_dcc_xfer = 40;	/* Timeout time on DCC xfers */
+static time_t wait_dcc_xfer = 40;	/* Timeout time on DCC xfers */
 static int dcc_limit = 4;	/* Maximum number of simultaneous file
 				   downloads allowed */
-static unsigned int dcc_block = 0;	/* Size of one dcc block */
-static int quiet_reject = 1;        /* Quietly reject dcc chat or sends from
+static size_t dcc_block = 0;	/* Size of one dcc block */
+static bool quiet_reject = 1;        /* Quietly reject dcc chat or sends from
                                    users without access? */
 
 /*
@@ -48,7 +48,7 @@ static int quiet_reject = 1;        /* Quietly reject dcc chat or sends from
 #ifdef HUB
 static void wipe_tmp_filename(char *, int);
 static int at_limit(char *);
-static void dcc_get_pending(int, char *, int);
+static void dcc_get_pending(int, char *, size_t);
 #endif /* HUB */
 
 static fileq_t *fileq = NULL;
@@ -501,12 +501,12 @@ inline static void handle_resend_packet(int idx, transfer_reget *reget_data)
  * Note: The first received packet during reget is a special 8 bit packet
  *       containing special information.
  */
-void dcc_get(int idx, char *buf, int len)
+void dcc_get(int idx, char *buf, size_t len)
 {
   char xnick[NICKLEN] = "";
   unsigned char bbuf[4] = "";
   unsigned long cmp, l;
-  int w = len + dcc[idx].u.xfer->sofar, p = 0;
+  size_t w = len + dcc[idx].u.xfer->sofar, p = 0;
 
   dcc[idx].timeval = now;		/* Mark as active		*/
 
@@ -723,10 +723,10 @@ void eof_dcc_get(int idx)
 }
 #endif /* HUB */
 
-void dcc_send(int idx, char *buf, int len)
+void dcc_send(int idx, char *buf, size_t len)
 {
   char s[SGRAB + 2] = "", *b = NULL;
-  unsigned long sent;
+  size_t sent;
 
   fwrite(buf, len, 1, dcc[idx].u.xfer->f);
 
@@ -895,8 +895,7 @@ void display_dcc_get(int idx, char *buf)
 
 void display_dcc_get_p(int idx, char *buf)
 {
-  sprintf(buf,TRANSFER_SEND_WAITED, now - dcc[idx].timeval,
-	  dcc[idx].u.xfer->origname);
+  sprintf(buf,TRANSFER_SEND_WAITED, now - dcc[idx].timeval, dcc[idx].u.xfer->origname);
 }
 #endif /* HUB */
 
@@ -953,7 +952,7 @@ struct dcc_table DCC_SEND =
   NULL
 };
 
-void dcc_fork_send(int idx, char *x, int y);
+void dcc_fork_send(int idx, char *x, size_t y);
 
 struct dcc_table DCC_FORK_SEND =
 {
@@ -969,12 +968,13 @@ struct dcc_table DCC_FORK_SEND =
   NULL
 };
 
-void dcc_fork_send(int idx, char *x, int y)
+void dcc_fork_send(int idx, char *x, size_t y)
 {
-  char s1[121] = "";
-
   if (dcc[idx].type != &DCC_FORK_SEND)
     return;
+
+  char s1[121] = "";
+
   dcc[idx].type = &DCC_SEND;
   dcc[idx].status = 0;
   dcc[idx].u.xfer->start_time = now;
@@ -1012,11 +1012,11 @@ struct dcc_table DCC_GET_PENDING =
   NULL
 };
 
-static void dcc_get_pending(int idx, char *buf, int len)
+static void dcc_get_pending(int idx, char *buf, size_t len)
 {
-  IP ip;
+  in_addr_t ip;
   port_t port;
-  int i;
+  sock_t i;
   char s[UHOSTLEN] = "";
 
   i = answer(dcc[idx].sock, s, &ip, &port, 1);
@@ -1043,7 +1043,7 @@ static void dcc_get_pending(int idx, char *buf, int len)
 
   /* Are we resuming? */
   if (dcc[idx].u.xfer->type == XFER_RESUME_PEND) {
-    long unsigned int l;
+    size_t l;
 
     if (dcc_block == 0 || dcc[idx].u.xfer->length < dcc_block) {
       l = dcc[idx].u.xfer->length - dcc[idx].u.xfer->offset;
@@ -1087,14 +1087,14 @@ static void dcc_get_pending(int idx, char *buf, int len)
 
 static int raw_dcc_resend_send(char *filename, char *nick, char *from, char *dir, int resend)
 {
-  int zz, i;
+  sock_t zz = -1;
+  int i;
   port_t port;
   char *nfn = NULL, *buf = NULL;
   long dccfilesize;
   FILE *f = NULL, *dccfile = NULL;
  
   sdprintf("raw_dcc_resend_send()");
-  zz = (-1);
   dccfile = fopen(filename, "rb");
   if (!dccfile) {
     putlog(LOG_MISC, "*", "Failed to open %s: %s", filename, strerror(errno));
@@ -1137,7 +1137,7 @@ static int raw_dcc_resend_send(char *filename, char *nick, char *from, char *dir
   if ((i = new_dcc(&DCC_GET_PENDING, sizeof(struct xfer_info))) == -1)
      return DCCSEND_FULL;
   dcc[i].sock = zz;
-  dcc[i].addr = (IP) (-559026163);
+  dcc[i].addr = (in_addr_t) (-559026163);
   dcc[i].port = port;
   strcpy(dcc[i].nick, nick);
   strcpy(dcc[i].host, "irc");
@@ -1156,7 +1156,7 @@ static int raw_dcc_resend_send(char *filename, char *nick, char *from, char *dir
   if (nick[0] != '*') {
     dprintf(DP_HELP, "PRIVMSG %s :\001DCC %sSEND %s %lu %d %lu\001\n", nick,
 	    resend ? "RE" :  "", nfn,
-	    iptolong(natip[0] ? (IP) inet_addr(natip) : getmyip()), port,
+	    iptolong(natip[0] ? (in_addr_t) inet_addr(natip) : getmyip()), port,
 	    dccfilesize);
     putlog(LOG_FILES, "*",TRANSFER_BEGIN_DCC, resend ? TRANSFER_RE :  "",
 	   nfn, nick);

+ 6 - 6
src/mod/transfer.mod/transfer.h

@@ -74,7 +74,7 @@ typedef struct zarrf {
 #define TRANSFER_CANCELLED          "Cancelled: %s to %s\n"
 #define TRANSFER_ABORT_DCCSEND      "Cancelled: %s  (aborted dcc send)\n"
 #define TRANSFER_NOTICE_ABORT       "NOTICE %s :Transfer of %s aborted by %s\n"
-#define TRANSFER_DCC_CANCEL         "DCC cancel: GET %s (%s) at %lu/%lu"
+#define TRANSFER_DCC_CANCEL         "DCC cancel: GET %s (%s) at %zu/%zu"
 #define TRANSFER_NO_MATCHES         "No matches.\n"
 #define TRANSFER_CANCELLED_FILE     "Cancelled %d file%s.\n"
 #define TRANSFER_COMPLETED_DCC      "Completed dcc send %s from %s!%s"
@@ -88,7 +88,7 @@ typedef struct zarrf {
 #define TRANSFER_USERFILE_LOST      "Lost userfile transfer from %s; aborting."
 /* #define TRANSFER_BYE	            "0xf1e) */
 #define TRANSFER_USERFILE_DISCON    "Disconnected %s (aborted userfile transfer)"
-#define TRANSFER_LOST_DCCSEND       "Lost dcc send %s from %s!%s (%lu/%lu)"
+#define TRANSFER_LOST_DCCSEND       "Lost dcc send %s from %s!%s (%zu/%zu)"
 #define TRANSFER_REGET_PACKET       "(!) reget packet from %s for %s is invalid!"
 #define TRANSFER_BEHIND_FILEEND     "!! Resuming file transfer behind file end for %s to %s"
 #define TRANSFER_TRY_SKIP_AHEAD     "!!! Trying to skip ahead on userfile transfer"
@@ -103,10 +103,10 @@ typedef struct zarrf {
 #define TRANSFER_DICONNECT_TIMEOUT  "Disconnected %s (timed-out userfile transfer)"
 #define TRANSFER_NOTICE_TIMEOUT     "NOTICE %s :Timeout during transfer, aborting %s.\n"
 #define TRANSFER_LOG_TIMEOUT        "EGGDROP TEAM IS TEH GAY"
-#define TRANSFER_DCC_GET_TIMEOUT    "DCC timeout: GET %s (%s) at %lu/%lu"
-#define TRANSFER_DCC_SEND_TIMEOUT   "DCC timeout: SEND %s (%s) at %lu/%lu"
-#define TRANSFER_SEND               "send  (%lu)/%lu\n    Filename: %s\n"
-#define TRANSFER_SEND_WAITED        "send  waited %lus\n    Filename: %s\n"
+#define TRANSFER_DCC_GET_TIMEOUT    "DCC timeout: GET %s (%s) at %zu/%zu"
+#define TRANSFER_DCC_SEND_TIMEOUT   "DCC timeout: SEND %s (%s) at %zu/%zu"
+#define TRANSFER_SEND               "send  (%zu)/%zu\n    Filename: %s\n"
+#define TRANSFER_SEND_WAITED        "send  waited %lis\n    Filename: %s\n"
 #define TRANSFER_CONN_SEND          "conn  send"
 #define TRANSFER_DCC_CONN           "DCC connection: SEND %s (%s)"
 #define TRANSFER_NOTICE_BAD_CONN    "NOTICE %s :Bad connection (%s)\n"

+ 13 - 15
src/mod/update.mod/update.c

@@ -164,8 +164,8 @@ static botcmd_t C_update[] =
 
 static void got_nu(char *botnick, char *code, char *par)
 {
-/* needupdate? curver */
-  time_t newts;
+  if (!par || !*par) 
+    return;
 #ifdef LEAF
   if (!conf.bot->u || !userlist || !get_user_by_handle(userlist, botnick))	/* probably still getting userfile */
     return;
@@ -179,9 +179,10 @@ static void got_nu(char *botnick, char *code, char *par)
   if (localhub && updated)
     return;
 #endif /* LEAF */
-   if (!par || !*par) 
-     return;
-   newts = atol(newsplit(&par));
+
+/* needupdate? curver */
+   time_t newts = atol(newsplit(&par));
+
    if (newts > buildts) {
 #ifdef LEAF
      struct bot_addr *bi = NULL, *obi = NULL;
@@ -216,12 +217,11 @@ static cmd_t update_bot[] = {
 
 void updatein(int idx, char *msg)
 {
-  char *code = NULL;
-  int f, i;
+  char *code = newsplit(&msg);
+  int y, f = 0, i = 0;
 
-  code = newsplit(&msg);
   for (f = 0, i = 0; C_update[i].name && !f; i++) {
-    int y = egg_strcasecmp(code, C_update[i].name);
+    y = egg_strcasecmp(code, C_update[i].name);
 
     if (!y)
       /* Found a match */
@@ -258,7 +258,7 @@ void finish_update(int idx)
     FILE *f = NULL;
     f = fopen(dcc[idx].u.xfer->filename, "rb");
     fseek(f, 0, SEEK_END);
-    putlog(LOG_DEBUG, "*", "Update binary is %lu bytes and its length: %lu status: %lu", ftell(f), dcc[idx].u.xfer->length, dcc[idx].u.xfer->length);
+    putlog(LOG_DEBUG, "*", "Update binary is %li bytes and its length: %zu status: %zu", ftell(f), dcc[idx].u.xfer->length, dcc[idx].u.xfer->length);
     fclose(f);
   }
 
@@ -350,8 +350,8 @@ static void start_sending_binary(int idx)
     dcc[idx].status |= STAT_SENDINGU;
     i = dcc_total - 1;
     strcpy(dcc[i].host, dcc[idx].nick);		/* Store bot's nick */
-    dprintf(idx, "sb us %lu %d %lu\n",
-	    iptolong(natip[0] ? (IP) inet_addr(natip) : getmyip()),
+    dprintf(idx, "sb us %lu %hd %zu\n",
+	    iptolong(natip[0] ? (in_addr_t) inet_addr(natip) : getmyip()),
 	    dcc[i].port, dcc[i].u.xfer->length);
   }
 #endif /* HUB */
@@ -443,9 +443,7 @@ void update_report(int idx, int details)
 #ifdef HUB
 static void cmd_bupdate(int idx, char *par)
 {
-  int i;
-
-  for (i = 0; i < dcc_total; i++) {
+  for (int i = 0; i < dcc_total; i++) {
     if (!egg_strcasecmp(dcc[i].nick, par)) {
       dprintf(i, "sb u?\n");
       dcc[i].status &= ~(STAT_SENDINGU | STAT_UPDATED);

+ 130 - 176
src/net.c

@@ -46,7 +46,7 @@ union sockaddr_union cached_myip4_so;
 union sockaddr_union cached_myip6_so;
 #endif /* USE_IPV6 */
 
-int     identd_hack = 0;	/* identd_open() won't work on most servers, dont even bother warning. */
+bool    identd_hack = 0;	/* identd_open() won't work on most servers, dont even bother warning. */
 char	firewall[121] = "";	/* Socks server for firewall		    */
 port_t	firewallport = 1080;	/* Default port of Sock4/5 firewalls	    */
 char	botuser[21] = ""; 	/* Username of the user running the bot    */
@@ -78,22 +78,20 @@ unsigned long my_atoul(char *s)
 int hostprotocol(char *host)
 {
 #ifdef USE_IPV6
-  struct hostent *he = NULL;
-#  ifndef HAVE_GETHOSTBYNAME2
-  int error_num;
-#  endif /* !HAVE_GETHOSTBYNAME2 */
-
   if (!host || (host && !host[0]))
     return 0;
 
+  struct hostent *he = NULL;
+
   if (!setjmp(alarmret)) {
     alarm(resolve_timeout);
 
-#  ifdef HAVE_GETHOSTBYNAME2
+#   ifdef HAVE_GETHOSTBYNAME2
     he = gethostbyname2(host, AF_INET6);
-#  else
+#   else
+    int error_num;
     he = getipnodebyname(host, AF_INET6, AI_DEFAULT, &error_num);
-#  endif /* HAVE_GETHOSTBYNAME2 */
+#   endif /* HAVE_GETHOSTBYNAME2 */
     alarm(0);
   } else
     he = NULL;
@@ -106,11 +104,12 @@ int hostprotocol(char *host)
 }
 
 /* get the protocol used on a socket */
-int sockprotocol(int sock)
+int sockprotocol(sock_t sock)
 {
   struct sockaddr sa;
   socklen_t socklen = sizeof(sa);
 
+  egg_bzero(&sa, socklen);
   if (getsockname(sock, &sa, &socklen))
     return -1;
   else
@@ -120,19 +119,16 @@ int sockprotocol(int sock)
 /* AF_INET-independent resolving routine */
 int get_ip(char *hostname, union sockaddr_union *so)
 {
-#ifdef USE_IPV6
-  struct addrinfo hints, *ai = NULL, *res = NULL;
-  int error = 0;
-#else
-  struct hostent *hp = NULL;
-#endif /* USE_IPV6 */
+  if (!hostname || (hostname && !hostname[0]))
+    return 1;
 
   egg_memset(so, 0, sizeof(union sockaddr_union));
   debug1("get_ip(%s)", hostname);
 
-  if (!hostname || (hostname && !hostname[0]))
-    return 1;
 #ifdef USE_IPV6
+  struct addrinfo hints, *ai = NULL, *res = NULL;
+  int error = 0;
+
   egg_memset(&hints, 0, sizeof(struct addrinfo));
   hints.ai_socktype = SOCK_STREAM;
 
@@ -155,6 +151,7 @@ int get_ip(char *hostname, union sockaddr_union *so)
     freeaddrinfo(res);
   return error;
 #else
+  struct hostent *hp = NULL;
 
   if (!(hp = gethostbyname(hostname)))
     return -1;
@@ -202,9 +199,7 @@ int seed_PRNG(void)
  */
 void init_net()
 {
-  int i;
-
-  for (i = 0; i < MAXSOCKS; i++) {
+  for (int i = 0; i < MAXSOCKS; i++) {
     egg_bzero(&socklist[i], sizeof(socklist[i]));
 #ifdef HAVE_SSL
     socklist[i].ssl=NULL;
@@ -265,23 +260,21 @@ char *myipstr(int af_type)
 
 /* Get my ip number
  */
-IP getmyip() {
-  return (IP) cached_myip4_so.sin.sin_addr.s_addr;
+in_addr_t getmyip() {
+  return cached_myip4_so.sin.sin_addr.s_addr;
 }
 
 /* see if it's necessary to set inaddr_any... because if we can't resolve, we die anyway */
 void cache_my_ip()
 {
-  char s[121] = "";
-  int error;
-#ifdef USE_IPV6
-  int any = 0;
-#endif /* USE_IPV6 */
+  int error = 0;
 
   debug0("cache_my_ip()");
   egg_memset(&cached_myip4_so, 0, sizeof(union sockaddr_union));
 
 #ifdef USE_IPV6
+  bool any = 0;
+
   egg_memset(&cached_myip6_so, 0, sizeof(union sockaddr_union));
 
   if (conf.bot->ip6) {
@@ -302,7 +295,6 @@ void cache_my_ip()
   }
 #endif /* USE_IPV6 */
 
-  error = 0;
   if (conf.bot->ip) {
     if (get_ip(conf.bot->ip, &cached_myip4_so))
       error = 1;
@@ -310,6 +302,8 @@ void cache_my_ip()
     if (get_ip(conf.bot->host, &cached_myip4_so))
       error = 2;
   } else {
+    char s[121] = "";
+
     gethostname(s, sizeof(s));
     if (get_ip(s, &cached_myip4_so)) {
       /* error = 3; */
@@ -331,11 +325,9 @@ void cache_my_ip()
  *           -1  - socket not found
  *           -2  - illegal operation
  */
-int sockoptions(int sock, int operation, int sock_options)
+int sockoptions(sock_t sock, int operation, int sock_options)
 {
-  int i;
-
-  for (i = 0; i < MAXSOCKS; i++)
+  for (int i = 0; i < MAXSOCKS; i++) {
     if ((socklist[i].sock == sock) && !(socklist[i].flags & SOCK_UNUSED)) {
       if (operation == EGG_OPTION_SET)
 	      socklist[i].flags |= sock_options;
@@ -345,16 +337,15 @@ int sockoptions(int sock, int operation, int sock_options)
 	      return -2;
       return 0;
     }
+  }
   return -1;
 }
 
 /* Return a free entry in the socket entry
  */
-int allocsock(int sock, int options)
+sock_t allocsock(sock_t sock, int options)
 {
-  int i;
-
-  for (i = 0; i < MAXSOCKS; i++) {
+  for (sock_t i = 0; i < MAXSOCKS; i++) {
     if (socklist[i].flags & SOCK_UNUSED) {
       /* yay!  there is table space */
       socklist[i].inbuf = socklist[i].outbuf = NULL;
@@ -379,9 +370,10 @@ int allocsock(int sock, int options)
 
 /* Request a normal socket for i/o
  */
-void setsock(int sock, int options)
+void setsock(sock_t sock, int options)
 {
-  int i = allocsock(sock, options), parm;
+  sock_t i = allocsock(sock, options);
+  bool parm;
 
   if (((sock != STDOUT) || backgrd) && !(socklist[i].flags & SOCK_NONSOCK)) {
     parm = 1;
@@ -397,20 +389,17 @@ void setsock(int sock, int options)
   }
   /* Yay async i/o ! */
   fcntl(sock, F_SETFL, O_NONBLOCK);
-
 }
 
 #ifdef USE_IPV6
-int real_getsock(int options, int af_def, char *fname, int line)
+sock_t real_getsock(int options, int af_def, char *fname, int line)
 {
 #else
-int real_getsock(int options, char *fname, int line)
+sock_t real_getsock(int options, char *fname, int line)
 {
   int af_def = AF_INET;
 #endif /* USE_IPV6 */
-  int sock;
-
-  sock = socket(af_def, SOCK_STREAM, 0);
+  sock_t sock = socket(af_def, SOCK_STREAM, 0);
 
   if (sock >= 0)
     setsock(sock, options);
@@ -422,12 +411,12 @@ int real_getsock(int options, char *fname, int line)
 }
 
 #ifdef HAVE_SSL
-void dropssl(register int sock)
+void dropssl(register sock_t sock)
 {
-  int i;
-
   if (sock < 0)
     return;
+  sock_t i;
+
   for (i = 0; (i < MAXSOCKS); i++)
     if (socklist[i].sock == sock) break;
 
@@ -444,16 +433,14 @@ void dropssl(register int sock)
 
 /* Done with a socket
  */
-void real_killsock(register int sock, const char *file, int line)
+void real_killsock(register sock_t sock, const char *file, int line)
 {
-  register int	i;
-
   if (sock < 0) {
     putlog(LOG_ERRORS, "*", "Attempt to kill socket -1 %s:%d", file, line);
     return;
   }
 
-  for (i = 0; i < MAXSOCKS; i++) {
+  for (register int i = 0; i < MAXSOCKS; i++) {
     if ((socklist[i].sock == sock) && !(socklist[i].flags & SOCK_UNUSED)) {
 #ifdef HAVE_SSL
       dropssl(sock);
@@ -475,26 +462,21 @@ void real_killsock(register int sock, const char *file, int line)
       return;
     }
   }
-  putlog(LOG_MISC, "*", "Attempt to kill un-allocated socket %d %s:%d !!", sock, file, line);
+  putlog(LOG_MISC, "*", "Attempt to kill un-allocated socket %lu %s:%d !!", sock, file, line);
 }
 
 /* Send connection request to proxy
  */
-static int proxy_connect(int sock, char *host, int port, int proxy)
+static sock_t proxy_connect(sock_t sock, char *host, int port, int proxy)
 {
 #ifdef USE_IPV6
   unsigned char x[32] = "";
-  int af_ty;
+  int af_ty = sockprotocol(sock);
 #else
   unsigned char x[10] = "";
 #endif /* USE_IPV6 */
-  struct hostent *hp = NULL;
   char s[256] = "";
-  int i;
 
-#ifdef USE_IPV6
-  af_ty = sockprotocol(sock);
-#endif /* USE_IPV6 */
   /* socks proxy */
   if (proxy == PROXY_SOCKS) {
     /* numeric IP? */
@@ -503,9 +485,11 @@ static int proxy_connect(int sock, char *host, int port, int proxy)
 #else
     if (host[strlen(host) - 1] >= '0' && host[strlen(host) - 1] <= '9') {
 #endif /* USE_IPV6 */
-      IP ip = ((IP) inet_addr(host));
+      in_addr_t ip = ((in_addr_t) inet_addr(host));
       egg_memcpy(x, &ip, 4);
     } else {
+      struct hostent *hp = NULL;
+
       /* no, must be host.domain */
       if (!setjmp(alarmret)) {
 #ifdef USE_IPV6
@@ -526,7 +510,7 @@ static int proxy_connect(int sock, char *host, int port, int proxy)
       }
       egg_memcpy(x, hp->h_addr, hp->h_length);
     }
-    for (i = 0; i < MAXSOCKS; i++)
+    for (int i = 0; i < MAXSOCKS; i++)
       if (!(socklist[i].flags & SOCK_UNUSED) && socklist[i].sock == sock)
         socklist[i].flags |= SOCK_PROXYWAIT;    /* drummer */
 #ifdef USE_IPV6
@@ -562,12 +546,11 @@ static int proxy_connect(int sock, char *host, int port, int proxy)
  *   -1  strerror()/errno type error
  *   -2  can't resolve hostname
  */
-int open_telnet_raw(int sock, char *server, port_t sport)
+sock_t open_telnet_raw(sock_t sock, char *server, port_t sport)
 {
   static port_t port = 0;
   union sockaddr_union so;
   char host[121] = "";
-  int i, rc;
   volatile int proxy;
 
   /* firewall?  use socks */
@@ -591,6 +574,7 @@ int open_telnet_raw(int sock, char *server, port_t sport)
 
   if (!setjmp(alarmret)) {
     alarm(resolve_timeout);
+
     if (!get_ip(host, &so)) {
       alarm(0);
       /* ok, we resolved it, bind an appropriate ip */
@@ -621,7 +605,7 @@ int open_telnet_raw(int sock, char *server, port_t sport)
     }
   }
 
-  for (i = 0; i < MAXSOCKS; i++) {
+  for (int i = 0; i < MAXSOCKS; i++) {
     if (!(socklist[i].flags & SOCK_UNUSED) && (socklist[i].sock == sock)) {
       socklist[i].flags = (socklist[i].flags & ~SOCK_VIRTUAL) | SOCK_CONNECT;
       socklist[i].host = strdup(server);
@@ -629,7 +613,7 @@ int open_telnet_raw(int sock, char *server, port_t sport)
     }
   }
 
-  rc = connect(sock, &so.sa, SIZEOF_SOCKADDR(so));
+  int rc = connect(sock, &so.sa, SIZEOF_SOCKADDR(so));
   if (rc < 0) {    if (errno == EINPROGRESS) {
       /* Firewall?  announce connect attempt to proxy */
       if (firewall[0])
@@ -648,9 +632,9 @@ int open_telnet_raw(int sock, char *server, port_t sport)
 }
 
 /* Ordinary non-binary connection attempt */
-int open_telnet(char *server, port_t port)
+sock_t open_telnet(char *server, port_t port)
 {
-  int ret = -1, sock = -1;
+  sock_t sock = -1;
 
 #ifdef USE_IPV6
   sock = getsock(0, hostprotocol(server));
@@ -658,8 +642,8 @@ int open_telnet(char *server, port_t port)
   sock = getsock(0);
 #endif /* USE_IPV6 */
   if (sock >= 0)
-    ret = open_telnet_raw(sock, server, port);
-  return ret;
+    return open_telnet_raw(sock, server, port);
+  return -1;
 }
 
 /* Returns a socket number for a listening socket that will accept any
@@ -668,21 +652,21 @@ int open_telnet(char *server, port_t port)
  * 'addr' is ignored if af_def is AF_INET6 -poptix (02/03/03)
  */
 #ifdef USE_IPV6
-int open_address_listen(IP addr, int af_def, port_t *port)
+sock_t open_address_listen(in_addr_t addr, int af_def, port_t *port)
 #else
-int open_address_listen(IP addr, port_t *port)
+sock_t open_address_listen(in_addr_t addr, port_t *port)
 #endif /* USE_IPV6 */
  {
-  int sock = 0;
-  socklen_t addrlen;
-  struct sockaddr_in name;
-
   if (firewall[0]) {
     /* FIXME: can't do listen port thru firewall yet */
-    putlog(LOG_MISC, "*", "!! Cant open a listen port (you are using a "
-           "firewall)");
+    putlog(LOG_MISC, "*", "!! Cant open a listen port (you are using a firewall)");
     return -1;
   }
+
+  sock_t sock = 0;
+  socklen_t addrlen;
+  struct sockaddr_in name;
+
 #ifdef USE_IPV6
   if (af_def == AF_INET6) {
     struct sockaddr_in6 name6;
@@ -691,7 +675,7 @@ int open_address_listen(IP addr, port_t *port)
     if (sock < 1)
       return -1;
 
-    debug2("Opening listen socket on port %d with AF_INET6, sock: %d", *port, sock);
+    debug2("Opening listen socket on port %d with AF_INET6, sock: %lu", *port, sock);
     egg_bzero((char *) &name6, sizeof(name6));
     name6.sin6_family = af_def;
     name6.sin6_port = htons(*port); /* 0 = just assign us a port */
@@ -720,7 +704,7 @@ int open_address_listen(IP addr, port_t *port)
     if (sock < 1)
       return -1;
 
-    debug2("Opening listen socket on port %d with AF_INET, sock: %d", *port, sock);
+    debug2("Opening listen socket on port %d with AF_INET, sock: %lu", *port, sock);
     egg_bzero((char *) &name, sizeof(struct sockaddr_in));
     name.sin_family = AF_INET;
     name.sin_port = htons(*port); /* 0 = just assign us a port */
@@ -749,7 +733,7 @@ int open_address_listen(IP addr, port_t *port)
 /* Returns a socket number for a listening socket that will accept any
  * connection -- port # is returned in port
  */
-int open_listen(port_t *port)
+sock_t open_listen(port_t *port)
 {
 #ifdef USE_IPV6
   return open_address_listen(conf.bot->ip ? getmyip() : INADDR_ANY, AF_INET, port);
@@ -762,7 +746,7 @@ int open_listen(port_t *port)
  * the above is being left in for compatibility, and should NOT LONGER BE USED IN THE CORE CODE.
  */
 
-int open_listen_by_af(port_t *port, int af_def)
+sock_t open_listen_by_af(port_t *port, int af_def)
 {
 #ifdef USE_IPV6
   return open_address_listen(conf.bot->ip ? getmyip() : INADDR_ANY, af_def, port);
@@ -772,7 +756,7 @@ int open_listen_by_af(port_t *port, int af_def)
 }
 
 #ifdef HAVE_SSL
-int ssl_link(register int sock, int state)
+int ssl_link(register sock_t sock, int state)
 {
   int err = 0, i = 0, errs = 0;
 
@@ -838,40 +822,10 @@ int ssl_link(register int sock, int state)
 }
 #endif /* HAVE_SSL */
 
-
-/* Given a network-style IP address, returns the hostname. The hostname
- * will be in the "##.##.##.##" format if there was an error.
- * 
- * NOTE: This function is depreciated. Try using the async dns approach
- *       instead.
- */
-char *hostnamefromip(IP ip)
-{
-  struct hostent *hp = NULL;
-  IP addr = ip;
-  unsigned char *p = NULL;
-  static char s[UHOSTLEN] = "";
-
-  if (!setjmp(alarmret)) {
-    alarm(resolve_timeout);
-    hp = gethostbyaddr((char *) &addr, sizeof(addr), AF_INET);
-    alarm(0);
-  } else {
-    hp = NULL;
-  }
-  if (hp == NULL) {
-    p = (unsigned char *) &addr;
-    sprintf(s, "%u.%u.%u.%u", p[0], p[1], p[2], p[3]);
-    return s;
-  }
-  strncpyz(s, hp->h_name, sizeof s);
-  return s;
-}
-
 /* Returns the given network byte order IP address in the
  * dotted format - "##.##.##.##"
  */
-char *iptostr(IP ip)
+char *iptostr(in_addr_t ip)
 {
   static char ipbuf[32];
   struct in_addr a;
@@ -884,9 +838,9 @@ char *iptostr(IP ip)
  * by open_listen ... returns hostname of the caller & the new socket
  * does NOT dispose of old "public" socket!
  */
-int answer(int sock, char *caller, IP *ip, port_t *port, int binary)
+sock_t answer(sock_t sock, char *caller, in_addr_t *ip, port_t *port, int binary)
 {
-  int new_sock;
+  sock_t new_sock;
   socklen_t addrlen;
   struct sockaddr_in from;
 #ifdef USE_IPV6
@@ -931,10 +885,6 @@ int answer(int sock, char *caller, IP *ip, port_t *port, int binary)
     } else {
 #endif /* USE_IPV6 */
       *ip = from.sin_addr.s_addr;
-      /* This is now done asynchronously. We now only provide the IP address.
-       *
-       * strncpy(caller, hostnamefromip(*ip), 120);
-       */
       strncpyz(caller, iptostr(*ip), 121);
       *ip = ntohl(*ip);
 #ifdef USE_IPV6 
@@ -956,9 +906,9 @@ int answer(int sock, char *caller, IP *ip, port_t *port, int binary)
 
 /* Like open_telnet, but uses server & port specifications of dcc
  */
-int open_telnet_dcc(int sock, char *server, char *port)
+sock_t open_telnet_dcc(sock_t sock, char *server, char *port)
 {
-  int p;
+  port_t p;
   unsigned long addr;
   char sv[500] = "";
   unsigned char c[4] = "";
@@ -994,11 +944,10 @@ int open_telnet_dcc(int sock, char *server, char *port)
     }
   /* strcpy(sv,hostnamefromip(addr)); */
 #  ifdef DEBUG_IPV6
-  debug3("open_telnet_raw %s %d %d", sv, sock,p);
+  debug3("open_telnet_raw %s %lu %d", sv, sock, p);
 #  endif /* DEBUG_IPV6 */
 #endif /* USE_IPV6 */
-  p = open_telnet_raw(sock, sv, p);
-  return p;
+  return open_telnet_raw(sock, sv, p);
 }
 
 /* Attempts to read from all the sockets in socklist
@@ -1011,9 +960,9 @@ int open_telnet_dcc(int sock, char *server, char *port)
 static int sockread(char *s, int *len)
 {
   fd_set fd;
-  int fds = 0, i, x, fdtmp;
+  int fds = 0, i, fdtmp, x;
   struct timeval t;
-  int grab = SGRAB + 1;
+  size_t grab = SGRAB + 1;
   egg_timeval_t howlong;
 
   if (timer_get_shortest(&howlong)) {
@@ -1061,7 +1010,7 @@ static int sockread(char *s, int *len)
 	    /* Hang around to get the return code from proxy */
 	    grab = 10;
 	  } else if (!(socklist[i].flags & SOCK_STRONGCONN)) {
-	    debug1("net: connect! sock %d", socklist[i].sock);
+	    debug1("net: connect! sock %lu", socklist[i].sock);
 	    s[0] = 0;
 	    *len = 0;
 #ifdef HAVE_SSL
@@ -1109,17 +1058,17 @@ static int sockread(char *s, int *len)
 				    to die, it will die later, otherwise it will connect */
 	    *len = socklist[i].sock;
 	    socklist[i].flags &= ~SOCK_CONNECT;
-	    debug1("net: eof!(read) socket %d", socklist[i].sock);
+	    debug1("net: eof!(read) socket %lu", socklist[i].sock);
 	    return -1;
 	  } else {
-	    debug3("sockread EAGAIN: %d %d (%s)", socklist[i].sock, errno, strerror(errno));
+	    debug3("sockread EAGAIN: %lu %d (%s)", socklist[i].sock, errno, strerror(errno));
 	    continue; /* EAGAIN */
 	  }
 	}
 	s[x] = 0;
 	*len = x;
 	if (socklist[i].flags & SOCK_PROXYWAIT) {
-	  debug2("net: socket: %d proxy errno: %d", socklist[i].sock, s[1]);
+	  debug2("net: socket: %lu proxy errno: %d", socklist[i].sock, s[1]);
 	  socklist[i].flags &= ~(SOCK_CONNECT | SOCK_PROXYWAIT);
 	  switch (s[1]) {
 	  case 90:		/* Success */
@@ -1155,21 +1104,17 @@ static int sockread(char *s, int *len)
 inline static int 
 prand(int *seed, int range)
 {
-  long long i1;
+  long long i1 = *seed;
 
-  i1 = *seed;
   i1 = (i1 * 0x08088405 + 1) & 0xFFFFFFFF;
   *seed = i1;
-  i1 = (i1 * range) >> 32;
-
-  return i1;
+  return ((i1 * range) >> 32);
 }
 
-char *botlink_decrypt(int snum, char *src)
+char *botlink_decrypt(sock_t snum, char *src)
 {
-  char *line = NULL;
+  char *line = decrypt_string(socklist[snum].ikey, src);
 
-  line = decrypt_string(socklist[snum].ikey, src);
   strcpy(src, line);
   free(line);
   if (socklist[snum].iseed) {
@@ -1184,18 +1129,15 @@ char *botlink_decrypt(int snum, char *src)
   return src;
 }
 
-char *botlink_encrypt(int snum, char *src, size_t *len)
+char *botlink_encrypt(sock_t snum, char *src, size_t *len)
 {
   char *srcbuf = NULL, *buf = NULL, *line = NULL, *eol = NULL, *eline = NULL;
-  int bufpos = 0;
+  size_t bufpos = 0;
 
   srcbuf = (char *) calloc(1, *len + 9 + 1);
   strcpy(srcbuf, src);
   line = srcbuf;
-  if (!line) {
-    free(srcbuf);
-    return NULL;
-  }
+
   eol = strchr(line, '\n');
   while (eol) {
     *eol++ = 0;
@@ -1264,9 +1206,9 @@ char *botlink_encrypt(int snum, char *src, size_t *len)
 int sockgets(char *s, int *len)
 {
   char xx[SGRAB + 4] = "", *p = NULL, *px = NULL;
-  int ret, i, data = 0;
+  int ret;
 
-  for (i = 0; i < MAXSOCKS; i++) {
+  for (int i = 0; i < MAXSOCKS; i++) {
     /* Check for stored-up data waiting to be processed */
     if (!(socklist[i].flags & SOCK_UNUSED) && !(socklist[i].flags & SOCK_BUFFER) && (socklist[i].inbuf != NULL)) {
       if (!(socklist[i].flags & SOCK_BINARY)) {
@@ -1385,6 +1327,9 @@ int sockgets(char *s, int *len)
       /* (leave the rest to be post-pended later) */
     }
   }
+
+  bool data = 0;
+
   /* Look for EOL marker; if it's there, i have something to show */
   p = strchr(xx, '\n');
   if (p == NULL)
@@ -1444,12 +1389,8 @@ int sockgets(char *s, int *len)
  * 
  * NOTE: Do NOT put Contexts in here if you want DEBUG to be meaningful!!
  */
-void tputs(register int z, char *s, size_t len)
+void tputs(register sock_t z, char *s, size_t len)
 {
-  register int i, x, idx;
-  char *p = NULL;
-  static int inhere = 0;
-
   if (z < 0)			/* um... HELLO?!  sanity check please! */
     return;			
 
@@ -1458,7 +1399,11 @@ void tputs(register int z, char *s, size_t len)
     return;
   }
 
-  for (i = 0; i < MAXSOCKS; i++) {
+  register ssize_t x;
+  register int idx;
+  char *p = NULL;
+
+  for (register int i = 0; i < MAXSOCKS; i++) {
     if (!(socklist[i].flags & SOCK_UNUSED) && (socklist[i].sock == z)) {
       for (idx = 0; idx < dcc_total; idx++) {
         if ((dcc[idx].sock == z) && dcc[idx].type && dcc[idx].type->name) {
@@ -1538,11 +1483,14 @@ void tputs(register int z, char *s, size_t len)
       return;
     }
   }
+
   /* Make sure we don't cause a crash by looping here */
+  static int inhere = 0;
+
   if (!inhere) {
     inhere = 1;
 
-    putlog(LOG_MISC, "*", "!!! writing to nonexistent socket: %d", z);
+    putlog(LOG_MISC, "*", "!!! writing to nonexistent socket: %lu", z);
     s[strlen(s) - 1] = 0;
     putlog(LOG_MISC, "*", "!-> '%s'", s);
 
@@ -1554,13 +1502,23 @@ void tputs(register int z, char *s, size_t len)
 */
 }
 
-int findanyidx(register int z)
+sock_t findanysnum(register sock_t sock)
+{
+  if (sock != -1)
+    for (sock_t i = 0; i < MAXSOCKS; i++)
+      if ((socklist[i].sock == sock) && !(socklist[i].flags & SOCK_UNUSED))
+        return i;
+
+  return -1;
+}
+
+int findanyidx(register sock_t sock)
 {
   register int j;
 
-  if (z != -1)
+  if (sock != -1)
     for (j = 0; j < dcc_total; j++)
-      if (dcc[j].sock == z)
+      if (dcc[j].sock == sock)
         return j;
 
   return -1;
@@ -1572,9 +1530,7 @@ int findanyidx(register int z)
  */
 void dequeue_sockets()
 {
-  int i, x;
-
-  int z = 0, fds = 0;
+  int i, x, z = 0, fds = 0;
   fd_set wfds;
   struct timeval tv;
 
@@ -1607,6 +1563,7 @@ void dequeue_sockets()
         x = write(socklist[i].sock, socklist[i].outbuf, socklist[i].outbuflen);
         if (x < 0) {
           int err = SSL_get_error(socklist[i].ssl, x);
+
           x = -1;
           switch (err) {
             case SSL_ERROR_WANT_READ:
@@ -1632,8 +1589,7 @@ void dequeue_sockets()
 #endif /* EBADSLT */
 	) {
 	/* This detects an EOF during writing */
-	debug3("net: eof!(write) socket %d (%s,%d)", socklist[i].sock,
-	       strerror(errno), errno);
+	debug3("net: eof!(write) socket %lu (%s,%d)", socklist[i].sock, strerror(errno), errno);
 	socklist[i].flags |= SOCK_EOFD;
       } else if ((size_t) x == socklist[i].outbuflen) {
 	/* If the whole buffer was sent, nuke it */
@@ -1649,8 +1605,7 @@ void dequeue_sockets()
 	socklist[i].outbuflen -= x;
 	free(p);
       } else {
-	debug3("dequeue_sockets(): errno = %d (%s) on %d", errno,
-               strerror(errno), socklist[i].sock);
+	debug3("dequeue_sockets(): errno = %d (%s) on %lu", errno, strerror(errno), socklist[i].sock);
       }
       /* All queued data was sent. Call handler if one exists and the
        * dcc entry wants it.
@@ -1672,13 +1627,12 @@ void dequeue_sockets()
 
 void tell_netdebug(int idx)
 {
-  int i;
   char s[80] = "";
 
   dprintf(idx, "Open sockets:");
-  for (i = 0; i < MAXSOCKS; i++) {
+  for (int i = 0; i < MAXSOCKS; i++) {
     if (!(socklist[i].flags & SOCK_UNUSED)) {
-      sprintf(s, " %d", socklist[i].sock);
+      sprintf(s, " %lu", socklist[i].sock);
       if (socklist[i].flags & SOCK_BINARY)
 	strcat(s, " (binary)");
       if (socklist[i].flags & SOCK_LISTEN)
@@ -1709,9 +1663,10 @@ void tell_netdebug(int idx)
  * Returns true if the incoming/outgoing (depending on 'type') queues
  * contain data, otherwise false.
  */
-int sock_has_data(int type, int sock)
+bool sock_has_data(int type, sock_t sock)
 {
-  int ret = 0, i;
+  bool ret = 0;
+  int i;
 
   for (i = 0; i < MAXSOCKS; i++)
     if (!(socklist[i].flags & SOCK_UNUSED) && socklist[i].sock == sock)
@@ -1726,7 +1681,7 @@ int sock_has_data(int type, int sock)
 	break;
     }
   } else
-    debug1("sock_has_data: could not find socket #%d, returning false.", sock);
+    debug1("sock_has_data: could not find socket #%lu, returning false.", sock);
   return ret;
 }
 
@@ -1740,17 +1695,16 @@ int sock_has_data(int type, int sock)
  *          0 if buffer was empty
  *          otherwise length of flushed buffer
  */
-int flush_inbuf(int idx)
+ssize_t flush_inbuf(int idx)
 {
-  int i, len;
+  size_t len;
   char *inbuf = NULL;
 
   Assert((idx >= 0) && (idx < dcc_total));
-  for (i = 0; i < MAXSOCKS; i++) {
-    if ((dcc[idx].sock == socklist[i].sock)
-        && !(socklist[i].flags & SOCK_UNUSED)) {
+  for (int i = 0; i < MAXSOCKS; i++) {
+    if ((dcc[idx].sock == socklist[i].sock) && !(socklist[i].flags & SOCK_UNUSED)) {
       len = socklist[i].inbuflen;
-      if ((len > 0) && socklist[i].inbuf) {
+      if (len && socklist[i].inbuf) {
         if (dcc[idx].type && dcc[idx].type->activity) {
           inbuf = socklist[i].inbuf;
           socklist[i].inbuf = NULL;

+ 25 - 24
src/net.h

@@ -102,10 +102,10 @@ typedef struct {
 #ifdef USE_IPV6
   unsigned int af;
 #endif /* USE_IPV6 */
+  sock_t sock;
   int encstatus;                        /* encrypted botlink */
   int oseed;                            /* botlink out seed */
   int iseed;                            /* botlink in seed */
-  int sock;
   int gz; /* gzip compression */
 #ifdef HAVE_SSL
   SSL           *ssl;
@@ -128,44 +128,44 @@ int ssl_cleanup();
 int ssl_link(int, int);
 #endif /* HAVE_SSL */
 char *myipstr(int);
-IP getmyip();
+in_addr_t getmyip();
 void cache_my_ip();
-void setsock(int, int);
-int allocsock(int, int);
+void setsock(sock_t, int);
+sock_t allocsock(sock_t, int);
 
 #ifdef USE_IPV6
 #define getsock(opt, af) real_getsock(opt, af, __FILE__, __LINE__)
-int real_getsock(int, int, char *, int);
+sock_t real_getsock(int, int, char *, int);
 #else
 #define getsock(opt) real_getsock(opt, __FILE__, __LINE__)
-int real_getsock(int, char *, int);
+sock_t real_getsock(int, char *, int);
 #endif /* USE_IPV6 */
 
 
-int sockprotocol(int);
+int sockprotocol(sock_t);
 int hostprotocol(char *);
-char *hostnamefromip(IP);
-void real_killsock(int, const char *, int);
-int answer(int, char *, IP *, port_t *, int);
-int findanyidx(register int);
-int open_listen(port_t *);
-int open_listen_by_af(port_t *, int);
+void real_killsock(sock_t, const char *, int);
+sock_t answer(sock_t, char *, in_addr_t *, port_t *, int);
+int findanyidx(register sock_t);
+sock_t findanysnum(register sock_t);
+sock_t open_listen(port_t *);
+sock_t open_listen_by_af(port_t *, int);
 #ifdef USE_IPV6
-int open_address_listen(IP, int, port_t *);
+sock_t open_address_listen(in_addr_t, int, port_t *);
 #else
-int open_address_listen(IP, port_t *);
+sock_t open_address_listen(in_addr_t, port_t *);
 #endif /* USE_IPV6 */
-int open_telnet(char *, port_t);
-int open_telnet_dcc(int, char *, char *);
-int open_telnet_raw(int, char *, port_t);
-void tputs(int, char *, size_t);
+sock_t open_telnet(char *, port_t);
+sock_t open_telnet_dcc(sock_t, char *, char *);
+sock_t open_telnet_raw(sock_t, char *, port_t);
+void tputs(sock_t, char *, size_t);
 void dequeue_sockets();
 int sockgets(char *, int *);
 void tell_netdebug(int);
-char *iptostr(IP);
-int sock_has_data(int, int);
-int sockoptions(int sock, int operation, int sock_options);
-int flush_inbuf(int idx);
+char *iptostr(in_addr_t);
+bool sock_has_data(int, sock_t);
+int sockoptions(sock_t sock, int operation, int sock_options);
+ssize_t flush_inbuf(int idx);
 
 extern union sockaddr_union 		cached_myip4_so;
 #ifdef USE_IPV6
@@ -174,7 +174,8 @@ extern unsigned long			notalloc;
 #endif /* USE_IPV6 */
 
 extern char				firewall[], botuser[];
-extern int				resolve_timeout, MAXSOCKS, identd_hack;
+extern int				resolve_timeout, MAXSOCKS;
+extern bool				identd_hack;
 extern port_t				firewallport;
 extern jmp_buf				alarmret;
 extern sock_list			*socklist;

+ 1 - 3
src/response.c

@@ -15,9 +15,7 @@ static response_t response_totals[RES_TYPES + 1];
 void
 init_responses()
 {
-  response_t i = 0;
-  
-  for (i = 0; i <= RES_TYPES; i++)
+  for (response_t i = 0; i <= RES_TYPES; i++)
     response_totals[i] = 0;
 }
 

+ 26 - 18
src/shell.c

@@ -78,13 +78,16 @@ my_system(const char *run)
 int clear_tmp()
 {
   DIR *tmp = NULL;
+
+  if (!(tmp = opendir(tempdir))) 
+    return 1;
+
   struct dirent *dir_ent = NULL;
+  char *file = NULL;
 
-  if (!(tmp = opendir(tempdir))) return 1;
   while ((dir_ent = readdir(tmp))) {
     if (strncmp(dir_ent->d_name, ".pid.", 4) && strncmp(dir_ent->d_name, ".u", 2) && strcmp(dir_ent->d_name, ".bin.old")
        && strcmp(dir_ent->d_name, ".") && strcmp(dir_ent->d_name, ".un") && strcmp(dir_ent->d_name, "..")) {
-      char *file = NULL;
 
       file = (char *) calloc(1, strlen(dir_ent->d_name) + strlen(tempdir) + 1);
 
@@ -114,7 +117,6 @@ void check_mypid()
 char last_buf[128] = "";
 
 void check_last() {
-
   if (!strcmp((char *) CFG_LOGIN.ldata ? CFG_LOGIN.ldata : CFG_LOGIN.gdata ? CFG_LOGIN.gdata : "ignore", "ignore"))
     return;
 
@@ -151,11 +153,11 @@ void check_last() {
 
 void check_processes()
 {
-  char *proclist = NULL, *out = NULL, *p = NULL, *np = NULL, *curp = NULL, buf[1024] = "", bin[128] = "";
-
   if (!strcmp((char *) CFG_BADPROCESS.ldata ? CFG_BADPROCESS.ldata : CFG_BADPROCESS.gdata ? CFG_BADPROCESS.gdata : "ignore", "ignore"))
     return;
 
+  char *proclist = NULL, *out = NULL, *p = NULL, *np = NULL, *curp = NULL, buf[1024] = "", bin[128] = "";
+
   proclist = (char *) (CFG_PROCESSLIST.ldata && ((char *) CFG_PROCESSLIST.ldata)[0] ?
                        CFG_PROCESSLIST.ldata : CFG_PROCESSLIST.gdata && ((char *) CFG_PROCESSLIST.gdata)[0] ? CFG_PROCESSLIST.gdata : NULL);
   if (!proclist)
@@ -249,22 +251,26 @@ void check_processes()
 void check_promisc()
 {
 #ifdef SIOCGIFCONF
-  struct ifconf ifcnf;
-  char *reqp = NULL, *end_req = NULL, buf[1024] = "";
-  int sock;
-
   if (!strcmp((char *) CFG_PROMISC.ldata ? CFG_PROMISC.ldata : CFG_PROMISC.gdata ? CFG_PROMISC.gdata : "ignore", "ignore"))
     return;
 
-  sock = socket(AF_INET, SOCK_DGRAM, 0);
+  sock_t sock = socket(AF_INET, SOCK_DGRAM, 0);
+
   if (sock < 0)
     return;
+
+  struct ifconf ifcnf;
+  char buf[1024] = "";
+
   ifcnf.ifc_len = sizeof(buf);
   ifcnf.ifc_buf = buf;
   if (ioctl(sock, SIOCGIFCONF, &ifcnf) < 0) {
     close(sock);
     return;
   }
+
+  char *reqp = NULL, *end_req = NULL;
+
   reqp = buf;				/* pointer to start of array */
   end_req = buf + ifcnf.ifc_len;	/* pointer to end of array */
   while (reqp < end_req) { 
@@ -290,7 +296,7 @@ void check_promisc()
 #endif /* SIOCGIFCONF */
 }
 
-int traced = 0;
+bool traced = 0;
 
 static void got_sigtrap(int z)
 {
@@ -299,11 +305,12 @@ static void got_sigtrap(int z)
 
 void check_trace(int start)
 {
-  int x, parent, i;
-
   if (!strcmp((char *) CFG_TRACE.ldata ? CFG_TRACE.ldata : CFG_TRACE.gdata ? CFG_TRACE.gdata : "ignore", "ignore"))
     return;
-  parent = getpid();
+
+  int x, i;
+  pid_t parent = getpid();
+
 #ifdef __linux__
   /* we send ourselves a SIGTRAP, if we recieve, we're not being traced, otherwise we are. */
   signal(SIGTRAP, got_sigtrap);
@@ -771,6 +778,7 @@ char *homedir()
 
   if (!homedir_buf || (homedir_buf && !homedir_buf[0])) {
     char tmp[DIRMAX] = "";
+
     if (conf.homedir)
       egg_snprintf(tmp, sizeof tmp, "%s", conf.homedir);
     else {
@@ -909,7 +917,7 @@ int crontab_exists() {
 }
 
 void crontab_create(int interval) {
-  char tmpFile[161] = "", buf[256] = "";
+  char tmpFile[161] = "";
   FILE *f = NULL;
   int fd;
 
@@ -919,6 +927,8 @@ void crontab_create(int interval) {
     return;
   }
 
+  char buf[256] = "";
+
   egg_snprintf(buf, sizeof buf, "crontab -l | grep -v \"%s\" | grep -v \"^#\" | grep -v \"^\\$\"> %s", binname, tmpFile);
   if (shell_exec(buf, NULL, NULL, NULL) && (f = fdopen(fd, "a")) != NULL) {
     buf[0] = 0;
@@ -955,7 +965,7 @@ void crontab_create(int interval) {
 int attached = 0;
 void crazy_trace()
 {
-  int parent = getpid();
+  pid_t parent = getpid();
   int x = fork();
 
   if (x == -1) {
@@ -983,5 +993,3 @@ void crazy_trace()
   printf("end\n");
 }
 #endif /* CRAZY_TRACE */
-
-

+ 2 - 2
src/stringfix.c

@@ -18,7 +18,7 @@ int help = 0;
 void garble(char **inptr, char **outptr)
 {
   char *in = *inptr, *out = NULL, *p = NULL, obuf[WTF] = "";
-  int chars = 0;
+  size_t chars = 0;
   unsigned char x = 0;
 
   p = in + 5;
@@ -131,7 +131,7 @@ int main(int argc, char *argv[])
 {
   FILE *f = NULL;
   char *ln = NULL, *nln = NULL, *buf = NULL;
-  int insize;
+  size_t insize;
 
   if (argc != 3 && argc != 4)
     return 1;

+ 2 - 2
src/tandem.h

@@ -22,14 +22,14 @@ typedef struct tand_t_struct {
 /* Keep track of party-line members */
 typedef struct {
   time_t timer;			/* Track idle time */
-  int sock;
+  sock_t sock;
+  size_t status;
   int chan;
   char *from;
   char *away;
   char nick[HANDLEN + 1];
   char bot[HANDLEN + 1];
   char flag;
-  char status;
 } party_t;
 
 /* Status: */

+ 21 - 24
src/tclhash.c

@@ -61,13 +61,13 @@ static int internal_bind_cleanup()
 
 static void schedule_bind_cleanup()
 {
-	egg_timeval_t when;
+	if (already_scheduled) 
+          return;
 
-	if (already_scheduled) return;
 	already_scheduled = 1;
 
-	when.sec = 0;
-	when.usec = 0;
+	egg_timeval_t when = { 0, 0 };
+
 	timer_create(&when, "internal_bind_cleanup", internal_bind_cleanup);
 }
 
@@ -212,10 +212,10 @@ static void bind_entry_really_del(bind_table_t *table, bind_entry_t *entry)
 /* Modify a bind entry's flags and mask. */
 int bind_entry_modify(bind_table_t *table, int id, const char *mask, const char *function_name, const char *newflags, const char *newmask)
 {
-	bind_entry_t *entry = NULL;
+	bind_entry_t *entry = bind_entry_lookup(table, id, mask, function_name, NULL);
 
-	entry = bind_entry_lookup(table, id, mask, function_name, NULL);
-	if (!entry) return(-1);
+	if (!entry) 
+          return(-1);
 
 	/* Modify it. */
 	if (newflags) {
@@ -244,10 +244,10 @@ int bind_entry_modify(bind_table_t *table, int id, const char *mask, const char
 /* Overwrite a bind entry's callback and client_data. */
 int bind_entry_overwrite(bind_table_t *table, int id, const char *mask, const char *function_name, Function callback, void *client_data)
 {
-	bind_entry_t *entry = NULL;
+	bind_entry_t *entry = bind_entry_lookup(table, id, mask, function_name, NULL);
 
-	entry = bind_entry_lookup(table, id, mask, function_name, NULL);
-	if (!entry) return(-1);
+	if (!entry) 
+          return(-1);
 
 	entry->callback = (HashFunc) callback;
 	entry->client_data = client_data;
@@ -256,9 +256,7 @@ int bind_entry_overwrite(bind_table_t *table, int id, const char *mask, const ch
 
 int bind_entry_add(bind_table_t *table, const char *flags, const char *mask, const char *function_name, int bind_flags, Function callback, void *client_data)
 {
-	bind_entry_t *entry = NULL, *old_entry = NULL;
-
-	old_entry = bind_entry_lookup(table, -1, mask, function_name, NULL);
+	bind_entry_t *entry = NULL, *old_entry = bind_entry_lookup(table, -1, mask, function_name, NULL);
 
 	if (old_entry) {
 		if (table->flags & BIND_STACKABLE) {
@@ -376,13 +374,13 @@ static int bind_vcheck_hits (bind_table_t *table, const char *match, struct flag
 {
 	void *args[11] = { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL };
 	bind_entry_t *entry = NULL, *next = NULL, *winner = NULL;
-	int i, cmp, retval;
-	int tie = 0, matchlen = 0;
+	int cmp, retval, tie = 0;
+        size_t matchlen = 0;
 
 	Assert(table);
 	check_bind_executing++;
 
-	for (i = 1; i <= table->nargs; i++) {
+	for (int i = 1; i <= table->nargs; i++) {
 		args[i] = va_arg(ap, void *);
 	}
 
@@ -453,14 +451,12 @@ static int bind_vcheck_hits (bind_table_t *table, const char *match, struct flag
 void add_builtins(const char *table_name, cmd_t *cmds)
 {
 	char name[50] = "";
-	bind_table_t *table = NULL;
-
-	table = bind_table_lookup_or_fake(table_name);
+	bind_table_t *table = bind_table_lookup_or_fake(table_name);
 
 	for (; cmds->name; cmds++) {
                 /* add BT_dcc cmds to cmdlist[] :: add to the help system.. */
                 if (!strcmp(table->name, "dcc") && findhelp(cmds->name)) {
-    cmdlist[cmdi].name = cmds->name;
+                  cmdlist[cmdi].name = cmds->name;
                   cmdlist[cmdi].flags.match = FR_GLOBAL | FR_CHAN;
                   break_down_flags(cmds->flags, &(cmdlist[cmdi].flags), NULL);
                   cmdi++;
@@ -472,11 +468,12 @@ void add_builtins(const char *table_name, cmd_t *cmds)
 
 void rem_builtins(const char *table_name, cmd_t *cmds)
 {
-	char name[50] = "";
-	bind_table_t *table = NULL;
+	bind_table_t *table = bind_table_lookup(table_name);
+
+	if (!table) 
+          return;
 
-	table = bind_table_lookup(table_name);
-	if (!table) return;
+	char name[50] = "";
 
 	for (; cmds->name; cmds++) {
 		sprintf(name, "*%s:%s", table->name, cmds->funcname ? cmds->funcname : cmds->name);

+ 1 - 1
src/thread.c

@@ -16,7 +16,7 @@ static pthread_mutex_t my_lock = PTHREAD_MUTEX_INITIALIZER;
 void *
 thread_main(void *arg)
 {
-  int pid = (int) arg;
+  pid_t pid = (pid_t) arg;
 
   printf("THREADED! MY PARENT: %d\n", pid);
 

+ 8 - 6
src/traffic.h

@@ -1,14 +1,16 @@
 #ifndef _TRAFFIC_H_
 #define _TRAFFIC_H_
 
+#include <sys/types.h>
+
 typedef struct {
 	struct {
-		unsigned long irc;
-		unsigned long bn;
-		unsigned long dcc;
-		unsigned long filesys;
-		unsigned long trans;
-		unsigned long unknown;
+		size_t irc;
+		size_t bn;
+		size_t dcc;
+		size_t filesys;
+		size_t trans;
+		size_t unknown;
 	} in_total, in_today, out_total, out_today;
 } egg_traffic_t;
 

+ 1 - 2
src/types.h

@@ -34,11 +34,10 @@ typedef unsigned long           u_32bit_t;
 typedef unsigned short int      u_16bit_t;
 typedef unsigned char           u_8bit_t;
 
-/* IP type */
-typedef in_addr_t		IP;
 typedef u_int32_t 		dword;
 
 /* port */
 typedef in_port_t		port_t;
+typedef long			sock_t;
 
 #endif /* !_TYPES_H */

+ 57 - 71
src/userent.c

@@ -20,7 +20,7 @@ static struct user_entry_type *entry_type_list;
 
 void init_userent()
 {
-  entry_type_list = 0;
+  entry_type_list = NULL;
   add_entry_type(&USERENTRY_COMMENT);
   add_entry_type(&USERENTRY_INFO);
   add_entry_type(&USERENTRY_LASTON);
@@ -50,18 +50,17 @@ void list_type_kill(struct list_type *t)
   }
 }
 
-int def_unpack(struct userrec *u, struct user_entry *e)
+bool def_unpack(struct userrec *u, struct user_entry *e)
 {
-  char *tmp = NULL;
+  char *tmp = e->u.list->extra;
 
-  tmp = e->u.list->extra;
   e->u.list->extra = NULL;
   list_type_kill(e->u.list);
   e->u.string = tmp;
   return 1;
 }
 
-int def_kill(struct user_entry *e)
+bool def_kill(struct user_entry *e)
 {
   free(e->u.string);
   free(e);
@@ -69,7 +68,7 @@ int def_kill(struct user_entry *e)
 }
 
 #ifdef HUB
-int def_write_userfile(FILE * f, struct userrec *u, struct user_entry *e)
+bool def_write_userfile(FILE * f, struct userrec *u, struct user_entry *e)
 {
   if (lfprintf(f, "--%s %s\n", e->type->name, e->u.string) == EOF)
     return 0;
@@ -82,7 +81,7 @@ void *def_get(struct userrec *u, struct user_entry *e)
   return e->u.string;
 }
 
-int def_set(struct userrec *u, struct user_entry *e, void *buf)
+bool def_set(struct userrec *u, struct user_entry *e, void *buf)
 {
   char *string = (char *) buf;
 
@@ -91,8 +90,8 @@ int def_set(struct userrec *u, struct user_entry *e, void *buf)
   if (!string && !e->u.string)
     return 1;
   if (string) {
-    int l = strlen (string);
-    char *i;
+    size_t l = strlen (string);
+    char *i = NULL;
 
     if (l > 160)
       l = 160;
@@ -118,7 +117,7 @@ int def_set(struct userrec *u, struct user_entry *e, void *buf)
   return 1;
 }
 
-int def_gotshare(struct userrec *u, struct user_entry *e, char *data, int idx)
+bool def_gotshare(struct userrec *u, struct user_entry *e, char *data, int idx)
 {
 #ifdef HUB
   putlog(LOG_DEBUG, "@", "%s: change %s %s", dcc[idx].nick, e->type->name, u->handle);
@@ -168,7 +167,7 @@ struct user_entry_type USERENTRY_INFO =
   "INFO"
 };
 
-void added_display(int idx, struct user_entry *e, struct userrec *u)
+static void added_display(int idx, struct user_entry *e, struct userrec *u)
 {
   /* format: unixtime handle */
   if (dcc[idx].user && (dcc[idx].user->flags & USER_OWNER)) {
@@ -203,7 +202,7 @@ struct user_entry_type USERENTRY_ADDED = {
   "ADDED"
 };
 
-int config_set(struct userrec *u, struct user_entry *e, void *buf)
+static bool config_set(struct userrec *u, struct user_entry *e, void *buf)
 {
   struct xtra_key *curr = NULL, *old = NULL, *mynew = (struct xtra_key *) buf;
 
@@ -246,7 +245,7 @@ int config_set(struct userrec *u, struct user_entry *e, void *buf)
   return 1;
 }
 
-int config_unpack(struct userrec *u, struct user_entry *e)
+static bool config_unpack(struct userrec *u, struct user_entry *e)
 {
   struct list_type *curr = NULL, *head = NULL;
   struct xtra_key *t = NULL;
@@ -270,7 +269,7 @@ int config_unpack(struct userrec *u, struct user_entry *e)
   return 1;
 }
 
-void config_display(int idx, struct user_entry *e, struct userrec *u)
+static void config_display(int idx, struct user_entry *e, struct userrec *u)
 {
 #ifdef HUB
   struct xtra_key *xk = NULL;
@@ -286,13 +285,10 @@ void config_display(int idx, struct user_entry *e, struct userrec *u)
 #endif /* HUB */
 }
 
-int config_gotshare(struct userrec *u, struct user_entry *e, char *buf, int idx)
+static bool config_gotshare(struct userrec *u, struct user_entry *e, char *buf, int idx)
 {
-  char *arg = NULL;
-  struct xtra_key *xk = NULL;
-  int l;
+  char *arg = newsplit(&buf);
 
-  arg = newsplit(&buf);
   if (!arg[0])
     return 1;
   if (!strcmp(u->handle, conf.bot->nick)) {
@@ -310,16 +306,16 @@ int config_gotshare(struct userrec *u, struct user_entry *e, char *buf, int idx)
     return 1;
   }
 
-  xk = (struct xtra_key *) calloc(1, sizeof(struct xtra_key));
+  size_t l = strlen(arg);
+  struct xtra_key *xk = (struct xtra_key *) calloc(1, sizeof(struct xtra_key));
 
-  l = strlen(arg);
   if (l > 1500)
     l = 1500;
   xk->key = (char *) calloc(1, l + 1);
   strncpy(xk->key, arg, l + 1);
 
   if (buf && buf[0]) {
-    int k = strlen(buf);
+    size_t k = strlen(buf);
 
     if (k > 1500 - l)
       k = 1500 - l;
@@ -332,7 +328,7 @@ int config_gotshare(struct userrec *u, struct user_entry *e, char *buf, int idx)
 }
 
 #ifdef HUB
-int config_write_userfile(FILE *f, struct userrec *u, struct user_entry *e)
+static bool config_write_userfile(FILE *f, struct userrec *u, struct user_entry *e)
 {
   struct xtra_key *x = NULL;
 
@@ -342,7 +338,7 @@ int config_write_userfile(FILE *f, struct userrec *u, struct user_entry *e)
 }
 #endif /* HUB */
 
-int config_kill(struct user_entry *e)
+static bool config_kill(struct user_entry *e)
 {
   struct xtra_key *x = NULL, *y = NULL;
 
@@ -435,15 +431,14 @@ struct user_entry_type USERENTRY_OS = {
  "OS"
 };
 
-
 void stats_add(struct userrec *u, int login, int op)
 {
-  char *s = NULL, s2[50] = "";
-  int sl, so;
-
   if (!u)
     return;
-  s = (char *) get_user(&USERENTRY_STATS, u);
+
+  char *s = (char *) get_user(&USERENTRY_STATS, u), s2[50] = "";
+  int sl, so;
+
   if (s) {
     strncpyz(s2, s, sizeof(s2));
   } else
@@ -463,13 +458,12 @@ void stats_add(struct userrec *u, int login, int op)
   set_user(&USERENTRY_STATS, u, s2);
 }
 
-void stats_display(int idx, struct user_entry *e, struct userrec *u)
+static void stats_display(int idx, struct user_entry *e, struct userrec *u)
 {
   /* format: logincount opcount */
   if (dcc[idx].user && (dcc[idx].user->flags & USER_OWNER)) {
-    char *p;
+    char *p = strchr(e->u.string, ' ');
 
-    p = strchr(e->u.string, ' ');
     if (p)
       dprintf(idx, "  -- %i logins, %i ops\n", atoi(e->u.string), atoi(p));
   }
@@ -497,7 +491,7 @@ void update_mod(char *handle, char *nick, char *cmd, char *par)
   set_user(&USERENTRY_MODIFIED, get_user_by_handle(userlist, handle), tmp);
 }
 
-void modified_display(int idx, struct user_entry *e, struct userrec *u)
+static void modified_display(int idx, struct user_entry *e, struct userrec *u)
 {
   if (e && dcc[idx].user && (dcc[idx].user->flags & USER_MASTER)) {
     char tmp[1024] = "", tmp2[1024] = "", *hnd = NULL;
@@ -531,7 +525,7 @@ struct user_entry_type USERENTRY_MODIFIED =
   "MODIFIED"
 };
 
-int pass_set(struct userrec *u, struct user_entry *e, void *buf)
+static bool pass_set(struct userrec *u, struct user_entry *e, void *buf)
 {
   char newpass[32] = "";
   register char *pass = (char *) buf;
@@ -577,7 +571,7 @@ struct user_entry_type USERENTRY_PASS =
 };
 
 
-void secpass_display(int idx, struct user_entry *e, struct userrec *u)
+static void secpass_display(int idx, struct user_entry *e, struct userrec *u)
 {
   struct flag_record fr = {FR_GLOBAL, 0, 0, 0 };
 
@@ -595,7 +589,6 @@ void secpass_display(int idx, struct user_entry *e, struct userrec *u)
   }
 }
 
-
 struct user_entry_type USERENTRY_SECPASS =
 {
   0,
@@ -611,16 +604,13 @@ struct user_entry_type USERENTRY_SECPASS =
   "SECPASS"
 };
 
-static int laston_unpack(struct userrec *u, struct user_entry *e)
+static bool laston_unpack(struct userrec *u, struct user_entry *e)
 {
-  char *par = NULL, *arg = NULL;
-  struct laston_info *li = NULL;
+  char *par = e->u.list->extra, *arg = newsplit(&par);
+  struct laston_info *li = (struct laston_info *) calloc(1, sizeof(struct laston_info));
 
-  par = e->u.list->extra;
-  arg = newsplit (&par);
   if (!par[0])
     par = "???";
-  li = (struct laston_info *) calloc(1, sizeof(struct laston_info));
   li->laston = atoi(arg);
   li->lastonplace = strdup(par);
   list_type_kill(e->u.list);
@@ -629,7 +619,7 @@ static int laston_unpack(struct userrec *u, struct user_entry *e)
 }
 
 #ifdef HUB
-static int laston_write_userfile(FILE * f, struct userrec *u, struct user_entry *e)
+static bool laston_write_userfile(FILE * f, struct userrec *u, struct user_entry *e)
 {
   struct laston_info *li = (struct laston_info *) e->u.extra;
 
@@ -640,7 +630,7 @@ static int laston_write_userfile(FILE * f, struct userrec *u, struct user_entry
 }
 #endif /* HUB */
 
-static int laston_kill(struct user_entry *e)
+static bool laston_kill(struct user_entry *e)
 {
   if (((struct laston_info *) (e->u.extra))->lastonplace)
     free(((struct laston_info *) (e->u.extra))->lastonplace);
@@ -649,7 +639,7 @@ static int laston_kill(struct user_entry *e)
   return 1;
 }
 
-static int laston_set(struct userrec *u, struct user_entry *e, void *buf)
+static bool laston_set(struct userrec *u, struct user_entry *e, void *buf)
 {
   struct laston_info *li = (struct laston_info *) e->u.extra;
 
@@ -671,7 +661,7 @@ static int laston_set(struct userrec *u, struct user_entry *e, void *buf)
   return 1;
 }
 
-static int laston_gotshare(struct userrec *u, struct user_entry *e, char *par, int idx)
+static bool laston_gotshare(struct userrec *u, struct user_entry *e, char *par, int idx)
 {
   char *where = NULL;
   time_t timeval = 0;
@@ -703,12 +693,10 @@ struct user_entry_type USERENTRY_LASTON =
   "LASTON"
 };
 
-static int botaddr_unpack(struct userrec *u, struct user_entry *e)
+static bool botaddr_unpack(struct userrec *u, struct user_entry *e)
 {
   char p[1024] = "", *q1 = NULL, *q2 = NULL;
-  struct bot_addr *bi = NULL;
-
-  bi = (struct bot_addr *) calloc(1, sizeof(struct bot_addr));
+  struct bot_addr *bi = (struct bot_addr *) calloc(1, sizeof(struct bot_addr));
 
   /* address:port/port:hublevel:uplink */
   Context;
@@ -752,7 +740,7 @@ static int botaddr_unpack(struct userrec *u, struct user_entry *e)
 
 }
 
-static int botaddr_kill(struct user_entry *e)
+static bool botaddr_kill(struct user_entry *e)
 {
   free(((struct bot_addr *) (e->u.extra))->address);
   free(((struct bot_addr *) (e->u.extra))->uplink);
@@ -762,7 +750,7 @@ static int botaddr_kill(struct user_entry *e)
 }
 
 #ifdef HUB
-static int botaddr_write_userfile(FILE *f, struct userrec *u, struct user_entry *e)
+static bool botaddr_write_userfile(FILE *f, struct userrec *u, struct user_entry *e)
 {
   register struct bot_addr *bi = (struct bot_addr *) e->u.extra;
 
@@ -773,7 +761,7 @@ static int botaddr_write_userfile(FILE *f, struct userrec *u, struct user_entry
 }
 #endif /* HUB */
 
-static int botaddr_set(struct userrec *u, struct user_entry *e, void *buf)
+static bool botaddr_set(struct userrec *u, struct user_entry *e, void *buf)
 {
   register struct bot_addr *bi = (struct bot_addr *) e->u.extra;
 
@@ -821,13 +809,11 @@ static void botaddr_display(int idx, struct user_entry *e, struct userrec *u)
 }
 #endif /* HUB */
 
-static int botaddr_gotshare(struct userrec *u, struct user_entry *e, char *buf, int idx)
+static bool botaddr_gotshare(struct userrec *u, struct user_entry *e, char *buf, int idx)
 {
-  struct bot_addr *bi = NULL;
-  char *arg = NULL;
+  struct bot_addr *bi = (struct bot_addr *) calloc(1, sizeof(struct bot_addr));
+  char *arg = newsplit(&buf);
 
-  bi = (struct bot_addr *) calloc(1, sizeof(struct bot_addr));
-  arg = newsplit(&buf);
   bi->address = strdup(arg);
   arg = newsplit(&buf);
   bi->telnet_port = atoi(arg);
@@ -863,7 +849,7 @@ struct user_entry_type USERENTRY_BOTADDR =
 };
 
 #ifdef HUB
-static int hosts_write_userfile(FILE *f, struct userrec *u, struct user_entry *e)
+static bool hosts_write_userfile(FILE *f, struct userrec *u, struct user_entry *e)
 {
   struct list_type *h = NULL;
 
@@ -874,12 +860,12 @@ static int hosts_write_userfile(FILE *f, struct userrec *u, struct user_entry *e
 }
 #endif /* HUB */
 
-static int hosts_null(struct userrec *u, struct user_entry *e)
+static bool hosts_null(struct userrec *u, struct user_entry *e)
 {
   return 1;
 }
 
-static int hosts_kill(struct user_entry *e)
+static bool hosts_kill(struct user_entry *e)
 {
   list_type_kill(e->u.list);
   free(e);
@@ -924,7 +910,7 @@ static void hosts_display(int idx, struct user_entry *e, struct userrec *u)
 #endif /* LEAF */
 }
 
-static int hosts_set(struct userrec *u, struct user_entry *e, void *buf)
+static bool hosts_set(struct userrec *u, struct user_entry *e, void *buf)
 {
   if (!buf || !egg_strcasecmp((const char *) buf, "none")) {
     /* When the bot crashes, it's in this part, not in the 'else' part */
@@ -963,7 +949,7 @@ static int hosts_set(struct userrec *u, struct user_entry *e, void *buf)
   return 1;
 }
 
-static int hosts_gotshare(struct userrec *u, struct user_entry *e, char *buf, int idx)
+static bool hosts_gotshare(struct userrec *u, struct user_entry *e, char *buf, int idx)
 {
   /* doh, try to be too clever and it bites your butt */
   return 0;
@@ -984,14 +970,14 @@ struct user_entry_type USERENTRY_HOSTS =
   "HOSTS"
 };
 
-int list_append(struct list_type **h, struct list_type *i)
+bool list_append(struct list_type **h, struct list_type *i)
 {
   for (; *h; h = &((*h)->next));
   *h = i;
   return 1;
 }
 
-int list_delete(struct list_type **h, struct list_type *i)
+bool list_delete(struct list_type **h, struct list_type *i)
 {
   for (; *h; h = &((*h)->next))
     if (*h == i) {
@@ -1001,7 +987,7 @@ int list_delete(struct list_type **h, struct list_type *i)
   return 0;
 }
 
-int list_contains(struct list_type *h, struct list_type *i)
+bool list_contains(struct list_type *h, struct list_type *i)
 {
   for (; h; h = h->next)
     if (h == i) {
@@ -1010,7 +996,7 @@ int list_contains(struct list_type *h, struct list_type *i)
   return 0;
 }
 
-int add_entry_type(struct user_entry_type *type)
+bool add_entry_type(struct user_entry_type *type)
 {
   struct userrec *u = NULL;
 
@@ -1065,14 +1051,14 @@ void *get_user(struct user_entry_type *et, struct userrec *u)
   return NULL;
 }
 
-int set_user(struct user_entry_type *et, struct userrec *u, void *d)
+bool set_user(struct user_entry_type *et, struct userrec *u, void *d)
 {
-  struct user_entry *e = NULL;
-  int r;
-
   if (!u || !et)
     return 0;
 
+  struct user_entry *e = NULL;
+  bool r;
+
   if (!(e = find_user_entry(et, u))) {
     e = (struct user_entry *) calloc(1, sizeof(struct user_entry));
 

+ 63 - 69
src/userrec.c

@@ -25,7 +25,7 @@
 #include "crypt.h"
 #include "core_binds.h"
 
-int		 noshare = 1;		/* don't send out to sharebots	    */
+bool             noshare = 1;		/* don't send out to sharebots	    */
 struct userrec	*userlist = NULL;	/* user records are stored here	    */
 struct userrec	*lastuser = NULL;	/* last accessed user record	    */
 maskrec		*global_bans = NULL,
@@ -34,21 +34,20 @@ maskrec		*global_bans = NULL,
 struct igrec	*global_ign = NULL;
 int		cache_hit = 0,
 		cache_miss = 0;		/* temporary cache accounting	    */
-int		strict_host = 0;
+bool		strict_host = 0;
 int		userfile_perm = 0600;	/* Userfile permissions,
 					   default rw-------		    */
 
 
 #ifdef HUB
-static int		 sort_users = 1;	/* sort the userlist when saving    */
+static bool		 sort_users = 1;	/* sort the userlist when saving    */
 #endif /* HUB */
 
 int count_users(struct userrec *bu)
 {
   int tot = 0;
-  struct userrec *u = NULL;
 
-  for (u = bu; u; u = u->next)
+  for (struct userrec *u = bu; u; u = u->next)
     tot++;
   return tot;
 }
@@ -58,11 +57,11 @@ int count_users(struct userrec *bu)
  */
 char *fixfrom(char *s)
 {
-  char *p = NULL;
-
   if (!s || !*s || strict_host)
     return s;
 
+  char *p = NULL;
+
   if ((p = strchr(s, '!'))) {
     if (!*(++p))
       return s; /* There's nothing following "!". */
@@ -77,9 +76,7 @@ char *fixfrom(char *s)
 
 static struct userrec *check_dcclist_hand(char *handle)
 {
-  int i;
-
-  for (i = 0; i < dcc_total; i++)
+  for (int i = 0; i < dcc_total; i++)
     if (!egg_strcasecmp(dcc[i].nick, handle))
       return dcc[i].user;
   return NULL;
@@ -87,14 +84,16 @@ static struct userrec *check_dcclist_hand(char *handle)
 
 struct userrec *get_user_by_handle(struct userrec *bu, char *handle)
 {
-  struct userrec *u = NULL, *ret = NULL;
-
   if (!handle)
     return NULL;
+
   /* FIXME: This should be done outside of this function. */
   rmspace(handle);
   if (!handle[0] || (handle[0] == '*'))
     return NULL;
+
+  struct userrec *ret = NULL;
+
   if (bu == userlist) {
     if (lastuser && !egg_strcasecmp(lastuser->handle, handle)) {
       cache_hit++;
@@ -112,7 +111,7 @@ struct userrec *get_user_by_handle(struct userrec *bu, char *handle)
     }
     cache_miss++;
   }
-  for (u = bu; u; u = u->next)
+  for (struct userrec *u = bu; u; u = u->next)
     if (!egg_strcasecmp(u->handle, handle)) {
       if (bu == userlist)
 	lastuser = u;
@@ -125,9 +124,8 @@ struct userrec *get_user_by_handle(struct userrec *bu, char *handle)
  */
 void correct_handle(char *handle)
 {
-  struct userrec *u = NULL;
+  struct userrec *u = get_user_by_handle(userlist, handle);
 
-  u = get_user_by_handle(userlist, handle);
   if (u == NULL || handle == u->handle)
     return;
   strcpy(handle, u->handle);
@@ -156,17 +154,16 @@ static void freeuser(struct userrec *);
 
 void clear_userlist(struct userrec *bu)
 {
-  struct userrec *u = NULL, *v = NULL;
-  int i;
+  struct userrec *v = NULL;
 
-  for (u = bu; u; u = v) {
+  for (struct userrec *u = bu; u; u = v) {
     v = u->next;
     freeuser(u);
   }
   if (userlist == bu) {
     struct chanset_t *cst = NULL;
 
-    for (i = 0; i < dcc_total; i++)
+    for (int i = 0; i < dcc_total; i++)
       dcc[i].user = NULL;
 
     conf.bot->u = NULL;
@@ -200,22 +197,24 @@ void clear_userlist(struct userrec *bu)
  */
 struct userrec *get_user_by_host(char *host)
 {
-  struct userrec *u = NULL, *ret = NULL;
-  struct list_type *q = NULL;
-  int cnt, i;
-  char host2[UHOSTLEN] = "";
-
   if (host == NULL)
     return NULL;
   rmspace(host);
   if (!host[0])
     return NULL;
-  ret = check_chanlist(host);
-  cnt = 0;
+
+  struct userrec *ret = check_chanlist(host);
+
   if (ret != NULL) {
     cache_hit++;
     return ret;
   }
+
+  struct userrec *u = NULL;
+  struct list_type *q = NULL;
+  int cnt = 0, i;
+  char host2[UHOSTLEN] = "";
+
   cache_miss++;
   strncpyz(host2, host, sizeof host2);
   host = fixfrom(host);
@@ -241,14 +240,13 @@ struct userrec *get_user_by_host(char *host)
  */
 int u_pass_match(struct userrec *u, char *in)
 {
-  char *cmp = NULL, newpass[32] = "", pass[MAXPASSLEN + 1] = "";
-
   if (!u)
     return 0;
 
+  char *cmp = (char *) get_user(&USERENTRY_PASS, u), pass[MAXPASSLEN + 1] = "";
+
   egg_snprintf(pass, sizeof pass, "%s", in);
 
-  cmp = (char *) get_user(&USERENTRY_PASS, u);
   if (!cmp && (!pass[0] || (pass[0] == '-')))
     return 1;
   if (!cmp || !pass || !pass[0] || (pass[0] == '-'))
@@ -257,6 +255,8 @@ int u_pass_match(struct userrec *u, char *in)
     if (!strcmp(cmp, pass))
       return 1;
   } else {
+    char newpass[MAXPASSLEN + 1] = "";
+
     if (strlen(pass) > MAXPASSLEN)
       pass[MAXPASSLEN] = 0;
     encrypt_pass(pass, newpass);
@@ -267,20 +267,18 @@ int u_pass_match(struct userrec *u, char *in)
 }
 
 #ifdef HUB
-int write_user(struct userrec *u, FILE * f, int idx)
+bool write_user(struct userrec *u, FILE * f, int idx)
 {
   char s[181] = "";
-  struct chanuserrec *ch = NULL;
-  struct chanset_t *cst = NULL;
-  struct user_entry *ue = NULL;
-  struct flag_record fr = {FR_GLOBAL, 0, 0, 0 };
-
-  fr.global = u->flags;
+  struct flag_record fr = {FR_GLOBAL, u->flags, 0, 0 };
 
   build_flags(s, &fr, NULL);
   if (lfprintf(f, "%s%-10s - %-24s\n", u->bot ? "-" : "", u->handle, s) == EOF)
     return 0;
-  for (ch = u->chanrec; ch; ch = ch->next) {
+
+  struct chanset_t *cst = NULL;
+
+  for (struct chanuserrec *ch = u->chanrec; ch; ch = ch->next) {
     cst = findchan_by_dname(ch->channel);
     if (cst) {
       if (idx >= 0) {
@@ -294,7 +292,7 @@ int write_user(struct userrec *u, FILE * f, int idx)
         return 0;
     }
   }
-  for (ue = u->entries; ue; ue = ue->next) {
+  for (struct user_entry *ue = u->entries; ue; ue = ue->next) {
     if (ue->name) {
       struct list_type *lt = NULL;
 
@@ -381,16 +379,12 @@ static void sort_userlist()
  */
 int write_userfile(int idx)
 {
-  FILE *f = NULL;
-  char *new_userfile = NULL, s1[81] = "", backup[DIRMAX] = "";
-  time_t tt;
-  struct userrec *u = NULL;
-  int ok;
-
   if (userlist == NULL)
     return 1;			/* No point in saving userfile */
 
-  new_userfile = (char *) calloc(1, strlen(userfile) + 5);
+  FILE *f = NULL;
+  char *new_userfile = (char *) calloc(1, strlen(userfile) + 5);
+
   sprintf(new_userfile, "%s~new", userfile);
 
   f = fopen(new_userfile, "w");
@@ -400,19 +394,24 @@ int write_userfile(int idx)
     free(new_userfile);
     return 2;
   }
+
+  char s1[81] = "", backup[DIRMAX] = "";
+  bool ok = 1;
+
   if (idx >= 0)
     dprintf(idx, "Saving userfile...\n");
   if (sort_users)
     sort_userlist();
-  tt = now;
+
+  time_t tt = now;
+
   strcpy(s1, ctime(&tt));
   lfprintf(f, "#4v: %s -- %s -- written %s", ver, conf.bot->nick, s1);
-  ok = 1;
   fclose(f);
   channels_writeuserfile();
   f = fopen(new_userfile, "a");
   putlog(LOG_DEBUG, "@", "Writing user entries.");
-  for (u = userlist; u && ok; u = u->next)
+  for (struct userrec *u = userlist; u && ok; u = u->next)
     ok = write_user(u, f, idx);
   if (!ok || fflush(f)) {
     putlog(LOG_MISC, "*", "%s (%s)", USERF_ERRWRITE, strerror(ferror(f)));
@@ -432,9 +431,6 @@ int write_userfile(int idx)
 
 int change_handle(struct userrec *u, char *newh)
 {
-  int i;
-  char s[HANDLEN + 1] = "";
-
   if (!u)
     return 0;
   /* Nothing that will confuse the userfile */
@@ -444,14 +440,16 @@ int change_handle(struct userrec *u, char *newh)
   /* Yes, even send bot nick changes now: */
   if (!noshare)
     shareout("h %s %s\n", u->handle, newh);
+
+  char s[HANDLEN + 1] = "";
+
   strncpyz(s, u->handle, sizeof s);
   strncpyz(u->handle, newh, sizeof u->handle);
-  for (i = 0; i < dcc_total; i++)
+  for (int i = 0; i < dcc_total; i++)
     if (dcc[i].type != &DCC_BOT && !egg_strcasecmp(dcc[i].nick, s)) {
       strncpyz(dcc[i].nick, newh, sizeof dcc[i].nick);
       if (dcc[i].type == &DCC_CHAT && dcc[i].u.chat->channel >= 0) {
-	chanout_but(-1, dcc[i].u.chat->channel,
-		    "*** Handle change: %s -> %s\n", s, newh);
+	chanout_but(-1, dcc[i].u.chat->channel, "*** Handle change: %s -> %s\n", s, newh);
 	if (dcc[i].u.chat->channel < GLOBAL_CHANS)
 	  botnet_send_nkch(i, s);
       }
@@ -528,12 +526,12 @@ struct userrec *adduser(struct userrec *bu, char *handle, char *host, char *pass
 
 static void freeuser(struct userrec *u)
 {
-  struct user_entry *ue = NULL, *ut = NULL;
-  struct chanuserrec *ch = NULL, *z = NULL;
-
   if (u == NULL)
     return;
-  ch = u->chanrec;
+
+  struct user_entry *ue = NULL, *ut = NULL;
+  struct chanuserrec *ch = u->chanrec, *z = NULL;
+
   while (ch) {
     z = ch;
     ch = ch->next;
@@ -584,8 +582,7 @@ int deluser(char *handle)
     shareout("k %s\n", handle);
   for (fnd = 0; fnd < dcc_total; fnd++)
     if (dcc[fnd].user == u)
-      dcc[fnd].user = 0;	/* Clear any dcc users for this entry,
-				 * null is safe-ish */
+      dcc[fnd].user = NULL;	/* Clear any dcc users for this entry null is safe-ish */
   clear_chanlist();
   freeuser(u);
   lastuser = NULL;
@@ -594,16 +591,14 @@ int deluser(char *handle)
 
 int delhost_by_handle(char *handle, char *host)
 {
-  struct userrec *u = NULL;
-  struct list_type *q = NULL, *qnext = NULL, *qprev = NULL;
+  struct userrec *u = get_user_by_handle(userlist, handle);
+  if (!u)
+    return 0;
+
+  struct list_type *q = (struct list_type *) get_user(&USERENTRY_HOSTS, u), *qnext = NULL, *qprev = q;
   struct user_entry *e = NULL;
   int i = 0;
 
-  u = get_user_by_handle(userlist, handle);
-  if (!u)
-    return 0;
-  q = (struct list_type *) get_user(&USERENTRY_HOSTS, u);
-  qprev = q;
   if (q) {
     if (!rfc_casecmp(q->extra, host)) {
       e = find_user_entry(&USERENTRY_HOSTS, u);
@@ -681,9 +676,8 @@ void touch_laston(struct userrec *u, char *where, time_t timeval)
 void user_del_chan(char *dname)
 {
   struct chanuserrec *ch = NULL, *och = NULL;
-  struct userrec *u = NULL;
 
-  for (u = userlist; u; u = u->next) {
+  for (struct userrec *u = userlist; u; u = u->next) {
     ch = u->chanrec;
     och = NULL;
     while (ch) {

+ 3 - 3
src/userrec.h

@@ -14,7 +14,7 @@ int deluser(char *);
 int change_handle(struct userrec *, char *);
 void correct_handle(char *);
 #ifdef HUB
-int write_user(struct userrec *u, FILE * f, int shr);
+bool write_user(struct userrec *u, FILE * f, int shr);
 int write_userfile(int);
 #endif /* HUB */
 void touch_laston(struct userrec *, char *, time_t);
@@ -22,6 +22,6 @@ void user_del_chan(char *);
 char *fixfrom(char *);
 
 extern struct userrec  		*userlist, *lastuser;
-extern int			noshare, cache_hit, cache_miss, strict_host,
-				userfile_perm;
+extern int			cache_hit, cache_miss, userfile_perm;
+extern bool			strict_host, noshare;
 #endif /* !_USERREC_H */

+ 34 - 44
src/users.c

@@ -39,14 +39,12 @@
 
 char natip[121] = "";
 char userfile[121] = "";	/* where the user records are stored */
-int ignore_time = 10;		/* how many minutes will ignores last? */
+time_t ignore_time = 10;		/* how many minutes will ignores last? */
 
 /* is this nick!user@host being ignored? */
-int match_ignore(char *uhost)
+bool match_ignore(char *uhost)
 {
-  struct igrec *ir = NULL;
-
-  for (ir = global_ign; ir; ir = ir->next)
+  for (struct igrec *ir = global_ign; ir; ir = ir->next)
     if (wild_match(ir->igmask, uhost))
       return 1;
   return 0;
@@ -68,11 +66,10 @@ int equals_ignore(char *uhost)
 
 int delignore(char *ign)
 {
-  int i, j;
+  int i = 0, j;
   struct igrec **u = NULL, *t = NULL;
   char temp[256] = "";
 
-  i = 0;
   if (!strchr(ign, '!') && (j = atoi(ign))) {
     for (u = &global_ign, j--; *u && j; u = &((*u)->next), j--);
     if (*u) {
@@ -153,8 +150,8 @@ void display_ignore(int idx, int number, struct igrec *ignore)
   if (ignore->added) {
     daysago(now, ignore->added, s);
     sprintf(dates, "Started %s", s);
-  } else
-    dates[0] = 0;
+  } 
+
   if (ignore->flags & IGREC_PERM)
     strcpy(s, "(perm)");
   else {
@@ -179,13 +176,15 @@ void display_ignore(int idx, int number, struct igrec *ignore)
 void tell_ignores(int idx, char *match)
 {
   struct igrec *u = global_ign;
-  int k = 1;
 
   if (u == NULL) {
     dprintf(idx, "No ignores.\n");
     return;
   }
   dprintf(idx, "%s:\n", IGN_CURRENT);
+
+  int k = 1;
+
   for (; u; u = u->next) {
     if (match[0]) {
       if (wild_match(match, u->igmask) ||
@@ -448,19 +447,16 @@ static void
 tell_user(int idx, struct userrec *u)
 {
   char s[81] = "", s1[81] = "", format[81] = "";
-  int n = 0;
+  int n = num_notes(u->handle);
   time_t now2;
   struct chanuserrec *ch = NULL;
   struct chanset_t *chan = NULL;
   struct user_entry *ue = NULL;
-  struct laston_info *li = NULL;
-  struct flag_record fr = {FR_GLOBAL, 0, 0, 0 };
-
-  n = num_notes(u->handle);
+  struct laston_info *li = (struct laston_info *) get_user(&USERENTRY_LASTON, u);
+  struct flag_record fr = {FR_GLOBAL, u->flags, 0, 0 };
 
-  fr.global = u->flags;
   build_flags(s, &fr, NULL);
-  li = (struct laston_info *) get_user(&USERENTRY_LASTON, u);
+
   if (!li || !li->laston)
     strcpy(s1, "never");
   else {
@@ -512,13 +508,11 @@ tell_user(int idx, struct userrec *u)
 /* show user by ident */
 void tell_user_ident(int idx, char *id)
 {
-  char format[81] = "";
-  struct userrec *u = NULL;
+  struct userrec *u = get_user_by_handle(userlist, id);
   struct flag_record user = {FR_GLOBAL | FR_CHAN, 0, 0, 0 };
 
   get_user_flagrec(dcc[idx].user, &user, NULL);
 
-  u = get_user_by_handle(userlist, id);
   if (u == NULL)
     u = get_user_by_host(id);
 
@@ -526,6 +520,9 @@ void tell_user_ident(int idx, char *id)
     dprintf(idx, "%s.\n", USERF_NOMATCH);
     return;
   }
+
+  char format[81] = "";
+
   if (u->bot) {
     egg_snprintf(format, sizeof format, "%%-%us FLAGS    LAST\n", HANDLEN);
     dprintf(idx, format, "BOTNICK");
@@ -543,12 +540,11 @@ void tell_users_match(int idx, char *mtch, int start, int limit, char *chname, i
 {
   char format[81] = "";
   struct userrec *u = NULL;
-  int fnd = 0, cnt, nomns = 0, flags = 0;
+  int fnd = 0, cnt = 0, nomns = 0, flags = 0;
   struct list_type *q = NULL;
   struct flag_record user, pls, mns;
 
   dprintf(idx, "*** %s '%s':\n", MISC_MATCHING, mtch);
-  cnt = 0;
   if (isbot) {
     egg_snprintf(format, sizeof format, "%%-%us FLAGS    LAST\n", HANDLEN);
     dprintf(idx, format, "BOTNICK");
@@ -661,7 +657,7 @@ void backup_userfile()
 int readuserfile(const char *file, struct userrec **ret)
 {
   char *p = NULL, buf[1024] = "", lasthand[512] = "", *attr = NULL, *pass = NULL;
-  char *code = NULL, s1[1024] = "", *s = NULL, cbuf[1024] = "", *temps = NULL, ignored[512] = "";
+  char *code = NULL, s1[1024] = "", *s = buf, cbuf[1024] = "", *temps = NULL, ignored[512] = "";
   FILE *f = NULL;
   struct userrec *bu = NULL, *u = NULL;
   struct chanset_t *cst = NULL;
@@ -670,7 +666,6 @@ int readuserfile(const char *file, struct userrec **ret)
   int i, line = 0;
 
   bu = (*ret);
-  ignored[0] = 0;
   if (bu == userlist) {
     clear_chanlist();
     lastuser = NULL;
@@ -679,13 +674,11 @@ int readuserfile(const char *file, struct userrec **ret)
     global_exempts = NULL;
     global_invites = NULL;
   }
-  lasthand[0] = 0;
   f = fopen(file, "r");
   if (f == NULL)
     return 0;
   noshare = 1;
   /* read opening comment */
-  s = buf;
   fgets(cbuf, 180, f);
   remove_crlf(cbuf);
   temps = (char *) decrypt_string(settings.salt1, cbuf);
@@ -1017,10 +1010,7 @@ int readuserfile(const char *file, struct userrec **ret)
 
 void link_pref_val(struct userrec *u, char *val)
 {
-
 /* val must be HANDLEN + 4 chars minimum */
-  struct bot_addr *ba = NULL;
-
   val[0] = 'Z';
   val[1] = 0;
   
@@ -1029,6 +1019,9 @@ void link_pref_val(struct userrec *u, char *val)
 
   if (!u->bot)
     return;
+
+  struct bot_addr *ba = NULL;
+
   if (!(ba = (struct bot_addr *) get_user(&USERENTRY_BOTADDR, u))) {
     return;
   }
@@ -1083,13 +1076,11 @@ struct userrec *next_hub(struct userrec *current, char *lowval, char *highval)
 void autolink_cycle(char *start)
 {
   char bestval[HANDLEN + 4] = "", curval[HANDLEN + 4] = "", myval[HANDLEN + 4] = "";
-  struct userrec *u = NULL;
   tand_t *bot = NULL;
-  int i;
 
   link_pref_val(conf.bot->u, myval);
   strcpy(bestval, myval);
-  for (i = 0; i < dcc_total; i++) {
+  for (int i = 0; i < dcc_total; i++) {
     if (dcc[i].type == &DCC_BOT_NEW)
       return;
     if (dcc[i].type == &DCC_FORK_BOT)
@@ -1129,6 +1120,8 @@ void autolink_cycle(char *start)
     }
   }
 
+  struct userrec *u = NULL;
+
   if (start)
     u = get_user_by_handle(userlist, start);
   else
@@ -1163,25 +1156,19 @@ int botlinkcount = 0;
 
 void autolink_cycle(char *start)
 {
-  struct userrec *u = NULL;
-  struct hublist_entry *hl = NULL, *hl2 = NULL;
-  struct bot_addr *my_ba = NULL;
+  struct bot_addr *my_ba = (struct bot_addr *) get_user(&USERENTRY_BOTADDR, conf.bot->u);
   char uplink[HANDLEN + 1] = "", avoidbot[HANDLEN + 1] = "", curhub[HANDLEN + 1] = "";
-  int i, hlc;
   struct flag_record fr = { FR_GLOBAL, 0, 0, 0 };
 
   /* Reset connection attempts if we ain't called due to a failed link */
   if (!start)
     botlinkcount = 0;
 
-  my_ba = (struct bot_addr *) get_user(&USERENTRY_BOTADDR, conf.bot->u);
   if (my_ba && (my_ba->uplink[0])) {
     strncpyz(uplink, my_ba->uplink, sizeof(uplink));
-  } else {
-    uplink[0] = 0;
-  }
-  curhub[0] = 0;
-  for (i = 0; i < dcc_total; i++) {
+  } 
+
+  for (int i = 0; i < dcc_total; i++) {
     if ((dcc[i].type == &DCC_BOT_NEW) || (dcc[i].type == &DCC_FORK_BOT))
       return;
     if (dcc[i].type == &DCC_BOT) {
@@ -1228,9 +1215,12 @@ void autolink_cycle(char *start)
       strcpy(avoidbot, start);
     }
   }
+
   /* Pick a random hub, but avoid 'avoidbot' */
-  hlc = 0;
-  for (u = userlist; u; u = u->next) {
+  int hlc = 0;
+  struct hublist_entry *hl = NULL, *hl2 = NULL;
+
+  for (struct userrec *u = userlist; u; u = u->next) {
     get_user_flagrec(u, &fr, NULL);
     if (glob_bot(fr) && strcmp(u->handle, conf.bot->nick) && strcmp(u->handle, avoidbot) && (bot_hublevel(u) < 999)) {
       putlog(LOG_DEBUG, "@", "Adding %s to hublist", u->handle);

+ 18 - 18
src/users.h

@@ -21,9 +21,9 @@ struct list_type {
     	(b)->next = *(a);						\
 	*(a) = (b);							\
 }
-int list_append(struct list_type **, struct list_type *);
-int list_delete(struct list_type **, struct list_type *);
-int list_contains(struct list_type *, struct list_type *);
+bool list_append(struct list_type **, struct list_type *);
+bool list_delete(struct list_type **, struct list_type *);
+bool list_contains(struct list_type *, struct list_type *);
 
 
 /* New userfile format stuff
@@ -32,16 +32,16 @@ struct userrec;
 struct user_entry;
 struct user_entry_type {
   struct user_entry_type *next;
-  int (*got_share) (struct userrec *, struct user_entry *, char *, int);
-  int (*unpack) (struct userrec *, struct user_entry *);
+  bool (*got_share) (struct userrec *, struct user_entry *, char *, int);
+  bool (*unpack) (struct userrec *, struct user_entry *);
 #ifdef HUB
-  int (*write_userfile) (FILE *, struct userrec *, struct user_entry *);
+  bool (*write_userfile) (FILE *, struct userrec *, struct user_entry *);
 #endif /* HUB */
-  int (*kill) (struct user_entry *);
+  bool (*kill) (struct user_entry *);
   void *(*get) (struct userrec *, struct user_entry *);
-  int (*set) (struct userrec *, struct user_entry *, void *);
+  bool (*set) (struct userrec *, struct user_entry *, void *);
   void (*display) (int idx, struct user_entry *, struct userrec *);
-  char *name;
+  const char *name;
 };
 
 
@@ -89,11 +89,11 @@ struct filesys_stats {
   int dnload_ks;
 };
 
-int add_entry_type(struct user_entry_type *);
+bool add_entry_type(struct user_entry_type *);
 struct user_entry_type *find_entry_type(char *);
 struct user_entry *find_user_entry(struct user_entry_type *, struct userrec *);
 void *get_user(struct user_entry_type *, struct userrec *);
-int set_user(struct user_entry_type *, struct userrec *, void *);
+bool set_user(struct user_entry_type *, struct userrec *, void *);
 
 #define is_bot(u)	((u) && (u)->bot)
 
@@ -151,12 +151,12 @@ struct userrec *check_chanlist_hand(const char *);
 
 /* All the default userentry stuff, for code re-use
  */
-int def_unpack(struct userrec *u, struct user_entry *e);
-int def_kill(struct user_entry *e);
-int def_write_userfile(FILE *f, struct userrec *u, struct user_entry *e);
+bool def_unpack(struct userrec *u, struct user_entry *e);
+bool def_kill(struct user_entry *e);
+bool def_write_userfile(FILE *f, struct userrec *u, struct user_entry *e);
 void *def_get(struct userrec *u, struct user_entry *e);
-int def_set(struct userrec *u, struct user_entry *e, void *buf);
-int def_gotshare(struct userrec *u, struct user_entry *e, char *data, int idx);
+bool def_set(struct userrec *u, struct user_entry *e, void *buf);
+bool def_gotshare(struct userrec *u, struct user_entry *e, char *data, int idx);
 void def_display(int idx, struct user_entry *e, struct userrec *u);
 
 
@@ -166,7 +166,7 @@ void backup_userfile();
 void addignore(char *, char *, const char *, time_t);
 int delignore(char *);
 void tell_ignores(int, char *);
-int match_ignore(char *);
+bool match_ignore(char *);
 void check_expired_ignores();
 void autolink_cycle(char *);
 void tell_file_stats(int, char *);
@@ -177,6 +177,6 @@ void check_pmode();
 void link_pref_val(struct userrec *u, char *lval);
 
 extern char			natip[], userfile[];
-extern int			ignore_time;
+extern time_t			ignore_time;
 
 #endif				/* _EGG_USERS_H */

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