Apache HTTPD
mod_dbd.c
Go to the documentation of this file.
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/* Overview of what this is and does:
18 * http://www.apache.org/~niq/dbd.html
19 * or
20 * http://apache.webthing.com/database/
21 */
22
23#include "apr_reslist.h"
24#include "apr_strings.h"
25#include "apr_hash.h"
26#include "apr_tables.h"
27#include "apr_lib.h"
28#include "apr_dbd.h"
29
30#define APR_WANT_MEMFUNC
31#define APR_WANT_STRFUNC
32#include "apr_want.h"
33
34#include "http_protocol.h"
35#include "http_config.h"
36#include "http_log.h"
37#include "http_request.h"
38#include "mod_dbd.h"
39
40extern module AP_MODULE_DECLARE_DATA dbd_module;
41
44 ap_dbd_t *dbd),
45 (pool, cfg, dbd), OK, DECLINED)
46
47/************ svr cfg: manage db connection pool ****************/
48
49#define NMIN_SET 0x1
50#define NKEEP_SET 0x2
51#define NMAX_SET 0x4
52#define EXPTIME_SET 0x8
53
54typedef struct dbd_group_t dbd_group_t;
55
60#if APR_HAS_THREADS
61 apr_thread_mutex_t *mutex;
63 int destroyed;
64#else
66#endif
67};
68
69typedef struct {
72} svr_cfg;
73
77
80
81/* a default DBDriver value that'll generate meaningful error messages */
82static const char *const no_dbdriver = "[DBDriver unset]";
83
84/* A default nmin of >0 will help with generating meaningful
85 * startup error messages if the database is down.
86 */
87#define DEFAULT_NMIN 1
88#define DEFAULT_NKEEP 2
89#define DEFAULT_NMAX 10
90#define DEFAULT_EXPTIME 300
91
92#define DEFAULT_SQL_INIT_ARRAY_SIZE 5
93
95{
96 svr_cfg *svr = apr_pcalloc(pool, sizeof(svr_cfg));
97 dbd_cfg_t *cfg = svr->cfg = apr_pcalloc(pool, sizeof(dbd_cfg_t));
98
99 cfg->server = s;
100 cfg->name = no_dbdriver; /* to generate meaningful error messages */
101 cfg->params = ""; /* don't risk segfault on misconfiguration */
102 cfg->persist = -1;
103#if APR_HAS_THREADS
104 cfg->nmin = DEFAULT_NMIN;
105 cfg->nkeep = DEFAULT_NKEEP;
106 cfg->nmax = DEFAULT_NMAX;
107 cfg->exptime = DEFAULT_EXPTIME;
108#endif
109 cfg->queries = apr_hash_make(pool);
111 sizeof(const char *));
112
113 return svr;
114}
115
116static void *merge_dbd_config(apr_pool_t *pool, void *basev, void *addv)
117{
118 dbd_cfg_t *base = ((svr_cfg*) basev)->cfg;
119 dbd_cfg_t *add = ((svr_cfg*) addv)->cfg;
120 svr_cfg *svr = apr_pcalloc(pool, sizeof(svr_cfg));
121 dbd_cfg_t *new = svr->cfg = apr_pcalloc(pool, sizeof(dbd_cfg_t));
122
123 new->server = add->server;
124 new->name = (add->name != no_dbdriver) ? add->name : base->name;
125 new->params = strcmp(add->params, "") ? add->params : base->params;
126 new->persist = (add->persist != -1) ? add->persist : base->persist;
127#if APR_HAS_THREADS
128 new->nmin = (add->set&NMIN_SET) ? add->nmin : base->nmin;
129 new->nkeep = (add->set&NKEEP_SET) ? add->nkeep : base->nkeep;
130 new->nmax = (add->set&NMAX_SET) ? add->nmax : base->nmax;
131 new->exptime = (add->set&EXPTIME_SET) ? add->exptime : base->exptime;
132#endif
133 new->queries = apr_hash_overlay(pool, add->queries, base->queries);
134 new->init_queries = apr_array_append(pool, add->init_queries,
135 base->init_queries);
136
137 return svr;
138}
139
140static void ap_dbd_sql_init(server_rec *s, const char *query)
141{
142 svr_cfg *svr;
143 const char **arr_item;
144
145 svr = ap_get_module_config(s->module_config, &dbd_module);
146 if (!svr) {
147 /* some modules may call from within config directive handlers, and
148 * if these are called in a server context that contains no mod_dbd
149 * config directives, then we have to create our own server config
150 */
152 ap_set_module_config(s->module_config, &dbd_module, svr);
153 }
154
155 if (query) {
156 arr_item = apr_array_push(svr->cfg->init_queries);
157 *arr_item = query;
158 }
159}
160
161static const char *dbd_param(cmd_parms *cmd, void *dconf, const char *val)
162{
163 apr_status_t rv;
165 svr_cfg *svr = ap_get_module_config(cmd->server->module_config,
166 &dbd_module);
167 dbd_cfg_t *cfg = svr->cfg;
168
169 switch ((long) cmd->info) {
170 case cmd_name:
171 cfg->name = val;
172 /* loading the driver involves once-only dlloading that is
173 * best done at server startup. This also guarantees that
174 * we won't return an error later.
175 */
176 rv = apr_dbd_get_driver(cmd->pool, cfg->name, &driver);
177 if (APR_STATUS_IS_ENOTIMPL(rv)) {
178 return apr_psprintf(cmd->pool, "No driver for %s", cfg->name);
179 }
180 else if (APR_STATUS_IS_EDSOOPEN(rv)) {
181 return apr_psprintf(cmd->pool,
183 "Can't load driver file dbd%s.nlm",
184#else
185 "Can't load driver file apr_dbd_%s.so",
186#endif
187 cfg->name);
188 }
189 else if (APR_STATUS_IS_ESYMNOTFOUND(rv)) {
190 return apr_psprintf(cmd->pool,
191 "Failed to load driver apr_dbd_%s_driver",
192 cfg->name);
193 }
194 break;
195 case cmd_params:
196 cfg->params = val;
197 break;
198 }
199
200 return NULL;
201}
202
203#if APR_HAS_THREADS
204static const char *dbd_param_int(cmd_parms *cmd, void *dconf, const char *val)
205{
206 svr_cfg *svr = ap_get_module_config(cmd->server->module_config,
207 &dbd_module);
208 dbd_cfg_t *cfg = svr->cfg;
209 const char *p;
210
211 for (p = val; *p; ++p) {
212 if (!apr_isdigit(*p)) {
213 return "Argument must be numeric!";
214 }
215 }
216
217 switch ((long) cmd->info) {
218 case cmd_min:
219 cfg->nmin = atoi(val);
220 cfg->set |= NMIN_SET;
221 break;
222 case cmd_keep:
223 cfg->nkeep = atoi(val);
224 cfg->set |= NKEEP_SET;
225 break;
226 case cmd_max:
227 cfg->nmax = atoi(val);
228 cfg->set |= NMAX_SET;
229 break;
230 case cmd_exp:
231 cfg->exptime = atoi(val);
232 cfg->set |= EXPTIME_SET;
233 break;
234 }
235
236 return NULL;
237}
238#endif
239
240static const char *dbd_param_flag(cmd_parms *cmd, void *dconf, int flag)
241{
242 svr_cfg *svr = ap_get_module_config(cmd->server->module_config,
243 &dbd_module);
244
245 switch ((long) cmd->info) {
246 case cmd_persist:
247 svr->cfg->persist = flag;
248 break;
249 }
250
251 return NULL;
252}
253
254static const char *dbd_prepare(cmd_parms *cmd, void *dconf, const char *query,
255 const char *label)
256{
257 if (!label) {
258 label = query;
259 query = "";
260 }
261
262 ap_dbd_prepare(cmd->server, query, label);
263
264 return NULL;
265}
266
267static const char *dbd_init_sql(cmd_parms *cmd, void *dconf, const char *query)
268{
269 if (!query || *query == '\n') {
270 return "You should specify SQL statement";
271 }
272
273 ap_dbd_sql_init(cmd->server, query);
274
275 return NULL;
276}
277
278static const command_rec dbd_cmds[] = {
279 AP_INIT_TAKE1("DBDriver", dbd_param, (void*)cmd_name, RSRC_CONF,
280 "SQL Driver"),
281 AP_INIT_TAKE1("DBDParams", dbd_param, (void*)cmd_params, RSRC_CONF,
282 "SQL Driver Params"),
283 AP_INIT_FLAG("DBDPersist", dbd_param_flag, (void*)cmd_persist, RSRC_CONF,
284 "Use persistent connection/pool"),
285 AP_INIT_TAKE12("DBDPrepareSQL", dbd_prepare, NULL, RSRC_CONF,
286 "SQL statement to prepare (or nothing, to override "
287 "statement inherited from main server) and label"),
289 "SQL statement to be executed after connection is created"),
290#if APR_HAS_THREADS
291 AP_INIT_TAKE1("DBDMin", dbd_param_int, (void*)cmd_min, RSRC_CONF,
292 "Minimum number of connections"),
293 /* XXX: note that mod_proxy calls this "smax" */
294 AP_INIT_TAKE1("DBDKeep", dbd_param_int, (void*)cmd_keep, RSRC_CONF,
295 "Maximum number of sustained connections"),
296 AP_INIT_TAKE1("DBDMax", dbd_param_int, (void*)cmd_max, RSRC_CONF,
297 "Maximum number of connections"),
298 /* XXX: note that mod_proxy calls this "ttl" (time to live) */
299 AP_INIT_TAKE1("DBDExptime", dbd_param_int, (void*)cmd_exp, RSRC_CONF,
300 "Keepalive time for idle connections"),
301#endif
302 {NULL}
303};
304
306 apr_pool_t *ptemp)
307{
310 return OK;
311}
312
314 const char *label)
315{
316 svr_cfg *svr;
317
318 svr = ap_get_module_config(s->module_config, &dbd_module);
319 if (!svr) {
320 /* some modules may call from within config directive handlers, and
321 * if these are called in a server context that contains no mod_dbd
322 * config directives, then we have to create our own server config
323 */
325 ap_set_module_config(s->module_config, &dbd_module, svr);
326 }
327
328 if (apr_hash_get(svr->cfg->queries, label, APR_HASH_KEY_STRING)
329 && strcmp(query, "")) {
331 "conflicting SQL statements with label %s", label);
332 }
333
335}
336
337typedef struct {
338 const char *label, *query;
340
342 apr_pool_t *ptemp, server_rec *s)
343{
344 server_rec *sp;
346 sizeof(dbd_query_t));
347
348 for (sp = s; sp; sp = sp->next) {
349 svr_cfg *svr = ap_get_module_config(sp->module_config, &dbd_module);
350 dbd_cfg_t *cfg = svr->cfg;
352 dbd_group_t *group;
353
354 /* dbd_setup in 2.2.3 and under was causing spurious error messages
355 * when dbd isn't configured. We can stop that with a quick check here
356 * together with a similar check in ap_dbd_open (where being
357 * unconfigured is a genuine error that must be reported).
358 */
359 if (cfg->name == no_dbdriver || !cfg->persist) {
360 continue;
361 }
362
363 for (group = group_list; group; group = group->next) {
364 dbd_cfg_t *group_cfg = group->cfg;
366 int group_ok = 1;
367
368 if (strcmp(cfg->name, group_cfg->name)
369 || strcmp(cfg->params, group_cfg->params)) {
370 continue;
371 }
372
373#if APR_HAS_THREADS
374 if (cfg->nmin != group_cfg->nmin
375 || cfg->nkeep != group_cfg->nkeep
376 || cfg->nmax != group_cfg->nmax
377 || cfg->exptime != group_cfg->exptime) {
378 continue;
379 }
380#endif
381
382 add_queries->nelts = 0;
383
384 for (hi = hi_first; hi; hi = apr_hash_next(hi)) {
385 const char *label, *query;
386 const char *group_query;
387
388 apr_hash_this(hi, (void*) &label, NULL, (void*) &query);
389
392
393 if (!group_query) {
395
396 add_query->label = label;
397 add_query->query = query;
398 }
399 else if (strcmp(query, group_query)) {
400 group_ok = 0;
401 break;
402 }
403 }
404
405 if (group_ok) {
406 int i;
407
408 for (i = 0; i < add_queries->nelts; ++i) {
410 + i;
411
412 apr_hash_set(group_cfg->queries, add_query->label,
414 }
415
416 svr->group = group;
417 break;
418 }
419 }
420
421 if (!svr->group) {
422 svr->group = group = apr_pcalloc(pconf, sizeof(dbd_group_t));
423
424 group->cfg = cfg;
425
426 group->next = group_list;
427 group_list = group;
428 }
429 }
430
431 return OK;
432}
433
435 ap_dbd_t *rec)
436{
438
439 rec->prepared = apr_hash_make(pool);
440
441 for (hi = apr_hash_first(pool, cfg->queries); hi;
442 hi = apr_hash_next(hi)) {
443 const char *label, *query;
445
446 apr_hash_this(hi, (void*) &label, NULL, (void*) &query);
447
448 if (!strcmp(query, "")) {
449 continue;
450 }
451
452 stmt = NULL;
453 if (apr_dbd_prepare(rec->driver, pool, rec->handle, query,
454 label, &stmt)) {
455 return APR_EGENERAL;
456 }
457 else {
459 }
460 }
461
462 return APR_SUCCESS;
463}
464
466 ap_dbd_t *rec)
467{
468 int i;
470
471 for (i = 0; i < cfg->init_queries->nelts; i++) {
472 int nrows;
473 char **query_p;
474
475 query_p = (char **)cfg->init_queries->elts + i;
476
477 if (apr_dbd_query(rec->driver, rec->handle, &nrows, *query_p)) {
478 rv = APR_EGENERAL;
479 break;
480 }
481 }
482
483 return rv;
484}
485
487{
488 ap_dbd_t *rec = data;
489
490 return apr_dbd_close(rec->driver, rec->handle);
491}
492
493#if APR_HAS_THREADS
494static apr_status_t dbd_destruct(void *data, void *params, apr_pool_t *pool)
495{
496 dbd_group_t *group = params;
497
498 if (!group->destroyed) {
499 ap_dbd_t *rec = data;
500
501 apr_pool_destroy(rec->pool);
502 }
503
504 return APR_SUCCESS;
505}
506#endif
507
508/* an apr_reslist_constructor for SQL connections
509 * Also use this for opening in non-reslist modes, since it gives
510 * us all the error-handling in one place.
511 */
513 void *params, apr_pool_t *pool)
514{
515 dbd_group_t *group = params;
516 dbd_cfg_t *cfg = group->cfg;
518 ap_dbd_t *rec;
519 apr_status_t rv;
520 const char *err = "";
521
523 if (rv != APR_SUCCESS) {
525 "Failed to create memory pool");
526 return rv;
527 }
528 apr_pool_tag(rec_pool, "dbd_rec_pool");
529
530 rec = apr_pcalloc(rec_pool, sizeof(ap_dbd_t));
531
532 rec->pool = rec_pool;
533
534 /* The driver is loaded at config time now, so this just checks a hash.
535 * If that changes, the driver DSO could be registered to unload against
536 * our pool, which is probably not what we want. Error checking isn't
537 * necessary now, but in case that changes in the future ...
538 */
539 rv = apr_dbd_get_driver(rec->pool, cfg->name, &rec->driver);
540 if (rv != APR_SUCCESS) {
541 if (APR_STATUS_IS_ENOTIMPL(rv)) {
543 "driver for %s not available", cfg->name);
544 }
545 else if (APR_STATUS_IS_EDSOOPEN(rv)) {
547 "can't find driver for %s", cfg->name);
548 }
549 else if (APR_STATUS_IS_ESYMNOTFOUND(rv)) {
551 "driver for %s is invalid or corrupted",
552 cfg->name);
553 }
554 else {
556 "mod_dbd not compatible with APR in get_driver");
557 }
558 apr_pool_destroy(rec->pool);
559 return rv;
560 }
561
562 rv = apr_dbd_open_ex(rec->driver, rec->pool, cfg->params, &rec->handle, &err);
563 if (rv != APR_SUCCESS) {
564 switch (rv) {
565 case APR_EGENERAL:
567 "Can't connect to %s: %s", cfg->name, err);
568 break;
569 default:
571 "mod_dbd not compatible with APR in open");
572 break;
573 }
574
575 apr_pool_destroy(rec->pool);
576 return rv;
577 }
578
581
582 /* we use a sub-pool for the prepared statements for each connection so
583 * that they will be cleaned up first, before the connection is closed
584 */
585 rv = apr_pool_create(&prepared_pool, rec->pool);
586 if (rv != APR_SUCCESS) {
588 "Failed to create memory pool");
589
590 apr_pool_destroy(rec->pool);
591 return rv;
592 }
593 apr_pool_tag(prepared_pool, "dbd_prepared_pool");
594
596 if (rv != APR_SUCCESS) {
597 const char *errmsg = apr_dbd_error(rec->driver, rec->handle, rv);
599 "failed to prepare SQL statements: %s",
600 (errmsg ? errmsg : "[???]"));
601
602 apr_pool_destroy(rec->pool);
603 return rv;
604 }
605
607
608 *data_ptr = rec;
609
610 return APR_SUCCESS;
611}
612
613#if APR_HAS_THREADS
614static apr_status_t dbd_destroy(void *data)
615{
616 dbd_group_t *group = data;
617
618 group->destroyed = 1;
619
620 return APR_SUCCESS;
621}
622
624{
625 dbd_cfg_t *cfg = group->cfg;
626 apr_status_t rv;
627
628 /* We create the reslist using a sub-pool of the pool passed to our
629 * child_init hook. No other threads can be here because we're
630 * either in the child_init phase or dbd_setup_lock() acquired our mutex.
631 * No other threads will use this sub-pool after this, except via
632 * reslist calls, which have an internal mutex.
633 *
634 * We need to short-circuit the cleanup registered internally by
635 * apr_reslist_create(). We do this by registering dbd_destroy()
636 * as a cleanup afterwards, so that it will run before the reslist's
637 * internal cleanup.
638 *
639 * If we didn't do this, then we could free memory twice when the pool
640 * was destroyed. When apr_pool_destroy() runs, it first destroys all
641 * all the per-connection sub-pools created in dbd_construct(), and
642 * then it runs the reslist's cleanup. The cleanup calls dbd_destruct()
643 * on each resource, which would then attempt to destroy the sub-pools
644 * a second time.
645 */
646 rv = apr_reslist_create(&group->reslist,
647 cfg->nmin, cfg->nkeep, cfg->nmax,
648 apr_time_from_sec(cfg->exptime),
650 group->pool);
651 if (rv != APR_SUCCESS) {
653 "failed to initialise");
654 return rv;
655 }
656
659
660 return APR_SUCCESS;
661}
662#endif
663
665{
666 dbd_group_t *group;
668
669 for (group = group_list; group; group = group->next) {
671
672 rv2 = apr_pool_create(&group->pool, pool);
673 if (rv2 != APR_SUCCESS) {
675 "Failed to create reslist cleanup memory pool");
676 return rv2;
677 }
678 apr_pool_tag(group->pool, "dbd_group");
679
680#if APR_HAS_THREADS
681 rv2 = dbd_setup(s, group);
682 if (rv2 == APR_SUCCESS) {
683 continue;
684 }
685 else if (rv == APR_SUCCESS) {
686 rv = rv2;
687 }
688
689 /* we failed, so create a mutex so that subsequent competing callers
690 * to ap_dbd_open can serialize themselves while they retry
691 */
692 rv2 = apr_thread_mutex_create(&group->mutex,
694 if (rv2 != APR_SUCCESS) {
696 "Failed to create thread mutex");
697 return rv2;
698 }
699#endif
700 }
701
702 return rv;
703}
704
706{
708 if (rv) {
710 "child init failed!");
711 }
712}
713
714#if APR_HAS_THREADS
716{
718
719 /* several threads could be here at the same time, all trying to
720 * initialize the reslist because dbd_setup_init failed to do so
721 */
722 if (!group->mutex) {
723 /* we already logged an error when the mutex couldn't be created */
724 return APR_EGENERAL;
725 }
726
727 rv2 = apr_thread_mutex_lock(group->mutex);
728 if (rv2 != APR_SUCCESS) {
730 "Failed to acquire thread mutex");
731 return rv2;
732 }
733
734 if (!group->reslist) {
735 rv = dbd_setup(s, group);
736 }
737
738 rv2 = apr_thread_mutex_unlock(group->mutex);
739 if (rv2 != APR_SUCCESS) {
741 "Failed to release thread mutex");
742 if (rv == APR_SUCCESS) {
743 rv = rv2;
744 }
745 }
746
747 return rv;
748}
749#endif
750
751/* Functions we export for modules to use:
752 - open acquires a connection from the pool (opens one if necessary)
753 - close releases it back in to the pool
754*/
756{
757 svr_cfg *svr = ap_get_module_config(s->module_config, &dbd_module);
758
759 if (!svr->cfg->persist) {
760 apr_pool_destroy(rec->pool);
761 }
762#if APR_HAS_THREADS
763 else {
764 apr_reslist_release(svr->group->reslist, rec);
765 }
766#endif
767}
768
770{
771 svr_cfg *svr;
772 apr_status_t rv = apr_dbd_check_conn(rec->driver, pool, rec->handle);
773 const char *errmsg;
774
775 if ((rv == APR_SUCCESS) || (rv == APR_ENOTIMPL)) {
776 return APR_SUCCESS;
777 }
778
779 /* we don't have a driver-specific error code, so we'll just pass
780 * a "success" value and rely on the driver to ignore it
781 */
782 errmsg = apr_dbd_error(rec->driver, rec->handle, 0);
783 if (!errmsg) {
784 errmsg = "(unknown)";
785 }
786
787 svr = ap_get_module_config(s->module_config, &dbd_module);
789 "DBD [%s] Error: %s", svr->cfg->name, errmsg);
790 return rv;
791}
792
794{
795 svr_cfg *svr = ap_get_module_config(s->module_config, &dbd_module);
796 dbd_group_t *group = svr->group;
797 dbd_cfg_t *cfg = svr->cfg;
798 ap_dbd_t *rec = NULL;
799#if APR_HAS_THREADS
800 apr_status_t rv;
801#endif
802
803 /* If nothing is configured, we shouldn't be here */
804 if (cfg->name == no_dbdriver) {
806 "not configured");
807 return NULL;
808 }
809
810 if (!cfg->persist) {
811 /* Return a once-only connection */
812 group = apr_pcalloc(pool, sizeof(dbd_group_t));
813
814 group->cfg = cfg;
815
816 dbd_construct((void*) &rec, group, pool);
817 return rec;
818 }
819
820#if APR_HAS_THREADS
821 if (!group->reslist) {
822 if (dbd_setup_lock(s, group) != APR_SUCCESS) {
823 return NULL;
824 }
825 }
826
827 rv = apr_reslist_acquire(group->reslist, (void*) &rec);
828 if (rv != APR_SUCCESS) {
830 "Failed to acquire DBD connection from pool!");
831 return NULL;
832 }
833
834 if (dbd_check(pool, s, rec) != APR_SUCCESS) {
835 apr_reslist_invalidate(group->reslist, rec);
836 return NULL;
837 }
838#else
839 /* If we have a persistent connection and it's good, we'll use it;
840 * since this is non-threaded, we can update without a mutex
841 */
842 rec = group->rec;
843 if (rec) {
844 if (dbd_check(pool, s, rec) != APR_SUCCESS) {
845 apr_pool_destroy(rec->pool);
846 rec = NULL;
847 }
848 }
849
850 /* We don't have a connection right now, so we'll open one */
851 if (!rec) {
852 dbd_construct((void*) &rec, group, group->pool);
853 group->rec = rec;
854 }
855#endif
856
857 return rec;
858}
859
860#if APR_HAS_THREADS
861typedef struct {
862 ap_dbd_t *rec;
865
866static apr_status_t dbd_release(void *data)
867{
869 apr_reslist_release(acq->reslist, acq->rec);
870 return APR_SUCCESS;
871}
872
874{
876
877 while (!ap_is_initial_req(r)) {
878 if (r->prev) {
879 r = r->prev;
880 }
881 else if (r->main) {
882 r = r->main;
883 }
884 }
885
886 acq = ap_get_module_config(r->request_config, &dbd_module);
887 if (!acq) {
888 acq = apr_palloc(r->pool, sizeof(dbd_acquire_t));
889 acq->rec = ap_dbd_open(r->pool, r->server);
890 if (acq->rec) {
892 &dbd_module);
893
895 if (svr->cfg->persist) {
896 acq->reslist = svr->group->reslist;
899 }
900 }
901 }
902
903 return acq->rec;
904}
905
907{
908 dbd_acquire_t *acq = ap_get_module_config(c->conn_config, &dbd_module);
909
910 if (!acq) {
911 acq = apr_palloc(c->pool, sizeof(dbd_acquire_t));
912 acq->rec = ap_dbd_open(c->pool, c->base_server);
913 if (acq->rec) {
914 svr_cfg *svr = ap_get_module_config(c->base_server->module_config,
915 &dbd_module);
916
917 ap_set_module_config(c->conn_config, &dbd_module, acq);
918 if (svr->cfg->persist) {
919 acq->reslist = svr->group->reslist;
922 }
923 }
924 }
925
926 return acq->rec;
927}
928#else
930{
931 ap_dbd_t *rec;
932
933 while (!ap_is_initial_req(r)) {
934 if (r->prev) {
935 r = r->prev;
936 }
937 else if (r->main) {
938 r = r->main;
939 }
940 }
941
942 rec = ap_get_module_config(r->request_config, &dbd_module);
943 if (!rec) {
945 if (rec) {
947 }
948 }
949
950 return rec;
951}
952
954{
955 ap_dbd_t *rec = ap_get_module_config(c->conn_config, &dbd_module);
956
957 if (!rec) {
958 rec = ap_dbd_open(c->pool, c->base_server);
959 if (rec) {
960 ap_set_module_config(c->conn_config, &dbd_module, rec);
961 }
962 }
963
964 return rec;
965}
966#endif
967
985
988 NULL,
989 NULL,
992 dbd_cmds,
994};
995
#define NETWARE
APR-UTIL DBD library.
APR Hash Tables.
APR general purpose library routines.
APR-UTIL Resource List Routines.
APR Strings library.
apr_array_append(apr_pool_t *p, const apr_array_header_t *first, const apr_array_header_t *second)
Definition apr_tables.c:213
APR Table library.
APR Standard Headers Support.
static apr_pool_t * pconf
Definition event.c:441
#define AP_INIT_TAKE1(directive, func, mconfig, where, help)
#define ap_get_module_config(v, m)
void ap_hook_post_config(ap_HOOK_post_config_t *pf, const char *const *aszPre, const char *const *aszSucc, int nOrder)
Definition config.c:105
#define AP_DECLARE_MODULE(foo)
#define AP_INIT_FLAG(directive, func, mconfig, where, help)
ap_conf_vector_t * base
#define ap_set_module_config(v, m, val)
void ap_hook_pre_config(ap_HOOK_pre_config_t *pf, const char *const *aszPre, const char *const *aszSucc, int nOrder)
Definition config.c:91
#define AP_INIT_TAKE12(directive, func, mconfig, where, help)
request_rec * r
void ap_hook_child_init(ap_HOOK_child_init_t *pf, const char *const *aszPre, const char *const *aszSucc, int nOrder)
Definition config.c:167
#define DECLINED
Definition httpd.h:457
#define OK
Definition httpd.h:456
#define APLOGNO(n)
Definition http_log.h:117
#define APLOG_ERR
Definition http_log.h:67
#define ap_log_error
Definition http_log.h:370
#define APLOG_MARK
Definition http_log.h:283
#define APLOG_WARNING
Definition http_log.h:68
#define APLOG_CRIT
Definition http_log.h:66
int ap_is_initial_req(request_rec *r)
Definition request.c:2567
#define APR_EGENERAL
Definition apr_errno.h:313
#define APR_ENOTIMPL
Definition apr_errno.h:476
#define APR_STATUS_IS_ENOTIMPL(s)
Definition apr_errno.h:615
#define APR_STATUS_IS_EDSOOPEN(s)
Definition apr_errno.h:403
#define APR_STATUS_IS_ESYMNOTFOUND(s)
Definition apr_errno.h:424
apr_pool_t apr_dbd_t const char * query
Definition apr_dbd.h:396
const char const apr_dbd_driver_t ** driver
Definition apr_dbd.h:106
struct apr_dbd_prepared_t apr_dbd_prepared_t
Definition apr_dbd.h:87
apr_pool_t apr_dbd_t const char const char * label
Definition apr_dbd.h:397
apr_pool_t const char * params
Definition apr_dbd.h:141
apr_dbd_t int * nrows
Definition apr_dbd.h:272
#define APR_HOOK_MIDDLE
Definition apr_hooks.h:303
#define APR_IMPLEMENT_OPTIONAL_HOOK_RUN_ALL(ns, link, ret, name, args_decl, args_use, ok, decline)
#define APR_OPTIONAL_HOOK(ns, name, pfn, aszPre, aszSucc, nOrder)
#define APR_REGISTER_OPTIONAL_FN(name)
#define RSRC_CONF
#define DBD_DECLARE_NONSTD(type)
Definition mod_dbd.h:39
ap_dbd_t * ap_dbd_cacquire(conn_rec *c)
Definition mod_dbd.c:953
ap_dbd_t * ap_dbd_acquire(request_rec *r)
Definition mod_dbd.c:929
apr_status_t dbd_run_post_connect(apr_pool_t *pool, dbd_cfg_t *cfg, ap_dbd_t *dbd)
Definition mod_dbd.c:45
ap_dbd_t * ap_dbd_open(apr_pool_t *pool, server_rec *s)
Definition mod_dbd.c:793
void ap_dbd_prepare(server_rec *s, const char *query, const char *label)
Definition mod_dbd.c:313
void ap_dbd_close(server_rec *s, ap_dbd_t *rec)
Definition mod_dbd.c:755
#define STANDARD20_MODULE_STUFF
apr_size_t size
apr_uint32_t val
Definition apr_atomic.h:66
const char int apr_pool_t * pool
Definition apr_cstr.h:84
#define apr_isdigit(c)
Definition apr_lib.h:209
#define APR_SUCCESS
Definition apr_errno.h:225
int apr_status_t
Definition apr_errno.h:44
const char apr_int32_t flag
void * data
#define APR_HASH_KEY_STRING
Definition apr_hash.h:47
void * rec
Definition apr_hash.h:270
apr_vformatter_buff_t * c
Definition apr_lib.h:175
#define apr_pool_create(newpool, parent)
Definition apr_pools.h:322
#define apr_pcalloc(p, size)
Definition apr_pools.h:465
const char * s
Definition apr_strings.h:95
apr_int32_t apr_int32_t apr_int32_t err
apr_cmdtype_e cmd
#define apr_time_from_sec(sec)
Definition apr_time.h:78
Apache Configuration.
Apache Logging library.
HTTP protocol handling.
Apache Request library.
apr_pool_t * p
Definition md_event.c:32
static void(* dbd_prepare)(server_rec *, const char *, const char *)
static void * merge_dbd_config(apr_pool_t *pool, void *basev, void *addv)
Definition mod_dbd.c:116
static void dbd_child_init(apr_pool_t *p, server_rec *s)
Definition mod_dbd.c:705
static apr_status_t dbd_setup_init(apr_pool_t *pool, server_rec *s)
Definition mod_dbd.c:664
static const char * dbd_param_flag(cmd_parms *cmd, void *dconf, int flag)
Definition mod_dbd.c:240
static void * create_dbd_config(apr_pool_t *pool, server_rec *s)
Definition mod_dbd.c:94
static const command_rec dbd_cmds[]
Definition mod_dbd.c:278
static void dbd_hooks(apr_pool_t *pool)
Definition mod_dbd.c:968
static apr_pool_t * config_pool
Definition mod_dbd.c:78
static int dbd_post_config(apr_pool_t *pconf, apr_pool_t *plog, apr_pool_t *ptemp, server_rec *s)
Definition mod_dbd.c:341
static apr_status_t dbd_init_sql_init(apr_pool_t *pool, dbd_cfg_t *cfg, ap_dbd_t *rec)
Definition mod_dbd.c:465
#define DEFAULT_NKEEP
Definition mod_dbd.c:88
static const char *const no_dbdriver
Definition mod_dbd.c:82
static const char * dbd_init_sql(cmd_parms *cmd, void *dconf, const char *query)
Definition mod_dbd.c:267
#define DEFAULT_NMAX
Definition mod_dbd.c:89
#define EXPTIME_SET
Definition mod_dbd.c:52
static apr_status_t dbd_prepared_init(apr_pool_t *pool, dbd_cfg_t *cfg, ap_dbd_t *rec)
Definition mod_dbd.c:434
cmd_parts
Definition mod_dbd.c:74
@ cmd_keep
Definition mod_dbd.c:75
@ cmd_params
Definition mod_dbd.c:74
@ cmd_persist
Definition mod_dbd.c:74
@ cmd_exp
Definition mod_dbd.c:75
@ cmd_name
Definition mod_dbd.c:74
@ cmd_min
Definition mod_dbd.c:75
@ cmd_max
Definition mod_dbd.c:75
static void ap_dbd_sql_init(server_rec *s, const char *query)
Definition mod_dbd.c:140
#define DEFAULT_SQL_INIT_ARRAY_SIZE
Definition mod_dbd.c:92
#define NMAX_SET
Definition mod_dbd.c:51
static apr_status_t dbd_check(apr_pool_t *pool, server_rec *s, ap_dbd_t *rec)
Definition mod_dbd.c:769
#define NKEEP_SET
Definition mod_dbd.c:50
#define NMIN_SET
Definition mod_dbd.c:49
#define DEFAULT_NMIN
Definition mod_dbd.c:87
static dbd_group_t * group_list
Definition mod_dbd.c:79
static apr_status_t dbd_construct(void **data_ptr, void *params, apr_pool_t *pool)
Definition mod_dbd.c:512
static int dbd_pre_config(apr_pool_t *pconf, apr_pool_t *plog, apr_pool_t *ptemp)
Definition mod_dbd.c:305
#define DEFAULT_EXPTIME
Definition mod_dbd.c:90
static apr_status_t dbd_close(void *data)
Definition mod_dbd.c:486
static const char * dbd_param(cmd_parms *cmd, void *dconf, const char *val)
Definition mod_dbd.c:161
Database Access Extension Module for Apache.
return NULL
Definition mod_so.c:359
int i
Definition mod_so.c:347
Structure to store things which are per connection.
Definition httpd.h:1152
int persist
Definition mod_dbd.h:64
const char * name
Definition mod_dbd.h:62
apr_hash_t * queries
Definition mod_dbd.h:72
server_rec * server
Definition mod_dbd.h:61
const char * params
Definition mod_dbd.h:63
apr_array_header_t * init_queries
Definition mod_dbd.h:73
dbd_cfg_t * cfg
Definition mod_dbd.c:57
dbd_group_t * next
Definition mod_dbd.c:58
ap_dbd_t * rec
Definition mod_dbd.c:65
apr_pool_t * pool
Definition mod_dbd.c:59
const char * label
Definition mod_dbd.c:338
A structure that represents the current request.
Definition httpd.h:845
request_rec * prev
Definition httpd.h:856
apr_pool_t * pool
Definition httpd.h:847
struct ap_conf_vector_t * request_config
Definition httpd.h:1049
request_rec * main
Definition httpd.h:860
server_rec * server
Definition httpd.h:851
A structure to store information for each virtual server.
Definition httpd.h:1322
struct ap_conf_vector_t * module_config
Definition httpd.h:1341
dbd_group_t * group
Definition mod_dbd.c:71
dbd_cfg_t * cfg
Definition mod_dbd.c:70