is compiled in debug mode it can toss an error if a bad key is provided.
* Servers are now sorted, meaning that servers are now ordered so that
clients with the same lists, will have same distribution. (Idea from
Ross McFarland).
+ * Added MEMCACHED_BAD_KEY_PROVIDED error for auto, set, and get operations
+ when the library is compiled with --enable-debug. This additional code
+ will test for bad keys.
0.15 Tue Jan 29 14:55:44 PST 2008
* More work on the C++ API.
MEMCACHED_FETCH_NOTFINISHED,
MEMCACHED_TIMEOUT,
MEMCACHED_BUFFERED,
+ MEMCACHED_BAD_KEY_PROVIDED,
MEMCACHED_MAXIMUM_RETURN, /* Always add new error code before */
} memcached_return;
memcached_hosts.c \
memcached_io.c \
md5.c \
+ memcached_key.c \
memcached_quit.c \
memcached_parse.c \
memcached_response.c \
#include <fcntl.h>
#include <sys/un.h>
#include <netinet/tcp.h>
-#include "libmemcached_config.h"
+#include <libmemcached_config.h>
#if TIME_WITH_SYS_TIME
# include <sys/time.h>
memcached_result_st *result);
void server_list_free(memcached_st *ptr, memcached_server_st *servers);
+memcached_return key_proof(char **keys, size_t *key_length,
+ unsigned int number_of_keys);
+
+#ifdef HAVE_DEBUG
+#define key_test(A,B,C) key_proof(A,B,C)
+#else
+#define key_test(A,B,C) MEMCACHED_SUCCESS
+#endif
#endif /* __COMMON_H__ */
if (ptr->hosts == NULL || ptr->number_of_hosts == 0)
return MEMCACHED_NO_SERVERS;
+ if (key_test(&key, &key_length, 1) == MEMCACHED_BAD_KEY_PROVIDED)
+ return MEMCACHED_BAD_KEY_PROVIDED;
+
server_key= memcached_generate_hash(ptr, key, key_length);
send_length= snprintf(buffer, MEMCACHED_DEFAULT_COMMAND_SIZE,
if (ptr->number_of_hosts == 0)
return MEMCACHED_NO_SERVERS;
+ if (key_test(keys, key_length, number_of_keys) == MEMCACHED_BAD_KEY_PROVIDED)
+ return MEMCACHED_BAD_KEY_PROVIDED;
+
if (ptr->flags & MEM_SUPPORT_CAS)
{
get_command= "gets ";
if (ptr->number_of_hosts == 0)
return MEMCACHED_NO_SERVERS;
+ if (key_test(&key, &key_length, 1) == MEMCACHED_BAD_KEY_PROVIDED)
+ return MEMCACHED_BAD_KEY_PROVIDED;
+
server_key= memcached_generate_hash(ptr, master_key, master_key_length);
if (cas)
return "ACTION QUEUED";
case MEMCACHED_TIMEOUT:
return "A TIMEOUT OCCURRED";
+ case MEMCACHED_BAD_KEY_PROVIDED:
+ return "A BAD KEY WAS PROVIDED/CHARACTERS OUT OF RANGE";
case MEMCACHED_MAXIMUM_RETURN:
return "Gibberish returned!";
default:
return 0;
}
+uint8_t bad_key_test(memcached_st *memc)
+{
+#ifdef HAVE_DEBUG
+ memcached_return rc;
+ char *key= "foo bad";
+ char *string;
+ size_t string_length;
+ uint32_t flags;
+
+ string= memcached_get(memc, key, strlen(key),
+ &string_length, &flags, &rc);
+ assert(rc == MEMCACHED_BAD_KEY_PROVIDED);
+ assert(string_length == 0);
+ assert(!string);
+#endif
+
+ return 0;
+}
+
uint8_t get_test(memcached_st *memc)
{
memcached_return rc;
{"behavior_test", 0, get_stats_keys },
{"callback_test", 0, get_stats_keys },
{"version_string_test", 0, version_string_test},
+ {"bad_key", 1, bad_key_test },
{0, 0, 0}
};