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