]> jfr.im git - irc/quakenet/newserv.git/blame - newsearch/ns-channel.c
SearchCtx should contain 'type' - this is to make life easier when defining new searc...
[irc/quakenet/newserv.git] / newsearch / ns-channel.c
CommitLineData
c86edd1d
Q
1/*
2 * CHANNEL functionality
3 */
4
5#include "newsearch.h"
6
7#include <stdio.h>
8#include <stdlib.h>
9
c86edd1d
Q
10#include "../channel/channel.h"
11
c8be5183
CP
12void *channel_exe(searchCtx *ctx, struct searchNode *thenode, void *theinput);
13void channel_free(searchCtx *ctx, struct searchNode *thenode);
c86edd1d 14
f33f3f52 15struct searchNode *channel_parse(searchCtx *ctx, int argc, char **argv) {
c86edd1d
Q
16 struct searchNode *thenode;
17 channel *cp;
18
f33f3f52 19 if (ctx->type != SEARCHTYPE_NICK) {
c86edd1d
Q
20 parseError = "channel: this function is only valid for nick searches.";
21 return NULL;
22 }
23
24 if (argc<1) {
25 parseError = "channel: usage: channel <channel name>";
26 return NULL;
27 }
28
29 if (!(cp=findchannel(argv[0]))) {
30 parseError = "channel: unknown channel";
31 return NULL;
32 }
33
9ce4f0be
IB
34 if (!(thenode=(struct searchNode *)malloc(sizeof (struct searchNode)))) {
35 parseError = "malloc: could not allocate memory for this search.";
36 return NULL;
37 }
c86edd1d 38
c7f7a584 39 thenode->returntype = RETURNTYPE_BOOL;
c86edd1d
Q
40 thenode->localdata = cp;
41 thenode->exe = channel_exe;
42 thenode->free = channel_free;
43
44 return thenode;
45}
46
c8be5183 47void *channel_exe(searchCtx *ctx, struct searchNode *thenode, void *theinput) {
c86edd1d
Q
48 nick *np = (nick *)theinput;
49 channel *cp = thenode->localdata;
50
51 if (getnumerichandlefromchanhash(cp->users, np->numeric)) {
c7f7a584 52 return (void *)1;
c86edd1d 53 } else {
c7f7a584 54 return (void *)0;
c86edd1d
Q
55 }
56}
57
c8be5183 58void channel_free(searchCtx *ctx, struct searchNode *thenode) {
c86edd1d
Q
59 free(thenode);
60}
61