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, "");
29 deregistersearchcommand( reg_nodesearch
);
32 static void controlwallwrapper(int level
, char *format
, ...) {
37 vsnprintf(buf
, sizeof(buf
), format
, ap
);
38 controlwall(NO_OPER
, level
, "%s", buf
);
42 int do_pnodesearch_real(replyFunc reply
, wallFunc wall
, void *source
, int cargc
, char **cargv
) {
43 nick
*sender
= senderNSExtern
= source
;
44 struct searchNode
*search
;
47 NodeDisplayFunc display
=defaultpnodefn
;
50 patricia_node_t
*subset
= iptree
->head
;
55 ret
= parseopts(cargc
, cargv
, &arg
, &limit
, (void *)&subset
, (void *)&display
, reg_nodesearch
->outputtree
, reply
, sender
);
60 reply(sender
,"No search terms - aborting.");
65 rejoinline(cargv
[arg
],cargc
-arg
);
68 newsearch_ctxinit(&ctx
, search_parse
, reply
, wall
, NULL
, reg_nodesearch
, sender
, display
, limit
);
70 if (!(search
= ctx
.parser(&ctx
, cargv
[arg
]))) {
71 reply(sender
,"Parse error: %s",parseError
);
75 pnodesearch_exe(search
, &ctx
, subset
);
77 (search
->free
)(&ctx
, search
);
82 int do_pnodesearch(void *source
, int cargc
, char **cargv
) {
83 return do_pnodesearch_real(controlreply
, controlwallwrapper
, source
, cargc
, cargv
);
86 void pnodesearch_exe(struct searchNode
*search
, searchCtx
*ctx
, patricia_node_t
*subset
) {
88 patricia_node_t
*node
;
89 nick
*sender
= ctx
->sender
;
90 int limit
= ctx
->limit
;
91 NodeDisplayFunc display
= ctx
->displayfn
;
93 /* Get a marker value to mark "seen" channels for unique count */
94 //nmarker=nextnodemarker();
96 /* The top-level node needs to return a BOOL */
97 search
=coerceNode(ctx
, search
, RETURNTYPE_BOOL
);
99 PATRICIA_WALK(subset
, node
) {
100 if ((search
->exe
)(ctx
, search
, node
)) {
102 display(ctx
, sender
, node
);
105 ctx
->reply(sender
, "--- More than %d matches, skipping the rest",limit
);
111 ctx
->reply(sender
,"--- End of list: %d matches",