apr_dbm.h 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  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. #ifndef APR_DBM_H
  17. #define APR_DBM_H
  18. #include "apu.h"
  19. #include "apr.h"
  20. #include "apr_errno.h"
  21. #include "apr_pools.h"
  22. #include "apr_file_info.h"
  23. #ifdef __cplusplus
  24. extern "C" {
  25. #endif
  26. /**
  27. * @file apr_dbm.h
  28. * @brief APR-UTIL DBM library
  29. */
  30. /**
  31. * @defgroup APR_Util_DBM DBM routines
  32. * @ingroup APR_Util
  33. * @{
  34. */
  35. /**
  36. * Structure for referencing a dbm
  37. */
  38. typedef struct apr_dbm_t apr_dbm_t;
  39. /**
  40. * Structure for referencing the datum record within a dbm
  41. */
  42. typedef struct
  43. {
  44. /** pointer to the 'data' to retrieve/store in the DBM */
  45. char *dptr;
  46. /** size of the 'data' to retrieve/store in the DBM */
  47. apr_size_t dsize;
  48. } apr_datum_t;
  49. /* modes to open the DB */
  50. #define APR_DBM_READONLY 1 /**< open for read-only access */
  51. #define APR_DBM_READWRITE 2 /**< open for read-write access */
  52. #define APR_DBM_RWCREATE 3 /**< open for r/w, create if needed */
  53. #define APR_DBM_RWTRUNC 4 /**< open for r/w, truncating an existing
  54. DB if present */
  55. /**
  56. * Open a dbm file by file name and type of DBM
  57. * @param dbm The newly opened database
  58. * @param type The type of the DBM (not all may be available at run time)
  59. * <pre>
  60. * db for Berkeley DB files
  61. * gdbm for GDBM files
  62. * ndbm for NDBM files
  63. * sdbm for SDBM files (always available)
  64. * default for the default DBM type
  65. * </pre>
  66. * @param name The dbm file name to open
  67. * @param mode The flag value
  68. * <PRE>
  69. * APR_DBM_READONLY open for read-only access
  70. * APR_DBM_READWRITE open for read-write access
  71. * APR_DBM_RWCREATE open for r/w, create if needed
  72. * APR_DBM_RWTRUNC open for r/w, truncate if already there
  73. * </PRE>
  74. * @param perm Permissions to apply to if created
  75. * @param cntxt The pool to use when creating the dbm
  76. * @remark The dbm name may not be a true file name, as many dbm packages
  77. * append suffixes for seperate data and index files.
  78. * @bug In apr-util 0.9 and 1.x, the type arg was case insensitive. This
  79. * was highly inefficient, and as of 2.x the dbm name must be provided in
  80. * the correct case (lower case for all bundled providers)
  81. */
  82. APU_DECLARE(apr_status_t) apr_dbm_open_ex(apr_dbm_t **dbm, const char* type,
  83. const char *name,
  84. apr_int32_t mode, apr_fileperms_t perm,
  85. apr_pool_t *cntxt);
  86. /**
  87. * Open a dbm file by file name
  88. * @param dbm The newly opened database
  89. * @param name The dbm file name to open
  90. * @param mode The flag value
  91. * <PRE>
  92. * APR_DBM_READONLY open for read-only access
  93. * APR_DBM_READWRITE open for read-write access
  94. * APR_DBM_RWCREATE open for r/w, create if needed
  95. * APR_DBM_RWTRUNC open for r/w, truncate if already there
  96. * </PRE>
  97. * @param perm Permissions to apply to if created
  98. * @param cntxt The pool to use when creating the dbm
  99. * @remark The dbm name may not be a true file name, as many dbm packages
  100. * append suffixes for seperate data and index files.
  101. */
  102. APU_DECLARE(apr_status_t) apr_dbm_open(apr_dbm_t **dbm, const char *name,
  103. apr_int32_t mode, apr_fileperms_t perm,
  104. apr_pool_t *cntxt);
  105. /**
  106. * Close a dbm file previously opened by apr_dbm_open
  107. * @param dbm The database to close
  108. */
  109. APU_DECLARE(void) apr_dbm_close(apr_dbm_t *dbm);
  110. /**
  111. * Fetch a dbm record value by key
  112. * @param dbm The database
  113. * @param key The key datum to find this record
  114. * @param pvalue The value datum retrieved for this record
  115. */
  116. APU_DECLARE(apr_status_t) apr_dbm_fetch(apr_dbm_t *dbm, apr_datum_t key,
  117. apr_datum_t *pvalue);
  118. /**
  119. * Store a dbm record value by key
  120. * @param dbm The database
  121. * @param key The key datum to store this record by
  122. * @param value The value datum to store in this record
  123. */
  124. APU_DECLARE(apr_status_t) apr_dbm_store(apr_dbm_t *dbm, apr_datum_t key,
  125. apr_datum_t value);
  126. /**
  127. * Delete a dbm record value by key
  128. * @param dbm The database
  129. * @param key The key datum of the record to delete
  130. * @remark It is not an error to delete a non-existent record.
  131. */
  132. APU_DECLARE(apr_status_t) apr_dbm_delete(apr_dbm_t *dbm, apr_datum_t key);
  133. /**
  134. * Search for a key within the dbm
  135. * @param dbm The database
  136. * @param key The datum describing a key to test
  137. */
  138. APU_DECLARE(int) apr_dbm_exists(apr_dbm_t *dbm, apr_datum_t key);
  139. /**
  140. * Retrieve the first record key from a dbm
  141. * @param dbm The database
  142. * @param pkey The key datum of the first record
  143. */
  144. APU_DECLARE(apr_status_t) apr_dbm_firstkey(apr_dbm_t *dbm, apr_datum_t *pkey);
  145. /**
  146. * Retrieve the next record key from a dbm
  147. * @param dbm The database
  148. * @param pkey The key datum of the next record
  149. */
  150. APU_DECLARE(apr_status_t) apr_dbm_nextkey(apr_dbm_t *dbm, apr_datum_t *pkey);
  151. /**
  152. * Proactively toss any memory associated with the apr_datum_t.
  153. * @param dbm The database
  154. * @param data The datum to free.
  155. */
  156. APU_DECLARE(void) apr_dbm_freedatum(apr_dbm_t *dbm, apr_datum_t data);
  157. /**
  158. * Report more information when an apr_dbm function fails.
  159. * @param dbm The database
  160. * @param errcode A DBM-specific value for the error (for logging). If this
  161. * isn't needed, it may be NULL.
  162. * @param errbuf Location to store the error text
  163. * @param errbufsize The size of the provided buffer
  164. * @return The errbuf parameter, for convenience.
  165. */
  166. APU_DECLARE(char *) apr_dbm_geterror(apr_dbm_t *dbm, int *errcode,
  167. char *errbuf, apr_size_t errbufsize);
  168. /**
  169. * If the specified file/path were passed to apr_dbm_open(), return the
  170. * actual file/path names which would be (created and) used. At most, two
  171. * files may be used; used2 may be NULL if only one file is used.
  172. * @param pool The pool for allocating used1 and used2.
  173. * @param type The type of DBM you require info on @see apr_dbm_open_ex
  174. * @param pathname The path name to generate used-names from.
  175. * @param used1 The first pathname used by the apr_dbm implementation.
  176. * @param used2 The second pathname used by apr_dbm. If only one file is
  177. * used by the specific implementation, this will be set to NULL.
  178. * @return An error if the specified type is invalid.
  179. * @remark The dbm file(s) don't need to exist. This function only manipulates
  180. * the pathnames.
  181. */
  182. APU_DECLARE(apr_status_t) apr_dbm_get_usednames_ex(apr_pool_t *pool,
  183. const char *type,
  184. const char *pathname,
  185. const char **used1,
  186. const char **used2);
  187. /**
  188. * If the specified file/path were passed to apr_dbm_open(), return the
  189. * actual file/path names which would be (created and) used. At most, two
  190. * files may be used; used2 may be NULL if only one file is used.
  191. * @param pool The pool for allocating used1 and used2.
  192. * @param pathname The path name to generate used-names from.
  193. * @param used1 The first pathname used by the apr_dbm implementation.
  194. * @param used2 The second pathname used by apr_dbm. If only one file is
  195. * used by the specific implementation, this will be set to NULL.
  196. * @remark The dbm file(s) don't need to exist. This function only manipulates
  197. * the pathnames.
  198. */
  199. APU_DECLARE(void) apr_dbm_get_usednames(apr_pool_t *pool,
  200. const char *pathname,
  201. const char **used1,
  202. const char **used2);
  203. /** @} */
  204. #ifdef __cplusplus
  205. }
  206. #endif
  207. #endif /* !APR_DBM_H */