Wed Jan 8 2020 09:49:42

Asterisk developer's documentation


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 /*! \file
20  * \brief Persistant data storage (akin to *doze registry)
21  */
22 
23 #ifndef _ASTERISK_ASTDB_H
24 #define _ASTERISK_ASTDB_H
25 
26 #if defined(__cplusplus) || defined(c_plusplus)
27 extern "C" {
28 #endif
29 
30 struct ast_db_entry {
31  struct ast_db_entry *next;
32  char *key;
33  char data[0];
34 };
35 
36 /*!\brief Get key value specified by family/key */
37 int ast_db_get(const char *family, const char *key, char *out, int outlen);
38 
39 /*!\brief Get key value specified by family/key as a heap allocated string.
40  *
41  * Given a \a family and \a key, sets \a out to a pointer to a heap
42  * allocated string. In the event of an error, \a out will be set to
43  * NULL. The string must be freed by calling ast_free().
44  *
45  * \retval -1 An error occurred
46  * \retval 0 Success
47  */
48 int ast_db_get_allocated(const char *family, const char *key, char **out);
49 
50 /*!\brief Store value addressed by family/key */
51 int ast_db_put(const char *family, const char *key, const char *value);
52 
53 /*!\brief Delete entry in astdb */
54 int ast_db_del(const char *family, const char *key);
55 
56 /*!\brief Delete one or more entries in astdb
57  * If both parameters are NULL, the entire database will be purged. If
58  * only keytree is NULL, all entries within the family will be purged.
59  * It is an error for keytree to have a value when family is NULL.
60  *
61  * \retval -1 An error occurred
62  * \retval >= 0 Number of records deleted
63  */
64 int ast_db_deltree(const char *family, const char *keytree);
65 
66 /*!\brief Get a list of values within the astdb tree
67  * If family is specified, only those keys will be returned. If keytree
68  * is specified, subkeys are expected to exist (separated from the key with
69  * a slash). If subkeys do not exist and keytree is specified, the tree will
70  * consist of either a single entry or NULL will be returned.
71  *
72  * Resulting tree should be freed by passing the return value to ast_db_freetree()
73  * when usage is concluded.
74  */
75 struct ast_db_entry *ast_db_gettree(const char *family, const char *keytree);
76 
77 /*!\brief Free structure created by ast_db_gettree() */
78 void ast_db_freetree(struct ast_db_entry *entry);
79 
80 #if defined(__cplusplus) || defined(c_plusplus)
81 }
82 #endif
83 
84 #endif /* _ASTERISK_ASTDB_H */
int ast_db_get(const char *family, const char *key, char *out, int outlen)
Get key value specified by family/key.
Definition: db.c:348
void ast_db_freetree(struct ast_db_entry *entry)
Free structure created by ast_db_gettree()
Definition: db.c:656
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: db.c:358
int value
Definition: syslog.c:39
struct ast_db_entry * next
Definition: astdb.h:31
struct ast_db_entry * ast_db_gettree(const char *family, const char *keytree)
Get a list of values within the astdb tree If family is specified, only those keys will be returned...
Definition: db.c:631
Definition: astdb.h:30
char data[0]
Definition: astdb.h:33
int ast_db_del(const char *family, const char *key)
Delete entry in astdb.
Definition: db.c:365
int ast_db_put(const char *family, const char *key, const char *value)
Store value addressed by family/key.
Definition: db.c:260
int ast_db_deltree(const char *family, const char *keytree)
Delete one or more entries in astdb If both parameters are NULL, the entire database will be purged...
Definition: db.c:241
char * key
Definition: astdb.h:32