bmcweb: /s/boost::string_view/std::string_view/g
With boost 1.69, we get the new option, BOOST_BEAST_USE_STD_STRING_VIEW
which allows us to use std::string for all beast interfaces, instead of
boost string_view. This was originally intended to try to reduce the
binary size, but the comparison shows only a minor improvement.
boost::string_view: 7420780 bytes
std::string_view: 7419948 bytes
832 bytes saved ! ! ! ! !
So instead, we will use the argument that it's more standard and easier
for people to grok.
Tested By:
Pulled down some bmcweb endpoints, and observed no change. Because the
two objects are essentially drop in replacements for one another, there
should be no change.
Change-Id: I001e8cf2a0124de4792a7154bf246e3c35ef3f97
Signed-off-by: Ed Tanous <ed.tanous@intel.com>
diff --git a/include/http_utility.hpp b/include/http_utility.hpp
index 0f5bb8c..e2b1a11 100644
--- a/include/http_utility.hpp
+++ b/include/http_utility.hpp
@@ -5,7 +5,7 @@
{
inline bool requestPrefersHtml(const crow::Request& req)
{
- boost::string_view header = req.getHeaderValue("accept");
+ std::string_view header = req.getHeaderValue("accept");
std::vector<std::string> encodings;
// chrome currently sends 6 accepts headers, firefox sends 4.
encodings.reserve(6);
@@ -25,7 +25,7 @@
return false;
}
-inline std::string urlEncode(const boost::string_view value)
+inline std::string urlEncode(const std::string_view value)
{
std::ostringstream escaped;
escaped.fill('0');
diff --git a/include/pam_authenticate.hpp b/include/pam_authenticate.hpp
index 7f2a33c..f211a29 100644
--- a/include/pam_authenticate.hpp
+++ b/include/pam_authenticate.hpp
@@ -17,7 +17,7 @@
char* appPass = reinterpret_cast<char*>(appdataPtr);
size_t appPassSize = std::strlen(appPass);
char* pass = reinterpret_cast<char*>(malloc(appPassSize + 1));
- if (!pass)
+ if (pass == nullptr)
{
return PAM_AUTH_ERR;
}
@@ -27,7 +27,7 @@
*resp = reinterpret_cast<pam_response*>(
calloc(numMsg, sizeof(struct pam_response)));
- if (resp == NULL)
+ if (resp == nullptr)
{
return PAM_AUTH_ERR;
}
@@ -47,8 +47,8 @@
return PAM_SUCCESS;
}
-inline bool pamAuthenticateUser(const boost::string_view username,
- const boost::string_view password)
+inline bool pamAuthenticateUser(const std::string_view username,
+ const std::string_view password)
{
std::string userStr(username);
std::string passStr(password);
diff --git a/include/sessions.hpp b/include/sessions.hpp
index 510f566..6bc1c99 100644
--- a/include/sessions.hpp
+++ b/include/sessions.hpp
@@ -102,7 +102,7 @@
{
public:
std::shared_ptr<UserSession> generateUserSession(
- const boost::string_view username,
+ const std::string_view username,
PersistenceType persistence = PersistenceType::TIMEOUT)
{
// TODO(ed) find a secure way to not generate session identifiers if
@@ -148,7 +148,7 @@
}
std::shared_ptr<UserSession>
- loginSessionByToken(const boost::string_view token)
+ loginSessionByToken(const std::string_view token)
{
applySessionTimeouts();
auto sessionIt = authTokens.find(std::string(token));
@@ -161,7 +161,7 @@
return userSession;
}
- std::shared_ptr<UserSession> getSessionByUid(const boost::string_view uid)
+ std::shared_ptr<UserSession> getSessionByUid(const std::string_view uid)
{
applySessionTimeouts();
// TODO(Ed) this is inefficient
diff --git a/include/token_authorization_middleware.hpp b/include/token_authorization_middleware.hpp
index b186a5f..c5c6523 100644
--- a/include/token_authorization_middleware.hpp
+++ b/include/token_authorization_middleware.hpp
@@ -39,7 +39,7 @@
}
if (ctx.session == nullptr)
{
- boost::string_view authHeader = req.getHeaderValue("Authorization");
+ std::string_view authHeader = req.getHeaderValue("Authorization");
if (!authHeader.empty())
{
// Reject any kind of auth other than basic or token
@@ -104,12 +104,12 @@
private:
const std::shared_ptr<crow::persistent_data::UserSession>
- performBasicAuth(boost::string_view auth_header) const
+ performBasicAuth(std::string_view auth_header) const
{
BMCWEB_LOG_DEBUG << "[AuthMiddleware] Basic authentication";
std::string authData;
- boost::string_view param = auth_header.substr(strlen("Basic "));
+ std::string_view param = auth_header.substr(strlen("Basic "));
if (!crow::utility::base64Decode(param, authData))
{
return nullptr;
@@ -146,11 +146,11 @@
}
const std::shared_ptr<crow::persistent_data::UserSession>
- performTokenAuth(boost::string_view auth_header) const
+ performTokenAuth(std::string_view auth_header) const
{
BMCWEB_LOG_DEBUG << "[AuthMiddleware] Token authentication";
- boost::string_view token = auth_header.substr(strlen("Token "));
+ std::string_view token = auth_header.substr(strlen("Token "));
auto session =
persistent_data::SessionStore::getInstance().loginSessionByToken(
token);
@@ -162,7 +162,7 @@
{
BMCWEB_LOG_DEBUG << "[AuthMiddleware] X-Auth-Token authentication";
- boost::string_view token = req.getHeaderValue("X-Auth-Token");
+ std::string_view token = req.getHeaderValue("X-Auth-Token");
if (token.empty())
{
return nullptr;
@@ -178,7 +178,7 @@
{
BMCWEB_LOG_DEBUG << "[AuthMiddleware] Cookie authentication";
- boost::string_view cookieValue = req.getHeaderValue("Cookie");
+ std::string_view cookieValue = req.getHeaderValue("Cookie");
if (cookieValue.empty())
{
return nullptr;
@@ -195,7 +195,7 @@
{
endIndex = cookieValue.size();
}
- boost::string_view authKey =
+ std::string_view authKey =
cookieValue.substr(startIndex, endIndex - startIndex);
const std::shared_ptr<crow::persistent_data::UserSession> session =
@@ -209,7 +209,7 @@
// RFC7231 defines methods that need csrf protection
if (req.method() != "GET"_method)
{
- boost::string_view csrf = req.getHeaderValue("X-XSRF-TOKEN");
+ std::string_view csrf = req.getHeaderValue("X-XSRF-TOKEN");
// Make sure both tokens are filled
if (csrf.empty() || session->csrfToken.empty())
{
@@ -274,9 +274,9 @@
BMCWEB_ROUTE(app, "/login")
.methods(
"POST"_method)([&](const crow::Request& req, crow::Response& res) {
- boost::string_view contentType = req.getHeaderValue("content-type");
- boost::string_view username;
- boost::string_view password;
+ std::string_view contentType = req.getHeaderValue("content-type");
+ std::string_view username;
+ std::string_view password;
bool looksLikeIbm = false;