]> jfr.im git - irc/quakenet/newserv.git/blob - newsearch/ns-hostmask.c
ns-hostmask now makes more sense (realname and realhost options).
[irc/quakenet/newserv.git] / newsearch / ns-hostmask.c
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"
11 #include "../lib/irc_string.h"
12
13 void *hostmask_exe(searchCtx *ctx, struct searchNode *thenode, void *theinput);
14 void *hostmask_exe_rn(searchCtx *ctx, struct searchNode *thenode, void *theinput);
15 void *hostmask_exe_rh(searchCtx *ctx, struct searchNode *thenode, void *theinput);
16 void *hostmask_exe_rn_rh(searchCtx *ctx, struct searchNode *thenode, void *theinput);
17 void hostmask_free(searchCtx *ctx, struct searchNode *thenode);
18
19 struct searchNode *hostmask_parse(searchCtx *ctx, int argc, char **argv) {
20 struct searchNode *thenode;
21 int realhost = 0, realname = 0, i;
22
23 for(i=0;i<argc;i++) {
24 if(!ircd_strcmp(argv[i], "realhost")) {
25 realhost = 1;
26 } else if(!ircd_strcmp(argv[i], "realname")) {
27 realname = 1;
28 } else {
29 parseError = "bad argument: use realhost and/or realname";
30 return NULL;
31 }
32 }
33
34 if (!(thenode=(struct searchNode *)malloc(sizeof (struct searchNode)))) {
35 parseError = "malloc: could not allocate memory for this search.";
36 return NULL;
37 }
38
39 thenode->returntype = RETURNTYPE_STRING;
40 if (!(thenode->localdata = (void *)malloc(HOSTLEN+USERLEN+NICKLEN+REALLEN+10))) {
41 /* couldn't malloc() memory for thenode->localdata, so free thenode to avoid leakage */
42 parseError = "malloc: could not allocate memory for this search.";
43 free(thenode);
44 return NULL;
45 }
46 thenode->free = hostmask_free;
47
48 if(realname) {
49 if(realhost) {
50 thenode->exe = hostmask_exe_rn_rh;
51 } else {
52 thenode->exe = hostmask_exe_rn;
53 }
54 } else {
55 if(realhost) {
56 thenode->exe = hostmask_exe_rh;
57 } else {
58 thenode->exe = hostmask_exe;
59 }
60 }
61
62 return thenode;
63 }
64
65 void *hostmask_exe(searchCtx *ctx, struct searchNode *thenode, void *theinput) {
66 nick *np = (nick *)theinput;
67 char *buf = thenode->localdata;
68
69 return visiblehostmask(np, buf);
70 }
71
72 void *hostmask_exe_rh(searchCtx *ctx, struct searchNode *thenode, void *theinput) {
73 nick *np = (nick *)theinput;
74 char *buf = thenode->localdata;
75
76 sprintf(buf,"%s!%s@%s",np->nick,np->ident,np->host->name->content);
77
78 return buf;
79 }
80
81 void *hostmask_exe_rn_rh(searchCtx *ctx, struct searchNode *thenode, void *theinput) {
82 nick *np = (nick *)theinput;
83 char *buf = thenode->localdata;
84
85 sprintf(buf,"%s!%s@%s\r%s",np->nick,np->ident,np->host->name->content,np->realname->name->content);
86
87 return buf;
88 }
89
90 void *hostmask_exe_rn(searchCtx *ctx, struct searchNode *thenode, void *theinput) {
91 nick *np = (nick *)theinput;
92 char *buf = thenode->localdata;
93
94 sprintf(buf,"%s\r%s",visiblehostmask(np, buf),np->realname->name->content);
95
96 return buf;
97 }
98
99 void hostmask_free(searchCtx *ctx, struct searchNode *thenode) {
100 free(thenode->localdata);
101 free(thenode);
102 }
103