Sat Aug 6 00:39:22 2011

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: 80878 $")
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 
00044 static char *app = "Zapateller";
00045 
00046 static char *synopsis = "Block telemarketers with SIT";
00047 
00048 static char *descrip = 
00049 "  Zapateller(options):  Generates special information tone to block\n"
00050 "telemarketers from calling you.  Options is a pipe-delimited list of\n" 
00051 "options.  The following options are available:\n"
00052 "'answer' causes the line to be answered before playing the tone,\n" 
00053 "'nocallerid' causes Zapateller to only play the tone if there\n"
00054 "is no callerid information available.  Options should be separated by |\n"
00055 "characters\n";
00056 
00057 
00058 static int zapateller_exec(struct ast_channel *chan, void *data)
00059 {
00060    int res = 0;
00061    struct ast_module_user *u;
00062    int answer = 0, nocallerid = 0;
00063    char *c;
00064    char *stringp=NULL;
00065    
00066    u = ast_module_user_add(chan);
00067 
00068    stringp=data;
00069         c = strsep(&stringp, "|");
00070         while(!ast_strlen_zero(c)) {
00071       if (!strcasecmp(c, "answer"))
00072          answer = 1;
00073       else if (!strcasecmp(c, "nocallerid"))
00074          nocallerid = 1;
00075 
00076                 c = strsep(&stringp, "|");
00077         }
00078 
00079    ast_stopstream(chan);
00080    if (chan->_state != AST_STATE_UP) {
00081 
00082       if (answer) 
00083          res = ast_answer(chan);
00084       if (!res) {
00085          res = ast_safe_sleep(chan, 500);
00086       }
00087    }
00088    if (!ast_strlen_zero(chan->cid.cid_num) && nocallerid) {
00089       ast_module_user_remove(u);
00090       return res;
00091    } 
00092    if (!res) 
00093       res = ast_tonepair(chan, 950, 0, 330, 0);
00094    if (!res) 
00095       res = ast_tonepair(chan, 1400, 0, 330, 0);
00096    if (!res) 
00097       res = ast_tonepair(chan, 1800, 0, 330, 0);
00098    if (!res) 
00099       res = ast_tonepair(chan, 0, 0, 1000, 0);
00100    ast_module_user_remove(u);
00101    return res;
00102 }
00103 
00104 static int unload_module(void)
00105 {
00106    int res;
00107 
00108    res = ast_unregister_application(app);
00109    
00110    ast_module_user_hangup_all();
00111 
00112    return res; 
00113 }
00114 
00115 static int load_module(void)
00116 {
00117    return ast_register_application(app, zapateller_exec, synopsis, descrip);
00118 }
00119 
00120 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Block Telemarketers with Special Information Tone");

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