Index: channels/chan_sip.c =================================================================== --- channels/chan_sip.c (revision 136523) +++ channels/chan_sip.c (working copy) @@ -796,6 +796,7 @@ #define SIP_PAGE2_BUGGY_MWI (1 << 26) /*!< 26: Buggy CISCO MWI fix */ #define SIP_PAGE2_OUTGOING_CALL (1 << 27) /*!< 27: Is this an outgoing call? */ #define SIP_PAGE2_UDPTL_DESTINATION (1 << 28) /*!< 28: Use source IP of RTP as destination if NAT is enabled */ +#define SIP_PAGE2_DIALOG_ESTABLISHED (1 << 29) /*!< 29: Has a dialog been established? */ #define SIP_PAGE2_FLAGS_TO_COPY \ (SIP_PAGE2_ALLOWSUBSCRIBE | SIP_PAGE2_ALLOWOVERLAP | SIP_PAGE2_VIDEOSUPPORT | \ @@ -2108,6 +2109,7 @@ } else if (p->refer && !ast_test_flag(&p->flags[0], SIP_ALREADYGONE)) { if (option_debug > 2) ast_log(LOG_DEBUG, "Finally hanging up channel after transfer: %s\n", p->callid); + ast_clear_flag(&p->flags[1], SIP_PAGE2_DIALOG_ESTABLISHED); transmit_request_with_auth(p, SIP_BYE, 0, XMIT_RELIABLE, 1); sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT); } else @@ -3624,6 +3626,7 @@ if (p->vrtp) videoqos = ast_rtp_get_quality(p->vrtp, NULL); /* Send a hangup */ + ast_clear_flag(&p->flags[1], SIP_PAGE2_DIALOG_ESTABLISHED); transmit_request_with_auth(p, SIP_BYE, 0, XMIT_RELIABLE, 1); /* Get RTCP quality before end of call */ @@ -3696,8 +3699,10 @@ if (option_debug > 1) ast_log(LOG_DEBUG,"T38State change to %d on channel %s\n", p->t38.state, ast->name); res = transmit_response_with_t38_sdp(p, "200 OK", &p->initreq, XMIT_CRITICAL); + ast_set_flag(&p->flags[1], SIP_PAGE2_DIALOG_ESTABLISHED); } else { res = transmit_response_with_sdp(p, "200 OK", &p->initreq, XMIT_CRITICAL); + ast_set_flag(&p->flags[1], SIP_PAGE2_DIALOG_ESTABLISHED); } } ast_mutex_unlock(&p->lock); @@ -4624,8 +4629,11 @@ found = (!strcmp(p->callid, callid)); else found = (!strcmp(p->callid, callid) && - (!pedanticsipchecking || ast_strlen_zero(tag) || ast_strlen_zero(p->theirtag) || !strcmp(p->theirtag, tag))) ; + (!pedanticsipchecking || ast_strlen_zero(tag) || ast_strlen_zero(p->theirtag) || + !ast_test_flag(&p->flags[1], SIP_PAGE2_DIALOG_ESTABLISHED) || !strcmp(p->theirtag, tag))); + ast_log(LOG_NOTICE, "Compared %s to %s\n", p->theirtag, tag); + if (option_debug > 4) ast_log(LOG_DEBUG, "= %s Their Call ID: %s Their Tag %s Our tag: %s\n", found ? "Found" : "No match", p->callid, p->theirtag, p->tag); @@ -12116,6 +12124,7 @@ return; /* Perhaps there is an SD change INVITE outstanding */ + ast_clear_flag(&p->flags[1], SIP_PAGE2_DIALOG_ESTABLISHED); transmit_request_with_auth(p, SIP_BYE, 0, XMIT_RELIABLE, TRUE); } ast_clear_flag(&p->flags[0], SIP_PENDINGBYE); @@ -12331,6 +12340,7 @@ } /* If I understand this right, the branch is different for a non-200 ACK only */ p->invitestate = INV_TERMINATED; + ast_set_flag(&p->flags[1], SIP_PAGE2_DIALOG_ESTABLISHED); xmitres = transmit_request(p, SIP_ACK, seqno, XMIT_UNRELIABLE, TRUE); check_pendings(p); break; @@ -12825,6 +12835,8 @@ res = handle_response_register(p, resp, rest, req, ignore, seqno); else if (sipmethod == SIP_BYE) /* Ok, we're ready to go */ ast_set_flag(&p->flags[0], SIP_NEEDDESTROY); + else if (sipmethod == SIP_SUBSCRIBE) + ast_set_flag(&p->flags[1], SIP_PAGE2_DIALOG_ESTABLISHED); break; case 202: /* Transfer accepted */ if (sipmethod == SIP_REFER) @@ -14513,6 +14525,7 @@ } } else { /* The other side is already setup for T.38 most likely so we need to acknowledge this too */ + ast_set_flag(&p->flags[1], SIP_PAGE2_DIALOG_ESTABLISHED); transmit_response_with_t38_sdp(p, "200 OK", req, XMIT_CRITICAL); p->t38.state = T38_ENABLED; if (option_debug) @@ -14533,6 +14546,7 @@ } } else { /* we are not bridged in a call */ + ast_set_flag(&p->flags[1], SIP_PAGE2_DIALOG_ESTABLISHED); transmit_response_with_t38_sdp(p, "200 OK", req, XMIT_CRITICAL); p->t38.state = T38_ENABLED; if (option_debug) @@ -14562,9 +14576,11 @@ } } /* Respond to normal re-invite */ - if (sendok) + if (sendok) { /* If this is not a re-invite or something to ignore - it's critical */ + ast_set_flag(&p->flags[1], SIP_PAGE2_DIALOG_ESTABLISHED); transmit_response_with_sdp(p, "200 OK", req, (reinvite ? XMIT_RELIABLE : (ast_test_flag(req, SIP_PKT_IGNORE) ? XMIT_UNRELIABLE : XMIT_CRITICAL))); + } } p->invitestate = INV_TERMINATED; break; @@ -15205,6 +15221,7 @@ if (option_debug > 2) ast_log(LOG_DEBUG, "Received bye, no owner, selfdestruct soon.\n"); } + ast_clear_flag(&p->flags[1], SIP_PAGE2_DIALOG_ESTABLISHED); transmit_response(p, "200 OK", req); return 1; @@ -15463,6 +15480,7 @@ sip_scheddestroy(p, (p->expiry + 10) * 1000); /* Set timer for destruction of call at expiration */ if (p->subscribed == MWI_NOTIFICATION) { + ast_set_flag(&p->flags[1], SIP_PAGE2_DIALOG_ESTABLISHED); transmit_response(p, "200 OK", req); if (p->relatedpeer) { /* Send first notification */ ASTOBJ_WRLOCK(p->relatedpeer); @@ -15479,7 +15497,7 @@ ast_set_flag(&p->flags[0], SIP_NEEDDESTROY); return 0; } - + ast_set_flag(&p->flags[1], SIP_PAGE2_DIALOG_ESTABLISHED); transmit_response(p, "200 OK", req); transmit_state_notify(p, firststate, 1, FALSE); /* Send first notification */ append_history(p, "Subscribestatus", "%s", ast_extension_state2str(firststate));