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 | |
AST_MODULE_INFO_STANDARD (ASTERISK_GPL_KEY,"Require phone number to be entered, if no CallerID sent") | |
static int | load_module (void) |
static int | privacy_exec (struct ast_channel *chan, const char *data) |
static int | unload_module (void) |
Variables | |
static char * | app = "PrivacyManager" |
Block all calls without Caller*ID, require phone # to be entered.
Definition in file app_privacy.c.
AST_MODULE_INFO_STANDARD | ( | ASTERISK_GPL_KEY | , | |
"Require phone number to be | entered, | |||
if no CallerID sent" | ||||
) |
static int load_module | ( | void | ) | [static] |
Definition at line 220 of file app_privacy.c.
References ast_register_application_xml, and privacy_exec().
00221 { 00222 return ast_register_application_xml(app, privacy_exec); 00223 }
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, LOG_WARNING, maxretries, ast_party_id::name, ast_party_id::number, parse(), pbx_builtin_setvar_helper(), phone, ast_party_number::plan, ast_party_number::presentation, ast_party_name::presentation, ast_party_number::str, and ast_party_number::valid.
Referenced by load_module().
00091 { 00092 int res=0; 00093 int retries; 00094 int maxretries = 3; 00095 int minlength = 10; 00096 int x = 0; 00097 char phone[30]; 00098 char *parse = NULL; 00099 AST_DECLARE_APP_ARGS(args, 00100 AST_APP_ARG(maxretries); 00101 AST_APP_ARG(minlength); 00102 AST_APP_ARG(options); 00103 AST_APP_ARG(checkcontext); 00104 ); 00105 00106 if (chan->caller.id.number.valid 00107 && !ast_strlen_zero(chan->caller.id.number.str)) { 00108 ast_verb(3, "CallerID number present: Skipping\n"); 00109 } else { 00110 /*Answer the channel if it is not already*/ 00111 if (chan->_state != AST_STATE_UP) { 00112 if ((res = ast_answer(chan))) { 00113 return -1; 00114 } 00115 } 00116 00117 parse = ast_strdupa(data); 00118 00119 AST_STANDARD_APP_ARGS(args, parse); 00120 00121 if (!ast_strlen_zero(args.maxretries)) { 00122 if (sscanf(args.maxretries, "%30d", &x) == 1 && x > 0) { 00123 maxretries = x; 00124 } else { 00125 ast_log(LOG_WARNING, "Invalid max retries argument: '%s'\n", args.maxretries); 00126 } 00127 } 00128 if (!ast_strlen_zero(args.minlength)) { 00129 if (sscanf(args.minlength, "%30d", &x) == 1 && x > 0) { 00130 minlength = x; 00131 } else { 00132 ast_log(LOG_WARNING, "Invalid min length argument: '%s'\n", args.minlength); 00133 } 00134 } 00135 00136 /* Play unidentified call */ 00137 res = ast_safe_sleep(chan, 1000); 00138 if (!res) { 00139 res = ast_streamfile(chan, "privacy-unident", chan->language); 00140 } 00141 if (!res) { 00142 res = ast_waitstream(chan, ""); 00143 } 00144 00145 /* Ask for 10 digit number, give 3 attempts */ 00146 for (retries = 0; retries < maxretries; retries++) { 00147 if (!res) { 00148 res = ast_streamfile(chan, "privacy-prompt", chan->language); 00149 } 00150 if (!res) { 00151 res = ast_waitstream(chan, ""); 00152 } 00153 00154 if (!res) { 00155 res = ast_readstring(chan, phone, sizeof(phone) - 1, /* digit timeout ms */ 3200, /* first digit timeout */ 5000, "#"); 00156 } 00157 00158 if (res < 0) { 00159 break; 00160 } 00161 00162 /* Make sure we get at least digits */ 00163 if (strlen(phone) >= minlength ) { 00164 /* if we have a checkcontext argument, do pattern matching */ 00165 if (!ast_strlen_zero(args.checkcontext)) { 00166 if (!ast_exists_extension(NULL, args.checkcontext, phone, 1, NULL)) { 00167 res = ast_streamfile(chan, "privacy-incorrect", chan->language); 00168 if (!res) { 00169 res = ast_waitstream(chan, ""); 00170 } 00171 } else { 00172 break; 00173 } 00174 } else { 00175 break; 00176 } 00177 } else { 00178 res = ast_streamfile(chan, "privacy-incorrect", chan->language); 00179 if (!res) { 00180 res = ast_waitstream(chan, ""); 00181 } 00182 } 00183 } 00184 00185 /* Got a number, play sounds and send them on their way */ 00186 if ((retries < maxretries) && res >= 0) { 00187 res = ast_streamfile(chan, "privacy-thankyou", chan->language); 00188 if (!res) { 00189 res = ast_waitstream(chan, ""); 00190 } 00191 00192 /* 00193 * This is a caller entered number that is going to be used locally. 00194 * Therefore, the given number presentation is allowed and should 00195 * be passed out to other channels. This is the point of the 00196 * privacy application. 00197 */ 00198 chan->caller.id.name.presentation = AST_PRES_ALLOWED_USER_NUMBER_NOT_SCREENED; 00199 chan->caller.id.number.presentation = AST_PRES_ALLOWED_USER_NUMBER_NOT_SCREENED; 00200 chan->caller.id.number.plan = 0;/* Unknown */ 00201 00202 ast_set_callerid(chan, phone, "Privacy Manager", NULL); 00203 00204 ast_verb(3, "Changed Caller*ID number to '%s'\n", phone); 00205 00206 pbx_builtin_setvar_helper(chan, "PRIVACYMGRSTATUS", "SUCCESS"); 00207 } else { 00208 pbx_builtin_setvar_helper(chan, "PRIVACYMGRSTATUS", "FAILED"); 00209 } 00210 } 00211 00212 return 0; 00213 }
static int unload_module | ( | void | ) | [static] |
Definition at line 215 of file app_privacy.c.
References ast_unregister_application().
00216 { 00217 return ast_unregister_application(app); 00218 }
char* app = "PrivacyManager" [static] |
Definition at line 88 of file app_privacy.c.