#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 int | acf_rand_exec (struct ast_channel *chan, char *cmd, char *parse, char *buffer, size_t buflen) |
AST_MODULE_INFO_STANDARD (ASTERISK_GPL_KEY,"Random number dialplan function") | |
static int | load_module (void) |
static int | unload_module (void) |
Variables | |
static struct ast_custom_function | acf_rand |
Tilghman Lesher ( http://asterisk.drunkcoder.com/ )
Definition in 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, "%d", &min_int) != 1) 00057 min_int = 0; 00058 00059 if (ast_strlen_zero(args.max) || sscanf(args.max, "%d", &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 }
AST_MODULE_INFO_STANDARD | ( | ASTERISK_GPL_KEY | , | |
"Random number dialplan function" | ||||
) |
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 }
struct ast_custom_function acf_rand [static] |