Asterisk - The Open Source Telephony Project GIT-master-0bf3178
app_zapateller.c
Go to the documentation of this file.
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#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 <synopsis>
45 Block telemarketers with SIT.
46 </synopsis>
47 <syntax>
48 <parameter name="options" required="true">
49 <para>Comma delimited list of options.</para>
50 <optionlist>
51 <option name="answer">
52 <para>Causes the line to be answered before playing the tone.</para>
53 </option>
54 <option name="nocallerid">
55 <para>Causes Zapateller to only play the tone if there is no
56 callerid information available.</para>
57 </option>
58 </optionlist>
59 </parameter>
60 </syntax>
61 <description>
62 <para>Generates special information tone to block telemarketers from calling you.</para>
63 <para>This application will set the following channel variable upon completion:</para>
64 <variablelist>
65 <variable name="ZAPATELLERSTATUS">
66 <para>This will contain the last action accomplished by the
67 Zapateller application. Possible values include:</para>
68 <value name="NOTHING" />
69 <value name="ANSWERED" />
70 <value name="ZAPPED" />
71 </variable>
72 </variablelist>
73 </description>
74 </application>
75 ***/
76
77static char *app = "Zapateller";
78
79static int zapateller_exec(struct ast_channel *chan, const char *data)
80{
81 int res = 0;
82 int i, answer = 0, nocallerid = 0;
83 char *parse = ast_strdupa((char *)data);
86 );
87
89
90 for (i = 0; i < args.argc; i++) {
91 if (!strcasecmp(args.options[i], "answer"))
92 answer = 1;
93 else if (!strcasecmp(args.options[i], "nocallerid"))
94 nocallerid = 1;
95 }
96
97 pbx_builtin_setvar_helper(chan, "ZAPATELLERSTATUS", "NOTHING");
98 ast_stopstream(chan);
99 if (ast_channel_state(chan) != AST_STATE_UP) {
100 if (answer) {
101 res = ast_answer(chan);
102 pbx_builtin_setvar_helper(chan, "ZAPATELLERSTATUS", "ANSWERED");
103 }
104 if (!res)
105 res = ast_safe_sleep(chan, 500);
106 }
107
108 if (nocallerid /* Zap caller if no caller id. */
109 && ast_channel_caller(chan)->id.number.valid
110 && !ast_strlen_zero(ast_channel_caller(chan)->id.number.str)) {
111 /* We have caller id. */
112 return res;
113 }
114
115 if (!res)
116 res = ast_tonepair(chan, 950, 0, 330, 0);
117 if (!res)
118 res = ast_tonepair(chan, 1400, 0, 330, 0);
119 if (!res)
120 res = ast_tonepair(chan, 1800, 0, 330, 0);
121 if (!res)
122 res = ast_tonepair(chan, 0, 0, 1000, 0);
123
124 pbx_builtin_setvar_helper(chan, "ZAPATELLERSTATUS", "ZAPPED");
125 return res;
126}
127
128static int unload_module(void)
129{
131}
132
133static int load_module(void)
134{
136}
137
138AST_MODULE_INFO_STANDARD_EXTENDED(ASTERISK_GPL_KEY, "Block Telemarketers with Special Information Tone");
static int zapateller_exec(struct ast_channel *chan, const char *data)
static char * app
static int load_module(void)
AST_MODULE_INFO_STANDARD_EXTENDED(ASTERISK_GPL_KEY, "Block Telemarketers with Special Information Tone")
static int unload_module(void)
Asterisk main include file. File version handling, generic pbx functions.
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: astmm.h:298
static int answer(void *data)
Definition: chan_pjsip.c:687
General Asterisk PBX channel definitions.
struct ast_party_caller * ast_channel_caller(struct ast_channel *chan)
int ast_tonepair(struct ast_channel *chan, int freq1, int freq2, int duration, int vol)
Definition: channel.c:7622
int ast_answer(struct ast_channel *chan)
Answer a channel.
Definition: channel.c:2824
int ast_safe_sleep(struct ast_channel *chan, int ms)
Wait for a specified amount of time, looking for hangups.
Definition: channel.c:1593
ast_channel_state
ast_channel states
Definition: channelstate.h:35
@ AST_STATE_UP
Definition: channelstate.h:42
Generic File Format Support. Should be included by clients of the file handling routines....
int ast_stopstream(struct ast_channel *c)
Stops a stream.
Definition: file.c:222
Application convenience functions, designed to give consistent look and feel to Asterisk apps.
#define AST_APP_ARG(name)
Define an application argument.
#define AST_DECLARE_APP_ARGS(name, arglist)
Declare a structure to hold an application's arguments.
#define AST_STANDARD_APP_ARGS(args, parse)
Performs the 'standard' argument separation process for an application.
Asterisk locking-related definitions:
Asterisk module definitions.
#define ASTERISK_GPL_KEY
The text the key() function should return.
Definition: module.h:46
int ast_unregister_application(const char *app)
Unregister an application.
Definition: pbx_app.c:392
@ AST_MODULE_LOAD_SUCCESS
Definition: module.h:70
@ AST_MODULE_LOAD_DECLINE
Module has failed to load, may be in an inconsistent state.
Definition: module.h:78
#define ast_register_application_xml(app, execute)
Register an application using XML documentation.
Definition: module.h:640
Core PBX routines and definitions.
int pbx_builtin_setvar_helper(struct ast_channel *chan, const char *name, const char *value)
Add a variable to the channel variable stack, removing the most recently set value for the same name.
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:65
Main Channel structure associated with a channel.
Number structure.
Definition: app_followme.c:154
const char * args
static struct test_options options
Support for translation of data formats. translate.c.