| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
#include "asterisk.h" |
| 33 |
|
| 34 |
#include "asterisk/pbx.h" |
| 35 |
#include "asterisk/module.h" |
| 36 |
#include "asterisk/app.h" |
| 37 |
#include "asterisk/manager.h" |
| 38 |
#include "asterisk/channel.h" |
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
enum read_option_flags { |
| 130 |
OPT_ANSWER = (1 << 0), |
| 131 |
}; |
| 132 |
|
| 133 |
AST_APP_OPTIONS(senddtmf_app_options, { |
| 134 |
AST_APP_OPTION('a', OPT_ANSWER), |
| 135 |
}); |
| 136 |
|
| 137 |
enum { |
| 138 |
|
| 139 |
OPT_ARG_ARRAY_SIZE, |
| 140 |
}; |
| 141 |
|
| 142 |
static const char senddtmf_name[] = "SendDTMF"; |
| 143 |
|
| 144 |
static int senddtmf_exec(struct ast_channel *chan, const char *vdata) |
| 145 |
{ |
| 146 |
int res; |
| 147 |
char *data; |
| 148 |
int dinterval = 0, duration = 0; |
| 149 |
struct ast_channel *chan_found = NULL; |
| 150 |
struct ast_channel *chan_dest = chan; |
| 151 |
struct ast_channel *chan_autoservice = NULL; |
| 152 |
char *opt_args[OPT_ARG_ARRAY_SIZE]; |
| 153 |
struct ast_flags flags = {0}; |
| 154 |
AST_DECLARE_APP_ARGS(args, |
| 155 |
AST_APP_ARG(digits); |
| 156 |
AST_APP_ARG(dinterval); |
| 157 |
AST_APP_ARG(duration); |
| 158 |
AST_APP_ARG(channel); |
| 159 |
AST_APP_ARG(options); |
| 160 |
); |
| 161 |
|
| 162 |
if (ast_strlen_zero(vdata)) { |
| 163 |
ast_log(LOG_WARNING, "SendDTMF requires an argument\n"); |
| 164 |
return 0; |
| 165 |
} |
| 166 |
|
| 167 |
data = ast_strdupa(vdata); |
| 168 |
AST_STANDARD_APP_ARGS(args, data); |
| 169 |
|
| 170 |
if (ast_strlen_zero(args.digits)) { |
| 171 |
ast_log(LOG_WARNING, "The digits argument is required (0-9,*#,a-d,A-D,wfF)\n"); |
| 172 |
return 0; |
| 173 |
} |
| 174 |
if (!ast_strlen_zero(args.dinterval)) { |
| 175 |
ast_app_parse_timelen(args.dinterval, &dinterval, TIMELEN_MILLISECONDS); |
| 176 |
} |
| 177 |
if (!ast_strlen_zero(args.duration)) { |
| 178 |
ast_app_parse_timelen(args.duration, &duration, TIMELEN_MILLISECONDS); |
| 179 |
} |
| 180 |
if (!ast_strlen_zero(args.channel)) { |
| 181 |
chan_found = ast_channel_get_by_name(args.channel); |
| 182 |
if (!chan_found) { |
| 183 |
ast_log(LOG_WARNING, "No such channel: %s\n", args.channel); |
| 184 |
return 0; |
| 185 |
} |
| 186 |
chan_dest = chan_found; |
| 187 |
if (chan_found != chan) { |
| 188 |
chan_autoservice = chan; |
| 189 |
} |
| 190 |
} |
| 191 |
if (!ast_strlen_zero(args.options)) { |
| 192 |
ast_app_parse_options(senddtmf_app_options, &flags, opt_args, args.options); |
| 193 |
} |
| 194 |
if (ast_test_flag(&flags, OPT_ANSWER)) { |
| 195 |
ast_auto_answer(chan_dest); |
| 196 |
} |
| 197 |
res = ast_dtmf_stream(chan_dest, chan_autoservice, args.digits, |
| 198 |
dinterval <= 0 ? 250 : dinterval, duration); |
| 199 |
if (chan_found) { |
| 200 |
ast_channel_unref(chan_found); |
| 201 |
} |
| 202 |
|
| 203 |
return chan_autoservice ? 0 : res; |
| 204 |
} |
| 205 |
|
| 206 |
static int manager_play_dtmf(struct mansession *s, const struct message *m) |
| 207 |
{ |
| 208 |
const char *channel = astman_get_header(m, "Channel"); |
| 209 |
const char *digit = astman_get_header(m, "Digit"); |
| 210 |
const char *duration = astman_get_header(m, "Duration"); |
| 211 |
const char *receive_s = astman_get_header(m, "Receive"); |
| 212 |
struct ast_channel *chan; |
| 213 |
unsigned int duration_ms = 0; |
| 214 |
|
| 215 |
if (!(chan = ast_channel_get_by_name(channel))) { |
| 216 |
astman_send_error(s, m, "Channel not found"); |
| 217 |
return 0; |
| 218 |
} |
| 219 |
|
| 220 |
if (ast_strlen_zero(digit)) { |
| 221 |
astman_send_error(s, m, "No digit specified"); |
| 222 |
chan = ast_channel_unref(chan); |
| 223 |
return 0; |
| 224 |
} |
| 225 |
|
| 226 |
if (!ast_strlen_zero(duration) && (sscanf(duration, "%30u", &duration_ms) != 1)) { |
| 227 |
astman_send_error(s, m, "Could not convert Duration parameter"); |
| 228 |
chan = ast_channel_unref(chan); |
| 229 |
return 0; |
| 230 |
} |
| 231 |
|
| 232 |
if (ast_true(receive_s)) { |
| 233 |
struct ast_frame f = { AST_FRAME_DTMF, }; |
| 234 |
f.len = duration_ms; |
| 235 |
f.subclass.integer = *digit; |
| 236 |
ast_queue_frame(chan, &f); |
| 237 |
} else { |
| 238 |
ast_senddigit_external(chan, *digit, duration_ms); |
| 239 |
} |
| 240 |
|
| 241 |
chan = ast_channel_unref(chan); |
| 242 |
|
| 243 |
astman_send_ack(s, m, "DTMF successfully queued"); |
| 244 |
|
| 245 |
return 0; |
| 246 |
} |
| 247 |
|
| 248 |
static int manager_send_flash(struct mansession *s, const struct message *m) |
| 249 |
{ |
| 250 |
const char *channel = astman_get_header(m, "Channel"); |
| 251 |
const char *receive_s = astman_get_header(m, "Receive"); |
| 252 |
struct ast_channel *chan; |
| 253 |
|
| 254 |
if (!(chan = ast_channel_get_by_name(channel))) { |
| 255 |
astman_send_error(s, m, "Channel not found"); |
| 256 |
return 0; |
| 257 |
} |
| 258 |
|
| 259 |
if (ast_true(receive_s)) { |
| 260 |
struct ast_frame f = { AST_FRAME_CONTROL, }; |
| 261 |
f.subclass.integer = AST_CONTROL_FLASH; |
| 262 |
ast_queue_frame(chan, &f); |
| 263 |
} else { |
| 264 |
struct ast_frame f = { AST_FRAME_CONTROL, }; |
| 265 |
f.subclass.integer = AST_CONTROL_FLASH; |
| 266 |
ast_channel_lock(chan); |
| 267 |
ast_write(chan, &f); |
| 268 |
ast_channel_unlock(chan); |
| 269 |
} |
| 270 |
|
| 271 |
chan = ast_channel_unref(chan); |
| 272 |
astman_send_ack(s, m, "Flash successfully queued"); |
| 273 |
return 0; |
| 274 |
} |
| 275 |
|
| 276 |
static int unload_module(void) |
| 277 |
{ |
| 278 |
int res; |
| 279 |
|
| 280 |
res = ast_unregister_application(senddtmf_name); |
| 281 |
res |= ast_manager_unregister("PlayDTMF"); |
| 282 |
res |= ast_manager_unregister("SendFlash"); |
| 283 |
|
| 284 |
return res; |
| 285 |
} |
| 286 |
|
| 287 |
static int load_module(void) |
| 288 |
{ |
| 289 |
int res; |
| 290 |
|
| 291 |
res = ast_manager_register_xml("PlayDTMF", EVENT_FLAG_CALL, manager_play_dtmf); |
| 292 |
res |= ast_manager_register_xml("SendFlash", EVENT_FLAG_CALL, manager_send_flash); |
| 293 |
res |= ast_register_application_xml(senddtmf_name, senddtmf_exec); |
| 294 |
|
| 295 |
return res; |
| 296 |
} |
| 297 |
|
| 298 |
AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Send DTMF digits Application"); |