[Asterisk-cvs] asterisk/channels chan_sip.c,1.829,1.830

kpfleming kpfleming
Tue Aug 30 17:33:28 CDT 2005


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

Modified Files:
	chan_sip.c 
Log Message:
don't terminate subscriptions before they should be (issue #5063)


Index: chan_sip.c
===================================================================
RCS file: /usr/cvsroot/asterisk/channels/chan_sip.c,v
retrieving revision 1.829
retrieving revision 1.830
diff -u -d -r1.829 -r1.830
--- chan_sip.c	30 Aug 2005 21:26:32 -0000	1.829
+++ chan_sip.c	30 Aug 2005 21:34:41 -0000	1.830
@@ -1221,6 +1221,15 @@
 	struct sip_pvt *p = data;
 
 	p->autokillid = -1;
+
+	/* If this is a subscription, tell the phone that we got a timeout */
+	if (p->subscribed) {
+		p->subscribed = TIMEOUT;
+		transmit_state_notify(p, AST_EXTENSION_DEACTIVATED, 1, 1);	/* Send first notification */
+		p->subscribed = NONE;
+		append_history(p, "Subscribestatus", "timeout");
+		return 10000;	/* Reschedule this destruction so that we know that it's gone */
+	}
 	ast_log(LOG_DEBUG, "Auto destroying call '%s'\n", p->callid);
 	append_history(p, "AutoDestroy", "");
 	if (p->owner) {
@@ -1243,11 +1252,6 @@
 		append_history(p, "SchedDestroy", tmp);
 	}
 
-	/* If this is a subscription, tell the phone that we got a timeout */
-	if (p->subscribed) {
-		p->subscribed = TIMEOUT;
-		transmit_state_notify(p, AST_EXTENSION_DEACTIVATED, 1, 1);	/* Send first notification */
-	}
 	if (p->autokillid > -1)
 		ast_sched_del(sched, p->autokillid);
 	p->autokillid = ast_sched_add(sched, ms, __sip_autodestruct, p);
@@ -5887,6 +5891,7 @@
 		ast_verbose(VERBOSE_PREFIX_2 "Extension state: Watcher for hint %s %s. Notify User %s\n", exten, state == AST_EXTENSION_DEACTIVATED ? "deactivated" : "removed", p->username);
 		p->stateid = -1;
 		p->subscribed = NONE;
+		append_history(p, "Subscribestatus", state == AST_EXTENSION_REMOVED ? "HintRemoved" : "Deactivated");
 		break;
 	default:	/* Tell user */
 		p->laststate = state;
@@ -7932,7 +7937,7 @@
 		if (!strncasecmp(cur->callid, argv[3],len)) {
 			ast_cli(fd,"\n");
 			if (cur->subscribed != NONE)
-				ast_cli(fd, "  * Subscription\n");
+				ast_cli(fd, "  * Subscription (type: %s)\n", subscription_type2str(cur->subscribed));
 			else
 				ast_cli(fd, "  * SIP Call\n");
 			ast_cli(fd, "  Direction:              %s\n", ast_test_flag(cur, SIP_OUTGOING)?"Outgoing":"Incoming");
@@ -9918,9 +9923,8 @@
 	int gotdest;
 	int res = 0;
 	int firststate = 0;
-	struct ast_channel *c=NULL;
 
-	if (p->initreq.headers) {
+	if (p->initreq.headers) {	
 		/* We already have a dialog */
 		if (p->initreq.method != SIP_SUBSCRIBE) {
 			/* This is a SUBSCRIBE within another SIP dialog, which we do not support */
@@ -9934,7 +9938,7 @@
 				ast_log(LOG_DEBUG, "Got a re-subscribe on existing subscription %s\n", p->callid);
 		}
 	}
-	if (!ignore) {
+	if (!ignore && !p->initreq.headers) {
 		/* Use this as the basis */
 		if (debug)
 			ast_verbose("Using latest SUBSCRIBE request as basis request\n");
@@ -9942,7 +9946,7 @@
 		ast_clear_flag(p, SIP_OUTGOING);
 		copy_request(&p->initreq, req);
 		check_via(p, req);
-	} else if (debug)
+	} else if (debug && ignore)
 		ast_verbose("Ignoring this SUBSCRIBE request\n");
 
 	if (!p->lastinvite) {
@@ -9976,8 +9980,9 @@
 			char *event = get_header(req, "Event");	/* Get Event package name */
 			char *accept = get_header(req, "Accept");
 
-			/* Initialize tag */	
-			p->tag = rand();
+			/* Initialize tag for new subscriptions */	
+			if (!p->tag)
+				p->tag = rand();
 
 			if (!strcmp(event, "presence") || !strcmp(event, "dialog")) { /* Presence, RFC 3842 */
 
@@ -10044,8 +10049,7 @@
 				return 0;
 			}
 		}
-	} else 
-		c = p->owner;
+	}
 
 	if (!ignore && p)
 		p->lastinvite = seqno;
@@ -10064,8 +10068,11 @@
 		if (sipdebug || option_debug > 1)
 			ast_log(LOG_DEBUG, "Adding subscription for extension %s context %s for peer %s\n", p->exten, p->context, p->username);
 		transmit_response(p, "200 OK", req);
+		if (p->autokillid > -1)
+			sip_cancel_destroy(p);	/* Remove subscription expiry for renewals */
 		sip_scheddestroy(p, (p->expiry + 10) * 1000);	/* Set timer for destruction of call at expiration */
 		transmit_state_notify(p, firststate, 1, 1);	/* Send first notification */
+		append_history(p, "Subscribestatus", "active");
 	}
 	return 1;
 }




More information about the svn-commits mailing list