X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=libmemcached%2Fstorage.cc;h=97470048e5d081e78b71e355d5343188d2db2080;hb=b5495838fb245aa1068a1198ed549b98a9c3e666;hp=e5f67dbcd2e50b7f07118aaa4db10dad3f877bec;hpb=d360b4e7edb133db3dc9750538e4de6b1c5cdcf7;p=m6w6%2Flibmemcached diff --git a/libmemcached/storage.cc b/libmemcached/storage.cc index e5f67dbc..97470048 100644 --- a/libmemcached/storage.cc +++ b/libmemcached/storage.cc @@ -74,6 +74,24 @@ static inline const char *storage_op_string(memcached_storage_action_t verb) 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) @@ -137,7 +155,8 @@ static memcached_return_t memcached_send_binary(memcached_st *ptr, protocol_binary_request_set request= {}; size_t send_length= sizeof(request.bytes); - request.message.header.request.magic= PROTOCOL_BINARY_REQ; + initialize_binary_request(server, request.message.header); + request.message.header.request.opcode= get_com_code(verb, reply); request.message.header.request.keylen= htons((uint16_t)(key_length + memcached_array_size(ptr->_namespace))); request.message.header.request.datatype= PROTOCOL_BINARY_RAW_BYTES; @@ -175,10 +194,12 @@ static memcached_return_t memcached_send_binary(memcached_st *ptr, { memcached_io_reset(server); +#if 0 if (memcached_has_error(ptr)) { memcached_set_error(*server, rc, MEMCACHED_AT); } +#endif return MEMCACHED_WRITE_FAILURE; } @@ -319,10 +340,12 @@ static memcached_return_t memcached_send_ascii(memcached_st *ptr, } assert(memcached_failed(rc)); +#if 0 if (memcached_has_error(ptr) == false) { return memcached_set_error(*ptr, rc, MEMCACHED_AT); } +#endif return rc; } @@ -342,9 +365,9 @@ static inline memcached_return_t memcached_send(memcached_st *ptr, return rc; } - if (memcached_failed(rc= memcached_key_test(*ptr, (const char **)&key, &key_length, 1))) + if (memcached_failed(memcached_key_test(*ptr, (const char **)&key, &key_length, 1))) { - return rc; + return memcached_last_error(ptr); } uint32_t server_key= memcached_generate_hash_with_redistribution(ptr, group_key, group_key_length); @@ -362,18 +385,42 @@ static inline memcached_return_t memcached_send(memcached_st *ptr, 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; } @@ -403,10 +450,6 @@ memcached_return_t memcached_add(memcached_st *ptr, 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; }