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 "apr_pools.h"
24#include "apr_file_info.h"
25
26#ifdef __cplusplus
27extern "C" {
28#endif
29
30/**
31 * @file apr_dbm.h
32 * @brief APR-UTIL DBM library
33 */
34/**
35 * @defgroup APR_Util_DBM DBM routines
36 * @ingroup APR_Util
37 * @{
38 */
39/**
40 * Structure for referencing a dbm
41 */
42typedef struct apr_dbm_t apr_dbm_t;
43
44/**
45 * Structure for referencing the datum record within a dbm
46 */
47typedef struct
48{
49 /** pointer to the 'data' to retrieve/store in the DBM */
50 char *dptr;
51 /** size of the 'data' to retrieve/store in the DBM */
52 apr_size_t dsize;
54
55/* modes to open the DB */
56#define APR_DBM_READONLY 1 /**< open for read-only access */
57#define APR_DBM_READWRITE 2 /**< open for read-write access */
58#define APR_DBM_RWCREATE 3 /**< open for r/w, create if needed */
59#define APR_DBM_RWTRUNC 4 /**< open for r/w, truncating an existing
60 DB if present */
61/**
62 * Open a dbm file by file name and type of DBM
63 * @param dbm The newly opened database
64 * @param type The type of the DBM (not all may be available at run time)
65 * <pre>
66 * db for Berkeley DB files
67 * lmdb for LMDB files
68 * gdbm for GDBM files
69 * ndbm for NDBM files
70 * sdbm for SDBM files (always available)
71 * default for the default DBM type
72 * </pre>
73 * @param name The dbm file name to open
74 * @param mode The flag value
75 * <PRE>
76 * APR_DBM_READONLY open for read-only access
77 * APR_DBM_READWRITE open for read-write access
78 * APR_DBM_RWCREATE open for r/w, create if needed
79 * APR_DBM_RWTRUNC open for r/w, truncate if already there
80 * </PRE>
81 * @param perm Permissions to apply to if created
82 * @param cntxt The pool to use when creating the dbm
83 * @remark The dbm name may not be a true file name, as many dbm packages
84 * append suffixes for seperate data and index files.
85 * @bug In apr-util 0.9 and 1.x, the type arg was case insensitive. This
86 * was highly inefficient, and as of 2.x the dbm name must be provided in
87 * the correct case (lower case for all bundled providers)
88 */
89
90APU_DECLARE(apr_status_t) apr_dbm_open_ex(apr_dbm_t **dbm, const char* type,
91 const char *name,
92 apr_int32_t mode, apr_fileperms_t perm,
93 apr_pool_t *cntxt);
94
95
96/**
97 * Open a dbm file by file name
98 * @param dbm The newly opened database
99 * @param name The dbm file name to open
100 * @param mode The flag value
101 * <PRE>
102 * APR_DBM_READONLY open for read-only access
103 * APR_DBM_READWRITE open for read-write access
104 * APR_DBM_RWCREATE open for r/w, create if needed
105 * APR_DBM_RWTRUNC open for r/w, truncate if already there
106 * </PRE>
107 * @param perm Permissions to apply to if created
108 * @param cntxt The pool to use when creating the dbm
109 * @remark The dbm name may not be a true file name, as many dbm packages
110 * append suffixes for seperate data and index files.
111 */
112APU_DECLARE(apr_status_t) apr_dbm_open(apr_dbm_t **dbm, const char *name,
113 apr_int32_t mode, apr_fileperms_t perm,
114 apr_pool_t *cntxt);
115
116/**
117 * Close a dbm file previously opened by apr_dbm_open
118 * @param dbm The database to close
119 */
120APU_DECLARE(void) apr_dbm_close(apr_dbm_t *dbm);
121
122/**
123 * Fetch a dbm record value by key
124 * @param dbm The database
125 * @param key The key datum to find this record
126 * @param pvalue The value datum retrieved for this record
127 */
129 apr_datum_t *pvalue);
130/**
131 * Store a dbm record value by key
132 * @param dbm The database
133 * @param key The key datum to store this record by
134 * @param value The value datum to store in this record
135 */
137 apr_datum_t value);
138
139/**
140 * Delete a dbm record value by key
141 * @param dbm The database
142 * @param key The key datum of the record to delete
143 * @remark It is not an error to delete a non-existent record.
144 */
146
147/**
148 * Search for a key within the dbm
149 * @param dbm The database
150 * @param key The datum describing a key to test
151 */
152APU_DECLARE(int) apr_dbm_exists(apr_dbm_t *dbm, apr_datum_t key);
153
154/**
155 * Retrieve the first record key from a dbm
156 * @param dbm The database
157 * @param pkey The key datum of the first record
158 */
160
161/**
162 * Retrieve the next record key from a dbm
163 * @param dbm The database
164 * @param pkey The key datum of the next record
165 */
167
168/**
169 * Proactively toss any memory associated with the apr_datum_t.
170 * @param dbm The database
171 * @param data The datum to free.
172 */
173APU_DECLARE(void) apr_dbm_freedatum(apr_dbm_t *dbm, apr_datum_t data);
174
175/**
176 * Report more information when an apr_dbm function fails.
177 * @param dbm The database
178 * @param errcode A DBM-specific value for the error (for logging). If this
179 * isn't needed, it may be NULL.
180 * @param errbuf Location to store the error text
181 * @param errbufsize The size of the provided buffer
182 * @return The errbuf parameter, for convenience.
183 */
184APU_DECLARE(char *) apr_dbm_geterror(apr_dbm_t *dbm, int *errcode,
185 char *errbuf, apr_size_t errbufsize);
186/**
187 * If the specified file/path were passed to apr_dbm_open(), return the
188 * actual file/path names which would be (created and) used. At most, two
189 * files may be used; used2 may be NULL if only one file is used.
190 * @param pool The pool for allocating used1 and used2.
191 * @param type The type of DBM you require info on @see apr_dbm_open_ex
192 * @param pathname The path name to generate used-names from.
193 * @param used1 The first pathname used by the apr_dbm implementation.
194 * @param used2 The second pathname used by apr_dbm. If only one file is
195 * used by the specific implementation, this will be set to NULL.
196 * @return An error if the specified type is invalid.
197 * @remark The dbm file(s) don't need to exist. This function only manipulates
198 * the pathnames.
199 */
201 const char *type,
202 const char *pathname,
203 const char **used1,
204 const char **used2);
205
206/**
207 * If the specified file/path were passed to apr_dbm_open(), return the
208 * actual file/path names which would be (created and) used. At most, two
209 * files may be used; used2 may be NULL if only one file is used.
210 * @param pool The pool for allocating used1 and used2.
211 * @param pathname The path name to generate used-names from.
212 * @param used1 The first pathname used by the apr_dbm implementation.
213 * @param used2 The second pathname used by apr_dbm. If only one file is
214 * used by the specific implementation, this will be set to NULL.
215 * @remark The dbm file(s) don't need to exist. This function only manipulates
216 * the pathnames.
217 */
218APU_DECLARE(void) apr_dbm_get_usednames(apr_pool_t *pool,
219 const char *pathname,
220 const char **used1,
221 const char **used2);
222
223/** @} */
224#ifdef __cplusplus
225}
226#endif
227
228#endif /* !APR_DBM_H */
APR Platform Definitions.
APR Error Codes.
APR File Information.
APR memory allocation.
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)
struct apr_dbm_t apr_dbm_t
Definition apr_dbm.h:42
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_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
struct apr_pool_t apr_pool_t
Definition apr_pools.h:60
Definition apr_dbm.h:48
apr_size_t dsize
Definition apr_dbm.h:52
char * dptr
Definition apr_dbm.h:50