From patchwork Tue Jun 11 14:16:22 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rodger Combs X-Patchwork-Id: 13506 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 615774477B1 for ; Tue, 11 Jun 2019 17:24:52 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 450F86809F2; Tue, 11 Jun 2019 17:24:52 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-it1-f193.google.com (mail-it1-f193.google.com [209.85.166.193]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id EAA81680347 for ; Tue, 11 Jun 2019 17:24:45 +0300 (EEST) Received: by mail-it1-f193.google.com with SMTP id j194so5248131ite.0 for ; Tue, 11 Jun 2019 07:24:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=HCQGK4y/sic0LDmIwZu2iquYEqR7l49qPiCeACV0pgs=; b=hzVh9cBnyZtuF14t/WMFbm6o/A+PLLez3uF30v8xNnlBCM/V6t+tCLpWu+S74xObw0 mhcvqHY3nPPJNKyqWpPgc60QJDAtofA+NJNCXieDMhszbgeNIPnLiRoB8BiNVGxCgUVU 4ERJbHtS3tSDOuhbkJnUMQAvxak/UXULP1+GSYDMSwB6m1cgG+7586cRRdLv8QtYy3Nf CkBikS+b9oXfeMtOTZh0iN/k0jnI622ubdReiJ+rI8SavMj+MojZCn+7z4yDai0huApX 0SIjdkPt5wZybMPSg1MzmW8XRsQyXULLDBk3LqYmcg6hi+LRzVNsMxpG+iJDY8TIctob WW4g== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=HCQGK4y/sic0LDmIwZu2iquYEqR7l49qPiCeACV0pgs=; b=Vd/n8+OuuTdZ7D9StV0pDMFFl+kcEsYb/beoHmIRzek5Zd3BsITXxSR58A1a1KzZFn m60e8E6jpp+EyulHE4heHwpuzdL0KTCVmJYJMKJFXPoRhIr+RC9AsM3WLd4xcqYdKgKH BRxIPYOBfVvUC/4A0IN6750ihkTgvavYNzME5S8bxMX1xFDUER7beYIKo9hfr4ik9mC1 GL4P6dkDTfhwQzj5SliNIHenAGVwNBvvntzPBTmzmzCk5UZ5RHtuypu9ZsaSvL4SiaU1 gQTPz0xnooeseLleeFBcAajNBJmqdH3WRRCM3aD5HIOP7udYb4qkFCHQd4s6OYsTCVR6 oi1g== X-Gm-Message-State: APjAAAXLKW1PWdckhloRvc/O7aBnNf8HrdWBNZb9+ZC3EunHLn1TjMr3 teYLcbLT1PSSGfjqSsFKJASVgsCY3Eo= X-Google-Smtp-Source: APXvYqwmdQwaMD/2r/tNzC+NqvDrbLmA+lUwAoY31AS82TrxKWZXe9JxE7818hcJGGX0a3tjFEEoYw== X-Received: by 2002:a24:c7c7:: with SMTP id t190mr16948732itg.159.1560262596944; Tue, 11 Jun 2019 07:16:36 -0700 (PDT) Received: from Rodgers-MBP.localdomain ([71.201.155.37]) by smtp.gmail.com with ESMTPSA id w23sm5005046ioa.51.2019.06.11.07.16.35 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 11 Jun 2019 07:16:36 -0700 (PDT) From: Rodger Combs To: ffmpeg-devel@ffmpeg.org Date: Tue, 11 Jun 2019 09:16:22 -0500 Message-Id: <20190611141623.59440-5-rodger.combs@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190611141623.59440-1-rodger.combs@gmail.com> References: <20190611141623.59440-1-rodger.combs@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 5/6] lavf/tls: factor ff_tls_process_underlying into its own function 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.c | 45 +++++++++++++++++++++++++++------------------ libavformat/tls.h | 1 + 2 files changed, 28 insertions(+), 18 deletions(-) diff --git a/libavformat/tls.c b/libavformat/tls.c index 10e0792e29..ccd551061d 100644 --- a/libavformat/tls.c +++ b/libavformat/tls.c @@ -51,6 +51,29 @@ static void set_options(TLSShared *c, const char *uri) if (!c->key_file && av_find_info_tag(buf, sizeof(buf), "key", p)) c->key_file = av_strdup(buf); + + if (av_find_info_tag(buf, sizeof(buf), "listen", p)) + c->listen = 1; +} + +int ff_tls_process_underlying(TLSShared *c, URLContext *parent, const char *uri, int *port) +{ + struct addrinfo hints = { 0 }, *ai = NULL; + + set_options(c, uri); + + av_url_split(NULL, 0, NULL, 0, c->underlying_host, sizeof(c->underlying_host), port, NULL, 0, uri); + + hints.ai_flags = AI_NUMERICHOST; + if (!getaddrinfo(c->underlying_host, NULL, &hints, &ai)) { + c->numerichost = 1; + freeaddrinfo(ai); + } + + if (!c->host && !(c->host = av_strdup(c->underlying_host))) + return AVERROR(ENOMEM); + + return 0; } int ff_tls_open_underlying(TLSShared *c, URLContext *parent, const char *uri, AVDictionary **options) @@ -58,37 +81,23 @@ int ff_tls_open_underlying(TLSShared *c, URLContext *parent, const char *uri, AV int port; const char *p; char buf[200], opts[50] = ""; - struct addrinfo hints = { 0 }, *ai = NULL; const char *proxy_path; int use_proxy; + int ret; - set_options(c, uri); + if ((ret = ff_tls_process_underlying(c, parent, uri, &port)) < 0) + return ret; if (c->listen) snprintf(opts, sizeof(opts), "?listen=1"); - av_url_split(NULL, 0, NULL, 0, c->underlying_host, sizeof(c->underlying_host), &port, NULL, 0, uri); - p = strchr(uri, '?'); - if (!p) { + if (!p) p = opts; - } else { - if (av_find_info_tag(opts, sizeof(opts), "listen", p)) - c->listen = 1; - } ff_url_join(buf, sizeof(buf), "tcp", NULL, c->underlying_host, port, "%s", p); - hints.ai_flags = AI_NUMERICHOST; - if (!getaddrinfo(c->underlying_host, NULL, &hints, &ai)) { - c->numerichost = 1; - freeaddrinfo(ai); - } - - if (!c->host && !(c->host = av_strdup(c->underlying_host))) - return AVERROR(ENOMEM); - proxy_path = getenv("http_proxy"); use_proxy = !ff_http_match_no_proxy(getenv("no_proxy"), c->underlying_host) && proxy_path && av_strstart(proxy_path, "http://", NULL); diff --git a/libavformat/tls.h b/libavformat/tls.h index beb19d6d55..a954f51733 100644 --- a/libavformat/tls.h +++ b/libavformat/tls.h @@ -51,6 +51,7 @@ 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 } +int ff_tls_process_underlying(TLSShared *c, URLContext *parent, const char *uri, int *port); int ff_tls_open_underlying(TLSShared *c, URLContext *parent, const char *uri, AVDictionary **options); void ff_gnutls_init(void);