Merged revisions 126573 via svnmerge from
[asterisk-bristuff.git] / apps / app_senddtmf.c
blob67bd4feaa776deda89c32e5e29817079655ce820
1 /*
2 * Asterisk -- An open source telephony toolkit.
4 * Copyright (C) 1999 - 2005, Digium, Inc.
6 * Mark Spencer <markster@digium.com>
8 * See http://www.asterisk.org for more information about
9 * the Asterisk project. Please do not directly contact
10 * any of the maintainers of this project for assistance;
11 * the project provides a web site, mailing lists and IRC
12 * channels for your use.
14 * This program is free software, distributed under the terms of
15 * the GNU General Public License Version 2. See the LICENSE file
16 * at the top of the source tree.
19 /*! \file
21 * \brief App to send DTMF digits
23 * \author Mark Spencer <markster@digium.com>
25 * \ingroup applications
28 #include "asterisk.h"
30 ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
32 #include "asterisk/pbx.h"
33 #include "asterisk/module.h"
34 #include "asterisk/app.h"
35 #include "asterisk/manager.h"
36 #include "asterisk/channel.h"
38 static char *app = "SendDTMF";
40 static char *synopsis = "Sends arbitrary DTMF digits";
42 static char *descrip =
43 " SendDTMF(digits[,timeout_ms]): Sends DTMF digits on a channel. \n"
44 " Accepted digits: 0-9, *#abcd, w (.5s pause)\n"
45 " The application will either pass the assigned digits or terminate if it\n"
46 " encounters an error.\n";
49 static int senddtmf_exec(struct ast_channel *chan, void *vdata)
51 int res = 0;
52 char *data;
53 int timeout = 0, duration = 0;
54 AST_DECLARE_APP_ARGS(args,
55 AST_APP_ARG(digits);
56 AST_APP_ARG(timeout);
57 AST_APP_ARG(duration);
60 if (ast_strlen_zero(vdata)) {
61 ast_log(LOG_WARNING, "SendDTMF requires an argument (digits or *#aAbBcCdD)\n");
62 return 0;
65 data = ast_strdupa(vdata);
66 AST_STANDARD_APP_ARGS(args, data);
68 if (!ast_strlen_zero(args.timeout))
69 timeout = atoi(args.timeout);
70 if (!ast_strlen_zero(args.duration))
71 duration = atoi(args.duration);
72 res = ast_dtmf_stream(chan, NULL, args.digits, timeout <= 0 ? 250 : timeout, duration);
74 return res;
77 static char mandescr_playdtmf[] =
78 "Description: Plays a dtmf digit on the specified channel.\n"
79 "Variables: (all are required)\n"
80 " Channel: Channel name to send digit to\n"
81 " Digit: The dtmf digit to play\n";
83 static int manager_play_dtmf(struct mansession *s, const struct message *m)
85 const char *channel = astman_get_header(m, "Channel");
86 const char *digit = astman_get_header(m, "Digit");
87 struct ast_channel *chan = ast_get_channel_by_name_locked(channel);
89 if (!chan) {
90 astman_send_error(s, m, "Channel not specified");
91 return 0;
93 if (!digit) {
94 astman_send_error(s, m, "No digit specified");
95 ast_channel_unlock(chan);
96 return 0;
99 ast_senddigit(chan, *digit, 0);
101 ast_channel_unlock(chan);
102 astman_send_ack(s, m, "DTMF successfully queued");
104 return 0;
107 static int unload_module(void)
109 int res;
111 res = ast_unregister_application(app);
112 res |= ast_manager_unregister("PlayDTMF");
114 return res;
117 static int load_module(void)
119 int res;
121 res = ast_manager_register2( "PlayDTMF", EVENT_FLAG_CALL, manager_play_dtmf, "Play DTMF signal on a specific channel.", mandescr_playdtmf );
122 res |= ast_register_application(app, senddtmf_exec, synopsis, descrip);
124 return res;
127 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Send DTMF digits Application");