diff options
Diffstat (limited to 'libavformat/tls.c')
-rw-r--r-- | libavformat/tls.c | 52 |
1 files changed, 41 insertions, 11 deletions
diff --git a/libavformat/tls.c b/libavformat/tls.c index fab243e93e..10e0792e29 100644 --- a/libavformat/tls.c +++ b/libavformat/tls.c @@ -2,20 +2,20 @@ * TLS/SSL Protocol * Copyright (c) 2011 Martin Storsjo * - * This file is part of Libav. + * This file is part of FFmpeg. * - * Libav is free software; you can redistribute it and/or + * FFmpeg is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * - * Libav is distributed in the hope that it will be useful, + * FFmpeg is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public - * License along with Libav; if not, write to the Free Software + * License along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ @@ -29,6 +29,30 @@ #include "libavutil/opt.h" #include "libavutil/parseutils.h" +static void set_options(TLSShared *c, const char *uri) +{ + char buf[1024]; + const char *p = strchr(uri, '?'); + if (!p) + return; + + if (!c->ca_file && av_find_info_tag(buf, sizeof(buf), "cafile", p)) + c->ca_file = av_strdup(buf); + + if (!c->verify && av_find_info_tag(buf, sizeof(buf), "verify", p)) { + char *endptr = NULL; + c->verify = strtol(buf, &endptr, 10); + if (buf == endptr) + c->verify = 1; + } + + if (!c->cert_file && av_find_info_tag(buf, sizeof(buf), "cert", p)) + c->cert_file = av_strdup(buf); + + if (!c->key_file && av_find_info_tag(buf, sizeof(buf), "key", p)) + c->key_file = av_strdup(buf); +} + int ff_tls_open_underlying(TLSShared *c, URLContext *parent, const char *uri, AVDictionary **options) { int port; @@ -38,10 +62,12 @@ int ff_tls_open_underlying(TLSShared *c, URLContext *parent, const char *uri, AV const char *proxy_path; int use_proxy; + set_options(c, uri); + if (c->listen) snprintf(opts, sizeof(opts), "?listen=1"); - av_url_split(NULL, 0, NULL, 0, c->host, sizeof(c->host), &port, NULL, 0, uri); + av_url_split(NULL, 0, NULL, 0, c->underlying_host, sizeof(c->underlying_host), &port, NULL, 0, uri); p = strchr(uri, '?'); @@ -52,16 +78,19 @@ int ff_tls_open_underlying(TLSShared *c, URLContext *parent, const char *uri, AV c->listen = 1; } - ff_url_join(buf, sizeof(buf), "tcp", NULL, c->host, port, "%s", p); + ff_url_join(buf, sizeof(buf), "tcp", NULL, c->underlying_host, port, "%s", p); hints.ai_flags = AI_NUMERICHOST; - if (!getaddrinfo(c->host, NULL, &hints, &ai)) { + 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->host) && + use_proxy = !ff_http_match_no_proxy(getenv("no_proxy"), c->underlying_host) && proxy_path && av_strstart(proxy_path, "http://", NULL); if (use_proxy) { @@ -70,11 +99,12 @@ int ff_tls_open_underlying(TLSShared *c, URLContext *parent, const char *uri, AV av_url_split(NULL, 0, proxy_auth, sizeof(proxy_auth), proxy_host, sizeof(proxy_host), &proxy_port, NULL, 0, proxy_path); - ff_url_join(dest, sizeof(dest), NULL, NULL, c->host, port, NULL); + ff_url_join(dest, sizeof(dest), NULL, NULL, c->underlying_host, port, NULL); ff_url_join(buf, sizeof(buf), "httpproxy", proxy_auth, proxy_host, proxy_port, "/%s", dest); } - return ffurl_open(&c->tcp, buf, AVIO_FLAG_READ_WRITE, - &parent->interrupt_callback, options, parent->protocols, parent); + return ffurl_open_whitelist(&c->tcp, buf, AVIO_FLAG_READ_WRITE, + &parent->interrupt_callback, options, + parent->protocol_whitelist, parent->protocol_blacklist, parent); } |