[svn-commits] oej: branch oej/siptransdirection r45285 - /team/oej/siptransdirection/channels/

svn-commits at lists.digium.com svn-commits at lists.digium.com
Mon Oct 16 13:26:16 MST 2006


Author: oej
Date: Mon Oct 16 15:26:16 2006
New Revision: 45285

URL: http://svn.digium.com/view/asterisk?rev=45285&view=rev
Log:
Trying to add some sense of direction in a transaction.

If we have an OUTBOUND call, we still may get a RE-INVITE which
creates an inbound transaction.

On an INBOUND call, we might send a RE-INVITE, which creates
an outbound transaction.

This outbound/inbound stuff confuses the CANCEL and the ACK
and mixes some TO/FROM headers and tags.

This patch is *not* tested yet.

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=45285&r1=45284&r2=45285&view=diff
==============================================================================
--- team/oej/siptransdirection/channels/chan_sip.c (original)
+++ team/oej/siptransdirection/channels/chan_sip.c Mon Oct 16 15:26:16 2006
@@ -449,7 +449,6 @@
 #define INC_CALL_LIMIT	1
 
 static struct ast_codec_pref prefs;
-
 
 /*! \brief sip_request: The data grabbed from the UDP socket */
 struct sip_request {
@@ -4142,6 +4141,7 @@
 	char *c, *n;
 	char *ot, *of;
 	int is_strict = 0;	/* Strict routing flag */
+	int is_outbound = ast_test_flag(p, SIP_OUTGOING);	/* Incoming session */
 
 	memset(req, 0, sizeof(struct sip_request));
 	
@@ -4199,14 +4199,24 @@
 	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)
+		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 (ast_test_flag(p, 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, SIP_OUTGOING))
+		else if (is_outbound)
 			snprintf(newto, sizeof(newto), "%s;tag=%s", ot, p->tag);
 		else
 			snprintf(newto, sizeof(newto), "%s", ot);
@@ -4214,13 +4224,13 @@
 	}
 
 	if (ast_test_flag(p, SIP_OUTGOING)) {
-		add_header(req, "From", of);
-		add_header(req, "To", ot);
-	} else {
-		add_header(req, "From", ot);
-		add_header(req, "To", of);
-	}
-	add_header(req, "Contact", p->our_contact);
+		add_header(req, "From", is_outbound ? of : ot);
+		add_header(req, "To",  is_outbound ? ot : of);
+	}
+
+	/* Don't add Contact for BYE and Cancel requests */
+	if (sipmethod != SIP_BYE && sipmethod != SIP_CANCEL)
+		add_header(req, "Contact", p->our_contact);
 	copy_header(req, orig, "Call-ID");
 	add_header(req, "CSeq", tmp);
 



More information about the svn-commits mailing list