]> jfr.im git - irc/quakenet/newserv.git/blame - newsearch/ns-hostmask.c
SearchCtx should contain 'type' - this is to make life easier when defining new searc...
[irc/quakenet/newserv.git] / newsearch / ns-hostmask.c
CommitLineData
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"
c86edd1d
Q
11#include "../lib/irc_string.h"
12
c8be5183
CP
13void *hostmask_exe(searchCtx *ctx, struct searchNode *thenode, void *theinput);
14void *hostmask_exe_real(searchCtx *ctx, struct searchNode *thenode, void *theinput);
15void hostmask_free(searchCtx *ctx, struct searchNode *thenode);
c86edd1d 16
f33f3f52 17struct searchNode *hostmask_parse(searchCtx *ctx, int argc, char **argv) {
c86edd1d
Q
18 struct searchNode *thenode;
19
f33f3f52 20 if (ctx->type != SEARCHTYPE_NICK) {
c86edd1d
Q
21 parseError = "hostmask: this function is only valid for nick searches.";
22 return NULL;
23 }
24
9ce4f0be
IB
25 if (!(thenode=(struct searchNode *)malloc(sizeof (struct searchNode)))) {
26 parseError = "malloc: could not allocate memory for this search.";
27 return NULL;
28 }
c86edd1d
Q
29
30 thenode->returntype = RETURNTYPE_STRING;
e39a7352 31 if (!(thenode->localdata = (void *)malloc(HOSTLEN+USERLEN+NICKLEN+REALLEN+10))) {
9ce4f0be
IB
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 }
c86edd1d
Q
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
c8be5183 49void *hostmask_exe(searchCtx *ctx, struct searchNode *thenode, void *theinput) {
c86edd1d
Q
50 nick *np = (nick *)theinput;
51 char *buf = thenode->localdata;
52
c86edd1d
Q
53 return visiblehostmask(np, buf);
54}
55
c8be5183 56void *hostmask_exe_real(searchCtx *ctx, struct searchNode *thenode, void *theinput) {
c86edd1d
Q
57 nick *np = (nick *)theinput;
58 char *buf = thenode->localdata;
59
e39a7352 60 sprintf(buf,"%s!%s@%s\r%s",np->nick,np->ident,np->host->name->content,np->realname->name->content);
c86edd1d
Q
61
62 return buf;
63}
64
c8be5183 65void hostmask_free(searchCtx *ctx, struct searchNode *thenode) {
c86edd1d
Q
66 free(thenode->localdata);
67 free(thenode);
68}
69