]>
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.";
26 if (ctx
->searchcmd
== reg_chansearch
) {
28 parseError
="nick: usage: (nick target)";
32 if ((localdata
->np
=getnickbynick(argv
[0]))==NULL
) {
33 parseError
="nick: unknown nickname";
37 } else if (ctx
->searchcmd
== reg_nicksearch
) {
39 parseError
="nick: usage: (match (nick) target)";
45 parseError
="nick: invalid search command";
50 if (!(thenode
=(struct searchNode
*)malloc(sizeof(struct searchNode
)))) {
51 /* couldn't malloc() memory for thenode, so free localdata to avoid leakage */
52 parseError
= "malloc: could not allocate memory for this search.";
57 if (ctx
->searchcmd
== reg_chansearch
)
58 thenode
->returntype
= RETURNTYPE_BOOL
;
60 thenode
->returntype
= RETURNTYPE_STRING
;
61 thenode
->localdata
= localdata
;
62 thenode
->exe
= nick_exe
;
63 thenode
->free
= nick_free
;
68 void *nick_exe(searchCtx
*ctx
, struct searchNode
*thenode
, void *theinput
) {
69 struct nick_localdata
*localdata
;
73 localdata
= thenode
->localdata
;
75 if (ctx
->searchcmd
== reg_chansearch
) {
76 cip
= (chanindex
*)theinput
;
78 if (cip
->channel
==NULL
|| getnumerichandlefromchanhash(cip
->channel
->users
, localdata
->np
->numeric
)==NULL
)
83 np
= (nick
*)theinput
;
89 void nick_free(searchCtx
*ctx
, struct searchNode
*thenode
) {
90 free(thenode
->localdata
);