Asterisk.org: Developer Documentation (28 Oct 2009)

Wed Oct 28 15:48:56 2009

## Asterisk developer's documentation

# func_db.c File Reference

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

`#include <stdlib.h>`
`#include <string.h>`
`#include <sys/types.h>`
`#include <regex.h>`
`#include "asterisk.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

static char * | function_db_exists (struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len)
static char * | function_db_read (struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len)
static void | function_db_write (struct ast_channel *chan, char *cmd, char *data, const char *value)

## Variables

static struct ast_custom_function | db_exists_function
static struct ast_custom_function | db_function

## Detailed Description

Functions for interaction with the Asterisk database.

Definition in file func_db.c.

## Function Documentation

static char* function_db_exists | ( | struct ast_channel * | chan,
|  | char * | cmd,
|  | char * | data,
|  | char * | buf,
|  | size_t | len |
| ) |  |  | `[static]`

Definition at line 123 of file func_db.c.

References ast_app_separate_args(), ast_db_get(), ast_log(), ast_strdupa, ast_strlen_zero(), key(), LOG_WARNING, and pbx_builtin_setvar_helper().

    00124 {
    00125    int argc;
    00126    char *args;
    00127    char *argv[2];
    00128    char *family;
    00129    char *key;
    00130
    00131    if (ast_strlen_zero(data)) {
    00132       ast_log(LOG_WARNING, "DB_EXISTS requires an argument, DB(<family>/<key>)\n");
    00133       return buf;
    00134    }
    00135
    00136    args = ast_strdupa(data);
    00137    argc = ast_app_separate_args(args, '/', argv, sizeof(argv) / sizeof(argv[0]));
    00138
    00139    if (argc > 1) {
    00140       family = argv[0];
    00141       key = argv[1];
    00142    } else {
    00143       ast_log(LOG_WARNING, "DB_EXISTS requires an argument, DB(<family>/<key>)\n");
    00144       return buf;
    00145    }
    00146
    00147    if (ast_db_get(family, key, buf, len-1))
    00148       ast_copy_string(buf, "0", len);
    00149    else {
    00150       pbx_builtin_setvar_helper(chan, "DB_RESULT", buf);
    00151       ast_copy_string(buf, "1", len);
    00152    }
    00153
    00154    return buf;
    00155 }

static char* function_db_read | ( | struct ast_channel * | chan,
|  | char * | cmd,
|  | char * | data,
|  | char * | buf,
|  | size_t | len |
| ) |  |  | `[static]`

Definition at line 44 of file func_db.c.

References ast_app_separate_args(), ast_db_get(), ast_log(), ast_strdupa, ast_strlen_zero(), key(), LOG_DEBUG, LOG_WARNING, and pbx_builtin_setvar_helper().

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

static void function_db_write | ( | struct ast_channel * | chan,
|  | char * | cmd,
|  | char * | data,
|  | const char * | value |
| ) |  |  | `[static]`

Definition at line 77 of file func_db.c.

References ast_app_separate_args(), ast_db_put(), ast_log(), ast_strdupa, ast_strlen_zero(), key(), and LOG_WARNING.

    00078 {
    00079    int argc;
    00080    char *args;
    00081    char *argv[2];
    00082    char *family;
    00083    char *key;
    00084
    00085    if (ast_strlen_zero(data)) {
    00086       ast_log(LOG_WARNING, "DB requires an argument, DB(<family>/<key>)=<value>\n");
    00087       return;
    00088    }
    00089
    00090    args = ast_strdupa(data);
    00091    argc = ast_app_separate_args(args, '/', argv, sizeof(argv) / sizeof(argv[0]));
    00092
    00093    if (argc > 1) {
    00094       family = argv[0];
    00095       key = argv[1];
    00096    } else {
    00097       ast_log(LOG_WARNING, "DB requires an argument, DB(<family>/<key>)=value\n");
    00098       return;
    00099    }
    00100
    00101    if (ast_db_put(family, key, (char*)value)) {
    00102       ast_log(LOG_WARNING, "DB: Error writing value to database.\n");
    00103    }
    00104 }

## Variable Documentation

struct ast_custom_function db_exists_function`[static]`

Definition at line 160 of file func_db.c.

struct ast_custom_function db_function`[static]`

Definition at line 109 of file func_db.c.