mirror of
https://github.com/php-win-ext/phpredis.git
synced 2026-03-24 17:12:15 +01:00
Issue #1508
Wrap all calls of `call_user_function` into `ra_call_user_function` where AUTH command sended before function call.
This commit is contained in:
committed by
michael-grunder
parent
85419ce7d3
commit
112c77e3a1
@@ -222,6 +222,19 @@ redis_array_get(zval *id TSRMLS_DC)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
if (object) {
|
||||
redis_object *redis = PHPREDIS_GET_OBJECT(redis_object, object);
|
||||
if (redis->sock->auth && redis->sock->status != REDIS_SOCK_STATUS_CONNECTED) {
|
||||
redis_sock_server_open(redis->sock TSRMLS_CC);
|
||||
redis_sock_auth(redis->sock TSRMLS_CC);
|
||||
}
|
||||
}
|
||||
return call_user_function(function_table, object, function_name, retval_ptr, param_count, params);
|
||||
}
|
||||
|
||||
/* {{{ proto RedisArray RedisArray::__construct()
|
||||
Public constructor */
|
||||
PHP_METHOD(RedisArray, __construct)
|
||||
@@ -398,7 +411,7 @@ ra_forward_call(INTERNAL_FUNCTION_PARAMETERS, RedisArray *ra, const char *cmd, i
|
||||
|
||||
/* multi/exec */
|
||||
if(ra->z_multi_exec) {
|
||||
call_user_function(&redis_ce->function_table, ra->z_multi_exec, &z_fun, return_value, argc, z_callargs);
|
||||
ra_call_user_function(&redis_ce->function_table, ra->z_multi_exec, &z_fun, return_value, argc, z_callargs TSRMLS_CC);
|
||||
zval_dtor(return_value);
|
||||
zval_dtor(&z_fun);
|
||||
for (i = 0; i < argc; ++i) {
|
||||
@@ -416,7 +429,7 @@ ra_forward_call(INTERNAL_FUNCTION_PARAMETERS, RedisArray *ra, const char *cmd, i
|
||||
/* add MULTI + SADD */
|
||||
ra_index_multi(redis_inst, MULTI TSRMLS_CC);
|
||||
/* call using discarded temp value and extract exec results after. */
|
||||
call_user_function(&redis_ce->function_table, redis_inst, &z_fun, return_value, argc, z_callargs);
|
||||
ra_call_user_function(&redis_ce->function_table, redis_inst, &z_fun, return_value, argc, z_callargs TSRMLS_CC);
|
||||
zval_dtor(return_value);
|
||||
|
||||
/* add keys to index. */
|
||||
@@ -425,7 +438,7 @@ ra_forward_call(INTERNAL_FUNCTION_PARAMETERS, RedisArray *ra, const char *cmd, i
|
||||
/* call EXEC */
|
||||
ra_index_exec(redis_inst, return_value, 0 TSRMLS_CC);
|
||||
} else { /* call directly through. */
|
||||
call_user_function(&redis_ce->function_table, redis_inst, &z_fun, return_value, argc, z_callargs);
|
||||
ra_call_user_function(&redis_ce->function_table, redis_inst, &z_fun, return_value, argc, z_callargs TSRMLS_CC);
|
||||
|
||||
if (!b_write_cmd) {
|
||||
/* check if we have an error. */
|
||||
@@ -634,7 +647,7 @@ PHP_METHOD(RedisArray, _continuum)
|
||||
static void
|
||||
multihost_distribute_call(RedisArray *ra, zval *return_value, zval *z_fun, int argc, zval *argv TSRMLS_DC)
|
||||
{
|
||||
zval z_arg;
|
||||
zval z_arg, z_tmp;
|
||||
int i;
|
||||
|
||||
/* Init our array return */
|
||||
@@ -643,7 +656,7 @@ multihost_distribute_call(RedisArray *ra, zval *return_value, zval *z_fun, int a
|
||||
/* Iterate our RedisArray nodes */
|
||||
for (i = 0; i < ra->count; ++i) {
|
||||
/* Call each node in turn */
|
||||
call_user_function(&redis_array_ce->function_table, &ra->redis[i], z_fun, &z_arg, argc, argv);
|
||||
ra_call_user_function(&redis_array_ce->function_table, &ra->redis[i], z_fun, &z_tmp, argc, argv TSRMLS_CC);
|
||||
|
||||
/* Add the result for this host */
|
||||
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)
|
||||
/* prepare call */
|
||||
ZVAL_STRINGL(&z_fun, "MGET", 4);
|
||||
/* call MGET on the node */
|
||||
call_user_function(&redis_ce->function_table, &ra->redis[n], &z_fun, &z_ret, 1, &z_argarray);
|
||||
ra_call_user_function(&redis_ce->function_table, &ra->redis[n], &z_fun, &z_ret, 1, &z_argarray TSRMLS_CC);
|
||||
zval_dtor(&z_fun);
|
||||
|
||||
/* cleanup args array */
|
||||
@@ -1097,7 +1110,7 @@ PHP_METHOD(RedisArray, mset)
|
||||
ZVAL_STRINGL(&z_fun, "MSET", 4);
|
||||
|
||||
/* call */
|
||||
call_user_function(&redis_ce->function_table, &ra->redis[n], &z_fun, &z_ret, 1, &z_argarray);
|
||||
ra_call_user_function(&redis_ce->function_table, &ra->redis[n], &z_fun, &z_ret, 1, &z_argarray TSRMLS_CC);
|
||||
zval_dtor(&z_fun);
|
||||
zval_dtor(&z_ret);
|
||||
|
||||
@@ -1229,7 +1242,7 @@ static void ra_generic_del(INTERNAL_FUNCTION_PARAMETERS, char *kw, int kw_len) {
|
||||
}
|
||||
|
||||
/* call */
|
||||
call_user_function(&redis_ce->function_table, &ra->redis[n], &z_fun, &z_ret, 1, &z_argarray);
|
||||
ra_call_user_function(&redis_ce->function_table, &ra->redis[n], &z_fun, &z_ret, 1, &z_argarray TSRMLS_CC);
|
||||
|
||||
if(ra->index) {
|
||||
zval_dtor(&z_ret);
|
||||
|
||||
@@ -69,4 +69,6 @@ typedef struct RedisArray_ {
|
||||
zend_object *create_redis_array_object(zend_class_entry *ce TSRMLS_DC);
|
||||
void free_redis_array_object(zend_object *object);
|
||||
|
||||
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);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -470,7 +470,7 @@ ra_call_extractor(RedisArray *ra, const char *key, int key_len TSRMLS_DC)
|
||||
ZVAL_NULL(&z_ret);
|
||||
/* call extraction function */
|
||||
ZVAL_STRINGL(&z_argv, key, key_len);
|
||||
call_user_function(EG(function_table), NULL, &ra->z_fun, &z_ret, 1, &z_argv);
|
||||
ra_call_user_function(EG(function_table), NULL, &ra->z_fun, &z_ret, 1, &z_argv TSRMLS_CC);
|
||||
|
||||
if (Z_TYPE(z_ret) == IS_STRING) {
|
||||
out = zval_get_string(&z_ret);
|
||||
@@ -511,7 +511,7 @@ ra_call_distributor(RedisArray *ra, const char *key, int key_len TSRMLS_DC)
|
||||
ZVAL_NULL(&z_ret);
|
||||
/* call extraction function */
|
||||
ZVAL_STRINGL(&z_argv, key, key_len);
|
||||
call_user_function(EG(function_table), NULL, &ra->z_dist, &z_ret, 1, &z_argv);
|
||||
ra_call_user_function(EG(function_table), NULL, &ra->z_dist, &z_ret, 1, &z_argv TSRMLS_CC);
|
||||
|
||||
ret = (Z_TYPE(z_ret) == IS_LONG) ? Z_LVAL(z_ret) : -1;
|
||||
|
||||
@@ -609,7 +609,7 @@ ra_index_multi(zval *z_redis, long multi_value TSRMLS_DC) {
|
||||
/* run MULTI */
|
||||
ZVAL_STRINGL(&z_fun_multi, "MULTI", 5);
|
||||
ZVAL_LONG(&z_args[0], multi_value);
|
||||
call_user_function(&redis_ce->function_table, z_redis, &z_fun_multi, &z_ret, 1, z_args);
|
||||
ra_call_user_function(&redis_ce->function_table, z_redis, &z_fun_multi, &z_ret, 1, z_args TSRMLS_CC);
|
||||
zval_dtor(&z_fun_multi);
|
||||
zval_dtor(&z_ret);
|
||||
}
|
||||
@@ -639,7 +639,7 @@ ra_index_change_keys(const char *cmd, zval *z_keys, zval *z_redis TSRMLS_DC) {
|
||||
}
|
||||
|
||||
/* run cmd */
|
||||
call_user_function(&redis_ce->function_table, z_redis, &z_fun, &z_ret, argc, z_args);
|
||||
ra_call_user_function(&redis_ce->function_table, z_redis, &z_fun, &z_ret, argc, z_args TSRMLS_CC);
|
||||
|
||||
zval_dtor(&z_args[0]);
|
||||
zval_dtor(&z_fun);
|
||||
@@ -695,7 +695,7 @@ ra_index_key(const char *key, int key_len, zval *z_redis TSRMLS_DC) {
|
||||
ZVAL_STRINGL(&z_args[1], key, key_len);
|
||||
|
||||
/* run SADD */
|
||||
call_user_function(&redis_ce->function_table, z_redis, &z_fun_sadd, &z_ret, 2, z_args);
|
||||
ra_call_user_function(&redis_ce->function_table, z_redis, &z_fun_sadd, &z_ret, 2, z_args TSRMLS_CC);
|
||||
zval_dtor(&z_fun_sadd);
|
||||
zval_dtor(&z_args[1]);
|
||||
zval_dtor(&z_args[0]);
|
||||
@@ -709,7 +709,7 @@ ra_index_exec(zval *z_redis, zval *return_value, int keep_all TSRMLS_DC) {
|
||||
|
||||
/* run EXEC */
|
||||
ZVAL_STRINGL(&z_fun_exec, "EXEC", 4);
|
||||
call_user_function(&redis_ce->function_table, z_redis, &z_fun_exec, &z_ret, 0, NULL);
|
||||
ra_call_user_function(&redis_ce->function_table, z_redis, &z_fun_exec, &z_ret, 0, NULL TSRMLS_CC);
|
||||
zval_dtor(&z_fun_exec);
|
||||
|
||||
/* 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) {
|
||||
|
||||
/* run DISCARD */
|
||||
ZVAL_STRINGL(&z_fun_discard, "DISCARD", 7);
|
||||
call_user_function(&redis_ce->function_table, z_redis, &z_fun_discard, &z_ret, 0, NULL);
|
||||
ra_call_user_function(&redis_ce->function_table, z_redis, &z_fun_discard, &z_ret, 0, NULL TSRMLS_CC);
|
||||
|
||||
zval_dtor(&z_fun_discard);
|
||||
zval_dtor(&z_ret);
|
||||
@@ -749,7 +749,7 @@ ra_index_unwatch(zval *z_redis, zval *return_value TSRMLS_DC) {
|
||||
|
||||
/* run UNWATCH */
|
||||
ZVAL_STRINGL(&z_fun_unwatch, "UNWATCH", 7);
|
||||
call_user_function(&redis_ce->function_table, z_redis, &z_fun_unwatch, &z_ret, 0, NULL);
|
||||
ra_call_user_function(&redis_ce->function_table, z_redis, &z_fun_unwatch, &z_ret, 0, NULL TSRMLS_CC);
|
||||
|
||||
zval_dtor(&z_fun_unwatch);
|
||||
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
|
||||
/* run TYPE */
|
||||
ZVAL_NULL(&z_ret);
|
||||
ZVAL_STRINGL(&z_fun, "TYPE", 4);
|
||||
call_user_function(&redis_ce->function_table, z_redis, &z_fun, &z_ret, 1, &z_arg);
|
||||
ra_call_user_function(&redis_ce->function_table, z_redis, &z_fun, &z_ret, 1, &z_arg TSRMLS_CC);
|
||||
zval_dtor(&z_fun);
|
||||
zval_dtor(&z_ret);
|
||||
|
||||
/* run TYPE */
|
||||
ZVAL_NULL(&z_ret);
|
||||
ZVAL_STRINGL(&z_fun, "TTL", 3);
|
||||
call_user_function(&redis_ce->function_table, z_redis, &z_fun, &z_ret, 1, &z_arg);
|
||||
ra_call_user_function(&redis_ce->function_table, z_redis, &z_fun, &z_ret, 1, &z_arg TSRMLS_CC);
|
||||
zval_dtor(&z_fun);
|
||||
zval_dtor(&z_ret);
|
||||
|
||||
@@ -828,7 +828,7 @@ ra_remove_from_index(zval *z_redis, const char *key, int key_len TSRMLS_DC) {
|
||||
ZVAL_STRINGL(&z_args[0], PHPREDIS_INDEX_NAME, sizeof(PHPREDIS_INDEX_NAME) - 1);
|
||||
ZVAL_STRINGL(&z_args[1], key, key_len);
|
||||
|
||||
call_user_function(&redis_ce->function_table, z_redis, &z_fun_srem, &z_ret, 2, z_args);
|
||||
ra_call_user_function(&redis_ce->function_table, z_redis, &z_fun_srem, &z_ret, 2, z_args TSRMLS_CC);
|
||||
|
||||
/* cleanup */
|
||||
zval_dtor(&z_fun_srem);
|
||||
@@ -850,7 +850,7 @@ ra_del_key(const char *key, int key_len, zval *z_from TSRMLS_DC) {
|
||||
/* run DEL on source */
|
||||
ZVAL_STRINGL(&z_fun_del, "DEL", 3);
|
||||
ZVAL_STRINGL(&z_args[0], key, key_len);
|
||||
call_user_function(&redis_ce->function_table, z_from, &z_fun_del, &z_ret, 1, z_args);
|
||||
ra_call_user_function(&redis_ce->function_table, z_from, &z_fun_del, &z_ret, 1, z_args TSRMLS_CC);
|
||||
zval_dtor(&z_fun_del);
|
||||
zval_dtor(&z_args[0]);
|
||||
zval_dtor(&z_ret);
|
||||
@@ -875,7 +875,7 @@ ra_expire_key(const char *key, int key_len, zval *z_to, long ttl TSRMLS_DC) {
|
||||
ZVAL_STRINGL(&z_fun_expire, "EXPIRE", 6);
|
||||
ZVAL_STRINGL(&z_args[0], key, key_len);
|
||||
ZVAL_LONG(&z_args[1], ttl);
|
||||
call_user_function(&redis_ce->function_table, z_to, &z_fun_expire, &z_ret, 2, z_args);
|
||||
ra_call_user_function(&redis_ce->function_table, z_to, &z_fun_expire, &z_ret, 2, z_args TSRMLS_CC);
|
||||
zval_dtor(&z_fun_expire);
|
||||
zval_dtor(&z_args[0]);
|
||||
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
|
||||
ZVAL_STRINGL(&z_args[1], "0", 1);
|
||||
ZVAL_STRINGL(&z_args[2], "-1", 2);
|
||||
ZVAL_BOOL(&z_args[3], 1);
|
||||
call_user_function(&redis_ce->function_table, z_from, &z_fun_zrange, &z_ret, 4, z_args);
|
||||
ra_call_user_function(&redis_ce->function_table, z_from, &z_fun_zrange, &z_ret, 4, z_args TSRMLS_CC);
|
||||
zval_dtor(&z_fun_zrange);
|
||||
zval_dtor(&z_args[2]);
|
||||
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
|
||||
|
||||
/* run ZADD on target */
|
||||
ZVAL_STRINGL(&z_fun_zadd, "ZADD", 4);
|
||||
call_user_function(&redis_ce->function_table, z_to, &z_fun_zadd, &z_ret_dest, 1 + 2 * count, z_zadd_args);
|
||||
ra_call_user_function(&redis_ce->function_table, z_to, &z_fun_zadd, &z_ret_dest, 1 + 2 * count, z_zadd_args TSRMLS_CC);
|
||||
|
||||
/* Expire if needed */
|
||||
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
|
||||
/* run GET on source */
|
||||
ZVAL_STRINGL(&z_fun_get, "GET", 3);
|
||||
ZVAL_STRINGL(&z_args[0], key, key_len);
|
||||
call_user_function(&redis_ce->function_table, z_from, &z_fun_get, &z_ret, 1, z_args);
|
||||
ra_call_user_function(&redis_ce->function_table, z_from, &z_fun_get, &z_ret, 1, z_args TSRMLS_CC);
|
||||
zval_dtor(&z_fun_get);
|
||||
|
||||
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
|
||||
ZVAL_LONG(&z_args[1], ttl);
|
||||
ZVAL_STRINGL(&z_args[2], Z_STRVAL(z_ret), Z_STRLEN(z_ret)); /* copy z_ret to arg 1 */
|
||||
zval_dtor(&z_ret); /* free memory from our previous call */
|
||||
call_user_function(&redis_ce->function_table, z_to, &z_fun_set, &z_ret, 3, z_args);
|
||||
ra_call_user_function(&redis_ce->function_table, z_to, &z_fun_set, &z_ret, 3, z_args TSRMLS_CC);
|
||||
/* cleanup */
|
||||
zval_dtor(&z_args[2]);
|
||||
} else {
|
||||
ZVAL_STRINGL(&z_fun_set, "SET", 3);
|
||||
ZVAL_STRINGL(&z_args[1], Z_STRVAL(z_ret), Z_STRLEN(z_ret)); /* copy z_ret to arg 1 */
|
||||
zval_dtor(&z_ret); /* free memory from our previous return value */
|
||||
call_user_function(&redis_ce->function_table, z_to, &z_fun_set, &z_ret, 2, z_args);
|
||||
ra_call_user_function(&redis_ce->function_table, z_to, &z_fun_set, &z_ret, 2, z_args TSRMLS_CC);
|
||||
/* cleanup */
|
||||
zval_dtor(&z_args[1]);
|
||||
}
|
||||
@@ -1005,7 +1005,7 @@ ra_move_hash(const char *key, int key_len, zval *z_from, zval *z_to, long ttl TS
|
||||
/* run HGETALL on source */
|
||||
ZVAL_STRINGL(&z_args[0], key, key_len);
|
||||
ZVAL_STRINGL(&z_fun_hgetall, "HGETALL", 7);
|
||||
call_user_function(&redis_ce->function_table, z_from, &z_fun_hgetall, &z_args[1], 1, z_args);
|
||||
ra_call_user_function(&redis_ce->function_table, z_from, &z_fun_hgetall, &z_args[1], 1, z_args TSRMLS_CC);
|
||||
zval_dtor(&z_fun_hgetall);
|
||||
|
||||
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
|
||||
|
||||
/* run HMSET on target */
|
||||
ZVAL_STRINGL(&z_fun_hmset, "HMSET", 5);
|
||||
call_user_function(&redis_ce->function_table, z_to, &z_fun_hmset, &z_ret_dest, 2, z_args);
|
||||
ra_call_user_function(&redis_ce->function_table, z_to, &z_fun_hmset, &z_ret_dest, 2, z_args TSRMLS_CC);
|
||||
zval_dtor(&z_fun_hmset);
|
||||
zval_dtor(&z_ret_dest);
|
||||
|
||||
@@ -1052,7 +1052,7 @@ ra_move_collection(const char *key, int key_len, zval *z_from, zval *z_to,
|
||||
ZVAL_STRING(&z_retrieve_args[i], cmd_list[i]);
|
||||
}
|
||||
|
||||
call_user_function(&redis_ce->function_table, z_from, &z_fun_retrieve, &z_ret, list_count, z_retrieve_args);
|
||||
ra_call_user_function(&redis_ce->function_table, z_from, &z_fun_retrieve, &z_ret, list_count, z_retrieve_args TSRMLS_CC);
|
||||
|
||||
/* cleanup */
|
||||
zval_dtor(&z_fun_retrieve);
|
||||
@@ -1084,7 +1084,7 @@ ra_move_collection(const char *key, int key_len, zval *z_from, zval *z_to,
|
||||
/* Clean up our input return value */
|
||||
zval_dtor(&z_ret);
|
||||
|
||||
call_user_function(&redis_ce->function_table, z_to, &z_fun_sadd, &z_ret, count, z_sadd_args);
|
||||
ra_call_user_function(&redis_ce->function_table, z_to, &z_fun_sadd, &z_ret, count, z_sadd_args TSRMLS_CC);
|
||||
|
||||
/* cleanup */
|
||||
zval_dtor(&z_fun_sadd);
|
||||
@@ -1209,7 +1209,7 @@ ra_rehash_server(RedisArray *ra, zval *z_redis, zend_string *hostname, zend_bool
|
||||
ZVAL_STRING(&z_argv, "*");
|
||||
}
|
||||
ZVAL_NULL(&z_ret);
|
||||
call_user_function(&redis_ce->function_table, z_redis, &z_fun, &z_ret, 1, &z_argv);
|
||||
ra_call_user_function(&redis_ce->function_table, z_redis, &z_fun, &z_ret, 1, &z_argv TSRMLS_CC);
|
||||
zval_dtor(&z_argv);
|
||||
zval_dtor(&z_fun);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user