All pastes #27618 Raw Edit

Stuff

public text v1 · immutable
#27618 ·published 2005-11-04 17:40 UTC
rendered paste body
Index: channels/chan_iax2.c
===================================================================
RCS file: /usr/cvsroot/asterisk/channels/chan_iax2.c,v
retrieving revision 1.368
diff -u -r1.368 chan_iax2.c
--- channels/chan_iax2.c	31 Oct 2005 23:16:26 -0000	1.368
+++ channels/chan_iax2.c	4 Nov 2005 16:30:12 -0000
@@ -9157,6 +9157,31 @@
 	return -1;
 }
 
+/*! \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);
+		/* Checking if port is 0 */
+		res = -1;
+	}
+	return res;
+}
+
 static char *function_iaxpeer(struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len)
 {
 	char *ret = NULL;
@@ -9187,6 +9212,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 +9255,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"