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, void *data) |
| static int | unload_module (void) |
Variables | |
| static struct ast_module_info __MODULE_INFO_SECTION | __mod_info = { __MODULE_INFO_GLOBALS .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT , .description = "Require phone number to be entered, if no CallerID sent" , .key = ASTERISK_GPL_KEY , .buildopt_sum = AST_BUILDOPT_SUM, .load = load_module, .unload = unload_module, } |
| 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 212 of file app_privacy.c.
| static void __unreg_module | ( | void | ) | [static] |
Definition at line 212 of file app_privacy.c.
| static int load_module | ( | void | ) | [static] |
Definition at line 207 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, |
| void * | data | ||
| ) | [static] |
Definition at line 83 of file app_privacy.c.
References ast_channel::_state, ast_answer(), AST_APP_ARG, AST_DECLARE_APP_ARGS, ast_exists_extension(), ast_log(), AST_PRES_UNAVAILABLE, 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::cid, ast_callerid::cid_num, ast_callerid::cid_pres, ast_channel::language, LOG_WARNING, maxretries, parse(), pbx_builtin_setvar_helper(), and phone.
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 (!ast_strlen_zero(chan->cid.cid_num)) {
ast_verb(3, "CallerID 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, "");
}
ast_set_callerid(chan, phone, "Privacy Manager", NULL);
/* Clear the unavailable presence bit so if it came in on PRI
* the caller id will now be passed out to other channels
*/
chan->cid.cid_pres &= (AST_PRES_UNAVAILABLE ^ 0xFF);
ast_verb(3, "Changed Caller*ID to '%s', callerpres to %d\n", phone, chan->cid.cid_pres);
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 202 of file app_privacy.c.
References ast_unregister_application().
{
return ast_unregister_application(app);
}
struct ast_module_info __MODULE_INFO_SECTION __mod_info = { __MODULE_INFO_GLOBALS .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT , .description = "Require phone number to be entered, if no CallerID sent" , .key = ASTERISK_GPL_KEY , .buildopt_sum = AST_BUILDOPT_SUM, .load = load_module, .unload = unload_module, } [static] |
Definition at line 212 of file app_privacy.c.
char* app = "PrivacyManager" [static] |
Definition at line 81 of file app_privacy.c.
struct ast_module_info* ast_module_info = &__mod_info [static] |
Definition at line 212 of file app_privacy.c.