mod_dbd.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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. * @file mod_dbd.h
  18. * @brief Database Access Extension Module for Apache
  19. *
  20. * Overview of what this is and does:
  21. * http://www.apache.org/~niq/dbd.html
  22. * or
  23. * http://apache.webthing.com/database/
  24. *
  25. * @defgroup MOD_DBD mod_dbd
  26. * @ingroup APACHE_MODS
  27. * @{
  28. */
  29. #ifndef DBD_H
  30. #define DBD_H
  31. /* Create a set of DBD_DECLARE(type), DBD_DECLARE_NONSTD(type) and
  32. * DBD_DECLARE_DATA with appropriate export and import tags for the platform
  33. */
  34. #if !defined(WIN32)
  35. #define DBD_DECLARE(type) type
  36. #define DBD_DECLARE_NONSTD(type) type
  37. #define DBD_DECLARE_DATA
  38. #elif defined(DBD_DECLARE_STATIC)
  39. #define DBD_DECLARE(type) type __stdcall
  40. #define DBD_DECLARE_NONSTD(type) type
  41. #define DBD_DECLARE_DATA
  42. #elif defined(DBD_DECLARE_EXPORT)
  43. #define DBD_DECLARE(type) __declspec(dllexport) type __stdcall
  44. #define DBD_DECLARE_NONSTD(type) __declspec(dllexport) type
  45. #define DBD_DECLARE_DATA __declspec(dllexport)
  46. #else
  47. #define DBD_DECLARE(type) __declspec(dllimport) type __stdcall
  48. #define DBD_DECLARE_NONSTD(type) __declspec(dllimport) type
  49. #define DBD_DECLARE_DATA __declspec(dllimport)
  50. #endif
  51. #include <httpd.h>
  52. #include <apr_optional.h>
  53. #include <apr_hash.h>
  54. #include <apr_hooks.h>
  55. typedef struct {
  56. server_rec *server;
  57. const char *name;
  58. const char *params;
  59. int persist;
  60. #if APR_HAS_THREADS
  61. int nmin;
  62. int nkeep;
  63. int nmax;
  64. int exptime;
  65. int set;
  66. #endif
  67. apr_hash_t *queries;
  68. apr_array_header_t *init_queries;
  69. } dbd_cfg_t;
  70. typedef struct {
  71. apr_dbd_t *handle;
  72. const apr_dbd_driver_t *driver;
  73. apr_hash_t *prepared;
  74. apr_pool_t *pool;
  75. } ap_dbd_t;
  76. /* Export functions to access the database */
  77. /* acquire a connection that MUST be explicitly closed.
  78. * Returns NULL on error
  79. */
  80. DBD_DECLARE_NONSTD(ap_dbd_t*) ap_dbd_open(apr_pool_t*, server_rec*);
  81. /* release a connection acquired with ap_dbd_open */
  82. DBD_DECLARE_NONSTD(void) ap_dbd_close(server_rec*, ap_dbd_t*);
  83. /* acquire a connection that will have the lifetime of a request
  84. * and MUST NOT be explicitly closed. Return NULL on error.
  85. * This is the preferred function for most applications.
  86. */
  87. DBD_DECLARE_NONSTD(ap_dbd_t*) ap_dbd_acquire(request_rec*);
  88. /* acquire a connection that will have the lifetime of a connection
  89. * and MUST NOT be explicitly closed. Return NULL on error.
  90. * This is the preferred function for most applications.
  91. */
  92. DBD_DECLARE_NONSTD(ap_dbd_t*) ap_dbd_cacquire(conn_rec*);
  93. /* Prepare a statement for use by a client module during
  94. * the server startup/configuration phase. Can't be called
  95. * after the server has created its children (use apr_dbd_*).
  96. */
  97. DBD_DECLARE_NONSTD(void) ap_dbd_prepare(server_rec*, const char*, const char*);
  98. /* Also export them as optional functions for modules that prefer it */
  99. APR_DECLARE_OPTIONAL_FN(ap_dbd_t*, ap_dbd_open, (apr_pool_t*, server_rec*));
  100. APR_DECLARE_OPTIONAL_FN(void, ap_dbd_close, (server_rec*, ap_dbd_t*));
  101. APR_DECLARE_OPTIONAL_FN(ap_dbd_t*, ap_dbd_acquire, (request_rec*));
  102. APR_DECLARE_OPTIONAL_FN(ap_dbd_t*, ap_dbd_cacquire, (conn_rec*));
  103. APR_DECLARE_OPTIONAL_FN(void, ap_dbd_prepare, (server_rec*, const char*, const char*));
  104. APR_DECLARE_EXTERNAL_HOOK(dbd, DBD, apr_status_t, post_connect,
  105. (apr_pool_t *, dbd_cfg_t *, ap_dbd_t *))
  106. #endif
  107. /** @} */