]> git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Include/Protocol/Http.h
MdePkg/Http.h: Refine the coding style.
[mirror_edk2.git] / MdePkg / Include / Protocol / Http.h
1 /** @file
2 This file defines the EFI HTTP Protocol interface. It is split into
3 the following two main sections:
4 HTTP Service Binding Protocol (HTTPSB)
5 HTTP Protocol (HTTP)
6
7 Copyright (c) 2016 - 2017, Intel Corporation. All rights reserved.<BR>
8 (C) Copyright 2015-2017 Hewlett Packard Enterprise Development LP<BR>
9 This program and the accompanying materials
10 are licensed and made available under the terms and conditions of the BSD License
11 which accompanies this distribution. The full text of the license may be found at
12 http://opensource.org/licenses/bsd-license.php
13
14 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
15 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
16
17 @par Revision Reference:
18 This Protocol is introduced in UEFI Specification 2.5
19
20 **/
21
22 #ifndef __EFI_HTTP_PROTOCOL_H__
23 #define __EFI_HTTP_PROTOCOL_H__
24
25 #define EFI_HTTP_SERVICE_BINDING_PROTOCOL_GUID \
26 { \
27 0xbdc8e6af, 0xd9bc, 0x4379, {0xa7, 0x2a, 0xe0, 0xc4, 0xe7, 0x5d, 0xae, 0x1c } \
28 }
29
30 #define EFI_HTTP_PROTOCOL_GUID \
31 { \
32 0x7a59b29b, 0x910b, 0x4171, {0x82, 0x42, 0xa8, 0x5a, 0x0d, 0xf2, 0x5b, 0x5b } \
33 }
34
35 typedef struct _EFI_HTTP_PROTOCOL EFI_HTTP_PROTOCOL;
36
37 ///
38 /// EFI_HTTP_VERSION
39 ///
40 typedef enum {
41 HttpVersion10,
42 HttpVersion11,
43 HttpVersionUnsupported
44 } EFI_HTTP_VERSION;
45
46 ///
47 /// EFI_HTTP_METHOD
48 ///
49 typedef enum {
50 HttpMethodGet,
51 HttpMethodPost,
52 HttpMethodPatch,
53 HttpMethodOptions,
54 HttpMethodConnect,
55 HttpMethodHead,
56 HttpMethodPut,
57 HttpMethodDelete,
58 HttpMethodTrace,
59 HttpMethodMax
60 } EFI_HTTP_METHOD;
61
62 ///
63 /// EFI_HTTP_STATUS_CODE
64 ///
65 typedef enum {
66 HTTP_STATUS_UNSUPPORTED_STATUS = 0,
67 HTTP_STATUS_100_CONTINUE,
68 HTTP_STATUS_101_SWITCHING_PROTOCOLS,
69 HTTP_STATUS_200_OK,
70 HTTP_STATUS_201_CREATED,
71 HTTP_STATUS_202_ACCEPTED,
72 HTTP_STATUS_203_NON_AUTHORITATIVE_INFORMATION,
73 HTTP_STATUS_204_NO_CONTENT,
74 HTTP_STATUS_205_RESET_CONTENT,
75 HTTP_STATUS_206_PARTIAL_CONTENT,
76 HTTP_STATUS_300_MULTIPLE_CHIOCES,
77 HTTP_STATUS_301_MOVED_PERMANENTLY,
78 HTTP_STATUS_302_FOUND,
79 HTTP_STATUS_303_SEE_OTHER,
80 HTTP_STATUS_304_NOT_MODIFIED,
81 HTTP_STATUS_305_USE_PROXY,
82 HTTP_STATUS_307_TEMPORARY_REDIRECT,
83 HTTP_STATUS_400_BAD_REQUEST,
84 HTTP_STATUS_401_UNAUTHORIZED,
85 HTTP_STATUS_402_PAYMENT_REQUIRED,
86 HTTP_STATUS_403_FORBIDDEN,
87 HTTP_STATUS_404_NOT_FOUND,
88 HTTP_STATUS_405_METHOD_NOT_ALLOWED,
89 HTTP_STATUS_406_NOT_ACCEPTABLE,
90 HTTP_STATUS_407_PROXY_AUTHENTICATION_REQUIRED,
91 HTTP_STATUS_408_REQUEST_TIME_OUT,
92 HTTP_STATUS_409_CONFLICT,
93 HTTP_STATUS_410_GONE,
94 HTTP_STATUS_411_LENGTH_REQUIRED,
95 HTTP_STATUS_412_PRECONDITION_FAILED,
96 HTTP_STATUS_413_REQUEST_ENTITY_TOO_LARGE,
97 HTTP_STATUS_414_REQUEST_URI_TOO_LARGE,
98 HTTP_STATUS_415_UNSUPPORTED_MEDIA_TYPE,
99 HTTP_STATUS_416_REQUESTED_RANGE_NOT_SATISFIED,
100 HTTP_STATUS_417_EXPECTATION_FAILED,
101 HTTP_STATUS_500_INTERNAL_SERVER_ERROR,
102 HTTP_STATUS_501_NOT_IMPLEMENTED,
103 HTTP_STATUS_502_BAD_GATEWAY,
104 HTTP_STATUS_503_SERVICE_UNAVAILABLE,
105 HTTP_STATUS_504_GATEWAY_TIME_OUT,
106 HTTP_STATUS_505_HTTP_VERSION_NOT_SUPPORTED,
107 HTTP_STATUS_308_PERMANENT_REDIRECT
108 } EFI_HTTP_STATUS_CODE;
109
110 ///
111 /// EFI_HTTPv4_ACCESS_POINT
112 ///
113 typedef struct {
114 ///
115 /// Set to TRUE to instruct the EFI HTTP instance to use the default address
116 /// information in every TCP connection made by this instance. In addition, when set
117 /// to TRUE, LocalAddress and LocalSubnet are ignored.
118 ///
119 BOOLEAN UseDefaultAddress;
120 ///
121 /// If UseDefaultAddress is set to FALSE, this defines the local IP address to be
122 /// used in every TCP connection opened by this instance.
123 ///
124 EFI_IPv4_ADDRESS LocalAddress;
125 ///
126 /// If UseDefaultAddress is set to FALSE, this defines the local subnet to be used
127 /// in every TCP connection opened by this instance.
128 ///
129 EFI_IPv4_ADDRESS LocalSubnet;
130 ///
131 /// This defines the local port to be used in
132 /// every TCP connection opened by this instance.
133 ///
134 UINT16 LocalPort;
135 } EFI_HTTPv4_ACCESS_POINT;
136
137 ///
138 /// EFI_HTTPv6_ACCESS_POINT
139 ///
140 typedef struct {
141 ///
142 /// Local IP address to be used in every TCP connection opened by this instance.
143 ///
144 EFI_IPv6_ADDRESS LocalAddress;
145 ///
146 /// Local port to be used in every TCP connection opened by this instance.
147 ///
148 UINT16 LocalPort;
149 } EFI_HTTPv6_ACCESS_POINT;
150
151 ///
152 /// EFI_HTTP_CONFIG_DATA_ACCESS_POINT
153 ///
154
155
156 typedef struct {
157 ///
158 /// HTTP version that this instance will support.
159 ///
160 EFI_HTTP_VERSION HttpVersion;
161 ///
162 /// Time out (in milliseconds) when blocking for requests.
163 ///
164 UINT32 TimeOutMillisec;
165 ///
166 /// Defines behavior of EFI DNS and TCP protocols consumed by this instance. If
167 /// FALSE, this instance will use EFI_DNS4_PROTOCOL and EFI_TCP4_PROTOCOL. If TRUE,
168 /// this instance will use EFI_DNS6_PROTOCOL and EFI_TCP6_PROTOCOL.
169 ///
170 BOOLEAN LocalAddressIsIPv6;
171
172 union {
173 ///
174 /// When LocalAddressIsIPv6 is FALSE, this points to the local address, subnet, and
175 /// port used by the underlying TCP protocol.
176 ///
177 EFI_HTTPv4_ACCESS_POINT *IPv4Node;
178 ///
179 /// When LocalAddressIsIPv6 is TRUE, this points to the local IPv6 address and port
180 /// used by the underlying TCP protocol.
181 ///
182 EFI_HTTPv6_ACCESS_POINT *IPv6Node;
183 } AccessPoint;
184 } EFI_HTTP_CONFIG_DATA;
185
186 ///
187 /// EFI_HTTP_REQUEST_DATA
188 ///
189 typedef struct {
190 ///
191 /// The HTTP method (e.g. GET, POST) for this HTTP Request.
192 ///
193 EFI_HTTP_METHOD Method;
194 ///
195 /// The URI of a remote host. From the information in this field, the HTTP instance
196 /// will be able to determine whether to use HTTP or HTTPS and will also be able to
197 /// determine the port number to use. If no port number is specified, port 80 (HTTP)
198 /// is assumed. See RFC 3986 for more details on URI syntax.
199 ///
200 CHAR16 *Url;
201 } EFI_HTTP_REQUEST_DATA;
202
203 ///
204 /// EFI_HTTP_RESPONSE_DATA
205 ///
206 typedef struct {
207 ///
208 /// Response status code returned by the remote host.
209 ///
210 EFI_HTTP_STATUS_CODE StatusCode;
211 } EFI_HTTP_RESPONSE_DATA;
212
213 ///
214 /// EFI_HTTP_HEADER
215 ///
216 typedef struct {
217 ///
218 /// Null terminated string which describes a field name. See RFC 2616 Section 14 for
219 /// detailed information about field names.
220 ///
221 CHAR8 *FieldName;
222 ///
223 /// Null terminated string which describes the corresponding field value. See RFC 2616
224 /// Section 14 for detailed information about field values.
225 ///
226 CHAR8 *FieldValue;
227 } EFI_HTTP_HEADER;
228
229 ///
230 /// EFI_HTTP_MESSAGE
231 ///
232 typedef struct {
233 ///
234 /// HTTP message data.
235 ///
236 union {
237 ///
238 /// When the token is used to send a HTTP request, Request is a pointer to storage that
239 /// contains such data as URL and HTTP method.
240 ///
241 EFI_HTTP_REQUEST_DATA *Request;
242 ///
243 /// When used to await a response, Response points to storage containing HTTP response
244 /// status code.
245 ///
246 EFI_HTTP_RESPONSE_DATA *Response;
247 } Data;
248 ///
249 /// Number of HTTP header structures in Headers list. On request, this count is
250 /// provided by the caller. On response, this count is provided by the HTTP driver.
251 ///
252 UINTN HeaderCount;
253 ///
254 /// Array containing list of HTTP headers. On request, this array is populated by the
255 /// caller. On response, this array is allocated and populated by the HTTP driver. It
256 /// is the responsibility of the caller to free this memory on both request and
257 /// response.
258 ///
259 EFI_HTTP_HEADER *Headers;
260 ///
261 /// Length in bytes of the HTTP body. This can be zero depending on the HttpMethod type.
262 ///
263 UINTN BodyLength;
264 ///
265 /// Body associated with the HTTP request or response. This can be NULL depending on
266 /// the HttpMethod type.
267 ///
268 VOID *Body;
269 } EFI_HTTP_MESSAGE;
270
271
272 ///
273 /// EFI_HTTP_TOKEN
274 ///
275 typedef struct {
276 ///
277 /// This Event will be signaled after the Status field is updated by the EFI HTTP
278 /// Protocol driver. The type of Event must be EFI_NOTIFY_SIGNAL. The Task Priority
279 /// Level (TPL) of Event must be lower than or equal to TPL_CALLBACK.
280 ///
281 EFI_EVENT Event;
282 ///
283 /// Status will be set to one of the following value if the HTTP request is
284 /// successfully sent or if an unexpected error occurs:
285 /// EFI_SUCCESS: The HTTP request was successfully sent to the remote host.
286 /// EFI_HTTP_ERROR: The response message was successfully received but contains a
287 /// HTTP error. The response status code is returned in token.
288 /// EFI_ABORTED: The HTTP request was cancelled by the caller and removed from
289 /// the transmit queue.
290 /// EFI_TIMEOUT: The HTTP request timed out before reaching the remote host.
291 /// EFI_DEVICE_ERROR: An unexpected system or network error occurred.
292 ///
293 EFI_STATUS Status;
294 ///
295 /// Pointer to storage containing HTTP message data.
296 ///
297 EFI_HTTP_MESSAGE *Message;
298 } EFI_HTTP_TOKEN;
299
300 /**
301 Returns the operational parameters for the current HTTP child instance.
302
303 The GetModeData() function is used to read the current mode data (operational
304 parameters) for this HTTP protocol instance.
305
306 @param[in] This Pointer to EFI_HTTP_PROTOCOL instance.
307 @param[out] HttpConfigData Point to buffer for operational parameters of this
308 HTTP instance.
309
310 @retval EFI_SUCCESS Operation succeeded.
311 @retval EFI_INVALID_PARAMETER This is NULL.
312 HttpConfigData is NULL.
313 HttpInstance->LocalAddressIsIPv6 is FALSE and
314 HttpConfigData->IPv4Node is NULL.
315 HttpInstance->LocalAddressIsIPv6 is TRUE and
316 HttpConfigData->IPv6Node is NULL.
317 @retval EFI_NOT_STARTED This EFI HTTP Protocol instance has not been started.
318 **/
319 typedef
320 EFI_STATUS
321 (EFIAPI *EFI_HTTP_GET_MODE_DATA)(
322 IN EFI_HTTP_PROTOCOL *This,
323 OUT EFI_HTTP_CONFIG_DATA *HttpConfigData
324 );
325
326 /**
327 Initialize or brutally reset the operational parameters for this EFI HTTP instance.
328
329 The Configure() function does the following:
330 When HttpConfigData is not NULL Initialize this EFI HTTP instance by configuring
331 timeout, local address, port, etc.
332 When HttpConfigData is NULL, reset this EFI HTTP instance by closing all active
333 connections with remote hosts, canceling all asynchronous tokens, and flush request
334 and response buffers without informing the appropriate hosts.
335
336 No other EFI HTTP function can be executed by this instance until the Configure()
337 function is executed and returns successfully.
338
339 @param[in] This Pointer to EFI_HTTP_PROTOCOL instance.
340 @param[in] HttpConfigData Pointer to the configure data to configure the instance.
341
342 @retval EFI_SUCCESS Operation succeeded.
343 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
344 This is NULL.
345 HttpConfigData->LocalAddressIsIPv6 is FALSE and
346 HttpConfigData->IPv4Node is NULL.
347 HttpConfigData->LocalAddressIsIPv6 is TRUE and
348 HttpConfigData->IPv6Node is NULL.
349 @retval EFI_ALREADY_STARTED Reinitialize this HTTP instance without calling
350 Configure() with NULL to reset it.
351 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
352 @retval EFI_OUT_OF_RESOURCES Could not allocate enough system resources when
353 executing Configure().
354 @retval EFI_UNSUPPORTED One or more options in ConfigData are not supported
355 in the implementation.
356 **/
357 typedef
358 EFI_STATUS
359 (EFIAPI *EFI_HTTP_CONFIGURE)(
360 IN EFI_HTTP_PROTOCOL *This,
361 IN EFI_HTTP_CONFIG_DATA *HttpConfigData OPTIONAL
362 );
363
364 /**
365 The Request() function queues an HTTP request to this HTTP instance,
366 similar to Transmit() function in the EFI TCP driver. When the HTTP request is sent
367 successfully, or if there is an error, Status in token will be updated and Event will
368 be signaled.
369
370 @param[in] This Pointer to EFI_HTTP_PROTOCOL instance.
371 @param[in] Token Pointer to storage containing HTTP request token.
372
373 @retval EFI_SUCCESS Outgoing data was processed.
374 @retval EFI_NOT_STARTED This EFI HTTP Protocol instance has not been started.
375 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
376 @retval EFI_TIMEOUT Data was dropped out of the transmit or receive queue.
377 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
378 This is NULL.
379 Token is NULL.
380 Token->Message is NULL.
381 Token->Message->Body is not NULL,
382 Token->Message->BodyLength is non-zero, and
383 Token->Message->Data is NULL, but a previous call to
384 Request()has not been completed successfully.
385 @retval EFI_OUT_OF_RESOURCES Could not allocate enough system resources.
386 @retval EFI_UNSUPPORTED The HTTP method is not supported in current implementation.
387 **/
388 typedef
389 EFI_STATUS
390 (EFIAPI *EFI_HTTP_REQUEST) (
391 IN EFI_HTTP_PROTOCOL *This,
392 IN EFI_HTTP_TOKEN *Token
393 );
394
395 /**
396 Abort an asynchronous HTTP request or response token.
397
398 The Cancel() function aborts a pending HTTP request or response transaction. If
399 Token is not NULL and the token is in transmit or receive queues when it is being
400 cancelled, its Token->Status will be set to EFI_ABORTED and then Token->Event will
401 be signaled. If the token is not in one of the queues, which usually means that the
402 asynchronous operation has completed, EFI_NOT_FOUND is returned. If Token is NULL,
403 all asynchronous tokens issued by Request() or Response() will be aborted.
404
405 @param[in] This Pointer to EFI_HTTP_PROTOCOL instance.
406 @param[in] Token Point to storage containing HTTP request or response
407 token.
408
409 @retval EFI_SUCCESS Request and Response queues are successfully flushed.
410 @retval EFI_INVALID_PARAMETER This is NULL.
411 @retval EFI_NOT_STARTED This instance hasn't been configured.
412 @retval EFI_NOT_FOUND The asynchronous request or response token is not
413 found.
414 @retval EFI_UNSUPPORTED The implementation does not support this function.
415 **/
416 typedef
417 EFI_STATUS
418 (EFIAPI *EFI_HTTP_CANCEL)(
419 IN EFI_HTTP_PROTOCOL *This,
420 IN EFI_HTTP_TOKEN *Token
421 );
422
423 /**
424 The Response() function queues an HTTP response to this HTTP instance, similar to
425 Receive() function in the EFI TCP driver. When the HTTP Response is received successfully,
426 or if there is an error, Status in token will be updated and Event will be signaled.
427
428 The HTTP driver will queue a receive token to the underlying TCP instance. When data
429 is received in the underlying TCP instance, the data will be parsed and Token will
430 be populated with the response data. If the data received from the remote host
431 contains an incomplete or invalid HTTP header, the HTTP driver will continue waiting
432 (asynchronously) for more data to be sent from the remote host before signaling
433 Event in Token.
434
435 It is the responsibility of the caller to allocate a buffer for Body and specify the
436 size in BodyLength. If the remote host provides a response that contains a content
437 body, up to BodyLength bytes will be copied from the receive buffer into Body and
438 BodyLength will be updated with the amount of bytes received and copied to Body. This
439 allows the client to download a large file in chunks instead of into one contiguous
440 block of memory. Similar to HTTP request, if Body is not NULL and BodyLength is
441 non-zero and all other fields are NULL or 0, the HTTP driver will queue a receive
442 token to underlying TCP instance. If data arrives in the receive buffer, up to
443 BodyLength bytes of data will be copied to Body. The HTTP driver will then update
444 BodyLength with the amount of bytes received and copied to Body.
445
446 If the HTTP driver does not have an open underlying TCP connection with the host
447 specified in the response URL, Request() will return EFI_ACCESS_DENIED. This is
448 consistent with RFC 2616 recommendation that HTTP clients should attempt to maintain
449 an open TCP connection between client and host.
450
451 @param[in] This Pointer to EFI_HTTP_PROTOCOL instance.
452 @param[in] Token Pointer to storage containing HTTP response token.
453
454 @retval EFI_SUCCESS Allocation succeeded.
455 @retval EFI_NOT_STARTED This EFI HTTP Protocol instance has not been
456 initialized.
457 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
458 This is NULL.
459 Token is NULL.
460 Token->Message->Headers is NULL.
461 Token->Message is NULL.
462 Token->Message->Body is not NULL,
463 Token->Message->BodyLength is non-zero, and
464 Token->Message->Data is NULL, but a previous call to
465 Response() has not been completed successfully.
466 @retval EFI_OUT_OF_RESOURCES Could not allocate enough system resources.
467 @retval EFI_ACCESS_DENIED An open TCP connection is not present with the host
468 specified by response URL.
469 **/
470 typedef
471 EFI_STATUS
472 (EFIAPI *EFI_HTTP_RESPONSE) (
473 IN EFI_HTTP_PROTOCOL *This,
474 IN EFI_HTTP_TOKEN *Token
475 );
476
477 /**
478 The Poll() function can be used by network drivers and applications to increase the
479 rate that data packets are moved between the communication devices and the transmit
480 and receive queues.
481
482 In some systems, the periodic timer event in the managed network driver may not poll
483 the underlying communications device fast enough to transmit and/or receive all data
484 packets without missing incoming packets or dropping outgoing packets. Drivers and
485 applications that are experiencing packet loss should try calling the Poll() function
486 more often.
487
488 @param[in] This Pointer to EFI_HTTP_PROTOCOL instance.
489
490 @retval EFI_SUCCESS Incoming or outgoing data was processed..
491 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred
492 @retval EFI_INVALID_PARAMETER This is NULL.
493 @retval EFI_NOT_READY No incoming or outgoing data is processed.
494 @retval EFI_NOT_STARTED This EFI HTTP Protocol instance has not been started.
495 **/
496 typedef
497 EFI_STATUS
498 (EFIAPI *EFI_HTTP_POLL) (
499 IN EFI_HTTP_PROTOCOL *This
500 );
501
502 ///
503 /// The EFI HTTP protocol is designed to be used by EFI drivers and applications to
504 /// create and transmit HTTP Requests, as well as handle HTTP responses that are
505 /// returned by a remote host. This EFI protocol uses and relies on an underlying EFI
506 /// TCP protocol.
507 ///
508 struct _EFI_HTTP_PROTOCOL {
509 EFI_HTTP_GET_MODE_DATA GetModeData;
510 EFI_HTTP_CONFIGURE Configure;
511 EFI_HTTP_REQUEST Request;
512 EFI_HTTP_CANCEL Cancel;
513 EFI_HTTP_RESPONSE Response;
514 EFI_HTTP_POLL Poll;
515 };
516
517 extern EFI_GUID gEfiHttpServiceBindingProtocolGuid;
518 extern EFI_GUID gEfiHttpProtocolGuid;
519
520 #endif