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/image.h"#include "asterisk/callerid.h"#include "asterisk/app.h"#include "asterisk/config.h"
Go to the source code of this file.
Functions | |
| static void | __reg_module (void) |
| static void | __unreg_module (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 = AST_BUILDOPT_SUM, .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, } |
| static char * | app = "PrivacyManager" |
| static struct ast_module_info * | ast_module_info = &__mod_info |
Block all calls without Caller*ID, require phone # to be entered.
Definition in file app_privacy.c.
| static void __reg_module | ( | void | ) | [static] |
Definition at line 225 of file app_privacy.c.
| static void __unreg_module | ( | void | ) | [static] |
Definition at line 225 of file app_privacy.c.
| static int load_module | ( | void | ) | [static] |
Definition at line 220 of file app_privacy.c.
References ast_register_application_xml, and privacy_exec().
{
return ast_register_application_xml(app, privacy_exec);
}
| static int privacy_exec | ( | struct ast_channel * | chan, |
| const char * | data | ||
| ) | [static] |
Definition at line 90 of file app_privacy.c.
References ast_channel::_state, args, ast_answer(), AST_APP_ARG, 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_channel::caller, ast_party_caller::id, ast_channel::language, LOG_WARNING, maxretries, ast_party_id::name, ast_party_id::number, parse(), pbx_builtin_setvar_helper(), phone, ast_party_number::plan, ast_party_name::presentation, ast_party_number::presentation, ast_party_number::str, and ast_party_number::valid.
Referenced by load_module().
{
int res=0;
int retries;
int maxretries = 3;
int minlength = 10;
int x = 0;
char phone[30];
char *parse = NULL;
AST_DECLARE_APP_ARGS(args,
AST_APP_ARG(maxretries);
AST_APP_ARG(minlength);
AST_APP_ARG(options);
AST_APP_ARG(checkcontext);
);
if (chan->caller.id.number.valid
&& !ast_strlen_zero(chan->caller.id.number.str)) {
ast_verb(3, "CallerID number present: Skipping\n");
} else {
/*Answer the channel if it is not already*/
if (chan->_state != AST_STATE_UP) {
if ((res = ast_answer(chan))) {
return -1;
}
}
parse = ast_strdupa(data);
AST_STANDARD_APP_ARGS(args, parse);
if (!ast_strlen_zero(args.maxretries)) {
if (sscanf(args.maxretries, "%30d", &x) == 1 && x > 0) {
maxretries = x;
} else {
ast_log(LOG_WARNING, "Invalid max retries argument: '%s'\n", args.maxretries);
}
}
if (!ast_strlen_zero(args.minlength)) {
if (sscanf(args.minlength, "%30d", &x) == 1 && x > 0) {
minlength = x;
} else {
ast_log(LOG_WARNING, "Invalid min length argument: '%s'\n", args.minlength);
}
}
/* Play unidentified call */
res = ast_safe_sleep(chan, 1000);
if (!res) {
res = ast_streamfile(chan, "privacy-unident", chan->language);
}
if (!res) {
res = ast_waitstream(chan, "");
}
/* Ask for 10 digit number, give 3 attempts */
for (retries = 0; retries < maxretries; retries++) {
if (!res) {
res = ast_streamfile(chan, "privacy-prompt", chan->language);
}
if (!res) {
res = ast_waitstream(chan, "");
}
if (!res) {
res = ast_readstring(chan, phone, sizeof(phone) - 1, /* digit timeout ms */ 3200, /* first digit timeout */ 5000, "#");
}
if (res < 0) {
break;
}
/* Make sure we get at least digits */
if (strlen(phone) >= minlength ) {
/* if we have a checkcontext argument, do pattern matching */
if (!ast_strlen_zero(args.checkcontext)) {
if (!ast_exists_extension(NULL, args.checkcontext, phone, 1, NULL)) {
res = ast_streamfile(chan, "privacy-incorrect", chan->language);
if (!res) {
res = ast_waitstream(chan, "");
}
} else {
break;
}
} else {
break;
}
} else {
res = ast_streamfile(chan, "privacy-incorrect", chan->language);
if (!res) {
res = ast_waitstream(chan, "");
}
}
}
/* Got a number, play sounds and send them on their way */
if ((retries < maxretries) && res >= 0) {
res = ast_streamfile(chan, "privacy-thankyou", chan->language);
if (!res) {
res = ast_waitstream(chan, "");
}
/*
* This is a caller entered number that is going to be used locally.
* Therefore, the given number presentation is allowed and should
* be passed out to other channels. This is the point of the
* privacy application.
*/
chan->caller.id.name.presentation = AST_PRES_ALLOWED_USER_NUMBER_NOT_SCREENED;
chan->caller.id.number.presentation = AST_PRES_ALLOWED_USER_NUMBER_NOT_SCREENED;
chan->caller.id.number.plan = 0;/* Unknown */
ast_set_callerid(chan, phone, "Privacy Manager", NULL);
ast_verb(3, "Changed Caller*ID number to '%s'\n", phone);
pbx_builtin_setvar_helper(chan, "PRIVACYMGRSTATUS", "SUCCESS");
} else {
pbx_builtin_setvar_helper(chan, "PRIVACYMGRSTATUS", "FAILED");
}
}
return 0;
}
| static int unload_module | ( | void | ) | [static] |
Definition at line 215 of file app_privacy.c.
References ast_unregister_application().
{
return ast_unregister_application(app);
}
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 = AST_BUILDOPT_SUM, .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, } [static] |
Definition at line 225 of file app_privacy.c.
char* app = "PrivacyManager" [static] |
Definition at line 88 of file app_privacy.c.
struct ast_module_info* ast_module_info = &__mod_info [static] |
Definition at line 225 of file app_privacy.c.