aboutsummaryrefslogtreecommitdiffstats
path: root/main/dial.c
diff options
context:
space:
mode:
authorrussell <russell@f38db490-d61c-443f-a65b-d21fe96a405b>2007-04-10 19:16:24 +0000
committerrussell <russell@f38db490-d61c-443f-a65b-d21fe96a405b>2007-04-10 19:16:24 +0000
commita54cf285d680065e14fd194fc9efc7f79f751b31 (patch)
tree8a672fb9b536c8a281410363e25a775963abbad4 /main/dial.c
parent391b59a48e3418549f812914150ad997d2f1c8a1 (diff)
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. git-svn-id: http://svn.digium.com/svn/asterisk/trunk@61259 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'main/dial.c')
-rw-r--r--main/dial.c38
1 files changed, 34 insertions, 4 deletions
diff --git a/main/dial.c b/main/dial.c
index 9536629e9..a3fcd9992 100644
--- a/main/dial.c
+++ b/main/dial.c
@@ -43,6 +43,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
#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 @@ static int answer_exec_disable(void *data)
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 @@ static const struct ast_option_types {
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 @@ static void handle_frame(struct ast_dial *dial, struct ast_dial_channel *channel
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 @@ static enum ast_dial_result monitor_dial(struct ast_dial *dial, struct ast_chann
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 @@ static enum ast_dial_result monitor_dial(struct ast_dial *dial, struct ast_chann
/* 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) {