[edk2] [PATCH v2 1/1] MdeModulePkg:DxeHttpLib: Add checks in HttpGenRequestMessage API

2016-05-05 Thread Nagaraj Hegde
v2:
More input validation based on Request and HeaderCount.

HttpGenRequestMessage assumes that HTTP message would always
contain a request-line, headers and an optional message body.
However, subsequent to a HTTP PUT/POST request, HTTP requests
would contain just the message body. This patch supports
creation of such request messages with additional checks.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Hegde, Nagaraj P nagaraj-p.he...@hpe.com
---
 MdeModulePkg/Library/DxeHttpLib/DxeHttpLib.c | 225 +++-
 1 file changed, 130 insertions(+), 95 deletions(-)

diff --git a/MdeModulePkg/Library/DxeHttpLib/DxeHttpLib.c 
b/MdeModulePkg/Library/DxeHttpLib/DxeHttpLib.c
index 8d61d0b..1b0858c 100644
--- a/MdeModulePkg/Library/DxeHttpLib/DxeHttpLib.c
+++ b/MdeModulePkg/Library/DxeHttpLib/DxeHttpLib.c
@@ -1681,61 +1681,92 @@ HttpGenRequestMessage (
   HttpUtilitiesProtocol = NULL;
 
   //
-  // Locate the HTTP_UTILITIES protocol.
+  // 1. If we have a Request, we cannot have a NULL Url
+  // 2. If we have a Request, HeaderCount can not be non-zero
+  // 3. If we do not have a Request, HeaderCount should be zero
+  // 4. If we do not have Request and Headers, we need at least a message-body
   //
-  Status = gBS->LocateProtocol (
-  ,
-  NULL,
-  (VOID **)
-  );
-
-  if (EFI_ERROR (Status)) {
-DEBUG ((DEBUG_ERROR,"Failed to locate Http Utilities protocol. Status = 
%r.\n", Status));
-return Status;
+  if ((Message->Data.Request != NULL && Url == NULL) ||
+  (Message->Data.Request != NULL && Message->HeaderCount == 0) ||
+  (Message->Data.Request == NULL && Message->HeaderCount != 0) ||
+  (Message->Data.Request == NULL && Message->HeaderCount == 0 && 
Message->BodyLength == 0)) {
+return EFI_INVALID_PARAMETER;
+  }
+
+  if (Message->HeaderCount != 0) {
+//
+// Locate the HTTP_UTILITIES protocol.
+//
+Status = gBS->LocateProtocol (
+,
+NULL,
+(VOID **)
+);
+
+if (EFI_ERROR (Status)) {
+  DEBUG ((DEBUG_ERROR,"Failed to locate Http Utilities protocol. Status = 
%r.\n", Status));
+  return Status;
+}
+
+//
+// Build AppendList to send into HttpUtilitiesBuild
+//
+AppendList = AllocateZeroPool (sizeof (EFI_HTTP_HEADER *) * 
(Message->HeaderCount));
+if (AppendList == NULL) {
+  return EFI_OUT_OF_RESOURCES;
+}
+
+for(Index = 0; Index < Message->HeaderCount; Index++){
+  AppendList[Index] = >Headers[Index];
+}
+
+//
+// Build raw HTTP Headers
+//
+Status = HttpUtilitiesProtocol->Build (
+HttpUtilitiesProtocol,
+0,
+NULL,
+0,
+NULL,
+Message->HeaderCount,
+AppendList,
+,
+
+);
+
+if (AppendList != NULL) {
+  FreePool (AppendList);
+}
+
+if (EFI_ERROR (Status) || HttpHdr == NULL){
+  return Status;
+}
   }
 
   //
-  // Build AppendList to send into HttpUtilitiesBuild
+  // If we have headers to be sent, account for it.
   //
-  AppendList = AllocateZeroPool (sizeof (EFI_HTTP_HEADER *) * 
(Message->HeaderCount));
-  if (AppendList == NULL) {
-return EFI_OUT_OF_RESOURCES;
-  }
-
-  for(Index = 0; Index < Message->HeaderCount; Index++){
-AppendList[Index] = >Headers[Index];
+  if (Message->HeaderCount != 0) {
+MsgSize = HttpHdrSize;
   }
 
   //
-  // Build raw HTTP Headers
+  // If we have a request line, account for the fields.
   //
-  Status = HttpUtilitiesProtocol->Build (
-  HttpUtilitiesProtocol,
-  0,
-  NULL,
-  0,
-  NULL,
-  Message->HeaderCount,
-  AppendList,
-  ,
-  
-  );
-
-  if (AppendList != NULL) {
-FreePool (AppendList);
-  }
-
-  if (EFI_ERROR (Status) || HttpHdr == NULL){
-return Status;
+  if (Message->Data.Request != NULL) {
+MsgSize += HTTP_METHOD_MAXIMUM_LEN + AsciiStrLen (HTTP_VERSION_CRLF_STR) + 
AsciiStrLen (Url);
   }
 
+
   //
-  // Calculate HTTP message length.
+  // If we have a message body to be sent, account for it.
   //
-  MsgSize = Message->BodyLength + HTTP_METHOD_MAXIMUM_LEN + AsciiStrLen (Url) +
-AsciiStrLen (HTTP_VERSION_CRLF_STR) + HttpHdrSize;
-
+  MsgSize += Message->BodyLength;
 
+  //
+  // memory for the string that needs to be sent to TCP
+  //
   *RequestMsg = AllocateZeroPool (MsgSize);
   if (*RequestMsg == NULL) {
 Status = EFI_OUT_OF_RESOURCES;
@@ -1746,60 +1777,64 @@ HttpGenRequestMessage (
   //
   // Construct header request
   //
-  switch (Message->Data.Request->Method) {
-  case HttpMethodGet:
-StrLength = sizeof (HTTP_METHOD_GET) - 1;
-CopyMem (RequestPtr, HTTP_METHOD_GET, StrLength);
-RequestPtr += StrLength;
-break;
-  

[edk2] [PATCH v1 1/1] NetworkPkg:HttpDxe: Code changes to support HTTP PUT/POST operations

2016-05-04 Thread Nagaraj Hegde
Code changes enables HttpDxe to handle PUT/POST operations.
EfiHttpRequest assumes "Request" and "HttpMsg->Headers" can
never be NULL. Also, HttpResponseWorker assumes HTTP Reponse
will contain headers. We could have response which could contain
only a string (HTTP 100 Continue) and no headers. Code changes
tries to do-away from these assumptions, which would enable
HttpDxe to support PUT/POST operations.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Hegde, Nagaraj P nagaraj-p.he...@hpe.com
---
 NetworkPkg/HttpDxe/HttpDriver.c |   3 +
 NetworkPkg/HttpDxe/HttpImpl.c   | 399 +++-
 NetworkPkg/HttpDxe/HttpProto.h  |   1 +
 3 files changed, 226 insertions(+), 177 deletions(-)

diff --git a/NetworkPkg/HttpDxe/HttpDriver.c b/NetworkPkg/HttpDxe/HttpDriver.c
index 2518f4e..0bde012 100644
--- a/NetworkPkg/HttpDxe/HttpDriver.c
+++ b/NetworkPkg/HttpDxe/HttpDriver.c
@@ -2,6 +2,7 @@
   The driver binding and service binding protocol for HttpDxe driver.
 
   Copyright (c) 2015, Intel Corporation. All rights reserved.
+  (C) Copyright 2016 Hewlett Packard Enterprise Development LP
 
   This program and the accompanying materials
   are licensed and made available under the terms and conditions of the BSD 
License
@@ -939,6 +940,8 @@ HttpServiceBindingCreateChild (
   
   HttpInstance->Signature = HTTP_PROTOCOL_SIGNATURE;
   HttpInstance->Service   = HttpService;
+  HttpInstance->Method = HttpMethodMax;
+
   CopyMem (>Http, , sizeof 
(HttpInstance->Http));
   NetMapInit (>TxTokens);
   NetMapInit (>RxTokens);
diff --git a/NetworkPkg/HttpDxe/HttpImpl.c b/NetworkPkg/HttpDxe/HttpImpl.c
index 7a236f4..9360355 100644
--- a/NetworkPkg/HttpDxe/HttpImpl.c
+++ b/NetworkPkg/HttpDxe/HttpImpl.c
@@ -248,151 +248,178 @@ EfiHttpRequest (
   HTTP_TOKEN_WRAP   *Wrap;
   CHAR8 *FileUrl;
   UINTN RequestMsgSize;
-  
+
+  Url = NULL;
+  HostName = NULL;
+  RequestMsg = NULL;
+  HostNameStr = NULL;
+  Wrap = NULL;
+  FileUrl = NULL;
   if ((This == NULL) || (Token == NULL)) {
 return EFI_INVALID_PARAMETER;
   }
 
   HttpMsg = Token->Message;
-  if ((HttpMsg == NULL) || (HttpMsg->Headers == NULL)) {
+  if (HttpMsg == NULL) {
 return EFI_INVALID_PARAMETER;
   }
 
-  //
-  // Current implementation does not support POST/PUT method.
-  // If future version supports these two methods, Request could be NULL for a 
special case that to send large amounts
-  // of data. For this case, the implementation need check whether previous 
call to Request() has been completed or not.
-  // 
-  //
   Request = HttpMsg->Data.Request;
-  if ((Request == NULL) || (Request->Url == NULL)) {
-return EFI_INVALID_PARAMETER;
-  }
 
   //
-  // Only support GET and HEAD method in current implementation.
+  // Only support GET, HEAD, PUT and POST method in current implementation.
   //
-  if ((Request->Method != HttpMethodGet) && (Request->Method != 
HttpMethodHead)) {
+  if ((Request != NULL) && (Request->Method != HttpMethodGet) &&
+  (Request->Method != HttpMethodHead) && (Request->Method != 
HttpMethodPut) && (Request->Method != HttpMethodPost)) {
 return EFI_UNSUPPORTED;
   }
 
   HttpInstance = HTTP_INSTANCE_FROM_PROTOCOL (This);
   ASSERT (HttpInstance != NULL);
 
+  if (Request != NULL) {
+HttpInstance->Method = Request->Method;
+  }
+
   if (HttpInstance->State < HTTP_STATE_HTTP_CONFIGED) {
 return EFI_NOT_STARTED;
   }
 
-  //
-  // Check whether the token already existed.
-  //
-  if (EFI_ERROR (NetMapIterate (>TxTokens, HttpTokenExist, 
Token))) {
-return EFI_ACCESS_DENIED;   
-  }  
+  if (Request == NULL) {
+//
+// Request would be NULL only for PUT/POST operation (in the current 
implementation)
+//
+if ((HttpInstance->Method != HttpMethodPut) && (HttpInstance->Method != 
HttpMethodPost)) {
+  return EFI_INVALID_PARAMETER;
+}
 
-  HostName= NULL;
-  Wrap= NULL;
-  HostNameStr = NULL;
+//
+// For PUT/POST, we need to have the TCP already configured. Bail out if 
it is not!
+//
+if (HttpInstance->State < HTTP_STATE_TCP_CONFIGED) {
+  return EFI_INVALID_PARAMETER;
+}
 
-  //
-  // Parse the URI of the remote host.
-  //
-  Url = HttpInstance->Url;
-  UrlLen = StrLen (Request->Url) + 1;
-  if (UrlLen > HTTP_URL_BUFFER_LEN) {
-Url = AllocateZeroPool (UrlLen);
-if (Url == NULL) {
-  return EFI_OUT_OF_RESOURCES;
+//
+// We need to have the Message Body for sending the HTTP message across in 
these cases.
+//
+if (HttpMsg->Body == NULL || HttpMsg->BodyLength == 0) {
+  return EFI_INVALID_PARAMETER;
 }
-FreePool (HttpInstance->Url);
-HttpInstance->Url = Url;
-  } 
 
+//
+// Use existing TCP instance to transmit the packet.
+//
+Configure   = FALSE;
+ReConfigure = FALSE;
+  } else {
+//
+// Check whether the token already existed.
+//
+if (EFI_ERROR (NetMapIterate (>TxTokens, HttpTokenExist, 

[edk2] [PATCH v1 1/1] MdeModulePkg:DxeHttpLib: Add checks in HttpGenRequestMessage API

2016-05-04 Thread Nagaraj Hegde
HttpGenRequestMessage assumes that HTTP message would always
contain a request-line, headers and an optional message body.
However, subsequent to a HTTP PUT/POST request, HTTP requests
would contain just the message body. This patch supports
creation of such request messages with additional checks.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Hegde, Nagaraj P nagaraj-p.he...@hpe.com
---
 MdeModulePkg/Library/DxeHttpLib/DxeHttpLib.c | 219 +++-
 1 file changed, 124 insertions(+), 95 deletions(-)

diff --git a/MdeModulePkg/Library/DxeHttpLib/DxeHttpLib.c 
b/MdeModulePkg/Library/DxeHttpLib/DxeHttpLib.c
index 8d61d0b..fa0f591 100644
--- a/MdeModulePkg/Library/DxeHttpLib/DxeHttpLib.c
+++ b/MdeModulePkg/Library/DxeHttpLib/DxeHttpLib.c
@@ -1681,61 +1681,86 @@ HttpGenRequestMessage (
   HttpUtilitiesProtocol = NULL;
 
   //
-  // Locate the HTTP_UTILITIES protocol.
+  // If we have a Request, we cannot have a NULL Url
   //
-  Status = gBS->LocateProtocol (
-  ,
-  NULL,
-  (VOID **)
-  );
-
-  if (EFI_ERROR (Status)) {
-DEBUG ((DEBUG_ERROR,"Failed to locate Http Utilities protocol. Status = 
%r.\n", Status));
-return Status;
+  if (Message->Data.Request != NULL && Url == NULL) {
+return EFI_INVALID_PARAMETER;
+  }
+
+  if (Message->HeaderCount != 0) {
+//
+// Locate the HTTP_UTILITIES protocol.
+//
+Status = gBS->LocateProtocol (
+,
+NULL,
+(VOID **)
+);
+
+if (EFI_ERROR (Status)) {
+  DEBUG ((DEBUG_ERROR,"Failed to locate Http Utilities protocol. Status = 
%r.\n", Status));
+  return Status;
+}
+
+//
+// Build AppendList to send into HttpUtilitiesBuild
+//
+AppendList = AllocateZeroPool (sizeof (EFI_HTTP_HEADER *) * 
(Message->HeaderCount));
+if (AppendList == NULL) {
+  return EFI_OUT_OF_RESOURCES;
+}
+
+for(Index = 0; Index < Message->HeaderCount; Index++){
+  AppendList[Index] = >Headers[Index];
+}
+
+//
+// Build raw HTTP Headers
+//
+Status = HttpUtilitiesProtocol->Build (
+HttpUtilitiesProtocol,
+0,
+NULL,
+0,
+NULL,
+Message->HeaderCount,
+AppendList,
+,
+
+);
+
+if (AppendList != NULL) {
+  FreePool (AppendList);
+}
+
+if (EFI_ERROR (Status) || HttpHdr == NULL){
+  return Status;
+}
   }
 
   //
-  // Build AppendList to send into HttpUtilitiesBuild
+  // If we have headers to be sent, account for it.
   //
-  AppendList = AllocateZeroPool (sizeof (EFI_HTTP_HEADER *) * 
(Message->HeaderCount));
-  if (AppendList == NULL) {
-return EFI_OUT_OF_RESOURCES;
-  }
-
-  for(Index = 0; Index < Message->HeaderCount; Index++){
-AppendList[Index] = >Headers[Index];
+  if (Message->HeaderCount != 0) {
+MsgSize = HttpHdrSize;
   }
 
   //
-  // Build raw HTTP Headers
+  // If we have a request line, account for the fields.
   //
-  Status = HttpUtilitiesProtocol->Build (
-  HttpUtilitiesProtocol,
-  0,
-  NULL,
-  0,
-  NULL,
-  Message->HeaderCount,
-  AppendList,
-  ,
-  
-  );
-
-  if (AppendList != NULL) {
-FreePool (AppendList);
-  }
-
-  if (EFI_ERROR (Status) || HttpHdr == NULL){
-return Status;
+  if (Message->Data.Request != NULL) {
+MsgSize += HTTP_METHOD_MAXIMUM_LEN + AsciiStrLen (HTTP_VERSION_CRLF_STR) + 
AsciiStrLen (Url);
   }
 
+
   //
-  // Calculate HTTP message length.
+  // If we have a message body to be sent, account for it.
   //
-  MsgSize = Message->BodyLength + HTTP_METHOD_MAXIMUM_LEN + AsciiStrLen (Url) +
-AsciiStrLen (HTTP_VERSION_CRLF_STR) + HttpHdrSize;
-
+  MsgSize += Message->BodyLength;
 
+  //
+  // memory for the string that needs to be sent to TCP
+  //
   *RequestMsg = AllocateZeroPool (MsgSize);
   if (*RequestMsg == NULL) {
 Status = EFI_OUT_OF_RESOURCES;
@@ -1746,60 +1771,64 @@ HttpGenRequestMessage (
   //
   // Construct header request
   //
-  switch (Message->Data.Request->Method) {
-  case HttpMethodGet:
-StrLength = sizeof (HTTP_METHOD_GET) - 1;
-CopyMem (RequestPtr, HTTP_METHOD_GET, StrLength);
-RequestPtr += StrLength;
-break;
-  case HttpMethodPut:
-StrLength = sizeof (HTTP_METHOD_PUT) - 1;
-CopyMem (RequestPtr, HTTP_METHOD_PUT, StrLength);
-RequestPtr += StrLength;
-break;
-  case HttpMethodPatch:
-StrLength = sizeof (HTTP_METHOD_PATCH) - 1;
-CopyMem (RequestPtr, HTTP_METHOD_PATCH, StrLength);
-RequestPtr += StrLength;
-break;
-  case HttpMethodPost:
-StrLength = sizeof (HTTP_METHOD_POST) - 1;
-CopyMem (RequestPtr, HTTP_METHOD_POST, StrLength);
-RequestPtr += StrLength;
-break;
-  case 

[edk2] [PATCH v1] MdePkg:Http11.h: Add defines for "Expect" header

2016-04-25 Thread Nagaraj Hegde
Add #defines for "Expect" header, which is a part of RFC 2616
and used for HTTP PUT/POST operations.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Hegde, Nagaraj P 
---
 MdePkg/Include/IndustryStandard/Http11.h | 13 +
 1 file changed, 13 insertions(+)

diff --git a/MdePkg/Include/IndustryStandard/Http11.h 
b/MdePkg/Include/IndustryStandard/Http11.h
index 8a09f96..f735430 100644
--- a/MdePkg/Include/IndustryStandard/Http11.h
+++ b/MdePkg/Include/IndustryStandard/Http11.h
@@ -234,6 +234,19 @@
 /// Example: X-Auth-Token: 24de6b1f8fa147ad59f6452def628798
 ///
 #define  HTTP_HEADER_X_AUTH_TOKEN  "X-Auth-Token"
+///
+/// Expect Header
+/// The "Expect" header field in a request indicates a certain set of
+/// behaviors (expectations) that need to be supported by the server in
+/// order to properly handle this request. The only such expectation
+/// defined by this specification is 100-continue.
+///
+#define  HTTP_HEADER_EXPECT"Expect"
+
+///
+/// Expect Header Value
+///
+#define  HTTP_EXPECT_100_CONTINUE   "100-continue"
 
 #pragma pack()
 
-- 
2.6.2.windows.1

___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


[edk2] [PATCH v1 1/2] MdeModulePkg:DxeHttpLib: Update to DxeHttpLib API

2016-04-04 Thread Nagaraj Hegde
Rename and update the logic of HttpGenRequestString API provided
by DxeHttpLib. The RequestString size is returned as an argument.
The user is not expected to do a AsciiStrLen anymore, and is not
logical too, since request string can contain message body and
using AsciiStrLen on such a string can provide truncated lengths.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Nagaraj Hegde <nagaraj-p.he...@hpe.com>
---
 MdeModulePkg/Include/Library/HttpLib.h   | 10 +++---
 MdeModulePkg/Library/DxeHttpLib/DxeHttpLib.c | 34 +---
 2 files changed, 28 insertions(+), 16 deletions(-)

diff --git a/MdeModulePkg/Include/Library/HttpLib.h 
b/MdeModulePkg/Include/Library/HttpLib.h
index af9ab5f..d8424ad 100644
--- a/MdeModulePkg/Include/Library/HttpLib.h
+++ b/MdeModulePkg/Include/Library/HttpLib.h
@@ -417,12 +417,13 @@ HttpFreeHeaderFields (
   );
 
 /**
-  Generate HTTP request string.
+  Generate HTTP request message.
 
   @param[in]   MessagePointer to storage containing HTTP message 
data.
   @param[in]   UrlThe URL of a remote host.
-  @param[out]  RequestString  Pointer to the created HTTP request string.
+  @param[out]  RequestMsg Pointer to the created HTTP request message.
   NULL if any error occured.
+  @param[out]  RequestMsgSize Size of the RequestMsg (in bytes).
 
   @return EFI_SUCCESS If HTTP request string was created 
successfully
   @retval EFI_OUT_OF_RESOURCESFailed to allocate resources.
@@ -431,10 +432,11 @@ HttpFreeHeaderFields (
 **/
 EFI_STATUS
 EFIAPI
-HttpGenRequestString (
+HttpGenRequestMessage (
   IN CONST EFI_HTTP_MESSAGE*Message,
   IN CONST CHAR8   *Url,
- OUT CHAR8 **RequestString
+ OUT CHAR8 **RequestMsg,
+ OUT UINTN *RequestMsgSize
   );
 
 /**
diff --git a/MdeModulePkg/Library/DxeHttpLib/DxeHttpLib.c 
b/MdeModulePkg/Library/DxeHttpLib/DxeHttpLib.c
index 662c40c..cdbb0c7 100644
--- a/MdeModulePkg/Library/DxeHttpLib/DxeHttpLib.c
+++ b/MdeModulePkg/Library/DxeHttpLib/DxeHttpLib.c
@@ -1630,12 +1630,13 @@ HttpFreeHeaderFields (
 }
 
 /**
-  Generate HTTP request string.
+  Generate HTTP request message.
 
   @param[in]   MessagePointer to storage containing HTTP message 
data.
   @param[in]   UrlThe URL of a remote host.
-  @param[out]  RequestString  Pointer to the created HTTP request string.
+  @param[out]  RequestMsg Pointer to the created HTTP request message.
   NULL if any error occured.
+  @param[out]  RequestMsgSize Size of the RequestMsg (in bytes).
 
   @return EFI_SUCCESS If HTTP request string was created 
successfully
   @retval EFI_OUT_OF_RESOURCESFailed to allocate resources.
@@ -1644,10 +1645,11 @@ HttpFreeHeaderFields (
 **/
 EFI_STATUS
 EFIAPI
-HttpGenRequestString (
+HttpGenRequestMessage (
   IN CONST EFI_HTTP_MESSAGE*Message,
   IN CONST CHAR8   *Url,
- OUT CHAR8 **Request
+ OUT CHAR8 **RequestMsg,
+ OUT UINTN *RequestMsgSize
   )
 {
   EFI_STATUS   Status;
@@ -1664,7 +1666,7 @@ HttpGenRequestString (
 
   ASSERT (Message != NULL);
 
-  *Request = NULL;
+  *RequestMsg = NULL;
   MsgSize = 0;
   Success = FALSE;
   HttpHdr = NULL;
@@ -1727,13 +1729,13 @@ HttpGenRequestString (
 AsciiStrLen (HTTP_VERSION_CRLF_STR) + HttpHdrSize;
 
 
-  *Request = AllocateZeroPool (MsgSize);
-  if (*Request == NULL) {
+  *RequestMsg = AllocateZeroPool (MsgSize);
+  if (*RequestMsg == NULL) {
 Status = EFI_OUT_OF_RESOURCES;
 goto Exit;
   }
 
-  RequestPtr = *Request;
+  RequestPtr = *RequestMsg;
   //
   // Construct header request
   //
@@ -1793,18 +1795,26 @@ HttpGenRequestString (
   RequestPtr += HttpHdrSize;
 
   //
+  // Construct body
+  //
+  if (Message->Body != NULL) {
+CopyMem (RequestPtr, Message->Body, Message->BodyLength);
+RequestPtr += Message->BodyLength;
+  }
+
+  //
   // Done
   //
-  *RequestPtr = 0;
+  (*RequestMsgSize) = (UINTN)(RequestPtr) - (UINTN)(*RequestMsg);
   Success = TRUE;
 
 Exit:
 
   if (!Success) {
-if (*Request != NULL) {
-  FreePool (*Request);
+if (*RequestMsg != NULL) {
+  FreePool (*RequestMsg);
 }
-*Request = NULL;
+*RequestMsg = NULL;
 return Status;
   }
 
-- 
2.6.2.windows.1

___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


[edk2] [PATCH v1 2/2] NetworkPkg:HttpDxe:Consume DxeHttpLib API changes

2016-04-04 Thread Nagaraj Hegde
HttpGenRequestString is updated to HttpGenRequestMessage,
with an additional argument. This patch updates the caller
of the DxeHttpLib API. Also, we will avoid adding any '\0'
to the string, which was added to make AsciiStrLen to
work on the string.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Nagaraj Hegde <nagaraj-p.he...@hpe.com>
---
 NetworkPkg/HttpDxe/HttpImpl.c   | 15 ---
 NetworkPkg/HttpDxe/HttpProto.c  | 14 --
 NetworkPkg/HttpUtilitiesDxe/HttpUtilitiesProtocol.c |  9 +
 3 files changed, 17 insertions(+), 21 deletions(-)

diff --git a/NetworkPkg/HttpDxe/HttpImpl.c b/NetworkPkg/HttpDxe/HttpImpl.c
index 63b683e..eb44b09 100644
--- a/NetworkPkg/HttpDxe/HttpImpl.c
+++ b/NetworkPkg/HttpDxe/HttpImpl.c
@@ -240,12 +240,13 @@ EfiHttpRequest (
   HTTP_PROTOCOL *HttpInstance;
   BOOLEAN   Configure;
   BOOLEAN   ReConfigure;
-  CHAR8 *RequestStr;
+  CHAR8 *RequestMsg;
   CHAR8 *Url;
   UINTN UrlLen;
   CHAR16*HostNameStr;
   HTTP_TOKEN_WRAP   *Wrap;
   CHAR8 *FileUrl;
+  UINTN RequestMsgSize;
   
   if ((This == NULL) || (Token == NULL)) {
 return EFI_INVALID_PARAMETER;
@@ -314,7 +315,7 @@ EfiHttpRequest (
 goto Error1;
   }
 
-  RequestStr = NULL;
+  RequestMsg = NULL;
   HostName   = NULL;
   Status = HttpUrlGetHostName (Url, UrlParser, );
   if (EFI_ERROR (Status)) {
@@ -498,7 +499,7 @@ EfiHttpRequest (
 }
   }
 
-  Status = HttpGenRequestString (HttpMsg, FileUrl, );
+  Status = HttpGenRequestMessage (HttpMsg, FileUrl, , 
);
 
   if (EFI_ERROR (Status)) {
 goto Error3;
@@ -515,8 +516,8 @@ EfiHttpRequest (
   Status = HttpTransmitTcp (
  HttpInstance,
  Wrap,
- (UINT8*) RequestStr,
- AsciiStrLen (RequestStr)
+ (UINT8*) RequestMsg,
+ RequestMsgSize
  );
   if (EFI_ERROR (Status)) {
 goto Error5;
@@ -534,8 +535,8 @@ Error5:
 NetMapRemoveTail (>TxTokens, NULL);
 
 Error4:
-  if (RequestStr != NULL) {
-FreePool (RequestStr);
+  if (RequestMsg != NULL) {
+FreePool (RequestMsg);
   }  
 
 Error3:
diff --git a/NetworkPkg/HttpDxe/HttpProto.c b/NetworkPkg/HttpDxe/HttpProto.c
index 156f138..8b0c894 100644
--- a/NetworkPkg/HttpDxe/HttpProto.c
+++ b/NetworkPkg/HttpDxe/HttpProto.c
@@ -1462,8 +1462,9 @@ HttpTcpTransmit (
 {
   HTTP_TOKEN_WRAP   *ValueInItem;
   EFI_STATUSStatus;
-  CHAR8 *RequestStr;
+  CHAR8 *RequestMsg;
   CHAR8 *Url;
+  UINTN RequestMsgSize;
 
   ValueInItem = (HTTP_TOKEN_WRAP *) Item->Value;
   if (ValueInItem->TcpWrap.IsTxDone) {
@@ -1483,10 +1484,11 @@ HttpTcpTransmit (
   //
   // Create request message.
   //
-  Status = HttpGenRequestString (
+  Status = HttpGenRequestMessage (
  ValueInItem->HttpToken->Message,
  Url,
- 
+ ,
+ 
  );
   FreePool (Url);
 
@@ -1500,10 +1502,10 @@ HttpTcpTransmit (
   Status = HttpTransmitTcp (
  ValueInItem->HttpInstance,
  ValueInItem,
- (UINT8*) RequestStr,
- AsciiStrLen (RequestStr)
+ (UINT8*) RequestMsg,
+ RequestMsgSize
  );
-  FreePool (RequestStr);
+  FreePool (RequestMsg);
   return Status;
 }
 
diff --git a/NetworkPkg/HttpUtilitiesDxe/HttpUtilitiesProtocol.c 
b/NetworkPkg/HttpUtilitiesDxe/HttpUtilitiesProtocol.c
index 739d3b7..79001de 100644
--- a/NetworkPkg/HttpUtilitiesDxe/HttpUtilitiesProtocol.c
+++ b/NetworkPkg/HttpUtilitiesDxe/HttpUtilitiesProtocol.c
@@ -207,11 +207,6 @@ HttpUtilitiesBuild (
   StrLength = sizeof("\r\n") - 1;
   *NewMessageSize += StrLength;
 
-  //
-  // Final 0 for end flag
-  //
-  *NewMessageSize += 1; 
-
   *NewMessage = AllocateZeroPool (*NewMessageSize);
   if (*NewMessage == NULL) {
 Status = EFI_OUT_OF_RESOURCES;
@@ -243,9 +238,7 @@ HttpUtilitiesBuild (
   CopyMem (NewMessagePtr, "\r\n", StrLength);
   NewMessagePtr += StrLength;
 
-  *NewMessagePtr = 0;
-
-  ASSERT (*NewMessageSize == (UINTN)NewMessagePtr - (UINTN)(*NewMessage) + 1);
+  ASSERT (*NewMessageSize == (UINTN)NewMessagePtr - (UINTN)(*NewMessage));
 
   //
   // Free allocated buffer 
-- 
2.6.2.windows.1

___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


[edk2] [PATCH v1 0/2] Rename and update HttpGenRequestString API

2016-04-04 Thread Nagaraj Hegde
This patch series updates the message creation logic for the API
HttpGenRequestString in DxeHttpLib and also updates the name of the 
API to avoid confusion. Following the update to API are the changes
to the callers.

Nagaraj Hegde (2):
  MdeModulePkg:DxeHttpLib: Update to DxeHttpLib API
  NetworkPkg:HttpDxe:Consume DxeHttpLib API changes

 MdeModulePkg/Include/Library/HttpLib.h  | 10 +++---
 MdeModulePkg/Library/DxeHttpLib/DxeHttpLib.c| 34 +---
 NetworkPkg/HttpDxe/HttpImpl.c   | 15 +
 NetworkPkg/HttpDxe/HttpProto.c  | 14 
 NetworkPkg/HttpUtilitiesDxe/HttpUtilitiesProtocol.c |  9 +-
 5 files changed, 45 insertions(+), 37 deletions(-)

-- 
2.6.2.windows.1

___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


[edk2] [PATCH] NetworkPkg/HttpDxe: Missing CloseEvent() in HttpResponseWorker

2015-11-03 Thread Nagaraj Hegde
Two additional scenarios in which CloseEvent() needs to be called:

We sent a Request to HTTP server, following which we did a
Response() call, with the intent of capturing only the headers.
In this case, we execute an if condition in HttpResponseWorker do
a goto Exit. HttpDxe will cache the body that it received for which
we dint ask for right now. After we have received the headers, we
call a Response() again. Now, we get the data out of cache and
again do a goto Exit. In both cases, two CreateEvent() are called,
one on Event in RxToken in Wrap structure and another on Event in
RxToken in HttpInstance structure. In Exit label, we are missing
the CloseEvent() call for both the Events created.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Nagaraj Hegde <nagaraj-p.he...@hpe.com>
---
 NetworkPkg/HttpDxe/HttpImpl.c | 12 
 1 file changed, 12 insertions(+)

diff --git a/NetworkPkg/HttpDxe/HttpImpl.c b/NetworkPkg/HttpDxe/HttpImpl.c
index 3094400..0e7e60d 100644
--- a/NetworkPkg/HttpDxe/HttpImpl.c
+++ b/NetworkPkg/HttpDxe/HttpImpl.c
@@ -1130,6 +1130,18 @@ Exit:
   }
   Token->Status = Status;
   gBS->SignalEvent (Token->Event);
+
+  if (Wrap != NULL) {
+if (Wrap->TcpWrap.RxToken.CompletionToken.Event != NULL) {
+  gBS->CloseEvent (Wrap->TcpWrap.RxToken.CompletionToken.Event);
+}
+  }
+
+  if (HttpInstance->RxToken.CompletionToken.Event != NULL) {
+gBS->CloseEvent (HttpInstance->RxToken.CompletionToken.Event);
+HttpInstance->RxToken.CompletionToken.Event = NULL;
+  }
+
   FreePool (Wrap);
   return Status;
 
-- 
2.6.2.windows.1

___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel