[asterisk-commits] jdixon: branch jdixon/chan_usbradio-1.4 r175769 - /team/jdixon/chan_usbradio-...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Sat Feb 14 03:24:59 CST 2009


Author: jdixon
Date: Sat Feb 14 03:24:59 2009
New Revision: 175769

URL: http://svn.digium.com/svn-view/asterisk?view=rev&rev=175769
Log:
Got caller disconnect working and fixed segfault upon disconnection

Modified:
    team/jdixon/chan_usbradio-1.4/channels/chan_irlp.c

Modified: team/jdixon/chan_usbradio-1.4/channels/chan_irlp.c
URL: http://svn.digium.com/svn-view/asterisk/team/jdixon/chan_usbradio-1.4/channels/chan_irlp.c?view=diff&rev=175769&r1=175768&r2=175769
==============================================================================
--- team/jdixon/chan_usbradio-1.4/channels/chan_irlp.c (original)
+++ team/jdixon/chan_usbradio-1.4/channels/chan_irlp.c Sat Feb 14 03:24:59 2009
@@ -261,6 +261,7 @@
 time_t keepalive = 0;
 static char db_active = 'a';
 static char db_loading = 0;
+static unsigned long xmagic = 0;
 
 #ifdef OLD_ASTERISK
 #define ast_free free
@@ -309,6 +310,7 @@
 	proto = default_proto;
 #endif
 	time(&lingertime);
+	xmagic = 0;
 	keepalive = 0;
 	in_node = 0;
 	nodenum = 0;
@@ -705,13 +707,13 @@
     *p++ = 201;
     *p++ = 0;
     *p++ = 1;
-    *((long *) p) = htonl(0x0310f987);
+    *((long *) p) = xmagic; /* htonl(something); */
     p += 4;
     hl = 8;
 
     rp = (struct rtcp_t *)p;
     *((short *) p) = htons((2 << 14) | 203 | (1 << 8));
-    rp->r.bye.src[0] = htonl(0x0310f987);
+    rp->r.bye.src[0] = xmagic; /* (htonl(something)) */
     ap = (unsigned char *) rp->r.sdes.item;
     l = 0; 
     if (reason != NULL) {
@@ -740,29 +742,13 @@
     return l;
 }
 
-static void send_bye(char *reason)
-{
-char	buf[200],ipbuf[100];
+static void send_bye_ip(char *reason, char *ipbuf)
+{
+char	buf[200];
 int	len,x;
 struct sockaddr_in sin;
 
-	if (!*remote_irlp_node_ip)
-	{
-#ifdef	STNTYPE
-		char *cp;
-
-		cp = irlp_read_file(IRLP_ROOT,"calledip");
-		if (!cp) return;
-		if (cp[strlen(cp) - 1] == '\n')
-			cp[strlen(cp) - 1] = 0;
-		strncpy(ipbuf,cp,sizeof(ipbuf) - 1);
-		ast_free(cp);
-#endif
-	}
-	else
-	{
-		strncpy(ipbuf,remote_irlp_node_ip,sizeof(buf) - 1);
-	}
+	if ((!ipbuf) || (*ipbuf < '0') || (*ipbuf > '9')) return;
         sin.sin_family = AF_INET;
         sin.sin_addr.s_addr = inet_addr(ipbuf);
         sin.sin_port = htons(tx_audio_port + 1);
@@ -772,26 +758,34 @@
 	        sendto((alt_ctrl_sock != -1) ? alt_ctrl_sock : ctrl_sock,buf,len,
         	        0,(struct sockaddr *)&sin,sizeof(struct sockaddr));
 	}
+	sprintf(buf,"nc %s 15425 < /dev/null > /dev/null &",ipbuf);
+	ast_safe_system(buf);  
 	return;
 }
 
-static void send_bye_ip(char *reason, char *ipbuf)
-{
+static void send_bye(char *reason)
+{
+char	ipbuf[100];
+#ifdef	STNTYPE
 char	buf[200];
-int	len,x;
-struct sockaddr_in sin;
-
-        sin.sin_family = AF_INET;
-        sin.sin_addr.s_addr = inet_addr(ipbuf);
-        sin.sin_port = htons(tx_audio_port + 1);
-	len = rtcp_make_bye((unsigned char *)buf,reason);
-	for(x = 0; x < 1; x++)
-	{	
-printf("foop: sending bye to %s\n",ipbuf);
-	        sendto((alt_ctrl_sock != -1) ? alt_ctrl_sock : ctrl_sock,buf,len,
-        	        0,(struct sockaddr *)&sin,sizeof(struct sockaddr));
-	}
-	return;
+
+	if (!*remote_irlp_node_ip)
+	{
+		char *cp;
+
+		cp = irlp_read_file(IRLP_ROOT,"calledip");
+		if (!cp) return;
+		if (cp[strlen(cp) - 1] == '\n')
+			cp[strlen(cp) - 1] = 0;
+		strncpy(ipbuf,cp,sizeof(ipbuf) - 1);
+		ast_free(cp);
+	}
+	else
+#endif
+	{
+		strncpy(ipbuf,remote_irlp_node_ip,sizeof(ipbuf) - 1);
+	}
+	send_bye_ip(reason,ipbuf);
 }
 
 static void send_keepalive(void)
@@ -889,7 +883,6 @@
 		ast_log(LOG_WARNING, "irlp_call called unknown node %04d on %s\n", nodenum,ast->name);
 		return -1;
 	}
-printf("foop: calling node %s on %s\n",str,cp);
         sin.sin_family = AF_INET;
         sin.sin_addr.s_addr = inet_addr(cp);
         sin.sin_port = htons(tx_audio_port + 1);
@@ -1059,13 +1052,14 @@
 		      {
 	                 if (!is_rtcp_bye((unsigned char *)buf,recvlen))
 			 {
+			    if (!xmagic) memcpy(&xmagic,buf + 4,sizeof(xmagic));
 	                    if (strncmp(ip, "127.0.0.1",IRLP_IP_SIZE) != 0)
 			    {
 
-				if (remote_irlp_node_ip[0] && strcasecmp(remote_irlp_node_ip,ip))
+				if (remote_irlp_node_ip[0] && strcasecmp(remote_irlp_node_ip,ip)) 
 				{
 					ast_log(LOG_NOTICE,"irlp node attempted connect from %s while busy\n", ip);
-					send_bye_ip("busy",ip);
+					send_bye_ip("Exiting Speak Freely",ip);
 				} else
 	                       if (strncmp(remote_irlp_node_ip, ip, IRLP_IP_SIZE) != 0) 
 			       {
@@ -1339,6 +1333,7 @@
 		ast_log(LOG_WARNING, "Asked to hangup channel not connected\n");
 		return 0;
 	}
+	send_bye("disconnected");
 	reset_stuff();
 	irlp_destroy(p);
 	curcall = 0;
@@ -1350,7 +1345,6 @@
 #ifdef	STNTYPE
 	ast_safe_system(IRLP_END);
 #endif
-	send_bye("disconnected");
 	return 0;
 }
 




More information about the asterisk-commits mailing list