X-Git-Url: https://jfr.im/git/irc/quakenet/newserv.git/blobdiff_plain/0f402ca493cf3e63e2b8f195e7b8c4c9887a8643..211567363bd8bfbd70cef81e4208ea02d49ebb55:/newsearch/ns-eq.c diff --git a/newsearch/ns-eq.c b/newsearch/ns-eq.c index e1f3116f..99ee0842 100644 --- a/newsearch/ns-eq.c +++ b/newsearch/ns-eq.c @@ -9,14 +9,15 @@ #include struct eq_localdata { + int type; int count; struct searchNode **nodes; }; -void eq_free(struct searchNode *thenode); -void *eq_exe(struct searchNode *thenode, int type, void *theinput); +void eq_free(searchCtx *ctx, struct searchNode *thenode); +void *eq_exe(searchCtx *ctx, struct searchNode *thenode, void *theinput); -struct searchNode *eq_parse(int type, int argc, char **argv) { +struct searchNode *eq_parse(searchCtx *ctx, int argc, char **argv) { struct eq_localdata *localdata; struct searchNode *thenode; int i; @@ -47,24 +48,39 @@ struct searchNode *eq_parse(int type, int argc, char **argv) { thenode->free = eq_free; for (i=0;inodes[i] = search_parse(type, argv[i]))) { - eq_free(thenode); + /* Parse the node.. */ + localdata->nodes[i] = ctx->parser(ctx, argv[i]); + + /* Subsequent nodes get coerced to match the type of the first node */ + if (i) + localdata->nodes[i]=coerceNode(ctx,localdata->nodes[i],localdata->type); + + /* If a node didn't parse, give up */ + if (!localdata->nodes[i]) { + eq_free(ctx, thenode); return NULL; } + + if (!i) { + /* First arg determines the type */ + localdata->type = localdata->nodes[0]->returntype & RETURNTYPE_TYPE; + } + localdata->count++; } return thenode; } -void eq_free(struct searchNode *thenode) { +void eq_free(searchCtx *ctx, struct searchNode *thenode) { struct eq_localdata *localdata; int i; localdata=thenode->localdata; for (i=0;icount;i++) { - (localdata->nodes[i]->free)(localdata->nodes[i]); + if (localdata->nodes[i]) + (localdata->nodes[i]->free)(ctx, localdata->nodes[i]); } free(localdata->nodes); @@ -72,7 +88,7 @@ void eq_free(struct searchNode *thenode) { free(thenode); } -void *eq_exe(struct searchNode *thenode, int type, void *theinput) { +void *eq_exe(searchCtx *ctx, struct searchNode *thenode, void *theinput) { int i; char *strval; int intval; @@ -82,40 +98,37 @@ void *eq_exe(struct searchNode *thenode, int type, void *theinput) { localdata=thenode->localdata; if (localdata->count==0) - return trueval(type); + return (void *)1; - switch (localdata->nodes[0]->returntype & RETURNTYPE_TYPE) { + switch (localdata->type) { case RETURNTYPE_INT: - intval = (int)(localdata->nodes[0]->exe)(localdata->nodes[0], RETURNTYPE_INT, theinput); + intval = (int)((long)(localdata->nodes[0]->exe)(ctx, localdata->nodes[0], theinput)); for (i=1;icount;i++) { - if ((int)(localdata->nodes[i]->exe)(localdata->nodes[i], RETURNTYPE_INT, theinput) != intval) - return falseval(type); + if ((int)((long)(localdata->nodes[i]->exe)(ctx, localdata->nodes[i], theinput) != intval)) + return (void *)0; } - - return trueval(type); + return (void *)1; case RETURNTYPE_BOOL: - intval = (int)(localdata->nodes[0]->exe)(localdata->nodes[0], RETURNTYPE_BOOL, theinput); + intval = (int)((long)(localdata->nodes[0]->exe)(ctx, localdata->nodes[0], theinput)); for (i=1;icount;i++) { - rval=(int)(localdata->nodes[i]->exe)(localdata->nodes[i], RETURNTYPE_BOOL, theinput); + rval=(int)((long)(localdata->nodes[i]->exe)(ctx, localdata->nodes[i], theinput)); if ((rval && !intval) || (!rval && intval)) { /* LOGICAL XOR GOES HERE FS */ - return falseval(type); + return (void *)0; } } - - return trueval(type); + return (void *)1; case RETURNTYPE_STRING: - strval = (char *)(localdata->nodes[0]->exe)(localdata->nodes[0], RETURNTYPE_STRING, theinput); + strval = (char *)(localdata->nodes[0]->exe)(ctx, localdata->nodes[0], theinput); for (i=1;icount;i++) { - if (ircd_strcmp(strval, (char *)(localdata->nodes[i]->exe)(localdata->nodes[i], RETURNTYPE_STRING, theinput))) - return falseval(type); + if (ircd_strcmp(strval, (char *)(localdata->nodes[i]->exe)(ctx, localdata->nodes[i], theinput))) + return (void *)0; } - - return trueval(type); + return (void *)1; default: - return falseval(type); + return (void *)0; } }