#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 | |
static void | __reg_module (void) |
static void | __unreg_module (void) |
static int | load_module (void) |
static int | random_exec (struct ast_channel *chan, void *data) |
static int | unload_module (void) |
Variables | |
static struct ast_module_info | __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT | AST_MODFLAG_BUILDSUM, .description = "Random goto" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = "361d7bb937402d51e4658efb5b4d76e4" , .load = load_module, .unload = unload_module, } |
static char * | app_random = "Random" |
static const struct ast_module_info * | ast_module_info = &__mod_info |
static char * | random_descrip |
static char * | random_synopsis = "Conditionally branches, based upon a probability" |
Definition in file app_random.c.
static void __reg_module | ( | void | ) | [static] |
Definition at line 108 of file app_random.c.
static void __unreg_module | ( | void | ) | [static] |
Definition at line 108 of file app_random.c.
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, 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, "%30d", &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 }
struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT | AST_MODFLAG_BUILDSUM, .description = "Random goto" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = "361d7bb937402d51e4658efb5b4d76e4" , .load = load_module, .unload = unload_module, } [static] |
Definition at line 108 of file app_random.c.
char* app_random = "Random" [static] |
Definition at line 44 of file app_random.c.
const struct ast_module_info* ast_module_info = &__mod_info [static] |
Definition at line 108 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.