From 6e0bfd69eb8331d195f9fc4a449a3d52baa6793d Mon Sep 17 00:00:00 2001 From: Paul Querna Date: Mon, 4 Apr 2005 08:28:38 +0000 Subject: - make memcahe optional - update for 2.1.x branch changes. - some mucking around with the conf stuff --- src/Makefile.am | 16 ++-------- src/gnutls_cache.c | 88 ++++++++++++++++++++++++++++++++++-------------------- src/mod_gnutls.c | 4 +-- 3 files changed, 59 insertions(+), 49 deletions(-) (limited to 'src') diff --git a/src/Makefile.am b/src/Makefile.am index 1f1860b..30315a1 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -9,13 +9,13 @@ lib_LTLIBRARIES = libmod_gnutls.la make_so: $(lib_LTLIBRARIES) @if test ! -L mod_gnutls.so ; then ln -s .libs/libmod_gnutls.so mod_gnutls.so ; fi -clean: +clean: rm -f mod_gnutls.so rm -f *.o *.lo *.la rm -fr .libs install: make_so - @${APXS_BIN} -i -n svn_view mod_gnutls.so + @${APXS_BIN} -i -n gnutls mod_gnutls.so @echo "" @echo "" @echo "***********************************************" @@ -27,15 +27,3 @@ install: make_so @echo "***********************************************" @echo "" -activate: make_so - @${APXS_BIN} -i -a -n svn_view mod_gnutls.so - @echo "" - @echo "" - @echo "***********************************************" - @echo "" - @echo " Please read the documentation at " - @echo " http://www.outoforder.cc/ for " - @echo " details on configuration of this module " - @echo "" - @echo "***********************************************" - @echo "" diff --git a/src/gnutls_cache.c b/src/gnutls_cache.c index cee30fa..c1a6f37 100644 --- a/src/gnutls_cache.c +++ b/src/gnutls_cache.c @@ -16,8 +16,38 @@ */ #include "mod_gnutls.h" + +#if HAVE_APR_MEMCACHE +#include "apr_memcache.h" +#endif + #include "ap_mpm.h" +#define GNUTLS_SESSION_ID_STRING_LEN \ + ((GNUTLS_MAX_SESSION_ID + 1) * 2) +#define MC_TAG "mod_gnutls:" +#define MC_TAG_LEN \ + (sizeof(MC_TAG)) +#define STR_SESSION_LEN (GNUTLS_SESSION_ID_STRING_LEN + MC_TAG_LEN) + +static char *gnutls_session_id2sz(unsigned char *id, int idlen, + char *str, int strsize) +{ + char *cp; + int n; + + cp = apr_cpystrn(str, MC_TAG, MC_TAG_LEN); + for (n = 0; n < idlen && n < GNUTLS_MAX_SESSION_ID; n++) { + apr_snprintf(cp, strsize - (cp-str), "%02X", id[n]); + cp += 2; + } + *cp = '\0'; + return str; +} + + +#if HAVE_APR_MEMCACHE + /** * GnuTLS Session Cache using libmemcached * @@ -26,7 +56,7 @@ /* The underlying apr_memcache system is thread safe... woohoo */ static apr_memcache_t* mc; -int mod_gnutls_cache_child_init(apr_pool_t *p, server_rec *s, +int mc_cache_child_init(apr_pool_t *p, server_rec *s, mod_gnutls_srvconf_rec *sc) { apr_status_t rv = APR_SUCCESS; @@ -109,32 +139,8 @@ int mod_gnutls_cache_child_init(apr_pool_t *p, server_rec *s, return rv; } -/* thanks mod_ssl */ -#define GNUTLS_SESSION_ID_STRING_LEN \ - ((GNUTLS_MAX_SESSION_ID + 1) * 2) -#define MC_TAG "mod_gnutls:" -#define MC_TAG_LEN \ - (sizeof(MC_TAG)) -#define STR_SESSION_LEN (GNUTLS_SESSION_ID_STRING_LEN + MC_TAG_LEN) - - -static char *gnutls_session_id2sz(unsigned char *id, int idlen, - char *str, int strsize) -{ - char *cp; - int n; - - cp = apr_cpystrn(str, MC_TAG, MC_TAG_LEN); - for (n = 0; n < idlen && n < GNUTLS_MAX_SESSION_ID; n++) { - apr_snprintf(cp, strsize - (cp-str), "%02X", id[n]); - cp += 2; - } - *cp = '\0'; - return str; -} - - -static int cache_store(void* baton, gnutls_datum_t key, gnutls_datum_t data) +static int mc_cache_store(void* baton, gnutls_datum_t key, + gnutls_datum_t data) { apr_status_t rv = APR_SUCCESS; mod_gnutls_handle_t *ctxt = baton; @@ -161,7 +167,7 @@ static int cache_store(void* baton, gnutls_datum_t key, gnutls_datum_t data) return 0; } -static gnutls_datum_t cache_fetch(void* baton, gnutls_datum_t key) +static gnutls_datum_t mc_cache_fetch(void* baton, gnutls_datum_t key) { apr_status_t rv = APR_SUCCESS; mod_gnutls_handle_t *ctxt = baton; @@ -190,7 +196,7 @@ static gnutls_datum_t cache_fetch(void* baton, gnutls_datum_t key) return data; } - /* TODO: Eliminate this memcpy. ffs. gnutls-- */ + /* TODO: Eliminate this memcpy. gnutls-- */ data.data = gnutls_malloc(value_len); if (data.data == NULL) return data; @@ -201,7 +207,7 @@ static gnutls_datum_t cache_fetch(void* baton, gnutls_datum_t key) return data; } -static int cache_delete(void* baton, gnutls_datum_t key) +static int mc_cache_delete(void* baton, gnutls_datum_t key) { apr_status_t rv = APR_SUCCESS; mod_gnutls_handle_t *ctxt = baton; @@ -225,11 +231,27 @@ static int cache_delete(void* baton, gnutls_datum_t key) return 0; } +#endif /* have_apr_memcache */ + +int mod_gnutls_cache_child_init(apr_pool_t *p, server_rec *s, + mod_gnutls_srvconf_rec *sc) +{ +#if HAVE_APR_MEMCACHE + return mc_cache_child_init(p, s, sc); +#else + return 0; +#endif +} + int mod_gnutls_cache_session_init(mod_gnutls_handle_t *ctxt) { - gnutls_db_set_retrieve_function(ctxt->session, cache_fetch); - gnutls_db_set_remove_function(ctxt->session, cache_delete); - gnutls_db_set_store_function(ctxt->session, cache_store); +#if HAVE_APR_MEMCACHE + gnutls_db_set_retrieve_function(ctxt->session, mc_cache_fetch); + gnutls_db_set_remove_function(ctxt->session, mc_cache_delete); + gnutls_db_set_store_function(ctxt->session, mc_cache_store); gnutls_db_set_ptr(ctxt->session, ctxt); +#else + /* TODO: Alternative Cache Backends */ +#endif return 0; } diff --git a/src/mod_gnutls.c b/src/mod_gnutls.c index 833edc2..a1668f3 100644 --- a/src/mod_gnutls.c +++ b/src/mod_gnutls.c @@ -124,7 +124,7 @@ static void mod_gnutls_hook_child_init(apr_pool_t *p, server_rec *s) } } -static const char *mod_gnutls_hook_http_method(const request_rec * r) +static const char *mod_gnutls_hook_http_scheme(const request_rec * r) { mod_gnutls_srvconf_rec *sc = (mod_gnutls_srvconf_rec *) ap_get_module_config(r->server-> @@ -340,7 +340,7 @@ static void gnutls_hooks(apr_pool_t * p) APR_HOOK_MIDDLE); ap_hook_child_init(mod_gnutls_hook_child_init, NULL, NULL, APR_HOOK_MIDDLE); - ap_hook_http_method(mod_gnutls_hook_http_method, NULL, NULL, + ap_hook_http_scheme(mod_gnutls_hook_http_scheme, NULL, NULL, APR_HOOK_MIDDLE); ap_hook_default_port(mod_gnutls_hook_default_port, NULL, NULL, APR_HOOK_MIDDLE); -- cgit