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 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_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:124
#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:172
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:188
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 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.path = ( uri->path ? uri->path : "/" );
618  request_uri.query = uri->query;
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: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: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: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: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: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:547
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:588
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: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:188
#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 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:72
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: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 134 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 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

HTTP POST method.

Definition at line 144 of file httpcore.c.

Referenced by http_open_post_uri(), and peerblk_retrieval_open().