]> jfr.im git - irc/quakenet/newserv.git/blame - patriciasearch/patriciasearch.c
Remove old newsearch parser.
[irc/quakenet/newserv.git] / patriciasearch / patriciasearch.c
CommitLineData
3128667f
P
1#include <stdio.h>
2#include <stdarg.h>
3#include <string.h>
4
5#include "../control/control.h"
6#include "../irc/irc_config.h"
7#include "../lib/irc_string.h"
8#include "../parser/parser.h"
9#include "../lib/splitline.h"
10#include "../lib/version.h"
11#include "../lib/stringbuf.h"
12#include "../lib/strlfunc.h"
13#include "patriciasearch.h"
5857b2db 14#include "../lib/version.h"
0555113a 15#include "../newsearch/newsearch.h"
5857b2db
P
16
17MODULE_VERSION("")
3128667f 18
3128667f
P
19searchCmd *reg_nodesearch;
20
21int do_pnodesearch(void *source, int cargc, char **cargv);
22
23NodeDisplayFunc defaultpnodefn = printnode;
24
3128667f 25void _init() {
3128667f
P
26 reg_nodesearch = (searchCmd *)registersearchcommand("nodesearch",NO_OPER,do_pnodesearch, printnode);
27
ea634fc1
P
28 registersearchterm(reg_nodesearch, "users", ps_users_parse, 0, "");
29 registersearchterm(reg_nodesearch, "nick", ps_nick_parse, 0, "");
a4b2a5b9 30 registersearchterm(reg_nodesearch, "ipvsix", ps_ipv6_parse, 0, "");
3128667f
P
31}
32
33void _fini() {
3128667f
P
34 deregistersearchcommand( reg_nodesearch );
35}
36
37static void controlwallwrapper(int level, char *format, ...) {
38 char buf[1024];
39 va_list ap;
40
41 va_start(ap, format);
42 vsnprintf(buf, sizeof(buf), format, ap);
43 controlwall(NO_OPER, level, "%s", buf);
44 va_end(ap);
45}
46
47int do_pnodesearch_real(replyFunc reply, wallFunc wall, void *source, int cargc, char **cargv) {
a4b2a5b9 48 nick *sender = source;
3128667f
P
49 int limit=500;
50 int arg=0;
51 NodeDisplayFunc display=defaultpnodefn;
3128667f
P
52 int ret;
53 patricia_node_t *subset = iptree->head;
a4b2a5b9 54 parsertree *tree;
3128667f 55
a4b2a5b9
P
56 if (cargc<1) {
57 reply( sender, "Usage: [flags] <criteria>");
96135b6a 58 reply( sender, "For help, see help nodesearch");
a4b2a5b9
P
59 return CMD_OK;
60 }
3128667f 61
6cb1b086 62 ret = parseopts(cargc, cargv, &arg, &limit, (void *)&subset, (void *)&display, reg_nodesearch->outputtree, reply, sender);
3128667f
P
63 if(ret != CMD_OK)
64 return ret;
65
66 if (arg>=cargc) {
67 reply(sender,"No search terms - aborting.");
68 return CMD_ERROR;
69 }
70
71 if (arg<(cargc-1)) {
72 rejoinline(cargv[arg],cargc-arg);
73 }
74
a4b2a5b9
P
75 tree = parse_string(reg_nodesearch, cargv[arg]);
76 if(!tree) {
77 displaystrerror(reply, sender, cargv[arg]);
3128667f
P
78 return CMD_ERROR;
79 }
80
a4b2a5b9 81 ast_nodesearch(tree->root, reply, sender, wall, display, NULL, NULL, limit);
3128667f 82
a4b2a5b9 83 parse_free(tree);
3128667f
P
84
85 return CMD_OK;
86}
87
88int do_pnodesearch(void *source, int cargc, char **cargv) {
89 return do_pnodesearch_real(controlreply, controlwallwrapper, source, cargc, cargv);
90}
91
6b2202d0 92void pnodesearch_exe(struct searchNode *search, searchCtx *ctx, patricia_node_t *subset) {
3128667f
P
93 int matches = 0;
94 patricia_node_t *node;
6b2202d0 95 nick *sender = ctx->sender;
a4b2a5b9 96 senderNSExtern = sender;
6b2202d0
CP
97 int limit = ctx->limit;
98 NodeDisplayFunc display = ctx->displayfn;
3128667f
P
99
100 /* Get a marker value to mark "seen" channels for unique count */
101 //nmarker=nextnodemarker();
102
103 /* The top-level node needs to return a BOOL */
104 search=coerceNode(ctx, search, RETURNTYPE_BOOL);
105
106 PATRICIA_WALK(subset, node) {
107 if ((search->exe)(ctx, search, node)) {
108 if (matches<limit)
109 display(ctx, sender, node);
110
111 if (matches==limit)
112 ctx->reply(sender, "--- More than %d matches, skipping the rest",limit);
113 matches++;
114 }
115 }
116 PATRICIA_WALK_END;
117
118 ctx->reply(sender,"--- End of list: %d matches",
119 matches);
120}
121
122