]> jfr.im git - irc/quakenet/newserv.git/blobdiff - newsearch/ns-modes.c
merge
[irc/quakenet/newserv.git] / newsearch / ns-modes.c
index d0aa849dc2dded45b86581539f67432724903b7a..c77c32275f8d99ea1542db111dc7a1a0bfbf91b0 100644 (file)
@@ -7,38 +7,30 @@
 #include <stdio.h>
 #include <stdlib.h>
 
-#include "../channel/channel.h"
-#include "../lib/flags.h"
-
 struct modes_localdata {
-  int         type;
   flag_t      setmodes;
   flag_t      clearmodes;
 }; 
 
-void *modes_exe(struct searchNode *thenode, int type, void *theinput);
-void modes_free(struct searchNode *thenode);
+void *modes_exe(searchCtx *ctx, struct searchNode *thenode, void *theinput);
+void modes_free(searchCtx *ctx, struct searchNode *thenode);
 
-struct searchNode *modes_parse(int type, int argc, char **argv) {
+struct searchNode *modes_parse(searchCtx *ctx, int argc, char **argv) {
   struct modes_localdata *localdata;
-  struct searchNode *thenode;
+  struct searchNode *thenode, *modestring;
   const flag *flaglist;
-
+  char *p;
+  
   if (argc!=1) {
     parseError="modes: usage: modes (mode string)";
     return NULL;
   }
     
-  switch (type) {
-  case SEARCHTYPE_CHANNEL:
+  if (ctx->searchcmd == reg_chansearch) {
     flaglist=cmodeflags;
-    break;
-
-  case SEARCHTYPE_NICK:
+  } else if (ctx->searchcmd == reg_nicksearch) {
     flaglist=umodeflags;
-    break;
-
-  default:
+  } else {
     parseError="modes: unsupported search type";
     return NULL;
   }
@@ -48,13 +40,18 @@ struct searchNode *modes_parse(int type, int argc, char **argv) {
     return NULL;
   }
   
-  localdata->type=type;
   localdata->setmodes=0;
   localdata->clearmodes = ~0;
   
-  setflags(&(localdata->setmodes), 0xFFFF, argv[0], flaglist, REJECT_NONE);
-  setflags(&(localdata->clearmodes), 0xFFFF, argv[0], flaglist, REJECT_NONE);
-
+  if (!(modestring=argtoconststr("modes", ctx, argv[0], &p))) {
+    free(localdata);
+    return NULL;
+  }
+  
+  setflags(&(localdata->setmodes), 0xFFFF, p, flaglist, REJECT_NONE);
+  setflags(&(localdata->clearmodes), 0xFFFF, p, flaglist, REJECT_NONE);
+  (modestring->free)(ctx, modestring);
+  
   localdata->clearmodes = ~(localdata->clearmodes);
   
   if (!(thenode=(struct searchNode *)malloc(sizeof(struct searchNode)))) {
@@ -72,7 +69,7 @@ struct searchNode *modes_parse(int type, int argc, char **argv) {
   return thenode;
 }
 
-void *modes_exe(struct searchNode *thenode, int type, void *value) {
+void *modes_exe(searchCtx *ctx, struct searchNode *thenode, void *value) {
   struct modes_localdata *localdata;
   nick *np;
   chanindex *cip;
@@ -80,33 +77,28 @@ void *modes_exe(struct searchNode *thenode, int type, void *value) {
   
   localdata = (struct modes_localdata *)thenode->localdata;
 
-  switch (localdata->type) {
-  case SEARCHTYPE_CHANNEL:
+  if (ctx->searchcmd == reg_chansearch) {
     cip=(chanindex *)value;
     if (!cip->channel)
       return NULL;
     flags=cip->channel->flags;
-    break;
-
-  case SEARCHTYPE_NICK:
+  } else if (ctx->searchcmd == reg_nicksearch) {
     np=(nick *)value;
     flags=np->umodes;
-    break;
-
-  default:
+  } else {
     return NULL;
   }
 
   if (~flags & (localdata->setmodes))
-    return falseval(type);
+    return (void *)0;
 
   if (flags & (localdata->clearmodes))
-    return falseval(type);
+    return (void *)0;
   
-  return trueval(type);
+  return (void *)1;
 }
 
-void modes_free(struct searchNode *thenode) {
+void modes_free(searchCtx *ctx, struct searchNode *thenode) {
   free (thenode->localdata);
   free (thenode);
 }