Mon Oct 8 12:39:22 2012

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_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 = "ac1f6a56484a8820659555499174e588" , .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, }
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 274 of file func_db.c.

static void __unreg_module ( void   )  [static]

Definition at line 274 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 211 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().

00213 {
00214    AST_DECLARE_APP_ARGS(args,
00215       AST_APP_ARG(family);
00216       AST_APP_ARG(key);
00217    );
00218 
00219    buf[0] = '\0';
00220 
00221    if (ast_strlen_zero(parse)) {
00222       ast_log(LOG_WARNING, "DB_DELETE requires an argument, DB_DELETE(<family>/<key>)\n");
00223       return -1;
00224    }
00225 
00226    AST_NONSTANDARD_APP_ARGS(args, parse, '/');
00227 
00228    if (args.argc < 2) {
00229       ast_log(LOG_WARNING, "DB_DELETE requires an argument, DB_DELETE(<family>/<key>)\n");
00230       return -1;
00231    }
00232 
00233    if (ast_db_get(args.family, args.key, buf, len - 1)) {
00234       ast_debug(1, "DB_DELETE: %s/%s not found in database.\n", args.family, args.key);
00235    } else {
00236       if (ast_db_del(args.family, args.key)) {
00237          ast_debug(1, "DB_DELETE: %s/%s could not be deleted from the database\n", args.family, args.key);
00238       }
00239    }
00240 
00241    pbx_builtin_setvar_helper(chan, "DB_RESULT", buf);
00242 
00243    return 0;
00244 }

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

Definition at line 173 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().

00175 {
00176    AST_DECLARE_APP_ARGS(args,
00177       AST_APP_ARG(family);
00178       AST_APP_ARG(key);
00179    );
00180 
00181    buf[0] = '\0';
00182 
00183    if (ast_strlen_zero(parse)) {
00184       ast_log(LOG_WARNING, "DB_EXISTS requires an argument, DB(<family>/<key>)\n");
00185       return -1;
00186    }
00187 
00188    AST_NONSTANDARD_APP_ARGS(args, parse, '/');
00189 
00190    if (args.argc < 2) {
00191       ast_log(LOG_WARNING, "DB_EXISTS requires an argument, DB(<family>/<key>)\n");
00192       return -1;
00193    }
00194 
00195    if (ast_db_get(args.family, args.key, buf, len - 1)) {
00196       strcpy(buf, "0");
00197    } else {
00198       pbx_builtin_setvar_helper(chan, "DB_RESULT", buf);
00199       strcpy(buf, "1");
00200    }
00201 
00202    return 0;
00203 }

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

Definition at line 109 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().

00111 {
00112    AST_DECLARE_APP_ARGS(args,
00113       AST_APP_ARG(family);
00114       AST_APP_ARG(key);
00115    );
00116 
00117    buf[0] = '\0';
00118 
00119    if (ast_strlen_zero(parse)) {
00120       ast_log(LOG_WARNING, "DB requires an argument, DB(<family>/<key>)\n");
00121       return -1;
00122    }
00123 
00124    AST_NONSTANDARD_APP_ARGS(args, parse, '/');
00125 
00126    if (args.argc < 2) {
00127       ast_log(LOG_WARNING, "DB requires an argument, DB(<family>/<key>)\n");
00128       return -1;
00129    }
00130 
00131    if (ast_db_get(args.family, args.key, buf, len - 1)) {
00132       ast_debug(1, "DB: %s/%s not found in database.\n", args.family, args.key);
00133    } else {
00134       pbx_builtin_setvar_helper(chan, "DB_RESULT", buf);
00135    }
00136 
00137    return 0;
00138 }

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

Definition at line 140 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.

00142 {
00143    AST_DECLARE_APP_ARGS(args,
00144       AST_APP_ARG(family);
00145       AST_APP_ARG(key);
00146    );
00147 
00148    if (ast_strlen_zero(parse)) {
00149       ast_log(LOG_WARNING, "DB requires an argument, DB(<family>/<key>)=<value>\n");
00150       return -1;
00151    }
00152 
00153    AST_NONSTANDARD_APP_ARGS(args, parse, '/');
00154 
00155    if (args.argc < 2) {
00156       ast_log(LOG_WARNING, "DB requires an argument, DB(<family>/<key>)=value\n");
00157       return -1;
00158    }
00159 
00160    if (ast_db_put(args.family, args.key, value)) {
00161       ast_log(LOG_WARNING, "DB: Error writing value to database.\n");
00162    }
00163 
00164    return 0;
00165 }

static int load_module ( void   )  [static]

Definition at line 263 of file func_db.c.

References ast_custom_function_register, db_delete_function, db_exists_function, and db_function.

00264 {
00265    int res = 0;
00266 
00267    res |= ast_custom_function_register(&db_function);
00268    res |= ast_custom_function_register(&db_exists_function);
00269    res |= ast_custom_function_register(&db_delete_function);
00270 
00271    return res;
00272 }

static int unload_module ( void   )  [static]

Definition at line 252 of file func_db.c.

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

00253 {
00254    int res = 0;
00255 
00256    res |= ast_custom_function_unregister(&db_function);
00257    res |= ast_custom_function_unregister(&db_exists_function);
00258    res |= ast_custom_function_unregister(&db_delete_function);
00259 
00260    return res;
00261 }


Variable Documentation

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

Definition at line 274 of file func_db.c.

struct ast_module_info* ast_module_info = &__mod_info [static]

Definition at line 274 of file func_db.c.

struct ast_custom_function db_delete_function [static]

Initial value:

 {
   .name = "DB_DELETE",
   .read = function_db_delete,
}

Definition at line 247 of file func_db.c.

Referenced by load_module(), and unload_module().

struct ast_custom_function db_exists_function [static]

Initial value:

 {
   .name = "DB_EXISTS",
   .read = function_db_exists,
   .read_max = 2,
}

Definition at line 205 of file func_db.c.

Referenced by load_module(), and unload_module().

struct ast_custom_function db_function [static]

Initial value:

 {
   .name = "DB",
   .read = function_db_read,
   .write = function_db_write,
}

Definition at line 167 of file func_db.c.

Referenced by load_module(), and unload_module().


Generated on Mon Oct 8 12:39:22 2012 for Asterisk - The Open Source Telephony Project by  doxygen 1.4.7