]> jfr.im git - irc/quakenet/newserv.git/blobdiff - newsearch/ns-hostpct.c
CHANSERV: authtracker now keeps 240 days history
[irc/quakenet/newserv.git] / newsearch / ns-hostpct.c
index 88c95e35f2cfb91918177540c0e20cf0b4500aa0..ca87951ae07b34fb5608acab1245e9a2ec193b8a 100644 (file)
@@ -7,66 +7,38 @@
 #include <stdio.h>
 #include <stdlib.h>
 
-struct hostpct_localdata {
-  long pct;
-};
+void *hostpct_exe(searchCtx *ctx, struct searchNode *thenode, void *theinput);
+void hostpct_free(searchCtx *ctx, struct searchNode *thenode);
 
-void *hostpct_exe(struct searchNode *thenode, int type, void *theinput);
-void hostpct_free(struct searchNode *thenode);
-
-struct searchNode *hostpct_parse(int type, int argc, char **argv) {
-  struct hostpct_localdata *localdata;
+struct searchNode *hostpct_parse(searchCtx *ctx, int argc, char **argv) {
   struct searchNode *thenode;
 
-  if (type != SEARCHTYPE_CHANNEL) {
-    parseError = "uniquehostpct: this function is only valid for channel searches.";
-    return NULL;
-  }
-
-  if (argc!=1) {
-    parseError="uniquehostpct: usage: (uniquehostpct number)";
-    return NULL;
-  }
-
-  if (!(localdata=(struct hostpct_localdata *)malloc(sizeof(struct hostpct_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 = hostpct_exe;
   thenode->free = hostpct_free;
 
   return thenode;
 }
 
-void *hostpct_exe(struct searchNode *thenode, int type, void *theinput) {
-  int hostreq;
+void *hostpct_exe(searchCtx *ctx, struct searchNode *thenode, void *theinput) {
   int i;
   unsigned int marker;
+  unsigned int hosts=0;
   nick *np;
   chanindex *cip = (chanindex *)theinput;
-  struct hostpct_localdata *localdata;
 
-  localdata = thenode->localdata;
-  
   if (cip->channel==NULL)
-    return falseval(type);
+    return (void *)0;
   
   marker=nexthostmarker();
   
-  hostreq=(cip->channel->users->totalusers * localdata->pct) / 100;
-  
   for (i=0;i<cip->channel->users->hashsize;i++) {
     if (cip->channel->users->content[i]==nouser)
       continue;
@@ -75,19 +47,15 @@ void *hostpct_exe(struct searchNode *thenode, int type, void *theinput) {
       continue;
 
     if (np->host->marker!=marker) {
-      /* new unique host */
-      if (--hostreq <= 0) {
-        return trueval(type);
-      }
+      hosts++;
       np->host->marker=marker;
     }
   }
   
-  return falseval(type);
+  return (void *)(long)((hosts * 100)/cip->channel->users->totalusers);
 }
 
-void hostpct_free(struct searchNode *thenode) {
-  free(thenode->localdata);
+void hostpct_free(searchCtx *ctx, struct searchNode *thenode) {
   free(thenode);
 }