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
);
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
;
64 TGDisplayFunc display
=defaulttgfn
;
66 patricia_node_t
*subset
= iptree
->head
;
70 reply( sender
, "Usage: [flags] <criteria>");
71 reply( sender
, "For help, see help nicksearch");
75 ret
= parseopts(cargc
, cargv
, &arg
, &limit
, (void *)&subset
, (void **)&display
, reg_tgsearch
->outputtree
, reply
, sender
);
80 reply(sender
,"No search terms - aborting.");
85 rejoinline(cargv
[arg
],cargc
-arg
);
88 tree
= parse_string(reg_tgsearch
, cargv
[arg
]);
90 displaystrerror(reply
, sender
, cargv
[arg
]);
94 ast_tgsearch(tree
->root
, reply
, sender
, wall
, display
, NULL
, NULL
, limit
);
101 int do_tgsearch(void *source
, int cargc
, char **cargv
) {
102 return do_tgsearch_real(controlreply
, controlwallwrapper
, source
, cargc
, cargv
);
105 void tgsearch_exe(struct searchNode
*search
, searchCtx
*ctx
) {
109 nick
*np
, *sender
= ctx
->sender
;
110 senderNSExtern
= sender
;
111 TGDisplayFunc display
= ctx
->displayfn
;
112 int limit
= ctx
->limit
;
114 /* Get a marker value to mark "seen" channels for unique count */
115 //nmarker=nextnodemarker();
117 /* The top-level node needs to return a BOOL */
118 search
=coerceNode(ctx
, search
, RETURNTYPE_BOOL
);
120 for ( i
= 0; i
< TRUSTS_HASH_GROUPSIZE
; i
++ ) {
121 for ( tg
= trustgroupidtable
[i
]; tg
; tg
= tg
-> nextbyid
) {
122 if ((search
->exe
)(ctx
, search
, tg
)) {
124 display(ctx
, sender
, tg
);
127 ctx
->reply(sender
, "--- More than %d matches, skipping the rest",limit
);
132 ctx
->reply(sender
,"--- End of list: %d matches",
136 int do_thsearch_real(replyFunc reply
, wallFunc wall
, void *source
, int cargc
, char **cargv
) {
137 nick
*sender
= senderNSExtern
= source
;
138 struct searchNode
*search
;
141 THDisplayFunc display
=defaultthfn
;
144 patricia_node_t
*subset
= iptree
->head
;
149 ret
= parseopts(cargc
, cargv
, &arg
, &limit
, (void *)&subset
, (void **)&display
, reg_tgsearch
->outputtree
, reply
, sender
);
154 reply(sender
,"No search terms - aborting.");
159 rejoinline(cargv
[arg
],cargc
-arg
);
162 newsearch_ctxinit(&ctx
, search_parse
, reply
, wall
, NULL
, reg_thsearch
, sender
, display
, limit
);
164 if (!(search
= ctx
.parser(&ctx
, cargv
[arg
]))) {
165 reply(sender
,"Parse error: %s",parseError
);
169 thsearch_exe(search
, &ctx
, sender
, display
, limit
, subset
);
171 (search
->free
)(&ctx
, search
);
176 int do_thsearch(void *source
, int cargc
, char **cargv
) {
177 return do_thsearch_real(controlreply
, controlwallwrapper
, source
, cargc
, cargv
);
180 void thsearch_exe(struct searchNode
*search
, searchCtx
*ctx
, nick
*sender
, THDisplayFunc display
, int limit
, patricia_node_t
*subset
) {
185 /* Get a marker value to mark "seen" channels for unique count */
186 //nmarker=nextnodemarker();
188 /* The top-level node needs to return a BOOL */
189 search
=coerceNode(ctx
, search
, RETURNTYPE_BOOL
);
191 for ( i
= 0; i
< TRUSTS_HASH_HOSTSIZE
; i
++ ) {
192 for ( tgh
= trusthostidtable
[i
]; tgh
; tgh
= tgh
-> nextbyid
) {
193 if ((search
->exe
)(ctx
, search
, tgh
)) {
195 display(ctx
, sender
, tgh
);
198 ctx
->reply(sender
, "--- More than %d matches, skipping the rest",limit
);
203 ctx
->reply(sender
,"--- End of list: %d matches",