core.
*
*/
-#include "common.h"
+#include "libmemcached/common.h"
#include <sys/types.h>
/*
{
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_set_error(ptr, MEMCACHED_BAD_KEY_PROVIDED, NULL);
-
- if ((key_length > MEMCACHED_PREFIX_KEY_MAX_SIZE -1))
- return memcached_set_error(ptr, MEMCACHED_KEY_TOO_BIG, NULL);
-
- memcached_array_free(ptr->prefix_key);
- ptr->prefix_key= memcached_strcpy(ptr, (const char *)data, strlen((const char*)data));
-
- if (! ptr->prefix_key)
- return memcached_set_error(ptr, MEMCACHED_MEMORY_ALLOCATION_FAILURE, NULL);
- }
- else
- {
- memcached_array_free(ptr->prefix_key);
- ptr->prefix_key= NULL;
- }
-
- break;
+ return memcached_set_prefix_key(ptr, (char*)data, data ? strlen((char*)data) : 0);
}
case MEMCACHED_CALLBACK_USER_DATA:
{
Common include file for libmemached
*/
-#ifndef __LIBMEMCACHED_COMMON_H__
-#define __LIBMEMCACHED_COMMON_H__
+#pragma once
#include <config.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
#ifdef __cplusplus
}
#endif
-
-#endif /* __LIBMEMCACHED_COMMON_H__ */
#define MEMCACHED_VERSION_STRING_LENGTH 24
-typedef enum {
+enum memcached_return_t {
MEMCACHED_SUCCESS,
MEMCACHED_FAILURE,
MEMCACHED_HOST_LOOKUP_FAILURE,
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 {
libmemcached/memcached/protocol_binary.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 \
libmemcached/memcached.c \
libmemcached/options.cc \
libmemcached/parse.c \
+ libmemcached/prefix_key.cc \
libmemcached/purge.c \
libmemcached/quit.c \
libmemcached/response.c \
*
*/
-#include "common.h"
+#include "libmemcached/common.h"
#include <iostream>
static memcached_return_t _parse_file_options(memcached_st *self, memcached_string_t *filename)
{
- std::string real_name(filename->c_str, filename->size);
- FILE *fp= fopen(real_name.c_str(), "r");
+ 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 tmp;
- tmp.c_str= real_name.c_str();
- tmp.size= real_name.size();
- return memcached_set_errno(self, errno, &tmp);
+ 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;
%name-prefix="libmemcached_"
%parse-param { Context *context }
%parse-param { yyscan_t *scanner }
-%locations
%pure-parser
%require "2.2"
%start begin
#include <config.h>
-#include <cstdint>
-#include <sstream>
+#include <stdint.h>
#include <libmemcached/options/context.h>
#include <libmemcached/options/string.h>
#pragma GCC diagnostic ignored "-Wold-style-cast"
#include <libmemcached/options/scanner.h>
-int libmemcached_lex(YYSTYPE* lvalp, YYLTYPE* llocp, void* scanner);
+int libmemcached_lex(YYSTYPE* lvalp, void* scanner);
#define parser_abort(A, B) do { parser_abort_func((A), (B)); YYABORT; } while (0)
memcached_set_error_string(context->memc, context->rc, error_message.c_str(), error_message.size());
}
-inline void libmemcached_error(YYLTYPE *locp, Context *context, yyscan_t *scanner, const char *error)
+inline void libmemcached_error(Context *context, yyscan_t *scanner, const char *error)
{
if (not context->end())
parser_abort_func(context, error);
#include <libmemcached/options/symbol.h>
#define YY_EXTRA_TYPE Context*
-#define YY_USER_ACTION yylloc->first_line = yylineno;
}
%}
%option bison-bridge
-%option bison-locations
%option case-insensitive
%option debug
%option nounput
%option noyywrap
-%option yylineno
%option outfile="libmemcached/options/scanner.cc" header-file="libmemcached/options/scanner.h"
%option perf-report
%option prefix="libmemcached_"
--- /dev/null
+/* 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>
+
+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;
+}
--- /dev/null
+/* 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
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);