#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "asterisk.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"
Include dependency graph for app_privacy.c:
Go to the source code of this file.
Defines | |
#define | PRIV_CONFIG "privacy.conf" |
Functions | |
char * | description (void) |
Provides a description of the module. | |
char * | key () |
Returns the ASTERISK_GPL_KEY. | |
int | load_module (void) |
Initialize the module. | |
static int | privacy_exec (struct ast_channel *chan, void *data) |
int | unload_module (void) |
Cleanup all module structures, sockets, etc. | |
int | usecount (void) |
Provides a usecount. | |
Variables | |
static char * | app = "PrivacyManager" |
static char * | descrip |
LOCAL_USER_DECL | |
STANDARD_LOCAL_USER | |
static char * | synopsis = "Require phone number to be entered, if no CallerID sent" |
static char * | tdesc = "Require phone number to be entered, if no CallerID sent" |
Definition in file app_privacy.c.
|
Definition at line 48 of file app_privacy.c. Referenced by privacy_exec(). |
|
Provides a description of the module.
Definition at line 237 of file app_privacy.c. References tdesc. 00238 { 00239 return tdesc; 00240 }
|
|
Returns the ASTERISK_GPL_KEY. This returns the ASTERISK_GPL_KEY, signifiying that you agree to the terms of the GPL stated in the ASTERISK_GPL_KEY. Your module will not load if it does not return the EXACT message:
char *key(void) { return ASTERISK_GPL_KEY; }
Definition at line 251 of file app_privacy.c. References ASTERISK_GPL_KEY. 00252 { 00253 return ASTERISK_GPL_KEY; 00254 }
|
|
Initialize the module. Initialize the Agents module. This function is being called by Asterisk when loading the module. Among other thing it registers applications, cli commands and reads the cofiguration file.
Definition at line 230 of file app_privacy.c. References app, ast_register_application(), descrip, privacy_exec(), and synopsis. 00231 { 00232 return ast_register_application (app, privacy_exec, synopsis, 00233 descrip); 00234 }
|
|
Definition at line 83 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_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(), cfg, ast_channel::cid, ast_callerid::cid_num, ast_channel::context, ast_channel::language, LOCAL_USER_ADD, LOCAL_USER_REMOVE, LOG_ERROR, LOG_WARNING, maxretries, option_priority_jumping, option_verbose, parse(), pbx_builtin_setvar_helper(), phone, PRIV_CONFIG, s, and VERBOSE_PREFIX_3. 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 *s; 00091 char phone[30]; 00092 struct localuser *u; 00093 struct ast_config *cfg = NULL; 00094 char *parse = NULL; 00095 int priority_jump = 0; 00096 AST_DECLARE_APP_ARGS(args, 00097 AST_APP_ARG(maxretries); 00098 AST_APP_ARG(minlength); 00099 AST_APP_ARG(options); 00100 ); 00101 00102 LOCAL_USER_ADD (u); 00103 if (!ast_strlen_zero(chan->cid.cid_num)) { 00104 if (option_verbose > 2) 00105 ast_verbose (VERBOSE_PREFIX_3 "CallerID Present: Skipping\n"); 00106 } else { 00107 /*Answer the channel if it is not already*/ 00108 if (chan->_state != AST_STATE_UP) { 00109 res = ast_answer(chan); 00110 if (res) { 00111 LOCAL_USER_REMOVE(u); 00112 return -1; 00113 } 00114 } 00115 00116 if (!ast_strlen_zero((char *)data)) 00117 { 00118 parse = ast_strdupa(data); 00119 if (!parse) { 00120 ast_log(LOG_ERROR, "Out of memory!\n"); 00121 LOCAL_USER_REMOVE(u); 00122 return -1; 00123 } 00124 00125 AST_STANDARD_APP_ARGS(args, parse); 00126 00127 if (args.maxretries) { 00128 if (sscanf(args.maxretries, "%d", &x) == 1) 00129 maxretries = x; 00130 else 00131 ast_log(LOG_WARNING, "Invalid max retries argument\n"); 00132 } 00133 if (args.minlength) { 00134 if (sscanf(args.minlength, "%d", &x) == 1) 00135 minlength = x; 00136 else 00137 ast_log(LOG_WARNING, "Invalid min length argument\n"); 00138 } 00139 if (args.options) 00140 if (strchr(args.options, 'j')) 00141 priority_jump = 1; 00142 00143 } 00144 00145 if (!x) 00146 { 00147 /*Read in the config file*/ 00148 cfg = ast_config_load(PRIV_CONFIG); 00149 00150 if (cfg && (s = ast_variable_retrieve(cfg, "general", "maxretries"))) { 00151 if (sscanf(s, "%d", &x) == 1) 00152 maxretries = x; 00153 else 00154 ast_log(LOG_WARNING, "Invalid max retries argument\n"); 00155 } 00156 00157 if (cfg && (s = ast_variable_retrieve(cfg, "general", "minlength"))) { 00158 if (sscanf(s, "%d", &x) == 1) 00159 minlength = x; 00160 else 00161 ast_log(LOG_WARNING, "Invalid min length argument\n"); 00162 } 00163 } 00164 00165 /*Play unidentified call*/ 00166 res = ast_safe_sleep(chan, 1000); 00167 if (!res) 00168 res = ast_streamfile(chan, "privacy-unident", chan->language); 00169 if (!res) 00170 res = ast_waitstream(chan, ""); 00171 00172 /*Ask for 10 digit number, give 3 attempts*/ 00173 for (retries = 0; retries < maxretries; retries++) { 00174 if (!res) 00175 res = ast_streamfile(chan, "privacy-prompt", chan->language); 00176 if (!res) 00177 res = ast_waitstream(chan, ""); 00178 00179 if (!res ) 00180 res = ast_readstring(chan, phone, sizeof(phone) - 1, /* digit timeout ms */ 3200, /* first digit timeout */ 5000, "#"); 00181 00182 if (res < 0) 00183 break; 00184 00185 /*Make sure we get at least digits*/ 00186 if (strlen(phone) >= minlength ) 00187 break; 00188 else { 00189 res = ast_streamfile(chan, "privacy-incorrect", chan->language); 00190 if (!res) 00191 res = ast_waitstream(chan, ""); 00192 } 00193 } 00194 00195 /*Got a number, play sounds and send them on their way*/ 00196 if ((retries < maxretries) && !res ) { 00197 res = ast_streamfile(chan, "privacy-thankyou", chan->language); 00198 if (!res) 00199 res = ast_waitstream(chan, ""); 00200 ast_set_callerid (chan, phone, "Privacy Manager", NULL); 00201 if (option_verbose > 2) 00202 ast_verbose (VERBOSE_PREFIX_3 "Changed Caller*ID to %s\n",phone); 00203 pbx_builtin_setvar_helper(chan, "PRIVACYMGRSTATUS", "SUCCESS"); 00204 } else { 00205 if (priority_jump || option_priority_jumping) 00206 ast_goto_if_exists(chan, chan->context, chan->exten, chan->priority + 101); 00207 pbx_builtin_setvar_helper(chan, "PRIVACYMGRSTATUS", "FAILED"); 00208 } 00209 if (cfg) 00210 ast_config_destroy(cfg); 00211 } 00212 00213 LOCAL_USER_REMOVE (u); 00214 return 0; 00215 }
|
|
Cleanup all module structures, sockets, etc. This is called at exit. Any registrations and memory allocations need to be unregistered and free'd here. Nothing else will do these for you (until exit).
Definition at line 218 of file app_privacy.c. References app, ast_unregister_application(), and STANDARD_HANGUP_LOCALUSERS. 00219 { 00220 int res; 00221 00222 res = ast_unregister_application (app); 00223 00224 STANDARD_HANGUP_LOCALUSERS; 00225 00226 return res; 00227 }
|
|
Provides a usecount. This function will be called by various parts of asterisk. Basically, all it has to do is to return a usecount when called. You will need to maintain your usecount within the module somewhere. The usecount should be how many channels provided by this module are in use.
Definition at line 243 of file app_privacy.c. References STANDARD_USECOUNT. 00244 { 00245 int res; 00246 STANDARD_USECOUNT (res); 00247 return res; 00248 }
|
|
Definition at line 52 of file app_privacy.c. |
|
Definition at line 56 of file app_privacy.c. |
|
Definition at line 79 of file app_privacy.c. |
|
Definition at line 77 of file app_privacy.c. |
|
Definition at line 54 of file app_privacy.c. |
|
Definition at line 50 of file app_privacy.c. |