]> jfr.im git - irc/quakenet/newserv.git/blobdiff - newsearch/ns-host.c
CHANSERV: fix issue where chanserv_relay doesn't wait for db to be loaded before...
[irc/quakenet/newserv.git] / newsearch / ns-host.c
index 6bf89ba76dfc69ada5c62ac9c4c28a6d630d8fab..ab919d840f016c012ab75a57565f5f17394e6dfc 100644 (file)
 #include "../irc/irc_config.h"
 #include "../lib/irc_string.h"
 
-void *host_exe(struct searchNode *thenode, int type, void *theinput);
-void *host_exe_real(struct searchNode *thenode, int type, void *theinput);
-void host_free(struct searchNode *thenode);
-
-struct searchNode *host_parse(int type, int argc, char **argv) {
-  struct searchNode *thenode;
-
-  if (type != SEARCHTYPE_NICK) {
-    parseError = "host: this function is only valid for nick searches.";
+void *host_exe(searchCtx *ctx, struct searchNode *thenode, void *theinput);
+void *host_exe_real(searchCtx *ctx, struct searchNode *thenode, void *theinput);
+void host_free(searchCtx *ctx, struct searchNode *thenode);
+
+struct searchNode *host_parse(searchCtx *ctx, int argc, char **argv) {
+  struct searchNode *thenode, *argsn;
+  char *p;
+  
+  if (!(thenode=(struct searchNode *)malloc(sizeof (struct searchNode)))) {
+    parseError = "malloc: could not allocate memory for this search.";
     return NULL;
   }
 
-  thenode=(struct searchNode *)malloc(sizeof (struct searchNode));
-
   thenode->returntype = RETURNTYPE_STRING;
-  thenode->localdata = (void *)malloc(HOSTLEN+1);
+  if (!(thenode->localdata = (void *)malloc(HOSTLEN+1))) {
+    /* couldn't malloc() memory for thenode->localdata, so free thenode to avoid leakage */
+    parseError = "malloc: could not allocate memory for this search.";
+    free(thenode);
+    return NULL;
+  }
   thenode->exe = host_exe;
   thenode->free = host_free;
 
-  /* Allow "host real" to match realhost */
-
-  if (argc>0 && !ircd_strcmp(argv[0],"real")) {
-    thenode->exe = host_exe_real;
+  if (argc>0) {
+    if (!(argsn=argtoconststr("host", ctx, argv[0], &p))) {
+      free(thenode);
+      return NULL;
+    }
+  
+    /* Allow "host real" to match realhost */
+    if (!ircd_strcmp(p,"real"))
+      thenode->exe = host_exe_real;
+
+    argsn->free(ctx, argsn);
   }
 
   return thenode;
 }
 
-void *host_exe(struct searchNode *thenode, int type, void *theinput) {
+void *host_exe(searchCtx *ctx, struct searchNode *thenode, void *theinput) {
   nick *np = (nick *)theinput;
   char *buf = thenode->localdata;
 
-  if (type != RETURNTYPE_STRING) {
-    return (void *)1;
-  }
-
   if (IsSetHost(np)) {
     return np->sethost->content;
   } else if (IsHideHost(np)) {
@@ -56,17 +63,13 @@ void *host_exe(struct searchNode *thenode, int type, void *theinput) {
   }
 }
 
-void *host_exe_real(struct searchNode *thenode, int type, void *theinput) {
+void *host_exe_real(searchCtx *ctx, struct searchNode *thenode, void *theinput) {
   nick *np = (nick *)theinput;
 
-  if (type != RETURNTYPE_STRING) {
-    return (void *)1;
-  }
-
   return np->host->name->content;
 }
 
-void host_free(struct searchNode *thenode) {
+void host_free(searchCtx *ctx, struct searchNode *thenode) {
   free(thenode->localdata);
   free(thenode);
 }