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