CLEANUP: ssl: move all BIO_* definitions to openssl-compat

The following macros are now defined for openssl < 1.1 so that we
can remove the code performing direct access to the structures :

  BIO_get_data(), BIO_set_data(), BIO_set_init(), BIO_meth_free(),
  BIO_meth_new(), BIO_meth_set_gets(), BIO_meth_set_puts(),
  BIO_meth_set_read(), BIO_meth_set_write(), BIO_meth_set_create(),
  BIO_meth_set_ctrl(), BIO_meth_set_destroy()
diff --git a/include/common/openssl-compat.h b/include/common/openssl-compat.h
index ca171cd..0e05649 100644
--- a/include/common/openssl-compat.h
+++ b/include/common/openssl-compat.h
@@ -296,5 +296,21 @@
 #define SSL_CTX_get_extra_chain_certs(ctx, chain) do { *(chain) = (ctx)->extra_certs; } while (0)
 #endif
 
+#if HA_OPENSSL_VERSION_NUMBER < 0x10100000L
+#define BIO_get_data(b)            (b)->ptr
+#define BIO_set_data(b, v)         do { (b)->ptr  = (v); } while (0)
+#define BIO_set_init(b, v)         do { (b)->init = (v); } while (0)
+
+#define BIO_meth_free(m)           free(m)
+#define BIO_meth_new(type, name)   calloc(1, sizeof(BIO_METHOD))
+#define BIO_meth_set_gets(m, f)    do { (m)->bgets   = (f); } while (0)
+#define BIO_meth_set_puts(m, f)    do { (m)->bputs   = (f); } while (0)
+#define BIO_meth_set_read(m, f)    do { (m)->bread   = (f); } while (0)
+#define BIO_meth_set_write(m, f)   do { (m)->bwrite  = (f); } while (0)
+#define BIO_meth_set_create(m, f)  do { (m)->create  = (f); } while (0)
+#define BIO_meth_set_ctrl(m, f)    do { (m)->ctrl    = (f); } while (0)
+#define BIO_meth_set_destroy(m, f) do { (m)->destroy = (f); } while (0)
+#endif
+
 #endif /* USE_OPENSSL */
 #endif /* _COMMON_OPENSSL_COMPAT_H */
diff --git a/src/ssl_sock.c b/src/ssl_sock.c
index 072d717..1a579f5 100644
--- a/src/ssl_sock.c
+++ b/src/ssl_sock.c
@@ -228,11 +228,7 @@
 	struct ssl_sock_ctx *ctx;
 	int ret;
 
-#if HA_OPENSSL_VERSION_NUMBER < 0x10100000
-	ctx = h->ptr;
-#else
 	ctx = BIO_get_data(h);
-#endif
 	tmpbuf.size = num;
 	tmpbuf.area = (void *)(uintptr_t)buf;
 	tmpbuf.data = num;
@@ -264,11 +260,7 @@
 	struct ssl_sock_ctx *ctx;
 	int ret;
 
-#if HA_OPENSSL_VERSION_NUMBER < 0x10100000
-	ctx = h->ptr;
-#else
 	ctx = BIO_get_data(h);
-#endif
 	tmpbuf.size = size;
 	tmpbuf.area = buf;
 	tmpbuf.data = 0;
@@ -297,13 +289,8 @@
 
 static int ha_ssl_new(BIO *h)
 {
-#if HA_OPENSSL_VERSION_NUMBER < 0x10100000L
-	h->init = 1;
-	h->ptr = NULL;
-#else
 	BIO_set_init(h, 1);
 	BIO_set_data(h, NULL);
-#endif
 	BIO_clear_flags(h, ~0);
 	return 1;
 }
@@ -5164,11 +5151,7 @@
 			conn->err_code = CO_ER_SSL_NO_MEM;
 			goto err;
 		}
-#if HA_OPENSSL_VERSION_NUMBER < 0x10100000
-		ctx->bio->ptr = ctx;
-#else
 		BIO_set_data(ctx->bio, ctx);
-#endif
 		SSL_set_bio(ctx->ssl, ctx->bio, ctx->bio);
 
 		/* set connection pointer */
@@ -5229,11 +5212,7 @@
 			conn->err_code = CO_ER_SSL_NO_MEM;
 			goto err;
 		}
-#if HA_OPENSSL_VERSION_NUMBER < 0x10100000
-		ctx->bio->ptr = ctx;
-#else
 		BIO_set_data(ctx->bio, ctx);
-#endif
 		SSL_set_bio(ctx->ssl, ctx->bio, ctx->bio);
 
 		/* set connection pointer */
@@ -9770,17 +9749,6 @@
 #endif
 	/* Load SSL string for the verbose & debug mode. */
 	ERR_load_SSL_strings();
-#if HA_OPENSSL_VERSION_NUMBER < 0x10100000L
-	ha_meth = malloc(sizeof(*ha_meth));
-	bzero(ha_meth, sizeof(*ha_meth));
-	ha_meth->bwrite = ha_ssl_write;
-	ha_meth->bread = ha_ssl_read;
-	ha_meth->ctrl = ha_ssl_ctrl;
-	ha_meth->create = ha_ssl_new;
-	ha_meth->destroy = ha_ssl_free;
-	ha_meth->bputs = ha_ssl_puts;
-	ha_meth->bgets = ha_ssl_gets;
-#else
 	ha_meth = BIO_meth_new(0x666, "ha methods");
 	BIO_meth_set_write(ha_meth, ha_ssl_write);
 	BIO_meth_set_read(ha_meth, ha_ssl_read);
@@ -9789,7 +9757,6 @@
 	BIO_meth_set_destroy(ha_meth, ha_ssl_free);
 	BIO_meth_set_puts(ha_meth, ha_ssl_puts);
 	BIO_meth_set_gets(ha_meth, ha_ssl_gets);
-#endif
 }
 
 /* Compute and register the version string */
@@ -9894,11 +9861,7 @@
 #if (HA_OPENSSL_VERSION_NUMBER >= 0x00907000L) && (HA_OPENSSL_VERSION_NUMBER < 0x10100000L)
         CRYPTO_cleanup_all_ex_data();
 #endif
-#if (HA_OPENSSL_VERSION_NUMBER < 0x10100000L)
-	free(ha_meth);
-#else
 	BIO_meth_free(ha_meth);
-#endif
 }