update comment to match the state of the code
[asterisk-bristuff.git] / apps / app_senddtmf.c
blobe48ba4fe069b074a170a9d064187f531f25f5d23
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 <stdlib.h>
33 #include <stdio.h>
34 #include <string.h>
36 #include "asterisk/lock.h"
37 #include "asterisk/file.h"
38 #include "asterisk/logger.h"
39 #include "asterisk/channel.h"
40 #include "asterisk/pbx.h"
41 #include "asterisk/module.h"
42 #include "asterisk/translate.h"
43 #include "asterisk/options.h"
44 #include "asterisk/utils.h"
45 #include "asterisk/app.h"
46 #include "asterisk/manager.h"
48 static char *app = "SendDTMF";
50 static char *synopsis = "Sends arbitrary DTMF digits";
52 static char *descrip =
53 " SendDTMF(digits[|timeout_ms]): Sends DTMF digits on a channel. \n"
54 " Accepted digits: 0-9, *#abcd, w (.5s pause)\n"
55 " The application will either pass the assigned digits or terminate if it\n"
56 " encounters an error.\n";
59 static int senddtmf_exec(struct ast_channel *chan, void *data)
61 int res = 0;
62 struct ast_module_user *u;
63 char *digits = NULL, *to = NULL;
64 int timeout = 250;
66 if (ast_strlen_zero(data)) {
67 ast_log(LOG_WARNING, "SendDTMF requires an argument (digits or *#aAbBcCdD)\n");
68 return 0;
71 u = ast_module_user_add(chan);
73 digits = ast_strdupa(data);
75 if ((to = strchr(digits,'|'))) {
76 *to = '\0';
77 to++;
78 timeout = atoi(to);
81 if (timeout <= 0)
82 timeout = 250;
84 res = ast_dtmf_stream(chan,NULL,digits,timeout);
86 ast_module_user_remove(u);
88 return res;
91 static char mandescr_playdtmf[] =
92 "Description: Plays a dtmf digit on the specified channel.\n"
93 "Variables: (all are required)\n"
94 " Channel: Channel name to send digit to\n"
95 " Digit: The dtmf digit to play\n";
97 static int manager_play_dtmf(struct mansession *s, const struct message *m)
99 const char *channel = astman_get_header(m, "Channel");
100 const char *digit = astman_get_header(m, "Digit");
101 struct ast_channel *chan = ast_get_channel_by_name_locked(channel);
103 if (!chan) {
104 astman_send_error(s, m, "Channel not specified");
105 return 0;
107 if (!digit) {
108 astman_send_error(s, m, "No digit specified");
109 ast_mutex_unlock(&chan->lock);
110 return 0;
113 ast_senddigit(chan, *digit);
115 ast_mutex_unlock(&chan->lock);
116 astman_send_ack(s, m, "DTMF successfully queued");
118 return 0;
121 static int unload_module(void)
123 int res;
125 res = ast_unregister_application(app);
126 res |= ast_manager_unregister("PlayDTMF");
128 ast_module_user_hangup_all();
130 return res;
133 static int load_module(void)
135 int res;
137 res = ast_manager_register2( "PlayDTMF", EVENT_FLAG_CALL, manager_play_dtmf, "Play DTMF signal on a specific channel.", mandescr_playdtmf );
138 res |= ast_register_application(app, senddtmf_exec, synopsis, descrip);
140 return res;
143 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Send DTMF digits Application");