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