Sat Aug 6 00:39:57 2011

Asterisk developer's documentation


func_rand.c File Reference

Generate Random Number. More...

#include "asterisk.h"
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <sys/types.h>
#include "asterisk/module.h"
#include "asterisk/channel.h"
#include "asterisk/pbx.h"
#include "asterisk/logger.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, 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_DEFAULT | AST_MODFLAG_BUILDSUM, .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 = "361d7bb937402d51e4658efb5b4d76e4" , .load = load_module, .unload = unload_module, }
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 <cpatry@gmail.com>

Tilghman Lesher ( http://asterisk.drunkcoder.com/ )

Definition in file func_rand.c.


Function Documentation

static void __reg_module ( void   )  [static]

Definition at line 104 of file func_rand.c.

static void __unreg_module ( void   )  [static]

Definition at line 104 of file func_rand.c.

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

Definition at line 42 of file func_rand.c.

References AST_APP_ARG, AST_DECLARE_APP_ARGS, ast_log(), ast_module_user_add, ast_module_user_remove, ast_random(), AST_STANDARD_APP_ARGS, ast_strlen_zero(), ast_module_user::chan, and LOG_DEBUG.

00044 {
00045    struct ast_module_user *u;
00046    int min_int, response_int, max_int;
00047    AST_DECLARE_APP_ARGS(args,
00048               AST_APP_ARG(min);
00049               AST_APP_ARG(max);
00050    );
00051 
00052    u = ast_module_user_add(chan);
00053 
00054    AST_STANDARD_APP_ARGS(args, parse);
00055 
00056    if (ast_strlen_zero(args.min) || sscanf(args.min, "%30d", &min_int) != 1)
00057       min_int = 0;
00058 
00059    if (ast_strlen_zero(args.max) || sscanf(args.max, "%30d", &max_int) != 1)
00060       max_int = RAND_MAX;
00061 
00062    if (max_int < min_int) {
00063       int tmp = max_int;
00064 
00065       max_int = min_int;
00066       min_int = tmp;
00067       ast_log(LOG_DEBUG, "max<min\n");
00068    }
00069 
00070    response_int = min_int + (ast_random() % (max_int - min_int + 1));
00071    ast_log(LOG_DEBUG, "%d was the lucky number in range [%d,%d]\n",
00072       response_int, min_int, max_int);
00073    snprintf(buffer, buflen, "%d", response_int);
00074 
00075    ast_module_user_remove(u);
00076 
00077    return 0;
00078 }

static int load_module ( void   )  [static]

Definition at line 99 of file func_rand.c.

References acf_rand, and ast_custom_function_register().

00100 {
00101    return ast_custom_function_register(&acf_rand);
00102 }

static int unload_module ( void   )  [static]

Definition at line 92 of file func_rand.c.

References acf_rand, and ast_custom_function_unregister().

00093 {
00094    ast_custom_function_unregister(&acf_rand);
00095 
00096    return 0;
00097 }


Variable Documentation

struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT | AST_MODFLAG_BUILDSUM, .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 = "361d7bb937402d51e4658efb5b4d76e4" , .load = load_module, .unload = unload_module, } [static]

Definition at line 104 of file func_rand.c.

struct ast_custom_function acf_rand [static]

Definition at line 80 of file func_rand.c.

Referenced by load_module(), and unload_module().

const struct ast_module_info* ast_module_info = &__mod_info [static]

Definition at line 104 of file func_rand.c.


Generated on Sat Aug 6 00:39:57 2011 for Asterisk - the Open Source PBX by  doxygen 1.4.7