]>
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
) {
27 struct searchNode
*nickname
;
31 parseError
="nick: usage: (nick target)";
36 if (!(nickname
=argtoconststr("nick", ctx
, argv
[0], &p
))) {
41 localdata
->np
=getnickbynick(p
);
42 (nickname
->free
)(ctx
, nickname
);
43 if (localdata
->np
==NULL
) {
44 parseError
="nick: unknown nickname";
48 } else if (ctx
->searchcmd
== reg_nicksearch
) {
50 parseError
="nick: usage: (match (nick) target)";
56 parseError
="nick: invalid search command";
61 if (!(thenode
=(struct searchNode
*)malloc(sizeof(struct searchNode
)))) {
62 /* couldn't malloc() memory for thenode, so free localdata to avoid leakage */
63 parseError
= "malloc: could not allocate memory for this search.";
68 if (ctx
->searchcmd
== reg_chansearch
)
69 thenode
->returntype
= RETURNTYPE_BOOL
;
71 thenode
->returntype
= RETURNTYPE_STRING
;
72 thenode
->localdata
= localdata
;
73 thenode
->exe
= nick_exe
;
74 thenode
->free
= nick_free
;
79 void *nick_exe(searchCtx
*ctx
, struct searchNode
*thenode
, void *theinput
) {
80 struct nick_localdata
*localdata
;
84 localdata
= thenode
->localdata
;
86 if (ctx
->searchcmd
== reg_chansearch
) {
87 cip
= (chanindex
*)theinput
;
89 if (cip
->channel
==NULL
|| getnumerichandlefromchanhash(cip
->channel
->users
, localdata
->np
->numeric
)==NULL
)
94 np
= (nick
*)theinput
;
100 void nick_free(searchCtx
*ctx
, struct searchNode
*thenode
) {
101 free(thenode
->localdata
);