diff options
author | kpfleming <kpfleming@f38db490-d61c-443f-a65b-d21fe96a405b> | 2005-08-25 04:04:14 +0000 |
---|---|---|
committer | kpfleming <kpfleming@f38db490-d61c-443f-a65b-d21fe96a405b> | 2005-08-25 04:04:14 +0000 |
commit | 79e8eab9d5b2404c60298fa037ab694621ab52df (patch) | |
tree | 02f70488a411431e8372602491b05a77b8e34e18 /apps/app_random.c | |
parent | 5074a39dc1371daf6739a94c0d223a879caa7267 (diff) |
ensure that Random() can support priority labels as targets (issue #5013)
git-svn-id: http://svn.digium.com/svn/asterisk/trunk@6406 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'apps/app_random.c')
-rwxr-xr-x | apps/app_random.c | 42 |
1 files changed, 7 insertions, 35 deletions
diff --git a/apps/app_random.c b/apps/app_random.c index 70f77998c..c486be468 100755 --- a/apps/app_random.c +++ b/apps/app_random.c @@ -5,7 +5,7 @@ * * Copyright (c) 2003 - 2005 Tilghman Lesher. All rights reserved. * - * Tilghman Lesher <asterisk__app_random__20040111@the-tilghman.com> + * Tilghman Lesher <asterisk__app_random__200508@the-tilghman.com> * * This code is released by the author with no restrictions on usage or distribution. * @@ -41,15 +41,16 @@ STANDARD_LOCAL_USER; LOCAL_USER_DECL; +static char random_state[256]; + static int random_exec(struct ast_channel *chan, void *data) { int res=0; struct localuser *u; char *s; - char *exten, *pri, *context; char *prob; - int probint, priorityint; + int probint; if (!data) { ast_log(LOG_WARNING, "Random requires an argument ([probability]:[[context|]extension|]priority)\n"); @@ -63,42 +64,12 @@ static int random_exec(struct ast_channel *chan, void *data) probint = 0; if ((random() % 100) + probint > 100) { - context = strsep(&s, "|"); - exten = strsep(&s, "|"); - if (!exten) { - /* Only a priority */ - pri = context; - exten = NULL; - context = NULL; - } else { - pri = strsep(&s, "|"); - if (!pri) { - pri = exten; - exten = context; - context = NULL; - } - } - if (!pri) { - ast_log(LOG_WARNING, "No label specified\n"); - LOCAL_USER_REMOVE(u); - return -1; - } else if (sscanf(pri, "%d", &priorityint) != 1) { - ast_log(LOG_WARNING, "Priority '%s' must be a number > 0\n", pri); - LOCAL_USER_REMOVE(u); - return -1; - } - /* At this point we have a priority and */ - /* maybe an extension and a context */ - chan->priority = priorityint - 1; - if (exten && strcasecmp(exten, "BYEXTENSION")) - strncpy(chan->exten, exten, sizeof(chan->exten)-1); - if (context) - strncpy(chan->context, context, sizeof(chan->context)-1); + res = ast_parseable_goto(chan, s); if (option_verbose > 2) ast_verbose( VERBOSE_PREFIX_3 "Random branches to (%s,%s,%d)\n", chan->context,chan->exten, chan->priority+1); - LOCAL_USER_REMOVE(u); } + LOCAL_USER_REMOVE(u); return res; } @@ -110,6 +81,7 @@ int unload_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); } |