summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEd Tanous <edtanous@google.com>2023-03-07 02:04:25 +0300
committerEd Tanous <ed@tanous.net>2023-03-15 18:52:56 +0300
commitd9f466b3b92f242343dcdecae83b40579f92c506 (patch)
treee59b36731a8b3f26dcdab50b0e889d217a849114
parent6ce82fabeba1f2549b98c3ad2f8542c6879682c8 (diff)
downloadbmcweb-d9f466b3b92f242343dcdecae83b40579f92c506.tar.xz
Take url views by value
Any of our things taking URLs should be taking url_view by value, similar to how we take string_view. From the beast documentation: "...it acts like a string_view in terms of ownership." [1] Therefore, we should treat it like we treat string_view, and take by value, not reference. [1] https://www.boost.org/doc/libs/master/libs/url/doc/html/url/ref/boost__urls__url_view.html Tested: Stacked these patches. Redfish service validator passes. Signed-off-by: Ed Tanous <edtanous@google.com> Change-Id: I696b495f4aa04984225853f653cc175c0eaad79d
-rw-r--r--.clang-tidy1
-rw-r--r--http/utility.hpp16
-rw-r--r--redfish-core/include/error_messages.hpp49
-rw-r--r--redfish-core/lib/virtual_media.hpp2
-rw-r--r--redfish-core/src/error_messages.cpp49
5 files changed, 54 insertions, 63 deletions
diff --git a/.clang-tidy b/.clang-tidy
index bad6111fcb..4e09243ee4 100644
--- a/.clang-tidy
+++ b/.clang-tidy
@@ -316,3 +316,4 @@ CheckOptions:
- { key: readability-identifier-naming.NamespaceCase, value: lower_case }
- { key: readability-identifier-naming.StructCase, value: CamelCase }
- { key: cppcoreguidelines-macro-usage.AllowedRegexp, value: DEBUG*|NLOHMANN_JSON_SERIALIZE_ENUM }
+ - { key: performance-unnecessary-value-param.AllowedTypes, value: ((segments_view)|(url_view)) }
diff --git a/http/utility.hpp b/http/utility.hpp
index 4e6ed71675..fd01bf1624 100644
--- a/http/utility.hpp
+++ b/http/utility.hpp
@@ -643,10 +643,10 @@ class UrlSegmentMatcherVisitor
std::string_view segment;
};
-inline bool readUrlSegments(const boost::urls::url_view& url,
+inline bool readUrlSegments(boost::urls::url_view url,
std::initializer_list<UrlSegment>&& segments)
{
- const boost::urls::segments_view& urlSegments = url.segments();
+ boost::urls::segments_view urlSegments = url.segments();
if (!urlSegments.is_absolute())
{
@@ -687,16 +687,16 @@ inline bool readUrlSegments(const boost::urls::url_view& url,
} // namespace details
template <typename... Args>
-inline bool readUrlSegments(const boost::urls::url_view& url, Args&&... args)
+inline bool readUrlSegments(boost::urls::url_view url, Args&&... args)
{
return details::readUrlSegments(url, {std::forward<Args>(args)...});
}
-inline boost::urls::url replaceUrlSegment(const boost::urls::url_view& urlView,
+inline boost::urls::url replaceUrlSegment(boost::urls::url_view urlView,
const uint replaceLoc,
std::string_view newSegment)
{
- const boost::urls::segments_view& urlSegments = urlView.segments();
+ boost::urls::segments_view urlSegments = urlView.segments();
boost::urls::url url("/");
if (!urlSegments.is_absolute())
@@ -722,7 +722,7 @@ inline boost::urls::url replaceUrlSegment(const boost::urls::url_view& urlView,
return url;
}
-inline std::string setProtocolDefaults(const boost::urls::url_view& urlView)
+inline std::string setProtocolDefaults(boost::urls::url_view urlView)
{
if (urlView.scheme() == "https")
{
@@ -739,7 +739,7 @@ inline std::string setProtocolDefaults(const boost::urls::url_view& urlView)
return "";
}
-inline uint16_t setPortDefaults(const boost::urls::url_view& url)
+inline uint16_t setPortDefaults(boost::urls::url_view url)
{
uint16_t port = url.port_number();
if (port != 0)
@@ -821,7 +821,7 @@ template <>
struct adl_serializer<boost::urls::url_view>
{
// NOLINTNEXTLINE(readability-identifier-naming)
- static void to_json(json& j, const boost::urls::url_view& url)
+ static void to_json(json& j, boost::urls::url_view url)
{
j = url.buffer();
}
diff --git a/redfish-core/include/error_messages.hpp b/redfish-core/include/error_messages.hpp
index 08e8a3b531..e45ea45701 100644
--- a/redfish-core/include/error_messages.hpp
+++ b/redfish-core/include/error_messages.hpp
@@ -71,10 +71,9 @@ void malformedJSON(crow::Response& res);
* @param[in] arg1 Parameter of message that will replace %1 in its body.
*
* @returns Message ResourceMissingAtURI formatted to JSON */
-nlohmann::json resourceMissingAtURI(const boost::urls::url_view& arg1);
+nlohmann::json resourceMissingAtURI(boost::urls::url_view arg1);
-void resourceMissingAtURI(crow::Response& res,
- const boost::urls::url_view& arg1);
+void resourceMissingAtURI(crow::Response& res, boost::urls::url_view arg1);
/**
* @brief Formats ActionParameterValueFormatError message into JSON
@@ -144,11 +143,10 @@ void unrecognizedRequestBody(crow::Response& res);
* @param[in] arg2 Parameter of message that will replace %2 in its body.
*
* @returns Message ResourceAtUriUnauthorized formatted to JSON */
-nlohmann::json resourceAtUriUnauthorized(const boost::urls::url_view& arg1,
+nlohmann::json resourceAtUriUnauthorized(boost::urls::url_view arg1,
std::string_view arg2);
-void resourceAtUriUnauthorized(crow::Response& res,
- const boost::urls::url_view& arg1,
+void resourceAtUriUnauthorized(crow::Response& res, boost::urls::url_view arg1,
std::string_view arg2);
/**
@@ -294,10 +292,10 @@ void propertyValueOutOfRange(crow::Response& res, std::string_view arg1,
* @param[in] arg1 Parameter of message that will replace %1 in its body.
*
* @returns Message ResourceAtUriInUnknownFormat formatted to JSON */
-nlohmann::json resourceAtUriInUnknownFormat(const boost::urls::url_view& arg1);
+nlohmann::json resourceAtUriInUnknownFormat(boost::urls::url_view arg1);
void resourceAtUriInUnknownFormat(crow::Response& res,
- const boost::urls::url_view& arg1);
+ boost::urls::url_view arg1);
/**
* @brief Formats ServiceDisabled message into JSON
@@ -404,10 +402,9 @@ void resourceTypeIncompatible(crow::Response& res, std::string_view arg1,
* @param[in] arg2 Parameter of message that will replace %2 in its body.
*
* @returns Message ResetRequired formatted to JSON */
-nlohmann::json resetRequired(const boost::urls::url_view& arg1,
- std::string_view arg2);
+nlohmann::json resetRequired(boost::urls::url_view arg1, std::string_view arg2);
-void resetRequired(crow::Response& res, const boost::urls::url_view& arg1,
+void resetRequired(crow::Response& res, boost::urls::url_view arg1,
std::string_view arg2);
/**
@@ -462,11 +459,11 @@ void propertyValueConflict(crow::Response& res, std::string_view arg1,
* @returns Message PropertyValueResourceConflict to JSON */
nlohmann::json propertyValueResourceConflict(std::string_view arg1,
std::string_view arg2,
- const boost::urls::url_view& arg3);
+ boost::urls::url_view arg3);
void propertyValueResourceConflict(crow::Response& res, std::string_view arg1,
std::string_view arg2,
- const boost::urls::url_view& arg3);
+ boost::urls::url_view arg3);
/**
* @brief Formats PropertyValueExternalConflict message into JSON
@@ -508,10 +505,9 @@ void propertyValueIncorrect(crow::Response& res, std::string_view arg1,
* @param[in] arg1 Parameter of message that will replace %1 in its body.
*
* @returns Message ResourceCreationConflict formatted to JSON */
-nlohmann::json resourceCreationConflict(const boost::urls::url_view& arg1);
+nlohmann::json resourceCreationConflict(boost::urls::url_view arg1);
-void resourceCreationConflict(crow::Response& res,
- const boost::urls::url_view& arg1);
+void resourceCreationConflict(crow::Response& res, boost::urls::url_view arg1);
/**
* @brief Formats MaximumErrorsExceeded message into JSON
@@ -604,10 +600,10 @@ void resourceNotFound(crow::Response& res, std::string_view arg1,
* @param[in] arg1 Parameter of message that will replace %1 in its body.
*
* @returns Message CouldNotEstablishConnection formatted to JSON */
-nlohmann::json couldNotEstablishConnection(const boost::urls::url_view& arg1);
+nlohmann::json couldNotEstablishConnection(boost::urls::url_view arg1);
void couldNotEstablishConnection(crow::Response& res,
- const boost::urls::url_view& arg1);
+ boost::urls::url_view arg1);
/**
* @brief Formats PropertyNotWritable message into JSON
@@ -686,11 +682,11 @@ void actionParameterNotSupported(crow::Response& res, std::string_view arg1,
* @param[in] arg2 Parameter of message that will replace %2 in its body.
*
* @returns Message SourceDoesNotSupportProtocol formatted to JSON */
-nlohmann::json sourceDoesNotSupportProtocol(const boost::urls::url_view& arg1,
+nlohmann::json sourceDoesNotSupportProtocol(boost::urls::url_view arg1,
std::string_view arg2);
void sourceDoesNotSupportProtocol(crow::Response& res,
- const boost::urls::url_view& arg1,
+ boost::urls::url_view arg1,
std::string_view arg2);
/**
@@ -722,9 +718,9 @@ void accountRemoved(crow::Response& res);
* @param[in] arg1 Parameter of message that will replace %1 in its body.
*
* @returns Message AccessDenied formatted to JSON */
-nlohmann::json accessDenied(const boost::urls::url_view& arg1);
+nlohmann::json accessDenied(boost::urls::url_view arg1);
-void accessDenied(crow::Response& res, const boost::urls::url_view& arg1);
+void accessDenied(crow::Response& res, boost::urls::url_view arg1);
/**
* @brief Formats QueryNotSupported message into JSON
@@ -819,9 +815,9 @@ void noValidSession(crow::Response& res);
* @param[in] arg1 Parameter of message that will replace %1 in its body.
*
* @returns Message InvalidObject formatted to JSON */
-nlohmann::json invalidObject(const boost::urls::url_view& arg1);
+nlohmann::json invalidObject(boost::urls::url_view arg1);
-void invalidObject(crow::Response& res, const boost::urls::url_view& arg1);
+void invalidObject(crow::Response& res, boost::urls::url_view arg1);
/**
* @brief Formats ResourceInStandby message into JSON
@@ -1041,10 +1037,9 @@ void queryParameterOutOfRange(crow::Response& res, std::string_view arg1,
*
* @returns Message PasswordChangeRequired formatted to JSON */
-nlohmann::json passwordChangeRequired(const boost::urls::url_view& arg1);
+nlohmann::json passwordChangeRequired(boost::urls::url_view arg1);
-void passwordChangeRequired(crow::Response& res,
- const boost::urls::url_view& arg1);
+void passwordChangeRequired(crow::Response& res, boost::urls::url_view arg1);
/**
* @brief Formats InvalidUpload message into JSON
diff --git a/redfish-core/lib/virtual_media.hpp b/redfish-core/lib/virtual_media.hpp
index 73a9855aa8..88bdb215b2 100644
--- a/redfish-core/lib/virtual_media.hpp
+++ b/redfish-core/lib/virtual_media.hpp
@@ -362,7 +362,7 @@ enum class TransferProtocol
*
*/
inline std::optional<TransferProtocol>
- getTransferProtocolFromUri(const boost::urls::url_view& imageUri)
+ getTransferProtocolFromUri(boost::urls::url_view imageUri)
{
std::string_view scheme = imageUri.scheme();
if (scheme == "smb")
diff --git a/redfish-core/src/error_messages.cpp b/redfish-core/src/error_messages.cpp
index 77531f0a7c..b4358295c9 100644
--- a/redfish-core/src/error_messages.cpp
+++ b/redfish-core/src/error_messages.cpp
@@ -204,14 +204,13 @@ void malformedJSON(crow::Response& res)
* See header file for more information
* @endinternal
*/
-nlohmann::json resourceMissingAtURI(const boost::urls::url_view& arg1)
+nlohmann::json resourceMissingAtURI(boost::urls::url_view arg1)
{
std::array<std::string_view, 1> args{arg1.buffer()};
return getLog(redfish::registries::base::Index::resourceMissingAtURI, args);
}
-void resourceMissingAtURI(crow::Response& res,
- const boost::urls::url_view& arg1)
+void resourceMissingAtURI(crow::Response& res, boost::urls::url_view arg1)
{
res.result(boost::beast::http::status::bad_request);
addMessageToErrorJson(res.jsonValue, resourceMissingAtURI(arg1));
@@ -313,15 +312,14 @@ void unrecognizedRequestBody(crow::Response& res)
* See header file for more information
* @endinternal
*/
-nlohmann::json resourceAtUriUnauthorized(const boost::urls::url_view& arg1,
+nlohmann::json resourceAtUriUnauthorized(boost::urls::url_view arg1,
std::string_view arg2)
{
return getLog(redfish::registries::base::Index::resourceAtUriUnauthorized,
std::to_array<std::string_view>({arg1.buffer(), arg2}));
}
-void resourceAtUriUnauthorized(crow::Response& res,
- const boost::urls::url_view& arg1,
+void resourceAtUriUnauthorized(crow::Response& res, boost::urls::url_view arg1,
std::string_view arg2)
{
res.result(boost::beast::http::status::unauthorized);
@@ -544,7 +542,7 @@ void propertyValueOutOfRange(crow::Response& res, std::string_view arg1,
* See header file for more information
* @endinternal
*/
-nlohmann::json resourceAtUriInUnknownFormat(const boost::urls::url_view& arg1)
+nlohmann::json resourceAtUriInUnknownFormat(boost::urls::url_view arg1)
{
return getLog(
redfish::registries::base::Index::resourceAtUriInUnknownFormat,
@@ -552,7 +550,7 @@ nlohmann::json resourceAtUriInUnknownFormat(const boost::urls::url_view& arg1)
}
void resourceAtUriInUnknownFormat(crow::Response& res,
- const boost::urls::url_view& arg1)
+ boost::urls::url_view arg1)
{
res.result(boost::beast::http::status::bad_request);
addMessageToErrorJson(res.jsonValue, resourceAtUriInUnknownFormat(arg1));
@@ -719,14 +717,13 @@ void resourceTypeIncompatible(crow::Response& res, std::string_view arg1,
* See header file for more information
* @endinternal
*/
-nlohmann::json resetRequired(const boost::urls::url_view& arg1,
- std::string_view arg2)
+nlohmann::json resetRequired(boost::urls::url_view arg1, std::string_view arg2)
{
return getLog(redfish::registries::base::Index::resetRequired,
std::to_array<std::string_view>({arg1.buffer(), arg2}));
}
-void resetRequired(crow::Response& res, const boost::urls::url_view& arg1,
+void resetRequired(crow::Response& res, boost::urls::url_view arg1,
std::string_view arg2)
{
res.result(boost::beast::http::status::bad_request);
@@ -802,7 +799,7 @@ void propertyValueConflict(crow::Response& res, std::string_view arg1,
*/
nlohmann::json propertyValueResourceConflict(std::string_view arg1,
std::string_view arg2,
- const boost::urls::url_view& arg3)
+ boost::urls::url_view arg3)
{
return getLog(
redfish::registries::base::Index::propertyValueResourceConflict,
@@ -811,7 +808,7 @@ nlohmann::json propertyValueResourceConflict(std::string_view arg1,
void propertyValueResourceConflict(crow::Response& res, std::string_view arg1,
std::string_view arg2,
- const boost::urls::url_view& arg3)
+ boost::urls::url_view arg3)
{
res.result(boost::beast::http::status::conflict);
addMessageToErrorJson(res.jsonValue,
@@ -869,14 +866,13 @@ void propertyValueIncorrect(crow::Response& res, std::string_view arg1,
* See header file for more information
* @endinternal
*/
-nlohmann::json resourceCreationConflict(const boost::urls::url_view& arg1)
+nlohmann::json resourceCreationConflict(boost::urls::url_view arg1)
{
return getLog(redfish::registries::base::Index::resourceCreationConflict,
std::to_array<std::string_view>({arg1.buffer()}));
}
-void resourceCreationConflict(crow::Response& res,
- const boost::urls::url_view& arg1)
+void resourceCreationConflict(crow::Response& res, boost::urls::url_view arg1)
{
res.result(boost::beast::http::status::bad_request);
addMessageToErrorJson(res.jsonValue, resourceCreationConflict(arg1));
@@ -1021,14 +1017,14 @@ void resourceNotFound(crow::Response& res, std::string_view arg1,
* See header file for more information
* @endinternal
*/
-nlohmann::json couldNotEstablishConnection(const boost::urls::url_view& arg1)
+nlohmann::json couldNotEstablishConnection(boost::urls::url_view arg1)
{
return getLog(redfish::registries::base::Index::couldNotEstablishConnection,
std::to_array<std::string_view>({arg1.buffer()}));
}
void couldNotEstablishConnection(crow::Response& res,
- const boost::urls::url_view& arg1)
+ boost::urls::url_view arg1)
{
res.result(boost::beast::http::status::not_found);
addMessageToErrorJson(res.jsonValue, couldNotEstablishConnection(arg1));
@@ -1145,7 +1141,7 @@ void actionParameterNotSupported(crow::Response& res, std::string_view arg1,
* See header file for more information
* @endinternal
*/
-nlohmann::json sourceDoesNotSupportProtocol(const boost::urls::url_view& arg1,
+nlohmann::json sourceDoesNotSupportProtocol(boost::urls::url_view arg1,
std::string_view arg2)
{
return getLog(
@@ -1154,7 +1150,7 @@ nlohmann::json sourceDoesNotSupportProtocol(const boost::urls::url_view& arg1,
}
void sourceDoesNotSupportProtocol(crow::Response& res,
- const boost::urls::url_view& arg1,
+ boost::urls::url_view arg1,
std::string_view arg2)
{
res.result(boost::beast::http::status::bad_request);
@@ -1206,13 +1202,13 @@ void accountRemoved(crow::Response& res)
* See header file for more information
* @endinternal
*/
-nlohmann::json accessDenied(const boost::urls::url_view& arg1)
+nlohmann::json accessDenied(boost::urls::url_view arg1)
{
return getLog(redfish::registries::base::Index::accessDenied,
std::to_array<std::string_view>({arg1.buffer()}));
}
-void accessDenied(crow::Response& res, const boost::urls::url_view& arg1)
+void accessDenied(crow::Response& res, boost::urls::url_view arg1)
{
res.result(boost::beast::http::status::forbidden);
addMessageToErrorJson(res.jsonValue, accessDenied(arg1));
@@ -1373,13 +1369,13 @@ void noValidSession(crow::Response& res)
* See header file for more information
* @endinternal
*/
-nlohmann::json invalidObject(const boost::urls::url_view& arg1)
+nlohmann::json invalidObject(boost::urls::url_view arg1)
{
return getLog(redfish::registries::base::Index::invalidObject,
std::to_array<std::string_view>({arg1.buffer()}));
}
-void invalidObject(crow::Response& res, const boost::urls::url_view& arg1)
+void invalidObject(crow::Response& res, boost::urls::url_view arg1)
{
res.result(boost::beast::http::status::bad_request);
addMessageToErrorJson(res.jsonValue, invalidObject(arg1));
@@ -1719,7 +1715,7 @@ void queryParameterOutOfRange(crow::Response& res, std::string_view arg1,
queryParameterOutOfRange(arg1, arg2, arg3));
}
-nlohmann::json passwordChangeRequired(const boost::urls::url_view& arg1)
+nlohmann::json passwordChangeRequired(boost::urls::url_view arg1)
{
return getLog(redfish::registries::base::Index::passwordChangeRequired,
std::to_array<std::string_view>({arg1.buffer()}));
@@ -1732,8 +1728,7 @@ nlohmann::json passwordChangeRequired(const boost::urls::url_view& arg1)
* See header file for more information
* @endinternal
*/
-void passwordChangeRequired(crow::Response& res,
- const boost::urls::url_view& arg1)
+void passwordChangeRequired(crow::Response& res, boost::urls::url_view arg1)
{
messages::addMessageToJsonRoot(res.jsonValue, passwordChangeRequired(arg1));
}