]> jfr.im git - irc/quakenet/newserv.git/blob - newsearch/ns-host.c
Add jupe support
[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 "../nick/nick.h"
12 #include "../lib/irc_string.h"
13
14 void *host_exe(struct searchNode *thenode, int type, void *theinput);
15 void *host_exe_real(struct searchNode *thenode, int type, void *theinput);
16 void host_free(struct searchNode *thenode);
17
18 struct searchNode *host_parse(int type, int argc, char **argv) {
19 struct searchNode *thenode;
20
21 if (type != SEARCHTYPE_NICK) {
22 parseError = "host: 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+1);
30 thenode->exe = host_exe;
31 thenode->free = host_free;
32
33 /* Allow "host real" to match realhost */
34
35 if (argc>0 && !ircd_strcmp(argv[0],"real")) {
36 thenode->exe = host_exe_real;
37 }
38
39 return thenode;
40 }
41
42 void *host_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 if (IsSetHost(np)) {
51 return np->sethost->content;
52 } else if (IsHideHost(np)) {
53 sprintf(buf,"%s.%s",np->authname,HIS_HIDDENHOST);
54 return buf;
55 } else {
56 return np->host->name->content;
57 }
58 }
59
60 void *host_exe_real(struct searchNode *thenode, int type, void *theinput) {
61 nick *np = (nick *)theinput;
62
63 if (type != RETURNTYPE_STRING) {
64 return (void *)1;
65 }
66
67 return np->host->name->content;
68 }
69
70 void host_free(struct searchNode *thenode) {
71 free(thenode->localdata);
72 free(thenode);
73 }