Skip to content
Snippets Groups Projects
Commit 1d7a548a authored by Tilghman Lesher's avatar Tilghman Lesher
Browse files

Ensure the arguments are initialized. Also miscellaneous CG cleanup.

(closes issue #16576)
 Reported by: uxbod
 Patches: 
       20100505__issue16576.diff.txt uploaded by tilghman (license 14)
 Tested by: uxbod


git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@262656 65c4cc65-6c06-0410-ace0-fbb531ad65f3
parent 4b1d9f85
No related branches found
No related tags found
No related merge requests found
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
* \brief Block all calls without Caller*ID, require phone # to be entered * \brief Block all calls without Caller*ID, require phone # to be entered
* *
* \author Mark Spencer <markster@digium.com> * \author Mark Spencer <markster@digium.com>
* *
* \ingroup applications * \ingroup applications
*/ */
...@@ -101,48 +101,55 @@ static int privacy_exec(struct ast_channel *chan, const char *data) ...@@ -101,48 +101,55 @@ static int privacy_exec(struct ast_channel *chan, const char *data)
} else { } else {
/*Answer the channel if it is not already*/ /*Answer the channel if it is not already*/
if (chan->_state != AST_STATE_UP) { if (chan->_state != AST_STATE_UP) {
if ((res = ast_answer(chan))) if ((res = ast_answer(chan))) {
return -1; return -1;
}
} }
if (!ast_strlen_zero(data)) { parse = ast_strdupa(S_OR(data, ""));
parse = ast_strdupa(data);
AST_STANDARD_APP_ARGS(args, parse);
if (args.maxretries) { AST_STANDARD_APP_ARGS(args, parse);
if (sscanf(args.maxretries, "%30d", &x) == 1)
maxretries = x; if (!ast_strlen_zero(args.maxretries)) {
else if (sscanf(args.maxretries, "%30d", &x) == 1 && x > 0) {
ast_log(LOG_WARNING, "Invalid max retries argument\n"); maxretries = x;
} else {
ast_log(LOG_WARNING, "Invalid max retries argument: '%s'\n", args.maxretries);
} }
if (args.minlength) { }
if (sscanf(args.minlength, "%30d", &x) == 1) if (!ast_strlen_zero(args.minlength)) {
minlength = x; if (sscanf(args.minlength, "%30d", &x) == 1 && x > 0) {
else minlength = x;
ast_log(LOG_WARNING, "Invalid min length argument\n"); } else {
ast_log(LOG_WARNING, "Invalid min length argument: '%s'\n", args.minlength);
} }
} }
/* Play unidentified call */ /* Play unidentified call */
res = ast_safe_sleep(chan, 1000); res = ast_safe_sleep(chan, 1000);
if (!res) if (!res) {
res = ast_streamfile(chan, "privacy-unident", chan->language); res = ast_streamfile(chan, "privacy-unident", chan->language);
if (!res) }
if (!res) {
res = ast_waitstream(chan, ""); res = ast_waitstream(chan, "");
}
/* Ask for 10 digit number, give 3 attempts */ /* Ask for 10 digit number, give 3 attempts */
for (retries = 0; retries < maxretries; retries++) { for (retries = 0; retries < maxretries; retries++) {
if (!res) if (!res) {
res = ast_streamfile(chan, "privacy-prompt", chan->language); res = ast_streamfile(chan, "privacy-prompt", chan->language);
if (!res) }
if (!res) {
res = ast_waitstream(chan, ""); res = ast_waitstream(chan, "");
}
if (!res ) if (!res) {
res = ast_readstring(chan, phone, sizeof(phone) - 1, /* digit timeout ms */ 3200, /* first digit timeout */ 5000, "#"); res = ast_readstring(chan, phone, sizeof(phone) - 1, /* digit timeout ms */ 3200, /* first digit timeout */ 5000, "#");
}
if (res < 0) if (res < 0) {
break; break;
}
/* Make sure we get at least digits */ /* Make sure we get at least digits */
if (strlen(phone) >= minlength ) { if (strlen(phone) >= minlength ) {
...@@ -161,25 +168,27 @@ static int privacy_exec(struct ast_channel *chan, const char *data) ...@@ -161,25 +168,27 @@ static int privacy_exec(struct ast_channel *chan, const char *data)
} }
} else { } else {
res = ast_streamfile(chan, "privacy-incorrect", chan->language); res = ast_streamfile(chan, "privacy-incorrect", chan->language);
if (!res) if (!res) {
res = ast_waitstream(chan, ""); res = ast_waitstream(chan, "");
}
} }
} }
/* Got a number, play sounds and send them on their way */ /* Got a number, play sounds and send them on their way */
if ((retries < maxretries) && res >= 0 ) { if ((retries < maxretries) && res >= 0) {
res = ast_streamfile(chan, "privacy-thankyou", chan->language); res = ast_streamfile(chan, "privacy-thankyou", chan->language);
if (!res) if (!res) {
res = ast_waitstream(chan, ""); res = ast_waitstream(chan, "");
}
ast_set_callerid (chan, phone, "Privacy Manager", NULL); ast_set_callerid(chan, phone, "Privacy Manager", NULL);
/* Clear the unavailable presence bit so if it came in on PRI /* Clear the unavailable presence bit so if it came in on PRI
* the caller id will now be passed out to other channels * the caller id will now be passed out to other channels
*/ */
chan->cid.cid_pres &= (AST_PRES_UNAVAILABLE ^ 0xFF); chan->cid.cid_pres &= (AST_PRES_UNAVAILABLE ^ 0xFF);
ast_verb(3, "Changed Caller*ID to %s, callerpres to %d\n",phone,chan->cid.cid_pres); ast_verb(3, "Changed Caller*ID to '%s', callerpres to %d\n", phone, chan->cid.cid_pres);
pbx_builtin_setvar_helper(chan, "PRIVACYMGRSTATUS", "SUCCESS"); pbx_builtin_setvar_helper(chan, "PRIVACYMGRSTATUS", "SUCCESS");
} else { } else {
...@@ -192,7 +201,7 @@ static int privacy_exec(struct ast_channel *chan, const char *data) ...@@ -192,7 +201,7 @@ static int privacy_exec(struct ast_channel *chan, const char *data)
static int unload_module(void) static int unload_module(void)
{ {
return ast_unregister_application (app); return ast_unregister_application(app);
} }
static int load_module(void) static int load_module(void)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment