app_senddtmf.c
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #include "asterisk.h"
00029
00030 ASTERISK_FILE_VERSION(__FILE__, "$Revision: 184081 $")
00031
00032 #include "asterisk/pbx.h"
00033 #include "asterisk/module.h"
00034 #include "asterisk/app.h"
00035 #include "asterisk/manager.h"
00036 #include "asterisk/channel.h"
00037
00038 static char *app = "SendDTMF";
00039
00040 static char *synopsis = "Sends arbitrary DTMF digits";
00041
00042 static char *descrip =
00043 " SendDTMF(digits[,[timeout_ms][,duration_ms]]): Sends DTMF digits on a channel. \n"
00044 " Accepted digits: 0-9, *#abcd, (default .25s pause between digits)\n"
00045 " The application will either pass the assigned digits or terminate if it\n"
00046 " encounters an error.\n"
00047 " Optional Params: \n"
00048 " timeout_ms: pause between digits.\n"
00049 " duration_ms: duration of each digit.\n";
00050
00051 static int senddtmf_exec(struct ast_channel *chan, void *vdata)
00052 {
00053 int res = 0;
00054 char *data;
00055 int timeout = 0, duration = 0;
00056 AST_DECLARE_APP_ARGS(args,
00057 AST_APP_ARG(digits);
00058 AST_APP_ARG(timeout);
00059 AST_APP_ARG(duration);
00060 );
00061
00062 if (ast_strlen_zero(vdata)) {
00063 ast_log(LOG_WARNING, "SendDTMF requires an argument (digits or *#aAbBcCdD)\n");
00064 return 0;
00065 }
00066
00067 data = ast_strdupa(vdata);
00068 AST_STANDARD_APP_ARGS(args, data);
00069
00070 if (!ast_strlen_zero(args.timeout))
00071 timeout = atoi(args.timeout);
00072 if (!ast_strlen_zero(args.duration))
00073 duration = atoi(args.duration);
00074 res = ast_dtmf_stream(chan, NULL, args.digits, timeout <= 0 ? 250 : timeout, duration);
00075
00076 return res;
00077 }
00078
00079 static char mandescr_playdtmf[] =
00080 "Description: Plays a dtmf digit on the specified channel.\n"
00081 "Variables: (all are required)\n"
00082 " Channel: Channel name to send digit to\n"
00083 " Digit: The dtmf digit to play\n";
00084
00085 static int manager_play_dtmf(struct mansession *s, const struct message *m)
00086 {
00087 const char *channel = astman_get_header(m, "Channel");
00088 const char *digit = astman_get_header(m, "Digit");
00089 struct ast_channel *chan = ast_get_channel_by_name_locked(channel);
00090
00091 if (!chan) {
00092 astman_send_error(s, m, "Channel not specified");
00093 return 0;
00094 }
00095 if (ast_strlen_zero(digit)) {
00096 astman_send_error(s, m, "No digit specified");
00097 ast_channel_unlock(chan);
00098 return 0;
00099 }
00100
00101 ast_senddigit(chan, *digit, 0);
00102
00103 ast_channel_unlock(chan);
00104 astman_send_ack(s, m, "DTMF successfully queued");
00105
00106 return 0;
00107 }
00108
00109 static int unload_module(void)
00110 {
00111 int res;
00112
00113 res = ast_unregister_application(app);
00114 res |= ast_manager_unregister("PlayDTMF");
00115
00116 return res;
00117 }
00118
00119 static int load_module(void)
00120 {
00121 int res;
00122
00123 res = ast_manager_register2( "PlayDTMF", EVENT_FLAG_CALL, manager_play_dtmf, "Play DTMF signal on a specific channel.", mandescr_playdtmf );
00124 res |= ast_register_application(app, senddtmf_exec, synopsis, descrip);
00125
00126 return res;
00127 }
00128
00129 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Send DTMF digits Application");