]> jfr.im git - irc/quakenet/newserv.git/commitdiff
update patricia search for ast + add ipvsix command
authorPaul <redacted>
Thu, 25 Dec 2008 20:04:48 +0000 (20:04 +0000)
committerPaul <redacted>
Thu, 25 Dec 2008 20:04:48 +0000 (20:04 +0000)
patriciasearch/Makefile.in
patriciasearch/newsearch_ast.c [new file with mode: 0644]
patriciasearch/patriciasearch.c
patriciasearch/patriciasearch.h
patriciasearch/ps-ipv6.c [new file with mode: 0644]

index c68b8e5eaa6876b961381ae548ed228981dbe1b0..17946010c34db3fcf300ceb7b362d6fc76ff6c88 100644 (file)
@@ -3,5 +3,5 @@
 .PHONY: all
 all: patriciasearch.so
 
-patriciasearch.so: ps-nick.o ps-users.o patriciasearch.o formats.o
+patriciasearch.so: ps-nick.o ps-users.o ps-ipv6.o patriciasearch.o formats.o newsearch_ast.o
 
diff --git a/patriciasearch/newsearch_ast.c b/patriciasearch/newsearch_ast.c
new file mode 100644 (file)
index 0000000..16da4fa
--- /dev/null
@@ -0,0 +1,36 @@
+#include "../lib/sstring.h"
+#include "../lib/strlfunc.h"
+#include "../lib/stringbuf.h"
+#include <stdarg.h>
+#include <string.h>
+#include "patriciasearch.h"
+
+int ast_nodesearch(searchASTExpr *tree, replyFunc reply, void *sender, wallFunc wall, ChanDisplayFunc display, HeaderFunc header, void *headerarg, int limit) {
+  searchCtx ctx;
+  searchASTCache cache;
+  searchNode *search;
+  char buf[1024];
+
+  newsearch_ctxinit(&ctx, search_astparse, reply, wall, &cache, reg_nodesearch, sender, display, limit);
+
+  memset(&cache, 0, sizeof(cache));
+  cache.tree = tree;
+
+  buf[0] = '\0';
+  reply(sender, "Parsing: %s", ast_printtree(buf, sizeof(buf), tree, reg_nodesearch));
+  search = ctx.parser(&ctx, (char *)tree);
+  if(!search) {
+    reply(sender, "Parse error: %s", parseError);
+    return CMD_ERROR;
+  }
+
+  reply(sender, "Executing...");
+  if(header)
+    header(sender, headerarg);
+  pnodesearch_exe(search, &ctx, iptree->head);
+
+  (search->free)(&ctx, search);
+
+  return CMD_OK;
+}
+
index d1b2e64c0deb17bab6ed6d550ba9e75b15c52f27..928884c4aa151d0e9fd9574774ba7dfa600785f4 100644 (file)
@@ -23,6 +23,7 @@ void _init() {
 
   registersearchterm(reg_nodesearch, "users", ps_users_parse, 0, "");
   registersearchterm(reg_nodesearch, "nick", ps_nick_parse, 0, "");
+  registersearchterm(reg_nodesearch, "ipvsix", ps_ipv6_parse, 0, "");
 }
 
 void _fini() {
@@ -40,17 +41,19 @@ static void controlwallwrapper(int level, char *format, ...) {
 }
 
 int do_pnodesearch_real(replyFunc reply, wallFunc wall, void *source, int cargc, char **cargv) {
-  nick *sender = senderNSExtern = source;
-  struct searchNode *search;
+  nick *sender = source;
   int limit=500;
   int arg=0;
   NodeDisplayFunc display=defaultpnodefn;
-  searchCtx ctx;
   int ret;
   patricia_node_t *subset = iptree->head;
+  parsertree *tree;
 
-  if (cargc<1)
-    return CMD_USAGE;
+  if (cargc<1) { 
+    reply( sender, "Usage: [flags] <criteria>");
+    reply( sender, "For help, see help nicksearch");
+    return CMD_OK;
+  }
 
   ret = parseopts(cargc, cargv, &arg, &limit, (void *)&subset, (void *)&display, reg_nodesearch->outputtree, reply, sender);
   if(ret != CMD_OK)
@@ -65,16 +68,15 @@ int do_pnodesearch_real(replyFunc reply, wallFunc wall, void *source, int cargc,
     rejoinline(cargv[arg],cargc-arg);
   }
 
-  newsearch_ctxinit(&ctx, search_parse, reply, wall, NULL, reg_nodesearch, sender, display, limit);
-
-  if (!(search = ctx.parser(&ctx, cargv[arg]))) {
-    reply(sender,"Parse error: %s",parseError);
+  tree = parse_string(reg_nodesearch, cargv[arg]);
+  if(!tree) {
+    displaystrerror(reply, sender, cargv[arg]);
     return CMD_ERROR;
   }
 
-  pnodesearch_exe(search, &ctx, subset);
+  ast_nodesearch(tree->root, reply, sender, wall, display, NULL, NULL, limit);
 
-  (search->free)(&ctx, search);
+  parse_free(tree);
 
   return CMD_OK;
 }
@@ -87,6 +89,7 @@ void pnodesearch_exe(struct searchNode *search, searchCtx *ctx, patricia_node_t
   int matches = 0;
   patricia_node_t *node;
   nick *sender = ctx->sender;
+  senderNSExtern = sender;
   int limit = ctx->limit;
   NodeDisplayFunc display = ctx->displayfn;
 
index ae8ab89405873f6931969ee1dd709626eaebe8b4..6436509b2e72d19f02fe36ad30026e3e86bcac58 100644 (file)
@@ -1,6 +1,7 @@
 #include "../newsearch/newsearch.h"
 #include "../patricia/patricia.h"
 #include "../patricianick/patricianick.h"
+#include "../newsearch/parser.h"
 
 typedef void (*NodeDisplayFunc)(struct searchCtx *, nick *, patricia_node_t *);
 
@@ -20,3 +21,4 @@ extern searchCmd *reg_nodesearch;
  
 struct searchNode *ps_nick_parse(searchCtx *ctx, int argc, char **argv);
 struct searchNode *ps_users_parse(searchCtx *ctx, int argc, char **argv);
+struct searchNode *ps_ipv6_parse(searchCtx *ctx, int argc, char **argv);
diff --git a/patriciasearch/ps-ipv6.c b/patriciasearch/ps-ipv6.c
new file mode 100644 (file)
index 0000000..c14be42
--- /dev/null
@@ -0,0 +1,41 @@
+/*
+ * ipv6 functionality 
+ */
+
+#include "patriciasearch.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+
+void *ps_ipv6_exe(searchCtx *ctx, struct searchNode *thenode, void *theinput);
+void ps_ipv6_free(searchCtx *ctx, struct searchNode *thenode);
+
+struct searchNode *ps_ipv6_parse(searchCtx *ctx, int argc, char **argv) {
+  struct searchNode *thenode;
+
+  if (!(thenode=(struct searchNode *)malloc(sizeof (struct searchNode)))) {
+    parseError = "malloc: could not allocate memory for this search.";
+    return NULL;
+  }
+
+  thenode->returntype = RETURNTYPE_BOOL;
+  thenode->localdata = NULL;
+  thenode->exe = ps_ipv6_exe;
+  thenode->free = ps_ipv6_free;
+
+  return thenode;
+}
+
+void *ps_ipv6_exe(searchCtx *ctx, struct searchNode *thenode, void *theinput) {
+  patricia_node_t *node = (patricia_node_t *)theinput;
+
+  if (irc_in_addr_is_ipv4(&node->prefix->sin))
+    return (void *)0;
+  
+  return (void *)1;
+}
+
+void ps_ipv6_free(searchCtx *ctx, struct searchNode *thenode) {
+  free(thenode);
+}
+