]>
Commit | Line | Data |
---|---|---|
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 | ||
13 | void *hostmask_exe(struct searchNode *thenode, int type, void *theinput); | |
14 | void *hostmask_exe_real(struct searchNode *thenode, int type, void *theinput); | |
15 | void hostmask_free(struct searchNode *thenode); | |
16 | ||
17 | struct searchNode *hostmask_parse(int type, int argc, char **argv) { | |
18 | struct searchNode *thenode; | |
19 | ||
20 | if (type != SEARCHTYPE_NICK) { | |
21 | parseError = "hostmask: this function is only valid for nick searches."; | |
22 | return NULL; | |
23 | } | |
24 | ||
25 | thenode=(struct searchNode *)malloc(sizeof (struct searchNode)); | |
26 | ||
27 | thenode->returntype = RETURNTYPE_STRING; | |
28 | thenode->localdata = (void *)malloc(HOSTLEN+USERLEN+NICKLEN+3); | |
29 | thenode->exe = hostmask_exe; | |
30 | thenode->free = hostmask_free; | |
31 | ||
32 | /* Allow "hostmask real" to match realhost */ | |
33 | ||
34 | if (argc>0 && !ircd_strcmp(argv[0],"real")) { | |
35 | thenode->exe = hostmask_exe_real; | |
36 | } | |
37 | ||
38 | return thenode; | |
39 | } | |
40 | ||
41 | void *hostmask_exe(struct searchNode *thenode, int type, void *theinput) { | |
42 | nick *np = (nick *)theinput; | |
43 | char *buf = thenode->localdata; | |
44 | ||
45 | if (type != RETURNTYPE_STRING) { | |
46 | return (void *)1; | |
47 | } | |
48 | ||
49 | return visiblehostmask(np, buf); | |
50 | } | |
51 | ||
52 | void *hostmask_exe_real(struct searchNode *thenode, int type, void *theinput) { | |
53 | nick *np = (nick *)theinput; | |
54 | char *buf = thenode->localdata; | |
55 | ||
56 | if (type != RETURNTYPE_STRING) { | |
57 | return (void *)1; | |
58 | } | |
59 | ||
60 | sprintf(buf,"%s!%s@%s",np->nick,np->ident,np->host->name->content); | |
61 | ||
62 | return buf; | |
63 | } | |
64 | ||
65 | void hostmask_free(struct searchNode *thenode) { | |
66 | free(thenode->localdata); | |
67 | free(thenode); | |
68 | } | |
69 |