Asterisk - The Open Source Telephony Project  GIT-master-e8cda4b
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 Persistant 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)
28 extern "C" {
29 #endif
30 
31 struct ast_db_entry {
32  struct ast_db_entry *next;
33  char *key;
34  char data[0];
35 };
36 
37 /*! \brief Get key value specified by family/key */
38 int 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  */
51 int ast_db_get_allocated(const char *family, const char *key, char **out);
52 
53 /*! \brief Store value addressed by family/key */
54 int ast_db_put(const char *family, const char *key, const char *value);
55 
56 /*! \brief Delete entry in astdb */
57 int ast_db_del(const char *family, const char *key);
58 
59 /*!
60  * \brief Delete one or more entries in astdb
61  *
62  * \details
63  * If both parameters are NULL, the entire database will be purged. If
64  * only keytree is NULL, all entries within the family will be purged.
65  * It is an error for keytree to have a value when family is NULL.
66  *
67  * \retval -1 An error occurred
68  * \retval >= 0 Number of records deleted
69  */
70 int ast_db_deltree(const char *family, const char *keytree);
71 
72 /*!
73  * \brief Get a list of values within the astdb tree
74  *
75  * \details
76  * If family is specified, only those keys will be returned. If keytree
77  * is specified, subkeys are expected to exist (separated from the key with
78  * a slash). If subkeys do not exist and keytree is specified, the tree will
79  * consist of either a single entry or NULL will be returned.
80  *
81  * Resulting tree should be freed by passing the return value to ast_db_freetree()
82  * when usage is concluded.
83  */
84 struct ast_db_entry *ast_db_gettree(const char *family, const char *keytree);
85 
86 /*!
87  * \brief Get a list of values with the given key prefix
88  *
89  * \param family The family to search under
90  * \param key_prefix The key prefix to search under
91  *
92  * \retval NULL An error occurred
93  */
94 struct ast_db_entry *ast_db_gettree_by_prefix(const char *family, const char *key_prefix);
95 
96 /*! \brief Free structure created by ast_db_gettree() */
97 void ast_db_freetree(struct ast_db_entry *entry);
98 
99 #if defined(__cplusplus) || defined(c_plusplus)
100 }
101 #endif
102 
103 #endif /* _ASTERISK_ASTDB_H */
void ast_db_freetree(struct ast_db_entry *entry)
Free structure created by ast_db_gettree()
Definition: main/db.c:598
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:422
int value
Definition: syslog.c:37
struct ast_db_entry * next
Definition: astdb.h:32
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:571
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:531
Definition: astdb.h:31
char data[0]
Definition: astdb.h:34
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:412
FILE * out
Definition: utils/frame.c:33
int ast_db_del(const char *family, const char *key)
Delete entry in astdb.
Definition: main/db.c:429
Definition: search.h:40
int ast_db_put(const char *family, const char *key, const char *value)
Store value addressed by family/key.
Definition: main/db.c:327
int ast_db_deltree(const char *family, const char *keytree)
Delete one or more entries in astdb.
Definition: main/db.c:457
char * key
Definition: astdb.h:33