Mon Aug 31 12:30:36 2015

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

 AST_MODULE_INFO_STANDARD (ASTERISK_GPL_KEY,"Database (astdb) related dialplan functions")
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_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_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

AST_MODULE_INFO_STANDARD ( ASTERISK_GPL_KEY  ,
"Database (astdb) related dialplan functions"   
)
static int function_db_delete ( struct ast_channel chan,
const char *  cmd,
char *  parse,
char *  buf,
size_t  len 
) [static]

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

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

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 256 of file func_db.c.

References function_db_delete().

00258 {
00259    /* Throwaway to hold the result from the read */
00260    char buf[128];
00261    return function_db_delete(chan, cmd, parse, buf, sizeof(buf));
00262 }

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

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

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

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

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

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

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

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

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

static int load_module ( void   )  [static]
static int unload_module ( void   )  [static]

Definition at line 270 of file func_db.c.

References ast_custom_function_unregister().

00271 {
00272    int res = 0;
00273 
00274    res |= ast_custom_function_unregister(&db_function);
00275    res |= ast_custom_function_unregister(&db_exists_function);
00276    res |= ast_custom_function_unregister(&db_delete_function);
00277 
00278    return res;
00279 }


Variable Documentation

Initial value:
 {
   .name = "DB_DELETE",
   .read = function_db_delete,
   .write = function_db_delete_write,
}

Definition at line 264 of file func_db.c.

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

Definition at line 211 of file func_db.c.

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

Definition at line 173 of file func_db.c.


Generated on 31 Aug 2015 for Asterisk - The Open Source Telephony Project by  doxygen 1.6.1