Sat Aug 6 00:39:21 2011

Asterisk developer's documentation


app_senddtmf.c

Go to the documentation of this file.
00001 /*
00002  * Asterisk -- An open source telephony toolkit.
00003  *
00004  * Copyright (C) 1999 - 2005, Digium, Inc.
00005  *
00006  * Mark Spencer <markster@digium.com>
00007  *
00008  * See http://www.asterisk.org for more information about
00009  * the Asterisk project. Please do not directly contact
00010  * any of the maintainers of this project for assistance;
00011  * the project provides a web site, mailing lists and IRC
00012  * channels for your use.
00013  *
00014  * This program is free software, distributed under the terms of
00015  * the GNU General Public License Version 2. See the LICENSE file
00016  * at the top of the source tree.
00017  */
00018 
00019 /*! \file
00020  *
00021  * \brief App to send DTMF digits
00022  *
00023  * \author Mark Spencer <markster@digium.com>
00024  * 
00025  * \ingroup applications
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");

Generated on Sat Aug 6 00:39:21 2011 for Asterisk - the Open Source PBX by  doxygen 1.4.7