iPXE
http.h File Reference

Hyper Text Transport Protocol. More...

#include <stdint.h>
#include <ipxe/refcnt.h>
#include <ipxe/interface.h>
#include <ipxe/iobuf.h>
#include <ipxe/process.h>
#include <ipxe/retry.h>
#include <ipxe/linebuf.h>
#include <ipxe/pool.h>
#include <ipxe/tables.h>
#include <ipxe/ntlm.h>

Go to the source code of this file.

Data Structures

struct  http_scheme
 An HTTP URI scheme. More...
struct  http_connection
 An HTTP connection. More...
struct  http_method
 An HTTP method. More...
struct  http_request_range
 HTTP request range descriptor. More...
struct  http_request_content
 HTTP request content descriptor. More...
struct  http_request_auth_basic
 HTTP request Basic authentication descriptor. More...
struct  http_request_auth_digest
 HTTP request Digest authentication descriptor. More...
struct  http_request_auth_ntlm
 HTTP request NTLM authentication descriptor. More...
struct  http_request_auth
 HTTP request authentication descriptor. More...
struct  http_request
 An HTTP request. More...
struct  http_request_header
 An HTTP request header. More...
struct  http_response_transfer
 HTTP response transfer descriptor. More...
struct  http_response_content
 HTTP response content descriptor. More...
struct  http_response_auth_basic
 HTTP response Basic authorization descriptor. More...
struct  http_response_auth_digest
 HTTP response Digest authorization descriptor. More...
struct  http_response_auth_ntlm
 HTTP response NTLM authorization descriptor. More...
struct  http_response_auth
 HTTP response authorization descriptor. More...
struct  http_response
 An HTTP response. More...
struct  http_response_header
 An HTTP response header. More...
struct  http_state
 HTTP transaction state. More...
struct  http_transaction
 An HTTP transaction. More...
struct  http_transfer_encoding
 An HTTP transfer encoding. More...
struct  http_content_encoding
 An HTTP content encoding. More...
struct  http_authentication
 An HTTP authentication scheme. More...

Macros

#define HTTP_PORT   80
 HTTP default port.
#define HTTPS_PORT   443
 HTTPS default port.
#define HTTP_SCHEMES   __table ( struct http_scheme, "http_schemes" )
 HTTP scheme table.
#define __http_scheme   __table_entry ( HTTP_SCHEMES, 01 )
 Declare an HTTP scheme.
#define HTTP_METHODS   __table ( struct http_method, "http_methods" )
 HTTP method table.
#define __http_method   __table_entry ( HTTP_METHODS, 01 )
 Declare an HTTP method.
#define HTTP_DIGEST_NC   "00000001"
 HTTP Digest authentication client nonce count.
#define HTTP_DIGEST_CNONCE_LEN   8
 HTTP Digest authentication client nonce length.
#define HTTP_DIGEST_RESPONSE_LEN   32
 HTTP Digest authentication response length.
#define HTTP_REQUEST_HEADERS   __table ( struct http_request_header, "http_request_headers" )
 HTTP request header table.
#define __http_request_header   __table_entry ( HTTP_REQUEST_HEADERS, 01 )
 Declare an HTTP request header.
#define HTTP_RESPONSE_HEADERS   __table ( struct http_response_header, "http_response_headers" )
 HTTP response header table.
#define __http_response_header   __table_entry ( HTTP_RESPONSE_HEADERS, 01 )
 Declare an HTTP response header.
#define HTTP_TRANSFER_ENCODINGS   __table ( struct http_transfer_encoding, "http_transfer_encodings" )
 HTTP transfer encoding table.
#define __http_transfer_encoding   __table_entry ( HTTP_TRANSFER_ENCODINGS, 01 )
 Declare an HTTP transfer encoding.
#define HTTP_CONTENT_ENCODINGS   __table ( struct http_content_encoding, "http_content_encodings" )
 HTTP content encoding table.
#define __http_content_encoding   __table_entry ( HTTP_CONTENT_ENCODINGS, 01 )
 Declare an HTTP content encoding.
#define HTTP_AUTHENTICATIONS   __table ( struct http_authentication, "http_authentications" )
 HTTP authentication scheme table.
#define __http_authentication   __table_entry ( HTTP_AUTHENTICATIONS, 01 )
 Declare an HTTP authentication scheme.

Enumerations

enum  http_response_flags { HTTP_RESPONSE_KEEPALIVE = 0x0001 , HTTP_RESPONSE_CONTENT_LEN = 0x0002 , HTTP_RESPONSE_RETRY = 0x0004 }
 HTTP response flags. More...

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 FILE_SECBOOT (PERMITTED)
char * http_token (char **line, char **value)
 Get HTTP response token.
int http_connect (struct interface *xfer, struct uri *uri)
 Connect to an HTTP server.
int http_open (struct interface *xfer, struct http_method *method, struct uri *uri, struct http_request_range *range, struct http_request_content *content)
 Open HTTP transaction.
int http_open_uri (struct interface *xfer, struct uri *uri)
 Open HTTP transaction for simple URI.

Variables

struct http_method http_head __http_method
 HTTP HEAD method.

Detailed Description

Hyper Text Transport Protocol.

Definition in file http.h.

Macro Definition Documentation

◆ HTTP_PORT

#define HTTP_PORT   80

HTTP default port.

Definition at line 35 of file http.h.

◆ HTTPS_PORT

#define HTTPS_PORT   443

HTTPS default port.

Definition at line 38 of file http.h.

◆ HTTP_SCHEMES

#define HTTP_SCHEMES   __table ( struct http_scheme, "http_schemes" )

HTTP scheme table.

Definition at line 55 of file http.h.

Referenced by http_scheme().

◆ __http_scheme

#define __http_scheme   __table_entry ( HTTP_SCHEMES, 01 )

Declare an HTTP scheme.

Definition at line 58 of file http.h.

◆ HTTP_METHODS

#define HTTP_METHODS   __table ( struct http_method, "http_methods" )

HTTP method table.

Definition at line 106 of file http.h.

Referenced by http_method().

◆ __http_method

struct http_method http_put __http_method   __table_entry ( HTTP_METHODS, 01 )

Declare an HTTP method.

HTTP PUT method.

HTTP POST method.

HTTP GET method.

Definition at line 109 of file http.h.

◆ HTTP_DIGEST_NC

#define HTTP_DIGEST_NC   "00000001"

HTTP Digest authentication client nonce count.

We choose to generate a new client nonce each time.

Definition at line 127 of file http.h.

Referenced by http_digest_authenticate(), and http_format_digest_auth().

◆ HTTP_DIGEST_CNONCE_LEN

#define HTTP_DIGEST_CNONCE_LEN   8

HTTP Digest authentication client nonce length.

We choose to use a 32-bit hex client nonce.

Definition at line 133 of file http.h.

◆ HTTP_DIGEST_RESPONSE_LEN

#define HTTP_DIGEST_RESPONSE_LEN   32

HTTP Digest authentication response length.

The Digest authentication response is a Base16-encoded 16-byte MD5 checksum.

Definition at line 140 of file http.h.

◆ HTTP_REQUEST_HEADERS

#define HTTP_REQUEST_HEADERS   __table ( struct http_request_header, "http_request_headers" )

HTTP request header table.

Definition at line 249 of file http.h.

249#define HTTP_REQUEST_HEADERS \
250 __table ( struct http_request_header, "http_request_headers" )

Referenced by http_format_headers().

◆ __http_request_header

struct http_request_header http_request_accept_encoding __http_request_header   __table_entry ( HTTP_REQUEST_HEADERS, 01 )

Declare an HTTP request header.

HTTP "Accept-Encoding" header.

HTTP "Content-Length" header.

HTTP "Content-Type" header.

HTTP "Range" header.

HTTP "Connection" header.

HTTP "User-Agent" header.

HTTP "X-P2P-PeerDist" header.

Definition at line 253 of file http.h.

◆ HTTP_RESPONSE_HEADERS

#define HTTP_RESPONSE_HEADERS   __table ( struct http_response_header, "http_response_headers" )

HTTP response header table.

Definition at line 385 of file http.h.

385#define HTTP_RESPONSE_HEADERS \
386 __table ( struct http_response_header, "http_response_headers" )

Referenced by http_parse_header().

◆ __http_response_header

struct http_response_header http_response_retry_after __http_response_header   __table_entry ( HTTP_RESPONSE_HEADERS, 01 )

Declare an HTTP response header.

HTTP "Retry-After" header.

HTTP "Content-Encoding" header.

HTTP "Content-Length" header.

HTTP "Connection" header.

HTTP "Transfer-Encoding" header.

Definition at line 389 of file http.h.

◆ HTTP_TRANSFER_ENCODINGS

#define HTTP_TRANSFER_ENCODINGS   __table ( struct http_transfer_encoding, "http_transfer_encodings" )

HTTP transfer encoding table.

Definition at line 480 of file http.h.

480#define HTTP_TRANSFER_ENCODINGS \
481 __table ( struct http_transfer_encoding, "http_transfer_encodings" )

Referenced by http_parse_transfer_encoding().

◆ __http_transfer_encoding

#define __http_transfer_encoding   __table_entry ( HTTP_TRANSFER_ENCODINGS, 01 )

Declare an HTTP transfer encoding.

Definition at line 484 of file http.h.

◆ HTTP_CONTENT_ENCODINGS

#define HTTP_CONTENT_ENCODINGS   __table ( struct http_content_encoding, "http_content_encodings" )

HTTP content encoding table.

Definition at line 512 of file http.h.

512#define HTTP_CONTENT_ENCODINGS \
513 __table ( struct http_content_encoding, "http_content_encodings" )

Referenced by http_format_accept_encoding(), and http_parse_content_encoding().

◆ __http_content_encoding

#define __http_content_encoding   __table_entry ( HTTP_CONTENT_ENCODINGS, 01 )

Declare an HTTP content encoding.

Definition at line 516 of file http.h.

◆ HTTP_AUTHENTICATIONS

#define HTTP_AUTHENTICATIONS   __table ( struct http_authentication, "http_authentications" )

HTTP authentication scheme table.

Definition at line 554 of file http.h.

554#define HTTP_AUTHENTICATIONS \
555 __table ( struct http_authentication, "http_authentications" )

Referenced by http_authentication().

◆ __http_authentication

struct http_authentication http_ntlm_auth __http_authentication   __table_entry ( HTTP_AUTHENTICATIONS, 01 )

Declare an HTTP authentication scheme.

HTTP NTLM authentication scheme.

Definition at line 558 of file http.h.

Enumeration Type Documentation

◆ http_response_flags

HTTP response flags.

Enumerator
HTTP_RESPONSE_KEEPALIVE 

Keep connection alive after close.

HTTP_RESPONSE_CONTENT_LEN 

Content length specified.

HTTP_RESPONSE_RETRY 

Transaction may be retried on failure.

Definition at line 362 of file http.h.

362 {
363 /** Keep connection alive after close */
365 /** Content length specified */
367 /** Transaction may be retried on failure */
368 HTTP_RESPONSE_RETRY = 0x0004,
369};
@ HTTP_RESPONSE_CONTENT_LEN
Content length specified.
Definition http.h:366
@ HTTP_RESPONSE_KEEPALIVE
Keep connection alive after close.
Definition http.h:364
@ HTTP_RESPONSE_RETRY
Transaction may be retried on failure.
Definition http.h:368

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL )

◆ FILE_SECBOOT()

FILE_SECBOOT ( PERMITTED )

◆ http_token()

char * http_token ( char ** line,
char ** value )
extern

Get HTTP response token.

Parameters
lineLine position
valueToken value to fill in (if any)
Return values
tokenToken, or NULL

Definition at line 219 of file httpcore.c.

219 {
220 char *token;
221 char quote = '\0';
222 char c;
223
224 /* Avoid returning uninitialised data */
225 if ( value )
226 *value = NULL;
227
228 /* Skip any initial whitespace or commas */
229 while ( ( isspace ( **line ) ) || ( **line == ',' ) )
230 (*line)++;
231
232 /* Check for end of line and record token position */
233 if ( ! **line )
234 return NULL;
235 token = *line;
236
237 /* Scan for end of token */
238 while ( ( c = **line ) ) {
239
240 /* Terminate if we hit an unquoted whitespace or comma */
241 if ( ( isspace ( c ) || ( c == ',' ) ) && ! quote )
242 break;
243
244 /* Terminate if we hit a closing quote */
245 if ( c == quote )
246 break;
247
248 /* Check for value separator */
249 if ( value && ( ! *value ) && ( c == '=' ) ) {
250
251 /* Terminate key portion of token */
252 *((*line)++) = '\0';
253
254 /* Check for quote character */
255 c = **line;
256 if ( ( c == '"' ) || ( c == '\'' ) ) {
257 quote = c;
258 (*line)++;
259 }
260
261 /* Record value portion of token */
262 *value = *line;
263
264 } else {
265
266 /* Move to next character */
267 (*line)++;
268 }
269 }
270
271 /* Terminate token, if applicable */
272 if ( c )
273 *((*line)++) = '\0';
274
275 return token;
276}
#define NULL
NULL pointer (VOID *).
Definition Base.h:321
u8 token
Definition CIB_PRM.h:14
pseudo_bit_t value[0x00020]
Definition arbel.h:2
int isspace(int character)
Check to see if character is a space.
Definition ctype.c:42

References isspace(), NULL, token, and value.

Referenced by http_parse_connection(), http_parse_digest_auth(), http_parse_status(), and http_parse_www_authenticate().

◆ http_connect()

int http_connect ( struct interface * xfer,
struct uri * uri )
extern

Connect to an HTTP server.

Parameters
xferData transfer interface
uriConnection URI
Return values
rcReturn status code

HTTP connections are pooled. The caller should be prepared to receive a pool_reopen() message.

Definition at line 237 of file httpconn.c.

237 {
238 struct http_connection *conn;
239 struct http_scheme *scheme;
240 struct sockaddr_tcpip server;
241 unsigned int port;
242 int rc;
243
244 /* Identify scheme */
245 scheme = http_scheme ( uri );
246 if ( ! scheme )
247 return -ENOTSUP;
248
249 /* Sanity check */
250 if ( ! uri->host )
251 return -EINVAL;
252
253 /* Identify port */
254 port = uri_port ( uri, scheme->port );
255
256 /* Look for a reusable connection in the pool. Reuse the most
257 * recent connection in order to accommodate authentication
258 * schemes that break the stateless nature of HTTP and rely on
259 * the same connection being reused for authentication
260 * responses.
261 */
262 list_for_each_entry_reverse ( conn, &http_connection_pool, pool.list ) {
263
264 /* Sanity checks */
265 assert ( conn->uri != NULL );
266 assert ( conn->uri->host != NULL );
267
268 /* Reuse connection, if possible */
269 if ( ( scheme == conn->scheme ) &&
270 ( strcmp ( uri->host, conn->uri->host ) == 0 ) &&
271 ( port == uri_port ( conn->uri, scheme->port ) ) ) {
272
273 /* Remove from connection pool, stop timer,
274 * attach to parent interface, and return.
275 */
276 pool_del ( &conn->pool );
277 intf_plug_plug ( &conn->xfer, xfer );
278 DBGC2 ( conn, "HTTPCONN %p reused %s://%s:%d\n", conn,
279 conn->scheme->name, conn->uri->host, port );
280 return 0;
281 }
282 }
283
284 /* Allocate and initialise structure */
285 conn = zalloc ( sizeof ( *conn ) );
286 if ( ! conn ) {
287 rc = -ENOMEM;
288 goto err_alloc;
289 }
290 ref_init ( &conn->refcnt, http_conn_free );
291 conn->uri = uri_get ( uri );
292 conn->scheme = scheme;
293 intf_init ( &conn->socket, &http_conn_socket_desc, &conn->refcnt );
294 intf_init ( &conn->xfer, &http_conn_xfer_desc, &conn->refcnt );
295 pool_init ( &conn->pool, http_conn_expired, &conn->refcnt );
296
297 /* Open socket */
298 memset ( &server, 0, sizeof ( server ) );
299 server.st_port = htons ( port );
300 if ( ( rc = xfer_open_named_socket ( &conn->socket, SOCK_STREAM,
301 ( struct sockaddr * ) &server,
302 uri->host, NULL ) ) != 0 )
303 goto err_open;
304
305 /* Add filter, if any */
306 if ( scheme->filter && ( ( rc = scheme->filter ( conn ) ) != 0 ) )
307 goto err_filter;
308
309 /* Attach to parent interface, mortalise self, and return */
310 intf_plug_plug ( &conn->xfer, xfer );
311 ref_put ( &conn->refcnt );
312
313 DBGC2 ( conn, "HTTPCONN %p created %s://%s:%d\n", conn,
314 conn->scheme->name, conn->uri->host, port );
315 return 0;
316
317 err_filter:
318 err_open:
319 DBGC2 ( conn, "HTTPCONN %p could not create %s://%s:%d: %s\n", conn,
320 conn->scheme->name, conn->uri->host, port, strerror ( rc ) );
321 http_conn_close ( conn, rc );
322 ref_put ( &conn->refcnt );
323 err_alloc:
324 return rc;
325}
u8 port
Port number.
Definition CIB_PRM.h:3
struct arbelprm_rc_send_wqe rc
Definition arbel.h:3
#define assert(condition)
Assert a condition at run-time.
Definition assert.h:50
#define SOCK_STREAM
Definition socket.h:25
#define DBGC2(...)
Definition compiler.h:547
#define EINVAL
Invalid argument.
Definition errno.h:429
#define ENOMEM
Not enough space.
Definition errno.h:535
#define ENOTSUP
Operation not supported.
Definition errno.h:590
static struct interface_descriptor http_conn_xfer_desc
HTTP connection data transfer interface descriptor.
Definition httpconn.c:223
static struct http_scheme * http_scheme(struct uri *uri)
Identify HTTP scheme.
Definition httpconn.c:59
static struct interface_descriptor http_conn_socket_desc
HTTP connection socket interface descriptor.
Definition httpconn.c:210
static void http_conn_expired(struct pooled_connection *pool)
Disconnect idle HTTP connection.
Definition httpconn.c:118
static void http_conn_close(struct http_connection *conn, int rc)
Close HTTP connection.
Definition httpconn.c:95
static void http_conn_free(struct refcnt *refcnt)
Free HTTP connection.
Definition httpconn.c:80
#define htons(value)
Definition byteswap.h:136
void * memset(void *dest, int character, size_t len) __nonnull
void intf_plug_plug(struct interface *a, struct interface *b)
Plug two object interfaces together.
Definition interface.c:108
static void intf_init(struct interface *intf, struct interface_descriptor *desc, struct refcnt *refcnt)
Initialise an object interface.
Definition interface.h:204
#define list_for_each_entry_reverse(pos, head, member)
Iterate over entries in a list in reverse order.
Definition list.h:445
void * zalloc(size_t size)
Allocate cleared memory.
Definition malloc.c:662
void pool_del(struct pooled_connection *pool)
Remove connection from pool.
Definition pool.c:83
timer_init & pool
Definition pool.h:66
#define ref_put(refcnt)
Drop reference to object.
Definition refcnt.h:107
#define ref_init(refcnt, free)
Initialise a reference counter.
Definition refcnt.h:65
int xfer_open_named_socket(struct interface *xfer, int semantics, struct sockaddr *peer, const char *name, struct sockaddr *local)
Open named socket.
Definition resolv.c:403
char * strerror(int errno)
Retrieve string representation of error number.
Definition strerror.c:79
int strcmp(const char *first, const char *second)
Compare strings.
Definition string.c:174
An HTTP connection.
Definition http.h:72
struct interface socket
Transport layer interface.
Definition http.h:85
struct uri * uri
Connection URI.
Definition http.h:81
struct pooled_connection pool
Pooled connection.
Definition http.h:89
struct refcnt refcnt
Reference count.
Definition http.h:74
struct interface xfer
Data transfer interface.
Definition http.h:87
struct http_scheme * scheme
HTTP scheme.
Definition http.h:83
An HTTP URI scheme.
Definition http.h:41
unsigned int port
Default port.
Definition http.h:45
int(* filter)(struct http_connection *conn)
Transport-layer filter (if any).
Definition http.h:51
const char * name
Scheme name (e.g.
Definition http.h:43
TCP/IP socket address.
Definition tcpip.h:76
Generalized socket address structure.
Definition socket.h:97
A Uniform Resource Identifier.
Definition uri.h:65
const char * host
Host name.
Definition uri.h:77
unsigned int uri_port(const struct uri *uri, unsigned int default_port)
Get port from URI.
Definition uri.c:457
static struct uri * uri_get(struct uri *uri)
Increment URI reference count.
Definition uri.h:195

References assert, DBGC2, EINVAL, ENOMEM, ENOTSUP, http_scheme::filter, uri::host, htons, http_conn_close(), http_conn_expired(), http_conn_free(), http_conn_socket_desc, http_conn_xfer_desc, http_scheme(), intf_init(), intf_plug_plug(), list_for_each_entry_reverse, memset(), http_scheme::name, NULL, http_connection::pool, pool, pool_del(), http_scheme::port, port, rc, ref_init, ref_put, http_connection::refcnt, http_connection::scheme, SOCK_STREAM, http_connection::socket, sockaddr_tcpip::st_port, strcmp(), strerror(), http_connection::uri, uri_get(), uri_port(), http_connection::xfer, xfer_open_named_socket(), and zalloc().

Referenced by http_open(), and http_reopen().

◆ http_open()

int http_open ( struct interface * xfer,
struct http_method * method,
struct uri * uri,
struct http_request_range * range,
struct http_request_content * content )
extern

Open HTTP transaction.

Parameters
xferData transfer interface
methodRequest method
uriRequest URI
rangeContent range (if any)
contentRequest content (if any)
Return values
rcReturn status code

Definition at line 665 of file httpcore.c.

667 {
668 struct http_transaction *http;
669 struct uri request_uri;
670 struct uri request_host;
671 size_t request_uri_len;
672 size_t request_host_len;
673 size_t content_len;
674 char *request_uri_string;
675 char *request_host_string;
676 void *content_data;
677 int rc;
678
679 /* Calculate request URI length */
680 memset ( &request_uri, 0, sizeof ( request_uri ) );
681 request_uri.epath = ( uri->epath ? uri->epath : "/" );
682 request_uri.equery = uri->equery;
683 request_uri_len =
684 ( format_uri ( &request_uri, NULL, 0 ) + 1 /* NUL */);
685
686 /* Calculate host name length */
687 memset ( &request_host, 0, sizeof ( request_host ) );
688 request_host.host = uri->host;
689 request_host.port = uri->port;
690 request_host_len =
691 ( format_uri ( &request_host, NULL, 0 ) + 1 /* NUL */ );
692
693 /* Calculate request content length */
694 content_len = ( content ? content->len : 0 );
695
696 /* Allocate and initialise structure */
697 http = zalloc ( sizeof ( *http ) + request_uri_len + request_host_len +
698 content_len );
699 if ( ! http ) {
700 rc = -ENOMEM;
701 goto err_alloc;
702 }
703 request_uri_string = ( ( ( void * ) http ) + sizeof ( *http ) );
704 request_host_string = ( request_uri_string + request_uri_len );
705 content_data = ( request_host_string + request_host_len );
706 format_uri ( &request_uri, request_uri_string, request_uri_len );
707 format_uri ( &request_host, request_host_string, request_host_len );
708 ref_init ( &http->refcnt, http_free );
709 intf_init ( &http->xfer, &http_xfer_desc, &http->refcnt );
710 intf_init ( &http->content, &http_content_desc, &http->refcnt );
711 intf_init ( &http->transfer, &http_transfer_desc, &http->refcnt );
712 intf_init ( &http->conn, &http_conn_desc, &http->refcnt );
713 intf_plug_plug ( &http->transfer, &http->content );
714 process_init ( &http->process, &http_process_desc, &http->refcnt );
715 timer_init ( &http->retry, http_retry_expired, &http->refcnt );
716 timer_init ( &http->watchdog, http_watchdog_expired, &http->refcnt );
717 http->uri = uri_get ( uri );
718 http->request.method = method;
719 http->request.uri = request_uri_string;
720 http->request.host = request_host_string;
721 if ( range ) {
722 memcpy ( &http->request.range, range,
723 sizeof ( http->request.range ) );
724 }
725 if ( content ) {
726 http->request.content.type = content->type;
727 http->request.content.data = content_data;
728 http->request.content.len = content_len;
729 memcpy ( content_data, content->data, content_len );
730 }
731 http->state = &http_request;
732 DBGC2 ( http, "HTTP %p %s://%s%s\n", http, http->uri->scheme,
733 http->request.host, http->request.uri );
734
735 /* Open connection */
736 if ( ( rc = http_connect ( &http->conn, uri ) ) != 0 ) {
737 DBGC ( http, "HTTP %p could not connect: %s\n",
738 http, strerror ( rc ) );
739 goto err_connect;
740 }
741
742 /* Start watchdog timer */
743 http_watchdog ( http );
744
745 /* Attach to parent interface, mortalise self, and return */
746 intf_plug_plug ( &http->xfer, xfer );
747 ref_put ( &http->refcnt );
748 return 0;
749
750 err_connect:
751 http_close ( http, rc );
752 ref_put ( &http->refcnt );
753 err_alloc:
754 return rc;
755}
#define DBGC(...)
Definition compiler.h:530
int http_connect(struct interface *xfer, struct uri *uri)
Connect to an HTTP server.
Definition httpconn.c:237
static struct interface_descriptor http_xfer_desc
HTTP data transfer interface descriptor.
Definition httpcore.c:611
static struct process_descriptor http_process_desc
HTTP process descriptor.
Definition httpcore.c:652
static void http_watchdog_expired(struct retry_timer *watchdog, int over __unused)
Handle idle connection watchdog timer expiry.
Definition httpcore.c:398
static void http_free(struct refcnt *refcnt)
Free HTTP transaction.
Definition httpcore.c:290
static struct interface_descriptor http_conn_desc
HTTP server connection interface descriptor.
Definition httpcore.c:647
static struct interface_descriptor http_content_desc
HTTP content-decoded interface descriptor.
Definition httpcore.c:624
static void http_close(struct http_transaction *http, int rc)
Close HTTP transaction.
Definition httpcore.c:306
static void http_watchdog(struct http_transaction *http)
Hold off HTTP idle connection watchdog timer.
Definition httpcore.c:337
static void http_retry_expired(struct retry_timer *retry, int over __unused)
Handle connection retry timer expiry.
Definition httpcore.c:383
static struct interface_descriptor http_transfer_desc
HTTP transfer-decoded interface descriptor.
Definition httpcore.c:634
uint8_t method
Definition ib_mad.h:3
void * memcpy(void *dest, const void *src, size_t len) __nonnull
struct pci_range range
PCI bus:dev.fn address range.
Definition pcicloud.c:40
static void process_init(struct process *process, struct process_descriptor *desc, struct refcnt *refcnt)
Initialise process and add to process list.
Definition process.h:162
size_t len
Content length.
Definition http.h:157
const void * data
Content data (if any).
Definition http.h:155
const char * type
Content type (if any).
Definition http.h:153
An HTTP request.
Definition http.h:218
struct http_request_range range
Range descriptor.
Definition http.h:226
const char * host
Server host name.
Definition http.h:224
struct http_method * method
Method.
Definition http.h:220
const char * uri
Request URI string.
Definition http.h:222
struct http_request_content content
Content descriptor.
Definition http.h:228
An HTTP transaction.
Definition http.h:423
struct refcnt refcnt
Reference count.
Definition http.h:425
struct retry_timer watchdog
Idle connection watchdog timer.
Definition http.h:439
struct process process
Transmit process.
Definition http.h:435
struct retry_timer retry
Reconnection timer.
Definition http.h:437
struct uri * uri
Request URI.
Definition http.h:442
struct interface conn
Server connection.
Definition http.h:433
struct interface transfer
Transfer-decoded interface.
Definition http.h:431
struct interface content
Content-decoded interface.
Definition http.h:429
struct http_request request
Request.
Definition http.h:444
struct interface xfer
Data transfer interface.
Definition http.h:427
struct http_state * state
Transaction state.
Definition http.h:451
const char * epath
Path (with original URI encoding).
Definition uri.h:83
const char * scheme
Scheme.
Definition uri.h:69
const char * equery
Query (with original URI encoding).
Definition uri.h:85
const char * port
Port number.
Definition uri.h:79
size_t format_uri(const struct uri *uri, char *buf, size_t len)
Format URI.
Definition uri.c:473

References http_transaction::conn, http_request::content, http_transaction::content, http_request_content::data, DBGC, DBGC2, ENOMEM, uri::epath, uri::equery, format_uri(), http_request::host, uri::host, http_close(), http_conn_desc, http_connect(), http_content_desc, http_free(), http_process_desc, http_retry_expired(), http_transfer_desc, http_watchdog(), http_watchdog_expired(), http_xfer_desc, intf_init(), intf_plug_plug(), http_request_content::len, memcpy(), memset(), http_request::method, method, NULL, uri::port, http_transaction::process, process_init(), http_request::range, range, rc, ref_init, ref_put, http_transaction::refcnt, http_transaction::request, http_transaction::retry, uri::scheme, http_transaction::state, strerror(), http_transaction::transfer, http_request_content::type, http_request::uri, http_transaction::uri, uri_get(), http_transaction::watchdog, http_transaction::xfer, and zalloc().

Referenced by http_block_read(), http_block_read_capacity(), http_open_uri(), peerblk_raw_open(), peerblk_retrieval_open(), and REQUIRING_SYMBOL().

◆ http_open_uri()

int http_open_uri ( struct interface * xfer,
struct uri * uri )
extern

Open HTTP transaction for simple URI.

Parameters
xferData transfer interface
uriRequest URI
Return values
rcReturn status code

Definition at line 2018 of file httpcore.c.

2018 {
2019 struct parameters *params = uri->params;
2020 struct http_request_content content;
2021 struct http_method *method;
2022 const char *type;
2023 void *data;
2024 size_t len;
2025 size_t check_len;
2026 int rc;
2027
2028 /* Calculate length of form parameter list, if any */
2029 len = ( params ? http_form_params ( params, NULL, 0 ) : 0 );
2030
2031 /* Use POST if and only if there are form parameters */
2032 if ( len ) {
2033
2034 /* Use POST */
2035 method = &http_post;
2036 type = "application/x-www-form-urlencoded";
2037
2038 /* Allocate temporary form parameter list */
2039 data = zalloc ( len + 1 /* NUL */ );
2040 if ( ! data ) {
2041 rc = -ENOMEM;
2042 goto err_alloc;
2043 }
2044
2045 /* Construct temporary form parameter list */
2046 check_len = http_form_params ( params, data,
2047 ( len + 1 /* NUL */ ) );
2048 assert ( check_len == len );
2049
2050 } else {
2051
2052 /* Use GET */
2053 method = &http_get;
2054 type = NULL;
2055 data = NULL;
2056 }
2057
2058 /* Use explicitly requested method name if applicable */
2059 if ( params && params->method ) {
2060 method = http_method ( params->method );
2061 if ( ! method ) {
2062 DBGC ( uri, "HTTP unsupported method \"%s\"\n",
2063 params->method );
2064 rc = -ENOTSUP;
2065 goto err_method;
2066 }
2067 }
2068
2069 /* Construct request content */
2070 content.type = type;
2071 content.data = data;
2072 content.len = len;
2073
2074 /* Open HTTP transaction */
2075 if ( ( rc = http_open ( xfer, method, uri, NULL, &content ) ) != 0 )
2076 goto err_open;
2077
2078 err_open:
2079 err_method:
2080 free ( data );
2081 err_alloc:
2082 return rc;
2083}
ring len
Length.
Definition dwmac.h:226
uint32_t type
Operating system type.
Definition ena.h:1
uint8_t data[48]
Additional event data.
Definition ena.h:11
static size_t http_form_params(struct parameters *params, char *buf, size_t len)
Construct HTTP form parameter list.
Definition httpcore.c:1961
int http_open(struct interface *xfer, struct http_method *method, struct uri *uri, struct http_request_range *range, struct http_request_content *content)
Open HTTP transaction.
Definition httpcore.c:665
static void(* free)(struct refcnt *refcnt))
Definition refcnt.h:55
An HTTP method.
Definition http.h:100
HTTP request content descriptor.
Definition http.h:151
A request parameter list.
Definition params.h:17
const char * method
Request method.
Definition params.h:25
struct parameters * params
Request parameters.
Definition uri.h:89

References assert, data, http_request_content::data, DBGC, ENOMEM, ENOTSUP, free, http_form_params(), http_method(), http_open(), http_request_content::len, len, method, parameters::method, NULL, uri::params, rc, http_request_content::type, type, and zalloc().

Variable Documentation

◆ __http_method

struct http_method http_put __http_method
extern

HTTP HEAD method.

HTTP PUT method.

HTTP POST method.

HTTP GET method.

Definition at line 112 of file http.h.