]>
jfr.im git - irc/quakenet/newserv.git/blob - newsearch/ns-nick.c
10 struct nick_localdata
{
15 void *nick_exe(struct searchNode
*thenode
, int type
, void *theinput
);
16 void nick_free(struct searchNode
*thenode
);
18 struct searchNode
*nick_parse(int type
, int argc
, char **argv
) {
19 struct nick_localdata
*localdata
;
20 struct searchNode
*thenode
;
22 if (!(localdata
=(struct nick_localdata
*)malloc(sizeof(struct nick_localdata
)))) {
23 parseError
= "malloc: could not allocate memory for this search.";
28 case SEARCHTYPE_CHANNEL
:
30 parseError
="nick: usage: (nick target)";
34 if ((localdata
->np
=getnickbynick(argv
[0]))==NULL
) {
35 parseError
="nick: unknown nickname";
39 localdata
->type
= type
;
44 parseError
="nick: usage: (match (nick) target)";
48 localdata
->type
= type
;
53 parseError
="nick: unsupported search type";
58 if (!(thenode
=(struct searchNode
*)malloc(sizeof(struct searchNode
)))) {
59 /* couldn't malloc() memory for thenode, so free localdata to avoid leakage */
60 parseError
= "malloc: could not allocate memory for this search.";
65 if (type
== SEARCHTYPE_CHANNEL
)
66 thenode
->returntype
= RETURNTYPE_BOOL
;
68 thenode
->returntype
= RETURNTYPE_STRING
;
69 thenode
->localdata
= localdata
;
70 thenode
->exe
= nick_exe
;
71 thenode
->free
= nick_free
;
76 void *nick_exe(struct searchNode
*thenode
, int type
, void *theinput
) {
77 struct nick_localdata
*localdata
;
81 localdata
= thenode
->localdata
;
83 switch (localdata
->type
) {
84 case SEARCHTYPE_CHANNEL
:
85 cip
= (chanindex
*)theinput
;
87 if (cip
->channel
==NULL
|| getnumerichandlefromchanhash(cip
->channel
->users
, localdata
->np
->numeric
)==NULL
)
88 return falseval(type
); /* user/channel not found */
89 return trueval(type
); /* found user on channel */
92 np
= (nick
*)theinput
;
94 if (type
!= RETURNTYPE_STRING
)
99 if (type
!= RETURNTYPE_STRING
)
105 void nick_free(struct searchNode
*thenode
) {
106 free(thenode
->localdata
);