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)
{
snprintf(referto, sizeof(referto), "<sip:%s>", 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);
}
}
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);
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")) {
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;
}
}