[svn-commits] rmudgett: branch group/bridge_construction r381178 - in /team/group/bridge_co...

SVN commits to the Digium repositories svn-commits at lists.digium.com
Mon Feb 11 12:06:41 CST 2013


Author: rmudgett
Date: Mon Feb 11 12:06:37 2013
New Revision: 381178

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=381178
Log:
features: Don't cache a struct ast_app pointer.

Caching a struct ast_app pointer is not a good idea because someone could
unload the application.  After the applicaiton unload the cached ast_app
pointer is no longer valid.  Only pbx.c can cache the pointer because it
knows when the application is unloaded and removes the pointer.

* Fixed one-touch Monitor and MixMonitor to not cache the ast_app pointer
and not use the silly monitor_ok/mixmonitor_ok/stopmixmonitor_ok flags.

* Extracted bridge_check_monitor() from ast_bridge_call() and use propper
locking.
........

Merged revisions 381177 from http://svn.asterisk.org/svn/asterisk/trunk

Modified:
    team/group/bridge_construction/   (props changed)
    team/group/bridge_construction/main/features.c

Propchange: team/group/bridge_construction/
------------------------------------------------------------------------------
--- bridge_construction-integrated (original)
+++ bridge_construction-integrated Mon Feb 11 12:06:37 2013
@@ -1,1 +1,1 @@
-/trunk:1-381161
+/trunk:1-381177

Modified: team/group/bridge_construction/main/features.c
URL: http://svnview.digium.com/svn/asterisk/team/group/bridge_construction/main/features.c?view=diff&rev=381178&r1=381177&r2=381178
==============================================================================
--- team/group/bridge_construction/main/features.c (original)
+++ team/group/bridge_construction/main/features.c Mon Feb 11 12:06:37 2013
@@ -783,15 +783,6 @@
 /* module and CLI command definitions */
 static const char *parkcall = "Park";
 
-static struct ast_app *monitor_app = NULL;
-static int monitor_ok = 1;
-
-static struct ast_app *mixmonitor_app = NULL;
-static int mixmonitor_ok = 1;
-
-static struct ast_app *stopmixmonitor_app = NULL;
-static int stopmixmonitor_ok = 1;
-
 static pthread_t parking_thread;
 struct ast_dial_features {
 	/*! Channel's feature flags. */
@@ -2287,14 +2278,10 @@
 	const char *touch_format = NULL;
 	const char *touch_monitor = NULL;
 	const char *touch_monitor_prefix = NULL;
-
-	if (!monitor_ok) {
-		ast_log(LOG_ERROR,"Cannot record the call. The monitor application is disabled.\n");
-		return -1;
-	}
-
-	if (!monitor_app && !(monitor_app = pbx_findapp("Monitor"))) {
-		monitor_ok = 0;
+	struct ast_app *monitor_app;
+
+	monitor_app = pbx_findapp("Monitor");
+	if (!monitor_app) {
 		ast_log(LOG_ERROR,"Cannot record the call. The monitor application is disabled.\n");
 		return -1;
 	}
@@ -2378,15 +2365,11 @@
 	const char *mixmonitor_spy_type = "MixMonitor";
 	const char *touch_format;
 	const char *touch_monitor;
+	struct ast_app *mixmonitor_app;
 	int count = 0;
 
-	if (!mixmonitor_ok) {
-		ast_log(LOG_ERROR,"Cannot record the call. The mixmonitor application is disabled.\n");
-		return -1;
-	}
-
-	if (!(mixmonitor_app = pbx_findapp("MixMonitor"))) {
-		mixmonitor_ok = 0;
+	mixmonitor_app = pbx_findapp("MixMonitor");
+	if (!mixmonitor_app) {
 		ast_log(LOG_ERROR,"Cannot record the call. The mixmonitor application is disabled.\n");
 		return -1;
 	}
@@ -2419,18 +2402,15 @@
 		count = ast_channel_audiohook_count_by_source_running(callee_chan, mixmonitor_spy_type, AST_AUDIOHOOK_TYPE_SPY);
 		ast_channel_unlock(callee_chan);
 		if (count > 0) {
-			if (!stopmixmonitor_ok) {
+			struct ast_app *stopmixmonitor_app;
+
+			stopmixmonitor_app = pbx_findapp("StopMixMonitor");
+			if (!stopmixmonitor_app) {
 				ast_log(LOG_ERROR,"Cannot stop recording the call. The stopmixmonitor application is disabled.\n");
 				return -1;
 			}
-			if (!(stopmixmonitor_app = pbx_findapp("StopMixMonitor"))) {
-				stopmixmonitor_ok = 0;
-				ast_log(LOG_ERROR,"Cannot stop recording the call. The stopmixmonitor application is disabled.\n");
-				return -1;
-			} else {
-				pbx_exec(callee_chan, stopmixmonitor_app, "");
-				return AST_FEATURE_RETURN_SUCCESS;
-			}
+			pbx_exec(callee_chan, stopmixmonitor_app, "");
+			return AST_FEATURE_RETURN_SUCCESS;
 		}
 
 		ast_log(LOG_WARNING,"Stopped MixMonitors are attached to the channel.\n");
@@ -4424,6 +4404,48 @@
 }
 
 /*!
+ * \internal
+ * \brief Check if Monitor needs to be started on a channel.
+ * \since 12.0.0
+ *
+ * \param chan The bridge considers this channel the caller.
+ * \param peer The bridge considers this channel the callee.
+ *
+ * \return Nothing
+ */
+static void bridge_check_monitor(struct ast_channel *chan, struct ast_channel *peer)
+{
+	const char *value;
+	const char *monitor_args = NULL;
+	struct ast_channel *monitor_chan = NULL;
+
+	ast_channel_lock(chan);
+	value = pbx_builtin_getvar_helper(chan, "AUTO_MONITOR");
+	if (!ast_strlen_zero(value)) {
+		monitor_args = ast_strdupa(value);
+		monitor_chan = chan;
+	}
+	ast_channel_unlock(chan);
+	if (!monitor_chan) {
+		ast_channel_lock(peer);
+		value = pbx_builtin_getvar_helper(peer, "AUTO_MONITOR");
+		if (!ast_strlen_zero(value)) {
+			monitor_args = ast_strdupa(value);
+			monitor_chan = peer;
+		}
+		ast_channel_unlock(peer);
+	}
+	if (monitor_chan) {
+		struct ast_app *monitor_app;
+
+		monitor_app = pbx_findapp("Monitor");
+		if (monitor_app) {
+			pbx_exec(monitor_chan, monitor_app, monitor_args);
+		}
+	}
+}
+
+/*!
  * \brief bridge the call and set CDR
  *
  * \param chan The bridge considers this channel the caller.
@@ -4476,22 +4498,7 @@
 		ast_indicate(peer, AST_CONTROL_RINGING);
 	}
 
-	if (monitor_ok) {
-		const char *monitor_exec;
-		struct ast_channel *src = NULL;
-		if (!monitor_app) {
-			if (!(monitor_app = pbx_findapp("Monitor")))
-				monitor_ok=0;
-		}
-		if ((monitor_exec = pbx_builtin_getvar_helper(chan, "AUTO_MONITOR")))
-			src = chan;
-		else if ((monitor_exec = pbx_builtin_getvar_helper(peer, "AUTO_MONITOR")))
-			src = peer;
-		if (monitor_app && src) {
-			char *tmp = ast_strdupa(monitor_exec);
-			pbx_exec(src, monitor_app, tmp);
-		}
-	}
+	bridge_check_monitor(chan, peer);
 
 	set_config_flags(chan, config);
 




More information about the svn-commits mailing list