]> jfr.im git - irc/quakenet/newserv.git/commitdiff
Split whowas into two modules.
authorGunnar Beutner <redacted>
Sun, 4 Aug 2013 22:11:57 +0000 (00:11 +0200)
committerGunnar Beutner <redacted>
Sun, 4 Aug 2013 22:11:57 +0000 (00:11 +0200)
--HG--
branch : shroudtrusts

whowas/Makefile
whowas/whowas.c
whowas/whowas.h
whowas/whowas_commands.c [new file with mode: 0644]

index d22c5b5c67749838a40784673ef67fc3b8906f71..d144a691c02266fd2aa1c48dc9341a3b5def144a 100644 (file)
@@ -1,5 +1,7 @@
 include ../build.mk
 .PHONY: all
-all: whowas.so
+all: whowas.so whowas_commands.so
 
 whowas.so: whowas.o
+
+whowas_commands.so: whowas_commands.o
index 2132e90f7a5048a0aa0812e89ecadf5487febb25..6ce62d80ec55712fe10fb0c56a42b3ef0c0fe037 100644 (file)
@@ -4,52 +4,18 @@
 #include "../control/control.h"
 #include "../irc/irc.h"
 #include "../lib/irc_string.h"
+#include "../lib/version.h"
 #include "whowas.h"
 
-static whowas *wwhead, *wwtail;
-static int wwcount;
+MODULE_VERSION("");
 
-int ww_cmdwhowas(void *source, int cargc, char **cargv) {
-  nick *np = source;
-  char *pattern;
-  whowas *ww;
-  char hostmask[WW_MASKLEN+1];
-  char timebuf[30];
-  int matches = 0, limit = 500;
-
-  if(cargc<1)
-    return CMD_USAGE;
-
-  pattern = cargv[0];
-
-  if(cargc>1)
-    limit = strtol(cargv[1], NULL, 10);
-
-  for(ww=wwhead;ww;ww=ww->next) {
-    snprintf(hostmask, sizeof(hostmask), "%s!%s@%s", ww->nick, ww->ident, ww->host);
-
-    if (match2strings(pattern, hostmask)) {
-      matches++;
-
-      if(matches<=limit) {
-        strftime(timebuf, 30, "%d/%m/%y %H:%M:%S", localtime(&(ww->seen)));
+whowas *whowas_head = NULL, *whowas_tail = NULL;
+int whowas_count = 0;
 
-        controlreply(np, "[%s] %s (%s): %s", timebuf, hostmask, ww->realname, ww->reason->content);
-      } else if(matches==limit+1) {
-        controlreply(np, "--- More than %d matches, skipping the rest", limit);
-      }
-    }
-  }
-
-  controlreply(np, "--- Found %d entries.", matches);
-
-  return CMD_OK;
-}
-
-void ww_handlequitorkill(int hooknum, void *arg) {
-  void **args=arg;
-  nick *np=args[0];
-  char *reason=args[1];
+static void ww_handlequitorkill(int hooknum, void *arg) {
+  void **args = arg;
+  nick *np = args[0];
+  char *reason = args[1];
   char *rreason;
   char resbuf[512];
   whowas *ww;
@@ -58,15 +24,15 @@ void ww_handlequitorkill(int hooknum, void *arg) {
   time(&now);
 
   /* Clean up old records. */
-  while((ww = wwtail) && (ww->seen < now - WW_MAXAGE || wwcount >= WW_MAXENTRIES)) {
-    wwtail = ww->prev;
+  while ((ww = whowas_tail) && (ww->seen < now - WW_MAXAGE || whowas_count >= WW_MAXENTRIES)) {
+    whowas_tail = ww->prev;
 
     if (ww->prev)
       ww->prev->next = NULL;
     else
-      wwhead = ww->prev;
+      whowas_head = ww->prev;
 
-    wwcount--;
+    whowas_count--;
     free(ww);
   }
 
@@ -78,32 +44,30 @@ void ww_handlequitorkill(int hooknum, void *arg) {
   strncpy(ww->realname, np->realname->name->content, REALLEN);
   ww->seen = getnettime();
 
-  if(hooknum==HOOK_NICK_KILL && (rreason=strchr(reason,' '))) {
-    sprintf(resbuf,"Killed%s",rreason);
-    reason=resbuf;
+  if (hooknum == HOOK_NICK_KILL && (rreason = strchr(reason, ' '))) {
+    sprintf(resbuf, "Killed%s", rreason);
+    reason = resbuf;
   }
 
   ww->reason = getsstring(reason, WW_REASONLEN);
 
-  if(wwhead)
-    wwhead->prev = ww;
+  if (whowas_head)
+    whowas_head->prev = ww;
 
-  ww->next = wwhead;
-  wwhead = ww;
+  ww->next = whowas_head;
+  whowas_head = ww;
 
   ww->prev = NULL;
 
-  if(!wwtail)
-    wwtail = ww;
+  if (!whowas_tail)
+    whowas_tail = ww;
 
-  wwcount++;
+  whowas_count++;
 }
 
 void _init(void) {
   registerhook(HOOK_NICK_QUIT, ww_handlequitorkill);
   registerhook(HOOK_NICK_KILL, ww_handlequitorkill);
-
-  registercontrolhelpcmd("whowas", NO_OPER, 2, &ww_cmdwhowas, "Usage: whowas <mask> ?limit?\nLooks up information about recently disconnected users.");
 }
 
 void _fini(void) {
@@ -112,10 +76,8 @@ void _fini(void) {
   deregisterhook(HOOK_NICK_QUIT, ww_handlequitorkill);
   deregisterhook(HOOK_NICK_KILL, ww_handlequitorkill);
 
-  deregistercontrolcmd("whowas", &ww_cmdwhowas);
-
-  while((ww = wwhead)) {
-    wwhead = ww->next;
+  while ((ww = whowas_head)) {
+    whowas_head = ww->next;
     free(ww);
   }
 }
index f98074bee07899f35cbfcbcb2ed895d6dea0e198..217a85f6f0decc92ef0956beb141bb49ba4eed04 100644 (file)
@@ -4,10 +4,10 @@
 #define WW_REASONLEN 512
 
 typedef struct whowas {
-  char nick[NICKLEN+1];
-  char ident[USERLEN+1];
-  char host[HOSTLEN+1];
-  char realname[REALLEN+1];
+  char nick[NICKLEN + 1];
+  char ident[USERLEN + 1];
+  char host[HOSTLEN + 1];
+  char realname[REALLEN + 1];
   sstring *reason;
 
   time_t seen;
@@ -15,3 +15,7 @@ typedef struct whowas {
   struct whowas *next;
   struct whowas *prev;
 } whowas;
+
+extern whowas *whowas_head, *whowas_tail;
+extern int whowas_count;
+
diff --git a/whowas/whowas_commands.c b/whowas/whowas_commands.c
new file mode 100644 (file)
index 0000000..90e37ff
--- /dev/null
@@ -0,0 +1,55 @@
+#include <stdio.h>
+#include <string.h>
+#include "../core/hooks.h"
+#include "../control/control.h"
+#include "../irc/irc.h"
+#include "../lib/irc_string.h"
+#include "../lib/version.h"
+#include "whowas.h"
+
+MODULE_VERSION("");
+
+static int ww_cmdwhowas(void *source, int cargc, char **cargv) {
+  nick *np = source;
+  char *pattern;
+  whowas *ww;
+  char hostmask[WW_MASKLEN + 1];
+  char timebuf[30];
+  int matches = 0, limit = 500;
+
+  if (cargc < 1)
+    return CMD_USAGE;
+
+  pattern = cargv[0];
+
+  if (cargc > 1)
+    limit = strtol(cargv[1], NULL, 10);
+
+  for (ww = whowas_head; ww; ww = ww->next) {
+    snprintf(hostmask, sizeof(hostmask), "%s!%s@%s", ww->nick, ww->ident, ww->host);
+
+    if (match2strings(pattern, hostmask)) {
+      matches++;
+
+      if (matches <= limit) {
+        strftime(timebuf, 30, "%d/%m/%y %H:%M:%S", localtime(&(ww->seen)));
+
+        controlreply(np, "[%s] %s (%s): %s", timebuf, hostmask, ww->realname, ww->reason->content);
+      } else if (matches == limit + 1) {
+        controlreply(np, "--- More than %d matches, skipping the rest", limit);
+      }
+    }
+  }
+
+  controlreply(np, "--- Found %d entries.", matches);
+
+  return CMD_OK;
+}
+
+void _init(void) {
+  registercontrolhelpcmd("whowas", NO_OPER, 2, &ww_cmdwhowas, "Usage: whowas <mask> ?limit?\nLooks up information about recently disconnected users.");
+}
+
+void _fini(void) {
+  deregistercontrolcmd("whowas", &ww_cmdwhowas);
+}