diff options
author | Brian Aker <brian@tangent.org> | 2012-10-13 19:12:16 -0400 |
---|---|---|
committer | Brian Aker <brian@tangent.org> | 2012-10-13 19:12:16 -0400 |
commit | 3a41c6c5dedb9638e678402c5e867f2de6e923ee (patch) | |
tree | 14f2916812c7d8d93f75d671abdeea89fd0676e5 | |
parent | 9a27e356b30f92fb8158cf289c9b8b4b7c7aaa19 (diff) | |
download | libmemcached-3a41c6c5dedb9638e678402c5e867f2de6e923ee.tar.gz |
Update for version 1.2
-rw-r--r-- | Makefile.am | 7 | ||||
-rw-r--r-- | clients/execute.h | 2 | ||||
-rw-r--r-- | clients/memcapable.cc | 2 | ||||
-rw-r--r-- | clients/memcat.cc | 2 | ||||
-rw-r--r-- | clients/memcp.cc | 2 | ||||
-rw-r--r-- | clients/memdump.cc | 2 | ||||
-rw-r--r-- | clients/memerror.cc | 2 | ||||
-rw-r--r-- | clients/memexist.cc | 2 | ||||
-rw-r--r-- | clients/memflush.cc | 3 | ||||
-rw-r--r-- | clients/memparse.cc | 2 | ||||
-rw-r--r-- | clients/memping.cc | 4 | ||||
-rw-r--r-- | clients/memrm.cc | 3 | ||||
-rw-r--r-- | clients/memslap.cc | 2 | ||||
-rw-r--r-- | clients/memstat.cc | 2 | ||||
-rw-r--r-- | clients/memtouch.cc | 2 | ||||
-rw-r--r-- | clients/utilities.h | 2 | ||||
-rw-r--r-- | configure.ac | 2 | ||||
-rw-r--r-- | example/byteorder.cc | 89 | ||||
-rw-r--r-- | example/byteorder.h | 49 | ||||
-rw-r--r-- | example/include.am | 28 | ||||
-rw-r--r-- | example/interface_v0.cc | 561 | ||||
-rw-r--r-- | example/interface_v1.cc | 417 | ||||
-rw-r--r-- | example/memcached_light.cc | 646 | ||||
-rw-r--r-- | example/memcached_light.h | 44 | ||||
-rw-r--r-- | example/storage.cc | 168 | ||||
-rw-r--r-- | example/storage.h | 24 | ||||
-rw-r--r-- | example/t/include.am | 40 | ||||
-rw-r--r-- | example/t/memcached_light.cc | 248 | ||||
-rw-r--r-- | libmemcached-1.0/include.am | 56 | ||||
-rw-r--r-- | libmemcached-1.0/struct/include.am | 13 | ||||
-rw-r--r-- | libmemcached-1.0/t/include.am | 32 | ||||
-rw-r--r-- | libmemcached-1.0/types/include.am | 8 | ||||
-rw-r--r-- | libmemcached-1.2/alloc.h (renamed from libmemcached-1.0/alloc.h) | 0 | ||||
-rw-r--r-- | libmemcached-1.2/allocators.h (renamed from libmemcached-1.0/allocators.h) | 0 | ||||
-rw-r--r-- | libmemcached-1.2/analyze.h (renamed from libmemcached-1.0/analyze.h) | 2 | ||||
-rw-r--r-- | libmemcached-1.2/auto.h (renamed from libmemcached-1.0/auto.h) | 0 | ||||
-rw-r--r-- | libmemcached-1.2/basic_string.h (renamed from libmemcached-1.0/basic_string.h) | 0 | ||||
-rw-r--r-- | libmemcached-1.2/behavior.h (renamed from libmemcached-1.0/behavior.h) | 0 | ||||
-rw-r--r-- | libmemcached-1.2/callback.h (renamed from libmemcached-1.0/callback.h) | 0 | ||||
-rw-r--r-- | libmemcached-1.2/callbacks.h (renamed from libmemcached-1.0/callbacks.h) | 0 | ||||
-rw-r--r-- | libmemcached-1.2/configure.h.in (renamed from libmemcached-1.0/configure.h.in) | 0 | ||||
-rw-r--r-- | libmemcached-1.2/defaults.h (renamed from libmemcached-1.0/defaults.h) | 0 | ||||
-rw-r--r-- | libmemcached-1.2/delete.h (renamed from libmemcached-1.0/delete.h) | 0 | ||||
-rw-r--r-- | libmemcached-1.2/deprecated_types.h (renamed from libmemcached-1.0/deprecated_types.h) | 0 | ||||
-rw-r--r-- | libmemcached-1.2/dump.h (renamed from libmemcached-1.0/dump.h) | 0 | ||||
-rw-r--r-- | libmemcached-1.2/encoding_key.h (renamed from libmemcached-1.0/encoding_key.h) | 0 | ||||
-rw-r--r-- | libmemcached-1.2/error.h (renamed from libmemcached-1.0/error.h) | 0 | ||||
-rw-r--r-- | libmemcached-1.2/exception.hpp (renamed from libmemcached-1.0/exception.hpp) | 0 | ||||
-rw-r--r-- | libmemcached-1.2/exist.h (renamed from libmemcached-1.0/exist.h) | 0 | ||||
-rw-r--r-- | libmemcached-1.2/fetch.h (renamed from libmemcached-1.0/fetch.h) | 0 | ||||
-rw-r--r-- | libmemcached-1.2/flush.h (renamed from libmemcached-1.0/flush.h) | 0 | ||||
-rw-r--r-- | libmemcached-1.2/flush_buffers.h (renamed from libmemcached-1.0/flush_buffers.h) | 0 | ||||
-rw-r--r-- | libmemcached-1.2/get.h (renamed from libmemcached-1.0/get.h) | 0 | ||||
-rw-r--r-- | libmemcached-1.2/hash.h (renamed from libmemcached-1.0/hash.h) | 0 | ||||
-rw-r--r-- | libmemcached-1.2/include.am | 56 | ||||
-rw-r--r-- | libmemcached-1.2/limits.h (renamed from libmemcached-1.0/limits.h) | 0 | ||||
-rw-r--r-- | libmemcached-1.2/memcached.h (renamed from libmemcached-1.0/memcached.h) | 108 | ||||
-rw-r--r-- | libmemcached-1.2/memcached.hpp (renamed from libmemcached-1.0/memcached.hpp) | 2 | ||||
-rw-r--r-- | libmemcached-1.2/memcached/vbucket.h (renamed from libmemcachedprotocol-0.0/vbucket.h) | 0 | ||||
-rw-r--r-- | libmemcached-1.2/options.h (renamed from libmemcached-1.0/options.h) | 0 | ||||
-rw-r--r-- | libmemcached-1.2/parse.h (renamed from libmemcached-1.0/parse.h) | 0 | ||||
-rw-r--r-- | libmemcached-1.2/platform.h (renamed from libmemcached-1.0/platform.h) | 0 | ||||
-rw-r--r-- | libmemcached-1.2/quit.h (renamed from libmemcached-1.0/quit.h) | 0 | ||||
-rw-r--r-- | libmemcached-1.2/result.h (renamed from libmemcached-1.0/result.h) | 2 | ||||
-rw-r--r-- | libmemcached-1.2/return.h (renamed from libmemcached-1.0/return.h) | 0 | ||||
-rw-r--r-- | libmemcached-1.2/sasl.h (renamed from libmemcached-1.0/sasl.h) | 2 | ||||
-rw-r--r-- | libmemcached-1.2/server.h (renamed from libmemcached-1.0/server.h) | 2 | ||||
-rw-r--r-- | libmemcached-1.2/server_list.h (renamed from libmemcached-1.0/server_list.h) | 0 | ||||
-rw-r--r-- | libmemcached-1.2/stats.h (renamed from libmemcached-1.0/stats.h) | 2 | ||||
-rw-r--r-- | libmemcached-1.2/storage.h (renamed from libmemcached-1.0/storage.h) | 0 | ||||
-rw-r--r-- | libmemcached-1.2/strerror.h (renamed from libmemcached-1.0/strerror.h) | 0 | ||||
-rw-r--r-- | libmemcached-1.2/struct/allocator.h (renamed from libmemcached-1.0/struct/allocator.h) | 0 | ||||
-rw-r--r-- | libmemcached-1.2/struct/analysis.h (renamed from libmemcached-1.0/struct/analysis.h) | 0 | ||||
-rw-r--r-- | libmemcached-1.2/struct/callback.h (renamed from libmemcached-1.0/struct/callback.h) | 0 | ||||
-rw-r--r-- | libmemcached-1.2/struct/include.am | 13 | ||||
-rw-r--r-- | libmemcached-1.2/struct/memcached.h (renamed from libmemcached-1.0/struct/memcached.h) | 0 | ||||
-rw-r--r-- | libmemcached-1.2/struct/result.h (renamed from libmemcached-1.0/struct/result.h) | 0 | ||||
-rw-r--r-- | libmemcached-1.2/struct/sasl.h (renamed from libmemcached-1.0/struct/sasl.h) | 0 | ||||
-rw-r--r-- | libmemcached-1.2/struct/server.h (renamed from libmemcached-1.0/struct/server.h) | 0 | ||||
-rw-r--r-- | libmemcached-1.2/struct/stat.h (renamed from libmemcached-1.0/struct/stat.h) | 0 | ||||
-rw-r--r-- | libmemcached-1.2/struct/string.h (renamed from libmemcached-1.0/struct/string.h) | 0 | ||||
-rw-r--r-- | libmemcached-1.2/t/c_sasl_test.c (renamed from libmemcached-1.0/t/c_sasl_test.c) | 2 | ||||
-rw-r--r-- | libmemcached-1.2/t/c_test.c (renamed from libmemcached-1.0/t/c_test.c) | 2 | ||||
-rw-r--r-- | libmemcached-1.2/t/cc_test.cc (renamed from libmemcached-1.0/t/cc_test.cc) | 2 | ||||
-rw-r--r-- | libmemcached-1.2/t/include.am | 30 | ||||
-rw-r--r-- | libmemcached-1.2/touch.h (renamed from libmemcached-1.0/touch.h) | 0 | ||||
-rw-r--r-- | libmemcached-1.2/triggers.h (renamed from libmemcached-1.0/triggers.h) | 0 | ||||
-rw-r--r-- | libmemcached-1.2/types.h (renamed from libmemcached-1.0/types.h) | 0 | ||||
-rw-r--r-- | libmemcached-1.2/types/behavior.h (renamed from libmemcached-1.0/types/behavior.h) | 0 | ||||
-rw-r--r-- | libmemcached-1.2/types/callback.h (renamed from libmemcached-1.0/types/callback.h) | 0 | ||||
-rw-r--r-- | libmemcached-1.2/types/connection.h (renamed from libmemcached-1.0/types/connection.h) | 0 | ||||
-rw-r--r-- | libmemcached-1.2/types/hash.h (renamed from libmemcached-1.0/types/hash.h) | 0 | ||||
-rw-r--r-- | libmemcached-1.2/types/include.am | 8 | ||||
-rw-r--r-- | libmemcached-1.2/types/return.h (renamed from libmemcached-1.0/types/return.h) | 0 | ||||
-rw-r--r-- | libmemcached-1.2/types/server_distribution.h (renamed from libmemcached-1.0/types/server_distribution.h) | 0 | ||||
-rw-r--r-- | libmemcached-1.2/verbosity.h (renamed from libmemcached-1.0/verbosity.h) | 0 | ||||
-rw-r--r-- | libmemcached-1.2/version.h (renamed from libmemcached-1.0/version.h) | 0 | ||||
-rw-r--r-- | libmemcached-1.2/visibility.h (renamed from libmemcached-1.0/visibility.h) | 0 | ||||
-rw-r--r-- | libmemcached/common.h | 2 | ||||
-rw-r--r-- | libmemcached/include.am | 4 | ||||
-rw-r--r-- | libmemcached/memcached.h | 39 | ||||
-rw-r--r-- | libmemcached/memcached.hpp | 40 | ||||
-rw-r--r-- | libmemcached/memcached/protocol_binary.h | 2 | ||||
-rw-r--r-- | libmemcached/memory.h | 2 | ||||
-rw-r--r-- | libmemcached/util.h | 40 | ||||
-rw-r--r-- | libmemcachedprotocol-0.0/binary.h | 728 | ||||
-rw-r--r-- | libmemcachedprotocol-0.0/callback.h | 416 | ||||
-rw-r--r-- | libmemcachedprotocol-0.0/handler.h | 218 | ||||
-rw-r--r-- | libmemcachedprotocol-0.0/include.am | 9 | ||||
-rw-r--r-- | libmemcachedprotocol/ascii_handler.c | 1123 | ||||
-rw-r--r-- | libmemcachedprotocol/ascii_handler.h | 40 | ||||
-rw-r--r-- | libmemcachedprotocol/binary_handler.c | 1198 | ||||
-rw-r--r-- | libmemcachedprotocol/binary_handler.h | 47 | ||||
-rw-r--r-- | libmemcachedprotocol/cache.c | 189 | ||||
-rw-r--r-- | libmemcachedprotocol/cache.h | 148 | ||||
-rw-r--r-- | libmemcachedprotocol/common.h | 162 | ||||
-rw-r--r-- | libmemcachedprotocol/handler.c | 437 | ||||
-rw-r--r-- | libmemcachedprotocol/include.am | 34 | ||||
-rw-r--r-- | libmemcachedprotocol/pedantic.c | 237 | ||||
-rw-r--r-- | libmemcachedutil-1.0/include.am | 13 | ||||
-rw-r--r-- | libmemcachedutil-1.2/flush.h (renamed from libmemcachedutil-1.0/flush.h) | 0 | ||||
-rw-r--r-- | libmemcachedutil-1.2/include.am | 11 | ||||
-rw-r--r-- | libmemcachedutil-1.2/ostream.hpp (renamed from libmemcachedutil-1.0/ostream.hpp) | 0 | ||||
-rw-r--r-- | libmemcachedutil-1.2/pid.h (renamed from libmemcachedutil-1.0/pid.h) | 0 | ||||
-rw-r--r-- | libmemcachedutil-1.2/ping.h (renamed from libmemcachedutil-1.0/ping.h) | 0 | ||||
-rw-r--r-- | libmemcachedutil-1.2/pool.h (renamed from libmemcachedutil-1.0/pool.h) | 3 | ||||
-rw-r--r-- | libmemcachedutil-1.2/util.h (renamed from libmemcachedutil-1.0/util.h) | 12 | ||||
-rw-r--r-- | libmemcachedutil-1.2/version.h (renamed from libmemcachedutil-1.0/version.h) | 0 | ||||
-rw-r--r-- | libmemcachedutil/common.h | 5 | ||||
-rw-r--r-- | libtest/comparison.hpp | 4 | ||||
-rw-r--r-- | libtest/memcached.cc | 4 | ||||
-rw-r--r-- | tests/cycle.cc | 2 | ||||
-rw-r--r-- | tests/failure.cc | 2 | ||||
-rw-r--r-- | tests/libmemcached-1.0/atomsmasher.cc | 2 | ||||
-rw-r--r-- | tests/libmemcached-1.0/basic.cc | 2 | ||||
-rw-r--r-- | tests/libmemcached-1.0/debug.cc | 2 | ||||
-rw-r--r-- | tests/libmemcached-1.0/deprecated.cc | 2 | ||||
-rw-r--r-- | tests/libmemcached-1.0/dump.cc | 4 | ||||
-rw-r--r-- | tests/libmemcached-1.0/encoding_key.cc | 4 | ||||
-rw-r--r-- | tests/libmemcached-1.0/error_conditions.cc | 2 | ||||
-rw-r--r-- | tests/libmemcached-1.0/generate.cc | 2 | ||||
-rw-r--r-- | tests/libmemcached-1.0/ketama.cc | 2 | ||||
-rw-r--r-- | tests/libmemcached-1.0/mem_functions.cc | 24 | ||||
-rw-r--r-- | tests/libmemcached-1.0/memcached_fetch_execute.cc | 2 | ||||
-rw-r--r-- | tests/libmemcached-1.0/memcached_get.cc | 2 | ||||
-rw-r--r-- | tests/libmemcached-1.0/namespace.cc | 2 | ||||
-rw-r--r-- | tests/libmemcached-1.0/parser.cc | 4 | ||||
-rw-r--r-- | tests/libmemcached-1.0/plus.cpp | 2 | ||||
-rw-r--r-- | tests/libmemcached-1.0/pool.cc | 4 | ||||
-rw-r--r-- | tests/libmemcached-1.0/print.cc | 2 | ||||
-rw-r--r-- | tests/libmemcached-1.0/replication.cc | 2 | ||||
-rw-r--r-- | tests/libmemcached-1.0/sasl.cc | 2 | ||||
-rw-r--r-- | tests/libmemcached-1.0/server_add.cc | 2 | ||||
-rw-r--r-- | tests/libmemcached-1.0/setup_and_teardowns.cc | 2 | ||||
-rw-r--r-- | tests/libmemcached-1.0/stat.cc | 4 | ||||
-rw-r--r-- | tests/libmemcached-1.0/string.cc | 2 | ||||
-rw-r--r-- | tests/libmemcached-1.0/touch.cc | 8 | ||||
-rw-r--r-- | tests/libmemcached-1.0/virtual_buckets.cc | 2 | ||||
-rw-r--r-- | tests/mem_udp.cc | 4 | ||||
-rw-r--r-- | tests/memcapable.cc | 2 | ||||
-rw-r--r-- | tests/memcat.cc | 2 | ||||
-rw-r--r-- | tests/memcp.cc | 2 | ||||
-rw-r--r-- | tests/memdump.cc | 2 | ||||
-rw-r--r-- | tests/memerror.cc | 2 | ||||
-rw-r--r-- | tests/memexist.cc | 4 | ||||
-rw-r--r-- | tests/memflush.cc | 2 | ||||
-rw-r--r-- | tests/memrm.cc | 2 | ||||
-rw-r--r-- | tests/memslap.cc | 2 | ||||
-rw-r--r-- | tests/memstat.cc | 2 | ||||
-rw-r--r-- | tests/memtouch.cc | 4 | ||||
-rw-r--r-- | tests/parser.cc | 2 | ||||
-rw-r--r-- | win32/include.am | 1 |
172 files changed, 279 insertions, 7712 deletions
diff --git a/Makefile.am b/Makefile.am index cc6bc018..0ad054e8 100644 --- a/Makefile.am +++ b/Makefile.am @@ -37,18 +37,15 @@ dist_aclocal_DATA= include libtest/include.am include libhashkit-1.0/include.am -include libmemcached-1.0/include.am -include libmemcachedprotocol-0.0/include.am -include libmemcachedutil-1.0/include.am +include libmemcached-1.2/include.am +include libmemcachedutil-1.2/include.am include clients/include.am include docs/include.am include man/include.am -include example/include.am include libhashkit/include.am include libmemcached/include.am include libmemcachedutil/include.am -include libmemcachedprotocol/include.am include libmemcachedinternal/include.am include libmemcachedinternal/util/include.am include poll/include.am diff --git a/clients/execute.h b/clients/execute.h index ebf92f62..57831360 100644 --- a/clients/execute.h +++ b/clients/execute.h @@ -13,7 +13,7 @@ #include <stdio.h> -#include <libmemcached-1.0/memcached.h> +#include <libmemcached-1.2/memcached.h> #include "clients/generator.h" #ifdef __cplusplus diff --git a/clients/memcapable.cc b/clients/memcapable.cc index 2026acee..980e3392 100644 --- a/clients/memcapable.cc +++ b/clients/memcapable.cc @@ -34,7 +34,7 @@ #include <sys/types.h> #include <unistd.h> -#include <libmemcached-1.0/memcached.h> +#include <libmemcached-1.2/memcached.h> #include "libmemcached/socket.hpp" #include "libmemcached/memcached/protocol_binary.h" diff --git a/clients/memcat.cc b/clients/memcat.cc index ef287781..bc66edf3 100644 --- a/clients/memcat.cc +++ b/clients/memcat.cc @@ -17,7 +17,7 @@ #include <getopt.h> #include <iostream> #include <unistd.h> -#include <libmemcached-1.0/memcached.h> +#include <libmemcached-1.2/memcached.h> #include "utilities.h" diff --git a/clients/memcp.cc b/clients/memcp.cc index 4ad0919d..11a5a3d0 100644 --- a/clients/memcp.cc +++ b/clients/memcp.cc @@ -31,7 +31,7 @@ #include <unistd.h> -#include <libmemcached-1.0/memcached.h> +#include <libmemcached-1.2/memcached.h> #include "client_options.h" #include "utilities.h" diff --git a/clients/memdump.cc b/clients/memdump.cc index 5b333728..26cf02ae 100644 --- a/clients/memdump.cc +++ b/clients/memdump.cc @@ -25,7 +25,7 @@ #include <sys/types.h> #include <unistd.h> -#include <libmemcached-1.0/memcached.h> +#include <libmemcached-1.2/memcached.h> #include "client_options.h" #include "utilities.h" diff --git a/clients/memerror.cc b/clients/memerror.cc index 910b2a6d..a8d4a007 100644 --- a/clients/memerror.cc +++ b/clients/memerror.cc @@ -21,7 +21,7 @@ #include <iostream> #include <unistd.h> -#include <libmemcached-1.0/memcached.h> +#include <libmemcached-1.2/memcached.h> #include "utilities.h" diff --git a/clients/memexist.cc b/clients/memexist.cc index af9a72c9..36d2066d 100644 --- a/clients/memexist.cc +++ b/clients/memexist.cc @@ -17,7 +17,7 @@ #include <iostream> #include <unistd.h> -#include <libmemcached-1.0/memcached.h> +#include <libmemcached-1.2/memcached.h> #include "client_options.h" #include "utilities.h" diff --git a/clients/memflush.cc b/clients/memflush.cc index 5342d757..02179fe5 100644 --- a/clients/memflush.cc +++ b/clients/memflush.cc @@ -17,7 +17,8 @@ #include <iostream> #include <unistd.h> -#include <libmemcached-1.0/memcached.h> +#include <libmemcached-1.2/memcached.h> + #include "client_options.h" #include "utilities.h" diff --git a/clients/memparse.cc b/clients/memparse.cc index ab4cee9e..351f785c 100644 --- a/clients/memparse.cc +++ b/clients/memparse.cc @@ -41,7 +41,7 @@ #include <cstring> #include <iostream> -#include <libmemcached-1.0/memcached.h> +#include <libmemcached-1.2/memcached.h> int main(int argc, char *argv[]) { diff --git a/clients/memping.cc b/clients/memping.cc index f4fcec86..f316212d 100644 --- a/clients/memping.cc +++ b/clients/memping.cc @@ -15,8 +15,8 @@ #include <unistd.h> #include <string.h> #include <getopt.h> -#include <libmemcached-1.0/memcached.h> -#include <libmemcachedutil-1.0/util.h> +#include <libmemcached-1.2/memcached.h> +#include <libmemcachedutil-1.2/util.h> #include "client_options.h" #include "utilities.h" diff --git a/clients/memrm.cc b/clients/memrm.cc index 3b7f8a4b..3bf4141a 100644 --- a/clients/memrm.cc +++ b/clients/memrm.cc @@ -17,7 +17,8 @@ #include <iostream> #include <unistd.h> -#include <libmemcached-1.0/memcached.h> +#include <libmemcached-1.2/memcached.h> + #include "client_options.h" #include "utilities.h" diff --git a/clients/memslap.cc b/clients/memslap.cc index 777820a0..419a25b4 100644 --- a/clients/memslap.cc +++ b/clients/memslap.cc @@ -55,7 +55,7 @@ #include <iostream> -#include <libmemcached-1.0/memcached.h> +#include <libmemcached-1.2/memcached.h> #include "client_options.h" #include "utilities.h" diff --git a/clients/memstat.cc b/clients/memstat.cc index 6fd42d6c..3eb3c0c0 100644 --- a/clients/memstat.cc +++ b/clients/memstat.cc @@ -26,7 +26,7 @@ #include <sys/types.h> #include <sys/types.h> -#include <libmemcached-1.0/memcached.h> +#include <libmemcached-1.2/memcached.h> #include "client_options.h" #include "utilities.h" diff --git a/clients/memtouch.cc b/clients/memtouch.cc index 8bb3c78c..8f9d7b28 100644 --- a/clients/memtouch.cc +++ b/clients/memtouch.cc @@ -17,7 +17,7 @@ #include <getopt.h> #include <iostream> #include <unistd.h> -#include <libmemcached-1.0/memcached.h> +#include <libmemcached-1.2/memcached.h> #include "utilities.h" diff --git a/clients/utilities.h b/clients/utilities.h index da973b5f..2aed219a 100644 --- a/clients/utilities.h +++ b/clients/utilities.h @@ -12,7 +12,7 @@ #pragma once #include <getopt.h> -#include <libmemcached-1.0/memcached.h> +#include <libmemcached-1.2/memcached.h> #include "clients/client_options.h" #if TIME_WITH_SYS_TIME diff --git a/configure.ac b/configure.ac index 60d399d2..afeb970d 100644 --- a/configure.ac +++ b/configure.ac @@ -272,7 +272,7 @@ AX_AM_JOBSERVER([yes]) AC_CONFIG_FILES([ Makefile docs/conf.py - libmemcached-1.0/configure.h + libmemcached-1.2/configure.h support/libmemcached.pc support/libmemcached.spec ]) diff --git a/example/byteorder.cc b/example/byteorder.cc deleted file mode 100644 index 5b25624a..00000000 --- a/example/byteorder.cc +++ /dev/null @@ -1,89 +0,0 @@ -/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: - * - * Libmemcached library - * - * Copyright (C) 2011 Data Differential, http://datadifferential.com/ - * Copyright (C) 2006-2009 Brian Aker All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * - * * The names of its contributors may not be used to endorse or - * promote products derived from this software without specific prior - * written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#include <config.h> - -#include <sys/types.h> - -#include <example/byteorder.h> - -/* Byte swap a 64-bit number. */ -#ifndef swap64 -static inline uint64_t swap64(uint64_t in) -{ -#ifndef WORDS_BIGENDIAN - /* Little endian, flip the bytes around until someone makes a faster/better - * way to do this. */ - uint64_t rv= 0; - for (uint8_t x= 0; x < 8; x++) - { - rv= (rv << 8) | (in & 0xff); - in >>= 8; - } - return rv; -#else - /* big-endian machines don't need byte swapping */ - return in; -#endif // WORDS_BIGENDIAN -} -#endif - -#ifdef HAVE_HTONLL - -uint64_t example_ntohll(uint64_t value) -{ - return ntohll(value); -} - -uint64_t example_htonll(uint64_t value) -{ - return htonll(value); -} - -#else // HAVE_HTONLL - -uint64_t example_ntohll(uint64_t value) -{ - return swap64(value); -} - -uint64_t example_htonll(uint64_t value) -{ - return swap64(value); -} - -#endif // HAVE_HTONLL diff --git a/example/byteorder.h b/example/byteorder.h deleted file mode 100644 index 1e319a3e..00000000 --- a/example/byteorder.h +++ /dev/null @@ -1,49 +0,0 @@ -/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: - * - * Byteorder for example - * - * Copyright (C) 2011 Data Differential, http://datadifferential.com/ - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * - * * The names of its contributors may not be used to endorse or - * promote products derived from this software without specific prior - * written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif - -uint64_t example_ntohll(uint64_t); - -uint64_t example_htonll(uint64_t); - -#ifdef __cplusplus -} -#endif diff --git a/example/include.am b/example/include.am deleted file mode 100644 index 8dfa5f4a..00000000 --- a/example/include.am +++ /dev/null @@ -1,28 +0,0 @@ -# vim:ft=automake -# included from Top Level Makefile.am -# All paths should be given relative to the root - -if HAVE_LIBEVENT -noinst_PROGRAMS+= example/memcached_light -endif - -noinst_HEADERS+= example/byteorder.h -noinst_HEADERS+= example/memcached_light.h -noinst_HEADERS+= example/storage.h - -example_memcached_light_SOURCES= -example_memcached_light_LDADD= -example_memcached_light_LDFLAGS= - -example_memcached_light_SOURCES+= example/byteorder.cc -example_memcached_light_SOURCES+= example/interface_v0.cc -example_memcached_light_SOURCES+= example/interface_v1.cc -example_memcached_light_SOURCES+= example/memcached_light.cc -example_memcached_light_SOURCES+= example/storage.cc -example_memcached_light_SOURCES+= util/daemon.cc -example_memcached_light_SOURCES+= util/pidfile.cc - -example_memcached_light_LDADD+= libmemcached/libmemcachedprotocol.la -example_memcached_light_LDFLAGS+= @LIBEVENT_LDFLAGS@ - -include example/t/include.am diff --git a/example/interface_v0.cc b/example/interface_v0.cc deleted file mode 100644 index 1cba4eb1..00000000 --- a/example/interface_v0.cc +++ /dev/null @@ -1,561 +0,0 @@ -/* -*- Mode: C; tab-width: 2; c-basic-offset: 2; indent-tabs-mode: nil -*- */ -/** - * This file contains an implementation of the callback interface for level 0 - * in the protocol library. You might want to have your copy of the protocol - * specification next to your coffee ;-) - */ - -#include "config.h" - -#include <cassert> -#include <sys/types.h> -#include <cstdio> -#include <unistd.h> -#include <fcntl.h> -#include <cerrno> -#include <cstdlib> -#include <cstring> - -#include <libmemcachedprotocol-0.0/handler.h> -#include <example/byteorder.h> -#include "example/memcached_light.h" -#include "example/storage.h" -#include "util/log.hpp" - - -using namespace datadifferential; - -static util::log_info_st *log_file= NULL; - -static protocol_binary_response_status noop_command_handler(const void *cookie, - protocol_binary_request_header *header, - memcached_binary_protocol_raw_response_handler response_handler) -{ - protocol_binary_response_no_extras response; - memset(&response, 0, sizeof(protocol_binary_response_no_extras)); - - response.message.header.response.magic= PROTOCOL_BINARY_RES; - response.message.header.response.opcode= PROTOCOL_BINARY_CMD_NOOP; - response.message.header.response.status= htons(PROTOCOL_BINARY_RESPONSE_SUCCESS); - response.message.header.response.opaque= header->request.opaque; - - return response_handler(cookie, header, (protocol_binary_response_header*)&response); -} - -static protocol_binary_response_status quit_command_handler(const void *cookie, - protocol_binary_request_header *header, - memcached_binary_protocol_raw_response_handler response_handler) -{ - protocol_binary_response_no_extras response; - memset(&response, 0, sizeof(protocol_binary_response_no_extras)); - - response.message.header.response.magic= PROTOCOL_BINARY_RES; - response.message.header.response.opcode= PROTOCOL_BINARY_CMD_QUIT; - response.message.header.response.status= htons(PROTOCOL_BINARY_RESPONSE_SUCCESS); - response.message.header.response.opaque= header->request.opaque; - - if (header->request.opcode == PROTOCOL_BINARY_CMD_QUIT) - { - response_handler(cookie, header, (protocol_binary_response_header*)&response); - } - - /* I need a better way to signal to close the connection */ - return PROTOCOL_BINARY_RESPONSE_EINTERNAL; -} - -static protocol_binary_response_status get_command_handler(const void *cookie, - protocol_binary_request_header *header, - memcached_binary_protocol_raw_response_handler response_handler) -{ - uint8_t opcode= header->request.opcode; - union protocol_binary_response_get_un { - protocol_binary_response_get response; - char buffer[4096]; - }; - - protocol_binary_response_get_un msg; - memset(&msg, 0, sizeof(protocol_binary_response_get_un)); - - msg.response.message.header.response.magic= PROTOCOL_BINARY_RES; - msg.response.message.header.response.opcode= opcode; - msg.response.message.header.response.status= htons(PROTOCOL_BINARY_RESPONSE_SUCCESS); - msg.response.message.header.response.opaque= header->request.opaque; - - struct item *item= get_item(header + 1, ntohs(header->request.keylen)); - if (item) - { - msg.response.message.body.flags= htonl(item->flags); - char *ptr= (char*)(msg.response.bytes + sizeof(*header) + 4); - uint32_t bodysize= 4; - msg.response.message.header.response.cas= example_htonll(item->cas); - if (opcode == PROTOCOL_BINARY_CMD_GETK || opcode == PROTOCOL_BINARY_CMD_GETKQ) - { - memcpy(ptr, item->key, item->nkey); - msg.response.message.header.response.keylen= htons((uint16_t)item->nkey); - ptr += item->nkey; - bodysize += (uint32_t)item->nkey; - } - memcpy(ptr, item->data, item->size); - bodysize += (uint32_t)item->size; - msg.response.message.header.response.bodylen= htonl(bodysize); - msg.response.message.header.response.extlen= 4; - - release_item(item); - return response_handler(cookie, header, (protocol_binary_response_header*)&msg); - } - else if (opcode == PROTOCOL_BINARY_CMD_GET || opcode == PROTOCOL_BINARY_CMD_GETK) - { - msg.response.message.header.response.status= htons(PROTOCOL_BINARY_RESPONSE_KEY_ENOENT); - return response_handler(cookie, header, (protocol_binary_response_header*)&msg); - } - - /* Q shouldn't report a miss ;-) */ - return PROTOCOL_BINARY_RESPONSE_SUCCESS; -} - -static protocol_binary_response_status delete_command_handler(const void *cookie, - protocol_binary_request_header *header, - memcached_binary_protocol_raw_response_handler response_handler) -{ - size_t keylen= ntohs(header->request.keylen); - - char *key= ((char*)header) + sizeof(*header); - protocol_binary_response_no_extras response; - memset(&response, 0, sizeof(protocol_binary_response_no_extras)); - - response.message.header.response.magic= PROTOCOL_BINARY_RES; - response.message.header.response.opcode= header->request.opcode; - response.message.header.response.opaque= header->request.opaque; - - if (delete_item(key, keylen) == false) - { - log_file->write(util::VERBOSE_NOTICE, "%s not found: %.*s", __func__, keylen, key); - response.message.header.response.status= htons(PROTOCOL_BINARY_RESPONSE_KEY_ENOENT); - return response_handler(cookie, header, (protocol_binary_response_header*)&response); - } - else if (header->request.opcode == PROTOCOL_BINARY_CMD_DELETE) - { - log_file->write(util::VERBOSE_NOTICE, "%s not found: %.*s", __func__, keylen, key); - /* DELETEQ doesn't want success response */ - response.message.header.response.status= htons(PROTOCOL_BINARY_RESPONSE_SUCCESS); - return response_handler(cookie, header, (protocol_binary_response_header*)&response); - } - - log_file->write(util::VERBOSE_NOTICE, "%s deleted: %.*s", __func__, keylen, key); - - return PROTOCOL_BINARY_RESPONSE_SUCCESS; -} - -static protocol_binary_response_status flush_command_handler(const void *cookie, - protocol_binary_request_header *header, - memcached_binary_protocol_raw_response_handler response_handler) -{ - uint8_t opcode= header->request.opcode; - - /* @fixme sett inn when! */ - flush(0); - - if (opcode == PROTOCOL_BINARY_CMD_FLUSH) - { - protocol_binary_response_no_extras response; - memset(&response, 0, sizeof(protocol_binary_response_no_extras)); - - response.message.header.response.magic= PROTOCOL_BINARY_RES; - response.message.header.response.opcode= opcode; - response.message.header.response.status= htons(PROTOCOL_BINARY_RESPONSE_SUCCESS); - response.message.header.response.opaque= header->request.opaque; - - return response_handler(cookie, header, (protocol_binary_response_header*)&response); - } - - return PROTOCOL_BINARY_RESPONSE_SUCCESS; -} - -static protocol_binary_response_status arithmetic_command_handler(const void *cookie, - protocol_binary_request_header *header, - memcached_binary_protocol_raw_response_handler response_handler) -{ - protocol_binary_request_incr *req= (protocol_binary_request_incr*)header; - protocol_binary_response_incr response; - memset(&response, 0, sizeof(protocol_binary_response_incr)); - - response.message.header.response.magic= PROTOCOL_BINARY_RES; - response.message.header.response.opcode= header->request.opcode; - response.message.header.response.opaque= header->request.opaque; - - uint16_t keylen= ntohs(header->request.keylen); - uint64_t initial= example_ntohll(req->message.body.initial); - uint64_t delta= example_ntohll(req->message.body.delta); - uint32_t expiration= ntohl(req->message.body.expiration); - uint32_t flags= 0; - void *key= req->bytes + sizeof(req->bytes); - protocol_binary_response_status rval= PROTOCOL_BINARY_RESPONSE_SUCCESS; - - uint64_t value= initial; - - struct item *item= get_item(key, keylen); - if (item != NULL) - { - if (header->request.opcode == PROTOCOL_BINARY_CMD_INCREMENT || - header->request.opcode == PROTOCOL_BINARY_CMD_INCREMENTQ) - { - value= (*(uint64_t*)item->data) + delta; - } - else - { - if (delta > *(uint64_t*)item->data) - { - value= 0; - } - else - { - value= *(uint64_t*)item->data - delta; - } - } - expiration= (uint32_t)item->exp; - flags= item->flags; - - release_item(item); - delete_item(key, keylen); - } - - item= create_item(key, keylen, NULL, sizeof(value), flags, (time_t)expiration); - if (item == NULL) - { - rval= PROTOCOL_BINARY_RESPONSE_ENOMEM; - } - else - { - memcpy(item->data, &value, sizeof(value)); - put_item(item); - } - - response.message.header.response.status= htons(rval); - if (rval == PROTOCOL_BINARY_RESPONSE_SUCCESS) - { - response.message.header.response.bodylen= ntohl(8); - response.message.body.value= example_ntohll((*(uint64_t*)item->data)); - response.message.header.response.cas= example_ntohll(item->cas); - - release_item(item); - if (header->request.opcode == PROTOCOL_BINARY_CMD_INCREMENTQ || - header->request.opcode == PROTOCOL_BINARY_CMD_DECREMENTQ) - { - return PROTOCOL_BINARY_RESPONSE_SUCCESS; - } - } - - return response_handler(cookie, header, (protocol_binary_response_header*)&response); -} - -static protocol_binary_response_status version_command_handler(const void *cookie, - protocol_binary_request_header *header, - memcached_binary_protocol_raw_response_handler response_handler) -{ - const char *versionstring= "1.0.0"; - union protocol_binary_response_header_un - { - protocol_binary_response_header packet; - char buffer[256]; - }; - - protocol_binary_response_header_un response; - memset(&response, 0, sizeof(protocol_binary_response_header_un)); - - response.packet.response.magic= PROTOCOL_BINARY_RES; - response.packet.response.opcode= PROTOCOL_BINARY_CMD_VERSION; - response.packet.response.status= htons(PROTOCOL_BINARY_RESPONSE_SUCCESS); - response.packet.response.opaque= header->request.opaque; - response.packet.response.cas= 0; - response.packet.response.bodylen= htonl((uint32_t)strlen(versionstring)); - - assert(sizeof(protocol_binary_response_header) +strlen(versionstring) <= 256); - memcpy(response.buffer + sizeof(protocol_binary_response_header), versionstring, strlen(versionstring)); - - return response_handler(cookie, header, (protocol_binary_response_header*)&response); -} - -static protocol_binary_response_status concat_command_handler(const void *cookie, - protocol_binary_request_header *header, - memcached_binary_protocol_raw_response_handler response_handler) -{ - protocol_binary_response_status rval= PROTOCOL_BINARY_RESPONSE_SUCCESS; - uint16_t keylen= ntohs(header->request.keylen); - uint64_t cas= example_ntohll(header->request.cas); - void *key= header + 1; - uint32_t vallen= ntohl(header->request.bodylen) - keylen; - void *val= (char*)key + keylen; - - struct item *item= get_item(key, keylen); - struct item *nitem= NULL; - - if (item == NULL) - { - rval= PROTOCOL_BINARY_RESPONSE_KEY_ENOENT; - } - else if (cas != 0 && cas != item->cas) - { - rval= PROTOCOL_BINARY_RESPONSE_KEY_EEXISTS; - } - else if ((nitem= create_item(key, keylen, NULL, item->size + vallen, - item->flags, item->exp)) == NULL) - { - release_item(item); - rval= PROTOCOL_BINARY_RESPONSE_ENOMEM; - } - else - { - if (header->request.opcode == PROTOCOL_BINARY_CMD_APPEND || - header->request.opcode == PROTOCOL_BINARY_CMD_APPENDQ) - { - memcpy(nitem->data, item->data, item->size); - memcpy(((char*)(nitem->data)) + item->size, val, vallen); - } - else - { - memcpy(nitem->data, val, vallen); - memcpy(((char*)(nitem->data)) + vallen, item->data, item->size); - } - release_item(item); - delete_item(key, keylen); - put_item(nitem); - cas= nitem->cas; - release_item(nitem); - - if (header->request.opcode == PROTOCOL_BINARY_CMD_APPEND || - header->request.opcode == PROTOCOL_BINARY_CMD_PREPEND) - { - protocol_binary_response_no_extras response; - memset(&response, 0, sizeof(protocol_binary_response_no_extras)); - - response.message.header.response.magic= PROTOCOL_BINARY_RES; - response.message.header.response.opcode= header->request.opcode; - response.message.header.response.status= htons(rval); - response.message.header.response.opaque= header->request.opaque; - response.message.header.response.cas= example_htonll(cas); - - return response_handler(cookie, header, (protocol_binary_response_header*)&response); - } - } - - return rval; -} - -static protocol_binary_response_status set_command_handler(const void *cookie, - protocol_binary_request_header *header, - memcached_binary_protocol_raw_response_handler response_handler) -{ - size_t keylen= ntohs(header->request.keylen); - size_t datalen= ntohl(header->request.bodylen) - keylen - 8; - protocol_binary_request_replace *request= (protocol_binary_request_replace*)header; - uint32_t flags= ntohl(request->message.body.flags); - time_t timeout= (time_t)ntohl(request->message.body.expiration); - char *key= ((char*)header) + sizeof(*header) + 8; - char *data= key + keylen; - - protocol_binary_response_no_extras response; - memset(&response, 0, sizeof(protocol_binary_response_no_extras)); - - response.message.header.response.magic= PROTOCOL_BINARY_RES; - response.message.header.response.opcode= header->request.opcode; - response.message.header.response.status= htons(PROTOCOL_BINARY_RESPONSE_SUCCESS); - response.message.header.response.opaque= header->request.opaque; - - if (header->request.cas != 0) - { - /* validate cas */ - struct item* item= get_item(key, keylen); - if (item != NULL) - { - if (item->cas != example_ntohll(header->request.cas)) - { - release_item(item); - response.message.header.response.status= htons(PROTOCOL_BINARY_RESPONSE_KEY_EEXISTS); - return response_handler(cookie, header, (protocol_binary_response_header*)&response); - } - release_item(item); - } - } - - delete_item(key, keylen); - struct item* item= create_item(key, keylen, data, datalen, flags, timeout); - if (item == NULL) - { - response.message.header.response.status= htons(PROTOCOL_BINARY_RESPONSE_ENOMEM); - } - else - { - put_item(item); - /* SETQ shouldn't return a message */ - if (header->request.opcode == PROTOCOL_BINARY_CMD_SET) - { - response.message.header.response.cas= example_htonll(item->cas); - release_item(item); - return response_handler(cookie, header, (protocol_binary_response_header*)&response); - } - release_item(item); - - return PROTOCOL_BINARY_RESPONSE_SUCCESS; - } - - return response_handler(cookie, header, (protocol_binary_response_header*)&response); -} - -static protocol_binary_response_status add_command_handler(const void *cookie, - protocol_binary_request_header *header, - memcached_binary_protocol_raw_response_handler response_handler) -{ - size_t keylen= ntohs(header->request.keylen); - size_t datalen= ntohl(header->request.bodylen) - keylen - 8; - protocol_binary_request_add *request= (protocol_binary_request_add*)header; - uint32_t flags= ntohl(request->message.body.flags); - time_t timeout= (time_t)ntohl(request->message.body.expiration); - char *key= ((char*)header) + sizeof(*header) + 8; - char *data= key + keylen; - - protocol_binary_response_no_extras response; - memset(&response, 0, sizeof(protocol_binary_response_no_extras)); - - response.message.header.response.magic= PROTOCOL_BINARY_RES; - response.message.header.response.opcode= header->request.opcode; - response.message.header.response.status= htons(PROTOCOL_BINARY_RESPONSE_SUCCESS); - response.message.header.response.opaque= header->request.opaque; - - struct item* item= get_item(key, keylen); - if (item == NULL) - { - item= create_item(key, keylen, data, datalen, flags, timeout); - if (item == NULL) - response.message.header.response.status= htons(PROTOCOL_BINARY_RESPONSE_ENOMEM); - else - { - put_item(item); - /* ADDQ shouldn't return a message */ - if (header->request.opcode == PROTOCOL_BINARY_CMD_ADD) - { - response.message.header.response.cas= example_htonll(item->cas); - release_item(item); - return response_handler(cookie, header, (protocol_binary_response_header*)&response); - } - release_item(item); - return PROTOCOL_BINARY_RESPONSE_SUCCESS; - } - } - else - { - release_item(item); - response.message.header.response.status= htons(PROTOCOL_BINARY_RESPONSE_KEY_EEXISTS); - } - - return response_handler(cookie, header, (protocol_binary_response_header*)&response); -} - -static protocol_binary_response_status replace_command_handler(const void *cookie, - protocol_binary_request_header *header, - memcached_binary_protocol_raw_response_handler response_handler) -{ - size_t keylen= ntohs(header->request.keylen); - size_t datalen= ntohl(header->request.bodylen) - keylen - 8; - protocol_binary_request_replace *request= (protocol_binary_request_replace*)header; - uint32_t flags= ntohl(request->message.body.flags); - time_t timeout= (time_t)ntohl(request->message.body.expiration); - char *key= ((char*)header) + sizeof(*header) + 8; - char *data= key + keylen; - - protocol_binary_response_no_extras response; - memset(&response, 0, sizeof(protocol_binary_response_no_extras)); - - response.message.header.response.magic= PROTOCOL_BINARY_RES; - response.message.header.response.opcode= header->request.opcode; - response.message.header.response.status= htons(PROTOCOL_BINARY_RESPONSE_SUCCESS); - response.message.header.response.opaque= header->request.opaque; - - struct item* item= get_item(key, keylen); - if (item == NULL) - { - response.message.header.response.status= htons(PROTOCOL_BINARY_RESPONSE_KEY_ENOENT); - } - else if (header->request.cas == 0 || example_ntohll(header->request.cas) == item->cas) - { - release_item(item); - delete_item(key, keylen); - item= create_item(key, keylen, data, datalen, flags, timeout); - - if (item == NULL) - { - response.message.header.response.status= htons(PROTOCOL_BINARY_RESPONSE_ENOMEM); - } - else - { - put_item(item); - /* REPLACEQ shouldn't return a message */ - if (header->request.opcode == PROTOCOL_BINARY_CMD_REPLACE) - { - response.message.header.response.cas= example_htonll(item->cas); - release_item(item); - return response_handler(cookie, header, (protocol_binary_response_header*)&response); - } - release_item(item); - return PROTOCOL_BINARY_RESPONSE_SUCCESS; - } - } - else - { - response.message.header.response.status= htons(PROTOCOL_BINARY_RESPONSE_KEY_EEXISTS); - release_item(item); - } - - return response_handler(cookie, header, (protocol_binary_response_header*)&response); -} - -static protocol_binary_response_status stat_command_handler(const void *cookie, - protocol_binary_request_header *header, - memcached_binary_protocol_raw_response_handler response_handler) -{ - /* Just send the terminating packet*/ - protocol_binary_response_no_extras response; - memset(&response, 0, sizeof(protocol_binary_response_no_extras)); - - response.message.header.response.magic= PROTOCOL_BINARY_RES; - response.message.header.response.opcode= PROTOCOL_BINARY_CMD_STAT; - response.message.header.response.status= htons(PROTOCOL_BINARY_RESPONSE_SUCCESS); - response.message.header.response.opaque= header->request.opaque; - - return response_handler(cookie, header, (protocol_binary_response_header*)&response); -} - -memcached_binary_protocol_callback_st interface_v0_impl; - -void initialize_interface_v0_handler(util::log_info_st& arg) -{ - log_file= &arg; - - interface_v0_impl.interface_version= MEMCACHED_PROTOCOL_HANDLER_V0; - interface_v0_impl.interface.v0.comcode[PROTOCOL_BINARY_CMD_GET]= get_command_handler; - interface_v0_impl.interface.v0.comcode[PROTOCOL_BINARY_CMD_SET]= set_command_handler; - interface_v0_impl.interface.v0.comcode[PROTOCOL_BINARY_CMD_ADD]= add_command_handler; - interface_v0_impl.interface.v0.comcode[PROTOCOL_BINARY_CMD_REPLACE]= replace_command_handler; - interface_v0_impl.interface.v0.comcode[PROTOCOL_BINARY_CMD_DELETE]= delete_command_handler; - interface_v0_impl.interface.v0.comcode[PROTOCOL_BINARY_CMD_INCREMENT]= arithmetic_command_handler; - interface_v0_impl.interface.v0.comcode[PROTOCOL_BINARY_CMD_DECREMENT]= arithmetic_command_handler; - interface_v0_impl.interface.v0.comcode[PROTOCOL_BINARY_CMD_QUIT]= quit_command_handler; - interface_v0_impl.interface.v0.comcode[PROTOCOL_BINARY_CMD_FLUSH]= flush_command_handler; - interface_v0_impl.interface.v0.comcode[PROTOCOL_BINARY_CMD_GETQ]= get_command_handler; - interface_v0_impl.interface.v0.comcode[PROTOCOL_BINARY_CMD_NOOP]= noop_command_handler; - interface_v0_impl.interface.v0.comcode[PROTOCOL_BINARY_CMD_VERSION]= version_command_handler; - interface_v0_impl.interface.v0.comcode[PROTOCOL_BINARY_CMD_GETK]= get_command_handler; - interface_v0_impl.interface.v0.comcode[PROTOCOL_BINARY_CMD_GETKQ]= get_command_handler; - interface_v0_impl.interface.v0.comcode[PROTOCOL_BINARY_CMD_APPEND]= concat_command_handler; - interface_v0_impl.interface.v0.comcode[PROTOCOL_BINARY_CMD_PREPEND]= concat_command_handler; - interface_v0_impl.interface.v0.comcode[PROTOCOL_BINARY_CMD_STAT]= stat_command_handler; - interface_v0_impl.interface.v0.comcode[PROTOCOL_BINARY_CMD_SETQ]= set_command_handler; - interface_v0_impl.interface.v0.comcode[PROTOCOL_BINARY_CMD_ADDQ]= add_command_handler; - interface_v0_impl.interface.v0.comcode[PROTOCOL_BINARY_CMD_REPLACEQ]= replace_command_handler; - interface_v0_impl.interface.v0.comcode[PROTOCOL_BINARY_CMD_DELETEQ]= delete_command_handler; - interface_v0_impl.interface.v0.comcode[PROTOCOL_BINARY_CMD_INCREMENTQ]= arithmetic_command_handler; - interface_v0_impl.interface.v0.comcode[PROTOCOL_BINARY_CMD_DECREMENTQ]= arithmetic_command_handler; - interface_v0_impl.interface.v0.comcode[PROTOCOL_BINARY_CMD_QUITQ]= quit_command_handler; - interface_v0_impl.interface.v0.comcode[PROTOCOL_BINARY_CMD_FLUSHQ]= flush_command_handler; - interface_v0_impl.interface.v0.comcode[PROTOCOL_BINARY_CMD_APPENDQ]= concat_command_handler; - interface_v0_impl.interface.v0.comcode[PROTOCOL_BINARY_CMD_PREPENDQ]= concat_command_handler; -} diff --git a/example/interface_v1.cc b/example/interface_v1.cc deleted file mode 100644 index 8afe12a3..00000000 --- a/example/interface_v1.cc +++ /dev/null @@ -1,417 +0,0 @@ -/* -*- Mode: C; tab-width: 2; c-basic-offset: 2; indent-tabs-mode: nil -*- */ -/** - * This file contains an implementation of the callback interface for level 1 - * in the protocol library. If you compare the implementation with the one - * in interface_v0.cc you will see that this implementation is much easier and - * hides all of the protocol logic and let you focus on the application - * logic. One "problem" with this layer is that it is synchronous, so that - * you will not receive the next command before a answer to the previous - * command is being sent. - */ -#include "config.h" - -#include <cassert> -#include <cerrno> -#include <cstdio> -#include <cstdlib> -#include <cstring> -#include <fcntl.h> -#include <sys/types.h> -#include <unistd.h> - -#include <libmemcachedprotocol-0.0/handler.h> -#include <example/byteorder.h> -#include "example/memcached_light.h" -#include "example/storage.h" -#include "util/log.hpp" - -static datadifferential::util::log_info_st *log_file= NULL; - -static protocol_binary_response_status add_handler(const void *cookie, - const void *key, - uint16_t keylen, - const void *data, - uint32_t datalen, - uint32_t flags, - uint32_t exptime, - uint64_t *cas) -{ - (void)cookie; - protocol_binary_response_status rval= PROTOCOL_BINARY_RESPONSE_SUCCESS; - struct item* item= get_item(key, keylen); - if (item == NULL) - { - item= create_item(key, keylen, data, datalen, flags, (time_t)exptime); - if (item == 0) - { - rval= PROTOCOL_BINARY_RESPONSE_ENOMEM; - } - else - { - put_item(item); - *cas= item->cas; - release_item(item); - } - } - else - { - rval= PROTOCOL_BINARY_RESPONSE_KEY_EEXISTS; - } - - return rval; -} - -static protocol_binary_response_status append_handler(const void *cookie, - const void *key, - uint16_t keylen, - const void* val, - uint32_t vallen, - uint64_t cas, - uint64_t *result_cas) -{ - (void)cookie; - protocol_binary_response_status rval= PROTOCOL_BINARY_RESPONSE_SUCCESS; - - struct item *item= get_item(key, keylen); - struct item *nitem; - - if (item == NULL) - { - rval= PROTOCOL_BINARY_RESPONSE_KEY_ENOENT; - } - else if (cas != 0 && cas != item->cas) - { - rval= PROTOCOL_BINARY_RESPONSE_KEY_EEXISTS; - } - else if ((nitem= create_item(key, keylen, NULL, item->size + vallen, - item->flags, item->exp)) == NULL) - { - release_item(item); - rval= PROTOCOL_BINARY_RESPONSE_ENOMEM; - } - else - { - memcpy(nitem->data, item->data, item->size); - memcpy(((char*)(nitem->data)) + item->size, val, vallen); - release_item(item); - delete_item(key, keylen); - put_item(nitem); - *result_cas= nitem->cas; - release_item(nitem); - } - - return rval; -} - -static protocol_binary_response_status decrement_handler(const void *cookie, - const void *key, - uint16_t keylen, - uint64_t delta, - uint64_t initial, - uint32_t expiration, - uint64_t *result, - uint64_t *result_cas) { - (void)cookie; - protocol_binary_response_status rval= PROTOCOL_BINARY_RESPONSE_SUCCESS; - uint64_t val= initial; - struct item *item= get_item(key, keylen); - - if (item != NULL) - { - if (delta > *(uint64_t*)item->data) - val= 0; - else - val= *(uint64_t*)item->data - delta; - - expiration= (uint32_t)item->exp; - release_item(item); - delete_item(key, keylen); - } - - item= create_item(key, keylen, NULL, sizeof(initial), 0, (time_t)expiration); - if (item == 0) - { - rval= PROTOCOL_BINARY_RESPONSE_ENOMEM; - } - else - { - memcpy(item->data, &val, sizeof(val)); - put_item(item); - *result= val; - *result_cas= item->cas; - release_item(item); - } - - return rval; -} - -static protocol_binary_response_status delete_handler(const void *, // cookie - const void *key, - uint16_t keylen, - uint64_t cas) -{ - protocol_binary_response_status rval= PROTOCOL_BINARY_RESPONSE_SUCCESS; - - if (cas != 0) - { - struct item *item= get_item(key, keylen); - if (item != NULL) - { - if (item->cas != cas) - { - release_item(item); - return PROTOCOL_BINARY_RESPONSE_KEY_EEXISTS; - } - release_item(item); - } - } - - if (!delete_item(key, keylen)) - { - rval= PROTOCOL_BINARY_RESPONSE_KEY_ENOENT; - } - - return rval; -} - - -static protocol_binary_response_status flush_handler(const void * /* cookie */, uint32_t /* when */) -{ - return PROTOCOL_BINARY_RESPONSE_SUCCESS; -} - -static protocol_binary_response_status get_handler(const void *cookie, - const void *key, - uint16_t keylen, - memcached_binary_protocol_get_response_handler response_handler) { - struct item *item= get_item(key, keylen); - - if (item == NULL) - { - return PROTOCOL_BINARY_RESPONSE_KEY_ENOENT; - } - - protocol_binary_response_status rc; - rc= response_handler(cookie, key, (uint16_t)keylen, - item->data, (uint32_t)item->size, item->flags, - item->cas); - release_item(item); - return rc; -} - -static protocol_binary_response_status increment_handler(const void *cookie, - const void *key, - uint16_t keylen, - uint64_t delta, - uint64_t initial, - uint32_t expiration, - uint64_t *result, - uint64_t *result_cas) { - (void)cookie; - protocol_binary_response_status rval= PROTOCOL_BINARY_RESPONSE_SUCCESS; - uint64_t val= initial; - struct item *item= get_item(key, keylen); - - if (item != NULL) - { - val= (*(uint64_t*)item->data) + delta; - expiration= (uint32_t)item->exp; - release_item(item); - delete_item(key, keylen); - } - - item= create_item(key, keylen, NULL, sizeof(initial), 0, (time_t)expiration); - if (item == NULL) - { - rval= PROTOCOL_BINARY_RESPONSE_ENOMEM; - } - else - { - char buffer[1024] = {0}; - memcpy(buffer, key, keylen); - memcpy(item->data, &val, sizeof(val)); - put_item(item); - *result= val; - *result_cas= item->cas; - release_item(item); - } - - return rval; -} - -static protocol_binary_response_status noop_handler(const void *cookie) { - (void)cookie; - return PROTOCOL_BINARY_RESPONSE_SUCCESS; -} - -static protocol_binary_response_status prepend_handler(const void *cookie, - const void *key, - uint16_t keylen, - const void* val, - uint32_t vallen, - uint64_t cas, - uint64_t *result_cas) { - (void)cookie; - protocol_binary_response_status rval= PROTOCOL_BINARY_RESPONSE_SUCCESS; - - struct item *item= get_item(key, keylen); - struct item *nitem= NULL; - - if (item == NULL) - { - rval= PROTOCOL_BINARY_RESPONSE_KEY_ENOENT; - } - else if (cas != 0 && cas != item->cas) - { - rval= PROTOCOL_BINARY_RESPONSE_KEY_EEXISTS; - } - else if ((nitem= create_item(key, keylen, NULL, item->size + vallen, - item->flags, item->exp)) == NULL) - { - rval= PROTOCOL_BINARY_RESPONSE_ENOMEM; - } - else - { - memcpy(nitem->data, val, vallen); - memcpy(((char*)(nitem->data)) + vallen, item->data, item->size); - release_item(item); - item= NULL; - delete_item(key, keylen); - put_item(nitem); - *result_cas= nitem->cas; - } - - if (item) - release_item(item); - - if (nitem) - release_item(nitem); - - return rval; -} - -static protocol_binary_response_status quit_handler(const void *) //cookie -{ - return PROTOCOL_BINARY_RESPONSE_SUCCESS; -} - -static protocol_binary_response_status replace_handler(const void *, // cookie - const void *key, - uint16_t keylen, - const void* data, - uint32_t datalen, - uint32_t flags, - uint32_t exptime, - uint64_t cas, - uint64_t *result_cas) -{ - protocol_binary_response_status rval= PROTOCOL_BINARY_RESPONSE_SUCCESS; - struct item* item= get_item(key, keylen); - - if (item == NULL) - { - rval= PROTOCOL_BINARY_RESPONSE_KEY_ENOENT; - } - else if (cas == 0 || cas == item->cas) - { - release_item(item); - delete_item(key, keylen); - item= create_item(key, keylen, data, datalen, flags, (time_t)exptime); - if (item == 0) - { - rval= PROTOCOL_BINARY_RESPONSE_ENOMEM; - } - else - { - put_item(item); - *result_cas= item->cas; - release_item(item); - } - } - else - { - rval= PROTOCOL_BINARY_RESPONSE_KEY_EEXISTS; - release_item(item); - } - - return rval; -} - -static protocol_binary_response_status set_handler(const void *cookie, - const void *key, - uint16_t keylen, - const void* data, - uint32_t datalen, - uint32_t flags, - uint32_t exptime, - uint64_t cas, - uint64_t *result_cas) { - (void)cookie; - protocol_binary_response_status rval= PROTOCOL_BINARY_RESPONSE_SUCCESS; - - if (cas != 0) - { - struct item* item= get_item(key, keylen); - if (item != NULL && cas != item->cas) - { - /* Invalid CAS value */ - release_item(item); - return PROTOCOL_BINARY_RESPONSE_KEY_EEXISTS; - } - } - - delete_item(key, keylen); - struct item* item= create_item(key, keylen, data, datalen, flags, (time_t)exptime); - if (item == 0) - { - rval= PROTOCOL_BINARY_RESPONSE_ENOMEM; - } - else - { - put_item(item); - *result_cas= item->cas; - release_item(item); - } - - return rval; -} - -static protocol_binary_response_status stat_handler(const void *cookie, - const void *, // key - uint16_t, // keylen, - memcached_binary_protocol_stat_response_handler response_handler) -{ - /* Just return an empty packet */ - return response_handler(cookie, NULL, 0, NULL, 0); -} - -static protocol_binary_response_status version_handler(const void *cookie, - memcached_binary_protocol_version_response_handler response_handler) -{ - const char *version= "0.1.1"; - return response_handler(cookie, version, (uint32_t)strlen(version)); -} - -memcached_binary_protocol_callback_st interface_v1_impl; - -void initialize_interface_v1_handler(datadifferential::util::log_info_st& arg) -{ - log_file= &arg; - memset(&interface_v1_impl, 0, sizeof(memcached_binary_protocol_callback_st)); - - interface_v1_impl.interface_version= MEMCACHED_PROTOCOL_HANDLER_V1; - interface_v1_impl.interface.v1.add= add_handler; - interface_v1_impl.interface.v1.append= append_handler; - interface_v1_impl.interface.v1.decrement= decrement_handler; - interface_v1_impl.interface.v1.delete_object= delete_handler; - interface_v1_impl.interface.v1.flush_object= flush_handler; - interface_v1_impl.interface.v1.get= get_handler; - interface_v1_impl.interface.v1.increment= increment_handler; - interface_v1_impl.interface.v1.noop= noop_handler; - interface_v1_impl.interface.v1.prepend= prepend_handler; - interface_v1_impl.interface.v1.quit= quit_handler; - interface_v1_impl.interface.v1.replace= replace_handler; - interface_v1_impl.interface.v1.set= set_handler; - interface_v1_impl.interface.v1.stat= stat_handler; - interface_v1_impl.interface.v1.version= version_handler; -} diff --git a/example/memcached_light.cc b/example/memcached_light.cc deleted file mode 100644 index 3f14c8ee..00000000 --- a/example/memcached_light.cc +++ /dev/null @@ -1,646 +0,0 @@ -/* -*- Mode: C; tab-width: 2; c-basic-offset: 2; indent-tabs-mode: nil -*- */ -/** - * What is a library without an example to show you how to use the library? - * This example use both interfaces to implement a small memcached server. - * Please note that this is an exemple on how to use the library, not - * an implementation of a scalable memcached server. If you look closely - * at the example it isn't even multithreaded ;-) - * - * With that in mind, let me give you some pointers into the source: - * storage.c/h - Implements the item store for this server and not really - * interesting for this example. - * interface_v0.cc - Shows an implementation of the memcached server by using - * the "raw" access to the packets as they arrive - * interface_v1.cc - Shows an implementation of the memcached server by using - * the more "logical" interface. - * memcached_light.cc- This file sets up all of the sockets and run the main - * message loop. - * - * - * config.h is included so that I can use the ntohll/htonll on platforms that - * doesn't have that (this is a private function inside libmemcached, so you - * cannot use it directly from libmemcached without special modifications to - * the library) - */ - -#include <config.h> - -#include <libmemcachedprotocol-0.0/handler.h> -#include <libmemcached/socket.hpp> -#include <example/byteorder.h> -#include "example/storage.h" -#include "example/memcached_light.h" - -#include "util/daemon.hpp" -#include "util/log.hpp" -#include "util/pidfile.hpp" - -using namespace datadifferential; - -#include <event.h> - -#include <cassert> -#include <cerrno> -#include <cstdio> -#include <cstdlib> -#include <cstring> -#include <fcntl.h> -#include <getopt.h> -#include <iostream> -#include <sys/types.h> -#include <unistd.h> - -extern memcached_binary_protocol_callback_st interface_v0_impl; -extern memcached_binary_protocol_callback_st interface_v1_impl; - -static memcached_socket_t server_sockets[1024]; -static int num_server_sockets= 0; - -struct connection -{ - void *userdata; - struct event event; -}; - -/* The default maximum number of connections... (change with -c) */ -static int maxconns= 1024; - -static struct connection *socket_userdata_map; -static struct event_base *event_base= NULL; - -struct options_st { - std::string pid_file; - std::string service; - std::string log_file; - bool is_verbose; - bool opt_daemon; - - options_st() : - service("9999"), - is_verbose(false), - opt_daemon(false) - { - } -}; - -static options_st global_options; - -/** - * Callback for driving a client connection - * @param fd the socket for the client socket - * @param which identifying the event that occurred (not used) - * @param arg the connection structure for the client - */ -static void drive_client(memcached_socket_t fd, short, void *arg) -{ - struct connection *client= (struct connection*)arg; - struct memcached_protocol_client_st* c= (struct memcached_protocol_client_st*)client->userdata; - assert(c != NULL); - - memcached_protocol_event_t events= memcached_protocol_client_work(c); - if (events & MEMCACHED_PROTOCOL_ERROR_EVENT) - { - if (global_options.is_verbose) - { - struct sockaddr_in sin; - socklen_t addrlen= sizeof(sin); - - if (getsockname(fd, (struct sockaddr *)&sin, &addrlen) != -1) - { - std::cout << __FILE__ << ":" << __LINE__ - << " close(MEMCACHED_PROTOCOL_ERROR_EVENT)" - << " " << inet_ntoa(sin.sin_addr) << ":" << sin.sin_port - << " fd:" << fd - << std::endl; - } - else - { - std::cout << __FILE__ << ":" << __LINE__ << "close() MEMCACHED_PROTOCOL_ERROR_EVENT" << std::endl; - } - } - - memcached_protocol_client_destroy(c); - closesocket(fd); - } - else - { - short flags = 0; - if (events & MEMCACHED_PROTOCOL_WRITE_EVENT) - { - flags= EV_WRITE; - } - - if (events & MEMCACHED_PROTOCOL_READ_EVENT) - { - flags|= EV_READ; - } - - event_set(&client->event, int(fd), flags, drive_client, client); - event_base_set(event_base, &client->event); - - if (event_add(&client->event, 0) == -1) - { - memcached_protocol_client_destroy(c); - closesocket(fd); - } - } -} - -/** - * Callback for accepting new connections - * @param fd the socket for the server socket - * @param which identifying the event that occurred (not used) - * @param arg the connection structure for the server - */ -static void accept_handler(memcached_socket_t fd, short, void *arg) -{ - struct connection *server= (struct connection *)arg; - /* accept new client */ - struct sockaddr_storage addr; - socklen_t addrlen= sizeof(addr); - memcached_socket_t sock= accept(fd, (struct sockaddr *)&addr, &addrlen); - - if (sock == INVALID_SOCKET) - { - perror("Failed to accept client"); - } - -#ifndef WIN32 - if (sock >= maxconns) - { - closesocket(sock); - return ; - } -#endif - - struct memcached_protocol_client_st* c= memcached_protocol_create_client((memcached_protocol_st*)server->userdata, sock); - if (c == NULL) - { - closesocket(sock); - } - else - { - memcached_protocol_client_set_verbose(c, global_options.is_verbose); - struct connection *client = &socket_userdata_map[sock]; - client->userdata= c; - - event_set(&client->event, int(sock), EV_READ, drive_client, client); - event_base_set(event_base, &client->event); - if (event_add(&client->event, 0) == -1) - { - std::cerr << "Failed to add event for " << sock << std::endl; - memcached_protocol_client_destroy(c); - closesocket(sock); - } - } -} - -static bool server_socket(util::log_info_st& log_file, const std::string& service) -{ - struct addrinfo *ai; - struct addrinfo hints; - memset(&hints, 0, sizeof(struct addrinfo)); - - hints.ai_flags= AI_PASSIVE; - hints.ai_family= AF_UNSPEC; - hints.ai_socktype= SOCK_STREAM; - - int error= getaddrinfo("127.0.0.1", service.c_str(), &hints, &ai); - if (error != 0) - { - if (error != EAI_SYSTEM) - { - std::string buffer("getaddrinfo: "); - buffer+= gai_strerror(error); - log_file.write(util::VERBOSE_ERROR, buffer.c_str()); - } - else - { - std::string buffer("getaddrinfo: "); - buffer+= strerror(errno); - log_file.write(util::VERBOSE_ERROR, buffer.c_str()); - } - - return false; - } - - struct linger ling= {0, 0}; - - for (struct addrinfo *next= ai; next; next= next->ai_next) - { - memcached_socket_t sock= socket(ai->ai_family, ai->ai_socktype, ai->ai_protocol); - if (sock == INVALID_SOCKET) - { - std::string buffer("Failed to create socket: "); - buffer+= strerror(errno); - log_file.write(util::VERBOSE_ERROR, buffer.c_str()); - continue; - } - - int flags; -#ifdef WIN32 - u_long arg = 1; - if (ioctlsocket(sock, FIONBIO, &arg) == SOCKET_ERROR) - { - std::cerr << "Failed to set nonblocking io: " << strerror(errno) << std::endl; - closesocket(sock); - continue; - } -#else - flags= fcntl(sock, F_GETFL, 0); - if (flags == -1) - { - std::string buffer("Failed to get socket flags: "); - buffer+= strerror(errno); - log_file.write(util::VERBOSE_ERROR, buffer.c_str()); - closesocket(sock); - continue; - } - - if ((flags & O_NONBLOCK) != O_NONBLOCK) - { - if (fcntl(sock, F_SETFL, flags | O_NONBLOCK) == -1) - { - std::string buffer("Failed to set socket to nonblocking mode: "); - buffer+= strerror(errno); - log_file.write(util::VERBOSE_ERROR, buffer.c_str()); - closesocket(sock); - continue; - } - } -#endif - - flags= 1; - if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (void *)&flags, sizeof(flags)) != 0) - { - std::cerr << "Failed to set SO_REUSEADDR: " << strerror(errno) << std::endl; - } - - if (setsockopt(sock, SOL_SOCKET, SO_KEEPALIVE, (void *)&flags, sizeof(flags)) != 0) - { - std::cerr << "Failed to set SO_KEEPALIVE: " << strerror(errno) << std::endl; - } - - if (setsockopt(sock, SOL_SOCKET, SO_LINGER, (void *)&ling, sizeof(ling)) != 0) - { - std::cerr << "Failed to set SO_LINGER: " << strerror(errno) << std::endl; - } - - if (setsockopt(sock, IPPROTO_TCP, TCP_NODELAY, (void *)&flags, sizeof(flags)) != 0) - { - std::cerr << "Failed to set TCP_NODELAY: " << strerror(errno) << std::endl; - } - - if (bind(sock, next->ai_addr, next->ai_addrlen) == SOCKET_ERROR) - { - if (get_socket_errno() != EADDRINUSE) - { - std::cerr << "bind(): " << strerror(errno) << std::endl; - freeaddrinfo(ai); - } - closesocket(sock); - continue; - } - - if (listen(sock, 1024) == SOCKET_ERROR) - { - std::string buffer("listen(): "); - buffer+= strerror(errno); - log_file.write(util::VERBOSE_ERROR, buffer.c_str()); - closesocket(sock); - continue; - } - - if (global_options.is_verbose) - { - std::string buffer("Listening to: "); - buffer+= global_options.service; - log_file.write(util::VERBOSE_NOTICE, buffer.c_str()); - } - - server_sockets[num_server_sockets++]= sock; - } - - freeaddrinfo(ai); - - return (num_server_sockets > 0) ? true : false; -} - -/** - * Convert a command code to a textual string - * @param cmd the comcode to convert - * @return a textual string with the command or NULL for unknown commands - */ -static const char* comcode2str(uint8_t cmd) -{ - static const char * const text[] = { - "GET", "SET", "ADD", "REPLACE", "DELETE", - "INCREMENT", "DECREMENT", "QUIT", "FLUSH", - "GETQ", "NOOP", "VERSION", "GETK", "GETKQ", - "APPEND", "PREPEND", "STAT", "SETQ", "ADDQ", - "REPLACEQ", "DELETEQ", "INCREMENTQ", "DECREMENTQ", - "QUITQ", "FLUSHQ", "APPENDQ", "PREPENDQ" - }; - - if (cmd <= PROTOCOL_BINARY_CMD_PREPENDQ) - { - return text[cmd]; - } - - return NULL; -} - -/** - * Print out the command we are about to execute - */ -static void pre_execute(const void *cookie, - protocol_binary_request_header *header) -{ - if (global_options.is_verbose) - { - if (header) - { - const char *cmd= comcode2str(header->request.opcode); - if (cmd != NULL) - { - std::cout << "pre_execute from " << cookie << ": " << cmd << std::endl; - } - else - { - std::cout << "pre_execute from " << cookie << ": " << header->request.opcode << std::endl; - } - } - else - { - std::cout << "pre_execute from " << cookie << std::endl; - } - } -} - -/** - * Print out the command we just executed - */ -static void post_execute(const void *cookie, - protocol_binary_request_header *header) -{ - if (global_options.is_verbose) - { - if (header) - { - const char *cmd= comcode2str(header->request.opcode); - if (cmd != NULL) - { - std::cout << "post_execute from " << cookie << ": " << cmd << std::endl; - } - else - { - std::cout << "post_execute from " << cookie << ": " << header->request.opcode << std::endl; - } - } - else - { - std::cout << "post_execute from " << cookie << std::endl; - } - } -} - -/** - * Callback handler for all unknown commands. - * Send an unknown command back to the client - */ -static protocol_binary_response_status unknown(const void *cookie, - protocol_binary_request_header *header, - memcached_binary_protocol_raw_response_handler response_handler) -{ - protocol_binary_response_no_extras response; - memset(&response, 0, sizeof(protocol_binary_response_no_extras)); - - response.message.header.response.magic= PROTOCOL_BINARY_RES; - response.message.header.response.opcode= header->request.opcode; - response.message.header.response.status= htons(PROTOCOL_BINARY_RESPONSE_UNKNOWN_COMMAND); - response.message.header.response.opaque= header->request.opaque; - - return response_handler(cookie, header, (protocol_binary_response_header*)&response); -} - -/** - * Program entry point. Bind to the specified port(s) and serve clients - * - * @param argc number of items in the argument vector - * @param argv argument vector - * @return EXIT_SUCCESS on success, 1 otherwise - */ -int main(int argc, char **argv) -{ - memcached_binary_protocol_callback_st *interface= &interface_v0_impl; - - { - enum long_option_t { - OPT_HELP, - OPT_VERBOSE, - OPT_DAEMON, - OPT_PROTOCOL_VERSION, - OPT_VERSION, - OPT_PORT, - OPT_MAX_CONNECTIONS, - OPT_LOGFILE, - OPT_PIDFILE - }; - - static struct option long_options[]= - { - { "help", no_argument, NULL, OPT_HELP }, - { "port", required_argument, NULL, OPT_PORT }, - { "verbose", no_argument, NULL, OPT_VERBOSE }, - { "daemon", no_argument, NULL, OPT_DAEMON }, - { "protocol", no_argument, NULL, OPT_PROTOCOL_VERSION }, - { "version", no_argument, NULL, OPT_VERSION }, - { "max-connections", required_argument, NULL, OPT_MAX_CONNECTIONS }, - { "pid-file", required_argument, NULL, OPT_PIDFILE }, - { "log-file", required_argument, NULL, OPT_LOGFILE }, - {0, 0, 0, 0} - }; - - bool opt_help= false; - int option_index; - bool done= false; - while (done == false) - { - switch (getopt_long(argc, argv, "", long_options, &option_index)) - { - case -1: - done= true; - break; - - case OPT_PROTOCOL_VERSION: - interface= &interface_v1_impl; - break; - - case OPT_PIDFILE: - global_options.pid_file= optarg; - break; - - case OPT_LOGFILE: - global_options.log_file= optarg; - break; - - case OPT_VERBOSE: - global_options.is_verbose= true; - break; - - case OPT_VERSION: - break; - - case OPT_DAEMON: - global_options.opt_daemon= true; - break; - - case OPT_PORT: - global_options.service= optarg; - break; - - case OPT_MAX_CONNECTIONS: - maxconns= atoi(optarg); - break; - - case OPT_HELP: /* FALLTHROUGH */ - opt_help= true; - break; - - default: - { - std::cerr << "Unknown option: " << optarg << std::endl; - return EXIT_FAILURE; - } - } - } - - if (opt_help) - { - std::cout << "Usage: " << argv[0] << std::endl; - for (struct option *ptr_option= long_options; ptr_option->name; ptr_option++) - { - std::cout << "\t" << ptr_option->name << std::endl; - } - return EXIT_SUCCESS; - } - } - - if (global_options.opt_daemon) - { - util::daemonize(false, true); - } - - if (initialize_storage() == false) - { - /* Error message already printed */ - return EXIT_FAILURE; - } - - util::Pidfile _pid_file(global_options.pid_file); - - if (_pid_file.create() == false) - { - std::cerr << "Failed to create pid-file" << _pid_file.error_message() << std::endl; - return EXIT_FAILURE; - } - - util::log_info_st log_file(argv[0], global_options.log_file, false); - log_file.write(util::VERBOSE_NOTICE, "starting log"); - - /* - * We need to initialize the handlers manually due to a bug in the - * warnings generated by struct initialization in gcc (all the way up to 4.4) - */ - initialize_interface_v0_handler(log_file); - initialize_interface_v1_handler(log_file); - - - if (server_socket(log_file, global_options.service) == false) - { - return EXIT_FAILURE; - } - - if (num_server_sockets == 0) - { - log_file.write(util::VERBOSE_ERROR, "No server sockets are available."); - return EXIT_FAILURE; - } - - /* - * Create and initialize the handles to the protocol handlers. I want - * to be able to trace the traffic throught the pre/post handlers, and - * set up a common handler for unknown messages - */ - interface->pre_execute= pre_execute; - interface->post_execute= post_execute; - interface->unknown= unknown; - - struct memcached_protocol_st *protocol_handle; - if ((protocol_handle= memcached_protocol_create_instance()) == NULL) - { - log_file.write(util::VERBOSE_ERROR, "No server sockets are available."); - return EXIT_FAILURE; - } - - socket_userdata_map= (struct connection*)calloc((size_t)(maxconns), sizeof(struct connection)); - if (socket_userdata_map == NULL) - { - log_file.write(util::VERBOSE_ERROR, "Failed to allocate room for connections"); - return EXIT_FAILURE; - } - - memcached_binary_protocol_set_callbacks(protocol_handle, interface); - memcached_binary_protocol_set_pedantic(protocol_handle, true); - - event_base= event_init(); - if (event_base == NULL) - { - std::cerr << "Failed to create an instance of libevent" << std::endl; - return EXIT_FAILURE; - } - - for (int xx= 0; xx < num_server_sockets; ++xx) - { - struct connection *conn= &socket_userdata_map[server_sockets[xx]]; - conn->userdata= protocol_handle; - - event_set(&conn->event, int(server_sockets[xx]), EV_READ | EV_PERSIST, accept_handler, conn); - - event_base_set(event_base, &conn->event); - if (event_add(&conn->event, 0) == -1) - { - log_file.write(util::VERBOSE_ERROR, "Failed to add event"); - closesocket(server_sockets[xx]); - } - } - - if (global_options.opt_daemon) - { - if (util::daemon_is_ready(true) == false) - { - log_file.write(util::VERBOSE_ERROR, "Failed for util::daemon_is_ready()"); - return EXIT_FAILURE; - } - } - - - /* Serve all of the clients */ - switch (event_base_loop(event_base, 0)) - { - case -1: - log_file.write(util::VERBOSE_ERROR, "event_base_loop() failed"); - break; - - case 1: - log_file.write(util::VERBOSE_ERROR, "event_base_loop(), no events were registered"); - break; - - default: - break; - } - log_file.write(util::VERBOSE_NOTICE, "exiting"); - - /* NOTREACHED */ - return EXIT_SUCCESS; -} diff --git a/example/memcached_light.h b/example/memcached_light.h deleted file mode 100644 index 6abb8744..00000000 --- a/example/memcached_light.h +++ /dev/null @@ -1,44 +0,0 @@ -/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: - * - * Memcached Light interface definitions - * - * Copyright (C) 2012 Data Differential, http://datadifferential.com/ - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * - * * The names of its contributors may not be used to endorse or - * promote products derived from this software without specific prior - * written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -/* -*- Mode: C; tab-width: 2; c-basic-offset: 2; indent-tabs-mode: nil -*- */ -#pragma once - -#include "util/log.hpp" - -void initialize_interface_v0_handler(datadifferential::util::log_info_st&); -void initialize_interface_v1_handler(datadifferential::util::log_info_st&); diff --git a/example/storage.cc b/example/storage.cc deleted file mode 100644 index 2e63a3e3..00000000 --- a/example/storage.cc +++ /dev/null @@ -1,168 +0,0 @@ -/* -*- Mode: C; tab-width: 2; c-basic-offset: 2; indent-tabs-mode: nil -*- */ -#include "config.h" -#include <stdlib.h> -#include <inttypes.h> -#include <time.h> -#include <stdbool.h> -#include <string.h> -#include "storage.h" - -struct list_entry { - struct item item; - struct list_entry *next; - struct list_entry *prev; -}; - -static struct list_entry *root; -static uint64_t cas; - -bool initialize_storage(void) -{ - return true; -} - -void shutdown_storage(void) -{ - /* Do nothing */ -} - -void put_item(struct item* item) -{ - struct list_entry* entry= (struct list_entry*)item; - - update_cas(item); - - if (root == NULL) - { - entry->next= entry->prev= entry; - } - else - { - entry->prev= root->prev; - entry->next= root; - entry->prev->next= entry; - entry->next->prev= entry; - } - - root= entry; -} - -struct item* get_item(const void* key, size_t nkey) -{ - struct list_entry *walker= root; - - if (root == NULL) - { - return NULL; - } - - do - { - if (((struct item*)walker)->nkey == nkey && - memcmp(((struct item*)walker)->key, key, nkey) == 0) - { - return (struct item*)walker; - } - walker= walker->next; - } while (walker != root); - - return NULL; -} - -struct item* create_item(const void* key, size_t nkey, const void* data, - size_t size, uint32_t flags, time_t exp) -{ - struct item* ret= (struct item*)calloc(1, sizeof(struct list_entry)); - - if (ret != NULL) - { - ret->key= malloc(nkey); - if (size > 0) - { - ret->data= malloc(size); - } - - if (ret->key == NULL || (size > 0 && ret->data == NULL)) - { - free(ret->key); - free(ret->data); - free(ret); - return NULL; - } - - memcpy(ret->key, key, nkey); - if (data != NULL) - { - memcpy(ret->data, data, size); - } - - ret->nkey= nkey; - ret->size= size; - ret->flags= flags; - ret->exp= exp; - } - - return ret; -} - -bool delete_item(const void* key, size_t nkey) -{ - struct item* item= get_item(key, nkey); - bool ret= false; - - if (item) - { - /* remove from linked list */ - struct list_entry *entry= (struct list_entry*)item; - - if (entry->next == entry) - { - /* Only one object in the list */ - root= NULL; - } - else - { - /* ensure that we don't loose track of the root, and this will - * change the start position for the next search ;-) */ - root= entry->next; - entry->prev->next= entry->next; - entry->next->prev= entry->prev; - } - - free(item->key); - free(item->data); - free(item); - ret= true; - } - - return ret; -} - -void flush(uint32_t /* when */) -{ - /* remove the complete linked list */ - if (root == NULL) - { - return; - } - - root->prev->next= NULL; - while (root != NULL) - { - struct item* tmp= (struct item*)root; - root= root->next; - - free(tmp->key); - free(tmp->data); - free(tmp); - } -} - -void update_cas(struct item* item) -{ - item->cas= ++cas; -} - -void release_item(struct item* /* item */) -{ -} diff --git a/example/storage.h b/example/storage.h deleted file mode 100644 index bd1b8780..00000000 --- a/example/storage.h +++ /dev/null @@ -1,24 +0,0 @@ -/* -*- Mode: C; tab-width: 2; c-basic-offset: 2; indent-tabs-mode: nil -*- */ -#pragma once - -struct item { - uint64_t cas; - void* key; - size_t nkey; - void* data; - size_t size; - uint32_t flags; - time_t exp; -}; - -bool initialize_storage(void); -void shutdown_storage(void); - -void update_cas(struct item* item); -void put_item(struct item* item); -struct item* get_item(const void* key, size_t nkey); -struct item* create_item(const void* key, size_t nkey, const void *data, - size_t size, uint32_t flags, time_t exp); -bool delete_item(const void* key, size_t nkey); -void flush(uint32_t when); -void release_item(struct item* item); diff --git a/example/t/include.am b/example/t/include.am deleted file mode 100644 index 394e4c6c..00000000 --- a/example/t/include.am +++ /dev/null @@ -1,40 +0,0 @@ -# vim:ft=automake -# Copyright (C) 2012 Data Differential -# All rights reserved. -# -# Use and distribution licensed under the BSD license. See -# the COPYING file in the parent directory for full text. -# -# included from Top Level Makefile.am -# All paths should be given relative to the root - -MEMCACHED_LIGHT_TESTS_LDADDS= \ - libmemcached/libmemcached.la \ - libmemcached/libmemcachedutil.la \ - libtest/libtest.la - -example_t_memcached_light_CXXFLAGS= -example_t_memcached_light_DEPENDENCIES= -example_t_memcached_light_LDADD= -example_t_memcached_light_SOURCES= - -example_t_memcached_light_SOURCES+= example/t/memcached_light.cc -example_t_memcached_light_SOURCES+= tests/libmemcached-1.0/memcached_get.cc -example_t_memcached_light_SOURCES+= tests/libmemcached-1.0/print.cc -example_t_memcached_light_SOURCES+= tests/libmemcached-1.0/setup_and_teardowns.cc -example_t_memcached_light_CXXFLAGS+= $(AM_CXXFLAGS) -example_t_memcached_light_DEPENDENCIES+= $(MEMCACHED_LIGHT_TESTS_LDADDS) -example_t_memcached_light_DEPENDENCIES+= example/memcached_light -example_t_memcached_light_LDADD+= $(MEMCACHED_LIGHT_TESTS_LDADDS) -example_t_memcached_light_LDADD+= $(LIBUUID_LDFLAGS) -check_PROGRAMS+= example/t/memcached_light -noinst_PROGRAMS+= example/t/memcached_light - -test-memcached_light: example/t/memcached_light example/memcached_light - @example/t/memcached_light - -gdb-memcached_light: example/t/memcached_light example/memcached_light - @$(DEBUG_COMMAND) example/t/memcached_light - -valgrind-memcached_light: example/t/memcached_light example/memcached_light - $(VALGRIND_COMMAND) example/t/memcached_light diff --git a/example/t/memcached_light.cc b/example/t/memcached_light.cc deleted file mode 100644 index c5956b24..00000000 --- a/example/t/memcached_light.cc +++ /dev/null @@ -1,248 +0,0 @@ -/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: - * - * Test memcat - * - * Copyright (C) 2011 Data Differential, http://datadifferential.com/ - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * - * * The names of its contributors may not be used to endorse or - * promote products derived from this software without specific prior - * written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - - -/* - Test that we are cycling the servers we are creating during testing. -*/ - -#include <config.h> - -#include <libtest/test.hpp> -#include <libmemcached-1.0/memcached.h> - -#include "tests/libmemcached-1.0/memcached_get.h" - -using namespace libtest; - -#ifndef __INTEL_COMPILER -#pragma GCC diagnostic ignored "-Wstrict-aliasing" -#endif - -static std::string executable("example/memcached_light"); - -static test_return_t help_TEST(void *) -{ - const char *args[]= { "--help", 0 }; - - test_compare(EXIT_SUCCESS, exec_cmdline(executable, args, true)); - - return TEST_SUCCESS; -} - -static test_return_t verbose_TEST(void *) -{ - const char *args[]= { "--help", "--verbose", 0 }; - - test_compare(EXIT_SUCCESS, exec_cmdline(executable, args, true)); - - return TEST_SUCCESS; -} - -static test_return_t daemon_TEST(void *) -{ - const char *args[]= { "--help", "--daemon", 0 }; - - test_compare(EXIT_SUCCESS, exec_cmdline(executable, args, true)); - - return TEST_SUCCESS; -} - -static test_return_t protocol_TEST(void *) -{ - const char *args[]= { "--help", "--protocol", 0 }; - - test_compare(EXIT_SUCCESS, exec_cmdline(executable, args, true)); - - return TEST_SUCCESS; -} - -static test_return_t version_TEST(void *) -{ - const char *args[]= { "--help", "--version", 0 }; - - test_compare(EXIT_SUCCESS, exec_cmdline(executable, args, true)); - - return TEST_SUCCESS; -} - -static test_return_t port_TEST(void *) -{ - const char *args[]= { "--help", "--port=9090", 0 }; - - test_compare(EXIT_SUCCESS, exec_cmdline(executable, args, true)); - - return TEST_SUCCESS; -} - -static test_return_t pid_file_TEST(void *) -{ - const char *args[]= { "--help", "--pid-file=/tmp/foo.pid", 0 }; - - test_compare(EXIT_SUCCESS, exec_cmdline(executable, args, true)); - - return TEST_SUCCESS; -} - -static test_return_t log_file_TEST(void *) -{ - const char *args[]= { "--help", "--log-file=/tmp/foo.log", 0 }; - - test_compare(EXIT_SUCCESS, exec_cmdline(executable, args, true)); - - return TEST_SUCCESS; -} - -static test_return_t max_connections_file_TEST(void *) -{ - const char *args[]= { "--help", "--max-connections=/tmp/foo.max_connections", 0 }; - - test_compare(EXIT_SUCCESS, exec_cmdline(executable, args, true)); - - return TEST_SUCCESS; -} - -typedef test_return_t (*libmemcached_test_callback_fn)(memcached_st *); - -static test_return_t _runner_default(libmemcached_test_callback_fn func, void *object) -{ - if (func) - { - test_true(object); - test_return_t ret; - try { - ret= func((memcached_st*)object); - } - catch (std::exception& e) - { - libtest::Error << e.what(); - return TEST_FAILURE; - } - - return ret; - } - - return TEST_SUCCESS; -} - -class MemcachedLightRunner : public libtest::Runner { -public: - test_return_t run(test_callback_fn* func, void *object) - { - return _runner_default(libmemcached_test_callback_fn(func), object); - } -}; - -test_st cmdline_option_TESTS[] ={ - {"--help", true, help_TEST }, - {"--verbose", true, verbose_TEST }, - {"--daemon", true, daemon_TEST }, - {"--protocol", true, protocol_TEST }, - {"--version", true, version_TEST }, - {"--port", true, port_TEST }, - {"--pid-file", true, pid_file_TEST }, - {"--log-file", true, log_file_TEST }, - {"--max-connections", true, max_connections_file_TEST }, - {0, 0, 0} -}; - -/* Clean the server before beginning testing */ -test_st basic_TESTS[] ={ -#if 0 - {"memcached_get()", true, (test_callback_fn*)get_test }, - {"memcached_get() test 2", false, (test_callback_fn*)get_test2 }, - {"memcached_get() test 3", false, (test_callback_fn*)get_test3 }, - {"memcached_get() test 4", false, (test_callback_fn*)get_test4 }, - {"memcached_get() test 5", false, (test_callback_fn*)get_test5 }, -#endif - {0, 0, 0} -}; - -collection_st collection[] ={ - {"command line options", 0, 0, cmdline_option_TESTS }, - {"basic", 0, 0, basic_TESTS }, - {0, 0, 0, 0} -}; - -static void *world_create(server_startup_st& servers, test_return_t& error) -{ - if (access(executable.c_str(), X_OK) != 0) - { - error= TEST_SKIPPED; - return NULL; - } - - if (HAVE_MEMCACHED_LIGHT_BINARY == 0) - { - error= TEST_SKIPPED; - return NULL; - } - - if (server_startup(servers, "memcached-light", libtest::default_port(), 0, NULL) == 0) - { - error= TEST_FAILURE; - return NULL; - } - - - char buffer[1024]; - int length= snprintf(buffer, sizeof(buffer), "--server=localhost:%d", int(libtest::default_port())); - fatal_assert(length > 0); - - memcached_st *memc= memcached(buffer, length); - - fatal_assert(memc); - - return (void*)memc; -} - -static bool world_destroy(void *object) -{ - memcached_st *memc= (memcached_st*)object; - memcached_free(memc); - - return TEST_SUCCESS; -} - - -void get_world(libtest::Framework* world) -{ - world->create(world_create); - world->destroy(world_destroy); - world->collections(collection); - world->set_runner(new MemcachedLightRunner); -} - diff --git a/libmemcached-1.0/include.am b/libmemcached-1.0/include.am deleted file mode 100644 index 19e48289..00000000 --- a/libmemcached-1.0/include.am +++ /dev/null @@ -1,56 +0,0 @@ -# vim:ft=automake -# included from Top Level Makefile.am -# All paths should be given relative to the root - -EXTRA_DIST+= libmemcached-1.0/configure.h.in -BUILT_SOURCES+= libmemcached-1.0/configure.h - -include libmemcached-1.0/struct/include.am -include libmemcached-1.0/types/include.am - -# Tests for this version of the interface -include libmemcached-1.0/t/include.am - -nobase_include_HEADERS+= libmemcached-1.0/alloc.h -nobase_include_HEADERS+= libmemcached-1.0/allocators.h -nobase_include_HEADERS+= libmemcached-1.0/analyze.h -nobase_include_HEADERS+= libmemcached-1.0/auto.h -nobase_include_HEADERS+= libmemcached-1.0/basic_string.h -nobase_include_HEADERS+= libmemcached-1.0/behavior.h -nobase_include_HEADERS+= libmemcached-1.0/callback.h -nobase_include_HEADERS+= libmemcached-1.0/callbacks.h -nobase_include_HEADERS+= libmemcached-1.0/configure.h -nobase_include_HEADERS+= libmemcached-1.0/defaults.h -nobase_include_HEADERS+= libmemcached-1.0/delete.h -nobase_include_HEADERS+= libmemcached-1.0/deprecated_types.h -nobase_include_HEADERS+= libmemcached-1.0/dump.h -nobase_include_HEADERS+= libmemcached-1.0/encoding_key.h -nobase_include_HEADERS+= libmemcached-1.0/error.h -nobase_include_HEADERS+= libmemcached-1.0/exception.hpp -nobase_include_HEADERS+= libmemcached-1.0/exist.h -nobase_include_HEADERS+= libmemcached-1.0/fetch.h -nobase_include_HEADERS+= libmemcached-1.0/flush.h -nobase_include_HEADERS+= libmemcached-1.0/flush_buffers.h -nobase_include_HEADERS+= libmemcached-1.0/get.h -nobase_include_HEADERS+= libmemcached-1.0/hash.h -nobase_include_HEADERS+= libmemcached-1.0/limits.h -nobase_include_HEADERS+= libmemcached-1.0/memcached.h -nobase_include_HEADERS+= libmemcached-1.0/memcached.hpp -nobase_include_HEADERS+= libmemcached-1.0/options.h -nobase_include_HEADERS+= libmemcached-1.0/parse.h -nobase_include_HEADERS+= libmemcached-1.0/platform.h -nobase_include_HEADERS+= libmemcached-1.0/quit.h -nobase_include_HEADERS+= libmemcached-1.0/result.h -nobase_include_HEADERS+= libmemcached-1.0/return.h -nobase_include_HEADERS+= libmemcached-1.0/sasl.h -nobase_include_HEADERS+= libmemcached-1.0/server.h -nobase_include_HEADERS+= libmemcached-1.0/server_list.h -nobase_include_HEADERS+= libmemcached-1.0/stats.h -nobase_include_HEADERS+= libmemcached-1.0/storage.h -nobase_include_HEADERS+= libmemcached-1.0/strerror.h -nobase_include_HEADERS+= libmemcached-1.0/touch.h -nobase_include_HEADERS+= libmemcached-1.0/triggers.h -nobase_include_HEADERS+= libmemcached-1.0/types.h -nobase_include_HEADERS+= libmemcached-1.0/verbosity.h -nobase_include_HEADERS+= libmemcached-1.0/version.h -nobase_include_HEADERS+= libmemcached-1.0/visibility.h diff --git a/libmemcached-1.0/struct/include.am b/libmemcached-1.0/struct/include.am deleted file mode 100644 index fc2d9223..00000000 --- a/libmemcached-1.0/struct/include.am +++ /dev/null @@ -1,13 +0,0 @@ -# vim:ft=automake -# included from Top Level Makefile.am -# All paths should be given relative to the root - -nobase_include_HEADERS+= libmemcached-1.0/struct/allocator.h -nobase_include_HEADERS+= libmemcached-1.0/struct/analysis.h -nobase_include_HEADERS+= libmemcached-1.0/struct/callback.h -nobase_include_HEADERS+= libmemcached-1.0/struct/memcached.h -nobase_include_HEADERS+= libmemcached-1.0/struct/result.h -nobase_include_HEADERS+= libmemcached-1.0/struct/sasl.h -nobase_include_HEADERS+= libmemcached-1.0/struct/server.h -nobase_include_HEADERS+= libmemcached-1.0/struct/stat.h -nobase_include_HEADERS+= libmemcached-1.0/struct/string.h diff --git a/libmemcached-1.0/t/include.am b/libmemcached-1.0/t/include.am deleted file mode 100644 index 96705114..00000000 --- a/libmemcached-1.0/t/include.am +++ /dev/null @@ -1,32 +0,0 @@ -# vim:ft=automake -# Copyright (C) 2011 Data Differential -# All rights reserved. -# -# Use and distribution licensed under the BSD license. See -# the COPYING file in the parent directory for full text. -# -# included from Top Level Makefile.am -# All paths should be given relative to the root - -LIBMEMCACHED_1_0_TEST_PATH= libmemcached-1.0/t - -# Test linking with C application -libmemcached_1_0_t_c_test_SOURCES= libmemcached-1.0/t/c_test.c -libmemcached_1_0_t_c_test_LDADD= libmemcached/libmemcached.la -libmemcached_1_0_t_c_test_DEPENDENCIES= libmemcached/libmemcached.la -check_PROGRAMS+= libmemcached-1.0/t/c_test -noinst_PROGRAMS+= libmemcached-1.0/t/c_test - -# Test linking with C++ application -libmemcached_1_0_t_cc_test_SOURCES= libmemcached-1.0/t/cc_test.cc -libmemcached_1_0_t_cc_test_LDADD= libmemcached/libmemcached.la -libmemcached_1_0_t_cc_test_DEPENDENCIES= libmemcached/libmemcached.la -check_PROGRAMS+= libmemcached-1.0/t/cc_test -noinst_PROGRAMS+= libmemcached-1.0/t/cc_test - -# Test linking with C application/SASL include -libmemcached_1_0_t_c_sasl_test_SOURCES= libmemcached-1.0/t/c_sasl_test.c -libmemcached_1_0_t_c_sasl_test_LDADD= libmemcached/libmemcached.la -libmemcached_1_0_t_c_sasl_test_DEPENDENCIES= libmemcached/libmemcached.la -check_PROGRAMS+= libmemcached-1.0/t/c_sasl_test -noinst_PROGRAMS+= libmemcached-1.0/t/c_sasl_test diff --git a/libmemcached-1.0/types/include.am b/libmemcached-1.0/types/include.am deleted file mode 100644 index fa330469..00000000 --- a/libmemcached-1.0/types/include.am +++ /dev/null @@ -1,8 +0,0 @@ -# vim:ft=automake - -nobase_include_HEADERS+= libmemcached-1.0/types/behavior.h -nobase_include_HEADERS+= libmemcached-1.0/types/callback.h -nobase_include_HEADERS+= libmemcached-1.0/types/connection.h -nobase_include_HEADERS+= libmemcached-1.0/types/hash.h -nobase_include_HEADERS+= libmemcached-1.0/types/return.h -nobase_include_HEADERS+= libmemcached-1.0/types/server_distribution.h diff --git a/libmemcached-1.0/alloc.h b/libmemcached-1.2/alloc.h index bc65b951..bc65b951 100644 --- a/libmemcached-1.0/alloc.h +++ b/libmemcached-1.2/alloc.h diff --git a/libmemcached-1.0/allocators.h b/libmemcached-1.2/allocators.h index 86f05a06..86f05a06 100644 --- a/libmemcached-1.0/allocators.h +++ b/libmemcached-1.2/allocators.h diff --git a/libmemcached-1.0/analyze.h b/libmemcached-1.2/analyze.h index 0da38143..50a7f063 100644 --- a/libmemcached-1.0/analyze.h +++ b/libmemcached-1.2/analyze.h @@ -35,7 +35,7 @@ * */ -#include <libmemcached-1.0/struct/analysis.h> +#include <libmemcached-1.2/struct/analysis.h> #pragma once diff --git a/libmemcached-1.0/auto.h b/libmemcached-1.2/auto.h index f37d50fc..f37d50fc 100644 --- a/libmemcached-1.0/auto.h +++ b/libmemcached-1.2/auto.h diff --git a/libmemcached-1.0/basic_string.h b/libmemcached-1.2/basic_string.h index de8d3d51..de8d3d51 100644 --- a/libmemcached-1.0/basic_string.h +++ b/libmemcached-1.2/basic_string.h diff --git a/libmemcached-1.0/behavior.h b/libmemcached-1.2/behavior.h index c6633532..c6633532 100644 --- a/libmemcached-1.0/behavior.h +++ b/libmemcached-1.2/behavior.h diff --git a/libmemcached-1.0/callback.h b/libmemcached-1.2/callback.h index a62e9aa6..a62e9aa6 100644 --- a/libmemcached-1.0/callback.h +++ b/libmemcached-1.2/callback.h diff --git a/libmemcached-1.0/callbacks.h b/libmemcached-1.2/callbacks.h index e321ceb4..e321ceb4 100644 --- a/libmemcached-1.0/callbacks.h +++ b/libmemcached-1.2/callbacks.h diff --git a/libmemcached-1.0/configure.h.in b/libmemcached-1.2/configure.h.in index 3f0465a0..3f0465a0 100644 --- a/libmemcached-1.0/configure.h.in +++ b/libmemcached-1.2/configure.h.in diff --git a/libmemcached-1.0/defaults.h b/libmemcached-1.2/defaults.h index 38c29ba3..38c29ba3 100644 --- a/libmemcached-1.0/defaults.h +++ b/libmemcached-1.2/defaults.h diff --git a/libmemcached-1.0/delete.h b/libmemcached-1.2/delete.h index 617d5857..617d5857 100644 --- a/libmemcached-1.0/delete.h +++ b/libmemcached-1.2/delete.h diff --git a/libmemcached-1.0/deprecated_types.h b/libmemcached-1.2/deprecated_types.h index 716d3e44..716d3e44 100644 --- a/libmemcached-1.0/deprecated_types.h +++ b/libmemcached-1.2/deprecated_types.h diff --git a/libmemcached-1.0/dump.h b/libmemcached-1.2/dump.h index b6e639e8..b6e639e8 100644 --- a/libmemcached-1.0/dump.h +++ b/libmemcached-1.2/dump.h diff --git a/libmemcached-1.0/encoding_key.h b/libmemcached-1.2/encoding_key.h index 3adbcb62..3adbcb62 100644 --- a/libmemcached-1.0/encoding_key.h +++ b/libmemcached-1.2/encoding_key.h diff --git a/libmemcached-1.0/error.h b/libmemcached-1.2/error.h index 7fdc18b8..7fdc18b8 100644 --- a/libmemcached-1.0/error.h +++ b/libmemcached-1.2/error.h diff --git a/libmemcached-1.0/exception.hpp b/libmemcached-1.2/exception.hpp index 4759072a..4759072a 100644 --- a/libmemcached-1.0/exception.hpp +++ b/libmemcached-1.2/exception.hpp diff --git a/libmemcached-1.0/exist.h b/libmemcached-1.2/exist.h index ef60a81a..ef60a81a 100644 --- a/libmemcached-1.0/exist.h +++ b/libmemcached-1.2/exist.h diff --git a/libmemcached-1.0/fetch.h b/libmemcached-1.2/fetch.h index bff186ac..bff186ac 100644 --- a/libmemcached-1.0/fetch.h +++ b/libmemcached-1.2/fetch.h diff --git a/libmemcached-1.0/flush.h b/libmemcached-1.2/flush.h index 820a98e7..820a98e7 100644 --- a/libmemcached-1.0/flush.h +++ b/libmemcached-1.2/flush.h diff --git a/libmemcached-1.0/flush_buffers.h b/libmemcached-1.2/flush_buffers.h index 31b58687..31b58687 100644 --- a/libmemcached-1.0/flush_buffers.h +++ b/libmemcached-1.2/flush_buffers.h diff --git a/libmemcached-1.0/get.h b/libmemcached-1.2/get.h index 32e4c5f3..32e4c5f3 100644 --- a/libmemcached-1.0/get.h +++ b/libmemcached-1.2/get.h diff --git a/libmemcached-1.0/hash.h b/libmemcached-1.2/hash.h index 9fdb7d6f..9fdb7d6f 100644 --- a/libmemcached-1.0/hash.h +++ b/libmemcached-1.2/hash.h diff --git a/libmemcached-1.2/include.am b/libmemcached-1.2/include.am new file mode 100644 index 00000000..9e597d0a --- /dev/null +++ b/libmemcached-1.2/include.am @@ -0,0 +1,56 @@ +# vim:ft=automake +# included from Top Level Makefile.am +# All paths should be given relative to the root + +EXTRA_DIST+= libmemcached-1.2/configure.h.in +BUILT_SOURCES+= libmemcached-1.2/configure.h + +include libmemcached-1.2/struct/include.am +include libmemcached-1.2/types/include.am + +# Tests for this version of the interface +include libmemcached-1.2/t/include.am + +nobase_include_HEADERS+= libmemcached-1.2/alloc.h +nobase_include_HEADERS+= libmemcached-1.2/allocators.h +nobase_include_HEADERS+= libmemcached-1.2/analyze.h +nobase_include_HEADERS+= libmemcached-1.2/auto.h +nobase_include_HEADERS+= libmemcached-1.2/basic_string.h +nobase_include_HEADERS+= libmemcached-1.2/behavior.h +nobase_include_HEADERS+= libmemcached-1.2/callback.h +nobase_include_HEADERS+= libmemcached-1.2/callbacks.h +nobase_include_HEADERS+= libmemcached-1.2/configure.h +nobase_include_HEADERS+= libmemcached-1.2/defaults.h +nobase_include_HEADERS+= libmemcached-1.2/delete.h +nobase_include_HEADERS+= libmemcached-1.2/dump.h +nobase_include_HEADERS+= libmemcached-1.2/encoding_key.h +nobase_include_HEADERS+= libmemcached-1.2/error.h +nobase_include_HEADERS+= libmemcached-1.2/exception.hpp +nobase_include_HEADERS+= libmemcached-1.2/exist.h +nobase_include_HEADERS+= libmemcached-1.2/fetch.h +nobase_include_HEADERS+= libmemcached-1.2/flush.h +nobase_include_HEADERS+= libmemcached-1.2/flush_buffers.h +nobase_include_HEADERS+= libmemcached-1.2/get.h +nobase_include_HEADERS+= libmemcached-1.2/hash.h +nobase_include_HEADERS+= libmemcached-1.2/limits.h +nobase_include_HEADERS+= libmemcached-1.2/memcached.h +nobase_include_HEADERS+= libmemcached-1.2/memcached.hpp +nobase_include_HEADERS+= libmemcached-1.2/memcached/vbucket.h +nobase_include_HEADERS+= libmemcached-1.2/options.h +nobase_include_HEADERS+= libmemcached-1.2/parse.h +nobase_include_HEADERS+= libmemcached-1.2/platform.h +nobase_include_HEADERS+= libmemcached-1.2/quit.h +nobase_include_HEADERS+= libmemcached-1.2/result.h +nobase_include_HEADERS+= libmemcached-1.2/return.h +nobase_include_HEADERS+= libmemcached-1.2/sasl.h +nobase_include_HEADERS+= libmemcached-1.2/server.h +nobase_include_HEADERS+= libmemcached-1.2/server_list.h +nobase_include_HEADERS+= libmemcached-1.2/stats.h +nobase_include_HEADERS+= libmemcached-1.2/storage.h +nobase_include_HEADERS+= libmemcached-1.2/strerror.h +nobase_include_HEADERS+= libmemcached-1.2/touch.h +nobase_include_HEADERS+= libmemcached-1.2/triggers.h +nobase_include_HEADERS+= libmemcached-1.2/types.h +nobase_include_HEADERS+= libmemcached-1.2/verbosity.h +nobase_include_HEADERS+= libmemcached-1.2/version.h +nobase_include_HEADERS+= libmemcached-1.2/visibility.h diff --git a/libmemcached-1.0/limits.h b/libmemcached-1.2/limits.h index 076df407..076df407 100644 --- a/libmemcached-1.0/limits.h +++ b/libmemcached-1.2/limits.h diff --git a/libmemcached-1.0/memcached.h b/libmemcached-1.2/memcached.h index 23462a76..7d932471 100644 --- a/libmemcached-1.0/memcached.h +++ b/libmemcached-1.2/memcached.h @@ -55,71 +55,69 @@ #include <sys/types.h> -#include <libmemcached-1.0/visibility.h> -#include <libmemcached-1.0/configure.h> -#include <libmemcached-1.0/platform.h> +#include <libmemcached-1.2/visibility.h> +#include <libmemcached-1.2/configure.h> +#include <libmemcached-1.2/platform.h> -#include <libmemcached-1.0/limits.h> -#include <libmemcached-1.0/defaults.h> +#include <libmemcached-1.2/limits.h> +#include <libmemcached-1.2/defaults.h> -#include <libmemcached-1.0/types/behavior.h> -#include <libmemcached-1.0/types/callback.h> -#include <libmemcached-1.0/types/connection.h> -#include <libmemcached-1.0/types/hash.h> -#include <libmemcached-1.0/types/return.h> -#include <libmemcached-1.0/types/server_distribution.h> +#include <libmemcached-1.2/types/behavior.h> +#include <libmemcached-1.2/types/callback.h> +#include <libmemcached-1.2/types/connection.h> +#include <libmemcached-1.2/types/hash.h> +#include <libmemcached-1.2/types/return.h> +#include <libmemcached-1.2/types/server_distribution.h> -#include <libmemcached-1.0/return.h> +#include <libmemcached-1.2/return.h> -#include <libmemcached-1.0/types.h> -#include <libmemcached-1.0/callbacks.h> -#include <libmemcached-1.0/alloc.h> -#include <libmemcached-1.0/triggers.h> +#include <libmemcached-1.2/types.h> +#include <libmemcached-1.2/callbacks.h> +#include <libmemcached-1.2/alloc.h> +#include <libmemcached-1.2/triggers.h> #include <libhashkit-1.0/hashkit.h> -#include <libmemcached-1.0/struct/callback.h> -#include <libmemcached-1.0/struct/string.h> -#include <libmemcached-1.0/struct/result.h> -#include <libmemcached-1.0/struct/allocator.h> -#include <libmemcached-1.0/struct/sasl.h> -#include <libmemcached-1.0/struct/memcached.h> -#include <libmemcached-1.0/struct/server.h> -#include <libmemcached-1.0/struct/stat.h> +#include <libmemcached-1.2/struct/callback.h> +#include <libmemcached-1.2/struct/string.h> +#include <libmemcached-1.2/struct/result.h> +#include <libmemcached-1.2/struct/allocator.h> +#include <libmemcached-1.2/struct/sasl.h> +#include <libmemcached-1.2/struct/memcached.h> +#include <libmemcached-1.2/struct/server.h> +#include <libmemcached-1.2/struct/stat.h> -#include <libmemcached-1.0/basic_string.h> -#include <libmemcached-1.0/error.h> -#include <libmemcached-1.0/stats.h> +#include <libmemcached-1.2/basic_string.h> +#include <libmemcached-1.2/error.h> +#include <libmemcached-1.2/stats.h> // Everything above this line must be in the order specified. -#include <libmemcached-1.0/allocators.h> -#include <libmemcached-1.0/analyze.h> -#include <libmemcached-1.0/auto.h> -#include <libmemcached-1.0/behavior.h> -#include <libmemcached-1.0/callback.h> -#include <libmemcached-1.0/delete.h> -#include <libmemcached-1.0/dump.h> -#include <libmemcached-1.0/encoding_key.h> -#include <libmemcached-1.0/exist.h> -#include <libmemcached-1.0/fetch.h> -#include <libmemcached-1.0/flush.h> -#include <libmemcached-1.0/flush_buffers.h> -#include <libmemcached-1.0/get.h> -#include <libmemcached-1.0/hash.h> -#include <libmemcached-1.0/options.h> -#include <libmemcached-1.0/parse.h> -#include <libmemcached-1.0/quit.h> -#include <libmemcached-1.0/result.h> -#include <libmemcached-1.0/server.h> -#include <libmemcached-1.0/server_list.h> -#include <libmemcached-1.0/storage.h> -#include <libmemcached-1.0/strerror.h> -#include <libmemcached-1.0/touch.h> -#include <libmemcached-1.0/verbosity.h> -#include <libmemcached-1.0/version.h> -#include <libmemcached-1.0/sasl.h> - -#include <libmemcached-1.0/deprecated_types.h> +#include <libmemcached-1.2/allocators.h> +#include <libmemcached-1.2/analyze.h> +#include <libmemcached-1.2/auto.h> +#include <libmemcached-1.2/behavior.h> +#include <libmemcached-1.2/callback.h> +#include <libmemcached-1.2/delete.h> +#include <libmemcached-1.2/dump.h> +#include <libmemcached-1.2/encoding_key.h> +#include <libmemcached-1.2/exist.h> +#include <libmemcached-1.2/fetch.h> +#include <libmemcached-1.2/flush.h> +#include <libmemcached-1.2/flush_buffers.h> +#include <libmemcached-1.2/get.h> +#include <libmemcached-1.2/hash.h> +#include <libmemcached-1.2/options.h> +#include <libmemcached-1.2/parse.h> +#include <libmemcached-1.2/quit.h> +#include <libmemcached-1.2/result.h> +#include <libmemcached-1.2/server.h> +#include <libmemcached-1.2/server_list.h> +#include <libmemcached-1.2/storage.h> +#include <libmemcached-1.2/strerror.h> +#include <libmemcached-1.2/touch.h> +#include <libmemcached-1.2/verbosity.h> +#include <libmemcached-1.2/version.h> +#include <libmemcached-1.2/sasl.h> #ifdef __cplusplus extern "C" { diff --git a/libmemcached-1.0/memcached.hpp b/libmemcached-1.2/memcached.hpp index 4f12e2ec..0bcb200e 100644 --- a/libmemcached-1.0/memcached.hpp +++ b/libmemcached-1.2/memcached.hpp @@ -50,7 +50,7 @@ #pragma once -#include <libmemcached-1.0/memcached.h> +#include <libmemcached-1.2/memcached.h> #if 0 #include <libmemcached/exception.hpp> #endif diff --git a/libmemcachedprotocol-0.0/vbucket.h b/libmemcached-1.2/memcached/vbucket.h index e2cc563e..e2cc563e 100644 --- a/libmemcachedprotocol-0.0/vbucket.h +++ b/libmemcached-1.2/memcached/vbucket.h diff --git a/libmemcached-1.0/options.h b/libmemcached-1.2/options.h index f5a6e06d..f5a6e06d 100644 --- a/libmemcached-1.0/options.h +++ b/libmemcached-1.2/options.h diff --git a/libmemcached-1.0/parse.h b/libmemcached-1.2/parse.h index a91f769d..a91f769d 100644 --- a/libmemcached-1.0/parse.h +++ b/libmemcached-1.2/parse.h diff --git a/libmemcached-1.0/platform.h b/libmemcached-1.2/platform.h index 763febaa..763febaa 100644 --- a/libmemcached-1.0/platform.h +++ b/libmemcached-1.2/platform.h diff --git a/libmemcached-1.0/quit.h b/libmemcached-1.2/quit.h index 90ff3ff0..90ff3ff0 100644 --- a/libmemcached-1.0/quit.h +++ b/libmemcached-1.2/quit.h diff --git a/libmemcached-1.0/result.h b/libmemcached-1.2/result.h index 615957f3..a1943507 100644 --- a/libmemcached-1.0/result.h +++ b/libmemcached-1.2/result.h @@ -35,7 +35,7 @@ * */ -#include <libmemcached-1.0/struct/result.h> +#include <libmemcached-1.2/struct/result.h> #pragma once diff --git a/libmemcached-1.0/return.h b/libmemcached-1.2/return.h index 65dc63af..65dc63af 100644 --- a/libmemcached-1.0/return.h +++ b/libmemcached-1.2/return.h diff --git a/libmemcached-1.0/sasl.h b/libmemcached-1.2/sasl.h index c3084217..c85c9f64 100644 --- a/libmemcached-1.0/sasl.h +++ b/libmemcached-1.2/sasl.h @@ -67,4 +67,4 @@ sasl_callback_t *memcached_get_sasl_callbacks(memcached_st *ptr); } #endif -#include <libmemcached-1.0/struct/sasl.h> +#include <libmemcached-1.2/struct/sasl.h> diff --git a/libmemcached-1.0/server.h b/libmemcached-1.2/server.h index dc650d2a..aad0c3ee 100644 --- a/libmemcached-1.0/server.h +++ b/libmemcached-1.2/server.h @@ -38,7 +38,7 @@ #pragma once -#include <libmemcached-1.0/struct/server.h> +#include <libmemcached-1.2/struct/server.h> #ifdef __cplusplus extern "C" { diff --git a/libmemcached-1.0/server_list.h b/libmemcached-1.2/server_list.h index 04bebab4..04bebab4 100644 --- a/libmemcached-1.0/server_list.h +++ b/libmemcached-1.2/server_list.h diff --git a/libmemcached-1.0/stats.h b/libmemcached-1.2/stats.h index 708064f1..37d34814 100644 --- a/libmemcached-1.0/stats.h +++ b/libmemcached-1.2/stats.h @@ -35,7 +35,7 @@ * */ -#include <libmemcached-1.0/struct/stat.h> +#include <libmemcached-1.2/struct/stat.h> #pragma once diff --git a/libmemcached-1.0/storage.h b/libmemcached-1.2/storage.h index e634235a..e634235a 100644 --- a/libmemcached-1.0/storage.h +++ b/libmemcached-1.2/storage.h diff --git a/libmemcached-1.0/strerror.h b/libmemcached-1.2/strerror.h index 16bf424a..16bf424a 100644 --- a/libmemcached-1.0/strerror.h +++ b/libmemcached-1.2/strerror.h diff --git a/libmemcached-1.0/struct/allocator.h b/libmemcached-1.2/struct/allocator.h index 3ff6ade8..3ff6ade8 100644 --- a/libmemcached-1.0/struct/allocator.h +++ b/libmemcached-1.2/struct/allocator.h diff --git a/libmemcached-1.0/struct/analysis.h b/libmemcached-1.2/struct/analysis.h index 09cccedc..09cccedc 100644 --- a/libmemcached-1.0/struct/analysis.h +++ b/libmemcached-1.2/struct/analysis.h diff --git a/libmemcached-1.0/struct/callback.h b/libmemcached-1.2/struct/callback.h index 21b96765..21b96765 100644 --- a/libmemcached-1.0/struct/callback.h +++ b/libmemcached-1.2/struct/callback.h diff --git a/libmemcached-1.2/struct/include.am b/libmemcached-1.2/struct/include.am new file mode 100644 index 00000000..4a468b6f --- /dev/null +++ b/libmemcached-1.2/struct/include.am @@ -0,0 +1,13 @@ +# vim:ft=automake +# included from Top Level Makefile.am +# All paths should be given relative to the root + +nobase_include_HEADERS+= libmemcached-1.2/struct/allocator.h +nobase_include_HEADERS+= libmemcached-1.2/struct/analysis.h +nobase_include_HEADERS+= libmemcached-1.2/struct/callback.h +nobase_include_HEADERS+= libmemcached-1.2/struct/memcached.h +nobase_include_HEADERS+= libmemcached-1.2/struct/result.h +nobase_include_HEADERS+= libmemcached-1.2/struct/sasl.h +nobase_include_HEADERS+= libmemcached-1.2/struct/server.h +nobase_include_HEADERS+= libmemcached-1.2/struct/stat.h +nobase_include_HEADERS+= libmemcached-1.2/struct/string.h diff --git a/libmemcached-1.0/struct/memcached.h b/libmemcached-1.2/struct/memcached.h index 624887b7..624887b7 100644 --- a/libmemcached-1.0/struct/memcached.h +++ b/libmemcached-1.2/struct/memcached.h diff --git a/libmemcached-1.0/struct/result.h b/libmemcached-1.2/struct/result.h index c3bfddb5..c3bfddb5 100644 --- a/libmemcached-1.0/struct/result.h +++ b/libmemcached-1.2/struct/result.h diff --git a/libmemcached-1.0/struct/sasl.h b/libmemcached-1.2/struct/sasl.h index da9eed38..da9eed38 100644 --- a/libmemcached-1.0/struct/sasl.h +++ b/libmemcached-1.2/struct/sasl.h diff --git a/libmemcached-1.0/struct/server.h b/libmemcached-1.2/struct/server.h index a8a30565..a8a30565 100644 --- a/libmemcached-1.0/struct/server.h +++ b/libmemcached-1.2/struct/server.h diff --git a/libmemcached-1.0/struct/stat.h b/libmemcached-1.2/struct/stat.h index acd4e21f..acd4e21f 100644 --- a/libmemcached-1.0/struct/stat.h +++ b/libmemcached-1.2/struct/stat.h diff --git a/libmemcached-1.0/struct/string.h b/libmemcached-1.2/struct/string.h index 9edb637a..9edb637a 100644 --- a/libmemcached-1.0/struct/string.h +++ b/libmemcached-1.2/struct/string.h diff --git a/libmemcached-1.0/t/c_sasl_test.c b/libmemcached-1.2/t/c_sasl_test.c index 93f729d1..413c3cd3 100644 --- a/libmemcached-1.0/t/c_sasl_test.c +++ b/libmemcached-1.2/t/c_sasl_test.c @@ -44,7 +44,7 @@ #include <sasl/sasl.h> #endif -#include <libmemcached-1.0/memcached.h> +#include <libmemcached-1.2/memcached.h> int main(void) { diff --git a/libmemcached-1.0/t/c_test.c b/libmemcached-1.2/t/c_test.c index 40935fac..ac40cac0 100644 --- a/libmemcached-1.0/t/c_test.c +++ b/libmemcached-1.2/t/c_test.c @@ -40,7 +40,7 @@ #include <stdlib.h> -#include <libmemcached-1.0/memcached.h> +#include <libmemcached-1.2/memcached.h> int main(void) { diff --git a/libmemcached-1.0/t/cc_test.cc b/libmemcached-1.2/t/cc_test.cc index 71ee8c30..87210d27 100644 --- a/libmemcached-1.0/t/cc_test.cc +++ b/libmemcached-1.2/t/cc_test.cc @@ -40,7 +40,7 @@ #include <cstdlib> -#include <libmemcached-1.0/memcached.h> +#include <libmemcached-1.2/memcached.h> int main(void) { diff --git a/libmemcached-1.2/t/include.am b/libmemcached-1.2/t/include.am new file mode 100644 index 00000000..544d9a46 --- /dev/null +++ b/libmemcached-1.2/t/include.am @@ -0,0 +1,30 @@ +# vim:ft=automake +# Copyright (C) 2011 Data Differential +# All rights reserved. +# +# Use and distribution licensed under the BSD license. See +# the COPYING file in the parent directory for full text. +# +# included from Top Level Makefile.am +# All paths should be given relative to the root + +# Test linking with C application +libmemcached_1_2_t_c_test_SOURCES= libmemcached-1.2/t/c_test.c +libmemcached_1_2_t_c_test_LDADD= libmemcached/libmemcached.la +libmemcached_1_2_t_c_test_DEPENDENCIES= libmemcached/libmemcached.la +check_PROGRAMS+= libmemcached-1.2/t/c_test +noinst_PROGRAMS+= libmemcached-1.2/t/c_test + +# Test linking with C++ application +libmemcached_1_2_t_cc_test_SOURCES= libmemcached-1.2/t/cc_test.cc +libmemcached_1_2_t_cc_test_LDADD= libmemcached/libmemcached.la +libmemcached_1_2_t_cc_test_DEPENDENCIES= libmemcached/libmemcached.la +check_PROGRAMS+= libmemcached-1.2/t/cc_test +noinst_PROGRAMS+= libmemcached-1.2/t/cc_test + +# Test linking with C application/SASL include +libmemcached_1_2_t_c_sasl_test_SOURCES= libmemcached-1.2/t/c_sasl_test.c +libmemcached_1_2_t_c_sasl_test_LDADD= libmemcached/libmemcached.la +libmemcached_1_2_t_c_sasl_test_DEPENDENCIES= libmemcached/libmemcached.la +check_PROGRAMS+= libmemcached-1.2/t/c_sasl_test +noinst_PROGRAMS+= libmemcached-1.2/t/c_sasl_test diff --git a/libmemcached-1.0/touch.h b/libmemcached-1.2/touch.h index e143c037..e143c037 100644 --- a/libmemcached-1.0/touch.h +++ b/libmemcached-1.2/touch.h diff --git a/libmemcached-1.0/triggers.h b/libmemcached-1.2/triggers.h index b331429e..b331429e 100644 --- a/libmemcached-1.0/triggers.h +++ b/libmemcached-1.2/triggers.h diff --git a/libmemcached-1.0/types.h b/libmemcached-1.2/types.h index 53992d3a..53992d3a 100644 --- a/libmemcached-1.0/types.h +++ b/libmemcached-1.2/types.h diff --git a/libmemcached-1.0/types/behavior.h b/libmemcached-1.2/types/behavior.h index d0af189a..d0af189a 100644 --- a/libmemcached-1.0/types/behavior.h +++ b/libmemcached-1.2/types/behavior.h diff --git a/libmemcached-1.0/types/callback.h b/libmemcached-1.2/types/callback.h index d5481f50..d5481f50 100644 --- a/libmemcached-1.0/types/callback.h +++ b/libmemcached-1.2/types/callback.h diff --git a/libmemcached-1.0/types/connection.h b/libmemcached-1.2/types/connection.h index d2a072b7..d2a072b7 100644 --- a/libmemcached-1.0/types/connection.h +++ b/libmemcached-1.2/types/connection.h diff --git a/libmemcached-1.0/types/hash.h b/libmemcached-1.2/types/hash.h index 7651eb1a..7651eb1a 100644 --- a/libmemcached-1.0/types/hash.h +++ b/libmemcached-1.2/types/hash.h diff --git a/libmemcached-1.2/types/include.am b/libmemcached-1.2/types/include.am new file mode 100644 index 00000000..a968c05f --- /dev/null +++ b/libmemcached-1.2/types/include.am @@ -0,0 +1,8 @@ +# vim:ft=automake + +nobase_include_HEADERS+= libmemcached-1.2/types/behavior.h +nobase_include_HEADERS+= libmemcached-1.2/types/callback.h +nobase_include_HEADERS+= libmemcached-1.2/types/connection.h +nobase_include_HEADERS+= libmemcached-1.2/types/hash.h +nobase_include_HEADERS+= libmemcached-1.2/types/return.h +nobase_include_HEADERS+= libmemcached-1.2/types/server_distribution.h diff --git a/libmemcached-1.0/types/return.h b/libmemcached-1.2/types/return.h index f4ec9b08..f4ec9b08 100644 --- a/libmemcached-1.0/types/return.h +++ b/libmemcached-1.2/types/return.h diff --git a/libmemcached-1.0/types/server_distribution.h b/libmemcached-1.2/types/server_distribution.h index 95e129f6..95e129f6 100644 --- a/libmemcached-1.0/types/server_distribution.h +++ b/libmemcached-1.2/types/server_distribution.h diff --git a/libmemcached-1.0/verbosity.h b/libmemcached-1.2/verbosity.h index 29946486..29946486 100644 --- a/libmemcached-1.0/verbosity.h +++ b/libmemcached-1.2/verbosity.h diff --git a/libmemcached-1.0/version.h b/libmemcached-1.2/version.h index c443accb..c443accb 100644 --- a/libmemcached-1.0/version.h +++ b/libmemcached-1.2/version.h diff --git a/libmemcached-1.0/visibility.h b/libmemcached-1.2/visibility.h index d4e4eea0..d4e4eea0 100644 --- a/libmemcached-1.0/visibility.h +++ b/libmemcached-1.2/visibility.h diff --git a/libmemcached/common.h b/libmemcached/common.h index 5c86eb16..935bd12c 100644 --- a/libmemcached/common.h +++ b/libmemcached/common.h @@ -89,7 +89,7 @@ # include <dlfcn.h> #endif -#include <libmemcached-1.0/memcached.h> +#include <libmemcached-1.2/memcached.h> #include <libmemcached/watchpoint.h> #include <libmemcached/is.h> diff --git a/libmemcached/include.am b/libmemcached/include.am index 13304e62..9534799a 100644 --- a/libmemcached/include.am +++ b/libmemcached/include.am @@ -9,10 +9,6 @@ include libmemcached/csl/include.am EXTRA_DIST+= libmemcached/libmemcached_probes.d EXTRA_DIST+= libmemcached/memcached/README.txt -nobase_include_HEADERS+= libmemcached/memcached.h -nobase_include_HEADERS+= libmemcached/memcached.hpp -nobase_include_HEADERS+= libmemcached/util.h - noinst_HEADERS+= libmemcached/array.h noinst_HEADERS+= libmemcached/assert.hpp noinst_HEADERS+= libmemcached/backtrace.hpp diff --git a/libmemcached/memcached.h b/libmemcached/memcached.h deleted file mode 100644 index a45077ee..00000000 --- a/libmemcached/memcached.h +++ /dev/null @@ -1,39 +0,0 @@ -/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: - * - * Libmemcached library - * - * Copyright (C) 2011 Data Differential, http://datadifferential.com/ - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * - * * The names of its contributors may not be used to endorse or - * promote products derived from this software without specific prior - * written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#pragma once - -#include <libmemcached-1.0/memcached.h> diff --git a/libmemcached/memcached.hpp b/libmemcached/memcached.hpp deleted file mode 100644 index d38e6d24..00000000 --- a/libmemcached/memcached.hpp +++ /dev/null @@ -1,40 +0,0 @@ -/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: - * - * Libmemcached library - * - * Copyright (C) 2011 Data Differential, http://datadifferential.com/ - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * - * * The names of its contributors may not be used to endorse or - * promote products derived from this software without specific prior - * written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#pragma once - -#include <libmemcached-1.0/memcached.hpp> - diff --git a/libmemcached/memcached/protocol_binary.h b/libmemcached/memcached/protocol_binary.h index 51e2c422..ff9d6373 100644 --- a/libmemcached/memcached/protocol_binary.h +++ b/libmemcached/memcached/protocol_binary.h @@ -36,7 +36,7 @@ #ifndef PROTOCOL_BINARY_H #define PROTOCOL_BINARY_H -#include <libmemcachedprotocol-0.0/vbucket.h> +#include <libmemcached-1.2/memcached/vbucket.h> /** * \addtogroup Protocol diff --git a/libmemcached/memory.h b/libmemcached/memory.h index 06cc9985..804bde30 100644 --- a/libmemcached/memory.h +++ b/libmemcached/memory.h @@ -38,7 +38,7 @@ #include <config.h> -#include <libmemcached-1.0/struct/memcached.h> +#include <libmemcached/common.h> #ifdef __cplusplus #include <cstddef> diff --git a/libmemcached/util.h b/libmemcached/util.h deleted file mode 100644 index 03ed6da5..00000000 --- a/libmemcached/util.h +++ /dev/null @@ -1,40 +0,0 @@ -/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: - * - * Libmemcached library - * - * Copyright (C) 2011 Data Differential, http://datadifferential.com/ - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * - * * The names of its contributors may not be used to endorse or - * promote products derived from this software without specific prior - * written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#pragma once - -#include <libmemcachedutil-1.0/util.h> - diff --git a/libmemcachedprotocol-0.0/binary.h b/libmemcachedprotocol-0.0/binary.h deleted file mode 100644 index 51e2c422..00000000 --- a/libmemcachedprotocol-0.0/binary.h +++ /dev/null @@ -1,728 +0,0 @@ -/* -*- Mode: C; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */ -/* - * Copyright (c) <2008>, Sun Microsystems, Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * * Neither the name of the nor the - * names of its contributors may be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY SUN MICROSYSTEMS, INC. ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL SUN MICROSYSTEMS, INC. BE LIABLE FOR ANY - * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -/* - * Summary: Constants used by to implement the binary protocol. - * - * Copy: See Copyright for the status of this software. - * - * Author: Trond Norbye <trond.norbye@sun.com> - */ - -#ifndef PROTOCOL_BINARY_H -#define PROTOCOL_BINARY_H - -#include <libmemcachedprotocol-0.0/vbucket.h> - -/** - * \addtogroup Protocol - * @{ - */ - -/** - * This file contains definitions of the constants and packet formats - * defined in the binary specification. Please note that you _MUST_ remember - * to convert each multibyte field to / from network byte order to / from - * host order. - */ -#ifdef __cplusplus -extern "C" -{ -#endif - - /** - * Definition of the legal "magic" values used in a packet. - * See section 3.1 Magic byte - */ - typedef enum { - PROTOCOL_BINARY_REQ = 0x80, - PROTOCOL_BINARY_RES = 0x81 - } protocol_binary_magic; - - /** - * Definition of the valid response status numbers. - * See section 3.2 Response Status - */ - typedef enum { - PROTOCOL_BINARY_RESPONSE_SUCCESS = 0x00, - PROTOCOL_BINARY_RESPONSE_KEY_ENOENT = 0x01, - PROTOCOL_BINARY_RESPONSE_KEY_EEXISTS = 0x02, - PROTOCOL_BINARY_RESPONSE_E2BIG = 0x03, - PROTOCOL_BINARY_RESPONSE_EINVAL = 0x04, - PROTOCOL_BINARY_RESPONSE_NOT_STORED = 0x05, - PROTOCOL_BINARY_RESPONSE_DELTA_BADVAL = 0x06, - PROTOCOL_BINARY_RESPONSE_NOT_MY_VBUCKET = 0x07, - PROTOCOL_BINARY_RESPONSE_AUTH_ERROR = 0x20, - PROTOCOL_BINARY_RESPONSE_AUTH_CONTINUE = 0x21, - PROTOCOL_BINARY_RESPONSE_UNKNOWN_COMMAND = 0x81, - PROTOCOL_BINARY_RESPONSE_ENOMEM = 0x82, - PROTOCOL_BINARY_RESPONSE_NOT_SUPPORTED = 0x83, - PROTOCOL_BINARY_RESPONSE_EINTERNAL = 0x84, - PROTOCOL_BINARY_RESPONSE_EBUSY = 0x85, - PROTOCOL_BINARY_RESPONSE_ETMPFAIL = 0x86 - } protocol_binary_response_status; - - /** - * Defintion of the different command opcodes. - * See section 3.3 Command Opcodes - */ - typedef enum { - PROTOCOL_BINARY_CMD_GET = 0x00, - PROTOCOL_BINARY_CMD_SET = 0x01, - PROTOCOL_BINARY_CMD_ADD = 0x02, - PROTOCOL_BINARY_CMD_REPLACE = 0x03, - PROTOCOL_BINARY_CMD_DELETE = 0x04, - PROTOCOL_BINARY_CMD_INCREMENT = 0x05, - PROTOCOL_BINARY_CMD_DECREMENT = 0x06, - PROTOCOL_BINARY_CMD_QUIT = 0x07, - PROTOCOL_BINARY_CMD_FLUSH = 0x08, - PROTOCOL_BINARY_CMD_GETQ = 0x09, - PROTOCOL_BINARY_CMD_NOOP = 0x0a, - PROTOCOL_BINARY_CMD_VERSION = 0x0b, - PROTOCOL_BINARY_CMD_GETK = 0x0c, - PROTOCOL_BINARY_CMD_GETKQ = 0x0d, - PROTOCOL_BINARY_CMD_APPEND = 0x0e, - PROTOCOL_BINARY_CMD_PREPEND = 0x0f, - PROTOCOL_BINARY_CMD_STAT = 0x10, - PROTOCOL_BINARY_CMD_SETQ = 0x11, - PROTOCOL_BINARY_CMD_ADDQ = 0x12, - PROTOCOL_BINARY_CMD_REPLACEQ = 0x13, - PROTOCOL_BINARY_CMD_DELETEQ = 0x14, - PROTOCOL_BINARY_CMD_INCREMENTQ = 0x15, - PROTOCOL_BINARY_CMD_DECREMENTQ = 0x16, - PROTOCOL_BINARY_CMD_QUITQ = 0x17, - PROTOCOL_BINARY_CMD_FLUSHQ = 0x18, - PROTOCOL_BINARY_CMD_APPENDQ = 0x19, - PROTOCOL_BINARY_CMD_PREPENDQ = 0x1a, - PROTOCOL_BINARY_CMD_VERBOSITY = 0x1b, - PROTOCOL_BINARY_CMD_TOUCH = 0x1c, - PROTOCOL_BINARY_CMD_GAT = 0x1d, - PROTOCOL_BINARY_CMD_GATQ = 0x1e, - PROTOCOL_BINARY_CMD_GATK = 0x23, - PROTOCOL_BINARY_CMD_GATKQ = 0x24, - - PROTOCOL_BINARY_CMD_SASL_LIST_MECHS = 0x20, - PROTOCOL_BINARY_CMD_SASL_AUTH = 0x21, - PROTOCOL_BINARY_CMD_SASL_STEP = 0x22, - - /* These commands are used for range operations and exist within - * this header for use in other projects. Range operations are - * not expected to be implemented in the memcached server itself. - */ - PROTOCOL_BINARY_CMD_RGET = 0x30, - PROTOCOL_BINARY_CMD_RSET = 0x31, - PROTOCOL_BINARY_CMD_RSETQ = 0x32, - PROTOCOL_BINARY_CMD_RAPPEND = 0x33, - PROTOCOL_BINARY_CMD_RAPPENDQ = 0x34, - PROTOCOL_BINARY_CMD_RPREPEND = 0x35, - PROTOCOL_BINARY_CMD_RPREPENDQ = 0x36, - PROTOCOL_BINARY_CMD_RDELETE = 0x37, - PROTOCOL_BINARY_CMD_RDELETEQ = 0x38, - PROTOCOL_BINARY_CMD_RINCR = 0x39, - PROTOCOL_BINARY_CMD_RINCRQ = 0x3a, - PROTOCOL_BINARY_CMD_RDECR = 0x3b, - PROTOCOL_BINARY_CMD_RDECRQ = 0x3c, - /* End Range operations */ - - /* VBucket commands */ - PROTOCOL_BINARY_CMD_SET_VBUCKET = 0x3d, - PROTOCOL_BINARY_CMD_GET_VBUCKET = 0x3e, - PROTOCOL_BINARY_CMD_DEL_VBUCKET = 0x3f, - /* End VBucket commands */ - - /* TAP commands */ - PROTOCOL_BINARY_CMD_TAP_CONNECT = 0x40, - PROTOCOL_BINARY_CMD_TAP_MUTATION = 0x41, - PROTOCOL_BINARY_CMD_TAP_DELETE = 0x42, - PROTOCOL_BINARY_CMD_TAP_FLUSH = 0x43, - PROTOCOL_BINARY_CMD_TAP_OPAQUE = 0x44, - PROTOCOL_BINARY_CMD_TAP_VBUCKET_SET = 0x45, - PROTOCOL_BINARY_CMD_TAP_CHECKPOINT_START = 0x46, - PROTOCOL_BINARY_CMD_TAP_CHECKPOINT_END = 0x47, - /* End TAP */ - - PROTOCOL_BINARY_CMD_LAST_RESERVED = 0xef, - - /* Scrub the data */ - PROTOCOL_BINARY_CMD_SCRUB = 0xf0 - } protocol_binary_command; - - /** - * Definition of the data types in the packet - * See section 3.4 Data Types - */ - typedef enum { - PROTOCOL_BINARY_RAW_BYTES = 0x00 - } protocol_binary_datatypes; - - /** - * Definition of the header structure for a request packet. - * See section 2 - */ - typedef union { - struct { - uint8_t magic; - uint8_t opcode; - uint16_t keylen; - uint8_t extlen; - uint8_t datatype; - uint16_t vbucket; - uint32_t bodylen; - uint32_t opaque; - uint64_t cas; - } request; - uint8_t bytes[24]; - } protocol_binary_request_header; - - /** - * Definition of the header structure for a response packet. - * See section 2 - */ - typedef union { - struct { - uint8_t magic; - uint8_t opcode; - uint16_t keylen; - uint8_t extlen; - uint8_t datatype; - uint16_t status; - uint32_t bodylen; - uint32_t opaque; - uint64_t cas; - } response; - uint8_t bytes[24]; - } protocol_binary_response_header; - - /** - * Definition of a request-packet containing no extras - */ - union protocol_binary_request_no_extras { - struct { - protocol_binary_request_header header; - } message; - uint8_t bytes[sizeof(protocol_binary_request_header)]; - }; - typedef union protocol_binary_request_no_extras protocol_binary_request_no_extras; - - /** - * Definition of a response-packet containing no extras - */ - typedef union { - struct { - protocol_binary_response_header header; - } message; - uint8_t bytes[sizeof(protocol_binary_response_header)]; - } protocol_binary_response_no_extras; - - /** - * Definition of the packet used by the get, getq, getk and getkq command. - * See section 4 - */ - typedef protocol_binary_request_no_extras protocol_binary_request_get; - typedef protocol_binary_request_no_extras protocol_binary_request_getq; - typedef protocol_binary_request_no_extras protocol_binary_request_getk; - typedef protocol_binary_request_no_extras protocol_binary_request_getkq; - - /** - * Definition of the packet returned from a successful get, getq, getk and - * getkq. - * See section 4 - */ - typedef union { - struct { - protocol_binary_response_header header; - struct { - uint32_t flags; - } body; - } message; - uint8_t bytes[sizeof(protocol_binary_response_header) + 4]; - } protocol_binary_response_get; - - typedef protocol_binary_response_get protocol_binary_response_getq; - typedef protocol_binary_response_get protocol_binary_response_getk; - typedef protocol_binary_response_get protocol_binary_response_getkq; - - /** - * Definition of the packet used by the delete command - * See section 4 - */ - typedef protocol_binary_request_no_extras protocol_binary_request_delete; - - /** - * Definition of the packet returned by the delete command - * See section 4 - */ - typedef protocol_binary_response_no_extras protocol_binary_response_delete; - - /** - * Definition of the packet used by the flush command - * See section 4 - * Please note that the expiration field is optional, so remember to see - * check the header.bodysize to see if it is present. - */ - typedef union { - struct { - protocol_binary_request_header header; - struct { - uint32_t expiration; - } body; - } message; - uint8_t bytes[sizeof(protocol_binary_request_header) + 4]; - } protocol_binary_request_flush; - - /** - * Definition of the packet returned by the flush command - * See section 4 - */ - typedef protocol_binary_response_no_extras protocol_binary_response_flush; - - /** - * Definition of the packet used by set, add and replace - * See section 4 - */ - typedef union { - struct { - protocol_binary_request_header header; - struct { - uint32_t flags; - uint32_t expiration; - } body; - } message; - uint8_t bytes[sizeof(protocol_binary_request_header) + 8]; - } protocol_binary_request_set; - typedef protocol_binary_request_set protocol_binary_request_add; - typedef protocol_binary_request_set protocol_binary_request_replace; - - /** - * Definition of the packet returned by set, add and replace - * See section 4 - */ - typedef protocol_binary_response_no_extras protocol_binary_response_set; - typedef protocol_binary_response_no_extras protocol_binary_response_add; - typedef protocol_binary_response_no_extras protocol_binary_response_replace; - - /** - * Definition of the noop packet - * See section 4 - */ - typedef protocol_binary_request_no_extras protocol_binary_request_noop; - - /** - * Definition of the packet returned by the noop command - * See section 4 - */ - typedef protocol_binary_response_no_extras protocol_binary_response_noop; - - /** - * Definition of the structure used by the increment and decrement - * command. - * See section 4 - */ - typedef union { - struct { - protocol_binary_request_header header; - struct { - uint64_t delta; - uint64_t initial; - uint32_t expiration; - } body; - } message; - uint8_t bytes[sizeof(protocol_binary_request_header) + 20]; - } protocol_binary_request_incr; - typedef protocol_binary_request_incr protocol_binary_request_decr; - - /** - * Definition of the response from an incr or decr command - * command. - * See section 4 - */ - typedef union { - struct { - protocol_binary_response_header header; - struct { - uint64_t value; - } body; - } message; - uint8_t bytes[sizeof(protocol_binary_response_header) + 8]; - } protocol_binary_response_incr; - typedef protocol_binary_response_incr protocol_binary_response_decr; - - /** - * Definition of the quit - * See section 4 - */ - typedef protocol_binary_request_no_extras protocol_binary_request_quit; - - /** - * Definition of the packet returned by the quit command - * See section 4 - */ - typedef protocol_binary_response_no_extras protocol_binary_response_quit; - - /** - * Definition of the packet used by append and prepend command - * See section 4 - */ - typedef protocol_binary_request_no_extras protocol_binary_request_append; - typedef protocol_binary_request_no_extras protocol_binary_request_prepend; - - /** - * Definition of the packet returned from a successful append or prepend - * See section 4 - */ - typedef protocol_binary_response_no_extras protocol_binary_response_append; - typedef protocol_binary_response_no_extras protocol_binary_response_prepend; - - /** - * Definition of the packet used by the version command - * See section 4 - */ - typedef protocol_binary_request_no_extras protocol_binary_request_version; - - /** - * Definition of the packet returned from a successful version command - * See section 4 - */ - typedef protocol_binary_response_no_extras protocol_binary_response_version; - - - /** - * Definition of the packet used by the stats command. - * See section 4 - */ - typedef protocol_binary_request_no_extras protocol_binary_request_stats; - - /** - * Definition of the packet returned from a successful stats command - * See section 4 - */ - typedef protocol_binary_response_no_extras protocol_binary_response_stats; - - /** - * Definition of the packet used by the verbosity command - */ - typedef union { - struct { - protocol_binary_request_header header; - struct { - uint32_t level; - } body; - } message; - uint8_t bytes[sizeof(protocol_binary_request_header) + 4]; - } protocol_binary_request_verbosity; - - /** - * Definition of the packet returned from the verbosity command - */ - typedef protocol_binary_response_no_extras protocol_binary_response_verbosity; - - /** - * Definition of the packet used by the touch command. - */ - typedef union { - struct { - protocol_binary_request_header header; - struct { - uint32_t expiration; - } body; - } message; - uint8_t bytes[sizeof(protocol_binary_request_header) + 4]; - } protocol_binary_request_touch; - - /** - * Definition of the packet returned from the touch command - */ - typedef protocol_binary_response_no_extras protocol_binary_response_touch; - - /** - * Definition of the packet used by the GAT(Q) command. - */ - typedef union { - struct { - protocol_binary_request_header header; - struct { - uint32_t expiration; - } body; - } message; - uint8_t bytes[sizeof(protocol_binary_request_header) + 4]; - } protocol_binary_request_gat; - - typedef protocol_binary_request_gat protocol_binary_request_gatq; - - /** - * Definition of the packet returned from the GAT(Q) - */ - typedef protocol_binary_response_get protocol_binary_response_gat; - typedef protocol_binary_response_get protocol_binary_response_gatq; - - - /** - * Definition of a request for a range operation. - * See http://code.google.com/p/memcached/wiki/RangeOps - * - * These types are used for range operations and exist within - * this header for use in other projects. Range operations are - * not expected to be implemented in the memcached server itself. - */ - typedef union { - struct { - protocol_binary_response_header header; - struct { - uint16_t size; - uint8_t reserved; - uint8_t flags; - uint32_t max_results; - } body; - } message; - uint8_t bytes[sizeof(protocol_binary_request_header) + 4]; - } protocol_binary_request_rangeop; - - typedef protocol_binary_request_rangeop protocol_binary_request_rget; - typedef protocol_binary_request_rangeop protocol_binary_request_rset; - typedef protocol_binary_request_rangeop protocol_binary_request_rsetq; - typedef protocol_binary_request_rangeop protocol_binary_request_rappend; - typedef protocol_binary_request_rangeop protocol_binary_request_rappendq; - typedef protocol_binary_request_rangeop protocol_binary_request_rprepend; - typedef protocol_binary_request_rangeop protocol_binary_request_rprependq; - typedef protocol_binary_request_rangeop protocol_binary_request_rdelete; - typedef protocol_binary_request_rangeop protocol_binary_request_rdeleteq; - typedef protocol_binary_request_rangeop protocol_binary_request_rincr; - typedef protocol_binary_request_rangeop protocol_binary_request_rincrq; - typedef protocol_binary_request_rangeop protocol_binary_request_rdecr; - typedef protocol_binary_request_rangeop protocol_binary_request_rdecrq; - - - /** - * Definition of tap commands - * See To be written - * - */ - - typedef union { - struct { - protocol_binary_request_header header; - struct { - /** - * flags is a bitmask used to set properties for the - * the connection. Please In order to be forward compatible - * you should set all undefined bits to 0. - * - * If the bit require extra userdata, it will be stored - * in the user-data field of the body (passed to the engine - * as enginespeciffic). That means that when you parse the - * flags and the engine-specific data, you have to work your - * way from bit 0 and upwards to find the correct offset for - * the data. - * - */ - uint32_t flags; - - /** - * Backfill age - * - * By using this flag you can limit the amount of data being - * transmitted. If you don't specify a backfill age, the - * server will transmit everything it contains. - * - * The first 8 bytes in the engine specific data contains - * the oldest entry (from epoc) you're interested in. - * Specifying a time in the future (for the server you are - * connecting to), will cause it to start streaming current - * changes. - */ -#define TAP_CONNECT_FLAG_BACKFILL 0x01 - /** - * Dump will cause the server to send the data stored on the - * server, but disconnect when the keys stored in the server - * are transmitted. - */ -#define TAP_CONNECT_FLAG_DUMP 0x02 - /** - * The body contains a list of 16 bits words in network byte - * order specifying the vbucket ids to monitor. The first 16 - * bit word contains the number of buckets. The number of 0 - * means "all buckets" - */ -#define TAP_CONNECT_FLAG_LIST_VBUCKETS 0x04 - /** - * The responsibility of the vbuckets is to be transferred - * over to the caller when all items are transferred. - */ -#define TAP_CONNECT_FLAG_TAKEOVER_VBUCKETS 0x08 - /** - * The tap consumer supports ack'ing of tap messages - */ -#define TAP_CONNECT_SUPPORT_ACK 0x10 - /** - * The tap consumer would prefer to just get the keys - * back. If the engine supports this it will set - * the TAP_FLAG_NO_VALUE flag in each of the - * tap packets returned. - */ -#define TAP_CONNECT_REQUEST_KEYS_ONLY 0x20 - /** - * The body contains a list of (vbucket_id, last_checkpoint_id) - * pairs. This provides the checkpoint support in TAP streams. - * The last checkpoint id represents the last checkpoint that - * was successfully persisted. - */ -#define TAP_CONNECT_CHECKPOINT 0x40 - /** - * The tap consumer is a registered tap client, which means that - * the tap server will maintain its checkpoint cursor permanently. - */ -#define TAP_CONNECT_REGISTERED_CLIENT 0x80 - } body; - } message; - uint8_t bytes[sizeof(protocol_binary_request_header) + 4]; - } protocol_binary_request_tap_connect; - - typedef union { - struct { - protocol_binary_request_header header; - struct { - struct { - uint16_t enginespecific_length; - /* - * The flag section support the following flags - */ - /** - * Request that the consumer send a response packet - * for this packet. The opaque field must be preserved - * in the response. - */ -#define TAP_FLAG_ACK 0x01 - /** - * The value for the key is not included in the packet - */ -#define TAP_FLAG_NO_VALUE 0x02 - uint16_t flags; - uint8_t ttl; - uint8_t res1; - uint8_t res2; - uint8_t res3; - } tap; - struct { - uint32_t flags; - uint32_t expiration; - } item; - } body; - } message; - uint8_t bytes[sizeof(protocol_binary_request_header) + 16]; - } protocol_binary_request_tap_mutation; - - typedef union { - struct { - protocol_binary_request_header header; - struct { - struct { - uint16_t enginespecific_length; - /** - * See the definition of the flags for - * protocol_binary_request_tap_mutation for a description - * of the available flags. - */ - uint16_t flags; - uint8_t ttl; - uint8_t res1; - uint8_t res2; - uint8_t res3; - } tap; - } body; - } message; - uint8_t bytes[sizeof(protocol_binary_request_header) + 8]; - } protocol_binary_request_tap_no_extras; - - typedef protocol_binary_request_tap_no_extras protocol_binary_request_tap_delete; - typedef protocol_binary_request_tap_no_extras protocol_binary_request_tap_flush; - typedef protocol_binary_request_tap_no_extras protocol_binary_request_tap_opaque; - typedef protocol_binary_request_tap_no_extras protocol_binary_request_tap_vbucket_set; - - - /** - * Definition of the packet used by the scrub. - */ - typedef protocol_binary_request_no_extras protocol_binary_request_scrub; - - /** - * Definition of the packet returned from scrub. - */ - typedef protocol_binary_response_no_extras protocol_binary_response_scrub; - - - /** - * Definition of the packet used by set vbucket - */ - typedef union { - struct { - protocol_binary_request_header header; - struct { - vbucket_state_t state; - } body; - } message; - uint8_t bytes[sizeof(protocol_binary_request_header) + sizeof(vbucket_state_t)]; - } protocol_binary_request_set_vbucket; - /** - * Definition of the packet returned from set vbucket - */ - typedef protocol_binary_response_no_extras protocol_binary_response_set_vbucket; - /** - * Definition of the packet used by del vbucket - */ - typedef protocol_binary_request_no_extras protocol_binary_request_del_vbucket; - /** - * Definition of the packet returned from del vbucket - */ - typedef protocol_binary_response_no_extras protocol_binary_response_del_vbucket; - - /** - * Definition of the packet used by get vbucket - */ - typedef protocol_binary_request_no_extras protocol_binary_request_get_vbucket; - - /** - * Definition of the packet returned from get vbucket - */ - typedef union { - struct { - protocol_binary_response_header header; - struct { - vbucket_state_t state; - } body; - } message; - uint8_t bytes[sizeof(protocol_binary_response_header) + sizeof(vbucket_state_t)]; - } protocol_binary_response_get_vbucket; - - - /** - * @} - */ - -#ifdef __cplusplus -} -#endif -#endif /* PROTOCOL_BINARY_H */ diff --git a/libmemcachedprotocol-0.0/callback.h b/libmemcachedprotocol-0.0/callback.h deleted file mode 100644 index 638536c8..00000000 --- a/libmemcachedprotocol-0.0/callback.h +++ /dev/null @@ -1,416 +0,0 @@ -/* - * Summary: Definition of the callback interface - * - * Copy: See Copyright for the status of this software. - * - * Author: Trond Norbye - */ - -#pragma once - -/** - * Callback to send data back from a successful GET/GETQ/GETK/GETKQ command - * - * @param cookie Just pass along the cookie supplied in the callback - * @param key What to insert as key in the reply - * @param keylen The length of the key - * @param body What to store in the body of the package - * @param bodylen The number of bytes of the body - * @param flags The flags stored with the item - * @param cas The CAS value to insert into the response (should be 0 - * if you don't care) - */ -typedef protocol_binary_response_status -(*memcached_binary_protocol_get_response_handler)(const void *cookie, - const void *key, - uint16_t keylen, - const void *body, - uint32_t bodylen, - uint32_t flags, - uint64_t cas); -/** - * Callback to send data back from a STAT command - * - * @param cookie Just pass along the cookie supplied in the callback - * @param key What to insert as key in the reply - * @param keylen The length of the key - * @param body What to store in the body of the package - * @param bodylen The number of bytes of the body - */ -typedef protocol_binary_response_status -(*memcached_binary_protocol_stat_response_handler)(const void *cookie, - const void *key, - uint16_t keylen, - const void *body, - uint32_t bodylen); -/** - * Callback to send data back from a VERSION command - * - * @param cookie Just pass along the cookie supplied in the callback - * @param text The version string - * @param length The number of bytes in the version string - */ -typedef protocol_binary_response_status -(*memcached_binary_protocol_version_response_handler)(const void *cookie, - const void *text, - uint32_t length); - - -/** - * In the low level interface you need to format the response - * packet yourself (giving you complete freedom :-) - * - * @param cookie Just pass along the cookie supplied in the callback - * @param request Pointer to the request packet you are sending a reply to - * @param response Pointer to the response packet to send - * - */ -typedef protocol_binary_response_status (*memcached_binary_protocol_raw_response_handler)(const void *cookie, - protocol_binary_request_header *request, - protocol_binary_response_header *response); - -/** - * In the low lever interface you have to do most of the work by - * yourself, but it also gives you a lot of freedom :-) - * @param cookie identification for this connection, just pass it along to - * the response handler - * @param header the command received over the wire. Never try to access - * <u>anything</u> outside the command. - * @param resonse_handler call this function to send data back to the client - */ -typedef protocol_binary_response_status (*memcached_binary_protocol_command_handler)(const void *cookie, - protocol_binary_request_header *header, - memcached_binary_protocol_raw_response_handler response_handler); - -/** - * The raw interface to the packets is implemented in version 0. It contains - * just an array with command handlers. The inxed in the array is the - * com code. - */ -typedef struct { - memcached_binary_protocol_command_handler comcode[256]; -} memcached_binary_protocol_callback_v0_st; - - -/** - * The first version of the callback struct containing all of the - * documented commands in the initial release of the binary protocol - * (aka. memcached 1.4.0). - * - * You might miss the Q commands (addq etc) but the response function - * knows how to deal with them so you don't need to worry about that :-) - */ -typedef struct { - /** - * Add an item to the cache - * @param cookie id of the client receiving the command - * @param key the key to add - * @param len the length of the key - * @param val the value to store for the key (may be NIL) - * @param vallen the length of the data - * @param flags the flags to store with the key - * @param exptime the expiry time for the key-value pair - * @param cas the resulting cas for the add operation (if success) - */ - protocol_binary_response_status (*add)(const void *cookie, - const void *key, - uint16_t keylen, - const void* val, - uint32_t vallen, - uint32_t flags, - uint32_t exptime, - uint64_t *cas); - - /** - * Append data to an <b>existing</b> key-value pair. - * - * @param cookie id of the client receiving the command - * @param key the key to add data to - * @param len the length of the key - * @param val the value to append to the value - * @param vallen the length of the data - * @param cas the CAS in the request - * @param result_cas the resulting cas for the append operation - * - */ - protocol_binary_response_status (*append)(const void *cookie, - const void *key, - uint16_t keylen, - const void* val, - uint32_t vallen, - uint64_t cas, - uint64_t *result_cas); - - /** - * Decrement the value for a key - * - * @param cookie id of the client receiving the command - * @param key the key to decrement the value for - * @param len the length of the key - * @param delta the amount to decrement - * @param initial initial value to store (if the key doesn't exist) - * @param expiration expiration time for the object (if the key doesn't exist) - * @param cas the CAS in the request - * @param result the result from the decrement - * @param result_cas the cas of the item - * - */ - protocol_binary_response_status (*decrement)(const void *cookie, - const void *key, - uint16_t keylen, - uint64_t delta, - uint64_t initial, - uint32_t expiration, - uint64_t *result, - uint64_t *result_cas); - - /** - * Delete an existing key - * - * @param cookie id of the client receiving the command - * @param key the key to delete_object - * @param len the length of the key - * @param cas the CAS in the request - */ - protocol_binary_response_status (*delete_object)(const void *cookie, - const void *key, - uint16_t keylen, - uint64_t cas); - - - /** - * Flush the cache - * - * @param cookie id of the client receiving the command - * @param when when the cache should be flushed (0 == immediately) - */ - protocol_binary_response_status (*flush_object)(const void *cookie, - uint32_t when); - - - - /** - * Get a key-value pair - * - * @param cookie id of the client receiving the command - * @param key the key to get - * @param len the length of the key - * @param response_handler to send the result back to the client - */ - protocol_binary_response_status (*get)(const void *cookie, - const void *key, - uint16_t keylen, - memcached_binary_protocol_get_response_handler response_handler); - - /** - * Increment the value for a key - * - * @param cookie id of the client receiving the command - * @param key the key to increment the value on - * @param len the length of the key - * @param delta the amount to increment - * @param initial initial value to store (if the key doesn't exist) - * @param expiration expiration time for the object (if the key doesn't exist) - * @param cas the CAS in the request - * @param result the result from the decrement - * @param result_cas the cas of the item - * - */ - protocol_binary_response_status (*increment)(const void *cookie, - const void *key, - uint16_t keylen, - uint64_t delta, - uint64_t initial, - uint32_t expiration, - uint64_t *result, - uint64_t *result_cas); - - /** - * The noop command was received. This is just a notification callback (the - * response is automatically created). - * - * @param cookie id of the client receiving the command - */ - protocol_binary_response_status (*noop)(const void *cookie); - - /** - * Prepend data to an <b>existing</b> key-value pair. - * - * @param cookie id of the client receiving the command - * @param key the key to prepend data to - * @param len the length of the key - * @param val the value to prepend to the value - * @param vallen the length of the data - * @param cas the CAS in the request - * @param result-cas the cas id of the item - * - */ - protocol_binary_response_status (*prepend)(const void *cookie, - const void *key, - uint16_t keylen, - const void* val, - uint32_t vallen, - uint64_t cas, - uint64_t *result_cas); - - /** - * The quit command was received. This is just a notification callback (the - * response is automatically created). - * - * @param cookie id of the client receiving the command - */ - protocol_binary_response_status (*quit)(const void *cookie); - - - /** - * Replace an <b>existing</b> item to the cache - * - * @param cookie id of the client receiving the command - * @param key the key to replace the content for - * @param len the length of the key - * @param val the value to store for the key (may be NIL) - * @param vallen the length of the data - * @param flags the flags to store with the key - * @param exptime the expiry time for the key-value pair - * @param cas the cas id in the request - * @param result_cas the cas id of the item - */ - protocol_binary_response_status (*replace)(const void *cookie, - const void *key, - uint16_t keylen, - const void* val, - uint32_t vallen, - uint32_t flags, - uint32_t exptime, - uint64_t cas, - uint64_t *result_cas); - - - /** - * Set a key-value pair in the cache - * - * @param cookie id of the client receiving the command - * @param key the key to insert - * @param len the length of the key - * @param val the value to store for the key (may be NIL) - * @param vallen the length of the data - * @param flags the flags to store with the key - * @param exptime the expiry time for the key-value pair - * @param cas the cas id in the request - * @param result_cas the cas id of the new item - */ - protocol_binary_response_status (*set)(const void *cookie, - const void *key, - uint16_t keylen, - const void* val, - uint32_t vallen, - uint32_t flags, - uint32_t exptime, - uint64_t cas, - uint64_t *result_cas); - - /** - * Get status information - * - * @param cookie id of the client receiving the command - * @param key the key to get status for (or NIL to request all status). - * Remember to insert the terminating packet if multiple - * packets should be returned. - * @param keylen the length of the key - * @param response_handler to send the result back to the client, but - * don't send reply on success! - * - */ - protocol_binary_response_status (*stat)(const void *cookie, - const void *key, - uint16_t keylen, - memcached_binary_protocol_stat_response_handler response_handler); - - /** - * Get the version information - * - * @param cookie id of the client receiving the command - * @param response_handler to send the result back to the client, but - * don't send reply on success! - * - */ - protocol_binary_response_status (*version)(const void *cookie, - memcached_binary_protocol_version_response_handler response_handler); -} memcached_binary_protocol_callback_v1_st; - - -/** - * The version numbers for the different callback structures. - */ -typedef enum { - /** Version 0 is a lowlevel interface that tries to maximize your freedom */ - MEMCACHED_PROTOCOL_HANDLER_V0= 0, - /** - * Version 1 abstracts more of the protocol details, and let you work at - * a logical level - */ - MEMCACHED_PROTOCOL_HANDLER_V1= 1 -} memcached_protocol_interface_version_t; - -/** - * Definition of the protocol callback structure. - */ -typedef struct { - /** - * The interface version you provide callbacks for. - */ - memcached_protocol_interface_version_t interface_version; - - /** - * Callback fired just before the command will be executed. - * - * @param cookie id of the client receiving the command - * @param header the command header as received on the wire. If you look - * at the content you <b>must</b> ensure that you don't - * try to access beyond the end of the message. - */ - void (*pre_execute)(const void *cookie, - protocol_binary_request_header *header); - /** - * Callback fired just after the command was exected (please note - * that the data transfer back to the client is not finished at this - * time). - * - * @param cookie id of the client receiving the command - * @param header the command header as received on the wire. If you look - * at the content you <b>must</b> ensure that you don't - * try to access beyond the end of the message. - */ - void (*post_execute)(const void *cookie, - protocol_binary_request_header *header); - - /** - * Callback fired if no specialized callback is registered for this - * specific command code. - * - * @param cookie id of the client receiving the command - * @param header the command header as received on the wire. You <b>must</b> - * ensure that you don't try to access beyond the end of the - * message. - * @param response_handler The response handler to send data back. - */ - protocol_binary_response_status (*unknown)(const void *cookie, - protocol_binary_request_header *header, - memcached_binary_protocol_raw_response_handler response_handler); - - /** - * The different interface levels we support. A pointer is used so the - * size of the structure is fixed. You must ensure that the memory area - * passed as the pointer is valid as long as you use the protocol handler. - */ - union { - memcached_binary_protocol_callback_v0_st v0; - - /** - * The first version of the callback struct containing all of the - * documented commands in the initial release of the binary protocol - * (aka. memcached 1.4.0). - */ - memcached_binary_protocol_callback_v1_st v1; - } interface; -} memcached_binary_protocol_callback_st; diff --git a/libmemcachedprotocol-0.0/handler.h b/libmemcachedprotocol-0.0/handler.h deleted file mode 100644 index 113338df..00000000 --- a/libmemcachedprotocol-0.0/handler.h +++ /dev/null @@ -1,218 +0,0 @@ -/* LibMemcached - * Copyright (C) 2006-2009 Brian Aker - * All rights reserved. - * - * Use and distribution licensed under the BSD license. See - * the COPYING file in the parent directory for full text. - * - * Summary: Definition of the callback interface to the protocol handler - * - * Author: Trond Norbye - * - */ - -#pragma once - -#include <sys/types.h> -#if !defined(__cplusplus) -# include <stdbool.h> -#endif - -#include <libmemcached-1.0/visibility.h> -#include <libmemcached-1.0/platform.h> -#include <libmemcachedprotocol-0.0/binary.h> -#include <libmemcachedprotocol-0.0/callback.h> - -/* Forward declarations */ -/* - * You should only access memcached_protocol_st from one thread!, - * and never assume anything about the internal layout / sizes of the - * structures. - */ -typedef struct memcached_protocol_st memcached_protocol_st; -typedef struct memcached_protocol_client_st memcached_protocol_client_st; - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * Function the protocol handler should call to receive data. - * This function should behave exactly like read(2) - * - * @param cookie a cookie used to represent a given client - * @param fd the filedescriptor associated with the client - * @param buf destination buffer - * @param nbuf number of bytes to receive - * @return the number of bytes copied into buf - * or -1 upon error (errno should contain more information) - */ -typedef ssize_t (*memcached_protocol_recv_func)(const void *cookie, - memcached_socket_t fd, - void *buf, - size_t nbuf); - -/** - * Function the protocol handler should call to send data. - * This function should behave exactly like write(2) - * - * @param cookie a cookie used to represent a given client - * @param fd the filedescriptor associated with the client - * @param buf the source buffer - * @param nbuf number of bytes to send - * @return the number of bytes sent - * or -1 upon error (errno should contain more information) - */ -typedef ssize_t (*memcached_protocol_send_func)(const void *cookie, - memcached_socket_t fd, - const void *buf, - size_t nbuf); - -/** - * Create an instance of the protocol handler - * - * @return NULL if allocation of an instance fails - */ -LIBMEMCACHED_API -memcached_protocol_st *memcached_protocol_create_instance(void); - -/** - * Get the callbacks associated with a protocol handler instance - * @return the callbacks currently used - */ -LIBMEMCACHED_API -memcached_binary_protocol_callback_st *memcached_binary_protocol_get_callbacks(memcached_protocol_st *instance); - -/** - * Set the callbacks to be used by the given protocol handler instance - * @param instance the instance to update - * @param callback the callbacks to use - */ -LIBMEMCACHED_API -void memcached_binary_protocol_set_callbacks(memcached_protocol_st *instance, memcached_binary_protocol_callback_st *callback); - -/** - * Should the library inspect the packages being sent and received and verify - * that they are according to the specification? If it encounters an invalid - * packet, it will return an EINVAL packet. - * - * @param instance the instance to update - * @param enable true if you want the library to check packages, false otherwise - */ -LIBMEMCACHED_API -void memcached_binary_protocol_set_pedantic(memcached_protocol_st *instance, bool enable); - -/** - * Is the library inpecting each package? - * @param instance the instance to check - * @return true it the library is inspecting each package, false otherwise - */ -LIBMEMCACHED_API -bool memcached_binary_protocol_get_pedantic(memcached_protocol_st *instance); - -/** - * Destroy an instance of the protocol handler - * - * @param instance The instance to destroy - */ -LIBMEMCACHED_API -void memcached_protocol_destroy_instance(memcached_protocol_st *instance); - -/** - * Set the IO functions used by the instance to send and receive data. The - * functions should behave like recv(3socket) and send(3socket). - * - * @param instance the instance to specify the IO functions for - * @param recv the function to call for reciving data - * @param send the function to call for sending data - */ -LIBMEMCACHED_API -void memached_protocol_set_io_functions(memcached_protocol_st *instance, - memcached_protocol_recv_func recv, - memcached_protocol_send_func send); - - -/** - * Create a new client instance and associate it with a socket - * @param instance the protocol instance to bind the client to - * @param sock the client socket - * @return NULL if allocation fails, otherwise an instance - */ -LIBMEMCACHED_API -memcached_protocol_client_st *memcached_protocol_create_client(memcached_protocol_st *instance, memcached_socket_t sock); - -/** - * Destroy a client handle. - * The caller needs to close the socket accociated with the client - * <b>before</b> calling this function. This function invalidates the - * client memory area. - * - * @param client the client to destroy - */ -LIBMEMCACHED_API -void memcached_protocol_client_destroy(memcached_protocol_client_st *client); - -LIBMEMCACHED_API -void memcached_protocol_client_set_verbose(struct memcached_protocol_client_st *client, bool arg); - -/** - * Error event means that the client encountered an error with the - * connection so you should shut it down - */ -#define MEMCACHED_PROTOCOL_ERROR_EVENT 1 -/** - * Please notify when there is more data available to read - */ -#define MEMCACHED_PROTOCOL_READ_EVENT 2 -/** - * Please notify when it is possible to send more data - */ -#define MEMCACHED_PROTOCOL_WRITE_EVENT 4 -/** - * Backed paused the execution for this client - */ -#define MEMCACHED_PROTOCOL_PAUSE_EVENT 8 - -/** - * The different events the client is interested in. This is a bitmask of - * the constants defined above. - */ -typedef uint32_t memcached_protocol_event_t; - -/** - * Let the client do some work. This might involve reading / sending data - * to/from the client, or perform callbacks to execute a command. - * @param client the client structure to work on - * @return The next event the protocol handler will be notified for - */ -LIBMEMCACHED_API -memcached_protocol_event_t memcached_protocol_client_work(memcached_protocol_client_st *client); - -/** - * Get the socket attached to a client handle - * @param client the client to query - * @return the socket handle - */ -LIBMEMCACHED_API -memcached_socket_t memcached_protocol_client_get_socket(memcached_protocol_client_st *client); - -/** - * Get the error id socket attached to a client handle - * @param client the client to query for an error code - * @return the OS error code from the client - */ -LIBMEMCACHED_API -int memcached_protocol_client_get_errno(memcached_protocol_client_st *client); - -/** - * Get a raw response handler for the given cookie - * @param cookie the cookie passed along into the callback - * @return the raw reponse handler you may use if you find - * the generic callback too limiting - */ -LIBMEMCACHED_API -memcached_binary_protocol_raw_response_handler memcached_binary_protocol_get_raw_response_handler(const void *cookie); - -#ifdef __cplusplus -} -#endif diff --git a/libmemcachedprotocol-0.0/include.am b/libmemcachedprotocol-0.0/include.am deleted file mode 100644 index 3683c0f1..00000000 --- a/libmemcachedprotocol-0.0/include.am +++ /dev/null @@ -1,9 +0,0 @@ -# vim:ft=automake -# included from Top Level Makefile.am -# All paths should be given relative to the root - -nobase_include_HEADERS+= \ - libmemcachedprotocol-0.0/binary.h \ - libmemcachedprotocol-0.0/callback.h \ - libmemcachedprotocol-0.0/handler.h \ - libmemcachedprotocol-0.0/vbucket.h diff --git a/libmemcachedprotocol/ascii_handler.c b/libmemcachedprotocol/ascii_handler.c deleted file mode 100644 index 8cd29720..00000000 --- a/libmemcachedprotocol/ascii_handler.c +++ /dev/null @@ -1,1123 +0,0 @@ -/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: - * - * Libmemcached library - * - * Copyright (C) 2011 Data Differential, http://datadifferential.com/ - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * - * * The names of its contributors may not be used to endorse or - * promote products derived from this software without specific prior - * written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#include <libmemcachedprotocol/common.h> - -#include <ctype.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <errno.h> - - -static void print_ascii_command(memcached_protocol_client_st *client) -{ - if (client->is_verbose) - { - switch (client->ascii_command) - { - case SET_CMD: - fprintf(stderr, "%s:%d SET_CMD\n", __FILE__, __LINE__); - break; - - case ADD_CMD: - fprintf(stderr, "%s:%d ADD_CMD\n", __FILE__, __LINE__); - break; - - case REPLACE_CMD: - fprintf(stderr, "%s:%d REPLACE_CMD\n", __FILE__, __LINE__); - break; - - case CAS_CMD: - fprintf(stderr, "%s:%d CAS_CMD\n", __FILE__, __LINE__); - break; - - case APPEND_CMD: - fprintf(stderr, "%s:%d APPEND_CMD\n", __FILE__, __LINE__); - break; - - case PREPEND_CMD: - fprintf(stderr, "%s:%d PREPEND_CMD\n", __FILE__, __LINE__); - break; - - case DELETE_CMD: - fprintf(stderr, "%s:%d DELETE_CMD\n", __FILE__, __LINE__); - break; - - case INCR_CMD: /* FALLTHROUGH */ - fprintf(stderr, "%s:%d INCR_CMD\n", __FILE__, __LINE__); - break; - - case DECR_CMD: - fprintf(stderr, "%s:%d DECR_CMD\n", __FILE__, __LINE__); - break; - - case STATS_CMD: - fprintf(stderr, "%s:%d STATS_CMD\n", __FILE__, __LINE__); - break; - - case FLUSH_ALL_CMD: - fprintf(stderr, "%s:%d FLUSH_ALL_CMD\n", __FILE__, __LINE__); - break; - - case VERSION_CMD: - fprintf(stderr, "%s:%d VERSION_CMD\n", __FILE__, __LINE__); - break; - - case QUIT_CMD: - fprintf(stderr, "%s:%d QUIT_CMD\n", __FILE__, __LINE__); - break; - - case VERBOSITY_CMD: - fprintf(stderr, "%s:%d VERBOSITY_CMD\n", __FILE__, __LINE__); - break; - - case GET_CMD: - fprintf(stderr, "%s:%d GET_CMD\n", __FILE__, __LINE__); - break; - - case GETS_CMD: - fprintf(stderr, "%s:%d GETS_CMD\n", __FILE__, __LINE__); - break; - - default: - case UNKNOWN_CMD: - fprintf(stderr, "%s:%d UNKNOWN_CMD\n", __FILE__, __LINE__); - break; - - } - } -} - -/** - * Try to parse a key from the string. - * @pointer start pointer to a pointer to the string (IN and OUT) - * @return length of the string of -1 if this was an illegal key (invalid - * characters or invalid length) - * @todo add length! - */ -static uint16_t parse_ascii_key(char **start) -{ - uint16_t len= 0; - char *c= *start; - /* Strip leading whitespaces */ - while (isspace(*c)) - { - ++c; - } - - *start= c; - - while (*c != '\0' && !isspace(*c) && !iscntrl(*c)) - { - ++c; - ++len; - } - - - if (len == 0 || len > 240 || (*c != '\0' && *c != '\r' && iscntrl(*c))) - { - return 0; - } - - return len; -} - -/** - * Spool a zero-terminated string - * @param client destination - * @param text the text to spool - * @return status of the spool operation - */ -static protocol_binary_response_status raw_response_handler(memcached_protocol_client_st *client, const char *text) -{ - if (client->is_verbose) - { - fprintf(stderr, "%s:%d %s\n", __FILE__, __LINE__, text); - } - - if (client->root->drain(client) == false) - { - return PROTOCOL_BINARY_RESPONSE_EINTERNAL; - } - - assert(client->output != NULL); -#if 0 - if (client->output == NULL) - { - /* I can write directly to the socket.... */ - do - { - size_t num_bytes= len -offset; - ssize_t nw= client->root->send(client, - client->sock, - ptr + offset, - num_bytes); - if (nw == -1) - { - if (get_socket_errno() == EWOULDBLOCK) - { - break; - } - else if (get_socket_errno() != EINTR) - { - client->error= errno; - return PROTOCOL_BINARY_RESPONSE_EINTERNAL; - } - } - else - { - offset += (size_t)nw; - } - } while (offset < len); - } -#endif - - return client->root->spool(client, text, strlen(text)); -} - -/** - * Send a "CLIENT_ERROR" message back to the client with the correct - * format of the command being sent - * @param client the client to send the message to - */ -static void send_command_usage(memcached_protocol_client_st *client) -{ - const char *errmsg[]= { - [GET_CMD]= "CLIENT_ERROR: Syntax error: get <key>*\r\n", - [GETS_CMD]= "CLIENT_ERROR: Syntax error: gets <key>*\r\n", - [SET_CMD]= "CLIENT_ERROR: Syntax error: set <key> <flags> <exptime> <bytes> [noreply]\r\n", - [ADD_CMD]= "CLIENT_ERROR: Syntax error: add <key> <flags> <exptime> <bytes> [noreply]\r\n", - [REPLACE_CMD]= "CLIENT_ERROR: Syntax error: replace <key> <flags> <exptime> <bytes> [noreply]\r\n", - [CAS_CMD]= "CLIENT_ERROR: Syntax error: cas <key> <flags> <exptime> <bytes> <casid> [noreply]\r\n", - [APPEND_CMD]= "CLIENT_ERROR: Syntax error: append <key> <flags> <exptime> <bytes> [noreply]\r\n", - [PREPEND_CMD]= "CLIENT_ERROR: Syntax error: prepend <key> <flags> <exptime> <bytes> [noreply]\r\n", - [DELETE_CMD]= "CLIENT_ERROR: Syntax error: delete_object <key> [noreply]\r\n", - [INCR_CMD]= "CLIENT_ERROR: Syntax error: incr <key> <value> [noreply]\r\n", - [DECR_CMD]= "CLIENT_ERROR: Syntax error: decr <key> <value> [noreply]\r\n", - [STATS_CMD]= "CLIENT_ERROR: Syntax error: stats [key]\r\n", - [FLUSH_ALL_CMD]= "CLIENT_ERROR: Syntax error: flush_all [timeout] [noreply]\r\n", - [VERSION_CMD]= "CLIENT_ERROR: Syntax error: version\r\n", - [QUIT_CMD]="CLIENT_ERROR: Syntax error: quit\r\n", - - [VERBOSITY_CMD]= "CLIENT_ERROR: Syntax error: verbosity <num>\r\n", - [UNKNOWN_CMD]= "CLIENT_ERROR: Unknown command\r\n", - }; - - client->mute = false; - raw_response_handler(client, errmsg[client->ascii_command]); -} - -/** - * Callback for the VERSION responses - * @param cookie client identifier - * @param text the length of the body - * @param textlen the length of the body - */ -static protocol_binary_response_status ascii_version_response_handler(const void *cookie, - const void *text, - uint32_t textlen) -{ - memcached_protocol_client_st *client= (memcached_protocol_client_st*)cookie; - raw_response_handler(client, "VERSION "); - client->root->spool(client, text, textlen); - raw_response_handler(client, "\r\n"); - return PROTOCOL_BINARY_RESPONSE_SUCCESS; -} - -/** - * Callback for the GET/GETQ/GETK and GETKQ responses - * @param cookie client identifier - * @param key the key for the item - * @param keylen the length of the key - * @param body the length of the body - * @param bodylen the length of the body - * @param flags the flags for the item - * @param cas the CAS id for the item - */ -static protocol_binary_response_status -ascii_get_response_handler(const void *cookie, - const void *key, - uint16_t keylen, - const void *body, - uint32_t bodylen, - uint32_t flags, - uint64_t cas) -{ - memcached_protocol_client_st *client= (void*)cookie; - char buffer[300]; - strcpy(buffer, "VALUE "); - const char *source= key; - char *dest= buffer + 6; - - for (int x= 0; x < keylen; ++x) - { - if (*source != '\0' && !isspace(*source) && !iscntrl(*source)) - { - *dest= *source; - } - else - { - return PROTOCOL_BINARY_RESPONSE_EINVAL; /* key constraints in ascii */ - } - - ++dest; - ++source; - } - - size_t used= (size_t)(dest - buffer); - - if (client->ascii_command == GETS_CMD) - { - snprintf(dest, sizeof(buffer) - used, " %u %u %" PRIu64 "\r\n", flags, - bodylen, cas); - } - else - { - snprintf(dest, sizeof(buffer) - used, " %u %u\r\n", flags, bodylen); - } - - client->root->spool(client, buffer, strlen(buffer)); - client->root->spool(client, body, bodylen); - client->root->spool(client, "\r\n", 2); - - return PROTOCOL_BINARY_RESPONSE_SUCCESS; -} - -/** - * Callback for the STAT responses - * @param cookie client identifier - * @param key the key for the item - * @param keylen the length of the key - * @param body the length of the body - * @param bodylen the length of the body - */ -static protocol_binary_response_status ascii_stat_response_handler(const void *cookie, - const void *key, - uint16_t keylen, - const void *body, - uint32_t bodylen) -{ - - memcached_protocol_client_st *client= (void*)cookie; - - if (key != NULL) - { - raw_response_handler(client, "STAT "); - client->root->spool(client, key, keylen); - raw_response_handler(client, " "); - client->root->spool(client, body, bodylen); - raw_response_handler(client, "\r\n"); - } - else - { - raw_response_handler(client, "END\r\n"); - } - - return PROTOCOL_BINARY_RESPONSE_SUCCESS; -} - -/** - * Process a get or a gets request. - * @param client the client handle - * @param buffer the complete get(s) command - * @param end the last character in the command - */ -static void ascii_process_gets(memcached_protocol_client_st *client, - char *buffer, char *end) -{ - char *key= buffer; - - /* Skip command */ - key += (client->ascii_command == GETS_CMD) ? 5 : 4; - - int num_keys= 0; - while (key < end) - { - uint16_t nkey= parse_ascii_key(&key); - if (nkey == 0) /* Invalid key... stop processing this line */ - { - break; - } - - (void)client->root->callback->interface.v1.get(client, key, nkey, - ascii_get_response_handler); - key += nkey; - ++num_keys; - } - - if (num_keys == 0) - { - send_command_usage(client); - } - else - { - client->root->spool(client, "END\r\n", 5); - } -} - -/** - * Try to split up the command line "asdf asdf asdf asdf\n" into an - * argument vector for easier parsing. - * @param start the first character in the command line - * @param end the last character in the command line ("\n") - * @param vec the vector to insert the pointers into - * @size the number of elements in the vector - * @return the number of tokens in the vector - */ -static int ascii_tokenize_command(char *str, char *end, char **vec, int size) -{ - int elem= 0; - - while (str < end) - { - /* Skip leading blanks */ - while (str < end && isspace(*str)) - { - ++str; - } - - if (str == end) - { - return elem; - } - - vec[elem++]= str; - /* find the next non-blank field */ - while (str < end && !isspace(*str)) - { - ++str; - } - - /* zero-terminate it for easier parsing later on */ - *str= '\0'; - ++str; - - /* Is the vector full? */ - if (elem == size) - { - break; - } - } - - return elem; -} - -/** - * If we for some reasons needs to push the line back to read more - * data we have to reverse the tokenization. Just do the brain-dead replace - * of all '\0' to ' ' and set the last character to '\n'. We could have used - * the vector we created, but then we would have to search for all of the - * spaces we ignored... - * @param start pointer to the first character in the buffer to recover - * @param end pointer to the last character in the buffer to recover - */ -static void recover_tokenize_command(char *start, char *end) -{ - while (start < end) - { - if (*start == '\0') - *start= ' '; - ++start; - } - - *end= '\n'; -} - -/** - * Convert the textual command into a comcode - */ -static enum ascii_cmd ascii_to_cmd(char *start, size_t length) -{ - struct { - const char *cmd; - size_t len; - enum ascii_cmd cc; - } commands[]= { - { .cmd= "get", .len= 3, .cc= GET_CMD }, - { .cmd= "gets", .len= 4, .cc= GETS_CMD }, - { .cmd= "set", .len= 3, .cc= SET_CMD }, - { .cmd= "add", .len= 3, .cc= ADD_CMD }, - { .cmd= "replace", .len= 7, .cc= REPLACE_CMD }, - { .cmd= "cas", .len= 3, .cc= CAS_CMD }, - { .cmd= "append", .len= 6, .cc= APPEND_CMD }, - { .cmd= "prepend", .len= 7, .cc= PREPEND_CMD }, - { .cmd= "delete_object", .len= 6, .cc= DELETE_CMD }, - { .cmd= "incr", .len= 4, .cc= INCR_CMD }, - { .cmd= "decr", .len= 4, .cc= DECR_CMD }, - { .cmd= "stats", .len= 5, .cc= STATS_CMD }, - { .cmd= "flush_all", .len= 9, .cc= FLUSH_ALL_CMD }, - { .cmd= "version", .len= 7, .cc= VERSION_CMD }, - { .cmd= "quit", .len= 4, .cc= QUIT_CMD }, - { .cmd= "verbosity", .len= 9, .cc= VERBOSITY_CMD }, - { .cmd= NULL, .len= 0, .cc= UNKNOWN_CMD }}; - - int x= 0; - while (commands[x].len > 0) { - if (length >= commands[x].len) - { - if (strncmp(start, commands[x].cmd, commands[x].len) == 0) - { - /* Potential hit */ - if (length == commands[x].len || isspace(*(start + commands[x].len))) - { - return commands[x].cc; - } - } - } - ++x; - } - - return UNKNOWN_CMD; -} - -/** - * Perform a delete_object operation. - * - * @param client client requesting the deletion - * @param tokens the command as a vector - * @param ntokens the number of items in the vector - */ -static void process_delete(memcached_protocol_client_st *client, - char **tokens, int ntokens) -{ - char *key= tokens[1]; - uint16_t nkey; - - if (ntokens != 2 || (nkey= parse_ascii_key(&key)) == 0) - { - send_command_usage(client); - return; - } - - if (client->root->callback->interface.v1.delete_object == NULL) - { - raw_response_handler(client, "SERVER_ERROR: callback not implemented\r\n"); - return; - } - - protocol_binary_response_status rval= client->root->callback->interface.v1.delete_object(client, key, nkey, 0); - - if (rval == PROTOCOL_BINARY_RESPONSE_SUCCESS) - { - raw_response_handler(client, "DELETED\r\n"); - } - else if (rval == PROTOCOL_BINARY_RESPONSE_KEY_ENOENT) - { - raw_response_handler(client, "NOT_FOUND\r\n"); - } - else - { - char msg[80]; - snprintf(msg, sizeof(msg), "SERVER_ERROR: delete_object failed %u\r\n",(uint32_t)rval); - raw_response_handler(client, msg); - } -} - -static void process_arithmetic(memcached_protocol_client_st *client, - char **tokens, int ntokens) -{ - char *key= tokens[1]; - uint16_t nkey; - - if (ntokens != 3 || (nkey= parse_ascii_key(&key)) == 0) - { - send_command_usage(client); - return; - } - - uint64_t cas; - uint64_t result; - uint64_t delta= strtoull(tokens[2], NULL, 10); - - protocol_binary_response_status rval; - if (client->ascii_command == INCR_CMD) - { - if (client->root->callback->interface.v1.increment == NULL) - { - raw_response_handler(client, "SERVER_ERROR: callback not implemented\r\n"); - return; - } - rval= client->root->callback->interface.v1.increment(client, - key, nkey, - delta, 0, - 0, - &result, - &cas); - } - else - { - if (client->root->callback->interface.v1.decrement == NULL) - { - raw_response_handler(client, "SERVER_ERROR: callback not implemented\r\n"); - return; - } - rval= client->root->callback->interface.v1.decrement(client, - key, nkey, - delta, 0, - 0, - &result, - &cas); - } - - if (rval == PROTOCOL_BINARY_RESPONSE_SUCCESS) - { - char buffer[80]; - snprintf(buffer, sizeof(buffer), "%"PRIu64"\r\n", result); - raw_response_handler(client, buffer); - } - else - { - raw_response_handler(client, "NOT_FOUND\r\n"); - } -} - -/** - * Process the stats command (with or without a key specified) - * @param key pointer to the first character after "stats" - * @param end pointer to the "\n" - */ -static void process_stats(memcached_protocol_client_st *client, - char *key, char *end) -{ - if (client->root->callback->interface.v1.stat == NULL) - { - raw_response_handler(client, "SERVER_ERROR: callback not implemented\r\n"); - return; - } - - while (isspace(*key)) - { - key++; - } - - uint16_t nkey= (uint16_t)(end - key); - (void)client->root->callback->interface.v1.stat(client, key, nkey, - ascii_stat_response_handler); -} - -static void process_version(memcached_protocol_client_st *client, - char **tokens, int ntokens) -{ - (void)tokens; - if (ntokens != 1) - { - send_command_usage(client); - return; - } - - if (client->root->callback->interface.v1.version == NULL) - { - raw_response_handler(client, "SERVER_ERROR: callback not implemented\r\n"); - return; - } - - client->root->callback->interface.v1.version(client, - ascii_version_response_handler); -} - -static void process_flush(memcached_protocol_client_st *client, - char **tokens, int ntokens) -{ - if (ntokens > 2) - { - send_command_usage(client); - return; - } - - if (client->root->callback->interface.v1.flush_object == NULL) - { - raw_response_handler(client, "SERVER_ERROR: callback not implemented\r\n"); - return; - } - - uint32_t timeout= 0; - if (ntokens == 2) - { - timeout= (uint32_t)strtoul(tokens[1], NULL, 10); - } - - protocol_binary_response_status rval; - rval= client->root->callback->interface.v1.flush_object(client, timeout); - if (rval == PROTOCOL_BINARY_RESPONSE_SUCCESS) - raw_response_handler(client, "OK\r\n"); - else - raw_response_handler(client, "SERVER_ERROR: internal error\r\n"); -} - -/** - * Process one of the storage commands - * @param client the client performing the operation - * @param tokens the command tokens - * @param ntokens the number of tokens - * @param start pointer to the first character in the line - * @param end pointer to the pointer where the last character of this - * command is (IN and OUT) - * @param length the number of bytes available - * @return -1 if an error occurs (and we should just terminate the connection - * because we are out of sync) - * 0 storage command completed, continue processing - * 1 We need more data, so just go ahead and wait for more! - */ -static inline int process_storage_command(memcached_protocol_client_st *client, - char **tokens, int ntokens, char *start, - char **end, ssize_t length) -{ - (void)ntokens; /* already checked */ - char *key= tokens[1]; - uint16_t nkey= parse_ascii_key(&key); - if (nkey == 0) - { - /* return error */ - raw_response_handler(client, "CLIENT_ERROR: bad key\r\n"); - return -1; - } - - uint32_t flags= (uint32_t)strtoul(tokens[2], NULL, 10); - uint32_t timeout= (uint32_t)strtoul(tokens[3], NULL, 10); - unsigned long nbytes= strtoul(tokens[4], NULL, 10); - - /* Do we have all data? */ - unsigned long need= nbytes + (unsigned long)((*end - start) + 1) + 2; /* \n\r\n */ - if ((ssize_t)need > length) - { - /* Keep on reading */ - recover_tokenize_command(start, *end); - return 1; - } - - void *data= (*end) + 1; - uint64_t cas= 0; - uint64_t result_cas; - protocol_binary_response_status rval; - switch (client->ascii_command) - { - case SET_CMD: - rval= client->root->callback->interface.v1.set(client, key, - (uint16_t)nkey, - data, - (uint32_t)nbytes, - flags, - timeout, cas, - &result_cas); - break; - case ADD_CMD: - rval= client->root->callback->interface.v1.add(client, key, - (uint16_t)nkey, - data, - (uint32_t)nbytes, - flags, - timeout, &result_cas); - break; - case CAS_CMD: - cas= strtoull(tokens[5], NULL, 10); - /* FALLTHROUGH */ - case REPLACE_CMD: - rval= client->root->callback->interface.v1.replace(client, key, - (uint16_t)nkey, - data, - (uint32_t)nbytes, - flags, - timeout, cas, - &result_cas); - break; - case APPEND_CMD: - rval= client->root->callback->interface.v1.append(client, key, - (uint16_t)nkey, - data, - (uint32_t)nbytes, - cas, - &result_cas); - break; - case PREPEND_CMD: - rval= client->root->callback->interface.v1.prepend(client, key, - (uint16_t)nkey, - data, - (uint32_t)nbytes, - cas, - &result_cas); - break; - - /* gcc complains if I don't put all of the enums in here.. */ - case GET_CMD: - case GETS_CMD: - case DELETE_CMD: - case DECR_CMD: - case INCR_CMD: - case STATS_CMD: - case FLUSH_ALL_CMD: - case VERSION_CMD: - case QUIT_CMD: - case VERBOSITY_CMD: - case UNKNOWN_CMD: - default: - abort(); /* impossible */ - } - - if (rval == PROTOCOL_BINARY_RESPONSE_SUCCESS) - { - raw_response_handler(client, "STORED\r\n"); - } - else - { - if (client->ascii_command == CAS_CMD) - { - if (rval == PROTOCOL_BINARY_RESPONSE_KEY_EEXISTS) - { - raw_response_handler(client, "EXISTS\r\n"); - } - else if (rval == PROTOCOL_BINARY_RESPONSE_KEY_ENOENT) - { - raw_response_handler(client, "NOT_FOUND\r\n"); - } - else - { - raw_response_handler(client, "NOT_STORED\r\n"); - } - } - else - { - raw_response_handler(client, "NOT_STORED\r\n"); - } - } - - *end += nbytes + 2; - - return 0; -} - -static int process_cas_command(memcached_protocol_client_st *client, - char **tokens, int ntokens, char *start, - char **end, ssize_t length) -{ - if (ntokens != 6) - { - send_command_usage(client); - return false; - } - - if (client->root->callback->interface.v1.replace == NULL) - { - raw_response_handler(client, "SERVER_ERROR: callback not implemented\r\n"); - return false; - } - - return process_storage_command(client, tokens, ntokens, start, end, length); -} - -static int process_set_command(memcached_protocol_client_st *client, - char **tokens, int ntokens, char *start, - char **end, ssize_t length) -{ - if (ntokens != 5) - { - send_command_usage(client); - return false; - } - - if (client->root->callback->interface.v1.set == NULL) - { - raw_response_handler(client, "SERVER_ERROR: callback not implemented\r\n"); - return false; - } - - return process_storage_command(client, tokens, ntokens, start, end, length); -} - -static int process_add_command(memcached_protocol_client_st *client, - char **tokens, int ntokens, char *start, - char **end, ssize_t length) -{ - if (ntokens != 5) - { - send_command_usage(client); - return false; - } - - if (client->root->callback->interface.v1.add == NULL) - { - raw_response_handler(client, "SERVER_ERROR: callback not implemented\r\n"); - return false; - } - - return process_storage_command(client, tokens, ntokens, start, end, length); -} - -static int process_replace_command(memcached_protocol_client_st *client, - char **tokens, int ntokens, char *start, - char **end, ssize_t length) -{ - if (ntokens != 5) - { - send_command_usage(client); - return false; - } - - if (client->root->callback->interface.v1.replace == NULL) - { - raw_response_handler(client, "SERVER_ERROR: callback not implemented\r\n"); - return false; - } - - return process_storage_command(client, tokens, ntokens, start, end, length); -} - -static int process_append_command(memcached_protocol_client_st *client, - char **tokens, int ntokens, char *start, - char **end, ssize_t length) -{ - if (ntokens != 5) - { - send_command_usage(client); - return false; - } - - if (client->root->callback->interface.v1.append == NULL) - { - raw_response_handler(client, "SERVER_ERROR: callback not implemented\r\n"); - return false; - } - - return process_storage_command(client, tokens, ntokens, start, end, length); -} - -static int process_prepend_command(memcached_protocol_client_st *client, - char **tokens, int ntokens, char *start, - char **end, ssize_t length) -{ - if (ntokens != 5) - { - send_command_usage(client); - return false; - } - - if (client->root->callback->interface.v1.prepend == NULL) - { - raw_response_handler(client, "SERVER_ERROR: callback not implemented\r\n"); - return false; - } - - return process_storage_command(client, tokens, ntokens, start, end, length); -} - -/** - * The ASCII protocol support is just one giant big hack. Instead of adding - * a optimal ascii support, I just convert the ASCII commands to the binary - * protocol and calls back into the command handlers for the binary protocol ;) - */ -memcached_protocol_event_t memcached_ascii_protocol_process_data(memcached_protocol_client_st *client, ssize_t *length, void **endptr) -{ - char *ptr= (char*)client->root->input_buffer; - *endptr= ptr; - - do { - /* Do we have \n (indicating the command preamble)*/ - char *end= memchr(ptr, '\n', (size_t)*length); - if (end == NULL) - { - *endptr= ptr; - return MEMCACHED_PROTOCOL_READ_EVENT; - } - - client->ascii_command= ascii_to_cmd(ptr, (size_t)(*length)); - - /* we got all data available, execute the callback! */ - if (client->root->callback->pre_execute != NULL) - { - client->root->callback->pre_execute(client, NULL); - } - - - /* A multiget lists all of the keys, and I don't want to have an - * avector of let's say 512 pointers to tokenize all of them, so let's - * just handle them immediately - */ - if (client->ascii_command == GET_CMD || - client->ascii_command == GETS_CMD) - { - if (client->root->callback->interface.v1.get != NULL) - { - ascii_process_gets(client, ptr, end); - } - else - { - raw_response_handler(client, "SERVER_ERROR: Command not implemented\n"); - } - } - else - { - /* None of the defined commands takes 10 parameters, so lets just use - * that as a maximum limit. - */ - char *tokens[10]; - int ntokens= ascii_tokenize_command(ptr, end, tokens, 10); - - if (ntokens < 10) - { - client->mute= strcmp(tokens[ntokens - 1], "noreply") == 0; - if (client->mute) - { - --ntokens; /* processed noreply token*/ - } - } - - int error= 0; - - print_ascii_command(client); - switch (client->ascii_command) - { - case SET_CMD: - error= process_set_command(client, tokens, ntokens, ptr, &end, *length); - break; - - case ADD_CMD: - error= process_add_command(client, tokens, ntokens, ptr, &end, *length); - break; - - case REPLACE_CMD: - error= process_replace_command(client, tokens, ntokens, ptr, &end, *length); - break; - - case CAS_CMD: - error= process_cas_command(client, tokens, ntokens, ptr, &end, *length); - break; - - case APPEND_CMD: - error= process_append_command(client, tokens, ntokens, ptr, &end, *length); - break; - - case PREPEND_CMD: - error= process_prepend_command(client, tokens, ntokens, ptr, &end, *length); - break; - - case DELETE_CMD: - process_delete(client, tokens, ntokens); - break; - - case INCR_CMD: /* FALLTHROUGH */ - case DECR_CMD: - process_arithmetic(client, tokens, ntokens); - break; - - case STATS_CMD: - if (client->mute) - { - send_command_usage(client); - } - else - { - recover_tokenize_command(ptr, end); - process_stats(client, ptr + 6, end); - } - break; - - case FLUSH_ALL_CMD: - process_flush(client, tokens, ntokens); - break; - - case VERSION_CMD: - if (client->mute) - { - send_command_usage(client); - } - else - { - process_version(client, tokens, ntokens); - } - break; - - case QUIT_CMD: - if (ntokens != 1 || client->mute) - { - send_command_usage(client); - } - else - { - if (client->root->callback->interface.v1.quit != NULL) - { - client->root->callback->interface.v1.quit(client); - } - - return MEMCACHED_PROTOCOL_ERROR_EVENT; - } - break; - - case VERBOSITY_CMD: - if (ntokens != 2) - { - send_command_usage(client); - } - else - { - raw_response_handler(client, "OK\r\n"); - } - break; - - case UNKNOWN_CMD: - send_command_usage(client); - break; - - case GET_CMD: - case GETS_CMD: - default: - /* Should already be handled */ - abort(); - } - - if (error == -1) - { - return MEMCACHED_PROTOCOL_ERROR_EVENT; - } - else if (error == 1) - { - return MEMCACHED_PROTOCOL_READ_EVENT; - } - } - - if (client->root->callback->post_execute != NULL) - { - client->root->callback->post_execute(client, NULL); - } - - /* Move past \n */ - ++end; - *length -= end - ptr; - ptr= end; - } while (*length > 0); - - *endptr= ptr; - return MEMCACHED_PROTOCOL_READ_EVENT; -} diff --git a/libmemcachedprotocol/ascii_handler.h b/libmemcachedprotocol/ascii_handler.h deleted file mode 100644 index 02f8831e..00000000 --- a/libmemcachedprotocol/ascii_handler.h +++ /dev/null @@ -1,40 +0,0 @@ -/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: - * - * Libmemcached library - * - * Copyright (C) 2011 Data Differential, http://datadifferential.com/ - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * - * * The names of its contributors may not be used to endorse or - * promote products derived from this software without specific prior - * written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#pragma once - -LIBMEMCACHED_LOCAL -memcached_protocol_event_t memcached_ascii_protocol_process_data(memcached_protocol_client_st *client, ssize_t *length, void **endptr); diff --git a/libmemcachedprotocol/binary_handler.c b/libmemcachedprotocol/binary_handler.c deleted file mode 100644 index d720424a..00000000 --- a/libmemcachedprotocol/binary_handler.c +++ /dev/null @@ -1,1198 +0,0 @@ -/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: - * - * Libmemcached library - * - * Copyright (C) 2011 Data Differential, http://datadifferential.com/ - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * - * * The names of its contributors may not be used to endorse or - * promote products derived from this software without specific prior - * written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#include <libmemcachedprotocol/common.h> - -#include <stdlib.h> -#include <sys/types.h> -#include <errno.h> -#include <stdbool.h> -#include <string.h> -#include <stdio.h> - -/* -** ********************************************************************** -** INTERNAL INTERFACE -** ********************************************************************** -*/ - -/** - * Send a preformatted packet back to the client. If the connection is in - * pedantic mode, it will validate the packet and refuse to send it if it - * breaks the specification. - * - * @param cookie client identification - * @param request the original request packet - * @param response the packet to send - * @return The status of the operation - */ -static protocol_binary_response_status raw_response_handler(const void *cookie, - protocol_binary_request_header *request, - protocol_binary_response_header *response) -{ - memcached_protocol_client_st *client= (void*)cookie; - - if (client->root->pedantic && - !memcached_binary_protocol_pedantic_check_response(request, response)) - { - return PROTOCOL_BINARY_RESPONSE_EINVAL; - } - - if (client->root->drain(client) == false) - { - return PROTOCOL_BINARY_RESPONSE_EINTERNAL; - } - - size_t len= sizeof(protocol_binary_response_header) + htonl(response->response.bodylen); - size_t offset= 0; - char *ptr= (void*)response; - - if (client->output == NULL) - { - /* I can write directly to the socket.... */ - do - { - size_t num_bytes= len - offset; - ssize_t nw= client->root->send(client, - client->sock, - ptr + offset, - num_bytes); - if (nw == -1) - { - if (get_socket_errno() == EWOULDBLOCK) - { - break; - } - else if (get_socket_errno() != EINTR) - { - client->error= errno; - return PROTOCOL_BINARY_RESPONSE_EINTERNAL; - } - } - else - { - offset += (size_t)nw; - } - } while (offset < len); - } - - return client->root->spool(client, ptr, len - offset); -} - -static void print_cmd(protocol_binary_command cmd) -{ - switch (cmd) - { - case PROTOCOL_BINARY_CMD_GET: fprintf(stderr, "%s:%d PROTOCOL_BINARY_CMD_GET\n", __FILE__, __LINE__); return; - case PROTOCOL_BINARY_CMD_SET: fprintf(stderr, "%s:%d PROTOCOL_BINARY_CMD_SET\n", __FILE__, __LINE__); return; - case PROTOCOL_BINARY_CMD_ADD: fprintf(stderr, "%s:%d PROTOCOL_BINARY_CMD_ADD\n", __FILE__, __LINE__); return; - case PROTOCOL_BINARY_CMD_REPLACE: fprintf(stderr, "%s:%d PROTOCOL_BINARY_CMD_REPLACE\n", __FILE__, __LINE__); return; - case PROTOCOL_BINARY_CMD_DELETE: fprintf(stderr, "%s:%d PROTOCOL_BINARY_CMD_DELETE\n", __FILE__, __LINE__); return; - case PROTOCOL_BINARY_CMD_INCREMENT: fprintf(stderr, "%s:%d PROTOCOL_BINARY_CMD_INCREMENT\n", __FILE__, __LINE__); return; - case PROTOCOL_BINARY_CMD_DECREMENT: fprintf(stderr, "%s:%d PROTOCOL_BINARY_CMD_DECREMENT\n", __FILE__, __LINE__); return; - case PROTOCOL_BINARY_CMD_QUIT: fprintf(stderr, "%s:%d PROTOCOL_BINARY_CMD_QUIT\n", __FILE__, __LINE__); return; - case PROTOCOL_BINARY_CMD_FLUSH: fprintf(stderr, "%s:%d PROTOCOL_BINARY_CMD_FLUSH\n", __FILE__, __LINE__); return; - case PROTOCOL_BINARY_CMD_GETQ: fprintf(stderr, "%s:%d PROTOCOL_BINARY_CMD_GETQ\n", __FILE__, __LINE__); return; - case PROTOCOL_BINARY_CMD_NOOP: fprintf(stderr, "%s:%d PROTOCOL_BINARY_CMD_NOOP\n", __FILE__, __LINE__); return; - case PROTOCOL_BINARY_CMD_VERSION: fprintf(stderr, "%s:%d PROTOCOL_BINARY_CMD_VERSION\n", __FILE__, __LINE__); return; - case PROTOCOL_BINARY_CMD_GETK: fprintf(stderr, "%s:%d PROTOCOL_BINARY_CMD_GETK\n", __FILE__, __LINE__); return; - case PROTOCOL_BINARY_CMD_GETKQ: fprintf(stderr, "%s:%d PROTOCOL_BINARY_CMD_GETKQ\n", __FILE__, __LINE__); return; - case PROTOCOL_BINARY_CMD_APPEND: fprintf(stderr, "%s:%d PROTOCOL_BINARY_CMD_APPEND\n", __FILE__, __LINE__); return; - case PROTOCOL_BINARY_CMD_PREPEND: fprintf(stderr, "%s:%d PROTOCOL_BINARY_CMD_PREPEND\n", __FILE__, __LINE__); return; - case PROTOCOL_BINARY_CMD_STAT: fprintf(stderr, "%s:%d PROTOCOL_BINARY_CMD_STAT\n", __FILE__, __LINE__); return; - case PROTOCOL_BINARY_CMD_SETQ: fprintf(stderr, "%s:%d PROTOCOL_BINARY_CMD_SETQ\n", __FILE__, __LINE__); return; - case PROTOCOL_BINARY_CMD_ADDQ: fprintf(stderr, "%s:%d PROTOCOL_BINARY_CMD_ADDQ\n", __FILE__, __LINE__); return; - case PROTOCOL_BINARY_CMD_REPLACEQ: fprintf(stderr, "%s:%d PROTOCOL_BINARY_CMD_REPLACEQ\n", __FILE__, __LINE__); return; - case PROTOCOL_BINARY_CMD_DELETEQ: fprintf(stderr, "%s:%d PROTOCOL_BINARY_CMD_DELETEQ\n", __FILE__, __LINE__); return; - case PROTOCOL_BINARY_CMD_INCREMENTQ: fprintf(stderr, "%s:%d PROTOCOL_BINARY_CMD_INCREMENTQ\n", __FILE__, __LINE__); return; - case PROTOCOL_BINARY_CMD_DECREMENTQ: fprintf(stderr, "%s:%d PROTOCOL_BINARY_CMD_DECREMENTQ\n", __FILE__, __LINE__); return; - case PROTOCOL_BINARY_CMD_QUITQ: fprintf(stderr, "%s:%d PROTOCOL_BINARY_CMD_QUITQ\n", __FILE__, __LINE__); return; - case PROTOCOL_BINARY_CMD_FLUSHQ: fprintf(stderr, "%s:%d PROTOCOL_BINARY_CMD_FLUSHQ\n", __FILE__, __LINE__); return; - case PROTOCOL_BINARY_CMD_APPENDQ: fprintf(stderr, "%s:%d PROTOCOL_BINARY_CMD_APPENDQ\n", __FILE__, __LINE__); return; - case PROTOCOL_BINARY_CMD_PREPENDQ: fprintf(stderr, "%s:%d PROTOCOL_BINARY_CMD_PREPENDQ\n", __FILE__, __LINE__); return; - case PROTOCOL_BINARY_CMD_VERBOSITY: fprintf(stderr, "%s:%d PROTOCOL_BINARY_CMD_VERBOSITY\n", __FILE__, __LINE__); return; - case PROTOCOL_BINARY_CMD_TOUCH: fprintf(stderr, "%s:%d PROTOCOL_BINARY_CMD_TOUCH\n", __FILE__, __LINE__); return; - case PROTOCOL_BINARY_CMD_GAT: fprintf(stderr, "%s:%d PROTOCOL_BINARY_CMD_GAT\n", __FILE__, __LINE__); return; - case PROTOCOL_BINARY_CMD_GATQ: fprintf(stderr, "%s:%d PROTOCOL_BINARY_CMD_GATQ\n", __FILE__, __LINE__); return; - case PROTOCOL_BINARY_CMD_SASL_LIST_MECHS: fprintf(stderr, "%s:%d PROTOCOL_BINARY_CMD_SASL_LIST_MECHS\n", __FILE__, __LINE__); return; - case PROTOCOL_BINARY_CMD_SASL_AUTH: fprintf(stderr, "%s:%d PROTOCOL_BINARY_CMD_SASL_AUTH\n", __FILE__, __LINE__); return; - case PROTOCOL_BINARY_CMD_SASL_STEP: fprintf(stderr, "%s:%d PROTOCOL_BINARY_CMD_SASL_STEP\n", __FILE__, __LINE__); return; - case PROTOCOL_BINARY_CMD_RGET: fprintf(stderr, "%s:%d PROTOCOL_BINARY_CMD_RGET\n", __FILE__, __LINE__); return; - case PROTOCOL_BINARY_CMD_RSET: fprintf(stderr, "%s:%d PROTOCOL_BINARY_CMD_RSET\n", __FILE__, __LINE__); return; - case PROTOCOL_BINARY_CMD_RSETQ: fprintf(stderr, "%s:%d PROTOCOL_BINARY_CMD_RSETQ\n", __FILE__, __LINE__); return; - case PROTOCOL_BINARY_CMD_RAPPEND: fprintf(stderr, "%s:%d PROTOCOL_BINARY_CMD_RAPPEND\n", __FILE__, __LINE__); return; - case PROTOCOL_BINARY_CMD_RAPPENDQ: fprintf(stderr, "%s:%d PROTOCOL_BINARY_CMD_RAPPENDQ\n", __FILE__, __LINE__); return; - case PROTOCOL_BINARY_CMD_RPREPEND: fprintf(stderr, "%s:%d PROTOCOL_BINARY_CMD_RPREPEND\n", __FILE__, __LINE__); return; - case PROTOCOL_BINARY_CMD_RPREPENDQ: fprintf(stderr, "%s:%d PROTOCOL_BINARY_CMD_RPREPENDQ\n", __FILE__, __LINE__); return; - case PROTOCOL_BINARY_CMD_RDELETE: fprintf(stderr, "%s:%d PROTOCOL_BINARY_CMD_RDELETE\n", __FILE__, __LINE__); return; - case PROTOCOL_BINARY_CMD_RDELETEQ: fprintf(stderr, "%s:%d PROTOCOL_BINARY_CMD_RDELETEQ\n", __FILE__, __LINE__); return; - case PROTOCOL_BINARY_CMD_RINCR: fprintf(stderr, "%s:%d PROTOCOL_BINARY_CMD_RINCR\n", __FILE__, __LINE__); return; - case PROTOCOL_BINARY_CMD_RINCRQ: fprintf(stderr, "%s:%d PROTOCOL_BINARY_CMD_RINCRQ\n", __FILE__, __LINE__); return; - case PROTOCOL_BINARY_CMD_RDECR: fprintf(stderr, "%s:%d PROTOCOL_BINARY_CMD_RDECR\n", __FILE__, __LINE__); return; - case PROTOCOL_BINARY_CMD_RDECRQ: fprintf(stderr, "%s:%d PROTOCOL_BINARY_CMD_RDECRQ\n", __FILE__, __LINE__); return; - case PROTOCOL_BINARY_CMD_SET_VBUCKET: fprintf(stderr, "%s:%d PROTOCOL_BINARY_CMD_SET_VBUCKET\n", __FILE__, __LINE__); return; - case PROTOCOL_BINARY_CMD_GET_VBUCKET: fprintf(stderr, "%s:%d PROTOCOL_BINARY_CMD_GET_VBUCKET\n", __FILE__, __LINE__); return; - case PROTOCOL_BINARY_CMD_DEL_VBUCKET: fprintf(stderr, "%s:%d PROTOCOL_BINARY_CMD_DEL_VBUCKET\n", __FILE__, __LINE__); return; - case PROTOCOL_BINARY_CMD_TAP_CONNECT: fprintf(stderr, "%s:%d PROTOCOL_BINARY_CMD_TAP_CONNECT\n", __FILE__, __LINE__); return; - case PROTOCOL_BINARY_CMD_TAP_MUTATION: fprintf(stderr, "%s:%d PROTOCOL_BINARY_CMD_TAP_MUTATION\n", __FILE__, __LINE__); return; - case PROTOCOL_BINARY_CMD_TAP_DELETE: fprintf(stderr, "%s:%d PROTOCOL_BINARY_CMD_TAP_DELETE\n", __FILE__, __LINE__); return; - case PROTOCOL_BINARY_CMD_TAP_FLUSH: fprintf(stderr, "%s:%d PROTOCOL_BINARY_CMD_TAP_FLUSH\n", __FILE__, __LINE__); return; - case PROTOCOL_BINARY_CMD_TAP_OPAQUE: fprintf(stderr, "%s:%d PROTOCOL_BINARY_CMD_TAP_OPAQUE\n", __FILE__, __LINE__); return; - case PROTOCOL_BINARY_CMD_TAP_VBUCKET_SET: fprintf(stderr, "%s:%d PROTOCOL_BINARY_CMD_TAP_VBUCKET_SET\n", __FILE__, __LINE__); return; - case PROTOCOL_BINARY_CMD_TAP_CHECKPOINT_START: fprintf(stderr, "%s:%d PROTOCOL_BINARY_CMD_TAP_CHECKPOINT_START\n", __FILE__, __LINE__); return; - case PROTOCOL_BINARY_CMD_TAP_CHECKPOINT_END: fprintf(stderr, "%s:%d PROTOCOL_BINARY_CMD_TAP_CHECKPOINT_END\n", __FILE__, __LINE__); return; - case PROTOCOL_BINARY_CMD_LAST_RESERVED: fprintf(stderr, "%s:%d PROTOCOL_BINARY_CMD_LAST_RESERVED\n", __FILE__, __LINE__); return; - case PROTOCOL_BINARY_CMD_GATK: fprintf(stderr, "%s:%d PROTOCOL_BINARY_CMD_GATK\n", __FILE__, __LINE__); return; - case PROTOCOL_BINARY_CMD_GATKQ: fprintf(stderr, "%s:%d PROTOCOL_BINARY_CMD_GATKQ\n", __FILE__, __LINE__); return; - case PROTOCOL_BINARY_CMD_SCRUB: fprintf(stderr, "%s:%d PROTOCOL_BINARY_CMD_SCRUB\n", __FILE__, __LINE__); return; - default: - abort(); - } -} - -/* - * Version 0 of the interface is really low level and protocol specific, - * while the version 1 of the interface is more API focused. We need a - * way to translate between the command codes on the wire and the - * application level interface in V1, so let's just use the V0 of the - * interface as a map instead of creating a huuuge switch :-) - */ - -/** - * Callback for the GET/GETQ/GETK and GETKQ responses - * @param cookie client identifier - * @param key the key for the item - * @param keylen the length of the key - * @param body the length of the body - * @param bodylen the length of the body - * @param flags the flags for the item - * @param cas the CAS id for the item - */ -static protocol_binary_response_status get_response_handler(const void *cookie, - const void *key, - uint16_t keylen, - const void *body, - uint32_t bodylen, - uint32_t flags, - uint64_t cas) -{ - memcached_protocol_client_st *client= (void*)cookie; - uint8_t opcode= client->current_command->request.opcode; - - if (opcode == PROTOCOL_BINARY_CMD_GET || opcode == PROTOCOL_BINARY_CMD_GETQ) - { - keylen= 0; - } - - protocol_binary_response_get response= { - .message.header.response= { - .magic= PROTOCOL_BINARY_RES, - .opcode= opcode, - .status= htons(PROTOCOL_BINARY_RESPONSE_SUCCESS), - .opaque= client->current_command->request.opaque, - .cas= memcached_htonll(cas), - .keylen= htons(keylen), - .extlen= 4, - .bodylen= htonl(bodylen + keylen + 4), - }, - }; - - response.message.body.flags= htonl(flags); - - protocol_binary_response_status rval; - const protocol_binary_response_status success= PROTOCOL_BINARY_RESPONSE_SUCCESS; - if ((rval= client->root->spool(client, response.bytes, sizeof(response.bytes))) != success || - (rval= client->root->spool(client, key, keylen)) != success || - (rval= client->root->spool(client, body, bodylen)) != success) - { - return rval; - } - - return PROTOCOL_BINARY_RESPONSE_SUCCESS; -} - -/** - * Callback for the STAT responses - * @param cookie client identifier - * @param key the key for the item - * @param keylen the length of the key - * @param body the length of the body - * @param bodylen the length of the body - */ -static protocol_binary_response_status stat_response_handler(const void *cookie, - const void *key, - uint16_t keylen, - const void *body, - uint32_t bodylen) -{ - - memcached_protocol_client_st *client= (void*)cookie; - - protocol_binary_response_no_extras response= { - .message.header.response= { - .magic= PROTOCOL_BINARY_RES, - .opcode= client->current_command->request.opcode, - .status= htons(PROTOCOL_BINARY_RESPONSE_SUCCESS), - .opaque= client->current_command->request.opaque, - .keylen= htons(keylen), - .bodylen= htonl(bodylen + keylen), - .cas= 0 - }, - }; - - protocol_binary_response_status rval; - const protocol_binary_response_status success= PROTOCOL_BINARY_RESPONSE_SUCCESS; - if ((rval= client->root->spool(client, response.bytes, sizeof(response.bytes))) != success || - (rval= client->root->spool(client, key, keylen)) != success || - (rval= client->root->spool(client, body, bodylen)) != success) - { - return rval; - } - - return PROTOCOL_BINARY_RESPONSE_SUCCESS; -} - -/** - * Callback for the VERSION responses - * @param cookie client identifier - * @param text the length of the body - * @param textlen the length of the body - */ -static protocol_binary_response_status version_response_handler(const void *cookie, - const void *text, - uint32_t textlen) -{ - - memcached_protocol_client_st *client= (void*)cookie; - - protocol_binary_response_no_extras response= { - .message.header.response= { - .magic= PROTOCOL_BINARY_RES, - .opcode= client->current_command->request.opcode, - .status= htons(PROTOCOL_BINARY_RESPONSE_SUCCESS), - .opaque= client->current_command->request.opaque, - .bodylen= htonl(textlen), - .cas= 0 - }, - }; - - protocol_binary_response_status rval; - const protocol_binary_response_status success= PROTOCOL_BINARY_RESPONSE_SUCCESS; - if ((rval= client->root->spool(client, response.bytes, sizeof(response.bytes))) != success || - (rval= client->root->spool(client, text, textlen)) != success) - { - return rval; - } - - return PROTOCOL_BINARY_RESPONSE_SUCCESS; -} - -/** - * Callback for ADD and ADDQ - * @param cookie the calling client - * @param header the add/addq command - * @param response_handler not used - * @return the result of the operation - */ -static protocol_binary_response_status -add_command_handler(const void *cookie, - protocol_binary_request_header *header, - memcached_binary_protocol_raw_response_handler response_handler) -{ - protocol_binary_response_status rval; - - memcached_protocol_client_st *client= (void*)cookie; - if (client->root->callback->interface.v1.add != NULL) - { - uint16_t keylen= ntohs(header->request.keylen); - uint32_t datalen= ntohl(header->request.bodylen) - keylen - 8; - protocol_binary_request_add *request= (void*)header; - uint32_t flags= ntohl(request->message.body.flags); - uint32_t timeout= ntohl(request->message.body.expiration); - char *key= ((char*)header) + sizeof(*header) + 8; - char *data= key + keylen; - uint64_t cas; - - rval= client->root->callback->interface.v1.add(cookie, key, keylen, - data, datalen, flags, - timeout, &cas); - - if (rval == PROTOCOL_BINARY_RESPONSE_SUCCESS && - header->request.opcode == PROTOCOL_BINARY_CMD_ADD) - { - /* Send a positive request */ - protocol_binary_response_no_extras response= { - .message= { - .header.response= { - .magic= PROTOCOL_BINARY_RES, - .opcode= PROTOCOL_BINARY_CMD_ADD, - .status= htons(PROTOCOL_BINARY_RESPONSE_SUCCESS), - .opaque= header->request.opaque, - .cas= memcached_ntohll(cas) - } - } - }; - rval= response_handler(cookie, header, (void*)&response); - } - } - else - { - rval= PROTOCOL_BINARY_RESPONSE_UNKNOWN_COMMAND; - } - - return rval; -} - -/** - * Callback for DECREMENT and DECREMENTQ - * @param cookie the calling client - * @param header the command - * @param response_handler not used - * @return the result of the operation - */ -static protocol_binary_response_status -decrement_command_handler(const void *cookie, - protocol_binary_request_header *header, - memcached_binary_protocol_raw_response_handler response_handler) -{ - (void)response_handler; - protocol_binary_response_status rval; - - memcached_protocol_client_st *client= (void*)cookie; - if (client->root->callback->interface.v1.decrement != NULL) - { - uint16_t keylen= ntohs(header->request.keylen); - protocol_binary_request_decr *request= (void*)header; - uint64_t init= memcached_ntohll(request->message.body.initial); - uint64_t delta= memcached_ntohll(request->message.body.delta); - uint32_t timeout= ntohl(request->message.body.expiration); - void *key= request->bytes + sizeof(request->bytes); - uint64_t result; - uint64_t cas; - - rval= client->root->callback->interface.v1.decrement(cookie, key, keylen, - delta, init, timeout, - &result, &cas); - if (rval == PROTOCOL_BINARY_RESPONSE_SUCCESS && - header->request.opcode == PROTOCOL_BINARY_CMD_DECREMENT) - { - /* Send a positive request */ - protocol_binary_response_decr response= { - .message= { - .header.response= { - .magic= PROTOCOL_BINARY_RES, - .opcode= PROTOCOL_BINARY_CMD_DECREMENT, - .status= htons(PROTOCOL_BINARY_RESPONSE_SUCCESS), - .opaque= header->request.opaque, - .cas= memcached_ntohll(cas), - .bodylen= htonl(8) - }, - .body.value= memcached_htonll(result) - } - }; - rval= response_handler(cookie, header, (void*)&response); - } - } - else - { - rval= PROTOCOL_BINARY_RESPONSE_UNKNOWN_COMMAND; - } - - return rval; -} - -/** - * Callback for DELETE and DELETEQ - * @param cookie the calling client - * @param header the command - * @param response_handler not used - * @return the result of the operation - */ -static protocol_binary_response_status delete_command_handler(const void *cookie, - protocol_binary_request_header *header, - memcached_binary_protocol_raw_response_handler response_handler) -{ - (void)response_handler; - protocol_binary_response_status rval; - - memcached_protocol_client_st *client= (void*)cookie; - if (client->root->callback->interface.v1.delete_object != NULL) - { - uint16_t keylen= ntohs(header->request.keylen); - void *key= (header +1); - uint64_t cas= memcached_ntohll(header->request.cas); - rval= client->root->callback->interface.v1.delete_object(cookie, key, keylen, cas); - if (rval == PROTOCOL_BINARY_RESPONSE_SUCCESS && - header->request.opcode == PROTOCOL_BINARY_CMD_DELETE) - { - /* Send a positive request */ - protocol_binary_response_no_extras response= { - .message= { - .header.response= { - .magic= PROTOCOL_BINARY_RES, - .opcode= PROTOCOL_BINARY_CMD_DELETE, - .status= htons(PROTOCOL_BINARY_RESPONSE_SUCCESS), - .opaque= header->request.opaque, - } - } - }; - rval= response_handler(cookie, header, (void*)&response); - } - } - else - { - rval= PROTOCOL_BINARY_RESPONSE_UNKNOWN_COMMAND; - } - - return rval; -} - -/** - * Callback for FLUSH and FLUSHQ - * @param cookie the calling client - * @param header the command - * @param response_handler not used - * @return the result of the operation - */ -static protocol_binary_response_status -flush_command_handler(const void *cookie, - protocol_binary_request_header *header, - memcached_binary_protocol_raw_response_handler response_handler) -{ - (void)response_handler; - protocol_binary_response_status rval; - - memcached_protocol_client_st *client= (void*)cookie; - if (client->root->callback->interface.v1.flush_object != NULL) - { - protocol_binary_request_flush *flush_object= (void*)header; - uint32_t timeout= 0; - if (htonl(header->request.bodylen) == 4) - { - timeout= ntohl(flush_object->message.body.expiration); - } - - rval= client->root->callback->interface.v1.flush_object(cookie, timeout); - if (rval == PROTOCOL_BINARY_RESPONSE_SUCCESS && - header->request.opcode == PROTOCOL_BINARY_CMD_FLUSH) - { - /* Send a positive request */ - protocol_binary_response_no_extras response= { - .message= { - .header.response= { - .magic= PROTOCOL_BINARY_RES, - .opcode= PROTOCOL_BINARY_CMD_FLUSH, - .status= htons(PROTOCOL_BINARY_RESPONSE_SUCCESS), - .opaque= header->request.opaque, - } - } - }; - rval= response_handler(cookie, header, (void*)&response); - } - } - else - { - rval= PROTOCOL_BINARY_RESPONSE_UNKNOWN_COMMAND; - } - - return rval; -} - -/** - * Callback for GET, GETK, GETQ, GETKQ - * @param cookie the calling client - * @param header the command - * @param response_handler not used - * @return the result of the operation - */ -static protocol_binary_response_status -get_command_handler(const void *cookie, - protocol_binary_request_header *header, - memcached_binary_protocol_raw_response_handler response_handler) -{ - (void)response_handler; - protocol_binary_response_status rval; - - memcached_protocol_client_st *client= (void*)cookie; - if (client->root->callback->interface.v1.get != NULL) - { - uint16_t keylen= ntohs(header->request.keylen); - void *key= (header + 1); - rval= client->root->callback->interface.v1.get(cookie, key, keylen, - get_response_handler); - - if (rval == PROTOCOL_BINARY_RESPONSE_KEY_ENOENT && - (header->request.opcode == PROTOCOL_BINARY_CMD_GETQ || - header->request.opcode == PROTOCOL_BINARY_CMD_GETKQ)) - { - /* Quiet commands shouldn't respond on cache misses */ - rval= PROTOCOL_BINARY_RESPONSE_SUCCESS; - } - } - else - { - rval= PROTOCOL_BINARY_RESPONSE_UNKNOWN_COMMAND; - } - - return rval; -} - -/** - * Callback for INCREMENT and INCREMENTQ - * @param cookie the calling client - * @param header the command - * @param response_handler not used - * @return the result of the operation - */ -static protocol_binary_response_status -increment_command_handler(const void *cookie, - protocol_binary_request_header *header, - memcached_binary_protocol_raw_response_handler response_handler) -{ - (void)response_handler; - protocol_binary_response_status rval; - - memcached_protocol_client_st *client= (void*)cookie; - if (client->root->callback->interface.v1.increment != NULL) - { - uint16_t keylen= ntohs(header->request.keylen); - protocol_binary_request_incr *request= (void*)header; - uint64_t init= memcached_ntohll(request->message.body.initial); - uint64_t delta= memcached_ntohll(request->message.body.delta); - uint32_t timeout= ntohl(request->message.body.expiration); - void *key= request->bytes + sizeof(request->bytes); - uint64_t cas; - uint64_t result; - - rval= client->root->callback->interface.v1.increment(cookie, key, keylen, - delta, init, timeout, - &result, &cas); - if (rval == PROTOCOL_BINARY_RESPONSE_SUCCESS && - header->request.opcode == PROTOCOL_BINARY_CMD_INCREMENT) - { - /* Send a positive request */ - protocol_binary_response_incr response= { - .message= { - .header.response= { - .magic= PROTOCOL_BINARY_RES, - .opcode= PROTOCOL_BINARY_CMD_INCREMENT, - .status= htons(PROTOCOL_BINARY_RESPONSE_SUCCESS), - .opaque= header->request.opaque, - .cas= memcached_ntohll(cas), - .bodylen= htonl(8) - }, - .body.value= memcached_htonll(result) - } - }; - - rval= response_handler(cookie, header, (void*)&response); - } - } - else - { - rval= PROTOCOL_BINARY_RESPONSE_UNKNOWN_COMMAND; - } - - return rval; -} - -/** - * Callback for noop. Inform the v1 interface about the noop packet, and - * create and send a packet back to the client - * - * @param cookie the calling client - * @param header the command - * @param response_handler the response handler - * @return the result of the operation - */ -static protocol_binary_response_status -noop_command_handler(const void *cookie, - protocol_binary_request_header *header, - memcached_binary_protocol_raw_response_handler response_handler) -{ - memcached_protocol_client_st *client= (void*)cookie; - if (client->root->callback->interface.v1.noop != NULL) - { - client->root->callback->interface.v1.noop(cookie); - } - - protocol_binary_response_no_extras response= { - .message= { - .header.response= { - .magic= PROTOCOL_BINARY_RES, - .opcode= PROTOCOL_BINARY_CMD_NOOP, - .status= htons(PROTOCOL_BINARY_RESPONSE_SUCCESS), - .opaque= header->request.opaque, - } - } - }; - - return response_handler(cookie, header, (void*)&response); -} - -/** - * Callback for APPEND and APPENDQ - * @param cookie the calling client - * @param header the command - * @param response_handler not used - * @return the result of the operation - */ -static protocol_binary_response_status -append_command_handler(const void *cookie, - protocol_binary_request_header *header, - memcached_binary_protocol_raw_response_handler response_handler) -{ - (void)response_handler; - protocol_binary_response_status rval; - - memcached_protocol_client_st *client= (void*)cookie; - if (client->root->callback->interface.v1.append != NULL) - { - uint16_t keylen= ntohs(header->request.keylen); - uint32_t datalen= ntohl(header->request.bodylen) - keylen; - char *key= (void*)(header +1); - char *data= key +keylen; - uint64_t cas= memcached_ntohll(header->request.cas); - uint64_t result_cas; - - rval= client->root->callback->interface.v1.append(cookie, key, keylen, - data, datalen, cas, - &result_cas); - if (rval == PROTOCOL_BINARY_RESPONSE_SUCCESS && - header->request.opcode == PROTOCOL_BINARY_CMD_APPEND) - { - /* Send a positive request */ - protocol_binary_response_no_extras response= { - .message= { - .header.response= { - .magic= PROTOCOL_BINARY_RES, - .opcode= PROTOCOL_BINARY_CMD_APPEND, - .status= htons(PROTOCOL_BINARY_RESPONSE_SUCCESS), - .opaque= header->request.opaque, - .cas= memcached_ntohll(result_cas), - }, - } - }; - rval= response_handler(cookie, header, (void*)&response); - } - } - else - { - rval= PROTOCOL_BINARY_RESPONSE_UNKNOWN_COMMAND; - } - - return rval; -} - -/** - * Callback for PREPEND and PREPENDQ - * @param cookie the calling client - * @param header the command - * @param response_handler not used - * @return the result of the operation - */ -static protocol_binary_response_status -prepend_command_handler(const void *cookie, - protocol_binary_request_header *header, - memcached_binary_protocol_raw_response_handler response_handler) -{ - (void)response_handler; - protocol_binary_response_status rval; - - memcached_protocol_client_st *client= (void*)cookie; - if (client->root->callback->interface.v1.prepend != NULL) - { - uint16_t keylen= ntohs(header->request.keylen); - uint32_t datalen= ntohl(header->request.bodylen) - keylen; - char *key= (char*)(header + 1); - char *data= key + keylen; - uint64_t cas= memcached_ntohll(header->request.cas); - uint64_t result_cas; - rval= client->root->callback->interface.v1.prepend(cookie, key, keylen, - data, datalen, cas, - &result_cas); - if (rval == PROTOCOL_BINARY_RESPONSE_SUCCESS && - header->request.opcode == PROTOCOL_BINARY_CMD_PREPEND) - { - /* Send a positive request */ - protocol_binary_response_no_extras response= { - .message= { - .header.response= { - .magic= PROTOCOL_BINARY_RES, - .opcode= PROTOCOL_BINARY_CMD_PREPEND, - .status= htons(PROTOCOL_BINARY_RESPONSE_SUCCESS), - .opaque= header->request.opaque, - .cas= memcached_ntohll(result_cas), - }, - } - }; - rval= response_handler(cookie, header, (void*)&response); - } - } - else - { - rval= PROTOCOL_BINARY_RESPONSE_UNKNOWN_COMMAND; - } - - return rval; -} - -/** - * Callback for QUIT and QUITQ. Notify the client and shut down the connection - * @param cookie the calling client - * @param header the command - * @param response_handler not used - * @return the result of the operation - */ -static protocol_binary_response_status -quit_command_handler(const void *cookie, - protocol_binary_request_header *header, - memcached_binary_protocol_raw_response_handler response_handler) -{ - memcached_protocol_client_st *client= (void*)cookie; - if (client->root->callback->interface.v1.quit != NULL) - { - client->root->callback->interface.v1.quit(cookie); - } - - protocol_binary_response_no_extras response= { - .message= { - .header.response= { - .magic= PROTOCOL_BINARY_RES, - .opcode= PROTOCOL_BINARY_CMD_QUIT, - .status= htons(PROTOCOL_BINARY_RESPONSE_SUCCESS), - .opaque= header->request.opaque - } - } - }; - - if (header->request.opcode == PROTOCOL_BINARY_CMD_QUIT) - { - response_handler(cookie, header, (void*)&response); - } - - /* I need a better way to signal to close the connection */ - return PROTOCOL_BINARY_RESPONSE_EINTERNAL; -} - -/** - * Callback for REPLACE and REPLACEQ - * @param cookie the calling client - * @param header the command - * @param response_handler not used - * @return the result of the operation - */ -static protocol_binary_response_status -replace_command_handler(const void *cookie, - protocol_binary_request_header *header, - memcached_binary_protocol_raw_response_handler response_handler) -{ - (void)response_handler; - protocol_binary_response_status rval; - - memcached_protocol_client_st *client= (void*)cookie; - if (client->root->callback->interface.v1.replace != NULL) - { - uint16_t keylen= ntohs(header->request.keylen); - uint32_t datalen= ntohl(header->request.bodylen) - keylen - 8; - protocol_binary_request_replace *request= (void*)header; - uint32_t flags= ntohl(request->message.body.flags); - uint32_t timeout= ntohl(request->message.body.expiration); - char *key= ((char*)header) + sizeof(*header) + 8; - char *data= key + keylen; - uint64_t cas= memcached_ntohll(header->request.cas); - uint64_t result_cas; - - rval= client->root->callback->interface.v1.replace(cookie, key, keylen, - data, datalen, flags, - timeout, cas, - &result_cas); - if (rval == PROTOCOL_BINARY_RESPONSE_SUCCESS && - header->request.opcode == PROTOCOL_BINARY_CMD_REPLACE) - { - /* Send a positive request */ - protocol_binary_response_no_extras response= { - .message= { - .header.response= { - .magic= PROTOCOL_BINARY_RES, - .opcode= PROTOCOL_BINARY_CMD_REPLACE, - .status= htons(PROTOCOL_BINARY_RESPONSE_SUCCESS), - .opaque= header->request.opaque, - .cas= memcached_ntohll(result_cas), - }, - } - }; - rval= response_handler(cookie, header, (void*)&response); - } - } - else - { - rval= PROTOCOL_BINARY_RESPONSE_UNKNOWN_COMMAND; - } - - return rval; -} - -/** - * Callback for SET and SETQ - * @param cookie the calling client - * @param header the command - * @param response_handler not used - * @return the result of the operation - */ -static protocol_binary_response_status set_command_handler(const void *cookie, - protocol_binary_request_header *header, - memcached_binary_protocol_raw_response_handler response_handler) -{ - (void)response_handler; - protocol_binary_response_status rval; - - memcached_protocol_client_st *client= (void*)cookie; - if (client->root->callback->interface.v1.set != NULL) - { - uint16_t keylen= ntohs(header->request.keylen); - uint32_t datalen= ntohl(header->request.bodylen) - keylen - 8; - protocol_binary_request_replace *request= (void*)header; - uint32_t flags= ntohl(request->message.body.flags); - uint32_t timeout= ntohl(request->message.body.expiration); - char *key= ((char*)header) + sizeof(*header) + 8; - char *data= key + keylen; - uint64_t cas= memcached_ntohll(header->request.cas); - uint64_t result_cas; - - - rval= client->root->callback->interface.v1.set(cookie, key, keylen, - data, datalen, flags, - timeout, cas, &result_cas); - if (rval == PROTOCOL_BINARY_RESPONSE_SUCCESS && - header->request.opcode == PROTOCOL_BINARY_CMD_SET) - { - /* Send a positive request */ - protocol_binary_response_no_extras response= { - .message= { - .header.response= { - .magic= PROTOCOL_BINARY_RES, - .opcode= PROTOCOL_BINARY_CMD_SET, - .status= htons(PROTOCOL_BINARY_RESPONSE_SUCCESS), - .opaque= header->request.opaque, - .cas= memcached_ntohll(result_cas), - }, - } - }; - rval= response_handler(cookie, header, (void*)&response); - } - } - else - { - rval= PROTOCOL_BINARY_RESPONSE_UNKNOWN_COMMAND; - } - - return rval; -} - -/** - * Callback for STAT - * @param cookie the calling client - * @param header the command - * @param response_handler not used - * @return the result of the operation - */ -static protocol_binary_response_status -stat_command_handler(const void *cookie, - protocol_binary_request_header *header, - memcached_binary_protocol_raw_response_handler response_handler) -{ - (void)response_handler; - protocol_binary_response_status rval; - - memcached_protocol_client_st *client= (void*)cookie; - if (client->root->callback->interface.v1.stat != NULL) - { - uint16_t keylen= ntohs(header->request.keylen); - - rval= client->root->callback->interface.v1.stat(cookie, - (void*)(header + 1), - keylen, - stat_response_handler); - } - else - { - rval= PROTOCOL_BINARY_RESPONSE_UNKNOWN_COMMAND; - } - - return rval; -} - -/** - * Callback for VERSION - * @param cookie the calling client - * @param header the command - * @param response_handler not used - * @return the result of the operation - */ -static protocol_binary_response_status -version_command_handler(const void *cookie, - protocol_binary_request_header *header, - memcached_binary_protocol_raw_response_handler response_handler) -{ - (void)response_handler; - (void)header; - protocol_binary_response_status rval; - - memcached_protocol_client_st *client= (void*)cookie; - if (client->root->callback->interface.v1.version != NULL) - { - rval= client->root->callback->interface.v1.version(cookie, - version_response_handler); - } - else - { - rval= PROTOCOL_BINARY_RESPONSE_UNKNOWN_COMMAND; - } - - return rval; -} - -/** - * The map to remap between the com codes and the v1 logical setting - */ -static memcached_binary_protocol_command_handler comcode_v0_v1_remap[256]= { - [PROTOCOL_BINARY_CMD_ADDQ]= add_command_handler, - [PROTOCOL_BINARY_CMD_ADD]= add_command_handler, - [PROTOCOL_BINARY_CMD_APPENDQ]= append_command_handler, - [PROTOCOL_BINARY_CMD_APPEND]= append_command_handler, - [PROTOCOL_BINARY_CMD_DECREMENTQ]= decrement_command_handler, - [PROTOCOL_BINARY_CMD_DECREMENT]= decrement_command_handler, - [PROTOCOL_BINARY_CMD_DELETEQ]= delete_command_handler, - [PROTOCOL_BINARY_CMD_DELETE]= delete_command_handler, - [PROTOCOL_BINARY_CMD_FLUSHQ]= flush_command_handler, - [PROTOCOL_BINARY_CMD_FLUSH]= flush_command_handler, - [PROTOCOL_BINARY_CMD_GETKQ]= get_command_handler, - [PROTOCOL_BINARY_CMD_GETK]= get_command_handler, - [PROTOCOL_BINARY_CMD_GETQ]= get_command_handler, - [PROTOCOL_BINARY_CMD_GET]= get_command_handler, - [PROTOCOL_BINARY_CMD_INCREMENTQ]= increment_command_handler, - [PROTOCOL_BINARY_CMD_INCREMENT]= increment_command_handler, - [PROTOCOL_BINARY_CMD_NOOP]= noop_command_handler, - [PROTOCOL_BINARY_CMD_PREPENDQ]= prepend_command_handler, - [PROTOCOL_BINARY_CMD_PREPEND]= prepend_command_handler, - [PROTOCOL_BINARY_CMD_QUITQ]= quit_command_handler, - [PROTOCOL_BINARY_CMD_QUIT]= quit_command_handler, - [PROTOCOL_BINARY_CMD_REPLACEQ]= replace_command_handler, - [PROTOCOL_BINARY_CMD_REPLACE]= replace_command_handler, - [PROTOCOL_BINARY_CMD_SETQ]= set_command_handler, - [PROTOCOL_BINARY_CMD_SET]= set_command_handler, - [PROTOCOL_BINARY_CMD_STAT]= stat_command_handler, - [PROTOCOL_BINARY_CMD_VERSION]= version_command_handler, -}; - -/** - * Try to execute a command. Fire the pre/post functions and the specialized - * handler function if it's set. If not, the unknown probe should be fired - * if it's present. - * @param client the client connection to operate on - * @param header the command to execute - * @return true if success or false if a fatal error occured so that the - * connection should be shut down. - */ -static protocol_binary_response_status execute_command(memcached_protocol_client_st *client, protocol_binary_request_header *header) -{ - if (client->root->pedantic && - memcached_binary_protocol_pedantic_check_request(header)) - { - /* @todo return invalid command packet */ - } - - /* we got all data available, execute the callback! */ - if (client->root->callback->pre_execute != NULL) - { - client->root->callback->pre_execute(client, header); - } - - protocol_binary_response_status rval= PROTOCOL_BINARY_RESPONSE_UNKNOWN_COMMAND; - uint8_t cc= header->request.opcode; - - if (client->is_verbose) - { - print_cmd(cc); - } - - switch (client->root->callback->interface_version) - { - case 0: - if (client->root->callback->interface.v0.comcode[cc] != NULL) - { - rval= client->root->callback->interface.v0.comcode[cc](client, header, raw_response_handler); - } - break; - - case 1: - if (comcode_v0_v1_remap[cc] != NULL) - { - rval= comcode_v0_v1_remap[cc](client, header, raw_response_handler); - } - break; - - default: - /* Unknown interface. - * It should be impossible to get here so I'll just call abort - * to avoid getting a compiler warning :-) - */ - abort(); - } - - - if (rval == PROTOCOL_BINARY_RESPONSE_UNKNOWN_COMMAND && - client->root->callback->unknown != NULL) - { - rval= client->root->callback->unknown(client, header, raw_response_handler); - } - - if (rval != PROTOCOL_BINARY_RESPONSE_SUCCESS && - rval != PROTOCOL_BINARY_RESPONSE_EINTERNAL && - rval != PROTOCOL_BINARY_RESPONSE_NOT_SUPPORTED) - { - protocol_binary_response_no_extras response= { - .message= { - .header.response= { - .magic= PROTOCOL_BINARY_RES, - .opcode= cc, - .status= htons(rval), - .opaque= header->request.opaque, - }, - } - }; - rval= raw_response_handler(client, header, (void*)&response); - } - - if (client->root->callback->post_execute != NULL) - { - client->root->callback->post_execute(client, header); - } - - return rval; -} - -/* -** ********************************************************************** -** "PROTOECTED" INTERFACE -** ********************************************************************** -*/ -memcached_protocol_event_t memcached_binary_protocol_process_data(memcached_protocol_client_st *client, ssize_t *length, void **endptr) -{ - /* try to parse all of the received packets */ - protocol_binary_request_header *header; - header= (void*)client->root->input_buffer; - if (header->request.magic != (uint8_t)PROTOCOL_BINARY_REQ) - { - client->error= EINVAL; - return MEMCACHED_PROTOCOL_ERROR_EVENT; - } - ssize_t len= *length; - - while (len >= (ssize_t)sizeof(*header) && - (len >= (ssize_t)(sizeof(*header) + ntohl(header->request.bodylen)))) - { - /* I have the complete package */ - client->current_command= header; - protocol_binary_response_status rv= execute_command(client, header); - - if (rv == PROTOCOL_BINARY_RESPONSE_EINTERNAL) - { - *length= len; - *endptr= (void*)header; - return MEMCACHED_PROTOCOL_ERROR_EVENT; - } - else if (rv == PROTOCOL_BINARY_RESPONSE_NOT_SUPPORTED) - { - return MEMCACHED_PROTOCOL_PAUSE_EVENT; - } - - ssize_t total= (ssize_t)(sizeof(*header) + ntohl(header->request.bodylen)); - len -= total; - if (len > 0) - { - intptr_t ptr= (intptr_t)header; - ptr += total; - if ((ptr % 8) == 0) - { - header= (void*)ptr; - } - else - { - /* Fix alignment */ - memmove(client->root->input_buffer, (void*)ptr, (size_t)len); - header= (void*)client->root->input_buffer; - } - } - *length= len; - *endptr= (void*)header; - } - - return MEMCACHED_PROTOCOL_READ_EVENT; -} - -/* -** ********************************************************************** -** PUBLIC INTERFACE -** ********************************************************************** -*/ -memcached_binary_protocol_callback_st *memcached_binary_protocol_get_callbacks(memcached_protocol_st *instance) -{ - return instance->callback; -} - -void memcached_binary_protocol_set_callbacks(memcached_protocol_st *instance, memcached_binary_protocol_callback_st *callback) -{ - instance->callback= callback; -} - -memcached_binary_protocol_raw_response_handler memcached_binary_protocol_get_raw_response_handler(const void *cookie) -{ - (void)cookie; - return raw_response_handler; -} - -void memcached_binary_protocol_set_pedantic(memcached_protocol_st *instance, bool enable) -{ - instance->pedantic= enable; -} - -bool memcached_binary_protocol_get_pedantic(memcached_protocol_st *instance) -{ - return instance->pedantic; -} - diff --git a/libmemcachedprotocol/binary_handler.h b/libmemcachedprotocol/binary_handler.h deleted file mode 100644 index d5a74e78..00000000 --- a/libmemcachedprotocol/binary_handler.h +++ /dev/null @@ -1,47 +0,0 @@ -/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: - * - * Libmemcached library - * - * Copyright (C) 2011 Data Differential, http://datadifferential.com/ - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * - * * The names of its contributors may not be used to endorse or - * promote products derived from this software without specific prior - * written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#pragma once - -LIBMEMCACHED_LOCAL -bool memcached_binary_protocol_pedantic_check_request(const protocol_binary_request_header *request); - -LIBMEMCACHED_LOCAL -bool memcached_binary_protocol_pedantic_check_response(const protocol_binary_request_header *request, - const protocol_binary_response_header *response); - -LIBMEMCACHED_LOCAL -memcached_protocol_event_t memcached_binary_protocol_process_data(memcached_protocol_client_st *client, ssize_t *length, void **endptr); diff --git a/libmemcachedprotocol/cache.c b/libmemcachedprotocol/cache.c deleted file mode 100644 index 6240be7d..00000000 --- a/libmemcachedprotocol/cache.c +++ /dev/null @@ -1,189 +0,0 @@ -/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: - * - * Libmemcached library - * - * Copyright (C) 2011 Data Differential, http://datadifferential.com/ - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * - * * The names of its contributors may not be used to endorse or - * promote products derived from this software without specific prior - * written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -/* -*- Mode: C; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */ -#include "config.h" - -#include <stdlib.h> -#include <string.h> -#include <inttypes.h> - -#ifndef NDEBUG -#include <signal.h> -#endif - -#include <libmemcachedprotocol/common.h> - -#ifndef NDEBUG -const uint64_t redzone_pattern = 0xdeadbeefcafebabe; -int cache_error = 0; -#endif - -const size_t initial_pool_size = 64; - -cache_t* cache_create(const char *name, size_t bufsize, size_t align, - cache_constructor_t* constructor, - cache_destructor_t* destructor) { - cache_t* ret = calloc(1, sizeof(cache_t)); - size_t name_length= strlen(name); - char* nm= calloc(1, (sizeof(char) * name_length) +1); - memcpy(nm, name, name_length); - void** ptr = calloc(initial_pool_size, bufsize); - if (ret == NULL || nm == NULL || ptr == NULL || - pthread_mutex_init(&ret->mutex, NULL) == -1) { - free(ret); - free(nm); - free(ptr); - return NULL; - } - - ret->name = nm; - ret->ptr = ptr; - ret->freetotal = initial_pool_size; - ret->constructor = constructor; - ret->destructor = destructor; - -#ifndef NDEBUG - ret->bufsize = bufsize + 2 * sizeof(redzone_pattern); -#else - ret->bufsize = bufsize; -#endif - - (void)align; - - return ret; -} - -static inline void* get_object(void *ptr) { -#ifndef NDEBUG - uint64_t *pre = ptr; - return pre + 1; -#else - return ptr; -#endif -} - -void cache_destroy(cache_t *cache) { - while (cache->freecurr > 0) { - void *ptr = cache->ptr[--cache->freecurr]; - if (cache->destructor) { - cache->destructor(get_object(ptr), NULL); - } - free(ptr); - } - free(cache->name); - free(cache->ptr); - pthread_mutex_destroy(&cache->mutex); -} - -void* cache_alloc(cache_t *cache) { - void *ret; - void *object; - pthread_mutex_lock(&cache->mutex); - if (cache->freecurr > 0) { - ret = cache->ptr[--cache->freecurr]; - object = get_object(ret); - } else { - object = ret = malloc(cache->bufsize); - if (ret != NULL) { - object = get_object(ret); - - if (cache->constructor != NULL && - cache->constructor(object, NULL, 0) != 0) { - free(ret); - object = NULL; - } - } - } - pthread_mutex_unlock(&cache->mutex); - -#ifndef NDEBUG - if (object != NULL) { - /* add a simple form of buffer-check */ - uint64_t *pre = ret; - *pre = redzone_pattern; - ret = pre+1; - memcpy(((char*)ret) + cache->bufsize - (2 * sizeof(redzone_pattern)), - &redzone_pattern, sizeof(redzone_pattern)); - } -#endif - - return object; -} - -void cache_free(cache_t *cache, void *ptr) { - pthread_mutex_lock(&cache->mutex); - -#ifndef NDEBUG - /* validate redzone... */ - if (memcmp(((char*)ptr) + cache->bufsize - (2 * sizeof(redzone_pattern)), - &redzone_pattern, sizeof(redzone_pattern)) != 0) { - raise(SIGABRT); - cache_error = 1; - pthread_mutex_unlock(&cache->mutex); - return; - } - uint64_t *pre = ptr; - --pre; - if (*pre != redzone_pattern) { - raise(SIGABRT); - cache_error = -1; - pthread_mutex_unlock(&cache->mutex); - return; - } - ptr = pre; -#endif - if (cache->freecurr < cache->freetotal) { - cache->ptr[cache->freecurr++] = ptr; - } else { - /* try to enlarge free connections array */ - size_t newtotal = cache->freetotal * 2; - void **new_free = realloc(cache->ptr, sizeof(char *) * newtotal); - if (new_free) { - cache->freetotal = newtotal; - cache->ptr = new_free; - cache->ptr[cache->freecurr++] = ptr; - } else { - if (cache->destructor) { - cache->destructor(ptr, NULL); - } - free(ptr); - - } - } - pthread_mutex_unlock(&cache->mutex); -} - diff --git a/libmemcachedprotocol/cache.h b/libmemcachedprotocol/cache.h deleted file mode 100644 index 6f84feaa..00000000 --- a/libmemcachedprotocol/cache.h +++ /dev/null @@ -1,148 +0,0 @@ -/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: - * - * Libmemcached library - * - * Copyright (C) 2011 Data Differential, http://datadifferential.com/ - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * - * * The names of its contributors may not be used to endorse or - * promote products derived from this software without specific prior - * written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -/* -*- Mode: C; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */ -#pragma once - -#include <pthread.h> - -#ifdef HAVE_UMEM_H -# include <umem.h> -# define cache_t umem_cache_t -# define cache_alloc(a) umem_cache_alloc(a, UMEM_DEFAULT) -# define cache_free(a, b) umem_cache_free(a, b) -# define cache_create(a,b,c,d,e) umem_cache_create((char*)a, b, c, d, e, NULL, NULL, NULL, 0) -# define cache_destroy(a) umem_cache_destroy(a); -#else -# ifndef NDEBUG -/* may be used for debug purposes */ -extern int cache_error; -# endif - -/** - * Constructor used to initialize allocated objects - * - * @param obj pointer to the object to initialized. - * @param notused1 This parameter is currently not used. - * @param notused2 This parameter is currently not used. - * @return you should return 0, but currently this is not checked - */ -typedef int cache_constructor_t(void* obj, void* notused1, int notused2); -/** - * Destructor used to clean up allocated objects before they are - * returned to the operating system. - * - * @param obj pointer to the object to initialized. - * @param notused1 This parameter is currently not used. - * @param notused2 This parameter is currently not used. - * @return you should return 0, but currently this is not checked - */ -typedef void cache_destructor_t(void* obj, void* notused); - -/** - * Definition of the structure to keep track of the internal details of - * the cache allocator. Touching any of these variables results in - * undefined behavior. - */ -typedef struct { - /** Mutex to protect access to the structure */ - pthread_mutex_t mutex; - /** Name of the cache objects in this cache (provided by the caller) */ - char *name; - /** List of pointers to available buffers in this cache */ - void **ptr; - /** The size of each element in this cache */ - size_t bufsize; - /** The capacity of the list of elements */ - size_t freetotal; - /** The current number of free elements */ - size_t freecurr; - /** The constructor to be called each time we allocate more memory */ - cache_constructor_t* constructor; - /** The destructor to be called each time before we release memory */ - cache_destructor_t* destructor; -} cache_t; - -/** - * Create an object cache. - * - * The object cache will let you allocate objects of the same size. It is fully - * MT safe, so you may allocate objects from multiple threads without having to - * do any syncrhonization in the application code. - * - * @param name the name of the object cache. This name may be used for debug purposes - * and may help you track down what kind of object you have problems with - * (buffer overruns, leakage etc) - * @param bufsize the size of each object in the cache - * @param align the alignment requirements of the objects in the cache. - * @param constructor the function to be called to initialize memory when we need - * to allocate more memory from the os. - * @param destructor the function to be called before we release the memory back - * to the os. - * @return a handle to an object cache if successful, NULL otherwise. - */ -cache_t* cache_create(const char* name, size_t bufsize, size_t align, - cache_constructor_t* constructor, - cache_destructor_t* destructor); -/** - * Destroy an object cache. - * - * Destroy and invalidate an object cache. You should return all buffers allocated - * with cache_alloc by using cache_free before calling this function. Not doing - * so results in undefined behavior (the buffers may or may not be invalidated) - * - * @param handle the handle to the object cache to destroy. - */ -void cache_destroy(cache_t* handle); -/** - * Allocate an object from the cache. - * - * @param handle the handle to the object cache to allocate from - * @return a pointer to an initialized object from the cache, or NULL if - * the allocation cannot be satisfied. - */ -void* cache_alloc(cache_t* handle); -/** - * Return an object back to the cache. - * - * The caller should return the object in an initialized state so that - * the object may be returned in an expected state from cache_alloc. - * - * @param handle handle to the object cache to return the object to - * @param ptr pointer to the object to return. - */ -void cache_free(cache_t* handle, void* ptr); -#endif // HAVE_UMEM_H diff --git a/libmemcachedprotocol/common.h b/libmemcachedprotocol/common.h deleted file mode 100644 index 8453ccd8..00000000 --- a/libmemcachedprotocol/common.h +++ /dev/null @@ -1,162 +0,0 @@ -/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: - * - * Libmemcached library - * - * Copyright (C) 2011 Data Differential, http://datadifferential.com/ - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * - * * The names of its contributors may not be used to endorse or - * promote products derived from this software without specific prior - * written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#pragma once - -#include "config.h" -#include <assert.h> - -#include <libmemcachedprotocol-0.0/handler.h> -#include <libmemcachedprotocol/cache.h> -#include <libmemcached/byteorder.h> -#include <libmemcached/socket.hpp> - -/* - * I don't really need the following two functions as function pointers - * in the instance handle, but I don't want to put them in the global - * namespace for those linking statically (personally I don't like that, - * but some people still do). If it ever shows up as a performance thing - * I'll look into optimizing this ;-) - */ -typedef bool (*drain_func)(memcached_protocol_client_st *client); -typedef protocol_binary_response_status (*spool_func)(memcached_protocol_client_st *client, - const void *data, - size_t length); - -/** - * Definition of the per instance structure. - */ -struct memcached_protocol_st { - memcached_binary_protocol_callback_st *callback; - memcached_protocol_recv_func recv; - memcached_protocol_send_func send; - - /* - * I really don't need these as funciton pointers, but I don't want - * to clutter the namespace if someone links statically. - */ - drain_func drain; - spool_func spool; - - /* - * To avoid keeping a buffer in each client all the time I have a - * bigger buffer in the instance that I read to initially, and then - * I try to parse and execute as much from the buffer. If I wasn't able - * to process all data I'll keep that in a per-connection buffer until - * the next time I can read from the socket. - */ - uint8_t *input_buffer; - size_t input_buffer_size; - - bool pedantic; - /* @todo use multiple sized buffers */ - cache_t *buffer_cache; -}; - -struct chunk_st { - /* Pointer to the data */ - char *data; - /* The offset to the first byte into the buffer that is used */ - size_t offset; - /* The offset into the buffer for the first free byte */ - size_t nbytes; - /* The number of bytes in the buffer */ - size_t size; - /* Pointer to the next buffer in the chain */ - struct chunk_st *next; -}; - -#define CHUNK_BUFFERSIZE 2048 - -typedef memcached_protocol_event_t (*process_data)(struct memcached_protocol_client_st *client, ssize_t *length, void **endptr); - -enum ascii_cmd { - GET_CMD, - GETS_CMD, - SET_CMD, - ADD_CMD, - REPLACE_CMD, - CAS_CMD, - APPEND_CMD, - PREPEND_CMD, - DELETE_CMD, - INCR_CMD, - DECR_CMD, - STATS_CMD, - FLUSH_ALL_CMD, - VERSION_CMD, - QUIT_CMD, - VERBOSITY_CMD, - UNKNOWN_CMD -}; - -struct memcached_protocol_client_st { - bool is_verbose; - memcached_protocol_st *root; - memcached_socket_t sock; - int error; - - /* Linked list of data to send */ - struct chunk_st *output; - struct chunk_st *output_tail; - - /* - * While we process input data, this is where we spool incomplete commands - * if we need to receive more data.... - * @todo use the buffercace - */ - uint8_t *input_buffer; - size_t input_buffer_size; - size_t input_buffer_offset; - - /* The callback to the protocol handler to use (ascii or binary) */ - process_data work; - - /* - * Should the spool data discard the data to send or not? (aka noreply in - * the ascii protocol.. - */ - bool mute; - - /* Members used by the binary protocol */ - protocol_binary_request_header *current_command; - - /* Members used by the ascii protocol */ - enum ascii_cmd ascii_command; -}; - -#include "ascii_handler.h" -#include "binary_handler.h" diff --git a/libmemcachedprotocol/handler.c b/libmemcachedprotocol/handler.c deleted file mode 100644 index 59b461f6..00000000 --- a/libmemcachedprotocol/handler.c +++ /dev/null @@ -1,437 +0,0 @@ -/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: - * - * Libmemcached library - * - * Copyright (C) 2011 Data Differential, http://datadifferential.com/ - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * - * * The names of its contributors may not be used to endorse or - * promote products derived from this software without specific prior - * written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -/* -*- Mode: C; tab-width: 2; c-basic-offset: 2; indent-tabs-mode: nil -*- */ -#include <libmemcachedprotocol/common.h> - -#include <stdlib.h> -#include <sys/types.h> -#include <errno.h> -#include <stdbool.h> -#include <string.h> -#include <strings.h> -#include <ctype.h> -#include <stdio.h> - -/* -** ********************************************************************** -** INTERNAL INTERFACE -** ********************************************************************** -*/ - -/** - * The default function to receive data from the client. This function - * just wraps the recv function to receive from a socket. - * See man -s3socket recv for more information. - * - * @param cookie cookie indentifying a client, not used - * @param sock socket to read from - * @param buf the destination buffer - * @param nbytes the number of bytes to read - * @return the number of bytes transferred of -1 upon error - */ -static ssize_t default_recv(const void *cookie, - memcached_socket_t sock, - void *buf, - size_t nbytes) -{ - (void)cookie; - return recv(sock, buf, nbytes, 0); -} - -/** - * The default function to send data to the server. This function - * just wraps the send function to send through a socket. - * See man -s3socket send for more information. - * - * @param cookie cookie indentifying a client, not used - * @param sock socket to send to - * @param buf the source buffer - * @param nbytes the number of bytes to send - * @return the number of bytes transferred of -1 upon error - */ -static ssize_t default_send(const void *cookie, - memcached_socket_t fd, - const void *buf, - size_t nbytes) -{ - (void)cookie; - return send(fd, buf, nbytes, MSG_NOSIGNAL); -} - -/** - * Try to drain the output buffers without blocking - * - * @param client the client to drain - * @return false if an error occured (connection should be shut down) - * true otherwise (please note that there may be more data to - * left in the buffer to send) - */ -static bool drain_output(struct memcached_protocol_client_st *client) -{ - if (client->is_verbose) - { - fprintf(stderr, "%s:%d %s mute:%d output:%s length:%d\n", __FILE__, __LINE__, __func__, (int)client->mute, - client->output ? "yes" : "no", - client->output ? (int)(client->output->nbytes - client->output->offset) : 0); - } - - /* Do we have pending data to send? */ - while (client->output != NULL) - { - ssize_t len= client->root->send(client, - client->sock, - client->output->data + client->output->offset, - client->output->nbytes - client->output->offset); - - if (len == -1) - { - if (get_socket_errno() == EWOULDBLOCK) - { - return true; - } - else if (get_socket_errno() != EINTR) - { - client->error= get_socket_errno(); - return false; - } - } - else - { - client->output->offset += (size_t)len; - if (client->output->offset == client->output->nbytes) - { - /* This was the complete buffer */ - struct chunk_st *old= client->output; - client->output= client->output->next; - if (client->output == NULL) - { - client->output_tail= NULL; - } - cache_free(client->root->buffer_cache, old); - } - } - } - - return true; -} - -/** - * Allocate an output buffer and chain it into the output list - * - * @param client the client that needs the buffer - * @return pointer to the new chunk if the allocation succeeds, NULL otherwise - */ -static struct chunk_st *allocate_output_chunk(struct memcached_protocol_client_st *client) -{ - struct chunk_st *ret= cache_alloc(client->root->buffer_cache); - - if (ret == NULL) - { - return NULL; - } - - ret->offset= ret->nbytes= 0; - ret->next= NULL; - ret->size= CHUNK_BUFFERSIZE; - ret->data= (void*)(ret + 1); - if (client->output == NULL) - { - client->output= client->output_tail= ret; - } - else - { - client->output_tail->next= ret; - client->output_tail= ret; - } - - return ret; -} - -/** - * Spool data into the send-buffer for a client. - * - * @param client the client to spool the data for - * @param data the data to spool - * @param length the number of bytes of data to spool - * @return PROTOCOL_BINARY_RESPONSE_SUCCESS if success, - * PROTOCOL_BINARY_RESPONSE_ENOMEM if we failed to allocate memory - */ -static protocol_binary_response_status spool_output(struct memcached_protocol_client_st *client, - const void *data, - size_t length) -{ - if (client->is_verbose) - { - fprintf(stderr, "%s:%d %s mute:%d length:%d\n", __FILE__, __LINE__, __func__, (int)client->mute, (int)length); - } - - if (client->mute) - { - return PROTOCOL_BINARY_RESPONSE_SUCCESS; - } - - size_t offset= 0; - - struct chunk_st *chunk= client->output; - while (offset < length) - { - if (chunk == NULL || (chunk->size - chunk->nbytes) == 0) - { - if ((chunk= allocate_output_chunk(client)) == NULL) - { - return PROTOCOL_BINARY_RESPONSE_ENOMEM; - } - } - - size_t bulk= length - offset; - if (bulk > chunk->size - chunk->nbytes) - { - bulk= chunk->size - chunk->nbytes; - } - - memcpy(chunk->data + chunk->nbytes, data, bulk); - chunk->nbytes += bulk; - offset += bulk; - } - - return PROTOCOL_BINARY_RESPONSE_SUCCESS; -} - -/** - * Try to determine the protocol used on this connection. - * If the first byte contains the magic byte PROTOCOL_BINARY_REQ we should - * be using the binary protocol on the connection. I implemented the support - * for the ASCII protocol by wrapping into the simple interface (aka v1), - * so the implementors needs to provide an implementation of that interface - * - */ -static memcached_protocol_event_t determine_protocol(struct memcached_protocol_client_st *client, ssize_t *length, void **endptr) -{ - if (*client->root->input_buffer == (uint8_t)PROTOCOL_BINARY_REQ) - { - if (client->is_verbose) - { - fprintf(stderr, "%s:%d PROTOCOL: memcached_binary_protocol_process_data\n", __FILE__, __LINE__); - } - client->work= memcached_binary_protocol_process_data; - } - else if (client->root->callback->interface_version == 1) - { - if (client->is_verbose) - { - fprintf(stderr, "%s:%d PROTOCOL: memcached_ascii_protocol_process_data\n", __FILE__, __LINE__); - } - - /* - * The ASCII protocol can only be used if the implementors provide - * an implementation for the version 1 of the interface.. - * - * @todo I should allow the implementors to provide an implementation - * for version 0 and 1 at the same time and set the preferred - * interface to use... - */ - client->work= memcached_ascii_protocol_process_data; - } - else - { - if (client->is_verbose) - { - fprintf(stderr, "%s:%d PROTOCOL: Unsupported protocol\n", __FILE__, __LINE__); - } - - /* Let's just output a warning the way it is supposed to look like - * in the ASCII protocol... - */ - const char *err= "CLIENT_ERROR: Unsupported protocol\r\n"; - client->root->spool(client, err, strlen(err)); - client->root->drain(client); - - return MEMCACHED_PROTOCOL_ERROR_EVENT; /* Unsupported protocol */ - } - - return client->work(client, length, endptr); -} - -/* -** ********************************************************************** -** * PUBLIC INTERFACE -** * See protocol_handler.h for function description -** ********************************************************************** -*/ -struct memcached_protocol_st *memcached_protocol_create_instance(void) -{ - struct memcached_protocol_st *ret= calloc(1, sizeof(*ret)); - if (ret != NULL) - { - ret->recv= default_recv; - ret->send= default_send; - ret->drain= drain_output; - ret->spool= spool_output; - ret->input_buffer_size= 1 * 1024 * 1024; - ret->input_buffer= malloc(ret->input_buffer_size); - if (ret->input_buffer == NULL) - { - free(ret); - ret= NULL; - - return NULL; - } - - ret->buffer_cache= cache_create("protocol_handler", - CHUNK_BUFFERSIZE + sizeof(struct chunk_st), - 0, NULL, NULL); - if (ret->buffer_cache == NULL) - { - free(ret->input_buffer); - free(ret); - } - } - - return ret; -} - -void memcached_protocol_destroy_instance(struct memcached_protocol_st *instance) -{ - cache_destroy(instance->buffer_cache); - free(instance->input_buffer); - free(instance); -} - -struct memcached_protocol_client_st *memcached_protocol_create_client(struct memcached_protocol_st *instance, memcached_socket_t sock) -{ - struct memcached_protocol_client_st *ret= calloc(1, sizeof(memcached_protocol_client_st)); - if (ret != NULL) - { - ret->root= instance; - ret->sock= sock; - ret->work= determine_protocol; - } - - return ret; -} - -void memcached_protocol_client_destroy(struct memcached_protocol_client_st *client) -{ - free(client); -} - -void memcached_protocol_client_set_verbose(struct memcached_protocol_client_st *client, bool arg) -{ - if (client) - { - client->is_verbose= arg; - } -} - -memcached_protocol_event_t memcached_protocol_client_work(struct memcached_protocol_client_st *client) -{ - /* Try to send data and read from the socket */ - bool more_data= true; - do - { - ssize_t len= client->root->recv(client, - client->sock, - client->root->input_buffer + client->input_buffer_offset, - client->root->input_buffer_size - client->input_buffer_offset); - - if (len > 0) - { - /* Do we have the complete packet? */ - if (client->input_buffer_offset > 0) - { - memcpy(client->root->input_buffer, client->input_buffer, - client->input_buffer_offset); - len += (ssize_t)client->input_buffer_offset; - - /* @todo use buffer-cache! */ - free(client->input_buffer); - client->input_buffer_offset= 0; - } - - void *endptr; - memcached_protocol_event_t events= client->work(client, &len, &endptr); - if (events == MEMCACHED_PROTOCOL_ERROR_EVENT) - { - return MEMCACHED_PROTOCOL_ERROR_EVENT; - } - - if (len > 0) - { - /* save the data for later on */ - /* @todo use buffer-cache */ - client->input_buffer= malloc((size_t)len); - if (client->input_buffer == NULL) - { - client->error= ENOMEM; - return MEMCACHED_PROTOCOL_ERROR_EVENT; - } - memcpy(client->input_buffer, endptr, (size_t)len); - client->input_buffer_offset= (size_t)len; - more_data= false; - } - } - else if (len == 0) - { - /* Connection closed */ - drain_output(client); - return MEMCACHED_PROTOCOL_ERROR_EVENT; - } - else - { - if (get_socket_errno() != EWOULDBLOCK) - { - client->error= get_socket_errno(); - /* mark this client as terminated! */ - return MEMCACHED_PROTOCOL_ERROR_EVENT; - } - more_data= false; - } - } while (more_data); - - if (!drain_output(client)) - { - return MEMCACHED_PROTOCOL_ERROR_EVENT; - } - - memcached_protocol_event_t ret= MEMCACHED_PROTOCOL_READ_EVENT; - if (client->output) - { - ret|= MEMCACHED_PROTOCOL_READ_EVENT; - } - - return ret; -} diff --git a/libmemcachedprotocol/include.am b/libmemcachedprotocol/include.am deleted file mode 100644 index 33d00fe9..00000000 --- a/libmemcachedprotocol/include.am +++ /dev/null @@ -1,34 +0,0 @@ -# vim:ft=automake -# included from Top Level Makefile.am -# All paths should be given relative to the root - - -lib_LTLIBRARIES+= libmemcached/libmemcachedprotocol.la - -noinst_HEADERS+= libmemcachedprotocol/ascii_handler.h -noinst_HEADERS+= libmemcachedprotocol/binary_handler.h -noinst_HEADERS+= libmemcachedprotocol/cache.h -noinst_HEADERS+= libmemcachedprotocol/common.h - -libmemcached_libmemcachedprotocol_la_SOURCES= -libmemcached_libmemcachedprotocol_la_SOURCES+= libmemcached/byteorder.cc -libmemcached_libmemcachedprotocol_la_SOURCES+= libmemcachedprotocol/ascii_handler.c -libmemcached_libmemcachedprotocol_la_SOURCES+= libmemcachedprotocol/binary_handler.c -libmemcached_libmemcachedprotocol_la_SOURCES+= libmemcachedprotocol/cache.c -libmemcached_libmemcachedprotocol_la_SOURCES+= libmemcachedprotocol/handler.c -libmemcached_libmemcachedprotocol_la_SOURCES+= libmemcachedprotocol/pedantic.c - -libmemcached_libmemcachedprotocol_la_CFLAGS= -libmemcached_libmemcachedprotocol_la_CFLAGS+= ${AM_CFLAGS} -libmemcached_libmemcachedprotocol_la_CFLAGS+= ${NO_CONVERSION} -libmemcached_libmemcachedprotocol_la_CFLAGS+= -DBUILDING_LIBMEMCACHED -libmemcached_libmemcachedprotocol_la_CFLAGS+= ${PTHREAD_CFLAGS} - -libmemcached_libmemcachedprotocol_la_CXXFLAGS= -libmemcached_libmemcachedprotocol_la_CXXFLAGS+= ${AM_CXXFLAGS} -libmemcached_libmemcachedprotocol_la_CXXFLAGS+= -DBUILDING_LIBMEMCACHED -libmemcached_libmemcachedprotocol_la_CXXFLAGS+= ${PTHREAD_CFLAGS} - -libmemcached_libmemcachedprotocol_la_LIBADD= ${PTHREAD_LIBS} -libmemcached_libmemcachedprotocol_la_LDFLAGS= ${AM_LDFLAGS} -libmemcached_libmemcachedprotocol_la_LDFLAGS+= -version-info ${MEMCACHED_PROTOCAL_LIBRARY_VERSION} diff --git a/libmemcachedprotocol/pedantic.c b/libmemcachedprotocol/pedantic.c deleted file mode 100644 index 54a2add0..00000000 --- a/libmemcachedprotocol/pedantic.c +++ /dev/null @@ -1,237 +0,0 @@ -/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: - * - * Libmemcached library - * - * Copyright (C) 2011 Data Differential, http://datadifferential.com/ - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * - * * The names of its contributors may not be used to endorse or - * promote products derived from this software without specific prior - * written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -/* -*- Mode: C; tab-width: 2; c-basic-offset: 2; indent-tabs-mode: nil -*- */ -#include <libmemcachedprotocol/common.h> - -#include <sys/types.h> - -#define ensure(a) if (!(a)) { return false; } - -bool memcached_binary_protocol_pedantic_check_request(const protocol_binary_request_header *request) -{ - ensure(request->request.magic == PROTOCOL_BINARY_REQ); - ensure(request->request.datatype == PROTOCOL_BINARY_RAW_BYTES); - - ensure(request->bytes[6] == 0); - ensure(request->bytes[7] == 0); - - uint8_t opcode= request->request.opcode; - uint16_t keylen= ntohs(request->request.keylen); - uint8_t extlen= request->request.extlen; - uint32_t bodylen= ntohl(request->request.bodylen); - - ensure(bodylen >= (keylen + extlen)); - - switch (opcode) { - case PROTOCOL_BINARY_CMD_GET: - case PROTOCOL_BINARY_CMD_GETK: - case PROTOCOL_BINARY_CMD_GETKQ: - case PROTOCOL_BINARY_CMD_GETQ: - ensure(extlen == 0); - ensure(keylen > 0); - ensure(keylen == bodylen); - ensure(request->request.cas == 0); - break; - - case PROTOCOL_BINARY_CMD_ADD: - case PROTOCOL_BINARY_CMD_ADDQ: - /* it makes no sense to run add with a cas value */ - ensure(request->request.cas == 0); - /* FALLTHROUGH */ - case PROTOCOL_BINARY_CMD_SET: - case PROTOCOL_BINARY_CMD_SETQ: - case PROTOCOL_BINARY_CMD_REPLACE: - case PROTOCOL_BINARY_CMD_REPLACEQ: - ensure(keylen > 0); - ensure(extlen == 8); - break; - - case PROTOCOL_BINARY_CMD_DELETE: - case PROTOCOL_BINARY_CMD_DELETEQ: - ensure(extlen == 0); - ensure(keylen > 0); - ensure(keylen == bodylen); - break; - - case PROTOCOL_BINARY_CMD_INCREMENT: - case PROTOCOL_BINARY_CMD_INCREMENTQ: - case PROTOCOL_BINARY_CMD_DECREMENT: - case PROTOCOL_BINARY_CMD_DECREMENTQ: - ensure(extlen == 20); - ensure(keylen > 0); - ensure(keylen + extlen == bodylen); - break; - - case PROTOCOL_BINARY_CMD_QUIT: - case PROTOCOL_BINARY_CMD_QUITQ: - case PROTOCOL_BINARY_CMD_NOOP: - case PROTOCOL_BINARY_CMD_VERSION: - ensure(extlen == 0); - ensure(keylen == 0); - ensure(bodylen == 0); - break; - - case PROTOCOL_BINARY_CMD_FLUSH: - case PROTOCOL_BINARY_CMD_FLUSHQ: - ensure(extlen == 0 || extlen == 4); - ensure(keylen == 0); - ensure(bodylen == extlen); - break; - - case PROTOCOL_BINARY_CMD_STAT: - ensure(extlen == 0); - /* May have key, but not value */ - ensure(keylen == bodylen); - break; - - case PROTOCOL_BINARY_CMD_APPEND: - case PROTOCOL_BINARY_CMD_APPENDQ: - case PROTOCOL_BINARY_CMD_PREPEND: - case PROTOCOL_BINARY_CMD_PREPENDQ: - ensure(extlen == 0); - ensure(keylen > 0); - break; - default: - /* Unknown command */ - ; - } - - return true; -} - -bool memcached_binary_protocol_pedantic_check_response(const protocol_binary_request_header *request, - const protocol_binary_response_header *response) -{ - ensure(response->response.magic == PROTOCOL_BINARY_RES); - ensure(response->response.datatype == PROTOCOL_BINARY_RAW_BYTES); - ensure(response->response.opaque == request->request.opaque); - - uint16_t status= ntohs(response->response.status); - uint8_t opcode= response->response.opcode; - - if (status == PROTOCOL_BINARY_RESPONSE_SUCCESS) - { - switch (opcode) { - case PROTOCOL_BINARY_CMD_ADDQ: - case PROTOCOL_BINARY_CMD_APPENDQ: - case PROTOCOL_BINARY_CMD_DECREMENTQ: - case PROTOCOL_BINARY_CMD_DELETEQ: - case PROTOCOL_BINARY_CMD_FLUSHQ: - case PROTOCOL_BINARY_CMD_INCREMENTQ: - case PROTOCOL_BINARY_CMD_PREPENDQ: - case PROTOCOL_BINARY_CMD_QUITQ: - case PROTOCOL_BINARY_CMD_REPLACEQ: - case PROTOCOL_BINARY_CMD_SETQ: - /* Quiet command shouldn't return on success */ - return false; - default: - break; - } - - switch (opcode) { - case PROTOCOL_BINARY_CMD_ADD: - case PROTOCOL_BINARY_CMD_REPLACE: - case PROTOCOL_BINARY_CMD_SET: - case PROTOCOL_BINARY_CMD_APPEND: - case PROTOCOL_BINARY_CMD_PREPEND: - ensure(response->response.keylen == 0); - ensure(response->response.extlen == 0); - ensure(response->response.bodylen == 0); - ensure(response->response.cas != 0); - break; - case PROTOCOL_BINARY_CMD_FLUSH: - case PROTOCOL_BINARY_CMD_NOOP: - case PROTOCOL_BINARY_CMD_QUIT: - case PROTOCOL_BINARY_CMD_DELETE: - ensure(response->response.keylen == 0); - ensure(response->response.extlen == 0); - ensure(response->response.bodylen == 0); - ensure(response->response.cas == 0); - break; - - case PROTOCOL_BINARY_CMD_DECREMENT: - case PROTOCOL_BINARY_CMD_INCREMENT: - ensure(response->response.keylen == 0); - ensure(response->response.extlen == 0); - ensure(ntohl(response->response.bodylen) == 8); - ensure(response->response.cas != 0); - break; - - case PROTOCOL_BINARY_CMD_STAT: - ensure(response->response.extlen == 0); - /* key and value exists in all packets except in the terminating */ - ensure(response->response.cas == 0); - break; - - case PROTOCOL_BINARY_CMD_VERSION: - ensure(response->response.keylen == 0); - ensure(response->response.extlen == 0); - ensure(response->response.bodylen != 0); - ensure(response->response.cas == 0); - break; - - case PROTOCOL_BINARY_CMD_GET: - case PROTOCOL_BINARY_CMD_GETQ: - ensure(response->response.keylen == 0); - ensure(response->response.extlen == 4); - ensure(response->response.cas != 0); - break; - - case PROTOCOL_BINARY_CMD_GETK: - case PROTOCOL_BINARY_CMD_GETKQ: - ensure(response->response.keylen != 0); - ensure(response->response.extlen == 4); - ensure(response->response.cas != 0); - break; - - default: - /* Undefined command code */ - break; - } - } - else - { - ensure(response->response.cas == 0); - ensure(response->response.extlen == 0); - if (opcode != PROTOCOL_BINARY_CMD_GETK) - { - ensure(response->response.keylen == 0); - } - } - - return true; -} diff --git a/libmemcachedutil-1.0/include.am b/libmemcachedutil-1.0/include.am deleted file mode 100644 index 39a15937..00000000 --- a/libmemcachedutil-1.0/include.am +++ /dev/null @@ -1,13 +0,0 @@ -# vim:ft=automake -# included from Top Level Makefile.am -# All paths should be given relative to the root - - -nobase_include_HEADERS+= \ - libmemcachedutil-1.0/flush.h \ - libmemcachedutil-1.0/ostream.hpp \ - libmemcachedutil-1.0/pid.h \ - libmemcachedutil-1.0/ping.h \ - libmemcachedutil-1.0/pool.h \ - libmemcachedutil-1.0/util.h \ - libmemcachedutil-1.0/version.h diff --git a/libmemcachedutil-1.0/flush.h b/libmemcachedutil-1.2/flush.h index dd7e7799..dd7e7799 100644 --- a/libmemcachedutil-1.0/flush.h +++ b/libmemcachedutil-1.2/flush.h diff --git a/libmemcachedutil-1.2/include.am b/libmemcachedutil-1.2/include.am new file mode 100644 index 00000000..ef8ad0b2 --- /dev/null +++ b/libmemcachedutil-1.2/include.am @@ -0,0 +1,11 @@ +# vim:ft=automake +# included from Top Level Makefile.am +# All paths should be given relative to the root + +nobase_include_HEADERS+= libmemcachedutil-1.2/flush.h +nobase_include_HEADERS+= libmemcachedutil-1.2/ostream.hpp +nobase_include_HEADERS+= libmemcachedutil-1.2/pid.h +nobase_include_HEADERS+= libmemcachedutil-1.2/ping.h +nobase_include_HEADERS+= libmemcachedutil-1.2/pool.h +nobase_include_HEADERS+= libmemcachedutil-1.2/util.h +nobase_include_HEADERS+= libmemcachedutil-1.2/version.h diff --git a/libmemcachedutil-1.0/ostream.hpp b/libmemcachedutil-1.2/ostream.hpp index cce7bfcd..cce7bfcd 100644 --- a/libmemcachedutil-1.0/ostream.hpp +++ b/libmemcachedutil-1.2/ostream.hpp diff --git a/libmemcachedutil-1.0/pid.h b/libmemcachedutil-1.2/pid.h index 01738acc..01738acc 100644 --- a/libmemcachedutil-1.0/pid.h +++ b/libmemcachedutil-1.2/pid.h diff --git a/libmemcachedutil-1.0/ping.h b/libmemcachedutil-1.2/ping.h index faea8b2b..faea8b2b 100644 --- a/libmemcachedutil-1.0/ping.h +++ b/libmemcachedutil-1.2/ping.h diff --git a/libmemcachedutil-1.0/pool.h b/libmemcachedutil-1.2/pool.h index a11117ca..bcd7f75d 100644 --- a/libmemcachedutil-1.0/pool.h +++ b/libmemcachedutil-1.2/pool.h @@ -37,9 +37,6 @@ #pragma once - -#include <libmemcached-1.0/memcached.h> - #ifdef __cplusplus extern "C" { #endif diff --git a/libmemcachedutil-1.0/util.h b/libmemcachedutil-1.2/util.h index d3620988..9f18e39e 100644 --- a/libmemcachedutil-1.0/util.h +++ b/libmemcachedutil-1.2/util.h @@ -37,10 +37,10 @@ #pragma once -#include <libmemcached-1.0/memcached.h> +#include <libmemcached-1.2/memcached.h> -#include <libmemcachedutil-1.0/pid.h> -#include <libmemcachedutil-1.0/flush.h> -#include <libmemcachedutil-1.0/ping.h> -#include <libmemcachedutil-1.0/pool.h> -#include <libmemcachedutil-1.0/version.h> +#include <libmemcachedutil-1.2/pid.h> +#include <libmemcachedutil-1.2/flush.h> +#include <libmemcachedutil-1.2/ping.h> +#include <libmemcachedutil-1.2/pool.h> +#include <libmemcachedutil-1.2/version.h> diff --git a/libmemcachedutil-1.0/version.h b/libmemcachedutil-1.2/version.h index 372283a0..372283a0 100644 --- a/libmemcachedutil-1.0/version.h +++ b/libmemcachedutil-1.2/version.h diff --git a/libmemcachedutil/common.h b/libmemcachedutil/common.h index 5c7b59f4..6d0dc08b 100644 --- a/libmemcachedutil/common.h +++ b/libmemcachedutil/common.h @@ -2,7 +2,7 @@ * * Libmemcached Utility library * - * Copyright (C) 2011 Data Differential, http://datadifferential.com/ + * Copyright (C) 2011-2012 Data Differential, http://datadifferential.com/ * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are @@ -40,6 +40,7 @@ #include <config.h> -#include <libmemcachedutil-1.0/util.h> +#include <libmemcachedutil-1.2/util.h> + #include <libmemcached/assert.hpp> #include <libmemcached/backtrace.hpp> diff --git a/libtest/comparison.hpp b/libtest/comparison.hpp index 32dc22fa..db9cc8a7 100644 --- a/libtest/comparison.hpp +++ b/libtest/comparison.hpp @@ -39,8 +39,8 @@ #include <typeinfo> #if defined(HAVE_LIBMEMCACHED) && HAVE_LIBMEMCACHED -#include <libmemcached-1.0/memcached.h> -#include <libmemcachedutil-1.0/ostream.hpp> +#include <libmemcached-1.2/memcached.h> +#include <libmemcachedutil-1.2/ostream.hpp> #include <libtest/memcached.hpp> #endif diff --git a/libtest/memcached.cc b/libtest/memcached.cc index 37a3102e..63335bd9 100644 --- a/libtest/memcached.cc +++ b/libtest/memcached.cc @@ -37,8 +37,8 @@ #include <config.h> #include <libtest/common.h> -#include <libmemcached-1.0/memcached.h> -#include <libmemcachedutil-1.0/util.h> +#include <libmemcached-1.2/memcached.h> +#include <libmemcachedutil-1.2/util.h> using namespace libtest; diff --git a/tests/cycle.cc b/tests/cycle.cc index e18037df..904d4312 100644 --- a/tests/cycle.cc +++ b/tests/cycle.cc @@ -43,7 +43,7 @@ #include <libtest/test.hpp> using namespace libtest; -#include <libmemcached-1.0/memcached.h> +#include <libmemcached-1.2/memcached.h> static test_return_t server_startup_single_TEST(void *obj) { diff --git a/tests/failure.cc b/tests/failure.cc index b03a0433..fe96745d 100644 --- a/tests/failure.cc +++ b/tests/failure.cc @@ -39,7 +39,7 @@ /* C++ interface test */ -#include <libmemcached-1.0/memcached.hpp> +#include <libmemcached-1.2/memcached.hpp> #include <libmemcached/server_instance.h> #include <libtest/test.hpp> diff --git a/tests/libmemcached-1.0/atomsmasher.cc b/tests/libmemcached-1.0/atomsmasher.cc index 9b246b17..5a82833a 100644 --- a/tests/libmemcached-1.0/atomsmasher.cc +++ b/tests/libmemcached-1.0/atomsmasher.cc @@ -16,7 +16,7 @@ #include <libtest/test.hpp> -#include <libmemcached-1.0/memcached.h> +#include <libmemcached-1.2/memcached.h> #include <cstdio> #include <cstdlib> diff --git a/tests/libmemcached-1.0/basic.cc b/tests/libmemcached-1.0/basic.cc index 392c6778..24754270 100644 --- a/tests/libmemcached-1.0/basic.cc +++ b/tests/libmemcached-1.0/basic.cc @@ -38,7 +38,7 @@ #include <config.h> #include <libtest/test.hpp> -#include <libmemcached-1.0/memcached.h> +#include <libmemcached-1.2/memcached.h> #include "libmemcached/is.h" #include "tests/basic.h" diff --git a/tests/libmemcached-1.0/debug.cc b/tests/libmemcached-1.0/debug.cc index 6808089a..5110d199 100644 --- a/tests/libmemcached-1.0/debug.cc +++ b/tests/libmemcached-1.0/debug.cc @@ -42,7 +42,7 @@ using namespace libtest; -#include <libmemcached-1.0/memcached.h> +#include <libmemcached-1.2/memcached.h> #include <tests/debug.h> #include <tests/print.h> diff --git a/tests/libmemcached-1.0/deprecated.cc b/tests/libmemcached-1.0/deprecated.cc index c5096ff7..e0932ca5 100644 --- a/tests/libmemcached-1.0/deprecated.cc +++ b/tests/libmemcached-1.0/deprecated.cc @@ -38,7 +38,7 @@ #include <config.h> #include <libtest/test.hpp> -#include <libmemcached-1.0/memcached.h> +#include <libmemcached-1.2/memcached.h> #include <tests/deprecated.h> test_return_t server_list_null_test(memcached_st *ptr) diff --git a/tests/libmemcached-1.0/dump.cc b/tests/libmemcached-1.0/dump.cc index 27583ead..aa693f3d 100644 --- a/tests/libmemcached-1.0/dump.cc +++ b/tests/libmemcached-1.0/dump.cc @@ -41,8 +41,8 @@ #include <libtest/test.hpp> -#include <libmemcached-1.0/memcached.h> -#include <libmemcachedutil-1.0/util.h> +#include <libmemcached-1.2/memcached.h> +#include <libmemcachedutil-1.2/util.h> using namespace libtest; diff --git a/tests/libmemcached-1.0/encoding_key.cc b/tests/libmemcached-1.0/encoding_key.cc index 8d3e0dbc..dddd122a 100644 --- a/tests/libmemcached-1.0/encoding_key.cc +++ b/tests/libmemcached-1.0/encoding_key.cc @@ -38,8 +38,8 @@ #include <config.h> #include <libtest/test.hpp> -#include <libmemcached-1.0/memcached.h> -#include <libmemcachedutil-1.0/util.h> +#include <libmemcached-1.2/memcached.h> +#include <libmemcachedutil-1.2/util.h> #include "tests/libmemcached-1.0/encoding_key.h" diff --git a/tests/libmemcached-1.0/error_conditions.cc b/tests/libmemcached-1.0/error_conditions.cc index b5a05c77..18fa1883 100644 --- a/tests/libmemcached-1.0/error_conditions.cc +++ b/tests/libmemcached-1.0/error_conditions.cc @@ -40,7 +40,7 @@ #define BUILDING_LIBMEMCACHED -#include <libmemcached-1.0/memcached.h> +#include <libmemcached-1.2/memcached.h> #include "libmemcached/is.h" #include <tests/error_conditions.h> diff --git a/tests/libmemcached-1.0/generate.cc b/tests/libmemcached-1.0/generate.cc index 37f4a36e..7c19265c 100644 --- a/tests/libmemcached-1.0/generate.cc +++ b/tests/libmemcached-1.0/generate.cc @@ -38,7 +38,7 @@ #include <config.h> #include <libtest/test.hpp> -#include <libmemcachedutil-1.0/util.h> +#include <libmemcachedutil-1.2/util.h> #include <libmemcached/is.h> #include <tests/libmemcached-1.0/generate.h> diff --git a/tests/libmemcached-1.0/ketama.cc b/tests/libmemcached-1.0/ketama.cc index de8ac905..12e78501 100644 --- a/tests/libmemcached-1.0/ketama.cc +++ b/tests/libmemcached-1.0/ketama.cc @@ -37,7 +37,7 @@ #include <config.h> #include <libtest/test.hpp> -#include <libmemcached-1.0/memcached.h> +#include <libmemcached-1.2/memcached.h> #include "libmemcached/server_instance.h" #include "libmemcached/continuum.hpp" diff --git a/tests/libmemcached-1.0/mem_functions.cc b/tests/libmemcached-1.0/mem_functions.cc index a1daa8ab..b83ebb86 100644 --- a/tests/libmemcached-1.0/mem_functions.cc +++ b/tests/libmemcached-1.0/mem_functions.cc @@ -46,7 +46,7 @@ Test cases */ -#include <libmemcached-1.0/memcached.h> +#include <libmemcached-1.2/memcached.h> #include <libmemcached/is.h> #include <libmemcached/server_instance.h> @@ -76,7 +76,7 @@ using namespace libtest; -#include <libmemcachedutil-1.0/util.h> +#include <libmemcachedutil-1.2/util.h> #include "tests/hash_results.h" @@ -3731,7 +3731,7 @@ test_return_t memcached_get_MEMCACHED_ERRNO(memcached_st *) { size_t len; uint32_t flags; - memcached_return rc; + memcached_return_t rc; // Create a handle. memcached_st *tl_memc_h= memcached(test_literal_param("--server=localhost:9898 --server=localhost:9899")); // This server should not exist @@ -3757,7 +3757,7 @@ test_return_t memcached_get_MEMCACHED_NOTFOUND(memcached_st *memc) { size_t len; uint32_t flags; - memcached_return rc; + memcached_return_t rc; // See if memcached is reachable. char *value= memcached_get(memc, @@ -3781,7 +3781,7 @@ test_return_t memcached_get_by_key_MEMCACHED_ERRNO(memcached_st *) { size_t len; uint32_t flags; - memcached_return rc; + memcached_return_t rc; // Create a handle. memcached_st *tl_memc_h= memcached_create(NULL); @@ -3811,7 +3811,7 @@ test_return_t memcached_get_by_key_MEMCACHED_NOTFOUND(memcached_st *memc) { size_t len; uint32_t flags; - memcached_return rc; + memcached_return_t rc; // See if memcached is reachable. char *value= memcached_get_by_key(memc, @@ -4372,7 +4372,7 @@ test_return_t wrong_failure_counter_two_test(memcached_st *memc) /* Check if we still are connected */ uint32_t flags; size_t string_length; - memcached_return rc; + memcached_return_t rc; char *string= memcached_get(memc, key, strlen(key), &string_length, &flags, &rc); @@ -4437,7 +4437,7 @@ test_return_t regression_bug_490486(memcached_st *original_memc) char blob[1024]= { 0 }; for (size_t x= 0; x < keys.size(); ++x) { - memcached_return rc= memcached_set(memc, + memcached_return_t rc= memcached_set(memc, keys.key_at(x), keys.length_at(x), blob, sizeof(blob), 0, 0); test_true(rc == MEMCACHED_SUCCESS or rc == MEMCACHED_BUFFERED); // MEMCACHED_TIMEOUT <-- hash been observed on OSX @@ -4447,7 +4447,7 @@ test_return_t regression_bug_490486(memcached_st *original_memc) /* Try to get all of them with a large multiget */ size_t counter= 0; - memcached_execute_function callbacks[]= { &callback_counter }; + memcached_execute_fn callbacks[]= { &callback_counter }; memcached_return_t rc= memcached_mget_execute(memc, keys.keys_ptr(), keys.lengths_ptr(), keys.size(), callbacks, &counter, 1); @@ -4635,7 +4635,7 @@ test_return_t regression_bug_490520(memcached_st *original_memc) char key[251]; int key_length= snprintf(key, sizeof(key), "0200%u", x); - memcached_return rc= memcached_set(memc, key, key_length, blob, sizeof(blob), 0, 0); + memcached_return_t rc= memcached_set(memc, key, key_length, blob, sizeof(blob), 0, 0); test_true_got(rc == MEMCACHED_SUCCESS or rc == MEMCACHED_BUFFERED, memcached_last_error_message(memc)); } @@ -4728,7 +4728,7 @@ test_return_t regression_bug_854604(memcached_st *) return TEST_SUCCESS; } -static void die_message(memcached_st* mc, memcached_return error, const char* what, uint32_t it) +static void die_message(memcached_st* mc, memcached_return_t error, const char* what, uint32_t it) { fprintf(stderr, "Iteration #%u: ", it); @@ -4759,7 +4759,7 @@ test_return_t regression_bug_(memcached_st *memc) for (uint32_t x= 0; x < TEST_CONSTANT_CREATION; x++) { memcached_st* mc= memcached_create(NULL); - memcached_return rc; + memcached_return_t rc; rc= memcached_behavior_set(mc, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL, 1); if (rc != MEMCACHED_SUCCESS) diff --git a/tests/libmemcached-1.0/memcached_fetch_execute.cc b/tests/libmemcached-1.0/memcached_fetch_execute.cc index a22393f8..6296cff7 100644 --- a/tests/libmemcached-1.0/memcached_fetch_execute.cc +++ b/tests/libmemcached-1.0/memcached_fetch_execute.cc @@ -37,7 +37,7 @@ #include <config.h> #include <libtest/test.hpp> -#include <libmemcached-1.0/memcached.h> +#include <libmemcached-1.2/memcached.h> #include <libmemcached/util.h> using namespace libtest; diff --git a/tests/libmemcached-1.0/memcached_get.cc b/tests/libmemcached-1.0/memcached_get.cc index 1db1a7e3..08fef67f 100644 --- a/tests/libmemcached-1.0/memcached_get.cc +++ b/tests/libmemcached-1.0/memcached_get.cc @@ -41,7 +41,7 @@ Test cases */ -#include <libmemcached-1.0/memcached.h> +#include <libmemcached-1.2/memcached.h> #include "tests/libmemcached-1.0/memcached_get.h" #include "tests/libmemcached-1.0/setup_and_teardowns.h" diff --git a/tests/libmemcached-1.0/namespace.cc b/tests/libmemcached-1.0/namespace.cc index cbe4d1b8..dd19143e 100644 --- a/tests/libmemcached-1.0/namespace.cc +++ b/tests/libmemcached-1.0/namespace.cc @@ -40,7 +40,7 @@ using namespace libtest; -#include <libmemcached-1.0/memcached.h> +#include <libmemcached-1.2/memcached.h> #include <tests/namespace.h> diff --git a/tests/libmemcached-1.0/parser.cc b/tests/libmemcached-1.0/parser.cc index 6a75a2dc..ec0e2304 100644 --- a/tests/libmemcached-1.0/parser.cc +++ b/tests/libmemcached-1.0/parser.cc @@ -44,8 +44,8 @@ using namespace libtest; #include <string> #include <cerrno> -#include <libmemcached-1.0/memcached.h> -#include <libmemcachedutil-1.0/util.h> +#include <libmemcached-1.2/memcached.h> +#include <libmemcachedutil-1.2/util.h> #include <tests/libmemcached-1.0/parser.h> #include <tests/print.h> diff --git a/tests/libmemcached-1.0/plus.cpp b/tests/libmemcached-1.0/plus.cpp index e7bfd836..ed14c104 100644 --- a/tests/libmemcached-1.0/plus.cpp +++ b/tests/libmemcached-1.0/plus.cpp @@ -40,7 +40,7 @@ /* C++ interface test */ -#include <libmemcached-1.0/memcached.hpp> +#include <libmemcached-1.2/memcached.hpp> #include <libtest/test.hpp> #include <cstdio> diff --git a/tests/libmemcached-1.0/pool.cc b/tests/libmemcached-1.0/pool.cc index b6653139..75920e04 100644 --- a/tests/libmemcached-1.0/pool.cc +++ b/tests/libmemcached-1.0/pool.cc @@ -47,8 +47,8 @@ using namespace libtest; #include <semaphore.h> -#include <libmemcached-1.0/memcached.h> -#include <libmemcachedutil-1.0/util.h> +#include <libmemcached-1.2/memcached.h> +#include <libmemcachedutil-1.2/util.h> #include <libmemcached/is.h> #include <tests/pool.h> diff --git a/tests/libmemcached-1.0/print.cc b/tests/libmemcached-1.0/print.cc index 11125493..e738aa04 100644 --- a/tests/libmemcached-1.0/print.cc +++ b/tests/libmemcached-1.0/print.cc @@ -43,7 +43,7 @@ using namespace libtest; #include <iostream> -#include <libmemcached-1.0/memcached.h> +#include <libmemcached-1.2/memcached.h> #include "tests/print.h" diff --git a/tests/libmemcached-1.0/replication.cc b/tests/libmemcached-1.0/replication.cc index 2e1808ea..f23c2f49 100644 --- a/tests/libmemcached-1.0/replication.cc +++ b/tests/libmemcached-1.0/replication.cc @@ -40,7 +40,7 @@ using namespace libtest; -#include <libmemcached-1.0/memcached.h> +#include <libmemcached-1.2/memcached.h> #include "libmemcached/server_instance.h" diff --git a/tests/libmemcached-1.0/sasl.cc b/tests/libmemcached-1.0/sasl.cc index 65ce0310..6f0bd7ac 100644 --- a/tests/libmemcached-1.0/sasl.cc +++ b/tests/libmemcached-1.0/sasl.cc @@ -43,7 +43,7 @@ using namespace libtest; Test cases */ -#include <libmemcached-1.0/memcached.h> +#include <libmemcached-1.2/memcached.h> static test_return_t pre_sasl(memcached_st *) { diff --git a/tests/libmemcached-1.0/server_add.cc b/tests/libmemcached-1.0/server_add.cc index 8fd717c6..0c36ea3c 100644 --- a/tests/libmemcached-1.0/server_add.cc +++ b/tests/libmemcached-1.0/server_add.cc @@ -40,7 +40,7 @@ using namespace libtest; -#include <libmemcached-1.0/memcached.h> +#include <libmemcached-1.2/memcached.h> #include <tests/server_add.h> diff --git a/tests/libmemcached-1.0/setup_and_teardowns.cc b/tests/libmemcached-1.0/setup_and_teardowns.cc index ad2126fa..49fea874 100644 --- a/tests/libmemcached-1.0/setup_and_teardowns.cc +++ b/tests/libmemcached-1.0/setup_and_teardowns.cc @@ -38,7 +38,7 @@ #include <config.h> #include <libtest/test.hpp> -#include <libmemcachedutil-1.0/util.h> +#include <libmemcachedutil-1.2/util.h> #include "tests/print.h" #include "tests/libmemcached-1.0/setup_and_teardowns.h" diff --git a/tests/libmemcached-1.0/stat.cc b/tests/libmemcached-1.0/stat.cc index 605c8baa..bb2bf271 100644 --- a/tests/libmemcached-1.0/stat.cc +++ b/tests/libmemcached-1.0/stat.cc @@ -41,8 +41,8 @@ #include <libtest/test.hpp> -#include <libmemcached-1.0/memcached.h> -#include <libmemcachedutil-1.0/util.h> +#include <libmemcached-1.2/memcached.h> +#include <libmemcachedutil-1.2/util.h> using namespace libtest; diff --git a/tests/libmemcached-1.0/string.cc b/tests/libmemcached-1.0/string.cc index babe1bf2..529c7015 100644 --- a/tests/libmemcached-1.0/string.cc +++ b/tests/libmemcached-1.0/string.cc @@ -40,7 +40,7 @@ #include <config.h> -#include <libmemcached-1.0/memcached.h> +#include <libmemcached-1.2/memcached.h> #include "libmemcached/string.hpp" #include "libmemcached/is.h" diff --git a/tests/libmemcached-1.0/touch.cc b/tests/libmemcached-1.0/touch.cc index 07f0096f..751137f6 100644 --- a/tests/libmemcached-1.0/touch.cc +++ b/tests/libmemcached-1.0/touch.cc @@ -40,8 +40,8 @@ using namespace libtest; -#include <libmemcached-1.0/memcached.h> -#include <libmemcachedutil-1.0/util.h> +#include <libmemcached-1.2/memcached.h> +#include <libmemcachedutil-1.2/util.h> #include "tests/touch.h" @@ -60,7 +60,7 @@ test_return_t test_memcached_touch(memcached_st *memc) size_t len; uint32_t flags; - memcached_return rc; + memcached_return_t rc; test_null(memcached_get(memc, test_literal_param(__func__), @@ -106,7 +106,7 @@ test_return_t test_memcached_touch_by_key(memcached_st *memc) size_t len; uint32_t flags; - memcached_return rc; + memcached_return_t rc; test_null(memcached_get_by_key(memc, test_literal_param("grouping_key"), diff --git a/tests/libmemcached-1.0/virtual_buckets.cc b/tests/libmemcached-1.0/virtual_buckets.cc index 5ed812fa..5348fbb3 100644 --- a/tests/libmemcached-1.0/virtual_buckets.cc +++ b/tests/libmemcached-1.0/virtual_buckets.cc @@ -42,7 +42,7 @@ using namespace libtest; #include <tests/virtual_buckets.h> -#include <libmemcached-1.0/memcached.h> +#include <libmemcached-1.2/memcached.h> #include <cstring> diff --git a/tests/mem_udp.cc b/tests/mem_udp.cc index ed657bf4..a6eedfd5 100644 --- a/tests/mem_udp.cc +++ b/tests/mem_udp.cc @@ -45,11 +45,11 @@ using namespace libtest; -#include <libmemcached-1.0/memcached.h> +#include <libmemcached-1.2/memcached.h> #include <libmemcached/server_instance.h> #include <libmemcached/io.h> #include <libmemcached/udp.hpp> -#include <libmemcachedutil-1.0/util.h> +#include <libmemcachedutil-1.2/util.h> #include <cstdio> #include <cstdlib> diff --git a/tests/memcapable.cc b/tests/memcapable.cc index 09b47efa..647a6341 100644 --- a/tests/memcapable.cc +++ b/tests/memcapable.cc @@ -42,7 +42,7 @@ #include <config.h> #include <libtest/test.hpp> -#include <libmemcached-1.0/memcached.h> +#include <libmemcached-1.2/memcached.h> using namespace libtest; diff --git a/tests/memcat.cc b/tests/memcat.cc index ed606d1d..9144fed3 100644 --- a/tests/memcat.cc +++ b/tests/memcat.cc @@ -42,7 +42,7 @@ #include <config.h> #include <libtest/test.hpp> -#include <libmemcached-1.0/memcached.h> +#include <libmemcached-1.2/memcached.h> using namespace libtest; diff --git a/tests/memcp.cc b/tests/memcp.cc index 3c8d6b02..27562067 100644 --- a/tests/memcp.cc +++ b/tests/memcp.cc @@ -42,7 +42,7 @@ #include <config.h> #include <libtest/test.hpp> -#include <libmemcached-1.0/memcached.h> +#include <libmemcached-1.2/memcached.h> using namespace libtest; diff --git a/tests/memdump.cc b/tests/memdump.cc index 840c1a17..cc4d0023 100644 --- a/tests/memdump.cc +++ b/tests/memdump.cc @@ -42,7 +42,7 @@ #include <config.h> #include <libtest/test.hpp> -#include <libmemcached-1.0/memcached.h> +#include <libmemcached-1.2/memcached.h> using namespace libtest; diff --git a/tests/memerror.cc b/tests/memerror.cc index 9b3ddd35..b2f90e19 100644 --- a/tests/memerror.cc +++ b/tests/memerror.cc @@ -42,7 +42,7 @@ #include <config.h> #include <libtest/test.hpp> -#include <libmemcached-1.0/memcached.h> +#include <libmemcached-1.2/memcached.h> using namespace libtest; diff --git a/tests/memexist.cc b/tests/memexist.cc index 47496a64..f34b2efe 100644 --- a/tests/memexist.cc +++ b/tests/memexist.cc @@ -42,8 +42,8 @@ #include <config.h> #include <libtest/test.hpp> -#include <libmemcached-1.0/memcached.h> -#include <libmemcachedutil-1.0/util.h> +#include <libmemcached-1.2/memcached.h> +#include <libmemcachedutil-1.2/util.h> using namespace libtest; diff --git a/tests/memflush.cc b/tests/memflush.cc index 0f708a9b..5a0bb2e3 100644 --- a/tests/memflush.cc +++ b/tests/memflush.cc @@ -42,7 +42,7 @@ #include <config.h> #include <libtest/test.hpp> -#include <libmemcached-1.0/memcached.h> +#include <libmemcached-1.2/memcached.h> using namespace libtest; diff --git a/tests/memrm.cc b/tests/memrm.cc index 1f5f722a..d47b58e7 100644 --- a/tests/memrm.cc +++ b/tests/memrm.cc @@ -42,7 +42,7 @@ #include <config.h> #include <libtest/test.hpp> -#include <libmemcached-1.0/memcached.h> +#include <libmemcached-1.2/memcached.h> using namespace libtest; diff --git a/tests/memslap.cc b/tests/memslap.cc index 792d15fb..3925029a 100644 --- a/tests/memslap.cc +++ b/tests/memslap.cc @@ -42,7 +42,7 @@ #include <config.h> #include <libtest/test.hpp> -#include <libmemcached-1.0/memcached.h> +#include <libmemcached-1.2/memcached.h> using namespace libtest; diff --git a/tests/memstat.cc b/tests/memstat.cc index b2dea7e9..57c6a587 100644 --- a/tests/memstat.cc +++ b/tests/memstat.cc @@ -42,7 +42,7 @@ #include <config.h> #include <libtest/test.hpp> -#include <libmemcached-1.0/memcached.h> +#include <libmemcached-1.2/memcached.h> using namespace libtest; diff --git a/tests/memtouch.cc b/tests/memtouch.cc index 207ac1dc..bffe48e0 100644 --- a/tests/memtouch.cc +++ b/tests/memtouch.cc @@ -42,8 +42,8 @@ #include <config.h> #include <libtest/test.hpp> -#include <libmemcached-1.0/memcached.h> -#include <libmemcachedutil-1.0/util.h> +#include <libmemcached-1.2/memcached.h> +#include <libmemcachedutil-1.2/util.h> using namespace libtest; diff --git a/tests/parser.cc b/tests/parser.cc index 220d9ef5..15dab12b 100644 --- a/tests/parser.cc +++ b/tests/parser.cc @@ -39,7 +39,7 @@ /* C++ interface test */ -#include <libmemcached-1.0/memcached.hpp> +#include <libmemcached-1.2/memcached.hpp> #include <libtest/test.hpp> using namespace libtest; diff --git a/win32/include.am b/win32/include.am index 43e8d9b1..f4578f5b 100644 --- a/win32/include.am +++ b/win32/include.am @@ -6,6 +6,5 @@ noinst_HEADERS+= win32/wrappers.h if BUILD_WIN32_WRAPPERS libhashkit_libhashkit_la_LDFLAGS+=-no-undefined libmemcached_libmemcached_la_LDFLAGS+=-no-undefined -libmemcached_libmemcachedprotocol_la_LDFLAGS+=-no-undefined libmemcached_libmemcachedutil_la_LDFLAGS+=-no-undefined endif |