[svn-commits] rmudgett: branch 1.8 r331248 - in /branches/1.8: apps/ channels/ main/

SVN commits to the Digium repositories svn-commits at lists.digium.com
Tue Aug 9 17:13:03 CDT 2011


Author: rmudgett
Date: Tue Aug  9 17:12:59 2011
New Revision: 331248

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=331248
Log:
Misc minor items found in code.

* Add some reentrancy protection in pbx.c when creating the contexts_table
hash table.

* Fix inverted test in chan_sip.c conditional code.

* Fix uninitialized variable and use of the wrong variable in chan_iax2.c.

* Fix test of return value in app_parkandannounce.c.  Explicitly testing
for -1 is bad if the function does not actually return that value when it
fails.

* Fixup some comments and add some curly braces in features.c.

Modified:
    branches/1.8/apps/app_parkandannounce.c
    branches/1.8/channels/chan_iax2.c
    branches/1.8/channels/chan_sip.c
    branches/1.8/main/features.c
    branches/1.8/main/pbx.c

Modified: branches/1.8/apps/app_parkandannounce.c
URL: http://svnview.digium.com/svn/asterisk/branches/1.8/apps/app_parkandannounce.c?view=diff&rev=331248&r1=331247&r2=331248
==============================================================================
--- branches/1.8/apps/app_parkandannounce.c (original)
+++ branches/1.8/apps/app_parkandannounce.c Tue Aug  9 17:12:59 2011
@@ -142,8 +142,10 @@
 	before we are done announcing and the channel is messed with, Kablooeee.  So we use Masq to prevent this.  */
 
 	res = ast_masq_park_call(chan, NULL, timeout, &lot);
-	if (res == -1)
-		return res;
+	if (res) {
+		/* Parking failed. */
+		return -1;
+	}
 
 	ast_verb(3, "Call Parking Called, lot: %d, timeout: %d, context: %s\n", lot, timeout, args.return_context);
 

Modified: branches/1.8/channels/chan_iax2.c
URL: http://svnview.digium.com/svn/asterisk/branches/1.8/channels/chan_iax2.c?view=diff&rev=331248&r1=331247&r2=331248
==============================================================================
--- branches/1.8/channels/chan_iax2.c (original)
+++ branches/1.8/channels/chan_iax2.c Tue Aug  9 17:12:59 2011
@@ -9257,7 +9257,8 @@
 	struct ast_channel *chan1, *chan2;
 	struct iax_dual *d;
 	struct ast_frame *f;
-	int ext;
+	int ext = 0;
+
 	d = stuff;
 	chan1 = d->chan1;
 	chan2 = d->chan2;
@@ -10694,7 +10695,7 @@
 					pbx_builtin_setvar_helper(owner, "BLINDTRANSFER", bridged_chan->name);
 					pbx_builtin_setvar_helper(bridged_chan, "BLINDTRANSFER", owner->name);
 
-					if (ast_parking_ext_valid(ies.called_number, c, iaxs[fr->callno]->context)) {
+					if (ast_parking_ext_valid(ies.called_number, owner, iaxs[fr->callno]->context)) {
 						ast_debug(1, "Parking call '%s'\n", bridged_chan->name);
 						if (iax_park(bridged_chan, owner, ies.called_number)) {
 							ast_log(LOG_WARNING, "Failed to park call '%s'\n",

Modified: branches/1.8/channels/chan_sip.c
URL: http://svnview.digium.com/svn/asterisk/branches/1.8/channels/chan_sip.c?view=diff&rev=331248&r1=331247&r2=331248
==============================================================================
--- branches/1.8/channels/chan_sip.c (original)
+++ branches/1.8/channels/chan_sip.c Tue Aug  9 17:12:59 2011
@@ -20764,7 +20764,7 @@
 	
 
 #ifdef WHEN_WE_KNOW_THAT_THE_CLIENT_SUPPORTS_MESSAGE
-	if (!res) {
+	if (res) {
 		transmit_message_with_text(transferer->tech_pvt, "Unable to park call.\n");
 	} else {
 		/* Then tell the transferer what happened */

Modified: branches/1.8/main/features.c
URL: http://svnview.digium.com/svn/asterisk/branches/1.8/main/features.c?view=diff&rev=331248&r1=331247&r2=331248
==============================================================================
--- branches/1.8/main/features.c (original)
+++ branches/1.8/main/features.c Tue Aug  9 17:12:59 2011
@@ -649,7 +649,8 @@
 
 static int parkinglot_cmp_cb(void *obj, void *arg, int flags)
 {
-	struct ast_parkinglot *parkinglot = obj, *parkinglot2 = arg;
+	struct ast_parkinglot *parkinglot = obj;
+	struct ast_parkinglot *parkinglot2 = arg;
 
 	return !strcasecmp(parkinglot->name, parkinglot2->name) ? CMP_MATCH | CMP_STOP : 0;
 }
@@ -3406,14 +3407,17 @@
 
 /*!
  * \brief bridge the call and set CDR
- * \param chan,peer,config
- * 
+ *
+ * \param chan The bridge considers this channel the caller.
+ * \param peer The bridge considers this channel the callee.
+ * \param config Configuration for this bridge.
+ *
  * Set start time, check for two channels,check if monitor on
  * check for feature activation, create new CDR
  * \retval res on success.
  * \retval -1 on failure to bridge.
  */
-int ast_bridge_call(struct ast_channel *chan,struct ast_channel *peer,struct ast_bridge_config *config)
+int ast_bridge_call(struct ast_channel *chan, struct ast_channel *peer, struct ast_bridge_config *config)
 {
 	/* Copy voice back and forth between the two channels.  Give the peer
 	   the ability to transfer calls with '#<extension' syntax. */
@@ -4324,8 +4328,8 @@
 		struct ao2_iterator iter;
 		struct ast_parkinglot *curlot;
 		int ms = -1;	/* poll2 timeout, uninitialized */
+
 		iter = ao2_iterator_init(parkinglots, 0);
-
 		while ((curlot = ao2_iterator_next(&iter))) {
 			manage_parkinglot(curlot, pfds, nfds, &new_pfds, &new_nfds, &ms);
 			ao2_ref(curlot, -1);
@@ -5022,8 +5026,9 @@
 			if ((sscanf(var->value, "%30d", &transferdigittimeout) != 1) || (transferdigittimeout < 1)) {
 				ast_log(LOG_WARNING, "%s is not a valid transferdigittimeout\n", var->value);
 				transferdigittimeout = DEFAULT_TRANSFER_DIGIT_TIMEOUT;
-			} else
+			} else {
 				transferdigittimeout = transferdigittimeout * 1000;
+			}
 		} else if (!strcasecmp(var->name, "featuredigittimeout")) {
 			if ((sscanf(var->value, "%30d", &featuredigittimeout) != 1) || (featuredigittimeout < 1)) {
 				ast_log(LOG_WARNING, "%s is not a valid featuredigittimeout\n", var->value);
@@ -5033,14 +5038,16 @@
 			if ((sscanf(var->value, "%30d", &atxfernoanswertimeout) != 1) || (atxfernoanswertimeout < 1)) {
 				ast_log(LOG_WARNING, "%s is not a valid atxfernoanswertimeout\n", var->value);
 				atxfernoanswertimeout = DEFAULT_NOANSWER_TIMEOUT_ATTENDED_TRANSFER;
-			} else
+			} else {
 				atxfernoanswertimeout = atxfernoanswertimeout * 1000;
+			}
 		} else if (!strcasecmp(var->name, "atxferloopdelay")) {
 			if ((sscanf(var->value, "%30u", &atxferloopdelay) != 1)) {
 				ast_log(LOG_WARNING, "%s is not a valid atxferloopdelay\n", var->value);
 				atxferloopdelay = DEFAULT_ATXFER_LOOP_DELAY;
-			} else 
+			} else {
 				atxferloopdelay *= 1000;
+			}
 		} else if (!strcasecmp(var->name, "atxferdropcall")) {
 			atxferdropcall = ast_true(var->value);
 		} else if (!strcasecmp(var->name, "atxfercallbackretries")) {
@@ -5051,12 +5058,13 @@
 		} else if (!strcasecmp(var->name, "courtesytone")) {
 			ast_copy_string(courtesytone, var->value, sizeof(courtesytone));
 		}  else if (!strcasecmp(var->name, "parkedplay")) {
-			if (!strcasecmp(var->value, "both"))
+			if (!strcasecmp(var->value, "both")) {
 				parkedplay = 2;
-			else if (!strcasecmp(var->value, "parked"))
+			} else if (!strcasecmp(var->value, "parked")) {
 				parkedplay = 1;
-			else
+			} else {
 				parkedplay = 0;
+			}
 		} else if (!strcasecmp(var->name, "xfersound")) {
 			ast_copy_string(xfersound, var->value, sizeof(xfersound));
 		} else if (!strcasecmp(var->name, "xferfailsound")) {
@@ -5076,11 +5084,12 @@
 
 	unmap_features();
 	for (var = ast_variable_browse(cfg, "featuremap"); var; var = var->next) {
-		if (remap_feature(var->name, var->value))
+		if (remap_feature(var->name, var->value)) {
 			ast_log(LOG_NOTICE, "Unknown feature '%s'\n", var->name);
-	}
-
-	/* Map a key combination to an application*/
+		}
+	}
+
+	/* Map a key combination to an application */
 	ast_unregister_features();
 	for (var = ast_variable_browse(cfg, "applicationmap"); var; var = var->next) {
 		char *tmp_val = ast_strdupa(var->value);
@@ -5180,23 +5189,27 @@
 		/* Is this a parkinglot definition ? */
 		if (!strncasecmp(ctg, "parkinglot_", strlen("parkinglot_"))) {
 			ast_debug(2, "Found configuration section %s, assume parking context\n", ctg);
-			if(!build_parkinglot(ctg, ast_variable_browse(cfg, ctg)))
+			if (!build_parkinglot(ctg, ast_variable_browse(cfg, ctg))) {
 				ast_log(LOG_ERROR, "Could not build parking lot %s. Configuration error.\n", ctg);
-			else
+			} else {
 				ast_debug(1, "Configured parking context %s\n", ctg);
+			}
 			continue;	
 		}
+
 		/* No, check if it's a group */
 		for (i = 0; i < ARRAY_LEN(categories); i++) {
-			if (!strcasecmp(categories[i], ctg))
+			if (!strcasecmp(categories[i], ctg)) {
 				break;
-		}
-
-		if (i < ARRAY_LEN(categories)) 
+			}
+		}
+		if (i < ARRAY_LEN(categories)) {
 			continue;
-
-		if (!(fg = register_group(ctg)))
+		}
+
+		if (!(fg = register_group(ctg))) {
 			continue;
+		}
 
 		for (var = ast_variable_browse(cfg, ctg); var; var = var->next) {
 			struct ast_call_feature *feature;
@@ -5937,18 +5950,20 @@
 	} else if ( (delta = config->play_warning - config->timelimit) > 0) {
 		int w = config->warning_freq;
 
-		/* If the first warning is requested _after_ the entire call would end,
-		   and no warning frequency is requested, then turn off the warning. If
-		   a warning frequency is requested, reduce the 'first warning' time by
-		   that frequency until it falls within the call's total time limit.
-		   Graphically:
-				  timelim->|    delta        |<-playwarning
-			0__________________|_________________|
-					 | w  |    |    |    |
-
-		   so the number of intervals to cut is 1+(delta-1)/w
-		*/
-
+		/*
+		 * If the first warning is requested _after_ the entire call
+		 * would end, and no warning frequency is requested, then turn
+		 * off the warning. If a warning frequency is requested, reduce
+		 * the 'first warning' time by that frequency until it falls
+		 * within the call's total time limit.
+		 *
+		 * Graphically:
+		 *                timelim->|    delta        |<-playwarning
+		 *      0__________________|_________________|
+		 *                       | w  |    |    |    |
+		 *
+		 * so the number of intervals to cut is 1+(delta-1)/w
+		 */
 		if (w == 0) {
 			config->play_warning = 0;
 		} else {
@@ -6205,9 +6220,9 @@
 	}
 
 	res |= ast_devstate_prov_add("Park", metermaidstate);
-#ifdef TEST_FRAMEWORK
+#if defined(TEST_FRAMEWORK)
 	res |= AST_TEST_REGISTER(features_test);
-#endif
+#endif	/* defined(TEST_FRAMEWORK) */
 
 	return res;
 }

Modified: branches/1.8/main/pbx.c
URL: http://svnview.digium.com/svn/asterisk/branches/1.8/main/pbx.c?view=diff&rev=331248&r1=331247&r2=331248
==============================================================================
--- branches/1.8/main/pbx.c (original)
+++ branches/1.8/main/pbx.c Tue Aug  9 17:12:59 2011
@@ -7010,12 +7010,17 @@
 	int length = sizeof(struct ast_context) + strlen(name) + 1;
 
 	if (!contexts_table) {
-		contexts_table = ast_hashtab_create(17,
-										   ast_hashtab_compare_contexts,
-										   ast_hashtab_resize_java,
-										   ast_hashtab_newsize_java,
-										   ast_hashtab_hash_contexts,
-										   0);
+		/* Protect creation of contexts_table from reentrancy. */
+		ast_wrlock_contexts();
+		if (!contexts_table) {
+			contexts_table = ast_hashtab_create(17,
+				ast_hashtab_compare_contexts,
+				ast_hashtab_resize_java,
+				ast_hashtab_newsize_java,
+				ast_hashtab_hash_contexts,
+				0);
+		}
+		ast_unlock_contexts();
 	}
 
 	ast_copy_string(search.name, name, sizeof(search.name));
@@ -7235,7 +7240,7 @@
 
 	begintime = ast_tvnow();
 	ast_mutex_lock(&context_merge_lock);/* Serialize ast_merge_contexts_and_delete */
-	ast_rdlock_contexts();
+	ast_wrlock_contexts();
 	iter = ast_hashtab_start_traversal(contexts_table);
 	while ((tmp = ast_hashtab_next(iter))) {
 		context_merge(extcontexts, exttable, tmp, registrar);




More information about the svn-commits mailing list