Mon Jun 27 16:50:59 2011

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"

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, const char *data)
static int unload_module (void)

Variables

static struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .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 = "8586c2a7d357cb591cc3a6607a8f62d1" , .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, }
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 218 of file app_privacy.c.

static void __unreg_module ( void   )  [static]

Definition at line 218 of file app_privacy.c.

static int load_module ( void   )  [static]

Definition at line 213 of file app_privacy.c.

References ast_register_application_xml, and privacy_exec().

00214 {
00215    return ast_register_application_xml(app, privacy_exec);
00216 }

static int privacy_exec ( struct ast_channel chan,
const char *  data 
) [static]

Definition at line 83 of file app_privacy.c.

References ast_channel::_state, args, ast_answer(), AST_APP_ARG, AST_DECLARE_APP_ARGS, ast_exists_extension(), ast_log(), ast_readstring(), ast_safe_sleep(), AST_STANDARD_APP_ARGS, AST_STATE_UP, ast_strdupa, ast_streamfile(), ast_strlen_zero(), ast_verb, ast_waitstream(), ast_channel::caller, ast_party_caller::id, ast_channel::language, LOG_WARNING, maxretries, ast_party_id::number, parse(), phone, ast_party_number::str, and ast_party_number::valid.

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 (chan->caller.id.number.valid
00100       && !ast_strlen_zero(chan->caller.id.number.str)) {
00101       ast_verb(3, "CallerID number present: Skipping\n");
00102    } else {
00103       /*Answer the channel if it is not already*/
00104       if (chan->_state != AST_STATE_UP) {
00105          if ((res = ast_answer(chan))) {
00106             return -1;
00107          }
00108       }
00109 
00110       parse = ast_strdupa(data);
00111 
00112       AST_STANDARD_APP_ARGS(args, parse);
00113 
00114       if (!ast_strlen_zero(args.maxretries)) {
00115          if (sscanf(args.maxretries, "%30d", &x) == 1 && x > 0) {
00116             maxretries = x;
00117          } else {
00118             ast_log(LOG_WARNING, "Invalid max retries argument: '%s'\n", args.maxretries);
00119          }
00120       }
00121       if (!ast_strlen_zero(args.minlength)) {
00122          if (sscanf(args.minlength, "%30d", &x) == 1 && x > 0) {
00123             minlength = x;
00124          } else {
00125             ast_log(LOG_WARNING, "Invalid min length argument: '%s'\n", args.minlength);
00126          }
00127       }
00128 
00129       /* Play unidentified call */
00130       res = ast_safe_sleep(chan, 1000);
00131       if (!res) {
00132          res = ast_streamfile(chan, "privacy-unident", chan->language);
00133       }
00134       if (!res) {
00135          res = ast_waitstream(chan, "");
00136       }
00137 
00138       /* Ask for 10 digit number, give 3 attempts */
00139       for (retries = 0; retries < maxretries; retries++) {
00140          if (!res) {
00141             res = ast_streamfile(chan, "privacy-prompt", chan->language);
00142          }
00143          if (!res) {
00144             res = ast_waitstream(chan, "");
00145          }
00146 
00147          if (!res) {
00148             res = ast_readstring(chan, phone, sizeof(phone) - 1, /* digit timeout ms */ 3200, /* first digit timeout */ 5000, "#");
00149          }
00150 
00151          if (res < 0) {
00152             break;
00153          }
00154 
00155          /* Make sure we get at least digits */
00156          if (strlen(phone) >= minlength ) {
00157             /* if we have a checkcontext argument, do pattern matching */
00158             if (!ast_strlen_zero(args.checkcontext)) {
00159                if (!ast_exists_extension(NULL, args.checkcontext, phone, 1, NULL)) {
00160                   res = ast_streamfile(chan, "privacy-incorrect", chan->language);
00161                   if (!res) {
00162                      res = ast_waitstream(chan, "");
00163                   }
00164                } else {
00165                   break;
00166                }
00167             } else {
00168                break;
00169             }
00170          } else {
00171             res = ast_streamfile(chan, "privacy-incorrect", chan->language);
00172             if (!res) {
00173                res = ast_waitstream(chan, "");
00174             }
00175          }
00176       }
00177 
00178       /* Got a number, play sounds and send them on their way */
00179       if ((retries < maxretries) && res >= 0) {
00180          res = ast_streamfile(chan, "privacy-thankyou", chan->language);
00181          if (!res) {
00182             res = ast_waitstream(chan, "");
00183          }
00184 
00185          /*
00186           * This is a caller entered number that is going to be used locally.
00187           * Therefore, the given number presentation is allowed and should
00188           * be passed out to other channels.  This is the point of the
00189           * privacy application.
00190           */
00191          chan->caller.id.name.presentation = AST_PRES_ALLOWED_USER_NUMBER_NOT_SCREENED;
00192          chan->caller.id.number.presentation = AST_PRES_ALLOWED_USER_NUMBER_NOT_SCREENED;
00193          chan->caller.id.number.plan = 0;/* Unknown */
00194 
00195          ast_set_callerid(chan, phone, "Privacy Manager", NULL);
00196 
00197          ast_verb(3, "Changed Caller*ID number to '%s'\n", phone);
00198 
00199          pbx_builtin_setvar_helper(chan, "PRIVACYMGRSTATUS", "SUCCESS");
00200       } else {
00201          pbx_builtin_setvar_helper(chan, "PRIVACYMGRSTATUS", "FAILED");
00202       }
00203    }
00204 
00205    return 0;
00206 }

static int unload_module ( void   )  [static]

Definition at line 208 of file app_privacy.c.

References ast_unregister_application().

00209 {
00210    return ast_unregister_application(app);
00211 }


Variable Documentation

struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .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 = "8586c2a7d357cb591cc3a6607a8f62d1" , .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, } [static]

Definition at line 218 of file app_privacy.c.

char* app = "PrivacyManager" [static]

Definition at line 81 of file app_privacy.c.

struct ast_module_info* ast_module_info = &__mod_info [static]

Definition at line 218 of file app_privacy.c.


Generated on Mon Jun 27 16:50:59 2011 for Asterisk - The Open Source Telephony Project by  doxygen 1.4.7