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/include/event_service_manager.hpp b/redfish-core/include/event_service_manager.hpp
index 7f3b43a..6f1e91b 100644
--- a/redfish-core/include/event_service_manager.hpp
+++ b/redfish-core/include/event_service_manager.hpp
@@ -519,7 +519,7 @@
{
if (std::find(metricReportDefinitions.begin(),
metricReportDefinitions.end(),
- mrdUri.string()) == metricReportDefinitions.end())
+ mrdUri.buffer()) == metricReportDefinitions.end())
{
return;
}
diff --git a/redfish-core/include/redfish_aggregator.hpp b/redfish-core/include/redfish_aggregator.hpp
index 99da8ee..8170b64 100644
--- a/redfish-core/include/redfish_aggregator.hpp
+++ b/redfish-core/include/redfish_aggregator.hpp
@@ -312,7 +312,7 @@
BMCWEB_LOG_ERROR << "Port value out of range";
return;
}
- url.set_port(static_cast<uint16_t>(*propVal));
+ url.set_port(std::to_string(static_cast<uint16_t>(*propVal)));
}
else if (prop.first == "AuthType")
@@ -435,8 +435,7 @@
}
// We didn't recognize the prefix and need to return a 404
- boost::urls::string_value name = req.urlView.segments().back();
- std::string_view nameStr(name.data(), name.size());
+ std::string_view nameStr = req.urlView.segments().back();
messages::resourceNotFound(asyncResp->res, "", nameStr);
}
@@ -461,9 +460,7 @@
// don't need to write an error code
if (isCollection == AggregationType::Resource)
{
- boost::urls::string_value name =
- sharedReq->urlView.segments().back();
- std::string_view nameStr(name.data(), name.size());
+ std::string_view nameStr = sharedReq->urlView.segments().back();
messages::resourceNotFound(asyncResp->res, "", nameStr);
}
return;
diff --git a/redfish-core/include/utils/collection.hpp b/redfish-core/include/utils/collection.hpp
index 97f622d..f117302 100644
--- a/redfish-core/include/utils/collection.hpp
+++ b/redfish-core/include/utils/collection.hpp
@@ -29,7 +29,7 @@
const char* subtree = "/xyz/openbmc_project/inventory")
{
BMCWEB_LOG_DEBUG << "Get collection members for: "
- << collectionPath.string();
+ << collectionPath.buffer();
crow::connections::systemBus->async_method_call(
[collectionPath, aResp{std::move(aResp)}](
const boost::system::error_code ec,
diff --git a/redfish-core/include/utils/query_param.hpp b/redfish-core/include/utils/query_param.hpp
index fec5384..bfe1001 100644
--- a/redfish-core/include/utils/query_param.hpp
+++ b/redfish-core/include/utils/query_param.hpp
@@ -16,7 +16,6 @@
#include <boost/beast/http/status.hpp>
#include <boost/beast/http/verb.hpp>
#include <boost/url/params_view.hpp>
-#include <boost/url/string.hpp>
#include <nlohmann/json.hpp>
#include <algorithm>
@@ -374,80 +373,78 @@
return true;
}
-inline std::optional<Query>
- parseParameters(const boost::urls::params_view& urlParams,
- crow::Response& res)
+inline std::optional<Query> parseParameters(boost::urls::params_view urlParams,
+ crow::Response& res)
{
Query ret;
for (const boost::urls::params_view::value_type& it : urlParams)
{
- std::string_view key(it.key.data(), it.key.size());
- std::string_view value(it.value.data(), it.value.size());
- if (key == "only")
+ if (it.key == "only")
{
if (!it.value.empty())
{
- messages::queryParameterValueFormatError(res, value, key);
+ messages::queryParameterValueFormatError(res, it.value, it.key);
return std::nullopt;
}
ret.isOnly = true;
}
- else if (key == "$expand" && bmcwebInsecureEnableQueryParams)
+ else if (it.key == "$expand" && bmcwebInsecureEnableQueryParams)
{
- if (!getExpandType(value, ret))
+ if (!getExpandType(it.value, ret))
{
- messages::queryParameterValueFormatError(res, value, key);
+ messages::queryParameterValueFormatError(res, it.value, it.key);
return std::nullopt;
}
}
- else if (key == "$top")
+ else if (it.key == "$top")
{
- QueryError topRet = getTopParam(value, ret);
+ QueryError topRet = getTopParam(it.value, ret);
if (topRet == QueryError::ValueFormat)
{
- messages::queryParameterValueFormatError(res, value, key);
+ messages::queryParameterValueFormatError(res, it.value, it.key);
return std::nullopt;
}
if (topRet == QueryError::OutOfRange)
{
messages::queryParameterOutOfRange(
- res, value, "$top", "0-" + std::to_string(Query::maxTop));
+ res, it.value, "$top",
+ "0-" + std::to_string(Query::maxTop));
return std::nullopt;
}
}
- else if (key == "$skip")
+ else if (it.key == "$skip")
{
- QueryError topRet = getSkipParam(value, ret);
+ QueryError topRet = getSkipParam(it.value, ret);
if (topRet == QueryError::ValueFormat)
{
- messages::queryParameterValueFormatError(res, value, key);
+ messages::queryParameterValueFormatError(res, it.value, it.key);
return std::nullopt;
}
if (topRet == QueryError::OutOfRange)
{
messages::queryParameterOutOfRange(
- res, value, key,
+ res, it.value, it.key,
"0-" + std::to_string(std::numeric_limits<size_t>::max()));
return std::nullopt;
}
}
- else if (key == "$select")
+ else if (it.key == "$select")
{
- if (!getSelectParam(value, ret))
+ if (!getSelectParam(it.value, ret))
{
- messages::queryParameterValueFormatError(res, value, key);
+ messages::queryParameterValueFormatError(res, it.value, it.key);
return std::nullopt;
}
}
else
{
// Intentionally ignore other errors Redfish spec, 7.3.1
- if (key.starts_with("$"))
+ if (it.key.starts_with("$"))
{
// Services shall return... The HTTP 501 Not Implemented
// status code for any unsupported query parameters that
// start with $ .
- messages::queryParameterValueFormatError(res, value, key);
+ messages::queryParameterValueFormatError(res, it.value, it.key);
res.result(boost::beast::http::status::not_implemented);
return std::nullopt;
}
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",
diff --git a/redfish-core/src/error_messages.cpp b/redfish-core/src/error_messages.cpp
index 5f055bf..bee3140 100644
--- a/redfish-core/src/error_messages.cpp
+++ b/redfish-core/src/error_messages.cpp
@@ -206,8 +206,7 @@
*/
nlohmann::json resourceMissingAtURI(const boost::urls::url_view& arg1)
{
- std::array<std::string_view, 1> args{
- std::string_view{arg1.data(), arg1.size()}};
+ std::array<std::string_view, 1> args{arg1.buffer()};
return getLog(redfish::registries::base::Index::resourceMissingAtURI, args);
}
@@ -293,9 +292,8 @@
nlohmann::json resourceAtUriUnauthorized(const boost::urls::url_view& arg1,
std::string_view arg2)
{
- return getLog(
- redfish::registries::base::Index::resourceAtUriUnauthorized,
- std::to_array({std::string_view{arg1.data(), arg1.size()}, arg2}));
+ return getLog(redfish::registries::base::Index::resourceAtUriUnauthorized,
+ std::to_array<std::string_view>({arg1.buffer(), arg2}));
}
void resourceAtUriUnauthorized(crow::Response& res,
@@ -524,10 +522,9 @@
*/
nlohmann::json resourceAtUriInUnknownFormat(const boost::urls::url_view& arg1)
{
- std::string_view arg1str{arg1.data(), arg1.size()};
return getLog(
redfish::registries::base::Index::resourceAtUriInUnknownFormat,
- std::to_array({arg1str}));
+ std::to_array<std::string_view>({arg1.buffer()}));
}
void resourceAtUriInUnknownFormat(crow::Response& res,
@@ -701,9 +698,8 @@
nlohmann::json resetRequired(const boost::urls::url_view& arg1,
std::string_view arg2)
{
- std::string_view arg1str(arg1.data(), arg1.size());
return getLog(redfish::registries::base::Index::resetRequired,
- std::to_array({arg1str, arg2}));
+ std::to_array<std::string_view>({arg1.buffer(), arg2}));
}
void resetRequired(crow::Response& res, const boost::urls::url_view& arg1,
@@ -786,8 +782,7 @@
{
return getLog(
redfish::registries::base::Index::propertyValueResourceConflict,
- std::to_array(
- {arg1, arg2, std::string_view{arg3.data(), arg3.size()}}));
+ std::to_array<std::string_view>({arg1, arg2, arg3.buffer()}));
}
void propertyValueResourceConflict(crow::Response& res, std::string_view arg1,
@@ -852,9 +847,8 @@
*/
nlohmann::json resourceCreationConflict(const boost::urls::url_view& arg1)
{
- std::string_view arg1str(arg1.data(), arg1.size());
return getLog(redfish::registries::base::Index::resourceCreationConflict,
- std::to_array({arg1str}));
+ std::to_array<std::string_view>({arg1.buffer()}));
}
void resourceCreationConflict(crow::Response& res,
@@ -1005,9 +999,8 @@
*/
nlohmann::json couldNotEstablishConnection(const boost::urls::url_view& arg1)
{
- std::string_view arg1str(arg1.data(), arg1.size());
return getLog(redfish::registries::base::Index::couldNotEstablishConnection,
- std::to_array({arg1str}));
+ std::to_array<std::string_view>({arg1.buffer()}));
}
void couldNotEstablishConnection(crow::Response& res,
@@ -1131,10 +1124,9 @@
nlohmann::json sourceDoesNotSupportProtocol(const boost::urls::url_view& arg1,
std::string_view arg2)
{
- std::string_view arg1str(arg1.data(), arg1.size());
return getLog(
redfish::registries::base::Index::sourceDoesNotSupportProtocol,
- std::to_array({arg1str, arg2}));
+ std::to_array<std::string_view>({arg1.buffer(), arg2}));
}
void sourceDoesNotSupportProtocol(crow::Response& res,
@@ -1192,9 +1184,8 @@
*/
nlohmann::json accessDenied(const boost::urls::url_view& arg1)
{
- std::string_view arg1str(arg1.data(), arg1.size());
return getLog(redfish::registries::base::Index::accessDenied,
- std::to_array({arg1str}));
+ std::to_array<std::string_view>({arg1.buffer()}));
}
void accessDenied(crow::Response& res, const boost::urls::url_view& arg1)
@@ -1360,9 +1351,8 @@
*/
nlohmann::json invalidObject(const boost::urls::url_view& arg1)
{
- std::string_view arg1str(arg1.data(), arg1.size());
return getLog(redfish::registries::base::Index::invalidObject,
- std::to_array({arg1str}));
+ std::to_array<std::string_view>({arg1.buffer()}));
}
void invalidObject(crow::Response& res, const boost::urls::url_view& arg1)
@@ -1707,9 +1697,8 @@
nlohmann::json passwordChangeRequired(const boost::urls::url_view& arg1)
{
- std::string_view arg1str(arg1.data(), arg1.size());
return getLog(redfish::registries::base::Index::passwordChangeRequired,
- std::to_array({arg1str}));
+ std::to_array<std::string_view>({arg1.buffer()}));
}
/**