Fri Jun 19 12:10:36 2009

Asterisk developer's documentation


func_db.c File Reference

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_exists (struct ast_channel *chan, const char *cmd, char *parse, char *buf, size_t len)
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_DEFAULT , .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 = "a9c98e5d177805051735cb5b0b16b0a0" , .load = load_module, .unload = unload_module, }
static struct ast_module_infoast_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


Detailed Description

Functions for interaction with the Asterisk database.

Author:
Russell Bryant <russelb@clemson.edu>

Definition in file func_db.c.


Function Documentation

static void __reg_module ( void   )  [static]

Definition at line 225 of file func_db.c.

static void __unreg_module ( void   )  [static]

Definition at line 225 of file func_db.c.

static int function_db_delete ( struct ast_channel chan,
const char *  cmd,
char *  parse,
char *  buf,
size_t  len 
) [static]

Definition at line 157 of file func_db.c.

References AST_APP_ARG, ast_db_del(), ast_db_get(), ast_debug, AST_DECLARE_APP_ARGS, ast_log(), AST_NONSTANDARD_APP_ARGS, ast_strlen_zero(), chan, LOG_WARNING, and pbx_builtin_setvar_helper().

00159 {
00160    AST_DECLARE_APP_ARGS(args,
00161               AST_APP_ARG(family);
00162               AST_APP_ARG(key);
00163    );
00164 
00165    buf[0] = '\0';
00166 
00167    if (ast_strlen_zero(parse)) {
00168       ast_log(LOG_WARNING, "DB_DELETE requires an argument, DB_DELETE(<family>/<key>)\n");
00169       return -1;
00170    }
00171 
00172    AST_NONSTANDARD_APP_ARGS(args, parse, '/');
00173 
00174    if (args.argc < 2) {
00175       ast_log(LOG_WARNING, "DB_DELETE requires an argument, DB_DELETE(<family>/<key>)\n");
00176       return -1;
00177    }
00178 
00179    if (ast_db_get(args.family, args.key, buf, len - 1)) {
00180       ast_debug(1, "DB_DELETE: %s/%s not found in database.\n", args.family, args.key);
00181    } else {
00182       if (ast_db_del(args.family, args.key)) {
00183          ast_debug(1, "DB_DELETE: %s/%s could not be deleted from the database\n", args.family, args.key);
00184       }
00185    }
00186    pbx_builtin_setvar_helper(chan, "DB_RESULT", buf);
00187 
00188    return 0;
00189 }

static int function_db_exists ( struct ast_channel chan,
const char *  cmd,
char *  parse,
char *  buf,
size_t  len 
) [static]

Definition at line 113 of file func_db.c.

References AST_APP_ARG, ast_db_get(), AST_DECLARE_APP_ARGS, ast_log(), AST_NONSTANDARD_APP_ARGS, ast_strlen_zero(), chan, LOG_WARNING, and pbx_builtin_setvar_helper().

00115 {
00116    AST_DECLARE_APP_ARGS(args,
00117               AST_APP_ARG(family);
00118               AST_APP_ARG(key);
00119    );
00120 
00121    buf[0] = '\0';
00122 
00123    if (ast_strlen_zero(parse)) {
00124       ast_log(LOG_WARNING, "DB_EXISTS requires an argument, DB(<family>/<key>)\n");
00125       return -1;
00126    }
00127 
00128    AST_NONSTANDARD_APP_ARGS(args, parse, '/');
00129 
00130    if (args.argc < 2) {
00131       ast_log(LOG_WARNING, "DB_EXISTS requires an argument, DB(<family>/<key>)\n");
00132       return -1;
00133    }
00134 
00135    if (ast_db_get(args.family, args.key, buf, len - 1))
00136       strcpy(buf, "0");
00137    else {
00138       pbx_builtin_setvar_helper(chan, "DB_RESULT", buf);
00139       strcpy(buf, "1");
00140    }
00141 
00142    return 0;
00143 }

static int function_db_read ( struct ast_channel chan,
const char *  cmd,
char *  parse,
char *  buf,
size_t  len 
) [static]

Definition at line 43 of file func_db.c.

References AST_APP_ARG, ast_db_get(), ast_debug, AST_DECLARE_APP_ARGS, ast_log(), AST_NONSTANDARD_APP_ARGS, ast_strlen_zero(), chan, LOG_WARNING, and pbx_builtin_setvar_helper().

00045 {
00046    AST_DECLARE_APP_ARGS(args,
00047               AST_APP_ARG(family);
00048               AST_APP_ARG(key);
00049    );
00050 
00051    buf[0] = '\0';
00052 
00053    if (ast_strlen_zero(parse)) {
00054       ast_log(LOG_WARNING, "DB requires an argument, DB(<family>/<key>)\n");
00055       return -1;
00056    }
00057 
00058    AST_NONSTANDARD_APP_ARGS(args, parse, '/');
00059 
00060    if (args.argc < 2) {
00061       ast_log(LOG_WARNING, "DB requires an argument, DB(<family>/<key>)\n");
00062       return -1;
00063    }
00064 
00065    if (ast_db_get(args.family, args.key, buf, len - 1)) {
00066       ast_debug(1, "DB: %s/%s not found in database.\n", args.family, args.key);
00067    } else
00068       pbx_builtin_setvar_helper(chan, "DB_RESULT", buf);
00069 
00070    return 0;
00071 }

static int function_db_write ( struct ast_channel chan,
const char *  cmd,
char *  parse,
const char *  value 
) [static]

Definition at line 73 of file func_db.c.

References AST_APP_ARG, ast_db_put(), AST_DECLARE_APP_ARGS, ast_log(), AST_NONSTANDARD_APP_ARGS, ast_strlen_zero(), and LOG_WARNING.

00075 {
00076    AST_DECLARE_APP_ARGS(args,
00077               AST_APP_ARG(family);
00078               AST_APP_ARG(key);
00079    );
00080 
00081    if (ast_strlen_zero(parse)) {
00082       ast_log(LOG_WARNING, "DB requires an argument, DB(<family>/<key>)=<value>\n");
00083       return -1;
00084    }
00085 
00086    AST_NONSTANDARD_APP_ARGS(args, parse, '/');
00087 
00088    if (args.argc < 2) {
00089       ast_log(LOG_WARNING, "DB requires an argument, DB(<family>/<key>)=value\n");
00090       return -1;
00091    }
00092 
00093    if (ast_db_put(args.family, args.key, (char *) value))
00094       ast_log(LOG_WARNING, "DB: Error writing value to database.\n");
00095 
00096    return 0;
00097 }

static int load_module ( void   )  [static]

Definition at line 214 of file func_db.c.

References ast_custom_function_register, db_delete_function, db_exists_function, and db_function.

00215 {
00216    int res = 0;
00217 
00218    res |= ast_custom_function_register(&db_function);
00219    res |= ast_custom_function_register(&db_exists_function);
00220    res |= ast_custom_function_register(&db_delete_function);
00221 
00222    return res;
00223 }

static int unload_module ( void   )  [static]

Definition at line 203 of file func_db.c.

References ast_custom_function_unregister(), db_delete_function, db_exists_function, and db_function.

00204 {
00205    int res = 0;
00206 
00207    res |= ast_custom_function_unregister(&db_function);
00208    res |= ast_custom_function_unregister(&db_exists_function);
00209    res |= ast_custom_function_unregister(&db_delete_function);
00210 
00211    return res;
00212 }


Variable Documentation

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

Definition at line 225 of file func_db.c.

struct ast_module_info* ast_module_info = &__mod_info [static]

Definition at line 225 of file func_db.c.

struct ast_custom_function db_delete_function [static]

Definition at line 192 of file func_db.c.

Referenced by load_module(), and unload_module().

struct ast_custom_function db_exists_function [static]

Definition at line 145 of file func_db.c.

Referenced by load_module(), and unload_module().

struct ast_custom_function db_function [static]

Definition at line 99 of file func_db.c.

Referenced by load_module(), and unload_module().


Generated on Fri Jun 19 12:10:36 2009 for Asterisk - the Open Source PBX by  doxygen 1.4.7