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 "../trusts2/trusts.h"
14 #include "trusts_search.h"
16 typedef void (*TGDisplayFunc
)(struct searchCtx
*, nick
*, trustgroup_t
*);
17 typedef void (*THDisplayFunc
)(struct searchCtx
*, nick
*, trusthost_t
*);
19 int do_tgsearch(void *source
, int cargc
, char **cargv
);
20 int do_tgsearch_real(replyFunc reply
, wallFunc wall
, void *source
, int cargc
, char **cargv
);
21 void tgsearch_exe(struct searchNode
*search
, searchCtx
*ctx
, nick
*sender
, TGDisplayFunc display
, int limit
, patricia_node_t
*subset
);
22 int do_thsearch(void *source
, int cargc
, char **cargv
);
23 int do_thsearch_real(replyFunc reply
, wallFunc wall
, void *source
, int cargc
, char **cargv
);
24 void thsearch_exe(struct searchNode
*search
, searchCtx
*ctx
, nick
*sender
, THDisplayFunc display
, int limit
, patricia_node_t
*subset
);
26 searchCmd
*reg_tgsearch
;
27 searchCmd
*reg_thsearch
;
29 TGDisplayFunc defaulttgfn
= printtg
;
30 THDisplayFunc defaultthfn
= printth
;
33 reg_tgsearch
= (searchCmd
*)registersearchcommand("tgsearch",NO_OPER
,do_tgsearch
, printtg
);
34 reg_thsearch
= (searchCmd
*)registersearchcommand("thsearch",NO_OPER
,do_thsearch
, printth
);
36 regdisp(reg_tgsearch
, "all", printtgfull
, 0, "show trustgroup details, including hosts, excludes trust comments");
37 regdisp(reg_tgsearch
, "default", printtg
, 0, "displays trust group id");
38 regdisp(reg_thsearch
, "default", printth
, 0, "displays trust host id");
42 unregdisp( reg_tgsearch
, "all", printtgfull
);
43 unregdisp(reg_tgsearch
, "default", printtg
);
44 unregdisp(reg_thsearch
, "default", printth
);
46 deregistersearchcommand( reg_tgsearch
);
47 deregistersearchcommand( reg_thsearch
);
50 static void controlwallwrapper(int level
, char *format
, ...) {
55 vsnprintf(buf
, sizeof(buf
), format
, ap
);
56 controlwall(NO_OPER
, level
, "%s", buf
);
60 int do_tgsearch_real(replyFunc reply
, wallFunc wall
, void *source
, int cargc
, char **cargv
) {
61 nick
*sender
= senderNSExtern
= source
;
62 struct searchNode
*search
;
65 TGDisplayFunc display
=defaulttgfn
;
68 patricia_node_t
*subset
= iptree
->head
;
73 ret
= parseopts(cargc
, cargv
, &arg
, &limit
, (void *)&subset
, (void **)&display
, reg_tgsearch
->outputtree
, reply
, sender
);
78 reply(sender
,"No search terms - aborting.");
83 rejoinline(cargv
[arg
],cargc
-arg
);
86 newsearch_ctxinit(&ctx
, search_parse
, reply
, wall
, NULL
, reg_tgsearch
, sender
, display
, limit
);
88 if (!(search
= ctx
.parser(&ctx
, cargv
[arg
]))) {
89 reply(sender
,"Parse error: %s",parseError
);
93 tgsearch_exe(search
, &ctx
, sender
, display
, limit
, subset
);
95 (search
->free
)(&ctx
, search
);
100 int do_tgsearch(void *source
, int cargc
, char **cargv
) {
101 return do_tgsearch_real(controlreply
, controlwallwrapper
, source
, cargc
, cargv
);
104 void tgsearch_exe(struct searchNode
*search
, searchCtx
*ctx
, nick
*sender
, TGDisplayFunc display
, int limit
, patricia_node_t
*subset
) {
109 /* Get a marker value to mark "seen" channels for unique count */
110 //nmarker=nextnodemarker();
112 /* The top-level node needs to return a BOOL */
113 search
=coerceNode(ctx
, search
, RETURNTYPE_BOOL
);
115 for ( i
= 0; i
< TRUSTS_HASH_GROUPSIZE
; i
++ ) {
116 for ( tg
= trustgroupidtable
[i
]; tg
; tg
= tg
-> nextbyid
) {
117 if ((search
->exe
)(ctx
, search
, tg
)) {
119 display(ctx
, sender
, tg
);
122 ctx
->reply(sender
, "--- More than %d matches, skipping the rest",limit
);
127 ctx
->reply(sender
,"--- End of list: %d matches",
131 int do_thsearch_real(replyFunc reply
, wallFunc wall
, void *source
, int cargc
, char **cargv
) {
132 nick
*sender
= senderNSExtern
= source
;
133 struct searchNode
*search
;
136 THDisplayFunc display
=defaultthfn
;
139 patricia_node_t
*subset
= iptree
->head
;
144 ret
= parseopts(cargc
, cargv
, &arg
, &limit
, (void *)&subset
, (void **)&display
, reg_tgsearch
->outputtree
, reply
, sender
);
149 reply(sender
,"No search terms - aborting.");
154 rejoinline(cargv
[arg
],cargc
-arg
);
157 newsearch_ctxinit(&ctx
, search_parse
, reply
, wall
, NULL
, reg_thsearch
, sender
, display
, limit
);
159 if (!(search
= ctx
.parser(&ctx
, cargv
[arg
]))) {
160 reply(sender
,"Parse error: %s",parseError
);
164 thsearch_exe(search
, &ctx
, sender
, display
, limit
, subset
);
166 (search
->free
)(&ctx
, search
);
171 int do_thsearch(void *source
, int cargc
, char **cargv
) {
172 return do_thsearch_real(controlreply
, controlwallwrapper
, source
, cargc
, cargv
);
175 void thsearch_exe(struct searchNode
*search
, searchCtx
*ctx
, nick
*sender
, THDisplayFunc display
, int limit
, patricia_node_t
*subset
) {
180 /* Get a marker value to mark "seen" channels for unique count */
181 //nmarker=nextnodemarker();
183 /* The top-level node needs to return a BOOL */
184 search
=coerceNode(ctx
, search
, RETURNTYPE_BOOL
);
186 for ( i
= 0; i
< TRUSTS_HASH_HOSTSIZE
; i
++ ) {
187 for ( tgh
= trusthostidtable
[i
]; tgh
; tgh
= tgh
-> nextbyid
) {
188 if ((search
->exe
)(ctx
, search
, tgh
)) {
190 display(ctx
, sender
, tgh
);
193 ctx
->reply(sender
, "--- More than %d matches, skipping the rest",limit
);
198 ctx
->reply(sender
,"--- End of list: %d matches",