Author: Thomas Helvey <tom.helvey@cox.net> Message: Add hasher, fix bugster
[ircu2.10.12-pk.git] / ircd / class.c
index 58acaf880ef0961950d174498e79091ca9aefd53..bf099f964f5a66ed8ca05478e5a1129bc8654eb8 100644 (file)
@@ -52,6 +52,7 @@ struct ConnectionClass* make_class(void)
   struct ConnectionClass *tmp;
 
   tmp = (struct ConnectionClass*) MyMalloc(sizeof(struct ConnectionClass));
+  tmp->ref_count = 1;
   assert(0 != tmp);
   ++connClassAllocCount;
   return tmp;
@@ -59,10 +60,11 @@ struct ConnectionClass* make_class(void)
 
 void free_class(struct ConnectionClass* p)
 {
-  if (p) {
+  if (p)
+  {
     assert(0 == p->valid);
     if (p->cc_name)
-     MyFree(p->cc_name);
+      MyFree(p->cc_name);
     MyFree(p);
     --connClassAllocCount;
   }
@@ -117,15 +119,17 @@ 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
      */
     if (cl->valid)
       prev = cl;
-    else {
+    else
+    {
       prev->next = cl->next;
-      if (0 == cl->ref_count)
+      if (0 == --cl->ref_count)
         free_class(cl);
     }
   }
@@ -163,42 +167,12 @@ get_client_class(struct Client *acptr)
   if (acptr && !IsMe(acptr) && (cli_confs(acptr)))
     for (tmp = cli_confs(acptr); tmp; tmp = tmp->next)
     {
-      if (tmp->value.aconf && !(cl = tmp->value.aconf->conn_class))
+      if (tmp->value.aconf && (cl = tmp->value.aconf->conn_class))
         return ConClass(cl);
     }
   return "(null-class)";
 }
 
-unsigned int get_client_ping(struct Client *acptr)
-{
-  unsigned int ping = 0;
-  unsigned int ping2;
-  struct ConfItem *aconf;
-  struct SLink *link;
-
-  link = cli_confs(acptr);
-
-  if (link) {
-    while (link) {
-      aconf = link->value.aconf;
-      if (aconf->status & (CONF_CLIENT | CONF_SERVER)) {
-        ping2 = get_conf_ping(aconf);
-        if ((ping2 != BAD_PING) && ((ping > ping2) || !ping))
-          ping = ping2;
-      }
-      link = link->next;
-    }
-  }
-  else {
-    ping = feature_int(FEAT_PINGFREQUENCY);
-    Debug((DEBUG_DEBUG, "No Attached Confs for: %s", cli_name(acptr)));
-  }
-  if (ping <= 0)
-    ping = feature_int(FEAT_PINGFREQUENCY);
-  Debug((DEBUG_DEBUG, "Client %s Ping %d", cli_name(acptr), ping));
-  return (ping);
-}
-
 unsigned int get_con_freq(struct ConnectionClass * clptr)
 {
   if (clptr)
@@ -228,7 +202,11 @@ void add_class(char *name, unsigned int ping, unsigned int confreq,
     t->next = p;
   }
   else
+  {
+    if (ConClass(t) != NULL)
+      MyFree(ConClass(t));
     p = t;
+  }
   Debug((DEBUG_DEBUG, "Add Class %s: cf: %u pf: %u ml: %u sq: %d",
          name, confreq, ping, maxli, sendq));
   ConClass(p) = name;
@@ -254,7 +232,8 @@ struct ConnectionClass* find_class(const char *name)
 }
 
 void
-report_classes(struct Client *sptr)
+report_classes(struct Client *sptr, struct StatDesc *sd, int stat,
+               char *param)
 {
   struct ConnectionClass *cltmp;
 
@@ -292,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));
 }