Index: /branches/1.8/channels/chan_sip.c =================================================================== --- /branches/1.8/channels/chan_sip.c (revision 358643) +++ /branches/1.8/channels/chan_sip.c (working copy) @@ -12171,7 +12171,7 @@ /* If init=1, we should not generate a new branch. If it's 0, we need a new branch. */ reqprep(&req, p, sipmethod, 0, init ? 0 : 1); } - + if (p->options && p->options->auth) { add_header(&req, p->options->authheader, p->options->auth); } @@ -19755,6 +19755,10 @@ if (p->invitestate == INV_PROCEEDING || p->invitestate == INV_EARLY_MEDIA) { p->invitestate = INV_CANCELLED; transmit_request(p, SIP_CANCEL, p->lastinvite, XMIT_RELIABLE, FALSE); + /* If the cancel occurred on an initial invite, cancel the pending BYE */ + if (!ast_test_flag(&p->flags[1], SIP_PAGE2_DIALOG_ESTABLISHED)) { + ast_clear_flag(&p->flags[0], SIP_PENDINGBYE); + } /* Actually don't destroy us yet, wait for the 487 on our original INVITE, but do set an autodestruct just in case we never get it. */ } else { @@ -19768,8 +19772,8 @@ } /* Perhaps there is an SD change INVITE outstanding */ transmit_request_with_auth(p, SIP_BYE, 0, XMIT_RELIABLE, TRUE); + ast_clear_flag(&p->flags[0], SIP_PENDINGBYE); } - ast_clear_flag(&p->flags[0], SIP_PENDINGBYE); sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT); } else if (ast_test_flag(&p->flags[0], SIP_NEEDREINVITE)) { /* if we can't REINVITE, hold it for later */ @@ -19931,7 +19935,7 @@ int outgoing = ast_test_flag(&p->flags[0], SIP_OUTGOING); int res = 0; int xmitres = 0; - int reinvite = (p->owner && p->owner->_state == AST_STATE_UP); + int reinvite = ast_test_flag(&p->flags[1], SIP_PAGE2_DIALOG_ESTABLISHED); char *p_hdrval; int rtn; struct ast_party_connected_line connected; @@ -20121,10 +20125,11 @@ p->authtries = 0; if (find_sdp(req)) { if ((res = process_sdp(p, req, SDP_T38_ACCEPT)) && !req->ignore) - if (!reinvite) + if (!reinvite) { /* This 200 OK's SDP is not acceptable, so we need to ack, then hangup */ /* For re-invites, we try to recover */ ast_set_flag(&p->flags[0], SIP_PENDINGBYE); + } ast_rtp_instance_activate(p->rtp); } @@ -20168,9 +20173,9 @@ update_call_counter(p, DEC_CALL_RINGING); parse_ok_contact(p, req); /* Save Record-Route for any later requests we make on this dialogue */ - if (!reinvite) + if (!reinvite) { build_route(p, req, 1, resp); - + } if(set_address_from_contact(p)) { /* Bad contact - we don't know how to reach this device */ /* We need to ACK, but then send a bye */ @@ -20318,6 +20323,7 @@ update_call_counter(p, DEC_CALL_LIMIT); append_history(p, "Hangup", "Got 487 on CANCEL request from us on call without owner. Killing this dialog."); } + check_pendings(p); sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT); break; case 415: /* Unsupported media type */ @@ -20963,8 +20969,9 @@ } /* If this is a NOTIFY for a subscription clear the flag that indicates that we have a NOTIFY pending */ - if (!p->owner && sipmethod == SIP_NOTIFY && p->pendinginvite) + if (!p->owner && sipmethod == SIP_NOTIFY && p->pendinginvite) { p->pendinginvite = 0; + } /* Get their tag if we haven't already */ if (ast_strlen_zero(p->theirtag) || (resp >= 200)) {