]>
jfr.im git - irc/quakenet/newserv.git/blob - newsearch/ns-nick.c
10 struct nick_localdata
{
14 void *nick_exe(searchCtx
*ctx
, struct searchNode
*thenode
, void *theinput
);
15 void nick_free(searchCtx
*ctx
, struct searchNode
*thenode
);
17 struct searchNode
*nick_parse(searchCtx
*ctx
, int argc
, char **argv
) {
18 struct nick_localdata
*localdata
;
19 struct searchNode
*thenode
;
21 if (!(localdata
=(struct nick_localdata
*)malloc(sizeof(struct nick_localdata
)))) {
22 parseError
= "malloc: could not allocate memory for this search.";
27 case SEARCHTYPE_CHANNEL
:
29 parseError
="nick: usage: (nick target)";
33 if ((localdata
->np
=getnickbynick(argv
[0]))==NULL
) {
34 parseError
="nick: unknown nickname";
42 parseError
="nick: usage: (match (nick) target)";
50 parseError
="nick: unsupported search type";
55 if (!(thenode
=(struct searchNode
*)malloc(sizeof(struct searchNode
)))) {
56 /* couldn't malloc() memory for thenode, so free localdata to avoid leakage */
57 parseError
= "malloc: could not allocate memory for this search.";
62 if (ctx
->type
== SEARCHTYPE_CHANNEL
)
63 thenode
->returntype
= RETURNTYPE_BOOL
;
65 thenode
->returntype
= RETURNTYPE_STRING
;
66 thenode
->localdata
= localdata
;
67 thenode
->exe
= nick_exe
;
68 thenode
->free
= nick_free
;
73 void *nick_exe(searchCtx
*ctx
, struct searchNode
*thenode
, void *theinput
) {
74 struct nick_localdata
*localdata
;
78 localdata
= thenode
->localdata
;
81 case SEARCHTYPE_CHANNEL
:
82 cip
= (chanindex
*)theinput
;
84 if (cip
->channel
==NULL
|| getnumerichandlefromchanhash(cip
->channel
->users
, localdata
->np
->numeric
)==NULL
)
91 np
= (nick
*)theinput
;
97 void nick_free(searchCtx
*ctx
, struct searchNode
*thenode
) {
98 free(thenode
->localdata
);