]> git.proxmox.com Git - mirror_edk2.git/blame - NetworkPkg/HttpDxe/HttpImpl.c
MdePkg PiHob.h: Add FV3 HOB definitions
[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
526 goto Error1;\r
527 }\r
528 }\r
529\r
530 //\r
531 // Save the RemotePort and RemoteHost.\r
532 //\r
533 ASSERT (HttpInstance->RemoteHost == NULL);\r
534 HttpInstance->RemotePort = RemotePort;\r
535 HttpInstance->RemoteHost = HostName;\r
536 HostName = NULL;\r
537 }\r
538\r
539 if (ReConfigure) {\r
540 //\r
541 // The request URL is different from previous calls to Request(), close existing TCP instance.\r
542 //\r
a2e61982
ZL
543 if (!HttpInstance->LocalAddressIsIPv6) {\r
544 ASSERT (HttpInstance->Tcp4 != NULL);\r
545 } else {\r
546 ASSERT (HttpInstance->Tcp6 != NULL);\r
547 }\r
dac45de3
JW
548\r
549 if (HttpInstance->UseHttps && !TlsConfigure) {\r
550 Status = TlsCloseSession (HttpInstance);\r
551 if (EFI_ERROR (Status)) {\r
552 goto Error1;\r
553 }\r
554 \r
555 TlsCloseTxRxEvent (HttpInstance);\r
556 }\r
557 \r
47f51a06
YT
558 HttpCloseConnection (HttpInstance);\r
559 EfiHttpCancel (This, NULL);\r
560 }\r
561\r
562 //\r
563 // Wrap the HTTP token in HTTP_TOKEN_WRAP\r
564 //\r
565 Wrap = AllocateZeroPool (sizeof (HTTP_TOKEN_WRAP));\r
566 if (Wrap == NULL) {\r
567 Status = EFI_OUT_OF_RESOURCES;\r
568 goto Error1;\r
569 }\r
570\r
571 Wrap->HttpToken = Token;\r
572 Wrap->HttpInstance = HttpInstance;\r
d8293d31
NH
573 if (Request != NULL) {\r
574 Wrap->TcpWrap.Method = Request->Method;\r
575 }\r
dac45de3
JW
576 \r
577 Status = HttpInitSession (\r
578 HttpInstance, \r
579 Wrap, \r
580 Configure || ReConfigure, \r
581 TlsConfigure\r
582 );\r
a2e61982
ZL
583 if (EFI_ERROR (Status)) {\r
584 goto Error2;\r
dac45de3 585 }\r
b659408b 586\r
dac45de3 587 if (!Configure && !ReConfigure && !TlsConfigure) {\r
47f51a06
YT
588 //\r
589 // For the new HTTP token, create TX TCP token events. \r
590 //\r
b659408b 591 Status = HttpCreateTcpTxEvent (Wrap);\r
47f51a06
YT
592 if (EFI_ERROR (Status)) {\r
593 goto Error1;\r
594 }\r
595 }\r
a2e61982 596 \r
47f51a06
YT
597 //\r
598 // Create request message.\r
599 //\r
b199d941 600 FileUrl = Url;\r
d8293d31 601 if (Url != NULL && *FileUrl != '/') {\r
b199d941
GCPL
602 //\r
603 // Convert the absolute-URI to the absolute-path\r
604 //\r
605 while (*FileUrl != ':') {\r
606 FileUrl++;\r
607 }\r
608 if ((*(FileUrl+1) == '/') && (*(FileUrl+2) == '/')) {\r
609 FileUrl += 3;\r
610 while (*FileUrl != '/') {\r
611 FileUrl++;\r
612 }\r
613 } else {\r
614 Status = EFI_INVALID_PARAMETER;\r
615 goto Error3;\r
616 }\r
617 }\r
f58554fc 618\r
19c25725 619 Status = HttpGenRequestMessage (HttpMsg, FileUrl, &RequestMsg, &RequestMsgSize);\r
f58554fc 620\r
63f1d6a4 621 if (EFI_ERROR (Status) || NULL == RequestMsg) {\r
47f51a06
YT
622 goto Error3;\r
623 }\r
624\r
63f1d6a4
JW
625 ASSERT (RequestMsg != NULL);\r
626\r
d8293d31
NH
627 //\r
628 // Every request we insert a TxToken and a response call would remove the TxToken.\r
97c567ef 629 // In cases of PUT/POST/PATCH, after an initial request-response pair, we would do a\r
d8293d31
NH
630 // continuous request without a response call. So, in such cases, where Request\r
631 // structure is NULL, we would not insert a TxToken.\r
632 //\r
633 if (Request != NULL) {\r
634 Status = NetMapInsertTail (&HttpInstance->TxTokens, Token, Wrap);\r
635 if (EFI_ERROR (Status)) {\r
636 goto Error4;\r
637 }\r
47f51a06
YT
638 }\r
639\r
47f51a06
YT
640 //\r
641 // Transmit the request message.\r
642 //\r
b659408b 643 Status = HttpTransmitTcp (\r
47f51a06
YT
644 HttpInstance,\r
645 Wrap,\r
19c25725
NH
646 (UINT8*) RequestMsg,\r
647 RequestMsgSize\r
47f51a06
YT
648 );\r
649 if (EFI_ERROR (Status)) {\r
650 goto Error5; \r
651 }\r
652\r
49c9f74c 653 DispatchDpc ();\r
b659408b 654 \r
cdf8c32e
NH
655 if (HostName != NULL) {\r
656 FreePool (HostName);\r
657 }\r
b659408b 658 \r
47f51a06
YT
659 return EFI_SUCCESS;\r
660\r
661Error5:\r
30526a51
JW
662 //\r
663 // We would have inserted a TxToken only if Request structure is not NULL.\r
664 // Hence check before we do a remove in this error case.\r
665 //\r
666 if (Request != NULL) {\r
667 NetMapRemoveTail (&HttpInstance->TxTokens, NULL);\r
668 }\r
47f51a06
YT
669\r
670Error4:\r
19c25725
NH
671 if (RequestMsg != NULL) {\r
672 FreePool (RequestMsg);\r
47f51a06
YT
673 } \r
674\r
675Error3:\r
dac45de3
JW
676 if (HttpInstance->UseHttps) {\r
677 TlsCloseSession (HttpInstance);\r
678 TlsCloseTxRxEvent (HttpInstance);\r
679 }\r
47f51a06 680\r
47f51a06 681Error2:\r
dac45de3
JW
682 HttpCloseConnection (HttpInstance);\r
683 \r
b659408b
ZL
684 HttpCloseTcpConnCloseEvent (HttpInstance);\r
685 if (NULL != Wrap->TcpWrap.Tx4Token.CompletionToken.Event) {\r
686 gBS->CloseEvent (Wrap->TcpWrap.Tx4Token.CompletionToken.Event);\r
687 Wrap->TcpWrap.Tx4Token.CompletionToken.Event = NULL;\r
688 }\r
689 if (NULL != Wrap->TcpWrap.Tx6Token.CompletionToken.Event) {\r
690 gBS->CloseEvent (Wrap->TcpWrap.Tx6Token.CompletionToken.Event);\r
691 Wrap->TcpWrap.Tx6Token.CompletionToken.Event = NULL;\r
47f51a06
YT
692 }\r
693\r
694Error1:\r
47f51a06
YT
695 if (HostName != NULL) {\r
696 FreePool (HostName);\r
697 }\r
698 if (Wrap != NULL) {\r
699 FreePool (Wrap);\r
700 }\r
701 if (UrlParser!= NULL) {\r
702 HttpUrlFreeParser (UrlParser);\r
703 }\r
704\r
705 return Status;\r
706 \r
707}\r
708\r
709/**\r
b659408b 710 Cancel a user's Token. \r
47f51a06
YT
711 \r
712 @param[in] Map The HTTP instance's token queue.\r
713 @param[in] Item Object container for one HTTP token and token's wrap.\r
714 @param[in] Context The user's token to cancel.\r
715\r
716 @retval EFI_SUCCESS Continue to check the next Item.\r
717 @retval EFI_ABORTED The user's Token (Token != NULL) is cancelled.\r
718\r
719**/\r
720EFI_STATUS\r
721EFIAPI\r
722HttpCancelTokens (\r
723 IN NET_MAP *Map,\r
724 IN NET_MAP_ITEM *Item,\r
725 IN VOID *Context\r
726 )\r
727{\r
47f51a06
YT
728 EFI_HTTP_TOKEN *Token;\r
729 HTTP_TOKEN_WRAP *Wrap;\r
b659408b 730 HTTP_PROTOCOL *HttpInstance;\r
47f51a06
YT
731\r
732 Token = (EFI_HTTP_TOKEN *) Context;\r
733\r
734 //\r
735 // Return EFI_SUCCESS to check the next item in the map if\r
736 // this one doesn't match.\r
737 //\r
738 if ((Token != NULL) && (Token != Item->Key)) {\r
739 return EFI_SUCCESS;\r
740 }\r
741\r
742 Wrap = (HTTP_TOKEN_WRAP *) Item->Value;\r
743 ASSERT (Wrap != NULL);\r
b659408b 744 HttpInstance = Wrap->HttpInstance;\r
47f51a06 745 \r
b659408b 746 if (!HttpInstance->LocalAddressIsIPv6) {\r
b659408b 747 if (Wrap->TcpWrap.Rx4Token.CompletionToken.Event != NULL) {\r
30526a51
JW
748 //\r
749 // Cancle the Token before close its Event.\r
750 //\r
751 HttpInstance->Tcp4->Cancel (HttpInstance->Tcp4, &Wrap->TcpWrap.Rx4Token.CompletionToken);\r
47f51a06 752\r
30526a51
JW
753 //\r
754 // Dispatch the DPC queued by the NotifyFunction of the canceled token's events.\r
755 //\r
756 DispatchDpc ();\r
b659408b 757 }\r
30526a51 758 } else {\r
b659408b 759 if (Wrap->TcpWrap.Rx6Token.CompletionToken.Event != NULL) {\r
30526a51
JW
760 //\r
761 // Cancle the Token before close its Event.\r
762 //\r
763 HttpInstance->Tcp6->Cancel (HttpInstance->Tcp6, &Wrap->TcpWrap.Rx6Token.CompletionToken);\r
47f51a06 764\r
30526a51
JW
765 //\r
766 // Dispatch the DPC queued by the NotifyFunction of the canceled token's events.\r
767 //\r
768 DispatchDpc ();\r
b659408b 769 }\r
47f51a06
YT
770 }\r
771\r
47f51a06
YT
772 //\r
773 // If only one item is to be cancel, return EFI_ABORTED to stop\r
774 // iterating the map any more.\r
775 //\r
776 if (Token != NULL) {\r
777 return EFI_ABORTED;\r
778 }\r
779\r
780 return EFI_SUCCESS; \r
781}\r
782\r
783/**\r
784 Cancel the user's receive/transmit request. It is the worker function of\r
785 EfiHttpCancel API. If a matching token is found, it will call HttpCancelTokens to cancel the\r
786 token.\r
787\r
788 @param[in] HttpInstance Pointer to HTTP_PROTOCOL structure.\r
789 @param[in] Token The token to cancel. If NULL, all token will be\r
790 cancelled.\r
791\r
792 @retval EFI_SUCCESS The token is cancelled.\r
793 @retval EFI_NOT_FOUND The asynchronous request or response token is not found. \r
794 @retval Others Other error as indicated.\r
795\r
796**/\r
797EFI_STATUS\r
798HttpCancel (\r
799 IN HTTP_PROTOCOL *HttpInstance,\r
800 IN EFI_HTTP_TOKEN *Token\r
801 )\r
802{\r
803 EFI_STATUS Status;\r
804\r
805 //\r
806 // First check the tokens queued by EfiHttpRequest().\r
807 //\r
808 Status = NetMapIterate (&HttpInstance->TxTokens, HttpCancelTokens, Token);\r
809 if (EFI_ERROR (Status)) {\r
810 if (Token != NULL) {\r
811 if (Status == EFI_ABORTED) {\r
812 return EFI_SUCCESS;\r
813 } \r
814 } else {\r
815 return Status;\r
816 }\r
817 }\r
818\r
dac45de3
JW
819 if (!HttpInstance->UseHttps) {\r
820 //\r
821 // Then check the tokens queued by EfiHttpResponse(), except for Https.\r
822 //\r
823 Status = NetMapIterate (&HttpInstance->RxTokens, HttpCancelTokens, Token);\r
824 if (EFI_ERROR (Status)) {\r
825 if (Token != NULL) {\r
826 if (Status == EFI_ABORTED) {\r
827 return EFI_SUCCESS;\r
828 } else {\r
829 return EFI_NOT_FOUND;\r
830 }\r
47f51a06 831 } else {\r
dac45de3 832 return Status;\r
47f51a06 833 }\r
dac45de3
JW
834 }\r
835 } else {\r
836 if (!HttpInstance->LocalAddressIsIPv6) {\r
837 HttpInstance->Tcp4->Cancel (HttpInstance->Tcp4, &HttpInstance->Tcp4TlsRxToken.CompletionToken);\r
47f51a06 838 } else {\r
dac45de3 839 HttpInstance->Tcp6->Cancel (HttpInstance->Tcp6, &HttpInstance->Tcp6TlsRxToken.CompletionToken);\r
47f51a06
YT
840 }\r
841 }\r
dac45de3 842 \r
47f51a06
YT
843 return EFI_SUCCESS;\r
844}\r
845\r
846\r
847/**\r
848 Abort an asynchronous HTTP request or response token.\r
849\r
850 The Cancel() function aborts a pending HTTP request or response transaction. If\r
851 Token is not NULL and the token is in transmit or receive queues when it is being\r
852 cancelled, its Token->Status will be set to EFI_ABORTED and then Token->Event will\r
853 be signaled. If the token is not in one of the queues, which usually means that the\r
854 asynchronous operation has completed, EFI_NOT_FOUND is returned. If Token is NULL,\r
855 all asynchronous tokens issued by Request() or Response() will be aborted.\r
856\r
857 @param[in] This Pointer to EFI_HTTP_PROTOCOL instance.\r
858 @param[in] Token Point to storage containing HTTP request or response\r
859 token.\r
860\r
861 @retval EFI_SUCCESS Request and Response queues are successfully flushed.\r
862 @retval EFI_INVALID_PARAMETER This is NULL.\r
863 @retval EFI_NOT_STARTED This instance hasn't been configured.\r
47f51a06
YT
864 @retval EFI_NOT_FOUND The asynchronous request or response token is not\r
865 found.\r
866 @retval EFI_UNSUPPORTED The implementation does not support this function.\r
867\r
868**/\r
869EFI_STATUS\r
870EFIAPI\r
871EfiHttpCancel (\r
872 IN EFI_HTTP_PROTOCOL *This,\r
873 IN EFI_HTTP_TOKEN *Token\r
874 )\r
875{\r
876 HTTP_PROTOCOL *HttpInstance;\r
877\r
878 if (This == NULL) {\r
879 return EFI_INVALID_PARAMETER;\r
880 }\r
881\r
882 HttpInstance = HTTP_INSTANCE_FROM_PROTOCOL (This);\r
883 ASSERT (HttpInstance != NULL);\r
884\r
885 if (HttpInstance->State != HTTP_STATE_TCP_CONNECTED) {\r
886 return EFI_NOT_STARTED;\r
887 }\r
888\r
889 return HttpCancel (HttpInstance, Token);\r
890\r
891}\r
892\r
893/**\r
894 A callback function to intercept events during message parser.\r
895\r
896 This function will be invoked during HttpParseMessageBody() with various events type. An error\r
897 return status of the callback function will cause the HttpParseMessageBody() aborted.\r
898\r
899 @param[in] EventType Event type of this callback call.\r
900 @param[in] Data A pointer to data buffer.\r
901 @param[in] Length Length in bytes of the Data.\r
902 @param[in] Context Callback context set by HttpInitMsgParser().\r
903\r
904 @retval EFI_SUCCESS Continue to parser the message body.\r
905\r
906**/\r
907EFI_STATUS\r
908EFIAPI\r
909HttpBodyParserCallback (\r
910 IN HTTP_BODY_PARSE_EVENT EventType,\r
911 IN CHAR8 *Data,\r
912 IN UINTN Length,\r
913 IN VOID *Context\r
914 )\r
915{\r
916 HTTP_TOKEN_WRAP *Wrap;\r
5ba9f065
ZL
917 UINTN BodyLength;\r
918 CHAR8 *Body;\r
47f51a06
YT
919\r
920 if (EventType != BodyParseEventOnComplete) {\r
921 return EFI_SUCCESS;\r
922 }\r
923\r
924 if (Data == NULL || Length != 0 || Context == NULL) {\r
925 return EFI_SUCCESS;\r
926 }\r
927\r
928 Wrap = (HTTP_TOKEN_WRAP *) Context;\r
5ba9f065
ZL
929 Body = Wrap->HttpToken->Message->Body;\r
930 BodyLength = Wrap->HttpToken->Message->BodyLength;\r
931 if (Data < Body + BodyLength) {\r
932 Wrap->HttpInstance->NextMsg = Data;\r
933 } else {\r
934 Wrap->HttpInstance->NextMsg = NULL;\r
935 }\r
936 \r
47f51a06
YT
937\r
938 //\r
b659408b 939 // Free Tx4Token or Tx6Token since already received corrsponding HTTP response.\r
47f51a06
YT
940 //\r
941 FreePool (Wrap);\r
942\r
943 return EFI_SUCCESS;\r
944}\r
945\r
946/**\r
947 The work function of EfiHttpResponse().\r
948\r
949 @param[in] Wrap Pointer to HTTP token's wrap data.\r
950\r
951 @retval EFI_SUCCESS Allocation succeeded.\r
952 @retval EFI_OUT_OF_RESOURCES Failed to complete the opration due to lack of resources.\r
b659408b 953 @retval EFI_NOT_READY Can't find a corresponding Tx4Token/Tx6Token or \r
5ca29abe 954 the EFI_HTTP_UTILITIES_PROTOCOL is not available.\r
47f51a06
YT
955\r
956**/\r
957EFI_STATUS\r
958HttpResponseWorker (\r
959 IN HTTP_TOKEN_WRAP *Wrap\r
960 )\r
961{\r
962 EFI_STATUS Status;\r
963 EFI_HTTP_MESSAGE *HttpMsg;\r
47f51a06
YT
964 CHAR8 *EndofHeader;\r
965 CHAR8 *HttpHeaders;\r
966 UINTN SizeofHeaders;\r
47f51a06
YT
967 UINTN BufferSize;\r
968 UINTN StatusCode;\r
969 CHAR8 *Tmp;\r
970 CHAR8 *HeaderTmp;\r
971 CHAR8 *StatusCodeStr;\r
972 UINTN BodyLen;\r
973 HTTP_PROTOCOL *HttpInstance;\r
974 EFI_HTTP_TOKEN *Token;\r
975 NET_MAP_ITEM *Item;\r
976 HTTP_TOKEN_WRAP *ValueInItem;\r
977 UINTN HdrLen;\r
dac45de3 978 NET_FRAGMENT Fragment;\r
47f51a06 979\r
3fd7bd08 980 if (Wrap == NULL || Wrap->HttpInstance == NULL) {\r
981 return EFI_INVALID_PARAMETER;\r
982 }\r
983 \r
47f51a06
YT
984 HttpInstance = Wrap->HttpInstance;\r
985 Token = Wrap->HttpToken;\r
47f51a06
YT
986 HttpMsg = Token->Message;\r
987\r
b659408b
ZL
988 HttpInstance->EndofHeader = NULL;\r
989 HttpInstance->HttpHeaders = NULL;\r
990 HttpMsg->Headers = NULL;\r
991 HttpHeaders = NULL;\r
992 SizeofHeaders = 0;\r
993 BufferSize = 0;\r
994 EndofHeader = NULL;\r
6be1193f 995 ValueInItem = NULL;\r
dac45de3
JW
996 Fragment.Len = 0;\r
997 Fragment.Bulk = NULL;\r
47f51a06
YT
998 \r
999 if (HttpMsg->Data.Response != NULL) {\r
47f51a06
YT
1000 //\r
1001 // Check whether we have cached header from previous call.\r
1002 //\r
1003 if ((HttpInstance->CacheBody != NULL) && (HttpInstance->NextMsg != NULL)) {\r
1004 //\r
1005 // The data is stored at [NextMsg, CacheBody + CacheLen].\r
1006 //\r
1007 HdrLen = HttpInstance->CacheBody + HttpInstance->CacheLen - HttpInstance->NextMsg;\r
1008 HttpHeaders = AllocateZeroPool (HdrLen);\r
1009 if (HttpHeaders == NULL) {\r
1010 Status = EFI_OUT_OF_RESOURCES;\r
1011 goto Error;\r
1012 }\r
1013\r
1014 CopyMem (HttpHeaders, HttpInstance->NextMsg, HdrLen);\r
1015 FreePool (HttpInstance->CacheBody);\r
1016 HttpInstance->CacheBody = NULL;\r
1017 HttpInstance->NextMsg = NULL;\r
1018 HttpInstance->CacheOffset = 0;\r
1019 SizeofHeaders = HdrLen;\r
1020 BufferSize = HttpInstance->CacheLen;\r
1021\r
1022 //\r
1023 // Check whether we cached the whole HTTP headers.\r
1024 //\r
1025 EndofHeader = AsciiStrStr (HttpHeaders, HTTP_END_OF_HDR_STR); \r
b659408b 1026 } \r
47f51a06 1027\r
b659408b
ZL
1028 HttpInstance->EndofHeader = &EndofHeader;\r
1029 HttpInstance->HttpHeaders = &HttpHeaders;\r
47f51a06 1030\r
b347a22a
JW
1031\r
1032 if (HttpInstance->TimeoutEvent == NULL) {\r
1033 //\r
1034 // Create TimeoutEvent for response\r
1035 //\r
1036 Status = gBS->CreateEvent (\r
1037 EVT_TIMER,\r
1038 TPL_CALLBACK,\r
1039 NULL,\r
1040 NULL,\r
1041 &HttpInstance->TimeoutEvent\r
1042 );\r
1043 if (EFI_ERROR (Status)) {\r
1044 goto Error;\r
1045 }\r
1046 }\r
1047\r
1048 //\r
1049 // Start the timer, and wait Timeout seconds to receive the header packet.\r
1050 //\r
1051 Status = gBS->SetTimer (HttpInstance->TimeoutEvent, TimerRelative, HTTP_RESPONSE_TIMEOUT * TICKS_PER_SECOND);\r
1052 if (EFI_ERROR (Status)) {\r
1053 goto Error;\r
1054 }\r
1055\r
1056 Status = HttpTcpReceiveHeader (HttpInstance, &SizeofHeaders, &BufferSize, HttpInstance->TimeoutEvent);\r
1057\r
1058 gBS->SetTimer (HttpInstance->TimeoutEvent, TimerCancel, 0);\r
1059\r
b659408b
ZL
1060 if (EFI_ERROR (Status)) {\r
1061 goto Error;\r
1062 }\r
47f51a06 1063\r
1b96428d
ZL
1064 ASSERT (HttpHeaders != NULL);\r
1065\r
47f51a06
YT
1066 //\r
1067 // Cache the part of body.\r
1068 //\r
1069 BodyLen = BufferSize - (EndofHeader - HttpHeaders);\r
1070 if (BodyLen > 0) {\r
1071 if (HttpInstance->CacheBody != NULL) {\r
1072 FreePool (HttpInstance->CacheBody);\r
1073 }\r
1074\r
1075 HttpInstance->CacheBody = AllocateZeroPool (BodyLen);\r
1076 if (HttpInstance->CacheBody == NULL) {\r
1077 Status = EFI_OUT_OF_RESOURCES;\r
1078 goto Error;\r
1079 }\r
1080\r
1081 CopyMem (HttpInstance->CacheBody, EndofHeader, BodyLen);\r
1082 HttpInstance->CacheLen = BodyLen;\r
1083 }\r
1084\r
47f51a06
YT
1085 //\r
1086 // Search for Status Code.\r
1087 //\r
1088 StatusCodeStr = HttpHeaders + AsciiStrLen (HTTP_VERSION_STR) + 1;\r
1089 if (StatusCodeStr == NULL) {\r
30526a51 1090 Status = EFI_NOT_READY;\r
47f51a06
YT
1091 goto Error;\r
1092 }\r
1093\r
1094 StatusCode = AsciiStrDecimalToUintn (StatusCodeStr);\r
1095\r
1096 //\r
1097 // Remove the first line of HTTP message, e.g. "HTTP/1.1 200 OK\r\n".\r
1098 //\r
1099 Tmp = AsciiStrStr (HttpHeaders, HTTP_CRLF_STR);\r
1100 if (Tmp == NULL) {\r
30526a51 1101 Status = EFI_NOT_READY;\r
47f51a06
YT
1102 goto Error;\r
1103 }\r
1104\r
47f51a06 1105 //\r
d8293d31
NH
1106 // We could have response with just a HTTP message and no headers. For Example,\r
1107 // "100 Continue". In such cases, we would not want to unnecessarily call a Parse\r
1108 // method. A "\r\n" following Tmp string again would indicate an end. Compare and\r
1109 // set SizeofHeaders to 0.\r
47f51a06 1110 //\r
d8293d31
NH
1111 Tmp = Tmp + AsciiStrLen (HTTP_CRLF_STR);\r
1112 if (CompareMem (Tmp, HTTP_CRLF_STR, AsciiStrLen (HTTP_CRLF_STR)) == 0) {\r
1113 SizeofHeaders = 0;\r
1114 } else {\r
1115 SizeofHeaders = SizeofHeaders - (Tmp - HttpHeaders);\r
47f51a06
YT
1116 }\r
1117\r
47f51a06 1118 HttpMsg->Data.Response->StatusCode = HttpMappingToStatusCode (StatusCode);\r
072289f4 1119 HttpInstance->StatusCode = StatusCode;\r
d8293d31 1120\r
47f51a06
YT
1121 Status = EFI_NOT_READY;\r
1122 ValueInItem = NULL;\r
47f51a06
YT
1123\r
1124 //\r
97c567ef 1125 // In cases of PUT/POST/PATCH, after an initial request-response pair, we would do a\r
d8293d31
NH
1126 // continuous request without a response call. So, we would not do an insert of\r
1127 // TxToken. After we have sent the complete file, we will call a response to get\r
1128 // a final response from server. In such a case, we would not have any TxTokens.\r
1129 // Hence, check that case before doing a NetMapRemoveHead.\r
47f51a06 1130 //\r
d8293d31
NH
1131 if (!NetMapIsEmpty (&HttpInstance->TxTokens)) {\r
1132 NetMapRemoveHead (&HttpInstance->TxTokens, (VOID**) &ValueInItem);\r
1133 if (ValueInItem == NULL) {\r
1134 goto Error;\r
1135 }\r
47f51a06 1136\r
d8293d31
NH
1137 //\r
1138 // The first Tx Token not transmitted yet, insert back and return error.\r
1139 //\r
1140 if (!ValueInItem->TcpWrap.IsTxDone) {\r
1141 goto Error2;\r
1142 }\r
47f51a06
YT
1143 }\r
1144\r
d8293d31
NH
1145 if (SizeofHeaders != 0) {\r
1146 HeaderTmp = AllocateZeroPool (SizeofHeaders);\r
1147 if (HeaderTmp == NULL) {\r
30526a51 1148 Status = EFI_OUT_OF_RESOURCES;\r
5646819f 1149 goto Error2;\r
d8293d31
NH
1150 }\r
1151\r
1152 CopyMem (HeaderTmp, Tmp, SizeofHeaders);\r
1153 FreePool (HttpHeaders);\r
1154 HttpHeaders = HeaderTmp;\r
1155\r
1156 //\r
1157 // Check whether the EFI_HTTP_UTILITIES_PROTOCOL is available.\r
1158 //\r
1159 if (mHttpUtilities == NULL) {\r
1160 Status = EFI_NOT_READY;\r
5646819f 1161 goto Error2;\r
d8293d31
NH
1162 }\r
1163\r
1164 //\r
1165 // Parse the HTTP header into array of key/value pairs.\r
1166 //\r
1167 Status = mHttpUtilities->Parse (\r
1168 mHttpUtilities,\r
1169 HttpHeaders,\r
1170 SizeofHeaders,\r
1171 &HttpMsg->Headers,\r
1172 &HttpMsg->HeaderCount\r
1173 );\r
1174 if (EFI_ERROR (Status)) {\r
5646819f 1175 goto Error2;\r
d8293d31
NH
1176 }\r
1177\r
1178 FreePool (HttpHeaders);\r
1179 HttpHeaders = NULL;\r
1180\r
1181\r
1182 //\r
1183 // Init message-body parser by header information.\r
1184 //\r
1185 Status = HttpInitMsgParser (\r
1186 HttpInstance->Method,\r
1187 HttpMsg->Data.Response->StatusCode,\r
1188 HttpMsg->HeaderCount,\r
1189 HttpMsg->Headers,\r
1190 HttpBodyParserCallback,\r
1191 (VOID *) ValueInItem,\r
1192 &HttpInstance->MsgParser\r
1193 );\r
47f51a06
YT
1194 if (EFI_ERROR (Status)) {\r
1195 goto Error2;\r
1196 }\r
1197\r
d8293d31
NH
1198 //\r
1199 // Check whether we received a complete HTTP message.\r
1200 //\r
1201 if (HttpInstance->CacheBody != NULL) {\r
1202 Status = HttpParseMessageBody (HttpInstance->MsgParser, HttpInstance->CacheLen, HttpInstance->CacheBody);\r
1203 if (EFI_ERROR (Status)) {\r
1204 goto Error2;\r
1205 }\r
1206\r
1207 if (HttpIsMessageComplete (HttpInstance->MsgParser)) {\r
1208 //\r
1209 // Free the MsgParse since we already have a full HTTP message.\r
1210 //\r
1211 HttpFreeMsgParser (HttpInstance->MsgParser);\r
1212 HttpInstance->MsgParser = NULL;\r
1213 }\r
47f51a06
YT
1214 }\r
1215 }\r
1216\r
d8293d31 1217 if ((HttpMsg->Body == NULL) || (HttpMsg->BodyLength == 0)) {\r
47f51a06
YT
1218 Status = EFI_SUCCESS;\r
1219 goto Exit;\r
1220 }\r
d8293d31 1221 }\r
47f51a06
YT
1222\r
1223 //\r
1224 // Receive the response body.\r
1225 //\r
1226 BodyLen = 0;\r
1227\r
1228 //\r
1229 // First check whether we cached some data.\r
1230 //\r
1231 if (HttpInstance->CacheBody != NULL) {\r
1232 //\r
1233 // Calculate the length of the cached data.\r
1234 //\r
1235 if (HttpInstance->NextMsg != NULL) {\r
1236 //\r
1237 // We have a cached HTTP message which includes a part of HTTP header of next message.\r
1238 //\r
1239 BodyLen = HttpInstance->NextMsg - (HttpInstance->CacheBody + HttpInstance->CacheOffset); \r
1240 } else {\r
1241 BodyLen = HttpInstance->CacheLen - HttpInstance->CacheOffset;\r
1242 }\r
1243\r
1244 if (BodyLen > 0) {\r
1245 //\r
1246 // We have some cached data. Just copy the data and return.\r
1247 //\r
1248 if (HttpMsg->BodyLength < BodyLen) {\r
1249 CopyMem (HttpMsg->Body, HttpInstance->CacheBody + HttpInstance->CacheOffset, HttpMsg->BodyLength);\r
1250 HttpInstance->CacheOffset = HttpInstance->CacheOffset + HttpMsg->BodyLength;\r
1251 } else {\r
1252 //\r
1253 // Copy all cached data out.\r
1254 //\r
1255 CopyMem (HttpMsg->Body, HttpInstance->CacheBody + HttpInstance->CacheOffset, BodyLen);\r
1256 HttpInstance->CacheOffset = BodyLen + HttpInstance->CacheOffset;\r
1257 HttpMsg->BodyLength = BodyLen;\r
1258\r
1259 if (HttpInstance->NextMsg == NULL) {\r
1260 //\r
1261 // There is no HTTP header of next message. Just free the cache buffer.\r
1262 //\r
1263 FreePool (HttpInstance->CacheBody);\r
1264 HttpInstance->CacheBody = NULL;\r
1265 HttpInstance->NextMsg = NULL;\r
1266 HttpInstance->CacheOffset = 0;\r
1267 }\r
1268 }\r
1269 //\r
1270 // Return since we aready received required data.\r
1271 //\r
1272 Status = EFI_SUCCESS;\r
1273 goto Exit;\r
1274 } \r
1275\r
1276 if (BodyLen == 0 && HttpInstance->MsgParser == NULL) {\r
1277 //\r
1278 // We received a complete HTTP message, and we don't have more data to return to caller.\r
1279 //\r
1280 HttpMsg->BodyLength = 0;\r
1281 Status = EFI_SUCCESS;\r
1282 goto Exit; \r
1283 } \r
1284 }\r
1285\r
1286 ASSERT (HttpInstance->MsgParser != NULL);\r
1287\r
1288 //\r
1289 // We still need receive more data when there is no cache data and MsgParser is not NULL;\r
1290 //\r
dac45de3
JW
1291 if (!HttpInstance->UseHttps) {\r
1292 Status = HttpTcpReceiveBody (Wrap, HttpMsg);\r
1293\r
1294 if (EFI_ERROR (Status)) {\r
1295 goto Error2;\r
1296 }\r
1297 \r
1298 } else {\r
1299 if (HttpInstance->TimeoutEvent == NULL) {\r
1300 //\r
1301 // Create TimeoutEvent for response\r
1302 //\r
1303 Status = gBS->CreateEvent (\r
1304 EVT_TIMER,\r
1305 TPL_CALLBACK,\r
1306 NULL,\r
1307 NULL,\r
1308 &HttpInstance->TimeoutEvent\r
1309 );\r
1310 if (EFI_ERROR (Status)) {\r
1311 goto Error2;\r
1312 }\r
1313 }\r
1314\r
1315 //\r
1316 // Start the timer, and wait Timeout seconds to receive the body packet.\r
1317 //\r
1318 Status = gBS->SetTimer (HttpInstance->TimeoutEvent, TimerRelative, HTTP_RESPONSE_TIMEOUT * TICKS_PER_SECOND);\r
1319 if (EFI_ERROR (Status)) {\r
1320 goto Error2;\r
1321 }\r
1322 \r
1323 Status = HttpsReceive (HttpInstance, &Fragment, HttpInstance->TimeoutEvent);\r
1324\r
1325 gBS->SetTimer (HttpInstance->TimeoutEvent, TimerCancel, 0);\r
1326 \r
1327 if (EFI_ERROR (Status)) {\r
1328 goto Error2;\r
1329 }\r
1330\r
1331 //\r
1332 // Check whether we receive a complete HTTP message.\r
1333 //\r
1334 Status = HttpParseMessageBody (\r
1335 HttpInstance->MsgParser,\r
1336 (UINTN) Fragment.Len,\r
1337 (CHAR8 *) Fragment.Bulk\r
1338 );\r
1339 if (EFI_ERROR (Status)) {\r
1340 goto Error2;\r
1341 }\r
1342\r
1343 if (HttpIsMessageComplete (HttpInstance->MsgParser)) {\r
1344 //\r
1345 // Free the MsgParse since we already have a full HTTP message.\r
1346 //\r
1347 HttpFreeMsgParser (HttpInstance->MsgParser);\r
1348 HttpInstance->MsgParser = NULL;\r
1349 }\r
1350\r
1351 //\r
1352 // We receive part of header of next HTTP msg.\r
1353 //\r
1354 if (HttpInstance->NextMsg != NULL) {\r
cb7dbc13 1355 HttpMsg->BodyLength = MIN ((UINTN) HttpInstance->NextMsg - (UINTN) Fragment.Bulk, HttpMsg->BodyLength);\r
dac45de3
JW
1356 CopyMem (HttpMsg->Body, Fragment.Bulk, HttpMsg->BodyLength);\r
1357 \r
1358 HttpInstance->CacheLen = Fragment.Len - HttpMsg->BodyLength;\r
1359 if (HttpInstance->CacheLen != 0) {\r
1360 if (HttpInstance->CacheBody != NULL) {\r
1361 FreePool (HttpInstance->CacheBody);\r
1362 }\r
1363 \r
1364 HttpInstance->CacheBody = AllocateZeroPool (HttpInstance->CacheLen);\r
1365 if (HttpInstance->CacheBody == NULL) {\r
1366 Status = EFI_OUT_OF_RESOURCES;\r
1367 goto Error2;\r
1368 }\r
1369 \r
1370 CopyMem (HttpInstance->CacheBody, Fragment.Bulk + HttpMsg->BodyLength, HttpInstance->CacheLen);\r
1371 HttpInstance->CacheOffset = 0;\r
1372\r
cb7dbc13 1373 HttpInstance->NextMsg = HttpInstance->CacheBody + ((UINTN) HttpInstance->NextMsg - (UINTN) (Fragment.Bulk + HttpMsg->BodyLength));\r
dac45de3
JW
1374 }\r
1375 } else {\r
1376 HttpMsg->BodyLength = MIN (Fragment.Len, (UINT32) HttpMsg->BodyLength);\r
1377 CopyMem (HttpMsg->Body, Fragment.Bulk, HttpMsg->BodyLength);\r
1378 HttpInstance->CacheLen = Fragment.Len - HttpMsg->BodyLength;\r
1379 if (HttpInstance->CacheLen != 0) {\r
1380 if (HttpInstance->CacheBody != NULL) {\r
1381 FreePool (HttpInstance->CacheBody);\r
1382 }\r
1383 \r
1384 HttpInstance->CacheBody = AllocateZeroPool (HttpInstance->CacheLen);\r
1385 if (HttpInstance->CacheBody == NULL) {\r
1386 Status = EFI_OUT_OF_RESOURCES;\r
1387 goto Error2;\r
1388 }\r
1389\r
1390 CopyMem (HttpInstance->CacheBody, Fragment.Bulk + HttpMsg->BodyLength, HttpInstance->CacheLen);\r
1391 HttpInstance->CacheOffset = 0;\r
1392 }\r
1393 }\r
1394\r
1395 if (Fragment.Bulk != NULL) {\r
1396 FreePool (Fragment.Bulk);\r
1397 Fragment.Bulk = NULL;\r
1398 }\r
1399\r
1400 goto Exit;\r
47f51a06
YT
1401 }\r
1402\r
1403 return Status;\r
1404\r
1405Exit:\r
1406 Item = NetMapFindKey (&Wrap->HttpInstance->RxTokens, Wrap->HttpToken);\r
1407 if (Item != NULL) {\r
1408 NetMapRemoveItem (&Wrap->HttpInstance->RxTokens, Item, NULL);\r
1409 }\r
072289f4
ZL
1410\r
1411 if (HttpInstance->StatusCode >= HTTP_ERROR_OR_NOT_SUPPORT_STATUS_CODE) {\r
1412 Token->Status = EFI_HTTP_ERROR;\r
1413 } else {\r
1414 Token->Status = Status;\r
1415 }\r
1416\r
47f51a06 1417 gBS->SignalEvent (Token->Event);\r
b659408b 1418 HttpCloseTcpRxEvent (Wrap);\r
47f51a06
YT
1419 FreePool (Wrap);\r
1420 return Status;\r
1421\r
1422Error2:\r
5646819f
FS
1423 if (ValueInItem != NULL) {\r
1424 NetMapInsertHead (&HttpInstance->TxTokens, ValueInItem->HttpToken, ValueInItem);\r
1425 }\r
47f51a06
YT
1426\r
1427Error:\r
30526a51
JW
1428 Item = NetMapFindKey (&Wrap->HttpInstance->RxTokens, Wrap->HttpToken);\r
1429 if (Item != NULL) {\r
1430 NetMapRemoveItem (&Wrap->HttpInstance->RxTokens, Item, NULL);\r
1431 }\r
dac45de3
JW
1432\r
1433 if (!HttpInstance->UseHttps) {\r
1434 HttpTcpTokenCleanup (Wrap);\r
1435 } else {\r
1436 FreePool (Wrap);\r
1437 }\r
47f51a06
YT
1438 \r
1439 if (HttpHeaders != NULL) {\r
1440 FreePool (HttpHeaders);\r
dac45de3
JW
1441 HttpHeaders = NULL;\r
1442 }\r
1443\r
1444 if (Fragment.Bulk != NULL) {\r
1445 FreePool (Fragment.Bulk);\r
1446 Fragment.Bulk = NULL;\r
47f51a06
YT
1447 }\r
1448\r
1449 if (HttpMsg->Headers != NULL) {\r
1450 FreePool (HttpMsg->Headers);\r
dac45de3 1451 HttpMsg->Headers = NULL;\r
47f51a06
YT
1452 }\r
1453\r
1454 if (HttpInstance->CacheBody != NULL) {\r
1455 FreePool (HttpInstance->CacheBody);\r
1456 HttpInstance->CacheBody = NULL;\r
1457 }\r
1458\r
072289f4
ZL
1459 if (HttpInstance->StatusCode >= HTTP_ERROR_OR_NOT_SUPPORT_STATUS_CODE) {\r
1460 Token->Status = EFI_HTTP_ERROR;\r
1461 } else {\r
1462 Token->Status = Status;\r
1463 }\r
1464\r
47f51a06
YT
1465 gBS->SignalEvent (Token->Event);\r
1466\r
1467 return Status; \r
1468\r
1469}\r
1470\r
1471\r
1472/**\r
1473 The Response() function queues an HTTP response to this HTTP instance, similar to\r
f0ab5a81 1474 Receive() function in the EFI TCP driver. When the HTTP response is received successfully,\r
47f51a06
YT
1475 or if there is an error, Status in token will be updated and Event will be signaled.\r
1476\r
1477 The HTTP driver will queue a receive token to the underlying TCP instance. When data\r
1478 is received in the underlying TCP instance, the data will be parsed and Token will\r
1479 be populated with the response data. If the data received from the remote host\r
1480 contains an incomplete or invalid HTTP header, the HTTP driver will continue waiting\r
1481 (asynchronously) for more data to be sent from the remote host before signaling\r
1482 Event in Token.\r
1483\r
1484 It is the responsibility of the caller to allocate a buffer for Body and specify the\r
1485 size in BodyLength. If the remote host provides a response that contains a content\r
1486 body, up to BodyLength bytes will be copied from the receive buffer into Body and\r
1487 BodyLength will be updated with the amount of bytes received and copied to Body. This\r
1488 allows the client to download a large file in chunks instead of into one contiguous\r
1489 block of memory. Similar to HTTP request, if Body is not NULL and BodyLength is\r
1490 non-zero and all other fields are NULL or 0, the HTTP driver will queue a receive\r
1491 token to underlying TCP instance. If data arrives in the receive buffer, up to\r
1492 BodyLength bytes of data will be copied to Body. The HTTP driver will then update\r
1493 BodyLength with the amount of bytes received and copied to Body.\r
1494\r
1495 If the HTTP driver does not have an open underlying TCP connection with the host\r
1496 specified in the response URL, Request() will return EFI_ACCESS_DENIED. This is\r
1497 consistent with RFC 2616 recommendation that HTTP clients should attempt to maintain\r
1498 an open TCP connection between client and host.\r
1499\r
1500 @param[in] This Pointer to EFI_HTTP_PROTOCOL instance.\r
1501 @param[in] Token Pointer to storage containing HTTP response token.\r
1502\r
1503 @retval EFI_SUCCESS Allocation succeeded.\r
1504 @retval EFI_NOT_STARTED This EFI HTTP Protocol instance has not been\r
1505 initialized.\r
1506 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:\r
1507 This is NULL.\r
1508 Token is NULL.\r
1509 Token->Message->Headers is NULL.\r
1510 Token->Message is NULL.\r
1511 Token->Message->Body is not NULL,\r
1512 Token->Message->BodyLength is non-zero, and\r
1513 Token->Message->Data is NULL, but a previous call to\r
1514 Response() has not been completed successfully.\r
1515 @retval EFI_OUT_OF_RESOURCES Could not allocate enough system resources.\r
1516 @retval EFI_ACCESS_DENIED An open TCP connection is not present with the host\r
1517 specified by response URL.\r
1518**/\r
1519EFI_STATUS\r
1520EFIAPI\r
1521EfiHttpResponse (\r
1522 IN EFI_HTTP_PROTOCOL *This,\r
1523 IN EFI_HTTP_TOKEN *Token\r
1524 )\r
1525{\r
1526 EFI_STATUS Status;\r
1527 EFI_HTTP_MESSAGE *HttpMsg;\r
1528 HTTP_PROTOCOL *HttpInstance;\r
1529 HTTP_TOKEN_WRAP *Wrap;\r
1530\r
1531 if ((This == NULL) || (Token == NULL)) {\r
1532 return EFI_INVALID_PARAMETER;\r
1533 }\r
1534\r
1535 HttpMsg = Token->Message;\r
1536 if (HttpMsg == NULL) {\r
1537 return EFI_INVALID_PARAMETER;\r
1538 }\r
1539 \r
1540 HttpInstance = HTTP_INSTANCE_FROM_PROTOCOL (This);\r
1541 ASSERT (HttpInstance != NULL);\r
1542\r
1543 if (HttpInstance->State != HTTP_STATE_TCP_CONNECTED) {\r
1544 return EFI_NOT_STARTED;\r
1545 }\r
1546\r
47f51a06
YT
1547 //\r
1548 // Check whether the token already existed.\r
1549 //\r
1550 if (EFI_ERROR (NetMapIterate (&HttpInstance->RxTokens, HttpTokenExist, Token))) {\r
1551 return EFI_ACCESS_DENIED; \r
1552 }\r
1553\r
1554 Wrap = AllocateZeroPool (sizeof (HTTP_TOKEN_WRAP));\r
1555 if (Wrap == NULL) {\r
1556 return EFI_OUT_OF_RESOURCES;\r
1557 }\r
1558\r
1559 Wrap->HttpInstance = HttpInstance;\r
1560 Wrap->HttpToken = Token;\r
1561\r
dac45de3
JW
1562 //\r
1563 // Notes: For Https, receive token wrapped in HTTP_TOKEN_WRAP is not used to \r
1564 // receive the https response. A special TlsRxToken is used for receiving TLS \r
1565 // related messages. It should be a blocking response.\r
1566 //\r
1567 if (!HttpInstance->UseHttps) {\r
1568 Status = HttpCreateTcpRxEvent (Wrap);\r
1569 if (EFI_ERROR (Status)) {\r
1570 goto Error;\r
1571 }\r
47f51a06
YT
1572 }\r
1573\r
1574 Status = NetMapInsertTail (&HttpInstance->RxTokens, Token, Wrap);\r
1575 if (EFI_ERROR (Status)) {\r
1576 goto Error;\r
1577 }\r
1578\r
1579 //\r
1580 // If already have pending RxTokens, return directly.\r
1581 //\r
1582 if (NetMapGetCount (&HttpInstance->RxTokens) > 1) {\r
1583 return EFI_SUCCESS;\r
1584 }\r
1585\r
1586 return HttpResponseWorker (Wrap);\r
1587\r
1588Error:\r
1589 if (Wrap != NULL) {\r
b659408b
ZL
1590 if (Wrap->TcpWrap.Rx4Token.CompletionToken.Event != NULL) {\r
1591 gBS->CloseEvent (Wrap->TcpWrap.Rx4Token.CompletionToken.Event);\r
1592 }\r
1593\r
1594 if (Wrap->TcpWrap.Rx6Token.CompletionToken.Event != NULL) {\r
1595 gBS->CloseEvent (Wrap->TcpWrap.Rx6Token.CompletionToken.Event);\r
47f51a06
YT
1596 }\r
1597 FreePool (Wrap);\r
1598 } \r
1599\r
1600 return Status; \r
1601}\r
1602\r
1603/**\r
1604 The Poll() function can be used by network drivers and applications to increase the\r
1605 rate that data packets are moved between the communication devices and the transmit\r
1606 and receive queues.\r
1607\r
1608 In some systems, the periodic timer event in the managed network driver may not poll\r
1609 the underlying communications device fast enough to transmit and/or receive all data\r
1610 packets without missing incoming packets or dropping outgoing packets. Drivers and\r
1611 applications that are experiencing packet loss should try calling the Poll() function\r
1612 more often.\r
1613\r
1614 @param[in] This Pointer to EFI_HTTP_PROTOCOL instance.\r
1615\r
1616 @retval EFI_SUCCESS Incoming or outgoing data was processed.\r
1617 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.\r
1618 @retval EFI_INVALID_PARAMETER This is NULL.\r
1619 @retval EFI_NOT_READY No incoming or outgoing data is processed.\r
1620 @retval EFI_NOT_STARTED This EFI HTTP Protocol instance has not been started.\r
1621\r
1622**/\r
1623EFI_STATUS\r
1624EFIAPI\r
1625EfiHttpPoll (\r
1626 IN EFI_HTTP_PROTOCOL *This\r
1627 )\r
1628{\r
49c9f74c 1629 EFI_STATUS Status;\r
b659408b 1630 HTTP_PROTOCOL *HttpInstance;\r
47f51a06
YT
1631\r
1632 if (This == NULL) {\r
1633 return EFI_INVALID_PARAMETER;\r
1634 }\r
1635\r
1636 HttpInstance = HTTP_INSTANCE_FROM_PROTOCOL (This);\r
1637 ASSERT (HttpInstance != NULL);\r
1638\r
1b96428d 1639 if (HttpInstance->State != HTTP_STATE_TCP_CONNECTED) {\r
47f51a06
YT
1640 return EFI_NOT_STARTED;\r
1641 }\r
b659408b
ZL
1642 \r
1643 if (HttpInstance->LocalAddressIsIPv6) {\r
1b96428d
ZL
1644 if (HttpInstance->Tcp6 == NULL) {\r
1645 return EFI_NOT_STARTED;\r
1646 }\r
b659408b
ZL
1647 Status = HttpInstance->Tcp6->Poll (HttpInstance->Tcp6);\r
1648 } else {\r
1b96428d
ZL
1649 if (HttpInstance->Tcp4 == NULL) {\r
1650 return EFI_NOT_STARTED;\r
1651 }\r
b659408b
ZL
1652 Status = HttpInstance->Tcp4->Poll (HttpInstance->Tcp4);\r
1653 }\r
1654 \r
49c9f74c 1655 DispatchDpc ();\r
b659408b 1656 \r
49c9f74c 1657 return Status;\r
47f51a06 1658}\r