summaryrefslogtreecommitdiff
path: root/channels
diff options
context:
space:
mode:
authorJonathan Rose <jrose@digium.com>2012-02-02 17:07:35 +0000
committerJonathan Rose <jrose@digium.com>2012-02-02 17:07:35 +0000
commit516419697278a9d029825b17f55a25302bf3fc0d (patch)
tree5fcb156dfc4b8eeeb172c44852a565159376e01a /channels
parent0e334d427b55915fca4d3bd0241df1d23c2aa68c (diff)
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) ........ Merged revisions 353769 from http://svn.asterisk.org/svn/asterisk/branches/1.8 ........ Merged revisions 353771 from http://svn.asterisk.org/svn/asterisk/branches/10 git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@353772 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'channels')
-rw-r--r--channels/chan_sip.c61
1 files changed, 36 insertions, 25 deletions
diff --git a/channels/chan_sip.c b/channels/chan_sip.c
index de64ea413..a46fad349 100644
--- a/channels/chan_sip.c
+++ b/channels/chan_sip.c
@@ -17252,10 +17252,9 @@ static char *_sip_show_peers(int fd, int *total, struct mansession *s, const str
int havepattern = FALSE;
struct sip_peer *peer;
struct ao2_iterator i;
-
+
/* 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 %-11s %-32.32s %s\n"
-#define FORMAT "%-25.25s %-39.39s %-3.3s %-10.10s %-3.3s %-8s %-11s %-32.32s %s\n"
char name[256];
int total_peers = 0;
@@ -17269,8 +17268,7 @@ static char *_sip_show_peers(int fd, int *total, struct mansession *s, const str
int objcount = ao2_container_count(peers);
struct sip_peer **peerarray;
int k;
-
-
+
realtimepeers = ast_check_realtime("sippeers");
peerarray = ast_calloc(sizeof(struct sip_peer *), objcount);
@@ -17296,10 +17294,9 @@ static char *_sip_show_peers(int fd, int *total, struct mansession *s, const str
if (!s) /* Normal list */
ast_cli(fd, FORMAT2, "Name/username", "Host", "Dyn", "Forcerport", "ACL", "Port", "Status", "Description", (realtimepeers ? "Realtime" : ""));
-
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);
if (!(peer->type & SIP_TYPE_PEER)) {
@@ -17319,15 +17316,30 @@ static char *_sip_show_peers(int fd, int *total, struct mansession *s, const str
ao2_unlock(peer);
}
ao2_iterator_destroy(&i);
-
+
qsort(peerarray, total_peers, sizeof(struct sip_peer *), peercomparefunc);
for(k=0; k < total_peers; k++) {
char status[20] = "";
char srch[2000];
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];
-
+
+ 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);
if (havepattern && regexec(&regexbuf, peer->name, 0, NULL, 0)) {
ao2_unlock(peer);
@@ -17339,7 +17351,7 @@ static char *_sip_show_peers(int fd, int *total, struct mansession *s, const str
snprintf(name, sizeof(name), "%s/%s", peer->name, peer->username);
else
ast_copy_string(name, peer->name, sizeof(name));
-
+
pstatus = peer_status(peer, status, sizeof(status));
if (pstatus == 1)
peers_mon_online++;
@@ -17354,22 +17366,22 @@ static char *_sip_show_peers(int fd, int *total, struct mansession *s, const str
}
}
- snprintf(srch, sizeof(srch), FORMAT, name,
- ast_sockaddr_isnull(&peer->addr) ? "(Unspecified)" : ast_sockaddr_stringify_addr(&peer->addr),
- peer->host_dynamic ? " D " : " ", /* Dynamic or not? */
+ snprintf(srch, sizeof(srch), FORMAT2, name,
+ tmp_host,
+ peer->host_dynamic ? " D " : " ", /* Dynamic or not? */
ast_test_flag(&peer->flags[0], SIP_NAT_FORCE_RPORT) ? " N " : " ", /* NAT=yes? */
- peer->ha ? " A " : " ", /* permit/deny */
- ast_sockaddr_isnull(&peer->addr) ? 0 : ast_sockaddr_stringify_port(&peer->addr), status,
+ peer->ha ? " A " : " ", /* permit/deny */
+ tmp_port, status,
peer->description ? peer->description : "",
realtimepeers ? (peer->is_realtime ? "Cached RT":"") : "");
if (!s) {/* Normal CLI list */
- ast_cli(fd, FORMAT, name,
- ast_sockaddr_isnull(&peer->addr) ? "(Unspecified)" : ast_sockaddr_stringify_addr(&peer->addr),
- peer->host_dynamic ? " D " : " ", /* Dynamic or not? */
+ ast_cli(fd, FORMAT2, name,
+ tmp_host,
+ peer->host_dynamic ? " D " : " ", /* Dynamic or not? */
ast_test_flag(&peer->flags[0], SIP_NAT_FORCE_RPORT) ? " N " : " ", /* NAT=yes? */
peer->ha ? " A " : " ", /* permit/deny */
- ast_sockaddr_isnull(&peer->addr) ? 0 : ast_sockaddr_stringify_port(&peer->addr), status,
+ tmp_port, status,
peer->description ? peer->description : "",
realtimepeers ? (peer->is_realtime ? "Cached RT":"") : "");
} else { /* Manager format */
@@ -17391,9 +17403,9 @@ static char *_sip_show_peers(int fd, int *total, struct mansession *s, const str
"Description: %s\r\n\r\n",
idtext,
peer->name,
- ast_sockaddr_isnull(&peer->addr) ? "-none-" : ast_sockaddr_stringify_addr(&peer->addr),
- ast_sockaddr_isnull(&peer->addr) ? 0 : ast_sockaddr_stringify_port(&peer->addr),
- peer->host_dynamic ? "yes" : "no", /* Dynamic or not? */
+ ast_sockaddr_isnull(&peer->addr) ? "-none-" : tmp_host,
+ ast_sockaddr_isnull(&peer->addr) ? "0" : tmp_port,
+ 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[1], SIP_PAGE2_VIDEOSUPPORT) ? "yes" : "no", /* VIDEOSUPPORT=yes? */
ast_test_flag(&peer->flags[1], SIP_PAGE2_TEXTSUPPORT) ? "yes" : "no", /* TEXTSUPPORT=yes? */
@@ -17405,7 +17417,7 @@ static char *_sip_show_peers(int fd, int *total, struct mansession *s, const str
ao2_unlock(peer);
peer = peerarray[k] = sip_unref_peer(peer, "toss iterator peer ptr");
}
-
+
if (!s)
ast_cli(fd, "%d sip peers [Monitored: %d online, %d offline Unmonitored: %d online, %d offline]\n",
total_peers, peers_mon_online, peers_mon_offline, peers_unmon_online, peers_unmon_offline);
@@ -17415,11 +17427,10 @@ static char *_sip_show_peers(int fd, int *total, struct mansession *s, const str
if (total)
*total = total_peers;
-
+
ast_free(peerarray);
-
+
return CLI_SUCCESS;
-#undef FORMAT
#undef FORMAT2
}