]> jfr.im git - irc/quakenet/newserv.git/blob - chanserv/newsearch/csns-qusers.c
ddf0566696b67f4ace85a020125b1519ccee50cb
[irc/quakenet/newserv.git] / chanserv / newsearch / csns-qusers.c
1 /*
2 * exists functionality
3 */
4
5 #include "../../newsearch/newsearch.h"
6 #include "../../lib/flags.h"
7 #include "../chanserv.h"
8
9 #include <stdio.h>
10 #include <stdlib.h>
11
12 void *qusers_exe(searchCtx *, struct searchNode *thenode, void *theinput);
13 void qusers_free(searchCtx *, struct searchNode *thenode);
14
15 struct qusers_localdata {
16 flag_t setmodes;
17 flag_t clearmodes;
18 };
19
20 struct searchNode *qusers_parse(searchCtx *ctx, int type, int argc, char **argv) {
21 struct searchNode *thenode;
22 struct qusers_localdata *localdata;
23
24 if (type != SEARCHTYPE_CHANNEL) {
25 parseError = "qusers: this function is only valid for channel searches.";
26 return NULL;
27 }
28
29 if (!(thenode=(struct searchNode *)malloc(sizeof (struct searchNode)))) {
30 parseError = "malloc: could not allocate memory for this search.";
31 return NULL;
32 }
33
34 thenode->localdata=localdata=malloc(sizeof(struct qusers_localdata));
35 thenode->returntype = RETURNTYPE_INT;
36 thenode->exe = qusers_exe;
37 thenode->free = qusers_free;
38
39 if (argc==0) {
40 localdata->setmodes=0;
41 localdata->clearmodes=0;
42 } else {
43 localdata->setmodes=0;
44 localdata->clearmodes=~0;
45
46 setflags(&(localdata->setmodes), QCUFLAG_ALL, argv[0], rcuflags, REJECT_NONE);
47 setflags(&(localdata->clearmodes), QCUFLAG_ALL, argv[0], rcuflags, REJECT_NONE);
48
49 localdata->clearmodes = ~localdata->clearmodes;
50 }
51
52 return thenode;
53 }
54
55 void *qusers_exe(searchCtx *ctx, struct searchNode *thenode, void *theinput) {
56 chanindex *cip = (chanindex *)theinput;
57 regchan *rcp;
58 regchanuser *rcup;
59 struct qusers_localdata *localdata=thenode->localdata;
60 unsigned long i,count=0;
61
62 if (!(rcp=cip->exts[chanservext]))
63 return (void *)0;
64
65 for (i=0;i<REGCHANUSERHASHSIZE;i++) {
66 for (rcup=rcp->regusers[i];rcup;rcup=rcup->nextbychan) {
67 if ((rcup->flags & localdata->setmodes) != localdata->setmodes)
68 continue;
69
70 if (rcup->flags & localdata->clearmodes)
71 continue;
72
73 count++;
74 }
75 }
76
77 return (void *)count;
78 }
79
80 void qusers_free(searchCtx *ctx, struct searchNode *thenode) {
81 free(thenode->localdata);
82 free(thenode);
83 }
84