dect
/
asterisk
Archived
13
0
Fork 0

Handle 401 for INVITE as well (should we add support for BYE too?)

git-svn-id: http://svn.digium.com/svn/asterisk/trunk@1714 f38db490-d61c-443f-a65b-d21fe96a405b
This commit is contained in:
markster 2003-11-10 04:22:33 +00:00
parent 66a4e3b2cd
commit fcf061fc44
1 changed files with 22 additions and 14 deletions

View File

@ -398,12 +398,12 @@ static int transmit_response_with_sdp(struct sip_pvt *p, char *msg, struct sip_r
static int transmit_response_with_auth(struct sip_pvt *p, char *msg, struct sip_request *req, char *rand, int reliable);
static int transmit_request(struct sip_pvt *p, char *msg, int inc, int reliable);
static int transmit_request_with_auth(struct sip_pvt *p, char *msg, int inc, int reliable);
static int transmit_invite(struct sip_pvt *p, char *msg, int sendsdp, char *auth, char *vxml_url,char *distinctive_ring, int init);
static int transmit_invite(struct sip_pvt *p, char *msg, int sendsdp, char *auth, char *authheader, char *vxml_url,char *distinctive_ring, int init);
static int transmit_reinvite_with_sdp(struct sip_pvt *p, struct ast_rtp *rtp, struct ast_rtp *vrtp);
static int transmit_info_with_digit(struct sip_pvt *p, char digit);
static int transmit_message_with_text(struct sip_pvt *p, char *text);
static int transmit_refer(struct sip_pvt *p, char *dest);
static int do_proxy_auth(struct sip_pvt *p, struct sip_request *req, char *msg, int init);
static int do_proxy_auth(struct sip_pvt *p, struct sip_request *req, char *header, char *respheader, char *msg, int init);
static char *getsipuri(char *header);
static void free_old_route(struct sip_route *route);
static int build_reply_digest(struct sip_pvt *p, char *orig_header, char *digest, int digest_len);
@ -870,7 +870,7 @@ static int sip_call(struct ast_channel *ast, char *dest, int timeout)
res = find_user(p,INC_OUT_USE);
p->restrictcid = ast->restrictcid;
p->jointcapability = p->capability;
transmit_invite(p, "INVITE", 1, NULL, vxml_url,distinctive_ring, 1);
transmit_invite(p, "INVITE", 1, NULL, NULL, vxml_url,distinctive_ring, 1);
if (p->maxtime) {
/* Initialize auto-congest time */
p->initid = ast_sched_add(sched, p->maxtime * 2, auto_congest, p);
@ -2761,7 +2761,7 @@ static void initreqprep(struct sip_request *req, struct sip_pvt *p, char *cmd, c
add_header(req, "User-Agent", "Asterisk PBX");
}
static int transmit_invite(struct sip_pvt *p, char *cmd, int sdp, char *auth, char *vxml_url, char *distinctive_ring, int init)
static int transmit_invite(struct sip_pvt *p, char *cmd, int sdp, char *auth, char *authheader, char *vxml_url, char *distinctive_ring, int init)
{
struct sip_request req;
@ -2771,7 +2771,7 @@ static int transmit_invite(struct sip_pvt *p, char *cmd, int sdp, char *auth, ch
reqprep(&req, p, cmd, 0);
if (auth)
add_header(&req, "Proxy-Authorization", auth);
add_header(&req, authheader, auth);
if (distinctive_ring)
{
@ -4313,7 +4313,7 @@ static int sip_no_debug(int fd, int argc, char *argv[])
return RESULT_SUCCESS;
}
static int reply_digest(struct sip_pvt *p, struct sip_request *req, char *header, char *orig_header, char *digest, int digest_len);
static int reply_digest(struct sip_pvt *p, struct sip_request *req, char *header, char *respheader, char *digest, int digest_len);
static int do_register_auth(struct sip_pvt *p, struct sip_request *req, char *header, char *respheader) {
char digest[256];
@ -4326,7 +4326,7 @@ static int do_register_auth(struct sip_pvt *p, struct sip_request *req, char *he
return transmit_register(p->registry,"REGISTER",digest, respheader);
}
static int do_proxy_auth(struct sip_pvt *p, struct sip_request *req, char *msg, int init) {
static int do_proxy_auth(struct sip_pvt *p, struct sip_request *req, char *header, char *respheader, char *msg, int init) {
char digest[256];
p->authtries++;
memset(digest,0,sizeof(digest));
@ -4334,7 +4334,7 @@ static int do_proxy_auth(struct sip_pvt *p, struct sip_request *req, char *msg,
/* No way to authenticate */
return -1;
}
return transmit_invite(p,msg,!strcasecmp(msg, "INVITE"),digest, NULL,NULL, init);
return transmit_invite(p,msg,!strcasecmp(msg, "INVITE"),digest, respheader, NULL,NULL, init);
}
static int reply_digest(struct sip_pvt *p, struct sip_request *req, char *header, char *orig_header, char *digest, int digest_len) {
@ -4671,7 +4671,15 @@ static void handle_response(struct sip_pvt *p, int resp, char *rest, struct sip_
}
break;
case 401: /* Not authorized on REGISTER */
if (p->registry && !strcasecmp(msg, "REGISTER")) {
if (!strcasecmp(msg, "INVITE")) {
/* First we ACK */
transmit_request(p, "ACK", seqno, 0);
/* Then we AUTH */
if ((p->authtries > 1) || do_proxy_auth(p, req, "WWW-Authenticate", "Authorization", "INVITE", 1)) {
ast_log(LOG_NOTICE, "Failed to authenticate on INVITE to '%s'\n", get_header(&p->initreq, "From"));
p->needdestroy = 1;
}
} else if (p->registry && !strcasecmp(msg, "REGISTER")) {
if ((p->authtries > 1) || do_register_auth(p, req, "WWW-Authenticate", "Authorization")) {
ast_log(LOG_NOTICE, "Failed to authenticate on REGISTER to '%s'\n", get_header(&p->initreq, "From"));
p->needdestroy = 1;
@ -4684,7 +4692,7 @@ static void handle_response(struct sip_pvt *p, int resp, char *rest, struct sip_
/* First we ACK */
transmit_request(p, "ACK", seqno, 0);
/* Then we AUTH */
if ((p->authtries > 1) || do_proxy_auth(p, req, "INVITE", 1)) {
if ((p->authtries > 1) || do_proxy_auth(p, req, "Proxy-Authenticate", "Proxy-Authorization", "INVITE", 1)) {
ast_log(LOG_NOTICE, "Failed to authenticate on INVITE to '%s'\n", get_header(&p->initreq, "From"));
p->needdestroy = 1;
}
@ -4692,7 +4700,7 @@ static void handle_response(struct sip_pvt *p, int resp, char *rest, struct sip_
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, "BYE", 0)) {
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"));
p->needdestroy = 1;
}
@ -4771,7 +4779,7 @@ static void handle_response(struct sip_pvt *p, int resp, char *rest, struct sip_
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, "BYE", 0)) {
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"));
p->needdestroy = 1;
}
@ -5518,9 +5526,9 @@ static int sip_poke_peer(struct sip_peer *peer)
p->outgoing = 1;
#ifdef VOCAL_DATA_HACK
strncpy(p->username, "__VOCAL_DATA_SHOULD_READ_THE_SIP_SPEC__", sizeof(p->username));
transmit_invite(p, "INVITE", 0, NULL, NULL,NULL, 1);
transmit_invite(p, "INVITE", 0, NULL, NULL, NULL,NULL, 1);
#else
transmit_invite(p, "OPTIONS", 0, NULL, NULL,NULL, 1);
transmit_invite(p, "OPTIONS", 0, NULL, NULL, NULL,NULL, 1);
#endif
gettimeofday(&peer->ps, NULL);
peer->pokeexpire = ast_sched_add(sched, DEFAULT_MAXMS * 2, sip_poke_noanswer, peer);