]>
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_real(searchCtx
*ctx
, struct searchNode
*thenode
, void *theinput
);
15 void hostmask_free(searchCtx
*ctx
, struct searchNode
*thenode
);
17 struct searchNode
*hostmask_parse(searchCtx
*ctx
, int type
, int argc
, char **argv
) {
18 struct searchNode
*thenode
;
20 if (type
!= SEARCHTYPE_NICK
) {
21 parseError
= "hostmask: this function is only valid for nick searches.";
25 if (!(thenode
=(struct searchNode
*)malloc(sizeof (struct searchNode
)))) {
26 parseError
= "malloc: could not allocate memory for this search.";
30 thenode
->returntype
= RETURNTYPE_STRING
;
31 if (!(thenode
->localdata
= (void *)malloc(HOSTLEN
+USERLEN
+NICKLEN
+REALLEN
+10))) {
32 /* couldn't malloc() memory for thenode->localdata, so free thenode to avoid leakage */
33 parseError
= "malloc: could not allocate memory for this search.";
37 thenode
->exe
= hostmask_exe
;
38 thenode
->free
= hostmask_free
;
40 /* Allow "hostmask real" to match realhost */
42 if (argc
>0 && !ircd_strcmp(argv
[0],"real")) {
43 thenode
->exe
= hostmask_exe_real
;
49 void *hostmask_exe(searchCtx
*ctx
, struct searchNode
*thenode
, void *theinput
) {
50 nick
*np
= (nick
*)theinput
;
51 char *buf
= thenode
->localdata
;
53 return visiblehostmask(np
, buf
);
56 void *hostmask_exe_real(searchCtx
*ctx
, struct searchNode
*thenode
, void *theinput
) {
57 nick
*np
= (nick
*)theinput
;
58 char *buf
= thenode
->localdata
;
60 sprintf(buf
,"%s!%s@%s\r%s",np
->nick
,np
->ident
,np
->host
->name
->content
,np
->realname
->name
->content
);
65 void hostmask_free(searchCtx
*ctx
, struct searchNode
*thenode
) {
66 free(thenode
->localdata
);