#include "../lib/stringbuf.h"
#include "../lib/strlfunc.h"
#include "patriciasearch.h"
+#include "../lib/version.h"
+#include "../newsearch/newsearch.h"
+
+MODULE_VERSION("")
-CommandTree *pnodeOutputTree;
searchCmd *reg_nodesearch;
int do_pnodesearch(void *source, int cargc, char **cargv);
NodeDisplayFunc defaultpnodefn = printnode;
-void regpnodedisp(const char *name, NodeDisplayFunc handler) {
- addcommandtotree(pnodeOutputTree, name, 0, 0, (CommandHandler)handler);
-}
-
-void unregpnodedisp(const char *name, NodeDisplayFunc handler) {
- deletecommandfromtree(pnodeOutputTree, name, (CommandHandler)handler);
-}
-
void _init() {
- pnodeOutputTree=newcommandtree();
-
reg_nodesearch = (searchCmd *)registersearchcommand("nodesearch",NO_OPER,do_pnodesearch, printnode);
- registersearchterm(reg_nodesearch, "users",ps_users_parse);
- registersearchterm(reg_nodesearch, "nick",ps_nick_parse);
+ 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() {
- destroycommandtree(pnodeOutputTree);
-
deregistersearchcommand( reg_nodesearch );
}
}
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 nodesearch");
+ return CMD_OK;
+ }
- ret = parseopts(cargc, cargv, &arg, &limit, (void *)&subset, (void **)&display, reg_nodesearch->outputtree, reply, sender);
+ ret = parseopts(cargc, cargv, &arg, &limit, (void *)&subset, (void *)&display, reg_nodesearch->outputtree, reply, sender);
if(ret != CMD_OK)
return ret;
rejoinline(cargv[arg],cargc-arg);
}
- newsearch_ctxinit(&ctx, search_parse, reply, wall, NULL, reg_nodesearch);
-
- 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, sender, display, limit, subset);
+ ast_nodesearch(tree->root, reply, sender, wall, display, NULL, NULL, limit);
- (search->free)(&ctx, search);
+ parse_free(tree);
return CMD_OK;
}
return do_pnodesearch_real(controlreply, controlwallwrapper, source, cargc, cargv);
}
-void pnodesearch_exe(struct searchNode *search, searchCtx *ctx, nick *sender, NodeDisplayFunc display, int limit, patricia_node_t *subset) {
+void pnodesearch_exe(struct searchNode *search, searchCtx *ctx, patricia_node_t *subset) {
int matches = 0;
patricia_node_t *node;
+ nick *sender = ctx->sender;
+ senderNSExtern = sender;
+ int limit = ctx->limit;
+ NodeDisplayFunc display = ctx->displayfn;
/* Get a marker value to mark "seen" channels for unique count */
//nmarker=nextnodemarker();