Mon Jun 27 16:51:14 2011

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 = "8586c2a7d357cb591cc3a6607a8f62d1" , .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 270 of file func_db.c.

static void __unreg_module ( void   )  [static]

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

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

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

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

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

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

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

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

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

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

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

static int load_module ( void   )  [static]

Definition at line 259 of file func_db.c.

References ast_custom_function_register, db_delete_function, db_exists_function, and db_function.

00260 {
00261    int res = 0;
00262 
00263    res |= ast_custom_function_register(&db_function);
00264    res |= ast_custom_function_register(&db_exists_function);
00265    res |= ast_custom_function_register(&db_delete_function);
00266 
00267    return res;
00268 }

static int unload_module ( void   )  [static]

Definition at line 248 of file func_db.c.

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

00249 {
00250    int res = 0;
00251 
00252    res |= ast_custom_function_unregister(&db_function);
00253    res |= ast_custom_function_unregister(&db_exists_function);
00254    res |= ast_custom_function_unregister(&db_delete_function);
00255 
00256    return res;
00257 }


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

Definition at line 270 of file func_db.c.

struct ast_module_info* ast_module_info = &__mod_info [static]

Definition at line 270 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 243 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 201 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 163 of file func_db.c.

Referenced by load_module(), and unload_module().


Generated on Mon Jun 27 16:51:14 2011 for Asterisk - The Open Source Telephony Project by  doxygen 1.4.7