]> jfr.im git - irc/quakenet/newserv.git/blobdiff - newsearch/newsearch.c
nickwatch: Implement hook for messages/notices.
[irc/quakenet/newserv.git] / newsearch / newsearch.c
index 782e59bf0a3271c9a06035df775b3a1e477fef18..0b08bdfb73daa5b7c574e1149f39b6a5646fc66a 100644 (file)
@@ -211,6 +211,7 @@ void _init() {
   registersearchterm(reg_whowassearch, "cidr",cidr_parse, 0, "CIDR matching");
   registersearchterm(reg_nicksearch, "ipvsix",ipv6_parse, 0, "IPv6 user");
   registersearchterm(reg_whowassearch, "ipvsix",ipv6_parse, 0, "IPv6 user");
+  registersearchterm(reg_nicksearch, "message",message_parse, 0, "Last message");
 
   /* Whowas operations */
   registersearchterm(reg_whowassearch, "quit",quit_parse, 0, "User quit");
@@ -218,6 +219,7 @@ void _init() {
   registersearchterm(reg_whowassearch, "renamed",renamed_parse, 0, "User changed nick");
   registersearchterm(reg_whowassearch, "age",age_parse, 0, "Whowas record age in seconds");
   registersearchterm(reg_whowassearch, "newnick",newnick_parse, 0, "New nick (for rename whowas records)");
+  registersearchterm(reg_whowassearch, "reason",reason_parse, 0, "Quit/kill reason");
 
   /* Channel operations */
   registersearchterm(reg_chansearch, "exists",exists_parse, 0, "Returns if channel exists on network. Note: newserv may store data on empty channels");         /* channel only */
@@ -455,7 +457,7 @@ int parseopts(int cargc, char **cargv, int *arg, int *limit, void **subset, void
   return CMD_OK;
 }
 
-void newsearch_ctxinit(searchCtx *ctx, searchParseFunc searchfn, replyFunc replyfn, wallFunc wallfn, void *arg, searchCmd *cmd, nick *np, void *displayfn, int limit) {
+void newsearch_ctxinit(searchCtx *ctx, searchParseFunc searchfn, replyFunc replyfn, wallFunc wallfn, void *arg, searchCmd *cmd, nick *np, void *displayfn, int limit, void *target) {
   memset(ctx, 0, sizeof(searchCtx));
   
   ctx->reply = replyfn;
@@ -465,6 +467,7 @@ void newsearch_ctxinit(searchCtx *ctx, searchParseFunc searchfn, replyFunc reply
   ctx->searchcmd = cmd;
   ctx->sender = np;
   ctx->limit = limit;
+  ctx->target = target;
   ctx->displayfn = displayfn;
 }
 
@@ -501,7 +504,7 @@ int do_nicksearch_real(replyFunc reply, wallFunc wall, void *source, int cargc,
     return CMD_ERROR;
   }
 
-  ast_nicksearch(tree->root, reply, sender, wall, display, NULL, NULL, limit);
+  ast_nicksearch(tree->root, reply, sender, wall, display, NULL, NULL, limit, NULL);
 
   parse_free(tree);
 
@@ -530,7 +533,7 @@ void nicksearch_exe(struct searchNode *search, searchCtx *ctx) {
   search=coerceNode(ctx, search, RETURNTYPE_BOOL);
   
   for (i=0;i<NICKHASHSIZE;i++) {
-    for (np=nicktable[i];np;np=np->next) {
+    for (np=ctx->target ? ctx->target : nicktable[i];np;np=np->next) {
       if ((search->exe)(ctx, search, np)) {
         /* Add total channels */
         tchans += np->channels->cursi;
@@ -551,9 +554,13 @@ void nicksearch_exe(struct searchNode *search, searchCtx *ctx) {
          ctx->reply(sender, "--- More than %d matches, skipping the rest",limit);
        matches++;
       }
+
+      if (ctx->target)
+        goto done;
     }
   }
 
+done:
   ctx->reply(sender,"--- End of list: %d matches; users were on %u channels (%u unique, %.1f average clones)", 
                 matches, tchans, uchans, (float)tchans/uchans);
 }
@@ -591,7 +598,7 @@ int do_whowassearch_real(replyFunc reply, wallFunc wall, void *source, int cargc
     return CMD_ERROR;
   }
 
-  ast_whowassearch(tree->root, reply, sender, wall, display, NULL, NULL, limit);
+  ast_whowassearch(tree->root, reply, sender, wall, display, NULL, NULL, limit, NULL);
 
   parse_free(tree);
 
@@ -614,10 +621,14 @@ void whowassearch_exe(struct searchNode *search, searchCtx *ctx) {
   search=coerceNode(ctx, search, RETURNTYPE_BOOL);
 
   for (i = whowasoffset; i < whowasoffset + WW_MAXENTRIES; i++) {
-    ww = &whowasrecs[i % WW_MAXENTRIES];
+    if (ctx->target) {
+      ww = ctx->target;
+    } else {
+      ww = &whowasrecs[i % WW_MAXENTRIES];
 
-    if (ww->type == WHOWAS_UNUSED)
-      continue;
+      if (ww->type == WHOWAS_UNUSED)
+        continue;
+    }
 
     /* Note: We're passing the nick to the filter function. The original
      * whowas record is in the nick's ->next field. */
@@ -629,6 +640,9 @@ void whowassearch_exe(struct searchNode *search, searchCtx *ctx) {
         ctx->reply(sender, "--- More than %d matches, skipping the rest",limit);
       matches++;
     }
+
+    if (ctx->target)
+      break;
   }
 
   ctx->reply(sender,"--- End of list: %d matches", matches);
@@ -667,7 +681,7 @@ int do_chansearch_real(replyFunc reply, wallFunc wall, void *source, int cargc,
     return CMD_ERROR;
   }
 
-  ast_chansearch(tree->root, reply, sender, wall, display, NULL, NULL, limit);
+  ast_chansearch(tree->root, reply, sender, wall, display, NULL, NULL, limit, NULL);
 
   parse_free(tree);
 
@@ -690,17 +704,21 @@ void chansearch_exe(struct searchNode *search, searchCtx *ctx) {
   search=coerceNode(ctx, search, RETURNTYPE_BOOL);
   
   for (i=0;i<CHANNELHASHSIZE;i++) {
-    for (cip=chantable[i];cip;cip=cip->next) {
+    for (cip=ctx->target ? ctx->target : chantable[i];cip;cip=cip->next) {
       if ((search->exe)(ctx, search, cip)) {
        if (matches<limit)
          display(ctx, sender, cip);
        if (matches==limit)
          ctx->reply(sender, "--- More than %d matches, skipping the rest",limit);
        matches++;
+
+        if (ctx->target)
+          goto done;
       }
     }
   }
 
+done:
   ctx->reply(sender,"--- End of list: %d matches", matches);
 }
 
@@ -737,7 +755,7 @@ int do_usersearch_real(replyFunc reply, wallFunc wall, void *source, int cargc,
     return CMD_ERROR;
   }
 
-  ast_usersearch(tree->root, reply, sender, wall, display, NULL, NULL, limit);
+  ast_usersearch(tree->root, reply, sender, wall, display, NULL, NULL, limit, NULL);
 
   parse_free(tree);
 
@@ -760,7 +778,7 @@ void usersearch_exe(struct searchNode *search, searchCtx *ctx) {
   search=coerceNode(ctx, search, RETURNTYPE_BOOL);
   
   for (i=0;i<AUTHNAMEHASHSIZE;i++) {
-    for (aup=authnametable[i];aup;aup=aup->next) {
+    for (aup=ctx->target ? ctx->target : authnametable[i];aup;aup=aup->next) {
       if ((search->exe)(ctx, search, aup)) {
        if (matches<limit)
          display(ctx, sender, aup);
@@ -768,9 +786,13 @@ void usersearch_exe(struct searchNode *search, searchCtx *ctx) {
          ctx->reply(sender, "--- More than %d matches, skipping the rest",limit);
        matches++;
       }
+
+      if (ctx->target)
+        goto done;
     }
   }
 
+done:
   ctx->reply(sender,"--- End of list: %d matches", matches);
 }