3 * Copyright (c) 2011 Martin Storsjo
5 * This file is part of Libav.
7 * Libav is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * Libav is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with Libav; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
25 #include "os_support.h"
28 #include "libavutil/avstring.h"
29 #include "libavutil/opt.h"
30 #include "libavutil/parseutils.h"
32 int ff_tls_open_underlying(TLSShared *c, URLContext *parent, const char *uri, AVDictionary **options)
36 char buf[200], opts[50] = "";
37 struct addrinfo hints = { 0 }, *ai = NULL;
38 const char *proxy_path;
42 snprintf(opts, sizeof(opts), "?listen=1");
44 av_url_split(NULL, 0, NULL, 0, c->host, sizeof(c->host), &port, NULL, 0, uri);
51 if (av_find_info_tag(opts, sizeof(opts), "listen", p))
55 ff_url_join(buf, sizeof(buf), "tcp", NULL, c->host, port, "%s", p);
57 hints.ai_flags = AI_NUMERICHOST;
58 if (!getaddrinfo(c->host, NULL, &hints, &ai)) {
63 proxy_path = getenv("http_proxy");
64 use_proxy = !ff_http_match_no_proxy(getenv("no_proxy"), c->host) &&
65 proxy_path && av_strstart(proxy_path, "http://", NULL);
68 char proxy_host[200], proxy_auth[200], dest[200];
70 av_url_split(NULL, 0, proxy_auth, sizeof(proxy_auth),
71 proxy_host, sizeof(proxy_host), &proxy_port, NULL, 0,
73 ff_url_join(dest, sizeof(dest), NULL, NULL, c->host, port, NULL);
74 ff_url_join(buf, sizeof(buf), "httpproxy", proxy_auth, proxy_host,
75 proxy_port, "/%s", dest);
78 return ffurl_open(&c->tcp, buf, AVIO_FLAG_READ_WRITE,
79 &parent->interrupt_callback, options);