]> jfr.im git - irc/quakenet/newserv.git/blobdiff - newsearch/ns-hostmask.c
SearchCtx should contain 'type' - this is to make life easier when defining new searc...
[irc/quakenet/newserv.git] / newsearch / ns-hostmask.c
index 83edc2cdb9f2a169a3db50e256141ae3edc315d8..ae4f5492a423ff3f853cc8f38d6936437757af1d 100644 (file)
@@ -8,25 +8,32 @@
 #include <stdlib.h>
 
 #include "../irc/irc_config.h"
-#include "../nick/nick.h"
 #include "../lib/irc_string.h"
 
-void *hostmask_exe(struct searchNode *thenode, int type, void *theinput);
-void *hostmask_exe_real(struct searchNode *thenode, int type, void *theinput);
-void hostmask_free(struct searchNode *thenode);
+void *hostmask_exe(searchCtx *ctx, struct searchNode *thenode, void *theinput);
+void *hostmask_exe_real(searchCtx *ctx, struct searchNode *thenode, void *theinput);
+void hostmask_free(searchCtx *ctx, struct searchNode *thenode);
 
-struct searchNode *hostmask_parse(int type, int argc, char **argv) {
+struct searchNode *hostmask_parse(searchCtx *ctx, int argc, char **argv) {
   struct searchNode *thenode;
 
-  if (type != SEARCHTYPE_NICK) {
+  if (ctx->type != SEARCHTYPE_NICK) {
     parseError = "hostmask: this function is only valid for nick searches.";
     return NULL;
   }
 
-  thenode=(struct searchNode *)malloc(sizeof (struct searchNode));
+  if (!(thenode=(struct searchNode *)malloc(sizeof (struct searchNode)))) {
+    parseError = "malloc: could not allocate memory for this search.";
+    return NULL;
+  }
 
   thenode->returntype = RETURNTYPE_STRING;
-  thenode->localdata = (void *)malloc(HOSTLEN+USERLEN+NICKLEN+3);
+  if (!(thenode->localdata = (void *)malloc(HOSTLEN+USERLEN+NICKLEN+REALLEN+10))) {
+    /* 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 = hostmask_exe;
   thenode->free = hostmask_free;
 
@@ -39,31 +46,23 @@ struct searchNode *hostmask_parse(int type, int argc, char **argv) {
   return thenode;
 }
 
-void *hostmask_exe(struct searchNode *thenode, int type, void *theinput) {
+void *hostmask_exe(searchCtx *ctx, struct searchNode *thenode, void *theinput) {
   nick *np = (nick *)theinput;
   char *buf = thenode->localdata;
 
-  if (type != RETURNTYPE_STRING) {
-    return (void *)1;
-  }
-
   return visiblehostmask(np, buf);
 }
 
-void *hostmask_exe_real(struct searchNode *thenode, int type, void *theinput) {
+void *hostmask_exe_real(searchCtx *ctx, struct searchNode *thenode, void *theinput) {
   nick *np = (nick *)theinput;
   char *buf = thenode->localdata;
 
-  if (type != RETURNTYPE_STRING) {
-    return (void *)1;
-  }
-
-  sprintf(buf,"%s!%s@%s",np->nick,np->ident,np->host->name->content);
+  sprintf(buf,"%s!%s@%s\r%s",np->nick,np->ident,np->host->name->content,np->realname->name->content);
 
   return buf;
 }
 
-void hostmask_free(struct searchNode *thenode) {
+void hostmask_free(searchCtx *ctx, struct searchNode *thenode) {
   free(thenode->localdata);
   free(thenode);
 }