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: 265453 $")
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
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083 static char *app = "SendDTMF";
00084
00085 static int senddtmf_exec(struct ast_channel *chan, const char *vdata)
00086 {
00087 int res = 0;
00088 char *data;
00089 int dinterval = 0, duration = 0;
00090 struct ast_channel *dchan;
00091 AST_DECLARE_APP_ARGS(args,
00092 AST_APP_ARG(digits);
00093 AST_APP_ARG(dinterval);
00094 AST_APP_ARG(duration);
00095 AST_APP_ARG(channel);
00096 );
00097
00098 if (ast_strlen_zero(vdata)) {
00099 ast_log(LOG_WARNING, "SendDTMF requires an argument (digits or *#aAbBcCdD)\n");
00100 return 0;
00101 }
00102
00103 dchan = chan;
00104
00105 data = ast_strdupa(vdata);
00106 AST_STANDARD_APP_ARGS(args, data);
00107
00108 if (!ast_strlen_zero(args.dinterval)) {
00109 ast_app_parse_timelen(args.dinterval, &dinterval, TIMELEN_MILLISECONDS);
00110 }
00111 if (!ast_strlen_zero(args.duration)) {
00112 ast_app_parse_timelen(args.duration, &duration, TIMELEN_MILLISECONDS);
00113 }
00114 if (!ast_strlen_zero(args.channel)) {
00115 dchan = ast_channel_get_by_name(args.channel);
00116 }
00117 if (dchan != chan) {
00118 ast_autoservice_start(chan);
00119 }
00120 res = ast_dtmf_stream(dchan, NULL, args.digits, dinterval <= 0 ? 250 : dinterval, duration);
00121 if (dchan != chan) {
00122 ast_autoservice_stop(chan);
00123 ast_channel_unref(dchan);
00124 }
00125
00126 return res;
00127 }
00128
00129 static int manager_play_dtmf(struct mansession *s, const struct message *m)
00130 {
00131 const char *channel = astman_get_header(m, "Channel");
00132 const char *digit = astman_get_header(m, "Digit");
00133 struct ast_channel *chan;
00134
00135 if (!(chan = ast_channel_get_by_name(channel))) {
00136 astman_send_error(s, m, "Channel not found");
00137 return 0;
00138 }
00139
00140 if (ast_strlen_zero(digit)) {
00141 astman_send_error(s, m, "No digit specified");
00142 chan = ast_channel_unref(chan);
00143 return 0;
00144 }
00145
00146 ast_senddigit(chan, *digit, 0);
00147
00148 chan = ast_channel_unref(chan);
00149
00150 astman_send_ack(s, m, "DTMF successfully queued");
00151
00152 return 0;
00153 }
00154
00155 static int unload_module(void)
00156 {
00157 int res;
00158
00159 res = ast_unregister_application(app);
00160 res |= ast_manager_unregister("PlayDTMF");
00161
00162 return res;
00163 }
00164
00165 static int load_module(void)
00166 {
00167 int res;
00168
00169 res = ast_manager_register_xml("PlayDTMF", EVENT_FLAG_CALL, manager_play_dtmf);
00170 res |= ast_register_application_xml(app, senddtmf_exec);
00171
00172 return res;
00173 }
00174
00175 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Send DTMF digits Application");