--- ../pristine/asterisk-1.4.4/channels/chan_sip.c 2007-04-30 08:17:59.000000000 -0600 +++ channels/chan_sip.c 2007-04-30 08:55:33.000000000 -0600 @@ -3368,6 +3368,7 @@ /* We can't send anything in CALLING state */ ast_set_flag(&p->flags[0], SIP_PENDINGBYE); /* Do we need a timer here if we don't hear from them at all? */ + sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT); } else { /* Send a new request: CANCEL */ transmit_request(p, SIP_CANCEL, p->ocseq, XMIT_RELIABLE, FALSE); @@ -3415,7 +3416,8 @@ but we can't send one while we have "INVITE" outstanding. */ ast_set_flag(&p->flags[0], SIP_PENDINGBYE); ast_clear_flag(&p->flags[0], SIP_NEEDREINVITE); - sip_cancel_destroy(p); + if(oldowner) + sip_cancel_destroy(p); } } } @@ -11674,7 +11676,7 @@ /* RFC3261 says we must treat every 1xx response (but not 100) that we don't recognize as if it was 183. */ - if (resp > 100 && resp < 200 && resp!=101 && resp != 180 && resp != 183) + if (resp > 101 && resp < 200 && resp != 180 && resp != 183) resp = 183; /* Any response between 100 and 199 is PROCEEDING */ @@ -11688,6 +11690,11 @@ switch (resp) { case 100: /* Trying */ + if (!ast_test_flag(req, SIP_PKT_IGNORE) && p->owner) + sip_cancel_destroy(p); + check_pendings(p); + break; + case 101: /* Dialog establishment */ if (!ast_test_flag(req, SIP_PKT_IGNORE)) sip_cancel_destroy(p); @@ -11695,9 +11702,8 @@ break; case 180: /* 180 Ringing */ - if (!ast_test_flag(req, SIP_PKT_IGNORE)) - sip_cancel_destroy(p); if (!ast_test_flag(req, SIP_PKT_IGNORE) && p->owner) { + sip_cancel_destroy(p); ast_queue_control(p->owner, AST_CONTROL_RINGING); if (p->owner->_state != AST_STATE_UP) { ast_setstate(p->owner, AST_STATE_RINGING); @@ -11715,7 +11721,7 @@ break; case 183: /* Session progress */ - if (!ast_test_flag(req, SIP_PKT_IGNORE)) + if (!ast_test_flag(req, SIP_PKT_IGNORE) && p->owner) sip_cancel_destroy(p); /* Ignore 183 Session progress without SDP */ if (find_sdp(req)) { @@ -11730,7 +11736,7 @@ break; case 200: /* 200 OK on invite - someone's answering our call */ - if (!ast_test_flag(req, SIP_PKT_IGNORE)) + if (!ast_test_flag(req, SIP_PKT_IGNORE) && p->owner) sip_cancel_destroy(p); p->authtries = 0; if (find_sdp(req)) { @@ -11888,6 +11894,7 @@ ast_queue_hangup(p->owner); else if (!ast_test_flag(req, SIP_PKT_IGNORE)) update_call_counter(p, DEC_CALL_LIMIT); + sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT); break; case 488: /* Not acceptable here */ transmit_request(p, SIP_ACK, seqno, XMIT_UNRELIABLE, FALSE); @@ -12430,7 +12437,7 @@ ast_set_flag(&p->flags[0], SIP_NEEDDESTROY); } else if ((resp >= 100) && (resp < 200)) { if (sipmethod == SIP_INVITE) { - if (!ast_test_flag(req, SIP_PKT_IGNORE)) + if (!ast_test_flag(req, SIP_PKT_IGNORE) && p->owner) sip_cancel_destroy(p); if (find_sdp(req)) process_sdp(p, req); @@ -12535,7 +12542,7 @@ default: /* Errors without handlers */ if ((resp >= 100) && (resp < 200)) { if (sipmethod == SIP_INVITE) { /* re-invite */ - if (!ast_test_flag(req, SIP_PKT_IGNORE)) + if (!ast_test_flag(req, SIP_PKT_IGNORE) && p->owner) sip_cancel_destroy(p); } } @@ -12549,7 +12556,7 @@ case 503: /* Service Unavailable */ case 504: /* Server timeout */ - if (sipmethod == SIP_INVITE) { /* re-invite failed */ + if (sipmethod == SIP_INVITE && p->owner) { /* re-invite failed */ sip_cancel_destroy(p); } break; @@ -13329,7 +13336,9 @@ if (!ast_test_flag(req, SIP_PKT_IGNORE)) { int newcall = (p->initreq.headers ? TRUE : FALSE); - sip_cancel_destroy(p); + if(p->owner) + sip_cancel_destroy(p); + /* This also counts as a pending invite */ p->pendinginvite = seqno; check_via(p, req);