added gnutls backend and moved backend code into new files
[ircu2.10.12-pk.git] / ircd / whowas.c
index b8fc1734eb3fd4cf91b36f9f44c868d7b9702165..fed3fffe748325630e016e8aa9efa6971357ac80 100644 (file)
@@ -40,6 +40,7 @@
 #include "ircd_alloc.h"
 #include "ircd_chattr.h"
 #include "ircd_features.h"
+#include "ircd_log.h"
 #include "ircd_string.h"
 #include "list.h"
 #include "numeric.h"
@@ -51,7 +52,7 @@
 #include "sys.h"
 #include "msg.h"
 
-#include <assert.h>
+/* #include <assert.h> -- Now using assert in ircd_log.h */
 #include <stdlib.h>
 #include <string.h>
 
@@ -74,7 +75,7 @@ struct Whowas* whowashash[WW_MAX];
  * like MODE +o &lt;nick>, KICK #chan &lt;nick>, KILL &lt;nick> etc), there is no
  * real important reason for a nick history anymore.
  * Nevertheless, there are two reason why we might want to keep it:
- * @li The /WHOWAS command, which is often useful to catch harrassing
+ * @li The /WHOWAS command, which is often useful to catch harassing
  *    users or abusers in general.
  * @li Clients still use the normal nicks in the client-server protocol,
  *    and it might be considered a nice feature that here we still have
@@ -106,7 +107,7 @@ struct Whowas* whowashash[WW_MAX];
  *    point to the start of the 'hash list': all entries with the same hashv.
  *    We'll have to search this list to find the entry with the correct &lt;nick>.
  *    Once we found the correct whowas entry, we have a pointer to the
- *    corresponding client - if still online - for nich chasing purposes.
+ *    corresponding client - if still online - for nick chasing purposes.
  *    Note that the same nick can occur multiple times in the whowas history,
  *    each of these having the same hash value of course.  While a /WHOWAS on
  *    just a nick will return all entries, nick chasing will only find the
@@ -208,18 +209,6 @@ whowas_free(struct Whowas *ww)
   wwList.ww_alloc--;
 }
 
-/** Initialize a whowas record.
- * @param[in,out] ww Whowas record to initialize.
- * @return The pointer \a ww.
- */
-static struct Whowas *
-whowas_init(struct Whowas *ww)
-{
-  if (ww)
-    memset(ww, 0, sizeof(*ww));
-  return ww;
-}
-
 /** Return a fresh Whowas record.
  * If the total number of records is smaller than determined by
  * FEAT_NICKNAMEHISTORYLENGTH, allocate a new one.  Otherwise,
@@ -229,11 +218,20 @@ whowas_init(struct Whowas *ww)
 static struct Whowas *
 whowas_alloc(void)
 {
-  if (wwList.ww_alloc >= feature_int(FEAT_NICKNAMEHISTORYLENGTH))
-    return whowas_init(whowas_clean(wwList.ww_tail));
+  struct Whowas *ww;
 
-  wwList.ww_alloc++; /* going to allocate a new one... */
-  return whowas_init((struct Whowas *) MyMalloc(sizeof(struct Whowas)));
+  if (wwList.ww_alloc >= feature_int(FEAT_NICKNAMEHISTORYLENGTH)) {
+    /* reclaim the oldest whowas entry */
+    ww = whowas_clean(wwList.ww_tail);
+  } else {
+    /* allocate a new one */
+    wwList.ww_alloc++;
+    ww = (struct Whowas *) MyMalloc(sizeof(struct Whowas));
+  }
+
+  assert(ww != NULL);
+  memset(ww, 0, sizeof(*ww));
+  return ww;
 }
 
 /** If necessary, trim the whowas list.