]> git.proxmox.com Git - mirror_edk2.git/blobdiff - NetworkPkg/HttpBootDxe/HttpBootSupport.c
OvmfPkg/VirtioScsiDxe: list "VirtioScsi.h" in the INF file
[mirror_edk2.git] / NetworkPkg / HttpBootDxe / HttpBootSupport.c
index d786d725dc2d269196f24ccebd808b06df505f2f..d508e2c1a979f85df8ace5f4a5c2940bdfb2c921 100644 (file)
@@ -160,7 +160,7 @@ HttpBootPrintErrorMessage (
   AsciiPrint ("\n");\r
 \r
   switch (StatusCode) {\r
-  case HTTP_STATUS_300_MULTIPLE_CHIOCES:\r
+  case HTTP_STATUS_300_MULTIPLE_CHOICES:\r
     AsciiPrint ("\n  Redirection: 300 Multiple Choices");\r
     break; \r
     \r
@@ -186,6 +186,10 @@ HttpBootPrintErrorMessage (
 \r
   case HTTP_STATUS_307_TEMPORARY_REDIRECT:\r
     AsciiPrint ("\n  Redirection: 307 Temporary Redirect");\r
+    break;\r
+\r
+  case HTTP_STATUS_308_PERMANENT_REDIRECT:\r
+    AsciiPrint ("\n  Redirection: 308 Permanent Redirect");\r
     break; \r
 \r
   case HTTP_STATUS_400_BAD_REQUEST:\r
@@ -631,6 +635,7 @@ HttpBootSetHeader (
 \r
 **/\r
 VOID\r
+EFIAPI\r
 HttpIoNotifyDpc (\r
   IN VOID                *Context\r
   )\r
@@ -646,6 +651,7 @@ HttpIoNotifyDpc (
 \r
 **/\r
 VOID\r
+EFIAPI\r
 HttpIoNotify (\r
   IN EFI_EVENT              Event,\r
   IN VOID                   *Context\r
@@ -665,6 +671,9 @@ HttpIoNotify (
   @param[in]  Controller     The handle of the controller.\r
   @param[in]  IpVersion      IP_VERSION_4 or IP_VERSION_6.\r
   @param[in]  ConfigData     The HTTP_IO configuration data.\r
+  @param[in]  Callback       Callback function which will be invoked when specified\r
+                             HTTP_IO_CALLBACK_EVENT happened.\r
+  @param[in]  Context        The Context data which will be passed to the Callback function.\r
   @param[out] HttpIo         The HTTP_IO.\r
   \r
   @retval EFI_SUCCESS            The HTTP_IO is created and configured.\r
@@ -681,6 +690,8 @@ HttpIoCreateIo (
   IN EFI_HANDLE             Controller,\r
   IN UINT8                  IpVersion,\r
   IN HTTP_IO_CONFIG_DATA    *ConfigData,\r
+  IN HTTP_IO_CALLBACK       Callback,\r
+  IN VOID                   *Context,\r
   OUT HTTP_IO               *HttpIo\r
   )\r
 {\r
@@ -733,6 +744,8 @@ HttpIoCreateIo (
   HttpIo->Controller  = Controller;\r
   HttpIo->IpVersion   = IpVersion;\r
   HttpIo->Http        = Http;\r
+  HttpIo->Callback    = Callback;\r
+  HttpIo->Context     = Context;\r
 \r
   ZeroMem (&HttpConfigData, sizeof (EFI_HTTP_CONFIG_DATA));\r
   HttpConfigData.HttpVersion        = HttpVersion11;\r
@@ -902,6 +915,17 @@ HttpIoSendRequest (
   HttpIo->ReqToken.Message->BodyLength   = BodyLength;\r
   HttpIo->ReqToken.Message->Body         = Body;\r
 \r
+  if (HttpIo->Callback != NULL) {\r
+    Status = HttpIo->Callback (\r
+               HttpIoRequest,\r
+               HttpIo->ReqToken.Message,\r
+               HttpIo->Context\r
+               );\r
+    if (EFI_ERROR (Status)) {\r
+      return Status;\r
+    }\r
+  }\r
+\r
   //\r
   // Queue the request token to HTTP instances.\r
   //\r
@@ -1010,6 +1034,18 @@ HttpIoRecvResponse (
     HttpIo->IsRxDone = FALSE;\r
   }\r
 \r
+  if ((HttpIo->Callback != NULL) && \r
+      (HttpIo->RspToken.Status == EFI_SUCCESS || HttpIo->RspToken.Status == EFI_HTTP_ERROR)) {\r
+    Status = HttpIo->Callback (\r
+               HttpIoResponse,\r
+               HttpIo->RspToken.Message,\r
+               HttpIo->Context\r
+               );\r
+    if (EFI_ERROR (Status)) {\r
+      return Status;\r
+    }\r
+  }\r
+\r
   //\r
   // Store the received data into the wrapper.\r
   //\r
@@ -1176,13 +1212,21 @@ HttpBootCheckImageType (
 \r
   //\r
   // Determine the image type by the HTTP Content-Type header field first.\r
-  //   "application/efi" -> EFI Image\r
+  //   "application/efi"         -> EFI Image\r
+  //   "application/vnd.efi-iso" -> CD/DVD Image\r
+  //   "application/vnd.efi-img" -> Virtual Disk Image\r
   //\r
   Header = HttpFindHeader (HeaderCount, Headers, HTTP_HEADER_CONTENT_TYPE);\r
   if (Header != NULL) {\r
     if (AsciiStriCmp (Header->FieldValue, HTTP_CONTENT_TYPE_APP_EFI) == 0) {\r
       *ImageType = ImageTypeEfi;\r
       return EFI_SUCCESS;\r
+    } else if (AsciiStriCmp (Header->FieldValue, HTTP_CONTENT_TYPE_APP_ISO) == 0) {\r
+      *ImageType = ImageTypeVirtualCd;\r
+      return EFI_SUCCESS;\r
+    } else if (AsciiStriCmp (Header->FieldValue, HTTP_CONTENT_TYPE_APP_IMG) == 0) {\r
+      *ImageType = ImageTypeVirtualDisk;\r
+      return EFI_SUCCESS;\r
     }\r
   }\r
 \r
@@ -1276,3 +1320,25 @@ HttpBootRegisterRamDisk (
   return Status;\r
 }\r
 \r
+/**\r
+  Indicate if the HTTP status code indicates a redirection.\r
+  \r
+  @param[in]  StatusCode      HTTP status code from server.\r
+\r
+  @return                     TRUE if it's redirection.\r
+\r
+**/\r
+BOOLEAN\r
+HttpBootIsHttpRedirectStatusCode (\r
+  IN   EFI_HTTP_STATUS_CODE        StatusCode\r
+  )\r
+{\r
+  if (StatusCode == HTTP_STATUS_301_MOVED_PERMANENTLY ||\r
+      StatusCode == HTTP_STATUS_302_FOUND ||\r
+      StatusCode == HTTP_STATUS_307_TEMPORARY_REDIRECT ||\r
+      StatusCode == HTTP_STATUS_308_PERMANENT_REDIRECT) {\r
+    return TRUE;\r
+  }\r
+\r
+  return FALSE;\r
+}\r