Apache Portable Runtime
apr_sdbm.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 /*
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
22  */
23 
24 #ifndef APR_SDBM_H
25 #define APR_SDBM_H
26 
27 #include "apu.h"
28 #include "apr_errno.h"
29 #include "apr_file_io.h" /* for apr_fileperms_t */
30 
31 /**
32  * @file apr_sdbm.h
33  * @brief apr-util SDBM library
34  */
35 /**
36  * @defgroup APR_Util_DBM_SDBM SDBM library
37  * @ingroup APR_Util_DBM
38  * @{
39  */
40 
41 /**
42  * Structure for referencing an sdbm
43  */
44 typedef struct apr_sdbm_t apr_sdbm_t;
45 
46 /**
47  * Structure for referencing the datum record within an sdbm
48  */
49 typedef struct {
50  /** pointer to the data stored/retrieved */
51  char *dptr;
52  /** size of data */
53  /* apr_ssize_t for release 2.0??? */
54  int dsize;
56 
57 /* The extensions used for the database files */
58 /** SDBM Directory file extension */
59 #define APR_SDBM_DIRFEXT ".dir"
60 /** SDBM page file extension */
61 #define APR_SDBM_PAGFEXT ".pag"
62 
63 /* flags to sdbm_store */
64 #define APR_SDBM_INSERT 0 /**< Insert */
65 #define APR_SDBM_REPLACE 1 /**< Replace */
66 #define APR_SDBM_INSERTDUP 2 /**< Insert with duplicates */
67 
68 /**
69  * Open an sdbm database by file name
70  * @param db The newly opened database
71  * @param name The sdbm file to open
72  * @param mode The flag values (APR_FOPEN_READ and APR_FOPEN_BINARY flags are
73  * implicit)
74  * <PRE>
75  * APR_FOPEN_WRITE open for read-write access
76  * APR_FOPEN_CREATE create the sdbm if it does not exist
77  * APR_FOPEN_TRUNCATE empty the contents of the sdbm
78  * APR_FOPEN_EXCL fail for APR_FOPEN_CREATE if the file exists
79  * APR_FOPEN_DELONCLOSE delete the sdbm when closed
80  * APR_FOPEN_SHARELOCK support locking across process/machines
81  * </PRE>
82  * @param perms Permissions to apply to if created
83  * @param p The pool to use when creating the sdbm
84  * @remark The sdbm name is not a true file name, as sdbm appends suffixes
85  * for seperate data and index files.
86  */
87 APR_DECLARE(apr_status_t) apr_sdbm_open(apr_sdbm_t **db, const char *name,
88  apr_int32_t mode,
89  apr_fileperms_t perms, apr_pool_t *p);
90 
91 /**
92  * Close an sdbm file previously opened by apr_sdbm_open
93  * @param db The database to close
94  */
96 
97 /**
98  * Lock an sdbm database for concurency of multiple operations
99  * @param db The database to lock
100  * @param type The lock type
101  * <PRE>
102  * APR_FLOCK_SHARED
103  * APR_FLOCK_EXCLUSIVE
104  * </PRE>
105  * @remark Calls to apr_sdbm_lock may be nested. All apr_sdbm functions
106  * perform implicit locking. Since an APR_FLOCK_SHARED lock cannot be
107  * portably promoted to an APR_FLOCK_EXCLUSIVE lock, apr_sdbm_store and
108  * apr_sdbm_delete calls will fail if an APR_FLOCK_SHARED lock is held.
109  * The apr_sdbm_lock call requires the database to be opened with the
110  * APR_FOPEN_SHARELOCK mode value.
111  */
113 
114 /**
115  * Release an sdbm lock previously aquired by apr_sdbm_lock
116  * @param db The database to unlock
117  */
119 
120 /**
121  * Fetch an sdbm record value by key
122  * @param db The database
123  * @param value The value datum retrieved for this record
124  * @param key The key datum to find this record
125  */
127  apr_sdbm_datum_t *value,
128  apr_sdbm_datum_t key);
129 
130 /**
131  * Store an sdbm record value by key
132  * @param db 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  * @param opt The method used to store the record
136  * <PRE>
137  * APR_SDBM_INSERT return an error if the record exists
138  * APR_SDBM_REPLACE overwrite any existing record for key
139  * </PRE>
140  */
142  apr_sdbm_datum_t value, int opt);
143 
144 /**
145  * Delete an sdbm record value by key
146  * @param db The database
147  * @param key The key datum of the record to delete
148  * @remark It is not an error to delete a non-existent record.
149  */
151  const apr_sdbm_datum_t key);
152 
153 /**
154  * Retrieve the first record key from a dbm
155  * @param db The database
156  * @param key The key datum of the first record
157  * @remark The keys returned are not ordered. To traverse the list of keys
158  * for an sdbm opened with APR_FOPEN_SHARELOCK, the caller must use apr_sdbm_lock
159  * prior to retrieving the first record, and hold the lock until after the
160  * last call to apr_sdbm_nextkey.
161  */
163 
164 /**
165  * Retrieve the next record key from an sdbm
166  * @param db The database
167  * @param key The key datum of the next record
168  */
170 
171 /**
172  * Returns true if the sdbm database opened for read-only access
173  * @param db The database to test
174  */
176 /** @} */
177 #endif /* APR_SDBM_H */
char * dptr
Definition: apr_sdbm.h:51
apr_status_t apr_sdbm_store(apr_sdbm_t *db, apr_sdbm_datum_t key, apr_sdbm_datum_t value, int opt)
int dsize
Definition: apr_sdbm.h:54
Definition: apr_sdbm.h:49
apr_status_t apr_sdbm_open(apr_sdbm_t **db, const char *name, apr_int32_t mode, apr_fileperms_t perms, apr_pool_t *p)
apr_status_t apr_sdbm_unlock(apr_sdbm_t *db)
apr_status_t apr_sdbm_lock(apr_sdbm_t *db, int type)
APR File I/O Handling.
apr_status_t apr_sdbm_nextkey(apr_sdbm_t *db, apr_sdbm_datum_t *key)
apr_status_t apr_sdbm_delete(apr_sdbm_t *db, const apr_sdbm_datum_t key)
apr_int32_t apr_fileperms_t
Definition: apr_file_info.h:125
apr_status_t apr_sdbm_fetch(apr_sdbm_t *db, apr_sdbm_datum_t *value, apr_sdbm_datum_t key)
APR Error Codes.
#define APR_DECLARE(type)
Definition: apr.h:500
Definition: sdbm_private.h:49
apr_status_t apr_sdbm_close(apr_sdbm_t *db)
apr_status_t apr_sdbm_firstkey(apr_sdbm_t *db, apr_sdbm_datum_t *key)
struct apr_pool_t apr_pool_t
Definition: apr_pools.h:60
int apr_status_t
Definition: apr_errno.h:44
int apr_sdbm_rdonly(apr_sdbm_t *db)