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"
15 #include "../lib/version.h"
19 typedef void (*TGDisplayFunc
)(struct searchCtx
*, nick
*, trustgroup_t
*);
20 typedef void (*THDisplayFunc
)(struct searchCtx
*, nick
*, trusthost_t
*);
22 int do_tgsearch(void *source
, int cargc
, char **cargv
);
23 int do_tgsearch_real(replyFunc reply
, wallFunc wall
, void *source
, int cargc
, char **cargv
);
24 void tgsearch_exe(struct searchNode
*search
, searchCtx
*ctx
);
25 int do_thsearch(void *source
, int cargc
, char **cargv
);
26 int do_thsearch_real(replyFunc reply
, wallFunc wall
, void *source
, int cargc
, char **cargv
);
27 void thsearch_exe(struct searchNode
*search
, searchCtx
*ctx
, nick
*sender
, THDisplayFunc display
, int limit
, patricia_node_t
*subset
);
29 searchCmd
*reg_tgsearch
;
30 searchCmd
*reg_thsearch
;
32 TGDisplayFunc defaulttgfn
= printtg
;
33 THDisplayFunc defaultthfn
= printth
;
36 reg_tgsearch
= (searchCmd
*)registersearchcommand("tgsearch",NO_OPER
,do_tgsearch
, printtg
);
37 reg_thsearch
= (searchCmd
*)registersearchcommand("thsearch",NO_OPER
,do_thsearch
, printth
);
39 regdisp(reg_tgsearch
, "all", printtgfull
, 0, "show trustgroup details, including hosts, excludes trust comments");
40 regdisp(reg_tgsearch
, "default", printtg
, 0, "displays trust group id");
41 regdisp(reg_thsearch
, "default", printth
, 0, "displays trust host id");
45 unregdisp( reg_tgsearch
, "all", printtgfull
);
46 unregdisp(reg_tgsearch
, "default", printtg
);
47 unregdisp(reg_thsearch
, "default", printth
);
49 deregistersearchcommand( reg_tgsearch
);
50 deregistersearchcommand( reg_thsearch
);
53 static void controlwallwrapper(int level
, char *format
, ...) {
58 vsnprintf(buf
, sizeof(buf
), format
, ap
);
59 controlwall(NO_OPER
, level
, "%s", buf
);
63 int do_tgsearch_real(replyFunc reply
, wallFunc wall
, void *source
, int cargc
, char **cargv
) {
64 nick
*sender
= senderNSExtern
= source
;
67 TGDisplayFunc display
=defaulttgfn
;
69 patricia_node_t
*subset
= iptree
->head
;
73 reply( sender
, "Usage: [flags] <criteria>");
74 reply( sender
, "For help, see help nicksearch");
78 ret
= parseopts(cargc
, cargv
, &arg
, &limit
, (void *)&subset
, (void **)&display
, reg_tgsearch
->outputtree
, reply
, sender
);
83 reply(sender
,"No search terms - aborting.");
88 rejoinline(cargv
[arg
],cargc
-arg
);
91 tree
= parse_string(reg_tgsearch
, cargv
[arg
]);
93 displaystrerror(reply
, sender
, cargv
[arg
]);
97 ast_tgsearch(tree
->root
, reply
, sender
, wall
, display
, NULL
, NULL
, limit
);
104 int do_tgsearch(void *source
, int cargc
, char **cargv
) {
105 return do_tgsearch_real(controlreply
, controlwallwrapper
, source
, cargc
, cargv
);
108 void tgsearch_exe(struct searchNode
*search
, searchCtx
*ctx
) {
112 nick
*np
, *sender
= ctx
->sender
;
113 senderNSExtern
= sender
;
114 TGDisplayFunc display
= ctx
->displayfn
;
115 int limit
= ctx
->limit
;
117 /* Get a marker value to mark "seen" channels for unique count */
118 //nmarker=nextnodemarker();
120 /* The top-level node needs to return a BOOL */
121 search
=coerceNode(ctx
, search
, RETURNTYPE_BOOL
);
123 for ( i
= 0; i
< TRUSTS_HASH_GROUPSIZE
; i
++ ) {
124 for ( tg
= trustgroupidtable
[i
]; tg
; tg
= tg
-> nextbyid
) {
125 if ((search
->exe
)(ctx
, search
, tg
)) {
127 display(ctx
, sender
, tg
);
130 ctx
->reply(sender
, "--- More than %d matches, skipping the rest",limit
);
135 ctx
->reply(sender
,"--- End of list: %d matches",
139 int do_thsearch_real(replyFunc reply
, wallFunc wall
, void *source
, int cargc
, char **cargv
) {
140 nick
*sender
= senderNSExtern
= source
;
141 struct searchNode
*search
;
144 THDisplayFunc display
=defaultthfn
;
147 patricia_node_t
*subset
= iptree
->head
;
152 ret
= parseopts(cargc
, cargv
, &arg
, &limit
, (void *)&subset
, (void **)&display
, reg_tgsearch
->outputtree
, reply
, sender
);
157 reply(sender
,"No search terms - aborting.");
162 rejoinline(cargv
[arg
],cargc
-arg
);
165 newsearch_ctxinit(&ctx
, search_parse
, reply
, wall
, NULL
, reg_thsearch
, sender
, display
, limit
);
167 if (!(search
= ctx
.parser(&ctx
, cargv
[arg
]))) {
168 reply(sender
,"Parse error: %s",parseError
);
172 thsearch_exe(search
, &ctx
, sender
, display
, limit
, subset
);
174 (search
->free
)(&ctx
, search
);
179 int do_thsearch(void *source
, int cargc
, char **cargv
) {
180 return do_thsearch_real(controlreply
, controlwallwrapper
, source
, cargc
, cargv
);
183 void thsearch_exe(struct searchNode
*search
, searchCtx
*ctx
, nick
*sender
, THDisplayFunc display
, int limit
, patricia_node_t
*subset
) {
188 /* Get a marker value to mark "seen" channels for unique count */
189 //nmarker=nextnodemarker();
191 /* The top-level node needs to return a BOOL */
192 search
=coerceNode(ctx
, search
, RETURNTYPE_BOOL
);
194 for ( i
= 0; i
< TRUSTS_HASH_HOSTSIZE
; i
++ ) {
195 for ( tgh
= trusthostidtable
[i
]; tgh
; tgh
= tgh
-> nextbyid
) {
196 if ((search
->exe
)(ctx
, search
, tgh
)) {
198 display(ctx
, sender
, tgh
);
201 ctx
->reply(sender
, "--- More than %d matches, skipping the rest",limit
);
206 ctx
->reply(sender
,"--- End of list: %d matches",