Wed Jan 8 2020 09:49:42

Asterisk developer's documentation


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 ASTERISK_FILE_VERSION(__FILE__, "$Revision: 328209 $")
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);
87  AST_APP_ARG(options)[2];
88  );
89 
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 (chan->_state != 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  && chan->caller.id.number.valid
112  && !ast_strlen_zero(chan->caller.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 {
138 }
139 
140 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Block Telemarketers with Special Information Tone");
int ast_safe_sleep(struct ast_channel *chan, int ms)
Wait for a specified amount of time, looking for hangups.
Definition: channel.c:1916
Main Channel structure associated with a channel.
Definition: channel.h:742
char * str
Subscriber phone number (Malloced)
Definition: channel.h:241
#define AST_MODULE_INFO_STANDARD(keystr, desc)
Definition: module.h:396
Asterisk main include file. File version handling, generic pbx functions.
struct ast_party_caller caller
Channel Caller ID information.
Definition: channel.h:804
Support for translation of data formats. translate.c.
static int unload_module(void)
#define AST_DECLARE_APP_ARGS(name, arglist)
Declare a structure to hold an application&#39;s arguments.
Definition: app.h:572
Generic File Format Support. Should be included by clients of the file handling routines. File service providers should instead include mod_format.h.
int ast_unregister_application(const char *app)
Unregister an application.
Definition: pbx.c:7705
struct ast_party_id id
Caller party ID.
Definition: channel.h:370
General Asterisk PBX channel definitions.
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:63
Core PBX routines and definitions.
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: utils.h:663
static char * app
static struct @350 args
void * data
Definition: pbx.c:893
enum ast_channel_state _state
Definition: channel.h:839
static void parse(struct mgcp_request *req)
Definition: chan_mgcp.c:1858
static int zapateller_exec(struct ast_channel *chan, const char *data)
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...
Definition: pbx.c:10546
int ast_answer(struct ast_channel *chan)
Answer a channel.
Definition: channel.c:3086
Application convenience functions, designed to give consistent look and feel to Asterisk apps...
static int load_module(void)
#define AST_APP_ARG(name)
Define an application argument.
Definition: app.h:555
#define AST_STANDARD_APP_ARGS(args, parse)
Performs the &#39;standard&#39; argument separation process for an application.
Definition: app.h:604
int ast_tonepair(struct ast_channel *chan, int freq1, int freq2, int duration, int vol)
Definition: channel.c:7969
#define ASTERISK_GPL_KEY
The text the key() function should return.
Definition: module.h:38
Asterisk module definitions.
unsigned char valid
TRUE if the number information is valid/present.
Definition: channel.h:247
int ast_stopstream(struct ast_channel *c)
Stops a stream.
Definition: file.c:128
#define ast_register_application_xml(app, execute)
Register an application using XML documentation.
Definition: module.h:437
#define ASTERISK_FILE_VERSION(file, version)
Register/unregister a source code file with the core.
Definition: asterisk.h:180
struct ast_party_number number
Subscriber phone number.
Definition: channel.h:292