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_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 HEAD method.
struct http_method http_get
 HTTP GET method.
struct http_method http_post
 HTTP POST 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_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 120 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 126 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 133 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 242 of file http.h.

242#define HTTP_REQUEST_HEADERS \
243 __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 246 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 378 of file http.h.

378#define HTTP_RESPONSE_HEADERS \
379 __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 382 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 473 of file http.h.

473#define HTTP_TRANSFER_ENCODINGS \
474 __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 477 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 505 of file http.h.

505#define HTTP_CONTENT_ENCODINGS \
506 __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 509 of file http.h.

◆ HTTP_AUTHENTICATIONS

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

HTTP authentication scheme table.

Definition at line 547 of file http.h.

547#define HTTP_AUTHENTICATIONS \
548 __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 551 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 355 of file http.h.

355 {
356 /** Keep connection alive after close */
358 /** Content length specified */
360 /** Transaction may be retried on failure */
361 HTTP_RESPONSE_RETRY = 0x0004,
362};
@ HTTP_RESPONSE_CONTENT_LEN
Content length specified.
Definition http.h:359
@ HTTP_RESPONSE_KEEPALIVE
Keep connection alive after close.
Definition http.h:357
@ HTTP_RESPONSE_RETRY
Transaction may be retried on failure.
Definition http.h:361

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 196 of file httpcore.c.

196 {
197 char *token;
198 char quote = '\0';
199 char c;
200
201 /* Avoid returning uninitialised data */
202 if ( value )
203 *value = NULL;
204
205 /* Skip any initial whitespace or commas */
206 while ( ( isspace ( **line ) ) || ( **line == ',' ) )
207 (*line)++;
208
209 /* Check for end of line and record token position */
210 if ( ! **line )
211 return NULL;
212 token = *line;
213
214 /* Scan for end of token */
215 while ( ( c = **line ) ) {
216
217 /* Terminate if we hit an unquoted whitespace or comma */
218 if ( ( isspace ( c ) || ( c == ',' ) ) && ! quote )
219 break;
220
221 /* Terminate if we hit a closing quote */
222 if ( c == quote )
223 break;
224
225 /* Check for value separator */
226 if ( value && ( ! *value ) && ( c == '=' ) ) {
227
228 /* Terminate key portion of token */
229 *((*line)++) = '\0';
230
231 /* Check for quote character */
232 c = **line;
233 if ( ( c == '"' ) || ( c == '\'' ) ) {
234 quote = c;
235 (*line)++;
236 }
237
238 /* Record value portion of token */
239 *value = *line;
240
241 } else {
242
243 /* Move to next character */
244 (*line)++;
245 }
246 }
247
248 /* Terminate token, if applicable */
249 if ( c )
250 *((*line)++) = '\0';
251
252 return token;
253}
#define NULL
NULL pointer (VOID *)
Definition Base.h:322
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:522
#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 642 of file httpcore.c.

644 {
645 struct http_transaction *http;
646 struct uri request_uri;
647 struct uri request_host;
648 size_t request_uri_len;
649 size_t request_host_len;
650 size_t content_len;
651 char *request_uri_string;
652 char *request_host_string;
653 void *content_data;
654 int rc;
655
656 /* Calculate request URI length */
657 memset ( &request_uri, 0, sizeof ( request_uri ) );
658 request_uri.epath = ( uri->epath ? uri->epath : "/" );
659 request_uri.equery = uri->equery;
660 request_uri_len =
661 ( format_uri ( &request_uri, NULL, 0 ) + 1 /* NUL */);
662
663 /* Calculate host name length */
664 memset ( &request_host, 0, sizeof ( request_host ) );
665 request_host.host = uri->host;
666 request_host.port = uri->port;
667 request_host_len =
668 ( format_uri ( &request_host, NULL, 0 ) + 1 /* NUL */ );
669
670 /* Calculate request content length */
671 content_len = ( content ? content->len : 0 );
672
673 /* Allocate and initialise structure */
674 http = zalloc ( sizeof ( *http ) + request_uri_len + request_host_len +
675 content_len );
676 if ( ! http ) {
677 rc = -ENOMEM;
678 goto err_alloc;
679 }
680 request_uri_string = ( ( ( void * ) http ) + sizeof ( *http ) );
681 request_host_string = ( request_uri_string + request_uri_len );
682 content_data = ( request_host_string + request_host_len );
683 format_uri ( &request_uri, request_uri_string, request_uri_len );
684 format_uri ( &request_host, request_host_string, request_host_len );
685 ref_init ( &http->refcnt, http_free );
686 intf_init ( &http->xfer, &http_xfer_desc, &http->refcnt );
687 intf_init ( &http->content, &http_content_desc, &http->refcnt );
688 intf_init ( &http->transfer, &http_transfer_desc, &http->refcnt );
689 intf_init ( &http->conn, &http_conn_desc, &http->refcnt );
690 intf_plug_plug ( &http->transfer, &http->content );
691 process_init ( &http->process, &http_process_desc, &http->refcnt );
692 timer_init ( &http->retry, http_retry_expired, &http->refcnt );
693 timer_init ( &http->watchdog, http_watchdog_expired, &http->refcnt );
694 http->uri = uri_get ( uri );
695 http->request.method = method;
696 http->request.uri = request_uri_string;
697 http->request.host = request_host_string;
698 if ( range ) {
699 memcpy ( &http->request.range, range,
700 sizeof ( http->request.range ) );
701 }
702 if ( content ) {
703 http->request.content.type = content->type;
704 http->request.content.data = content_data;
705 http->request.content.len = content_len;
706 memcpy ( content_data, content->data, content_len );
707 }
708 http->state = &http_request;
709 DBGC2 ( http, "HTTP %p %s://%s%s\n", http, http->uri->scheme,
710 http->request.host, http->request.uri );
711
712 /* Open connection */
713 if ( ( rc = http_connect ( &http->conn, uri ) ) != 0 ) {
714 DBGC ( http, "HTTP %p could not connect: %s\n",
715 http, strerror ( rc ) );
716 goto err_connect;
717 }
718
719 /* Start watchdog timer */
720 http_watchdog ( http );
721
722 /* Attach to parent interface, mortalise self, and return */
723 intf_plug_plug ( &http->xfer, xfer );
724 ref_put ( &http->refcnt );
725 return 0;
726
727 err_connect:
728 http_close ( http, rc );
729 ref_put ( &http->refcnt );
730 err_alloc:
731 return rc;
732}
#define DBGC(...)
Definition compiler.h:505
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:588
static struct process_descriptor http_process_desc
HTTP process descriptor.
Definition httpcore.c:629
static void http_watchdog_expired(struct retry_timer *watchdog, int over __unused)
Handle idle connection watchdog timer expiry.
Definition httpcore.c:375
static void http_free(struct refcnt *refcnt)
Free HTTP transaction.
Definition httpcore.c:267
static struct interface_descriptor http_conn_desc
HTTP server connection interface descriptor.
Definition httpcore.c:624
static struct interface_descriptor http_content_desc
HTTP content-decoded interface descriptor.
Definition httpcore.c:601
static void http_close(struct http_transaction *http, int rc)
Close HTTP transaction.
Definition httpcore.c:283
static void http_watchdog(struct http_transaction *http)
Hold off HTTP idle connection watchdog timer.
Definition httpcore.c:314
static void http_retry_expired(struct retry_timer *retry, int over __unused)
Handle connection retry timer expiry.
Definition httpcore.c:360
static struct interface_descriptor http_transfer_desc
HTTP transfer-decoded interface descriptor.
Definition httpcore.c:611
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:150
const void * data
Content data (if any)
Definition http.h:148
const char * type
Content type (if any)
Definition http.h:146
An HTTP request.
Definition http.h:211
struct http_request_range range
Range descriptor.
Definition http.h:219
const char * host
Server host name.
Definition http.h:217
struct http_method * method
Method.
Definition http.h:213
const char * uri
Request URI string.
Definition http.h:215
struct http_request_content content
Content descriptor.
Definition http.h:221
An HTTP transaction.
Definition http.h:416
struct refcnt refcnt
Reference count.
Definition http.h:418
struct retry_timer watchdog
Idle connection watchdog timer.
Definition http.h:432
struct process process
Transmit process.
Definition http.h:428
struct retry_timer retry
Reconnection timer.
Definition http.h:430
struct uri * uri
Request URI.
Definition http.h:435
struct interface conn
Server connection.
Definition http.h:426
struct interface transfer
Transfer-decoded interface.
Definition http.h:424
struct interface content
Content-decoded interface.
Definition http.h:422
struct http_request request
Request.
Definition http.h:437
struct interface xfer
Data transfer interface.
Definition http.h:420
struct http_state * state
Transaction state.
Definition http.h:444
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 1984 of file httpcore.c.

1984 {
1985 struct parameters *params = uri->params;
1986 struct http_request_content content;
1987 struct http_method *method;
1988 const char *type;
1989 void *data;
1990 size_t len;
1991 size_t check_len;
1992 int rc;
1993
1994 /* Calculate length of form parameter list, if any */
1995 len = ( params ? http_form_params ( params, NULL, 0 ) : 0 );
1996
1997 /* Use POST if and only if there are form parameters */
1998 if ( len ) {
1999
2000 /* Use POST */
2001 method = &http_post;
2002 type = "application/x-www-form-urlencoded";
2003
2004 /* Allocate temporary form parameter list */
2005 data = zalloc ( len + 1 /* NUL */ );
2006 if ( ! data ) {
2007 rc = -ENOMEM;
2008 goto err_alloc;
2009 }
2010
2011 /* Construct temporary form parameter list */
2012 check_len = http_form_params ( params, data,
2013 ( len + 1 /* NUL */ ) );
2014 assert ( check_len == len );
2015
2016 } else {
2017
2018 /* Use GET */
2019 method = &http_get;
2020 type = NULL;
2021 data = NULL;
2022 }
2023
2024 /* Construct request content */
2025 content.type = type;
2026 content.data = data;
2027 content.len = len;
2028
2029 /* Open HTTP transaction */
2030 if ( ( rc = http_open ( xfer, method, uri, NULL, &content ) ) != 0 )
2031 goto err_open;
2032
2033 err_open:
2034 free ( data );
2035 err_alloc:
2036 return rc;
2037}
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
struct http_method http_post
HTTP POST method.
Definition httpcore.c:149
struct http_method http_get
HTTP GET method.
Definition httpcore.c:144
static size_t http_form_params(struct parameters *params, char *buf, size_t len)
Construct HTTP form parameter list.
Definition httpcore.c:1927
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:642
static void(* free)(struct refcnt *refcnt))
Definition refcnt.h:55
An HTTP method.
Definition http.h:100
HTTP request content descriptor.
Definition http.h:144
A request parameter list.
Definition params.h:17
struct parameters * params
Request parameters.
Definition uri.h:89

References assert, data, http_request_content::data, ENOMEM, free, http_form_params(), http_get, http_open(), http_post, http_request_content::len, len, method, NULL, uri::params, rc, http_request_content::type, type, and zalloc().

Variable Documentation

◆ http_head

struct http_method http_head
extern

HTTP HEAD method.

Definition at line 139 of file httpcore.c.

139 {
140 .name = "HEAD",
141};

Referenced by http_block_read_capacity(), and http_rx_headers().

◆ http_get

struct http_method http_get
extern

HTTP GET method.

Definition at line 144 of file httpcore.c.

144 {
145 .name = "GET",
146};

Referenced by http_block_read(), http_open_uri(), and peerblk_raw_open().

◆ http_post

struct http_method http_post
extern

HTTP POST method.

Definition at line 149 of file httpcore.c.

149 {
150 .name = "POST",
151};

Referenced by http_open_uri(), and peerblk_retrieval_open().