From: Paul Date: Tue, 12 Aug 2008 19:16:17 +0000 (+0100) Subject: newsearch changes to support addition of trust_search/patriciasearch X-Git-Url: https://jfr.im/git/irc/quakenet/newserv.git/commitdiff_plain/a92bb8e10d7efcc0f34df2467cea4252400c9ce4 newsearch changes to support addition of trust_search/patriciasearch --- diff --git a/chanserv/newsearch/chanserv_newsearch.c b/chanserv/newsearch/chanserv_newsearch.c index eb02b0aa..cd9b1e06 100644 --- a/chanserv/newsearch/chanserv_newsearch.c +++ b/chanserv/newsearch/chanserv_newsearch.c @@ -10,17 +10,17 @@ int cs_dospewdb(void *source, int cargc, char **cargv); 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.", ""); @@ -33,17 +33,17 @@ void _init() { } 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); diff --git a/chanserv/newsearch/chanserv_newsearch.h b/chanserv/newsearch/chanserv_newsearch.h index ba204455..27ffc04f 100644 --- a/chanserv/newsearch/chanserv_newsearch.h +++ b/chanserv/newsearch/chanserv_newsearch.h @@ -8,11 +8,11 @@ void printnick_authchans(searchCtx *, nick *, nick *); 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 diff --git a/chanserv/newsearch/csns-qchanflags.c b/chanserv/newsearch/csns-qchanflags.c index b14bd812..4f8ce610 100644 --- a/chanserv/newsearch/csns-qchanflags.c +++ b/chanserv/newsearch/csns-qchanflags.c @@ -17,15 +17,10 @@ struct qchanflags_localdata { 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; diff --git a/chanserv/newsearch/csns-qemail.c b/chanserv/newsearch/csns-qemail.c index 6db9fea5..ef451abd 100644 --- a/chanserv/newsearch/csns-qemail.c +++ b/chanserv/newsearch/csns-qemail.c @@ -10,14 +10,9 @@ 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; diff --git a/chanserv/newsearch/csns-qlasthost.c b/chanserv/newsearch/csns-qlasthost.c index 0aba8452..6e300ad2 100644 --- a/chanserv/newsearch/csns-qlasthost.c +++ b/chanserv/newsearch/csns-qlasthost.c @@ -10,14 +10,9 @@ 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; diff --git a/chanserv/newsearch/csns-qsuspendreason.c b/chanserv/newsearch/csns-qsuspendreason.c index 127d1472..faffbbd8 100644 --- a/chanserv/newsearch/csns-qsuspendreason.c +++ b/chanserv/newsearch/csns-qsuspendreason.c @@ -10,14 +10,9 @@ 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; diff --git a/chanserv/newsearch/csns-qusername.c b/chanserv/newsearch/csns-qusername.c index 83f0f8e1..3551b124 100644 --- a/chanserv/newsearch/csns-qusername.c +++ b/chanserv/newsearch/csns-qusername.c @@ -10,14 +10,9 @@ 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; diff --git a/chanserv/newsearch/csns-qusers.c b/chanserv/newsearch/csns-qusers.c index ddf05666..92843d27 100644 --- a/chanserv/newsearch/csns-qusers.c +++ b/chanserv/newsearch/csns-qusers.c @@ -17,15 +17,10 @@ struct qusers_localdata { 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; diff --git a/newsearch/newsearch.c b/newsearch/newsearch.c index 6726213c..a0b276f6 100644 --- a/newsearch/newsearch.c +++ b/newsearch/newsearch.c @@ -1,7 +1,6 @@ #include #include #include -#include "newsearch.h" #include "../irc/irc_config.h" #include "../lib/irc_string.h" @@ -11,13 +10,13 @@ #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); @@ -32,137 +31,230 @@ UserDisplayFunc defaultuserfn = printuser; 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: 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 \nSearches for nicknames with the given criteria."); - registercontrolhelpcmd("chansearch",NO_OPER,4,do_chansearch, "Usage: chansearch \nSearches for channels with the given criteria."); - registercontrolhelpcmd("usersearch",NO_OPER,4,do_usersearch, "Usage: usersearch \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;ihandler, 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;ihandler,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;ihandler, 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, ...) { @@ -175,10 +267,11 @@ 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)++; @@ -198,7 +291,7 @@ static int parseopts(int cargc, char **cargv, int *arg, int *limit, void **displ 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; @@ -206,6 +299,19 @@ static int parseopts(int cargc, char **cargv, int *arg, int *limit, void **displ *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); @@ -216,14 +322,14 @@ static int parseopts(int cargc, char **cargv, int *arg, int *limit, void **displ 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) { @@ -238,7 +344,7 @@ int do_nicksearch_real(replyFunc reply, wallFunc wall, void *source, int cargc, 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; @@ -251,7 +357,7 @@ int do_nicksearch_real(replyFunc reply, wallFunc wall, void *source, int cargc, 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); @@ -325,7 +431,7 @@ int do_chansearch_real(replyFunc reply, wallFunc wall, void *source, int cargc, 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; @@ -338,7 +444,7 @@ int do_chansearch_real(replyFunc reply, wallFunc wall, void *source, int cargc, 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; @@ -390,7 +496,7 @@ int do_usersearch_real(replyFunc reply, wallFunc wall, void *source, int cargc, 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; @@ -403,7 +509,7 @@ int do_usersearch_real(replyFunc reply, wallFunc wall, void *source, int cargc, 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; @@ -751,7 +857,7 @@ struct searchNode *search_parse(searchCtx *ctx, char *input) { 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 { diff --git a/newsearch/newsearch.h b/newsearch/newsearch.h index 7ab3a6d5..99fb0fb0 100644 --- a/newsearch/newsearch.h +++ b/newsearch/newsearch.h @@ -1,27 +1,21 @@ #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 @@ -69,6 +63,20 @@ struct searchVariable { 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; @@ -76,7 +84,7 @@ typedef struct searchCtx { void *arg; struct searchVariable vars[MAX_VARIABLES]; int lastvar; - int type; + struct searchCmd *searchcmd; } searchCtx; /* Core functions */ @@ -149,14 +157,14 @@ struct searchNode *channeliter_parse(searchCtx *ctx, int argc, char **argv); 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 *); @@ -182,7 +190,7 @@ struct searchVariable *var_register(searchCtx *ctx, char *arg, int type); 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 */ @@ -228,10 +236,16 @@ int ast_nicksearch(searchASTExpr *tree, replyFunc reply, void *sender, wallFunc 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; diff --git a/newsearch/newsearch_ast.c b/newsearch/newsearch_ast.c index e0712994..5925d447 100644 --- a/newsearch/newsearch_ast.c +++ b/newsearch/newsearch_ast.c @@ -142,10 +142,10 @@ int ast_nicksearch(searchASTExpr *tree, replyFunc reply, void *sender, wallFunc 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); @@ -168,10 +168,10 @@ int ast_chansearch(searchASTExpr *tree, replyFunc reply, void *sender, wallFunc 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); @@ -197,10 +197,10 @@ int ast_usersearch(searchASTExpr *tree, replyFunc reply, void *sender, wallFunc 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); @@ -219,11 +219,11 @@ int ast_usersearch(searchASTExpr *tree, replyFunc reply, void *sender, wallFunc /* 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); @@ -234,7 +234,7 @@ static char *ast_printtree_real(StringBuf *buf, searchASTExpr *expr) { for(i=0;iu.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, ')'); @@ -247,7 +247,7 @@ static char *ast_printtree_real(StringBuf *buf, searchASTExpr *expr) { 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; @@ -255,7 +255,7 @@ char *ast_printtree(char *buf, size_t bufsize, searchASTExpr *expr) { b.len = 0; b.buf = buf; - p = ast_printtree_real(&b, expr); + p = ast_printtree_real(&b, expr, cmd); sbterminate(&b); return p; diff --git a/newsearch/ns-authedpct.c b/newsearch/ns-authedpct.c index ebbf8a94..8558e9ad 100644 --- a/newsearch/ns-authedpct.c +++ b/newsearch/ns-authedpct.c @@ -13,11 +13,6 @@ void authedpct_free(searchCtx *ctx, struct searchNode *thenode); 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."; diff --git a/newsearch/ns-authid.c b/newsearch/ns-authid.c index 98a0973c..184a4a95 100644 --- a/newsearch/ns-authid.c +++ b/newsearch/ns-authid.c @@ -13,11 +13,6 @@ void authid_free(searchCtx *ctx, struct searchNode *thenode); 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; diff --git a/newsearch/ns-authname.c b/newsearch/ns-authname.c index 1d4aaf01..f1e299b3 100644 --- a/newsearch/ns-authname.c +++ b/newsearch/ns-authname.c @@ -13,11 +13,6 @@ void authname_free(searchCtx *ctx, struct searchNode *thenode); 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; diff --git a/newsearch/ns-authts.c b/newsearch/ns-authts.c index 7ef8e704..5551d5ab 100644 --- a/newsearch/ns-authts.c +++ b/newsearch/ns-authts.c @@ -13,11 +13,6 @@ void authts_free(searchCtx *ctx, struct searchNode *thenode); 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; diff --git a/newsearch/ns-channel.c b/newsearch/ns-channel.c index 9395ba47..884ff6a3 100644 --- a/newsearch/ns-channel.c +++ b/newsearch/ns-channel.c @@ -16,11 +16,6 @@ struct searchNode *channel_parse(searchCtx *ctx, int argc, char **argv) { 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 "; return NULL; diff --git a/newsearch/ns-channeliter.c b/newsearch/ns-channeliter.c index b1d47cac..245847f2 100644 --- a/newsearch/ns-channeliter.c +++ b/newsearch/ns-channeliter.c @@ -27,11 +27,6 @@ struct searchNode *channeliter_parse(searchCtx *ctx, int argc, char **argv) { 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; diff --git a/newsearch/ns-channels.c b/newsearch/ns-channels.c index 8627eddb..1e116474 100644 --- a/newsearch/ns-channels.c +++ b/newsearch/ns-channels.c @@ -16,11 +16,6 @@ void channels_free(searchCtx *ctx, struct searchNode *thenode); 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; diff --git a/newsearch/ns-country.c b/newsearch/ns-country.c index 7bdb1571..57f2a0ed 100644 --- a/newsearch/ns-country.c +++ b/newsearch/ns-country.c @@ -22,11 +22,6 @@ struct searchNode *country_parse(searchCtx *ctx, int argc, char **argv) { 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 "; return NULL; diff --git a/newsearch/ns-exists.c b/newsearch/ns-exists.c index ad1fe4be..63d66134 100644 --- a/newsearch/ns-exists.c +++ b/newsearch/ns-exists.c @@ -13,11 +13,6 @@ void exists_free(searchCtx *ctx, struct searchNode *thenode); 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; diff --git a/newsearch/ns-gline.c b/newsearch/ns-gline.c index 8735dc6b..a5f2f027 100644 --- a/newsearch/ns-gline.c +++ b/newsearch/ns-gline.c @@ -39,10 +39,14 @@ struct searchNode *gline_parse(searchCtx *ctx, int argc, char **argv) { 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: @@ -118,7 +122,7 @@ void *gline_exe(searchCtx *ctx, struct searchNode *thenode, void *theinput) { 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; @@ -150,7 +154,7 @@ void gline_free(searchCtx *ctx, struct searchNode *thenode) { return; } - if (ctx->type == SEARCHTYPE_CHANNEL) { + if (ctx->searchcmd == reg_chansearch) { for (i=0;inext; @@ -197,7 +201,7 @@ void gline_free(searchCtx *ctx, struct searchNode *thenode) { 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); } diff --git a/newsearch/ns-host.c b/newsearch/ns-host.c index ab9318d3..2dd5bf3e 100644 --- a/newsearch/ns-host.c +++ b/newsearch/ns-host.c @@ -17,11 +17,6 @@ void host_free(searchCtx *ctx, struct searchNode *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; diff --git a/newsearch/ns-hostmask.c b/newsearch/ns-hostmask.c index ae4f5492..85dd9c07 100644 --- a/newsearch/ns-hostmask.c +++ b/newsearch/ns-hostmask.c @@ -17,11 +17,6 @@ void hostmask_free(searchCtx *ctx, struct searchNode *thenode); 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; diff --git a/newsearch/ns-hostpct.c b/newsearch/ns-hostpct.c index 45676afb..ca87951a 100644 --- a/newsearch/ns-hostpct.c +++ b/newsearch/ns-hostpct.c @@ -13,11 +13,6 @@ void hostpct_free(searchCtx *ctx, struct searchNode *thenode); 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."; diff --git a/newsearch/ns-ident.c b/newsearch/ns-ident.c index 14c4fa2a..825988cd 100644 --- a/newsearch/ns-ident.c +++ b/newsearch/ns-ident.c @@ -13,11 +13,6 @@ void ident_free(searchCtx *ctx, struct searchNode *thenode); 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; diff --git a/newsearch/ns-ip.c b/newsearch/ns-ip.c index 1b657c64..16c4d900 100644 --- a/newsearch/ns-ip.c +++ b/newsearch/ns-ip.c @@ -13,11 +13,6 @@ void ip_free(searchCtx *ctx, struct searchNode *thenode); 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; diff --git a/newsearch/ns-kick.c b/newsearch/ns-kick.c index 7db84c61..bdd0839c 100644 --- a/newsearch/ns-kick.c +++ b/newsearch/ns-kick.c @@ -15,11 +15,6 @@ struct searchNode *kick_parse(searchCtx *ctx, int argc, char **argv) { 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; diff --git a/newsearch/ns-kill.c b/newsearch/ns-kill.c index 6f8b474c..1b7aadd4 100644 --- a/newsearch/ns-kill.c +++ b/newsearch/ns-kill.c @@ -36,10 +36,14 @@ struct searchNode *kill_parse(searchCtx *ctx, int argc, char **argv) { 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]; @@ -77,12 +81,11 @@ void *kill_exe(searchCtx *ctx, struct searchNode *thenode, void *theinput) { 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++; @@ -110,7 +113,7 @@ void kill_free(searchCtx *ctx, struct searchNode *thenode) { } /* 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;inext) { @@ -154,7 +157,7 @@ void kill_free(searchCtx *ctx, struct searchNode *thenode) { 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); } diff --git a/newsearch/ns-modes.c b/newsearch/ns-modes.c index e676ae10..48042917 100644 --- a/newsearch/ns-modes.c +++ b/newsearch/ns-modes.c @@ -25,16 +25,11 @@ struct searchNode *modes_parse(searchCtx *ctx, int argc, char **argv) { 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; } @@ -75,20 +70,15 @@ void *modes_exe(searchCtx *ctx, struct searchNode *thenode, void *value) { 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; } diff --git a/newsearch/ns-name.c b/newsearch/ns-name.c index b287f981..2b5abc49 100644 --- a/newsearch/ns-name.c +++ b/newsearch/ns-name.c @@ -13,11 +13,6 @@ void name_free(searchCtx *ctx, struct searchNode *thenode); 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."; diff --git a/newsearch/ns-nick.c b/newsearch/ns-nick.c index 60505adf..55538731 100644 --- a/newsearch/ns-nick.c +++ b/newsearch/ns-nick.c @@ -23,8 +23,7 @@ struct searchNode *nick_parse(searchCtx *ctx, int argc, char **argv) { return NULL; } - switch (ctx->type) { - case SEARCHTYPE_CHANNEL: + if (ctx->searchcmd == reg_chansearch) { if (argc!=1) { parseError="nick: usage: (nick target)"; free(localdata); @@ -35,19 +34,15 @@ struct searchNode *nick_parse(searchCtx *ctx, int argc, char **argv) { 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; } @@ -59,7 +54,7 @@ struct searchNode *nick_parse(searchCtx *ctx, int argc, char **argv) { return NULL; } - if (ctx->type == SEARCHTYPE_CHANNEL) + if (ctx->searchcmd == reg_chansearch) thenode->returntype = RETURNTYPE_BOOL; else thenode->returntype = RETURNTYPE_STRING; @@ -77,17 +72,14 @@ void *nick_exe(searchCtx *ctx, struct searchNode *thenode, void *theinput) { 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; diff --git a/newsearch/ns-notice.c b/newsearch/ns-notice.c index 5adeeb77..543fcd7f 100644 --- a/newsearch/ns-notice.c +++ b/newsearch/ns-notice.c @@ -35,11 +35,14 @@ struct searchNode *notice_parse(searchCtx *ctx, int argc, char **argv) { 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 == '\"') @@ -80,7 +83,7 @@ void *notice_exe(searchCtx *ctx, struct searchNode *thenode, void *theinput) { 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; @@ -103,7 +106,7 @@ void notice_free(searchCtx *ctx, struct searchNode *thenode) { localdata = thenode->localdata; - if (ctx->type == SEARCHTYPE_CHANNEL) { + if (ctx->searchcmd == reg_chansearch) { nickmarker=nextnickmarker(); for (i=0;itype != 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."; diff --git a/newsearch/ns-realname.c b/newsearch/ns-realname.c index 6dbb9117..e5582444 100644 --- a/newsearch/ns-realname.c +++ b/newsearch/ns-realname.c @@ -13,11 +13,6 @@ void realname_free(searchCtx *ctx, struct searchNode *thenode); 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; diff --git a/newsearch/ns-server.c b/newsearch/ns-server.c index f6c6b55a..4683b4a8 100644 --- a/newsearch/ns-server.c +++ b/newsearch/ns-server.c @@ -24,11 +24,6 @@ struct searchNode *server_parse(searchCtx *ctx, int argc, char **argv) { 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; diff --git a/newsearch/ns-services.c b/newsearch/ns-services.c index 9cf3d009..5a30bbff 100644 --- a/newsearch/ns-services.c +++ b/newsearch/ns-services.c @@ -13,11 +13,6 @@ void services_free(searchCtx *ctx, struct searchNode *thenode); 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."; diff --git a/newsearch/ns-size.c b/newsearch/ns-size.c index c66ebc6a..12e5acbd 100644 --- a/newsearch/ns-size.c +++ b/newsearch/ns-size.c @@ -13,11 +13,6 @@ void size_free(searchCtx *ctx, struct searchNode *thenode); 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."; diff --git a/newsearch/ns-timestamp.c b/newsearch/ns-timestamp.c index 3344c85d..8cc070d9 100644 --- a/newsearch/ns-timestamp.c +++ b/newsearch/ns-timestamp.c @@ -16,11 +16,6 @@ void timestamp_free(searchCtx *ctx, struct searchNode *thenode); 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; diff --git a/newsearch/ns-topic.c b/newsearch/ns-topic.c index 9260af3e..4bb44f5c 100644 --- a/newsearch/ns-topic.c +++ b/newsearch/ns-topic.c @@ -13,11 +13,6 @@ void topic_free(searchCtx *ctx, struct searchNode *thenode); 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.";