? iax_just_show_peer-aka-rev5_split.diff
Index: chan_iax2.c
===================================================================
RCS file: /usr/cvsroot/asterisk/channels/chan_iax2.c,v
retrieving revision 1.230
diff -u -r1.230 chan_iax2.c
--- chan_iax2.c	29 Dec 2004 23:02:21 -0000	1.230
+++ chan_iax2.c	1 Jan 2005 01:08:53 -0000
@@ -639,6 +639,20 @@
 		return csub;
 }
 
+static struct iax2_peer *find_peer(const char *name) {
+	struct iax2_peer *peer;
+    struct iax2_peer *prev;
+	ast_mutex_lock(&peerl.lock);
+	for(peer = peerl.peers; peer; peer = peer->next) {
+		if (!strcasecmp(peer->name, name)) {
+			break;
+		}
+		prev = peer;
+	}
+	ast_mutex_unlock(&peerl.lock);
+	return peer;
+}
+
 static int iax2_getpeername(struct sockaddr_in sin, char *host, int len, int lockpeer)
 {
 	struct iax2_peer *peer;
@@ -1590,6 +1604,59 @@
 "to establish the maximum excess jitter buffer that is permitted before the jitter\n"
 "buffer size is reduced.";
 
+
+/*--- iax2_show_peer: Show one peer in detail ---*/
+static int iax2_show_peer(int fd, int argc, char *argv[])
+{
+	char status[30] = "";
+	char cbuf[256];
+	char iabuf[INET_ADDRSTRLEN];
+	struct iax2_peer *peer;
+	char codec_buf[512];
+
+	if (argc != 4)
+		return RESULT_SHOWUSAGE;
+	ast_mutex_lock(&peerl.lock);
+	peer = find_peer(argv[3]);
+	if (peer) {
+		ast_cli(fd,"\n\n");
+		ast_cli(fd, "  * Name       : %s\n", peer->name);
+		ast_cli(fd, "  Secret       : %s\n", ast_strlen_zero(peer->secret)?"<Not set>":"<Set>");
+		ast_cli(fd, "  Context      : %s\n", peer->context);
+		ast_cli(fd, "  Mailbox      : %s\n", peer->mailbox);
+		ast_cli(fd, "  Dynamic      : %s\n", ast_test_flag(peer, IAX_DYNAMIC) ? "Yes":"No");
+		ast_cli(fd, "  Callerid     : %s\n", ast_callerid_merge(cbuf, sizeof(cbuf), peer->cid_name, peer->cid_num, "<unspecified>"));
+		ast_cli(fd, "  Expire       : %d\n", peer->expire);
+		ast_cli(fd, "  ACL          : %s\n", (peer->ha?"Yes":"No"));
+		ast_cli(fd, "  Addr->IP     : %s Port %d\n",  peer->addr.sin_addr.s_addr ? ast_inet_ntoa(iabuf, sizeof(iabuf), peer->addr.sin_addr) : "(Unspecified)", ntohs(peer->addr.sin_port));
+		ast_cli(fd, "  Defaddr->IP  : %s Port %d\n", ast_inet_ntoa(iabuf, sizeof(iabuf), peer->defaddr.sin_addr), ntohs(peer->defaddr.sin_port));
+		ast_cli(fd, "  Username     : %s\n", peer->username);
+		ast_cli(fd, "  Codecs       : ");
+		ast_getformatname_multiple(codec_buf, sizeof(codec_buf) -1, peer->capability);
+		ast_cli(fd, "%s\n", codec_buf);
+
+		ast_cli(fd, "  Status       : ");
+		if (peer->lastms < 0)
+			strncpy(status, "UNREACHABLE", sizeof(status) - 1);
+		else if (peer->lastms > peer->maxms)
+			snprintf(status, sizeof(status), "LAGGED (%d ms)", peer->lastms);
+		else if (peer->lastms)
+			snprintf(status, sizeof(status), "OK (%d ms)", peer->lastms);
+		else
+			strncpy(status, "UNKNOWN", sizeof(status) - 1);
+		ast_cli(fd, "%s\n",status);
+		ast_cli(fd,"\n");
+	} else {
+		ast_cli(fd,"Peer %s not found.\n", argv[3]);
+		ast_cli(fd,"\n");
+	}
+
+	ast_mutex_unlock(&peerl.lock);
+
+	return RESULT_SUCCESS;
+}
+
+
 static int iax2_show_stats(int fd, int argc, char *argv[])
 {
 	struct iax_frame *cur;
@@ -1673,6 +1740,10 @@
 "Usage: iax show cache\n"
 "       Display currently cached IAX Dialplan results.\n";
 
+static char show_peer_usage[] =
+"Usage: iax show peer <name>\n"
+"       Display details on specific IAX peer\n";
+
 static struct ast_cli_entry cli_set_jitter = 
 { { "iax2", "set", "jitter", NULL }, iax2_set_jitter, "Sets IAX jitter buffer", jitter_usage };
 
@@ -1682,6 +1753,8 @@
 static struct ast_cli_entry cli_show_cache =
 { { "iax2", "show", "cache", NULL }, iax2_show_cache, "Display IAX cached dialplan", show_cache_usage };
 
+static struct ast_cli_entry  cli_show_peer =
+	{ { "iax2", "show", "peer", NULL }, iax2_show_peer, "Show details on specific IAX peer", show_peer_usage };
 
 static unsigned int calc_rxstamp(struct chan_iax2_pvt *p, unsigned int offset);
 
@@ -3816,7 +3889,7 @@
 	int gotcapability=0;
 	char iabuf[INET_ADDRSTRLEN];
 	struct ast_variable *v = NULL, *tmpvar = NULL;
-	
+
 	if (!iaxs[callno])
 		return res;
 	if (ies->called_number)
@@ -3925,8 +3998,6 @@
 				iaxs[callno]->vars = tmpvar;
 			}
 		}
-
-
 		iaxs[callno]->encmethods = user->encmethods;
 		/* Store the requested username if not specified */
 		if (ast_strlen_zero(iaxs[callno]->username))
@@ -6044,6 +6115,7 @@
 					if (!format) {
 						ast_log(LOG_DEBUG, "We don't do requested format %s, falling back to peer capability %d\n", ast_getformatname(iaxs[fr.callno]->peerformat), iaxs[fr.callno]->peercapability);
 						format = iaxs[fr.callno]->peercapability & iaxs[fr.callno]->capability;
+
 						if (!format) {
 							if (authdebug)
 								ast_log(LOG_NOTICE, "Rejected connect attempt from %s, requested/capability 0x%x/0x%x incompatible  with our capability 0x%x.\n", ast_inet_ntoa(iabuf, sizeof(iabuf), sin.sin_addr), iaxs[fr.callno]->peerformat, iaxs[fr.callno]->peercapability, iaxs[fr.callno]->capability);
@@ -7792,6 +7864,7 @@
 	ast_cli_unregister(&cli_set_jitter);
 	ast_cli_unregister(&cli_show_stats);
 	ast_cli_unregister(&cli_show_cache);
+	ast_cli_unregister(&cli_show_peer);
 	ast_unregister_switch(&iax2_switch);
 	ast_channel_unregister(channeltype);
 	delete_users();
@@ -7819,6 +7892,7 @@
 	
 	struct sockaddr_in sin;
 	
+
 	iax_set_output(iax_debug_output);
 	iax_set_error(iax_error_output);
 	
@@ -7870,6 +7944,7 @@
 	ast_cli_register(&cli_set_jitter);
 	ast_cli_register(&cli_show_stats);
 	ast_cli_register(&cli_show_cache);
+	ast_cli_register(&cli_show_peer);
 
 	ast_register_application(papp, iax2_prov_app, psyn, pdescrip);
 	
