(closes issue #12846)
[asterisk-bristuff.git] / apps / app_zapateller.c
blob5a209e3152b2ce45bc6823305d534e64ebfeb995
1 /*
2 * Asterisk -- An open source telephony toolkit.
4 * Copyright (C) 1999 - 2005, Digium, Inc.
6 * Mark Spencer <markster@digium.com>
8 * See http://www.asterisk.org for more information about
9 * the Asterisk project. Please do not directly contact
10 * any of the maintainers of this project for assistance;
11 * the project provides a web site, mailing lists and IRC
12 * channels for your use.
14 * This program is free software, distributed under the terms of
15 * the GNU General Public License Version 2. See the LICENSE file
16 * at the top of the source tree.
19 /*! \file
21 * \brief Playback the special information tone to get rid of telemarketers
23 * \author Mark Spencer <markster@digium.com>
25 * \ingroup applications
28 #include "asterisk.h"
30 ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
32 #include <stdlib.h>
33 #include <stdio.h>
34 #include <string.h>
36 #include "asterisk/lock.h"
37 #include "asterisk/file.h"
38 #include "asterisk/logger.h"
39 #include "asterisk/channel.h"
40 #include "asterisk/pbx.h"
41 #include "asterisk/module.h"
42 #include "asterisk/translate.h"
44 static char *app = "Zapateller";
46 static char *synopsis = "Block telemarketers with SIT";
48 static char *descrip =
49 " Zapateller(options): Generates special information tone to block\n"
50 "telemarketers from calling you. Options is a pipe-delimited list of\n"
51 "options. The following options are available:\n"
52 "'answer' causes the line to be answered before playing the tone,\n"
53 "'nocallerid' causes Zapateller to only play the tone if there\n"
54 "is no callerid information available. Options should be separated by |\n"
55 "characters\n";
58 static int zapateller_exec(struct ast_channel *chan, void *data)
60 int res = 0;
61 struct ast_module_user *u;
62 int answer = 0, nocallerid = 0;
63 char *c;
64 char *stringp=NULL;
66 u = ast_module_user_add(chan);
68 stringp=data;
69 c = strsep(&stringp, "|");
70 while(!ast_strlen_zero(c)) {
71 if (!strcasecmp(c, "answer"))
72 answer = 1;
73 else if (!strcasecmp(c, "nocallerid"))
74 nocallerid = 1;
76 c = strsep(&stringp, "|");
79 ast_stopstream(chan);
80 if (chan->_state != AST_STATE_UP) {
82 if (answer)
83 res = ast_answer(chan);
84 if (!res) {
85 res = ast_safe_sleep(chan, 500);
88 if (!ast_strlen_zero(chan->cid.cid_num) && nocallerid) {
89 ast_module_user_remove(u);
90 return res;
92 if (!res)
93 res = ast_tonepair(chan, 950, 0, 330, 0);
94 if (!res)
95 res = ast_tonepair(chan, 1400, 0, 330, 0);
96 if (!res)
97 res = ast_tonepair(chan, 1800, 0, 330, 0);
98 if (!res)
99 res = ast_tonepair(chan, 0, 0, 1000, 0);
100 ast_module_user_remove(u);
101 return res;
104 static int unload_module(void)
106 int res;
108 res = ast_unregister_application(app);
110 ast_module_user_hangup_all();
112 return res;
115 static int load_module(void)
117 return ast_register_application(app, zapateller_exec, synopsis, descrip);
120 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Block Telemarketers with Special Information Tone");