]>
Commit | Line | Data |
---|---|---|
bbef4b5d | 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 | ||
b888ae09 CP |
12 | void *qusers_exe(searchCtx *, struct searchNode *thenode, void *theinput); |
13 | void qusers_free(searchCtx *, struct searchNode *thenode); | |
bbef4b5d | 14 | |
15 | struct qusers_localdata { | |
16 | flag_t setmodes; | |
17 | flag_t clearmodes; | |
18 | }; | |
19 | ||
a92bb8e1 | 20 | struct searchNode *qusers_parse(searchCtx *ctx, int argc, char **argv) { |
bbef4b5d | 21 | struct searchNode *thenode; |
22 | struct qusers_localdata *localdata; | |
23 | ||
bbef4b5d | 24 | if (!(thenode=(struct searchNode *)malloc(sizeof (struct searchNode)))) { |
25 | parseError = "malloc: could not allocate memory for this search."; | |
26 | return NULL; | |
27 | } | |
28 | ||
29 | thenode->localdata=localdata=malloc(sizeof(struct qusers_localdata)); | |
30 | thenode->returntype = RETURNTYPE_INT; | |
31 | thenode->exe = qusers_exe; | |
32 | thenode->free = qusers_free; | |
33 | ||
34 | if (argc==0) { | |
35 | localdata->setmodes=0; | |
36 | localdata->clearmodes=0; | |
37 | } else { | |
38 | localdata->setmodes=0; | |
39 | localdata->clearmodes=~0; | |
40 | ||
41 | setflags(&(localdata->setmodes), QCUFLAG_ALL, argv[0], rcuflags, REJECT_NONE); | |
42 | setflags(&(localdata->clearmodes), QCUFLAG_ALL, argv[0], rcuflags, REJECT_NONE); | |
43 | ||
44 | localdata->clearmodes = ~localdata->clearmodes; | |
45 | } | |
46 | ||
47 | return thenode; | |
48 | } | |
49 | ||
20b9980a | 50 | void *qusers_exe(searchCtx *ctx, struct searchNode *thenode, void *theinput) { |
bbef4b5d | 51 | chanindex *cip = (chanindex *)theinput; |
52 | regchan *rcp; | |
53 | regchanuser *rcup; | |
54 | struct qusers_localdata *localdata=thenode->localdata; | |
55 | unsigned long i,count=0; | |
56 | ||
57 | if (!(rcp=cip->exts[chanservext])) | |
58 | return (void *)0; | |
59 | ||
60 | for (i=0;i<REGCHANUSERHASHSIZE;i++) { | |
61 | for (rcup=rcp->regusers[i];rcup;rcup=rcup->nextbychan) { | |
62 | if ((rcup->flags & localdata->setmodes) != localdata->setmodes) | |
63 | continue; | |
64 | ||
65 | if (rcup->flags & localdata->clearmodes) | |
66 | continue; | |
67 | ||
68 | count++; | |
69 | } | |
70 | } | |
71 | ||
72 | return (void *)count; | |
73 | } | |
74 | ||
20b9980a | 75 | void qusers_free(searchCtx *ctx, struct searchNode *thenode) { |
bbef4b5d | 76 | free(thenode->localdata); |
77 | free(thenode); | |
78 | } | |
79 |