Skip to content

Commit

Permalink
tls: updated bio functions to support libssl v1.1.0 api
Browse files Browse the repository at this point in the history
(cherry picked from commit fe99687)
  • Loading branch information
miconda authored and linuxmaniac committed Oct 27, 2016
1 parent 58daa31 commit 81df84b
Showing 1 changed file with 47 additions and 12 deletions.
59 changes: 47 additions & 12 deletions modules/tls/tls_bio.c
@@ -1,4 +1,4 @@
/*
/*
* Kamailio TLS module
*
* Copyright (C) 2010 iptelorg GmbH
Expand Down Expand Up @@ -137,14 +137,22 @@ int tls_BIO_mbuf_set(BIO* b, struct tls_mbuf* rd, struct tls_mbuf* wr)
struct tls_bio_mbuf_data* d;

TLS_BIO_DBG("tls_BIO_mbuf_set called (%p => %p, %p)\n", b, rd, wr);
if (unlikely(b->ptr == 0)){
BUG("null BIO ptr\n");
#if OPENSSL_VERSION_NUMBER < 0x010100000L
d = b->ptr;
#else
d = BIO_get_data(b);
#endif
if (unlikely(d == 0)){
BUG("null BIO ptr data\n");
return 0;
}
d = b->ptr;
d->rd = rd;
d->wr = wr;
#if OPENSSL_VERSION_NUMBER < 0x010100000L
b->init = 1;
#else
BIO_set_init(b, 1);
#endif
return 1;
}

Expand All @@ -157,8 +165,9 @@ int tls_BIO_mbuf_set(BIO* b, struct tls_mbuf* rd, struct tls_mbuf* wr)
static int tls_bio_mbuf_new(BIO* b)
{
struct tls_bio_mbuf_data* d;

TLS_BIO_DBG("tls_bio_mbuf_new called (%p)\n", b);
#if OPENSSL_VERSION_NUMBER < 0x010100000L
b->init = 0; /* not initialized yet */
b->num = 0;
b->ptr = 0;
Expand All @@ -169,6 +178,14 @@ static int tls_bio_mbuf_new(BIO* b)
d->rd = 0;
d->wr = 0;
b->ptr = d;
#else
BIO_set_init(b, 0);
BIO_set_data(b, NULL);
d = OPENSSL_zalloc(sizeof(*d));
if (unlikely(d == 0))
return 0;
BIO_set_data(b, d);
#endif
return 1;
}

Expand All @@ -183,11 +200,23 @@ static int tls_bio_mbuf_free(BIO* b)
TLS_BIO_DBG("tls_bio_mbuf_free called (%p)\n", b);
if (unlikely( b == 0))
return 0;
#if OPENSSL_VERSION_NUMBER < 0x010100000L
if (likely(b->ptr)){
OPENSSL_free(b->ptr);
b->ptr = 0;
b->init = 0;
}
#else
do {
struct tls_bio_mbuf_data* d;
d = BIO_get_data(b);
if (likely(d)) {
OPENSSL_free(d);
BIO_set_data(b, NULL);
BIO_set_init(b, 0);
}
} while(0);
#endif
return 1;
}

Expand All @@ -203,10 +232,14 @@ static int tls_bio_mbuf_read(BIO* b, char* dst, int dst_len)
struct tls_bio_mbuf_data* d;
struct tls_mbuf* rd;
int ret;

ret = 0;
if (likely(dst)) {
d= b->ptr;
#if OPENSSL_VERSION_NUMBER < 0x010100000L
d = b->ptr;
#else
d = BIO_get_data(b);
#endif
BIO_clear_retry_flags(b);
if (unlikely(d == 0 || d->rd->buf == 0)) {
if (d == 0)
Expand Down Expand Up @@ -256,9 +289,13 @@ static int tls_bio_mbuf_write(BIO* b, const char* src, int src_len)
struct tls_bio_mbuf_data* d;
struct tls_mbuf* wr;
int ret;

ret = 0;
d= b->ptr;
#if OPENSSL_VERSION_NUMBER < 0x010100000L
d = b->ptr;
#else
d = BIO_get_data(b);
#endif
BIO_clear_retry_flags(b);
if (unlikely(d == 0 || d->wr->buf == 0)) {
if (d == 0)
Expand Down Expand Up @@ -330,12 +367,10 @@ static long tls_bio_mbuf_ctrl(BIO* b, int cmd, long arg1, void* arg2)
static int tls_bio_mbuf_puts(BIO* b, const char* s)
{
int len;

TLS_BIO_DBG("puts called (%p, %s)\n", b, s);
len=strlen(s);
return tls_bio_mbuf_write(b, s, len);
}



/* vi: set ts=4 sw=4 tw=79:ai:cindent: */

0 comments on commit 81df84b

Please sign in to comment.