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: 211580 $")
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
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081 static char *app = "PrivacyManager";
00082
00083 static int privacy_exec (struct ast_channel *chan, void *data)
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
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
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
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, 3200, 5000, "#");
00143
00144 if (res < 0)
00145 break;
00146
00147
00148 if (strlen(phone) >= minlength ) {
00149
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
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
00178
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 }
00192
00193 static int unload_module(void)
00194 {
00195 return ast_unregister_application (app);
00196 }
00197
00198 static int load_module(void)
00199 {
00200 return ast_register_application_xml(app, privacy_exec);
00201 }
00202
00203 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Require phone number to be entered, if no CallerID sent");