]>
jfr.im git - irc/quakenet/newserv.git/blob - newsearch/ns-cumodecount.c
2 * CUMODECOUNT functionality
10 struct cumodecount_localdata
{
13 struct searchNode
*xnode
;
20 const flag cumodecountlist
[] = {
26 void *cumodecount_exe(searchCtx
*ctx
, struct searchNode
*thenode
, void *theinput
);
27 void cumodecount_free(searchCtx
*ctx
, struct searchNode
*thenode
);
29 struct searchNode
*cumodecount_parse(searchCtx
*ctx
, int argc
, char **argv
) {
30 struct cumodecount_localdata
*localdata
;
31 struct searchNode
*thenode
, *flagstr
;
36 parseError
="cumodes: usage: cumodecount (mode string)";
40 if (!(localdata
=(struct cumodecount_localdata
*)malloc(sizeof(struct cumodecount_localdata
)))) {
41 parseError
= "malloc: could not allocate memory for this search.";
48 if (!(flagstr
=argtoconststr("cumodecount", ctx
, argv
[0], &p
))) {
49 localdata
->xnode
->free(ctx
, localdata
->xnode
);
54 setflags(&(fset
), CU_ALL
, p
, cumodecountlist
, REJECT_NONE
);
55 setflags(&(fclear
), CU_ALL
, p
, cumodecountlist
, REJECT_NONE
);
56 flagstr
->free(ctx
, flagstr
);
58 localdata
->setmodes
=0;
59 localdata
->clearmodes
=~0;
62 localdata
->setmodes
|=CUMODE_OP
;
64 localdata
->setmodes
|=CUMODE_VOICE
;
66 localdata
->clearmodes
&=~CUMODE_OP
;
67 if(!(fclear
& CU_VOICE
))
68 localdata
->clearmodes
&=~CUMODE_VOICE
;
70 localdata
->clearmodes
= ~(localdata
->clearmodes
);
72 if (!(thenode
=(struct searchNode
*)malloc(sizeof(struct searchNode
)))) {
73 /* couldn't malloc() memory for thenode, so free localdata to avoid leakage */
74 parseError
= "malloc: could not allocate memory for this search.";
79 thenode
->returntype
= RETURNTYPE_INT
;
80 thenode
->localdata
= (void *)localdata
;
81 thenode
->exe
= cumodecount_exe
;
82 thenode
->free
= cumodecount_free
;
87 void *cumodecount_exe(searchCtx
*ctx
, struct searchNode
*thenode
, void *value
) {
88 struct cumodecount_localdata
*localdata
;
89 chanindex
*cip
= (chanindex
*)value
;
93 if(!cip
->channel
|| !cip
->channel
->users
)
96 localdata
= (struct cumodecount_localdata
*)thenode
->localdata
;
99 for (i
=0;i
<cip
->channel
->users
->hashsize
;i
++) {
100 if (cip
->channel
->users
->content
[i
]!=nouser
) {
101 flags
= cip
->channel
->users
->content
[i
];
103 if (~flags
& (localdata
->setmodes
))
105 else if (flags
& (localdata
->clearmodes
))
112 return (void *)(long)count
;
115 void cumodecount_free(searchCtx
*ctx
, struct searchNode
*thenode
) {
116 free (thenode
->localdata
);