#include "asterisk.h"
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "asterisk/lock.h"
#include "asterisk/file.h"
#include "asterisk/utils.h"
#include "asterisk/logger.h"
#include "asterisk/options.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.
Defines | |
#define | PRIV_CONFIG "privacy.conf" |
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 | __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT | AST_MODFLAG_BUILDSUM, .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 = "361d7bb937402d51e4658efb5b4d76e4" , .load = load_module, .unload = unload_module, } |
static char * | app = "PrivacyManager" |
static const struct ast_module_info * | ast_module_info = &__mod_info |
static char * | descrip |
static char * | synopsis = "Require phone number to be entered, if no CallerID sent" |
Definition in file app_privacy.c.
#define PRIV_CONFIG "privacy.conf" |
static void __reg_module | ( | void | ) | [static] |
Definition at line 232 of file app_privacy.c.
static void __unreg_module | ( | void | ) | [static] |
Definition at line 232 of file app_privacy.c.
static int load_module | ( | void | ) | [static] |
Definition at line 227 of file app_privacy.c.
References ast_register_application(), and privacy_exec().
00228 { 00229 return ast_register_application (app, privacy_exec, synopsis, descrip); 00230 }
static int privacy_exec | ( | struct ast_channel * | chan, | |
void * | data | |||
) | [static] |
Definition at line 78 of file app_privacy.c.
References ast_channel::_state, ast_answer(), AST_APP_ARG, ast_config_destroy(), ast_config_load(), AST_DECLARE_APP_ARGS, ast_goto_if_exists(), ast_log(), ast_module_user_add, ast_module_user_remove, ast_opt_priority_jumping, 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_variable_retrieve(), ast_verbose(), ast_waitstream(), ast_channel::cid, ast_callerid::cid_num, ast_callerid::cid_pres, ast_channel::context, ast_channel::language, LOG_WARNING, maxretries, option_verbose, parse(), pbx_builtin_setvar_helper(), phone, PRIV_CONFIG, s, and VERBOSE_PREFIX_3.
Referenced by load_module().
00079 { 00080 int res=0; 00081 int retries; 00082 int maxretries = 3; 00083 int minlength = 10; 00084 int x = 0; 00085 const char *s; 00086 char phone[30]; 00087 struct ast_module_user *u; 00088 struct ast_config *cfg = NULL; 00089 char *parse = NULL; 00090 int priority_jump = 0; 00091 AST_DECLARE_APP_ARGS(args, 00092 AST_APP_ARG(maxretries); 00093 AST_APP_ARG(minlength); 00094 AST_APP_ARG(options); 00095 ); 00096 00097 u = ast_module_user_add(chan); 00098 00099 if (!ast_strlen_zero(chan->cid.cid_num)) { 00100 if (option_verbose > 2) 00101 ast_verbose (VERBOSE_PREFIX_3 "CallerID Present: Skipping\n"); 00102 } else { 00103 /*Answer the channel if it is not already*/ 00104 if (chan->_state != AST_STATE_UP) { 00105 res = ast_answer(chan); 00106 if (res) { 00107 ast_module_user_remove(u); 00108 return -1; 00109 } 00110 } 00111 00112 if (!ast_strlen_zero(data)) { 00113 parse = ast_strdupa(data); 00114 00115 AST_STANDARD_APP_ARGS(args, parse); 00116 00117 if (args.maxretries) { 00118 if (sscanf(args.maxretries, "%30d", &x) == 1) 00119 maxretries = x; 00120 else 00121 ast_log(LOG_WARNING, "Invalid max retries argument\n"); 00122 } 00123 if (args.minlength) { 00124 if (sscanf(args.minlength, "%30d", &x) == 1) 00125 minlength = x; 00126 else 00127 ast_log(LOG_WARNING, "Invalid min length argument\n"); 00128 } 00129 if (args.options) 00130 if (strchr(args.options, 'j')) 00131 priority_jump = 1; 00132 00133 } 00134 00135 if (!x) 00136 { 00137 /*Read in the config file*/ 00138 cfg = ast_config_load(PRIV_CONFIG); 00139 00140 if (cfg && (s = ast_variable_retrieve(cfg, "general", "maxretries"))) { 00141 if (sscanf(s, "%30d", &x) == 1) 00142 maxretries = x; 00143 else 00144 ast_log(LOG_WARNING, "Invalid max retries argument\n"); 00145 } 00146 00147 if (cfg && (s = ast_variable_retrieve(cfg, "general", "minlength"))) { 00148 if (sscanf(s, "%30d", &x) == 1) 00149 minlength = x; 00150 else 00151 ast_log(LOG_WARNING, "Invalid min length argument\n"); 00152 } 00153 } 00154 00155 /*Play unidentified call*/ 00156 res = ast_safe_sleep(chan, 1000); 00157 if (!res) 00158 res = ast_streamfile(chan, "privacy-unident", chan->language); 00159 if (!res) 00160 res = ast_waitstream(chan, ""); 00161 00162 /*Ask for 10 digit number, give 3 attempts*/ 00163 for (retries = 0; retries < maxretries; retries++) { 00164 if (!res) 00165 res = ast_streamfile(chan, "privacy-prompt", chan->language); 00166 if (!res) 00167 res = ast_waitstream(chan, ""); 00168 00169 if (!res ) 00170 res = ast_readstring(chan, phone, sizeof(phone) - 1, /* digit timeout ms */ 3200, /* first digit timeout */ 5000, "#"); 00171 00172 if (res < 0) 00173 break; 00174 00175 /*Make sure we get at least digits*/ 00176 if (strlen(phone) >= minlength ) 00177 break; 00178 else { 00179 res = ast_streamfile(chan, "privacy-incorrect", chan->language); 00180 if (!res) 00181 res = ast_waitstream(chan, ""); 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 ast_set_callerid (chan, phone, "Privacy Manager", NULL); 00192 00193 /* Clear the unavailable presence bit so if it came in on PRI 00194 * the caller id will now be passed out to other channels 00195 */ 00196 chan->cid.cid_pres &= (AST_PRES_UNAVAILABLE ^ 0xFF); 00197 00198 if (option_verbose > 2) { 00199 ast_verbose (VERBOSE_PREFIX_3 "Changed Caller*ID to %s, callerpres to %d\n",phone,chan->cid.cid_pres); 00200 } 00201 pbx_builtin_setvar_helper(chan, "PRIVACYMGRSTATUS", "SUCCESS"); 00202 } else { 00203 if (priority_jump || ast_opt_priority_jumping) 00204 ast_goto_if_exists(chan, chan->context, chan->exten, chan->priority + 101); 00205 pbx_builtin_setvar_helper(chan, "PRIVACYMGRSTATUS", "FAILED"); 00206 } 00207 if (cfg) 00208 ast_config_destroy(cfg); 00209 } 00210 00211 ast_module_user_remove(u); 00212 00213 return 0; 00214 }
static int unload_module | ( | void | ) | [static] |
Definition at line 216 of file app_privacy.c.
References ast_module_user_hangup_all, and ast_unregister_application().
00217 { 00218 int res; 00219 00220 res = ast_unregister_application (app); 00221 00222 ast_module_user_hangup_all(); 00223 00224 return res; 00225 }
struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT | AST_MODFLAG_BUILDSUM, .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 = "361d7bb937402d51e4658efb5b4d76e4" , .load = load_module, .unload = unload_module, } [static] |
Definition at line 232 of file app_privacy.c.
char* app = "PrivacyManager" [static] |
Definition at line 52 of file app_privacy.c.
const struct ast_module_info* ast_module_info = &__mod_info [static] |
Definition at line 232 of file app_privacy.c.
char* descrip [static] |
Definition at line 56 of file app_privacy.c.
Definition at line 54 of file app_privacy.c.