@@ -142,6 +142,7 @@ typedef struct {
142142
143143 zend_bool is_persistent ;
144144 zend_bool compression_enabled ;
145+ zend_bool encoding_enabled ;
145146
146147 zend_long serializer ;
147148 zend_long compression_type ;
@@ -1227,6 +1228,7 @@ static PHP_METHOD(Memcached, __construct)
12271228 memc_user_data -> serializer = MEMC_G (serializer_type );
12281229 memc_user_data -> compression_type = MEMC_G (compression_type );
12291230 memc_user_data -> compression_enabled = 1 ;
1231+ memc_user_data -> encoding_enabled = 0 ;
12301232 memc_user_data -> store_retry_count = MEMC_G (store_retry_count );
12311233 memc_user_data -> set_udf_flags = -1 ;
12321234 memc_user_data -> is_persistent = is_persistent ;
@@ -3265,6 +3267,42 @@ static PHP_METHOD(Memcached, setSaslAuthData)
32653267/* }}} */
32663268#endif /* HAVE_MEMCACHED_SASL */
32673269
3270+ #ifdef HAVE_MEMCACHED_SET_ENCODING_KEY
3271+ /* {{{ Memcached::setEncodingKey(string key)
3272+ Sets AES encryption key (libmemcached 1.0.6 and higher) */
3273+ static PHP_METHOD (Memcached , setEncodingKey )
3274+ {
3275+ MEMC_METHOD_INIT_VARS ;
3276+ memcached_return status ;
3277+ zend_string * key ;
3278+
3279+ /* "S" */
3280+ ZEND_PARSE_PARAMETERS_START (1 , 1 )
3281+ Z_PARAM_STR (key )
3282+ ZEND_PARSE_PARAMETERS_END ();
3283+
3284+ MEMC_METHOD_FETCH_OBJECT ;
3285+
3286+ // libmemcached < 1.0.18 cannot handle a change of encoding key. Warn about this and return false.
3287+ #if defined(LIBMEMCACHED_VERSION_HEX ) && LIBMEMCACHED_VERSION_HEX < 0x01000018
3288+ if (memc_user_data -> encoding_enabled ) {
3289+ php_error_docref (NULL , E_WARNING , "libmemcached versions less than 1.0.18 cannot change encoding key" );
3290+ RETURN_FALSE ;
3291+ }
3292+ #endif
3293+
3294+ status = memcached_set_encoding_key (intern -> memc , ZSTR_VAL (key ), ZSTR_LEN (key ));
3295+
3296+ if (s_memc_status_handle_result_code (intern , status ) == FAILURE ) {
3297+ RETURN_FALSE ;
3298+ }
3299+
3300+ memc_user_data -> encoding_enabled = 1 ;
3301+ RETURN_TRUE ;
3302+ }
3303+ /* }}} */
3304+ #endif /* HAVE_MEMCACHED_SET_ENCODING_KEY */
3305+
32683306/* {{{ Memcached::getResultCode()
32693307 Returns the result code from the last operation */
32703308static PHP_METHOD (Memcached , getResultCode )
@@ -4034,6 +4072,12 @@ ZEND_BEGIN_ARG_INFO(arginfo_setSaslAuthData, 0)
40344072ZEND_END_ARG_INFO ()
40354073#endif
40364074
4075+ #ifdef HAVE_MEMCACHED_SET_ENCODING_KEY
4076+ ZEND_BEGIN_ARG_INFO (arginfo_setEncodingKey , 0 )
4077+ ZEND_ARG_INFO (0 , key )
4078+ ZEND_END_ARG_INFO ()
4079+ #endif
4080+
40374081ZEND_BEGIN_ARG_INFO (arginfo_setOption , 0 )
40384082 ZEND_ARG_INFO (0 , option )
40394083 ZEND_ARG_INFO (0 , value )
@@ -4133,6 +4177,9 @@ static zend_function_entry memcached_class_methods[] = {
41334177 MEMC_ME (setBucket , arginfo_setBucket )
41344178#ifdef HAVE_MEMCACHED_SASL
41354179 MEMC_ME (setSaslAuthData , arginfo_setSaslAuthData )
4180+ #endif
4181+ #ifdef HAVE_MEMCACHED_SET_ENCODING_KEY
4182+ MEMC_ME (setEncodingKey , arginfo_setEncodingKey )
41364183#endif
41374184 MEMC_ME (isPersistent , arginfo_isPersistent )
41384185 MEMC_ME (isPristine , arginfo_isPristine )
@@ -4282,6 +4329,15 @@ static void php_memc_register_constants(INIT_FUNC_ARGS)
42824329 REGISTER_MEMC_CLASS_CONST_BOOL (HAVE_MSGPACK , 0 );
42834330#endif
42844331
4332+ /*
4333+ * Indicate whether set_encoding_key is available
4334+ */
4335+ #ifdef HAVE_MEMCACHED_SET_ENCODING_KEY
4336+ REGISTER_MEMC_CLASS_CONST_BOOL (HAVE_ENCODING , 1 );
4337+ #else
4338+ REGISTER_MEMC_CLASS_CONST_BOOL (HAVE_ENCODING , 0 );
4339+ #endif
4340+
42854341#ifdef HAVE_MEMCACHED_SESSION
42864342 REGISTER_MEMC_CLASS_CONST_BOOL (HAVE_SESSION , 1 );
42874343#else
0 commit comments