summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--NEWS1
-rw-r--r--README.FreeBSD6
-rw-r--r--SConstruct12
-rw-r--r--configure.ac31
-rw-r--r--src/CMakeLists.txt20
-rw-r--r--src/Makefile.am4
-rw-r--r--src/SConscript6
-rw-r--r--src/config.h.cmake2
-rw-r--r--src/mod_cml.c49
-rw-r--r--src/mod_cml.h8
-rw-r--r--src/mod_cml_funcs.c88
-rw-r--r--src/mod_cml_lua.c8
-rw-r--r--src/mod_trigger_b4_dl.c93
-rw-r--r--src/server.c2
14 files changed, 162 insertions, 168 deletions
diff --git a/NEWS b/NEWS
index a5272441..f1da579a 100644
--- a/NEWS
+++ b/NEWS
@@ -6,6 +6,7 @@ NEWS
- 1.4.40
* [mod_ssi] enhance support for ssi vars (thx fbrosson)
* add handling for lua 5.2 and 5.3 (fixes #2674)
+ * use libmemcached instead of deprecated libmemcache
- 1.4.39 - 2016-01-02
* [core] fix memset_s call (fixes #2698)
diff --git a/README.FreeBSD b/README.FreeBSD
index 5d0d2b7a..d7c34655 100644
--- a/README.FreeBSD
+++ b/README.FreeBSD
@@ -28,9 +28,9 @@ FreeBSD dependencies:
or
pkg install fam
- Lua 5.1, 5.2 or 5.3 (mod_magnet and mod_cml)
- pkg install lua51
-- (deprecated) memcache library (mod_cml and mod_trigger_b4_dl feature)
- pkg install libmemcache
+ pkg install lua51 (or lua52 or lua53)
+- memcached library (mod_cml and mod_trigger_b4_dl feature)
+ pkg install libmemcached
- gdbm (mod_trigger_b4_dl feature)
pkg install gdbm
- LDAP (mod_auth feature)
diff --git a/SConstruct b/SConstruct
index 37ba6fda..932b22f4 100644
--- a/SConstruct
+++ b/SConstruct
@@ -117,9 +117,9 @@ vars.AddVariables(
BoolVariable('build_static', 'enable static build', 'no'),
BoolVariable('build_fullstatic', 'enable fullstatic build', 'no'),
BoolVariable('with_sqlite3', 'enable sqlite3 support', 'no'),
- BoolVariable('with_memcache', 'enable memcache support', 'no'),
+ BoolVariable('with_memcached', 'enable memcached support', 'no'),
BoolVariable('with_fam', 'enable FAM/gamin support', 'no'),
- BoolVariable('with_openssl', 'enable memcache support', 'no'),
+ BoolVariable('with_openssl', 'enable openssl support', 'no'),
BoolVariable('with_gzip', 'enable gzip compression', 'no'),
BoolVariable('with_bzip2', 'enable bzip2 compression', 'no'),
BoolVariable('with_lua', 'enable lua support for mod_cml', 'no'),
@@ -215,7 +215,7 @@ if 1:
checkTypes(autoconf, Split('pid_t size_t off_t'))
autoconf.env.Append( LIBSQLITE3 = '', LIBXML2 = '', LIBMYSQL = '', LIBZ = '',
- LIBBZ2 = '', LIBCRYPT = '', LIBMEMCACHE = '', LIBFCGI = '', LIBPCRE = '',
+ LIBBZ2 = '', LIBCRYPT = '', LIBMEMCACHED = '', LIBFCGI = '', LIBPCRE = '',
LIBLDAP = '', LIBLBER = '', LIBLUA = '', LIBDL = '', LIBUUID = '')
if env['with_fam']:
@@ -253,9 +253,9 @@ if 1:
if autoconf.CheckLibWithHeader('bz2', 'bzlib.h', 'C'):
autoconf.env.Append(CPPFLAGS = [ '-DHAVE_BZLIB_H', '-DHAVE_LIBBZ2' ], LIBBZ2 = 'bz2')
- if env['with_memcache']:
- if autoconf.CheckLibWithHeader('memcache', 'memcache.h', 'C'):
- autoconf.env.Append(CPPFLAGS = [ '-DHAVE_MEMCACHE_H', '-DHAVE_LIBMEMCACHE' ], LIBMEMCACHE = 'memcache')
+ if env['with_memcached']:
+ if autoconf.CheckLibWithHeader('memcached', 'libmemcached/memcached.h', 'C'):
+ autoconf.env.Append(CPPFLAGS = [ '-DUSE_MEMCACHED' ], LIBMEMCACHED = 'memcached')
if env['with_sqlite3']:
if autoconf.CheckLibWithHeader('sqlite3', 'sqlite3.h', 'C'):
diff --git a/configure.ac b/configure.ac
index aa9a924f..6b244262 100644
--- a/configure.ac
+++ b/configure.ac
@@ -497,20 +497,19 @@ if test "$WITH_GDBM" != "no"; then
AC_SUBST(GDBM_LIB)
fi
-dnl Check for memcache
-AC_MSG_CHECKING(for memcache)
-AC_ARG_WITH(memcache, AC_HELP_STRING([--with-memcache],[memcached storage for mod_trigger_b4_dl]),
-[WITH_MEMCACHE=$withval],[WITH_MEMCACHE=no])
-AC_MSG_RESULT([$WITH_MEMCACHE])
-if test "$WITH_MEMCACHE" != "no"; then
- AC_CHECK_LIB(memcache, mc_new, [
- AC_CHECK_HEADERS([memcache.h],[
- MEMCACHE_LIB=-lmemcache
- AC_DEFINE([HAVE_MEMCACHE], [1], [libmemcache])
- AC_DEFINE([HAVE_MEMCACHE_H], [1], [memcache.h])
- ])
- ])
- AC_SUBST(MEMCACHE_LIB)
+dnl Check for memcached
+AC_MSG_CHECKING(for memcached)
+AC_ARG_WITH(memcached, AC_HELP_STRING([--with-memcached],[memcached storage for mod_trigger_b4_dl]),
+[WITH_MEMCACHED=$withval],[WITH_MEMCACHED=no])
+AC_MSG_RESULT([$WITH_MEMCACHED])
+if test "$WITH_MEMCACHED" != "no"; then
+ AC_CHECK_LIB(memcached, memcached, [
+ AC_CHECK_HEADERS([libmemcached/memcached.h],[
+ MEMCACHED_LIB=-lmemcached
+ AC_DEFINE([USE_MEMCACHED], [1], [libmemcached])
+ ])
+ ])
+ AC_SUBST(MEMCACHED_LIB)
fi
dnl Check for lua
@@ -767,8 +766,8 @@ else
disable_feature="$disable_feature $features"
fi
-features="storage-memcache"
-if test ! "x$MEMCACHE_LIB" = x; then
+features="storage-memcached"
+if test ! "x$MEMCACHED_LIB" = x; then
enable_feature="$enable_feature $features"
else
disable_feature="$disable_feature $features"
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 613af887..d99b2c2c 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -27,7 +27,7 @@ option(WITH_LUA "with lua 5.1 for mod_magnet [default: off]")
# option(WITH_KERBEROS5 "use Kerberos5 support with OpenSSL [default: off]")
option(WITH_FAM "fam/gamin for reducing number of stat() calls [default: off]")
option(WITH_GDBM "gdbm storage for mod_trigger_b4_dl [default: off]")
-option(WITH_MEMCACHE "memcached storage for mod_trigger_b4_dl [default: off]")
+option(WITH_MEMCACHED "memcached storage for mod_trigger_b4_dl [default: off]")
option(WITH_LIBEV "libev support for fdevent handlers [default: off]")
option(WITH_LIBUNWIND "with libunwind to print backtraces in asserts [default: off]")
@@ -427,12 +427,14 @@ else()
unset(HAVE_GDBM)
endif()
-if(WITH_MEMCACHE)
- check_include_files(memcache.h HAVE_MEMCACHE_H)
- check_library_exists(memcache mc_new "" HAVE_MEMCACHE)
-else()
- unset(HAVE_MEMCACHE_H)
- unset(HAVE_MEMCACHE)
+if(WITH_MEMCACHED)
+ check_include_files(libmemcached/memcached.h HAVE_LIBMEMCACHED_MEMCACHED_H)
+ check_library_exists(memcached memcached "" HAVE_LIBMEMCACHED)
+ if(HAVE_LIBMEMCACHED_MEMCACHED_H AND HAVE_LIBMEMCACHED)
+ set(USE_MEMCACHED 1)
+ else()
+ message(FATAL_ERROR "didn't find libmemcached")
+ endif()
endif()
if(NOT BUILD_STATIC)
@@ -630,8 +632,8 @@ if(HAVE_GDBM_H)
target_link_libraries(mod_trigger_b4_dl gdbm)
endif()
-if(HAVE_MEMCACHE_H)
- target_link_libraries(mod_trigger_b4_dl memcache)
+if(WITH_MEMCACHED)
+ target_link_libraries(mod_trigger_b4_dl memcached)
endif()
if(CMAKE_COMPILER_IS_GNUCC)
diff --git a/src/Makefile.am b/src/Makefile.am
index 906823ec..f7e651af 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -124,12 +124,12 @@ lib_LTLIBRARIES += mod_cml.la
mod_cml_la_SOURCES = mod_cml.c mod_cml_lua.c mod_cml_funcs.c
mod_cml_la_CFLAGS = $(AM_CFLAGS) $(LUA_CFLAGS)
mod_cml_la_LDFLAGS = -module -export-dynamic -avoid-version
-mod_cml_la_LIBADD = $(MEMCACHE_LIB) $(common_libadd) $(LUA_LIBS) -lm
+mod_cml_la_LIBADD = $(MEMCACHED_LIB) $(common_libadd) $(LUA_LIBS) -lm
lib_LTLIBRARIES += mod_trigger_b4_dl.la
mod_trigger_b4_dl_la_SOURCES = mod_trigger_b4_dl.c
mod_trigger_b4_dl_la_LDFLAGS = -module -export-dynamic -avoid-version
-mod_trigger_b4_dl_la_LIBADD = $(GDBM_LIB) $(MEMCACHE_LIB) $(PCRE_LIB) $(common_libadd)
+mod_trigger_b4_dl_la_LIBADD = $(GDBM_LIB) $(MEMCACHED_LIB) $(PCRE_LIB) $(common_libadd)
lib_LTLIBRARIES += mod_mysql_vhost.la
mod_mysql_vhost_la_SOURCES = mod_mysql_vhost.c
diff --git a/src/SConscript b/src/SConscript
index a03e101f..84ae4ff8 100644
--- a/src/SConscript
+++ b/src/SConscript
@@ -109,12 +109,12 @@ modules = {
'mod_flv_streaming' : { 'src' : [ 'mod_flv_streaming.c' ] },
'mod_cml': {
'src' : [ 'mod_cml_lua.c', 'mod_cml.c', 'mod_cml_funcs.c' ],
- 'lib' : [ env['LIBPCRE'], env['LIBMEMCACHE'], env['LIBLUA'] ]
+ 'lib' : [ env['LIBPCRE'], env['LIBMEMCACHED'], env['LIBLUA'] ]
},
}
-if env['with_memcache']:
- modules[mod_trigger_b4_dl] = { 'src' : [ 'mod_trigger_b4_dl.c' ], 'lib' : [ env['LIBPCRE'], env['LIBMEMCACHE'] ] }
+if env['with_memcached']:
+ modules['mod_trigger_b4_dl'] = { 'src' : [ 'mod_trigger_b4_dl.c' ], 'lib' : [ env['LIBPCRE'], env['LIBMEMCACHED'] ] }
if env['with_lua']:
modules['mod_magnet'] = { 'src' : [ 'mod_magnet.c', 'mod_magnet_cache.c' ], 'lib' : [ env['LIBLUA'] ] }
diff --git a/src/config.h.cmake b/src/config.h.cmake
index f80e4a1e..19c8843b 100644
--- a/src/config.h.cmake
+++ b/src/config.h.cmake
@@ -99,7 +99,7 @@
#cmakedefine HAVE_GDBM
/* memcache */
-#cmakedefine HAVE_MEMCACHE_H
+#cmakedefine USE_MEMCACHED
/* inotify */
#cmakedefine HAVE_INOTIFY_INIT
diff --git a/src/mod_cml.c b/src/mod_cml.c
index 3cdc3b85..5d83aa60 100644
--- a/src/mod_cml.c
+++ b/src/mod_cml.c
@@ -51,8 +51,8 @@ FREE_FUNC(mod_cml_free) {
buffer_free(s->power_magnet);
array_free(s->mc_hosts);
-#if defined(HAVE_MEMCACHE_H)
- if (s->mc) mc_free(s->mc);
+#if defined(USE_MEMCACHED)
+ if (s->memc) memcached_free(s->memc);
#endif
free(s);
@@ -96,8 +96,8 @@ SETDEFAULTS_FUNC(mod_cml_set_defaults) {
s->mc_hosts = array_init();
s->mc_namespace = buffer_init();
s->power_magnet = buffer_init();
-#if defined(HAVE_MEMCACHE_H)
- s->mc = NULL;
+#if defined(USE_MEMCACHED)
+ s->memc = NULL;
#endif
cv[0].destination = s->ext;
@@ -112,24 +112,37 @@ SETDEFAULTS_FUNC(mod_cml_set_defaults) {
}
if (s->mc_hosts->used) {
-#if defined(HAVE_MEMCACHE_H)
+#if defined(USE_MEMCACHED)
+ buffer *option_string = buffer_init();
size_t k;
- s->mc = mc_new();
- for (k = 0; k < s->mc_hosts->used; k++) {
+ {
+ data_string *ds = (data_string *)s->mc_hosts->data[0];
+
+ buffer_append_string_len(option_string, CONST_STR_LEN("--SERVER="));
+ buffer_append_string_buffer(option_string, ds->value);
+ }
+
+ for (k = 1; k < s->mc_hosts->used; k++) {
data_string *ds = (data_string *)s->mc_hosts->data[k];
- if (0 != mc_server_add4(s->mc, ds->value->ptr)) {
- log_error_write(srv, __FILE__, __LINE__, "sb",
- "connection to host failed:",
- ds->value);
+ buffer_append_string_len(option_string, CONST_STR_LEN(" --SERVER="));
+ buffer_append_string_buffer(option_string, ds->value);
+ }
+
+ s->memc = memcached(CONST_BUF_LEN(option_string));
- return HANDLER_ERROR;
- }
+ if (NULL == s->memc) {
+ log_error_write(srv, __FILE__, __LINE__, "sb",
+ "configuring memcached failed for option string:",
+ option_string);
}
+ buffer_free(option_string);
+
+ if (NULL == s->memc) return HANDLER_ERROR;
#else
log_error_write(srv, __FILE__, __LINE__, "s",
- "memcache support is not compiled in but cml.memcache-hosts is set, aborting");
+ "memcache support is not compiled in but cml.memcache-hosts is set, aborting");
return HANDLER_ERROR;
#endif
}
@@ -145,8 +158,8 @@ static int mod_cml_patch_connection(server *srv, connection *con, plugin_data *p
plugin_config *s = p->config_storage[0];
PATCH(ext);
-#if defined(HAVE_MEMCACHE_H)
- PATCH(mc);
+#if defined(USE_MEMCACHED)
+ PATCH(memc);
#endif
PATCH(mc_namespace);
PATCH(power_magnet);
@@ -166,8 +179,8 @@ static int mod_cml_patch_connection(server *srv, connection *con, plugin_data *p
if (buffer_is_equal_string(du->key, CONST_STR_LEN("cml.extension"))) {
PATCH(ext);
} else if (buffer_is_equal_string(du->key, CONST_STR_LEN("cml.memcache-hosts"))) {
-#if defined(HAVE_MEMCACHE_H)
- PATCH(mc);
+#if defined(USE_MEMCACHED)
+ PATCH(memc);
#endif
} else if (buffer_is_equal_string(du->key, CONST_STR_LEN("cml.memcache-namespace"))) {
PATCH(mc_namespace);
diff --git a/src/mod_cml.h b/src/mod_cml.h
index 1afd708d..2639f428 100644
--- a/src/mod_cml.h
+++ b/src/mod_cml.h
@@ -8,8 +8,8 @@
#include "stream.h"
#include "plugin.h"
-#if defined(HAVE_MEMCACHE_H)
-#include <memcache.h>
+#if defined(USE_MEMCACHED)
+#include <libmemcached/memcached.h>
#endif
#define plugin_data mod_cache_plugin_data
@@ -19,8 +19,8 @@ typedef struct {
array *mc_hosts;
buffer *mc_namespace;
-#if defined(HAVE_MEMCACHE_H)
- struct memcache *mc;
+#if defined(USE_MEMCACHED)
+ memcached_st *memc;
#endif
buffer *power_magnet;
} plugin_config;
diff --git a/src/mod_cml_funcs.c b/src/mod_cml_funcs.c
index aa7af749..38bae477 100644
--- a/src/mod_cml_funcs.c
+++ b/src/mod_cml_funcs.c
@@ -32,6 +32,8 @@ typedef char HASHHEX[HASHHEXLEN+1];
#ifdef HAVE_LUA_H
+#include <lauxlib.h>
+
int f_crypto_md5(lua_State *L) {
li_MD5_CTX Md5Ctx;
HASH HA1;
@@ -182,117 +184,87 @@ int f_file_isdir(lua_State *L) {
-#ifdef HAVE_MEMCACHE_H
+#ifdef USE_MEMCACHED
int f_memcache_exists(lua_State *L) {
- char *r;
- int n = lua_gettop(L);
- struct memcache *mc;
- size_t s_len;
- const char *s;
+ size_t key_len;
+ const char *key;
+ memcached_st *memc;
if (!lua_islightuserdata(L, lua_upvalueindex(1))) {
lua_pushstring(L, "where is my userdata ?");
lua_error(L);
}
- mc = lua_touserdata(L, lua_upvalueindex(1));
+ memc = lua_touserdata(L, lua_upvalueindex(1));
- if (n != 1) {
+ if (1 != lua_gettop(L)) {
lua_pushstring(L, "expected one argument");
lua_error(L);
}
- if (!lua_isstring(L, 1)) {
- lua_pushstring(L, "argument has to be a string");
- lua_error(L);
- }
-
- s = lua_tolstring(L, 1, &s_len);
- if (NULL == (r = mc_aget(mc, (char*) s, s_len))) {
- lua_pushboolean(L, 0);
- return 1;
- }
-
- free(r);
-
- lua_pushboolean(L, 1);
+ key = luaL_checklstring(L, 1, &key_len);
+ lua_pushboolean(L, (MEMCACHED_SUCCESS == memcached_exist(memc, key, key_len)));
return 1;
}
int f_memcache_get_string(lua_State *L) {
- char *r;
- int n = lua_gettop(L);
- size_t s_len;
- const char *s;
-
- struct memcache *mc;
+ size_t key_len, value_len;
+ char *value;
+ const char *key;
+ memcached_st *memc;
if (!lua_islightuserdata(L, lua_upvalueindex(1))) {
lua_pushstring(L, "where is my userdata ?");
lua_error(L);
}
- mc = lua_touserdata(L, lua_upvalueindex(1));
+ memc = lua_touserdata(L, lua_upvalueindex(1));
-
- if (n != 1) {
+ if (1 != lua_gettop(L)) {
lua_pushstring(L, "expected one argument");
lua_error(L);
}
- if (!lua_isstring(L, 1)) {
- lua_pushstring(L, "argument has to be a string");
- lua_error(L);
- }
-
- s = lua_tolstring(L, 1, &s_len);
- if (NULL == (r = mc_aget(mc, (char*) s, s_len))) {
+ key = luaL_checklstring(L, 1, &key_len);
+ if (NULL == (value = memcached_get(memc, key, key_len, &value_len, NULL, NULL))) {
lua_pushnil(L);
return 1;
}
- lua_pushstring(L, r);
+ lua_pushlstring(L, value, value_len);
- free(r);
+ free(value);
return 1;
}
int f_memcache_get_long(lua_State *L) {
- char *r;
- int n = lua_gettop(L);
- size_t s_len;
- const char *s;
-
- struct memcache *mc;
+ size_t key_len, value_len;
+ char *value;
+ const char *key;
+ memcached_st *memc;
if (!lua_islightuserdata(L, lua_upvalueindex(1))) {
lua_pushstring(L, "where is my userdata ?");
lua_error(L);
}
- mc = lua_touserdata(L, lua_upvalueindex(1));
-
+ memc = lua_touserdata(L, lua_upvalueindex(1));
- if (n != 1) {
+ if (1 != lua_gettop(L)) {
lua_pushstring(L, "expected one argument");
lua_error(L);
}
- if (!lua_isstring(L, 1)) {
- lua_pushstring(L, "argument has to be a string");
- lua_error(L);
- }
-
- s = lua_tolstring(L, 1, &s_len);
- if (NULL == (r = mc_aget(mc, (char*) s, s_len))) {
+ key = luaL_checklstring(L, 1, &key_len);
+ if (NULL == (value = memcached_get(memc, key, key_len, &value_len, NULL, NULL))) {
lua_pushnil(L);
return 1;
}
- lua_pushinteger(L, strtol(r, NULL, 10));
+ lua_pushinteger(L, strtol(value, NULL, 10));
- free(r);
+ free(value);
return 1;
}
diff --git a/src/mod_cml_lua.c b/src/mod_cml_lua.c
index 5fbefc24..eff07d2e 100644
--- a/src/mod_cml_lua.c
+++ b/src/mod_cml_lua.c
@@ -128,16 +128,16 @@ int cache_parse_lua(server *srv, connection *con, plugin_data *p, buffer *fn) {
lua_register(L, "file_isdir", f_file_isreg);
lua_register(L, "dir_files", f_dir_files);
-#ifdef HAVE_MEMCACHE_H
- lua_pushlightuserdata(L, p->conf.mc);
+#ifdef USE_MEMCACHED
+ lua_pushlightuserdata(L, p->conf.memc);
lua_pushcclosure(L, f_memcache_get_long, 1);
lua_setglobal(L, "memcache_get_long");
- lua_pushlightuserdata(L, p->conf.mc);
+ lua_pushlightuserdata(L, p->conf.memc);
lua_pushcclosure(L, f_memcache_get_string, 1);
lua_setglobal(L, "memcache_get_string");
- lua_pushlightuserdata(L, p->conf.mc);
+ lua_pushlightuserdata(L, p->conf.memc);
lua_pushcclosure(L, f_memcache_exists, 1);
lua_setglobal(L, "memcache_exists");
#endif
diff --git a/src/mod_trigger_b4_dl.c b/src/mod_trigger_b4_dl.c
index 79a6a3c9..54b29af9 100644
--- a/src/mod_trigger_b4_dl.c
+++ b/src/mod_trigger_b4_dl.c
@@ -11,7 +11,7 @@
#include <fcntl.h>
#include <string.h>
-#if (defined(HAVE_GDBM_H) || defined(HAVE_MEMCACHE_H)) && defined(HAVE_PCRE_H)
+#if (defined(HAVE_GDBM_H) || defined(USE_MEMCACHED)) && defined(HAVE_PCRE_H)
#if defined(HAVE_GDBM_H)
# include <gdbm.h>
@@ -21,8 +21,8 @@
# include <pcre.h>
#endif
-#if defined(HAVE_MEMCACHE_H)
-# include <memcache.h>
+#if defined(USE_MEMCACHED)
+# include <libmemcached/memcached.h>
#endif
/**
@@ -49,8 +49,8 @@ typedef struct {
GDBM_FILE db;
#endif
-#if defined(HAVE_MEMCACHE_H)
- struct memcache *mc;
+#if defined(USE_MEMCACHED)
+ memcached_st *memc;
#endif
unsigned short trigger_timeout;
@@ -108,8 +108,8 @@ FREE_FUNC(mod_trigger_b4_dl_free) {
#if defined(HAVE_GDBM_H)
if (s->db) gdbm_close(s->db);
#endif
-#if defined(HAVE_MEMCACHE_H)
- if (s->mc) mc_free(s->mc);
+#if defined(USE_MEMCACHED)
+ if (s->memc) memcached_free(s->memc);
#endif
free(s);
@@ -213,21 +213,34 @@ SETDEFAULTS_FUNC(mod_trigger_b4_dl_set_defaults) {
#endif
if (s->mc_hosts->used) {
-#if defined(HAVE_MEMCACHE_H)
+#if defined(USE_MEMCACHED)
+ buffer *option_string = buffer_init();
size_t k;
- s->mc = mc_new();
- for (k = 0; k < s->mc_hosts->used; k++) {
+ {
+ data_string *ds = (data_string *)s->mc_hosts->data[0];
+
+ buffer_append_string_len(option_string, CONST_STR_LEN("--SERVER="));
+ buffer_append_string_buffer(option_string, ds->value);
+ }
+
+ for (k = 1; k < s->mc_hosts->used; k++) {
data_string *ds = (data_string *)s->mc_hosts->data[k];
- if (0 != mc_server_add4(s->mc, ds->value->ptr)) {
- log_error_write(srv, __FILE__, __LINE__, "sb",
- "connection to host failed:",
- ds->value);
+ buffer_append_string_len(option_string, CONST_STR_LEN(" --SERVER="));
+ buffer_append_string_buffer(option_string, ds->value);
+ }
- return HANDLER_ERROR;
- }
+ s->memc = memcached(CONST_BUF_LEN(option_string));
+
+ if (NULL == s->memc) {
+ log_error_write(srv, __FILE__, __LINE__, "sb",
+ "configuring memcached failed for option string:",
+ option_string);
}
+ buffer_free(option_string);
+
+ if (NULL == s->memc) return HANDLER_ERROR;
#else
log_error_write(srv, __FILE__, __LINE__, "s",
"memcache support is not compiled in but trigger-before-download.memcache-hosts is set, aborting");
@@ -236,7 +249,7 @@ SETDEFAULTS_FUNC(mod_trigger_b4_dl_set_defaults) {
}
-#if (!defined(HAVE_GDBM_H) && !defined(HAVE_MEMCACHE_H)) || !defined(HAVE_PCRE_H)
+#if (!defined(HAVE_GDBM_H) && !defined(USE_MEMCACHED)) || !defined(HAVE_PCRE_H)
log_error_write(srv, __FILE__, __LINE__, "s",
"(either gdbm or libmemcache) and pcre are require, but were not found, aborting");
return HANDLER_ERROR;
@@ -263,8 +276,8 @@ static int mod_trigger_b4_dl_patch_connection(server *srv, connection *con, plug
PATCH(deny_url);
PATCH(mc_namespace);
PATCH(debug);
-#if defined(HAVE_MEMCACHE_H)
- PATCH(mc);
+#if defined(USE_MEMCACHED)
+ PATCH(memc);
#endif
/* skip the first, the global context */
@@ -300,8 +313,8 @@ static int mod_trigger_b4_dl_patch_connection(server *srv, connection *con, plug
} else if (buffer_is_equal_string(du->key, CONST_STR_LEN("trigger-before-download.memcache-namespace"))) {
PATCH(mc_namespace);
} else if (buffer_is_equal_string(du->key, CONST_STR_LEN("trigger-before-download.memcache-hosts"))) {
-#if defined(HAVE_MEMCACHE_H)
- PATCH(mc);
+#if defined(USE_MEMCACHED)
+ PATCH(memc);
#endif
}
}
@@ -329,11 +342,11 @@ URIHANDLER_FUNC(mod_trigger_b4_dl_uri_handler) {
if (!p->conf.trigger_regex || !p->conf.download_regex) return HANDLER_GO_ON;
-# if !defined(HAVE_GDBM_H) && !defined(HAVE_MEMCACHE_H)
+# if !defined(HAVE_GDBM_H) && !defined(USE_MEMCACHED)
return HANDLER_GO_ON;
-# elif defined(HAVE_GDBM_H) && defined(HAVE_MEMCACHE_H)
- if (!p->conf.db && !p->conf.mc) return HANDLER_GO_ON;
- if (p->conf.db && p->conf.mc) {
+# elif defined(HAVE_GDBM_H) && defined(USE_MEMCACHED)
+ if (!p->conf.db && !p->conf.memc) return HANDLER_GO_ON;
+ if (p->conf.db && p->conf.memc) {
/* can't decide which one */
return HANDLER_GO_ON;
@@ -341,7 +354,7 @@ URIHANDLER_FUNC(mod_trigger_b4_dl_uri_handler) {
# elif defined(HAVE_GDBM_H)
if (!p->conf.db) return HANDLER_GO_ON;
# else
- if (!p->conf.mc) return HANDLER_GO_ON;
+ if (!p->conf.memc) return HANDLER_GO_ON;
# endif
if (NULL != (ds = (data_string *)array_get_element(con->request.headers, "X-Forwarded-For"))) {
@@ -384,8 +397,8 @@ URIHANDLER_FUNC(mod_trigger_b4_dl_uri_handler) {
}
}
# endif
-# if defined(HAVE_MEMCACHE_H)
- if (p->conf.mc) {
+# if defined(USE_MEMCACHED)
+ if (p->conf.memc) {
size_t i, len;
buffer_copy_buffer(p->tmp_buf, p->conf.mc_namespace);
buffer_append_string(p->tmp_buf, remote_ip);
@@ -399,12 +412,12 @@ URIHANDLER_FUNC(mod_trigger_b4_dl_uri_handler) {
log_error_write(srv, __FILE__, __LINE__, "sb", "(debug) triggered IP:", p->tmp_buf);
}
- if (0 != mc_set(p->conf.mc,
+ if (MEMCACHED_SUCCESS != memcached_set(p->conf.memc,
CONST_BUF_LEN(p->tmp_buf),
- (char *)&(srv->cur_ts), sizeof(srv->cur_ts),
+ (const char *)&(srv->cur_ts), sizeof(srv->cur_ts),
p->conf.trigger_timeout, 0)) {
log_error_write(srv, __FILE__, __LINE__, "s",
- "insert failed");
+ "insert failed");
}
}
# endif
@@ -470,9 +483,8 @@ URIHANDLER_FUNC(mod_trigger_b4_dl_uri_handler) {
}
# endif
-# if defined(HAVE_MEMCACHE_H)
- if (p->conf.mc) {
- void *r;
+# if defined(USE_MEMCACHED)
+ if (p->conf.memc) {
size_t i, len;
buffer_copy_buffer(p->tmp_buf, p->conf.mc_namespace);
@@ -493,10 +505,7 @@ URIHANDLER_FUNC(mod_trigger_b4_dl_uri_handler) {
* and the timestamp is updated
*
*/
- if (NULL == (r = mc_aget(p->conf.mc,
- CONST_BUF_LEN(p->tmp_buf)
- ))) {
-
+ if (MEMCACHED_SUCCESS != memcached_exist(p->conf.memc, CONST_BUF_LEN(p->tmp_buf))) {
response_header_insert(srv, con, CONST_STR_LEN("Location"), CONST_BUF_LEN(p->conf.deny_url));
con->http_status = 307;
@@ -505,15 +514,13 @@ URIHANDLER_FUNC(mod_trigger_b4_dl_uri_handler) {
return HANDLER_FINISHED;
}
- free(r);
-
/* set a new timeout */
- if (0 != mc_set(p->conf.mc,
+ if (MEMCACHED_SUCCESS != memcached_set(p->conf.memc,
CONST_BUF_LEN(p->tmp_buf),
- (char *)&(srv->cur_ts), sizeof(srv->cur_ts),
+ (const char *)&(srv->cur_ts), sizeof(srv->cur_ts),
p->conf.trigger_timeout, 0)) {
log_error_write(srv, __FILE__, __LINE__, "s",
- "insert failed");
+ "insert failed");
}
}
# endif
diff --git a/src/server.c b/src/server.c
index 8a8a9254..24f11d5d 100644
--- a/src/server.c
+++ b/src/server.c
@@ -484,7 +484,7 @@ static void show_features (void) {
#else
"\t- LDAP support\n"
#endif
-#ifdef HAVE_MEMCACHE_H
+#ifdef USE_MEMCACHED
"\t+ memcached support\n"
#else
"\t- memcached support\n"