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, void *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 207 of file app_privacy.c.
References ast_register_application_xml, and privacy_exec().
00208 { 00209 return ast_register_application_xml(app, privacy_exec); 00210 }
| 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, LOG_WARNING, maxretries, parse(), pbx_builtin_setvar_helper(), phone, and S_OR.
Referenced by load_module().
00084 { 00085 int res=0; 00086 int retries; 00087 int maxretries = 3; 00088 int minlength = 10; 00089 int x = 0; 00090 char phone[30]; 00091 char *parse = NULL; 00092 AST_DECLARE_APP_ARGS(args, 00093 AST_APP_ARG(maxretries); 00094 AST_APP_ARG(minlength); 00095 AST_APP_ARG(options); 00096 AST_APP_ARG(checkcontext); 00097 ); 00098 00099 if (!ast_strlen_zero(chan->cid.cid_num)) { 00100 ast_verb(3, "CallerID Present: Skipping\n"); 00101 } else { 00102 /*Answer the channel if it is not already*/ 00103 if (chan->_state != AST_STATE_UP) { 00104 if ((res = ast_answer(chan))) { 00105 return -1; 00106 } 00107 } 00108 00109 parse = ast_strdupa(S_OR(data, "")); 00110 00111 AST_STANDARD_APP_ARGS(args, parse); 00112 00113 if (!ast_strlen_zero(args.maxretries)) { 00114 if (sscanf(args.maxretries, "%30d", &x) == 1 && x > 0) { 00115 maxretries = x; 00116 } else { 00117 ast_log(LOG_WARNING, "Invalid max retries argument: '%s'\n", args.maxretries); 00118 } 00119 } 00120 if (!ast_strlen_zero(args.minlength)) { 00121 if (sscanf(args.minlength, "%30d", &x) == 1 && x > 0) { 00122 minlength = x; 00123 } else { 00124 ast_log(LOG_WARNING, "Invalid min length argument: '%s'\n", args.minlength); 00125 } 00126 } 00127 00128 /* Play unidentified call */ 00129 res = ast_safe_sleep(chan, 1000); 00130 if (!res) { 00131 res = ast_streamfile(chan, "privacy-unident", chan->language); 00132 } 00133 if (!res) { 00134 res = ast_waitstream(chan, ""); 00135 } 00136 00137 /* Ask for 10 digit number, give 3 attempts */ 00138 for (retries = 0; retries < maxretries; retries++) { 00139 if (!res) { 00140 res = ast_streamfile(chan, "privacy-prompt", chan->language); 00141 } 00142 if (!res) { 00143 res = ast_waitstream(chan, ""); 00144 } 00145 00146 if (!res) { 00147 res = ast_readstring(chan, phone, sizeof(phone) - 1, /* digit timeout ms */ 3200, /* first digit timeout */ 5000, "#"); 00148 } 00149 00150 if (res < 0) { 00151 break; 00152 } 00153 00154 /* Make sure we get at least digits */ 00155 if (strlen(phone) >= minlength ) { 00156 /* if we have a checkcontext argument, do pattern matching */ 00157 if (!ast_strlen_zero(args.checkcontext)) { 00158 if (!ast_exists_extension(NULL, args.checkcontext, phone, 1, NULL)) { 00159 res = ast_streamfile(chan, "privacy-incorrect", chan->language); 00160 if (!res) { 00161 res = ast_waitstream(chan, ""); 00162 } 00163 } else { 00164 break; 00165 } 00166 } else { 00167 break; 00168 } 00169 } else { 00170 res = ast_streamfile(chan, "privacy-incorrect", chan->language); 00171 if (!res) { 00172 res = ast_waitstream(chan, ""); 00173 } 00174 } 00175 } 00176 00177 /* Got a number, play sounds and send them on their way */ 00178 if ((retries < maxretries) && res >= 0) { 00179 res = ast_streamfile(chan, "privacy-thankyou", chan->language); 00180 if (!res) { 00181 res = ast_waitstream(chan, ""); 00182 } 00183 00184 ast_set_callerid(chan, phone, "Privacy Manager", NULL); 00185 00186 /* Clear the unavailable presence bit so if it came in on PRI 00187 * the caller id will now be passed out to other channels 00188 */ 00189 chan->cid.cid_pres &= (AST_PRES_UNAVAILABLE ^ 0xFF); 00190 00191 ast_verb(3, "Changed Caller*ID to '%s', callerpres to %d\n", phone, chan->cid.cid_pres); 00192 00193 pbx_builtin_setvar_helper(chan, "PRIVACYMGRSTATUS", "SUCCESS"); 00194 } else { 00195 pbx_builtin_setvar_helper(chan, "PRIVACYMGRSTATUS", "FAILED"); 00196 } 00197 } 00198 00199 return 0; 00200 }
| static int unload_module | ( | void | ) | [static] |
Definition at line 202 of file app_privacy.c.
References ast_unregister_application().
00203 { 00204 return ast_unregister_application(app); 00205 }
char* app = "PrivacyManager" [static] |
Definition at line 81 of file app_privacy.c.
1.6.1