apr_sdbm.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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. * 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. /* apr_ssize_t for release 2.0??? */
  48. int dsize;
  49. } apr_sdbm_datum_t;
  50. /* The extensions used for the database files */
  51. /** SDBM Directory file extension */
  52. #define APR_SDBM_DIRFEXT ".dir"
  53. /** SDBM page file extension */
  54. #define APR_SDBM_PAGFEXT ".pag"
  55. /* flags to sdbm_store */
  56. #define APR_SDBM_INSERT 0 /**< Insert */
  57. #define APR_SDBM_REPLACE 1 /**< Replace */
  58. #define APR_SDBM_INSERTDUP 2 /**< Insert with duplicates */
  59. /**
  60. * Open an sdbm database by file name
  61. * @param db The newly opened database
  62. * @param name The sdbm file to open
  63. * @param mode The flag values (APR_READ and APR_BINARY flags are implicit)
  64. * <PRE>
  65. * APR_WRITE open for read-write access
  66. * APR_CREATE create the sdbm if it does not exist
  67. * APR_TRUNCATE empty the contents of the sdbm
  68. * APR_EXCL fail for APR_CREATE if the file exists
  69. * APR_DELONCLOSE delete the sdbm when closed
  70. * APR_SHARELOCK support locking across process/machines
  71. * </PRE>
  72. * @param perms Permissions to apply to if created
  73. * @param p The pool to use when creating the sdbm
  74. * @remark The sdbm name is not a true file name, as sdbm appends suffixes
  75. * for seperate data and index files.
  76. */
  77. APU_DECLARE(apr_status_t) apr_sdbm_open(apr_sdbm_t **db, const char *name,
  78. apr_int32_t mode,
  79. apr_fileperms_t perms, apr_pool_t *p);
  80. /**
  81. * Close an sdbm file previously opened by apr_sdbm_open
  82. * @param db The database to close
  83. */
  84. APU_DECLARE(apr_status_t) apr_sdbm_close(apr_sdbm_t *db);
  85. /**
  86. * Lock an sdbm database for concurency of multiple operations
  87. * @param db The database to lock
  88. * @param type The lock type
  89. * <PRE>
  90. * APR_FLOCK_SHARED
  91. * APR_FLOCK_EXCLUSIVE
  92. * </PRE>
  93. * @remark Calls to apr_sdbm_lock may be nested. All apr_sdbm functions
  94. * perform implicit locking. Since an APR_FLOCK_SHARED lock cannot be
  95. * portably promoted to an APR_FLOCK_EXCLUSIVE lock, apr_sdbm_store and
  96. * apr_sdbm_delete calls will fail if an APR_FLOCK_SHARED lock is held.
  97. * The apr_sdbm_lock call requires the database to be opened with the
  98. * APR_SHARELOCK mode value.
  99. */
  100. APU_DECLARE(apr_status_t) apr_sdbm_lock(apr_sdbm_t *db, int type);
  101. /**
  102. * Release an sdbm lock previously aquired by apr_sdbm_lock
  103. * @param db The database to unlock
  104. */
  105. APU_DECLARE(apr_status_t) apr_sdbm_unlock(apr_sdbm_t *db);
  106. /**
  107. * Fetch an sdbm record value by key
  108. * @param db The database
  109. * @param value The value datum retrieved for this record
  110. * @param key The key datum to find this record
  111. */
  112. APU_DECLARE(apr_status_t) apr_sdbm_fetch(apr_sdbm_t *db,
  113. apr_sdbm_datum_t *value,
  114. apr_sdbm_datum_t key);
  115. /**
  116. * Store an sdbm record value by key
  117. * @param db The database
  118. * @param key The key datum to store this record by
  119. * @param value The value datum to store in this record
  120. * @param opt The method used to store the record
  121. * <PRE>
  122. * APR_SDBM_INSERT return an error if the record exists
  123. * APR_SDBM_REPLACE overwrite any existing record for key
  124. * </PRE>
  125. */
  126. APU_DECLARE(apr_status_t) apr_sdbm_store(apr_sdbm_t *db, apr_sdbm_datum_t key,
  127. apr_sdbm_datum_t value, int opt);
  128. /**
  129. * Delete an sdbm record value by key
  130. * @param db The database
  131. * @param key The key datum of the record to delete
  132. * @remark It is not an error to delete a non-existent record.
  133. */
  134. APU_DECLARE(apr_status_t) apr_sdbm_delete(apr_sdbm_t *db,
  135. const apr_sdbm_datum_t key);
  136. /**
  137. * Retrieve the first record key from a dbm
  138. * @param db The database
  139. * @param key The key datum of the first record
  140. * @remark The keys returned are not ordered. To traverse the list of keys
  141. * for an sdbm opened with APR_SHARELOCK, the caller must use apr_sdbm_lock
  142. * prior to retrieving the first record, and hold the lock until after the
  143. * last call to apr_sdbm_nextkey.
  144. */
  145. APU_DECLARE(apr_status_t) apr_sdbm_firstkey(apr_sdbm_t *db, apr_sdbm_datum_t *key);
  146. /**
  147. * Retrieve the next record key from an sdbm
  148. * @param db The database
  149. * @param key The key datum of the next record
  150. */
  151. APU_DECLARE(apr_status_t) apr_sdbm_nextkey(apr_sdbm_t *db, apr_sdbm_datum_t *key);
  152. /**
  153. * Returns true if the sdbm database opened for read-only access
  154. * @param db The database to test
  155. */
  156. APU_DECLARE(int) apr_sdbm_rdonly(apr_sdbm_t *db);
  157. /** @} */
  158. #endif /* APR_SDBM_H */