diff options
author | oej <oej@f38db490-d61c-443f-a65b-d21fe96a405b> | 2006-10-25 20:12:06 +0000 |
---|---|---|
committer | oej <oej@f38db490-d61c-443f-a65b-d21fe96a405b> | 2006-10-25 20:12:06 +0000 |
commit | 97acb8526e4f405893a980f2411736929c0a05eb (patch) | |
tree | 7dfddafacf368984bc1a1c281f605649f647b9f7 | |
parent | f014525e0054f1308b4ff8bac05374acdba3c3b8 (diff) |
First stab at transaction direction fix, this for trunk for testing
git-svn-id: http://svn.digium.com/svn/asterisk/trunk@46275 f38db490-d61c-443f-a65b-d21fe96a405b
-rw-r--r-- | channels/chan_sip.c | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/channels/chan_sip.c b/channels/chan_sip.c index 98b1414b3..7116c09f2 100644 --- a/channels/chan_sip.c +++ b/channels/chan_sip.c @@ -5546,6 +5546,7 @@ static int reqprep(struct sip_request *req, struct sip_pvt *p, int sipmethod, in 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 @@ static int reqprep(struct sip_request *req, struct sip_pvt *p, int sipmethod, in 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 @@ static int reqprep(struct sip_request *req, struct sip_pvt *p, int sipmethod, in 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 @@ static int reqprep(struct sip_request *req, struct sip_pvt *p, int sipmethod, in 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 { |