Author: Thomas Helvey <tom.helvey@cox.net> Message: Add hasher, fix bugster
authorThomas Helvey <tom.helvey@cox.net>
Sun, 12 Jan 2003 23:54:36 +0000 (23:54 +0000)
committerThomas Helvey <tom.helvey@cox.net>
Sun, 12 Jan 2003 23:54:36 +0000 (23:54 +0000)
git-svn-id: file:///home/klmitch/undernet-ircu/undernet-ircu-svn/ircu2/trunk@916 c9e4aea6-c8fd-4c43-8297-357d70d61c8c

ChangeLog
include/class.h
include/ircd_string.h
ircd/class.c
ircd/gline.c
ircd/ircd_string.c

index 9a954dd865d2b397cbf5866701f1ef17da4319a9..d5ee7d961aaf9a6ccb1d06ddc73885522f6b1756 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2003-01-12  Thomas Helvey <tom.helvey@cox.net>
+       * include/class.h, include/ircd_string.h, ircd/class.c,
+       ircd/gline.c, ircd_string.c: Fix undefined order
+       of evaluation bug in gline.c, add general purpose hasher for
+       conf entries. 
 2003-01-11  Thomas Helvey <tom.helvey@cox.net>
        * include/channel.h, include/ircd_alloc.h, ircd/channel.c,
        ircd/client.c, ircd/gline.c, ircd/ircd_alloc.c,
index df53e164d224bd70116fe003d79bf93047fbeda7..27211c9e1cf0db7ba70afba5d721e574ccc58c27 100644 (file)
@@ -80,7 +80,8 @@ extern char *get_conf_class(const struct ConfItem *aconf);
 extern int get_conf_ping(const struct ConfItem *aconf);
 extern char *get_client_class(struct Client *acptr);
 extern void add_class(char *name, unsigned int ping,
-                      unsigned int confreq, unsigned int maxli, unsigned int sendq);
+                      unsigned int confreq, unsigned int maxli,
+                      unsigned int sendq);
 extern void check_class(void);
 extern void report_classes(struct Client *sptr, struct StatDesc *sd, int stat,
                            char *param);
index 3f97249cdb03b11d976c7acdc6e704d4af1e6a61..af2584ec029a0ad1aff09cc8b762759f1b93e351 100644 (file)
@@ -23,11 +23,15 @@ extern int string_is_hostname(const char* str);
 extern int string_is_address(const char* str);
 extern int string_has_wildcards(const char* str);
 
+/*! Return hash for string using PJW algorithm */
+extern unsigned hash_pjw(const char* str);
 extern char*       ircd_strncpy(char* dest, const char* src, size_t len);
 extern int         ircd_strcmp(const char *a, const char *b);
 extern int         ircd_strncmp(const char *a, const char *b, size_t n);
-extern int         unique_name_vector(char* names, char token, char** vector, int size);
-extern int         token_vector(char* names, char token, char** vector, int size);
+extern int         unique_name_vector(char* names, char token,
+                                      char** vector, int size);
+extern int         token_vector(char* names, char token,
+                                char** vector, int size);
 extern const char* ircd_ntoa(const char* addr);
 extern const char* ircd_ntoa_r(char* buf, const char* addr);
 extern char*       host_from_uh(char* buf, const char* userhost, size_t len);
index c922dbb686655dddae50100e8282b1cacd93e5c7..bf099f964f5a66ed8ca05478e5a1129bc8654eb8 100644 (file)
@@ -119,7 +119,8 @@ void class_delete_marked(void)
 
   for (prev = cl = connClassList; cl; cl = prev->next) {
     Debug((DEBUG_DEBUG, "Class %s : CF: %d PF: %d ML: %d LI: %d SQ: %d",
-           ConClass(cl), ConFreq(cl), PingFreq(cl), MaxLinks(cl), Links(cl), MaxSendq(cl)));
+           ConClass(cl), ConFreq(cl), PingFreq(cl), MaxLinks(cl),
+           Links(cl), MaxSendq(cl)));
     /*
      * unlink marked classes, delete unreferenced ones
      */
@@ -270,7 +271,8 @@ get_sendq(struct Client *cptr)
 void class_send_meminfo(struct Client* cptr)
 {
   send_reply(cptr, SND_EXPLICIT | RPL_STATSDEBUG, ":Classes: inuse: %d(%d)",
-             connClassAllocCount, connClassAllocCount * sizeof(struct ConnectionClass));
+             connClassAllocCount,
+             connClassAllocCount * sizeof(struct ConnectionClass));
 }
 
 
index e2672f457a4fbdec703ee8881c7bbf91ec1d5157..23a254f30f3a7a963cc49d07f596c55fa5f5cad1 100644 (file)
@@ -242,7 +242,8 @@ gline_checkmask(char *mask)
     } else if (*mask == '*' || *mask == '?')
       flags |= MASK_WILD_0 | MASK_WILDS; /* found a wildcard */
     else if (*mask == '/') { /* n.n.n.n/n notation; parse bit specifier */
-      ipmask = strtoul(++mask, &mask, 10);
+      ++mask;
+      ipmask = strtoul(mask, &mask, 10);
 
       if (*mask || dots != 3 || ipmask > 32 || /* sanity-check to date */
          (flags & (MASK_WILDS | MASK_IP)) != MASK_IP)
index aaf782631e7852f9364d16fab81248dba24d3f82..dc3886ef51ed680809a08e2b28001a94b0a3d0da 100644 (file)
@@ -45,7 +45,8 @@ static const char* hostExpr = "^([-0-9A-Za-z]*[0-9A-Za-z]\\.)+[A-Za-z]+$";
 static regex_t hostRegex;
 
 static const char* addrExpr =
-    "^((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])\\.){1,3}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])$";
+    "^((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])\\.){1,3}"
+    "(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])$";
 static regex_t addrRegex;
 
 int init_string(void)
@@ -91,6 +92,22 @@ int string_has_wildcards(const char* str)
   return 0;
 }
 
+unsigned int hash_pjw(const char* str)
+{
+  unsigned h = 0;
+  unsigned g;
+  assert(str);
+
+  for ( ; *str; ++str) {
+    h = (h << 4) + *str;
+    if ((g = h & 0xf0000000)) {
+      h ^= g >> 24;  /* fold top four bits onto ------X- */
+      h ^= g;        /* clear top four bits */
+    }
+  }
+  return h;
+}
+
 /*
  * strtoken.c
  *