]> jfr.im git - irc/quakenet/newserv.git/commitdiff
newsearch changes to support addition of trust_search/patriciasearch
authorPaul <redacted>
Tue, 12 Aug 2008 19:16:17 +0000 (20:16 +0100)
committerPaul <redacted>
Tue, 12 Aug 2008 19:16:17 +0000 (20:16 +0100)
39 files changed:
chanserv/newsearch/chanserv_newsearch.c
chanserv/newsearch/chanserv_newsearch.h
chanserv/newsearch/csns-qchanflags.c
chanserv/newsearch/csns-qemail.c
chanserv/newsearch/csns-qlasthost.c
chanserv/newsearch/csns-qsuspendreason.c
chanserv/newsearch/csns-qusername.c
chanserv/newsearch/csns-qusers.c
newsearch/newsearch.c
newsearch/newsearch.h
newsearch/newsearch_ast.c
newsearch/ns-authedpct.c
newsearch/ns-authid.c
newsearch/ns-authname.c
newsearch/ns-authts.c
newsearch/ns-channel.c
newsearch/ns-channeliter.c
newsearch/ns-channels.c
newsearch/ns-country.c
newsearch/ns-exists.c
newsearch/ns-gline.c
newsearch/ns-host.c
newsearch/ns-hostmask.c
newsearch/ns-hostpct.c
newsearch/ns-ident.c
newsearch/ns-ip.c
newsearch/ns-kick.c
newsearch/ns-kill.c
newsearch/ns-modes.c
newsearch/ns-name.c
newsearch/ns-nick.c
newsearch/ns-notice.c
newsearch/ns-oppct.c
newsearch/ns-realname.c
newsearch/ns-server.c
newsearch/ns-services.c
newsearch/ns-size.c
newsearch/ns-timestamp.c
newsearch/ns-topic.c

index eb02b0aaf8c46c537eec46f957ab85f85cf45569..cd9b1e06d10edb59793399855f3565c2a6aff68d 100644 (file)
@@ -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);
index ba2044551c15f38e143f4638bc8103e0c7fc3302..27ffc04fbcdad2a279639de7029233d68f818a86 100644 (file)
@@ -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
index b14bd8129b841b71fc26c1f6d71fa415a25b87a6..4f8ce6101ebaacefc57dc123976484305e25f06e 100644 (file)
@@ -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;
index 6db9fea5bfc840870ab2feda9488d941dd7eca27..ef451abd79f1d62cee9f4233c66a3699bfe0678e 100644 (file)
 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;
index 0aba845285ce2654193ccca4782ebabee3d81c23..6e300ad2552096ea8cbf67a8f6db81cc75792691 100644 (file)
 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;
index 127d147237accf586a463fc5dd3e29e7e313731d..faffbbd8247950b50ce502f0a84820addb2e6e3d 100644 (file)
 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;
index 83f0f8e1bc6d335f2280433cd3a9a33716b945a2..3551b1243d0de3b23a42c0476f29f13cee1c6f76 100644 (file)
 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;
index ddf0566696b67f4ace85a020125b1519ccee50cb..92843d273bcf6d18bc96595a8a70633441a23896 100644 (file)
@@ -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;
index 6726213ca5eaef2657cc805d3ec0622b76b0574f..a0b276f6737b3ee4a9f9cf21dbcfbd411e182e82 100644 (file)
@@ -1,7 +1,6 @@
 #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);
@@ -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: <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, ...) {
@@ -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 {
index 7ab3a6d5bda91dc506f675e5fccddd7d1da6bfe1..99fb0fb034cb8eaa25dcd268ace419b2e1ec327f 100644 (file)
@@ -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;
index e071299443822d3bd41b7332d8888479b81200de..5925d447f4fa4870434a073f6eafc7c4d66b91e1 100644 (file)
@@ -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;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, ')');
 
@@ -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;
index ebbf8a94fa201a1dd0504f66d5bc17d4d4227dd6..8558e9ad2832c57cdd20d949bbe3f39c5dd09bf0 100644 (file)
@@ -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.";
index 98a0973cbf0c489eb670d720003b8e3efda305d3..184a4a954b611a26c1b2c697a2f81a57a7ece116 100644 (file)
@@ -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;
index 1d4aaf01dc612a4d74201c3e579e6321e4bbb4c0..f1e299b383f48d77bc1f049bbd228cf938e2b49d 100644 (file)
@@ -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;
index 7ef8e7044d2e0000c987022e0774a8f501f80e9a..5551d5aba069209af11a79000d025ba865f3e457 100644 (file)
@@ -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;
index 9395ba475f0b3b1d2cc6fa2c7f29b1e7310fbb69..884ff6a32e0c7d964d6ca4f06d0523b24533b2c8 100644 (file)
@@ -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 <channel name>";
     return NULL;
index b1d47cac896309b7e2350eba6c9988b76c93d0de..245847f210bc0c7f21df464140b843a3aaba38e9 100644 (file)
@@ -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;
index 8627eddb958ca2eeea9507495b03c4fee5fe545e..1e116474f8a8c9dce171f35cebe2890bce3b2479 100644 (file)
@@ -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;
index 7bdb15719019fb6a5a4475a5cbf3f4f8c23bba67..57f2a0ed864418d74fcf61b4742f5191433516e4 100644 (file)
@@ -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 <country 2 character ISO code>";
     return NULL;
index ad1fe4befc4a8c039821bc81518d036c41b88f43..63d6613472144a47fed0a150ba5903e450c57a58 100644 (file)
@@ -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;
index 8735dc6bfb8bd0f557499da63ae3e05994e33a8c..a5f2f0279c0d3bed2d1c48c2112690b3277e5e9c 100644 (file)
@@ -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;i<CHANNELHASHSIZE;i++) {
       for (cip=chantable[i];cip;cip=ncip) {
         ncip = cip->next;
@@ -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);
 }
index ab9318d3794daaf39e94d6848870c2db228206ad..2dd5bf3e42708a266aacb4e84ec4d9521dfcf6a9 100644 (file)
@@ -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;
index ae4f5492a423ff3f853cc8f38d6936437757af1d..85dd9c079ecd71cf84c86d61c13dbce00b62a8ae 100644 (file)
@@ -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;
index 45676afbde43609548e7f76ceba195324749085f..ca87951ae07b34fb5608acab1245e9a2ec193b8a 100644 (file)
@@ -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.";
index 14c4fa2a52a0d89fa56458182e08cfd1b8e3e8ec..825988cda2641f0bd309580d54b4db40f3bb26c4 100644 (file)
@@ -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;
index 1b657c64430ef77a569ed8078b9878cf5b705392..16c4d90033390a21044f808d7d58fa9302c2519c 100644 (file)
@@ -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;
index 7db84c61e2a52121a3ddfc4fd858c3670b382cc4..bdd0839c5a1ccb834594e6e776c6170b2fb24c58 100644 (file)
@@ -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;
index 6f8b474c73b832b89e6462a7b6bb3171b8cf7bee..1b7aadd4f8b17f9bc5b934fc8faa70c1f0f137e6 100644 (file)
@@ -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;i<CHANNELHASHSIZE;i++) {
       for (cip=chantable[i];cip;cip=cip->next) {
@@ -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);
 }
index e676ae10cb9c1394a8ccc4b57f084557b88e4408..48042917614fe5d97b7608bb7f76f2fcfb7ed540 100644 (file)
@@ -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;
   }
 
index b287f981a6f48ebfe3d0ad4175cada3c0c49cf28..2b5abc49af0aafcc363565828ef2b39ae6b0c00f 100644 (file)
@@ -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.";
index 60505adf62313674b6a9e57642caf95cefc335b5..55538731d90ac8675a178a328e5605e11d18ddbe 100644 (file)
@@ -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;
index 5adeeb7707e4f16ed9b91c0df8ade247156ec048..543fcd7f9ddb53e23ec26d25a1a5838e91ab9f51 100644 (file)
@@ -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;i<CHANNELHASHSIZE;i++) {
       for (cip=chantable[i];cip;cip=ncip) {
index d1e0d353719a4a020e696d84db5bf5c405734cf4..0f835a85a16bfa3aaf7fb17343ff05af21a4baa7 100644 (file)
@@ -13,11 +13,6 @@ void oppct_free(searchCtx *ctx, struct searchNode *thenode);
 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.";
index 6dbb9117f9b56ecca176cc07739b5875bcca429f..e55824447100768bed5c9d63449908c84768f1a7 100644 (file)
@@ -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;
index f6c6b55a2d582a8665502942d7f71a2319242630..4683b4a8fad4356aaed1068442ce65681f2679f7 100644 (file)
@@ -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;
index 9cf3d0098dec157939fbb8201033166bfb794c09..5a30bbffbdac76d4f1acaf4a57657f3d4befabbe 100644 (file)
@@ -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.";
index c66ebc6a57e8fd39b9fecd321df0c803bcb28e03..12e5acbd1cef69c391a2de3cc3a8753761806a46 100644 (file)
@@ -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.";
index 3344c85d1afafd48aa0ce83ec46128c51a198532..8cc070d925488adca973b4ea62106afa3f84d7fa 100644 (file)
@@ -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;
index 9260af3e3a377f46b8296d28b5d38ac2c654ec2f..4bb44f5c72c4a64db6ad9cd95540b46efe209704 100644 (file)
@@ -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.";