Asterisk - The Open Source Telephony Project GIT-master-f36a736
astdb.h
Go to the documentation of this file.
1/*
2 * Asterisk -- An open source telephony toolkit.
3 *
4 * Copyright (C) 1999 - 2005, Digium, Inc.
5 *
6 * Mark Spencer <markster@digium.com>
7 *
8 * See http://www.asterisk.org for more information about
9 * the Asterisk project. Please do not directly contact
10 * any of the maintainers of this project for assistance;
11 * the project provides a web site, mailing lists and IRC
12 * channels for your use.
13 *
14 * This program is free software, distributed under the terms of
15 * the GNU General Public License Version 2. See the LICENSE file
16 * at the top of the source tree.
17 */
18
19/*!
20 * \file
21 * \brief Persistent data storage (akin to *doze registry)
22 */
23
24#ifndef _ASTERISK_ASTDB_H
25#define _ASTERISK_ASTDB_H
26
27#if defined(__cplusplus) || defined(c_plusplus)
28extern "C" {
29#endif
30
33 char *key;
34 char data[0];
35};
36
37/*! \brief Get key value specified by family/key */
38int ast_db_get(const char *family, const char *key, char *value, int valuelen);
39
40/*!
41 * \brief Get key value specified by family/key as a heap allocated string.
42 *
43 * \details
44 * Given a \a family and \a key, sets \a out to a pointer to a heap
45 * allocated string. In the event of an error, \a out will be set to
46 * NULL. The string must be freed by calling ast_free().
47 *
48 * \retval -1 An error occurred
49 * \retval 0 Success
50 */
51int ast_db_get_allocated(const char *family, const char *key, char **out);
52
53/*!
54 * \brief Check if family/key exitsts
55 *
56 * \param family
57 * \param key
58 * \retval 1 if family/key exists
59 * \retval 0 if family/key does not exist or an error occurred
60 */
61int ast_db_exists(const char *family, const char *key);
62
63/*! \brief Store value addressed by family/key */
64int ast_db_put(const char *family, const char *key, const char *value);
65
66/*! \brief Delete entry in astdb */
67int ast_db_del(const char *family, const char *key);
68
69/*! \brief Same as ast_db_del, but with more stringent error checking
70 *
71 * \details
72 * Unlike ast_db_del, if the key does not exist in the first place,
73 * an error is emitted and -1 is returned.
74 *
75 * \retval -1 An error occured (including key not found to begin with)
76 * \retval 0 Successfully deleted
77 */
78int ast_db_del2(const char *family, const char *key);
79
80/*!
81 * \brief Delete one or more entries in astdb
82 *
83 * \details
84 * If both parameters are NULL, the entire database will be purged. If
85 * only keytree is NULL, all entries within the family will be purged.
86 * It is an error for keytree to have a value when family is NULL.
87 *
88 * \retval -1 An error occurred
89 * \retval >= 0 Number of records deleted
90 */
91int ast_db_deltree(const char *family, const char *keytree);
92
93/*!
94 * \brief Get a list of values within the astdb tree
95 *
96 * \details
97 * If family is specified, only those keys will be returned. If keytree
98 * is specified, subkeys are expected to exist (separated from the key with
99 * a slash). If subkeys do not exist and keytree is specified, the tree will
100 * consist of either a single entry or NULL will be returned.
101 *
102 * Resulting tree should be freed by passing the return value to ast_db_freetree()
103 * when usage is concluded.
104 */
105struct ast_db_entry *ast_db_gettree(const char *family, const char *keytree);
106
107/*!
108 * \brief Get a list of values with the given key prefix
109 *
110 * \param family The family to search under
111 * \param key_prefix The key prefix to search under
112 *
113 * \retval NULL An error occurred
114 */
115struct ast_db_entry *ast_db_gettree_by_prefix(const char *family, const char *key_prefix);
116
117/*! \brief Free structure created by ast_db_gettree() */
119
120#if defined(__cplusplus) || defined(c_plusplus)
121}
122#endif
123
124#endif /* _ASTERISK_ASTDB_H */
int ast_db_put(const char *family, const char *key, const char *value)
Store value addressed by family/key.
Definition: main/db.c:341
struct ast_db_entry * ast_db_gettree_by_prefix(const char *family, const char *key_prefix)
Get a list of values with the given key prefix.
Definition: main/db.c:673
int ast_db_del2(const char *family, const char *key)
Same as ast_db_del, but with more stringent error checking.
Definition: main/db.c:507
int ast_db_get_allocated(const char *family, const char *key, char **out)
Get key value specified by family/key as a heap allocated string.
Definition: main/db.c:437
int ast_db_get(const char *family, const char *key, char *value, int valuelen)
Get key value specified by family/key.
Definition: main/db.c:427
int ast_db_del(const char *family, const char *key)
Delete entry in astdb.
Definition: main/db.c:478
struct ast_db_entry * ast_db_gettree(const char *family, const char *keytree)
Get a list of values within the astdb tree.
Definition: main/db.c:641
int ast_db_deltree(const char *family, const char *keytree)
Delete one or more entries in astdb.
Definition: main/db.c:565
int ast_db_exists(const char *family, const char *key)
Check if family/key exitsts.
Definition: main/db.c:444
void ast_db_freetree(struct ast_db_entry *entry)
Free structure created by ast_db_gettree()
Definition: main/db.c:701
Definition: astdb.h:31
struct ast_db_entry * next
Definition: astdb.h:32
char * key
Definition: astdb.h:33
char data[0]
Definition: astdb.h:34
Definition: search.h:40
int value
Definition: syslog.c:37
FILE * out
Definition: utils/frame.c:33