| 32 | #include "libavutil/parseutils.h" |
| 33 | |
| 34 | int ff_tls_open_underlying(TLSShared *c, URLContext *parent, const char *uri, AVDictionary **options) |
| 35 | { |
| 36 | int port; |
| 37 | const char *p; |
| 38 | char buf[200], opts[50] = ""; |
| 39 | struct addrinfo hints = { 0 }, *ai = NULL; |
| 40 | const char *proxy_path; |
| 41 | char *env_http_proxy, *env_no_proxy; |
| 42 | int use_proxy; |
| 43 | int ret; |
| 44 | |
| 45 | p = strchr(uri, '?'); |
| 46 | if (p) { |
| 47 | ret = ff_parse_opts_from_query_string(c, p, 1); |
| 48 | if (ret < 0) |
| 49 | return ret; |
| 50 | } |
| 51 | |
| 52 | if (c->listen && !c->is_dtls) |
| 53 | snprintf(opts, sizeof(opts), "?listen=1"); |
| 54 | |
| 55 | av_url_split(NULL, 0, NULL, 0, c->underlying_host, sizeof(c->underlying_host), &port, NULL, 0, uri); |
| 56 | |
| 57 | if (!p) { |
| 58 | p = opts; |
| 59 | } else { |
| 60 | if (av_find_info_tag(opts, sizeof(opts), "listen", p)) |
| 61 | c->listen = 1; |
| 62 | } |
| 63 | |
| 64 | ff_url_join(buf, sizeof(buf), c->is_dtls ? "udp" : "tcp", NULL, (c->is_dtls && c->listen) ? "" : c->underlying_host, port, "%s", p); |
| 65 | |
| 66 | hints.ai_flags = AI_NUMERICHOST; |
| 67 | if (!getaddrinfo(c->underlying_host, NULL, &hints, &ai)) { |
| 68 | c->numerichost = 1; |
| 69 | freeaddrinfo(ai); |
| 70 | } |
| 71 | |
| 72 | if (!c->host && !(c->host = av_strdup(c->underlying_host))) |
| 73 | return AVERROR(ENOMEM); |
| 74 | |
| 75 | env_http_proxy = getenv_utf8("http_proxy"); |
| 76 | proxy_path = c->http_proxy ? c->http_proxy : env_http_proxy; |
| 77 | |
| 78 | env_no_proxy = getenv_utf8("no_proxy"); |
| 79 | use_proxy = !ff_http_match_no_proxy(env_no_proxy, c->underlying_host) && |
| 80 | proxy_path && av_strstart(proxy_path, "http://", NULL); |
| 81 | freeenv_utf8(env_no_proxy); |
| 82 | |
| 83 | if (!c->is_dtls && use_proxy) { |
| 84 | char proxy_host[200], proxy_auth[200], dest[200]; |
| 85 | int proxy_port; |
| 86 | av_url_split(NULL, 0, proxy_auth, sizeof(proxy_auth), |
| 87 | proxy_host, sizeof(proxy_host), &proxy_port, NULL, 0, |
| 88 | proxy_path); |
| 89 | ff_url_join(dest, sizeof(dest), NULL, NULL, c->underlying_host, port, NULL); |
| 90 | ff_url_join(buf, sizeof(buf), "httpproxy", proxy_auth, proxy_host, |
| 91 | proxy_port, "/%s", dest); |
no test coverage detected