X-Git-Url: https://jfr.im/git/irc/quakenet/newserv.git/blobdiff_plain/9d867b50deac9ac18a805962c62584591a70255f..211567363bd8bfbd70cef81e4208ea02d49ebb55:/newsearch/ns-authedpct.c diff --git a/newsearch/ns-authedpct.c b/newsearch/ns-authedpct.c index d12d854e..f8b67dce 100644 --- a/newsearch/ns-authedpct.c +++ b/newsearch/ns-authedpct.c @@ -7,60 +7,34 @@ #include #include -struct authedpct_localdata { - long pct; -}; +void *authedpct_exe(searchCtx *ctx, struct searchNode *thenode, void *theinput); +void authedpct_free(searchCtx *ctx, struct searchNode *thenode); -void *authedpct_exe(struct searchNode *thenode, int type, void *theinput); -void authedpct_free(struct searchNode *thenode); - -struct searchNode *authedpct_parse(int type, int argc, char **argv) { - struct authedpct_localdata *localdata; +struct searchNode *authedpct_parse(searchCtx *ctx, int argc, char **argv) { struct searchNode *thenode; - if (type != SEARCHTYPE_CHANNEL) { - parseError = "authedpct: this function is only valid for channel searches."; - return NULL; - } - - if (argc!=1) { - parseError="authedpct: usage: (authedpct number)"; - return NULL; - } - - if (!(localdata=(struct authedpct_localdata *)malloc(sizeof(struct authedpct_localdata)))) { - parseError = "malloc: could not allocate memory for this search."; - return NULL; - } - - localdata->pct = strtoul(argv[0],NULL,10); - if (!(thenode=(struct searchNode *)malloc(sizeof(struct searchNode)))) { /* couldn't malloc() memory for thenode, so free localdata to avoid leakage */ parseError = "malloc: could not allocate memory for this search."; - free(localdata); return NULL; } - thenode->returntype = RETURNTYPE_BOOL; - thenode->localdata = localdata; + thenode->returntype = RETURNTYPE_INT; + thenode->localdata = NULL; thenode->exe = authedpct_exe; thenode->free = authedpct_free; return thenode; } -void *authedpct_exe(struct searchNode *thenode, int type, void *theinput) { +void *authedpct_exe(searchCtx *ctx, struct searchNode *thenode, void *theinput) { int i; int j=0; nick *np; chanindex *cip = (chanindex *)theinput; - struct authedpct_localdata *localdata; - localdata = thenode->localdata; - if (!cip->channel) - return falseval(type); + return (void *)0; for (i=0;ichannel->users->hashsize;i++) { if (cip->channel->users->content[i]==nouser) @@ -69,15 +43,11 @@ void *authedpct_exe(struct searchNode *thenode, int type, void *theinput) { if ((np=getnickbynumeric(cip->channel->users->content[i])) && IsAccount(np)) j++; } - - if (((j * 100) / cip->channel->users->totalusers) >= localdata->pct) - return trueval(type); - else - return falseval(type); -} -void authedpct_free(struct searchNode *thenode) { - free(thenode->localdata); + return (void *)(long)((j * 100) / cip->channel->users->totalusers); +} + +void authedpct_free(searchCtx *ctx, struct searchNode *thenode) { free(thenode); }