Forráskód Böngészése

tls: updated bio functions to support libssl v1.1.0 api

Daniel-Constantin Mierla 9 éve
szülő
commit
fe99687608
1 módosított fájl, 47 hozzáadás és 12 törlés
  1. 47 12
      modules/tls/tls_bio.c

+ 47 - 12
modules/tls/tls_bio.c

@@ -1,4 +1,4 @@
-/* 
+/*
  * Kamailio TLS module
  * Kamailio TLS module
  *
  *
  * Copyright (C) 2010 iptelorg GmbH
  * Copyright (C) 2010 iptelorg GmbH
@@ -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;
 	struct tls_bio_mbuf_data* d;
 
 
 	TLS_BIO_DBG("tls_BIO_mbuf_set called (%p => %p, %p)\n", b, rd, wr);
 	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;
 		return 0;
 	}
 	}
-	d = b->ptr;
 	d->rd = rd;
 	d->rd = rd;
 	d->wr = wr;
 	d->wr = wr;
+#if OPENSSL_VERSION_NUMBER < 0x010100000L
 	b->init = 1;
 	b->init = 1;
+#else
+	BIO_set_init(b, 1);
+#endif
 	return 1;
 	return 1;
 }
 }
 
 
@@ -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)
 static int tls_bio_mbuf_new(BIO* b)
 {
 {
 	struct tls_bio_mbuf_data* d;
 	struct tls_bio_mbuf_data* d;
-	
+
 	TLS_BIO_DBG("tls_bio_mbuf_new called (%p)\n", b);
 	TLS_BIO_DBG("tls_bio_mbuf_new called (%p)\n", b);
+#if OPENSSL_VERSION_NUMBER < 0x010100000L
 	b->init = 0; /* not initialized yet */
 	b->init = 0; /* not initialized yet */
 	b->num = 0;
 	b->num = 0;
 	b->ptr = 0;
 	b->ptr = 0;
@@ -169,6 +178,14 @@ static int tls_bio_mbuf_new(BIO* b)
 	d->rd = 0;
 	d->rd = 0;
 	d->wr = 0;
 	d->wr = 0;
 	b->ptr = d;
 	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;
 	return 1;
 }
 }
 
 
@@ -183,11 +200,23 @@ static int tls_bio_mbuf_free(BIO* b)
 	TLS_BIO_DBG("tls_bio_mbuf_free called (%p)\n", b);
 	TLS_BIO_DBG("tls_bio_mbuf_free called (%p)\n", b);
 	if (unlikely( b == 0))
 	if (unlikely( b == 0))
 			return 0;
 			return 0;
+#if OPENSSL_VERSION_NUMBER < 0x010100000L
 	if (likely(b->ptr)){
 	if (likely(b->ptr)){
 		OPENSSL_free(b->ptr);
 		OPENSSL_free(b->ptr);
 		b->ptr = 0;
 		b->ptr = 0;
 		b->init = 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;
 	return 1;
 }
 }
 
 
@@ -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_bio_mbuf_data* d;
 	struct tls_mbuf* rd;
 	struct tls_mbuf* rd;
 	int ret;
 	int ret;
-	
+
 	ret = 0;
 	ret = 0;
 	if (likely(dst)) {
 	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);
 		BIO_clear_retry_flags(b);
 		if (unlikely(d == 0 || d->rd->buf == 0)) {
 		if (unlikely(d == 0 || d->rd->buf == 0)) {
 			if (d == 0)
 			if (d == 0)
@@ -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_bio_mbuf_data* d;
 	struct tls_mbuf* wr;
 	struct tls_mbuf* wr;
 	int ret;
 	int ret;
-	
+
 	ret = 0;
 	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);
 	BIO_clear_retry_flags(b);
 	if (unlikely(d == 0 || d->wr->buf == 0)) {
 	if (unlikely(d == 0 || d->wr->buf == 0)) {
 		if (d == 0)
 		if (d == 0)
@@ -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)
 static int tls_bio_mbuf_puts(BIO* b, const char* s)
 {
 {
 	int len;
 	int len;
-	
+
 	TLS_BIO_DBG("puts called (%p, %s)\n", b, s);
 	TLS_BIO_DBG("puts called (%p, %s)\n", b, s);
 	len=strlen(s);
 	len=strlen(s);
 	return tls_bio_mbuf_write(b, s, len);
 	return tls_bio_mbuf_write(b, s, len);
 }
 }
 
 
-
-
 /* vi: set ts=4 sw=4 tw=79:ai:cindent: */
 /* vi: set ts=4 sw=4 tw=79:ai:cindent: */