--- chan_sip.c.ORIGINAL 2012-02-05 23:22:53.000000000 -0500 +++ chan_sip.c 2012-02-28 23:30:54.000000000 -0500 @@ -21726,6 +21726,7 @@ } else if (!strcmp(event, "message-summary")) { const char *mailbox = NULL; char *c = ast_strdupa(get_body(req, "Voice-Message", ':')); + const char *expired = get_header(req, "Subscription-State"); if (!p->mwi) { struct sip_peer *peer = find_peer(NULL, &p->recv, TRUE, FINDPEERS, FALSE, p->socket.type); @@ -21756,6 +21757,23 @@ transmit_response(p, "489 Bad event", req); res = -1; } + //deal with expiry + if (!strcmp(expired, "terminated;reason=timeout")) { + ast_log(LOG_NOTICE, "Got dialog termination/timeout (%s)\n", event); + if (p->mwi->call) { + dialog_unlink_all(p->mwi->call); + p->mwi->call = dialog_unref(p->mwi->call, "remove p->mwi->call (termination/timeout)"); + } + AST_SCHED_DEL(sched, p->mwi->resub); + if ((p->mwi->resub = ast_sched_add(sched, 1000, sip_subscribe_mwi_do, ASTOBJ_REF(p->mwi))) < 0) { + ast_log(LOG_NOTICE, "Failed to shed_add mwi_do\n"); + ASTOBJ_UNREF(p->mwi, sip_subscribe_mwi_destroy); + } + + + } + + } else if (!strcmp(event, "keep-alive")) { /* Used by Sipura/Linksys for NAT pinhole, * just confirm that we received the packet. */ @@ -24983,7 +25001,7 @@ p->method = req->method; /* Find out which SIP method they are using */ ast_debug(4, "**** Received %s (%d) - Command in SIP %s\n", sip_methods[p->method].text, sip_methods[p->method].id, cmd); - if (p->icseq && (p->icseq > seqno) ) { + if (p->icseq && (p->icseq > seqno) && req->method != SIP_NOTIFY ) { if (p->pendinginvite && seqno == p->pendinginvite && (req->method == SIP_ACK || req->method == SIP_CANCEL)) { ast_debug(2, "Got CANCEL or ACK on INVITE with transactions in between.\n"); } else { @@ -25001,6 +25019,7 @@ } else if (p->icseq && p->icseq == seqno && req->method != SIP_ACK && + req->method != SIP_NOTIFY && (p->method != SIP_CANCEL || p->alreadygone)) { /* ignore means "don't do anything with it" but still have to respond appropriately. We do this if we receive a repeat of