45 #define BUFFER_SIZE MAX_URL_SIZE 46 #define MAX_REDIRECTS 8 56 int64_t
off, end_off, filesize;
86 z_stream inflate_stream;
94 #define OFFSET(x) offsetof(HTTPContext, x) 95 #define D AV_OPT_FLAG_DECODING_PARAM 96 #define E AV_OPT_FLAG_ENCODING_PARAM 97 #define DEFAULT_USER_AGENT "Lavf/" AV_STRINGIFY(LIBAVFORMAT_VERSION) 100 {
"chunked_post",
"use chunked transfer-encoding for posts",
OFFSET(chunked_post),
AV_OPT_TYPE_INT, { .i64 = 1 }, 0, 1,
E },
101 {
"headers",
"set custom HTTP headers, can override built in default headers",
OFFSET(headers),
AV_OPT_TYPE_STRING, { 0 }, 0, 0,
D |
E },
102 {
"content_type",
"set a specific content type for the POST messages",
OFFSET(content_type),
AV_OPT_TYPE_STRING, { 0 }, 0, 0,
D |
E },
105 {
"multiple_requests",
"use persistent connections",
OFFSET(multiple_requests),
AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, D |
E },
113 {
"none",
"No auth method set, autodetect", 0,
AV_OPT_TYPE_CONST, { .i64 =
HTTP_AUTH_NONE }, 0, 0, D |
E,
"auth_type"},
115 {
"send_expect_100",
"Force sending an Expect: 100-continue header for POST",
OFFSET(send_expect_100),
AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1,
E },
118 {
"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 },
124 const char *hoststr,
const char *auth,
125 const char *proxyauth,
int *new_location);
139 const char *path, *proxy_path, *lower_proto =
"tcp", *local_path;
140 char hostname[1024], hoststr[1024], proto[10];
141 char auth[1024], proxyauth[1024] =
"";
144 int port, use_proxy, err, location_changed = 0;
148 hostname,
sizeof(hostname), &port,
152 proxy_path = getenv(
"http_proxy");
156 if (!strcmp(proto,
"https")) {
165 if (path1[0] ==
'\0')
177 hostname,
sizeof(hostname), &port,
NULL, 0, proxy_path);
190 auth, proxyauth, &location_changed);
194 return location_changed;
202 int location_changed, attempts = 0, redirects = 0;
208 if (location_changed < 0)
232 location_changed == 1) {
242 location_changed = 0;
290 if (len < 2 || strcmp(
"\r\n", s->
headers + len - 2))
292 "No trailing CRLF found in HTTP header.\n");
308 }
else if (len == 0) {
330 if (q > line && q[-1] ==
'\r')
336 if ((q - line) < line_size - 1)
347 if (http_code >= 400 && http_code < 600 &&
362 new_loc =
av_strdup(redirected_location);
376 if (!strncmp(p,
"bytes ", 6)) {
379 if ((slash = strchr(p,
'/')) && strlen(slash) > 0)
393 inflateEnd(&s->inflate_stream);
394 if (inflateInit2(&s->inflate_stream, 32 + 15) != Z_OK) {
396 s->inflate_stream.msg);
399 if (zlibCompileFlags() & (1 << 17)) {
401 "Your zlib was compiled without gzip support.\n");
406 "Compressed (%s) content, need zlib with gzip support\n", p);
422 int len = 4 + strlen(p) + strlen(tag);
450 if (line[0] ==
'\0') {
456 if (line_count == 0) {
468 while (*p !=
'\0' && *p !=
':')
487 !strncmp(p,
"bytes", 5)) {
500 if (!strcmp(p,
"close"))
518 static inline int has_header(
const char *str,
const char *header)
552 const char *hoststr,
const char *auth,
553 const char *proxyauth,
int *new_location)
558 char *authstr =
NULL, *proxyauthstr =
NULL;
559 int64_t off = s->
off;
562 int send_expect_100 = 0;
577 method = post ?
"POST" :
"GET";
597 len +=
av_strlcatf(headers + len,
sizeof(headers) - len,
600 len +=
av_strlcpy(headers + len,
"Accept: */*\r\n",
601 sizeof(headers) - len);
606 len +=
av_strlcatf(headers + len,
sizeof(headers) - len,
607 "Range: bytes=%"PRId64
"-", s->
off);
609 len +=
av_strlcatf(headers + len,
sizeof(headers) - len,
612 sizeof(headers) - len);
615 len +=
av_strlcatf(headers + len,
sizeof(headers) - len,
616 "Expect: 100-continue\r\n");
620 len +=
av_strlcpy(headers + len,
"Connection: keep-alive\r\n",
621 sizeof(headers) - len);
623 len +=
av_strlcpy(headers + len,
"Connection: close\r\n",
624 sizeof(headers) - len);
628 len +=
av_strlcatf(headers + len,
sizeof(headers) - len,
629 "Host: %s\r\n", hoststr);
631 len +=
av_strlcatf(headers + len,
sizeof(headers) - len,
635 len +=
av_strlcatf(headers + len,
sizeof(headers) - len,
638 len +=
av_strlcatf(headers + len,
sizeof(headers) - len,
639 "Icy-MetaData: %d\r\n", 1);
654 post && s->
chunked_post ?
"Transfer-Encoding: chunked\r\n" :
"",
656 authstr ? authstr :
"",
657 proxyauthstr ?
"Proxy-" :
"", proxyauthstr ? proxyauthstr :
"");
678 if (post && !s->
post_data && !send_expect_100) {
691 return (off == s->
off) ? 0 : -1;
720 #define DECOMPRESS_BUF_SIZE (256 * 1024) 726 if (!s->inflate_buffer) {
727 s->inflate_buffer =
av_malloc(DECOMPRESS_BUF_SIZE);
728 if (!s->inflate_buffer)
732 if (s->inflate_stream.avail_in == 0) {
733 int read =
http_buf_read(h, s->inflate_buffer, DECOMPRESS_BUF_SIZE);
736 s->inflate_stream.next_in = s->inflate_buffer;
737 s->inflate_stream.avail_in = read;
740 s->inflate_stream.avail_out =
size;
741 s->inflate_stream.next_out = buf;
743 ret = inflate(&s->inflate_stream, Z_SYNC_FLUSH);
744 if (ret != Z_OK && ret != Z_STREAM_END)
746 ret, s->inflate_stream.msg);
748 return size - s->inflate_stream.avail_out;
755 int err, new_location;
778 av_dlog(
NULL,
"Chunked encoding data size: %"PRId64
"'\n",
791 return http_buf_read_compressed(h, buf, size);
817 val = strstr(key,
"='");
820 end = strstr(val,
"';");
853 char data[255 * 16 + 1];
860 if ((ret =
av_opt_set(s,
"icy_metadata_packet", data, 0)) < 0)
868 return FFMIN(size, remaining);
892 char crlf[] =
"\r\n";
904 snprintf(temp,
sizeof(temp),
"%x\r\n", size);
917 char footer[] =
"0\r\n\r\n";
923 ret = ret > 0 ? 0 : ret;
936 inflateEnd(&s->inflate_stream);
954 int64_t old_off = s->
off;
956 int old_buf_size, ret;
961 else if ((whence == SEEK_CUR && off == 0) ||
962 (whence == SEEK_SET && off == s->
off))
969 memcpy(old_buf, s->
buf_ptr, old_buf_size);
971 if (whence == SEEK_CUR)
973 else if (whence == SEEK_END)
981 memcpy(s->
buffer, old_buf, old_buf_size);
999 #define HTTP_CLASS(flavor) \ 1000 static const AVClass flavor ## _context_class = { \ 1001 .class_name = # flavor, \ 1002 .item_name = av_default_item_name, \ 1003 .option = options, \ 1004 .version = LIBAVUTIL_VERSION_INT, \ 1007 #if CONFIG_HTTP_PROTOCOL 1020 .priv_data_class = &http_context_class,
1025 #if CONFIG_HTTPS_PROTOCOL 1038 .priv_data_class = &https_context_class,
1043 #if CONFIG_HTTPPROXY_PROTOCOL 1055 char hostname[1024], hoststr[1024];
1056 char auth[1024], pathbuf[1024], *path;
1057 char lower_url[100];
1058 int port, ret = 0, attempts = 0;
1065 av_url_split(
NULL, 0, auth,
sizeof(auth), hostname,
sizeof(hostname), &port,
1066 pathbuf,
sizeof(pathbuf), uri);
1072 ff_url_join(lower_url,
sizeof(lower_url),
"tcp",
NULL, hostname, port,
1083 "CONNECT %s HTTP/1.1\r\n" 1085 "Connection: close\r\n" 1090 authstr ?
"Proxy-" :
"", authstr ? authstr :
"");
1129 http_proxy_close(h);
1140 .
name =
"httpproxy",
1141 .url_open = http_proxy_open,
1143 .url_write = http_proxy_write,
1144 .url_close = http_proxy_close,
static int http_get_line(HTTPContext *s, char *line, int line_size)
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.
static void parse_content_range(URLContext *h, const char *p)
void * av_malloc(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
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)
void ff_make_absolute_url(char *buf, int size, const char *base, const char *rel)
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
#define URL_PROTOCOL_FLAG_NETWORK
#define AV_OPT_FLAG_EXPORT
The option is inteded for exporting values to the caller.
HTTPAuthType
Authentication types, ordered from weakest to strongest.
#define AV_LOG_WARNING
Something somehow does not look correct.
static int http_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.
char * av_stristr(const char *s1, const char *s2)
Locate the first case-independent occurrence in the string haystack of the string needle...
int is_streamed
true if streamed (no seek possible), default = false
AVIOInterruptCB interrupt_callback
HTTPAuthState proxy_auth_state
char * icy_metadata_headers
#define AVIO_FLAG_WRITE
write-only
int av_strncasecmp(const char *a, const char *b, size_t n)
Locale-independent case-insensitive compare.
static int http_getc(HTTPContext *s)
HTTP Authentication state structure.
void av_freep(void *arg)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
av_dlog(ac->avr, "%d samples - audio_convert: %s to %s (%s)\, len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt), use_generic ? ac->func_descr_generic :ac->func_descr)
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.
static int http_get_file_handle(URLContext *h)
static int http_buf_read(URLContext *h, uint8_t *buf, int size)
miscellaneous OS support macros and functions.
static int http_read_header(URLContext *h, int *new_location)
#define HTTP_HEADERS_SIZE
static int http_open_cnx(URLContext *h, AVDictionary **options)
int av_reallocp(void *ptr, size_t size)
Allocate or reallocate a block of memory.
#define DEFAULT_USER_AGENT
#define AVERROR_EOF
End of file.
void ff_http_init_auth_state(URLContext *dest, const URLContext *src)
Initialize the authentication state based on another HTTP URLContext.
HTTP 1.0 Basic auth from RFC 1945 (also in RFC 2617)
static int http_open_cnx_internal(URLContext *h, AVDictionary **options)
void av_dict_copy(AVDictionary **dst, const AVDictionary *src, int flags)
Copy entries from one AVDictionary struct into another.
static void update_metadata(HTTPContext *s, char *data)
void av_free(void *ptr)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc(). ...
static int http_write(URLContext *h, const uint8_t *buf, int size)
static const AVOption options[]
void av_dict_free(AVDictionary **pm)
Free all the memory allocated for an AVDictionary struct and all keys and values. ...
void av_log(void *avcl, int level, const char *fmt,...)
int av_isspace(int c)
Locale-independent conversion of ASCII isspace.
size_t av_strlcpy(char *dst, const char *src, size_t size)
Copy the string src to dst, but no more than size - 1 bytes, and null-terminate dst.
AVDictionary * chained_options
static int store_icy(URLContext *h, int size)
char * icy_metadata_packet
int av_strcasecmp(const char *a, const char *b)
int ff_http_match_no_proxy(const char *no_proxy, const char *hostname)
int ffurl_get_file_handle(URLContext *h)
Return the file descriptor associated with this URL.
int stale
Auth ok, but needs to be resent with a new nonce.
offset must point to a pointer immediately followed by an int for the length
int ff_url_join(char *str, int size, const char *proto, const char *authorization, const char *hostname, int port, const char *fmt,...)
static int http_read(URLContext *h, uint8_t *buf, int size)
char * av_strdup(const char *s)
Duplicate the string s.
#define AVIO_FLAG_READ_WRITE
read-write pseudo flag
int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags)
Set the given entry in *pm, overwriting an existing entry.
unsigned char buffer[BUFFER_SIZE]
Describe the class of an AVClass context structure.
size_t av_strlcatf(char *dst, size_t size, const char *fmt,...)
char * ff_http_auth_create_response(HTTPAuthState *state, const char *auth, const char *path, const char *method)
static int has_header(const char *str, const char *header)
int ffurl_close(URLContext *h)
Close the resource accessed by the URLContext h, and free the memory used by it.
static int process_line(URLContext *h, char *line, int line_count, int *new_location)
int ff_http_do_new_request(URLContext *h, const char *uri)
Send a new HTTP request, reusing the old connection.
int av_strstart(const char *str, const char *pfx, const char **ptr)
Return non-zero if pfx is a prefix of str.
static int parse_content_encoding(URLContext *h, const char *p)
int ffurl_open(URLContext **puc, const char *filename, int flags, const AVIOInterruptCB *int_cb, AVDictionary **options)
Create an URLContext for accessing to the resource indicated by url, and open it. ...
static int http_open(URLContext *h, const char *uri, int flags, AVDictionary **options)
#define AVSEEK_SIZE
Passing this as the "whence" parameter to a seek function causes it to return the filesize without se...
void ff_http_auth_handle_header(HTTPAuthState *state, const char *key, const char *value)
static int parse_location(HTTPContext *s, const char *p)
static int http_shutdown(URLContext *h, int flags)
#define AV_OPT_FLAG_READONLY
The option may not be set through the AVOptions API, only read.
static int parse_icy(HTTPContext *s, const char *tag, const char *p)
HTTPAuthType auth_type
The currently chosen auth type.
static int http_read_stream(URLContext *h, uint8_t *buf, int size)
static int http_read_stream_all(URLContext *h, uint8_t *buf, int size)
unbuffered private I/O API
static int64_t http_seek(URLContext *h, int64_t off, int whence)
int av_opt_set(void *obj, const char *name, const char *val, int search_flags)
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...
#define HTTP_CLASS(flavor)
No authentication specified.
static int check_http_code(URLContext *h, int http_code, const char *end)