Refactor: memcachd_key_test -> memcached_key_test
[m6w6/libmemcached] / libmemcached / memcached_get.c
index dcaa8988a257344a543c34cf39e0fe6963c714c5..9688286450d508392b5cfc9b31b9e7a6ba097833 100644 (file)
@@ -27,6 +27,12 @@ char *memcached_get_by_key(memcached_st *ptr,
   uint32_t dummy_flags;
   memcached_return dummy_error;
 
+  if (ptr->flags & MEM_USE_UDP)
+  {
+    *error= MEMCACHED_NOT_SUPPORTED;
+    return NULL;
+  }
+
   /* Request the key */
   *error= memcached_mget_by_key(ptr, 
                                 master_key, 
@@ -120,6 +126,9 @@ memcached_return memcached_mget_by_key(memcached_st *ptr,
   uint8_t get_command_length= 4;
   unsigned int master_server_key= 0;
 
+   if (ptr->flags & MEM_USE_UDP)
+    return MEMCACHED_NOT_SUPPORTED;
+
   LIBMEMCACHED_MEMCACHED_MGET_START();
   ptr->cursor_server= 0;
 
@@ -129,7 +138,7 @@ memcached_return memcached_mget_by_key(memcached_st *ptr,
   if (ptr->number_of_hosts == 0)
     return MEMCACHED_NO_SERVERS;
 
-  if ((ptr->flags & MEM_VERIFY_KEY) && (memcachd_key_test(keys, key_length, number_of_keys) == MEMCACHED_BAD_KEY_PROVIDED))
+  if ((ptr->flags & MEM_VERIFY_KEY) && (memcached_key_test(keys, key_length, number_of_keys) == MEMCACHED_BAD_KEY_PROVIDED))
     return MEMCACHED_BAD_KEY_PROVIDED;
 
   if (ptr->flags & MEM_SUPPORT_CAS)
@@ -140,7 +149,7 @@ memcached_return memcached_mget_by_key(memcached_st *ptr,
 
   if (master_key && master_key_length)
   {
-    if ((ptr->flags & MEM_VERIFY_KEY) && (memcachd_key_test((char **)&master_key, &master_key_length, 1) == MEMCACHED_BAD_KEY_PROVIDED))
+    if ((ptr->flags & MEM_VERIFY_KEY) && (memcached_key_test((char **)&master_key, &master_key_length, 1) == MEMCACHED_BAD_KEY_PROVIDED))
       return MEMCACHED_BAD_KEY_PROVIDED;
     master_server_key= memcached_generate_hash(ptr, master_key, master_key_length);
   }
@@ -250,6 +259,7 @@ static memcached_return binary_mget_by_key(memcached_st *ptr,
                                            unsigned int number_of_keys)
 {
   memcached_return rc= MEMCACHED_NOTFOUND;
+  uint32_t x;
 
   int flush= number_of_keys == 1;
 
@@ -257,7 +267,7 @@ static memcached_return binary_mget_by_key(memcached_st *ptr,
     If a server fails we warn about errors and start all over with sending keys
     to the server.
   */
-  for (int x= 0; x < number_of_keys; x++) 
+  for (x= 0; x < number_of_keys; x++) 
   {
     unsigned int server_key;
 
@@ -273,13 +283,23 @@ static memcached_return binary_mget_by_key(memcached_st *ptr,
         continue;
     }
      
-    protocol_binary_request_getk request= {0};
+    protocol_binary_request_getk request= {.bytes= {0}};
     request.message.header.request.magic= PROTOCOL_BINARY_REQ;
     if (number_of_keys == 1)
       request.message.header.request.opcode= PROTOCOL_BINARY_CMD_GETK;
     else
       request.message.header.request.opcode= PROTOCOL_BINARY_CMD_GETKQ;
 
+    memcached_return vk;
+    vk= memcached_validate_key_length(key_length[x],
+                                      ptr->flags & MEM_BINARY_PROTOCOL);
+    unlikely (vk != MEMCACHED_SUCCESS)
+    {
+      if (x > 0)
+        memcached_io_reset(&ptr->hosts[server_key]);
+      return vk;
+    }
+
     request.message.header.request.keylen= htons((uint16_t)key_length[x]);
     request.message.header.request.datatype= PROTOCOL_BINARY_RAW_BYTES;
     request.message.header.request.bodylen= htonl(key_length[x]);
@@ -301,12 +321,12 @@ static memcached_return binary_mget_by_key(memcached_st *ptr,
     /*
      * Send a noop command to flush the buffers
      */
-    protocol_binary_request_noop request= {0};
+    protocol_binary_request_noop request= {.bytes= {0}};
     request.message.header.request.magic= PROTOCOL_BINARY_REQ;
     request.message.header.request.opcode= PROTOCOL_BINARY_CMD_NOOP;
     request.message.header.request.datatype= PROTOCOL_BINARY_RAW_BYTES;
     
-    for (int x= 0; x < ptr->number_of_hosts; x++)
+    for (x= 0; x < ptr->number_of_hosts; x++)
       if (memcached_server_response_count(&ptr->hosts[x])) 
       {
         if (memcached_io_write(&ptr->hosts[x], NULL, 0, 1) == -1)