struct nick_localdata {
nick *np;
- int type;
};
-void *nick_exe(struct searchNode *thenode, void *theinput);
-void nick_free(struct searchNode *thenode);
+void *nick_exe(searchCtx *ctx, struct searchNode *thenode, void *theinput);
+void nick_free(searchCtx *ctx, struct searchNode *thenode);
-struct searchNode *nick_parse(int type, int argc, char **argv) {
+struct searchNode *nick_parse(searchCtx *ctx, int argc, char **argv) {
struct nick_localdata *localdata;
struct searchNode *thenode;
return NULL;
}
- switch (type) {
- case SEARCHTYPE_CHANNEL:
+ if (ctx->searchcmd == reg_chansearch) {
+ struct searchNode *nickname;
+ char *p;
+
if (argc!=1) {
parseError="nick: usage: (nick target)";
free(localdata);
return NULL;
}
- if ((localdata->np=getnickbynick(argv[0]))==NULL) {
+
+ if (!(nickname=argtoconststr("nick", ctx, argv[0], &p))) {
+ free(localdata);
+ return NULL;
+ }
+
+ localdata->np=getnickbynick(p);
+ (nickname->free)(ctx, nickname);
+ if (localdata->np==NULL) {
parseError="nick: unknown nickname";
free(localdata);
return NULL;
}
- localdata->type = type;
- break;
-
- case SEARCHTYPE_NICK:
+ } else {
if (argc) {
parseError="nick: usage: (match (nick) target)";
free(localdata);
return NULL;
}
- localdata->type = type;
localdata->np = NULL;
- break;
-
- default:
- parseError="nick: unsupported search type";
- free(localdata);
- return NULL;
}
if (!(thenode=(struct searchNode *)malloc(sizeof(struct searchNode)))) {
return NULL;
}
- if (type == SEARCHTYPE_CHANNEL)
+ if (ctx->searchcmd == reg_chansearch)
thenode->returntype = RETURNTYPE_BOOL;
else
thenode->returntype = RETURNTYPE_STRING;
return thenode;
}
-void *nick_exe(struct searchNode *thenode, void *theinput) {
+void *nick_exe(searchCtx *ctx, struct searchNode *thenode, void *theinput) {
struct nick_localdata *localdata;
nick *np;
chanindex *cip;
localdata = thenode->localdata;
- switch (localdata->type) {
- case SEARCHTYPE_CHANNEL:
+ if (ctx->searchcmd == reg_chansearch) {
cip = (chanindex *)theinput;
if (cip->channel==NULL || getnumerichandlefromchanhash(cip->channel->users, localdata->np->numeric)==NULL)
return (void *)0;
return (void *)1;
-
- default:
- case SEARCHTYPE_NICK:
+ } else {
np = (nick *)theinput;
return np->nick;
}
}
-void nick_free(struct searchNode *thenode) {
+void nick_free(searchCtx *ctx, struct searchNode *thenode) {
free(thenode->localdata);
free(thenode);
}