public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Nickle Wang via groups.io" <nicklew=nvidia.com@groups.io>
To: <devel@edk2.groups.io>
Cc: Abner Chang <abner.chang@amd.com>,
	Igor Kulchytskyy <igork@ami.com>,
	"Nick Ramirez" <nramirez@nvidia.com>
Subject: [edk2-devel] [edk2-redfish-client][PATCH 09/10] RedfishClientPkg/RedfishVersionLib: use HTTP cache lib
Date: Wed, 3 Jan 2024 20:01:11 +0800	[thread overview]
Message-ID: <20240103120111.62336-1-nicklew@nvidia.com> (raw)

Use Redfish Http cache library to query Redfish service.

Signed-off-by: Nickle Wang <nicklew@nvidia.com>
Cc: Abner Chang <abner.chang@amd.com>
Cc: Igor Kulchytskyy <igork@ami.com>
Cc: Nick Ramirez <nramirez@nvidia.com>
---
 .../RedfishVersionLib/RedfishVersionLib.inf   |  3 ++
 .../RedfishVersionLib/RedfishVersionLib.c     | 30 ++++++++++++++-----
 2 files changed, 25 insertions(+), 8 deletions(-)

diff --git a/RedfishClientPkg/Library/RedfishVersionLib/RedfishVersionLib.inf b/RedfishClientPkg/Library/RedfishVersionLib/RedfishVersionLib.inf
index 34d13d64..10e335af 100644
--- a/RedfishClientPkg/Library/RedfishVersionLib/RedfishVersionLib.inf
+++ b/RedfishClientPkg/Library/RedfishVersionLib/RedfishVersionLib.inf
@@ -1,6 +1,7 @@
 ## @file
 #
 #  (C) Copyright 2022 Hewlett Packard Enterprise Development LP<BR>
+#  Copyright (c) 2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
 #
 #  SPDX-License-Identifier: BSD-2-Clause-Patent
 #
@@ -31,11 +32,13 @@
 
 [LibraryClasses]
   BaseLib
+  BaseMemoryLib
   DebugLib
   MemoryAllocationLib
   PcdLib
   RedfishLib
   JsonLib
+  RedfishHttpCacheLib
 
 [Protocols]
 
diff --git a/RedfishClientPkg/Library/RedfishVersionLib/RedfishVersionLib.c b/RedfishClientPkg/Library/RedfishVersionLib/RedfishVersionLib.c
index bcaca3c7..9a31c6a9 100644
--- a/RedfishClientPkg/Library/RedfishVersionLib/RedfishVersionLib.c
+++ b/RedfishClientPkg/Library/RedfishVersionLib/RedfishVersionLib.c
@@ -2,6 +2,7 @@
   Redfish version library implementation
 
   (C) Copyright 2022 Hewlett Packard Enterprise Development LP<BR>
+  Copyright (c) 2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
 
   SPDX-License-Identifier: BSD-2-Clause-Patent
 
@@ -10,15 +11,17 @@
 #include <Uefi.h>
 #include <RedfishBase.h>
 #include <Library/BaseLib.h>
+#include <Library/BaseMemoryLib.h>
 #include <Library/DebugLib.h>
 #include <Library/PcdLib.h>
 #include <Library/RedfishLib.h>
 #include <Library/JsonLib.h>
 #include <Library/MemoryAllocationLib.h>
 #include <Library/RedfishVersionLib.h>
+#include <Library/RedfishHttpCacheLib.h>
 
 #define REDFISH_VERSION_DEFAULT_STRING  L"v1"
-#define REDFISH_ROOT_URI                "/redfish"
+#define REDFISH_ROOT_URI                L"/redfish"
 
 REDFISH_SERVICE  *mCacheService;
 EFI_STRING       mVersionCache;
@@ -26,7 +29,7 @@ UINTN            mVersionStringSize;
 
 /**
   Cache the redfish service version for later use so we don't have to query
-  HTTP request everytime.
+  HTTP request every time.
 
   @param[in]   Service  Redfish service instance
   @param[in]   Version  Version string to cache
@@ -66,7 +69,7 @@ CacheVersion (
 
 /**
   Query HTTP request to BMC with given redfish service and return redfish
-  version information. If there is troulbe to get Redfish version on BMC,
+  version information. If there is trouble to get Redfish version on BMC,
   The value of PcdDefaultRedfishVersion is returned.
 
   It's call responsibility to release returned buffer.
@@ -90,6 +93,7 @@ RedfishGetVersion (
   EDKII_JSON_VALUE  Value;
 
   VersionString = NULL;
+  ZeroMem (&Response, sizeof (REDFISH_RESPONSE));
 
   if (Service == NULL) {
     goto ON_ERROR;
@@ -105,13 +109,14 @@ RedfishGetVersion (
   //
   // Get resource from redfish service.
   //
-  Status = RedfishGetByUri (
+  Status = RedfishHttpGetResource (
              Service,
              REDFISH_ROOT_URI,
-             &Response
+             &Response,
+             TRUE
              );
   if (EFI_ERROR (Status)) {
-    DEBUG ((DEBUG_ERROR, "%a, RedfishGetByService to %a failed: %r\n", __func__, REDFISH_ROOT_URI, Status));
+    DEBUG ((DEBUG_ERROR, "%a, RedfishGetByService to %s failed: %r\n", __func__, REDFISH_ROOT_URI, Status));
     if (Response.Payload != NULL) {
       RedfishDumpPayload (Response.Payload);
       RedfishFreeResponse (
@@ -151,18 +156,27 @@ ON_ERROR:
     VersionString = REDFISH_VERSION_DEFAULT_STRING;
   }
 
+  if (Response.Payload != NULL) {
+    RedfishFreeResponse (
+      Response.StatusCode,
+      Response.HeaderCount,
+      Response.Headers,
+      Response.Payload
+      );
+  }
+
   DEBUG ((DEBUG_MANAGEABILITY, "%a: Redfish version - %s\n", __func__, VersionString));
   return AllocateCopyPool (StrSize (VersionString), VersionString);
 }
 
 /**
 
-  Initial redfish version library instace.
+  Initial redfish version library instate.
 
   @param[in] ImageHandle     The image handle.
   @param[in] SystemTable     The system table.
 
-  @retval  EFI_SUCEESS  Install Boot manager menu success.
+  @retval  EFI_SUCCESS  Install Boot manager menu success.
   @retval  Other        Return error status.
 
 **/
-- 
2.34.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#113079): https://edk2.groups.io/g/devel/message/113079
Mute This Topic: https://groups.io/mt/103500391/7686176
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io]
-=-=-=-=-=-=-=-=-=-=-=-



                 reply	other threads:[~2024-01-03 12:01 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240103120111.62336-1-nicklew@nvidia.com \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox