From: Gunnar Beutner Date: Tue, 20 Aug 2013 14:43:34 +0000 (+0200) Subject: newsearch: Implement channel operator for whowassearch. X-Git-Url: https://jfr.im/git/irc/quakenet/newserv.git/commitdiff_plain/4fcd68d272d9aa8fcc05ff300f1e1053dfda8001?ds=sidebyside newsearch: Implement channel operator for whowassearch. --- diff --git a/newsearch/newsearch.c b/newsearch/newsearch.c index c8500f28..f48e6e9b 100644 --- a/newsearch/newsearch.c +++ b/newsearch/newsearch.c @@ -196,7 +196,8 @@ void _init() { registersearchterm(reg_whowassearch, "ident",ident_parse, 0, "User's current ident"); registersearchterm(reg_nicksearch, "host",host_parse, 0, "User's host, allow \"host real\" to match real host"); registersearchterm(reg_whowassearch, "host",host_parse, 0, "User's host, allow \"host real\" to match real host"); - registersearchterm(reg_nicksearch, "channel",channel_parse, 0, "Valid Channel Name to match users against"); /* nick only */ + registersearchterm(reg_nicksearch, "channel",channel_parse, 0, "Valid Channel Name to match users against"); + registersearchterm(reg_whowassearch, "channel",channel_parse, 0, "Valid Channel Name to match users against"); registersearchterm(reg_nicksearch, "timestamp",timestamp_parse, 0, "User's Timestamp"); registersearchterm(reg_whowassearch, "timestamp",timestamp_parse, 0, "User's Timestamp"); registersearchterm(reg_nicksearch, "country",country_parse, 0, "2 letter country code (data source is geoip)"); diff --git a/newsearch/ns-channel.c b/newsearch/ns-channel.c index 3a79920f..0d364775 100644 --- a/newsearch/ns-channel.c +++ b/newsearch/ns-channel.c @@ -14,7 +14,7 @@ void channel_free(searchCtx *ctx, struct searchNode *thenode); struct searchNode *channel_parse(searchCtx *ctx, int argc, char **argv) { struct searchNode *thenode, *convsn; - channel *cp; + chanindex *cip; char *p; if (argc<1) { @@ -25,12 +25,8 @@ struct searchNode *channel_parse(searchCtx *ctx, int argc, char **argv) { if (!(convsn=argtoconststr("channel", ctx, argv[0], &p))) return NULL; - cp=findchannel(p); + cip=findorcreatechanindex(p); convsn->free(ctx, convsn); - if (!cp) { - parseError = "channel: unknown channel"; - return NULL; - } if (!(thenode=(struct searchNode *)malloc(sizeof (struct searchNode)))) { parseError = "malloc: could not allocate memory for this search."; @@ -38,7 +34,7 @@ struct searchNode *channel_parse(searchCtx *ctx, int argc, char **argv) { } thenode->returntype = RETURNTYPE_BOOL; - thenode->localdata = cp; + thenode->localdata = cip; thenode->exe = channel_exe; thenode->free = channel_free; @@ -47,16 +43,32 @@ struct searchNode *channel_parse(searchCtx *ctx, int argc, char **argv) { void *channel_exe(searchCtx *ctx, struct searchNode *thenode, void *theinput) { nick *np = (nick *)theinput; - channel *cp = thenode->localdata; + chanindex *cip = thenode->localdata; + channel *cp; + whowas *ww; + int i; - if (getnumerichandlefromchanhash(cp->users, np->numeric)) { - return (void *)1; + if (ctx->searchcmd == reg_nicksearch) { + cp = cip->channel; + + if (!cp) + return (void *)0; + + if (getnumerichandlefromchanhash(cp->users, np->numeric)) + return (void *)1; } else { - return (void *)0; + ww = (whowas *)np->next; /* Eww. */ + + for (i = 0; i < WW_MAXCHANNELS; i++) + if (ww->channels[i] == cip) + return (void *)1; } + + return (void *)0; } void channel_free(searchCtx *ctx, struct searchNode *thenode) { + releasechanindex(thenode->localdata); free(thenode); }