X-Git-Url: https://jfr.im/git/irc/quakenet/newserv.git/blobdiff_plain/798a53a27e24f354d6ec78317467b998302cd0b0..babee1a0fda9095a0a2b2b5c529e03382a7d0363:/newsearch/ns-hostmask.c diff --git a/newsearch/ns-hostmask.c b/newsearch/ns-hostmask.c index 22e9eea1..caa66e08 100644 --- a/newsearch/ns-hostmask.c +++ b/newsearch/ns-hostmask.c @@ -10,16 +10,36 @@ #include "../irc/irc_config.h" #include "../lib/irc_string.h" -void *hostmask_exe(struct searchNode *thenode, void *theinput); -void *hostmask_exe_real(struct searchNode *thenode, void *theinput); -void hostmask_free(struct searchNode *thenode); +void *hostmask_exe(searchCtx *ctx, struct searchNode *thenode, void *theinput); +void *hostmask_exe_rn(searchCtx *ctx, struct searchNode *thenode, void *theinput); +void *hostmask_exe_rh(searchCtx *ctx, struct searchNode *thenode, void *theinput); +void *hostmask_exe_rn_rh(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) { - parseError = "hostmask: this function is only valid for nick searches."; - return NULL; + int realhost = 0, realname = 0, i, error = 0; + + for(i=0;ifree(ctx, convsn); + + if(error) { + parseError = "bad argument: use realhost and/or realname"; + return NULL; + } } if (!(thenode=(struct searchNode *)malloc(sizeof (struct searchNode)))) { @@ -28,32 +48,39 @@ struct searchNode *hostmask_parse(int type, int argc, char **argv) { } thenode->returntype = RETURNTYPE_STRING; - if (!(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; - /* Allow "hostmask real" to match realhost */ - - if (argc>0 && !ircd_strcmp(argv[0],"real")) { - thenode->exe = hostmask_exe_real; + if(realname) { + if(realhost) { + thenode->exe = hostmask_exe_rn_rh; + } else { + thenode->exe = hostmask_exe_rn; + } + } else { + if(realhost) { + thenode->exe = hostmask_exe_rh; + } else { + thenode->exe = hostmask_exe; + } } return thenode; } -void *hostmask_exe(struct searchNode *thenode, void *theinput) { +void *hostmask_exe(searchCtx *ctx, struct searchNode *thenode, void *theinput) { nick *np = (nick *)theinput; char *buf = thenode->localdata; return visiblehostmask(np, buf); } -void *hostmask_exe_real(struct searchNode *thenode, void *theinput) { +void *hostmask_exe_rh(searchCtx *ctx, struct searchNode *thenode, void *theinput) { nick *np = (nick *)theinput; char *buf = thenode->localdata; @@ -62,7 +89,25 @@ void *hostmask_exe_real(struct searchNode *thenode, void *theinput) { return buf; } -void hostmask_free(struct searchNode *thenode) { +void *hostmask_exe_rn_rh(searchCtx *ctx, struct searchNode *thenode, void *theinput) { + nick *np = (nick *)theinput; + char *buf = thenode->localdata; + + sprintf(buf,"%s!%s@%s\r%s",np->nick,np->ident,np->host->name->content,np->realname->name->content); + + return buf; +} + +void *hostmask_exe_rn(searchCtx *ctx, struct searchNode *thenode, void *theinput) { + nick *np = (nick *)theinput; + char *buf = thenode->localdata; + + sprintf(buf,"%s\r%s",visiblehostmask(np, buf),np->realname->name->content); + + return buf; +} + +void hostmask_free(searchCtx *ctx, struct searchNode *thenode) { free(thenode->localdata); free(thenode); }