X-Git-Url: https://jfr.im/git/irc/quakenet/newserv.git/blobdiff_plain/c86edd1d9e5994aea33cfad3164e4827e591e7e6..f33f3f52f58acdd2b9b6796713ac8f24d9881545:/newsearch/ns-hostmask.c diff --git a/newsearch/ns-hostmask.c b/newsearch/ns-hostmask.c index 83edc2cd..ae4f5492 100644 --- a/newsearch/ns-hostmask.c +++ b/newsearch/ns-hostmask.c @@ -8,25 +8,32 @@ #include #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); }