Wed Jan 8 2020 09:50:13

Asterisk developer's documentation


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"

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)
 
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 = "ac1f6a56484a8820659555499174e588" , .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, }
 
static struct ast_custom_function acf_rand
 
static 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

static void __reg_module ( void  )
static

Definition at line 109 of file func_rand.c.

static void __unreg_module ( void  )
static

Definition at line 109 of file func_rand.c.

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

Definition at line 59 of file func_rand.c.

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

61 {
62  int min_int, response_int, max_int;
64  AST_APP_ARG(min);
65  AST_APP_ARG(max);
66  );
67 
69 
70  if (ast_strlen_zero(args.min) || sscanf(args.min, "%30d", &min_int) != 1)
71  min_int = 0;
72 
73  if (ast_strlen_zero(args.max) || sscanf(args.max, "%30d", &max_int) != 1)
74  max_int = RAND_MAX;
75 
76  if (max_int < min_int) {
77  int tmp = max_int;
78 
79  max_int = min_int;
80  min_int = tmp;
81  ast_debug(1, "max<min\n");
82  }
83 
84  response_int = min_int + (ast_random() % (max_int - min_int + 1));
85  ast_debug(1, "%d was the lucky number in range [%d,%d]\n", response_int, min_int, max_int);
86  snprintf(buffer, buflen, "%d", response_int);
87 
88  return 0;
89 }
#define AST_DECLARE_APP_ARGS(name, arglist)
Declare a structure to hold an application&#39;s arguments.
Definition: app.h:572
#define ast_debug(level,...)
Log a DEBUG message.
Definition: logger.h:236
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:63
long int ast_random(void)
Definition: utils.c:1640
static struct @350 args
static void parse(struct mgcp_request *req)
Definition: chan_mgcp.c:1858
#define AST_APP_ARG(name)
Define an application argument.
Definition: app.h:555
#define AST_STANDARD_APP_ARGS(args, parse)
Performs the &#39;standard&#39; argument separation process for an application.
Definition: app.h:604
static int load_module ( void  )
static

Definition at line 104 of file func_rand.c.

References ast_custom_function_register.

105 {
107 }
static struct ast_custom_function acf_rand
Definition: func_rand.c:91
#define ast_custom_function_register(acf)
Register a custom function.
Definition: pbx.h:1164
static int unload_module ( void  )
static

Definition at line 97 of file func_rand.c.

References ast_custom_function_unregister().

98 {
100 
101  return 0;
102 }
int ast_custom_function_unregister(struct ast_custom_function *acf)
Unregister a custom function.
Definition: pbx.c:3814
static struct ast_custom_function acf_rand
Definition: func_rand.c:91

Variable Documentation

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

Definition at line 109 of file func_rand.c.

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:59

Definition at line 91 of file func_rand.c.

Definition at line 109 of file func_rand.c.