summaryrefslogtreecommitdiff
path: root/ssl.c
diff options
context:
space:
mode:
authorMichael Grunder <michael.grunder@gmail.com>2020-07-29 11:53:03 -0700
committerGitHub <noreply@github.com>2020-07-29 11:53:03 -0700
commitd8ff72387d5474e56228a3403dc91354d9916189 (patch)
tree1a6fa645967132b78d92d52de9c9175b429236ba /ssl.c
parentbe32bcdc8e84ae7dc091ceeffca2c5d4126f415c (diff)
Move SSL management to a distinct private pointer. (#855)
We need to allow our users to use redisContext->privdata as context for any RESP3 PUSH messages, which means we can't use it for managing SSL connections. Bulletpoints: * Create a secondary redisContext member for internal use only called privctx and rename the redisContextFuncs->free_privdata accordingly. * Adds a `free_privdata` function pointer so the user can tie allocated memory to the lifetime of a redisContext (like they can already do with redisAsyncContext) * Enables SSL tests in .travis.yml
Diffstat (limited to 'ssl.c')
-rw-r--r--ssl.c22
1 files changed, 11 insertions, 11 deletions
diff --git a/ssl.c b/ssl.c
index d74212d..7df58fb 100644
--- a/ssl.c
+++ b/ssl.c
@@ -267,7 +267,7 @@ error:
static int redisSSLConnect(redisContext *c, SSL *ssl) {
- if (c->privdata) {
+ if (c->privctx) {
__redisSetError(c, REDIS_ERR_OTHER, "redisContext was already associated");
return REDIS_ERR;
}
@@ -288,14 +288,14 @@ static int redisSSLConnect(redisContext *c, SSL *ssl) {
ERR_clear_error();
int rv = SSL_connect(rssl->ssl);
if (rv == 1) {
- c->privdata = rssl;
+ c->privctx = rssl;
return REDIS_OK;
}
rv = SSL_get_error(rssl->ssl, rv);
if (((c->flags & REDIS_BLOCK) == 0) &&
(rv == SSL_ERROR_WANT_READ || rv == SSL_ERROR_WANT_WRITE)) {
- c->privdata = rssl;
+ c->privctx = rssl;
return REDIS_OK;
}
@@ -337,7 +337,7 @@ int redisInitiateSSLWithContext(redisContext *c, redisSSLContext *redis_ssl_ctx)
/* We want to verify that redisSSLConnect() won't fail on this, as it will
* not own the SSL object in that case and we'll end up leaking.
*/
- if (c->privdata)
+ if (c->privctx)
return REDIS_ERR;
SSL *ssl = SSL_new(redis_ssl_ctx->ssl_ctx);
@@ -381,8 +381,8 @@ static int maybeCheckWant(redisSSL *rssl, int rv) {
* Implementation of redisContextFuncs for SSL connections.
*/
-static void redisSSLFree(void *privdata){
- redisSSL *rsc = privdata;
+static void redisSSLFree(void *privctx){
+ redisSSL *rsc = privctx;
if (!rsc) return;
if (rsc->ssl) {
@@ -393,7 +393,7 @@ static void redisSSLFree(void *privdata){
}
static ssize_t redisSSLRead(redisContext *c, char *buf, size_t bufcap) {
- redisSSL *rssl = c->privdata;
+ redisSSL *rssl = c->privctx;
int nread = SSL_read(rssl->ssl, buf, bufcap);
if (nread > 0) {
@@ -435,7 +435,7 @@ static ssize_t redisSSLRead(redisContext *c, char *buf, size_t bufcap) {
}
static ssize_t redisSSLWrite(redisContext *c) {
- redisSSL *rssl = c->privdata;
+ redisSSL *rssl = c->privctx;
size_t len = rssl->lastLen ? rssl->lastLen : sdslen(c->obuf);
int rv = SSL_write(rssl->ssl, c->obuf, len);
@@ -458,7 +458,7 @@ static ssize_t redisSSLWrite(redisContext *c) {
static void redisSSLAsyncRead(redisAsyncContext *ac) {
int rv;
- redisSSL *rssl = ac->c.privdata;
+ redisSSL *rssl = ac->c.privctx;
redisContext *c = &ac->c;
rssl->wantRead = 0;
@@ -488,7 +488,7 @@ static void redisSSLAsyncRead(redisAsyncContext *ac) {
static void redisSSLAsyncWrite(redisAsyncContext *ac) {
int rv, done = 0;
- redisSSL *rssl = ac->c.privdata;
+ redisSSL *rssl = ac->c.privctx;
redisContext *c = &ac->c;
rssl->pendingWrite = 0;
@@ -517,7 +517,7 @@ static void redisSSLAsyncWrite(redisAsyncContext *ac) {
}
redisContextFuncs redisContextSSLFuncs = {
- .free_privdata = redisSSLFree,
+ .free_privctx = redisSSLFree,
.async_read = redisSSLAsyncRead,
.async_write = redisSSLAsyncWrite,
.read = redisSSLRead,