X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;ds=sidebyside;f=NetworkPkg%2FHttpBootDxe%2FHttpBootClient.c;h=2ccac8c842073e16c2697ce6dcf3759370e8e554;hb=90f658c460736462d8955c0be7e4c0fa57097586;hp=b81b03c96070400db493e148f53ebfcb1e4cb2a4;hpb=b659408b933f40765960e877de3e1f8ceaab52cb;p=mirror_edk2.git diff --git a/NetworkPkg/HttpBootDxe/HttpBootClient.c b/NetworkPkg/HttpBootDxe/HttpBootClient.c index b81b03c960..2ccac8c842 100644 --- a/NetworkPkg/HttpBootDxe/HttpBootClient.c +++ b/NetworkPkg/HttpBootDxe/HttpBootClient.c @@ -1,7 +1,8 @@ /** @file Implementation of the boot file download function. -Copyright (c) 2015, Intel Corporation. All rights reserved.
+Copyright (c) 2015 - 2016, Intel Corporation. All rights reserved.
+(C) Copyright 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 that accompanies this distribution. The full text of the license may be found at @@ -456,81 +457,6 @@ HttpBootCreateHttpIo ( return EFI_SUCCESS; } -/** - Get the file content from cached data. - - @param[in] Private The pointer to the driver's private data. - @param[in] Uri Uri of the file to be retrieved from cache. - @param[in, out] BufferSize On input the size of Buffer in bytes. On output with a return - code of EFI_SUCCESS, the amount of data transferred to - Buffer. On output with a return code of EFI_BUFFER_TOO_SMALL, - the size of Buffer required to retrieve the requested file. - @param[out] Buffer The memory buffer to transfer the file to. IF Buffer is NULL, - then the size of the requested file is returned in - BufferSize. - - @retval EFI_SUCCESS Successfully created. - @retval Others Failed to create HttpIo. - -**/ -EFI_STATUS -HttpBootGetFileFromCache ( - IN HTTP_BOOT_PRIVATE_DATA *Private, - IN CHAR16 *Uri, - IN OUT UINTN *BufferSize, - OUT UINT8 *Buffer - ) -{ - LIST_ENTRY *Entry; - LIST_ENTRY *Entry2; - HTTP_BOOT_CACHE_CONTENT *Cache; - HTTP_BOOT_ENTITY_DATA *EntityData; - UINTN CopyedSize; - - if (Uri == NULL || BufferSize == 0 || Buffer == NULL) { - return EFI_INVALID_PARAMETER; - } - - NET_LIST_FOR_EACH (Entry, &Private->CacheList) { - Cache = NET_LIST_USER_STRUCT (Entry, HTTP_BOOT_CACHE_CONTENT, Link); - // - // Compare the URI to see whether we already have a cache for this file. - // - if ((Cache->RequestData != NULL) && - (Cache->RequestData->Url != NULL) && - (StrCmp (Uri, Cache->RequestData->Url) == 0)) - { - // - // Hit cache, check buffer size. - // - if (*BufferSize < Cache->EntityLength) { - *BufferSize = Cache->EntityLength; - return EFI_BUFFER_TOO_SMALL; - } - - // - // Fill data to buffer. - // - CopyedSize = 0; - NET_LIST_FOR_EACH (Entry2, &Cache->EntityDataList) { - EntityData = NET_LIST_USER_STRUCT (Entry2, HTTP_BOOT_ENTITY_DATA, Link); - if (*BufferSize > CopyedSize) { - CopyMem ( - Buffer + CopyedSize, - EntityData->DataStart, - MIN (EntityData->DataLength, *BufferSize - CopyedSize) - ); - CopyedSize += MIN (EntityData->DataLength, *BufferSize - CopyedSize); - } - } - *BufferSize = CopyedSize; - return EFI_SUCCESS; - } - } - - return EFI_NOT_FOUND; -} - /** Release all the resource of a cache item. @@ -609,6 +535,91 @@ HttpBootFreeCacheList ( } } +/** + Get the file content from cached data. + + @param[in] Private The pointer to the driver's private data. + @param[in] Uri Uri of the file to be retrieved from cache. + @param[in, out] BufferSize On input the size of Buffer in bytes. On output with a return + code of EFI_SUCCESS, the amount of data transferred to + Buffer. On output with a return code of EFI_BUFFER_TOO_SMALL, + the size of Buffer required to retrieve the requested file. + @param[out] Buffer The memory buffer to transfer the file to. IF Buffer is NULL, + then the size of the requested file is returned in + BufferSize. + + @retval EFI_SUCCESS Successfully created. + @retval Others Failed to create HttpIo. + +**/ +EFI_STATUS +HttpBootGetFileFromCache ( + IN HTTP_BOOT_PRIVATE_DATA *Private, + IN CHAR16 *Uri, + IN OUT UINTN *BufferSize, + OUT UINT8 *Buffer + ) +{ + LIST_ENTRY *Entry; + LIST_ENTRY *Entry2; + HTTP_BOOT_CACHE_CONTENT *Cache; + HTTP_BOOT_ENTITY_DATA *EntityData; + UINTN CopyedSize; + + if (Uri == NULL || BufferSize == 0 || Buffer == NULL) { + return EFI_INVALID_PARAMETER; + } + + // + // Search file in the cache list, the cache entry will be released upon a successful + // match. + // + NET_LIST_FOR_EACH (Entry, &Private->CacheList) { + Cache = NET_LIST_USER_STRUCT (Entry, HTTP_BOOT_CACHE_CONTENT, Link); + // + // Compare the URI to see whether we already have a cache for this file. + // + if ((Cache->RequestData != NULL) && + (Cache->RequestData->Url != NULL) && + (StrCmp (Uri, Cache->RequestData->Url) == 0)) + { + // + // Hit cache, check buffer size. + // + if (*BufferSize < Cache->EntityLength) { + *BufferSize = Cache->EntityLength; + return EFI_BUFFER_TOO_SMALL; + } + + // + // Fill data to buffer. + // + CopyedSize = 0; + NET_LIST_FOR_EACH (Entry2, &Cache->EntityDataList) { + EntityData = NET_LIST_USER_STRUCT (Entry2, HTTP_BOOT_ENTITY_DATA, Link); + if (*BufferSize > CopyedSize) { + CopyMem ( + Buffer + CopyedSize, + EntityData->DataStart, + MIN (EntityData->DataLength, *BufferSize - CopyedSize) + ); + CopyedSize += MIN (EntityData->DataLength, *BufferSize - CopyedSize); + } + } + *BufferSize = CopyedSize; + + // + // On success, free the cached data to release the memory resource. + // + RemoveEntryList (&Cache->Link); + HttpBootFreeCache (Cache); + return EFI_SUCCESS; + } + } + + return EFI_NOT_FOUND; +} + /** A callback function to intercept events during message parser. @@ -707,10 +718,11 @@ HttpBootGetBootFile ( ) { EFI_STATUS Status; + EFI_HTTP_STATUS_CODE StatusCode; CHAR8 *HostName; EFI_HTTP_REQUEST_DATA *RequestData; - HTTP_IO_RESOPNSE_DATA *ResponseData; - HTTP_IO_RESOPNSE_DATA ResponseBody; + HTTP_IO_RESPONSE_DATA *ResponseData; + HTTP_IO_RESPONSE_DATA ResponseBody; HTTP_IO *HttpIo; HTTP_IO_HEADER *HttpIoHeader; VOID *Parser; @@ -719,6 +731,8 @@ HttpBootGetBootFile ( HTTP_BOOT_CACHE_CONTENT *Cache; UINT8 *Block; CHAR16 *Url; + BOOLEAN IdentityMode; + UINTN ReceivedSize; ASSERT (Private != NULL); ASSERT (Private->HttpCreated); @@ -794,7 +808,7 @@ HttpBootGetBootFile ( } Status = HttpBootSetHeader ( HttpIoHeader, - HTTP_FIELD_NAME_HOST, + HTTP_HEADER_HOST, HostName ); FreePool (HostName); @@ -807,7 +821,7 @@ HttpBootGetBootFile ( // Status = HttpBootSetHeader ( HttpIoHeader, - HTTP_FIELD_NAME_ACCEPT, + HTTP_HEADER_ACCEPT, "*/*" ); if (EFI_ERROR (Status)) { @@ -819,7 +833,7 @@ HttpBootGetBootFile ( // Status = HttpBootSetHeader ( HttpIoHeader, - HTTP_FIELD_NAME_USER_AGENT, + HTTP_HEADER_USER_AGENT, HTTP_USER_AGENT_EFI_HTTP_BOOT ); if (EFI_ERROR (Status)) { @@ -872,7 +886,7 @@ HttpBootGetBootFile ( // // 3.1 First step, use zero BodyLength to only receive the response headers. // - ResponseData = AllocateZeroPool (sizeof(HTTP_IO_RESOPNSE_DATA)); + ResponseData = AllocateZeroPool (sizeof(HTTP_IO_RESPONSE_DATA)); if (ResponseData == NULL) { Status = EFI_OUT_OF_RESOURCES; goto ERROR_4; @@ -882,7 +896,12 @@ HttpBootGetBootFile ( TRUE, ResponseData ); - if (EFI_ERROR (Status)) { + if (EFI_ERROR (Status) || EFI_ERROR (ResponseData->Status)) { + if (EFI_ERROR (ResponseData->Status)) { + StatusCode = HttpIo->RspToken.Message->Data.Response->StatusCode; + HttpBootPrintErrorMessage (StatusCode); + Status = ResponseData->Status; + } goto ERROR_5; } @@ -921,51 +940,94 @@ HttpBootGetBootFile ( // Block = NULL; if (!HeaderOnly) { - ZeroMem (&ResponseBody, sizeof (HTTP_IO_RESOPNSE_DATA)); - while (!HttpIsMessageComplete (Parser)) { + // + // 3.4.1, check whether we are in identity transfer-coding. + // + ContentLength = 0; + Status = HttpGetEntityLength (Parser, &ContentLength); + if (!EFI_ERROR (Status)) { + IdentityMode = TRUE; + } else { + IdentityMode = FALSE; + } + + // + // 3.4.2, start the message-body download, the identity and chunked transfer-coding + // is handled in different path here. + // + ZeroMem (&ResponseBody, sizeof (HTTP_IO_RESPONSE_DATA)); + if (IdentityMode) { // - // Allocate a block to hold the message-body, if caller doesn't provide - // a buffer, the block will be cached and we will allocate a new one here. + // In identity transfer-coding there is no need to parse the message body, + // just download the message body to the user provided buffer directly. // - if (Block == NULL || Context.BufferSize == 0) { - Block = AllocatePool (HTTP_BOOT_BLOCK_SIZE); - if (Block == NULL) { - Status = EFI_OUT_OF_RESOURCES; + ReceivedSize = 0; + while (ReceivedSize < ContentLength) { + ResponseBody.Body = (CHAR8*) Buffer + ReceivedSize; + ResponseBody.BodyLength = *BufferSize - ReceivedSize; + Status = HttpIoRecvResponse ( + &Private->HttpIo, + FALSE, + &ResponseBody + ); + if (EFI_ERROR (Status)) { goto ERROR_6; } - Context.NewBlock = TRUE; - Context.Block = Block; - } else { - Context.NewBlock = FALSE; - } - - ResponseBody.Body = (CHAR8*) Block; - ResponseBody.BodyLength = HTTP_BOOT_BLOCK_SIZE; - Status = HttpIoRecvResponse ( - &Private->HttpIo, - FALSE, - &ResponseBody - ); - if (EFI_ERROR (Status)) { - goto ERROR_6; + ReceivedSize += ResponseBody.BodyLength; } - + } else { // - // Parse the new received block of the message-body, the block will be saved in cache. + // In "chunked" transfer-coding mode, so we need to parse the received + // data to get the real entity content. // - Status = HttpParseMessageBody ( - Parser, - ResponseBody.BodyLength, - ResponseBody.Body - ); - if (EFI_ERROR (Status)) { - goto ERROR_6; + Block = NULL; + while (!HttpIsMessageComplete (Parser)) { + // + // Allocate a buffer in Block to hold the message-body. + // If caller provides a buffer, this Block will be reused in every HttpIoRecvResponse(). + // Otherwise a buffer, the buffer in Block will be cached and we should allocate a new before + // every HttpIoRecvResponse(). + // + if (Block == NULL || Context.BufferSize == 0) { + Block = AllocatePool (HTTP_BOOT_BLOCK_SIZE); + if (Block == NULL) { + Status = EFI_OUT_OF_RESOURCES; + goto ERROR_6; + } + Context.NewBlock = TRUE; + Context.Block = Block; + } else { + Context.NewBlock = FALSE; + } + + ResponseBody.Body = (CHAR8*) Block; + ResponseBody.BodyLength = HTTP_BOOT_BLOCK_SIZE; + Status = HttpIoRecvResponse ( + &Private->HttpIo, + FALSE, + &ResponseBody + ); + if (EFI_ERROR (Status)) { + goto ERROR_6; + } + + // + // Parse the new received block of the message-body, the block will be saved in cache. + // + Status = HttpParseMessageBody ( + Parser, + ResponseBody.BodyLength, + ResponseBody.Body + ); + if (EFI_ERROR (Status)) { + goto ERROR_6; + } } } } - + // - // 3.5 Message-body receive & parse is completed, get the file size. + // 3.5 Message-body receive & parse is completed, we should be able to get the file size now. // Status = HttpGetEntityLength (Parser, &ContentLength); if (EFI_ERROR (Status)) {