]> jfr.im git - irc/quakenet/newserv.git/blob - newsearch/ns-channel.c
merge
[irc/quakenet/newserv.git] / newsearch / ns-channel.c
1 /*
2 * CHANNEL functionality
3 */
4
5 #include "newsearch.h"
6
7 #include <stdio.h>
8 #include <stdlib.h>
9
10 #include "../channel/channel.h"
11
12 void *channel_exe(searchCtx *ctx, struct searchNode *thenode, void *theinput);
13 void channel_free(searchCtx *ctx, struct searchNode *thenode);
14
15 struct searchNode *channel_parse(searchCtx *ctx, int argc, char **argv) {
16 struct searchNode *thenode, *convsn;
17 channel *cp;
18 char *p;
19
20 if (argc<1) {
21 parseError = "channel: usage: channel <channel name>";
22 return NULL;
23 }
24
25 if (!(convsn=argtoconststr("channel", ctx, argv[0], &p)))
26 return NULL;
27
28 cp=findchannel(p);
29 convsn->free(ctx, convsn);
30 if (!cp) {
31 parseError = "channel: unknown channel";
32 return NULL;
33 }
34
35 if (!(thenode=(struct searchNode *)malloc(sizeof (struct searchNode)))) {
36 parseError = "malloc: could not allocate memory for this search.";
37 return NULL;
38 }
39
40 thenode->returntype = RETURNTYPE_BOOL;
41 thenode->localdata = cp;
42 thenode->exe = channel_exe;
43 thenode->free = channel_free;
44
45 return thenode;
46 }
47
48 void *channel_exe(searchCtx *ctx, struct searchNode *thenode, void *theinput) {
49 nick *np = (nick *)theinput;
50 channel *cp = thenode->localdata;
51
52 if (getnumerichandlefromchanhash(cp->users, np->numeric)) {
53 return (void *)1;
54 } else {
55 return (void *)0;
56 }
57 }
58
59 void channel_free(searchCtx *ctx, struct searchNode *thenode) {
60 free(thenode);
61 }
62