[Asterisk-cvs] asterisk/channels chan_iax2.c,1.368,1.369

russell russell
Fri Nov 4 13:48:57 CST 2005


Update of /usr/cvsroot/asterisk/channels
In directory mongoose.digium.com:/tmp/cvs-serv8995/channels

Modified Files:
	chan_iax2.c 
Log Message:
allow the IAXPEER function to check a peer's status


Index: chan_iax2.c
===================================================================
RCS file: /usr/cvsroot/asterisk/channels/chan_iax2.c,v
retrieving revision 1.368
retrieving revision 1.369
diff -u -d -r1.368 -r1.369
--- chan_iax2.c	31 Oct 2005 23:16:26 -0000	1.368
+++ chan_iax2.c	4 Nov 2005 18:40:35 -0000	1.369
@@ -1872,6 +1872,30 @@
 }
 #endif /* IAXTESTS */
 
+/*! \brief  peer_status: Report Peer status in character string */
+/* 	returns 1 if peer is online, -1 if unmonitored */
+static int peer_status(struct iax2_peer *peer, char *status, int statuslen)
+{
+	int res = 0;
+	if (peer->maxms) {
+		if (peer->lastms < 0) {
+			ast_copy_string(status, "UNREACHABLE", statuslen);
+		} else if (peer->lastms > peer->maxms) {
+			snprintf(status, statuslen, "LAGGED (%d ms)", peer->lastms);
+			res = 1;
+		} else if (peer->lastms) {
+			snprintf(status, statuslen, "OK (%d ms)", peer->lastms);
+			res = 1;
+		} else {
+			ast_copy_string(status, "UNKNOWN", statuslen);
+		}
+	} else { 
+		ast_copy_string(status, "Unmonitored", statuslen);
+		res = -1;
+	}
+	return res;
+}
+
 /*--- iax2_show_peer: Show one peer in detail ---*/
 static int iax2_show_peer(int fd, int argc, char *argv[])
 {
@@ -1920,14 +1944,7 @@
 		ast_cli(fd, ")\n");
 
 		ast_cli(fd, "  Status       : ");
-		if (peer->lastms < 0)
-			ast_copy_string(status, "UNREACHABLE", sizeof(status));
-		else if (peer->historicms > peer->maxms)
-			snprintf(status, sizeof(status), "LAGGED (%d ms)", peer->historicms);
-		else if (peer->historicms)
-			snprintf(status, sizeof(status), "OK (%d ms)", peer->historicms);
-		else
-			ast_copy_string(status, "UNKNOWN", sizeof(status));
+		peer_status(peer, status, sizeof(status));	
 		ast_cli(fd, " Qualify        : every %d when OK, every %d when UNREACHABLE (sample smoothing %s)\n", peer->pokefreqok, peer->pokefreqnotok, (peer->smoothing == 1) ? "On" : "Off");
 		ast_cli(fd, "%s\n",status);
 		ast_cli(fd,"\n");
@@ -4188,6 +4205,7 @@
 		char nm[20];
 		char status[20];
 		char srch[2000];
+		int retstatus;
 
 		if (registeredonly && !peer->addr.sin_addr.s_addr)
 			continue;
@@ -4198,27 +4216,15 @@
 			snprintf(name, sizeof(name), "%s/%s", peer->name, peer->username);
 		else
 			ast_copy_string(name, peer->name, sizeof(name));
-		if (peer->maxms) {
-			if (peer->lastms < 0) {
-				ast_copy_string(status, "UNREACHABLE", sizeof(status));
-				offline_peers++;
-			}
-			else if (peer->historicms > peer->maxms)  {
-				snprintf(status, sizeof(status), "LAGGED (%d ms)", peer->historicms);
-				offline_peers++;
-			}
-			else if (peer->historicms)  {
-				snprintf(status, sizeof(status), "OK (%d ms)", peer->historicms);
-				online_peers++;
-			}
-			else  {
-				ast_copy_string(status, "UNKNOWN", sizeof(status));
-				offline_peers++;
-			}
-		} else {
-			ast_copy_string(status, "Unmonitored", sizeof(status));
+		
+		retstatus = peer_status(peer, status, sizeof(status));
+		if (retstatus > 0)
+			online_peers++;
+		else if (!retstatus)
+			offline_peers++;
+		else
 			unmonitored_peers++;
-		}
+		
 		ast_copy_string(nm, ast_inet_ntoa(iabuf, sizeof(iabuf), peer->mask), sizeof(nm));
 
 		snprintf(srch, sizeof(srch), FORMAT, name, 
@@ -9187,6 +9193,8 @@
 
 	if (!strcasecmp(colname, "ip")) {
 		ast_copy_string(buf, peer->addr.sin_addr.s_addr ? ast_inet_ntoa(iabuf, sizeof(iabuf), peer->addr.sin_addr) : "", len);
+	} else  if (!strcasecmp(colname, "status")) {
+		peer_status(peer, buf, len); 
 	} else  if (!strcasecmp(colname, "mailbox")) {
 		ast_copy_string(buf, peer->mailbox, len);
 	} else  if (!strcasecmp(colname, "context")) {
@@ -9228,6 +9236,7 @@
     .read = function_iaxpeer,
 	.desc = "If peername specified, valid items are:\n"
 	"- ip (default)          The IP address.\n"
+	"- status                The peer's status (if qualify=yes)\n"
 	"- mailbox               The configured mailbox.\n"
 	"- context               The configured context.\n"
 	"- expire                The epoch time of the next expire.\n"




More information about the svn-commits mailing list