]> jfr.im git - irc/quakenet/newserv.git/blob - newsearch/ns-channel.c
Initial Import
[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 "../nick/nick.h"
11 #include "../channel/channel.h"
12
13 void *channel_exe(struct searchNode *thenode, int type, void *theinput);
14 void channel_free(struct searchNode *thenode);
15
16 struct searchNode *channel_parse(int type, int argc, char **argv) {
17 struct searchNode *thenode;
18 channel *cp;
19
20 if (type != SEARCHTYPE_NICK) {
21 parseError = "channel: this function is only valid for nick searches.";
22 return NULL;
23 }
24
25 if (argc<1) {
26 parseError = "channel: usage: channel <channel name>";
27 return NULL;
28 }
29
30 if (!(cp=findchannel(argv[0]))) {
31 parseError = "channel: unknown channel";
32 return NULL;
33 }
34
35 thenode=(struct searchNode *)malloc(sizeof (struct searchNode));
36
37 thenode->returntype = RETURNTYPE_STRING;
38 thenode->localdata = cp;
39 thenode->exe = channel_exe;
40 thenode->free = channel_free;
41
42 return thenode;
43 }
44
45 void *channel_exe(struct searchNode *thenode, int type, void *theinput) {
46 nick *np = (nick *)theinput;
47 channel *cp = thenode->localdata;
48
49 if (getnumerichandlefromchanhash(cp->users, np->numeric)) {
50 return trueval(type);
51 } else {
52 return falseval(type);
53 }
54 }
55
56 void channel_free(struct searchNode *thenode) {
57 free(thenode);
58 }
59