From: Paul Date: Thu, 25 Dec 2008 20:04:48 +0000 (+0000) Subject: update patricia search for ast + add ipvsix command X-Git-Url: https://jfr.im/git/irc/quakenet/newserv.git/commitdiff_plain/6b4f75b89984df359a4f99c133b0e98d2efa7039 update patricia search for ast + add ipvsix command --- diff --git a/patriciasearch/Makefile.in b/patriciasearch/Makefile.in index c68b8e5e..17946010 100644 --- a/patriciasearch/Makefile.in +++ b/patriciasearch/Makefile.in @@ -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 index 00000000..16da4fa5 --- /dev/null +++ b/patriciasearch/newsearch_ast.c @@ -0,0 +1,36 @@ +#include "../lib/sstring.h" +#include "../lib/strlfunc.h" +#include "../lib/stringbuf.h" +#include +#include +#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; +} + diff --git a/patriciasearch/patriciasearch.c b/patriciasearch/patriciasearch.c index d1b2e64c..928884c4 100644 --- a/patriciasearch/patriciasearch.c +++ b/patriciasearch/patriciasearch.c @@ -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] "); + 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; diff --git a/patriciasearch/patriciasearch.h b/patriciasearch/patriciasearch.h index ae8ab894..6436509b 100644 --- a/patriciasearch/patriciasearch.h +++ b/patriciasearch/patriciasearch.h @@ -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 index 00000000..c14be422 --- /dev/null +++ b/patriciasearch/ps-ipv6.c @@ -0,0 +1,41 @@ +/* + * ipv6 functionality + */ + +#include "patriciasearch.h" + +#include +#include + +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); +} +