Fix sip show peers port output, align columns, and fix ami port output.

A previous patch I committed from ASTERISK-16930 unexpectedly changed some output for
the AMI action "sippeers" which this patch changes back. Also, this aligns the output
for the cli command "sip show peers" and fixes another issue that patch introduced by
using ast_sockaddr_stringify calls multiple times without immediately using the pointer.
I also went ahead and did a little janitorial work to clean up whitespace in
_sip_show_peers.

(issue ASTERISK-16930)
(closes issue ASTERISK-19281)
Reported by: Patrick El Youssef
Patches:
	ASTERISK-19281.diff uploaded by Walter Doekes (license 5674)


git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/1.8@353769 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
Jonathan Rose
2012-02-02 16:57:36 +00:00
parent 3c1a9894e8
commit ad24624751

View File

@@ -16631,7 +16631,6 @@ static char *_sip_show_peers(int fd, int *total, struct mansession *s, const str
/* the last argument is left-aligned, so we don't need a size anyways */ /* the last argument is left-aligned, so we don't need a size anyways */
#define FORMAT2 "%-25.25s %-39.39s %-3.3s %-10.10s %-3.3s %-8s %-10s %s\n" #define FORMAT2 "%-25.25s %-39.39s %-3.3s %-10.10s %-3.3s %-8s %-10s %s\n"
#define FORMAT "%-25.25s %-39.39s %-3.3s %-3.3s %-3.3s %-8s %-10s %s\n"
char name[256]; char name[256];
int total_peers = 0; int total_peers = 0;
@@ -16646,7 +16645,6 @@ static char *_sip_show_peers(int fd, int *total, struct mansession *s, const str
struct sip_peer **peerarray; struct sip_peer **peerarray;
int k; int k;
realtimepeers = ast_check_realtime("sippeers"); realtimepeers = ast_check_realtime("sippeers");
peerarray = ast_calloc(sizeof(struct sip_peer *), objcount); peerarray = ast_calloc(sizeof(struct sip_peer *), objcount);
@@ -16673,7 +16671,6 @@ static char *_sip_show_peers(int fd, int *total, struct mansession *s, const str
if (!s) /* Normal list */ if (!s) /* Normal list */
ast_cli(fd, FORMAT2, "Name/username", "Host", "Dyn", "Forcerport", "ACL", "Port", "Status", (realtimepeers ? "Realtime" : "")); ast_cli(fd, FORMAT2, "Name/username", "Host", "Dyn", "Forcerport", "ACL", "Port", "Status", (realtimepeers ? "Realtime" : ""));
i = ao2_iterator_init(peers, 0); i = ao2_iterator_init(peers, 0);
while ((peer = ao2_t_iterator_next(&i, "iterate thru peers table"))) { while ((peer = ao2_t_iterator_next(&i, "iterate thru peers table"))) {
ao2_lock(peer); ao2_lock(peer);
@@ -16702,8 +16699,23 @@ static char *_sip_show_peers(int fd, int *total, struct mansession *s, const str
char status[20] = ""; char status[20] = "";
char srch[2000]; char srch[2000];
char pstatus; char pstatus;
/*
* tmp_port and tmp_host store copies of ast_sockaddr_stringify strings since the
* string pointers for that function aren't valid between subsequent calls to
* ast_sockaddr_stringify functions
*/
char *tmp_port;
char *tmp_host;
peer = peerarray[k]; peer = peerarray[k];
tmp_port = ast_sockaddr_isnull(&peer->addr) ?
"0" : ast_strdupa(ast_sockaddr_stringify_port(&peer->addr));
tmp_host = ast_sockaddr_isnull(&peer->addr) ?
"(Unspecified)" : ast_strdupa(ast_sockaddr_stringify_addr(&peer->addr));
ao2_lock(peer); ao2_lock(peer);
if (havepattern && regexec(&regexbuf, peer->name, 0, NULL, 0)) { if (havepattern && regexec(&regexbuf, peer->name, 0, NULL, 0)) {
ao2_unlock(peer); ao2_unlock(peer);
@@ -16730,21 +16742,21 @@ static char *_sip_show_peers(int fd, int *total, struct mansession *s, const str
} }
} }
snprintf(srch, sizeof(srch), FORMAT, name, snprintf(srch, sizeof(srch), FORMAT2, name,
ast_sockaddr_isnull(&peer->addr) ? "(Unspecified)" : ast_sockaddr_stringify_addr(&peer->addr), tmp_host,
peer->host_dynamic ? " D " : " ", /* Dynamic or not? */ peer->host_dynamic ? " D " : " ", /* Dynamic or not? */
ast_test_flag(&peer->flags[0], SIP_NAT_FORCE_RPORT) ? " N " : " ", /* NAT=yes? */ ast_test_flag(&peer->flags[0], SIP_NAT_FORCE_RPORT) ? " N " : " ", /* NAT=yes? */
peer->ha ? " A " : " ", /* permit/deny */ peer->ha ? " A " : " ", /* permit/deny */
ast_sockaddr_isnull(&peer->addr) ? 0 : ast_sockaddr_stringify_port(&peer->addr), status, tmp_port, status,
realtimepeers ? (peer->is_realtime ? "Cached RT":"") : ""); realtimepeers ? (peer->is_realtime ? "Cached RT":"") : "");
if (!s) {/* Normal CLI list */ if (!s) {/* Normal CLI list */
ast_cli(fd, FORMAT, name, ast_cli(fd, FORMAT2, name,
ast_sockaddr_isnull(&peer->addr) ? "(Unspecified)" : ast_sockaddr_stringify_addr(&peer->addr), tmp_host,
peer->host_dynamic ? " D " : " ", /* Dynamic or not? */ peer->host_dynamic ? " D " : " ", /* Dynamic or not? */
ast_test_flag(&peer->flags[0], SIP_NAT_FORCE_RPORT) ? " N " : " ", /* NAT=yes? */ ast_test_flag(&peer->flags[0], SIP_NAT_FORCE_RPORT) ? " N " : " ", /* NAT=yes? */
peer->ha ? " A " : " ", /* permit/deny */ peer->ha ? " A " : " ", /* permit/deny */
ast_sockaddr_isnull(&peer->addr) ? 0 : ast_sockaddr_stringify_port(&peer->addr), status, tmp_port, status,
realtimepeers ? (peer->is_realtime ? "Cached RT":"") : ""); realtimepeers ? (peer->is_realtime ? "Cached RT":"") : "");
} else { /* Manager format */ } else { /* Manager format */
/* The names here need to be the same as other channels */ /* The names here need to be the same as other channels */
@@ -16764,9 +16776,9 @@ static char *_sip_show_peers(int fd, int *total, struct mansession *s, const str
"RealtimeDevice: %s\r\n\r\n", "RealtimeDevice: %s\r\n\r\n",
idtext, idtext,
peer->name, peer->name,
ast_sockaddr_isnull(&peer->addr) ? "-none-" : ast_sockaddr_stringify_addr(&peer->addr), ast_sockaddr_isnull(&peer->addr) ? "-none-" : tmp_host,
ast_sockaddr_isnull(&peer->addr) ? 0 : ast_sockaddr_stringify_port(&peer->addr), ast_sockaddr_isnull(&peer->addr) ? "0" : tmp_port,
peer->host_dynamic ? "yes" : "no", /* Dynamic or not? */ peer->host_dynamic ? "yes" : "no", /* Dynamic or not? */
ast_test_flag(&peer->flags[0], SIP_NAT_FORCE_RPORT) ? "yes" : "no", /* NAT=yes? */ ast_test_flag(&peer->flags[0], SIP_NAT_FORCE_RPORT) ? "yes" : "no", /* NAT=yes? */
ast_test_flag(&peer->flags[1], SIP_PAGE2_VIDEOSUPPORT) ? "yes" : "no", /* VIDEOSUPPORT=yes? */ ast_test_flag(&peer->flags[1], SIP_PAGE2_VIDEOSUPPORT) ? "yes" : "no", /* VIDEOSUPPORT=yes? */
ast_test_flag(&peer->flags[1], SIP_PAGE2_TEXTSUPPORT) ? "yes" : "no", /* TEXTSUPPORT=yes? */ ast_test_flag(&peer->flags[1], SIP_PAGE2_TEXTSUPPORT) ? "yes" : "no", /* TEXTSUPPORT=yes? */
@@ -16791,7 +16803,6 @@ static char *_sip_show_peers(int fd, int *total, struct mansession *s, const str
ast_free(peerarray); ast_free(peerarray);
return CLI_SUCCESS; return CLI_SUCCESS;
#undef FORMAT
#undef FORMAT2 #undef FORMAT2
} }