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
00029
00030
00031
00032 #include "asterisk.h"
00033
00034 ASTERISK_FILE_VERSION(__FILE__, "$Revision: 328209 $")
00035
00036 #include "asterisk/lock.h"
00037 #include "asterisk/file.h"
00038 #include "asterisk/utils.h"
00039 #include "asterisk/channel.h"
00040 #include "asterisk/pbx.h"
00041 #include "asterisk/module.h"
00042 #include "asterisk/translate.h"
00043 #include "asterisk/image.h"
00044 #include "asterisk/callerid.h"
00045 #include "asterisk/app.h"
00046 #include "asterisk/config.h"
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
00082
00083
00084
00085
00086
00087
00088 static char *app = "PrivacyManager";
00089
00090 static int privacy_exec(struct ast_channel *chan, const char *data)
00091 {
00092 int res=0;
00093 int retries;
00094 int maxretries = 3;
00095 int minlength = 10;
00096 int x = 0;
00097 char phone[30];
00098 char *parse = NULL;
00099 AST_DECLARE_APP_ARGS(args,
00100 AST_APP_ARG(maxretries);
00101 AST_APP_ARG(minlength);
00102 AST_APP_ARG(options);
00103 AST_APP_ARG(checkcontext);
00104 );
00105
00106 if (chan->caller.id.number.valid
00107 && !ast_strlen_zero(chan->caller.id.number.str)) {
00108 ast_verb(3, "CallerID number present: Skipping\n");
00109 } else {
00110
00111 if (chan->_state != AST_STATE_UP) {
00112 if ((res = ast_answer(chan))) {
00113 return -1;
00114 }
00115 }
00116
00117 parse = ast_strdupa(data);
00118
00119 AST_STANDARD_APP_ARGS(args, parse);
00120
00121 if (!ast_strlen_zero(args.maxretries)) {
00122 if (sscanf(args.maxretries, "%30d", &x) == 1 && x > 0) {
00123 maxretries = x;
00124 } else {
00125 ast_log(LOG_WARNING, "Invalid max retries argument: '%s'\n", args.maxretries);
00126 }
00127 }
00128 if (!ast_strlen_zero(args.minlength)) {
00129 if (sscanf(args.minlength, "%30d", &x) == 1 && x > 0) {
00130 minlength = x;
00131 } else {
00132 ast_log(LOG_WARNING, "Invalid min length argument: '%s'\n", args.minlength);
00133 }
00134 }
00135
00136
00137 res = ast_safe_sleep(chan, 1000);
00138 if (!res) {
00139 res = ast_streamfile(chan, "privacy-unident", chan->language);
00140 }
00141 if (!res) {
00142 res = ast_waitstream(chan, "");
00143 }
00144
00145
00146 for (retries = 0; retries < maxretries; retries++) {
00147 if (!res) {
00148 res = ast_streamfile(chan, "privacy-prompt", chan->language);
00149 }
00150 if (!res) {
00151 res = ast_waitstream(chan, "");
00152 }
00153
00154 if (!res) {
00155 res = ast_readstring(chan, phone, sizeof(phone) - 1, 3200, 5000, "#");
00156 }
00157
00158 if (res < 0) {
00159 break;
00160 }
00161
00162
00163 if (strlen(phone) >= minlength ) {
00164
00165 if (!ast_strlen_zero(args.checkcontext)) {
00166 if (!ast_exists_extension(NULL, args.checkcontext, phone, 1, NULL)) {
00167 res = ast_streamfile(chan, "privacy-incorrect", chan->language);
00168 if (!res) {
00169 res = ast_waitstream(chan, "");
00170 }
00171 } else {
00172 break;
00173 }
00174 } else {
00175 break;
00176 }
00177 } else {
00178 res = ast_streamfile(chan, "privacy-incorrect", chan->language);
00179 if (!res) {
00180 res = ast_waitstream(chan, "");
00181 }
00182 }
00183 }
00184
00185
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
00192
00193
00194
00195
00196
00197
00198 chan->caller.id.name.presentation = AST_PRES_ALLOWED_USER_NUMBER_NOT_SCREENED;
00199 chan->caller.id.number.presentation = AST_PRES_ALLOWED_USER_NUMBER_NOT_SCREENED;
00200 chan->caller.id.number.plan = 0;
00201
00202 ast_set_callerid(chan, phone, "Privacy Manager", NULL);
00203
00204 ast_verb(3, "Changed Caller*ID number to '%s'\n", phone);
00205
00206 pbx_builtin_setvar_helper(chan, "PRIVACYMGRSTATUS", "SUCCESS");
00207 } else {
00208 pbx_builtin_setvar_helper(chan, "PRIVACYMGRSTATUS", "FAILED");
00209 }
00210 }
00211
00212 return 0;
00213 }
00214
00215 static int unload_module(void)
00216 {
00217 return ast_unregister_application(app);
00218 }
00219
00220 static int load_module(void)
00221 {
00222 return ast_register_application_xml(app, privacy_exec);
00223 }
00224
00225 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Require phone number to be entered, if no CallerID sent");