]>
jfr.im git - irc/quakenet/newserv.git/blob - newsearch/ns-modes.c
10 struct modes_localdata
{
15 void *modes_exe(searchCtx
*ctx
, struct searchNode
*thenode
, void *theinput
);
16 void modes_free(searchCtx
*ctx
, struct searchNode
*thenode
);
18 struct searchNode
*modes_parse(searchCtx
*ctx
, int argc
, char **argv
) {
19 struct modes_localdata
*localdata
;
20 struct searchNode
*thenode
, *modestring
;
25 parseError
="modes: usage: modes (mode string)";
29 if (ctx
->searchcmd
== reg_chansearch
) {
31 } else if (ctx
->searchcmd
== reg_nicksearch
) {
34 parseError
="modes: unsupported search type";
38 if (!(localdata
=(struct modes_localdata
*)malloc(sizeof(struct modes_localdata
)))) {
39 parseError
= "malloc: could not allocate memory for this search.";
43 localdata
->setmodes
=0;
44 localdata
->clearmodes
= ~0;
46 if (!(modestring
=argtoconststr("modes", ctx
, argv
[0], &p
))) {
51 setflags(&(localdata
->setmodes
), 0xFFFF, p
, flaglist
, REJECT_NONE
);
52 setflags(&(localdata
->clearmodes
), 0xFFFF, p
, flaglist
, REJECT_NONE
);
53 (modestring
->free
)(ctx
, modestring
);
55 localdata
->clearmodes
= ~(localdata
->clearmodes
);
57 if (!(thenode
=(struct searchNode
*)malloc(sizeof(struct searchNode
)))) {
58 /* couldn't malloc() memory for thenode, so free localdata to avoid leakage */
59 parseError
= "malloc: could not allocate memory for this search.";
64 thenode
->returntype
= RETURNTYPE_BOOL
;
65 thenode
->localdata
= (void *)localdata
;
66 thenode
->exe
= modes_exe
;
67 thenode
->free
= modes_free
;
72 void *modes_exe(searchCtx
*ctx
, struct searchNode
*thenode
, void *value
) {
73 struct modes_localdata
*localdata
;
78 localdata
= (struct modes_localdata
*)thenode
->localdata
;
80 if (ctx
->searchcmd
== reg_chansearch
) {
81 cip
=(chanindex
*)value
;
84 flags
=cip
->channel
->flags
;
85 } else if (ctx
->searchcmd
== reg_nicksearch
) {
92 if (~flags
& (localdata
->setmodes
))
95 if (flags
& (localdata
->clearmodes
))
101 void modes_free(searchCtx
*ctx
, struct searchNode
*thenode
) {
102 free (thenode
->localdata
);