Fri Aug 24 02:25:36 2007

Asterisk developer's documentation


func_db.c File Reference

Functions for interaction with the Asterisk database. More...

#include "asterisk.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <regex.h>
#include "asterisk/module.h"
#include "asterisk/channel.h"
#include "asterisk/pbx.h"
#include "asterisk/logger.h"
#include "asterisk/options.h"
#include "asterisk/utils.h"
#include "asterisk/app.h"
#include "asterisk/astdb.h"

Include dependency graph for func_db.c:

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, char *cmd, char *parse, char *buf, size_t len)
static int function_db_exists (struct ast_channel *chan, char *cmd, char *parse, char *buf, size_t len)
static int function_db_read (struct ast_channel *chan, char *cmd, char *parse, char *buf, size_t len)
static int function_db_write (struct ast_channel *chan, 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,
char *  cmd,
char *  parse,
char *  buf,
size_t  len 
) [static]

Definition at line 164 of file func_db.c.

References AST_APP_ARG, ast_db_del(), ast_db_get(), AST_DECLARE_APP_ARGS, ast_log(), AST_NONSTANDARD_APP_ARGS, ast_strlen_zero(), key(), LOG_DEBUG, LOG_WARNING, and pbx_builtin_setvar_helper().

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

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

Definition at line 120 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(), key(), LOG_WARNING, and pbx_builtin_setvar_helper().

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

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

Definition at line 49 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(), key(), LOG_DEBUG, LOG_WARNING, and pbx_builtin_setvar_helper().

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

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

Definition at line 80 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(), key(), and LOG_WARNING.

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

static int load_module ( void   )  [static]

Definition at line 222 of file func_db.c.

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

00223 {
00224    int res = 0;
00225 
00226    res |= ast_custom_function_register(&db_function);
00227    res |= ast_custom_function_register(&db_exists_function);
00228    res |= ast_custom_function_register(&db_delete_function);
00229 
00230    return res;
00231 }

static int unload_module ( void   )  [static]

Definition at line 211 of file func_db.c.

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

00212 {
00213    int res = 0;
00214 
00215    res |= ast_custom_function_unregister(&db_function);
00216    res |= ast_custom_function_unregister(&db_exists_function);
00217    res |= ast_custom_function_unregister(&db_delete_function);
00218 
00219    return res;
00220 }


Variable Documentation

struct ast_custom_function db_delete_function [static]

Definition at line 200 of file func_db.c.

Referenced by load_module(), and unload_module().

struct ast_custom_function db_exists_function [static]

Definition at line 152 of file func_db.c.

Referenced by load_module(), and unload_module().

struct ast_custom_function db_function [static]

Definition at line 106 of file func_db.c.

Referenced by load_module(), and unload_module().


Generated on Fri Aug 24 02:25:36 2007 for Asterisk - the Open Source PBX by  doxygen 1.5.1