iPXE
Data Structures | Macros | Enumerations | Functions | Variables
http.h File Reference

Hyper Text Transport Protocol. More...

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

Go to the source code of this file.

Data Structures

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

Macros

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

Enumerations

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

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 
char * http_token (char **line, char **value)
 Get HTTP response token. More...
 
int http_connect (struct interface *xfer, struct uri *uri)
 Connect to an HTTP server. 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...
 
int http_open_uri (struct interface *xfer, struct uri *uri)
 Open HTTP transaction for simple URI. More...
 

Variables

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...
 

Detailed Description

Hyper Text Transport Protocol.

Definition in file http.h.

Macro Definition Documentation

◆ HTTP_PORT

#define HTTP_PORT   80

HTTP default port.

Definition at line 34 of file http.h.

◆ HTTPS_PORT

#define HTTPS_PORT   443

HTTPS default port.

Definition at line 37 of file http.h.

◆ HTTP_SCHEMES

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

HTTP scheme table.

Definition at line 54 of file http.h.

◆ __http_scheme

#define __http_scheme   __table_entry ( HTTP_SCHEMES, 01 )

Declare an HTTP scheme.

Definition at line 57 of file http.h.

◆ HTTP_DIGEST_NC

#define HTTP_DIGEST_NC   "00000001"

HTTP Digest authentication client nonce count.

We choose to generate a new client nonce each time.

Definition at line 119 of file http.h.

◆ HTTP_DIGEST_CNONCE_LEN

#define HTTP_DIGEST_CNONCE_LEN   8

HTTP Digest authentication client nonce length.

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

Definition at line 125 of file http.h.

◆ HTTP_DIGEST_RESPONSE_LEN

#define HTTP_DIGEST_RESPONSE_LEN   32

HTTP Digest authentication response length.

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

Definition at line 132 of file http.h.

◆ HTTP_REQUEST_HEADERS

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

HTTP request header table.

Definition at line 241 of file http.h.

◆ __http_request_header

struct http_request_header http_request_accept_encoding __http_request_header   __table_entry ( HTTP_REQUEST_HEADERS, 01 )

Declare an HTTP request header.

HTTP "Accept-Encoding" header.

HTTP "Content-Length" header.

HTTP "Content-Type" header.

HTTP "Range" header.

HTTP "Connection" header.

HTTP "User-Agent" header.

HTTP "X-P2P-PeerDist" header.

Definition at line 245 of file http.h.

◆ HTTP_RESPONSE_HEADERS

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

HTTP response header table.

Definition at line 377 of file http.h.

◆ __http_response_header

struct http_response_header http_response_retry_after __http_response_header   __table_entry ( HTTP_RESPONSE_HEADERS, 01 )

Declare an HTTP response header.

HTTP "Retry-After" header.

HTTP "Content-Encoding" header.

HTTP "Content-Length" header.

HTTP "Connection" header.

HTTP "Transfer-Encoding" header.

Definition at line 381 of file http.h.

◆ HTTP_TRANSFER_ENCODINGS

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

HTTP transfer encoding table.

Definition at line 470 of file http.h.

◆ __http_transfer_encoding

#define __http_transfer_encoding   __table_entry ( HTTP_TRANSFER_ENCODINGS, 01 )

Declare an HTTP transfer encoding.

Definition at line 474 of file http.h.

◆ HTTP_CONTENT_ENCODINGS

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

HTTP content encoding table.

Definition at line 502 of file http.h.

◆ __http_content_encoding

#define __http_content_encoding   __table_entry ( HTTP_CONTENT_ENCODINGS, 01 )

Declare an HTTP content encoding.

Definition at line 506 of file http.h.

◆ HTTP_AUTHENTICATIONS

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

HTTP authentication scheme table.

Definition at line 544 of file http.h.

◆ __http_authentication

struct http_authentication http_ntlm_auth __http_authentication   __table_entry ( HTTP_AUTHENTICATIONS, 01 )

Declare an HTTP authentication scheme.

HTTP NTLM authentication scheme.

Definition at line 548 of file http.h.

Enumeration Type Documentation

◆ http_response_flags

HTTP response flags.

Enumerator
HTTP_RESPONSE_KEEPALIVE 

Keep connection alive after close.

HTTP_RESPONSE_CONTENT_LEN 

Content length specified.

HTTP_RESPONSE_RETRY 

Transaction may be retried on failure.

Definition at line 354 of file http.h.

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

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

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

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

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_connect()

int http_connect ( struct interface xfer,
struct uri uri 
)

Connect to an HTTP server.

Parameters
xferData transfer interface
uriConnection URI
Return values
rcReturn status code

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

Definition at line 236 of file httpconn.c.

236  {
237  struct http_connection *conn;
238  struct http_scheme *scheme;
239  struct sockaddr_tcpip server;
240  unsigned int port;
241  int rc;
242 
243  /* Identify scheme */
244  scheme = http_scheme ( uri );
245  if ( ! scheme )
246  return -ENOTSUP;
247 
248  /* Sanity check */
249  if ( ! uri->host )
250  return -EINVAL;
251 
252  /* Identify port */
253  port = uri_port ( uri, scheme->port );
254 
255  /* Look for a reusable connection in the pool. Reuse the most
256  * recent connection in order to accommodate authentication
257  * schemes that break the stateless nature of HTTP and rely on
258  * the same connection being reused for authentication
259  * responses.
260  */
261  list_for_each_entry_reverse ( conn, &http_connection_pool, pool.list ) {
262 
263  /* Sanity checks */
264  assert ( conn->uri != NULL );
265  assert ( conn->uri->host != NULL );
266 
267  /* Reuse connection, if possible */
268  if ( ( scheme == conn->scheme ) &&
269  ( strcmp ( uri->host, conn->uri->host ) == 0 ) &&
270  ( port == uri_port ( conn->uri, scheme->port ) ) ) {
271 
272  /* Remove from connection pool, stop timer,
273  * attach to parent interface, and return.
274  */
275  pool_del ( &conn->pool );
276  intf_plug_plug ( &conn->xfer, xfer );
277  DBGC2 ( conn, "HTTPCONN %p reused %s://%s:%d\n", conn,
278  conn->scheme->name, conn->uri->host, port );
279  return 0;
280  }
281  }
282 
283  /* Allocate and initialise structure */
284  conn = zalloc ( sizeof ( *conn ) );
285  if ( ! conn ) {
286  rc = -ENOMEM;
287  goto err_alloc;
288  }
289  ref_init ( &conn->refcnt, http_conn_free );
290  conn->uri = uri_get ( uri );
291  conn->scheme = scheme;
292  intf_init ( &conn->socket, &http_conn_socket_desc, &conn->refcnt );
293  intf_init ( &conn->xfer, &http_conn_xfer_desc, &conn->refcnt );
294  pool_init ( &conn->pool, http_conn_expired, &conn->refcnt );
295 
296  /* Open socket */
297  memset ( &server, 0, sizeof ( server ) );
298  server.st_port = htons ( port );
299  if ( ( rc = xfer_open_named_socket ( &conn->socket, SOCK_STREAM,
300  ( struct sockaddr * ) &server,
301  uri->host, NULL ) ) != 0 )
302  goto err_open;
303 
304  /* Add filter, if any */
305  if ( scheme->filter && ( ( rc = scheme->filter ( conn ) ) != 0 ) )
306  goto err_filter;
307 
308  /* Attach to parent interface, mortalise self, and return */
309  intf_plug_plug ( &conn->xfer, xfer );
310  ref_put ( &conn->refcnt );
311 
312  DBGC2 ( conn, "HTTPCONN %p created %s://%s:%d\n", conn,
313  conn->scheme->name, conn->uri->host, port );
314  return 0;
315 
316  err_filter:
317  err_open:
318  DBGC2 ( conn, "HTTPCONN %p could not create %s://%s:%d: %s\n", conn,
319  conn->scheme->name, conn->uri->host, port, strerror ( rc ) );
320  http_conn_close ( conn, rc );
321  ref_put ( &conn->refcnt );
322  err_alloc:
323  return rc;
324 }
#define EINVAL
Invalid argument.
Definition: errno.h:428
TCP/IP socket address.
Definition: tcpip.h:75
struct refcnt refcnt
Reference count.
Definition: http.h:73
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
static struct uri * uri_get(struct uri *uri)
Increment URI reference count.
Definition: uri.h:194
static struct interface_descriptor http_conn_socket_desc
HTTP connection socket interface descriptor.
Definition: httpconn.c:209
timer_init & pool
Definition: pool.h:65
#define ref_init(refcnt, free)
Initialise a reference counter.
Definition: refcnt.h:64
unsigned int port
Default port.
Definition: http.h:44
int(* filter)(struct http_connection *conn)
Transport-layer filter (if any)
Definition: http.h:50
void intf_plug_plug(struct interface *a, struct interface *b)
Plug two object interfaces together.
Definition: interface.c:107
struct interface socket
Transport layer interface.
Definition: http.h:84
void pool_del(struct pooled_connection *pool)
Remove connection from pool.
Definition: pool.c:82
#define ENOTSUP
Operation not supported.
Definition: errno.h:589
struct interface xfer
Data transfer interface.
Definition: http.h:86
#define ENOMEM
Not enough space.
Definition: errno.h:534
u8 port
Port number.
Definition: CIB_PRM.h:31
static struct http_scheme * http_scheme(struct uri *uri)
Identify HTTP scheme.
Definition: httpconn.c:58
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
#define list_for_each_entry_reverse(pos, head, member)
Iterate over entries in a list in reverse order.
Definition: list.h:444
const char * name
Scheme name (e.g.
Definition: http.h:42
Generalized socket address structure.
Definition: socket.h:96
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
static void http_conn_close(struct http_connection *conn, int rc)
Close HTTP connection.
Definition: httpconn.c:94
#define SOCK_STREAM
Definition: socket.h:24
const char * host
Host name.
Definition: uri.h:76
struct http_scheme * scheme
HTTP scheme.
Definition: http.h:82
An HTTP URI scheme.
Definition: http.h:40
#define DBGC2(...)
Definition: compiler.h:522
int strcmp(const char *first, const char *second)
Compare strings.
Definition: string.c:173
struct uri * uri
Connection URI.
Definition: http.h:80
static void http_conn_free(struct refcnt *refcnt)
Free HTTP connection.
Definition: httpconn.c:79
unsigned int uri_port(const struct uri *uri, unsigned int default_port)
Get port from URI.
Definition: uri.c:455
A Uniform Resource Identifier.
Definition: uri.h:64
static void http_conn_expired(struct pooled_connection *pool)
Disconnect idle HTTP connection.
Definition: httpconn.c:117
static void intf_init(struct interface *intf, struct interface_descriptor *desc, struct refcnt *refcnt)
Initialise an object interface.
Definition: interface.h:203
struct pooled_connection pool
Pooled connection.
Definition: http.h:88
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321
An HTTP connection.
Definition: http.h:71
#define htons(value)
Definition: byteswap.h:135
int xfer_open_named_socket(struct interface *xfer, int semantics, struct sockaddr *peer, const char *name, struct sockaddr *local)
Open named socket.
Definition: resolv.c:402
#define ref_put(refcnt)
Drop reference to object.
Definition: refcnt.h:106
void * memset(void *dest, int character, size_t len) __nonnull
static struct interface_descriptor http_conn_xfer_desc
HTTP connection data transfer interface descriptor.
Definition: httpconn.c:222

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

Referenced by http_open(), and http_reopen().

◆ http_open()

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

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

604  {
605  struct http_transaction *http;
606  struct uri request_uri;
607  struct uri request_host;
608  size_t request_uri_len;
609  size_t request_host_len;
610  size_t content_len;
611  char *request_uri_string;
612  char *request_host_string;
613  void *content_data;
614  int rc;
615 
616  /* Calculate request URI length */
617  memset ( &request_uri, 0, sizeof ( request_uri ) );
618  request_uri.epath = ( uri->epath ? uri->epath : "/" );
619  request_uri.equery = uri->equery;
620  request_uri_len =
621  ( format_uri ( &request_uri, NULL, 0 ) + 1 /* NUL */);
622 
623  /* Calculate host name length */
624  memset ( &request_host, 0, sizeof ( request_host ) );
625  request_host.host = uri->host;
626  request_host.port = uri->port;
627  request_host_len =
628  ( format_uri ( &request_host, NULL, 0 ) + 1 /* NUL */ );
629 
630  /* Calculate request content length */
631  content_len = ( content ? content->len : 0 );
632 
633  /* Allocate and initialise structure */
634  http = zalloc ( sizeof ( *http ) + request_uri_len + request_host_len +
635  content_len );
636  if ( ! http ) {
637  rc = -ENOMEM;
638  goto err_alloc;
639  }
640  request_uri_string = ( ( ( void * ) http ) + sizeof ( *http ) );
641  request_host_string = ( request_uri_string + request_uri_len );
642  content_data = ( request_host_string + request_host_len );
643  format_uri ( &request_uri, request_uri_string, request_uri_len );
644  format_uri ( &request_host, request_host_string, request_host_len );
645  ref_init ( &http->refcnt, http_free );
646  intf_init ( &http->xfer, &http_xfer_desc, &http->refcnt );
647  intf_init ( &http->content, &http_content_desc, &http->refcnt );
648  intf_init ( &http->transfer, &http_transfer_desc, &http->refcnt );
649  intf_init ( &http->conn, &http_conn_desc, &http->refcnt );
650  intf_plug_plug ( &http->transfer, &http->content );
651  process_init ( &http->process, &http_process_desc, &http->refcnt );
652  timer_init ( &http->timer, http_expired, &http->refcnt );
653  http->uri = uri_get ( uri );
654  http->request.method = method;
655  http->request.uri = request_uri_string;
656  http->request.host = request_host_string;
657  if ( range ) {
658  memcpy ( &http->request.range, range,
659  sizeof ( http->request.range ) );
660  }
661  if ( content ) {
662  http->request.content.type = content->type;
663  http->request.content.data = content_data;
664  http->request.content.len = content_len;
665  memcpy ( content_data, content->data, content_len );
666  }
667  http->state = &http_request;
668  DBGC2 ( http, "HTTP %p %s://%s%s\n", http, http->uri->scheme,
669  http->request.host, http->request.uri );
670 
671  /* Open connection */
672  if ( ( rc = http_connect ( &http->conn, uri ) ) != 0 ) {
673  DBGC ( http, "HTTP %p could not connect: %s\n",
674  http, strerror ( rc ) );
675  goto err_connect;
676  }
677 
678  /* Attach to parent interface, mortalise self, and return */
679  intf_plug_plug ( &http->xfer, xfer );
680  ref_put ( &http->refcnt );
681  return 0;
682 
683  err_connect:
684  http_close ( http, rc );
685  ref_put ( &http->refcnt );
686  err_alloc:
687  return rc;
688 }
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:340
static void http_close(struct http_transaction *http, int rc)
Close HTTP transaction.
Definition: httpcore.c:279
static struct interface_descriptor http_transfer_desc
HTTP transfer-decoded interface descriptor.
Definition: httpcore.c:571
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:561
#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:584
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:548
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:589
#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:263
static struct http_state http_request
HTTP request state.
Definition: httpcore.c:122
static void intf_init(struct interface *intf, struct interface_descriptor *desc, struct refcnt *refcnt)
Initialise an object interface.
Definition: interface.h:203
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321
#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_uri(), peerblk_raw_open(), and peerblk_retrieval_open().

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

1938  {
1939  struct parameters *params = uri->params;
1940  struct http_request_content content;
1941  struct http_method *method;
1942  const char *type;
1943  void *data;
1944  size_t len;
1945  size_t check_len;
1946  int rc;
1947 
1948  /* Calculate length of form parameter list, if any */
1949  len = ( params ? http_form_params ( params, NULL, 0 ) : 0 );
1950 
1951  /* Use POST if and only if there are form parameters */
1952  if ( len ) {
1953 
1954  /* Use POST */
1955  method = &http_post;
1956  type = "application/x-www-form-urlencoded";
1957 
1958  /* Allocate temporary form parameter list */
1959  data = zalloc ( len + 1 /* NUL */ );
1960  if ( ! data ) {
1961  rc = -ENOMEM;
1962  goto err_alloc;
1963  }
1964 
1965  /* Construct temporary form parameter list */
1966  check_len = http_form_params ( params, data,
1967  ( len + 1 /* NUL */ ) );
1968  assert ( check_len == len );
1969 
1970  } else {
1971 
1972  /* Use GET */
1973  method = &http_get;
1974  type = NULL;
1975  data = NULL;
1976  }
1977 
1978  /* Construct request content */
1979  content.type = type;
1980  content.data = data;
1981  content.len = len;
1982 
1983  /* Open HTTP transaction */
1984  if ( ( rc = http_open ( xfer, method, uri, NULL, &content ) ) != 0 )
1985  goto err_open;
1986 
1987  err_open:
1988  free ( data );
1989  err_alloc:
1990  return rc;
1991 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
A request parameter list.
Definition: params.h:16
An HTTP method.
Definition: http.h:99
uint8_t method
Definition: ib_mad.h:14
#define ENOMEM
Not enough space.
Definition: errno.h:534
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
struct parameters * params
Request parameters.
Definition: uri.h:88
HTTP request content descriptor.
Definition: http.h:143
struct http_method http_get
HTTP GET method.
Definition: httpcore.c:140
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:54
void * zalloc(size_t size)
Allocate cleared memory.
Definition: malloc.c:624
static size_t http_form_params(struct parameters *params, char *buf, size_t len)
Construct HTTP form parameter list.
Definition: httpcore.c:1881
uint32_t len
Length.
Definition: ena.h:14
uint32_t type
Operating system type.
Definition: ena.h:12
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:602
uint8_t data[48]
Additional event data.
Definition: ena.h:22
A Uniform Resource Identifier.
Definition: uri.h:64
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321
struct http_method http_post
HTTP POST method.
Definition: httpcore.c:145

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

Variable Documentation

◆ http_head

struct http_method http_head

HTTP HEAD method.

Definition at line 135 of file httpcore.c.

Referenced by http_block_read_capacity(), and http_rx_headers().

◆ http_get

struct http_method http_get

HTTP GET method.

Definition at line 140 of file httpcore.c.

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

◆ http_post

struct http_method http_post

HTTP POST method.

Definition at line 145 of file httpcore.c.

Referenced by http_open_uri(), and peerblk_retrieval_open().