1
/* Copyright 2000-2005 The Apache Software Foundation or its licensors, as
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
* you may not use this file except in compliance with the License.
6
* You may obtain a copy of the License at
8
* http://www.apache.org/licenses/LICENSE-2.0
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.
18
* sdbm - ndbm work-alike hashed database library
19
* based on Per-Ake Larson's Dynamic Hashing algorithms. BIT 18 (1978).
20
* author: oz@nexus.yorku.ca
21
* status: ex-public domain
28
#include "apr_errno.h"
29
#include "apr_file_io.h" /* for apr_fileperms_t */
33
* @brief apr-util SDBM library
36
* @defgroup APR_Util_DBM_SDBM SDBM library
37
* @ingroup APR_Util_DBM
42
* Structure for referencing an sdbm
44
typedef struct apr_sdbm_t apr_sdbm_t;
47
* Structure for referencing the datum record within an sdbm
50
/** pointer to the data stored/retrieved */
56
/* The extensions used for the database files */
57
/** SDBM Directory file extension */
58
#define APR_SDBM_DIRFEXT ".dir"
59
/** SDBM page file extension */
60
#define APR_SDBM_PAGFEXT ".pag"
62
/* flags to sdbm_store */
63
#define APR_SDBM_INSERT 0 /**< Insert */
64
#define APR_SDBM_REPLACE 1 /**< Replace */
65
#define APR_SDBM_INSERTDUP 2 /**< Insert with duplicates */
68
* Open an sdbm database by file name
69
* @param db The newly opened database
70
* @param name The sdbm file to open
71
* @param mode The flag values (APR_READ and APR_BINARY flags are implicit)
73
* APR_WRITE open for read-write access
74
* APR_CREATE create the sdbm if it does not exist
75
* APR_TRUNCATE empty the contents of the sdbm
76
* APR_EXCL fail for APR_CREATE if the file exists
77
* APR_DELONCLOSE delete the sdbm when closed
78
* APR_SHARELOCK support locking across process/machines
80
* @param perms Permissions to apply to if created
81
* @param p The pool to use when creating the sdbm
82
* @remark The sdbm name is not a true file name, as sdbm appends suffixes
83
* for seperate data and index files.
85
APU_DECLARE(apr_status_t) apr_sdbm_open(apr_sdbm_t **db, const char *name,
87
apr_fileperms_t perms, apr_pool_t *p);
90
* Close an sdbm file previously opened by apr_sdbm_open
91
* @param db The database to close
93
APU_DECLARE(apr_status_t) apr_sdbm_close(apr_sdbm_t *db);
96
* Lock an sdbm database for concurency of multiple operations
97
* @param db The database to lock
98
* @param type The lock type
101
* APR_FLOCK_EXCLUSIVE
103
* @remark Calls to apr_sdbm_lock may be nested. All apr_sdbm functions
104
* perform implicit locking. Since an APR_FLOCK_SHARED lock cannot be
105
* portably promoted to an APR_FLOCK_EXCLUSIVE lock, apr_sdbm_store and
106
* apr_sdbm_delete calls will fail if an APR_FLOCK_SHARED lock is held.
107
* The apr_sdbm_lock call requires the database to be opened with the
108
* APR_SHARELOCK mode value.
110
APU_DECLARE(apr_status_t) apr_sdbm_lock(apr_sdbm_t *db, int type);
113
* Release an sdbm lock previously aquired by apr_sdbm_lock
114
* @param db The database to unlock
116
APU_DECLARE(apr_status_t) apr_sdbm_unlock(apr_sdbm_t *db);
119
* Fetch an sdbm record value by key
120
* @param db The database
121
* @param value The value datum retrieved for this record
122
* @param key The key datum to find this record
124
APU_DECLARE(apr_status_t) apr_sdbm_fetch(apr_sdbm_t *db,
125
apr_sdbm_datum_t *value,
126
apr_sdbm_datum_t key);
129
* Store an sdbm record value by key
130
* @param db The database
131
* @param key The key datum to store this record by
132
* @param value The value datum to store in this record
133
* @param opt The method used to store the record
135
* APR_SDBM_INSERT return an error if the record exists
136
* APR_SDBM_REPLACE overwrite any existing record for key
139
APU_DECLARE(apr_status_t) apr_sdbm_store(apr_sdbm_t *db, apr_sdbm_datum_t key,
140
apr_sdbm_datum_t value, int opt);
143
* Delete an sdbm record value by key
144
* @param db The database
145
* @param key The key datum of the record to delete
146
* @remark It is not an error to delete a non-existent record.
148
APU_DECLARE(apr_status_t) apr_sdbm_delete(apr_sdbm_t *db,
149
const apr_sdbm_datum_t key);
152
* Retrieve the first record key from a dbm
153
* @param db The database
154
* @param key The key datum of the first record
155
* @remark The keys returned are not ordered. To traverse the list of keys
156
* for an sdbm opened with APR_SHARELOCK, the caller must use apr_sdbm_lock
157
* prior to retrieving the first record, and hold the lock until after the
158
* last call to apr_sdbm_nextkey.
160
APU_DECLARE(apr_status_t) apr_sdbm_firstkey(apr_sdbm_t *db, apr_sdbm_datum_t *key);
163
* Retrieve the next record key from an sdbm
164
* @param db The database
165
* @param key The key datum of the next record
167
APU_DECLARE(apr_status_t) apr_sdbm_nextkey(apr_sdbm_t *db, apr_sdbm_datum_t *key);
170
* Returns true if the sdbm database opened for read-only access
171
* @param db The database to test
173
APU_DECLARE(int) apr_sdbm_rdonly(apr_sdbm_t *db);
175
#endif /* APR_SDBM_H */