]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Include/Library/HttpLib.h
MdeModulePkg: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / MdeModulePkg / Include / Library / HttpLib.h
index cd97b644f1e9a975c3da58c62e519e42c0a958cb..93100eb350e5eeb925dfc8f41363b6658fe40767 100644 (file)
@@ -2,14 +2,9 @@
   This library is used to share code between UEFI network stack modules.\r
   It provides the helper routines to parse the HTTP message byte stream.\r
 \r
-Copyright (c) 2015 - 2016, 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<BR>\r
-http://opensource.org/licenses/bsd-license.php\r
-\r
-THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+Copyright (c) 2015 - 2018, Intel Corporation. All rights reserved.<BR>\r
+(C) Copyright 2016 Hewlett Packard Enterprise Development LP<BR>\r
+SPDX-License-Identifier: BSD-2-Clause-Patent\r
 \r
 **/\r
 \r
@@ -18,12 +13,13 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 \r
 #include <Protocol/Http.h>\r
 \r
+\r
 /**\r
   Decode a percent-encoded URI component to the ASCII character.\r
-  \r
-  Decode the input component in Buffer according to RFC 3986. The caller is responsible to make \r
+\r
+  Decode the input component in Buffer according to RFC 3986. The caller is responsible to make\r
   sure ResultBuffer points to a buffer with size equal or greater than ((AsciiStrSize (Buffer))\r
-  in bytes. \r
+  in bytes.\r
 \r
   @param[in]    Buffer           The pointer to a percent-encoded URI component.\r
   @param[in]    BufferLength     Length of Buffer in bytes.\r
@@ -32,7 +28,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 \r
   @retval EFI_SUCCESS            Successfully decoded the URI.\r
   @retval EFI_INVALID_PARAMETER  Buffer is not a valid percent-encoded string.\r
-  \r
+\r
 **/\r
 EFI_STATUS\r
 EFIAPI\r
@@ -59,7 +55,7 @@ UriPercentDecode (
   @retval EFI_SUCCESS              Successfully dereferenced the HTTP URL.\r
   @retval EFI_INVALID_PARAMETER    UrlParser is NULL or Url is not a valid HTTP URL.\r
   @retval EFI_OUT_OF_RESOURCES     Could not allocate needed resources.\r
-  \r
+\r
 **/\r
 EFI_STATUS\r
 EFIAPI\r
@@ -84,7 +80,7 @@ HttpParseUrl (
   @retval EFI_INVALID_PARAMETER    Uri is NULL or HostName is NULL or UrlParser is invalid.\r
   @retval EFI_NOT_FOUND            No hostName component in the URL.\r
   @retval EFI_OUT_OF_RESOURCES     Could not allocate needed resources.\r
-  \r
+\r
 **/\r
 EFI_STATUS\r
 EFIAPI\r
@@ -107,7 +103,7 @@ HttpUrlGetHostName (
   @retval EFI_INVALID_PARAMETER    Uri is NULL or Ip4Address is NULL or UrlParser is invalid.\r
   @retval EFI_NOT_FOUND            No IPv4 address component in the URL.\r
   @retval EFI_OUT_OF_RESOURCES     Could not allocate needed resources.\r
-  \r
+\r
 **/\r
 EFI_STATUS\r
 EFIAPI\r
@@ -130,7 +126,7 @@ HttpUrlGetIp4 (
   @retval EFI_INVALID_PARAMETER    Uri is NULL or Ip6Address is NULL or UrlParser is invalid.\r
   @retval EFI_NOT_FOUND            No IPv6 address component in the URL.\r
   @retval EFI_OUT_OF_RESOURCES     Could not allocate needed resources.\r
-  \r
+\r
 **/\r
 EFI_STATUS\r
 EFIAPI\r
@@ -153,7 +149,7 @@ HttpUrlGetIp6 (
   @retval EFI_INVALID_PARAMETER    Uri is NULL or Port is NULL or UrlParser is invalid.\r
   @retval EFI_NOT_FOUND            No port number in the URL.\r
   @retval EFI_OUT_OF_RESOURCES     Could not allocate needed resources.\r
-  \r
+\r
 **/\r
 EFI_STATUS\r
 EFIAPI\r
@@ -177,7 +173,7 @@ HttpUrlGetPort (
   @retval EFI_INVALID_PARAMETER    Uri is NULL or HostName is NULL or UrlParser is invalid.\r
   @retval EFI_NOT_FOUND            No hostName component in the URL.\r
   @retval EFI_OUT_OF_RESOURCES     Could not allocate needed resources.\r
-  \r
+\r
 **/\r
 EFI_STATUS\r
 EFIAPI\r
@@ -191,7 +187,7 @@ HttpUrlGetPath (
   Release the resource of the URL parser.\r
 \r
   @param[in]    UrlParser            Pointer to the parser.\r
-  \r
+\r
 **/\r
 VOID\r
 EFIAPI\r
@@ -229,7 +225,7 @@ typedef enum {
 \r
   @retval EFI_SUCCESS              Continue to parser the message body.\r
   @retval Others                   Abort the parse.\r
\r
+\r
 **/\r
 typedef\r
 EFI_STATUS\r
@@ -284,7 +280,8 @@ HttpInitMsgParser (
 \r
   @retval EFI_SUCCESS                Successfully parse the message-body.\r
   @retval EFI_INVALID_PARAMETER      MsgParser is NULL or Body is NULL or BodyLength is 0.\r
-  @retval Others                     Operation aborted.\r
+  @retval EFI_ABORTED                Operation aborted.\r
+  @retval Other                      Error happened while parsing message body.\r
 \r
 **/\r
 EFI_STATUS\r
@@ -321,7 +318,7 @@ HttpIsMessageComplete (
   @retval EFI_SUCCESS                Successfully to get the entity length.\r
   @retval EFI_NOT_READY              Entity length is not valid yet.\r
   @retval EFI_INVALID_PARAMETER      MsgParser is NULL or ContentLength is NULL.\r
-  \r
+\r
 **/\r
 EFI_STATUS\r
 EFIAPI\r
@@ -334,7 +331,7 @@ HttpGetEntityLength (
   Release the resource of the message parser.\r
 \r
   @param[in]    MsgParser            Pointer to the message parser.\r
-  \r
+\r
 **/\r
 VOID\r
 EFIAPI\r
@@ -343,5 +340,142 @@ HttpFreeMsgParser (
   );\r
 \r
 \r
+/**\r
+  Find a specified header field according to the field name.\r
+\r
+  @param[in]   HeaderCount      Number of HTTP header structures in Headers list.\r
+  @param[in]   Headers          Array containing list of HTTP headers.\r
+  @param[in]   FieldName        Null terminated string which describes a field name.\r
+\r
+  @return    Pointer to the found header or NULL.\r
+\r
+**/\r
+EFI_HTTP_HEADER *\r
+EFIAPI\r
+HttpFindHeader (\r
+  IN  UINTN                HeaderCount,\r
+  IN  EFI_HTTP_HEADER      *Headers,\r
+  IN  CHAR8                *FieldName\r
+  );\r
+\r
+/**\r
+  Set FieldName and FieldValue into specified HttpHeader.\r
+\r
+  @param[in,out]  HttpHeader          Specified HttpHeader.\r
+  @param[in]      FieldName           FieldName of this HttpHeader, a NULL terminated ASCII string.\r
+  @param[in]      FieldValue          FieldValue of this HttpHeader, a NULL terminated ASCII string.\r
+\r
+\r
+  @retval EFI_SUCCESS             The FieldName and FieldValue are set into HttpHeader successfully.\r
+  @retval EFI_INVALID_PARAMETER   The parameter is invalid.\r
+  @retval EFI_OUT_OF_RESOURCES    Failed to allocate resources.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+HttpSetFieldNameAndValue (\r
+   IN  OUT   EFI_HTTP_HEADER       *HttpHeader,\r
+   IN  CONST CHAR8                 *FieldName,\r
+   IN  CONST CHAR8                 *FieldValue\r
+  );\r
+\r
+/**\r
+  Get one key/value header pair from the raw string.\r
+\r
+  @param[in]  String             Pointer to the raw string.\r
+  @param[out] FieldName          Points directly to field name within 'HttpHeader'.\r
+  @param[out] FieldValue         Points directly to field value within 'HttpHeader'.\r
+\r
+  @return     Pointer to the next raw string.\r
+  @return     NULL if no key/value header pair from this raw string.\r
+\r
+**/\r
+CHAR8 *\r
+EFIAPI\r
+HttpGetFieldNameAndValue (\r
+  IN     CHAR8   *String,\r
+     OUT CHAR8   **FieldName,\r
+     OUT CHAR8   **FieldValue\r
+  );\r
+\r
+/**\r
+  Free existing HeaderFields.\r
+\r
+  @param[in]  HeaderFields       Pointer to array of key/value header pairs waiting for free.\r
+  @param[in]  FieldCount         The number of header pairs in HeaderFields.\r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+HttpFreeHeaderFields (\r
+  IN  EFI_HTTP_HEADER  *HeaderFields,\r
+  IN  UINTN            FieldCount\r
+  );\r
+\r
+/**\r
+  Generate HTTP request message.\r
+\r
+  This function will allocate memory for the whole HTTP message and generate a\r
+  well formatted HTTP Request message in it, include the Request-Line, header\r
+  fields and also the message body. It is the caller's responsibility to free\r
+  the buffer returned in *RequestMsg.\r
+\r
+  @param[in]   Message            Pointer to the EFI_HTTP_MESSAGE structure which\r
+                                  contains the required information to generate\r
+                                  the HTTP request message.\r
+  @param[in]   Url                The URL of a remote host.\r
+  @param[out]  RequestMsg         Pointer to the created HTTP request message.\r
+                                  NULL if any error occured.\r
+  @param[out]  RequestMsgSize     Size of the RequestMsg (in bytes).\r
+\r
+  @retval EFI_SUCCESS             If HTTP request string was created successfully.\r
+  @retval EFI_OUT_OF_RESOURCES    Failed to allocate resources.\r
+  @retval EFI_INVALID_PARAMETER   The input arguments are invalid.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+HttpGenRequestMessage (\r
+  IN     CONST EFI_HTTP_MESSAGE        *Message,\r
+  IN     CONST CHAR8                   *Url,\r
+     OUT CHAR8                         **RequestMsg,\r
+     OUT UINTN                         *RequestMsgSize\r
+  );\r
+\r
+/**\r
+  Translate the status code in HTTP message to EFI_HTTP_STATUS_CODE defined\r
+  in UEFI 2.5 specification.\r
+\r
+  @param[in]  StatusCode         The status code value in HTTP message.\r
+\r
+  @return                        Value defined in EFI_HTTP_STATUS_CODE .\r
+\r
+**/\r
+EFI_HTTP_STATUS_CODE\r
+EFIAPI\r
+HttpMappingToStatusCode (\r
+  IN UINTN                  StatusCode\r
+  );\r
+\r
+/**\r
+  Check whether header field called FieldName is in DeleteList.\r
+\r
+  @param[in]  DeleteList        Pointer to array of key/value header pairs.\r
+  @param[in]  DeleteCount       The number of header pairs.\r
+  @param[in]  FieldName         Pointer to header field's name.\r
+\r
+  @return     TRUE if FieldName is not in DeleteList, that means this header field is valid.\r
+  @return     FALSE if FieldName is in DeleteList, that means this header field is invalid.\r
+\r
+**/\r
+BOOLEAN\r
+EFIAPI\r
+HttpIsValidHttpHeader (\r
+  IN  CHAR8            *DeleteList[],\r
+  IN  UINTN            DeleteCount,\r
+  IN  CHAR8            *FieldName\r
+  );\r
+\r
+\r
 #endif\r
 \r