ssl_scache_memcache.c revision 341bd61e8bccf51d8f2a5580168272e6e9098500
/* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/* _ _
* _ __ ___ ___ __| | ___ ___| | mod_ssl
* | '_ ` _ \ / _ \ / _` | / __/ __| | Apache Interface to OpenSSL
* | | | | | | (_) | (_| | \__ \__ \ |
* |_| |_| |_|\___/ \__,_|___|___/___/_|
* |_____|
* Distributed Session Cache on top of memcached
*/
#include "ssl_private.h"
#ifdef HAVE_SSL_CACHE_MEMCACHE
#include "apr_memcache.h"
#include "ap_mpm.h"
/*
* SSL Session Caching using memcached as a backend.
*/
/*
**
** High-Level "handlers" as per ssl_scache.c
**
*/
/* The underlying apr_memcache system is thread safe.. */
#define MC_TAG "mod_ssl:"
#define MC_TAG_LEN \
(sizeof(MC_TAG))
#define MC_KEY_LEN 254
#ifndef MC_DEFAULT_SERVER_PORT
#define MC_DEFAULT_SERVER_PORT 11211
#endif
#ifndef MC_DEFAULT_SERVER_MIN
#define MC_DEFAULT_SERVER_MIN 0
#endif
#ifndef MC_DEFAULT_SERVER_SMAX
#define MC_DEFAULT_SERVER_SMAX 1
#endif
#ifndef MC_DEFAULT_SERVER_TTL
#define MC_DEFAULT_SERVER_TTL 600
#endif
struct context {
const char *servers;
};
{
return NULL;
}
{
int thread_limit = 0;
int nservers = 0;
char *cache_config;
char *split;
char *tok;
/* Find all the servers in the first run to get a total count */
while (split) {
nservers++;
}
if (rv != APR_SUCCESS) {
"SSLSessionCache: Failed to create Memcache Object of '%d' size.",
nservers);
return rv;
}
/* Now add each server to the memcache */
while (split) {
char *host_str;
char *scope_id;
if (rv != APR_SUCCESS) {
"SSLSessionCache: Failed to Parse Server: '%s'", split);
return rv;
}
"SSLSessionCache: Failed to Parse Server, "
"no hostname specified: '%s'", split);
return APR_EINVAL;
}
if (port == 0) {
}
&st);
if (rv != APR_SUCCESS) {
"SSLSessionCache: Failed to Create Server: %s:%d",
return rv;
}
if (rv != APR_SUCCESS) {
"SSLSessionCache: Failed to Add Server: %s:%d",
return rv;
}
}
return APR_SUCCESS;
}
{
/* noop. */
}
{
char *cp;
int n;
cp += 2;
}
*cp = '\0';
return str;
}
{
char buf[MC_KEY_LEN];
if(!strkey) {
return APR_EGENERAL;
}
if (rv != APR_SUCCESS) {
"scache_mc: error setting key '%s' "
return rv;
}
return APR_SUCCESS;
}
apr_pool_t *p)
{
if (!strkey) {
"scache_mc: Key generation borked.");
return APR_EGENERAL;
}
/* ### this could do with a subpool, but _getp looks like it will
* eat memory like it's going out of fashion anyway. */
if (rv) {
if (rv != APR_NOTFOUND) {
"scache_mc: 'get_session' FAIL");
}
return rv;
}
"scache_mc: 'get_session' OVERFLOW");
return rv;
}
return APR_SUCCESS;
}
apr_pool_t *p)
{
char buf[MC_KEY_LEN];
if(!strkey) {
return;
}
if (rv != APR_SUCCESS) {
"scache_mc: error deleting key '%s' ",
strkey);
return;
}
}
{
/* SSLModConfigRec *mc = myModConfig(r->server); */
/* TODO: Make a mod_status handler. meh. */
}
const modssl_sesscache_provider modssl_sesscache_mc = {
"memcache",
0,
};
#endif