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 CommandTree
*pnodeOutputTree
;
16 searchCmd
*reg_nodesearch
;
18 int do_pnodesearch(void *source
, int cargc
, char **cargv
);
20 NodeDisplayFunc defaultpnodefn
= printnode
;
22 void regpnodedisp(const char *name
, NodeDisplayFunc handler
) {
23 addcommandtotree(pnodeOutputTree
, name
, 0, 0, (CommandHandler
)handler
);
26 void unregpnodedisp(const char *name
, NodeDisplayFunc handler
) {
27 deletecommandfromtree(pnodeOutputTree
, name
, (CommandHandler
)handler
);
31 pnodeOutputTree
=newcommandtree();
33 reg_nodesearch
= (searchCmd
*)registersearchcommand("nodesearch",NO_OPER
,do_pnodesearch
, printnode
);
35 registersearchterm(reg_nodesearch
, "users", ps_users_parse
, 0, "");
36 registersearchterm(reg_nodesearch
, "nick", ps_nick_parse
, 0, "");
40 destroycommandtree(pnodeOutputTree
);
42 deregistersearchcommand( reg_nodesearch
);
45 static void controlwallwrapper(int level
, char *format
, ...) {
50 vsnprintf(buf
, sizeof(buf
), format
, ap
);
51 controlwall(NO_OPER
, level
, "%s", buf
);
55 int do_pnodesearch_real(replyFunc reply
, wallFunc wall
, void *source
, int cargc
, char **cargv
) {
56 nick
*sender
= senderNSExtern
= source
;
57 struct searchNode
*search
;
60 NodeDisplayFunc display
=defaultpnodefn
;
63 patricia_node_t
*subset
= iptree
->head
;
68 ret
= parseopts(cargc
, cargv
, &arg
, &limit
, (void *)&subset
, (void **)&display
, reg_nodesearch
->outputtree
, reply
, sender
);
73 reply(sender
,"No search terms - aborting.");
78 rejoinline(cargv
[arg
],cargc
-arg
);
81 newsearch_ctxinit(&ctx
, search_parse
, reply
, wall
, NULL
, reg_nodesearch
, sender
);
83 if (!(search
= ctx
.parser(&ctx
, cargv
[arg
]))) {
84 reply(sender
,"Parse error: %s",parseError
);
88 pnodesearch_exe(search
, &ctx
, sender
, display
, limit
, subset
);
90 (search
->free
)(&ctx
, search
);
95 int do_pnodesearch(void *source
, int cargc
, char **cargv
) {
96 return do_pnodesearch_real(controlreply
, controlwallwrapper
, source
, cargc
, cargv
);
99 void pnodesearch_exe(struct searchNode
*search
, searchCtx
*ctx
, nick
*sender
, NodeDisplayFunc display
, int limit
, patricia_node_t
*subset
) {
101 patricia_node_t
*node
;
103 /* Get a marker value to mark "seen" channels for unique count */
104 //nmarker=nextnodemarker();
106 /* The top-level node needs to return a BOOL */
107 search
=coerceNode(ctx
, search
, RETURNTYPE_BOOL
);
109 PATRICIA_WALK(subset
, node
) {
110 if ((search
->exe
)(ctx
, search
, node
)) {
112 display(ctx
, sender
, node
);
115 ctx
->reply(sender
, "--- More than %d matches, skipping the rest",limit
);
121 ctx
->reply(sender
,"--- End of list: %d matches",