--- asterisk-1.4.32/channels/chan_sip.c 2010-05-05 09:42:22.000000000 -0700 +++ asterisk-1.4.32-new/channels/chan_sip.c 2010-06-22 10:54:26.000000000 -0700 @@ -1831,7 +1831,7 @@ static int __sip_xmit(struct sip_pvt *p, char *data, int len) { int res; - const struct sockaddr_in *dst = sip_real_dst(p); + const struct sockaddr_in *dst = sip_real_dst(p); res = sendto(sipsock, data, len, 0, (const struct sockaddr *)dst, sizeof(struct sockaddr_in)); if (res == -1) { @@ -4873,12 +4873,13 @@ /* See if the method is capable of creating a dialog */ if (sip_methods[intended_method].can_create == CAN_CREATE_DIALOG) { + const char *event = get_header(req, "Event"); if (intended_method == SIP_REFER) { /* We do support REFER, but not outside of a dialog yet */ transmit_response_using_temp(callid, sin, 1, intended_method, req, "603 Declined (no dialog)"); - } else if (intended_method == SIP_NOTIFY) { - /* We do not support out-of-dialog NOTIFY either, - like voicemail notification, so cancel that early */ + } else if (intended_method == SIP_NOTIFY && (!event || strcmp(event, "keep-alive"))) { + /* We do not support out-of-dialog NOTIFY either, unless it is a + * keep-alive, like voicemail notification, so cancel that early */ transmit_response_using_temp(callid, sin, 1, intended_method, req, "489 Bad event"); } else { /* Ok, time to create a new SIP dialog object, a pvt */ @@ -14185,8 +14186,11 @@ if (option_debug > 1 && sipdebug) ast_log(LOG_DEBUG, "Got NOTIFY Event: %s\n", event); - - if (strcmp(event, "refer")) { + + if (!strcmp(event, "keep-alive")) { + /* Return 200 OK for keep-alive events */ + transmit_response(p, "200 OK", req); + } else if (strcmp(event, "refer")) { /* We don't understand this event. */ /* Here's room to implement incoming voicemail notifications :-) */ transmit_response(p, "489 Bad event", req);