[Asterisk-cvs] asterisk/channels chan_sip.c,1.206,1.207

markster at lists.digium.com markster at lists.digium.com
Sun Nov 9 21:56:20 CST 2003


Update of /usr/cvsroot/asterisk/channels
In directory mongoose.digium.com:/tmp/cvs-serv23875/channels

Modified Files:
	chan_sip.c 
Log Message:
Handle 401 for INVITE as well (should we add support for BYE too?)


Index: chan_sip.c
===================================================================
RCS file: /usr/cvsroot/asterisk/channels/chan_sip.c,v
retrieving revision 1.206
retrieving revision 1.207
diff -u -d -r1.206 -r1.207
--- chan_sip.c	4 Nov 2003 02:40:09 -0000	1.206
+++ chan_sip.c	10 Nov 2003 04:22:33 -0000	1.207
@@ -398,12 +398,12 @@
 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 @@
 	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 @@
 	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 @@
 		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 @@
 	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 @@
 	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 @@
 		/* 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 @@
 			}
 			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 @@
 				/* 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 @@
 				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 @@
 				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 @@
 	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);




More information about the svn-commits mailing list