X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=NetworkPkg%2FHttpDxe%2FHttpImpl.c;h=6b877314bd571ebd8f033ced9fbe5a9c40f84f52;hb=4542f8b8135f1f1ee5654e25139be9769e139ddd;hp=f70e116f38d7e78f7bfc131c343b26aa4bc622bc;hpb=f75a7f568e6d0944327970b3f3f2dafd9bba76b1;p=mirror_edk2.git diff --git a/NetworkPkg/HttpDxe/HttpImpl.c b/NetworkPkg/HttpDxe/HttpImpl.c index f70e116f38..6b877314bd 100644 --- a/NetworkPkg/HttpDxe/HttpImpl.c +++ b/NetworkPkg/HttpDxe/HttpImpl.c @@ -4,13 +4,7 @@ Copyright (c) 2015 - 2018, Intel Corporation. All rights reserved.
(C) Copyright 2015-2016 Hewlett Packard Enterprise Development LP
- This program and the accompanying materials - are licensed and made available under the terms and conditions of the BSD License - which accompanies this distribution. The full text of the license may be found at - http://opensource.org/licenses/bsd-license.php. - - THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, - WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. + SPDX-License-Identifier: BSD-2-Clause-Patent **/ @@ -405,10 +399,22 @@ EfiHttpRequest ( goto Error1; } - HostName = NULL; - Status = HttpUrlGetHostName (Url, UrlParser, &HostName); + Status = HttpUrlGetHostName (Url, UrlParser, &HostName); if (EFI_ERROR (Status)) { - goto Error1; + goto Error1; + } + + if (HttpInstance->LocalAddressIsIPv6) { + HostNameSize = AsciiStrSize (HostName); + + if (HostNameSize > 2 && HostName[0] == '[' && HostName[HostNameSize - 2] == ']') { + // + // HostName format is expressed as IPv6, so, remove '[' and ']'. + // + HostNameSize -= 2; + CopyMem (HostName, HostName + 1, HostNameSize - 1); + HostName[HostNameSize - 1] = '\0'; + } } Status = HttpUrlGetPort (Url, UrlParser, &RemotePort); @@ -916,6 +922,7 @@ HttpBodyParserCallback ( IN VOID *Context ) { + HTTP_CALLBACK_DATA *CallbackData; HTTP_TOKEN_WRAP *Wrap; UINTN BodyLength; CHAR8 *Body; @@ -928,21 +935,18 @@ HttpBodyParserCallback ( return EFI_SUCCESS; } - Wrap = (HTTP_TOKEN_WRAP *) Context; - Body = Wrap->HttpToken->Message->Body; - BodyLength = Wrap->HttpToken->Message->BodyLength; + CallbackData = (HTTP_CALLBACK_DATA *) Context; + + Wrap = (HTTP_TOKEN_WRAP *) (CallbackData->Wrap); + Body = CallbackData->ParseData; + BodyLength = CallbackData->ParseDataLength; + if (Data < Body + BodyLength) { Wrap->HttpInstance->NextMsg = Data; } else { Wrap->HttpInstance->NextMsg = NULL; } - - // - // Free Tx4Token or Tx6Token since already received corrsponding HTTP response. - // - FreePool (Wrap); - return EFI_SUCCESS; } @@ -1191,7 +1195,7 @@ HttpResponseWorker ( HttpMsg->HeaderCount, HttpMsg->Headers, HttpBodyParserCallback, - (VOID *) ValueInItem, + (VOID *) (&HttpInstance->CallbackData), &HttpInstance->MsgParser ); if (EFI_ERROR (Status)) { @@ -1202,18 +1206,28 @@ HttpResponseWorker ( // Check whether we received a complete HTTP message. // if (HttpInstance->CacheBody != NULL) { + // + // Record the CallbackData data. + // + HttpInstance->CallbackData.Wrap = (VOID *) Wrap; + HttpInstance->CallbackData.ParseData = (VOID *) HttpInstance->CacheBody; + HttpInstance->CallbackData.ParseDataLength = HttpInstance->CacheLen; + + // + // Parse message with CallbackData data. + // Status = HttpParseMessageBody (HttpInstance->MsgParser, HttpInstance->CacheLen, HttpInstance->CacheBody); if (EFI_ERROR (Status)) { goto Error2; } + } - if (HttpIsMessageComplete (HttpInstance->MsgParser)) { - // - // Free the MsgParse since we already have a full HTTP message. - // - HttpFreeMsgParser (HttpInstance->MsgParser); - HttpInstance->MsgParser = NULL; - } + if (HttpIsMessageComplete (HttpInstance->MsgParser)) { + // + // Free the MsgParse since we already have a full HTTP message. + // + HttpFreeMsgParser (HttpInstance->MsgParser); + HttpInstance->MsgParser = NULL; } } @@ -1332,12 +1346,26 @@ HttpResponseWorker ( } // - // Check whether we receive a complete HTTP message. + // Process the received the body packet. + // + HttpMsg->BodyLength = MIN (Fragment.Len, (UINT32) HttpMsg->BodyLength); + + CopyMem (HttpMsg->Body, Fragment.Bulk, HttpMsg->BodyLength); + + // + // Record the CallbackData data. + // + HttpInstance->CallbackData.Wrap = (VOID *) Wrap; + HttpInstance->CallbackData.ParseData = HttpMsg->Body; + HttpInstance->CallbackData.ParseDataLength = HttpMsg->BodyLength; + + // + // Parse Body with CallbackData data. // Status = HttpParseMessageBody ( HttpInstance->MsgParser, - (UINTN) Fragment.Len, - (CHAR8 *) Fragment.Bulk + HttpMsg->BodyLength, + HttpMsg->Body ); if (EFI_ERROR (Status)) { goto Error2; @@ -1352,46 +1380,28 @@ HttpResponseWorker ( } // - // We receive part of header of next HTTP msg. + // Check whether there is the next message header in the HttpMsg->Body. // if (HttpInstance->NextMsg != NULL) { - HttpMsg->BodyLength = MIN ((UINTN) HttpInstance->NextMsg - (UINTN) Fragment.Bulk, HttpMsg->BodyLength); - CopyMem (HttpMsg->Body, Fragment.Bulk, HttpMsg->BodyLength); - - HttpInstance->CacheLen = Fragment.Len - HttpMsg->BodyLength; - if (HttpInstance->CacheLen != 0) { - if (HttpInstance->CacheBody != NULL) { - FreePool (HttpInstance->CacheBody); - } - - HttpInstance->CacheBody = AllocateZeroPool (HttpInstance->CacheLen); - if (HttpInstance->CacheBody == NULL) { - Status = EFI_OUT_OF_RESOURCES; - goto Error2; - } - - CopyMem (HttpInstance->CacheBody, Fragment.Bulk + HttpMsg->BodyLength, HttpInstance->CacheLen); - HttpInstance->CacheOffset = 0; + HttpMsg->BodyLength = HttpInstance->NextMsg - (CHAR8 *) HttpMsg->Body; + } - HttpInstance->NextMsg = HttpInstance->CacheBody + ((UINTN) HttpInstance->NextMsg - (UINTN) (Fragment.Bulk + HttpMsg->BodyLength)); + HttpInstance->CacheLen = Fragment.Len - HttpMsg->BodyLength; + if (HttpInstance->CacheLen != 0) { + if (HttpInstance->CacheBody != NULL) { + FreePool (HttpInstance->CacheBody); } - } else { - HttpMsg->BodyLength = MIN (Fragment.Len, (UINT32) HttpMsg->BodyLength); - CopyMem (HttpMsg->Body, Fragment.Bulk, HttpMsg->BodyLength); - HttpInstance->CacheLen = Fragment.Len - HttpMsg->BodyLength; - if (HttpInstance->CacheLen != 0) { - if (HttpInstance->CacheBody != NULL) { - FreePool (HttpInstance->CacheBody); - } - HttpInstance->CacheBody = AllocateZeroPool (HttpInstance->CacheLen); - if (HttpInstance->CacheBody == NULL) { - Status = EFI_OUT_OF_RESOURCES; - goto Error2; - } + HttpInstance->CacheBody = AllocateZeroPool (HttpInstance->CacheLen); + if (HttpInstance->CacheBody == NULL) { + Status = EFI_OUT_OF_RESOURCES; + goto Error2; + } - CopyMem (HttpInstance->CacheBody, Fragment.Bulk + HttpMsg->BodyLength, HttpInstance->CacheLen); - HttpInstance->CacheOffset = 0; + CopyMem (HttpInstance->CacheBody, Fragment.Bulk + HttpMsg->BodyLength, HttpInstance->CacheLen); + HttpInstance->CacheOffset = 0; + if (HttpInstance->NextMsg != NULL) { + HttpInstance->NextMsg = HttpInstance->CacheBody; } }