]> jfr.im git - irc/quakenet/newserv.git/blobdiff - newsearch/ns-channel.c
newsearch: Implement channel operator for whowassearch.
[irc/quakenet/newserv.git] / newsearch / ns-channel.c
index 3a79920f309e0fbdfb011d4438a13d7f65f867da..0d3647751e3af7336a46dee486eb681424009a73 100644 (file)
@@ -14,7 +14,7 @@ void channel_free(searchCtx *ctx, struct searchNode *thenode);
 
 struct searchNode *channel_parse(searchCtx *ctx, int argc, char **argv) {
   struct searchNode *thenode, *convsn;
-  channel *cp;
+  chanindex *cip;
   char *p;
   
   if (argc<1) {
@@ -25,12 +25,8 @@ struct searchNode *channel_parse(searchCtx *ctx, int argc, char **argv) {
   if (!(convsn=argtoconststr("channel", ctx, argv[0], &p)))
     return NULL;
 
-  cp=findchannel(p);
+  cip=findorcreatechanindex(p);
   convsn->free(ctx, convsn);
-  if (!cp) {
-    parseError = "channel: unknown channel";
-    return NULL;
-  }
 
   if (!(thenode=(struct searchNode *)malloc(sizeof (struct searchNode)))) {
     parseError = "malloc: could not allocate memory for this search.";
@@ -38,7 +34,7 @@ struct searchNode *channel_parse(searchCtx *ctx, int argc, char **argv) {
   }
 
   thenode->returntype = RETURNTYPE_BOOL;
-  thenode->localdata = cp;
+  thenode->localdata = cip;
   thenode->exe = channel_exe;
   thenode->free = channel_free;
 
@@ -47,16 +43,32 @@ struct searchNode *channel_parse(searchCtx *ctx, int argc, char **argv) {
 
 void *channel_exe(searchCtx *ctx, struct searchNode *thenode, void *theinput) {
   nick *np = (nick *)theinput;
-  channel *cp = thenode->localdata;
+  chanindex *cip = thenode->localdata;
+  channel *cp;
+  whowas *ww;
+  int i;
 
-  if (getnumerichandlefromchanhash(cp->users, np->numeric)) {
-    return (void *)1;
+  if (ctx->searchcmd == reg_nicksearch) {
+    cp = cip->channel;
+
+    if (!cp)
+      return (void *)0;
+
+    if (getnumerichandlefromchanhash(cp->users, np->numeric))
+      return (void *)1;
   } else {
-    return (void *)0;
+    ww = (whowas *)np->next; /* Eww. */
+
+    for (i = 0; i < WW_MAXCHANNELS; i++)
+      if (ww->channels[i] == cip)
+        return (void *)1;
   }
+
+  return (void *)0;
 }
 
 void channel_free(searchCtx *ctx, struct searchNode *thenode) {
+  releasechanindex(thenode->localdata);
   free(thenode);
 }