]> jfr.im git - irc/quakenet/newserv.git/blame - newsearch/ns-hostmask.c
newsearch changes to support addition of trust_search/patriciasearch
[irc/quakenet/newserv.git] / newsearch / ns-hostmask.c
CommitLineData
c86edd1d
Q
1/*
2 * HOSTMASK functionality
3 */
4
5#include "newsearch.h"
6
7#include <stdio.h>
8#include <stdlib.h>
9
10#include "../irc/irc_config.h"
c86edd1d
Q
11#include "../lib/irc_string.h"
12
c8be5183
CP
13void *hostmask_exe(searchCtx *ctx, struct searchNode *thenode, void *theinput);
14void *hostmask_exe_real(searchCtx *ctx, struct searchNode *thenode, void *theinput);
15void hostmask_free(searchCtx *ctx, struct searchNode *thenode);
c86edd1d 16
f33f3f52 17struct searchNode *hostmask_parse(searchCtx *ctx, int argc, char **argv) {
c86edd1d
Q
18 struct searchNode *thenode;
19
9ce4f0be
IB
20 if (!(thenode=(struct searchNode *)malloc(sizeof (struct searchNode)))) {
21 parseError = "malloc: could not allocate memory for this search.";
22 return NULL;
23 }
c86edd1d
Q
24
25 thenode->returntype = RETURNTYPE_STRING;
e39a7352 26 if (!(thenode->localdata = (void *)malloc(HOSTLEN+USERLEN+NICKLEN+REALLEN+10))) {
9ce4f0be
IB
27 /* couldn't malloc() memory for thenode->localdata, so free thenode to avoid leakage */
28 parseError = "malloc: could not allocate memory for this search.";
29 free(thenode);
30 return NULL;
31 }
c86edd1d
Q
32 thenode->exe = hostmask_exe;
33 thenode->free = hostmask_free;
34
35 /* Allow "hostmask real" to match realhost */
36
37 if (argc>0 && !ircd_strcmp(argv[0],"real")) {
38 thenode->exe = hostmask_exe_real;
39 }
40
41 return thenode;
42}
43
c8be5183 44void *hostmask_exe(searchCtx *ctx, struct searchNode *thenode, void *theinput) {
c86edd1d
Q
45 nick *np = (nick *)theinput;
46 char *buf = thenode->localdata;
47
c86edd1d
Q
48 return visiblehostmask(np, buf);
49}
50
c8be5183 51void *hostmask_exe_real(searchCtx *ctx, struct searchNode *thenode, void *theinput) {
c86edd1d
Q
52 nick *np = (nick *)theinput;
53 char *buf = thenode->localdata;
54
e39a7352 55 sprintf(buf,"%s!%s@%s\r%s",np->nick,np->ident,np->host->name->content,np->realname->name->content);
c86edd1d
Q
56
57 return buf;
58}
59
c8be5183 60void hostmask_free(searchCtx *ctx, struct searchNode *thenode) {
c86edd1d
Q
61 free(thenode->localdata);
62 free(thenode);
63}
64