]> jfr.im git - irc/quakenet/newserv.git/blob - newsearch/ns-hostmask.c
Merged.
[irc/quakenet/newserv.git] / newsearch / ns-hostmask.c
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 "../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 if (!(thenode=(struct searchNode *)malloc(sizeof (struct searchNode)))) {
26 parseError = "malloc: could not allocate memory for this search.";
27 return NULL;
28 }
29
30 thenode->returntype = RETURNTYPE_STRING;
31 if (!(thenode->localdata = (void *)malloc(HOSTLEN+USERLEN+NICKLEN+3))) {
32 /* couldn't malloc() memory for thenode->localdata, so free thenode to avoid leakage */
33 parseError = "malloc: could not allocate memory for this search.";
34 free(thenode);
35 return NULL;
36 }
37 thenode->exe = hostmask_exe;
38 thenode->free = hostmask_free;
39
40 /* Allow "hostmask real" to match realhost */
41
42 if (argc>0 && !ircd_strcmp(argv[0],"real")) {
43 thenode->exe = hostmask_exe_real;
44 }
45
46 return thenode;
47 }
48
49 void *hostmask_exe(struct searchNode *thenode, int type, void *theinput) {
50 nick *np = (nick *)theinput;
51 char *buf = thenode->localdata;
52
53 if (type != RETURNTYPE_STRING) {
54 return (void *)1;
55 }
56
57 return visiblehostmask(np, buf);
58 }
59
60 void *hostmask_exe_real(struct searchNode *thenode, int type, void *theinput) {
61 nick *np = (nick *)theinput;
62 char *buf = thenode->localdata;
63
64 if (type != RETURNTYPE_STRING) {
65 return (void *)1;
66 }
67
68 sprintf(buf,"%s!%s@%s",np->nick,np->ident,np->host->name->content);
69
70 return buf;
71 }
72
73 void hostmask_free(struct searchNode *thenode) {
74 free(thenode->localdata);
75 free(thenode);
76 }
77