Asterisk - The Open Source Telephony Project  18.5.0
Functions | Variables
app_privacy.c File Reference

Block all calls without Caller*ID, require phone # to be entered. More...

#include "asterisk.h"
#include "asterisk/lock.h"
#include "asterisk/file.h"
#include "asterisk/utils.h"
#include "asterisk/channel.h"
#include "asterisk/pbx.h"
#include "asterisk/module.h"
#include "asterisk/translate.h"
#include "asterisk/callerid.h"
#include "asterisk/app.h"
#include "asterisk/config.h"
Include dependency graph for app_privacy.c:

Go to the source code of this file.

Functions

static void __reg_module (void)
 
static void __unreg_module (void)
 
struct ast_moduleAST_MODULE_SELF_SYM (void)
 
static int load_module (void)
 
static int privacy_exec (struct ast_channel *chan, const char *data)
 
static int unload_module (void)
 

Variables

static struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "Require phone number to be entered, if no CallerID sent" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = "30ef0c93b36035ec78c9cfd712d36d9b" , .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, .support_level = AST_MODULE_SUPPORT_CORE, }
 
static char * app = "PrivacyManager"
 
static const struct ast_module_infoast_module_info = &__mod_info
 

Detailed Description

Block all calls without Caller*ID, require phone # to be entered.

Author
Mark Spencer marks.nosp@m.ter@.nosp@m.digiu.nosp@m.m.co.nosp@m.m

Definition in file app_privacy.c.

Function Documentation

◆ __reg_module()

static void __reg_module ( void  )
static

Definition at line 222 of file app_privacy.c.

◆ __unreg_module()

static void __unreg_module ( void  )
static

Definition at line 222 of file app_privacy.c.

◆ AST_MODULE_SELF_SYM()

struct ast_module* AST_MODULE_SELF_SYM ( void  )

Definition at line 222 of file app_privacy.c.

◆ load_module()

static int load_module ( void  )
static

Definition at line 217 of file app_privacy.c.

References app, ast_register_application_xml, and privacy_exec().

218 {
220 }
static char * app
Definition: app_privacy.c:85
static int privacy_exec(struct ast_channel *chan, const char *data)
Definition: app_privacy.c:87
#define ast_register_application_xml(app, execute)
Register an application using XML documentation.
Definition: module.h:626

◆ privacy_exec()

static int privacy_exec ( struct ast_channel chan,
const char *  data 
)
static

Definition at line 87 of file app_privacy.c.

References args, ast_answer(), AST_APP_ARG, ast_channel_caller(), ast_channel_language(), AST_DECLARE_APP_ARGS, ast_exists_extension(), ast_log, AST_PRES_ALLOWED_USER_NUMBER_NOT_SCREENED, ast_readstring(), ast_safe_sleep(), ast_set_callerid(), AST_STANDARD_APP_ARGS, AST_STATE_UP, ast_strdupa, ast_streamfile(), ast_strlen_zero, ast_verb, ast_waitstream(), ast_party_caller::id, LOG_WARNING, maxretries, ast_party_id::name, NULL, ast_party_id::number, options, parse(), pbx_builtin_setvar_helper(), phone, ast_party_number::plan, ast_party_name::presentation, ast_party_number::presentation, and ast_party_number::valid.

Referenced by load_module().

88 {
89  int res=0;
90  int retries;
91  int maxretries = 3;
92  int minlength = 10;
93  int x = 0;
94  char phone[30];
95  char *parse = NULL;
97  AST_APP_ARG(maxretries);
98  AST_APP_ARG(minlength);
100  AST_APP_ARG(checkcontext);
101  );
102 
103  if (ast_channel_caller(chan)->id.number.valid
104  && !ast_strlen_zero(ast_channel_caller(chan)->id.number.str)) {
105  ast_verb(3, "CallerID number present: Skipping\n");
106  } else {
107  /*Answer the channel if it is not already*/
108  if (ast_channel_state(chan) != AST_STATE_UP) {
109  if ((res = ast_answer(chan))) {
110  return -1;
111  }
112  }
113 
114  parse = ast_strdupa(data);
115 
116  AST_STANDARD_APP_ARGS(args, parse);
117 
118  if (!ast_strlen_zero(args.maxretries)) {
119  if (sscanf(args.maxretries, "%30d", &x) == 1 && x > 0) {
120  maxretries = x;
121  } else {
122  ast_log(LOG_WARNING, "Invalid max retries argument: '%s'\n", args.maxretries);
123  }
124  }
125  if (!ast_strlen_zero(args.minlength)) {
126  if (sscanf(args.minlength, "%30d", &x) == 1 && x > 0) {
127  minlength = x;
128  } else {
129  ast_log(LOG_WARNING, "Invalid min length argument: '%s'\n", args.minlength);
130  }
131  }
132 
133  /* Play unidentified call */
134  res = ast_safe_sleep(chan, 1000);
135  if (!res) {
136  res = ast_streamfile(chan, "privacy-unident", ast_channel_language(chan));
137  }
138  if (!res) {
139  res = ast_waitstream(chan, "");
140  }
141 
142  /* Ask for 10 digit number, give 3 attempts */
143  for (retries = 0; retries < maxretries; retries++) {
144  if (!res) {
145  res = ast_streamfile(chan, "privacy-prompt", ast_channel_language(chan));
146  }
147  if (!res) {
148  res = ast_waitstream(chan, "");
149  }
150 
151  if (!res) {
152  res = ast_readstring(chan, phone, sizeof(phone) - 1, /* digit timeout ms */ 3200, /* first digit timeout */ 5000, "#");
153  }
154 
155  if (res < 0) {
156  break;
157  }
158 
159  /* Make sure we get at least digits */
160  if (strlen(phone) >= minlength ) {
161  /* if we have a checkcontext argument, do pattern matching */
162  if (!ast_strlen_zero(args.checkcontext)) {
163  if (!ast_exists_extension(NULL, args.checkcontext, phone, 1, NULL)) {
164  res = ast_streamfile(chan, "privacy-incorrect", ast_channel_language(chan));
165  if (!res) {
166  res = ast_waitstream(chan, "");
167  }
168  } else {
169  break;
170  }
171  } else {
172  break;
173  }
174  } else {
175  res = ast_streamfile(chan, "privacy-incorrect", ast_channel_language(chan));
176  if (!res) {
177  res = ast_waitstream(chan, "");
178  }
179  }
180  }
181 
182  /* Got a number, play sounds and send them on their way */
183  if ((retries < maxretries) && res >= 0) {
184  res = ast_streamfile(chan, "privacy-thankyou", ast_channel_language(chan));
185  if (!res) {
186  res = ast_waitstream(chan, "");
187  }
188 
189  /*
190  * This is a caller entered number that is going to be used locally.
191  * Therefore, the given number presentation is allowed and should
192  * be passed out to other channels. This is the point of the
193  * privacy application.
194  */
197  ast_channel_caller(chan)->id.number.plan = 0;/* Unknown */
198 
199  ast_set_callerid(chan, phone, "Privacy Manager", NULL);
200 
201  ast_verb(3, "Changed Caller*ID number to '%s'\n", phone);
202 
203  pbx_builtin_setvar_helper(chan, "PRIVACYMGRSTATUS", "SUCCESS");
204  } else {
205  pbx_builtin_setvar_helper(chan, "PRIVACYMGRSTATUS", "FAILED");
206  }
207  }
208 
209  return 0;
210 }
struct ast_party_caller * ast_channel_caller(struct ast_channel *chan)
int ast_safe_sleep(struct ast_channel *chan, int ms)
Wait for a specified amount of time, looking for hangups.
Definition: channel.c:1574
int presentation
Q.931 encoded presentation-indicator encoded field.
Definition: channel.h:278
void ast_set_callerid(struct ast_channel *chan, const char *cid_num, const char *cid_name, const char *cid_ani)
Set caller ID number, name and ANI and generate AMI event.
Definition: channel.c:7434
int ast_streamfile(struct ast_channel *c, const char *filename, const char *preflang)
Streams a file.
Definition: file.c:1250
int presentation
Q.931 presentation-indicator and screening-indicator encoded fields.
Definition: channel.h:296
struct ast_party_name name
Subscriber name.
Definition: channel.h:341
#define AST_STANDARD_APP_ARGS(args, parse)
Performs the &#39;standard&#39; argument separation process for an application.
#define LOG_WARNING
Definition: logger.h:274
static char phone[80]
Definition: pbx_dundi.c:207
ast_channel_state
ast_channel states
Definition: channelstate.h:35
const char * args
#define NULL
Definition: resample.c:96
#define AST_PRES_ALLOWED_USER_NUMBER_NOT_SCREENED
Definition: callerid.h:329
#define ast_verb(level,...)
Definition: logger.h:463
#define ast_strlen_zero(foo)
Definition: strings.h:52
Number structure.
Definition: app_followme.c:154
struct ast_party_id id
Caller party ID.
Definition: channel.h:421
#define ast_log
Definition: astobj2.c:42
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: astmm.h:300
int ast_exists_extension(struct ast_channel *c, const char *context, const char *exten, int priority, const char *callerid)
Determine whether an extension exists.
Definition: pbx.c:4179
int plan
Q.931 Type-Of-Number and Numbering-Plan encoded fields.
Definition: channel.h:294
static int maxretries
Definition: res_adsi.c:60
static void parse(struct mgcp_request *req)
Definition: chan_mgcp.c:1872
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...
int ast_waitstream(struct ast_channel *c, const char *breakon)
Waits for a stream to stop or digit to be pressed.
Definition: file.c:1776
int ast_answer(struct ast_channel *chan)
Answer a channel.
Definition: channel.c:2814
const char * ast_channel_language(const struct ast_channel *chan)
const char * data
Description of a tone.
Definition: indications.h:52
static struct test_options options
int ast_readstring(struct ast_channel *c, char *s, int len, int timeout, int rtimeout, char *enders)
Reads multiple digits.
Definition: channel.c:6655
#define AST_DECLARE_APP_ARGS(name, arglist)
Declare a structure to hold an application&#39;s arguments.
unsigned char valid
TRUE if the number information is valid/present.
Definition: channel.h:298
#define AST_APP_ARG(name)
Define an application argument.
struct ast_party_number number
Subscriber phone number.
Definition: channel.h:343

◆ unload_module()

static int unload_module ( void  )
static

Definition at line 212 of file app_privacy.c.

References app, and ast_unregister_application().

213 {
215 }
int ast_unregister_application(const char *app)
Unregister an application.
Definition: pbx_app.c:392
static char * app
Definition: app_privacy.c:85

Variable Documentation

◆ __mod_info

struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "Require phone number to be entered, if no CallerID sent" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = "30ef0c93b36035ec78c9cfd712d36d9b" , .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, .support_level = AST_MODULE_SUPPORT_CORE, }
static

Definition at line 222 of file app_privacy.c.

◆ app

char* app = "PrivacyManager"
static

Definition at line 85 of file app_privacy.c.

Referenced by load_module(), and unload_module().

◆ ast_module_info

const struct ast_module_info* ast_module_info = &__mod_info
static

Definition at line 222 of file app_privacy.c.