.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
--- /dev/null
+#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;
+}
+
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() {
}
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)
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;
}
int matches = 0;
patricia_node_t *node;
nick *sender = ctx->sender;
+ senderNSExtern = sender;
int limit = ctx->limit;
NodeDisplayFunc display = ctx->displayfn;
#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 *);
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);
--- /dev/null
+/*
+ * 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);
+}
+