Apache Portable Runtime
|
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 /* apr_ssize_t for release 2.0??? */ 00054 int dsize; 00055 } apr_sdbm_datum_t; 00056 00057 /* The extensions used for the database files */ 00058 /** SDBM Directory file extension */ 00059 #define APR_SDBM_DIRFEXT ".dir" 00060 /** SDBM page file extension */ 00061 #define APR_SDBM_PAGFEXT ".pag" 00062 00063 /* flags to sdbm_store */ 00064 #define APR_SDBM_INSERT 0 /**< Insert */ 00065 #define APR_SDBM_REPLACE 1 /**< Replace */ 00066 #define APR_SDBM_INSERTDUP 2 /**< Insert with duplicates */ 00067 00068 /** 00069 * Open an sdbm database by file name 00070 * @param db The newly opened database 00071 * @param name The sdbm file to open 00072 * @param mode The flag values (APR_READ and APR_BINARY flags are implicit) 00073 * <PRE> 00074 * APR_WRITE open for read-write access 00075 * APR_CREATE create the sdbm if it does not exist 00076 * APR_TRUNCATE empty the contents of the sdbm 00077 * APR_EXCL fail for APR_CREATE if the file exists 00078 * APR_DELONCLOSE delete the sdbm when closed 00079 * APR_SHARELOCK support locking across process/machines 00080 * </PRE> 00081 * @param perms Permissions to apply to if created 00082 * @param p The pool to use when creating the sdbm 00083 * @remark The sdbm name is not a true file name, as sdbm appends suffixes 00084 * for seperate data and index files. 00085 */ 00086 APU_DECLARE(apr_status_t) apr_sdbm_open(apr_sdbm_t **db, const char *name, 00087 apr_int32_t mode, 00088 apr_fileperms_t perms, apr_pool_t *p); 00089 00090 /** 00091 * Close an sdbm file previously opened by apr_sdbm_open 00092 * @param db The database to close 00093 */ 00094 APU_DECLARE(apr_status_t) apr_sdbm_close(apr_sdbm_t *db); 00095 00096 /** 00097 * Lock an sdbm database for concurency of multiple operations 00098 * @param db The database to lock 00099 * @param type The lock type 00100 * <PRE> 00101 * APR_FLOCK_SHARED 00102 * APR_FLOCK_EXCLUSIVE 00103 * </PRE> 00104 * @remark Calls to apr_sdbm_lock may be nested. All apr_sdbm functions 00105 * perform implicit locking. Since an APR_FLOCK_SHARED lock cannot be 00106 * portably promoted to an APR_FLOCK_EXCLUSIVE lock, apr_sdbm_store and 00107 * apr_sdbm_delete calls will fail if an APR_FLOCK_SHARED lock is held. 00108 * The apr_sdbm_lock call requires the database to be opened with the 00109 * APR_SHARELOCK mode value. 00110 */ 00111 APU_DECLARE(apr_status_t) apr_sdbm_lock(apr_sdbm_t *db, int type); 00112 00113 /** 00114 * Release an sdbm lock previously aquired by apr_sdbm_lock 00115 * @param db The database to unlock 00116 */ 00117 APU_DECLARE(apr_status_t) apr_sdbm_unlock(apr_sdbm_t *db); 00118 00119 /** 00120 * Fetch an sdbm record value by key 00121 * @param db The database 00122 * @param value The value datum retrieved for this record 00123 * @param key The key datum to find this record 00124 */ 00125 APU_DECLARE(apr_status_t) apr_sdbm_fetch(apr_sdbm_t *db, 00126 apr_sdbm_datum_t *value, 00127 apr_sdbm_datum_t key); 00128 00129 /** 00130 * Store an sdbm record value by key 00131 * @param db The database 00132 * @param key The key datum to store this record by 00133 * @param value The value datum to store in this record 00134 * @param opt The method used to store the record 00135 * <PRE> 00136 * APR_SDBM_INSERT return an error if the record exists 00137 * APR_SDBM_REPLACE overwrite any existing record for key 00138 * </PRE> 00139 */ 00140 APU_DECLARE(apr_status_t) apr_sdbm_store(apr_sdbm_t *db, apr_sdbm_datum_t key, 00141 apr_sdbm_datum_t value, int opt); 00142 00143 /** 00144 * Delete an sdbm record value by key 00145 * @param db The database 00146 * @param key The key datum of the record to delete 00147 * @remark It is not an error to delete a non-existent record. 00148 */ 00149 APU_DECLARE(apr_status_t) apr_sdbm_delete(apr_sdbm_t *db, 00150 const apr_sdbm_datum_t key); 00151 00152 /** 00153 * Retrieve the first record key from a dbm 00154 * @param db The database 00155 * @param key The key datum of the first record 00156 * @remark The keys returned are not ordered. To traverse the list of keys 00157 * for an sdbm opened with APR_SHARELOCK, the caller must use apr_sdbm_lock 00158 * prior to retrieving the first record, and hold the lock until after the 00159 * last call to apr_sdbm_nextkey. 00160 */ 00161 APU_DECLARE(apr_status_t) apr_sdbm_firstkey(apr_sdbm_t *db, apr_sdbm_datum_t *key); 00162 00163 /** 00164 * Retrieve the next record key from an sdbm 00165 * @param db The database 00166 * @param key The key datum of the next record 00167 */ 00168 APU_DECLARE(apr_status_t) apr_sdbm_nextkey(apr_sdbm_t *db, apr_sdbm_datum_t *key); 00169 00170 /** 00171 * Returns true if the sdbm database opened for read-only access 00172 * @param db The database to test 00173 */ 00174 APU_DECLARE(int) apr_sdbm_rdonly(apr_sdbm_t *db); 00175 /** @} */ 00176 #endif /* APR_SDBM_H */