]>
Commit | Line | Data |
---|---|---|
c86edd1d Q |
1 | /* |
2 | * HOST 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 |
13 | void *host_exe(searchCtx *ctx, struct searchNode *thenode, void *theinput); |
14 | void *host_exe_real(searchCtx *ctx, struct searchNode *thenode, void *theinput); | |
15 | void host_free(searchCtx *ctx, struct searchNode *thenode); | |
c86edd1d | 16 | |
f33f3f52 | 17 | struct searchNode *host_parse(searchCtx *ctx, int argc, char **argv) { |
31686847 CP |
18 | struct searchNode *thenode, *argsn; |
19 | char *p; | |
20 | ||
9ce4f0be IB |
21 | if (!(thenode=(struct searchNode *)malloc(sizeof (struct searchNode)))) { |
22 | parseError = "malloc: could not allocate memory for this search."; | |
23 | return NULL; | |
24 | } | |
c86edd1d Q |
25 | |
26 | thenode->returntype = RETURNTYPE_STRING; | |
9ce4f0be IB |
27 | if (!(thenode->localdata = (void *)malloc(HOSTLEN+1))) { |
28 | /* couldn't malloc() memory for thenode->localdata, so free thenode to avoid leakage */ | |
29 | parseError = "malloc: could not allocate memory for this search."; | |
30 | free(thenode); | |
31 | return NULL; | |
32 | } | |
c86edd1d Q |
33 | thenode->exe = host_exe; |
34 | thenode->free = host_free; | |
35 | ||
e7554768 CP |
36 | if (argc>0) { |
37 | if (!(argsn=argtoconststr("host", ctx, argv[0], &p))) { | |
38 | free(thenode); | |
39 | return NULL; | |
40 | } | |
31686847 | 41 | |
e7554768 CP |
42 | /* Allow "host real" to match realhost */ |
43 | if (!ircd_strcmp(p,"real")) | |
44 | thenode->exe = host_exe_real; | |
e7554768 | 45 | |
3c4b38ec CP |
46 | argsn->free(ctx, argsn); |
47 | } | |
c86edd1d Q |
48 | |
49 | return thenode; | |
50 | } | |
51 | ||
c8be5183 | 52 | void *host_exe(searchCtx *ctx, struct searchNode *thenode, void *theinput) { |
c86edd1d Q |
53 | nick *np = (nick *)theinput; |
54 | char *buf = thenode->localdata; | |
55 | ||
c86edd1d Q |
56 | if (IsSetHost(np)) { |
57 | return np->sethost->content; | |
58 | } else if (IsHideHost(np)) { | |
59 | sprintf(buf,"%s.%s",np->authname,HIS_HIDDENHOST); | |
60 | return buf; | |
61 | } else { | |
62 | return np->host->name->content; | |
63 | } | |
64 | } | |
65 | ||
c8be5183 | 66 | void *host_exe_real(searchCtx *ctx, struct searchNode *thenode, void *theinput) { |
c86edd1d Q |
67 | nick *np = (nick *)theinput; |
68 | ||
c86edd1d Q |
69 | return np->host->name->content; |
70 | } | |
71 | ||
c8be5183 | 72 | void host_free(searchCtx *ctx, struct searchNode *thenode) { |
c86edd1d Q |
73 | free(thenode->localdata); |
74 | free(thenode); | |
75 | } |