]> git.proxmox.com Git - mirror_edk2.git/blobdiff - NetworkPkg/HttpDxe/HttpProto.c
NetworkPkg: Convert source file to DOS format
[mirror_edk2.git] / NetworkPkg / HttpDxe / HttpProto.c
index 199d575cf906a0c68f21db24439755f3d49c2ab4..d7fe271168fe29b41eb9dbb154fdf2719371b510 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Miscellaneous routines for HttpDxe driver.\r
 \r
-Copyright (c) 2015 - 2016, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2015 - 2017, 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
@@ -642,7 +642,7 @@ HttpInitProtocol (
     //\r
     Status = NetLibCreateServiceChild (\r
                HttpInstance->Service->ControllerHandle,\r
-               HttpInstance->Service->ImageHandle,\r
+               HttpInstance->Service->Ip4DriverBindingHandle,\r
                &gEfiTcp4ServiceBindingProtocolGuid,\r
                &HttpInstance->Tcp4ChildHandle\r
                );\r
@@ -655,7 +655,7 @@ HttpInitProtocol (
                     HttpInstance->Tcp4ChildHandle,\r
                     &gEfiTcp4ProtocolGuid,\r
                     (VOID **) &Interface,\r
-                    HttpInstance->Service->ImageHandle,\r
+                    HttpInstance->Service->Ip4DriverBindingHandle,\r
                     HttpInstance->Service->ControllerHandle,\r
                     EFI_OPEN_PROTOCOL_BY_DRIVER\r
                     );\r
@@ -668,7 +668,7 @@ HttpInitProtocol (
                     HttpInstance->Tcp4ChildHandle,\r
                     &gEfiTcp4ProtocolGuid,\r
                     (VOID **) &HttpInstance->Tcp4,\r
-                    HttpInstance->Service->ImageHandle,\r
+                    HttpInstance->Service->Ip4DriverBindingHandle,\r
                     HttpInstance->Handle,\r
                     EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER\r
                     );\r
@@ -680,7 +680,7 @@ HttpInitProtocol (
                     HttpInstance->Service->Tcp4ChildHandle,\r
                     &gEfiTcp4ProtocolGuid,\r
                     (VOID **) &Interface,\r
-                    HttpInstance->Service->ImageHandle,\r
+                    HttpInstance->Service->Ip4DriverBindingHandle,\r
                     HttpInstance->Handle,\r
                     EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER\r
                     );\r
@@ -693,7 +693,7 @@ HttpInitProtocol (
     //\r
     Status = NetLibCreateServiceChild (\r
                HttpInstance->Service->ControllerHandle,\r
-               HttpInstance->Service->ImageHandle,\r
+               HttpInstance->Service->Ip6DriverBindingHandle,\r
                &gEfiTcp6ServiceBindingProtocolGuid,\r
                &HttpInstance->Tcp6ChildHandle\r
                );\r
@@ -706,7 +706,7 @@ HttpInitProtocol (
                     HttpInstance->Tcp6ChildHandle,\r
                     &gEfiTcp6ProtocolGuid,\r
                     (VOID **) &Interface,\r
-                    HttpInstance->Service->ImageHandle,\r
+                    HttpInstance->Service->Ip6DriverBindingHandle,\r
                     HttpInstance->Service->ControllerHandle,\r
                     EFI_OPEN_PROTOCOL_BY_DRIVER\r
                     );\r
@@ -719,7 +719,7 @@ HttpInitProtocol (
                     HttpInstance->Tcp6ChildHandle,\r
                     &gEfiTcp6ProtocolGuid,\r
                     (VOID **) &HttpInstance->Tcp6,\r
-                    HttpInstance->Service->ImageHandle,\r
+                    HttpInstance->Service->Ip6DriverBindingHandle,\r
                     HttpInstance->Handle,\r
                     EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER\r
                     );\r
@@ -732,7 +732,7 @@ HttpInitProtocol (
                     HttpInstance->Service->Tcp6ChildHandle,\r
                     &gEfiTcp6ProtocolGuid,\r
                     (VOID **) &Interface,\r
-                    HttpInstance->Service->ImageHandle,\r
+                    HttpInstance->Service->Ip6DriverBindingHandle,\r
                     HttpInstance->Handle,\r
                     EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER\r
                     );\r
@@ -756,20 +756,20 @@ ON_ERROR:
     gBS->CloseProtocol (\r
            HttpInstance->Tcp4ChildHandle,\r
            &gEfiTcp4ProtocolGuid,\r
-           HttpInstance->Service->ImageHandle,\r
+           HttpInstance->Service->Ip4DriverBindingHandle,\r
            HttpInstance->Service->ControllerHandle\r
            );\r
 \r
     gBS->CloseProtocol (\r
            HttpInstance->Tcp4ChildHandle,\r
            &gEfiTcp4ProtocolGuid,\r
-           HttpInstance->Service->ImageHandle,\r
+           HttpInstance->Service->Ip4DriverBindingHandle,\r
            HttpInstance->Handle\r
            );    \r
     \r
     NetLibDestroyServiceChild (\r
       HttpInstance->Service->ControllerHandle,\r
-      HttpInstance->Service->ImageHandle,\r
+      HttpInstance->Service->Ip4DriverBindingHandle,\r
       &gEfiTcp4ServiceBindingProtocolGuid,\r
       HttpInstance->Tcp4ChildHandle\r
       );\r
@@ -779,7 +779,7 @@ ON_ERROR:
     gBS->CloseProtocol (\r
            HttpInstance->Service->Tcp4ChildHandle,\r
            &gEfiTcp4ProtocolGuid,\r
-           HttpInstance->Service->ImageHandle,\r
+           HttpInstance->Service->Ip4DriverBindingHandle,\r
            HttpInstance->Handle\r
            );\r
   }\r
@@ -788,20 +788,20 @@ ON_ERROR:
     gBS->CloseProtocol (\r
            HttpInstance->Tcp6ChildHandle,\r
            &gEfiTcp6ProtocolGuid,\r
-           HttpInstance->Service->ImageHandle,\r
+           HttpInstance->Service->Ip6DriverBindingHandle,\r
            HttpInstance->Service->ControllerHandle\r
            );\r
 \r
     gBS->CloseProtocol (\r
            HttpInstance->Tcp6ChildHandle,\r
            &gEfiTcp6ProtocolGuid,\r
-           HttpInstance->Service->ImageHandle,\r
+           HttpInstance->Service->Ip6DriverBindingHandle,\r
            HttpInstance->Handle\r
            );\r
     \r
     NetLibDestroyServiceChild (\r
       HttpInstance->Service->ControllerHandle,\r
-      HttpInstance->Service->ImageHandle,\r
+      HttpInstance->Service->Ip6DriverBindingHandle,\r
       &gEfiTcp6ServiceBindingProtocolGuid,\r
       HttpInstance->Tcp6ChildHandle\r
       );\r
@@ -811,7 +811,7 @@ ON_ERROR:
     gBS->CloseProtocol (\r
            HttpInstance->Service->Tcp6ChildHandle,\r
            &gEfiTcp6ProtocolGuid,\r
-           HttpInstance->Service->ImageHandle,\r
+           HttpInstance->Service->Ip6DriverBindingHandle,\r
            HttpInstance->Handle\r
            );\r
   }\r
@@ -864,24 +864,31 @@ HttpCleanProtocol (
   NetMapClean (&HttpInstance->TxTokens);\r
   NetMapClean (&HttpInstance->RxTokens);\r
 \r
+  if (HttpInstance->TlsSb != NULL && HttpInstance->TlsChildHandle != NULL) {\r
+    //\r
+    // Destroy the TLS instance.   \r
+    //\r
+    HttpInstance->TlsSb->DestroyChild (HttpInstance->TlsSb, HttpInstance->TlsChildHandle);\r
+  }\r
+\r
   if (HttpInstance->Tcp4ChildHandle != NULL) {\r
     gBS->CloseProtocol (\r
            HttpInstance->Tcp4ChildHandle,\r
            &gEfiTcp4ProtocolGuid,\r
-           HttpInstance->Service->ImageHandle,\r
+           HttpInstance->Service->Ip4DriverBindingHandle,\r
            HttpInstance->Service->ControllerHandle\r
            );\r
 \r
     gBS->CloseProtocol (\r
            HttpInstance->Tcp4ChildHandle,\r
            &gEfiTcp4ProtocolGuid,\r
-           HttpInstance->Service->ImageHandle,\r
+           HttpInstance->Service->Ip4DriverBindingHandle,\r
            HttpInstance->Handle\r
            );\r
     \r
     NetLibDestroyServiceChild (\r
       HttpInstance->Service->ControllerHandle,\r
-      HttpInstance->Service->ImageHandle,\r
+      HttpInstance->Service->Ip4DriverBindingHandle,\r
       &gEfiTcp4ServiceBindingProtocolGuid,\r
       HttpInstance->Tcp4ChildHandle\r
       );\r
@@ -891,7 +898,7 @@ HttpCleanProtocol (
     gBS->CloseProtocol (\r
            HttpInstance->Service->Tcp4ChildHandle,\r
            &gEfiTcp4ProtocolGuid,\r
-           HttpInstance->Service->ImageHandle,\r
+           HttpInstance->Service->Ip4DriverBindingHandle,\r
            HttpInstance->Handle\r
            );\r
   }  \r
@@ -900,20 +907,20 @@ HttpCleanProtocol (
     gBS->CloseProtocol (\r
            HttpInstance->Tcp6ChildHandle,\r
            &gEfiTcp6ProtocolGuid,\r
-           HttpInstance->Service->ImageHandle,\r
+           HttpInstance->Service->Ip6DriverBindingHandle,\r
            HttpInstance->Service->ControllerHandle\r
            );\r
 \r
     gBS->CloseProtocol (\r
            HttpInstance->Tcp6ChildHandle,\r
            &gEfiTcp6ProtocolGuid,\r
-           HttpInstance->Service->ImageHandle,\r
+           HttpInstance->Service->Ip6DriverBindingHandle,\r
            HttpInstance->Handle\r
            );\r
     \r
     NetLibDestroyServiceChild (\r
       HttpInstance->Service->ControllerHandle,\r
-      HttpInstance->Service->ImageHandle,\r
+      HttpInstance->Service->Ip6DriverBindingHandle,\r
       &gEfiTcp6ServiceBindingProtocolGuid,\r
       HttpInstance->Tcp6ChildHandle\r
       );\r
@@ -923,7 +930,7 @@ HttpCleanProtocol (
     gBS->CloseProtocol (\r
            HttpInstance->Service->Tcp6ChildHandle,\r
            &gEfiTcp6ProtocolGuid,\r
-           HttpInstance->Service->ImageHandle,\r
+           HttpInstance->Service->Ip6DriverBindingHandle,\r
            HttpInstance->Handle\r
            );\r
   }\r
@@ -1475,6 +1482,8 @@ HttpTransmitTcp (
 \r
   Status                = EFI_SUCCESS;\r
   Buffer                = NULL;\r
+  TempFragment.Len      = 0;\r
+  TempFragment.Bulk     = NULL;\r
 \r
   //\r
   // Need to encrypt data.\r
@@ -1489,7 +1498,7 @@ HttpTransmitTcp (
       Status = EFI_OUT_OF_RESOURCES;\r
       return Status;\r
     }\r
-    ((TLS_RECORD_HEADER *) Buffer)->ContentType = TLS_CONTENT_TYPE_APPLICATION_DATA;\r
+    ((TLS_RECORD_HEADER *) Buffer)->ContentType = TlsContentTypeApplicationData;\r
     ((TLS_RECORD_HEADER *) Buffer)->Version.Major = HttpInstance->TlsConfigData.Version.Major;\r
     ((TLS_RECORD_HEADER *) Buffer)->Version.Minor = HttpInstance->TlsConfigData.Version.Minor;\r
     ((TLS_RECORD_HEADER *) Buffer)->Length = (UINT16) (TxStringLen);\r
@@ -1867,7 +1876,7 @@ HttpTcpReceiveHeader (
       //\r
       // Check whether we received end of HTTP headers.\r
       //\r
-      *EndofHeader = AsciiStrStr (*HttpHeaders, HTTP_END_OF_HDR_STR); \r
+      *EndofHeader = AsciiStrStr (*HttpHeaders, HTTP_END_OF_HDR_STR);\r
     };\r
     \r
     //\r
@@ -1987,7 +1996,9 @@ HttpTcpReceiveHeader (
   //\r
   // Skip the CRLF after the HTTP headers.\r
   //\r
-  *EndofHeader = *EndofHeader + AsciiStrLen (HTTP_END_OF_HDR_STR);  \r
+  *EndofHeader = *EndofHeader + AsciiStrLen (HTTP_END_OF_HDR_STR);\r
+\r
+  *SizeofHeaders = *EndofHeader - *HttpHeaders;\r
 \r
   return EFI_SUCCESS;\r
 }\r
@@ -2029,8 +2040,8 @@ HttpTcpReceiveBody (
   \r
   if (HttpInstance->LocalAddressIsIPv6) {\r
     Rx6Token = &Wrap->TcpWrap.Rx6Token;\r
-    Rx6Token ->Packet.RxData->DataLength = (UINT32) HttpMsg->BodyLength;\r
-    Rx6Token ->Packet.RxData->FragmentTable[0].FragmentLength = (UINT32) HttpMsg->BodyLength;\r
+    Rx6Token ->Packet.RxData->DataLength = (UINT32) MIN (MAX_UINT32, HttpMsg->BodyLength);\r
+    Rx6Token ->Packet.RxData->FragmentTable[0].FragmentLength = (UINT32) MIN (MAX_UINT32, HttpMsg->BodyLength);\r
     Rx6Token ->Packet.RxData->FragmentTable[0].FragmentBuffer = (VOID *) HttpMsg->Body;\r
     Rx6Token->CompletionToken.Status = EFI_NOT_READY;\r
 \r
@@ -2041,8 +2052,8 @@ HttpTcpReceiveBody (
     }\r
   } else {\r
     Rx4Token = &Wrap->TcpWrap.Rx4Token;\r
-    Rx4Token->Packet.RxData->DataLength = (UINT32) HttpMsg->BodyLength;\r
-    Rx4Token->Packet.RxData->FragmentTable[0].FragmentLength = (UINT32) HttpMsg->BodyLength;\r
+    Rx4Token->Packet.RxData->DataLength = (UINT32) MIN (MAX_UINT32, HttpMsg->BodyLength);\r
+    Rx4Token->Packet.RxData->FragmentTable[0].FragmentLength = (UINT32) MIN (MAX_UINT32, HttpMsg->BodyLength);\r
     Rx4Token->Packet.RxData->FragmentTable[0].FragmentBuffer = (VOID *) HttpMsg->Body;\r
     \r
     Rx4Token->CompletionToken.Status = EFI_NOT_READY;\r