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"
18 searchCmd
*reg_nodesearch
;
20 int do_pnodesearch(void *source
, int cargc
, char **cargv
);
22 NodeDisplayFunc defaultpnodefn
= printnode
;
25 reg_nodesearch
= (searchCmd
*)registersearchcommand("nodesearch",NO_OPER
,do_pnodesearch
, printnode
);
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, "");
33 deregistersearchcommand( reg_nodesearch
);
36 static void controlwallwrapper(int level
, char *format
, ...) {
41 vsnprintf(buf
, sizeof(buf
), format
, ap
);
42 controlwall(NO_OPER
, level
, "%s", buf
);
46 int do_pnodesearch_real(replyFunc reply
, wallFunc wall
, void *source
, int cargc
, char **cargv
) {
47 nick
*sender
= source
;
50 NodeDisplayFunc display
=defaultpnodefn
;
52 patricia_node_t
*subset
= iptree
->head
;
56 reply( sender
, "Usage: [flags] <criteria>");
57 reply( sender
, "For help, see help nodesearch");
61 ret
= parseopts(cargc
, cargv
, &arg
, &limit
, (void *)&subset
, (void *)&display
, reg_nodesearch
->outputtree
, reply
, sender
);
66 reply(sender
,"No search terms - aborting.");
71 rejoinline(cargv
[arg
],cargc
-arg
);
74 tree
= parse_string(reg_nodesearch
, cargv
[arg
]);
76 displaystrerror(reply
, sender
, cargv
[arg
]);
80 ast_nodesearch(tree
->root
, reply
, sender
, wall
, display
, NULL
, NULL
, limit
);
87 int do_pnodesearch(void *source
, int cargc
, char **cargv
) {
88 return do_pnodesearch_real(controlreply
, controlwallwrapper
, source
, cargc
, cargv
);
91 void pnodesearch_exe(struct searchNode
*search
, searchCtx
*ctx
, patricia_node_t
*subset
) {
93 patricia_node_t
*node
;
94 nick
*sender
= ctx
->sender
;
95 senderNSExtern
= sender
;
96 int limit
= ctx
->limit
;
97 NodeDisplayFunc display
= ctx
->displayfn
;
99 /* Get a marker value to mark "seen" channels for unique count */
100 //nmarker=nextnodemarker();
102 /* The top-level node needs to return a BOOL */
103 search
=coerceNode(ctx
, search
, RETURNTYPE_BOOL
);
105 PATRICIA_WALK(subset
, node
) {
106 if ((search
->exe
)(ctx
, search
, node
)) {
108 display(ctx
, sender
, node
);
111 ctx
->reply(sender
, "--- More than %d matches, skipping the rest",limit
);
117 ctx
->reply(sender
,"--- End of list: %d matches",