Asterisk - The Open Source Telephony Project  18.5.0
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 = "30ef0c93b36035ec78c9cfd712d36d9b" , .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 107 of file func_rand.c.

◆ __unreg_module()

static void __unreg_module ( void  )
static

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

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

59 {
60  int min_int, response_int, max_int;
64  );
65 
67 
68  if (ast_strlen_zero(args.min) || sscanf(args.min, "%30d", &min_int) != 1)
69  min_int = 0;
70 
71  if (ast_strlen_zero(args.max) || sscanf(args.max, "%30d", &max_int) != 1)
72  max_int = RAND_MAX;
73 
74  if (max_int < min_int) {
75  int tmp = max_int;
76 
77  max_int = min_int;
78  min_int = tmp;
79  ast_debug(1, "max<min\n");
80  }
81 
82  response_int = min_int + (ast_random() % (max_int - min_int + 1));
83  ast_debug(1, "%d was the lucky number in range [%d,%d]\n", response_int, min_int, max_int);
84  snprintf(buffer, buflen, "%d", response_int);
85 
86  return 0;
87 }
#define AST_STANDARD_APP_ARGS(args, parse)
Performs the &#39;standard&#39; argument separation process for an application.
static int tmp()
Definition: bt_open.c:389
const char * args
#define ast_strlen_zero(foo)
Definition: strings.h:52
#define ast_debug(level,...)
Log a DEBUG message.
Definition: logger.h:452
long int ast_random(void)
Definition: main/utils.c:2064
static void parse(struct mgcp_request *req)
Definition: chan_mgcp.c:1872
#define min(a, b)
Definition: f2c.h:197
#define AST_DECLARE_APP_ARGS(name, arglist)
Declare a structure to hold an application&#39;s arguments.
#define AST_APP_ARG(name)
Define an application argument.
#define max(a, b)
Definition: f2c.h:198

◆ AST_MODULE_SELF_SYM()

struct ast_module* AST_MODULE_SELF_SYM ( void  )

Definition at line 107 of file func_rand.c.

◆ load_module()

static int load_module ( void  )
static

Definition at line 102 of file func_rand.c.

References ast_custom_function_register.

103 {
105 }
static struct ast_custom_function acf_rand
Definition: func_rand.c:89
#define ast_custom_function_register(acf)
Register a custom function.
Definition: pbx.h:1508

◆ unload_module()

static int unload_module ( void  )
static

Definition at line 95 of file func_rand.c.

References ast_custom_function_unregister().

96 {
98 
99  return 0;
100 }
int ast_custom_function_unregister(struct ast_custom_function *acf)
Unregister a custom function.
static struct ast_custom_function acf_rand
Definition: func_rand.c:89

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 = "30ef0c93b36035ec78c9cfd712d36d9b" , .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, .support_level = AST_MODULE_SUPPORT_CORE, }
static

Definition at line 107 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:57

Definition at line 89 of file func_rand.c.

◆ ast_module_info

const struct ast_module_info* ast_module_info = &__mod_info
static

Definition at line 107 of file func_rand.c.