@@ -142,6 +142,7 @@ typedef struct {
142
142
143
143
zend_bool is_persistent ;
144
144
zend_bool compression_enabled ;
145
+ zend_bool encoding_enabled ;
145
146
146
147
zend_long serializer ;
147
148
zend_long compression_type ;
@@ -1227,6 +1228,7 @@ static PHP_METHOD(Memcached, __construct)
1227
1228
memc_user_data -> serializer = MEMC_G (serializer_type );
1228
1229
memc_user_data -> compression_type = MEMC_G (compression_type );
1229
1230
memc_user_data -> compression_enabled = 1 ;
1231
+ memc_user_data -> encoding_enabled = 0 ;
1230
1232
memc_user_data -> store_retry_count = MEMC_G (store_retry_count );
1231
1233
memc_user_data -> set_udf_flags = -1 ;
1232
1234
memc_user_data -> is_persistent = is_persistent ;
@@ -3265,6 +3267,42 @@ static PHP_METHOD(Memcached, setSaslAuthData)
3265
3267
/* }}} */
3266
3268
#endif /* HAVE_MEMCACHED_SASL */
3267
3269
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
+
3268
3306
/* {{{ Memcached::getResultCode()
3269
3307
Returns the result code from the last operation */
3270
3308
static PHP_METHOD (Memcached , getResultCode )
@@ -4034,6 +4072,12 @@ ZEND_BEGIN_ARG_INFO(arginfo_setSaslAuthData, 0)
4034
4072
ZEND_END_ARG_INFO ()
4035
4073
#endif
4036
4074
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
+
4037
4081
ZEND_BEGIN_ARG_INFO (arginfo_setOption , 0 )
4038
4082
ZEND_ARG_INFO (0 , option )
4039
4083
ZEND_ARG_INFO (0 , value )
@@ -4133,6 +4177,9 @@ static zend_function_entry memcached_class_methods[] = {
4133
4177
MEMC_ME (setBucket , arginfo_setBucket )
4134
4178
#ifdef HAVE_MEMCACHED_SASL
4135
4179
MEMC_ME (setSaslAuthData , arginfo_setSaslAuthData )
4180
+ #endif
4181
+ #ifdef HAVE_MEMCACHED_SET_ENCODING_KEY
4182
+ MEMC_ME (setEncodingKey , arginfo_setEncodingKey )
4136
4183
#endif
4137
4184
MEMC_ME (isPersistent , arginfo_isPersistent )
4138
4185
MEMC_ME (isPristine , arginfo_isPristine )
@@ -4282,6 +4329,15 @@ static void php_memc_register_constants(INIT_FUNC_ARGS)
4282
4329
REGISTER_MEMC_CLASS_CONST_BOOL (HAVE_MSGPACK , 0 );
4283
4330
#endif
4284
4331
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
+
4285
4341
#ifdef HAVE_MEMCACHED_SESSION
4286
4342
REGISTER_MEMC_CLASS_CONST_BOOL (HAVE_SESSION , 1 );
4287
4343
#else
0 commit comments