mod_dbd.c revision 842ae4bd224140319ae7feec1872b93dfd491143
/* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/* Overview of what this is and does:
* or
*/
#include <ctype.h>
#include "http_protocol.h"
#include "http_config.h"
#include "http_log.h"
#include "apr_reslist.h"
#include "apr_strings.h"
#include "apr_dbd.h"
#include "mod_dbd.h"
/************ svr cfg: manage db connection pool ****************/
#define NMIN_SET 0x1
#define NKEEP_SET 0x2
#define NMAX_SET 0x4
#define EXPTIME_SET 0x8
typedef struct dbd_prepared {
const char *label;
const char *query;
struct dbd_prepared *next;
} dbd_prepared;
typedef struct svr_cfg {
const char *name;
const char *params;
int persist;
#if APR_HAS_THREADS
int nmin;
int nkeep;
int nmax;
int exptime;
#else
#endif
unsigned int set;
} svr_cfg;
} cmd_parts;
/* a default DBDriver value that'll generate meaningful error messages */
static const char *const no_dbdriver = "[DBDriver unset]";
for (p = val; *p; ++p) \
if (!isdigit(*p)) \
return "Argument must be numeric!"
{
const char *p;
case cmd_name:
/* loading the driver involves once-only dlloading that is
* best done at server startup. This also guarantees that
* we won't return an error later.
*/
case APR_ENOTIMPL:
case APR_EDSOOPEN:
"DBD: Can't load driver file apr_dbd_%s.so",
case APR_ESYMNOTFOUND:
"DBD: Failed to load driver apr_dbd_%s_driver",
}
break;
case cmd_params:
break;
#if APR_HAS_THREADS
case cmd_min:
break;
case cmd_keep:
break;
case cmd_max:
break;
case cmd_exp:
break;
#endif
}
return NULL;
}
{
case cmd_persist:
break;
}
return NULL;
}
const char *label)
{
}
const char *label)
{
return NULL;
}
static const command_rec dbd_cmds[] = {
"SQL Driver"),
"SQL Driver Params"),
"Use persistent connection/pool"),
"Prepared SQL statement, label"),
#if APR_HAS_THREADS
"Minimum number of connections"),
/* XXX: note that mod_proxy calls this "smax" */
"Maximum number of sustained connections"),
"Maximum number of connections"),
/* XXX: note that mod_proxy calls this "ttl" (time to live) */
"Keepalive time for idle connections"),
#endif
{NULL}
};
#if APR_HAS_THREADS
#endif
return (void*) cfg;
}
/* A default nmin of >0 will help with generating meaningful
* startup error messages if the database is down.
*/
#define DEFAULT_NMIN 1
#define DEFAULT_NKEEP 2
#define DEFAULT_NMAX 10
#define DEFAULT_EXPTIME 300
{
#if APR_HAS_THREADS
#endif
return svr;
}
{
dbd_prepared *p;
}
else {
ret = APR_EGENERAL;
}
}
return ret;
}
/************ svr cfg: manage db connection pool ****************/
/* an apr_reslist_constructor for SQL connections
* Also use this for opening in non-reslist modes, since it gives
* us all the error-handling in one place.
*/
{
/* this pool is mostly so dbd_close can destroy the prepared stmts */
if (rv != APR_SUCCESS) {
"DBD: Failed to create memory pool");
}
/* The driver is loaded at config time now, so this just checks a hash.
* If that changes, the driver DSO could be registered to unload against
* our pool, which is probably not what we want. Error checking isn't
* necessary now, but in case that changes in the future ...
*/
switch (rv) {
case APR_ENOTIMPL:
return rv;
case APR_EDSOOPEN:
return rv;
case APR_ESYMNOTFOUND:
return rv;
default:
"DBD: mod_dbd not compatible with apr in get_driver");
return rv;
case APR_SUCCESS:
break;
}
switch (rv) {
case APR_EGENERAL:
return rv;
default:
"DBD: mod_dbd not compatible with apr in open");
return rv;
case APR_SUCCESS:
break;
}
if (rv != APR_SUCCESS) {
"DBD: failed to initialise prepared SQL statements");
}
return rv;
}
{
return rv;
}
#if APR_HAS_THREADS
{
}
{
/* create a pool just for the reslist from a process-lifetime pool;
* that pool (s->process->pool in the dbd_setup_lock case,
* whatever was passed to ap_run_child_init in the dbd_setup_init case)
* will be shared with other threads doing other non-mod_dbd things
* so we can't use it for the reslist directly
*/
if (rv != APR_SUCCESS) {
"DBD: Failed to create reslist memory pool");
return rv;
}
if (rv == APR_SUCCESS) {
(void*)apr_reslist_destroy,
}
else {
"DBD: failed to initialise");
}
return rv;
}
{
return APR_SUCCESS;
}
if (rv == APR_SUCCESS) {
return rv;
}
/* we failed, so create a mutex so that subsequent competing callers
* to ap_dbd_open can serialize themselves while they retry
*/
if (rv != APR_SUCCESS) {
"DBD: Failed to create thread mutex");
}
return rv;
}
{
/* several threads could be here at the same time, all trying to
* initialize the reslist because dbd_setup_init failed to do so
*/
/* we already logged an error when the mutex couldn't be created */
return APR_EGENERAL;
}
if (rv != APR_SUCCESS) {
"DBD: Failed to acquire thread mutex");
return rv;
}
}
if (rv != APR_SUCCESS) {
"DBD: Failed to release thread mutex");
if (rv2 == APR_SUCCESS) {
}
}
return rv2;
}
#endif
/* Functions we export for modules to use:
- open acquires a connection from the pool (opens one if necessary)
- close releases it back in to the pool
*/
{
}
#if APR_HAS_THREADS
else {
}
#endif
}
#if APR_HAS_THREADS
{
const char *errmsg;
/* Return a once-only connection */
}
return NULL;
}
}
if (rv != APR_SUCCESS) {
"Failed to acquire DBD connection from pool!");
return NULL;
}
if (!errmsg) {
errmsg = "(unknown)";
}
return NULL;
}
return arec;
}
#else
{
const char *errmsg;
/* Return a once-only connection */
}
/* since we're in nothread-land, we can mess with svr->conn with impunity */
/* If we have a persistent connection and it's good, we'll use it */
if (!errmsg) {
errmsg = "(unknown)";
}
}
}
/* We don't have a connection right now, so we'll open one */
}
}
}
#endif
#if APR_HAS_THREADS
typedef struct {
} dbd_pool_rec;
{
return APR_SUCCESS;
}
{
if (!req) {
}
else {
}
}
}
}
{
if (!req) {
}
else {
}
}
}
}
#else
{
if (!ret) {
if (ret) {
}
/* if persist then dbd_open registered cleanup on proc pool */
}
}
return ret;
}
{
if (!ret) {
if (ret) {
}
/* if persist then dbd_open registered cleanup on proc pool */
}
}
return ret;
}
#endif
{
#if APR_HAS_THREADS
#endif
}
NULL,
NULL,
};