#include "asterisk.h"
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include "asterisk/file.h"
#include "asterisk/logger.h"
#include "asterisk/options.h"
#include "asterisk/channel.h"
#include "asterisk/pbx.h"
#include "asterisk/module.h"
Go to the source code of this file.
Functions | |
AST_MODULE_INFO_STANDARD (ASTERISK_GPL_KEY,"Random goto") | |
static int | load_module (void) |
static int | random_exec (struct ast_channel *chan, void *data) |
static int | unload_module (void) |
Variables | |
static char * | app_random = "Random" |
static char * | random_descrip |
static char * | random_synopsis = "Conditionally branches, based upon a probability" |
Definition in file app_random.c.
AST_MODULE_INFO_STANDARD | ( | ASTERISK_GPL_KEY | , | |
"Random goto" | ||||
) |
static int load_module | ( | void | ) | [static] |
Definition at line 103 of file app_random.c.
References ast_register_application(), and random_exec().
00104 { 00105 return ast_register_application(app_random, random_exec, random_synopsis, random_descrip); 00106 }
static int random_exec | ( | struct ast_channel * | chan, | |
void * | data | |||
) | [static] |
Definition at line 54 of file app_random.c.
References ast_log(), ast_module_user_add, ast_module_user_remove, ast_parseable_goto(), ast_random(), ast_strdupa, ast_strlen_zero(), ast_verbose(), ast_module_user::chan, ast_channel::context, ast_channel::exten, LOG_WARNING, option_verbose, ast_channel::priority, s, strsep(), and VERBOSE_PREFIX_3.
Referenced by load_module().
00055 { 00056 int res=0; 00057 struct ast_module_user *u; 00058 00059 char *s; 00060 char *prob; 00061 int probint; 00062 static int deprecated = 0; 00063 00064 if (ast_strlen_zero(data)) { 00065 ast_log(LOG_WARNING, "Random requires an argument ([probability]:[[context|]extension|]priority)\n"); 00066 return -1; 00067 } 00068 00069 u = ast_module_user_add(chan); 00070 00071 s = ast_strdupa(data); 00072 00073 prob = strsep(&s,":"); 00074 if ((!prob) || (sscanf(prob, "%d", &probint) != 1)) 00075 probint = 0; 00076 00077 if (!deprecated) { 00078 deprecated = 1; 00079 ast_log(LOG_WARNING, "Random is deprecated in Asterisk 1.4. Replace with GotoIf($[${RAND(0,99)} + %d >= 100]?%s)\n", probint, s); 00080 } 00081 00082 if ((ast_random() % 100) + probint >= 100) { 00083 res = ast_parseable_goto(chan, s); 00084 if (option_verbose > 2) 00085 ast_verbose( VERBOSE_PREFIX_3 "Random branches to (%s,%s,%d)\n", 00086 chan->context,chan->exten, chan->priority+1); 00087 } 00088 ast_module_user_remove(u); 00089 return res; 00090 }
static int unload_module | ( | void | ) | [static] |
Definition at line 92 of file app_random.c.
References ast_module_user_hangup_all, and ast_unregister_application().
00093 { 00094 int res; 00095 00096 res = ast_unregister_application(app_random); 00097 00098 ast_module_user_hangup_all(); 00099 00100 return res; 00101 }
char* app_random = "Random" [static] |
Definition at line 44 of file app_random.c.
char* random_descrip [static] |
Initial value:
"Random([probability]:[[context|]extension|]priority)\n" " probability := INTEGER in the range 1 to 100\n" "DEPRECATED: Use GotoIf($[${RAND(1,100)} > <number>]?<label>)\n"
Definition at line 48 of file app_random.c.
char* random_synopsis = "Conditionally branches, based upon a probability" [static] |
Definition at line 46 of file app_random.c.