[asterisk-commits] mmichelson: trunk r274539 - /trunk/channels/chan_sip.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Wed Jul 7 11:21:58 CDT 2010


Author: mmichelson
Date: Wed Jul  7 11:21:53 2010
New Revision: 274539

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=274539
Log:
Use the relatedpeer field of a sip_pvt during INVITE processing.

Review: https://reviewboard.asterisk.org/r/629


Modified:
    trunk/channels/chan_sip.c

Modified: trunk/channels/chan_sip.c
URL: http://svnview.digium.com/svn/asterisk/trunk/channels/chan_sip.c?view=diff&rev=274539&r1=274538&r2=274539
==============================================================================
--- trunk/channels/chan_sip.c (original)
+++ trunk/channels/chan_sip.c Wed Jul  7 11:21:53 2010
@@ -3441,10 +3441,8 @@
 		}
 	}
 
-	if (p->subscribed == MWI_NOTIFICATION) {
-		if (p->relatedpeer) {
-			p->relatedpeer = unref_peer(p->relatedpeer, "__sip_autodestruct: unref peer p->relatedpeer");	/* Remove link to peer. If it's realtime, make sure it's gone from memory) */
-		}
+	if (p->relatedpeer) {
+		p->relatedpeer = unref_peer(p->relatedpeer, "__sip_autodestruct: unref peer p->relatedpeer");	/* Remove link to peer. If it's realtime, make sure it's gone from memory) */
 	}
 
 	/* Reset schedule ID */
@@ -4650,6 +4648,7 @@
 	} else
 		return -1;
 
+	/* XXX TODO: get flags directly from peer only as they are needed using dialog->relatedpeer */
 	ast_copy_flags(&dialog->flags[0], &peer->flags[0], SIP_FLAGS_TO_COPY);
 	ast_copy_flags(&dialog->flags[1], &peer->flags[1], SIP_PAGE2_FLAGS_TO_COPY);
 	ast_copy_flags(&dialog->flags[2], &peer->flags[2], SIP_PAGE3_FLAGS_TO_COPY);
@@ -4694,6 +4693,7 @@
 		ast_rtp_instance_set_hold_timeout(dialog->trtp, peer->rtpholdtimeout);
 	}
 
+	/* XXX TODO: get fields directly from peer only as they are needed using dialog->relatedpeer */
 	ast_string_field_set(dialog, peername, peer->name);
 	ast_string_field_set(dialog, authname, peer->username);
 	ast_string_field_set(dialog, username, peer->username);
@@ -4813,6 +4813,7 @@
 				dialog->sa.sin_port = dialog->recv.sin_port = htons(portno);
 			}
 		}
+		dialog->relatedpeer = ref_peer(peer, "create_addr: setting dialog's relatedpeer pointer");
 		unref_peer(peer, "create_addr: unref peer from find_peer hashtab lookup");
 		return res;
 	}
@@ -5258,7 +5259,7 @@
 	ast_copy_string(name, fup->username, sizeof(name));
 
 	/* Check the list of devices */
-	if ((p = find_peer(ast_strlen_zero(fup->peername) ? name : fup->peername, NULL, TRUE, FINDALLDEVICES, FALSE, 0))) {
+	if ((p = fup->relatedpeer)) {
 		inuse = &p->inUse;
 		call_limit = &p->call_limit;
 		inringing = &p->inRinging;
@@ -12897,17 +12898,14 @@
 /*! \brief Change onhold state of a peer using a pvt structure */
 static void sip_peer_hold(struct sip_pvt *p, int hold)
 {
-	struct sip_peer *peer = find_peer(p->peername, NULL, 1, FINDALLDEVICES, FALSE, 0);
-
-	if (!peer)
+	if (!p->relatedpeer)
 		return;
 
 	/* If they put someone on hold, increment the value... otherwise decrement it */
-	ast_atomic_fetchadd_int(&peer->onHold, (hold ? +1 : -1));
+	ast_atomic_fetchadd_int(&p->relatedpeer->onHold, (hold ? +1 : -1));
 
 	/* Request device state update */
-	ast_devstate_changed(AST_DEVICE_UNKNOWN, "SIP/%s", peer->name);
-	unref_peer(peer, "sip_peer_hold: from find_peer operation");
+	ast_devstate_changed(AST_DEVICE_UNKNOWN, "SIP/%s", p->relatedpeer->name);
 	
 	return;
 }
@@ -16429,8 +16427,8 @@
 
 #define FORMAT4 "%-15.15s  %-15.15s  %-15.15s  %-15.15s  %-13.13s  %-15.15s %-10.10s %-6.6d\n"
 #define FORMAT3 "%-15.15s  %-15.15s  %-15.15s  %-15.15s  %-13.13s  %-15.15s %-10.10s %-6.6s\n"
-#define FORMAT2 "%-15.15s  %-15.15s  %-15.15s  %-15.15s  %-7.7s  %-15.15s %-6.6s\n"
-#define FORMAT  "%-15.15s  %-15.15s  %-15.15s  %-15.15s  %-3.3s %-3.3s  %-15.15s %-10.10s\n"
+#define FORMAT2 "%-15.15s  %-15.15s  %-15.15s  %-15.15s  %-7.7s  %-15.15s %-10.10s %-10.10s\n"
+#define FORMAT  "%-15.15s  %-15.15s  %-15.15s  %-15.15s  %-3.3s %-3.3s  %-15.15s %-10.10s %-10.10s\n"
 
 /*! \brief callback for show channel|subscription */
 static int show_channels_cb(void *__cur, void *__arg, int flags)
@@ -16452,7 +16450,8 @@
 				AST_CLI_YESNO(ast_test_flag(&cur->flags[1], SIP_PAGE2_CALL_ONHOLD)),
 				cur->needdestroy ? "(d)" : "",
 				cur->lastmsg ,
-				referstatus
+				referstatus,
+				cur->relatedpeer ? cur->relatedpeer->name : "<guest>"
 			);
 		arg->numchans++;
 	}
@@ -16500,7 +16499,7 @@
 		return CLI_SHOWUSAGE;
 	arg.subscriptions = !strcasecmp(a->argv[e->args - 1], "subscriptions");
 	if (!arg.subscriptions)
-		ast_cli(arg.fd, FORMAT2, "Peer", "User/ANR", "Call ID", "Format", "Hold", "Last Message", "Expiry");
+		ast_cli(arg.fd, FORMAT2, "Peer", "User/ANR", "Call ID", "Format", "Hold", "Last Message", "Expiry", "Peer");
 	else
 		ast_cli(arg.fd, FORMAT3, "Peer", "User", "Call ID", "Extension", "Last state", "Type", "Mailbox", "Expiry");
 
@@ -18838,7 +18837,6 @@
 	char *c_copy = ast_strdupa(c);
 	/* Skip the Cseq and its subsequent spaces */
 	const char *msg = ast_skip_blanks(ast_skip_nonblanks(c_copy));
-	struct sip_peer *peer;
 
 	if (!msg)
 		msg = "";
@@ -19085,9 +19083,8 @@
 		case 405:
 		case 501: /* Not Implemented */
 			mark_method_unallowed(&p->allowed_methods, sipmethod);
-			if ((peer = find_peer(p->peername, 0, 1, FINDPEERS, FALSE, 0))) {
-				mark_method_allowed(&peer->disallowed_methods, sipmethod);
-				unref_peer(peer, "handle_response: marking a specific method as unallowed");
+			if (p->relatedpeer) {
+				mark_method_allowed(&p->relatedpeer->disallowed_methods, sipmethod);
 			}
 			if (sipmethod == SIP_INVITE)
 				handle_response_invite(p, resp, rest, req, seqno);
@@ -20367,6 +20364,7 @@
 	const char *required;
 	unsigned int required_profile = 0;
 	struct ast_channel *c = NULL;		/* New channel */
+	struct sip_peer *authpeer = NULL;	/* Matching Peer */
 	int reinvite = 0;
 	int rtn;
 
@@ -20700,7 +20698,7 @@
 		/* Handle authentication if this is our first invite */
 		int cc_recall_core_id = -1;
 		set_pvt_allowed_methods(p, req);
-		res = check_user(p, req, SIP_INVITE, e, XMIT_RELIABLE, sin);
+		res = check_user_full(p, req, SIP_INVITE, e, XMIT_RELIABLE, sin, &authpeer);
 		if (res == AUTH_CHALLENGE_SENT) {
 			p->invitestate = INV_COMPLETED;		/* Needs to restart in another INVITE transaction */
 			res = 0;
@@ -20720,6 +20718,9 @@
 			res = 0;
 			goto request_invite_cleanup;
 		}
+
+		/* Successful authentication and peer matching so record the peer related to this pvt (for easy access to peer settings) */
+		p->relatedpeer = ref_peer(authpeer, "setting dialog's relatedpeer pointer");
 
 		/* If T38 is needed but not present, then make it magically appear */
 		if (ast_test_flag(&p->flags[1], SIP_PAGE2_T38SUPPORT) && !p->udptl) {
@@ -24060,14 +24061,11 @@
 {
 	if (max == TRUE) {
 		if (p->stimer->st_cached_max_se) {
-			return p->stimer->st_cached_max_se;
-		} else if (p->peername) {
-			struct sip_peer *pp = find_peer(p->peername, NULL, TRUE, FINDPEERS, FALSE, 0);
-			if (pp) {
-				p->stimer->st_cached_max_se = pp->stimer.st_max_se;
-				unref_peer(pp, "unref peer pointer from find_peer call in st_get_se");
-				return (p->stimer->st_cached_max_se);
-			}
+			return  p->stimer->st_cached_max_se;
+		}
+		if (p->relatedpeer) {
+			p->stimer->st_cached_max_se = p->relatedpeer->stimer.st_max_se;
+			return (p->stimer->st_cached_max_se);
 		}
 		p->stimer->st_cached_max_se = global_max_se;
 		return (p->stimer->st_cached_max_se);
@@ -24076,13 +24074,9 @@
 	if (p->stimer->st_cached_min_se) {
 		return p->stimer->st_cached_min_se;
 	} 
-	if (p->peername) {
-		struct sip_peer *pp = find_peer(p->peername, NULL, TRUE, FINDPEERS, FALSE, 0);
-		if (pp) {
-			p->stimer->st_cached_min_se = pp->stimer.st_min_se;
-			unref_peer(pp, "unref peer pointer from find_peer call in st_get_se (2)");
-			return (p->stimer->st_cached_min_se);
-		}
+	if (p->relatedpeer) {
+		p->stimer->st_cached_min_se = p->relatedpeer->stimer.st_min_se;
+		return (p->stimer->st_cached_min_se);
 	}
 	p->stimer->st_cached_min_se = global_min_se;
 	return (p->stimer->st_cached_min_se);
@@ -24097,13 +24091,9 @@
 	if (p->stimer->st_cached_ref != SESSION_TIMER_REFRESHER_AUTO)
 		return p->stimer->st_cached_ref;
 
-	if (p->peername) {
-		struct sip_peer *pp = find_peer(p->peername, NULL, TRUE, FINDPEERS, FALSE, 0);
-		if (pp) {
-			p->stimer->st_cached_ref = pp->stimer.st_ref;
-			unref_peer(pp, "unref peer pointer from find_peer call in st_get_refresher");
-			return pp->stimer.st_ref;
-		}
+	if (p->relatedpeer) {
+		p->stimer->st_cached_ref = p->relatedpeer->stimer.st_ref;
+		return p->stimer->st_cached_ref;
 	}
 	
 	p->stimer->st_cached_ref = global_st_refresher;
@@ -24122,13 +24112,9 @@
 	if (p->stimer->st_cached_mode != SESSION_TIMER_MODE_INVALID)
 		return p->stimer->st_cached_mode;
 
-	if (p->peername) {
-		struct sip_peer *pp = find_peer(p->peername, NULL, TRUE, FINDPEERS, FALSE, 0);
-		if (pp) {
-			p->stimer->st_cached_mode = pp->stimer.st_mode_oper;
-			unref_peer(pp, "unref peer pointer from find_peer call in st_get_mode");
-			return pp->stimer.st_mode_oper;
-		}
+	if (p->relatedpeer) {
+		p->stimer->st_cached_mode = p->relatedpeer->stimer.st_mode_oper;
+		return p->stimer->st_cached_mode;
 	}
 
 	p->stimer->st_cached_mode = global_st_mode;




More information about the asterisk-commits mailing list