]>
jfr.im git - irc/quakenet/newserv.git/blob - newsearch/ns-cumodes.c
2 * CUMODES functionality
10 struct cumodes_localdata
{
13 struct searchNode
*xnode
;
20 const flag cumodelist
[] = {
26 void *cumodes_nick_exe(searchCtx
*ctx
, struct searchNode
*thenode
, void *theinput
);
27 void *cumodes_chan_exe(searchCtx
*ctx
, struct searchNode
*thenode
, void *theinput
);
28 void cumodes_free(searchCtx
*ctx
, struct searchNode
*thenode
);
30 struct searchNode
*cumodes_parse(searchCtx
*ctx
, int argc
, char **argv
) {
31 struct cumodes_localdata
*localdata
;
32 struct searchNode
*thenode
, *flagstr
;
37 parseError
="cumodes: usage: cumodes (string) (mode string)";
41 if (!(ctx
->searchcmd
== reg_nicksearch
) && !(ctx
->searchcmd
== reg_chansearch
)) {
42 parseError
="cumodes: cannot be used outside of nicksearch or chansearch";
46 if (!(localdata
=(struct cumodes_localdata
*)malloc(sizeof(struct cumodes_localdata
)))) {
47 parseError
= "malloc: could not allocate memory for this search.";
51 localdata
->xnode
= ctx
->parser(ctx
, argv
[0]);
52 if (!(localdata
->xnode
= coerceNode(ctx
, localdata
->xnode
, RETURNTYPE_STRING
))) {
60 if (!(flagstr
=argtoconststr("cumodes", ctx
, argv
[0], &p
))) {
61 localdata
->xnode
->free(ctx
, localdata
->xnode
);
65 setflags(&(fset
), CU_ALL
, p
, cumodelist
, REJECT_NONE
);
66 setflags(&(fclear
), CU_ALL
, p
, cumodelist
, REJECT_NONE
);
67 flagstr
->free(ctx
, flagstr
);
69 localdata
->setmodes
=0;
70 localdata
->clearmodes
=~0;
73 localdata
->setmodes
|=CUMODE_OP
;
75 localdata
->setmodes
|=CUMODE_VOICE
;
77 localdata
->clearmodes
&=~CUMODE_OP
;
78 if(!(fclear
& CU_VOICE
))
79 localdata
->clearmodes
&=~CUMODE_VOICE
;
81 localdata
->clearmodes
= ~(localdata
->clearmodes
);
83 if (!(thenode
=(struct searchNode
*)malloc(sizeof(struct searchNode
)))) {
84 /* couldn't malloc() memory for thenode, so free localdata to avoid leakage */
85 parseError
= "malloc: could not allocate memory for this search.";
86 (localdata
->xnode
->free
)(ctx
, localdata
->xnode
);
91 thenode
->returntype
= RETURNTYPE_BOOL
;
92 thenode
->localdata
= (void *)localdata
;
94 if (ctx
->searchcmd
== reg_nicksearch
) {
95 thenode
->exe
= cumodes_nick_exe
;
96 } else if (ctx
->searchcmd
== reg_chansearch
) {
97 thenode
->exe
= cumodes_chan_exe
;
98 } else { /* We really shouldn't get here */
99 parseError
= "cumodes: internal code error.";
101 (localdata
->xnode
->free
)(ctx
, localdata
->xnode
);
106 thenode
->free
= cumodes_free
;
111 void *cumodes_nick_exe(searchCtx
*ctx
, struct searchNode
*thenode
, void *value
) {
112 struct cumodes_localdata
*localdata
;
113 nick
*np
= (nick
*)value
;
116 unsigned long *lp
, flags
;
118 localdata
= (struct cumodes_localdata
*)thenode
->localdata
;
121 channame
= (char *)(localdata
->xnode
->exe
) (ctx
, localdata
->xnode
, value
);
122 cp
= findchannel(channame
);
126 lp
= getnumerichandlefromchanhash(cp
->users
,np
->numeric
);
132 if (~flags
& (localdata
->setmodes
))
135 if (flags
& (localdata
->clearmodes
))
141 void *cumodes_chan_exe(searchCtx
*ctx
, struct searchNode
*thenode
, void *value
) {
142 struct cumodes_localdata
*localdata
;
143 chanindex
*cip
= (chanindex
*)value
;
146 unsigned long *lp
, flags
;
148 if(!cip
->channel
|| !cip
->channel
->users
)
151 localdata
= (struct cumodes_localdata
*)thenode
->localdata
;
154 nickname
= (char *)(localdata
->xnode
->exe
) (ctx
, localdata
->xnode
, value
);
155 np
= getnickbynick(nickname
);
159 lp
= getnumerichandlefromchanhash(cip
->channel
->users
,np
->numeric
);
165 if (~flags
& (localdata
->setmodes
))
168 if (flags
& (localdata
->clearmodes
))
174 void cumodes_free(searchCtx
*ctx
, struct searchNode
*thenode
) {
175 struct cumodes_localdata
*localdata
= (struct cumodes_localdata
*)thenode
->localdata
;
176 (localdata
->xnode
->free
)(ctx
, localdata
->xnode
);
177 free (thenode
->localdata
);