]> git.proxmox.com Git - mirror_edk2.git/blame - NetworkPkg/HttpDxe/HttpImpl.c
NetworkPkg/UefiPxeBcDxe: Add the clarification compared to UefiPxeBcDxe in MdeModulePkg.
[mirror_edk2.git] / NetworkPkg / HttpDxe / HttpImpl.c
CommitLineData
47f51a06
YT
1/** @file\r
2 Implementation of EFI_HTTP_PROTOCOL protocol interfaces.\r
3\r
79f84eb6 4 Copyright (c) 2015 - 2018, Intel Corporation. All rights reserved.<BR>\r
f58554fc 5 (C) Copyright 2015-2016 Hewlett Packard Enterprise Development LP<BR>\r
47f51a06
YT
6\r
7 This program and the accompanying materials\r
8 are licensed and made available under the terms and conditions of the BSD License\r
9 which accompanies this distribution. The full text of the license may be found at\r
10 http://opensource.org/licenses/bsd-license.php.\r
11\r
12 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
13 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
14\r
15**/\r
16\r
17#include "HttpDriver.h"\r
18\r
19EFI_HTTP_PROTOCOL mEfiHttpTemplate = {\r
20 EfiHttpGetModeData,\r
21 EfiHttpConfigure,\r
22 EfiHttpRequest,\r
23 EfiHttpCancel,\r
24 EfiHttpResponse,\r
25 EfiHttpPoll\r
26};\r
27\r
28/**\r
29 Returns the operational parameters for the current HTTP child instance.\r
30\r
31 The GetModeData() function is used to read the current mode data (operational\r
32 parameters) for this HTTP protocol instance.\r
33\r
34 @param[in] This Pointer to EFI_HTTP_PROTOCOL instance.\r
35 @param[out] HttpConfigData Point to buffer for operational parameters of this\r
f75a7f56
LG
36 HTTP instance. It is the responsibility of the caller\r
37 to allocate the memory for HttpConfigData and\r
38 HttpConfigData->AccessPoint.IPv6Node/IPv4Node. In fact,\r
39 it is recommended to allocate sufficient memory to record\r
40 IPv6Node since it is big enough for all possibilities.\r
47f51a06
YT
41\r
42 @retval EFI_SUCCESS Operation succeeded.\r
43 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:\r
44 This is NULL.\r
45 HttpConfigData is NULL.\r
f75a7f56 46 HttpConfigData->AccessPoint.IPv4Node or\r
de15f8b6 47 HttpConfigData->AccessPoint.IPv6Node is NULL.\r
f0ab5a81 48 @retval EFI_NOT_STARTED This EFI HTTP Protocol instance has not been started.\r
47f51a06
YT
49\r
50**/\r
51EFI_STATUS\r
52EFIAPI\r
53EfiHttpGetModeData (\r
54 IN EFI_HTTP_PROTOCOL *This,\r
55 OUT EFI_HTTP_CONFIG_DATA *HttpConfigData\r
56 )\r
57{\r
58 HTTP_PROTOCOL *HttpInstance;\r
59\r
f0ab5a81
ZL
60 //\r
61 // Check input parameters.\r
62 //\r
47f51a06
YT
63 if ((This == NULL) || (HttpConfigData == NULL)) {\r
64 return EFI_INVALID_PARAMETER;\r
65 }\r
f0ab5a81 66\r
47f51a06 67 HttpInstance = HTTP_INSTANCE_FROM_PROTOCOL (This);\r
f0ab5a81 68\r
de15f8b6
JW
69 if ((HttpConfigData->AccessPoint.IPv6Node == NULL) ||\r
70 (HttpConfigData->AccessPoint.IPv4Node == NULL)) {\r
f0ab5a81
ZL
71 return EFI_INVALID_PARAMETER;\r
72 }\r
73\r
47f51a06
YT
74 if (HttpInstance->State < HTTP_STATE_HTTP_CONFIGED) {\r
75 return EFI_NOT_STARTED;\r
76 }\r
77\r
47f51a06
YT
78 HttpConfigData->HttpVersion = HttpInstance->HttpVersion;\r
79 HttpConfigData->TimeOutMillisec = HttpInstance->TimeOutMillisec;\r
80 HttpConfigData->LocalAddressIsIPv6 = HttpInstance->LocalAddressIsIPv6;\r
81\r
b659408b 82 if (HttpInstance->LocalAddressIsIPv6) {\r
b659408b 83 CopyMem (\r
f0ab5a81 84 HttpConfigData->AccessPoint.IPv6Node,\r
b659408b
ZL
85 &HttpInstance->Ipv6Node,\r
86 sizeof (HttpInstance->Ipv6Node)\r
47f51a06 87 );\r
b659408b 88 } else {\r
b659408b 89 CopyMem (\r
f0ab5a81 90 HttpConfigData->AccessPoint.IPv4Node,\r
b659408b
ZL
91 &HttpInstance->IPv4Node,\r
92 sizeof (HttpInstance->IPv4Node)\r
93 );\r
b659408b 94 }\r
47f51a06
YT
95\r
96 return EFI_SUCCESS;\r
97}\r
98\r
99/**\r
100 Initialize or brutally reset the operational parameters for this EFI HTTP instance.\r
101\r
102 The Configure() function does the following:\r
103 When HttpConfigData is not NULL Initialize this EFI HTTP instance by configuring\r
104 timeout, local address, port, etc.\r
105 When HttpConfigData is NULL, reset this EFI HTTP instance by closing all active\r
106 connections with remote hosts, canceling all asynchronous tokens, and flush request\r
107 and response buffers without informing the appropriate hosts.\r
108\r
f0ab5a81
ZL
109 No other EFI HTTP function can be executed by this instance until the Configure()\r
110 function is executed and returns successfully.\r
47f51a06
YT
111\r
112 @param[in] This Pointer to EFI_HTTP_PROTOCOL instance.\r
113 @param[in] HttpConfigData Pointer to the configure data to configure the instance.\r
114\r
115 @retval EFI_SUCCESS Operation succeeded.\r
116 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:\r
117 This is NULL.\r
118 HttpConfigData->LocalAddressIsIPv6 is FALSE and\r
de15f8b6 119 HttpConfigData->AccessPoint.IPv4Node is NULL.\r
47f51a06 120 HttpConfigData->LocalAddressIsIPv6 is TRUE and\r
de15f8b6 121 HttpConfigData->AccessPoint.IPv6Node is NULL.\r
47f51a06
YT
122 @retval EFI_ALREADY_STARTED Reinitialize this HTTP instance without calling\r
123 Configure() with NULL to reset it.\r
124 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.\r
125 @retval EFI_OUT_OF_RESOURCES Could not allocate enough system resources when\r
126 executing Configure().\r
127 @retval EFI_UNSUPPORTED One or more options in HttpConfigData are not supported\r
128 in the implementation.\r
129**/\r
130EFI_STATUS\r
131EFIAPI\r
132EfiHttpConfigure (\r
133 IN EFI_HTTP_PROTOCOL *This,\r
30c9eaea 134 IN EFI_HTTP_CONFIG_DATA *HttpConfigData OPTIONAL\r
f75a7f56 135 )\r
47f51a06
YT
136{\r
137 HTTP_PROTOCOL *HttpInstance;\r
138 EFI_STATUS Status;\r
f75a7f56 139\r
b659408b
ZL
140 //\r
141 // Check input parameters.\r
142 //\r
f0ab5a81 143 if (This == NULL ||\r
f75a7f56 144 (HttpConfigData != NULL &&\r
6be1193f
JW
145 ((HttpConfigData->LocalAddressIsIPv6 && HttpConfigData->AccessPoint.IPv6Node == NULL) ||\r
146 (!HttpConfigData->LocalAddressIsIPv6 && HttpConfigData->AccessPoint.IPv4Node == NULL)))) {\r
47f51a06
YT
147 return EFI_INVALID_PARAMETER;\r
148 }\r
149\r
150 HttpInstance = HTTP_INSTANCE_FROM_PROTOCOL (This);\r
2af10590 151 ASSERT (HttpInstance->Service != NULL);\r
47f51a06
YT
152\r
153 if (HttpConfigData != NULL) {\r
b659408b 154\r
79de8c79
JW
155 if (HttpConfigData->HttpVersion >= HttpVersionUnsupported) {\r
156 return EFI_UNSUPPORTED;\r
157 }\r
158\r
47f51a06
YT
159 //\r
160 // Now configure this HTTP instance.\r
161 //\r
162 if (HttpInstance->State != HTTP_STATE_UNCONFIGED) {\r
163 return EFI_ALREADY_STARTED;\r
164 }\r
165\r
166 HttpInstance->HttpVersion = HttpConfigData->HttpVersion;\r
167 HttpInstance->TimeOutMillisec = HttpConfigData->TimeOutMillisec;\r
168 HttpInstance->LocalAddressIsIPv6 = HttpConfigData->LocalAddressIsIPv6;\r
f75a7f56
LG
169\r
170 if (HttpConfigData->LocalAddressIsIPv6) {\r
b659408b
ZL
171 CopyMem (\r
172 &HttpInstance->Ipv6Node,\r
173 HttpConfigData->AccessPoint.IPv6Node,\r
174 sizeof (HttpInstance->Ipv6Node)\r
175 );\r
47f51a06
YT
176 } else {\r
177 CopyMem (\r
178 &HttpInstance->IPv4Node,\r
179 HttpConfigData->AccessPoint.IPv4Node,\r
180 sizeof (HttpInstance->IPv4Node)\r
181 );\r
47f51a06 182 }\r
f75a7f56 183\r
b659408b
ZL
184 //\r
185 // Creat Tcp child\r
186 //\r
187 Status = HttpInitProtocol (HttpInstance, HttpInstance->LocalAddressIsIPv6);\r
188 if (EFI_ERROR (Status)) {\r
189 return Status;\r
190 }\r
f75a7f56 191\r
b659408b
ZL
192 HttpInstance->State = HTTP_STATE_HTTP_CONFIGED;\r
193 return EFI_SUCCESS;\r
47f51a06
YT
194\r
195 } else {\r
b659408b
ZL
196 //\r
197 // Reset all the resources related to HttpInsance.\r
198 //\r
199 HttpCleanProtocol (HttpInstance);\r
200 HttpInstance->State = HTTP_STATE_UNCONFIGED;\r
201 return EFI_SUCCESS;\r
47f51a06
YT
202 }\r
203}\r
f75a7f56 204\r
47f51a06
YT
205\r
206/**\r
207 The Request() function queues an HTTP request to this HTTP instance.\r
208\r
209 Similar to Transmit() function in the EFI TCP driver. When the HTTP request is sent\r
210 successfully, or if there is an error, Status in token will be updated and Event will\r
211 be signaled.\r
212\r
213 @param[in] This Pointer to EFI_HTTP_PROTOCOL instance.\r
214 @param[in] Token Pointer to storage containing HTTP request token.\r
215\r
216 @retval EFI_SUCCESS Outgoing data was processed.\r
217 @retval EFI_NOT_STARTED This EFI HTTP Protocol instance has not been started.\r
218 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.\r
219 @retval EFI_TIMEOUT Data was dropped out of the transmit or receive queue.\r
220 @retval EFI_OUT_OF_RESOURCES Could not allocate enough system resources.\r
221 @retval EFI_UNSUPPORTED The HTTP method is not supported in current\r
222 implementation.\r
223 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:\r
224 This is NULL.\r
f0ab5a81 225 Token is NULL.\r
47f51a06
YT
226 Token->Message is NULL.\r
227 Token->Message->Body is not NULL,\r
228 Token->Message->BodyLength is non-zero, and\r
229 Token->Message->Data is NULL, but a previous call to\r
230 Request()has not been completed successfully.\r
231**/\r
232EFI_STATUS\r
233EFIAPI\r
234EfiHttpRequest (\r
235 IN EFI_HTTP_PROTOCOL *This,\r
236 IN EFI_HTTP_TOKEN *Token\r
237 )\r
238{\r
239 EFI_HTTP_MESSAGE *HttpMsg;\r
240 EFI_HTTP_REQUEST_DATA *Request;\r
241 VOID *UrlParser;\r
242 EFI_STATUS Status;\r
243 CHAR8 *HostName;\r
b9679cd7 244 UINTN HostNameSize;\r
47f51a06
YT
245 UINT16 RemotePort;\r
246 HTTP_PROTOCOL *HttpInstance;\r
247 BOOLEAN Configure;\r
248 BOOLEAN ReConfigure;\r
dac45de3 249 BOOLEAN TlsConfigure;\r
19c25725 250 CHAR8 *RequestMsg;\r
47f51a06 251 CHAR8 *Url;\r
51b0450e 252 UINTN UrlLen;\r
47f51a06
YT
253 CHAR16 *HostNameStr;\r
254 HTTP_TOKEN_WRAP *Wrap;\r
b199d941 255 CHAR8 *FileUrl;\r
19c25725 256 UINTN RequestMsgSize;\r
7cf59c85 257 EFI_HANDLE ImageHandle;\r
d8293d31
NH
258\r
259 //\r
260 // Initializations\r
261 //\r
262 Url = NULL;\r
5646819f 263 UrlParser = NULL;\r
6be1193f 264 RemotePort = 0;\r
d8293d31
NH
265 HostName = NULL;\r
266 RequestMsg = NULL;\r
267 HostNameStr = NULL;\r
268 Wrap = NULL;\r
269 FileUrl = NULL;\r
dac45de3 270 TlsConfigure = FALSE;\r
d8293d31 271\r
47f51a06
YT
272 if ((This == NULL) || (Token == NULL)) {\r
273 return EFI_INVALID_PARAMETER;\r
274 }\r
275\r
276 HttpMsg = Token->Message;\r
d8293d31 277 if (HttpMsg == NULL) {\r
47f51a06
YT
278 return EFI_INVALID_PARAMETER;\r
279 }\r
280\r
47f51a06 281 Request = HttpMsg->Data.Request;\r
47f51a06
YT
282\r
283 //\r
79f84eb6 284 // Only support GET, HEAD, DELETE, PATCH, PUT and POST method in current implementation.\r
47f51a06 285 //\r
d8293d31 286 if ((Request != NULL) && (Request->Method != HttpMethodGet) &&\r
f75a7f56
LG
287 (Request->Method != HttpMethodHead) && (Request->Method != HttpMethodDelete) &&\r
288 (Request->Method != HttpMethodPut) && (Request->Method != HttpMethodPost) &&\r
79f84eb6 289 (Request->Method != HttpMethodPatch)) {\r
47f51a06
YT
290 return EFI_UNSUPPORTED;\r
291 }\r
292\r
293 HttpInstance = HTTP_INSTANCE_FROM_PROTOCOL (This);\r
47f51a06 294\r
d8293d31
NH
295 //\r
296 // Capture the method into HttpInstance.\r
297 //\r
298 if (Request != NULL) {\r
299 HttpInstance->Method = Request->Method;\r
300 }\r
301\r
47f51a06
YT
302 if (HttpInstance->State < HTTP_STATE_HTTP_CONFIGED) {\r
303 return EFI_NOT_STARTED;\r
304 }\r
305\r
d8293d31
NH
306 if (Request == NULL) {\r
307 //\r
97c567ef 308 // Request would be NULL only for PUT/POST/PATCH operation (in the current implementation)\r
d8293d31 309 //\r
f75a7f56
LG
310 if ((HttpInstance->Method != HttpMethodPut) &&\r
311 (HttpInstance->Method != HttpMethodPost) &&\r
97c567ef 312 (HttpInstance->Method != HttpMethodPatch)) {\r
d8293d31
NH
313 return EFI_INVALID_PARAMETER;\r
314 }\r
47f51a06 315\r
d8293d31 316 //\r
97c567ef 317 // For PUT/POST/PATCH, we need to have the TCP already configured. Bail out if it is not!\r
d8293d31
NH
318 //\r
319 if (HttpInstance->State < HTTP_STATE_TCP_CONFIGED) {\r
320 return EFI_INVALID_PARAMETER;\r
321 }\r
47f51a06 322\r
d8293d31
NH
323 //\r
324 // We need to have the Message Body for sending the HTTP message across in these cases.\r
325 //\r
326 if (HttpMsg->Body == NULL || HttpMsg->BodyLength == 0) {\r
327 return EFI_INVALID_PARAMETER;\r
51b0450e 328 }\r
b659408b 329\r
d8293d31
NH
330 //\r
331 // Use existing TCP instance to transmit the packet.\r
332 //\r
333 Configure = FALSE;\r
334 ReConfigure = FALSE;\r
335 } else {\r
336 //\r
337 // Check whether the token already existed.\r
338 //\r
339 if (EFI_ERROR (NetMapIterate (&HttpInstance->TxTokens, HttpTokenExist, Token))) {\r
340 return EFI_ACCESS_DENIED;\r
341 }\r
47f51a06 342\r
d8293d31
NH
343 //\r
344 // Parse the URI of the remote host.\r
345 //\r
346 Url = HttpInstance->Url;\r
347 UrlLen = StrLen (Request->Url) + 1;\r
348 if (UrlLen > HTTP_URL_BUFFER_LEN) {\r
349 Url = AllocateZeroPool (UrlLen);\r
350 if (Url == NULL) {\r
351 return EFI_OUT_OF_RESOURCES;\r
352 }\r
353 FreePool (HttpInstance->Url);\r
354 HttpInstance->Url = Url;\r
355 }\r
47f51a06 356\r
47f51a06 357\r
b9679cd7 358 UnicodeStrToAsciiStrS (Request->Url, Url, UrlLen);\r
dac45de3
JW
359\r
360 //\r
f75a7f56 361 // From the information in Url, the HTTP instance will\r
dac45de3
JW
362 // be able to determine whether to use http or https.\r
363 //\r
364 HttpInstance->UseHttps = IsHttpsUrl (Url);\r
365\r
221463c2
JW
366 //\r
367 // HTTP is disabled, return directly if the URI is not HTTPS.\r
368 //\r
369 if (!PcdGetBool (PcdAllowHttpConnections) && !(HttpInstance->UseHttps)) {\r
f75a7f56 370\r
221463c2
JW
371 DEBUG ((EFI_D_ERROR, "EfiHttpRequest: HTTP is disabled.\n"));\r
372\r
373 return EFI_ACCESS_DENIED;\r
374 }\r
375\r
dac45de3
JW
376 //\r
377 // Check whether we need to create Tls child and open the TLS protocol.\r
378 //\r
379 if (HttpInstance->UseHttps && HttpInstance->TlsChildHandle == NULL) {\r
380 //\r
381 // Use TlsSb to create Tls child and open the TLS protocol.\r
382 //\r
7cf59c85
ZL
383 if (HttpInstance->LocalAddressIsIPv6) {\r
384 ImageHandle = HttpInstance->Service->Ip6DriverBindingHandle;\r
385 } else {\r
386 ImageHandle = HttpInstance->Service->Ip4DriverBindingHandle;\r
387 }\r
388\r
dac45de3 389 HttpInstance->TlsChildHandle = TlsCreateChild (\r
7cf59c85 390 ImageHandle,\r
45ea8a0c 391 &(HttpInstance->TlsSb),\r
dac45de3
JW
392 &(HttpInstance->Tls),\r
393 &(HttpInstance->TlsConfiguration)\r
394 );\r
395 if (HttpInstance->TlsChildHandle == NULL) {\r
396 return EFI_DEVICE_ERROR;\r
397 }\r
398\r
399 TlsConfigure = TRUE;\r
400 }\r
401\r
d8293d31
NH
402 UrlParser = NULL;\r
403 Status = HttpParseUrl (Url, (UINT32) AsciiStrLen (Url), FALSE, &UrlParser);\r
404 if (EFI_ERROR (Status)) {\r
405 goto Error1;\r
406 }\r
47f51a06 407\r
7191827f 408 Status = HttpUrlGetHostName (Url, UrlParser, &HostName);\r
d8293d31 409 if (EFI_ERROR (Status)) {\r
7191827f
JW
410 goto Error1;\r
411 }\r
412\r
413 if (HttpInstance->LocalAddressIsIPv6) {\r
414 HostNameSize = AsciiStrSize (HostName);\r
415\r
416 if (HostNameSize > 2 && HostName[0] == '[' && HostName[HostNameSize - 2] == ']') {\r
417 //\r
418 // HostName format is expressed as IPv6, so, remove '[' and ']'.\r
419 //\r
420 HostNameSize -= 2;\r
421 CopyMem (HostName, HostName + 1, HostNameSize - 1);\r
422 HostName[HostNameSize - 1] = '\0';\r
423 }\r
d8293d31
NH
424 }\r
425\r
426 Status = HttpUrlGetPort (Url, UrlParser, &RemotePort);\r
427 if (EFI_ERROR (Status)) {\r
dac45de3
JW
428 if (HttpInstance->UseHttps) {\r
429 RemotePort = HTTPS_DEFAULT_PORT;\r
430 } else {\r
431 RemotePort = HTTP_DEFAULT_PORT;\r
432 }\r
d8293d31 433 }\r
47f51a06 434 //\r
d8293d31
NH
435 // If Configure is TRUE, it indicates the first time to call Request();\r
436 // If ReConfigure is TRUE, it indicates the request URL is not same\r
437 // with the previous call to Request();\r
47f51a06 438 //\r
d8293d31
NH
439 Configure = TRUE;\r
440 ReConfigure = TRUE;\r
441\r
442 if (HttpInstance->RemoteHost == NULL) {\r
47f51a06 443 //\r
d8293d31 444 // Request() is called the first time.\r
47f51a06 445 //\r
d8293d31
NH
446 ReConfigure = FALSE;\r
447 } else {\r
448 if ((HttpInstance->RemotePort == RemotePort) &&\r
f75a7f56
LG
449 (AsciiStrCmp (HttpInstance->RemoteHost, HostName) == 0) &&\r
450 (!HttpInstance->UseHttps || (HttpInstance->UseHttps &&\r
451 !TlsConfigure &&\r
dac45de3 452 HttpInstance->TlsSessionState == EfiTlsSessionDataTransferring))) {\r
47f51a06 453 //\r
d8293d31 454 // Host Name and port number of the request URL are the same with previous call to Request().\r
dac45de3 455 // If Https protocol used, the corresponding SessionState is EfiTlsSessionDataTransferring.\r
d8293d31 456 // Check whether previous TCP packet sent out.\r
47f51a06 457 //\r
47f51a06 458\r
d8293d31
NH
459 if (EFI_ERROR (NetMapIterate (&HttpInstance->TxTokens, HttpTcpNotReady, NULL))) {\r
460 //\r
461 // Wrap the HTTP token in HTTP_TOKEN_WRAP\r
462 //\r
463 Wrap = AllocateZeroPool (sizeof (HTTP_TOKEN_WRAP));\r
464 if (Wrap == NULL) {\r
465 Status = EFI_OUT_OF_RESOURCES;\r
466 goto Error1;\r
467 }\r
468\r
469 Wrap->HttpToken = Token;\r
470 Wrap->HttpInstance = HttpInstance;\r
471\r
472 Status = HttpCreateTcpTxEvent (Wrap);\r
473 if (EFI_ERROR (Status)) {\r
474 goto Error1;\r
475 }\r
476\r
477 Status = NetMapInsertTail (&HttpInstance->TxTokens, Token, Wrap);\r
478 if (EFI_ERROR (Status)) {\r
479 goto Error1;\r
480 }\r
481\r
482 Wrap->TcpWrap.Method = Request->Method;\r
483\r
484 FreePool (HostName);\r
485\r
c0a0a5a5
JW
486 HttpUrlFreeParser (UrlParser);\r
487\r
d8293d31
NH
488 //\r
489 // Queue the HTTP token and return.\r
490 //\r
491 return EFI_SUCCESS;\r
492 } else {\r
493 //\r
494 // Use existing TCP instance to transmit the packet.\r
495 //\r
496 Configure = FALSE;\r
497 ReConfigure = FALSE;\r
47f51a06 498 }\r
47f51a06
YT
499 } else {\r
500 //\r
d8293d31 501 // Need close existing TCP instance and create a new TCP instance for data transmit.\r
47f51a06 502 //\r
d8293d31
NH
503 if (HttpInstance->RemoteHost != NULL) {\r
504 FreePool (HttpInstance->RemoteHost);\r
505 HttpInstance->RemoteHost = NULL;\r
506 HttpInstance->RemotePort = 0;\r
507 }\r
47f51a06
YT
508 }\r
509 }\r
f75a7f56 510 }\r
47f51a06
YT
511\r
512 if (Configure) {\r
513 //\r
b659408b 514 // Parse Url for IPv4 or IPv6 address, if failed, perform DNS resolution.\r
47f51a06 515 //\r
b659408b
ZL
516 if (!HttpInstance->LocalAddressIsIPv6) {\r
517 Status = NetLibAsciiStrToIp4 (HostName, &HttpInstance->RemoteAddr);\r
518 } else {\r
ac458853 519 Status = HttpUrlGetIp6 (Url, UrlParser, &HttpInstance->RemoteIpv6Addr);\r
b659408b
ZL
520 }\r
521\r
47f51a06 522 if (EFI_ERROR (Status)) {\r
b9679cd7
SZ
523 HostNameSize = AsciiStrSize (HostName);\r
524 HostNameStr = AllocateZeroPool (HostNameSize * sizeof (CHAR16));\r
47f51a06
YT
525 if (HostNameStr == NULL) {\r
526 Status = EFI_OUT_OF_RESOURCES;\r
527 goto Error1;\r
528 }\r
f75a7f56 529\r
b9679cd7 530 AsciiStrToUnicodeStrS (HostName, HostNameStr, HostNameSize);\r
b659408b
ZL
531 if (!HttpInstance->LocalAddressIsIPv6) {\r
532 Status = HttpDns4 (HttpInstance, HostNameStr, &HttpInstance->RemoteAddr);\r
533 } else {\r
534 Status = HttpDns6 (HttpInstance, HostNameStr, &HttpInstance->RemoteIpv6Addr);\r
535 }\r
f75a7f56 536\r
47f51a06
YT
537 FreePool (HostNameStr);\r
538 if (EFI_ERROR (Status)) {\r
fca04738 539 DEBUG ((EFI_D_ERROR, "Error: Could not retrieve the host address from DNS server.\n"));\r
47f51a06
YT
540 goto Error1;\r
541 }\r
542 }\r
543\r
544 //\r
545 // Save the RemotePort and RemoteHost.\r
546 //\r
547 ASSERT (HttpInstance->RemoteHost == NULL);\r
548 HttpInstance->RemotePort = RemotePort;\r
549 HttpInstance->RemoteHost = HostName;\r
550 HostName = NULL;\r
551 }\r
552\r
553 if (ReConfigure) {\r
554 //\r
555 // The request URL is different from previous calls to Request(), close existing TCP instance.\r
556 //\r
a2e61982
ZL
557 if (!HttpInstance->LocalAddressIsIPv6) {\r
558 ASSERT (HttpInstance->Tcp4 != NULL);\r
559 } else {\r
560 ASSERT (HttpInstance->Tcp6 != NULL);\r
561 }\r
dac45de3
JW
562\r
563 if (HttpInstance->UseHttps && !TlsConfigure) {\r
564 Status = TlsCloseSession (HttpInstance);\r
565 if (EFI_ERROR (Status)) {\r
566 goto Error1;\r
567 }\r
f75a7f56 568\r
dac45de3
JW
569 TlsCloseTxRxEvent (HttpInstance);\r
570 }\r
f75a7f56 571\r
47f51a06
YT
572 HttpCloseConnection (HttpInstance);\r
573 EfiHttpCancel (This, NULL);\r
574 }\r
575\r
576 //\r
577 // Wrap the HTTP token in HTTP_TOKEN_WRAP\r
578 //\r
579 Wrap = AllocateZeroPool (sizeof (HTTP_TOKEN_WRAP));\r
580 if (Wrap == NULL) {\r
581 Status = EFI_OUT_OF_RESOURCES;\r
582 goto Error1;\r
583 }\r
584\r
585 Wrap->HttpToken = Token;\r
586 Wrap->HttpInstance = HttpInstance;\r
d8293d31
NH
587 if (Request != NULL) {\r
588 Wrap->TcpWrap.Method = Request->Method;\r
589 }\r
f75a7f56 590\r
dac45de3 591 Status = HttpInitSession (\r
f75a7f56
LG
592 HttpInstance,\r
593 Wrap,\r
594 Configure || ReConfigure,\r
dac45de3
JW
595 TlsConfigure\r
596 );\r
a2e61982
ZL
597 if (EFI_ERROR (Status)) {\r
598 goto Error2;\r
dac45de3 599 }\r
b659408b 600\r
dac45de3 601 if (!Configure && !ReConfigure && !TlsConfigure) {\r
47f51a06 602 //\r
f75a7f56 603 // For the new HTTP token, create TX TCP token events.\r
47f51a06 604 //\r
b659408b 605 Status = HttpCreateTcpTxEvent (Wrap);\r
47f51a06
YT
606 if (EFI_ERROR (Status)) {\r
607 goto Error1;\r
608 }\r
609 }\r
f75a7f56 610\r
47f51a06
YT
611 //\r
612 // Create request message.\r
613 //\r
b199d941 614 FileUrl = Url;\r
d8293d31 615 if (Url != NULL && *FileUrl != '/') {\r
b199d941
GCPL
616 //\r
617 // Convert the absolute-URI to the absolute-path\r
618 //\r
619 while (*FileUrl != ':') {\r
620 FileUrl++;\r
621 }\r
622 if ((*(FileUrl+1) == '/') && (*(FileUrl+2) == '/')) {\r
623 FileUrl += 3;\r
624 while (*FileUrl != '/') {\r
625 FileUrl++;\r
626 }\r
627 } else {\r
628 Status = EFI_INVALID_PARAMETER;\r
629 goto Error3;\r
630 }\r
631 }\r
f58554fc 632\r
19c25725 633 Status = HttpGenRequestMessage (HttpMsg, FileUrl, &RequestMsg, &RequestMsgSize);\r
f58554fc 634\r
63f1d6a4 635 if (EFI_ERROR (Status) || NULL == RequestMsg) {\r
47f51a06
YT
636 goto Error3;\r
637 }\r
638\r
d8293d31
NH
639 //\r
640 // Every request we insert a TxToken and a response call would remove the TxToken.\r
97c567ef 641 // In cases of PUT/POST/PATCH, after an initial request-response pair, we would do a\r
d8293d31
NH
642 // continuous request without a response call. So, in such cases, where Request\r
643 // structure is NULL, we would not insert a TxToken.\r
644 //\r
645 if (Request != NULL) {\r
646 Status = NetMapInsertTail (&HttpInstance->TxTokens, Token, Wrap);\r
647 if (EFI_ERROR (Status)) {\r
648 goto Error4;\r
649 }\r
47f51a06
YT
650 }\r
651\r
47f51a06
YT
652 //\r
653 // Transmit the request message.\r
654 //\r
b659408b 655 Status = HttpTransmitTcp (\r
47f51a06
YT
656 HttpInstance,\r
657 Wrap,\r
19c25725
NH
658 (UINT8*) RequestMsg,\r
659 RequestMsgSize\r
47f51a06
YT
660 );\r
661 if (EFI_ERROR (Status)) {\r
f75a7f56 662 goto Error5;\r
47f51a06
YT
663 }\r
664\r
49c9f74c 665 DispatchDpc ();\r
f75a7f56 666\r
cdf8c32e
NH
667 if (HostName != NULL) {\r
668 FreePool (HostName);\r
669 }\r
c0a0a5a5
JW
670\r
671 if (UrlParser != NULL) {\r
672 HttpUrlFreeParser (UrlParser);\r
673 }\r
f75a7f56 674\r
47f51a06
YT
675 return EFI_SUCCESS;\r
676\r
677Error5:\r
30526a51
JW
678 //\r
679 // We would have inserted a TxToken only if Request structure is not NULL.\r
680 // Hence check before we do a remove in this error case.\r
681 //\r
682 if (Request != NULL) {\r
683 NetMapRemoveTail (&HttpInstance->TxTokens, NULL);\r
684 }\r
47f51a06
YT
685\r
686Error4:\r
19c25725
NH
687 if (RequestMsg != NULL) {\r
688 FreePool (RequestMsg);\r
f75a7f56 689 }\r
47f51a06
YT
690\r
691Error3:\r
dac45de3
JW
692 if (HttpInstance->UseHttps) {\r
693 TlsCloseSession (HttpInstance);\r
694 TlsCloseTxRxEvent (HttpInstance);\r
695 }\r
47f51a06 696\r
47f51a06 697Error2:\r
dac45de3 698 HttpCloseConnection (HttpInstance);\r
f75a7f56 699\r
b659408b
ZL
700 HttpCloseTcpConnCloseEvent (HttpInstance);\r
701 if (NULL != Wrap->TcpWrap.Tx4Token.CompletionToken.Event) {\r
702 gBS->CloseEvent (Wrap->TcpWrap.Tx4Token.CompletionToken.Event);\r
703 Wrap->TcpWrap.Tx4Token.CompletionToken.Event = NULL;\r
704 }\r
705 if (NULL != Wrap->TcpWrap.Tx6Token.CompletionToken.Event) {\r
706 gBS->CloseEvent (Wrap->TcpWrap.Tx6Token.CompletionToken.Event);\r
707 Wrap->TcpWrap.Tx6Token.CompletionToken.Event = NULL;\r
47f51a06
YT
708 }\r
709\r
710Error1:\r
47f51a06
YT
711 if (HostName != NULL) {\r
712 FreePool (HostName);\r
713 }\r
714 if (Wrap != NULL) {\r
715 FreePool (Wrap);\r
716 }\r
c0a0a5a5 717 if (UrlParser != NULL) {\r
47f51a06
YT
718 HttpUrlFreeParser (UrlParser);\r
719 }\r
720\r
721 return Status;\r
f75a7f56 722\r
47f51a06
YT
723}\r
724\r
725/**\r
f75a7f56
LG
726 Cancel a user's Token.\r
727\r
47f51a06
YT
728 @param[in] Map The HTTP instance's token queue.\r
729 @param[in] Item Object container for one HTTP token and token's wrap.\r
730 @param[in] Context The user's token to cancel.\r
731\r
732 @retval EFI_SUCCESS Continue to check the next Item.\r
733 @retval EFI_ABORTED The user's Token (Token != NULL) is cancelled.\r
734\r
735**/\r
736EFI_STATUS\r
737EFIAPI\r
738HttpCancelTokens (\r
739 IN NET_MAP *Map,\r
740 IN NET_MAP_ITEM *Item,\r
741 IN VOID *Context\r
742 )\r
743{\r
47f51a06
YT
744 EFI_HTTP_TOKEN *Token;\r
745 HTTP_TOKEN_WRAP *Wrap;\r
b659408b 746 HTTP_PROTOCOL *HttpInstance;\r
47f51a06
YT
747\r
748 Token = (EFI_HTTP_TOKEN *) Context;\r
749\r
750 //\r
751 // Return EFI_SUCCESS to check the next item in the map if\r
752 // this one doesn't match.\r
753 //\r
754 if ((Token != NULL) && (Token != Item->Key)) {\r
755 return EFI_SUCCESS;\r
756 }\r
757\r
758 Wrap = (HTTP_TOKEN_WRAP *) Item->Value;\r
759 ASSERT (Wrap != NULL);\r
b659408b 760 HttpInstance = Wrap->HttpInstance;\r
f75a7f56 761\r
b659408b 762 if (!HttpInstance->LocalAddressIsIPv6) {\r
b659408b 763 if (Wrap->TcpWrap.Rx4Token.CompletionToken.Event != NULL) {\r
30526a51
JW
764 //\r
765 // Cancle the Token before close its Event.\r
766 //\r
767 HttpInstance->Tcp4->Cancel (HttpInstance->Tcp4, &Wrap->TcpWrap.Rx4Token.CompletionToken);\r
47f51a06 768\r
30526a51
JW
769 //\r
770 // Dispatch the DPC queued by the NotifyFunction of the canceled token's events.\r
771 //\r
772 DispatchDpc ();\r
b659408b 773 }\r
30526a51 774 } else {\r
b659408b 775 if (Wrap->TcpWrap.Rx6Token.CompletionToken.Event != NULL) {\r
30526a51
JW
776 //\r
777 // Cancle the Token before close its Event.\r
778 //\r
779 HttpInstance->Tcp6->Cancel (HttpInstance->Tcp6, &Wrap->TcpWrap.Rx6Token.CompletionToken);\r
47f51a06 780\r
30526a51
JW
781 //\r
782 // Dispatch the DPC queued by the NotifyFunction of the canceled token's events.\r
783 //\r
784 DispatchDpc ();\r
b659408b 785 }\r
47f51a06
YT
786 }\r
787\r
47f51a06
YT
788 //\r
789 // If only one item is to be cancel, return EFI_ABORTED to stop\r
790 // iterating the map any more.\r
791 //\r
792 if (Token != NULL) {\r
793 return EFI_ABORTED;\r
794 }\r
795\r
f75a7f56 796 return EFI_SUCCESS;\r
47f51a06
YT
797}\r
798\r
799/**\r
800 Cancel the user's receive/transmit request. It is the worker function of\r
801 EfiHttpCancel API. If a matching token is found, it will call HttpCancelTokens to cancel the\r
802 token.\r
803\r
804 @param[in] HttpInstance Pointer to HTTP_PROTOCOL structure.\r
805 @param[in] Token The token to cancel. If NULL, all token will be\r
806 cancelled.\r
807\r
808 @retval EFI_SUCCESS The token is cancelled.\r
f75a7f56 809 @retval EFI_NOT_FOUND The asynchronous request or response token is not found.\r
47f51a06
YT
810 @retval Others Other error as indicated.\r
811\r
812**/\r
813EFI_STATUS\r
814HttpCancel (\r
815 IN HTTP_PROTOCOL *HttpInstance,\r
816 IN EFI_HTTP_TOKEN *Token\r
817 )\r
818{\r
819 EFI_STATUS Status;\r
820\r
821 //\r
822 // First check the tokens queued by EfiHttpRequest().\r
823 //\r
824 Status = NetMapIterate (&HttpInstance->TxTokens, HttpCancelTokens, Token);\r
825 if (EFI_ERROR (Status)) {\r
826 if (Token != NULL) {\r
827 if (Status == EFI_ABORTED) {\r
828 return EFI_SUCCESS;\r
f75a7f56 829 }\r
47f51a06
YT
830 } else {\r
831 return Status;\r
832 }\r
833 }\r
834\r
dac45de3
JW
835 if (!HttpInstance->UseHttps) {\r
836 //\r
837 // Then check the tokens queued by EfiHttpResponse(), except for Https.\r
838 //\r
839 Status = NetMapIterate (&HttpInstance->RxTokens, HttpCancelTokens, Token);\r
840 if (EFI_ERROR (Status)) {\r
841 if (Token != NULL) {\r
842 if (Status == EFI_ABORTED) {\r
843 return EFI_SUCCESS;\r
844 } else {\r
845 return EFI_NOT_FOUND;\r
846 }\r
47f51a06 847 } else {\r
dac45de3 848 return Status;\r
47f51a06 849 }\r
dac45de3
JW
850 }\r
851 } else {\r
852 if (!HttpInstance->LocalAddressIsIPv6) {\r
853 HttpInstance->Tcp4->Cancel (HttpInstance->Tcp4, &HttpInstance->Tcp4TlsRxToken.CompletionToken);\r
47f51a06 854 } else {\r
dac45de3 855 HttpInstance->Tcp6->Cancel (HttpInstance->Tcp6, &HttpInstance->Tcp6TlsRxToken.CompletionToken);\r
47f51a06
YT
856 }\r
857 }\r
f75a7f56 858\r
47f51a06
YT
859 return EFI_SUCCESS;\r
860}\r
861\r
862\r
863/**\r
864 Abort an asynchronous HTTP request or response token.\r
865\r
866 The Cancel() function aborts a pending HTTP request or response transaction. If\r
867 Token is not NULL and the token is in transmit or receive queues when it is being\r
868 cancelled, its Token->Status will be set to EFI_ABORTED and then Token->Event will\r
869 be signaled. If the token is not in one of the queues, which usually means that the\r
870 asynchronous operation has completed, EFI_NOT_FOUND is returned. If Token is NULL,\r
871 all asynchronous tokens issued by Request() or Response() will be aborted.\r
872\r
873 @param[in] This Pointer to EFI_HTTP_PROTOCOL instance.\r
874 @param[in] Token Point to storage containing HTTP request or response\r
875 token.\r
876\r
877 @retval EFI_SUCCESS Request and Response queues are successfully flushed.\r
878 @retval EFI_INVALID_PARAMETER This is NULL.\r
879 @retval EFI_NOT_STARTED This instance hasn't been configured.\r
47f51a06
YT
880 @retval EFI_NOT_FOUND The asynchronous request or response token is not\r
881 found.\r
882 @retval EFI_UNSUPPORTED The implementation does not support this function.\r
883\r
884**/\r
885EFI_STATUS\r
886EFIAPI\r
887EfiHttpCancel (\r
888 IN EFI_HTTP_PROTOCOL *This,\r
889 IN EFI_HTTP_TOKEN *Token\r
890 )\r
891{\r
892 HTTP_PROTOCOL *HttpInstance;\r
893\r
894 if (This == NULL) {\r
895 return EFI_INVALID_PARAMETER;\r
896 }\r
897\r
898 HttpInstance = HTTP_INSTANCE_FROM_PROTOCOL (This);\r
47f51a06
YT
899\r
900 if (HttpInstance->State != HTTP_STATE_TCP_CONNECTED) {\r
901 return EFI_NOT_STARTED;\r
902 }\r
903\r
904 return HttpCancel (HttpInstance, Token);\r
905\r
906}\r
907\r
908/**\r
909 A callback function to intercept events during message parser.\r
910\r
911 This function will be invoked during HttpParseMessageBody() with various events type. An error\r
912 return status of the callback function will cause the HttpParseMessageBody() aborted.\r
913\r
914 @param[in] EventType Event type of this callback call.\r
915 @param[in] Data A pointer to data buffer.\r
916 @param[in] Length Length in bytes of the Data.\r
917 @param[in] Context Callback context set by HttpInitMsgParser().\r
918\r
919 @retval EFI_SUCCESS Continue to parser the message body.\r
920\r
921**/\r
922EFI_STATUS\r
923EFIAPI\r
924HttpBodyParserCallback (\r
925 IN HTTP_BODY_PARSE_EVENT EventType,\r
926 IN CHAR8 *Data,\r
927 IN UINTN Length,\r
928 IN VOID *Context\r
929 )\r
930{\r
895b87e3 931 HTTP_CALLBACK_DATA *CallbackData;\r
47f51a06 932 HTTP_TOKEN_WRAP *Wrap;\r
5ba9f065
ZL
933 UINTN BodyLength;\r
934 CHAR8 *Body;\r
47f51a06
YT
935\r
936 if (EventType != BodyParseEventOnComplete) {\r
937 return EFI_SUCCESS;\r
938 }\r
939\r
940 if (Data == NULL || Length != 0 || Context == NULL) {\r
941 return EFI_SUCCESS;\r
942 }\r
943\r
895b87e3
JW
944 CallbackData = (HTTP_CALLBACK_DATA *) Context;\r
945\r
946 Wrap = (HTTP_TOKEN_WRAP *) (CallbackData->Wrap);\r
947 Body = CallbackData->ParseData;\r
948 BodyLength = CallbackData->ParseDataLength;\r
949\r
5ba9f065
ZL
950 if (Data < Body + BodyLength) {\r
951 Wrap->HttpInstance->NextMsg = Data;\r
952 } else {\r
953 Wrap->HttpInstance->NextMsg = NULL;\r
954 }\r
f75a7f56 955\r
47f51a06
YT
956 return EFI_SUCCESS;\r
957}\r
958\r
959/**\r
960 The work function of EfiHttpResponse().\r
961\r
962 @param[in] Wrap Pointer to HTTP token's wrap data.\r
963\r
964 @retval EFI_SUCCESS Allocation succeeded.\r
965 @retval EFI_OUT_OF_RESOURCES Failed to complete the opration due to lack of resources.\r
f75a7f56 966 @retval EFI_NOT_READY Can't find a corresponding Tx4Token/Tx6Token or\r
5ca29abe 967 the EFI_HTTP_UTILITIES_PROTOCOL is not available.\r
47f51a06
YT
968\r
969**/\r
970EFI_STATUS\r
971HttpResponseWorker (\r
972 IN HTTP_TOKEN_WRAP *Wrap\r
973 )\r
974{\r
975 EFI_STATUS Status;\r
976 EFI_HTTP_MESSAGE *HttpMsg;\r
47f51a06
YT
977 CHAR8 *EndofHeader;\r
978 CHAR8 *HttpHeaders;\r
979 UINTN SizeofHeaders;\r
47f51a06
YT
980 UINTN BufferSize;\r
981 UINTN StatusCode;\r
982 CHAR8 *Tmp;\r
983 CHAR8 *HeaderTmp;\r
984 CHAR8 *StatusCodeStr;\r
985 UINTN BodyLen;\r
986 HTTP_PROTOCOL *HttpInstance;\r
987 EFI_HTTP_TOKEN *Token;\r
988 NET_MAP_ITEM *Item;\r
989 HTTP_TOKEN_WRAP *ValueInItem;\r
990 UINTN HdrLen;\r
dac45de3 991 NET_FRAGMENT Fragment;\r
47f51a06 992\r
3fd7bd08 993 if (Wrap == NULL || Wrap->HttpInstance == NULL) {\r
994 return EFI_INVALID_PARAMETER;\r
995 }\r
f75a7f56 996\r
47f51a06
YT
997 HttpInstance = Wrap->HttpInstance;\r
998 Token = Wrap->HttpToken;\r
47f51a06
YT
999 HttpMsg = Token->Message;\r
1000\r
b659408b
ZL
1001 HttpInstance->EndofHeader = NULL;\r
1002 HttpInstance->HttpHeaders = NULL;\r
1003 HttpMsg->Headers = NULL;\r
1004 HttpHeaders = NULL;\r
1005 SizeofHeaders = 0;\r
1006 BufferSize = 0;\r
1007 EndofHeader = NULL;\r
6be1193f 1008 ValueInItem = NULL;\r
dac45de3
JW
1009 Fragment.Len = 0;\r
1010 Fragment.Bulk = NULL;\r
f75a7f56 1011\r
47f51a06 1012 if (HttpMsg->Data.Response != NULL) {\r
47f51a06
YT
1013 //\r
1014 // Check whether we have cached header from previous call.\r
1015 //\r
1016 if ((HttpInstance->CacheBody != NULL) && (HttpInstance->NextMsg != NULL)) {\r
1017 //\r
1018 // The data is stored at [NextMsg, CacheBody + CacheLen].\r
1019 //\r
1020 HdrLen = HttpInstance->CacheBody + HttpInstance->CacheLen - HttpInstance->NextMsg;\r
1021 HttpHeaders = AllocateZeroPool (HdrLen);\r
1022 if (HttpHeaders == NULL) {\r
1023 Status = EFI_OUT_OF_RESOURCES;\r
1024 goto Error;\r
1025 }\r
1026\r
1027 CopyMem (HttpHeaders, HttpInstance->NextMsg, HdrLen);\r
1028 FreePool (HttpInstance->CacheBody);\r
1029 HttpInstance->CacheBody = NULL;\r
1030 HttpInstance->NextMsg = NULL;\r
1031 HttpInstance->CacheOffset = 0;\r
1032 SizeofHeaders = HdrLen;\r
1033 BufferSize = HttpInstance->CacheLen;\r
1034\r
1035 //\r
1036 // Check whether we cached the whole HTTP headers.\r
1037 //\r
f75a7f56
LG
1038 EndofHeader = AsciiStrStr (HttpHeaders, HTTP_END_OF_HDR_STR);\r
1039 }\r
47f51a06 1040\r
b659408b
ZL
1041 HttpInstance->EndofHeader = &EndofHeader;\r
1042 HttpInstance->HttpHeaders = &HttpHeaders;\r
47f51a06 1043\r
b347a22a
JW
1044\r
1045 if (HttpInstance->TimeoutEvent == NULL) {\r
1046 //\r
1047 // Create TimeoutEvent for response\r
1048 //\r
1049 Status = gBS->CreateEvent (\r
1050 EVT_TIMER,\r
1051 TPL_CALLBACK,\r
1052 NULL,\r
1053 NULL,\r
1054 &HttpInstance->TimeoutEvent\r
1055 );\r
1056 if (EFI_ERROR (Status)) {\r
1057 goto Error;\r
1058 }\r
1059 }\r
1060\r
1061 //\r
1062 // Start the timer, and wait Timeout seconds to receive the header packet.\r
1063 //\r
1064 Status = gBS->SetTimer (HttpInstance->TimeoutEvent, TimerRelative, HTTP_RESPONSE_TIMEOUT * TICKS_PER_SECOND);\r
1065 if (EFI_ERROR (Status)) {\r
1066 goto Error;\r
1067 }\r
1068\r
1069 Status = HttpTcpReceiveHeader (HttpInstance, &SizeofHeaders, &BufferSize, HttpInstance->TimeoutEvent);\r
1070\r
1071 gBS->SetTimer (HttpInstance->TimeoutEvent, TimerCancel, 0);\r
1072\r
b659408b
ZL
1073 if (EFI_ERROR (Status)) {\r
1074 goto Error;\r
1075 }\r
47f51a06 1076\r
1b96428d
ZL
1077 ASSERT (HttpHeaders != NULL);\r
1078\r
47f51a06
YT
1079 //\r
1080 // Cache the part of body.\r
1081 //\r
1082 BodyLen = BufferSize - (EndofHeader - HttpHeaders);\r
1083 if (BodyLen > 0) {\r
1084 if (HttpInstance->CacheBody != NULL) {\r
1085 FreePool (HttpInstance->CacheBody);\r
1086 }\r
1087\r
1088 HttpInstance->CacheBody = AllocateZeroPool (BodyLen);\r
1089 if (HttpInstance->CacheBody == NULL) {\r
1090 Status = EFI_OUT_OF_RESOURCES;\r
1091 goto Error;\r
1092 }\r
1093\r
1094 CopyMem (HttpInstance->CacheBody, EndofHeader, BodyLen);\r
1095 HttpInstance->CacheLen = BodyLen;\r
1096 }\r
1097\r
47f51a06
YT
1098 //\r
1099 // Search for Status Code.\r
1100 //\r
1101 StatusCodeStr = HttpHeaders + AsciiStrLen (HTTP_VERSION_STR) + 1;\r
1102 if (StatusCodeStr == NULL) {\r
30526a51 1103 Status = EFI_NOT_READY;\r
47f51a06
YT
1104 goto Error;\r
1105 }\r
1106\r
1107 StatusCode = AsciiStrDecimalToUintn (StatusCodeStr);\r
1108\r
1109 //\r
1110 // Remove the first line of HTTP message, e.g. "HTTP/1.1 200 OK\r\n".\r
1111 //\r
1112 Tmp = AsciiStrStr (HttpHeaders, HTTP_CRLF_STR);\r
1113 if (Tmp == NULL) {\r
30526a51 1114 Status = EFI_NOT_READY;\r
47f51a06
YT
1115 goto Error;\r
1116 }\r
1117\r
47f51a06 1118 //\r
d8293d31
NH
1119 // We could have response with just a HTTP message and no headers. For Example,\r
1120 // "100 Continue". In such cases, we would not want to unnecessarily call a Parse\r
1121 // method. A "\r\n" following Tmp string again would indicate an end. Compare and\r
1122 // set SizeofHeaders to 0.\r
47f51a06 1123 //\r
d8293d31
NH
1124 Tmp = Tmp + AsciiStrLen (HTTP_CRLF_STR);\r
1125 if (CompareMem (Tmp, HTTP_CRLF_STR, AsciiStrLen (HTTP_CRLF_STR)) == 0) {\r
1126 SizeofHeaders = 0;\r
1127 } else {\r
1128 SizeofHeaders = SizeofHeaders - (Tmp - HttpHeaders);\r
47f51a06
YT
1129 }\r
1130\r
47f51a06 1131 HttpMsg->Data.Response->StatusCode = HttpMappingToStatusCode (StatusCode);\r
072289f4 1132 HttpInstance->StatusCode = StatusCode;\r
d8293d31 1133\r
47f51a06
YT
1134 Status = EFI_NOT_READY;\r
1135 ValueInItem = NULL;\r
47f51a06
YT
1136\r
1137 //\r
97c567ef 1138 // In cases of PUT/POST/PATCH, after an initial request-response pair, we would do a\r
d8293d31
NH
1139 // continuous request without a response call. So, we would not do an insert of\r
1140 // TxToken. After we have sent the complete file, we will call a response to get\r
1141 // a final response from server. In such a case, we would not have any TxTokens.\r
1142 // Hence, check that case before doing a NetMapRemoveHead.\r
47f51a06 1143 //\r
d8293d31
NH
1144 if (!NetMapIsEmpty (&HttpInstance->TxTokens)) {\r
1145 NetMapRemoveHead (&HttpInstance->TxTokens, (VOID**) &ValueInItem);\r
1146 if (ValueInItem == NULL) {\r
1147 goto Error;\r
1148 }\r
47f51a06 1149\r
d8293d31
NH
1150 //\r
1151 // The first Tx Token not transmitted yet, insert back and return error.\r
1152 //\r
1153 if (!ValueInItem->TcpWrap.IsTxDone) {\r
1154 goto Error2;\r
1155 }\r
47f51a06
YT
1156 }\r
1157\r
d8293d31
NH
1158 if (SizeofHeaders != 0) {\r
1159 HeaderTmp = AllocateZeroPool (SizeofHeaders);\r
1160 if (HeaderTmp == NULL) {\r
30526a51 1161 Status = EFI_OUT_OF_RESOURCES;\r
5646819f 1162 goto Error2;\r
d8293d31
NH
1163 }\r
1164\r
1165 CopyMem (HeaderTmp, Tmp, SizeofHeaders);\r
1166 FreePool (HttpHeaders);\r
1167 HttpHeaders = HeaderTmp;\r
1168\r
1169 //\r
1170 // Check whether the EFI_HTTP_UTILITIES_PROTOCOL is available.\r
1171 //\r
1172 if (mHttpUtilities == NULL) {\r
1173 Status = EFI_NOT_READY;\r
5646819f 1174 goto Error2;\r
d8293d31
NH
1175 }\r
1176\r
1177 //\r
1178 // Parse the HTTP header into array of key/value pairs.\r
1179 //\r
1180 Status = mHttpUtilities->Parse (\r
1181 mHttpUtilities,\r
1182 HttpHeaders,\r
1183 SizeofHeaders,\r
1184 &HttpMsg->Headers,\r
1185 &HttpMsg->HeaderCount\r
1186 );\r
1187 if (EFI_ERROR (Status)) {\r
5646819f 1188 goto Error2;\r
d8293d31
NH
1189 }\r
1190\r
1191 FreePool (HttpHeaders);\r
1192 HttpHeaders = NULL;\r
1193\r
1194\r
1195 //\r
1196 // Init message-body parser by header information.\r
1197 //\r
1198 Status = HttpInitMsgParser (\r
1199 HttpInstance->Method,\r
1200 HttpMsg->Data.Response->StatusCode,\r
1201 HttpMsg->HeaderCount,\r
1202 HttpMsg->Headers,\r
1203 HttpBodyParserCallback,\r
895b87e3 1204 (VOID *) (&HttpInstance->CallbackData),\r
d8293d31
NH
1205 &HttpInstance->MsgParser\r
1206 );\r
47f51a06
YT
1207 if (EFI_ERROR (Status)) {\r
1208 goto Error2;\r
1209 }\r
1210\r
d8293d31
NH
1211 //\r
1212 // Check whether we received a complete HTTP message.\r
1213 //\r
1214 if (HttpInstance->CacheBody != NULL) {\r
895b87e3
JW
1215 //\r
1216 // Record the CallbackData data.\r
1217 //\r
1218 HttpInstance->CallbackData.Wrap = (VOID *) Wrap;\r
1219 HttpInstance->CallbackData.ParseData = (VOID *) HttpInstance->CacheBody;\r
1220 HttpInstance->CallbackData.ParseDataLength = HttpInstance->CacheLen;\r
1221\r
1222 //\r
1223 // Parse message with CallbackData data.\r
1224 //\r
d8293d31
NH
1225 Status = HttpParseMessageBody (HttpInstance->MsgParser, HttpInstance->CacheLen, HttpInstance->CacheBody);\r
1226 if (EFI_ERROR (Status)) {\r
1227 goto Error2;\r
1228 }\r
895b87e3 1229 }\r
d8293d31 1230\r
895b87e3
JW
1231 if (HttpIsMessageComplete (HttpInstance->MsgParser)) {\r
1232 //\r
1233 // Free the MsgParse since we already have a full HTTP message.\r
1234 //\r
1235 HttpFreeMsgParser (HttpInstance->MsgParser);\r
1236 HttpInstance->MsgParser = NULL;\r
47f51a06
YT
1237 }\r
1238 }\r
1239\r
d8293d31 1240 if ((HttpMsg->Body == NULL) || (HttpMsg->BodyLength == 0)) {\r
47f51a06
YT
1241 Status = EFI_SUCCESS;\r
1242 goto Exit;\r
1243 }\r
d8293d31 1244 }\r
47f51a06
YT
1245\r
1246 //\r
1247 // Receive the response body.\r
1248 //\r
1249 BodyLen = 0;\r
1250\r
1251 //\r
1252 // First check whether we cached some data.\r
1253 //\r
1254 if (HttpInstance->CacheBody != NULL) {\r
1255 //\r
1256 // Calculate the length of the cached data.\r
1257 //\r
1258 if (HttpInstance->NextMsg != NULL) {\r
1259 //\r
1260 // We have a cached HTTP message which includes a part of HTTP header of next message.\r
1261 //\r
f75a7f56 1262 BodyLen = HttpInstance->NextMsg - (HttpInstance->CacheBody + HttpInstance->CacheOffset);\r
47f51a06
YT
1263 } else {\r
1264 BodyLen = HttpInstance->CacheLen - HttpInstance->CacheOffset;\r
1265 }\r
1266\r
1267 if (BodyLen > 0) {\r
1268 //\r
1269 // We have some cached data. Just copy the data and return.\r
1270 //\r
1271 if (HttpMsg->BodyLength < BodyLen) {\r
1272 CopyMem (HttpMsg->Body, HttpInstance->CacheBody + HttpInstance->CacheOffset, HttpMsg->BodyLength);\r
1273 HttpInstance->CacheOffset = HttpInstance->CacheOffset + HttpMsg->BodyLength;\r
1274 } else {\r
1275 //\r
1276 // Copy all cached data out.\r
1277 //\r
1278 CopyMem (HttpMsg->Body, HttpInstance->CacheBody + HttpInstance->CacheOffset, BodyLen);\r
1279 HttpInstance->CacheOffset = BodyLen + HttpInstance->CacheOffset;\r
1280 HttpMsg->BodyLength = BodyLen;\r
1281\r
1282 if (HttpInstance->NextMsg == NULL) {\r
1283 //\r
1284 // There is no HTTP header of next message. Just free the cache buffer.\r
1285 //\r
1286 FreePool (HttpInstance->CacheBody);\r
1287 HttpInstance->CacheBody = NULL;\r
1288 HttpInstance->NextMsg = NULL;\r
1289 HttpInstance->CacheOffset = 0;\r
1290 }\r
1291 }\r
1292 //\r
1293 // Return since we aready received required data.\r
1294 //\r
1295 Status = EFI_SUCCESS;\r
1296 goto Exit;\r
f75a7f56 1297 }\r
47f51a06
YT
1298\r
1299 if (BodyLen == 0 && HttpInstance->MsgParser == NULL) {\r
1300 //\r
1301 // We received a complete HTTP message, and we don't have more data to return to caller.\r
1302 //\r
1303 HttpMsg->BodyLength = 0;\r
1304 Status = EFI_SUCCESS;\r
f75a7f56
LG
1305 goto Exit;\r
1306 }\r
47f51a06
YT
1307 }\r
1308\r
1309 ASSERT (HttpInstance->MsgParser != NULL);\r
1310\r
1311 //\r
1312 // We still need receive more data when there is no cache data and MsgParser is not NULL;\r
1313 //\r
dac45de3
JW
1314 if (!HttpInstance->UseHttps) {\r
1315 Status = HttpTcpReceiveBody (Wrap, HttpMsg);\r
1316\r
1317 if (EFI_ERROR (Status)) {\r
1318 goto Error2;\r
1319 }\r
f75a7f56 1320\r
dac45de3
JW
1321 } else {\r
1322 if (HttpInstance->TimeoutEvent == NULL) {\r
1323 //\r
1324 // Create TimeoutEvent for response\r
1325 //\r
1326 Status = gBS->CreateEvent (\r
1327 EVT_TIMER,\r
1328 TPL_CALLBACK,\r
1329 NULL,\r
1330 NULL,\r
1331 &HttpInstance->TimeoutEvent\r
1332 );\r
1333 if (EFI_ERROR (Status)) {\r
1334 goto Error2;\r
1335 }\r
1336 }\r
1337\r
1338 //\r
1339 // Start the timer, and wait Timeout seconds to receive the body packet.\r
1340 //\r
1341 Status = gBS->SetTimer (HttpInstance->TimeoutEvent, TimerRelative, HTTP_RESPONSE_TIMEOUT * TICKS_PER_SECOND);\r
1342 if (EFI_ERROR (Status)) {\r
1343 goto Error2;\r
1344 }\r
f75a7f56 1345\r
dac45de3
JW
1346 Status = HttpsReceive (HttpInstance, &Fragment, HttpInstance->TimeoutEvent);\r
1347\r
1348 gBS->SetTimer (HttpInstance->TimeoutEvent, TimerCancel, 0);\r
f75a7f56 1349\r
dac45de3
JW
1350 if (EFI_ERROR (Status)) {\r
1351 goto Error2;\r
1352 }\r
1353\r
1354 //\r
895b87e3
JW
1355 // Process the received the body packet.\r
1356 //\r
1357 HttpMsg->BodyLength = MIN (Fragment.Len, (UINT32) HttpMsg->BodyLength);\r
1358\r
1359 CopyMem (HttpMsg->Body, Fragment.Bulk, HttpMsg->BodyLength);\r
1360\r
1361 //\r
1362 // Record the CallbackData data.\r
1363 //\r
1364 HttpInstance->CallbackData.Wrap = (VOID *) Wrap;\r
1365 HttpInstance->CallbackData.ParseData = HttpMsg->Body;\r
1366 HttpInstance->CallbackData.ParseDataLength = HttpMsg->BodyLength;\r
1367\r
1368 //\r
1369 // Parse Body with CallbackData data.\r
dac45de3
JW
1370 //\r
1371 Status = HttpParseMessageBody (\r
1372 HttpInstance->MsgParser,\r
895b87e3
JW
1373 HttpMsg->BodyLength,\r
1374 HttpMsg->Body\r
dac45de3
JW
1375 );\r
1376 if (EFI_ERROR (Status)) {\r
1377 goto Error2;\r
1378 }\r
1379\r
1380 if (HttpIsMessageComplete (HttpInstance->MsgParser)) {\r
1381 //\r
1382 // Free the MsgParse since we already have a full HTTP message.\r
1383 //\r
1384 HttpFreeMsgParser (HttpInstance->MsgParser);\r
1385 HttpInstance->MsgParser = NULL;\r
1386 }\r
1387\r
1388 //\r
895b87e3 1389 // Check whether there is the next message header in the HttpMsg->Body.\r
dac45de3
JW
1390 //\r
1391 if (HttpInstance->NextMsg != NULL) {\r
895b87e3
JW
1392 HttpMsg->BodyLength = HttpInstance->NextMsg - (CHAR8 *) HttpMsg->Body;\r
1393 }\r
dac45de3 1394\r
895b87e3
JW
1395 HttpInstance->CacheLen = Fragment.Len - HttpMsg->BodyLength;\r
1396 if (HttpInstance->CacheLen != 0) {\r
1397 if (HttpInstance->CacheBody != NULL) {\r
1398 FreePool (HttpInstance->CacheBody);\r
dac45de3 1399 }\r
f75a7f56 1400\r
895b87e3
JW
1401 HttpInstance->CacheBody = AllocateZeroPool (HttpInstance->CacheLen);\r
1402 if (HttpInstance->CacheBody == NULL) {\r
1403 Status = EFI_OUT_OF_RESOURCES;\r
1404 goto Error2;\r
1405 }\r
dac45de3 1406\r
895b87e3
JW
1407 CopyMem (HttpInstance->CacheBody, Fragment.Bulk + HttpMsg->BodyLength, HttpInstance->CacheLen);\r
1408 HttpInstance->CacheOffset = 0;\r
1409 if (HttpInstance->NextMsg != NULL) {\r
1410 HttpInstance->NextMsg = HttpInstance->CacheBody;\r
dac45de3
JW
1411 }\r
1412 }\r
1413\r
1414 if (Fragment.Bulk != NULL) {\r
1415 FreePool (Fragment.Bulk);\r
1416 Fragment.Bulk = NULL;\r
1417 }\r
1418\r
1419 goto Exit;\r
47f51a06
YT
1420 }\r
1421\r
1422 return Status;\r
1423\r
1424Exit:\r
1425 Item = NetMapFindKey (&Wrap->HttpInstance->RxTokens, Wrap->HttpToken);\r
1426 if (Item != NULL) {\r
1427 NetMapRemoveItem (&Wrap->HttpInstance->RxTokens, Item, NULL);\r
1428 }\r
072289f4
ZL
1429\r
1430 if (HttpInstance->StatusCode >= HTTP_ERROR_OR_NOT_SUPPORT_STATUS_CODE) {\r
1431 Token->Status = EFI_HTTP_ERROR;\r
1432 } else {\r
1433 Token->Status = Status;\r
1434 }\r
1435\r
47f51a06 1436 gBS->SignalEvent (Token->Event);\r
b659408b 1437 HttpCloseTcpRxEvent (Wrap);\r
47f51a06
YT
1438 FreePool (Wrap);\r
1439 return Status;\r
1440\r
1441Error2:\r
5646819f
FS
1442 if (ValueInItem != NULL) {\r
1443 NetMapInsertHead (&HttpInstance->TxTokens, ValueInItem->HttpToken, ValueInItem);\r
1444 }\r
47f51a06
YT
1445\r
1446Error:\r
30526a51
JW
1447 Item = NetMapFindKey (&Wrap->HttpInstance->RxTokens, Wrap->HttpToken);\r
1448 if (Item != NULL) {\r
1449 NetMapRemoveItem (&Wrap->HttpInstance->RxTokens, Item, NULL);\r
1450 }\r
dac45de3
JW
1451\r
1452 if (!HttpInstance->UseHttps) {\r
1453 HttpTcpTokenCleanup (Wrap);\r
1454 } else {\r
1455 FreePool (Wrap);\r
1456 }\r
f75a7f56 1457\r
47f51a06
YT
1458 if (HttpHeaders != NULL) {\r
1459 FreePool (HttpHeaders);\r
dac45de3
JW
1460 HttpHeaders = NULL;\r
1461 }\r
1462\r
1463 if (Fragment.Bulk != NULL) {\r
1464 FreePool (Fragment.Bulk);\r
1465 Fragment.Bulk = NULL;\r
47f51a06
YT
1466 }\r
1467\r
1468 if (HttpMsg->Headers != NULL) {\r
1469 FreePool (HttpMsg->Headers);\r
dac45de3 1470 HttpMsg->Headers = NULL;\r
47f51a06
YT
1471 }\r
1472\r
1473 if (HttpInstance->CacheBody != NULL) {\r
1474 FreePool (HttpInstance->CacheBody);\r
1475 HttpInstance->CacheBody = NULL;\r
1476 }\r
1477\r
072289f4
ZL
1478 if (HttpInstance->StatusCode >= HTTP_ERROR_OR_NOT_SUPPORT_STATUS_CODE) {\r
1479 Token->Status = EFI_HTTP_ERROR;\r
1480 } else {\r
1481 Token->Status = Status;\r
1482 }\r
1483\r
47f51a06
YT
1484 gBS->SignalEvent (Token->Event);\r
1485\r
f75a7f56 1486 return Status;\r
47f51a06
YT
1487\r
1488}\r
1489\r
1490\r
1491/**\r
1492 The Response() function queues an HTTP response to this HTTP instance, similar to\r
f0ab5a81 1493 Receive() function in the EFI TCP driver. When the HTTP response is received successfully,\r
47f51a06
YT
1494 or if there is an error, Status in token will be updated and Event will be signaled.\r
1495\r
1496 The HTTP driver will queue a receive token to the underlying TCP instance. When data\r
1497 is received in the underlying TCP instance, the data will be parsed and Token will\r
1498 be populated with the response data. If the data received from the remote host\r
1499 contains an incomplete or invalid HTTP header, the HTTP driver will continue waiting\r
1500 (asynchronously) for more data to be sent from the remote host before signaling\r
1501 Event in Token.\r
1502\r
1503 It is the responsibility of the caller to allocate a buffer for Body and specify the\r
1504 size in BodyLength. If the remote host provides a response that contains a content\r
1505 body, up to BodyLength bytes will be copied from the receive buffer into Body and\r
1506 BodyLength will be updated with the amount of bytes received and copied to Body. This\r
1507 allows the client to download a large file in chunks instead of into one contiguous\r
1508 block of memory. Similar to HTTP request, if Body is not NULL and BodyLength is\r
1509 non-zero and all other fields are NULL or 0, the HTTP driver will queue a receive\r
1510 token to underlying TCP instance. If data arrives in the receive buffer, up to\r
1511 BodyLength bytes of data will be copied to Body. The HTTP driver will then update\r
1512 BodyLength with the amount of bytes received and copied to Body.\r
1513\r
1514 If the HTTP driver does not have an open underlying TCP connection with the host\r
1515 specified in the response URL, Request() will return EFI_ACCESS_DENIED. This is\r
1516 consistent with RFC 2616 recommendation that HTTP clients should attempt to maintain\r
1517 an open TCP connection between client and host.\r
1518\r
1519 @param[in] This Pointer to EFI_HTTP_PROTOCOL instance.\r
1520 @param[in] Token Pointer to storage containing HTTP response token.\r
1521\r
1522 @retval EFI_SUCCESS Allocation succeeded.\r
1523 @retval EFI_NOT_STARTED This EFI HTTP Protocol instance has not been\r
1524 initialized.\r
1525 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:\r
1526 This is NULL.\r
1527 Token is NULL.\r
1528 Token->Message->Headers is NULL.\r
1529 Token->Message is NULL.\r
1530 Token->Message->Body is not NULL,\r
1531 Token->Message->BodyLength is non-zero, and\r
1532 Token->Message->Data is NULL, but a previous call to\r
1533 Response() has not been completed successfully.\r
1534 @retval EFI_OUT_OF_RESOURCES Could not allocate enough system resources.\r
1535 @retval EFI_ACCESS_DENIED An open TCP connection is not present with the host\r
1536 specified by response URL.\r
1537**/\r
1538EFI_STATUS\r
1539EFIAPI\r
1540EfiHttpResponse (\r
1541 IN EFI_HTTP_PROTOCOL *This,\r
1542 IN EFI_HTTP_TOKEN *Token\r
1543 )\r
1544{\r
1545 EFI_STATUS Status;\r
1546 EFI_HTTP_MESSAGE *HttpMsg;\r
1547 HTTP_PROTOCOL *HttpInstance;\r
1548 HTTP_TOKEN_WRAP *Wrap;\r
1549\r
1550 if ((This == NULL) || (Token == NULL)) {\r
1551 return EFI_INVALID_PARAMETER;\r
1552 }\r
1553\r
1554 HttpMsg = Token->Message;\r
1555 if (HttpMsg == NULL) {\r
1556 return EFI_INVALID_PARAMETER;\r
1557 }\r
f75a7f56 1558\r
47f51a06 1559 HttpInstance = HTTP_INSTANCE_FROM_PROTOCOL (This);\r
47f51a06
YT
1560\r
1561 if (HttpInstance->State != HTTP_STATE_TCP_CONNECTED) {\r
1562 return EFI_NOT_STARTED;\r
1563 }\r
1564\r
47f51a06
YT
1565 //\r
1566 // Check whether the token already existed.\r
1567 //\r
1568 if (EFI_ERROR (NetMapIterate (&HttpInstance->RxTokens, HttpTokenExist, Token))) {\r
f75a7f56 1569 return EFI_ACCESS_DENIED;\r
47f51a06
YT
1570 }\r
1571\r
1572 Wrap = AllocateZeroPool (sizeof (HTTP_TOKEN_WRAP));\r
1573 if (Wrap == NULL) {\r
1574 return EFI_OUT_OF_RESOURCES;\r
1575 }\r
1576\r
1577 Wrap->HttpInstance = HttpInstance;\r
1578 Wrap->HttpToken = Token;\r
1579\r
dac45de3 1580 //\r
f75a7f56
LG
1581 // Notes: For Https, receive token wrapped in HTTP_TOKEN_WRAP is not used to\r
1582 // receive the https response. A special TlsRxToken is used for receiving TLS\r
dac45de3
JW
1583 // related messages. It should be a blocking response.\r
1584 //\r
1585 if (!HttpInstance->UseHttps) {\r
1586 Status = HttpCreateTcpRxEvent (Wrap);\r
1587 if (EFI_ERROR (Status)) {\r
1588 goto Error;\r
1589 }\r
47f51a06
YT
1590 }\r
1591\r
1592 Status = NetMapInsertTail (&HttpInstance->RxTokens, Token, Wrap);\r
1593 if (EFI_ERROR (Status)) {\r
1594 goto Error;\r
1595 }\r
1596\r
1597 //\r
1598 // If already have pending RxTokens, return directly.\r
1599 //\r
1600 if (NetMapGetCount (&HttpInstance->RxTokens) > 1) {\r
1601 return EFI_SUCCESS;\r
1602 }\r
1603\r
1604 return HttpResponseWorker (Wrap);\r
1605\r
1606Error:\r
1607 if (Wrap != NULL) {\r
b659408b
ZL
1608 if (Wrap->TcpWrap.Rx4Token.CompletionToken.Event != NULL) {\r
1609 gBS->CloseEvent (Wrap->TcpWrap.Rx4Token.CompletionToken.Event);\r
1610 }\r
1611\r
1612 if (Wrap->TcpWrap.Rx6Token.CompletionToken.Event != NULL) {\r
1613 gBS->CloseEvent (Wrap->TcpWrap.Rx6Token.CompletionToken.Event);\r
47f51a06
YT
1614 }\r
1615 FreePool (Wrap);\r
f75a7f56 1616 }\r
47f51a06 1617\r
f75a7f56 1618 return Status;\r
47f51a06
YT
1619}\r
1620\r
1621/**\r
1622 The Poll() function can be used by network drivers and applications to increase the\r
1623 rate that data packets are moved between the communication devices and the transmit\r
1624 and receive queues.\r
1625\r
1626 In some systems, the periodic timer event in the managed network driver may not poll\r
1627 the underlying communications device fast enough to transmit and/or receive all data\r
1628 packets without missing incoming packets or dropping outgoing packets. Drivers and\r
1629 applications that are experiencing packet loss should try calling the Poll() function\r
1630 more often.\r
1631\r
1632 @param[in] This Pointer to EFI_HTTP_PROTOCOL instance.\r
1633\r
1634 @retval EFI_SUCCESS Incoming or outgoing data was processed.\r
1635 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.\r
1636 @retval EFI_INVALID_PARAMETER This is NULL.\r
1637 @retval EFI_NOT_READY No incoming or outgoing data is processed.\r
1638 @retval EFI_NOT_STARTED This EFI HTTP Protocol instance has not been started.\r
1639\r
1640**/\r
1641EFI_STATUS\r
1642EFIAPI\r
1643EfiHttpPoll (\r
1644 IN EFI_HTTP_PROTOCOL *This\r
1645 )\r
1646{\r
49c9f74c 1647 EFI_STATUS Status;\r
b659408b 1648 HTTP_PROTOCOL *HttpInstance;\r
47f51a06
YT
1649\r
1650 if (This == NULL) {\r
1651 return EFI_INVALID_PARAMETER;\r
1652 }\r
1653\r
1654 HttpInstance = HTTP_INSTANCE_FROM_PROTOCOL (This);\r
47f51a06 1655\r
1b96428d 1656 if (HttpInstance->State != HTTP_STATE_TCP_CONNECTED) {\r
47f51a06
YT
1657 return EFI_NOT_STARTED;\r
1658 }\r
f75a7f56 1659\r
b659408b 1660 if (HttpInstance->LocalAddressIsIPv6) {\r
1b96428d
ZL
1661 if (HttpInstance->Tcp6 == NULL) {\r
1662 return EFI_NOT_STARTED;\r
1663 }\r
b659408b
ZL
1664 Status = HttpInstance->Tcp6->Poll (HttpInstance->Tcp6);\r
1665 } else {\r
1b96428d
ZL
1666 if (HttpInstance->Tcp4 == NULL) {\r
1667 return EFI_NOT_STARTED;\r
1668 }\r
b659408b
ZL
1669 Status = HttpInstance->Tcp4->Poll (HttpInstance->Tcp4);\r
1670 }\r
f75a7f56 1671\r
49c9f74c 1672 DispatchDpc ();\r
f75a7f56 1673\r
49c9f74c 1674 return Status;\r
47f51a06 1675}\r