]> git.proxmox.com Git - mirror_edk2.git/blobdiff - NetworkPkg/HttpBootDxe/HttpBootConfig.c
NetworkPkg: Fix some typos of "according"
[mirror_edk2.git] / NetworkPkg / HttpBootDxe / HttpBootConfig.c
index 2ca38b533329b65057518f4224348c2a5f2bfa7e..f32bf18e9d64e6999cfd903ac8670515f45df2f3 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Helper functions for configuring or getting the parameters relating to HTTP Boot.\r
 \r
-Copyright (c) 2016, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2016 - 2017, Intel Corporation. All rights reserved.<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\r
@@ -104,7 +104,7 @@ HttpBootAddBootOption (
   //\r
   // Update the URI node with the input boot file URI.\r
   //\r
-  UnicodeStrToAsciiStr (Uri, AsciiUri);\r
+  UnicodeStrToAsciiStrS (Uri, AsciiUri, sizeof (AsciiUri));\r
   Length = sizeof (EFI_DEVICE_PATH_PROTOCOL) + AsciiStrSize (AsciiUri);\r
   Node = AllocatePool (Length);\r
   if (Node == NULL) {\r
@@ -142,9 +142,7 @@ HttpBootAddBootOption (
   }\r
 \r
   Status = EfiBootManagerAddLoadOptionVariable (&NewOption, (UINTN) -1);\r
-  if (EFI_ERROR (Status)) {\r
-    EfiBootManagerFreeLoadOption (&NewOption);\r
-  }\r
+  EfiBootManagerFreeLoadOption (&NewOption);\r
 \r
 ON_EXIT:\r
 \r
@@ -275,7 +273,9 @@ HttpBootFormExtractConfig (
     ConfigRequestHdr = HiiConstructConfigHdr (&gHttpBootConfigGuid, mHttpBootConfigStorageName, CallbackInfo->ChildHandle);\r
     Size = (StrLen (ConfigRequestHdr) + 32 + 1) * sizeof (CHAR16);\r
     ConfigRequest = AllocateZeroPool (Size);\r
-    ASSERT (ConfigRequest != NULL);\r
+    if (ConfigRequest == NULL) {\r
+      return EFI_OUT_OF_RESOURCES;\r
+    }\r
     AllocatedRequest = TRUE;\r
     UnicodeSPrint (ConfigRequest, Size, L"%s&OFFSET=0&WIDTH=%016LX", ConfigRequestHdr, (UINT64)BufferSize);\r
     FreePool (ConfigRequestHdr);\r
@@ -446,9 +446,16 @@ HttpBootFormCallback (
   )\r
 {\r
   EFI_INPUT_KEY                   Key;\r
-  UINTN                           Index;\r
   CHAR16                          *Uri;\r
+  UINTN                           UriLen;\r
+  CHAR8                           *AsciiUri;\r
   HTTP_BOOT_FORM_CALLBACK_INFO    *CallbackInfo;\r
+  EFI_STATUS                      Status;\r
+\r
+  Uri      = NULL;\r
+  UriLen   = 0;\r
+  AsciiUri = NULL;\r
+  Status   = EFI_SUCCESS;\r
   \r
   if (This == NULL || Value == NULL) {\r
     return EFI_INVALID_PARAMETER;\r
@@ -466,50 +473,63 @@ HttpBootFormCallback (
     // Get user input URI string\r
     //\r
     Uri = HiiGetString (CallbackInfo->RegisteredHandle, Value->string, NULL);\r
-    ASSERT (Uri != NULL);\r
-    if (Uri == NULL) {\r
-      return EFI_UNSUPPORTED;\r
-    }\r
 \r
     //\r
-    // Convert the scheme to all lower case.\r
+    // The URI should be either an empty string (for corporate environment) ,or http(s) for home environment.\r
+    // Pop up a message box for the unsupported URI.\r
     //\r
-    for (Index = 0; Index < StrLen (Uri); Index++) {\r
-      if (Uri[Index] == L':') {\r
-        break;\r
+    if (StrLen (Uri) != 0) {\r
+      UriLen = StrLen (Uri) + 1;\r
+      AsciiUri = AllocateZeroPool (UriLen);\r
+      if (AsciiUri == NULL) {\r
+        FreePool (Uri);\r
+        return EFI_OUT_OF_RESOURCES;\r
       }\r
-      if (Uri[Index] >= L'A' && Uri[Index] <= L'Z') {\r
-        Uri[Index] -= (CHAR16)(L'A' - L'a');\r
+\r
+      UnicodeStrToAsciiStrS (Uri, AsciiUri, UriLen);\r
+\r
+      Status = HttpBootCheckUriScheme (AsciiUri);\r
+      \r
+      if (Status == EFI_INVALID_PARAMETER) {\r
+\r
+        DEBUG ((EFI_D_ERROR, "HttpBootFormCallback: %r.\n", Status));\r
+\r
+        CreatePopUp (\r
+          EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,\r
+          &Key,\r
+          L"ERROR: Unsupported URI!",\r
+          L"Only supports HTTP and HTTPS",\r
+          NULL\r
+          ); \r
+      } else if (Status == EFI_ACCESS_DENIED) {\r
+      \r
+        DEBUG ((EFI_D_ERROR, "HttpBootFormCallback: %r.\n", Status));\r
+      \r
+        CreatePopUp (\r
+          EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,\r
+          &Key,\r
+          L"ERROR: Unsupported URI!",\r
+          L"HTTP is disabled",\r
+          NULL\r
+          );\r
       }\r
     }\r
 \r
-    //\r
-    // Set the converted URI string back\r
-    //\r
-    HiiSetString (CallbackInfo->RegisteredHandle, Value->string, Uri, NULL);\r
-\r
-    //\r
-    // The URI should be either an empty string (for corporate environment) ,or http(s) for home environment.\r
-    // Pop up a message box for other unsupported URI.\r
-    //\r
-    if ((StrLen (Uri) != 0) && (StrnCmp (Uri, L"http://", 7) != 0) && (StrnCmp (Uri, L"https://", 8) != 0)) {\r
-      CreatePopUp (\r
-        EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,\r
-        &Key,\r
-        L"ERROR: Unsupported URI!",\r
-        L"Only supports HTTP and HTTPS",\r
-        NULL\r
-        );\r
+    if (Uri != NULL) {\r
+      FreePool (Uri);\r
     }\r
 \r
-    FreePool (Uri);\r
+    if (AsciiUri != NULL) {\r
+      FreePool (AsciiUri);\r
+    }   \r
+    \r
     break;\r
 \r
   default:\r
     break;\r
   }\r
 \r
-  return EFI_SUCCESS;\r
+  return Status;\r
 }\r
 \r
 /**\r