[FFmpeg-devel] [PATCH 1/3] tls: Share code for common protocol functions and fields
Martin Storsjö
martin at martin.st
Fri Oct 30 13:01:20 EET 2020
---
libavformat/tls.h | 13 +++++++++++++
libavformat/tls_gnutls.c | 11 ++---------
libavformat/tls_libtls.c | 11 ++---------
libavformat/tls_mbedtls.c | 11 ++---------
libavformat/tls_openssl.c | 11 ++---------
libavformat/tls_schannel.c | 11 ++---------
libavformat/tls_securetransport.c | 11 ++---------
7 files changed, 25 insertions(+), 54 deletions(-)
diff --git a/libavformat/tls.h b/libavformat/tls.h
index beb19d6d55..4f3315427d 100644
--- a/libavformat/tls.h
+++ b/libavformat/tls.h
@@ -51,6 +51,19 @@ typedef struct TLSShared {
{"listen", "Listen for incoming connections", offsetof(pstruct, options_field . listen), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, .flags = TLS_OPTFL }, \
{"verifyhost", "Verify against a specific hostname", offsetof(pstruct, options_field . host), AV_OPT_TYPE_STRING, .flags = TLS_OPTFL }
+#define TLS_COMMON_PROTOCOL_FUNCTIONS \
+static int tls_get_file_handle(URLContext *h) \
+{ \
+ TLSContext *c = h->priv_data; \
+ return ffurl_get_file_handle(c->tls_shared.tcp); \
+}
+
+#define TLS_COMMON_PROTOCOL_FIELDS \
+ .url_get_file_handle = tls_get_file_handle, \
+ .priv_data_size = sizeof(TLSContext), \
+ .flags = URL_PROTOCOL_FLAG_NETWORK, \
+ .priv_data_class = &tls_class
+
int ff_tls_open_underlying(TLSShared *c, URLContext *parent, const char *uri, AVDictionary **options);
void ff_gnutls_init(void);
diff --git a/libavformat/tls_gnutls.c b/libavformat/tls_gnutls.c
index 0c4ef34f5f..b971f1015a 100644
--- a/libavformat/tls_gnutls.c
+++ b/libavformat/tls_gnutls.c
@@ -263,11 +263,7 @@ static int tls_write(URLContext *h, const uint8_t *buf, int size)
return print_tls_error(h, ret);
}
-static int tls_get_file_handle(URLContext *h)
-{
- TLSContext *c = h->priv_data;
- return ffurl_get_file_handle(c->tls_shared.tcp);
-}
+TLS_COMMON_PROTOCOL_FUNCTIONS
static const AVOption options[] = {
TLS_COMMON_OPTIONS(TLSContext, tls_shared),
@@ -287,8 +283,5 @@ const URLProtocol ff_tls_protocol = {
.url_read = tls_read,
.url_write = tls_write,
.url_close = tls_close,
- .url_get_file_handle = tls_get_file_handle,
- .priv_data_size = sizeof(TLSContext),
- .flags = URL_PROTOCOL_FLAG_NETWORK,
- .priv_data_class = &tls_class,
+ TLS_COMMON_PROTOCOL_FIELDS,
};
diff --git a/libavformat/tls_libtls.c b/libavformat/tls_libtls.c
index dff7f2d9fb..b7709dd954 100644
--- a/libavformat/tls_libtls.c
+++ b/libavformat/tls_libtls.c
@@ -175,11 +175,7 @@ static int ff_tls_write(URLContext *h, const uint8_t *buf, int size)
return AVERROR(EIO);
}
-static int tls_get_file_handle(URLContext *h)
-{
- TLSContext *c = h->priv_data;
- return ffurl_get_file_handle(c->tls_shared.tcp);
-}
+TLS_COMMON_PROTOCOL_FUNCTIONS
static const AVOption options[] = {
TLS_COMMON_OPTIONS(TLSContext, tls_shared),
@@ -199,8 +195,5 @@ const URLProtocol ff_tls_protocol = {
.url_read = ff_tls_read,
.url_write = ff_tls_write,
.url_close = ff_tls_close,
- .url_get_file_handle = tls_get_file_handle,
- .priv_data_size = sizeof(TLSContext),
- .flags = URL_PROTOCOL_FLAG_NETWORK,
- .priv_data_class = &tls_class,
+ TLS_COMMON_PROTOCOL_FIELDS,
};
diff --git a/libavformat/tls_mbedtls.c b/libavformat/tls_mbedtls.c
index 965adf1be4..6d7bef7572 100644
--- a/libavformat/tls_mbedtls.c
+++ b/libavformat/tls_mbedtls.c
@@ -320,11 +320,7 @@ static int tls_write(URLContext *h, const uint8_t *buf, int size)
return handle_tls_error(h, "mbedtls_ssl_write", ret);
}
-static int tls_get_file_handle(URLContext *h)
-{
- TLSContext *c = h->priv_data;
- return ffurl_get_file_handle(c->tls_shared.tcp);
-}
+TLS_COMMON_PROTOCOL_FUNCTIONS
static const AVOption options[] = {
TLS_COMMON_OPTIONS(TLSContext, tls_shared), \
@@ -345,8 +341,5 @@ const URLProtocol ff_tls_protocol = {
.url_read = tls_read,
.url_write = tls_write,
.url_close = tls_close,
- .url_get_file_handle = tls_get_file_handle,
- .priv_data_size = sizeof(TLSContext),
- .flags = URL_PROTOCOL_FLAG_NETWORK,
- .priv_data_class = &tls_class,
+ TLS_COMMON_PROTOCOL_FIELDS,
};
diff --git a/libavformat/tls_openssl.c b/libavformat/tls_openssl.c
index 002197fa76..802f29c980 100644
--- a/libavformat/tls_openssl.c
+++ b/libavformat/tls_openssl.c
@@ -345,11 +345,7 @@ static int tls_write(URLContext *h, const uint8_t *buf, int size)
return print_tls_error(h, ret);
}
-static int tls_get_file_handle(URLContext *h)
-{
- TLSContext *c = h->priv_data;
- return ffurl_get_file_handle(c->tls_shared.tcp);
-}
+TLS_COMMON_PROTOCOL_FUNCTIONS
static const AVOption options[] = {
TLS_COMMON_OPTIONS(TLSContext, tls_shared),
@@ -369,8 +365,5 @@ const URLProtocol ff_tls_protocol = {
.url_read = tls_read,
.url_write = tls_write,
.url_close = tls_close,
- .url_get_file_handle = tls_get_file_handle,
- .priv_data_size = sizeof(TLSContext),
- .flags = URL_PROTOCOL_FLAG_NETWORK,
- .priv_data_class = &tls_class,
+ TLS_COMMON_PROTOCOL_FIELDS,
};
diff --git a/libavformat/tls_schannel.c b/libavformat/tls_schannel.c
index 4bfaa85228..fef516ca94 100644
--- a/libavformat/tls_schannel.c
+++ b/libavformat/tls_schannel.c
@@ -583,11 +583,7 @@ done:
return ret < 0 ? ret : outbuf[1].cbBuffer;
}
-static int tls_get_file_handle(URLContext *h)
-{
- TLSContext *c = h->priv_data;
- return ffurl_get_file_handle(c->tls_shared.tcp);
-}
+TLS_COMMON_PROTOCOL_FUNCTIONS
static const AVOption options[] = {
TLS_COMMON_OPTIONS(TLSContext, tls_shared),
@@ -607,8 +603,5 @@ const URLProtocol ff_tls_protocol = {
.url_read = tls_read,
.url_write = tls_write,
.url_close = tls_close,
- .url_get_file_handle = tls_get_file_handle,
- .priv_data_size = sizeof(TLSContext),
- .flags = URL_PROTOCOL_FLAG_NETWORK,
- .priv_data_class = &tls_class,
+ TLS_COMMON_PROTOCOL_FIELDS
};
diff --git a/libavformat/tls_securetransport.c b/libavformat/tls_securetransport.c
index 3250b23051..de0a317cba 100644
--- a/libavformat/tls_securetransport.c
+++ b/libavformat/tls_securetransport.c
@@ -390,11 +390,7 @@ static int tls_write(URLContext *h, const uint8_t *buf, int size)
return print_tls_error(h, ret);
}
-static int tls_get_file_handle(URLContext *h)
-{
- TLSContext *c = h->priv_data;
- return ffurl_get_file_handle(c->tls_shared.tcp);
-}
+TLS_COMMON_PROTOCOL_FUNCTIONS
static const AVOption options[] = {
TLS_COMMON_OPTIONS(TLSContext, tls_shared),
@@ -414,8 +410,5 @@ const URLProtocol ff_tls_protocol = {
.url_read = tls_read,
.url_write = tls_write,
.url_close = tls_close,
- .url_get_file_handle = tls_get_file_handle,
- .priv_data_size = sizeof(TLSContext),
- .flags = URL_PROTOCOL_FLAG_NETWORK,
- .priv_data_class = &tls_class,
+ TLS_COMMON_PROTOCOL_FIELDS
};
--
2.24.3 (Apple Git-128)
More information about the ffmpeg-devel
mailing list