[asterisk-commits] file: branch 1.2 r42086 - /branches/1.2/channels/chan_iax2.c

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Wed Sep 6 08:55:23 MST 2006


Author: file
Date: Wed Sep  6 10:55:20 2006
New Revision: 42086

URL: http://svn.digium.com/view/asterisk?rev=42086&view=rev
Log:
Make realtime regseconds work as people expected (0 on registration expiration or release, and actual on normal state) (issue #7684 reported by kshumard)

Modified:
    branches/1.2/channels/chan_iax2.c

Modified: branches/1.2/channels/chan_iax2.c
URL: http://svn.digium.com/view/asterisk/branches/1.2/channels/chan_iax2.c?rev=42086&r1=42085&r2=42086&view=diff
==============================================================================
--- branches/1.2/channels/chan_iax2.c (original)
+++ branches/1.2/channels/chan_iax2.c Wed Sep  6 10:55:20 2006
@@ -2740,18 +2740,16 @@
 	return user;
 }
 
-static void realtime_update_peer(const char *peername, struct sockaddr_in *sin)
-{
-	char port[10];
-	char ipaddr[20];
-	char regseconds[20];
-	time_t nowtime;
+static void realtime_update_peer(const char *peername, struct sockaddr_in *sin, time_t regtime)
+{
+        char port[10];
+        char ipaddr[20];
+        char regseconds[20];
 	
-	time(&nowtime);
-	snprintf(regseconds, sizeof(regseconds), "%d", (int)nowtime);
-	ast_inet_ntoa(ipaddr, sizeof(ipaddr), sin->sin_addr);
-	snprintf(port, sizeof(port), "%d", ntohs(sin->sin_port));
-	ast_update_realtime("iaxpeers", "name", peername, "ipaddr", ipaddr, "port", port, "regseconds", regseconds, NULL);
+        snprintf(regseconds, sizeof(regseconds), "%d", (int)regtime);
+        ast_inet_ntoa(ipaddr, sizeof(ipaddr), sin->sin_addr);
+        snprintf(port, sizeof(port), "%d", ntohs(sin->sin_port));
+        ast_update_realtime("iaxpeers", "name", peername, "ipaddr", ipaddr, "port", port, "regseconds", regseconds, NULL);
 }
 
 struct create_addr_info {
@@ -5654,6 +5652,8 @@
 	struct iax2_peer *p = data;
 
 	ast_log(LOG_DEBUG, "Expiring registration for peer '%s'\n", p->name);
+	if (ast_test_flag((&globalflags), IAX_RTUPDATE) && (ast_test_flag(p, IAX_TEMPONLY|IAX_RTCACHEFRIENDS)))
+		realtime_update_peer(p->name, &p->addr, 0);
 	/* Reset the address */
 	memset(&p->addr, 0, sizeof(p->addr));
 	/* Reset expire notice */
@@ -5735,8 +5735,14 @@
 		return -1;
 	}
 
-	if (ast_test_flag((&globalflags), IAX_RTUPDATE) && (ast_test_flag(p, IAX_TEMPONLY|IAX_RTCACHEFRIENDS)))
-		realtime_update_peer(name, sin);
+	if (ast_test_flag((&globalflags), IAX_RTUPDATE) && (ast_test_flag(p, IAX_TEMPONLY|IAX_RTCACHEFRIENDS))) {
+		if (sin->sin_addr.s_addr) {
+			time_t nowtime;
+			time(&nowtime);
+			realtime_update_peer(name, sin, nowtime);
+		} else
+			realtime_update_peer(name, sin, 0);
+	}
 	if (inaddrcmp(&p->addr, sin)) {
 		if (iax2_regfunk)
 			iax2_regfunk(p->name, 1);



More information about the asterisk-commits mailing list