]>
jfr.im git - irc/quakenet/newserv.git/blob - newsearch/ns-modes.c
10 #include "../channel/channel.h"
11 #include "../lib/flags.h"
13 struct modes_localdata
{
19 void *modes_exe(struct searchNode
*thenode
, int type
, void *theinput
);
20 void modes_free(struct searchNode
*thenode
);
22 struct searchNode
*modes_parse(int type
, int argc
, char **argv
) {
23 struct modes_localdata
*localdata
;
24 struct searchNode
*thenode
;
28 parseError
="modes: usage: modes (mode string)";
33 case SEARCHTYPE_CHANNEL
:
42 parseError
="modes: unsupported search type";
46 if (!(localdata
=(struct modes_localdata
*)malloc(sizeof(struct modes_localdata
)))) {
47 parseError
= "malloc: could not allocate memory for this search.";
52 localdata
->setmodes
=0;
53 localdata
->clearmodes
= ~0;
55 setflags(&(localdata
->setmodes
), 0xFFFF, argv
[0], flaglist
, REJECT_NONE
);
56 setflags(&(localdata
->clearmodes
), 0xFFFF, argv
[0], flaglist
, REJECT_NONE
);
58 localdata
->clearmodes
= ~(localdata
->clearmodes
);
60 if (!(thenode
=(struct searchNode
*)malloc(sizeof(struct searchNode
)))) {
61 /* couldn't malloc() memory for thenode, so free localdata to avoid leakage */
62 parseError
= "malloc: could not allocate memory for this search.";
67 thenode
->returntype
= RETURNTYPE_BOOL
;
68 thenode
->localdata
= (void *)localdata
;
69 thenode
->exe
= modes_exe
;
70 thenode
->free
= modes_free
;
75 void *modes_exe(struct searchNode
*thenode
, int type
, void *value
) {
76 struct modes_localdata
*localdata
;
81 localdata
= (struct modes_localdata
*)thenode
->localdata
;
83 switch (localdata
->type
) {
84 case SEARCHTYPE_CHANNEL
:
85 cip
=(chanindex
*)value
;
88 flags
=cip
->channel
->flags
;
100 if (~flags
& (localdata
->setmodes
))
101 return falseval(type
);
103 if (flags
& (localdata
->clearmodes
))
104 return falseval(type
);
106 return trueval(type
);
109 void modes_free(struct searchNode
*thenode
) {
110 free (thenode
->localdata
);