]>
jfr.im git - irc/quakenet/newserv.git/blob - newsearch/ns-hostmask.c
2 * HOSTMASK functionality
10 #include "../irc/irc_config.h"
11 #include "../lib/irc_string.h"
13 void *hostmask_exe(searchCtx
*ctx
, struct searchNode
*thenode
, void *theinput
);
14 void *hostmask_exe_rn(searchCtx
*ctx
, struct searchNode
*thenode
, void *theinput
);
15 void *hostmask_exe_rh(searchCtx
*ctx
, struct searchNode
*thenode
, void *theinput
);
16 void *hostmask_exe_rn_rh(searchCtx
*ctx
, struct searchNode
*thenode
, void *theinput
);
17 void hostmask_free(searchCtx
*ctx
, struct searchNode
*thenode
);
19 struct searchNode
*hostmask_parse(searchCtx
*ctx
, int argc
, char **argv
) {
20 struct searchNode
*thenode
;
21 int realhost
= 0, realname
= 0, i
, error
= 0;
24 struct searchNode
*convsn
;
27 if (!(convsn
=argtoconststr("hostmask", ctx
, argv
[i
], &p
)))
30 if(!ircd_strcmp(p
, "realhost")) {
32 } else if(!ircd_strcmp(p
, "realname")) {
37 convsn
->free(ctx
, convsn
);
40 parseError
= "bad argument: use realhost and/or realname";
45 if (!(thenode
=(struct searchNode
*)malloc(sizeof (struct searchNode
)))) {
46 parseError
= "malloc: could not allocate memory for this search.";
50 thenode
->returntype
= RETURNTYPE_STRING
;
51 if (!(thenode
->localdata
= (void *)malloc(HOSTLEN
+USERLEN
+NICKLEN
+REALLEN
+10))) {
52 /* couldn't malloc() memory for thenode->localdata, so free thenode to avoid leakage */
53 parseError
= "malloc: could not allocate memory for this search.";
57 thenode
->free
= hostmask_free
;
61 thenode
->exe
= hostmask_exe_rn_rh
;
63 thenode
->exe
= hostmask_exe_rn
;
67 thenode
->exe
= hostmask_exe_rh
;
69 thenode
->exe
= hostmask_exe
;
76 void *hostmask_exe(searchCtx
*ctx
, struct searchNode
*thenode
, void *theinput
) {
77 nick
*np
= (nick
*)theinput
;
78 char *buf
= thenode
->localdata
;
80 return visiblehostmask(np
, buf
);
83 void *hostmask_exe_rh(searchCtx
*ctx
, struct searchNode
*thenode
, void *theinput
) {
84 nick
*np
= (nick
*)theinput
;
85 char *buf
= thenode
->localdata
;
87 sprintf(buf
,"%s!%s@%s",np
->nick
,np
->ident
,np
->host
->name
->content
);
92 void *hostmask_exe_rn_rh(searchCtx
*ctx
, struct searchNode
*thenode
, void *theinput
) {
93 nick
*np
= (nick
*)theinput
;
94 char *buf
= thenode
->localdata
;
96 sprintf(buf
,"%s!%s@%s\r%s",np
->nick
,np
->ident
,np
->host
->name
->content
,np
->realname
->name
->content
);
101 void *hostmask_exe_rn(searchCtx
*ctx
, struct searchNode
*thenode
, void *theinput
) {
102 nick
*np
= (nick
*)theinput
;
103 char *buf
= thenode
->localdata
;
105 sprintf(buf
,"%s\r%s",visiblehostmask(np
, buf
),np
->realname
->name
->content
);
110 void hostmask_free(searchCtx
*ctx
, struct searchNode
*thenode
) {
111 free(thenode
->localdata
);