aboutsummaryrefslogtreecommitdiffstats
path: root/src/gnutls_cache.c
diff options
context:
space:
mode:
authorGravatar Paul Querna 2005-04-04 08:28:38 +0000
committerGravatar Paul Querna 2005-04-04 08:28:38 +0000
commit6e0bfd69eb8331d195f9fc4a449a3d52baa6793d (patch)
tree8e3082866cfbe32e2bfdd44db40660ab92f31ba8 /src/gnutls_cache.c
parent7bd1f6a2642fdbf5c5f2f48af9af01765e6abe05 (diff)
- make memcahe optional
- update for 2.1.x branch changes. - some mucking around with the conf stuff
Diffstat (limited to 'src/gnutls_cache.c')
-rw-r--r--src/gnutls_cache.c88
1 files changed, 55 insertions, 33 deletions
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 @@
16 */ 16 */
17 17
18#include "mod_gnutls.h" 18#include "mod_gnutls.h"
19
20#if HAVE_APR_MEMCACHE
21#include "apr_memcache.h"
22#endif
23
19#include "ap_mpm.h" 24#include "ap_mpm.h"
20 25
26#define GNUTLS_SESSION_ID_STRING_LEN \
27 ((GNUTLS_MAX_SESSION_ID + 1) * 2)
28#define MC_TAG "mod_gnutls:"
29#define MC_TAG_LEN \
30 (sizeof(MC_TAG))
31#define STR_SESSION_LEN (GNUTLS_SESSION_ID_STRING_LEN + MC_TAG_LEN)
32
33static char *gnutls_session_id2sz(unsigned char *id, int idlen,
34 char *str, int strsize)
35{
36 char *cp;
37 int n;
38
39 cp = apr_cpystrn(str, MC_TAG, MC_TAG_LEN);
40 for (n = 0; n < idlen && n < GNUTLS_MAX_SESSION_ID; n++) {
41 apr_snprintf(cp, strsize - (cp-str), "%02X", id[n]);
42 cp += 2;
43 }
44 *cp = '\0';
45 return str;
46}
47
48
49#if HAVE_APR_MEMCACHE
50
21/** 51/**
22 * GnuTLS Session Cache using libmemcached 52 * GnuTLS Session Cache using libmemcached
23 * 53 *
@@ -26,7 +56,7 @@
26/* The underlying apr_memcache system is thread safe... woohoo */ 56/* The underlying apr_memcache system is thread safe... woohoo */
27static apr_memcache_t* mc; 57static apr_memcache_t* mc;
28 58
29int mod_gnutls_cache_child_init(apr_pool_t *p, server_rec *s, 59int mc_cache_child_init(apr_pool_t *p, server_rec *s,
30 mod_gnutls_srvconf_rec *sc) 60 mod_gnutls_srvconf_rec *sc)
31{ 61{
32 apr_status_t rv = APR_SUCCESS; 62 apr_status_t rv = APR_SUCCESS;
@@ -109,32 +139,8 @@ int mod_gnutls_cache_child_init(apr_pool_t *p, server_rec *s,
109 return rv; 139 return rv;
110} 140}
111 141
112/* thanks mod_ssl */ 142static int mc_cache_store(void* baton, gnutls_datum_t key,
113#define GNUTLS_SESSION_ID_STRING_LEN \ 143 gnutls_datum_t data)
114 ((GNUTLS_MAX_SESSION_ID + 1) * 2)
115#define MC_TAG "mod_gnutls:"
116#define MC_TAG_LEN \
117 (sizeof(MC_TAG))
118#define STR_SESSION_LEN (GNUTLS_SESSION_ID_STRING_LEN + MC_TAG_LEN)
119
120
121static char *gnutls_session_id2sz(unsigned char *id, int idlen,
122 char *str, int strsize)
123{
124 char *cp;
125 int n;
126
127 cp = apr_cpystrn(str, MC_TAG, MC_TAG_LEN);
128 for (n = 0; n < idlen && n < GNUTLS_MAX_SESSION_ID; n++) {
129 apr_snprintf(cp, strsize - (cp-str), "%02X", id[n]);
130 cp += 2;
131 }
132 *cp = '\0';
133 return str;
134}
135
136
137static int cache_store(void* baton, gnutls_datum_t key, gnutls_datum_t data)
138{ 144{
139 apr_status_t rv = APR_SUCCESS; 145 apr_status_t rv = APR_SUCCESS;
140 mod_gnutls_handle_t *ctxt = baton; 146 mod_gnutls_handle_t *ctxt = baton;
@@ -161,7 +167,7 @@ static int cache_store(void* baton, gnutls_datum_t key, gnutls_datum_t data)
161 return 0; 167 return 0;
162} 168}
163 169
164static gnutls_datum_t cache_fetch(void* baton, gnutls_datum_t key) 170static gnutls_datum_t mc_cache_fetch(void* baton, gnutls_datum_t key)
165{ 171{
166 apr_status_t rv = APR_SUCCESS; 172 apr_status_t rv = APR_SUCCESS;
167 mod_gnutls_handle_t *ctxt = baton; 173 mod_gnutls_handle_t *ctxt = baton;
@@ -190,7 +196,7 @@ static gnutls_datum_t cache_fetch(void* baton, gnutls_datum_t key)
190 return data; 196 return data;
191 } 197 }
192 198
193 /* TODO: Eliminate this memcpy. ffs. gnutls-- */ 199 /* TODO: Eliminate this memcpy. gnutls-- */
194 data.data = gnutls_malloc(value_len); 200 data.data = gnutls_malloc(value_len);
195 if (data.data == NULL) 201 if (data.data == NULL)
196 return data; 202 return data;
@@ -201,7 +207,7 @@ static gnutls_datum_t cache_fetch(void* baton, gnutls_datum_t key)
201 return data; 207 return data;
202} 208}
203 209
204static int cache_delete(void* baton, gnutls_datum_t key) 210static int mc_cache_delete(void* baton, gnutls_datum_t key)
205{ 211{
206 apr_status_t rv = APR_SUCCESS; 212 apr_status_t rv = APR_SUCCESS;
207 mod_gnutls_handle_t *ctxt = baton; 213 mod_gnutls_handle_t *ctxt = baton;
@@ -225,11 +231,27 @@ static int cache_delete(void* baton, gnutls_datum_t key)
225 return 0; 231 return 0;
226} 232}
227 233
234#endif /* have_apr_memcache */
235
236int mod_gnutls_cache_child_init(apr_pool_t *p, server_rec *s,
237 mod_gnutls_srvconf_rec *sc)
238{
239#if HAVE_APR_MEMCACHE
240 return mc_cache_child_init(p, s, sc);
241#else
242 return 0;
243#endif
244}
245
228int mod_gnutls_cache_session_init(mod_gnutls_handle_t *ctxt) 246int mod_gnutls_cache_session_init(mod_gnutls_handle_t *ctxt)
229{ 247{
230 gnutls_db_set_retrieve_function(ctxt->session, cache_fetch); 248#if HAVE_APR_MEMCACHE
231 gnutls_db_set_remove_function(ctxt->session, cache_delete); 249 gnutls_db_set_retrieve_function(ctxt->session, mc_cache_fetch);
232 gnutls_db_set_store_function(ctxt->session, cache_store); 250 gnutls_db_set_remove_function(ctxt->session, mc_cache_delete);
251 gnutls_db_set_store_function(ctxt->session, mc_cache_store);
233 gnutls_db_set_ptr(ctxt->session, ctxt); 252 gnutls_db_set_ptr(ctxt->session, ctxt);
253#else
254 /* TODO: Alternative Cache Backends */
255#endif
234 return 0; 256 return 0;
235} 257}