49 #define BUFFER_SIZE (MAX_URL_SIZE + HTTP_HEADERS_SIZE)
50 #define MAX_REDIRECTS 8
54 #define WHITESPACES " \n\t\r"
111 z_stream inflate_stream;
133 #define OFFSET(x) offsetof(HTTPContext, x)
134 #define D AV_OPT_FLAG_DECODING_PARAM
135 #define E AV_OPT_FLAG_ENCODING_PARAM
136 #define DEFAULT_USER_AGENT "Lavf/" AV_STRINGIFY(LIBAVFORMAT_VERSION)
139 {
"seekable",
"control seekability of connection",
OFFSET(seekable),
AV_OPT_TYPE_BOOL, { .i64 = -1 }, -1, 1,
D },
140 {
"chunked_post",
"use chunked transfer-encoding for posts",
OFFSET(chunked_post),
AV_OPT_TYPE_BOOL, { .i64 = 1 }, 0, 1,
E },
142 {
"headers",
"set custom HTTP headers, can override built in default headers",
OFFSET(headers),
AV_OPT_TYPE_STRING, { .str =
NULL }, 0, 0,
D |
E },
146 #if FF_API_HTTP_USER_AGENT
149 {
"multiple_requests",
"use persistent connections",
OFFSET(multiple_requests),
AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1,
D |
E },
153 {
"cookies",
"set cookies to be sent in applicable future requests, use newline delimited Set-Cookie HTTP field value syntax",
OFFSET(cookies),
AV_OPT_TYPE_STRING, { .str =
NULL }, 0, 0,
D },
159 {
"none",
"No auth method set, autodetect", 0,
AV_OPT_TYPE_CONST, { .i64 =
HTTP_AUTH_NONE }, 0, 0,
D |
E,
"auth_type"},
161 {
"send_expect_100",
"Force sending an Expect: 100-continue header for POST",
OFFSET(send_expect_100),
AV_OPT_TYPE_BOOL, { .i64 = -1 }, -1, 1,
E },
164 {
"end_offset",
"try to limit the request to bytes preceding this offset",
OFFSET(end_off),
AV_OPT_TYPE_INT64, { .i64 = 0 }, 0, INT64_MAX,
D },
165 {
"method",
"Override the HTTP method or set the expected HTTP method from a client",
OFFSET(method),
AV_OPT_TYPE_STRING, { .str =
NULL }, 0, 0,
D |
E },
166 {
"reconnect",
"auto reconnect after disconnect before EOF",
OFFSET(reconnect),
AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1,
D },
167 {
"reconnect_at_eof",
"auto reconnect at EOF",
OFFSET(reconnect_at_eof),
AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1,
D },
168 {
"reconnect_on_network_error",
"auto reconnect in case of tcp/tls error during connect",
OFFSET(reconnect_on_network_error),
AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1,
D },
169 {
"reconnect_on_http_error",
"list of http status codes to reconnect on",
OFFSET(reconnect_on_http_error),
AV_OPT_TYPE_STRING, { .str =
NULL }, 0, 0,
D },
170 {
"reconnect_streamed",
"auto reconnect streamed / non seekable streams",
OFFSET(reconnect_streamed),
AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1,
D },
171 {
"reconnect_delay_max",
"max reconnect delay in seconds after which to give up",
OFFSET(reconnect_delay_max),
AV_OPT_TYPE_INT, { .i64 = 120 }, 0, UINT_MAX/1000/1000,
D },
174 {
"reply_code",
"The http status code to return to a client",
OFFSET(reply_code),
AV_OPT_TYPE_INT, { .i64 = 200}, INT_MIN, 599,
E},
180 const char *hoststr,
const char *auth,
181 const char *proxyauth,
int *new_location);
198 const char *path, *proxy_path, *lower_proto =
"tcp", *local_path;
200 char hostname[1024], hoststr[1024], proto[10];
201 char auth[1024], proxyauth[1024] =
"";
204 int port, use_proxy, err, location_changed = 0;
208 hostname,
sizeof(hostname), &port,
209 path1,
sizeof(path1),
s->location);
210 if (strpbrk(hostname,
"\r\n"))
220 proxy_path =
s->http_proxy ?
s->http_proxy : getenv(
"http_proxy");
224 if (
h->protocol_whitelist &&
av_match_list(proto,
h->protocol_whitelist,
',') <= 0) {
225 av_log(
h,
AV_LOG_ERROR,
"Protocol '%s' not on whitelist '%s'!\n", proto,
h->protocol_whitelist);
229 if (
h->protocol_blacklist &&
av_match_list(proto,
h->protocol_blacklist,
',') > 0) {
234 if (!strcmp(proto,
"https")) {
245 }
else if (strcmp(proto,
"http")) {
252 hashmark = strchr(path1,
'#');
256 if (path1[0] ==
'\0') {
258 }
else if (path1[0] ==
'?') {
259 snprintf(sanitized_path,
sizeof(sanitized_path),
"/%s", path1);
260 path = sanitized_path;
272 hostname,
sizeof(hostname), &port,
NULL, 0, proxy_path);
277 if (
s->hd && strcmp(
s->hd->filename, buf))
283 h->protocol_whitelist,
h->protocol_blacklist,
h);
289 auth, proxyauth, &location_changed);
293 return location_changed;
298 const char *status_group;
307 status_group =
"4xx";
311 status_group =
"5xx";
315 return s->reconnect_on_network_error;
318 if (!
s->reconnect_on_http_error)
321 if (
av_match_list(status_group,
s->reconnect_on_http_error,
',') > 0)
324 snprintf(http_code,
sizeof(http_code),
"%d",
s->http_code);
326 return av_match_list(http_code,
s->reconnect_on_http_error,
',') > 0;
334 int location_changed, attempts = 0, redirects = 0;
335 int reconnect_delay = 0;
341 cur_auth_type =
s->auth_state.auth_type;
342 cur_proxy_auth_type =
s->auth_state.auth_type;
346 if (location_changed < 0) {
348 reconnect_delay >
s->reconnect_delay_max)
353 if (location_changed !=
AVERROR(ETIMEDOUT))
355 reconnect_delay = 1 + 2 * reconnect_delay;
365 if (
s->http_code == 401) {
373 if (
s->http_code == 407) {
374 if ((cur_proxy_auth_type ==
HTTP_AUTH_NONE ||
s->proxy_auth_state.stale) &&
381 if ((
s->http_code == 301 ||
s->http_code == 302 ||
382 s->http_code == 303 ||
s->http_code == 307 ||
s->http_code == 308) &&
383 location_changed == 1) {
386 if (redirects++ >=
s->max_redirects)
390 memset(&
s->auth_state, 0,
sizeof(
s->auth_state));
392 location_changed = 0;
400 if (location_changed < 0)
401 return location_changed;
429 char hostname1[1024], hostname2[1024], proto1[10], proto2[10];
433 !(!strcmp(
h->prot->name,
"http") ||
434 !strcmp(
h->prot->name,
"https")))
438 hostname1,
sizeof(hostname1), &port1,
439 NULL, 0,
s->location);
441 hostname2,
sizeof(hostname2), &port2,
443 if (strcmp(proto1, proto2) != 0) {
444 av_log(
h,
AV_LOG_INFO,
"Cannot reuse HTTP connection for different protocol %s vs %s\n",
448 if (port1 != port2 || strncmp(hostname1, hostname2,
sizeof(hostname2)) != 0) {
449 av_log(
h,
AV_LOG_INFO,
"Cannot reuse HTTP connection for different host: %s:%d != %s:%d\n",
456 if (!
s->end_chunked_post) {
465 s->end_chunked_post = 0;
468 s->icy_data_read = 0;
485 switch (status_code) {
492 if (status_code >= 400 && status_code <= 499)
494 else if (status_code >= 500)
497 return default_averror;
502 int ret,
body = 0, reply_code, message_len;
503 const char *reply_text, *content_type;
506 content_type =
"text/plain";
510 switch (status_code) {
514 reply_text =
"Bad Request";
519 reply_text =
"Forbidden";
524 reply_text =
"Not Found";
529 content_type =
s->content_type ?
s->content_type :
"application/octet-stream";
534 reply_text =
"Internal server error";
542 "HTTP/1.1 %03d %s\r\n"
543 "Content-Type: %s\r\n"
551 strlen(reply_text) + 6,
552 s->headers ?
s->headers :
"",
558 "HTTP/1.1 %03d %s\r\n"
559 "Content-Type: %s\r\n"
560 "Transfer-Encoding: chunked\r\n"
566 s->headers ?
s->headers :
"");
582 int ret, err, new_location;
620 char hostname[1024], proto[10];
622 const char *lower_proto =
"tcp";
624 av_url_split(proto,
sizeof(proto),
NULL, 0, hostname,
sizeof(hostname), &port,
626 if (!strcmp(proto,
"https"))
628 ff_url_join(lower_url,
sizeof(lower_url), lower_proto,
NULL, hostname, port,
634 h->protocol_whitelist,
h->protocol_blacklist,
h
653 if(
s->seekable == 1 )
658 s->filesize = UINT64_MAX;
670 int len = strlen(
s->headers);
671 if (
len < 2 || strcmp(
"\r\n",
s->headers +
len - 2)) {
673 "No trailing CRLF found in HTTP header. Adding it.\n");
677 s->headers[
len] =
'\r';
678 s->headers[
len + 1] =
'\n';
679 s->headers[
len + 2] =
'\0';
706 cc = (*c)->priv_data;
722 if (
s->buf_ptr >=
s->buf_end) {
726 }
else if (
len == 0) {
729 s->buf_ptr =
s->buffer;
730 s->buf_end =
s->buffer +
len;
733 return *
s->buf_ptr++;
748 if (q >
line && q[-1] ==
'\r')
754 if ((q -
line) < line_size - 1)
765 if (http_code >= 400 && http_code < 600 &&
767 (http_code != 407 ||
s->proxy_auth_state.auth_type !=
HTTP_AUTH_NONE)) {
780 new_loc =
av_strdup(redirected_location);
784 s->location = new_loc;
794 if (!strncmp(p,
"bytes ", 6)) {
796 s->off = strtoull(p,
NULL, 10);
797 if ((slash = strchr(p,
'/')) && strlen(slash) > 0)
798 s->filesize = strtoull(slash + 1,
NULL, 10);
800 if (
s->seekable == -1 && (!
s->is_akamai ||
s->filesize != 2147483647))
812 inflateEnd(&
s->inflate_stream);
813 if (inflateInit2(&
s->inflate_stream, 32 + 15) != Z_OK) {
815 s->inflate_stream.msg);
818 if (zlibCompileFlags() & (1 << 17)) {
820 "Your zlib was compiled without gzip support.\n");
825 "Compressed (%s) content, need zlib with gzip support\n", p);
840 int len = 4 + strlen(p) + strlen(
tag);
841 int is_first = !
s->icy_metadata_headers;
846 if (
s->icy_metadata_headers)
847 len += strlen(
s->icy_metadata_headers);
853 *
s->icy_metadata_headers =
'\0';
867 for (
i = 0, j = 0; exp_str[
i] !=
'\0' && j < exp_buf_len;
i++) {
868 if ((exp_str[
i] >=
'0' && exp_str[
i] <=
'9') ||
869 (exp_str[
i] >=
'A' && exp_str[
i] <=
'Z') ||
870 (exp_str[
i] >=
'a' && exp_str[
i] <=
'z')) {
871 exp_buf[j] = exp_str[
i];
879 while ((*expiry < '0' || *expiry >
'9') && *expiry !=
'\0')
887 char *param, *next_param, *cstr, *back;
888 char *saveptr =
NULL;
897 back = &cstr[strlen(cstr)-1];
906 while ((param =
av_strtok(next_param,
";", &saveptr))) {
928 const char *domain = e ? e->
value + (e->
value[0] ==
'.') :
"";
930 return *domain ? domain :
NULL;
935 return !host[strspn(host,
"0123456789.")] || strchr(host,
':');
940 int offset = strlen(host) - strlen(domain);
962 if (!cookie_entry || !cookie_entry->
value) {
969 struct tm new_tm = {0};
981 if (e2 && e2->
value) {
985 if (e2 && e2->
value) {
986 struct tm old_tm = {0};
1001 int host_only = host && !domain;
1010 if (!(eql = strchr(p,
'=')))
return AVERROR(EINVAL);
1017 value =
av_asprintf(
"%.*s%s%s",
len, eql, host_only ?
"; @hostonly=" :
"", host_only ? host :
"");
1030 char host[1024], *cookies, *cookie, *next, *saveptr =
NULL, *
bound;
1041 while ((cookie =
av_strtok(next,
"\n", &saveptr))) {
1043 int len = strlen(cookie), host_only;
1054 av_bprintf(&bp,
"%.*s%s%s\n",
len, cookie, host_only ?
"; @hostonly=" :
"", host_only ? host :
"");
1081 if (*cookies)
av_free(*cookies);
1083 if (!*cookies)
return AVERROR(ENOMEM);
1098 char *
tag, *p, *end, *method, *resource, *
version;
1102 if (
line[0] ==
'\0') {
1108 if (line_count == 0) {
1109 if (
s->is_connected_server) {
1120 av_log(
h,
AV_LOG_ERROR,
"Received and expected HTTP method do not match. (%s expected, %s received)\n",
1129 "(%s autodetected %s received)\n", auto_method, method);
1164 while (*p !=
'/' && *p !=
'\0')
1174 s->http_code = strtol(p, &end, 10);
1182 while (*p !=
'\0' && *p !=
':')
1197 s->filesize == UINT64_MAX) {
1198 s->filesize = strtoull(p,
NULL, 10);
1202 !strncmp(p,
"bytes", 5) &&
1203 s->seekable == -1) {
1207 s->filesize = UINT64_MAX;
1216 if (!strcmp(p,
"close"))
1222 s->is_mediagateway = 1;
1231 s->icy_metaint = strtoull(p,
NULL, 10);
1256 char *cookie, *set_cookies, *next;
1257 char *saveptr =
NULL;
1270 while ((cookie =
av_strtok(next,
"\n", &saveptr)) && !ret) {
1273 const char *domain, *eql;
1287 eql = strchr(cookie,
'=');
1288 if (!cookie_entry || !eql || eql == cookie + strspn(cookie,
WHITESPACES) ||
1289 memchr(cookie,
';', eql - cookie))
1298 struct tm tm_buf = {0};
1319 (
len && path[
len] && path[
len] !=
'/' && path[
len] !=
'?' &&
1327 char *
tmp = *cookies;
1357 s->chunksize = UINT64_MAX;
1373 if (
s->seekable == -1 &&
s->is_mediagateway &&
s->filesize == 2000000000)
1392 #define NEEDS_ESCAPE(ch) \
1393 ((ch) <= ' ' || (ch) >= '\x7f' || \
1394 (ch) == '"' || (ch) == '%' || (ch) == '<' || (ch) == '>' || (ch) == '\\' || \
1395 (ch) == '^' || (ch) == '`' || (ch) == '{' || (ch) == '}' || (ch) == '|')
1399 while (*path && q - buf < sizeof(buf) - 4) {
1400 if (path[0] == '%' && av_isxdigit(path[1]) && av_isxdigit(path[2])) {
1404 } else if (NEEDS_ESCAPE(*path)) {
1405 q += snprintf(q, 4, "%%%02X", (uint8_t)*path++);
1410 av_bprint_append_data(bp, buf, q - buf);
1414 static int http_connect(URLContext *h, const char *path, const char *local_path,
1415 const char *hoststr, const char *auth,
1416 const char *proxyauth, int *new_location)
1418 HTTPContext *s = h->priv_data;
1421 char *authstr = NULL, *proxyauthstr = NULL;
1422 uint64_t off = s->off;
1424 int send_expect_100 = 0;
1426 av_bprint_init_for_buffer(&request, s->buffer, sizeof(s->buffer));
1428 /* send http header */
1429 post = h->flags & AVIO_FLAG_WRITE;
1432 /* force POST method and disable chunked encoding when
1433 * custom HTTP post data is set */
1435 s->chunked_post = 0;
1441 method = post ? "POST" : "GET";
1443 authstr = ff_http_auth_create_response(&s->auth_state, auth,
1444 local_path, method);
1445 proxyauthstr = ff_http_auth_create_response(&s->proxy_auth_state, proxyauth,
1446 local_path, method);
1448 if (post && !s->post_data) {
1449 if (s->send_expect_100 != -1) {
1450 send_expect_100 = s->send_expect_100;
1452 send_expect_100 = 0;
1453 /* The user has supplied authentication but we don't know the auth type,
1454 * send Expect: 100-continue to get the 401 response including the
1455 * WWW-Authenticate header, or an 100 continue if no auth actually
1457 if (auth && *auth &&
1458 s->auth_state.auth_type == HTTP_AUTH_NONE &&
1459 s->http_code != 401)
1460 send_expect_100 = 1;
1464 av_bprintf(&request, "%s ", method);
1465 bprint_escaped_path(&request, path);
1466 av_bprintf(&request, " HTTP/1.1\r\n");
1468 if (post && s->chunked_post)
1469 av_bprintf(&request, "Transfer-Encoding: chunked\r\n");
1470 /* set default headers if needed */
1471 if (!has_header(s->headers, "\r\nUser-Agent: "))
1472 av_bprintf(&request, "User-Agent: %s\r\n", s->user_agent);
1474 /* set default headers if needed */
1475 if (!has_header(s->headers, "\r\nReferer: "))
1476 av_bprintf(&request, "Referer: %s\r\n", s->referer);
1478 if (!has_header(s->headers, "\r\nAccept: "))
1479 av_bprintf(&request, "Accept: *
1519 av_bprintf(&request,
"Proxy-%s", proxyauthstr);
1530 if ((err =
ffurl_write(
s->hd, request.str, request.len)) < 0)
1534 if ((err =
ffurl_write(
s->hd,
s->post_data,
s->post_datalen)) < 0)
1538 s->buf_ptr =
s->buffer;
1539 s->buf_end =
s->buffer;
1542 s->icy_data_read = 0;
1543 s->filesize = UINT64_MAX;
1545 s->end_chunked_post = 0;
1550 if (post && !
s->post_data && !send_expect_100) {
1567 if (off !=
s->off) {
1569 "Unexpected offset: expected %"PRIu64
", got %"PRIu64
"\n",
1590 if (
s->chunksize != UINT64_MAX) {
1594 if (!
s->chunksize) {
1603 s->chunksize = strtoull(
line,
NULL, 16);
1606 "Chunked encoding data size: %"PRIu64
"\n",
1609 if (!
s->chunksize &&
s->multiple_requests) {
1614 else if (!
s->chunksize) {
1619 else if (
s->chunksize == UINT64_MAX) {
1629 len =
s->buf_end -
s->buf_ptr;
1633 memcpy(buf,
s->buf_ptr,
len);
1636 uint64_t target_end =
s->end_off ?
s->end_off :
s->filesize;
1637 if ((!
s->willclose ||
s->chunksize == UINT64_MAX) &&
s->off >= target_end)
1641 (!
s->willclose ||
s->chunksize == UINT64_MAX) &&
s->off < target_end) {
1643 "Stream ends prematurely at %"PRIu64
", should be %"PRIu64
"\n",
1651 if (
s->chunksize > 0 &&
s->chunksize != UINT64_MAX) {
1653 s->chunksize -=
len;
1660 #define DECOMPRESS_BUF_SIZE (256 * 1024)
1666 if (!
s->inflate_buffer) {
1667 s->inflate_buffer =
av_malloc(DECOMPRESS_BUF_SIZE);
1668 if (!
s->inflate_buffer)
1672 if (
s->inflate_stream.avail_in == 0) {
1676 s->inflate_stream.next_in =
s->inflate_buffer;
1677 s->inflate_stream.avail_in = read;
1680 s->inflate_stream.avail_out =
size;
1681 s->inflate_stream.next_out = buf;
1683 ret =
inflate(&
s->inflate_stream, Z_SYNC_FLUSH);
1684 if (ret != Z_OK && ret != Z_STREAM_END)
1686 ret,
s->inflate_stream.msg);
1688 return size -
s->inflate_stream.avail_out;
1697 int err, new_location, read_ret;
1699 int reconnect_delay = 0;
1704 if (
s->end_chunked_post && !
s->end_header) {
1712 return http_buf_read_compressed(
h, buf,
size);
1715 while (read_ret < 0) {
1716 uint64_t target =
h->is_streamed ? 0 :
s->off;
1721 if (
h->is_streamed && !
s->reconnect_streamed)
1724 if (!(
s->reconnect &&
s->filesize > 0 &&
s->off <
s->filesize) &&
1728 if (reconnect_delay >
s->reconnect_delay_max)
1733 if (err !=
AVERROR(ETIMEDOUT))
1735 reconnect_delay = 1 + 2*reconnect_delay;
1737 if (seek_ret >= 0 && seek_ret != target) {
1775 end = strstr(
val,
"';");
1796 if (
s->icy_metaint <
s->icy_data_read)
1798 remaining =
s->icy_metaint -
s->icy_data_read;
1810 char data[255 * 16 + 1];
1821 s->icy_data_read = 0;
1822 remaining =
s->icy_metaint;
1832 if (
s->icy_metaint > 0) {
1840 s->icy_data_read +=
size;
1849 char crlf[] =
"\r\n";
1852 if (!
s->chunked_post) {
1865 (ret =
ffurl_write(
s->hd, crlf,
sizeof(crlf) - 1)) < 0)
1874 char footer[] =
"0\r\n\r\n";
1881 ret = ret > 0 ? 0 : ret;
1889 if (read_ret < 0 && read_ret !=
AVERROR(EAGAIN)) {
1894 s->end_chunked_post = 1;
1906 inflateEnd(&
s->inflate_stream);
1910 if (
s->hd && !
s->end_chunked_post)
1925 uint64_t old_off =
s->off;
1927 int old_buf_size, ret;
1932 else if (!force_reconnect &&
1933 ((whence == SEEK_CUR && off == 0) ||
1934 (whence == SEEK_SET && off ==
s->off)))
1936 else if ((
s->filesize == UINT64_MAX && whence == SEEK_END))
1939 if (whence == SEEK_CUR)
1941 else if (whence == SEEK_END)
1943 else if (whence != SEEK_SET)
1949 if (
s->off &&
h->is_streamed)
1953 if (
s->end_off ||
s->filesize != UINT64_MAX) {
1954 uint64_t end_pos =
s->end_off ?
s->end_off :
s->filesize;
1955 if (
s->off >= end_pos)
1960 old_buf_size =
s->buf_end -
s->buf_ptr;
1961 memcpy(old_buf,
s->buf_ptr, old_buf_size);
1967 memcpy(
s->buffer, old_buf, old_buf_size);
1968 s->buf_ptr =
s->buffer;
1969 s->buf_end =
s->buffer + old_buf_size;
1996 #define HTTP_CLASS(flavor) \
1997 static const AVClass flavor ## _context_class = { \
1998 .class_name = # flavor, \
1999 .item_name = av_default_item_name, \
2000 .option = options, \
2001 .version = LIBAVUTIL_VERSION_INT, \
2004 #if CONFIG_HTTP_PROTOCOL
2020 .priv_data_class = &http_context_class,
2022 .default_whitelist =
"http,https,tls,rtp,tcp,udp,crypto,httpproxy,data"
2026 #if CONFIG_HTTPS_PROTOCOL
2040 .priv_data_class = &https_context_class,
2042 .default_whitelist =
"http,https,tls,rtp,tcp,udp,crypto,httpproxy"
2046 #if CONFIG_HTTPPROXY_PROTOCOL
2058 char hostname[1024], hoststr[1024];
2059 char auth[1024], pathbuf[1024], *path;
2060 char lower_url[100];
2061 int port, ret = 0, attempts = 0;
2066 if(
s->seekable == 1 )
2071 av_url_split(
NULL, 0, auth,
sizeof(auth), hostname,
sizeof(hostname), &port,
2072 pathbuf,
sizeof(pathbuf), uri);
2077 for (
const char *p = path; *p; p++)
2078 if ((
uint8_t)*p <=
' ' || *p == 0x7f)
2081 ff_url_join(lower_url,
sizeof(lower_url),
"tcp",
NULL, hostname, port,
2085 &
h->interrupt_callback,
NULL,
2086 h->protocol_whitelist,
h->protocol_blacklist,
h);
2093 "CONNECT %s HTTP/1.1\r\n"
2095 "Connection: close\r\n"
2100 authstr ?
"Proxy-" :
"", authstr ? authstr :
"");
2103 if ((ret =
ffurl_write(
s->hd,
s->buffer, strlen(
s->buffer))) < 0)
2106 s->buf_ptr =
s->buffer;
2107 s->buf_end =
s->buffer;
2109 s->filesize = UINT64_MAX;
2110 cur_auth_type =
s->proxy_auth_state.auth_type;
2126 if (
s->http_code == 407 &&
2133 if (
s->http_code < 400)
2138 http_proxy_close(
h);
2149 .
name =
"httpproxy",
2150 .url_open = http_proxy_open,
2152 .url_write = http_proxy_write,
2153 .url_close = http_proxy_close,
static double val(void *priv, double ch)
static double bound(const double threshold, const double val)
simple assert() macros that are a bit more flexible than ISO C assert().
#define av_assert0(cond)
assert() equivalent, that is always enabled.
int ffurl_handshake(URLContext *c)
Perform one step of the protocol handshake to accept a new client.
int ffurl_alloc(URLContext **puc, const char *filename, int flags, const AVIOInterruptCB *int_cb)
Create a URLContext for accessing to the resource indicated by url, but do not initiate the connectio...
int ffurl_read(URLContext *h, unsigned char *buf, int size)
Read up to size bytes from the resource accessed by h, and store the read bytes in buf.
int ffurl_open_whitelist(URLContext **puc, const char *filename, int flags, const AVIOInterruptCB *int_cb, AVDictionary **options, const char *whitelist, const char *blacklist, URLContext *parent)
Create an URLContext for accessing to the resource indicated by url, and open it.
int ffurl_get_short_seek(URLContext *h)
Return the current short seek threshold value for this URL.
int ffurl_accept(URLContext *s, URLContext **c)
Accept an URLContext c on an URLContext s.
int ffurl_closep(URLContext **hh)
Close the resource accessed by the URLContext h, and free the memory used by it.
int ffurl_close(URLContext *h)
int ffurl_write(URLContext *h, const unsigned char *buf, int size)
Write size bytes from buf to the resource accessed by h.
int ffurl_get_file_handle(URLContext *h)
Return the file descriptor associated with this URL.
#define AVIO_FLAG_READ
read-only
#define AVSEEK_SIZE
ORing this as the "whence" parameter to a seek function causes it to return the filesize without seek...
#define AVIO_FLAG_WRITE
write-only
#define AVIO_FLAG_READ_WRITE
read-write pseudo flag
#define AVIO_FLAG_NONBLOCK
Use non-blocking mode.
char * av_asprintf(const char *fmt,...)
size_t av_strlcatf(char *dst, size_t size, const char *fmt,...)
void av_bprintf(AVBPrint *buf, const char *fmt,...)
void av_bprint_init(AVBPrint *buf, unsigned size_init, unsigned size_max)
int av_bprint_finalize(AVBPrint *buf, char **ret_str)
Finalize a print buffer.
#define AV_BPRINT_SIZE_UNLIMITED
static int av_bprint_is_complete(const AVBPrint *buf)
Test if the print buffer is complete (not truncated).
#define flags(name, subs,...)
int av_opt_set_dict(void *obj, AVDictionary **options)
Set all the options from a given dictionary on an object.
@ AV_OPT_TYPE_BINARY
offset must point to a pointer immediately followed by an int for the length
void av_url_split(char *proto, int proto_size, char *authorization, int authorization_size, char *hostname, int hostname_size, int *port_ptr, char *path, int path_size, const char *url)
Split a URL string into components.
void av_dict_free(AVDictionary **pm)
Free all the memory allocated for an AVDictionary struct and all keys and values.
#define AV_DICT_IGNORE_SUFFIX
Return first entry in a dictionary whose first part corresponds to the search key,...
int av_dict_copy(AVDictionary **dst, const AVDictionary *src, int flags)
Copy entries from one AVDictionary struct into another.
#define AV_DICT_DONT_STRDUP_VAL
Take ownership of a value that's been allocated with av_malloc() or another memory allocation functio...
int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags)
Set the given entry in *pm, overwriting an existing entry.
#define AV_DICT_DONT_STRDUP_KEY
Take ownership of a key that's been allocated with av_malloc() or another memory allocation function.
AVDictionaryEntry * av_dict_get(const AVDictionary *m, const char *key, const AVDictionaryEntry *prev, int flags)
Get a dictionary entry with matching key.
int av_dict_set_int(AVDictionary **pm, const char *key, int64_t value, int flags)
Convenience wrapper for av_dict_set that converts the value to a string and stores it.
#define AVERROR_HTTP_FORBIDDEN
#define AVERROR_HTTP_BAD_REQUEST
#define AVERROR_EXIT
Immediate exit was requested; the called function should not be restarted.
#define AVERROR_HTTP_SERVER_ERROR
#define AVERROR_HTTP_OTHER_4XX
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
#define AVERROR_EOF
End of file.
#define av_err2str(errnum)
Convenience macro, the return value should be used only directly in function arguments but never stan...
#define AVERROR_HTTP_UNAUTHORIZED
#define AVERROR_HTTP_NOT_FOUND
#define AV_LOG_TRACE
Extremely verbose debugging, useful for libav* development.
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
#define AV_LOG_WARNING
Something somehow does not look correct.
#define AV_LOG_VERBOSE
Detailed information.
#define AV_LOG_INFO
Standard information.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
char * av_strdup(const char *s)
Duplicate a string.
int av_reallocp(void *ptr, size_t size)
Allocate, reallocate, or free a block of memory through a pointer to a pointer.
char * av_strndup(const char *s, size_t len)
Duplicate a substring of a string.
char * av_strtok(char *s, const char *delim, char **saveptr)
Split the string into several tokens which can be accessed by successive calls to av_strtok().
char * av_stristr(const char *s1, const char *s2)
Locate the first case-independent occurrence in the string haystack of the string needle.
int av_strcasecmp(const char *a, const char *b)
Locale-independent case-insensitive compare.
int av_strstart(const char *str, const char *pfx, const char **ptr)
Return non-zero if pfx is a prefix of str.
static av_const int av_isspace(int c)
Locale-independent conversion of ASCII isspace.
int av_match_list(const char *name, const char *list, char separator)
Check if a name is in a list.
int av_stristart(const char *str, const char *pfx, const char **ptr)
Return non-zero if pfx is a prefix of str independent of case.
int av_strncasecmp(const char *a, const char *b, size_t n)
Locale-independent case-insensitive compare.
int av_opt_set(void *obj, const char *name, const char *val, int search_flags)
static int http_handshake(URLContext *c)
static int http_open(URLContext *h, const char *uri, int flags, AVDictionary **options)
static int cookie_string(AVDictionary *dict, char **cookies)
static int store_icy(URLContext *h, int size)
static int parse_content_encoding(URLContext *h, const char *p)
static int host_is_ip_literal(const char *host)
static int http_shutdown(URLContext *h, int flags)
int ff_http_do_new_request2(URLContext *h, const char *uri, AVDictionary **opts)
Send a new HTTP request, reusing the old connection.
static int parse_set_cookie(const char *set_cookie, AVDictionary **dict)
static int http_read(URLContext *h, uint8_t *buf, int size)
static int http_getc(HTTPContext *s)
static const AVOption options[]
static int get_cookies(HTTPContext *s, char **cookies, const char *path)
Create a string containing cookie values for use as a HTTP cookie header field value for a particular...
static int http_open_cnx_internal(URLContext *h, AVDictionary **options)
static void parse_content_range(URLContext *h, const char *p)
int ff_http_get_shutdown_status(URLContext *h)
Get the HTTP shutdown response status, be used after http_shutdown.
static void update_metadata(URLContext *h, char *data)
static int64_t http_seek_internal(URLContext *h, int64_t off, int whence, int force_reconnect)
static int http_get_line(HTTPContext *s, char *line, int line_size)
int ff_http_averror(int status_code, int default_averror)
static int http_buf_read(URLContext *h, uint8_t *buf, int size)
static int parse_icy(HTTPContext *s, const char *tag, const char *p)
static int has_header(const char *str, const char *header)
static int http_listen(URLContext *h, const char *uri, int flags, AVDictionary **options)
static int process_line(URLContext *h, char *line, int line_count, int *new_location)
static int check_http_code(URLContext *h, int http_code, const char *end)
static int host_in_cookie_domain(const char *host, const char *domain)
static int http_get_short_seek(URLContext *h)
static int http_get_file_handle(URLContext *h)
void ff_http_init_auth_state(URLContext *dest, const URLContext *src)
Initialize the authentication state based on another HTTP URLContext.
static int http_write_reply(URLContext *h, int status_code)
static int http_should_reconnect(HTTPContext *s, int err)
static void handle_http_errors(URLContext *h, int error)
static int http_read_header(URLContext *h, int *new_location)
#define DEFAULT_USER_AGENT
#define HTTP_CLASS(flavor)
static int http_connect(URLContext *h, const char *path, const char *local_path, const char *hoststr, const char *auth, const char *proxyauth, int *new_location)
static int parse_set_cookie_expiry_time(const char *exp_str, struct tm *buf)
static int http_write(URLContext *h, const uint8_t *buf, int size)
static void bprint_escaped_path(AVBPrint *bp, const char *path)
Escape unsafe characters in path in order to pass them safely to the HTTP request.
static const char * cookie_domain(const AVDictionary *cookie_params)
static int64_t http_seek(URLContext *h, int64_t off, int whence)
static int bind_cookies_to_host(HTTPContext *s)
static int http_open_cnx(URLContext *h, AVDictionary **options)
static int http_close(URLContext *h)
int ff_http_do_new_request(URLContext *h, const char *uri)
Send a new HTTP request, reusing the old connection.
static int http_accept(URLContext *s, URLContext **c)
static int http_read_stream(URLContext *h, uint8_t *buf, int size)
static int parse_cookie(HTTPContext *s, const char *p, const char *host, AVDictionary **cookies)
static int http_read_stream_all(URLContext *h, uint8_t *buf, int size)
static int parse_location(HTTPContext *s, const char *p)
char * ff_http_auth_create_response(HTTPAuthState *state, const char *auth, const char *path, const char *method)
void ff_http_auth_handle_header(HTTPAuthState *state, const char *key, const char *value)
HTTPAuthType
Authentication types, ordered from weakest to strongest.
@ HTTP_AUTH_NONE
No authentication specified.
@ HTTP_AUTH_BASIC
HTTP 1.0 Basic auth from RFC 1945 (also in RFC 2617)
common internal API header
static void body(uint32_t ABCD[4], const uint8_t *src, int nblocks)
int ff_network_sleep_interruptible(int64_t timeout, AVIOInterruptCB *int_cb)
Waits for up to 'timeout' microseconds.
int ff_http_match_no_proxy(const char *no_proxy, const char *hostname)
#define AV_OPT_FLAG_READONLY
The option may not be set through the AVOptions API, only read.
#define AV_OPT_FLAG_DEPRECATED
set if option is deprecated, users should refer to AVOption.help text for more information
#define AV_OPT_FLAG_EXPORT
The option is intended for exporting values to the caller.
miscellaneous OS support macros and functions.
char * av_small_strptime(const char *p, const char *fmt, struct tm *dt)
Simplified version of strptime.
time_t av_timegm(struct tm *tm)
Convert the decomposed UTC time in tm to a time_t value.
const URLProtocol ff_https_protocol
const URLProtocol ff_http_protocol
const URLProtocol ff_httpproxy_protocol
static const uint8_t header[24]
Describe the class of an AVClass context structure.
HTTP Authentication state structure.
HandshakeState handshake_step
AVDictionary * chained_options
char * icy_metadata_packet
char * reconnect_on_http_error
int seekable
Control seekability, 0 = disable, 1 = enable, -1 = probe.
unsigned char buffer[BUFFER_SIZE]
int reconnect_on_network_error
char * icy_metadata_headers
HTTPAuthState proxy_auth_state
char * cookies
holds newline ( ) delimited Set-Cookie header field values (without the "Set-Cookie: " field name)
AVDictionary * cookie_dict
AVIOInterruptCB interrupt_callback
static void error(const char *err)
int64_t av_gettime(void)
Get the current time in microseconds.
int ff_make_absolute_url(char *buf, int size, const char *base, const char *rel)
Convert a relative url into an absolute url, given a base url.
int ff_url_join(char *str, int size, const char *proto, const char *authorization, const char *hostname, int port, const char *fmt,...)
unbuffered private I/O API
#define URL_PROTOCOL_FLAG_NETWORK
static void inflate(uint8_t *dst, const uint8_t *p1, int width, int threshold, const uint8_t *coordinates[], int coord, int maxc)
static const uint8_t offset[127][2]