iPXE
http.h
Go to the documentation of this file.
1#ifndef _IPXE_HTTP_H
2#define _IPXE_HTTP_H
3
4/** @file
5 *
6 * Hyper Text Transport Protocol
7 *
8 */
9
10FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
11FILE_SECBOOT ( PERMITTED );
12
13#include <stdint.h>
14#include <ipxe/refcnt.h>
15#include <ipxe/interface.h>
16#include <ipxe/iobuf.h>
17#include <ipxe/process.h>
18#include <ipxe/retry.h>
19#include <ipxe/linebuf.h>
20#include <ipxe/pool.h>
21#include <ipxe/tables.h>
22#include <ipxe/ntlm.h>
23
24struct http_transaction;
25struct http_connection;
26
27/******************************************************************************
28 *
29 * HTTP URI schemes
30 *
31 ******************************************************************************
32 */
33
34/** HTTP default port */
35#define HTTP_PORT 80
36
37/** HTTPS default port */
38#define HTTPS_PORT 443
39
40/** An HTTP URI scheme */
42 /** Scheme name (e.g. "http" or "https") */
43 const char *name;
44 /** Default port */
45 unsigned int port;
46 /** Transport-layer filter (if any)
47 *
48 * @v conn HTTP connection
49 * @ret rc Return status code
50 */
51 int ( * filter ) ( struct http_connection *conn );
52};
53
54/** HTTP scheme table */
55#define HTTP_SCHEMES __table ( struct http_scheme, "http_schemes" )
56
57/** Declare an HTTP scheme */
58#define __http_scheme __table_entry ( HTTP_SCHEMES, 01 )
59
60/******************************************************************************
61 *
62 * Connections
63 *
64 ******************************************************************************
65 */
66
67/** An HTTP connection
68 *
69 * This represents a potentially reusable connection to an HTTP
70 * server.
71 */
73 /** Reference count */
74 struct refcnt refcnt;
75 /** Connection URI
76 *
77 * This encapsulates the server (and protocol) used for the
78 * connection. This may be the origin server or a proxy
79 * server.
80 */
81 struct uri *uri;
82 /** HTTP scheme */
84 /** Transport layer interface */
86 /** Data transfer interface */
88 /** Pooled connection */
90};
91
92/******************************************************************************
93 *
94 * HTTP methods
95 *
96 ******************************************************************************
97 */
98
99/** An HTTP method */
101 /** Method name (e.g. "GET" or "POST") */
102 const char *name;
103};
104
105/** HTTP method table */
106#define HTTP_METHODS __table ( struct http_method, "http_methods" )
107
108/** Declare an HTTP method */
109#define __http_method __table_entry ( HTTP_METHODS, 01 )
110
111extern struct http_method http_head __http_method;
112extern struct http_method http_get __http_method;
113extern struct http_method http_post __http_method;
114extern struct http_method http_put __http_method;
115
116/******************************************************************************
117 *
118 * Requests
119 *
120 ******************************************************************************
121 */
122
123/** HTTP Digest authentication client nonce count
124 *
125 * We choose to generate a new client nonce each time.
126 */
127#define HTTP_DIGEST_NC "00000001"
128
129/** HTTP Digest authentication client nonce length
130 *
131 * We choose to use a 32-bit hex client nonce.
132 */
133#define HTTP_DIGEST_CNONCE_LEN 8
134
135/** HTTP Digest authentication response length
136 *
137 * The Digest authentication response is a Base16-encoded 16-byte MD5
138 * checksum.
139 */
140#define HTTP_DIGEST_RESPONSE_LEN 32
141
142/** HTTP request range descriptor */
144 /** Range start */
145 size_t start;
146 /** Range length, or zero for no range request */
147 size_t len;
148};
149
150/** HTTP request content descriptor */
152 /** Content type (if any) */
153 const char *type;
154 /** Content data (if any) */
155 const void *data;
156 /** Content length */
157 size_t len;
158};
159
160/** HTTP request Basic authentication descriptor */
162 /** Username */
163 const char *username;
164 /** Password */
165 const char *password;
166};
167
168/** HTTP request Digest authentication descriptor */
170 /** Username */
171 const char *username;
172 /** Quality of protection */
173 const char *qop;
174 /** Algorithm */
175 const char *algorithm;
176 /** Client nonce */
177 char cnonce[ HTTP_DIGEST_CNONCE_LEN + 1 /* NUL */ ];
178 /** Response */
179 char response[ HTTP_DIGEST_RESPONSE_LEN + 1 /* NUL */ ];
180};
181
182/** HTTP request NTLM authentication descriptor */
184 /** Username */
185 const char *username;
186 /** LAN Manager response */
188 /** NT response */
190 /** Authenticate message length */
191 size_t len;
192};
193
194/** HTTP request authentication descriptor */
196 /** Authentication scheme (if any) */
198 /** Per-scheme information */
199 union {
200 /** Basic authentication descriptor */
202 /** Digest authentication descriptor */
204 /** NTLM authentication descriptor */
206 };
207};
208
209/** An HTTP request
210 *
211 * This represents a single request to be sent to a server, including
212 * the values required to construct all headers.
213 *
214 * Pointers within this structure must point to storage which is
215 * guaranteed to remain valid for the lifetime of the containing HTTP
216 * transaction.
217 */
219 /** Method */
221 /** Request URI string */
222 const char *uri;
223 /** Server host name */
224 const char *host;
225 /** Range descriptor */
227 /** Content descriptor */
229 /** Authentication descriptor */
231};
232
233/** An HTTP request header */
235 /** Header name (e.g. "User-Agent") */
236 const char *name;
237 /** Construct remaining header line
238 *
239 * @v http HTTP transaction
240 * @v buf Buffer
241 * @v len Length of buffer
242 * @ret len Header length if present, or negative error
243 */
244 int ( * format ) ( struct http_transaction *http, char *buf,
245 size_t len );
246};
247
248/** HTTP request header table */
249#define HTTP_REQUEST_HEADERS \
250 __table ( struct http_request_header, "http_request_headers" )
251
252/** Declare an HTTP request header */
253#define __http_request_header __table_entry ( HTTP_REQUEST_HEADERS, 01 )
254
255/******************************************************************************
256 *
257 * Responses
258 *
259 ******************************************************************************
260 */
261
262/** HTTP response transfer descriptor */
264 /** Transfer encoding */
266};
267
268/** HTTP response content descriptor */
270 /** Content length (may be zero) */
271 size_t len;
272 /** Content encoding */
274};
275
276/** HTTP response Basic authorization descriptor */
279
280/** HTTP response Digest authorization descriptor */
282 /** Realm */
283 const char *realm;
284 /** Quality of protection */
285 const char *qop;
286 /** Algorithm */
287 const char *algorithm;
288 /** Nonce */
289 const char *nonce;
290 /** Opaque */
291 const char *opaque;
292};
293
294/** HTTP response NTLM authorization descriptor */
296 /** Challenge message */
298 /** Challenge information */
300};
301
302/** HTTP response authorization descriptor */
304 /** Authentication scheme (if any) */
306 /** Per-scheme information */
307 union {
308 /** Basic authorization descriptor */
310 /** Digest authorization descriptor */
312 /** NTLM authorization descriptor */
314 };
315};
316
317/** An HTTP response
318 *
319 * This represents a single response received from the server,
320 * including all values parsed from headers.
321 *
322 * Pointers within this structure may point into the raw response
323 * buffer, and so should be invalidated when the response buffer is
324 * modified or discarded.
325 */
327 /** Raw response header lines
328 *
329 * This is the raw response data received from the server, up
330 * to and including the terminating empty line. String
331 * pointers within the response may point into this data
332 * buffer; NUL terminators will be added (overwriting the
333 * original terminating characters) as needed.
334 */
336 /** Status code
337 *
338 * This is the raw HTTP numeric status code (e.g. 404).
339 */
340 unsigned int status;
341 /** Return status code
342 *
343 * This is the iPXE return status code corresponding to the
344 * HTTP status code (e.g. -ENOENT).
345 */
346 int rc;
347 /** Redirection location */
348 const char *location;
349 /** Transfer descriptor */
351 /** Content descriptor */
353 /** Authorization descriptor */
355 /** Retry delay (in seconds) */
356 unsigned int retry_after;
357 /** Flags */
358 unsigned int flags;
359};
360
361/** HTTP response flags */
363 /** Keep connection alive after close */
365 /** Content length specified */
367 /** Transaction may be retried on failure */
369};
370
371/** An HTTP response header */
373 /** Header name (e.g. "Transfer-Encoding") */
374 const char *name;
375 /** Parse header line
376 *
377 * @v http HTTP transaction
378 * @v line Remaining header line
379 * @ret rc Return status code
380 */
381 int ( * parse ) ( struct http_transaction *http, char *line );
382};
383
384/** HTTP response header table */
385#define HTTP_RESPONSE_HEADERS \
386 __table ( struct http_response_header, "http_response_headers" )
387
388/** Declare an HTTP response header */
389#define __http_response_header __table_entry ( HTTP_RESPONSE_HEADERS, 01 )
390
391/******************************************************************************
392 *
393 * Transactions
394 *
395 ******************************************************************************
396 */
397
398/** HTTP transaction state */
400 /** Transmit data
401 *
402 * @v http HTTP transaction
403 * @ret rc Return status code
404 */
405 int ( * tx ) ( struct http_transaction *http );
406 /** Receive data
407 *
408 * @v http HTTP transaction
409 * @v iobuf I/O buffer (may be claimed)
410 * @ret rc Return status code
411 */
412 int ( * rx ) ( struct http_transaction *http,
413 struct io_buffer **iobuf );
414 /** Server connection closed
415 *
416 * @v http HTTP transaction
417 * @v rc Reason for close
418 */
419 void ( * close ) ( struct http_transaction *http, int rc );
420};
421
422/** An HTTP transaction */
424 /** Reference count */
426 /** Data transfer interface */
428 /** Content-decoded interface */
430 /** Transfer-decoded interface */
432 /** Server connection */
434 /** Transmit process */
436 /** Reconnection timer */
438 /** Idle connection watchdog timer */
440
441 /** Request URI */
442 struct uri *uri;
443 /** Request */
445 /** Response */
447 /** Temporary line buffer */
449
450 /** Transaction state */
452 /** Accumulated transfer-decoded length */
453 size_t len;
454 /** Chunk length remaining */
455 size_t remaining;
456};
457
458/******************************************************************************
459 *
460 * Transfer encoding
461 *
462 ******************************************************************************
463 */
464
465/** An HTTP transfer encoding */
467 /** Name */
468 const char *name;
469 /** Initialise transfer encoding
470 *
471 * @v http HTTP transaction
472 * @ret rc Return status code
473 */
474 int ( * init ) ( struct http_transaction *http );
475 /** Receive data state */
477};
478
479/** HTTP transfer encoding table */
480#define HTTP_TRANSFER_ENCODINGS \
481 __table ( struct http_transfer_encoding, "http_transfer_encodings" )
482
483/** Declare an HTTP transfer encoding */
484#define __http_transfer_encoding __table_entry ( HTTP_TRANSFER_ENCODINGS, 01 )
485
486/******************************************************************************
487 *
488 * Content encoding
489 *
490 ******************************************************************************
491 */
492
493/** An HTTP content encoding */
495 /** Name */
496 const char *name;
497 /** Check if content encoding is supported for this request
498 *
499 * @v http HTTP transaction
500 * @ret supported Content encoding is supported for this request
501 */
502 int ( * supported ) ( struct http_transaction *http );
503 /** Initialise content encoding
504 *
505 * @v http HTTP transaction
506 * @ret rc Return status code
507 */
508 int ( * init ) ( struct http_transaction *http );
509};
510
511/** HTTP content encoding table */
512#define HTTP_CONTENT_ENCODINGS \
513 __table ( struct http_content_encoding, "http_content_encodings" )
514
515/** Declare an HTTP content encoding */
516#define __http_content_encoding __table_entry ( HTTP_CONTENT_ENCODINGS, 01 )
517
518/******************************************************************************
519 *
520 * Authentication
521 *
522 ******************************************************************************
523 */
524
525/** An HTTP authentication scheme */
527 /** Name (e.g. "Digest") */
528 const char *name;
529 /** Parse remaining "WWW-Authenticate" header line
530 *
531 * @v http HTTP transaction
532 * @v line Remaining header line
533 * @ret rc Return status code
534 */
535 int ( * parse ) ( struct http_transaction *http, char *line );
536 /** Perform authentication
537 *
538 * @v http HTTP transaction
539 * @ret rc Return status code
540 */
541 int ( * authenticate ) ( struct http_transaction *http );
542 /** Construct remaining "Authorization" header line
543 *
544 * @v http HTTP transaction
545 * @v buf Buffer
546 * @v len Length of buffer
547 * @ret len Header length if present, or negative error
548 */
549 int ( * format ) ( struct http_transaction *http, char *buf,
550 size_t len );
551};
552
553/** HTTP authentication scheme table */
554#define HTTP_AUTHENTICATIONS \
555 __table ( struct http_authentication, "http_authentications" )
556
557/** Declare an HTTP authentication scheme */
558#define __http_authentication __table_entry ( HTTP_AUTHENTICATIONS, 01 )
559
560/******************************************************************************
561 *
562 * General
563 *
564 ******************************************************************************
565 */
566
567extern char * http_token ( char **line, char **value );
568extern int http_connect ( struct interface *xfer, struct uri *uri );
569extern int http_open ( struct interface *xfer, struct http_method *method,
570 struct uri *uri, struct http_request_range *range,
572extern int http_open_uri ( struct interface *xfer, struct uri *uri );
573
574#endif /* _IPXE_HTTP_H */
struct arbelprm_rc_send_wqe rc
Definition arbel.h:3
pseudo_bit_t value[0x00020]
Definition arbel.h:2
ring len
Length.
Definition dwmac.h:226
#define FILE_LICENCE(_licence)
Declare a particular licence as applying to a file.
Definition compiler.h:921
#define FILE_SECBOOT(_status)
Declare a file's UEFI Secure Boot permission status.
Definition compiler.h:951
char * http_token(char **line, char **value)
Get HTTP response token.
Definition httpcore.c:219
#define HTTP_DIGEST_CNONCE_LEN
HTTP Digest authentication client nonce length.
Definition http.h:133
http_response_flags
HTTP response flags.
Definition http.h:362
@ HTTP_RESPONSE_CONTENT_LEN
Content length specified.
Definition http.h:366
@ HTTP_RESPONSE_KEEPALIVE
Keep connection alive after close.
Definition http.h:364
@ HTTP_RESPONSE_RETRY
Transaction may be retried on failure.
Definition http.h:368
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:665
#define __http_method
Declare an HTTP method.
Definition http.h:109
int http_open_uri(struct interface *xfer, struct uri *uri)
Open HTTP transaction for simple URI.
Definition httpcore.c:2018
int http_connect(struct interface *xfer, struct uri *uri)
Connect to an HTTP server.
Definition httpconn.c:237
#define HTTP_DIGEST_RESPONSE_LEN
HTTP Digest authentication response length.
Definition http.h:140
uint8_t method
Definition ib_mad.h:3
Object interfaces.
I/O buffers.
Line buffering.
NT LAN Manager (NTLM) authentication.
struct pci_range range
PCI bus:dev.fn address range.
Definition pcicloud.c:40
Pooled connections.
Processes.
Reference counting.
Retry timers.
An HTTP authentication scheme.
Definition http.h:526
int(* format)(struct http_transaction *http, char *buf, size_t len)
Construct remaining "Authorization" header line.
Definition http.h:549
int(* parse)(struct http_transaction *http, char *line)
Parse remaining "WWW-Authenticate" header line.
Definition http.h:535
int(* authenticate)(struct http_transaction *http)
Perform authentication.
Definition http.h:541
const char * name
Name (e.g.
Definition http.h:528
An HTTP connection.
Definition http.h:72
struct interface socket
Transport layer interface.
Definition http.h:85
struct uri * uri
Connection URI.
Definition http.h:81
struct pooled_connection pool
Pooled connection.
Definition http.h:89
struct refcnt refcnt
Reference count.
Definition http.h:74
struct interface xfer
Data transfer interface.
Definition http.h:87
struct http_scheme * scheme
HTTP scheme.
Definition http.h:83
An HTTP content encoding.
Definition http.h:494
int(* supported)(struct http_transaction *http)
Check if content encoding is supported for this request.
Definition http.h:502
int(* init)(struct http_transaction *http)
Initialise content encoding.
Definition http.h:508
const char * name
Name.
Definition http.h:496
An HTTP method.
Definition http.h:100
const char * name
Method name (e.g.
Definition http.h:102
HTTP request Basic authentication descriptor.
Definition http.h:161
const char * username
Username.
Definition http.h:163
const char * password
Password.
Definition http.h:165
HTTP request Digest authentication descriptor.
Definition http.h:169
char cnonce[HTTP_DIGEST_CNONCE_LEN+1]
Client nonce.
Definition http.h:177
const char * qop
Quality of protection.
Definition http.h:173
char response[HTTP_DIGEST_RESPONSE_LEN+1]
Response.
Definition http.h:179
const char * algorithm
Algorithm.
Definition http.h:175
const char * username
Username.
Definition http.h:171
HTTP request NTLM authentication descriptor.
Definition http.h:183
struct ntlm_lm_response lm
LAN Manager response.
Definition http.h:187
size_t len
Authenticate message length.
Definition http.h:191
struct ntlm_nt_response nt
NT response.
Definition http.h:189
const char * username
Username.
Definition http.h:185
HTTP request authentication descriptor.
Definition http.h:195
struct http_authentication * auth
Authentication scheme (if any).
Definition http.h:197
struct http_request_auth_digest digest
Digest authentication descriptor.
Definition http.h:203
struct http_request_auth_ntlm ntlm
NTLM authentication descriptor.
Definition http.h:205
struct http_request_auth_basic basic
Basic authentication descriptor.
Definition http.h:201
HTTP request content descriptor.
Definition http.h:151
size_t len
Content length.
Definition http.h:157
const void * data
Content data (if any).
Definition http.h:155
const char * type
Content type (if any).
Definition http.h:153
An HTTP request header.
Definition http.h:234
int(* format)(struct http_transaction *http, char *buf, size_t len)
Construct remaining header line.
Definition http.h:244
const char * name
Header name (e.g.
Definition http.h:236
HTTP request range descriptor.
Definition http.h:143
size_t start
Range start.
Definition http.h:145
size_t len
Range length, or zero for no range request.
Definition http.h:147
An HTTP request.
Definition http.h:218
struct http_request_range range
Range descriptor.
Definition http.h:226
const char * host
Server host name.
Definition http.h:224
struct http_request_auth auth
Authentication descriptor.
Definition http.h:230
struct http_method * method
Method.
Definition http.h:220
const char * uri
Request URI string.
Definition http.h:222
struct http_request_content content
Content descriptor.
Definition http.h:228
HTTP response Basic authorization descriptor.
Definition http.h:277
HTTP response Digest authorization descriptor.
Definition http.h:281
const char * nonce
Nonce.
Definition http.h:289
const char * realm
Realm.
Definition http.h:283
const char * opaque
Opaque.
Definition http.h:291
const char * algorithm
Algorithm.
Definition http.h:287
const char * qop
Quality of protection.
Definition http.h:285
HTTP response NTLM authorization descriptor.
Definition http.h:295
struct ntlm_challenge * challenge
Challenge message.
Definition http.h:297
struct ntlm_challenge_info info
Challenge information.
Definition http.h:299
HTTP response authorization descriptor.
Definition http.h:303
struct http_response_auth_ntlm ntlm
NTLM authorization descriptor.
Definition http.h:313
struct http_response_auth_basic basic
Basic authorization descriptor.
Definition http.h:309
struct http_authentication * auth
Authentication scheme (if any).
Definition http.h:305
struct http_response_auth_digest digest
Digest authorization descriptor.
Definition http.h:311
HTTP response content descriptor.
Definition http.h:269
size_t len
Content length (may be zero).
Definition http.h:271
struct http_content_encoding * encoding
Content encoding.
Definition http.h:273
An HTTP response header.
Definition http.h:372
const char * name
Header name (e.g.
Definition http.h:374
int(* parse)(struct http_transaction *http, char *line)
Parse header line.
Definition http.h:381
HTTP response transfer descriptor.
Definition http.h:263
struct http_transfer_encoding * encoding
Transfer encoding.
Definition http.h:265
An HTTP response.
Definition http.h:326
unsigned int flags
Flags.
Definition http.h:358
struct http_response_content content
Content descriptor.
Definition http.h:352
struct http_response_auth auth
Authorization descriptor.
Definition http.h:354
unsigned int retry_after
Retry delay (in seconds).
Definition http.h:356
unsigned int status
Status code.
Definition http.h:340
struct line_buffer headers
Raw response header lines.
Definition http.h:335
int rc
Return status code.
Definition http.h:346
const char * location
Redirection location.
Definition http.h:348
struct http_response_transfer transfer
Transfer descriptor.
Definition http.h:350
An HTTP URI scheme.
Definition http.h:41
unsigned int port
Default port.
Definition http.h:45
int(* filter)(struct http_connection *conn)
Transport-layer filter (if any).
Definition http.h:51
const char * name
Scheme name (e.g.
Definition http.h:43
HTTP transaction state.
Definition http.h:399
int(* tx)(struct http_transaction *http)
Transmit data.
Definition http.h:405
void(* close)(struct http_transaction *http, int rc)
Server connection closed.
Definition http.h:419
int(* rx)(struct http_transaction *http, struct io_buffer **iobuf)
Receive data.
Definition http.h:412
An HTTP transaction.
Definition http.h:423
struct refcnt refcnt
Reference count.
Definition http.h:425
struct retry_timer watchdog
Idle connection watchdog timer.
Definition http.h:439
size_t remaining
Chunk length remaining.
Definition http.h:455
struct http_response response
Response.
Definition http.h:446
struct process process
Transmit process.
Definition http.h:435
struct retry_timer retry
Reconnection timer.
Definition http.h:437
size_t len
Accumulated transfer-decoded length.
Definition http.h:453
struct uri * uri
Request URI.
Definition http.h:442
struct interface conn
Server connection.
Definition http.h:433
struct line_buffer linebuf
Temporary line buffer.
Definition http.h:448
struct interface transfer
Transfer-decoded interface.
Definition http.h:431
struct interface content
Content-decoded interface.
Definition http.h:429
struct http_request request
Request.
Definition http.h:444
struct interface xfer
Data transfer interface.
Definition http.h:427
struct http_state * state
Transaction state.
Definition http.h:451
An HTTP transfer encoding.
Definition http.h:466
struct http_state state
Receive data state.
Definition http.h:476
int(* init)(struct http_transaction *http)
Initialise transfer encoding.
Definition http.h:474
const char * name
Name.
Definition http.h:468
An object interface.
Definition interface.h:125
A persistent I/O buffer.
Definition iobuf.h:38
A line buffer.
Definition linebuf.h:17
NTLM challenge information.
Definition ntlm.h:166
A Challenge message.
Definition ntlm.h:101
A LAN Manager response.
Definition ntlm.h:137
An NT response.
Definition ntlm.h:145
A pooled connection.
Definition pool.h:18
A retry timer.
Definition retry.h:22
A Uniform Resource Identifier.
Definition uri.h:65
Linker tables.