Add verbosity to STUN monitor requests jkister 2012011401 * adds CLI command "stun show status" now plays nice with ASTERISK-18327 patch -p1 -d asterisk-1.8.9.0-rc2 < stun-show-status-v3.patch ####################################################################### diff -ruBN asterisk-1.8.9.0-rc2.orig/res/res_stun_monitor.c asterisk-1.8.9.0-rc2/res/res_stun_monitor.c --- asterisk-1.8.9.0-rc2.orig/res/res_stun_monitor.c 2011-12-01 16:11:39.000000000 -0500 +++ asterisk-1.8.9.0-rc2/res/res_stun_monitor.c 2012-01-14 02:13:45.000000000 -0500 @@ -39,6 +39,7 @@ #include "asterisk/netsock2.h" #include "asterisk/lock.h" #include "asterisk/acl.h" +#include "asterisk/cli.h" #include #define DEFAULT_MONITOR_REFRESH 30 /*!< Default refresh period in seconds */ @@ -339,6 +340,60 @@ return 0; } +/*! \brief Execute stun show status command */ +static char *_stun_show_status(int fd, int argc, const char *argv[]) +{ + const char *status; + +#define DATALN "%-25s %-5d %-7d %-8d %-7s %-16s %-d\n" +#define HEADER "%-25s %-5s %-7s %-8s %-7s %-16s %-s\n" + + /* we only have one stun server, but start to play well with more */ + ast_cli(fd, HEADER, "Hostname", "Port", "Period", "Retries", "Status", "ExternAddr", "ExternPort"); + + if( args.stun_poll_failed_gripe == 1 ){ + status = "FAIL"; + }else if( args.external_addr_known == 1 ){ + status = "OK"; + }else{ + status = "INIT"; + } + ast_cli( fd, DATALN, + args.server_hostname, + args.stun_port, + args.refresh, + 3, /* retries - static for now */ + status, + ast_inet_ntoa(args.external_addr.sin_addr), + ntohs(args.external_addr.sin_port) + ); + +#undef HEADER +#undef DATALN + + return CLI_SUCCESS; +} + +static char *handle_cli_stun_show_status(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) +{ + switch (cmd) { + case CLI_INIT: + e->command = "stun show status"; + e->usage = + "Usage: stun show status\n" + " List all known STUN servers and statuses.\n"; + return NULL; + case CLI_GENERATE: + return NULL; + } + + return _stun_show_status(a->fd, a->argc, (const char **) a->argv); +} + +static struct ast_cli_entry cli_stun[] = { + AST_CLI_DEFINE(handle_cli_stun_show_status, "Show STUN servers and statuses"), +}; + static int __reload(int startup) { int res; @@ -365,6 +420,10 @@ { stun_stop_monitor(); ast_mutex_destroy(&args.lock); + + /* Unregister CLI commands */ + ast_cli_unregister_multiple(cli_stun, ARRAY_LEN(cli_stun)); + return 0; } @@ -377,6 +436,9 @@ return AST_MODULE_LOAD_DECLINE; } + /* Register CLI commands */ + ast_cli_register_multiple(cli_stun, sizeof(cli_stun) / sizeof(struct ast_cli_entry)); + return AST_MODULE_LOAD_SUCCESS; }