]> jfr.im git - irc/quakenet/newserv.git/blob - chanserv/newsearch/csns-qchanflags.c
b14bd8129b841b71fc26c1f6d71fa415a25b87a6
[irc/quakenet/newserv.git] / chanserv / newsearch / csns-qchanflags.c
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
20 struct searchNode *qchanflags_parse(searchCtx *ctx, int type, int argc, char **argv) {
21 struct searchNode *thenode;
22 struct qchanflags_localdata *localdata;
23
24 if (type != SEARCHTYPE_CHANNEL) {
25 parseError = "qchanflags: 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 qchanflags_localdata));
35 thenode->returntype = RETURNTYPE_INT;
36 thenode->exe = qchanflags_exe;
37 thenode->free = qchanflags_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), QCFLAG_ALL, argv[0], rcflags, REJECT_NONE);
47 setflags(&(localdata->clearmodes), QCFLAG_ALL, argv[0], rcflags, REJECT_NONE);
48
49 localdata->clearmodes = ~localdata->clearmodes;
50 }
51
52 return thenode;
53 }
54
55 void *qchanflags_exe(searchCtx *ctx, struct searchNode *thenode, void *theinput) {
56 chanindex *cip = (chanindex *)theinput;
57 regchan *rcp;
58 struct qchanflags_localdata *localdata=thenode->localdata;
59
60 if (!(rcp=cip->exts[chanservext]))
61 return (void *)0;
62
63 if (((rcp->flags & localdata->setmodes) != localdata->setmodes) || (rcp->flags & localdata->clearmodes))
64 return (void *)0;
65
66 return (void *)1;
67 }
68
69 void qchanflags_free(searchCtx *ctx, struct searchNode *thenode) {
70 free(thenode->localdata);
71 free(thenode);
72 }
73