[asterisk-commits] oej: branch oej/siptransdirection r46356 - /team/oej/siptransdirection/channels/

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Fri Oct 27 06:36:05 MST 2006


Author: oej
Date: Fri Oct 27 08:36:05 2006
New Revision: 46356

URL: http://svn.digium.com/view/asterisk?rev=46356&view=rev
Log:
Testing...

Modified:
    team/oej/siptransdirection/channels/chan_sip.c

Modified: team/oej/siptransdirection/channels/chan_sip.c
URL: http://svn.digium.com/view/asterisk/team/oej/siptransdirection/channels/chan_sip.c?rev=46356&r1=46355&r2=46356&view=diff
==============================================================================
--- team/oej/siptransdirection/channels/chan_sip.c (original)
+++ team/oej/siptransdirection/channels/chan_sip.c Fri Oct 27 08:36:05 2006
@@ -4154,7 +4154,7 @@
 	char tmp[80];
 	char newto[256];
 	char *c, *n;
-	char *ot, *of;
+	char *original_to, *original_from;
 	int is_strict = 0;	/* Strict routing flag */
 	int is_outbound = ast_test_flag(p, SIP_OUTGOING);	/* Incoming session */
 
@@ -4191,7 +4191,7 @@
 		c = p->uri;
 	} else {
 		/* We have no URI, use To: or From:  header as URI (depending on direction) */
-		c = get_header(orig, (ast_test_flag(p, SIP_OUTGOING)) ? "To" : "From");
+		c = get_header(orig, is_outbound ? "To" : "From");
 		ast_copy_string(stripped, c, sizeof(stripped));
 		c = get_in_brackets(stripped);
 		n = strchr(c, ';');
@@ -4211,36 +4211,36 @@
 			add_route(req, p->route);
 	}
 
-	ot = get_header(orig, "To");
-	of = get_header(orig, "From");
-
-	/* Let's try to figure out where this transaction is heading */
-	/* If we're sending an ACK, we did send the INVITE, regardless
-	   of the direction of the call  */
-	/* If we are sending an INVITE, it's outbound again (could be a re-invite) */
-	if (sipmethod == SIP_ACK || sipmethod == SIP_INVITE)
+	original_to = get_header(orig, "To");
+	original_from = get_header(orig, "From");
+
+	/* The dialog direction determines if our tag belongs to the to or
+		from header 
+	 */
+	/* If we send an BYE, ACK or an INVITE, this this transaction is outbound */
+	if (sipmethod == SIP_BYE || sipmethod == SIP_ACK || sipmethod == SIP_INVITE)
 		is_outbound = 1;
 
-	/* In other cases, let's stick with the direction of the dialog */
-
-	/* Add tag *unless* this is a CANCEL, in which case we need to send it exactly
-	   as our original request, including tag (or presumably lack thereof) */
-	
-	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 (is_outbound && !ast_strlen_zero(p->theirtag))
-			snprintf(newto, sizeof(newto), "%s;tag=%s", ot, p->theirtag);
-		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, SIP_OUTGOING)) {
-		add_header(req, "From", is_outbound ? of : ot);
-		add_header(req, "To",  is_outbound ? ot : of);
+
+	/* Do we need to add tags ? */
+	if (!strcasestr(original_to, "tag=") && sipmethod != SIP_CANCEL) {
+		if (is_outbound) {
+			if (!ast_strlen_zero(p->theirtag))
+				snprintf(newto, sizeof(newto), "%s;tag=%s", original_to, p->theirtag);
+			else 
+				snprintf(newto, sizeof(newto), "%s;tag=%s", original_to, p->tag);	/* XXX Why? */
+		} else
+			snprintf(newto, sizeof(newto), "%s", original_to);
+		original_to = newto;
+	}
+
+	/* If we're sending opposite from the original direction, change headers (compared with initreq) */
+	if (is_outbound != ast_test_flag(p, SIP_OUTGOING)) {
+		add_header(req, "From", original_to);
+		add_header(req, "To",  original_from);
+	} else {
+		add_header(req, "From", original_from);	
+		add_header(req, "To",  original_to);
 	}
 
 	/* Don't add Contact for BYE and Cancel requests */



More information about the asterisk-commits mailing list