Просмотр исходного кода

Merge branch 'jupenick-nicklen' into maint

* jupenick-nicklen:
  * Optimize RFC string comparisons and fix uninitialized value warning
  * Match my nick based on the max NICKLEN
  * Fix bot getting confused when changing to long nicks
  * Add a rfc_ncasecmp()
Bryan Drewery 14 лет назад
Родитель
Сommit
d7de564752
4 измененных файлов с 33 добавлено и 19 удалено
  1. 4 0
      doc/UPDATES
  2. 11 10
      src/mod/server.mod/servmsg.c
  3. 16 9
      src/rfc1459.c
  4. 2 0
      src/rfc1459.h

+ 4 - 0
doc/UPDATES

@@ -1,3 +1,7 @@
+maint
+  * Fix various compile warnings with newer GCC
+  * Fix bot getting confused when changing to long nicks
+
 1.3.3 - http://wraith.botpack.net/milestone/1.3.3
   * Fix --disable-ipv6 compiling
   * Update cmd_mop to support console channel (so it works via Auth commands better)

+ 11 - 10
src/mod/server.mod/servmsg.c

@@ -176,7 +176,7 @@ int check_bind_ctcpr(char *nick, char *uhost, struct userrec *u,
 
 bool match_my_nick(char *nick)
 {
-  return (!rfc_casecmp(nick, botname));
+  return (!rfc_ncasecmp(nick, botname, nick_len));
 }
 
 void rehash_monitor_list() {
@@ -390,6 +390,7 @@ got005(char *from, char *msg)
       /* we are default set to rfc1459, so only switch if NOT rfc1459 */
       if (strcasecmp(p, "rfc1459")) {
         rfc_casecmp = strcasecmp;
+        rfc_ncasecmp = strncasecmp;
         rfc_toupper = toupper;
       }
     }
@@ -898,13 +899,13 @@ static int gotpong(char *from, char *msg)
 }
 
 static int nick_which(const char* nick, bool& is_jupe, bool& is_orig) {
-  if (jupenick[0] && !rfc_casecmp(nick, jupenick)) {
+  if (jupenick[0] && !rfc_ncasecmp(nick, jupenick, nick_len)) {
     is_jupe = 1;
     // If some stupid reason they have the same jupenick/nick, make sure to mark it as on
-    if (!rfc_casecmp(nick, origbotname))
+    if (!rfc_ncasecmp(nick, origbotname, nick_len))
       is_orig = 1;
     return 1;
-  } else if (!rfc_casecmp(nick, origbotname)) {
+  } else if (!rfc_ncasecmp(nick, origbotname, nick_len)) {
     is_orig = 1;
   }
   return 0;
@@ -965,7 +966,7 @@ void real_release_nick(void *data) {
 
 void release_nick(const char* nick) {
   // Only do this if currently on a jupenick
-  if (jupenick[0] && ((!nick && match_my_nick(jupenick)) || (nick && !rfc_casecmp(jupenick, nick)))) {
+  if (jupenick[0] && ((!nick && match_my_nick(jupenick)) || (nick && !rfc_ncasecmp(jupenick, nick, nick_len)))) {
     keepnick = 0;
 
     // Delay releasing nick for 2 seconds to allow botnet to receive orders and user to type /NICK
@@ -1080,7 +1081,7 @@ static int got433(char *from, char *msg)
 
     if (tried_jupenick)
       jnick_juped = 0;
-    else if (!rfc_casecmp(tmp, origbotname))
+    else if (!rfc_ncasecmp(tmp, origbotname, nick_len))
       nick_juped = 0;
 
     tried_nick = 0;
@@ -1142,11 +1143,11 @@ static int got437(char *from, char *msg)
       }
     }
   } else if (server_online) {
-    if (!rfc_casecmp(s, origbotname)) {
+    if (!rfc_ncasecmp(s, origbotname, nick_len)) {
       if (!nick_juped)
         putlog(LOG_MISC, "*", "NICK IS TEMPORARILY UNAVAILABLE: '%s' (keeping '%s').", s, botname);
       nick_juped = 2;
-    } else if (jupenick[0] && !rfc_casecmp(s, jupenick)) {
+    } else if (jupenick[0] && !rfc_ncasecmp(s, jupenick, nick_len)) {
       if (!jnick_juped)
         putlog(LOG_MISC, "*", "JUPENICK IS TEMPORARILY UNAVAILABLE: '%s' (keeping '%s').", s, botname);
       jnick_juped = 2;
@@ -1214,12 +1215,12 @@ static int gotnick(char *from, char *msg)
     tried_jupenick = 0;
     tried_nick = 0;
 
-    if (jupenick[0] && !rfc_casecmp(msg, jupenick)) {
+    if (jupenick[0] && !rfc_ncasecmp(msg, jupenick, nick_len)) {
       altnick_char = rolls = 0;
       putlog(LOG_SERV | LOG_MISC, "*", "Regained jupenick '%s'.", msg);
       jnick_juped = 0;
       nick_juped = 0; // Unset this, no reason for it now.
-    } else if (!strcmp(msg, origbotname)) {
+    } else if (!strncmp(msg, origbotname, nick_len)) {
       altnick_char = rolls = 0;
       putlog(LOG_SERV | LOG_MISC, "*", "Regained nickname '%s'.", msg);
       nick_juped = 0;

+ 16 - 9
src/rfc1459.c

@@ -28,22 +28,29 @@
 #include "rfc1459.h"
 
 int (*rfc_casecmp) (const char *, const char *) = _rfc_casecmp;
+int (*rfc_ncasecmp) (const char *, const char *, size_t) = _rfc_ncasecmp;
 int (*rfc_toupper) (int) = _rfc_toupper;
 
 int
 _rfc_casecmp(const char *s1, const char *s2)
 {
-  register unsigned char *str1 = (unsigned char *) s1;
-  register unsigned char *str2 = (unsigned char *) s2;
-  register int res;
+  while ((*s1) && (*s2) && (rfc_toupper(*s1) == rfc_toupper(*s2))) {
+    ++s1;
+    ++s2;
+  }
+  return rfc_toupper(*s1) - rfc_toupper(*s2);
+}
 
-  while (!(res = rfc_toupper(*str1) - rfc_toupper(*str2))) {
-    if (*str1 == '\0')
-      return 0;
-    str1++;
-    str2++;
+int
+_rfc_ncasecmp(const char *s1, const char *s2, size_t n)
+{
+  if (!n)
+    return 0;
+  while (--n && (*s1) && (*s2) && (rfc_toupper(*s1) == rfc_toupper(*s2))) {
+    ++s1;
+    ++s2;
   }
-  return (res);
+  return rfc_toupper(*s1) - rfc_toupper(*s2);
 }
 
 unsigned char rfc_touppertab[] = { 0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xa,

+ 2 - 0
src/rfc1459.h

@@ -2,9 +2,11 @@
 #define _RFC1459_H
 
 int _rfc_casecmp(const char *, const char *);
+int _rfc_ncasecmp(const char *, const char *, size_t);
 int _rfc_toupper(int);
 
 extern int (*rfc_casecmp) (const char *, const char *);
+extern int (*rfc_ncasecmp) (const char *, const char *, size_t);
 extern int (*rfc_toupper) (int);
 
 #endif /* !_RFC1459_H */