Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 112c77e

Browse files
yatsukhnenkomichael-grunder
authored andcommitted
Issue #1508
Wrap all calls of `call_user_function` into `ra_call_user_function` where AUTH command sended before function call.
1 parent 85419ce commit 112c77e

3 files changed

Lines changed: 46 additions & 31 deletions

File tree

redis_array.c

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,19 @@ redis_array_get(zval *id TSRMLS_DC)
222222
return NULL;
223223
}
224224

225+
PHP_REDIS_API int
226+
ra_call_user_function(HashTable *function_table, zval *object, zval *function_name, zval *retval_ptr, uint param_count, zval params[] TSRMLS_DC)
227+
{
228+
if (object) {
229+
redis_object *redis = PHPREDIS_GET_OBJECT(redis_object, object);
230+
if (redis->sock->auth && redis->sock->status != REDIS_SOCK_STATUS_CONNECTED) {
231+
redis_sock_server_open(redis->sock TSRMLS_CC);
232+
redis_sock_auth(redis->sock TSRMLS_CC);
233+
}
234+
}
235+
return call_user_function(function_table, object, function_name, retval_ptr, param_count, params);
236+
}
237+
225238
/* {{{ proto RedisArray RedisArray::__construct()
226239
Public constructor */
227240
PHP_METHOD(RedisArray, __construct)
@@ -398,7 +411,7 @@ ra_forward_call(INTERNAL_FUNCTION_PARAMETERS, RedisArray *ra, const char *cmd, i
398411

399412
/* multi/exec */
400413
if(ra->z_multi_exec) {
401-
call_user_function(&redis_ce->function_table, ra->z_multi_exec, &z_fun, return_value, argc, z_callargs);
414+
ra_call_user_function(&redis_ce->function_table, ra->z_multi_exec, &z_fun, return_value, argc, z_callargs TSRMLS_CC);
402415
zval_dtor(return_value);
403416
zval_dtor(&z_fun);
404417
for (i = 0; i < argc; ++i) {
@@ -416,7 +429,7 @@ ra_forward_call(INTERNAL_FUNCTION_PARAMETERS, RedisArray *ra, const char *cmd, i
416429
/* add MULTI + SADD */
417430
ra_index_multi(redis_inst, MULTI TSRMLS_CC);
418431
/* call using discarded temp value and extract exec results after. */
419-
call_user_function(&redis_ce->function_table, redis_inst, &z_fun, return_value, argc, z_callargs);
432+
ra_call_user_function(&redis_ce->function_table, redis_inst, &z_fun, return_value, argc, z_callargs TSRMLS_CC);
420433
zval_dtor(return_value);
421434

422435
/* add keys to index. */
@@ -425,7 +438,7 @@ ra_forward_call(INTERNAL_FUNCTION_PARAMETERS, RedisArray *ra, const char *cmd, i
425438
/* call EXEC */
426439
ra_index_exec(redis_inst, return_value, 0 TSRMLS_CC);
427440
} else { /* call directly through. */
428-
call_user_function(&redis_ce->function_table, redis_inst, &z_fun, return_value, argc, z_callargs);
441+
ra_call_user_function(&redis_ce->function_table, redis_inst, &z_fun, return_value, argc, z_callargs TSRMLS_CC);
429442

430443
if (!b_write_cmd) {
431444
/* check if we have an error. */
@@ -634,7 +647,7 @@ PHP_METHOD(RedisArray, _continuum)
634647
static void
635648
multihost_distribute_call(RedisArray *ra, zval *return_value, zval *z_fun, int argc, zval *argv TSRMLS_DC)
636649
{
637-
zval z_arg;
650+
zval z_arg, z_tmp;
638651
int i;
639652

640653
/* Init our array return */
@@ -643,7 +656,7 @@ multihost_distribute_call(RedisArray *ra, zval *return_value, zval *z_fun, int a
643656
/* Iterate our RedisArray nodes */
644657
for (i = 0; i < ra->count; ++i) {
645658
/* Call each node in turn */
646-
call_user_function(&redis_array_ce->function_table, &ra->redis[i], z_fun, &z_arg, argc, argv);
659+
ra_call_user_function(&redis_array_ce->function_table, &ra->redis[i], z_fun, &z_tmp, argc, argv TSRMLS_CC);
647660

648661
/* Add the result for this host */
649662
add_assoc_zval_ex(return_value, ZSTR_VAL(ra->hosts[i]), ZSTR_LEN(ra->hosts[i]), &z_arg);
@@ -953,7 +966,7 @@ PHP_METHOD(RedisArray, mget)
953966
/* prepare call */
954967
ZVAL_STRINGL(&z_fun, "MGET", 4);
955968
/* call MGET on the node */
956-
call_user_function(&redis_ce->function_table, &ra->redis[n], &z_fun, &z_ret, 1, &z_argarray);
969+
ra_call_user_function(&redis_ce->function_table, &ra->redis[n], &z_fun, &z_ret, 1, &z_argarray TSRMLS_CC);
957970
zval_dtor(&z_fun);
958971

959972
/* cleanup args array */
@@ -1097,7 +1110,7 @@ PHP_METHOD(RedisArray, mset)
10971110
ZVAL_STRINGL(&z_fun, "MSET", 4);
10981111

10991112
/* call */
1100-
call_user_function(&redis_ce->function_table, &ra->redis[n], &z_fun, &z_ret, 1, &z_argarray);
1113+
ra_call_user_function(&redis_ce->function_table, &ra->redis[n], &z_fun, &z_ret, 1, &z_argarray TSRMLS_CC);
11011114
zval_dtor(&z_fun);
11021115
zval_dtor(&z_ret);
11031116

@@ -1229,7 +1242,7 @@ static void ra_generic_del(INTERNAL_FUNCTION_PARAMETERS, char *kw, int kw_len) {
12291242
}
12301243

12311244
/* call */
1232-
call_user_function(&redis_ce->function_table, &ra->redis[n], &z_fun, &z_ret, 1, &z_argarray);
1245+
ra_call_user_function(&redis_ce->function_table, &ra->redis[n], &z_fun, &z_ret, 1, &z_argarray TSRMLS_CC);
12331246

12341247
if(ra->index) {
12351248
zval_dtor(&z_ret);

redis_array.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,4 +69,6 @@ typedef struct RedisArray_ {
6969
zend_object *create_redis_array_object(zend_class_entry *ce TSRMLS_DC);
7070
void free_redis_array_object(zend_object *object);
7171

72+
PHP_REDIS_API int ra_call_user_function(HashTable *function_table, zval *object, zval *function_name, zval *retval_ptr, uint param_count, zval params[] TSRMLS_DC);
73+
7274
#endif

redis_array_impl.c

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,7 @@ ra_call_extractor(RedisArray *ra, const char *key, int key_len TSRMLS_DC)
470470
ZVAL_NULL(&z_ret);
471471
/* call extraction function */
472472
ZVAL_STRINGL(&z_argv, key, key_len);
473-
call_user_function(EG(function_table), NULL, &ra->z_fun, &z_ret, 1, &z_argv);
473+
ra_call_user_function(EG(function_table), NULL, &ra->z_fun, &z_ret, 1, &z_argv TSRMLS_CC);
474474

475475
if (Z_TYPE(z_ret) == IS_STRING) {
476476
out = zval_get_string(&z_ret);
@@ -511,7 +511,7 @@ ra_call_distributor(RedisArray *ra, const char *key, int key_len TSRMLS_DC)
511511
ZVAL_NULL(&z_ret);
512512
/* call extraction function */
513513
ZVAL_STRINGL(&z_argv, key, key_len);
514-
call_user_function(EG(function_table), NULL, &ra->z_dist, &z_ret, 1, &z_argv);
514+
ra_call_user_function(EG(function_table), NULL, &ra->z_dist, &z_ret, 1, &z_argv TSRMLS_CC);
515515

516516
ret = (Z_TYPE(z_ret) == IS_LONG) ? Z_LVAL(z_ret) : -1;
517517

@@ -609,7 +609,7 @@ ra_index_multi(zval *z_redis, long multi_value TSRMLS_DC) {
609609
/* run MULTI */
610610
ZVAL_STRINGL(&z_fun_multi, "MULTI", 5);
611611
ZVAL_LONG(&z_args[0], multi_value);
612-
call_user_function(&redis_ce->function_table, z_redis, &z_fun_multi, &z_ret, 1, z_args);
612+
ra_call_user_function(&redis_ce->function_table, z_redis, &z_fun_multi, &z_ret, 1, z_args TSRMLS_CC);
613613
zval_dtor(&z_fun_multi);
614614
zval_dtor(&z_ret);
615615
}
@@ -639,7 +639,7 @@ ra_index_change_keys(const char *cmd, zval *z_keys, zval *z_redis TSRMLS_DC) {
639639
}
640640

641641
/* run cmd */
642-
call_user_function(&redis_ce->function_table, z_redis, &z_fun, &z_ret, argc, z_args);
642+
ra_call_user_function(&redis_ce->function_table, z_redis, &z_fun, &z_ret, argc, z_args TSRMLS_CC);
643643

644644
zval_dtor(&z_args[0]);
645645
zval_dtor(&z_fun);
@@ -695,7 +695,7 @@ ra_index_key(const char *key, int key_len, zval *z_redis TSRMLS_DC) {
695695
ZVAL_STRINGL(&z_args[1], key, key_len);
696696

697697
/* run SADD */
698-
call_user_function(&redis_ce->function_table, z_redis, &z_fun_sadd, &z_ret, 2, z_args);
698+
ra_call_user_function(&redis_ce->function_table, z_redis, &z_fun_sadd, &z_ret, 2, z_args TSRMLS_CC);
699699
zval_dtor(&z_fun_sadd);
700700
zval_dtor(&z_args[1]);
701701
zval_dtor(&z_args[0]);
@@ -709,7 +709,7 @@ ra_index_exec(zval *z_redis, zval *return_value, int keep_all TSRMLS_DC) {
709709

710710
/* run EXEC */
711711
ZVAL_STRINGL(&z_fun_exec, "EXEC", 4);
712-
call_user_function(&redis_ce->function_table, z_redis, &z_fun_exec, &z_ret, 0, NULL);
712+
ra_call_user_function(&redis_ce->function_table, z_redis, &z_fun_exec, &z_ret, 0, NULL TSRMLS_CC);
713713
zval_dtor(&z_fun_exec);
714714

715715
/* extract first element of exec array and put into return_value. */
@@ -736,7 +736,7 @@ ra_index_discard(zval *z_redis, zval *return_value TSRMLS_DC) {
736736

737737
/* run DISCARD */
738738
ZVAL_STRINGL(&z_fun_discard, "DISCARD", 7);
739-
call_user_function(&redis_ce->function_table, z_redis, &z_fun_discard, &z_ret, 0, NULL);
739+
ra_call_user_function(&redis_ce->function_table, z_redis, &z_fun_discard, &z_ret, 0, NULL TSRMLS_CC);
740740

741741
zval_dtor(&z_fun_discard);
742742
zval_dtor(&z_ret);
@@ -749,7 +749,7 @@ ra_index_unwatch(zval *z_redis, zval *return_value TSRMLS_DC) {
749749

750750
/* run UNWATCH */
751751
ZVAL_STRINGL(&z_fun_unwatch, "UNWATCH", 7);
752-
call_user_function(&redis_ce->function_table, z_redis, &z_fun_unwatch, &z_ret, 0, NULL);
752+
ra_call_user_function(&redis_ce->function_table, z_redis, &z_fun_unwatch, &z_ret, 0, NULL TSRMLS_CC);
753753

754754
zval_dtor(&z_fun_unwatch);
755755
zval_dtor(&z_ret);
@@ -789,14 +789,14 @@ ra_get_key_type(zval *z_redis, const char *key, int key_len, zval *z_from, long
789789
/* run TYPE */
790790
ZVAL_NULL(&z_ret);
791791
ZVAL_STRINGL(&z_fun, "TYPE", 4);
792-
call_user_function(&redis_ce->function_table, z_redis, &z_fun, &z_ret, 1, &z_arg);
792+
ra_call_user_function(&redis_ce->function_table, z_redis, &z_fun, &z_ret, 1, &z_arg TSRMLS_CC);
793793
zval_dtor(&z_fun);
794794
zval_dtor(&z_ret);
795795

796796
/* run TYPE */
797797
ZVAL_NULL(&z_ret);
798798
ZVAL_STRINGL(&z_fun, "TTL", 3);
799-
call_user_function(&redis_ce->function_table, z_redis, &z_fun, &z_ret, 1, &z_arg);
799+
ra_call_user_function(&redis_ce->function_table, z_redis, &z_fun, &z_ret, 1, &z_arg TSRMLS_CC);
800800
zval_dtor(&z_fun);
801801
zval_dtor(&z_ret);
802802

@@ -828,7 +828,7 @@ ra_remove_from_index(zval *z_redis, const char *key, int key_len TSRMLS_DC) {
828828
ZVAL_STRINGL(&z_args[0], PHPREDIS_INDEX_NAME, sizeof(PHPREDIS_INDEX_NAME) - 1);
829829
ZVAL_STRINGL(&z_args[1], key, key_len);
830830

831-
call_user_function(&redis_ce->function_table, z_redis, &z_fun_srem, &z_ret, 2, z_args);
831+
ra_call_user_function(&redis_ce->function_table, z_redis, &z_fun_srem, &z_ret, 2, z_args TSRMLS_CC);
832832

833833
/* cleanup */
834834
zval_dtor(&z_fun_srem);
@@ -850,7 +850,7 @@ ra_del_key(const char *key, int key_len, zval *z_from TSRMLS_DC) {
850850
/* run DEL on source */
851851
ZVAL_STRINGL(&z_fun_del, "DEL", 3);
852852
ZVAL_STRINGL(&z_args[0], key, key_len);
853-
call_user_function(&redis_ce->function_table, z_from, &z_fun_del, &z_ret, 1, z_args);
853+
ra_call_user_function(&redis_ce->function_table, z_from, &z_fun_del, &z_ret, 1, z_args TSRMLS_CC);
854854
zval_dtor(&z_fun_del);
855855
zval_dtor(&z_args[0]);
856856
zval_dtor(&z_ret);
@@ -875,7 +875,7 @@ ra_expire_key(const char *key, int key_len, zval *z_to, long ttl TSRMLS_DC) {
875875
ZVAL_STRINGL(&z_fun_expire, "EXPIRE", 6);
876876
ZVAL_STRINGL(&z_args[0], key, key_len);
877877
ZVAL_LONG(&z_args[1], ttl);
878-
call_user_function(&redis_ce->function_table, z_to, &z_fun_expire, &z_ret, 2, z_args);
878+
ra_call_user_function(&redis_ce->function_table, z_to, &z_fun_expire, &z_ret, 2, z_args TSRMLS_CC);
879879
zval_dtor(&z_fun_expire);
880880
zval_dtor(&z_args[0]);
881881
zval_dtor(&z_ret);
@@ -899,7 +899,7 @@ ra_move_zset(const char *key, int key_len, zval *z_from, zval *z_to, long ttl TS
899899
ZVAL_STRINGL(&z_args[1], "0", 1);
900900
ZVAL_STRINGL(&z_args[2], "-1", 2);
901901
ZVAL_BOOL(&z_args[3], 1);
902-
call_user_function(&redis_ce->function_table, z_from, &z_fun_zrange, &z_ret, 4, z_args);
902+
ra_call_user_function(&redis_ce->function_table, z_from, &z_fun_zrange, &z_ret, 4, z_args TSRMLS_CC);
903903
zval_dtor(&z_fun_zrange);
904904
zval_dtor(&z_args[2]);
905905
zval_dtor(&z_args[1]);
@@ -937,7 +937,7 @@ ra_move_zset(const char *key, int key_len, zval *z_from, zval *z_to, long ttl TS
937937

938938
/* run ZADD on target */
939939
ZVAL_STRINGL(&z_fun_zadd, "ZADD", 4);
940-
call_user_function(&redis_ce->function_table, z_to, &z_fun_zadd, &z_ret_dest, 1 + 2 * count, z_zadd_args);
940+
ra_call_user_function(&redis_ce->function_table, z_to, &z_fun_zadd, &z_ret_dest, 1 + 2 * count, z_zadd_args TSRMLS_CC);
941941

942942
/* Expire if needed */
943943
ra_expire_key(key, key_len, z_to, ttl TSRMLS_CC);
@@ -964,7 +964,7 @@ ra_move_string(const char *key, int key_len, zval *z_from, zval *z_to, long ttl
964964
/* run GET on source */
965965
ZVAL_STRINGL(&z_fun_get, "GET", 3);
966966
ZVAL_STRINGL(&z_args[0], key, key_len);
967-
call_user_function(&redis_ce->function_table, z_from, &z_fun_get, &z_ret, 1, z_args);
967+
ra_call_user_function(&redis_ce->function_table, z_from, &z_fun_get, &z_ret, 1, z_args TSRMLS_CC);
968968
zval_dtor(&z_fun_get);
969969

970970
if(Z_TYPE(z_ret) != IS_STRING) { /* key not found or replaced */
@@ -980,14 +980,14 @@ ra_move_string(const char *key, int key_len, zval *z_from, zval *z_to, long ttl
980980
ZVAL_LONG(&z_args[1], ttl);
981981
ZVAL_STRINGL(&z_args[2], Z_STRVAL(z_ret), Z_STRLEN(z_ret)); /* copy z_ret to arg 1 */
982982
zval_dtor(&z_ret); /* free memory from our previous call */
983-
call_user_function(&redis_ce->function_table, z_to, &z_fun_set, &z_ret, 3, z_args);
983+
ra_call_user_function(&redis_ce->function_table, z_to, &z_fun_set, &z_ret, 3, z_args TSRMLS_CC);
984984
/* cleanup */
985985
zval_dtor(&z_args[2]);
986986
} else {
987987
ZVAL_STRINGL(&z_fun_set, "SET", 3);
988988
ZVAL_STRINGL(&z_args[1], Z_STRVAL(z_ret), Z_STRLEN(z_ret)); /* copy z_ret to arg 1 */
989989
zval_dtor(&z_ret); /* free memory from our previous return value */
990-
call_user_function(&redis_ce->function_table, z_to, &z_fun_set, &z_ret, 2, z_args);
990+
ra_call_user_function(&redis_ce->function_table, z_to, &z_fun_set, &z_ret, 2, z_args TSRMLS_CC);
991991
/* cleanup */
992992
zval_dtor(&z_args[1]);
993993
}
@@ -1005,7 +1005,7 @@ ra_move_hash(const char *key, int key_len, zval *z_from, zval *z_to, long ttl TS
10051005
/* run HGETALL on source */
10061006
ZVAL_STRINGL(&z_args[0], key, key_len);
10071007
ZVAL_STRINGL(&z_fun_hgetall, "HGETALL", 7);
1008-
call_user_function(&redis_ce->function_table, z_from, &z_fun_hgetall, &z_args[1], 1, z_args);
1008+
ra_call_user_function(&redis_ce->function_table, z_from, &z_fun_hgetall, &z_args[1], 1, z_args TSRMLS_CC);
10091009
zval_dtor(&z_fun_hgetall);
10101010

10111011
if (Z_TYPE(z_args[1]) != IS_ARRAY) { /* key not found or replaced */
@@ -1017,7 +1017,7 @@ ra_move_hash(const char *key, int key_len, zval *z_from, zval *z_to, long ttl TS
10171017

10181018
/* run HMSET on target */
10191019
ZVAL_STRINGL(&z_fun_hmset, "HMSET", 5);
1020-
call_user_function(&redis_ce->function_table, z_to, &z_fun_hmset, &z_ret_dest, 2, z_args);
1020+
ra_call_user_function(&redis_ce->function_table, z_to, &z_fun_hmset, &z_ret_dest, 2, z_args TSRMLS_CC);
10211021
zval_dtor(&z_fun_hmset);
10221022
zval_dtor(&z_ret_dest);
10231023

@@ -1052,7 +1052,7 @@ ra_move_collection(const char *key, int key_len, zval *z_from, zval *z_to,
10521052
ZVAL_STRING(&z_retrieve_args[i], cmd_list[i]);
10531053
}
10541054

1055-
call_user_function(&redis_ce->function_table, z_from, &z_fun_retrieve, &z_ret, list_count, z_retrieve_args);
1055+
ra_call_user_function(&redis_ce->function_table, z_from, &z_fun_retrieve, &z_ret, list_count, z_retrieve_args TSRMLS_CC);
10561056

10571057
/* cleanup */
10581058
zval_dtor(&z_fun_retrieve);
@@ -1084,7 +1084,7 @@ ra_move_collection(const char *key, int key_len, zval *z_from, zval *z_to,
10841084
/* Clean up our input return value */
10851085
zval_dtor(&z_ret);
10861086

1087-
call_user_function(&redis_ce->function_table, z_to, &z_fun_sadd, &z_ret, count, z_sadd_args);
1087+
ra_call_user_function(&redis_ce->function_table, z_to, &z_fun_sadd, &z_ret, count, z_sadd_args TSRMLS_CC);
10881088

10891089
/* cleanup */
10901090
zval_dtor(&z_fun_sadd);
@@ -1209,7 +1209,7 @@ ra_rehash_server(RedisArray *ra, zval *z_redis, zend_string *hostname, zend_bool
12091209
ZVAL_STRING(&z_argv, "*");
12101210
}
12111211
ZVAL_NULL(&z_ret);
1212-
call_user_function(&redis_ce->function_table, z_redis, &z_fun, &z_ret, 1, &z_argv);
1212+
ra_call_user_function(&redis_ce->function_table, z_redis, &z_fun, &z_ret, 1, &z_argv TSRMLS_CC);
12131213
zval_dtor(&z_argv);
12141214
zval_dtor(&z_fun);
12151215

0 commit comments

Comments
 (0)