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"
15 searchCmd
*reg_nodesearch
;
17 int do_pnodesearch(void *source
, int cargc
, char **cargv
);
19 NodeDisplayFunc defaultpnodefn
= printnode
;
22 reg_nodesearch
= (searchCmd
*)registersearchcommand("nodesearch",NO_OPER
,do_pnodesearch
, printnode
);
24 registersearchterm(reg_nodesearch
, "users", ps_users_parse
, 0, "");
25 registersearchterm(reg_nodesearch
, "nick", ps_nick_parse
, 0, "");
26 registersearchterm(reg_nodesearch
, "ipvsix", ps_ipv6_parse
, 0, "");
30 deregistersearchcommand( reg_nodesearch
);
33 static void controlwallwrapper(int level
, char *format
, ...) {
38 vsnprintf(buf
, sizeof(buf
), format
, ap
);
39 controlwall(NO_OPER
, level
, "%s", buf
);
43 int do_pnodesearch_real(replyFunc reply
, wallFunc wall
, void *source
, int cargc
, char **cargv
) {
44 nick
*sender
= source
;
47 NodeDisplayFunc display
=defaultpnodefn
;
49 patricia_node_t
*subset
= iptree
->head
;
53 reply( sender
, "Usage: [flags] <criteria>");
54 reply( sender
, "For help, see help nodesearch");
58 ret
= parseopts(cargc
, cargv
, &arg
, &limit
, (void *)&subset
, (void *)&display
, reg_nodesearch
->outputtree
, reply
, sender
);
63 reply(sender
,"No search terms - aborting.");
68 rejoinline(cargv
[arg
],cargc
-arg
);
71 tree
= parse_string(reg_nodesearch
, cargv
[arg
]);
73 displaystrerror(reply
, sender
, cargv
[arg
]);
77 ast_nodesearch(tree
->root
, reply
, sender
, wall
, display
, NULL
, NULL
, limit
);
84 int do_pnodesearch(void *source
, int cargc
, char **cargv
) {
85 return do_pnodesearch_real(controlreply
, controlwallwrapper
, source
, cargc
, cargv
);
88 void pnodesearch_exe(struct searchNode
*search
, searchCtx
*ctx
, patricia_node_t
*subset
) {
90 patricia_node_t
*node
;
91 nick
*sender
= ctx
->sender
;
92 senderNSExtern
= sender
;
93 int limit
= ctx
->limit
;
94 NodeDisplayFunc display
= ctx
->displayfn
;
96 /* Get a marker value to mark "seen" channels for unique count */
97 //nmarker=nextnodemarker();
99 /* The top-level node needs to return a BOOL */
100 search
=coerceNode(ctx
, search
, RETURNTYPE_BOOL
);
102 PATRICIA_WALK(subset
, node
) {
103 if ((search
->exe
)(ctx
, search
, node
)) {
105 display(ctx
, sender
, node
);
108 ctx
->reply(sender
, "--- More than %d matches, skipping the rest",limit
);
114 ctx
->reply(sender
,"--- End of list: %d matches",