Thu Apr 28 2011 17:13:29

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: 153365 $")
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 /*** DOCUMENTATION
00041    <application name="Zapateller" language="en_US">
00042       <synopsis>
00043          Block telemarketers with SIT.
00044       </synopsis>
00045       <syntax>
00046          <parameter name="options" required="true">
00047             <para>Comma delimited list of options.</para>
00048             <optionlist>
00049                <option name="answer">
00050                   <para>Causes the line to be answered before playing the tone.</para>
00051                </option>
00052                <option name="nocallerid">
00053                   <para>Causes Zapateller to only play the tone if there is no
00054                   callerid information available.</para>
00055                </option>
00056             </optionlist>
00057          </parameter>
00058       </syntax>
00059       <description>
00060          <para>Generates special information tone to block telemarketers from calling you.</para>
00061          <para>This application will set the following channel variable upon completion:</para>
00062          <variablelist>
00063             <variable name="ZAPATELLERSTATUS">
00064                <para>This will contain the last action accomplished by the
00065                Zapateller application. Possible values include:</para>
00066                <value name="NOTHING" />
00067                <value name="ANSWERED" />
00068                <value name="ZAPPED" />
00069             </variable>
00070          </variablelist>
00071       </description>
00072    </application>
00073  ***/
00074 
00075 static char *app = "Zapateller";
00076 
00077 static int zapateller_exec(struct ast_channel *chan, void *data)
00078 {
00079    int res = 0;
00080    int i, answer = 0, nocallerid = 0;
00081    char *parse = ast_strdupa((char *)data);
00082    AST_DECLARE_APP_ARGS(args,
00083       AST_APP_ARG(options)[2];
00084    );
00085 
00086    AST_STANDARD_APP_ARGS(args, parse);
00087 
00088    for (i = 0; i < args.argc; i++) {
00089       if (!strcasecmp(args.options[i], "answer"))
00090          answer = 1;
00091       else if (!strcasecmp(args.options[i], "nocallerid"))
00092          nocallerid = 1;
00093    }
00094 
00095    pbx_builtin_setvar_helper(chan, "ZAPATELLERSTATUS", "NOTHING");
00096    ast_stopstream(chan);
00097    if (chan->_state != AST_STATE_UP) {
00098       if (answer) {
00099          res = ast_answer(chan);
00100          pbx_builtin_setvar_helper(chan, "ZAPATELLERSTATUS", "ANSWERED");
00101       }
00102       if (!res)
00103          res = ast_safe_sleep(chan, 500);
00104    }
00105 
00106    if (!ast_strlen_zero(chan->cid.cid_num) && nocallerid)
00107       return res;
00108 
00109    if (!res) 
00110       res = ast_tonepair(chan, 950, 0, 330, 0);
00111    if (!res) 
00112       res = ast_tonepair(chan, 1400, 0, 330, 0);
00113    if (!res) 
00114       res = ast_tonepair(chan, 1800, 0, 330, 0);
00115    if (!res) 
00116       res = ast_tonepair(chan, 0, 0, 1000, 0);
00117    
00118    pbx_builtin_setvar_helper(chan, "ZAPATELLERSTATUS", "ZAPPED");
00119    return res;
00120 }
00121 
00122 static int unload_module(void)
00123 {
00124    return ast_unregister_application(app);
00125 }
00126 
00127 static int load_module(void)
00128 {
00129    return ((ast_register_application_xml(app, zapateller_exec)) ? AST_MODULE_LOAD_FAILURE : AST_MODULE_LOAD_SUCCESS);
00130 }
00131 
00132 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Block Telemarketers with Special Information Tone");