Removed build-time dependency to memcached with binary support
authorTrond Norbye <trond.norbye@sun.com>
Thu, 31 Jul 2008 08:46:10 +0000 (10:46 +0200)
committerTrond Norbye <trond.norbye@sun.com>
Thu, 31 Jul 2008 08:46:10 +0000 (10:46 +0200)
Added a copy of memcached/protocol_binary.h to the source bundle to avoid the
need of having a memcached server with support for the binary protocol
installed on the build machine.

config/memcached.m4 [deleted file]
config/protocol_binary.m4 [new file with mode: 0644]
configure.ac
libmemcached/Makefile.am
libmemcached/memcached/README.txt [new file with mode: 0644]
libmemcached/memcached/protocol_binary.h [new file with mode: 0644]

diff --git a/config/memcached.m4 b/config/memcached.m4
deleted file mode 100644 (file)
index 140e48a..0000000
+++ /dev/null
@@ -1,38 +0,0 @@
-dnl ---------------------------------------------------------------------------
-dnl Macro: MEMCACHED_TEST
-dnl ---------------------------------------------------------------------------
-saved_CPPFLAGS="$CPPFLAGS"
-CPPFLAGS=""
-AC_ARG_WITH(memcached,
-       [  --with-memcached=PATH   Specify path to memcached installation ],
-       [
-                if test "x$withval" != "xno" ; then
-                        CPPFLAGS="-I${withval}/include"
-                fi
-       ]
-)
-
-AC_CHECK_HEADER(memcached/protocol_binary.h, [
-                AC_RUN_IFELSE([ 
-                   AC_LANG_PROGRAM([
-                      #include "memcached/protocol_binary.h"
-                   ], [
-                      protocol_binary_request_set request;
-                      if (sizeof(request) != sizeof(request.bytes)) {
-                         return 1;
-                      }
-                   ])
-                ],[ 
-                   if test "x$CPPFLAGS" != "x" ; then
-                      CPPFLAGS="$saved_CPPFLAGS $CPPFLAGS"
-                   else
-                      CPPFLAGS="$saved_CPPFLAGS"
-                   fi
-               ], AC_MSG_ERROR([Unsupported struct padding done by compiler.])) 
-               ], [
-                  AC_MSG_ERROR([Cannot locate memcached/protocol_binary.])
-               ])
-
-dnl ---------------------------------------------------------------------------
-dnl End Macro: MEMCACHED_TEST
-dnl ---------------------------------------------------------------------------
diff --git a/config/protocol_binary.m4 b/config/protocol_binary.m4
new file mode 100644 (file)
index 0000000..96ce0c0
--- /dev/null
@@ -0,0 +1,19 @@
+dnl ---------------------------------------------------------------------------
+dnl Macro: PROTOCOL_BINARY_TEST
+dnl ---------------------------------------------------------------------------
+AC_RUN_IFELSE([ 
+   AC_LANG_PROGRAM([
+      #include "libmemcached/memcached/protocol_binary.h"
+   ], [
+      protocol_binary_request_set request;
+      if (sizeof(request) != sizeof(request.bytes)) {
+         return 1;
+      }
+   ])
+],[ 
+  ;
+], AC_MSG_ERROR([Unsupported struct padding done by compiler.])) 
+
+dnl ---------------------------------------------------------------------------
+dnl End Macro: PROTOCOL_BINARY_TEST
+dnl ---------------------------------------------------------------------------
index 83463ac63ea02cd204990ababe340323d699c643..d0c871c81b3396a28d77d3ec40457a0a1f97e54b 100644 (file)
@@ -51,9 +51,9 @@ AC_LANG_CPLUSPLUS
 
 sinclude(config/debug.m4)
 sinclude(config/dtrace.m4)
-sinclude(config/memcached.m4)
 sinclude(config/byteorder.m4)
 sinclude(config/64bit.m4)
+sinclude(config/protocol_binary.m4)
 
 # We only support GCC and Sun's forte at the moment
 if test "$GCC" = "yes"
index 7cb12a01408eaf97add3d56df39ae97b883cbe7d..b024d9f9e64eafb9446262dc33de4aeed879f59e 100644 (file)
@@ -1,4 +1,4 @@
-EXTRA_DIST = libmemcached_probes.d
+EXTRA_DIST = libmemcached_probes.d memcached/README.txt
 
 INCLUDES = -I$(top_builddir)
 LIBS =
@@ -22,7 +22,8 @@ DTRACEFILES = memcached.o \
 
 noinst_HEADERS = libmemcached_probes.h \
                 memcached_io.h \
-                 common.h
+                 common.h \
+                 memcached/protocol_binary.h
 
 pkginclude_HEADERS= memcached.h \
                    memcached.hh \
diff --git a/libmemcached/memcached/README.txt b/libmemcached/memcached/README.txt
new file mode 100644 (file)
index 0000000..adcac80
--- /dev/null
@@ -0,0 +1,7 @@
+For your convenience libmemcached contains a copy of protocol_binary.h so that
+you may compile libmemcached without having a memcached server with support
+for the binary protocol installed on your computer. Please do not modify this
+fine, but replace it with a fresh copy from a new distribution if they are 
+out of sync.
+
+Trond Norbye
diff --git a/libmemcached/memcached/protocol_binary.h b/libmemcached/memcached/protocol_binary.h
new file mode 100644 (file)
index 0000000..9d22514
--- /dev/null
@@ -0,0 +1,351 @@
+/*
+ * 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 <stdint.h>
+
+/**
+ * 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_UNKNOWN_COMMAND = 0x81,
+    PROTOCOL_BINARY_RESPONSE_ENOMEM = 0x82,
+  } 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_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 reserved;
+      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
+   */
+  typedef union {
+    struct {
+      protocol_binary_request_header header;
+    } message;
+    uint8_t bytes[sizeof(protocol_binary_request_header)];
+  } 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_nnoop;
+
+  /**
+   * 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;
+#ifdef __cplusplus
+}
+#endif
+#endif /* PROTOCOL_BINARY_H */