apr_sdbm.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. /* Copyright 2000-2005 The Apache Software Foundation or its licensors, as
  2. * applicable.
  3. *
  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
  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. * sdbm - ndbm work-alike hashed database library
  18. * based on Per-Ake Larson's Dynamic Hashing algorithms. BIT 18 (1978).
  19. * author: oz@nexus.yorku.ca
  20. * status: ex-public domain
  21. */
  22. #ifndef APR_SDBM_H
  23. #define APR_SDBM_H
  24. #include "apu.h"
  25. #include "apr_errno.h"
  26. #include "apr_file_io.h" /* for apr_fileperms_t */
  27. /**
  28. * @file apr_sdbm.h
  29. * @brief apr-util SDBM library
  30. */
  31. /**
  32. * @defgroup APR_Util_DBM_SDBM SDBM library
  33. * @ingroup APR_Util_DBM
  34. * @{
  35. */
  36. /**
  37. * Structure for referencing an sdbm
  38. */
  39. typedef struct apr_sdbm_t apr_sdbm_t;
  40. /**
  41. * Structure for referencing the datum record within an sdbm
  42. */
  43. typedef struct {
  44. /** pointer to the data stored/retrieved */
  45. char *dptr;
  46. /** size of data */
  47. int dsize;
  48. } apr_sdbm_datum_t;
  49. /* The extensions used for the database files */
  50. /** SDBM Directory file extension */
  51. #define APR_SDBM_DIRFEXT ".dir"
  52. /** SDBM page file extension */
  53. #define APR_SDBM_PAGFEXT ".pag"
  54. /* flags to sdbm_store */
  55. #define APR_SDBM_INSERT 0 /**< Insert */
  56. #define APR_SDBM_REPLACE 1 /**< Replace */
  57. #define APR_SDBM_INSERTDUP 2 /**< Insert with duplicates */
  58. /**
  59. * Open an sdbm database by file name
  60. * @param db The newly opened database
  61. * @param name The sdbm file to open
  62. * @param mode The flag values (APR_READ and APR_BINARY flags are implicit)
  63. * <PRE>
  64. * APR_WRITE open for read-write access
  65. * APR_CREATE create the sdbm if it does not exist
  66. * APR_TRUNCATE empty the contents of the sdbm
  67. * APR_EXCL fail for APR_CREATE if the file exists
  68. * APR_DELONCLOSE delete the sdbm when closed
  69. * APR_SHARELOCK support locking across process/machines
  70. * </PRE>
  71. * @param perms Permissions to apply to if created
  72. * @param p The pool to use when creating the sdbm
  73. * @remark The sdbm name is not a true file name, as sdbm appends suffixes
  74. * for seperate data and index files.
  75. */
  76. APU_DECLARE(apr_status_t) apr_sdbm_open(apr_sdbm_t **db, const char *name,
  77. apr_int32_t mode,
  78. apr_fileperms_t perms, apr_pool_t *p);
  79. /**
  80. * Close an sdbm file previously opened by apr_sdbm_open
  81. * @param db The database to close
  82. */
  83. APU_DECLARE(apr_status_t) apr_sdbm_close(apr_sdbm_t *db);
  84. /**
  85. * Lock an sdbm database for concurency of multiple operations
  86. * @param db The database to lock
  87. * @param type The lock type
  88. * <PRE>
  89. * APR_FLOCK_SHARED
  90. * APR_FLOCK_EXCLUSIVE
  91. * </PRE>
  92. * @remark Calls to apr_sdbm_lock may be nested. All apr_sdbm functions
  93. * perform implicit locking. Since an APR_FLOCK_SHARED lock cannot be
  94. * portably promoted to an APR_FLOCK_EXCLUSIVE lock, apr_sdbm_store and
  95. * apr_sdbm_delete calls will fail if an APR_FLOCK_SHARED lock is held.
  96. * The apr_sdbm_lock call requires the database to be opened with the
  97. * APR_SHARELOCK mode value.
  98. */
  99. APU_DECLARE(apr_status_t) apr_sdbm_lock(apr_sdbm_t *db, int type);
  100. /**
  101. * Release an sdbm lock previously aquired by apr_sdbm_lock
  102. * @param db The database to unlock
  103. */
  104. APU_DECLARE(apr_status_t) apr_sdbm_unlock(apr_sdbm_t *db);
  105. /**
  106. * Fetch an sdbm record value by key
  107. * @param db The database
  108. * @param value The value datum retrieved for this record
  109. * @param key The key datum to find this record
  110. */
  111. APU_DECLARE(apr_status_t) apr_sdbm_fetch(apr_sdbm_t *db,
  112. apr_sdbm_datum_t *value,
  113. apr_sdbm_datum_t key);
  114. /**
  115. * Store an sdbm record value by key
  116. * @param db The database
  117. * @param key The key datum to store this record by
  118. * @param value The value datum to store in this record
  119. * @param opt The method used to store the record
  120. * <PRE>
  121. * APR_SDBM_INSERT return an error if the record exists
  122. * APR_SDBM_REPLACE overwrite any existing record for key
  123. * </PRE>
  124. */
  125. APU_DECLARE(apr_status_t) apr_sdbm_store(apr_sdbm_t *db, apr_sdbm_datum_t key,
  126. apr_sdbm_datum_t value, int opt);
  127. /**
  128. * Delete an sdbm record value by key
  129. * @param db The database
  130. * @param key The key datum of the record to delete
  131. * @remark It is not an error to delete a non-existent record.
  132. */
  133. APU_DECLARE(apr_status_t) apr_sdbm_delete(apr_sdbm_t *db,
  134. const apr_sdbm_datum_t key);
  135. /**
  136. * Retrieve the first record key from a dbm
  137. * @param db The database
  138. * @param key The key datum of the first record
  139. * @remark The keys returned are not ordered. To traverse the list of keys
  140. * for an sdbm opened with APR_SHARELOCK, the caller must use apr_sdbm_lock
  141. * prior to retrieving the first record, and hold the lock until after the
  142. * last call to apr_sdbm_nextkey.
  143. */
  144. APU_DECLARE(apr_status_t) apr_sdbm_firstkey(apr_sdbm_t *db, apr_sdbm_datum_t *key);
  145. /**
  146. * Retrieve the next record key from an sdbm
  147. * @param db The database
  148. * @param key The key datum of the next record
  149. */
  150. APU_DECLARE(apr_status_t) apr_sdbm_nextkey(apr_sdbm_t *db, apr_sdbm_datum_t *key);
  151. /**
  152. * Returns true if the sdbm database opened for read-only access
  153. * @param db The database to test
  154. */
  155. APU_DECLARE(int) apr_sdbm_rdonly(apr_sdbm_t *db);
  156. /** @} */
  157. #endif /* APR_SDBM_H */