]> jfr.im git - irc/quakenet/newserv.git/blobdiff - newsearch/ns-services.c
Merge branch 'master' into chanserv-live
[irc/quakenet/newserv.git] / newsearch / ns-services.c
index d5d8eac936d11c331755e0ed77619ad7ceee5ab5..5a30bbffbdac76d4f1acaf4a57657f3d4befabbe 100644 (file)
@@ -7,61 +7,34 @@
 #include <stdio.h>
 #include <stdlib.h>
 
-struct services_localdata {
-  long count;
-};
+void *services_exe(searchCtx *ctx, struct searchNode *thenode, void *theinput);
+void services_free(searchCtx *ctx, struct searchNode *thenode);
 
-void *services_exe(struct searchNode *thenode, int type, void *theinput);
-void services_free(struct searchNode *thenode);
-
-struct searchNode *services_parse(int type, int argc, char **argv) {
-  struct services_localdata *localdata;
+struct searchNode *services_parse(searchCtx *ctx, int argc, char **argv) {
   struct searchNode *thenode;
 
-  if (type != SEARCHTYPE_CHANNEL) {
-    parseError = "services: this function is only valid for channel searches.";
-    return NULL;
-  }
-
-  if (argc!=1) {
-    parseError="services: usage: (services number)";
-    return NULL;
-  }
-
-  if (!(localdata=(struct services_localdata *)malloc(sizeof(struct services_localdata)))) {
-    parseError = "malloc: could not allocate memory for this search.";
-    return NULL;
-  }
-
-  localdata->count = 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 = services_exe;
   thenode->free = services_free;
 
   return thenode;
 }
 
-void *services_exe(struct searchNode *thenode, int type, void *theinput) {
+void *services_exe(searchCtx *ctx, struct searchNode *thenode, void *theinput) {
   chanindex *cip = (chanindex *)theinput;
   nick *np;
-  struct services_localdata *localdata;
   int i;
-
-  localdata = thenode->localdata;
-
-  long count = localdata->count;
-
+  unsigned long count=0;
+  
   if (cip->channel == NULL)
-    return falseval(type);
+    return (void *)0;
 
   for(i=0;i<cip->channel->users->hashsize;i++) {
     if (cip->channel->users->content[i]==nouser)
@@ -69,15 +42,15 @@ void *services_exe(struct searchNode *thenode, int type, void *theinput) {
       
     if (!(np=getnickbynumeric(cip->channel->users->content[i])))
       continue;
-    if (IsService(np) && !--count)
-      return trueval(type); /* channel found */
+
+    if (IsService(np))
+      count++;
   }
   
-  return falseval(type); /* channel not found */
+  return (void *)count;
 }
 
-void services_free(struct searchNode *thenode) {
-  free(thenode->localdata);
+void services_free(searchCtx *ctx, struct searchNode *thenode) {
   free(thenode);
 }