Debian Codegraph @

apps/app_zapateller.c

raw symbols SCIP
1 /*
2 * Asterisk -- An open source telephony toolkit.
3 *
4 * Copyright (C) 1999 - 2005, Digium, Inc.
5 *
6 * Mark Spencer <[email protected]>
7 *
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.
13 *
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.
17 */
18
19 /*! \file
20 *
21 * \brief Playback the special information tone to get rid of telemarketers
22 *
23 * \author Mark Spencer <[email protected]>
24 *
25 * \ingroup applications
26 */
27
28 /*** MODULEINFO
29 <support_level>extended</support_level>
30 ***/
31
32 #include "asterisk.h"
33
34 #include "asterisk/lock.h"
35 #include "asterisk/file.h"
36 #include "asterisk/channel.h"
37 #include "asterisk/pbx.h"
38 #include "asterisk/module.h"
39 #include "asterisk/translate.h"
40 #include "asterisk/app.h"
41
42 /*** DOCUMENTATION
43 <application name="Zapateller" language="en_US">
44 <since>
45 <version>0.1.12</version>
46 </since>
47 <synopsis>
48 Block telemarketers with SIT.
49 </synopsis>
50 <syntax>
51 <parameter name="options" required="true">
52 <para>Comma delimited list of options.</para>
53 <optionlist>
54 <option name="answer">
55 <para>Causes the line to be answered before playing the tone.</para>
56 </option>
57 <option name="nocallerid">
58 <para>Causes Zapateller to only play the tone if there is no
59 callerid information available.</para>
60 </option>
61 </optionlist>
62 </parameter>
63 </syntax>
64 <description>
65 <para>Generates special information tone to block telemarketers from calling you.</para>
66 <para>This application will set the following channel variable upon completion:</para>
67 <variablelist>
68 <variable name="ZAPATELLERSTATUS">
69 <para>This will contain the last action accomplished by the
70 Zapateller application. Possible values include:</para>
71 <value name="NOTHING" />
72 <value name="ANSWERED" />
73 <value name="ZAPPED" />
74 </variable>
75 </variablelist>
76 </description>
77 </application>
78 ***/
79
80 static char *app = "Zapateller";
81
82 static int zapateller_exec(struct ast_channel *chan, const char *data)
83 {
84 int res = 0;
85 int i, answer = 0, nocallerid = 0;
86 char *parse = ast_strdupa((char *)data);
87 AST_DECLARE_APP_ARGS(args,
88 AST_APP_ARG(options)[2];
89 );
90
91 AST_STANDARD_APP_ARGS(args, parse);
92
93 for (i = 0; i < args.argc; i++) {
94 if (!strcasecmp(args.options[i], "answer"))
95 answer = 1;
96 else if (!strcasecmp(args.options[i], "nocallerid"))
97 nocallerid = 1;
98 }
99
100 pbx_builtin_setvar_helper(chan, "ZAPATELLERSTATUS", "NOTHING");
101 ast_stopstream(chan);
102 if (ast_channel_state(chan) != AST_STATE_UP) {
103 if (answer) {
104 res = ast_answer(chan);
105 pbx_builtin_setvar_helper(chan, "ZAPATELLERSTATUS", "ANSWERED");
106 }
107 if (!res)
108 res = ast_safe_sleep(chan, 500);
109 }
110
111 if (nocallerid /* Zap caller if no caller id. */
112 && ast_channel_caller(chan)->id.number.valid
113 && !ast_strlen_zero(ast_channel_caller(chan)->id.number.str)) {
114 /* We have caller id. */
115 return res;
116 }
117
118 if (!res)
119 res = ast_tonepair(chan, 950, 0, 330, 0);
120 if (!res)
121 res = ast_tonepair(chan, 1400, 0, 330, 0);
122 if (!res)
123 res = ast_tonepair(chan, 1800, 0, 330, 0);
124 if (!res)
125 res = ast_tonepair(chan, 0, 0, 1000, 0);
126
127 pbx_builtin_setvar_helper(chan, "ZAPATELLERSTATUS", "ZAPPED");
128 return res;
129 }
130
131 static int unload_module(void)
132 {
133 return ast_unregister_application(app);
134 }
135
136 static int load_module(void)
137 {
138 return ((ast_register_application_xml(app, zapateller_exec)) ? AST_MODULE_LOAD_DECLINE : AST_MODULE_LOAD_SUCCESS);
139 }
140
141 AST_MODULE_INFO_STANDARD_EXTENDED(ASTERISK_GPL_KEY, "Block Telemarketers with Special Information Tone");