]> jfr.im git - irc/quakenet/newserv.git/blame - newsearch/ns-channel.c
LUA: port luadb to dbapi2 to drop postgres dependency
[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) {
31686847 16 struct searchNode *thenode, *convsn;
4fcd68d2 17 chanindex *cip;
31686847
CP
18 char *p;
19
c86edd1d
Q
20 if (argc<1) {
21 parseError = "channel: usage: channel <channel name>";
22 return NULL;
23 }
24
31686847
CP
25 if (!(convsn=argtoconststr("channel", ctx, argv[0], &p)))
26 return NULL;
27
4fcd68d2 28 cip=findorcreatechanindex(p);
31686847 29 convsn->free(ctx, convsn);
c86edd1d 30
9ce4f0be
IB
31 if (!(thenode=(struct searchNode *)malloc(sizeof (struct searchNode)))) {
32 parseError = "malloc: could not allocate memory for this search.";
33 return NULL;
34 }
c86edd1d 35
c7f7a584 36 thenode->returntype = RETURNTYPE_BOOL;
4fcd68d2 37 thenode->localdata = cip;
c86edd1d
Q
38 thenode->exe = channel_exe;
39 thenode->free = channel_free;
40
41 return thenode;
42}
43
c8be5183 44void *channel_exe(searchCtx *ctx, struct searchNode *thenode, void *theinput) {
c86edd1d 45 nick *np = (nick *)theinput;
4fcd68d2
GB
46 chanindex *cip = thenode->localdata;
47 channel *cp;
48 whowas *ww;
49 int i;
c86edd1d 50
6d6b2cb9
GB
51 if (ctx->searchcmd == reg_whowassearch) {
52 ww = (whowas *)np->next; /* Eww. */
53
54 for (i = 0; i < WW_MAXCHANNELS; i++)
55 if (ww->channels[i] == cip)
56 return (void *)1;
57 } else {
4fcd68d2
GB
58 cp = cip->channel;
59
60 if (!cp)
61 return (void *)0;
62
63 if (getnumerichandlefromchanhash(cp->users, np->numeric))
64 return (void *)1;
c86edd1d 65 }
4fcd68d2
GB
66
67 return (void *)0;
c86edd1d
Q
68}
69
c8be5183 70void channel_free(searchCtx *ctx, struct searchNode *thenode) {
4fcd68d2 71 releasechanindex(thenode->localdata);
c86edd1d
Q
72 free(thenode);
73}
74