[Asterisk-cvs] asterisk/channels chan_sip.c,1.875,1.876

kpfleming kpfleming
Tue Oct 4 19:42:22 CDT 2005


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

Modified Files:
	chan_sip.c 
Log Message:
fix various state-related bugs (issue #5369, with mod to return AST_DEVICE_INUSE)


Index: chan_sip.c
===================================================================
RCS file: /usr/cvsroot/asterisk/channels/chan_sip.c,v
retrieving revision 1.875
retrieving revision 1.876
diff -u -d -r1.875 -r1.876
--- chan_sip.c	4 Oct 2005 23:28:57 -0000	1.875
+++ chan_sip.c	4 Oct 2005 23:38:09 -0000	1.876
@@ -715,7 +715,7 @@
 	struct ast_variable *chanvars;	/* Variables to set for channel created by user */
 };
 
-/* Structure for SIP peer data, we place calls to peers if registred  or fixed IP address (host) */
+/* Structure for SIP peer data, we place calls to peers if registered  or fixed IP address (host) */
 struct sip_peer {
 	ASTOBJ_COMPONENTS(struct sip_peer);	/* name, refcount, objflags,  object pointers */
 					/* peer->name is the unique name of this object */
@@ -731,7 +731,7 @@
 	char regexten[AST_MAX_EXTENSION]; /* Extension to register (if regcontext is used) */
 	char fromuser[80];		/* From: user when calling this peer */
 	char fromdomain[MAXHOSTNAMELEN];	/* From: domain when calling this peer */
-	char fullcontact[256];		/* Contact registred with us (not in sip.conf) */
+	char fullcontact[256];		/* Contact registered with us (not in sip.conf) */
 	char cid_num[80];		/* Caller ID num */
 	char cid_name[80];		/* Caller ID name */
 	int callingpres;		/* Calling id presentation */
@@ -4880,6 +4880,10 @@
 	char *pidfstate = "--";
 	char *pidfnote= "Ready";
 
+	memset(from, 0, sizeof(from));
+	memset(to, 0, sizeof(to));
+	memset(tmp, 0, sizeof(tmp));
+
 	switch (state) {
 	case (AST_EXTENSION_RINGING | AST_EXTENSION_INUSE):
 		if (global_notifyringing)
@@ -4932,7 +4936,6 @@
 		}
 	}
 
-	memset(from, 0, sizeof(from));
 	ast_copy_string(from, get_header(&p->initreq, "From"), sizeof(from));
 	c = get_in_brackets(from);
 	if (strncmp(c, "sip:", 4)) {
@@ -4943,7 +4946,6 @@
 		*a = '\0';
 	mfrom = c;
 
-	memset(to, 0, sizeof(to));
 	ast_copy_string(to, get_header(&p->initreq, "To"), sizeof(to));
 	c = get_in_brackets(to);
 	if (strncmp(c, "sip:", 4)) {
@@ -4993,10 +4995,10 @@
 		break;
 	case PIDF_XML: /* Eyebeam supports this format */
 		ast_build_string(&t, &maxbytes, "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n");
-		ast_build_string(&t, &maxbytes, "<presence xmlns=\"urn:ietf:params:xml:ns:pidf\" \nxmlns:pp=\"urn:ietf:params:xml:ns:pidf:person\"\nxmlns:es=\"urn:ietf:params:xml:ns:pidf:rpid:status:rpid-status\"\nentity=\"%s\">\n", mfrom);
+		ast_build_string(&t, &maxbytes, "<presence xmlns=\"urn:ietf:params:xml:ns:pidf\" \nxmlns:pp=\"urn:ietf:params:xml:ns:pidf:person\"\nxmlns:es=\"urn:ietf:params:xml:ns:pidf:rpid:status:rpid-status\"\nxmlns:ep=\"urn:ietf:params:xml:ns:pidf:rpid:rpid-person\"\nentity=\"%s\">\n", mfrom);
 		ast_build_string(&t, &maxbytes, "<pp:person><status>\n");
 		if (pidfstate[0] != '-')
-			ast_build_string(&t, &maxbytes, "<es:activities><es:activity>%s</es:activity></es:activities>\n", pidfstate);
+			ast_build_string(&t, &maxbytes, "<ep:activities><ep:%s/></ep:activities>\n", pidfstate);
 		ast_build_string(&t, &maxbytes, "</status></pp:person>\n");
 		ast_build_string(&t, &maxbytes, "<note>%s</note>\n", pidfnote); /* Note */
 		ast_build_string(&t, &maxbytes, "<tuple id=\"%s\">\n", p->exten); /* Tuple start */
@@ -5032,7 +5034,7 @@
 }
 
 /*--- transmit_notify_with_mwi: Notify user of messages waiting in voicemail ---*/
-/*      Notification only works for registred peers with mailbox= definitions
+/*      Notification only works for registered peers with mailbox= definitions
  *      in sip.conf
  *      We use the SIP Event package message-summary
  *      MIME type defaults to  "application/simple-message-summary";
@@ -5245,7 +5247,7 @@
 			p->theirtag[0]='\0';	/* forget their old tag, so we don't match tags when getting response */
 		}
 	} else {
-		/* Build callid for registration if we haven't registred before */
+		/* Build callid for registration if we haven't registered before */
 		if (!r->callid_valid) {
 			build_callid(r->callid, sizeof(r->callid), __ourip, default_fromdomain);
 			r->callid_valid = 1;
@@ -6218,6 +6220,8 @@
 	switch(state) {
 	case AST_EXTENSION_DEACTIVATED:	/* Retry after a while */
 	case AST_EXTENSION_REMOVED:	/* Extension is gone */
+		if (p->autokillid > -1)
+			sip_cancel_destroy(p);	/* Remove subscription expiry for renewals */
 		sip_scheddestroy(p, 15000);	/* Delete subscription in 15 secs */
 		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;
@@ -6969,7 +6973,7 @@
 	if (!user) {
 		/* If we didn't find a user match, check for peers */
 		/* Look for peer based on the IP address we received data from */
-		/* If peer is registred from this IP address or have this as a default
+		/* If peer is registered from this IP address or have this as a default
 		   IP address, this call is from the peer 
  		*/
 		peer = find_peer(NULL, &p->recv, 1);
@@ -11205,6 +11209,20 @@
 }
 
 /*--- sip_devicestate: Part of PBX channel interface ---*/
+
+/* Return values:---
+	If we have qualify on and the device is not reachable, regardless of registration
+	state we return AST_DEVICE_UNAVAILABLE
+
+	For peers with call limit:
+		not registered			AST_DEVICE_UNAVAILABLE
+		registered, no call		AST_DEVICE_NOT_INUSE
+		registered, calls possible	AST_DEVICE_INUSE
+		registered, call limit reached	AST_DEVICE_BUSY
+	For peers without call limit:
+		not registered			AST_DEVICE_UNAVAILABLE
+		registered			AST_DEVICE_UNKNOWN
+*/
 static int sip_devicestate(void *data)
 {
 	char *host;
@@ -11221,7 +11239,7 @@
 		host = tmp + 1;
 
 	if (option_debug > 2) 
-		ast_log(LOG_DEBUG, "Checking device state for DNS host %s\n", host);
+		ast_log(LOG_DEBUG, "Checking device state for peer %s\n", host);
 
 	if ((p = find_peer(host, NULL, 1))) {
 		if (p->addr.sin_addr.s_addr || p->defaddr.sin_addr.s_addr) {
@@ -11232,8 +11250,10 @@
 			} else {
 				/* qualify is not on, or the peer is responding properly */
 				/* check call limit */
-				if (p->call_limit && (p->inUse >= p->call_limit))
+				if (p->call_limit && (p->inUse == p->call_limit))
 					res = AST_DEVICE_BUSY;
+				else if (p->call_limit && p->inUse)
+					res = AST_DEVICE_INUSE;
 				else if (p->call_limit)
 					res = AST_DEVICE_NOT_INUSE;
 				else
@@ -11314,7 +11334,7 @@
 	build_callid(p->callid, sizeof(p->callid), p->ourip, p->fromdomain);
 	
 	/* We have an extension to call, don't use the full contact here */
-	/* This to enable dialling registred peers with extension dialling,
+	/* This to enable dialling registered peers with extension dialling,
 	   like SIP/peername/extension 	
 	   SIP/peername will still use the full contact */
 	if (ext) {




More information about the svn-commits mailing list