]> jfr.im git - irc/quakenet/newserv.git/blob - trusts/newsearch/tns-tgroup.c
Update documentation.
[irc/quakenet/newserv.git] / trusts / newsearch / tns-tgroup.c
1 /*
2 * tgroup functionality
3 */
4
5 #include "../../newsearch/newsearch.h"
6 #include "../trusts.h"
7
8 #include <stdlib.h>
9
10 void *tgroup_exe(searchCtx *ctx, struct searchNode *thenode, void *theinput);
11 void tgroup_free(searchCtx *ctx, struct searchNode *thenode);
12
13 struct searchNode *tgroup_parse(searchCtx *ctx, int argc, char **argv) {
14 struct searchNode *thenode, *arg;
15 trustgroup *tg;
16 char *p;
17
18 if(argc < 1) {
19 parseError = "tgroup: usage: tgroup <#id|name|id>";
20 return NULL;
21 }
22
23 if(!(arg=argtoconststr("tgroup", ctx, argv[0], &p)))
24 return NULL;
25
26 tg = tg_strtotg(p);
27 (arg->free)(ctx, arg);
28 if(!tg) {
29 parseError = "tgroup: unknown group";
30 return NULL;
31 }
32
33 if(!(thenode=(struct searchNode *)malloc(sizeof (struct searchNode)))) {
34 parseError = "malloc: could not allocate memory for this search.";
35 return NULL;
36 }
37
38 thenode->returntype = RETURNTYPE_BOOL;
39 thenode->exe = tgroup_exe;
40 thenode->free = tgroup_free;
41 thenode->localdata = tg;
42
43 return thenode;
44 }
45
46 void *tgroup_exe(searchCtx *ctx, struct searchNode *thenode, void *theinput) {
47 nick *np = theinput;
48 trusthost *th = gettrusthost(np);
49 trustgroup *tg = thenode->localdata;
50
51 if(th && (th->group == tg))
52 return (void *)1;
53
54 return (void *)0;
55 }
56
57 void tgroup_free(searchCtx *ctx, struct searchNode *thenode) {
58 free(thenode);
59 }
60