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