return "set ";
}
+static inline uint8_t can_by_encrypted(const memcached_storage_action_t verb)
+{
+ switch (verb)
+ {
+ case SET_OP:
+ case ADD_OP:
+ case CAS_OP:
+ case REPLACE_OP:
+ return true;
+
+ case APPEND_OP:
+ case PREPEND_OP:
+ break;
+ }
+
+ return false;
+}
+
static inline uint8_t get_com_code(const memcached_storage_action_t verb, const bool reply)
{
if (reply == false)
{
memcached_io_reset(server);
+#if 0
if (memcached_has_error(ptr))
{
memcached_set_error(*server, rc, MEMCACHED_AT);
}
+#endif
return MEMCACHED_WRITE_FAILURE;
}
{ storage_op_string(verb), strlen(storage_op_string(verb))},
{ memcached_array_string(ptr->_namespace), memcached_array_size(ptr->_namespace) },
{ key, key_length },
- { flags_buffer, flags_buffer_length },
- { expiration_buffer, expiration_buffer_length },
- { value_buffer, value_buffer_length },
- { cas_buffer, cas_buffer_length },
+ { flags_buffer, size_t(flags_buffer_length) },
+ { expiration_buffer, size_t(expiration_buffer_length) },
+ { value_buffer, size_t(value_buffer_length) },
+ { cas_buffer, size_t(cas_buffer_length) },
{ " noreply", reply ? 0 : memcached_literal_param_size(" noreply") },
{ memcached_literal_param("\r\n") },
{ value, value_length },
/* Send command header */
memcached_return_t rc= memcached_vdo(instance, vector, 12, flush);
- if (rc == MEMCACHED_SUCCESS)
+
+ // If we should not reply, return with MEMCACHED_SUCCESS, unless error
+ if (reply == false)
{
- if (flush == false)
- {
- return MEMCACHED_BUFFERED;
- }
+ return memcached_success(rc) ? MEMCACHED_SUCCESS : rc;
+ }
- if (reply == false)
- {
- return MEMCACHED_SUCCESS;
- }
+ if (flush == false)
+ {
+ return memcached_success(rc) ? MEMCACHED_BUFFERED : rc;
+ }
+ if (rc == MEMCACHED_SUCCESS)
+ {
char buffer[MEMCACHED_DEFAULT_COMMAND_SIZE];
- rc= memcached_response(instance, buffer, MEMCACHED_DEFAULT_COMMAND_SIZE, NULL);
+ rc= memcached_response(instance, buffer, sizeof(buffer), NULL);
if (rc == MEMCACHED_STORED)
{
}
assert(memcached_failed(rc));
+#if 0
if (memcached_has_error(ptr) == false)
{
return memcached_set_error(*ptr, rc, MEMCACHED_AT);
}
+#endif
return rc;
}
return rc;
}
- if (memcached_failed(rc= memcached_validate_key_length(key_length, memcached_is_binary(ptr))))
- {
- return rc;
- }
-
if (memcached_failed(memcached_key_test(*ptr, (const char **)&key, &key_length, 1)))
{
- return MEMCACHED_BAD_KEY_PROVIDED;
+ return memcached_last_error(ptr);
}
uint32_t server_key= memcached_generate_hash_with_redistribution(ptr, group_key, group_key_length);
bool reply= memcached_is_replying(ptr);
- if (memcached_is_binary(ptr))
+ hashkit_string_st* destination= NULL;
+
+ if (memcached_is_encrypted(ptr))
{
- return memcached_send_binary(ptr, instance, server_key,
- key, key_length,
- value, value_length, expiration,
- flags, cas, flush, reply, verb);
+ if (can_by_encrypted(verb) == false)
+ {
+ return memcached_set_error(*ptr, MEMCACHED_NOT_SUPPORTED, MEMCACHED_AT,
+ memcached_literal_param("Operation not allowed while encyrption is enabled"));
+ }
+
+ if ((destination= hashkit_encrypt(&ptr->hashkit, value, value_length)) == NULL)
+ {
+ return rc;
+ }
+ value= hashkit_string_c_str(destination);
+ value_length= hashkit_string_length(destination);
}
- return memcached_send_ascii(ptr, instance,
+ if (memcached_is_binary(ptr))
+ {
+ rc= memcached_send_binary(ptr, instance, server_key,
key, key_length,
value, value_length, expiration,
flags, cas, flush, reply, verb);
+ }
+ else
+ {
+ rc= memcached_send_ascii(ptr, instance,
+ key, key_length,
+ value, value_length, expiration,
+ flags, cas, flush, reply, verb);
+ }
+
+ hashkit_string_free(destination);
+
+ return rc;
}
key, key_length, value, value_length,
expiration, flags, 0, ADD_OP);
- if (rc == MEMCACHED_NOTSTORED or rc == MEMCACHED_DATA_EXISTS)
- {
- memcached_set_error(*ptr, rc, MEMCACHED_AT);
- }
LIBMEMCACHED_MEMCACHED_ADD_END();
return rc;
}