[asterisk-commits] russell: trunk r61259 - in /trunk:
include/asterisk/dial.h main/dial.c
asterisk-commits at lists.digium.com
asterisk-commits at lists.digium.com
Tue Apr 10 12:16:25 MST 2007
Author: russell
Date: Tue Apr 10 14:16:24 2007
New Revision: 61259
URL: http://svn.digium.com/view/asterisk?view=rev&rev=61259
Log:
Add an option to the dial API for playing music instead of ringing to the caller.
I started this for use with SLA but ended up deciding not to use it. However,
there is no reason not to put this part in, anyway.
Modified:
trunk/include/asterisk/dial.h
trunk/main/dial.c
Modified: trunk/include/asterisk/dial.h
URL: http://svn.digium.com/view/asterisk/trunk/include/asterisk/dial.h?view=diff&rev=61259&r1=61258&r2=61259
==============================================================================
--- trunk/include/asterisk/dial.h (original)
+++ trunk/include/asterisk/dial.h Tue Apr 10 14:16:24 2007
@@ -39,6 +39,7 @@
enum ast_dial_option {
AST_DIAL_OPTION_RINGING, /*!< Always indicate ringing to caller */
AST_DIAL_OPTION_ANSWER_EXEC, /*!< Execute application upon answer in async mode */
+ AST_DIAL_OPTION_MUSIC, /*!< Play music on hold instead of ringing to the calling channel */
AST_DIAL_OPTION_MAX, /*!< End terminator -- must always remain last */
};
Modified: trunk/main/dial.c
URL: http://svn.digium.com/view/asterisk/trunk/main/dial.c?view=diff&rev=61259&r1=61258&r2=61259
==============================================================================
--- trunk/main/dial.c (original)
+++ trunk/main/dial.c Tue Apr 10 14:16:24 2007
@@ -43,6 +43,7 @@
#include "asterisk/linkedlists.h"
#include "asterisk/dial.h"
#include "asterisk/pbx.h"
+#include "asterisk/musiconhold.h"
/*! \brief Main dialing structure. Contains global options, channels being dialed, and more! */
struct ast_dial {
@@ -122,6 +123,21 @@
return 0;
}
+static void *music_enable(void *data)
+{
+ return ast_strdup(data);
+}
+
+static int music_disable(void *data)
+{
+ if (!data)
+ return -1;
+
+ free(data);
+
+ return 0;
+}
+
/* Application execution function for 'ANSWER_EXEC' option */
static void answer_exec_run(struct ast_channel *chan, char *app, char *args)
{
@@ -143,9 +159,10 @@
ast_dial_option_cb_enable enable;
ast_dial_option_cb_disable disable;
} option_types[] = {
- { AST_DIAL_OPTION_RINGING, NULL, NULL }, /*! Always indicate ringing to caller */
- { AST_DIAL_OPTION_ANSWER_EXEC, answer_exec_enable, answer_exec_disable }, /*! Execute application upon answer in async mode */
- { AST_DIAL_OPTION_MAX, NULL, NULL }, /*! Terminator of list */
+ { AST_DIAL_OPTION_RINGING, NULL, NULL }, /*!< Always indicate ringing to caller */
+ { AST_DIAL_OPTION_ANSWER_EXEC, answer_exec_enable, answer_exec_disable }, /*!< Execute application upon answer in async mode */
+ { AST_DIAL_OPTION_MUSIC, music_enable, music_disable }, /*!< Play music to the caller instead of ringing */
+ { AST_DIAL_OPTION_MAX, NULL, NULL }, /*!< Terminator of list */
};
/* free the buffer if allocated, and set the pointer to the second arg */
@@ -324,7 +341,8 @@
case AST_CONTROL_RINGING:
if (option_verbose > 2)
ast_verbose(VERBOSE_PREFIX_3 "%s is ringing\n", channel->owner->name);
- ast_indicate(chan, AST_CONTROL_RINGING);
+ if (!dial->options[AST_DIAL_OPTION_MUSIC])
+ ast_indicate(chan, AST_CONTROL_RINGING);
break;
case AST_CONTROL_PROGRESS:
if (option_verbose > 2)
@@ -430,6 +448,13 @@
set_state(dial, AST_DIAL_RESULT_RINGING);
if (chan)
ast_indicate(chan, AST_CONTROL_RINGING);
+ } else if (chan && dial->options[AST_DIAL_OPTION_MUSIC] &&
+ !ast_strlen_zero(dial->options[AST_DIAL_OPTION_MUSIC])) {
+ char *original_moh = ast_strdupa(chan->musicclass);
+ ast_indicate(chan, -1);
+ ast_string_field_set(chan, musicclass, dial->options[AST_DIAL_OPTION_MUSIC]);
+ ast_moh_start(chan, dial->options[AST_DIAL_OPTION_MUSIC], NULL);
+ ast_string_field_set(chan, musicclass, original_moh);
}
/* Go into an infinite loop while we are trying */
@@ -509,6 +534,11 @@
/* If ANSWER_EXEC is enabled as an option, execute application on answered channel */
if ((channel = find_relative_dial_channel(dial, who)) && (answer_exec = FIND_RELATIVE_OPTION(dial, channel, AST_DIAL_OPTION_ANSWER_EXEC)))
answer_exec_run(who, answer_exec->app, answer_exec->args);
+
+ if (chan && dial->options[AST_DIAL_OPTION_MUSIC] &&
+ !ast_strlen_zero(dial->options[AST_DIAL_OPTION_MUSIC])) {
+ ast_moh_stop(chan);
+ }
} else if (dial->state == AST_DIAL_RESULT_HANGUP) {
/* Hangup everything */
AST_LIST_TRAVERSE(&dial->channels, channel, list) {
More information about the asterisk-commits
mailing list