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