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