Asterisk - The Open Source Telephony Project GIT-master-27fb039
Loading...
Searching...
No Matches
Functions | Variables
func_rand.c File Reference

Generate Random Number. More...

#include "asterisk.h"
#include "asterisk/module.h"
#include "asterisk/channel.h"
#include "asterisk/pbx.h"
#include "asterisk/utils.h"
#include "asterisk/app.h"
Include dependency graph for func_rand.c:

Go to the source code of this file.

Functions

static void __reg_module (void)
 
static void __unreg_module (void)
 
static int acf_rand_exec (struct ast_channel *chan, const char *cmd, char *parse, char *buffer, size_t buflen)
 
struct ast_moduleAST_MODULE_SELF_SYM (void)
 
static int load_module (void)
 
static int unload_module (void)
 

Variables

static struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "Random number dialplan function" , .key = ASTERISK_GPL_KEY , .buildopt_sum = AST_BUILDOPT_SUM, .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, .support_level = AST_MODULE_SUPPORT_CORE, }
 
static struct ast_custom_function acf_rand
 
static const struct ast_module_infoast_module_info = &__mod_info
 

Detailed Description

Generate Random Number.

Author
Claude Patry cpatr.nosp@m.y@gm.nosp@m.ail.c.nosp@m.om
Tilghman Lesher ( http://asterisk.drunkcoder.com/ )

Definition in file func_rand.c.

Function Documentation

◆ __reg_module()

static void __reg_module ( void  )
static

Definition at line 111 of file func_rand.c.

◆ __unreg_module()

static void __unreg_module ( void  )
static

Definition at line 111 of file func_rand.c.

◆ acf_rand_exec()

static int acf_rand_exec ( struct ast_channel chan,
const char *  cmd,
char *  parse,
char *  buffer,
size_t  buflen 
)
static

Definition at line 61 of file func_rand.c.

63{
64 int min_int, response_int, max_int;
68 );
69
71
72 if (ast_strlen_zero(args.min) || sscanf(args.min, "%30d", &min_int) != 1)
73 min_int = 0;
74
75 if (ast_strlen_zero(args.max) || sscanf(args.max, "%30d", &max_int) != 1)
76 max_int = RAND_MAX;
77
78 if (max_int < min_int) {
79 int tmp = max_int;
80
81 max_int = min_int;
82 min_int = tmp;
83 ast_debug(1, "max<min\n");
84 }
85
86 response_int = min_int + (ast_random() % (max_int - min_int + 1));
87 ast_debug(1, "%d was the lucky number in range [%d,%d]\n", response_int, min_int, max_int);
88 snprintf(buffer, buflen, "%d", response_int);
89
90 return 0;
91}
#define min(a, b)
Definition f2c.h:197
#define max(a, b)
Definition f2c.h:198
#define AST_APP_ARG(name)
Define an application argument.
#define AST_DECLARE_APP_ARGS(name, arglist)
Declare a structure to hold an application's arguments.
#define AST_STANDARD_APP_ARGS(args, parse)
Performs the 'standard' argument separation process for an application.
#define ast_debug(level,...)
Log a DEBUG message.
static struct @519 args
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition strings.h:65
long int ast_random(void)
Definition utils.c:2348

References args, AST_APP_ARG, ast_debug, AST_DECLARE_APP_ARGS, ast_random(), AST_STANDARD_APP_ARGS, ast_strlen_zero(), max, and min.

◆ AST_MODULE_SELF_SYM()

struct ast_module * AST_MODULE_SELF_SYM ( void  )

Definition at line 111 of file func_rand.c.

◆ load_module()

static int load_module ( void  )
static

Definition at line 106 of file func_rand.c.

107{
109}
static struct ast_custom_function acf_rand
Definition func_rand.c:93
#define ast_custom_function_register(acf)
Register a custom function.
Definition pbx.h:1562

References acf_rand, and ast_custom_function_register.

◆ unload_module()

static int unload_module ( void  )
static

Definition at line 99 of file func_rand.c.

100{
102
103 return 0;
104}
int ast_custom_function_unregister(struct ast_custom_function *acf)
Unregister a custom function.

References acf_rand, and ast_custom_function_unregister().

Variable Documentation

◆ __mod_info

struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "Random number dialplan function" , .key = ASTERISK_GPL_KEY , .buildopt_sum = AST_BUILDOPT_SUM, .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, .support_level = AST_MODULE_SUPPORT_CORE, }
static

Definition at line 111 of file func_rand.c.

◆ acf_rand

struct ast_custom_function acf_rand
static
Initial value:
= {
.name = "RAND",
.read = acf_rand_exec,
.read_max = 12,
}
static int acf_rand_exec(struct ast_channel *chan, const char *cmd, char *parse, char *buffer, size_t buflen)
Definition func_rand.c:61

Definition at line 93 of file func_rand.c.

93 {
94 .name = "RAND",
95 .read = acf_rand_exec,
96 .read_max = 12,
97};

Referenced by load_module(), and unload_module().

◆ ast_module_info

const struct ast_module_info* ast_module_info = &__mod_info
static

Definition at line 111 of file func_rand.c.