Functions for interaction with the Asterisk database. More...
#include "asterisk.h"#include <regex.h>#include "asterisk/module.h"#include "asterisk/channel.h"#include "asterisk/pbx.h"#include "asterisk/utils.h"#include "asterisk/app.h"#include "asterisk/astdb.h"
Go to the source code of this file.
Functions | |
| static void | __reg_module (void) |
| static void | __unreg_module (void) |
| static int | function_db_delete (struct ast_channel *chan, const char *cmd, char *parse, char *buf, size_t len) |
| static int | function_db_delete_write (struct ast_channel *chan, const char *cmd, char *parse, const char *value) |
| Wrapper to execute DB_DELETE from a write operation. Allows execution even if live_dangerously is disabled. | |
| static int | function_db_exists (struct ast_channel *chan, const char *cmd, char *parse, char *buf, size_t len) |
| static int | function_db_keys (struct ast_channel *chan, const char *cmd, char *parse, struct ast_str **result, ssize_t maxlen) |
| static int | function_db_read (struct ast_channel *chan, const char *cmd, char *parse, char *buf, size_t len) |
| static int | function_db_write (struct ast_channel *chan, const char *cmd, char *parse, const char *value) |
| 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 = "Database (astdb) related dialplan functions" , .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, } |
| static struct ast_module_info * | ast_module_info = &__mod_info |
| static struct ast_custom_function | db_delete_function |
| static struct ast_custom_function | db_exists_function |
| static struct ast_custom_function | db_function |
| static struct ast_custom_function | db_keys_function |
Functions for interaction with the Asterisk database.
Definition in file func_db.c.
| static void __reg_module | ( | void | ) | [static] |
| static void __unreg_module | ( | void | ) | [static] |
| static int function_db_delete | ( | struct ast_channel * | chan, |
| const char * | cmd, | ||
| char * | parse, | ||
| char * | buf, | ||
| size_t | len | ||
| ) | [static] |
Definition at line 285 of file func_db.c.
References args, AST_APP_ARG, ast_db_del(), ast_db_get(), ast_debug, AST_DECLARE_APP_ARGS, ast_log(), AST_NONSTANDARD_APP_ARGS, ast_strlen_zero(), LOG_WARNING, and pbx_builtin_setvar_helper().
Referenced by function_db_delete_write().
{
AST_DECLARE_APP_ARGS(args,
AST_APP_ARG(family);
AST_APP_ARG(key);
);
buf[0] = '\0';
if (ast_strlen_zero(parse)) {
ast_log(LOG_WARNING, "DB_DELETE requires an argument, DB_DELETE(<family>/<key>)\n");
return -1;
}
AST_NONSTANDARD_APP_ARGS(args, parse, '/');
if (args.argc < 2) {
ast_log(LOG_WARNING, "DB_DELETE requires an argument, DB_DELETE(<family>/<key>)\n");
return -1;
}
if (ast_db_get(args.family, args.key, buf, len - 1)) {
ast_debug(1, "DB_DELETE: %s/%s not found in database.\n", args.family, args.key);
} else {
if (ast_db_del(args.family, args.key)) {
ast_debug(1, "DB_DELETE: %s/%s could not be deleted from the database\n", args.family, args.key);
}
}
pbx_builtin_setvar_helper(chan, "DB_RESULT", buf);
return 0;
}
| static int function_db_delete_write | ( | struct ast_channel * | chan, |
| const char * | cmd, | ||
| char * | parse, | ||
| const char * | value | ||
| ) | [static] |
Wrapper to execute DB_DELETE from a write operation. Allows execution even if live_dangerously is disabled.
Definition at line 324 of file func_db.c.
References function_db_delete().
{
/* Throwaway to hold the result from the read */
char buf[128];
return function_db_delete(chan, cmd, parse, buf, sizeof(buf));
}
| static int function_db_exists | ( | struct ast_channel * | chan, |
| const char * | cmd, | ||
| char * | parse, | ||
| char * | buf, | ||
| size_t | len | ||
| ) | [static] |
Definition at line 192 of file func_db.c.
References args, AST_APP_ARG, ast_db_get(), AST_DECLARE_APP_ARGS, ast_log(), AST_NONSTANDARD_APP_ARGS, ast_strlen_zero(), LOG_WARNING, and pbx_builtin_setvar_helper().
{
AST_DECLARE_APP_ARGS(args,
AST_APP_ARG(family);
AST_APP_ARG(key);
);
buf[0] = '\0';
if (ast_strlen_zero(parse)) {
ast_log(LOG_WARNING, "DB_EXISTS requires an argument, DB(<family>/<key>)\n");
return -1;
}
AST_NONSTANDARD_APP_ARGS(args, parse, '/');
if (args.argc < 2) {
ast_log(LOG_WARNING, "DB_EXISTS requires an argument, DB(<family>/<key>)\n");
return -1;
}
if (ast_db_get(args.family, args.key, buf, len - 1)) {
strcpy(buf, "0");
} else {
pbx_builtin_setvar_helper(chan, "DB_RESULT", buf);
strcpy(buf, "1");
}
return 0;
}
| static int function_db_keys | ( | struct ast_channel * | chan, |
| const char * | cmd, | ||
| char * | parse, | ||
| struct ast_str ** | result, | ||
| ssize_t | maxlen | ||
| ) | [static] |
Definition at line 230 of file func_db.c.
References ast_db_freetree(), ast_db_gettree(), ast_free, ast_str_append(), ast_str_append_escapecommas(), ast_str_reset(), ast_db_entry::key, last, and ast_db_entry::next.
{
size_t parselen = strlen(parse);
struct ast_db_entry *dbe, *orig_dbe;
struct ast_str *escape_buf = NULL;
const char *last = "";
/* Remove leading and trailing slashes */
while (parse[0] == '/') {
parse++;
parselen--;
}
while (parse[parselen - 1] == '/') {
parse[--parselen] = '\0';
}
ast_str_reset(*result);
/* Nothing within the database at that prefix? */
if (!(orig_dbe = dbe = ast_db_gettree(parse, NULL))) {
return 0;
}
for (; dbe; dbe = dbe->next) {
/* Find the current component */
char *curkey = &dbe->key[parselen + 1], *slash;
if (*curkey == '/') {
curkey++;
}
/* Remove everything after the current component */
if ((slash = strchr(curkey, '/'))) {
*slash = '\0';
}
/* Skip duplicates */
if (!strcasecmp(last, curkey)) {
continue;
}
last = curkey;
if (orig_dbe != dbe) {
ast_str_append(result, maxlen, ",");
}
ast_str_append_escapecommas(result, maxlen, curkey, strlen(curkey));
}
ast_db_freetree(orig_dbe);
ast_free(escape_buf);
return 0;
}
| static int function_db_read | ( | struct ast_channel * | chan, |
| const char * | cmd, | ||
| char * | parse, | ||
| char * | buf, | ||
| size_t | len | ||
| ) | [static] |
Definition at line 128 of file func_db.c.
References args, AST_APP_ARG, ast_db_get(), ast_debug, AST_DECLARE_APP_ARGS, ast_log(), AST_NONSTANDARD_APP_ARGS, ast_strlen_zero(), LOG_WARNING, and pbx_builtin_setvar_helper().
{
AST_DECLARE_APP_ARGS(args,
AST_APP_ARG(family);
AST_APP_ARG(key);
);
buf[0] = '\0';
if (ast_strlen_zero(parse)) {
ast_log(LOG_WARNING, "DB requires an argument, DB(<family>/<key>)\n");
return -1;
}
AST_NONSTANDARD_APP_ARGS(args, parse, '/');
if (args.argc < 2) {
ast_log(LOG_WARNING, "DB requires an argument, DB(<family>/<key>)\n");
return -1;
}
if (ast_db_get(args.family, args.key, buf, len - 1)) {
ast_debug(1, "DB: %s/%s not found in database.\n", args.family, args.key);
} else {
pbx_builtin_setvar_helper(chan, "DB_RESULT", buf);
}
return 0;
}
| static int function_db_write | ( | struct ast_channel * | chan, |
| const char * | cmd, | ||
| char * | parse, | ||
| const char * | value | ||
| ) | [static] |
Definition at line 159 of file func_db.c.
References args, AST_APP_ARG, ast_db_put(), AST_DECLARE_APP_ARGS, ast_log(), AST_NONSTANDARD_APP_ARGS, ast_strlen_zero(), and LOG_WARNING.
{
AST_DECLARE_APP_ARGS(args,
AST_APP_ARG(family);
AST_APP_ARG(key);
);
if (ast_strlen_zero(parse)) {
ast_log(LOG_WARNING, "DB requires an argument, DB(<family>/<key>)=<value>\n");
return -1;
}
AST_NONSTANDARD_APP_ARGS(args, parse, '/');
if (args.argc < 2) {
ast_log(LOG_WARNING, "DB requires an argument, DB(<family>/<key>)=value\n");
return -1;
}
if (ast_db_put(args.family, args.key, value)) {
ast_log(LOG_WARNING, "DB: Error writing value to database.\n");
}
return 0;
}
| static int load_module | ( | void | ) | [static] |
Definition at line 350 of file func_db.c.
References AST_CFE_READ, ast_custom_function_register, and ast_custom_function_register_escalating.
{
int res = 0;
res |= ast_custom_function_register(&db_function);
res |= ast_custom_function_register(&db_exists_function);
res |= ast_custom_function_register_escalating(&db_delete_function, AST_CFE_READ);
res |= ast_custom_function_register(&db_keys_function);
return res;
}
| static int unload_module | ( | void | ) | [static] |
Definition at line 338 of file func_db.c.
References ast_custom_function_unregister().
{
int res = 0;
res |= ast_custom_function_unregister(&db_function);
res |= ast_custom_function_unregister(&db_exists_function);
res |= ast_custom_function_unregister(&db_delete_function);
res |= ast_custom_function_unregister(&db_keys_function);
return res;
}
struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "Database (astdb) related dialplan functions" , .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, } [static] |
struct ast_module_info* ast_module_info = &__mod_info [static] |
struct ast_custom_function db_delete_function [static] |
{
.name = "DB_DELETE",
.read = function_db_delete,
.write = function_db_delete_write,
}
struct ast_custom_function db_exists_function [static] |
{
.name = "DB_EXISTS",
.read = function_db_exists,
.read_max = 2,
}
struct ast_custom_function db_function [static] |
{
.name = "DB",
.read = function_db_read,
.write = function_db_write,
}
struct ast_custom_function db_keys_function [static] |
{
.name = "DB_KEYS",
.read2 = function_db_keys,
}