Changeset 6e0bfd6 in mod_gnutls for src/gnutls_cache.c


Ignore:
Timestamp:
Apr 4, 2005, 4:28:38 AM (15 years ago)
Author:
Paul Querna <chip@…>
Branches:
debian/master, debian/stretch-backports, jessie-backports, master, msva, upstream
Children:
fcb122d
Parents:
7bd1f6a
Message:
  • make memcahe optional
  • update for 2.1.x branch changes.
  • some mucking around with the conf stuff
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/gnutls_cache.c

    r7bd1f6a r6e0bfd6  
    1717
    1818#include "mod_gnutls.h"
     19
     20#if HAVE_APR_MEMCACHE
     21#include "apr_memcache.h"
     22#endif
     23
    1924#include "ap_mpm.h"
     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
    2050
    2151/**
     
    2757static apr_memcache_t* mc;
    2858
    29 int mod_gnutls_cache_child_init(apr_pool_t *p, server_rec *s,
     59int mc_cache_child_init(apr_pool_t *p, server_rec *s,
    3060                                mod_gnutls_srvconf_rec *sc)
    3161{
     
    110140}
    111141
    112 /* thanks mod_ssl */
    113 #define GNUTLS_SESSION_ID_STRING_LEN \
    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 
    121 static 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 
    137 static int cache_store(void* baton, gnutls_datum_t key, gnutls_datum_t data)
     142static int mc_cache_store(void* baton, gnutls_datum_t key,
     143                          gnutls_datum_t data)
    138144{
    139145    apr_status_t rv = APR_SUCCESS;
     
    162168}
    163169
    164 static gnutls_datum_t cache_fetch(void* baton, gnutls_datum_t key)
     170static gnutls_datum_t mc_cache_fetch(void* baton, gnutls_datum_t key)
    165171{
    166172    apr_status_t rv = APR_SUCCESS;
     
    191197    }
    192198
    193     /* TODO: Eliminate this memcpy. ffs. gnutls-- */
     199    /* TODO: Eliminate this memcpy. gnutls-- */
    194200    data.data = gnutls_malloc(value_len);
    195201    if (data.data == NULL)
     
    202208}
    203209
    204 static int cache_delete(void* baton, gnutls_datum_t key)
     210static int mc_cache_delete(void* baton, gnutls_datum_t key)
    205211{
    206212    apr_status_t rv = APR_SUCCESS;
     
    226232}
    227233
     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
    228246int mod_gnutls_cache_session_init(mod_gnutls_handle_t *ctxt)
    229247{
    230     gnutls_db_set_retrieve_function(ctxt->session, cache_fetch);
    231     gnutls_db_set_remove_function(ctxt->session, cache_delete);
    232     gnutls_db_set_store_function(ctxt->session, cache_store);
     248#if HAVE_APR_MEMCACHE
     249    gnutls_db_set_retrieve_function(ctxt->session, mc_cache_fetch);
     250    gnutls_db_set_remove_function(ctxt->session, mc_cache_delete);
     251    gnutls_db_set_store_function(ctxt->session, mc_cache_store);
    233252    gnutls_db_set_ptr(ctxt->session, ctxt);
    234     return 0;
    235 }
     253#else
     254    /* TODO: Alternative Cache Backends */
     255#endif
     256    return 0;
     257}
Note: See TracChangeset for help on using the changeset viewer.