2
0

apr_dbm.h 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  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. #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. * GDBM for GDBM files
  61. * SDBM for SDBM files
  62. * DB for berkeley DB files
  63. * NDBM for NDBM files
  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. */
  79. APU_DECLARE(apr_status_t) apr_dbm_open_ex(apr_dbm_t **dbm, const char* type,
  80. const char *name,
  81. apr_int32_t mode, apr_fileperms_t perm,
  82. apr_pool_t *cntxt);
  83. /**
  84. * Open a dbm file by file name
  85. * @param dbm The newly opened database
  86. * @param name The dbm file name to open
  87. * @param mode The flag value
  88. * <PRE>
  89. * APR_DBM_READONLY open for read-only access
  90. * APR_DBM_READWRITE open for read-write access
  91. * APR_DBM_RWCREATE open for r/w, create if needed
  92. * APR_DBM_RWTRUNC open for r/w, truncate if already there
  93. * </PRE>
  94. * @param perm Permissions to apply to if created
  95. * @param cntxt The pool to use when creating the dbm
  96. * @remark The dbm name may not be a true file name, as many dbm packages
  97. * append suffixes for seperate data and index files.
  98. */
  99. APU_DECLARE(apr_status_t) apr_dbm_open(apr_dbm_t **dbm, const char *name,
  100. apr_int32_t mode, apr_fileperms_t perm,
  101. apr_pool_t *cntxt);
  102. /**
  103. * Close a dbm file previously opened by apr_dbm_open
  104. * @param dbm The database to close
  105. */
  106. APU_DECLARE(void) apr_dbm_close(apr_dbm_t *dbm);
  107. /**
  108. * Fetch a dbm record value by key
  109. * @param dbm The database
  110. * @param key The key datum to find this record
  111. * @param pvalue The value datum retrieved for this record
  112. */
  113. APU_DECLARE(apr_status_t) apr_dbm_fetch(apr_dbm_t *dbm, apr_datum_t key,
  114. apr_datum_t *pvalue);
  115. /**
  116. * Store a dbm record value by key
  117. * @param dbm 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. */
  121. APU_DECLARE(apr_status_t) apr_dbm_store(apr_dbm_t *dbm, apr_datum_t key,
  122. apr_datum_t value);
  123. /**
  124. * Delete a dbm record value by key
  125. * @param dbm The database
  126. * @param key The key datum of the record to delete
  127. * @remark It is not an error to delete a non-existent record.
  128. */
  129. APU_DECLARE(apr_status_t) apr_dbm_delete(apr_dbm_t *dbm, apr_datum_t key);
  130. /**
  131. * Search for a key within the dbm
  132. * @param dbm The database
  133. * @param key The datum describing a key to test
  134. */
  135. APU_DECLARE(int) apr_dbm_exists(apr_dbm_t *dbm, apr_datum_t key);
  136. /**
  137. * Retrieve the first record key from a dbm
  138. * @param dbm The database
  139. * @param pkey The key datum of the first record
  140. */
  141. APU_DECLARE(apr_status_t) apr_dbm_firstkey(apr_dbm_t *dbm, apr_datum_t *pkey);
  142. /**
  143. * Retrieve the next record key from a dbm
  144. * @param dbm The database
  145. * @param pkey The key datum of the next record
  146. */
  147. APU_DECLARE(apr_status_t) apr_dbm_nextkey(apr_dbm_t *dbm, apr_datum_t *pkey);
  148. /**
  149. * Proactively toss any memory associated with the apr_datum_t.
  150. * @param dbm The database
  151. * @param data The datum to free.
  152. */
  153. APU_DECLARE(void) apr_dbm_freedatum(apr_dbm_t *dbm, apr_datum_t data);
  154. /**
  155. * Report more information when an apr_dbm function fails.
  156. * @param dbm The database
  157. * @param errcode A DBM-specific value for the error (for logging). If this
  158. * isn't needed, it may be NULL.
  159. * @param errbuf Location to store the error text
  160. * @param errbufsize The size of the provided buffer
  161. * @return The errbuf parameter, for convenience.
  162. */
  163. APU_DECLARE(char *) apr_dbm_geterror(apr_dbm_t *dbm, int *errcode,
  164. char *errbuf, apr_size_t errbufsize);
  165. /**
  166. * If the specified file/path were passed to apr_dbm_open(), return the
  167. * actual file/path names which would be (created and) used. At most, two
  168. * files may be used; used2 may be NULL if only one file is used.
  169. * @param pool The pool for allocating used1 and used2.
  170. * @param type The type of DBM you require info on
  171. * @param pathname The path name to generate used-names from.
  172. * @param used1 The first pathname used by the apr_dbm implementation.
  173. * @param used2 The second pathname used by apr_dbm. If only one file is
  174. * used by the specific implementation, this will be set to NULL.
  175. * @return An error if the specified type is invalid.
  176. * @remark The dbm file(s) don't need to exist. This function only manipulates
  177. * the pathnames.
  178. */
  179. APU_DECLARE(apr_status_t) apr_dbm_get_usednames_ex(apr_pool_t *pool,
  180. const char *type,
  181. const char *pathname,
  182. const char **used1,
  183. const char **used2);
  184. /**
  185. * If the specified file/path were passed to apr_dbm_open(), return the
  186. * actual file/path names which would be (created and) used. At most, two
  187. * files may be used; used2 may be NULL if only one file is used.
  188. * @param pool The pool for allocating used1 and used2.
  189. * @param pathname The path name to generate used-names from.
  190. * @param used1 The first pathname used by the apr_dbm implementation.
  191. * @param used2 The second pathname used by apr_dbm. If only one file is
  192. * used by the specific implementation, this will be set to NULL.
  193. * @remark The dbm file(s) don't need to exist. This function only manipulates
  194. * the pathnames.
  195. */
  196. APU_DECLARE(void) apr_dbm_get_usednames(apr_pool_t *pool,
  197. const char *pathname,
  198. const char **used1,
  199. const char **used2);
  200. /** @} */
  201. #ifdef __cplusplus
  202. }
  203. #endif
  204. #endif /* !APR_DBM_H */