From patchwork Fri Oct 30 11:01:20 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Martin_Storsj=C3=B6?= X-Patchwork-Id: 23280 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 8849D44B216 for ; Fri, 30 Oct 2020 13:01:31 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 61BBF68A0D3; Fri, 30 Oct 2020 13:01:31 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f45.google.com (mail-wm1-f45.google.com [209.85.128.45]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 2679F6897CD for ; Fri, 30 Oct 2020 13:01:25 +0200 (EET) Received: by mail-wm1-f45.google.com with SMTP id h22so2568753wmb.0 for ; Fri, 30 Oct 2020 04:01:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=martin-st.20150623.gappssmtp.com; s=20150623; h=from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=KfwZDizSPNFpf/W+wyx0t6Bxr4Xm5870WxHMoCXDIfo=; b=bz+FaxutgqlIyVLYxPWVDcVGX6bFe0D8nrTGHgwuKCEpCdsJsTJRwLyWhw8Pi/ulVV CzbfaEgRSUHvu38d1WytIXw0xAvjsJQT1sFDdyAYQ68oBME/X9U8OXfejMvvgXp5n1Y8 mpK4V2ClciMIC03DFUfzr4/JTrh7nsZ6TRpdjaJb2gnTNH2NxpzZ42oD1ii9uYUsi0mW jiPAeYw53n/CJ5UC17H6FTfC9ZFUuHnn+9V/evkyppdRlrsWYPufVsPoMa8y4SBUMx1/ GQVP11ftvLT2UbQp2fp01EJgn2vI1gZKzCgZS2Ln9CGMr5t48BbOZhojfZhVUZNeM3q7 TY/g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=KfwZDizSPNFpf/W+wyx0t6Bxr4Xm5870WxHMoCXDIfo=; b=pejLR3NTpEe7xVdXZ62cfgsJt3fBohlrmgz59L+GnzMf9udZL5+8C3atDN9T73wREQ fKg4WPhh2kDblrmgpaKycCwzaX3edcb+c84/6ifcuImy8TS9Vv7OCxRIEW4H+WKWeliy q6+6i72UR0E7/1iJUI9xTs/tHoTM+Qbhf+ICDBut84Tl+por1qhNUAkyN2RLh0HrDqIF bCpVgtxdBi4U51QnIz6hkauCMmtqu9PcL+kwYoBkm2RobN0VdezvHLCmPlHOs5t0dTBD WBUJKp7YP4c1V1rHyeytmoVsncOauLh75EWV3B5Hhzxsl9YF/bPOneh8F+YBGYM33Amj /SbQ== X-Gm-Message-State: AOAM532uPDcj6OQA9LyITvCJIrCO/9w7+xnZdHoH0Jq/K2nrVb/eHQpm 3aw+db1+tFzNu7oe+6sWxCxkkQHfz11fBdeU X-Google-Smtp-Source: ABdhPJxUDv+jQyIvMxFfqaC3iUVlx0BkKswEyYsRgtBV5w6PEuciS2rAAXpGmn4KXz/ei8HGd6flWg== X-Received: by 2002:a7b:c18d:: with SMTP id y13mr1966410wmi.120.1604055683888; Fri, 30 Oct 2020 04:01:23 -0700 (PDT) Received: from localhost (host-96-177.parnet.fi. [77.234.96.177]) by smtp.gmail.com with ESMTPSA id u3sm8719787wro.33.2020.10.30.04.01.22 for (version=TLS1 cipher=AES128-SHA bits=128/128); Fri, 30 Oct 2020 04:01:23 -0700 (PDT) From: =?utf-8?q?Martin_Storsj=C3=B6?= To: ffmpeg-devel@ffmpeg.org Date: Fri, 30 Oct 2020 13:01:20 +0200 Message-Id: <20201030110122.26502-1-martin@martin.st> X-Mailer: git-send-email 2.24.3 (Apple Git-128) MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 1/3] tls: Share code for common protocol functions and fields X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" --- 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 };