[svn-commits] mmichelson: branch mmichelson/forward-loop r87038 - in /team/mmichelson/forwa...

SVN commits to the Digium repositories svn-commits at lists.digium.com
Thu Oct 25 11:45:54 CDT 2007


Author: mmichelson
Date: Thu Oct 25 11:45:54 2007
New Revision: 87038

URL: http://svn.digium.com/view/asterisk?view=rev&rev=87038
Log:
Added support for app_queue to prevent forwarding loops.
Fixed some not-so-thread-safe behavior, too.


Modified:
    team/mmichelson/forward-loop/apps/app_dial.c
    team/mmichelson/forward-loop/apps/app_queue.c
    team/mmichelson/forward-loop/main/global_datastores.c

Modified: team/mmichelson/forward-loop/apps/app_dial.c
URL: http://svn.digium.com/view/asterisk/team/mmichelson/forward-loop/apps/app_dial.c?view=diff&rev=87038&r1=87037&r2=87038
==============================================================================
--- team/mmichelson/forward-loop/apps/app_dial.c (original)
+++ team/mmichelson/forward-loop/apps/app_dial.c Thu Oct 25 11:45:54 2007
@@ -1094,7 +1094,7 @@
 		char *tech = strsep(&number, "/");
 		/* find if we already dialed this interface */
 		int dialed = 0;
-		struct ast_dialed_interface *cur;
+		struct ast_dialed_interface *di;
 		struct ast_datastore *datastore;
 		AST_LIST_HEAD(, ast_dialed_interface) *dialed_interfaces;
 		if (!number) {
@@ -1137,19 +1137,18 @@
 		} else 
 			dialed_interfaces = datastore->data;
 		AST_LIST_LOCK(dialed_interfaces);
-		AST_LIST_TRAVERSE(dialed_interfaces, cur, list) {
+		AST_LIST_TRAVERSE(dialed_interfaces, di, list) {
 			char *dash;
 			char *name = ast_strdupa(tmp->chan->name);
 			if ((dash = strchr(name, '-')))
 				*dash = '\0';
 			/* XXX case sensitive??? */
-			ast_log(LOG_DEBUG, "Checking interface '%s' against '%s'\n", cur->interface, name);
-			if(!strcasecmp(cur->interface, name)) {
+			ast_log(LOG_DEBUG, "Checking interface '%s' against '%s'\n", di->interface, name);
+			if(!strcasecmp(di->interface, name)) {
 				dialed = 1;
 				break;
 			}
 		}
-		AST_LIST_UNLOCK(dialed_interfaces);
 		if(!dialed) {
 			char *blah;
 			char *tech;
@@ -1160,19 +1159,20 @@
 			if ((blah = strchr(tech, '/')))
 				*blah = '\0';
 			if (strcasecmp(tech, "Local")) {
-				if(!(cur = ast_calloc(1, sizeof(*cur))))
+				if(!(di = ast_calloc(1, sizeof(*di))))
 					goto out;
-				ast_copy_string(cur->interface, interface, sizeof(cur->interface));
-				ast_log(LOG_DEBUG, "Adding interface '%s' to the list of dialed interfaces\n", cur->interface);
-				AST_LIST_INSERT_TAIL(dialed_interfaces, cur, list);
+				ast_copy_string(di->interface, interface, sizeof(di->interface));
+				ast_log(LOG_DEBUG, "Adding interface '%s' to the list of dialed interfaces\n", di->interface);
+				AST_LIST_INSERT_TAIL(dialed_interfaces, di, list);
 			}
 		} else {
-			ast_log(LOG_DEBUG, "Skipping dialing interface '%s' since it has already been dialed\n", cur->interface);
+			ast_log(LOG_DEBUG, "Skipping dialing interface '%s' since it has already been dialed\n", di->interface);
 			ast_hangup(tmp->chan);
 			tmp->chan = NULL;
 			free(tmp);
 			continue;
 		}
+		AST_LIST_UNLOCK(dialed_interfaces);
 		pbx_builtin_setvar_helper(tmp->chan, "DIALEDPEERNUMBER", numsubst);
 #if 0		
 		if (!ast_strlen_zero(tmp->chan->call_forward)) {

Modified: team/mmichelson/forward-loop/apps/app_queue.c
URL: http://svn.digium.com/view/asterisk/team/mmichelson/forward-loop/apps/app_queue.c?view=diff&rev=87038&r1=87037&r2=87038
==============================================================================
--- team/mmichelson/forward-loop/apps/app_queue.c (original)
+++ team/mmichelson/forward-loop/apps/app_queue.c Thu Oct 25 11:45:54 2007
@@ -93,6 +93,7 @@
 #include "asterisk/devicestate.h"
 #include "asterisk/stringfields.h"
 #include "asterisk/astobj2.h"
+#include "asterisk/global_datastores.h"
 
 enum {
 	QUEUE_STRATEGY_RINGALL = 0,
@@ -2130,6 +2131,7 @@
 						numnochan++;
 					} else {
 						ast_channel_inherit_variables(in, o->chan);
+						ast_channel_datastore_inherit(in, o->chan);
 						if (o->chan->cid.cid_num)
 							free(o->chan->cid.cid_num);
 						o->chan->cid.cid_num = ast_strdup(in->cid.cid_num);
@@ -2552,13 +2554,43 @@
 	memi = ao2_iterator_init(qe->parent->members, 0);
 	while ((cur = ao2_iterator_next(&memi))) {
 		struct callattempt *tmp = ast_calloc(1, sizeof(*tmp));
-
+		struct ast_datastore *datastore = ast_channel_datastore_find(qe->chan, &dialed_interface_info, NULL);
+		struct ast_dialed_interface *di;
+		int dialed = 0;
+		AST_LIST_HEAD(, ast_dialed_interface) *dialed_interfaces;
 		if (!tmp) {
 			ao2_ref(cur, -1);
 			ast_mutex_unlock(&qe->parent->lock);
 			if (use_weight)
 				AST_LIST_UNLOCK(&queues);
 			goto out;
+		}
+		if (!datastore) {
+			datastore = ast_channel_datastore_alloc(&dialed_interface_info, NULL);
+			datastore->inheritance = DATASTORE_INHERIT_FOREVER;
+			dialed_interfaces = ast_calloc(1, sizeof(*dialed_interfaces));
+			datastore->data = dialed_interfaces;
+			AST_LIST_HEAD_INIT(dialed_interfaces);
+			ast_channel_datastore_add(qe->chan, datastore);
+		} else
+			dialed_interfaces = datastore->data;
+		AST_LIST_LOCK(dialed_interfaces);
+		AST_LIST_TRAVERSE(dialed_interfaces, di, list) {
+			/* XXX case sensitive ?? */
+			if(!strcasecmp(cur->interface, di->interface)) {
+				dialed = 1;
+				break;
+			}
+		}
+		AST_LIST_UNLOCK(dialed_interfaces);
+		if (!dialed) {
+			di = ast_calloc(1, sizeof(*di));
+			ast_copy_string(di->interface, cur->interface, sizeof(di->interface));
+			AST_LIST_INSERT_TAIL(dialed_interfaces, di, list);
+		} else {
+			ast_log(LOG_DEBUG, "Skipping dialing interface '%s' since it has already been dialed\n", di->interface);
+			free(tmp);
+			continue;
 		}
 		tmp->stillgoing = -1;
 		tmp->member = cur;

Modified: team/mmichelson/forward-loop/main/global_datastores.c
URL: http://svn.digium.com/view/asterisk/team/mmichelson/forward-loop/main/global_datastores.c?view=diff&rev=87038&r1=87037&r2=87038
==============================================================================
--- team/mmichelson/forward-loop/main/global_datastores.c (original)
+++ team/mmichelson/forward-loop/main/global_datastores.c Thu Oct 25 11:45:54 2007
@@ -33,7 +33,9 @@
 	AST_LIST_HEAD_INIT(new_list);
 	AST_LIST_LOCK(old_list);
 	AST_LIST_TRAVERSE(old_list, di, list) {
-		AST_LIST_INSERT_TAIL(new_list, di, list);
+		struct ast_dialed_interface *di2 = ast_calloc(1, sizeof(*di2));
+		ast_copy_string(di2->interface, di->interface, sizeof(di2->interface));
+		AST_LIST_INSERT_TAIL(new_list, di2, list);
 	}
 	AST_LIST_UNLOCK(old_list);
 




More information about the svn-commits mailing list