libmemcached: fix typo [ci skip]
[awesomized/libmemcached] / libmemcached / auto.cc
index 9d85ad434858897556244f0447f0564cfddadaf5..06e7ab6419646abb82121ce5d9a775fb5aaeaa07 100644 (file)
@@ -37,7 +37,7 @@
 
 #include <libmemcached/common.h>
 
-static void auto_response(memcached_server_write_instance_st instance, const bool reply,  memcached_return_t& rc, uint64_t* value)
+static void auto_response(memcached_instance_st* instance, const bool reply,  memcached_return_t& rc, uint64_t* value)
 {
   // If the message was successfully sent, then get the response, otherwise
   // fail.
@@ -52,17 +52,23 @@ static void auto_response(memcached_server_write_instance_st instance, const boo
     rc= memcached_response(instance, &instance->root->result);
   }
 
-  if (memcached_success(rc))
+  if (memcached_fatal(rc))
   {
-    *value= instance->root->result.numeric_value;
+    assert(memcached_last_error(instance->root) != MEMCACHED_SUCCESS);
+    *value= UINT64_MAX;
   }
-  else
+  else if (memcached_failed(rc))
   {
     *value= UINT64_MAX;
   }
+  else
+  {
+    assert(memcached_last_error(instance->root) != MEMCACHED_NOTFOUND);
+    *value= instance->root->result.numeric_value;
+  }
 }
 
-static memcached_return_t text_incr_decr(memcached_server_write_instance_st instance,
+static memcached_return_t text_incr_decr(memcached_instance_st* instance,
                                          const bool is_incr,
                                          const char *key, size_t key_length,
                                          const uint64_t offset,
@@ -83,7 +89,7 @@ static memcached_return_t text_incr_decr(memcached_server_write_instance_st inst
     { memcached_literal_param("incr ") },
     { memcached_array_string(instance->root->_namespace), memcached_array_size(instance->root->_namespace) },
     { key, key_length },
-    { buffer, send_length },
+    { buffer, size_t(send_length) },
     { " noreply", reply ? 0 : memcached_literal_param_size(" noreply") },
     { memcached_literal_param("\r\n") }
   };
@@ -96,7 +102,7 @@ static memcached_return_t text_incr_decr(memcached_server_write_instance_st inst
   return memcached_vdo(instance, vector, 7, true);
 }
 
-static memcached_return_t binary_incr_decr(memcached_server_write_instance_st instance,
+static memcached_return_t binary_incr_decr(memcached_instance_st* instance,
                                            protocol_binary_command cmd,
                                            const char *key, const size_t key_length,
                                            const uint64_t offset,
@@ -118,7 +124,8 @@ static memcached_return_t binary_incr_decr(memcached_server_write_instance_st in
   }
   protocol_binary_request_incr request= {}; // = {.bytes= {0}};
 
-  request.message.header.request.magic= PROTOCOL_BINARY_REQ;
+  initialize_binary_request(instance, request.message.header);
+
   request.message.header.request.opcode= cmd;
   request.message.header.request.keylen= htons((uint16_t)(key_length + memcached_array_size(instance->root->_namespace)));
   request.message.header.request.extlen= 20;
@@ -148,7 +155,7 @@ memcached_return_t memcached_increment(memcached_st *memc,
 }
 
 static memcached_return_t increment_decrement_by_key(const protocol_binary_command command,
-                                                     memcached_st *memc,
+                                                     Memcached *memc,
                                                      const char *group_key, size_t group_key_length,
                                                      const char *key, size_t key_length,
                                                      uint64_t offset,
@@ -166,13 +173,19 @@ static memcached_return_t increment_decrement_by_key(const protocol_binary_comma
     return rc;
   }
 
+  if (memcached_is_encrypted(memc))
+  {
+    return memcached_set_error(*memc, MEMCACHED_NOT_SUPPORTED, MEMCACHED_AT, 
+                               memcached_literal_param("Operation not allowed while encyrption is enabled"));
+  }
+
   if (memcached_failed(rc= memcached_key_test(*memc, (const char **)&key, &key_length, 1)))
   {
     return memcached_last_error(memc);
   }
 
   uint32_t server_key= memcached_generate_hash_with_redistribution(memc, group_key, group_key_length);
-  memcached_server_write_instance_st instance= memcached_server_instance_fetch(memc, server_key);
+  memcached_instance_st* instance= memcached_instance_fetch(memc, server_key);
 
   bool reply= memcached_is_replying(instance->root);
 
@@ -197,7 +210,7 @@ static memcached_return_t increment_decrement_by_key(const protocol_binary_comma
 }
 
 static memcached_return_t increment_decrement_with_initial_by_key(const protocol_binary_command command,
-                                                                  memcached_st *memc,
+                                                                  Memcached *memc,
                                                                   const char *group_key,
                                                                   size_t group_key_length,
                                                                   const char *key,
@@ -219,13 +232,19 @@ static memcached_return_t increment_decrement_with_initial_by_key(const protocol
     return rc;
   }
 
+  if (memcached_is_encrypted(memc))
+  {
+    return memcached_set_error(*memc, MEMCACHED_NOT_SUPPORTED, MEMCACHED_AT, 
+                               memcached_literal_param("Operation not allowed while encryption is enabled"));
+  }
+
   if (memcached_failed(rc= memcached_key_test(*memc, (const char **)&key, &key_length, 1)))
   {
     return memcached_last_error(memc);
   }
 
   uint32_t server_key= memcached_generate_hash_with_redistribution(memc, group_key, group_key_length);
-  memcached_server_write_instance_st instance= memcached_server_instance_fetch(memc, server_key);
+  memcached_instance_st* instance= memcached_instance_fetch(memc, server_key);
 
   bool reply= memcached_is_replying(instance->root);
 
@@ -257,12 +276,13 @@ memcached_return_t memcached_decrement(memcached_st *memc,
 }
 
 
-memcached_return_t memcached_increment_by_key(memcached_st *memc,
+memcached_return_t memcached_increment_by_key(memcached_st *shell,
                                               const char *group_key, size_t group_key_length,
                                               const char *key, size_t key_length,
                                               uint64_t offset,
                                               uint64_t *value)
 {
+  Memcached* memc= memcached2Memcached(shell);
   LIBMEMCACHED_MEMCACHED_INCREMENT_START();
   memcached_return_t rc= increment_decrement_by_key(PROTOCOL_BINARY_CMD_INCREMENT,
                                                     memc,
@@ -275,12 +295,13 @@ memcached_return_t memcached_increment_by_key(memcached_st *memc,
   return rc;
 }
 
-memcached_return_t memcached_decrement_by_key(memcached_st *memc,
+memcached_return_t memcached_decrement_by_key(memcached_st *shell,
                                               const char *group_key, size_t group_key_length,
                                               const char *key, size_t key_length,
                                               uint64_t offset,
                                               uint64_t *value)
 {
+  Memcached* memc= memcached2Memcached(shell);
   LIBMEMCACHED_MEMCACHED_DECREMENT_START();
   memcached_return_t rc= increment_decrement_by_key(PROTOCOL_BINARY_CMD_DECREMENT,
                                                     memc,
@@ -305,7 +326,7 @@ memcached_return_t memcached_increment_with_initial(memcached_st *memc,
                                                  offset, initial, expiration, value);
 }
 
-memcached_return_t memcached_increment_with_initial_by_key(memcached_st *memc,
+memcached_return_t memcached_increment_with_initial_by_key(memcached_st *shell,
                                                            const char *group_key,
                                                            size_t group_key_length,
                                                            const char *key,
@@ -316,6 +337,7 @@ memcached_return_t memcached_increment_with_initial_by_key(memcached_st *memc,
                                                            uint64_t *value)
 {
   LIBMEMCACHED_MEMCACHED_INCREMENT_WITH_INITIAL_START();
+  Memcached* memc= memcached2Memcached(shell);
   memcached_return_t rc= increment_decrement_with_initial_by_key(PROTOCOL_BINARY_CMD_INCREMENT, 
                                                                  memc,
                                                                  group_key, group_key_length,
@@ -339,7 +361,7 @@ memcached_return_t memcached_decrement_with_initial(memcached_st *memc,
                                                  offset, initial, expiration, value);
 }
 
-memcached_return_t memcached_decrement_with_initial_by_key(memcached_st *memc,
+memcached_return_t memcached_decrement_with_initial_by_key(memcached_st *shell,
                                                            const char *group_key,
                                                            size_t group_key_length,
                                                            const char *key,
@@ -350,6 +372,7 @@ memcached_return_t memcached_decrement_with_initial_by_key(memcached_st *memc,
                                                            uint64_t *value)
 {
   LIBMEMCACHED_MEMCACHED_INCREMENT_WITH_INITIAL_START();
+  Memcached* memc= memcached2Memcached(shell);
   memcached_return_t rc= increment_decrement_with_initial_by_key(PROTOCOL_BINARY_CMD_DECREMENT, 
                                                                  memc,
                                                                  group_key, group_key_length,