| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
#include "asterisk.h" |
| 33 |
|
| 34 |
#include "asterisk/lock.h" |
| 35 |
#include "asterisk/file.h" |
| 36 |
#include "asterisk/utils.h" |
| 37 |
#include "asterisk/channel.h" |
| 38 |
#include "asterisk/pbx.h" |
| 39 |
#include "asterisk/module.h" |
| 40 |
#include "asterisk/translate.h" |
| 41 |
#include "asterisk/callerid.h" |
| 42 |
#include "asterisk/app.h" |
| 43 |
#include "asterisk/config.h" |
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
static char *app = "PrivacyManager"; |
| 89 |
|
| 90 |
static int privacy_exec(struct ast_channel *chan, const char *data) |
| 91 |
{ |
| 92 |
int res=0; |
| 93 |
int retries; |
| 94 |
int maxretries = 3; |
| 95 |
int minlength = 10; |
| 96 |
int x = 0; |
| 97 |
char phone[30]; |
| 98 |
char *parse = NULL; |
| 99 |
AST_DECLARE_APP_ARGS(args, |
| 100 |
AST_APP_ARG(maxretries); |
| 101 |
AST_APP_ARG(minlength); |
| 102 |
AST_APP_ARG(options); |
| 103 |
AST_APP_ARG(checkcontext); |
| 104 |
); |
| 105 |
|
| 106 |
if (ast_channel_caller(chan)->id.number.valid |
| 107 |
&& !ast_strlen_zero(ast_channel_caller(chan)->id.number.str)) { |
| 108 |
ast_verb(3, "CallerID number present: Skipping\n"); |
| 109 |
} else { |
| 110 |
|
| 111 |
if (ast_channel_state(chan) != AST_STATE_UP) { |
| 112 |
if ((res = ast_answer(chan))) { |
| 113 |
return -1; |
| 114 |
} |
| 115 |
} |
| 116 |
|
| 117 |
parse = ast_strdupa(data); |
| 118 |
|
| 119 |
AST_STANDARD_APP_ARGS(args, parse); |
| 120 |
|
| 121 |
if (!ast_strlen_zero(args.maxretries)) { |
| 122 |
if (sscanf(args.maxretries, "%30d", &x) == 1 && x > 0) { |
| 123 |
maxretries = x; |
| 124 |
} else { |
| 125 |
ast_log(LOG_WARNING, "Invalid max retries argument: '%s'\n", args.maxretries); |
| 126 |
} |
| 127 |
} |
| 128 |
if (!ast_strlen_zero(args.minlength)) { |
| 129 |
if (sscanf(args.minlength, "%30d", &x) == 1 && x > 0) { |
| 130 |
minlength = x; |
| 131 |
} else { |
| 132 |
ast_log(LOG_WARNING, "Invalid min length argument: '%s'\n", args.minlength); |
| 133 |
} |
| 134 |
} |
| 135 |
|
| 136 |
|
| 137 |
res = ast_safe_sleep(chan, 1000); |
| 138 |
if (!res) { |
| 139 |
res = ast_streamfile(chan, "privacy-unident", ast_channel_language(chan)); |
| 140 |
} |
| 141 |
if (!res) { |
| 142 |
res = ast_waitstream(chan, ""); |
| 143 |
} |
| 144 |
|
| 145 |
|
| 146 |
for (retries = 0; retries < maxretries; retries++) { |
| 147 |
if (!res) { |
| 148 |
res = ast_streamfile(chan, "privacy-prompt", ast_channel_language(chan)); |
| 149 |
} |
| 150 |
if (!res) { |
| 151 |
res = ast_waitstream(chan, ""); |
| 152 |
} |
| 153 |
|
| 154 |
if (!res) { |
| 155 |
res = ast_readstring(chan, phone, sizeof(phone) - 1, 3200, 5000, "#"); |
| 156 |
} |
| 157 |
|
| 158 |
if (res < 0) { |
| 159 |
break; |
| 160 |
} |
| 161 |
|
| 162 |
|
| 163 |
if (strlen(phone) >= minlength ) { |
| 164 |
|
| 165 |
if (!ast_strlen_zero(args.checkcontext)) { |
| 166 |
if (!ast_exists_extension(NULL, args.checkcontext, phone, 1, NULL)) { |
| 167 |
res = ast_streamfile(chan, "privacy-incorrect", ast_channel_language(chan)); |
| 168 |
if (!res) { |
| 169 |
res = ast_waitstream(chan, ""); |
| 170 |
} |
| 171 |
} else { |
| 172 |
break; |
| 173 |
} |
| 174 |
} else { |
| 175 |
break; |
| 176 |
} |
| 177 |
} else { |
| 178 |
res = ast_streamfile(chan, "privacy-incorrect", ast_channel_language(chan)); |
| 179 |
if (!res) { |
| 180 |
res = ast_waitstream(chan, ""); |
| 181 |
} |
| 182 |
} |
| 183 |
} |
| 184 |
|
| 185 |
|
| 186 |
if ((retries < maxretries) && res >= 0) { |
| 187 |
res = ast_streamfile(chan, "privacy-thankyou", ast_channel_language(chan)); |
| 188 |
if (!res) { |
| 189 |
res = ast_waitstream(chan, ""); |
| 190 |
} |
| 191 |
|
| 192 |
|
| 193 |
|
| 194 |
|
| 195 |
|
| 196 |
|
| 197 |
|
| 198 |
ast_channel_caller(chan)->id.name.presentation = AST_PRES_ALLOWED_USER_NUMBER_NOT_SCREENED; |
| 199 |
ast_channel_caller(chan)->id.number.presentation = AST_PRES_ALLOWED_USER_NUMBER_NOT_SCREENED; |
| 200 |
ast_channel_caller(chan)->id.number.plan = 0; |
| 201 |
|
| 202 |
ast_set_callerid(chan, phone, "Privacy Manager", NULL); |
| 203 |
|
| 204 |
ast_verb(3, "Changed Caller*ID number to '%s'\n", phone); |
| 205 |
|
| 206 |
pbx_builtin_setvar_helper(chan, "PRIVACYMGRSTATUS", "SUCCESS"); |
| 207 |
} else { |
| 208 |
pbx_builtin_setvar_helper(chan, "PRIVACYMGRSTATUS", "FAILED"); |
| 209 |
} |
| 210 |
} |
| 211 |
|
| 212 |
return 0; |
| 213 |
} |
| 214 |
|
| 215 |
static int unload_module(void) |
| 216 |
{ |
| 217 |
return ast_unregister_application(app); |
| 218 |
} |
| 219 |
|
| 220 |
static int load_module(void) |
| 221 |
{ |
| 222 |
return ast_register_application_xml(app, privacy_exec); |
| 223 |
} |
| 224 |
|
| 225 |
AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Require phone number to be entered, if no CallerID sent"); |