X-Git-Url: https://jfr.im/git/irc/quakenet/newserv.git/blobdiff_plain/c7f7a584fd6c8ee4a0ede6e79e8ce2177ab863f0..8855bb48b449ed06cfd3ce528b3c0a77c37cb24b:/newsearch/ns-modes.c?ds=sidebyside diff --git a/newsearch/ns-modes.c b/newsearch/ns-modes.c index 621bc8ca..c77c3227 100644 --- a/newsearch/ns-modes.c +++ b/newsearch/ns-modes.c @@ -8,34 +8,29 @@ #include struct modes_localdata { - int type; flag_t setmodes; flag_t clearmodes; }; -void *modes_exe(struct searchNode *thenode, 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; } @@ -45,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)))) { @@ -69,7 +69,7 @@ struct searchNode *modes_parse(int type, int argc, char **argv) { return thenode; } -void *modes_exe(struct searchNode *thenode, void *value) { +void *modes_exe(searchCtx *ctx, struct searchNode *thenode, void *value) { struct modes_localdata *localdata; nick *np; chanindex *cip; @@ -77,20 +77,15 @@ void *modes_exe(struct searchNode *thenode, 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; } @@ -103,7 +98,7 @@ void *modes_exe(struct searchNode *thenode, void *value) { return (void *)1; } -void modes_free(struct searchNode *thenode) { +void modes_free(searchCtx *ctx, struct searchNode *thenode) { free (thenode->localdata); free (thenode); }