[asterisk-commits] mmichelson: branch mmichelson/forward-loop r87062 - in /team/mmichelson/forwa...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Thu Oct 25 16:38:15 CDT 2007


Author: mmichelson
Date: Thu Oct 25 16:38:14 2007
New Revision: 87062

URL: http://svn.digium.com/view/asterisk?view=rev&rev=87062
Log:
Removed extraneous debug messages and added code to handle failure cases from running out of 
memory or other such possible problems.


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=87062&r1=87061&r2=87062
==============================================================================
--- team/mmichelson/forward-loop/apps/app_dial.c (original)
+++ team/mmichelson/forward-loop/apps/app_dial.c Thu Oct 25 16:38:14 2007
@@ -303,7 +303,6 @@
 struct dial_localuser {
 	struct ast_channel *chan;
 	unsigned int flags;
-	int forwards;
 	struct dial_localuser *next;
 };
 
@@ -321,8 +320,6 @@
 		free(oo);
 	}
 }
-
-#define AST_MAX_FORWARDS   8
 
 #define AST_MAX_WATCHERS 256
 
@@ -488,33 +485,23 @@
 					tech = "Local";
 				}
 				/* Before processing channel, go ahead and check for forwarding */
-				o->forwards++;
-				if (o->forwards < AST_MAX_FORWARDS) {
+				if (option_verbose > 2)
+					ast_verbose(VERBOSE_PREFIX_3 "Now forwarding %s to '%s/%s' (thanks to %s)\n", in->name, tech, stuff, c->name);
+				/* If we have been told to ignore forwards, just set this channel to null and continue processing extensions normally */
+				if (ast_test_flag(peerflags, OPT_IGNORE_FORWARDING)) {
 					if (option_verbose > 2)
-						ast_verbose(VERBOSE_PREFIX_3 "Now forwarding %s to '%s/%s' (thanks to %s)\n", in->name, tech, stuff, c->name);
-					/* If we have been told to ignore forwards, just set this channel to null and continue processing extensions normally */
-					if (ast_test_flag(peerflags, OPT_IGNORE_FORWARDING)) {
-						if (option_verbose > 2)
-							ast_verbose(VERBOSE_PREFIX_3 "Forwarding %s to '%s/%s' prevented.\n", in->name, tech, stuff);
-						c = o->chan = NULL;
-						cause = AST_CAUSE_BUSY;
-					} else {
-						/* Setup parameters */
-						if ((c = o->chan = ast_request(tech, in->nativeformats, stuff, &cause))) {
-							ast_log(LOG_DEBUG, "Requester 2 got channel %p\n", c);
-							ast_log(LOG_DEBUG, "Is it bridged? %s %p\n", ast_bridged_channel(c) ? "Yes" : "No", ast_bridged_channel(c));
-							if (single)
-								ast_channel_make_compatible(o->chan, in);
-							ast_channel_inherit_variables(in, o->chan);
-							ast_channel_datastore_inherit(in, o->chan);
-						} else
-							ast_log(LOG_NOTICE, "Unable to create local channel for call forward to '%s/%s' (cause = %d)\n", tech, stuff, cause);
-					}
+						ast_verbose(VERBOSE_PREFIX_3 "Forwarding %s to '%s/%s' prevented.\n", in->name, tech, stuff);
+					c = o->chan = NULL;
+					cause = AST_CAUSE_BUSY;
 				} else {
-					if (option_verbose > 2)
-						ast_verbose(VERBOSE_PREFIX_3 "Too many forwards from %s\n", c->name);
-					cause = AST_CAUSE_CONGESTION;
-					c = o->chan = NULL;
+					/* Setup parameters */
+					if ((c = o->chan = ast_request(tech, in->nativeformats, stuff, &cause))) {
+						if (single)
+							ast_channel_make_compatible(o->chan, in);
+						ast_channel_inherit_variables(in, o->chan);
+						ast_channel_datastore_inherit(in, o->chan);
+					} else
+						ast_log(LOG_NOTICE, "Unable to create local channel for call forward to '%s/%s' (cause = %d)\n", tech, stuff, cause);
 				}
 				if (!c) {
 					ast_clear_flag(o, DIAL_STILLGOING);	
@@ -1115,6 +1102,49 @@
 		}
 		ast_copy_string(numsubst, number, sizeof(numsubst));
 		/* Request the peer */
+		if (!(datastore = ast_channel_datastore_find(chan, &dialed_interface_info, NULL))) {
+			if(!(datastore = ast_channel_datastore_alloc(&dialed_interface_info, NULL))) {
+				ast_log(LOG_WARNING, "Unable to create channel datastore for dialed interfaces. Aborting!\n"); 
+				free(tmp);
+				goto out;
+			}
+			else {
+				datastore->inheritance = DATASTORE_INHERIT_FOREVER;
+				if((dialed_interfaces = ast_calloc(1, sizeof(*dialed_interfaces)))) {
+					datastore->data = dialed_interfaces;
+					AST_LIST_HEAD_INIT(dialed_interfaces);
+					ast_channel_datastore_add(chan, datastore);
+				} else {
+					free(tmp);
+					goto out;
+				}
+			}
+		} else 
+			dialed_interfaces = datastore->data;
+		AST_LIST_LOCK(dialed_interfaces);
+		AST_LIST_TRAVERSE(dialed_interfaces, di, list) {
+			/* XXX case sensitive??? */
+			if(!strcasecmp(di->interface, interface)) {
+				dialed = 1;
+				break;
+			}
+		}
+		if(!dialed && strcasecmp(tech, "Local")) {
+			if(!(di = ast_calloc(1, sizeof(*di) + strlen(interface)))) {
+				AST_LIST_UNLOCK(dialed_interfaces);
+				free(tmp);
+				goto out;
+			}
+			strcpy(di->interface, interface);
+			AST_LIST_INSERT_TAIL(dialed_interfaces, di, list);
+		} else {
+			AST_LIST_UNLOCK(dialed_interfaces);
+			ast_log(LOG_WARNING, "Skipping dialing interface '%s' again since it has already been dialed\n", di->interface);
+			free(tmp);
+			continue;
+		}
+		AST_LIST_UNLOCK(dialed_interfaces);
+
 		tmp->chan = ast_request(tech, chan->nativeformats, numsubst, &cause);
 		if (!tmp->chan) {
 			/* If we can't, just go on to the next call */
@@ -1125,43 +1155,8 @@
 			free(tmp);
 			continue;
 		}
-		ast_log(LOG_DEBUG, "Dialing from interface %s: %p\n", chan->name, chan);
-
-		if (!(datastore = ast_channel_datastore_find(chan, &dialed_interface_info, NULL))) {
-			ast_log(LOG_DEBUG, "Creating datastore for channel '%s'\n", chan->name);
-			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(chan, datastore);
-		} else 
-			dialed_interfaces = datastore->data;
-		AST_LIST_LOCK(dialed_interfaces);
-		AST_LIST_TRAVERSE(dialed_interfaces, di, list) {
-			/* XXX case sensitive??? */
-			ast_log(LOG_DEBUG, "Checking interface '%s' against '%s'\n", di->interface, interface);
-			if(!strcasecmp(di->interface, interface)) {
-				dialed = 1;
-				break;
-			}
-		}
-		if(!dialed && strcasecmp(tech, "Local")) {
-			if(!(di = ast_calloc(1, sizeof(*di) + strlen(interface))))
-				goto out;
-			strcpy(di->interface, 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_LIST_UNLOCK(dialed_interfaces);
-			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);
+
+				pbx_builtin_setvar_helper(tmp->chan, "DIALEDPEERNUMBER", numsubst);
 
 		/* Setup outgoing SDP to match incoming one */
 		ast_rtp_make_compatible(tmp->chan, chan, !outgoing && !rest);

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=87062&r1=87061&r2=87062
==============================================================================
--- team/mmichelson/forward-loop/apps/app_queue.c (original)
+++ team/mmichelson/forward-loop/apps/app_queue.c Thu Oct 25 16:38:14 2007
@@ -2566,7 +2566,14 @@
 			goto out;
 		}
 		if (!datastore) {
-			datastore = ast_channel_datastore_alloc(&dialed_interface_info, NULL);
+			if(!(datastore = ast_channel_datastore_alloc(&dialed_interface_info, NULL))) {
+				ao2_ref(cur, -1);
+				ast_mutex_unlock(&qe->parent->lock);
+				if(use_weight)
+					AST_LIST_UNLOCK(&queues);
+				free(tmp);
+				goto out;
+			}
 			datastore->inheritance = DATASTORE_INHERIT_FOREVER;
 			dialed_interfaces = ast_calloc(1, sizeof(*dialed_interfaces));
 			datastore->data = dialed_interfaces;
@@ -2583,7 +2590,15 @@
 			}
 		}
 		if (!dialed) {
-			di = ast_calloc(1, sizeof(*di));
+			if(!(di = ast_calloc(1, sizeof(*di)))) {
+				ao2_ref(cur, -1);
+				AST_LIST_UNLOCK(dialed_interfaces);
+				ast_mutex_unlock(&qe->parent->lock);
+				if(use_weight)
+					AST_LIST_UNLOCK(&queues);
+				free(tmp);
+				goto out;
+			} 
 			ast_copy_string(di->interface, cur->interface, sizeof(di->interface));
 			AST_LIST_INSERT_TAIL(dialed_interfaces, di, list);
 		} else {

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=87062&r1=87061&r2=87062
==============================================================================
--- team/mmichelson/forward-loop/main/global_datastores.c (original)
+++ team/mmichelson/forward-loop/main/global_datastores.c Thu Oct 25 16:38:14 2007
@@ -34,6 +34,10 @@
 	AST_LIST_LOCK(old_list);
 	AST_LIST_TRAVERSE(old_list, di, list) {
 		struct ast_dialed_interface *di2 = ast_calloc(1, sizeof(*di2) + strlen(di->interface));
+		if(!di2) {
+			AST_LIST_UNLOCK(old_list);
+			return NULL;
+		}
 		strcpy(di2->interface, di->interface);
 		AST_LIST_INSERT_TAIL(new_list, di2, list);
 	}




More information about the asterisk-commits mailing list