Apache Portable Runtime
Loading...
Searching...
No Matches
apr_dbm.h
Go to the documentation of this file.
1/* Licensed to the Apache Software Foundation (ASF) under one or more
2 * contributor license agreements. See the NOTICE file distributed with
3 * this work for additional information regarding copyright ownership.
4 * The ASF licenses this file to You under the Apache License, Version 2.0
5 * (the "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef APR_DBM_H
18#define APR_DBM_H
19
20#include "apu.h"
21#include "apr.h"
22#include "apr_errno.h"
23#include "apu_errno.h"
24#include "apr_pools.h"
25#include "apr_file_info.h"
26
27#ifdef __cplusplus
28extern "C" {
29#endif
30
31/**
32 * @file apr_dbm.h
33 * @brief APR-UTIL DBM library
34 */
35/**
36 * @defgroup APR_Util_DBM DBM routines
37 * @ingroup APR
38 * @{
39 */
40/**
41 * Structure representing a dbm driver.
42 */
44
45/**
46 * Structure for referencing a dbm
47 */
48typedef struct apr_dbm_t apr_dbm_t;
49
50/**
51 * Structure for referencing the datum record within a dbm
52 */
53typedef struct
54{
55 /** pointer to the 'data' to retrieve/store in the DBM */
56 char *dptr;
57 /** size of the 'data' to retrieve/store in the DBM */
58 apr_size_t dsize;
60
61/* modes to open the DB */
62#define APR_DBM_READONLY 1 /**< open for read-only access */
63#define APR_DBM_READWRITE 2 /**< open for read-write access */
64#define APR_DBM_RWCREATE 3 /**< open for r/w, create if needed */
65#define APR_DBM_RWTRUNC 4 /**< open for r/w, truncating an existing
66 DB if present */
67
68/**
69 * apr_dm_get_driver: get the driver struct for a name
70 *
71 * If the driver cannot be found, or cannot be opened, details of the
72 * error are returned in apu_err_t.
73 *
74 * @param driver - pointer to driver struct.
75 * @param name - driver name
76 * @param result - result and error message on failure
77 * @param pool - (process) pool to register cleanup
78 * @return APR_SUCCESS for success
79 * @return APR_ENOTIMPL for no driver (when DSO not enabled)
80 * @return APR_EDSOOPEN if DSO driver file can't be opened
81 * @return APR_ESYMNOTFOUND if the driver file doesn't contain a driver
82 */
84 const char *name, const apu_err_t **result, apr_pool_t *pool);
85
86/**
87 * Open a dbm file by file name and type of DBM
88 * @param dbm The newly opened database
89 * @param type The type of the DBM (not all may be available at run time)
90 * <pre>
91 * db for Berkeley DB files
92 * lmdb for LMDB files
93 * gdbm for GDBM files
94 * ndbm for NDBM files
95 * sdbm for SDBM files (always available)
96 * default for the default DBM type
97 * </pre>
98 * @param name The dbm file name to open
99 * @param mode The flag value
100 * <PRE>
101 * APR_DBM_READONLY open for read-only access
102 * APR_DBM_READWRITE open for read-write access
103 * APR_DBM_RWCREATE open for r/w, create if needed
104 * APR_DBM_RWTRUNC open for r/w, truncate if already there
105 * </PRE>
106 * @param perm Permissions to apply to if created
107 * @param cntxt The pool to use when creating the dbm
108 * @remark The dbm name may not be a true file name, as many dbm packages
109 * append suffixes for seperate data and index files.
110 * @bug In apr-util 0.9 and 1.x, the type arg was case insensitive. This
111 * was highly inefficient, and as of 2.x the dbm name must be provided in
112 * the correct case (lower case for all bundled providers)
113 */
114
116 const char *name,
117 apr_int32_t mode, apr_fileperms_t perm,
118 apr_pool_t *cntxt);
119
120/**
121 * Open a dbm file by file name and driver
122 * @param pdb The newly opened database
123 * @param driver The dbm driver to use
124 * @param name The dbm file name to open
125 * @param mode The flag value
126 * <PRE>
127 * APR_DBM_READONLY open for read-only access
128 * APR_DBM_READWRITE open for read-write access
129 * APR_DBM_RWCREATE open for r/w, create if needed
130 * APR_DBM_RWTRUNC open for r/w, truncate if already there
131 * </PRE>
132 * @param perm Permissions to apply to if created
133 * @param pool The pool to use when creating the dbm
134 * @remark The dbm name may not be a true file name, as many dbm packages
135 * append suffixes for separate data and index files.
136 */
138 const apr_dbm_driver_t *driver,
139 const char *name, apr_int32_t mode,
141
142/**
143 * Open a dbm file by file name
144 * @param dbm The newly opened database
145 * @param name The dbm file name to open
146 * @param mode The flag value
147 * <PRE>
148 * APR_DBM_READONLY open for read-only access
149 * APR_DBM_READWRITE open for read-write access
150 * APR_DBM_RWCREATE open for r/w, create if needed
151 * APR_DBM_RWTRUNC open for r/w, truncate if already there
152 * </PRE>
153 * @param perm Permissions to apply to if created
154 * @param cntxt The pool to use when creating the dbm
155 * @remark The dbm name may not be a true file name, as many dbm packages
156 * append suffixes for separate data and index files.
157 * @warning DBM drivers do not guarantee thread-safe or cross-process
158 * locking; multiple threads or processes reading and writing
159 * concurrently to the database is not safe and results in
160 * undefined behaviour (likely database corruption and possible
161 * crashes).
162 */
164 apr_int32_t mode, apr_fileperms_t perm,
165 apr_pool_t *cntxt);
166
167/**
168 * Close a dbm file previously opened by apr_dbm_open
169 * @param dbm The database to close
170 */
172
173/**
174 * Fetch a dbm record value by key
175 * @param dbm The database
176 * @param key The key datum to find this record
177 * @param pvalue The value datum retrieved for this record
178 */
180 apr_datum_t *pvalue);
181/**
182 * Store a dbm record value by key
183 * @param dbm The database
184 * @param key The key datum to store this record by
185 * @param value The value datum to store in this record
186 */
188 apr_datum_t value);
189
190/**
191 * Delete a dbm record value by key
192 * @param dbm The database
193 * @param key The key datum of the record to delete
194 * @remark It is not an error to delete a non-existent record.
195 */
197
198/**
199 * Search for a key within the dbm
200 * @param dbm The database
201 * @param key The datum describing a key to test
202 */
204
205/**
206 * Retrieve the first record key from a dbm
207 * @param dbm The database
208 * @param pkey The key datum of the first record
209 */
211
212/**
213 * Retrieve the next record key from a dbm
214 * @param dbm The database
215 * @param pkey The key datum of the next record
216 */
218
219/**
220 * Proactively toss any memory associated with the apr_datum_t.
221 * @param dbm The database
222 * @param data The datum to free.
223 */
225
226/**
227 * Report more information when an apr_dbm function fails.
228 * @param dbm The database
229 * @param errcode A DBM-specific value for the error (for logging). If this
230 * isn't needed, it may be NULL.
231 * @param errbuf Location to store the error text
232 * @param errbufsize The size of the provided buffer
233 * @return The errbuf parameter, for convenience.
234 */
236 char *errbuf, apr_size_t errbufsize);
237/**
238 * If the specified file/path were passed to apr_dbm_open(), return the
239 * actual file/path names which would be (created and) used. At most, two
240 * files may be used; used2 may be NULL if only one file is used.
241 * @param pool The pool for allocating used1 and used2.
242 * @param type The type of DBM you require info on @see apr_dbm_open_ex
243 * @param pathname The path name to generate used-names from.
244 * @param used1 The first pathname used by the apr_dbm implementation.
245 * @param used2 The second pathname used by apr_dbm. If only one file is
246 * used by the specific implementation, this will be set to NULL.
247 * @return An error if the specified type is invalid.
248 * @remark The dbm file(s) don't need to exist. This function only manipulates
249 * the pathnames.
250 */
252 const char *type,
253 const char *pathname,
254 const char **used1,
255 const char **used2);
256
257/**
258 * If the specified file/path were passed to apr_dbm_open(), return the
259 * actual file/path names which would be (created and) used. At most, two
260 * files may be used; used2 may be NULL if only one file is used.
261 * @param pool The pool for allocating used1 and used2.
262 * @param pathname The path name to generate used-names from.
263 * @param used1 The first pathname used by the apr_dbm implementation.
264 * @param used2 The second pathname used by apr_dbm. If only one file is
265 * used by the specific implementation, this will be set to NULL.
266 * @remark The dbm file(s) don't need to exist. This function only manipulates
267 * the pathnames.
268 */
270 const char *pathname,
271 const char **used1,
272 const char **used2);
273
274/** @} */
275#ifdef __cplusplus
276}
277#endif
278
279#endif /* !APR_DBM_H */
APR Platform Definitions.
APR Error Codes.
APR File Information.
APR memory allocation.
APR-Util Error Codes.
apr_status_t apr_dbm_store(apr_dbm_t *dbm, apr_datum_t key, apr_datum_t value)
void apr_dbm_get_usednames(apr_pool_t *pool, const char *pathname, const char **used1, const char **used2)
int apr_dbm_exists(apr_dbm_t *dbm, apr_datum_t key)
apr_status_t apr_dbm_delete(apr_dbm_t *dbm, apr_datum_t key)
apr_status_t apr_dbm_open2(apr_dbm_t **pdb, const apr_dbm_driver_t *driver, const char *name, apr_int32_t mode, apr_fileperms_t perm, apr_pool_t *pool)
apr_status_t apr_dbm_get_usednames_ex(apr_pool_t *pool, const char *type, const char *pathname, const char **used1, const char **used2)
apr_status_t apr_dbm_nextkey(apr_dbm_t *dbm, apr_datum_t *pkey)
void apr_dbm_close(apr_dbm_t *dbm)
apr_status_t apr_dbm_open(apr_dbm_t **dbm, const char *name, apr_int32_t mode, apr_fileperms_t perm, apr_pool_t *cntxt)
apr_status_t apr_dbm_get_driver(const apr_dbm_driver_t **driver, const char *name, const apu_err_t **result, apr_pool_t *pool)
apr_status_t apr_dbm_fetch(apr_dbm_t *dbm, apr_datum_t key, apr_datum_t *pvalue)
void apr_dbm_freedatum(apr_dbm_t *dbm, apr_datum_t data)
char * apr_dbm_geterror(apr_dbm_t *dbm, int *errcode, char *errbuf, apr_size_t errbufsize)
apr_status_t apr_dbm_firstkey(apr_dbm_t *dbm, apr_datum_t *pkey)
apr_status_t apr_dbm_open_ex(apr_dbm_t **dbm, const char *type, const char *name, apr_int32_t mode, apr_fileperms_t perm, apr_pool_t *cntxt)
int apr_status_t
Definition apr_errno.h:44
apr_int32_t apr_fileperms_t
Definition apr_file_info.h:125
#define APR_DECLARE(type)
Definition apr.h:523
struct apr_pool_t apr_pool_t
Definition apr_pools.h:60
Definition apr_dbm.h:54
apr_size_t dsize
Definition apr_dbm.h:58
char * dptr
Definition apr_dbm.h:56
Definition apr_dbm_private.h:47
Definition apr_dbm_private.h:94
int errcode
Definition apr_dbm_private.h:102
const apr_dbm_driver_t * type
Definition apr_dbm_private.h:107
apr_pool_t * pool
Definition apr_dbm_private.h:96
Definition apu_errno.h:418