Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/phpredis/phpredis.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--common.h65
-rw-r--r--library.c20
-rw-r--r--library.h1
-rw-r--r--redis.c10
4 files changed, 60 insertions, 36 deletions
diff --git a/common.h b/common.h
index 857e87cf..dc692524 100644
--- a/common.h
+++ b/common.h
@@ -258,38 +258,39 @@ typedef struct fold_item {
/* {{{ struct RedisSock */
typedef struct {
- php_stream *stream;
- zend_string *host;
- int port;
- zend_string *auth;
- double timeout;
- double read_timeout;
- long retry_interval;
- redis_sock_status status;
- int persistent;
- int watching;
- zend_string *persistent_id;
-
- redis_serializer serializer;
- int compression;
- int compression_level;
- long dbNumber;
-
- zend_string *prefix;
-
- short mode;
- fold_item *head;
- fold_item *current;
-
- zend_string *pipeline_cmd;
-
- zend_string *err;
-
- int scan;
-
- int readonly;
- int reply_literal;
- int tcp_keepalive;
+ php_stream *stream;
+ php_stream_context *stream_ctx;
+ zend_string *host;
+ int port;
+ zend_string *auth;
+ double timeout;
+ double read_timeout;
+ long retry_interval;
+ redis_sock_status status;
+ int persistent;
+ int watching;
+ zend_string *persistent_id;
+
+ redis_serializer serializer;
+ int compression;
+ int compression_level;
+ long dbNumber;
+
+ zend_string *prefix;
+
+ short mode;
+ fold_item *head;
+ fold_item *current;
+
+ zend_string *pipeline_cmd;
+
+ zend_string *err;
+
+ int scan;
+
+ int readonly;
+ int reply_literal;
+ int tcp_keepalive;
} RedisSock;
/* }}} */
diff --git a/library.c b/library.c
index a67f79bb..fcbb4fd7 100644
--- a/library.c
+++ b/library.c
@@ -1921,7 +1921,7 @@ PHP_REDIS_API int redis_sock_connect(RedisSock *redis_sock)
redis_sock->stream = php_stream_xport_create(host, host_len,
0, STREAM_XPORT_CLIENT | STREAM_XPORT_CONNECT,
persistent_id ? ZSTR_VAL(persistent_id) : NULL,
- tv_ptr, NULL, &estr, &err);
+ tv_ptr, redis_sock->stream_ctx, &estr, &err);
if (persistent_id) {
zend_string_release(persistent_id);
@@ -2043,6 +2043,24 @@ redis_sock_set_err(RedisSock *redis_sock, const char *msg, int msg_len)
}
}
+PHP_REDIS_API int
+redis_sock_set_stream_context(RedisSock *redis_sock, zval *options)
+{
+ zend_string *zkey;
+ zval *z_ele;
+
+ if (!redis_sock || Z_TYPE_P(options) != IS_ARRAY) {
+ return FAILURE;
+ } else if (!redis_sock->stream_ctx) {
+ redis_sock->stream_ctx = php_stream_context_alloc();
+ }
+ ZEND_HASH_FOREACH_STR_KEY_VAL(Z_ARRVAL_P(options), zkey, z_ele) {
+ php_stream_context_set_option(redis_sock->stream_ctx, "ssl", ZSTR_VAL(zkey), z_ele);
+ } ZEND_HASH_FOREACH_END();
+
+ return SUCCESS;
+}
+
/**
* redis_sock_read_multibulk_reply
*/
diff --git a/library.h b/library.h
index 05ef917e..a5c660b6 100644
--- a/library.h
+++ b/library.h
@@ -91,6 +91,7 @@ PHP_REDIS_API int redis_check_eof(RedisSock *redis_sock, int no_throw);
PHP_REDIS_API RedisSock *redis_sock_get(zval *id, int nothrow);
PHP_REDIS_API void redis_free_socket(RedisSock *redis_sock);
PHP_REDIS_API void redis_sock_set_err(RedisSock *redis_sock, const char *msg, int msg_len);
+PHP_REDIS_API int redis_sock_set_stream_context(RedisSock *redis_sock, zval *options);
PHP_REDIS_API int
redis_serialize(RedisSock *redis_sock, zval *z, char **val, size_t *val_len);
diff --git a/redis.c b/redis.c
index 585915de..46278abd 100644
--- a/redis.c
+++ b/redis.c
@@ -959,7 +959,7 @@ PHP_METHOD(Redis, pconnect)
PHP_REDIS_API int
redis_connect(INTERNAL_FUNCTION_PARAMETERS, int persistent)
{
- zval *object;
+ zval *object, *ssl = NULL;
char *host = NULL, *persistent_id = NULL;
zend_long port = -1, retry_interval = 0;
size_t host_len, persistent_id_len;
@@ -973,10 +973,10 @@ redis_connect(INTERNAL_FUNCTION_PARAMETERS, int persistent)
#endif
if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(),
- "Os|lds!ld", &object, redis_ce, &host,
+ "Os|lds!lda", &object, redis_ce, &host,
&host_len, &port, &timeout, &persistent_id,
&persistent_id_len, &retry_interval,
- &read_timeout) == FAILURE)
+ &read_timeout, &ssl) == FAILURE)
{
return FAILURE;
}
@@ -1016,6 +1016,10 @@ redis_connect(INTERNAL_FUNCTION_PARAMETERS, int persistent)
redis->sock = redis_sock_create(host, host_len, port, timeout, read_timeout, persistent,
persistent_id, retry_interval);
+ if (ssl != NULL) {
+ redis_sock_set_stream_context(redis->sock, ssl);
+ }
+
if (redis_sock_server_open(redis->sock) < 0) {
if (redis->sock->err) {
REDIS_THROW_EXCEPTION(ZSTR_VAL(redis->sock->err), 0);