Bladeren bron

* Code improvements
* Stripped ununsed code


svn: 966

Bryan Drewery 22 jaren geleden
bovenliggende
commit
9c6eb6bc11
23 gewijzigde bestanden met toevoegingen van 73 en 240 verwijderingen
  1. 1 1
      src/auth.c
  2. 7 5
      src/binary.c
  3. 1 1
      src/botnet.c
  4. 0 1
      src/chan.h
  5. 12 16
      src/chanprog.c
  6. 5 5
      src/crypt.c
  7. 1 2
      src/dcc.c
  8. 7 6
      src/dccutil.c
  9. 1 1
      src/dccutil.h
  10. 1 1
      src/log.c
  11. 1 6
      src/main.c
  12. 2 2
      src/match.c
  13. 2 5
      src/match.h
  14. 2 36
      src/misc.c
  15. 2 5
      src/misc.h
  16. 0 8
      src/mod/irc.mod/irc.c
  17. 8 8
      src/net.c
  18. 0 58
      src/rfc1459.c
  19. 0 2
      src/rfc1459.h
  20. 1 6
      src/userent.c
  21. 19 62
      src/userrec.c
  22. 0 2
      src/userrec.h
  23. 0 1
      src/users.h

+ 1 - 1
src/auth.c

@@ -32,7 +32,7 @@
 
 
 #ifdef S_AUTHCMDS
 #ifdef S_AUTHCMDS
 int auth_total = 0;
 int auth_total = 0;
-static int max_auth = 100;
+static int max_auth = 50;
 struct auth_t *auth = NULL;
 struct auth_t *auth = NULL;
 #endif /* S_AUTHCMDS */
 #endif /* S_AUTHCMDS */
 
 

+ 7 - 5
src/binary.c

@@ -15,9 +15,11 @@
 
 
 #ifndef CYGWIN_HACKS
 #ifndef CYGWIN_HACKS
 
 
+#define PREFIXLEN 16
+
 typedef struct encdata_struct {
 typedef struct encdata_struct {
-  char prefix[16];
-  char data[512];
+  char prefix[PREFIXLEN];
+  char data[65];
 } encdata_t;
 } encdata_t;
 
 
 static encdata_t encdata = {
 static encdata_t encdata = {
@@ -42,7 +44,7 @@ bin_md5(const char *fname, int todo)
 
 
   MD5_Init(&ctx);
   MD5_Init(&ctx);
   while ((len = fread(buf, 1, sizeof buf - 1, f))) {
   while ((len = fread(buf, 1, sizeof buf - 1, f))) {
-    if (!memcmp(buf, &encdata.prefix, 16)) {
+    if (!memcmp(buf, &encdata.prefix, PREFIXLEN)) {
       break;
       break;
     }
     }
     MD5_Update(&ctx, buf, len);
     MD5_Update(&ctx, buf, len);
@@ -93,8 +95,8 @@ bin_md5(const char *fname, int todo)
         werr(ERR_BINSTAT);
         werr(ERR_BINSTAT);
       }
       }
 
 
-      if (!memcmp(buf, &encdata.prefix, 16)) {
-        /* now we have 512 for data :D */
+      if (!memcmp(buf, &encdata.prefix, PREFIXLEN)) {
+        /* now we have 65 for data :D */
         char *enc_hash = NULL;
         char *enc_hash = NULL;
 
 
         enc_hash = encrypt_string(SALT1, hash);
         enc_hash = encrypt_string(SALT1, hash);

+ 1 - 1
src/botnet.c

@@ -34,7 +34,7 @@ tand_t			*tandbot = NULL;		/* Keep track of tandem bots on the
 party_t			*party = NULL;			/* Keep track of people on the botnet */
 party_t			*party = NULL;			/* Keep track of people on the botnet */
 int			tands = 0;			/* Number of bots on the botnet */
 int			tands = 0;			/* Number of bots on the botnet */
 
 
-static int 		maxparty = 100;			/* Maximum space for party line members
+static int 		maxparty = 50;			/* Maximum space for party line members
 							   currently */
 							   currently */
 static int		parties = 0;			/* Number of people on the botnet */
 static int		parties = 0;			/* Number of people on the botnet */
 static int		share_unlinks = 1;		/* Allow remote unlinks of my
 static int		share_unlinks = 1;		/* Allow remote unlinks of my

+ 0 - 1
src/chan.h

@@ -109,7 +109,6 @@ struct chan_t {
 #define CHANNOMSG  BIT5		/* +n					*/
 #define CHANNOMSG  BIT5		/* +n					*/
 #define CHANLIMIT  BIT6		/* -l -- used only for protecting modes	*/
 #define CHANLIMIT  BIT6		/* -l -- used only for protecting modes	*/
 #define CHANKEY    BIT7		/* +k					*/
 #define CHANKEY    BIT7		/* +k					*/
-/* FIXME: JUST REMOVE THESE :D */
 #define CHANANON   BIT8		/* +a -- ircd 2.9			*/
 #define CHANANON   BIT8		/* +a -- ircd 2.9			*/
 #define CHANQUIET  BIT9		/* +q -- ircd 2.9			*/
 #define CHANQUIET  BIT9		/* +q -- ircd 2.9			*/
 #define CHANNOCLR  BIT10	/* +c -- bahamut			*/
 #define CHANNOCLR  BIT10	/* +c -- bahamut			*/

+ 12 - 16
src/chanprog.c

@@ -46,28 +46,24 @@ int     		my_port;
 #endif /* HUB */
 #endif /* HUB */
 
 
 
 
-/* Remove space characters from beginning and end of string
- * (more efficent by Fred1)
+/* Remove leading and trailing whitespaces.
  */
  */
 void rmspace(char *s)
 void rmspace(char *s)
 {
 {
-  char *p = NULL, *end = NULL;
-  int len;
+  register char *p = NULL, *q = NULL;
 
 
-  if (!s || (s && !*s))
+  if (!s || !*s)
     return;
     return;
 
 
-  /* Wipe end of string */
-  end = s + strlen(s) - 1;
-  for (p = end; ((egg_isspace(*p)) && (p >= s)); p--);
-  if (p != end) *(p + 1) = 0;
-  len = p+1 - s;
-  for (p = s; ((egg_isspace(*p)) && (*p)); p++);
-  len -= (p - s);
-  if (p != s) {
-    /* +1 to include the null in the copy */
-    memmove(s, p, len + 1);
-  }
+  /* Remove trailing whitespaces. */
+  for (q = s + strlen(s) - 1; q >= s && egg_isspace(*q); q--);
+  *(q + 1) = 0;
+
+  /* Remove leading whitespaces. */
+  for (p = s; egg_isspace(*p); p++);
+
+  if (p != s)
+    memmove(s, p, q - p + 2);
 }
 }
 
 
 /* Returns memberfields if the nick is in the member list.
 /* Returns memberfields if the nick is in the member list.

+ 5 - 5
src/crypt.c

@@ -28,7 +28,7 @@ char *encrypt_binary(const char *keydata, unsigned char *data, int *datalen)
   if (newdatalen % CRYPT_BLOCKSIZE)             /* more than 1 block? */
   if (newdatalen % CRYPT_BLOCKSIZE)             /* more than 1 block? */
     newdatalen += (CRYPT_BLOCKSIZE - (newdatalen % CRYPT_BLOCKSIZE));
     newdatalen += (CRYPT_BLOCKSIZE - (newdatalen % CRYPT_BLOCKSIZE));
 
 
-  newdata = (unsigned char *) calloc(1, newdatalen);
+  newdata = calloc(1, newdatalen);
   egg_memcpy(newdata, data, *datalen);
   egg_memcpy(newdata, data, *datalen);
   if (newdatalen != *datalen)
   if (newdatalen != *datalen)
     egg_bzero((void *) &newdata[*datalen], (newdatalen - *datalen));
     egg_bzero((void *) &newdata[*datalen], (newdatalen - *datalen));
@@ -199,7 +199,7 @@ int lfprintf (FILE *stream, ...)
 
 
 void Encrypt_File(char *infile, char *outfile)
 void Encrypt_File(char *infile, char *outfile)
 {
 {
-  char  buf[8192];
+  char  buf[1024];
   FILE *f = NULL, *f2 = NULL;
   FILE *f = NULL, *f2 = NULL;
   int std = 0;
   int std = 0;
 
 
@@ -217,7 +217,7 @@ void Encrypt_File(char *infile, char *outfile)
   }
   }
 
 
   buf[0] = 0;
   buf[0] = 0;
-  while (fscanf(f, "%[^\n]\n", buf) != EOF) {
+  while (fgets(buf, sizeof buf, f) != NULL) {
     if (std)
     if (std)
       printf("%s\n", encrypt_string(SALT1, buf));
       printf("%s\n", encrypt_string(SALT1, buf));
     else
     else
@@ -251,7 +251,7 @@ void Decrypt_File(char *infile, char *outfile)
   }
   }
   
   
   buf[0] = 0;
   buf[0] = 0;
-  while (fscanf(f, "%[^\n]\n", buf) != EOF) {
+  while (fgets(buf, sizeof buf, f) != NULL) {
     temps = (char *) decrypt_string(SALT1, buf);
     temps = (char *) decrypt_string(SALT1, buf);
     if (!std)
     if (!std)
       fprintf(f2, "%s\n",temps);
       fprintf(f2, "%s\n",temps);
@@ -327,7 +327,7 @@ char *btoh(const unsigned char *md, int len)
   char buf[100] = "", *ret = NULL;
   char buf[100] = "", *ret = NULL;
 
 
   for (i = 0; i < len; i++)
   for (i = 0; i < len; i++)
-    sprintf(&(buf[i*2]), "%02x", md[i]);
+    sprintf(&(buf[i*2]), "%02X", md[i]);
 
 
   ret = buf;
   ret = buf;
   return ret;
   return ret;

+ 1 - 2
src/dcc.c

@@ -45,7 +45,7 @@ int	dcc_total = 0;		/* Total dcc's				   */
 char	network[41] = "EFnet"; /* Name of the IRC network you're on  */
 char	network[41] = "EFnet"; /* Name of the IRC network you're on  */
 
 
 static int	password_timeout = 20;	/* Time to wait for a password from a user */
 static int	password_timeout = 20;	/* Time to wait for a password from a user */
-static int     auth_timeout = 40;
+static int      auth_timeout = 40;
 static int	bot_timeout = 15;	/* Bot timeout value			   */
 static int	bot_timeout = 15;	/* Bot timeout value			   */
 static int	identtimeout = 15;	/* Timeout value for ident lookups	   */
 static int	identtimeout = 15;	/* Timeout value for ident lookups	   */
 static int	dupwait_timeout = 5;	/* Timeout for rejecting duplicate entries */
 static int	dupwait_timeout = 5;	/* Timeout for rejecting duplicate entries */
@@ -211,7 +211,6 @@ void send_timesync(int idx)
 #endif /* HUB */
 #endif /* HUB */
 }
 }
 
 
-
 static void greet_new_bot(int idx)
 static void greet_new_bot(int idx)
 {
 {
   int i;
   int i;

+ 7 - 6
src/dccutil.c

@@ -70,7 +70,7 @@ char *add_cr(char *buf)
   return WBUF;
   return WBUF;
 }
 }
 
 
-void dprintf (int idx, ...)
+void dprintf(int idx, ...)
 {
 {
   static char buf[1024] = "";
   static char buf[1024] = "";
   char *format = NULL;
   char *format = NULL;
@@ -81,6 +81,7 @@ void dprintf (int idx, ...)
   format = va_arg(va, char *);
   format = va_arg(va, char *);
   egg_vsnprintf(buf, 1023, format, va);
   egg_vsnprintf(buf, 1023, format, va);
   va_end(va);
   va_end(va);
+
   /* We can not use the return value vsnprintf() to determine where
   /* We can not use the return value vsnprintf() to determine where
    * to null terminate. The C99 standard specifies that vsnprintf()
    * to null terminate. The C99 standard specifies that vsnprintf()
    * shall return the number of bytes that would be written if the
    * shall return the number of bytes that would be written if the
@@ -177,7 +178,7 @@ void dprintf (int idx, ...)
   }
   }
 }
 }
 
 
-void chatout (char *format, ...)
+void chatout(char *format, ...)
 {
 {
   int i, len;
   int i, len;
   char s[601] = "";
   char s[601] = "";
@@ -200,7 +201,7 @@ void chatout (char *format, ...)
 
 
 /* Print to all on this channel but one.
 /* Print to all on this channel but one.
  */
  */
-void chanout_but (int x, ...)
+void chanout_but(int x, ...)
 {
 {
   int i, chan, len;
   int i, chan, len;
   char *format = NULL;
   char *format = NULL;
@@ -434,11 +435,11 @@ void set_away(int idx, char *s)
 }
 }
 
 
 
 
-/* Make a password, 10-15 random letters and digits
+/* Make a password, 10-14 random letters and digits
  */
  */
-void makepass(char *s)
+inline void makepass(char *s)
 {
 {
-  make_rand_str(s, 10 + randint(6));
+  make_rand_str(s, 10 + randint(5));
 }
 }
 
 
 void flush_lines(int idx, struct chat_info *ci)
 void flush_lines(int idx, struct chat_info *ci)

+ 1 - 1
src/dccutil.h

@@ -31,7 +31,7 @@ void chatout (char *, ...);
 void chanout_but (int, ...);
 void chanout_but (int, ...);
 void dcc_chatter(int);
 void dcc_chatter(int);
 void lostdcc(int);
 void lostdcc(int);
-void makepass(char *);
+inline void makepass(char *);
 void tell_dcc(int);
 void tell_dcc(int);
 void not_away(int);
 void not_away(int);
 void set_away(int, char *);
 void set_away(int, char *);

+ 1 - 1
src/log.c

@@ -27,7 +27,7 @@ int 	use_console_r = 1;      /* Allow users to set their console +r  */
 
 
 typedef struct {
 typedef struct {
 	int flag;
 	int flag;
-	char c;
+	unsigned char c;
 	char *type;
 	char *type;
 } logmode_mapping_t;
 } logmode_mapping_t;
 
 

+ 1 - 6
src/main.c

@@ -32,7 +32,6 @@
 #include "src/mod/irc.mod/irc.h"
 #include "src/mod/irc.mod/irc.h"
 #include "src/mod/server.mod/server.h"
 #include "src/mod/server.mod/server.h"
 #endif /* LEAF */
 #endif /* LEAF */
-/* FIXME: REMOVE AFTER 1.1.4 */
 #include "src/mod/channels.mod/channels.h"
 #include "src/mod/channels.mod/channels.h"
 #include <time.h>
 #include <time.h>
 #include <errno.h>
 #include <errno.h>
@@ -759,8 +758,6 @@ int main(int argc, char **argv)
   ctcp_init();
   ctcp_init();
   chanprog();
   chanprog();
 #ifdef HUB
 #ifdef HUB
-/* FIXME: Remove after 1.1.4 */
-  /* this should only happen while upgrading to 1.1.4 */
   if (!CFG_CHANSET.gdata) {
   if (!CFG_CHANSET.gdata) {
     cfg_noshare++;
     cfg_noshare++;
     set_cfg_str(NULL, "chanset", glob_chanset);
     set_cfg_str(NULL, "chanset", glob_chanset);
@@ -829,11 +826,9 @@ int main(int argc, char **argv)
 #ifndef CYGWIN_HACKS
 #ifndef CYGWIN_HACKS
     setpgid(0, 0);
     setpgid(0, 0);
 #endif /* !CYGWIN_HACKS */
 #endif /* !CYGWIN_HACKS */
-    /* fuck tcl.
     freopen("/dev/null", "r", stdin);
     freopen("/dev/null", "r", stdin);
     freopen("/dev/null", "w", stdout);
     freopen("/dev/null", "w", stdout);
     freopen("/dev/null", "w", stderr);
     freopen("/dev/null", "w", stderr);
-    */
 #ifdef CYGWIN_HACKS
 #ifdef CYGWIN_HACKS
     FreeConsole();
     FreeConsole();
 #endif /* CYGWIN_HACKS */
 #endif /* CYGWIN_HACKS */
@@ -901,7 +896,7 @@ int main(int argc, char **argv)
       socket_cleanup--;
       socket_cleanup--;
 
 
     xx = sockgets(buf, &i); 
     xx = sockgets(buf, &i); 
-//printf("BUF: %s\n", buf);
+
     if (xx >= 0) {		/* Non-error */
     if (xx >= 0) {		/* Non-error */
       int idx;
       int idx;
 
 

+ 2 - 2
src/match.c

@@ -35,7 +35,7 @@
 #define MATCH (match+sofar)
 #define MATCH (match+sofar)
 #define PERMATCH (match+saved+sofar)
 #define PERMATCH (match+saved+sofar)
 
 
-int _wild_match_per(register unsigned char *m, register unsigned char *n)
+int wild_match_per(register unsigned char *m, register unsigned char *n)
 {
 {
   unsigned char *ma = m, *lsm = NULL, *lsn = NULL, *lpm = NULL, *lpn = NULL;
   unsigned char *ma = m, *lsm = NULL, *lsn = NULL, *lpm = NULL, *lpn = NULL;
   int match = 1, saved = 0, space;
   int match = 1, saved = 0, space;
@@ -130,7 +130,7 @@ int _wild_match_per(register unsigned char *m, register unsigned char *n)
   return (*m) ? NOMATCH : PERMATCH;     /* End of both = match */
   return (*m) ? NOMATCH : PERMATCH;     /* End of both = match */
 }
 }
 
 
-int _wild_match(register unsigned char *m, register unsigned char *n)
+int wild_match(register unsigned char *m, register unsigned char *n)
 {
 {
   unsigned char *ma = m, *na = n, *lsm = NULL, *lsn = NULL;
   unsigned char *ma = m, *na = n, *lsm = NULL, *lsn = NULL;
   int match = 1;
   int match = 1;

+ 2 - 5
src/match.h

@@ -1,10 +1,7 @@
 #ifndef _MATCH_H
 #ifndef _MATCH_H
 #define _MATCH_H
 #define _MATCH_H
 
 
-int _wild_match(register unsigned char *, register unsigned char *);
-int _wild_match_per(register unsigned char *, register unsigned char *);
-
-#define wild_match(a,b) _wild_match((unsigned char *)(a),(unsigned char *)(b))
-#define wild_match_per(a,b) _wild_match_per((unsigned char *)(a),(unsigned char *)(b))
+int wild_match(register unsigned char *, register unsigned char *);
+int wild_match_per(register unsigned char *, register unsigned char *);
 
 
 #endif /* !_MATCH_H */
 #endif /* !_MATCH_H */

+ 2 - 36
src/misc.c

@@ -513,24 +513,6 @@ void show_channels(int idx, char *handle)
     dprintf(idx, "%s %s not have access to any channels.\n", handle ? u->handle : "You", handle ? "does" : "do");
     dprintf(idx, "%s %s not have access to any channels.\n", handle ? u->handle : "You", handle ? "does" : "do");
 }
 }
 
 
-int getting_users()
-{
-  int i;
-
-  for (i = 0; i < dcc_total; i++)
-    if ((dcc[i].type == &DCC_BOT) && (dcc[i].status & STAT_GETTING))
-      return 1;
-  return 0;
-}
-
-char *extracthostname(char *hostmask)
-{
-  char *p = NULL;
-
-  p = strrchr(hostmask, '@');
-  return p ? p + 1 : "";
-}
-
 /* Create a string with random letters and digits
 /* Create a string with random letters and digits
  */
  */
 void make_rand_str(char *s, int len)
 void make_rand_str(char *s, int len)
@@ -555,22 +537,6 @@ void make_rand_str(char *s, int len)
   s[len] = '\0';
   s[len] = '\0';
 }
 }
 
 
-/* Convert an octal string into a decimal integer value.  If the string
- * is empty or contains non-octal characters, -1 is returned.
- */
-int oatoi(const char *octal)
-{
-  register int i;
-
-  if (!*octal)
-    return -1;
-  for (i = 0; ((*octal >= '0') && (*octal <= '7')); octal++)
-    i = (i * 8) + (*octal - '0');
-  if (*octal)
-    return -1;
-  return i;
-}
-
 /* Return an allocated buffer which contains a copy of the string
 /* Return an allocated buffer which contains a copy of the string
  * 'str', with all 'div' characters escaped by 'mask'. 'mask'
  * 'str', with all 'div' characters escaped by 'mask'. 'mask'
  * characters are escaped too.
  * characters are escaped too.
@@ -666,7 +632,7 @@ char *strchr_unescape(char *str, const char div, register const char esc_char)
 /* As strchr_unescape(), but converts the complete string, without
 /* As strchr_unescape(), but converts the complete string, without
  * searching for a specific delimiter character.
  * searching for a specific delimiter character.
  */
  */
-void str_unescape(char *str, register const char esc_char)
+inline void str_unescape(char *str, register const char esc_char)
 {
 {
   (void) strchr_unescape(str, 0, esc_char);
   (void) strchr_unescape(str, 0, esc_char);
 }
 }
@@ -1074,7 +1040,7 @@ int goodpass(char *pass, int idx, char *nick)
   return 1;
   return 1;
 }
 }
 
 
-char *replace(const char *string, char *oldie, char *newbie)
+char *replace(const char *string, const char *oldie, const char *newbie)
 {
 {
   static char newstring[1024] = "";
   static char newstring[1024] = "";
   int str_index, newstr_index, oldie_index, end, new_len, old_len, cpy_len;
   int str_index, newstr_index, oldie_index, end, new_len, old_len, cpy_len;

+ 2 - 5
src/misc.h

@@ -33,10 +33,9 @@ char *color(int, int, int);
 void shuffle(char *, char *);
 void shuffle(char *, char *);
 void showhelp(int, struct flag_record *, char *);
 void showhelp(int, struct flag_record *, char *);
 int listen_all(int, int);
 int listen_all(int, int);
-char *replace(const char *, char *, char *);
+char *replace(const char *, const char *, const char *);
 int goodpass(char *, int, char *);
 int goodpass(char *, int, char *);
 void makeplaincookie(char *, char *, char *);
 void makeplaincookie(char *, char *, char *);
-int getting_users();
 char *kickreason(int);
 char *kickreason(int);
 int bot_aggressive_to(struct userrec *);
 int bot_aggressive_to(struct userrec *);
 int updatebin(int, char *, int);
 int updatebin(int, char *, int);
@@ -57,12 +56,10 @@ void daysdur(time_t, time_t, char *);
 void show_motd(int);
 void show_motd(int);
 void show_channels(int, char *);
 void show_channels(int, char *);
 void show_banner(int);
 void show_banner(int);
-char *extracthostname(char *);
 void make_rand_str(char *, int);
 void make_rand_str(char *, int);
-int oatoi(const char *);
 char *str_escape(const char *, const char, const char);
 char *str_escape(const char *, const char, const char);
 char *strchr_unescape(char *, const char, register const char);
 char *strchr_unescape(char *, const char, register const char);
-void str_unescape(char *, register const char);
+inline void str_unescape(char *, register const char);
 int str_isdigit(const char *);
 int str_isdigit(const char *);
 void kill_bot(char *, char *);
 void kill_bot(char *, char *);
 
 

+ 0 - 8
src/mod/irc.mod/irc.c

@@ -295,10 +295,6 @@ void getin_request(char *botnick, char *code, char *par)
       putlog(LOG_GETIN, "*", "opreq from %s/%s on %s - I'm too lagged", botnick, nick, chan->dname);
       putlog(LOG_GETIN, "*", "opreq from %s/%s on %s - I'm too lagged", botnick, nick, chan->dname);
       return;
       return;
     }
     }
-    if (getting_users()) {
-      putlog(LOG_GETIN, "*", "opreq from %s/%s on %s - I'm getting userlist right now", botnick, nick, chan->dname);
-      return;
-    }
     if (chan->channel.no_op) {
     if (chan->channel.no_op) {
       if (chan->channel.no_op > now)                      /* dont op until this time has passed */
       if (chan->channel.no_op > now)                      /* dont op until this time has passed */
         return;
         return;
@@ -339,10 +335,6 @@ void getin_request(char *botnick, char *code, char *par)
       putlog(LOG_GETIN, "*", "inreq from %s/%s for %s - I'm too lagged", botnick, nick, chan->dname);
       putlog(LOG_GETIN, "*", "inreq from %s/%s for %s - I'm too lagged", botnick, nick, chan->dname);
       return;
       return;
     }
     }
-    if (getting_users()) {
-      putlog(LOG_GETIN, "*", "inreq from %s/%s for %s - I'm getting userlist right now", botnick, nick, chan->dname);
-      return;
-    }
     if (!(channel_pending(chan) || channel_active(chan))) {
     if (!(channel_pending(chan) || channel_active(chan))) {
       putlog(LOG_GETIN, "*", "inreq from %s/%s for %s - I'm not on %s now", botnick, nick, chan->dname, chan->dname);
       putlog(LOG_GETIN, "*", "inreq from %s/%s for %s - I'm not on %s now", botnick, nick, chan->dname, chan->dname);
       return;
       return;

+ 8 - 8
src/net.c

@@ -1236,12 +1236,12 @@ char *botlink_decrypt(int snum, char *src)
   return src;
   return src;
 }
 }
 
 
-char *botlink_encrypt(int snum, char *src)
+char *botlink_encrypt(int snum, char *src, size_t *len)
 {
 {
   char *srcbuf = NULL, *buf = NULL, *line = NULL, *eol = NULL, *eline = NULL;
   char *srcbuf = NULL, *buf = NULL, *line = NULL, *eol = NULL, *eline = NULL;
   int bufpos = 0, i = 0;
   int bufpos = 0, i = 0;
 
 
-  srcbuf = calloc(1, strlen(src) + 9 + 1);
+  srcbuf = calloc(1, *len + 9 + 1);
   strcpy(srcbuf, src);
   strcpy(srcbuf, src);
   line = srcbuf;
   line = srcbuf;
   if (!line) {
   if (!line) {
@@ -1280,6 +1280,8 @@ char *botlink_encrypt(int snum, char *src)
     strcat(buf, "\n");
     strcat(buf, "\n");
   }
   }
   free(srcbuf);
   free(srcbuf);
+
+  *len = strlen(buf);
   return buf;
   return buf;
 }
 }
 
 
@@ -1335,7 +1337,7 @@ int sockgets(char *s, int *len)
 	  /* Strip CR if this was CR/LF combo */
 	  /* Strip CR if this was CR/LF combo */
 	  if (s[strlen(s) - 1] == '\r')
 	  if (s[strlen(s) - 1] == '\r')
 	    s[strlen(s) - 1] = 0;
 	    s[strlen(s) - 1] = 0;
-          if (socklist[i].encstatus && (strlen(s) > 0))
+          if (socklist[i].encstatus && s[0])
             botlink_decrypt(i, s);
             botlink_decrypt(i, s);
 	  *len = strlen(s);
 	  *len = strlen(s);
 	  return socklist[i].sock;
 	  return socklist[i].sock;
@@ -1453,7 +1455,7 @@ int sockgets(char *s, int *len)
       data = 1;
       data = 1;
     }
     }
   }
   }
-  if (socklist[ret].encstatus && (strlen(s) > 0))
+  if (socklist[ret].encstatus && s[0])
     botlink_decrypt(ret, s);
     botlink_decrypt(ret, s);
   *len = strlen(s);
   *len = strlen(s);
   /* Anything left that needs to be saved? */
   /* Anything left that needs to be saved? */
@@ -1522,10 +1524,8 @@ void tputs(register int z, char *s, size_t len)
         }
         }
       }
       }
 
 
-      if (socklist[i].encstatus && (strlen(s) > 0)) {
-        s = botlink_encrypt(i, s);
-        len = strlen(s);
-      }
+      if (socklist[i].encstatus && (len > 0))
+        s = botlink_encrypt(i, s, &len);		/* will modify len */
       
       
       if (socklist[i].outbuf != NULL) {
       if (socklist[i].outbuf != NULL) {
 	/* Already queueing: just add it */
 	/* Already queueing: just add it */

+ 0 - 58
src/rfc1459.c

@@ -21,72 +21,14 @@ rfc_casecmp(const char *s1, const char *s2)
   return (res);
   return (res);
 }
 }
 
 
-int
-rfc_ncasecmp(const char *str1, const char *str2, int n)
-{
-  register unsigned char *s1 = (unsigned char *) str1;
-  register unsigned char *s2 = (unsigned char *) str2;
-  register int res;
-
-  while (!(res = rfc_toupper(*s1) - rfc_toupper(*s2))) {
-    s1++;
-    s2++;
-    n--;
-    if (!n || (*s1 == '\0' && *s2 == '\0'))
-      return 0;
-  }
-  return (res);
-}
-
-unsigned char rfc_tolowertab[];
 unsigned char rfc_touppertab[];
 unsigned char rfc_touppertab[];
 
 
-int
-rfc_tolower(int c)
-{
-  return rfc_tolowertab[(unsigned char) (c)];
-}
-
 int
 int
 rfc_toupper(int c)
 rfc_toupper(int c)
 {
 {
   return rfc_touppertab[(unsigned char) (c)];
   return rfc_touppertab[(unsigned char) (c)];
 }
 }
 
 
-unsigned char rfc_tolowertab[] = { 0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xa,
-  0xb, 0xc, 0xd, 0xe, 0xf, 0x10, 0x11, 0x12, 0x13, 0x14,
-  0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d,
-  0x1e, 0x1f,
-  ' ', '!', '"', '#', '$', '%', '&', 0x27, '(', ')',
-  '*', '+', ',', '-', '.', '/',
-  '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
-  ':', ';', '<', '=', '>', '?',
-  '@', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i',
-  'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's',
-  't', 'u', 'v', 'w', 'x', 'y', 'z', '{', '|', '}', '~',
-  '_',
-  '`', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i',
-  'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's',
-  't', 'u', 'v', 'w', 'x', 'y', 'z', '{', '|', '}', '~',
-  0x7f,
-  0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89,
-  0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,
-  0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99,
-  0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f,
-  0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa8, 0xa9,
-  0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf,
-  0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7, 0xb8, 0xb9,
-  0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf,
-  0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9,
-  0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf,
-  0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9,
-  0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf,
-  0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9,
-  0xea, 0xeb, 0xec, 0xed, 0xee, 0xef,
-  0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9,
-  0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
-};
-
 unsigned char rfc_touppertab[] = { 0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xa,
 unsigned char rfc_touppertab[] = { 0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xa,
   0xb, 0xc, 0xd, 0xe, 0xf, 0x10, 0x11, 0x12, 0x13, 0x14,
   0xb, 0xc, 0xd, 0xe, 0xf, 0x10, 0x11, 0x12, 0x13, 0x14,
   0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d,
   0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d,

+ 0 - 2
src/rfc1459.h

@@ -2,8 +2,6 @@
 #define _RFC1459_H
 #define _RFC1459_H
 
 
 int rfc_casecmp(const char *, const char *);
 int rfc_casecmp(const char *, const char *);
-int rfc_ncasecmp(const char *, const char *, int);
 int rfc_toupper(int);
 int rfc_toupper(int);
-int rfc_tolower(int);
 
 
 #endif /* !_RFC1459_H */
 #endif /* !_RFC1459_H */

+ 1 - 6
src/userent.c

@@ -772,11 +772,6 @@ struct user_entry_type USERENTRY_BOTADDR =
   "BOTADDR"
   "BOTADDR"
 };
 };
 
 
-static int hosts_null(struct userrec *u, struct user_entry *e)
-{
-  return 1;
-}
-
 #ifdef HUB
 #ifdef HUB
 static int hosts_write_userfile(FILE *f, struct userrec *u, struct user_entry *e)
 static int hosts_write_userfile(FILE *f, struct userrec *u, struct user_entry *e)
 {
 {
@@ -883,7 +878,7 @@ struct user_entry_type USERENTRY_HOSTS =
 {
 {
   0,
   0,
   hosts_gotshare,
   hosts_gotshare,
-  hosts_null,
+  NULL,
 #ifdef HUB
 #ifdef HUB
   hosts_write_userfile,
   hosts_write_userfile,
 #endif /* HUB */
 #endif /* HUB */

+ 19 - 62
src/userrec.c

@@ -53,33 +53,29 @@ int count_users(struct userrec *bu)
   return tot;
   return tot;
 }
 }
 
 
-/* Convert "nick!~user@host", "nick!+user@host" and "nick!-user@host"
- * to "nick!user@host" if necessary. (drummer)
+/* Removes a username prefix (~+-^=) from a userhost.
+ * e.g, "nick!~user@host" -> "nick!user@host"
  */
  */
 char *fixfrom(char *s)
 char *fixfrom(char *s)
 {
 {
-  static char buf[512] = "";
   char *p = NULL;
   char *p = NULL;
 
 
-  if (s == NULL)
-    return NULL;
-  strncpyz(buf, s, sizeof buf);
-  if (strict_host)
-    return buf;
-  if ((p = strchr(buf, '!')))
-    p++;
-  else
-    p = s;			/* Sometimes we get passed just a
-				 * user@host here... */
-  /* These are ludicrous. */
-  if (strchr("~+-^=", *p) && (p[1] != '@')) /* added check for @ - drummer */
-/*    strcpy(p, p + 1); */
-    sprintf(p, "%s", p + 1);
-  /* Bug was: n!~@host -> n!@host  now: n!~@host */
-  return buf;
+  if (!s || !*s || strict_host)
+    return s;
+
+  if ((p = strchr(s, '!'))) {
+    if (!*(++p))
+      return s; /* There's nothing following "!". */
+  } else
+    p = s; /* There's no nick. */
+
+  if (strchr("~+-^=", *p) && *(p + 1) != '@')
+    memmove(p, p + 1, strlen(p)); /* NUL is included without +1. */
+
+  return s;
 }
 }
 
 
-struct userrec *check_dcclist_hand(char *handle)
+static struct userrec *check_dcclist_hand(char *handle)
 {
 {
   int i;
   int i;
 
 
@@ -156,6 +152,8 @@ void clear_masks(maskrec *m)
   }
   }
 }
 }
 
 
+static void freeuser(struct userrec *);
+
 void clear_userlist(struct userrec *bu)
 void clear_userlist(struct userrec *bu)
 {
 {
   struct userrec *u = NULL, *v = NULL;
   struct userrec *u = NULL, *v = NULL;
@@ -238,20 +236,6 @@ struct userrec *get_user_by_host(char *host)
   return ret;
   return ret;
 }
 }
 
 
-/* use fixfrom() or dont? (drummer)
- */
-struct userrec *get_user_by_equal_host(char *host)
-{
-  struct userrec *u = NULL;
-  struct list_type *q = NULL;
-
-  for (u = userlist; u; u = u->next)
-    for (q = get_user(&USERENTRY_HOSTS, u); q; q = q->next)
-      if (!rfc_casecmp(q->extra, host))
-	return u;
-  return NULL;
-}
-
 /* Try: pass_match_by_host("-",host)
 /* Try: pass_match_by_host("-",host)
  * will return 1 if no password is set for that host
  * will return 1 if no password is set for that host
  */
  */
@@ -474,7 +458,6 @@ int change_handle(struct userrec *u, char *newh)
   return 1;
   return 1;
 }
 }
 
 
-
 struct userrec *adduser(struct userrec *bu, char *handle, char *host, char *pass, int flags)
 struct userrec *adduser(struct userrec *bu, char *handle, char *host, char *pass, int flags)
 {
 {
   struct userrec *u = NULL, *x = NULL;
   struct userrec *u = NULL, *x = NULL;
@@ -540,7 +523,7 @@ struct userrec *adduser(struct userrec *bu, char *handle, char *host, char *pass
   return bu;
   return bu;
 }
 }
 
 
-void freeuser(struct userrec *u)
+static void freeuser(struct userrec *u)
 {
 {
   struct user_entry *ue = NULL, *ut = NULL;
   struct user_entry *ue = NULL, *ut = NULL;
   struct chanuserrec *ch = NULL, *z = NULL;
   struct chanuserrec *ch = NULL, *z = NULL;
@@ -692,32 +675,6 @@ void touch_laston(struct userrec *u, char *where, time_t timeval)
 
 
 }
 }
 
 
-/*  Go through all channel records and try to find a matching
- *  nick. Will return the user's user record if that is known
- *  to the bot.  (Fabian)
- *
- *  Warning: This is unreliable by concept!
- */
-struct userrec *get_user_by_nick(char *nick)
-{
-  struct chanset_t *chan = NULL;
-  memberlist *m = NULL;
-
-  for (chan = chanset; chan; chan = chan->next) {
-    for (m = chan->channel.member; m && m->nick[0] ;m = m->next) {
-      if (!rfc_casecmp(nick, m->nick)) {
-  	char word[512] = "";
-
-	egg_snprintf(word, sizeof word, "%s!%s", m->nick, m->userhost);
-	/* No need to check the return value ourself */
-	return get_user_by_host(word);;
-      }
-    }
-  }
-  /* Sorry, no matches */
-  return NULL;
-}
-
 void user_del_chan(char *dname)
 void user_del_chan(char *dname)
 {
 {
   struct chanuserrec *ch = NULL, *och = NULL;
   struct chanuserrec *ch = NULL, *och = NULL;

+ 0 - 2
src/userrec.h

@@ -11,14 +11,12 @@ int delhost_by_handle(char *, char *);
 int ishost_for_handle(char *, char *);
 int ishost_for_handle(char *, char *);
 int count_users(struct userrec *);
 int count_users(struct userrec *);
 int deluser(char *);
 int deluser(char *);
-void freeuser(struct userrec *);
 int change_handle(struct userrec *, char *);
 int change_handle(struct userrec *, char *);
 void correct_handle(char *);
 void correct_handle(char *);
 #ifdef HUB
 #ifdef HUB
 int write_user(struct userrec *u, FILE * f, int shr);
 int write_user(struct userrec *u, FILE * f, int shr);
 int write_userfile(int);
 int write_userfile(int);
 #endif /* HUB */
 #endif /* HUB */
-struct userrec *check_dcclist_hand(char *);
 void touch_laston(struct userrec *, char *, time_t);
 void touch_laston(struct userrec *, char *, time_t);
 void user_del_chan(char *);
 void user_del_chan(char *);
 char *fixfrom(char *);
 char *fixfrom(char *);

+ 0 - 1
src/users.h

@@ -149,7 +149,6 @@ extern struct igrec *global_ign;
 
 
 struct userrec *get_user_by_handle(struct userrec *, char *);
 struct userrec *get_user_by_handle(struct userrec *, char *);
 struct userrec *get_user_by_host(char *);
 struct userrec *get_user_by_host(char *);
-struct userrec *get_user_by_nick(char *);
 struct userrec *check_chanlist();
 struct userrec *check_chanlist();
 struct userrec *check_chanlist_hand();
 struct userrec *check_chanlist_hand();