Mon May 14 04:44:12 2007

Asterisk developer's documentation


app_privacy.c File Reference

Block all calls without Caller*ID, require phone # to be entered. More...

#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"

Include dependency graph for app_privacy.c:

Go to the source code of this file.

Defines

#define PRIV_CONFIG   "privacy.conf"

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"
static char * descrip
static char * synopsis = "Require phone number to be entered, if no CallerID sent"


Detailed Description

Block all calls without Caller*ID, require phone # to be entered.

Author:
Mark Spencer <markster@digium.com>

Definition in file app_privacy.c.


Define Documentation

#define PRIV_CONFIG   "privacy.conf"

Definition at line 50 of file app_privacy.c.

Referenced by privacy_exec().


Function Documentation

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 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, 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, "%d", &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, "%d", &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, "%d", &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, "%d", &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 }


Variable Documentation

char* app = "PrivacyManager" [static]

Definition at line 52 of file app_privacy.c.

char* descrip [static]

Definition at line 56 of file app_privacy.c.

char* synopsis = "Require phone number to be entered, if no CallerID sent" [static]

Definition at line 54 of file app_privacy.c.


Generated on Mon May 14 04:44:13 2007 for Asterisk - the Open Source PBX by  doxygen 1.5.1