aboutsummaryrefslogtreecommitdiffstats
path: root/src/gnutls_cache.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/gnutls_cache.c')
-rw-r--r--src/gnutls_cache.c28
1 files changed, 17 insertions, 11 deletions
diff --git a/src/gnutls_cache.c b/src/gnutls_cache.c
index 3ca8cb5..7bcb697 100644
--- a/src/gnutls_cache.c
+++ b/src/gnutls_cache.c
@@ -35,8 +35,6 @@
35 35
36/* it seems the default has some strange errors. Use SDBM 36/* it seems the default has some strange errors. Use SDBM
37 */ 37 */
38#define ODB "SDBM"
39
40#define MC_TAG "mod_gnutls:" 38#define MC_TAG "mod_gnutls:"
41#define MC_TAG_LEN sizeof(MC_TAG) 39#define MC_TAG_LEN sizeof(MC_TAG)
42#define STR_SESSION_LEN (GNUTLS_SESSION_ID_STRING_LEN + MC_TAG_LEN) 40#define STR_SESSION_LEN (GNUTLS_SESSION_ID_STRING_LEN + MC_TAG_LEN)
@@ -296,6 +294,14 @@ static int mc_cache_delete(void* baton, gnutls_datum_t key)
296 294
297#endif /* have_apr_memcache */ 295#endif /* have_apr_memcache */
298 296
297const char* db_type(mgs_srvconf_rec * sc)
298{
299 if (sc->cache_type == mgs_cache_sdbm)
300 return "sdbm";
301 else
302 return "default";
303}
304
299#define SSL_DBM_FILE_MODE ( APR_UREAD | APR_UWRITE | APR_GREAD | APR_WREAD ) 305#define SSL_DBM_FILE_MODE ( APR_UREAD | APR_UWRITE | APR_GREAD | APR_WREAD )
300 306
301static void dbm_cache_expire(mgs_handle_t *ctxt) 307static void dbm_cache_expire(mgs_handle_t *ctxt)
@@ -321,7 +327,7 @@ static void dbm_cache_expire(mgs_handle_t *ctxt)
321 total = 0; 327 total = 0;
322 deleted = 0; 328 deleted = 0;
323 329
324 rv = apr_dbm_open_ex(&dbm, ODB, ctxt->sc->cache_config, APR_DBM_RWCREATE, 330 rv = apr_dbm_open_ex(&dbm, db_type(ctxt->sc), ctxt->sc->cache_config, APR_DBM_RWCREATE,
325 SSL_DBM_FILE_MODE, spool); 331 SSL_DBM_FILE_MODE, spool);
326 if (rv != APR_SUCCESS) { 332 if (rv != APR_SUCCESS) {
327 ap_log_error(APLOG_MARK, APLOG_NOTICE, rv, 333 ap_log_error(APLOG_MARK, APLOG_NOTICE, rv,
@@ -374,7 +380,7 @@ static gnutls_datum_t dbm_cache_fetch(void* baton, gnutls_datum_t key)
374 if (mgs_session_id2dbm(ctxt->c, key.data, key.size, &dbmkey) < 0) 380 if (mgs_session_id2dbm(ctxt->c, key.data, key.size, &dbmkey) < 0)
375 return data; 381 return data;
376 382
377 rv = apr_dbm_open_ex(&dbm, ODB, ctxt->sc->cache_config, 383 rv = apr_dbm_open_ex(&dbm, db_type(ctxt->sc), ctxt->sc->cache_config,
378 APR_DBM_READONLY, SSL_DBM_FILE_MODE, ctxt->c->pool); 384 APR_DBM_READONLY, SSL_DBM_FILE_MODE, ctxt->c->pool);
379 if (rv != APR_SUCCESS) { 385 if (rv != APR_SUCCESS) {
380 ap_log_error(APLOG_MARK, APLOG_NOTICE, rv, 386 ap_log_error(APLOG_MARK, APLOG_NOTICE, rv,
@@ -444,7 +450,7 @@ static int dbm_cache_store(void* baton, gnutls_datum_t key,
444 memcpy((char *)dbmval.dptr+sizeof(apr_time_t), 450 memcpy((char *)dbmval.dptr+sizeof(apr_time_t),
445 data.data, data.size); 451 data.data, data.size);
446 452
447 rv = apr_dbm_open_ex(&dbm, ODB, ctxt->sc->cache_config, 453 rv = apr_dbm_open_ex(&dbm, db_type(ctxt->sc), ctxt->sc->cache_config,
448 APR_DBM_RWCREATE, SSL_DBM_FILE_MODE, ctxt->c->pool); 454 APR_DBM_RWCREATE, SSL_DBM_FILE_MODE, ctxt->c->pool);
449 if (rv != APR_SUCCESS) { 455 if (rv != APR_SUCCESS) {
450 ap_log_error(APLOG_MARK, APLOG_NOTICE, rv, 456 ap_log_error(APLOG_MARK, APLOG_NOTICE, rv,
@@ -484,7 +490,7 @@ static int dbm_cache_delete(void* baton, gnutls_datum_t key)
484 if (mgs_session_id2dbm(ctxt->c, key.data, key.size, &dbmkey) < 0) 490 if (mgs_session_id2dbm(ctxt->c, key.data, key.size, &dbmkey) < 0)
485 return -1; 491 return -1;
486 492
487 rv = apr_dbm_open_ex(&dbm, ODB, ctxt->sc->cache_config, 493 rv = apr_dbm_open_ex(&dbm, db_type(ctxt->sc), ctxt->sc->cache_config,
488 APR_DBM_RWCREATE, SSL_DBM_FILE_MODE, ctxt->c->pool); 494 APR_DBM_RWCREATE, SSL_DBM_FILE_MODE, ctxt->c->pool);
489 if (rv != APR_SUCCESS) { 495 if (rv != APR_SUCCESS) {
490 ap_log_error(APLOG_MARK, APLOG_NOTICE, rv, 496 ap_log_error(APLOG_MARK, APLOG_NOTICE, rv,
@@ -518,7 +524,7 @@ static int dbm_cache_post_config(apr_pool_t *p, server_rec *s,
518 const char* path1; 524 const char* path1;
519 const char* path2; 525 const char* path2;
520 526
521 rv = apr_dbm_open_ex(&dbm, ODB, sc->cache_config, APR_DBM_RWCREATE, 527 rv = apr_dbm_open_ex(&dbm, db_type(sc), sc->cache_config, APR_DBM_RWCREATE,
522 SSL_DBM_FILE_MODE, p); 528 SSL_DBM_FILE_MODE, p);
523 529
524 if (rv != APR_SUCCESS) { 530 if (rv != APR_SUCCESS) {
@@ -530,7 +536,7 @@ static int dbm_cache_post_config(apr_pool_t *p, server_rec *s,
530 536
531 apr_dbm_close(dbm); 537 apr_dbm_close(dbm);
532 538
533 apr_dbm_get_usednames_ex(p, ODB, sc->cache_config, &path1, &path2); 539 apr_dbm_get_usednames_ex(p, db_type(sc), sc->cache_config, &path1, &path2);
534 540
535 /* The Following Code takes logic directly from mod_ssl's DBM Cache */ 541 /* The Following Code takes logic directly from mod_ssl's DBM Cache */
536#if !defined(OS2) && !defined(WIN32) && !defined(BEOS) && !defined(NETWARE) 542#if !defined(OS2) && !defined(WIN32) && !defined(BEOS) && !defined(NETWARE)
@@ -549,7 +555,7 @@ static int dbm_cache_post_config(apr_pool_t *p, server_rec *s,
549int mgs_cache_post_config(apr_pool_t *p, server_rec *s, 555int mgs_cache_post_config(apr_pool_t *p, server_rec *s,
550 mgs_srvconf_rec *sc) 556 mgs_srvconf_rec *sc)
551{ 557{
552 if (sc->cache_type == mgs_cache_dbm) { 558 if (sc->cache_type == mgs_cache_dbm || sc->cache_type == mgs_cache_sdbm) {
553 return dbm_cache_post_config(p, s, sc); 559 return dbm_cache_post_config(p, s, sc);
554 } 560 }
555 return 0; 561 return 0;
@@ -558,7 +564,7 @@ int mgs_cache_post_config(apr_pool_t *p, server_rec *s,
558int mgs_cache_child_init(apr_pool_t *p, server_rec *s, 564int mgs_cache_child_init(apr_pool_t *p, server_rec *s,
559 mgs_srvconf_rec *sc) 565 mgs_srvconf_rec *sc)
560{ 566{
561 if (sc->cache_type == mgs_cache_dbm) { 567 if (sc->cache_type == mgs_cache_dbm || sc->cache_type == mgs_cache_sdbm) {
562 return 0; 568 return 0;
563 } 569 }
564#if HAVE_APR_MEMCACHE 570#if HAVE_APR_MEMCACHE
@@ -573,7 +579,7 @@ int mgs_cache_child_init(apr_pool_t *p, server_rec *s,
573 579
574int mgs_cache_session_init(mgs_handle_t *ctxt) 580int mgs_cache_session_init(mgs_handle_t *ctxt)
575{ 581{
576 if (ctxt->sc->cache_type == mgs_cache_dbm) { 582 if (ctxt->sc->cache_type == mgs_cache_dbm || ctxt->sc->cache_type == mgs_cache_sdbm) {
577 gnutls_db_set_retrieve_function(ctxt->session, dbm_cache_fetch); 583 gnutls_db_set_retrieve_function(ctxt->session, dbm_cache_fetch);
578 gnutls_db_set_remove_function(ctxt->session, dbm_cache_delete); 584 gnutls_db_set_remove_function(ctxt->session, dbm_cache_delete);
579 gnutls_db_set_store_function(ctxt->session, dbm_cache_store); 585 gnutls_db_set_store_function(ctxt->session, dbm_cache_store);