diff mbox

[FFmpeg-devel] openssl: Support version 1.1.0.

Message ID CAHVN4mimj+miqxQwK0d-tNUu_j-fnE=8ADR8bDxm3=nNi7UmDQ@mail.gmail.com
State Superseded
Headers show

Commit Message

Matt Oliver Oct. 9, 2016, 3:39 p.m. UTC
---
 configure                 |   3 +-
 libavformat/tls_openssl.c | 159
++++++++++++++++++++++++++++------------------
 2 files changed, 98 insertions(+), 64 deletions(-)

     avpriv_unlock_avformat();
@@ -107,6 +195,9 @@ void ff_openssl_deinit(void)
             av_free(openssl_mutexes);
         }
 #endif
+#if OPENSSL_VERSION_NUMBER >= 0x1010000fL
+        BIO_meth_free(url_bio_method);
+#endif
     }
     avpriv_unlock_avformat();
 }
@@ -132,69 +223,6 @@ static int tls_close(URLContext *h)
     return 0;
 }

-static int url_bio_create(BIO *b)
-{
-    b->init = 1;
-    b->ptr = NULL;
-    b->flags = 0;
-    return 1;
-}
-
-static int url_bio_destroy(BIO *b)
-{
-    return 1;
-}
-
-static int url_bio_bread(BIO *b, char *buf, int len)
-{
-    URLContext *h = b->ptr;
-    int ret = ffurl_read(h, buf, len);
-    if (ret >= 0)
-        return ret;
-    BIO_clear_retry_flags(b);
-    if (ret == AVERROR_EXIT)
-        return 0;
-    return -1;
-}
-
-static int url_bio_bwrite(BIO *b, const char *buf, int len)
-{
-    URLContext *h = b->ptr;
-    int ret = ffurl_write(h, buf, len);
-    if (ret >= 0)
-        return ret;
-    BIO_clear_retry_flags(b);
-    if (ret == AVERROR_EXIT)
-        return 0;
-    return -1;
-}
-
-static long url_bio_ctrl(BIO *b, int cmd, long num, void *ptr)
-{
-    if (cmd == BIO_CTRL_FLUSH) {
-        BIO_clear_retry_flags(b);
-        return 1;
-    }
-    return 0;
-}
-
-static int url_bio_bputs(BIO *b, const char *str)
-{
-    return url_bio_bwrite(b, str, strlen(str));
-}
-
-static BIO_METHOD url_bio_method = {
-    .type = BIO_TYPE_SOURCE_SINK,
-    .name = "urlprotocol bio",
-    .bwrite = url_bio_bwrite,
-    .bread = url_bio_bread,
-    .bputs = url_bio_bputs,
-    .bgets = NULL,
-    .ctrl = url_bio_ctrl,
-    .create = url_bio_create,
-    .destroy = url_bio_destroy,
-};
-
 static int tls_open(URLContext *h, const char *uri, int flags,
AVDictionary **options)
 {
     TLSContext *p = h->priv_data;
@@ -240,8 +268,13 @@ static int tls_open(URLContext *h, const char *uri,
int flags, AVDictionary **op
         ret = AVERROR(EIO);
         goto fail;
     }
+#if OPENSSL_VERSION_NUMBER >= 0x1010000fL
+    bio = BIO_new(url_bio_method);
+    BIO_set_data(bio, c->tcp);
+#else
     bio = BIO_new(&url_bio_method);
     bio->ptr = c->tcp;
+#endif
     SSL_set_bio(p->ssl, bio, bio);
     if (!c->listen && !c->numerichost)
         SSL_set_tlsext_host_name(p->ssl, c->host);

Comments

Michael Niedermayer Oct. 9, 2016, 4:18 p.m. UTC | #1
On Mon, Oct 10, 2016 at 02:39:51AM +1100, Matt Oliver wrote:
> ---
>  configure                 |   3 +-
>  libavformat/tls_openssl.c | 159
> ++++++++++++++++++++++++++++------------------
>  2 files changed, 98 insertions(+), 64 deletions(-)
> 
> diff --git a/configure b/configure
> index df6ffa2..750684a 100755
> --- a/configure
> +++ b/configure
> @@ -5813,7 +5813,8 @@ enabled omx               && { check_header
> OMX_Core.h ||
>                                      add_cflags -isystem/opt/vc/include/IL
> ; }
>                                  check_header OMX_Core.h ; } ||
>                                 die "ERROR: OpenMAX IL headers not found"; }
> -enabled openssl           && { use_pkg_config openssl openssl/ssl.h
> SSL_library_init ||
> +enabled openssl           && { use_pkg_config openssl openssl/ssl.h
> OPENSSL_init_ssl ||
> +                               use_pkg_config openssl openssl/ssl.h
> SSL_library_init ||
>                                 check_lib openssl/ssl.h SSL_library_init
> -lssl -lcrypto ||
>                                 check_lib openssl/ssl.h SSL_library_init
> -lssl32 -leay32 ||
>                                 check_lib openssl/ssl.h SSL_library_init
> -lssl -lcrypto -lws2_32 -lgdi32 ||
> diff --git a/libavformat/tls_openssl.c b/libavformat/tls_openssl.c
> index 46eb3e6..4effb39 100644
> --- a/libavformat/tls_openssl.c
> +++ b/libavformat/tls_openssl.c
> @@ -63,6 +63,85 @@ static unsigned long openssl_thread_id(void)
>  #endif
>  #endif
> 
> +static int url_bio_create(BIO *b)
> +{
> +#if OPENSSL_VERSION_NUMBER >= 0x1010000fL
> +    BIO_set_init(b, 1);
> +    BIO_set_data(b, NULL);
> +    BIO_set_flags(b, 0);
> +#else
> +    b->init = 1;
> +    b->ptr = NULL;
> +    b->flags = 0;
> +#endif
> +    return 1;
> +}
> +
> +static int url_bio_destroy(BIO *b)
> +{
> +    return 1;
> +}
> +

> +#if OPENSSL_VERSION_NUMBER >= 0x1010000fL
> +#define BIO_GET_DATA(x) BIO_get_data(x);
> +#else
> +#define BIO_GET_DATA(x) x->ptr;
> +#endif

this needs a () for protecting x


also there are these new warnings:

libavformat/tls_openssl.c: In function ‘url_bio_bread’:
libavformat/tls_openssl.c:94:5: warning: ISO C90 forbids mixed declarations and code [-Wdeclaration-after-statement]
libavformat/tls_openssl.c: In function ‘url_bio_bwrite’:
libavformat/tls_openssl.c:106:5: warning: ISO C90 forbids mixed declarations and code [-Wdeclaration-after-statement]


[...]
Matt Oliver Oct. 9, 2016, 5:37 p.m. UTC | #2
On 10 October 2016 at 03:18, Michael Niedermayer <michael@niedermayer.cc>
wrote:

> On Mon, Oct 10, 2016 at 02:39:51AM +1100, Matt Oliver wrote:
> > ---
> >  configure                 |   3 +-
> >  libavformat/tls_openssl.c | 159
> > ++++++++++++++++++++++++++++------------------
> >  2 files changed, 98 insertions(+), 64 deletions(-)
> >
> > diff --git a/configure b/configure
> > index df6ffa2..750684a 100755
> > --- a/configure
> > +++ b/configure
> > @@ -5813,7 +5813,8 @@ enabled omx               && { check_header
> > OMX_Core.h ||
> >                                      add_cflags
> -isystem/opt/vc/include/IL
> > ; }
> >                                  check_header OMX_Core.h ; } ||
> >                                 die "ERROR: OpenMAX IL headers not
> found"; }
> > -enabled openssl           && { use_pkg_config openssl openssl/ssl.h
> > SSL_library_init ||
> > +enabled openssl           && { use_pkg_config openssl openssl/ssl.h
> > OPENSSL_init_ssl ||
> > +                               use_pkg_config openssl openssl/ssl.h
> > SSL_library_init ||
> >                                 check_lib openssl/ssl.h SSL_library_init
> > -lssl -lcrypto ||
> >                                 check_lib openssl/ssl.h SSL_library_init
> > -lssl32 -leay32 ||
> >                                 check_lib openssl/ssl.h SSL_library_init
> > -lssl -lcrypto -lws2_32 -lgdi32 ||
> > diff --git a/libavformat/tls_openssl.c b/libavformat/tls_openssl.c
> > index 46eb3e6..4effb39 100644
> > --- a/libavformat/tls_openssl.c
> > +++ b/libavformat/tls_openssl.c
> > @@ -63,6 +63,85 @@ static unsigned long openssl_thread_id(void)
> >  #endif
> >  #endif
> >
> > +static int url_bio_create(BIO *b)
> > +{
> > +#if OPENSSL_VERSION_NUMBER >= 0x1010000fL
> > +    BIO_set_init(b, 1);
> > +    BIO_set_data(b, NULL);
> > +    BIO_set_flags(b, 0);
> > +#else
> > +    b->init = 1;
> > +    b->ptr = NULL;
> > +    b->flags = 0;
> > +#endif
> > +    return 1;
> > +}
> > +
> > +static int url_bio_destroy(BIO *b)
> > +{
> > +    return 1;
> > +}
> > +
>
> > +#if OPENSSL_VERSION_NUMBER >= 0x1010000fL
> > +#define BIO_GET_DATA(x) BIO_get_data(x);
> > +#else
> > +#define BIO_GET_DATA(x) x->ptr;
> > +#endif
>
> this needs a () for protecting x
>

Fixed locally.


> also there are these new warnings:
>
> libavformat/tls_openssl.c: In function ‘url_bio_bread’:
> libavformat/tls_openssl.c:94:5: warning: ISO C90 forbids mixed
> declarations and code [-Wdeclaration-after-statement]
> libavformat/tls_openssl.c: In function ‘url_bio_bwrite’:
> libavformat/tls_openssl.c:106:5: warning: ISO C90 forbids mixed
> declarations and code [-Wdeclaration-after-statement]
>

I assume the above was with 1.1.0 (as prior versions result in identical
code to what was there). Ive locally modified both functions so that
URLContext *h is only declared before ret but initialised in a new line
added after ret.
Lou Logan Oct. 9, 2016, 6:48 p.m. UTC | #3
On Sun, Oct 9, 2016, at 07:39 AM, Matt Oliver wrote:
> ---
>  configure                 |   3 +-
>  libavformat/tls_openssl.c | 159
> ++++++++++++++++++++++++++++------------------
>  2 files changed, 98 insertions(+), 64 deletions(-)

Does this fix ticket #5675? If it does you can mention that in the
commit message.
Matt Oliver Oct. 9, 2016, 8:29 p.m. UTC | #4
On 10 October 2016 at 05:48, Lou Logan <lou@lrcd.com> wrote:

> On Sun, Oct 9, 2016, at 07:39 AM, Matt Oliver wrote:
> > ---
> >  configure                 |   3 +-
> >  libavformat/tls_openssl.c | 159
> > ++++++++++++++++++++++++++++------------------
> >  2 files changed, 98 insertions(+), 64 deletions(-)
>
> Does this fix ticket #5675? If it does you can mention that in the
> commit message.
>
> Yes it does, new patch incomming
wm4 Oct. 14, 2016, 12:04 p.m. UTC | #5
On Mon, 10 Oct 2016 02:39:51 +1100
Matt Oliver <protogonoi@gmail.com> wrote:

> ---
>  configure                 |   3 +-
>  libavformat/tls_openssl.c | 159
> ++++++++++++++++++++++++++++------------------
>  2 files changed, 98 insertions(+), 64 deletions(-)
> 
> diff --git a/configure b/configure
> index df6ffa2..750684a 100755
> --- a/configure
> +++ b/configure
> @@ -5813,7 +5813,8 @@ enabled omx               && { check_header
> OMX_Core.h ||
>                                      add_cflags -isystem/opt/vc/include/IL
> ; }
>                                  check_header OMX_Core.h ; } ||
>                                 die "ERROR: OpenMAX IL headers not found"; }
> -enabled openssl           && { use_pkg_config openssl openssl/ssl.h
> SSL_library_init ||
> +enabled openssl           && { use_pkg_config openssl openssl/ssl.h
> OPENSSL_init_ssl ||
> +                               use_pkg_config openssl openssl/ssl.h
> SSL_library_init ||
>                                 check_lib openssl/ssl.h SSL_library_init
> -lssl -lcrypto ||
>                                 check_lib openssl/ssl.h SSL_library_init
> -lssl32 -leay32 ||
>                                 check_lib openssl/ssl.h SSL_library_init
> -lssl -lcrypto -lws2_32 -lgdi32 ||
> diff --git a/libavformat/tls_openssl.c b/libavformat/tls_openssl.c
> index 46eb3e6..4effb39 100644
> --- a/libavformat/tls_openssl.c
> +++ b/libavformat/tls_openssl.c
> @@ -63,6 +63,85 @@ static unsigned long openssl_thread_id(void)
>  #endif
>  #endif
> 
> +static int url_bio_create(BIO *b)
> +{
> +#if OPENSSL_VERSION_NUMBER >= 0x1010000fL
> +    BIO_set_init(b, 1);
> +    BIO_set_data(b, NULL);
> +    BIO_set_flags(b, 0);
> +#else
> +    b->init = 1;
> +    b->ptr = NULL;
> +    b->flags = 0;
> +#endif
> +    return 1;
> +}
> +
> +static int url_bio_destroy(BIO *b)
> +{
> +    return 1;
> +}
> +
> +#if OPENSSL_VERSION_NUMBER >= 0x1010000fL
> +#define BIO_GET_DATA(x) BIO_get_data(x);
> +#else
> +#define BIO_GET_DATA(x) x->ptr;
> +#endif
> +
> +static int url_bio_bread(BIO *b, char *buf, int len)
> +{
> +    URLContext *h = BIO_GET_DATA(b);
> +    int ret = ffurl_read(h, buf, len);
> +    if (ret >= 0)
> +        return ret;
> +    BIO_clear_retry_flags(b);
> +    if (ret == AVERROR_EXIT)
> +        return 0;
> +    return -1;
> +}
> +
> +static int url_bio_bwrite(BIO *b, const char *buf, int len)
> +{
> +    URLContext *h = BIO_GET_DATA(b);
> +    int ret = ffurl_write(h, buf, len);
> +    if (ret >= 0)
> +        return ret;
> +    BIO_clear_retry_flags(b);
> +    if (ret == AVERROR_EXIT)
> +        return 0;
> +    return -1;
> +}
> +
> +static long url_bio_ctrl(BIO *b, int cmd, long num, void *ptr)
> +{
> +    if (cmd == BIO_CTRL_FLUSH) {
> +        BIO_clear_retry_flags(b);
> +        return 1;
> +    }
> +    return 0;
> +}
> +
> +static int url_bio_bputs(BIO *b, const char *str)
> +{
> +    return url_bio_bwrite(b, str, strlen(str));
> +}
> +
> +#if OPENSSL_VERSION_NUMBER >= 0x1010000fL
> +static BIO_METHOD* url_bio_method;

More global mutable data? Are you serious? We've been trying our best
to avoid these, and only awful APIs like OpenSSL or GnuTLS force us to
have them (as well as our own awful APIs). Please remove this global if
possible.

> +#else
> +static BIO_METHOD url_bio_method = {
> +    .type = BIO_TYPE_SOURCE_SINK,
> +    .name = "urlprotocol bio",
> +    .bwrite = url_bio_bwrite,
> +    .bread = url_bio_bread,
> +    .bputs = url_bio_bputs,
> +    .bgets = NULL,
> +    .ctrl = url_bio_ctrl,
> +    .create = url_bio_create,
> +    .destroy = url_bio_destroy,
> +};
> +#endif
> +
>  int ff_openssl_init(void)
>  {
>      avpriv_lock_avformat();
> @@ -86,6 +165,15 @@ int ff_openssl_init(void)
>  #endif
>          }
>  #endif
> +#if OPENSSL_VERSION_NUMBER >= 0x1010000fL
> +        url_bio_method = BIO_meth_new(BIO_TYPE_SOURCE_SINK, "urlprotocol
> bio");
> +        BIO_meth_set_write(url_bio_method, url_bio_bwrite);
> +        BIO_meth_set_read(url_bio_method, url_bio_bread);
> +        BIO_meth_set_puts(url_bio_method, url_bio_bputs);
> +        BIO_meth_set_ctrl(url_bio_method, url_bio_ctrl);
> +        BIO_meth_set_create(url_bio_method, url_bio_create);
> +        BIO_meth_set_destroy(url_bio_method, url_bio_destroy);
> +#endif
>      }
>      openssl_init++;
>      avpriv_unlock_avformat();
> @@ -107,6 +195,9 @@ void ff_openssl_deinit(void)
>              av_free(openssl_mutexes);
>          }
>  #endif
> +#if OPENSSL_VERSION_NUMBER >= 0x1010000fL
> +        BIO_meth_free(url_bio_method);
> +#endif
>      }
>      avpriv_unlock_avformat();
>  }
> @@ -132,69 +223,6 @@ static int tls_close(URLContext *h)
>      return 0;
>  }
> 
> -static int url_bio_create(BIO *b)
> -{
> -    b->init = 1;
> -    b->ptr = NULL;
> -    b->flags = 0;
> -    return 1;
> -}
> -
> -static int url_bio_destroy(BIO *b)
> -{
> -    return 1;
> -}
> -
> -static int url_bio_bread(BIO *b, char *buf, int len)
> -{
> -    URLContext *h = b->ptr;
> -    int ret = ffurl_read(h, buf, len);
> -    if (ret >= 0)
> -        return ret;
> -    BIO_clear_retry_flags(b);
> -    if (ret == AVERROR_EXIT)
> -        return 0;
> -    return -1;
> -}
> -
> -static int url_bio_bwrite(BIO *b, const char *buf, int len)
> -{
> -    URLContext *h = b->ptr;
> -    int ret = ffurl_write(h, buf, len);
> -    if (ret >= 0)
> -        return ret;
> -    BIO_clear_retry_flags(b);
> -    if (ret == AVERROR_EXIT)
> -        return 0;
> -    return -1;
> -}
> -
> -static long url_bio_ctrl(BIO *b, int cmd, long num, void *ptr)
> -{
> -    if (cmd == BIO_CTRL_FLUSH) {
> -        BIO_clear_retry_flags(b);
> -        return 1;
> -    }
> -    return 0;
> -}
> -
> -static int url_bio_bputs(BIO *b, const char *str)
> -{
> -    return url_bio_bwrite(b, str, strlen(str));
> -}
> -
> -static BIO_METHOD url_bio_method = {
> -    .type = BIO_TYPE_SOURCE_SINK,
> -    .name = "urlprotocol bio",
> -    .bwrite = url_bio_bwrite,
> -    .bread = url_bio_bread,
> -    .bputs = url_bio_bputs,
> -    .bgets = NULL,
> -    .ctrl = url_bio_ctrl,
> -    .create = url_bio_create,
> -    .destroy = url_bio_destroy,
> -};
> -
>  static int tls_open(URLContext *h, const char *uri, int flags,
> AVDictionary **options)
>  {
>      TLSContext *p = h->priv_data;
> @@ -240,8 +268,13 @@ static int tls_open(URLContext *h, const char *uri,
> int flags, AVDictionary **op
>          ret = AVERROR(EIO);
>          goto fail;
>      }
> +#if OPENSSL_VERSION_NUMBER >= 0x1010000fL
> +    bio = BIO_new(url_bio_method);
> +    BIO_set_data(bio, c->tcp);
> +#else
>      bio = BIO_new(&url_bio_method);
>      bio->ptr = c->tcp;
> +#endif
>      SSL_set_bio(p->ssl, bio, bio);
>      if (!c->listen && !c->numerichost)
>          SSL_set_tlsext_host_name(p->ssl, c->host);
Matt Oliver Oct. 15, 2016, 3:21 a.m. UTC | #6
On 14 October 2016 at 23:04, wm4 <nfxjfg@googlemail.com> wrote:

> On Mon, 10 Oct 2016 02:39:51 +1100
> Matt Oliver <protogonoi@gmail.com> wrote:
>
> > ---
> >  configure                 |   3 +-
> >  libavformat/tls_openssl.c | 159
> > ++++++++++++++++++++++++++++------------------
> >  2 files changed, 98 insertions(+), 64 deletions(-)
> >
> > diff --git a/configure b/configure
> > index df6ffa2..750684a 100755
> > --- a/configure
> > +++ b/configure
> > @@ -5813,7 +5813,8 @@ enabled omx               && { check_header
> > OMX_Core.h ||
> >                                      add_cflags
> -isystem/opt/vc/include/IL
> > ; }
> >                                  check_header OMX_Core.h ; } ||
> >                                 die "ERROR: OpenMAX IL headers not
> found"; }
> > -enabled openssl           && { use_pkg_config openssl openssl/ssl.h
> > SSL_library_init ||
> > +enabled openssl           && { use_pkg_config openssl openssl/ssl.h
> > OPENSSL_init_ssl ||
> > +                               use_pkg_config openssl openssl/ssl.h
> > SSL_library_init ||
> >                                 check_lib openssl/ssl.h SSL_library_init
> > -lssl -lcrypto ||
> >                                 check_lib openssl/ssl.h SSL_library_init
> > -lssl32 -leay32 ||
> >                                 check_lib openssl/ssl.h SSL_library_init
> > -lssl -lcrypto -lws2_32 -lgdi32 ||
> > diff --git a/libavformat/tls_openssl.c b/libavformat/tls_openssl.c
> > index 46eb3e6..4effb39 100644
> > --- a/libavformat/tls_openssl.c
> > +++ b/libavformat/tls_openssl.c
> > @@ -63,6 +63,85 @@ static unsigned long openssl_thread_id(void)
> >  #endif
> >  #endif
> >
> > +static int url_bio_create(BIO *b)
> > +{
> > +#if OPENSSL_VERSION_NUMBER >= 0x1010000fL
> > +    BIO_set_init(b, 1);
> > +    BIO_set_data(b, NULL);
> > +    BIO_set_flags(b, 0);
> > +#else
> > +    b->init = 1;
> > +    b->ptr = NULL;
> > +    b->flags = 0;
> > +#endif
> > +    return 1;
> > +}
> > +
> > +static int url_bio_destroy(BIO *b)
> > +{
> > +    return 1;
> > +}
> > +
> > +#if OPENSSL_VERSION_NUMBER >= 0x1010000fL
> > +#define BIO_GET_DATA(x) BIO_get_data(x);
> > +#else
> > +#define BIO_GET_DATA(x) x->ptr;
> > +#endif
> > +
> > +static int url_bio_bread(BIO *b, char *buf, int len)
> > +{
> > +    URLContext *h = BIO_GET_DATA(b);
> > +    int ret = ffurl_read(h, buf, len);
> > +    if (ret >= 0)
> > +        return ret;
> > +    BIO_clear_retry_flags(b);
> > +    if (ret == AVERROR_EXIT)
> > +        return 0;
> > +    return -1;
> > +}
> > +
> > +static int url_bio_bwrite(BIO *b, const char *buf, int len)
> > +{
> > +    URLContext *h = BIO_GET_DATA(b);
> > +    int ret = ffurl_write(h, buf, len);
> > +    if (ret >= 0)
> > +        return ret;
> > +    BIO_clear_retry_flags(b);
> > +    if (ret == AVERROR_EXIT)
> > +        return 0;
> > +    return -1;
> > +}
> > +
> > +static long url_bio_ctrl(BIO *b, int cmd, long num, void *ptr)
> > +{
> > +    if (cmd == BIO_CTRL_FLUSH) {
> > +        BIO_clear_retry_flags(b);
> > +        return 1;
> > +    }
> > +    return 0;
> > +}
> > +
> > +static int url_bio_bputs(BIO *b, const char *str)
> > +{
> > +    return url_bio_bwrite(b, str, strlen(str));
> > +}
> > +
> > +#if OPENSSL_VERSION_NUMBER >= 0x1010000fL
> > +static BIO_METHOD* url_bio_method;
>
> More global mutable data? Are you serious? We've been trying our best
> to avoid these, and only awful APIs like OpenSSL or GnuTLS force us to
> have them (as well as our own awful APIs). Please remove this global if
> possible.
>
>
The only way would be to add a variable it to TLSContext. Which if that
works for you then let me know so I can push this.


> > +#else
> > +static BIO_METHOD url_bio_method = {
> > +    .type = BIO_TYPE_SOURCE_SINK,
> > +    .name = "urlprotocol bio",
> > +    .bwrite = url_bio_bwrite,
> > +    .bread = url_bio_bread,
> > +    .bputs = url_bio_bputs,
> > +    .bgets = NULL,
> > +    .ctrl = url_bio_ctrl,
> > +    .create = url_bio_create,
> > +    .destroy = url_bio_destroy,
> > +};
> > +#endif
> > +
> >  int ff_openssl_init(void)
> >  {
> >      avpriv_lock_avformat();
> > @@ -86,6 +165,15 @@ int ff_openssl_init(void)
> >  #endif
> >          }
> >  #endif
> > +#if OPENSSL_VERSION_NUMBER >= 0x1010000fL
> > +        url_bio_method = BIO_meth_new(BIO_TYPE_SOURCE_SINK,
> "urlprotocol
> > bio");
> > +        BIO_meth_set_write(url_bio_method, url_bio_bwrite);
> > +        BIO_meth_set_read(url_bio_method, url_bio_bread);
> > +        BIO_meth_set_puts(url_bio_method, url_bio_bputs);
> > +        BIO_meth_set_ctrl(url_bio_method, url_bio_ctrl);
> > +        BIO_meth_set_create(url_bio_method, url_bio_create);
> > +        BIO_meth_set_destroy(url_bio_method, url_bio_destroy);
> > +#endif
> >      }
> >      openssl_init++;
> >      avpriv_unlock_avformat();
> > @@ -107,6 +195,9 @@ void ff_openssl_deinit(void)
> >              av_free(openssl_mutexes);
> >          }
> >  #endif
> > +#if OPENSSL_VERSION_NUMBER >= 0x1010000fL
> > +        BIO_meth_free(url_bio_method);
> > +#endif
> >      }
> >      avpriv_unlock_avformat();
> >  }
> > @@ -132,69 +223,6 @@ static int tls_close(URLContext *h)
> >      return 0;
> >  }
> >
> > -static int url_bio_create(BIO *b)
> > -{
> > -    b->init = 1;
> > -    b->ptr = NULL;
> > -    b->flags = 0;
> > -    return 1;
> > -}
> > -
> > -static int url_bio_destroy(BIO *b)
> > -{
> > -    return 1;
> > -}
> > -
> > -static int url_bio_bread(BIO *b, char *buf, int len)
> > -{
> > -    URLContext *h = b->ptr;
> > -    int ret = ffurl_read(h, buf, len);
> > -    if (ret >= 0)
> > -        return ret;
> > -    BIO_clear_retry_flags(b);
> > -    if (ret == AVERROR_EXIT)
> > -        return 0;
> > -    return -1;
> > -}
> > -
> > -static int url_bio_bwrite(BIO *b, const char *buf, int len)
> > -{
> > -    URLContext *h = b->ptr;
> > -    int ret = ffurl_write(h, buf, len);
> > -    if (ret >= 0)
> > -        return ret;
> > -    BIO_clear_retry_flags(b);
> > -    if (ret == AVERROR_EXIT)
> > -        return 0;
> > -    return -1;
> > -}
> > -
> > -static long url_bio_ctrl(BIO *b, int cmd, long num, void *ptr)
> > -{
> > -    if (cmd == BIO_CTRL_FLUSH) {
> > -        BIO_clear_retry_flags(b);
> > -        return 1;
> > -    }
> > -    return 0;
> > -}
> > -
> > -static int url_bio_bputs(BIO *b, const char *str)
> > -{
> > -    return url_bio_bwrite(b, str, strlen(str));
> > -}
> > -
> > -static BIO_METHOD url_bio_method = {
> > -    .type = BIO_TYPE_SOURCE_SINK,
> > -    .name = "urlprotocol bio",
> > -    .bwrite = url_bio_bwrite,
> > -    .bread = url_bio_bread,
> > -    .bputs = url_bio_bputs,
> > -    .bgets = NULL,
> > -    .ctrl = url_bio_ctrl,
> > -    .create = url_bio_create,
> > -    .destroy = url_bio_destroy,
> > -};
> > -
> >  static int tls_open(URLContext *h, const char *uri, int flags,
> > AVDictionary **options)
> >  {
> >      TLSContext *p = h->priv_data;
> > @@ -240,8 +268,13 @@ static int tls_open(URLContext *h, const char *uri,
> > int flags, AVDictionary **op
> >          ret = AVERROR(EIO);
> >          goto fail;
> >      }
> > +#if OPENSSL_VERSION_NUMBER >= 0x1010000fL
> > +    bio = BIO_new(url_bio_method);
> > +    BIO_set_data(bio, c->tcp);
> > +#else
> >      bio = BIO_new(&url_bio_method);
> >      bio->ptr = c->tcp;
> > +#endif
> >      SSL_set_bio(p->ssl, bio, bio);
> >      if (!c->listen && !c->numerichost)
> >          SSL_set_tlsext_host_name(p->ssl, c->host);
>
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
diff mbox

Patch

diff --git a/configure b/configure
index df6ffa2..750684a 100755
--- a/configure
+++ b/configure
@@ -5813,7 +5813,8 @@  enabled omx               && { check_header
OMX_Core.h ||
                                     add_cflags -isystem/opt/vc/include/IL
; }
                                 check_header OMX_Core.h ; } ||
                                die "ERROR: OpenMAX IL headers not found"; }
-enabled openssl           && { use_pkg_config openssl openssl/ssl.h
SSL_library_init ||
+enabled openssl           && { use_pkg_config openssl openssl/ssl.h
OPENSSL_init_ssl ||
+                               use_pkg_config openssl openssl/ssl.h
SSL_library_init ||
                                check_lib openssl/ssl.h SSL_library_init
-lssl -lcrypto ||
                                check_lib openssl/ssl.h SSL_library_init
-lssl32 -leay32 ||
                                check_lib openssl/ssl.h SSL_library_init
-lssl -lcrypto -lws2_32 -lgdi32 ||
diff --git a/libavformat/tls_openssl.c b/libavformat/tls_openssl.c
index 46eb3e6..4effb39 100644
--- a/libavformat/tls_openssl.c
+++ b/libavformat/tls_openssl.c
@@ -63,6 +63,85 @@  static unsigned long openssl_thread_id(void)
 #endif
 #endif

+static int url_bio_create(BIO *b)
+{
+#if OPENSSL_VERSION_NUMBER >= 0x1010000fL
+    BIO_set_init(b, 1);
+    BIO_set_data(b, NULL);
+    BIO_set_flags(b, 0);
+#else
+    b->init = 1;
+    b->ptr = NULL;
+    b->flags = 0;
+#endif
+    return 1;
+}
+
+static int url_bio_destroy(BIO *b)
+{
+    return 1;
+}
+
+#if OPENSSL_VERSION_NUMBER >= 0x1010000fL
+#define BIO_GET_DATA(x) BIO_get_data(x);
+#else
+#define BIO_GET_DATA(x) x->ptr;
+#endif
+
+static int url_bio_bread(BIO *b, char *buf, int len)
+{
+    URLContext *h = BIO_GET_DATA(b);
+    int ret = ffurl_read(h, buf, len);
+    if (ret >= 0)
+        return ret;
+    BIO_clear_retry_flags(b);
+    if (ret == AVERROR_EXIT)
+        return 0;
+    return -1;
+}
+
+static int url_bio_bwrite(BIO *b, const char *buf, int len)
+{
+    URLContext *h = BIO_GET_DATA(b);
+    int ret = ffurl_write(h, buf, len);
+    if (ret >= 0)
+        return ret;
+    BIO_clear_retry_flags(b);
+    if (ret == AVERROR_EXIT)
+        return 0;
+    return -1;
+}
+
+static long url_bio_ctrl(BIO *b, int cmd, long num, void *ptr)
+{
+    if (cmd == BIO_CTRL_FLUSH) {
+        BIO_clear_retry_flags(b);
+        return 1;
+    }
+    return 0;
+}
+
+static int url_bio_bputs(BIO *b, const char *str)
+{
+    return url_bio_bwrite(b, str, strlen(str));
+}
+
+#if OPENSSL_VERSION_NUMBER >= 0x1010000fL
+static BIO_METHOD* url_bio_method;
+#else
+static BIO_METHOD url_bio_method = {
+    .type = BIO_TYPE_SOURCE_SINK,
+    .name = "urlprotocol bio",
+    .bwrite = url_bio_bwrite,
+    .bread = url_bio_bread,
+    .bputs = url_bio_bputs,
+    .bgets = NULL,
+    .ctrl = url_bio_ctrl,
+    .create = url_bio_create,
+    .destroy = url_bio_destroy,
+};
+#endif
+
 int ff_openssl_init(void)
 {
     avpriv_lock_avformat();
@@ -86,6 +165,15 @@  int ff_openssl_init(void)
 #endif
         }
 #endif
+#if OPENSSL_VERSION_NUMBER >= 0x1010000fL
+        url_bio_method = BIO_meth_new(BIO_TYPE_SOURCE_SINK, "urlprotocol
bio");
+        BIO_meth_set_write(url_bio_method, url_bio_bwrite);
+        BIO_meth_set_read(url_bio_method, url_bio_bread);
+        BIO_meth_set_puts(url_bio_method, url_bio_bputs);
+        BIO_meth_set_ctrl(url_bio_method, url_bio_ctrl);
+        BIO_meth_set_create(url_bio_method, url_bio_create);
+        BIO_meth_set_destroy(url_bio_method, url_bio_destroy);
+#endif
     }
     openssl_init++;