* adds CLI command "stun show status" jkister 2012060401 patch -p1 -d asterisk-10.4.2/ < stun-show-status-v4.patch ####################################################################### diff -ruBN asterisk-10.4.2.orig/res/res_stun_monitor.c asterisk-10.4.2/res/res_stun_monitor.c --- asterisk-10.4.2.orig/res/res_stun_monitor.c 2011-12-01 16:14:55.000000000 -0500 +++ asterisk-10.4.2/res/res_stun_monitor.c 2012-06-04 13:50:04.106705493 -0400 @@ -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 */ @@ -349,6 +350,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; @@ -375,6 +430,10 @@ { stun_stop_monitor(); ast_mutex_destroy(&args.lock); + + /* Unregister CLI commands */ + ast_cli_unregister_multiple(cli_stun, ARRAY_LEN(cli_stun)); + return 0; } @@ -387,6 +446,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; }