]> jfr.im git - irc/quakenet/newserv.git/blob - newsearch/ns-channel.c
CHANSERV: fix issue where chanserv_relay doesn't wait for db to be loaded before...
[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 chanindex *cip;
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 cip=findorcreatechanindex(p);
29 convsn->free(ctx, convsn);
30
31 if (!(thenode=(struct searchNode *)malloc(sizeof (struct searchNode)))) {
32 parseError = "malloc: could not allocate memory for this search.";
33 return NULL;
34 }
35
36 thenode->returntype = RETURNTYPE_BOOL;
37 thenode->localdata = cip;
38 thenode->exe = channel_exe;
39 thenode->free = channel_free;
40
41 return thenode;
42 }
43
44 void *channel_exe(searchCtx *ctx, struct searchNode *thenode, void *theinput) {
45 nick *np = (nick *)theinput;
46 chanindex *cip = thenode->localdata;
47 channel *cp;
48 whowas *ww;
49 int i;
50
51 if (ctx->searchcmd == reg_nicksearch) {
52 cp = cip->channel;
53
54 if (!cp)
55 return (void *)0;
56
57 if (getnumerichandlefromchanhash(cp->users, np->numeric))
58 return (void *)1;
59 } else {
60 ww = (whowas *)np->next; /* Eww. */
61
62 for (i = 0; i < WW_MAXCHANNELS; i++)
63 if (ww->channels[i] == cip)
64 return (void *)1;
65 }
66
67 return (void *)0;
68 }
69
70 void channel_free(searchCtx *ctx, struct searchNode *thenode) {
71 releasechanindex(thenode->localdata);
72 free(thenode);
73 }
74