int do_nicksearch(void *source, int cargc, char **cargv);
int do_chansearch(void *source, int cargc, char **cargv);
-struct searchNode *search_parse(int type, char *input);
void printnick_channels(nick *, nick *);
void printchannel(nick *, chanindex *);
int arg=0;
struct Command *cmd;
NickDisplayFunc display=printnick;
-
+ searchCtx ctx;
+
if (cargc<1)
return CMD_USAGE;
if (arg<(cargc-1)) {
rejoinline(cargv[arg],cargc-arg);
}
-
- if (!(search = search_parse(SEARCHTYPE_NICK, cargv[arg]))) {
+
+ ctx.parser = search_parse;
+ ctx.reply = controlreply;
+
+ if (!(search = ctx.parser(&ctx, SEARCHTYPE_NICK, cargv[arg]))) {
controlreply(sender,"Parse error: %s",parseError);
return CMD_ERROR;
}
- nicksearch_exe(search, controlreply, sender, display, limit);
- (search->free)(search);
+ nicksearch_exe(search, &ctx, sender, display, limit);
+
+ (search->free)(&ctx, search);
return CMD_OK;
}
-void nicksearch_exe(struct searchNode *search, replyFunc reply, nick *sender, NickDisplayFunc display, int limit) {
+void nicksearch_exe(struct searchNode *search, searchCtx *ctx, nick *sender, NickDisplayFunc display, int limit) {
int i, j;
int matches = 0;
unsigned int cmarker;
cmarker=nextchanmarker();
/* The top-level node needs to return a BOOL */
- search=coerceNode(search, RETURNTYPE_BOOL);
+ search=coerceNode(ctx, search, RETURNTYPE_BOOL);
for (i=0;i<NICKHASHSIZE;i++) {
for (np=nicktable[i];np;np=np->next) {
- if ((search->exe)(search, np)) {
+ if ((search->exe)(ctx, search, np)) {
/* Add total channels */
tchans += np->channels->cursi;
display(sender, np);
if (matches==limit)
- reply(sender, "--- More than %d matches, skipping the rest",limit);
+ ctx->reply(sender, "--- More than %d matches, skipping the rest",limit);
matches++;
}
}
}
- reply(sender,"--- End of list: %d matches; users were on %u channels (%u unique, %.1f average clones)",
+ ctx->reply(sender,"--- End of list: %d matches; users were on %u channels (%u unique, %.1f average clones)",
matches, tchans, uchans, (float)tchans/uchans);
}
int arg=0;
struct Command *cmd;
ChanDisplayFunc display=printchannel;
+ searchCtx ctx;
if (cargc<1)
return CMD_USAGE;
rejoinline(cargv[arg],cargc-arg);
}
- if (!(search = search_parse(SEARCHTYPE_CHANNEL, cargv[arg]))) {
+ ctx.parser = search_parse;
+ ctx.reply = controlreply;
+
+ if (!(search = ctx.parser(&ctx, SEARCHTYPE_CHANNEL, cargv[arg]))) {
controlreply(sender,"Parse error: %s",parseError);
return CMD_ERROR;
}
- chansearch_exe(search, controlreply, sender, display, limit);
+ chansearch_exe(search, &ctx, sender, display, limit);
- (search->free)(search);
+ (search->free)(&ctx, search);
return CMD_OK;
}
-void chansearch_exe(struct searchNode *search, replyFunc reply, nick *sender, ChanDisplayFunc display, int limit) {
+void chansearch_exe(struct searchNode *search, searchCtx *ctx, nick *sender, ChanDisplayFunc display, int limit) {
int i;
chanindex *cip;
int matches = 0;
- search=coerceNode(search, RETURNTYPE_BOOL);
+ search=coerceNode(ctx, search, RETURNTYPE_BOOL);
for (i=0;i<CHANNELHASHSIZE;i++) {
for (cip=chantable[i];cip;cip=cip->next) {
- if ((search->exe)(search, cip)) {
+ if ((search->exe)(ctx, search, cip)) {
if (matches<limit)
display(sender, cip);
if (matches==limit)
- reply(sender, "--- More than %d matches, skipping the rest",limit);
+ ctx->reply(sender, "--- More than %d matches, skipping the rest",limit);
matches++;
}
}
}
- reply(sender,"--- End of list: %d matches", matches);
+ ctx->reply(sender,"--- End of list: %d matches", matches);
}
struct coercedata {
};
/* Free a coerce node */
-void free_coerce(struct searchNode *thenode) {
+void free_coerce(searchCtx *ctx, struct searchNode *thenode) {
struct coercedata *cd=thenode->localdata;
- cd->child->free(cd->child);
+ cd->child->free(ctx, cd->child);
free(thenode->localdata);
free(thenode);
}
/* Free a coerce node with a stringbuf allocated */
-void free_coercestring(struct searchNode *thenode) {
+void free_coercestring(searchCtx *ctx, struct searchNode *thenode) {
free(((struct coercedata *)thenode->localdata)->u.stringbuf);
- free_coerce(thenode);
+ free_coerce(ctx, thenode);
}
/* exe_tostr_null: return the constant string */
-void *exe_tostr_null(struct searchNode *thenode, void *theinput) {
+void *exe_tostr_null(searchCtx *ctx, struct searchNode *thenode, void *theinput) {
struct coercedata *cd=thenode->localdata;
return cd->u.stringbuf;
}
/* exe_val_null: return the constant value */
-void *exe_val_null(struct searchNode *thenode, void *theinput) {
+void *exe_val_null(searchCtx *ctx, struct searchNode *thenode, void *theinput) {
struct coercedata *cd=thenode->localdata;
return (void *)cd->u.val;
}
/* Lots of very dull type conversion functions */
-void *exe_inttostr(struct searchNode *thenode, void *theinput) {
+void *exe_inttostr(searchCtx *ctx, struct searchNode *thenode, void *theinput) {
struct coercedata *cd=thenode->localdata;
- sprintf(cd->u.stringbuf, "%lu", (unsigned long)(cd->child->exe)(cd->child, theinput));
+ sprintf(cd->u.stringbuf, "%lu", (unsigned long)(cd->child->exe)(ctx, cd->child, theinput));
return cd->u.stringbuf;
}
-void *exe_booltostr(struct searchNode *thenode, void *theinput) {
+void *exe_booltostr(searchCtx *ctx, struct searchNode *thenode, void *theinput) {
struct coercedata *cd=thenode->localdata;
- if ((cd->child->exe)(cd->child, theinput)) {
+ if ((cd->child->exe)(ctx, cd->child, theinput)) {
sprintf(cd->u.stringbuf,"1");
} else {
cd->u.stringbuf[0]='\0';
return cd->u.stringbuf;
}
-void *exe_strtoint(struct searchNode *thenode, void *theinput) {
+void *exe_strtoint(searchCtx *ctx, struct searchNode *thenode, void *theinput) {
struct coercedata *cd=thenode->localdata;
- return (void *)strtoul((cd->child->exe)(cd->child,theinput),NULL,10);
+ return (void *)strtoul((cd->child->exe)(ctx,cd->child,theinput),NULL,10);
}
-void *exe_booltoint(struct searchNode *thenode, void *theinput) {
+void *exe_booltoint(searchCtx *ctx, struct searchNode *thenode, void *theinput) {
struct coercedata *cd=thenode->localdata;
/* Don't need to do anything */
- return (cd->child->exe)(cd->child, theinput);
+ return (cd->child->exe)(ctx, cd->child, theinput);
}
-void *exe_strtobool(struct searchNode *thenode, void *theinput) {
+void *exe_strtobool(searchCtx *ctx, struct searchNode *thenode, void *theinput) {
struct coercedata *cd=thenode->localdata;
- char *ch=(cd->child->exe)(cd->child, theinput);
+ char *ch=(cd->child->exe)(ctx, cd->child, theinput);
if (!ch || *ch=='\0' || (*ch=='0' && ch[1]=='\0')) {
return (void *)0;
}
}
-void *exe_inttobool(struct searchNode *thenode, void *theinput) {
+void *exe_inttobool(searchCtx *ctx, struct searchNode *thenode, void *theinput) {
struct coercedata *cd=thenode->localdata;
- if ((cd->child->exe)(cd->child, theinput)) {
+ if ((cd->child->exe)(ctx, cd->child, theinput)) {
return (void *)1;
} else {
return (void *)0;
}
}
-struct searchNode *coerceNode(struct searchNode *thenode, int type) {
+struct searchNode *coerceNode(searchCtx *ctx, struct searchNode *thenode, int type) {
struct searchNode *anode;
struct coercedata *cd;
case RETURNTYPE_INT:
if (thenode->returntype & RETURNTYPE_CONST) {
/* Constant node: sort it out now */
- sprintf(cd->u.stringbuf, "%lu", (unsigned long)thenode->exe(thenode, NULL));
+ sprintf(cd->u.stringbuf, "%lu", (unsigned long)thenode->exe(ctx, thenode, NULL));
anode->exe=exe_tostr_null;
anode->returntype |= RETURNTYPE_CONST;
} else {
case RETURNTYPE_BOOL:
if (thenode->returntype & RETURNTYPE_CONST) {
/* Constant bool value */
- if (thenode->exe(thenode,NULL)) {
+ if (thenode->exe(ctx, thenode,NULL)) {
/* True! */
sprintf(cd->u.stringbuf, "1");
} else {
switch (thenode->returntype & RETURNTYPE_TYPE) {
case RETURNTYPE_STRING:
if (thenode->returntype & RETURNTYPE_CONST) {
- cd->u.val=strtoul((thenode->exe)(thenode, NULL), NULL, 10);
+ cd->u.val=strtoul((thenode->exe)(ctx, thenode, NULL), NULL, 10);
anode->exe=exe_val_null;
anode->returntype |= RETURNTYPE_CONST;
} else {
default:
case RETURNTYPE_BOOL:
if (thenode->returntype & RETURNTYPE_CONST) {
- if ((thenode->exe)(thenode,NULL))
+ if ((thenode->exe)(ctx, thenode,NULL))
cd->u.val=1;
else
cd->u.val=0;
switch (thenode->returntype & RETURNTYPE_TYPE) {
case RETURNTYPE_STRING:
if (thenode->returntype & RETURNTYPE_CONST) {
- char *rv=(char *)((thenode->exe)(thenode, NULL));
+ char *rv=(char *)((thenode->exe)(ctx, thenode, NULL));
if (!rv || *rv=='\0' || (*rv=='0' && rv[1]=='\0'))
cd->u.val=0;
else
default:
case RETURNTYPE_INT:
if (thenode->returntype & RETURNTYPE_CONST) {
- if ((thenode->exe)(thenode,NULL))
+ if ((thenode->exe)(ctx, thenode,NULL))
cd->u.val=1;
else
cd->u.val=0;
}
/* Literals always return constant strings... */
-void *literal_exe(struct searchNode *thenode, void *theinput) {
+void *literal_exe(searchCtx *ctx, struct searchNode *thenode, void *theinput) {
if (thenode->localdata)
return ((sstring *)thenode->localdata)->content;
else
return "";
}
-void literal_free(struct searchNode *thenode) {
+void literal_free(searchCtx *ctx, struct searchNode *thenode) {
freesstring(thenode->localdata);
free(thenode);
}
* Given an input string, return a searchNode.
*/
-struct searchNode *search_parse(int type, char *input) {
+struct searchNode *search_parse(searchCtx *ctx, int type, char *input) {
/* OK, we need to split the input into chunks on spaces and brackets.. */
char *argvector[100];
char thestring[500];
parseError = "Unknown command";
return NULL;
} else {
- return ((parseFunc)cmd->handler)(type, j, argvector+1);
+ return ((parseFunc)cmd->handler)(ctx, type, j, argvector+1);
}
} else {
/* Literal */
#define RETURNTYPE_CONST 0x100
struct searchNode;
+struct searchCtx;
-typedef struct searchNode *(*parseFunc)(int, int, char **);
-typedef void (*freeFunc)(struct searchNode *);
-typedef void *(*exeFunc)(struct searchNode *, void *);
+typedef struct searchNode *(*searchParseFunc)(struct searchCtx *ctx, int type, char *input);
+typedef void (*replyFunc)(nick *np, char *format, ...);
+
+typedef struct searchCtx {
+ searchParseFunc parser;
+ replyFunc reply;
+} searchCtx;
+
+typedef struct searchNode *(*parseFunc)(searchCtx *, int, int, char **);
+typedef void (*freeFunc)(searchCtx *, struct searchNode *);
+typedef void *(*exeFunc)(searchCtx *, struct searchNode *, void *);
typedef void (*ChanDisplayFunc)(nick *, chanindex *);
typedef void (*NickDisplayFunc)(nick *, nick *);
/* Core functions */
/* Logical (BOOL -> BOOL)*/
-struct searchNode *and_parse(int type, int argc, char **argv);
-struct searchNode *not_parse(int type, int argc, char **argv);
-struct searchNode *or_parse(int type, int argc, char **argv);
+struct searchNode *and_parse(searchCtx *ctx, int type, int argc, char **argv);
+struct searchNode *not_parse(searchCtx *ctx, int type, int argc, char **argv);
+struct searchNode *or_parse(searchCtx *ctx, int type, int argc, char **argv);
/* Comparison (INT -> BOOL) */
-struct searchNode *eq_parse(int type, int argc, char **argv);
-struct searchNode *lt_parse(int type, int argc, char **argv);
-struct searchNode *gt_parse(int type, int argc, char **argv);
+struct searchNode *eq_parse(searchCtx *ctx, int type, int argc, char **argv);
+struct searchNode *lt_parse(searchCtx *ctx, int type, int argc, char **argv);
+struct searchNode *gt_parse(searchCtx *ctx, int type, int argc, char **argv);
/* String match (STRING -> BOOL) */
-struct searchNode *match_parse(int type, int argc, char **argv);
-struct searchNode *regex_parse(int type, int argc, char **argv);
+struct searchNode *match_parse(searchCtx *ctx, int type, int argc, char **argv);
+struct searchNode *regex_parse(searchCtx *ctx, int type, int argc, char **argv);
/* Length (STRING -> INT) */
-struct searchNode *length_parse(int type, int argc, char **argv);
+struct searchNode *length_parse(searchCtx *ctx, int type, int argc, char **argv);
/* kill/gline actions (BOOL) */
-struct searchNode *kill_parse(int type, int argc, char **argv);
-struct searchNode *gline_parse(int type, int argc, char **argv);
+struct searchNode *kill_parse(searchCtx *ctx, int type, int argc, char **argv);
+struct searchNode *gline_parse(searchCtx *ctx, int type, int argc, char **argv);
/* notice action (BOOL) */
-struct searchNode *notice_parse(int type, int argc, char **argv);
+struct searchNode *notice_parse(searchCtx *ctx, int type, int argc, char **argv);
/* Nick/Channel functions (various types) */
-struct searchNode *nick_parse(int type, int argc, char **argv);
-struct searchNode *modes_parse(int type, int argc, char **argv);
+struct searchNode *nick_parse(searchCtx *ctx, int type, int argc, char **argv);
+struct searchNode *modes_parse(searchCtx *ctx, int type, int argc, char **argv);
/* Nick functions (various types) */
-struct searchNode *hostmask_parse(int type, int argc, char **argv);
-struct searchNode *realname_parse(int type, int argc, char **argv);
-struct searchNode *authname_parse(int type, int argc, char **argv);
-struct searchNode *authts_parse(int type, int argc, char **argv);
-struct searchNode *ident_parse(int type, int argc, char **argv);
-struct searchNode *host_parse(int type, int argc, char **argv);
-struct searchNode *channel_parse(int type, int argc, char **argv);
-struct searchNode *timestamp_parse(int type, int argc, char **argv);
-struct searchNode *country_parse(int type, int argc, char **argv);
-struct searchNode *ip_parse(int type, int argc, char **argv);
-struct searchNode *channels_parse(int type, int argc, char **argv);
-struct searchNode *server_parse(int type, int argc, char **argv);
-struct searchNode *authid_parse(int type, int argc, char **argv);
+struct searchNode *hostmask_parse(searchCtx *ctx, int type, int argc, char **argv);
+struct searchNode *realname_parse(searchCtx *ctx, int type, int argc, char **argv);
+struct searchNode *authname_parse(searchCtx *ctx, int type, int argc, char **argv);
+struct searchNode *authts_parse(searchCtx *ctx, int type, int argc, char **argv);
+struct searchNode *ident_parse(searchCtx *ctx, int type, int argc, char **argv);
+struct searchNode *host_parse(searchCtx *ctx, int type, int argc, char **argv);
+struct searchNode *channel_parse(searchCtx *ctx, int type, int argc, char **argv);
+struct searchNode *timestamp_parse(searchCtx *ctx, int type, int argc, char **argv);
+struct searchNode *country_parse(searchCtx *ctx, int type, int argc, char **argv);
+struct searchNode *ip_parse(searchCtx *ctx, int type, int argc, char **argv);
+struct searchNode *channels_parse(searchCtx *ctx, int type, int argc, char **argv);
+struct searchNode *server_parse(searchCtx *ctx, int type, int argc, char **argv);
+struct searchNode *authid_parse(searchCtx *ctx, int type, int argc, char **argv);
/* Channel functions (various types) */
-struct searchNode *exists_parse(int type, int argc, char **argv);
-struct searchNode *services_parse(int type, int argc, char **argv);
-struct searchNode *size_parse(int type, int argc, char **argv);
-struct searchNode *name_parse(int type, int argc, char **argv);
-struct searchNode *topic_parse(int type, int argc, char **argv);
-struct searchNode *oppct_parse(int type, int argc, char **argv);
-struct searchNode *hostpct_parse(int type, int argc, char **argv);
-struct searchNode *authedpct_parse(int type, int argc, char **argv);
-struct searchNode *kick_parse(int type, int argc, char **argv);
+struct searchNode *exists_parse(searchCtx *ctx, int type, int argc, char **argv);
+struct searchNode *services_parse(searchCtx *ctx, int type, int argc, char **argv);
+struct searchNode *size_parse(searchCtx *ctx, int type, int argc, char **argv);
+struct searchNode *name_parse(searchCtx *ctx, int type, int argc, char **argv);
+struct searchNode *topic_parse(searchCtx *ctx, int type, int argc, char **argv);
+struct searchNode *oppct_parse(searchCtx *ctx, int type, int argc, char **argv);
+struct searchNode *hostpct_parse(searchCtx *ctx, int type, int argc, char **argv);
+struct searchNode *authedpct_parse(searchCtx *ctx, int type, int argc, char **argv);
+struct searchNode *kick_parse(searchCtx *ctx, int type, int argc, char **argv);
/* Interpret a string to give a node */
-struct searchNode *search_parse(int type, char *input);
+struct searchNode *search_parse(searchCtx *ctx, int type, char *input);
/* Force a node to return the thing you want */
-struct searchNode *coerceNode(struct searchNode *thenode, int type);
+struct searchNode *coerceNode(searchCtx *ctx, struct searchNode *thenode, int type);
/* Registration functions */
void registersearchterm(char *term, parseFunc parsefunc);
void printnick(nick *, nick *);
-typedef void (*replyFunc)(nick *np, char *format, ...);
-void nicksearch_exe(struct searchNode *search, replyFunc reply, nick *sender, NickDisplayFunc display, int limit);
-void chansearch_exe(struct searchNode *search, replyFunc reply, nick *sender, ChanDisplayFunc display, int limit);
+void nicksearch_exe(struct searchNode *search, searchCtx *sctx, nick *sender, NickDisplayFunc display, int limit);
+void chansearch_exe(struct searchNode *search, searchCtx *sctx, nick *sender, ChanDisplayFunc display, int limit);
#include <stdio.h>
#include <stdlib.h>
-void and_free(struct searchNode *thenode);
-void *and_exe(struct searchNode *thenode, void *theinput);
+void and_free(searchCtx *ctx, struct searchNode *thenode);
+void *and_exe(searchCtx *ctx, struct searchNode *thenode, void *theinput);
struct and_localdata {
int count;
searchNode **nodes;
};
-struct searchNode *and_parse(int type, int argc, char **argv) {
+struct searchNode *and_parse(searchCtx *ctx, int type, int argc, char **argv) {
searchNode *thenode, *subnode;
struct and_localdata *localdata;
int i;
thenode->free = and_free;
for (i=0;i<argc;i++) {
- subnode=search_parse(type, argv[i]); /* Propogate the search type */
- subnode=coerceNode(subnode, RETURNTYPE_BOOL); /* Needs to return BOOL */
+ subnode=ctx->parser(ctx, type, argv[i]); /* Propogate the search type */
+ subnode=coerceNode(ctx, subnode, RETURNTYPE_BOOL); /* Needs to return BOOL */
if (subnode) {
localdata->nodes[localdata->count++] = subnode;
} else {
- and_free(thenode);
+ and_free(ctx, thenode); /* ?? */
return NULL;
}
}
return thenode;
}
-void and_free(struct searchNode *thenode) {
+void and_free(searchCtx *ctx, struct searchNode *thenode) {
struct and_localdata *localdata;
int i;
localdata=thenode->localdata;
for (i=0;i<localdata->count;i++) {
- (localdata->nodes[i]->free)(localdata->nodes[i]);
+ (localdata->nodes[i]->free)(ctx, localdata->nodes[i]);
}
free(localdata->nodes);
free(thenode);
}
-void *and_exe(struct searchNode *thenode, void *theinput) {
+void *and_exe(searchCtx *ctx, struct searchNode *thenode, void *theinput) {
int i;
struct and_localdata *localdata;
localdata=thenode->localdata;
for (i=0;i<localdata->count;i++) {
- if (!(localdata->nodes[i]->exe)(localdata->nodes[i], theinput))
+ if (!(localdata->nodes[i]->exe)(ctx, localdata->nodes[i], theinput))
return NULL;
}
return (void *)1;
#include <stdio.h>
#include <stdlib.h>
-void *authedpct_exe(struct searchNode *thenode, void *theinput);
-void authedpct_free(struct searchNode *thenode);
+void *authedpct_exe(searchCtx *ctx, struct searchNode *thenode, void *theinput);
+void authedpct_free(searchCtx *ctx, struct searchNode *thenode);
-struct searchNode *authedpct_parse(int type, int argc, char **argv) {
+struct searchNode *authedpct_parse(searchCtx *ctx, int type, int argc, char **argv) {
struct searchNode *thenode;
if (type != SEARCHTYPE_CHANNEL) {
return thenode;
}
-void *authedpct_exe(struct searchNode *thenode, void *theinput) {
+void *authedpct_exe(searchCtx *ctx, struct searchNode *thenode, void *theinput) {
int i;
int j=0;
nick *np;
return (void *)(long)((j * 100) / cip->channel->users->totalusers);
}
-void authedpct_free(struct searchNode *thenode) {
+void authedpct_free(searchCtx *ctx, struct searchNode *thenode) {
free(thenode);
}
#include <stdio.h>
#include <stdlib.h>
-void *authid_exe(struct searchNode *thenode, void *theinput);
-void authid_free(struct searchNode *thenode);
+void *authid_exe(searchCtx *ctx, struct searchNode *thenode, void *theinput);
+void authid_free(searchCtx *ctx, struct searchNode *thenode);
-struct searchNode *authid_parse(int type, int argc, char **argv) {
+struct searchNode *authid_parse(searchCtx *ctx, int type, int argc, char **argv) {
struct searchNode *thenode;
if (type != SEARCHTYPE_NICK) {
return thenode;
}
-void *authid_exe(struct searchNode *thenode, void *theinput) {
+void *authid_exe(searchCtx *ctx, struct searchNode *thenode, void *theinput) {
nick *np = (nick *)theinput;
if (IsAccount(np) && np->auth)
}
-void authid_free(struct searchNode *thenode) {
+void authid_free(searchCtx *ctx, struct searchNode *thenode) {
free(thenode);
}
#include <stdio.h>
#include <stdlib.h>
-void *authname_exe(struct searchNode *thenode, void *theinput);
-void authname_free(struct searchNode *thenode);
+void *authname_exe(searchCtx *ctx, struct searchNode *thenode, void *theinput);
+void authname_free(searchCtx *ctx, struct searchNode *thenode);
-struct searchNode *authname_parse(int type, int argc, char **argv) {
+struct searchNode *authname_parse(searchCtx *ctx, int type, int argc, char **argv) {
struct searchNode *thenode;
if (type != SEARCHTYPE_NICK) {
return thenode;
}
-void *authname_exe(struct searchNode *thenode, void *theinput) {
+void *authname_exe(searchCtx *ctx, struct searchNode *thenode, void *theinput) {
nick *np = (nick *)theinput;
if (IsAccount(np))
}
-void authname_free(struct searchNode *thenode) {
+void authname_free(searchCtx *ctx, struct searchNode *thenode) {
free(thenode);
}
#include <stdio.h>
#include <stdlib.h>
-void *authts_exe(struct searchNode *thenode, void *theinput);
-void authts_free(struct searchNode *thenode);
+void *authts_exe(searchCtx *ctx, struct searchNode *thenode, void *theinput);
+void authts_free(searchCtx *ctx, struct searchNode *thenode);
-struct searchNode *authts_parse(int type, int argc, char **argv) {
+struct searchNode *authts_parse(searchCtx *ctx, int type, int argc, char **argv) {
struct searchNode *thenode;
if (type != SEARCHTYPE_NICK) {
return thenode;
}
-void *authts_exe(struct searchNode *thenode, void *theinput) {
+void *authts_exe(searchCtx *ctx, struct searchNode *thenode, void *theinput) {
nick *np = (nick *)theinput;
if (IsAccount(np))
}
-void authts_free(struct searchNode *thenode) {
+void authts_free(searchCtx *ctx, struct searchNode *thenode) {
free(thenode);
}
#include "../channel/channel.h"
-void *channel_exe(struct searchNode *thenode, void *theinput);
-void channel_free(struct searchNode *thenode);
+void *channel_exe(searchCtx *ctx, struct searchNode *thenode, void *theinput);
+void channel_free(searchCtx *ctx, struct searchNode *thenode);
-struct searchNode *channel_parse(int type, int argc, char **argv) {
+struct searchNode *channel_parse(searchCtx *ctx, int type, int argc, char **argv) {
struct searchNode *thenode;
channel *cp;
return thenode;
}
-void *channel_exe(struct searchNode *thenode, void *theinput) {
+void *channel_exe(searchCtx *ctx, struct searchNode *thenode, void *theinput) {
nick *np = (nick *)theinput;
channel *cp = thenode->localdata;
}
}
-void channel_free(struct searchNode *thenode) {
+void channel_free(searchCtx *ctx, struct searchNode *thenode) {
free(thenode);
}
#include "../irc/irc_config.h"
#include "../lib/irc_string.h"
-void *channels_exe(struct searchNode *thenode, void *theinput);
-void channels_free(struct searchNode *thenode);
+void *channels_exe(searchCtx *ctx, struct searchNode *thenode, void *theinput);
+void channels_free(searchCtx *ctx, struct searchNode *thenode);
-struct searchNode *channels_parse(int type, int argc, char **argv) {
+struct searchNode *channels_parse(searchCtx *ctx, int type, int argc, char **argv) {
struct searchNode *thenode;
if (type != SEARCHTYPE_NICK) {
return thenode;
}
-void *channels_exe(struct searchNode *thenode, void *theinput) {
+void *channels_exe(searchCtx *ctx, struct searchNode *thenode, void *theinput) {
nick *np = (nick *)theinput;
return (void *)(long)np->channels->cursi;
}
-void channels_free(struct searchNode *thenode) {
+void channels_free(searchCtx *ctx, struct searchNode *thenode) {
free(thenode);
}
#include "../geoip/geoip.h"
#include "../core/modules.h"
-void *country_exe(struct searchNode *thenode, void *theinput);
-void country_free(struct searchNode *thenode);
+void *country_exe(searchCtx *ctx, struct searchNode *thenode, void *theinput);
+void country_free(searchCtx *ctx, struct searchNode *thenode);
int ext;
-struct searchNode *country_parse(int type, int argc, char **argv) {
+struct searchNode *country_parse(searchCtx *ctx, int type, int argc, char **argv) {
struct searchNode *thenode;
GeoIP_LookupCode l;
long target;
return thenode;
}
-void *country_exe(struct searchNode *thenode, void *theinput) {
+void *country_exe(searchCtx *ctx, struct searchNode *thenode, void *theinput) {
nick *np = (nick *)theinput;
long country = (long)thenode->localdata, rc = (long)np->exts[ext];
return (void *)0;
}
-void country_free(struct searchNode *thenode) {
+void country_free(searchCtx *ctx, struct searchNode *thenode) {
free(thenode);
}
struct searchNode **nodes;
};
-void eq_free(struct searchNode *thenode);
-void *eq_exe(struct searchNode *thenode, void *theinput);
+void eq_free(searchCtx *ctx, struct searchNode *thenode);
+void *eq_exe(searchCtx *ctx, struct searchNode *thenode, void *theinput);
-struct searchNode *eq_parse(int type, int argc, char **argv) {
+struct searchNode *eq_parse(searchCtx *ctx, int type, int argc, char **argv) {
struct eq_localdata *localdata;
struct searchNode *thenode;
int i;
for (i=0;i<argc;i++) {
/* Parse the node.. */
- localdata->nodes[i] = search_parse(type, argv[i]);
+ localdata->nodes[i] = ctx->parser(ctx, type, argv[i]);
/* Subsequent nodes get coerced to match the type of the first node */
if (i)
- localdata->nodes[i]=coerceNode(localdata->nodes[i],localdata->type);
+ localdata->nodes[i]=coerceNode(ctx,localdata->nodes[i],localdata->type);
/* If a node didn't parse, give up */
if (!localdata->nodes[i]) {
- eq_free(thenode);
+ eq_free(ctx, thenode);
return NULL;
}
return thenode;
}
-void eq_free(struct searchNode *thenode) {
+void eq_free(searchCtx *ctx, struct searchNode *thenode) {
struct eq_localdata *localdata;
int i;
for (i=0;i<localdata->count;i++) {
if (localdata->nodes[i])
- (localdata->nodes[i]->free)(localdata->nodes[i]);
+ (localdata->nodes[i]->free)(ctx, localdata->nodes[i]);
}
free(localdata->nodes);
free(thenode);
}
-void *eq_exe(struct searchNode *thenode, void *theinput) {
+void *eq_exe(searchCtx *ctx, struct searchNode *thenode, void *theinput) {
int i;
char *strval;
int intval;
switch (localdata->type) {
case RETURNTYPE_INT:
- intval = (int)((long)(localdata->nodes[0]->exe)(localdata->nodes[0], theinput));
+ intval = (int)((long)(localdata->nodes[0]->exe)(ctx, localdata->nodes[0], theinput));
for (i=1;i<localdata->count;i++) {
- if ((int)((long)(localdata->nodes[i]->exe)(localdata->nodes[i], theinput) != intval))
+ if ((int)((long)(localdata->nodes[i]->exe)(ctx, localdata->nodes[i], theinput) != intval))
return (void *)0;
}
return (void *)1;
case RETURNTYPE_BOOL:
- intval = (int)((long)(localdata->nodes[0]->exe)(localdata->nodes[0], theinput));
+ intval = (int)((long)(localdata->nodes[0]->exe)(ctx, localdata->nodes[0], theinput));
for (i=1;i<localdata->count;i++) {
- rval=(int)((long)(localdata->nodes[i]->exe)(localdata->nodes[i], theinput));
+ rval=(int)((long)(localdata->nodes[i]->exe)(ctx, localdata->nodes[i], theinput));
if ((rval && !intval) || (!rval && intval)) { /* LOGICAL XOR GOES HERE FS */
return (void *)0;
}
return (void *)1;
case RETURNTYPE_STRING:
- strval = (char *)(localdata->nodes[0]->exe)(localdata->nodes[0], theinput);
+ strval = (char *)(localdata->nodes[0]->exe)(ctx, localdata->nodes[0], theinput);
for (i=1;i<localdata->count;i++) {
- if (ircd_strcmp(strval, (char *)(localdata->nodes[i]->exe)(localdata->nodes[i], theinput)))
+ if (ircd_strcmp(strval, (char *)(localdata->nodes[i]->exe)(ctx, localdata->nodes[i], theinput)))
return (void *)0;
}
return (void *)1;
#include <stdio.h>
#include <stdlib.h>
-void *exists_exe(struct searchNode *thenode, void *theinput);
-void exists_free(struct searchNode *thenode);
+void *exists_exe(searchCtx *ctx, struct searchNode *thenode, void *theinput);
+void exists_free(searchCtx *ctx, struct searchNode *thenode);
-struct searchNode *exists_parse(int type, int argc, char **argv) {
+struct searchNode *exists_parse(searchCtx *ctx, int type, int argc, char **argv) {
struct searchNode *thenode;
if (type != SEARCHTYPE_CHANNEL) {
return thenode;
}
-void *exists_exe(struct searchNode *thenode, void *theinput) {
+void *exists_exe(searchCtx *ctx, struct searchNode *thenode, void *theinput) {
chanindex *cip = (chanindex *)theinput;
if (cip->channel == NULL)
return (void *)1;
}
-void exists_free(struct searchNode *thenode) {
+void exists_free(searchCtx *ctx, struct searchNode *thenode) {
free(thenode);
}
extern nick *senderNSExtern;
static const char *defaultreason = "You (%u) have been g-lined for violating our terms of service";
-void *gline_exe(struct searchNode *thenode, void *theinput);
-void gline_free(struct searchNode *thenode);
+void *gline_exe(searchCtx *ctx, struct searchNode *thenode, void *theinput);
+void gline_free(searchCtx *ctx, struct searchNode *thenode);
struct gline_localdata {
unsigned int marker;
char reason[NSMAX_REASON_LEN];
};
-struct searchNode *gline_parse(int type, int argc, char **argv) {
+struct searchNode *gline_parse(searchCtx *ctx, int type, int argc, char **argv) {
struct gline_localdata *localdata;
struct searchNode *thenode;
int len;
return thenode;
}
-void *gline_exe(struct searchNode *thenode, void *theinput) {
+void *gline_exe(searchCtx *ctx, struct searchNode *thenode, void *theinput) {
struct gline_localdata *localdata;
nick *np;
chanindex *cip;
return (void *)1;
}
-void gline_free(struct searchNode *thenode) {
+void gline_free(searchCtx *ctx, struct searchNode *thenode) {
struct gline_localdata *localdata;
nick *np, *nnp;
chanindex *cip, *ncip;
struct searchNode **nodes;
};
-void gt_free(struct searchNode *thenode);
-void *gt_exe(struct searchNode *thenode, void *theinput);
+void gt_free(searchCtx *ctx, struct searchNode *thenode);
+void *gt_exe(searchCtx *ctx, struct searchNode *thenode, void *theinput);
-struct searchNode *gt_parse(int type, int argc, char **argv) {
+struct searchNode *gt_parse(searchCtx *ctx, int type, int argc, char **argv) {
struct gt_localdata *localdata;
struct searchNode *thenode;
int i;
for (i=0;i<argc;i++) {
/* Parse the node.. */
- localdata->nodes[i] = search_parse(type, argv[i]);
+ localdata->nodes[i] = ctx->parser(ctx, type, argv[i]);
/* Subsequent nodes get coerced to match the type of the first node */
if (i)
- localdata->nodes[i]=coerceNode(localdata->nodes[i],localdata->type);
+ localdata->nodes[i]=coerceNode(ctx,localdata->nodes[i],localdata->type);
/* If a node didn't parse, give up */
if (!localdata->nodes[i]) {
- gt_free(thenode);
+ gt_free(ctx, thenode);
return NULL;
}
return thenode;
}
-void gt_free(struct searchNode *thenode) {
+void gt_free(searchCtx *ctx, struct searchNode *thenode) {
struct gt_localdata *localdata;
int i;
for (i=0;i<localdata->count;i++) {
if (localdata->nodes[i])
- (localdata->nodes[i]->free)(localdata->nodes[i]);
+ (localdata->nodes[i]->free)(ctx, localdata->nodes[i]);
}
free(localdata->nodes);
free(thenode);
}
-void *gt_exe(struct searchNode *thenode, void *theinput) {
+void *gt_exe(searchCtx *ctx, struct searchNode *thenode, void *theinput) {
int i;
char *strval;
int intval;
switch (localdata->type) {
case RETURNTYPE_INT:
case RETURNTYPE_BOOL:
- intval = (int)((long)(localdata->nodes[0]->exe)(localdata->nodes[0], theinput));
+ intval = (int)((long)(localdata->nodes[0]->exe)(ctx, localdata->nodes[0], theinput));
for (i=1;i<localdata->count;i++) {
- if ((int)((long)(localdata->nodes[i]->exe)(localdata->nodes[i], theinput) >= intval))
+ if ((int)((long)(localdata->nodes[i]->exe)(ctx, localdata->nodes[i], theinput) >= intval))
return (void *)0;
}
return (void *)1;
case RETURNTYPE_STRING:
- strval = (char *)(localdata->nodes[0]->exe)(localdata->nodes[0], theinput);
+ strval = (char *)(localdata->nodes[0]->exe)(ctx, localdata->nodes[0], theinput);
for (i=1;i<localdata->count;i++) {
- if (ircd_strcmp(strval, (char *)(localdata->nodes[i]->exe)(localdata->nodes[i], theinput)) <= 0)
+ if (ircd_strcmp(strval, (char *)(localdata->nodes[i]->exe)(ctx, localdata->nodes[i], theinput)) <= 0)
return (void *)0;
}
return (void *)1;
#include "../irc/irc_config.h"
#include "../lib/irc_string.h"
-void *host_exe(struct searchNode *thenode, void *theinput);
-void *host_exe_real(struct searchNode *thenode, void *theinput);
-void host_free(struct searchNode *thenode);
+void *host_exe(searchCtx *ctx, struct searchNode *thenode, void *theinput);
+void *host_exe_real(searchCtx *ctx, struct searchNode *thenode, void *theinput);
+void host_free(searchCtx *ctx, struct searchNode *thenode);
-struct searchNode *host_parse(int type, int argc, char **argv) {
+struct searchNode *host_parse(searchCtx *ctx, int type, int argc, char **argv) {
struct searchNode *thenode;
if (type != SEARCHTYPE_NICK) {
return thenode;
}
-void *host_exe(struct searchNode *thenode, void *theinput) {
+void *host_exe(searchCtx *ctx, struct searchNode *thenode, void *theinput) {
nick *np = (nick *)theinput;
char *buf = thenode->localdata;
}
}
-void *host_exe_real(struct searchNode *thenode, void *theinput) {
+void *host_exe_real(searchCtx *ctx, struct searchNode *thenode, void *theinput) {
nick *np = (nick *)theinput;
return np->host->name->content;
}
-void host_free(struct searchNode *thenode) {
+void host_free(searchCtx *ctx, struct searchNode *thenode) {
free(thenode->localdata);
free(thenode);
}
#include "../irc/irc_config.h"
#include "../lib/irc_string.h"
-void *hostmask_exe(struct searchNode *thenode, void *theinput);
-void *hostmask_exe_real(struct searchNode *thenode, void *theinput);
-void hostmask_free(struct searchNode *thenode);
+void *hostmask_exe(searchCtx *ctx, struct searchNode *thenode, void *theinput);
+void *hostmask_exe_real(searchCtx *ctx, struct searchNode *thenode, void *theinput);
+void hostmask_free(searchCtx *ctx, struct searchNode *thenode);
-struct searchNode *hostmask_parse(int type, int argc, char **argv) {
+struct searchNode *hostmask_parse(searchCtx *ctx, int type, int argc, char **argv) {
struct searchNode *thenode;
if (type != SEARCHTYPE_NICK) {
return thenode;
}
-void *hostmask_exe(struct searchNode *thenode, void *theinput) {
+void *hostmask_exe(searchCtx *ctx, struct searchNode *thenode, void *theinput) {
nick *np = (nick *)theinput;
char *buf = thenode->localdata;
return visiblehostmask(np, buf);
}
-void *hostmask_exe_real(struct searchNode *thenode, void *theinput) {
+void *hostmask_exe_real(searchCtx *ctx, struct searchNode *thenode, void *theinput) {
nick *np = (nick *)theinput;
char *buf = thenode->localdata;
return buf;
}
-void hostmask_free(struct searchNode *thenode) {
+void hostmask_free(searchCtx *ctx, struct searchNode *thenode) {
free(thenode->localdata);
free(thenode);
}
#include <stdio.h>
#include <stdlib.h>
-void *hostpct_exe(struct searchNode *thenode, void *theinput);
-void hostpct_free(struct searchNode *thenode);
+void *hostpct_exe(searchCtx *ctx, struct searchNode *thenode, void *theinput);
+void hostpct_free(searchCtx *ctx, struct searchNode *thenode);
-struct searchNode *hostpct_parse(int type, int argc, char **argv) {
+struct searchNode *hostpct_parse(searchCtx *ctx, int type, int argc, char **argv) {
struct searchNode *thenode;
if (type != SEARCHTYPE_CHANNEL) {
return thenode;
}
-void *hostpct_exe(struct searchNode *thenode, void *theinput) {
+void *hostpct_exe(searchCtx *ctx, struct searchNode *thenode, void *theinput) {
int i;
unsigned int marker;
unsigned int hosts=0;
return (void *)(long)((hosts * 100)/cip->channel->users->totalusers);
}
-void hostpct_free(struct searchNode *thenode) {
+void hostpct_free(searchCtx *ctx, struct searchNode *thenode) {
free(thenode);
}
#include <stdio.h>
#include <stdlib.h>
-void *ident_exe(struct searchNode *thenode, void *theinput);
-void ident_free(struct searchNode *thenode);
+void *ident_exe(searchCtx *ctx, struct searchNode *thenode, void *theinput);
+void ident_free(searchCtx *ctx, struct searchNode *thenode);
-struct searchNode *ident_parse(int type, int argc, char **argv) {
+struct searchNode *ident_parse(searchCtx *ctx, int type, int argc, char **argv) {
struct searchNode *thenode;
if (type != SEARCHTYPE_NICK) {
return thenode;
}
-void *ident_exe(struct searchNode *thenode, void *theinput) {
+void *ident_exe(searchCtx *ctx, struct searchNode *thenode, void *theinput) {
nick *np = (nick *)theinput;
return np->ident;
}
-void ident_free(struct searchNode *thenode) {
+void ident_free(searchCtx *ctx, struct searchNode *thenode) {
free(thenode);
}
#include <stdio.h>
#include <stdlib.h>
-void *ip_exe(struct searchNode *thenode, void *theinput);
-void ip_free(struct searchNode *thenode);
+void *ip_exe(searchCtx *ctx, struct searchNode *thenode, void *theinput);
+void ip_free(searchCtx *ctx, struct searchNode *thenode);
-struct searchNode *ip_parse(int type, int argc, char **argv) {
+struct searchNode *ip_parse(searchCtx *ctx, int type, int argc, char **argv) {
struct searchNode *thenode;
if (type != SEARCHTYPE_NICK) {
return thenode;
}
-void *ip_exe(struct searchNode *thenode, void *theinput) {
+void *ip_exe(searchCtx *ctx, struct searchNode *thenode, void *theinput) {
nick *np = (nick *)theinput;
return (void *)IPtostr(np->p_ipaddr);
}
-void ip_free(struct searchNode *thenode) {
+void ip_free(searchCtx *ctx, struct searchNode *thenode) {
free(thenode);
}
#include <stdio.h>
#include <stdlib.h>
-void *kick_exe(struct searchNode *thenode, void *theinput);
-void kick_free(struct searchNode *thenode);
+void *kick_exe(searchCtx *ctx, struct searchNode *thenode, void *theinput);
+void kick_free(searchCtx *ctx, struct searchNode *thenode);
-struct searchNode *kick_parse(int type, int argc, char **argv) {
+struct searchNode *kick_parse(searchCtx *ctx, int type, int argc, char **argv) {
struct searchNode *thenode;
nick *np;
return thenode;
}
-void *kick_exe(struct searchNode *thenode, void *theinput) {
+void *kick_exe(searchCtx *ctx, struct searchNode *thenode, void *theinput) {
nick *np;
chanindex *cip;
return (void *)1;
}
-void kick_free(struct searchNode *thenode) {
+void kick_free(searchCtx *ctx, struct searchNode *thenode) {
free(thenode);
}
i.e. hitting too many users in a (kill) or (gline) - declared in newsearch.c */
extern nick *senderNSExtern;
-void *kill_exe(struct searchNode *thenode, void *theinput);
-void kill_free(struct searchNode *thenode);
+void *kill_exe(searchCtx *ctx, struct searchNode *thenode, void *theinput);
+void kill_free(searchCtx *ctx, struct searchNode *thenode);
static const char *defaultreason = "You (%n) have been disconnected for violating our terms of service";
struct kill_localdata {
char reason[NSMAX_REASON_LEN];
};
-struct searchNode *kill_parse(int type, int argc, char **argv) {
+struct searchNode *kill_parse(searchCtx *ctx, int type, int argc, char **argv) {
struct kill_localdata *localdata;
struct searchNode *thenode;
int len;
return thenode;
}
-void *kill_exe(struct searchNode *thenode, void *theinput) {
+void *kill_exe(searchCtx *ctx, struct searchNode *thenode, void *theinput) {
struct kill_localdata *localdata;
nick *np;
chanindex *cip;
return (void *)1;
}
-void kill_free(struct searchNode *thenode) {
+void kill_free(searchCtx *ctx, struct searchNode *thenode) {
struct kill_localdata *localdata;
nick *np, *nnp;
chanindex *cip;
#include <stdlib.h>
#include <string.h>
-void length_free(struct searchNode *thenode);
-void *length_exe(struct searchNode *thenode, void *theinput);
+void length_free(searchCtx *ctx, struct searchNode *thenode);
+void *length_exe(searchCtx *ctx, struct searchNode *thenode, void *theinput);
-struct searchNode *length_parse(int type, int argc, char **argv) {
+struct searchNode *length_parse(searchCtx *ctx, int type, int argc, char **argv) {
struct searchNode *thenode, *childnode;
if (!(thenode = (struct searchNode *)malloc(sizeof(struct searchNode)))) {
return NULL;
}
- childnode = search_parse(type, argv[0]);
- if (!(thenode->localdata = coerceNode(childnode, RETURNTYPE_STRING))) {
- length_free(thenode);
+ childnode = ctx->parser(ctx, type, argv[0]);
+ if (!(thenode->localdata = coerceNode(ctx, childnode, RETURNTYPE_STRING))) {
+ length_free(ctx, thenode);
return NULL;
}
return thenode;
}
-void length_free(struct searchNode *thenode) {
+void length_free(searchCtx *ctx, struct searchNode *thenode) {
struct searchNode *anode;
if ((anode=thenode->localdata))
- (anode->free)(anode);
+ (anode->free)(ctx, anode);
free(thenode);
}
-void *length_exe(struct searchNode *thenode, void *theinput) {
+void *length_exe(searchCtx *ctx, struct searchNode *thenode, void *theinput) {
char *strval;
struct searchNode *anode=thenode->localdata;
- strval=(char *)(anode->exe)(anode, theinput);
+ strval=(char *)(anode->exe)(ctx, anode, theinput);
return (void *)strlen(strval);
}
struct searchNode **nodes;
};
-void lt_free(struct searchNode *thenode);
-void *lt_exe(struct searchNode *thenode, void *theinput);
+void lt_free(searchCtx *ctx, struct searchNode *thenode);
+void *lt_exe(searchCtx *ctx, struct searchNode *thenode, void *theinput);
-struct searchNode *lt_parse(int type, int argc, char **argv) {
+struct searchNode *lt_parse(searchCtx *ctx, int type, int argc, char **argv) {
struct lt_localdata *localdata;
struct searchNode *thenode;
int i;
for (i=0;i<argc;i++) {
/* Parse the node.. */
- localdata->nodes[i] = search_parse(type, argv[i]);
+ localdata->nodes[i] = ctx->parser(ctx, type, argv[i]);
/* Subsequent nodes get coerced to match the type of the first node */
if (i)
- localdata->nodes[i]=coerceNode(localdata->nodes[i],localdata->type);
+ localdata->nodes[i]=coerceNode(ctx, localdata->nodes[i],localdata->type);
/* If a node didn't parse, give up */
if (!localdata->nodes[i]) {
- lt_free(thenode);
+ lt_free(ctx, thenode);
return NULL;
}
return thenode;
}
-void lt_free(struct searchNode *thenode) {
+void lt_free(searchCtx *ctx, struct searchNode *thenode) {
struct lt_localdata *localdata;
int i;
for (i=0;i<localdata->count;i++) {
if (localdata->nodes[i])
- (localdata->nodes[i]->free)(localdata->nodes[i]);
+ (localdata->nodes[i]->free)(ctx, localdata->nodes[i]);
}
free(localdata->nodes);
free(thenode);
}
-void *lt_exe(struct searchNode *thenode, void *theinput) {
+void *lt_exe(searchCtx *ctx, struct searchNode *thenode, void *theinput) {
int i;
char *strval;
int intval;
switch (localdata->type) {
case RETURNTYPE_INT:
case RETURNTYPE_BOOL:
- intval = (int)((long)(localdata->nodes[0]->exe)(localdata->nodes[0], theinput));
+ intval = (int)((long)(localdata->nodes[0]->exe)(ctx, localdata->nodes[0], theinput));
for (i=1;i<localdata->count;i++) {
- if ((int)((long)(localdata->nodes[i]->exe)(localdata->nodes[i], theinput) <= intval))
+ if ((int)((long)(localdata->nodes[i]->exe)(ctx, localdata->nodes[i], theinput) <= intval))
return (void *)0;
}
return (void *)1;
case RETURNTYPE_STRING:
- strval = (char *)(localdata->nodes[0]->exe)(localdata->nodes[0], theinput);
+ strval = (char *)(localdata->nodes[0]->exe)(ctx, localdata->nodes[0], theinput);
for (i=1;i<localdata->count;i++) {
- if (ircd_strcmp(strval, (char *)(localdata->nodes[i]->exe)(localdata->nodes[i], theinput)) >= 0)
+ if (ircd_strcmp(strval, (char *)(localdata->nodes[i]->exe)(ctx, localdata->nodes[i], theinput)) >= 0)
return (void *)0;
}
return (void *)1;
struct searchNode *patnode;
};
-void *match_exe(struct searchNode *thenode, void *theinput);
-void match_free(struct searchNode *thenode);
+void *match_exe(searchCtx *ctx, struct searchNode *thenode, void *theinput);
+void match_free(searchCtx *ctx, struct searchNode *thenode);
-struct searchNode *match_parse(int type, int argc, char **argv) {
+struct searchNode *match_parse(searchCtx *ctx, int type, int argc, char **argv) {
struct match_localdata *localdata;
struct searchNode *thenode;
struct searchNode *targnode, *patnode;
return NULL;
}
- targnode = search_parse(type, argv[0]);
- if (!(targnode = coerceNode(targnode, RETURNTYPE_STRING)))
+ /* @fixme check this works with new parsing semantics */
+ targnode = ctx->parser(ctx, type, argv[0]);
+ if (!(targnode = coerceNode(ctx,targnode, RETURNTYPE_STRING)))
return NULL;
- patnode = search_parse(type, argv[1]);
- if (!(patnode = coerceNode(patnode, RETURNTYPE_STRING))) {
- (targnode->free)(targnode);
+ patnode = ctx->parser(ctx, type, argv[1]);
+ if (!(patnode = coerceNode(ctx,patnode, RETURNTYPE_STRING))) {
+ (targnode->free)(ctx, targnode);
return NULL;
}
return thenode;
}
-void *match_exe(struct searchNode *thenode, void *theinput) {
+void *match_exe(searchCtx *ctx, struct searchNode *thenode, void *theinput) {
struct match_localdata *localdata;
char *pattern, *target;
localdata = thenode->localdata;
- pattern = (char *)(localdata->patnode->exe) (localdata->patnode, theinput);
- target = (char *)(localdata->targnode->exe)(localdata->targnode,theinput);
+ pattern = (char *)(localdata->patnode->exe) (ctx, localdata->patnode, theinput);
+ target = (char *)(localdata->targnode->exe)(ctx, localdata->targnode,theinput);
return (void *)(long)match2strings(pattern, target);
}
-void match_free(struct searchNode *thenode) {
+void match_free(searchCtx *ctx, struct searchNode *thenode) {
struct match_localdata *localdata;
localdata=thenode->localdata;
- (localdata->patnode->free)(localdata->patnode);
- (localdata->targnode->free)(localdata->targnode);
+ (localdata->patnode->free)(ctx, localdata->patnode);
+ (localdata->targnode->free)(ctx, localdata->targnode);
free(localdata);
free(thenode);
}
flag_t clearmodes;
};
-void *modes_exe(struct searchNode *thenode, void *theinput);
-void modes_free(struct searchNode *thenode);
+void *modes_exe(searchCtx *ctx, struct searchNode *thenode, void *theinput);
+void modes_free(searchCtx *ctx, struct searchNode *thenode);
-struct searchNode *modes_parse(int type, int argc, char **argv) {
+struct searchNode *modes_parse(searchCtx *ctx, int type, int argc, char **argv) {
struct modes_localdata *localdata;
struct searchNode *thenode;
const flag *flaglist;
return thenode;
}
-void *modes_exe(struct searchNode *thenode, void *value) {
+void *modes_exe(searchCtx *ctx, struct searchNode *thenode, void *value) {
struct modes_localdata *localdata;
nick *np;
chanindex *cip;
return (void *)1;
}
-void modes_free(struct searchNode *thenode) {
+void modes_free(searchCtx *ctx, struct searchNode *thenode) {
free (thenode->localdata);
free (thenode);
}
#include <stdio.h>
#include <stdlib.h>
-void *name_exe(struct searchNode *thenode, void *theinput);
-void name_free(struct searchNode *thenode);
+void *name_exe(searchCtx *ctx, struct searchNode *thenode, void *theinput);
+void name_free(searchCtx *ctx, struct searchNode *thenode);
-struct searchNode *name_parse(int type, int argc, char **argv) {
+struct searchNode *name_parse(searchCtx *ctx, int type, int argc, char **argv) {
struct searchNode *thenode;
if (type != SEARCHTYPE_CHANNEL) {
return thenode;
}
-void *name_exe(struct searchNode *thenode, void *theinput) {
+void *name_exe(searchCtx *ctx, struct searchNode *thenode, void *theinput) {
chanindex *cip = (chanindex *)theinput;
return cip->name->content;
}
-void name_free(struct searchNode *thenode) {
+void name_free(searchCtx *ctx, struct searchNode *thenode) {
free(thenode);
}
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 type, int argc, char **argv) {
struct nick_localdata *localdata;
struct searchNode *thenode;
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;
}
}
-void nick_free(struct searchNode *thenode) {
+void nick_free(searchCtx *ctx, struct searchNode *thenode) {
free(thenode->localdata);
free(thenode);
}
#include <stdio.h>
#include <stdlib.h>
-void not_free(struct searchNode *thenode);
-void *not_exe(struct searchNode *thenode, void *theinput);
+void not_free(searchCtx *ctx, struct searchNode *thenode);
+void *not_exe(searchCtx *ctx, struct searchNode *thenode, void *theinput);
-struct searchNode *not_parse(int type, int argc, char **argv) {
+struct searchNode *not_parse(searchCtx *ctx, int type, int argc, char **argv) {
searchNode *thenode, *subnode;
if (argc!=1) {
thenode->exe = not_exe;
thenode->free = not_free;
- subnode=search_parse(type, argv[0]); /* Propogate the search type */
+ subnode=ctx->parser(ctx, type, argv[0]); /* Propogate the search type */
if (!subnode) {
free(thenode);
}
/* Our subnode needs to return a BOOL */
- subnode=coerceNode(subnode, RETURNTYPE_BOOL);
+ subnode=coerceNode(ctx, subnode, RETURNTYPE_BOOL);
thenode->localdata=(void *)subnode;
return thenode;
}
-void not_free(struct searchNode *thenode) {
+void not_free(searchCtx *ctx, struct searchNode *thenode) {
struct searchNode *subnode;
subnode=thenode->localdata;
- (subnode->free)(subnode);
+ (subnode->free)(ctx, subnode);
free(thenode);
}
-void *not_exe(struct searchNode *thenode, void *theinput) {
+void *not_exe(searchCtx *ctx, struct searchNode *thenode, void *theinput) {
struct searchNode *subnode;
subnode=thenode->localdata;
- if ((subnode->exe)(subnode, theinput)) {
+ if ((subnode->exe)(ctx, subnode, theinput)) {
return (void *)0;
} else {
return (void *)1;
extern nick *senderNSExtern;
-void *notice_exe(struct searchNode *thenode, void *theinput);
-void notice_free(struct searchNode *thenode);
+void *notice_exe(searchCtx *ctx, struct searchNode *thenode, void *theinput);
+void notice_free(searchCtx *ctx, struct searchNode *thenode);
struct notice_localdata {
unsigned int marker;
char message[NSMAX_NOTICE_LEN];
};
-struct searchNode *notice_parse(int type, int argc, char **argv) {
+struct searchNode *notice_parse(searchCtx *ctx, int type, int argc, char **argv) {
struct notice_localdata *localdata;
struct searchNode *thenode;
int len;
return thenode;
}
-void *notice_exe(struct searchNode *thenode, void *theinput) {
+void *notice_exe(searchCtx *ctx, struct searchNode *thenode, void *theinput) {
struct notice_localdata *localdata;
nick *np;
chanindex *cip;
return (void *)1;
}
-void notice_free(struct searchNode *thenode) {
+void notice_free(searchCtx *ctx, struct searchNode *thenode) {
struct notice_localdata *localdata;
nick *np, *nnp;
chanindex *cip, *ncip;
#include <stdio.h>
#include <stdlib.h>
-void *oppct_exe(struct searchNode *thenode, void *theinput);
-void oppct_free(struct searchNode *thenode);
+void *oppct_exe(searchCtx *ctx, struct searchNode *thenode, void *theinput);
+void oppct_free(searchCtx *ctx, struct searchNode *thenode);
-struct searchNode *oppct_parse(int type, int argc, char **argv) {
+struct searchNode *oppct_parse(searchCtx *ctx, int type, int argc, char **argv) {
struct searchNode *thenode;
if (type != SEARCHTYPE_CHANNEL) {
return thenode;
}
-void *oppct_exe(struct searchNode *thenode, void *theinput) {
+void *oppct_exe(searchCtx *ctx, struct searchNode *thenode, void *theinput) {
int i;
int ops;
chanindex *cip = (chanindex *)theinput;
return (void *)(long)((ops * 100) / cip->channel->users->totalusers);
}
-void oppct_free(struct searchNode *thenode) {
+void oppct_free(searchCtx *ctx, struct searchNode *thenode) {
free(thenode);
}
#include <stdio.h>
#include <stdlib.h>
-void or_free(struct searchNode *thenode);
-void *or_exe(struct searchNode *thenode, void *theinput);
+void or_free(searchCtx *ctx, struct searchNode *thenode);
+void *or_exe(searchCtx *ctx, struct searchNode *thenode, void *theinput);
struct or_localdata {
int count;
searchNode **nodes;
};
-struct searchNode *or_parse(int type, int argc, char **argv) {
+struct searchNode *or_parse(searchCtx *ctx, int type, int argc, char **argv) {
searchNode *thenode, *subnode;
struct or_localdata *localdata;
int i;
thenode->free = or_free;
for (i=0;i<argc;i++) {
- subnode=search_parse(type, argv[i]); /* Propogate the search type */
- subnode=coerceNode(subnode, RETURNTYPE_BOOL); /* BOOL please */
+ subnode=ctx->parser(ctx, type, argv[i]); /* Propogate the search type */
+ subnode=coerceNode(ctx, subnode, RETURNTYPE_BOOL); /* BOOL please */
if (subnode) {
localdata->nodes[localdata->count++] = subnode;
} else {
- or_free(thenode);
+ or_free(ctx, thenode);
return NULL;
}
}
return thenode;
}
-void or_free(struct searchNode *thenode) {
+void or_free(searchCtx *ctx, struct searchNode *thenode) {
struct or_localdata *localdata;
int i;
localdata=thenode->localdata;
for (i=0;i<localdata->count;i++) {
- (localdata->nodes[i]->free)(localdata->nodes[i]);
+ (localdata->nodes[i]->free)(ctx, localdata->nodes[i]);
}
free(localdata->nodes);
free(thenode);
}
-void *or_exe(struct searchNode *thenode, void *theinput) {
+void *or_exe(searchCtx *ctx, struct searchNode *thenode, void *theinput) {
int i;
struct or_localdata *localdata;
localdata=thenode->localdata;
for (i=0;i<localdata->count;i++) {
- if ((localdata->nodes[i]->exe)(localdata->nodes[i], theinput))
+ if ((localdata->nodes[i]->exe)(ctx, localdata->nodes[i], theinput))
return (void *)1;
}
#include <stdio.h>
#include <stdlib.h>
-void *realname_exe(struct searchNode *thenode, void *theinput);
-void realname_free(struct searchNode *thenode);
+void *realname_exe(searchCtx *ctx, struct searchNode *thenode, void *theinput);
+void realname_free(searchCtx *ctx, struct searchNode *thenode);
-struct searchNode *realname_parse(int type, int argc, char **argv) {
+struct searchNode *realname_parse(searchCtx *ctx, int type, int argc, char **argv) {
struct searchNode *thenode;
if (type != SEARCHTYPE_NICK) {
return thenode;
}
-void *realname_exe(struct searchNode *thenode, void *theinput) {
+void *realname_exe(searchCtx *ctx, struct searchNode *thenode, void *theinput) {
nick *np = (nick *)theinput;
return np->realname->name->content;
}
-void realname_free(struct searchNode *thenode) {
+void realname_free(searchCtx *ctx, struct searchNode *thenode) {
free(thenode);
}
pcre_extra *pcre_extra;
};
-void *regex_exe(struct searchNode *thenode, void *theinput);
-void regex_free(struct searchNode *thenode);
+void *regex_exe(searchCtx *ctx, struct searchNode *thenode, void *theinput);
+void regex_free(searchCtx *ctx, struct searchNode *thenode);
-struct searchNode *regex_parse(int type, int argc, char **argv) {
+struct searchNode *regex_parse(searchCtx *ctx, int type, int argc, char **argv) {
struct regex_localdata *localdata;
struct searchNode *thenode;
struct searchNode *targnode, *patnode;
return NULL;
}
- targnode=search_parse(type, argv[0]);
- if (!(targnode = coerceNode(targnode, RETURNTYPE_STRING)))
+ targnode=ctx->parser(ctx, type, argv[0]);
+ if (!(targnode = coerceNode(ctx,targnode, RETURNTYPE_STRING)))
return NULL;
- patnode=search_parse(type, argv[1]);
- if (!(patnode = coerceNode(patnode, RETURNTYPE_STRING))) {
- (targnode->free)(targnode);
+ patnode=ctx->parser(ctx, type, argv[1]);
+ if (!(patnode = coerceNode(ctx,patnode, RETURNTYPE_STRING))) {
+ (targnode->free)(ctx, targnode);
return NULL;
}
if (!(patnode->returntype & RETURNTYPE_CONST)) {
parseError="regex: only constant regexes allowed";
- (targnode->free)(targnode);
- (patnode->free)(patnode);
+ (targnode->free)(ctx, targnode);
+ (patnode->free)(ctx, patnode);
return NULL;
}
- if (!(pcre=pcre_compile((char *)(patnode->exe)(patnode,NULL),
+ if (!(pcre=pcre_compile((char *)(patnode->exe)(ctx, patnode,NULL),
PCRE_CASELESS, &err, &erroffset, NULL))) {
parseError=err;
return NULL;
return thenode;
}
-void *regex_exe(struct searchNode *thenode, void *theinput) {
+void *regex_exe(searchCtx *ctx, struct searchNode *thenode, void *theinput) {
struct regex_localdata *localdata;
char *target;
localdata = thenode->localdata;
- target = (char *)((localdata->targnode->exe)(localdata->targnode,theinput));
+ target = (char *)((localdata->targnode->exe)(ctx, localdata->targnode,theinput));
if (pcre_exec(localdata->pcre, localdata->pcre_extra,target,strlen(target),0,
0,NULL,0)) {
}
}
-void regex_free(struct searchNode *thenode) {
+void regex_free(searchCtx *ctx, struct searchNode *thenode) {
struct regex_localdata *localdata;
localdata=thenode->localdata;
if (localdata->pcre)
pcre_free(localdata->pcre);
- (localdata->patnode->free)(localdata->patnode);
- (localdata->targnode->free)(localdata->targnode);
+ (localdata->patnode->free)(ctx, localdata->patnode);
+ (localdata->targnode->free)(ctx, localdata->targnode);
free(localdata);
free(thenode);
}
#include "../core/modules.h"
#include "../server/server.h"
-void *server_exe_bool(struct searchNode *thenode, void *theinput);
-void *server_exe_str(struct searchNode *thenode, void *theinput);
-void server_free(struct searchNode *thenode);
+void *server_exe_bool(searchCtx *ctx, struct searchNode *thenode, void *theinput);
+void *server_exe_str(searchCtx *ctx, struct searchNode *thenode, void *theinput);
+void server_free(searchCtx *ctx, struct searchNode *thenode);
int ext;
-struct searchNode *server_parse(int type, int argc, char **argv) {
+struct searchNode *server_parse(searchCtx *ctx, int type, int argc, char **argv) {
struct searchNode *thenode;
int i;
long numeric;
return thenode;
}
-void *server_exe_bool(struct searchNode *thenode, void *theinput) {
+void *server_exe_bool(searchCtx *ctx, struct searchNode *thenode, void *theinput) {
nick *np = (nick *)theinput;
long server = (long)thenode->localdata;
return (void *)0;
}
-void *server_exe_str(struct searchNode *thenode, void *theinput) {
+void *server_exe_str(searchCtx *ctx, struct searchNode *thenode, void *theinput) {
nick *np = (nick *)theinput;
sstring *n = serverlist[homeserver(np->numeric)].name;
return n->content;
}
-void server_free(struct searchNode *thenode) {
+void server_free(searchCtx *ctx, struct searchNode *thenode) {
free(thenode);
}
#include <stdio.h>
#include <stdlib.h>
-void *services_exe(struct searchNode *thenode, void *theinput);
-void services_free(struct searchNode *thenode);
+void *services_exe(searchCtx *ctx, struct searchNode *thenode, void *theinput);
+void services_free(searchCtx *ctx, struct searchNode *thenode);
-struct searchNode *services_parse(int type, int argc, char **argv) {
+struct searchNode *services_parse(searchCtx *ctx, int type, int argc, char **argv) {
struct searchNode *thenode;
if (type != SEARCHTYPE_CHANNEL) {
return thenode;
}
-void *services_exe(struct searchNode *thenode, void *theinput) {
+void *services_exe(searchCtx *ctx, struct searchNode *thenode, void *theinput) {
chanindex *cip = (chanindex *)theinput;
nick *np;
int i;
return (void *)count;
}
-void services_free(struct searchNode *thenode) {
+void services_free(searchCtx *ctx, struct searchNode *thenode) {
free(thenode);
}
#include <stdio.h>
#include <stdlib.h>
-void *size_exe(struct searchNode *thenode, void *theinput);
-void size_free(struct searchNode *thenode);
+void *size_exe(searchCtx *ctx, struct searchNode *thenode, void *theinput);
+void size_free(searchCtx *ctx, struct searchNode *thenode);
-struct searchNode *size_parse(int type, int argc, char **argv) {
+struct searchNode *size_parse(searchCtx *ctx, int type, int argc, char **argv) {
struct searchNode *thenode;
if (type != SEARCHTYPE_CHANNEL) {
return thenode;
}
-void *size_exe(struct searchNode *thenode, void *theinput) {
+void *size_exe(searchCtx *ctx, struct searchNode *thenode, void *theinput) {
chanindex *cip = (chanindex *)theinput;
if (cip->channel==NULL)
return (void *)((unsigned long)cip->channel->users->totalusers);
}
-void size_free(struct searchNode *thenode) {
+void size_free(searchCtx *ctx, struct searchNode *thenode) {
free(thenode);
}
#include "../irc/irc_config.h"
#include "../lib/irc_string.h"
-void *timestamp_exe(struct searchNode *thenode, void *theinput);
-void timestamp_free(struct searchNode *thenode);
+void *timestamp_exe(searchCtx *ctx, struct searchNode *thenode, void *theinput);
+void timestamp_free(searchCtx *ctx, struct searchNode *thenode);
-struct searchNode *timestamp_parse(int type, int argc, char **argv) {
+struct searchNode *timestamp_parse(searchCtx *ctx, int type, int argc, char **argv) {
struct searchNode *thenode;
if (type != SEARCHTYPE_NICK) {
return thenode;
}
-void *timestamp_exe(struct searchNode *thenode, void *theinput) {
+void *timestamp_exe(searchCtx *ctx, struct searchNode *thenode, void *theinput) {
nick *np = (nick *)theinput;
return (void *)np->timestamp;
}
-void timestamp_free(struct searchNode *thenode) {
+void timestamp_free(searchCtx *ctx, struct searchNode *thenode) {
free(thenode);
}
#include <stdio.h>
#include <stdlib.h>
-void *topic_exe(struct searchNode *thenode, void *theinput);
-void topic_free(struct searchNode *thenode);
+void *topic_exe(searchCtx *ctx, struct searchNode *thenode, void *theinput);
+void topic_free(searchCtx *ctx, struct searchNode *thenode);
-struct searchNode *topic_parse(int type, int argc, char **argv) {
+struct searchNode *topic_parse(searchCtx *ctx, int type, int argc, char **argv) {
struct searchNode *thenode;
if (type != SEARCHTYPE_CHANNEL) {
return thenode;
}
-void *topic_exe(struct searchNode *thenode, void *theinput) {
+void *topic_exe(searchCtx *ctx, struct searchNode *thenode, void *theinput) {
chanindex *cip = (chanindex *)theinput;
if ((cip->channel==NULL) || (cip->channel->topic==NULL))
return cip->channel->topic->content;
}
-void topic_free(struct searchNode *thenode) {
+void topic_free(searchCtx *ctx, struct searchNode *thenode) {
free(thenode);
}