Sat Mar 24 23:25:59 2007

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  * \ingroup applications
00024  */
00025  
00026 #include <stdlib.h>
00027 #include <stdio.h>
00028 #include <string.h>
00029 
00030 #include "asterisk.h"
00031 
00032 ASTERISK_FILE_VERSION(__FILE__, "$Revision: 17283 $")
00033 
00034 #include "asterisk/lock.h"
00035 #include "asterisk/file.h"
00036 #include "asterisk/logger.h"
00037 #include "asterisk/channel.h"
00038 #include "asterisk/pbx.h"
00039 #include "asterisk/module.h"
00040 #include "asterisk/translate.h"
00041 #include "asterisk/options.h"
00042 #include "asterisk/utils.h"
00043 #include "asterisk/app.h"
00044 #include "asterisk/manager.h"
00045 
00046 static char *tdesc = "Send DTMF digits Application";
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 STANDARD_LOCAL_USER;
00059 
00060 LOCAL_USER_DECL;
00061 
00062 static int senddtmf_exec(struct ast_channel *chan, void *data)
00063 {
00064    int res = 0;
00065    struct localuser *u;
00066    char *digits = NULL, *to = NULL;
00067    int timeout = 250;
00068 
00069    if (ast_strlen_zero(data)) {
00070       ast_log(LOG_WARNING, "SendDTMF requires an argument (digits or *#aAbBcCdD)\n");
00071       return 0;
00072    }
00073 
00074    LOCAL_USER_ADD(u);
00075 
00076    digits = ast_strdupa(data);
00077    if (!digits) {
00078       ast_log(LOG_ERROR, "Out of Memory!\n");
00079       LOCAL_USER_REMOVE(u);
00080       return -1;
00081    }
00082 
00083    if ((to = strchr(digits,'|'))) {
00084       *to = '\0';
00085       to++;
00086       timeout = atoi(to);
00087    }
00088       
00089    if(timeout <= 0)
00090       timeout = 250;
00091 
00092    res = ast_dtmf_stream(chan,NULL,digits,timeout);
00093       
00094    LOCAL_USER_REMOVE(u);
00095 
00096    return res;
00097 }
00098 
00099 static char mandescr_playdtmf[] =
00100    "Description: Plays a DTMF digit on the specified channel.\n"
00101    "Variables: (all are required)\n"
00102    "Channel: Channel name to send digit to\n"
00103    "Digit: The dtmf digit to play\n";
00104 
00105 static int manager_play_dtmf(struct mansession *s, struct message *m)
00106 {
00107    char *channel, *digit;
00108 
00109    channel = astman_get_header(m, "Channel");
00110    digit = astman_get_header(m, "Digit");
00111    struct ast_channel *chan = ast_get_channel_by_name_locked(channel);
00112    if (chan == NULL) {
00113       astman_send_error(s, m, "No such channel");
00114       return 0;
00115    }
00116    if (digit == NULL) {
00117       astman_send_error(s, m, "No digit specified");
00118       return 0;
00119    }
00120    ast_senddigit(chan, *digit);
00121    ast_mutex_unlock(&chan->lock);
00122    astman_send_ack(s, m, "DTMF successfully sent");
00123    return 0;
00124 }
00125 
00126 int unload_module(void)
00127 {
00128    int res;
00129 
00130    res = ast_unregister_application(app);
00131    res |= ast_manager_unregister("playDTMF");
00132 
00133    STANDARD_HANGUP_LOCALUSERS;
00134 
00135    return res; 
00136 }
00137 
00138 int load_module(void)
00139 {
00140    ast_manager_register2( "playDTMF", EVENT_FLAG_AGENT, manager_play_dtmf, "Play DTMF signal on a specific channel.", mandescr_playdtmf);
00141    return ast_register_application(app, senddtmf_exec, synopsis, descrip);
00142 }
00143 
00144 char *description(void)
00145 {
00146    return tdesc;
00147 }
00148 
00149 int usecount(void)
00150 {
00151    int res;
00152    STANDARD_USECOUNT(res);
00153    return res;
00154 }
00155 
00156 char *key()
00157 {
00158    return ASTERISK_GPL_KEY;
00159 }

Generated on Sat Mar 24 23:25:59 2007 for Asterisk - the Open Source PBX by  doxygen 1.4.6