00001 /* Licensed to the Apache Software Foundation (ASF) under one or more 00002 * contributor license agreements. See the NOTICE file distributed with 00003 * this work for additional information regarding copyright ownership. 00004 * The ASF licenses this file to You under the Apache License, Version 2.0 00005 * (the "License"); you may not use this file except in compliance with 00006 * the License. You may obtain a copy of the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 */ 00016 00017 /* 00018 * sdbm - ndbm work-alike hashed database library 00019 * based on Per-Ake Larson's Dynamic Hashing algorithms. BIT 18 (1978). 00020 * author: oz@nexus.yorku.ca 00021 * status: ex-public domain 00022 */ 00023 00024 #ifndef APR_SDBM_H 00025 #define APR_SDBM_H 00026 00027 #include "apu.h" 00028 #include "apr_errno.h" 00029 #include "apr_file_io.h" /* for apr_fileperms_t */ 00030 00031 /** 00032 * @file apr_sdbm.h 00033 * @brief apr-util SDBM library 00034 */ 00035 /** 00036 * @defgroup APR_Util_DBM_SDBM SDBM library 00037 * @ingroup APR_Util_DBM 00038 * @{ 00039 */ 00040 00041 /** 00042 * Structure for referencing an sdbm 00043 */ 00044 typedef struct apr_sdbm_t apr_sdbm_t; 00045 00046 /** 00047 * Structure for referencing the datum record within an sdbm 00048 */ 00049 typedef struct { 00050 /** pointer to the data stored/retrieved */ 00051 char *dptr; 00052 /** size of data */ 00053 int dsize; 00054 } apr_sdbm_datum_t; 00055 00056 /* The extensions used for the database files */ 00057 /** SDBM Directory file extension */ 00058 #define APR_SDBM_DIRFEXT ".dir" 00059 /** SDBM page file extension */ 00060 #define APR_SDBM_PAGFEXT ".pag" 00061 00062 /* flags to sdbm_store */ 00063 #define APR_SDBM_INSERT 0 /**< Insert */ 00064 #define APR_SDBM_REPLACE 1 /**< Replace */ 00065 #define APR_SDBM_INSERTDUP 2 /**< Insert with duplicates */ 00066 00067 /** 00068 * Open an sdbm database by file name 00069 * @param db The newly opened database 00070 * @param name The sdbm file to open 00071 * @param mode The flag values (APR_READ and APR_BINARY flags are implicit) 00072 * <PRE> 00073 * APR_WRITE open for read-write access 00074 * APR_CREATE create the sdbm if it does not exist 00075 * APR_TRUNCATE empty the contents of the sdbm 00076 * APR_EXCL fail for APR_CREATE if the file exists 00077 * APR_DELONCLOSE delete the sdbm when closed 00078 * APR_SHARELOCK support locking across process/machines 00079 * </PRE> 00080 * @param perms Permissions to apply to if created 00081 * @param p The pool to use when creating the sdbm 00082 * @remark The sdbm name is not a true file name, as sdbm appends suffixes 00083 * for seperate data and index files. 00084 */ 00085 APU_DECLARE(apr_status_t) apr_sdbm_open(apr_sdbm_t **db, const char *name, 00086 apr_int32_t mode, 00087 apr_fileperms_t perms, apr_pool_t *p); 00088 00089 /** 00090 * Close an sdbm file previously opened by apr_sdbm_open 00091 * @param db The database to close 00092 */ 00093 APU_DECLARE(apr_status_t) apr_sdbm_close(apr_sdbm_t *db); 00094 00095 /** 00096 * Lock an sdbm database for concurency of multiple operations 00097 * @param db The database to lock 00098 * @param type The lock type 00099 * <PRE> 00100 * APR_FLOCK_SHARED 00101 * APR_FLOCK_EXCLUSIVE 00102 * </PRE> 00103 * @remark Calls to apr_sdbm_lock may be nested. All apr_sdbm functions 00104 * perform implicit locking. Since an APR_FLOCK_SHARED lock cannot be 00105 * portably promoted to an APR_FLOCK_EXCLUSIVE lock, apr_sdbm_store and 00106 * apr_sdbm_delete calls will fail if an APR_FLOCK_SHARED lock is held. 00107 * The apr_sdbm_lock call requires the database to be opened with the 00108 * APR_SHARELOCK mode value. 00109 */ 00110 APU_DECLARE(apr_status_t) apr_sdbm_lock(apr_sdbm_t *db, int type); 00111 00112 /** 00113 * Release an sdbm lock previously aquired by apr_sdbm_lock 00114 * @param db The database to unlock 00115 */ 00116 APU_DECLARE(apr_status_t) apr_sdbm_unlock(apr_sdbm_t *db); 00117 00118 /** 00119 * Fetch an sdbm record value by key 00120 * @param db The database 00121 * @param value The value datum retrieved for this record 00122 * @param key The key datum to find this record 00123 */ 00124 APU_DECLARE(apr_status_t) apr_sdbm_fetch(apr_sdbm_t *db, 00125 apr_sdbm_datum_t *value, 00126 apr_sdbm_datum_t key); 00127 00128 /** 00129 * Store an sdbm record value by key 00130 * @param db The database 00131 * @param key The key datum to store this record by 00132 * @param value The value datum to store in this record 00133 * @param opt The method used to store the record 00134 * <PRE> 00135 * APR_SDBM_INSERT return an error if the record exists 00136 * APR_SDBM_REPLACE overwrite any existing record for key 00137 * </PRE> 00138 */ 00139 APU_DECLARE(apr_status_t) apr_sdbm_store(apr_sdbm_t *db, apr_sdbm_datum_t key, 00140 apr_sdbm_datum_t value, int opt); 00141 00142 /** 00143 * Delete an sdbm record value by key 00144 * @param db The database 00145 * @param key The key datum of the record to delete 00146 * @remark It is not an error to delete a non-existent record. 00147 */ 00148 APU_DECLARE(apr_status_t) apr_sdbm_delete(apr_sdbm_t *db, 00149 const apr_sdbm_datum_t key); 00150 00151 /** 00152 * Retrieve the first record key from a dbm 00153 * @param db The database 00154 * @param key The key datum of the first record 00155 * @remark The keys returned are not ordered. To traverse the list of keys 00156 * for an sdbm opened with APR_SHARELOCK, the caller must use apr_sdbm_lock 00157 * prior to retrieving the first record, and hold the lock until after the 00158 * last call to apr_sdbm_nextkey. 00159 */ 00160 APU_DECLARE(apr_status_t) apr_sdbm_firstkey(apr_sdbm_t *db, apr_sdbm_datum_t *key); 00161 00162 /** 00163 * Retrieve the next record key from an sdbm 00164 * @param db The database 00165 * @param key The key datum of the next record 00166 */ 00167 APU_DECLARE(apr_status_t) apr_sdbm_nextkey(apr_sdbm_t *db, apr_sdbm_datum_t *key); 00168 00169 /** 00170 * Returns true if the sdbm database opened for read-only access 00171 * @param db The database to test 00172 */ 00173 APU_DECLARE(int) apr_sdbm_rdonly(apr_sdbm_t *db); 00174 /** @} */ 00175 #endif /* APR_SDBM_H */