[svn-commits] russell: branch russell/iax2_find_callno_1.2 r115295 - /team/russell/iax2_fin...

SVN commits to the Digium repositories svn-commits at lists.digium.com
Mon May 5 10:59:58 CDT 2008


Author: russell
Date: Mon May  5 10:59:58 2008
New Revision: 115295

URL: http://svn.digium.com/view/asterisk?view=rev&rev=115295
Log:
finish the backport

Modified:
    team/russell/iax2_find_callno_1.2/channels/chan_iax2.c

Modified: team/russell/iax2_find_callno_1.2/channels/chan_iax2.c
URL: http://svn.digium.com/view/asterisk/team/russell/iax2_find_callno_1.2/channels/chan_iax2.c?view=diff&rev=115295&r1=115294&r2=115295
==============================================================================
--- team/russell/iax2_find_callno_1.2/channels/chan_iax2.c (original)
+++ team/russell/iax2_find_callno_1.2/channels/chan_iax2.c Mon May  5 10:59:58 2008
@@ -927,9 +927,179 @@
 	return res;
 }
 
+static void update_max_trunk(void)
+{
+	int max = TRUNK_CALL_START;
+	int x;
+	/* XXX Prolly don't need locks here XXX */
+	for (x=TRUNK_CALL_START;x<IAX_MAX_CALLS - 1; x++) {
+		if (iaxs[x])
+			max = x + 1;
+	}
+	maxtrunkcall = max;
+	if (option_debug && iaxdebug)
+		ast_log(LOG_DEBUG, "New max trunk callno is %d\n", max);
+}
+
+static void iax2_destroy_helper(struct chan_iax2_pvt *pvt)
+{
+	if (ast_test_flag(pvt, IAX_MAXAUTHREQ)) {
+		struct iax2_user *user;
+
+		ast_mutex_lock(&userl.lock);
+		user = userl.users;
+		while (user) {
+			if (!strcmp(user->name, pvt->username)) {
+				user->curauthreq--;
+				break;
+			}
+			user = user->next;
+		}
+		ast_mutex_unlock(&userl.lock);
+	}
+
+	/* No more pings or lagrq's */
+	if (pvt->pingid > -1)
+		ast_sched_del(sched, pvt->pingid);
+	if (pvt->lagid > -1)
+		ast_sched_del(sched, pvt->lagid);
+	if (pvt->autoid > -1)
+		ast_sched_del(sched, pvt->autoid);
+	if (pvt->authid > -1)
+		ast_sched_del(sched, pvt->authid);
+	if (pvt->initid > -1)
+		ast_sched_del(sched, pvt->initid);
+#ifdef NEWJB
+	if (pvt->jbid > -1)
+		ast_sched_del(sched, pvt->jbid);
+	pvt->jbid = -1;
+#endif
+	pvt->pingid = -1;
+	pvt->lagid = -1;
+	pvt->autoid = -1;
+	pvt->authid = -1;
+	pvt->initid = -1;
+}
+
+static void store_by_peercallno(struct chan_iax2_pvt *pvt)
+{
+	if (!pvt->peercallno) {
+		ast_log(LOG_ERROR, "This should not be called without a peer call number.\n");
+		return;
+	}
+
+	ao2_link(iax_peercallno_pvts, pvt);
+}
+
+static void remove_by_peercallno(struct chan_iax2_pvt *pvt)
+{
+	if (!pvt->peercallno) {
+		ast_log(LOG_ERROR, "This should not be called without a peer call number.\n");
+		return;
+	}
+
+	ao2_unlink(iax_peercallno_pvts, pvt);
+}
+
+
+
+static void iax2_destroy(int callno)
+{
+	struct chan_iax2_pvt *pvt;
+	struct ast_channel *owner;
+
+retry:
+	ast_mutex_lock(&iaxsl[callno]);
+	pvt = iaxs[callno];
+	gettimeofday(&lastused[callno], NULL);
+
+	if (pvt)
+		owner = pvt->owner;
+	else
+		owner = NULL;
+	if (owner) {
+		if (ast_mutex_trylock(&owner->lock)) {
+			ast_log(LOG_NOTICE, "Avoiding IAX destroy deadlock\n");
+			ast_mutex_unlock(&iaxsl[callno]);
+			usleep(1);
+			goto retry;
+		}
+	}
+	if (!owner)
+		iaxs[callno] = NULL;
+	if (pvt) {
+		if (owner) {
+			/* If there's an owner, prod it to give up */
+			owner->_softhangup |= AST_SOFTHANGUP_DEV;
+			ast_queue_hangup(owner);
+		} else {
+			pvt->owner = NULL;
+		}
+
+		if (pvt->peercallno) {
+			remove_by_peercallno(pvt);
+		}
+
+		if (!owner) {
+			ao2_ref(pvt, -1);
+			pvt = NULL;
+		}
+	}
+
+	if (owner) {
+		ast_mutex_unlock(&owner->lock);
+	}
+
+	ast_mutex_unlock(&iaxsl[callno]);
+
+	if (callno & 0x4000) {
+		update_max_trunk();
+	}
+}
+
+static void iax2_frame_free(struct iax_frame *fr)
+{
+	if (fr->retrans > -1)
+		ast_sched_del(sched, fr->retrans);
+	iax_frame_free(fr);
+}
+
 static void pvt_destructor(void *obj)
 {
-
+	struct chan_iax2_pvt *pvt = obj;
+	struct iax_frame *cur;
+
+	iax2_destroy_helper(pvt);
+
+	if (pvt->bridgetrans)
+		ast_translator_free_path(pvt->bridgetrans);
+	pvt->bridgetrans = NULL;
+
+	/* Already gone */
+	ast_set_flag(pvt, IAX_ALREADYGONE);	
+
+	for (cur = iaxq.head; cur ; cur = cur->next) {
+		/* Cancel any pending transmissions */
+		if (cur->callno == pvt->callno) 
+			cur->retries = -1;
+	}
+	if (pvt->reg) {
+		pvt->reg->callno = 0;
+	}
+	if (!pvt->owner) {
+		if (pvt->vars) {
+			ast_variables_destroy(pvt->vars);
+			pvt->vars = NULL;
+		}
+#ifdef NEWJB
+ 		{
+			jb_frame frame;
+			while (jb_getall(pvt->jb,&frame) == JB_OK)
+				iax2_frame_free(frame.data);
+			jb_destroy(pvt->jb);
+		}
+#endif
+	}
 }
 
 static struct chan_iax2_pvt *new_iax(struct sockaddr_in *sin, int lockpeer, const char *host)
@@ -1000,20 +1170,6 @@
 			return 1;
 	}
 	return 0;
-}
-
-static void update_max_trunk(void)
-{
-	int max = TRUNK_CALL_START;
-	int x;
-	/* XXX Prolly don't need locks here XXX */
-	for (x=TRUNK_CALL_START;x<IAX_MAX_CALLS - 1; x++) {
-		if (iaxs[x])
-			max = x + 1;
-	}
-	maxtrunkcall = max;
-	if (option_debug && iaxdebug)
-		ast_log(LOG_DEBUG, "New max trunk callno is %d\n", max);
 }
 
 static void update_max_nontrunk(void)
@@ -1075,26 +1231,6 @@
 	update_max_trunk();
 	update_max_nontrunk();
 	return res;
-}
-
-static void store_by_peercallno(struct chan_iax2_pvt *pvt)
-{
-	if (!pvt->peercallno) {
-		ast_log(LOG_ERROR, "This should not be called without a peer call number.\n");
-		return;
-	}
-
-	ao2_link(iax_peercallno_pvts, pvt);
-}
-
-static void remove_by_peercallno(struct chan_iax2_pvt *pvt)
-{
-	if (!pvt->peercallno) {
-		ast_log(LOG_ERROR, "This should not be called without a peer call number.\n");
-		return;
-	}
-
-	ao2_unlink(iax_peercallno_pvts, pvt);
 }
 
 static int find_callno(unsigned short callno, unsigned short dcallno, struct sockaddr_in *sin, int new, int lockpeer, int sockfd, int full_frame)
@@ -1214,13 +1350,6 @@
 		res = x;
 	}
 	return res;
-}
-
-static void iax2_frame_free(struct iax_frame *fr)
-{
-	if (fr->retrans > -1)
-		ast_sched_del(sched, fr->retrans);
-	iax_frame_free(fr);
 }
 
 static int iax2_queue_frame(int callno, struct ast_frame *f)
@@ -1696,112 +1825,7 @@
 	return res;
 }
 
-static void iax2_destroy(int callno)
-{
-	struct chan_iax2_pvt *pvt;
-	struct iax_frame *cur;
-	struct ast_channel *owner;
-	struct iax2_user *user;
-
-retry:
-	ast_mutex_lock(&iaxsl[callno]);
-	pvt = iaxs[callno];
-	gettimeofday(&lastused[callno], NULL);
-
-	if (pvt)
-		owner = pvt->owner;
-	else
-		owner = NULL;
-	if (owner) {
-		if (ast_mutex_trylock(&owner->lock)) {
-			ast_log(LOG_NOTICE, "Avoiding IAX destroy deadlock\n");
-			ast_mutex_unlock(&iaxsl[callno]);
-			usleep(1);
-			goto retry;
-		}
-	}
-	if (!owner)
-		iaxs[callno] = NULL;
-	if (pvt) {
-		if (!owner)
-			pvt->owner = NULL;
-		if (ast_test_flag(pvt, IAX_MAXAUTHREQ)) {
-			ast_mutex_lock(&userl.lock);
-			user = userl.users;
-			while (user) {
-				if (!strcmp(user->name, pvt->username)) {
-					user->curauthreq--;
-					break;
-				}
-				user = user->next;
-			}
-			ast_mutex_unlock(&userl.lock);
-		}
-		/* No more pings or lagrq's */
-		if (pvt->pingid > -1)
-			ast_sched_del(sched, pvt->pingid);
-		if (pvt->lagid > -1)
-			ast_sched_del(sched, pvt->lagid);
-		if (pvt->autoid > -1)
-			ast_sched_del(sched, pvt->autoid);
-		if (pvt->authid > -1)
-			ast_sched_del(sched, pvt->authid);
-		if (pvt->initid > -1)
-			ast_sched_del(sched, pvt->initid);
-#ifdef NEWJB
-		if (pvt->jbid > -1)
-			ast_sched_del(sched, pvt->jbid);
-		pvt->jbid = -1;
-#endif
-		pvt->pingid = -1;
-		pvt->lagid = -1;
-		pvt->autoid = -1;
-		pvt->authid = -1;
-		pvt->initid = -1;
-		if (pvt->bridgetrans)
-			ast_translator_free_path(pvt->bridgetrans);
-		pvt->bridgetrans = NULL;
-
-		/* Already gone */
-		ast_set_flag(pvt, IAX_ALREADYGONE);	
-
-		if (owner) {
-			/* If there's an owner, prod it to give up */
-			owner->_softhangup |= AST_SOFTHANGUP_DEV;
-			ast_queue_hangup(owner);
-		}
-
-		for (cur = iaxq.head; cur ; cur = cur->next) {
-			/* Cancel any pending transmissions */
-			if (cur->callno == pvt->callno) 
-				cur->retries = -1;
-		}
-		if (pvt->reg) {
-			pvt->reg->callno = 0;
-		}
-		if (!owner) {
-			if (pvt->vars) {
-				ast_variables_destroy(pvt->vars);
-				pvt->vars = NULL;
-			}
-#ifdef NEWJB
- 			{
-                            jb_frame frame;
-                            while(jb_getall(pvt->jb,&frame) == JB_OK)
-				iax2_frame_free(frame.data);
-                            jb_destroy(pvt->jb);
-                        }
-#endif
-			free(pvt);
-		}
-	}
-	if (owner) {
-		ast_mutex_unlock(&owner->lock);
-	}
-	ast_mutex_unlock(&iaxsl[callno]);
-	if (callno & 0x4000)
-		update_max_trunk();
-}
+
 static void iax2_destroy_nolock(int callno)
 {	
 	/* Actually it's easier to unlock, kill it, and relock */




More information about the svn-commits mailing list