]> jfr.im git - irc/quakenet/newserv.git/blob - newsearch/ns-host.c
nick->node
[irc/quakenet/newserv.git] / newsearch / ns-host.c
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"
11 #include "../lib/irc_string.h"
12
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);
16
17 struct searchNode *host_parse(searchCtx *ctx, int argc, char **argv) {
18 struct searchNode *thenode, *argsn;
19 char *p;
20
21 if (!(thenode=(struct searchNode *)malloc(sizeof (struct searchNode)))) {
22 parseError = "malloc: could not allocate memory for this search.";
23 return NULL;
24 }
25
26 thenode->returntype = RETURNTYPE_STRING;
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 }
33 thenode->exe = host_exe;
34 thenode->free = host_free;
35
36 if (!(argsn=argtoconststr("host", ctx, argv[0], &p))) {
37 free(thenode);
38 return NULL;
39 }
40
41 /* Allow "host real" to match realhost */
42 if (argc>0 && !ircd_strcmp(p,"real"))
43 thenode->exe = host_exe_real;
44
45 argsn->free(ctx, argsn);
46
47 return thenode;
48 }
49
50 void *host_exe(searchCtx *ctx, struct searchNode *thenode, void *theinput) {
51 nick *np = (nick *)theinput;
52 char *buf = thenode->localdata;
53
54 if (IsSetHost(np)) {
55 return np->sethost->content;
56 } else if (IsHideHost(np)) {
57 sprintf(buf,"%s.%s",np->authname,HIS_HIDDENHOST);
58 return buf;
59 } else {
60 return np->host->name->content;
61 }
62 }
63
64 void *host_exe_real(searchCtx *ctx, struct searchNode *thenode, void *theinput) {
65 nick *np = (nick *)theinput;
66
67 return np->host->name->content;
68 }
69
70 void host_free(searchCtx *ctx, struct searchNode *thenode) {
71 free(thenode->localdata);
72 free(thenode);
73 }