Fix prefix key so that it is not statically built.
[m6w6/libmemcached] / libmemcached / callback.c
index 252b4334e66166b2985def805da973457a5b9ed3..69e47d4d78ad9bd5bdc3c507496928f324e3a87c 100644 (file)
@@ -11,8 +11,6 @@
 
 #include "common.h"
 #include <sys/types.h>
-#include <sys/socket.h>
-#include <netinet/tcp.h>
 
 /*
   These functions provide data and function callback support
@@ -33,25 +31,21 @@ memcached_return_t memcached_callback_set(memcached_st *ptr,
         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;
-        }
+          return memcached_set_error(ptr, MEMCACHED_BAD_KEY_PROVIDED, NULL);
 
-        if ((key_length > MEMCACHED_PREFIX_KEY_MAX_SIZE -1)
-            || (strcpy(ptr->prefix_key, key) == NULL))
-        {
-          ptr->prefix_key_length= 0;
-          return MEMCACHED_BAD_KEY_PROVIDED;
-        }
-        else
-        {
-          ptr->prefix_key_length= key_length;
-        }
+        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));
+
+        f (! ptr->prefix_key)
+          return memcached_set_error(ptr, MEMCACHED_MEMORY_ALLOCATION_FAILURE, NULL);
       }
       else
       {
-        memset(ptr->prefix_key, 0, MEMCACHED_PREFIX_KEY_MAX_SIZE);
-        ptr->prefix_key_length= 0;
+        memcached_array_free(ptr->prefix_key);
+        ptr->prefix_key= NULL;
       }
 
       break;
@@ -126,15 +120,15 @@ void *memcached_callback_get(memcached_st *ptr,
   {
   case MEMCACHED_CALLBACK_PREFIX_KEY:
     {
-      if (ptr->prefix_key[0] == 0)
+      if (ptr->prefix_key)
       {
-        *error= MEMCACHED_FAILURE;
-        return NULL;
+        *error= MEMCACHED_SUCCESS;
+        return (void *)memcached_array_string(ptr->prefix_key);
       }
       else
       {
-        *error= MEMCACHED_SUCCESS;
-        return (void *)ptr->prefix_key;
+        *error= MEMCACHED_FAILURE;
+        return NULL;
       }
     }
   case MEMCACHED_CALLBACK_USER_DATA: