Asterisk - The Open Source Telephony Project GIT-master-7e7a603
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 = "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 = 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 108 of file func_rand.c.

◆ __unreg_module()

static void __unreg_module ( void  )
static

Definition at line 108 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 58 of file func_rand.c.

60{
61 int min_int, response_int, max_int;
65 );
66
68
69 if (ast_strlen_zero(args.min) || sscanf(args.min, "%30d", &min_int) != 1)
70 min_int = 0;
71
72 if (ast_strlen_zero(args.max) || sscanf(args.max, "%30d", &max_int) != 1)
73 max_int = RAND_MAX;
74
75 if (max_int < min_int) {
76 int tmp = max_int;
77
78 max_int = min_int;
79 min_int = tmp;
80 ast_debug(1, "max<min\n");
81 }
82
83 response_int = min_int + (ast_random() % (max_int - min_int + 1));
84 ast_debug(1, "%d was the lucky number in range [%d,%d]\n", response_int, min_int, max_int);
85 snprintf(buffer, buflen, "%d", response_int);
86
87 return 0;
88}
static int tmp()
Definition: bt_open.c:389
#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 force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:65
const char * args
long int ast_random(void)
Definition: utils.c:2312

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

◆ AST_MODULE_SELF_SYM()

struct ast_module * AST_MODULE_SELF_SYM ( void  )

Definition at line 108 of file func_rand.c.

◆ load_module()

static int load_module ( void  )
static

Definition at line 103 of file func_rand.c.

104{
106}
static struct ast_custom_function acf_rand
Definition: func_rand.c:90
#define ast_custom_function_register(acf)
Register a custom function.
Definition: pbx.h:1558

References acf_rand, and ast_custom_function_register.

◆ unload_module()

static int unload_module ( void  )
static

Definition at line 96 of file func_rand.c.

97{
99
100 return 0;
101}
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 = "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 = AST_BUILDOPT_SUM, .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, .support_level = AST_MODULE_SUPPORT_CORE, }
static

Definition at line 108 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:58

Definition at line 90 of file func_rand.c.

Referenced by load_module(), and unload_module().

◆ ast_module_info

const struct ast_module_info* ast_module_info = &__mod_info
static

Definition at line 108 of file func_rand.c.