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