Fri Jun 19 12:09:30 2009

Asterisk developer's documentation


app_zapateller.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 Playback the special information tone to get rid of telemarketers
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: 94806 $")
00031 
00032 #include "asterisk/lock.h"
00033 #include "asterisk/file.h"
00034 #include "asterisk/channel.h"
00035 #include "asterisk/pbx.h"
00036 #include "asterisk/module.h"
00037 #include "asterisk/translate.h"
00038 #include "asterisk/app.h"
00039 
00040 static char *app = "Zapateller";
00041 
00042 static char *synopsis = "Block telemarketers with SIT";
00043 
00044 static char *descrip = 
00045 "  Zapateller(options):  Generates special information tone to block\n"
00046 "telemarketers from calling you.  Options is a pipe-delimited list of\n" 
00047 "options.  The following options are available:\n"
00048 "    'answer'     - causes the line to be answered before playing the tone,\n" 
00049 "    'nocallerid' - causes Zapateller to only play the tone if there is no\n"
00050 "                   callerid information available.  Options should be\n"
00051 "                   separated by , characters\n\n"
00052 "  This application will set the following channel variable upon completion:\n"
00053 "    ZAPATELLERSTATUS - This will contain the last action accomplished by the\n"
00054 "                        Zapateller application. Possible values include:\n"
00055 "                        NOTHING | ANSWERED | ZAPPED\n\n";
00056 
00057 
00058 static int zapateller_exec(struct ast_channel *chan, void *data)
00059 {
00060    int res = 0;
00061    int i, answer = 0, nocallerid = 0;
00062    char *parse = ast_strdupa((char *)data);
00063    AST_DECLARE_APP_ARGS(args,
00064       AST_APP_ARG(options)[2];
00065    );
00066 
00067    AST_STANDARD_APP_ARGS(args, parse);
00068 
00069    for (i = 0; i < args.argc; i++) {
00070       if (!strcasecmp(args.options[i], "answer"))
00071          answer = 1;
00072       else if (!strcasecmp(args.options[i], "nocallerid"))
00073          nocallerid = 1;
00074    }
00075 
00076    pbx_builtin_setvar_helper(chan, "ZAPATELLERSTATUS", "NOTHING");
00077    ast_stopstream(chan);
00078    if (chan->_state != AST_STATE_UP) {
00079       if (answer) {
00080          res = ast_answer(chan);
00081          pbx_builtin_setvar_helper(chan, "ZAPATELLERSTATUS", "ANSWERED");
00082       }
00083       if (!res)
00084          res = ast_safe_sleep(chan, 500);
00085    }
00086 
00087    if (!ast_strlen_zero(chan->cid.cid_num) && nocallerid)
00088       return res;
00089 
00090    if (!res) 
00091       res = ast_tonepair(chan, 950, 0, 330, 0);
00092    if (!res) 
00093       res = ast_tonepair(chan, 1400, 0, 330, 0);
00094    if (!res) 
00095       res = ast_tonepair(chan, 1800, 0, 330, 0);
00096    if (!res) 
00097       res = ast_tonepair(chan, 0, 0, 1000, 0);
00098    
00099    pbx_builtin_setvar_helper(chan, "ZAPATELLERSTATUS", "ZAPPED");
00100    return res;
00101 }
00102 
00103 static int unload_module(void)
00104 {
00105    return ast_unregister_application(app);
00106 }
00107 
00108 static int load_module(void)
00109 {
00110    return ((ast_register_application(app, zapateller_exec, synopsis, descrip)) ? AST_MODULE_LOAD_FAILURE : AST_MODULE_LOAD_SUCCESS);
00111 }
00112 
00113 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Block Telemarketers with Special Information Tone");

Generated on Fri Jun 19 12:09:30 2009 for Asterisk - the Open Source PBX by  doxygen 1.4.7