+/**\r
+ Get the file content from cached data.\r
+\r
+ @param[in] Private The pointer to the driver's private data.\r
+ @param[in] Uri Uri of the file to be retrieved from cache.\r
+ @param[in, out] BufferSize On input the size of Buffer in bytes. On output with a return\r
+ code of EFI_SUCCESS, the amount of data transferred to\r
+ Buffer. On output with a return code of EFI_BUFFER_TOO_SMALL,\r
+ the size of Buffer required to retrieve the requested file.\r
+ @param[out] Buffer The memory buffer to transfer the file to. IF Buffer is NULL,\r
+ then the size of the requested file is returned in\r
+ BufferSize.\r
+\r
+ @retval EFI_SUCCESS Successfully created.\r
+ @retval Others Failed to create HttpIo.\r
+\r
+**/\r
+EFI_STATUS\r
+HttpBootGetFileFromCache (\r
+ IN HTTP_BOOT_PRIVATE_DATA *Private,\r
+ IN CHAR16 *Uri,\r
+ IN OUT UINTN *BufferSize,\r
+ OUT UINT8 *Buffer\r
+ )\r
+{\r
+ LIST_ENTRY *Entry;\r
+ LIST_ENTRY *Entry2;\r
+ HTTP_BOOT_CACHE_CONTENT *Cache;\r
+ HTTP_BOOT_ENTITY_DATA *EntityData;\r
+ UINTN CopyedSize;\r
+ \r
+ if (Uri == NULL || BufferSize == 0 || Buffer == NULL) {\r
+ return EFI_INVALID_PARAMETER;\r
+ }\r
+\r
+ //\r
+ // Search file in the cache list, the cache entry will be released upon a successful\r
+ // match.\r
+ //\r
+ NET_LIST_FOR_EACH (Entry, &Private->CacheList) {\r
+ Cache = NET_LIST_USER_STRUCT (Entry, HTTP_BOOT_CACHE_CONTENT, Link);\r
+ //\r
+ // Compare the URI to see whether we already have a cache for this file.\r
+ //\r
+ if ((Cache->RequestData != NULL) &&\r
+ (Cache->RequestData->Url != NULL) &&\r
+ (StrCmp (Uri, Cache->RequestData->Url) == 0)) \r
+ {\r
+ //\r
+ // Hit cache, check buffer size.\r
+ //\r
+ if (*BufferSize < Cache->EntityLength) {\r
+ *BufferSize = Cache->EntityLength;\r
+ return EFI_BUFFER_TOO_SMALL;\r
+ }\r
+\r
+ //\r
+ // Fill data to buffer.\r
+ //\r
+ CopyedSize = 0;\r
+ NET_LIST_FOR_EACH (Entry2, &Cache->EntityDataList) {\r
+ EntityData = NET_LIST_USER_STRUCT (Entry2, HTTP_BOOT_ENTITY_DATA, Link);\r
+ if (*BufferSize > CopyedSize) {\r
+ CopyMem (\r
+ Buffer + CopyedSize,\r
+ EntityData->DataStart,\r
+ MIN (EntityData->DataLength, *BufferSize - CopyedSize)\r
+ );\r
+ CopyedSize += MIN (EntityData->DataLength, *BufferSize - CopyedSize);\r
+ }\r
+ }\r
+ *BufferSize = CopyedSize;\r
+\r
+ //\r
+ // On success, free the cached data to release the memory resource.\r
+ //\r
+ RemoveEntryList (&Cache->Link);\r
+ HttpBootFreeCache (Cache);\r
+ return EFI_SUCCESS;\r
+ }\r
+ }\r
+\r
+ return EFI_NOT_FOUND;\r
+}\r
+\r