Check for BIO wrapper functions instead of making blind assumptions about
their existence based on the value of the OPENSSL_VERSION_NUMBER macro.

Fixes some of the build problems with LibreSSL.

* SConstruct: Check for BIO_set_init and provide SERF_NO_SSL_BIO_WRAPPERS.

* buckets/ssl_buckets.c: Use SERF_NO_SSL_BIO_WRAPPERS instead of
   USE_LEGACY_OPENSSL where BIO wrappers are used.


git-svn-id: https://svn.apache.org/repos/asf/serf/trunk@1775239 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/SConstruct b/SConstruct
index 6d8ea42..9398c7e 100644
--- a/SConstruct
+++ b/SConstruct
@@ -415,6 +415,12 @@
     env.Append(CPPPATH=['$OPENSSL/include'])
     env.Append(LIBPATH=['$OPENSSL/lib'])
 
+# Check for OpenSSL functions which are only available in some of
+# the versions we support. Also handles forks like LibreSSL.
+conf = Configure(env)
+if not conf.CheckFunc('BIO_set_init'):
+  env.Append(CPPDEFINES=['SERF_NO_SSL_BIO_WRAPPERS'])
+env = conf.Finish()
 
 # If build with gssapi, get its information and define SERF_HAVE_GSSAPI
 if gssapi and CALLOUT_OKAY:
diff --git a/buckets/ssl_buckets.c b/buckets/ssl_buckets.c
index f87ea27..d0a4080 100644
--- a/buckets/ssl_buckets.c
+++ b/buckets/ssl_buckets.c
@@ -322,7 +322,7 @@
 
 static void bio_set_data(BIO *bio, void *data)
 {
-#ifndef USE_LEGACY_OPENSSL
+#ifndef SERF_NO_SSL_BIO_WRAPPERS
     BIO_set_data(bio, data);
 #else
     bio->ptr = data;
@@ -331,7 +331,7 @@
 
 static void *bio_get_data(BIO *bio)
 {
-#ifndef USE_LEGACY_OPENSSL
+#ifndef SERF_NO_SSL_BIO_WRAPPERS
     return BIO_get_data(bio);
 #else
     return bio->ptr;
@@ -463,7 +463,7 @@
 
 static int bio_bucket_create(BIO *bio)
 {
-#ifndef USE_LEGACY_OPENSSL
+#ifndef SERF_NO_SSL_BIO_WRAPPERS
     BIO_set_shutdown(bio, 1);
     BIO_set_init(bio, 1);
     BIO_set_data(bio, NULL);
@@ -506,7 +506,7 @@
     return ret;
 }
 
-#ifdef USE_LEGACY_OPENSSL
+#ifdef SERF_NO_SSL_BIO_WRAPPERS
 static BIO_METHOD bio_bucket_method = {
     BIO_TYPE_MEM,
     "Serf SSL encryption and decryption buckets",
@@ -542,7 +542,7 @@
 {
     BIO_METHOD *biom = NULL;
 
-#ifndef USE_LEGACY_OPENSSL
+#ifndef SERF_NO_SSL_BIO_WRAPPERS
     biom = BIO_meth_new(BIO_TYPE_MEM,
                         "Serf SSL encryption and decryption buckets");
     if (biom) {
@@ -563,7 +563,7 @@
 {
     BIO_METHOD *biom = NULL;
 
-#ifndef USE_LEGACY_OPENSSL
+#ifndef SERF_NO_SSL_BIO_WRAPPERS
     biom = BIO_meth_new(BIO_TYPE_FILE, "Wrapper around APR file structures");
     if (biom) {
         BIO_meth_set_write(biom, bio_file_write);
@@ -582,7 +582,7 @@
 
 static void bio_meth_free(BIO_METHOD *biom)
 {
-#ifndef USE_LEGACY_OPENSSL
+#ifndef SERF_NO_SSL_BIO_WRAPPERS
     BIO_meth_free(biom);
 #endif
 }