iPXE
Macros | Functions | Variables
httpcore.c File Reference

Hyper Text Transfer Protocol (HTTP) core functionality. More...

#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <strings.h>
#include <byteswap.h>
#include <errno.h>
#include <ctype.h>
#include <assert.h>
#include <ipxe/uri.h>
#include <ipxe/refcnt.h>
#include <ipxe/iobuf.h>
#include <ipxe/xfer.h>
#include <ipxe/open.h>
#include <ipxe/process.h>
#include <ipxe/retry.h>
#include <ipxe/timer.h>
#include <ipxe/linebuf.h>
#include <ipxe/xferbuf.h>
#include <ipxe/blockdev.h>
#include <ipxe/acpi.h>
#include <ipxe/version.h>
#include <ipxe/params.h>
#include <ipxe/profile.h>
#include <ipxe/vsprintf.h>
#include <ipxe/errortab.h>
#include <ipxe/efi/efi_path.h>
#include <ipxe/http.h>

Go to the source code of this file.

Macros

#define EACCES_401   __einfo_error ( EINFO_EACCES_401 )
 
#define EINFO_EACCES_401   __einfo_uniqify ( EINFO_EACCES, 0x01, "HTTP 401 Unauthorized" )
 
#define EINVAL_STATUS   __einfo_error ( EINFO_EINVAL_STATUS )
 
#define EINFO_EINVAL_STATUS   __einfo_uniqify ( EINFO_EINVAL, 0x01, "Invalid status line" )
 
#define EINVAL_HEADER   __einfo_error ( EINFO_EINVAL_HEADER )
 
#define EINFO_EINVAL_HEADER   __einfo_uniqify ( EINFO_EINVAL, 0x02, "Invalid header" )
 
#define EINVAL_CONTENT_LENGTH   __einfo_error ( EINFO_EINVAL_CONTENT_LENGTH )
 
#define EINFO_EINVAL_CONTENT_LENGTH   __einfo_uniqify ( EINFO_EINVAL, 0x03, "Invalid content length" )
 
#define EINVAL_CHUNK_LENGTH   __einfo_error ( EINFO_EINVAL_CHUNK_LENGTH )
 
#define EINFO_EINVAL_CHUNK_LENGTH   __einfo_uniqify ( EINFO_EINVAL, 0x04, "Invalid chunk length" )
 
#define EIO_OTHER   __einfo_error ( EINFO_EIO_OTHER )
 
#define EINFO_EIO_OTHER   __einfo_uniqify ( EINFO_EIO, 0x01, "Unrecognised HTTP response code" )
 
#define EIO_CONTENT_LENGTH   __einfo_error ( EINFO_EIO_CONTENT_LENGTH )
 
#define EINFO_EIO_CONTENT_LENGTH   __einfo_uniqify ( EINFO_EIO, 0x02, "Content length mismatch" )
 
#define EIO_4XX   __einfo_error ( EINFO_EIO_4XX )
 
#define EINFO_EIO_4XX   __einfo_uniqify ( EINFO_EIO, 0x04, "HTTP 4xx Client Error" )
 
#define EIO_5XX   __einfo_error ( EINFO_EIO_5XX )
 
#define EINFO_EIO_5XX   __einfo_uniqify ( EINFO_EIO, 0x05, "HTTP 5xx Server Error" )
 
#define ENOENT_404   __einfo_error ( EINFO_ENOENT_404 )
 
#define EINFO_ENOENT_404   __einfo_uniqify ( EINFO_ENOENT, 0x01, "HTTP 404 Not Found" )
 
#define ENOTSUP_CONNECTION   __einfo_error ( EINFO_ENOTSUP_CONNECTION )
 
#define EINFO_ENOTSUP_CONNECTION   __einfo_uniqify ( EINFO_ENOTSUP, 0x01, "Unsupported connection header" )
 
#define ENOTSUP_TRANSFER   __einfo_error ( EINFO_ENOTSUP_TRANSFER )
 
#define EINFO_ENOTSUP_TRANSFER   __einfo_uniqify ( EINFO_ENOTSUP, 0x02, "Unsupported transfer encoding" )
 
#define EPERM_403   __einfo_error ( EINFO_EPERM_403 )
 
#define EINFO_EPERM_403   __einfo_uniqify ( EINFO_EPERM, 0x01, "HTTP 403 Forbidden" )
 
#define EPROTO_UNSOLICITED   __einfo_error ( EINFO_EPROTO_UNSOLICITED )
 
#define EINFO_EPROTO_UNSOLICITED   __einfo_uniqify ( EINFO_EPROTO, 0x01, "Unsolicited data" )
 
#define HTTP_RETRY_SECONDS   5
 Retry delay used when we cannot understand the Retry-After header. More...
 

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 
static int http_rx_linebuf (struct http_transaction *http, struct io_buffer *iobuf, struct line_buffer *linebuf)
 Handle received HTTP line-buffered data. More...
 
char * http_token (char **line, char **value)
 Get HTTP response token. More...
 
static void http_free (struct refcnt *refcnt)
 Free HTTP transaction. More...
 
static void http_close (struct http_transaction *http, int rc)
 Close HTTP transaction. More...
 
static void http_close_error (struct http_transaction *http, int rc)
 Close HTTP transaction with error (even if none specified) More...
 
static void http_reopen (struct http_transaction *http)
 Reopen stale HTTP connection. More...
 
static void http_expired (struct retry_timer *timer, int over __unused)
 Handle retry timer expiry. More...
 
static void http_step (struct http_transaction *http)
 HTTP transmit process. More...
 
static int http_conn_deliver (struct http_transaction *http, struct io_buffer *iobuf, struct xfer_metadata *meta __unused)
 Handle received HTTP data. More...
 
static void http_conn_close (struct http_transaction *http, int rc)
 Handle server connection close. More...
 
static int http_content_deliver (struct http_transaction *http, struct io_buffer *iobuf, struct xfer_metadata *meta)
 Handle received content-decoded data. More...
 
static struct xfer_bufferhttp_content_buffer (struct http_transaction *http)
 Get underlying data transfer buffer. More...
 
__weak int http_block_read (struct http_transaction *http __unused, struct interface *data __unused, uint64_t lba __unused, unsigned int count __unused, userptr_t buffer __unused, size_t len __unused)
 Read from block device (when HTTP block device support is not present) More...
 
__weak int http_block_read_capacity (struct http_transaction *http __unused, struct interface *data __unused)
 Read block device capacity (when HTTP block device support is not present) More...
 
static EFI_DEVICE_PATH_PROTOCOLhttp_efi_describe (struct http_transaction *http)
 Describe as an EFI device path. More...
 
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. More...
 
static int http_redirect (struct http_transaction *http, const char *location)
 Redirect HTTP transaction. More...
 
static int http_transfer_complete (struct http_transaction *http)
 Handle successful transfer completion. More...
 
static int http_format_headers (struct http_transaction *http, char *buf, size_t len)
 Construct HTTP request headers. More...
 
static int http_format_host (struct http_transaction *http, char *buf, size_t len)
 Construct HTTP "Host" header. More...
 
static int http_format_user_agent (struct http_transaction *http __unused, char *buf, size_t len)
 Construct HTTP "User-Agent" header. More...
 
static int http_format_connection (struct http_transaction *http __unused, char *buf, size_t len)
 Construct HTTP "Connection" header. More...
 
static int http_format_range (struct http_transaction *http, char *buf, size_t len)
 Construct HTTP "Range" header. More...
 
static int http_format_content_type (struct http_transaction *http, char *buf, size_t len)
 Construct HTTP "Content-Type" header. More...
 
static int http_format_content_length (struct http_transaction *http, char *buf, size_t len)
 Construct HTTP "Content-Length" header. More...
 
static int http_format_accept_encoding (struct http_transaction *http, char *buf, size_t len)
 Construct HTTP "Accept-Encoding" header. More...
 
static int http_tx_request (struct http_transaction *http)
 Transmit request. More...
 
static int http_parse_status (struct http_transaction *http, char *line)
 Parse HTTP status line. More...
 
static int http_parse_header (struct http_transaction *http, char *line)
 Parse HTTP header. More...
 
static int http_parse_headers (struct http_transaction *http)
 Parse HTTP response headers. More...
 
static int http_parse_location (struct http_transaction *http, char *line)
 Parse HTTP "Location" header. More...
 
static int http_parse_transfer_encoding (struct http_transaction *http, char *line)
 Parse HTTP "Transfer-Encoding" header. More...
 
static int http_parse_connection (struct http_transaction *http, char *line)
 Parse HTTP "Connection" header. More...
 
static int http_parse_content_length (struct http_transaction *http, char *line)
 Parse HTTP "Content-Length" header. More...
 
static int http_parse_content_encoding (struct http_transaction *http, char *line)
 Parse HTTP "Content-Encoding" header. More...
 
static int http_parse_retry_after (struct http_transaction *http, char *line)
 Parse HTTP "Retry-After" header. More...
 
static int http_rx_headers (struct http_transaction *http, struct io_buffer **iobuf)
 Handle received HTTP headers. More...
 
static int http_init_transfer_identity (struct http_transaction *http)
 Initialise transfer encoding. More...
 
static int http_rx_transfer_identity (struct http_transaction *http, struct io_buffer **iobuf)
 Handle received data. More...
 
static void http_close_transfer_identity (struct http_transaction *http, int rc)
 Handle server connection close. More...
 
static int http_init_transfer_chunked (struct http_transaction *http)
 Initialise transfer encoding. More...
 
static int http_rx_chunk_len (struct http_transaction *http, struct io_buffer **iobuf)
 Handle received chunk length. More...
 
static int http_rx_chunk_data (struct http_transaction *http, struct io_buffer **iobuf)
 Handle received chunk data. More...
 
static int http_rx_transfer_chunked (struct http_transaction *http, struct io_buffer **iobuf)
 Handle received chunked data. More...
 
static int http_rx_trailers (struct http_transaction *http, struct io_buffer **iobuf)
 Handle received HTTP trailer. More...
 
static size_t http_params (struct parameters *params, char *buf, size_t len)
 Construct HTTP parameter list. More...
 
static int http_open_get_uri (struct interface *xfer, struct uri *uri)
 Open HTTP transaction for simple GET URI. More...
 
static int http_open_post_uri (struct interface *xfer, struct uri *uri)
 Open HTTP transaction for simple POST URI. More...
 
int http_open_uri (struct interface *xfer, struct uri *uri)
 Open HTTP transaction for simple URI. More...
 
 REQUIRING_SYMBOL (http_open)
 
 REQUIRE_OBJECT (config_http)
 

Variables

static struct profiler http_rx_profiler __profiler = { .name = "http.rx" }
 Receive profiler. More...
 
struct errortab http_errors [] __errortab
 Human-readable error messages. More...
 
static struct http_state http_request
 HTTP request state. More...
 
static struct http_state http_headers
 HTTP response headers state. More...
 
static struct http_state http_trailers
 HTTP response trailers state. More...
 
static struct http_transfer_encoding http_transfer_identity
 Identity transfer encoding. More...
 
struct http_method http_head
 HTTP HEAD method. More...
 
struct http_method http_get
 HTTP GET method. More...
 
struct http_method http_post
 HTTP POST method. More...
 
static struct interface_operation http_xfer_operations []
 HTTP data transfer interface operations. More...
 
static struct interface_descriptor http_xfer_desc
 HTTP data transfer interface descriptor. More...
 
static struct interface_operation http_content_operations []
 HTTP content-decoded interface operations. More...
 
static struct interface_descriptor http_content_desc
 HTTP content-decoded interface descriptor. More...
 
static struct interface_operation http_transfer_operations []
 HTTP transfer-decoded interface operations. More...
 
static struct interface_descriptor http_transfer_desc
 HTTP transfer-decoded interface descriptor. More...
 
static struct interface_operation http_conn_operations []
 HTTP server connection interface operations. More...
 
static struct interface_descriptor http_conn_desc
 HTTP server connection interface descriptor. More...
 
static struct process_descriptor http_process_desc
 HTTP process descriptor. More...
 
struct http_request_header http_request_host __http_request_header
 HTTP "Host" header ". More...
 
struct http_response_header http_response_location __http_response_header
 HTTP "Location" header. More...
 
struct http_transfer_encoding http_transfer_chunked __http_transfer_encoding
 Chunked transfer encoding. More...
 

Detailed Description

Hyper Text Transfer Protocol (HTTP) core functionality.

Definition in file httpcore.c.

Macro Definition Documentation

◆ EACCES_401

#define EACCES_401   __einfo_error ( EINFO_EACCES_401 )

Definition at line 63 of file httpcore.c.

◆ EINFO_EACCES_401

#define EINFO_EACCES_401   __einfo_uniqify ( EINFO_EACCES, 0x01, "HTTP 401 Unauthorized" )

Definition at line 64 of file httpcore.c.

◆ EINVAL_STATUS

#define EINVAL_STATUS   __einfo_error ( EINFO_EINVAL_STATUS )

Definition at line 66 of file httpcore.c.

◆ EINFO_EINVAL_STATUS

#define EINFO_EINVAL_STATUS   __einfo_uniqify ( EINFO_EINVAL, 0x01, "Invalid status line" )

Definition at line 67 of file httpcore.c.

◆ EINVAL_HEADER

#define EINVAL_HEADER   __einfo_error ( EINFO_EINVAL_HEADER )

Definition at line 69 of file httpcore.c.

◆ EINFO_EINVAL_HEADER

#define EINFO_EINVAL_HEADER   __einfo_uniqify ( EINFO_EINVAL, 0x02, "Invalid header" )

Definition at line 70 of file httpcore.c.

◆ EINVAL_CONTENT_LENGTH

#define EINVAL_CONTENT_LENGTH   __einfo_error ( EINFO_EINVAL_CONTENT_LENGTH )

Definition at line 72 of file httpcore.c.

◆ EINFO_EINVAL_CONTENT_LENGTH

#define EINFO_EINVAL_CONTENT_LENGTH   __einfo_uniqify ( EINFO_EINVAL, 0x03, "Invalid content length" )

Definition at line 73 of file httpcore.c.

◆ EINVAL_CHUNK_LENGTH

#define EINVAL_CHUNK_LENGTH   __einfo_error ( EINFO_EINVAL_CHUNK_LENGTH )

Definition at line 75 of file httpcore.c.

◆ EINFO_EINVAL_CHUNK_LENGTH

#define EINFO_EINVAL_CHUNK_LENGTH   __einfo_uniqify ( EINFO_EINVAL, 0x04, "Invalid chunk length" )

Definition at line 76 of file httpcore.c.

◆ EIO_OTHER

#define EIO_OTHER   __einfo_error ( EINFO_EIO_OTHER )

Definition at line 78 of file httpcore.c.

◆ EINFO_EIO_OTHER

#define EINFO_EIO_OTHER   __einfo_uniqify ( EINFO_EIO, 0x01, "Unrecognised HTTP response code" )

Definition at line 79 of file httpcore.c.

◆ EIO_CONTENT_LENGTH

#define EIO_CONTENT_LENGTH   __einfo_error ( EINFO_EIO_CONTENT_LENGTH )

Definition at line 81 of file httpcore.c.

◆ EINFO_EIO_CONTENT_LENGTH

#define EINFO_EIO_CONTENT_LENGTH   __einfo_uniqify ( EINFO_EIO, 0x02, "Content length mismatch" )

Definition at line 82 of file httpcore.c.

◆ EIO_4XX

#define EIO_4XX   __einfo_error ( EINFO_EIO_4XX )

Definition at line 84 of file httpcore.c.

◆ EINFO_EIO_4XX

#define EINFO_EIO_4XX   __einfo_uniqify ( EINFO_EIO, 0x04, "HTTP 4xx Client Error" )

Definition at line 85 of file httpcore.c.

◆ EIO_5XX

#define EIO_5XX   __einfo_error ( EINFO_EIO_5XX )

Definition at line 87 of file httpcore.c.

◆ EINFO_EIO_5XX

#define EINFO_EIO_5XX   __einfo_uniqify ( EINFO_EIO, 0x05, "HTTP 5xx Server Error" )

Definition at line 88 of file httpcore.c.

◆ ENOENT_404

#define ENOENT_404   __einfo_error ( EINFO_ENOENT_404 )

Definition at line 90 of file httpcore.c.

◆ EINFO_ENOENT_404

#define EINFO_ENOENT_404   __einfo_uniqify ( EINFO_ENOENT, 0x01, "HTTP 404 Not Found" )

Definition at line 91 of file httpcore.c.

◆ ENOTSUP_CONNECTION

#define ENOTSUP_CONNECTION   __einfo_error ( EINFO_ENOTSUP_CONNECTION )

Definition at line 93 of file httpcore.c.

◆ EINFO_ENOTSUP_CONNECTION

#define EINFO_ENOTSUP_CONNECTION   __einfo_uniqify ( EINFO_ENOTSUP, 0x01, "Unsupported connection header" )

Definition at line 94 of file httpcore.c.

◆ ENOTSUP_TRANSFER

#define ENOTSUP_TRANSFER   __einfo_error ( EINFO_ENOTSUP_TRANSFER )

Definition at line 96 of file httpcore.c.

◆ EINFO_ENOTSUP_TRANSFER

#define EINFO_ENOTSUP_TRANSFER   __einfo_uniqify ( EINFO_ENOTSUP, 0x02, "Unsupported transfer encoding" )

Definition at line 97 of file httpcore.c.

◆ EPERM_403

#define EPERM_403   __einfo_error ( EINFO_EPERM_403 )

Definition at line 99 of file httpcore.c.

◆ EINFO_EPERM_403

#define EINFO_EPERM_403   __einfo_uniqify ( EINFO_EPERM, 0x01, "HTTP 403 Forbidden" )

Definition at line 100 of file httpcore.c.

◆ EPROTO_UNSOLICITED

#define EPROTO_UNSOLICITED   __einfo_error ( EINFO_EPROTO_UNSOLICITED )

Definition at line 102 of file httpcore.c.

◆ EINFO_EPROTO_UNSOLICITED

#define EINFO_EPROTO_UNSOLICITED   __einfo_uniqify ( EINFO_EPROTO, 0x01, "Unsolicited data" )

Definition at line 103 of file httpcore.c.

◆ HTTP_RETRY_SECONDS

#define HTTP_RETRY_SECONDS   5

Retry delay used when we cannot understand the Retry-After header.

Definition at line 107 of file httpcore.c.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ http_rx_linebuf()

static int http_rx_linebuf ( struct http_transaction http,
struct io_buffer iobuf,
struct line_buffer linebuf 
)
static

Handle received HTTP line-buffered data.

Parameters
httpHTTP transaction
iobufI/O buffer
linebufLine buffer
Return values
rcReturn status code

Definition at line 163 of file httpcore.c.

165  {
166  int consumed;
167  int rc;
168 
169  /* Buffer received line */
170  consumed = line_buffer ( linebuf, iobuf->data, iob_len ( iobuf ) );
171  if ( consumed < 0 ) {
172  rc = consumed;
173  DBGC ( http, "HTTP %p could not buffer line: %s\n",
174  http, strerror ( rc ) );
175  return rc;
176  }
177 
178  /* Consume line */
179  iob_pull ( iobuf, consumed );
180 
181  return 0;
182 }
#define iob_pull(iobuf, len)
Definition: iobuf.h:102
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define DBGC(...)
Definition: compiler.h:505
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
static size_t iob_len(struct io_buffer *iobuf)
Calculate length of data in an I/O buffer.
Definition: iobuf.h:155
void * data
Start of data.
Definition: iobuf.h:48
int line_buffer(struct line_buffer *linebuf, const char *data, size_t len)
Buffer up received data by lines.
Definition: linebuf.c:91

References io_buffer::data, DBGC, iob_len(), iob_pull, line_buffer(), rc, and strerror().

Referenced by http_rx_chunk_len(), http_rx_headers(), and http_rx_trailers().

◆ http_token()

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

Get HTTP response token.

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

Definition at line 191 of file httpcore.c.

191  {
192  char *token;
193  char quote = '\0';
194  char c;
195 
196  /* Avoid returning uninitialised data */
197  if ( value )
198  *value = NULL;
199 
200  /* Skip any initial whitespace or commas */
201  while ( ( isspace ( **line ) ) || ( **line == ',' ) )
202  (*line)++;
203 
204  /* Check for end of line and record token position */
205  if ( ! **line )
206  return NULL;
207  token = *line;
208 
209  /* Scan for end of token */
210  while ( ( c = **line ) ) {
211 
212  /* Terminate if we hit an unquoted whitespace or comma */
213  if ( ( isspace ( c ) || ( c == ',' ) ) && ! quote )
214  break;
215 
216  /* Terminate if we hit a closing quote */
217  if ( c == quote )
218  break;
219 
220  /* Check for value separator */
221  if ( value && ( ! *value ) && ( c == '=' ) ) {
222 
223  /* Terminate key portion of token */
224  *((*line)++) = '\0';
225 
226  /* Check for quote character */
227  c = **line;
228  if ( ( c == '"' ) || ( c == '\'' ) ) {
229  quote = c;
230  (*line)++;
231  }
232 
233  /* Record value portion of token */
234  *value = *line;
235 
236  } else {
237 
238  /* Move to next character */
239  (*line)++;
240  }
241  }
242 
243  /* Terminate token, if applicable */
244  if ( c )
245  *((*line)++) = '\0';
246 
247  return token;
248 }
uint32_t c
Definition: md4.c:30
pseudo_bit_t value[0x00020]
Definition: arbel.h:13
int isspace(int character)
Check to see if character is a space.
Definition: ctype.c:41
u8 token
Definition: CIB_PRM.h:42
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362

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

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

◆ http_free()

static void http_free ( struct refcnt refcnt)
static

Free HTTP transaction.

Parameters
refcntReference count

Definition at line 262 of file httpcore.c.

262  {
263  struct http_transaction *http =
265 
267  empty_line_buffer ( &http->linebuf );
268  uri_put ( http->uri );
269  free ( http );
270 }
static void uri_put(struct uri *uri)
Decrement URI reference count.
Definition: uri.h:205
struct line_buffer linebuf
Temporary line buffer.
Definition: http.h:438
struct uri * uri
Request URI.
Definition: http.h:432
A reference counter.
Definition: refcnt.h:26
struct http_response response
Response.
Definition: http.h:436
An HTTP transaction.
Definition: http.h:415
#define container_of(ptr, type, field)
Get containing structure.
Definition: stddef.h:35
void empty_line_buffer(struct line_buffer *linebuf)
Discard line buffer contents.
Definition: linebuf.c:65
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:54
struct line_buffer headers
Raw response header lines.
Definition: http.h:327

References container_of, empty_line_buffer(), free, http_response::headers, http_transaction::linebuf, http_transaction::response, http_transaction::uri, and uri_put().

Referenced by http_open().

◆ http_close()

static void http_close ( struct http_transaction http,
int  rc 
)
static

Close HTTP transaction.

Parameters
httpHTTP transaction
rcReason for close

Definition at line 278 of file httpcore.c.

278  {
279 
280  /* Stop process */
281  process_del ( &http->process );
282 
283  /* Stop timer */
284  stop_timer ( &http->timer );
285 
286  /* Close all interfaces */
287  intfs_shutdown ( rc, &http->conn, &http->transfer, &http->content,
288  &http->xfer, NULL );
289 }
struct interface xfer
Data transfer interface.
Definition: http.h:419
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
struct interface conn
Server connection.
Definition: http.h:425
void intfs_shutdown(int rc,...)
Shut down multiple object interfaces.
Definition: interface.c:325
void process_del(struct process *process)
Remove process from process list.
Definition: process.c:79
struct interface content
Content-decoded interface.
Definition: http.h:421
struct process process
Transmit process.
Definition: http.h:427
struct interface transfer
Transfer-decoded interface.
Definition: http.h:423
struct retry_timer timer
Reconnection timer.
Definition: http.h:429
void stop_timer(struct retry_timer *timer)
Stop timer.
Definition: retry.c:117
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362

References http_transaction::conn, http_transaction::content, intfs_shutdown(), NULL, http_transaction::process, process_del(), rc, stop_timer(), http_transaction::timer, http_transaction::transfer, and http_transaction::xfer.

Referenced by http_close_error(), http_close_transfer_identity(), http_conn_deliver(), http_open(), http_reopen(), http_step(), and http_transfer_complete().

◆ http_close_error()

static void http_close_error ( struct http_transaction http,
int  rc 
)
static

Close HTTP transaction with error (even if none specified)

Parameters
httpHTTP transaction
rcReason for close

Definition at line 297 of file httpcore.c.

297  {
298 
299  /* Treat any close as an error */
300  http_close ( http, ( rc ? rc : -EPIPE ) );
301 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
static void http_close(struct http_transaction *http, int rc)
Close HTTP transaction.
Definition: httpcore.c:278
#define EPIPE
Broken pipe.
Definition: errno.h:619

References EPIPE, http_close(), and rc.

◆ http_reopen()

static void http_reopen ( struct http_transaction http)
static

Reopen stale HTTP connection.

Parameters
httpHTTP transaction

Definition at line 308 of file httpcore.c.

308  {
309  int rc;
310 
311  /* Close existing connection */
312  intf_restart ( &http->conn, -ECANCELED );
313 
314  /* Reopen connection */
315  if ( ( rc = http_connect ( &http->conn, http->uri ) ) != 0 ) {
316  DBGC ( http, "HTTP %p could not reconnect: %s\n",
317  http, strerror ( rc ) );
318  goto err_connect;
319  }
320 
321  /* Reset state */
322  http->state = &http_request;
323 
324  /* Reschedule transmission process */
325  process_add ( &http->process );
326 
327  return;
328 
329  err_connect:
330  http_close ( http, rc );
331 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
void intf_restart(struct interface *intf, int rc)
Shut down and restart an object interface.
Definition: interface.c:342
struct interface conn
Server connection.
Definition: http.h:425
static void http_close(struct http_transaction *http, int rc)
Close HTTP transaction.
Definition: httpcore.c:278
#define DBGC(...)
Definition: compiler.h:505
struct uri * uri
Request URI.
Definition: http.h:432
struct http_state * state
Transaction state.
Definition: http.h:441
#define ECANCELED
Operation canceled.
Definition: errno.h:343
int http_connect(struct interface *xfer, struct uri *uri)
Connect to an HTTP server.
Definition: httpconn.c:236
void process_add(struct process *process)
Add process to process list.
Definition: process.c:59
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
struct process process
Transmit process.
Definition: http.h:427
static struct http_state http_request
HTTP request state.
Definition: httpcore.c:121

References http_transaction::conn, DBGC, ECANCELED, http_close(), http_connect(), http_request, intf_restart(), http_transaction::process, process_add(), rc, http_transaction::state, strerror(), and http_transaction::uri.

Referenced by http_expired(), and http_transfer_complete().

◆ http_expired()

static void http_expired ( struct retry_timer timer,
int over  __unused 
)
static

Handle retry timer expiry.

Parameters
timerRetry timer
overFailure indicator

Definition at line 339 of file httpcore.c.

339  {
340  struct http_transaction *http =
342 
343  /* Reopen connection */
344  http_reopen ( http );
345 }
A timer.
Definition: timer.h:28
An HTTP transaction.
Definition: http.h:415
#define container_of(ptr, type, field)
Get containing structure.
Definition: stddef.h:35
static void http_reopen(struct http_transaction *http)
Reopen stale HTTP connection.
Definition: httpcore.c:308

References container_of, and http_reopen().

Referenced by http_open().

◆ http_step()

static void http_step ( struct http_transaction http)
static

HTTP transmit process.

Parameters
httpHTTP transaction

Definition at line 352 of file httpcore.c.

352  {
353  int rc;
354 
355  /* Do nothing if we have nothing to transmit */
356  if ( ! http->state->tx )
357  return;
358 
359  /* Do nothing until connection is ready */
360  if ( ! xfer_window ( &http->conn ) )
361  return;
362 
363  /* Notify data transfer interface that window may have changed */
364  xfer_window_changed ( &http->xfer );
365 
366  /* Do nothing until data transfer interface is ready */
367  if ( ! xfer_window ( &http->xfer ) )
368  return;
369 
370  /* Transmit data */
371  if ( ( rc = http->state->tx ( http ) ) != 0 )
372  goto err;
373 
374  return;
375 
376  err:
377  http_close ( http, rc );
378 }
struct interface xfer
Data transfer interface.
Definition: http.h:419
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
void xfer_window_changed(struct interface *intf)
Report change of flow control window.
Definition: xfer.c:145
struct interface conn
Server connection.
Definition: http.h:425
static void http_close(struct http_transaction *http, int rc)
Close HTTP transaction.
Definition: httpcore.c:278
int(* tx)(struct http_transaction *http)
Transmit data.
Definition: http.h:397
struct http_state * state
Transaction state.
Definition: http.h:441
size_t xfer_window(struct interface *intf)
Check flow control window.
Definition: xfer.c:115

References http_transaction::conn, http_close(), rc, http_transaction::state, http_state::tx, http_transaction::xfer, xfer_window(), and xfer_window_changed().

◆ http_conn_deliver()

static int http_conn_deliver ( struct http_transaction http,
struct io_buffer iobuf,
struct xfer_metadata *meta  __unused 
)
static

Handle received HTTP data.

Parameters
httpHTTP transaction
iobufI/O buffer
metaTransfer metadata
Return values
rcReturn status code

This function takes ownership of the I/O buffer.

Definition at line 390 of file httpcore.c.

392  {
393  int rc;
394 
395  /* Handle received data */
396  profile_start ( &http_rx_profiler );
397  while ( iobuf && iob_len ( iobuf ) ) {
398 
399  /* Sanity check */
400  if ( ( ! http->state ) || ( ! http->state->rx ) ) {
401  DBGC ( http, "HTTP %p unexpected data\n", http );
403  goto err;
404  }
405 
406  /* Receive (some) data */
407  if ( ( rc = http->state->rx ( http, &iobuf ) ) != 0 )
408  goto err;
409  }
410 
411  /* Free I/O buffer, if applicable */
412  free_iob ( iobuf );
413 
414  profile_stop ( &http_rx_profiler );
415  return 0;
416 
417  err:
418  free_iob ( iobuf );
419  http_close ( http, rc );
420  return rc;
421 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
void free_iob(struct io_buffer *iobuf)
Free I/O buffer.
Definition: iobuf.c:146
static void http_close(struct http_transaction *http, int rc)
Close HTTP transaction.
Definition: httpcore.c:278
#define DBGC(...)
Definition: compiler.h:505
struct http_state * state
Transaction state.
Definition: http.h:441
static void profile_stop(struct profiler *profiler)
Stop profiling.
Definition: profile.h:171
int(* rx)(struct http_transaction *http, struct io_buffer **iobuf)
Receive data.
Definition: http.h:404
static void profile_start(struct profiler *profiler)
Start profiling.
Definition: profile.h:158
static size_t iob_len(struct io_buffer *iobuf)
Calculate length of data in an I/O buffer.
Definition: iobuf.h:155
#define EPROTO_UNSOLICITED
Definition: httpcore.c:102

References DBGC, EPROTO_UNSOLICITED, free_iob(), http_close(), iob_len(), profile_start(), profile_stop(), rc, http_state::rx, and http_transaction::state.

◆ http_conn_close()

static void http_conn_close ( struct http_transaction http,
int  rc 
)
static

Handle server connection close.

Parameters
httpHTTP transaction
rcReason for close

Definition at line 429 of file httpcore.c.

429  {
430 
431  /* Sanity checks */
432  assert ( http->state != NULL );
433  assert ( http->state->close != NULL );
434 
435  /* Restart server connection interface */
436  intf_restart ( &http->conn, rc );
437 
438  /* Hand off to state-specific method */
439  http->state->close ( http, rc );
440 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
void intf_restart(struct interface *intf, int rc)
Shut down and restart an object interface.
Definition: interface.c:342
void(* close)(struct http_transaction *http, int rc)
Server connection closed.
Definition: http.h:411
struct interface conn
Server connection.
Definition: http.h:425
struct http_state * state
Transaction state.
Definition: http.h:441
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362

References assert(), http_state::close, http_transaction::conn, intf_restart(), NULL, rc, and http_transaction::state.

◆ http_content_deliver()

static int http_content_deliver ( struct http_transaction http,
struct io_buffer iobuf,
struct xfer_metadata meta 
)
static

Handle received content-decoded data.

Parameters
httpHTTP transaction
iobufI/O buffer
metaData transfer metadata

Definition at line 449 of file httpcore.c.

451  {
452  int rc;
453 
454  /* Ignore content if this is anything other than a successful
455  * transfer.
456  */
457  if ( http->response.rc != 0 ) {
458  free_iob ( iobuf );
459  return 0;
460  }
461 
462  /* Deliver to data transfer interface */
463  profile_start ( &http_xfer_profiler );
464  if ( ( rc = xfer_deliver ( &http->xfer, iob_disown ( iobuf ),
465  meta ) ) != 0 )
466  return rc;
467  profile_stop ( &http_xfer_profiler );
468 
469  return 0;
470 }
struct interface xfer
Data transfer interface.
Definition: http.h:419
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
void free_iob(struct io_buffer *iobuf)
Free I/O buffer.
Definition: iobuf.c:146
static void profile_stop(struct profiler *profiler)
Stop profiling.
Definition: profile.h:171
#define iob_disown(iobuf)
Disown an I/O buffer.
Definition: iobuf.h:212
struct http_response response
Response.
Definition: http.h:436
static void profile_start(struct profiler *profiler)
Start profiling.
Definition: profile.h:158
int meta(WINDOW *, bool)
int rc
Return status code.
Definition: http.h:338
int xfer_deliver(struct interface *intf, struct io_buffer *iobuf, struct xfer_metadata *meta)
Deliver datagram.
Definition: xfer.c:193

References free_iob(), iob_disown, meta(), profile_start(), profile_stop(), http_response::rc, rc, http_transaction::response, http_transaction::xfer, and xfer_deliver().

◆ http_content_buffer()

static struct xfer_buffer* http_content_buffer ( struct http_transaction http)
static

Get underlying data transfer buffer.

Parameters
httpHTTP transaction
Return values
xferbufData transfer buffer, or NULL on error

Definition at line 479 of file httpcore.c.

479  {
480 
481  /* Deny access to the data transfer buffer if this is anything
482  * other than a successful transfer.
483  */
484  if ( http->response.rc != 0 )
485  return NULL;
486 
487  /* Hand off to data transfer interface */
488  return xfer_buffer ( &http->xfer );
489 }
struct interface xfer
Data transfer interface.
Definition: http.h:419
struct http_response response
Response.
Definition: http.h:436
int rc
Return status code.
Definition: http.h:338
struct xfer_buffer * xfer_buffer(struct interface *intf)
Get underlying data transfer buffer.
Definition: xferbuf.c:301
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362

References NULL, http_response::rc, http_transaction::response, http_transaction::xfer, and xfer_buffer().

◆ http_block_read()

__weak int http_block_read ( struct http_transaction *http  __unused,
struct interface *data  __unused,
uint64_t lba  __unused,
unsigned int count  __unused,
userptr_t buffer  __unused,
size_t len  __unused 
)

Read from block device (when HTTP block device support is not present)

Parameters
httpHTTP transaction
dataData interface
lbaStarting logical block address
countNumber of logical blocks
bufferData buffer
lenLength of data buffer
Return values
rcReturn status code

Definition at line 502 of file httpcore.c.

505  {
506 
507  return -ENOTSUP;
508 }
#define ENOTSUP
Operation not supported.
Definition: errno.h:589

References ENOTSUP.

◆ http_block_read_capacity()

__weak int http_block_read_capacity ( struct http_transaction *http  __unused,
struct interface *data  __unused 
)

Read block device capacity (when HTTP block device support is not present)

Parameters
controlControl interface
dataData interface
Return values
rcReturn status code

Definition at line 517 of file httpcore.c.

518  {
519 
520  return -ENOTSUP;
521 }
#define ENOTSUP
Operation not supported.
Definition: errno.h:589

References ENOTSUP.

◆ http_efi_describe()

static EFI_DEVICE_PATH_PROTOCOL* http_efi_describe ( struct http_transaction http)
static

Describe as an EFI device path.

Parameters
httpHTTP transaction
Return values
pathEFI device path, or NULL on error

Definition at line 530 of file httpcore.c.

530  {
531 
532  return efi_uri_path ( http->uri );
533 }
struct uri * uri
Request URI.
Definition: http.h:432
EFI_DEVICE_PATH_PROTOCOL * efi_uri_path(struct uri *uri)
Construct EFI device path for URI.
Definition: efi_path.c:195

References efi_uri_path(), and http_transaction::uri.

◆ 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 
)

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

603  {
604  struct http_transaction *http;
605  struct uri request_uri;
606  struct uri request_host;
607  size_t request_uri_len;
608  size_t request_host_len;
609  size_t content_len;
610  char *request_uri_string;
611  char *request_host_string;
612  void *content_data;
613  int rc;
614 
615  /* Calculate request URI length */
616  memset ( &request_uri, 0, sizeof ( request_uri ) );
617  request_uri.epath = ( uri->epath ? uri->epath : "/" );
618  request_uri.equery = uri->equery;
619  request_uri_len =
620  ( format_uri ( &request_uri, NULL, 0 ) + 1 /* NUL */);
621 
622  /* Calculate host name length */
623  memset ( &request_host, 0, sizeof ( request_host ) );
624  request_host.host = uri->host;
625  request_host.port = uri->port;
626  request_host_len =
627  ( format_uri ( &request_host, NULL, 0 ) + 1 /* NUL */ );
628 
629  /* Calculate request content length */
630  content_len = ( content ? content->len : 0 );
631 
632  /* Allocate and initialise structure */
633  http = zalloc ( sizeof ( *http ) + request_uri_len + request_host_len +
634  content_len );
635  if ( ! http ) {
636  rc = -ENOMEM;
637  goto err_alloc;
638  }
639  request_uri_string = ( ( ( void * ) http ) + sizeof ( *http ) );
640  request_host_string = ( request_uri_string + request_uri_len );
641  content_data = ( request_host_string + request_host_len );
642  format_uri ( &request_uri, request_uri_string, request_uri_len );
643  format_uri ( &request_host, request_host_string, request_host_len );
644  ref_init ( &http->refcnt, http_free );
645  intf_init ( &http->xfer, &http_xfer_desc, &http->refcnt );
646  intf_init ( &http->content, &http_content_desc, &http->refcnt );
647  intf_init ( &http->transfer, &http_transfer_desc, &http->refcnt );
648  intf_init ( &http->conn, &http_conn_desc, &http->refcnt );
649  intf_plug_plug ( &http->transfer, &http->content );
650  process_init ( &http->process, &http_process_desc, &http->refcnt );
651  timer_init ( &http->timer, http_expired, &http->refcnt );
652  http->uri = uri_get ( uri );
653  http->request.method = method;
654  http->request.uri = request_uri_string;
655  http->request.host = request_host_string;
656  if ( range ) {
657  memcpy ( &http->request.range, range,
658  sizeof ( http->request.range ) );
659  }
660  if ( content ) {
661  http->request.content.type = content->type;
662  http->request.content.data = content_data;
663  http->request.content.len = content_len;
664  memcpy ( content_data, content->data, content_len );
665  }
666  http->state = &http_request;
667  DBGC2 ( http, "HTTP %p %s://%s%s\n", http, http->uri->scheme,
668  http->request.host, http->request.uri );
669 
670  /* Open connection */
671  if ( ( rc = http_connect ( &http->conn, uri ) ) != 0 ) {
672  DBGC ( http, "HTTP %p could not connect: %s\n",
673  http, strerror ( rc ) );
674  goto err_connect;
675  }
676 
677  /* Attach to parent interface, mortalise self, and return */
678  intf_plug_plug ( &http->xfer, xfer );
679  ref_put ( &http->refcnt );
680  return 0;
681 
682  err_connect:
683  http_close ( http, rc );
684  ref_put ( &http->refcnt );
685  err_alloc:
686  return rc;
687 }
struct interface xfer
Data transfer interface.
Definition: http.h:419
const char * equery
Query (with original URI encoding)
Definition: uri.h:84
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
static __always_inline void struct pci_range * range
Definition: efi_pci_api.h:43
const char * host
Server host name.
Definition: http.h:216
static struct uri * uri_get(struct uri *uri)
Increment URI reference count.
Definition: uri.h:194
#define ref_init(refcnt, free)
Initialise a reference counter.
Definition: refcnt.h:64
struct interface conn
Server connection.
Definition: http.h:425
static void http_expired(struct retry_timer *timer, int over __unused)
Handle retry timer expiry.
Definition: httpcore.c:339
static void http_close(struct http_transaction *http, int rc)
Close HTTP transaction.
Definition: httpcore.c:278
static struct interface_descriptor http_transfer_desc
HTTP transfer-decoded interface descriptor.
Definition: httpcore.c:570
static void process_init(struct process *process, struct process_descriptor *desc, struct refcnt *refcnt)
Initialise process and add to process list.
Definition: process.h:161
static struct interface_descriptor http_content_desc
HTTP content-decoded interface descriptor.
Definition: httpcore.c:560
#define DBGC(...)
Definition: compiler.h:505
struct uri * uri
Request URI.
Definition: http.h:432
void intf_plug_plug(struct interface *a, struct interface *b)
Plug two object interfaces together.
Definition: interface.c:107
struct http_state * state
Transaction state.
Definition: http.h:441
uint8_t method
Definition: ib_mad.h:14
struct http_request_range range
Range descriptor.
Definition: http.h:218
struct http_request request
Request.
Definition: http.h:434
const char * port
Port number.
Definition: uri.h:78
int http_connect(struct interface *xfer, struct uri *uri)
Connect to an HTTP server.
Definition: httpconn.c:236
#define ENOMEM
Not enough space.
Definition: errno.h:534
const char * scheme
Scheme.
Definition: uri.h:68
void * memcpy(void *dest, const void *src, size_t len) __nonnull
An HTTP transaction.
Definition: http.h:415
const char * uri
Request URI string.
Definition: http.h:214
size_t format_uri(const struct uri *uri, char *buf, size_t len)
Format URI.
Definition: uri.c:471
struct http_request_content content
Content descriptor.
Definition: http.h:220
static struct interface_descriptor http_conn_desc
HTTP server connection interface descriptor.
Definition: httpcore.c:583
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
void * zalloc(size_t size)
Allocate cleared memory.
Definition: malloc.c:624
struct interface content
Content-decoded interface.
Definition: http.h:421
struct process process
Transmit process.
Definition: http.h:427
static struct interface_descriptor http_xfer_desc
HTTP data transfer interface descriptor.
Definition: httpcore.c:547
struct interface transfer
Transfer-decoded interface.
Definition: http.h:423
const char * type
Content type (if any)
Definition: http.h:145
const char * host
Host name.
Definition: uri.h:76
struct retry_timer timer
Reconnection timer.
Definition: http.h:429
const void * data
Content data (if any)
Definition: http.h:147
size_t len
Content length.
Definition: http.h:149
static struct process_descriptor http_process_desc
HTTP process descriptor.
Definition: httpcore.c:588
#define DBGC2(...)
Definition: compiler.h:522
struct refcnt refcnt
Reference count.
Definition: http.h:417
struct http_method * method
Method.
Definition: http.h:212
const char * epath
Path (with original URI encoding)
Definition: uri.h:82
A Uniform Resource Identifier.
Definition: uri.h:64
static void http_free(struct refcnt *refcnt)
Free HTTP transaction.
Definition: httpcore.c:262
static struct http_state http_request
HTTP request state.
Definition: httpcore.c:121
static void intf_init(struct interface *intf, struct interface_descriptor *desc, struct refcnt *refcnt)
Initialise an object interface.
Definition: interface.h:190
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362
#define ref_put(refcnt)
Drop reference to object.
Definition: refcnt.h:106
void * memset(void *dest, int character, size_t len) __nonnull

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

Referenced by http_block_read(), http_block_read_capacity(), http_open_get_uri(), http_open_post_uri(), peerblk_raw_open(), and peerblk_retrieval_open().

◆ http_redirect()

static int http_redirect ( struct http_transaction http,
const char *  location 
)
static

Redirect HTTP transaction.

Parameters
httpHTTP transaction
locationNew location
Return values
rcReturn status code

Definition at line 696 of file httpcore.c.

697  {
698  struct uri *location_uri;
699  struct uri *resolved_uri;
700  int rc;
701 
702  DBGC2 ( http, "HTTP %p redirecting to \"%s\"\n", http, location );
703 
704  /* Parse location URI */
705  location_uri = parse_uri ( location );
706  if ( ! location_uri ) {
707  rc = -ENOMEM;
708  goto err_parse_uri;
709  }
710 
711  /* Resolve as relative to original URI */
712  resolved_uri = resolve_uri ( http->uri, location_uri );
713  if ( ! resolved_uri ) {
714  rc = -ENOMEM;
715  goto err_resolve_uri;
716  }
717 
718  /* Redirect to new URI */
719  if ( ( rc = xfer_redirect ( &http->xfer, LOCATION_URI,
720  resolved_uri ) ) != 0 ) {
721  DBGC ( http, "HTTP %p could not redirect: %s\n",
722  http, strerror ( rc ) );
723  goto err_redirect;
724  }
725 
726  err_redirect:
727  uri_put ( resolved_uri );
728  err_resolve_uri:
729  uri_put ( location_uri );
730  err_parse_uri:
731  return rc;
732 }
struct interface xfer
Data transfer interface.
Definition: http.h:419
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
static void uri_put(struct uri *uri)
Decrement URI reference count.
Definition: uri.h:205
#define DBGC(...)
Definition: compiler.h:505
struct uri * uri
Request URI.
Definition: http.h:432
#define ENOMEM
Not enough space.
Definition: errno.h:534
Location is a URI.
Definition: open.h:27
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
#define DBGC2(...)
Definition: compiler.h:522
A Uniform Resource Identifier.
Definition: uri.h:64
struct uri * resolve_uri(const struct uri *base_uri, struct uri *relative_uri)
Resolve base+relative URI.
Definition: uri.c:694
struct uri * parse_uri(const char *uri_string)
Parse URI.
Definition: uri.c:296
int xfer_redirect(struct interface *intf, int type,...)
Send redirection event.
Definition: xfer.c:237

References DBGC, DBGC2, ENOMEM, LOCATION_URI, parse_uri(), rc, resolve_uri(), strerror(), http_transaction::uri, uri_put(), http_transaction::xfer, and xfer_redirect().

Referenced by http_transfer_complete().

◆ http_transfer_complete()

static int http_transfer_complete ( struct http_transaction http)
static

Handle successful transfer completion.

Parameters
httpHTTP transaction
Return values
rcReturn status code

Definition at line 740 of file httpcore.c.

740  {
741  struct http_authentication *auth;
742  const char *location;
743  int rc;
744 
745  /* Keep connection alive if applicable */
746  if ( http->response.flags & HTTP_RESPONSE_KEEPALIVE )
747  pool_recycle ( &http->conn );
748 
749  /* Restart server connection interface */
750  intf_restart ( &http->conn, 0 );
751 
752  /* No more data is expected */
753  http->state = NULL;
754 
755  /* If transaction is successful, then close the
756  * transfer-decoded interface. The content encoding may
757  * choose whether or not to immediately terminate the
758  * transaction.
759  */
760  if ( http->response.rc == 0 ) {
761  intf_shutdown ( &http->transfer, 0 );
762  return 0;
763  }
764 
765  /* Perform redirection, if applicable */
766  if ( ( location = http->response.location ) ) {
767  if ( ( rc = http_redirect ( http, location ) ) != 0 )
768  return rc;
769  http_close ( http, 0 );
770  return 0;
771  }
772 
773  /* Fail unless a retry is permitted */
774  if ( ! ( http->response.flags & HTTP_RESPONSE_RETRY ) )
775  return http->response.rc;
776 
777  /* Perform authentication, if applicable */
778  if ( ( auth = http->response.auth.auth ) ) {
779  http->request.auth.auth = auth;
780  DBGC2 ( http, "HTTP %p performing %s authentication\n",
781  http, auth->name );
782  if ( ( rc = auth->authenticate ( http ) ) != 0 ) {
783  DBGC ( http, "HTTP %p could not authenticate: %s\n",
784  http, strerror ( rc ) );
785  return rc;
786  }
787  }
788 
789  /* Restart content decoding interfaces */
790  intfs_restart ( http->response.rc, &http->content, &http->transfer,
791  NULL );
792  intf_plug_plug ( &http->transfer, &http->content );
793  http->len = 0;
794  assert ( http->remaining == 0 );
795 
796  /* Retry immediately if applicable. We cannot rely on an
797  * immediate timer expiry, since certain Microsoft-designed
798  * HTTP extensions such as NTLM break the fundamentally
799  * stateless nature of HTTP and rely on the same connection
800  * being reused for authentication. See RFC7230 section 2.3
801  * for further details.
802  */
803  if ( ! http->response.retry_after ) {
804  http_reopen ( http );
805  return 0;
806  }
807 
808  /* Start timer to initiate retry */
809  DBGC2 ( http, "HTTP %p retrying after %d seconds\n",
810  http, http->response.retry_after );
811  start_timer_fixed ( &http->timer,
812  ( http->response.retry_after * TICKS_PER_SEC ) );
813  return 0;
814 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
void intf_restart(struct interface *intf, int rc)
Shut down and restart an object interface.
Definition: interface.c:342
#define TICKS_PER_SEC
Number of ticks per second.
Definition: timer.h:15
void intf_shutdown(struct interface *intf, int rc)
Shut down an object interface.
Definition: interface.c:278
unsigned int flags
Flags.
Definition: http.h:350
struct interface conn
Server connection.
Definition: http.h:425
static void http_close(struct http_transaction *http, int rc)
Close HTTP transaction.
Definition: httpcore.c:278
static int http_redirect(struct http_transaction *http, const char *location)
Redirect HTTP transaction.
Definition: httpcore.c:696
#define DBGC(...)
Definition: compiler.h:505
void intf_plug_plug(struct interface *a, struct interface *b)
Plug two object interfaces together.
Definition: interface.c:107
const char * location
Redirection location.
Definition: http.h:340
struct http_state * state
Transaction state.
Definition: http.h:441
An HTTP authentication scheme.
Definition: http.h:516
struct http_response_auth auth
Authorization descriptor.
Definition: http.h:346
void intfs_restart(int rc,...)
Shut down and restart multiple object interfaces.
Definition: interface.c:385
struct http_request request
Request.
Definition: http.h:434
int(* authenticate)(struct http_transaction *http)
Perform authentication.
Definition: http.h:531
Keep connection alive after close.
Definition: http.h:356
struct http_response response
Response.
Definition: http.h:436
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
size_t len
Accumulated transfer-decoded length.
Definition: http.h:443
struct http_request_auth auth
Authentication descriptor.
Definition: http.h:222
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
struct http_authentication * auth
Authentication scheme (if any)
Definition: http.h:189
struct interface content
Content-decoded interface.
Definition: http.h:421
int rc
Return status code.
Definition: http.h:338
struct interface transfer
Transfer-decoded interface.
Definition: http.h:423
struct retry_timer timer
Reconnection timer.
Definition: http.h:429
void start_timer_fixed(struct retry_timer *timer, unsigned long timeout)
Start timer with a specified timeout.
Definition: retry.c:64
#define DBGC2(...)
Definition: compiler.h:522
struct http_authentication * auth
Authentication scheme (if any)
Definition: http.h:297
static void http_reopen(struct http_transaction *http)
Reopen stale HTTP connection.
Definition: httpcore.c:308
const char * name
Name (e.g.
Definition: http.h:518
size_t remaining
Chunk length remaining.
Definition: http.h:445
Transaction may be retried on failure.
Definition: http.h:360
void pool_recycle(struct interface *intf)
Recycle this connection after closing.
Definition: pool.c:41
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362
unsigned int retry_after
Retry delay (in seconds)
Definition: http.h:348

References assert(), http_request_auth::auth, http_request::auth, http_response_auth::auth, http_response::auth, http_authentication::authenticate, http_transaction::conn, http_transaction::content, DBGC, DBGC2, http_response::flags, http_close(), http_redirect(), http_reopen(), HTTP_RESPONSE_KEEPALIVE, HTTP_RESPONSE_RETRY, intf_plug_plug(), intf_restart(), intf_shutdown(), intfs_restart(), http_transaction::len, http_response::location, http_authentication::name, NULL, pool_recycle(), http_response::rc, rc, http_transaction::remaining, http_transaction::request, http_transaction::response, http_response::retry_after, start_timer_fixed(), http_transaction::state, strerror(), TICKS_PER_SEC, http_transaction::timer, and http_transaction::transfer.

Referenced by http_close_transfer_identity(), http_init_transfer_identity(), http_rx_headers(), http_rx_trailers(), and http_rx_transfer_identity().

◆ http_format_headers()

static int http_format_headers ( struct http_transaction http,
char *  buf,
size_t  len 
)
static

Construct HTTP request headers.

Parameters
httpHTTP transaction
bufBuffer
lenLength of buffer
Return values
lenLength, or negative error

Definition at line 831 of file httpcore.c.

832  {
833  struct http_request_header *header;
834  size_t used;
835  size_t remaining;
836  char *line;
837  int value_len;
838  int rc;
839 
840  /* Construct request line */
841  used = ssnprintf ( buf, len, "%s %s HTTP/1.1",
842  http->request.method->name, http->request.uri );
843  if ( used < len )
844  DBGC2 ( http, "HTTP %p TX %s\n", http, buf );
845  used += ssnprintf ( ( buf + used ), ( len - used ), "\r\n" );
846 
847  /* Construct all headers */
849 
850  /* Determine header value length */
851  value_len = header->format ( http, NULL, 0 );
852  if ( value_len < 0 ) {
853  rc = value_len;
854  return rc;
855  }
856 
857  /* Skip zero-length headers */
858  if ( ! value_len )
859  continue;
860 
861  /* Construct header */
862  line = ( buf + used );
863  used += ssnprintf ( ( buf + used ), ( len - used ), "%s: ",
864  header->name );
865  remaining = ( ( used < len ) ? ( len - used ) : 0 );
866  used += header->format ( http, ( buf + used ), remaining );
867  if ( used < len )
868  DBGC2 ( http, "HTTP %p TX %s\n", http, line );
869  used += ssnprintf ( ( buf + used ), ( len - used ), "\r\n" );
870  }
871 
872  /* Construct terminating newline */
873  used += ssnprintf ( ( buf + used ), ( len - used ), "\r\n" );
874 
875  return used;
876 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
An HTTP request header.
Definition: http.h:226
struct http_request request
Request.
Definition: http.h:434
int ssnprintf(char *buf, ssize_t ssize, const char *fmt,...)
Version of vsnprintf() that accepts a signed buffer size.
Definition: vsprintf.c:420
const char * uri
Request URI string.
Definition: http.h:214
const char * name
Method name (e.g.
Definition: http.h:101
#define for_each_table_entry(pointer, table)
Iterate through all entries within a linker table.
Definition: tables.h:385
uint32_t len
Length.
Definition: ena.h:14
#define DBGC2(...)
Definition: compiler.h:522
#define HTTP_REQUEST_HEADERS
HTTP request header table.
Definition: http.h:241
struct ena_aq_header header
Header.
Definition: ena.h:12
struct http_method * method
Method.
Definition: http.h:212
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362

References DBGC2, for_each_table_entry, header, HTTP_REQUEST_HEADERS, len, http_request::method, http_method::name, NULL, rc, http_transaction::request, ssnprintf(), and http_request::uri.

Referenced by http_tx_request().

◆ http_format_host()

static int http_format_host ( struct http_transaction http,
char *  buf,
size_t  len 
)
static

Construct HTTP "Host" header.

Parameters
httpHTTP transaction
bufBuffer
lenLength of buffer
Return values
lenLength of header value, or negative error

Definition at line 886 of file httpcore.c.

887  {
888 
889  /* Construct host URI */
890  return snprintf ( buf, len, "%s", http->request.host );
891 }
const char * host
Server host name.
Definition: http.h:216
struct http_request request
Request.
Definition: http.h:434
uint32_t len
Length.
Definition: ena.h:14
int snprintf(char *buf, size_t size, const char *fmt,...)
Write a formatted string to a buffer.
Definition: vsprintf.c:382

References http_request::host, len, http_transaction::request, and snprintf().

◆ http_format_user_agent()

static int http_format_user_agent ( struct http_transaction *http  __unused,
char *  buf,
size_t  len 
)
static

Construct HTTP "User-Agent" header.

Parameters
httpHTTP transaction
bufBuffer
lenLength of buffer
Return values
lenLength of header value, or negative error

Definition at line 907 of file httpcore.c.

908  {
909 
910  /* Construct user agent */
911  return snprintf ( buf, len, "iPXE/%s", product_version );
912 }
const char product_version[]
Product version string.
Definition: version.c:70
uint32_t len
Length.
Definition: ena.h:14
int snprintf(char *buf, size_t size, const char *fmt,...)
Write a formatted string to a buffer.
Definition: vsprintf.c:382

References len, product_version, and snprintf().

◆ http_format_connection()

static int http_format_connection ( struct http_transaction *http  __unused,
char *  buf,
size_t  len 
)
static

Construct HTTP "Connection" header.

Parameters
httpHTTP transaction
bufBuffer
lenLength of buffer
Return values
lenLength of header value, or negative error

Definition at line 928 of file httpcore.c.

929  {
930 
931  /* Always request keep-alive */
932  return snprintf ( buf, len, "keep-alive" );
933 }
uint32_t len
Length.
Definition: ena.h:14
int snprintf(char *buf, size_t size, const char *fmt,...)
Write a formatted string to a buffer.
Definition: vsprintf.c:382

References len, and snprintf().

◆ http_format_range()

static int http_format_range ( struct http_transaction http,
char *  buf,
size_t  len 
)
static

Construct HTTP "Range" header.

Parameters
httpHTTP transaction
bufBuffer
lenLength of buffer
Return values
lenLength of header value, or negative error

Definition at line 949 of file httpcore.c.

950  {
951 
952  /* Construct range, if applicable */
953  if ( http->request.range.len ) {
954  return snprintf ( buf, len, "bytes=%zd-%zd",
955  http->request.range.start,
956  ( http->request.range.start +
957  http->request.range.len - 1 ) );
958  } else {
959  return 0;
960  }
961 }
size_t start
Range start.
Definition: http.h:137
struct http_request_range range
Range descriptor.
Definition: http.h:218
struct http_request request
Request.
Definition: http.h:434
size_t len
Range length, or zero for no range request.
Definition: http.h:139
uint32_t len
Length.
Definition: ena.h:14
int snprintf(char *buf, size_t size, const char *fmt,...)
Write a formatted string to a buffer.
Definition: vsprintf.c:382

References len, http_request_range::len, http_request::range, http_transaction::request, snprintf(), and http_request_range::start.

◆ http_format_content_type()

static int http_format_content_type ( struct http_transaction http,
char *  buf,
size_t  len 
)
static

Construct HTTP "Content-Type" header.

Parameters
httpHTTP transaction
bufBuffer
lenLength of buffer
Return values
lenLength of header value, or negative error

Definition at line 977 of file httpcore.c.

978  {
979 
980  /* Construct content type, if applicable */
981  if ( http->request.content.type ) {
982  return snprintf ( buf, len, "%s", http->request.content.type );
983  } else {
984  return 0;
985  }
986 }
struct http_request request
Request.
Definition: http.h:434
struct http_request_content content
Content descriptor.
Definition: http.h:220
const char * type
Content type (if any)
Definition: http.h:145
uint32_t len
Length.
Definition: ena.h:14
int snprintf(char *buf, size_t size, const char *fmt,...)
Write a formatted string to a buffer.
Definition: vsprintf.c:382

References http_request::content, len, http_transaction::request, snprintf(), and http_request_content::type.

◆ http_format_content_length()

static int http_format_content_length ( struct http_transaction http,
char *  buf,
size_t  len 
)
static

Construct HTTP "Content-Length" header.

Parameters
httpHTTP transaction
bufBuffer
lenLength of buffer
Return values
lenLength of header value, or negative error

Definition at line 1002 of file httpcore.c.

1003  {
1004 
1005  /* Construct content length, if applicable */
1006  if ( http->request.content.len ) {
1007  return snprintf ( buf, len, "%zd", http->request.content.len );
1008  } else {
1009  return 0;
1010  }
1011 }
struct http_request request
Request.
Definition: http.h:434
struct http_request_content content
Content descriptor.
Definition: http.h:220
size_t len
Content length.
Definition: http.h:149
uint32_t len
Length.
Definition: ena.h:14
int snprintf(char *buf, size_t size, const char *fmt,...)
Write a formatted string to a buffer.
Definition: vsprintf.c:382

References http_request::content, len, http_request_content::len, http_transaction::request, and snprintf().

◆ http_format_accept_encoding()

static int http_format_accept_encoding ( struct http_transaction http,
char *  buf,
size_t  len 
)
static

Construct HTTP "Accept-Encoding" header.

Parameters
httpHTTP transaction
bufBuffer
lenLength of buffer
Return values
lenLength of header value, or negative error

Definition at line 1027 of file httpcore.c.

1028  {
1029  struct http_content_encoding *encoding;
1030  const char *sep = "";
1031  size_t used = 0;
1032 
1033  /* Construct list of content encodings */
1035  if ( encoding->supported && ( ! encoding->supported ( http ) ) )
1036  continue;
1037  used += ssnprintf ( ( buf + used ), ( len - used ),
1038  "%s%s", sep, encoding->name );
1039  sep = ", ";
1040  }
1041 
1042  return used;
1043 }
An HTTP content encoding.
Definition: http.h:484
int ssnprintf(char *buf, ssize_t ssize, const char *fmt,...)
Version of vsnprintf() that accepts a signed buffer size.
Definition: vsprintf.c:420
const char * name
Name.
Definition: http.h:486
#define for_each_table_entry(pointer, table)
Iterate through all entries within a linker table.
Definition: tables.h:385
uint32_t len
Length.
Definition: ena.h:14
int(* supported)(struct http_transaction *http)
Check if content encoding is supported for this request.
Definition: http.h:492
#define HTTP_CONTENT_ENCODINGS
HTTP content encoding table.
Definition: http.h:502

References for_each_table_entry, HTTP_CONTENT_ENCODINGS, len, http_content_encoding::name, ssnprintf(), and http_content_encoding::supported.

◆ http_tx_request()

static int http_tx_request ( struct http_transaction http)
static

Transmit request.

Parameters
httpHTTP transaction
Return values
rcReturn status code

Definition at line 1057 of file httpcore.c.

1057  {
1058  struct io_buffer *iobuf;
1059  int len;
1060  int check_len;
1061  int rc;
1062 
1063  /* Calculate request length */
1064  len = http_format_headers ( http, NULL, 0 );
1065  if ( len < 0 ) {
1066  rc = len;
1067  DBGC ( http, "HTTP %p could not construct request: %s\n",
1068  http, strerror ( rc ) );
1069  goto err_len;
1070  }
1071 
1072  /* Allocate I/O buffer */
1073  iobuf = alloc_iob ( len + 1 /* NUL */ + http->request.content.len );
1074  if ( ! iobuf ) {
1075  rc = -ENOMEM;
1076  goto err_alloc;
1077  }
1078 
1079  /* Construct request */
1080  check_len = http_format_headers ( http, iob_put ( iobuf, len ),
1081  ( len + 1 /* NUL */ ) );
1082  assert ( check_len == len );
1083  memcpy ( iob_put ( iobuf, http->request.content.len ),
1084  http->request.content.data, http->request.content.len );
1085 
1086  /* Deliver request */
1087  if ( ( rc = xfer_deliver_iob ( &http->conn,
1088  iob_disown ( iobuf ) ) ) != 0 ) {
1089  DBGC ( http, "HTTP %p could not deliver request: %s\n",
1090  http, strerror ( rc ) );
1091  goto err_deliver;
1092  }
1093 
1094  /* Clear any previous response */
1095  empty_line_buffer ( &http->response.headers );
1096  memset ( &http->response, 0, sizeof ( http->response ) );
1097 
1098  /* Move to response headers state */
1099  http->state = &http_headers;
1100 
1101  return 0;
1102 
1103  err_deliver:
1104  free_iob ( iobuf );
1105  err_alloc:
1106  err_len:
1107  return rc;
1108 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define iob_put(iobuf, len)
Definition: iobuf.h:120
int xfer_deliver_iob(struct interface *intf, struct io_buffer *iobuf)
Deliver datagram as I/O buffer without metadata.
Definition: xfer.c:254
struct interface conn
Server connection.
Definition: http.h:425
void free_iob(struct io_buffer *iobuf)
Free I/O buffer.
Definition: iobuf.c:146
#define DBGC(...)
Definition: compiler.h:505
struct http_state * state
Transaction state.
Definition: http.h:441
struct io_buffer * alloc_iob(size_t len)
Allocate I/O buffer.
Definition: iobuf.c:129
struct http_request request
Request.
Definition: http.h:434
#define ENOMEM
Not enough space.
Definition: errno.h:534
#define iob_disown(iobuf)
Disown an I/O buffer.
Definition: iobuf.h:212
void * memcpy(void *dest, const void *src, size_t len) __nonnull
struct http_response response
Response.
Definition: http.h:436
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
void empty_line_buffer(struct line_buffer *linebuf)
Discard line buffer contents.
Definition: linebuf.c:65
struct http_request_content content
Content descriptor.
Definition: http.h:220
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
struct line_buffer headers
Raw response header lines.
Definition: http.h:327
const void * data
Content data (if any)
Definition: http.h:147
size_t len
Content length.
Definition: http.h:149
uint32_t len
Length.
Definition: ena.h:14
static struct http_state http_headers
HTTP response headers state.
Definition: httpcore.c:122
static int http_format_headers(struct http_transaction *http, char *buf, size_t len)
Construct HTTP request headers.
Definition: httpcore.c:831
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362
void * memset(void *dest, int character, size_t len) __nonnull
A persistent I/O buffer.
Definition: iobuf.h:33

References alloc_iob(), assert(), http_transaction::conn, http_request::content, http_request_content::data, DBGC, empty_line_buffer(), ENOMEM, free_iob(), http_response::headers, http_format_headers(), http_headers, iob_disown, iob_put, len, http_request_content::len, memcpy(), memset(), NULL, rc, http_transaction::request, http_transaction::response, http_transaction::state, strerror(), and xfer_deliver_iob().

◆ http_parse_status()

static int http_parse_status ( struct http_transaction http,
char *  line 
)
static

Parse HTTP status line.

Parameters
httpHTTP transaction
lineStatus line
Return values
rcReturn status code

Definition at line 1130 of file httpcore.c.

1130  {
1131  char *endp;
1132  char *version;
1133  char *vernum;
1134  char *status;
1135  int response_rc;
1136 
1137  DBGC2 ( http, "HTTP %p RX %s\n", http, line );
1138 
1139  /* Parse HTTP version */
1140  version = http_token ( &line, NULL );
1141  if ( ( ! version ) || ( strncmp ( version, "HTTP/", 5 ) != 0 ) ) {
1142  DBGC ( http, "HTTP %p malformed version \"%s\"\n", http, line );
1143  return -EINVAL_STATUS;
1144  }
1145 
1146  /* Keepalive is enabled by default for anything newer than HTTP/1.0 */
1147  vernum = ( version + 5 /* "HTTP/" (presence already checked) */ );
1148  if ( vernum[0] == '0' ) {
1149  /* HTTP/0.x : keepalive not enabled by default */
1150  } else if ( strncmp ( vernum, "1.0", 3 ) == 0 ) {
1151  /* HTTP/1.0 : keepalive not enabled by default */
1152  } else {
1153  /* HTTP/1.1 or newer: keepalive enabled by default */
1155  }
1156 
1157  /* Parse status code */
1158  status = line;
1159  http->response.status = strtoul ( status, &endp, 10 );
1160  if ( *endp != ' ' ) {
1161  DBGC ( http, "HTTP %p malformed status code \"%s\"\n",
1162  http, status );
1163  return -EINVAL_STATUS;
1164  }
1165 
1166  /* Convert HTTP status code to iPXE return status code */
1167  if ( status[0] == '2' ) {
1168  /* 2xx Success */
1169  response_rc = 0;
1170  } else if ( status[0] == '3' ) {
1171  /* 3xx Redirection */
1172  response_rc = -EXDEV;
1173  } else if ( http->response.status == 401 ) {
1174  /* 401 Unauthorized */
1175  response_rc = -EACCES_401;
1176  } else if ( http->response.status == 403 ) {
1177  /* 403 Forbidden */
1178  response_rc = -EPERM_403;
1179  } else if ( http->response.status == 404 ) {
1180  /* 404 Not Found */
1181  response_rc = -ENOENT_404;
1182  } else if ( status[0] == '4' ) {
1183  /* 4xx Client Error (not already specified) */
1184  response_rc = -EIO_4XX;
1185  } else if ( status[0] == '5' ) {
1186  /* 5xx Server Error */
1187  response_rc = -EIO_5XX;
1188  } else {
1189  /* Unrecognised */
1190  response_rc = -EIO_OTHER;
1191  }
1192  http->response.rc = response_rc;
1193  if ( response_rc )
1194  DBGC ( http, "HTTP %p status %s\n", http, status );
1195 
1196  return 0;
1197 }
#define ENOENT_404
Definition: httpcore.c:90
unsigned int flags
Flags.
Definition: http.h:350
unsigned long strtoul(const char *string, char **endp, int base)
Convert string to numeric value.
Definition: string.c:471
#define EPERM_403
Definition: httpcore.c:99
#define DBGC(...)
Definition: compiler.h:505
#define EIO_OTHER
Definition: httpcore.c:78
int strncmp(const char *first, const char *second, size_t max)
Compare strings.
Definition: string.c:186
#define EXDEV
Improper link.
Definition: errno.h:684
uint8_t status
Status.
Definition: ena.h:16
#define EINVAL_STATUS
Definition: httpcore.c:66
Keep connection alive after close.
Definition: http.h:356
u32 version
Driver version.
Definition: ath9k_hw.c:1983
struct http_response response
Response.
Definition: http.h:436
#define EACCES_401
Definition: httpcore.c:63
int rc
Return status code.
Definition: http.h:338
unsigned int status
Status code.
Definition: http.h:332
char * http_token(char **line, char **value)
Get HTTP response token.
Definition: httpcore.c:191
#define EIO_5XX
Definition: httpcore.c:87
#define DBGC2(...)
Definition: compiler.h:522
#define EIO_4XX
Definition: httpcore.c:84
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362

References DBGC, DBGC2, EACCES_401, EINVAL_STATUS, EIO_4XX, EIO_5XX, EIO_OTHER, ENOENT_404, EPERM_403, EXDEV, http_response::flags, HTTP_RESPONSE_KEEPALIVE, http_token(), NULL, http_response::rc, http_transaction::response, status, http_response::status, strncmp(), strtoul(), and version.

Referenced by http_parse_headers().

◆ http_parse_header()

static int http_parse_header ( struct http_transaction http,
char *  line 
)
static

Parse HTTP header.

Parameters
httpHTTP transaction
lineHeader line
Return values
rcReturn status code

Definition at line 1206 of file httpcore.c.

1206  {
1207  struct http_response_header *header;
1208  char *name = line;
1209  char *sep;
1210 
1211  DBGC2 ( http, "HTTP %p RX %s\n", http, line );
1212 
1213  /* Extract header name */
1214  sep = strchr ( line, ':' );
1215  if ( ! sep ) {
1216  DBGC ( http, "HTTP %p malformed header \"%s\"\n", http, line );
1217  return -EINVAL_HEADER;
1218  }
1219  *sep = '\0';
1220 
1221  /* Extract remainder of line */
1222  line = ( sep + 1 );
1223  while ( isspace ( *line ) )
1224  line++;
1225 
1226  /* Process header, if recognised */
1228  if ( strcasecmp ( name, header->name ) == 0 )
1229  return header->parse ( http, line );
1230  }
1231 
1232  /* Unrecognised headers should be ignored */
1233  return 0;
1234 }
const char * name
Definition: ath9k_hw.c:1984
#define DBGC(...)
Definition: compiler.h:505
int strcasecmp(const char *first, const char *second)
Compare case-insensitive strings.
Definition: string.c:208
#define HTTP_RESPONSE_HEADERS
HTTP response header table.
Definition: http.h:377
char * strchr(const char *src, int character)
Find character within a string.
Definition: string.c:271
#define for_each_table_entry(pointer, table)
Iterate through all entries within a linker table.
Definition: tables.h:385
int isspace(int character)
Check to see if character is a space.
Definition: ctype.c:41
#define EINVAL_HEADER
Definition: httpcore.c:69
#define DBGC2(...)
Definition: compiler.h:522
struct ena_aq_header header
Header.
Definition: ena.h:12
An HTTP response header.
Definition: http.h:364

References DBGC, DBGC2, EINVAL_HEADER, for_each_table_entry, header, HTTP_RESPONSE_HEADERS, isspace(), name, strcasecmp(), and strchr().

Referenced by http_parse_headers().

◆ http_parse_headers()

static int http_parse_headers ( struct http_transaction http)
static

Parse HTTP response headers.

Parameters
httpHTTP transaction
Return values
rcReturn status code

Definition at line 1242 of file httpcore.c.

1242  {
1243  char *line;
1244  char *next;
1245  int rc;
1246 
1247  /* Get status line */
1248  line = http->response.headers.data;
1249  assert ( line != NULL );
1250  next = ( line + strlen ( line ) + 1 /* NUL */ );
1251 
1252  /* Parse status line */
1253  if ( ( rc = http_parse_status ( http, line ) ) != 0 )
1254  return rc;
1255 
1256  /* Process header lines */
1257  while ( 1 ) {
1258 
1259  /* Move to next line */
1260  line = next;
1261  next = ( line + strlen ( line ) + 1 /* NUL */ );
1262 
1263  /* Stop on terminating blank line */
1264  if ( ! line[0] )
1265  return 0;
1266 
1267  /* Process header line */
1268  if ( ( rc = http_parse_header ( http, line ) ) != 0 )
1269  return rc;
1270  }
1271 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
uint32_t next
Next descriptor address.
Definition: myson.h:18
static int http_parse_header(struct http_transaction *http, char *line)
Parse HTTP header.
Definition: httpcore.c:1206
char * data
Data buffer.
Definition: linebuf.h:18
struct http_response response
Response.
Definition: http.h:436
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
size_t strlen(const char *src)
Get length of string.
Definition: string.c:243
struct line_buffer headers
Raw response header lines.
Definition: http.h:327
static int http_parse_status(struct http_transaction *http, char *line)
Parse HTTP status line.
Definition: httpcore.c:1130
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362

References assert(), line_buffer::data, http_response::headers, http_parse_header(), http_parse_status(), next, NULL, rc, http_transaction::response, and strlen().

Referenced by http_rx_headers().

◆ http_parse_location()

static int http_parse_location ( struct http_transaction http,
char *  line 
)
static

Parse HTTP "Location" header.

Parameters
httpHTTP transaction
lineRemaining header line
Return values
rcReturn status code

Definition at line 1280 of file httpcore.c.

1280  {
1281 
1282  /* Store location */
1283  http->response.location = line;
1284  return 0;
1285 }
const char * location
Redirection location.
Definition: http.h:340
struct http_response response
Response.
Definition: http.h:436

References http_response::location, and http_transaction::response.

◆ http_parse_transfer_encoding()

static int http_parse_transfer_encoding ( struct http_transaction http,
char *  line 
)
static

Parse HTTP "Transfer-Encoding" header.

Parameters
httpHTTP transaction
lineRemaining header line
Return values
rcReturn status code

Definition at line 1300 of file httpcore.c.

1301  {
1302  struct http_transfer_encoding *encoding;
1303 
1304  /* Check for known transfer encodings */
1306  if ( strcasecmp ( line, encoding->name ) == 0 ) {
1307  http->response.transfer.encoding = encoding;
1308  return 0;
1309  }
1310  }
1311 
1312  DBGC ( http, "HTTP %p unrecognised Transfer-Encoding \"%s\"\n",
1313  http, line );
1314  return -ENOTSUP_TRANSFER;
1315 }
#define DBGC(...)
Definition: compiler.h:505
int strcasecmp(const char *first, const char *second)
Compare case-insensitive strings.
Definition: string.c:208
struct http_transfer_encoding * encoding
Transfer encoding.
Definition: http.h:257
struct http_response response
Response.
Definition: http.h:436
#define for_each_table_entry(pointer, table)
Iterate through all entries within a linker table.
Definition: tables.h:385
#define ENOTSUP_TRANSFER
Definition: httpcore.c:96
#define HTTP_TRANSFER_ENCODINGS
HTTP transfer encoding table.
Definition: http.h:470
struct http_response_transfer transfer
Transfer descriptor.
Definition: http.h:342
const char * name
Name.
Definition: http.h:458
An HTTP transfer encoding.
Definition: http.h:456

References DBGC, http_response_transfer::encoding, ENOTSUP_TRANSFER, for_each_table_entry, HTTP_TRANSFER_ENCODINGS, http_transfer_encoding::name, http_transaction::response, strcasecmp(), and http_response::transfer.

◆ http_parse_connection()

static int http_parse_connection ( struct http_transaction http,
char *  line 
)
static

Parse HTTP "Connection" header.

Parameters
httpHTTP transaction
lineRemaining header line
Return values
rcReturn status code

Definition at line 1331 of file httpcore.c.

1331  {
1332  char *token;
1333 
1334  /* Check for known connection intentions */
1335  while ( ( token = http_token ( &line, NULL ) ) ) {
1336  if ( strcasecmp ( token, "keep-alive" ) == 0 )
1338  if ( strcasecmp ( token, "close" ) == 0 )
1340  }
1341 
1342  return 0;
1343 }
unsigned int flags
Flags.
Definition: http.h:350
int strcasecmp(const char *first, const char *second)
Compare case-insensitive strings.
Definition: string.c:208
Keep connection alive after close.
Definition: http.h:356
struct http_response response
Response.
Definition: http.h:436
char * http_token(char **line, char **value)
Get HTTP response token.
Definition: httpcore.c:191
u8 token
Definition: CIB_PRM.h:42
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362

References http_response::flags, HTTP_RESPONSE_KEEPALIVE, http_token(), NULL, http_transaction::response, strcasecmp(), and token.

◆ http_parse_content_length()

static int http_parse_content_length ( struct http_transaction http,
char *  line 
)
static

Parse HTTP "Content-Length" header.

Parameters
httpHTTP transaction
lineRemaining header line
Return values
rcReturn status code

Definition at line 1358 of file httpcore.c.

1359  {
1360  char *endp;
1361 
1362  /* Parse length */
1363  http->response.content.len = strtoul ( line, &endp, 10 );
1364  if ( *endp != '\0' ) {
1365  DBGC ( http, "HTTP %p invalid Content-Length \"%s\"\n",
1366  http, line );
1367  return -EINVAL_CONTENT_LENGTH;
1368  }
1369 
1370  /* Record that we have a content length (since it may be zero) */
1372 
1373  return 0;
1374 }
Content length specified.
Definition: http.h:358
unsigned int flags
Flags.
Definition: http.h:350
unsigned long strtoul(const char *string, char **endp, int base)
Convert string to numeric value.
Definition: string.c:471
#define DBGC(...)
Definition: compiler.h:505
struct http_response response
Response.
Definition: http.h:436
struct http_response_content content
Content descriptor.
Definition: http.h:344
size_t len
Content length (may be zero)
Definition: http.h:263
#define EINVAL_CONTENT_LENGTH
Definition: httpcore.c:72

References http_response::content, DBGC, EINVAL_CONTENT_LENGTH, http_response::flags, HTTP_RESPONSE_CONTENT_LEN, http_response_content::len, http_transaction::response, and strtoul().

◆ http_parse_content_encoding()

static int http_parse_content_encoding ( struct http_transaction http,
char *  line 
)
static

Parse HTTP "Content-Encoding" header.

Parameters
httpHTTP transaction
lineRemaining header line
Return values
rcReturn status code

Definition at line 1390 of file httpcore.c.

1391  {
1392  struct http_content_encoding *encoding;
1393 
1394  /* Check for known content encodings */
1396  if ( encoding->supported && ( ! encoding->supported ( http ) ) )
1397  continue;
1398  if ( strcasecmp ( line, encoding->name ) == 0 ) {
1399  http->response.content.encoding = encoding;
1400  return 0;
1401  }
1402  }
1403 
1404  /* Some servers (e.g. Apache) have a habit of specifying
1405  * unwarranted content encodings. For example, if Apache
1406  * detects (via /etc/httpd/conf/magic) that a file's contents
1407  * are gzip-compressed, it will set "Content-Encoding: x-gzip"
1408  * regardless of the client's Accept-Encoding header. The
1409  * only viable way to handle such servers is to treat unknown
1410  * content encodings as equivalent to "identity".
1411  */
1412  DBGC ( http, "HTTP %p unrecognised Content-Encoding \"%s\"\n",
1413  http, line );
1414  return 0;
1415 }
#define DBGC(...)
Definition: compiler.h:505
int strcasecmp(const char *first, const char *second)
Compare case-insensitive strings.
Definition: string.c:208
An HTTP content encoding.
Definition: http.h:484
struct http_response response
Response.
Definition: http.h:436
struct http_response_content content
Content descriptor.
Definition: http.h:344
const char * name
Name.
Definition: http.h:486
struct http_content_encoding * encoding
Content encoding.
Definition: http.h:265
#define for_each_table_entry(pointer, table)
Iterate through all entries within a linker table.
Definition: tables.h:385
int(* supported)(struct http_transaction *http)
Check if content encoding is supported for this request.
Definition: http.h:492
#define HTTP_CONTENT_ENCODINGS
HTTP content encoding table.
Definition: http.h:502

References http_response::content, DBGC, http_response_content::encoding, for_each_table_entry, HTTP_CONTENT_ENCODINGS, http_content_encoding::name, http_transaction::response, strcasecmp(), and http_content_encoding::supported.

◆ http_parse_retry_after()

static int http_parse_retry_after ( struct http_transaction http,
char *  line 
)
static

Parse HTTP "Retry-After" header.

Parameters
httpHTTP transaction
lineRemaining header line
Return values
rcReturn status code

Definition at line 1431 of file httpcore.c.

1432  {
1433  char *endp;
1434 
1435  /* Try to parse value as a simple number of seconds */
1436  http->response.retry_after = strtoul ( line, &endp, 10 );
1437  if ( *endp != '\0' ) {
1438  /* For any value which is not a simple number of
1439  * seconds (e.g. a full HTTP date), just retry after a
1440  * fixed delay, since we don't have code able to parse
1441  * full HTTP dates.
1442  */
1444  DBGC ( http, "HTTP %p cannot understand Retry-After \"%s\"; "
1445  "using %d seconds\n", http, line, HTTP_RETRY_SECONDS );
1446  }
1447 
1448  /* Allow HTTP request to be retried after specified delay */
1450 
1451  return 0;
1452 }
unsigned int flags
Flags.
Definition: http.h:350
unsigned long strtoul(const char *string, char **endp, int base)
Convert string to numeric value.
Definition: string.c:471
#define DBGC(...)
Definition: compiler.h:505
struct http_response response
Response.
Definition: http.h:436
#define HTTP_RETRY_SECONDS
Retry delay used when we cannot understand the Retry-After header.
Definition: httpcore.c:107
Transaction may be retried on failure.
Definition: http.h:360
unsigned int retry_after
Retry delay (in seconds)
Definition: http.h:348

References DBGC, http_response::flags, HTTP_RESPONSE_RETRY, HTTP_RETRY_SECONDS, http_transaction::response, http_response::retry_after, and strtoul().

◆ http_rx_headers()

static int http_rx_headers ( struct http_transaction http,
struct io_buffer **  iobuf 
)
static

Handle received HTTP headers.

Parameters
httpHTTP transaction
iobufI/O buffer (may be claimed)
Return values
rcReturn status code

Definition at line 1467 of file httpcore.c.

1468  {
1469  struct http_transfer_encoding *transfer;
1470  struct http_content_encoding *content;
1471  char *line;
1472  int rc;
1473 
1474  /* Buffer header line */
1475  if ( ( rc = http_rx_linebuf ( http, *iobuf,
1476  &http->response.headers ) ) != 0 )
1477  return rc;
1478 
1479  /* Wait until we see the empty line marking end of headers */
1480  line = buffered_line ( &http->response.headers );
1481  if ( ( line == NULL ) || ( line[0] != '\0' ) )
1482  return 0;
1483 
1484  /* Process headers */
1485  if ( ( rc = http_parse_headers ( http ) ) != 0 )
1486  return rc;
1487 
1488  /* Initialise content encoding, if applicable */
1489  if ( ( content = http->response.content.encoding ) &&
1490  ( ( rc = content->init ( http ) ) != 0 ) ) {
1491  DBGC ( http, "HTTP %p could not initialise %s content "
1492  "encoding: %s\n", http, content->name, strerror ( rc ) );
1493  return rc;
1494  }
1495 
1496  /* Presize receive buffer, if we have a content length */
1497  if ( http->response.content.len ) {
1498  xfer_seek ( &http->transfer, http->response.content.len );
1499  xfer_seek ( &http->transfer, 0 );
1500  }
1501 
1502  /* Complete transfer if this is a HEAD request */
1503  if ( http->request.method == &http_head ) {
1504  if ( ( rc = http_transfer_complete ( http ) ) != 0 )
1505  return rc;
1506  return 0;
1507  }
1508 
1509  /* Default to identity transfer encoding, if none specified */
1510  if ( ! http->response.transfer.encoding )
1512 
1513  /* Move to transfer encoding-specific data state */
1514  transfer = http->response.transfer.encoding;
1515  http->state = &transfer->state;
1516 
1517  /* Initialise transfer encoding */
1518  if ( ( rc = transfer->init ( http ) ) != 0 ) {
1519  DBGC ( http, "HTTP %p could not initialise %s transfer "
1520  "encoding: %s\n", http, transfer->name, strerror ( rc ));
1521  return rc;
1522  }
1523 
1524  return 0;
1525 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
struct http_method http_head
HTTP HEAD method.
Definition: httpcore.c:134
static int http_parse_headers(struct http_transaction *http)
Parse HTTP response headers.
Definition: httpcore.c:1242
static struct http_transfer_encoding http_transfer_identity
Identity transfer encoding.
Definition: httpcore.c:124
#define DBGC(...)
Definition: compiler.h:505
struct http_state * state
Transaction state.
Definition: http.h:441
An HTTP content encoding.
Definition: http.h:484
struct http_request request
Request.
Definition: http.h:434
struct http_transfer_encoding * encoding
Transfer encoding.
Definition: http.h:257
struct http_response response
Response.
Definition: http.h:436
struct http_response_content content
Content descriptor.
Definition: http.h:344
const char * name
Name.
Definition: http.h:486
int xfer_seek(struct interface *intf, off_t offset)
Seek to position.
Definition: xfer.c:350
struct http_content_encoding * encoding
Content encoding.
Definition: http.h:265
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
size_t len
Content length (may be zero)
Definition: http.h:263
struct interface transfer
Transfer-decoded interface.
Definition: http.h:423
char * buffered_line(struct line_buffer *linebuf)
Retrieve buffered-up line.
Definition: linebuf.c:45
struct line_buffer headers
Raw response header lines.
Definition: http.h:327
struct http_response_transfer transfer
Transfer descriptor.
Definition: http.h:342
static int http_transfer_complete(struct http_transaction *http)
Handle successful transfer completion.
Definition: httpcore.c:740
struct http_method * method
Method.
Definition: http.h:212
int(* init)(struct http_transaction *http)
Initialise transfer encoding.
Definition: http.h:464
const char * name
Name.
Definition: http.h:458
struct http_state state
Receive data state.
Definition: http.h:466
An HTTP transfer encoding.
Definition: http.h:456
static int http_rx_linebuf(struct http_transaction *http, struct io_buffer *iobuf, struct line_buffer *linebuf)
Handle received HTTP line-buffered data.
Definition: httpcore.c:163
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362
int(* init)(struct http_transaction *http)
Initialise content encoding.
Definition: http.h:498

References buffered_line(), http_response::content, DBGC, http_response_transfer::encoding, http_response_content::encoding, http_response::headers, http_head, http_parse_headers(), http_rx_linebuf(), http_transfer_complete(), http_transfer_identity, http_transfer_encoding::init, http_content_encoding::init, http_response_content::len, http_request::method, http_transfer_encoding::name, http_content_encoding::name, NULL, rc, http_transaction::request, http_transaction::response, http_transaction::state, http_transfer_encoding::state, strerror(), http_response::transfer, http_transaction::transfer, and xfer_seek().

◆ http_init_transfer_identity()

static int http_init_transfer_identity ( struct http_transaction http)
static

Initialise transfer encoding.

Parameters
httpHTTP transaction
Return values
rcReturn status code

Definition at line 1546 of file httpcore.c.

1546  {
1547  int rc;
1548 
1549  /* Complete transfer immediately if we have a zero content length */
1550  if ( ( http->response.flags & HTTP_RESPONSE_CONTENT_LEN ) &&
1551  ( http->response.content.len == 0 ) &&
1552  ( ( rc = http_transfer_complete ( http ) ) != 0 ) )
1553  return rc;
1554 
1555  return 0;
1556 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
Content length specified.
Definition: http.h:358
unsigned int flags
Flags.
Definition: http.h:350
struct http_response response
Response.
Definition: http.h:436
struct http_response_content content
Content descriptor.
Definition: http.h:344
size_t len
Content length (may be zero)
Definition: http.h:263
static int http_transfer_complete(struct http_transaction *http)
Handle successful transfer completion.
Definition: httpcore.c:740

References http_response::content, http_response::flags, HTTP_RESPONSE_CONTENT_LEN, http_transfer_complete(), http_response_content::len, rc, and http_transaction::response.

◆ http_rx_transfer_identity()

static int http_rx_transfer_identity ( struct http_transaction http,
struct io_buffer **  iobuf 
)
static

Handle received data.

Parameters
httpHTTP transaction
iobufI/O buffer (may be claimed)
Return values
rcReturn status code

Definition at line 1565 of file httpcore.c.

1566  {
1567  size_t len = iob_len ( *iobuf );
1568  int rc;
1569 
1570  /* Update lengths */
1571  http->len += len;
1572 
1573  /* Fail if this transfer would overrun the expected content
1574  * length (if any).
1575  */
1576  if ( ( http->response.flags & HTTP_RESPONSE_CONTENT_LEN ) &&
1577  ( http->len > http->response.content.len ) ) {
1578  DBGC ( http, "HTTP %p content length overrun\n", http );
1579  return -EIO_CONTENT_LENGTH;
1580  }
1581 
1582  /* Hand off to content encoding */
1583  if ( ( rc = xfer_deliver_iob ( &http->transfer,
1584  iob_disown ( *iobuf ) ) ) != 0 )
1585  return rc;
1586 
1587  /* Complete transfer if we have received the expected content
1588  * length (if any).
1589  */
1590  if ( ( http->response.flags & HTTP_RESPONSE_CONTENT_LEN ) &&
1591  ( http->len == http->response.content.len ) &&
1592  ( ( rc = http_transfer_complete ( http ) ) != 0 ) )
1593  return rc;
1594 
1595  return 0;
1596 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
Content length specified.
Definition: http.h:358
unsigned int flags
Flags.
Definition: http.h:350
int xfer_deliver_iob(struct interface *intf, struct io_buffer *iobuf)
Deliver datagram as I/O buffer without metadata.
Definition: xfer.c:254
#define DBGC(...)
Definition: compiler.h:505
#define iob_disown(iobuf)
Disown an I/O buffer.
Definition: iobuf.h:212
struct http_response response
Response.
Definition: http.h:436
size_t len
Accumulated transfer-decoded length.
Definition: http.h:443
struct http_response_content content
Content descriptor.
Definition: http.h:344
#define EIO_CONTENT_LENGTH
Definition: httpcore.c:81
size_t len
Content length (may be zero)
Definition: http.h:263
static size_t iob_len(struct io_buffer *iobuf)
Calculate length of data in an I/O buffer.
Definition: iobuf.h:155
struct interface transfer
Transfer-decoded interface.
Definition: http.h:423
uint32_t len
Length.
Definition: ena.h:14
static int http_transfer_complete(struct http_transaction *http)
Handle successful transfer completion.
Definition: httpcore.c:740

References http_response::content, DBGC, EIO_CONTENT_LENGTH, http_response::flags, HTTP_RESPONSE_CONTENT_LEN, http_transfer_complete(), iob_disown, iob_len(), len, http_response_content::len, http_transaction::len, rc, http_transaction::response, http_transaction::transfer, and xfer_deliver_iob().

◆ http_close_transfer_identity()

static void http_close_transfer_identity ( struct http_transaction http,
int  rc 
)
static

Handle server connection close.

Parameters
httpHTTP transaction
rcReason for close

Definition at line 1604 of file httpcore.c.

1605  {
1606 
1607  /* Fail if any error occurred */
1608  if ( rc != 0 )
1609  goto err;
1610 
1611  /* Fail if we have a content length (since we would have
1612  * already closed the connection if we had received the
1613  * correct content length).
1614  */
1615  if ( http->response.flags & HTTP_RESPONSE_CONTENT_LEN ) {
1616  DBGC ( http, "HTTP %p content length underrun\n", http );
1618  goto err;
1619  }
1620 
1621  /* Indicate that transfer is complete */
1622  if ( ( rc = http_transfer_complete ( http ) ) != 0 )
1623  goto err;
1624 
1625  return;
1626 
1627  err:
1628  http_close ( http, rc );
1629 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
Content length specified.
Definition: http.h:358
unsigned int flags
Flags.
Definition: http.h:350
static void http_close(struct http_transaction *http, int rc)
Close HTTP transaction.
Definition: httpcore.c:278
#define DBGC(...)
Definition: compiler.h:505
struct http_response response
Response.
Definition: http.h:436
#define EIO_CONTENT_LENGTH
Definition: httpcore.c:81
static int http_transfer_complete(struct http_transaction *http)
Handle successful transfer completion.
Definition: httpcore.c:740

References DBGC, EIO_CONTENT_LENGTH, http_response::flags, http_close(), HTTP_RESPONSE_CONTENT_LEN, http_transfer_complete(), rc, and http_transaction::response.

◆ http_init_transfer_chunked()

static int http_init_transfer_chunked ( struct http_transaction http)
static

Initialise transfer encoding.

Parameters
httpHTTP transaction
Return values
rcReturn status code

Definition at line 1654 of file httpcore.c.

1654  {
1655 
1656  /* Sanity checks */
1657  assert ( http->remaining == 0 );
1658  assert ( http->linebuf.len == 0 );
1659 
1660  return 0;
1661 }
struct line_buffer linebuf
Temporary line buffer.
Definition: http.h:438
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
size_t len
Length of buffered data.
Definition: linebuf.h:20
size_t remaining
Chunk length remaining.
Definition: http.h:445

References assert(), line_buffer::len, http_transaction::linebuf, and http_transaction::remaining.

◆ http_rx_chunk_len()

static int http_rx_chunk_len ( struct http_transaction http,
struct io_buffer **  iobuf 
)
static

Handle received chunk length.

Parameters
httpHTTP transaction
iobufI/O buffer (may be claimed)
Return values
rcReturn status code

Definition at line 1670 of file httpcore.c.

1671  {
1672  char *line;
1673  char *endp;
1674  size_t len;
1675  int rc;
1676 
1677  /* Receive into temporary line buffer */
1678  if ( ( rc = http_rx_linebuf ( http, *iobuf, &http->linebuf ) ) != 0 )
1679  return rc;
1680 
1681  /* Wait until we receive a non-empty line */
1682  line = buffered_line ( &http->linebuf );
1683  if ( ( line == NULL ) || ( line[0] == '\0' ) )
1684  return 0;
1685 
1686  /* Parse chunk length */
1687  http->remaining = strtoul ( line, &endp, 16 );
1688  if ( *endp != '\0' ) {
1689  DBGC ( http, "HTTP %p invalid chunk length \"%s\"\n",
1690  http, line );
1691  return -EINVAL_CHUNK_LENGTH;
1692  }
1693 
1694  /* Empty line buffer */
1695  empty_line_buffer ( &http->linebuf );
1696 
1697  /* Update expected length */
1698  len = ( http->len + http->remaining );
1699  xfer_seek ( &http->transfer, len );
1700  xfer_seek ( &http->transfer, http->len );
1701 
1702  /* If chunk length is zero, then move to response trailers state */
1703  if ( ! http->remaining )
1704  http->state = &http_trailers;
1705 
1706  return 0;
1707 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
unsigned long strtoul(const char *string, char **endp, int base)
Convert string to numeric value.
Definition: string.c:471
struct line_buffer linebuf
Temporary line buffer.
Definition: http.h:438
#define DBGC(...)
Definition: compiler.h:505
struct http_state * state
Transaction state.
Definition: http.h:441
size_t len
Accumulated transfer-decoded length.
Definition: http.h:443
void empty_line_buffer(struct line_buffer *linebuf)
Discard line buffer contents.
Definition: linebuf.c:65
int xfer_seek(struct interface *intf, off_t offset)
Seek to position.
Definition: xfer.c:350
struct interface transfer
Transfer-decoded interface.
Definition: http.h:423
char * buffered_line(struct line_buffer *linebuf)
Retrieve buffered-up line.
Definition: linebuf.c:45
#define EINVAL_CHUNK_LENGTH
Definition: httpcore.c:75
uint32_t len
Length.
Definition: ena.h:14
size_t remaining
Chunk length remaining.
Definition: http.h:445
static int http_rx_linebuf(struct http_transaction *http, struct io_buffer *iobuf, struct line_buffer *linebuf)
Handle received HTTP line-buffered data.
Definition: httpcore.c:163
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362
static struct http_state http_trailers
HTTP response trailers state.
Definition: httpcore.c:123

References buffered_line(), DBGC, EINVAL_CHUNK_LENGTH, empty_line_buffer(), http_rx_linebuf(), http_trailers, len, http_transaction::len, http_transaction::linebuf, NULL, rc, http_transaction::remaining, http_transaction::state, strtoul(), http_transaction::transfer, and xfer_seek().

Referenced by http_rx_transfer_chunked().

◆ http_rx_chunk_data()

static int http_rx_chunk_data ( struct http_transaction http,
struct io_buffer **  iobuf 
)
static

Handle received chunk data.

Parameters
httpHTTP transaction
iobufI/O buffer (may be claimed)
Return values
rcReturn status code

Definition at line 1716 of file httpcore.c.

1717  {
1718  struct io_buffer *payload;
1719  uint8_t *crlf;
1720  size_t len;
1721  int rc;
1722 
1723  /* In the common case of a final chunk in a packet which also
1724  * includes the terminating CRLF, strip the terminating CRLF
1725  * (which we would ignore anyway) and hence avoid
1726  * unnecessarily copying the data.
1727  */
1728  if ( iob_len ( *iobuf ) == ( http->remaining + 2 /* CRLF */ ) ) {
1729  crlf = ( (*iobuf)->data + http->remaining );
1730  if ( ( crlf[0] == '\r' ) && ( crlf[1] == '\n' ) )
1731  iob_unput ( (*iobuf), 2 /* CRLF */ );
1732  }
1733  len = iob_len ( *iobuf );
1734 
1735  /* Use whole/partial buffer as applicable */
1736  if ( len <= http->remaining ) {
1737 
1738  /* Whole buffer is to be consumed: decrease remaining
1739  * length and use original I/O buffer as payload.
1740  */
1741  payload = iob_disown ( *iobuf );
1742  http->len += len;
1743  http->remaining -= len;
1744 
1745  } else {
1746 
1747  /* Partial buffer is to be consumed: copy data to a
1748  * temporary I/O buffer.
1749  */
1750  payload = alloc_iob ( http->remaining );
1751  if ( ! payload ) {
1752  rc = -ENOMEM;
1753  goto err;
1754  }
1755  memcpy ( iob_put ( payload, http->remaining ), (*iobuf)->data,
1756  http->remaining );
1757  iob_pull ( *iobuf, http->remaining );
1758  http->len += http->remaining;
1759  http->remaining = 0;
1760  }
1761 
1762  /* Hand off to content encoding */
1763  if ( ( rc = xfer_deliver_iob ( &http->transfer,
1764  iob_disown ( payload ) ) ) != 0 )
1765  goto err;
1766 
1767  return 0;
1768 
1769  err:
1770  assert ( payload == NULL );
1771  return rc;
1772 }
#define iob_pull(iobuf, len)
Definition: iobuf.h:102
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define iob_put(iobuf, len)
Definition: iobuf.h:120
int xfer_deliver_iob(struct interface *intf, struct io_buffer *iobuf)
Deliver datagram as I/O buffer without metadata.
Definition: xfer.c:254
struct io_buffer * alloc_iob(size_t len)
Allocate I/O buffer.
Definition: iobuf.c:129
#define ENOMEM
Not enough space.
Definition: errno.h:534
#define iob_disown(iobuf)
Disown an I/O buffer.
Definition: iobuf.h:212
void * memcpy(void *dest, const void *src, size_t len) __nonnull
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
size_t len
Accumulated transfer-decoded length.
Definition: http.h:443
#define iob_unput(iobuf, len)
Definition: iobuf.h:135
static size_t iob_len(struct io_buffer *iobuf)
Calculate length of data in an I/O buffer.
Definition: iobuf.h:155
struct interface transfer
Transfer-decoded interface.
Definition: http.h:423
unsigned char uint8_t
Definition: stdint.h:10
uint32_t len
Length.
Definition: ena.h:14
size_t remaining
Chunk length remaining.
Definition: http.h:445
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362
A persistent I/O buffer.
Definition: iobuf.h:33

References alloc_iob(), assert(), ENOMEM, iob_disown, iob_len(), iob_pull, iob_put, iob_unput, len, http_transaction::len, memcpy(), NULL, rc, http_transaction::remaining, http_transaction::transfer, and xfer_deliver_iob().

Referenced by http_rx_transfer_chunked().

◆ http_rx_transfer_chunked()

static int http_rx_transfer_chunked ( struct http_transaction http,
struct io_buffer **  iobuf 
)
static

Handle received chunked data.

Parameters
httpHTTP transaction
iobufI/O buffer (may be claimed)
Return values
rcReturn status code

Definition at line 1781 of file httpcore.c.

1782  {
1783 
1784  /* Handle as chunk length or chunk data as appropriate */
1785  if ( http->remaining ) {
1786  return http_rx_chunk_data ( http, iobuf );
1787  } else {
1788  return http_rx_chunk_len ( http, iobuf );
1789  }
1790 }
static int http_rx_chunk_len(struct http_transaction *http, struct io_buffer **iobuf)
Handle received chunk length.
Definition: httpcore.c:1670
size_t remaining
Chunk length remaining.
Definition: http.h:445
static int http_rx_chunk_data(struct http_transaction *http, struct io_buffer **iobuf)
Handle received chunk data.
Definition: httpcore.c:1716

References http_rx_chunk_data(), http_rx_chunk_len(), and http_transaction::remaining.

◆ http_rx_trailers()

static int http_rx_trailers ( struct http_transaction http,
struct io_buffer **  iobuf 
)
static

Handle received HTTP trailer.

Parameters
httpHTTP transaction
iobufI/O buffer (may be claimed)
Return values
rcReturn status code

Definition at line 1816 of file httpcore.c.

1817  {
1818  char *line;
1819  int rc;
1820 
1821  /* Buffer trailer line */
1822  if ( ( rc = http_rx_linebuf ( http, *iobuf, &http->linebuf ) ) != 0 )
1823  return rc;
1824 
1825  /* Wait until we see the empty line marking end of trailers */
1826  line = buffered_line ( &http->linebuf );
1827  if ( ( line == NULL ) || ( line[0] != '\0' ) )
1828  return 0;
1829 
1830  /* Empty line buffer */
1831  empty_line_buffer ( &http->linebuf );
1832 
1833  /* Transfer is complete */
1834  if ( ( rc = http_transfer_complete ( http ) ) != 0 )
1835  return rc;
1836 
1837  return 0;
1838 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
struct line_buffer linebuf
Temporary line buffer.
Definition: http.h:438
void empty_line_buffer(struct line_buffer *linebuf)
Discard line buffer contents.
Definition: linebuf.c:65
char * buffered_line(struct line_buffer *linebuf)
Retrieve buffered-up line.
Definition: linebuf.c:45
static int http_transfer_complete(struct http_transaction *http)
Handle successful transfer completion.
Definition: httpcore.c:740
static int http_rx_linebuf(struct http_transaction *http, struct io_buffer *iobuf, struct line_buffer *linebuf)
Handle received HTTP line-buffered data.
Definition: httpcore.c:163
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362

References buffered_line(), empty_line_buffer(), http_rx_linebuf(), http_transfer_complete(), http_transaction::linebuf, NULL, and rc.

◆ http_params()

static size_t http_params ( struct parameters params,
char *  buf,
size_t  len 
)
static

Construct HTTP parameter list.

Parameters
paramsParameter list
bufBuffer to contain HTTP POST parameters
lenLength of buffer
Return values
lenLength of parameter list (excluding terminating NUL)

Definition at line 1861 of file httpcore.c.

1861  {
1862  struct parameter *param;
1863  ssize_t remaining = len;
1864  size_t frag_len;
1865 
1866  /* Add each parameter in the form "key=value", joined with "&" */
1867  len = 0;
1868  for_each_param ( param, params ) {
1869 
1870  /* Add the "&", if applicable */
1871  if ( len ) {
1872  if ( remaining > 0 )
1873  *buf = '&';
1874  buf++;
1875  len++;
1876  remaining--;
1877  }
1878 
1879  /* URI-encode the key */
1880  frag_len = uri_encode_string ( 0, param->key, buf, remaining );
1881  buf += frag_len;
1882  len += frag_len;
1883  remaining -= frag_len;
1884 
1885  /* Add the "=" */
1886  if ( remaining > 0 )
1887  *buf = '=';
1888  buf++;
1889  len++;
1890  remaining--;
1891 
1892  /* URI-encode the value */
1893  frag_len = uri_encode_string ( 0, param->value, buf, remaining);
1894  buf += frag_len;
1895  len += frag_len;
1896  remaining -= frag_len;
1897  }
1898 
1899  /* Ensure string is NUL-terminated even if no parameters are present */
1900  if ( remaining > 0 )
1901  *buf = '\0';
1902 
1903  return len;
1904 }
size_t uri_encode_string(unsigned int field, const char *string, char *buf, ssize_t len)
Encode URI field string.
Definition: uri.c:235
#define for_each_param(param, params)
Iterate over all form parameters in a list.
Definition: params.h:75
struct hv_monitor_parameter param[4][32]
Parameters.
Definition: hyperv.h:24
uint32_t len
Length.
Definition: ena.h:14
A form parameter.
Definition: params.h:28
signed long ssize_t
Definition: stdint.h:7

References for_each_param, len, param, and uri_encode_string().

Referenced by http_open_post_uri().

◆ http_open_get_uri()

static int http_open_get_uri ( struct interface xfer,
struct uri uri 
)
static

Open HTTP transaction for simple GET URI.

Parameters
xferData transfer interface
uriRequest URI
Return values
rcReturn status code

Definition at line 1913 of file httpcore.c.

1913  {
1914 
1915  return http_open ( xfer, &http_get, uri, NULL, NULL );
1916 }
struct http_method http_get
HTTP GET method.
Definition: httpcore.c:139
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:601
A Uniform Resource Identifier.
Definition: uri.h:64
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362

References http_get, http_open(), and NULL.

Referenced by http_open_uri().

◆ http_open_post_uri()

static int http_open_post_uri ( struct interface xfer,
struct uri uri 
)
static

Open HTTP transaction for simple POST URI.

Parameters
xferData transfer interface
uriRequest URI
Return values
rcReturn status code

Definition at line 1925 of file httpcore.c.

1925  {
1926  struct parameters *params = uri->params;
1927  struct http_request_content content;
1928  void *data;
1929  size_t len;
1930  size_t check_len;
1931  int rc;
1932 
1933  /* Calculate length of parameter list */
1934  len = http_params ( params, NULL, 0 );
1935 
1936  /* Allocate temporary parameter list */
1937  data = zalloc ( len + 1 /* NUL */ );
1938  if ( ! data ) {
1939  rc = -ENOMEM;
1940  goto err_alloc;
1941  }
1942 
1943  /* Construct temporary parameter list */
1944  check_len = http_params ( params, data, ( len + 1 /* NUL */ ) );
1945  assert ( check_len == len );
1946 
1947  /* Construct request content */
1948  content.type = "application/x-www-form-urlencoded";
1949  content.data = data;
1950  content.len = len;
1951 
1952  /* Open HTTP transaction */
1953  if ( ( rc = http_open ( xfer, &http_post, uri, NULL, &content ) ) != 0 )
1954  goto err_open;
1955 
1956  err_open:
1957  free ( data );
1958  err_alloc:
1959  return rc;
1960 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
A form parameter list.
Definition: params.h:16
static size_t http_params(struct parameters *params, char *buf, size_t len)
Construct HTTP parameter list.
Definition: httpcore.c:1861
#define ENOMEM
Not enough space.
Definition: errno.h:534
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
struct parameters * params
Form parameters.
Definition: uri.h:88
HTTP request content descriptor.
Definition: http.h:143
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:54
void * zalloc(size_t size)
Allocate cleared memory.
Definition: malloc.c:624
uint32_t len
Length.
Definition: ena.h:14
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:601
A Uniform Resource Identifier.
Definition: uri.h:64
struct arbelprm_port_state_change_st data
Message.
Definition: arbel.h:12
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362
struct http_method http_post
HTTP POST method.
Definition: httpcore.c:144

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

Referenced by http_open_uri().

◆ http_open_uri()

int http_open_uri ( struct interface xfer,
struct uri uri 
)

Open HTTP transaction for simple URI.

Parameters
xferData transfer interface
uriRequest URI
Return values
rcReturn status code

Definition at line 1969 of file httpcore.c.

1969  {
1970 
1971  /* Open GET/POST URI as applicable */
1972  if ( uri->params ) {
1973  return http_open_post_uri ( xfer, uri );
1974  } else {
1975  return http_open_get_uri ( xfer, uri );
1976  }
1977 }
static int http_open_post_uri(struct interface *xfer, struct uri *uri)
Open HTTP transaction for simple POST URI.
Definition: httpcore.c:1925
struct parameters * params
Form parameters.
Definition: uri.h:88
static int http_open_get_uri(struct interface *xfer, struct uri *uri)
Open HTTP transaction for simple GET URI.
Definition: httpcore.c:1913
A Uniform Resource Identifier.
Definition: uri.h:64

References http_open_get_uri(), http_open_post_uri(), and uri::params.

◆ REQUIRING_SYMBOL()

REQUIRING_SYMBOL ( http_open  )

◆ REQUIRE_OBJECT()

REQUIRE_OBJECT ( config_http  )

Variable Documentation

◆ __profiler

struct profiler http_xfer_profiler __profiler = { .name = "http.rx" }
static

Receive profiler.

Data transfer profiler.

Definition at line 110 of file httpcore.c.

◆ __errortab

struct errortab http_errors [] __errortab
Initial value:
= {
}
#define EINFO_EIO_4XX
Definition: httpcore.c:85
#define __einfo_errortab(einfo)
Definition: errortab.h:23
#define EINFO_EIO_5XX
Definition: httpcore.c:88

Human-readable error messages.

Definition at line 116 of file httpcore.c.

◆ http_request

static struct http_state http_request
static
Initial value:
= {
.close = http_close_error,
}
static int http_tx_request(struct http_transaction *http)
Transmit request.
Definition: httpcore.c:1057
static void http_close_error(struct http_transaction *http, int rc)
Close HTTP transaction with error (even if none specified)
Definition: httpcore.c:297

HTTP request state.

Definition at line 121 of file httpcore.c.

Referenced by http_open(), and http_reopen().

◆ http_headers

static struct http_state http_headers
static
Initial value:
= {
.close = http_close_error,
}
static int http_rx_headers(struct http_transaction *http, struct io_buffer **iobuf)
Handle received HTTP headers.
Definition: httpcore.c:1467
static void http_close_error(struct http_transaction *http, int rc)
Close HTTP transaction with error (even if none specified)
Definition: httpcore.c:297

HTTP response headers state.

Definition at line 122 of file httpcore.c.

Referenced by http_tx_request().

◆ http_trailers

static struct http_state http_trailers
static
Initial value:
= {
.close = http_close_error,
}
static int http_rx_trailers(struct http_transaction *http, struct io_buffer **iobuf)
Handle received HTTP trailer.
Definition: httpcore.c:1816
static void http_close_error(struct http_transaction *http, int rc)
Close HTTP transaction with error (even if none specified)
Definition: httpcore.c:297

HTTP response trailers state.

Definition at line 123 of file httpcore.c.

Referenced by http_rx_chunk_len().

◆ http_transfer_identity

static struct http_transfer_encoding http_transfer_identity
static
Initial value:
= {
.name = "identity",
.state = {
},
}
static int http_rx_transfer_identity(struct http_transaction *http, struct io_buffer **iobuf)
Handle received data.
Definition: httpcore.c:1565
static void http_close_transfer_identity(struct http_transaction *http, int rc)
Handle server connection close.
Definition: httpcore.c:1604
static int http_init_transfer_identity(struct http_transaction *http)
Initialise transfer encoding.
Definition: httpcore.c:1546

Identity transfer encoding.

Definition at line 124 of file httpcore.c.

Referenced by http_rx_headers().

◆ http_head

struct http_method http_head
Initial value:
= {
.name = "HEAD",
}

HTTP HEAD method.

Definition at line 134 of file httpcore.c.

Referenced by http_block_read_capacity(), and http_rx_headers().

◆ http_get

struct http_method http_get
Initial value:
= {
.name = "GET",
}

HTTP GET method.

Definition at line 139 of file httpcore.c.

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

◆ http_post

struct http_method http_post
Initial value:
= {
.name = "POST",
}

HTTP POST method.

Definition at line 144 of file httpcore.c.

Referenced by http_open_post_uri(), and peerblk_retrieval_open().

◆ http_xfer_operations

struct interface_operation http_xfer_operations[]
static
Initial value:
= {
}
void xfer_window_changed(struct interface *intf)
Report change of flow control window.
Definition: xfer.c:145
void intf_close(struct interface *intf, int rc)
Close an object interface.
Definition: interface.c:249
static void http_close(struct http_transaction *http, int rc)
Close HTTP transaction.
Definition: httpcore.c:278
__weak int http_block_read_capacity(struct http_transaction *http __unused, struct interface *data __unused)
Read block device capacity (when HTTP block device support is not present)
Definition: httpcore.c:517
int block_read(struct interface *control, struct interface *data, uint64_t lba, unsigned int count, userptr_t buffer, size_t len)
Read from block device.
Definition: blockdev.c:47
static EFI_DEVICE_PATH_PROTOCOL * http_efi_describe(struct http_transaction *http)
Describe as an EFI device path.
Definition: httpcore.c:530
An HTTP transaction.
Definition: http.h:415
#define EFI_INTF_OP
Definition: efi.h:309
#define INTF_OP(op_type, object_type, op_func)
Define an object interface operation.
Definition: interface.h:32
EFI_DEVICE_PATH_PROTOCOL * efi_describe(struct interface *intf)
Describe object as an EFI device path.
Definition: efi_path.c:491
__weak int http_block_read(struct http_transaction *http __unused, struct interface *data __unused, uint64_t lba __unused, unsigned int count __unused, userptr_t buffer __unused, size_t len __unused)
Read from block device (when HTTP block device support is not present)
Definition: httpcore.c:502
static void http_step(struct http_transaction *http)
HTTP transmit process.
Definition: httpcore.c:352
int block_read_capacity(struct interface *control, struct interface *data)
Read block device capacity.
Definition: blockdev.c:105

HTTP data transfer interface operations.

Definition at line 536 of file httpcore.c.

◆ http_xfer_desc

struct interface_descriptor http_xfer_desc
static
Initial value:
=
An HTTP transaction.
Definition: http.h:415
static struct interface_operation http_xfer_operations[]
HTTP data transfer interface operations.
Definition: httpcore.c:536
#define INTF_DESC_PASSTHRU(object_type, intf, operations, passthru)
Define an object interface descriptor with pass-through interface.
Definition: interface.h:97

HTTP data transfer interface descriptor.

Definition at line 547 of file httpcore.c.

Referenced by http_open().

◆ http_content_operations

struct interface_operation http_content_operations[]
static
Initial value:
= {
}
void intf_close(struct interface *intf, int rc)
Close an object interface.
Definition: interface.c:249
A data transfer buffer.
Definition: xferbuf.h:19
static void http_close(struct http_transaction *http, int rc)
Close HTTP transaction.
Definition: httpcore.c:278
static struct xfer_buffer * http_content_buffer(struct http_transaction *http)
Get underlying data transfer buffer.
Definition: httpcore.c:479
static int http_content_deliver(struct http_transaction *http, struct io_buffer *iobuf, struct xfer_metadata *meta)
Handle received content-decoded data.
Definition: httpcore.c:449
An HTTP transaction.
Definition: http.h:415
#define INTF_OP(op_type, object_type, op_func)
Define an object interface operation.
Definition: interface.h:32
int xfer_deliver(struct interface *intf, struct io_buffer *iobuf, struct xfer_metadata *meta)
Deliver datagram.
Definition: xfer.c:193

HTTP content-decoded interface operations.

Definition at line 552 of file httpcore.c.

◆ http_content_desc

struct interface_descriptor http_content_desc
static
Initial value:
=
static struct interface_operation http_content_operations[]
HTTP content-decoded interface operations.
Definition: httpcore.c:552
An HTTP transaction.
Definition: http.h:415
#define INTF_DESC_PASSTHRU(object_type, intf, operations, passthru)
Define an object interface descriptor with pass-through interface.
Definition: interface.h:97

HTTP content-decoded interface descriptor.

Definition at line 560 of file httpcore.c.

Referenced by http_open().

◆ http_transfer_operations

struct interface_operation http_transfer_operations[]
static
Initial value:
= {
}
void intf_close(struct interface *intf, int rc)
Close an object interface.
Definition: interface.c:249
static void http_close(struct http_transaction *http, int rc)
Close HTTP transaction.
Definition: httpcore.c:278
An HTTP transaction.
Definition: http.h:415
#define INTF_OP(op_type, object_type, op_func)
Define an object interface operation.
Definition: interface.h:32

HTTP transfer-decoded interface operations.

Definition at line 565 of file httpcore.c.

◆ http_transfer_desc

struct interface_descriptor http_transfer_desc
static
Initial value:
=
An HTTP transaction.
Definition: http.h:415
static struct interface_operation http_transfer_operations[]
HTTP transfer-decoded interface operations.
Definition: httpcore.c:565
#define INTF_DESC_PASSTHRU(object_type, intf, operations, passthru)
Define an object interface descriptor with pass-through interface.
Definition: interface.h:97

HTTP transfer-decoded interface descriptor.

Definition at line 570 of file httpcore.c.

Referenced by http_open().

◆ http_conn_operations

struct interface_operation http_conn_operations[]
static
Initial value:
= {
}
void xfer_window_changed(struct interface *intf)
Report change of flow control window.
Definition: xfer.c:145
void intf_close(struct interface *intf, int rc)
Close an object interface.
Definition: interface.c:249
static int http_conn_deliver(struct http_transaction *http, struct io_buffer *iobuf, struct xfer_metadata *meta __unused)
Handle received HTTP data.
Definition: httpcore.c:390
An HTTP transaction.
Definition: http.h:415
void pool_reopen(struct interface *intf)
Reopen a defunct connection.
Definition: pool.c:51
#define INTF_OP(op_type, object_type, op_func)
Define an object interface operation.
Definition: interface.h:32
int xfer_deliver(struct interface *intf, struct io_buffer *iobuf, struct xfer_metadata *meta)
Deliver datagram.
Definition: xfer.c:193
static void http_reopen(struct http_transaction *http)
Reopen stale HTTP connection.
Definition: httpcore.c:308
static void http_step(struct http_transaction *http)
HTTP transmit process.
Definition: httpcore.c:352
static void http_conn_close(struct http_transaction *http, int rc)
Handle server connection close.
Definition: httpcore.c:429

HTTP server connection interface operations.

Definition at line 575 of file httpcore.c.

◆ http_conn_desc

struct interface_descriptor http_conn_desc
static
Initial value:
=
static struct interface_operation http_conn_operations[]
HTTP server connection interface operations.
Definition: httpcore.c:575
An HTTP transaction.
Definition: http.h:415
#define INTF_DESC_PASSTHRU(object_type, intf, operations, passthru)
Define an object interface descriptor with pass-through interface.
Definition: interface.h:97

HTTP server connection interface descriptor.

Definition at line 583 of file httpcore.c.

Referenced by http_open().

◆ http_process_desc

struct process_descriptor http_process_desc
static
Initial value:
=
A process.
Definition: process.h:17
#define PROC_DESC_ONCE(object_type, process, _step)
Define a process descriptor for a process that runs only once.
Definition: process.h:97
An HTTP transaction.
Definition: http.h:415
static void http_step(struct http_transaction *http)
HTTP transmit process.
Definition: httpcore.c:352

HTTP process descriptor.

Definition at line 588 of file httpcore.c.

Referenced by http_open().

◆ __http_request_header

struct http_request_header http_request_accept_encoding __http_request_header
Initial value:
= {
.name = "Host",
.format = http_format_host,
}
static int http_format_host(struct http_transaction *http, char *buf, size_t len)
Construct HTTP "Host" header.
Definition: httpcore.c:886

HTTP "Host" header ".

HTTP "Accept-Encoding" header.

HTTP "Content-Length" header.

HTTP "Content-Type" header.

HTTP "Range" header.

HTTP "Connection" header.

HTTP "User-Agent" header.

Definition at line 894 of file httpcore.c.

◆ __http_response_header

struct http_response_header http_response_retry_after __http_response_header
Initial value:
= {
.name = "Location",
}
static int http_parse_location(struct http_transaction *http, char *line)
Parse HTTP "Location" header.
Definition: httpcore.c:1280

HTTP "Location" header.

HTTP "Retry-After" header.

HTTP "Content-Encoding" header.

HTTP "Content-Length" header.

HTTP "Connection" header.

HTTP "Transfer-Encoding" header.

Definition at line 1288 of file httpcore.c.

◆ __http_transfer_encoding

struct http_transfer_encoding http_transfer_chunked __http_transfer_encoding
Initial value:
= {
.name = "chunked",
.state = {
.close = http_close_error,
},
}
static int http_rx_transfer_chunked(struct http_transaction *http, struct io_buffer **iobuf)
Handle received chunked data.
Definition: httpcore.c:1781
static int http_init_transfer_chunked(struct http_transaction *http)
Initialise transfer encoding.
Definition: httpcore.c:1654
static void http_close_error(struct http_transaction *http, int rc)
Close HTTP transaction with error (even if none specified)
Definition: httpcore.c:297

Chunked transfer encoding.

Definition at line 1793 of file httpcore.c.