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