]>
Commit | Line | Data |
---|---|---|
a1b20483 CP |
1 | /* |
2 | * qchanflags 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 *qchanflags_exe(searchCtx *, struct searchNode *thenode, void *theinput); | |
13 | void qchanflags_free(searchCtx *, struct searchNode *thenode); | |
14 | ||
15 | struct qchanflags_localdata { | |
16 | flag_t setmodes; | |
17 | flag_t clearmodes; | |
18 | }; | |
19 | ||
a92bb8e1 | 20 | struct searchNode *qchanflags_parse(searchCtx *ctx, int argc, char **argv) { |
a1b20483 CP |
21 | struct searchNode *thenode; |
22 | struct qchanflags_localdata *localdata; | |
23 | ||
a1b20483 CP |
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 qchanflags_localdata)); | |
30 | thenode->returntype = RETURNTYPE_INT; | |
31 | thenode->exe = qchanflags_exe; | |
32 | thenode->free = qchanflags_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 | ||
0070ca53 CP |
41 | setflags(&(localdata->setmodes), QCFLAG_ALL, argv[0], rcflags, REJECT_NONE); |
42 | setflags(&(localdata->clearmodes), QCFLAG_ALL, argv[0], rcflags, REJECT_NONE); | |
a1b20483 CP |
43 | |
44 | localdata->clearmodes = ~localdata->clearmodes; | |
45 | } | |
46 | ||
47 | return thenode; | |
48 | } | |
49 | ||
50 | void *qchanflags_exe(searchCtx *ctx, struct searchNode *thenode, void *theinput) { | |
51 | chanindex *cip = (chanindex *)theinput; | |
52 | regchan *rcp; | |
53 | struct qchanflags_localdata *localdata=thenode->localdata; | |
54 | ||
55 | if (!(rcp=cip->exts[chanservext])) | |
56 | return (void *)0; | |
57 | ||
58 | if (((rcp->flags & localdata->setmodes) != localdata->setmodes) || (rcp->flags & localdata->clearmodes)) | |
59 | return (void *)0; | |
60 | ||
61 | return (void *)1; | |
62 | } | |
63 | ||
64 | void qchanflags_free(searchCtx *ctx, struct searchNode *thenode) { | |
65 | free(thenode->localdata); | |
66 | free(thenode); | |
67 | } | |
68 |