Fri Nov 12 11:50:57 2010

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 "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"
Include dependency graph for app_privacy.c:

Go to the source code of this file.

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 , .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 = "0901e4e500243c855563a2d78b0c03e4" , .load = load_module, .unload = unload_module, }
static char * app = "PrivacyManager"
static struct ast_module_infoast_module_info = &__mod_info

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.


Function Documentation

static void __reg_module ( void   )  [static]

Definition at line 203 of file app_privacy.c.

static void __unreg_module ( void   )  [static]

Definition at line 203 of file app_privacy.c.

static int load_module ( void   )  [static]

Definition at line 198 of file app_privacy.c.

References ast_register_application_xml, and privacy_exec().

00199 {
00200    return ast_register_application_xml(app, privacy_exec);
00201 }

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_streamfile(), ast_strlen_zero(), ast_verb, ast_waitstream(), ast_channel::cid, ast_callerid::cid_num, ast_callerid::cid_pres, ast_channel::language, LOG_WARNING, maxretries, parse(), pbx_builtin_setvar_helper(), and phone.

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       if (!ast_strlen_zero(data)) {
00109          parse = ast_strdupa(data);
00110          
00111          AST_STANDARD_APP_ARGS(args, parse);
00112 
00113          if (args.maxretries) {
00114             if (sscanf(args.maxretries, "%30d", &x) == 1)
00115                maxretries = x;
00116             else
00117                ast_log(LOG_WARNING, "Invalid max retries argument\n");
00118          }
00119          if (args.minlength) {
00120             if (sscanf(args.minlength, "%30d", &x) == 1)
00121                minlength = x;
00122             else
00123                ast_log(LOG_WARNING, "Invalid min length argument\n");
00124          }
00125       }     
00126 
00127       /* Play unidentified call */
00128       res = ast_safe_sleep(chan, 1000);
00129       if (!res)
00130          res = ast_streamfile(chan, "privacy-unident", chan->language);
00131       if (!res)
00132          res = ast_waitstream(chan, "");
00133 
00134       /* Ask for 10 digit number, give 3 attempts */
00135       for (retries = 0; retries < maxretries; retries++) {
00136          if (!res)
00137             res = ast_streamfile(chan, "privacy-prompt", chan->language);
00138          if (!res)
00139             res = ast_waitstream(chan, "");
00140 
00141          if (!res ) 
00142             res = ast_readstring(chan, phone, sizeof(phone) - 1, /* digit timeout ms */ 3200, /* first digit timeout */ 5000, "#");
00143 
00144          if (res < 0)
00145             break;
00146 
00147          /* Make sure we get at least digits */
00148          if (strlen(phone) >= minlength ) {
00149             /* if we have a checkcontext argument, do pattern matching */
00150             if (!ast_strlen_zero(args.checkcontext)) {
00151                if (!ast_exists_extension(NULL, args.checkcontext, phone, 1, NULL)) {
00152                   res = ast_streamfile(chan, "privacy-incorrect", chan->language);
00153                   if (!res) {
00154                      res = ast_waitstream(chan, "");
00155                   }
00156                } else {
00157                   break;
00158                }
00159             } else {
00160                break;
00161             }
00162          } else {
00163             res = ast_streamfile(chan, "privacy-incorrect", chan->language);
00164             if (!res)
00165                res = ast_waitstream(chan, "");
00166          }
00167       }
00168       
00169       /* Got a number, play sounds and send them on their way */
00170       if ((retries < maxretries) && res >= 0 ) {
00171          res = ast_streamfile(chan, "privacy-thankyou", chan->language);
00172          if (!res)
00173             res = ast_waitstream(chan, "");
00174 
00175          ast_set_callerid (chan, phone, "Privacy Manager", NULL); 
00176 
00177          /* Clear the unavailable presence bit so if it came in on PRI
00178           * the caller id will now be passed out to other channels
00179           */
00180          chan->cid.cid_pres &= (AST_PRES_UNAVAILABLE ^ 0xFF);
00181 
00182          ast_verb(3, "Changed Caller*ID to %s, callerpres to %d\n",phone,chan->cid.cid_pres);
00183 
00184          pbx_builtin_setvar_helper(chan, "PRIVACYMGRSTATUS", "SUCCESS");
00185       } else {
00186          pbx_builtin_setvar_helper(chan, "PRIVACYMGRSTATUS", "FAILED");
00187       }
00188    }
00189 
00190    return 0;
00191 }

static int unload_module ( void   )  [static]

Definition at line 193 of file app_privacy.c.

References ast_unregister_application().

00194 {
00195    return ast_unregister_application (app);
00196 }


Variable Documentation

struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT , .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 = "0901e4e500243c855563a2d78b0c03e4" , .load = load_module, .unload = unload_module, } [static]

Definition at line 203 of file app_privacy.c.

char* app = "PrivacyManager" [static]

Definition at line 81 of file app_privacy.c.

Definition at line 203 of file app_privacy.c.


Generated by  doxygen 1.6.2