From f3efc756adf372a435bfac43114a1c5034b787d4 Mon Sep 17 00:00:00 2001 From: "Kevin P. Fleming" Date: Thu, 9 Jun 2005 22:41:18 +0000 Subject: allow transfer-to number for SIP transfers to contain an '@' (and enforce the max-forwards restriction for these transfers) (bug #4048) git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@5894 65c4cc65-6c06-0410-ace0-fbb531ad65f3 --- channels/chan_sip.c | 39 ++++++++++++++++++++++++++------------- 1 file changed, 26 insertions(+), 13 deletions(-) (limited to 'channels') diff --git a/channels/chan_sip.c b/channels/chan_sip.c index 7832542e7..3fbf3d9dd 100755 --- a/channels/chan_sip.c +++ b/channels/chan_sip.c @@ -2251,6 +2251,8 @@ static int sip_senddigit(struct ast_channel *ast, char digit) return res; } +#define DEFAULT_MAX_FORWARDS 70 + /*--- sip_transfer: Transfer SIP call */ static int sip_transfer(struct ast_channel *ast, const char *dest) @@ -4826,6 +4828,7 @@ static int transmit_refer(struct sip_pvt *p, const char *dest) char from[256]; char *of, *c; char referto[256]; + char tmp[80]; if (ast_test_flag(p, SIP_OUTGOING)) of = get_header(&p->initreq, "To"); @@ -4839,7 +4842,9 @@ static int transmit_refer(struct sip_pvt *p, const char *dest) } else of += 4; /* Get just the username part */ - if ((c = strchr(of, '@'))) { + if ((c = strchr(dest, '@'))) { + c = NULL; + } else if ((c = strchr(of, '@'))) { *c = '\0'; c++; } @@ -4849,16 +4854,26 @@ static int transmit_refer(struct sip_pvt *p, const char *dest) snprintf(referto, sizeof(referto), "", dest); } - /* save in case we get 407 challenge */ - ast_copy_string(p->refer_to, referto, sizeof(p->refer_to)); - ast_copy_string(p->referred_by, p->our_contact, sizeof(p->referred_by)); - - reqprep(&req, p, SIP_REFER, 0, 1); - add_header(&req, "Refer-To", referto); - if (!ast_strlen_zero(p->our_contact)) - add_header(&req, "Referred-By", p->our_contact); - add_blank_header(&req); - return send_request(p, &req, 1, p->ocseq); + ast_copy_string(tmp, get_header(&p->initreq, "Max-Forwards"), sizeof(tmp)); + if (strlen(tmp) && atoi(tmp)) { + p->maxforwards = atoi(tmp) - 1; + } else { + p->maxforwards = DEFAULT_MAX_FORWARDS - 1; + } + if (p->maxforwards > -1) { + /* save in case we get 407 challenge */ + ast_copy_string(p->refer_to, referto, sizeof(p->refer_to)); + ast_copy_string(p->referred_by, p->our_contact, sizeof(p->referred_by)); + + reqprep(&req, p, SIP_REFER, 0, 1); + add_header(&req, "Refer-To", referto); + if (!ast_strlen_zero(p->our_contact)) + add_header(&req, "Referred-By", p->our_contact); + add_blank_header(&req); + return send_request(p, &req, 1, p->ocseq); + } else { + return -1; + } } /*--- transmit_info_with_digit: Send SIP INFO dtmf message, see Cisco documentation on cisco.co @@ -11187,8 +11202,6 @@ static int sip_getheader(struct ast_channel *chan, void *data) return 0; } -#define DEFAULT_MAX_FORWARDS 70 - /*--- sip_sipredirect: Transfer call before connect with a 302 redirect ---*/ /* Called by the transfer() dialplan application through the sip_transfer() */ /* pbx interface function if the call is in ringing state */ -- cgit v1.2.3