VLC  3.0.0-git
Files | Functions
Messages

HTTP messages, header formatting and parsing. More...

Collaboration diagram for Messages:

Files

file  message.h
 

Functions

struct vlc_http_msgvlc_http_req_create (const char *method, const char *scheme, const char *authority, const char *path) VLC_USED
 Creates an HTTP request. More...
 
struct vlc_http_msgvlc_http_resp_create (unsigned status) VLC_USED
 Creates an HTTP response. More...
 
void vlc_http_msg_destroy (struct vlc_http_msg *)
 Destroys an HTTP message. More...
 
int vlc_http_msg_add_header (struct vlc_http_msg *, const char *name, const char *fmt,...) VLC_FORMAT(3
 Formats a header field. More...
 
int int vlc_http_msg_add_agent (struct vlc_http_msg *, const char *)
 Sets the agent field. More...
 
const char * vlc_http_msg_get_agent (const struct vlc_http_msg *)
 Gets the agent field. More...
 
time_t vlc_http_msg_get_time (const struct vlc_http_msg *, const char *name)
 Parses a timestamp header field. More...
 
int vlc_http_msg_add_time (struct vlc_http_msg *, const char *name, const time_t *t)
 Adds a timestamp header field. More...
 
int vlc_http_msg_add_atime (struct vlc_http_msg *)
 Adds a Date header field. More...
 
time_t vlc_http_msg_get_atime (const struct vlc_http_msg *)
 Gets message date. More...
 
time_t vlc_http_msg_get_mtime (const struct vlc_http_msg *)
 Gets resource date. More...
 
unsigned vlc_http_msg_get_retry_after (const struct vlc_http_msg *)
 Gets retry timeout. More...
 
void vlc_http_msg_get_cookies (const struct vlc_http_msg *, struct vlc_http_cookie_jar_t *, const char *host, const char *path)
 
int vlc_http_msg_add_cookies (struct vlc_http_msg *, struct vlc_http_cookie_jar_t *)
 
char * vlc_http_msg_get_basic_realm (const struct vlc_http_msg *)
 
int vlc_http_msg_add_creds_basic (struct vlc_http_msg *, bool proxy, const char *username, const char *password)
 Adds Basic credentials. More...
 
const char * vlc_http_msg_get_header (const struct vlc_http_msg *, const char *name)
 Looks up an header field. More...
 
int vlc_http_msg_get_status (const struct vlc_http_msg *m)
 Gets response status code. More...
 
const char * vlc_http_msg_get_method (const struct vlc_http_msg *)
 Gets request method. More...
 
const char * vlc_http_msg_get_scheme (const struct vlc_http_msg *)
 Gets request scheme. More...
 
const char * vlc_http_msg_get_authority (const struct vlc_http_msg *)
 Gets request authority. More...
 
const char * vlc_http_msg_get_path (const struct vlc_http_msg *)
 Gets request absolute path. More...
 
const char * vlc_http_msg_get_token (const struct vlc_http_msg *, const char *field, const char *token)
 Looks up a token in a header field. More...
 
const char * vlc_http_next_token (const char *)
 Finds next token. More...
 
uintmax_t vlc_http_msg_get_size (const struct vlc_http_msg *)
 Gets HTTP payload length. More...
 
struct vlc_http_msgvlc_http_msg_iterate (struct vlc_http_msg *) VLC_USED
 Gets next response headers. More...
 
struct vlc_http_msgvlc_http_msg_get_final (struct vlc_http_msg *) VLC_USED
 Gets final response headers. More...
 
struct block_tvlc_http_msg_read (struct vlc_http_msg *) VLC_USED
 Receives HTTP data. More...
 

Detailed Description

HTTP messages, header formatting and parsing.

Function Documentation

◆ vlc_http_msg_add_agent()

int int vlc_http_msg_add_agent ( struct vlc_http_msg ,
const char *   
)

Sets the agent field.

Sets the User-Agent or Server header field.

References vlc_http_msg::status, vlc_http_is_agent(), and vlc_http_msg_add_header().

Referenced by vlc_http_res_req(), and vlc_http_tunnel_open().

◆ vlc_http_msg_add_atime()

int vlc_http_msg_add_atime ( struct vlc_http_msg )

Adds a Date header field.

References vlc_http_msg_add_time().

◆ vlc_http_msg_add_cookies()

int vlc_http_msg_add_cookies ( struct vlc_http_msg ,
struct vlc_http_cookie_jar_t  
)

◆ vlc_http_msg_add_creds_basic()

int vlc_http_msg_add_creds_basic ( struct vlc_http_msg ,
bool  proxy,
const char *  username,
const char *  password 
)

Adds Basic credentials.

Formats a plain username and password pair using HTTP Basic (RFC7617) syntax.

Parameters
proxytrue for proxy authentication, false for origin server authentication
usernamenull-terminated username
passwordnull-terminated password
Returns
0 on success, -1 on out-of-memory (ENOMEM) or if username or password are invalid (EINVAL).

References asprintf(), unlikely, vlc_b64_encode_binary(), and vlc_http_msg_add_header().

Referenced by vlc_http_res_req(), and vlc_http_tunnel_open().

◆ vlc_http_msg_add_header()

int vlc_http_msg_add_header ( struct vlc_http_msg ,
const char *  name,
const char *  fmt,
  ... 
)

Formats a header field.

Adds an HTTP message header to an HTTP request or response. All headers must be formatted before the message is sent.

Parameters
nameheader field name
fmtprintf-style format string
Returns
0 on success, -1 on error (out of memory)

◆ vlc_http_msg_add_time()

int vlc_http_msg_add_time ( struct vlc_http_msg ,
const char *  name,
const time_t *  t 
)

Adds a timestamp header field.

Parameters
nameheader field name
tpointer to timestamp
Returns
0 on success, -1 on error (errno is set accordingly)

References gmtime_r(), vlc_http_days, vlc_http_months, and vlc_http_msg_add_header().

Referenced by vlc_http_file_req(), and vlc_http_msg_add_atime().

◆ vlc_http_msg_destroy()

void vlc_http_msg_destroy ( struct vlc_http_msg )

◆ vlc_http_msg_get_agent()

const char* vlc_http_msg_get_agent ( const struct vlc_http_msg )

Gets the agent field.

Gets the User-Agent or Server header field.

References vlc_http_msg::status, vlc_http_is_agent(), and vlc_http_msg_get_header().

◆ vlc_http_msg_get_atime()

time_t vlc_http_msg_get_atime ( const struct vlc_http_msg )

Gets message date.

Extracts the original date of the message from the HTTP Date header.

Returns
a time value on success, -1 on error.

References vlc_http_msg_get_time().

◆ vlc_http_msg_get_authority()

const char* vlc_http_msg_get_authority ( const struct vlc_http_msg )

Gets request authority.

Returns
request authority (e.g. "www.example.com:8080"), or NULL if response

References vlc_http_msg::authority.

◆ vlc_http_msg_get_basic_realm()

char* vlc_http_msg_get_basic_realm ( const struct vlc_http_msg )

◆ vlc_http_msg_get_cookies()

void vlc_http_msg_get_cookies ( const struct vlc_http_msg ,
struct vlc_http_cookie_jar_t ,
const char *  host,
const char *  path 
)

◆ vlc_http_msg_get_final()

struct vlc_http_msg* vlc_http_msg_get_final ( struct vlc_http_msg )

Gets final response headers.

Skips HTTP 1xx continue headers until a final set of response headers is received. This is a convenience wrapper around vlc_http_msg_iterate() for use when continuation headers are not useful (e.g. GET or CONNECT).

Parameters
mcurrent response headers or NULL
Returns
the final response headers (m if it was already final), NULL if the parameter was NULL, or NULL on error

References vlc_http_msg_get_status(), and vlc_http_msg_iterate().

Referenced by vlc_http_res_open(), and vlc_http_tunnel_open().

◆ vlc_http_msg_get_header()

const char* vlc_http_msg_get_header ( const struct vlc_http_msg ,
const char *  name 
)

Looks up an header field.

Finds an HTTP header field by (case-insensitive) name inside an HTTP message header. If the message has more than one matching field, their value are folded (as permitted by protocol specifications).

Returns
header field value (valid until message is destroyed), or NULL if no fields matched

References vlc_http_msg::headers, and vlc_http_msg_find_header().

Referenced by vlc_http_file_req(), vlc_http_file_resp(), vlc_http_msg_get_agent(), vlc_http_msg_get_file_size(), vlc_http_msg_get_retry_after(), vlc_http_msg_get_size(), vlc_http_msg_get_time(), vlc_http_msg_get_token(), vlc_http_res_get_redirect(), and vlc_http_res_get_type().

◆ vlc_http_msg_get_method()

const char* vlc_http_msg_get_method ( const struct vlc_http_msg )

Gets request method.

Returns
request method (e.g. "GET"), or NULL if response

References vlc_http_msg::method.

◆ vlc_http_msg_get_mtime()

time_t vlc_http_msg_get_mtime ( const struct vlc_http_msg )

Gets resource date.

Extracts the last modification date of the message content from the HTTP Last-Modified header.

Returns
a time value on success, -1 on error.

References vlc_http_msg_get_time().

Referenced by vlc_http_file_req().

◆ vlc_http_msg_get_path()

const char* vlc_http_msg_get_path ( const struct vlc_http_msg )

Gets request absolute path.

Returns
request absolute path (e.g. "/index.html"), or NULL if absent

References vlc_http_msg::path.

◆ vlc_http_msg_get_retry_after()

unsigned vlc_http_msg_get_retry_after ( const struct vlc_http_msg )

Gets retry timeout.

Extracts the time (in seconds) until the expiration of the "retry-after" time-out in the HTTP message. If the header value is an absolute date, it is converted relative to the current time.

Returns
the time in seconds, zero if the date is overdue or on error.

References vlc_http_mktime(), and vlc_http_msg_get_header().

◆ vlc_http_msg_get_scheme()

const char* vlc_http_msg_get_scheme ( const struct vlc_http_msg )

Gets request scheme.

Returns
request scheme (e.g. "https"), or NULL if absent

References vlc_http_msg::scheme.

◆ vlc_http_msg_get_size()

uintmax_t vlc_http_msg_get_size ( const struct vlc_http_msg )

Gets HTTP payload length.

Determines the total length (in bytes) of the payload associated with the HTTP message.

Returns
byte length, or (uintmax_t)-1 if unknown.

References vlc_http_msg::status, and vlc_http_msg_get_header().

Referenced by vlc_h1_stream_wait(), and vlc_http_file_get_size().

◆ vlc_http_msg_get_status()

int vlc_http_msg_get_status ( const struct vlc_http_msg m)

◆ vlc_http_msg_get_time()

time_t vlc_http_msg_get_time ( const struct vlc_http_msg ,
const char *  name 
)

Parses a timestamp header field.

Parameters
nameheader field name
Returns
a timestamp value, or -1 on error.

References vlc_http_mktime(), and vlc_http_msg_get_header().

Referenced by vlc_http_msg_get_atime(), and vlc_http_msg_get_mtime().

◆ vlc_http_msg_get_token()

const char* vlc_http_msg_get_token ( const struct vlc_http_msg ,
const char *  field,
const char *  token 
)

Looks up a token in a header field.

Finds the first occurence of a token within a HTTP field header.

Parameters
fieldHTTP header field name
tokenHTTP token name
Returns
the first byte of the token if found, NULL if not found.

References vlc_http_get_token(), and vlc_http_msg_get_header().

Referenced by vlc_h1_stream_wait(), vlc_http_msg_can_seek(), vlc_http_msg_get_basic_realm(), and vlc_http_res_get_redirect().

◆ vlc_http_msg_iterate()

struct vlc_http_msg* vlc_http_msg_iterate ( struct vlc_http_msg )

Gets next response headers.

Discards the current response headers and gets the next set of response headers for the same request. This is intended for HTTP 1xx continuation responses and for message trailers.

Parameters
mcurrent response headers (destroyed by the call)
Returns
next response headers or NULL on error

References vlc_http_msg::payload, vlc_http_msg_destroy(), and vlc_http_stream_read_headers().

Referenced by vlc_http_msg_get_final().

◆ vlc_http_msg_read()

struct block_t* vlc_http_msg_read ( struct vlc_http_msg )

Receives HTTP data.

Dequeues the next block of data from an HTTP message. If no pending data has been received, waits until data is received, the stream ends or the underlying connection fails.

Returns
data block
Return values
NULLon end-of-stream
vlc_http_erroron fatal error

References vlc_http_msg::payload, and vlc_http_stream_read().

Referenced by vlc_http_res_read().

◆ vlc_http_next_token()

const char* vlc_http_next_token ( const char *  )

Finds next token.

Finds the following token in a HTTP header field value.

Returns
First character of the following token, or NULL if there are no further tokens

References vlc_http_quoted_length().

Referenced by vlc_h1_stream_wait(), and vlc_http_get_token().

◆ vlc_http_req_create()

struct vlc_http_msg* vlc_http_req_create ( const char *  method,
const char *  scheme,
const char *  authority,
const char *  path 
)

Creates an HTTP request.

Allocates an HTTP request message.

Parameters
methodrequest method (e.g. "GET")
schemeprotocol scheme (e.g. "https")
authoritytarget host (e.g. "www.example.com:8080")
pathrequest path (e.g. "/dir/page.html")
Returns
an HTTP stream or NULL on allocation failure

References vlc_http_msg::authority, vlc_http_msg::count, vlc_http_msg::headers, vlc_http_msg::method, vlc_http_msg::path, vlc_http_msg::payload, vlc_http_msg::scheme, vlc_http_msg::status, strdup(), unlikely, and vlc_http_msg_destroy().

Referenced by vlc_http_res_req(), and vlc_http_tunnel_open().

◆ vlc_http_resp_create()

struct vlc_http_msg* vlc_http_resp_create ( unsigned  status)

Creates an HTTP response.

Allocates an HTTP response message.

Parameters
statusHTTP status code
Returns
an HTTP stream or NULL on allocation failure

References vlc_http_msg::authority, vlc_http_msg::count, vlc_http_msg::headers, vlc_http_msg::method, vlc_http_msg::path, vlc_http_msg::payload, vlc_http_msg::scheme, vlc_http_msg::status, and unlikely.

Referenced by vlc_http_msg_h2_headers(), and vlc_http_msg_headers().