UserDisplayFunc previousdefault;
void _init() {
- regnickdisp("auth", printnick_auth);
- regnickdisp("authchans", printnick_authchans);
- regchandisp("qusers", printchannel_qusers);
- reguserdisp("auth", printauth);
-
- registersearchterm("qusers", qusers_parse);
- registersearchterm("qlasthost", qlasthost_parse);
- registersearchterm("qemail", qemail_parse);
- registersearchterm("qsuspendreason", qsuspendreason_parse);
- registersearchterm("qusername", qusername_parse);
- registersearchterm("qchanflags", qchanflags_parse);
+ regdisp(reg_nicksearch, "auth", printnick_auth);
+ regdisp(reg_nicksearch, "authchans", printnick_authchans);
+ regdisp(reg_chansearch, "qusers", printchannel_qusers);
+ regdisp(reg_usersearch, "auth", printauth);
+
+ registersearchterm(reg_usersearch, "qusers", qusers_parse);
+ registersearchterm(reg_usersearch, "qlasthost", qlasthost_parse);
+ registersearchterm(reg_usersearch, "qemail", qemail_parse);
+ registersearchterm(reg_usersearch, "qsuspendreason", qsuspendreason_parse);
+ registersearchterm(reg_usersearch, "qusername", qusername_parse);
+ registersearchterm(reg_chansearch, "qchanflags", qchanflags_parse);
chanservaddcommand("nicksearch", QCMD_OPER, 5, cs_donicksearch, "Wrapper for standard newserv nicksearch command.", "");
chanservaddcommand("chansearch", QCMD_OPER, 5, cs_dochansearch, "Wrapper for standard newserv chansearch command.", "");
}
void _fini() {
- unregnickdisp("auth", printnick_auth);
- unregnickdisp("authchans", printnick_authchans);
- unregchandisp("qusers", printchannel_qusers);
- unreguserdisp("auth", printauth);
-
- deregistersearchterm("qusers", qusers_parse);
- deregistersearchterm("qlasthost", qlasthost_parse);
- deregistersearchterm("qemail", qemail_parse);
- deregistersearchterm("qsuspendreason", qsuspendreason_parse);
- deregistersearchterm("qusername", qusername_parse);
- deregistersearchterm("qchanflags", qchanflags_parse);
+ unregdisp(reg_nicksearch, "auth", printnick_auth);
+ unregdisp(reg_nicksearch, "authchans", printnick_authchans);
+ unregdisp(reg_chansearch, "qusers", printchannel_qusers);
+ unregdisp(reg_usersearch, "auth", printauth);
+
+ deregistersearchterm(reg_usersearch, "qusers", qusers_parse);
+ deregistersearchterm(reg_usersearch, "qlasthost", qlasthost_parse);
+ deregistersearchterm(reg_usersearch, "qemail", qemail_parse);
+ deregistersearchterm(reg_usersearch, "qsuspendreason", qsuspendreason_parse);
+ deregistersearchterm(reg_usersearch, "qusername", qusername_parse);
+ deregistersearchterm(reg_usersearch, "qchanflags", qchanflags_parse);
chanservremovecommand("nicksearch", cs_donicksearch);
chanservremovecommand("chansearch", cs_dochansearch);
void printchannel_qusers(searchCtx *, nick *, chanindex *);
void printauth(searchCtx *, nick *, authname *);
-struct searchNode *qusers_parse(searchCtx *, int type, int argc, char **argv);
-struct searchNode *qlasthost_parse(searchCtx *, int type, int argc, char **argv);
-struct searchNode *qemail_parse(searchCtx *, int type, int argc, char **argv);
-struct searchNode *qsuspendreason_parse(searchCtx *, int type, int argc, char **argv);
-struct searchNode *qusername_parse(searchCtx *, int type, int argc, char **argv);
-struct searchNode *qchanflags_parse(searchCtx *, int type, int argc, char **argv);
+struct searchNode *qusers_parse(searchCtx *, int argc, char **argv);
+struct searchNode *qlasthost_parse(searchCtx *, int argc, char **argv);
+struct searchNode *qemail_parse(searchCtx *, int argc, char **argv);
+struct searchNode *qsuspendreason_parse(searchCtx *, int argc, char **argv);
+struct searchNode *qusername_parse(searchCtx *, int argc, char **argv);
+struct searchNode *qchanflags_parse(searchCtx *, int argc, char **argv);
#endif
flag_t clearmodes;
};
-struct searchNode *qchanflags_parse(searchCtx *ctx, int type, int argc, char **argv) {
+struct searchNode *qchanflags_parse(searchCtx *ctx, int argc, char **argv) {
struct searchNode *thenode;
struct qchanflags_localdata *localdata;
- if (type != SEARCHTYPE_CHANNEL) {
- parseError = "qchanflags: this function is only valid for channel searches.";
- return NULL;
- }
-
if (!(thenode=(struct searchNode *)malloc(sizeof (struct searchNode)))) {
parseError = "malloc: could not allocate memory for this search.";
return NULL;
void *qemail_exe(searchCtx *ctx, struct searchNode *thenode, void *theinput);
void qemail_free(searchCtx *ctx, struct searchNode *thenode);
-struct searchNode *qemail_parse(searchCtx *ctx, int type, int argc, char **argv) {
+struct searchNode *qemail_parse(searchCtx *ctx, int argc, char **argv) {
struct searchNode *thenode;
- if (type != SEARCHTYPE_USER) {
- parseError = "qemail: this function is only valid for user searches.";
- return NULL;
- }
-
if (!(thenode=(struct searchNode *)malloc(sizeof (struct searchNode)))) {
parseError = "malloc: could not allocate memory for this search.";
return NULL;
void *qlasthost_exe(searchCtx *ctx, struct searchNode *thenode, void *theinput);
void qlasthost_free(searchCtx *ctx, struct searchNode *thenode);
-struct searchNode *qlasthost_parse(searchCtx *ctx, int type, int argc, char **argv) {
+struct searchNode *qlasthost_parse(searchCtx *ctx, int argc, char **argv) {
struct searchNode *thenode;
- if (type != SEARCHTYPE_USER) {
- parseError = "qlasthost: this function is only valid for user searches.";
- return NULL;
- }
-
if (!(thenode=(struct searchNode *)malloc(sizeof (struct searchNode)))) {
parseError = "malloc: could not allocate memory for this search.";
return NULL;
void *qsuspendreason_exe(searchCtx *ctx, struct searchNode *thenode, void *theinput);
void qsuspendreason_free(searchCtx *ctx, struct searchNode *thenode);
-struct searchNode *qsuspendreason_parse(searchCtx *ctx, int type, int argc, char **argv) {
+struct searchNode *qsuspendreason_parse(searchCtx *ctx, int argc, char **argv) {
struct searchNode *thenode;
- if (type != SEARCHTYPE_USER) {
- parseError = "qsuspendreason: this function is only valid for user searches.";
- return NULL;
- }
-
if (!(thenode=(struct searchNode *)malloc(sizeof (struct searchNode)))) {
parseError = "malloc: could not allocate memory for this search.";
return NULL;
void *qusername_exe(searchCtx *ctx, struct searchNode *thenode, void *theinput);
void qusername_free(searchCtx *ctx, struct searchNode *thenode);
-struct searchNode *qusername_parse(searchCtx *ctx, int type, int argc, char **argv) {
+struct searchNode *qusername_parse(searchCtx *ctx, int argc, char **argv) {
struct searchNode *thenode;
- if (type != SEARCHTYPE_USER) {
- parseError = "qusername: this function is only valid for user searches.";
- return NULL;
- }
-
if (!(thenode=(struct searchNode *)malloc(sizeof (struct searchNode)))) {
parseError = "malloc: could not allocate memory for this search.";
return NULL;
flag_t clearmodes;
};
-struct searchNode *qusers_parse(searchCtx *ctx, int type, int argc, char **argv) {
+struct searchNode *qusers_parse(searchCtx *ctx, int argc, char **argv) {
struct searchNode *thenode;
struct qusers_localdata *localdata;
- if (type != SEARCHTYPE_CHANNEL) {
- parseError = "qusers: this function is only valid for channel searches.";
- return NULL;
- }
-
if (!(thenode=(struct searchNode *)malloc(sizeof (struct searchNode)))) {
parseError = "malloc: could not allocate memory for this search.";
return NULL;
#include <stdio.h>
#include <stdarg.h>
#include <string.h>
-#include "newsearch.h"
#include "../irc/irc_config.h"
#include "../lib/irc_string.h"
#include "../lib/version.h"
#include "../lib/stringbuf.h"
#include "../lib/strlfunc.h"
+#include "../lib/array.h"
+#include "newsearch.h"
MODULE_VERSION("");
-CommandTree *searchTree;
-CommandTree *chanOutputTree;
-CommandTree *nickOutputTree;
-CommandTree *userOutputTree;
+CommandTree *searchCmdTree;
+searchList *globalterms = NULL;
int do_nicksearch(void *source, int cargc, char **cargv);
int do_chansearch(void *source, int cargc, char **cargv);
NickDisplayFunc defaultnickfn = printnick;
ChanDisplayFunc defaultchanfn = printchannel;
-void registersearchterm(char *term, parseFunc parsefunc);
-void deregistersearchterm(char *term, parseFunc parsefunc);
+searchCmd *reg_nicksearch, *reg_chansearch, *reg_usersearch;
-void regchandisp(const char *name, ChanDisplayFunc handler) {
- addcommandtotree(chanOutputTree, name, 0, 0, (CommandHandler)handler);
-}
+searchCmd *registersearchcommand(char *name, int level, CommandHandler cmd, void *defaultdisplayfunc) {
+ searchCmd *acmd;
+ searchList *sl;
-void unregchandisp(const char *name, ChanDisplayFunc handler) {
- deletecommandfromtree(chanOutputTree, name, (CommandHandler)handler);
-}
+ registercontrolhelpcmd(name, NO_OPER,4, cmd, "Usage: <criteria\nSearches with the given criteria");
+
+ acmd=(struct searchCmd *)malloc(sizeof(struct searchCmd));
-void regnickdisp(const char *name, NickDisplayFunc handler) {
- addcommandtotree(nickOutputTree, name, 0, 0, (CommandHandler)handler);
-}
+ acmd->handler = cmd;
+
+ acmd->name = getsstring( name, NSMAX_COMMAND_LEN);
+ acmd->outputtree = newcommandtree();
+ acmd->searchtree = newcommandtree();
-void unregnickdisp(const char *name, NickDisplayFunc handler) {
- deletecommandfromtree(nickOutputTree, name, (CommandHandler)handler);
+ addcommandtotree(searchCmdTree, name, 0, 0, (CommandHandler)acmd);
+
+ sl = globalterms;
+ while (sl) {
+ registersearchterm( acmd, sl->name->content, sl->cmd);
+ sl = sl->next;
+ }
+
+ return acmd;
}
-void reguserdisp(const char *name, UserDisplayFunc handler) {
- addcommandtotree(userOutputTree, name, 0, 0, (CommandHandler)handler);
+void deregistersearchcommand(searchCmd *scmd) {
+ deregistercontrolcmd(scmd->name->content, (CommandHandler)scmd->handler);
+ destroycommandtree(scmd->outputtree);
+ destroycommandtree(scmd->searchtree);
+ freesstring(scmd->name);
+ free(scmd);
}
-void unreguserdisp(const char *name, UserDisplayFunc handler) {
- deletecommandfromtree(userOutputTree, name, (CommandHandler)handler);
+void regdisp( searchCmd *cmd, const char *name, void *handler) {
+ addcommandtotree(cmd->outputtree, name, 0, 0, (CommandHandler) handler);
+}
+
+void unregdisp( searchCmd *cmd, const char *name, void *handler ) {
+ deletecommandfromtree(cmd->outputtree, name, (CommandHandler) handler);
}
+void *findcommandinlist( searchList *sl, char *name){
+ while(sl) {
+ if(strcmp(sl->name->content,name) == 0 ) {
+ return sl;
+ }
+ sl = sl->next;
+ }
+ return NULL;
+}
+
const char *parseError;
/* used for *_free functions that need to warn users of certain things
i.e. hitting too many users in a (kill) or (gline) */
nick *senderNSExtern;
void _init() {
- searchTree=newcommandtree();
- chanOutputTree=newcommandtree();
- nickOutputTree=newcommandtree();
- userOutputTree=newcommandtree();
+ searchCmdTree=newcommandtree();
+
+ reg_nicksearch = (searchCmd *)registersearchcommand("nicksearch",NO_OPER,&do_nicksearch, printnick);
+ reg_chansearch = (searchCmd *)registersearchcommand("chansearch",NO_OPER,&do_chansearch, printchannel);
+ reg_usersearch = (searchCmd *)registersearchcommand("usersearch",NO_OPER,&do_usersearch, printuser);
/* Boolean operations */
- registersearchterm("and",and_parse);
- registersearchterm("not",not_parse);
- registersearchterm("or",or_parse);
+ registerglobalsearchterm("and",and_parse);
+ registerglobalsearchterm("not",not_parse);
+ registerglobalsearchterm("or",or_parse);
- registersearchterm("eq",eq_parse);
+ registerglobalsearchterm("eq",eq_parse);
- registersearchterm("lt",lt_parse);
- registersearchterm("gt",gt_parse);
+ registerglobalsearchterm("lt",lt_parse);
+ registerglobalsearchterm("gt",gt_parse);
/* String operations */
- registersearchterm("match",match_parse);
- registersearchterm("regex",regex_parse);
- registersearchterm("length",length_parse);
+ registerglobalsearchterm("match",match_parse);
+ registerglobalsearchterm("regex",regex_parse);
+ registerglobalsearchterm("length",length_parse);
/* Nickname operations */
- registersearchterm("hostmask",hostmask_parse);
- registersearchterm("realname",realname_parse);
- registersearchterm("authname",authname_parse);
- registersearchterm("authts",authts_parse);
- registersearchterm("ident",ident_parse);
- registersearchterm("host",host_parse);
- registersearchterm("channel",channel_parse);
- registersearchterm("timestamp",timestamp_parse);
- registersearchterm("country",country_parse);
- registersearchterm("ip",ip_parse);
- registersearchterm("channels",channels_parse);
- registersearchterm("server",server_parse);
- registersearchterm("authid",authid_parse);
+ registersearchterm(reg_nicksearch, "hostmask",hostmask_parse); /* nick only */
+ registersearchterm(reg_nicksearch, "realname",realname_parse); /* nick only */
+ registersearchterm(reg_nicksearch, "authname",authname_parse); /* nick only */
+ registersearchterm(reg_nicksearch, "authts",authts_parse); /* nick only */
+ registersearchterm(reg_nicksearch, "ident",ident_parse); /* nick only */
+ registersearchterm(reg_nicksearch, "host",host_parse); /* nick only */
+ registersearchterm(reg_nicksearch, "channel",channel_parse); /* nick only */
+ registersearchterm(reg_nicksearch, "timestamp",timestamp_parse); /* nick only */
+ registersearchterm(reg_nicksearch, "country",country_parse); /* nick only */
+ registersearchterm(reg_nicksearch, "ip",ip_parse); /* nick only */
+ registersearchterm(reg_nicksearch, "channels",channels_parse); /* nick only */
+ registersearchterm(reg_nicksearch, "server",server_parse); /* nick only */
+ registersearchterm(reg_nicksearch, "authid",authid_parse); /* nick only */
/* Channel operations */
- registersearchterm("exists",exists_parse);
- registersearchterm("services",services_parse);
- registersearchterm("size",size_parse);
- registersearchterm("name",name_parse);
- registersearchterm("topic",topic_parse);
- registersearchterm("oppct",oppct_parse);
- registersearchterm("uniquehostpct",hostpct_parse);
- registersearchterm("authedpct",authedpct_parse);
- registersearchterm("kick",kick_parse);
+ registersearchterm(reg_chansearch, "exists",exists_parse); /* channel only */
+ registersearchterm(reg_chansearch, "services",services_parse); /* channel only */
+ registersearchterm(reg_chansearch, "size",size_parse); /* channel only */
+ registersearchterm(reg_chansearch, "name",name_parse); /* channel only */
+ registersearchterm(reg_chansearch, "topic",topic_parse); /* channel only */
+ registersearchterm(reg_chansearch, "oppct",oppct_parse); /* channel only */
+ registersearchterm(reg_chansearch, "uniquehostpct",hostpct_parse); /* channel only */
+ registersearchterm(reg_chansearch, "authedpct",authedpct_parse); /* channel only */
+ registersearchterm(reg_chansearch, "kick",kick_parse); /* channel only */
/* Nickname / channel operations */
- registersearchterm("modes",modes_parse);
- registersearchterm("nick",nick_parse);
+ registersearchterm(reg_chansearch, "modes",modes_parse);
+ registersearchterm(reg_nicksearch, "modes",modes_parse);
+ registersearchterm(reg_chansearch, "nick",nick_parse);
+ registersearchterm(reg_nicksearch, "nick",nick_parse);
/* Kill / gline parameters */
- registersearchterm("kill",kill_parse);
- registersearchterm("gline",gline_parse);
+ registersearchterm(reg_chansearch,"kill",kill_parse);
+ registersearchterm(reg_chansearch,"gline",gline_parse);
+ registersearchterm(reg_nicksearch,"kill",kill_parse);
+ registersearchterm(reg_nicksearch,"gline",gline_parse);
/* Iteration functionality */
- registersearchterm("any",any_parse);
- registersearchterm("all",all_parse);
- registersearchterm("var",var_parse);
+ registerglobalsearchterm("any",any_parse);
+ registerglobalsearchterm("all",all_parse);
+ registerglobalsearchterm("var",var_parse);
/* Iterable functions */
- registersearchterm("channeliter",channeliter_parse);
+ registersearchterm(reg_nicksearch, "channeliter",channeliter_parse); /* nick only */
/* Notice functionality */
- registersearchterm("notice",notice_parse);
-
+ registersearchterm(reg_chansearch,"notice",notice_parse);
+ registersearchterm(reg_nicksearch,"notice",notice_parse);
+
/* Nick output filters */
- regnickdisp("default",printnick);
- regnickdisp("channels",printnick_channels);
+ regdisp(reg_nicksearch,"default",printnick);
+ regdisp(reg_nicksearch,"channels",printnick_channels);
/* Channel output filters */
- regchandisp("default",printchannel);
- regchandisp("topic",printchannel_topic);
- regchandisp("services",printchannel_services);
+ regdisp(reg_chansearch,"default",printchannel);
+ regdisp(reg_chansearch,"topic",printchannel_topic);
+ regdisp(reg_chansearch,"services",printchannel_services);
/* Nick output filters */
- reguserdisp("default",printuser);
-
- registercontrolhelpcmd("nicksearch",NO_OPER,4,do_nicksearch, "Usage: nicksearch <criteria>\nSearches for nicknames with the given criteria.");
- registercontrolhelpcmd("chansearch",NO_OPER,4,do_chansearch, "Usage: chansearch <criteria>\nSearches for channels with the given criteria.");
- registercontrolhelpcmd("usersearch",NO_OPER,4,do_usersearch, "Usage: usersearch <criteria>\nSearches for users with the given criteria.");
+ regdisp(reg_usersearch,"default",printuser);
+
}
void _fini() {
- destroycommandtree(searchTree);
- destroycommandtree(chanOutputTree);
- destroycommandtree(nickOutputTree);
- destroycommandtree(userOutputTree);
- deregistercontrolcmd("nicksearch", do_nicksearch);
- deregistercontrolcmd("chansearch", do_chansearch);
- deregistercontrolcmd("usersearch", do_usersearch);
+ searchList *sl, *psl;
+ int i,n;
+ Command *cmdlist[100];
+
+ sl = globalterms;
+ while (sl) {
+ psl = sl;
+ sl = sl->next;
+
+ n=getcommandlist(searchCmdTree,cmdlist,100);
+ for(i=0;i<n;i++) {
+ deregistersearchterm( (searchCmd *)cmdlist[i]->handler, psl->name->content, psl->cmd);
+ }
+
+ freesstring(psl->name);
+ free(psl);
+
+ }
+
+ deregistersearchcommand( reg_nicksearch );
+ deregistersearchcommand( reg_chansearch );
+ deregistersearchcommand( reg_usersearch );
+ destroycommandtree( searchCmdTree );
+}
+
+void registerglobalsearchterm(char *term, parseFunc parsefunc) {
+ searchList *sl = malloc(sizeof(searchList));
+ int i,n;
+ Command *cmdlist[100];
+
+ sl->cmd = parsefunc;
+ sl->name = getsstring(term, NSMAX_COMMAND_LEN);
+ sl->next = NULL;
+
+ if ( globalterms != NULL ) {
+ sl->next = globalterms;
+ }
+ globalterms = sl;
+
+ n=getcommandlist(searchCmdTree,cmdlist,100);
+ for(i=0;i<n;i++) {
+ registersearchterm( (searchCmd *)cmdlist[i]->handler,term, parsefunc);
+ }
+}
+
+void deregisterglobalsearchterm(char *term, parseFunc parsefunc) {
+ int i,n;
+ Command *cmdlist[100];
+ searchList *sl, *psl=NULL;
+
+ sl = globalterms;
+ while (sl) {
+ if ( strcmp( sl->name->content, term) == 0 ) {
+ break;
+ }
+ psl = sl;
+ sl = sl->next;
+ }
+
+ if (sl) {
+ if( psl ) {
+ psl->next = sl->next;
+ }
+
+ n=getcommandlist(searchCmdTree,cmdlist,100);
+ for(i=0;i<n;i++) {
+ deregistersearchterm( (searchCmd *)cmdlist[i]->handler, term, parsefunc);
+ }
+ freesstring(sl->name);
+ free(sl);
+ }
}
-void registersearchterm(char *term, parseFunc parsefunc) {
- addcommandtotree(searchTree, term, 0, 0, (CommandHandler) parsefunc);
+void registersearchterm(searchCmd *cmd, char *term, parseFunc parsefunc) {
+ addcommandtotree(cmd->searchtree, term, 0, 0, (CommandHandler) parsefunc);
}
-void deregistersearchterm(char *term, parseFunc parsefunc) {
- deletecommandfromtree(searchTree, term, (CommandHandler) parsefunc);
+void deregistersearchterm(searchCmd *cmd, char *term, parseFunc parsefunc) {
+ deletecommandfromtree(cmd->searchtree, term, (CommandHandler) parsefunc);
}
static void controlwallwrapper(int level, char *format, ...) {
va_end(ap);
}
-static int parseopts(int cargc, char **cargv, int *arg, int *limit, void **display, CommandTree *tree, replyFunc reply, void *sender) {
+int parseopts(int cargc, char **cargv, int *arg, int *limit, void **subset, void **display, CommandTree *sl, replyFunc reply, void *sender) {
char *ch;
- struct Command *cmd;
-
+ Command *cmd;
+ struct irc_in_addr sin; unsigned char bits;
+
if (*cargv[0] == '-') {
/* options */
(*arg)++;
reply(sender,"Error: -d switch requires an argument");
return CMD_USAGE;
}
- cmd=findcommandintree(tree, cargv[*arg], 1);
+ cmd=findcommandintree(sl, cargv[*arg],1);
if (!cmd) {
reply(sender,"Error: unknown output format %s",cargv[*arg]);
return CMD_USAGE;
*display=(void *)cmd->handler;
(*arg)++;
break;
+
+ case 's':
+ if (cargc<*arg) {
+ reply(sender,"Error: -s switch requires an argument");
+ return CMD_USAGE;
+ }
+ if (ipmask_parse(cargv[*arg], &sin, &bits) == 0) {
+ reply(sender, "Error: Invalid CIDR mask supplied");
+ return CMD_USAGE;
+ }
+ *subset = (void *)refnode(iptree, &sin, bits);
+ (*arg)++;
+ break;
default:
reply(sender,"Unrecognised flag -%c.",*ch);
return CMD_OK;
}
-void newsearch_ctxinit(searchCtx *ctx, searchParseFunc searchfn, replyFunc replyfn, wallFunc wallfn, void *arg, int type) {
+void newsearch_ctxinit(searchCtx *ctx, searchParseFunc searchfn, replyFunc replyfn, wallFunc wallfn, void *arg, searchCmd *cmd) {
memset(ctx, 0, sizeof(searchCtx));
ctx->reply = replyfn;
ctx->wall = wallfn;
ctx->parser = searchfn;
ctx->arg = arg;
- ctx->type = type;
+ ctx->searchcmd = cmd;
}
int do_nicksearch_real(replyFunc reply, wallFunc wall, void *source, int cargc, char **cargv) {
if (cargc<1)
return CMD_USAGE;
- ret = parseopts(cargc, cargv, &arg, &limit, (void **)&display, nickOutputTree, reply, sender);
+ ret = parseopts(cargc, cargv, &arg, &limit, NULL, (void **)&display, reg_nicksearch->outputtree, reply, sender);
if(ret != CMD_OK)
return ret;
rejoinline(cargv[arg],cargc-arg);
}
- newsearch_ctxinit(&ctx, search_parse, reply, wall, NULL, SEARCHTYPE_NICK);
+ newsearch_ctxinit(&ctx, search_parse, reply, wall, NULL, reg_nicksearch);
if (!(search = ctx.parser(&ctx, cargv[arg]))) {
reply(sender,"Parse error: %s",parseError);
if (cargc<1)
return CMD_USAGE;
- ret = parseopts(cargc, cargv, &arg, &limit, (void **)&display, chanOutputTree, reply, sender);
+ ret = parseopts(cargc, cargv, &arg, &limit, NULL, (void **)&display, reg_chansearch->outputtree, reply, sender);
if(ret != CMD_OK)
return ret;
rejoinline(cargv[arg],cargc-arg);
}
- newsearch_ctxinit(&ctx, search_parse, reply, wall, NULL, SEARCHTYPE_CHANNEL);
+ newsearch_ctxinit(&ctx, search_parse, reply, wall, NULL, reg_chansearch);
if (!(search = ctx.parser(&ctx, cargv[arg]))) {
reply(sender,"Parse error: %s",parseError);
return CMD_ERROR;
if (cargc<1)
return CMD_USAGE;
- ret = parseopts(cargc, cargv, &arg, &limit, (void **)&display, userOutputTree, reply, sender);
+ ret = parseopts(cargc, cargv, &arg, &limit, NULL, (void **)&display, reg_usersearch->outputtree, reply, sender);
if(ret != CMD_OK)
return ret;
rejoinline(cargv[arg],cargc-arg);
}
- newsearch_ctxinit(&ctx, search_parse, reply, wall, NULL, SEARCHTYPE_USER);
+ newsearch_ctxinit(&ctx, search_parse, reply, wall, NULL, reg_usersearch);
if (!(search = ctx.parser(&ctx, cargv[arg]))) {
reply(sender,"Parse error: %s",parseError);
return CMD_ERROR;
if (*(ch-1) == 0) /* if the last character was a space */
j--; /* remove an argument */
- if (!(cmd=findcommandintree(searchTree,argvector[0],1))) {
+ if (!(cmd=findcommandintree(ctx->searchcmd->searchtree,argvector[0],1))) {
parseError = "Unknown command";
return NULL;
} else {
#include "../nick/nick.h"
+#include "../lib/sstring.h"
#include "../parser/parser.h"
#include "../channel/channel.h"
#include "../lib/flags.h"
#include "../authext/authext.h"
-
-#define SEARCHTYPE_CHANNEL 1
-#define SEARCHTYPE_NICK 2
-#define SEARCHTYPE_USER 3
-
+#include "../patricia/patricia.h"
#define NSMAX_KILL_LIMIT 500
#define NSMAX_GLINE_LIMIT 500
-
-
#define NSMAX_GLINE_CLONES 5
-
/* gline duration, in seconds */
#define NSGLINE_DURATION 3600
#define NSMAX_REASON_LEN 120
#define NSMAX_NOTICE_LEN 250
-
+#define NSMAX_COMMAND_LEN 20
#define RETURNTYPE_BOOL 0x01
#define RETURNTYPE_INT 0x02
struct coercedata cdata;
};
+typedef struct searchCmd {
+ void *defaultdisplayfunc;
+ sstring *name;
+ CommandHandler handler;
+ struct CommandTree *outputtree;
+ struct CommandTree *searchtree;
+} searchCmd;
+
+typedef struct searchList {
+ void *cmd;
+ sstring *name;
+ struct searchList *next;
+} searchList;
+
typedef struct searchCtx {
searchParseFunc parser;
replyFunc reply;
void *arg;
struct searchVariable vars[MAX_VARIABLES];
int lastvar;
- int type;
+ struct searchCmd *searchcmd;
} searchCtx;
/* Core functions */
struct searchNode *coerceNode(searchCtx *ctx, struct searchNode *thenode, int type);
/* Registration functions */
-void registersearchterm(char *term, parseFunc parsefunc);
-void deregistersearchterm(char *term, parseFunc parsefunc);
-void regchandisp(const char *name, ChanDisplayFunc handler);
-void unregchandisp(const char *name, ChanDisplayFunc handler);
-void regnickdisp(const char *name, NickDisplayFunc handler);
-void unregnickdisp(const char *name, NickDisplayFunc handler);
-void reguserdisp(const char *name, UserDisplayFunc handler);
-void unreguserdisp(const char *name, UserDisplayFunc handler);
+searchCmd *registersearchcommand(char *name, int level, CommandHandler cmd, void *defaultdisplayfunc);
+void deregistersearchcommand(searchCmd *scmd);
+void registersearchterm(searchCmd *cmd, char *term, parseFunc parsefunc);
+void deregistersearchterm(searchCmd *cmd, char *term, parseFunc parsefunc);
+void registerglobalsearchterm(char *term, parseFunc parsefunc);
+void deregisterglobalsearchterm(char *term, parseFunc parsefunc);
+void regdisp( searchCmd *cmd, const char *name, void *handler);
+void unregdisp( searchCmd *cmd, const char *name, void *handler);
/* Special nick* printf */
void nssnprintf(char *, size_t, const char *, nick *);
searchNode *var_get(searchCtx *ctx, char *arg);
void var_setstr(struct searchVariable *v, char *data);
-void newsearch_ctxinit(searchCtx *ctx, searchParseFunc searchfn, replyFunc replyfn, wallFunc wallfn, void *arg, int type);
+void newsearch_ctxinit(searchCtx *ctx, searchParseFunc searchfn, replyFunc replyfn, wallFunc wallfn, void *arg, searchCmd *cmd);
/* AST functions */
int ast_chansearch(searchASTExpr *tree, replyFunc reply, void *sender, wallFunc wall, ChanDisplayFunc display, HeaderFunc header, void *headerarg, int limit);
int ast_usersearch(searchASTExpr *tree, replyFunc reply, void *sender, wallFunc wall, UserDisplayFunc display, HeaderFunc header, void *headerarg, int limit);
-char *ast_printtree(char *buf, size_t bufsize, searchASTExpr *expr);
+char *ast_printtree(char *buf, size_t bufsize, searchASTExpr *expr, searchCmd *cmd);
+
+int parseopts(int cargc, char **cargv, int *arg, int *limit, void **subset, void **display, CommandTree *sl, replyFunc reply, void *sender);
/* erk */
-extern CommandTree *searchTree;
+extern searchList *globalterms;
+
+extern searchCmd *reg_nicksearch;
+extern searchCmd *reg_chansearch;
+extern searchCmd *reg_usersearch;
extern UserDisplayFunc defaultuserfn;
extern NickDisplayFunc defaultnickfn;
memset(&cache, 0, sizeof(cache));
cache.tree = tree;
- newsearch_ctxinit(&ctx, search_astparse, reply, wall, &cache, SEARCHTYPE_NICK);
+ newsearch_ctxinit(&ctx, search_astparse, reply, wall, &cache, reg_nicksearch);
buf[0] = '\0';
- reply(sender, "Parsing: %s", ast_printtree(buf, sizeof(buf), tree));
+ reply(sender, "Parsing: %s", ast_printtree(buf, sizeof(buf), tree, reg_nicksearch));
search = ctx.parser(&ctx, (char *)tree);
if(!search) {
reply(sender, "Parse error: %s", parseError);
searchNode *search;
char buf[1024];
- newsearch_ctxinit(&ctx, search_astparse, reply, wall, &cache, SEARCHTYPE_CHANNEL);
+ newsearch_ctxinit(&ctx, search_astparse, reply, wall, &cache, reg_chansearch);
buf[0] = '\0';
- reply(sender, "Parsing: %s", ast_printtree(buf, sizeof(buf), tree));
+ reply(sender, "Parsing: %s", ast_printtree(buf, sizeof(buf), tree, reg_chansearch));
search = ctx.parser(&ctx, (char *)tree);
if(!search) {
reply(sender, "Parse error: %s", parseError);
memset(&cache, 0, sizeof(cache));
cache.tree = tree;
- newsearch_ctxinit(&ctx, search_astparse, reply, wall, &cache, SEARCHTYPE_USER);
+ newsearch_ctxinit(&ctx, search_astparse, reply, wall, &cache, reg_usersearch);
buf[0] = '\0';
- reply(sender, "Parsing: %s", ast_printtree(buf, sizeof(buf), tree));
+ reply(sender, "Parsing: %s", ast_printtree(buf, sizeof(buf), tree, reg_usersearch));
search = ctx.parser(&ctx, (char *)tree);
if(!search) {
reply(sender, "Parse error: %s", parseError);
/* horribly inefficient -- don't call me very often! */
-static char *ast_printtree_real(StringBuf *buf, searchASTExpr *expr) {
+static char *ast_printtree_real(StringBuf *buf, searchASTExpr *expr, searchCmd *cmd) {
char lbuf[256];
if(expr->type == AST_NODE_CHILD) {
int i;
- sstring *command = getcommandname(searchTree, (void *)expr->u.child->fn);
+ sstring *command = getcommandname(cmd->searchtree, (void *)expr->u.child->fn);
if(command) {
snprintf(lbuf, sizeof(lbuf), "(%s", command->content);
for(i=0;i<expr->u.child->argc;i++) {
sbaddchar(buf, ' ');
- ast_printtree_real(buf, expr->u.child->argv[i]);
+ ast_printtree_real(buf, expr->u.child->argv[i], cmd);
}
sbaddchar(buf, ')');
return buf->buf;
}
-char *ast_printtree(char *buf, size_t bufsize, searchASTExpr *expr) {
+char *ast_printtree(char *buf, size_t bufsize, searchASTExpr *expr, searchCmd *cmd) {
StringBuf b;
char *p;
b.len = 0;
b.buf = buf;
- p = ast_printtree_real(&b, expr);
+ p = ast_printtree_real(&b, expr, cmd);
sbterminate(&b);
return p;
struct searchNode *authedpct_parse(searchCtx *ctx, int argc, char **argv) {
struct searchNode *thenode;
- if (ctx->type != SEARCHTYPE_CHANNEL) {
- parseError = "authedpct: this function is only valid for channel searches.";
- return NULL;
- }
-
if (!(thenode=(struct searchNode *)malloc(sizeof(struct searchNode)))) {
/* couldn't malloc() memory for thenode, so free localdata to avoid leakage */
parseError = "malloc: could not allocate memory for this search.";
struct searchNode *authid_parse(searchCtx *ctx, int argc, char **argv) {
struct searchNode *thenode;
- if (ctx->type != SEARCHTYPE_NICK) {
- parseError = "authid: this function is only valid for nick searches.";
- return NULL;
- }
-
if (!(thenode=(struct searchNode *)malloc(sizeof (struct searchNode)))) {
parseError = "malloc: could not allocate memory for this search.";
return NULL;
struct searchNode *authname_parse(searchCtx *ctx, int argc, char **argv) {
struct searchNode *thenode;
- if (ctx->type != SEARCHTYPE_NICK) {
- parseError = "authname: this function is only valid for nick searches.";
- return NULL;
- }
-
if (!(thenode=(struct searchNode *)malloc(sizeof (struct searchNode)))) {
parseError = "malloc: could not allocate memory for this search.";
return NULL;
struct searchNode *authts_parse(searchCtx *ctx, int argc, char **argv) {
struct searchNode *thenode;
- if (ctx->type != SEARCHTYPE_NICK) {
- parseError = "authts: this function is only valid for nick searches.";
- return NULL;
- }
-
if (!(thenode=(struct searchNode *)malloc(sizeof (struct searchNode)))) {
parseError = "malloc: could not allocate memory for this search.";
return NULL;
struct searchNode *thenode;
channel *cp;
- if (ctx->type != SEARCHTYPE_NICK) {
- parseError = "channel: this function is only valid for nick searches.";
- return NULL;
- }
-
if (argc<1) {
parseError = "channel: usage: channel <channel name>";
return NULL;
return NULL;
}
- if(ctx->type != SEARCHTYPE_NICK) {
- parseError = "channeliter: this function is only valid for nick searches.";
- return NULL;
- }
-
if(!(localdata=(struct channeliter_localdata *)malloc(sizeof(struct channeliter_localdata)))) {
parseError = "malloc: could not allocate memory for this search.";
return NULL;
struct searchNode *channels_parse(searchCtx *ctx, int argc, char **argv) {
struct searchNode *thenode;
- if (ctx->type != SEARCHTYPE_NICK) {
- parseError = "channels: this function is only valid for nick searches.";
- return NULL;
- }
-
if (!(thenode=(struct searchNode *)malloc(sizeof (struct searchNode)))) {
parseError = "malloc: could not allocate memory for this search.";
return NULL;
GeoIP_LookupCode l;
long target;
- if (ctx->type != SEARCHTYPE_NICK) {
- parseError = "country: this function is only valid for nick searches.";
- return NULL;
- }
-
if (argc<1) {
parseError = "country: usage: country <country 2 character ISO code>";
return NULL;
struct searchNode *exists_parse(searchCtx *ctx, int argc, char **argv) {
struct searchNode *thenode;
- if (ctx->type != SEARCHTYPE_CHANNEL) {
- parseError = "exists: this function is only valid for channel searches.";
- return NULL;
- }
-
if (!(thenode=(struct searchNode *)malloc(sizeof (struct searchNode)))) {
parseError = "malloc: could not allocate memory for this search.";
return NULL;
return NULL;
}
localdata->count = 0;
- if (ctx->type == SEARCHTYPE_CHANNEL)
+ if (ctx->searchcmd == reg_chansearch)
localdata->marker = nextchanmarker();
- else
+ else if (ctx->searchcmd == reg_nicksearch)
localdata->marker = nextnickmarker();
+ else {
+ parseError = "gline: invalid search type";
+ return NULL;
+ }
switch (argc) {
case 0:
localdata = thenode->localdata;
- if (ctx->type == SEARCHTYPE_CHANNEL) {
+ if (ctx->searchcmd == reg_chansearch) {
cip = (chanindex *)theinput;
cip->marker = localdata->marker;
localdata->count += cip->channel->users->totalusers;
return;
}
- if (ctx->type == SEARCHTYPE_CHANNEL) {
+ if (ctx->searchcmd == reg_chansearch) {
for (i=0;i<CHANNELHASHSIZE;i++) {
for (cip=chantable[i];cip;cip=ncip) {
ncip = cip->next;
ctx->reply(senderNSExtern, "Warning: your pattern matched privileged users (%d in total) - these have not been touched.", safe);
/* notify opers of the action */
ctx->wall(NL_GLINES, "%s/%s glined %d %s via %s for %s [%d untouched].", senderNSExtern->nick, senderNSExtern->authname, (localdata->count - safe),
- (localdata->count - safe) != 1 ? "users" : "user", (ctx->type == SEARCHTYPE_CHANNEL) ? "chansearch" : "nicksearch", longtoduration(localdata->duration, 1), safe);
+ (localdata->count - safe) != 1 ? "users" : "user", (ctx->searchcmd == reg_chansearch) ? "chansearch" : "nicksearch", longtoduration(localdata->duration, 1), safe);
free(localdata);
free(thenode);
}
struct searchNode *host_parse(searchCtx *ctx, int argc, char **argv) {
struct searchNode *thenode;
- if (ctx->type != SEARCHTYPE_NICK) {
- parseError = "host: this function is only valid for nick searches.";
- return NULL;
- }
-
if (!(thenode=(struct searchNode *)malloc(sizeof (struct searchNode)))) {
parseError = "malloc: could not allocate memory for this search.";
return NULL;
struct searchNode *hostmask_parse(searchCtx *ctx, int argc, char **argv) {
struct searchNode *thenode;
- if (ctx->type != SEARCHTYPE_NICK) {
- parseError = "hostmask: this function is only valid for nick searches.";
- return NULL;
- }
-
if (!(thenode=(struct searchNode *)malloc(sizeof (struct searchNode)))) {
parseError = "malloc: could not allocate memory for this search.";
return NULL;
struct searchNode *hostpct_parse(searchCtx *ctx, int argc, char **argv) {
struct searchNode *thenode;
- if (ctx->type != SEARCHTYPE_CHANNEL) {
- parseError = "uniquehostpct: this function is only valid for channel searches.";
- return NULL;
- }
-
if (!(thenode=(struct searchNode *)malloc(sizeof(struct searchNode)))) {
/* couldn't malloc() memory for thenode, so free localdata to avoid leakage */
parseError = "malloc: could not allocate memory for this search.";
struct searchNode *ident_parse(searchCtx *ctx, int argc, char **argv) {
struct searchNode *thenode;
- if (ctx->type != SEARCHTYPE_NICK) {
- parseError = "ident: this function is only valid for nick searches.";
- return NULL;
- }
-
if (!(thenode=(struct searchNode *)malloc(sizeof (struct searchNode)))) {
parseError = "malloc: could not allocate memory for this search.";
return NULL;
struct searchNode *ip_parse(searchCtx *ctx, int argc, char **argv) {
struct searchNode *thenode;
- if (ctx->type != SEARCHTYPE_NICK) {
- parseError = "ip: this function is only valid for nick searches.";
- return NULL;
- }
-
if (!(thenode=(struct searchNode *)malloc(sizeof (struct searchNode)))) {
parseError = "malloc: could not allocate memory for this search.";
return NULL;
struct searchNode *thenode;
nick *np;
- if (ctx->type!=SEARCHTYPE_CHANNEL) {
- parseError="kick: only channel searches are supported";
- return NULL;
- }
-
if (argc!=1) {
parseError="kick: usage: (kick target)";
return NULL;
return NULL;
}
localdata->count = 0;
- if (ctx->type == SEARCHTYPE_CHANNEL)
+ if (ctx->searchcmd == reg_chansearch)
localdata->marker = nextchanmarker();
- else
+ else if (ctx->searchcmd == reg_nicksearch)
localdata->marker = nextnickmarker();
+ else {
+ parseError = "kill: invalid search type";
+ return NULL;
+ }
if (argc==1) {
char *p = argv[0];
localdata = thenode->localdata;
- if (ctx->type == SEARCHTYPE_CHANNEL) {
+ if (ctx->searchcmd == reg_chansearch) {
cip = (chanindex *)theinput;
cip->marker = localdata->marker;
localdata->count += cip->channel->users->totalusers;
- }
- else {
+ } else {
np = (nick *)theinput;
np->marker = localdata->marker;
localdata->count++;
}
/* For channel searches, mark up all the nicks in the relevant channels first */
- if (ctx->type == SEARCHTYPE_CHANNEL) {
+ if (ctx->searchcmd == reg_chansearch) {
nickmarker=nextnickmarker();
for (i=0;i<CHANNELHASHSIZE;i++) {
for (cip=chantable[i];cip;cip=cip->next) {
ctx->reply(senderNSExtern, "Warning: your pattern matched privileged users (%d in total) - these have not been touched.", safe);
/* notify opers of the action */
ctx->wall(NL_KICKKILLS, "%s/%s killed %d %s via %s [%d untouched].", senderNSExtern->nick, senderNSExtern->authname, (localdata->count - safe),
- (localdata->count - safe) != 1 ? "users" : "user", (ctx->type == SEARCHTYPE_CHANNEL) ? "chansearch" : "nicksearch", safe);
+ (localdata->count - safe) != 1 ? "users" : "user", (ctx->searchcmd == reg_chansearch) ? "chansearch" : "nicksearch", safe);
free(localdata);
free(thenode);
}
return NULL;
}
- switch (ctx->type) {
- case SEARCHTYPE_CHANNEL:
+ if (ctx->searchcmd == reg_chansearch) {
flaglist=cmodeflags;
- break;
-
- case SEARCHTYPE_NICK:
+ } else if (ctx->searchcmd == reg_nicksearch) {
flaglist=umodeflags;
- break;
-
- default:
+ } else {
parseError="modes: unsupported search type";
return NULL;
}
localdata = (struct modes_localdata *)thenode->localdata;
- switch (ctx->type) {
- case SEARCHTYPE_CHANNEL:
+ if (ctx->searchcmd == reg_chansearch) {
cip=(chanindex *)value;
if (!cip->channel)
return NULL;
flags=cip->channel->flags;
- break;
-
- case SEARCHTYPE_NICK:
+ } else if (ctx->searchcmd == reg_nicksearch) {
np=(nick *)value;
flags=np->umodes;
- break;
-
- default:
+ } else {
return NULL;
}
struct searchNode *name_parse(searchCtx *ctx, int argc, char **argv) {
struct searchNode *thenode;
- if (ctx->type != SEARCHTYPE_CHANNEL) {
- parseError = "name: this function is only valid for channel searches.";
- return NULL;
- }
-
if (!(thenode=(struct searchNode *)malloc(sizeof(struct searchNode)))) {
/* couldn't malloc() memory for thenode, so free localdata to avoid leakage */
parseError = "malloc: could not allocate memory for this search.";
return NULL;
}
- switch (ctx->type) {
- case SEARCHTYPE_CHANNEL:
+ if (ctx->searchcmd == reg_chansearch) {
if (argc!=1) {
parseError="nick: usage: (nick target)";
free(localdata);
free(localdata);
return NULL;
}
- break;
-
- case SEARCHTYPE_NICK:
+ } else if (ctx->searchcmd == reg_nicksearch) {
if (argc) {
parseError="nick: usage: (match (nick) target)";
free(localdata);
return NULL;
}
localdata->np = NULL;
- break;
-
- default:
- parseError="nick: unsupported search type";
+ } else {
+ parseError="nick: invalid search command";
free(localdata);
return NULL;
}
return NULL;
}
- if (ctx->type == SEARCHTYPE_CHANNEL)
+ if (ctx->searchcmd == reg_chansearch)
thenode->returntype = RETURNTYPE_BOOL;
else
thenode->returntype = RETURNTYPE_STRING;
localdata = thenode->localdata;
- switch (ctx->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;
return NULL;
}
localdata->count = 0;
- if (ctx->type == SEARCHTYPE_CHANNEL)
+ if (ctx->searchcmd == reg_chansearch)
localdata->marker = nextchanmarker();
- else
+ else if (ctx->searchcmd == reg_nicksearch)
localdata->marker = nextnickmarker();
-
+ else {
+ parseError = "notice: invalid search type";
+ return NULL;
+ }
if (argc==1) {
char *p = argv[0];
if(*p == '\"')
localdata = thenode->localdata;
- if (ctx->type == SEARCHTYPE_CHANNEL) {
+ if (ctx->searchcmd == reg_chansearch) {
cip = (chanindex *)theinput;
cip->marker = localdata->marker;
localdata->count += cip->channel->users->totalusers;
localdata = thenode->localdata;
- if (ctx->type == SEARCHTYPE_CHANNEL) {
+ if (ctx->searchcmd == reg_chansearch) {
nickmarker=nextnickmarker();
for (i=0;i<CHANNELHASHSIZE;i++) {
for (cip=chantable[i];cip;cip=ncip) {
struct searchNode *oppct_parse(searchCtx *ctx, int argc, char **argv) {
struct searchNode *thenode;
- if (ctx->type != SEARCHTYPE_CHANNEL) {
- parseError = "oppct: this function is only valid for channel searches.";
- return NULL;
- }
-
if (!(thenode=(struct searchNode *)malloc(sizeof(struct searchNode)))) {
/* couldn't malloc() memory for thenode, so free localdata to avoid leakage */
parseError = "malloc: could not allocate memory for this search.";
struct searchNode *realname_parse(searchCtx *ctx, int argc, char **argv) {
struct searchNode *thenode;
- if (ctx->type != SEARCHTYPE_NICK) {
- parseError = "realname: this function is only valid for nick searches.";
- return NULL;
- }
-
if (!(thenode=(struct searchNode *)malloc(sizeof (struct searchNode)))) {
parseError = "malloc: could not allocate memory for this search.";
return NULL;
int i;
long numeric;
- if (ctx->type != SEARCHTYPE_NICK) {
- parseError = "server: this function is only valid for nick searches.";
- return NULL;
- }
-
if (!(thenode=(struct searchNode *)malloc(sizeof (struct searchNode)))) {
parseError = "malloc: could not allocate memory for this search.";
return NULL;
struct searchNode *services_parse(searchCtx *ctx, int argc, char **argv) {
struct searchNode *thenode;
- if (ctx->type != SEARCHTYPE_CHANNEL) {
- parseError = "services: this function is only valid for channel searches.";
- return NULL;
- }
-
if (!(thenode=(struct searchNode *)malloc(sizeof(struct searchNode)))) {
/* couldn't malloc() memory for thenode, so free localdata to avoid leakage */
parseError = "malloc: could not allocate memory for this search.";
struct searchNode *size_parse(searchCtx *ctx, int argc, char **argv) {
struct searchNode *thenode;
- if (ctx->type != SEARCHTYPE_CHANNEL) {
- parseError = "size: this function is only valid for channel searches.";
- return NULL;
- }
-
if (!(thenode=(struct searchNode *)malloc(sizeof(struct searchNode)))) {
/* couldn't malloc() memory for thenode, so free localdata to avoid leakage */
parseError = "malloc: could not allocate memory for this search.";
struct searchNode *timestamp_parse(searchCtx *ctx, int argc, char **argv) {
struct searchNode *thenode;
- if (ctx->type != SEARCHTYPE_NICK) {
- parseError = "timestamp: this function is only valid for nick searches.";
- return NULL;
- }
-
if (!(thenode=(struct searchNode *)malloc(sizeof (struct searchNode)))) {
parseError = "malloc: could not allocate memory for this search.";
return NULL;
struct searchNode *topic_parse(searchCtx *ctx, int argc, char **argv) {
struct searchNode *thenode;
- if (ctx->type != SEARCHTYPE_CHANNEL) {
- parseError = "topic: this function is only valid for channel searches.";
- return NULL;
- }
-
if (!(thenode=(struct searchNode *)malloc(sizeof(struct searchNode)))) {
/* couldn't malloc() memory for thenode, so free localdata to avoid leakage */
parseError = "malloc: could not allocate memory for this search.";