]>
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
;
24 if(!ircd_strcmp(argv
[i
], "realhost")) {
26 } else if(!ircd_strcmp(argv
[i
], "realname")) {
29 parseError
= "bad argument: use realhost and/or realname";
34 if (!(thenode
=(struct searchNode
*)malloc(sizeof (struct searchNode
)))) {
35 parseError
= "malloc: could not allocate memory for this search.";
39 thenode
->returntype
= RETURNTYPE_STRING
;
40 if (!(thenode
->localdata
= (void *)malloc(HOSTLEN
+USERLEN
+NICKLEN
+REALLEN
+10))) {
41 /* couldn't malloc() memory for thenode->localdata, so free thenode to avoid leakage */
42 parseError
= "malloc: could not allocate memory for this search.";
46 thenode
->free
= hostmask_free
;
50 thenode
->exe
= hostmask_exe_rn_rh
;
52 thenode
->exe
= hostmask_exe_rn
;
56 thenode
->exe
= hostmask_exe_rh
;
58 thenode
->exe
= hostmask_exe
;
65 void *hostmask_exe(searchCtx
*ctx
, struct searchNode
*thenode
, void *theinput
) {
66 nick
*np
= (nick
*)theinput
;
67 char *buf
= thenode
->localdata
;
69 return visiblehostmask(np
, buf
);
72 void *hostmask_exe_rh(searchCtx
*ctx
, struct searchNode
*thenode
, void *theinput
) {
73 nick
*np
= (nick
*)theinput
;
74 char *buf
= thenode
->localdata
;
76 sprintf(buf
,"%s!%s@%s",np
->nick
,np
->ident
,np
->host
->name
->content
);
81 void *hostmask_exe_rn_rh(searchCtx
*ctx
, struct searchNode
*thenode
, void *theinput
) {
82 nick
*np
= (nick
*)theinput
;
83 char *buf
= thenode
->localdata
;
85 sprintf(buf
,"%s!%s@%s\r%s",np
->nick
,np
->ident
,np
->host
->name
->content
,np
->realname
->name
->content
);
90 void *hostmask_exe_rn(searchCtx
*ctx
, struct searchNode
*thenode
, void *theinput
) {
91 nick
*np
= (nick
*)theinput
;
92 char *buf
= thenode
->localdata
;
94 sprintf(buf
,"%s\r%s",visiblehostmask(np
, buf
),np
->realname
->name
->content
);
99 void hostmask_free(searchCtx
*ctx
, struct searchNode
*thenode
) {
100 free(thenode
->localdata
);