]> jfr.im git - irc/quakenet/newserv.git/blobdiff - newsearch/newsearch.c
newsearch: Implement channel operator for whowassearch.
[irc/quakenet/newserv.git] / newsearch / newsearch.c
index 6d76342ceb7f5a8ec6b796d93e4ba3bfd98fb7ee..f48e6e9b62addd198e1486efcd4ff552b70982ea 100644 (file)
@@ -1,6 +1,7 @@
 #include <stdio.h>
 #include <stdarg.h>
 #include <string.h>
+#include <assert.h>
 
 #include "../irc/irc_config.h"
 #include "../lib/irc_string.h"
@@ -195,7 +196,8 @@ void _init() {
   registersearchterm(reg_whowassearch, "ident",ident_parse, 0, "User's current ident");
   registersearchterm(reg_nicksearch, "host",host_parse, 0, "User's host, allow \"host real\" to match real host");
   registersearchterm(reg_whowassearch, "host",host_parse, 0, "User's host, allow \"host real\" to match real host");             
-  registersearchterm(reg_nicksearch, "channel",channel_parse, 0, "Valid Channel Name to match users against");       /* nick only */
+  registersearchterm(reg_nicksearch, "channel",channel_parse, 0, "Valid Channel Name to match users against");
+  registersearchterm(reg_whowassearch, "channel",channel_parse, 0, "Valid Channel Name to match users against");       
   registersearchterm(reg_nicksearch, "timestamp",timestamp_parse, 0, "User's Timestamp");
   registersearchterm(reg_whowassearch, "timestamp",timestamp_parse, 0, "User's Timestamp");
   registersearchterm(reg_nicksearch, "country",country_parse, 0, "2 letter country code (data source is geoip)");
@@ -211,6 +213,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 +221,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 +459,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, array *targets) {
   memset(ctx, 0, sizeof(searchCtx));
   
   ctx->reply = replyfn;
@@ -465,6 +469,7 @@ void newsearch_ctxinit(searchCtx *ctx, searchParseFunc searchfn, replyFunc reply
   ctx->searchcmd = cmd;
   ctx->sender = np;
   ctx->limit = limit;
+  ctx->targets = targets;
   ctx->displayfn = displayfn;
 }
 
@@ -501,7 +506,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);
 
@@ -513,7 +518,7 @@ int do_nicksearch(void *source, int cargc, char **cargv) {
 }
 
 void nicksearch_exe(struct searchNode *search, searchCtx *ctx) {
-  int i, j;
+  int i, j, k;
   int matches = 0;
   unsigned int cmarker;
   unsigned int tchans=0,uchans=0;
@@ -530,7 +535,13 @@ 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=nicktable[i], k = 0;ctx->targets ? (k < ctx->targets->cursi) : (np != NULL);np=np->next, k++) {
+      if (ctx->targets) {
+        np = ((nick **)ctx->targets->content)[k];
+        if (!np)
+          continue;
+      }
+
       if ((search->exe)(ctx, search, np)) {
         /* Add total channels */
         tchans += np->channels->cursi;
@@ -552,6 +563,9 @@ void nicksearch_exe(struct searchNode *search, searchCtx *ctx) {
        matches++;
       }
     }
+
+    if (ctx->targets)
+      break;
   }
 
   ctx->reply(sender,"--- End of list: %d matches; users were on %u channels (%u unique, %.1f average clones)", 
@@ -591,7 +605,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);
 
@@ -610,6 +624,8 @@ void whowassearch_exe(struct searchNode *search, searchCtx *ctx) {
   WhowasDisplayFunc display = ctx->displayfn;
   int limit = ctx->limit;
 
+  assert(!ctx->targets);
+
   /* The top-level node needs to return a BOOL */
   search=coerceNode(ctx, search, RETURNTYPE_BOOL);
 
@@ -667,7 +683,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);
 
@@ -686,7 +702,9 @@ void chansearch_exe(struct searchNode *search, searchCtx *ctx) {
   senderNSExtern = sender;
   ChanDisplayFunc display = ctx->displayfn;
   int limit = ctx->limit;
-  
+
+  assert(!ctx->targets);  
+
   search=coerceNode(ctx, search, RETURNTYPE_BOOL);
   
   for (i=0;i<CHANNELHASHSIZE;i++) {
@@ -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);
 
@@ -757,6 +775,8 @@ void usersearch_exe(struct searchNode *search, searchCtx *ctx) {
   UserDisplayFunc display = ctx->displayfn;
   senderNSExtern = sender;
 
+  assert(!ctx->targets);
+
   search=coerceNode(ctx, search, RETURNTYPE_BOOL);
   
   for (i=0;i<AUTHNAMEHASHSIZE;i++) {
@@ -1036,11 +1056,11 @@ void nssnprintf(char *buf, size_t size, const char *format, nick *np) {
       case 'h':
         c = np->host->name->content; break;
       case 'I':
-        snprintf(hostbuf, sizeof(hostbuf), "%s", IPtostr(np->p_ipaddr));
+        snprintf(hostbuf, sizeof(hostbuf), "%s", IPtostr(np->ipaddress));
         c = hostbuf;
         break;
       case 'u':
-        snprintf(hostbuf, sizeof(hostbuf), "%s!%s@%s", np->nick, np->ident, IPtostr(np->p_ipaddr));
+        snprintf(hostbuf, sizeof(hostbuf), "%s!%s@%s", np->nick, np->ident, IPtostr(np->ipaddress));
         c = hostbuf;
         break;
       default: