[asterisk-commits] rmudgett: branch 1.8 r317670 - /branches/1.8/channels/chan_sip.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Fri May 6 11:19:26 CDT 2011


Author: rmudgett
Date: Fri May  6 11:19:18 2011
New Revision: 317670

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=317670
Log:
Fix SIP connected line updates.

This patch fixes a couple SIP connected line update problems:

1) The connected line needs to be updated when the initial INVITE is sent
if there is a peer callerid configured.  Previously, the connected line
information did not get reported until the call was connected so SIP could
not report connected line information in ringing or progress messages.

2) The connected line should not be updated on initial connect if there is
no connected line information.  Previously, all it did was wipe out any
default preset CONNECTEDLINE information set by the dialplan with empty
strings.

(closes issue #18367)
Reported by: GeorgeKonopacki
Patches:
      issue18367_v1.8.patch uploaded by rmudgett (license 664)
Tested by: rmudgett

Review: https://reviewboard.asterisk.org/r/1199/

Modified:
    branches/1.8/channels/chan_sip.c

Modified: branches/1.8/channels/chan_sip.c
URL: http://svnview.digium.com/svn/asterisk/branches/1.8/channels/chan_sip.c?view=diff&rev=317670&r1=317669&r2=317670
==============================================================================
--- branches/1.8/channels/chan_sip.c (original)
+++ branches/1.8/channels/chan_sip.c Fri May  6 11:19:18 2011
@@ -5375,8 +5375,34 @@
 		res = -1;
 	} else {
 		int xmitres;
+		struct ast_party_connected_line connected;
+		struct ast_set_party_connected_line update_connected;
 
 		sip_pvt_lock(p);
+
+		/* Supply initial connected line information if available. */
+		memset(&update_connected, 0, sizeof(update_connected));
+		ast_party_connected_line_init(&connected);
+		if (!ast_strlen_zero(p->cid_num)
+			|| (p->callingpres & AST_PRES_RESTRICTION) != AST_PRES_ALLOWED) {
+			update_connected.id.number = 1;
+			connected.id.number.valid = 1;
+			connected.id.number.str = (char *) p->cid_num;
+			connected.id.number.presentation = p->callingpres;
+		}
+		if (!ast_strlen_zero(p->cid_name)
+			|| (p->callingpres & AST_PRES_RESTRICTION) != AST_PRES_ALLOWED) {
+			update_connected.id.name = 1;
+			connected.id.name.valid = 1;
+			connected.id.name.str = (char *) p->cid_name;
+			connected.id.name.presentation = p->callingpres;
+		}
+		if (update_connected.id.number || update_connected.id.name) {
+			connected.id.tag = (char *) p->cid_tag;
+			connected.source = AST_CONNECTED_LINE_UPDATE_SOURCE_ANSWER;
+			ast_channel_queue_connected_line_update(ast, &connected, &update_connected);
+		}
+
 		xmitres = transmit_invite(p, SIP_INVITE, 1, 2, uri);
 		sip_pvt_unlock(p);
 		if (xmitres == XMIT_ERROR)
@@ -12380,15 +12406,18 @@
 			ast_set_flag(&p->flags[0], SIP_NEEDREINVITE);
 		}
 	} else {
+		ast_set_flag(&p->flags[1], SIP_PAGE2_CONNECTLINEUPDATE_PEND);
 		if (ast_test_flag(&p->flags[1], SIP_PAGE2_RPID_IMMEDIATE)) {
 			struct sip_request resp;
 
 			if ((p->owner->_state == AST_STATE_RING) && !ast_test_flag(&p->flags[0], SIP_PROGRESS_SENT)) {
+				ast_clear_flag(&p->flags[1], SIP_PAGE2_CONNECTLINEUPDATE_PEND);
 				respprep(&resp, p, "180 Ringing", &p->initreq);
 				add_rpid(&resp, p);
 				send_response(p, &resp, XMIT_UNRELIABLE, 0);
 				ast_set_flag(&p->flags[0], SIP_RINGING);
 			} else if (p->owner->_state == AST_STATE_RINGING) {
+				ast_clear_flag(&p->flags[1], SIP_PAGE2_CONNECTLINEUPDATE_PEND);
 				respprep(&resp, p, "183 Session Progress", &p->initreq);
 				add_rpid(&resp, p);
 				send_response(p, &resp, XMIT_UNRELIABLE, 0);
@@ -12396,8 +12425,6 @@
 			} else {
 				ast_debug(1, "Unable able to send update to '%s' in state '%s'\n", p->owner->name, ast_state2str(p->owner->_state));
 			}
-		} else {
-			ast_set_flag(&p->flags[1], SIP_PAGE2_CONNECTLINEUPDATE_PEND);
 		}
 	}
 }
@@ -19150,20 +19177,20 @@
 			ast_log(LOG_WARNING, "Unable to cancel SIP destruction.  Expect bad things.\n");
 		if (!req->ignore && p->owner) {
 			if (get_rpid(p, req)) {
+				/* Queue a connected line update */
 				ast_party_connected_line_init(&connected);
 				memset(&update_connected, 0, sizeof(update_connected));
-				if (p->cid_num) {
-					update_connected.id.number = 1;
-					connected.id.number.valid = 1;
-					connected.id.number.str = (char *) p->cid_num;
-					connected.id.number.presentation = p->callingpres;
-				}
-				if (p->cid_name) {
-					update_connected.id.name = 1;
-					connected.id.name.valid = 1;
-					connected.id.name.str = (char *) p->cid_name;
-					connected.id.name.presentation = p->callingpres;
-				}
+
+				update_connected.id.number = 1;
+				connected.id.number.valid = 1;
+				connected.id.number.str = (char *) p->cid_num;
+				connected.id.number.presentation = p->callingpres;
+
+				update_connected.id.name = 1;
+				connected.id.name.valid = 1;
+				connected.id.name.str = (char *) p->cid_name;
+				connected.id.name.presentation = p->callingpres;
+
 				connected.id.tag = (char *) p->cid_tag;
 				connected.source = AST_CONNECTED_LINE_UPDATE_SOURCE_ANSWER;
 				ast_channel_queue_connected_line_update(p->owner, &connected,
@@ -19215,18 +19242,17 @@
 				/* Queue a connected line update */
 				ast_party_connected_line_init(&connected);
 				memset(&update_connected, 0, sizeof(update_connected));
-				if (p->cid_num) {
-					update_connected.id.number = 1;
-					connected.id.number.valid = 1;
-					connected.id.number.str = (char *) p->cid_num;
-					connected.id.number.presentation = p->callingpres;
-				}
-				if (p->cid_name) {
-					update_connected.id.name = 1;
-					connected.id.name.valid = 1;
-					connected.id.name.str = (char *) p->cid_name;
-					connected.id.name.presentation = p->callingpres;
-				}
+
+				update_connected.id.number = 1;
+				connected.id.number.valid = 1;
+				connected.id.number.str = (char *) p->cid_num;
+				connected.id.number.presentation = p->callingpres;
+
+				update_connected.id.name = 1;
+				connected.id.name.valid = 1;
+				connected.id.name.str = (char *) p->cid_name;
+				connected.id.name.presentation = p->callingpres;
+
 				connected.id.tag = (char *) p->cid_tag;
 				connected.source = AST_CONNECTED_LINE_UPDATE_SOURCE_ANSWER;
 				ast_channel_queue_connected_line_update(p->owner, &connected,
@@ -19268,26 +19294,37 @@
 			ast_rtp_instance_activate(p->rtp);
 		}
 
-		if (!req->ignore && p->owner && (get_rpid(p, req) || !reinvite)) {
-			/* Queue a connected line update */
-			ast_party_connected_line_init(&connected);
-			memset(&update_connected, 0, sizeof(update_connected));
-			if (p->cid_num) {
-				update_connected.id.number = 1;
-				connected.id.number.valid = 1;
-				connected.id.number.str = (char *) p->cid_num;
-				connected.id.number.presentation = p->callingpres;
-			}
-			if (p->cid_name) {
-				update_connected.id.name = 1;
-				connected.id.name.valid = 1;
-				connected.id.name.str = (char *) p->cid_name;
-				connected.id.name.presentation = p->callingpres;
-			}
-			connected.id.tag = (char *) p->cid_tag;
-			connected.source = AST_CONNECTED_LINE_UPDATE_SOURCE_ANSWER;
-			ast_channel_queue_connected_line_update(p->owner, &connected,
-				&update_connected);
+		if (!req->ignore && p->owner) {
+			int rpid_changed;
+
+			rpid_changed = get_rpid(p, req);
+			if (rpid_changed || !reinvite) {
+				/* Queue a connected line update */
+				ast_party_connected_line_init(&connected);
+				memset(&update_connected, 0, sizeof(update_connected));
+				if (rpid_changed
+					|| !ast_strlen_zero(p->cid_num)
+					|| (p->callingpres & AST_PRES_RESTRICTION) != AST_PRES_ALLOWED) {
+					update_connected.id.number = 1;
+					connected.id.number.valid = 1;
+					connected.id.number.str = (char *) p->cid_num;
+					connected.id.number.presentation = p->callingpres;
+				}
+				if (rpid_changed
+					|| !ast_strlen_zero(p->cid_name)
+					|| (p->callingpres & AST_PRES_RESTRICTION) != AST_PRES_ALLOWED) {
+					update_connected.id.name = 1;
+					connected.id.name.valid = 1;
+					connected.id.name.str = (char *) p->cid_name;
+					connected.id.name.presentation = p->callingpres;
+				}
+				if (update_connected.id.number || update_connected.id.name) {
+					connected.id.tag = (char *) p->cid_tag;
+					connected.source = AST_CONNECTED_LINE_UPDATE_SOURCE_ANSWER;
+					ast_channel_queue_connected_line_update(p->owner, &connected,
+						&update_connected);
+				}
+			}
 		}
 
 		/* Parse contact header for continued conversation */
@@ -21160,20 +21197,20 @@
 	if (get_rpid(p, req)) {
 		struct ast_party_connected_line connected;
 		struct ast_set_party_connected_line update_connected;
+
 		ast_party_connected_line_init(&connected);
 		memset(&update_connected, 0, sizeof(update_connected));
-		if (p->cid_num) {
-			update_connected.id.number = 1;
-			connected.id.number.valid = 1;
-			connected.id.number.str = (char *) p->cid_num;
-			connected.id.number.presentation = p->callingpres;
-		}
-		if (p->cid_name) {
-			update_connected.id.name = 1;
-			connected.id.name.valid = 1;
-			connected.id.name.str = (char *) p->cid_name;
-			connected.id.name.presentation = p->callingpres;
-		}
+
+		update_connected.id.number = 1;
+		connected.id.number.valid = 1;
+		connected.id.number.str = (char *) p->cid_num;
+		connected.id.number.presentation = p->callingpres;
+
+		update_connected.id.name = 1;
+		connected.id.name.valid = 1;
+		connected.id.name.str = (char *) p->cid_name;
+		connected.id.name.presentation = p->callingpres;
+
 		connected.id.tag = (char *) p->cid_tag;
 		connected.source = AST_CONNECTED_LINE_UPDATE_SOURCE_TRANSFER;
 		ast_channel_queue_connected_line_update(p->owner, &connected, &update_connected);
@@ -21505,18 +21542,17 @@
 
 				ast_party_connected_line_init(&connected);
 				memset(&update_connected, 0, sizeof(update_connected));
-				if (p->cid_num) {
-					update_connected.id.number = 1;
-					connected.id.number.valid = 1;
-					connected.id.number.str = (char *) p->cid_num;
-					connected.id.number.presentation = p->callingpres;
-				}
-				if (p->cid_name) {
-					update_connected.id.name = 1;
-					connected.id.name.valid = 1;
-					connected.id.name.str = (char *) p->cid_name;
-					connected.id.name.presentation = p->callingpres;
-				}
+
+				update_connected.id.number = 1;
+				connected.id.number.valid = 1;
+				connected.id.number.str = (char *) p->cid_num;
+				connected.id.number.presentation = p->callingpres;
+
+				update_connected.id.name = 1;
+				connected.id.name.valid = 1;
+				connected.id.name.str = (char *) p->cid_name;
+				connected.id.name.presentation = p->callingpres;
+
 				connected.id.tag = (char *) p->cid_tag;
 				connected.source = AST_CONNECTED_LINE_UPDATE_SOURCE_TRANSFER;
 				ast_channel_queue_connected_line_update(p->owner, &connected,




More information about the asterisk-commits mailing list