[Asterisk-cvs] asterisk/channels chan_iax2.c,1.237,1.238

markster at lists.digium.com markster at lists.digium.com
Sat Jan 15 01:29:32 CST 2005


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

Modified Files:
	chan_iax2.c 
Log Message:
Simplify find_peer usage (bug #3341)


Index: chan_iax2.c
===================================================================
RCS file: /usr/cvsroot/asterisk/channels/chan_iax2.c,v
retrieving revision 1.237
retrieving revision 1.238
diff -u -d -r1.237 -r1.238
--- chan_iax2.c	14 Jan 2005 21:10:16 -0000	1.237
+++ chan_iax2.c	15 Jan 2005 07:33:17 -0000	1.238
@@ -551,6 +551,8 @@
 
 AST_MUTEX_DEFINE_STATIC(dpcache_lock);
 
+static void destroy_peer(struct iax2_peer *peer);
+
 static void iax_debug_output(const char *data)
 {
 	if (iaxdebug)
@@ -653,13 +655,11 @@
 static struct iax2_peer *find_peer(const char *name) 
 {
 	struct iax2_peer *peer;
-	struct iax2_peer *prev;
 	ast_mutex_lock(&peerl.lock);
 	for(peer = peerl.peers; peer; peer = peer->next) {
 		if (!strcasecmp(peer->name, name)) {
 			break;
 		}
-		prev = peer;
 	}
 	ast_mutex_unlock(&peerl.lock);
 	if(!peer)
@@ -1633,7 +1633,6 @@
 
 	if (argc != 4)
 		return RESULT_SHOWUSAGE;
-	ast_mutex_lock(&peerl.lock);
 	peer = find_peer(argv[3]);
 	if (peer) {
 		ast_cli(fd,"\n\n");
@@ -1676,13 +1675,13 @@
 			strncpy(status, "UNKNOWN", sizeof(status) - 1);
 		ast_cli(fd, "%s\n",status);
 		ast_cli(fd,"\n");
+		if (ast_test_flag(peer, IAX_TEMPONLY))
+			destroy_peer(peer);
 	} else {
 		ast_cli(fd,"Peer %s not found.\n", argv[3]);
 		ast_cli(fd,"\n");
 	}
 
-	ast_mutex_unlock(&peerl.lock);
-
 	return RESULT_SUCCESS;
 }
 
@@ -2118,7 +2117,6 @@
 static struct iax2_user *build_user(const char *name, struct ast_variable *v, int temponly);
 
 static void destroy_user(struct iax2_user *user);
-static void destroy_peer(struct iax2_peer *peer);
 
 static struct iax2_peer *realtime_peer(const char *peername)
 {
@@ -2236,17 +2234,7 @@
 	if (sockfd)
 		*sockfd = defaultsockfd;
 	sin->sin_family = AF_INET;
-	ast_mutex_lock(&peerl.lock);
-	p = peerl.peers;
-	while(p) {
-		if (!strcasecmp(p->name, peer)) {
-			break;
-		}
-		p = p->next;
-	}
-	ast_mutex_unlock(&peerl.lock);
-	if (!p)
-		p = realtime_peer(peer);
+	p = find_peer(peer);
 	if (p) {
 		found++;
 		if ((p->addr.sin_addr.s_addr || p->defaddr.sin_addr.s_addr) &&
@@ -4302,14 +4290,8 @@
 	/* We release the lock for the call to prevent a deadlock, but it's okay because
 	   only the current thread could possibly make it go away or make changes */
 	ast_mutex_unlock(&iaxsl[callno]);
-	ast_mutex_lock(&peerl.lock);
-	for (p = peerl.peers; p ; p = p->next) 
-		if (!strcasecmp(p->name, peer))
-			break;
-	ast_mutex_unlock(&peerl.lock);
+	p = find_peer(peer);
 	ast_mutex_lock(&iaxsl[callno]);
-	if (!p) 
-		p = realtime_peer(peer);
 
 	if (!p) {
 		if (authdebug)
@@ -4868,13 +4850,7 @@
 	char iabuf[INET_ADDRSTRLEN];
 	int version;
 	memset(&ied, 0, sizeof(ied));
-	for (p = peerl.peers;p;p = p->next) {
-		if (!strcasecmp(name, p->name)) {
-			break;
-		}
-	}
-	if (!p)
-		p = realtime_peer(name);
+	p = find_peer(name);
 	if (p) {
 		if (ast_test_flag(p, IAX_TEMPONLY))
 			realtime_update(name, sin);
@@ -4950,15 +4926,7 @@
 {
 	struct iax_ie_data ied;
 	struct iax2_peer *p;
-	ast_mutex_lock(&peerl.lock);
-	for (p = peerl.peers;p;p = p->next) {
-		if (!strcasecmp(name, p->name)) {
-			break;
-		}
-	}
-	ast_mutex_unlock(&peerl.lock);
-	if (!p)
-		p = realtime_peer(name);
+	p = find_peer(name);
 	if (p) {
 		memset(&ied, 0, sizeof(ied));
 		iax_ie_append_short(&ied, IAX_IE_AUTHMETHODS, p->authmethods);




More information about the svn-commits mailing list