#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 245 of file app_privacy.c. References tdesc. 00246 {
00247 return tdesc;
00248 }
|
|
|
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 259 of file app_privacy.c. References ASTERISK_GPL_KEY. 00260 {
00261 return ASTERISK_GPL_KEY;
00262 }
|
|
|
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 238 of file app_privacy.c. References app, ast_register_application(), descrip, privacy_exec(), and synopsis. 00239 {
00240 return ast_register_application (app, privacy_exec, synopsis,
00241 descrip);
00242 }
|
|
||||||||||||
|
Definition at line 83 of file app_privacy.c. References ast_channel::_state, ast_answer(), AST_APP_ARG, ast_config_load(), AST_DECLARE_APP_ARGS, 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_variable_retrieve(), ast_verbose(), ast_waitstream(), cfg, ast_channel::cid, ast_callerid::cid_num, ast_channel::language, LOCAL_USER_ADD, LOCAL_USER_REMOVE, LOG_ERROR, LOG_WARNING, maxretries, 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 >= 0 ) {
00197 res = ast_streamfile(chan, "privacy-thankyou", chan->language);
00198 if (!res)
00199 res = ast_waitstream(chan, "");
00200
00201 ast_set_callerid (chan, phone, "Privacy Manager", NULL);
00202
00203 /* Clear the unavailable presence bit so if it came in on PRI
00204 * the caller id will now be passed out to other channels
00205 */
00206 chan->cid.cid_pres &= (AST_PRES_UNAVAILABLE ^ 0xFF);
00207
00208 if (option_verbose > 2) {
00209 ast_verbose (VERBOSE_PREFIX_3 "Changed Caller*ID to %s, callerpres to %d\n",phone,chan->cid.cid_pres);
00210 }
00211 pbx_builtin_setvar_helper(chan, "PRIVACYMGRSTATUS", "SUCCESS");
00212 } else {
00213 if (priority_jump || option_priority_jumping)
00214 ast_goto_if_exists(chan, chan->context, chan->exten, chan->priority + 101);
00215 pbx_builtin_setvar_helper(chan, "PRIVACYMGRSTATUS", "FAILED");
00216 }
00217 if (cfg)
00218 ast_config_destroy(cfg);
00219 }
00220
00221 LOCAL_USER_REMOVE (u);
00222 return 0;
00223 }
|
|
|
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 226 of file app_privacy.c. References app, ast_unregister_application(), and STANDARD_HANGUP_LOCALUSERS. 00227 {
00228 int res;
00229
00230 res = ast_unregister_application (app);
00231
00232 STANDARD_HANGUP_LOCALUSERS;
00233
00234 return res;
00235 }
|
|
|
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 251 of file app_privacy.c. References STANDARD_USECOUNT. 00252 {
00253 int res;
00254 STANDARD_USECOUNT (res);
00255 return res;
00256 }
|
|
|
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. |
1.4.2