#include "../channel/channel.h"
-void *channel_exe(struct searchNode *thenode, int type, void *theinput);
-void channel_free(struct searchNode *thenode);
-
-struct searchNode *channel_parse(int type, int argc, char **argv) {
- struct searchNode *thenode;
- channel *cp;
-
- if (type != SEARCHTYPE_NICK) {
- parseError = "channel: this function is only valid for nick searches.";
- return NULL;
- }
+void *channel_exe(searchCtx *ctx, struct searchNode *thenode, void *theinput);
+void channel_free(searchCtx *ctx, struct searchNode *thenode);
+struct searchNode *channel_parse(searchCtx *ctx, int argc, char **argv) {
+ struct searchNode *thenode, *convsn;
+ chanindex *cip;
+ char *p;
+
if (argc<1) {
parseError = "channel: usage: channel <channel name>";
return NULL;
}
- if (!(cp=findchannel(argv[0]))) {
- parseError = "channel: unknown channel";
+ if (!(convsn=argtoconststr("channel", ctx, argv[0], &p)))
return NULL;
- }
- thenode=(struct searchNode *)malloc(sizeof (struct searchNode));
+ cip=findorcreatechanindex(p);
+ convsn->free(ctx, convsn);
+
+ if (!(thenode=(struct searchNode *)malloc(sizeof (struct searchNode)))) {
+ parseError = "malloc: could not allocate memory for this search.";
+ return NULL;
+ }
- thenode->returntype = RETURNTYPE_STRING;
- thenode->localdata = cp;
+ thenode->returntype = RETURNTYPE_BOOL;
+ thenode->localdata = cip;
thenode->exe = channel_exe;
thenode->free = channel_free;
return thenode;
}
-void *channel_exe(struct searchNode *thenode, int type, void *theinput) {
+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 (ctx->searchcmd == reg_whowassearch) {
+ ww = (whowas *)np->next; /* Eww. */
- if (getnumerichandlefromchanhash(cp->users, np->numeric)) {
- return trueval(type);
+ for (i = 0; i < WW_MAXCHANNELS; i++)
+ if (ww->channels[i] == cip)
+ return (void *)1;
} else {
- return falseval(type);
+ cp = cip->channel;
+
+ if (!cp)
+ return (void *)0;
+
+ if (getnumerichandlefromchanhash(cp->users, np->numeric))
+ return (void *)1;
}
+
+ return (void *)0;
}
-void channel_free(struct searchNode *thenode) {
+void channel_free(searchCtx *ctx, struct searchNode *thenode) {
+ releasechanindex(thenode->localdata);
free(thenode);
}