TLS is currently implemented over either OpenSSL or GnuTLS, with more
backends likely to appear in the future. Currently, those backend libraries
are part of the protocol names used during e.g. the configure stage of a
build. Hide those details behind a generically-named declaration for the
TLS protocol to avoid leaking those details into the configuration stage.
---

Added two-stage conditional compilation to avoid #ifdefs in the implementation
files.

 configure                 |  8 ++------
 libavformat/Makefile      |  5 +++--
 libavformat/network.c     | 20 --------------------
 libavformat/protocols.c   |  3 +--
 libavformat/tls.h         |  8 --------
 libavformat/tls_gnutls.c  | 10 +++++-----
 libavformat/tls_openssl.c | 10 +++++-----
 libavformat/utils.c       |  4 ++++
 8 files changed, 20 insertions(+), 48 deletions(-)

diff --git a/configure b/configure
index be52d4d..b7778d9 100755
--- a/configure
+++ b/configure
@@ -2468,12 +2468,8 @@ sctp_protocol_deps="struct_sctp_event_subscribe"
 sctp_protocol_select="network"
 srtp_protocol_select="rtp_protocol srtp"
 tcp_protocol_select="network"
-tls_gnutls_protocol_deps="gnutls"
-tls_gnutls_protocol_select="tcp_protocol"
-tls_openssl_protocol_conflict="tls_gnutls_protocol"
-tls_openssl_protocol_deps="openssl"
-tls_openssl_protocol_select="tcp_protocol"
-tls_protocol_deps_any="tls_gnutls_protocol tls_openssl_protocol"
+tls_protocol_deps_any="gnutls openssl"
+tls_protocol_select="tcp_protocol"
 udp_protocol_select="network"
 unix_protocol_deps="sys_un_h"
 unix_protocol_select="network"
diff --git a/libavformat/Makefile b/libavformat/Makefile
index 7b1df93..2c1c0f6 100644
--- a/libavformat/Makefile
+++ b/libavformat/Makefile
@@ -408,8 +408,9 @@ OBJS-$(CONFIG_RTP_PROTOCOL)              += rtpproto.o
 OBJS-$(CONFIG_SCTP_PROTOCOL)             += sctp.o
 OBJS-$(CONFIG_SRTP_PROTOCOL)             += srtpproto.o srtp.o
 OBJS-$(CONFIG_TCP_PROTOCOL)              += tcp.o
-OBJS-$(CONFIG_TLS_GNUTLS_PROTOCOL)       += tls_gnutls.o tls.o
-OBJS-$(CONFIG_TLS_OPENSSL_PROTOCOL)      += tls_openssl.o tls.o
+TLS-OBJS-$(CONFIG_GNUTLS)                += tls_gnutls.o
+TLS-OBJS-$(CONFIG_OPENSSL)               += tls_openssl.o
+OBJS-$(CONFIG_TLS_PROTOCOL)              += tls.o $(TLS-OBJS-yes)
 OBJS-$(CONFIG_UDP_PROTOCOL)              += udp.o
 OBJS-$(CONFIG_UNIX_PROTOCOL)             += unix.o
 
diff --git a/libavformat/network.c b/libavformat/network.c
index 2c34b4a..978ff73 100644
--- a/libavformat/network.c
+++ b/libavformat/network.c
@@ -25,26 +25,6 @@
 #include "libavcodec/internal.h"
 #include "libavutil/mem.h"
 
-void ff_tls_init(void)
-{
-#if CONFIG_TLS_OPENSSL_PROTOCOL
-    ff_openssl_init();
-#endif
-#if CONFIG_TLS_GNUTLS_PROTOCOL
-    ff_gnutls_init();
-#endif
-}
-
-void ff_tls_deinit(void)
-{
-#if CONFIG_TLS_OPENSSL_PROTOCOL
-    ff_openssl_deinit();
-#endif
-#if CONFIG_TLS_GNUTLS_PROTOCOL
-    ff_gnutls_deinit();
-#endif
-}
-
 int ff_network_inited_globally;
 
 int ff_network_init(void)
diff --git a/libavformat/protocols.c b/libavformat/protocols.c
index d254540..8ea5c0e 100644
--- a/libavformat/protocols.c
+++ b/libavformat/protocols.c
@@ -48,8 +48,7 @@ extern const URLProtocol ff_rtp_protocol;
 extern const URLProtocol ff_sctp_protocol;
 extern const URLProtocol ff_srtp_protocol;
 extern const URLProtocol ff_tcp_protocol;
-extern const URLProtocol ff_tls_gnutls_protocol;
-extern const URLProtocol ff_tls_openssl_protocol;
+extern const URLProtocol ff_tls_protocol;
 extern const URLProtocol ff_udp_protocol;
 extern const URLProtocol ff_unix_protocol;
 extern const URLProtocol ff_librtmp_protocol;
diff --git a/libavformat/tls.h b/libavformat/tls.h
index 22cb625..57adff9 100644
--- a/libavformat/tls.h
+++ b/libavformat/tls.h
@@ -26,8 +26,6 @@
 #include "url.h"
 #include "libavutil/opt.h"
 
-#define CONFIG_TLS_PROTOCOL (CONFIG_TLS_GNUTLS_PROTOCOL | 
CONFIG_TLS_OPENSSL_PROTOCOL)
-
 typedef struct TLSShared {
     char *ca_file;
     int verify;
@@ -51,10 +49,4 @@ typedef struct TLSShared {
 
 int ff_tls_open_underlying(TLSShared *c, URLContext *parent, const char *uri, 
AVDictionary **options);
 
-void ff_gnutls_init(void);
-void ff_gnutls_deinit(void);
-
-void ff_openssl_init(void);
-void ff_openssl_deinit(void);
-
 #endif /* AVFORMAT_TLS_H */
diff --git a/libavformat/tls_gnutls.c b/libavformat/tls_gnutls.c
index f8a612a..a888a0d 100644
--- a/libavformat/tls_gnutls.c
+++ b/libavformat/tls_gnutls.c
@@ -43,14 +43,14 @@ typedef struct TLSContext {
     int need_shutdown;
 } TLSContext;
 
-void ff_gnutls_init(void)
+void ff_tls_init(void)
 {
     avpriv_lock_avformat();
     gnutls_global_init();
     avpriv_unlock_avformat();
 }
 
-void ff_gnutls_deinit(void)
+void ff_tls_deinit(void)
 {
     avpriv_lock_avformat();
     gnutls_global_deinit();
@@ -84,7 +84,7 @@ static int tls_close(URLContext *h)
         gnutls_certificate_free_credentials(c->cred);
     if (c->tls_shared.tcp)
         ffurl_close(c->tls_shared.tcp);
-    ff_gnutls_deinit();
+    ff_tls_deinit();
     return 0;
 }
 
@@ -120,7 +120,7 @@ static int tls_open(URLContext *h, const char *uri, int 
flags, AVDictionary **op
     TLSShared *c = &p->tls_shared;
     int ret;
 
-    ff_gnutls_init();
+    ff_tls_init();
 
     if ((ret = ff_tls_open_underlying(c, h, uri, options)) < 0)
         goto fail;
@@ -233,7 +233,7 @@ static const AVClass tls_class = {
     .version    = LIBAVUTIL_VERSION_INT,
 };
 
-const URLProtocol ff_tls_gnutls_protocol = {
+const URLProtocol ff_tls_protocol = {
     .name           = "tls",
     .url_open2      = tls_open,
     .url_read       = tls_read,
diff --git a/libavformat/tls_openssl.c b/libavformat/tls_openssl.c
index 0abccf0..a9afbe1 100644
--- a/libavformat/tls_openssl.c
+++ b/libavformat/tls_openssl.c
@@ -66,7 +66,7 @@ static unsigned long openssl_thread_id(void)
 #endif
 #endif
 
-void ff_openssl_init(void)
+void ff_tls_init(void)
 {
     avpriv_lock_avformat();
     if (!openssl_init) {
@@ -89,7 +89,7 @@ void ff_openssl_init(void)
     avpriv_unlock_avformat();
 }
 
-void ff_openssl_deinit(void)
+void ff_tls_deinit(void)
 {
     avpriv_lock_avformat();
     openssl_init--;
@@ -128,7 +128,7 @@ static int tls_close(URLContext *h)
     if (c->url_bio_method)
         BIO_meth_free(c->url_bio_method);
 #endif
-    ff_openssl_deinit();
+    ff_tls_deinit();
     return 0;
 }
 
@@ -216,7 +216,7 @@ static int tls_open(URLContext *h, const char *uri, int 
flags, AVDictionary **op
     BIO *bio;
     int ret;
 
-    ff_openssl_init();
+    ff_tls_init();
 
     if ((ret = ff_tls_open_underlying(c, h, uri, options)) < 0)
         goto fail;
@@ -323,7 +323,7 @@ static const AVClass tls_class = {
     .version    = LIBAVUTIL_VERSION_INT,
 };
 
-const URLProtocol ff_tls_openssl_protocol = {
+const URLProtocol ff_tls_protocol = {
     .name           = "tls",
     .url_open2      = tls_open,
     .url_read       = tls_read,
diff --git a/libavformat/utils.c b/libavformat/utils.c
index eaba473..fd85a02 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -3211,8 +3211,10 @@ int avformat_network_init(void)
     ff_network_inited_globally = 1;
     if ((ret = ff_network_init()) < 0)
         return ret;
+#if CONFIG_TLS_PROTOCOL
     ff_tls_init();
 #endif
+#endif
     return 0;
 }
 
@@ -3220,8 +3222,10 @@ int avformat_network_deinit(void)
 {
 #if CONFIG_NETWORK
     ff_network_close();
+#if CONFIG_TLS_PROTOCOL
     ff_tls_deinit();
 #endif
+#endif
     return 0;
 }
 
-- 
2.1.4

_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel

Reply via email to