FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Data Structures | Macros | Enumerations | Functions | Variables
http.c File Reference
#include "config.h"
#include "libavutil/avassert.h"
#include "libavutil/avstring.h"
#include "libavutil/opt.h"
#include "avformat.h"
#include "http.h"
#include "httpauth.h"
#include "internal.h"
#include "network.h"
#include "os_support.h"
#include "url.h"

Go to the source code of this file.

Data Structures

struct  HTTPContext
 

Macros

#define BUFFER_SIZE   MAX_URL_SIZE
 
#define MAX_REDIRECTS   8
 
#define HTTP_SINGLE   1
 
#define HTTP_MUTLI   2
 
#define OFFSET(x)   offsetof(HTTPContext, x)
 
#define D   AV_OPT_FLAG_DECODING_PARAM
 
#define E   AV_OPT_FLAG_ENCODING_PARAM
 
#define DEFAULT_USER_AGENT   "Lavf/" AV_STRINGIFY(LIBAVFORMAT_VERSION)
 
#define HTTP_CLASS(flavor)
 

Enumerations

enum  HandshakeState { LOWER_PROTO, READ_HEADERS, WRITE_REPLY_HEADERS, FINISH }
 

Functions

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 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. More...
 
static int http_open_cnx_internal (URLContext *h, AVDictionary **options)
 
static int http_open_cnx (URLContext *h, AVDictionary **options)
 
int ff_http_do_new_request (URLContext *h, const char *uri)
 Send a new HTTP request, reusing the old connection. More...
 
int ff_http_averror (int status_code, int default_averror)
 
static int http_write_reply (URLContext *h, int status_code)
 
static void handle_http_errors (URLContext *h, int error)
 
static int http_handshake (URLContext *c)
 
static int http_listen (URLContext *h, const char *uri, int flags, AVDictionary **options)
 
static int http_open (URLContext *h, const char *uri, int flags, AVDictionary **options)
 
static int http_accept (URLContext *s, URLContext **c)
 
static int http_getc (HTTPContext *s)
 
static int http_get_line (HTTPContext *s, char *line, int line_size)
 
static int check_http_code (URLContext *h, int http_code, const char *end)
 
static int parse_location (HTTPContext *s, const char *p)
 
static void parse_content_range (URLContext *h, const char *p)
 
static int parse_content_encoding (URLContext *h, const char *p)
 
static int parse_icy (HTTPContext *s, const char *tag, const char *p)
 
static int parse_cookie (HTTPContext *s, const char *p, AVDictionary **cookies)
 
static int cookie_string (AVDictionary *dict, char **cookies)
 
static int process_line (URLContext *h, char *line, int line_count, int *new_location)
 
static int get_cookies (HTTPContext *s, char **cookies, const char *path, const char *domain)
 Create a string containing cookie values for use as a HTTP cookie header field value for a particular path and domain from the cookie values stored in the HTTP protocol context. More...
 
static int has_header (const char *str, const char *header)
 
static int http_buf_read (URLContext *h, uint8_t *buf, int size)
 
static int64_t http_seek_internal (URLContext *h, int64_t off, int whence, int force_reconnect)
 
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)
 
static void update_metadata (HTTPContext *s, char *data)
 
static int store_icy (URLContext *h, int size)
 
static int http_read (URLContext *h, uint8_t *buf, int size)
 
static int http_write (URLContext *h, const uint8_t *buf, int size)
 
static int http_shutdown (URLContext *h, int flags)
 
static int http_close (URLContext *h)
 
static int64_t http_seek (URLContext *h, int64_t off, int whence)
 
static int http_get_file_handle (URLContext *h)
 

Variables

static const AVOption options []
 

Macro Definition Documentation

#define BUFFER_SIZE   MAX_URL_SIZE

Definition at line 46 of file http.c.

Referenced by http_getc(), http_seek_internal(), and http_write_reply().

#define MAX_REDIRECTS   8

Definition at line 47 of file http.c.

Referenced by http_open_cnx().

#define HTTP_SINGLE   1

Definition at line 48 of file http.c.

Referenced by http_listen().

#define HTTP_MUTLI   2

Definition at line 49 of file http.c.

#define OFFSET (   x)    offsetof(HTTPContext, x)

Definition at line 116 of file http.c.

Definition at line 117 of file http.c.

Definition at line 118 of file http.c.

#define DEFAULT_USER_AGENT   "Lavf/" AV_STRINGIFY(LIBAVFORMAT_VERSION)

Definition at line 119 of file http.c.

#define HTTP_CLASS (   flavor)
Value:
static const AVClass flavor ## _context_class = { \
.class_name = # flavor, \
.item_name = av_default_item_name, \
.option = options, \
.version = LIBAVUTIL_VERSION_INT, \
}
#define LIBAVUTIL_VERSION_INT
Definition: version.h:62
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
Definition: log.h:72
av_default_item_name
static const AVOption options[]
Definition: http.c:121
Describe the class of an AVClass context structure.
Definition: log.h:67

Definition at line 1474 of file http.c.

Enumeration Type Documentation

Enumerator
LOWER_PROTO 
READ_HEADERS 
WRITE_REPLY_HEADERS 
FINISH 

Definition at line 50 of file http.c.

Function Documentation

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

Definition at line 979 of file http.c.

Referenced by http_open_cnx_internal().

static int http_read_header ( URLContext h,
int *  new_location 
)
static

Definition at line 947 of file http.c.

Referenced by http_connect(), http_handshake(), and http_read_stream().

void ff_http_init_auth_state ( URLContext dest,
const URLContext src 
)

Initialize the authentication state based on another HTTP URLContext.

This can be used to pre-initialize the authentication parameters if they are known beforehand, to avoid having to do an initial failing request just to get the parameters.

Parameters
destURL context whose authentication state gets updated
srcURL context whose authentication state gets copied

Definition at line 156 of file http.c.

static int http_open_cnx_internal ( URLContext h,
AVDictionary **  options 
)
static

Definition at line 166 of file http.c.

Referenced by http_open_cnx().

static int http_open_cnx ( URLContext h,
AVDictionary **  options 
)
static

Definition at line 227 of file http.c.

Referenced by ff_http_do_new_request(), http_open(), and http_seek_internal().

int ff_http_do_new_request ( URLContext h,
const char *  uri 
)

Send a new HTTP request, reusing the old connection.

Parameters
hpointer to the resource
uriuri used to perform the request
Returns
a negative value if an error condition occurred, 0 otherwise

Definition at line 283 of file http.c.

Referenced by rtmp_http_send_cmd().

int ff_http_averror ( int  status_code,
int  default_averror 
)

Definition at line 301 of file http.c.

Referenced by check_http_code(), ff_rtsp_averror(), http_open_cnx(), and process_line().

static int http_write_reply ( URLContext h,
int  status_code 
)
static

Definition at line 318 of file http.c.

Referenced by handle_http_errors(), and http_handshake().

static void handle_http_errors ( URLContext h,
int  error 
)
static

Definition at line 388 of file http.c.

Referenced by http_handshake().

static int http_handshake ( URLContext c)
static

Definition at line 394 of file http.c.

Referenced by http_listen().

static int http_listen ( URLContext h,
const char *  uri,
int  flags,
AVDictionary **  options 
)
static

Definition at line 430 of file http.c.

Referenced by http_open().

static int http_open ( URLContext h,
const char *  uri,
int  flags,
AVDictionary **  options 
)
static

Definition at line 459 of file http.c.

static int http_accept ( URLContext s,
URLContext **  c 
)
static

Definition at line 500 of file http.c.

static int http_getc ( HTTPContext s)
static

Definition at line 520 of file http.c.

Referenced by http_get_line().

static int http_get_line ( HTTPContext s,
char *  line,
int  line_size 
)
static

Definition at line 537 of file http.c.

Referenced by http_read_header(), and http_read_stream().

static int check_http_code ( URLContext h,
int  http_code,
const char *  end 
)
static

Definition at line 561 of file http.c.

Referenced by process_line().

static int parse_location ( HTTPContext s,
const char *  p 
)
static

Definition at line 576 of file http.c.

Referenced by process_line().

static void parse_content_range ( URLContext h,
const char *  p 
)
static

Definition at line 590 of file http.c.

Referenced by process_line().

static int parse_content_encoding ( URLContext h,
const char *  p 
)
static

Definition at line 605 of file http.c.

Referenced by process_line().

static int parse_icy ( HTTPContext s,
const char *  tag,
const char *  p 
)
static

Definition at line 639 of file http.c.

Referenced by process_line().

static int parse_cookie ( HTTPContext s,
const char *  p,
AVDictionary **  cookies 
)
static

Definition at line 661 of file http.c.

Referenced by get_cookies(), and process_line().

static int cookie_string ( AVDictionary dict,
char **  cookies 
)
static

Definition at line 675 of file http.c.

Referenced by http_read_header().

static int process_line ( URLContext h,
char *  line,
int  line_count,
int *  new_location 
)
static

Definition at line 698 of file http.c.

Referenced by http_read_header().

static int get_cookies ( HTTPContext s,
char **  cookies,
const char *  path,
const char *  domain 
)
static

Create a string containing cookie values for use as a HTTP cookie header field value for a particular path and domain from the cookie values stored in the HTTP protocol context.

The cookie string is stored in *cookies.

Returns
a negative value if an error condition occurred, 0 otherwise

Definition at line 842 of file http.c.

Referenced by http_connect().

static int has_header ( const char *  str,
const char *  header 
)
inlinestatic

Definition at line 939 of file http.c.

Referenced by http_connect().

static int http_buf_read ( URLContext h,
uint8_t buf,
int  size 
)
static

Definition at line 1138 of file http.c.

Referenced by http_read_stream().

static int64_t http_seek_internal ( URLContext h,
int64_t  off,
int  whence,
int  force_reconnect 
)
static

Definition at line 1415 of file http.c.

Referenced by http_read_stream(), and http_seek().

static int http_read_stream ( URLContext h,
uint8_t buf,
int  size 
)
static

Definition at line 1206 of file http.c.

Referenced by http_read(), and http_read_stream_all().

static int http_read_stream_all ( URLContext h,
uint8_t buf,
int  size 
)
static

Definition at line 1260 of file http.c.

Referenced by store_icy().

static void update_metadata ( HTTPContext s,
char *  data 
)
static

Definition at line 1272 of file http.c.

Referenced by store_icy().

static int store_icy ( URLContext h,
int  size 
)
static

Definition at line 1298 of file http.c.

Referenced by http_read().

static int http_read ( URLContext h,
uint8_t buf,
int  size 
)
static

Definition at line 1335 of file http.c.

static int http_write ( URLContext h,
const uint8_t buf,
int  size 
)
static

Definition at line 1352 of file http.c.

static int http_shutdown ( URLContext h,
int  flags 
)
static

Definition at line 1378 of file http.c.

Referenced by http_close().

static int http_close ( URLContext h)
static

Definition at line 1395 of file http.c.

static int64_t http_seek ( URLContext h,
int64_t  off,
int  whence 
)
static

Definition at line 1463 of file http.c.

static int http_get_file_handle ( URLContext h)
static

Definition at line 1468 of file http.c.

Variable Documentation

const AVOption options[]
static
Initial value:
= {
{ "seekable", "control seekability of connection", OFFSET(seekable), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, 1, D },
{ "chunked_post", "use chunked transfer-encoding for posts", OFFSET(chunked_post), AV_OPT_TYPE_INT, { .i64 = 1 }, 0, 1, E },
{ "headers", "set custom HTTP headers, can override built in default headers", OFFSET(headers), AV_OPT_TYPE_STRING, { 0 }, 0, 0, D | E },
{ "content_type", "set a specific content type for the POST messages", OFFSET(content_type), AV_OPT_TYPE_STRING, { 0 }, 0, 0, D | E },
{ "user_agent", "override User-Agent header", OFFSET(user_agent), AV_OPT_TYPE_STRING, { .str = DEFAULT_USER_AGENT }, 0, 0, D },
{ "user-agent", "override User-Agent header", OFFSET(user_agent), AV_OPT_TYPE_STRING, { .str = DEFAULT_USER_AGENT }, 0, 0, D },
{ "multiple_requests", "use persistent connections", OFFSET(multiple_requests), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, D | E },
{ "post_data", "set custom HTTP post data", OFFSET(post_data), AV_OPT_TYPE_BINARY, .flags = D | E },
{ "mime_type", "export the MIME type", OFFSET(mime_type), AV_OPT_TYPE_STRING, { 0 }, 0, 0, AV_OPT_FLAG_EXPORT | AV_OPT_FLAG_READONLY },
{ "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, { 0 }, 0, 0, D },
{ "icy", "request ICY metadata", OFFSET(icy), AV_OPT_TYPE_INT, { .i64 = 1 }, 0, 1, D },
{ "icy_metadata_headers", "return ICY metadata headers", OFFSET(icy_metadata_headers), AV_OPT_TYPE_STRING, { 0 }, 0, 0, AV_OPT_FLAG_EXPORT },
{ "icy_metadata_packet", "return current ICY metadata packet", OFFSET(icy_metadata_packet), AV_OPT_TYPE_STRING, { 0 }, 0, 0, AV_OPT_FLAG_EXPORT },
{ "metadata", "metadata read from the bitstream", OFFSET(metadata), AV_OPT_TYPE_DICT, {0}, 0, 0, AV_OPT_FLAG_EXPORT },
{ "auth_type", "HTTP authentication type", OFFSET(auth_state.auth_type), AV_OPT_TYPE_INT, { .i64 = HTTP_AUTH_NONE }, HTTP_AUTH_NONE, HTTP_AUTH_BASIC, D | E, "auth_type"},
{ "none", "No auth method set, autodetect", 0, AV_OPT_TYPE_CONST, { .i64 = HTTP_AUTH_NONE }, 0, 0, D | E, "auth_type"},
{ "basic", "HTTP basic authentication", 0, AV_OPT_TYPE_CONST, { .i64 = HTTP_AUTH_BASIC }, 0, 0, D | E, "auth_type"},
{ "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 },
{ "location", "The actual location of the data received", OFFSET(location), AV_OPT_TYPE_STRING, { 0 }, 0, 0, D | E },
{ "offset", "initial byte offset", OFFSET(off), AV_OPT_TYPE_INT64, { .i64 = 0 }, 0, INT64_MAX, D },
{ "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 },
{ "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 },
{ "reconnect", "auto reconnect after disconnect before EOF", OFFSET(reconnect), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, D },
{ "listen", "listen on HTTP", OFFSET(listen), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 2, D | E },
{ "resource", "The resource requested by a client", OFFSET(resource), AV_OPT_TYPE_STRING, { .str = NULL }, 0, 0, E },
{ "reply_code", "The http status code to return to a client", OFFSET(reply_code), AV_OPT_TYPE_INT, { .i64 = 200}, INT_MIN, 599, E},
{ NULL }
}
#define NULL
Definition: coverity.c:32
#define AV_OPT_FLAG_EXPORT
The option is inteded for exporting values to the caller.
Definition: opt.h:296
#define DEFAULT_USER_AGENT
Definition: http.c:119
HTTP 1.0 Basic auth from RFC 1945 (also in RFC 2617)
Definition: httpauth.h:30
#define E
Definition: http.c:118
#define OFFSET(x)
Definition: http.c:116
offset must point to a pointer immediately followed by an int for the length
Definition: opt.h:229
#define AV_OPT_FLAG_READONLY
The option may not be set through the AVOptions API, only read.
Definition: opt.h:301
#define D
Definition: http.c:117
No authentication specified.
Definition: httpauth.h:29

Definition at line 121 of file http.c.