]> jfr.im git - irc/quakenet/newserv.git/blobdiff - newsearch/ns-authedpct.c
merge
[irc/quakenet/newserv.git] / newsearch / ns-authedpct.c
index d12d854e3e0a3871ddb0b2c4ecb427127e654d63..8558e9ad2832c57cdd20d949bbe3f39c5dd09bf0 100644 (file)
@@ -7,50 +7,27 @@
 #include <stdio.h>
 #include <stdlib.h>
 
-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;
@@ -60,7 +37,7 @@ void *authedpct_exe(struct searchNode *thenode, int type, void *theinput) {
   localdata = thenode->localdata;
   
   if (!cip->channel)
-    return falseval(type);
+    return (void *)0;
   
   for (i=0;i<cip->channel->users->hashsize;i++) {
     if (cip->channel->users->content[i]==nouser)
@@ -69,15 +46,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);
 }