50
50
#endif
51
51
52
52
#ifdef ZTS
53
- #define MEMC_G (v ) TSRMG(php_memcached_globals_id, zend_php_memcached_globals *, memc_ini .v)
53
+ #define MEMC_G (v ) TSRMG(php_memcached_globals_id, zend_php_memcached_globals *, memc .v)
54
54
#else
55
- #define MEMC_G (v ) (php_memcached_globals.memc_ini .v)
55
+ #define MEMC_G (v ) (php_memcached_globals.memc .v)
56
56
#endif
57
57
58
58
#include <ctype.h>
@@ -285,10 +285,10 @@ PHP_INI_MH(OnUpdateSessionPrefixString)
285
285
}
286
286
287
287
#define MEMC_INI_ENTRY (key , default_value , update_fn , gkey ) \
288
- STD_PHP_INI_ENTRY("memcached."key, default_value, PHP_INI_ALL, update_fn, memc_ini .gkey, zend_php_memcached_globals, php_memcached_globals)
288
+ STD_PHP_INI_ENTRY("memcached."key, default_value, PHP_INI_ALL, update_fn, memc .gkey, zend_php_memcached_globals, php_memcached_globals)
289
289
290
290
#define MEMC_SESSION_INI_ENTRY (key , default_value , update_fn , gkey ) \
291
- STD_PHP_INI_ENTRY("memcached.sess_"key, default_value, PHP_INI_ALL, update_fn, session_ini .gkey, zend_php_memcached_globals, php_memcached_globals)
291
+ STD_PHP_INI_ENTRY("memcached.sess_"key, default_value, PHP_INI_ALL, update_fn, session .gkey, zend_php_memcached_globals, php_memcached_globals)
292
292
293
293
294
294
/* {{{ INI entries */
@@ -298,7 +298,7 @@ PHP_INI_BEGIN()
298
298
MEMC_SESSION_INI_ENTRY ("locking" , "1" , OnUpdateBool , lock_enabled )
299
299
MEMC_SESSION_INI_ENTRY ("lock_wait_min" , "1000" , OnUpdateLongGEZero , lock_wait_min )
300
300
MEMC_SESSION_INI_ENTRY ("lock_wait_max" , "2000" , OnUpdateLongGEZero , lock_wait_max )
301
- MEMC_SESSION_INI_ENTRY ("lock_retries" , "5" , OnUpdateLongGEZero , lock_retries )
301
+ MEMC_SESSION_INI_ENTRY ("lock_retries" , "5" , OnUpdateLong , lock_retries )
302
302
MEMC_SESSION_INI_ENTRY ("lock_expire" , "0" , OnUpdateLongGEZero , lock_expiration )
303
303
MEMC_SESSION_INI_ENTRY ("compression" , "1" , OnUpdateBool , compression_enabled )
304
304
MEMC_SESSION_INI_ENTRY ("binary_protocol" , "1" , OnUpdateBool , binary_protocol_enabled )
@@ -323,9 +323,6 @@ PHP_INI_BEGIN()
323
323
MEMC_INI_ENTRY ("compression_factor" , "1.3" , OnUpdateReal , compression_factor )
324
324
MEMC_INI_ENTRY ("compression_threshold" , "2000" , OnUpdateLong , compression_threshold )
325
325
MEMC_INI_ENTRY ("serializer" , SERIALIZER_DEFAULT_NAME , OnUpdateSerializer , serializer_name )
326
- #if HAVE_MEMCACHED_SASL
327
- MEMC_INI_ENTRY ("use_sasl" , "0" , OnUpdateBool , sasl_enabled )
328
- #endif
329
326
MEMC_INI_ENTRY ("store_retry_count" , "2" , OnUpdateLong , store_retry_count )
330
327
PHP_INI_END ()
331
328
/* }}} */
@@ -367,7 +364,7 @@ static
367
364
void php_memc_destroy (memcached_st * memc , php_memc_user_data_t * memc_user_data );
368
365
369
366
static
370
- zend_bool s_memcached_result_to_zval (memcached_result_st * result , zval * return_value );
367
+ zend_bool s_memcached_result_to_zval (memcached_st * memc , memcached_result_st * result , zval * return_value );
371
368
372
369
static
373
370
zend_string * s_zval_to_payload (zval * value , uint32_t * flags , enum memcached_serializer serializer , enum memcached_compression_type compression_type );
@@ -377,6 +374,24 @@ static
377
374
Method implementations
378
375
****************************************/
379
376
377
+ zend_bool php_memc_init_sasl_if_needed ()
378
+ {
379
+ #if HAVE_MEMCACHED_SASL
380
+ if (MEMC_G (sasl_initialised )) {
381
+ return 1 ;
382
+ }
383
+ if (sasl_client_init (NULL ) != SASL_OK ) {
384
+ php_error_docref (NULL , E_ERROR , "Failed to initialize SASL library" );
385
+ return 0 ;
386
+ }
387
+ return 1 ;
388
+ #else
389
+ php_error_docref (NULL , E_ERROR , "Memcached not built with sasl support" );
390
+ return 0 ;
391
+ #endif
392
+ }
393
+
394
+
380
395
381
396
memcached_return php_memcached_exist (memcached_st * memc , zend_string * key )
382
397
{
@@ -816,7 +831,7 @@ memcached_return s_memcached_get_multi(memcached_st *memc, HashTable *hash_keys,
816
831
}
817
832
818
833
ZVAL_UNDEF (& value );
819
- if (!s_memcached_result_to_zval (& result , & value )) {
834
+ if (!s_memcached_result_to_zval (memc , & result , & value )) {
820
835
if (EG (exception )) {
821
836
status = MEMC_RES_PAYLOAD_FAILURE ;
822
837
@@ -1136,9 +1151,9 @@ PHP_METHOD(Memcached, fetch)
1136
1151
size_t res_key_len = 0 ;
1137
1152
const char * payload = NULL ;
1138
1153
size_t payload_len = 0 ;
1139
- zval value ;
1140
1154
uint32_t flags = 0 ;
1141
1155
uint64_t cas = 0 ;
1156
+ zval value , zv_cas ;
1142
1157
memcached_result_st result ;
1143
1158
memcached_return status = MEMCACHED_SUCCESS ;
1144
1159
MEMC_METHOD_INIT_VARS ;
@@ -1157,29 +1172,25 @@ PHP_METHOD(Memcached, fetch)
1157
1172
RETURN_FALSE ;
1158
1173
}
1159
1174
1160
- payload = memcached_result_value (& result );
1161
- payload_len = memcached_result_length (& result );
1162
- flags = memcached_result_flags (& result );
1163
- res_key = memcached_result_key_value (& result );
1164
- res_key_len = memcached_result_key_length (& result );
1165
- cas = memcached_result_cas (& result );
1166
-
1167
- if (!s_memcached_result_to_zval (& result , & value )) {
1175
+ if (!s_memcached_result_to_zval (intern -> memc , & result , & value )) {
1168
1176
memcached_result_free (& result );
1169
1177
intern -> rescode = MEMC_RES_PAYLOAD_FAILURE ;
1170
1178
RETURN_FALSE ;
1171
1179
}
1172
1180
1173
1181
array_init (return_value );
1174
- add_assoc_stringl_ex (return_value , ZEND_STRL ("key" ), (char * )res_key , res_key_len );
1175
- add_assoc_zval_ex (return_value , ZEND_STRL ("value" ), & value );
1176
- if (cas != 0 ) {
1177
- /* XXX: also check against ULLONG_MAX or memc_behavior */
1178
- add_assoc_double_ex (return_value , ZEND_STRL ("cas" ), (double )cas );
1179
- }
1180
- if (MEMC_VAL_GET_USER_FLAGS (flags ) != 0 ) {
1181
- add_assoc_long_ex (return_value , ZEND_STRL ("flags" ), MEMC_VAL_GET_USER_FLAGS (flags ));
1182
- }
1182
+
1183
+ flags = memcached_result_flags (& result );
1184
+ res_key = memcached_result_key_value (& result );
1185
+ res_key_len = memcached_result_key_length (& result );
1186
+ cas = memcached_result_cas (& result );
1187
+
1188
+ add_assoc_stringl_ex (return_value , ZEND_STRL ("key" ), (char * ) res_key , res_key_len );
1189
+ add_assoc_zval_ex (return_value , ZEND_STRL ("value" ), & value );
1190
+
1191
+ s_uint64_to_zval (& zv_cas , cas );
1192
+ add_assoc_zval_ex (return_value , ZEND_STRL ("cas" ), & zv_cas );
1193
+ add_assoc_long_ex (return_value , ZEND_STRL ("flags" ), MEMC_VAL_GET_USER_FLAGS (flags ));
1183
1194
1184
1195
memcached_result_free (& result );
1185
1196
}
@@ -1193,9 +1204,9 @@ PHP_METHOD(Memcached, fetchAll)
1193
1204
size_t res_key_len = 0 ;
1194
1205
const char * payload = NULL ;
1195
1206
size_t payload_len = 0 ;
1196
- zval value , entry ;
1197
1207
uint32_t flags ;
1198
1208
uint64_t cas = 0 ;
1209
+ zval value , entry , zv_cas ;
1199
1210
memcached_result_st result ;
1200
1211
memcached_return status = MEMCACHED_SUCCESS ;
1201
1212
MEMC_METHOD_INIT_VARS ;
@@ -1211,30 +1222,27 @@ PHP_METHOD(Memcached, fetchAll)
1211
1222
memcached_result_create (intern -> memc , & result );
1212
1223
1213
1224
while ((memcached_fetch_result (intern -> memc , & result , & status )) != NULL ) {
1214
- payload = memcached_result_value (& result );
1215
- payload_len = memcached_result_length (& result );
1216
- flags = memcached_result_flags (& result );
1217
- res_key = memcached_result_key_value (& result );
1218
- res_key_len = memcached_result_key_length (& result );
1219
- cas = memcached_result_cas (& result );
1220
1225
1221
- if (!s_memcached_result_to_zval (& result , & value )) {
1226
+ if (!s_memcached_result_to_zval (intern -> memc , & result , & value )) {
1222
1227
memcached_result_free (& result );
1223
1228
zval_dtor (return_value );
1224
1229
intern -> rescode = MEMC_RES_PAYLOAD_FAILURE ;
1225
1230
RETURN_FALSE ;
1226
1231
}
1227
1232
1233
+ flags = memcached_result_flags (& result );
1234
+ res_key = memcached_result_key_value (& result );
1235
+ res_key_len = memcached_result_key_length (& result );
1236
+ cas = memcached_result_cas (& result );
1237
+
1228
1238
array_init (& entry );
1229
1239
add_assoc_stringl_ex (& entry , ZEND_STRL ("key" ), (char * )res_key , res_key_len );
1230
- add_assoc_zval_ex (& entry , ZEND_STRL ("value" ), & value );
1231
- if (cas != 0 ) {
1232
- /* XXX: also check against ULLONG_MAX or memc_behavior */
1233
- add_assoc_double_ex (& entry , ZEND_STRL ("cas" ), (double )cas );
1234
- }
1235
- if (MEMC_VAL_GET_USER_FLAGS (flags ) != 0 ) {
1236
- add_assoc_long_ex (& entry , ZEND_STRL ("flags" ), MEMC_VAL_GET_USER_FLAGS (flags ));
1237
- }
1240
+ add_assoc_zval_ex (& entry , ZEND_STRL ("value" ), & value );
1241
+
1242
+ s_uint64_to_zval (& zv_cas , cas );
1243
+ add_assoc_zval_ex (& entry , ZEND_STRL ("cas" ), & zv_cas );
1244
+ add_assoc_long_ex (& entry , ZEND_STRL ("flags" ), MEMC_VAL_GET_USER_FLAGS (flags ));
1245
+
1238
1246
add_next_index_zval (return_value , & entry );
1239
1247
}
1240
1248
@@ -2825,8 +2833,7 @@ static PHP_METHOD(Memcached, setSaslAuthData)
2825
2833
return ;
2826
2834
}
2827
2835
2828
- if (!MEMC_G (sasl_enabled )) {
2829
- php_error_docref (NULL , E_WARNING , "SASL support (memcached.use_sasl) isn't enabled in php.ini" );
2836
+ if (!php_memc_init_sasl_if_needed ()) {
2830
2837
RETURN_FALSE ;
2831
2838
}
2832
2839
@@ -3363,7 +3370,7 @@ zend_string *s_decompress_value (const char *payload, size_t payload_len, uint32
3363
3370
}
3364
3371
3365
3372
static
3366
- zend_bool s_unserialize_value (int val_type , zend_string * payload , zval * return_value )
3373
+ zend_bool s_unserialize_value (memcached_st * memc , int val_type , zend_string * payload , zval * return_value )
3367
3374
{
3368
3375
switch (val_type ) {
3369
3376
case MEMC_VAL_IS_SERIALIZED :
@@ -3402,7 +3409,10 @@ zend_bool s_unserialize_value (int val_type, zend_string *payload, zval *return_
3402
3409
3403
3410
case MEMC_VAL_IS_JSON :
3404
3411
#ifdef HAVE_JSON_API
3405
- php_json_decode (return_value , payload -> val , payload -> len , (serializer == SERIALIZER_JSON_ARRAY ), PHP_JSON_PARSER_DEFAULT_DEPTH );
3412
+ {
3413
+ php_memc_user_data_t * memc_user_data = memcached_get_user_data (memc );
3414
+ php_json_decode (return_value , payload -> val , payload -> len , (memc_user_data -> serializer == SERIALIZER_JSON_ARRAY ), PHP_JSON_PARSER_DEFAULT_DEPTH );
3415
+ }
3406
3416
#else
3407
3417
ZVAL_FALSE (return_value );
3408
3418
php_error_docref (NULL , E_WARNING , "could not unserialize value, no json support" );
@@ -3424,7 +3434,7 @@ zend_bool s_unserialize_value (int val_type, zend_string *payload, zval *return_
3424
3434
}
3425
3435
3426
3436
static
3427
- zend_bool s_memcached_result_to_zval (memcached_result_st * result , zval * return_value )
3437
+ zend_bool s_memcached_result_to_zval (memcached_st * memc , memcached_result_st * result , zval * return_value )
3428
3438
{
3429
3439
zend_string * data ;
3430
3440
const char * payload ;
@@ -3485,7 +3495,7 @@ zend_bool s_memcached_result_to_zval(memcached_result_st *result, zval *return_v
3485
3495
case MEMC_VAL_IS_IGBINARY :
3486
3496
case MEMC_VAL_IS_JSON :
3487
3497
case MEMC_VAL_IS_MSGPACK :
3488
- retval = s_unserialize_value (MEMC_VAL_GET_TYPE (flags ), data , return_value );
3498
+ retval = s_unserialize_value (memc , MEMC_VAL_GET_TYPE (flags ), data , return_value );
3489
3499
break ;
3490
3500
3491
3501
default :
@@ -3648,7 +3658,7 @@ int s_invoke_result_callback(zval *zmemc_obj, zend_fcall_info *fci, zend_fcall_i
3648
3658
3649
3659
intern = Z_MEMC_OBJ_P (zmemc_obj );
3650
3660
3651
- if (!s_memcached_result_to_zval (result , & value )) {
3661
+ if (!s_memcached_result_to_zval (intern -> memc , result , & value )) {
3652
3662
intern -> rescode = MEMC_RES_PAYLOAD_FAILURE ;
3653
3663
return -1 ;
3654
3664
}
@@ -4159,37 +4169,35 @@ PHP_GINIT_FUNCTION(php_memcached)
4159
4169
{
4160
4170
#ifdef HAVE_MEMCACHED_SESSION
4161
4171
4162
- php_memcached_globals -> session_ini .lock_enabled = 0 ;
4163
- php_memcached_globals -> session_ini .lock_wait_max = 2000 ;
4164
- php_memcached_globals -> session_ini .lock_wait_min = 1000 ;
4165
- php_memcached_globals -> session_ini .lock_retries = 5 ;
4166
- php_memcached_globals -> session_ini .lock_expiration = 30 ;
4167
- php_memcached_globals -> session_ini .compression_enabled = 1 ;
4168
- php_memcached_globals -> session_ini .binary_protocol_enabled = 1 ;
4169
- php_memcached_globals -> session_ini .consistent_hash_enabled = 1 ;
4170
- php_memcached_globals -> session_ini .number_of_replicas = 0 ;
4171
- php_memcached_globals -> session_ini .server_failure_limit = 1 ;
4172
- php_memcached_globals -> session_ini .randomize_replica_read_enabled = 1 ;
4173
- php_memcached_globals -> session_ini .remove_failed_servers_enabled = 1 ;
4174
- php_memcached_globals -> session_ini .connect_timeout = 1000 ;
4175
- php_memcached_globals -> session_ini .prefix = NULL ;
4176
- php_memcached_globals -> session_ini .persistent_enabled = 0 ;
4177
- php_memcached_globals -> session_ini .sasl_username = NULL ;
4178
- php_memcached_globals -> session_ini .sasl_password = NULL ;
4172
+ php_memcached_globals -> session .lock_enabled = 0 ;
4173
+ php_memcached_globals -> session .lock_wait_max = 2000 ;
4174
+ php_memcached_globals -> session .lock_wait_min = 1000 ;
4175
+ php_memcached_globals -> session .lock_retries = 5 ;
4176
+ php_memcached_globals -> session .lock_expiration = 30 ;
4177
+ php_memcached_globals -> session .compression_enabled = 1 ;
4178
+ php_memcached_globals -> session .binary_protocol_enabled = 1 ;
4179
+ php_memcached_globals -> session .consistent_hash_enabled = 1 ;
4180
+ php_memcached_globals -> session .number_of_replicas = 0 ;
4181
+ php_memcached_globals -> session .server_failure_limit = 1 ;
4182
+ php_memcached_globals -> session .randomize_replica_read_enabled = 1 ;
4183
+ php_memcached_globals -> session .remove_failed_servers_enabled = 1 ;
4184
+ php_memcached_globals -> session .connect_timeout = 1000 ;
4185
+ php_memcached_globals -> session .prefix = NULL ;
4186
+ php_memcached_globals -> session .persistent_enabled = 0 ;
4187
+ php_memcached_globals -> session .sasl_username = NULL ;
4188
+ php_memcached_globals -> session .sasl_password = NULL ;
4179
4189
4180
- php_memcached_globals -> no_effect = 0 ;
4181
-
4182
- #endif
4183
- php_memcached_globals -> memc_ini .serializer_name = NULL ;
4184
- php_memcached_globals -> memc_ini .serializer = SERIALIZER_DEFAULT ;
4185
- php_memcached_globals -> memc_ini .compression_type = NULL ;
4186
- php_memcached_globals -> memc_ini .compression_threshold = 2000 ;
4187
- php_memcached_globals -> memc_ini .compression_type_real = COMPRESSION_TYPE_FASTLZ ;
4188
- php_memcached_globals -> memc_ini .compression_factor = 1.30 ;
4189
- php_memcached_globals -> memc_ini .store_retry_count = 2 ;
4190
- #if HAVE_MEMCACHED_SASL
4191
- php_memcached_globals -> memc_ini .sasl_enabled = 0 ;
4192
4190
#endif
4191
+ php_memcached_globals -> memc .serializer_name = NULL ;
4192
+ php_memcached_globals -> memc .serializer = SERIALIZER_DEFAULT ;
4193
+ php_memcached_globals -> memc .compression_type = NULL ;
4194
+ php_memcached_globals -> memc .compression_threshold = 2000 ;
4195
+ php_memcached_globals -> memc .compression_type_real = COMPRESSION_TYPE_FASTLZ ;
4196
+ php_memcached_globals -> memc .compression_factor = 1.30 ;
4197
+ php_memcached_globals -> memc .store_retry_count = 2 ;
4198
+
4199
+ php_memcached_globals -> memc .sasl_initialised = 0 ;
4200
+ php_memcached_globals -> no_effect = 0 ;
4193
4201
}
4194
4202
4195
4203
zend_module_entry memcached_module_entry = {
@@ -4385,11 +4393,11 @@ static void php_memc_register_constants(INIT_FUNC_ARGS)
4385
4393
/*
4386
4394
* Serializer types.
4387
4395
*/
4388
- REGISTER_MEMC_CLASS_CONST_LONG (SERIALIZER_PHP , SERIALIZER_PHP );
4389
- REGISTER_MEMC_CLASS_CONST_LONG (SERIALIZER_IGBINARY , SERIALIZER_IGBINARY );
4390
- REGISTER_MEMC_CLASS_CONST_LONG (SERIALIZER_JSON , SERIALIZER_JSON );
4396
+ REGISTER_MEMC_CLASS_CONST_LONG (SERIALIZER_PHP , SERIALIZER_PHP );
4397
+ REGISTER_MEMC_CLASS_CONST_LONG (SERIALIZER_IGBINARY , SERIALIZER_IGBINARY );
4398
+ REGISTER_MEMC_CLASS_CONST_LONG (SERIALIZER_JSON , SERIALIZER_JSON );
4391
4399
REGISTER_MEMC_CLASS_CONST_LONG (SERIALIZER_JSON_ARRAY , SERIALIZER_JSON_ARRAY );
4392
- REGISTER_MEMC_CLASS_CONST_LONG (SERIALIZER_MSGPACK , SERIALIZER_MSGPACK );
4400
+ REGISTER_MEMC_CLASS_CONST_LONG (SERIALIZER_MSGPACK , SERIALIZER_MSGPACK );
4393
4401
4394
4402
/*
4395
4403
* Compression types
@@ -4487,15 +4495,6 @@ PHP_MINIT_FUNCTION(memcached)
4487
4495
#ifdef HAVE_MEMCACHED_SESSION
4488
4496
php_memc_session_minit (module_number );
4489
4497
#endif
4490
-
4491
- #if HAVE_MEMCACHED_SASL
4492
- if (MEMC_G (sasl_enabled )) {
4493
- if (sasl_client_init (NULL ) != SASL_OK ) {
4494
- php_error_docref (NULL , E_ERROR , "Failed to initialize SASL library" );
4495
- return FAILURE ;
4496
- }
4497
- }
4498
- #endif
4499
4498
return SUCCESS ;
4500
4499
}
4501
4500
/* }}} */
@@ -4504,7 +4503,7 @@ PHP_MINIT_FUNCTION(memcached)
4504
4503
PHP_MSHUTDOWN_FUNCTION (memcached )
4505
4504
{
4506
4505
#if HAVE_MEMCACHED_SASL
4507
- if (MEMC_G (sasl_enabled )) {
4506
+ if (MEMC_G (sasl_initialised )) {
4508
4507
sasl_done ();
4509
4508
}
4510
4509
#endif
0 commit comments