]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Library/DxeHttpLib/DxeHttpLib.c
BaseTools:Change the path of the file that Binary Cache
[mirror_edk2.git] / MdeModulePkg / Library / DxeHttpLib / DxeHttpLib.c
index 5fbb50d03ab61f60a05986bdc2b91c9c5bdda099..8b74554cd96157b2cb788b1c32f9c50a6664ef9f 100644 (file)
@@ -2,15 +2,9 @@
   This library is used to share code between UEFI network stack modules.\r
   It provides the helper routines to parse the HTTP message byte stream.\r
 \r
-Copyright (c) 2015 - 2018, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2015 - 2019, Intel Corporation. All rights reserved.<BR>\r
 (C) Copyright 2016 Hewlett Packard Enterprise Development LP<BR>\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<BR>\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
@@ -898,27 +892,6 @@ typedef struct {
   UINTN                         CurrentChunkParsedSize;\r
 } HTTP_BODY_PARSER;\r
 \r
-/**\r
-\r
-  Convert an Ascii char to its uppercase.\r
-\r
-  @param[in]       Char           Ascii character.\r
-\r
-  @return          Uppercase value of the input Char.\r
-\r
-**/\r
-CHAR8\r
-HttpIoCharToUpper (\r
-  IN      CHAR8                    Char\r
-  )\r
-{\r
-  if (Char >= 'a' && Char <= 'z') {\r
-    return  Char - ('a' - 'A');\r
-  }\r
-\r
-  return Char;\r
-}\r
-\r
 /**\r
   Convert an hexadecimal char to a value of type UINTN.\r
 \r
@@ -936,7 +909,7 @@ HttpIoHexCharToUintn (
     return Char - '0';\r
   }\r
 \r
-  return (10 + HttpIoCharToUpper (Char) - 'A');\r
+  return (10 + AsciiCharToUpper (Char) - 'A');\r
 }\r
 \r
 /**\r
@@ -1597,6 +1570,18 @@ HttpGetFieldNameAndValue (
 \r
   //\r
   // Each header field consists of a name followed by a colon (":") and the field value.\r
+  // The field value MAY be preceded by any amount of LWS, though a single SP is preferred.\r
+  //\r
+  // message-header = field-name ":" [ field-value ]\r
+  // field-name = token\r
+  // field-value = *( field-content | LWS )\r
+  //\r
+  // Note: "*(element)" allows any number element, including zero; "1*(element)" requires at least one element.\r
+  //       [element] means element is optional.\r
+  //       LWS  = [CRLF] 1*(SP|HT), it can be ' ' or '\t' or '\r\n ' or '\r\n\t'.\r
+  //       CRLF = '\r\n'.\r
+  //       SP   = ' '.\r
+  //       HT   = '\t' (Tab).\r
   //\r
   FieldNameStr = String;\r
   FieldValueStr = AsciiStrGetNextToken (FieldNameStr, ':');\r
@@ -1605,16 +1590,12 @@ HttpGetFieldNameAndValue (
   }\r
 \r
   //\r
-  // Replace ':' with 0\r
+  // Replace ':' with 0, then FieldName has been retrived from String.\r
   //\r
   *(FieldValueStr - 1) = 0;\r
 \r
   //\r
-  // The field value MAY be preceded by any amount of LWS, though a single SP is preferred.\r
-  // Note: LWS  = [CRLF] 1*(SP|HT), it can be '\r\n ' or '\r\n\t' or ' ' or '\t'.\r
-  //       CRLF = '\r\n'.\r
-  //       SP   = ' '.\r
-  //       HT   = '\t' (Tab).\r
+  // Handle FieldValueStr, skip all the preceded LWS.\r
   //\r
   while (TRUE) {\r
     if (*FieldValueStr == ' ' || *FieldValueStr == '\t') {\r
@@ -1622,6 +1603,9 @@ HttpGetFieldNameAndValue (
       // Boundary condition check.\r
       //\r
       if ((UINTN) EndofHeader - (UINTN) FieldValueStr < 1) {\r
+        //\r
+        // Wrong String format!\r
+        //\r
         return NULL;\r
       }\r
 \r
@@ -1631,25 +1615,45 @@ HttpGetFieldNameAndValue (
       // Boundary condition check.\r
       //\r
       if ((UINTN) EndofHeader - (UINTN) FieldValueStr < 3) {\r
-        return NULL;\r
+        //\r
+        // No more preceded LWS, so break here.\r
+        //\r
+        break;\r
       }\r
 \r
-      if (*(FieldValueStr + 1) == '\n' && (*(FieldValueStr + 2) == ' ' || *(FieldValueStr + 2) == '\t')) {\r
-        FieldValueStr = FieldValueStr + 3;\r
+      if (*(FieldValueStr + 1) == '\n' ) {\r
+        if (*(FieldValueStr + 2) == ' ' || *(FieldValueStr + 2) == '\t') {\r
+          FieldValueStr = FieldValueStr + 3;\r
+        } else {\r
+          //\r
+          // No more preceded LWS, so break here.\r
+          //\r
+          break;\r
+        }\r
+      } else {\r
+        //\r
+        // Wrong String format!\r
+        //\r
+        return NULL;\r
       }\r
     } else {\r
+      //\r
+      // No more preceded LWS, so break here.\r
+      //\r
       break;\r
     }\r
   }\r
 \r
-  //\r
-  // Header fields can be extended over multiple lines by preceding each extra\r
-  // line with at least one SP or HT.\r
-  //\r
   StrPtr = FieldValueStr;\r
   do {\r
+    //\r
+    // Handle the LWS within the field value.\r
+    //\r
     StrPtr = AsciiStrGetNextToken (StrPtr, '\r');\r
     if (StrPtr == NULL || *StrPtr != '\n') {\r
+      //\r
+      // Wrong String format!\r
+      //\r
       return NULL;\r
     }\r
 \r