[asterisk-commits] oej: trunk r46275 - /trunk/channels/chan_sip.c

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Wed Oct 25 13:12:07 MST 2006


Author: oej
Date: Wed Oct 25 15:12:06 2006
New Revision: 46275

URL: http://svn.digium.com/view/asterisk?rev=46275&view=rev
Log:
First stab at transaction direction fix, this for trunk for testing

Modified:
    trunk/channels/chan_sip.c

Modified: trunk/channels/chan_sip.c
URL: http://svn.digium.com/view/asterisk/trunk/channels/chan_sip.c?rev=46275&r1=46274&r2=46275&view=diff
==============================================================================
--- trunk/channels/chan_sip.c (original)
+++ trunk/channels/chan_sip.c Wed Oct 25 15:12:06 2006
@@ -5546,6 +5546,7 @@
 	const char *c;
 	const char *ot, *of;
 	int is_strict = FALSE;		/*!< Strict routing flag */
+	int is_outbound = ast_test_flag(&p->flags[0], SIP_OUTGOING);	/* Session direction */
 
 	memset(req, 0, sizeof(struct sip_request));
 	
@@ -5567,6 +5568,14 @@
 		if (sipdebug)
 			ast_log(LOG_DEBUG, "Strict routing enforced for session %s\n", p->callid);
 	}
+	
+	/* Let's try to figure out the direction of this transaction within the dialog */
+	/* If we're sending an ACK, we DID send the INVITE - which means outbound.
+	   INVITE's are outbound transactions, always 
+	*/
+	if (sipmethod == SIP_ACK || sipmethod == SIP_INVITE)
+		is_outbound = TRUE;
+	/* In other case's, let's follow the flow of the dialog */
 
 	if (sipmethod == SIP_CANCEL)
 		c = p->initreq.rlPart2;	/* Use original URI */
@@ -5584,7 +5593,7 @@
 	else {
 		char *n;
 		/* We have no URI, use To: or From:  header as URI (depending on direction) */
-		ast_copy_string(stripped, get_header(orig, (ast_test_flag(&p->flags[0], SIP_OUTGOING)) ? "To" : "From"),
+		ast_copy_string(stripped, get_header(orig, is_outbound ? "To" : "From"),
 				sizeof(stripped));
 		n = get_in_brackets(stripped);
 		c = strsep(&n, ";");	/* trim ; and beyond */
@@ -5607,16 +5616,16 @@
 	if (!strcasestr(ot, "tag=") && sipmethod != SIP_CANCEL) {
 		/* Add the proper tag if we don't have it already.  If they have specified
 		   their tag, use it.  Otherwise, use our own tag */
-		if (ast_test_flag(&p->flags[0], SIP_OUTGOING) && !ast_strlen_zero(p->theirtag))
+		if (is_outbound && !ast_strlen_zero(p->theirtag))
 			snprintf(newto, sizeof(newto), "%s;tag=%s", ot, p->theirtag);
-		else if (!ast_test_flag(&p->flags[0], SIP_OUTGOING))
+		else if (!is_outbound)
 			snprintf(newto, sizeof(newto), "%s;tag=%s", ot, p->tag);
 		else
 			snprintf(newto, sizeof(newto), "%s", ot);
 		ot = newto;
 	}
 
-	if (ast_test_flag(&p->flags[0], SIP_OUTGOING)) {
+	if (is_outbound) {
 		add_header(req, "From", of);
 		add_header(req, "To", ot);
 	} else {



More information about the asterisk-commits mailing list