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 #include "asterisk.h"
00029
00030 ASTERISK_FILE_VERSION(__FILE__, "$Revision: 184078 $")
00031
00032 #include <stdlib.h>
00033 #include <stdio.h>
00034 #include <string.h>
00035
00036 #include "asterisk/lock.h"
00037 #include "asterisk/file.h"
00038 #include "asterisk/logger.h"
00039 #include "asterisk/channel.h"
00040 #include "asterisk/pbx.h"
00041 #include "asterisk/module.h"
00042 #include "asterisk/translate.h"
00043 #include "asterisk/options.h"
00044 #include "asterisk/utils.h"
00045 #include "asterisk/app.h"
00046 #include "asterisk/manager.h"
00047
00048 static char *app = "SendDTMF";
00049
00050 static char *synopsis = "Sends arbitrary DTMF digits";
00051
00052 static char *descrip =
00053 " SendDTMF(digits[|timeout_ms]): Sends DTMF digits on a channel. \n"
00054 " Accepted digits: 0-9, *#abcd, w (.5s pause)\n"
00055 " The application will either pass the assigned digits or terminate if it\n"
00056 " encounters an error.\n";
00057
00058
00059 static int senddtmf_exec(struct ast_channel *chan, void *data)
00060 {
00061 int res = 0;
00062 struct ast_module_user *u;
00063 char *digits = NULL, *to = NULL;
00064 int timeout = 250;
00065
00066 if (ast_strlen_zero(data)) {
00067 ast_log(LOG_WARNING, "SendDTMF requires an argument (digits or *#aAbBcCdD)\n");
00068 return 0;
00069 }
00070
00071 u = ast_module_user_add(chan);
00072
00073 digits = ast_strdupa(data);
00074
00075 if ((to = strchr(digits,'|'))) {
00076 *to = '\0';
00077 to++;
00078 timeout = atoi(to);
00079 }
00080
00081 if (timeout <= 0)
00082 timeout = 250;
00083
00084 res = ast_dtmf_stream(chan,NULL,digits,timeout);
00085
00086 ast_module_user_remove(u);
00087
00088 return res;
00089 }
00090
00091 static char mandescr_playdtmf[] =
00092 "Description: Plays a dtmf digit on the specified channel.\n"
00093 "Variables: (all are required)\n"
00094 " Channel: Channel name to send digit to\n"
00095 " Digit: The dtmf digit to play\n";
00096
00097 static int manager_play_dtmf(struct mansession *s, const struct message *m)
00098 {
00099 const char *channel = astman_get_header(m, "Channel");
00100 const char *digit = astman_get_header(m, "Digit");
00101 struct ast_channel *chan = ast_get_channel_by_name_locked(channel);
00102
00103 if (!chan) {
00104 astman_send_error(s, m, "Channel not specified");
00105 return 0;
00106 }
00107 if (ast_strlen_zero(digit)) {
00108 astman_send_error(s, m, "No digit specified");
00109 ast_mutex_unlock(&chan->lock);
00110 return 0;
00111 }
00112
00113 ast_senddigit(chan, *digit);
00114
00115 ast_mutex_unlock(&chan->lock);
00116 astman_send_ack(s, m, "DTMF successfully queued");
00117
00118 return 0;
00119 }
00120
00121 static int unload_module(void)
00122 {
00123 int res;
00124
00125 res = ast_unregister_application(app);
00126 res |= ast_manager_unregister("PlayDTMF");
00127
00128 ast_module_user_hangup_all();
00129
00130 return res;
00131 }
00132
00133 static int load_module(void)
00134 {
00135 int res;
00136
00137 res = ast_manager_register2( "PlayDTMF", EVENT_FLAG_CALL, manager_play_dtmf, "Play DTMF signal on a specific channel.", mandescr_playdtmf );
00138 res |= ast_register_application(app, senddtmf_exec, synopsis, descrip);
00139
00140 return res;
00141 }
00142
00143 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Send DTMF digits Application");