diff --git a/CHANGES b/CHANGES index aa1d40812538894a7ebf07f3725daf965483c6e5..82250d9708b5e78254cc1463fadf629ca9e7f717 100644 --- a/CHANGES +++ b/CHANGES @@ -359,6 +359,8 @@ Asterisk Manager Interface status. * Added a "MixMonitorMute" AMI action for muting inbound and/or outbound audio in a MixMonitor recording. + * The 'iax2 show peers' output is now similar to the expected output of + 'sip show peers'. Channel Event Logging --------------------- diff --git a/UPGRADE.txt b/UPGRADE.txt index 0aff1da4aca8bf21c785adf60c2256f9104b2023..63eaf563c45c88a4cda44107a06b8124e8425e76 100644 --- a/UPGRADE.txt +++ b/UPGRADE.txt @@ -75,6 +75,9 @@ From 1.6.2 to 1.8: OSPCALLED to OSPOUTCALLED OSPRESULTS to OSPDESTREMAILS +* The Manager event 'iax2 show peers' output has been updated. It now has a + similar output of 'sip show peers'. + From 1.6.1 to 1.6.2: * SIP no longer sends the 183 progress message for early media by diff --git a/channels/chan_iax2.c b/channels/chan_iax2.c index 6cf3f652cbaeb01a02dca07db0e951a46c6a5192..2d778e514bd523dbb93ba8c9df1df8d0b75e774d 100644 --- a/channels/chan_iax2.c +++ b/channels/chan_iax2.c @@ -6422,7 +6422,7 @@ static char *handle_cli_iax2_show_users(struct ast_cli_entry *e, int cmd, struct #undef FORMAT2 } -static int __iax2_show_peers(int manager, int fd, struct mansession *s, const int argc, const char * const argv[]) +static int __iax2_show_peers(int fd, int *total, struct mansession *s, const int argc, const char * const argv[]) { regex_t regexbuf; int havepattern = 0; @@ -6432,18 +6432,17 @@ static int __iax2_show_peers(int manager, int fd, struct mansession *s, const in int unmonitored_peers = 0; struct ao2_iterator i; -#define FORMAT2 "%-15.15s %-15.15s %s %-15.15s %-8s %s %-10s%s" -#define FORMAT "%-15.15s %-15.15s %s %-15.15s %-5d%s %s %-10s%s" +#define FORMAT2 "%-15.15s %-15.15s %s %-15.15s %-8s %s %-10s\n" +#define FORMAT "%-15.15s %-15.15s %s %-15.15s %-5d%s %s %-10s\n" struct iax2_peer *peer = NULL; char name[256]; struct ast_str *encmethods = ast_str_alloca(256); int registeredonly=0; - char *term = manager ? "\r\n" : "\n"; char idtext[256] = ""; switch (argc) { case 6: - if (!strcasecmp(argv[3], "registered")) + if (!strcasecmp(argv[3], "registered")) registeredonly = 1; else return RESULT_SHOWUSAGE; @@ -6476,10 +6475,10 @@ static int __iax2_show_peers(int manager, int fd, struct mansession *s, const in if (!s) - ast_cli(fd, FORMAT2, "Name/Username", "Host", " ", "Mask", "Port", " ", "Status", term); + ast_cli(fd, FORMAT2, "Name/Username", "Host", " ", "Mask", "Port", " ", "Status"); i = ao2_iterator_init(peers, 0); - for (peer = ao2_iterator_next(&i); peer; + for (peer = ao2_iterator_next(&i); peer; peer_unref(peer), peer = ao2_iterator_next(&i)) { char nm[20]; char status[20]; @@ -6534,19 +6533,22 @@ static int __iax2_show_peers(int manager, int fd, struct mansession *s, const in ntohs(peer->addr.sin_port), ast_test_flag64(peer, IAX_TRUNK) ? "(T)" : " ", peer->encmethods ? "(E)" : " ", - status, - term); + status); } total_peers++; } ao2_iterator_destroy(&i); if (!s) - ast_cli(fd,"%d iax2 peers [%d online, %d offline, %d unmonitored]%s", total_peers, online_peers, offline_peers, unmonitored_peers, term); + ast_cli(fd,"%d iax2 peers [%d online, %d offline, %d unmonitored]\n", + total_peers, online_peers, offline_peers, unmonitored_peers); if (havepattern) regfree(®exbuf); + if (total) + *total = total_peers; + return RESULT_SUCCESS; #undef FORMAT #undef FORMAT2 @@ -6704,7 +6706,7 @@ static char *handle_cli_iax2_show_peers(struct ast_cli_entry *e, int cmd, struct return NULL; } - switch (__iax2_show_peers(0, a->fd, NULL, a->argc, a->argv)) { + switch (__iax2_show_peers(a->fd, NULL, NULL, a->argc, a->argv)) { case RESULT_SHOWUSAGE: return CLI_SHOWUSAGE; case RESULT_FAILURE: @@ -6758,12 +6760,23 @@ static int manager_iax2_show_peers(struct mansession *s, const struct message *m static const char * const a[] = { "iax2", "show", "peers" }; const char *id = astman_get_header(m,"ActionID"); char idtext[256] = ""; + int total = 0; if (!ast_strlen_zero(id)) snprintf(idtext, sizeof(idtext), "ActionID: %s\r\n", id); - astman_send_ack(s, m, "Peer status list will follow"); - return __iax2_show_peers(1, -1, s, 3, a); -} + + astman_send_listack(s, m, "Peer status list will follow", "start"); + /* List the peers in separate manager events */ + __iax2_show_peers(-1, &total, s, 3, a); + /* Send final confirmation */ + astman_append(s, + "Event: PeerlistComplete\r\n" + "EventList: Complete\r\n" + "ListItems: %d\r\n" + "%s" + "\r\n", total, idtext); + return 0; +} /*! \brief callback to display iax peers in manager format */ static int manager_iax2_show_peer_list(struct mansession *s, const struct message *m)