Index: chan_sip.c =================================================================== --- chan_sip.c (revision 174217) +++ chan_sip.c (working copy) @@ -8485,13 +8485,35 @@ contact info */ char tmp[256]; + /*Check here whether it is registration query*/ + if((p->method == SIP_REGISTER)&& get_header(req, "Contact")== "" ){ + int expiry; + struct sip_peer *peer = find_peer(p->exten,NULL,TRUE,FINDALLDEVICES,TRUE); + if(peer){ + if(peer->fullcontact){ + if (peer->expire >-1 ){ + expiry = ast_sched_when(sched, peer->expire); + snprintf(tmp, sizeof(tmp), "<%s:%s@%s:%d>;%d", "sip", peer->username, ast_inet_ntoa(peer->addr.sin_addr), ntohs(peer->addr.sin_port), expiry); + add_header(resp, "Contact",tmp); + } + } + + unref_peer(peer, "create_addr: unref peer from find_peer hashtab lookup"); + } + }else{ - snprintf(tmp, sizeof(tmp), "%d", p->expiry); - add_header(resp, "Expires", tmp); if (p->expiry) { /* Only add contact if we have an expiry time */ + if(p->our_contact){ char contact[SIPBUFSIZE]; snprintf(contact, sizeof(contact), "%s;expires=%d", p->our_contact, p->expiry); add_header(resp, "Contact", contact); /* Not when we unregister */ + } + snprintf(tmp, sizeof(tmp), "%d", p->expiry); + add_header(resp, "Expires", tmp); } + } + } else if (msg[0] != '4' && !ast_strlen_zero(p->our_contact)) { } else if (!ast_strlen_zero(p->our_contact) && resp_needs_contact(msg, p->method)) { add_header(resp, "Contact", p->our_contact); }