39 #define BUFFER_SIZE MAX_URL_SIZE
40 #define MAX_REDIRECTS 8
49 int64_t
off, filesize;
63 #define OFFSET(x) offsetof(HTTPContext, x)
64 #define D AV_OPT_FLAG_DECODING_PARAM
65 #define E AV_OPT_FLAG_ENCODING_PARAM
67 {
"chunked_post",
"use chunked transfer-encoding for posts",
OFFSET(chunked_post),
AV_OPT_TYPE_INT, {.i64 = 1}, 0, 1,
E },
68 {
"headers",
"custom HTTP headers, can override built in default headers",
OFFSET(headers),
AV_OPT_TYPE_STRING, { 0 }, 0, 0,
D|
E },
69 {
"multiple_requests",
"use persistent connections",
OFFSET(multiple_requests),
AV_OPT_TYPE_INT, {.i64 = 0}, 0, 1,
D|
E },
73 #define HTTP_CLASS(flavor)\
74 static const AVClass flavor ## _context_class = {\
75 .class_name = #flavor,\
76 .item_name = av_default_item_name,\
78 .version = LIBAVUTIL_VERSION_INT,\
85 const char *hoststr,
const char *auth,
86 const char *proxyauth,
int *new_location);
100 const char *path, *proxy_path, *lower_proto =
"tcp", *local_path;
101 char hostname[1024], hoststr[1024], proto[10];
102 char auth[1024], proxyauth[1024] =
"";
105 int port, use_proxy, err, location_changed = 0, redirects = 0, attempts = 0;
109 proxy_path = getenv(
"http_proxy");
110 use_proxy = (proxy_path !=
NULL) && !getenv(
"no_proxy") &&
117 hostname,
sizeof(hostname), &port,
121 if (!strcmp(proto,
"https")) {
130 if (path1[0] ==
'\0')
142 hostname,
sizeof(hostname), &port,
NULL, 0, proxy_path);
156 if (
http_connect(h, path, local_path, hoststr, auth, proxyauth, &location_changed) < 0)
178 && location_changed == 1) {
188 location_changed = 0;
220 if (len < 2 || strcmp(
"\r\n", s->
headers + len - 2))
233 }
else if (len == 0) {
255 if (q > line && q[-1] ==
'\r')
261 if ((q - line) < line_size - 1)
274 if (line[0] ==
'\0') {
280 if (line_count == 0) {
281 while (!isspace(*p) && *p !=
'\0')
300 while (*p !=
'\0' && *p !=
':')
318 if (!strncmp (p,
"bytes ", 6)) {
321 if ((slash = strchr(p,
'/')) && strlen(slash) > 0)
325 }
else if (!
av_strcasecmp(tag,
"Accept-Ranges") && !strncmp(p,
"bytes", 5)) {
337 if (!strcmp(p,
"close"))
344 static inline int has_header(
const char *str,
const char *header)
378 const char *hoststr,
const char *auth,
379 const char *proxyauth,
int *new_location)
383 char headers[1024] =
"";
384 char *authstr =
NULL, *proxyauthstr =
NULL;
400 method = post ?
"POST" :
"GET";
408 len +=
av_strlcatf(headers + len,
sizeof(headers) - len,
411 len +=
av_strlcpy(headers + len,
"Accept: */*\r\n",
412 sizeof(headers) - len);
414 len +=
av_strlcatf(headers + len,
sizeof(headers) - len,
415 "Range: bytes=%"PRId64
"-\r\n", s->
off);
419 len +=
av_strlcpy(headers + len,
"Connection: keep-alive\r\n",
420 sizeof(headers) - len);
422 len +=
av_strlcpy(headers + len,
"Connection: close\r\n",
423 sizeof(headers) - len);
428 len +=
av_strlcatf(headers + len,
sizeof(headers) - len,
429 "Host: %s\r\n", hoststr);
431 len +=
av_strlcatf(headers + len,
sizeof(headers) - len,
447 post && s->
chunked_post ?
"Transfer-Encoding: chunked\r\n" :
"",
449 authstr ? authstr :
"",
450 proxyauthstr ?
"Proxy-" :
"", proxyauthstr ? proxyauthstr :
"");
483 return (off == s->
off) ? 0 : -1;
514 int err, new_location;
554 char crlf[] =
"\r\n";
566 snprintf(temp,
sizeof(temp),
"%x\r\n", size);
579 char footer[] =
"0\r\n\r\n";
585 ret = ret > 0 ? 0 : ret;
611 int64_t old_off = s->
off;
622 memcpy(old_buf, s->
buf_ptr, old_buf_size);
624 if (whence == SEEK_CUR)
626 else if (whence == SEEK_END)
632 memcpy(s->
buffer, old_buf, old_buf_size);
650 #if CONFIG_HTTP_PROTOCOL
661 .priv_data_class = &http_context_class,
665 #if CONFIG_HTTPS_PROTOCOL
676 .priv_data_class = &https_context_class,
681 #if CONFIG_HTTPPROXY_PROTOCOL
693 char hostname[1024], hoststr[1024];
694 char auth[1024], pathbuf[1024], *path;
696 int port, ret = 0, attempts = 0;
703 av_url_split(
NULL, 0, auth,
sizeof(auth), hostname,
sizeof(hostname), &port,
704 pathbuf,
sizeof(pathbuf), uri);
721 "CONNECT %s HTTP/1.1\r\n"
723 "Connection: close\r\n"
728 authstr ?
"Proxy-" :
"", authstr ? authstr :
"");
779 .url_open = http_proxy_open,
781 .url_write = http_proxy_write,
782 .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 int http_open(URLContext *h, const char *uri, int flags)
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)
struct HTTPContext HTTPContext
#define URL_PROTOCOL_FLAG_NETWORK
char location[MAX_URL_SIZE]
HTTPAuthType
Authentication types, ordered from weakest to strongest.
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
int av_strncasecmp(const char *a, const char *b, size_t n)
Locale-independent case-insensitive compare.
av_dlog(ac->avr,"%d samples - audio_convert: %s to %s (%s)\n", 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)
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 ...
#define LIBAVFORMAT_IDENT
int end_chunked_post
A flag which indicates if the end of chunked encoding has been sent.
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)
void ff_http_init_auth_state(URLContext *dest, const URLContext *src)
Initialize the authentication state based on another HTTP URLContext.
static int http_open_cnx(URLContext *h)
static int http_write(URLContext *h, const uint8_t *buf, int size)
static const AVOption options[]
void av_log(void *avcl, int level, const char *fmt,...)
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.
int av_strcasecmp(const char *a, const char *b)
int willclose
Set if the server correctly handles Connection: close and will close the connection after feeding us ...
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
static int http_read(URLContext *h, uint8_t *buf, int size)
#define AVIO_FLAG_READ_WRITE
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.
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. ...
void ff_http_auth_handle_header(HTTPAuthState *state, const char *key, const char *value)
int multiple_requests
A flag which indicates if we use persistent connections.
static int http_shutdown(URLContext *h, int flags)
int end_header
A flag which indicates we have finished to read POST reply.
HTTPAuthType auth_type
The currently chosen auth type.
unbuffered private I/O API
static int64_t http_seek(URLContext *h, int64_t off, int whence)
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...
int64_t chunksize
Used if "Transfer-Encoding: chunked" otherwise -1.
#define HTTP_CLASS(flavor)
No authentication specified.