[Asterisk-cvs] asterisk/channels chan_sip.c,1.876,1.877

kpfleming kpfleming
Tue Oct 4 19:58:17 CDT 2005


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

Modified Files:
	chan_sip.c 
Log Message:
handle peer matching for subscriptions by name instead of IP address (issue #5103)


Index: chan_sip.c
===================================================================
RCS file: /usr/cvsroot/asterisk/channels/chan_sip.c,v
retrieving revision 1.876
retrieving revision 1.877
diff -u -d -r1.876 -r1.877
--- chan_sip.c	4 Oct 2005 23:38:09 -0000	1.876
+++ chan_sip.c	4 Oct 2005 23:54:04 -0000	1.877
@@ -6830,10 +6830,12 @@
 }
 
 
-/*--- check_user: Check if matching user or peer is defined ---*/
+/*--- check_user_full: Check if matching user or peer is defined ---*/
+/* 	Match user on From: user name and peer on IP/port */
+/*	This is used on first invite (not re-invites) and subscribe requests */
 static int check_user_full(struct sip_pvt *p, struct sip_request *req, int sipmethod, char *uri, int reliable, struct sockaddr_in *sin, int ignore, char *mailbox, int mailboxlen)
 {
-	struct sip_user *user;
+	struct sip_user *user = NULL;
 	struct sip_peer *peer;
 	char *of, from[256], *c;
 	char *rpid,rpid_num[50];
@@ -6857,6 +6859,8 @@
 	
 	memset(calleridname,0,sizeof(calleridname));
 	get_calleridname(from, calleridname, sizeof(calleridname));
+	if (calleridname[0])
+		ast_copy_string(p->cid_name, calleridname, sizeof(p->cid_name));
 
 	rpid = get_header(req, "Remote-Party-ID");
 	memset(rpid_num,0,sizeof(rpid_num));
@@ -6889,13 +6893,14 @@
 		ast_copy_string(p->cid_num, of, sizeof(p->cid_num));
 		ast_shrink_phone_number(p->cid_num);
 	}
-	if (*calleridname)
-		ast_copy_string(p->cid_name, calleridname, sizeof(p->cid_name));
 	if (ast_strlen_zero(of))
 		return 0;
-	user = find_user(of, 1);
+
+	if (!mailbox)	/* If it's a mailbox SUBSCRIBE, don't check users */
+		user = find_user(of, 1);
+
 	/* Find user based on user name in the from header */
-	if (!mailbox && user && ast_apply_ha(user->ha, sin)) {
+	if (user && ast_apply_ha(user->ha, sin)) {
 		ast_copy_flags(p, user, SIP_TRUSTRPID | SIP_USECLIENTCODE | SIP_NAT | SIP_PROG_INBAND | SIP_OSPAUTH);
 		/* copy channel vars */
 		for (v = user->chanvars ; v ; v = v->next) {
@@ -6972,11 +6977,16 @@
 
 	if (!user) {
 		/* If we didn't find a user match, check for peers */
-		/* Look for peer based on the IP address we received data from */
-		/* If peer is registered from this IP address or have this as a default
-		   IP address, this call is from the peer 
- 		*/
-		peer = find_peer(NULL, &p->recv, 1);
+		if (sipmethod == SIP_SUBSCRIBE)
+			/* For subscribes, match on peer name only */
+			peer = find_peer(of, NULL, 1);
+		else
+			/* Look for peer based on the IP address we received data from */
+			/* If peer is registered from this IP address or have this as a default
+			   IP address, this call is from the peer 
+			*/
+			peer = find_peer(NULL, &p->recv, 1);
+
 		if (peer) {
 			if (debug)
 				ast_verbose("Found peer '%s'\n", peer->name);
@@ -10521,11 +10531,20 @@
 		ast_verbose("Ignoring this SUBSCRIBE request\n");
 
 	if (!p->lastinvite) {
-		char mailbox[256]="";
+		char mailboxbuf[256]="";
 		int found = 0;
+		char *mailbox = NULL;
+		int mailboxsize = 0;
 
+		char *event = get_header(req, "Event");	/* Get Event package name */
+		char *accept = get_header(req, "Accept");
+
+ 		if (!strcmp(event, "message-summary") && !strcmp(accept, "application/simple-message-summary")) {
+			mailbox = mailboxbuf;
+			mailboxsize = sizeof(mailboxbuf);
+		}
 		/* Handle authentication if this is our first subscribe */
-		res = check_user_full(p, req, SIP_SUBSCRIBE, e, 0, sin, ignore, mailbox, sizeof(mailbox));
+		res = check_user_full(p, req, SIP_SUBSCRIBE, e, 0, sin, ignore, mailbox, mailboxsize);
 		if (res) {
 			if (res < 0) {
 				ast_log(LOG_NOTICE, "Failed to authenticate user %s for SUBSCRIBE\n", get_header(req, "From"));
@@ -10548,8 +10567,6 @@
 				transmit_response(p, "484 Address Incomplete", req);	/* Overlap dialing on SUBSCRIBE?? */
 			ast_set_flag(p, SIP_NEEDDESTROY);	
 		} else {
-			char *event = get_header(req, "Event");	/* Get Event package name */
-			char *accept = get_header(req, "Accept");
 
 			/* Initialize tag for new subscriptions */	
 			if (ast_strlen_zero(p->tag))




More information about the svn-commits mailing list