From de46e62fe493ce152e1804feec0d19d5d0cfaa9f Mon Sep 17 00:00:00 2001 From: Brian Aker Date: Tue, 29 Mar 2011 09:54:23 -0700 Subject: [PATCH] Merge in all scanner tree + virtual buckets. --- .bzrignore | 7 +- ChangeLog | 5 + Makefile.am | 1 + clients/include.am | 4 + clients/memcat.c | 4 +- clients/memcp.c | 4 +- clients/memdump.c | 4 +- clients/memflush.c | 4 +- clients/memparse.cc | 68 + clients/memrm.c | 5 +- clients/ms_conn.c | 2 +- configure.ac | 12 +- example/interface_v0.c | 2 +- libhashkit/function.c | 3 +- libhashkit/strerror.c | 14 +- libhashkit/types.h | 2 + libmemcached/array.c | 109 + libmemcached/array.h | 72 + libmemcached/auto.c | 51 +- libmemcached/auto.h | 103 +- libmemcached/behavior.c | 227 +- libmemcached/behavior.h | 12 + libmemcached/callback.c | 36 +- libmemcached/common.h | 106 +- libmemcached/constants.h | 22 +- libmemcached/delete.c | 12 +- libmemcached/error.c | 203 ++ libmemcached/error.h | 71 + libmemcached/get.c | 16 +- libmemcached/hash.c | 85 +- libmemcached/hash.h | 41 +- libmemcached/hosts.c | 56 +- libmemcached/include.am | 26 +- libmemcached/io.c | 103 +- libmemcached/io.h | 47 +- libmemcached/is.h | 48 + libmemcached/memcached.c | 177 +- libmemcached/memcached.h | 74 +- libmemcached/memcached/protocol_binary.h | 302 +- libmemcached/memcached/vbucket.h | 26 + libmemcached/options.cc | 151 + libmemcached/options.h | 64 + libmemcached/options/build.cc | 69 + libmemcached/options/build.h | 46 + libmemcached/options/context.h | 93 + libmemcached/options/include.am | 24 + libmemcached/options/lex_string.h | 16 + libmemcached/options/parser.cc | 2384 ++++++++++++++ libmemcached/options/parser.h | 122 + libmemcached/options/scanner.cc | 3581 ++++++++++++++++++++++ libmemcached/options/scanner.h | 478 +++ libmemcached/options/server.h | 56 + libmemcached/options/string.h | 53 + libmemcached/options/symbol.h | 57 + libmemcached/parse.h | 5 +- libmemcached/prefix_key.cc | 63 + libmemcached/prefix_key.h | 49 + libmemcached/protocol/binary_handler.c | 14 +- libmemcached/response.c | 2 +- libmemcached/result.c | 7 +- libmemcached/result.h | 2 +- libmemcached/server.h | 7 + libmemcached/stats.c | 18 +- libmemcached/storage.c | 13 +- libmemcached/strerror.c | 4 + libmemcached/string.c | 4 +- libmemcached/string.h | 21 +- libmemcached/types.h | 3 + libmemcached/virtual_bucket.c | 117 + libmemcached/virtual_bucket.h | 59 + libtest/failed.cc | 75 + libtest/failed.h | 53 + libtest/include.am | 9 +- libtest/server.c | 2 +- libtest/test.c | 7 + libtest/test.h | 89 +- libtest/visibility.h | 69 + m4/pandora_warnings.m4 | 2 +- m4/socket_send_flags.m4 | 17 + support/example.cnf | 11 + support/libmemcached.spec.in | 18 +- tests/basic.cc | 130 + tests/basic.h | 66 + tests/error_conditions.cc | 72 + tests/error_conditions.h | 50 + tests/hashkit_functions.c | 6 +- tests/include.am | 23 +- tests/mem_functions.c | 472 +-- tests/parser.cc | 535 ++++ tests/parser.h | 102 + tests/print.cc | 59 + tests/print.h | 51 + tests/replication.cc | 296 ++ tests/replication.h | 61 + tests/string.cc | 168 + tests/string.h | 69 + tests/virtual_buckets.cc | 141 + tests/virtual_buckets.h | 53 + 98 files changed, 11527 insertions(+), 927 deletions(-) create mode 100644 clients/memparse.cc create mode 100644 libmemcached/array.c create mode 100644 libmemcached/array.h create mode 100644 libmemcached/error.c create mode 100644 libmemcached/error.h create mode 100644 libmemcached/is.h create mode 100644 libmemcached/memcached/vbucket.h create mode 100644 libmemcached/options.cc create mode 100644 libmemcached/options.h create mode 100644 libmemcached/options/build.cc create mode 100644 libmemcached/options/build.h create mode 100644 libmemcached/options/context.h create mode 100644 libmemcached/options/include.am create mode 100644 libmemcached/options/lex_string.h create mode 100644 libmemcached/options/parser.cc create mode 100644 libmemcached/options/parser.h create mode 100644 libmemcached/options/scanner.cc create mode 100644 libmemcached/options/scanner.h create mode 100644 libmemcached/options/server.h create mode 100644 libmemcached/options/string.h create mode 100644 libmemcached/options/symbol.h create mode 100644 libmemcached/prefix_key.cc create mode 100644 libmemcached/prefix_key.h create mode 100644 libmemcached/virtual_bucket.c create mode 100644 libmemcached/virtual_bucket.h create mode 100644 libtest/failed.cc create mode 100644 libtest/failed.h create mode 100644 libtest/visibility.h create mode 100644 support/example.cnf create mode 100644 tests/basic.cc create mode 100644 tests/basic.h create mode 100644 tests/error_conditions.cc create mode 100644 tests/error_conditions.h create mode 100644 tests/parser.cc create mode 100644 tests/parser.h create mode 100644 tests/print.cc create mode 100644 tests/print.h create mode 100644 tests/replication.cc create mode 100644 tests/replication.h create mode 100644 tests/string.cc create mode 100644 tests/string.h create mode 100644 tests/virtual_buckets.cc create mode 100644 tests/virtual_buckets.h diff --git a/.bzrignore b/.bzrignore index 87578c4b..06c56d69 100644 --- a/.bzrignore +++ b/.bzrignore @@ -1,6 +1,8 @@ *.exe *.lo +*.output *.pop +*.rpm */*.l[oa] */*/*.l[oa] */*/.deps @@ -24,6 +26,7 @@ clients/memcp clients/memdump clients/memerror clients/memflush +clients/memparse clients/memrm clients/memslap clients/memstat @@ -40,6 +43,7 @@ config/ltmain.sh config/missing config/pandora_vc_revinfo config/plugin.ac +config/top.h configure docs/*.[13] docs/*.html @@ -73,6 +77,7 @@ libmemcached-?.??/ libmemcached.pop libmemcached/configure.h libmemcached/dtrace_probes.h +libmemcached/generated_probes.h libmemcached/memcached_configure.h libmemcached_examples.pop libmemcachedutil.pop @@ -185,5 +190,3 @@ tests/testhashkit tests/testplus tests/testudp unittests/unittests -config/top.h -libmemcached/generated_probes.h diff --git a/ChangeLog b/ChangeLog index 538463c4..9c0bea9c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +0.49 + * Fix calls to auto methods so that if value is not passed in nothing bad happens. + * New parser calls for generating memcached_st objects. + * New error system. + 0.48 Tue Mar 15 23:05:18 PDT 2011 * Fix memory leak in server parse. * Move test framework out to be its own library (easier to work with Gearman). diff --git a/Makefile.am b/Makefile.am index 31585120..7a09b51f 100644 --- a/Makefile.am +++ b/Makefile.am @@ -15,6 +15,7 @@ nobase_include_HEADERS = check_PROGRAMS = EXTRA_HEADERS = BUILT_SOURCES= +DISTCLEANFILES= EXTRA_DIST= \ ${srcdir}/m4/pandora_*.m4 \ .quickly \ diff --git a/clients/include.am b/clients/include.am index a709e38d..f7503754 100644 --- a/clients/include.am +++ b/clients/include.am @@ -18,6 +18,7 @@ bin_PROGRAMS+= \ clients/memdump \ clients/memerror \ clients/memflush \ + clients/memparse \ clients/memrm \ clients/memstat @@ -50,6 +51,9 @@ clients_libgenexec_la_SOURCES= clients/generator.c clients/execute.c clients_memcat_SOURCES= clients/memcat.c clients_memcat_LDADD= $(CLIENTS_LDADDS) +clients_memparse_SOURCES= clients/memparse.cc +clients_memparse_LDADD= $(CLIENTS_LDADDS) + clients_memcp_SOURCES= clients/memcp.c clients_memcp_LDADD= $(CLIENTS_LDADDS) diff --git a/clients/memcat.c b/clients/memcat.c index 8998ff0c..3f0d92b4 100644 --- a/clients/memcat.c +++ b/clients/memcat.c @@ -138,9 +138,9 @@ int main(int argc, char *argv[]) { fprintf(stderr, "memcat: %s: memcache error %s", argv[optind], memcached_strerror(memc, rc)); - if (memc->cached_errno) + if (memcached_last_error_errno(memc)) { - fprintf(stderr, " system error %s", strerror(memc->cached_errno)); + fprintf(stderr, " system error %s", strerror(memcached_last_error_errno(memc))); } fprintf(stderr, "\n"); diff --git a/clients/memcp.c b/clients/memcp.c index bce35ce6..bf3828ae 100644 --- a/clients/memcp.c +++ b/clients/memcp.c @@ -188,8 +188,8 @@ int main(int argc, char *argv[]) { fprintf(stderr, "memcp: %s: memcache error %s", ptr, memcached_strerror(memc, rc)); - if (memc->cached_errno) - fprintf(stderr, " system error %s", strerror(memc->cached_errno)); + if (memcached_last_error_errno(memc)) + fprintf(stderr, " system error %s", strerror(memcached_last_error_errno(memc))); fprintf(stderr, "\n"); return_code= -1; diff --git a/clients/memdump.c b/clients/memdump.c index 67a2a540..0e81dad4 100644 --- a/clients/memdump.c +++ b/clients/memdump.c @@ -100,8 +100,8 @@ int main(int argc, char *argv[]) if (rc != MEMCACHED_SUCCESS) { fprintf(stderr, "memdump: memcache error %s", memcached_strerror(memc, rc)); - if (memc->cached_errno) - fprintf(stderr, " system error %s", strerror(memc->cached_errno)); + if (memcached_last_error_errno(memc)) + fprintf(stderr, " system error %s", strerror(memcached_last_error_errno(memc))); fprintf(stderr, "\n"); } diff --git a/clients/memflush.c b/clients/memflush.c index 813bf9e1..848bc1e7 100644 --- a/clients/memflush.c +++ b/clients/memflush.c @@ -71,8 +71,8 @@ int main(int argc, char *argv[]) { fprintf(stderr, "memflush: memcache error %s", memcached_strerror(memc, rc)); - if (memc->cached_errno) - fprintf(stderr, " system error %s", strerror(memc->cached_errno)); + if (memcached_last_error_errno(memc)) + fprintf(stderr, " system error %s", strerror(memcached_last_error_errno(memc))); fprintf(stderr, "\n"); } diff --git a/clients/memparse.cc b/clients/memparse.cc new file mode 100644 index 00000000..2c80fcd5 --- /dev/null +++ b/clients/memparse.cc @@ -0,0 +1,68 @@ +/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: + * + * Libmemcached library + * + * Copyright (C) 2011 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. + * + */ + +#include + +#include + +#include + +int main(int argc, char *argv[]) +{ + + if (argc < 2) + { + std::cerr << "No arguments provided." << std::endl; + return EXIT_FAILURE; + } + + for (int x= 1; x < argc; x++) + { + char buffer[BUFSIZ]; + memcached_return_t rc; + rc= libmemcached_check_configuration(argv[x], strlen(argv[x]), buffer, sizeof(buffer)); + + if (rc != MEMCACHED_SUCCESS) + { + std::cerr << "Failed to parse argument #" << x << " " << argv[x] << std::endl; + std::cerr << "Error message from parser was:\t" << buffer << std::endl; + return EXIT_FAILURE; + } + } + + return EXIT_SUCCESS; +} diff --git a/clients/memrm.c b/clients/memrm.c index 8023a638..d4d93c2e 100644 --- a/clients/memrm.c +++ b/clients/memrm.c @@ -81,8 +81,8 @@ int main(int argc, char *argv[]) { fprintf(stderr, "memrm: %s: memcache error %s", argv[optind], memcached_strerror(memc, rc)); - if (memc->cached_errno) - fprintf(stderr, " system error %s", strerror(memc->cached_errno)); + if (memcached_last_error_errno(memc)) + fprintf(stderr, " system error %s", strerror(memcached_last_error_errno(memc))); fprintf(stderr, "\n"); return_code= -1; @@ -95,6 +95,7 @@ int main(int argc, char *argv[]) if (opt_servers) free(opt_servers); + if (opt_hash) free(opt_hash); diff --git a/clients/ms_conn.c b/clients/ms_conn.c index e7ee3f12..f380a667 100644 --- a/clients/ms_conn.c +++ b/clients/ms_conn.c @@ -3288,7 +3288,7 @@ static void ms_add_bin_header(ms_conn_t *c, header->request.extlen= (uint8_t)hdr_len; header->request.datatype= (uint8_t)PROTOCOL_BINARY_RAW_BYTES; - header->request.reserved= 0; + header->request.vbucket= 0; header->request.bodylen= htonl(body_len); header->request.opaque= 0; diff --git a/configure.ac b/configure.ac index c3b4300f..b4581e9f 100644 --- a/configure.ac +++ b/configure.ac @@ -1,5 +1,6 @@ #!/usr/bin/env bash -# libmemcached +# LibmemcacheD +# Copyright (C) 2011 Data Differential, http://datadifferential.com/ # Copyright (C) 2006-2010 Brian Aker, Monty Taylor, Trond Norbye # All rights reserved. # @@ -12,6 +13,8 @@ AC_CONFIG_SRCDIR([libmemcached/memcached.c]) AC_CONFIG_AUX_DIR(config) PANDORA_CANONICAL_TARGET(no-vc-changelog) +AC_CHECK_PROGS([YACC], ['bison'], [:]) +AC_CHECK_PROGS([LEX], ['flex'], [:]) #shared library versioning MEMCACHED_UTIL_LIBRARY_VERSION=1:0:0 @@ -32,7 +35,7 @@ AC_SUBST(MEMCACHED_PROTOCAL_LIBRARY_VERSION) AC_SUBST(MEMCACHED_LIBRARY_VERSION) -HASHKIT_LIBRARY_VERSION=0:0:0 +HASHKIT_LIBRARY_VERSION=1:0:0 AC_SUBST(HASHKIT_LIBRARY_VERSION) AH_TOP([ @@ -88,6 +91,10 @@ AH_BOTTOM([ #define MSG_DONTWAIT 0 #endif +#ifndef HAVE_MSG_MORE +#define MSG_MORE 0 +#endif + #endif ]) @@ -102,7 +109,6 @@ my_saved_libs="$LIBS" LIBS= PANDORA_REQUIRE_PTHREAD LIBS="$my_saved_libs" -PANDORA_CXX_DEMANGLE dnl Specialty checks DETECT_BYTEORDER diff --git a/example/interface_v0.c b/example/interface_v0.c index 3ca4daff..74a98eaf 100644 --- a/example/interface_v0.c +++ b/example/interface_v0.c @@ -52,7 +52,7 @@ static protocol_binary_response_status quit_command_handler(const void *cookie, response_handler(cookie, header, (void*)&response); /* I need a better way to signal to close the connection */ - return PROTOCOL_BINARY_RESPONSE_EIO; + return PROTOCOL_BINARY_RESPONSE_EINTERNAL; } static protocol_binary_response_status get_command_handler(const void *cookie, diff --git a/libhashkit/function.c b/libhashkit/function.c index 2e68b583..a779bb63 100644 --- a/libhashkit/function.c +++ b/libhashkit/function.c @@ -51,9 +51,10 @@ static hashkit_return_t _set_function(struct hashkit_function_st *self, hashkit_ self->function= hashkit_jenkins; break; case HASHKIT_HASH_CUSTOM: + return HASHKIT_INVALID_ARGUMENT; case HASHKIT_HASH_MAX: default: - return HASHKIT_FAILURE; + return HASHKIT_INVALID_HASH; } self->context= NULL; diff --git a/libhashkit/strerror.c b/libhashkit/strerror.c index ac51f996..50532e1d 100644 --- a/libhashkit/strerror.c +++ b/libhashkit/strerror.c @@ -13,15 +13,13 @@ const char *hashkit_strerror(hashkit_st *ptr, hashkit_return_t rc) (void)ptr; switch (rc) { - case HASHKIT_SUCCESS: - return "SUCCESS"; - case HASHKIT_FAILURE: - return "FAILURE"; - case HASHKIT_MEMORY_ALLOCATION_FAILURE: - return "MEMORY ALLOCATION FAILURE"; + case HASHKIT_SUCCESS: return "SUCCESS"; + case HASHKIT_FAILURE: return "FAILURE"; + case HASHKIT_MEMORY_ALLOCATION_FAILURE: return "MEMORY ALLOCATION FAILURE"; + case HASHKIT_INVALID_ARGUMENT: return "INVALID ARGUMENT"; + case HASHKIT_INVALID_HASH: return "INVALID hashkit_hash_algorithm_t"; case HASHKIT_MAXIMUM_RETURN: - return "Gibberish returned!"; default: - return "Gibberish returned!"; + return "INVALID hashkit_return_t"; } } diff --git a/libhashkit/types.h b/libhashkit/types.h index 8d396962..255620b8 100644 --- a/libhashkit/types.h +++ b/libhashkit/types.h @@ -19,6 +19,8 @@ typedef enum { HASHKIT_SUCCESS, HASHKIT_FAILURE, HASHKIT_MEMORY_ALLOCATION_FAILURE, + HASHKIT_INVALID_HASH, + HASHKIT_INVALID_ARGUMENT, HASHKIT_MAXIMUM_RETURN /* Always add new error code before */ } hashkit_return_t; diff --git a/libmemcached/array.c b/libmemcached/array.c new file mode 100644 index 00000000..2412369e --- /dev/null +++ b/libmemcached/array.c @@ -0,0 +1,109 @@ +/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: + * + * LibMemcached + * + * Copyright (C) 2011 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. + * + */ + +#include "libmemcached/common.h" + +struct memcached_array_st +{ + memcached_st *root; + size_t size; + char c_str[]; +}; + +memcached_array_st *memcached_array_clone(memcached_st *memc, const memcached_array_st *original) +{ + if (! original) + return NULL; + + return memcached_strcpy(memc, original->c_str, original->size); +} + +memcached_array_st *memcached_strcpy(memcached_st *memc, const char *str, size_t str_length) +{ + memcached_array_st *array= (struct memcached_array_st *)libmemcached_malloc(memc, sizeof(struct memcached_array_st) +str_length +1); + + if (! array) + return NULL; + + array->root= memc; + array->size= str_length -1; // We don't count the NULL ending + memcpy(array->c_str, str, str_length); + array->c_str[str_length]= 0; + + return array; +} + +memcached_string_t memcached_array_to_string(memcached_array_st *array) +{ + memcached_string_t tmp; + tmp.c_str= array->c_str; + tmp.size= array->size; + + return tmp; +} + +void memcached_array_free(memcached_array_st *array) +{ + if (! array) + return; + + WATCHPOINT_ASSERT(array->root); + if (array && array->root) + { + libmemcached_free(array->root, array); + } + else if (array) + { + free(array); + } +} + +size_t memcached_array_size(memcached_array_st *array) +{ + if (! array) + return 0; + + return array->size; +} + +const char *memcached_array_string(memcached_array_st *array) +{ + if (! array) + return NULL; + + return array->c_str; +} diff --git a/libmemcached/array.h b/libmemcached/array.h new file mode 100644 index 00000000..ddc97d5a --- /dev/null +++ b/libmemcached/array.h @@ -0,0 +1,72 @@ +/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: + * + * LibMemcached + * + * Copyright (C) 2011 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. + * + */ + +#pragma once + +#ifdef __cplusplus +extern "C" { +#endif + +LIBMEMCACHED_LOCAL +memcached_array_st *memcached_array_clone(memcached_st *memc, const memcached_array_st *original); + +LIBMEMCACHED_LOCAL +memcached_array_st *memcached_strcpy(memcached_st *memc, const char *str, size_t str_length); + +LIBMEMCACHED_LOCAL +void memcached_array_free(memcached_array_st *array); + +LIBMEMCACHED_LOCAL +size_t memcached_array_size(memcached_array_st *array); + +LIBMEMCACHED_LOCAL +const char *memcached_array_string(memcached_array_st *array); + +LIBMEMCACHED_LOCAL +memcached_string_t memcached_array_to_string(memcached_array_st *array); + +#ifdef __cplusplus +} // extern "C" +#endif + +#ifdef __cplusplus +#define memcached_print_array(X) static_cast(memcached_array_size(X)), memcached_array_string(X) +#define memcached_param_array(X) memcached_array_string(X), memcached_array_size(X) +#else +#define memcached_print_array(X) (int)memcached_array_size((X)), memcached_array_string((X)) +#define memcached_param_array(X) memcached_array_string(X), memcached_array_size(X) +#endif diff --git a/libmemcached/auto.c b/libmemcached/auto.c index a221144f..7bd0cc12 100644 --- a/libmemcached/auto.c +++ b/libmemcached/auto.c @@ -9,7 +9,7 @@ * */ -#include "common.h" +#include "libmemcached/common.h" static memcached_return_t text_incr_decr(memcached_st *ptr, const char *verb, @@ -24,8 +24,8 @@ static memcached_return_t text_incr_decr(memcached_st *ptr, memcached_server_write_instance_st instance; bool no_reply= ptr->flags.no_reply; - unlikely (memcached_server_count(ptr) == 0) - return MEMCACHED_NO_SERVERS; + if (memcached_server_count(ptr) == 0) + return memcached_set_error(ptr, MEMCACHED_NO_SERVERS, NULL); if (ptr->flags.verify_key && (memcached_key_test((const char **)&key, &key_length, 1) == MEMCACHED_BAD_KEY_PROVIDED)) return MEMCACHED_BAD_KEY_PROVIDED; @@ -36,8 +36,7 @@ static memcached_return_t text_incr_decr(memcached_st *ptr, int send_length; send_length= snprintf(buffer, MEMCACHED_DEFAULT_COMMAND_SIZE, "%s %.*s%.*s %" PRIu64 "%s\r\n", verb, - (int)ptr->prefix_key_length, - ptr->prefix_key, + memcached_print_array(ptr->prefix_key), (int)key_length, key, offset, no_reply ? " noreply" : ""); if (send_length >= MEMCACHED_DEFAULT_COMMAND_SIZE || send_length < 0) @@ -91,8 +90,8 @@ static memcached_return_t binary_incr_decr(memcached_st *ptr, uint8_t cmd, memcached_server_write_instance_st instance; bool no_reply= ptr->flags.no_reply; - unlikely (memcached_server_count(ptr) == 0) - return MEMCACHED_NO_SERVERS; + if (memcached_server_count(ptr) == 0) + return memcached_set_error(ptr, MEMCACHED_NO_SERVERS, NULL); server_key= memcached_generate_hash_with_redistribution(ptr, master_key, master_key_length); instance= memcached_server_instance_fetch(ptr, server_key); @@ -108,10 +107,10 @@ static memcached_return_t binary_incr_decr(memcached_st *ptr, uint8_t cmd, request.message.header.request.magic= PROTOCOL_BINARY_REQ; request.message.header.request.opcode= cmd; - request.message.header.request.keylen= htons((uint16_t)(key_length + ptr->prefix_key_length)); + request.message.header.request.keylen= htons((uint16_t)(key_length + memcached_array_size(ptr->prefix_key))); request.message.header.request.extlen= 20; request.message.header.request.datatype= PROTOCOL_BINARY_RAW_BYTES; - request.message.header.request.bodylen= htonl((uint32_t)(key_length + ptr->prefix_key_length + request.message.header.request.extlen)); + request.message.header.request.bodylen= htonl((uint32_t)(key_length + memcached_array_size(ptr->prefix_key) +request.message.header.request.extlen)); request.message.body.delta= htonll(offset); request.message.body.initial= htonll(initial); request.message.body.expiration= htonl((uint32_t) expiration); @@ -119,7 +118,7 @@ static memcached_return_t binary_incr_decr(memcached_st *ptr, uint8_t cmd, struct libmemcached_io_vector_st vector[]= { { .length= sizeof(request.bytes), .buffer= request.bytes }, - { .length= ptr->prefix_key_length, .buffer= ptr->prefix_key }, + { .length= memcached_array_size(ptr->prefix_key), .buffer= ptr->prefix_key }, { .length= key_length, .buffer= key } }; @@ -140,6 +139,10 @@ memcached_return_t memcached_increment(memcached_st *ptr, uint32_t offset, uint64_t *value) { + uint64_t local_value; + if (! value) + value= &local_value; + return memcached_increment_by_key(ptr, key, key_length, key, key_length, offset, value); } @@ -148,6 +151,10 @@ memcached_return_t memcached_decrement(memcached_st *ptr, uint32_t offset, uint64_t *value) { + uint64_t local_value; + if (! value) + value= &local_value; + return memcached_decrement_by_key(ptr, key, key_length, key, key_length, offset, value); } @@ -161,6 +168,10 @@ memcached_return_t memcached_increment_by_key(memcached_st *ptr, unlikely (rc != MEMCACHED_SUCCESS) return rc; + uint64_t local_value; + if (! value) + value= &local_value; + LIBMEMCACHED_MEMCACHED_INCREMENT_START(); if (ptr->flags.binary_protocol) { @@ -189,6 +200,10 @@ memcached_return_t memcached_decrement_by_key(memcached_st *ptr, unlikely (rc != MEMCACHED_SUCCESS) return rc; + uint64_t local_value; + if (! value) + value= &local_value; + LIBMEMCACHED_MEMCACHED_DECREMENT_START(); if (ptr->flags.binary_protocol) { @@ -215,6 +230,10 @@ memcached_return_t memcached_increment_with_initial(memcached_st *ptr, time_t expiration, uint64_t *value) { + uint64_t local_value; + if (! value) + value= &local_value; + return memcached_increment_with_initial_by_key(ptr, key, key_length, key, key_length, offset, initial, expiration, value); @@ -234,6 +253,10 @@ memcached_return_t memcached_increment_with_initial_by_key(memcached_st *ptr, unlikely (rc != MEMCACHED_SUCCESS) return rc; + uint64_t local_value; + if (! value) + value= &local_value; + LIBMEMCACHED_MEMCACHED_INCREMENT_WITH_INITIAL_START(); if (ptr->flags.binary_protocol) rc= binary_incr_decr(ptr, PROTOCOL_BINARY_CMD_INCREMENT, @@ -256,6 +279,10 @@ memcached_return_t memcached_decrement_with_initial(memcached_st *ptr, time_t expiration, uint64_t *value) { + uint64_t local_value; + if (! value) + value= &local_value; + return memcached_decrement_with_initial_by_key(ptr, key, key_length, key, key_length, offset, initial, expiration, value); @@ -275,6 +302,10 @@ memcached_return_t memcached_decrement_with_initial_by_key(memcached_st *ptr, unlikely (rc != MEMCACHED_SUCCESS) return rc; + uint64_t local_value; + if (! value) + value= &local_value; + LIBMEMCACHED_MEMCACHED_INCREMENT_WITH_INITIAL_START(); if (ptr->flags.binary_protocol) { diff --git a/libmemcached/auto.h b/libmemcached/auto.h index 227be9df..aa1b23dc 100644 --- a/libmemcached/auto.h +++ b/libmemcached/auto.h @@ -17,66 +17,69 @@ extern "C" { #endif LIBMEMCACHED_API -memcached_return_t memcached_increment(memcached_st *ptr, - const char *key, size_t key_length, - uint32_t offset, - uint64_t *value); + memcached_return_t memcached_increment(memcached_st *ptr, + const char *key, size_t key_length, + uint32_t offset, + uint64_t *value); LIBMEMCACHED_API -memcached_return_t memcached_decrement(memcached_st *ptr, - const char *key, size_t key_length, - uint32_t offset, - uint64_t *value); + memcached_return_t memcached_decrement(memcached_st *ptr, + const char *key, size_t key_length, + uint32_t offset, + uint64_t *value); LIBMEMCACHED_API -memcached_return_t memcached_increment_by_key(memcached_st *ptr, - const char *master_key, size_t master_key_length, - const char *key, size_t key_length, - uint64_t offset, - uint64_t *value); + memcached_return_t memcached_increment_by_key(memcached_st *ptr, + const char *master_key, size_t master_key_length, + const char *key, size_t key_length, + uint64_t offset, + uint64_t *value); LIBMEMCACHED_API -memcached_return_t memcached_decrement_by_key(memcached_st *ptr, - const char *master_key, size_t master_key_length, - const char *key, size_t key_length, - uint64_t offset, - uint64_t *value); + memcached_return_t memcached_decrement_by_key(memcached_st *ptr, + const char *master_key, size_t master_key_length, + const char *key, size_t key_length, + uint64_t offset, + uint64_t *value); LIBMEMCACHED_API -memcached_return_t memcached_increment_with_initial(memcached_st *ptr, - const char *key, - size_t key_length, - uint64_t offset, - uint64_t initial, - time_t expiration, - uint64_t *value); + memcached_return_t memcached_increment_with_initial(memcached_st *ptr, + const char *key, + size_t key_length, + uint64_t offset, + uint64_t initial, + time_t expiration, + uint64_t *value); + LIBMEMCACHED_API -memcached_return_t memcached_decrement_with_initial(memcached_st *ptr, - const char *key, - size_t key_length, - uint64_t offset, - uint64_t initial, - time_t expiration, - uint64_t *value); + memcached_return_t memcached_decrement_with_initial(memcached_st *ptr, + const char *key, + size_t key_length, + uint64_t offset, + uint64_t initial, + time_t expiration, + uint64_t *value); + LIBMEMCACHED_API -memcached_return_t memcached_increment_with_initial_by_key(memcached_st *ptr, - const char *master_key, - size_t master_key_length, - const char *key, - size_t key_length, - uint64_t offset, - uint64_t initial, - time_t expiration, - uint64_t *value); + memcached_return_t memcached_increment_with_initial_by_key(memcached_st *ptr, + const char *master_key, + size_t master_key_length, + const char *key, + size_t key_length, + uint64_t offset, + uint64_t initial, + time_t expiration, + uint64_t *value); + LIBMEMCACHED_API -memcached_return_t memcached_decrement_with_initial_by_key(memcached_st *ptr, - const char *master_key, - size_t master_key_length, - const char *key, - size_t key_length, - uint64_t offset, - uint64_t initial, - time_t expiration, - uint64_t *value); + memcached_return_t memcached_decrement_with_initial_by_key(memcached_st *ptr, + const char *master_key, + size_t master_key_length, + const char *key, + size_t key_length, + uint64_t offset, + uint64_t initial, + time_t expiration, + uint64_t *value); #ifdef __cplusplus } diff --git a/libmemcached/behavior.c b/libmemcached/behavior.c index 2b6ccdf9..0df96033 100644 --- a/libmemcached/behavior.c +++ b/libmemcached/behavior.c @@ -9,7 +9,9 @@ * */ -#include "common.h" +#include +#include + #include #include @@ -94,26 +96,16 @@ memcached_return_t memcached_behavior_set(memcached_st *ptr, return memcached_behavior_set_distribution(ptr, (memcached_server_distribution_t)data); case MEMCACHED_BEHAVIOR_KETAMA: { - if (data) - { - (void)memcached_behavior_set_key_hash(ptr, MEMCACHED_HASH_MD5); - (void)memcached_behavior_set_distribution_hash(ptr, MEMCACHED_HASH_MD5); - (void)memcached_behavior_set_distribution(ptr, MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA); - } - else - { - (void)memcached_behavior_set_key_hash(ptr, MEMCACHED_HASH_DEFAULT); - (void)memcached_behavior_set_distribution_hash(ptr, MEMCACHED_HASH_DEFAULT); - (void)memcached_behavior_set_distribution(ptr, MEMCACHED_DISTRIBUTION_MODULA); - } + if (data) // Turn on + return memcached_behavior_set_distribution(ptr, MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA); - break; + return memcached_behavior_set_distribution(ptr, MEMCACHED_DISTRIBUTION_MODULA); } case MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED: { (void)memcached_behavior_set_key_hash(ptr, MEMCACHED_HASH_MD5); (void)memcached_behavior_set_distribution_hash(ptr, MEMCACHED_HASH_MD5); - ptr->flags.ketama_weighted= set_flag(data); + ptr->ketama.weighted= set_flag(data); /** @note We try to keep the same distribution going. This should be deprecated and rewritten. */ @@ -129,7 +121,8 @@ memcached_return_t memcached_behavior_set(memcached_st *ptr, break; case MEMCACHED_BEHAVIOR_VERIFY_KEY: if (ptr->flags.binary_protocol) - return MEMCACHED_FAILURE; + return memcached_set_error_string(ptr, MEMCACHED_FAILURE, + memcached_string_with_size("MEMCACHED_BEHAVIOR_VERIFY_KEY if the binary protocol has been enabled.")); ptr->flags.verify_key= set_flag(data); break; case MEMCACHED_BEHAVIOR_SORT_HOSTS: @@ -161,7 +154,8 @@ memcached_return_t memcached_behavior_set(memcached_st *ptr, memcached_quit(ptr); break; case MEMCACHED_BEHAVIOR_USER_DATA: - return MEMCACHED_FAILURE; + return memcached_set_error_string(ptr, MEMCACHED_FAILURE, + memcached_string_with_size("MEMCACHED_BEHAVIOR_USER_DATA deprecated.")); case MEMCACHED_BEHAVIOR_HASH_WITH_PREFIX_KEY: ptr->flags.hash_with_prefix_key= set_flag(data); break; @@ -177,61 +171,23 @@ memcached_return_t memcached_behavior_set(memcached_st *ptr, break; case MEMCACHED_BEHAVIOR_CORK: { - memcached_server_write_instance_st instance; - bool action= set_flag(data); - - if (action == false) - { - ptr->flags.cork= set_flag(false); - return MEMCACHED_SUCCESS; - } - - instance= memcached_server_instance_fetch(ptr, 0); - if (! instance) - return MEMCACHED_NO_SERVERS; - - - /* We just try the first host, and if it is down we return zero */ - memcached_return_t rc; - rc= memcached_connect(instance); - if (rc != MEMCACHED_SUCCESS) - { - return rc; - } - - /* Now we test! */ - memcached_ternary_t enabled; - enabled= test_cork(instance, true); - - switch (enabled) - { - case MEM_FALSE: - return ptr->cached_errno ? MEMCACHED_ERRNO : MEMCACHED_FAILURE ; - case MEM_TRUE: - { - enabled= test_cork(instance, false); - - if (enabled == false) // Possible bug in OS? - { - memcached_quit_server(instance, false); // We should reset everything on this error. - return MEMCACHED_ERRNO; // Errno will be true because we will have already set it. - } - ptr->flags.cork= true; - ptr->flags.tcp_nodelay= true; - memcached_quit(ptr); // We go on and reset the connections. - } - break; - case MEM_NOT: - default: - return MEMCACHED_NOT_SUPPORTED; - } +#ifdef HAVE_MSG_MORE + break; +#else + return memcached_set_error_string(ptr, MEMCACHED_NOT_SUPPORTED, + memcached_string_with_size("MEMCACHED_BEHAVIOR_CORK is not supported on this platform.")); +#endif } break; + case MEMCACHED_BEHAVIOR_LOAD_FROM_FILE: + return memcached_set_error_string(ptr, MEMCACHED_INVALID_ARGUMENTS, + memcached_string_with_size("MEMCACHED_BEHAVIOR_LOAD_FROM_FILE can not be set with memcached_behavior_set()")); case MEMCACHED_BEHAVIOR_MAX: default: /* Shouldn't get here */ WATCHPOINT_ASSERT(0); - return MEMCACHED_FAILURE; + return memcached_set_error_string(ptr, MEMCACHED_INVALID_ARGUMENTS, + memcached_string_with_size("Invalid behavior passed to memcached_behavior_set()")); } return MEMCACHED_SUCCESS; @@ -272,7 +228,7 @@ uint64_t memcached_behavior_get(memcached_st *ptr, case MEMCACHED_BEHAVIOR_VERIFY_KEY: return ptr->flags.verify_key; case MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED: - return ptr->flags.ketama_weighted; + return ptr->ketama.weighted; case MEMCACHED_BEHAVIOR_DISTRIBUTION: return ptr->distribution; case MEMCACHED_BEHAVIOR_KETAMA: @@ -324,7 +280,7 @@ uint64_t memcached_behavior_get(memcached_st *ptr, if (getsockopt(instance->fd, SOL_SOCKET, SO_SNDBUF, &sock_size, &sock_length) < 0) { - ptr->cached_errno= errno; + memcached_set_errno(ptr, errno, NULL); return 0; /* Zero means error */ } } @@ -360,7 +316,7 @@ uint64_t memcached_behavior_get(memcached_st *ptr, if (getsockopt(instance->fd, SOL_SOCKET, SO_RCVBUF, &sock_size, &sock_length) < 0) { - ptr->cached_errno= errno; + memcached_set_errno(ptr, errno, NULL); return 0; /* Zero means error */ } @@ -369,7 +325,8 @@ uint64_t memcached_behavior_get(memcached_st *ptr, return (uint64_t) sock_size; } case MEMCACHED_BEHAVIOR_USER_DATA: - return MEMCACHED_FAILURE; + return memcached_set_error_string(ptr, MEMCACHED_FAILURE, + memcached_string_with_size("MEMCACHED_BEHAVIOR_USER_DATA deprecated.")); case MEMCACHED_BEHAVIOR_HASH_WITH_PREFIX_KEY: return ptr->flags.hash_with_prefix_key; case MEMCACHED_BEHAVIOR_NOREPLY: @@ -379,9 +336,15 @@ uint64_t memcached_behavior_get(memcached_st *ptr, case MEMCACHED_BEHAVIOR_RANDOMIZE_REPLICA_READ: return ptr->flags.randomize_replica_read; case MEMCACHED_BEHAVIOR_CORK: - return ptr->flags.cork; +#ifdef HAVE_MSG_MORE + return true; +#else + return false; +#endif case MEMCACHED_BEHAVIOR_TCP_KEEPALIVE: return ptr->flags.tcp_keepalive; + case MEMCACHED_BEHAVIOR_LOAD_FROM_FILE: + return ptr->configure.filename ? true : false; case MEMCACHED_BEHAVIOR_MAX: default: WATCHPOINT_ASSERT(0); /* Programming mistake if it gets this far */ @@ -396,15 +359,21 @@ memcached_return_t memcached_behavior_set_distribution(memcached_st *ptr, memcac { if (type < MEMCACHED_DISTRIBUTION_CONSISTENT_MAX) { + if (MEMCACHED_DISTRIBUTION_CONSISTENT_WEIGHTED) + { + ptr->ketama.weighted= true; + } + else + { + ptr->ketama.weighted= false; + } ptr->distribution= type; run_distribution(ptr); - } - else - { - return MEMCACHED_FAILURE; + return MEMCACHED_SUCCESS; } - return MEMCACHED_SUCCESS; + return memcached_set_error_string(ptr, MEMCACHED_INVALID_ARGUMENTS, + memcached_string_with_size("Invalid memcached_server_distribution_t")); } @@ -415,10 +384,11 @@ memcached_server_distribution_t memcached_behavior_get_distribution(memcached_st memcached_return_t memcached_behavior_set_key_hash(memcached_st *ptr, memcached_hash_t type) { - hashkit_return_t rc; - rc= hashkit_set_function(&ptr->hashkit, (hashkit_hash_algorithm_t)type); + if (hashkit_set_function(&ptr->hashkit, (hashkit_hash_algorithm_t)type) == HASHKIT_SUCCESS) + return MEMCACHED_SUCCESS; - return rc == HASHKIT_SUCCESS ? MEMCACHED_SUCCESS : MEMCACHED_FAILURE; + return memcached_set_error_string(ptr, MEMCACHED_INVALID_ARGUMENTS, + memcached_string_with_size("Invalid memcached_hash_t()")); } memcached_hash_t memcached_behavior_get_key_hash(memcached_st *ptr) @@ -428,13 +398,106 @@ memcached_hash_t memcached_behavior_get_key_hash(memcached_st *ptr) memcached_return_t memcached_behavior_set_distribution_hash(memcached_st *ptr, memcached_hash_t type) { - hashkit_return_t rc; - rc= hashkit_set_function(&ptr->distribution_hashkit, (hashkit_hash_algorithm_t)type); + if (hashkit_set_function(&ptr->distribution_hashkit, (hashkit_hash_algorithm_t)type) == HASHKIT_SUCCESS) + return MEMCACHED_SUCCESS; - return rc == HASHKIT_SUCCESS ? MEMCACHED_SUCCESS : MEMCACHED_FAILURE; + return memcached_set_error_string(ptr, MEMCACHED_INVALID_ARGUMENTS, + memcached_string_with_size("Invalid memcached_hash_t()")); } memcached_hash_t memcached_behavior_get_distribution_hash(memcached_st *ptr) { return (memcached_hash_t)hashkit_get_function(&ptr->distribution_hashkit); } + +const char *libmemcached_string_behavior(const memcached_behavior_t flag) +{ + switch (flag) + { + case MEMCACHED_BEHAVIOR_NO_BLOCK: return "MEMCACHED_BEHAVIOR_NO_BLOCK"; + case MEMCACHED_BEHAVIOR_TCP_NODELAY: return "MEMCACHED_BEHAVIOR_TCP_NODELAY"; + case MEMCACHED_BEHAVIOR_HASH: return "MEMCACHED_BEHAVIOR_HASH"; + case MEMCACHED_BEHAVIOR_KETAMA: return "MEMCACHED_BEHAVIOR_KETAMA"; + case MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE: return "MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE"; + case MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE: return "MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE"; + case MEMCACHED_BEHAVIOR_CACHE_LOOKUPS: return "MEMCACHED_BEHAVIOR_CACHE_LOOKUPS"; + case MEMCACHED_BEHAVIOR_SUPPORT_CAS: return "MEMCACHED_BEHAVIOR_SUPPORT_CAS"; + case MEMCACHED_BEHAVIOR_POLL_TIMEOUT: return "MEMCACHED_BEHAVIOR_POLL_TIMEOUT"; + case MEMCACHED_BEHAVIOR_DISTRIBUTION: return "MEMCACHED_BEHAVIOR_DISTRIBUTION"; + case MEMCACHED_BEHAVIOR_BUFFER_REQUESTS: return "MEMCACHED_BEHAVIOR_BUFFER_REQUESTS"; + case MEMCACHED_BEHAVIOR_USER_DATA: return "MEMCACHED_BEHAVIOR_USER_DATA"; + case MEMCACHED_BEHAVIOR_SORT_HOSTS: return "MEMCACHED_BEHAVIOR_SORT_HOSTS"; + case MEMCACHED_BEHAVIOR_VERIFY_KEY: return "MEMCACHED_BEHAVIOR_VERIFY_KEY"; + case MEMCACHED_BEHAVIOR_CONNECT_TIMEOUT: return "MEMCACHED_BEHAVIOR_CONNECT_TIMEOUT"; + case MEMCACHED_BEHAVIOR_RETRY_TIMEOUT: return "MEMCACHED_BEHAVIOR_RETRY_TIMEOUT"; + case MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED: return "MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED"; + case MEMCACHED_BEHAVIOR_KETAMA_HASH: return "MEMCACHED_BEHAVIOR_KETAMA_HASH"; + case MEMCACHED_BEHAVIOR_BINARY_PROTOCOL: return "MEMCACHED_BEHAVIOR_BINARY_PROTOCOL"; + case MEMCACHED_BEHAVIOR_SND_TIMEOUT: return "MEMCACHED_BEHAVIOR_SND_TIMEOUT"; + case MEMCACHED_BEHAVIOR_RCV_TIMEOUT: return "MEMCACHED_BEHAVIOR_RCV_TIMEOUT"; + case MEMCACHED_BEHAVIOR_SERVER_FAILURE_LIMIT: return "MEMCACHED_BEHAVIOR_SERVER_FAILURE_LIMIT"; + case MEMCACHED_BEHAVIOR_IO_MSG_WATERMARK: return "MEMCACHED_BEHAVIOR_IO_MSG_WATERMARK"; + case MEMCACHED_BEHAVIOR_IO_BYTES_WATERMARK: return "MEMCACHED_BEHAVIOR_IO_BYTES_WATERMARK"; + case MEMCACHED_BEHAVIOR_IO_KEY_PREFETCH: return "MEMCACHED_BEHAVIOR_IO_KEY_PREFETCH"; + case MEMCACHED_BEHAVIOR_HASH_WITH_PREFIX_KEY: return "MEMCACHED_BEHAVIOR_HASH_WITH_PREFIX_KEY"; + case MEMCACHED_BEHAVIOR_NOREPLY: return "MEMCACHED_BEHAVIOR_NOREPLY"; + case MEMCACHED_BEHAVIOR_USE_UDP: return "MEMCACHED_BEHAVIOR_USE_UDP"; + case MEMCACHED_BEHAVIOR_AUTO_EJECT_HOSTS: return "MEMCACHED_BEHAVIOR_AUTO_EJECT_HOSTS"; + case MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS: return "MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS"; + case MEMCACHED_BEHAVIOR_RANDOMIZE_REPLICA_READ: return "MEMCACHED_BEHAVIOR_RANDOMIZE_REPLICA_READ"; + case MEMCACHED_BEHAVIOR_CORK: return "MEMCACHED_BEHAVIOR_CORK"; + case MEMCACHED_BEHAVIOR_TCP_KEEPALIVE: return "MEMCACHED_BEHAVIOR_TCP_KEEPALIVE"; + case MEMCACHED_BEHAVIOR_TCP_KEEPIDLE: return "MEMCACHED_BEHAVIOR_TCP_KEEPIDLE"; + case MEMCACHED_BEHAVIOR_LOAD_FROM_FILE: return "MEMCACHED_BEHAVIOR_LOAD_FROM_FILE"; + default: + case MEMCACHED_BEHAVIOR_MAX: return "INVALID memcached_behavior_t"; + } +} + +const char *libmemcached_string_distribution(const memcached_server_distribution_t flag) +{ + switch (flag) + { + case MEMCACHED_DISTRIBUTION_MODULA: return "MEMCACHED_DISTRIBUTION_MODULA"; + case MEMCACHED_DISTRIBUTION_CONSISTENT: return "MEMCACHED_DISTRIBUTION_CONSISTENT"; + case MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA: return "MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA"; + case MEMCACHED_DISTRIBUTION_RANDOM: return "MEMCACHED_DISTRIBUTION_RANDOM"; + case MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA_SPY: return "MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA_SPY"; + case MEMCACHED_DISTRIBUTION_CONSISTENT_WEIGHTED: return "MEMCACHED_DISTRIBUTION_CONSISTENT_WEIGHTED"; + case MEMCACHED_DISTRIBUTION_VIRTUAL_BUCKET: return "MEMCACHED_DISTRIBUTION_VIRTUAL_BUCKET"; + default: + case MEMCACHED_DISTRIBUTION_CONSISTENT_MAX: return "INVALID memcached_server_distribution_t"; + } +} + +memcached_return_t memcached_bucket_set(memcached_st *self, + const uint32_t *host_map, + const uint32_t *forward_map, + const uint32_t buckets, + const uint32_t replicas) +{ + memcached_return_t rc; + + if (! self) + return MEMCACHED_INVALID_ARGUMENTS; + + if (! host_map) + return MEMCACHED_INVALID_ARGUMENTS; + + memcached_server_distribution_t old; + old= memcached_behavior_get_distribution(self); + + rc =memcached_behavior_set_distribution(self, MEMCACHED_DISTRIBUTION_VIRTUAL_BUCKET); + if (rc != MEMCACHED_SUCCESS) + { + return rc; + } + + rc= memcached_virtual_bucket_create(self, host_map, forward_map, buckets, replicas); + if (rc != MEMCACHED_SUCCESS) + { + memcached_behavior_set_distribution(self, old); + } + + return rc; +} diff --git a/libmemcached/behavior.h b/libmemcached/behavior.h index 39a430d7..ca6fb492 100644 --- a/libmemcached/behavior.h +++ b/libmemcached/behavior.h @@ -43,6 +43,18 @@ memcached_hash_t memcached_behavior_get_distribution_hash(memcached_st *ptr); LIBMEMCACHED_LOCAL bool _is_auto_eject_host(const memcached_st *ptr); +LIBMEMCACHED_LOCAL + const char *libmemcached_string_behavior(const memcached_behavior_t flag); + +LIBMEMCACHED_LOCAL + const char *libmemcached_string_distribution(const memcached_server_distribution_t flag); + +LIBMEMCACHED_API + memcached_return_t memcached_bucket_set(memcached_st *self, + const uint32_t *host_map, + const uint32_t *forward_map, + const uint32_t buckets, + const uint32_t replicas); #ifdef __cplusplus } diff --git a/libmemcached/callback.c b/libmemcached/callback.c index aba1a383..dcb3ddeb 100644 --- a/libmemcached/callback.c +++ b/libmemcached/callback.c @@ -9,7 +9,7 @@ * */ -#include "common.h" +#include "libmemcached/common.h" #include /* @@ -24,35 +24,7 @@ memcached_return_t memcached_callback_set(memcached_st *ptr, { case MEMCACHED_CALLBACK_PREFIX_KEY: { - char *key= (char *)data; - - if (key) - { - size_t key_length= strlen(key); - - if (memcached_key_test((const char **)&key, &key_length, 1) == MEMCACHED_BAD_KEY_PROVIDED) - { - return MEMCACHED_BAD_KEY_PROVIDED; - } - - if ((key_length > MEMCACHED_PREFIX_KEY_MAX_SIZE -1) - || (strncpy(ptr->prefix_key, key, MEMCACHED_PREFIX_KEY_MAX_SIZE) == NULL)) - { - ptr->prefix_key_length= 0; - return MEMCACHED_BAD_KEY_PROVIDED; - } - else - { - ptr->prefix_key_length= key_length; - } - } - else - { - ptr->prefix_key[0]= 0; - ptr->prefix_key_length= 0; - } - - break; + return memcached_set_prefix_key(ptr, (char*)data, data ? strlen((char*)data) : 0); } case MEMCACHED_CALLBACK_USER_DATA: { @@ -124,10 +96,10 @@ void *memcached_callback_get(memcached_st *ptr, { case MEMCACHED_CALLBACK_PREFIX_KEY: { - if (ptr->prefix_key_length) + if (ptr->prefix_key) { *error= MEMCACHED_SUCCESS; - return (void *)ptr->prefix_key; + return (void *)memcached_array_string(ptr->prefix_key); } else { diff --git a/libmemcached/common.h b/libmemcached/common.h index a7d95af7..e350149b 100644 --- a/libmemcached/common.h +++ b/libmemcached/common.h @@ -1,11 +1,38 @@ -/* LibMemcached - * Copyright (C) 2006-2009 Brian Aker - * All rights reserved. +/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: + * + * LibMemcached * - * Use and distribution licensed under the BSD license. See - * the COPYING file in the parent directory for full text. + * Copyright (C) 2011 Data Differential, http://datadifferential.com/ + * Copyright (C) 2006-2009 Brian Aker + * All rights reserved. * - * Summary: + * 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. * */ @@ -13,10 +40,9 @@ Common include file for libmemached */ -#ifndef __LIBMEMCACHED_COMMON_H__ -#define __LIBMEMCACHED_COMMON_H__ +#pragma once -#include "config.h" +#include #include #include @@ -47,6 +73,8 @@ #include "libmemcached/memcached.h" #include "libmemcached/watchpoint.h" +#include "libmemcached/is.h" +#include "libmemcached/prefix_key.h" typedef struct memcached_server_st * memcached_server_write_instance_st; @@ -65,10 +93,12 @@ memcached_return_t memcached_server_execute(memcached_st *ptr, #include "libmemcached/io.h" #include "libmemcached/do.h" #include "libmemcached/internal.h" +#include "libmemcached/array.h" #include "libmemcached/libmemcached_probes.h" #include "libmemcached/memcached/protocol_binary.h" #include "libmemcached/byteorder.h" #include "libmemcached/response.h" +#include "libmemcached/prefix_key.h" /* string value */ struct memcached_continuum_item_st @@ -77,14 +107,6 @@ struct memcached_continuum_item_st uint32_t value; }; -/* Yum, Fortran.... can you make the reference? */ -typedef enum { - MEM_NOT= -1, - MEM_FALSE= false, - MEM_TRUE= true -} memcached_ternary_t; - - #if !defined(__GNUC__) || (__GNUC__ == 2 && __GNUC_MINOR__ < 96) #define likely(x) if((x)) @@ -115,16 +137,6 @@ memcached_return_t run_distribution(memcached_st *ptr); #define memcached_server_response_decrement(A) (A)->cursor_active-- #define memcached_server_response_reset(A) (A)->cursor_active=0 -// These are private -#define memcached_is_allocated(__object) ((__object)->options.is_allocated) -#define memcached_is_initialized(__object) ((__object)->options.is_initialized) -#define memcached_is_purging(__object) ((__object)->state.is_purging) -#define memcached_is_processing_input(__object) ((__object)->state.is_processing_input) -#define memcached_set_purging(__object, __value) ((__object)->state.is_purging= (__value)) -#define memcached_set_processing_input(__object, __value) ((__object)->state.is_processing_input= (__value)) -#define memcached_set_initialized(__object, __value) ((__object)->options.is_initialized(= (__value)) -#define memcached_set_allocated(__object, __value) ((__object)->options.is_allocated(= (__value)) - LIBMEMCACHED_LOCAL void set_last_disconnected_host(memcached_server_write_instance_st ptr); @@ -164,44 +176,6 @@ static inline memcached_return_t memcached_validate_key_length(size_t key_length return MEMCACHED_SUCCESS; } -#ifdef TCP_CORK - #define CORK TCP_CORK -#elif defined TCP_NOPUSH - #define CORK TCP_NOPUSH -#endif - -/* - test_cork() tries to enable TCP_CORK. IF TCP_CORK is not an option - on the system it returns false but sets errno to 0. Otherwise on - failure errno is set. -*/ -static inline memcached_ternary_t test_cork(memcached_server_st *ptr, int enable) -{ -#ifdef CORK - if (ptr->type != MEMCACHED_CONNECTION_TCP) - return MEM_FALSE; - - int err= setsockopt(ptr->fd, IPPROTO_TCP, CORK, - &enable, (socklen_t)sizeof(int)); - if (! err) - { - return MEM_TRUE; - } - - perror(strerror(errno)); - ptr->cached_errno= errno; - - return MEM_FALSE; -#else - (void)ptr; - (void)enable; - - ptr->cached_errno= 0; - - return MEM_NOT; -#endif -} - static inline void libmemcached_free(const memcached_st *ptr, void *mem) { ptr->allocators.free(ptr, mem, ptr->allocators.context); @@ -225,5 +199,3 @@ static inline void *libmemcached_calloc(const memcached_st *ptr, size_t nelem, s #ifdef __cplusplus } #endif - -#endif /* __LIBMEMCACHED_COMMON_H__ */ diff --git a/libmemcached/constants.h b/libmemcached/constants.h index b12a3890..e2d69448 100644 --- a/libmemcached/constants.h +++ b/libmemcached/constants.h @@ -9,6 +9,7 @@ * */ +#pragma once #ifndef __LIBMEMCACHED_CONSTANTS_H__ #define __LIBMEMCACHED_CONSTANTS_H__ @@ -29,7 +30,7 @@ #define MEMCACHED_VERSION_STRING_LENGTH 24 -typedef enum { +enum memcached_return_t { MEMCACHED_SUCCESS, MEMCACHED_FAILURE, MEMCACHED_HOST_LOOKUP_FAILURE, @@ -73,18 +74,30 @@ typedef enum { MEMCACHED_AUTH_PROBLEM, MEMCACHED_AUTH_FAILURE, MEMCACHED_AUTH_CONTINUE, + MEMCACHED_PARSE_ERROR, + MEMCACHED_PARSE_USER_ERROR, MEMCACHED_MAXIMUM_RETURN /* Always add new error code before */ -} memcached_return_t; +}; +#ifndef __cplusplus +typedef enum memcached_return_t memcached_return_t; +#endif -typedef enum { + +enum memcached_server_distribution_t { MEMCACHED_DISTRIBUTION_MODULA, MEMCACHED_DISTRIBUTION_CONSISTENT, MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA, MEMCACHED_DISTRIBUTION_RANDOM, MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA_SPY, + MEMCACHED_DISTRIBUTION_CONSISTENT_WEIGHTED, + MEMCACHED_DISTRIBUTION_VIRTUAL_BUCKET, MEMCACHED_DISTRIBUTION_CONSISTENT_MAX -} memcached_server_distribution_t; +}; + +#ifndef __cplusplus +typedef enum memcached_server_distribution_t memcached_server_distribution_t; +#endif typedef enum { MEMCACHED_BEHAVIOR_NO_BLOCK, @@ -121,6 +134,7 @@ typedef enum { MEMCACHED_BEHAVIOR_CORK, MEMCACHED_BEHAVIOR_TCP_KEEPALIVE, MEMCACHED_BEHAVIOR_TCP_KEEPIDLE, + MEMCACHED_BEHAVIOR_LOAD_FROM_FILE, MEMCACHED_BEHAVIOR_MAX } memcached_behavior_t; diff --git a/libmemcached/delete.c b/libmemcached/delete.c index ef1fa6da..2f205cd6 100644 --- a/libmemcached/delete.c +++ b/libmemcached/delete.c @@ -92,8 +92,7 @@ memcached_return_t memcached_delete_by_key(memcached_st *ptr, } send_length= snprintf(buffer, MEMCACHED_DEFAULT_COMMAND_SIZE, "delete %.*s%.*s %u%s\r\n", - (int)ptr->prefix_key_length, - ptr->prefix_key, + memcached_print_array(ptr->prefix_key), (int) key_length, key, (uint32_t)expiration, no_reply ? " noreply" :"" ); @@ -103,8 +102,7 @@ memcached_return_t memcached_delete_by_key(memcached_st *ptr, { send_length= snprintf(buffer, MEMCACHED_DEFAULT_COMMAND_SIZE, "delete %.*s%.*s%s\r\n", - (int)ptr->prefix_key_length, - ptr->prefix_key, + memcached_print_array(ptr->prefix_key), (int)key_length, key, no_reply ? " noreply" :""); } @@ -163,9 +161,9 @@ static inline memcached_return_t binary_delete(memcached_st *ptr, request.message.header.request.opcode= PROTOCOL_BINARY_CMD_DELETEQ; else request.message.header.request.opcode= PROTOCOL_BINARY_CMD_DELETE; - request.message.header.request.keylen= htons((uint16_t)(key_length + ptr->prefix_key_length)); + request.message.header.request.keylen= htons((uint16_t)(key_length + memcached_array_size(ptr->prefix_key))); request.message.header.request.datatype= PROTOCOL_BINARY_RAW_BYTES; - request.message.header.request.bodylen= htonl((uint32_t)(key_length + ptr->prefix_key_length)); + request.message.header.request.bodylen= htonl((uint32_t)(key_length + memcached_array_size(ptr->prefix_key))); if (ptr->flags.use_udp && ! flush) { @@ -179,7 +177,7 @@ static inline memcached_return_t binary_delete(memcached_st *ptr, struct libmemcached_io_vector_st vector[]= { { .length= sizeof(request.bytes), .buffer= request.bytes}, - { .length= ptr->prefix_key_length, .buffer= ptr->prefix_key }, + { .length= memcached_array_size(ptr->prefix_key), .buffer= memcached_array_string(ptr->prefix_key) }, { .length= key_length, .buffer= key }, }; diff --git a/libmemcached/error.c b/libmemcached/error.c new file mode 100644 index 00000000..86f58e60 --- /dev/null +++ b/libmemcached/error.c @@ -0,0 +1,203 @@ +/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: + * + * LibMemcached + * + * Copyright (C) 2011 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. + * + */ + +#include "libmemcached/common.h" + +struct memcached_error_st +{ + memcached_st *root; + struct memcached_error_st *next; + memcached_return_t rc; + int local_errno; + size_t size; + char c_str[]; +}; + +static memcached_error_st *_set(memcached_st *memc, memcached_string_t *str) +{ + if (! memc) + return NULL; + + memcached_error_st *error; + error= (struct memcached_error_st *)libmemcached_malloc(memc, sizeof(struct memcached_error_st) +(str ? str->size :0) +1); + + if (! error) + return NULL; + + error->root= memc; + + if (str) + { + error->size= str->size; + memcpy(error->c_str, str->c_str, str->size); + error->c_str[str->size]= 0; + } + else + { + error->size= 0; + } + + error->next= memc->error_messages; + memc->error_messages= error; + + return error; +} + +memcached_return_t memcached_set_error_string(memcached_st *memc, memcached_return_t rc, const char *str, size_t length) +{ + memcached_string_t tmp; + tmp.c_str= str; + tmp.size= length; + return memcached_set_error(memc, rc, &tmp); +} + +memcached_return_t memcached_set_error(memcached_st *memc, memcached_return_t rc, memcached_string_t *str) +{ + if (rc == MEMCACHED_SUCCESS) + return MEMCACHED_SUCCESS; + + memcached_error_st *error= _set(memc, str); + + if (error) + { + error->local_errno= 0; + error->rc= rc; + } + + return rc; +} + +memcached_return_t memcached_set_errno(memcached_st *memc, int local_errno, memcached_string_t *str) +{ + memcached_error_st *error= _set(memc, str); + + if (error) + { + error->local_errno= local_errno; + error->rc= MEMCACHED_ERRNO; + } + + return error->rc; +} + +static void _error_print(const memcached_error_st *error) +{ + if (! error) + return; + + if (! error->size) + { + fprintf(stderr, "%s\n", memcached_strerror(NULL, error->rc) ); + } + else + { + fprintf(stderr, "%s %s\n", memcached_strerror(NULL, error->rc), error->c_str); + } + + _error_print(error->next); +} + +void memcached_error_print(const memcached_st *self) +{ + if (! self) + return; + + _error_print(self->error_messages); +} + +static void _error_free(memcached_error_st *error) +{ + if (! error) + return; + + _error_free(error->next); + + if (error && error->root) + { + libmemcached_free(error->root, error); + } + else if (error) + { + free(error); + } +} + +void memcached_error_free(memcached_st *self) +{ + if (! self) + return; + + _error_free(self->error_messages); +} + +const char *memcached_last_error_message(memcached_st *memc) +{ + if (! memc) + return memcached_strerror(memc, MEMCACHED_INVALID_ARGUMENTS); + + if (! memc->error_messages) + return memcached_strerror(memc, MEMCACHED_SUCCESS); + + if (! memc->error_messages->size) + { + return memcached_strerror(memc, memc->error_messages->rc); + } + + return memc->error_messages->c_str; +} + +memcached_return_t memcached_last_error(memcached_st *memc) +{ + if (! memc) + return MEMCACHED_INVALID_ARGUMENTS; + + if (! memc->error_messages) + return MEMCACHED_SUCCESS; + + return memc->error_messages->rc; +} + +int memcached_last_error_errno(memcached_st *memc) +{ + if (! memc) + return 0; + + if (! memc->error_messages) + return 0; + + return memc->error_messages->local_errno; +} diff --git a/libmemcached/error.h b/libmemcached/error.h new file mode 100644 index 00000000..f8320802 --- /dev/null +++ b/libmemcached/error.h @@ -0,0 +1,71 @@ +/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: + * + * LibMemcached + * + * Copyright (C) 2011 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. + * + */ + +#pragma once + +#ifdef __cplusplus +extern "C" { +#endif + +LIBMEMCACHED_LOCAL + memcached_return_t memcached_set_error(memcached_st *memc, memcached_return_t rc, memcached_string_t *str); + +LIBMEMCACHED_LOCAL + memcached_return_t memcached_set_error_string(memcached_st *memc, memcached_return_t rc, const char *str, size_t length); + +LIBMEMCACHED_LOCAL + memcached_return_t memcached_set_errno(memcached_st *memc, int local_errno, memcached_string_t *str); + +LIBMEMCACHED_LOCAL + void memcached_error_free(memcached_st *error); + +LIBMEMCACHED_API + const char *memcached_last_error_message(memcached_st *memc); + +LIBMEMCACHED_API + void memcached_error_print(const memcached_st *self); + +LIBMEMCACHED_API + memcached_return_t memcached_last_error(memcached_st *memc); + +LIBMEMCACHED_API + int memcached_last_error_errno(memcached_st *memc); + + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/libmemcached/get.c b/libmemcached/get.c index aa4e6f53..7cb5ec04 100644 --- a/libmemcached/get.c +++ b/libmemcached/get.c @@ -232,7 +232,7 @@ static memcached_return_t memcached_mget_by_key_real(memcached_st *ptr, struct libmemcached_io_vector_st vector[]= { { .length= get_command_length, .buffer= get_command }, - { .length= ptr->prefix_key_length, .buffer= ptr->prefix_key }, + { .length= memcached_array_size(ptr->prefix_key), .buffer= memcached_array_string(ptr->prefix_key) }, { .length= key_length[x], .buffer= keys[x] }, { .length= 1, .buffer= " " } }; @@ -374,7 +374,7 @@ static memcached_return_t simple_binary_mget(memcached_st *ptr, { memcached_return_t rc= MEMCACHED_NOTFOUND; - int flush= number_of_keys == 1; + bool flush= (number_of_keys == 1); /* If a server fails we warn about errors and start all over with sending keys @@ -423,14 +423,14 @@ static memcached_return_t simple_binary_mget(memcached_st *ptr, return vk; } - request.message.header.request.keylen= htons((uint16_t)(key_length[x] + ptr->prefix_key_length)); + request.message.header.request.keylen= htons((uint16_t)(key_length[x] + memcached_array_size(ptr->prefix_key))); request.message.header.request.datatype= PROTOCOL_BINARY_RAW_BYTES; - request.message.header.request.bodylen= htonl((uint32_t)( key_length[x] + ptr->prefix_key_length)); + request.message.header.request.bodylen= htonl((uint32_t)( key_length[x] + memcached_array_size(ptr->prefix_key))); struct libmemcached_io_vector_st vector[]= { { .length= sizeof(request.bytes), .buffer= request.bytes }, - { .length= ptr->prefix_key_length, .buffer= ptr->prefix_key }, + { .length= memcached_array_size(ptr->prefix_key), .buffer= memcached_array_string(ptr->prefix_key) }, { .length= key_length[x], .buffer= keys[x] } }; @@ -545,9 +545,9 @@ static memcached_return_t replication_binary_mget(memcached_st *ptr, .message.header.request= { .magic= PROTOCOL_BINARY_REQ, .opcode= PROTOCOL_BINARY_CMD_GETK, - .keylen= htons((uint16_t)(key_length[x] + ptr->prefix_key_length)), + .keylen= htons((uint16_t)(key_length[x] + memcached_array_size(ptr->prefix_key))), .datatype= PROTOCOL_BINARY_RAW_BYTES, - .bodylen= htonl((uint32_t)(key_length[x] + ptr->prefix_key_length)) + .bodylen= htonl((uint32_t)(key_length[x] + memcached_array_size(ptr->prefix_key))) } }; @@ -564,7 +564,7 @@ static memcached_return_t replication_binary_mget(memcached_st *ptr, struct libmemcached_io_vector_st vector[]= { { .length= sizeof(request.bytes), .buffer= request.bytes }, - { .length= ptr->prefix_key_length, .buffer= ptr->prefix_key }, + { .length= memcached_array_size(ptr->prefix_key), .buffer= memcached_array_string(ptr->prefix_key) }, { .length= key_length[x], .buffer= keys[x] } }; diff --git a/libmemcached/hash.c b/libmemcached/hash.c index dda30395..bf946423 100644 --- a/libmemcached/hash.c +++ b/libmemcached/hash.c @@ -1,15 +1,43 @@ -/* LibMemcached - * Copyright (C) 2006-2010 Brian Aker - * All rights reserved. +/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: + * + * Libmemcached library * - * Use and distribution licensed under the BSD license. See - * the COPYING file in the parent directory for full text. + * Copyright (C) 2011 Data Differential, http://datadifferential.com/ + * Copyright (C) 2006-2009 Brian Aker All rights reserved. * - * Summary: + * 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 "common.h" + +#include +#include uint32_t memcached_generate_hash_value(const char *key, size_t key_length, memcached_hash_t hash_algorithm) @@ -27,16 +55,17 @@ static uint32_t dispatch_host(const memcached_st *ptr, uint32_t hash) switch (ptr->distribution) { case MEMCACHED_DISTRIBUTION_CONSISTENT: + case MEMCACHED_DISTRIBUTION_CONSISTENT_WEIGHTED: case MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA: case MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA_SPY: { - uint32_t num= ptr->continuum_points_counter; + uint32_t num= ptr->ketama.continuum_points_counter; WATCHPOINT_ASSERT(ptr->continuum); hash= hash; memcached_continuum_item_st *begin, *end, *left, *right, *middle; - begin= left= ptr->continuum; - end= right= ptr->continuum + num; + begin= left= ptr->ketama.continuum; + end= right= ptr->ketama.continuum + num; while (left < right) { @@ -54,8 +83,12 @@ static uint32_t dispatch_host(const memcached_st *ptr, uint32_t hash) return hash % memcached_server_count(ptr); case MEMCACHED_DISTRIBUTION_RANDOM: return (uint32_t) random() % memcached_server_count(ptr); - case MEMCACHED_DISTRIBUTION_CONSISTENT_MAX: + case MEMCACHED_DISTRIBUTION_VIRTUAL_BUCKET: + { + return memcached_virtual_bucket_get(ptr, hash); + } default: + case MEMCACHED_DISTRIBUTION_CONSISTENT_MAX: WATCHPOINT_ASSERT(0); /* We have added a distribution without extending the logic */ return hash % memcached_server_count(ptr); } @@ -74,14 +107,14 @@ static inline uint32_t _generate_hash_wrapper(const memcached_st *ptr, const cha if (ptr->flags.hash_with_prefix_key) { - size_t temp_length= ptr->prefix_key_length + key_length; + size_t temp_length= memcached_array_size(ptr->prefix_key) + key_length; char temp[temp_length]; if (temp_length > MEMCACHED_MAX_KEY -1) return 0; - strncpy(temp, ptr->prefix_key, ptr->prefix_key_length); - strncpy(temp + ptr->prefix_key_length, key, key_length); + strncpy(temp, memcached_array_string(ptr->prefix_key), memcached_array_size(ptr->prefix_key)); + strncpy(temp + memcached_array_size(ptr->prefix_key), key, key_length); return generate_hash(ptr, temp, temp_length); } @@ -93,12 +126,12 @@ static inline uint32_t _generate_hash_wrapper(const memcached_st *ptr, const cha static inline void _regen_for_auto_eject(memcached_st *ptr) { - if (_is_auto_eject_host(ptr) && ptr->next_distribution_rebuild) + if (_is_auto_eject_host(ptr) && ptr->ketama.next_distribution_rebuild) { struct timeval now; if (gettimeofday(&now, NULL) == 0 && - now.tv_sec > ptr->next_distribution_rebuild) + now.tv_sec > ptr->ketama.next_distribution_rebuild) { run_distribution(ptr); } @@ -136,3 +169,23 @@ memcached_return_t memcached_set_hashkit(memcached_st *self, hashkit_st *hashk) return MEMCACHED_SUCCESS; } + +const char * libmemcached_string_hash(memcached_hash_t type) +{ + switch (type) + { + case MEMCACHED_HASH_DEFAULT: return "MEMCACHED_HASH_DEFAULT"; + case MEMCACHED_HASH_MD5: return "MEMCACHED_HASH_MD5"; + case MEMCACHED_HASH_CRC: return "MEMCACHED_HASH_CRC"; + case MEMCACHED_HASH_FNV1_64: return "MEMCACHED_HASH_FNV1_64"; + case MEMCACHED_HASH_FNV1A_64: return "MEMCACHED_HASH_FNV1A_64"; + case MEMCACHED_HASH_FNV1_32: return "MEMCACHED_HASH_FNV1_32"; + case MEMCACHED_HASH_FNV1A_32: return "MEMCACHED_HASH_FNV1A_32"; + case MEMCACHED_HASH_HSIEH: return "MEMCACHED_HASH_HSIEH"; + case MEMCACHED_HASH_MURMUR: return "MEMCACHED_HASH_MURMUR"; + case MEMCACHED_HASH_JENKINS: return "MEMCACHED_HASH_JENKINS"; + case MEMCACHED_HASH_CUSTOM: return "MEMCACHED_HASH_CUSTOM"; + default: + case MEMCACHED_HASH_MAX: return "INVALID memcached_hash_t"; + } +} diff --git a/libmemcached/hash.h b/libmemcached/hash.h index 0e664266..f36ad286 100644 --- a/libmemcached/hash.h +++ b/libmemcached/hash.h @@ -1,11 +1,37 @@ -/* LibMemcached - * Copyright (C) 2010 Brian Aker - * All rights reserved. +/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: + * + * Libmemcached library * - * Use and distribution licensed under the BSD license. See - * the COPYING file in the parent directory for full text. + * Copyright (C) 2011 Data Differential, http://datadifferential.com/ + * Copyright (C) 2006-2009 Brian Aker All rights reserved. * - * Summary: hash interface code + * 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. * */ @@ -35,6 +61,9 @@ uint32_t memcached_generate_hash_with_redistribution(memcached_st *ptr, const ch LIBMEMCACHED_API void memcached_autoeject(memcached_st *ptr); +LIBMEMCACHED_API + const char * libmemcached_string_hash(memcached_hash_t type); + #ifdef __cplusplus } #endif diff --git a/libmemcached/hosts.c b/libmemcached/hosts.c index 9723f8b6..d1fe29b8 100644 --- a/libmemcached/hosts.c +++ b/libmemcached/hosts.c @@ -17,6 +17,7 @@ static memcached_return_t server_add(memcached_st *ptr, const char *hostname, in_port_t port, uint32_t weight, memcached_connection_t type); + static memcached_return_t update_continuum(memcached_st *ptr); static int compare_servers(const void *p1, const void *p2) @@ -58,7 +59,9 @@ memcached_return_t run_distribution(memcached_st *ptr) case MEMCACHED_DISTRIBUTION_CONSISTENT: case MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA: case MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA_SPY: + case MEMCACHED_DISTRIBUTION_CONSISTENT_WEIGHTED: return update_continuum(ptr); + case MEMCACHED_DISTRIBUTION_VIRTUAL_BUCKET: case MEMCACHED_DISTRIBUTION_MODULA: break; case MEMCACHED_DISTRIBUTION_RANDOM: @@ -118,7 +121,7 @@ static memcached_return_t update_continuum(memcached_st *ptr) if (gettimeofday(&now, NULL) != 0) { - ptr->cached_errno = errno; + memcached_set_errno(ptr, errno, NULL); return MEMCACHED_ERRNO; } @@ -129,15 +132,15 @@ static memcached_return_t update_continuum(memcached_st *ptr) if (is_auto_ejecting) { live_servers= 0; - ptr->next_distribution_rebuild= 0; + ptr->ketama.next_distribution_rebuild= 0; for (host_index= 0; host_index < memcached_server_count(ptr); ++host_index) { if (list[host_index].next_retry <= now.tv_sec) live_servers++; else { - if (ptr->next_distribution_rebuild == 0 || list[host_index].next_retry < ptr->next_distribution_rebuild) - ptr->next_distribution_rebuild= list[host_index].next_retry; + if (ptr->ketama.next_distribution_rebuild == 0 || list[host_index].next_retry < ptr->ketama.next_distribution_rebuild) + ptr->ketama.next_distribution_rebuild= list[host_index].next_retry; } } } @@ -152,18 +155,18 @@ static memcached_return_t update_continuum(memcached_st *ptr) if (live_servers == 0) return MEMCACHED_SUCCESS; - if (live_servers > ptr->continuum_count) + if (live_servers > ptr->ketama.continuum_count) { memcached_continuum_item_st *new_ptr; - new_ptr= libmemcached_realloc(ptr, ptr->continuum, + new_ptr= libmemcached_realloc(ptr, ptr->ketama.continuum, sizeof(memcached_continuum_item_st) * (live_servers + MEMCACHED_CONTINUUM_ADDITION) * points_per_server); if (new_ptr == 0) return MEMCACHED_MEMORY_ALLOCATION_FAILURE; - ptr->continuum= new_ptr; - ptr->continuum_count= live_servers + MEMCACHED_CONTINUUM_ADDITION; + ptr->ketama.continuum= new_ptr; + ptr->ketama.continuum_count= live_servers + MEMCACHED_CONTINUUM_ADDITION; } if (is_ketama_weighted) @@ -231,15 +234,15 @@ static memcached_return_t update_continuum(memcached_st *ptr) for (uint32_t x= 0; x < pointer_per_hash; x++) { value= ketama_server_hash(sort_host, (size_t)sort_host_length, x); - ptr->continuum[continuum_index].index= host_index; - ptr->continuum[continuum_index++].value= value; + ptr->ketama.continuum[continuum_index].index= host_index; + ptr->ketama.continuum[continuum_index++].value= value; } } else { value= hashkit_digest(&ptr->distribution_hashkit, sort_host, (size_t)sort_host_length); - ptr->continuum[continuum_index].index= host_index; - ptr->continuum[continuum_index++].value= value; + ptr->ketama.continuum[continuum_index].index= host_index; + ptr->ketama.continuum[continuum_index++].value= value; } } } @@ -280,15 +283,15 @@ static memcached_return_t update_continuum(memcached_st *ptr) for (uint32_t x = 0; x < pointer_per_hash; x++) { value= ketama_server_hash(sort_host, (size_t)sort_host_length, x); - ptr->continuum[continuum_index].index= host_index; - ptr->continuum[continuum_index++].value= value; + ptr->ketama.continuum[continuum_index].index= host_index; + ptr->ketama.continuum[continuum_index++].value= value; } } else { value= hashkit_digest(&ptr->distribution_hashkit, sort_host, (size_t)sort_host_length); - ptr->continuum[continuum_index].index= host_index; - ptr->continuum[continuum_index++].value= value; + ptr->ketama.continuum[continuum_index].index= host_index; + ptr->ketama.continuum[continuum_index++].value= value; } } } @@ -299,8 +302,8 @@ static memcached_return_t update_continuum(memcached_st *ptr) WATCHPOINT_ASSERT(ptr); WATCHPOINT_ASSERT(ptr->continuum); WATCHPOINT_ASSERT(memcached_server_count(ptr) * MEMCACHED_POINTS_PER_SERVER <= MEMCACHED_CONTINUUM_SIZE); - ptr->continuum_points_counter= pointer_counter; - qsort(ptr->continuum, ptr->continuum_points_counter, sizeof(memcached_continuum_item_st), continuum_item_cmp); + ptr->ketama.continuum_points_counter= pointer_counter; + qsort(ptr->ketama.continuum, ptr->ketama.continuum_points_counter, sizeof(memcached_continuum_item_st), continuum_item_cmp); #ifdef DEBUG for (pointer_index= 0; memcached_server_count(ptr) && pointer_index < ((live_servers * MEMCACHED_POINTS_PER_SERVER) - 1); pointer_index++) @@ -449,3 +452,20 @@ static memcached_return_t server_add(memcached_st *ptr, const char *hostname, return run_distribution(ptr); } + +memcached_return_t memcached_server_add_parsed(memcached_st *ptr, + const char *hostname, + size_t hostname_length, + in_port_t port, + uint32_t weight) +{ + char buffer[NI_MAXHOST]; + + memcpy(buffer, hostname, hostname_length); + buffer[hostname_length]= 0; + + return server_add(ptr, buffer, + port, + weight, + MEMCACHED_CONNECTION_TCP); +} diff --git a/libmemcached/include.am b/libmemcached/include.am index 7d4841f8..42e251d6 100644 --- a/libmemcached/include.am +++ b/libmemcached/include.am @@ -2,6 +2,10 @@ # included from Top Level Makefile.am # All paths should be given relative to the root +libmemcached_libmemcached_la_SOURCES = + +include libmemcached/options/include.am + EXTRA_DIST+= \ libmemcached/configure.h.in \ libmemcached/libmemcached_probes.d \ @@ -13,15 +17,18 @@ noinst_HEADERS+= \ libmemcached/do.h \ libmemcached/internal.h \ libmemcached/io.h \ + libmemcached/is.h \ libmemcached/libmemcached_probes.h \ libmemcached/protocol/ascii_handler.h \ libmemcached/protocol/binary_handler.h \ libmemcached/protocol/common.h \ - libmemcached/response.h + libmemcached/response.h \ + libmemcached/virtual_bucket.h nobase_include_HEADERS+= \ libmemcached/allocators.h \ libmemcached/analyze.h \ + libmemcached/array.h \ libmemcached/auto.h \ libmemcached/behavior.h \ libmemcached/callback.h \ @@ -29,6 +36,7 @@ nobase_include_HEADERS+= \ libmemcached/constants.h \ libmemcached/delete.h \ libmemcached/dump.h \ + libmemcached/error.h \ libmemcached/exception.hpp \ libmemcached/fetch.h \ libmemcached/flush.h \ @@ -38,12 +46,15 @@ nobase_include_HEADERS+= \ libmemcached/memcached.h \ libmemcached/memcached.hpp \ libmemcached/memcached/protocol_binary.h \ + libmemcached/memcached/vbucket.h \ + libmemcached/options.h \ libmemcached/parse.h \ - libmemcached/platform.h \ + libmemcached/prefix_key.h \ libmemcached/protocol/cache.h \ libmemcached/protocol/callback.h \ libmemcached/protocol_handler.h \ libmemcached/quit.h \ + libmemcached/platform.h \ libmemcached/result.h \ libmemcached/sasl.h \ libmemcached/server.h \ @@ -80,13 +91,15 @@ libmemcached_libmemcachedcallbacks_la_SOURCES = libmemcached/callback.c # These symbols will not be exposed in the shipped .so noinst_LTLIBRARIES+= libmemcached/libmemcachedinternal.la libmemcached_libmemcachedinternal_la_SOURCES= \ + libmemcached/error.c \ libmemcached/string.c lib_LTLIBRARIES+= libmemcached/libmemcached.la libmemcached_libmemcached_la_CFLAGS= ${AM_CFLAGS} ${NO_CONVERSION} -libmemcached_libmemcached_la_SOURCES = \ +libmemcached_libmemcached_la_SOURCES+= \ libmemcached/allocators.c \ libmemcached/analyze.c \ + libmemcached/array.c \ libmemcached/auto.c \ libmemcached/behavior.c \ libmemcached/connect.c \ @@ -102,7 +115,9 @@ libmemcached_libmemcached_la_SOURCES = \ libmemcached/io.c \ libmemcached/key.c \ libmemcached/memcached.c \ + libmemcached/options.cc \ libmemcached/parse.c \ + libmemcached/prefix_key.cc \ libmemcached/purge.c \ libmemcached/quit.c \ libmemcached/response.c \ @@ -113,7 +128,10 @@ libmemcached_libmemcached_la_SOURCES = \ libmemcached/storage.c \ libmemcached/strerror.c \ libmemcached/verbosity.c \ - libmemcached/version.c + libmemcached/version.c \ + libmemcached/virtual_bucket.c + +libmemcached/options.cc: libmemcached/options/parser.h libmemcached_libmemcached_la_DEPENDENCIES= libmemcached/libmemcachedcallbacks.la libmemcached/libmemcachedinternal.la libhashkit/libhashkitinc.la diff --git a/libmemcached/io.c b/libmemcached/io.c index dedcdaf9..5acbbd52 100644 --- a/libmemcached/io.c +++ b/libmemcached/io.c @@ -1,16 +1,43 @@ -/* LibMemcached - * Copyright (C) 2006-2009 Brian Aker - * All rights reserved. +/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: + * + * LibMemcached * - * Use and distribution licensed under the BSD license. See - * the COPYING file in the parent directory for full text. + * Copyright (C) 2011 Data Differential, http://datadifferential.com/ + * Copyright (C) 2006-2009 Brian Aker + * All rights reserved. * - * Summary: Server IO, Not public! + * 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 "common.h" +#include "libmemcached/common.h" typedef enum { MEM_READ, @@ -18,6 +45,7 @@ typedef enum { } memc_read_or_write; static ssize_t io_flush(memcached_server_write_instance_st ptr, + const bool with_flush, memcached_return_t *error); static void increment_udp_message_id(memcached_server_write_instance_st ptr); @@ -199,40 +227,6 @@ static bool process_input_buffer(memcached_server_write_instance_st ptr) return false; } -static inline void memcached_io_cork_push(memcached_server_st *ptr) -{ - (void)ptr; -#ifdef CORK - if (ptr->root->flags.cork == false || ptr->state.is_corked) - return; - - int enable= 1; - int err= setsockopt(ptr->fd, IPPROTO_TCP, CORK, - &enable, (socklen_t)sizeof(int)); - if (! err) - ptr->state.is_corked= true; - - WATCHPOINT_ASSERT(ptr->state.is_corked == true); -#endif -} - -static inline void memcached_io_cork_pop(memcached_server_st *ptr) -{ - (void)ptr; -#ifdef CORK - if (ptr->root->flags.cork == false || ptr->state.is_corked == false) - return; - - int enable= 0; - int err= setsockopt(ptr->fd, IPPROTO_TCP, CORK, - &enable, (socklen_t)sizeof(int)); - if (! err) - ptr->state.is_corked= false; - - WATCHPOINT_ASSERT(ptr->state.is_corked == false); -#endif -} - #if 0 // Dead code, this should be removed. void memcached_io_preread(memcached_st *ptr) { @@ -368,12 +362,6 @@ static ssize_t _io_write(memcached_server_write_instance_st ptr, original_length= length; buffer_ptr= buffer; - /* more writable data is coming if a flush isn't required, so delay send */ - if (! with_flush) - { - memcached_io_cork_push(ptr); - } - while (length) { char *write_ptr; @@ -409,7 +397,7 @@ static ssize_t _io_write(memcached_server_write_instance_st ptr, ssize_t sent_length; WATCHPOINT_ASSERT(ptr->fd != INVALID_SOCKET); - sent_length= io_flush(ptr, &rc); + sent_length= io_flush(ptr, with_flush, &rc); if (sent_length == -1) { return -1; @@ -427,12 +415,10 @@ static ssize_t _io_write(memcached_server_write_instance_st ptr, { memcached_return_t rc; WATCHPOINT_ASSERT(ptr->fd != INVALID_SOCKET); - if (io_flush(ptr, &rc) == -1) + if (io_flush(ptr, with_flush, &rc) == -1) { return -1; } - - memcached_io_cork_pop(ptr); } return (ssize_t) original_length; @@ -541,7 +527,7 @@ memcached_server_write_instance_st memcached_io_get_readable_server(memcached_st int err= poll(fds, host_index, memc->poll_timeout); switch (err) { case -1: - memc->cached_errno = get_socket_errno(); + memcached_set_errno(memc, get_socket_errno(), NULL); /* FALLTHROUGH */ case 0: break; @@ -566,6 +552,7 @@ memcached_server_write_instance_st memcached_io_get_readable_server(memcached_st } static ssize_t io_flush(memcached_server_write_instance_st ptr, + const bool with_flush, memcached_return_t *error) { /* @@ -618,8 +605,16 @@ static ssize_t io_flush(memcached_server_write_instance_st ptr, if (ptr->type == MEMCACHED_CONNECTION_UDP) increment_udp_message_id(ptr); - WATCHPOINT_ASSERT(ptr->fd != -1); - sent_length= send(ptr->fd, local_write_ptr, write_length, MSG_NOSIGNAL|MSG_DONTWAIT); + WATCHPOINT_ASSERT(ptr->fd != INVALID_SOCKET); + if (with_flush) + { + sent_length= send(ptr->fd, local_write_ptr, write_length, MSG_NOSIGNAL|MSG_DONTWAIT); + } + else + { + sent_length= send(ptr->fd, local_write_ptr, write_length, MSG_NOSIGNAL|MSG_DONTWAIT|MSG_MORE); + } + if (sent_length == SOCKET_ERROR) { ptr->cached_errno= get_socket_errno(); diff --git a/libmemcached/io.h b/libmemcached/io.h index 3662954d..85d56b16 100644 --- a/libmemcached/io.h +++ b/libmemcached/io.h @@ -1,11 +1,38 @@ -/* LibMemcached - * Copyright (C) 2006-2009 Brian Aker - * All rights reserved. +/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: + * + * LibMemcached * - * Use and distribution licensed under the BSD license. See - * the COPYING file in the parent directory for full text. + * Copyright (C) 2011 Data Differential, http://datadifferential.com/ + * Copyright (C) 2006-2009 Brian Aker + * All rights reserved. * - * Summary: Server IO, Not public! + * 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. * */ @@ -16,10 +43,6 @@ #include "libmemcached/memcached.h" -#ifdef __cplusplus -extern "C" { -#endif - #define MAX_UDP_DATAGRAM_LENGTH 1400 #define UDP_DATAGRAM_HEADER_LENGTH 8 #define UDP_REQUEST_ID_MSG_SIG_DIGITS 10 @@ -46,6 +69,10 @@ struct libmemcached_io_vector_st const void *buffer; }; +#ifdef __cplusplus +extern "C" { +#endif + LIBMEMCACHED_LOCAL memcached_return_t memcached_io_wait_for_write(memcached_server_write_instance_st ptr); diff --git a/libmemcached/is.h b/libmemcached/is.h new file mode 100644 index 00000000..f155334b --- /dev/null +++ b/libmemcached/is.h @@ -0,0 +1,48 @@ +/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: + * + * LibMemcached + * + * Copyright (C) 2011 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. + * + */ + +#pragma once + +/* These are private */ +#define memcached_is_allocated(__object) ((__object)->options.is_allocated) +#define memcached_is_initialized(__object) ((__object)->options.is_initialized) +#define memcached_is_purging(__object) ((__object)->state.is_purging) +#define memcached_is_processing_input(__object) ((__object)->state.is_processing_input) +#define memcached_set_purging(__object, __value) ((__object)->state.is_purging= (__value)) +#define memcached_set_processing_input(__object, __value) ((__object)->state.is_processing_input= (__value)) +#define memcached_set_initialized(__object, __value) ((__object)->options.is_initialized(= (__value)) +#define memcached_set_allocated(__object, __value) ((__object)->options.is_allocated= (__value)) diff --git a/libmemcached/memcached.c b/libmemcached/memcached.c index 81895afa..149437af 100644 --- a/libmemcached/memcached.c +++ b/libmemcached/memcached.c @@ -1,15 +1,42 @@ -/* LibMemcached - * Copyright (C) 2006-2010 Brian Aker - * All rights reserved. +/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: + * + * Libmemcached library * - * Use and distribution licensed under the BSD license. See - * the COPYING file in the parent directory for full text. + * Copyright (C) 2011 Data Differential, http://datadifferential.com/ + * Copyright (C) 2006-2009 Brian Aker All rights reserved. * - * Summary: + * 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 "common.h" +#include +#include static const memcached_st global_copy= { .state= { @@ -21,9 +48,7 @@ static const memcached_st global_copy= { .auto_eject_hosts= false, .binary_protocol= false, .buffer_requests= false, - .cork= false, .hash_with_prefix_key= false, - .ketama_weighted= false, .no_block= false, .no_reply= false, .randomize_replica_read= false, @@ -34,14 +59,15 @@ static const memcached_st global_copy= { .use_sort_hosts= false, .use_udp= false, .verify_key= false, - .tcp_keepalive= false - } + .tcp_keepalive= false, + }, }; static inline bool _memcached_init(memcached_st *self) { self->state= global_copy.state; self->flags= global_copy.flags; + self->virtual_bucket= NULL; self->distribution= MEMCACHED_DISTRIBUTION_MODULA; @@ -50,7 +76,11 @@ static inline bool _memcached_init(memcached_st *self) if (! hash_ptr) return false; - self->continuum_points_counter= 0; + self->ketama.continuum= NULL; + self->ketama.continuum_count= 0; + self->ketama.continuum_points_counter= 0; + self->ketama.next_distribution_rebuild= 0; + self->ketama.weighted= false; self->number_of_hosts= 0; self->servers= NULL; @@ -67,23 +97,18 @@ static inline bool _memcached_init(memcached_st *self) self->tcp_keepidle= 0; self->io_key_prefetch= 0; - self->cached_errno= 0; self->poll_timeout= MEMCACHED_DEFAULT_TIMEOUT; self->connect_timeout= MEMCACHED_DEFAULT_CONNECT_TIMEOUT; self->retry_timeout= 0; - self->continuum_count= 0; self->send_size= -1; self->recv_size= -1; self->user_data= NULL; - self->next_distribution_rebuild= 0; - self->prefix_key_length= 0; self->number_of_replicas= 0; hash_ptr= hashkit_create(&self->distribution_hashkit); if (! hash_ptr) return false; - self->continuum= NULL; self->allocators= memcached_allocators_return_default(); @@ -95,9 +120,55 @@ static inline bool _memcached_init(memcached_st *self) self->sasl.callbacks= NULL; self->sasl.is_allocated= false; + self->error_messages= NULL; + self->prefix_key= NULL; + self->configure.filename= NULL; + return true; } +static void _free(memcached_st *ptr, bool release_st) +{ + /* If we have anything open, lets close it now */ + memcached_quit(ptr); + memcached_server_list_free(memcached_server_list(ptr)); + memcached_result_free(&ptr->result); + + memcached_virtual_bucket_free(ptr); + + if (ptr->last_disconnected_server) + memcached_server_free(ptr->last_disconnected_server); + + if (ptr->on_cleanup) + ptr->on_cleanup(ptr); + + if (ptr->ketama.continuum) + libmemcached_free(ptr, ptr->ketama.continuum); + + memcached_array_free(ptr->prefix_key); + ptr->prefix_key= NULL; + + memcached_error_free(ptr); + + if (ptr->sasl.callbacks) + { +#ifdef LIBMEMCACHED_WITH_SASL_SUPPORT + memcached_destroy_sasl_auth_data(ptr); +#endif + } + + if (release_st) + { + memcached_array_free(ptr->configure.filename); + ptr->configure.filename= NULL; + } + + if (memcached_is_allocated(ptr) && release_st) + { + libmemcached_free(ptr, ptr); + } +} + memcached_st *memcached_create(memcached_st *ptr) { if (ptr == NULL) @@ -138,6 +209,46 @@ memcached_st *memcached_create(memcached_st *ptr) return ptr; } +memcached_st *memcached_create_with_options(const char *string, size_t length) +{ + memcached_st *self= memcached_create(NULL); + + if (! self) + return NULL; + + memcached_return_t rc; + if ((rc= memcached_parse_configuration(self, string, length)) != MEMCACHED_SUCCESS) + { + return self; + } + + if (memcached_parse_filename(self)) + { + rc= memcached_parse_configure_file(self, memcached_parse_filename(self), memcached_parse_filename_length(self)); + } + + return self; +} + +memcached_return_t memcached_reset(memcached_st *ptr) +{ + WATCHPOINT_ASSERT(ptr); + if (! ptr) + return MEMCACHED_INVALID_ARGUMENTS; + + bool stored_is_allocated= memcached_is_allocated(ptr); + _free(ptr, false); + memcached_create(ptr); + memcached_set_allocated(ptr, stored_is_allocated); + + if (ptr->configure.filename) + { + return memcached_parse_configure_file(ptr, memcached_param_array(ptr->configure.filename)); + } + + return MEMCACHED_SUCCESS; +} + void memcached_servers_reset(memcached_st *ptr) { memcached_server_list_free(memcached_server_list(ptr)); @@ -163,31 +274,7 @@ void memcached_reset_last_disconnected_server(memcached_st *ptr) void memcached_free(memcached_st *ptr) { - /* If we have anything open, lets close it now */ - memcached_quit(ptr); - memcached_server_list_free(memcached_server_list(ptr)); - memcached_result_free(&ptr->result); - - if (ptr->last_disconnected_server) - memcached_server_free(ptr->last_disconnected_server); - - if (ptr->on_cleanup) - ptr->on_cleanup(ptr); - - if (ptr->continuum) - libmemcached_free(ptr, ptr->continuum); - - if (ptr->sasl.callbacks) - { -#ifdef LIBMEMCACHED_WITH_SASL_SUPPORT - memcached_destroy_sasl_auth_data(ptr); -#endif - } - - if (memcached_is_allocated(ptr)) - { - libmemcached_free(ptr, ptr); - } + _free(ptr, true); } /* @@ -267,11 +354,7 @@ memcached_st *memcached_clone(memcached_st *clone, const memcached_st *source) } - if (source->prefix_key_length) - { - strcpy(new_clone->prefix_key, source->prefix_key); - new_clone->prefix_key_length= source->prefix_key_length; - } + new_clone->prefix_key= memcached_array_clone(new_clone, source->prefix_key); #ifdef LIBMEMCACHED_WITH_SASL_SUPPORT if (source->sasl.callbacks) diff --git a/libmemcached/memcached.h b/libmemcached/memcached.h index c099d76e..311d5f26 100644 --- a/libmemcached/memcached.h +++ b/libmemcached/memcached.h @@ -1,12 +1,37 @@ -/* LibMemcached - * Copyright (C) 2006-2009 Brian Aker - * All rights reserved. +/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: + * + * Libmemcached library * - * Use and distribution licensed under the BSD license. See - * the COPYING file in the parent directory for full text. + * Copyright (C) 2011 Data Differential, http://datadifferential.com/ + * Copyright (C) 2006-2009 Brian Aker All rights reserved. * - * Summary: interface for memcached server - * Description: main include file for libmemcached + * 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. * */ @@ -28,6 +53,8 @@ #include #include #include +#include +#include #include #include // Everything above this line must be in the order specified. @@ -43,6 +70,7 @@ #include #include #include +#include #include #include #include @@ -63,14 +91,13 @@ struct memcached_st { bool is_processing_input:1; bool is_time_for_rebuild:1; } state; + struct { // Everything below here is pretty static. bool auto_eject_hosts:1; bool binary_protocol:1; bool buffer_requests:1; - bool cork:1; bool hash_with_prefix_key:1; - bool ketama_weighted:1; bool no_block:1; // Don't block bool no_reply:1; bool randomize_replica_read:1; @@ -83,9 +110,9 @@ struct memcached_st { bool verify_key:1; bool tcp_keepalive:1; } flags; + memcached_server_distribution_t distribution; hashkit_st hashkit; - uint32_t continuum_points_counter; // Ketama uint32_t number_of_hosts; memcached_server_st *servers; memcached_server_st *last_disconnected_server; @@ -96,20 +123,25 @@ struct memcached_st { uint32_t io_bytes_watermark; uint32_t io_key_prefetch; uint32_t tcp_keepidle; - int cached_errno; int32_t poll_timeout; int32_t connect_timeout; int32_t retry_timeout; - uint32_t continuum_count; // Ketama int send_size; int recv_size; void *user_data; - time_t next_distribution_rebuild; // Ketama - size_t prefix_key_length; uint32_t number_of_replicas; hashkit_st distribution_hashkit; memcached_result_st result; - memcached_continuum_item_st *continuum; // Ketama + + struct { + bool weighted; + uint32_t continuum_count; // Ketama + uint32_t continuum_points_counter; // Ketama + time_t next_distribution_rebuild; // Ketama + memcached_continuum_item_st *continuum; // Ketama + } ketama; + + struct memcached_virtual_bucket_t *virtual_bucket; struct _allocators_st { memcached_calloc_fn calloc; @@ -125,7 +157,11 @@ struct memcached_st { memcached_trigger_delete_key_fn delete_trigger; memcached_callback_st *callbacks; struct memcached_sasl_st sasl; - char prefix_key[MEMCACHED_PREFIX_KEY_MAX_SIZE]; + struct memcached_error_st *error_messages; + struct memcached_array_st *prefix_key; + struct { + struct memcached_array_st *filename; + } configure; struct { bool is_allocated:1; } options; @@ -142,9 +178,15 @@ void memcached_servers_reset(memcached_st *ptr); LIBMEMCACHED_API memcached_st *memcached_create(memcached_st *ptr); +LIBMEMCACHED_API +memcached_st *memcached_create_with_options(const char *string, size_t length); + LIBMEMCACHED_API void memcached_free(memcached_st *ptr); +LIBMEMCACHED_API +memcached_return_t memcached_reset(memcached_st *ptr); + LIBMEMCACHED_API void memcached_reset_last_disconnected_server(memcached_st *ptr); diff --git a/libmemcached/memcached/protocol_binary.h b/libmemcached/memcached/protocol_binary.h index ecdc52e3..4509bbcb 100644 --- a/libmemcached/memcached/protocol_binary.h +++ b/libmemcached/memcached/protocol_binary.h @@ -1,3 +1,4 @@ +/* -*- Mode: C; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */ /* * Copyright (c) <2008>, Sun Microsystems, Inc. * All rights reserved. @@ -35,6 +36,8 @@ #ifndef PROTOCOL_BINARY_H #define PROTOCOL_BINARY_H +#include "vbucket.h" + /** * \addtogroup Protocol * @{ @@ -72,14 +75,15 @@ extern "C" 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_PAUSE = 0xfe00, - PROTOCOL_BINARY_RESPONSE_EIO = 0xff00 - + 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; /** @@ -114,6 +118,10 @@ extern "C" 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_SASL_LIST_MECHS = 0x20, PROTOCOL_BINARY_CMD_SASL_AUTH = 0x21, @@ -135,9 +143,30 @@ extern "C" PROTOCOL_BINARY_CMD_RINCR = 0x39, PROTOCOL_BINARY_CMD_RINCRQ = 0x3a, PROTOCOL_BINARY_CMD_RDECR = 0x3b, - PROTOCOL_BINARY_CMD_RDECRQ = 0x3c + 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; /** @@ -159,7 +188,7 @@ extern "C" uint16_t keylen; uint8_t extlen; uint8_t datatype; - uint16_t reserved; + uint16_t vbucket; uint32_t bodylen; uint32_t opaque; uint64_t cas; @@ -390,6 +419,64 @@ extern "C" */ 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 @@ -425,6 +512,209 @@ extern "C" 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; + + /** * @} */ diff --git a/libmemcached/memcached/vbucket.h b/libmemcached/memcached/vbucket.h new file mode 100644 index 00000000..c6c4d8ca --- /dev/null +++ b/libmemcached/memcached/vbucket.h @@ -0,0 +1,26 @@ +/* -*- Mode: C; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */ +#ifndef MEMCACHED_VBUCKET_H +#define MEMCACHED_VBUCKET_H 1 + +#ifdef __cplusplus +extern "C" +{ +#endif + +typedef enum { + vbucket_state_active = 1, /**< Actively servicing a vbucket. */ + vbucket_state_replica, /**< Servicing a vbucket as a replica only. */ + vbucket_state_pending, /**< Pending active. */ + vbucket_state_dead /**< Not in use, pending deletion. */ +} vbucket_state_t; + +#define is_valid_vbucket_state_t(state) \ + (state == vbucket_state_active || \ + state == vbucket_state_replica || \ + state == vbucket_state_pending || \ + state == vbucket_state_dead) + +#ifdef __cplusplus +} +#endif +#endif diff --git a/libmemcached/options.cc b/libmemcached/options.cc new file mode 100644 index 00000000..b404652e --- /dev/null +++ b/libmemcached/options.cc @@ -0,0 +1,151 @@ +/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: + * + * Libmemcached library + * + * Copyright (C) 2011 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. + * + */ + +#include "libmemcached/common.h" + +#include + +#include + +const char *memcached_parse_filename(memcached_st *memc) +{ + return memcached_array_string(memc->configure.filename); +} + +size_t memcached_parse_filename_length(memcached_st *memc) +{ + return memcached_array_size(memc->configure.filename); +} + +static memcached_return_t _parse_file_options(memcached_st *self, memcached_string_t *filename) +{ + memcached_array_st *real_name= memcached_strcpy(self, filename->c_str, filename->size); + + if (not real_name) + return MEMCACHED_MEMORY_ALLOCATION_FAILURE; + + FILE *fp= fopen(memcached_array_string(real_name), "r"); + if (! fp) + { + memcached_string_t error_message= memcached_array_to_string(real_name); + memcached_return_t rc= memcached_set_errno(self, errno, &error_message); + memcached_array_free(real_name); + return rc; + } + memcached_array_free(real_name); + + char buffer[BUFSIZ]; + memcached_return_t rc= MEMCACHED_INVALID_ARGUMENTS; + while (fgets(buffer, sizeof(buffer), fp)) + { + size_t length= strlen(buffer); + + if (length == 1 and buffer[0] == '\n') + continue; + + rc= memcached_parse_configuration(self, buffer, length); + if (rc != MEMCACHED_SUCCESS) + break; + } + fclose(fp); + + return rc; +} + +memcached_return_t libmemcached_check_configuration(const char *option_string, size_t length, char *error_buffer, size_t error_buffer_size) +{ + memcached_st memc, *memc_ptr; + + if (! (memc_ptr= memcached_create(&memc))) + return MEMCACHED_MEMORY_ALLOCATION_FAILURE; + + memcached_return_t rc= memcached_parse_configuration(memc_ptr, option_string, length); + if (rc != MEMCACHED_SUCCESS && error_buffer && error_buffer_size) + { + strncpy(error_buffer, memcached_last_error_message(memc_ptr), error_buffer_size); + } + + if (rc== MEMCACHED_SUCCESS && memcached_behavior_get(memc_ptr, MEMCACHED_BEHAVIOR_LOAD_FROM_FILE)) + { + memcached_string_t filename= memcached_array_to_string(memc_ptr->configure.filename); + rc= _parse_file_options(memc_ptr, &filename); + + if (rc != MEMCACHED_SUCCESS && error_buffer && error_buffer_size) + { + strncpy(error_buffer, memcached_last_error_message(memc_ptr), error_buffer_size); + } + } + + memcached_free(memc_ptr); + + return rc; +} + +memcached_return_t memcached_parse_configuration(memcached_st *self, char const *option_string, size_t length) +{ + WATCHPOINT_ASSERT(self); + if (! self) + return memcached_set_error(self, MEMCACHED_INVALID_ARGUMENTS, NULL); + + memcached_return_t rc; + Context context(option_string, length, self, rc); + + context.start(); + + return rc; +} + +void memcached_set_configuration_file(memcached_st *self, const char *filename, size_t filename_length) +{ + memcached_array_free(self->configure.filename); + self->configure.filename= memcached_strcpy(self, filename, filename_length); +} + +memcached_return_t memcached_parse_configure_file(memcached_st *self, const char *filename, size_t filename_length) +{ + if (! self) + return memcached_set_error(self, MEMCACHED_INVALID_ARGUMENTS, NULL); + + if (! filename || filename_length == 0) + return memcached_set_error(self, MEMCACHED_INVALID_ARGUMENTS, NULL); + + memcached_string_t tmp; + tmp.c_str= filename; + tmp.size= filename_length; + + return _parse_file_options(self, &tmp); +} diff --git a/libmemcached/options.h b/libmemcached/options.h new file mode 100644 index 00000000..0a27be98 --- /dev/null +++ b/libmemcached/options.h @@ -0,0 +1,64 @@ +/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: + * + * Libmemcached library + * + * Copyright (C) 2011 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. + * + */ + +#pragma once + +#ifdef __cplusplus +extern "C" { +#endif + +LIBMEMCACHED_API + memcached_return_t libmemcached_check_configuration(const char *option_string, size_t length, char *error_buffer, size_t error_buffer_size); + +LIBMEMCACHED_API + memcached_return_t memcached_parse_configuration(memcached_st *ptr, const char *option_string, size_t length); + +LIBMEMCACHED_API + memcached_return_t memcached_parse_configure_file(memcached_st *ptr, const char *filename, size_t filename_length); + +LIBMEMCACHED_API + void memcached_set_configuration_file(memcached_st *self, const char *filename, size_t filename_length); + +LIBMEMCACHED_API + const char *memcached_parse_filename(memcached_st *memc); + +LIBMEMCACHED_LOCAL + size_t memcached_parse_filename_length(memcached_st *memc); + +#ifdef __cplusplus +} +#endif diff --git a/libmemcached/options/build.cc b/libmemcached/options/build.cc new file mode 100644 index 00000000..9381b516 --- /dev/null +++ b/libmemcached/options/build.cc @@ -0,0 +1,69 @@ +/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: + * + * LibMemcached + * + * Copyright (C) 2011 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. + * + */ + +#include +#include +#include + +namespace parser { + +void abort_func(Context *context, const char *error) +{ + if (context->rc == MEMCACHED_SUCCESS) + context->rc= MEMCACHED_PARSE_ERROR; + + memcached_string_st *error_string= memcached_string_create(context->memc, NULL, 1024); + memcached_string_append(error_string, memcached_string_with_size("Error occured while parsing: ")); + memcached_string_append(error_string, memcached_string_make_from_cstr(context->begin)); + memcached_string_append(error_string, memcached_string_with_size(" (")); + + if (context->rc == MEMCACHED_PARSE_ERROR and error) + { + memcached_string_append(error_string, memcached_string_make_from_cstr(error)); + } + else + { + memcached_string_append(error_string, memcached_string_make_from_cstr(memcached_strerror(NULL, context->rc))); + } + memcached_string_append(error_string, memcached_string_with_size(")")); + + memcached_set_error_string(context->memc, context->rc, memcached_string_value(error_string), memcached_string_length(error_string)); + + memcached_string_free(error_string); +} + +} // namespace parser diff --git a/libmemcached/options/build.h b/libmemcached/options/build.h new file mode 100644 index 00000000..d267354f --- /dev/null +++ b/libmemcached/options/build.h @@ -0,0 +1,46 @@ +/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: + * + * LibMemcached + * + * Copyright (C) 2011 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. + * + */ + +#pragma once + +class Conext; + +namespace parser { + +void abort_func(Context *context, const char *error); + +} diff --git a/libmemcached/options/context.h b/libmemcached/options/context.h new file mode 100644 index 00000000..9e4ecb3a --- /dev/null +++ b/libmemcached/options/context.h @@ -0,0 +1,93 @@ +/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: + * + * Libmemcached library + * + * Copyright (C) 2011 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. + * + */ + +#pragma once + +#include + +class Context +{ +public: + Context(const char *option_string, size_t option_string_length, memcached_st *memc_arg, + memcached_return_t &rc_arg) : + scanner(NULL), + begin(NULL), + pos(0), + memc(NULL), + rc(rc_arg), + _end(false) + { + buf= option_string; + length= option_string_length; + memc= memc_arg; + init_scanner(); + rc= MEMCACHED_SUCCESS; + } + + bool end() + { + return _end; + } + + void start(); + + void set_end() + { + rc= MEMCACHED_SUCCESS; + _end= true; + } + + ~Context() + { + destroy_scanner(); + } + + void *scanner; + const char *buf; + const char *begin; + size_t pos; + size_t length; + memcached_st *memc; + memcached_return_t &rc; + +protected: + void init_scanner(); + void destroy_scanner(); + +private: + bool _end; +}; diff --git a/libmemcached/options/include.am b/libmemcached/options/include.am new file mode 100644 index 00000000..067c387c --- /dev/null +++ b/libmemcached/options/include.am @@ -0,0 +1,24 @@ +# vim:ft=automake +# included from Top Level Makefile.am +# All paths should be given relative to the root + +DISTCLEANFILES+= \ + libmemcached/options/parser.output \ + libmemcached/options/parser.cc \ + libmemcached/options/parser.h \ + libmemcached/options/scanner.cc \ + libmemcached/options/scanner.h + +noinst_HEADERS+= \ + libmemcached/options/build.h \ + libmemcached/options/context.h \ + libmemcached/options/parser.h \ + libmemcached/options/scanner.h \ + libmemcached/options/server.h \ + libmemcached/options/string.h \ + libmemcached/options/symbol.h + +libmemcached_libmemcached_la_SOURCES+= \ + libmemcached/options/build.cc \ + libmemcached/options/parser.cc \ + libmemcached/options/scanner.cc diff --git a/libmemcached/options/lex_string.h b/libmemcached/options/lex_string.h new file mode 100644 index 00000000..991acba8 --- /dev/null +++ b/libmemcached/options/lex_string.h @@ -0,0 +1,16 @@ +#pragma once + +#include +#include + +struct string_t +{ + const char *c_str; + size_t length; +}; + +inline std::ostream& operator<<(std::ostream& output, const string_t& arg) +{ + output << arg.c_str; + return output; +} diff --git a/libmemcached/options/parser.cc b/libmemcached/options/parser.cc new file mode 100644 index 00000000..8b7134a9 --- /dev/null +++ b/libmemcached/options/parser.cc @@ -0,0 +1,2384 @@ +/* A Bison parser, made by GNU Bison 2.4.3. */ + +/* Skeleton implementation for Bison's Yacc-like parsers in C + + Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005, 2006, + 2009, 2010 Free Software Foundation, Inc. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +/* As a special exception, you may create a larger work that contains + part or all of the Bison parser skeleton and distribute that work + under terms of your choice, so long as that work isn't itself a + parser generator using the skeleton or a modified version thereof + as a parser skeleton. Alternatively, if you modify or redistribute + the parser skeleton itself, you may (at your option) remove this + special exception, which will cause the skeleton and the resulting + Bison output files to be licensed under the GNU General Public + License without this special exception. + + This special exception was added by the Free Software Foundation in + version 2.2 of Bison. */ + +/* C LALR(1) parser skeleton written by Richard Stallman, by + simplifying the original so-called "semantic" parser. */ + +/* All symbols defined below should begin with yy or YY, to avoid + infringing on user name space. This should be done even for local + variables, as they might otherwise be expanded by user macros. + There are some unavoidable exceptions within include files to + define necessary library symbols; they are noted "INFRINGES ON + USER NAME SPACE" below. */ + +/* Identify Bison output. */ +#define YYBISON 1 + +/* Bison version. */ +#define YYBISON_VERSION "2.4.3" + +/* Skeleton name. */ +#define YYSKELETON_NAME "yacc.c" + +/* Pure parsers. */ +#define YYPURE 1 + +/* Push parsers. */ +#define YYPUSH 0 + +/* Pull parsers. */ +#define YYPULL 1 + +/* Using locations. */ +#define YYLSP_NEEDED 0 + +/* Substitute the variable and function names. */ +#define yyparse config_parse +#define yylex config_lex +#define yyerror config_error +#define yylval config_lval +#define yychar config_char +#define yydebug config_debug +#define yynerrs config_nerrs + + +/* Copy the first part of user declarations. */ + +/* Line 189 of yacc.c */ +#line 36 "libmemcached/options/parser.yy" + + +#include + +#include + +#include +#include +#include +#include +#include +#include + +#pragma GCC diagnostic ignored "-Wold-style-cast" +#include + +int conf_lex(YYSTYPE* lvalp, void* scanner); + +#define parser_abort(A, B) do { parser::abort_func((A), (B)); YYABORT; } while (0) + +inline void config_error(Context *context, yyscan_t *scanner, const char *error) +{ + if (not context->end()) + parser::abort_func(context, error); +} + + + +/* Line 189 of yacc.c */ +#line 109 "libmemcached/options/parser.cc" + +/* Enabling traces. */ +#ifndef YYDEBUG +# define YYDEBUG 1 +#endif + +/* Enabling verbose error messages. */ +#ifdef YYERROR_VERBOSE +# undef YYERROR_VERBOSE +# define YYERROR_VERBOSE 1 +#else +# define YYERROR_VERBOSE 1 +#endif + +/* Enabling the token table. */ +#ifndef YYTOKEN_TABLE +# define YYTOKEN_TABLE 0 +#endif + + +/* Tokens. */ +#ifndef YYTOKENTYPE +# define YYTOKENTYPE + /* Put the tokens into the symbol table, so that GDB and other debuggers + know about them. */ + enum yytokentype { + COMMENT = 258, + END = 259, + ERROR = 260, + RESET = 261, + PARSER_DEBUG = 262, + INCLUDE = 263, + CONFIGURE_FILE = 264, + EMPTY_LINE = 265, + SERVER = 266, + SERVERS = 267, + SERVERS_OPTION = 268, + UNKNOWN_OPTION = 269, + UNKNOWN = 270, + AUTO_EJECT_HOSTS = 271, + BINARY_PROTOCOL = 272, + BUFFER_REQUESTS = 273, + CACHE_LOOKUPS = 274, + CONNECT_TIMEOUT = 275, + DISTRIBUTION = 276, + HASH = 277, + HASH_WITH_PREFIX_KEY = 278, + IO_BYTES_WATERMARK = 279, + IO_KEY_PREFETCH = 280, + IO_MSG_WATERMARK = 281, + KETAMA_HASH = 282, + KETAMA_WEIGHTED = 283, + NOREPLY = 284, + NUMBER_OF_REPLICAS = 285, + POLL_TIMEOUT = 286, + RANDOMIZE_REPLICA_READ = 287, + RCV_TIMEOUT = 288, + RETRY_TIMEOUT = 289, + SERVER_FAILURE_LIMIT = 290, + SND_TIMEOUT = 291, + SOCKET_RECV_SIZE = 292, + SOCKET_SEND_SIZE = 293, + SORT_HOSTS = 294, + SUPPORT_CAS = 295, + _TCP_NODELAY = 296, + _TCP_KEEPALIVE = 297, + _TCP_KEEPIDLE = 298, + USER_DATA = 299, + USE_UDP = 300, + VERIFY_KEY = 301, + PREFIX_KEY = 302, + MD5 = 303, + CRC = 304, + FNV1_64 = 305, + FNV1A_64 = 306, + FNV1_32 = 307, + FNV1A_32 = 308, + HSIEH = 309, + MURMUR = 310, + JENKINS = 311, + CONSISTENT = 312, + MODULA = 313, + RANDOM = 314, + TRUE = 315, + FALSE = 316, + NUMBER = 317, + FLOAT = 318, + HOSTNAME = 319, + HOSTNAME_WITH_PORT = 320, + IPADDRESS = 321, + IPADDRESS_WITH_PORT = 322, + STRING = 323, + QUOTED_STRING = 324, + FILE_PATH = 325 + }; +#endif + + + +#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED + +# define yystype YYSTYPE /* obsolescent; will be withdrawn */ +# define YYSTYPE_IS_DECLARED 1 +#endif + + +/* Copy the second part of user declarations. */ + + +/* Line 264 of yacc.c */ +#line 220 "libmemcached/options/parser.cc" + +#ifdef short +# undef short +#endif + +#ifdef YYTYPE_UINT8 +typedef YYTYPE_UINT8 yytype_uint8; +#else +typedef unsigned char yytype_uint8; +#endif + +#ifdef YYTYPE_INT8 +typedef YYTYPE_INT8 yytype_int8; +#elif (defined __STDC__ || defined __C99__FUNC__ \ + || defined __cplusplus || defined _MSC_VER) +typedef signed char yytype_int8; +#else +typedef short int yytype_int8; +#endif + +#ifdef YYTYPE_UINT16 +typedef YYTYPE_UINT16 yytype_uint16; +#else +typedef unsigned short int yytype_uint16; +#endif + +#ifdef YYTYPE_INT16 +typedef YYTYPE_INT16 yytype_int16; +#else +typedef short int yytype_int16; +#endif + +#ifndef YYSIZE_T +# ifdef __SIZE_TYPE__ +# define YYSIZE_T __SIZE_TYPE__ +# elif defined size_t +# define YYSIZE_T size_t +# elif ! defined YYSIZE_T && (defined __STDC__ || defined __C99__FUNC__ \ + || defined __cplusplus || defined _MSC_VER) +# include /* INFRINGES ON USER NAME SPACE */ +# define YYSIZE_T size_t +# else +# define YYSIZE_T unsigned int +# endif +#endif + +#define YYSIZE_MAXIMUM ((YYSIZE_T) -1) + +#ifndef YY_ +# if defined YYENABLE_NLS && YYENABLE_NLS +# if ENABLE_NLS +# include /* INFRINGES ON USER NAME SPACE */ +# define YY_(msgid) dgettext ("bison-runtime", msgid) +# endif +# endif +# ifndef YY_ +# define YY_(msgid) msgid +# endif +#endif + +/* Suppress unused-variable warnings by "using" E. */ +#if ! defined lint || defined __GNUC__ +# define YYUSE(e) ((void) (e)) +#else +# define YYUSE(e) /* empty */ +#endif + +/* Identity function, used to suppress warnings about constant conditions. */ +#ifndef lint +# define YYID(n) (n) +#else +#if (defined __STDC__ || defined __C99__FUNC__ \ + || defined __cplusplus || defined _MSC_VER) +static int +YYID (int yyi) +#else +static int +YYID (yyi) + int yyi; +#endif +{ + return yyi; +} +#endif + +#if ! defined yyoverflow || YYERROR_VERBOSE + +/* The parser invokes alloca or malloc; define the necessary symbols. */ + +# ifdef YYSTACK_USE_ALLOCA +# if YYSTACK_USE_ALLOCA +# ifdef __GNUC__ +# define YYSTACK_ALLOC __builtin_alloca +# elif defined __BUILTIN_VA_ARG_INCR +# include /* INFRINGES ON USER NAME SPACE */ +# elif defined _AIX +# define YYSTACK_ALLOC __alloca +# elif defined _MSC_VER +# include /* INFRINGES ON USER NAME SPACE */ +# define alloca _alloca +# else +# define YYSTACK_ALLOC alloca +# if ! defined _ALLOCA_H && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \ + || defined __cplusplus || defined _MSC_VER) +# include /* INFRINGES ON USER NAME SPACE */ +# ifndef _STDLIB_H +# define _STDLIB_H 1 +# endif +# endif +# endif +# endif +# endif + +# ifdef YYSTACK_ALLOC + /* Pacify GCC's `empty if-body' warning. */ +# define YYSTACK_FREE(Ptr) do { /* empty */; } while (YYID (0)) +# ifndef YYSTACK_ALLOC_MAXIMUM + /* The OS might guarantee only one guard page at the bottom of the stack, + and a page size can be as small as 4096 bytes. So we cannot safely + invoke alloca (N) if N exceeds 4096. Use a slightly smaller number + to allow for a few compiler-allocated temporary stack slots. */ +# define YYSTACK_ALLOC_MAXIMUM 4032 /* reasonable circa 2006 */ +# endif +# else +# define YYSTACK_ALLOC YYMALLOC +# define YYSTACK_FREE YYFREE +# ifndef YYSTACK_ALLOC_MAXIMUM +# define YYSTACK_ALLOC_MAXIMUM YYSIZE_MAXIMUM +# endif +# if (defined __cplusplus && ! defined _STDLIB_H \ + && ! ((defined YYMALLOC || defined malloc) \ + && (defined YYFREE || defined free))) +# include /* INFRINGES ON USER NAME SPACE */ +# ifndef _STDLIB_H +# define _STDLIB_H 1 +# endif +# endif +# ifndef YYMALLOC +# define YYMALLOC malloc +# if ! defined malloc && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \ + || defined __cplusplus || defined _MSC_VER) +void *malloc (YYSIZE_T); /* INFRINGES ON USER NAME SPACE */ +# endif +# endif +# ifndef YYFREE +# define YYFREE free +# if ! defined free && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \ + || defined __cplusplus || defined _MSC_VER) +void free (void *); /* INFRINGES ON USER NAME SPACE */ +# endif +# endif +# endif +#endif /* ! defined yyoverflow || YYERROR_VERBOSE */ + + +#if (! defined yyoverflow \ + && (! defined __cplusplus \ + || (defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL))) + +/* A type that is properly aligned for any stack member. */ +union yyalloc +{ + yytype_int16 yyss_alloc; + YYSTYPE yyvs_alloc; +}; + +/* The size of the maximum gap between one aligned stack and the next. */ +# define YYSTACK_GAP_MAXIMUM (sizeof (union yyalloc) - 1) + +/* The size of an array large to enough to hold all stacks, each with + N elements. */ +# define YYSTACK_BYTES(N) \ + ((N) * (sizeof (yytype_int16) + sizeof (YYSTYPE)) \ + + YYSTACK_GAP_MAXIMUM) + +/* Copy COUNT objects from FROM to TO. The source and destination do + not overlap. */ +# ifndef YYCOPY +# if defined __GNUC__ && 1 < __GNUC__ +# define YYCOPY(To, From, Count) \ + __builtin_memcpy (To, From, (Count) * sizeof (*(From))) +# else +# define YYCOPY(To, From, Count) \ + do \ + { \ + YYSIZE_T yyi; \ + for (yyi = 0; yyi < (Count); yyi++) \ + (To)[yyi] = (From)[yyi]; \ + } \ + while (YYID (0)) +# endif +# endif + +/* Relocate STACK from its old location to the new one. The + local variables YYSIZE and YYSTACKSIZE give the old and new number of + elements in the stack, and YYPTR gives the new location of the + stack. Advance YYPTR to a properly aligned location for the next + stack. */ +# define YYSTACK_RELOCATE(Stack_alloc, Stack) \ + do \ + { \ + YYSIZE_T yynewbytes; \ + YYCOPY (&yyptr->Stack_alloc, Stack, yysize); \ + Stack = &yyptr->Stack_alloc; \ + yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAXIMUM; \ + yyptr += yynewbytes / sizeof (*yyptr); \ + } \ + while (YYID (0)) + +#endif + +/* YYFINAL -- State number of the termination state. */ +#define YYFINAL 75 +/* YYLAST -- Last index in YYTABLE. */ +#define YYLAST 73 + +/* YYNTOKENS -- Number of terminals. */ +#define YYNTOKENS 74 +/* YYNNTS -- Number of nonterminals. */ +#define YYNNTS 12 +/* YYNRULES -- Number of rules. */ +#define YYNRULES 70 +/* YYNRULES -- Number of states. */ +#define YYNSTATES 86 + +/* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */ +#define YYUNDEFTOK 2 +#define YYMAXUTOK 325 + +#define YYTRANSLATE(YYX) \ + ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK) + +/* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX. */ +static const yytype_uint8 yytranslate[] = +{ + 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 73, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 62, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 63, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 1, 2, 3, 4, + 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, + 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, + 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, + 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, + 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, + 55, 56, 57, 58, 59, 60, 61, 64, 65, 66, + 67, 68, 69, 70, 71, 72 +}; + +#if YYDEBUG +/* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in + YYRHS. */ +static const yytype_uint8 yyprhs[] = +{ + 0, 0, 3, 5, 9, 11, 13, 15, 17, 19, + 21, 23, 27, 30, 33, 36, 38, 41, 44, 49, + 52, 55, 57, 59, 61, 63, 65, 67, 69, 71, + 73, 75, 77, 79, 81, 83, 85, 87, 89, 91, + 93, 95, 97, 99, 101, 103, 105, 107, 109, 111, + 113, 115, 119, 122, 124, 126, 129, 131, 133, 135, + 137, 139, 141, 143, 145, 147, 149, 151, 153, 155, + 157 +}; + +/* YYRHS -- A `-1'-separated list of the rules' RHS. */ +static const yytype_int8 yyrhs[] = +{ + 75, 0, -1, 76, -1, 75, 73, 76, -1, 77, + -1, 3, -1, 10, -1, 4, -1, 5, -1, 6, + -1, 7, -1, 8, 73, 84, -1, 11, 82, -1, + 13, 81, -1, 9, 84, -1, 78, -1, 47, 84, + -1, 21, 85, -1, 21, 85, 62, 83, -1, 22, + 83, -1, 79, 64, -1, 80, -1, 44, -1, 20, + -1, 26, -1, 24, -1, 25, -1, 30, -1, 31, + -1, 33, -1, 34, -1, 35, -1, 36, -1, 37, + -1, 38, -1, 16, -1, 17, -1, 18, -1, 19, + -1, 23, -1, 28, -1, 29, -1, 32, -1, 39, + -1, 40, -1, 41, -1, 42, -1, 43, -1, 45, + -1, 46, -1, 82, -1, 81, 62, 82, -1, 67, + 64, -1, 66, -1, 70, -1, 69, 64, -1, 68, + -1, 48, -1, 49, -1, 50, -1, 51, -1, 52, + -1, 53, -1, 54, -1, 55, -1, 56, -1, 70, + -1, 71, -1, 57, -1, 58, -1, 59, -1 +}; + +/* YYRLINE[YYN] -- source line where rule number YYN was defined. */ +static const yytype_uint16 yyrline[] = +{ + 0, 157, 157, 158, 162, 164, 166, 168, 173, 178, + 182, 186, 197, 204, 207, 211, 215, 222, 229, 240, + 247, 254, 261, 267, 271, 275, 279, 283, 287, 291, + 295, 299, 303, 307, 311, 318, 322, 326, 330, 334, + 338, 342, 346, 350, 354, 358, 362, 366, 370, 374, + 381, 388, 398, 404, 410, 416, 422, 431, 435, 439, + 443, 447, 451, 455, 459, 463, 470, 474, 482, 486, + 490 +}; +#endif + +#if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE +/* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM. + First, the terminals, then, starting at YYNTOKENS, nonterminals. */ +static const char *const yytname[] = +{ + "$end", "error", "$undefined", "COMMENT", "END", "ERROR", "RESET", + "PARSER_DEBUG", "INCLUDE", "CONFIGURE_FILE", "EMPTY_LINE", "SERVER", + "SERVERS", "SERVERS_OPTION", "UNKNOWN_OPTION", "UNKNOWN", + "AUTO_EJECT_HOSTS", "BINARY_PROTOCOL", "BUFFER_REQUESTS", + "CACHE_LOOKUPS", "CONNECT_TIMEOUT", "DISTRIBUTION", "HASH", + "HASH_WITH_PREFIX_KEY", "IO_BYTES_WATERMARK", "IO_KEY_PREFETCH", + "IO_MSG_WATERMARK", "KETAMA_HASH", "KETAMA_WEIGHTED", "NOREPLY", + "NUMBER_OF_REPLICAS", "POLL_TIMEOUT", "RANDOMIZE_REPLICA_READ", + "RCV_TIMEOUT", "RETRY_TIMEOUT", "SERVER_FAILURE_LIMIT", "SND_TIMEOUT", + "SOCKET_RECV_SIZE", "SOCKET_SEND_SIZE", "SORT_HOSTS", "SUPPORT_CAS", + "_TCP_NODELAY", "_TCP_KEEPALIVE", "_TCP_KEEPIDLE", "USER_DATA", + "USE_UDP", "VERIFY_KEY", "PREFIX_KEY", "MD5", "CRC", "FNV1_64", + "FNV1A_64", "FNV1_32", "FNV1A_32", "HSIEH", "MURMUR", "JENKINS", + "CONSISTENT", "MODULA", "RANDOM", "TRUE", "FALSE", "','", "'='", + "NUMBER", "FLOAT", "HOSTNAME", "HOSTNAME_WITH_PORT", "IPADDRESS", + "IPADDRESS_WITH_PORT", "STRING", "QUOTED_STRING", "FILE_PATH", "' '", + "$accept", "begin", "statement", "expression", "behaviors", + "behavior_number", "behavior_boolean", "server_list", "server", "hash", + "string", "distribution", 0 +}; +#endif + +# ifdef YYPRINT +/* YYTOKNUM[YYLEX-NUM] -- Internal token number corresponding to + token YYLEX-NUM. */ +static const yytype_uint16 yytoknum[] = +{ + 0, 256, 257, 258, 259, 260, 261, 262, 263, 264, + 265, 266, 267, 268, 269, 270, 271, 272, 273, 274, + 275, 276, 277, 278, 279, 280, 281, 282, 283, 284, + 285, 286, 287, 288, 289, 290, 291, 292, 293, 294, + 295, 296, 297, 298, 299, 300, 301, 302, 303, 304, + 305, 306, 307, 308, 309, 310, 311, 312, 313, 314, + 315, 316, 44, 61, 317, 318, 319, 320, 321, 322, + 323, 324, 325, 32 +}; +# endif + +/* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */ +static const yytype_uint8 yyr1[] = +{ + 0, 74, 75, 75, 76, 76, 76, 76, 76, 76, + 76, 76, 77, 77, 77, 77, 78, 78, 78, 78, + 78, 78, 78, 79, 79, 79, 79, 79, 79, 79, + 79, 79, 79, 79, 79, 80, 80, 80, 80, 80, + 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, + 81, 81, 82, 82, 82, 82, 82, 83, 83, 83, + 83, 83, 83, 83, 83, 83, 84, 84, 85, 85, + 85 +}; + +/* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */ +static const yytype_uint8 yyr2[] = +{ + 0, 2, 1, 3, 1, 1, 1, 1, 1, 1, + 1, 3, 2, 2, 2, 1, 2, 2, 4, 2, + 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 3, 2, 1, 1, 2, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1 +}; + +/* YYDEFACT[STATE-NAME] -- Default rule to reduce with in state + STATE-NUM when YYTABLE doesn't specify something else to do. Zero + means the default is an error. */ +static const yytype_uint8 yydefact[] = +{ + 0, 5, 7, 8, 9, 10, 0, 0, 6, 0, + 0, 35, 36, 37, 38, 23, 0, 0, 39, 25, + 26, 24, 40, 41, 27, 28, 42, 29, 30, 31, + 32, 33, 34, 43, 44, 45, 46, 47, 22, 48, + 49, 0, 0, 2, 4, 15, 0, 21, 0, 66, + 67, 14, 53, 0, 56, 0, 54, 12, 13, 50, + 68, 69, 70, 17, 57, 58, 59, 60, 61, 62, + 63, 64, 65, 19, 16, 1, 0, 20, 11, 52, + 55, 0, 0, 3, 51, 18 +}; + +/* YYDEFGOTO[NTERM-NUM]. */ +static const yytype_int8 yydefgoto[] = +{ + -1, 42, 43, 44, 45, 46, 47, 58, 57, 73, + 51, 63 +}; + +/* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing + STATE-NUM. */ +#define YYPACT_NINF -63 +static const yytype_int8 yypact[] = +{ + -1, -63, -63, -63, -63, -63, -62, -57, -63, -7, + -7, -63, -63, -63, -63, -63, 9, 1, -63, -63, + -63, -63, -63, -63, -63, -63, -63, -63, -63, -63, + -63, -63, -63, -63, -63, -63, -63, -63, -63, -63, + -63, -57, 0, -63, -63, -63, -38, -63, -57, -63, + -63, -63, -63, -17, -63, -16, -63, -63, 2, -63, + -63, -63, -63, 7, -63, -63, -63, -63, -63, -63, + -63, -63, -63, -63, -63, -63, -1, -63, -63, -63, + -63, -7, 1, -63, -63, -63 +}; + +/* YYPGOTO[NTERM-NUM]. */ +static const yytype_int8 yypgoto[] = +{ + -63, -63, -6, -63, -63, -63, -63, -63, -9, -11, + 17, -63 +}; + +/* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If + positive, shift that token. If negative, reduce the rule which + number is the opposite. If zero, do what YYDEFACT says. + If YYTABLE_NINF, syntax error. */ +#define YYTABLE_NINF -1 +static const yytype_uint8 yytable[] = +{ + 75, 59, 1, 2, 3, 4, 5, 6, 7, 8, + 9, 48, 10, 49, 50, 11, 12, 13, 14, 15, + 16, 17, 18, 19, 20, 21, 77, 22, 23, 24, + 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, + 35, 36, 37, 38, 39, 40, 41, 79, 80, 64, + 65, 66, 67, 68, 69, 70, 71, 72, 74, 52, + 53, 54, 55, 56, 81, 78, 60, 61, 62, 82, + 83, 85, 84, 76 +}; + +static const yytype_uint8 yycheck[] = +{ + 0, 10, 3, 4, 5, 6, 7, 8, 9, 10, + 11, 73, 13, 70, 71, 16, 17, 18, 19, 20, + 21, 22, 23, 24, 25, 26, 64, 28, 29, 30, + 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, + 41, 42, 43, 44, 45, 46, 47, 64, 64, 48, + 49, 50, 51, 52, 53, 54, 55, 56, 41, 66, + 67, 68, 69, 70, 62, 48, 57, 58, 59, 62, + 76, 82, 81, 73 +}; + +/* YYSTOS[STATE-NUM] -- The (internal number of the) accessing + symbol of state STATE-NUM. */ +static const yytype_uint8 yystos[] = +{ + 0, 3, 4, 5, 6, 7, 8, 9, 10, 11, + 13, 16, 17, 18, 19, 20, 21, 22, 23, 24, + 25, 26, 28, 29, 30, 31, 32, 33, 34, 35, + 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, + 46, 47, 75, 76, 77, 78, 79, 80, 73, 70, + 71, 84, 66, 67, 68, 69, 70, 82, 81, 82, + 57, 58, 59, 85, 48, 49, 50, 51, 52, 53, + 54, 55, 56, 83, 84, 0, 73, 64, 84, 64, + 64, 62, 62, 76, 82, 83 +}; + +#define yyerrok (yyerrstatus = 0) +#define yyclearin (yychar = YYEMPTY) +#define YYEMPTY (-2) +#define YYEOF 0 + +#define YYACCEPT goto yyacceptlab +#define YYABORT goto yyabortlab +#define YYERROR goto yyerrorlab + + +/* Like YYERROR except do call yyerror. This remains here temporarily + to ease the transition to the new meaning of YYERROR, for GCC. + Once GCC version 2 has supplanted version 1, this can go. However, + YYFAIL appears to be in use. Nevertheless, it is formally deprecated + in Bison 2.4.2's NEWS entry, where a plan to phase it out is + discussed. */ + +#define YYFAIL goto yyerrlab +#if defined YYFAIL + /* This is here to suppress warnings from the GCC cpp's + -Wunused-macros. Normally we don't worry about that warning, but + some users do, and we want to make it easy for users to remove + YYFAIL uses, which will produce warnings from Bison 2.5. */ +#endif + +#define YYRECOVERING() (!!yyerrstatus) + +#define YYBACKUP(Token, Value) \ +do \ + if (yychar == YYEMPTY && yylen == 1) \ + { \ + yychar = (Token); \ + yylval = (Value); \ + yytoken = YYTRANSLATE (yychar); \ + YYPOPSTACK (1); \ + goto yybackup; \ + } \ + else \ + { \ + yyerror (context, scanner, YY_("syntax error: cannot back up")); \ + YYERROR; \ + } \ +while (YYID (0)) + + +#define YYTERROR 1 +#define YYERRCODE 256 + + +/* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N]. + If N is 0, then set CURRENT to the empty location which ends + the previous symbol: RHS[0] (always defined). */ + +#define YYRHSLOC(Rhs, K) ((Rhs)[K]) +#ifndef YYLLOC_DEFAULT +# define YYLLOC_DEFAULT(Current, Rhs, N) \ + do \ + if (YYID (N)) \ + { \ + (Current).first_line = YYRHSLOC (Rhs, 1).first_line; \ + (Current).first_column = YYRHSLOC (Rhs, 1).first_column; \ + (Current).last_line = YYRHSLOC (Rhs, N).last_line; \ + (Current).last_column = YYRHSLOC (Rhs, N).last_column; \ + } \ + else \ + { \ + (Current).first_line = (Current).last_line = \ + YYRHSLOC (Rhs, 0).last_line; \ + (Current).first_column = (Current).last_column = \ + YYRHSLOC (Rhs, 0).last_column; \ + } \ + while (YYID (0)) +#endif + + +/* YY_LOCATION_PRINT -- Print the location on the stream. + This macro was not mandated originally: define only if we know + we won't break user code: when these are the locations we know. */ + +#ifndef YY_LOCATION_PRINT +# if defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL +# define YY_LOCATION_PRINT(File, Loc) \ + fprintf (File, "%d.%d-%d.%d", \ + (Loc).first_line, (Loc).first_column, \ + (Loc).last_line, (Loc).last_column) +# else +# define YY_LOCATION_PRINT(File, Loc) ((void) 0) +# endif +#endif + + +/* YYLEX -- calling `yylex' with the right arguments. */ + +#ifdef YYLEX_PARAM +# define YYLEX yylex (&yylval, YYLEX_PARAM) +#else +# define YYLEX yylex (&yylval, scanner) +#endif + +/* Enable debugging if requested. */ +#if YYDEBUG + +# ifndef YYFPRINTF +# include /* INFRINGES ON USER NAME SPACE */ +# define YYFPRINTF fprintf +# endif + +# define YYDPRINTF(Args) \ +do { \ + if (yydebug) \ + YYFPRINTF Args; \ +} while (YYID (0)) + +# define YY_SYMBOL_PRINT(Title, Type, Value, Location) \ +do { \ + if (yydebug) \ + { \ + YYFPRINTF (stderr, "%s ", Title); \ + yy_symbol_print (stderr, \ + Type, Value, context, scanner); \ + YYFPRINTF (stderr, "\n"); \ + } \ +} while (YYID (0)) + + +/*--------------------------------. +| Print this symbol on YYOUTPUT. | +`--------------------------------*/ + +/*ARGSUSED*/ +#if (defined __STDC__ || defined __C99__FUNC__ \ + || defined __cplusplus || defined _MSC_VER) +static void +yy_symbol_value_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep, Context *context, yyscan_t *scanner) +#else +static void +yy_symbol_value_print (yyoutput, yytype, yyvaluep, context, scanner) + FILE *yyoutput; + int yytype; + YYSTYPE const * const yyvaluep; + Context *context; + yyscan_t *scanner; +#endif +{ + if (!yyvaluep) + return; + YYUSE (context); + YYUSE (scanner); +# ifdef YYPRINT + if (yytype < YYNTOKENS) + YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep); +# else + YYUSE (yyoutput); +# endif + switch (yytype) + { + default: + break; + } +} + + +/*--------------------------------. +| Print this symbol on YYOUTPUT. | +`--------------------------------*/ + +#if (defined __STDC__ || defined __C99__FUNC__ \ + || defined __cplusplus || defined _MSC_VER) +static void +yy_symbol_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep, Context *context, yyscan_t *scanner) +#else +static void +yy_symbol_print (yyoutput, yytype, yyvaluep, context, scanner) + FILE *yyoutput; + int yytype; + YYSTYPE const * const yyvaluep; + Context *context; + yyscan_t *scanner; +#endif +{ + if (yytype < YYNTOKENS) + YYFPRINTF (yyoutput, "token %s (", yytname[yytype]); + else + YYFPRINTF (yyoutput, "nterm %s (", yytname[yytype]); + + yy_symbol_value_print (yyoutput, yytype, yyvaluep, context, scanner); + YYFPRINTF (yyoutput, ")"); +} + +/*------------------------------------------------------------------. +| yy_stack_print -- Print the state stack from its BOTTOM up to its | +| TOP (included). | +`------------------------------------------------------------------*/ + +#if (defined __STDC__ || defined __C99__FUNC__ \ + || defined __cplusplus || defined _MSC_VER) +static void +yy_stack_print (yytype_int16 *yybottom, yytype_int16 *yytop) +#else +static void +yy_stack_print (yybottom, yytop) + yytype_int16 *yybottom; + yytype_int16 *yytop; +#endif +{ + YYFPRINTF (stderr, "Stack now"); + for (; yybottom <= yytop; yybottom++) + { + int yybot = *yybottom; + YYFPRINTF (stderr, " %d", yybot); + } + YYFPRINTF (stderr, "\n"); +} + +# define YY_STACK_PRINT(Bottom, Top) \ +do { \ + if (yydebug) \ + yy_stack_print ((Bottom), (Top)); \ +} while (YYID (0)) + + +/*------------------------------------------------. +| Report that the YYRULE is going to be reduced. | +`------------------------------------------------*/ + +#if (defined __STDC__ || defined __C99__FUNC__ \ + || defined __cplusplus || defined _MSC_VER) +static void +yy_reduce_print (YYSTYPE *yyvsp, int yyrule, Context *context, yyscan_t *scanner) +#else +static void +yy_reduce_print (yyvsp, yyrule, context, scanner) + YYSTYPE *yyvsp; + int yyrule; + Context *context; + yyscan_t *scanner; +#endif +{ + int yynrhs = yyr2[yyrule]; + int yyi; + unsigned long int yylno = yyrline[yyrule]; + YYFPRINTF (stderr, "Reducing stack by rule %d (line %lu):\n", + yyrule - 1, yylno); + /* The symbols being reduced. */ + for (yyi = 0; yyi < yynrhs; yyi++) + { + YYFPRINTF (stderr, " $%d = ", yyi + 1); + yy_symbol_print (stderr, yyrhs[yyprhs[yyrule] + yyi], + &(yyvsp[(yyi + 1) - (yynrhs)]) + , context, scanner); + YYFPRINTF (stderr, "\n"); + } +} + +# define YY_REDUCE_PRINT(Rule) \ +do { \ + if (yydebug) \ + yy_reduce_print (yyvsp, Rule, context, scanner); \ +} while (YYID (0)) + +/* Nonzero means print parse trace. It is left uninitialized so that + multiple parsers can coexist. */ +int yydebug; +#else /* !YYDEBUG */ +# define YYDPRINTF(Args) +# define YY_SYMBOL_PRINT(Title, Type, Value, Location) +# define YY_STACK_PRINT(Bottom, Top) +# define YY_REDUCE_PRINT(Rule) +#endif /* !YYDEBUG */ + + +/* YYINITDEPTH -- initial size of the parser's stacks. */ +#ifndef YYINITDEPTH +# define YYINITDEPTH 200 +#endif + +/* YYMAXDEPTH -- maximum size the stacks can grow to (effective only + if the built-in stack extension method is used). + + Do not make this value too large; the results are undefined if + YYSTACK_ALLOC_MAXIMUM < YYSTACK_BYTES (YYMAXDEPTH) + evaluated with infinite-precision integer arithmetic. */ + +#ifndef YYMAXDEPTH +# define YYMAXDEPTH 10000 +#endif + + + +#if YYERROR_VERBOSE + +# ifndef yystrlen +# if defined __GLIBC__ && defined _STRING_H +# define yystrlen strlen +# else +/* Return the length of YYSTR. */ +#if (defined __STDC__ || defined __C99__FUNC__ \ + || defined __cplusplus || defined _MSC_VER) +static YYSIZE_T +yystrlen (const char *yystr) +#else +static YYSIZE_T +yystrlen (yystr) + const char *yystr; +#endif +{ + YYSIZE_T yylen; + for (yylen = 0; yystr[yylen]; yylen++) + continue; + return yylen; +} +# endif +# endif + +# ifndef yystpcpy +# if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE +# define yystpcpy stpcpy +# else +/* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in + YYDEST. */ +#if (defined __STDC__ || defined __C99__FUNC__ \ + || defined __cplusplus || defined _MSC_VER) +static char * +yystpcpy (char *yydest, const char *yysrc) +#else +static char * +yystpcpy (yydest, yysrc) + char *yydest; + const char *yysrc; +#endif +{ + char *yyd = yydest; + const char *yys = yysrc; + + while ((*yyd++ = *yys++) != '\0') + continue; + + return yyd - 1; +} +# endif +# endif + +# ifndef yytnamerr +/* Copy to YYRES the contents of YYSTR after stripping away unnecessary + quotes and backslashes, so that it's suitable for yyerror. The + heuristic is that double-quoting is unnecessary unless the string + contains an apostrophe, a comma, or backslash (other than + backslash-backslash). YYSTR is taken from yytname. If YYRES is + null, do not copy; instead, return the length of what the result + would have been. */ +static YYSIZE_T +yytnamerr (char *yyres, const char *yystr) +{ + if (*yystr == '"') + { + YYSIZE_T yyn = 0; + char const *yyp = yystr; + + for (;;) + switch (*++yyp) + { + case '\'': + case ',': + goto do_not_strip_quotes; + + case '\\': + if (*++yyp != '\\') + goto do_not_strip_quotes; + /* Fall through. */ + default: + if (yyres) + yyres[yyn] = *yyp; + yyn++; + break; + + case '"': + if (yyres) + yyres[yyn] = '\0'; + return yyn; + } + do_not_strip_quotes: ; + } + + if (! yyres) + return yystrlen (yystr); + + return yystpcpy (yyres, yystr) - yyres; +} +# endif + +/* Copy into YYRESULT an error message about the unexpected token + YYCHAR while in state YYSTATE. Return the number of bytes copied, + including the terminating null byte. If YYRESULT is null, do not + copy anything; just return the number of bytes that would be + copied. As a special case, return 0 if an ordinary "syntax error" + message will do. Return YYSIZE_MAXIMUM if overflow occurs during + size calculation. */ +static YYSIZE_T +yysyntax_error (char *yyresult, int yystate, int yychar) +{ + int yyn = yypact[yystate]; + + if (! (YYPACT_NINF < yyn && yyn <= YYLAST)) + return 0; + else + { + int yytype = YYTRANSLATE (yychar); + YYSIZE_T yysize0 = yytnamerr (0, yytname[yytype]); + YYSIZE_T yysize = yysize0; + YYSIZE_T yysize1; + int yysize_overflow = 0; + enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 }; + char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM]; + int yyx; + +# if 0 + /* This is so xgettext sees the translatable formats that are + constructed on the fly. */ + YY_("syntax error, unexpected %s"); + YY_("syntax error, unexpected %s, expecting %s"); + YY_("syntax error, unexpected %s, expecting %s or %s"); + YY_("syntax error, unexpected %s, expecting %s or %s or %s"); + YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s"); +# endif + char *yyfmt; + char const *yyf; + static char const yyunexpected[] = "syntax error, unexpected %s"; + static char const yyexpecting[] = ", expecting %s"; + static char const yyor[] = " or %s"; + char yyformat[sizeof yyunexpected + + sizeof yyexpecting - 1 + + ((YYERROR_VERBOSE_ARGS_MAXIMUM - 2) + * (sizeof yyor - 1))]; + char const *yyprefix = yyexpecting; + + /* Start YYX at -YYN if negative to avoid negative indexes in + YYCHECK. */ + int yyxbegin = yyn < 0 ? -yyn : 0; + + /* Stay within bounds of both yycheck and yytname. */ + int yychecklim = YYLAST - yyn + 1; + int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS; + int yycount = 1; + + yyarg[0] = yytname[yytype]; + yyfmt = yystpcpy (yyformat, yyunexpected); + + for (yyx = yyxbegin; yyx < yyxend; ++yyx) + if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR) + { + if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM) + { + yycount = 1; + yysize = yysize0; + yyformat[sizeof yyunexpected - 1] = '\0'; + break; + } + yyarg[yycount++] = yytname[yyx]; + yysize1 = yysize + yytnamerr (0, yytname[yyx]); + yysize_overflow |= (yysize1 < yysize); + yysize = yysize1; + yyfmt = yystpcpy (yyfmt, yyprefix); + yyprefix = yyor; + } + + yyf = YY_(yyformat); + yysize1 = yysize + yystrlen (yyf); + yysize_overflow |= (yysize1 < yysize); + yysize = yysize1; + + if (yysize_overflow) + return YYSIZE_MAXIMUM; + + if (yyresult) + { + /* Avoid sprintf, as that infringes on the user's name space. + Don't have undefined behavior even if the translation + produced a string with the wrong number of "%s"s. */ + char *yyp = yyresult; + int yyi = 0; + while ((*yyp = *yyf) != '\0') + { + if (*yyp == '%' && yyf[1] == 's' && yyi < yycount) + { + yyp += yytnamerr (yyp, yyarg[yyi++]); + yyf += 2; + } + else + { + yyp++; + yyf++; + } + } + } + return yysize; + } +} +#endif /* YYERROR_VERBOSE */ + + +/*-----------------------------------------------. +| Release the memory associated to this symbol. | +`-----------------------------------------------*/ + +/*ARGSUSED*/ +#if (defined __STDC__ || defined __C99__FUNC__ \ + || defined __cplusplus || defined _MSC_VER) +static void +yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep, Context *context, yyscan_t *scanner) +#else +static void +yydestruct (yymsg, yytype, yyvaluep, context, scanner) + const char *yymsg; + int yytype; + YYSTYPE *yyvaluep; + Context *context; + yyscan_t *scanner; +#endif +{ + YYUSE (yyvaluep); + YYUSE (context); + YYUSE (scanner); + + if (!yymsg) + yymsg = "Deleting"; + YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp); + + switch (yytype) + { + + default: + break; + } +} + +/* Prevent warnings from -Wmissing-prototypes. */ +#ifdef YYPARSE_PARAM +#if defined __STDC__ || defined __cplusplus +int yyparse (void *YYPARSE_PARAM); +#else +int yyparse (); +#endif +#else /* ! YYPARSE_PARAM */ +#if defined __STDC__ || defined __cplusplus +int yyparse (Context *context, yyscan_t *scanner); +#else +int yyparse (); +#endif +#endif /* ! YYPARSE_PARAM */ + + + + + +/*-------------------------. +| yyparse or yypush_parse. | +`-------------------------*/ + +#ifdef YYPARSE_PARAM +#if (defined __STDC__ || defined __C99__FUNC__ \ + || defined __cplusplus || defined _MSC_VER) +int +yyparse (void *YYPARSE_PARAM) +#else +int +yyparse (YYPARSE_PARAM) + void *YYPARSE_PARAM; +#endif +#else /* ! YYPARSE_PARAM */ +#if (defined __STDC__ || defined __C99__FUNC__ \ + || defined __cplusplus || defined _MSC_VER) +int +yyparse (Context *context, yyscan_t *scanner) +#else +int +yyparse (context, scanner) + Context *context; + yyscan_t *scanner; +#endif +#endif +{ +/* The lookahead symbol. */ +int yychar; + +/* The semantic value of the lookahead symbol. */ +YYSTYPE yylval; + + /* Number of syntax errors so far. */ + int yynerrs; + + int yystate; + /* Number of tokens to shift before error messages enabled. */ + int yyerrstatus; + + /* The stacks and their tools: + `yyss': related to states. + `yyvs': related to semantic values. + + Refer to the stacks thru separate pointers, to allow yyoverflow + to reallocate them elsewhere. */ + + /* The state stack. */ + yytype_int16 yyssa[YYINITDEPTH]; + yytype_int16 *yyss; + yytype_int16 *yyssp; + + /* The semantic value stack. */ + YYSTYPE yyvsa[YYINITDEPTH]; + YYSTYPE *yyvs; + YYSTYPE *yyvsp; + + YYSIZE_T yystacksize; + + int yyn; + int yyresult; + /* Lookahead token as an internal (translated) token number. */ + int yytoken; + /* The variables used to return semantic value and location from the + action routines. */ + YYSTYPE yyval; + +#if YYERROR_VERBOSE + /* Buffer for error messages, and its allocated size. */ + char yymsgbuf[128]; + char *yymsg = yymsgbuf; + YYSIZE_T yymsg_alloc = sizeof yymsgbuf; +#endif + +#define YYPOPSTACK(N) (yyvsp -= (N), yyssp -= (N)) + + /* The number of symbols on the RHS of the reduced rule. + Keep to zero when no symbol should be popped. */ + int yylen = 0; + + yytoken = 0; + yyss = yyssa; + yyvs = yyvsa; + yystacksize = YYINITDEPTH; + + YYDPRINTF ((stderr, "Starting parse\n")); + + yystate = 0; + yyerrstatus = 0; + yynerrs = 0; + yychar = YYEMPTY; /* Cause a token to be read. */ + + /* Initialize stack pointers. + Waste one element of value and location stack + so that they stay on the same level as the state stack. + The wasted elements are never initialized. */ + yyssp = yyss; + yyvsp = yyvs; + + goto yysetstate; + +/*------------------------------------------------------------. +| yynewstate -- Push a new state, which is found in yystate. | +`------------------------------------------------------------*/ + yynewstate: + /* In all cases, when you get here, the value and location stacks + have just been pushed. So pushing a state here evens the stacks. */ + yyssp++; + + yysetstate: + *yyssp = yystate; + + if (yyss + yystacksize - 1 <= yyssp) + { + /* Get the current used size of the three stacks, in elements. */ + YYSIZE_T yysize = yyssp - yyss + 1; + +#ifdef yyoverflow + { + /* Give user a chance to reallocate the stack. Use copies of + these so that the &'s don't force the real ones into + memory. */ + YYSTYPE *yyvs1 = yyvs; + yytype_int16 *yyss1 = yyss; + + /* Each stack pointer address is followed by the size of the + data in use in that stack, in bytes. This used to be a + conditional around just the two extra args, but that might + be undefined if yyoverflow is a macro. */ + yyoverflow (YY_("memory exhausted"), + &yyss1, yysize * sizeof (*yyssp), + &yyvs1, yysize * sizeof (*yyvsp), + &yystacksize); + + yyss = yyss1; + yyvs = yyvs1; + } +#else /* no yyoverflow */ +# ifndef YYSTACK_RELOCATE + goto yyexhaustedlab; +# else + /* Extend the stack our own way. */ + if (YYMAXDEPTH <= yystacksize) + goto yyexhaustedlab; + yystacksize *= 2; + if (YYMAXDEPTH < yystacksize) + yystacksize = YYMAXDEPTH; + + { + yytype_int16 *yyss1 = yyss; + union yyalloc *yyptr = + (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize)); + if (! yyptr) + goto yyexhaustedlab; + YYSTACK_RELOCATE (yyss_alloc, yyss); + YYSTACK_RELOCATE (yyvs_alloc, yyvs); +# undef YYSTACK_RELOCATE + if (yyss1 != yyssa) + YYSTACK_FREE (yyss1); + } +# endif +#endif /* no yyoverflow */ + + yyssp = yyss + yysize - 1; + yyvsp = yyvs + yysize - 1; + + YYDPRINTF ((stderr, "Stack size increased to %lu\n", + (unsigned long int) yystacksize)); + + if (yyss + yystacksize - 1 <= yyssp) + YYABORT; + } + + YYDPRINTF ((stderr, "Entering state %d\n", yystate)); + + if (yystate == YYFINAL) + YYACCEPT; + + goto yybackup; + +/*-----------. +| yybackup. | +`-----------*/ +yybackup: + + /* Do appropriate processing given the current state. Read a + lookahead token if we need one and don't already have one. */ + + /* First try to decide what to do without reference to lookahead token. */ + yyn = yypact[yystate]; + if (yyn == YYPACT_NINF) + goto yydefault; + + /* Not known => get a lookahead token if don't already have one. */ + + /* YYCHAR is either YYEMPTY or YYEOF or a valid lookahead symbol. */ + if (yychar == YYEMPTY) + { + YYDPRINTF ((stderr, "Reading a token: ")); + yychar = YYLEX; + } + + if (yychar <= YYEOF) + { + yychar = yytoken = YYEOF; + YYDPRINTF ((stderr, "Now at end of input.\n")); + } + else + { + yytoken = YYTRANSLATE (yychar); + YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc); + } + + /* If the proper action on seeing token YYTOKEN is to reduce or to + detect an error, take that action. */ + yyn += yytoken; + if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken) + goto yydefault; + yyn = yytable[yyn]; + if (yyn <= 0) + { + if (yyn == 0 || yyn == YYTABLE_NINF) + goto yyerrlab; + yyn = -yyn; + goto yyreduce; + } + + /* Count tokens shifted since error; after three, turn off error + status. */ + if (yyerrstatus) + yyerrstatus--; + + /* Shift the lookahead token. */ + YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc); + + /* Discard the shifted token. */ + yychar = YYEMPTY; + + yystate = yyn; + *++yyvsp = yylval; + + goto yynewstate; + + +/*-----------------------------------------------------------. +| yydefault -- do the default action for the current state. | +`-----------------------------------------------------------*/ +yydefault: + yyn = yydefact[yystate]; + if (yyn == 0) + goto yyerrlab; + goto yyreduce; + + +/*-----------------------------. +| yyreduce -- Do a reduction. | +`-----------------------------*/ +yyreduce: + /* yyn is the number of a rule to reduce with. */ + yylen = yyr2[yyn]; + + /* If YYLEN is nonzero, implement the default value of the action: + `$$ = $1'. + + Otherwise, the following line sets YYVAL to garbage. + This behavior is undocumented and Bison + users should not rely upon it. Assigning to YYVAL + unconditionally makes the parser a bit smaller, and it avoids a + GCC warning that YYVAL may be used uninitialized. */ + yyval = yyvsp[1-yylen]; + + + YY_REDUCE_PRINT (yyn); + switch (yyn) + { + case 4: + +/* Line 1464 of yacc.c */ +#line 163 "libmemcached/options/parser.yy" + { ;} + break; + + case 5: + +/* Line 1464 of yacc.c */ +#line 165 "libmemcached/options/parser.yy" + { ;} + break; + + case 6: + +/* Line 1464 of yacc.c */ +#line 167 "libmemcached/options/parser.yy" + { ;} + break; + + case 7: + +/* Line 1464 of yacc.c */ +#line 169 "libmemcached/options/parser.yy" + { + context->set_end(); + YYACCEPT; + ;} + break; + + case 8: + +/* Line 1464 of yacc.c */ +#line 174 "libmemcached/options/parser.yy" + { + context->rc= MEMCACHED_PARSE_USER_ERROR; + parser_abort(context, NULL); + ;} + break; + + case 9: + +/* Line 1464 of yacc.c */ +#line 179 "libmemcached/options/parser.yy" + { + memcached_reset(context->memc); + ;} + break; + + case 10: + +/* Line 1464 of yacc.c */ +#line 183 "libmemcached/options/parser.yy" + { + yydebug= 1; + ;} + break; + + case 11: + +/* Line 1464 of yacc.c */ +#line 187 "libmemcached/options/parser.yy" + { + if ((context->rc= memcached_parse_configure_file(context->memc, (yyvsp[(3) - (3)].string).c_str, (yyvsp[(3) - (3)].string).length)) != MEMCACHED_SUCCESS) + { + parser_abort(context, NULL); + } + ;} + break; + + case 12: + +/* Line 1464 of yacc.c */ +#line 198 "libmemcached/options/parser.yy" + { + if ((context->rc= memcached_server_add_parsed(context->memc, (yyvsp[(2) - (2)].server).c_str, (yyvsp[(2) - (2)].server).length, (yyvsp[(2) - (2)].server).port, 0)) != MEMCACHED_SUCCESS) + { + parser_abort(context, NULL); + } + ;} + break; + + case 13: + +/* Line 1464 of yacc.c */ +#line 205 "libmemcached/options/parser.yy" + { + ;} + break; + + case 14: + +/* Line 1464 of yacc.c */ +#line 208 "libmemcached/options/parser.yy" + { + memcached_set_configuration_file(context->memc, (yyvsp[(2) - (2)].string).c_str, (yyvsp[(2) - (2)].string).length); + ;} + break; + + case 16: + +/* Line 1464 of yacc.c */ +#line 216 "libmemcached/options/parser.yy" + { + if ((context->rc= memcached_set_prefix_key(context->memc, (yyvsp[(2) - (2)].string).c_str, (yyvsp[(2) - (2)].string).length)) != MEMCACHED_SUCCESS) + { + parser_abort(context, NULL);; + } + ;} + break; + + case 17: + +/* Line 1464 of yacc.c */ +#line 223 "libmemcached/options/parser.yy" + { + if ((context->rc= memcached_behavior_set(context->memc, MEMCACHED_BEHAVIOR_DISTRIBUTION, (yyvsp[(2) - (2)].distribution))) != MEMCACHED_SUCCESS) + { + parser_abort(context, NULL);; + } + ;} + break; + + case 18: + +/* Line 1464 of yacc.c */ +#line 230 "libmemcached/options/parser.yy" + { + if ((context->rc= memcached_behavior_set(context->memc, MEMCACHED_BEHAVIOR_DISTRIBUTION, (yyvsp[(2) - (4)].distribution))) != MEMCACHED_SUCCESS) + { + parser_abort(context, NULL);; + } + if ((context->rc= memcached_behavior_set_distribution_hash(context->memc, (yyvsp[(4) - (4)].hash))) != MEMCACHED_SUCCESS) + { + parser_abort(context, NULL);; + } + ;} + break; + + case 19: + +/* Line 1464 of yacc.c */ +#line 241 "libmemcached/options/parser.yy" + { + if ((context->rc= memcached_behavior_set(context->memc, MEMCACHED_BEHAVIOR_HASH, (yyvsp[(2) - (2)].hash))) != MEMCACHED_SUCCESS) + { + parser_abort(context, NULL);; + } + ;} + break; + + case 20: + +/* Line 1464 of yacc.c */ +#line 248 "libmemcached/options/parser.yy" + { + if ((context->rc= memcached_behavior_set(context->memc, (yyvsp[(1) - (2)].behavior), (yyvsp[(2) - (2)].number))) != MEMCACHED_SUCCESS) + { + parser_abort(context, NULL);; + } + ;} + break; + + case 21: + +/* Line 1464 of yacc.c */ +#line 255 "libmemcached/options/parser.yy" + { + if ((context->rc= memcached_behavior_set(context->memc, (yyvsp[(1) - (1)].behavior), true)) != MEMCACHED_SUCCESS) + { + parser_abort(context, NULL);; + } + ;} + break; + + case 22: + +/* Line 1464 of yacc.c */ +#line 262 "libmemcached/options/parser.yy" + { + ;} + break; + + case 23: + +/* Line 1464 of yacc.c */ +#line 268 "libmemcached/options/parser.yy" + { + (yyval.behavior)= MEMCACHED_BEHAVIOR_CONNECT_TIMEOUT; + ;} + break; + + case 24: + +/* Line 1464 of yacc.c */ +#line 272 "libmemcached/options/parser.yy" + { + (yyval.behavior)= MEMCACHED_BEHAVIOR_IO_MSG_WATERMARK; + ;} + break; + + case 25: + +/* Line 1464 of yacc.c */ +#line 276 "libmemcached/options/parser.yy" + { + (yyval.behavior)= MEMCACHED_BEHAVIOR_IO_BYTES_WATERMARK; + ;} + break; + + case 26: + +/* Line 1464 of yacc.c */ +#line 280 "libmemcached/options/parser.yy" + { + (yyval.behavior)= MEMCACHED_BEHAVIOR_IO_KEY_PREFETCH; + ;} + break; + + case 27: + +/* Line 1464 of yacc.c */ +#line 284 "libmemcached/options/parser.yy" + { + (yyval.behavior)= MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS; + ;} + break; + + case 28: + +/* Line 1464 of yacc.c */ +#line 288 "libmemcached/options/parser.yy" + { + (yyval.behavior)= MEMCACHED_BEHAVIOR_POLL_TIMEOUT; + ;} + break; + + case 29: + +/* Line 1464 of yacc.c */ +#line 292 "libmemcached/options/parser.yy" + { + (yyval.behavior)= MEMCACHED_BEHAVIOR_RCV_TIMEOUT; + ;} + break; + + case 30: + +/* Line 1464 of yacc.c */ +#line 296 "libmemcached/options/parser.yy" + { + (yyval.behavior)= MEMCACHED_BEHAVIOR_RETRY_TIMEOUT; + ;} + break; + + case 31: + +/* Line 1464 of yacc.c */ +#line 300 "libmemcached/options/parser.yy" + { + (yyval.behavior)= MEMCACHED_BEHAVIOR_SERVER_FAILURE_LIMIT; + ;} + break; + + case 32: + +/* Line 1464 of yacc.c */ +#line 304 "libmemcached/options/parser.yy" + { + (yyval.behavior)= MEMCACHED_BEHAVIOR_SND_TIMEOUT; + ;} + break; + + case 33: + +/* Line 1464 of yacc.c */ +#line 308 "libmemcached/options/parser.yy" + { + (yyval.behavior)= MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE; + ;} + break; + + case 34: + +/* Line 1464 of yacc.c */ +#line 312 "libmemcached/options/parser.yy" + { + (yyval.behavior)= MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE; + ;} + break; + + case 35: + +/* Line 1464 of yacc.c */ +#line 319 "libmemcached/options/parser.yy" + { + (yyval.behavior)= MEMCACHED_BEHAVIOR_AUTO_EJECT_HOSTS; + ;} + break; + + case 36: + +/* Line 1464 of yacc.c */ +#line 323 "libmemcached/options/parser.yy" + { + (yyval.behavior)= MEMCACHED_BEHAVIOR_BINARY_PROTOCOL; + ;} + break; + + case 37: + +/* Line 1464 of yacc.c */ +#line 327 "libmemcached/options/parser.yy" + { + (yyval.behavior)= MEMCACHED_BEHAVIOR_BUFFER_REQUESTS; + ;} + break; + + case 38: + +/* Line 1464 of yacc.c */ +#line 331 "libmemcached/options/parser.yy" + { + (yyval.behavior)= MEMCACHED_BEHAVIOR_CACHE_LOOKUPS; + ;} + break; + + case 39: + +/* Line 1464 of yacc.c */ +#line 335 "libmemcached/options/parser.yy" + { + (yyval.behavior)= MEMCACHED_BEHAVIOR_HASH_WITH_PREFIX_KEY; + ;} + break; + + case 40: + +/* Line 1464 of yacc.c */ +#line 339 "libmemcached/options/parser.yy" + { + (yyval.behavior)= MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED; + ;} + break; + + case 41: + +/* Line 1464 of yacc.c */ +#line 343 "libmemcached/options/parser.yy" + { + (yyval.behavior)= MEMCACHED_BEHAVIOR_NOREPLY; + ;} + break; + + case 42: + +/* Line 1464 of yacc.c */ +#line 347 "libmemcached/options/parser.yy" + { + (yyval.behavior)= MEMCACHED_BEHAVIOR_RANDOMIZE_REPLICA_READ; + ;} + break; + + case 43: + +/* Line 1464 of yacc.c */ +#line 351 "libmemcached/options/parser.yy" + { + (yyval.behavior)= MEMCACHED_BEHAVIOR_SORT_HOSTS; + ;} + break; + + case 44: + +/* Line 1464 of yacc.c */ +#line 355 "libmemcached/options/parser.yy" + { + (yyval.behavior)= MEMCACHED_BEHAVIOR_SUPPORT_CAS; + ;} + break; + + case 45: + +/* Line 1464 of yacc.c */ +#line 359 "libmemcached/options/parser.yy" + { + (yyval.behavior)= MEMCACHED_BEHAVIOR_TCP_NODELAY; + ;} + break; + + case 46: + +/* Line 1464 of yacc.c */ +#line 363 "libmemcached/options/parser.yy" + { + (yyval.behavior)= MEMCACHED_BEHAVIOR_TCP_KEEPALIVE; + ;} + break; + + case 47: + +/* Line 1464 of yacc.c */ +#line 367 "libmemcached/options/parser.yy" + { + (yyval.behavior)= MEMCACHED_BEHAVIOR_TCP_KEEPIDLE; + ;} + break; + + case 48: + +/* Line 1464 of yacc.c */ +#line 371 "libmemcached/options/parser.yy" + { + (yyval.behavior)= MEMCACHED_BEHAVIOR_USE_UDP; + ;} + break; + + case 49: + +/* Line 1464 of yacc.c */ +#line 375 "libmemcached/options/parser.yy" + { + (yyval.behavior)= MEMCACHED_BEHAVIOR_VERIFY_KEY; + ;} + break; + + case 50: + +/* Line 1464 of yacc.c */ +#line 382 "libmemcached/options/parser.yy" + { + if ((context->rc= memcached_server_add_parsed(context->memc, (yyvsp[(1) - (1)].server).c_str, (yyvsp[(1) - (1)].server).length, (yyvsp[(1) - (1)].server).port, 0)) != MEMCACHED_SUCCESS) + { + parser_abort(context, NULL);; + } + ;} + break; + + case 51: + +/* Line 1464 of yacc.c */ +#line 389 "libmemcached/options/parser.yy" + { + if ((context->rc= memcached_server_add_parsed(context->memc, (yyvsp[(3) - (3)].server).c_str, (yyvsp[(3) - (3)].server).length, (yyvsp[(3) - (3)].server).port, 0)) != MEMCACHED_SUCCESS) + { + parser_abort(context, NULL);; + } + ;} + break; + + case 52: + +/* Line 1464 of yacc.c */ +#line 399 "libmemcached/options/parser.yy" + { + (yyval.server).c_str= (yyvsp[(1) - (2)].string).c_str; + (yyval.server).length= (yyvsp[(1) - (2)].string).length -1; // -1 to remove : + (yyval.server).port= (yyvsp[(2) - (2)].number); + ;} + break; + + case 53: + +/* Line 1464 of yacc.c */ +#line 405 "libmemcached/options/parser.yy" + { + (yyval.server).c_str= (yyvsp[(1) - (1)].string).c_str; + (yyval.server).length= (yyvsp[(1) - (1)].string).length; + (yyval.server).port= MEMCACHED_DEFAULT_PORT; + ;} + break; + + case 54: + +/* Line 1464 of yacc.c */ +#line 411 "libmemcached/options/parser.yy" + { + (yyval.server).c_str= (yyvsp[(1) - (1)].string).c_str; + (yyval.server).length= (yyvsp[(1) - (1)].string).length; + (yyval.server).port= MEMCACHED_DEFAULT_PORT; + ;} + break; + + case 55: + +/* Line 1464 of yacc.c */ +#line 417 "libmemcached/options/parser.yy" + { + (yyval.server).c_str= (yyvsp[(1) - (2)].string).c_str; + (yyval.server).length= (yyvsp[(1) - (2)].string).length -1; // -1 to remove : + (yyval.server).port= (yyvsp[(2) - (2)].number); + ;} + break; + + case 56: + +/* Line 1464 of yacc.c */ +#line 423 "libmemcached/options/parser.yy" + { + (yyval.server).c_str= (yyvsp[(1) - (1)].string).c_str; + (yyval.server).length= (yyvsp[(1) - (1)].string).length; + (yyval.server).port= MEMCACHED_DEFAULT_PORT; + ;} + break; + + case 57: + +/* Line 1464 of yacc.c */ +#line 432 "libmemcached/options/parser.yy" + { + (yyval.hash)= MEMCACHED_HASH_MD5; + ;} + break; + + case 58: + +/* Line 1464 of yacc.c */ +#line 436 "libmemcached/options/parser.yy" + { + (yyval.hash)= MEMCACHED_HASH_CRC; + ;} + break; + + case 59: + +/* Line 1464 of yacc.c */ +#line 440 "libmemcached/options/parser.yy" + { + (yyval.hash)= MEMCACHED_HASH_FNV1_64; + ;} + break; + + case 60: + +/* Line 1464 of yacc.c */ +#line 444 "libmemcached/options/parser.yy" + { + (yyval.hash)= MEMCACHED_HASH_FNV1A_64; + ;} + break; + + case 61: + +/* Line 1464 of yacc.c */ +#line 448 "libmemcached/options/parser.yy" + { + (yyval.hash)= MEMCACHED_HASH_FNV1_32; + ;} + break; + + case 62: + +/* Line 1464 of yacc.c */ +#line 452 "libmemcached/options/parser.yy" + { + (yyval.hash)= MEMCACHED_HASH_FNV1A_32; + ;} + break; + + case 63: + +/* Line 1464 of yacc.c */ +#line 456 "libmemcached/options/parser.yy" + { + (yyval.hash)= MEMCACHED_HASH_HSIEH; + ;} + break; + + case 64: + +/* Line 1464 of yacc.c */ +#line 460 "libmemcached/options/parser.yy" + { + (yyval.hash)= MEMCACHED_HASH_MURMUR; + ;} + break; + + case 65: + +/* Line 1464 of yacc.c */ +#line 464 "libmemcached/options/parser.yy" + { + (yyval.hash)= MEMCACHED_HASH_JENKINS; + ;} + break; + + case 66: + +/* Line 1464 of yacc.c */ +#line 471 "libmemcached/options/parser.yy" + { + (yyval.string)= (yyvsp[(1) - (1)].string); + ;} + break; + + case 67: + +/* Line 1464 of yacc.c */ +#line 475 "libmemcached/options/parser.yy" + { + (yyval.string).c_str= (yyvsp[(1) - (1)].string).c_str +1; // +1 to move use passed the initial quote + (yyval.string).length= (yyvsp[(1) - (1)].string).length -1; // -1 removes the end quote + ;} + break; + + case 68: + +/* Line 1464 of yacc.c */ +#line 483 "libmemcached/options/parser.yy" + { + (yyval.distribution)= MEMCACHED_DISTRIBUTION_CONSISTENT; + ;} + break; + + case 69: + +/* Line 1464 of yacc.c */ +#line 487 "libmemcached/options/parser.yy" + { + (yyval.distribution)= MEMCACHED_DISTRIBUTION_MODULA; + ;} + break; + + case 70: + +/* Line 1464 of yacc.c */ +#line 491 "libmemcached/options/parser.yy" + { + (yyval.distribution)= MEMCACHED_DISTRIBUTION_RANDOM; + ;} + break; + + + +/* Line 1464 of yacc.c */ +#line 2165 "libmemcached/options/parser.cc" + default: break; + } + YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc); + + YYPOPSTACK (yylen); + yylen = 0; + YY_STACK_PRINT (yyss, yyssp); + + *++yyvsp = yyval; + + /* Now `shift' the result of the reduction. Determine what state + that goes to, based on the state we popped back to and the rule + number reduced by. */ + + yyn = yyr1[yyn]; + + yystate = yypgoto[yyn - YYNTOKENS] + *yyssp; + if (0 <= yystate && yystate <= YYLAST && yycheck[yystate] == *yyssp) + yystate = yytable[yystate]; + else + yystate = yydefgoto[yyn - YYNTOKENS]; + + goto yynewstate; + + +/*------------------------------------. +| yyerrlab -- here on detecting error | +`------------------------------------*/ +yyerrlab: + /* If not already recovering from an error, report this error. */ + if (!yyerrstatus) + { + ++yynerrs; +#if ! YYERROR_VERBOSE + yyerror (context, scanner, YY_("syntax error")); +#else + { + YYSIZE_T yysize = yysyntax_error (0, yystate, yychar); + if (yymsg_alloc < yysize && yymsg_alloc < YYSTACK_ALLOC_MAXIMUM) + { + YYSIZE_T yyalloc = 2 * yysize; + if (! (yysize <= yyalloc && yyalloc <= YYSTACK_ALLOC_MAXIMUM)) + yyalloc = YYSTACK_ALLOC_MAXIMUM; + if (yymsg != yymsgbuf) + YYSTACK_FREE (yymsg); + yymsg = (char *) YYSTACK_ALLOC (yyalloc); + if (yymsg) + yymsg_alloc = yyalloc; + else + { + yymsg = yymsgbuf; + yymsg_alloc = sizeof yymsgbuf; + } + } + + if (0 < yysize && yysize <= yymsg_alloc) + { + (void) yysyntax_error (yymsg, yystate, yychar); + yyerror (context, scanner, yymsg); + } + else + { + yyerror (context, scanner, YY_("syntax error")); + if (yysize != 0) + goto yyexhaustedlab; + } + } +#endif + } + + + + if (yyerrstatus == 3) + { + /* If just tried and failed to reuse lookahead token after an + error, discard it. */ + + if (yychar <= YYEOF) + { + /* Return failure if at end of input. */ + if (yychar == YYEOF) + YYABORT; + } + else + { + yydestruct ("Error: discarding", + yytoken, &yylval, context, scanner); + yychar = YYEMPTY; + } + } + + /* Else will try to reuse lookahead token after shifting the error + token. */ + goto yyerrlab1; + + +/*---------------------------------------------------. +| yyerrorlab -- error raised explicitly by YYERROR. | +`---------------------------------------------------*/ +yyerrorlab: + + /* Pacify compilers like GCC when the user code never invokes + YYERROR and the label yyerrorlab therefore never appears in user + code. */ + if (/*CONSTCOND*/ 0) + goto yyerrorlab; + + /* Do not reclaim the symbols of the rule which action triggered + this YYERROR. */ + YYPOPSTACK (yylen); + yylen = 0; + YY_STACK_PRINT (yyss, yyssp); + yystate = *yyssp; + goto yyerrlab1; + + +/*-------------------------------------------------------------. +| yyerrlab1 -- common code for both syntax error and YYERROR. | +`-------------------------------------------------------------*/ +yyerrlab1: + yyerrstatus = 3; /* Each real token shifted decrements this. */ + + for (;;) + { + yyn = yypact[yystate]; + if (yyn != YYPACT_NINF) + { + yyn += YYTERROR; + if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR) + { + yyn = yytable[yyn]; + if (0 < yyn) + break; + } + } + + /* Pop the current state because it cannot handle the error token. */ + if (yyssp == yyss) + YYABORT; + + + yydestruct ("Error: popping", + yystos[yystate], yyvsp, context, scanner); + YYPOPSTACK (1); + yystate = *yyssp; + YY_STACK_PRINT (yyss, yyssp); + } + + *++yyvsp = yylval; + + + /* Shift the error token. */ + YY_SYMBOL_PRINT ("Shifting", yystos[yyn], yyvsp, yylsp); + + yystate = yyn; + goto yynewstate; + + +/*-------------------------------------. +| yyacceptlab -- YYACCEPT comes here. | +`-------------------------------------*/ +yyacceptlab: + yyresult = 0; + goto yyreturn; + +/*-----------------------------------. +| yyabortlab -- YYABORT comes here. | +`-----------------------------------*/ +yyabortlab: + yyresult = 1; + goto yyreturn; + +#if !defined(yyoverflow) || YYERROR_VERBOSE +/*-------------------------------------------------. +| yyexhaustedlab -- memory exhaustion comes here. | +`-------------------------------------------------*/ +yyexhaustedlab: + yyerror (context, scanner, YY_("memory exhausted")); + yyresult = 2; + /* Fall through. */ +#endif + +yyreturn: + if (yychar != YYEMPTY) + yydestruct ("Cleanup: discarding lookahead", + yytoken, &yylval, context, scanner); + /* Do not reclaim the symbols of the rule which action triggered + this YYABORT or YYACCEPT. */ + YYPOPSTACK (yylen); + YY_STACK_PRINT (yyss, yyssp); + while (yyssp != yyss) + { + yydestruct ("Cleanup: popping", + yystos[*yyssp], yyvsp, context, scanner); + YYPOPSTACK (1); + } +#ifndef yyoverflow + if (yyss != yyssa) + YYSTACK_FREE (yyss); +#endif +#if YYERROR_VERBOSE + if (yymsg != yymsgbuf) + YYSTACK_FREE (yymsg); +#endif + /* Make sure YYID is used. */ + return YYID (yyresult); +} + + + +/* Line 1684 of yacc.c */ +#line 496 "libmemcached/options/parser.yy" + + +void Context::start() +{ + config_parse(this, (void **)scanner); +} + + diff --git a/libmemcached/options/parser.h b/libmemcached/options/parser.h new file mode 100644 index 00000000..99f682fd --- /dev/null +++ b/libmemcached/options/parser.h @@ -0,0 +1,122 @@ +/* A Bison parser, made by GNU Bison 2.4.3. */ + +/* Skeleton interface for Bison's Yacc-like parsers in C + + Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005, 2006, + 2009, 2010 Free Software Foundation, Inc. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +/* As a special exception, you may create a larger work that contains + part or all of the Bison parser skeleton and distribute that work + under terms of your choice, so long as that work isn't itself a + parser generator using the skeleton or a modified version thereof + as a parser skeleton. Alternatively, if you modify or redistribute + the parser skeleton itself, you may (at your option) remove this + special exception, which will cause the skeleton and the resulting + Bison output files to be licensed under the GNU General Public + License without this special exception. + + This special exception was added by the Free Software Foundation in + version 2.2 of Bison. */ + + +/* Tokens. */ +#ifndef YYTOKENTYPE +# define YYTOKENTYPE + /* Put the tokens into the symbol table, so that GDB and other debuggers + know about them. */ + enum yytokentype { + COMMENT = 258, + END = 259, + ERROR = 260, + RESET = 261, + PARSER_DEBUG = 262, + INCLUDE = 263, + CONFIGURE_FILE = 264, + EMPTY_LINE = 265, + SERVER = 266, + SERVERS = 267, + SERVERS_OPTION = 268, + UNKNOWN_OPTION = 269, + UNKNOWN = 270, + AUTO_EJECT_HOSTS = 271, + BINARY_PROTOCOL = 272, + BUFFER_REQUESTS = 273, + CACHE_LOOKUPS = 274, + CONNECT_TIMEOUT = 275, + DISTRIBUTION = 276, + HASH = 277, + HASH_WITH_PREFIX_KEY = 278, + IO_BYTES_WATERMARK = 279, + IO_KEY_PREFETCH = 280, + IO_MSG_WATERMARK = 281, + KETAMA_HASH = 282, + KETAMA_WEIGHTED = 283, + NOREPLY = 284, + NUMBER_OF_REPLICAS = 285, + POLL_TIMEOUT = 286, + RANDOMIZE_REPLICA_READ = 287, + RCV_TIMEOUT = 288, + RETRY_TIMEOUT = 289, + SERVER_FAILURE_LIMIT = 290, + SND_TIMEOUT = 291, + SOCKET_RECV_SIZE = 292, + SOCKET_SEND_SIZE = 293, + SORT_HOSTS = 294, + SUPPORT_CAS = 295, + _TCP_NODELAY = 296, + _TCP_KEEPALIVE = 297, + _TCP_KEEPIDLE = 298, + USER_DATA = 299, + USE_UDP = 300, + VERIFY_KEY = 301, + PREFIX_KEY = 302, + MD5 = 303, + CRC = 304, + FNV1_64 = 305, + FNV1A_64 = 306, + FNV1_32 = 307, + FNV1A_32 = 308, + HSIEH = 309, + MURMUR = 310, + JENKINS = 311, + CONSISTENT = 312, + MODULA = 313, + RANDOM = 314, + TRUE = 315, + FALSE = 316, + NUMBER = 317, + FLOAT = 318, + HOSTNAME = 319, + HOSTNAME_WITH_PORT = 320, + IPADDRESS = 321, + IPADDRESS_WITH_PORT = 322, + STRING = 323, + QUOTED_STRING = 324, + FILE_PATH = 325 + }; +#endif + + + +#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED + +# define yystype YYSTYPE /* obsolescent; will be withdrawn */ +# define YYSTYPE_IS_DECLARED 1 +#endif + + + + diff --git a/libmemcached/options/scanner.cc b/libmemcached/options/scanner.cc new file mode 100644 index 00000000..ecc818c0 --- /dev/null +++ b/libmemcached/options/scanner.cc @@ -0,0 +1,3581 @@ +#line 2 "libmemcached/options/scanner.cc" +#line 22 "libmemcached/options/scanner.l" + +#pragma GCC diagnostic ignored "-Wold-style-cast" +#pragma GCC diagnostic ignored "-Wunused-parameter" + +#include +#include +#include +#include + +#define YY_EXTRA_TYPE Context* + + + + +#line 18 "libmemcached/options/scanner.cc" + +#define YY_INT_ALIGNED short int + +/* A lexical scanner generated by flex */ + +/* %not-for-header */ + +/* %if-c-only */ +/* %if-not-reentrant */ +/* %endif */ +/* %endif */ +/* %ok-for-header */ + +#define FLEX_SCANNER +#define YY_FLEX_MAJOR_VERSION 2 +#define YY_FLEX_MINOR_VERSION 5 +#define YY_FLEX_SUBMINOR_VERSION 35 +#if YY_FLEX_SUBMINOR_VERSION > 0 +#define FLEX_BETA +#endif + +/* %if-c++-only */ +/* %endif */ + +/* %if-c-only */ + +/* %endif */ + +/* %if-c-only */ + +/* %endif */ + +/* First, we deal with platform-specific or compiler-specific issues. */ + +/* begin standard C headers. */ +/* %if-c-only */ +#include +#include +#include +#include +/* %endif */ + +/* %if-tables-serialization */ +/* %endif */ +/* end standard C headers. */ + +/* %if-c-or-c++ */ +/* flex integer type definitions */ + +#ifndef FLEXINT_H +#define FLEXINT_H + +/* C99 systems have . Non-C99 systems may or may not. */ + +#if defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L + +/* C99 says to define __STDC_LIMIT_MACROS before including stdint.h, + * if you want the limit (max/min) macros for int types. + */ +#ifndef __STDC_LIMIT_MACROS +#define __STDC_LIMIT_MACROS 1 +#endif + +#include +typedef int8_t flex_int8_t; +typedef uint8_t flex_uint8_t; +typedef int16_t flex_int16_t; +typedef uint16_t flex_uint16_t; +typedef int32_t flex_int32_t; +typedef uint32_t flex_uint32_t; +#else +typedef signed char flex_int8_t; +typedef short int flex_int16_t; +typedef int flex_int32_t; +typedef unsigned char flex_uint8_t; +typedef unsigned short int flex_uint16_t; +typedef unsigned int flex_uint32_t; +#endif /* ! C99 */ + +/* Limits of integral types. */ +#ifndef INT8_MIN +#define INT8_MIN (-128) +#endif +#ifndef INT16_MIN +#define INT16_MIN (-32767-1) +#endif +#ifndef INT32_MIN +#define INT32_MIN (-2147483647-1) +#endif +#ifndef INT8_MAX +#define INT8_MAX (127) +#endif +#ifndef INT16_MAX +#define INT16_MAX (32767) +#endif +#ifndef INT32_MAX +#define INT32_MAX (2147483647) +#endif +#ifndef UINT8_MAX +#define UINT8_MAX (255U) +#endif +#ifndef UINT16_MAX +#define UINT16_MAX (65535U) +#endif +#ifndef UINT32_MAX +#define UINT32_MAX (4294967295U) +#endif + +#endif /* ! FLEXINT_H */ + +/* %endif */ + +/* %if-c++-only */ +/* %endif */ + +#ifdef __cplusplus + +/* The "const" storage-class-modifier is valid. */ +#define YY_USE_CONST + +#else /* ! __cplusplus */ + +/* C99 requires __STDC__ to be defined as 1. */ +#if defined (__STDC__) + +#define YY_USE_CONST + +#endif /* defined (__STDC__) */ +#endif /* ! __cplusplus */ + +#ifdef YY_USE_CONST +#define yyconst const +#else +#define yyconst +#endif + +/* %not-for-header */ + +/* Returned upon end-of-file. */ +#define YY_NULL 0 +/* %ok-for-header */ + +/* %not-for-header */ + +/* Promotes a possibly negative, possibly signed char to an unsigned + * integer for use as an array index. If the signed char is negative, + * we want to instead treat it as an 8-bit unsigned char, hence the + * double cast. + */ +#define YY_SC_TO_UI(c) ((unsigned int) (unsigned char) c) +/* %ok-for-header */ + +/* %if-reentrant */ + +/* An opaque pointer. */ +#ifndef YY_TYPEDEF_YY_SCANNER_T +#define YY_TYPEDEF_YY_SCANNER_T +typedef void* yyscan_t; +#endif + +/* For convenience, these vars (plus the bison vars far below) + are macros in the reentrant scanner. */ +#define yyin yyg->yyin_r +#define yyout yyg->yyout_r +#define yyextra yyg->yyextra_r +#define yyleng yyg->yyleng_r +#define yytext yyg->yytext_r +#define yylineno (YY_CURRENT_BUFFER_LVALUE->yy_bs_lineno) +#define yycolumn (YY_CURRENT_BUFFER_LVALUE->yy_bs_column) +#define yy_flex_debug yyg->yy_flex_debug_r + +/* %endif */ + +/* %if-not-reentrant */ +/* %endif */ + +/* Enter a start condition. This macro really ought to take a parameter, + * but we do it the disgusting crufty way forced on us by the ()-less + * definition of BEGIN. + */ +#define BEGIN yyg->yy_start = 1 + 2 * + +/* Translate the current start state into a value that can be later handed + * to BEGIN to return to the state. The YYSTATE alias is for lex + * compatibility. + */ +#define YY_START ((yyg->yy_start - 1) / 2) +#define YYSTATE YY_START + +/* Action number for EOF rule of a given start state. */ +#define YY_STATE_EOF(state) (YY_END_OF_BUFFER + state + 1) + +/* Special action meaning "start processing a new file". */ +#define YY_NEW_FILE config_restart(yyin ,yyscanner ) + +#define YY_END_OF_BUFFER_CHAR 0 + +/* Size of default input buffer. */ +#ifndef YY_BUF_SIZE +#define YY_BUF_SIZE 16384 +#endif + +/* The state buf must be large enough to hold one state per character in the main buffer. + */ +#define YY_STATE_BUF_SIZE ((YY_BUF_SIZE + 2) * sizeof(yy_state_type)) + +#ifndef YY_TYPEDEF_YY_BUFFER_STATE +#define YY_TYPEDEF_YY_BUFFER_STATE +typedef struct yy_buffer_state *YY_BUFFER_STATE; +#endif + +/* %if-not-reentrant */ +/* %endif */ + +/* %if-c-only */ +/* %if-not-reentrant */ +/* %endif */ +/* %endif */ + +#define EOB_ACT_CONTINUE_SCAN 0 +#define EOB_ACT_END_OF_FILE 1 +#define EOB_ACT_LAST_MATCH 2 + + #define YY_LESS_LINENO(n) + +/* Return all but the first "n" matched characters back to the input stream. */ +#define yyless(n) \ + do \ + { \ + /* Undo effects of setting up yytext. */ \ + int yyless_macro_arg = (n); \ + YY_LESS_LINENO(yyless_macro_arg);\ + *yy_cp = yyg->yy_hold_char; \ + YY_RESTORE_YY_MORE_OFFSET \ + yyg->yy_c_buf_p = yy_cp = yy_bp + yyless_macro_arg - YY_MORE_ADJ; \ + YY_DO_BEFORE_ACTION; /* set up yytext again */ \ + } \ + while ( 0 ) + +#define unput(c) yyunput( c, yyg->yytext_ptr , yyscanner ) + +#ifndef YY_TYPEDEF_YY_SIZE_T +#define YY_TYPEDEF_YY_SIZE_T +typedef size_t yy_size_t; +#endif + +#ifndef YY_STRUCT_YY_BUFFER_STATE +#define YY_STRUCT_YY_BUFFER_STATE +struct yy_buffer_state + { +/* %if-c-only */ + FILE *yy_input_file; +/* %endif */ + +/* %if-c++-only */ +/* %endif */ + + char *yy_ch_buf; /* input buffer */ + char *yy_buf_pos; /* current position in input buffer */ + + /* Size of input buffer in bytes, not including room for EOB + * characters. + */ + yy_size_t yy_buf_size; + + /* Number of characters read into yy_ch_buf, not including EOB + * characters. + */ + int yy_n_chars; + + /* Whether we "own" the buffer - i.e., we know we created it, + * and can realloc() it to grow it, and should free() it to + * delete it. + */ + int yy_is_our_buffer; + + /* Whether this is an "interactive" input source; if so, and + * if we're using stdio for input, then we want to use getc() + * instead of fread(), to make sure we stop fetching input after + * each newline. + */ + int yy_is_interactive; + + /* Whether we're considered to be at the beginning of a line. + * If so, '^' rules will be active on the next match, otherwise + * not. + */ + int yy_at_bol; + + int yy_bs_lineno; /**< The line count. */ + int yy_bs_column; /**< The column count. */ + + /* Whether to try to fill the input buffer when we reach the + * end of it. + */ + int yy_fill_buffer; + + int yy_buffer_status; + +#define YY_BUFFER_NEW 0 +#define YY_BUFFER_NORMAL 1 + /* When an EOF's been seen but there's still some text to process + * then we mark the buffer as YY_EOF_PENDING, to indicate that we + * shouldn't try reading from the input source any more. We might + * still have a bunch of tokens to match, though, because of + * possible backing-up. + * + * When we actually see the EOF, we change the status to "new" + * (via config_restart()), so that the user can continue scanning by + * just pointing yyin at a new input file. + */ +#define YY_BUFFER_EOF_PENDING 2 + + }; +#endif /* !YY_STRUCT_YY_BUFFER_STATE */ + +/* %if-c-only Standard (non-C++) definition */ +/* %not-for-header */ + +/* %if-not-reentrant */ +/* %endif */ +/* %ok-for-header */ + +/* %endif */ + +/* We provide macros for accessing buffer states in case in the + * future we want to put the buffer states in a more general + * "scanner state". + * + * Returns the top of the stack, or NULL. + */ +#define YY_CURRENT_BUFFER ( yyg->yy_buffer_stack \ + ? yyg->yy_buffer_stack[yyg->yy_buffer_stack_top] \ + : NULL) + +/* Same as previous macro, but useful when we know that the buffer stack is not + * NULL or when we need an lvalue. For internal use only. + */ +#define YY_CURRENT_BUFFER_LVALUE yyg->yy_buffer_stack[yyg->yy_buffer_stack_top] + +/* %if-c-only Standard (non-C++) definition */ + +/* %if-not-reentrant */ +/* %not-for-header */ + +/* %ok-for-header */ + +/* %endif */ + +void config_restart (FILE *input_file ,yyscan_t yyscanner ); +void config__switch_to_buffer (YY_BUFFER_STATE new_buffer ,yyscan_t yyscanner ); +YY_BUFFER_STATE config__create_buffer (FILE *file,int size ,yyscan_t yyscanner ); +void config__delete_buffer (YY_BUFFER_STATE b ,yyscan_t yyscanner ); +void config__flush_buffer (YY_BUFFER_STATE b ,yyscan_t yyscanner ); +void config_push_buffer_state (YY_BUFFER_STATE new_buffer ,yyscan_t yyscanner ); +void config_pop_buffer_state (yyscan_t yyscanner ); + +static void config_ensure_buffer_stack (yyscan_t yyscanner ); +static void config__load_buffer_state (yyscan_t yyscanner ); +static void config__init_buffer (YY_BUFFER_STATE b,FILE *file ,yyscan_t yyscanner ); + +#define YY_FLUSH_BUFFER config__flush_buffer(YY_CURRENT_BUFFER ,yyscanner) + +YY_BUFFER_STATE config__scan_buffer (char *base,yy_size_t size ,yyscan_t yyscanner ); +YY_BUFFER_STATE config__scan_string (yyconst char *yy_str ,yyscan_t yyscanner ); +YY_BUFFER_STATE config__scan_bytes (yyconst char *bytes,int len ,yyscan_t yyscanner ); + +/* %endif */ + +void *config_alloc (yy_size_t ,yyscan_t yyscanner ); +void *config_realloc (void *,yy_size_t ,yyscan_t yyscanner ); +void config_free (void * ,yyscan_t yyscanner ); + +#define yy_new_buffer config__create_buffer + +#define yy_set_interactive(is_interactive) \ + { \ + if ( ! YY_CURRENT_BUFFER ){ \ + config_ensure_buffer_stack (yyscanner); \ + YY_CURRENT_BUFFER_LVALUE = \ + config__create_buffer(yyin,YY_BUF_SIZE ,yyscanner); \ + } \ + YY_CURRENT_BUFFER_LVALUE->yy_is_interactive = is_interactive; \ + } + +#define yy_set_bol(at_bol) \ + { \ + if ( ! YY_CURRENT_BUFFER ){\ + config_ensure_buffer_stack (yyscanner); \ + YY_CURRENT_BUFFER_LVALUE = \ + config__create_buffer(yyin,YY_BUF_SIZE ,yyscanner); \ + } \ + YY_CURRENT_BUFFER_LVALUE->yy_at_bol = at_bol; \ + } + +#define YY_AT_BOL() (YY_CURRENT_BUFFER_LVALUE->yy_at_bol) + +/* %% [1.0] yytext/yyin/yyout/yy_state_type/yylineno etc. def's & init go here */ +/* Begin user sect3 */ + +#define config_wrap(n) 1 +#define YY_SKIP_YYWRAP + +#define FLEX_DEBUG + +typedef unsigned char YY_CHAR; + +typedef int yy_state_type; + +#define yytext_ptr yytext_r + +/* %if-c-only Standard (non-C++) definition */ + +static yy_state_type yy_get_previous_state (yyscan_t yyscanner ); +static yy_state_type yy_try_NUL_trans (yy_state_type current_state ,yyscan_t yyscanner); +static int yy_get_next_buffer (yyscan_t yyscanner ); +static void yy_fatal_error (yyconst char msg[] ,yyscan_t yyscanner ); + +/* %endif */ + +/* Done after the current pattern has been matched and before the + * corresponding action - sets up yytext. + */ +#define YY_DO_BEFORE_ACTION \ + yyg->yytext_ptr = yy_bp; \ +/* %% [2.0] code to fiddle yytext and yyleng for yymore() goes here \ */\ + yyleng = (size_t) (yy_cp - yy_bp); \ + yyg->yy_hold_char = *yy_cp; \ + *yy_cp = '\0'; \ +/* %% [3.0] code to copy yytext_ptr to yytext[] goes here, if %array \ */\ + yyg->yy_c_buf_p = yy_cp; + +/* %% [4.0] data tables for the DFA and the user's section 1 definitions go here */ +#define YY_NUM_RULES 96 +#define YY_END_OF_BUFFER 97 +/* This struct is not used in this scanner, + but its presence is necessary. */ +struct yy_trans_info + { + flex_int32_t yy_verify; + flex_int32_t yy_nxt; + }; +static yyconst flex_int16_t yy_accept[811] = + { 0, + 0, 0, 97, 95, 3, 3, 1, 95, 95, 2, + 93, 93, 93, 93, 93, 93, 93, 93, 93, 93, + 93, 93, 95, 0, 94, 76, 0, 2, 93, 0, + 93, 93, 93, 93, 93, 93, 93, 93, 93, 93, + 93, 93, 93, 93, 93, 93, 93, 93, 0, 4, + 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, + 76, 76, 76, 76, 76, 0, 0, 0, 2, 89, + 0, 93, 81, 93, 72, 93, 93, 93, 93, 93, + 93, 80, 93, 93, 93, 93, 93, 93, 76, 76, + 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, + + 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, + 76, 90, 90, 0, 0, 0, 2, 93, 93, 93, + 93, 93, 93, 93, 93, 93, 93, 93, 93, 93, + 74, 76, 76, 76, 76, 76, 76, 76, 0, 0, + 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, + 76, 76, 76, 76, 76, 76, 0, 0, 93, 70, + 73, 75, 93, 0, 86, 93, 93, 93, 93, 93, + 69, 93, 76, 76, 76, 76, 76, 76, 76, 76, + 0, 0, 0, 0, 0, 0, 76, 76, 76, 76, + 76, 76, 0, 0, 76, 76, 0, 0, 76, 76, + + 76, 0, 0, 0, 76, 0, 76, 0, 0, 93, + 0, 0, 0, 93, 93, 78, 87, 79, 93, 0, + 0, 76, 76, 76, 76, 76, 76, 0, 22, 0, + 0, 0, 0, 0, 0, 0, 76, 76, 76, 0, + 0, 76, 76, 0, 0, 76, 76, 0, 0, 76, + 0, 0, 76, 0, 0, 0, 0, 0, 0, 0, + 0, 76, 92, 0, 93, 0, 0, 84, 82, 68, + 88, 71, 0, 0, 76, 76, 0, 0, 76, 76, + 76, 0, 0, 0, 0, 0, 0, 0, 0, 76, + 76, 76, 0, 0, 76, 76, 0, 0, 0, 0, + + 76, 0, 0, 76, 0, 0, 76, 0, 0, 0, + 0, 0, 0, 0, 0, 76, 92, 91, 93, 85, + 83, 0, 0, 0, 0, 0, 0, 0, 0, 76, + 76, 76, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 33, 0, 0, 0, 0, 0, 0, 76, + 0, 0, 0, 0, 0, 5, 76, 0, 0, 0, + 0, 0, 0, 0, 76, 0, 0, 0, 0, 65, + 0, 0, 64, 0, 0, 92, 93, 0, 0, 0, + 0, 0, 0, 0, 0, 76, 0, 0, 76, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + + 0, 0, 0, 0, 0, 76, 0, 0, 0, 0, + 0, 6, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 77, 0, 0, 0, 0, 0, 0, 0, 0, + 76, 0, 0, 76, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 76, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 63, 62, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 76, + + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 53, 52, 0, 0, 0, 0, 0, 0, 0, 0, + 8, 7, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 76, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 66, + 67, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 55, 54, 0, 0, 57, + 0, 0, 56, 0, 0, 0, 0, 0, 0, 0, + + 0, 0, 0, 0, 0, 76, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 41, 40, 0, 0, 0, 0, 47, 46, + 0, 0, 0, 0, 0, 61, 0, 60, 0, 0, + 0, 0, 0, 0, 16, 15, 0, 0, 0, 0, + 21, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 37, 36, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 59, 58, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + + 0, 43, 42, 0, 0, 0, 0, 0, 0, 0, + 0, 12, 11, 14, 13, 18, 17, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 32, 31, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, + 9, 20, 19, 0, 0, 0, 28, 0, 0, 27, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 30, 0, 29, 0, 0, 0, + 0, 0, 0, 49, 51, 48, 50, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 26, + 25, 35, 34, 0, 0, 0, 0, 24, 23, 0, + + 0, 0, 0, 0, 0, 45, 44, 39, 38, 0 + } ; + +static yyconst flex_int32_t yy_ec[256] = + { 0, + 1, 1, 1, 1, 1, 1, 1, 1, 2, 3, + 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 4, 1, 5, 6, 1, 1, 1, 1, 1, + 1, 1, 1, 7, 8, 9, 1, 10, 11, 12, + 13, 14, 15, 16, 10, 10, 10, 17, 1, 1, + 18, 1, 1, 1, 19, 20, 21, 22, 23, 24, + 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, + 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, + 1, 1, 1, 1, 45, 1, 46, 47, 48, 49, + + 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, + 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, + 70, 71, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1 + } ; + +static yyconst flex_int32_t yy_meta[72] = + { 0, + 1, 1, 2, 1, 1, 1, 1, 1, 3, 3, + 3, 3, 3, 3, 3, 3, 1, 1, 3, 3, + 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, + 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, + 3, 3, 3, 3, 1, 3, 3, 3, 3, 3, + 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, + 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, + 3 + } ; + +static yyconst flex_int16_t yy_base[817] = + { 0, + 0, 949, 919, 2202, 2202, 2202, 2202, 906, 902, 63, + 71, 79, 73, 65, 81, 66, 72, 114, 112, 130, + 123, 119, 906, 900, 898, 184, 247, 255, 121, 263, + 129, 263, 264, 269, 265, 271, 273, 275, 320, 322, + 327, 331, 332, 333, 340, 371, 380, 381, 899, 2202, + 429, 77, 379, 382, 131, 141, 169, 260, 345, 258, + 441, 447, 272, 276, 329, 489, 505, 513, 522, 2202, + 530, 530, 421, 532, 536, 537, 541, 570, 585, 590, + 595, 376, 605, 596, 640, 644, 646, 652, 324, 343, + 386, 398, 393, 389, 395, 463, 510, 516, 524, 526, + + 534, 527, 521, 524, 528, 587, 589, 581, 582, 596, + 603, 707, 715, 724, 732, 740, 749, 749, 750, 751, + 755, 645, 763, 762, 800, 802, 804, 812, 813, 833, + 822, 627, 651, 648, 648, 749, 645, 658, 848, 860, + 751, 754, 773, 777, 820, 825, 464, 821, 821, 465, + 852, 848, 853, 466, 884, 863, 912, 921, 921, 923, + 927, 928, 929, 94, 933, 977, 965, 983, 978, 987, + 998, 1000, 572, 876, 892, 918, 916, 925, 913, 1004, + 908, 929, 916, 960, 982, 971, 990, 993, 1016, 761, + 1015, 1011, 1013, 1014, 1010, 1032, 1018, 1019, 1036, 786, + + 1029, 1035, 1036, 1031, 964, 1033, 1049, 1092, 1100, 1060, + 105, 889, 886, 1101, 1102, 1100, 1109, 1110, 1111, 1099, + 1106, 1087, 1095, 1132, 1107, 1120, 1125, 1112, 2202, 1113, + 1117, 1124, 1151, 1140, 1140, 1159, 1166, 1156, 1151, 1150, + 1151, 1148, 1160, 1165, 1166, 1187, 1160, 1170, 1171, 1161, + 1174, 1175, 1166, 1181, 1173, 1184, 1175, 1187, 1199, 1200, + 1208, 1194, 1229, 1256, 1256, 887, 884, 2202, 2202, 1241, + 1242, 1263, 1226, 1227, 1239, 1242, 1226, 1231, 1224, 1238, + 1265, 1259, 1264, 1270, 889, 886, 1271, 808, 807, 1252, + 1252, 1290, 1273, 1280, 1300, 1282, 1279, 1280, 1276, 1277, + + 1321, 1286, 1293, 1317, 1295, 1297, 1294, 1310, 1318, 1320, + 1324, 1313, 1329, 1330, 1316, 1323, 1377, 2202, 1346, 2202, + 2202, 1330, 1331, 1322, 1335, 1335, 1336, 1351, 1362, 1361, + 1356, 1361, 1364, 1365, 1367, 1373, 1367, 1373, 1378, 1372, + 1373, 1374, 0, 1383, 1384, 1387, 1388, 1391, 1392, 1379, + 1402, 1403, 1401, 1405, 1409, 2202, 824, 1412, 1415, 1426, + 1420, 1425, 1414, 1417, 1450, 1430, 1443, 1433, 1446, 2202, + 1432, 1433, 2202, 1443, 1444, 1492, 1493, 1464, 1465, 1451, + 1454, 1469, 1488, 1482, 1483, 1495, 1482, 1483, 1484, 1497, + 1498, 833, 1489, 1508, 779, 1492, 1511, 1509, 1510, 1510, + + 1511, 1513, 1514, 1516, 1517, 1518, 1511, 1513, 1534, 1538, + 1551, 2202, 1553, 1541, 1542, 1553, 1554, 1555, 1556, 1542, + 1543, 1561, 1562, 1566, 1554, 1567, 1557, 1569, 1570, 1567, + 1568, 1602, 1557, 1560, 1567, 1590, 1589, 1591, 1599, 1600, + 1622, 1604, 1605, 1606, 784, 745, 1593, 1613, 1599, 1598, + 1618, 1604, 1616, 1617, 766, 726, 1612, 1613, 1604, 1605, + 1632, 1610, 1613, 1631, 1634, 1651, 1653, 1643, 1644, 1664, + 1654, 1666, 1656, 1652, 1653, 1672, 1673, 1663, 1672, 1676, + 1666, 1675, 1679, 2202, 2202, 1656, 1657, 669, 653, 1663, + 1664, 1664, 1665, 1667, 1669, 1687, 1708, 1703, 1705, 1704, + + 1705, 1706, 1722, 1718, 1720, 1725, 1721, 1723, 1722, 1723, + 1713, 1714, 1712, 1713, 678, 677, 1717, 1718, 1717, 1718, + 1724, 1725, 1730, 1732, 1727, 1748, 1748, 1768, 1751, 1771, + 2202, 2202, 1757, 1758, 1769, 1767, 1755, 1772, 1770, 1758, + 2202, 2202, 1776, 1777, 1771, 1772, 1783, 1784, 1774, 1775, + 1783, 1784, 1789, 1791, 1784, 1783, 1804, 1804, 1821, 1809, + 1809, 1825, 1813, 1824, 1825, 1829, 1830, 1816, 1817, 2202, + 2202, 1833, 1834, 675, 674, 1819, 1820, 1821, 1822, 631, + 622, 626, 606, 566, 540, 2202, 2202, 1822, 1840, 2202, + 1824, 1842, 2202, 1833, 1835, 1849, 1852, 1857, 1859, 1861, + + 1862, 1871, 1872, 1870, 1871, 558, 1882, 1883, 1884, 1870, + 1878, 1887, 1873, 1881, 1875, 1876, 1881, 1882, 542, 533, + 1883, 1884, 2202, 2202, 1881, 1882, 1886, 1888, 2202, 2202, + 1890, 1911, 1913, 1915, 1930, 2202, 1932, 2202, 1919, 1920, + 1925, 1926, 1922, 1923, 2202, 2202, 1939, 1940, 1925, 1926, + 2202, 1942, 1943, 1932, 1948, 1951, 1935, 1951, 1954, 1951, + 1953, 1948, 1951, 2202, 2202, 1972, 1974, 532, 494, 1983, + 1984, 1982, 1983, 1984, 1985, 2202, 2202, 1975, 1976, 1985, + 1986, 1980, 1981, 412, 411, 1981, 1982, 1994, 1995, 1992, + 1998, 1989, 1995, 2001, 1992, 2008, 2010, 2008, 2029, 2031, + + 2033, 2202, 2202, 419, 379, 2017, 2019, 2020, 2021, 2029, + 2030, 2202, 2202, 2202, 2202, 2202, 2202, 405, 404, 2026, + 2027, 2051, 403, 2042, 2053, 359, 2044, 2202, 2202, 2053, + 2054, 2055, 2056, 2048, 2049, 2057, 2058, 2059, 2061, 2202, + 2202, 2202, 2202, 326, 316, 2050, 2202, 333, 2053, 2202, + 327, 2091, 2093, 2095, 2096, 2090, 2091, 323, 301, 299, + 266, 2090, 2091, 2092, 2202, 2093, 2202, 2086, 2087, 193, + 146, 2094, 2095, 2202, 2202, 2202, 2202, 2104, 2105, 170, + 153, 152, 151, 2093, 2094, 2104, 2105, 2090, 2091, 2202, + 2202, 2202, 2202, 2112, 2113, 2100, 2102, 2202, 2202, 2124, + + 2145, 150, 149, 2144, 2146, 2202, 2202, 2202, 2202, 2202, + 2195, 119, 2198, 117, 116, 108 + } ; + +static yyconst flex_int16_t yy_def[817] = + { 0, + 810, 1, 810, 810, 810, 810, 810, 811, 810, 812, + 812, 812, 12, 12, 12, 12, 12, 12, 12, 12, + 12, 12, 813, 811, 811, 810, 814, 812, 12, 814, + 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, + 12, 12, 12, 12, 12, 12, 12, 12, 813, 810, + 26, 51, 51, 51, 51, 51, 51, 51, 51, 51, + 51, 51, 51, 51, 51, 815, 816, 815, 812, 810, + 816, 12, 12, 12, 12, 12, 12, 12, 12, 12, + 12, 12, 12, 12, 12, 12, 12, 12, 51, 51, + 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, + + 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, + 51, 816, 815, 816, 816, 816, 812, 12, 12, 12, + 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, + 12, 51, 51, 51, 51, 51, 51, 51, 810, 810, + 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, + 51, 51, 51, 51, 51, 51, 816, 816, 12, 12, + 12, 12, 12, 810, 12, 12, 12, 12, 12, 12, + 12, 12, 51, 51, 51, 51, 51, 51, 51, 51, + 810, 810, 810, 810, 810, 810, 51, 51, 51, 51, + 51, 51, 810, 810, 51, 51, 810, 810, 51, 51, + + 51, 810, 810, 810, 51, 810, 51, 816, 816, 12, + 810, 810, 810, 12, 12, 12, 12, 12, 12, 810, + 810, 51, 51, 51, 51, 51, 51, 810, 810, 810, + 810, 810, 810, 810, 810, 810, 51, 51, 51, 810, + 810, 51, 51, 810, 810, 51, 51, 810, 810, 51, + 810, 810, 51, 810, 810, 810, 810, 810, 810, 810, + 810, 51, 816, 816, 12, 810, 810, 810, 810, 12, + 12, 12, 810, 810, 51, 51, 810, 810, 51, 51, + 51, 810, 810, 810, 810, 810, 810, 810, 810, 51, + 51, 51, 810, 810, 51, 51, 810, 810, 810, 810, + + 51, 810, 810, 51, 810, 810, 51, 810, 810, 810, + 810, 810, 810, 810, 810, 51, 816, 810, 12, 810, + 810, 810, 810, 810, 810, 810, 810, 810, 810, 51, + 51, 51, 810, 810, 810, 810, 810, 810, 810, 810, + 810, 810, 51, 810, 810, 810, 810, 810, 810, 51, + 810, 810, 810, 810, 810, 810, 51, 810, 810, 810, + 810, 810, 810, 810, 51, 810, 810, 810, 810, 810, + 810, 810, 810, 810, 810, 816, 12, 810, 810, 810, + 810, 810, 810, 810, 810, 51, 810, 810, 51, 810, + 810, 810, 810, 810, 810, 810, 810, 810, 810, 810, + + 810, 810, 810, 810, 810, 51, 810, 810, 810, 810, + 810, 810, 810, 810, 810, 810, 810, 810, 810, 810, + 810, 810, 810, 810, 810, 810, 810, 810, 810, 810, + 810, 12, 810, 810, 810, 810, 810, 810, 810, 810, + 51, 810, 810, 51, 810, 810, 810, 810, 810, 810, + 810, 810, 810, 810, 810, 810, 810, 810, 810, 810, + 51, 810, 810, 810, 810, 810, 810, 810, 810, 810, + 810, 810, 810, 810, 810, 810, 810, 810, 810, 810, + 810, 810, 810, 810, 810, 810, 810, 810, 810, 810, + 810, 810, 810, 810, 810, 810, 810, 810, 810, 51, + + 810, 810, 810, 810, 810, 810, 810, 810, 810, 810, + 810, 810, 810, 810, 810, 810, 810, 810, 810, 810, + 810, 810, 810, 810, 810, 810, 810, 810, 810, 810, + 810, 810, 810, 810, 810, 810, 810, 810, 810, 810, + 810, 810, 810, 810, 810, 810, 810, 810, 810, 810, + 810, 810, 810, 810, 51, 810, 810, 810, 810, 810, + 810, 810, 810, 810, 810, 810, 810, 810, 810, 810, + 810, 810, 810, 810, 810, 810, 810, 810, 810, 810, + 810, 810, 810, 810, 810, 810, 810, 810, 810, 810, + 810, 810, 810, 810, 810, 810, 810, 810, 810, 810, + + 810, 810, 810, 810, 810, 51, 810, 810, 810, 810, + 810, 810, 810, 810, 810, 810, 810, 810, 810, 810, + 810, 810, 810, 810, 810, 810, 810, 810, 810, 810, + 810, 810, 810, 810, 810, 810, 810, 810, 810, 810, + 810, 810, 810, 810, 810, 810, 810, 810, 810, 810, + 810, 810, 810, 810, 810, 810, 810, 810, 810, 810, + 810, 810, 810, 810, 810, 810, 810, 810, 810, 810, + 810, 810, 810, 810, 810, 810, 810, 810, 810, 810, + 810, 810, 810, 810, 810, 810, 810, 810, 810, 810, + 810, 810, 810, 810, 810, 810, 810, 810, 810, 810, + + 810, 810, 810, 810, 810, 810, 810, 810, 810, 810, + 810, 810, 810, 810, 810, 810, 810, 810, 810, 810, + 810, 810, 810, 810, 810, 810, 810, 810, 810, 810, + 810, 810, 810, 810, 810, 810, 810, 810, 810, 810, + 810, 810, 810, 810, 810, 810, 810, 810, 810, 810, + 810, 810, 810, 810, 810, 810, 810, 810, 810, 810, + 810, 810, 810, 810, 810, 810, 810, 810, 810, 810, + 810, 810, 810, 810, 810, 810, 810, 810, 810, 810, + 810, 810, 810, 810, 810, 810, 810, 810, 810, 810, + 810, 810, 810, 810, 810, 810, 810, 810, 810, 810, + + 810, 810, 810, 810, 810, 810, 810, 810, 810, 0, + 810, 810, 810, 810, 810, 810 + } ; + +static yyconst flex_int16_t yy_nxt[2274] = + { 0, + 4, 5, 6, 7, 8, 4, 7, 9, 4, 10, + 10, 10, 10, 10, 10, 10, 4, 7, 11, 11, + 12, 13, 14, 15, 11, 16, 17, 18, 11, 11, + 19, 11, 11, 11, 11, 20, 21, 22, 11, 11, + 11, 11, 11, 11, 4, 11, 11, 12, 13, 14, + 15, 11, 16, 17, 18, 11, 11, 19, 11, 11, + 11, 11, 20, 21, 22, 11, 11, 11, 11, 11, + 11, 27, 28, 28, 28, 28, 28, 28, 28, 30, + 31, 31, 31, 31, 31, 31, 31, 30, 31, 31, + 31, 31, 31, 31, 31, 34, 35, 29, 29, 37, + + 36, 29, 39, 40, 29, 29, 212, 29, 29, 213, + 116, 32, 38, 29, 33, 89, 29, 266, 113, 68, + 267, 29, 34, 35, 29, 29, 37, 36, 29, 39, + 40, 29, 29, 42, 29, 29, 41, 70, 32, 38, + 29, 33, 89, 29, 43, 47, 29, 29, 45, 29, + 44, 29, 46, 29, 48, 29, 29, 94, 29, 95, + 42, 29, 29, 41, 29, 29, 807, 806, 793, 792, + 791, 43, 47, 29, 29, 45, 29, 44, 29, 46, + 29, 48, 29, 29, 94, 29, 95, 790, 29, 29, + 785, 29, 29, 51, 51, 51, 51, 51, 51, 51, + + 784, 96, 52, 53, 54, 55, 51, 51, 51, 56, + 57, 51, 58, 51, 51, 59, 51, 60, 51, 61, + 62, 63, 64, 65, 51, 51, 51, 51, 96, 52, + 53, 54, 55, 51, 51, 51, 56, 57, 51, 58, + 51, 51, 59, 51, 60, 51, 61, 62, 63, 64, + 65, 51, 51, 51, 51, 66, 67, 67, 67, 67, + 67, 67, 67, 27, 69, 69, 69, 69, 69, 69, + 69, 66, 71, 71, 71, 71, 71, 71, 71, 70, + 70, 70, 97, 777, 73, 70, 75, 70, 74, 70, + 100, 70, 109, 101, 72, 29, 29, 29, 29, 29, + + 29, 29, 77, 29, 29, 29, 76, 29, 29, 97, + 29, 73, 110, 75, 78, 74, 776, 100, 775, 109, + 101, 72, 29, 29, 29, 29, 29, 29, 29, 77, + 29, 29, 29, 76, 29, 29, 70, 29, 70, 110, + 774, 78, 80, 70, 767, 82, 79, 70, 70, 70, + 765, 111, 29, 83, 29, 29, 70, 29, 81, 29, + 763, 132, 29, 29, 29, 29, 29, 29, 84, 80, + 762, 85, 29, 79, 133, 29, 750, 98, 111, 29, + 83, 29, 29, 99, 29, 81, 29, 70, 132, 29, + 29, 29, 29, 29, 29, 84, 70, 70, 85, 29, + + 92, 133, 29, 29, 98, 90, 29, 86, 29, 134, + 99, 29, 29, 29, 93, 87, 29, 91, 135, 88, + 747, 743, 742, 735, 136, 137, 734, 92, 717, 716, + 29, 138, 90, 29, 86, 29, 134, 70, 29, 29, + 29, 93, 87, 29, 91, 135, 88, 51, 51, 51, + 51, 136, 137, 29, 51, 51, 29, 51, 138, 102, + 51, 103, 51, 104, 51, 51, 51, 51, 51, 105, + 139, 193, 197, 202, 51, 51, 51, 51, 106, 107, + 29, 51, 51, 29, 51, 108, 102, 51, 103, 51, + 104, 51, 51, 51, 51, 51, 105, 66, 112, 112, + + 112, 112, 112, 112, 112, 106, 107, 140, 194, 198, + 203, 703, 108, 114, 115, 115, 115, 115, 115, 115, + 115, 66, 112, 112, 112, 112, 112, 112, 112, 70, + 27, 117, 117, 117, 117, 117, 117, 117, 71, 71, + 71, 71, 71, 71, 71, 71, 70, 141, 70, 702, + 665, 142, 70, 70, 143, 144, 145, 70, 146, 664, + 147, 148, 29, 149, 29, 29, 118, 29, 29, 120, + 119, 29, 29, 29, 141, 651, 29, 121, 142, 220, + 122, 143, 144, 145, 634, 146, 70, 147, 148, 29, + 149, 29, 29, 118, 29, 29, 120, 119, 29, 29, + + 29, 70, 29, 29, 121, 29, 70, 123, 150, 151, + 633, 70, 70, 632, 153, 154, 221, 29, 155, 124, + 29, 70, 29, 125, 152, 29, 127, 29, 29, 29, + 29, 29, 29, 631, 123, 150, 151, 29, 156, 630, + 29, 153, 154, 126, 29, 155, 124, 29, 629, 29, + 125, 152, 29, 127, 29, 29, 70, 29, 29, 173, + 70, 128, 70, 163, 29, 156, 129, 29, 70, 174, + 126, 175, 29, 176, 131, 29, 29, 29, 29, 29, + 29, 29, 179, 180, 29, 130, 173, 29, 128, 164, + 163, 624, 623, 129, 571, 570, 174, 544, 175, 29, + + 176, 131, 29, 29, 29, 29, 29, 29, 29, 179, + 180, 29, 130, 543, 29, 71, 71, 71, 71, 71, + 71, 71, 71, 66, 112, 112, 112, 112, 112, 112, + 112, 70, 71, 157, 157, 157, 157, 157, 157, 157, + 114, 158, 158, 158, 158, 158, 158, 158, 71, 71, + 71, 71, 71, 71, 71, 71, 70, 30, 117, 117, + 117, 117, 117, 117, 117, 70, 70, 70, 240, 187, + 512, 70, 177, 511, 160, 159, 188, 162, 70, 70, + 178, 29, 29, 29, 29, 29, 161, 29, 165, 502, + 29, 501, 189, 251, 29, 29, 187, 29, 29, 177, + + 166, 160, 159, 188, 162, 241, 190, 178, 29, 29, + 29, 29, 29, 161, 29, 165, 70, 29, 70, 189, + 70, 29, 29, 450, 29, 29, 167, 166, 70, 70, + 252, 168, 29, 190, 29, 29, 29, 29, 70, 29, + 447, 412, 169, 191, 170, 29, 192, 29, 29, 70, + 171, 340, 339, 167, 29, 172, 195, 29, 168, 29, + 196, 29, 29, 29, 29, 29, 29, 181, 29, 169, + 191, 170, 29, 192, 29, 29, 182, 171, 183, 184, + 199, 29, 172, 195, 29, 200, 201, 196, 185, 207, + 186, 204, 29, 337, 181, 29, 336, 321, 320, 269, + + 268, 50, 25, 182, 25, 183, 184, 199, 50, 26, + 25, 222, 200, 201, 223, 185, 207, 186, 810, 205, + 208, 209, 209, 209, 209, 209, 209, 209, 206, 114, + 71, 71, 71, 71, 71, 71, 71, 70, 222, 70, + 224, 223, 225, 70, 70, 70, 205, 226, 227, 70, + 231, 232, 233, 29, 23, 29, 29, 210, 29, 29, + 29, 29, 29, 29, 29, 29, 810, 224, 29, 225, + 810, 259, 810, 211, 226, 227, 810, 231, 232, 233, + 29, 70, 29, 29, 210, 29, 29, 29, 29, 29, + 29, 29, 29, 70, 70, 29, 215, 29, 214, 70, + + 29, 216, 234, 70, 235, 810, 810, 236, 260, 29, + 29, 228, 29, 217, 70, 29, 70, 218, 29, 29, + 237, 229, 29, 215, 29, 214, 238, 29, 216, 234, + 29, 235, 29, 29, 236, 219, 29, 29, 239, 29, + 217, 242, 29, 243, 218, 29, 29, 237, 230, 29, + 244, 245, 246, 238, 247, 248, 249, 29, 250, 29, + 29, 253, 219, 254, 256, 239, 255, 257, 242, 258, + 243, 261, 262, 810, 810, 810, 70, 244, 245, 246, + 810, 247, 248, 249, 810, 250, 810, 810, 253, 810, + 254, 256, 29, 255, 257, 29, 258, 265, 261, 262, + + 71, 263, 263, 263, 263, 263, 263, 263, 208, 264, + 264, 264, 264, 264, 264, 264, 70, 70, 70, 29, + 810, 273, 29, 270, 265, 70, 70, 70, 274, 275, + 276, 279, 29, 29, 29, 29, 29, 29, 271, 277, + 280, 29, 29, 29, 29, 29, 29, 272, 273, 810, + 270, 281, 282, 283, 284, 274, 275, 276, 279, 29, + 29, 29, 29, 29, 29, 271, 285, 280, 29, 29, + 29, 29, 29, 29, 272, 286, 278, 287, 281, 282, + 283, 284, 288, 289, 290, 291, 292, 293, 294, 295, + 296, 297, 298, 285, 299, 301, 302, 303, 304, 305, + + 306, 307, 286, 308, 287, 309, 310, 311, 312, 288, + 289, 290, 291, 292, 293, 294, 295, 296, 297, 298, + 313, 314, 301, 302, 303, 304, 305, 306, 307, 315, + 308, 300, 309, 310, 311, 312, 316, 71, 317, 317, + 317, 317, 317, 317, 317, 318, 324, 313, 314, 326, + 810, 810, 810, 322, 323, 328, 315, 70, 70, 341, + 329, 810, 330, 316, 208, 71, 71, 71, 71, 71, + 71, 71, 70, 29, 29, 331, 29, 29, 319, 70, + 322, 323, 328, 325, 332, 333, 327, 329, 29, 330, + 334, 29, 335, 338, 343, 29, 342, 344, 29, 346, + + 29, 29, 331, 29, 29, 319, 347, 348, 350, 351, + 352, 332, 333, 353, 354, 29, 359, 334, 29, 335, + 338, 343, 29, 360, 361, 29, 346, 363, 355, 364, + 374, 365, 366, 347, 345, 350, 351, 352, 356, 367, + 353, 354, 368, 359, 349, 369, 370, 371, 372, 373, + 360, 810, 378, 379, 363, 380, 364, 357, 365, 366, + 810, 362, 70, 387, 810, 358, 367, 375, 381, 368, + 382, 383, 369, 370, 371, 372, 373, 377, 29, 378, + 379, 29, 380, 384, 357, 71, 376, 376, 376, 376, + 376, 376, 376, 318, 385, 381, 386, 382, 383, 389, + + 388, 390, 391, 392, 377, 29, 393, 394, 29, 395, + 384, 396, 397, 398, 399, 400, 401, 402, 403, 404, + 405, 385, 406, 386, 407, 408, 389, 409, 390, 391, + 392, 410, 411, 393, 394, 413, 395, 414, 396, 397, + 398, 399, 400, 401, 402, 403, 404, 405, 415, 406, + 420, 407, 408, 421, 409, 416, 417, 422, 410, 411, + 418, 419, 413, 424, 414, 425, 426, 810, 427, 428, + 429, 430, 431, 810, 810, 415, 810, 420, 810, 810, + 421, 810, 416, 417, 433, 434, 435, 418, 419, 436, + 424, 437, 425, 426, 423, 427, 428, 429, 430, 431, + + 71, 71, 71, 71, 71, 71, 71, 71, 318, 70, + 438, 433, 434, 435, 439, 440, 436, 441, 437, 442, + 443, 444, 445, 446, 448, 29, 449, 451, 29, 452, + 432, 453, 454, 455, 456, 457, 458, 438, 459, 460, + 461, 439, 440, 462, 441, 463, 442, 443, 444, 445, + 446, 448, 29, 449, 451, 29, 452, 432, 453, 454, + 455, 456, 457, 458, 464, 459, 460, 461, 465, 466, + 462, 467, 463, 468, 469, 470, 471, 472, 473, 474, + 475, 476, 477, 480, 478, 481, 483, 484, 485, 486, + 487, 464, 479, 482, 488, 465, 466, 489, 467, 490, + + 468, 469, 470, 471, 472, 473, 474, 475, 476, 477, + 480, 478, 481, 483, 484, 485, 486, 487, 70, 479, + 482, 488, 491, 492, 489, 493, 490, 494, 495, 496, + 498, 499, 500, 503, 29, 504, 505, 29, 506, 517, + 507, 508, 509, 510, 513, 514, 515, 516, 519, 491, + 492, 520, 493, 521, 494, 495, 522, 498, 499, 500, + 503, 29, 504, 505, 29, 506, 497, 507, 508, 509, + 510, 513, 514, 515, 516, 519, 518, 523, 520, 524, + 521, 525, 526, 522, 527, 528, 529, 530, 531, 532, + 533, 534, 535, 536, 537, 538, 539, 540, 541, 542, + + 545, 546, 547, 548, 523, 549, 524, 550, 525, 526, + 551, 527, 528, 529, 530, 531, 532, 533, 534, 535, + 536, 537, 538, 539, 540, 541, 542, 545, 546, 547, + 548, 552, 549, 553, 550, 554, 555, 551, 556, 557, + 558, 559, 560, 561, 562, 563, 564, 565, 566, 567, + 568, 569, 572, 573, 574, 575, 576, 577, 552, 578, + 553, 579, 554, 555, 580, 556, 557, 558, 559, 560, + 561, 562, 563, 564, 565, 566, 567, 568, 569, 572, + 573, 574, 575, 576, 577, 581, 578, 582, 579, 583, + 584, 580, 585, 586, 587, 588, 589, 590, 591, 592, + + 593, 594, 595, 596, 597, 598, 599, 600, 601, 602, + 603, 604, 581, 605, 582, 606, 583, 584, 607, 585, + 586, 587, 588, 589, 590, 591, 592, 593, 594, 595, + 596, 597, 598, 599, 600, 601, 602, 603, 604, 608, + 605, 609, 606, 610, 611, 607, 612, 613, 614, 615, + 616, 617, 618, 619, 620, 621, 622, 625, 626, 627, + 628, 635, 636, 637, 638, 639, 608, 640, 609, 641, + 610, 611, 642, 612, 613, 614, 615, 616, 617, 618, + 619, 620, 621, 622, 625, 626, 627, 628, 635, 636, + 637, 638, 639, 643, 640, 644, 641, 645, 646, 642, + + 647, 648, 649, 650, 652, 653, 654, 655, 656, 657, + 658, 659, 660, 661, 662, 663, 666, 667, 668, 669, + 643, 670, 644, 671, 645, 646, 672, 647, 648, 649, + 650, 652, 653, 654, 655, 656, 657, 658, 659, 660, + 661, 662, 663, 666, 667, 668, 669, 673, 670, 674, + 671, 675, 676, 672, 677, 678, 679, 680, 681, 682, + 683, 684, 685, 686, 687, 688, 689, 690, 691, 692, + 693, 694, 695, 696, 673, 697, 674, 698, 675, 676, + 699, 677, 678, 679, 680, 681, 682, 683, 684, 685, + 686, 687, 688, 689, 690, 691, 692, 693, 694, 695, + + 696, 700, 697, 701, 698, 704, 705, 699, 706, 707, + 708, 709, 710, 711, 712, 713, 714, 715, 718, 719, + 720, 721, 722, 723, 724, 725, 726, 727, 700, 728, + 701, 729, 704, 705, 730, 706, 707, 708, 709, 710, + 711, 712, 713, 714, 715, 718, 719, 720, 721, 722, + 723, 724, 725, 726, 727, 731, 728, 732, 729, 733, + 736, 730, 737, 738, 739, 740, 741, 744, 745, 746, + 748, 749, 751, 752, 753, 754, 755, 756, 757, 758, + 759, 760, 731, 761, 732, 764, 733, 736, 766, 737, + 738, 739, 740, 741, 744, 745, 746, 748, 749, 751, + + 752, 753, 754, 755, 756, 757, 758, 759, 760, 768, + 761, 769, 764, 770, 771, 766, 772, 773, 778, 779, + 780, 781, 782, 783, 786, 787, 788, 789, 794, 795, + 796, 797, 798, 799, 800, 801, 768, 802, 769, 803, + 770, 771, 804, 772, 773, 778, 779, 780, 781, 782, + 783, 786, 787, 788, 789, 794, 795, 796, 797, 798, + 799, 800, 801, 805, 802, 808, 803, 809, 810, 804, + 810, 810, 810, 810, 810, 810, 810, 810, 810, 810, + 810, 810, 810, 810, 810, 810, 810, 810, 810, 810, + 805, 810, 808, 810, 809, 24, 810, 24, 49, 49, + + 49, 3, 810, 810, 810, 810, 810, 810, 810, 810, + 810, 810, 810, 810, 810, 810, 810, 810, 810, 810, + 810, 810, 810, 810, 810, 810, 810, 810, 810, 810, + 810, 810, 810, 810, 810, 810, 810, 810, 810, 810, + 810, 810, 810, 810, 810, 810, 810, 810, 810, 810, + 810, 810, 810, 810, 810, 810, 810, 810, 810, 810, + 810, 810, 810, 810, 810, 810, 810, 810, 810, 810, + 810, 810, 810 + } ; + +static yyconst flex_int16_t yy_chk[2274] = + { 0, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 10, 10, 10, 10, 10, 10, 10, 10, 11, + 11, 11, 11, 11, 11, 11, 11, 12, 12, 12, + 12, 12, 12, 12, 12, 13, 14, 14, 16, 15, + + 14, 16, 16, 17, 17, 13, 164, 17, 13, 164, + 816, 12, 15, 15, 12, 52, 15, 211, 815, 814, + 211, 812, 13, 14, 14, 16, 15, 14, 16, 16, + 17, 17, 13, 19, 17, 13, 18, 29, 12, 15, + 15, 12, 52, 15, 19, 21, 18, 19, 20, 18, + 19, 22, 20, 29, 22, 21, 29, 55, 21, 56, + 19, 31, 20, 18, 31, 20, 803, 802, 783, 782, + 781, 19, 21, 18, 19, 20, 18, 19, 22, 20, + 29, 22, 21, 29, 55, 21, 56, 780, 31, 20, + 771, 31, 20, 26, 26, 26, 26, 26, 26, 26, + + 770, 57, 26, 26, 26, 26, 26, 26, 26, 26, + 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, + 26, 26, 26, 26, 26, 26, 26, 26, 57, 26, + 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, + 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, + 26, 26, 26, 26, 26, 27, 27, 27, 27, 27, + 27, 27, 27, 28, 28, 28, 28, 28, 28, 28, + 28, 30, 30, 30, 30, 30, 30, 30, 30, 32, + 33, 35, 58, 761, 33, 34, 35, 36, 34, 37, + 60, 38, 63, 60, 32, 32, 33, 35, 32, 33, + + 35, 34, 37, 36, 34, 37, 36, 38, 37, 58, + 38, 33, 64, 35, 38, 34, 760, 60, 759, 63, + 60, 32, 32, 33, 35, 32, 33, 35, 34, 37, + 36, 34, 37, 36, 38, 37, 39, 38, 40, 64, + 758, 38, 40, 41, 751, 42, 39, 42, 43, 44, + 748, 65, 39, 43, 40, 39, 45, 40, 41, 41, + 745, 89, 41, 42, 43, 44, 42, 43, 44, 40, + 744, 45, 45, 39, 90, 45, 726, 59, 65, 39, + 43, 40, 39, 59, 40, 41, 41, 46, 89, 41, + 42, 43, 44, 42, 43, 44, 47, 48, 45, 45, + + 54, 90, 45, 46, 59, 53, 46, 46, 82, 91, + 59, 82, 47, 48, 54, 47, 48, 53, 92, 48, + 723, 719, 718, 705, 93, 94, 704, 54, 685, 684, + 46, 95, 53, 46, 46, 82, 91, 73, 82, 47, + 48, 54, 47, 48, 53, 92, 48, 51, 51, 51, + 51, 93, 94, 73, 51, 51, 73, 51, 95, 61, + 51, 61, 51, 61, 51, 51, 51, 51, 51, 62, + 96, 147, 150, 154, 51, 51, 51, 51, 62, 62, + 73, 51, 51, 73, 51, 62, 61, 51, 61, 51, + 61, 51, 51, 51, 51, 51, 62, 66, 66, 66, + + 66, 66, 66, 66, 66, 62, 62, 96, 147, 150, + 154, 669, 62, 67, 67, 67, 67, 67, 67, 67, + 67, 68, 68, 68, 68, 68, 68, 68, 68, 68, + 69, 69, 69, 69, 69, 69, 69, 69, 71, 71, + 71, 71, 71, 71, 71, 71, 72, 97, 74, 668, + 620, 98, 75, 76, 99, 100, 101, 77, 102, 619, + 103, 104, 72, 105, 74, 72, 72, 74, 75, 76, + 74, 75, 76, 77, 97, 606, 77, 77, 98, 173, + 78, 99, 100, 101, 585, 102, 78, 103, 104, 72, + 105, 74, 72, 72, 74, 75, 76, 74, 75, 76, + + 77, 79, 78, 77, 77, 78, 80, 79, 106, 107, + 584, 81, 84, 583, 108, 109, 173, 79, 110, 80, + 79, 83, 80, 81, 107, 80, 84, 81, 84, 78, + 81, 84, 78, 582, 79, 106, 107, 83, 111, 581, + 83, 108, 109, 83, 79, 110, 80, 79, 580, 80, + 81, 107, 80, 84, 81, 84, 85, 81, 84, 132, + 86, 85, 87, 122, 83, 111, 86, 83, 88, 133, + 83, 134, 85, 135, 88, 85, 86, 122, 87, 86, + 122, 87, 137, 138, 88, 87, 132, 88, 85, 122, + 122, 575, 574, 86, 516, 515, 133, 489, 134, 85, + + 135, 88, 85, 86, 122, 87, 86, 122, 87, 137, + 138, 88, 87, 488, 88, 112, 112, 112, 112, 112, + 112, 112, 112, 113, 113, 113, 113, 113, 113, 113, + 113, 113, 114, 114, 114, 114, 114, 114, 114, 114, + 115, 115, 115, 115, 115, 115, 115, 115, 116, 116, + 116, 116, 116, 116, 116, 116, 116, 117, 117, 117, + 117, 117, 117, 117, 117, 118, 119, 120, 190, 141, + 456, 121, 136, 455, 119, 118, 142, 121, 124, 123, + 136, 118, 119, 120, 118, 119, 120, 121, 123, 446, + 121, 445, 143, 200, 124, 123, 141, 124, 123, 136, + + 124, 119, 118, 142, 121, 190, 144, 136, 118, 119, + 120, 118, 119, 120, 121, 123, 125, 121, 126, 143, + 127, 124, 123, 395, 124, 123, 125, 124, 128, 129, + 200, 126, 125, 144, 126, 125, 127, 126, 131, 127, + 392, 357, 127, 145, 128, 129, 146, 128, 129, 130, + 129, 289, 288, 125, 131, 130, 148, 131, 126, 125, + 149, 126, 125, 127, 126, 130, 127, 139, 130, 127, + 145, 128, 129, 146, 128, 129, 139, 129, 139, 140, + 151, 131, 130, 148, 131, 152, 153, 149, 140, 156, + 140, 155, 130, 286, 139, 130, 285, 267, 266, 213, + + 212, 49, 25, 139, 24, 139, 140, 151, 23, 9, + 8, 174, 152, 153, 175, 140, 156, 140, 3, 155, + 157, 157, 157, 157, 157, 157, 157, 157, 155, 158, + 158, 158, 158, 158, 158, 158, 158, 159, 174, 160, + 176, 175, 177, 161, 162, 163, 155, 178, 179, 165, + 181, 182, 183, 159, 2, 160, 159, 159, 160, 161, + 162, 163, 161, 162, 163, 165, 0, 176, 165, 177, + 0, 205, 0, 163, 178, 179, 0, 181, 182, 183, + 159, 167, 160, 159, 159, 160, 161, 162, 163, 161, + 162, 163, 165, 166, 169, 165, 167, 167, 166, 168, + + 167, 168, 184, 170, 185, 0, 0, 186, 205, 166, + 169, 180, 166, 169, 171, 168, 172, 170, 168, 170, + 187, 180, 170, 167, 167, 166, 188, 167, 168, 184, + 171, 185, 172, 171, 186, 172, 166, 169, 189, 166, + 169, 191, 168, 192, 170, 168, 170, 187, 180, 170, + 193, 194, 195, 188, 196, 197, 198, 171, 199, 172, + 171, 201, 172, 202, 203, 189, 202, 203, 191, 204, + 192, 206, 207, 0, 0, 0, 210, 193, 194, 195, + 0, 196, 197, 198, 0, 199, 0, 0, 201, 0, + 202, 203, 210, 202, 203, 210, 204, 210, 206, 207, + + 208, 208, 208, 208, 208, 208, 208, 208, 209, 209, + 209, 209, 209, 209, 209, 209, 216, 214, 215, 210, + 0, 220, 210, 214, 210, 217, 218, 219, 221, 222, + 223, 225, 216, 214, 215, 216, 214, 215, 215, 224, + 226, 217, 218, 219, 217, 218, 219, 219, 220, 0, + 214, 227, 228, 230, 231, 221, 222, 223, 225, 216, + 214, 215, 216, 214, 215, 215, 232, 226, 217, 218, + 219, 217, 218, 219, 219, 233, 224, 234, 227, 228, + 230, 231, 235, 236, 237, 238, 239, 240, 241, 242, + 243, 244, 245, 232, 246, 247, 248, 249, 250, 251, + + 252, 253, 233, 254, 234, 255, 256, 257, 258, 235, + 236, 237, 238, 239, 240, 241, 242, 243, 244, 245, + 259, 260, 247, 248, 249, 250, 251, 252, 253, 261, + 254, 246, 255, 256, 257, 258, 262, 263, 263, 263, + 263, 263, 263, 263, 263, 263, 275, 259, 260, 276, + 0, 0, 0, 273, 274, 277, 261, 270, 271, 290, + 278, 0, 279, 262, 264, 264, 264, 264, 264, 264, + 264, 264, 265, 270, 271, 280, 270, 271, 265, 272, + 273, 274, 277, 275, 281, 282, 276, 278, 265, 279, + 283, 265, 284, 287, 291, 272, 290, 292, 272, 293, + + 270, 271, 280, 270, 271, 265, 294, 295, 296, 297, + 298, 281, 282, 299, 300, 265, 302, 283, 265, 284, + 287, 291, 272, 303, 304, 272, 293, 305, 301, 306, + 316, 307, 308, 294, 292, 296, 297, 298, 301, 309, + 299, 300, 310, 302, 295, 311, 312, 313, 314, 315, + 303, 0, 322, 323, 305, 324, 306, 301, 307, 308, + 0, 304, 319, 331, 0, 301, 309, 316, 325, 310, + 326, 327, 311, 312, 313, 314, 315, 319, 319, 322, + 323, 319, 324, 328, 301, 317, 317, 317, 317, 317, + 317, 317, 317, 317, 329, 325, 330, 326, 327, 332, + + 331, 333, 334, 335, 319, 319, 336, 337, 319, 338, + 328, 339, 340, 341, 342, 344, 345, 346, 347, 348, + 349, 329, 350, 330, 351, 352, 332, 353, 333, 334, + 335, 354, 355, 336, 337, 358, 338, 359, 339, 340, + 341, 342, 344, 345, 346, 347, 348, 349, 360, 350, + 363, 351, 352, 364, 353, 361, 361, 365, 354, 355, + 362, 362, 358, 366, 359, 367, 368, 0, 369, 371, + 372, 374, 375, 0, 0, 360, 0, 363, 0, 0, + 364, 0, 361, 361, 378, 379, 380, 362, 362, 381, + 366, 382, 367, 368, 365, 369, 371, 372, 374, 375, + + 376, 376, 376, 376, 376, 376, 376, 376, 376, 377, + 383, 378, 379, 380, 384, 385, 381, 386, 382, 387, + 388, 389, 390, 391, 393, 377, 394, 396, 377, 397, + 377, 398, 399, 400, 401, 402, 403, 383, 404, 405, + 406, 384, 385, 407, 386, 408, 387, 388, 389, 390, + 391, 393, 377, 394, 396, 377, 397, 377, 398, 399, + 400, 401, 402, 403, 409, 404, 405, 406, 410, 411, + 407, 413, 408, 414, 415, 416, 417, 418, 419, 420, + 421, 422, 423, 425, 424, 426, 427, 428, 429, 430, + 431, 409, 424, 426, 433, 410, 411, 434, 413, 435, + + 414, 415, 416, 417, 418, 419, 420, 421, 422, 423, + 425, 424, 426, 427, 428, 429, 430, 431, 432, 424, + 426, 433, 436, 437, 434, 438, 435, 439, 440, 441, + 442, 443, 444, 447, 432, 448, 449, 432, 450, 461, + 451, 452, 453, 454, 457, 458, 459, 460, 462, 436, + 437, 463, 438, 464, 439, 440, 465, 442, 443, 444, + 447, 432, 448, 449, 432, 450, 441, 451, 452, 453, + 454, 457, 458, 459, 460, 462, 461, 466, 463, 467, + 464, 468, 469, 465, 470, 471, 472, 473, 474, 475, + 476, 477, 478, 479, 480, 481, 482, 483, 486, 487, + + 490, 491, 492, 493, 466, 494, 467, 495, 468, 469, + 496, 470, 471, 472, 473, 474, 475, 476, 477, 478, + 479, 480, 481, 482, 483, 486, 487, 490, 491, 492, + 493, 497, 494, 498, 495, 499, 500, 496, 501, 502, + 503, 504, 505, 506, 507, 508, 509, 510, 511, 512, + 513, 514, 517, 518, 519, 520, 521, 522, 497, 523, + 498, 524, 499, 500, 525, 501, 502, 503, 504, 505, + 506, 507, 508, 509, 510, 511, 512, 513, 514, 517, + 518, 519, 520, 521, 522, 526, 523, 527, 524, 528, + 529, 525, 530, 533, 534, 535, 536, 537, 538, 539, + + 540, 543, 544, 545, 546, 547, 548, 549, 550, 551, + 552, 553, 526, 554, 527, 555, 528, 529, 556, 530, + 533, 534, 535, 536, 537, 538, 539, 540, 543, 544, + 545, 546, 547, 548, 549, 550, 551, 552, 553, 557, + 554, 558, 555, 559, 560, 556, 561, 562, 563, 564, + 565, 566, 567, 568, 569, 572, 573, 576, 577, 578, + 579, 588, 589, 591, 592, 594, 557, 595, 558, 596, + 559, 560, 597, 561, 562, 563, 564, 565, 566, 567, + 568, 569, 572, 573, 576, 577, 578, 579, 588, 589, + 591, 592, 594, 598, 595, 599, 596, 600, 601, 597, + + 602, 603, 604, 605, 607, 608, 609, 610, 611, 612, + 613, 614, 615, 616, 617, 618, 621, 622, 625, 626, + 598, 627, 599, 628, 600, 601, 631, 602, 603, 604, + 605, 607, 608, 609, 610, 611, 612, 613, 614, 615, + 616, 617, 618, 621, 622, 625, 626, 632, 627, 633, + 628, 634, 635, 631, 637, 639, 640, 641, 642, 643, + 644, 647, 648, 649, 650, 652, 653, 654, 655, 656, + 657, 658, 659, 660, 632, 661, 633, 662, 634, 635, + 663, 637, 639, 640, 641, 642, 643, 644, 647, 648, + 649, 650, 652, 653, 654, 655, 656, 657, 658, 659, + + 660, 666, 661, 667, 662, 670, 671, 663, 672, 673, + 674, 675, 678, 679, 680, 681, 682, 683, 686, 687, + 688, 689, 690, 691, 692, 693, 694, 695, 666, 696, + 667, 697, 670, 671, 698, 672, 673, 674, 675, 678, + 679, 680, 681, 682, 683, 686, 687, 688, 689, 690, + 691, 692, 693, 694, 695, 699, 696, 700, 697, 701, + 706, 698, 707, 708, 709, 710, 711, 720, 721, 722, + 724, 725, 727, 730, 731, 732, 733, 734, 735, 736, + 737, 738, 699, 739, 700, 746, 701, 706, 749, 707, + 708, 709, 710, 711, 720, 721, 722, 724, 725, 727, + + 730, 731, 732, 733, 734, 735, 736, 737, 738, 752, + 739, 753, 746, 754, 755, 749, 756, 757, 762, 763, + 764, 766, 768, 769, 772, 773, 778, 779, 784, 785, + 786, 787, 788, 789, 794, 795, 752, 796, 753, 797, + 754, 755, 800, 756, 757, 762, 763, 764, 766, 768, + 769, 772, 773, 778, 779, 784, 785, 786, 787, 788, + 789, 794, 795, 801, 796, 804, 797, 805, 0, 800, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 801, 0, 804, 0, 805, 811, 0, 811, 813, 813, + + 813, 810, 810, 810, 810, 810, 810, 810, 810, 810, + 810, 810, 810, 810, 810, 810, 810, 810, 810, 810, + 810, 810, 810, 810, 810, 810, 810, 810, 810, 810, + 810, 810, 810, 810, 810, 810, 810, 810, 810, 810, + 810, 810, 810, 810, 810, 810, 810, 810, 810, 810, + 810, 810, 810, 810, 810, 810, 810, 810, 810, 810, + 810, 810, 810, 810, 810, 810, 810, 810, 810, 810, + 810, 810, 810 + } ; + +static yyconst flex_int16_t yy_rule_linenum[96] = + { 0, + 76, 79, 81, 83, 87, 88, 90, 91, 92, 93, + 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, + 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, + 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, + 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, + 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, + 144, 145, 146, 147, 148, 150, 151, 153, 154, 155, + 156, 157, 158, 160, 161, 164, 169, 170, 171, 173, + 174, 175, 176, 177, 178, 179, 180, 181, 183, 189, + 195, 201, 207, 213, 219 + + } ; + +/* The intent behind this definition is that it'll catch + * any uses of REJECT which flex missed. + */ +#define REJECT reject_used_but_not_detected +#define yymore() yymore_used_but_not_detected +#define YY_MORE_ADJ 0 +#define YY_RESTORE_YY_MORE_OFFSET +#line 1 "libmemcached/options/scanner.l" +/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: + * + * Libmemcached Scanner and Parser + * + * Copyright (C) 2011 DataDifferental, http://datadifferential.com + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#line 37 "libmemcached/options/scanner.l" +#include +#include + +#define PARAM config_get_extra(yyscanner) + +#define get_lex_chars(buffer, result, max_size, context) \ +{ \ + if (context->pos >= context->length) \ + { \ + result= YY_NULL; \ + } \ + else \ + { \ + result= context->length - context->pos; \ + result > max_size ? result = max_size : 0; \ + memcpy(buffer, context->buf + context->pos, result); \ + context->pos += result; \ + } \ +} + + +#define YY_INPUT(buffer, result, max_size) get_lex_chars(buffer, result, max_size, PARAM) + +#line 1361 "libmemcached/options/scanner.cc" + +#define INITIAL 0 + +#ifndef YY_NO_UNISTD_H +/* Special case for "unistd.h", since it is non-ANSI. We include it way + * down here because we want the user's section 1 to have been scanned first. + * The user has a chance to override it with an option. + */ +/* %if-c-only */ +#include +/* %endif */ +/* %if-c++-only */ +/* %endif */ +#endif + +#ifndef YY_EXTRA_TYPE +#define YY_EXTRA_TYPE void * +#endif + +/* %if-c-only Reentrant structure and macros (non-C++). */ +/* %if-reentrant */ + +/* Holds the entire state of the reentrant scanner. */ +struct yyguts_t + { + + /* User-defined. Not touched by flex. */ + YY_EXTRA_TYPE yyextra_r; + + /* The rest are the same as the globals declared in the non-reentrant scanner. */ + FILE *yyin_r, *yyout_r; + size_t yy_buffer_stack_top; /**< index of top of stack. */ + size_t yy_buffer_stack_max; /**< capacity of stack. */ + YY_BUFFER_STATE * yy_buffer_stack; /**< Stack as an array. */ + char yy_hold_char; + int yy_n_chars; + int yyleng_r; + char *yy_c_buf_p; + int yy_init; + int yy_start; + int yy_did_buffer_switch_on_eof; + int yy_start_stack_ptr; + int yy_start_stack_depth; + int *yy_start_stack; + yy_state_type yy_last_accepting_state; + char* yy_last_accepting_cpos; + + int yylineno_r; + int yy_flex_debug_r; + + char *yytext_r; + int yy_more_flag; + int yy_more_len; + + YYSTYPE * yylval_r; + + }; /* end struct yyguts_t */ + +/* %if-c-only */ + +static int yy_init_globals (yyscan_t yyscanner ); + +/* %endif */ + +/* %if-reentrant */ + + /* This must go here because YYSTYPE and YYLTYPE are included + * from bison output in section 1.*/ + # define yylval yyg->yylval_r + +int config_lex_init (yyscan_t* scanner); + +int config_lex_init_extra (YY_EXTRA_TYPE user_defined,yyscan_t* scanner); + +/* %endif */ + +/* %endif End reentrant structures and macros. */ + +/* Accessor methods to globals. + These are made visible to non-reentrant scanners for convenience. */ + +int config_lex_destroy (yyscan_t yyscanner ); + +int config_get_debug (yyscan_t yyscanner ); + +void config_set_debug (int debug_flag ,yyscan_t yyscanner ); + +YY_EXTRA_TYPE config_get_extra (yyscan_t yyscanner ); + +void config_set_extra (YY_EXTRA_TYPE user_defined ,yyscan_t yyscanner ); + +FILE *config_get_in (yyscan_t yyscanner ); + +void config_set_in (FILE * in_str ,yyscan_t yyscanner ); + +FILE *config_get_out (yyscan_t yyscanner ); + +void config_set_out (FILE * out_str ,yyscan_t yyscanner ); + +int config_get_leng (yyscan_t yyscanner ); + +char *config_get_text (yyscan_t yyscanner ); + +int config_get_lineno (yyscan_t yyscanner ); + +void config_set_lineno (int line_number ,yyscan_t yyscanner ); + +int config_get_column (yyscan_t yyscanner ); + +void config_set_column (int column_no ,yyscan_t yyscanner ); + +/* %if-bison-bridge */ + +YYSTYPE * config_get_lval (yyscan_t yyscanner ); + +void config_set_lval (YYSTYPE * yylval_param ,yyscan_t yyscanner ); + +/* %endif */ + +/* Macros after this point can all be overridden by user definitions in + * section 1. + */ + +#ifndef YY_SKIP_YYWRAP +#ifdef __cplusplus +extern "C" int config_wrap (yyscan_t yyscanner ); +#else +extern int config_wrap (yyscan_t yyscanner ); +#endif +#endif + +/* %not-for-header */ + +/* %ok-for-header */ + +/* %endif */ + +#ifndef yytext_ptr +static void yy_flex_strncpy (char *,yyconst char *,int ,yyscan_t yyscanner); +#endif + +#ifdef YY_NEED_STRLEN +static int yy_flex_strlen (yyconst char * ,yyscan_t yyscanner); +#endif + +#ifndef YY_NO_INPUT +/* %if-c-only Standard (non-C++) definition */ +/* %not-for-header */ + +#ifdef __cplusplus +static int yyinput (yyscan_t yyscanner ); +#else +static int input (yyscan_t yyscanner ); +#endif +/* %ok-for-header */ + +/* %endif */ +#endif + +/* %if-c-only */ + +/* %endif */ + +/* Amount of stuff to slurp up with each read. */ +#ifndef YY_READ_BUF_SIZE +#define YY_READ_BUF_SIZE 8192 +#endif + +/* Copy whatever the last rule matched to the standard output. */ +#ifndef ECHO +/* %if-c-only Standard (non-C++) definition */ +/* This used to be an fputs(), but since the string might contain NUL's, + * we now use fwrite(). + */ +#define ECHO do { if (fwrite( yytext, yyleng, 1, yyout )) {} } while (0) +/* %endif */ +/* %if-c++-only C++ definition */ +/* %endif */ +#endif + +/* Gets input and stuffs it into "buf". number of characters read, or YY_NULL, + * is returned in "result". + */ +#ifndef YY_INPUT +#define YY_INPUT(buf,result,max_size) \ +/* %% [5.0] fread()/read() definition of YY_INPUT goes here unless we're doing C++ \ */\ + if ( YY_CURRENT_BUFFER_LVALUE->yy_is_interactive ) \ + { \ + int c = '*'; \ + unsigned n; \ + for ( n = 0; n < max_size && \ + (c = getc( yyin )) != EOF && c != '\n'; ++n ) \ + buf[n] = (char) c; \ + if ( c == '\n' ) \ + buf[n++] = (char) c; \ + if ( c == EOF && ferror( yyin ) ) \ + YY_FATAL_ERROR( "input in flex scanner failed" ); \ + result = n; \ + } \ + else \ + { \ + errno=0; \ + while ( (result = fread(buf, 1, max_size, yyin))==0 && ferror(yyin)) \ + { \ + if( errno != EINTR) \ + { \ + YY_FATAL_ERROR( "input in flex scanner failed" ); \ + break; \ + } \ + errno=0; \ + clearerr(yyin); \ + } \ + }\ +\ +/* %if-c++-only C++ definition \ */\ +/* %endif */ + +#endif + +/* No semi-colon after return; correct usage is to write "yyterminate();" - + * we don't want an extra ';' after the "return" because that will cause + * some compilers to complain about unreachable statements. + */ +#ifndef yyterminate +#define yyterminate() return YY_NULL +#endif + +/* Number of entries by which start-condition stack grows. */ +#ifndef YY_START_STACK_INCR +#define YY_START_STACK_INCR 25 +#endif + +/* Report a fatal error. */ +#ifndef YY_FATAL_ERROR +/* %if-c-only */ +#define YY_FATAL_ERROR(msg) yy_fatal_error( msg , yyscanner) +/* %endif */ +/* %if-c++-only */ +/* %endif */ +#endif + +/* %if-tables-serialization structures and prototypes */ +/* %not-for-header */ + +/* %ok-for-header */ + +/* %not-for-header */ + +/* %tables-yydmap generated elements */ +/* %endif */ +/* end tables serialization structures and prototypes */ + +/* %ok-for-header */ + +/* Default declaration of generated scanner - a define so the user can + * easily add parameters. + */ +#ifndef YY_DECL +#define YY_DECL_IS_OURS 1 +/* %if-c-only Standard (non-C++) definition */ + +extern int config_lex \ + (YYSTYPE * yylval_param ,yyscan_t yyscanner); + +#define YY_DECL int config_lex \ + (YYSTYPE * yylval_param , yyscan_t yyscanner) +/* %endif */ +/* %if-c++-only C++ definition */ +/* %endif */ +#endif /* !YY_DECL */ + +/* Code executed at the beginning of each rule, after yytext and yyleng + * have been set up. + */ +#ifndef YY_USER_ACTION +#define YY_USER_ACTION +#endif + +/* Code executed at the end of each rule. */ +#ifndef YY_BREAK +#define YY_BREAK break; +#endif + +/* %% [6.0] YY_RULE_SETUP definition goes here */ +#define YY_RULE_SETUP \ + if ( yyleng > 0 ) \ + YY_CURRENT_BUFFER_LVALUE->yy_at_bol = \ + (yytext[yyleng - 1] == '\n'); \ + YY_USER_ACTION + +/* %not-for-header */ + +/** The main scanner function which does all the work. + */ +YY_DECL +{ + register yy_state_type yy_current_state; + register char *yy_cp, *yy_bp; + register int yy_act; + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + +/* %% [7.0] user's declarations go here */ +#line 73 "libmemcached/options/scanner.l" + + + +#line 1668 "libmemcached/options/scanner.cc" + + yylval = yylval_param; + + if ( !yyg->yy_init ) + { + yyg->yy_init = 1; + +#ifdef YY_USER_INIT + YY_USER_INIT; +#endif + + if ( ! yyg->yy_start ) + yyg->yy_start = 1; /* first start state */ + + if ( ! yyin ) +/* %if-c-only */ + yyin = stdin; +/* %endif */ +/* %if-c++-only */ +/* %endif */ + + if ( ! yyout ) +/* %if-c-only */ + yyout = stdout; +/* %endif */ +/* %if-c++-only */ +/* %endif */ + + if ( ! YY_CURRENT_BUFFER ) { + config_ensure_buffer_stack (yyscanner); + YY_CURRENT_BUFFER_LVALUE = + config__create_buffer(yyin,YY_BUF_SIZE ,yyscanner); + } + + config__load_buffer_state(yyscanner ); + } + + while ( 1 ) /* loops until end-of-file is reached */ + { +/* %% [8.0] yymore()-related code goes here */ + yy_cp = yyg->yy_c_buf_p; + + /* Support of yytext. */ + *yy_cp = yyg->yy_hold_char; + + /* yy_bp points to the position in yy_ch_buf of the start of + * the current run. + */ + yy_bp = yy_cp; + +/* %% [9.0] code to set up and find next match goes here */ + yy_current_state = yyg->yy_start; + yy_current_state += YY_AT_BOL(); +yy_match: + do + { + register YY_CHAR yy_c = yy_ec[YY_SC_TO_UI(*yy_cp)]; + if ( yy_accept[yy_current_state] ) + { + yyg->yy_last_accepting_state = yy_current_state; + yyg->yy_last_accepting_cpos = yy_cp; + } + while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) + { + yy_current_state = (int) yy_def[yy_current_state]; + if ( yy_current_state >= 811 ) + yy_c = yy_meta[(unsigned int) yy_c]; + } + yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; + ++yy_cp; + } + while ( yy_base[yy_current_state] != 2202 ); + +yy_find_action: +/* %% [10.0] code to find the action number goes here */ + yy_act = yy_accept[yy_current_state]; + if ( yy_act == 0 ) + { /* have to back up */ + yy_cp = yyg->yy_last_accepting_cpos; + yy_current_state = yyg->yy_last_accepting_state; + yy_act = yy_accept[yy_current_state]; + } + + YY_DO_BEFORE_ACTION; + +/* %% [11.0] code for yylineno update goes here */ + +do_action: /* This label is used only to access EOF actions. */ + +/* %% [12.0] debug code goes here */ + if ( yy_flex_debug ) + { + if ( yy_act == 0 ) + fprintf( stderr, "--scanner backing up\n" ); + else if ( yy_act < 96 ) + fprintf( stderr, "--accepting rule at line %ld (\"%s\")\n", + (long)yy_rule_linenum[yy_act], yytext ); + else if ( yy_act == 96 ) + fprintf( stderr, "--accepting default rule (\"%s\")\n", + yytext ); + else if ( yy_act == 97 ) + fprintf( stderr, "--(end of buffer or a NUL)\n" ); + else + fprintf( stderr, "--EOF (start condition %d)\n", YY_START ); + } + + switch ( yy_act ) + { /* beginning of action switch */ +/* %% [13.0] actions go here */ + case 0: /* must back up */ + /* undo the effects of YY_DO_BEFORE_ACTION */ + *yy_cp = yyg->yy_hold_char; + yy_cp = yyg->yy_last_accepting_cpos; + yy_current_state = yyg->yy_last_accepting_state; + goto yy_find_action; + +case 1: +YY_RULE_SETUP +#line 76 "libmemcached/options/scanner.l" +{ return yytext[0];} + YY_BREAK +case 2: +YY_RULE_SETUP +#line 79 "libmemcached/options/scanner.l" +{ yylval->number = atoi(yytext); return (NUMBER); } + YY_BREAK +case 3: +/* rule 3 can match eol */ +YY_RULE_SETUP +#line 81 "libmemcached/options/scanner.l" +; /* skip whitespace */ + YY_BREAK +case 4: +*yy_cp = yyg->yy_hold_char; /* undo effects of setting up yytext */ +yyg->yy_c_buf_p = yy_cp -= 1; +YY_DO_BEFORE_ACTION; /* set up yytext again */ +YY_RULE_SETUP +#line 83 "libmemcached/options/scanner.l" +{ + return COMMENT; + } + YY_BREAK +case 5: +YY_RULE_SETUP +#line 87 "libmemcached/options/scanner.l" +{ yyextra->begin= yytext; return SERVER; } + YY_BREAK +case 6: +YY_RULE_SETUP +#line 88 "libmemcached/options/scanner.l" +{ yyextra->begin= yytext; return SERVERS_OPTION; } + YY_BREAK +case 7: +YY_RULE_SETUP +#line 90 "libmemcached/options/scanner.l" +{ yyextra->begin= yytext; return VERIFY_KEY; } + YY_BREAK +case 8: +YY_RULE_SETUP +#line 91 "libmemcached/options/scanner.l" +{ yyextra->begin= yytext; return VERIFY_KEY; } + YY_BREAK +case 9: +YY_RULE_SETUP +#line 92 "libmemcached/options/scanner.l" +{ yyextra->begin= yytext; return AUTO_EJECT_HOSTS; } + YY_BREAK +case 10: +YY_RULE_SETUP +#line 93 "libmemcached/options/scanner.l" +{ yyextra->begin= yytext; return AUTO_EJECT_HOSTS; } + YY_BREAK +case 11: +YY_RULE_SETUP +#line 94 "libmemcached/options/scanner.l" +{ yyextra->begin= yytext; return BINARY_PROTOCOL; } + YY_BREAK +case 12: +YY_RULE_SETUP +#line 95 "libmemcached/options/scanner.l" +{ yyextra->begin= yytext; return BINARY_PROTOCOL; } + YY_BREAK +case 13: +YY_RULE_SETUP +#line 96 "libmemcached/options/scanner.l" +{ yyextra->begin= yytext; return BUFFER_REQUESTS; } + YY_BREAK +case 14: +YY_RULE_SETUP +#line 97 "libmemcached/options/scanner.l" +{ yyextra->begin= yytext; return BUFFER_REQUESTS; } + YY_BREAK +case 15: +YY_RULE_SETUP +#line 98 "libmemcached/options/scanner.l" +{ yyextra->begin= yytext; return CACHE_LOOKUPS; } + YY_BREAK +case 16: +YY_RULE_SETUP +#line 99 "libmemcached/options/scanner.l" +{ yyextra->begin= yytext; return CACHE_LOOKUPS; } + YY_BREAK +case 17: +YY_RULE_SETUP +#line 100 "libmemcached/options/scanner.l" +{ yyextra->begin= yytext; return CONFIGURE_FILE; } + YY_BREAK +case 18: +YY_RULE_SETUP +#line 101 "libmemcached/options/scanner.l" +{ yyextra->begin= yytext; return CONFIGURE_FILE; } + YY_BREAK +case 19: +YY_RULE_SETUP +#line 102 "libmemcached/options/scanner.l" +{ yyextra->begin= yytext; return CONNECT_TIMEOUT; } + YY_BREAK +case 20: +YY_RULE_SETUP +#line 103 "libmemcached/options/scanner.l" +{ yyextra->begin= yytext; return CONNECT_TIMEOUT; } + YY_BREAK +case 21: +YY_RULE_SETUP +#line 104 "libmemcached/options/scanner.l" +{ yyextra->begin= yytext; return DISTRIBUTION; } + YY_BREAK +case 22: +YY_RULE_SETUP +#line 105 "libmemcached/options/scanner.l" +{ yyextra->begin= yytext; return HASH; } + YY_BREAK +case 23: +YY_RULE_SETUP +#line 106 "libmemcached/options/scanner.l" +{ yyextra->begin= yytext; return HASH_WITH_PREFIX_KEY; } + YY_BREAK +case 24: +YY_RULE_SETUP +#line 107 "libmemcached/options/scanner.l" +{ yyextra->begin= yytext; return HASH_WITH_PREFIX_KEY; } + YY_BREAK +case 25: +YY_RULE_SETUP +#line 108 "libmemcached/options/scanner.l" +{ yyextra->begin= yytext; return IO_BYTES_WATERMARK; } + YY_BREAK +case 26: +YY_RULE_SETUP +#line 109 "libmemcached/options/scanner.l" +{ yyextra->begin= yytext; return IO_BYTES_WATERMARK; } + YY_BREAK +case 27: +YY_RULE_SETUP +#line 110 "libmemcached/options/scanner.l" +{ yyextra->begin= yytext; return IO_KEY_PREFETCH; } + YY_BREAK +case 28: +YY_RULE_SETUP +#line 111 "libmemcached/options/scanner.l" +{ yyextra->begin= yytext; return IO_KEY_PREFETCH; } + YY_BREAK +case 29: +YY_RULE_SETUP +#line 112 "libmemcached/options/scanner.l" +{ yyextra->begin= yytext; return IO_MSG_WATERMARK; } + YY_BREAK +case 30: +YY_RULE_SETUP +#line 113 "libmemcached/options/scanner.l" +{ yyextra->begin= yytext; return IO_MSG_WATERMARK; } + YY_BREAK +case 31: +YY_RULE_SETUP +#line 114 "libmemcached/options/scanner.l" +{ yyextra->begin= yytext; return KETAMA_WEIGHTED; } + YY_BREAK +case 32: +YY_RULE_SETUP +#line 115 "libmemcached/options/scanner.l" +{ yyextra->begin= yytext; return KETAMA_WEIGHTED; } + YY_BREAK +case 33: +YY_RULE_SETUP +#line 116 "libmemcached/options/scanner.l" +{ yyextra->begin= yytext; return NOREPLY; } + YY_BREAK +case 34: +YY_RULE_SETUP +#line 117 "libmemcached/options/scanner.l" +{ yyextra->begin= yytext; return NUMBER_OF_REPLICAS; } + YY_BREAK +case 35: +YY_RULE_SETUP +#line 118 "libmemcached/options/scanner.l" +{ yyextra->begin= yytext; return NUMBER_OF_REPLICAS; } + YY_BREAK +case 36: +YY_RULE_SETUP +#line 119 "libmemcached/options/scanner.l" +{ yyextra->begin= yytext; return POLL_TIMEOUT; } + YY_BREAK +case 37: +YY_RULE_SETUP +#line 120 "libmemcached/options/scanner.l" +{ yyextra->begin= yytext; return POLL_TIMEOUT; } + YY_BREAK +case 38: +YY_RULE_SETUP +#line 121 "libmemcached/options/scanner.l" +{ yyextra->begin= yytext; return RANDOMIZE_REPLICA_READ; } + YY_BREAK +case 39: +YY_RULE_SETUP +#line 122 "libmemcached/options/scanner.l" +{ yyextra->begin= yytext; return RANDOMIZE_REPLICA_READ; } + YY_BREAK +case 40: +YY_RULE_SETUP +#line 123 "libmemcached/options/scanner.l" +{ yyextra->begin= yytext; return RCV_TIMEOUT; } + YY_BREAK +case 41: +YY_RULE_SETUP +#line 124 "libmemcached/options/scanner.l" +{ yyextra->begin= yytext; return RCV_TIMEOUT; } + YY_BREAK +case 42: +YY_RULE_SETUP +#line 125 "libmemcached/options/scanner.l" +{ yyextra->begin= yytext; return RETRY_TIMEOUT; } + YY_BREAK +case 43: +YY_RULE_SETUP +#line 126 "libmemcached/options/scanner.l" +{ yyextra->begin= yytext; return RETRY_TIMEOUT; } + YY_BREAK +case 44: +YY_RULE_SETUP +#line 127 "libmemcached/options/scanner.l" +{ yyextra->begin= yytext; return SERVER_FAILURE_LIMIT; } + YY_BREAK +case 45: +YY_RULE_SETUP +#line 128 "libmemcached/options/scanner.l" +{ yyextra->begin= yytext; return SERVER_FAILURE_LIMIT; } + YY_BREAK +case 46: +YY_RULE_SETUP +#line 129 "libmemcached/options/scanner.l" +{ yyextra->begin= yytext; return SND_TIMEOUT; } + YY_BREAK +case 47: +YY_RULE_SETUP +#line 130 "libmemcached/options/scanner.l" +{ yyextra->begin= yytext; return SND_TIMEOUT; } + YY_BREAK +case 48: +YY_RULE_SETUP +#line 131 "libmemcached/options/scanner.l" +{ yyextra->begin= yytext; return SOCKET_RECV_SIZE; } + YY_BREAK +case 49: +YY_RULE_SETUP +#line 132 "libmemcached/options/scanner.l" +{ yyextra->begin= yytext; return SOCKET_RECV_SIZE; } + YY_BREAK +case 50: +YY_RULE_SETUP +#line 133 "libmemcached/options/scanner.l" +{ yyextra->begin= yytext; return SOCKET_SEND_SIZE; } + YY_BREAK +case 51: +YY_RULE_SETUP +#line 134 "libmemcached/options/scanner.l" +{ yyextra->begin= yytext; return SOCKET_SEND_SIZE; } + YY_BREAK +case 52: +YY_RULE_SETUP +#line 135 "libmemcached/options/scanner.l" +{ yyextra->begin= yytext; return SORT_HOSTS; } + YY_BREAK +case 53: +YY_RULE_SETUP +#line 136 "libmemcached/options/scanner.l" +{ yyextra->begin= yytext; return SORT_HOSTS; } + YY_BREAK +case 54: +YY_RULE_SETUP +#line 137 "libmemcached/options/scanner.l" +{ yyextra->begin= yytext; return SUPPORT_CAS; } + YY_BREAK +case 55: +YY_RULE_SETUP +#line 138 "libmemcached/options/scanner.l" +{ yyextra->begin= yytext; return SUPPORT_CAS; } + YY_BREAK +case 56: +YY_RULE_SETUP +#line 139 "libmemcached/options/scanner.l" +{ yyextra->begin= yytext; return _TCP_NODELAY; } + YY_BREAK +case 57: +YY_RULE_SETUP +#line 140 "libmemcached/options/scanner.l" +{ yyextra->begin= yytext; return _TCP_NODELAY; } + YY_BREAK +case 58: +YY_RULE_SETUP +#line 141 "libmemcached/options/scanner.l" +{ yyextra->begin= yytext; return _TCP_KEEPALIVE; } + YY_BREAK +case 59: +YY_RULE_SETUP +#line 142 "libmemcached/options/scanner.l" +{ yyextra->begin= yytext; return _TCP_KEEPALIVE; } + YY_BREAK +case 60: +YY_RULE_SETUP +#line 143 "libmemcached/options/scanner.l" +{ yyextra->begin= yytext; return _TCP_KEEPIDLE; } + YY_BREAK +case 61: +YY_RULE_SETUP +#line 144 "libmemcached/options/scanner.l" +{ yyextra->begin= yytext; return _TCP_KEEPIDLE; } + YY_BREAK +case 62: +YY_RULE_SETUP +#line 145 "libmemcached/options/scanner.l" +{ yyextra->begin= yytext; return USER_DATA; } + YY_BREAK +case 63: +YY_RULE_SETUP +#line 146 "libmemcached/options/scanner.l" +{ yyextra->begin= yytext; return USER_DATA; } + YY_BREAK +case 64: +YY_RULE_SETUP +#line 147 "libmemcached/options/scanner.l" +{ yyextra->begin= yytext; return USE_UDP; } + YY_BREAK +case 65: +YY_RULE_SETUP +#line 148 "libmemcached/options/scanner.l" +{ yyextra->begin= yytext; return USE_UDP; } + YY_BREAK +case 66: +YY_RULE_SETUP +#line 150 "libmemcached/options/scanner.l" +{ yyextra->begin= yytext; return PREFIX_KEY; } + YY_BREAK +case 67: +YY_RULE_SETUP +#line 151 "libmemcached/options/scanner.l" +{ yyextra->begin= yytext; return PREFIX_KEY; } + YY_BREAK +case 68: +YY_RULE_SETUP +#line 153 "libmemcached/options/scanner.l" +{ yyextra->begin= yytext; return INCLUDE; } + YY_BREAK +case 69: +YY_RULE_SETUP +#line 154 "libmemcached/options/scanner.l" +{ yyextra->begin= yytext; return RESET; } + YY_BREAK +case 70: +YY_RULE_SETUP +#line 155 "libmemcached/options/scanner.l" +{ yyextra->begin= yytext; return PARSER_DEBUG; } + YY_BREAK +case 71: +YY_RULE_SETUP +#line 156 "libmemcached/options/scanner.l" +{ yyextra->begin= yytext; return SERVERS; } + YY_BREAK +case 72: +YY_RULE_SETUP +#line 157 "libmemcached/options/scanner.l" +{ yyextra->begin= yytext; return END; } + YY_BREAK +case 73: +YY_RULE_SETUP +#line 158 "libmemcached/options/scanner.l" +{ yyextra->begin= yytext; return ERROR; } + YY_BREAK +case 74: +YY_RULE_SETUP +#line 160 "libmemcached/options/scanner.l" +{ return TRUE; } + YY_BREAK +case 75: +YY_RULE_SETUP +#line 161 "libmemcached/options/scanner.l" +{ return FALSE; } + YY_BREAK +case 76: +YY_RULE_SETUP +#line 164 "libmemcached/options/scanner.l" +{ + yyextra->begin= yytext; + return UNKNOWN_OPTION; + } + YY_BREAK +case 77: +YY_RULE_SETUP +#line 169 "libmemcached/options/scanner.l" +{ return CONSISTENT; } + YY_BREAK +case 78: +YY_RULE_SETUP +#line 170 "libmemcached/options/scanner.l" +{ return MODULA; } + YY_BREAK +case 79: +YY_RULE_SETUP +#line 171 "libmemcached/options/scanner.l" +{ return RANDOM; } + YY_BREAK +case 80: +YY_RULE_SETUP +#line 173 "libmemcached/options/scanner.l" +{ return MD5; } + YY_BREAK +case 81: +YY_RULE_SETUP +#line 174 "libmemcached/options/scanner.l" +{ return CRC; } + YY_BREAK +case 82: +YY_RULE_SETUP +#line 175 "libmemcached/options/scanner.l" +{ return FNV1_64; } + YY_BREAK +case 83: +YY_RULE_SETUP +#line 176 "libmemcached/options/scanner.l" +{ return FNV1A_64; } + YY_BREAK +case 84: +YY_RULE_SETUP +#line 177 "libmemcached/options/scanner.l" +{ return FNV1_32; } + YY_BREAK +case 85: +YY_RULE_SETUP +#line 178 "libmemcached/options/scanner.l" +{ return FNV1A_32; } + YY_BREAK +case 86: +YY_RULE_SETUP +#line 179 "libmemcached/options/scanner.l" +{ return HSIEH; } + YY_BREAK +case 87: +YY_RULE_SETUP +#line 180 "libmemcached/options/scanner.l" +{ return MURMUR; } + YY_BREAK +case 88: +YY_RULE_SETUP +#line 181 "libmemcached/options/scanner.l" +{ return JENKINS; } + YY_BREAK +case 89: +YY_RULE_SETUP +#line 183 "libmemcached/options/scanner.l" +{ + yylval->string.c_str = yytext; + yylval->string.length = yyleng; + return HOSTNAME_WITH_PORT; + } + YY_BREAK +case 90: +YY_RULE_SETUP +#line 189 "libmemcached/options/scanner.l" +{ + yylval->string.c_str = yytext; + yylval->string.length = yyleng; + return HOSTNAME; + } + YY_BREAK +case 91: +YY_RULE_SETUP +#line 195 "libmemcached/options/scanner.l" +{ + yylval->string.c_str = yytext; + yylval->string.length = yyleng; + return IPADDRESS_WITH_PORT; + } + YY_BREAK +case 92: +YY_RULE_SETUP +#line 201 "libmemcached/options/scanner.l" +{ + yylval->string.c_str = yytext; + yylval->string.length = yyleng; + return IPADDRESS; + } + YY_BREAK +case 93: +YY_RULE_SETUP +#line 207 "libmemcached/options/scanner.l" +{ + yylval->string.c_str = yytext; + yylval->string.length = yyleng; + return STRING; + } + YY_BREAK +case 94: +YY_RULE_SETUP +#line 213 "libmemcached/options/scanner.l" +{ + yylval->string.c_str = yytext; + yylval->string.length = yyleng; + return QUOTED_STRING; + } + YY_BREAK +case 95: +YY_RULE_SETUP +#line 219 "libmemcached/options/scanner.l" +{ + yyextra->begin= yytext; + return UNKNOWN; + } + YY_BREAK +case 96: +YY_RULE_SETUP +#line 224 "libmemcached/options/scanner.l" +ECHO; + YY_BREAK +#line 2301 "libmemcached/options/scanner.cc" +case YY_STATE_EOF(INITIAL): + yyterminate(); + + case YY_END_OF_BUFFER: + { + /* Amount of text matched not including the EOB char. */ + int yy_amount_of_matched_text = (int) (yy_cp - yyg->yytext_ptr) - 1; + + /* Undo the effects of YY_DO_BEFORE_ACTION. */ + *yy_cp = yyg->yy_hold_char; + YY_RESTORE_YY_MORE_OFFSET + + if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_NEW ) + { + /* We're scanning a new file or input source. It's + * possible that this happened because the user + * just pointed yyin at a new source and called + * config_lex(). If so, then we have to assure + * consistency between YY_CURRENT_BUFFER and our + * globals. Here is the right place to do so, because + * this is the first action (other than possibly a + * back-up) that will match for the new input source. + */ + yyg->yy_n_chars = YY_CURRENT_BUFFER_LVALUE->yy_n_chars; + YY_CURRENT_BUFFER_LVALUE->yy_input_file = yyin; + YY_CURRENT_BUFFER_LVALUE->yy_buffer_status = YY_BUFFER_NORMAL; + } + + /* Note that here we test for yy_c_buf_p "<=" to the position + * of the first EOB in the buffer, since yy_c_buf_p will + * already have been incremented past the NUL character + * (since all states make transitions on EOB to the + * end-of-buffer state). Contrast this with the test + * in input(). + */ + if ( yyg->yy_c_buf_p <= &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars] ) + { /* This was really a NUL. */ + yy_state_type yy_next_state; + + yyg->yy_c_buf_p = yyg->yytext_ptr + yy_amount_of_matched_text; + + yy_current_state = yy_get_previous_state( yyscanner ); + + /* Okay, we're now positioned to make the NUL + * transition. We couldn't have + * yy_get_previous_state() go ahead and do it + * for us because it doesn't know how to deal + * with the possibility of jamming (and we don't + * want to build jamming into it because then it + * will run more slowly). + */ + + yy_next_state = yy_try_NUL_trans( yy_current_state , yyscanner); + + yy_bp = yyg->yytext_ptr + YY_MORE_ADJ; + + if ( yy_next_state ) + { + /* Consume the NUL. */ + yy_cp = ++yyg->yy_c_buf_p; + yy_current_state = yy_next_state; + goto yy_match; + } + + else + { +/* %% [14.0] code to do back-up for compressed tables and set up yy_cp goes here */ + yy_cp = yyg->yy_c_buf_p; + goto yy_find_action; + } + } + + else switch ( yy_get_next_buffer( yyscanner ) ) + { + case EOB_ACT_END_OF_FILE: + { + yyg->yy_did_buffer_switch_on_eof = 0; + + if ( config_wrap(yyscanner ) ) + { + /* Note: because we've taken care in + * yy_get_next_buffer() to have set up + * yytext, we can now set up + * yy_c_buf_p so that if some total + * hoser (like flex itself) wants to + * call the scanner after we return the + * YY_NULL, it'll still work - another + * YY_NULL will get returned. + */ + yyg->yy_c_buf_p = yyg->yytext_ptr + YY_MORE_ADJ; + + yy_act = YY_STATE_EOF(YY_START); + goto do_action; + } + + else + { + if ( ! yyg->yy_did_buffer_switch_on_eof ) + YY_NEW_FILE; + } + break; + } + + case EOB_ACT_CONTINUE_SCAN: + yyg->yy_c_buf_p = + yyg->yytext_ptr + yy_amount_of_matched_text; + + yy_current_state = yy_get_previous_state( yyscanner ); + + yy_cp = yyg->yy_c_buf_p; + yy_bp = yyg->yytext_ptr + YY_MORE_ADJ; + goto yy_match; + + case EOB_ACT_LAST_MATCH: + yyg->yy_c_buf_p = + &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars]; + + yy_current_state = yy_get_previous_state( yyscanner ); + + yy_cp = yyg->yy_c_buf_p; + yy_bp = yyg->yytext_ptr + YY_MORE_ADJ; + goto yy_find_action; + } + break; + } + + default: + YY_FATAL_ERROR( + "fatal flex scanner internal error--no action found" ); + } /* end of action switch */ + } /* end of scanning one token */ +} /* end of config_lex */ +/* %ok-for-header */ + +/* %if-c++-only */ +/* %not-for-header */ + +/* %ok-for-header */ + +/* %endif */ + +/* yy_get_next_buffer - try to read in a new buffer + * + * Returns a code representing an action: + * EOB_ACT_LAST_MATCH - + * EOB_ACT_CONTINUE_SCAN - continue scanning from current position + * EOB_ACT_END_OF_FILE - end of file + */ +/* %if-c-only */ +static int yy_get_next_buffer (yyscan_t yyscanner) +/* %endif */ +/* %if-c++-only */ +/* %endif */ +{ + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + register char *dest = YY_CURRENT_BUFFER_LVALUE->yy_ch_buf; + register char *source = yyg->yytext_ptr; + register int number_to_move, i; + int ret_val; + + if ( yyg->yy_c_buf_p > &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars + 1] ) + YY_FATAL_ERROR( + "fatal flex scanner internal error--end of buffer missed" ); + + if ( YY_CURRENT_BUFFER_LVALUE->yy_fill_buffer == 0 ) + { /* Don't try to fill the buffer, so this is an EOF. */ + if ( yyg->yy_c_buf_p - yyg->yytext_ptr - YY_MORE_ADJ == 1 ) + { + /* We matched a single character, the EOB, so + * treat this as a final EOF. + */ + return EOB_ACT_END_OF_FILE; + } + + else + { + /* We matched some text prior to the EOB, first + * process it. + */ + return EOB_ACT_LAST_MATCH; + } + } + + /* Try to read more data. */ + + /* First move last chars to start of buffer. */ + number_to_move = (int) (yyg->yy_c_buf_p - yyg->yytext_ptr) - 1; + + for ( i = 0; i < number_to_move; ++i ) + *(dest++) = *(source++); + + if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_EOF_PENDING ) + /* don't do the read, it's not guaranteed to return an EOF, + * just force an EOF + */ + YY_CURRENT_BUFFER_LVALUE->yy_n_chars = yyg->yy_n_chars = 0; + + else + { + int num_to_read = + YY_CURRENT_BUFFER_LVALUE->yy_buf_size - number_to_move - 1; + + while ( num_to_read <= 0 ) + { /* Not enough room in the buffer - grow it. */ + + /* just a shorter name for the current buffer */ + YY_BUFFER_STATE b = YY_CURRENT_BUFFER; + + int yy_c_buf_p_offset = + (int) (yyg->yy_c_buf_p - b->yy_ch_buf); + + if ( b->yy_is_our_buffer ) + { + int new_size = b->yy_buf_size * 2; + + if ( new_size <= 0 ) + b->yy_buf_size += b->yy_buf_size / 8; + else + b->yy_buf_size *= 2; + + b->yy_ch_buf = (char *) + /* Include room in for 2 EOB chars. */ + config_realloc((void *) b->yy_ch_buf,b->yy_buf_size + 2 ,yyscanner ); + } + else + /* Can't grow it, we don't own it. */ + b->yy_ch_buf = 0; + + if ( ! b->yy_ch_buf ) + YY_FATAL_ERROR( + "fatal error - scanner input buffer overflow" ); + + yyg->yy_c_buf_p = &b->yy_ch_buf[yy_c_buf_p_offset]; + + num_to_read = YY_CURRENT_BUFFER_LVALUE->yy_buf_size - + number_to_move - 1; + + } + + if ( num_to_read > YY_READ_BUF_SIZE ) + num_to_read = YY_READ_BUF_SIZE; + + /* Read in more data. */ + YY_INPUT( (&YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move]), + yyg->yy_n_chars, (size_t) num_to_read ); + + YY_CURRENT_BUFFER_LVALUE->yy_n_chars = yyg->yy_n_chars; + } + + if ( yyg->yy_n_chars == 0 ) + { + if ( number_to_move == YY_MORE_ADJ ) + { + ret_val = EOB_ACT_END_OF_FILE; + config_restart(yyin ,yyscanner); + } + + else + { + ret_val = EOB_ACT_LAST_MATCH; + YY_CURRENT_BUFFER_LVALUE->yy_buffer_status = + YY_BUFFER_EOF_PENDING; + } + } + + else + ret_val = EOB_ACT_CONTINUE_SCAN; + + if ((yy_size_t) (yyg->yy_n_chars + number_to_move) > YY_CURRENT_BUFFER_LVALUE->yy_buf_size) { + /* Extend the array by 50%, plus the number we really need. */ + yy_size_t new_size = yyg->yy_n_chars + number_to_move + (yyg->yy_n_chars >> 1); + YY_CURRENT_BUFFER_LVALUE->yy_ch_buf = (char *) config_realloc((void *) YY_CURRENT_BUFFER_LVALUE->yy_ch_buf,new_size ,yyscanner ); + if ( ! YY_CURRENT_BUFFER_LVALUE->yy_ch_buf ) + YY_FATAL_ERROR( "out of dynamic memory in yy_get_next_buffer()" ); + } + + yyg->yy_n_chars += number_to_move; + YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars] = YY_END_OF_BUFFER_CHAR; + YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars + 1] = YY_END_OF_BUFFER_CHAR; + + yyg->yytext_ptr = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[0]; + + return ret_val; +} + +/* yy_get_previous_state - get the state just before the EOB char was reached */ + +/* %if-c-only */ +/* %not-for-header */ + + static yy_state_type yy_get_previous_state (yyscan_t yyscanner) +/* %endif */ +/* %if-c++-only */ +/* %endif */ +{ + register yy_state_type yy_current_state; + register char *yy_cp; + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + +/* %% [15.0] code to get the start state into yy_current_state goes here */ + yy_current_state = yyg->yy_start; + yy_current_state += YY_AT_BOL(); + + for ( yy_cp = yyg->yytext_ptr + YY_MORE_ADJ; yy_cp < yyg->yy_c_buf_p; ++yy_cp ) + { +/* %% [16.0] code to find the next state goes here */ + register YY_CHAR yy_c = (*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : 1); + if ( yy_accept[yy_current_state] ) + { + yyg->yy_last_accepting_state = yy_current_state; + yyg->yy_last_accepting_cpos = yy_cp; + } + while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) + { + yy_current_state = (int) yy_def[yy_current_state]; + if ( yy_current_state >= 811 ) + yy_c = yy_meta[(unsigned int) yy_c]; + } + yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; + } + + return yy_current_state; +} + +/* yy_try_NUL_trans - try to make a transition on the NUL character + * + * synopsis + * next_state = yy_try_NUL_trans( current_state ); + */ +/* %if-c-only */ + static yy_state_type yy_try_NUL_trans (yy_state_type yy_current_state , yyscan_t yyscanner) +/* %endif */ +/* %if-c++-only */ +/* %endif */ +{ + register int yy_is_jam; + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; /* This var may be unused depending upon options. */ +/* %% [17.0] code to find the next state, and perhaps do backing up, goes here */ + register char *yy_cp = yyg->yy_c_buf_p; + + register YY_CHAR yy_c = 1; + if ( yy_accept[yy_current_state] ) + { + yyg->yy_last_accepting_state = yy_current_state; + yyg->yy_last_accepting_cpos = yy_cp; + } + while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) + { + yy_current_state = (int) yy_def[yy_current_state]; + if ( yy_current_state >= 811 ) + yy_c = yy_meta[(unsigned int) yy_c]; + } + yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; + yy_is_jam = (yy_current_state == 810); + + return yy_is_jam ? 0 : yy_current_state; +} + +/* %if-c-only */ + +/* %endif */ + +/* %if-c-only */ +#ifndef YY_NO_INPUT +#ifdef __cplusplus + static int yyinput (yyscan_t yyscanner) +#else + static int input (yyscan_t yyscanner) +#endif + +/* %endif */ +/* %if-c++-only */ +/* %endif */ +{ + int c; + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + + *yyg->yy_c_buf_p = yyg->yy_hold_char; + + if ( *yyg->yy_c_buf_p == YY_END_OF_BUFFER_CHAR ) + { + /* yy_c_buf_p now points to the character we want to return. + * If this occurs *before* the EOB characters, then it's a + * valid NUL; if not, then we've hit the end of the buffer. + */ + if ( yyg->yy_c_buf_p < &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars] ) + /* This was really a NUL. */ + *yyg->yy_c_buf_p = '\0'; + + else + { /* need more input */ + int offset = yyg->yy_c_buf_p - yyg->yytext_ptr; + ++yyg->yy_c_buf_p; + + switch ( yy_get_next_buffer( yyscanner ) ) + { + case EOB_ACT_LAST_MATCH: + /* This happens because yy_g_n_b() + * sees that we've accumulated a + * token and flags that we need to + * try matching the token before + * proceeding. But for input(), + * there's no matching to consider. + * So convert the EOB_ACT_LAST_MATCH + * to EOB_ACT_END_OF_FILE. + */ + + /* Reset buffer status. */ + config_restart(yyin ,yyscanner); + + /*FALLTHROUGH*/ + + case EOB_ACT_END_OF_FILE: + { + if ( config_wrap(yyscanner ) ) + return EOF; + + if ( ! yyg->yy_did_buffer_switch_on_eof ) + YY_NEW_FILE; +#ifdef __cplusplus + return yyinput(yyscanner); +#else + return input(yyscanner); +#endif + } + + case EOB_ACT_CONTINUE_SCAN: + yyg->yy_c_buf_p = yyg->yytext_ptr + offset; + break; + } + } + } + + c = *(unsigned char *) yyg->yy_c_buf_p; /* cast for 8-bit char's */ + *yyg->yy_c_buf_p = '\0'; /* preserve yytext */ + yyg->yy_hold_char = *++yyg->yy_c_buf_p; + +/* %% [19.0] update BOL and yylineno */ + YY_CURRENT_BUFFER_LVALUE->yy_at_bol = (c == '\n'); + + return c; +} +/* %if-c-only */ +#endif /* ifndef YY_NO_INPUT */ +/* %endif */ + +/** Immediately switch to a different input stream. + * @param input_file A readable stream. + * @param yyscanner The scanner object. + * @note This function does not reset the start condition to @c INITIAL . + */ +/* %if-c-only */ + void config_restart (FILE * input_file , yyscan_t yyscanner) +/* %endif */ +/* %if-c++-only */ +/* %endif */ +{ + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + + if ( ! YY_CURRENT_BUFFER ){ + config_ensure_buffer_stack (yyscanner); + YY_CURRENT_BUFFER_LVALUE = + config__create_buffer(yyin,YY_BUF_SIZE ,yyscanner); + } + + config__init_buffer(YY_CURRENT_BUFFER,input_file ,yyscanner); + config__load_buffer_state(yyscanner ); +} + +/** Switch to a different input buffer. + * @param new_buffer The new input buffer. + * @param yyscanner The scanner object. + */ +/* %if-c-only */ + void config__switch_to_buffer (YY_BUFFER_STATE new_buffer , yyscan_t yyscanner) +/* %endif */ +/* %if-c++-only */ +/* %endif */ +{ + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + + /* TODO. We should be able to replace this entire function body + * with + * config_pop_buffer_state(); + * config_push_buffer_state(new_buffer); + */ + config_ensure_buffer_stack (yyscanner); + if ( YY_CURRENT_BUFFER == new_buffer ) + return; + + if ( YY_CURRENT_BUFFER ) + { + /* Flush out information for old buffer. */ + *yyg->yy_c_buf_p = yyg->yy_hold_char; + YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = yyg->yy_c_buf_p; + YY_CURRENT_BUFFER_LVALUE->yy_n_chars = yyg->yy_n_chars; + } + + YY_CURRENT_BUFFER_LVALUE = new_buffer; + config__load_buffer_state(yyscanner ); + + /* We don't actually know whether we did this switch during + * EOF (config_wrap()) processing, but the only time this flag + * is looked at is after config_wrap() is called, so it's safe + * to go ahead and always set it. + */ + yyg->yy_did_buffer_switch_on_eof = 1; +} + +/* %if-c-only */ +static void config__load_buffer_state (yyscan_t yyscanner) +/* %endif */ +/* %if-c++-only */ +/* %endif */ +{ + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + yyg->yy_n_chars = YY_CURRENT_BUFFER_LVALUE->yy_n_chars; + yyg->yytext_ptr = yyg->yy_c_buf_p = YY_CURRENT_BUFFER_LVALUE->yy_buf_pos; + yyin = YY_CURRENT_BUFFER_LVALUE->yy_input_file; + yyg->yy_hold_char = *yyg->yy_c_buf_p; +} + +/** Allocate and initialize an input buffer state. + * @param file A readable stream. + * @param size The character buffer size in bytes. When in doubt, use @c YY_BUF_SIZE. + * @param yyscanner The scanner object. + * @return the allocated buffer state. + */ +/* %if-c-only */ + YY_BUFFER_STATE config__create_buffer (FILE * file, int size , yyscan_t yyscanner) +/* %endif */ +/* %if-c++-only */ +/* %endif */ +{ + YY_BUFFER_STATE b; + + b = (YY_BUFFER_STATE) config_alloc(sizeof( struct yy_buffer_state ) ,yyscanner ); + if ( ! b ) + YY_FATAL_ERROR( "out of dynamic memory in config__create_buffer()" ); + + b->yy_buf_size = size; + + /* yy_ch_buf has to be 2 characters longer than the size given because + * we need to put in 2 end-of-buffer characters. + */ + b->yy_ch_buf = (char *) config_alloc(b->yy_buf_size + 2 ,yyscanner ); + if ( ! b->yy_ch_buf ) + YY_FATAL_ERROR( "out of dynamic memory in config__create_buffer()" ); + + b->yy_is_our_buffer = 1; + + config__init_buffer(b,file ,yyscanner); + + return b; +} + +/** Destroy the buffer. + * @param b a buffer created with config__create_buffer() + * @param yyscanner The scanner object. + */ +/* %if-c-only */ + void config__delete_buffer (YY_BUFFER_STATE b , yyscan_t yyscanner) +/* %endif */ +/* %if-c++-only */ +/* %endif */ +{ + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + + if ( ! b ) + return; + + if ( b == YY_CURRENT_BUFFER ) /* Not sure if we should pop here. */ + YY_CURRENT_BUFFER_LVALUE = (YY_BUFFER_STATE) 0; + + if ( b->yy_is_our_buffer ) + config_free((void *) b->yy_ch_buf ,yyscanner ); + + config_free((void *) b ,yyscanner ); +} + +/* %if-c-only */ + +#ifndef __cplusplus +extern int isatty (int ); +#endif /* __cplusplus */ + +/* %endif */ + +/* %if-c++-only */ +/* %endif */ + +/* Initializes or reinitializes a buffer. + * This function is sometimes called more than once on the same buffer, + * such as during a config_restart() or at EOF. + */ +/* %if-c-only */ + static void config__init_buffer (YY_BUFFER_STATE b, FILE * file , yyscan_t yyscanner) +/* %endif */ +/* %if-c++-only */ +/* %endif */ + +{ + int oerrno = errno; + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + + config__flush_buffer(b ,yyscanner); + + b->yy_input_file = file; + b->yy_fill_buffer = 1; + + /* If b is the current buffer, then config__init_buffer was _probably_ + * called from config_restart() or through yy_get_next_buffer. + * In that case, we don't want to reset the lineno or column. + */ + if (b != YY_CURRENT_BUFFER){ + b->yy_bs_lineno = 1; + b->yy_bs_column = 0; + } + +/* %if-c-only */ + + b->yy_is_interactive = file ? (isatty( fileno(file) ) > 0) : 0; + +/* %endif */ +/* %if-c++-only */ +/* %endif */ + errno = oerrno; +} + +/** Discard all buffered characters. On the next scan, YY_INPUT will be called. + * @param b the buffer state to be flushed, usually @c YY_CURRENT_BUFFER. + * @param yyscanner The scanner object. + */ +/* %if-c-only */ + void config__flush_buffer (YY_BUFFER_STATE b , yyscan_t yyscanner) +/* %endif */ +/* %if-c++-only */ +/* %endif */ +{ + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + if ( ! b ) + return; + + b->yy_n_chars = 0; + + /* We always need two end-of-buffer characters. The first causes + * a transition to the end-of-buffer state. The second causes + * a jam in that state. + */ + b->yy_ch_buf[0] = YY_END_OF_BUFFER_CHAR; + b->yy_ch_buf[1] = YY_END_OF_BUFFER_CHAR; + + b->yy_buf_pos = &b->yy_ch_buf[0]; + + b->yy_at_bol = 1; + b->yy_buffer_status = YY_BUFFER_NEW; + + if ( b == YY_CURRENT_BUFFER ) + config__load_buffer_state(yyscanner ); +} + +/* %if-c-or-c++ */ +/** Pushes the new state onto the stack. The new state becomes + * the current state. This function will allocate the stack + * if necessary. + * @param new_buffer The new state. + * @param yyscanner The scanner object. + */ +/* %if-c-only */ +void config_push_buffer_state (YY_BUFFER_STATE new_buffer , yyscan_t yyscanner) +/* %endif */ +/* %if-c++-only */ +/* %endif */ +{ + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + if (new_buffer == NULL) + return; + + config_ensure_buffer_stack(yyscanner); + + /* This block is copied from config__switch_to_buffer. */ + if ( YY_CURRENT_BUFFER ) + { + /* Flush out information for old buffer. */ + *yyg->yy_c_buf_p = yyg->yy_hold_char; + YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = yyg->yy_c_buf_p; + YY_CURRENT_BUFFER_LVALUE->yy_n_chars = yyg->yy_n_chars; + } + + /* Only push if top exists. Otherwise, replace top. */ + if (YY_CURRENT_BUFFER) + yyg->yy_buffer_stack_top++; + YY_CURRENT_BUFFER_LVALUE = new_buffer; + + /* copied from config__switch_to_buffer. */ + config__load_buffer_state(yyscanner ); + yyg->yy_did_buffer_switch_on_eof = 1; +} +/* %endif */ + +/* %if-c-or-c++ */ +/** Removes and deletes the top of the stack, if present. + * The next element becomes the new top. + * @param yyscanner The scanner object. + */ +/* %if-c-only */ +void config_pop_buffer_state (yyscan_t yyscanner) +/* %endif */ +/* %if-c++-only */ +/* %endif */ +{ + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + if (!YY_CURRENT_BUFFER) + return; + + config__delete_buffer(YY_CURRENT_BUFFER ,yyscanner); + YY_CURRENT_BUFFER_LVALUE = NULL; + if (yyg->yy_buffer_stack_top > 0) + --yyg->yy_buffer_stack_top; + + if (YY_CURRENT_BUFFER) { + config__load_buffer_state(yyscanner ); + yyg->yy_did_buffer_switch_on_eof = 1; + } +} +/* %endif */ + +/* %if-c-or-c++ */ +/* Allocates the stack if it does not exist. + * Guarantees space for at least one push. + */ +/* %if-c-only */ +static void config_ensure_buffer_stack (yyscan_t yyscanner) +/* %endif */ +/* %if-c++-only */ +/* %endif */ +{ + int num_to_alloc; + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + + if (!yyg->yy_buffer_stack) { + + /* First allocation is just for 2 elements, since we don't know if this + * scanner will even need a stack. We use 2 instead of 1 to avoid an + * immediate realloc on the next call. + */ + num_to_alloc = 1; + yyg->yy_buffer_stack = (struct yy_buffer_state**)config_alloc + (num_to_alloc * sizeof(struct yy_buffer_state*) + , yyscanner); + if ( ! yyg->yy_buffer_stack ) + YY_FATAL_ERROR( "out of dynamic memory in config_ensure_buffer_stack()" ); + + memset(yyg->yy_buffer_stack, 0, num_to_alloc * sizeof(struct yy_buffer_state*)); + + yyg->yy_buffer_stack_max = num_to_alloc; + yyg->yy_buffer_stack_top = 0; + return; + } + + if (yyg->yy_buffer_stack_top >= (yyg->yy_buffer_stack_max) - 1){ + + /* Increase the buffer to prepare for a possible push. */ + int grow_size = 8 /* arbitrary grow size */; + + num_to_alloc = yyg->yy_buffer_stack_max + grow_size; + yyg->yy_buffer_stack = (struct yy_buffer_state**)config_realloc + (yyg->yy_buffer_stack, + num_to_alloc * sizeof(struct yy_buffer_state*) + , yyscanner); + if ( ! yyg->yy_buffer_stack ) + YY_FATAL_ERROR( "out of dynamic memory in config_ensure_buffer_stack()" ); + + /* zero only the new slots.*/ + memset(yyg->yy_buffer_stack + yyg->yy_buffer_stack_max, 0, grow_size * sizeof(struct yy_buffer_state*)); + yyg->yy_buffer_stack_max = num_to_alloc; + } +} +/* %endif */ + +/* %if-c-only */ +/** Setup the input buffer state to scan directly from a user-specified character buffer. + * @param base the character buffer + * @param size the size in bytes of the character buffer + * @param yyscanner The scanner object. + * @return the newly allocated buffer state object. + */ +YY_BUFFER_STATE config__scan_buffer (char * base, yy_size_t size , yyscan_t yyscanner) +{ + YY_BUFFER_STATE b; + + if ( size < 2 || + base[size-2] != YY_END_OF_BUFFER_CHAR || + base[size-1] != YY_END_OF_BUFFER_CHAR ) + /* They forgot to leave room for the EOB's. */ + return 0; + + b = (YY_BUFFER_STATE) config_alloc(sizeof( struct yy_buffer_state ) ,yyscanner ); + if ( ! b ) + YY_FATAL_ERROR( "out of dynamic memory in config__scan_buffer()" ); + + b->yy_buf_size = size - 2; /* "- 2" to take care of EOB's */ + b->yy_buf_pos = b->yy_ch_buf = base; + b->yy_is_our_buffer = 0; + b->yy_input_file = 0; + b->yy_n_chars = b->yy_buf_size; + b->yy_is_interactive = 0; + b->yy_at_bol = 1; + b->yy_fill_buffer = 0; + b->yy_buffer_status = YY_BUFFER_NEW; + + config__switch_to_buffer(b ,yyscanner ); + + return b; +} +/* %endif */ + +/* %if-c-only */ +/** Setup the input buffer state to scan a string. The next call to config_lex() will + * scan from a @e copy of @a str. + * @param yystr a NUL-terminated string to scan + * @param yyscanner The scanner object. + * @return the newly allocated buffer state object. + * @note If you want to scan bytes that may contain NUL values, then use + * config__scan_bytes() instead. + */ +YY_BUFFER_STATE config__scan_string (yyconst char * yystr , yyscan_t yyscanner) +{ + + return config__scan_bytes(yystr,strlen(yystr) ,yyscanner); +} +/* %endif */ + +/* %if-c-only */ +/** Setup the input buffer state to scan the given bytes. The next call to config_lex() will + * scan from a @e copy of @a bytes. + * @param bytes the byte buffer to scan + * @param len the number of bytes in the buffer pointed to by @a bytes. + * @param yyscanner The scanner object. + * @return the newly allocated buffer state object. + */ +YY_BUFFER_STATE config__scan_bytes (yyconst char * yybytes, int _yybytes_len , yyscan_t yyscanner) +{ + YY_BUFFER_STATE b; + char *buf; + yy_size_t n; + int i; + + /* Get memory for full buffer, including space for trailing EOB's. */ + n = _yybytes_len + 2; + buf = (char *) config_alloc(n ,yyscanner ); + if ( ! buf ) + YY_FATAL_ERROR( "out of dynamic memory in config__scan_bytes()" ); + + for ( i = 0; i < _yybytes_len; ++i ) + buf[i] = yybytes[i]; + + buf[_yybytes_len] = buf[_yybytes_len+1] = YY_END_OF_BUFFER_CHAR; + + b = config__scan_buffer(buf,n ,yyscanner); + if ( ! b ) + YY_FATAL_ERROR( "bad buffer in config__scan_bytes()" ); + + /* It's okay to grow etc. this buffer, and we should throw it + * away when we're done. + */ + b->yy_is_our_buffer = 1; + + return b; +} +/* %endif */ + +#ifndef YY_EXIT_FAILURE +#define YY_EXIT_FAILURE 2 +#endif + +/* %if-c-only */ +static void yy_fatal_error (yyconst char* msg , yyscan_t yyscanner) +{ + (void) fprintf( stderr, "%s\n", msg ); + exit( YY_EXIT_FAILURE ); +} +/* %endif */ +/* %if-c++-only */ +/* %endif */ + +/* Redefine yyless() so it works in section 3 code. */ + +#undef yyless +#define yyless(n) \ + do \ + { \ + /* Undo effects of setting up yytext. */ \ + int yyless_macro_arg = (n); \ + YY_LESS_LINENO(yyless_macro_arg);\ + yytext[yyleng] = yyg->yy_hold_char; \ + yyg->yy_c_buf_p = yytext + yyless_macro_arg; \ + yyg->yy_hold_char = *yyg->yy_c_buf_p; \ + *yyg->yy_c_buf_p = '\0'; \ + yyleng = yyless_macro_arg; \ + } \ + while ( 0 ) + +/* Accessor methods (get/set functions) to struct members. */ + +/* %if-c-only */ +/* %if-reentrant */ + +/** Get the user-defined data for this scanner. + * @param yyscanner The scanner object. + */ +YY_EXTRA_TYPE config_get_extra (yyscan_t yyscanner) +{ + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + return yyextra; +} + +/* %endif */ + +/** Get the current line number. + * @param yyscanner The scanner object. + */ +int config_get_lineno (yyscan_t yyscanner) +{ + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + + if (! YY_CURRENT_BUFFER) + return 0; + + return yylineno; +} + +/** Get the current column number. + * @param yyscanner The scanner object. + */ +int config_get_column (yyscan_t yyscanner) +{ + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + + if (! YY_CURRENT_BUFFER) + return 0; + + return yycolumn; +} + +/** Get the input stream. + * @param yyscanner The scanner object. + */ +FILE *config_get_in (yyscan_t yyscanner) +{ + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + return yyin; +} + +/** Get the output stream. + * @param yyscanner The scanner object. + */ +FILE *config_get_out (yyscan_t yyscanner) +{ + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + return yyout; +} + +/** Get the length of the current token. + * @param yyscanner The scanner object. + */ +int config_get_leng (yyscan_t yyscanner) +{ + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + return yyleng; +} + +/** Get the current token. + * @param yyscanner The scanner object. + */ + +char *config_get_text (yyscan_t yyscanner) +{ + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + return yytext; +} + +/* %if-reentrant */ + +/** Set the user-defined data. This data is never touched by the scanner. + * @param user_defined The data to be associated with this scanner. + * @param yyscanner The scanner object. + */ +void config_set_extra (YY_EXTRA_TYPE user_defined , yyscan_t yyscanner) +{ + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + yyextra = user_defined ; +} + +/* %endif */ + +/** Set the current line number. + * @param line_number + * @param yyscanner The scanner object. + */ +void config_set_lineno (int line_number , yyscan_t yyscanner) +{ + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + + /* lineno is only valid if an input buffer exists. */ + if (! YY_CURRENT_BUFFER ) + yy_fatal_error( "config_set_lineno called with no buffer" , yyscanner); + + yylineno = line_number; +} + +/** Set the current column. + * @param line_number + * @param yyscanner The scanner object. + */ +void config_set_column (int column_no , yyscan_t yyscanner) +{ + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + + /* column is only valid if an input buffer exists. */ + if (! YY_CURRENT_BUFFER ) + yy_fatal_error( "config_set_column called with no buffer" , yyscanner); + + yycolumn = column_no; +} + +/** Set the input stream. This does not discard the current + * input buffer. + * @param in_str A readable stream. + * @param yyscanner The scanner object. + * @see config__switch_to_buffer + */ +void config_set_in (FILE * in_str , yyscan_t yyscanner) +{ + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + yyin = in_str ; +} + +void config_set_out (FILE * out_str , yyscan_t yyscanner) +{ + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + yyout = out_str ; +} + +int config_get_debug (yyscan_t yyscanner) +{ + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + return yy_flex_debug; +} + +void config_set_debug (int bdebug , yyscan_t yyscanner) +{ + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + yy_flex_debug = bdebug ; +} + +/* %endif */ + +/* %if-reentrant */ +/* Accessor methods for yylval and yylloc */ + +/* %if-bison-bridge */ + +YYSTYPE * config_get_lval (yyscan_t yyscanner) +{ + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + return yylval; +} + +void config_set_lval (YYSTYPE * yylval_param , yyscan_t yyscanner) +{ + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + yylval = yylval_param; +} + +/* %endif */ + +/* User-visible API */ + +/* config_lex_init is special because it creates the scanner itself, so it is + * the ONLY reentrant function that doesn't take the scanner as the last argument. + * That's why we explicitly handle the declaration, instead of using our macros. + */ + +int config_lex_init(yyscan_t* ptr_yy_globals) + +{ + if (ptr_yy_globals == NULL){ + errno = EINVAL; + return 1; + } + + *ptr_yy_globals = (yyscan_t) config_alloc ( sizeof( struct yyguts_t ), NULL ); + + if (*ptr_yy_globals == NULL){ + errno = ENOMEM; + return 1; + } + + /* By setting to 0xAA, we expose bugs in yy_init_globals. Leave at 0x00 for releases. */ + memset(*ptr_yy_globals,0x00,sizeof(struct yyguts_t)); + + return yy_init_globals ( *ptr_yy_globals ); +} + +/* config_lex_init_extra has the same functionality as config_lex_init, but follows the + * convention of taking the scanner as the last argument. Note however, that + * this is a *pointer* to a scanner, as it will be allocated by this call (and + * is the reason, too, why this function also must handle its own declaration). + * The user defined value in the first argument will be available to config_alloc in + * the yyextra field. + */ + +int config_lex_init_extra(YY_EXTRA_TYPE yy_user_defined,yyscan_t* ptr_yy_globals ) + +{ + struct yyguts_t dummy_yyguts; + + config_set_extra (yy_user_defined, &dummy_yyguts); + + if (ptr_yy_globals == NULL){ + errno = EINVAL; + return 1; + } + + *ptr_yy_globals = (yyscan_t) config_alloc ( sizeof( struct yyguts_t ), &dummy_yyguts ); + + if (*ptr_yy_globals == NULL){ + errno = ENOMEM; + return 1; + } + + /* By setting to 0xAA, we expose bugs in + yy_init_globals. Leave at 0x00 for releases. */ + memset(*ptr_yy_globals,0x00,sizeof(struct yyguts_t)); + + config_set_extra (yy_user_defined, *ptr_yy_globals); + + return yy_init_globals ( *ptr_yy_globals ); +} + +/* %endif if-c-only */ + +/* %if-c-only */ +static int yy_init_globals (yyscan_t yyscanner) +{ + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + /* Initialization is the same as for the non-reentrant scanner. + * This function is called from config_lex_destroy(), so don't allocate here. + */ + + yyg->yy_buffer_stack = 0; + yyg->yy_buffer_stack_top = 0; + yyg->yy_buffer_stack_max = 0; + yyg->yy_c_buf_p = (char *) 0; + yyg->yy_init = 0; + yyg->yy_start = 0; + + yyg->yy_start_stack_ptr = 0; + yyg->yy_start_stack_depth = 0; + yyg->yy_start_stack = NULL; + +/* Defined in main.c */ +#ifdef YY_STDINIT + yyin = stdin; + yyout = stdout; +#else + yyin = (FILE *) 0; + yyout = (FILE *) 0; +#endif + + /* For future reference: Set errno on error, since we are called by + * config_lex_init() + */ + return 0; +} +/* %endif */ + +/* %if-c-only SNIP! this currently causes conflicts with the c++ scanner */ +/* config_lex_destroy is for both reentrant and non-reentrant scanners. */ +int config_lex_destroy (yyscan_t yyscanner) +{ + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + + /* Pop the buffer stack, destroying each element. */ + while(YY_CURRENT_BUFFER){ + config__delete_buffer(YY_CURRENT_BUFFER ,yyscanner ); + YY_CURRENT_BUFFER_LVALUE = NULL; + config_pop_buffer_state(yyscanner); + } + + /* Destroy the stack itself. */ + config_free(yyg->yy_buffer_stack ,yyscanner); + yyg->yy_buffer_stack = NULL; + + /* Destroy the start condition stack. */ + config_free(yyg->yy_start_stack ,yyscanner ); + yyg->yy_start_stack = NULL; + + /* Reset the globals. This is important in a non-reentrant scanner so the next time + * config_lex() is called, initialization will occur. */ + yy_init_globals( yyscanner); + +/* %if-reentrant */ + /* Destroy the main struct (reentrant only). */ + config_free ( yyscanner , yyscanner ); + yyscanner = NULL; +/* %endif */ + return 0; +} +/* %endif */ + +/* + * Internal utility routines. + */ + +#ifndef yytext_ptr +static void yy_flex_strncpy (char* s1, yyconst char * s2, int n , yyscan_t yyscanner) +{ + register int i; + for ( i = 0; i < n; ++i ) + s1[i] = s2[i]; +} +#endif + +#ifdef YY_NEED_STRLEN +static int yy_flex_strlen (yyconst char * s , yyscan_t yyscanner) +{ + register int n; + for ( n = 0; s[n]; ++n ) + ; + + return n; +} +#endif + +void *config_alloc (yy_size_t size , yyscan_t yyscanner) +{ + return (void *) malloc( size ); +} + +void *config_realloc (void * ptr, yy_size_t size , yyscan_t yyscanner) +{ + /* The cast to (char *) in the following accommodates both + * implementations that use char* generic pointers, and those + * that use void* generic pointers. It works with the latter + * because both ANSI C and C++ allow castless assignment from + * any pointer type to void*, and deal with argument conversions + * as though doing an assignment. + */ + return (void *) realloc( (char *) ptr, size ); +} + +void config_free (void * ptr , yyscan_t yyscanner) +{ + free( (char *) ptr ); /* see config_realloc() for (char *) cast */ +} + +/* %if-tables-serialization definitions */ +/* %define-yytables The name for this specific scanner's tables. */ +#define YYTABLES_NAME "yytables" +/* %endif */ + +/* %ok-for-header */ + +#line 224 "libmemcached/options/scanner.l" + + + +void Context::init_scanner() +{ + config_lex_init(&scanner); + config_set_extra(this,scanner); +} + +void Context::destroy_scanner() +{ + config_lex_destroy(scanner); +} + + diff --git a/libmemcached/options/scanner.h b/libmemcached/options/scanner.h new file mode 100644 index 00000000..062d9adf --- /dev/null +++ b/libmemcached/options/scanner.h @@ -0,0 +1,478 @@ +#ifndef config_HEADER_H +#define config_HEADER_H 1 +#define config_IN_HEADER 1 + +#line 6 "libmemcached/options/scanner.h" +#line 22 "libmemcached/options/scanner.l" + +#pragma GCC diagnostic ignored "-Wold-style-cast" +#pragma GCC diagnostic ignored "-Wunused-parameter" + +#include +#include +#include +#include + +#define YY_EXTRA_TYPE Context* + + + + +#line 22 "libmemcached/options/scanner.h" + +#define YY_INT_ALIGNED short int + +/* A lexical scanner generated by flex */ + +/* %not-for-header */ + +#define FLEX_SCANNER +#define YY_FLEX_MAJOR_VERSION 2 +#define YY_FLEX_MINOR_VERSION 5 +#define YY_FLEX_SUBMINOR_VERSION 35 +#if YY_FLEX_SUBMINOR_VERSION > 0 +#define FLEX_BETA +#endif + +/* %if-c++-only */ +/* %endif */ + +/* %if-c-only */ + +/* %endif */ + +/* %if-c-only */ + +/* %endif */ + +/* First, we deal with platform-specific or compiler-specific issues. */ + +/* begin standard C headers. */ +/* %if-c-only */ +#include +#include +#include +#include +/* %endif */ + +/* %if-tables-serialization */ +/* %endif */ +/* end standard C headers. */ + +/* %if-c-or-c++ */ +/* flex integer type definitions */ + +#ifndef FLEXINT_H +#define FLEXINT_H + +/* C99 systems have . Non-C99 systems may or may not. */ + +#if defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L + +/* C99 says to define __STDC_LIMIT_MACROS before including stdint.h, + * if you want the limit (max/min) macros for int types. + */ +#ifndef __STDC_LIMIT_MACROS +#define __STDC_LIMIT_MACROS 1 +#endif + +#include +typedef int8_t flex_int8_t; +typedef uint8_t flex_uint8_t; +typedef int16_t flex_int16_t; +typedef uint16_t flex_uint16_t; +typedef int32_t flex_int32_t; +typedef uint32_t flex_uint32_t; +#else +typedef signed char flex_int8_t; +typedef short int flex_int16_t; +typedef int flex_int32_t; +typedef unsigned char flex_uint8_t; +typedef unsigned short int flex_uint16_t; +typedef unsigned int flex_uint32_t; +#endif /* ! C99 */ + +/* Limits of integral types. */ +#ifndef INT8_MIN +#define INT8_MIN (-128) +#endif +#ifndef INT16_MIN +#define INT16_MIN (-32767-1) +#endif +#ifndef INT32_MIN +#define INT32_MIN (-2147483647-1) +#endif +#ifndef INT8_MAX +#define INT8_MAX (127) +#endif +#ifndef INT16_MAX +#define INT16_MAX (32767) +#endif +#ifndef INT32_MAX +#define INT32_MAX (2147483647) +#endif +#ifndef UINT8_MAX +#define UINT8_MAX (255U) +#endif +#ifndef UINT16_MAX +#define UINT16_MAX (65535U) +#endif +#ifndef UINT32_MAX +#define UINT32_MAX (4294967295U) +#endif + +#endif /* ! FLEXINT_H */ + +/* %endif */ + +/* %if-c++-only */ +/* %endif */ + +#ifdef __cplusplus + +/* The "const" storage-class-modifier is valid. */ +#define YY_USE_CONST + +#else /* ! __cplusplus */ + +/* C99 requires __STDC__ to be defined as 1. */ +#if defined (__STDC__) + +#define YY_USE_CONST + +#endif /* defined (__STDC__) */ +#endif /* ! __cplusplus */ + +#ifdef YY_USE_CONST +#define yyconst const +#else +#define yyconst +#endif + +/* %not-for-header */ + +/* %not-for-header */ + +/* %if-reentrant */ + +/* An opaque pointer. */ +#ifndef YY_TYPEDEF_YY_SCANNER_T +#define YY_TYPEDEF_YY_SCANNER_T +typedef void* yyscan_t; +#endif + +/* For convenience, these vars (plus the bison vars far below) + are macros in the reentrant scanner. */ +#define yyin yyg->yyin_r +#define yyout yyg->yyout_r +#define yyextra yyg->yyextra_r +#define yyleng yyg->yyleng_r +#define yytext yyg->yytext_r +#define yylineno (YY_CURRENT_BUFFER_LVALUE->yy_bs_lineno) +#define yycolumn (YY_CURRENT_BUFFER_LVALUE->yy_bs_column) +#define yy_flex_debug yyg->yy_flex_debug_r + +/* %endif */ + +/* %if-not-reentrant */ +/* %endif */ + +/* Size of default input buffer. */ +#ifndef YY_BUF_SIZE +#define YY_BUF_SIZE 16384 +#endif + +#ifndef YY_TYPEDEF_YY_BUFFER_STATE +#define YY_TYPEDEF_YY_BUFFER_STATE +typedef struct yy_buffer_state *YY_BUFFER_STATE; +#endif + +/* %if-not-reentrant */ +/* %endif */ + +/* %if-c-only */ +/* %if-not-reentrant */ +/* %endif */ +/* %endif */ + +#ifndef YY_TYPEDEF_YY_SIZE_T +#define YY_TYPEDEF_YY_SIZE_T +typedef size_t yy_size_t; +#endif + +#ifndef YY_STRUCT_YY_BUFFER_STATE +#define YY_STRUCT_YY_BUFFER_STATE +struct yy_buffer_state + { +/* %if-c-only */ + FILE *yy_input_file; +/* %endif */ + +/* %if-c++-only */ +/* %endif */ + + char *yy_ch_buf; /* input buffer */ + char *yy_buf_pos; /* current position in input buffer */ + + /* Size of input buffer in bytes, not including room for EOB + * characters. + */ + yy_size_t yy_buf_size; + + /* Number of characters read into yy_ch_buf, not including EOB + * characters. + */ + int yy_n_chars; + + /* Whether we "own" the buffer - i.e., we know we created it, + * and can realloc() it to grow it, and should free() it to + * delete it. + */ + int yy_is_our_buffer; + + /* Whether this is an "interactive" input source; if so, and + * if we're using stdio for input, then we want to use getc() + * instead of fread(), to make sure we stop fetching input after + * each newline. + */ + int yy_is_interactive; + + /* Whether we're considered to be at the beginning of a line. + * If so, '^' rules will be active on the next match, otherwise + * not. + */ + int yy_at_bol; + + int yy_bs_lineno; /**< The line count. */ + int yy_bs_column; /**< The column count. */ + + /* Whether to try to fill the input buffer when we reach the + * end of it. + */ + int yy_fill_buffer; + + int yy_buffer_status; + + }; +#endif /* !YY_STRUCT_YY_BUFFER_STATE */ + +/* %if-c-only Standard (non-C++) definition */ +/* %not-for-header */ + +/* %endif */ + +/* %if-c-only Standard (non-C++) definition */ + +/* %if-not-reentrant */ +/* %not-for-header */ + +/* %endif */ + +void config_restart (FILE *input_file ,yyscan_t yyscanner ); +void config__switch_to_buffer (YY_BUFFER_STATE new_buffer ,yyscan_t yyscanner ); +YY_BUFFER_STATE config__create_buffer (FILE *file,int size ,yyscan_t yyscanner ); +void config__delete_buffer (YY_BUFFER_STATE b ,yyscan_t yyscanner ); +void config__flush_buffer (YY_BUFFER_STATE b ,yyscan_t yyscanner ); +void config_push_buffer_state (YY_BUFFER_STATE new_buffer ,yyscan_t yyscanner ); +void config_pop_buffer_state (yyscan_t yyscanner ); + +YY_BUFFER_STATE config__scan_buffer (char *base,yy_size_t size ,yyscan_t yyscanner ); +YY_BUFFER_STATE config__scan_string (yyconst char *yy_str ,yyscan_t yyscanner ); +YY_BUFFER_STATE config__scan_bytes (yyconst char *bytes,int len ,yyscan_t yyscanner ); + +/* %endif */ + +void *config_alloc (yy_size_t ,yyscan_t yyscanner ); +void *config_realloc (void *,yy_size_t ,yyscan_t yyscanner ); +void config_free (void * ,yyscan_t yyscanner ); + +/* %% [1.0] yytext/yyin/yyout/yy_state_type/yylineno etc. def's & init go here */ +/* Begin user sect3 */ + +#define config_wrap(n) 1 +#define YY_SKIP_YYWRAP + +#define FLEX_DEBUG + +#define yytext_ptr yytext_r + +/* %if-c-only Standard (non-C++) definition */ + +/* %endif */ + +#ifdef YY_HEADER_EXPORT_START_CONDITIONS +#define INITIAL 0 + +#endif + +#ifndef YY_NO_UNISTD_H +/* Special case for "unistd.h", since it is non-ANSI. We include it way + * down here because we want the user's section 1 to have been scanned first. + * The user has a chance to override it with an option. + */ +/* %if-c-only */ +#include +/* %endif */ +/* %if-c++-only */ +/* %endif */ +#endif + +#ifndef YY_EXTRA_TYPE +#define YY_EXTRA_TYPE void * +#endif + +/* %if-c-only Reentrant structure and macros (non-C++). */ +/* %if-reentrant */ + +/* %if-c-only */ + +/* %endif */ + +/* %if-reentrant */ + +int config_lex_init (yyscan_t* scanner); + +int config_lex_init_extra (YY_EXTRA_TYPE user_defined,yyscan_t* scanner); + +/* %endif */ + +/* %endif End reentrant structures and macros. */ + +/* Accessor methods to globals. + These are made visible to non-reentrant scanners for convenience. */ + +int config_lex_destroy (yyscan_t yyscanner ); + +int config_get_debug (yyscan_t yyscanner ); + +void config_set_debug (int debug_flag ,yyscan_t yyscanner ); + +YY_EXTRA_TYPE config_get_extra (yyscan_t yyscanner ); + +void config_set_extra (YY_EXTRA_TYPE user_defined ,yyscan_t yyscanner ); + +FILE *config_get_in (yyscan_t yyscanner ); + +void config_set_in (FILE * in_str ,yyscan_t yyscanner ); + +FILE *config_get_out (yyscan_t yyscanner ); + +void config_set_out (FILE * out_str ,yyscan_t yyscanner ); + +int config_get_leng (yyscan_t yyscanner ); + +char *config_get_text (yyscan_t yyscanner ); + +int config_get_lineno (yyscan_t yyscanner ); + +void config_set_lineno (int line_number ,yyscan_t yyscanner ); + +int config_get_column (yyscan_t yyscanner ); + +void config_set_column (int column_no ,yyscan_t yyscanner ); + +/* %if-bison-bridge */ + +YYSTYPE * config_get_lval (yyscan_t yyscanner ); + +void config_set_lval (YYSTYPE * yylval_param ,yyscan_t yyscanner ); + +/* %endif */ + +/* Macros after this point can all be overridden by user definitions in + * section 1. + */ + +#ifndef YY_SKIP_YYWRAP +#ifdef __cplusplus +extern "C" int config_wrap (yyscan_t yyscanner ); +#else +extern int config_wrap (yyscan_t yyscanner ); +#endif +#endif + +/* %not-for-header */ + +/* %endif */ + +#ifndef yytext_ptr +static void yy_flex_strncpy (char *,yyconst char *,int ,yyscan_t yyscanner); +#endif + +#ifdef YY_NEED_STRLEN +static int yy_flex_strlen (yyconst char * ,yyscan_t yyscanner); +#endif + +#ifndef YY_NO_INPUT +/* %if-c-only Standard (non-C++) definition */ +/* %not-for-header */ + +/* %endif */ +#endif + +/* %if-c-only */ + +/* %endif */ + +/* Amount of stuff to slurp up with each read. */ +#ifndef YY_READ_BUF_SIZE +#define YY_READ_BUF_SIZE 8192 +#endif + +/* Number of entries by which start-condition stack grows. */ +#ifndef YY_START_STACK_INCR +#define YY_START_STACK_INCR 25 +#endif + +/* %if-tables-serialization structures and prototypes */ +/* %not-for-header */ + +/* %not-for-header */ + +/* Default declaration of generated scanner - a define so the user can + * easily add parameters. + */ +#ifndef YY_DECL +#define YY_DECL_IS_OURS 1 +/* %if-c-only Standard (non-C++) definition */ + +extern int config_lex \ + (YYSTYPE * yylval_param ,yyscan_t yyscanner); + +#define YY_DECL int config_lex \ + (YYSTYPE * yylval_param , yyscan_t yyscanner) +/* %endif */ +/* %if-c++-only C++ definition */ +/* %endif */ +#endif /* !YY_DECL */ + +/* %not-for-header */ + +/* %if-c++-only */ +/* %not-for-header */ + +/* %endif */ + +/* yy_get_previous_state - get the state just before the EOB char was reached */ + +/* %if-c-only */ +/* %not-for-header */ + +#undef YY_NEW_FILE +#undef YY_FLUSH_BUFFER +#undef yy_set_bol +#undef yy_new_buffer +#undef yy_set_interactive +#undef YY_DO_BEFORE_ACTION + +#ifdef YY_DECL_IS_OURS +#undef YY_DECL_IS_OURS +#undef YY_DECL +#endif + +#line 224 "libmemcached/options/scanner.l" + + +#line 477 "libmemcached/options/scanner.h" +#undef config_IN_HEADER +#endif /* config_HEADER_H */ diff --git a/libmemcached/options/server.h b/libmemcached/options/server.h new file mode 100644 index 00000000..af6e0f3e --- /dev/null +++ b/libmemcached/options/server.h @@ -0,0 +1,56 @@ +/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: + * + * Libmemcached library + * + * Copyright (C) 2011 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. + * + */ + +#pragma once + +#include +#include +#include + +struct server_t +{ + const char *c_str; + size_t length; + in_port_t port; +}; + +inline std::ostream& operator<<(std::ostream& output, const server_t& arg) +{ + output.write(arg.c_str, arg.length); + output << ':' << arg.port; + return output; +} diff --git a/libmemcached/options/string.h b/libmemcached/options/string.h new file mode 100644 index 00000000..82d60acb --- /dev/null +++ b/libmemcached/options/string.h @@ -0,0 +1,53 @@ +/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: + * + * Libmemcached library + * + * Copyright (C) 2011 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. + * + */ + +#pragma once + +#include +#include + +struct string_t +{ + const char *c_str; + size_t length; +}; + +inline std::ostream& operator<<(std::ostream& output, const string_t& arg) +{ + output.write(arg.c_str, arg.length); + return output; +} diff --git a/libmemcached/options/symbol.h b/libmemcached/options/symbol.h new file mode 100644 index 00000000..b14eb331 --- /dev/null +++ b/libmemcached/options/symbol.h @@ -0,0 +1,57 @@ +/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: + * + * Libmemcached library + * + * Copyright (C) 2011 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. + * + */ + +#pragma once + +#include +#include +#include + +union YYSTYPE +{ + long long number; + string_t string; + string_t option; + server_t server; + double double_number; + memcached_server_distribution_t distribution; + memcached_hash_t hash; + memcached_behavior_t behavior; + bool boolean; +}; + +typedef union YYSTYPE YYSTYPE; diff --git a/libmemcached/parse.h b/libmemcached/parse.h index 45a5d746..a91f769d 100644 --- a/libmemcached/parse.h +++ b/libmemcached/parse.h @@ -9,8 +9,7 @@ * */ -#ifndef __LIBMEMCACHED_PARSE_H__ -#define __LIBMEMCACHED_PARSE_H__ +#pragma once #ifdef __cplusplus extern "C" { @@ -22,5 +21,3 @@ memcached_server_list_st memcached_servers_parse(const char *server_strings); #ifdef __cplusplus } #endif - -#endif /* __LIBMEMCACHED_PARSE_H__ */ diff --git a/libmemcached/prefix_key.cc b/libmemcached/prefix_key.cc new file mode 100644 index 00000000..526f5fac --- /dev/null +++ b/libmemcached/prefix_key.cc @@ -0,0 +1,63 @@ +/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: + * + * Libmemcached library + * + * Copyright (C) 2011 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. + * + */ + +#include + +memcached_return_t memcached_set_prefix_key(memcached_st *self, const char *key, size_t key_length) +{ + if (key && key_length) + { + if (memcached_key_test((const char **)&key, &key_length, 1) == MEMCACHED_BAD_KEY_PROVIDED) + return memcached_set_error(self, MEMCACHED_BAD_KEY_PROVIDED, NULL); + + if ((key_length > MEMCACHED_PREFIX_KEY_MAX_SIZE -1)) + return memcached_set_error(self, MEMCACHED_KEY_TOO_BIG, NULL); + + memcached_array_free(self->prefix_key); + self->prefix_key= memcached_strcpy(self, key, key_length); + + if (! self->prefix_key) + return memcached_set_error(self, MEMCACHED_MEMORY_ALLOCATION_FAILURE, NULL); + } + else + { + memcached_array_free(self->prefix_key); + self->prefix_key= NULL; + } + + return MEMCACHED_SUCCESS; +} diff --git a/libmemcached/prefix_key.h b/libmemcached/prefix_key.h new file mode 100644 index 00000000..bd81160f --- /dev/null +++ b/libmemcached/prefix_key.h @@ -0,0 +1,49 @@ +/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: + * + * Libmemcached library + * + * Copyright (C) 2011 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. + * + */ + +#pragma once + +#ifdef __cplusplus +extern "C" { +#endif + +LIBMEMCACHED_LOCAL + memcached_return_t memcached_set_prefix_key(memcached_st *self, const char *str, size_t length); + +#ifdef __cplusplus +} +#endif diff --git a/libmemcached/protocol/binary_handler.c b/libmemcached/protocol/binary_handler.c index 81c09c99..a9e4ce95 100644 --- a/libmemcached/protocol/binary_handler.c +++ b/libmemcached/protocol/binary_handler.c @@ -39,7 +39,7 @@ raw_response_handler(const void *cookie, if (!client->root->drain(client)) { - return PROTOCOL_BINARY_RESPONSE_EIO; + return PROTOCOL_BINARY_RESPONSE_EINTERNAL; } size_t len= sizeof(*response) + htonl(response->response.bodylen); @@ -65,7 +65,7 @@ raw_response_handler(const void *cookie, else if (get_socket_errno() != EINTR) { client->error= errno; - return PROTOCOL_BINARY_RESPONSE_EIO; + return PROTOCOL_BINARY_RESPONSE_EINTERNAL; } } else @@ -700,7 +700,7 @@ quit_command_handler(const void *cookie, } /* I need a better way to signal to close the connection */ - return PROTOCOL_BINARY_RESPONSE_EIO; + return PROTOCOL_BINARY_RESPONSE_EINTERNAL; } /** @@ -970,8 +970,8 @@ static protocol_binary_response_status execute_command(memcached_protocol_client } if (rval != PROTOCOL_BINARY_RESPONSE_SUCCESS && - rval != PROTOCOL_BINARY_RESPONSE_EIO && - rval != PROTOCOL_BINARY_RESPONSE_PAUSE) + rval != PROTOCOL_BINARY_RESPONSE_EINTERNAL && + rval != PROTOCOL_BINARY_RESPONSE_NOT_SUPPORTED) { protocol_binary_response_no_extras response= { .message= { @@ -1018,12 +1018,12 @@ memcached_protocol_event_t memcached_binary_protocol_process_data(memcached_prot client->current_command= header; protocol_binary_response_status rv= execute_command(client, header); - if (rv == PROTOCOL_BINARY_RESPONSE_EIO) + if (rv == PROTOCOL_BINARY_RESPONSE_EINTERNAL) { *length= len; *endptr= (void*)header; return MEMCACHED_PROTOCOL_ERROR_EVENT; - } else if (rv == PROTOCOL_BINARY_RESPONSE_PAUSE) + } else if (rv == PROTOCOL_BINARY_RESPONSE_NOT_SUPPORTED) return MEMCACHED_PROTOCOL_PAUSE_EVENT; ssize_t total= (ssize_t)(sizeof(*header) + ntohl(header->request.bodylen)); diff --git a/libmemcached/response.c b/libmemcached/response.c index 867a999e..49825fb1 100644 --- a/libmemcached/response.c +++ b/libmemcached/response.c @@ -115,7 +115,7 @@ static memcached_return_t textual_value_fetch(memcached_server_write_instance_st key= result->item_key; result->key_length= 0; - for (prefix_length= ptr->root->prefix_key_length; !(iscntrl(*string_ptr) || isspace(*string_ptr)) ; string_ptr++) + for (prefix_length= memcached_array_size(ptr->root->prefix_key); !(iscntrl(*string_ptr) || isspace(*string_ptr)) ; string_ptr++) { if (prefix_length == 0) { diff --git a/libmemcached/result.c b/libmemcached/result.c index c6c754f3..6e58eebd 100644 --- a/libmemcached/result.c +++ b/libmemcached/result.c @@ -18,7 +18,7 @@ #include "common.h" static inline void _result_init(memcached_result_st *self, - const memcached_st *memc) + memcached_st *memc) { self->item_flags= 0; self->item_expiration= 0; @@ -50,9 +50,8 @@ memcached_result_st *memcached_result_create(const memcached_st *memc, ptr->options.is_initialized= true; - _result_init(ptr, memc); + _result_init(ptr, (memcached_st *)memc); - ptr->root= memc; WATCHPOINT_SET(ptr->value.options.is_initialized= false); memcached_string_create(memc, &ptr->value, 0); WATCHPOINT_ASSERT_INITIALIZED(&ptr->value); @@ -96,7 +95,7 @@ memcached_return_t memcached_result_set_value(memcached_result_st *ptr, if (rc == MEMCACHED_MEMORY_ALLOCATION_FAILURE) { - ((memcached_st *)ptr->root)->cached_errno= errno; + memcached_set_errno(ptr->root, errno, NULL); } return rc; diff --git a/libmemcached/result.h b/libmemcached/result.h index 46ea6eff..701b89b7 100644 --- a/libmemcached/result.h +++ b/libmemcached/result.h @@ -17,7 +17,7 @@ struct memcached_result_st { time_t item_expiration; size_t key_length; uint64_t item_cas; - const memcached_st *root; + memcached_st *root; memcached_string_st value; char item_key[MEMCACHED_MAX_KEY]; struct { diff --git a/libmemcached/server.h b/libmemcached/server.h index 4248e143..aadd690f 100644 --- a/libmemcached/server.h +++ b/libmemcached/server.h @@ -96,6 +96,13 @@ LIBMEMCACHED_API memcached_return_t memcached_server_add(memcached_st *ptr, const char *hostname, in_port_t port); +LIBMEMCACHED_LOCAL + memcached_return_t memcached_server_add_parsed(memcached_st *ptr, + const char *hostname, + size_t hostname_length, + in_port_t port, + uint32_t weight); + LIBMEMCACHED_API memcached_return_t memcached_server_add_udp_with_weight(memcached_st *ptr, const char *hostname, diff --git a/libmemcached/stats.c b/libmemcached/stats.c index 5a37dfd9..83d342a1 100644 --- a/libmemcached/stats.c +++ b/libmemcached/stats.c @@ -400,21 +400,21 @@ error: return rc; } -memcached_stat_st *memcached_stat(memcached_st *ptr, char *args, memcached_return_t *error) +memcached_stat_st *memcached_stat(memcached_st *self, char *args, memcached_return_t *error) { memcached_return_t rc; memcached_stat_st *stats; - if (! ptr) + if (! self) { - WATCHPOINT_ASSERT(memc_ptr); + WATCHPOINT_ASSERT(self); return NULL; } WATCHPOINT_ASSERT(error); - unlikely (ptr->flags.use_udp) + unlikely (self->flags.use_udp) { if (error) *error= MEMCACHED_NOT_SUPPORTED; @@ -422,7 +422,7 @@ memcached_stat_st *memcached_stat(memcached_st *ptr, char *args, memcached_retur return NULL; } - stats= libmemcached_calloc(ptr, memcached_server_count(ptr), sizeof(memcached_stat_st)); + stats= libmemcached_calloc(self, memcached_server_count(self), sizeof(memcached_stat_st)); if (! stats) { @@ -433,7 +433,7 @@ memcached_stat_st *memcached_stat(memcached_st *ptr, char *args, memcached_retur } rc= MEMCACHED_SUCCESS; - for (uint32_t x= 0; x < memcached_server_count(ptr); x++) + for (uint32_t x= 0; x < memcached_server_count(self); x++) { memcached_return_t temp_return; memcached_server_write_instance_st instance; @@ -441,11 +441,11 @@ memcached_stat_st *memcached_stat(memcached_st *ptr, char *args, memcached_retur stat_instance= stats + x; - stat_instance->root= ptr; + stat_instance->root= self; - instance= memcached_server_instance_fetch(ptr, x); + instance= memcached_server_instance_fetch(self, x); - if (ptr->flags.binary_protocol) + if (self->flags.binary_protocol) { temp_return= binary_stats_fetch(stat_instance, args, instance, NULL); } diff --git a/libmemcached/storage.c b/libmemcached/storage.c index 191802ab..c31a473a 100644 --- a/libmemcached/storage.c +++ b/libmemcached/storage.c @@ -108,8 +108,7 @@ static inline memcached_return_t memcached_send(memcached_st *ptr, check_length= snprintf(buffer, MEMCACHED_DEFAULT_COMMAND_SIZE, "%s %.*s%.*s %u %llu %lu %llu%s\r\n", storage_op_string(verb), - (int)ptr->prefix_key_length, - ptr->prefix_key, + memcached_print_array(ptr->prefix_key), (int)key_length, key, flags, (unsigned long long)expiration, (unsigned long)value_length, (unsigned long long)cas, @@ -132,10 +131,10 @@ static inline memcached_return_t memcached_send(memcached_st *ptr, memcpy(buffer_ptr, command, strlen(command)); /* Copy in the key prefix, switch to the buffer_ptr */ - buffer_ptr= memcpy((buffer_ptr + strlen(command)), ptr->prefix_key, ptr->prefix_key_length); + buffer_ptr= memcpy((buffer_ptr + strlen(command)), memcached_array_string(ptr->prefix_key), memcached_array_size(ptr->prefix_key)); /* Copy in the key, adjust point if a key prefix was used. */ - buffer_ptr= memcpy(buffer_ptr + (ptr->prefix_key_length ? ptr->prefix_key_length : 0), + buffer_ptr= memcpy(buffer_ptr + memcached_array_size(ptr->prefix_key), key, key_length); buffer_ptr+= key_length; buffer_ptr[0]= ' '; @@ -479,7 +478,7 @@ static memcached_return_t memcached_send_binary(memcached_st *ptr, request.message.header.request.magic= PROTOCOL_BINARY_REQ; request.message.header.request.opcode= get_com_code(verb, noreply); - request.message.header.request.keylen= htons((uint16_t)(key_length + ptr->prefix_key_length)); + request.message.header.request.keylen= htons((uint16_t)(key_length + memcached_array_size(ptr->prefix_key))); request.message.header.request.datatype= PROTOCOL_BINARY_RAW_BYTES; if (verb == APPEND_OP || verb == PREPEND_OP) send_length -= 8; /* append & prepend does not contain extras! */ @@ -490,7 +489,7 @@ static memcached_return_t memcached_send_binary(memcached_st *ptr, request.message.body.expiration= htonl((uint32_t)expiration); } - request.message.header.request.bodylen= htonl((uint32_t) (key_length + ptr->prefix_key_length + value_length + + request.message.header.request.bodylen= htonl((uint32_t) (key_length + memcached_array_size(ptr->prefix_key) + value_length + request.message.header.request.extlen)); if (cas) @@ -515,7 +514,7 @@ static memcached_return_t memcached_send_binary(memcached_st *ptr, struct libmemcached_io_vector_st vector[]= { { .length= send_length, .buffer= request.bytes }, - { .length= ptr->prefix_key_length, .buffer= ptr->prefix_key }, + { .length= memcached_array_size(ptr->prefix_key), .buffer= memcached_array_string(ptr->prefix_key) }, { .length= key_length, .buffer= key }, { .length= value_length, .buffer= value } }; diff --git a/libmemcached/strerror.c b/libmemcached/strerror.c index d1c0f297..773ccd03 100644 --- a/libmemcached/strerror.c +++ b/libmemcached/strerror.c @@ -91,6 +91,10 @@ const char *memcached_strerror(memcached_st *ptr, memcached_return_t rc) return "AUTHENTICATION FAILURE"; case MEMCACHED_AUTH_CONTINUE: return "CONTINUE AUTHENTICATION"; + case MEMCACHED_PARSE_ERROR: + return "ERROR OCCURED WHILE PARSING"; + case MEMCACHED_PARSE_USER_ERROR: + return "USER INITIATED ERROR OCCURED WHILE PARSING"; case MEMCACHED_MAXIMUM_RETURN: return "Gibberish returned!"; default: diff --git a/libmemcached/string.c b/libmemcached/string.c index 34597067..b5badc5e 100644 --- a/libmemcached/string.c +++ b/libmemcached/string.c @@ -75,7 +75,7 @@ memcached_string_st *memcached_string_create(const memcached_st *memc, memcached self->options.is_allocated= true; } - self->root= memc; + self->root= (memcached_st *)memc; _init_string(self); @@ -84,7 +84,7 @@ memcached_string_st *memcached_string_create(const memcached_st *memc, memcached { if (rc == MEMCACHED_MEMORY_ALLOCATION_FAILURE) { - ((memcached_st *)memc)->cached_errno= errno; + memcached_set_errno(self->root, errno, NULL); } libmemcached_free(memc, self); diff --git a/libmemcached/string.h b/libmemcached/string.h index ca2c1220..ca3dad14 100644 --- a/libmemcached/string.h +++ b/libmemcached/string.h @@ -9,6 +9,7 @@ * */ +#pragma once #ifndef __LIBMEMCACHED_STRING_H__ #define __LIBMEMCACHED_STRING_H__ @@ -26,13 +27,18 @@ struct memcached_string_st { char *end; char *string; size_t current_size; - const memcached_st *root; + memcached_st *root; struct { bool is_allocated:1; bool is_initialized:1; } options; }; +struct memcached_string_t { + size_t size; + const char *c_str; +}; + #ifdef __cplusplus extern "C" { #endif @@ -78,5 +84,18 @@ void memcached_string_set_length(memcached_string_st *self, size_t length); } #endif +#ifdef BUILDING_LIBMEMCACHED + +#ifdef __cplusplus +#define memcached_string_with_size(X) (X), (static_cast((sizeof(X) - 1))) +#define memcached_string_make(X) (static_cast((sizeof(X) - 1))), (X) +#else +#define memcached_string_with_size(X) (X), ((size_t)((sizeof(X) - 1))) +#define memcached_string_make(X) (((size_t)((sizeof(X) - 1))), (X) +#endif + +#define memcached_string_make_from_cstr(X) (X), ((X) ? strlen(X) : 0) + +#endif #endif /* __LIBMEMCACHED_STRING_H__ */ diff --git a/libmemcached/types.h b/libmemcached/types.h index 28a1535c..89c1203b 100644 --- a/libmemcached/types.h +++ b/libmemcached/types.h @@ -16,6 +16,8 @@ typedef struct memcached_st memcached_st; typedef struct memcached_stat_st memcached_stat_st; typedef struct memcached_analysis_st memcached_analysis_st; typedef struct memcached_result_st memcached_result_st; +typedef struct memcached_array_st memcached_array_st; +typedef struct memcached_error_st memcached_error_st; // All of the flavors of memcache_server_st typedef struct memcached_server_st memcached_server_st; @@ -26,6 +28,7 @@ typedef struct memcached_callback_st memcached_callback_st; // The following two structures are internal, and never exposed to users. typedef struct memcached_string_st memcached_string_st; +typedef struct memcached_string_t memcached_string_t; typedef struct memcached_continuum_item_st memcached_continuum_item_st; diff --git a/libmemcached/virtual_bucket.c b/libmemcached/virtual_bucket.c new file mode 100644 index 00000000..26dd90c4 --- /dev/null +++ b/libmemcached/virtual_bucket.c @@ -0,0 +1,117 @@ +/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: + * + * Libmemcached library + * + * Copyright (C) 2011 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. + * + */ + +#include +#include + +struct bucket_t { + uint32_t master; + uint32_t forward; +}; + +struct memcached_virtual_bucket_t { + bool has_forward; + uint32_t size; + uint32_t replicas; + struct bucket_t buckets[]; +}; + +memcached_return_t memcached_virtual_bucket_create(memcached_st *self, + const uint32_t *host_map, + const uint32_t *forward_map, + const uint32_t buckets, + const uint32_t replicas) +{ + if (! self || ! host_map || ! buckets) + return MEMCACHED_INVALID_ARGUMENTS; + + memcached_virtual_bucket_free(self); + + struct memcached_virtual_bucket_t *virtual_bucket= (struct memcached_virtual_bucket_t *)malloc(sizeof(struct memcached_virtual_bucket_t) + sizeof(struct bucket_t) *buckets); + + if (! virtual_bucket) + return MEMCACHED_MEMORY_ALLOCATION_FAILURE; + + virtual_bucket->size= buckets; + virtual_bucket->replicas= replicas; + self->virtual_bucket= virtual_bucket; + + for (uint32_t x=0; x < buckets; x++) + { + virtual_bucket->buckets[x].master= host_map[x]; + if (forward_map) + { + virtual_bucket->buckets[x].forward= forward_map[x]; + } + else + { + virtual_bucket->buckets[x].forward= 0; + } + } + + + return MEMCACHED_SUCCESS; +} + +void memcached_virtual_bucket_free(memcached_st *self) +{ + if (! self) + return; + + if (! self->virtual_bucket) + return; + + free(self->virtual_bucket); + self->virtual_bucket= NULL; +} + +uint32_t memcached_virtual_bucket_get(const memcached_st *self, uint32_t digest) +{ + if (! self) + return 0; + + if (! self->virtual_bucket) + return 0; + + if (self->virtual_bucket) + { + uint32_t result= (uint32_t) (digest & (self->virtual_bucket->size -1)); + return self->virtual_bucket->buckets[result].master; + } + + return (uint32_t) (digest & (self->number_of_hosts -1)); +} diff --git a/libmemcached/virtual_bucket.h b/libmemcached/virtual_bucket.h new file mode 100644 index 00000000..e1c38536 --- /dev/null +++ b/libmemcached/virtual_bucket.h @@ -0,0 +1,59 @@ +/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: + * + * Libmemcached library + * + * Copyright (C) 2011 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. + * + */ + +#pragma once + +#ifdef __cplusplus +extern "C" { +#endif + +LIBMEMCACHED_LOCAL +memcached_return_t memcached_virtual_bucket_create(memcached_st *self, + const uint32_t *host_map, + const uint32_t *forward_map, + const uint32_t buckets, + const uint32_t replicas); + +LIBMEMCACHED_LOCAL +uint32_t memcached_virtual_bucket_get(const memcached_st *self, uint32_t digest); + +LIBMEMCACHED_LOCAL +void memcached_virtual_bucket_free(memcached_st *self); + +#ifdef __cplusplus +} +#endif diff --git a/libtest/failed.cc b/libtest/failed.cc new file mode 100644 index 00000000..df022467 --- /dev/null +++ b/libtest/failed.cc @@ -0,0 +1,75 @@ +/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: + * + * uTest Framework + * + * Copyright (C) 2011 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. + * + */ + +#include + +#include + +#include +#include +#include + +struct failed_test_names_st +{ + failed_test_names_st(const char *collection_arg, const char *test_arg) : + collection(collection_arg), + test(test_arg) + { + } + + std::string collection; + std::string test; +}; + +typedef std::vector Failures; + +static Failures failures; + +void push_failed_test(const char *collection, const char *test) +{ + failures.push_back(failed_test_names_st(collection, test)); +} + +void print_failed_test(void) +{ + for (Failures::iterator iter= failures.begin(); iter != failures.end(); iter++) + { + std::cerr << "\t" << (*iter).collection << " " << (*iter).test << std::endl; + } + std::cerr << std::endl; +} + diff --git a/libtest/failed.h b/libtest/failed.h new file mode 100644 index 00000000..16d1aecc --- /dev/null +++ b/libtest/failed.h @@ -0,0 +1,53 @@ +/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: + * + * uTest Framework + * + * Copyright (C) 2011 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. + * + */ + +#pragma once +#include + +#ifdef __cplusplus +extern "C" { +#endif + +LIBTEST_INTERNAL_API + void push_failed_test(const char *collection, const char *test); + +LIBTEST_INTERNAL_API + void print_failed_test(void); + +#ifdef __cplusplus +} +#endif diff --git a/libtest/include.am b/libtest/include.am index d6d9b18a..f14d9435 100644 --- a/libtest/include.am +++ b/libtest/include.am @@ -9,12 +9,17 @@ # All paths should be given relative to the root noinst_HEADERS+= \ + libtest/failed.h \ libtest/server.h \ - libtest/test.h + libtest/test.h \ + libtest/visibility.h noinst_LTLIBRARIES+= libtest/libserver.la libtest_libserver_la_SOURCES= libtest/server.c noinst_LTLIBRARIES+= libtest/libtest.la -libtest_libtest_la_SOURCES= libtest/test.c +libtest_libtest_la_SOURCES=\ + libtest/test.c +libtest_libtest_la_CFLAGS= ${AM_CFLAGS} ${NO_CONVERSION} +libtest_libtest_la_CPPFLAGS= ${AM_CPPFLAGS} diff --git a/libtest/server.c b/libtest/server.c index 4349a668..c96ffb51 100644 --- a/libtest/server.c +++ b/libtest/server.c @@ -47,7 +47,7 @@ static void global_sleep(void) static void kill_file(const char *file_buffer) { - FILE *fp= fopen(file_buffer, "r"); + FILE *fp; while ((fp= fopen(file_buffer, "r"))) { diff --git a/libtest/test.c b/libtest/test.c index 3d11d208..da989b17 100644 --- a/libtest/test.c +++ b/libtest/test.c @@ -27,6 +27,7 @@ #include #include +#include static void world_stats_print(world_stats_st *stats) { @@ -298,6 +299,9 @@ skip_pre: stats.success++; break; case TEST_FAILURE: +#if 0 + push_failed_test(next->name, run->name); +#endif stats.failed++; failed= true; break; @@ -343,6 +347,9 @@ cleanup: if (stats.collection_failed || stats.collection_skipped) { fprintf(stderr, "Some test failures and/or skipped test occurred.\n\n"); +#if 0 + print_failed_test(); +#endif } else { diff --git a/libtest/test.h b/libtest/test.h index cc0fd78a..b7a2f5ee 100644 --- a/libtest/test.h +++ b/libtest/test.h @@ -1,19 +1,49 @@ -/* uTest - * Copyright (C) 2006-2009 Brian Aker - * All rights reserved. +/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: + * + * Gearmand client and server library. + * + * Copyright (C) 2011 Data Differential, http://datadifferential.com/ + * Copyright (C) 2006-2010 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. * - * Use and distribution licensed under the BSD license. See - * the COPYING file in the parent directory for full text. */ +#pragma once + +#include + /* Structures for generic tests. */ -#ifdef __cplusplus -extern "C" { -#endif - #include #include #include @@ -39,9 +69,6 @@ typedef test_return_t (*test_callback_fn)(void *); typedef test_return_t (*test_callback_runner_fn)(test_callback_fn, void *); typedef test_return_t (*test_callback_error_fn)(test_return_t, void *); -/* Help function for use with gettimeofday() */ -long int timedif(struct timeval a, struct timeval b); - /** A structure describing the test case. */ @@ -139,14 +166,25 @@ typedef struct { uint32_t total; } world_stats_st; +#ifdef __cplusplus +extern "C" { +#endif + +/* Help function for use with gettimeofday() */ +LIBTEST_API +long int timedif(struct timeval a, struct timeval b); + /* How we make all of this work :) */ +LIBTEST_API void get_world(world_st *world); +LIBTEST_INTERNAL_API void create_core(void); /** @note Friendly print function for errors. */ +LIBTEST_API const char *test_strerror(test_return_t code); #define test_fail(A) \ @@ -189,6 +227,16 @@ do \ } \ } while (0) +#define test_false_with(A,B) \ +do \ +{ \ + if ((A)) { \ + fprintf(stderr, "\nAssertion failed at %s:%d: %s with %s\n", __FILE__, __LINE__, #A, (B));\ + create_core(); \ + return TEST_FAILURE; \ + } \ +} while (0) + #define test_strcmp(A,B) \ do \ { \ @@ -200,6 +248,23 @@ do \ } \ } while (0) + +#define STRINGIFY(x) #x +#define TOSTRING(x) STRINGIFY(x) +#define AT __FILE__ ":" TOSTRING(__LINE__) + +#ifdef __cplusplus +#define STRING_WITH_LEN(X) (X), (static_cast((sizeof(X) - 1))) +#else +#define STRING_WITH_LEN(X) (X), ((size_t)((sizeof(X) - 1))) +#endif + +#ifdef __cplusplus +#define STRING_PARAM_WITH_LEN(X) X, static_cast(sizeof(X) - 1) +#else +#define STRING_PARAM_WITH_LEN(X) X, (size_t)((sizeof(X) - 1)) +#endif + #ifdef __cplusplus } #endif diff --git a/libtest/visibility.h b/libtest/visibility.h new file mode 100644 index 00000000..73d01f18 --- /dev/null +++ b/libtest/visibility.h @@ -0,0 +1,69 @@ +/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: + * + * Gearmand client and server library. + * + * Copyright (C) 2011 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. + * + */ + +#pragma once + +#if defined(BUILDING_LIBTEST) +# if defined(HAVE_VISIBILITY) +# define LIBTEST_API __attribute__ ((visibility("default"))) +# define LIBTEST_INTERNAL_API __attribute__ ((visibility("hidden"))) +# define LIBTEST_API_DEPRECATED __attribute__ ((deprecated,visibility("default"))) +# define LIBTEST_LOCAL __attribute__ ((visibility("hidden"))) +# elif defined (__SUNPRO_C) && (__SUNPRO_C >= 0x550) +# define LIBTEST_API __global +# define LIBTEST_INTERNAL_API __hidden +# define LIBTEST_API_DEPRECATED __global +# define LIBTEST_LOCAL __hidden +# elif defined(_MSC_VER) +# define LIBTEST_API extern __declspec(dllexport) +# define LIBTEST_INTERNAL_API extern __declspec(dllexport) +# define LIBTEST_DEPRECATED_API extern __declspec(dllexport) +# define LIBTEST_LOCAL +# endif /* defined(HAVE_VISIBILITY) */ +#else /* defined(BUILDING_LIBTEST) */ +# if defined(_MSC_VER) +# define LIBTEST_API extern __declspec(dllimport) +# define LIBTEST_INTERNAL_API extern __declspec(dllimport) +# define LIBTEST_API_DEPRECATED extern __declspec(dllimport) +# define LIBTEST_LOCAL +# else +# define LIBTEST_API +# define LIBTEST_INTERNAL_API +# define LIBTEST_API_DEPRECATED +# define LIBTEST_LOCAL +# endif /* defined(_MSC_VER) */ +#endif /* defined(BUILDING_LIBTEST) */ diff --git a/m4/pandora_warnings.m4 b/m4/pandora_warnings.m4 index 30ff3434..7ef435ff 100644 --- a/m4/pandora_warnings.m4 +++ b/m4/pandora_warnings.m4 @@ -129,7 +129,7 @@ AC_DEFUN([PANDORA_WARNINGS],[ m4_if(PW_LESS_WARNINGS,[no],[ BASE_WARNINGS_FULL="${W_CONVERSION} -Wstrict-aliasing" CC_WARNINGS_FULL="-Wswitch-default -Wswitch-enum -Wwrite-strings" - CXX_WARNINGS_FULL="-Weffc++ -Wold-style-cast" + CXX_WARNINGS_FULL="" NO_OLD_STYLE_CAST="-Wno-old-style-cast" NO_EFF_CXX="-Wno-effc++" ],[ diff --git a/m4/socket_send_flags.m4 b/m4/socket_send_flags.m4 index 8251980d..290bc4a2 100644 --- a/m4/socket_send_flags.m4 +++ b/m4/socket_send_flags.m4 @@ -38,10 +38,27 @@ int flags= MSG_DONTWAIT; AC_LANG_POP ]) + AC_CACHE_CHECK([for MSG_MORE], [ac_cv_msg_more], [ + AC_LANG_PUSH([C]) + save_CFLAGS="$CFLAGS" + CFLAGS="$CFLAGS -I${srcdir}" + AC_TRY_LINK([ +#include + ], [ +int flags= MSG_MORE; + ], + [ ac_cv_msg_more=yes ], + [ ac_cv_msg_more=no ]) + CFLAGS="$save_CFLAGS" + AC_LANG_POP + ]) + AS_IF([test "x$ac_cv_msg_nosignal" = "xyes"],[ AC_DEFINE(HAVE_MSG_NOSIGNAL, 1, [Define to 1 if you have a MSG_NOSIGNAL])]) AS_IF([test "x$ac_cv_msg_dontwait" = "xyes"],[ AC_DEFINE(HAVE_MSG_DONTWAIT, 1, [Define to 1 if you have a MSG_DONTWAIT])]) + AS_IF([test "x$ac_cv_msg_more" = "xyes"],[ + AC_DEFINE(HAVE_MSG_MORE, 1, [Define to 1 if you have a HAVE_MSG_MORE])]) ]) dnl --------------------------------------------------------------------------- diff --git a/support/example.cnf b/support/example.cnf new file mode 100644 index 00000000..3ccb796f --- /dev/null +++ b/support/example.cnf @@ -0,0 +1,11 @@ +# http://en.wikipedia.org/wiki/Consistent_hashing +--distribution=consistent + +# Store one additional copy on each node. +--number-of-replicas=2 +--prefix-key="my_foo" +--prefix-key="my_prefix" +--server=localhost:11211 +--server=localhost:11212 +--server=localhost:11213 +--verify-key diff --git a/support/libmemcached.spec.in b/support/libmemcached.spec.in index ee9f20f9..98f21a31 100644 --- a/support/libmemcached.spec.in +++ b/support/libmemcached.spec.in @@ -82,11 +82,11 @@ you will need to install %{name}-devel. %exclude %{_libdir}/libhashkit.la %exclude %{_libdir}/libmemcachedutil.la %exclude %{_libdir}/libmemcachedprotocol.la -%{_libdir}/libhashkit.so.0.0.0 +%{_libdir}/libhashkit.so.1.0.0 %{_libdir}/libmemcached.so.6.0.0 %{_libdir}/libmemcachedutil.so.1.0.0 %{_libdir}/libmemcachedprotocol.so.0.0.0 -%{_libdir}/libhashkit.so.0 +%{_libdir}/libhashkit.so.1 %{_libdir}/libmemcached.so.6 %{_libdir}/libmemcachedprotocol.so.0 %{_libdir}/libmemcachedutil.so.1 @@ -104,10 +104,6 @@ you will need to install %{name}-devel. %files devel %defattr (-,root,root,-) %doc examples -%{_includedir}/libmemcached/allocators.h -%{_includedir}/libmemcached/delete.h -%{_includedir}/libmemcached/fetch.h -%{_includedir}/libmemcached/flush.h %{_includedir}/libhashkit/algorithm.h %{_includedir}/libhashkit/behavior.h %{_includedir}/libhashkit/configure.h @@ -117,22 +113,31 @@ you will need to install %{name}-devel. %{_includedir}/libhashkit/strerror.h %{_includedir}/libhashkit/types.h %{_includedir}/libhashkit/visibility.h +%{_includedir}/libmemcached/allocators.h %{_includedir}/libmemcached/analyze.h +%{_includedir}/libmemcached/array.h %{_includedir}/libmemcached/auto.h %{_includedir}/libmemcached/behavior.h %{_includedir}/libmemcached/callback.h %{_includedir}/libmemcached/configure.h %{_includedir}/libmemcached/constants.h +%{_includedir}/libmemcached/delete.h %{_includedir}/libmemcached/dump.h +%{_includedir}/libmemcached/error.h %{_includedir}/libmemcached/exception.hpp +%{_includedir}/libmemcached/fetch.h +%{_includedir}/libmemcached/flush.h %{_includedir}/libmemcached/flush_buffers.h %{_includedir}/libmemcached/get.h %{_includedir}/libmemcached/hash.h %{_includedir}/libmemcached/memcached.h %{_includedir}/libmemcached/memcached.hpp +%{_includedir}/libmemcached/memcached/protocol_binary.h %{_includedir}/libmemcached/memcached_util.h +%{_includedir}/libmemcached/options.h %{_includedir}/libmemcached/parse.h %{_includedir}/libmemcached/platform.h +%{_includedir}/libmemcached/prefix_key.h %{_includedir}/libmemcached/protocol/cache.h %{_includedir}/libmemcached/protocol/callback.h %{_includedir}/libmemcached/protocol_handler.h @@ -154,7 +159,6 @@ you will need to install %{name}-devel. %{_includedir}/libmemcached/version.h %{_includedir}/libmemcached/visibility.h %{_includedir}/libmemcached/watchpoint.h -%{_includedir}/libmemcached/memcached/protocol_binary.h %{_libdir}/libhashkit.so %{_libdir}/libmemcached.so %{_libdir}/libmemcachedprotocol.so diff --git a/tests/basic.cc b/tests/basic.cc new file mode 100644 index 00000000..fea343d5 --- /dev/null +++ b/tests/basic.cc @@ -0,0 +1,130 @@ +/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: + * + * Libmemcached + * + * Copyright (C) 2011 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. + * + */ + +#include +#include +#include +#include "tests/basic.h" + +test_return_t basic_init_test(memcached_st *junk) +{ + (void)junk; + + memcached_st memc; + memcached_st *memc_ptr; + + memc_ptr= memcached_create(&memc); + test_true(memc_ptr); + test_false(memcached_is_allocated(&memc)); + memcached_free(memc_ptr); + + return TEST_SUCCESS; +} + +test_return_t basic_clone_test(memcached_st *memc) +{ + memcached_st *memc_ptr; + + memc_ptr= memcached_clone(NULL, memc); + test_true(memc_ptr); + test_true(memcached_is_allocated(memc_ptr)); + memcached_free(memc_ptr); + + return TEST_SUCCESS; +} + +test_return_t basic_reset_stack_test(memcached_st *junk) +{ + (void)junk; + memcached_st memc; + + memcached_create(&memc); + + memcached_reset(&memc); + test_false(memcached_is_allocated(&memc)); + + memcached_free(&memc); + test_false(memcached_is_allocated(&memc)); + + return TEST_SUCCESS; +} + +test_return_t basic_reset_heap_test(memcached_st *junk) +{ + (void)junk; + memcached_st *memc_ptr; + + memc_ptr= memcached_create(NULL); + test_true(memcached_is_allocated(memc_ptr)); + + memcached_reset(memc_ptr); + test_true(memcached_is_allocated(memc_ptr)); + + memcached_free(memc_ptr); + + return TEST_SUCCESS; +} + +test_return_t basic_reset_stack_clone_test(memcached_st *memc) +{ + memcached_st clone; + memcached_st *memc_ptr; + + memset(&clone, 0, sizeof(clone)); + memc_ptr= memcached_clone(&clone, memc); + test_true(memc_ptr); + + memcached_reset(memc_ptr); + + memcached_free(memc_ptr); + + return TEST_SUCCESS; +} + +test_return_t basic_reset_heap_clone_test(memcached_st *memc) +{ + memcached_st *memc_ptr; + + memc_ptr= memcached_clone(NULL, memc); + test_true(memc_ptr); + + memcached_reset(memc_ptr); + + memcached_free(memc_ptr); + + return TEST_SUCCESS; +} diff --git a/tests/basic.h b/tests/basic.h new file mode 100644 index 00000000..7c1536ef --- /dev/null +++ b/tests/basic.h @@ -0,0 +1,66 @@ +/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: + * + * Libmemcached + * + * Copyright (C) 2011 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. + * + */ + +#pragma once + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +LIBTEST_INTERNAL_API +test_return_t basic_init_test(memcached_st *junk); + +LIBTEST_INTERNAL_API +test_return_t basic_clone_test(memcached_st *memc); + +LIBTEST_INTERNAL_API +test_return_t basic_reset_stack_test(memcached_st *junk); + +LIBTEST_INTERNAL_API +test_return_t basic_reset_heap_test(memcached_st *junk); + +LIBTEST_INTERNAL_API +test_return_t basic_reset_stack_clone_test(memcached_st *memc); + +LIBTEST_INTERNAL_API +test_return_t basic_reset_heap_clone_test(memcached_st *memc); + +#ifdef __cplusplus +} +#endif diff --git a/tests/error_conditions.cc b/tests/error_conditions.cc new file mode 100644 index 00000000..d06f4225 --- /dev/null +++ b/tests/error_conditions.cc @@ -0,0 +1,72 @@ +/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: + * + * Libmemcached + * + * Copyright (C) 2011 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. + * + */ + +#include + +#define BUILDING_LIBMEMCACHED + +#include +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +test_return_t memcached_increment_MEMCACHED_NO_SERVERS(memcached_st *junk) +{ + (void)junk; + memcached_st *memc_ptr; + + memc_ptr= memcached_create(NULL); + test_true(memc_ptr); + + memcached_increment(memc_ptr, memcached_string_with_size("dead key"), 1, NULL); + test_true(memcached_last_error(memc_ptr) == MEMCACHED_NO_SERVERS); + + memcached_increment(memc_ptr, memcached_string_with_size("dead key"), 1, NULL); + test_true(memcached_last_error(memc_ptr) == MEMCACHED_NO_SERVERS); + + memcached_free(memc_ptr); + + return TEST_SUCCESS; +} + +#ifdef __cplusplus +} +#endif diff --git a/tests/error_conditions.h b/tests/error_conditions.h new file mode 100644 index 00000000..1bfa9ed2 --- /dev/null +++ b/tests/error_conditions.h @@ -0,0 +1,50 @@ +/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: + * + * Libmemcached + * + * Copyright (C) 2011 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. + * + */ + +#pragma once + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +test_return_t memcached_increment_MEMCACHED_NO_SERVERS(memcached_st *junk); + +#ifdef __cplusplus +} +#endif diff --git a/tests/hashkit_functions.c b/tests/hashkit_functions.c index 0f2c42a9..23feb9e5 100644 --- a/tests/hashkit_functions.c +++ b/tests/hashkit_functions.c @@ -345,10 +345,10 @@ static test_return_t hashkit_set_function_test(hashkit_st *hashk) continue; #endif - if (rc == HASHKIT_FAILURE && algo == HASHKIT_HASH_CUSTOM) + if (rc == HASHKIT_INVALID_ARGUMENT && algo == HASHKIT_HASH_CUSTOM) continue; - test_true(rc == HASHKIT_SUCCESS); + test_true_got(rc == HASHKIT_SUCCESS, hashkit_strerror(NULL, rc)); switch (algo) { @@ -448,7 +448,7 @@ static test_return_t hashkit_set_distribution_function_test(hashkit_st *hashk) if (rc == HASHKIT_FAILURE && algo == HASHKIT_HASH_HSIEH) continue; - if (rc == HASHKIT_FAILURE && algo == HASHKIT_HASH_CUSTOM) + if (rc == HASHKIT_INVALID_ARGUMENT && algo == HASHKIT_HASH_CUSTOM) continue; test_true(rc == HASHKIT_SUCCESS); diff --git a/tests/include.am b/tests/include.am index f940caf8..490ed023 100644 --- a/tests/include.am +++ b/tests/include.am @@ -28,10 +28,18 @@ EXTRA_DIST+= \ tests/output_plus.res noinst_HEADERS+= \ + tests/basic.h \ + tests/error_conditions.h \ tests/hash_results.h \ tests/ketama_test_cases.h \ tests/ketama_test_cases_spy.h \ - tests/libmemcached_world.h + tests/libmemcached_world.h \ + tests/parser.h \ + tests/print.h \ + tests/replication.h \ + tests/string.h \ + tests/virtual_buckets.h + noinst_PROGRAMS+= \ tests/atomsmasher \ @@ -44,7 +52,16 @@ noinst_PROGRAMS+= \ tests/testudp tests_testapp_CFLAGS= $(AM_CFLAGS) $(NO_CONVERSION) $(NO_STRICT_ALIASING) -tests_testapp_SOURCES= tests/mem_functions.c +tests_testapp_SOURCES= \ + tests/basic.cc \ + tests/error_conditions.cc \ + tests/mem_functions.c \ + tests/parser.cc \ + tests/print.cc \ + tests/replication.cc \ + tests/string.cc \ + tests/virtual_buckets.cc + tests_testapp_DEPENDENCIES= \ $(BUILT_SOURCES) \ clients/libgenexec.la \ @@ -231,7 +248,7 @@ UDP_COMMAND= tests/testudp $(COLLECTION) $(SUITE) HASH_COMMAND= tests/testhashkit $(COLLECTION) $(SUITE) -test-mem: tests/testapp +test-mem: tests/testapp support/example.cnf $(MEM_COMMAND) test-udp: tests/testudp diff --git a/tests/mem_functions.c b/tests/mem_functions.c index c46ef51a..e3f6426a 100644 --- a/tests/mem_functions.c +++ b/tests/mem_functions.c @@ -34,6 +34,13 @@ #define SMALL_STRING_LEN 1024 #include +#include "tests/parser.h" +#include "tests/string.h" +#include "tests/replication.h" +#include "tests/basic.h" +#include "tests/error_conditions.h" +#include "tests/print.h" +#include "tests/virtual_buckets.h" #ifdef HAVE_LIBMEMCACHEDUTIL @@ -189,21 +196,6 @@ static test_return_t server_sort2_test(memcached_st *ptr) return TEST_SUCCESS; } -static memcached_return_t server_print_callback(const memcached_st *ptr, - const memcached_server_st *server, - void *context) -{ - (void)server; // Just in case we aren't printing. - (void)ptr; - (void)context; - -#if 0 - fprintf(stderr, "%s(%d)", memcached_server_name(server), memcached_server_port(server)); -#endif - - return MEMCACHED_SUCCESS; -} - static test_return_t memcached_server_remove_test(memcached_st *ptr) { memcached_return_t rc; @@ -218,6 +210,7 @@ static test_return_t memcached_server_remove_test(memcached_st *ptr) memc= memcached_create(&local_memc); servers= memcached_servers_parse(server_string); + assert(servers); rc= memcached_server_push(memc, servers); memcached_server_list_free(servers); @@ -327,7 +320,7 @@ static test_return_t clone_test(memcached_st *memc) test_true(memc_clone->flags.buffer_requests == memc->flags.buffer_requests); test_true(memc_clone->flags.use_sort_hosts == memc->flags.use_sort_hosts); test_true(memc_clone->flags.verify_key == memc->flags.verify_key); - test_true(memc_clone->flags.ketama_weighted == memc->flags.ketama_weighted); + test_true(memc_clone->ketama.weighted == memc->ketama.weighted); test_true(memc_clone->flags.binary_protocol == memc->flags.binary_protocol); test_true(memc_clone->flags.hash_with_prefix_key == memc->flags.hash_with_prefix_key); test_true(memc_clone->flags.no_reply == memc->flags.no_reply); @@ -411,10 +404,10 @@ static test_return_t error_test(memcached_st *memc) 2300930706U, 2943759320U, 674306647U, 2400528935U, 54481931U, 4186304426U, 1741088401U, 2979625118U, 4159057246U, 3425930182U, 2593724503U, 1868899624U, - 1769812374U, 2302537950U, 1110330676U }; + 1769812374U, 2302537950U, 1110330676U, 3365377466U, + 1336171666U, 3365377466U }; // You have updated the memcache_error messages but not updated docs/tests. - test_true(MEMCACHED_MAXIMUM_RETURN == 43); for (rc= MEMCACHED_SUCCESS; rc < MEMCACHED_MAXIMUM_RETURN; rc++) { uint32_t hash_val; @@ -428,6 +421,7 @@ static test_return_t error_test(memcached_st *memc) } test_true(values[rc] == hash_val); } + test_true(MEMCACHED_MAXIMUM_RETURN == 45); return TEST_SUCCESS; } @@ -854,7 +848,7 @@ static test_return_t bad_key_test(memcached_st *memc) rc= memcached_callback_set(memc_clone, MEMCACHED_CALLBACK_PREFIX_KEY, NULL); test_true(rc == MEMCACHED_SUCCESS); - char *longkey= malloc(max_keylen + 1); + char *longkey= (char *)malloc(max_keylen + 1); if (longkey != NULL) { memset(longkey, 'a', max_keylen + 1); @@ -2952,7 +2946,7 @@ static test_return_t user_supplied_bug18(memcached_st *trash) /* VDEAAAAA hashes to fffcd1b5, after the last continuum point, and lets * us test the boundary wraparound. */ - test_true(memcached_generate_hash(memc, (char *)"VDEAAAAA", 8) == memc->continuum[0].index); + test_true(memcached_generate_hash(memc, (char *)"VDEAAAAA", 8) == memc->ketama.continuum[0].index); /* verify the standard ketama set. */ for (x= 0; x < 99; x++) @@ -3113,7 +3107,7 @@ static test_return_t auto_eject_hosts(memcached_st *trash) instance= memcached_server_instance_by_position(memc, 2); ((memcached_server_write_instance_st)instance)->next_retry = time(NULL) + 15; - memc->next_distribution_rebuild= time(NULL) - 1; + memc->ketama.next_distribution_rebuild= time(NULL) - 1; /* This would not work if there were only two hosts. @@ -3127,7 +3121,7 @@ static test_return_t auto_eject_hosts(memcached_st *trash) /* and re-added when it's back. */ ((memcached_server_write_instance_st)instance)->next_retry = time(NULL) - 1; - memc->next_distribution_rebuild= time(NULL) - 1; + memc->ketama.next_distribution_rebuild= time(NULL) - 1; memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_DISTRIBUTION, memc->distribution); for (size_t x= 0; x < 99; x++) @@ -3238,118 +3232,6 @@ static test_return_t result_alloc(memcached_st *memc) return TEST_SUCCESS; } -static test_return_t string_static_null(memcached_st *memc) -{ - memcached_string_st string; - memcached_string_st *string_ptr; - - string_ptr= memcached_string_create(memc, &string, 0); - test_true(string.options.is_initialized == true); - test_true(string_ptr); - - /* The following two better be the same! */ - test_true(memcached_is_allocated(string_ptr) == false); - test_true(memcached_is_allocated(&string) == false); - test_true(&string == string_ptr); - - test_true(string.options.is_initialized == true); - test_true(memcached_is_initialized(&string) == true); - memcached_string_free(&string); - test_true(memcached_is_initialized(&string) == false); - - return TEST_SUCCESS; -} - -static test_return_t string_alloc_null(memcached_st *memc) -{ - memcached_string_st *string; - - string= memcached_string_create(memc, NULL, 0); - test_true(string); - test_true(memcached_is_allocated(string) == true); - test_true(memcached_is_initialized(string) == true); - memcached_string_free(string); - - return TEST_SUCCESS; -} - -static test_return_t string_alloc_with_size(memcached_st *memc) -{ - memcached_string_st *string; - - string= memcached_string_create(memc, NULL, 1024); - test_true(string); - test_true(memcached_is_allocated(string) == true); - test_true(memcached_is_initialized(string) == true); - memcached_string_free(string); - - return TEST_SUCCESS; -} - -static test_return_t string_alloc_with_size_toobig(memcached_st *memc) -{ - memcached_string_st *string; - - string= memcached_string_create(memc, NULL, SIZE_MAX); - test_true(string == NULL); - - return TEST_SUCCESS; -} - -static test_return_t string_alloc_append(memcached_st *memc) -{ - unsigned int x; - char buffer[SMALL_STRING_LEN]; - memcached_string_st *string; - - /* Ring the bell! */ - memset(buffer, 6, SMALL_STRING_LEN); - - string= memcached_string_create(memc, NULL, 100); - test_true(string); - test_true(memcached_is_allocated(string) == true); - test_true(memcached_is_initialized(string) == true); - - for (x= 0; x < 1024; x++) - { - memcached_return_t rc; - rc= memcached_string_append(string, buffer, SMALL_STRING_LEN); - test_true(rc == MEMCACHED_SUCCESS); - } - test_true(memcached_is_allocated(string) == true); - memcached_string_free(string); - - return TEST_SUCCESS; -} - -static test_return_t string_alloc_append_toobig(memcached_st *memc) -{ - memcached_return_t rc; - unsigned int x; - char buffer[SMALL_STRING_LEN]; - memcached_string_st *string; - - /* Ring the bell! */ - memset(buffer, 6, SMALL_STRING_LEN); - - string= memcached_string_create(memc, NULL, 100); - test_true(string); - test_true(memcached_is_allocated(string) == true); - test_true(memcached_is_initialized(string) == true); - - for (x= 0; x < 1024; x++) - { - rc= memcached_string_append(string, buffer, SMALL_STRING_LEN); - test_true(rc == MEMCACHED_SUCCESS); - } - rc= memcached_string_append(string, buffer, SIZE_MAX); - test_true(rc == MEMCACHED_MEMORY_ALLOCATION_FAILURE); - test_true(memcached_is_allocated(string) == true); - memcached_string_free(string); - - return TEST_SUCCESS; -} - static test_return_t cleanup_pairs(memcached_st *memc) { (void)memc; @@ -3966,9 +3848,10 @@ static test_return_t set_prefix(memcached_st *memc) /* Test a clean set */ rc= memcached_callback_set(memc, MEMCACHED_CALLBACK_PREFIX_KEY, (void *)key); - test_true(rc == MEMCACHED_SUCCESS); + test_true_got(rc == MEMCACHED_SUCCESS, memcached_last_error_message(memc)); value= memcached_callback_get(memc, MEMCACHED_CALLBACK_PREFIX_KEY, &rc); + test_true(value); test_true(memcmp(value, key, 4) == 0); test_true(rc == MEMCACHED_SUCCESS); @@ -3977,6 +3860,7 @@ static test_return_t set_prefix(memcached_st *memc) test_true(rc == MEMCACHED_SUCCESS); value= memcached_callback_get(memc, MEMCACHED_CALLBACK_PREFIX_KEY, &rc); + test_false(value); test_true(rc == MEMCACHED_FAILURE); /* Now setup for main test */ @@ -3984,6 +3868,7 @@ static test_return_t set_prefix(memcached_st *memc) test_true(rc == MEMCACHED_SUCCESS); value= memcached_callback_get(memc, MEMCACHED_CALLBACK_PREFIX_KEY, &rc); + test_true(value); test_true(rc == MEMCACHED_SUCCESS); test_true(memcmp(value, key, 4) == 0); @@ -3996,6 +3881,7 @@ static test_return_t set_prefix(memcached_st *memc) test_true(rc == MEMCACHED_SUCCESS); value= memcached_callback_get(memc, MEMCACHED_CALLBACK_PREFIX_KEY, &rc); + test_false(value); test_true(rc == MEMCACHED_FAILURE); test_true(value == NULL); @@ -4574,259 +4460,6 @@ static test_return_t ping_test(memcached_st *memc) } #endif -static test_return_t replication_set_test(memcached_st *memc) -{ - memcached_return_t rc; - memcached_st *memc_clone= memcached_clone(NULL, memc); - memcached_behavior_set(memc_clone, MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS, 0); - - rc= memcached_set(memc, "bubba", 5, "0", 1, 0, 0); - test_true(rc == MEMCACHED_SUCCESS); - - /* - ** We are using the quiet commands to store the replicas, so we need - ** to ensure that all of them are processed before we can continue. - ** In the test we go directly from storing the object to trying to - ** receive the object from all of the different servers, so we - ** could end up in a race condition (the memcached server hasn't yet - ** processed the quiet command from the replication set when it process - ** the request from the other client (created by the clone)). As a - ** workaround for that we call memcached_quit to send the quit command - ** to the server and wait for the response ;-) If you use the test code - ** as an example for your own code, please note that you shouldn't need - ** to do this ;-) - */ - memcached_quit(memc); - - /* - ** "bubba" should now be stored on all of our servers. We don't have an - ** easy to use API to address each individual server, so I'll just iterate - ** through a bunch of "master keys" and I should most likely hit all of the - ** servers... - */ - for (int x= 'a'; x <= 'z'; ++x) - { - char key[2]= { [0]= (char)x }; - size_t len; - uint32_t flags; - char *val= memcached_get_by_key(memc_clone, key, 1, "bubba", 5, - &len, &flags, &rc); - test_true(rc == MEMCACHED_SUCCESS); - test_true(val != NULL); - free(val); - } - - memcached_free(memc_clone); - - return TEST_SUCCESS; -} - -static test_return_t replication_get_test(memcached_st *memc) -{ - memcached_return_t rc; - - /* - * Don't do the following in your code. I am abusing the internal details - * within the library, and this is not a supported interface. - * This is to verify correct behavior in the library - */ - for (uint32_t host= 0; host < memcached_server_count(memc); ++host) - { - memcached_st *memc_clone= memcached_clone(NULL, memc); - memcached_server_instance_st instance= - memcached_server_instance_by_position(memc_clone, host); - - ((memcached_server_write_instance_st)instance)->port= 0; - - for (int x= 'a'; x <= 'z'; ++x) - { - char key[2]= { [0]= (char)x }; - size_t len; - uint32_t flags; - char *val= memcached_get_by_key(memc_clone, key, 1, "bubba", 5, - &len, &flags, &rc); - test_true(rc == MEMCACHED_SUCCESS); - test_true(val != NULL); - free(val); - } - - memcached_free(memc_clone); - } - - return TEST_SUCCESS; -} - -static test_return_t replication_mget_test(memcached_st *memc) -{ - memcached_return_t rc; - memcached_st *memc_clone= memcached_clone(NULL, memc); - memcached_behavior_set(memc_clone, MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS, 0); - - const char *keys[]= { "bubba", "key1", "key2", "key3" }; - size_t len[]= { 5, 4, 4, 4 }; - - for (size_t x= 0; x< 4; ++x) - { - rc= memcached_set(memc, keys[x], len[x], "0", 1, 0, 0); - test_true(rc == MEMCACHED_SUCCESS); - } - - /* - ** We are using the quiet commands to store the replicas, so we need - ** to ensure that all of them are processed before we can continue. - ** In the test we go directly from storing the object to trying to - ** receive the object from all of the different servers, so we - ** could end up in a race condition (the memcached server hasn't yet - ** processed the quiet command from the replication set when it process - ** the request from the other client (created by the clone)). As a - ** workaround for that we call memcached_quit to send the quit command - ** to the server and wait for the response ;-) If you use the test code - ** as an example for your own code, please note that you shouldn't need - ** to do this ;-) - */ - memcached_quit(memc); - - /* - * Don't do the following in your code. I am abusing the internal details - * within the library, and this is not a supported interface. - * This is to verify correct behavior in the library - */ - memcached_result_st result_obj; - for (uint32_t host= 0; host < memc_clone->number_of_hosts; host++) - { - memcached_st *new_clone= memcached_clone(NULL, memc); - memcached_server_instance_st instance= - memcached_server_instance_by_position(new_clone, host); - ((memcached_server_write_instance_st)instance)->port= 0; - - for (int x= 'a'; x <= 'z'; ++x) - { - char key[2]= { [0]= (char)x, [1]= 0 }; - - rc= memcached_mget_by_key(new_clone, key, 1, keys, len, 4); - test_true(rc == MEMCACHED_SUCCESS); - - memcached_result_st *results= memcached_result_create(new_clone, &result_obj); - test_true(results); - - int hits= 0; - while ((results= memcached_fetch_result(new_clone, &result_obj, &rc)) != NULL) - { - hits++; - } - test_true(hits == 4); - memcached_result_free(&result_obj); - } - - memcached_free(new_clone); - } - - memcached_free(memc_clone); - - return TEST_SUCCESS; -} - -static test_return_t replication_randomize_mget_test(memcached_st *memc) -{ - memcached_result_st result_obj; - memcached_return_t rc; - memcached_st *memc_clone= memcached_clone(NULL, memc); - memcached_behavior_set(memc_clone, MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS, 3); - memcached_behavior_set(memc_clone, MEMCACHED_BEHAVIOR_RANDOMIZE_REPLICA_READ, 1); - - const char *keys[]= { "key1", "key2", "key3", "key4", "key5", "key6", "key7" }; - size_t len[]= { 4, 4, 4, 4, 4, 4, 4 }; - - for (size_t x= 0; x< 7; ++x) - { - rc= memcached_set(memc, keys[x], len[x], "1", 1, 0, 0); - test_true(rc == MEMCACHED_SUCCESS); - } - - memcached_quit(memc); - - for (size_t x= 0; x< 7; ++x) - { - const char key[2]= { [0]= (const char)x }; - - rc= memcached_mget_by_key(memc_clone, key, 1, keys, len, 7); - test_true(rc == MEMCACHED_SUCCESS); - - memcached_result_st *results= memcached_result_create(memc_clone, &result_obj); - test_true(results); - - int hits= 0; - while ((results= memcached_fetch_result(memc_clone, &result_obj, &rc)) != NULL) - { - ++hits; - } - test_true(hits == 7); - memcached_result_free(&result_obj); - } - memcached_free(memc_clone); - return TEST_SUCCESS; -} - -static test_return_t replication_delete_test(memcached_st *memc) -{ - memcached_return_t rc; - memcached_st *memc_clone= memcached_clone(NULL, memc); - /* Delete the items from all of the servers except 1 */ - uint64_t repl= memcached_behavior_get(memc, - MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS); - memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS, --repl); - - const char *keys[]= { "bubba", "key1", "key2", "key3" }; - size_t len[]= { 5, 4, 4, 4 }; - - for (size_t x= 0; x< 4; ++x) - { - rc= memcached_delete_by_key(memc, keys[0], len[0], keys[x], len[x], 0); - test_true(rc == MEMCACHED_SUCCESS); - } - - /* - * Don't do the following in your code. I am abusing the internal details - * within the library, and this is not a supported interface. - * This is to verify correct behavior in the library - */ - uint32_t hash= memcached_generate_hash(memc, keys[0], len[0]); - for (uint32_t x= 0; x < (repl + 1); ++x) - { - memcached_server_instance_st instance= - memcached_server_instance_by_position(memc_clone, x); - - ((memcached_server_write_instance_st)instance)->port= 0; - if (++hash == memc_clone->number_of_hosts) - hash= 0; - } - - memcached_result_st result_obj; - for (uint32_t host= 0; host < memc_clone->number_of_hosts; ++host) - { - for (size_t x= 'a'; x <= 'z'; ++x) - { - const char key[2]= { [0]= (const char)x }; - - rc= memcached_mget_by_key(memc_clone, key, 1, keys, len, 4); - test_true(rc == MEMCACHED_SUCCESS); - - memcached_result_st *results= memcached_result_create(memc_clone, &result_obj); - test_true(results); - - int hits= 0; - while ((results= memcached_fetch_result(memc_clone, &result_obj, &rc)) != NULL) - { - ++hits; - } - test_true(hits == 4); - memcached_result_free(&result_obj); - } - } - memcached_free(memc_clone); - - return TEST_SUCCESS; -} #if 0 static test_return_t hash_sanity_test (memcached_st *memc) @@ -4853,7 +4486,7 @@ static test_return_t hash_sanity_test (memcached_st *memc) static test_return_t hsieh_avaibility_test (memcached_st *memc) { - memcached_return_t expected_rc= MEMCACHED_FAILURE; + memcached_return_t expected_rc= MEMCACHED_INVALID_ARGUMENTS; #ifdef HAVE_HSIEH_HASH expected_rc= MEMCACHED_SUCCESS; #endif @@ -4866,7 +4499,7 @@ static test_return_t hsieh_avaibility_test (memcached_st *memc) static test_return_t murmur_avaibility_test (memcached_st *memc) { - memcached_return_t expected_rc= MEMCACHED_FAILURE; + memcached_return_t expected_rc= MEMCACHED_INVALID_ARGUMENTS; #ifdef HAVE_MURMUR_HASH expected_rc= MEMCACHED_SUCCESS; #endif @@ -5289,7 +4922,7 @@ static test_return_t ketama_compatibility_libmemcached(memcached_st *trash) /* VDEAAAAA hashes to fffcd1b5, after the last continuum point, and lets * us test the boundary wraparound. */ - test_true(memcached_generate_hash(memc, (char *)"VDEAAAAA", 8) == memc->continuum[0].index); + test_true(memcached_generate_hash(memc, (char *)"VDEAAAAA", 8) == memc->ketama.continuum[0].index); /* verify the standard ketama set. */ for (x= 0; x < 99; x++) @@ -5312,7 +4945,6 @@ static test_return_t ketama_compatibility_spymemcached(memcached_st *trash) { memcached_return_t rc; uint64_t value; - int x; memcached_server_st *server_pool; memcached_st *memc; @@ -5331,6 +4963,7 @@ static test_return_t ketama_compatibility_spymemcached(memcached_st *trash) test_true(memcached_behavior_get_distribution(memc) == MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA_SPY); server_pool = memcached_servers_parse("10.0.1.1:11211 600,10.0.1.2:11211 300,10.0.1.3:11211 200,10.0.1.4:11211 350,10.0.1.5:11211 1000,10.0.1.6:11211 800,10.0.1.7:11211 950,10.0.1.8:11211 100"); + assert(server_pool); memcached_server_push(memc, server_pool); /* verify that the server list was parsed okay. */ @@ -5348,10 +4981,10 @@ static test_return_t ketama_compatibility_spymemcached(memcached_st *trash) /* VDEAAAAA hashes to fffcd1b5, after the last continuum point, and lets * us test the boundary wraparound. */ - test_true(memcached_generate_hash(memc, (char *)"VDEAAAAA", 8) == memc->continuum[0].index); + test_true(memcached_generate_hash(memc, (char *)"VDEAAAAA", 8) == memc->ketama.continuum[0].index); /* verify the standard ketama set. */ - for (x= 0; x < 99; x++) + for (uint32_t x= 0; x < 99; x++) { uint32_t server_idx= memcached_generate_hash(memc, ketama_test_cases_spy[x].key, strlen(ketama_test_cases_spy[x].key)); @@ -5984,6 +5617,7 @@ static test_return_t wrong_failure_counter_two_test(memcached_st *memc) test_true_got(rc == MEMCACHED_SUCCESS, memcached_strerror(NULL, rc)); test_true(string); free(string); + memcached_free(memc_clone); return TEST_SUCCESS; } @@ -6118,7 +5752,7 @@ static test_return_t regression_bug_583031(memcached_st *unused) (void)memcached_get(memc, "dsf", 3, &length, &flags, &rc); - test_true_got(rc == MEMCACHED_TIMEOUT, memcached_strerror(NULL, rc)); + test_true_got(rc == MEMCACHED_TIMEOUT || rc == MEMCACHED_ERRNO, memcached_strerror(memc, rc)); memcached_free(memc); @@ -6130,6 +5764,7 @@ static test_return_t regression_bug_728286(memcached_st *unused) { (void)unused; memcached_server_st *servers = memcached_servers_parse("1.2.3.4:99"); + assert(servers); memcached_server_free(servers); return TEST_SUCCESS; @@ -6368,6 +6003,16 @@ test_st behavior_tests[] ={ {0, 0, 0} }; +test_st basic_tests[] ={ + {"init", 1, (test_callback_fn)basic_init_test}, + {"clone", 1, (test_callback_fn)basic_clone_test}, + {"reset", 1, (test_callback_fn)basic_reset_stack_test}, + {"reset heap", 1, (test_callback_fn)basic_reset_heap_test}, + {"reset stack clone", 1, (test_callback_fn)basic_reset_stack_clone_test}, + {"reset heap clone", 1, (test_callback_fn)basic_reset_heap_clone_test}, + {0, 0, 0} +}; + test_st regression_binary_vs_block[] ={ {"block add", 1, (test_callback_fn)block_add_regression}, {"binary add", 1, (test_callback_fn)binary_add_regression}, @@ -6386,6 +6031,7 @@ test_st string_tests[] ={ {"string alloc with malloc failure", 0, (test_callback_fn)string_alloc_with_size_toobig }, {"string append", 0, (test_callback_fn)string_alloc_append }, {"string append failure (too big)", 0, (test_callback_fn)string_alloc_append_toobig }, + {"string_alloc_append_multiple", 0, (test_callback_fn)string_alloc_append_multiple }, {0, 0, (test_callback_fn)0} }; @@ -6556,10 +6202,35 @@ test_st hash_tests[] ={ }; test_st error_conditions[] ={ - {"memcached_get_MEMCACHED_ERRNO", 0, (test_callback_fn)memcached_get_MEMCACHED_ERRNO }, - {"memcached_get_MEMCACHED_NOTFOUND", 0, (test_callback_fn)memcached_get_MEMCACHED_NOTFOUND }, - {"memcached_get_by_key_MEMCACHED_ERRNO", 0, (test_callback_fn)memcached_get_by_key_MEMCACHED_ERRNO }, - {"memcached_get_by_key_MEMCACHED_NOTFOUND", 0, (test_callback_fn)memcached_get_by_key_MEMCACHED_NOTFOUND }, + {"memcached_get(MEMCACHED_ERRNO)", 0, (test_callback_fn)memcached_get_MEMCACHED_ERRNO }, + {"memcached_get(MEMCACHED_NOTFOUND)", 0, (test_callback_fn)memcached_get_MEMCACHED_NOTFOUND }, + {"memcached_get_by_key(MEMCACHED_ERRNO)", 0, (test_callback_fn)memcached_get_by_key_MEMCACHED_ERRNO }, + {"memcached_get_by_key(MEMCACHED_NOTFOUND)", 0, (test_callback_fn)memcached_get_by_key_MEMCACHED_NOTFOUND }, + {"memcached_get_by_key(MEMCACHED_NOTFOUND)", 0, (test_callback_fn)memcached_get_by_key_MEMCACHED_NOTFOUND }, + {"memcached_increment(MEMCACHED_NO_SERVERS)", 0, (test_callback_fn)memcached_increment_MEMCACHED_NO_SERVERS }, + {0, 0, (test_callback_fn)0} +}; + + +test_st parser_tests[] ={ + {"behavior", 0, (test_callback_fn)behavior_parser_test }, + {"boolean_options", 0, (test_callback_fn)parser_boolean_options_test }, + {"configure_file", 0, (test_callback_fn)memcached_create_with_options_with_filename }, + {"distribtions", 0, (test_callback_fn)parser_distribution_test }, + {"hash", 0, (test_callback_fn)parser_hash_test }, + {"libmemcached_check_configuration", 0, (test_callback_fn)libmemcached_check_configuration_test }, + {"libmemcached_check_configuration_with_filename", 0, (test_callback_fn)libmemcached_check_configuration_with_filename_test }, + {"memcached_parse_configure_file", 0, (test_callback_fn)memcached_parse_configure_file_test }, + {"number_options", 0, (test_callback_fn)parser_number_options_test }, + {"randomly generated options", 0, (test_callback_fn)random_statement_build_test }, + {"prefix_key", 0, (test_callback_fn)parser_key_prefix_test }, + {"server", 0, (test_callback_fn)server_test }, + {"servers", 0, (test_callback_fn)servers_test }, + {0, 0, (test_callback_fn)0} +}; + +test_st virtual_bucket_tests[] ={ + {"basic", 0, (test_callback_fn)virtual_back_map }, {0, 0, (test_callback_fn)0} }; @@ -6567,6 +6238,7 @@ collection_st collection[] ={ #if 0 {"hash_sanity", 0, 0, hash_sanity}, #endif + {"basic", 0, 0, basic_tests}, {"hsieh_availability", 0, 0, hsieh_availability}, {"murmur_availability", 0, 0, murmur_availability}, {"block", 0, 0, tests}, @@ -6625,6 +6297,8 @@ collection_st collection[] ={ {"behaviors", 0, 0, behavior_tests}, {"regression_binary_vs_block", (test_callback_fn)key_setup, (test_callback_fn)key_teardown, regression_binary_vs_block}, {"error_conditions", 0, 0, error_conditions}, + {"parser", 0, 0, parser_tests}, + {"virtual buckets", 0, 0, virtual_bucket_tests}, {0, 0, 0, 0} }; diff --git a/tests/parser.cc b/tests/parser.cc new file mode 100644 index 00000000..61d846c9 --- /dev/null +++ b/tests/parser.cc @@ -0,0 +1,535 @@ +/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: + * + * Libmemcached Client and Server + * + * Copyright (C) 2011 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. + * + */ + +#include + +#include +#include +#include + +#define BUILDING_LIBMEMCACHED +#include + +#include "tests/parser.h" +#include "tests/print.h" + +enum scanner_type_t +{ + NIL, + UNSIGNED, + SIGNED, + ARRAY +}; + + +struct scanner_string_st { + const char *c_str; + size_t size; +}; + +static inline scanner_string_st scanner_string(const char *arg, size_t arg_size) +{ + scanner_string_st local= { arg, arg_size }; + return local; +} + +#define make_scanner_string(X) scanner_string((X), static_cast(sizeof(X) - 1)) + +static struct scanner_string_st scanner_string_null= { 0, 0}; + +struct scanner_variable_t { + enum scanner_type_t type; + struct scanner_string_st option; + struct scanner_string_st result; + test_return_t (*check_func)(memcached_st *memc, const scanner_string_st &hostname); +}; + +// Check and make sure the first host is what we expect it to be +static test_return_t __check_host(memcached_st *memc, const scanner_string_st &hostname) +{ + memcached_server_instance_st instance= + memcached_server_instance_by_position(memc, 0); + + test_true(instance); + + const char *first_hostname = memcached_server_name(instance); + test_true(first_hostname); + test_strcmp(first_hostname, hostname.c_str); + + return TEST_SUCCESS; +} + +// Check and make sure the prefix_key is what we expect it to be +static test_return_t __check_prefix_key(memcached_st *memc, const scanner_string_st &hostname) +{ + memcached_server_instance_st instance= + memcached_server_instance_by_position(memc, 0); + + test_true(instance); + + const char *first_hostname = memcached_server_name(instance); + test_true(first_hostname); + test_strcmp(first_hostname, hostname.c_str); + + return TEST_SUCCESS; +} + +static test_return_t __check_IO_MSG_WATERMARK(memcached_st *memc, const scanner_string_st &value) +{ + uint64_t value_number; + + value_number= atoll(value.c_str); + + test_true(memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_IO_MSG_WATERMARK) == value_number); + return TEST_SUCCESS; +} + +static test_return_t __check_AUTO_EJECT_HOSTS(memcached_st *memc, const scanner_string_st &value) +{ + (void)value; + test_true(memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_AUTO_EJECT_HOSTS)); + return TEST_SUCCESS; +} + +static test_return_t __check_CACHE_LOOKUPS(memcached_st *memc, const scanner_string_st &value) +{ + (void)value; + test_true(memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_CACHE_LOOKUPS)); + return TEST_SUCCESS; +} + +static test_return_t __check_NOREPLY(memcached_st *memc, const scanner_string_st &value) +{ + (void)value; + test_true(memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_NOREPLY)); + return TEST_SUCCESS; +} + +static test_return_t __check_VERIFY_KEY(memcached_st *memc, const scanner_string_st &value) +{ + (void)value; + test_true(memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_VERIFY_KEY)); + return TEST_SUCCESS; +} + +static test_return_t __check_distribution_RANDOM(memcached_st *memc, const scanner_string_st &value) +{ + (void)value; + test_true(memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_DISTRIBUTION) == MEMCACHED_DISTRIBUTION_RANDOM); + return TEST_SUCCESS; +} + +scanner_variable_t test_server_strings[]= { + { ARRAY, make_scanner_string("--server=localhost"), make_scanner_string("localhost"), __check_host }, + { ARRAY, make_scanner_string("--server=10.0.2.1"), make_scanner_string("10.0.2.1"), __check_host }, + { ARRAY, make_scanner_string("--server=example.com"), make_scanner_string("example.com"), __check_host }, + { ARRAY, make_scanner_string("--server=localhost:30"), make_scanner_string("localhost"), __check_host }, + { ARRAY, make_scanner_string("--server=10.0.2.1:20"), make_scanner_string("10.0.2.1"), __check_host }, + { ARRAY, make_scanner_string("--server=example.com:1024"), make_scanner_string("example.com"), __check_host }, + { NIL, scanner_string_null, scanner_string_null, NULL } +}; + +scanner_variable_t test_servers_strings[]= { + { ARRAY, make_scanner_string("--servers=localhost:11221,localhost:11222,localhost:11223,localhost:11224,localhost:11225"), scanner_string_null, NULL }, + { ARRAY, make_scanner_string("--servers=a.example.com:81,localhost:82,b.example.com"), scanner_string_null, NULL }, + { ARRAY, make_scanner_string("--servers=localhost,localhost:80"), scanner_string_null, NULL }, + { NIL, scanner_string_null, scanner_string_null, NULL} +}; + + +scanner_variable_t bad_test_strings[]= { + { ARRAY, make_scanner_string("-servers=localhost:11221,localhost:11222,localhost:11223,localhost:11224,localhost:11225"), scanner_string_null, NULL }, + { ARRAY, make_scanner_string("-- servers=a.example.com:81,localhost:82,b.example.com"), scanner_string_null, NULL }, + { ARRAY, make_scanner_string("--servers=localhost+80"), scanner_string_null, NULL}, + { ARRAY, make_scanner_string("--servers=localhost.com."), scanner_string_null, NULL}, + { ARRAY, make_scanner_string("--server=localhost.com."), scanner_string_null, NULL}, + { ARRAY, make_scanner_string("--server=localhost.com.:80"), scanner_string_null, NULL}, + { NIL, scanner_string_null, scanner_string_null, NULL} +}; + +scanner_variable_t test_number_options[]= { + { ARRAY, make_scanner_string("--CONNECT_TIMEOUT=456"), scanner_string_null, NULL }, + { ARRAY, make_scanner_string("--IO_MSG_WATERMARK=456"), make_scanner_string("456"), __check_IO_MSG_WATERMARK }, + { ARRAY, make_scanner_string("--IO_BYTES_WATERMARK=456"), scanner_string_null, NULL }, + { ARRAY, make_scanner_string("--IO_KEY_PREFETCH=456"), scanner_string_null, NULL }, + { ARRAY, make_scanner_string("--NUMBER_OF_REPLICAS=456"), scanner_string_null, NULL }, + { ARRAY, make_scanner_string("--POLL_TIMEOUT=456"), scanner_string_null, NULL }, + { ARRAY, make_scanner_string("--RCV_TIMEOUT=456"), scanner_string_null, NULL }, + { ARRAY, make_scanner_string("--RETRY_TIMEOUT=456"), scanner_string_null, NULL }, + { ARRAY, make_scanner_string("--SERVER_FAILURE_LIMIT=456"), scanner_string_null, NULL }, + { ARRAY, make_scanner_string("--SND_TIMEOUT=456"), scanner_string_null, NULL }, + { ARRAY, make_scanner_string("--SOCKET_RECV_SIZE=456"), scanner_string_null, NULL }, + { ARRAY, make_scanner_string("--SOCKET_SEND_SIZE=456"), scanner_string_null, NULL }, + { NIL, scanner_string_null, scanner_string_null, NULL} +}; + +scanner_variable_t test_boolean_options[]= { + { ARRAY, make_scanner_string("--AUTO_EJECT_HOSTS"), scanner_string_null, __check_AUTO_EJECT_HOSTS }, + { ARRAY, make_scanner_string("--BINARY_PROTOCOL"), scanner_string_null, NULL }, + { ARRAY, make_scanner_string("--BUFFER_REQUESTS"), scanner_string_null, NULL }, + { ARRAY, make_scanner_string("--CACHE_LOOKUPS"), scanner_string_null, __check_CACHE_LOOKUPS }, + { ARRAY, make_scanner_string("--HASH_WITH_PREFIX_KEY"), scanner_string_null, NULL }, + { ARRAY, make_scanner_string("--KETAMA_WEIGHTED"), scanner_string_null, NULL }, + { ARRAY, make_scanner_string("--NOREPLY"), scanner_string_null, __check_NOREPLY }, + { ARRAY, make_scanner_string("--RANDOMIZE_REPLICA_READ"), scanner_string_null, NULL }, + { ARRAY, make_scanner_string("--SORT_HOSTS"), scanner_string_null, NULL }, + { ARRAY, make_scanner_string("--SUPPORT_CAS"), scanner_string_null, NULL }, + { ARRAY, make_scanner_string("--TCP_NODELAY"), scanner_string_null, NULL }, + { ARRAY, make_scanner_string("--TCP_KEEPALIVE"), scanner_string_null, NULL }, + { ARRAY, make_scanner_string("--TCP_KEEPIDLE"), scanner_string_null, NULL }, + { ARRAY, make_scanner_string("--USE_UDP"), scanner_string_null, NULL }, + { ARRAY, make_scanner_string("--VERIFY_KEY"), scanner_string_null, __check_VERIFY_KEY }, + { NIL, scanner_string_null, scanner_string_null, NULL} +}; + +scanner_variable_t prefix_key_strings[]= { + { ARRAY, make_scanner_string("--PREFIX_KEY=foo"), make_scanner_string("foo"), __check_prefix_key }, + { ARRAY, make_scanner_string("--PREFIX-KEY=\"foo\""), make_scanner_string("foo"), __check_prefix_key }, + { ARRAY, make_scanner_string("--PREFIX-KEY=\"This is a very long key\""), make_scanner_string("This is a very long key"), __check_prefix_key }, + { NIL, scanner_string_null, scanner_string_null, NULL} +}; + +scanner_variable_t distribution_strings[]= { + { ARRAY, make_scanner_string("--DISTRIBUTION=consistent"), scanner_string_null, NULL }, + { ARRAY, make_scanner_string("--DISTRIBUTION=consistent,CRC"), scanner_string_null, NULL }, + { ARRAY, make_scanner_string("--DISTRIBUTION=consistent,MD5"), scanner_string_null, NULL }, + { ARRAY, make_scanner_string("--DISTRIBUTION=random"), scanner_string_null, __check_distribution_RANDOM }, + { ARRAY, make_scanner_string("--DISTRIBUTION=modula"), scanner_string_null, NULL }, + { NIL, scanner_string_null, scanner_string_null, NULL} +}; + +scanner_variable_t hash_strings[]= { + { ARRAY, make_scanner_string("--HASH=CRC"), scanner_string_null, NULL }, + { ARRAY, make_scanner_string("--HASH=FNV1A_32"), scanner_string_null, NULL }, + { ARRAY, make_scanner_string("--HASH=FNV1A_64"), scanner_string_null, NULL }, + { ARRAY, make_scanner_string("--HASH=FNV1_32"), scanner_string_null, NULL }, + { ARRAY, make_scanner_string("--HASH=FNV1_64"), scanner_string_null, NULL }, + { ARRAY, make_scanner_string("--HASH=JENKINS"), scanner_string_null, NULL }, + { ARRAY, make_scanner_string("--HASH=MD5"), scanner_string_null, NULL }, + { ARRAY, make_scanner_string("--HASH=MURMUR"), scanner_string_null, NULL }, + { NIL, scanner_string_null, scanner_string_null, NULL} +}; + + +static test_return_t _test_option(scanner_variable_t *scanner, bool test_true= true) +{ + (void)test_true; + memcached_st *memc; + memc= memcached_create(NULL); + + for (scanner_variable_t *ptr= scanner; ptr->type != NIL; ptr++) + { + memcached_return_t rc; + rc= memcached_parse_configuration(memc, ptr->option.c_str, ptr->option.size); + if (test_true) + { + if (rc != MEMCACHED_SUCCESS) + memcached_error_print(memc); + + test_true(rc == MEMCACHED_SUCCESS); + + if (ptr->check_func) + { + (*ptr->check_func)(memc, ptr->result); + } + } + else + { + test_false_with(rc == MEMCACHED_SUCCESS, ptr->option.c_str); + } + memcached_reset(memc); + } + memcached_free(memc); + + return TEST_SUCCESS; +} + +test_return_t server_test(memcached_st *junk) +{ + (void)junk; + return _test_option(test_server_strings); +} + +test_return_t servers_test(memcached_st *junk) +{ + (void)junk; + + test_return_t rc; + if ((rc= _test_option(test_server_strings)) != TEST_SUCCESS) + { + return rc; + } + +#if 0 + memcached_server_fn callbacks[1]; + callbacks[0]= server_print_callback; + memcached_server_cursor(memc, callbacks, NULL, 1); +#endif + + if ((rc= _test_option(bad_test_strings, false)) != TEST_SUCCESS) + { + return rc; + } + + return TEST_SUCCESS; +} + +test_return_t parser_number_options_test(memcached_st *junk) +{ + (void)junk; + return _test_option(test_number_options); +} + +test_return_t parser_boolean_options_test(memcached_st *junk) +{ + (void)junk; + return _test_option(test_boolean_options); +} + +test_return_t behavior_parser_test(memcached_st *junk) +{ + (void)junk; + return TEST_SUCCESS; +} + +test_return_t parser_hash_test(memcached_st *junk) +{ + (void)junk; + return _test_option(hash_strings); +} + +test_return_t parser_distribution_test(memcached_st *junk) +{ + (void)junk; + return _test_option(distribution_strings); +} + +test_return_t parser_key_prefix_test(memcached_st *junk) +{ + (void)junk; + return _test_option(distribution_strings); +} + +#define SUPPORT_EXAMPLE_CNF "support/example.cnf" + +test_return_t memcached_parse_configure_file_test(memcached_st *junk) +{ + (void)junk; + + if (access(SUPPORT_EXAMPLE_CNF, R_OK)) + return TEST_SKIPPED; + + memcached_st memc; + memcached_st *memc_ptr= memcached_create(&memc); + + test_true(memc_ptr); + + memcached_return_t rc= memcached_parse_configure_file(memc_ptr, memcached_string_with_size(SUPPORT_EXAMPLE_CNF)); + test_true_got(rc == MEMCACHED_SUCCESS, memcached_last_error_message(memc_ptr) ? memcached_last_error_message(memc_ptr) : memcached_strerror(NULL, rc)); + memcached_free(memc_ptr); + + return TEST_SUCCESS; +} + +test_return_t memcached_create_with_options_with_filename(memcached_st *junk) +{ + (void)junk; + if (access(SUPPORT_EXAMPLE_CNF, R_OK)) + return TEST_SKIPPED; + + memcached_st *memc_ptr; + memc_ptr= memcached_create_with_options(STRING_WITH_LEN("--CONFIGURE-FILE=\"support/example.cnf\"")); + test_true_got(memc_ptr, memcached_last_error_message(memc_ptr)); + memcached_free(memc_ptr); + + return TEST_SUCCESS; +} + +test_return_t libmemcached_check_configuration_with_filename_test(memcached_st *junk) +{ + (void)junk; + + if (access(SUPPORT_EXAMPLE_CNF, R_OK)) + return TEST_SKIPPED; + + memcached_return_t rc; + char buffer[BUFSIZ]; + + rc= libmemcached_check_configuration(STRING_WITH_LEN("--CONFIGURE-FILE=\"support/example.cnf\""), buffer, sizeof(buffer)); + test_true_got(rc == MEMCACHED_SUCCESS, buffer); + + rc= libmemcached_check_configuration(STRING_WITH_LEN("--CONFIGURE-FILE=support/example.cnf"), buffer, sizeof(buffer)); + test_false_with(rc == MEMCACHED_SUCCESS, buffer); + + rc= libmemcached_check_configuration(STRING_WITH_LEN("--CONFIGURE-FILE=\"bad-path/example.cnf\""), buffer, sizeof(buffer)); + test_true_got(rc == MEMCACHED_ERRNO, buffer); + + return TEST_SUCCESS; +} + +test_return_t libmemcached_check_configuration_test(memcached_st *junk) +{ + (void)junk; + + memcached_return_t rc; + char buffer[BUFSIZ]; + + rc= libmemcached_check_configuration(STRING_WITH_LEN("--server=localhost"), buffer, sizeof(buffer)); + test_true_got(rc == MEMCACHED_SUCCESS, buffer); + + rc= libmemcached_check_configuration(STRING_WITH_LEN("--dude=localhost"), buffer, sizeof(buffer)); + test_false_with(rc == MEMCACHED_SUCCESS, buffer); + test_true(rc == MEMCACHED_PARSE_ERROR); + + return TEST_SUCCESS; +} + +test_return_t memcached_create_with_options_test(memcached_st *junk) +{ + (void)junk; + + memcached_st *memc_ptr; + memc_ptr= memcached_create_with_options(STRING_WITH_LEN("--server=localhost")); + test_true_got(memc_ptr, memcached_last_error_message(memc_ptr)); + memcached_free(memc_ptr); + + memc_ptr= memcached_create_with_options(STRING_WITH_LEN("--dude=localhost")); + test_false_with(memc_ptr, memcached_last_error_message(memc_ptr)); + + return TEST_SUCCESS; +} + +test_return_t test_include_keyword(memcached_st *junk) +{ + if (access(SUPPORT_EXAMPLE_CNF, R_OK)) + return TEST_SKIPPED; + + (void)junk; + char buffer[BUFSIZ]; + memcached_return_t rc; + rc= libmemcached_check_configuration(STRING_WITH_LEN("INCLUDE \"support/example.cnf\""), buffer, sizeof(buffer)); + test_true_got(rc == MEMCACHED_SUCCESS, buffer); + + return TEST_SUCCESS; +} + +test_return_t test_end_keyword(memcached_st *junk) +{ + (void)junk; + char buffer[BUFSIZ]; + memcached_return_t rc; + rc= libmemcached_check_configuration(STRING_WITH_LEN("--server=localhost END bad keywords"), buffer, sizeof(buffer)); + test_true_got(rc == MEMCACHED_SUCCESS, buffer); + + return TEST_SUCCESS; +} + +test_return_t test_reset_keyword(memcached_st *junk) +{ + (void)junk; + char buffer[BUFSIZ]; + memcached_return_t rc; + rc= libmemcached_check_configuration(STRING_WITH_LEN("--server=localhost reset --server=bad.com"), buffer, sizeof(buffer)); + test_true_got(rc == MEMCACHED_SUCCESS, buffer); + + return TEST_SUCCESS; +} + +test_return_t test_error_keyword(memcached_st *junk) +{ + (void)junk; + char buffer[BUFSIZ]; + memcached_return_t rc; + rc= libmemcached_check_configuration(STRING_WITH_LEN("--server=localhost ERROR --server=bad.com"), buffer, sizeof(buffer)); + test_true_got(rc != MEMCACHED_SUCCESS, buffer); + + return TEST_SUCCESS; +} + +#define RANDOM_STRINGS 50 +test_return_t random_statement_build_test(memcached_st *junk) +{ + (void)junk; + std::vector option_list; + + for (scanner_variable_t *ptr= test_server_strings; ptr->type != NIL; ptr++) + option_list.push_back(&ptr->option); + +#if 0 + for (scanner_variable_t *ptr= test_servers_strings; ptr->type != NIL; ptr++) + option_list.push_back(&ptr->option); +#endif + + for (scanner_variable_t *ptr= test_number_options; ptr->type != NIL; ptr++) + option_list.push_back(&ptr->option); + + for (scanner_variable_t *ptr= test_boolean_options; ptr->type != NIL; ptr++) + option_list.push_back(&ptr->option); + + for (scanner_variable_t *ptr= prefix_key_strings; ptr->type != NIL; ptr++) + option_list.push_back(&ptr->option); + + for (scanner_variable_t *ptr= distribution_strings; ptr->type != NIL; ptr++) + option_list.push_back(&ptr->option); + + for (scanner_variable_t *ptr= hash_strings; ptr->type != NIL; ptr++) + option_list.push_back(&ptr->option); + + for (uint32_t x= 0; x < RANDOM_STRINGS; x++) + { + std::string random_options; + + uint32_t number_of= random() % option_list.size(); + for (uint32_t options= 0; options < number_of; options++) + { + random_options+= option_list[random() % option_list.size()]->c_str; + random_options+= " "; + } + + memcached_return_t rc; + memcached_st *memc_ptr= memcached_create(NULL); + rc= memcached_parse_configuration(memc_ptr, random_options.c_str(), random_options.size() -1); + if (rc == MEMCACHED_PARSE_ERROR) + { + std::cerr << std::endl << "Failed to parse(" << memcached_strerror(NULL, rc) << "): " << random_options << std::endl; + memcached_error_print(memc_ptr); + } + memcached_free(memc_ptr); + } + + return TEST_SUCCESS; +} diff --git a/tests/parser.h b/tests/parser.h new file mode 100644 index 00000000..b21cdf70 --- /dev/null +++ b/tests/parser.h @@ -0,0 +1,102 @@ +/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: + * + * Gearmand client and server library. + * + * Copyright (C) 2011 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. + * + */ + +#pragma once + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +LIBTEST_INTERNAL_API +test_return_t server_test(memcached_st *memc); + +LIBTEST_INTERNAL_API +test_return_t servers_test(memcached_st *memc); + +LIBTEST_INTERNAL_API +test_return_t behavior_parser_test(memcached_st *junk); + +LIBTEST_INTERNAL_API +test_return_t parser_number_options_test(memcached_st *junk); + +LIBTEST_INTERNAL_API +test_return_t parser_distribution_test(memcached_st *junk); + +LIBTEST_INTERNAL_API +test_return_t parser_hash_test(memcached_st *junk); + +LIBTEST_INTERNAL_API +test_return_t parser_boolean_options_test(memcached_st *junk); + +LIBTEST_INTERNAL_API +test_return_t parser_key_prefix_test(memcached_st *junk); + +LIBTEST_INTERNAL_API +test_return_t memcached_parse_configure_file_test(memcached_st *junk); + +LIBTEST_INTERNAL_API + test_return_t libmemcached_check_configuration_test(memcached_st *junk); + +LIBTEST_INTERNAL_API + test_return_t memcached_create_with_options_test(memcached_st *junk); + +LIBTEST_INTERNAL_API + test_return_t memcached_create_with_options_with_filename(memcached_st *junk); + +LIBTEST_INTERNAL_API + test_return_t libmemcached_check_configuration_with_filename_test(memcached_st *junk); + +LIBTEST_INTERNAL_API + test_return_t random_statement_build_test(memcached_st *junk); + +LIBTEST_INTERNAL_API +test_return_t test_include_keyword(memcached_st *junk); + +LIBTEST_INTERNAL_API +test_return_t test_end_keyword(memcached_st *junk); + +LIBTEST_INTERNAL_API +test_return_t test_reset_keyword(memcached_st *junk); + +LIBTEST_INTERNAL_API +test_return_t test_error_keyword(memcached_st *junk); + +#ifdef __cplusplus +} +#endif diff --git a/tests/print.cc b/tests/print.cc new file mode 100644 index 00000000..570ab0f0 --- /dev/null +++ b/tests/print.cc @@ -0,0 +1,59 @@ +/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: + * + * Gearmand client and server library. + * + * Copyright (C) 2011 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. + * + */ + +#include + +#include + +#include +#include + +#include "tests/print.h" + +memcached_return_t server_print_callback(const memcached_st *ptr, + const memcached_server_st *server, + void *context) +{ + (void)ptr; + + if (context) + { + std::cerr << memcached_server_name(server) << ":" << memcached_server_port(server) << std::endl; + } + + return MEMCACHED_SUCCESS; +} diff --git a/tests/print.h b/tests/print.h new file mode 100644 index 00000000..efd148f6 --- /dev/null +++ b/tests/print.h @@ -0,0 +1,51 @@ +/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: + * + * Gearmand client and server library. + * + * Copyright (C) 2011 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. + * + */ + +#pragma once + +#ifdef __cplusplus +extern "C" { +#endif + +LIBTEST_INTERNAL_API +memcached_return_t server_print_callback(const memcached_st *ptr, + const memcached_server_st *server, + void *context); + +#ifdef __cplusplus +} +#endif diff --git a/tests/replication.cc b/tests/replication.cc new file mode 100644 index 00000000..3034c6a4 --- /dev/null +++ b/tests/replication.cc @@ -0,0 +1,296 @@ +/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: + * + * Gearmand client and server library. + * + * Copyright (C) 2011 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. + * + */ + +#include + +#include +#include "libmemcached/common.h" +#include + +test_return_t replication_set_test(memcached_st *memc) +{ + memcached_return_t rc; + memcached_st *memc_clone= memcached_clone(NULL, memc); + memcached_behavior_set(memc_clone, MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS, 0); + + rc= memcached_set(memc, "bubba", 5, "0", 1, 0, 0); + test_true(rc == MEMCACHED_SUCCESS); + + /* + ** We are using the quiet commands to store the replicas, so we need + ** to ensure that all of them are processed before we can continue. + ** In the test we go directly from storing the object to trying to + ** receive the object from all of the different servers, so we + ** could end up in a race condition (the memcached server hasn't yet + ** processed the quiet command from the replication set when it process + ** the request from the other client (created by the clone)). As a + ** workaround for that we call memcached_quit to send the quit command + ** to the server and wait for the response ;-) If you use the test code + ** as an example for your own code, please note that you shouldn't need + ** to do this ;-) + */ + memcached_quit(memc); + + /* + ** "bubba" should now be stored on all of our servers. We don't have an + ** easy to use API to address each individual server, so I'll just iterate + ** through a bunch of "master keys" and I should most likely hit all of the + ** servers... + */ + for (int x= 'a'; x <= 'z'; ++x) + { + const char key[2]= { (char)x, 0 }; + size_t len; + uint32_t flags; + char *val= memcached_get_by_key(memc_clone, key, 1, "bubba", 5, + &len, &flags, &rc); + test_true(rc == MEMCACHED_SUCCESS); + test_true(val != NULL); + free(val); + } + + memcached_free(memc_clone); + + return TEST_SUCCESS; +} + +test_return_t replication_get_test(memcached_st *memc) +{ + memcached_return_t rc; + + /* + * Don't do the following in your code. I am abusing the internal details + * within the library, and this is not a supported interface. + * This is to verify correct behavior in the library + */ + for (uint32_t host= 0; host < memcached_server_count(memc); ++host) + { + memcached_st *memc_clone= memcached_clone(NULL, memc); + memcached_server_instance_st instance= + memcached_server_instance_by_position(memc_clone, host); + + ((memcached_server_write_instance_st)instance)->port= 0; + + for (int x= 'a'; x <= 'z'; ++x) + { + const char key[2]= { (char)x, 0 }; + size_t len; + uint32_t flags; + char *val= memcached_get_by_key(memc_clone, key, 1, "bubba", 5, + &len, &flags, &rc); + test_true(rc == MEMCACHED_SUCCESS); + test_true(val != NULL); + free(val); + } + + memcached_free(memc_clone); + } + + return TEST_SUCCESS; +} + +test_return_t replication_mget_test(memcached_st *memc) +{ + memcached_return_t rc; + memcached_st *memc_clone= memcached_clone(NULL, memc); + memcached_behavior_set(memc_clone, MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS, 0); + + const char *keys[]= { "bubba", "key1", "key2", "key3" }; + size_t len[]= { 5, 4, 4, 4 }; + + for (size_t x= 0; x< 4; ++x) + { + rc= memcached_set(memc, keys[x], len[x], "0", 1, 0, 0); + test_true(rc == MEMCACHED_SUCCESS); + } + + /* + ** We are using the quiet commands to store the replicas, so we need + ** to ensure that all of them are processed before we can continue. + ** In the test we go directly from storing the object to trying to + ** receive the object from all of the different servers, so we + ** could end up in a race condition (the memcached server hasn't yet + ** processed the quiet command from the replication set when it process + ** the request from the other client (created by the clone)). As a + ** workaround for that we call memcached_quit to send the quit command + ** to the server and wait for the response ;-) If you use the test code + ** as an example for your own code, please note that you shouldn't need + ** to do this ;-) + */ + memcached_quit(memc); + + /* + * Don't do the following in your code. I am abusing the internal details + * within the library, and this is not a supported interface. + * This is to verify correct behavior in the library + */ + memcached_result_st result_obj; + for (uint32_t host= 0; host < memc_clone->number_of_hosts; host++) + { + memcached_st *new_clone= memcached_clone(NULL, memc); + memcached_server_instance_st instance= + memcached_server_instance_by_position(new_clone, host); + ((memcached_server_write_instance_st)instance)->port= 0; + + for (int x= 'a'; x <= 'z'; ++x) + { + char key[2]= { (char)x, 0 }; + + rc= memcached_mget_by_key(new_clone, key, 1, keys, len, 4); + test_true(rc == MEMCACHED_SUCCESS); + + memcached_result_st *results= memcached_result_create(new_clone, &result_obj); + test_true(results); + + int hits= 0; + while ((results= memcached_fetch_result(new_clone, &result_obj, &rc)) != NULL) + { + hits++; + } + test_true(hits == 4); + memcached_result_free(&result_obj); + } + + memcached_free(new_clone); + } + + memcached_free(memc_clone); + + return TEST_SUCCESS; +} + +test_return_t replication_randomize_mget_test(memcached_st *memc) +{ + memcached_result_st result_obj; + memcached_return_t rc; + memcached_st *memc_clone= memcached_clone(NULL, memc); + memcached_behavior_set(memc_clone, MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS, 3); + memcached_behavior_set(memc_clone, MEMCACHED_BEHAVIOR_RANDOMIZE_REPLICA_READ, 1); + + const char *keys[]= { "key1", "key2", "key3", "key4", "key5", "key6", "key7" }; + size_t len[]= { 4, 4, 4, 4, 4, 4, 4 }; + + for (size_t x= 0; x< 7; ++x) + { + rc= memcached_set(memc, keys[x], len[x], "1", 1, 0, 0); + test_true(rc == MEMCACHED_SUCCESS); + } + + memcached_quit(memc); + + for (size_t x= 0; x< 7; ++x) + { + const char key[2]= { (char)x, 0 }; + + rc= memcached_mget_by_key(memc_clone, key, 1, keys, len, 7); + test_true(rc == MEMCACHED_SUCCESS); + + memcached_result_st *results= memcached_result_create(memc_clone, &result_obj); + test_true(results); + + int hits= 0; + while ((results= memcached_fetch_result(memc_clone, &result_obj, &rc)) != NULL) + { + ++hits; + } + test_true(hits == 7); + memcached_result_free(&result_obj); + } + memcached_free(memc_clone); + return TEST_SUCCESS; +} + +test_return_t replication_delete_test(memcached_st *memc) +{ + memcached_return_t rc; + memcached_st *memc_clone= memcached_clone(NULL, memc); + /* Delete the items from all of the servers except 1 */ + uint64_t repl= memcached_behavior_get(memc, + MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS); + memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS, --repl); + + const char *keys[]= { "bubba", "key1", "key2", "key3" }; + size_t len[]= { 5, 4, 4, 4 }; + + for (size_t x= 0; x< 4; ++x) + { + rc= memcached_delete_by_key(memc, keys[0], len[0], keys[x], len[x], 0); + test_true(rc == MEMCACHED_SUCCESS); + } + + /* + * Don't do the following in your code. I am abusing the internal details + * within the library, and this is not a supported interface. + * This is to verify correct behavior in the library + */ + uint32_t hash= memcached_generate_hash(memc, keys[0], len[0]); + for (uint32_t x= 0; x < (repl + 1); ++x) + { + memcached_server_instance_st instance= + memcached_server_instance_by_position(memc_clone, x); + + ((memcached_server_write_instance_st)instance)->port= 0; + if (++hash == memc_clone->number_of_hosts) + hash= 0; + } + + memcached_result_st result_obj; + for (uint32_t host= 0; host < memc_clone->number_of_hosts; ++host) + { + for (size_t x= 'a'; x <= 'z'; ++x) + { + const char key[2]= { (char)x, 0 }; + + rc= memcached_mget_by_key(memc_clone, key, 1, keys, len, 4); + test_true(rc == MEMCACHED_SUCCESS); + + memcached_result_st *results= memcached_result_create(memc_clone, &result_obj); + test_true(results); + + int hits= 0; + while ((results= memcached_fetch_result(memc_clone, &result_obj, &rc)) != NULL) + { + ++hits; + } + test_true(hits == 4); + memcached_result_free(&result_obj); + } + } + memcached_free(memc_clone); + + return TEST_SUCCESS; +} diff --git a/tests/replication.h b/tests/replication.h new file mode 100644 index 00000000..d7eba14a --- /dev/null +++ b/tests/replication.h @@ -0,0 +1,61 @@ +/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: + * + * Gearmand client and server library. + * + * Copyright (C) 2011 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. + * + */ + +#pragma once + +#ifdef __cplusplus +extern "C" { +#endif + +LIBTEST_INTERNAL_API +test_return_t replication_set_test(memcached_st *memc); + +LIBTEST_INTERNAL_API +test_return_t replication_get_test(memcached_st *memc); + +LIBTEST_INTERNAL_API +test_return_t replication_mget_test(memcached_st *memc); + +LIBTEST_INTERNAL_API +test_return_t replication_delete_test(memcached_st *memc); + +LIBTEST_INTERNAL_API +test_return_t replication_randomize_mget_test(memcached_st *memc); + +#ifdef __cplusplus +} +#endif diff --git a/tests/string.cc b/tests/string.cc new file mode 100644 index 00000000..827d0f2c --- /dev/null +++ b/tests/string.cc @@ -0,0 +1,168 @@ +/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: + * + * Gearmand client and server library. + * + * Copyright (C) 2011 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. + * + */ + +#include "libmemcached/common.h" +#include "libmemcached/error.h" +#include "tests/string.h" + +test_return_t string_static_null(memcached_st *memc) +{ + memcached_string_st string; + memcached_string_st *string_ptr; + + string_ptr= memcached_string_create(memc, &string, 0); + test_true(string.options.is_initialized == true); + test_true(string_ptr); + + /* The following two better be the same! */ + test_true(memcached_is_allocated(string_ptr) == false); + test_true(memcached_is_allocated(&string) == false); + test_true(&string == string_ptr); + + test_true(string.options.is_initialized == true); + test_true(memcached_is_initialized(&string) == true); + memcached_string_free(&string); + test_true(memcached_is_initialized(&string) == false); + + return TEST_SUCCESS; +} + +test_return_t string_alloc_null(memcached_st *memc) +{ + memcached_string_st *string; + + string= memcached_string_create(memc, NULL, 0); + test_true(string); + test_true(memcached_is_allocated(string) == true); + test_true(memcached_is_initialized(string) == true); + memcached_string_free(string); + + return TEST_SUCCESS; +} + +test_return_t string_alloc_with_size(memcached_st *memc) +{ + memcached_string_st *string; + + string= memcached_string_create(memc, NULL, 1024); + test_true(string); + test_true(memcached_is_allocated(string) == true); + test_true(memcached_is_initialized(string) == true); + memcached_string_free(string); + + return TEST_SUCCESS; +} + +test_return_t string_alloc_with_size_toobig(memcached_st *memc) +{ + memcached_string_st *string; + + string= memcached_string_create(memc, NULL, SIZE_MAX); + test_true(string == NULL); + + return TEST_SUCCESS; +} + +test_return_t string_alloc_append(memcached_st *memc) +{ + unsigned int x; + char buffer[SMALL_STRING_LEN]; + memcached_string_st *string; + + /* Ring the bell! */ + memset(buffer, 6, SMALL_STRING_LEN); + + string= memcached_string_create(memc, NULL, 100); + test_true(string); + test_true(memcached_is_allocated(string) == true); + test_true(memcached_is_initialized(string) == true); + + for (x= 0; x < 1024; x++) + { + memcached_return_t rc; + rc= memcached_string_append(string, buffer, SMALL_STRING_LEN); + test_true(rc == MEMCACHED_SUCCESS); + } + test_true(memcached_is_allocated(string) == true); + memcached_string_free(string); + + return TEST_SUCCESS; +} + +test_return_t string_alloc_append_toobig(memcached_st *memc) +{ + memcached_return_t rc; + char buffer[SMALL_STRING_LEN]; + memcached_string_st *string; + + /* Ring the bell! */ + memset(buffer, 6, sizeof(buffer)); + + string= memcached_string_create(memc, NULL, 100); + test_true(string); + test_true(memcached_is_allocated(string) == true); + test_true(memcached_is_initialized(string) == true); + + for (unsigned int x= 0; x < 1024; x++) + { + rc= memcached_string_append(string, buffer, SMALL_STRING_LEN); + test_true(rc == MEMCACHED_SUCCESS); + } + rc= memcached_string_append(string, buffer, SIZE_MAX); + test_true(rc == MEMCACHED_MEMORY_ALLOCATION_FAILURE); + test_true(memcached_is_allocated(string) == true); + memcached_string_free(string); + + return TEST_SUCCESS; +} + +test_return_t string_alloc_append_multiple(memcached_st *memc) +{ + memcached_string_st *error_string= memcached_string_create(memc, NULL, 1024); + memcached_string_append(error_string, memcached_string_with_size("Error occured while parsing: ")); + memcached_string_append(error_string, memcached_string_make_from_cstr("jog the strlen() method")); + memcached_string_append(error_string, memcached_string_with_size(" (")); + + memcached_string_append(error_string, memcached_string_make_from_cstr(memcached_strerror(NULL, MEMCACHED_SUCCESS))); + memcached_string_append(error_string, memcached_string_with_size(")")); + + memcached_set_error_string(memc, MEMCACHED_FAILURE, memcached_string_value(error_string), memcached_string_length(error_string)); + + memcached_string_free(error_string); + + return TEST_SUCCESS; +} diff --git a/tests/string.h b/tests/string.h new file mode 100644 index 00000000..eebd0c11 --- /dev/null +++ b/tests/string.h @@ -0,0 +1,69 @@ +/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: + * + * Gearmand client and server library. + * + * Copyright (C) 2011 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. + * + */ + +#pragma once + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +LIBTEST_INTERNAL_API +test_return_t string_static_null(memcached_st *memc); + +LIBTEST_INTERNAL_API +test_return_t string_alloc_null(memcached_st *memc); + +LIBTEST_INTERNAL_API +test_return_t string_alloc_with_size(memcached_st *memc); + +LIBTEST_INTERNAL_API +test_return_t string_alloc_with_size_toobig(memcached_st *memc); + +LIBTEST_INTERNAL_API +test_return_t string_alloc_append(memcached_st *memc); + +LIBTEST_INTERNAL_API +test_return_t string_alloc_append_toobig(memcached_st *memc); + +LIBTEST_INTERNAL_API +test_return_t string_alloc_append_multiple(memcached_st *memc); + +#ifdef __cplusplus +} +#endif diff --git a/tests/virtual_buckets.cc b/tests/virtual_buckets.cc new file mode 100644 index 00000000..73db3001 --- /dev/null +++ b/tests/virtual_buckets.cc @@ -0,0 +1,141 @@ +/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: + * + * Libmemcached Client and Server + * + * Copyright (C) 2011 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. + * + */ + +#include + +#include + +#include + +struct libtest_string_t { + const char *c_str; + size_t size; +}; + +static inline libtest_string_t libtest_string(const char *arg, size_t arg_size) +{ + libtest_string_t local= { arg, arg_size }; + return local; +} + +#define make_libtest_string(X) libtest_string((X), static_cast(sizeof(X) - 1)) + +static libtest_string_t libtest_string_t_null= { 0, 0}; + +static bool libtest_string_is_null(const libtest_string_t &string) +{ + if (string.c_str == 0 and string.size == 0) + return true; + + return false; +} + +struct expect_t { + libtest_string_t key; + uint32_t server_id; + uint32_t bucket_id; +}; + +expect_t basic_keys[]= { + { make_libtest_string("hello"), 0, 0 }, + { make_libtest_string("doctor"), 0, 0 }, + { make_libtest_string("name"), 1, 3 }, + { make_libtest_string("continue"), 1, 3 }, + { make_libtest_string("yesterday"), 0, 0 }, + { make_libtest_string("tomorrow"), 1, 1 }, + { make_libtest_string("another key"), 2, 2 }, + { libtest_string_t_null, 0, 0 } +}; + +test_return_t virtual_back_map(memcached_st *) +{ + memcached_return_t rc; + memcached_server_st *server_pool; + memcached_st *memc; + + memc= memcached_create(NULL); + test_true(memc); + + uint32_t server_map[] = { 0, 1, 2, 1 }; + rc= memcached_bucket_set(memc, server_map, NULL, 4, 2); + test_true(rc == MEMCACHED_SUCCESS); + + memcached_server_distribution_t dt; + dt= memcached_behavior_get_distribution(memc); + test_true(dt == MEMCACHED_DISTRIBUTION_VIRTUAL_BUCKET); + + memcached_behavior_set_key_hash(memc, MEMCACHED_HASH_CRC); + test_true(rc == MEMCACHED_SUCCESS); + + memcached_hash_t hash_type= memcached_behavior_get_key_hash(memc); + test_true(hash_type == MEMCACHED_HASH_CRC); + + server_pool = memcached_servers_parse("localhost:11211, localhost1:11210, localhost2:11211"); + test_true(server_pool); + memcached_server_push(memc, server_pool); + + /* verify that the server list was parsed okay. */ + test_true(memcached_server_count(memc) == 3); + test_true(strcmp(server_pool[0].hostname, "localhost") == 0); + test_true(server_pool[0].port == 11211); + + test_true(strcmp(server_pool[1].hostname, "localhost1") == 0); + test_true(server_pool[1].port == 11210); + + test_true(strcmp(server_pool[2].hostname, "localhost2") == 0); + test_true(server_pool[2].port == 11211); + + dt= memcached_behavior_get_distribution(memc); + hash_type= memcached_behavior_get_key_hash(memc); + test_true(dt == MEMCACHED_DISTRIBUTION_VIRTUAL_BUCKET); + test_true(hash_type == MEMCACHED_HASH_CRC); + + /* verify the standard ketama set. */ + for (expect_t *ptr= basic_keys; not libtest_string_is_null(ptr->key); ptr++) + { + uint32_t server_idx = memcached_generate_hash(memc, ptr->key.c_str, ptr->key.size); + + char buffer[1024]; + snprintf(buffer, sizeof(buffer), "%.*s:%lu Got/Expected %u == %u", (int)ptr->key.size, ptr->key.c_str, (unsigned long)ptr->key.size, server_idx, ptr->server_id); + test_true_got(server_idx == ptr->server_id, buffer); + } + + memcached_server_list_free(server_pool); + memcached_free(memc); + + return TEST_SUCCESS; +} diff --git a/tests/virtual_buckets.h b/tests/virtual_buckets.h new file mode 100644 index 00000000..054ec492 --- /dev/null +++ b/tests/virtual_buckets.h @@ -0,0 +1,53 @@ +/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: + * + * Libmemcached Client and Server + * + * Copyright (C) 2011 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. + * + */ + +#pragma once + +#include + +struct memcached_st; + +#ifdef __cplusplus +extern "C" { +#endif + +LIBTEST_INTERNAL_API +test_return_t virtual_back_map(memcached_st *); + +#ifdef __cplusplus +} +#endif -- 2.30.2