]> jfr.im git - irc/quakenet/newserv.git/blame - chanserv/newsearch/csns-qchanflags.c
Fix memory/resource leaks.
[irc/quakenet/newserv.git] / chanserv / newsearch / csns-qchanflags.c
CommitLineData
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
12void *qchanflags_exe(searchCtx *, struct searchNode *thenode, void *theinput);
13void qchanflags_free(searchCtx *, struct searchNode *thenode);
14
15struct qchanflags_localdata {
16 flag_t setmodes;
17 flag_t clearmodes;
18};
19
a92bb8e1 20struct 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 {
757e4853
CP
38 struct searchNode *arg;
39 char *p;
40
a1b20483
CP
41 localdata->setmodes=0;
42 localdata->clearmodes=~0;
757e4853
CP
43
44 if (!(arg=argtoconststr("qchanflags", ctx, argv[0], &p))) {
45 free(thenode);
46 return NULL;
47 }
48
49 setflags(&(localdata->setmodes), QCFLAG_ALL, p, rcflags, REJECT_NONE);
50 setflags(&(localdata->clearmodes), QCFLAG_ALL, p, rcflags, REJECT_NONE);
51 arg->free(ctx, arg);
52
a1b20483
CP
53 localdata->clearmodes = ~localdata->clearmodes;
54 }
55
56 return thenode;
57}
58
59void *qchanflags_exe(searchCtx *ctx, struct searchNode *thenode, void *theinput) {
60 chanindex *cip = (chanindex *)theinput;
61 regchan *rcp;
62 struct qchanflags_localdata *localdata=thenode->localdata;
63
64 if (!(rcp=cip->exts[chanservext]))
65 return (void *)0;
66
67 if (((rcp->flags & localdata->setmodes) != localdata->setmodes) || (rcp->flags & localdata->clearmodes))
68 return (void *)0;
69
70 return (void *)1;
71}
72
73void qchanflags_free(searchCtx *ctx, struct searchNode *thenode) {
74 free(thenode->localdata);
75 free(thenode);
76}
77