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
00029
00030
00031
00032 #include "asterisk.h"
00033
00034 ASTERISK_FILE_VERSION(__FILE__, "$Revision: 373945 $")
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
00088
00089 static const char senddtmf_name[] = "SendDTMF";
00090
00091 static int senddtmf_exec(struct ast_channel *chan, const char *vdata)
00092 {
00093 int res;
00094 char *data;
00095 int dinterval = 0, duration = 0;
00096 struct ast_channel *chan_found = NULL;
00097 struct ast_channel *chan_dest = chan;
00098 struct ast_channel *chan_autoservice = NULL;
00099 AST_DECLARE_APP_ARGS(args,
00100 AST_APP_ARG(digits);
00101 AST_APP_ARG(dinterval);
00102 AST_APP_ARG(duration);
00103 AST_APP_ARG(channel);
00104 );
00105
00106 if (ast_strlen_zero(vdata)) {
00107 ast_log(LOG_WARNING, "SendDTMF requires an argument\n");
00108 return 0;
00109 }
00110
00111 data = ast_strdupa(vdata);
00112 AST_STANDARD_APP_ARGS(args, data);
00113
00114 if (ast_strlen_zero(args.digits)) {
00115 ast_log(LOG_WARNING, "The digits argument is required (0-9,*#,a-d,A-D,wfF)\n");
00116 return 0;
00117 }
00118 if (!ast_strlen_zero(args.dinterval)) {
00119 ast_app_parse_timelen(args.dinterval, &dinterval, TIMELEN_MILLISECONDS);
00120 }
00121 if (!ast_strlen_zero(args.duration)) {
00122 ast_app_parse_timelen(args.duration, &duration, TIMELEN_MILLISECONDS);
00123 }
00124 if (!ast_strlen_zero(args.channel)) {
00125 chan_found = ast_channel_get_by_name(args.channel);
00126 if (!chan_found) {
00127 ast_log(LOG_WARNING, "No such channel: %s\n", args.channel);
00128 return 0;
00129 }
00130 chan_dest = chan_found;
00131 if (chan_found != chan) {
00132 chan_autoservice = chan;
00133 }
00134 }
00135 res = ast_dtmf_stream(chan_dest, chan_autoservice, args.digits,
00136 dinterval <= 0 ? 250 : dinterval, duration);
00137 if (chan_found) {
00138 ast_channel_unref(chan_found);
00139 }
00140
00141 return chan_autoservice ? 0 : res;
00142 }
00143
00144 static int manager_play_dtmf(struct mansession *s, const struct message *m)
00145 {
00146 const char *channel = astman_get_header(m, "Channel");
00147 const char *digit = astman_get_header(m, "Digit");
00148 struct ast_channel *chan;
00149
00150 if (!(chan = ast_channel_get_by_name(channel))) {
00151 astman_send_error(s, m, "Channel not found");
00152 return 0;
00153 }
00154
00155 if (ast_strlen_zero(digit)) {
00156 astman_send_error(s, m, "No digit specified");
00157 chan = ast_channel_unref(chan);
00158 return 0;
00159 }
00160
00161 ast_senddigit(chan, *digit, 0);
00162
00163 chan = ast_channel_unref(chan);
00164
00165 astman_send_ack(s, m, "DTMF successfully queued");
00166
00167 return 0;
00168 }
00169
00170 static int unload_module(void)
00171 {
00172 int res;
00173
00174 res = ast_unregister_application(senddtmf_name);
00175 res |= ast_manager_unregister("PlayDTMF");
00176
00177 return res;
00178 }
00179
00180 static int load_module(void)
00181 {
00182 int res;
00183
00184 res = ast_manager_register_xml("PlayDTMF", EVENT_FLAG_CALL, manager_play_dtmf);
00185 res |= ast_register_application_xml(senddtmf_name, senddtmf_exec);
00186
00187 return res;
00188 }
00189
00190 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Send DTMF digits Application");