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

Deprecate the use of Random in 1.3, 1.4

git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@8270 65c4cc65-6c06-0410-ace0-fbb531ad65f3
parent 6b46e27b
No related branches found
No related tags found
No related merge requests found
...@@ -39,6 +39,8 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$") ...@@ -39,6 +39,8 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
#include "asterisk/pbx.h" #include "asterisk/pbx.h"
#include "asterisk/module.h" #include "asterisk/module.h"
/* TODO This app should be removed from trunk following the release of 1.4 */
static char *tdesc = "Random goto"; static char *tdesc = "Random goto";
static char *app_random = "Random"; static char *app_random = "Random";
...@@ -47,14 +49,13 @@ static char *random_synopsis = "Conditionally branches, based upon a probability ...@@ -47,14 +49,13 @@ static char *random_synopsis = "Conditionally branches, based upon a probability
static char *random_descrip = static char *random_descrip =
"Random([probability]:[[context|]extension|]priority)\n" "Random([probability]:[[context|]extension|]priority)\n"
" probability := INTEGER in the range 1 to 100\n"; " probability := INTEGER in the range 1 to 100\n"
"DEPRECATED: Use GotoIf($[${RAND(1,100)} > <number>]?<label>)\n";
STANDARD_LOCAL_USER; STANDARD_LOCAL_USER;
LOCAL_USER_DECL; LOCAL_USER_DECL;
static char random_state[256];
static int random_exec(struct ast_channel *chan, void *data) static int random_exec(struct ast_channel *chan, void *data)
{ {
int res=0; int res=0;
...@@ -63,7 +64,8 @@ static int random_exec(struct ast_channel *chan, void *data) ...@@ -63,7 +64,8 @@ static int random_exec(struct ast_channel *chan, void *data)
char *s; char *s;
char *prob; char *prob;
int probint; int probint;
static int deprecated = 0;
if (ast_strlen_zero(data)) { if (ast_strlen_zero(data)) {
ast_log(LOG_WARNING, "Random requires an argument ([probability]:[[context|]extension|]priority)\n"); ast_log(LOG_WARNING, "Random requires an argument ([probability]:[[context|]extension|]priority)\n");
return -1; return -1;
...@@ -82,7 +84,12 @@ static int random_exec(struct ast_channel *chan, void *data) ...@@ -82,7 +84,12 @@ static int random_exec(struct ast_channel *chan, void *data)
if ((!prob) || (sscanf(prob, "%d", &probint) != 1)) if ((!prob) || (sscanf(prob, "%d", &probint) != 1))
probint = 0; probint = 0;
if ((random() % 100) + probint > 100) { if (!deprecated) {
deprecated = 1;
ast_log(LOG_WARNING, "Random is deprecated in Asterisk 1.3 or later. Replace with GotoIf($[${RAND(0,99)} + %d >= 100]?%s)\n", probint, s);
}
if ((ast_random() % 100) + probint > 100) {
res = ast_parseable_goto(chan, s); res = ast_parseable_goto(chan, s);
if (option_verbose > 2) if (option_verbose > 2)
ast_verbose( VERBOSE_PREFIX_3 "Random branches to (%s,%s,%d)\n", ast_verbose( VERBOSE_PREFIX_3 "Random branches to (%s,%s,%d)\n",
...@@ -105,7 +112,6 @@ int unload_module(void) ...@@ -105,7 +112,6 @@ int unload_module(void)
int load_module(void) int load_module(void)
{ {
initstate((getppid() * 65535 + getpid()) % RAND_MAX, random_state, 256);
return ast_register_application(app_random, random_exec, random_synopsis, random_descrip); return ast_register_application(app_random, random_exec, random_synopsis, random_descrip);
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment