Index: channels/chan_sip.c =================================================================== --- channels/chan_sip.c (revision 138681) +++ 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 | \ @@ -3696,8 +3697,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 +4627,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); @@ -12336,6 +12342,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; @@ -12828,8 +12835,11 @@ } } else if (sipmethod == SIP_REGISTER) 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_BYE) { /* Ok, we're ready to go */ + ast_set_flag(&p->flags[0], SIP_NEEDDESTROY); + ast_clear_flag(&p->flags[1], SIP_PAGE2_DIALOG_ESTABLISHED); + } else if (sipmethod == SIP_SUBSCRIBE) + ast_set_flag(&p->flags[1], SIP_PAGE2_DIALOG_ESTABLISHED); break; case 202: /* Transfer accepted */ if (sipmethod == SIP_REFER) @@ -14518,6 +14528,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) @@ -14538,6 +14549,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) @@ -14567,9 +14579,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; @@ -15210,6 +15224,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; @@ -15468,6 +15483,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); @@ -15484,7 +15500,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));