00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #include "asterisk.h"
00029
00030 ASTERISK_FILE_VERSION(__FILE__, "$Revision: 102525 $")
00031
00032 #include "asterisk/lock.h"
00033 #include "asterisk/file.h"
00034 #include "asterisk/utils.h"
00035 #include "asterisk/channel.h"
00036 #include "asterisk/pbx.h"
00037 #include "asterisk/module.h"
00038 #include "asterisk/translate.h"
00039 #include "asterisk/image.h"
00040 #include "asterisk/callerid.h"
00041 #include "asterisk/app.h"
00042 #include "asterisk/config.h"
00043
00044 static char *app = "PrivacyManager";
00045
00046 static char *synopsis = "Require phone number to be entered, if no CallerID sent";
00047
00048 static char *descrip =
00049 " PrivacyManager([maxretries][,minlength]): If no Caller*ID \n"
00050 "is sent, PrivacyManager answers the channel and asks the caller to\n"
00051 "enter their phone number. The caller is given 'maxretries' attempts to do so.\n"
00052 "The application does nothing if Caller*ID was received on the channel.\n"
00053 " maxretries default 3 -maximum number of attempts the caller is allowed \n"
00054 " to input a callerid.\n"
00055 " minlength default 10 -minimum allowable digits in the input callerid number.\n"
00056 "The application sets the following channel variable upon completion: \n"
00057 "PRIVACYMGRSTATUS The status of the privacy manager's attempt to collect \n"
00058 " a phone number from the user. A text string that is either:\n"
00059 " SUCCESS | FAILED \n"
00060 ;
00061
00062
00063 static int privacy_exec (struct ast_channel *chan, void *data)
00064 {
00065 int res=0;
00066 int retries;
00067 int maxretries = 3;
00068 int minlength = 10;
00069 int x = 0;
00070 char phone[30];
00071 char *parse = NULL;
00072 AST_DECLARE_APP_ARGS(args,
00073 AST_APP_ARG(maxretries);
00074 AST_APP_ARG(minlength);
00075 AST_APP_ARG(options);
00076 );
00077
00078 if (!ast_strlen_zero(chan->cid.cid_num)) {
00079 ast_verb(3, "CallerID Present: Skipping\n");
00080 } else {
00081
00082 if (chan->_state != AST_STATE_UP) {
00083 if ((res = ast_answer(chan)))
00084 return -1;
00085 }
00086
00087 if (!ast_strlen_zero(data)) {
00088 parse = ast_strdupa(data);
00089
00090 AST_STANDARD_APP_ARGS(args, parse);
00091
00092 if (args.maxretries) {
00093 if (sscanf(args.maxretries, "%d", &x) == 1)
00094 maxretries = x;
00095 else
00096 ast_log(LOG_WARNING, "Invalid max retries argument\n");
00097 }
00098 if (args.minlength) {
00099 if (sscanf(args.minlength, "%d", &x) == 1)
00100 minlength = x;
00101 else
00102 ast_log(LOG_WARNING, "Invalid min length argument\n");
00103 }
00104
00105 }
00106
00107
00108 res = ast_safe_sleep(chan, 1000);
00109 if (!res)
00110 res = ast_streamfile(chan, "privacy-unident", chan->language);
00111 if (!res)
00112 res = ast_waitstream(chan, "");
00113
00114
00115 for (retries = 0; retries < maxretries; retries++) {
00116 if (!res)
00117 res = ast_streamfile(chan, "privacy-prompt", chan->language);
00118 if (!res)
00119 res = ast_waitstream(chan, "");
00120
00121 if (!res )
00122 res = ast_readstring(chan, phone, sizeof(phone) - 1, 3200, 5000, "#");
00123
00124 if (res < 0)
00125 break;
00126
00127
00128 if (strlen(phone) >= minlength )
00129 break;
00130 else {
00131 res = ast_streamfile(chan, "privacy-incorrect", chan->language);
00132 if (!res)
00133 res = ast_waitstream(chan, "");
00134 }
00135 }
00136
00137
00138 if ((retries < maxretries) && res >= 0 ) {
00139 res = ast_streamfile(chan, "privacy-thankyou", chan->language);
00140 if (!res)
00141 res = ast_waitstream(chan, "");
00142
00143 ast_set_callerid (chan, phone, "Privacy Manager", NULL);
00144
00145
00146
00147
00148 chan->cid.cid_pres &= (AST_PRES_UNAVAILABLE ^ 0xFF);
00149
00150 ast_verb(3, "Changed Caller*ID to %s, callerpres to %d\n",phone,chan->cid.cid_pres);
00151
00152 pbx_builtin_setvar_helper(chan, "PRIVACYMGRSTATUS", "SUCCESS");
00153 } else {
00154 pbx_builtin_setvar_helper(chan, "PRIVACYMGRSTATUS", "FAILED");
00155 }
00156 }
00157
00158 return 0;
00159 }
00160
00161 static int unload_module(void)
00162 {
00163 return ast_unregister_application (app);
00164 }
00165
00166 static int load_module(void)
00167 {
00168 return ast_register_application(app, privacy_exec, synopsis, descrip);
00169 }
00170
00171 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Require phone number to be entered, if no CallerID sent");