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
00029
00030
00031
00032 #include "asterisk.h"
00033
00034 ASTERISK_FILE_VERSION(__FILE__, "$Revision: 328209 $")
00035
00036 #include "asterisk/pbx.h"
00037 #include "asterisk/module.h"
00038 #include "asterisk/app.h"
00039 #include "asterisk/manager.h"
00040 #include "asterisk/channel.h"
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
00084
00085
00086
00087 static char *app = "SendDTMF";
00088
00089 static int senddtmf_exec(struct ast_channel *chan, const char *vdata)
00090 {
00091 int res = 0;
00092 char *data;
00093 int dinterval = 0, duration = 0;
00094 struct ast_channel *dchan;
00095 AST_DECLARE_APP_ARGS(args,
00096 AST_APP_ARG(digits);
00097 AST_APP_ARG(dinterval);
00098 AST_APP_ARG(duration);
00099 AST_APP_ARG(channel);
00100 );
00101
00102 if (ast_strlen_zero(vdata)) {
00103 ast_log(LOG_WARNING, "SendDTMF requires an argument (digits or *#aAbBcCdD)\n");
00104 return 0;
00105 }
00106
00107 dchan = chan;
00108
00109 data = ast_strdupa(vdata);
00110 AST_STANDARD_APP_ARGS(args, data);
00111
00112 if (!ast_strlen_zero(args.dinterval)) {
00113 ast_app_parse_timelen(args.dinterval, &dinterval, TIMELEN_MILLISECONDS);
00114 }
00115 if (!ast_strlen_zero(args.duration)) {
00116 ast_app_parse_timelen(args.duration, &duration, TIMELEN_MILLISECONDS);
00117 }
00118 if (!ast_strlen_zero(args.channel)) {
00119 dchan = ast_channel_get_by_name(args.channel);
00120 }
00121 if (dchan != chan) {
00122 ast_autoservice_start(chan);
00123 }
00124 res = ast_dtmf_stream(dchan, NULL, args.digits, dinterval <= 0 ? 250 : dinterval, duration);
00125 if (dchan != chan) {
00126 ast_autoservice_stop(chan);
00127 ast_channel_unref(dchan);
00128 }
00129
00130 return res;
00131 }
00132
00133 static int manager_play_dtmf(struct mansession *s, const struct message *m)
00134 {
00135 const char *channel = astman_get_header(m, "Channel");
00136 const char *digit = astman_get_header(m, "Digit");
00137 struct ast_channel *chan;
00138
00139 if (!(chan = ast_channel_get_by_name(channel))) {
00140 astman_send_error(s, m, "Channel not found");
00141 return 0;
00142 }
00143
00144 if (ast_strlen_zero(digit)) {
00145 astman_send_error(s, m, "No digit specified");
00146 chan = ast_channel_unref(chan);
00147 return 0;
00148 }
00149
00150 ast_senddigit(chan, *digit, 0);
00151
00152 chan = ast_channel_unref(chan);
00153
00154 astman_send_ack(s, m, "DTMF successfully queued");
00155
00156 return 0;
00157 }
00158
00159 static int unload_module(void)
00160 {
00161 int res;
00162
00163 res = ast_unregister_application(app);
00164 res |= ast_manager_unregister("PlayDTMF");
00165
00166 return res;
00167 }
00168
00169 static int load_module(void)
00170 {
00171 int res;
00172
00173 res = ast_manager_register_xml("PlayDTMF", EVENT_FLAG_CALL, manager_play_dtmf);
00174 res |= ast_register_application_xml(app, senddtmf_exec);
00175
00176 return res;
00177 }
00178
00179 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Send DTMF digits Application");