]> jfr.im git - irc/quakenet/newserv.git/commitdiff
Remove old newsearch parser.
authorGunnar Beutner <redacted>
Wed, 31 Jul 2013 14:32:12 +0000 (16:32 +0200)
committerGunnar Beutner <redacted>
Wed, 31 Jul 2013 14:32:12 +0000 (16:32 +0200)
newsearch/Makefile
newsearch/newsearch.c
newsearch/newsearch.h
patriciasearch/patriciasearch.c

index 02b2101f9852bd1a744ad8dbc1994ab73e34b368..7ec0f9dc066d85fb76d3f832e181d0f96dc23867 100644 (file)
@@ -8,12 +8,7 @@ all: newsearch.so
 
 NSCOMMANDS=ns-not.o ns-and.o ns-or.o ns-eq.o ns-match.o ns-hostmask.o ns-realname.o ns-away.o ns-modes.o ns-nick.o ns-ident.o ns-regex.o ns-host.o ns-channel.o ns-lt.o ns-gt.o ns-timestamp.o ns-country.o ns-authname.o ns-ip.o ns-kill.o ns-gline.o ns-exists.o ns-services.o ns-size.o ns-name.o ns-topic.o ns-oppct.o ns-cumodecount.o ns-cumodepct.o ns-hostpct.o ns-authedpct.o ns-length.o ns-kick.o ns-authts.o ns-channels.o ns-server.o ns-authid.o ns-notice.o newsearch_ast.o ns-any.o ns-channeliter.o ns-var.o ns-all.o ns-cumodes.o ns-cidr.o ns-nickiter.o ns-ipv6.o ns-away.o
 
-ifeq (${NEWSEARCH_NEWPARSER},1)
-CFLAGS+=-DNEWSEARCH_NEWPARSER=1
 newsearch.so: newsearch.o formats.o y.tab.o lex.yy.o parser.o ${NSCOMMANDS}
-else
-newsearch.so: newsearch.o formats.o ${NSCOMMANDS}
-endif
 
 y.tab.c y.tab.h: newsearch.y
        ${YACC} -d newsearch.y
index d4531b4c12306f7561e761f324c3d6320c1d40a4..bca5b6e2a08d82d45fe5ed691338eda6d517a31c 100644 (file)
@@ -445,12 +445,7 @@ int do_nicksearch_real(replyFunc reply, wallFunc wall, void *source, int cargc,
   int arg=0;
   NickDisplayFunc display=defaultnickfn;
   int ret;
-#ifndef NEWSEARCH_NEWPARSER
-  searchCtx ctx;
-  struct searchNode *search;
-#else
   parsertree *tree;
-#endif
 
   if (cargc<1) {
     reply( sender, "Usage: [flags] <criteria>");
@@ -471,17 +466,6 @@ int do_nicksearch_real(replyFunc reply, wallFunc wall, void *source, int cargc,
     rejoinline(cargv[arg],cargc-arg);
   }
 
-#ifndef NEWSEARCH_NEWPARSER
-  newsearch_ctxinit(&ctx, search_parse, reply, wall, NULL, reg_nicksearch, sender, display, limit);
-  if (!(search = ctx.parser(&ctx, cargv[arg]))) {
-    reply(sender,"Parse error: %s",parseError);
-    return CMD_ERROR;
-  }
-
-  nicksearch_exe(search, &ctx);
-
-  (search->free)(&ctx, search);
-#else
   tree = parse_string(reg_nicksearch, cargv[arg]);
   if(!tree) {
     displaystrerror(reply, sender, cargv[arg]);
@@ -491,7 +475,6 @@ int do_nicksearch_real(replyFunc reply, wallFunc wall, void *source, int cargc,
   ast_nicksearch(tree->root, reply, sender, wall, display, NULL, NULL, limit);
 
   parse_free(tree);
-#endif
 
   return CMD_OK;
 }
@@ -552,12 +535,7 @@ int do_chansearch_real(replyFunc reply, wallFunc wall, void *source, int cargc,
   int arg=0;
   ChanDisplayFunc display=defaultchanfn;
   int ret;
-#ifndef NEWSEARCH_NEWPARSER
-  struct searchNode *search;
-  searchCtx ctx;
-#else
   parsertree *tree;
-#endif
 
   if (cargc<1) {
     reply( sender, "Usage: [flags] <criteria>");
@@ -578,17 +556,6 @@ int do_chansearch_real(replyFunc reply, wallFunc wall, void *source, int cargc,
     rejoinline(cargv[arg],cargc-arg);
   }
 
-#ifndef NEWSEARCH_NEWPARSER
-  newsearch_ctxinit(&ctx, search_parse, reply, wall, NULL, reg_chansearch, sender, display, limit);
-  if (!(search = ctx.parser(&ctx, cargv[arg]))) {
-    reply(sender,"Parse error: %s",parseError);
-    return CMD_ERROR;
-  }
-
-  chansearch_exe(search, &ctx);
-
-  (search->free)(&ctx, search);
-#else
   tree = parse_string(reg_chansearch, cargv[arg]);
   if(!tree) {
     displaystrerror(reply, sender, cargv[arg]);
@@ -598,7 +565,6 @@ int do_chansearch_real(replyFunc reply, wallFunc wall, void *source, int cargc,
   ast_chansearch(tree->root, reply, sender, wall, display, NULL, NULL, limit);
 
   parse_free(tree);
-#endif
 
   return CMD_OK;
 }
@@ -639,12 +605,7 @@ int do_usersearch_real(replyFunc reply, wallFunc wall, void *source, int cargc,
   int arg=0;
   UserDisplayFunc display=defaultuserfn;
   int ret;
-#ifndef NEWSEARCH_NEWPARSER
-  struct searchNode *search;
-  searchCtx ctx;
-#else
   parsertree *tree;
-#endif
 
   if (cargc<1) {
     reply( sender, "Usage: [flags] <criteria>");
@@ -665,18 +626,6 @@ int do_usersearch_real(replyFunc reply, wallFunc wall, void *source, int cargc,
     rejoinline(cargv[arg],cargc-arg);
   }
 
-#ifndef NEWSEARCH_NEWPARSER
-  newsearch_ctxinit(&ctx, search_parse, reply, wall, NULL, reg_usersearch, sender, display, limit);
-
-  if (!(search = ctx.parser(&ctx, cargv[arg]))) {
-    reply(sender,"Parse error: %s",parseError);
-    return CMD_ERROR;
-  }
-
-  usersearch_exe(search, &ctx);
-
-  (search->free)(&ctx, search);
-#else
   tree = parse_string(reg_usersearch, cargv[arg]);
   if(!tree) {
     displaystrerror(reply, sender, cargv[arg]);
@@ -686,7 +635,6 @@ int do_usersearch_real(replyFunc reply, wallFunc wall, void *source, int cargc,
   ast_usersearch(tree->root, reply, sender, wall, display, NULL, NULL, limit);
 
   parse_free(tree);
-#endif
 
   return CMD_OK;
 }
@@ -946,172 +894,6 @@ void literal_free(searchCtx *ctx, struct searchNode *thenode) {
   free(thenode);
 }
 
-static int unescape(char *input, char *output, size_t buflen) {
-  char *ch, *ch2;
-  int e=0;
-  
-  if (*input=='\"') {
-    for (ch=input;*ch;ch++) {
-      if(ch - input >= buflen) {
-        parseError="Buffer overflow";
-        return 0;
-      }
-    }
-      
-    if (*(ch-1) != '\"') {
-      parseError="Quote mismatch";
-      return 0;
-    }
-
-    *(ch-1)='\0';
-    input++;
-  }
-    
-  ch2=output;
-  for (ch=input;*ch;ch++) {
-    if(ch - input >= buflen) {
-      parseError="Buffer overflow";
-      return 0;
-    }
-    
-    if (e) {
-      e=0;
-      *ch2++=*ch;
-    } else if (*ch=='\\') {
-      e=1;
-    } else {
-      *ch2++=*ch;
-    }
-  }
-  *ch2='\0';
-  
-  return 1;
-}
-
-struct searchNode *search_parse(searchCtx *ctx, char *cinput) {
-  /* OK, we need to split the input into chunks on spaces and brackets.. */
-  char *argvector[100];
-  char inputb[1024];
-  char *input;
-  char thestring[500];
-  int i,j,q=0,e=0;
-  char *ch;
-  struct Command *cmd;
-  struct searchNode *thenode;
-
-  strlcpy(inputb, cinput, sizeof(inputb));
-  input = inputb;
-  
-  /* If it starts with a bracket, it's a function call.. */
-  if (*input=='(') {
-    /* Skip past string */
-    for (ch=input;*ch;ch++);
-    if (*(ch-1) != ')') {
-      parseError = "Bracket mismatch!";
-      return NULL;
-    }
-    input++;
-    *(ch-1)='\0';
-
-    /* Split further args */
-    i=-1; /* i = -1 BoW, 0 = inword, 1 = bracket nest depth */
-    j=0;  /* j = current arg */
-    e=0;
-    q=0;
-    argvector[0]="";
-    for (ch=input;*ch;ch++) {
-      /*printf("i: %d j: %d e: %d q: %d ch: '%c'\n", i, j, e, q, *ch);*/
-      if (i==-1) {
-        argvector[j]=ch;
-        if (*ch=='(') {
-          i=1;
-        } else if (*ch != ' ') {
-          i=0;
-          if (*ch=='\\') {
-            e=1;
-          } else if (*ch=='\"') {
-            q=1;
-          }
-        }
-      } else if (e==1) {
-        e=0;
-      } else if (q==1) {
-        if (*ch=='\\')  {
-          e=1;
-        } else if (*ch=='\"')  {
-          q=0;
-        }
-      } else if (i==0) {
-        if (*ch=='\\') {
-          e=1;
-        } else if (*ch=='\"') {
-          q=1;
-        } else if (*ch==' ') {
-          *ch='\0';
-          j++;
-          if(j >= (sizeof(argvector) / sizeof(*argvector))) {
-            parseError = "Too many arguments";
-            return NULL;
-          }
-          i=-1;
-        }
-      } else {
-        if (*ch=='\\') {
-          e=1;
-        } else if (*ch=='\"') {
-          q=1;
-        } else if (*ch=='(') {
-          i++;
-        } else if (*ch==')') {
-          i--;
-        }
-      }
-    }
-    
-    if (i>0) {
-      parseError = "Bracket mismatch!";
-      return NULL;
-    }
-
-    if (*(ch-1) == 0) /* if the last character was a space */
-      j--; /* remove an argument */
-    
-/*    for(k=1;k<=j;k++)
-      if(!unescape(argvector[k], argvector[k], sizeof(inputb)))
-        return NULL;
-*/
-
-    if (!(cmd=findcommandintree(ctx->searchcmd->searchtree,argvector[0],1))) {
-      parseError = "Unknown command (for valid command list, see help <searchcmd>)";
-      return NULL;
-    } else {
-      if (!controlpermitted(cmd->level, ctx->sender)) { 
-        parseError = "Access denied (for valid command list, see help <searchcmd>)";
-        return NULL;
-      }
-      return ((parseFunc)cmd->handler)(ctx, j, argvector+1);
-    }
-  } else {
-    /* Literal */
-    
-    /* slug: disabled now we unescape during the main parse stage */
-    if(!unescape(input, thestring, sizeof(thestring)))
-      return NULL;
-
-    if (!(thenode=(struct searchNode *)malloc(sizeof(struct searchNode)))) {
-      parseError = "malloc: could not allocate memory for this search.";
-      return NULL;
-    }
-
-    thenode->localdata  = getsstring(thestring,512);
-    thenode->returntype = RETURNTYPE_CONST | RETURNTYPE_STRING;
-    thenode->exe        = literal_exe;
-    thenode->free       = literal_free;
-
-    return thenode;
-  }    
-}
-
 void nssnprintf(char *buf, size_t size, const char *format, nick *np) {
   StringBuf b;
   const char *p;
@@ -1250,7 +1032,6 @@ void var_setstr(struct searchVariable *v, char *data) {
   v->cdata.u.stringbuf = data;
 }
 
-#ifdef NEWSEARCH_NEWPARSER
 void displaystrerror(replyFunc reply, nick *np, const char *input) {
   char buf[515];
 
@@ -1269,7 +1050,6 @@ void displaystrerror(replyFunc reply, nick *np, const char *input) {
 
   reply(np, "Parse error: %s", parseStrError);
 }
-#endif
 
 struct searchNode *argtoconststr(char *command, searchCtx *ctx, char *arg, char **p) {
   struct searchNode *c;
index 727886a00fdebf70a128e739faa880022e3952d9..9473864d945da6139b30f2e66c78cf58b9e12a99 100644 (file)
@@ -154,9 +154,6 @@ struct searchNode *hostpct_parse(searchCtx *ctx, int argc, char **argv);
 struct searchNode *authedpct_parse(searchCtx *ctx, int argc, char **argv);
 struct searchNode *kick_parse(searchCtx *ctx, int argc, char **argv);
 
-/* Interpret a string to give a node */
-struct searchNode *search_parse(searchCtx *ctx, char *input);
-
 /* Iteration functions */
 struct searchNode *any_parse(searchCtx *ctx, int argc, char **argv);
 struct searchNode *all_parse(searchCtx *ctx, int argc, char **argv);
index 5bccf563bd5ae5b0fe1cf4506affd59a5ac9f003..c9018c7928633fc5840a0a3528a6fd6e54738612 100644 (file)
@@ -74,11 +74,7 @@ int do_pnodesearch_real(replyFunc reply, wallFunc wall, void *source, int cargc,
 
   tree = parse_string(reg_nodesearch, cargv[arg]);
   if(!tree) {
-#ifdef NEWSEARCH_NEWPARSER
     displaystrerror(reply, sender, cargv[arg]);
-#else
-    reply(sender,"Something went wrong.");
-#endif
     return CMD_ERROR;
   }