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 --- autogen.sh | 4 +-- configure.ac | 21 ++++++++---- include/mod_gnutls.h.in | 4 +-- src/Makefile.am | 16 ++------- src/gnutls_cache.c | 88 ++++++++++++++++++++++++++++++------------------- src/mod_gnutls.c | 4 +-- 6 files changed, 76 insertions(+), 61 deletions(-) diff --git a/autogen.sh b/autogen.sh index 6c8e11f..20db562 100755 --- a/autogen.sh +++ b/autogen.sh @@ -3,8 +3,8 @@ # $Id: autogen.sh,v 1.1 2004/03/04 08:12:13 firechipmunk Exp $ libtoolize --force --copy #libtoolize14 --force --copy -aclocal -I m4 +aclocal-1.9 -I m4 autoheader -automake --add-missing --copy --foreign +automake-1.9 --add-missing --copy --foreign autoconf rm -rf autom4te.cache diff --git a/configure.ac b/configure.ac index 001f145..086b9f5 100644 --- a/configure.ac +++ b/configure.ac @@ -1,16 +1,18 @@ -AC_INIT + +AC_INIT(mod_gnutls, 0.1.0) OOO_CONFIG_NICE(config.nice) +AC_PREREQ(2.53) AC_CONFIG_SRCDIR([src/mod_gnutls.c]) +AC_CONFIG_AUX_DIR(config) AM_MAINTAINER_MODE AC_CANONICAL_TARGET -AM_INIT_AUTOMAKE(mod_gnutls, 0.1.0) -AM_CONFIG_HEADER([include/mod_gnutls_config.h:config.in]) +AM_INIT_AUTOMAKE(AC_PACKAGE_NAME, AC_PACKAGE_VERSION) +AM_CONFIG_HEADER(include/mod_gnutls_config.h:config.in) AC_PROG_CC AC_PROG_LD AC_PROG_INSTALL -AM_PROG_LIBTOOL AP_VERSION=2.0.40 @@ -19,10 +21,15 @@ CHECK_APACHE(,$AP_VERSION, AC_MSG_ERROR([*** Apache version $AP_VERSION not found!]) ) -MIN_TLS_VERSION=1.1.0 +LIBTOOL="`${APR_CONFIG} --apr-libtool`" +AC_SUBST(LIBTOOL) + +MIN_TLS_VERSION=1.2.0 CHECK_LIBGNUTLS($MIN_TLS_VERSION) -CHECK_APR_MEMCACHE() +have_apr_memcache=0 +CHECK_APR_MEMCACHE([have_apr_memcache=1], [have_apr_memcache=0]) +AC_SUBST(have_apr_memcache) MODULE_CFLAGS="${LIBGNUTLS_CFLAGS} ${APR_MEMCACHE_CFLAGS} ${APXS_CFLAGS} ${AP_INCLUDES} ${APR_INCLUDES} ${APU_INCLUDES}" MODULE_LIBS="${APR_MEMCACHE_LIBS} ${LIBGNUTLS_LIBS}" @@ -30,7 +37,7 @@ MODULE_LIBS="${APR_MEMCACHE_LIBS} ${LIBGNUTLS_LIBS}" AC_SUBST(MODULE_CFLAGS) AC_SUBST(MODULE_LIBS) -AC_CONFIG_FILES([Makefile src/Makefile]) +AC_CONFIG_FILES([Makefile src/Makefile include/mod_gnutls.h]) AC_OUTPUT echo "---" diff --git a/include/mod_gnutls.h.in b/include/mod_gnutls.h.in index 03ba4d1..469e678 100644 --- a/include/mod_gnutls.h.in +++ b/include/mod_gnutls.h.in @@ -29,9 +29,7 @@ #ifndef __mod_gnutls_h_inc #define __mod_gnutls_h_inc -#if HAVE_APR_MEMCACHE -#include "apr_memcache.h" -#endif +#define HAVE_APR_MEMCACHE @have_apr_memcache@ #include #include 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