178 static int verbose_level = 3;
190 static struct cache_type cache_types[] = {
196 #define STR(x) vstring_str(x)
200 static void cache_type(
ARGV *argv)
202 struct cache_type *cp;
204 if (argv->
argc != 2) {
210 for (cp = cache_types; cp->mode != 0; cp++) {
211 if (strcmp(cp->mode, argv->
argv[1]) == 0) {
212 scache = cp->create();
221 static void handle_events(
ARGV *argv)
227 if (argv->
argc != 2 || (delay = atoi(argv->
argv[1])) <= 0) {
234 if (after < before + delay)
235 sleep(before + delay - after);
240 static void save_endp(
ARGV *argv)
246 || (ttl = atoi(argv->
argv[1])) <= 0
247 || (fd = atoi(argv->
argv[4])) <= 0) {
248 msg_error(
"usage: save_endp ttl endpoint endp_props fd");
258 static void find_endp(
ARGV *argv)
262 if (argv->
argc != 2) {
272 static void save_dest(
ARGV *argv)
276 if (argv->
argc != 5 || (ttl = atoi(argv->
argv[1])) <= 0) {
277 msg_error(
"usage: save_dest ttl destination dest_props endpoint");
285 static void find_dest(
ARGV *argv)
289 if (argv->
argc != 2) {
290 msg_error(
"usage: find_dest destination");
299 static void verbose(
ARGV *argv)
303 if (argv->
argc != 2 || (level = atoi(argv->
argv[1])) < 0) {
307 verbose_level = level;
315 void (*action) (
ARGV *);
319 #define FLAG_NEED_CACHE (1<<0)
321 static void help(
ARGV *);
323 static struct action actions[] = {
324 "cache_type", cache_type, 0,
325 "save_endp", save_endp, FLAG_NEED_CACHE,
326 "find_endp", find_endp, FLAG_NEED_CACHE,
327 "save_dest", save_dest, FLAG_NEED_CACHE,
328 "find_dest", find_dest, FLAG_NEED_CACHE,
329 "sleep", handle_events, 0,
330 "verbose", verbose, 0,
337 static void help(
ARGV *argv)
342 for (ap = actions; ap->command != 0; ap++)
369 int main(
int unused_argc,
char **unused_argv)
374 int interactive = isatty(0);
383 if (argv->
argc > 0 && argv->
argv[0][0] !=
'#') {
385 for (ap = actions; ap->command != 0; ap++) {
386 if (strcmp(ap->command, argv->
argv[0]) == 0) {
387 if ((ap->flags & FLAG_NEED_CACHE) != 0 && scache == 0)
395 if (ap->command == 0)
void msg_error(const char *fmt,...)
int main(int argc, char **argv)
int vstring_get_nonl(VSTRING *vp, VSTREAM *fp)
ARGV * argv_free(ARGV *argvp)
#define scache_find_dest(scache, dest_label, dest_prop, endp_prop)
#define scache_free(scache)
SCACHE * scache_multi_create(void)
VSTREAM * vstream_printf(const char *fmt,...)
SCACHE * scache_single_create(void)
VSTRING * vstring_alloc(ssize_t len)
#define scache_save_endp(scache, ttl, endp_label, endp_prop, fd)
NORETURN msg_fatal(const char *fmt,...)
int vstream_fflush(VSTREAM *stream)
ARGV * argv_split(const char *, const char *)
#define scache_find_endp(scache, endp_label, endp_prop)
VSTRING * vstring_free(VSTRING *vp)
#define vstream_fileno(vp)
#define scache_save_dest(scache, ttl, dest_label, dest_prop, endp_label)
void event_drain(int time_limit)