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 33 of file http.h.

◆ HTTPS_PORT

#define HTTPS_PORT   443

HTTPS default port.

Definition at line 36 of file http.h.

◆ HTTP_SCHEMES

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

HTTP scheme table.

Definition at line 56 of file http.h.

◆ __http_scheme

#define __http_scheme   __table_entry ( HTTP_SCHEMES, 01 )

Declare an HTTP scheme.

Definition at line 59 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 121 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 127 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 134 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 243 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 247 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 379 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 383 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 472 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 476 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 504 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 508 of file http.h.

◆ HTTP_AUTHENTICATIONS

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

HTTP authentication scheme table.

Definition at line 546 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 550 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 356 of file http.h.

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

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

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

235  {
236  struct http_connection *conn;
237  struct http_scheme *scheme;
238  struct sockaddr_tcpip server;
239  struct interface *socket;
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  socket = &conn->socket;
300  if ( scheme->filter &&
301  ( ( rc = scheme->filter ( socket, uri->host, &socket ) ) != 0 ) )
302  goto err_filter;
303  if ( ( rc = xfer_open_named_socket ( socket, SOCK_STREAM,
304  ( struct sockaddr * ) &server,
305  uri->host, NULL ) ) != 0 )
306  goto err_open;
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_open:
317  err_filter:
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:75
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:177
static struct interface_descriptor http_conn_socket_desc
HTTP connection socket interface descriptor.
Definition: httpconn.c:208
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:43
void intf_plug_plug(struct interface *a, struct interface *b)
Plug two object interfaces together.
Definition: interface.c:102
struct interface socket
Transport layer interface.
Definition: http.h:86
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:88
#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:57
int(* filter)(struct interface *xfer, const char *name, struct interface **next)
Transport-layer filter (if any)
Definition: http.h:51
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
An object interface.
Definition: interface.h:109
#define list_for_each_entry_reverse(pos, head, member)
Iterate over entries in a list in reverse order.
Definition: list.h:433
const char * name
Scheme name (e.g.
Definition: http.h:41
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:93
#define SOCK_STREAM
Definition: socket.h:24
const char * host
Host name.
Definition: uri.h:62
struct http_scheme * scheme
HTTP scheme.
Definition: http.h:84
An HTTP URI scheme.
Definition: http.h:39
#define DBGC2(...)
Definition: compiler.h:522
int strcmp(const char *first, const char *second)
Compare strings.
Definition: string.c:157
struct uri * uri
Connection URI.
Definition: http.h:82
static void http_conn_free(struct refcnt *refcnt)
Free HTTP connection.
Definition: httpconn.c:78
unsigned int uri_port(const struct uri *uri, unsigned int default_port)
Get port from URI.
Definition: uri.c:441
A Uniform Resource Identifier.
Definition: uri.h:50
static void http_conn_expired(struct pooled_connection *pool)
Disconnect idle HTTP connection.
Definition: httpconn.c:116
static void intf_init(struct interface *intf, struct interface_descriptor *desc, struct refcnt *refcnt)
Initialise an object interface.
Definition: interface.h:173
struct pooled_connection pool
Pooled connection.
Definition: http.h:90
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362
An HTTP connection.
Definition: http.h:73
#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:221

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

588  {
589  struct http_transaction *http;
590  struct uri request_uri;
591  struct uri request_host;
592  size_t request_uri_len;
593  size_t request_host_len;
594  size_t content_len;
595  char *request_uri_string;
596  char *request_host_string;
597  void *content_data;
598  int rc;
599 
600  /* Calculate request URI length */
601  memset ( &request_uri, 0, sizeof ( request_uri ) );
602  request_uri.path = ( uri->path ? uri->path : "/" );
603  request_uri.query = uri->query;
604  request_uri_len =
605  ( format_uri ( &request_uri, NULL, 0 ) + 1 /* NUL */);
606 
607  /* Calculate host name length */
608  memset ( &request_host, 0, sizeof ( request_host ) );
609  request_host.host = uri->host;
610  request_host.port = uri->port;
611  request_host_len =
612  ( format_uri ( &request_host, NULL, 0 ) + 1 /* NUL */ );
613 
614  /* Calculate request content length */
615  content_len = ( content ? content->len : 0 );
616 
617  /* Allocate and initialise structure */
618  http = zalloc ( sizeof ( *http ) + request_uri_len + request_host_len +
619  content_len );
620  if ( ! http ) {
621  rc = -ENOMEM;
622  goto err_alloc;
623  }
624  request_uri_string = ( ( ( void * ) http ) + sizeof ( *http ) );
625  request_host_string = ( request_uri_string + request_uri_len );
626  content_data = ( request_host_string + request_host_len );
627  format_uri ( &request_uri, request_uri_string, request_uri_len );
628  format_uri ( &request_host, request_host_string, request_host_len );
629  ref_init ( &http->refcnt, http_free );
630  intf_init ( &http->xfer, &http_xfer_desc, &http->refcnt );
631  intf_init ( &http->content, &http_content_desc, &http->refcnt );
632  intf_init ( &http->transfer, &http_transfer_desc, &http->refcnt );
633  intf_init ( &http->conn, &http_conn_desc, &http->refcnt );
634  intf_plug_plug ( &http->transfer, &http->content );
635  process_init ( &http->process, &http_process_desc, &http->refcnt );
636  timer_init ( &http->timer, http_expired, &http->refcnt );
637  http->uri = uri_get ( uri );
638  http->request.method = method;
639  http->request.uri = request_uri_string;
640  http->request.host = request_host_string;
641  if ( range ) {
642  memcpy ( &http->request.range, range,
643  sizeof ( http->request.range ) );
644  }
645  if ( content ) {
646  http->request.content.type = content->type;
647  http->request.content.data = content_data;
648  http->request.content.len = content_len;
649  memcpy ( content_data, content->data, content_len );
650  }
651  http->state = &http_request;
652  DBGC2 ( http, "HTTP %p %s://%s%s\n", http, http->uri->scheme,
653  http->request.host, http->request.uri );
654 
655  /* Open connection */
656  if ( ( rc = http_connect ( &http->conn, uri ) ) != 0 ) {
657  DBGC ( http, "HTTP %p could not connect: %s\n",
658  http, strerror ( rc ) );
659  goto err_connect;
660  }
661 
662  /* Attach to parent interface, mortalise self, and return */
663  intf_plug_plug ( &http->xfer, xfer );
664  ref_put ( &http->refcnt );
665  return 0;
666 
667  err_connect:
668  http_close ( http, rc );
669  ref_put ( &http->refcnt );
670  err_alloc:
671  return rc;
672 }
struct interface xfer
Data transfer interface.
Definition: http.h:421
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
const char * host
Server host name.
Definition: http.h:218
static struct uri * uri_get(struct uri *uri)
Increment URI reference count.
Definition: uri.h:177
#define ref_init(refcnt, free)
Initialise a reference counter.
Definition: refcnt.h:64
struct interface conn
Server connection.
Definition: http.h:427
static void http_expired(struct retry_timer *timer, int over __unused)
Handle retry timer expiry.
Definition: httpcore.c:338
static void http_close(struct http_transaction *http, int rc)
Close HTTP transaction.
Definition: httpcore.c:277
static struct interface_descriptor http_transfer_desc
HTTP transfer-decoded interface descriptor.
Definition: httpcore.c:555
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:545
#define DBGC(...)
Definition: compiler.h:505
struct uri * uri
Request URI.
Definition: http.h:434
void intf_plug_plug(struct interface *a, struct interface *b)
Plug two object interfaces together.
Definition: interface.c:102
struct http_state * state
Transaction state.
Definition: http.h:443
uint8_t method
Definition: ib_mad.h:14
struct http_request_range range
Range descriptor.
Definition: http.h:220
struct http_request request
Request.
Definition: http.h:436
const char * port
Port number.
Definition: uri.h:64
int http_connect(struct interface *xfer, struct uri *uri)
Connect to an HTTP server.
Definition: httpconn.c:235
#define ENOMEM
Not enough space.
Definition: errno.h:534
const char * scheme
Scheme.
Definition: uri.h:54
void * memcpy(void *dest, const void *src, size_t len) __nonnull
An HTTP transaction.
Definition: http.h:417
const char * uri
Request URI string.
Definition: http.h:216
const char * path
Path.
Definition: uri.h:66
size_t format_uri(const struct uri *uri, char *buf, size_t len)
Format URI.
Definition: uri.c:457
struct http_request_content content
Content descriptor.
Definition: http.h:222
static struct interface_descriptor http_conn_desc
HTTP server connection interface descriptor.
Definition: httpcore.c:568
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:423
struct process process
Transmit process.
Definition: http.h:429
static struct interface_descriptor http_xfer_desc
HTTP data transfer interface descriptor.
Definition: httpcore.c:532
struct interface transfer
Transfer-decoded interface.
Definition: http.h:425
const char * type
Content type (if any)
Definition: http.h:147
const char * host
Host name.
Definition: uri.h:62
struct retry_timer timer
Reconnection timer.
Definition: http.h:431
const void * data
Content data (if any)
Definition: http.h:149
size_t len
Content length.
Definition: http.h:151
static struct process_descriptor http_process_desc
HTTP process descriptor.
Definition: httpcore.c:573
const char * query
Query.
Definition: uri.h:68
#define DBGC2(...)
Definition: compiler.h:522
struct refcnt refcnt
Reference count.
Definition: http.h:419
struct http_method * method
Method.
Definition: http.h:214
A Uniform Resource Identifier.
Definition: uri.h:50
static void http_free(struct refcnt *refcnt)
Free HTTP transaction.
Definition: httpcore.c:261
static struct http_state http_request
HTTP request state.
Definition: httpcore.c:120
static void intf_init(struct interface *intf, struct interface_descriptor *desc, struct refcnt *refcnt)
Initialise an object interface.
Definition: interface.h:173
#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, 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::path, uri::port, http_transaction::process, process_init(), uri::query, 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_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 1954 of file httpcore.c.

1954  {
1955 
1956  /* Open GET/POST URI as applicable */
1957  if ( uri->params ) {
1958  return http_open_post_uri ( xfer, uri );
1959  } else {
1960  return http_open_get_uri ( xfer, uri );
1961  }
1962 }
static int http_open_post_uri(struct interface *xfer, struct uri *uri)
Open HTTP transaction for simple POST URI.
Definition: httpcore.c:1910
struct parameters * params
Form parameters.
Definition: uri.h:72
static int http_open_get_uri(struct interface *xfer, struct uri *uri)
Open HTTP transaction for simple GET URI.
Definition: httpcore.c:1898
A Uniform Resource Identifier.
Definition: uri.h:50

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

Variable Documentation

◆ http_head

struct http_method http_head

HTTP HEAD method.

Definition at line 133 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 138 of file httpcore.c.

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

◆ http_post

struct http_method http_post

HTTP POST method.

Definition at line 143 of file httpcore.c.

Referenced by http_open_post_uri(), and peerblk_retrieval_open().