Provide more fine grained control of sip and iax show peers (bug #1470)

git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@2856 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
Mark Spencer 2004-05-02 05:38:20 +00:00
parent 9d1e203b3d
commit 44de97d496
2 changed files with 71 additions and 2 deletions

View File

@ -2956,7 +2956,7 @@ static int iax2_show_peers(int fd, int argc, char *argv[])
struct iax2_peer *peer;
char name[256] = "";
int registeredonly=0;
if ((argc != 3) && (argc != 4))
if ((argc != 3) && (argc != 4) && (argc != 5))
return RESULT_SHOWUSAGE;
if ((argc == 4)) {
if (!strcasecmp(argv[3], "registered")) {
@ -2969,6 +2969,8 @@ static int iax2_show_peers(int fd, int argc, char *argv[])
for (peer = peerl.peers;peer;peer = peer->next) {
char nm[20];
char status[20];
int print_line = -1;
char srch[2000];
if (registeredonly && !peer->addr.sin_addr.s_addr)
continue;
if (strlen(peer->username))
@ -2987,11 +2989,32 @@ static int iax2_show_peers(int fd, int argc, char *argv[])
} else
strcpy(status, "Unmonitored");
strncpy(nm, inet_ntoa(peer->mask), sizeof(nm)-1);
sprintf(srch, FORMAT, name,
peer->addr.sin_addr.s_addr ? inet_ntoa(peer->addr.sin_addr) : "(Unspecified)",
peer->dynamic ? "(D)" : "(S)",
nm,
ntohs(peer->addr.sin_port), peer->trunk ? "(T)" : " ", status);
if (argc == 5) {
if (!strcasecmp(argv[3],"include") && strstr(srch,argv[4])) {
print_line = -1;
} else if (!strcasecmp(argv[3],"exclude") && !strstr(srch,argv[4])) {
print_line = 1;
} else if (!strcasecmp(argv[3],"begin") && !strncasecmp(srch,argv[4],strlen(argv[4]))) {
print_line = -1;
} else {
print_line = 0;
}
}
if (print_line) {
ast_cli(fd, FORMAT, name,
peer->addr.sin_addr.s_addr ? inet_ntoa(peer->addr.sin_addr) : "(Unspecified)",
peer->dynamic ? "(D)" : "(S)",
nm,
ntohs(peer->addr.sin_port), peer->trunk ? "(T)" : " ", status);
}
}
ast_mutex_unlock(&peerl.lock);
return RESULT_SUCCESS;
@ -3176,6 +3199,12 @@ static struct ast_cli_entry cli_show_channels =
{ { "iax2", "show", "channels", NULL }, iax2_show_channels, "Show active IAX channels", show_channels_usage };
static struct ast_cli_entry cli_show_peers =
{ { "iax2", "show", "peers", NULL }, iax2_show_peers, "Show defined IAX peers", show_peers_usage };
static struct ast_cli_entry cli_show_peers_include =
{ { "iax2", "show", "peers", "include", NULL }, iax2_show_peers, "Show defined IAX peers", show_peers_usage };
static struct ast_cli_entry cli_show_peers_exclude =
{ { "iax2", "show", "peers", "exclude", NULL }, iax2_show_peers, "Show defined IAX peers", show_peers_usage };
static struct ast_cli_entry cli_show_peers_begin =
{ { "iax2", "show", "peers", "begin", NULL }, iax2_show_peers, "Show defined IAX peers", show_peers_usage };
static struct ast_cli_entry cli_show_registry =
{ { "iax2", "show", "registry", NULL }, iax2_show_registry, "Show IAX registration status", show_reg_usage };
static struct ast_cli_entry cli_debug =
@ -6740,6 +6769,9 @@ static int __unload_module(void)
ast_cli_unregister(&cli_show_users);
ast_cli_unregister(&cli_show_channels);
ast_cli_unregister(&cli_show_peers);
ast_cli_unregister(&cli_show_peers_include);
ast_cli_unregister(&cli_show_peers_exclude);
ast_cli_unregister(&cli_show_peers_begin);
ast_cli_unregister(&cli_show_firmware);
ast_cli_unregister(&cli_show_registry);
ast_cli_unregister(&cli_debug);
@ -6807,6 +6839,9 @@ int load_module(void)
ast_cli_register(&cli_show_users);
ast_cli_register(&cli_show_channels);
ast_cli_register(&cli_show_peers);
ast_cli_register(&cli_show_peers_include);
ast_cli_register(&cli_show_peers_exclude);
ast_cli_register(&cli_show_peers_begin);
ast_cli_register(&cli_show_firmware);
ast_cli_register(&cli_show_registry);
ast_cli_register(&cli_debug);

View File

@ -4600,13 +4600,15 @@ static int sip_show_peers(int fd, int argc, char *argv[])
#define FORMAT "%-15.15s %-15.15s %s %-15.15s %-8d %-10s\n"
struct sip_peer *peer;
char name[256] = "";
if (argc != 3)
if (argc != 3 && argc != 5)
return RESULT_SHOWUSAGE;
ast_mutex_lock(&peerl.lock);
ast_cli(fd, FORMAT2, "Name/username", "Host", " ", "Mask", "Port", "Status");
for (peer = peerl.peers;peer;peer = peer->next) {
char nm[20] = "";
char status[20];
int print_line = -1;
char srch[2000];
strncpy(nm, inet_ntoa(peer->mask), sizeof(nm)-1);
if (strlen(peer->username))
snprintf(name, sizeof(name), "%s/%s", peer->name, peer->username);
@ -4623,11 +4625,31 @@ static int sip_show_peers(int fd, int argc, char *argv[])
strcpy(status, "UNKNOWN");
} else
strcpy(status, "Unmonitored");
sprintf(srch, FORMAT, name,
peer->addr.sin_addr.s_addr ? inet_ntoa(peer->addr.sin_addr) : "(Unspecified)",
peer->dynamic ? "(D)" : " ",
nm,
ntohs(peer->addr.sin_port), status);
if (argc == 5) {
if (!strcasecmp(argv[3],"include") && strstr(srch,argv[4])) {
print_line = -1;
} else if (!strcasecmp(argv[3],"exclude") && !strstr(srch,argv[4])) {
print_line = 1;
} else if (!strcasecmp(argv[3],"begin") && !strncasecmp(srch,argv[4],strlen(argv[4]))) {
print_line = -1;
} else {
print_line = 0;
}
}
if (print_line) {
ast_cli(fd, FORMAT, name,
peer->addr.sin_addr.s_addr ? inet_ntoa(peer->addr.sin_addr) : "(Unspecified)",
peer->dynamic ? "(D)" : " ",
nm,
ntohs(peer->addr.sin_port), status);
}
}
ast_mutex_unlock(&peerl.lock);
return RESULT_SUCCESS;
@ -5118,6 +5140,12 @@ static struct ast_cli_entry cli_debug_peer =
{ { "sip", "debug", "peer", NULL }, sip_do_debug, "Enable SIP debugging on Peername", debug_usage };
static struct ast_cli_entry cli_show_peers =
{ { "sip", "show", "peers", NULL }, sip_show_peers, "Show defined SIP peers", show_peers_usage };
static struct ast_cli_entry cli_show_peers_include =
{ { "sip", "show", "peers", "include", NULL }, sip_show_peers, "Show defined SIP peers", show_peers_usage };
static struct ast_cli_entry cli_show_peers_exclude =
{ { "sip", "show", "peers", "exclude", NULL }, sip_show_peers, "Show defined SIP peers", show_peers_usage };
static struct ast_cli_entry cli_show_peers_begin =
{ { "sip", "show", "peers", "begin", NULL }, sip_show_peers, "Show defined SIP peers", show_peers_usage };
static struct ast_cli_entry cli_inuse_show =
{ { "sip", "show", "inuse", NULL }, sip_show_inuse, "List all inuse/limit", show_inuse_usage };
static struct ast_cli_entry cli_show_registry =
@ -7165,6 +7193,9 @@ int load_module()
ast_cli_register(&cli_show_channels);
ast_cli_register(&cli_show_channel);
ast_cli_register(&cli_show_peers);
ast_cli_register(&cli_show_peers_begin);
ast_cli_register(&cli_show_peers_include);
ast_cli_register(&cli_show_peers_exclude);
ast_cli_register(&cli_show_registry);
ast_cli_register(&cli_debug);
ast_cli_register(&cli_debug_ip);
@ -7201,6 +7232,9 @@ int unload_module()
ast_cli_unregister(&cli_show_channels);
ast_cli_unregister(&cli_show_channel);
ast_cli_unregister(&cli_show_peers);
ast_cli_unregister(&cli_show_peers_include);
ast_cli_unregister(&cli_show_peers_exclude);
ast_cli_unregister(&cli_show_peers_begin);
ast_cli_unregister(&cli_show_registry);
ast_cli_unregister(&cli_debug);
ast_cli_unregister(&cli_debug_ip);