Prepare for boost::url upgrade
The new boost URL now interops properly with std::string_view, which is
great, and cleans up a bunch of mediocre code to convert one to another.
It has also been pulled into boost-proper, so we no longer need a
boost-url dependency that's separate.
Unfortunately, boost url makes these improvements by changing
boost::string_view for boost::urls::const_string, which causes us to
have some compile errors on the missing type.
The bulk of these changes fall into a couple categories, and have to be
executed in one commit.
string() is replaced with buffer() on the url and url_view types
boost::string_view is replaced by std::string_view for many times, in
many cases removing a temporary that we had in the code previously.
Tested: Code compiles with boost 1.81.0 beta.
Redfish service validator passes.
Pretty good unit test coverage for URL-specific use cases.
Signed-off-by: Ed Tanous <edtanous@google.com>
Change-Id: I8d3dc89b53d1cc390887fe53605d4867f75f76fd
diff --git a/redfish-core/lib/metric_report.hpp b/redfish-core/lib/metric_report.hpp
index 33c8c9c..0fb3a68 100644
--- a/redfish-core/lib/metric_report.hpp
+++ b/redfish-core/lib/metric_report.hpp
@@ -42,16 +42,12 @@
const TimestampReadings& timestampReadings)
{
json["@odata.type"] = "#MetricReport.v1_3_0.MetricReport";
- json["@odata.id"] =
- crow::utility::urlFromPieces("redfish", "v1", "TelemetryService",
- "MetricReports", id)
- .string();
+ json["@odata.id"] = crow::utility::urlFromPieces(
+ "redfish", "v1", "TelemetryService", "MetricReports", id);
json["Id"] = id;
json["Name"] = id;
- json["MetricReportDefinition"]["@odata.id"] =
- crow::utility::urlFromPieces("redfish", "v1", "TelemetryService",
- "MetricReportDefinitions", id)
- .string();
+ json["MetricReportDefinition"]["@odata.id"] = crow::utility::urlFromPieces(
+ "redfish", "v1", "TelemetryService", "MetricReportDefinitions", id);
const auto& [timestamp, readings] = timestampReadings;
json["Timestamp"] = redfish::time_utils::getDateTimeUintMs(timestamp);
diff --git a/redfish-core/lib/metric_report_definition.hpp b/redfish-core/lib/metric_report_definition.hpp
index bc1b894..e6308eb 100644
--- a/redfish-core/lib/metric_report_definition.hpp
+++ b/redfish-core/lib/metric_report_definition.hpp
@@ -34,16 +34,13 @@
{
asyncResp->res.jsonValue["@odata.type"] =
"#MetricReportDefinition.v1_3_0.MetricReportDefinition";
- asyncResp->res.jsonValue["@odata.id"] =
- crow::utility::urlFromPieces("redfish", "v1", "TelemetryService",
- "MetricReportDefinitions", id)
- .string();
+ asyncResp->res.jsonValue["@odata.id"] = crow::utility::urlFromPieces(
+ "redfish", "v1", "TelemetryService", "MetricReportDefinitions", id);
asyncResp->res.jsonValue["Id"] = id;
asyncResp->res.jsonValue["Name"] = id;
asyncResp->res.jsonValue["MetricReport"]["@odata.id"] =
crow::utility::urlFromPieces("redfish", "v1", "TelemetryService",
- "MetricReports", id)
- .string();
+ "MetricReports", id);
asyncResp->res.jsonValue["Status"]["State"] = "Enabled";
asyncResp->res.jsonValue["ReportUpdates"] = "Overwrite";
diff --git a/redfish-core/lib/redfish_v1.hpp b/redfish-core/lib/redfish_v1.hpp
index fa3ca36..95db449 100644
--- a/redfish-core/lib/redfish_v1.hpp
+++ b/redfish-core/lib/redfish_v1.hpp
@@ -38,12 +38,11 @@
BMCWEB_LOG_ERROR << "404 on path " << path;
- boost::urls::string_value name = req.urlView.segments().back();
- std::string_view nameStr(name.data(), name.size());
+ std::string name = req.urlView.segments().back();
// Note, if we hit the wildcard route, we don't know the "type" the user was
// actually requesting, but giving them a return with an empty string is
// still better than nothing.
- messages::resourceNotFound(asyncResp->res, "", nameStr);
+ messages::resourceNotFound(asyncResp->res, "", name);
}
inline void redfish405(App& app, const crow::Request& req,
diff --git a/redfish-core/lib/virtual_media.hpp b/redfish-core/lib/virtual_media.hpp
index af38163..402cbbd 100644
--- a/redfish-core/lib/virtual_media.hpp
+++ b/redfish-core/lib/virtual_media.hpp
@@ -32,12 +32,12 @@
inline std::string getTransferProtocolTypeFromUri(const std::string& imageUri)
{
boost::urls::result<boost::urls::url_view> url =
- boost::urls::parse_uri(boost::string_view(imageUri));
+ boost::urls::parse_uri(imageUri);
if (!url)
{
return "None";
}
- boost::string_view scheme = url->scheme();
+ std::string_view scheme = url->scheme();
if (scheme == "smb")
{
return "CIFS";
@@ -294,7 +294,7 @@
inline std::optional<TransferProtocol>
getTransferProtocolFromUri(const boost::urls::url_view& imageUri)
{
- boost::string_view scheme = imageUri.scheme();
+ std::string_view scheme = imageUri.scheme();
if (scheme == "smb")
{
return TransferProtocol::smb;
@@ -401,7 +401,7 @@
return false;
}
boost::urls::result<boost::urls::url_view> url =
- boost::urls::parse_uri(boost::string_view(imageUrl));
+ boost::urls::parse_uri(imageUrl);
if (!url)
{
messages::actionParameterValueFormatError(res, imageUrl, "Image",