From 9145d4bbc8857cd06fa7b6b263dad95818c13edd Mon Sep 17 00:00:00 2001 From: Mark Michelson Date: Thu, 9 Apr 2009 20:14:33 +0000 Subject: [PATCH] Merge revision 187488 to 1.6.0. A note to all of you. Don't block revisions in a branch if you actually meant to merge them. Two very old revisions somehow didn't get merged into 1.6.0 and this change was dependent on those two old revisions. What should have taken 2 minutes has now wasted about 30 minutes of my time :( git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/1.6.0@187555 65c4cc65-6c06-0410-ace0-fbb531ad65f3 --- channels/chan_sip.c | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/channels/chan_sip.c b/channels/chan_sip.c index 59db02f5aa..133154ae78 100644 --- a/channels/chan_sip.c +++ b/channels/chan_sip.c @@ -17045,12 +17045,25 @@ static int handle_request_invite(struct sip_pvt *p, struct sip_request *req, int } if (!req->ignore && p->pendinginvite) { - /* We already have a pending invite. Sorry. You are on hold. */ - p->glareinvite = seqno; /* must hold on to this seqno to process ack and retransmit correctly */ - transmit_response_reliable(p, "491 Request Pending", req); - ast_debug(1, "Got INVITE on call where we already have pending INVITE, deferring that - %s\n", p->callid); - /* Don't destroy dialog here */ - return 0; + if (!ast_test_flag(&p->flags[0], SIP_OUTGOING) && ast_test_flag(&p->flags[1], SIP_PAGE2_DIALOG_ESTABLISHED)) { + /* We have received a reINVITE on an incoming call to which we have sent a 200 OK but not yet received + * an ACK. According to RFC 5407, Section 3.1.4, the proper way to handle this race condition is to accept + * the reINVITE since we have established a dialog. + */ + + /* Note that this will both clear the pendinginvite flag and cancel the + * retransmission of the 200 OK. Basically, we're accepting this reINVITE as both an ACK + * and a reINVITE in one request. + * */ + __sip_ack(p, p->lastinvite, 1, 0); + } else { + /* We already have a pending invite. Sorry. You are on hold. */ + p->glareinvite = seqno; + transmit_response_reliable(p, "491 Request Pending", req); + ast_debug(1, "Got INVITE on call where we already have pending INVITE, deferring that - %s\n", p->callid); + /* Don't destroy dialog here */ + return 0; + } } p_replaces = get_header(req, "Replaces");