38228425bb5092b3c39e5ee2164798aaecdc52e4
[mirror_edk2.git] / NetworkPkg / HttpDxe / HttpImpl.h
1 /** @file
2 The header files of implementation of EFI_HTTP_PROTOCOL protocol interfaces.
3
4 Copyright (c) 2015 - 2016, Intel Corporation. All rights reserved.<BR>
5
6 This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php.
10
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
13
14 **/
15
16 #ifndef __EFI_HTTP_IMPL_H__
17 #define __EFI_HTTP_IMPL_H__
18
19 #define HTTP_DEFAULT_PORT 80
20 #define HTTP_END_OF_HDR_STR "\r\n\r\n"
21 #define HTTP_CRLF_STR "\r\n"
22 #define HTTP_VERSION_STR "HTTP/1.1"
23 #define HTTP_VERSION_CRLF_STR " HTTP/1.1\r\n"
24 #define HTTP_GET_STR "GET "
25 #define HTTP_HEAD_STR "HEAD "
26 #define HTTP_ERROR_OR_NOT_SUPPORT_STATUS_CODE 300
27
28 //
29 // Connect method has maximum length according to EFI_HTTP_METHOD defined in
30 // UEFI2.5 spec so use this.
31 //
32 #define HTTP_MAXIMUM_METHOD_LEN sizeof ("CONNECT")
33
34 /**
35 Returns the operational parameters for the current HTTP child instance.
36
37 The GetModeData() function is used to read the current mode data (operational
38 parameters) for this HTTP protocol instance.
39
40 @param[in] This Pointer to EFI_HTTP_PROTOCOL instance.
41 @param[out] HttpConfigData Point to buffer for operational parameters of this
42 HTTP instance.
43
44 @retval EFI_SUCCESS Operation succeeded.
45 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
46 This is NULL.
47 HttpConfigData is NULL.
48 HttpInstance->LocalAddressIsIPv6 is FALSE and
49 HttpConfigData->IPv4Node is NULL.
50 HttpInstance->LocalAddressIsIPv6 is TRUE and
51 HttpConfigData->IPv6Node is NULL.
52 @retval EFI_NOT_STARTED This EFI HTTP Protocol instance has not been started.
53
54 **/
55 EFI_STATUS
56 EFIAPI
57 EfiHttpGetModeData (
58 IN EFI_HTTP_PROTOCOL *This,
59 OUT EFI_HTTP_CONFIG_DATA *HttpConfigData
60 );
61
62 /**
63 Initialize or brutally reset the operational parameters for this EFI HTTP instance.
64
65 The Configure() function does the following:
66 When HttpConfigData is not NULL Initialize this EFI HTTP instance by configuring
67 timeout, local address, port, etc.
68 When HttpConfigData is NULL, reset this EFI HTTP instance by closing all active
69 connections with remote hosts, canceling all asynchronous tokens, and flush request
70 and response buffers without informing the appropriate hosts.
71
72 No other EFI HTTP function can be executed by this instance until the Configure()
73 function is executed and returns successfully.
74
75 @param[in] This Pointer to EFI_HTTP_PROTOCOL instance.
76 @param[in] HttpConfigData Pointer to the configure data to configure the instance.
77
78 @retval EFI_SUCCESS Operation succeeded.
79 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
80 This is NULL.
81 HttpConfigData is NULL.
82 HttpConfigData->LocalAddressIsIPv6 is FALSE and
83 HttpConfigData->IPv4Node is NULL.
84 HttpConfigData->LocalAddressIsIPv6 is TRUE and
85 HttpConfigData->IPv6Node is NULL.
86 @retval EFI_ALREADY_STARTED Reinitialize this HTTP instance without calling
87 Configure() with NULL to reset it.
88 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
89 @retval EFI_OUT_OF_RESOURCES Could not allocate enough system resources when
90 executing Configure().
91 @retval EFI_UNSUPPORTED One or more options in ConfigData are not supported
92 in the implementation.
93 **/
94 EFI_STATUS
95 EFIAPI
96 EfiHttpConfigure (
97 IN EFI_HTTP_PROTOCOL *This,
98 IN EFI_HTTP_CONFIG_DATA *HttpConfigData
99 );
100
101 /**
102 The Request() function queues an HTTP request to this HTTP instance.
103
104 Similar to Transmit() function in the EFI TCP driver. When the HTTP request is sent
105 successfully, or if there is an error, Status in token will be updated and Event will
106 be signaled.
107
108 @param[in] This Pointer to EFI_HTTP_PROTOCOL instance.
109 @param[in] Token Pointer to storage containing HTTP request token.
110
111 @retval EFI_SUCCESS Outgoing data was processed.
112 @retval EFI_NOT_STARTED This EFI HTTP Protocol instance has not been started.
113 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
114 @retval EFI_TIMEOUT Data was dropped out of the transmit or receive queue.
115 @retval EFI_OUT_OF_RESOURCES Could not allocate enough system resources.
116 @retval EFI_UNSUPPORTED The HTTP method is not supported in current
117 implementation.
118 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
119 This is NULL.
120 Token is NULL.
121 Token->Message is NULL.
122 Token->Message->Body is not NULL,
123 Token->Message->BodyLength is non-zero, and
124 Token->Message->Data is NULL, but a previous call to
125 Request()has not been completed successfully.
126 **/
127 EFI_STATUS
128 EFIAPI
129 EfiHttpRequest (
130 IN EFI_HTTP_PROTOCOL *This,
131 IN EFI_HTTP_TOKEN *Token
132 );
133
134 /**
135 Abort an asynchronous HTTP request or response token.
136
137 The Cancel() function aborts a pending HTTP request or response transaction. If
138 Token is not NULL and the token is in transmit or receive queues when it is being
139 cancelled, its Token->Status will be set to EFI_ABORTED and then Token->Event will
140 be signaled. If the token is not in one of the queues, which usually means that the
141 asynchronous operation has completed, EFI_NOT_FOUND is returned. If Token is NULL,
142 all asynchronous tokens issued by Request() or Response() will be aborted.
143
144 @param[in] This Pointer to EFI_HTTP_PROTOCOL instance.
145 @param[in] Token Point to storage containing HTTP request or response
146 token.
147
148 @retval EFI_SUCCESS Request and Response queues are successfully flushed.
149 @retval EFI_INVALID_PARAMETER This is NULL.
150 @retval EFI_NOT_STARTED This instance hasn't been configured.
151 @retval EFI_NOT_FOUND The asynchronous request or response token is not
152 found.
153 @retval EFI_UNSUPPORTED The implementation does not support this function.
154 **/
155 EFI_STATUS
156 EFIAPI
157 EfiHttpCancel (
158 IN EFI_HTTP_PROTOCOL *This,
159 IN EFI_HTTP_TOKEN *Token
160 );
161
162 /**
163 The Response() function queues an HTTP response to this HTTP instance, similar to
164 Receive() function in the EFI TCP driver. When the HTTP response is received successfully,
165 or if there is an error, Status in token will be updated and Event will be signaled.
166
167 The HTTP driver will queue a receive token to the underlying TCP instance. When data
168 is received in the underlying TCP instance, the data will be parsed and Token will
169 be populated with the response data. If the data received from the remote host
170 contains an incomplete or invalid HTTP header, the HTTP driver will continue waiting
171 (asynchronously) for more data to be sent from the remote host before signaling
172 Event in Token.
173
174 It is the responsibility of the caller to allocate a buffer for Body and specify the
175 size in BodyLength. If the remote host provides a response that contains a content
176 body, up to BodyLength bytes will be copied from the receive buffer into Body and
177 BodyLength will be updated with the amount of bytes received and copied to Body. This
178 allows the client to download a large file in chunks instead of into one contiguous
179 block of memory. Similar to HTTP request, if Body is not NULL and BodyLength is
180 non-zero and all other fields are NULL or 0, the HTTP driver will queue a receive
181 token to underlying TCP instance. If data arrives in the receive buffer, up to
182 BodyLength bytes of data will be copied to Body. The HTTP driver will then update
183 BodyLength with the amount of bytes received and copied to Body.
184
185 If the HTTP driver does not have an open underlying TCP connection with the host
186 specified in the response URL, Request() will return EFI_ACCESS_DENIED. This is
187 consistent with RFC 2616 recommendation that HTTP clients should attempt to maintain
188 an open TCP connection between client and host.
189
190 @param[in] This Pointer to EFI_HTTP_PROTOCOL instance.
191 @param[in] Token Pointer to storage containing HTTP response token.
192
193 @retval EFI_SUCCESS Allocation succeeded.
194 @retval EFI_NOT_STARTED This EFI HTTP Protocol instance has not been
195 initialized.
196 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
197 This is NULL.
198 Token is NULL.
199 Token->Message->Headers is NULL.
200 Token->Message is NULL.
201 Token->Message->Body is not NULL,
202 Token->Message->BodyLength is non-zero, and
203 Token->Message->Data is NULL, but a previous call to
204 Response() has not been completed successfully.
205 @retval EFI_OUT_OF_RESOURCES Could not allocate enough system resources.
206 @retval EFI_ACCESS_DENIED An open TCP connection is not present with the host
207 specified by response URL.
208 **/
209 EFI_STATUS
210 EFIAPI
211 EfiHttpResponse (
212 IN EFI_HTTP_PROTOCOL *This,
213 IN EFI_HTTP_TOKEN *Token
214 );
215
216 /**
217 The Poll() function can be used by network drivers and applications to increase the
218 rate that data packets are moved between the communication devices and the transmit
219 and receive queues.
220
221 In some systems, the periodic timer event in the managed network driver may not poll
222 the underlying communications device fast enough to transmit and/or receive all data
223 packets without missing incoming packets or dropping outgoing packets. Drivers and
224 applications that are experiencing packet loss should try calling the Poll() function
225 more often.
226
227 @param[in] This Pointer to EFI_HTTP_PROTOCOL instance.
228
229 @retval EFI_SUCCESS Incoming or outgoing data was processed.
230 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
231 @retval EFI_INVALID_PARAMETER This is NULL.
232 @retval EFI_NOT_READY No incoming or outgoing data is processed.
233 @retval EFI_NOT_STARTED This EFI HTTP Protocol instance has not been started.
234
235 **/
236 EFI_STATUS
237 EFIAPI
238 EfiHttpPoll (
239 IN EFI_HTTP_PROTOCOL *This
240 );
241
242 extern EFI_HTTP_PROTOCOL mEfiHttpTemplate;
243
244 #endif