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

Generated on Thu Apr 16 06:27:13 2015 for Asterisk - The Open Source Telephony Project by  doxygen 1.5.6