2011-02-05 22:19:49 +00:00
|
|
|
/*
|
|
|
|
* TLS/SSL Protocol
|
|
|
|
* Copyright (c) 2011 Martin Storsjo
|
|
|
|
*
|
|
|
|
* This file is part of Libav.
|
|
|
|
*
|
|
|
|
* Libav 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,
|
|
|
|
* 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
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "avformat.h"
|
2015-05-26 17:25:41 +00:00
|
|
|
#include "internal.h"
|
|
|
|
#include "network.h"
|
|
|
|
#include "os_support.h"
|
2011-02-05 22:19:49 +00:00
|
|
|
#include "url.h"
|
2015-05-26 17:25:41 +00:00
|
|
|
#include "tls.h"
|
2011-02-05 22:19:49 +00:00
|
|
|
#include "libavutil/avstring.h"
|
2011-02-22 10:02:01 +00:00
|
|
|
#include "libavutil/opt.h"
|
2013-09-19 09:30:52 +00:00
|
|
|
#include "libavutil/parseutils.h"
|
2011-11-10 14:58:58 +00:00
|
|
|
|
2015-05-26 17:25:41 +00:00
|
|
|
int ff_tls_open_underlying(TLSShared *c, URLContext *parent, const char *uri, AVDictionary **options)
|
2011-11-10 14:58:58 +00:00
|
|
|
{
|
2011-02-05 22:19:49 +00:00
|
|
|
int port;
|
2014-10-09 19:34:54 +00:00
|
|
|
const char *p;
|
2015-05-26 17:25:41 +00:00
|
|
|
char buf[200], opts[50] = "";
|
2011-02-05 22:19:49 +00:00
|
|
|
struct addrinfo hints = { 0 }, *ai = NULL;
|
2011-11-10 13:26:23 +00:00
|
|
|
const char *proxy_path;
|
|
|
|
int use_proxy;
|
2011-02-05 22:19:49 +00:00
|
|
|
|
2013-09-19 09:30:52 +00:00
|
|
|
if (c->listen)
|
|
|
|
snprintf(opts, sizeof(opts), "?listen=1");
|
|
|
|
|
2015-05-26 17:25:41 +00:00
|
|
|
av_url_split(NULL, 0, NULL, 0, c->host, sizeof(c->host), &port, NULL, 0, uri);
|
2014-10-09 19:34:54 +00:00
|
|
|
|
|
|
|
p = strchr(uri, '?');
|
|
|
|
|
|
|
|
if (!p) {
|
|
|
|
p = opts;
|
|
|
|
} else {
|
|
|
|
if (av_find_info_tag(opts, sizeof(opts), "listen", p))
|
|
|
|
c->listen = 1;
|
|
|
|
}
|
|
|
|
|
2015-05-26 17:25:41 +00:00
|
|
|
ff_url_join(buf, sizeof(buf), "tcp", NULL, c->host, port, "%s", p);
|
2011-02-05 22:19:49 +00:00
|
|
|
|
|
|
|
hints.ai_flags = AI_NUMERICHOST;
|
2015-05-26 17:25:41 +00:00
|
|
|
if (!getaddrinfo(c->host, NULL, &hints, &ai)) {
|
|
|
|
c->numerichost = 1;
|
2011-02-05 22:19:49 +00:00
|
|
|
freeaddrinfo(ai);
|
|
|
|
}
|
|
|
|
|
2013-02-27 09:13:47 +00:00
|
|
|
proxy_path = getenv("http_proxy");
|
2015-05-26 17:25:41 +00:00
|
|
|
use_proxy = !ff_http_match_no_proxy(getenv("no_proxy"), c->host) &&
|
2014-08-14 20:31:25 +00:00
|
|
|
proxy_path && av_strstart(proxy_path, "http://", NULL);
|
2013-02-27 09:13:47 +00:00
|
|
|
|
2011-11-10 13:26:23 +00:00
|
|
|
if (use_proxy) {
|
|
|
|
char proxy_host[200], proxy_auth[200], dest[200];
|
|
|
|
int proxy_port;
|
|
|
|
av_url_split(NULL, 0, proxy_auth, sizeof(proxy_auth),
|
|
|
|
proxy_host, sizeof(proxy_host), &proxy_port, NULL, 0,
|
|
|
|
proxy_path);
|
2015-05-26 17:25:41 +00:00
|
|
|
ff_url_join(dest, sizeof(dest), NULL, NULL, c->host, port, NULL);
|
2011-11-10 13:26:23 +00:00
|
|
|
ff_url_join(buf, sizeof(buf), "httpproxy", proxy_auth, proxy_host,
|
|
|
|
proxy_port, "/%s", dest);
|
|
|
|
}
|
|
|
|
|
2015-05-26 17:25:41 +00:00
|
|
|
return ffurl_open(&c->tcp, buf, AVIO_FLAG_READ_WRITE,
|
2015-02-28 00:00:50 +00:00
|
|
|
&parent->interrupt_callback, options, parent->protocols, parent);
|
2011-02-05 22:19:49 +00:00
|
|
|
}
|