Index: chan_sip.c =================================================================== RCS file: /usr/cvsroot/asterisk/channels/chan_sip.c,v retrieving revision 1.251 diff -u -r1.251 chan_sip.c --- chan_sip.c 24 Nov 2003 21:27:51 -0000 1.251 +++ chan_sip.c 25 Nov 2003 17:11:45 -0000 @@ -2789,6 +2789,13 @@ if (auth) add_header(&req, authheader, auth); + + if (!strcasecmp(cmd, "REFER")) { + if (strlen(p->refer_to)) + add_header(&req, "Refer-To", p->refer_to); + if (strlen(p->referred_by)) + add_header(&req, "Referred-By", p->referred_by); + } if (distinctive_ring) { @@ -3104,9 +3111,14 @@ snprintf(referto, sizeof(referto), "", dest); } + /* save in case we get 407 challenge */ + strncpy(p->refer_to, referto, sizeof(p->refer_to) - 1); + strncpy(p->referred_by, p->our_contact, sizeof(p->referred_by) - 1); + reqprep(&req, p, "REFER", 0); add_header(&req, "Refer-To", referto); - add_header(&req, "Referred-By", callerid); + if (strlen(p->our_contact)) + add_header(&req, "Referred-By", p->our_contact); return send_request(p, &req, 1, p->ocseq); } @@ -4027,7 +4039,7 @@ } p->canreinvite = peer->canreinvite; if (strlen(peer->username)) - strncpy(p->username, peer->name, sizeof(p->username) - 1); + strncpy(p->username, peer->username, sizeof(p->username) - 1); strncpy(p->peername, peer->name, sizeof(p->peername) - 1); if (strlen(peer->context)) strncpy(p->context, peer->context, sizeof(p->context) - 1); @@ -4761,12 +4773,12 @@ ast_log(LOG_NOTICE, "Failed to authenticate on INVITE to '%s'\n", get_header(&p->initreq, "From")); p->needdestroy = 1; } - } else if (!strcasecmp(msg, "BYE")) { + } else if (!strcasecmp(msg, "BYE") || !strcasecmp(msg, "REFER")) { if (!strlen(p->peername)) - ast_log(LOG_WARNING, "Asked to authenticate BYE, to %s:%d but we have no matching peer!\n", - inet_ntoa(p->recv.sin_addr), ntohs(p->recv.sin_port)); - if ((p->authtries > 1) || do_proxy_auth(p, req, "Proxy-Authenticate", "Proxy-Authorization", "BYE", 0)) { - ast_log(LOG_NOTICE, "Failed to authenticate on BYE to '%s'\n", get_header(&p->initreq, "From")); + ast_log(LOG_WARNING, "Asked to authenticate %s, to %s:%d but we have no matching peer!\n", + msg, inet_ntoa(p->recv.sin_addr), ntohs(p->recv.sin_port)); + if ((p->authtries > 1) || do_proxy_auth(p, req, "Proxy-Authenticate", "Proxy-Authorization", msg, 0)) { + ast_log(LOG_NOTICE, "Failed to authenticate on %s to '%s'\n", msg, get_header(&p->initreq, "From")); p->needdestroy = 1; } } else if (p->registry && !strcasecmp(msg, "REGISTER")) { @@ -4840,12 +4852,12 @@ transmit_request(p, "ACK", seqno, 0); break; case 407: - if (!strcasecmp(msg, "BYE")) { + if (!strcasecmp(msg, "BYE") || !strcasecmp(msg, "REFER")) { if (!strlen(p->peername)) - ast_log(LOG_WARNING, "Asked to authenticate BYE, to %s:%d but we have no matching peer!\n", - inet_ntoa(p->recv.sin_addr), ntohs(p->recv.sin_port)); - if ((p->authtries > 1) || do_proxy_auth(p, req, "Proxy-Authenticate", "Proxy-Authorization", "BYE", 0)) { - ast_log(LOG_NOTICE, "Failed to authenticate on BYE to '%s'\n", get_header(&p->initreq, "From")); + ast_log(LOG_WARNING, "Asked to authenticate %s, to %s:%d but we have no matching peer!\n", + msg, inet_ntoa(p->recv.sin_addr), ntohs(p->recv.sin_port)); + if ((p->authtries > 1) || do_proxy_auth(p, req, "Proxy-Authenticate", "Proxy-Authorization", msg, 0)) { + ast_log(LOG_NOTICE, "Failed to authenticate on %s to '%s'\n", msg, get_header(&p->initreq, "From")); p->needdestroy = 1; } }