[asterisk-commits] mmichelson: branch mmichelson/features_config r389933 - /team/mmichelson/feat...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Tue May 28 13:25:36 CDT 2013


Author: mmichelson
Date: Tue May 28 13:25:32 2013
New Revision: 389933

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=389933
Log:
Change features.c not to use global variables but instead use stored configuration.

This brought up a few items that needed to be addressed, which I will get to in the
next commits.


Modified:
    team/mmichelson/features_config/main/features.c

Modified: team/mmichelson/features_config/main/features.c
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/features_config/main/features.c?view=diff&rev=389933&r1=389932&r2=389933
==============================================================================
--- team/mmichelson/features_config/main/features.c (original)
+++ team/mmichelson/features_config/main/features.c Tue May 28 13:25:32 2013
@@ -396,12 +396,6 @@
 
 #define DEFAULT_PARK_TIME							45000	/*!< ms */
 #define DEFAULT_PARK_EXTENSION						"700"
-#define DEFAULT_TRANSFER_DIGIT_TIMEOUT				3000	/*!< ms */
-#define DEFAULT_FEATURE_DIGIT_TIMEOUT				1000	/*!< ms */
-#define DEFAULT_NOANSWER_TIMEOUT_ATTENDED_TRANSFER	15000	/*!< ms */
-#define DEFAULT_ATXFER_DROP_CALL					0		/*!< Do not drop call. */
-#define DEFAULT_ATXFER_LOOP_DELAY					10000	/*!< ms */
-#define DEFAULT_ATXFER_CALLBACK_RETRIES				2
 #define DEFAULT_COMEBACK_CONTEXT					"parkedcallstimeout"
 #define DEFAULT_COMEBACK_TO_ORIGIN					1
 #define DEFAULT_COMEBACK_DIAL_TIME					30
@@ -436,8 +430,6 @@
 } feature_interpret_op;
 
 static const char *parkedcall = "ParkedCall";
-
-static char pickup_ext[AST_MAX_EXTENSION];                 /*!< Call pickup extension */
 
 /*! Parking lot access ramp dialplan usage entry. */
 struct parking_dp_ramp {
@@ -612,10 +604,6 @@
 static int parkedplay = 0;                                 /*!< Who to play courtesytone to when someone picks up a parked call. */
 static int parkeddynamic = 0;                              /*!< Enable creation of parkinglots dynamically */
 static char courtesytone[256];                             /*!< Courtesy tone used to pickup parked calls and on-touch-record */
-static char xfersound[256];                                /*!< Call transfer sound */
-static char xferfailsound[256];                            /*!< Call transfer failure sound */
-static char pickupsound[256];                              /*!< Pickup sound */
-static char pickupfailsound[256];                          /*!< Pickup failure sound */
 
 /*!
  * \brief Context for parking dialback to parker.
@@ -631,14 +619,6 @@
 AST_MUTEX_DEFINE_STATIC(features_reload_lock);
 
 static int adsipark;
-
-static int transferdigittimeout;
-static int featuredigittimeout;
-
-static int atxfernoanswertimeout;
-static unsigned int atxferdropcall;
-static unsigned int atxferloopdelay;
-static unsigned int atxfercallbackretries;
 
 static char *registrar = "features";		   /*!< Registrar for operations */
 
@@ -851,7 +831,8 @@
 
 const char *ast_pickup_ext(void)
 {
-	return pickup_ext;
+	/* XXX Heh, this is WAY wrong */
+	return "";
 }
 
 struct ast_bridge_thread_obj
@@ -2348,6 +2329,7 @@
 	const char *transferer_real_context;
 	char xferto[256] = "";
 	int res;
+	RAII_VAR(struct ast_features_xfer_config *, xfer_cfg, NULL, ao2_cleanup);
 
 	ast_debug(1, "Executing Blind Transfer %s, %s (sense=%d) \n", ast_channel_name(chan), ast_channel_name(peer), sense);
 	set_peers(&transferer, &transferee, peer, chan, sense);
@@ -2367,7 +2349,11 @@
 		xferto[0] = (char) res;
 	}
 
-	res = ast_app_dtget(transferer, transferer_real_context, xferto, sizeof(xferto), 100, transferdigittimeout);
+	ast_channel_lock(transferer);
+	xfer_cfg = ast_get_chan_features_xfer_config(transferer);
+	ast_channel_unlock(transferer);
+
+	res = ast_app_dtget(transferer, transferer_real_context, xferto, sizeof(xferto), 100, xfer_cfg->transferdigittimeout);
 	if (res < 0) {  /* hangup or error, (would be 0 for invalid and 1 for valid) */
 		finishup(transferee);
 		return -1;
@@ -2523,6 +2509,7 @@
 	char *transferer_name;
 	char *transferer_name_orig;
 	char *dash;
+	RAII_VAR(struct ast_features_xfer_config *, xfer_cfg, NULL, ao2_cleanup);
 
 	ast_debug(1, "Executing Attended Transfer %s, %s (sense=%d) \n", ast_channel_name(chan), ast_channel_name(peer), sense);
 	set_peers(&transferer, &transferee, peer, chan, sense);
@@ -2542,8 +2529,12 @@
 		xferto[0] = (char) res;
 	}
 
+	ast_channel_lock(transferer);
+	xfer_cfg = ast_get_chan_features_xfer_config(transferer);
+	ast_channel_unlock(transferer);
+
 	/* this is specific of atxfer */
-	res = ast_app_dtget(transferer, transferer_real_context, xferto, sizeof(xferto), 100, transferdigittimeout);
+	res = ast_app_dtget(transferer, transferer_real_context, xferto, sizeof(xferto), 100, xfer_cfg->transferdigittimeout);
 	if (res < 0) {  /* hangup or error, (would be 0 for invalid and 1 for valid) */
 		finishup(transferee);
 		return -1;
@@ -2614,7 +2605,7 @@
 	/* Dial party C */
 	newchan = feature_request_and_dial(transferer, transferer_name_orig, transferer,
 		transferee, "Local", ast_channel_nativeformats(transferer), xferto,
-		atxfernoanswertimeout, &outstate, ast_channel_language(transferer));
+		xfer_cfg->atxfernoanswertimeout, &outstate, ast_channel_language(transferer));
 	ast_debug(2, "Dial party C result: newchan:%d, outstate:%d\n", !!newchan, outstate);
 
 	if (!ast_check_hangup(transferer)) {
@@ -2631,12 +2622,12 @@
 			case AST_CONTROL_UNHOLD:/* Caller requested cancel or party C answer timeout. */
 			case AST_CONTROL_BUSY:
 			case AST_CONTROL_CONGESTION:
-				if (ast_stream_and_wait(transferer, xfersound, "")) {
+				if (ast_stream_and_wait(transferer, xfer_cfg->xfersound, "")) {
 					ast_log(LOG_WARNING, "Failed to play transfer sound!\n");
 				}
 				break;
 			default:
-				if (ast_stream_and_wait(transferer, xferfailsound, "")) {
+				if (ast_stream_and_wait(transferer, xfer_cfg->xferfailsound, "")) {
 					ast_log(LOG_WARNING, "Failed to play transfer failed sound!\n");
 				}
 				break;
@@ -2646,7 +2637,7 @@
 		}
 
 		if (check_compat(transferer, newchan)) {
-			if (ast_stream_and_wait(transferer, xferfailsound, "")) {
+			if (ast_stream_and_wait(transferer, xfer_cfg->xferfailsound, "")) {
 				ast_log(LOG_WARNING, "Failed to play transfer failed sound!\n");
 			}
 			atxfer_fail_cleanup(transferee, transferer, &connected_line);
@@ -2664,7 +2655,7 @@
 
 		if (ast_check_hangup(newchan) || !ast_check_hangup(transferer)) {
 			ast_autoservice_chan_hangup_peer(transferer, newchan);
-			if (ast_stream_and_wait(transferer, xfersound, "")) {
+			if (ast_stream_and_wait(transferer, xfer_cfg->xfersound, "")) {
 				ast_log(LOG_WARNING, "Failed to play transfer sound!\n");
 			}
 			atxfer_fail_cleanup(transferee, transferer, &connected_line);
@@ -2692,7 +2683,7 @@
 		/* Transferer (party B) has hung up at this point.  Doing blonde transfer. */
 		ast_debug(1, "Actually doing a blonde transfer.\n");
 
-		if (!newchan && !atxferdropcall) {
+		if (!newchan && !xfer_cfg->atxferdropcall) {
 			/* Party C is not available, try to call party B back. */
 			unsigned int tries = 0;
 
@@ -2713,7 +2704,7 @@
 				newchan = feature_request_and_dial(transferer, transferer_name_orig,
 					transferee, transferee, transferer_tech,
 					ast_channel_nativeformats(transferee), transferer_name,
-					atxfernoanswertimeout, &outstate, ast_channel_language(transferer));
+					xfer_cfg->atxfernoanswertimeout, &outstate, ast_channel_language(transferer));
 				ast_debug(2, "Dial party B result: newchan:%d, outstate:%d\n",
 					!!newchan, outstate);
 				if (newchan) {
@@ -2745,16 +2736,16 @@
 				}
 
 				++tries;
-				if (atxfercallbackretries <= tries) {
+				if (xfer_cfg->atxfercallbackretries <= tries) {
 					/* No more callback tries remaining. */
 					break;
 				}
 
-				if (atxferloopdelay) {
+				if (xfer_cfg->atxferloopdelay) {
 					/* Transfer failed, sleeping */
 					ast_debug(1, "Sleeping for %d ms before retrying atxfer.\n",
-						atxferloopdelay);
-					ast_safe_sleep(transferee, atxferloopdelay);
+						xfer_cfg->atxferloopdelay);
+					ast_safe_sleep(transferee, xfer_cfg->atxferloopdelay);
 					if (ast_check_hangup(transferee)) {
 						ast_party_connected_line_free(&connected_line);
 						return -1;
@@ -2766,7 +2757,7 @@
 				newchan = feature_request_and_dial(transferer, transferer_name_orig,
 					transferer, transferee, "Local",
 					ast_channel_nativeformats(transferee), xferto,
-					atxfernoanswertimeout, &outstate, ast_channel_language(transferer));
+					xfer_cfg->atxfernoanswertimeout, &outstate, ast_channel_language(transferer));
 				ast_debug(2, "Redial party C result: newchan:%d, outstate:%d\n",
 					!!newchan, outstate);
 				if (newchan || ast_check_hangup(transferee)) {
@@ -2927,7 +2918,7 @@
 		ast_channel_update_connected_line(newchan, &connected_line, NULL);
 	}
 
-	if (ast_stream_and_wait(newchan, xfersound, ""))
+	if (ast_stream_and_wait(newchan, xfer_cfg->xfersound, ""))
 		ast_log(LOG_WARNING, "Failed to play transfer sound!\n");
 	bridge_call_thread_launch(tobj);
 
@@ -5419,23 +5410,6 @@
 		"applicationmap"
 	};
 
-	/* Set general features global defaults. */
-	featuredigittimeout = DEFAULT_FEATURE_DIGIT_TIMEOUT;
-
-	/* Set global call pickup defaults. */
-	strcpy(pickup_ext, "*8");
-	pickupsound[0] = '\0';
-	pickupfailsound[0] = '\0';
-
-	/* Set global call transfer defaults. */
-	strcpy(xfersound, "beep");
-	strcpy(xferfailsound, "beeperr");
-	transferdigittimeout = DEFAULT_TRANSFER_DIGIT_TIMEOUT;
-	atxfernoanswertimeout = DEFAULT_NOANSWER_TIMEOUT_ATTENDED_TRANSFER;
-	atxferloopdelay = DEFAULT_ATXFER_LOOP_DELAY;
-	atxferdropcall = DEFAULT_ATXFER_DROP_CALL;
-	atxfercallbackretries = DEFAULT_ATXFER_CALLBACK_RETRIES;
-
 	/* Set global call parking defaults. */
 	courtesytone[0] = '\0';
 	parkedplay = 0;
@@ -5449,39 +5423,6 @@
 			parkeddynamic = ast_true(var->value);
 		} else if (!strcasecmp(var->name, "adsipark")) {
 			adsipark = ast_true(var->value);
-		} else if (!strcasecmp(var->name, "transferdigittimeout")) {
-			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 {
-				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);
-				featuredigittimeout = DEFAULT_FEATURE_DIGIT_TIMEOUT;
-			}
-		} else if (!strcasecmp(var->name, "atxfernoanswertimeout")) {
-			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 {
-				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 {
-				atxferloopdelay *= 1000;
-			}
-		} else if (!strcasecmp(var->name, "atxferdropcall")) {
-			atxferdropcall = ast_true(var->value);
-		} else if (!strcasecmp(var->name, "atxfercallbackretries")) {
-			if ((sscanf(var->value, "%30u", &atxfercallbackretries) != 1)) {
-				ast_log(LOG_WARNING, "%s is not a valid atxfercallbackretries\n", var->value);
-				atxfercallbackretries = DEFAULT_ATXFER_CALLBACK_RETRIES;
-			}
 		} else if (!strcasecmp(var->name, "courtesytone")) {
 			ast_copy_string(courtesytone, var->value, sizeof(courtesytone));
 		}  else if (!strcasecmp(var->name, "parkedplay")) {
@@ -5492,16 +5433,6 @@
 			} else {
 				parkedplay = 0;
 			}
-		} else if (!strcasecmp(var->name, "xfersound")) {
-			ast_copy_string(xfersound, var->value, sizeof(xfersound));
-		} else if (!strcasecmp(var->name, "xferfailsound")) {
-			ast_copy_string(xferfailsound, var->value, sizeof(xferfailsound));
-		} else if (!strcasecmp(var->name, "pickupexten")) {
-			ast_copy_string(pickup_ext, var->value, sizeof(pickup_ext));
-		} else if (!strcasecmp(var->name, "pickupsound")) {
-			ast_copy_string(pickupsound, var->value, sizeof(pickupsound));
-		} else if (!strcasecmp(var->name, "pickupfailsound")) {
-			ast_copy_string(pickupfailsound, var->value, sizeof(pickupfailsound));
 		}
 	}
 
@@ -6467,10 +6398,12 @@
 		struct ast_bridge_features *features, int play_tone)
 {
 	RAII_VAR(struct ast_bridge *, chan_bridge, NULL, ao2_cleanup);
+	RAII_VAR(struct ast_features_xfer_config *, xfer_cfg, NULL, ao2_cleanup);
 	struct ast_channel *bridge_chan = NULL;
 
 	ast_channel_lock(chan);
 	chan_bridge = ast_channel_get_bridge(chan);
+	xfer_cfg = ast_get_chan_features_xfer_config(chan);
 	ast_channel_unlock(chan);
 
 	if (chan_bridge) {
@@ -6495,7 +6428,7 @@
 		}
 	}
 
-	if (play_tone && !ast_strlen_zero(xfersound)) {
+	if (play_tone && !ast_strlen_zero(xfer_cfg->xfersound)) {
 		struct ast_channel *play_chan = bridge_chan ?: chan;
 		RAII_VAR(struct ast_bridge_channel *, play_bridge_channel, NULL, ao2_cleanup);
 
@@ -6507,7 +6440,7 @@
 			ast_log(LOG_WARNING, "Unable to play tone for channel %s. Unable to get bridge channel\n",
 					ast_channel_name(play_chan));
 		} else {
-			ast_bridge_channel_queue_playfile(play_bridge_channel, NULL, xfersound, NULL);
+			ast_bridge_channel_queue_playfile(play_bridge_channel, NULL, xfer_cfg->xfersound, NULL);
 		}
 	}
 	return 0;
@@ -6897,13 +6830,14 @@
 	/* The found channel is already locked. */
 	target = ast_pickup_find_by_group(chan);
 	if (target) {
+		RAII_VAR(struct ast_features_pickup_config *, pickup_cfg, ast_get_chan_features_pickup_config(target), ao2_cleanup);
 		ast_log(LOG_NOTICE, "pickup %s attempt by %s\n", ast_channel_name(target), ast_channel_name(chan));
 
 		res = ast_do_pickup(chan, target);
 		ast_channel_unlock(target);
 		if (!res) {
-			if (!ast_strlen_zero(pickupsound)) {
-				pbx_builtin_setvar_helper(target, "BRIDGE_PLAY_SOUND", pickupsound);
+			if (!ast_strlen_zero(pickup_cfg->pickupsound)) {
+				pbx_builtin_setvar_helper(target, "BRIDGE_PLAY_SOUND", pickup_cfg->pickupsound);
 			}
 		} else {
 			ast_log(LOG_WARNING, "pickup %s failed by %s\n", ast_channel_name(target), ast_channel_name(chan));
@@ -6912,10 +6846,16 @@
 	}
 
 	if (res < 0) {
+		RAII_VAR(struct ast_features_pickup_config *, pickup_cfg, NULL, ao2_cleanup);
+
+		ast_channel_lock(chan);
+		pickup_cfg = ast_get_chan_features_pickup_config(chan);
+		ast_channel_unlock(chan);
+
 		ast_debug(1, "No call pickup possible... for %s\n", ast_channel_name(chan));
-		if (!ast_strlen_zero(pickupfailsound)) {
+		if (!ast_strlen_zero(pickup_cfg->pickupfailsound)) {
 			ast_answer(chan);
-			ast_stream_and_wait(chan, pickupfailsound, "");
+			ast_stream_and_wait(chan, pickup_cfg->pickupfailsound, "");
 		}
 	}
 




More information about the asterisk-commits mailing list