[asterisk-commits] mmichelson: branch mmichelson/queue_bugbug r394488 - /team/mmichelson/queue_b...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Tue Jul 16 14:27:24 CDT 2013
Author: mmichelson
Date: Tue Jul 16 14:27:22 2013
New Revision: 394488
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=394488
Log:
Refactor mixmonitor setup on queues.
The BUGBUG comment suggested monitoring the bridge instead of setting up
a mixmonitor on the calling channel. For now anyway, I have not done this.
However, having mixmonitor setup as a single routine makes it much simpler
to do this if desired. However, I think it's debatable whether we actually
want to be monitoring the bridge instead of the caller.
In addition to the refactoring, I actually fixed a bug. The
MONITOR_EXEC channel variable went through its escaping and variable
substitution routine, but the unescaped variable name was being passed
to the MixMonitor application rather than the escaped name. I did not
find any open issues pertaining to this.
Modified:
team/mmichelson/queue_bugbug/apps/app_queue.c
Modified: team/mmichelson/queue_bugbug/apps/app_queue.c
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/queue_bugbug/apps/app_queue.c?view=diff&rev=394488&r1=394487&r2=394488
==============================================================================
--- team/mmichelson/queue_bugbug/apps/app_queue.c (original)
+++ team/mmichelson/queue_bugbug/apps/app_queue.c Tue Jul 16 14:27:22 2013
@@ -112,6 +112,7 @@
#include "asterisk/bridging.h"
#include "asterisk/stasis_bridging.h"
#include "asterisk/core_local.h"
+#include "asterisk/mixmonitor.h"
/* Define, to debug reference counts on queues, without debugging reference counts on queue members */
/* #define REF_DEBUG_ONLY_QUEUES */
@@ -5172,6 +5173,8 @@
{
struct queue_stasis_data *queue_data = obj;
+ ast_log(LOG_NOTICE, "Things bein' destroyed\n");
+
ao2_cleanup(queue_data->member);
ast_string_field_free_memory(queue_data);
}
@@ -5409,6 +5412,82 @@
ast_channel_unlock(chan);
ast_after_bridge_set_go_on(peer, context, extension, priority,
opt_args[OPT_ARG_CALLEE_GO_ON]);
+ }
+}
+
+static void escape_and_substitute(struct ast_channel *chan, const char *input,
+ char *output, size_t size)
+{
+ const char *m = input;
+ char escaped[size];
+ char *p;
+
+ for (p = escaped; p < escaped + size - 1; p++, m++) {
+ switch (*m) {
+ case '^':
+ if (*(m + 1) == '{') {
+ *p = '$';
+ }
+ break;
+ case ',':
+ *p++ = '\\';
+ /* Fall through */
+ default:
+ *p = *m;
+ }
+ if (*m == '\0')
+ break;
+ }
+
+ if (p == escaped + size) {
+ escaped[size - 1] = '\0';
+ }
+
+ pbx_substitute_variables_helper(chan, escaped, output, size - 1);
+}
+
+static void setup_mixmonitor(struct queue_ent *qe, const char *filename)
+{
+ char escaped_filename[256];
+ char file_with_ext[256];
+ char mixmonargs[1512];
+ char escaped_monitor_exec[1024];
+ const char *monitor_options;
+ const char *monitor_exec;
+
+ if (filename) {
+ escape_and_substitute(qe->chan, filename, escaped_filename, sizeof(escaped_filename));
+ } else {
+ ast_copy_string(escaped_filename, ast_channel_uniqueid(qe->chan), sizeof(escaped_filename));
+ }
+
+ ast_channel_lock(qe->chan);
+ if ((monitor_exec = pbx_builtin_getvar_helper(qe->chan, "MONITOR_EXEC"))) {
+ monitor_exec = ast_strdupa(monitor_exec);
+ }
+ if ((monitor_options = pbx_builtin_getvar_helper(qe->chan, "MONITOR_OPTIONS"))) {
+ monitor_options = ast_strdupa(monitor_options);
+ } else {
+ monitor_options = "";
+ }
+ ast_channel_unlock(qe->chan);
+
+ if (monitor_exec) {
+ escape_and_substitute(qe->chan, monitor_exec, escaped_monitor_exec, sizeof(escaped_monitor_exec));
+ }
+
+ snprintf(file_with_ext, sizeof(file_with_ext), "%s.%s", escaped_filename, qe->parent->monfmt);
+
+ if (!ast_strlen_zero(escaped_monitor_exec)) {
+ snprintf(mixmonargs, sizeof(mixmonargs), "b%s,%s", monitor_options, escaped_monitor_exec);
+ } else {
+ snprintf(mixmonargs, sizeof(mixmonargs), "b%s", monitor_options);
+ }
+
+ ast_debug(1, "Arguments being passed to MixMonitor: %s,%s\n", file_with_ext, mixmonargs);
+
+ if (ast_start_mixmonitor(qe->chan, file_with_ext, mixmonargs)) {
+ ast_log(LOG_WARNING, "Unable to start mixmonitor. Is the MixMonitor app loaded?\n");
}
}
@@ -5469,13 +5548,8 @@
char *macroexec = NULL;
char *gosubexec = NULL;
const char *monitorfilename;
- const char *monitor_exec;
- const char *monitor_options;
- char tmpid[256], tmpid2[256];
- char meid[1024], meid2[1024];
- char mixmonargs[1512];
- struct ast_app *mixmonapp = NULL;
- char *p;
+ char tmpid[256];
+ char meid[1024];
int forwardsallowed = 1;
int block_connected_line = 0;
int callcompletedinsl;
@@ -5901,96 +5975,7 @@
ast_monitor_setjoinfiles(which, 1);
}
} else {
- mixmonapp = pbx_findapp("MixMonitor");
-
- if (mixmonapp) {
- ast_debug(1, "Starting MixMonitor as requested.\n");
- if (!monitorfilename) {
- if (qe->chan) {
- ast_copy_string(tmpid, ast_channel_uniqueid(qe->chan), sizeof(tmpid));
- } else {
- snprintf(tmpid, sizeof(tmpid), "chan-%lx", ast_random());
- }
- } else {
- const char *m = monitorfilename;
- for (p = tmpid2; p < tmpid2 + sizeof(tmpid2) - 1; p++, m++) {
- switch (*m) {
- case '^':
- if (*(m + 1) == '{')
- *p = '$';
- break;
- case ',':
- *p++ = '\\';
- /* Fall through */
- default:
- *p = *m;
- }
- if (*m == '\0')
- break;
- }
- if (p == tmpid2 + sizeof(tmpid2))
- tmpid2[sizeof(tmpid2) - 1] = '\0';
-
- pbx_substitute_variables_helper(qe->chan, tmpid2, tmpid, sizeof(tmpid) - 1);
- }
-
- ast_channel_lock(qe->chan);
- if ((monitor_exec = pbx_builtin_getvar_helper(qe->chan, "MONITOR_EXEC"))) {
- monitor_exec = ast_strdupa(monitor_exec);
- }
- if ((monitor_options = pbx_builtin_getvar_helper(qe->chan, "MONITOR_OPTIONS"))) {
- monitor_options = ast_strdupa(monitor_options);
- } else {
- monitor_options = "";
- }
- ast_channel_unlock(qe->chan);
-
- if (monitor_exec) {
- const char *m = monitor_exec;
- for (p = meid2; p < meid2 + sizeof(meid2) - 1; p++, m++) {
- switch (*m) {
- case '^':
- if (*(m + 1) == '{')
- *p = '$';
- break;
- case ',':
- *p++ = '\\';
- /* Fall through */
- default:
- *p = *m;
- }
- if (*m == '\0') {
- break;
- }
- }
- if (p == meid2 + sizeof(meid2)) {
- meid2[sizeof(meid2) - 1] = '\0';
- }
-
- pbx_substitute_variables_helper(qe->chan, meid2, meid, sizeof(meid) - 1);
- }
-
- snprintf(tmpid2, sizeof(tmpid2), "%s.%s", tmpid, qe->parent->monfmt);
-
- if (!ast_strlen_zero(monitor_exec)) {
- snprintf(mixmonargs, sizeof(mixmonargs), "%s,b%s,%s", tmpid2, monitor_options, monitor_exec);
- } else {
- snprintf(mixmonargs, sizeof(mixmonargs), "%s,b%s", tmpid2, monitor_options);
- }
-
- ast_debug(1, "Arguments being passed to MixMonitor: %s\n", mixmonargs);
- /* BUGBUG
- * This needs to be done differently. We need to start a MixMonitor on
- * the actual queue bridge itself, not drop some channel out and pull it
- * back. Once the media channel work is done, start a media channel on
- * the bridge.
- *
- * Alternatively, don't use pbx_exec to put an audio hook on a channel.
- */
- pbx_exec(qe->chan, mixmonapp, mixmonargs);
- } else {
- ast_log(LOG_WARNING, "Asked to run MixMonitor on this call, but cannot find the MixMonitor app!\n");
- }
+ setup_mixmonitor(qe, monitorfilename);
}
}
/* Drop out of the queue at this point, to prepare for next caller */
More information about the asterisk-commits
mailing list