]> git.proxmox.com Git - mirror_edk2.git/blobdiff - NetworkPkg/HttpDxe/HttpImpl.c
NetworkPkg/TlsAuthConfigDxe: Provide the UI to support TLS auth configuration
[mirror_edk2.git] / NetworkPkg / HttpDxe / HttpImpl.c
index 7ee661316e0f19b4ef4ad027fdc1adfe194d1d9a..6fcb0b7c6e27a0ddfa1fd64ac6bdb2cb16e24c8d 100644 (file)
@@ -114,7 +114,6 @@ EfiHttpGetModeData (
   @retval EFI_SUCCESS             Operation succeeded.\r
   @retval EFI_INVALID_PARAMETER   One or more of the following conditions is TRUE:\r
                                   This is NULL.\r
-                                  HttpConfigData is NULL.\r
                                   HttpConfigData->LocalAddressIsIPv6 is FALSE and\r
                                   HttpConfigData->IPv4Node is NULL.\r
                                   HttpConfigData->LocalAddressIsIPv6 is TRUE and\r
@@ -141,9 +140,9 @@ EfiHttpConfigure (
   // Check input parameters.\r
   //\r
   if (This == NULL ||\r
-      HttpConfigData == NULL ||\r
-     ((HttpConfigData->LocalAddressIsIPv6 && HttpConfigData->AccessPoint.IPv6Node == NULL) ||\r
-     (!HttpConfigData->LocalAddressIsIPv6 && HttpConfigData->AccessPoint.IPv4Node == NULL))) {\r
+      (HttpConfigData != NULL && \r
+       ((HttpConfigData->LocalAddressIsIPv6 && HttpConfigData->AccessPoint.IPv6Node == NULL) ||\r
+        (!HttpConfigData->LocalAddressIsIPv6 && HttpConfigData->AccessPoint.IPv4Node == NULL)))) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
@@ -237,6 +236,7 @@ EfiHttpRequest (
   VOID                          *UrlParser;\r
   EFI_STATUS                    Status;\r
   CHAR8                         *HostName;\r
+  UINTN                         HostNameSize;\r
   UINT16                        RemotePort;\r
   HTTP_PROTOCOL                 *HttpInstance;\r
   BOOLEAN                       Configure;\r
@@ -254,6 +254,7 @@ EfiHttpRequest (
   //\r
   Url = NULL;\r
   UrlParser = NULL;\r
+  RemotePort = 0;\r
   HostName = NULL;\r
   RequestMsg = NULL;\r
   HostNameStr = NULL;\r
@@ -343,7 +344,7 @@ EfiHttpRequest (
     }\r
 \r
 \r
-    UnicodeStrToAsciiStr (Request->Url, Url);\r
+    UnicodeStrToAsciiStrS (Request->Url, Url, UrlLen);\r
     UrlParser = NULL;\r
     Status = HttpParseUrl (Url, (UINT32) AsciiStrLen (Url), FALSE, &UrlParser);\r
     if (EFI_ERROR (Status)) {\r
@@ -443,13 +444,14 @@ EfiHttpRequest (
     }\r
 \r
     if (EFI_ERROR (Status)) {\r
-      HostNameStr = AllocateZeroPool ((AsciiStrLen (HostName) + 1) * sizeof (CHAR16));\r
+      HostNameSize = AsciiStrSize (HostName);\r
+      HostNameStr = AllocateZeroPool (HostNameSize * sizeof (CHAR16));\r
       if (HostNameStr == NULL) {\r
         Status = EFI_OUT_OF_RESOURCES;\r
         goto Error1;\r
       }\r
       \r
-      AsciiStrToUnicodeStr (HostName, HostNameStr);\r
+      AsciiStrToUnicodeStrS (HostName, HostNameStr, HostNameSize);\r
       if (!HttpInstance->LocalAddressIsIPv6) {\r
         Status = HttpDns4 (HttpInstance, HostNameStr, &HttpInstance->RemoteAddr);\r
       } else {\r
@@ -462,7 +464,6 @@ EfiHttpRequest (
       }\r
     }\r
 \r
-\r
     //\r
     // Save the RemotePort and RemoteHost.\r
     //\r
@@ -578,13 +579,13 @@ EfiHttpRequest (
   return EFI_SUCCESS;\r
 \r
 Error5:\r
-    //\r
-    // We would have inserted a TxToken only if Request structure is not NULL.\r
-    // Hence check before we do a remove in this error case.\r
-    //\r
-    if (Request != NULL) {\r
-      NetMapRemoveTail (&HttpInstance->TxTokens, NULL);\r
-    }\r
+  //\r
+  // We would have inserted a TxToken only if Request structure is not NULL.\r
+  // Hence check before we do a remove in this error case.\r
+  //\r
+  if (Request != NULL) {\r
+    NetMapRemoveTail (&HttpInstance->TxTokens, NULL);\r
+  }\r
 \r
 Error4:\r
   if (RequestMsg != NULL) {\r
@@ -606,7 +607,6 @@ Error2:
   }\r
 \r
 Error1:\r
-\r
   if (HostName != NULL) {\r
     FreePool (HostName);\r
   }\r
@@ -640,7 +640,6 @@ HttpCancelTokens (
   IN VOID                   *Context\r
   )\r
 {\r
-\r
   EFI_HTTP_TOKEN            *Token;\r
   HTTP_TOKEN_WRAP           *Wrap;\r
   HTTP_PROTOCOL             *HttpInstance;\r
@@ -658,42 +657,33 @@ HttpCancelTokens (
   Wrap = (HTTP_TOKEN_WRAP *) Item->Value;\r
   ASSERT (Wrap != NULL);\r
   HttpInstance = Wrap->HttpInstance;\r
-\r
-  //\r
-  // Free resources.\r
-  //\r
-  NetMapRemoveItem (Map, Item, NULL); \r
   \r
   if (!HttpInstance->LocalAddressIsIPv6) {\r
-    if (Wrap->TcpWrap.Tx4Token.CompletionToken.Event != NULL) {\r
-      gBS->CloseEvent (Wrap->TcpWrap.Tx4Token.CompletionToken.Event);\r
-    }\r
-    \r
     if (Wrap->TcpWrap.Rx4Token.CompletionToken.Event != NULL) {\r
-      gBS->CloseEvent (Wrap->TcpWrap.Rx4Token.CompletionToken.Event);\r
-    }\r
-    \r
-    if (Wrap->TcpWrap.Rx4Token.Packet.RxData->FragmentTable[0].FragmentBuffer != NULL) {\r
-      FreePool (Wrap->TcpWrap.Rx4Token.Packet.RxData->FragmentTable[0].FragmentBuffer);\r
-    }\r
+      //\r
+      // Cancle the Token before close its Event.\r
+      //\r
+      HttpInstance->Tcp4->Cancel (HttpInstance->Tcp4, &Wrap->TcpWrap.Rx4Token.CompletionToken);\r
 \r
-  } else {\r
-    if (Wrap->TcpWrap.Tx6Token.CompletionToken.Event != NULL) {\r
-      gBS->CloseEvent (Wrap->TcpWrap.Tx6Token.CompletionToken.Event);\r
+      //\r
+      // Dispatch the DPC queued by the NotifyFunction of the canceled token's events.\r
+      //\r
+      DispatchDpc ();\r
     }\r
-\r
+  } else {\r
     if (Wrap->TcpWrap.Rx6Token.CompletionToken.Event != NULL) {\r
-      gBS->CloseEvent (Wrap->TcpWrap.Rx6Token.CompletionToken.Event);\r
-    }\r
+      //\r
+      // Cancle the Token before close its Event.\r
+      //\r
+      HttpInstance->Tcp6->Cancel (HttpInstance->Tcp6, &Wrap->TcpWrap.Rx6Token.CompletionToken);\r
 \r
-    if (Wrap->TcpWrap.Rx6Token.Packet.RxData->FragmentTable[0].FragmentBuffer != NULL) {\r
-      FreePool (Wrap->TcpWrap.Rx6Token.Packet.RxData->FragmentTable[0].FragmentBuffer);\r
+      //\r
+      // Dispatch the DPC queued by the NotifyFunction of the canceled token's events.\r
+      //\r
+      DispatchDpc ();\r
     }\r
   }\r
 \r
-\r
-  FreePool (Wrap);\r
-\r
   //\r
   // If only one item is to be cancel, return EFI_ABORTED to stop\r
   // iterating the map any more.\r
@@ -908,6 +898,7 @@ HttpResponseWorker (
   SizeofHeaders             = 0;\r
   BufferSize                = 0;\r
   EndofHeader               = NULL;\r
+  ValueInItem               = NULL;\r
  \r
   if (HttpMsg->Data.Response != NULL) {\r
     //\r
@@ -1008,6 +999,7 @@ HttpResponseWorker (
     //\r
     StatusCodeStr = HttpHeaders + AsciiStrLen (HTTP_VERSION_STR) + 1;\r
     if (StatusCodeStr == NULL) {\r
+      Status = EFI_NOT_READY;\r
       goto Error;\r
     }\r
 \r
@@ -1018,6 +1010,7 @@ HttpResponseWorker (
     //\r
     Tmp = AsciiStrStr (HttpHeaders, HTTP_CRLF_STR);\r
     if (Tmp == NULL) {\r
+      Status = EFI_NOT_READY;\r
       goto Error;\r
     }\r
 \r
@@ -1064,6 +1057,7 @@ HttpResponseWorker (
     if (SizeofHeaders != 0) {\r
       HeaderTmp = AllocateZeroPool (SizeofHeaders);\r
       if (HeaderTmp == NULL) {\r
+        Status = EFI_OUT_OF_RESOURCES;\r
         goto Error2;\r
       }\r
 \r
@@ -1203,42 +1197,14 @@ HttpResponseWorker (
 \r
   ASSERT (HttpInstance->MsgParser != NULL);\r
 \r
-  if (HttpInstance->TimeoutEvent == NULL) {\r
-    //\r
-    // Create TimeoutEvent for response\r
-    //\r
-    Status = gBS->CreateEvent (\r
-                    EVT_TIMER,\r
-                    TPL_CALLBACK,\r
-                    NULL,\r
-                    NULL,\r
-                    &HttpInstance->TimeoutEvent\r
-                    );\r
-    if (EFI_ERROR (Status)) {\r
-      goto Error2;\r
-    }\r
-  }\r
-\r
-  //\r
-  // Start the timer, and wait Timeout seconds to receive the body packet.\r
-  //\r
-  Status = gBS->SetTimer (HttpInstance->TimeoutEvent, TimerRelative, HTTP_RESPONSE_TIMEOUT * TICKS_PER_SECOND);\r
-  if (EFI_ERROR (Status)) {\r
-    goto Error2;\r
-  }\r
-\r
   //\r
   // We still need receive more data when there is no cache data and MsgParser is not NULL;\r
   //\r
-  Status = HttpTcpReceiveBody (Wrap, HttpMsg, HttpInstance->TimeoutEvent);\r
-\r
-  gBS->SetTimer (HttpInstance->TimeoutEvent, TimerCancel, 0);\r
-\r
+  Status = HttpTcpReceiveBody (Wrap, HttpMsg);\r
   if (EFI_ERROR (Status)) {\r
     goto Error2;\r
   }\r
 \r
-  FreePool (Wrap);\r
   return Status;\r
 \r
 Exit:\r
@@ -1264,6 +1230,11 @@ Error2:
   }\r
 \r
 Error:\r
+  Item = NetMapFindKey (&Wrap->HttpInstance->RxTokens, Wrap->HttpToken);\r
+  if (Item != NULL) {\r
+    NetMapRemoveItem (&Wrap->HttpInstance->RxTokens, Item, NULL);\r
+  }\r
+  \r
   HttpTcpTokenCleanup (Wrap);\r
   \r
   if (HttpHeaders != NULL) {\r